// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
leaq 0x28(%rdi), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movq $0x0, 0x8(%rsp)
xorl %esi, %esi
movq $0x0, (%rsp)
cmpq (%r15), %r13
jae 0x1200a9
movq %rsi, %rbx
movq 0x10(%r15), %rdi
addq %r14, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0x28(%rsp), %r8
callq 0x11fc0f
movq 0x28(%rsp), %r12
cmpq $-0x1, %r12
je 0x12007b
movq %rax, %rbp
incq 0x30(%rsp,%r12,8)
cmpq $-0x1, %rax
movq %rbx, %rsi
je 0x12009d
cmpq %rsi, (%rsp)
jne 0x120080
leaq (%rsi,%rsi), %rbx
testq %rsi, %rsi
pushq $0x2
popq %rax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq 0x8(%rsp), %rdi
callq 0x2370
movq %rbx, %rsi
jmp 0x120085
movq %rbx, %rsi
jmp 0x12009d
movq 0x8(%rsp), %rax
leaq (%r12,%rbp,2), %rdx
movq %rax, 0x8(%rsp)
movq (%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
incq %rcx
movq %rcx, (%rsp)
incq %r13
addq $0x20, %r14
jmp 0x120008
movq 0x8(%rsp), %r13
movq (%rsp), %rax
leaq (,%rax,8), %rsi
addq %r13, %rsi
movq %r13, %rdi
callq 0xf116c
movq 0x132f14(%rip), %r15    # 0x252fe0
leaq 0xcea1f(%rip), %r14     # 0x1eeaf2
xorl %r12d, %r12d
cmpq %r12, (%rsp)
je 0x1200fc
movq (%r15), %rdi
movq (%r13,%r12,8), %rcx
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
movq %r14, %rsi
xorl %eax, %eax
callq 0x22b0
incq %r12
jmp 0x1200d6
movq %r13, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220