// File: /workspace/github_c_makefile_star2_O2/pahihu[P]mixal/main.c
// Function: main
int main(int argc, char **argv)
{
    char title[8];
    Flag dump = false, punch = false, asm_only = false;
    
    precompute_field_data();

    /* Assemble the input: */
    strcpy(title, "OBJS");
    install_error_handler(assembler_error);
    if (argc == 1) {
        set_configuration(0);                           /* default config */
        assemble_file("-");
    } else {
        int i, j;
        unsigned flags;

    /* --- Process flags --- */
        flags = 0;
        for (i = 1; i < argc; ++i) {
            if (*argv[i] == '-')
                switch (argv[i][1]) {
		        case 'a': asm_only = true; break;
                case 'b': flags += MIXCONFIG_BINARY; break;
                case 'c': flags += MIXCONFIG_CORE; break;
                case 'd': dump = true; break;
                case 'e':
                    if (++i == argc) usage();
                    entry_point = atol(argv[i]);
                    break;
                case 'f': flags += MIXCONFIG_FLOAT; break;
                case 'g':
                    flags += MIXCONFIG_PUSHGO;
                    if (i+1 != argc) {
                        if (isdigit(*argv[i+1]))
                            io_set_go_device(atol(argv[++i]));
                    }
                    break;
                case 'h': usage(); break;
                case 'i': flags += MIXCONFIG_INTERRUPT; break;
                case 'm': flags += MIXCONFIG_MASTER; break;
                case 'o': punch = true; break;
                case 'r': io_redirect(); break;
                case 't':
                    if (++i == argc) usage();
                    set_trace_count(atol(argv[i]));
                    break;
                case 'x': flags += MIXCONFIG_INDEX; break;
                case 'v': VERBOSE = true; break;
                default: usage();
                }
        }
        set_configuration(flags);

        /* --- Assemble MIXAL source files --- */
        for (i = 1; i < argc; i++) {
            if (*argv[i] == '-') {
                char flag = argv[i][1];
                if (flag == 'e' || flag == 't')
                    i++;
                else if (flag == 'g') {
                    if ((i+1 != argc) && isdigit(*argv[i+1]))
                        i++;
                }
            } else {
                for (j = 0; j < 5; j++) {
                    int ch = argv[i][j];
                    if (ch == 0 || ch == '.')
                        break;
                    title[j] = toupper(ch);
                }
                title[j] = '\0';
                assemble_file(argv[i]);
            }
        }
    }
    resolve_generated_futures();
    if (num_errors != 0) {
        fprintf(stderr, "%u errors found\n", num_errors);
        exit(1);
    }

    /* --- Punch object deck --- */
    if (punch)
        punch_object_deck(title, entry_point);

    /* --- Check assemble only --- */
    if (asm_only)
        return 0;

    /* Now run it: */
    set_initial_state();
    {
        clock_t finish, start = clock();
        run();
        finish = clock();
        fprintf(stderr, "%g seconds elapsed\n", 
                (float)(finish - start) / CLOCKS_PER_SEC);
    }
    print_CPU_state();
    if (dump) print_DUMP();
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl %edi, %ebp
callq 0x3718
movb $0x0, 0x14(%rsp)
movl $0x534a424f, 0x10(%rsp) # imm = 0x534A424F
leaq 0x2cf(%rip), %rax       # 0x5ba8
movq %rax, 0xb418(%rip)      # 0x10cf8
cmpl $0x1, %ebp
jne 0x5905
xorl %edi, %edi
callq 0x65fa
leaq 0x3a5e(%rip), %rdi      # 0x9351
callq 0x5c14
movb $0x1, %bl
movb $0x1, %r14b
movb $0x1, %bpl
jmp 0x5aef
pushq $0x1
popq %r15
xorl %r14d, %r14d
leaq 0x3e71(%rip), %r12      # 0x9784
movl %r15d, %r13d
movl $0x0, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
cmpl %ebp, %r13d
jge 0x5a37
movslq %r13d, %rax
movq (%rbx,%rax,8), %rax
cmpb $0x2d, (%rax)
jne 0x5a2f
movzbl 0x1(%rax), %eax
addl $-0x61, %eax
cmpl $0x17, %eax
ja 0x5b83
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl %r15d, 0xc(%rsp)
jmp 0x5a2f
movl $0x1, 0xb36c(%rip)      # 0x10ce0
jmp 0x5a2f
addl $0x10, %r14d
leal 0x1(%r13), %r15d
cmpl %ebp, %r15d
je 0x59af
callq 0x32d0
movq (%rax), %rax
movslq %r15d, %rcx
movq (%rbx,%rcx,8), %rdi
movsbq (%rdi), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x59af
callq 0x3240
movl %eax, %edi
callq 0x48a0
movl %r15d, %r13d
pushq $0x1
popq %r15
jmp 0x5a2f
incl %r14d
jmp 0x5a2f
callq 0x4898
jmp 0x5a2f
addl $0x8, %r14d
jmp 0x5a2f
incl %r13d
cmpl %ebp, %r13d
je 0x5b83
movslq %r13d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x3240
leaq 0x9d52(%rip), %rcx      # 0xf738
movl %eax, (%rcx)
jmp 0x5a2f
addl $0x2, %r14d
jmp 0x5a2f
addl $0x4, %r14d
jmp 0x5a2f
movl %r15d, 0x8(%rsp)
jmp 0x5a2f
movl %r15d, 0x4(%rsp)
jmp 0x5a2f
subl $-0x80, %r14d
jmp 0x5a2f
incl %r13d
cmpl %ebp, %r13d
je 0x5b83
movslq %r13d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x3240
movl %eax, %edi
callq 0x6584
jmp 0x5a2f
addl $0x20, %r14d
incl %r13d
jmp 0x592e
movl %r14d, %edi
callq 0x65fa
pushq $0x1
popq %r15
cmpl %ebp, %r15d
jge 0x5ad5
movslq %r15d, %rax
movq (%rbx,%rax,8), %r14
cmpb $0x2d, (%r14)
jne 0x5a72
movzbl 0x1(%r14), %eax
cmpl $0x74, %eax
je 0x5a6d
cmpl $0x67, %eax
je 0x5aae
cmpl $0x65, %eax
jne 0x5aa9
incl %r15d
jmp 0x5aa9
xorl %r12d, %r12d
cmpq $0x5, %r12
je 0x5a9b
movzbl (%r14,%r12), %eax
testl %eax, %eax
je 0x5a9b
cmpl $0x2e, %eax
je 0x5a9b
movsbl %al, %edi
callq 0x30a0
movb %al, 0x10(%rsp,%r12)
incq %r12
jmp 0x5a75
movb $0x0, 0x10(%rsp,%r12)
movq %r14, %rdi
callq 0x5c14
incl %r15d
jmp 0x5a43
leal 0x1(%r15), %r14d
cmpl %ebp, %r14d
je 0x5aa9
callq 0x32d0
movq (%rax), %rax
movslq %r14d, %rcx
movq (%rbx,%rcx,8), %rcx
movsbq (%rcx), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
cmovnel %r14d, %r15d
jmp 0x5aa9
cmpl $0x0, 0x4(%rsp)
sete %r14b
cmpl $0x0, 0xc(%rsp)
sete %bl
cmpl $0x0, 0x8(%rsp)
sete %bpl
callq 0x8404
movl 0xb206(%rip), %edx      # 0x10d00
testl %edx, %edx
jne 0x5b88
testb %r14b, %r14b
jne 0x5b1a
leaq 0x9c2a(%rip), %rax      # 0xf738
movl (%rax), %esi
leaq 0x10(%rsp), %rdi
callq 0x4c0f
testb %bl, %bl
jne 0x5b2f
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x658b
callq 0x30e0
movq %rax, %rbx
callq 0x6d09
callq 0x30e0
movq 0x94ab(%rip), %rcx      # 0xeff8
subq %rbx, %rax
cvtsi2ss %rax, %xmm0
movq (%rcx), %rdi
divss 0x3c20(%rip), %xmm0     # 0x9780
cvtss2sd %xmm0, %xmm0
leaq 0x3cf6(%rip), %rsi      # 0x9861
movb $0x1, %al
callq 0x31c0
callq 0x6744
testb %bpl, %bpl
jne 0x5b1e
callq 0x698a
jmp 0x5b1e
callq 0x5d5a
movq 0x9469(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x3cb7(%rip), %rsi      # 0x9850
xorl %eax, %eax
callq 0x31c0
pushq $0x1
popq %rdi
callq 0x3290