// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::attempt_emit_loop_header(spirv_cross::SPIRBlock&, spirv_cross::SPIRBlock::Method)
bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method)
{
	SPIRBlock::ContinueBlockType continue_type = continue_block_type(get<SPIRBlock>(block.continue_block));

	if (method == SPIRBlock::MergeToSelectForLoop || method == SPIRBlock::MergeToSelectContinueForLoop)
	{
		uint32_t current_count = statement_count;
		// If we're trying to create a true for loop,
		// we need to make sure that all opcodes before branch statement do not actually emit any code.
		// We can then take the condition expression and create a for (; cond ; ) { body; } structure instead.
		emit_block_instructions(block);

		bool condition_is_temporary = forced_temporaries.find(block.condition) == end(forced_temporaries);

		// This can work! We only did trivial things which could be forwarded in block body!
		if (current_count == statement_count && condition_is_temporary)
		{
			switch (continue_type)
			{
			case SPIRBlock::ForLoop:
			{
				// This block may be a dominating block, so make sure we flush undeclared variables before building the for loop header.
				flush_undeclared_variables(block);

				// Important that we do this in this order because
				// emitting the continue block can invalidate the condition expression.
				auto initializer = emit_for_loop_initializers(block);
				auto condition = to_expression(block.condition);
				emit_block_hints(block);
				if (method != SPIRBlock::MergeToSelectContinueForLoop)
				{
					auto continue_block = emit_continue_block(block.continue_block);
					statement("for (", initializer, "; ", condition, "; ", continue_block, ")");
				}
				else
					statement("for (", initializer, "; ", condition, "; )");
				break;
			}

			case SPIRBlock::WhileLoop:
				// This block may be a dominating block, so make sure we flush undeclared variables before building the while loop header.
				flush_undeclared_variables(block);
				emit_while_loop_initializers(block);
				emit_block_hints(block);
				statement("while (", to_expression(block.condition), ")");
				break;

			default:
				SPIRV_CROSS_THROW("For/while loop detected, but need while/for loop semantics.");
			}

			begin_scope();
			return true;
		}
		else
		{
			block.disable_block_optimization = true;
			force_recompile = true;
			begin_scope(); // We'll see an end_scope() later.
			return false;
		}
	}
	else if (method == SPIRBlock::MergeToDirectForLoop)
	{
		auto &child = get<SPIRBlock>(block.next_block);

		// This block may be a dominating block, so make sure we flush undeclared variables before building the for loop header.
		flush_undeclared_variables(child);

		uint32_t current_count = statement_count;

		// If we're trying to create a true for loop,
		// we need to make sure that all opcodes before branch statement do not actually emit any code.
		// We can then take the condition expression and create a for (; cond ; ) { body; } structure instead.
		emit_block_instructions(child);

		bool condition_is_temporary = forced_temporaries.find(child.condition) == end(forced_temporaries);

		if (current_count == statement_count && condition_is_temporary)
		{
			propagate_loop_dominators(child);

			switch (continue_type)
			{
			case SPIRBlock::ForLoop:
			{
				// Important that we do this in this order because
				// emitting the continue block can invalidate the condition expression.
				auto initializer = emit_for_loop_initializers(block);
				auto condition = to_expression(child.condition);
				auto continue_block = emit_continue_block(block.continue_block);
				emit_block_hints(block);
				statement("for (", initializer, "; ", condition, "; ", continue_block, ")");
				break;
			}

			case SPIRBlock::WhileLoop:
				emit_while_loop_initializers(block);
				emit_block_hints(block);
				statement("while (", to_expression(child.condition), ")");
				break;

			default:
				SPIRV_CROSS_THROW("For/while loop detected, but need while/for loop semantics.");
			}

			begin_scope();
			branch(child.self, child.true_block);
			return true;
		}
		else
		{
			block.disable_block_optimization = true;
			force_recompile = true;
			begin_scope(); // We'll see an end_scope() later.
			return false;
		}
	}
	else
		return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl 0x20(%rsi), %esi
callq 0x7870
movq %rbx, %rdi
movq %rax, %rsi
callq 0x15288
movl %eax, %ebp
testl $0xfffffffd, %r15d      # imm = 0xFFFFFFFD
je 0x4f6ab
cmpl $0x1, %r15d
jne 0x4f8b6
movl 0x18(%r14), %esi
movq %rbx, %rdi
callq 0x7870
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4fbe0
movl 0x750(%rbx), %eax
movl %eax, 0x24(%rsp)
movq %r15, 0x410(%rbx)
movq 0x38(%r15), %r12
movq 0x40(%r15), %r13
cmpq %r13, %r12
je 0x4f78e
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x48(%rax)
addq $0xc, %r12
jmp 0x4f690
movl 0x750(%rbx), %eax
movl %eax, 0x24(%rsp)
movq %r14, 0x410(%rbx)
movq 0x38(%r14), %r12
movq 0x40(%r14), %r13
cmpq %r13, %r12
je 0x4f6db
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x48(%rax)
addq $0xc, %r12
jmp 0x4f6c4
movq $0x0, 0x410(%rbx)
leaq 0x228(%rbx), %rdi
leaq 0x28(%r14), %rsi
callq 0x21122
testq %rax, %rax
jne 0x4f892
movl 0x24(%rsp), %eax
cmpl 0x750(%rbx), %eax
jne 0x4f892
cmpl $0x2, %ebp
je 0x4f8bd
cmpl $0x1, %ebp
jne 0x4fa56
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4fbe0
movq %rsp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4f000
movl 0x28(%r14), %edx
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x33f8a
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
cmpl $0x2, %r15d
jne 0x4f99c
leaq 0x6b29f(%rip), %rsi     # 0xbaa0a
leaq 0x6b29e(%rip), %rcx     # 0xbaa10
leaq 0x6b29a(%rip), %r9      # 0xbaa13
movq %rsp, %rdx
leaq 0x28(%rsp), %r8
movq %rbx, %rdi
callq 0x591ba
jmp 0x4f9fa
movq $0x0, 0x410(%rbx)
leaq 0x228(%rbx), %rdi
leaq 0x28(%r15), %r12
movq %r12, %rsi
callq 0x21122
testq %rax, %rax
jne 0x4f892
movl 0x24(%rsp), %eax
cmpl 0x750(%rbx), %eax
jne 0x4f892
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4ebfa
cmpl $0x2, %ebp
je 0x4f912
cmpl $0x1, %ebp
jne 0x4fab8
movq %rsp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4f000
movl (%r12), %edx
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x33f8a
movl 0x20(%r14), %edx
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4ed30
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
leaq 0x6b1ea(%rip), %rax     # 0xbaa15
leaq 0x6b1d8(%rip), %rsi     # 0xbaa0a
leaq 0x6b1d7(%rip), %rcx     # 0xbaa10
movq %rsp, %rdx
leaq 0x28(%rsp), %r8
movq %rbx, %rdi
movq %rcx, %r9
pushq %rax
pushq %r12
callq 0x5907e
addq $0x10, %rsp
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f86e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f957
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x4f957
movb $0x1, %al
movb %al, 0xb0(%r14)
movb %al, 0x1d0(%rbx)
leaq 0x6b32f(%rip), %rsi     # 0xbabd7
movq %rbx, %rdi
callq 0x59e02
incl 0x638(%rbx)
xorl %eax, %eax
jmp 0x4fa47
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4fbe0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ef52
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
movl 0x28(%r14), %edx
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x33f8a
leaq 0x6b11c(%rip), %rsi     # 0xbaa17
leaq 0x6b113(%rip), %rcx     # 0xbaa15
movq %rbx, %rdi
movq %r14, %rdx
callq 0x59372
jmp 0x4fa15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ef52
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
movl (%r12), %edx
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x33f8a
leaq 0x6b0d2(%rip), %rsi     # 0xbaa17
leaq 0x6b0c9(%rip), %rcx     # 0xbaa15
movq %rbx, %rdi
movq %r14, %rdx
callq 0x59372
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f972
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x6b25e(%rip), %rsi     # 0xbabd7
movq %rbx, %rdi
callq 0x59e02
incl 0x638(%rbx)
movl 0x8(%r15), %esi
movl 0x2c(%r15), %edx
movq %rbx, %rdi
callq 0x4e7dc
jmp 0x4fa45
movl 0x20(%r14), %edx
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4ed30
leaq 0x6b05e(%rip), %rax     # 0xbaa15
leaq 0x6b04c(%rip), %rsi     # 0xbaa0a
leaq 0x6b04b(%rip), %rcx     # 0xbaa10
movq %rsp, %rdx
leaq 0x28(%rsp), %r8
movq %rbx, %rdi
movq %rcx, %r9
pushq %rax
pushq %r14
callq 0x5907e
addq $0x10, %rsp
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f9fa
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4fa15
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4fa30
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x6b1a0(%rip), %rsi     # 0xbabd7
movq %rbx, %rdi
callq 0x59e02
incl 0x638(%rbx)
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x6afac(%rip), %rsi     # 0xbaa1f
leaq 0x6afe0(%rip), %rdx     # 0xbaa5a
movq %rsp, %rdi
callq 0x7be0
movb $0x1, %bpl
movq %rsp, %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xac331(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xac309(%rip), %rsi     # 0xfbdb0
movq 0xad52a(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
jmp 0x4fb18
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x6af4a(%rip), %rsi     # 0xbaa1f
leaq 0x6af7e(%rip), %rdx     # 0xbaa5a
movq %rsp, %rdi
callq 0x7be0
movb $0x1, %bpl
movq %rsp, %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xac2cf(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xac2a7(%rip), %rsi     # 0xfbdb0
movq 0xad4c8(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4fb31
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
je 0x4fbd8
jmp 0x4fb68
movq %rax, %rbx
jmp 0x4fb68
jmp 0x4fb84
jmp 0x4fb7f
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4fb5e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
jne 0x4fb68
jmp 0x4fbd8
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x4fbd8
jmp 0x4fb7f
jmp 0x4fb7a
jmp 0x4fb7a
jmp 0x4fb7a
movq %rax, %rbx
jmp 0x4fbbd
movq %rax, %rbx
jmp 0x4fba2
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4fba2
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4fbbd
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4fbd8
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0