// File: /workspace/github_c_makefile_star2_O3/c0stya[P]fslib/src/fscompile.c
// Function: main
int main(int argc, char * argv[]) {
    struct _fst * fst = fst_create(); 

    const char * ifilename = NULL; 
    const char * ofilename = NULL;

    FILE * fin = stdin;
    FILE * fout = stdout;
    FILE * isym = NULL;
    FILE * osym = NULL;
    FILE * ssym = NULL;

    struct _symt * ist = NULL;
    struct _symt * ost = NULL;
    struct _symt * sst = NULL;

    int c;
    int acc=0;
    int opt_index = -1;

    const char * short_options = "I:O:S:";

    const struct option long_options [] = {
        { "isym", required_argument, NULL, 'I' },
        { "osym", required_argument, NULL, 'O' },
        { "ssym", required_argument, NULL, 'S' },
        { "acc", 0, NULL, 'a' },
        { "help", 0, NULL, 'h' },
        { "sr", 0, NULL, 's' },
        { 0, 0, NULL, 0}
    };

    while ( (c = getopt_long(argc, argv,  
                short_options, long_options, &opt_index )) != -1 ) {
        switch(c) {
            case 'a':
                acc = 1;
                break;
            case 'I': 
                isym = file_open(optarg);
                ist = symt_create();
                symt_read(ist, isym);
                break;
            case 'O': 
                osym = file_open(optarg);
                ost = symt_create();
                symt_read(ost, osym);
                break;
            case 'S': 
                ssym = file_open(optarg);
                sst = symt_create();
                symt_read(sst, ssym);
                break;
            default:
                fprintf(stderr, "Usage: %s [--acc] [--isym filename] [--osym filename]"
                    "[--ssym filename] [input_file] [output_file]\n", argv[0]);
                exit(EXIT_SUCCESS);
        } 
    }

    if (optind < argc)
        ifilename = argv[optind];
    if (optind+1 < argc)
        ofilename = argv[optind+1];

    if (ifilename) {
        if (( fin = fopen(ifilename, "rb")) == NULL ) {
            fprintf(stderr, "Error opening file: %s", ifilename);
            exit(EXIT_FAILURE);
        }
    }

    if (ofilename) {
        if (( fout = fopen(ofilename, "w")) == NULL ) {
            fprintf(stderr, "Error opening file: %s", ofilename);
            exit(EXIT_FAILURE);
        }
    }

    fst = fst_compile(fst, fin, ist, ost, sst, acc);
    fst_write(fst, fout);

    fst_remove(fst);
    
    if (fin != stdout)
        fclose(fin);
    if (fout != stdout)
        fclose(fout);

    if (isym != NULL)
        fclose(isym);
    if (osym != NULL)
        fclose(osym);
    if (ssym != NULL)
        fclose(ssym);

    if (ist != NULL)
        symt_remove(ist); 
    if (ost != NULL)
        symt_remove(ost); 
    if (sst != NULL)
        symt_remove(sst); 

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, -0x58(%rbp)
movl %edi, -0x34(%rbp)
xorl %eax, %eax
callq 0x2140
movq %rax, -0x88(%rbp)
movq 0x4cb3(%rip), %rax      # 0x9fc8
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq 0x4c9d(%rip), %rax      # 0x9fc0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
leaq -0x5c(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x49b5(%rip), %rsi      # 0x9cf0
leaq -0x170(%rbp), %rdi
movl $0xe0, %edx
callq 0x1160
leaq 0x1421(%rip), %rdx      # 0x6774
movq $0x0, -0x70(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
xorl %ecx, %ecx
movl -0x34(%rbp), %r13d
leaq -0x170(%rbp), %r15
movq -0x58(%rbp), %r14
movl %ecx, %r12d
movl %r13d, %edi
movq %r14, %rsi
movq %rdx, %rbx
movq %r15, %rcx
leaq -0x5c(%rbp), %r8
callq 0x10b0
movq %rbx, %rdx
movl $0x1, %ecx
cmpl $0x61, %eax
je 0x5394
cmpl $0x4e, %eax
jg 0x53f6
cmpl $-0x1, %eax
je 0x5461
cmpl $0x49, %eax
jne 0x55b4
movq 0x4c01(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x52bc
movq %rax, %r14
xorl %eax, %eax
callq 0x2b2a
movq %rax, -0x30(%rbp)
movq %rax, %rdi
movq %r14, -0x70(%rbp)
jmp 0x544e
cmpl $0x4f, %eax
je 0x542a
cmpl $0x53, %eax
jne 0x55b4
movq 0x4bcd(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x52bc
movq %rax, %r14
xorl %eax, %eax
callq 0x2b2a
movq %rax, -0x80(%rbp)
movq %rax, %rdi
movq %r14, -0x48(%rbp)
jmp 0x544e
movq 0x4ba7(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x52bc
movq %rax, %r14
xorl %eax, %eax
callq 0x2b2a
movq %rax, -0x78(%rbp)
movq %rax, %rdi
movq %r14, -0x40(%rbp)
movq %r14, %rsi
callq 0x2860
movq %rbx, %rdx
movl %r12d, %ecx
jmp 0x5389
movq 0x4b68(%rip), %rax      # 0x9fd0
movslq (%rax), %rax
movl -0x34(%rbp), %esi
cmpl %esi, %eax
movq -0x58(%rbp), %rdx
jge 0x547c
movq (%rdx,%rax,8), %r15
jmp 0x547f
xorl %r15d, %r15d
movq -0x30(%rbp), %r13
movq -0x68(%rbp), %rcx
incl %eax
cmpl %esi, %eax
jge 0x5495
cltq
movq (%rdx,%rax,8), %rbx
jmp 0x5497
xorl %ebx, %ebx
testq %r15, %r15
je 0x54b7
leaq 0xc2b(%rip), %rsi       # 0x60ce
movq %r15, %rdi
callq 0x11a0
movq %rax, %rcx
testq %rax, %rax
je 0x55bd
movq %r13, -0x30(%rbp)
testq %rbx, %rbx
je 0x54e2
movq %rcx, %r14
leaq 0x132f(%rip), %rsi      # 0x67f9
movq %rbx, %rdi
callq 0x11a0
movq %r14, %rcx
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x55c5
movq -0x88(%rbp), %rdi
movq %rcx, %r13
movq %rcx, %rsi
movq -0x30(%rbp), %rdx
movq -0x78(%rbp), %r15
movq %r15, %rcx
movq -0x80(%rbp), %r14
movq %r14, %r8
movl %r12d, %r9d
callq 0x146c
movq %rax, %rbx
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x22ee
movq %rbx, %rdi
callq 0x224b
movq 0x4a99(%rip), %rbx      # 0x9fc0
cmpq (%rbx), %r13
je 0x5537
movq %r13, %rdi
callq 0x1090
movq (%rbx), %r13
movq -0x48(%rbp), %rbx
movq -0x40(%rbp), %r12
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x554d
callq 0x1090
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
movq -0x30(%rbp), %r13
je 0x555f
callq 0x1090
testq %r12, %r12
je 0x556c
movq %r12, %rdi
callq 0x1090
testq %rbx, %rbx
je 0x5579
movq %rbx, %rdi
callq 0x1090
testq %r13, %r13
je 0x5586
movq %r13, %rdi
callq 0x2b6b
testq %r15, %r15
je 0x5593
movq %r15, %rdi
callq 0x2b6b
testq %r14, %r14
je 0x55a0
movq %r14, %rdi
callq 0x2b6b
xorl %eax, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x1352
movq %r15, %rdi
callq 0x1304
movq %rbx, %rdi
callq 0x132b