// File: /workspace/github_c_makefile_star2_O2/c0stya[P]fslib/src/fsprint.c
// Function: main
int main(int argc, char * argv[]) {
    struct _fst * fst; 
    const char * ifilename = NULL; 

    FILE * fin = stdin;
    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 = "h";

    const struct option long_options [] = {
        { "isym", required_argument, NULL, 'I' },
        { "osym", required_argument, NULL, 'O' },
        { "ssym", required_argument, NULL, 'S' },
        { "help", required_argument, 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 [input_file]\n", argv[0]);
                exit(EXIT_SUCCESS);
        } 
    }

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

    fst = fst_create();
    fst_read(fst, fin);
    fst_print_sym(fst, ist, ost, sst);
    fst_remove(fst);
    
    if (fin != stdout) {
        fclose(fin);
    }

    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 $0xd8, %rsp
movq %rsi, %r13
movl %edi, %r14d
movq 0x416f(%rip), %rax      # 0x8fc8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq -0x44(%rbp), %rax
orl $-0x1, (%rax)
leaq 0x3ec2(%rip), %rsi      # 0x8d30
leaq -0x100(%rbp), %rdi
movl $0xa0, %edx
callq 0x1150
leaq 0x18f0(%rip), %r12      # 0x6776
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
xorl %r15d, %r15d
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
xorl %ebx, %ebx
movl %r14d, %edi
movq %r13, %rsi
movq %r12, %rdx
leaq -0x100(%rbp), %rcx
leaq -0x44(%rbp), %r8
callq 0x10b0
cmpl $0x53, %eax
jne 0x4ef2
movq 0x4108(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
callq 0x4df4
movq %rax, %r15
xorl %eax, %eax
callq 0x294a
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
callq 0x26a8
jmp 0x4eab
cmpl $-0x1, %eax
je 0x4f63
cmpl $0x4f, %eax
je 0x4f34
cmpl $0x49, %eax
jne 0x5048
movq 0x40cc(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
callq 0x4df4
movq %rax, -0x38(%rbp)
xorl %eax, %eax
callq 0x294a
movq %rax, -0x50(%rbp)
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x26a8
jmp 0x4eab
movq 0x409d(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
callq 0x4df4
movq %rax, -0x40(%rbp)
xorl %eax, %eax
callq 0x294a
movq %rax, -0x58(%rbp)
movq %rax, %rdi
movq -0x40(%rbp), %rsi
callq 0x26a8
jmp 0x4eab
movq 0x4066(%rip), %rax      # 0x8fd0
movslq (%rax), %rax
cmpl %r14d, %eax
jge 0x4f98
movq (%r13,%rax,8), %r14
testq %r14, %r14
je 0x4f98
leaq 0x114b(%rip), %rsi      # 0x60ce
movq %r14, %rdi
callq 0x1190
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x506b
xorl %eax, %eax
callq 0x1fb0
movq %rax, %r14
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x2248
movq %r14, %rdi
movq -0x50(%rbp), %r13
movq %r13, %rsi
movq -0x58(%rbp), %r12
movq %r12, %rdx
movq %rbx, %rcx
callq 0x301b
movq %r14, %rdi
callq 0x20b0
movq -0x30(%rbp), %rdi
movq 0x3fe6(%rip), %rax      # 0x8fc0
cmpq (%rax), %rdi
je 0x4fe4
callq 0x1090
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x4ff2
callq 0x1090
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x5000
callq 0x1090
testq %r15, %r15
je 0x500d
movq %r15, %rdi
callq 0x1090
testq %r13, %r13
je 0x501a
movq %r13, %rdi
callq 0x2999
testq %r12, %r12
je 0x5027
movq %r12, %rdi
callq 0x2999
testq %rbx, %rbx
je 0x5034
movq %rbx, %rdi
callq 0x2999
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3fa9(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq (%r13), %rdx
leaq 0x172f(%rip), %rsi      # 0x678c
xorl %eax, %eax
callq 0x1130
xorl %edi, %edi
callq 0x11c0
movq 0x3f86(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x103b(%rip), %rsi      # 0x60b7
movq %r14, %rdx
xorl %eax, %eax
callq 0x1130
pushq $0x1
popq %rdi
callq 0x11c0