// CheckStyle: stop header check
// CheckStyle: stop line length check
// GENERATED CONTENT - DO NOT EDIT
// GENERATORS: org.graalvm.compiler.replacements.processor.ReplacementsAnnotationProcessor, org.graalvm.compiler.replacements.processor.PluginGenerator
package org.graalvm.compiler.replacements.amd64;


import java.lang.annotation.Annotation;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.graph.NodeInputList;
import org.graalvm.compiler.nodes.ConstantNode;
import org.graalvm.compiler.nodes.PluginReplacementNode;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedFoldInvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedPluginFactory;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedPluginInjectionProvider;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;

//        class: org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions
//       method: lzcnt(jdk.vm.ci.code.TargetDescription)
// generated-by: org.graalvm.compiler.replacements.processor.GeneratedFoldPlugin
final class Plugin_AMD64IntegerSubstitutions_lzcnt extends GeneratedFoldInvocationPlugin {

    @Override
    public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) {
        if (!b.isPluginEnabled(this)) {
            return false;
        }
        if (b.shouldDeferPlugin(this)) {
            b.replacePlugin(this, targetMethod, args, PluginReplacementNode_AMD64IntegerSubstitutions_lzcnt.FUNCTION);
            return true;
        }
        if (!checkInjectedArgument(b, args[0], targetMethod)) {
            return false;
        }
        jdk.vm.ci.code.TargetDescription arg0 = injectedTargetDescription;
        boolean result = org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions.lzcnt(arg0);
        JavaConstant constant = JavaConstant.forInt(result ? 1 : 0);
        ConstantNode node = ConstantNode.forConstant(constant, b.getMetaAccess()/* A META_ACCESS */, b.getGraph()/* A STRUCTURED_GRAPH */);
        b.push(JavaKind.Int, node);
        b.notifyReplacedCall(targetMethod, node);
        return true;
    }
    @Override
    public Class<? extends Annotation> getSource() {
        return org.graalvm.compiler.api.replacements.Fold.class;
    }

    private final jdk.vm.ci.code.TargetDescription injectedTargetDescription;

    Plugin_AMD64IntegerSubstitutions_lzcnt(GeneratedPluginInjectionProvider injection) {
        this.injectedTargetDescription = injection.getInjectedArgument(jdk.vm.ci.code.TargetDescription.class);
    }
}
final class PluginReplacementNode_AMD64IntegerSubstitutions_lzcnt implements PluginReplacementNode.ReplacementFunction {
    static PluginReplacementNode.ReplacementFunction FUNCTION = new PluginReplacementNode_AMD64IntegerSubstitutions_lzcnt();

    @Override
    public boolean replace(GraphBuilderContext b, GeneratedPluginInjectionProvider injection, Stamp stamp, NodeInputList<ValueNode> args) {
        assert args.get(0).isNullConstant();
        jdk.vm.ci.code.TargetDescription arg0 = injection.getInjectedArgument(jdk.vm.ci.code.TargetDescription.class);
        boolean result = org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions.lzcnt(arg0);
        JavaConstant constant = JavaConstant.forInt(result ? 1 : 0);
        ConstantNode node = ConstantNode.forConstant(constant, b.getMetaAccess()/* B META_ACCESS */, b.getGraph()/* B STRUCTURED_GRAPH */);
        b.push(JavaKind.Int, node);
        return true;
    }
}

//        class: org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions
//       method: tzcnt(jdk.vm.ci.code.TargetDescription)
// generated-by: org.graalvm.compiler.replacements.processor.GeneratedFoldPlugin
final class Plugin_AMD64IntegerSubstitutions_tzcnt extends GeneratedFoldInvocationPlugin {

    @Override
    public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) {
        if (!b.isPluginEnabled(this)) {
            return false;
        }
        if (b.shouldDeferPlugin(this)) {
            b.replacePlugin(this, targetMethod, args, PluginReplacementNode_AMD64IntegerSubstitutions_tzcnt.FUNCTION);
            return true;
        }
        if (!checkInjectedArgument(b, args[0], targetMethod)) {
            return false;
        }
        jdk.vm.ci.code.TargetDescription arg0 = injectedTargetDescription;
        boolean result = org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions.tzcnt(arg0);
        JavaConstant constant = JavaConstant.forInt(result ? 1 : 0);
        ConstantNode node = ConstantNode.forConstant(constant, b.getMetaAccess()/* A META_ACCESS */, b.getGraph()/* A STRUCTURED_GRAPH */);
        b.push(JavaKind.Int, node);
        b.notifyReplacedCall(targetMethod, node);
        return true;
    }
    @Override
    public Class<? extends Annotation> getSource() {
        return org.graalvm.compiler.api.replacements.Fold.class;
    }

    private final jdk.vm.ci.code.TargetDescription injectedTargetDescription;

    Plugin_AMD64IntegerSubstitutions_tzcnt(GeneratedPluginInjectionProvider injection) {
        this.injectedTargetDescription = injection.getInjectedArgument(jdk.vm.ci.code.TargetDescription.class);
    }
}
final class PluginReplacementNode_AMD64IntegerSubstitutions_tzcnt implements PluginReplacementNode.ReplacementFunction {
    static PluginReplacementNode.ReplacementFunction FUNCTION = new PluginReplacementNode_AMD64IntegerSubstitutions_tzcnt();

    @Override
    public boolean replace(GraphBuilderContext b, GeneratedPluginInjectionProvider injection, Stamp stamp, NodeInputList<ValueNode> args) {
        assert args.get(0).isNullConstant();
        jdk.vm.ci.code.TargetDescription arg0 = injection.getInjectedArgument(jdk.vm.ci.code.TargetDescription.class);
        boolean result = org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions.tzcnt(arg0);
        JavaConstant constant = JavaConstant.forInt(result ? 1 : 0);
        ConstantNode node = ConstantNode.forConstant(constant, b.getMetaAccess()/* B META_ACCESS */, b.getGraph()/* B STRUCTURED_GRAPH */);
        b.push(JavaKind.Int, node);
        return true;
    }
}

public class PluginFactory_AMD64IntegerSubstitutions implements GeneratedPluginFactory {
    @Override
    public void registerPlugins(InvocationPlugins plugins, GeneratedPluginInjectionProvider injection) {
        plugins.register(new Plugin_AMD64IntegerSubstitutions_lzcnt(injection), org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions.class, "lzcnt", jdk.vm.ci.code.TargetDescription.class);
        plugins.register(new Plugin_AMD64IntegerSubstitutions_tzcnt(injection), org.graalvm.compiler.replacements.amd64.AMD64IntegerSubstitutions.class, "tzcnt", jdk.vm.ci.code.TargetDescription.class);
    }
}