// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movl %edx, %r12d
movl %esi, %r13d
movl %edi, %r15d
leaq -0x792(%rip), %rsi      # 0x5abc
leaq -0x6a2(%rip), %rdx      # 0x5bb3
xorl %ebp, %ebp
pushq $0x8
popq %rcx
xorl %edi, %edi
xorl %r8d, %r8d
callq 0x88ba
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x6491
decl %r13d
decl %r12d
leaq 0x44(%rsp), %rbx
leaq 0x40(%rsp), %r14
movl %r13d, %edi
movl %r12d, %esi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x61d6
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movl (%rbx), %eax
movq %rax, (%rsp)
movl (%r14), %eax
movq %rax, 0x8(%rsp)
testl %r15d, %r15d
cmovlel %ebp, %r15d
xorl %ebp, %ebp
subl $0x1, %r15d
jb 0x6332
movl %r13d, %edi
movl %r12d, %esi
leaq 0x1c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
callq 0x61d6
andq $0x0, 0x20(%rsp)
movl 0x1c(%rsp), %r14d
leal 0x1(%r14), %edx
movl 0x18(%rsp), %ebx
leal 0x1(%rbx), %ecx
leaq 0x20(%rsp), %rdi
leaq 0x6def7(%rip), %rsi     # 0x741ee
movl %edx, %r8d
movl %ecx, %r9d
xorl %eax, %eax
callq 0x7530
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x7f92
testl %eax, %eax
jne 0x6438
cmpl (%rsp), %ebx
setae %al
cmpl 0x8(%rsp), %r14d
setbe %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %ebp
jmp 0x62ba
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x918c
movq %rax, %r12
leaq 0x70cd9(%rip), %rsi     # 0x77022
movq %rbx, %rdi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %rax, %r8
callq 0x8c4c
movl %eax, %r13d
testl %ebp, %ebp
je 0x636d
testl %r13d, %r13d
je 0x649f
testl %ebp, %ebp
jne 0x637a
testl %r13d, %r13d
jne 0x64bc
xorl %r14d, %r14d
testl %r13d, %r13d
je 0x63f1
movq %r12, %rdi
callq 0x9202
testl %eax, %eax
je 0x63f4
andq $0x0, 0x20(%rsp)
movq (%r12), %rdx
movq 0x8(%r12), %rcx
incq %rdx
incq %rcx
leaq 0x20(%rsp), %rdi
leaq 0x6debf(%rip), %rsi     # 0x7426e
xorl %eax, %eax
callq 0x7530
movq 0x30(%rsp), %rbx
movq 0x10(%r12), %rax
movq (%rax), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x46d0
testl %eax, %eax
jne 0x646f
movq (%r12), %rcx
movq 0x8(%r12), %r8
cmpq 0x8(%rsp), %rcx
jg 0x644b
cmpq (%rsp), %r8
jl 0x644b
incl %r14d
jmp 0x637d
xorl %r14d, %r14d
cmpl %r14d, %ebp
jne 0x64d7
leaq 0x6df19(%rip), %rdi     # 0x7431d
movl %ebp, %esi
xorl %eax, %eax
callq 0x5de0
movq %r12, %rdi
callq 0x91ec
movq 0x10(%rsp), %rdi
callq 0x87b0
movq 0x30(%rsp), %rdi
callq 0x45d0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rsi
leaq 0x6dbd8(%rip), %rdi     # 0x7401c
xorl %eax, %eax
callq 0x5d48
movq (%rsp), %rsi
incl %esi
movq 0x8(%rsp), %rdx
incl %edx
incq %rcx
incq %r8
leaq 0x6de46(%rip), %rdi     # 0x742ab
movq %r15, %r9
xorl %eax, %eax
callq 0x5d48
movq (%rsp), %rcx
incl %ecx
movq 0x8(%rsp), %r8
incl %r8d
leaq 0x6ddf4(%rip), %rdi     # 0x74278
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x5d48
leaq 0x6db6c(%rip), %rdi     # 0x74004
xorl %eax, %eax
callq 0x5d48
movq (%rsp), %rdx
incl %edx
movq 0x8(%rsp), %rcx
incl %ecx
leaq 0x6dd4b(%rip), %rdi     # 0x741fe
movl %ebp, %esi
xorl %eax, %eax
callq 0x5d48
movq (%rsp), %rsi
incl %esi
movq 0x8(%rsp), %rdx
incl %edx
leaq 0x6dd67(%rip), %rdi     # 0x74237
xorl %eax, %eax
callq 0x5d48
movq (%rsp), %rcx
incl %ecx
movq 0x8(%rsp), %r8
incl %r8d
leaq 0x6ddfa(%rip), %rdi     # 0x742e6
movl %ebp, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x5d48