// File: Merulo[P]CompilerJFTT/src/IRs/FourthIR.cpp
// Function: FourthIR::recursiveUsageTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Block&)
bool FourthIR::recursiveUsageTest(std::string name, Block& b)
{
    if (b.visited)
    {
        return true;
    }
    b.visited = true;

    for(auto& l : b.lines)
    {
        if(l.two == name)
        {
            return false;
        }
        if (l.two.find("(" + name + ")") != std::string::npos)
        {
            return false;
        }
        if (l.one.find("(" + name + ")") != std::string::npos)
        {
            return false;
        }  
        if (l.one == name)
        {
            if (l.operation == "COPY")
            {
                return true;
            }
            if (l.operation == "CONST")
            {
                return true;
            }
            if (l.operation == "READ")
            {
                return true;
            }
            return false;
        }
    }
    if (!b.blockJump.empty())
    {
        Block& nextBlock = getPairByName(b.blockJump).block;
        return recursiveUsageTest(name, nextBlock);
    }
    else if (!b.blockIfFalse.empty())
    {
        Block& blockTrue = getPairByName(b.blockIfTrue).block;
        bool r1 = recursiveUsageTest(name, blockTrue);  
        Block& blockFalse = getPairByName(b.blockIfFalse).block;
        bool r2 = recursiveUsageTest(name, blockFalse);  
        return r1 && r2;
    }
    return true;
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rsi, 0xa0(%rsp)
movq %rdi, 0x258(%rsp)
movq %rsi, 0x250(%rsp)
movq %rdx, 0x248(%rsp)
movq 0x258(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x248(%rsp), %rax
testb $0x1, 0x98(%rax)
je 0x37b35
movb $0x1, 0x267(%rsp)
jmp 0x38169
movq 0x248(%rsp), %rax
movb $0x1, 0x98(%rax)
movq 0x248(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x240(%rsp)
movq 0x240(%rsp), %rdi
callq 0xe3f0
movq %rax, 0x238(%rsp)
movq 0x240(%rsp), %rdi
callq 0xe380
movq %rax, 0x230(%rsp)
leaq 0x238(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0xec10
testb $0x1, %al
jne 0x37ba0
jmp 0x37e31
leaq 0x238(%rsp), %rdi
callq 0xfb10
movq 0xa0(%rsp), %rsi
movq %rax, 0x228(%rsp)
movq 0x228(%rsp), %rdi
addq $0x40, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x37bd4
jmp 0x37be1
movb $0x0, 0x267(%rsp)
jmp 0x38169
movq 0xa0(%rsp), %rdx
movq 0x228(%rsp), %rax
addq $0x40, %rax
movq %rax, 0x90(%rsp)
leaq 0x1aacb(%rip), %rsi     # 0x526cf
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x5070
movq 0x98(%rsp), %rsi
leaq 0x1990c(%rip), %rdx     # 0x51534
leaq 0x208(%rsp), %rdi
callq 0x4fd0
jmp 0x37c37
movq 0x90(%rsp), %rdi
leaq 0x208(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
movq %rax, 0x88(%rsp)
leaq 0x208(%rsp), %rdi
callq 0x46e8
leaq 0x1e8(%rsp), %rdi
callq 0x46e8
movq 0x88(%rsp), %rax
cmpq $-0x1, %rax
je 0x37cb3
movb $0x0, 0x267(%rsp)
jmp 0x38169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
movq 0xa0(%rsp), %rdx
movq 0x228(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x78(%rsp)
leaq 0x1a9fc(%rip), %rsi     # 0x526cf
leaq 0x198(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x5070
movq 0x80(%rsp), %rsi
leaq 0x1983d(%rip), %rdx     # 0x51534
leaq 0x1b8(%rsp), %rdi
callq 0x4fd0
jmp 0x37d06
movq 0x78(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46d0
movq %rax, 0x70(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x46e8
leaq 0x198(%rsp), %rdi
callq 0x46e8
movq 0x70(%rsp), %rax
cmpq $-0x1, %rax
je 0x37d79
movb $0x0, 0x267(%rsp)
jmp 0x38169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
movq 0xa0(%rsp), %rsi
movq 0x228(%rsp), %rdi
addq $0x20, %rdi
callq 0xd2c0
testb $0x1, %al
jne 0x37d9b
jmp 0x37e1d
movq 0x228(%rsp), %rdi
leaq 0x19353(%rip), %rsi     # 0x510fd
callq 0xdd10
testb $0x1, %al
jne 0x37db5
jmp 0x37dc2
movb $0x1, 0x267(%rsp)
jmp 0x38169
movq 0x228(%rsp), %rdi
leaq 0x19791(%rip), %rsi     # 0x51562
callq 0xdd10
testb $0x1, %al
jne 0x37ddc
jmp 0x37de9
movb $0x1, 0x267(%rsp)
jmp 0x38169
movq 0x228(%rsp), %rdi
leaq 0x1973e(%rip), %rsi     # 0x51536
callq 0xdd10
testb $0x1, %al
jne 0x37e03
jmp 0x37e10
movb $0x1, 0x267(%rsp)
jmp 0x38169
movb $0x0, 0x267(%rsp)
jmp 0x38169
jmp 0x37e1f
leaq 0x238(%rsp), %rdi
callq 0xf950
jmp 0x37b82
movq 0x248(%rsp), %rdi
addq $0x78, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x37f40
movq 0x248(%rsp), %rsi
addq $0x78, %rsi
leaq 0x170(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x4180
movq 0xa8(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x39340
movq %rax, 0x68(%rsp)
jmp 0x37e81
leaq 0x170(%rsp), %rdi
callq 0x46e8
movq 0x68(%rsp), %rax
movq 0xa0(%rsp), %rsi
movq %rax, 0x190(%rsp)
leaq 0x150(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x4180
movq 0xa8(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x190(%rsp), %rdx
callq 0x37ae0
movb %al, 0x5f(%rsp)
jmp 0x37ed5
movb 0x5f(%rsp), %al
andb $0x1, %al
movb %al, 0x267(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x46e8
jmp 0x38169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
movq 0x248(%rsp), %rdi
addq $0x58, %rdi
callq 0x45b0
testb $0x1, %al
jne 0x3815f
movq 0x248(%rsp), %rsi
addq $0x38, %rsi
leaq 0x128(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x4180
movq 0xa8(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x39340
movq %rax, 0x48(%rsp)
jmp 0x37f90
leaq 0x128(%rsp), %rdi
callq 0x46e8
movq 0x48(%rsp), %rax
movq 0xa0(%rsp), %rsi
movq %rax, 0x148(%rsp)
leaq 0x100(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x4180
movq 0xa8(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x148(%rsp), %rdx
callq 0x37ae0
movb %al, 0x3f(%rsp)
jmp 0x37fe4
leaq 0x100(%rsp), %rdi
callq 0x46e8
movb 0x3f(%rsp), %al
andb $0x1, %al
movb %al, 0x127(%rsp)
movq 0x248(%rsp), %rsi
addq $0x58, %rsi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x4180
movq 0xa8(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x39340
movq %rax, 0x28(%rsp)
jmp 0x38035
leaq 0xd8(%rsp), %rdi
callq 0x46e8
movq 0x28(%rsp), %rax
movq 0xa0(%rsp), %rsi
movq %rax, 0xf8(%rsp)
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4180
movq 0xa8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0xf8(%rsp), %rdx
callq 0x37ae0
movb %al, 0x1f(%rsp)
jmp 0x38089
leaq 0xb0(%rsp), %rdi
callq 0x46e8
movb 0x1f(%rsp), %al
andb $0x1, %al
movb %al, 0xd7(%rsp)
xorl %eax, %eax
testb $0x1, 0x127(%rsp)
movb %al, 0xf(%rsp)
je 0x380be
movb 0xd7(%rsp), %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x267(%rsp)
jmp 0x38169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e0(%rsp)
movl %eax, 0x1dc(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x46e8
jmp 0x3817a
jmp 0x38161
movb $0x1, 0x267(%rsp)
movb 0x267(%rsp), %al
andb $0x1, %al
addq $0x268, %rsp            # imm = 0x268
retq
movq 0x1e0(%rsp), %rdi
callq 0x45f0
nopw (%rax,%rax)