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

    rev = 1;

#ifdef DEBUG
    printf("rev = %d\n", rev);
#endif

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

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

    pnam = argv[0];

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

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

    if (numer && bylen) {
        if ((tree = aa_new(lncomparator)) == NULL) {
            fprintf(stderr, "aa_new error\n");
            exit(EXIT_FAILURE);
        }

    } else if (numer || bylen) {
        if ((tree = aa_new(ncomparator)) == 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, bylen);
    } else {
        for (i = optind; i < argc; i++) {
            if ((fin = fopen(argv[i], "rb")) == NULL) {
                handle_ferr(argv[i], "sort2");
                continue;
            }

            dofile(argv[i], fin, tree, bylen);

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

    if (bylen && uniq) {
        aa_traverse(tree, lprint, TRAV_IN);
    } else if (bylen) {
        aa_traverse(tree, lprintall, TRAV_IN);
    } else if (uniq) {
        aa_traverse(tree, print, TRAV_IN);
    } else {
        aa_traverse(tree, printall, TRAV_IN);
    }

    cleanup(tree);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x3eb3(%rip), %rsi      # 0x5d00
leaq 0x20(%rsp), %rdi
movl $0xe0, %edx
callq 0x1120
movl $0x1, 0x4286(%rip)      # 0x60ec
cmpl $0x1, %ebp
jne 0x1eaa
leaq 0x278(%rip), %rdi       # 0x20ea
callq 0x13c4
testq %rax, %rax
je 0x20b7
movq %rax, %rbx
movq 0x4146(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
leaq 0x128c(%rip), %rdi      # 0x3120
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x212c
leaq 0x3b5(%rip), %rsi       # 0x225a
jmp 0x207f
movq (%rbx), %rax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
leaq 0x20(%rsp), %r12
leaq 0x1c(%rsp), %r13
leaq 0x11eb(%rip), %r15      # 0x30b0
movl $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movl %ecx, %r14d
movl %ebp, %edi
movq %rbx, %rsi
leaq 0x1242(%rip), %rdx      # 0x3126
movq %r12, %rcx
movq %r13, %r8
callq 0x10a0
movb $0x1, %cl
leal -0x6e(%rax), %edx
cmpl $0x8, %edx
ja 0x1f0d
movslq (%r15,%rdx,4), %rax
addq %r15, %rax
jmpq *%rax
movb $0x1, %al
movl %eax, 0x8(%rsp)
movl %r14d, %ecx
jmp 0x1ed5
testl %eax, %eax
je 0x1f21
cmpl $0x62, %eax
jne 0x1f4b
movb $0x1, %al
movl %eax, 0x4(%rsp)
movl %r14d, %ecx
jmp 0x1ed5
movl 0x1c(%rsp), %eax
cmpq $0x5, %rax
ja 0x20a5
leaq 0x119e(%rip), %rdx      # 0x30d4
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
orl $-0x1, 0x41a6(%rip)     # 0x60ec
movl %r14d, %ecx
jmp 0x1ed5
cmpl $-0x1, %eax
je 0x1f72
cmpl $0x68, %eax
jne 0x20a5
movq 0x10(%rsp), %rdi
callq 0x22a6
jmp 0x2091
callq 0x2342
jmp 0x2091
testb $0x1, 0x8(%rsp)
je 0x1f89
testb $0x1, 0x4(%rsp)
je 0x1f90
leaq 0x411(%rip), %rdi       # 0x2398
jmp 0x1fa0
testb $0x1, 0x4(%rsp)
je 0x1f99
leaq 0x47b(%rip), %rdi       # 0x2412
jmp 0x1fa0
leaq 0x14a(%rip), %rdi       # 0x20ea
callq 0x13c4
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x20cc
movq 0x401e(%rip), %rax      # 0x5fd8
movslq (%rax), %r12
cmpl %ebp, %r12d
jge 0x2023
movslq %ebp, %r15
movzbl 0x4(%rsp), %ebp
andl $0x1, %ebp
cmpq %r15, %r12
jge 0x205d
movq (%rbx,%r12,8), %rdi
leaq 0x115a(%rip), %rsi      # 0x313b
callq 0x1160
movq (%rbx,%r12,8), %rdi
testq %rax, %rax
je 0x2012
movq %rax, %r13
movq %rax, %rsi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
callq 0x212c
movq %r13, %rdi
callq 0x1080
cmpl $-0x1, %eax
jne 0x201e
movq (%rbx,%r12,8), %rdi
leaq 0x1125(%rip), %rsi      # 0x313e
callq 0x138c
incq %r12
jmp 0x1fcd
movq 0x3fa6(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
movl 0x4(%rsp), %ebx
movzbl %bl, %ecx
andl $0x1, %ecx
leaq 0x10e2(%rip), %rdi      # 0x3120
movq 0x8(%rsp), %rdx
callq 0x212c
testb $0x1, %bl
je 0x2064
leaq 0x3e7(%rip), %rax       # 0x243b
leaq 0x402(%rip), %rsi       # 0x245d
jmp 0x2072
testb $0x1, 0x4(%rsp)
jne 0x204d
leaq 0x431(%rip), %rax       # 0x249c
leaq 0x1e8(%rip), %rsi       # 0x225a
testb $0x1, %r14b
cmovneq %rax, %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1790
movq %rbx, %rdi
callq 0x228b
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
callq 0x22a6
pushq $0x1
popq %rdi
callq 0x1180
movq 0x3f3a(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1048(%rip), %rdi      # 0x3110
pushq $0xf
jmp 0x20df
movq 0x3f25(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1050(%rip), %rdi      # 0x312d
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
jmp 0x20af