// File: /workspace/github_c_makefile_star2_O3/chbarts[P]aa-tree/sort.c
// Function: main
int main(int argc, char *argv[])
{
    aa *tree;
    char *pnam;
    FILE *fin;
    int i, lind, c;
    bool uniq = false, rev = false, numer = false;
    extern int optind;
    struct option longopts[] = {
        {"uniqify", 0, 0, 0},
        {"reverse", 0, 0, 0},
        {"numer", 0, 0, 0},
        {"help", 0, 0, 0},
        {"version", 0, 0, 0},
        {0, 0, 0, 0}
    };

    if (argc == 1) {
        if ((tree = aa_new(comparator)) == NULL) {
            fprintf(stderr, "aa_new() error\n");
            exit(EXIT_FAILURE);
        }

        dofile("stdin", stdin, tree, false, false);
        aa_traverse(tree, printall, TRAV_IN);
        cleanup(tree, numer);
        return 0;
    }

    pnam = argv[0];

    while ((c = getopt_long(argc, argv, "urnhv", longopts, &lind)) != -1) {
        switch (c) {
        case 0:
            switch (lind) {
            case 0:
                uniq = true;
                break;
            case 1:
                rev = true;
                break;
            case 2:
                numer = true;
                break;
            case 3:
                usage(pnam);
                return 0;
                break;
            case 4:
                version();
                return 0;
                break;
            default:
                usage(pnam);
                exit(EXIT_FAILURE);
                break;
            }

            break;
        case 'u':
            uniq = true;
            break;
        case 'r':
            rev = true;
            break;
        case 'n':
            numer = true;
            break;
        case 'h':
            usage(pnam);
            return 0;
            break;
        case 'v':
            version();
            return 0;
            break;
        default:
            usage(pnam);
            exit(EXIT_FAILURE);
            break;
        }
    }

    if (rev && numer) {
        if ((tree = aa_new(rncomparator)) == NULL) {
            fprintf(stderr, "aa_new error\n");
            exit(EXIT_FAILURE);
        }
    } else if (numer) {
        if ((tree = aa_new(ncomparator)) == NULL) {
            fprintf(stderr, "aa_new error\n");
            exit(EXIT_FAILURE);
        }
    } else if (rev) {
        if ((tree = aa_new(rcomparator)) == NULL) {
            fprintf(stderr, "aa_new error\n");
            exit(EXIT_FAILURE);
        }
    } else {
        if ((tree = aa_new(comparator)) == NULL) {
            fprintf(stderr, "aa_new error\n");
            exit(EXIT_FAILURE);
        }
    }

    if (optind >= argc) {
        dofile("stdin", stdin, tree, numer, rev);
    } else {
        for (i = optind; i < argc; i++) {
            if ((fin = fopen(argv[i], "rb")) == NULL) {
                handle_ferr(argv[i], "sort");
                continue;
            }

            dofile(argv[i], fin, tree, numer, rev);

            if (fclose(fin) == EOF) {
                handle_ferr(argv[i], "sort");
            }
        }
    }

    if (uniq && numer) {
        aa_traverse(tree, printn, TRAV_IN);
    } else if (uniq) {
        aa_traverse(tree, print, TRAV_IN);
    } else if (numer) {
        aa_traverse(tree, printalln, TRAV_IN);
    } else {
        aa_traverse(tree, printall, TRAV_IN);
    }

    cleanup(tree, numer);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movl %edi, %ebx
leaq 0x3dff(%rip), %rsi      # 0x5d20
leaq 0x20(%rsp), %rdi
movl $0xc0, %edx
callq 0x10f0
cmpl $0x1, %ebx
jne 0x1f9a
leaq 0x2ec(%rip), %rdi       # 0x2228
callq 0x1518
testq %rax, %rax
je 0x221e
movq %rax, %rbx
movq 0x407c(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
leaq 0x11b8(%rip), %rdi      # 0x3116
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2261
leaq 0x4e6(%rip), %rsi       # 0x2458
movq %rbx, %rdi
xorl %edx, %edx
callq 0x196d
leaq 0x819(%rip), %rsi       # 0x279c
movq %rbx, %rdi
xorl %edx, %edx
callq 0x196d
movq %rbx, %rdi
callq 0x1a83
jmp 0x2067
movq (%r14), %rax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
leaq 0x1171(%rip), %r12      # 0x311c
leaq 0x20(%rsp), %r13
leaq 0x1c(%rsp), %rbp
leaq 0x10f4(%rip), %r15      # 0x30b0
xorl %esi, %esi
xorl %edx, %edx
movb %cl, 0xf(%rsp)
movl %esi, %ecx
movl %ecx, 0x18(%rsp)
movl %edx, %ecx
movl %ecx, 0x8(%rsp)
movl %ebx, %edi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %rbp, %r8
callq 0x1080
cmpl $0x6d, %eax
jle 0x1fff
addl $-0x6e, %eax
cmpl $0x8, %eax
ja 0x220a
movb $0x1, %cl
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
testl %eax, %eax
jne 0x2044
movb $0x1, %cl
movl 0x1c(%rsp), %eax
cmpl $0x2, %eax
je 0x1fcc
cmpl $0x4, %eax
movl 0x8(%rsp), %edx
movl 0x18(%rsp), %esi
ja 0x220a
movl %eax, %eax
leaq 0x10ac(%rip), %rdi      # 0x30d4
movslq (%rdi,%rax,4), %rax
addq %rdi, %rax
jmpq *%rax
movl 0x8(%rsp), %edx
jmp 0x1fc6
movl 0x8(%rsp), %edx
movl 0x18(%rsp), %esi
jmp 0x1fc0
cmpl $-0x1, %eax
movl 0x8(%rsp), %ecx
je 0x207b
cmpl $0x68, %eax
jne 0x220a
movq 0x10(%rsp), %rdi
callq 0x24b9
jmp 0x2067
callq 0x2540
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, 0x18(%rsp)
je 0x20a2
testb $0x1, %cl
je 0x20c2
leaq 0x508(%rip), %rdi       # 0x2596
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x20f7
callq 0x1237
testb $0x1, %cl
je 0x20dd
leaq 0x504(%rip), %rdi       # 0x25b2
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x20f7
callq 0x11ed
leaq 0x4fd(%rip), %rdi       # 0x25c6
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x20f7
callq 0x1212
leaq 0x144(%rip), %rdi       # 0x2228
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2223
movl 0x8(%rsp), %ecx
movq 0x3ed6(%rip), %rax      # 0x5fd8
movslq (%rax), %rax
cmpl %eax, %ebx
jle 0x2177
leaq (%r14,%rax,8), %r15
subl %eax, %ebx
xorl %r14d, %r14d
movzbl %cl, %ebp
andl $0x1, %ebp
movzbl 0x18(%rsp), %r13d
andl $0x1, %r13d
movq (%r15,%r14,8), %rdi
leaq 0x1003(%rip), %rsi      # 0x3130
callq 0x1130
movq (%r15,%r14,8), %rdi
testq %rax, %rax
je 0x2161
movq %rax, %r12
movq %rax, %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0x2261
movq %r12, %rdi
callq 0x1070
cmpl $-0x1, %eax
jne 0x216d
movq (%r15,%r14,8), %rdi
leaq 0xfcb(%rip), %rsi       # 0x3133
callq 0x1190
incq %r14
cmpl %r14d, %ebx
jne 0x2122
jmp 0x21a2
movq 0x3e52(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
movzbl %cl, %ecx
andl $0x1, %ecx
movzbl 0x18(%rsp), %r8d
andl $0x1, %r8d
leaq 0xf7e(%rip), %rdi       # 0x3116
movq 0x10(%rsp), %rdx
callq 0x2261
leaq 0x45a(%rip), %rax       # 0x2603
leaq 0x46e(%rip), %rcx       # 0x261e
testb $0x1, 0x8(%rsp)
cmovneq %rax, %rcx
leaq 0x474(%rip), %rax       # 0x2634
leaq 0x291(%rip), %rsi       # 0x2458
cmovneq %rax, %rsi
leaq 0x594(%rip), %rax       # 0x2766
leaq 0x5c3(%rip), %rbx       # 0x279c
cmovneq %rax, %rbx
testb $0x1, 0xf(%rsp)
cmovneq %rcx, %rsi
movq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
callq 0x196d
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x196d
movq %r14, %rdi
jmp 0x1f90
movq 0x10(%rsp), %rdi
callq 0x24b9
movl $0x1, %edi
callq 0x1150
callq 0x125c
callq 0x11c8