// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::branch_to_continue(unsigned int, unsigned int)
void CompilerGLSL::branch_to_continue(uint32_t from, uint32_t to)
{
	auto &to_block = get<SPIRBlock>(to);
	if (from == to)
		return;

	assert(is_continue(to));
	if (to_block.complex_continue)
	{
		// Just emit the whole block chain as is.
		auto usage_counts = expression_usage_counts;
		auto invalid = invalid_expressions;

		emit_block_chain(to_block);

		// Expression usage counts and invalid expressions
		// are moot after returning from the continue block.
		// Since we emit the same block multiple times,
		// we don't want to invalidate ourselves.
		expression_usage_counts = usage_counts;
		invalid_expressions = invalid;
	}
	else
	{
		auto &from_block = get<SPIRBlock>(from);
		bool outside_control_flow = false;
		uint32_t loop_dominator = 0;

		// FIXME: Refactor this to not use the old loop_dominator tracking.
		if (from_block.merge_block)
		{
			// If we are a loop header, we don't set the loop dominator,
			// so just use "self" here.
			loop_dominator = from;
		}
		else if (from_block.loop_dominator != SPIRBlock::NoDominator)
		{
			loop_dominator = from_block.loop_dominator;
		}

		if (loop_dominator != 0)
		{
			auto &dominator = get<SPIRBlock>(loop_dominator);

			// For non-complex continue blocks, we implicitly branch to the continue block
			// by having the continue block be part of the loop header in for (; ; continue-block).
			outside_control_flow = block_is_outside_flow_control_from_block(dominator, from_block);
		}

		// Some simplification for for-loops. We always end up with a useless continue;
		// statement since we branch to a loop block.
		// Walk the CFG, if we uncoditionally execute the block calling continue assuming we're in the loop block,
		// we can avoid writing out an explicit continue statement.
		// Similar optimization to return statements if we know we're outside flow control.
		if (!outside_control_flow)
			statement("continue;");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
movl -0x10(%rbp), %esi
callq 0x87d0
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jne 0x99999
jmp 0x99b7a
movq -0xb8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x2fdb0
testb $0x1, %al
jne 0x999ae
jmp 0x999b0
jmp 0x999cf
leaq 0xab4b5(%rip), %rdi     # 0x144e6c
leaq 0xa786e(%rip), %rsi     # 0x14122c
movl $0x23fc, %edx           # imm = 0x23FC
leaq 0xab4b2(%rip), %rcx     # 0x144e7c
callq 0x7260
movq -0x18(%rbp), %rax
testb $0x1, 0xb1(%rax)
je 0x99ab4
movq -0xb8(%rbp), %rsi
addq $0x6e8, %rsi            # imm = 0x6E8
leaq -0x50(%rbp), %rdi
callq 0x371a0
movq -0xb8(%rbp), %rsi
addq $0x198, %rsi            # imm = 0x198
leaq -0x88(%rbp), %rdi
callq 0x124a0
jmp 0x99a13
movq -0xb8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x982d0
jmp 0x99a25
movq -0xb8(%rbp), %rdi
addq $0x6e8, %rdi            # imm = 0x6E8
leaq -0x50(%rbp), %rsi
callq 0x35aa0
jmp 0x99a3e
movq -0xb8(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
leaq -0x88(%rbp), %rsi
callq 0x385a0
jmp 0x99a5a
leaq -0x88(%rbp), %rdi
callq 0x13900
leaq -0x50(%rbp), %rdi
callq 0x150d0
jmp 0x99b7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x99aa6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x13900
leaq -0x50(%rbp), %rdi
callq 0x150d0
jmp 0x99b83
movq -0xb8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x87d0
movq %rax, -0xa0(%rbp)
movb $0x0, -0xa1(%rbp)
movl $0x0, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x99af3
movl -0xc(%rbp), %eax
movl %eax, -0xa8(%rbp)
jmp 0x99b18
movq -0xa0(%rbp), %rax
cmpl $-0x1, 0xb4(%rax)
je 0x99b16
movq -0xa0(%rbp), %rax
movl 0xb4(%rax), %eax
movl %eax, -0xa8(%rbp)
jmp 0x99b18
cmpl $0x0, -0xa8(%rbp)
je 0x99b5c
movq -0xb8(%rbp), %rdi
movl -0xa8(%rbp), %esi
callq 0x87d0
movq -0xb8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rsi
movq -0xa0(%rbp), %rdx
callq 0x23b20
andb $0x1, %al
movb %al, -0xa1(%rbp)
testb $0x1, -0xa1(%rbp)
jne 0x99b78
movq -0xb8(%rbp), %rdi
leaq 0xab350(%rip), %rsi     # 0x144ec3
callq 0xa81b0
jmp 0x99b7a
addq $0xc0, %rsp
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x7640
nop