// File: 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:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rsi, 0x60(%rsp)
movq %rdi, 0x1d8(%rsp)
movq %rsi, 0x1d0(%rsp)
movq %rdx, 0x1c8(%rsp)
movq %rcx, 0x1c0(%rsp)
movq 0x1d8(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x1c8(%rsp), %rax
testb $0x1, 0x98(%rax)
je 0x2dad7
movb $0x1, 0x1e7(%rsp)
jmp 0x2dfe6
movq 0x1c8(%rsp), %rdi
movq 0x1c0(%rsp), %rsi
callq 0x29d70
testb $0x1, %al
jne 0x2daf2
jmp 0x2daff
movb $0x1, 0x1e7(%rsp)
jmp 0x2dfe6
movq 0x1c8(%rsp), %rax
movb $0x1, 0x98(%rax)
movq 0x1c8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0xe3f0
movq %rax, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0xe380
movq %rax, 0x1a8(%rsp)
leaq 0x1b0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0xec10
testb $0x1, %al
jne 0x2db6a
jmp 0x2dcc7
leaq 0x1b0(%rsp), %rdi
callq 0xfb10
movq 0x60(%rsp), %rsi
movq %rax, 0x1a0(%rsp)
movq 0x1a0(%rsp), %rdi
addq $0x20, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x2dbb5
movq 0x60(%rsp), %rsi
movq 0x1a0(%rsp), %rdi
addq $0x40, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x2dbb5
jmp 0x2dbc2
movb $0x0, 0x1e7(%rsp)
jmp 0x2dfe6
movq 0x60(%rsp), %rdx
leaq 0x24b01(%rip), %rsi     # 0x526cf
leaq 0x160(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x5070
movq 0x58(%rsp), %rsi
leaq 0x23948(%rip), %rdx     # 0x51534
leaq 0x180(%rsp), %rdi
callq 0x4fd0
jmp 0x2dbfb
leaq 0x160(%rsp), %rdi
callq 0x46e8
movq 0x1a0(%rsp), %rdi
addq $0x20, %rdi
leaq 0x180(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
cmpq $-0x1, %rax
jne 0x2dc4e
movq 0x1a0(%rsp), %rdi
addq $0x40, %rdi
leaq 0x180(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
cmpq $-0x1, %rax
je 0x2dc89
movb $0x0, 0x1e7(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x2dc94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x46e8
jmp 0x2dff7
movl $0x0, 0x150(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x46e8
movl 0x150(%rsp), %eax
testl %eax, %eax
je 0x2dcb3
jmp 0x2dcae
jmp 0x2dfe6
jmp 0x2dcb5
leaq 0x1b0(%rsp), %rdi
callq 0xf950
jmp 0x2db4c
movq 0x1c8(%rsp), %rdi
addq $0x78, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x2dddc
movq 0x1c8(%rsp), %rsi
addq $0x78, %rsi
leaq 0x128(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x4180
movq 0x68(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x50(%rsp)
jmp 0x2dd1b
leaq 0x128(%rsp), %rdi
callq 0x46e8
movq 0x50(%rsp), %rax
movq 0x60(%rsp), %rsi
movq %rax, 0x148(%rsp)
leaq 0x108(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x4180
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x148(%rsp), %rdx
movq 0x1c0(%rsp), %rcx
callq 0x2da80
movb %al, 0x47(%rsp)
jmp 0x2dd71
movb 0x47(%rsp), %al
andb $0x1, %al
movb %al, 0x1e7(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x46e8
jmp 0x2dfe6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x46e8
jmp 0x2dff7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x46e8
jmp 0x2dff7
movq 0x1c8(%rsp), %rsi
addq $0x38, %rsi
leaq 0xe0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4180
movq 0x68(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x30(%rsp)
jmp 0x2de17
leaq 0xe0(%rsp), %rdi
callq 0x46e8
movq 0x30(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x1c8(%rsp), %rsi
addq $0x58, %rsi
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4180
movq 0x68(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rdi, %rdx
addq $0x10, %rdx
callq 0x3d720
movq %rax, 0x20(%rsp)
jmp 0x2de6c
leaq 0xb8(%rsp), %rdi
callq 0x46e8
movq 0x20(%rsp), %rax
movq 0x60(%rsp), %rsi
movq %rax, 0xd8(%rsp)
leaq 0x98(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x4180
movq 0x68(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x100(%rsp), %rdx
movq 0x1c0(%rsp), %rcx
movb $0x0, 0x77(%rsp)
callq 0x2da80
movb %al, 0x17(%rsp)
jmp 0x2dec7
movb 0x17(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x7(%rsp)
jne 0x2ded8
jmp 0x2df1d
movq 0x60(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x4180
jmp 0x2dee9
movq 0x68(%rsp), %rdi
movb $0x1, 0x77(%rsp)
movq 0xd8(%rsp), %rdx
movq 0x1c0(%rsp), %rcx
leaq 0x78(%rsp), %rsi
callq 0x2da80
movb %al, 0x6(%rsp)
jmp 0x2df13
movb 0x6(%rsp), %al
movb %al, 0x7(%rsp)
jmp 0x2df1d
movb 0x7(%rsp), %al
andb $0x1, %al
movb %al, 0x1e7(%rsp)
testb $0x1, 0x77(%rsp)
jne 0x2df33
jmp 0x2df3d
leaq 0x78(%rsp), %rdi
callq 0x46e8
leaq 0x98(%rsp), %rdi
callq 0x46e8
jmp 0x2dfe6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x46e8
jmp 0x2dff7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x46e8
jmp 0x2dff7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x2dfd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
testb $0x1, 0x77(%rsp)
jne 0x2dfcb
jmp 0x2dfd5
leaq 0x78(%rsp), %rdi
callq 0x46e8
jmp 0x2dfd7
leaq 0x98(%rsp), %rdi
callq 0x46e8
jmp 0x2dff7
movb 0x1e7(%rsp), %al
andb $0x1, %al
addq $0x1e8, %rsp            # imm = 0x1E8
retq
movq 0x158(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)