// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::emit_hoisted_temporaries(std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>&)
void CompilerGLSL::emit_hoisted_temporaries(vector<pair<uint32_t, uint32_t>> &temporaries)
{
	// If we need to force temporaries for certain IDs due to continue blocks, do it before starting loop header.
	// Need to sort these to ensure that reference output is stable.
	sort(begin(temporaries), end(temporaries),
	     [](const pair<uint32_t, uint32_t> &a, const pair<uint32_t, uint32_t> &b) { return a.second < b.second; });

	for (auto &tmp : temporaries)
	{
		add_local_variable_name(tmp.second);
		auto flags = ir.meta[tmp.second].decoration.decoration_flags;
		auto &type = get<SPIRType>(tmp.first);
		statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(tmp.second)), ";");

		hoisted_temporaries.insert(tmp.second);
		forced_temporaries.insert(tmp.second);

		// The temporary might be read from before it's assigned, set up the expression now.
		set<SPIRExpression>(tmp.second, to_name(tmp.second), tmp.first, true);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x10(%rbp), %rdi
callq 0xa23a0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0xa23d0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x9bc00
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x51450
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x512a0
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa8de0
testb $0x1, %al
jne 0x9b91d
jmp 0x9bbe4
leaq -0x38(%rbp), %rdi
callq 0xa8e20
movq -0x138(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x78460
movq -0x138(%rbp), %rdi
addq $0x38, %rdi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rsi
addq $0x60, %rsi
leaq -0x88(%rbp), %rdi
callq 0xef10
movq -0x138(%rbp), %rdi
movq -0x48(%rbp), %rax
movl (%rax), %esi
callq 0xea90
movq %rax, -0x140(%rbp)
jmp 0x9b984
movq -0x138(%rbp), %rdi
movq -0x140(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x61830
movq %rax, -0x148(%rbp)
jmp 0x9b9b5
movq -0x138(%rbp), %rsi
movq -0x148(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0xe8(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x9b9f6
movq -0x150(%rbp), %rdx
movq -0x138(%rbp), %rsi
movq (%rsi), %rax
movq 0xc8(%rax), %rax
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rcx
xorl %r8d, %r8d
callq *%rax
jmp 0x9ba23
movq -0x138(%rbp), %rdi
leaq 0xad675(%rip), %rcx     # 0x1490a6
leaq -0xa8(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0xa37e0
jmp 0x9ba46
leaq -0xc8(%rbp), %rdi
callq 0x7708
leaq -0xe8(%rbp), %rdi
callq 0x7708
movq -0x138(%rbp), %rdi
addq $0x298, %rdi            # imm = 0x298
movq -0x48(%rbp), %rsi
addq $0x4, %rsi
callq 0x2e890
movb %dl, -0x159(%rbp)
movq %rax, -0x158(%rbp)
jmp 0x9ba88
movq -0x138(%rbp), %rdi
movb -0x159(%rbp), %al
movq -0x158(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
movb %al, -0xf0(%rbp)
addq $0x228, %rdi            # imm = 0x228
movq -0x48(%rbp), %rsi
addq $0x4, %rsi
callq 0x2e890
movb %dl, -0x169(%rbp)
movq %rax, -0x168(%rbp)
jmp 0x9bacc
movq -0x138(%rbp), %rsi
movb -0x169(%rbp), %al
movq -0x168(%rbp), %rcx
movq %rcx, -0x108(%rbp)
movb %al, -0x100(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %edx
movl %edx, -0x170(%rbp)
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x128(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x9bb11
movl -0x170(%rbp), %esi
movq -0x138(%rbp), %rdi
movq -0x48(%rbp), %rcx
movb $0x1, -0x129(%rbp)
leaq -0x128(%rbp), %rdx
leaq -0x129(%rbp), %r8
callq 0xa2780
jmp 0x9bb3e
leaq -0x128(%rbp), %rdi
callq 0x7708
leaq -0x88(%rbp), %rdi
callq 0xf250
leaq -0x38(%rbp), %rdi
callq 0xa8e40
jmp 0x9b907
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x9bbd6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x9bbaa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7708
leaq -0xe8(%rbp), %rdi
callq 0x7708
jmp 0x9bbd6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x7708
leaq -0x88(%rbp), %rdi
callq 0xf250
jmp 0x9bbed
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0x7640
nopl (%rax)