// File: /workspace/github_c_makefile_star2_O3/JulStrat[P]bams/bams_app.c
// Function: main
int
main(int argc, char *argv[])
{
    int a, b;
    size_t i;
    int min_key = INT_MAX, max_key = INT_MIN;
    BAMS *bas;
    size_t less = 0;
    size_t equal = 0;
    size_t great = 0;

    size_t less_a = 0;
    size_t equal_a = 0;
    size_t great_a = 0;
    size_t all_a = 0;

    int *less_keys;
    int *equal_keys;
    int *great_keys;
    int *all_keys;

    srand(time(NULL));
    for (i = 0; i < ARR_SZ; i++) {
        arint[i] = rand();
        if (arint[i] < min_key) {
            min_key = arint[i];
        }
        if (arint[i] > max_key) {
            max_key = arint[i];
        }
    }

    bas = bams_create(sizeof (int), cmp_int);

    for (i = 0; i < ARR_SZ; i++) {
        bams_insert(bas, &arint[i]);
    }

#if 0
    for (i = 0; i < ARR_SZ; i++) {
        if (0 == bams_contains(bas, &arint[i])) {
            printf("Error: %d not in set.\n", arint[i]);
            break;
        };
    }
#endif

    a = arint[0];
    for (i = 0; i < ARR_SZ; i++) {
        if (arint[i] < a) {
            less++;
        } else if (arint[i] > a) {
            great++;
        } else {
            equal++;
        }
    }
    assert(less == bams_count_less(bas, &a));
    printf("Less than %d: Expected %lu, %lu\n", a, less,
           bams_count_less(bas, &a));

    assert(equal == bams_count_equal(bas, &a));
    printf("Equal to %d: Expected %lu, %lu\n", a, equal,
           bams_count_equal(bas, &a));

    assert(great == bams_count_great(bas, &a));
    printf("Great than %d: Expected %lu, %lu\n", a, great,
           bams_count_great(bas, &a));

    assert(*(int *) bams_min(bas) == min_key);
    printf("Min key: %d, expected: %d\n", *(int *) bams_min(bas), min_key);

    assert(*(int *) bams_max(bas) == max_key);
    printf("Max key: %d, expected: %d\n", *(int *) bams_max(bas), max_key);

    less_keys = bams_less(bas, &a, &less_a);
    assert(less == less_a);
    for (i = 0; i < less_a; i++) {
        assert(less_keys[i] < a);
    }
    free(less_keys);

    equal_keys = bams_equal(bas, &a, &equal_a);
    printf("Equal: %lu, %lu\n", equal, equal_a);
    assert(equal == equal_a);
    for (i = 0; i < equal_a; i++) {
        assert(equal_keys[i] == a);
    }
    free(equal_keys);

    great_keys = bams_great(bas, &a, &great_a);
    assert(great == great_a);
    for (i = 0; i < great_a; i++) {
        assert(great_keys[i] > a);
    }
    free(great_keys);

    all_keys = bams_array(bas, &all_a);
    assert(ARR_SZ == all_a);
    for (i = 1; i < all_a; i++) {
        assert(all_keys[i] >= all_keys[i - 1]);
    }
    free(all_keys);

    printf("Set size: %lu\n", bams_size(bas));
    printf("Check structure result: %d\n", bams_check_structure(bas));
    bams_free(bas);

    /*
     * big set 
     */
    /*
     * bas = bams_create(sizeof (int), cmp_int); for (i = 0; i < 1024 *
     * 1024 * 32; i++) { a = rand(); bams_insert(bas, &a); } printf("Set
     * size: %lu\n", bams_size(bas)); printf("Check structure result:
     * %d\n", bams_check_structure(bas)); bams_free(bas); 
     */
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorl %r14d, %r14d
movq %r14, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movq %r14, 0x20(%rsp)
movq %r14, 0x18(%rsp)
xorl %edi, %edi
callq 0x1080
movl %eax, %edi
callq 0x1060
movl $0x80000000, %ebp       # imm = 0x80000000
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
leaq 0x3e6d(%rip), %rbx      # 0x5080
callq 0x10b0
movl %eax, (%r14,%rbx)
cmpl %r13d, %eax
cmovll %eax, %r13d
cmpl %ebp, %eax
cmovgl %eax, %ebp
addq $0x4, %r14
cmpq $0x3ffffc, %r14         # imm = 0x3FFFFC
jne 0x1213
leaq -0x80(%rip), %rsi       # 0x11bc
movl $0x4, %edi
callq 0x1b07
movq %rax, %r15
xorl %r14d, %r14d
leaq (%rbx,%r14), %rsi
movq %r15, %rdi
callq 0x1b6e
addq $0x4, %r14
cmpq $0x3ffffc, %r14         # imm = 0x3FFFFC
jne 0x124c
movq %r15, 0x10(%rsp)
movl 0x3e10(%rip), %eax      # 0x5080
movl %eax, 0x8(%rsp)
xorl %ecx, %ecx
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpl %eax, (%rcx,%rbx)
jge 0x1289
incq %r12
jmp 0x1293
jle 0x1290
incq %r14
jmp 0x1293
incq %r15
addq $0x4, %rcx
cmpq $0x3ffffc, %rcx         # imm = 0x3FFFFC
jne 0x127f
leaq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e62
cmpq %rax, %r12
jne 0x15ab
leaq 0x8(%rsp), %rsi
movl (%rsi), %eax
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
callq 0x1e62
leaq 0x1d72(%rip), %rdi      # 0x3047
movl 0xc(%rsp), %esi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x1f46
cmpq %rax, %r15
jne 0x15ca
leaq 0x8(%rsp), %rsi
movl (%rsi), %eax
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
callq 0x1f46
leaq 0x1d75(%rip), %rdi      # 0x308b
movl 0xc(%rsp), %esi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x203d
cmpq %rax, %r14
jne 0x15e9
leaq 0x8(%rsp), %rsi
movl (%rsi), %eax
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
callq 0x203d
leaq 0x1d77(%rip), %rdi      # 0x30ce
movl 0xc(%rsp), %esi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x1cb4
cmpl %r13d, (%rax)
jne 0x1608
movq %rbx, %rdi
callq 0x1cb4
movl (%rax), %esi
leaq 0x1d88(%rip), %rdi      # 0x3112
movl %r13d, %edx
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x1d6b
cmpl %ebp, (%rax)
jne 0x1627
movq %rbx, %rdi
callq 0x1d6b
movl (%rax), %esi
leaq 0x1d9a(%rip), %rdi      # 0x314f
movl %ebp, %edx
xorl %eax, %eax
callq 0x1040
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rdx
callq 0x2129
cmpq (%r13), %r12
jne 0x1646
testq %r12, %r12
je 0x13f9
movl 0x8(%rsp), %ecx
xorl %edx, %edx
cmpl %ecx, (%rax,%rdx,4)
jge 0x154e
incq %rdx
cmpq %rdx, %r12
jne 0x13e8
movq %rax, %rdi
callq 0x1030
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %r13
movq 0x10(%rsp), %rdi
movq %r13, %rdx
callq 0x2284
movq %rax, %r12
movq (%r13), %rdx
leaq 0x1d64(%rip), %rdi      # 0x318a
movq %r15, %rsi
xorl %eax, %eax
callq 0x1040
cmpq (%r13), %r15
jne 0x1665
testq %r15, %r15
je 0x1457
movl 0x8(%rsp), %eax
xorl %ecx, %ecx
cmpl %eax, (%r12,%rcx,4)
jne 0x156d
incq %rcx
cmpq %rcx, %r15
jne 0x1445
movq %r12, %rdi
callq 0x1030
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %r15
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rdx
callq 0x244d
cmpq (%r15), %r14
jne 0x1684
testq %r14, %r14
je 0x149e
movl 0x8(%rsp), %ecx
xorl %edx, %edx
cmpl %ecx, (%rax,%rdx,4)
jle 0x158c
incq %rdx
cmpq %rdx, %r14
jne 0x148d
movq %rax, %rdi
callq 0x1030
leaq 0x18(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x25b3
cmpq $0xfffff, (%r14)        # imm = 0xFFFFF
jne 0x16a3
movl $0x1, %ecx
movl (%rax,%rcx,4), %edx
cmpl -0x4(%rax,%rcx,4), %edx
jl 0x152f
incq %rcx
cmpq $0xfffff, %rcx          # imm = 0xFFFFF
jne 0x14c8
movq %rax, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x264d
leaq 0x1d1d(%rip), %rdi      # 0x3211
movq %rax, %rsi
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x2736
leaq 0x1d13(%rip), %rdi      # 0x3220
movl %eax, %esi
xorl %eax, %eax
callq 0x1040
movq %rbx, %rdi
callq 0x26d8
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cbc(%rip), %rdi      # 0x31f2
leaq 0x1ae8(%rip), %rsi      # 0x3025
leaq 0x1aec(%rip), %rcx      # 0x3030
movl $0x81, %edx
callq 0x1050
leaq 0x1c24(%rip), %rdi      # 0x3179
leaq 0x1ac9(%rip), %rsi      # 0x3025
leaq 0x1acd(%rip), %rcx      # 0x3030
movl $0x6b, %edx
callq 0x1050
leaq 0x1c38(%rip), %rdi      # 0x31ac
leaq 0x1aaa(%rip), %rsi      # 0x3025
leaq 0x1aae(%rip), %rcx      # 0x3030
movl $0x73, %edx
callq 0x1050
leaq 0x1c3d(%rip), %rdi      # 0x31d0
leaq 0x1a8b(%rip), %rsi      # 0x3025
leaq 0x1a8f(%rip), %rcx      # 0x3030
movl $0x7a, %edx
callq 0x1050
leaq 0x1a52(%rip), %rdi      # 0x3004
leaq 0x1a6c(%rip), %rsi      # 0x3025
leaq 0x1a70(%rip), %rcx      # 0x3030
movl $0x56, %edx
callq 0x1050
leaq 0x1a97(%rip), %rdi      # 0x3068
leaq 0x1a4d(%rip), %rsi      # 0x3025
leaq 0x1a51(%rip), %rcx      # 0x3030
movl $0x5a, %edx
callq 0x1050
leaq 0x1abb(%rip), %rdi      # 0x30ab
leaq 0x1a2e(%rip), %rsi      # 0x3025
leaq 0x1a32(%rip), %rcx      # 0x3030
movl $0x5e, %edx
callq 0x1050
leaq 0x1ae1(%rip), %rdi      # 0x30f0
leaq 0x1a0f(%rip), %rsi      # 0x3025
leaq 0x1a13(%rip), %rcx      # 0x3030
movl $0x62, %edx
callq 0x1050
leaq 0x1aff(%rip), %rdi      # 0x312d
leaq 0x19f0(%rip), %rsi      # 0x3025
leaq 0x19f4(%rip), %rcx      # 0x3030
movl $0x65, %edx
callq 0x1050
leaq 0x1b1d(%rip), %rdi      # 0x316a
leaq 0x19d1(%rip), %rsi      # 0x3025
leaq 0x19d5(%rip), %rcx      # 0x3030
movl $0x69, %edx
callq 0x1050
leaq 0x1b2f(%rip), %rdi      # 0x319b
leaq 0x19b2(%rip), %rsi      # 0x3025
leaq 0x19b6(%rip), %rcx      # 0x3030
movl $0x71, %edx
callq 0x1050
leaq 0x1b34(%rip), %rdi      # 0x31bf
leaq 0x1993(%rip), %rsi      # 0x3025
leaq 0x1997(%rip), %rcx      # 0x3030
movl $0x78, %edx
callq 0x1050
leaq 0x1b38(%rip), %rdi      # 0x31e2
leaq 0x1974(%rip), %rsi      # 0x3025
leaq 0x1978(%rip), %rcx      # 0x3030
movl $0x7f, %edx
callq 0x1050
nop