// File: saumya-prakash[P]AssemblerEmulator/asm.cpp
// Function: main
int main(int argc, char **argv)
{
    if(argc==1)
    {
        cout<<"Fatal Error: No input file specified."<<endl;
        exit(EXIT_FAILURE);
    }

    ifstream src;

    src.open(argv[1], ofstream::in);

    if(!src)
    {
        cout<<"Error in opening file"<<endl;
        exit(EXIT_FAILURE);
    }

    Assembler a1(src, argv[1]);

    a1.assemble();
    a1.generate_listing_file();
    a1.generate_log_file();

    if(a1.get_assembly_status()==false)
    {   
        cout<<endl<<"Errors: "<<endl;
        a1.print_errors(cout);
        cout<<endl;
    }

    if(a1.get_assembly_status()==true)
    {
        cout<<"Assembled successfully"<<endl;
        cout<<endl;
    }


    if(a1.get_warning_status()==true)
    {
        cout<<endl<<"Warnings: "<<endl;
        a1.print_warnings(cout);
        cout<<endl;
    }


    src.close();
    

    exit(EXIT_SUCCESS);
}

// Assembly:
subq $0x3e8, %rsp            # imm = 0x3E8
movl $0x0, 0x3e4(%rsp)
movl %edi, 0x3e0(%rsp)
movq %rsi, 0x3d8(%rsp)
cmpl $0x1, 0x3e0(%rsp)
jne 0x4577
movq 0x17a86(%rip), %rdi     # 0x1bfd8
leaq 0xfaab(%rip), %rsi      # 0x14004
callq 0x3270
movq %rax, %rdi
movq 0x17a60(%rip), %rsi     # 0x1bfc8
callq 0x32d0
movl $0x1, %edi
callq 0x3370
leaq 0x1d0(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x3330
movq 0x60(%rsp), %rdi
movq 0x3d8(%rsp), %rax
movq 0x8(%rax), %rsi
movl $0x8, %edx
callq 0x31a0
jmp 0x45a6
movq 0x1d0(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x1d0(%rsp,%rax), %rdi
callq 0x3130
movb %al, 0x5f(%rsp)
jmp 0x45c5
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x45cf
jmp 0x461f
movq 0x17a02(%rip), %rdi     # 0x1bfd8
leaq 0xfa4d(%rip), %rsi      # 0x1402a
callq 0x3270
movq %rax, 0x50(%rsp)
jmp 0x45e9
movq 0x50(%rsp), %rdi
movq 0x179d3(%rip), %rsi     # 0x1bfc8
callq 0x32d0
jmp 0x45fc
movl $0x1, %edi
callq 0x3370
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x48be
movq 0x3d8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0x6f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x34a0
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0x70(%rsp), %rdi
callq 0x48e0
jmp 0x4655
leaq 0x90(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x49a0
jmp 0x4671
leaq 0x70(%rsp), %rdi
callq 0x3180
leaq 0x6f(%rsp), %rdi
callq 0x32f0
leaq 0x90(%rsp), %rdi
callq 0x6480
jmp 0x4694
leaq 0x90(%rsp), %rdi
callq 0x9fc0
jmp 0x46a3
leaq 0x90(%rsp), %rdi
callq 0xad40
jmp 0x46b2
leaq 0x90(%rsp), %rdi
callq 0x4ac0
movb %al, 0x3f(%rsp)
jmp 0x46c5
movb 0x3f(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x47b2
movq 0x178fa(%rip), %rdi     # 0x1bfd8
movq 0x178e3(%rip), %rsi     # 0x1bfc8
callq 0x32d0
movq %rax, 0x30(%rsp)
jmp 0x46f1
movq 0x30(%rsp), %rdi
leaq 0xf943(%rip), %rsi      # 0x14040
callq 0x3270
movq %rax, 0x28(%rsp)
jmp 0x4709
movq 0x28(%rsp), %rdi
movq 0x178b3(%rip), %rsi     # 0x1bfc8
callq 0x32d0
jmp 0x471c
movq 0x178b5(%rip), %rsi     # 0x1bfd8
leaq 0x90(%rsp), %rdi
callq 0xb4c0
jmp 0x4732
movq 0x1789f(%rip), %rdi     # 0x1bfd8
movq 0x17888(%rip), %rsi     # 0x1bfc8
callq 0x32d0
jmp 0x4747
jmp 0x47b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x477d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x3180
leaq 0x6f(%rsp), %rdi
callq 0x32f0
jmp 0x48be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x4b00
jmp 0x48be
leaq 0x90(%rsp), %rdi
callq 0x4ac0
movb %al, 0x27(%rsp)
jmp 0x47c5
movb 0x27(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x4817
movq 0x177fe(%rip), %rdi     # 0x1bfd8
leaq 0xf868(%rip), %rsi      # 0x14049
callq 0x3270
movq %rax, 0x18(%rsp)
jmp 0x47ed
movq 0x18(%rsp), %rdi
movq 0x177cf(%rip), %rsi     # 0x1bfc8
callq 0x32d0
jmp 0x4800
movq 0x177d1(%rip), %rdi     # 0x1bfd8
movq 0x177ba(%rip), %rsi     # 0x1bfc8
callq 0x32d0
jmp 0x4815
jmp 0x4817
leaq 0x90(%rsp), %rdi
callq 0x4ae0
movb %al, 0x17(%rsp)
jmp 0x482a
movb 0x17(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x48a8
movq 0x17799(%rip), %rdi     # 0x1bfd8
movq 0x17782(%rip), %rsi     # 0x1bfc8
callq 0x32d0
movq %rax, 0x8(%rsp)
jmp 0x4852
movq 0x8(%rsp), %rdi
leaq 0xf802(%rip), %rsi      # 0x14060
callq 0x3270
movq %rax, (%rsp)
jmp 0x4869
movq (%rsp), %rdi
movq 0x17754(%rip), %rsi     # 0x1bfc8
callq 0x32d0
jmp 0x487b
movq 0x17756(%rip), %rsi     # 0x1bfd8
leaq 0x90(%rsp), %rdi
callq 0xb770
jmp 0x4891
movq 0x17740(%rip), %rdi     # 0x1bfd8
movq 0x17729(%rip), %rsi     # 0x1bfc8
callq 0x32d0
jmp 0x48a6
jmp 0x48a8
leaq 0x1d0(%rsp), %rdi
callq 0x30a0
jmp 0x48b7
xorl %edi, %edi
callq 0x3370
leaq 0x1d0(%rsp), %rdi
callq 0x30b0
movq 0x1c8(%rsp), %rdi
callq 0x3490
nopl (%rax,%rax)