// File: rossy[P]crossc/SPIRV-Cross/spirv_cfg.cpp
// Function: spirv_cross::DominatorBuilder::lift_continue_block_dominator()
void DominatorBuilder::lift_continue_block_dominator()
{
	// It is possible for a continue block to be the dominator of a variable is only accessed inside the while block of a do-while loop.
	// We cannot safely declare variables inside a continue block, so move any variable declared
	// in a continue block to the entry block to simplify.
	// It makes very little sense for a continue block to ever be a dominator, so fall back to the simplest
	// solution.

	if (!dominator)
		return;

	auto &block = cfg.get_compiler().get<SPIRBlock>(dominator);
	auto post_order = cfg.get_visit_order(dominator);

	// If we are branching to a block with a higher post-order traversal index (continue blocks), we have a problem
	// since we cannot create sensible GLSL code for this, fallback to entry block.
	bool back_edge_dominator = false;
	switch (block.terminator)
	{
	case SPIRBlock::Direct:
		if (cfg.get_visit_order(block.next_block) > post_order)
			back_edge_dominator = true;
		break;

	case SPIRBlock::Select:
		if (cfg.get_visit_order(block.true_block) > post_order)
			back_edge_dominator = true;
		if (cfg.get_visit_order(block.false_block) > post_order)
			back_edge_dominator = true;
		break;

	case SPIRBlock::MultiSelect:
		for (auto &target : block.cases)
		{
			if (cfg.get_visit_order(target.block) > post_order)
				back_edge_dominator = true;
		}
		if (block.default_block && cfg.get_visit_order(block.default_block) > post_order)
			back_edge_dominator = true;
		break;

	default:
		break;
	}

	if (back_edge_dominator)
		dominator = cfg.get_function().entry_block;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, 0x8(%rax)
jne 0x806f
jmp 0x81ea
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x8a50
movq %rax, %rdi
movq -0x40(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x8a70
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x10(%rbp)
movq (%rax), %rdi
movl 0x8(%rax), %esi
callq 0x8ab0
movl %eax, -0x14(%rbp)
movb $0x0, -0x15(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x80cf
jmp 0x80b8
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x80f0
jmp 0x80c2
movl -0x44(%rbp), %eax
subl $0x3, %eax
je 0x812d
jmp 0x81c9
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x8ab0
cmpl -0x14(%rbp), %eax
jbe 0x80eb
movb $0x1, -0x15(%rbp)
jmp 0x81cb
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %esi
callq 0x8ab0
cmpl -0x14(%rbp), %eax
jbe 0x810c
movb $0x1, -0x15(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
callq 0x8ab0
cmpl -0x14(%rbp), %eax
jbe 0x8128
movb $0x1, -0x15(%rbp)
jmp 0x81cb
movq -0x10(%rbp), %rax
addq $0x98, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x8b10
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x8b40
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x8b70
testb $0x1, %al
jne 0x8168
jmp 0x81a1
leaq -0x28(%rbp), %rdi
callq 0x8bb0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x8ab0
cmpl -0x14(%rbp), %eax
jbe 0x8194
movb $0x1, -0x15(%rbp)
jmp 0x8196
leaq -0x28(%rbp), %rdi
callq 0x8bd0
jmp 0x8155
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x81c7
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x34(%rax), %esi
callq 0x8ab0
cmpl -0x14(%rbp), %eax
jbe 0x81c7
movb $0x1, -0x15(%rbp)
jmp 0x81cb
jmp 0x81cb
testb $0x1, -0x15(%rbp)
je 0x81ea
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x8bf0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movl 0x60(%rcx), %ecx
movl %ecx, 0x8(%rax)
addq $0x50, %rsp
popq %rbp
retq