// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::CombinedImageSamplerHandler::register_combined_image_sampler(spirv_cross::SPIRFunction&, unsigned int, unsigned int, bool)
void Compiler::CombinedImageSamplerHandler::register_combined_image_sampler(SPIRFunction &caller, uint32_t image_id,
                                                                            uint32_t sampler_id, bool depth)
{
	// We now have a texture ID and a sampler ID which will either be found as a global
	// or a parameter in our own function. If both are global, they will not need a parameter,
	// otherwise, add it to our list.
	SPIRFunction::CombinedImageSamplerParameter param = {
		0u, image_id, sampler_id, true, true, depth,
	};

	auto texture_itr = find_if(begin(caller.arguments), end(caller.arguments),
	                           [image_id](const SPIRFunction::Parameter &p) { return p.id == image_id; });
	auto sampler_itr = find_if(begin(caller.arguments), end(caller.arguments),
	                           [sampler_id](const SPIRFunction::Parameter &p) { return p.id == sampler_id; });

	if (texture_itr != end(caller.arguments))
	{
		param.global_image = false;
		param.image_id = uint32_t(texture_itr - begin(caller.arguments));
	}

	if (sampler_itr != end(caller.arguments))
	{
		param.global_sampler = false;
		param.sampler_id = uint32_t(sampler_itr - begin(caller.arguments));
	}

	if (param.global_image && param.global_sampler)
		return;

	auto itr = find_if(begin(caller.combined_parameters), end(caller.combined_parameters),
	                   [&param](const SPIRFunction::CombinedImageSamplerParameter &p) {
		                   return param.image_id == p.image_id && param.sampler_id == p.sampler_id &&
		                          param.global_image == p.global_image && param.global_sampler == p.global_sampler;
	                   });

	if (itr == end(caller.combined_parameters))
	{
		uint32_t id = compiler.ir.increase_bound_by(3);
		auto type_id = id + 0;
		auto ptr_type_id = id + 1;
		auto combined_id = id + 2;
		auto &base = compiler.expression_type(image_id);
		auto &type = compiler.set<SPIRType>(type_id);
		auto &ptr_type = compiler.set<SPIRType>(ptr_type_id);

		type = base;
		type.self = type_id;
		type.basetype = SPIRType::SampledImage;
		type.pointer = false;
		type.storage = StorageClassGeneric;
		type.image.depth = depth;

		ptr_type = type;
		ptr_type.pointer = true;
		ptr_type.storage = StorageClassUniformConstant;

		// Build new variable.
		compiler.set<SPIRVariable>(combined_id, ptr_type_id, StorageClassFunction, 0);

		// Inherit RelaxedPrecision (and potentially other useful flags if deemed relevant).
		auto &new_flags = compiler.ir.meta[combined_id].decoration.decoration_flags;
		auto &old_flags = compiler.ir.meta[sampler_id].decoration.decoration_flags;
		new_flags.reset();
		if (old_flags.get(DecorationRelaxedPrecision))
			new_flags.set(DecorationRelaxedPrecision);

		param.id = combined_id;

		compiler.set_name(combined_id,
		                  join("SPIRV_Cross_Combined", compiler.to_name(image_id), compiler.to_name(sampler_id)));

		caller.combined_parameters.push_back(param);
		caller.shadow_arguments.push_back({ ptr_type_id, combined_id, 0u, 0u, true });
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %r15d
movq %rdi, 0x30(%rsp)
andl $0x0, 0x1c(%rsp)
movl %edx, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
movw $0x101, 0x28(%rsp)      # imm = 0x101
movl %r8d, 0x2c(%rsp)
movb %r8b, 0x2a(%rsp)
movq 0x18(%rsi), %r8
movq 0x20(%rsi), %r10
movq %r10, %r14
subq %r8, %r14
pushq $0x14
popq %r9
movq %r14, %rax
cqto
idivq %r9
movq %rax, %rbx
sarq $0x2, %rbx
movq %r14, %rax
movq %r8, %r11
movq %rbx, %rdx
testq %rdx, %rdx
jle 0x13acd
cmpl %r15d, 0x4(%r11)
je 0x13b15
cmpl %r15d, 0x18(%r11)
je 0x13b05
cmpl %r15d, 0x2c(%r11)
je 0x13b0b
cmpl %r15d, 0x40(%r11)
je 0x13b11
addq $0x50, %r11
decq %rdx
addq $-0x50, %rax
jmp 0x13aa3
cqto
idivq %r9
cmpq $0x1, %rax
je 0x13afb
cmpq $0x2, %rax
je 0x13af1
movq %r10, %rdi
cmpq $0x3, %rax
jne 0x13b18
cmpl %r15d, 0x4(%r11)
je 0x13b15
addq $0x14, %r11
cmpl %r15d, 0x4(%r11)
je 0x13b15
addq $0x14, %r11
cmpl %r15d, 0x4(%r11)
cmovneq %r10, %r11
jmp 0x13b15
addq $0x14, %r11
jmp 0x13b15
addq $0x28, %r11
jmp 0x13b15
addq $0x3c, %r11
movq %r11, %rdi
movq %r8, %r11
testq %rbx, %rbx
jle 0x13b45
cmpl %ecx, 0x4(%r11)
je 0x13b90
cmpl %ecx, 0x18(%r11)
je 0x13b80
cmpl %ecx, 0x2c(%r11)
je 0x13b86
cmpl %ecx, 0x40(%r11)
je 0x13b8c
addq $0x50, %r11
decq %rbx
addq $-0x50, %r14
jmp 0x13b1b
movq %r14, %rax
cqto
idivq %r9
cmpq $0x1, %rax
je 0x13b76
cmpq $0x2, %rax
je 0x13b6c
movq %r10, %rbx
cmpq $0x3, %rax
jne 0x13b93
cmpl %ecx, 0x4(%r11)
je 0x13b90
addq $0x14, %r11
cmpl %ecx, 0x4(%r11)
je 0x13b90
addq $0x14, %r11
cmpl %ecx, 0x4(%r11)
cmovneq %r10, %r11
jmp 0x13b90
addq $0x14, %r11
jmp 0x13b90
addq $0x28, %r11
jmp 0x13b90
addq $0x3c, %r11
movq %r11, %rbx
movl %ecx, 0x14(%rsp)
cmpq %r10, %rdi
je 0x13bb7
movb $0x0, 0x28(%rsp)
subq %r8, %rdi
movq %rdi, %rax
cqto
idivq %r9
movl %eax, 0x20(%rsp)
cmpq %r10, %rbx
jne 0x13bc0
jmp 0x13bd4
cmpq %r10, %rbx
je 0x13e77
movb $0x0, 0x29(%rsp)
subq %r8, %rbx
movq %rbx, %rax
cqto
idivq %r9
movl %eax, 0x24(%rsp)
leaq 0x80(%rsi), %rax
movq %rax, 0x58(%rsp)
movq 0x80(%rsi), %r14
movq %rsi, 0x60(%rsp)
movq 0x88(%rsi), %rbp
leaq 0x1c(%rsp), %rax
leaq 0x38(%rsp), %r12
movq %rax, (%r12)
movq %rbp, 0x8(%rsp)
subq %r14, %rbp
movq %rbp, %rbx
sarq $0x6, %rbx
testq %rbx, %rbx
jle 0x13c6a
movq %r12, %rdi
movq %r14, %rsi
callq 0x16cfe
testb %al, %al
jne 0x13c9d
leaq 0x10(%r14), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x16cfe
testb %al, %al
jne 0x13ca0
leaq 0x20(%r14), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x16cfe
testb %al, %al
jne 0x13ca0
leaq 0x30(%r14), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x16cfe
testb %al, %al
jne 0x13ca0
addq $0x40, %r14
decq %rbx
addq $-0x40, %rbp
jmp 0x13c10
sarq $0x4, %rbp
cmpq $0x1, %rbp
je 0x13e89
cmpq $0x2, %rbp
je 0x13e94
cmpq $0x3, %rbp
jne 0x13cae
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x16cfe
testb %al, %al
je 0x13e90
movq %r14, %r13
movq 0x8(%rsp), %r12
cmpq %r12, %r13
jne 0x13e77
movq 0x30(%rsp), %rbp
movq 0x8(%rbp), %rdi
addq $0x8, %rdi
pushq $0x3
popq %rsi
callq 0x202bc
movl %eax, %r14d
leal 0x1(%r14), %r12d
leaq 0x18(%rsp), %rax
movl %r12d, (%rax)
leal 0x2(%r14), %eax
movq %rax, 0x8(%rsp)
movq 0x8(%rbp), %rdi
movl %r15d, %esi
callq 0x104b0
movq %rax, %rbx
movq 0x8(%rbp), %rdi
movl %r14d, %esi
callq 0x17718
movq %rax, %r13
movq 0x8(%rbp), %rdi
movl %r12d, %esi
callq 0x17718
movq %rax, %r12
movq %r13, %rdi
movq %rbx, %rsi
callq 0x173b0
movl %r14d, 0x8(%r13)
movl $0xe, 0xc(%r13)
movb $0x0, 0x60(%r13)
movl $0x8, 0x64(%r13)
movl 0x2c(%rsp), %eax
movb %al, 0x88(%r13)
movq %r12, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %r13
callq 0x173b0
movb $0x1, 0x60(%r12)
andl $0x0, 0x64(%r12)
movq 0x8(%rbp), %rdi
leaq 0x38(%rsp), %rcx
movl $0x7, (%rcx)
leaq 0x68(%rsp), %r8
andl $0x0, (%r8)
movl %r13d, %esi
leaq 0x18(%rsp), %rdx
callq 0x17734
movq 0x8(%rbp), %rax
movq 0x38(%rax), %rbx
imulq $0x148, %r13, %rax      # imm = 0x148
leaq (%rbx,%rax), %r14
addq $0x60, %r14
movl 0x14(%rsp), %eax
imulq $0x148, %rax, %r12      # imm = 0x148
movq %r14, %rdi
callq 0x17770
testb $0x1, 0x60(%rbx,%r12)
je 0x13dae
orb $0x1, (%r14)
movl %r13d, 0x1c(%rsp)
movq 0x30(%rsp), %r12
movq 0x8(%r12), %r14
movq (%r14), %rax
leaq 0x68(%rsp), %rdi
pushq $0x1
popq %rbx
movq %r14, %rsi
movl %r15d, %edx
movl %ebx, %ecx
callq *0x38(%rax)
movq 0x8(%r12), %rsi
movq (%rsi), %rax
leaq 0x88(%rsp), %rdi
movl 0x14(%rsp), %edx
movl %ebx, %ecx
callq *0x38(%rax)
leaq 0x7c12d(%rip), %rsi     # 0x8ff20
leaq 0x38(%rsp), %rdi
leaq 0x68(%rsp), %rdx
leaq 0x88(%rsp), %rcx
callq 0x1777d
addq $0x8, %r14
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movl %r13d, %esi
callq 0x1f57e
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x6548
leaq 0x88(%rsp), %rdi
callq 0x6548
leaq 0x68(%rsp), %rdi
callq 0x6548
leaq 0x1c(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0x177f8
movq 0x60(%rsp), %rdi
addq $0x30, %rdi
movl 0x18(%rsp), %eax
movl %eax, (%rbx)
movl %r13d, 0x4(%rbx)
andq $0x0, 0x8(%rbx)
movb $0x1, 0x10(%rbx)
leaq 0x38(%rsp), %rsi
callq 0x1b17e
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %r12
jmp 0x13eae
addq $0x10, %r14
movq 0x8(%rsp), %r12
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x16cfe
testb %al, %al
jne 0x13ec1
addq $0x10, %r14
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x16cfe
testb %al, %al
cmoveq %r12, %r14
movq %r14, %r13
jmp 0x13ca5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x6548
jmp 0x13edb
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x6548
jmp 0x13eed
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0
nop