// File: rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::build_function_control_flow_graphs_and_analyze()
void Compiler::build_function_control_flow_graphs_and_analyze()
{
	CFGBuilder handler(*this);
	handler.function_cfgs[ir.default_entry_point].reset(new CFG(*this, get<SPIRFunction>(ir.default_entry_point)));
	traverse_all_reachable_opcodes(get<SPIRFunction>(ir.default_entry_point), handler);
	function_cfgs = move(handler.function_cfgs);

	for (auto &f : function_cfgs)
	{
		auto &func = get<SPIRFunction>(f.first);
		AnalyzeVariableScopeAccessHandler scope_handler(*this, func);
		analyze_variable_scope(func, scope_handler);
		find_function_local_luts(func, scope_handler);

		// Check if we can actually use the loop variables we found in analyze_variable_scope.
		// To use multiple initializers, we need the same type and qualifiers.
		for (auto block : func.blocks)
		{
			auto &b = get<SPIRBlock>(block);
			if (b.loop_variables.size() < 2)
				continue;

			auto &flags = get_decoration_bitset(b.loop_variables.front());
			uint32_t type = get<SPIRVariable>(b.loop_variables.front()).basetype;
			bool invalid_initializers = false;
			for (auto loop_variable : b.loop_variables)
			{
				if (flags != get_decoration_bitset(loop_variable) ||
				    type != get<SPIRVariable>(b.loop_variables.front()).basetype)
				{
					invalid_initializers = true;
					break;
				}
			}

			if (invalid_initializers)
			{
				for (auto loop_variable : b.loop_variables)
					get<SPIRVariable>(loop_variable).loop_variable = false;
				b.loop_variables.clear();
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x248(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x2ba60
movq -0x248(%rbp), %rsi
leaq -0x40(%rbp), %rdi
addq $0x108, %rsi            # imm = 0x108
callq 0x32420
movq %rax, -0x240(%rbp)
jmp 0x2b543
movl $0x90, %edi
callq 0x7360
movq %rax, -0x250(%rbp)
jmp 0x2b556
movq -0x248(%rbp), %rdi
movl 0x108(%rdi), %esi
callq 0x106d0
movq %rax, -0x258(%rbp)
jmp 0x2b571
movq -0x258(%rbp), %rdx
movq -0x248(%rbp), %rsi
movq -0x250(%rbp), %rdi
callq 0x77d0
jmp 0x2b58d
movq -0x250(%rbp), %rsi
movq -0x240(%rbp), %rdi
callq 0x32450
movq -0x248(%rbp), %rdi
movl 0x108(%rdi), %esi
callq 0x106d0
movq %rax, -0x260(%rbp)
jmp 0x2b5bb
movq -0x260(%rbp), %rsi
movq -0x248(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x21b20
jmp 0x2b5d4
movq -0x248(%rbp), %rdi
leaq -0x50(%rbp), %rsi
addq $0x10, %rsi
addq $0x3a0, %rdi            # imm = 0x3A0
callq 0x32480
movq -0x248(%rbp), %rax
addq $0x3a0, %rax            # imm = 0x3A0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x324b0
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
callq 0x324e0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x32510
testb $0x1, %al
jne 0x2b630
jmp 0x2ba38
leaq -0x70(%rbp), %rdi
callq 0x32540
movq -0x248(%rbp), %rdi
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl (%rax), %esi
callq 0x106d0
movq %rax, -0x268(%rbp)
jmp 0x2b658
movq -0x248(%rbp), %rsi
movq -0x268(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdx
leaq -0x1c0(%rbp), %rdi
callq 0x283e0
jmp 0x2b682
movq -0x248(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq -0x1c0(%rbp), %rdx
callq 0x29860
jmp 0x2b69e
movq -0x248(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq -0x1c0(%rbp), %rdx
callq 0x29410
jmp 0x2b6ba
movq -0x88(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rdi
callq 0x86d0
movq %rax, -0x1d0(%rbp)
movq -0x1c8(%rbp), %rdi
callq 0x8700
movq %rax, -0x1d8(%rbp)
leaq -0x1d0(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x8730
testb $0x1, %al
jne 0x2b70e
jmp 0x2ba1e
leaq -0x1d0(%rbp), %rdi
callq 0x8770
movq -0x248(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x1dc(%rbp)
movl -0x1dc(%rbp), %esi
callq 0x87d0
movq %rax, -0x270(%rbp)
jmp 0x2b73d
movq -0x270(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x1e8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x8650
cmpq $0x2, %rax
jae 0x2b7b9
jmp 0x2ba0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x2ba4a
movq -0x250(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x90, %esi
callq 0x7370
jmp 0x2ba4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x325d0
jmp 0x2ba4a
movq -0x1e8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x32570
movq -0x248(%rbp), %rdi
movl (%rax), %esi
callq 0x23480
movq %rax, -0x278(%rbp)
jmp 0x2b7e3
movq -0x278(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x1e8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x32570
movq -0x248(%rbp), %rdi
movl (%rax), %esi
callq 0xfec0
movq %rax, -0x280(%rbp)
jmp 0x2b81b
movq -0x280(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x1f4(%rbp)
movb $0x0, -0x1f5(%rbp)
movq -0x1e8(%rbp), %rax
addq $0xd0, %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rdi
callq 0x86d0
movq %rax, -0x208(%rbp)
movq -0x200(%rbp), %rdi
callq 0x8700
movq %rax, -0x210(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x8730
testb $0x1, %al
jne 0x2b888
jmp 0x2b950
leaq -0x208(%rbp), %rdi
callq 0x8770
movq -0x248(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x214(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x290(%rbp)
movl -0x214(%rbp), %esi
callq 0x23480
movq %rax, -0x288(%rbp)
jmp 0x2b8c5
movq -0x288(%rbp), %rsi
movq -0x290(%rbp), %rdi
callq 0x325a0
movb %al, -0x291(%rbp)
jmp 0x2b8e0
movb -0x291(%rbp), %al
testb $0x1, %al
jne 0x2b934
jmp 0x2b8ec
movl -0x1f4(%rbp), %eax
movl %eax, -0x2a4(%rbp)
movq -0x1e8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x32570
movq -0x248(%rbp), %rdi
movl (%rax), %esi
callq 0xfec0
movq %rax, -0x2a0(%rbp)
jmp 0x2b922
movl -0x2a4(%rbp), %eax
movq -0x2a0(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0x2b93d
movb $0x1, -0x1f5(%rbp)
jmp 0x2b950
jmp 0x2b93f
leaq -0x208(%rbp), %rdi
callq 0x8790
jmp 0x2b86c
testb $0x1, -0x1f5(%rbp)
je 0x2ba0b
movq -0x1e8(%rbp), %rax
addq $0xd0, %rax
movq %rax, -0x220(%rbp)
movq -0x220(%rbp), %rdi
callq 0x86d0
movq %rax, -0x228(%rbp)
movq -0x220(%rbp), %rdi
callq 0x8700
movq %rax, -0x230(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x8730
testb $0x1, %al
jne 0x2b9b0
jmp 0x2b9f8
leaq -0x228(%rbp), %rdi
callq 0x8770
movq -0x248(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x234(%rbp)
movl -0x234(%rbp), %esi
callq 0xfec0
movq %rax, -0x2b0(%rbp)
jmp 0x2b9df
movq -0x2b0(%rbp), %rax
movb $0x0, 0x64(%rax)
leaq -0x228(%rbp), %rdi
callq 0x8790
jmp 0x2b997
movq -0x1e8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x8a00
jmp 0x2ba0d
leaq -0x1d0(%rbp), %rdi
callq 0x8790
jmp 0x2b6f2
leaq -0x1c0(%rbp), %rdi
callq 0x325d0
leaq -0x70(%rbp), %rdi
callq 0x32650
jmp 0x2b61a
leaq -0x50(%rbp), %rdi
callq 0x32680
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x32680
movq -0x58(%rbp), %rdi
callq 0x7640
nopl (%rax)