// File: /workspace/github_cpp_makefile_star2_O3/Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::isUsedInEndingBlock(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Block&, Block&)
bool SecondIR::isUsedInEndingBlock(std::string variable, Block& startingBlock, Block& endingBlock)
{
    if (startingBlock.visited)
    {
        return true;
    }
    if (startingBlock == endingBlock)
    {
        return true;
    }

    startingBlock.visited = true;

    for(auto& l : startingBlock.lines)
    {
        if (l.one == variable || l.two == variable)
        {
            return false;
        }
        std::string index = "(" + variable + ")";
        if (l.one.find(index) != std::string::npos || l.two.find(index) != std::string::npos)
        {
            return false;
        }
    }

    if (!startingBlock.blockJump.empty())
    {
        Block& next = getBlockByName(startingBlock.blockJump, _blocks);
        return isUsedInEndingBlock(variable, next, endingBlock);
    }

    Block& nextTrue = getBlockByName(startingBlock.blockIfTrue, _blocks);
    Block& nextFalse = getBlockByName(startingBlock.blockIfFalse, _blocks);

    return isUsedInEndingBlock(variable, nextTrue, endingBlock) 
        && isUsedInEndingBlock(variable, nextFalse, endingBlock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movb $0x1, %bl
cmpb $0x0, 0x98(%rdx)
jne 0x21943
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r13
movq 0x8(%rdx), %rdx
cmpq 0x8(%rcx), %rdx
jne 0x21593
testq %rdx, %rdx
je 0x21943
movq (%r14), %rsi
movq (%r12), %rdi
callq 0x42b0
testl %eax, %eax
je 0x21943
movq %r13, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movb $0x1, 0x98(%r12)
movq 0x20(%r12), %r13
movq 0x28(%r12), %r14
cmpq %r14, %r13
je 0x21706
addq $0x40, %r13
leaq -0x20(%r13), %rbp
movq -0x18(%r13), %rdx
movq 0x8(%r15), %rbx
cmpq %rbx, %rdx
jne 0x215eb
testq %rdx, %rdx
je 0x21923
movq (%r15), %rsi
movq (%rbp), %rdi
callq 0x42b0
testl %eax, %eax
je 0x21923
cmpq %rbx, 0x8(%r13)
jne 0x21611
testq %rbx, %rbx
je 0x21923
movq (%r15), %rsi
movq (%r13), %rdi
movq %rbx, %rdx
callq 0x42b0
testl %eax, %eax
je 0x21923
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
leaq 0x16f9d(%rip), %rsi     # 0x385bd
movq %r15, %rdx
callq 0x5344
movq %rbx, %rdi
leaq 0x15ed2(%rip), %rsi     # 0x37504
callq 0x4510
leaq 0x28(%rsp), %rbx
movq %rbx, 0x18(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2165f
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x21665
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x20(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x21699
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rcx
movq %rbp, %rdi
xorl %edx, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
cmpq $-0x1, %rax
jne 0x2190b
movq 0x20(%rsp), %rcx
movq %r13, %rdi
xorl %edx, %edx
callq 0x44a0
movq %rbx, %rcx
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %rcx, %rdi
je 0x216e8
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42a0
cmpq $-0x1, %rbx
jne 0x21923
leaq 0x68(%r13), %rax
addq $0x28, %r13
cmpq %r14, %r13
movq %rax, %r13
jne 0x215bd
movq 0x80(%r12), %rdx
testq %rdx, %rdx
je 0x217c9
leaq 0x108(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x78(%r12), %rsi
addq %rsi, %rdx
leaq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0xc7aa
movq 0x8(%rsp), %r13
leaq 0x10(%r13), %rdx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2bb9e
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2176f
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xe8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
callq 0xc7aa
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq 0x10(%rsp), %rcx
callq 0x21540
movl %eax, %ebx
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x21943
movq 0xe8(%rsp), %rsi
jmp 0x2193b
leaq 0xc8(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x38(%r12), %rsi
movq 0x40(%r12), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0xc7aa
movq 0x8(%rsp), %rdi
leaq 0x10(%rdi), %r14
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2bb9e
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21826
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xa8(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x58(%r12), %rsi
movq 0x60(%r12), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %r12
movq %r12, %rdi
callq 0xc7aa
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2bb9e
movq %rax, %r14
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
je 0x2187f
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x88(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %r12
movq %r12, %rdi
callq 0xc7aa
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x10(%rsp), %rcx
callq 0x21540
testb %al, %al
je 0x21927
leaq 0x48(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0xc7aa
leaq 0x38(%rsp), %rsi
movq 0x8(%rsp), %rdi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
callq 0x21540
movl %eax, %ebx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x21929
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x21929
cmpq %rbx, %rsi
je 0x21923
movq 0x28(%rsp), %rax
incq %rax
movq %rsi, %rdi
movq %rax, %rsi
callq 0x42a0
xorl %ebx, %ebx
jmp 0x21943
xorl %ebx, %ebx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x21943
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42a0
movl %ebx, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x219ae
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x219ae
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
je 0x21a15
movq 0xa8(%rsp), %rsi
jmp 0x21a0d
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x21a15
movq 0xc8(%rsp), %rsi
jmp 0x21a0d
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x21a15
movq 0x88(%rsp), %rsi
jmp 0x21a0d
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x21a15
movq 0xe8(%rsp), %rsi
jmp 0x21a0d
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x21a15
movq 0x108(%rsp), %rsi
jmp 0x21a0d
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x21a15
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x44c0
nop