// File: /workspace/github_c_makefile_star2_O3/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 0x3949
movb $0x0, 0x14(%rsp)
movl $0x534a424f, 0x10(%rsp) # imm = 0x534A424F
leaq -0x28d4(%rip), %rax     # 0x3407
movq %rax, 0xb016(%rip)      # 0x10cf8
cmpl $0x1, %ebp
je 0x5f19
jle 0x5f2e
movl $0x1, %r13d
xorl %r12d, %r12d
leaq 0x3a7f(%rip), %r15      # 0x9780
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
xorl %r14d, %r14d
movslq %r13d, %rax
movq (%rbx,%rax,8), %rax
cmpb $0x2d, (%rax)
jne 0x5e19
movzbl 0x1(%rax), %eax
addl $-0x61, %eax
cmpl $0x17, %eax
ja 0x5f52
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x1, 0x8(%rsp)
jmp 0x5e19
movl $0x1, 0xaf8c(%rip)      # 0x10ce0
jmp 0x5e19
movl %r12d, 0x4(%rsp)
addl $0x10, %r14d
leal 0x1(%r13), %r12d
cmpl %ebp, %r12d
je 0x5d94
callq 0x32d0
movq (%rax), %rax
movslq %r12d, %rcx
movq (%rbx,%rcx,8), %rdi
movsbq (%rdi), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x5d94
callq 0x3240
movl %eax, %edi
callq 0x4bcb
movl %r12d, %r13d
movl 0x4(%rsp), %r12d
jmp 0x5e19
incl %r14d
jmp 0x5e19
callq 0x4bc3
jmp 0x5e19
addl $0x8, %r14d
jmp 0x5e19
incl %r13d
cmpl %ebp, %r13d
je 0x5f52
movslq %r13d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x3240
leaq 0x996c(%rip), %rcx      # 0xf738
movl %eax, (%rcx)
jmp 0x5e19
addl $0x2, %r14d
jmp 0x5e19
addl $0x4, %r14d
jmp 0x5e19
movl $0x1, %r12d
jmp 0x5e19
movl $0x1, 0xc(%rsp)
jmp 0x5e19
subl $-0x80, %r14d
jmp 0x5e19
incl %r13d
cmpl %ebp, %r13d
je 0x5f52
movslq %r13d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x3240
movl %eax, %edi
callq 0x69a0
jmp 0x5e19
addl $0x20, %r14d
incl %r13d
cmpl %ebp, %r13d
jl 0x5d14
testl %r12d, %r12d
sete %r15b
movl %r14d, %edi
callq 0x6a1f
cmpl $0x2, %ebp
jl 0x5ed8
movl $0x1, %r12d
movslq %r12d, %rax
movq (%rbx,%rax,8), %r14
cmpb $0x2d, (%r14)
jne 0x5e69
movzbl 0x1(%r14), %eax
cmpl $0x74, %eax
je 0x5e64
cmpl $0x67, %eax
je 0x5eb0
cmpl $0x65, %eax
jne 0x5ea6
incl %r12d
jmp 0x5ea6
xorl %r13d, %r13d
movzbl (%r14,%r13), %eax
testl %eax, %eax
je 0x5e96
cmpl $0x2e, %eax
je 0x5e96
movsbl %al, %edi
callq 0x30a0
movb %al, 0x10(%rsp,%r13)
incq %r13
cmpq $0x5, %r13
jne 0x5e6c
movl $0x5, %r13d
movl %r13d, %eax
movb $0x0, 0x10(%rsp,%rax)
movq %r14, %rdi
callq 0x5f79
incl %r12d
cmpl %ebp, %r12d
jl 0x5e43
jmp 0x5ed8
leal 0x1(%r12), %r14d
cmpl %ebp, %r14d
je 0x5ea6
callq 0x32d0
movq (%rax), %rax
movslq %r14d, %rcx
movq (%rbx,%rcx,8), %rcx
movsbq (%rcx), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
cmovnel %r14d, %r12d
jmp 0x5ea6
callq 0x8b54
movl 0xae1d(%rip), %edx      # 0x10d00
testl %edx, %edx
jne 0x5f57
cmpl $0x0, 0xc(%rsp)
je 0x5f01
leaq 0x9843(%rip), %rax      # 0xf738
movl (%rax), %esi
leaq 0x10(%rsp), %rdi
callq 0x4f5a
cmpl $0x0, 0x8(%rsp)
je 0x5f47
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
callq 0x6a1f
leaq 0x342a(%rip), %rdi      # 0x9351
callq 0x5f79
jmp 0x5f35
xorl %edi, %edi
callq 0x6a1f
callq 0x8b54
movl 0xadc0(%rip), %edx      # 0x10d00
movb $0x1, %r15b
testl %edx, %edx
jne 0x5f57
movzbl %r15b, %edi
callq 0x3473
jmp 0x5f08
callq 0x60d8
movq 0x909a(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x38e8(%rip), %rsi      # 0x9850
xorl %eax, %eax
callq 0x31c0
movl $0x1, %edi
callq 0x3290