// File: Merulo[P]CompilerJFTT/src/Main.cpp
// Function: main
int main(int argc, char** argv)
{
    if (argc < 3)
    {
        std::cout<<"USAGE: ./kompilator input output"<<std::endl;
        std::cout<<"Not enough arguments\n";
        return 1;
    }
    d.FIR->setSymbolTable(d.ST);
    yyin = fopen(argv[1], "r");
    yyparse();

    bool emulator = true;

    for(int i = 0; i < argc; i++)
    {
        std::string str = argv[i];
        std::string output;
        if (i + 1 < argc)
        {
            output = argv[i+1];
        }
        if (str == "-em")
        {
            emulator = false;
        }        
        if (str == "-FIR")
        {
            d.FIR->print(output);
            return 0;
        }
        if (str == "-SIR")
        {
            d.convertToSIR();
            d.SIR->print(output);   
            return 0;
        }
        if (str == "-TIR")
        {
            d.convertToSIR();
            d.convertToTIR();
            d.TIR->print(output);
            return 0;
        }
        if (str == "-FOIR")
        {
            d.convertToSIR();
            d.convertToTIR();
            d.convertToFOIR(argv[2], emulator);
            d.FOIR->print(output);
            return 0;
        }
    }

    d.convertToSIR();
    d.convertToTIR();
    d.convertToFOIR(argv[2], emulator);
    d.converToFIIR();
    d.FIIR->print(argv[2]);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x48610
movq 0x209ea(%rip), %rdi     # 0x68fc0
leaq 0x9fa2(%rip), %rsi      # 0x5257f
callq 0x4320
movq %rax, %rdi
movq 0x209a4(%rip), %rsi     # 0x68f90
callq 0x4380
movq 0x209c8(%rip), %rdi     # 0x68fc0
leaq 0x9fa1(%rip), %rsi      # 0x525a0
callq 0x4320
movl $0x1, -0x4(%rbp)
jmp 0x48b8b
leaq 0x20e91(%rip), %rdi     # 0x694a8
callq 0x48ee0
movq %rax, -0x110(%rbp)
leaq 0x20e6e(%rip), %rsi     # 0x69498
leaq -0x20(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x38f80
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rsi
callq 0x3d850
jmp 0x4864f
leaq -0x20(%rbp), %rdi
callq 0xcec0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xa20b(%rip), %rsi      # 0x52872
callq 0x4400
movq %rax, 0x20d9d(%rip)     # 0x69410
callq 0x44c20
movb $0x1, -0x2d(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x489ff
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x120(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x4600
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x4f10
jmp 0x486cb
leaq -0x59(%rbp), %rdi
callq 0x43b0
leaq -0x80(%rbp), %rdi
callq 0x44b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jge 0x48747
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rsi
leaq -0x80(%rbp), %rdi
callq 0x44a0
jmp 0x48700
jmp 0x48747
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xcec0
jmp 0x48b97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x43b0
jmp 0x48b97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x489e8
leaq 0x9e68(%rip), %rsi      # 0x525b6
leaq -0x58(%rbp), %rdi
callq 0xdd10
movb %al, -0x121(%rbp)
jmp 0x4875f
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x4876b
jmp 0x4876f
movb $0x0, -0x2d(%rbp)
leaq 0x9e44(%rip), %rsi      # 0x525ba
leaq -0x58(%rbp), %rdi
callq 0xdd10
movb %al, -0x122(%rbp)
jmp 0x48787
movb -0x122(%rbp), %al
testb $0x1, %al
jne 0x48793
jmp 0x487c3
leaq 0x20d0e(%rip), %rdi     # 0x694a8
callq 0x48ee0
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x3d870
jmp 0x487ad
movl $0x0, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x489b5
leaq 0x9df5(%rip), %rsi      # 0x525bf
leaq -0x58(%rbp), %rdi
callq 0xdd10
movb %al, -0x123(%rbp)
jmp 0x487db
movb -0x123(%rbp), %al
testb $0x1, %al
jne 0x487e7
jmp 0x48825
leaq 0x20caa(%rip), %rdi     # 0x69498
callq 0x490f0
jmp 0x487f5
leaq 0x20cbc(%rip), %rdi     # 0x694b8
callq 0x49200
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x3d870
jmp 0x4880f
movl $0x0, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x489b5
leaq 0x9d98(%rip), %rsi      # 0x525c4
leaq -0x58(%rbp), %rdi
callq 0xdd10
movb %al, -0x124(%rbp)
jmp 0x4883d
movb -0x124(%rbp), %al
testb $0x1, %al
jne 0x48849
jmp 0x48895
leaq 0x20c48(%rip), %rdi     # 0x69498
callq 0x490f0
jmp 0x48857
leaq 0x20c3a(%rip), %rdi     # 0x69498
callq 0x49220
jmp 0x48865
leaq 0x20c5c(%rip), %rdi     # 0x694c8
callq 0x49330
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x3d870
jmp 0x4887f
movl $0x0, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x489b5
leaq 0x9d2d(%rip), %rsi      # 0x525c9
leaq -0x58(%rbp), %rdi
callq 0xdd10
movb %al, -0x125(%rbp)
jmp 0x488ad
movb -0x125(%rbp), %al
testb $0x1, %al
jne 0x488bc
jmp 0x489ab
leaq 0x20bd5(%rip), %rdi     # 0x69498
callq 0x490f0
jmp 0x488ca
leaq 0x20bc7(%rip), %rdi     # 0x69498
callq 0x49220
jmp 0x488d8
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x138(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x4600
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0x4f10
jmp 0x48916
movzbl -0x2d(%rbp), %edx
andl $0x1, %edx
leaq 0x20b74(%rip), %rdi     # 0x69498
leaq -0xa8(%rbp), %rsi
callq 0x49350
jmp 0x48932
leaq -0xa8(%rbp), %rdi
callq 0x46e8
leaq -0xa9(%rbp), %rdi
callq 0x43b0
leaq 0x20b87(%rip), %rdi     # 0x694d8
callq 0x494d0
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x3d870
jmp 0x48964
movl $0x0, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x489b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4899d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x46e8
leaq -0xa9(%rbp), %rdi
callq 0x43b0
jmp 0x489e8
movl $0x0, -0x84(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x46e8
leaq -0x58(%rbp), %rdi
callq 0x46e8
movl -0x84(%rbp), %eax
testl %eax, %eax
je 0x489d8
jmp 0x489d3
jmp 0x48b8b
jmp 0x489da
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x48683
leaq -0x80(%rbp), %rdi
callq 0x46e8
leaq -0x58(%rbp), %rdi
callq 0x46e8
jmp 0x48b97
leaq 0x20a92(%rip), %rdi     # 0x69498
movq %rdi, -0x150(%rbp)
callq 0x490f0
movq -0x150(%rbp), %rdi
callq 0x49220
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x148(%rbp)
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x4600
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
leaq -0xd0(%rbp), %rdi
callq 0x4f10
jmp 0x48a5c
movzbl -0x2d(%rbp), %edx
andl $0x1, %edx
leaq 0x20a2e(%rip), %rdi     # 0x69498
leaq -0xd0(%rbp), %rsi
callq 0x49350
jmp 0x48a78
leaq -0xd0(%rbp), %rdi
callq 0x46e8
leaq -0xd1(%rbp), %rdi
callq 0x43b0
leaq 0x20a01(%rip), %rdi     # 0x69498
callq 0x494f0
leaq 0x20a45(%rip), %rdi     # 0x694e8
callq 0x495a0
movq %rax, -0x168(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x160(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x4600
movq -0x160(%rbp), %rsi
movq -0x158(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x4f10
jmp 0x48aed
movq -0x168(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x3d870
jmp 0x48b02
leaq -0xf8(%rbp), %rdi
callq 0x46e8
leaq -0xf9(%rbp), %rdi
callq 0x43b0
movl $0x0, -0x4(%rbp)
jmp 0x48b8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x48b49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x46e8
leaq -0xd1(%rbp), %rdi
callq 0x43b0
jmp 0x48b97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x48b7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x46e8
leaq -0xf9(%rbp), %rdi
callq 0x43b0
jmp 0x48b97
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x45f0