// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::CombinedImageSamplerHandler::end_function_scope(unsigned int const*, unsigned int)
bool Compiler::CombinedImageSamplerHandler::end_function_scope(const uint32_t *args, uint32_t length)
{
	if (length < 3)
		return false;

	auto &callee = compiler.get<SPIRFunction>(args[2]);
	args += 3;

	// There are two types of cases we have to handle,
	// a callee might call sampler2D(texture2D, sampler) directly where
	// one or more parameters originate from parameters.
	// Alternatively, we need to provide combined image samplers to our callees,
	// and in this case we need to add those as well.

	pop_remap_parameters();

	// Our callee has now been processed at least once.
	// No point in doing it again.
	callee.do_combined_parameters = false;

	auto &params = functions.top()->combined_parameters;
	functions.pop();
	if (functions.empty())
		return true;

	auto &caller = *functions.top();
	if (caller.do_combined_parameters)
	{
		for (auto &param : params)
		{
			uint32_t image_id = param.global_image ? param.image_id : args[param.image_id];
			uint32_t sampler_id = param.global_sampler ? param.sampler_id : args[param.sampler_id];

			auto *i = compiler.maybe_get_backing_variable(image_id);
			auto *s = compiler.maybe_get_backing_variable(sampler_id);
			if (i)
				image_id = i->self;
			if (s)
				sampler_id = s->self;

			register_combined_image_sampler(caller, image_id, sampler_id, param.depth);
		}
	}

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0x4(%rsp)
cmpl $0x3, %edx
jb 0x16dd8
movq %rsi, %r14
movq %rdi, %r15
movq 0x8(%rdi), %rdi
movl 0x8(%rsi), %esi
callq 0xb98a
movq %rax, %rbx
leaq 0x10(%r15), %rdi
callq 0x222fe
movb $0x0, 0xca(%rbx)
leaq 0x60(%r15), %rdi
movq 0x90(%r15), %rax
cmpq 0x98(%r15), %rax
jne 0x16ce2
movq 0xa8(%r15), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rbx
callq 0x225ce
movq 0x90(%r15), %rax
cmpq 0x70(%r15), %rax
je 0x16dd8
cmpq 0x98(%r15), %rax
jne 0x16d15
movq 0xa8(%r15), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rax
movq %rax, 0x10(%rsp)
cmpb $0x1, 0xca(%rax)
jne 0x16dd8
movq 0x80(%rbx), %r12
movq 0x88(%rbx), %rax
movq %rax, 0x8(%rsp)
cmpq %rax, %r12
je 0x16dd8
addq $0xc, %r14
addq $0x8, %r12
leaq -0x4(%r12), %rax
movl -0x4(%r12), %ecx
movl (%r12), %edx
leaq (%r14,%rcx,4), %rcx
cmpb $0x0, 0x4(%r12)
cmovneq %rax, %rcx
movl (%rcx), %ebp
leaq (%r14,%rdx,4), %rax
cmpb $0x0, 0x5(%r12)
cmovneq %r12, %rax
movl (%rax), %r13d
movq 0x8(%r15), %rdi
movl %ebp, %esi
callq 0x12c9a
movq %rax, %rbx
movq 0x8(%r15), %rdi
movl %r13d, %esi
callq 0x12c9a
testq %rbx, %rbx
je 0x16da0
movl 0x8(%rbx), %ebp
testq %rax, %rax
je 0x16da9
movl 0x8(%rax), %r13d
movzbl 0x6(%r12), %r8d
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
movl %r13d, %ecx
callq 0x16df0
leaq 0x10(%r12), %rax
addq $0x8, %r12
cmpq 0x8(%rsp), %r12
movq %rax, %r12
jne 0x16d4f
cmpl $0x3, 0x4(%rsp)
setae %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop