// File: /workspace/github_c_makefile_star2_O0/endeav0r[P]hsvm/src/assembler.c
// Function: main
int main (int argc, char * argv[])
{
    int c;
    char * output_filename = NULL;

    while ((c = getopt(argc, argv, "o:")) != -1) {
        switch (c) {
        case 'o' :
            output_filename = optarg;
            break;
        case '?' :
            if (optopt == 'o')
                printf("argument o requires argument\n");
            else
                printf("unknown argument %c\n", c);
            return -1;
        }
    }

    if (output_filename == NULL) {
        printf("usage: %s -o filename <sources>\n", argv[0]);
        printf("\n");
        printf(" -o specifies output filename\n");
        printf(" <sources> specifices assembly files for input\n");
        return -1;
    }

    struct _token * first = NULL;
    struct _token * last = NULL;
    int source_i;

    for (source_i = optind; source_i < argc; source_i++) {
        if (first == NULL) {
            first = get_tokens(argv[source_i]);
            if (first == NULL)
                return -1;
            last = first;
        }
        else {
            last->next = get_tokens(argv[source_i]);
            if (last->next == NULL)
                return -1;
        }
        while (last->next != NULL) { last = last->next; }
    }

    unsigned char * mem;
    mem = (unsigned char *) malloc(0x10000);
    int assembled_bytes = assemble(first, mem);

    write_mem(output_filename, mem, assembled_bytes);

    free(mem);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x618c(%rip), %rdx      # 0x9248
callq 0x2280
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x312b
movl -0x14(%rbp), %eax
movl %eax, -0x48(%rbp)
subl $0x3f, %eax
je 0x30f0
jmp 0x30d6
movl -0x48(%rbp), %eax
subl $0x6f, %eax
jne 0x3129
jmp 0x30e0
movq 0x8ee9(%rip), %rax      # 0xbfd0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x3129
movq 0x8ee9(%rip), %rax      # 0xbfe0
cmpl $0x6f, (%rax)
jne 0x310c
leaq 0x6148(%rip), %rdi      # 0x924b
movb $0x0, %al
callq 0x2120
jmp 0x311d
movl -0x14(%rbp), %esi
leaq 0x6153(%rip), %rdi      # 0x9269
movb $0x0, %al
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x327c
jmp 0x30ae
cmpq $0x0, -0x20(%rbp)
jne 0x317d
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x613e(%rip), %rdi      # 0x927e
movb $0x0, %al
callq 0x2120
leaq 0x66c4(%rip), %rdi      # 0x9812
movb $0x0, %al
callq 0x2120
leaq 0x6143(%rip), %rdi      # 0x929f
movb $0x0, %al
callq 0x2120
leaq 0x6154(%rip), %rdi      # 0x92be
movb $0x0, %al
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x327c
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq 0x8e34(%rip), %rax      # 0xbfc8
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x323b
cmpq $0x0, -0x28(%rbp)
jne 0x31de
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2f00
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x31d4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x327c
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x3210
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2f00
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x320e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x327c
jmp 0x3210
jmp 0x3212
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x322b
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x3212
jmp 0x322d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3199
movl $0x10000, %edi          # imm = 0x10000
callq 0x21e0
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2700
movzwl %ax, %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x3000
movq -0x40(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop