// File: /workspace/github_c_makefile_star2_O1/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 0x3969
movb $0x0, 0x14(%rsp)
movl $0x534a424f, 0x10(%rsp) # imm = 0x534A424F
leaq -0x28a4(%rip), %rax     # 0x3407
movq %rax, 0xb046(%rip)      # 0x10cf8
cmpl $0x1, %ebp
jne 0x5cd7
xorl %edi, %edi
callq 0x6a0b
leaq 0x368c(%rip), %rdi      # 0x9351
callq 0x5f46
movb $0x1, %r12b
movb $0x1, %r13b
movb $0x1, %bl
jmp 0x5ef5
jle 0x5e2d
movl $0x1, %r13d
xorl %r15d, %r15d
leaq 0x3a93(%rip), %r12      # 0x9780
movl $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r14d, %r14d
movslq %r13d, %rax
movq (%rbx,%rax,8), %rax
cmpb $0x2d, (%rax)
jne 0x5e05
movzbl 0x1(%rax), %eax
addl $-0x61, %eax
cmpl $0x17, %eax
ja 0x5f3c
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, 0x4(%rsp)
jmp 0x5e05
movl $0x1, 0xafa0(%rip)      # 0x10ce0
jmp 0x5e05
movl %r15d, 0xc(%rsp)
addl $0x10, %r14d
leal 0x1(%r13), %r15d
cmpl %ebp, %r15d
je 0x5d80
callq 0x32d0
movq (%rax), %rax
movslq %r15d, %rcx
movq (%rbx,%rcx,8), %rdi
movsbq (%rdi), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x5d80
callq 0x3240
movl %eax, %edi
callq 0x4b83
movl %r15d, %r13d
movl 0xc(%rsp), %r15d
jmp 0x5e05
incl %r14d
jmp 0x5e05
callq 0x4b7b
jmp 0x5e05
addl $0x8, %r14d
jmp 0x5e05
incl %r13d
cmpl %ebp, %r13d
je 0x5f3c
movslq %r13d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x3240
leaq 0x9980(%rip), %rcx      # 0xf738
movl %eax, (%rcx)
jmp 0x5e05
addl $0x2, %r14d
jmp 0x5e05
addl $0x4, %r14d
jmp 0x5e05
movl $0x1, %r15d
jmp 0x5e05
movl $0x1, 0x8(%rsp)
jmp 0x5e05
subl $-0x80, %r14d
jmp 0x5e05
incl %r13d
cmpl %ebp, %r13d
je 0x5f3c
movslq %r13d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x3240
movl %eax, %edi
callq 0x698c
jmp 0x5e05
addl $0x20, %r14d
incl %r13d
cmpl %ebp, %r13d
jl 0x5d00
cmpl $0x0, 0x8(%rsp)
sete %r13b
cmpl $0x0, 0x4(%rsp)
sete %r12b
testl %r15d, %r15d
sete 0x4(%rsp)
jmp 0x5e3b
movb $0x1, %r12b
xorl %r14d, %r14d
movb $0x1, %r13b
movb $0x1, 0x4(%rsp)
movl %r14d, %edi
callq 0x6a0b
cmpl $0x2, %ebp
jl 0x5ef1
movb %r12b, 0x8(%rsp)
movl $0x1, %r12d
movslq %r12d, %rax
movq (%rbx,%rax,8), %r14
cmpb $0x2d, (%r14)
jne 0x5e7d
movzbl 0x1(%r14), %eax
cmpl $0x74, %eax
je 0x5e78
cmpl $0x67, %eax
je 0x5ec4
cmpl $0x65, %eax
jne 0x5eba
incl %r12d
jmp 0x5eba
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0x5eaa
cmpl $0x2e, %eax
je 0x5eaa
movsbl %al, %edi
callq 0x30a0
movb %al, 0x10(%rsp,%r15)
incq %r15
cmpq $0x5, %r15
jne 0x5e80
movl $0x5, %r15d
movl %r15d, %eax
movb $0x0, 0x10(%rsp,%rax)
movq %r14, %rdi
callq 0x5f46
incl %r12d
cmpl %ebp, %r12d
jl 0x5e57
jmp 0x5eec
leal 0x1(%r12), %r14d
cmpl %ebp, %r14d
je 0x5eba
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 0x5eba
movb 0x8(%rsp), %r12b
movb 0x4(%rsp), %bl
callq 0x8b34
movl 0xae00(%rip), %edi      # 0x10d00
testl %edi, %edi
jne 0x5f41
testb %r13b, %r13b
jne 0x5f1c
leaq 0x9828(%rip), %rax      # 0xf738
movl (%rax), %esi
leaq 0x10(%rsp), %rdi
callq 0x4f05
testb %r12b, %r12b
jne 0x5f32
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %bl, %edi
callq 0x3496
jmp 0x5f21
callq 0x609d
callq 0x3473