// File: rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::AnalyzeVariableScopeAccessHandler::set_current_block(spirv_cross::SPIRBlock const&)
void Compiler::AnalyzeVariableScopeAccessHandler::set_current_block(const SPIRBlock &block)
{
	current_block = &block;

	// If we're branching to a block which uses OpPhi, in GLSL
	// this will be a variable write when we branch,
	// so we need to track access to these variables as well to
	// have a complete picture.
	const auto test_phi = [this, &block](uint32_t to) {
		auto &next = compiler.get<SPIRBlock>(to);
		for (auto &phi : next.phi_variables)
		{
			if (phi.parent == block.self)
			{
				accessed_variables_to_block[phi.function_variable].insert(block.self);
				// Phi variables are also accessed in our target branch block.
				accessed_variables_to_block[phi.function_variable].insert(next.self);

				notify_variable_access(phi.local_variable, block.self);
			}
		}
	};

	switch (block.terminator)
	{
	case SPIRBlock::Direct:
		notify_variable_access(block.condition, block.self);
		test_phi(block.next_block);
		break;

	case SPIRBlock::Select:
		notify_variable_access(block.condition, block.self);
		test_phi(block.true_block);
		test_phi(block.false_block);
		break;

	case SPIRBlock::MultiSelect:
		notify_variable_access(block.condition, block.self);
		for (auto &target : block.cases)
			test_phi(target.block);
		if (block.default_block)
			test_phi(block.default_block);
		break;

	default:
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, 0x130(%rax)
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x284f7
jmp 0x284e0
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x28523
jmp 0x284ea
movl -0x44(%rbp), %eax
subl $0x3, %eax
je 0x2855f
jmp 0x285f5
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x28600
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
leaq -0x20(%rbp), %rdi
callq 0x28690
jmp 0x285f7
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x28600
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %esi
leaq -0x20(%rbp), %rdi
callq 0x28690
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
leaq -0x20(%rbp), %rdi
callq 0x28690
jmp 0x285f7
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x28600
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 0x285b1
jmp 0x285d9
leaq -0x30(%rbp), %rdi
callq 0x8bb0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %esi
leaq -0x20(%rbp), %rdi
callq 0x28690
leaq -0x30(%rbp), %rdi
callq 0x8bd0
jmp 0x2859e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x285f3
movq -0x10(%rbp), %rax
movl 0x34(%rax), %esi
leaq -0x20(%rbp), %rdi
callq 0x28690
jmp 0x285f7
jmp 0x285f7
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)