// File: salihbektas[P]Simple-CPU-emulator/main.cpp
// Function: main
int main(int argc, char* argv[])
{
    int option;

    //Console argumans check
    if(argc != 3){
        cerr<< "Wrong Usage" << endl
            << "Example Usage: "<<argv[0]<<" <file_name.txt> <option>" << endl;
        return 1;
    }
    //Option check
    if (argv[2][0] != '0' && argv[2][0] != '1' && argv[2][0] != '2'){
        cerr << "Wrong option" << endl
             << "Option must be 0, 1 or 2" << endl;
        return 1;
    }

    if (argv[2][0] == '0')
        option = 0;
    else if (argv[2][0] == '1')
        option = 1;
    else if (argv[2][0] == '2')
        option = 2;

    CPU myCPU;
    CPUProgramDyn myProg(argv[1]);
    Memory myMemory;

    Computer myComputer(myCPU, myProg, myMemory, option);
    myComputer.execute();

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x24d9
movq 0xdb7a(%rip), %rdi      # 0xfff0
leaq 0xab87(%rip), %rsi      # 0xd004
callq 0x20f0
movq %rax, %rdi
movq 0xdb34(%rip), %rsi      # 0xffc0
callq 0x2100
movq %rax, %rdi
leaq 0xab75(%rip), %rsi      # 0xd010
callq 0x20f0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0xab67(%rip), %rsi      # 0xd020
callq 0x20f0
movq %rax, %rdi
movq 0xdaf8(%rip), %rsi      # 0xffc0
callq 0x2100
movl $0x1, -0x4(%rbp)
jmp 0x26ec
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
je 0x2555
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x31, %eax
je 0x2555
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x32, %eax
je 0x2555
movq 0xdae0(%rip), %rdi      # 0xfff0
leaq 0xab23(%rip), %rsi      # 0xd03a
callq 0x20f0
movq %rax, %rdi
movq 0xda9a(%rip), %rsi      # 0xffc0
callq 0x2100
movq %rax, %rdi
leaq 0xab12(%rip), %rsi      # 0xd047
callq 0x20f0
movq %rax, %rdi
movq 0xda7c(%rip), %rsi      # 0xffc0
callq 0x2100
movl $0x1, -0x4(%rbp)
jmp 0x26ec
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0x256e
movl $0x0, -0x14(%rbp)
jmp 0x25a2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0x2587
movl $0x1, -0x14(%rbp)
jmp 0x25a0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x32, %eax
jne 0x259e
movl $0x2, -0x14(%rbp)
jmp 0x25a0
jmp 0x25a2
leaq -0x30(%rbp), %rdi
callq 0x28a0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0xa380
leaq -0x128(%rbp), %rdi
callq 0x2730
jmp 0x25ca
movups -0x30(%rbp), %xmm0
movups -0x24(%rbp), %xmm1
movups %xmm1, -0x274(%rbp)
movaps %xmm0, -0x280(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xa1f0
jmp 0x25f2
leaq -0x378(%rbp), %rdi
movq %rdi, -0x380(%rbp)
leaq -0x128(%rbp), %rsi
movl $0xc8, %edx
callq 0x20b0
movq -0x380(%rbp), %rsi
movl -0x14(%rbp), %edx
movq %rsp, %rax
movq %rax, %rdi
addq $0x20, %rdi
movl $0x19, %ecx
rep  movsq (%rsi), %es:(%rdi)
movups -0x274(%rbp), %xmm0
movups %xmm0, 0xc(%rax)
movaps -0x280(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x258(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
callq 0xbc70
jmp 0x2657
leaq -0x2b0(%rbp), %rdi
callq 0xa6d0
leaq -0x258(%rbp), %rdi
callq 0xbfc0
jmp 0x2671
movl $0x0, -0x4(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x2710
leaq -0x60(%rbp), %rdi
callq 0xa6d0
jmp 0x26ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x26e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0xa6d0
jmp 0x26e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x2710
leaq -0x60(%rbp), %rdi
callq 0xa6d0
jmp 0x26f8
movl -0x4(%rbp), %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
movq -0x130(%rbp), %rdi
callq 0x21d0
nopw %cs:(%rax,%rax)
nop