// File: /workspace/github_c_makefile_star2_O2/c0stya[P]fslib/src/fssort.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;
    int sort_outer = 0;
    int c;

    while ( (c = getopt(argc, argv, "ioh")) != -1 ) {
        switch(c) {
            case 'i': 
                sort_outer = 0;
                break;
            case 'o': 
                sort_outer = 1;
                break;
            default:
                fprintf(stderr, "Usage: %s [-o] [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_arc_sort(fst, sort_outer);
    fst_write(fst, fout);
    fst_remove(fst);
    
    if (fin != stdout) {
        fclose(fin);
    }

    if (fout != stdout) {
        fclose(fout);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r13
movl %edi, %ebx
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x1fb0
movq %rax, -0x38(%rbp)
movq 0x31b1(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq 0x319b(%rip), %rax      # 0x7fc8
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0x93b(%rip), %r15       # 0x5776
movl %r12d, %r14d
movl %ebx, %edi
movq %r13, %rsi
movq %r15, %rdx
callq 0x11a0
movl $0x0, %r12d
cmpl $0x69, %eax
je 0x4e3b
cmpl $0x6f, %eax
jne 0x4e61
pushq $0x1
popq %r12
jmp 0x4e3b
cmpl $-0x1, %eax
jne 0x4f3d
movq 0x3167(%rip), %rax      # 0x7fd8
movslq (%rax), %rax
cmpl %ebx, %eax
jge 0x4e7f
movq (%r13,%rax,8), %r15
jmp 0x4e82
xorl %r15d, %r15d
incl %eax
cmpl %ebx, %eax
jge 0x4e91
cltq
movq (%r13,%rax,8), %rbx
jmp 0x4e93
xorl %ebx, %ebx
movq -0x30(%rbp), %r12
testq %r15, %r15
je 0x4eb7
leaq 0x22b(%rip), %rsi       # 0x50ce
movq %r15, %rdi
callq 0x1180
movq %rax, %r12
testq %rax, %rax
je 0x4f60
testq %rbx, %rbx
movq -0x40(%rbp), %r15
je 0x4edb
leaq 0x8de(%rip), %rsi       # 0x57a5
movq %rbx, %rdi
callq 0x1180
movq %rax, %r15
testq %rax, %rax
je 0x4f76
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2248
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2b84
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2139
movq %rbx, %rdi
callq 0x20b0
movq 0x30b9(%rip), %rbx      # 0x7fc8
cmpq (%rbx), %r12
je 0x4f1f
movq %r12, %rdi
callq 0x1090
movq (%rbx), %r12
cmpq %r12, %r15
je 0x4f2c
movq %r15, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30b4(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq (%r13), %rdx
leaq 0x828(%rip), %rsi       # 0x577a
xorl %eax, %eax
callq 0x1120
xorl %edi, %edi
callq 0x11c0
movq 0x3091(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x146(%rip), %rsi       # 0x50b7
movq %r15, %rdx
jmp 0x4f8a
movq 0x307b(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x130(%rip), %rsi       # 0x50b7
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1120
pushq $0x1
popq %rdi
callq 0x11c0