// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
movq 0xd0(%rdx), %rax
cmpq 0xd8(%rdx), %rax
je 0x401e9
movq %rdx, %r15
movq %rsi, %r14
movq %r13, 0x8(%rsp)
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x40276
movl %eax, %r12d
movq 0xd0(%r15), %rbx
movq 0xd8(%r15), %rbp
xorl %r13d, %r13d
cmpq %rbp, %rbx
je 0x3ff90
movl (%rbx), %esi
movq %r14, %rdi
callq 0x9c0e
movl 0x3c(%rax), %eax
testq %rax, %rax
je 0x3ff87
movq 0x20(%r14), %rcx
shlq $0x4, %rax
cmpl $0xd, 0x8(%rcx,%rax)
jne 0x3ff8a
incl %r13d
addq $0x4, %rbx
jmp 0x3ff61
movq 0xd0(%r15), %rbp
movq 0xd8(%r15), %rax
movq %rax, 0x10(%rsp)
subq %rbp, %rax
cmpq $0x4, %rax
sete %cl
testl %r13d, %r13d
sete %dl
testb %dl, %cl
je 0x3ffdd
movl (%rbp), %esi
movq %r14, %rdi
callq 0x9c0e
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2619e
movq %rbx, %rax
jmp 0x40200
shrq $0x2, %rax
cmpl %eax, %r13d
setne %al
testb %al, %r12b
je 0x4019c
movq 0x8(%rsp), %r13
leaq 0x10(%r13), %rax
movq %rax, (%r13)
andq $0x0, 0x8(%r13)
movb $0x0, 0x10(%r13)
leaq 0x18(%rsp), %r15
cmpq 0x10(%rsp), %rbp
je 0x401fd
movl (%rbp), %esi
movq %r14, %rdi
callq 0x9c0e
movl 0x3c(%rax), %eax
testq %rax, %rax
je 0x40039
movq 0x20(%r14), %rcx
shlq $0x4, %rax
cmpl $0xd, 0x8(%rcx,%rax)
jne 0x4006c
movl (%rbp), %esi
movq %r14, %rdi
callq 0x9c0e
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2619e
movq %r14, %rdi
movq %r15, %rsi
leaq 0x59a22(%rip), %rdx     # 0x99a81
callq 0x953a
movq %r15, %rdi
jmp 0x4018e
cmpq $0x0, 0x8(%r13)
je 0x40087
movq %r13, %rdi
leaq 0x5500e(%rip), %rsi     # 0x9508b
callq 0x64d0
jmp 0x40118
movl (%rbp), %esi
movq %r14, %rdi
callq 0x9c0e
movq %rax, %r13
movl 0xc(%rax), %esi
movq %r14, %rdi
callq 0x90a4
movq %rax, %r12
movl 0x8(%r13), %edx
movq (%r14), %rax
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq *0x128(%rax)
movq (%r14), %rax
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movq 0x8(%rsp), %r13
callq *0x98(%rax)
leaq 0x18(%rsp), %r15
movq %r15, %rdi
leaq 0x38(%rsp), %r12
movq %r12, %rsi
movq %rbx, %rdx
leaq 0x4f796(%rip), %rcx     # 0x8f886
callq 0x471e4
movq %r13, %rdi
movq %r15, %rsi
callq 0x6320
movq %r15, %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x6548
movq %r12, %rdi
callq 0x6548
movl (%rbp), %esi
movq %r14, %rdi
callq 0x9c0e
movq %rax, %r12
movl (%rbp), %edx
movq (%r14), %rax
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
pushq $0x1
popq %rcx
callq *0x38(%rax)
movl 0x3c(%r12), %edx
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2b9f0
leaq 0x18(%rsp), %r15
movq %r15, %rdi
leaq 0x38(%rsp), %r12
movq %r12, %rsi
leaq 0x59884(%rip), %rdx     # 0x999ea
movq %rbx, %rcx
callq 0x4725e
movq %r13, %rdi
movq %r15, %rsi
callq 0x64f0
movq %r15, %rdi
callq 0x6548
leaq 0x58(%rsp), %rdi
callq 0x6548
movq %r12, %rdi
callq 0x6548
addq $0x4, %rbp
jmp 0x4000c
leaq 0x18(%rsp), %r15
leaq 0x598d9(%rip), %r12     # 0x99a81
movq 0x8(%rsp), %r13
cmpq 0x10(%rsp), %rbp
je 0x401e9
movl (%rbp), %esi
movq %r14, %rdi
callq 0x9c0e
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2619e
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x953a
movq %r15, %rdi
callq 0x6548
addq $0x4, %rbp
jmp 0x401ad
leaq 0x4f697(%rip), %rsi     # 0x8f887
leaq 0x18(%rsp), %rdx
movq %r13, %rdi
callq 0x6100
movq %r13, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x40219
jmp 0x4021e
jmp 0x40260
jmp 0x40260
jmp 0x40260
movq %rax, %r14
jmp 0x40234
movq %rax, %r14
jmp 0x4023e
jmp 0x40260
jmp 0x40260
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x6548
leaq 0x58(%rsp), %rdi
callq 0x6548
leaq 0x38(%rsp), %rdi
jmp 0x4024d
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x6548
jmp 0x40263
movq %rax, %r14
leaq 0x18(%rsp), %rdi
jmp 0x40268
jmp 0x40260
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x6548
movq %r14, %rdi
callq 0x64b0
nop