// File: ELD[P]HackAssembler/src/main.cpp
// Function: main
int main(int argc, char* argv[])
{
    if (argc <= 1) {
        std::cout << "No target file specified!" << std::endl << "Example usage: ./hackasm [file]" << std::endl;
        return -1;
    }

    std::string file(argv[1]);
    std::ifstream fileHandle(file);

    hack::Parser parser(fileHandle);
    std::string outFileName = file.substr(0, file.find_last_of('.'));
    std::ofstream ofs(outFileName + ".hack");
    parser.translateAssembly(ofs);
    ofs.close();

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x550, %rsp            # imm = 0x550
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jg 0x7fdb
movq 0x4d01a(%rip), %rdi     # 0x54fb0
leaq 0x32067(%rip), %rsi     # 0x3a004
callq 0x6400
movq %rax, %rdi
movq 0x4cfd4(%rip), %rsi     # 0x54f80
callq 0x6460
movq %rax, %rdi
leaq 0x32063(%rip), %rsi     # 0x3a01e
callq 0x6400
movq %rax, %rdi
movq 0x4cfb6(%rip), %rsi     # 0x54f80
callq 0x6460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x81e0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x548(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x540(%rbp)
callq 0x6720
movq -0x548(%rbp), %rsi
movq -0x540(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x8200
jmp 0x8013
leaq -0x31(%rbp), %rdi
callq 0x6480
leaq -0x250(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x6630
jmp 0x8033
leaq -0x2f8(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0xa360
jmp 0x8048
leaq -0x30(%rbp), %rdi
movq %rdi, -0x550(%rbp)
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x67b0
movq -0x550(%rbp), %rsi
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x318(%rbp), %rdi
callq 0x6440
jmp 0x8080
leaq 0x31fb7(%rip), %rdx     # 0x3a03e
leaq -0x538(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x82b0
jmp 0x809c
leaq -0x518(%rbp), %rdi
leaq -0x538(%rbp), %rsi
movl $0x10, %edx
callq 0x67c0
jmp 0x80b6
leaq -0x538(%rbp), %rdi
callq 0x62b0
leaq -0x2f8(%rbp), %rdi
leaq -0x518(%rbp), %rsi
callq 0xb3c0
jmp 0x80d7
leaq -0x518(%rbp), %rdi
callq 0x65c0
jmp 0x80e5
movl $0x0, -0x4(%rbp)
leaq -0x518(%rbp), %rdi
callq 0x6600
leaq -0x318(%rbp), %rdi
callq 0x62b0
leaq -0x2f8(%rbp), %rdi
callq 0x8330
leaq -0x250(%rbp), %rdi
callq 0x6100
leaq -0x30(%rbp), %rdi
callq 0x62b0
jmp 0x81e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x6480
jmp 0x81ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x81d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x81c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x81bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x81b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x538(%rbp), %rdi
callq 0x62b0
jmp 0x81b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x518(%rbp), %rdi
callq 0x6600
leaq -0x318(%rbp), %rdi
callq 0x62b0
leaq -0x2f8(%rbp), %rdi
callq 0x8330
leaq -0x250(%rbp), %rdi
callq 0x6100
leaq -0x30(%rbp), %rdi
callq 0x62b0
jmp 0x81ec
movl -0x4(%rbp), %eax
addq $0x550, %rsp            # imm = 0x550
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x6710
nopw %cs:(%rax,%rax)
nop