// File: /workspace/github_cpp_makefile_star2_O1/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 0x4f849
movq %rdx, %r15
movq %rsi, %r14
movq %rbx, (%rsp)
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x4fc12
movl %eax, %r12d
movq 0xd0(%r15), %rbx
movq 0xd8(%r15), %rbp
xorl %r13d, %r13d
cmpq %rbp, %rbx
je 0x4f803
movl (%rbx), %esi
movq %r14, %rdi
callq 0xb40a
movl 0x3c(%rax), %eax
testq %rax, %rax
je 0x4f7fa
movq 0x20(%r14), %rcx
shlq $0x4, %rax
cmpl $0xd, 0x8(%rcx,%rax)
jne 0x4f7fd
incl %r13d
addq $0x4, %rbx
jmp 0x4f7d4
movq 0xd0(%r15), %rbp
movq 0xd8(%r15), %rax
movq %rax, 0x28(%rsp)
subq %rbp, %rax
cmpq $0x4, %rax
sete %cl
testl %r13d, %r13d
sete %dl
testb %dl, %cl
je 0x4f86a
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb40a
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2ce16
jmp 0x4f862
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x66058(%rip), %rdx     # 0xb58af
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x7c64
movq %rbx, %rax
jmp 0x4fb37
shrq $0x2, %rax
cmpl %eax, %r13d
setne %al
testb %al, %r12b
je 0x4fab8
movq (%rsp), %rcx
leaq 0x10(%rcx), %rax
movq %rax, 0x70(%rsp)
movq %rax, (%rcx)
movq $0x0, 0x8(%rcx)
movb $0x0, 0x10(%rcx)
cmpq 0x28(%rsp), %rbp
je 0x4fb33
leaq 0x18(%rsp), %r12
leaq 0x8(%rsp), %r15
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb40a
movl 0x3c(%rax), %eax
testq %rax, %rax
je 0x4f8d0
movq 0x20(%r14), %rcx
shlq $0x4, %rax
cmpl $0xd, 0x8(%rcx,%rax)
jne 0x4f913
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb40a
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2ce16
movq %r14, %rdi
movq %r15, %rsi
leaq 0x701f3(%rip), %rdx     # 0xbfae9
callq 0xaa50
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4faa7
movq 0x18(%rsp), %rsi
jmp 0x4fa9f
movq (%rsp), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x4f92f
leaq 0x6b796(%rip), %rsi     # 0xbb0bb
callq 0x64e0
jmp 0x4f9f0
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb40a
movq %rax, %r13
movl 0xc(%rax), %esi
movq %r14, %rdi
callq 0xa426
movq %rax, %r12
movl 0x8(%r13), %edx
movq (%r14), %rax
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq *0x128(%rax)
movq (%r14), %rax
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq *0x98(%rax)
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movq %r13, %rdx
leaq 0x65f23(%rip), %rcx     # 0xb58ae
callq 0x59720
leaq 0x18(%rsp), %r12
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x6310
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4f9b8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4f9d4
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4f9f0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb40a
movq %rax, %r12
movl (%rbp), %edx
movq (%r14), %rax
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movl 0x3c(%r12), %edx
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x345e6
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x7001a(%rip), %rdx     # 0xbfa52
movq %r12, %rcx
callq 0x597cc
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 0x4fa6f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4fa8b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4faa7
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
addq $0x4, %rbp
cmpq 0x28(%rsp), %rbp
jne 0x4f8ae
jmp 0x4fb33
cmpq 0x28(%rsp), %rbp
je 0x4fb19
leaq 0x18(%rsp), %r13
leaq 0x8(%rsp), %r15
leaq 0x70019(%rip), %r12     # 0xbfae9
movl (%rbp), %esi
movq %r14, %rdi
callq 0xb40a
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2ce16
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xaa50
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4fb0e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
addq $0x4, %rbp
cmpq 0x28(%rsp), %rbp
jne 0x4fad0
movq (%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x65d84(%rip), %rdx     # 0xb58af
movq %rdx, %rsi
callq 0x7c64
movq (%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4fb59
jmp 0x4fb5e
jmp 0x4fbe8
jmp 0x4fbe8
jmp 0x4fbe8
movq %rax, %r14
jmp 0x4fb84
movq %rax, %r14
jmp 0x4fba0
jmp 0x4fbe8
jmp 0x4fbe8
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4fb84
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4fba0
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4fbeb
movq 0x40(%rsp), %rsi
jmp 0x4fbc8
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4fbeb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x4fbeb
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4fc09
movq 0x18(%rsp), %rsi
jmp 0x4fc01
jmp 0x4fbe8
movq %rax, %r14
movq (%rsp), %rax
movq (%rax), %rdi
cmpq 0x70(%rsp), %rdi
je 0x4fc09
movq 0x70(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x6260
movq %r14, %rdi
callq 0x64a0
nop