// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::propagate_loop_dominators(spirv_cross::SPIRBlock const&)
void CompilerGLSL::propagate_loop_dominators(const SPIRBlock &block)
{
	// Propagate down the loop dominator block, so that dominated blocks can back trace.
	if (block.merge == SPIRBlock::MergeLoop || block.loop_dominator)
	{
		uint32_t dominator = block.merge == SPIRBlock::MergeLoop ? block.self : block.loop_dominator;

		auto set_dominator = [this](uint32_t self, uint32_t new_dominator) {
			auto &dominated_block = this->get<SPIRBlock>(self);

			// If we already have a loop dominator, we're trying to break out to merge targets
			// which should not update the loop dominator.
			if (!dominated_block.loop_dominator)
				dominated_block.loop_dominator = new_dominator;
		};

		// After merging a loop, we inherit the loop dominator always.
		if (block.merge_block)
			set_dominator(block.merge_block, block.loop_dominator);

		if (block.true_block)
			set_dominator(block.true_block, dominator);
		if (block.false_block)
			set_dominator(block.false_block, dominator);
		if (block.next_block)
			set_dominator(block.next_block, dominator);
		if (block.default_block)
			set_dominator(block.default_block, dominator);

		for (auto &c : block.cases)
			set_dominator(c.block, dominator);

		// In older glslang output continue_block can be == loop header.
		if (block.continue_block && block.continue_block != block.self)
			set_dominator(block.continue_block, dominator);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10(%rax)
je 0x9a073
movq -0x10(%rbp), %rax
cmpl $0x0, 0xb4(%rax)
je 0x9a1d1
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x9a089
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x4c(%rbp)
jmp 0x9a096
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl %ecx, -0x14(%rbp)
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x9a0c8
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %edx
leaq -0x20(%rbp), %rdi
callq 0x9a1e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x9a0e5
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %esi
movl -0x14(%rbp), %edx
leaq -0x20(%rbp), %rdi
callq 0x9a1e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x9a102
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
movl -0x14(%rbp), %edx
leaq -0x20(%rbp), %rdi
callq 0x9a1e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x9a11f
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
movl -0x14(%rbp), %edx
leaq -0x20(%rbp), %rdi
callq 0x9a1e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x9a13c
movq -0x10(%rbp), %rax
movl 0x34(%rax), %esi
movl -0x14(%rbp), %edx
leaq -0x20(%rbp), %rdi
callq 0x9a1e0
movq -0x10(%rbp), %rax
addq $0x98, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x8b10
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x8b40
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8b70
testb $0x1, %al
jne 0x9a177
jmp 0x9a1a2
leaq -0x30(%rbp), %rdi
callq 0x8bb0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %esi
movl -0x14(%rbp), %edx
leaq -0x20(%rbp), %rdi
callq 0x9a1e0
leaq -0x30(%rbp), %rdi
callq 0x8bd0
jmp 0x9a164
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x9a1cf
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x9a1cf
movq -0x10(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x14(%rbp), %edx
leaq -0x20(%rbp), %rdi
callq 0x9a1e0
jmp 0x9a1d1
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)