// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::InterfaceVariableAccessHandler::handle(spv::Op, unsigned int const*, unsigned int)
bool Compiler::InterfaceVariableAccessHandler::handle(Op opcode, const uint32_t *args, uint32_t length)
{
	uint32_t variable = 0;
	switch (opcode)
	{
	// Need this first, otherwise, GCC complains about unhandled switch statements.
	default:
		break;

	case OpFunctionCall:
	{
		// Invalid SPIR-V.
		if (length < 3)
			return false;

		uint32_t count = length - 3;
		args += 3;
		for (uint32_t i = 0; i < count; i++)
		{
			auto *var = compiler.maybe_get<SPIRVariable>(args[i]);
			if (var && storage_class_is_interface(var->storage))
				variables.insert(args[i]);
		}
		break;
	}

	case OpAtomicStore:
	case OpStore:
		// Invalid SPIR-V.
		if (length < 1)
			return false;
		variable = args[0];
		break;

	case OpCopyMemory:
	{
		if (length < 2)
			return false;

		auto *var = compiler.maybe_get<SPIRVariable>(args[0]);
		if (var && storage_class_is_interface(var->storage))
			variables.insert(variable);

		var = compiler.maybe_get<SPIRVariable>(args[1]);
		if (var && storage_class_is_interface(var->storage))
			variables.insert(variable);
		break;
	}

	case OpExtInst:
	{
		if (length < 5)
			return false;
		uint32_t extension_set = args[2];
		if (compiler.get<SPIRExtension>(extension_set).ext == SPIRExtension::SPV_AMD_shader_explicit_vertex_parameter)
		{
			enum AMDShaderExplicitVertexParameter
			{
				InterpolateAtVertexAMD = 1
			};

			auto op = static_cast<AMDShaderExplicitVertexParameter>(args[3]);

			switch (op)
			{
			case InterpolateAtVertexAMD:
			{
				auto *var = compiler.maybe_get<SPIRVariable>(args[4]);
				if (var && storage_class_is_interface(var->storage))
					variables.insert(args[4]);
				break;
			}

			default:
				break;
			}
		}
		break;
	}

	case OpAccessChain:
	case OpInBoundsAccessChain:
	case OpLoad:
	case OpCopyObject:
	case OpImageTexelPointer:
	case OpAtomicLoad:
	case OpAtomicExchange:
	case OpAtomicCompareExchange:
	case OpAtomicCompareExchangeWeak:
	case OpAtomicIIncrement:
	case OpAtomicIDecrement:
	case OpAtomicIAdd:
	case OpAtomicISub:
	case OpAtomicSMin:
	case OpAtomicUMin:
	case OpAtomicSMax:
	case OpAtomicUMax:
	case OpAtomicAnd:
	case OpAtomicOr:
	case OpAtomicXor:
		// Invalid SPIR-V.
		if (length < 3)
			return false;
		variable = args[2];
		break;
	}

	if (variable)
	{
		auto *var = compiler.maybe_get<SPIRVariable>(variable);
		if (var && storage_class_is_interface(var->storage))
			variables.insert(variable);
	}
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %ecx, %r12d
movq %rdx, %r15
andl $0x0, 0xc(%rsp)
movq %rdi, %r14
movb $0x1, %bl
leal -0xe5(%rsi), %eax
cmpl $0xe, %eax
jb 0x11349
leal -0x39(%rsi), %eax
cmpl $0x9, %eax
ja 0x1139c
leaq 0x7e5a8(%rip), %rcx     # 0x8f8e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x3, %r12d
jae 0x11353
xorl %ebx, %ebx
jmp 0x1138d
movl 0x8(%r15), %esi
movl %esi, 0xc(%rsp)
testl %esi, %esi
je 0x1138d
movq 0x8(%r14), %rdi
callq 0x170fa
testq %rax, %rax
je 0x1138d
movl 0x10(%rax), %eax
cmpl $0xc, %eax
ja 0x1138d
movl $0x160f, %ecx           # imm = 0x160F
btl %eax, %ecx
jae 0x1138d
movq 0x10(%r14), %rdi
leaq 0xc(%rsp), %rsi
callq 0x1af30
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xc, %esi
je 0x11480
cmpl $0x53, %esi
je 0x11349
cmpl $0xe3, %esi
je 0x11349
cmpl $0xe4, %esi
jne 0x1138d
testl %r12d, %r12d
je 0x1134f
movl (%r15), %esi
jmp 0x11357
cmpl $0x3, %r12d
jb 0x1134f
addl $-0x3, %r12d
addq $0xc, %r15
movl $0x160f, %ebp           # imm = 0x160F
subq $0x1, %r12
jb 0x114d5
movq 0x8(%r14), %rdi
movl (%r15), %esi
callq 0x170fa
testq %rax, %rax
je 0x1140b
movl 0x10(%rax), %eax
cmpl $0xc, %eax
ja 0x1140b
btl %eax, %ebp
jae 0x1140b
movq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0x1af30
addq $0x4, %r15
jmp 0x113d7
cmpl $0x2, %r12d
jb 0x1134f
movq 0x8(%r14), %rdi
movl (%r15), %esi
callq 0x170fa
testq %rax, %rax
je 0x1144c
movl 0x10(%rax), %eax
cmpl $0xc, %eax
ja 0x1144c
movl $0x160f, %ecx           # imm = 0x160F
btl %eax, %ecx
jae 0x1144c
movq 0x10(%r14), %rdi
leaq 0xc(%rsp), %rsi
callq 0x1af30
movq 0x8(%r14), %rdi
movl 0x4(%r15), %esi
callq 0x170fa
testq %rax, %rax
je 0x114d5
movl 0x10(%rax), %eax
cmpl $0xc, %eax
ja 0x114d5
movl $0x160f, %ecx           # imm = 0x160F
btl %eax, %ecx
jae 0x114d5
movq 0x10(%r14), %rdi
leaq 0xc(%rsp), %rsi
callq 0x1af30
jmp 0x114d5
cmpl $0x5, %r12d
jb 0x1134f
movl 0x8(%r15), %esi
movq 0x8(%r14), %rdi
callq 0x17130
cmpl $0x3, 0xc(%rax)
jne 0x114d5
cmpl $0x1, 0xc(%r15)
jne 0x114d5
movq 0x8(%r14), %rdi
movl 0x10(%r15), %esi
callq 0x170fa
testq %rax, %rax
je 0x114d5
movl 0x10(%rax), %eax
cmpl $0xc, %eax
ja 0x114d5
movl $0x160f, %ecx           # imm = 0x160F
btl %eax, %ecx
jae 0x114d5
addq $0x10, %r15
movq 0x10(%r14), %rdi
movq %r15, %rsi
jmp 0x11479
movl 0xc(%rsp), %esi
jmp 0x1135b