// File: /workspace/github_c_makefile_star2_O3/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 -0x804(%rip), %rsi      # 0x5e6c
leaq -0x6d7(%rip), %rdx      # 0x5fa0
xorl %r14d, %r14d
movl $0x8, %ecx
xorl %edi, %edi
xorl %r8d, %r8d
callq 0x92d3
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x6971
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, 0x24(%rsp)
addl %r8d, %esi
movq %rsi, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testl %ebx, %ebx
jle 0x6800
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), %r13d
movl 0x3c(%rsp), %eax
movl %eax, %r12d
subl %r13d, %r12d
imulq %rcx, %r12
movq %r12, %rax
mulq %rsi
subq %rdx, %r12
shrq %r12
addq %rdx, %r12
shrq $0x1e, %r12
movq $0x0, 0x40(%rsp)
addl 0x10(%rsp), %r15d
leal (%r12,%r13), %ecx
incl %ecx
leaq 0x40(%rsp), %rdi
leaq 0x8ba3b(%rip), %rsi     # 0x921ee
movl %r15d, %edx
movl %r15d, %r8d
movl %ecx, %r9d
xorl %eax, %eax
callq 0x7c37
movq 0x50(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x87cd
testl %eax, %eax
jne 0x6912
addl %r13d, %r12d
cmpl 0x24(%rsp), %r12d
setae %al
cmpl 0x8(%rsp), %r13d
setbe %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %r14d
decl %ebx
movq %rbp, %r13
jne 0x6735
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x9def
movq %rax, %rbx
movl 0x24(%rsp), %edx
movl 0x8(%rsp), %r15d
leaq 0x8e887(%rip), %rsi     # 0x950a7
movq %r12, %rdi
movq %rdx, 0x28(%rsp)
movq %r15, %rcx
movq %rax, %r8
callq 0x9698
testl %r14d, %r14d
je 0x6840
testl %eax, %eax
je 0x697f
testl %r14d, %r14d
jne 0x684d
testl %eax, %eax
jne 0x69a0
xorl %r13d, %r13d
testl %eax, %eax
je 0x68cd
movq %rbx, %rdi
callq 0x9e6d
testl %eax, %eax
je 0x68cd
xorl %r13d, %r13d
movq $0x0, 0x40(%rsp)
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
incq %rdx
incq %rcx
leaq 0x40(%rsp), %rdi
leaq 0x8b9e9(%rip), %rsi     # 0x9226e
xorl %eax, %eax
callq 0x7c37
movq 0x50(%rsp), %rbp
movq 0x10(%rbx), %rax
movq (%rax), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x46d0
testl %eax, %eax
jne 0x694c
movq (%rbx), %rcx
movq 0x8(%rbx), %r8
cmpq %r15, %rcx
jg 0x6925
cmpq 0x28(%rsp), %r8
jl 0x6925
incl %r13d
movq %rbx, %rdi
callq 0x9e6d
testl %eax, %eax
jne 0x6863
cmpl %r13d, %r14d
jne 0x69be
leaq 0x8ba40(%rip), %rdi     # 0x9231d
movl %r14d, %esi
xorl %eax, %eax
callq 0x61e2
movq %rbx, %rdi
callq 0x9e57
movq 0x30(%rsp), %rdi
callq 0x91b4
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 0x8b6fe(%rip), %rdi     # 0x9201c
xorl %eax, %eax
callq 0x6148
movq 0x18(%rsp), %rsi
addl 0x10(%rsp), %esi
movq 0x8(%rsp), %rdx
incl %edx
incq %rcx
incq %r8
leaq 0x8b969(%rip), %rdi     # 0x922ab
movq %r12, %r9
xorl %eax, %eax
callq 0x6148
movq 0x18(%rsp), %rcx
addl 0x10(%rsp), %ecx
movq 0x8(%rsp), %r8
incl %r8d
leaq 0x8b914(%rip), %rdi     # 0x92278
movq %rbp, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x6148
leaq 0x8b68c(%rip), %rdi     # 0x92004
xorl %eax, %eax
callq 0x6148
movq 0x18(%rsp), %rdx
addl 0x10(%rsp), %edx
movq 0x8(%rsp), %rcx
incl %ecx
leaq 0x8b868(%rip), %rdi     # 0x921fe
movl %r14d, %esi
xorl %eax, %eax
callq 0x6148
movq 0x18(%rsp), %rsi
addl 0x10(%rsp), %esi
movq 0x8(%rsp), %rdx
incl %edx
leaq 0x8b880(%rip), %rdi     # 0x92237
xorl %eax, %eax
callq 0x6148
movq 0x18(%rsp), %rcx
addl 0x10(%rsp), %ecx
movq 0x8(%rsp), %r8
incl %r8d
leaq 0x8b910(%rip), %rdi     # 0x922e6
movl %r14d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x6148