// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::declare_temporary[abi:cxx11](unsigned int, unsigned int)
string CompilerGLSL::declare_temporary(uint32_t result_type, uint32_t result_id)
{
	auto &type = get<SPIRType>(result_type);
	auto flags = ir.meta[result_id].decoration.decoration_flags;

	// If we're declaring temporaries inside continue blocks,
	// we must declare the temporary in the loop header so that the continue block can avoid declaring new variables.
	if (current_continue_block && !hoisted_temporaries.count(result_id))
	{
		auto &header = get<SPIRBlock>(current_continue_block->loop_dominator);
		if (find_if(begin(header.declare_temporary), end(header.declare_temporary),
		            [result_type, result_id](const pair<uint32_t, uint32_t> &tmp) {
			            return tmp.first == result_type && tmp.second == result_id;
		            }) == end(header.declare_temporary))
		{
			header.declare_temporary.emplace_back(result_type, result_id);
			hoisted_temporaries.insert(result_id);
			force_recompile = true;
		}

		return join(to_name(result_id), " = ");
	}
	else if (hoisted_temporaries.count(result_id))
	{
		// The temporary has already been declared earlier, so just "declare" the temporary by writing to it.
		return join(to_name(result_id), " = ");
	}
	else
	{
		// The result_id has not been made into an expression yet, so use flags interface.
		add_local_variable_name(result_id);
		return join(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(result_id)), " = ");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x158(%rbp)
movq %rdi, %rax
movq %rax, -0x150(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x148(%rbp)
movl -0x14(%rbp), %esi
callq 0xea90
movq -0x148(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x8, %rdi
addq $0x30, %rdi
movl -0x18(%rbp), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rsi
addq $0x60, %rsi
leaq -0x60(%rbp), %rdi
callq 0xef10
movq -0x148(%rbp), %rax
cmpq $0x0, 0x430(%rax)
je 0x7821c
movq -0x148(%rbp), %rdi
addq $0x298, %rdi            # imm = 0x298
leaq -0x18(%rbp), %rsi
callq 0x13520
movq %rax, -0x160(%rbp)
jmp 0x7802f
movq -0x160(%rbp), %rax
cmpq $0x0, %rax
jne 0x7821c
movq -0x148(%rbp), %rdi
movq 0x430(%rdi), %rax
movl 0xb4(%rax), %esi
callq 0x87d0
movq %rax, -0x168(%rbp)
jmp 0x78062
movq -0x168(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
addq $0x68, %rdi
callq 0xa23a0
movq %rax, -0x170(%rbp)
jmp 0x78083
movq -0x170(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rdi
addq $0x68, %rdi
callq 0xa23d0
movq %rax, -0x178(%rbp)
jmp 0x780a7
movq -0x178(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x78400
movq %rax, -0x180(%rbp)
jmp 0x780ea
movq -0x180(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
addq $0x68, %rdi
callq 0xa23d0
movq %rax, -0x188(%rbp)
jmp 0x7810b
movq -0x188(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xa2360
testb $0x1, %al
jne 0x7812f
jmp 0x781a7
movq -0x78(%rbp), %rdi
addq $0x68, %rdi
leaq -0x14(%rbp), %rsi
leaq -0x18(%rbp), %rdx
callq 0xa2400
jmp 0x78146
movq -0x148(%rbp), %rdi
addq $0x298, %rdi            # imm = 0x298
leaq -0x18(%rbp), %rsi
callq 0x2e890
movb %dl, -0x191(%rbp)
movq %rax, -0x190(%rbp)
jmp 0x7816c
movq -0x148(%rbp), %rax
movb -0x191(%rbp), %cl
movq -0x190(%rbp), %rdx
movq %rdx, -0xb0(%rbp)
movb %cl, -0xa8(%rbp)
movb $0x1, 0x1d0(%rax)
jmp 0x781a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x783e7
movq -0x148(%rbp), %rsi
movl -0x18(%rbp), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0xd0(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x781c8
movq -0x158(%rbp), %rdi
leaq 0xd0e39(%rip), %rdx     # 0x14900f
leaq -0xd0(%rbp), %rsi
callq 0xa2480
jmp 0x781e4
leaq -0xd0(%rbp), %rdi
callq 0x7708
movl $0x1, -0xd4(%rbp)
jmp 0x783ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x7708
jmp 0x783e7
movq -0x148(%rbp), %rdi
addq $0x298, %rdi            # imm = 0x298
leaq -0x18(%rbp), %rsi
callq 0x13520
movq %rax, -0x1a0(%rbp)
jmp 0x7823c
movq -0x1a0(%rbp), %rax
cmpq $0x0, %rax
je 0x782be
movq -0x148(%rbp), %rsi
movl -0x18(%rbp), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0xf8(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x7826a
movq -0x158(%rbp), %rdi
leaq 0xd0d97(%rip), %rdx     # 0x14900f
leaq -0xf8(%rbp), %rsi
callq 0xa2480
jmp 0x78286
leaq -0xf8(%rbp), %rdi
callq 0x7708
movl $0x1, -0xd4(%rbp)
jmp 0x783ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x7708
jmp 0x783e7
movq -0x148(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x78460
jmp 0x782cf
movq -0x148(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x61830
movq %rax, -0x1a8(%rbp)
jmp 0x782ec
movq -0x148(%rbp), %rsi
movq -0x1a8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl -0x18(%rbp), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x140(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x78326
movq -0x1b0(%rbp), %rdx
movq -0x148(%rbp), %rsi
movq (%rsi), %rax
movq 0xc8(%rax), %rax
leaq -0x120(%rbp), %rdi
leaq -0x140(%rbp), %rcx
xorl %r8d, %r8d
callq *%rax
jmp 0x78353
movq -0x158(%rbp), %rdi
leaq 0xd0cae(%rip), %rcx     # 0x14900f
leaq -0x100(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0xa2530
jmp 0x78376
leaq -0x120(%rbp), %rdi
callq 0x7708
leaq -0x140(%rbp), %rdi
callq 0x7708
movl $0x1, -0xd4(%rbp)
jmp 0x783ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x783c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x7708
leaq -0x140(%rbp), %rdi
callq 0x7708
jmp 0x783e7
leaq -0x60(%rbp), %rdi
callq 0xf250
movq -0x150(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0xf250
movq -0x68(%rbp), %rdi
callq 0x7640
nopl (%rax)