// File: /workspace/github_cpp_makefile_star2_O1/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 0x179d9
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 0x179ca
movq %rdx, %r15
movq %rdi, %r14
movabsq $0x6c0400000000, %rax   # imm = 0x6C0400000000
btq %rsi, %rax
jae 0x17a36
movq 0x8(%r14), %rdi
movl 0x8(%r15), %esi
callq 0x12cda
testq %rax, %rax
je 0x179ca
movq 0x8(%r14), %rdi
movl 0xc(%rax), %esi
callq 0xa426
cmpl $0xd, 0xc(%rax)
jne 0x179ca
cmpl $0x1, 0x8c(%rax)
jne 0x179ca
cmpl $0x5, 0x84(%rax)
je 0x179ca
movb $0x1, 0x10(%r14)
jmp 0x179ca
movl $0x30, %eax
btq %rsi, %rax
jae 0x17ad6
cmpl $0x3, %ecx
jb 0x179c8
movl (%r15), %esi
movl %esi, 0x8(%rsp)
movq 0x8(%r14), %rdi
callq 0xa426
cmpl $0xd, 0xc(%rax)
jne 0x179ca
cmpl $0x1, 0x8c(%rax)
jne 0x179ca
cmpl $0x5, 0x84(%rax)
je 0x179ca
movl 0x4(%r15), %r12d
movl 0x8(%r15), %ebp
movq 0x8(%r14), %rdi
movb $0x1, %r15b
leaq 0x6(%rsp), %r8
movb %r15b, (%r8)
leaq 0x9de0f(%rip), %rdx     # 0xb58af
leaq 0x8(%rsp), %rcx
movl %r12d, %esi
callq 0x1c27a
movq 0x8(%r14), %rdi
movl %r12d, %esi
movl %ebp, %edx
movl $0x1, %ecx
callq 0x12d38
movq 0x8(%r14), %rax
movq 0x20(%rax), %rax
shlq $0x4, %r12
movb %r15b, 0xc(%rax,%r12)
jmp 0x179ca
testq %rsi, %rsi
jne 0x179ca
cmpl $0x3, %ecx
jb 0x179c8
movl (%r15), %esi
movl %esi, 0xc(%rsp)
movq 0x8(%r14), %rdi
callq 0xa426
cmpl $0xd, 0xc(%rax)
jne 0x179ca
cmpl $0x1, 0x8c(%rax)
jne 0x179ca
cmpl $0x5, 0x84(%rax)
je 0x179ca
movl 0x4(%r15), %ebp
movl 0x8(%r15), %r15d
movq 0x8(%r14), %rdi
leaq 0x7(%rsp), %r8
movb $0x1, (%r8)
leaq 0x9dd77(%rip), %rdx     # 0xb58af
leaq 0xc(%rsp), %rcx
movl %ebp, %esi
callq 0x1c27a
movq 0x8(%r14), %rdi
movl %ebp, %esi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x12d38
jmp 0x179ca