// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/test/test-regidx.c
// Function: test_random
void test_random(int nregs, uint32_t min, uint32_t max)
{
    min--;
    max--;

    // Init index with no file name, we will insert the regions manually
    regidx_t *idx = regidx_init(NULL,custom_parse,custom_free,sizeof(char*),NULL);
    if ( !idx ) error("init failed\n");

    // Test region
    uint32_t beg,end;
    get_random_region(min,max,&beg,&end);

    // Insert regions
    int i, nexp = 0;
    kstring_t str = {0,0,0};
    for (i=0; i<nregs; i++)
    {
        uint32_t b,e;
        get_random_region(min,max,&b,&e);
        str.l = 0;
        ksprintf(&str,"1\t%"PRIu32"\t%"PRIu32"\t1:%"PRIu32"-%"PRIu32"",b+1,e+1,b+1,e+1);
        if ( regidx_insert(idx,str.s)!=0 ) error("insert failed: %s\n", str.s);
        if ( e>=beg && b<=end ) nexp++;
    }

    // Test
    regitr_t *itr = regitr_init(idx);
    int nhit = 0, ret = regidx_overlap(idx,"1",beg,end,itr);
    if ( nexp && !ret ) error("query failed, expected %d overlap(s), found none: %d-%d\n", nexp,beg+1,end+1);
    if ( !nexp && ret ) error("query failed, expected no overlaps, found some: %d-%d\n", beg+1,end+1);
    while ( ret && regitr_overlap(itr) )
    {
        str.l = 0;
        ksprintf(&str,"1:%"PRIhts_pos"-%"PRIhts_pos"",itr->beg+1,itr->end+1);
        if ( strcmp(str.s,regitr_payload(itr,char*)) )
            error("query failed, incorrect payload: %s vs %s (%d-%d)\n",str.s,regitr_payload(itr,char*),beg+1,end+1);
        if ( itr->beg > end || itr->end < beg )
            error("query failed, incorrect hit: %d-%d vs %"PRIhts_pos"-%"PRIhts_pos", payload %s\n", beg+1,end+1,itr->beg+1,itr->end+1,regitr_payload(itr,char*));
        nhit++;
    }
    if ( nexp!=nhit ) error("query failed, expected %d overlap(s), found %d: %d-%d\n",nexp,nhit,beg+1,end+1);
    debug("ok: found %d overlaps\n", nexp);

    // Clean up
    regitr_destroy(itr);
    regidx_destroy(idx);
    free(str.s);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r13d
movl %esi, %r12d
movl %edi, %ebx
leaq -0x80d(%rip), %rsi      # 0x5e5c
leaq -0x6dd(%rip), %rdx      # 0x5f93
xorl %r14d, %r14d
movl $0x8, %ecx
xorl %edi, %edi
xorl %r8d, %r8d
callq 0x92c7
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x6966
leal -0x1(%r12), %eax
movq %rax, 0x28(%rsp)
leal -0x1(%r13), %ebp
callq 0x40f0
movslq %eax, %r15
callq 0x40f0
movslq %eax, %rcx
movq %r12, 0x10(%rsp)
subl %r12d, %r13d
imulq %r13, %r15
movabsq $0x200000005, %rdi      # imm = 0x200000005
movq %r15, %rax
mulq %rdi
subq %rdx, %r15
shrq %r15
addq %rdx, %r15
shrq $0x1e, %r15
movq %r15, 0x18(%rsp)
movq 0x28(%rsp), %rax
leal (%rax,%r15), %r8d
movl %ebp, 0x3c(%rsp)
movl %ebp, %esi
subl %r8d, %esi
imulq %rcx, %rsi
movq %rsi, %rax
mulq %rdi
subq %rdx, %rsi
shrq %rsi
addq %rdx, %rsi
shrq $0x1e, %rsi
movl %r8d, 0x20(%rsp)
addl %r8d, %esi
movq %rsi, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testl %ebx, %ebx
jle 0x67f9
xorl %r14d, %r14d
callq 0x40f0
movslq %eax, %r15
callq 0x40f0
movslq %eax, %rcx
movq %r13, %rbp
imulq %r13, %r15
movq %r15, %rax
movabsq $0x200000005, %rsi      # imm = 0x200000005
mulq %rsi
subq %rdx, %r15
shrq %r15
addq %rdx, %r15
shrq $0x1e, %r15
movq 0x28(%rsp), %rax
leal (%rax,%r15), %r12d
movl 0x3c(%rsp), %eax
movl %eax, %r13d
subl %r12d, %r13d
imulq %rcx, %r13
movq %r13, %rax
mulq %rsi
subq %rdx, %r13
shrq %r13
addq %rdx, %r13
shrq $0x1e, %r13
movq $0x0, 0x40(%rsp)
addl 0x10(%rsp), %r15d
leal (%r12,%r13), %ecx
incl %ecx
leaq 0x40(%rsp), %rdi
leaq 0x8da42(%rip), %rsi     # 0x941ee
movl %r15d, %edx
movl %r15d, %r8d
movl %ecx, %r9d
xorl %eax, %eax
callq 0x7c1b
movq 0x50(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x8743
testl %eax, %eax
jne 0x6903
addl %r12d, %r13d
cmpl 0x20(%rsp), %r13d
setae %al
cmpl 0x8(%rsp), %r12d
setbe %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %r14d
decl %ebx
movq %rbp, %r13
jne 0x672e
movq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x9df9
movq %rax, %rbx
movl 0x20(%rsp), %edx
movl 0x8(%rsp), %ecx
leaq 0x9088c(%rip), %rsi     # 0x970a4
movq %r15, %rdi
movq %rdx, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movq %rax, %r8
callq 0x96b7
movl %eax, %ebp
testl %r14d, %r14d
je 0x683c
testl %ebp, %ebp
je 0x6974
testl %r14d, %r14d
jne 0x6849
testl %ebp, %ebp
jne 0x6995
xorl %r15d, %r15d
testl %ebp, %ebp
je 0x68be
movq %rbx, %rdi
callq 0x9e7f
testl %eax, %eax
je 0x68be
movq $0x0, 0x40(%rsp)
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
incq %rdx
incq %rcx
leaq 0x40(%rsp), %rdi
leaq 0x8d9f0(%rip), %rsi     # 0x9426e
xorl %eax, %eax
callq 0x7c1b
movq 0x50(%rsp), %r12
movq 0x10(%rbx), %rax
movq (%rax), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x46d0
testl %eax, %eax
jne 0x6941
movq (%rbx), %rcx
cmpq 0x28(%rsp), %rcx
jg 0x6916
movq 0x20(%rsp), %rax
cmpq %rax, 0x8(%rbx)
jl 0x6916
incl %r15d
jmp 0x684c
cmpl %r15d, %r14d
jne 0x69b3
leaq 0x8da4f(%rip), %rdi     # 0x9431d
movl %r14d, %esi
xorl %eax, %eax
callq 0x61db
movq %rbx, %rdi
callq 0x9e69
movq 0x30(%rsp), %rdi
callq 0x91ad
movq 0x50(%rsp), %rdi
callq 0x45d0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %rsi
leaq 0x8d70d(%rip), %rdi     # 0x9401c
xorl %eax, %eax
callq 0x6141
movq 0x18(%rsp), %rsi
addl 0x10(%rsp), %esi
movq 0x8(%rsp), %rdx
incl %edx
incq %rcx
movq 0x8(%rbx), %r8
incq %r8
leaq 0x8d974(%rip), %rdi     # 0x942ab
movq %r13, %r9
xorl %eax, %eax
callq 0x6141
movq 0x18(%rsp), %rcx
addl 0x10(%rsp), %ecx
movq 0x8(%rsp), %r8
incl %r8d
leaq 0x8d91f(%rip), %rdi     # 0x94278
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x6141
leaq 0x8d697(%rip), %rdi     # 0x94004
xorl %eax, %eax
callq 0x6141
movq 0x18(%rsp), %rdx
addl 0x10(%rsp), %edx
movq 0x8(%rsp), %rcx
incl %ecx
leaq 0x8d873(%rip), %rdi     # 0x941fe
movl %r14d, %esi
xorl %eax, %eax
callq 0x6141
movq 0x18(%rsp), %rsi
addl 0x10(%rsp), %esi
movq 0x8(%rsp), %rdx
incl %edx
leaq 0x8d88b(%rip), %rdi     # 0x94237
xorl %eax, %eax
callq 0x6141
movq 0x18(%rsp), %rcx
addl 0x10(%rsp), %ecx
movq 0x8(%rsp), %r8
incl %r8d
leaq 0x8d91b(%rip), %rdi     # 0x942e6
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x6141