// File: /workspace/github_c_makefile_star2_O3/c0stya[P]fslib/src/fsdraw.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 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' },
        { "help", 0, NULL, 'h' },
        { 0, 0, NULL, 0}
    };

    while ( (c = getopt_long(argc, argv,  
                short_options, long_options, &opt_index )) != -1 ) {
        switch(c) {
            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 [--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_read(fst, fin);
    fst_draw_sym(fst, fout, ist, ost, sst);
    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 $0xe8, %rsp
movq %rsi, %r14
movl %edi, %r12d
xorl %eax, %eax
callq 0x2140
movq %rax, -0x68(%rbp)
movq 0x4cb7(%rip), %rax      # 0x9fc8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq 0x4ca1(%rip), %rax      # 0x9fc0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
leaq -0x4c(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x49f9(%rip), %rsi      # 0x9d30
leaq -0x110(%rbp), %rdi
movl $0xa0, %edx
callq 0x1160
leaq 0x1427(%rip), %r13      # 0x6776
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
xorl %r15d, %r15d
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
xorl %ebx, %ebx
movl %r12d, %edi
movq %r14, %rsi
movq %r13, %rdx
leaq -0x110(%rbp), %rcx
leaq -0x4c(%rbp), %r8
callq 0x10b0
cmpl $0x53, %eax
jne 0x53bb
movq 0x4c3f(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x52bc
movq %rax, %r15
xorl %eax, %eax
callq 0x2b2a
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2860
jmp 0x5374
cmpl $-0x1, %eax
je 0x542c
cmpl $0x4f, %eax
je 0x53fd
cmpl $0x49, %eax
jne 0x5571
movq 0x4c03(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x52bc
movq %rax, -0x40(%rbp)
xorl %eax, %eax
callq 0x2b2a
movq %rax, -0x58(%rbp)
movq %rax, %rdi
movq -0x40(%rbp), %rsi
callq 0x2860
jmp 0x5374
movq 0x4bd4(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x52bc
movq %rax, -0x48(%rbp)
xorl %eax, %eax
callq 0x2b2a
movq %rax, -0x60(%rbp)
movq %rax, %rdi
movq -0x48(%rbp), %rsi
callq 0x2860
jmp 0x5374
movq 0x4b9d(%rip), %rax      # 0x9fd0
movslq (%rax), %rax
cmpl %r12d, %eax
movq -0x30(%rbp), %rcx
jge 0x5445
movq (%r14,%rax,8), %r13
jmp 0x5448
xorl %r13d, %r13d
incl %eax
cmpl %r12d, %eax
jge 0x5457
cltq
movq (%r14,%rax,8), %r14
jmp 0x545a
xorl %r14d, %r14d
testq %r13, %r13
je 0x547a
leaq 0xc68(%rip), %rsi       # 0x60ce
movq %r13, %rdi
callq 0x11a0
movq %rax, %rcx
testq %rax, %rax
je 0x5579
testq %r14, %r14
je 0x54a1
movq %rcx, %r12
leaq 0x1363(%rip), %rsi      # 0x67ec
movq %r14, %rdi
callq 0x11a0
movq %r12, %rcx
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x5581
movq %rcx, -0x30(%rbp)
movq -0x68(%rbp), %r13
movq %r13, %rdi
movq -0x30(%rbp), %rsi
callq 0x2409
movq %r13, %rdi
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %r12
movq %r12, %rdx
movq -0x60(%rbp), %r14
movq %r14, %rcx
movq %rbx, %r8
callq 0x3647
movq %r13, %rdi
callq 0x224b
movq -0x30(%rbp), %rcx
movq 0x4adb(%rip), %rax      # 0x9fc0
cmpq (%rax), %rcx
movq -0x48(%rbp), %r13
je 0x5500
movq %rcx, %rdi
callq 0x1090
movq 0x4ac3(%rip), %rax      # 0x9fc0
movq (%rax), %rcx
movq -0x38(%rbp), %rdi
cmpq %rcx, %rdi
je 0x550e
callq 0x1090
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x551c
callq 0x1090
testq %r13, %r13
je 0x5529
movq %r13, %rdi
callq 0x1090
testq %r15, %r15
je 0x5536
movq %r15, %rdi
callq 0x1090
testq %r12, %r12
je 0x5543
movq %r12, %rdi
callq 0x2b6b
testq %r14, %r14
je 0x5550
movq %r14, %rdi
callq 0x2b6b
testq %rbx, %rbx
je 0x555d
movq %rbx, %rdi
callq 0x2b6b
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x1352
movq %r13, %rdi
callq 0x1304
movq %r14, %rdi
callq 0x132b