// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: evaluate_bench_idx(bench_idx*, kvec_pe_hit*, ma_ug_t*)
void evaluate_bench_idx(bench_idx* idx, kvec_pe_hit* hits, ma_ug_t *ug)
{
    uint64_t k, distance, is_trans, trans[2];
    kvec_t(uint64_t) buf;
    kv_init(buf);
    for (k = trans[0] = trans[1] = 0; k < hits->a.n; ++k) 
    {
        distance = get_hic_distance_bench(&(hits->a.a[k]), &(idx->link), idx, ug, &is_trans);
        if(is_trans != (uint64_t)-1) trans[is_trans]++;
        if(distance == (uint64_t)-1 || is_trans == (uint64_t)-1) continue;
        distance = (distance << 1) + is_trans;
        kv_push(uint64_t, buf, distance); 
    }

    radix_sort_hc64(buf.a, buf.a+buf.n);

    for (k = 0; k < buf.n; k++)
    {
        fprintf(stderr, "%lu\t%lu\n", buf.a[k]>>1, buf.a[k]&1);
    }
    /**
    uint64_t up_dis = buf.a[(uint64_t)(buf.n*0.99)]>>1, step = 7240;
    uint64_t step_s = 0, step_e = step, cnt[2];
    for (k = cnt[0] = cnt[1] = 0; k < buf.n; k++)
    {
        if(step_s > up_dis) step_e = (buf.a[buf.n-1]>>1) + 1;
        if((buf.a[k]>>1) < step_e && (buf.a[k]>>1) >= step_s)
        {
            cnt[buf.a[k]&1]++;
        }
        if((buf.a[k]>>1) >= step_e)
        {
            while (!((buf.a[k]>>1) < step_e && (buf.a[k]>>1) >= step_s))
            {
                fprintf(stderr, "i: %lu, step_s: %lu, step_e: %lu, cnt[0]: %lu, cnt[1]: %lu, rate: %f\n", 
                step_s/step, step_s, step_e, cnt[0], cnt[1], ((double)cnt[1])/(double)(cnt[0] + cnt[1]));
                step_s += step;
                step_e += step;
                cnt[0] = cnt[1] = 0;
            }
        }
    }

    if(cnt[0] > 0 || cnt[1] > 0)
    {
        fprintf(stderr, "i: %lu, step_s: %lu, step_e: %lu, cnt[0]: %lu, cnt[1]: %lu, rate: %f\n", 
                step_s/step, step_s, step_e, cnt[0], cnt[1], ((double)cnt[1])/(double)(cnt[0] + cnt[1]));
    }
    **/
    kv_destroy(buf);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq %rsi, 0x20(%rsp)
movq (%rsi), %r13
testq %r13, %r13
je 0x1654f2
movq %rdi, %rdx
leaq 0x28(%rdi), %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdi
addq %r14, %rdi
movq 0x28(%rsp), %rsi
movq %rdx, %r12
movq 0x30(%rsp), %rcx
leaq 0x38(%rsp), %r8
callq 0x165007
movq 0x38(%rsp), %r15
cmpq $-0x1, %r15
je 0x1654b7
movq %rax, %rbx
incq 0x40(%rsp,%r15,8)
cmpq $-0x1, %rax
je 0x1654b7
movq 0x10(%rsp), %rdx
cmpq 0x18(%rsp), %rdx
jne 0x165492
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
leaq (,%rcx,8), %rsi
movq 0x8(%rsp), %rdi
movq %rdx, %r13
callq 0x2370
jmp 0x16549a
movq 0x8(%rsp), %rax
movq %rdx, %r13
leaq (%r15,%rbx,2), %rdx
movq %rax, 0x8(%rsp)
movq %rdx, (%rax,%r13,8)
incq %r13
movq %r13, 0x10(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %r13
incq %rbp
addq $0x20, %r14
cmpq %r13, %rbp
movq %r12, %rdx
jb 0x16541e
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r14
leaq (%rbx,%r14,8), %rsi
movq %rbx, %rdi
callq 0x1379f9
testq %r14, %r14
je 0x1654fd
movq %r14, %rsi
movq %rbx, %rdi
callq 0x1ce8f
jmp 0x1654fd
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
callq 0x1379f9
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220