// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::block_is_loop_candidate(spirv_cross::SPIRBlock const&, spirv_cross::SPIRBlock::Method) const
bool Compiler::block_is_loop_candidate(const SPIRBlock &block, SPIRBlock::Method method) const
{
	// Tried and failed.
	if (block.disable_block_optimization || block.complex_continue)
		return false;

	if (method == SPIRBlock::MergeToSelectForLoop || method == SPIRBlock::MergeToSelectContinueForLoop)
	{
		// Try to detect common for loop pattern
		// which the code backend can use to create cleaner code.
		// for(;;) { if (cond) { some_body; } else { break; } }
		// is the pattern we're looking for.
		bool ret = block.terminator == SPIRBlock::Select && block.merge == SPIRBlock::MergeLoop &&
		           block.true_block != block.merge_block && block.true_block != block.self &&
		           block.false_block == block.merge_block;

		if (ret && method == SPIRBlock::MergeToSelectContinueForLoop)
			ret = block.true_block == block.continue_block;

		// If we have OpPhi which depends on branches which came from our own block,
		// we need to flush phi variables in else block instead of a trivial break,
		// so we cannot assume this is a for loop candidate.
		if (ret)
		{
			for (auto &phi : block.phi_variables)
				if (phi.parent == block.self)
					return false;

			auto *merge = maybe_get<SPIRBlock>(block.merge_block);
			if (merge)
				for (auto &phi : merge->phi_variables)
					if (phi.parent == block.self)
						return false;
		}
		return ret;
	}
	else if (method == SPIRBlock::MergeToDirectForLoop)
	{
		// Empty loop header that just sets up merge target
		// and branches to loop body.
		bool ret = block.terminator == SPIRBlock::Direct && block.merge == SPIRBlock::MergeLoop && block.ops.empty();

		if (!ret)
			return false;

		auto &child = get<SPIRBlock>(block.next_block);
		ret = child.terminator == SPIRBlock::Select && child.merge == SPIRBlock::MergeNone &&
		      child.false_block == block.merge_block && child.true_block != block.merge_block &&
		      child.true_block != block.self;

		// If we have OpPhi which depends on branches which came from our own block,
		// we need to flush phi variables in else block instead of a trivial break,
		// so we cannot assume this is a for loop candidate.
		if (ret)
		{
			for (auto &phi : block.phi_variables)
				if (phi.parent == block.self || phi.parent == child.self)
					return false;

			for (auto &phi : child.phi_variables)
				if (phi.parent == block.self)
					return false;

			auto *merge = maybe_get<SPIRBlock>(block.merge_block);
			if (merge)
				for (auto &phi : merge->phi_variables)
					if (phi.parent == block.self || phi.parent == child.false_block)
						return false;
		}

		return ret;
	}
	else
		return false;
}

// Assembly:
cmpb $0x0, 0xb0(%rsi)
je 0x121d2
xorl %eax, %eax
retq
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
cmpb $0x0, 0xb1(%rsi)
je 0x121eb
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq %rdi, %r14
cmpl $0x2, %edx
je 0x121fc
cmpl $0x1, %edx
je 0x12243
testl %edx, %edx
jne 0x121e3
xorl %eax, %eax
cmpl $0x2, 0xc(%rbx)
jne 0x121e5
cmpl $0x1, 0x10(%rbx)
jne 0x121e5
movl 0x2c(%rbx), %eax
movl 0x8(%rbx), %ecx
movl 0x1c(%rbx), %esi
cmpl %esi, %eax
sete %dil
cmpl %ecx, %eax
sete %r8b
orb %dil, %r8b
jne 0x121e3
xorl $0x2, %edx
movl 0x30(%rbx), %edi
movl %edi, %r8d
xorl %esi, %r8d
orl %edx, %r8d
jne 0x122d3
cmpl 0x20(%rbx), %eax
jne 0x121e3
jmp 0x122db
xorl %eax, %eax
cmpl $0x1, 0xc(%rbx)
jne 0x121e5
cmpl $0x1, 0x10(%rbx)
jne 0x121e5
movq 0x38(%rbx), %rax
cmpq 0x40(%rbx), %rax
jne 0x121e3
movl 0x18(%rbx), %esi
movq %r14, %rdi
callq 0x6c24
movq %rax, %r15
xorl %eax, %eax
cmpl $0x2, 0xc(%r15)
jne 0x121e5
cmpl $0x0, 0x10(%r15)
jne 0x121e5
movl 0x30(%r15), %esi
cmpl 0x1c(%rbx), %esi
jne 0x121e3
movl 0x2c(%r15), %eax
cmpl %esi, %eax
je 0x121e3
movl 0x8(%rbx), %ecx
cmpl %ecx, %eax
je 0x121e3
movq 0x50(%rbx), %rdx
movq 0x58(%rbx), %rdi
movl 0x8(%r15), %r8d
xorl %eax, %eax
cmpq %rdi, %rdx
je 0x12334
movl 0x4(%rdx), %r9d
cmpl %ecx, %r9d
je 0x121e5
addq $0xc, %rdx
cmpl %r8d, %r9d
jne 0x122b3
jmp 0x121e5
cmpl %esi, %edi
jne 0x121e3
movq 0x50(%rbx), %rdi
movq 0x58(%rbx), %rdx
xorl %eax, %eax
cmpq %rdx, %rdi
je 0x122fb
leaq 0xc(%rdi), %r8
cmpl %ecx, 0x4(%rdi)
movq %r8, %rdi
jne 0x122e5
jmp 0x121e5
movq %r14, %rdi
callq 0x175b6
testq %rax, %rax
je 0x12397
movq 0x50(%rax), %rdx
movq 0x58(%rax), %rcx
movl 0x8(%rbx), %esi
cmpq %rcx, %rdx
sete %al
je 0x121e5
leaq 0xc(%rdx), %rdi
cmpl %esi, 0x4(%rdx)
movq %rdi, %rdx
jne 0x12317
jmp 0x121e5
movq 0x50(%r15), %rdi
movq 0x58(%r15), %rdx
xorl %eax, %eax
cmpq %rdx, %rdi
je 0x12354
leaq 0xc(%rdi), %r8
cmpl %ecx, 0x4(%rdi)
movq %r8, %rdi
jne 0x1233e
jmp 0x121e5
movq %r14, %rdi
callq 0x175b6
testq %rax, %rax
je 0x12397
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rdx
movl 0x8(%rbx), %esi
movl 0x30(%r15), %edi
cmpq %rdx, %rcx
sete %al
je 0x121e5
movl 0x4(%rcx), %r8d
cmpl %esi, %r8d
je 0x121e5
addq $0xc, %rcx
cmpl %edi, %r8d
jne 0x12370
jmp 0x121e5
movb $0x1, %al
jmp 0x121e5