// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::to_combined_image_sampler[abi:cxx11](unsigned int, unsigned int)
string CompilerGLSL::to_combined_image_sampler(uint32_t image_id, uint32_t samp_id)
{
	// Keep track of the array indices we have used to load the image.
	// We'll need to use the same array index into the combined image sampler array.
	auto image_expr = to_expression(image_id);
	string array_expr;
	auto array_index = image_expr.find_first_of('[');
	if (array_index != string::npos)
		array_expr = image_expr.substr(array_index, string::npos);

	auto &args = current_function->arguments;

	// For GLSL and ESSL targets, we must enumerate all possible combinations for sampler2D(texture2D, sampler) and redirect
	// all possible combinations into new sampler2D uniforms.
	auto *image = maybe_get_backing_variable(image_id);
	auto *samp = maybe_get_backing_variable(samp_id);
	if (image)
		image_id = image->self;
	if (samp)
		samp_id = samp->self;

	auto image_itr = find_if(begin(args), end(args),
	                         [image_id](const SPIRFunction::Parameter &param) { return param.id == image_id; });

	auto sampler_itr = find_if(begin(args), end(args),
	                           [samp_id](const SPIRFunction::Parameter &param) { return param.id == samp_id; });

	if (image_itr != end(args) || sampler_itr != end(args))
	{
		// If any parameter originates from a parameter, we will find it in our argument list.
		bool global_image = image_itr == end(args);
		bool global_sampler = sampler_itr == end(args);
		uint32_t iid = global_image ? image_id : uint32_t(image_itr - begin(args));
		uint32_t sid = global_sampler ? samp_id : uint32_t(sampler_itr - begin(args));

		auto &combined = current_function->combined_parameters;
		auto itr = find_if(begin(combined), end(combined), [=](const SPIRFunction::CombinedImageSamplerParameter &p) {
			return p.global_image == global_image && p.global_sampler == global_sampler && p.image_id == iid &&
			       p.sampler_id == sid;
		});

		if (itr != end(combined))
			return to_expression(itr->id) + array_expr;
		else
		{
			SPIRV_CROSS_THROW(
			    "Cannot find mapping for combined sampler parameter, was build_combined_image_samplers() used "
			    "before compile() was called?");
		}
	}
	else
	{
		// For global sampler2D, look directly at the global remapping table.
		auto &mapping = combined_image_samplers;
		auto itr = find_if(begin(mapping), end(mapping), [image_id, samp_id](const CombinedImageSampler &combined) {
			return combined.image_id == image_id && combined.sampler_id == samp_id;
		});

		if (itr != end(combined_image_samplers))
			return to_expression(itr->combined_id) + array_expr;
		else
		{
			SPIRV_CROSS_THROW("Cannot find mapping for combined sampler, was build_combined_image_samplers() used "
			                  "before compile() was called?");
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rdi, -0x260(%rbp)
movq %rdi, %rax
movq %rax, -0x258(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x250(%rbp)
movl -0x14(%rbp), %edx
leaq -0x38(%rbp), %rdi
callq 0x71b50
leaq -0x58(%rbp), %rdi
callq 0x7530
leaq -0x38(%rbp), %rdi
movl $0x5b, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x7230
movq %rax, -0x60(%rbp)
cmpq $-0x1, -0x60(%rbp)
je 0x7b050
movq -0x60(%rbp), %rdx
leaq -0x80(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movq $-0x1, %rcx
callq 0x73a0
jmp 0x7b021
leaq -0x58(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7430
leaq -0x80(%rbp), %rdi
callq 0x7708
jmp 0x7b050
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x7b867
movq -0x250(%rbp), %rdi
movq 0x148(%rdi), %rax
addq $0x18, %rax
movq %rax, -0x98(%rbp)
movl -0x14(%rbp), %esi
callq 0x1fa90
movq %rax, -0x268(%rbp)
jmp 0x7b07a
movq -0x250(%rbp), %rdi
movq -0x268(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x18(%rbp), %esi
callq 0x1fa90
movq %rax, -0x270(%rbp)
jmp 0x7b0a0
movq -0x270(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x7b0c5
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x14(%rbp)
cmpq $0x0, -0xa8(%rbp)
je 0x7b0dc
movq -0xa8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x98(%rbp), %rdi
callq 0x30b60
movq %rax, -0x278(%rbp)
jmp 0x7b0f1
movq -0x278(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x98(%rbp), %rdi
callq 0x30b90
movq %rax, -0x280(%rbp)
jmp 0x7b114
movq -0x280(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movl -0xc4(%rbp), %edx
callq 0x7b890
movq %rax, -0x288(%rbp)
jmp 0x7b14d
movq -0x288(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x30b60
movq %rax, -0x290(%rbp)
jmp 0x7b170
movq -0x290(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x98(%rbp), %rdi
callq 0x30b90
movq %rax, -0x298(%rbp)
jmp 0x7b193
movq -0x298(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xe4(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movl -0xe4(%rbp), %edx
callq 0x7b8f0
movq %rax, -0x2a0(%rbp)
jmp 0x7b1cc
movq -0x2a0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x30b90
movq %rax, -0x2a8(%rbp)
jmp 0x7b1ef
movq -0x2a8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x11610
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x2a9(%rbp)
jne 0x7b25b
movq -0x98(%rbp), %rdi
callq 0x30b90
movq %rax, -0x2b8(%rbp)
jmp 0x7b234
movq -0x2b8(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x11610
movb %al, -0x2a9(%rbp)
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x7b26a
jmp 0x7b612
movq -0x98(%rbp), %rdi
callq 0x30b90
movq %rax, -0x2c0(%rbp)
jmp 0x7b27f
movq -0x2c0(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0xa3760
movb %al, -0xf9(%rbp)
movq -0x98(%rbp), %rdi
callq 0x30b90
movq %rax, -0x2c8(%rbp)
jmp 0x7b2bb
movq -0x2c8(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xa3760
andb $0x1, %al
movb %al, -0x109(%rbp)
testb $0x1, -0xf9(%rbp)
je 0x7b2f8
movl -0x14(%rbp), %eax
movl %eax, -0x2cc(%rbp)
jmp 0x7b334
movq -0x98(%rbp), %rdi
callq 0x30b60
movq %rax, -0x2d8(%rbp)
jmp 0x7b30d
movq -0x2d8(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x30bc0
movl %eax, -0x2cc(%rbp)
movl -0x2cc(%rbp), %eax
movl %eax, -0x11c(%rbp)
testb $0x1, -0x109(%rbp)
je 0x7b354
movl -0x18(%rbp), %eax
movl %eax, -0x2dc(%rbp)
jmp 0x7b390
movq -0x98(%rbp), %rdi
callq 0x30b60
movq %rax, -0x2e8(%rbp)
jmp 0x7b369
movq -0x2e8(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x30bc0
movl %eax, -0x2dc(%rbp)
movq -0x250(%rbp), %rax
movl -0x2dc(%rbp), %ecx
movl %ecx, -0x12c(%rbp)
movq 0x148(%rax), %rax
subq $-0x80, %rax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rdi
callq 0x30c10
movq %rax, -0x2f0(%rbp)
jmp 0x7b3ca
movq -0x2f0(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x140(%rbp), %rdi
callq 0x30c40
movq %rax, -0x2f8(%rbp)
jmp 0x7b3ed
movq -0x2f8(%rbp), %rax
movq %rax, -0x158(%rbp)
movb -0xf9(%rbp), %al
andb $0x1, %al
movb %al, -0x164(%rbp)
movb -0x109(%rbp), %al
andb $0x1, %al
movb %al, -0x163(%rbp)
movl -0x11c(%rbp), %eax
movl %eax, -0x160(%rbp)
movl -0x12c(%rbp), %eax
movl %eax, -0x15c(%rbp)
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
movl -0x15c(%rbp), %eax
movl %eax, -0x170(%rbp)
movq -0x164(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rdx
movl -0x170(%rbp), %ecx
callq 0x7b950
movq %rax, -0x300(%rbp)
jmp 0x7b472
movq -0x300(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x140(%rbp), %rdi
callq 0x30c40
movq %rax, -0x308(%rbp)
jmp 0x7b495
movq -0x308(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x148(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x30ae0
testb $0x1, %al
jne 0x7b4bc
jmp 0x7b536
leaq -0x148(%rbp), %rdi
callq 0xa37a0
movq -0x250(%rbp), %rsi
movl (%rax), %edx
leaq -0x1a0(%rbp), %rdi
callq 0x71b50
jmp 0x7b4df
movq -0x260(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0xa1530
jmp 0x7b4f8
leaq -0x1a0(%rbp), %rdi
callq 0x7708
movl $0x1, -0x1a4(%rbp)
jmp 0x7b845
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x7708
jmp 0x7b867
movb $0x1, -0x1ca(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x318(%rbp)
leaq -0x1c9(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x7650
movq -0x310(%rbp), %rdx
leaq 0xc73b7(%rip), %rsi     # 0x142926
leaq -0x1c8(%rbp), %rdi
callq 0x7520
jmp 0x7b57d
movq -0x318(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x9c50
jmp 0x7b592
movq -0x318(%rbp), %rdi
movb $0x0, -0x1ca(%rbp)
leaq 0x132831(%rip), %rsi    # 0x1addd8
leaq -0x7191e(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x7b885
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x7b5ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x7708
leaq -0x1c9(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x1ca(%rbp)
jne 0x7b601
jmp 0x7b60d
movq -0x318(%rbp), %rdi
callq 0x72c0
jmp 0x7b867
movq -0x250(%rbp), %rax
addq $0x1d8, %rax            # imm = 0x1D8
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x30f70
movq %rax, -0x320(%rbp)
jmp 0x7b63b
movq -0x320(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x30fa0
movq %rax, -0x328(%rbp)
jmp 0x7b65e
movq -0x328(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1f8(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x1f4(%rbp)
movq -0x1e8(%rbp), %rdi
movq -0x1f0(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
callq 0x7ba10
movq %rax, -0x330(%rbp)
jmp 0x7b6a1
movq -0x250(%rbp), %rdi
movq -0x330(%rbp), %rax
movq %rax, -0x1e0(%rbp)
addq $0x1d8, %rdi            # imm = 0x1D8
callq 0x30fa0
movq %rax, -0x338(%rbp)
jmp 0x7b6cb
movq -0x338(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x32310
testb $0x1, %al
jne 0x7b6f2
jmp 0x7b76c
leaq -0x1e0(%rbp), %rdi
callq 0xa37c0
movq -0x250(%rbp), %rsi
movl (%rax), %edx
leaq -0x220(%rbp), %rdi
callq 0x71b50
jmp 0x7b715
movq -0x260(%rbp), %rdi
leaq -0x220(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0xa1530
jmp 0x7b72e
leaq -0x220(%rbp), %rdi
callq 0x7708
movl $0x1, -0x1a4(%rbp)
jmp 0x7b845
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x7708
jmp 0x7b867
movb $0x1, -0x242(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x348(%rbp)
leaq -0x241(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x7650
movq -0x340(%rbp), %rdx
leaq 0xc71fb(%rip), %rsi     # 0x1429a0
leaq -0x240(%rbp), %rdi
callq 0x7520
jmp 0x7b7b3
movq -0x348(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x9c50
jmp 0x7b7c8
movq -0x348(%rbp), %rdi
movb $0x0, -0x242(%rbp)
leaq 0x1325fb(%rip), %rsi    # 0x1addd8
leaq -0x71b54(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x7b885
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x7b820
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x7708
leaq -0x241(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x242(%rbp)
jne 0x7b837
jmp 0x7b843
movq -0x348(%rbp), %rdi
callq 0x72c0
jmp 0x7b867
leaq -0x58(%rbp), %rdi
callq 0x7708
leaq -0x38(%rbp), %rdi
callq 0x7708
movq -0x258(%rbp), %rax
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x7708
leaq -0x38(%rbp), %rdi
callq 0x7708
movq -0x88(%rbp), %rdi
callq 0x7640
nopw %cs:(%rax,%rax)