// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl 0x20(%rsi), %esi
callq 0x78fe
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1544a
movl %eax, %ebp
testl $0xfffffffd, %r15d      # imm = 0xFFFFFFFD
je 0x4fe5a
cmpl $0x1, %r15d
jne 0x500bf
movl %ebp, 0xc(%rsp)
movl 0x18(%r14), %esi
movq %rbx, %rdi
callq 0x78fe
movq %rax, %r12
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
callq 0x50400
movl 0x750(%rbx), %eax
movl %eax, 0x34(%rsp)
movq %r12, 0x410(%rbx)
movq 0x38(%r12), %r13
movq 0x40(%r12), %r15
cmpq %r15, %r13
je 0x4ff6a
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x48(%rax)
addq $0xc, %r13
jmp 0x4fe3f
movl 0x750(%rbx), %eax
movl %eax, 0xc(%rsp)
movq %r14, 0x410(%rbx)
movq 0x38(%r14), %r12
movq 0x40(%r14), %r13
cmpq %r13, %r12
je 0x4fe8a
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x48(%rax)
addq $0xc, %r12
jmp 0x4fe73
movq $0x0, 0x410(%rbx)
leaq 0x228(%rbx), %rdi
leaq 0x28(%r14), %rcx
movl 0x28(%r14), %r8d
xorl %r12d, %r12d
movq %r8, %rax
xorl %edx, %edx
divq 0x230(%rbx)
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
callq 0x1f088
testq %rax, %rax
je 0x4fece
cmpq $0x0, (%rax)
setne %r12b
testb %r12b, %r12b
jne 0x5009b
movl 0xc(%rsp), %eax
cmpl 0x750(%rbx), %eax
jne 0x5009b
cmpl $0x2, %ebp
je 0x500c6
cmpl $0x1, %ebp
jne 0x50265
movq %rbx, %rdi
movq %r14, %rsi
callq 0x50400
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4f786
movl 0x28(%r14), %edx
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x345e6
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
cmpl $0x2, %r15d
jne 0x501a9
leaq 0x6bad5(%rip), %rsi     # 0xbba1a
leaq 0x6bad4(%rip), %rcx     # 0xbba20
leaq 0x6bad0(%rip), %r9      # 0xbba23
leaq 0x10(%rsp), %rdx
leaq 0x38(%rsp), %r8
movq %rbx, %rdi
callq 0x599b4
jmp 0x50209
movq $0x0, 0x410(%rbx)
leaq 0x228(%rbx), %rdi
addq $0x28, %r12
movq %rbp, %r15
movl 0x28(%rbp), %ecx
xorl %r13d, %r13d
movq %rcx, %rax
xorl %edx, %edx
divq 0x230(%rbx)
movq %rdx, %rsi
movq %r12, %rdx
callq 0x1f088
testq %rax, %rax
je 0x4ffad
cmpq $0x0, (%rax)
setne %r13b
movl 0xc(%rsp), %ebp
testb %r13b, %r13b
jne 0x5009b
movl 0x34(%rsp), %eax
cmpl 0x750(%rbx), %eax
jne 0x5009b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4f3d2
cmpl $0x2, %ebp
je 0x5011d
cmpl $0x1, %ebp
jne 0x502cb
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4f786
movl (%r12), %edx
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x345e6
movl 0x20(%r14), %edx
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4f510
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
leaq 0x6b9f3(%rip), %rax     # 0xbba25
leaq 0x6b9e1(%rip), %rsi     # 0xbba1a
leaq 0x6b9e0(%rip), %rcx     # 0xbba20
leaq 0x10(%rsp), %rdx
leaq 0x38(%rsp), %r8
movq %rbx, %rdi
movq %rcx, %r9
pushq %rax
pushq %r12
callq 0x59878
addq $0x10, %rsp
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50077
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50164
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x50164
movb $0x1, %al
movb %al, 0xb0(%r14)
movb %al, 0x1d0(%rbx)
leaq 0x6bb36(%rip), %rsi     # 0xbbbe7
movq %rbx, %rdi
callq 0x5a5fc
incl 0x638(%rbx)
xorl %eax, %eax
jmp 0x50256
movq %rbx, %rdi
movq %r14, %rsi
callq 0x50400
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f6d8
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
movl 0x28(%r14), %edx
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x345e6
leaq 0x6b921(%rip), %rsi     # 0xbba27
leaq 0x6b918(%rip), %rcx     # 0xbba25
movq %rbx, %rdi
movq %r14, %rdx
callq 0x59b6c
jmp 0x50224
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f6d8
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x158(%rax)
movl (%r12), %edx
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x345e6
leaq 0x6b8d5(%rip), %rsi     # 0xbba27
leaq 0x6b8cc(%rip), %rcx     # 0xbba25
movq %rbx, %rdi
movq %r14, %rdx
callq 0x59b6c
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5017f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x6ba61(%rip), %rsi     # 0xbbbe7
movq %rbx, %rdi
callq 0x5a5fc
incl 0x638(%rbx)
movl 0x8(%r15), %esi
movl 0x2c(%r15), %edx
movq %rbx, %rdi
callq 0x4ef9e
jmp 0x50254
movl 0x20(%r14), %edx
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4f510
leaq 0x6b861(%rip), %rax     # 0xbba25
leaq 0x6b84f(%rip), %rsi     # 0xbba1a
leaq 0x6b84e(%rip), %rcx     # 0xbba20
leaq 0x10(%rsp), %rdx
leaq 0x38(%rsp), %r8
movq %rbx, %rdi
movq %rcx, %r9
pushq %rax
pushq %r14
callq 0x59878
addq $0x10, %rsp
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50209
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50224
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5023f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x6b9a1(%rip), %rsi     # 0xbbbe7
movq %rbx, %rdi
callq 0x5a5fc
incl 0x638(%rbx)
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x6b7ad(%rip), %rsi     # 0xbba2f
leaq 0x6b7e1(%rip), %rdx     # 0xbba6a
leaq 0x10(%rsp), %rdi
callq 0x7c64
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xacaee(%rip), %rax     # 0xfcd98
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xacac6(%rip), %rsi     # 0xfcd80
movq 0xadd17(%rip), %rdx     # 0xfdfd8
movq %r14, %rdi
callq 0x6470
jmp 0x5032f
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x6b747(%rip), %rsi     # 0xbba2f
leaq 0x6b77b(%rip), %rdx     # 0xbba6a
leaq 0x10(%rsp), %rdi
callq 0x7c64
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xaca88(%rip), %rax     # 0xfcd98
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xaca60(%rip), %rsi     # 0xfcd80
movq 0xadcb1(%rip), %rdx     # 0xfdfd8
movq %r14, %rdi
callq 0x6470
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x50351
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x50351
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x503f7
jmp 0x50387
jmp 0x503a3
jmp 0x5039e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x50382
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x50382
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x503f7
movq %r14, %rdi
callq 0x6200
jmp 0x503f7
jmp 0x5039e
jmp 0x50399
jmp 0x50399
jmp 0x50399
movq %rax, %rbx
jmp 0x503dc
movq %rax, %rbx
jmp 0x503c1
movq %rax, %rbx
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x503c1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x503dc
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x503f7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop