// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::DummySamplerForCombinedImageHandler::handle(spv::Op, unsigned int const*, unsigned int)
bool Compiler::DummySamplerForCombinedImageHandler::handle(Op opcode, const uint32_t *args, uint32_t length)
{
	if (need_dummy_sampler)
	{
		// No need to traverse further, we know the result.
		return false;
	}

	switch (opcode)
	{
	case OpLoad:
	{
		if (length < 3)
			return false;

		uint32_t result_type = args[0];

		auto &type = compiler.get<SPIRType>(result_type);
		bool separate_image =
		    type.basetype == SPIRType::Image && type.image.sampled == 1 && type.image.dim != DimBuffer;

		// If not separate image, don't bother.
		if (!separate_image)
			return true;

		uint32_t id = args[1];
		uint32_t ptr = args[2];
		compiler.set<SPIRExpression>(id, "", result_type, true);
		compiler.register_read(id, ptr, true);
		break;
	}

	case OpImageFetch:
	case OpImageQuerySizeLod:
	case OpImageQuerySize:
	case OpImageQueryLevels:
	case OpImageQuerySamples:
	{
		// If we are fetching or querying LOD from a plain OpTypeImage, we must pre-combine with our dummy sampler.
		auto *var = compiler.maybe_get_backing_variable(args[2]);
		if (var)
		{
			auto &type = compiler.get<SPIRType>(var->basetype);
			if (type.basetype == SPIRType::Image && type.image.sampled == 1 && type.image.dim != DimBuffer)
				need_dummy_sampler = true;
		}

		break;
	}

	case OpInBoundsAccessChain:
	case OpAccessChain:
	{
		if (length < 3)
			return false;

		uint32_t result_type = args[0];
		auto &type = compiler.get<SPIRType>(result_type);
		bool separate_image =
		    type.basetype == SPIRType::Image && type.image.sampled == 1 && type.image.dim != DimBuffer;
		if (!separate_image)
			return true;

		uint32_t id = args[1];
		uint32_t ptr = args[2];
		compiler.set<SPIRExpression>(id, "", result_type, true);
		compiler.register_read(id, ptr, true);

		// Other backends might use SPIRAccessChain for this later.
		compiler.ir.ids[id].set_allow_type_rewrite();
		break;
	}

	default:
		break;
	}

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
cmpb $0x0, 0x10(%rdi)
je 0x13f23
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
addl $-0x3d, %esi
cmpl $0x2e, %esi
ja 0x13f14
movq %rdx, %r15
movq %rdi, %r14
movabsq $0x6c0400000000, %rax   # imm = 0x6C0400000000
btq %rsi, %rax
jae 0x13f80
movq 0x8(%r14), %rdi
movl 0x8(%r15), %esi
callq 0x1067e
testq %rax, %rax
je 0x13f14
movq 0x8(%r14), %rdi
movl 0xc(%rax), %esi
callq 0x90a4
cmpl $0xd, 0xc(%rax)
jne 0x13f14
cmpl $0x1, 0x8c(%rax)
jne 0x13f14
cmpl $0x5, 0x84(%rax)
je 0x13f14
movb $0x1, 0x10(%r14)
jmp 0x13f14
pushq $0x30
popq %rax
btq %rsi, %rax
jae 0x14018
cmpl $0x3, %ecx
jb 0x13f12
movl (%r15), %esi
movl %esi, 0x8(%rsp)
movq 0x8(%r14), %rdi
callq 0x90a4
cmpl $0xd, 0xc(%rax)
jne 0x13f14
cmpl $0x1, 0x8c(%rax)
jne 0x13f14
cmpl $0x5, 0x84(%rax)
je 0x13f14
movl 0x4(%r15), %r12d
movl 0x8(%r15), %ebp
movq 0x8(%r14), %rdi
movb $0x1, %r15b
leaq 0x6(%rsp), %r8
movb %r15b, (%r8)
leaq 0x7b8a3(%rip), %rdx     # 0x8f887
leaq 0x8(%rsp), %rcx
movl %r12d, %esi
callq 0x17816
movq 0x8(%r14), %rdi
pushq $0x1
popq %rcx
movl %r12d, %esi
movl %ebp, %edx
callq 0x106dc
movq 0x8(%r14), %rax
movq 0x20(%rax), %rax
shlq $0x4, %r12
movb %r15b, 0xc(%rax,%r12)
jmp 0x13f14
testq %rsi, %rsi
jne 0x13f14
cmpl $0x3, %ecx
jb 0x13f12
movl (%r15), %esi
movl %esi, 0xc(%rsp)
movq 0x8(%r14), %rdi
callq 0x90a4
cmpl $0xd, 0xc(%rax)
jne 0x13f14
cmpl $0x1, 0x8c(%rax)
jne 0x13f14
cmpl $0x5, 0x84(%rax)
je 0x13f14
movl 0x4(%r15), %ebp
movl 0x8(%r15), %r15d
movq 0x8(%r14), %rdi
leaq 0x7(%rsp), %r8
movb $0x1, (%r8)
leaq 0x7b80d(%rip), %rdx     # 0x8f887
leaq 0xc(%rsp), %rcx
movl %ebp, %esi
callq 0x17816
movq 0x8(%r14), %rdi
pushq $0x1
popq %rcx
movl %ebp, %esi
movl %r15d, %edx
callq 0x106dc
jmp 0x13f14