// File: /workspace/github_c_makefile_star2_O1/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 0x3dd7(%rip), %rsi      # 0x5d20
leaq 0x20(%rsp), %rdi
movl $0xc0, %edx
callq 0x10f0
cmpl $0x1, %ebx
jne 0x1fc2
leaq 0x2ff(%rip), %rdi       # 0x2263
callq 0x1518
testq %rax, %rax
je 0x2259
movq %rax, %rbx
movq 0x4054(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
leaq 0x1190(%rip), %rdi      # 0x3116
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x229c
leaq 0x4fa(%rip), %rsi       # 0x2494
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1974
leaq 0x82d(%rip), %rsi       # 0x27d8
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1974
movq %rbx, %rdi
callq 0x1a8a
jmp 0x2231
movq (%r14), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
leaq 0x1143(%rip), %r12      # 0x311c
leaq 0x20(%rsp), %r13
leaq 0x1c(%rsp), %rbp
leaq 0x10c6(%rip), %r15      # 0x30b0
xorl %eax, %eax
xorl %edx, %edx
movl %eax, %ecx
movl %ecx, %eax
movl %eax, 0x8(%rsp)
movl %edx, %ecx
movl %ecx, %eax
movl %eax, 0xc(%rsp)
movl %ebx, %edi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %rbp, %r8
callq 0x1080
cmpl $0x6d, %eax
jle 0x202d
addl $-0x6e, %eax
cmpl $0x8, %eax
ja 0x2245
movb $0x1, %cl
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
testl %eax, %eax
jne 0x2083
movb $0x1, %cl
movl 0x1c(%rsp), %eax
cmpl $0x2, %eax
je 0x1ff8
cmpl $0x4, %eax
movl 0xc(%rsp), %edx
ja 0x2245
movl %eax, %eax
leaq 0x1082(%rip), %rsi      # 0x30d4
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
movl 0xc(%rsp), %edx
jmp 0x1ff0
movb $0x1, %al
movl %eax, 0x18(%rsp)
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %eax
jmp 0x1fee
movb $0x1, %al
movl %eax, 0x18(%rsp)
movl 0x8(%rsp), %eax
jmp 0x1fee
cmpl $-0x1, %eax
movl 0xc(%rsp), %ecx
je 0x20ae
cmpl $0x68, %eax
jne 0x2245
movq 0x10(%rsp), %rdi
callq 0x24f5
jmp 0x2231
callq 0x257c
jmp 0x2231
movl 0x8(%rsp), %eax
testb $0x1, %al
je 0x20d6
testb $0x1, %cl
je 0x20d6
leaq 0x510(%rip), %rdi       # 0x25d2
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x212f
callq 0x1237
testb $0x1, %cl
je 0x20f6
leaq 0x50c(%rip), %rdi       # 0x25ee
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x212f
callq 0x1212
testb $0x1, %al
je 0x2115
leaq 0x501(%rip), %rdi       # 0x2602
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x212f
callq 0x11ed
leaq 0x147(%rip), %rdi       # 0x2263
callq 0x1518
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x225e
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %edx
movq 0x3e9a(%rip), %rax      # 0x5fd8
movslq (%rax), %rax
movzbl %cl, %r13d
cmpl %eax, %ebx
movl %r13d, 0x8(%rsp)
jle 0x21b7
leaq (%r14,%rax,8), %r15
subl %eax, %ebx
xorl %r14d, %r14d
andl $0x1, %r13d
movzbl %dl, %ebp
andl $0x1, %ebp
movq (%r15,%r14,8), %rdi
leaq 0xfc4(%rip), %rsi       # 0x3130
callq 0x1130
movq (%r15,%r14,8), %rdi
testq %rax, %rax
je 0x21a1
movq %rax, %r12
movq %rax, %rsi
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
movl %ebp, %r8d
callq 0x229c
movq %r12, %rdi
callq 0x1070
cmpl $-0x1, %eax
jne 0x21ad
movq (%r15,%r14,8), %rdi
leaq 0xf8b(%rip), %rsi       # 0x3133
callq 0x1190
incq %r14
cmpl %r14d, %ebx
jne 0x2161
jmp 0x21e1
movq 0x3e12(%rip), %rax      # 0x5fd0
movq (%rax), %rsi
andl $0x1, %r13d
movzbl %dl, %r8d
andl $0x1, %r8d
leaq 0xf42(%rip), %rdi       # 0x3116
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
callq 0x229c
leaq 0x457(%rip), %rax       # 0x263f
leaq 0x46b(%rip), %rcx       # 0x265a
testb $0x1, 0xc(%rsp)
cmovneq %rax, %rcx
leaq 0x471(%rip), %rax       # 0x2670
leaq 0x28e(%rip), %rsi       # 0x2494
cmovneq %rax, %rsi
testb $0x1, 0x18(%rsp)
cmovneq %rcx, %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1974
movl 0x8(%rsp), %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x24ca
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
callq 0x24f5
movl $0x1, %edi
callq 0x1150
callq 0x125c
callq 0x11c8