// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::emit_for_loop_initializers[abi:cxx11](spirv_cross::SPIRBlock const&)
string CompilerGLSL::emit_for_loop_initializers(const SPIRBlock &block)
{
	if (block.loop_variables.empty())
		return "";

	bool same_types = for_loop_initializers_are_same_type(block);
	// We can only declare for loop initializers if all variables are of same type.
	// If we cannot do this, declare individual variables before the loop header.

	// We might have a loop variable candidate which was not assigned to for some reason.
	uint32_t missing_initializers = 0;
	for (auto &variable : block.loop_variables)
	{
		uint32_t expr = get<SPIRVariable>(variable).static_expression;

		// Sometimes loop variables are initialized with OpUndef, but we can just declare
		// a plain variable without initializer in this case.
		if (expr == 0 || ir.ids[expr].get_type() == TypeUndef)
			missing_initializers++;
	}

	if (block.loop_variables.size() == 1 && missing_initializers == 0)
	{
		return variable_decl(get<SPIRVariable>(block.loop_variables.front()));
	}
	else if (!same_types || missing_initializers == uint32_t(block.loop_variables.size()))
	{
		for (auto &loop_var : block.loop_variables)
			statement(variable_decl(get<SPIRVariable>(loop_var)), ";");
		return "";
	}
	else
	{
		// We have a mix of loop variables, either ones with a clear initializer, or ones without.
		// Separate the two streams.
		string expr;

		for (auto &loop_var : block.loop_variables)
		{
			uint32_t static_expr = get<SPIRVariable>(loop_var).static_expression;
			if (static_expr == 0 || ir.ids[static_expr].get_type() == TypeUndef)
			{
				statement(variable_decl(get<SPIRVariable>(loop_var)), ";");
			}
			else
			{
				if (expr.empty())
				{
					// For loop initializers are of the form <type id = value, id = value, id = value, etc ...
					auto &var = get<SPIRVariable>(loop_var);
					auto &type = get<SPIRType>(var.basetype);
					expr = join(to_qualifiers_glsl(var.self), type_to_glsl(type), " ");
				}
				else
					expr += ", ";

				auto &v = get<SPIRVariable>(loop_var);
				expr += join(to_name(loop_var), " = ", to_expression(v.static_expression));
			}
		}
		return expr;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq 0xd0(%rdx), %rax
cmpq 0xd8(%rdx), %rax
je 0x4f08d
movq %rdx, %r15
movq %rsi, %r14
movq %rbx, (%rsp)
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x4f490
movl %eax, %r12d
movq 0xd0(%r15), %rbp
movq 0xd8(%r15), %rbx
xorl %r13d, %r13d
cmpq %rbx, %rbp
je 0x4f0a8
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb3ca
movl 0x3c(%rax), %eax
testq %rax, %rax
je 0x4f071
movq 0x20(%r14), %rcx
shlq $0x4, %rax
cmpl $0xd, 0x8(%rcx,%rax)
jne 0x4f074
incl %r13d
addq $0x4, %rbp
cmpq %rbx, %rbp
jne 0x4f04f
movq 0xd0(%r15), %rbp
movq 0xd8(%r15), %rsi
jmp 0x4f0ab
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x65814(%rip), %rdx     # 0xb48af
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x7be0
jmp 0x4f0df
movq %rbp, %rsi
movq %rsi, %rax
subq %rbp, %rax
cmpq $0x4, %rax
sete %cl
testl %r13d, %r13d
sete %dl
testb %dl, %cl
je 0x4f0e7
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb3ca
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2c7ac
movq %rbx, %rax
jmp 0x4f3b5
shrq $0x2, %rax
cmpl %eax, %r13d
setne %al
testb %al, %r12b
movq %rsi, 0x70(%rsp)
je 0x4f338
movq (%rsp), %rcx
leaq 0x10(%rcx), %rax
movq %rax, 0x68(%rsp)
movq %rax, (%rcx)
movq $0x0, 0x8(%rcx)
movb $0x0, 0x10(%rcx)
cmpq %rsi, %rbp
je 0x4f3b1
leaq 0x18(%rsp), %r12
leaq 0x8(%rsp), %r15
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb3ca
movl 0x3c(%rax), %eax
testq %rax, %rax
je 0x4f150
movq 0x20(%r14), %rcx
shlq $0x4, %rax
cmpl $0xd, 0x8(%rcx,%rax)
jne 0x4f193
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb3ca
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2c7ac
movq %r14, %rdi
movq %r15, %rsi
leaq 0x6f97b(%rip), %rdx     # 0xbeaf1
callq 0xaa14
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f327
movq 0x18(%rsp), %rsi
jmp 0x4f31f
movq (%rsp), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x4f1af
leaq 0x6af06(%rip), %rsi     # 0xba0ab
callq 0x64e0
jmp 0x4f270
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb3ca
movq %rax, %r13
movl 0xc(%rax), %esi
movq %r14, %rdi
callq 0xa3ea
movq %rax, %r12
movl 0x8(%r13), %edx
movq (%r14), %rax
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq *0x128(%rax)
movq (%r14), %rax
leaq 0x48(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq *0x98(%rax)
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
movq %r13, %rdx
leaq 0x656a3(%rip), %rcx     # 0xb48ae
callq 0x58f26
leaq 0x18(%rsp), %r12
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x6310
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f238
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4f254
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4f270
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb3ca
movq %rax, %r12
movl (%rbp), %edx
movq (%r14), %rax
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movl 0x3c(%r12), %edx
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x33f8a
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x6f7a2(%rip), %rdx     # 0xbea5a
movq %r12, %rcx
callq 0x58fd2
leaq 0x18(%rsp), %r12
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq (%rsp), %rdi
callq 0x60b0
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f2ef
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4f30b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4f327
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
addq $0x4, %rbp
cmpq 0x70(%rsp), %rbp
jne 0x4f12e
jmp 0x4f3b1
cmpq %rsi, %rbp
je 0x4f397
leaq 0x18(%rsp), %r13
leaq 0x8(%rsp), %r15
leaq 0x6f7a3(%rip), %r12     # 0xbeaf1
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb3ca
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2c7ac
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xaa14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4f38c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
addq $0x4, %rbp
cmpq 0x70(%rsp), %rbp
jne 0x4f34e
movq (%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x65506(%rip), %rdx     # 0xb48af
movq %rdx, %rsi
callq 0x7be0
movq (%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4f3d7
jmp 0x4f3dc
jmp 0x4f466
jmp 0x4f466
jmp 0x4f466
movq %rax, %r14
jmp 0x4f402
movq %rax, %r14
jmp 0x4f41e
jmp 0x4f466
jmp 0x4f466
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f402
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4f41e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4f469
movq 0x38(%rsp), %rsi
jmp 0x4f446
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f469
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x4f469
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4f487
movq 0x18(%rsp), %rsi
jmp 0x4f47f
jmp 0x4f466
movq %rax, %r14
movq (%rsp), %rax
movq (%rax), %rdi
cmpq 0x68(%rsp), %rdi
je 0x4f487
movq 0x68(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x6260
movq %r14, %rdi
callq 0x64a0
nop