// File: /workspace/github_cpp_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movb $0x1, %bpl
cmpb $0x0, 0x98(%rdx)
jne 0x151d0
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, %rdi
movq %rcx, %rsi
callq 0x8141
testb %al, %al
jne 0x151d0
movq %r14, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
movb $0x1, 0x98(%r12)
movq 0x20(%r12), %r13
movq %r12, 0x10(%rsp)
movq 0x28(%r12), %rax
movq %rax, 0x20(%rsp)
leaq 0xe8(%rsp), %rbx
leaq 0x108(%rsp), %r14
cmpq 0x20(%rsp), %r13
je 0x15075
addq $0x20, %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x8141
testb %al, %al
jne 0x15104
addq $0x20, %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x8141
testb %al, %al
jne 0x15104
movq %rbx, %rdi
leaq 0xf5b3(%rip), %rsi      # 0x245bd
movq %r15, %rdx
callq 0x4acd
movq %r14, %rdi
movq %rbx, %rsi
leaq 0xe4e5(%rip), %rdx      # 0x23504
callq 0x4a8f
movq %rbx, %rdi
callq 0x4548
addq $-0x20, %r13
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4530
cmpq $-0x1, %rax
jne 0x150f7
leaq 0x20(%r13), %rdi
xorl %ebp, %ebp
movq %r14, %rsi
xorl %edx, %edx
callq 0x4530
movq %rax, %r12
movq %r14, %rdi
callq 0x4548
addq $0x48, %r13
cmpq $-0x1, %r12
je 0x14fc7
jmp 0x151d0
movq 0x18(%rsp), %r13
leaq 0x10(%r13), %rbx
movq 0x10(%rsp), %rbp
cmpq $0x0, 0x80(%rbp)
je 0x1510b
addq $0x78, %rbp
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4390
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1b1b0
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x4548
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x4390
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq 0x8(%rsp), %rcx
callq 0x14f50
movl %eax, %ebp
leaq 0xa8(%rsp), %rdi
jmp 0x151cb
leaq 0x108(%rsp), %rdi
callq 0x4548
xorl %ebp, %ebp
jmp 0x151d0
leaq 0x38(%rbp), %rsi
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x4390
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1b1b0
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x4548
addq $0x58, %rbp
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4390
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x1b1b0
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x4548
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x4390
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq 0x8(%rsp), %r14
movq %r14, %rcx
callq 0x14f50
testb %al, %al
je 0x151c4
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x4390
leaq 0x28(%rsp), %rsi
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x14f50
movl %eax, %ebp
leaq 0x28(%rsp), %rdi
callq 0x4548
jmp 0x151c6
xorl %ebp, %ebp
leaq 0x48(%rsp), %rdi
callq 0x4548
movl %ebp, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4548
jmp 0x1520d
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x15239
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x15239
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x15239
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x15239
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x15239
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490