// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl %edi, %ebx
leaq 0x3d13(%rip), %rsi      # 0x5d00
leaq 0x20(%rsp), %rdi
movl $0xe0, %edx
callq 0x1120
movl $0x1, 0x40e6(%rip)      # 0x60ec
cmpl $0x1, %ebx
jne 0x204a
leaq 0x297(%rip), %rdi       # 0x22a9
callq 0x14b8
testq %rax, %rax
je 0x229f
movq %rax, %rbx
movq 0x3fa6(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
leaq 0x10ec(%rip), %rdi      # 0x3120
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x22ed
leaq 0x3b1(%rip), %rsi       # 0x23f6
jmp 0x2254
movq (%r14), %rax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
leaq 0x20(%rsp), %r13
leaq 0x1c(%rsp), %rbp
leaq 0x104b(%rip), %r12      # 0x30b0
movl $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movl %ecx, %r15d
movl %ebx, %edi
movq %r14, %rsi
leaq 0x10a2(%rip), %rdx      # 0x3126
movq %r13, %rcx
movq %rbp, %r8
callq 0x10a0
movb $0x1, %cl
cmpl $0x67, %eax
jle 0x20ab
leal -0x6e(%rax), %edx
cmpl $0x8, %edx
ja 0x2136
movslq (%r12,%rdx,4), %rax
addq %r12, %rax
jmpq *%rax
testl %eax, %eax
je 0x20bf
cmpl $0x62, %eax
jne 0x2104
movb $0x1, %al
movl %eax, 0x4(%rsp)
movl %r15d, %ecx
jmp 0x2075
movl 0x1c(%rsp), %eax
cmpq $0x5, %rax
ja 0x228b
leaq 0x1000(%rip), %rdx      # 0x30d4
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0xffffffff, 0x4005(%rip) # imm = 0xFFFFFFFF
movl %r15d, %ecx
jmp 0x2075
movb $0x1, %al
movl %eax, 0x8(%rsp)
movl %r15d, %ecx
jmp 0x2075
callq 0x24e6
jmp 0x2277
cmpl $-0x1, %eax
jne 0x228b
testb $0x1, 0x8(%rsp)
je 0x214e
testb $0x1, 0x4(%rsp)
je 0x2155
leaq 0x41a(%rip), %rdi       # 0x253c
callq 0x14b8
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x218a
callq 0x1242
cmpl $0x68, %eax
jne 0x228b
movq 0x10(%rsp), %rdi
callq 0x2447
jmp 0x2277
testb $0x1, 0x4(%rsp)
je 0x2170
leaq 0x463(%rip), %rdi       # 0x25bf
callq 0x14b8
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x218a
callq 0x121d
leaq 0x132(%rip), %rdi       # 0x22a9
callq 0x14b8
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x22a4
movq 0x3e47(%rip), %rax      # 0x5fd8
movslq (%rax), %rax
cmpl %eax, %ebx
jle 0x21fb
leaq (%r14,%rax,8), %r12
subl %eax, %ebx
xorl %r14d, %r14d
movzbl 0x4(%rsp), %ebp
andl $0x1, %ebp
movq (%r12,%r14,8), %rdi
leaq 0xf87(%rip), %rsi       # 0x313b
callq 0x1160
movq (%r12,%r14,8), %rdi
testq %rax, %rax
je 0x21e5
movq %rax, %r13
movq %rax, %rsi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
callq 0x22ed
movq %r13, %rdi
callq 0x1080
cmpl $-0x1, %eax
jne 0x21f1
movq (%r12,%r14,8), %rdi
leaq 0xf52(%rip), %rsi       # 0x313e
callq 0x11c0
incq %r14
cmpl %r14d, %ebx
jne 0x21a9
jmp 0x221e
movq 0x3dce(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
movzbl 0x4(%rsp), %ecx
andl $0x1, %ecx
leaq 0xf0c(%rip), %rdi       # 0x3120
movq 0x8(%rsp), %rdx
callq 0x22ed
leaq 0x3c3(%rip), %rax       # 0x25e8
leaq 0x3e0(%rip), %rcx       # 0x260c
testb $0x1, %r15b
cmovneq %rax, %rcx
leaq 0x417(%rip), %rax       # 0x2652
leaq 0x1b4(%rip), %rsi       # 0x23f6
cmovneq %rax, %rsi
testb $0x1, 0x4(%rsp)
cmovneq %rcx, %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1914
leaq 0x475(%rip), %rsi       # 0x26da
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1914
movq %rbx, %rdi
callq 0x1a2a
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 0x2447
movl $0x1, %edi
callq 0x1180
callq 0x1267
callq 0x11f8