// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: evaluate_bench_idx_hap(bench_idx*, kvec_pe_hit_hap*, ma_ug_t*)
void evaluate_bench_idx_hap(bench_idx* idx, kvec_pe_hit_hap* 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->n_u; ++k) 
    {
        distance = get_hic_distance_bench_hap(&(hits->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)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
cmpq $0x0, 0x18(%rsi)
je 0x15e990
movq %rdi, %rdx
leaq 0x28(%rdi), %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq $0x0, (%rsp)
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rsi, 0x8(%rsp)
movq (%rsi), %rdi
addq %r13, %rdi
movq 0x18(%rsp), %rsi
movq %rdx, %r14
movq 0x20(%rsp), %rcx
leaq 0x28(%rsp), %r8
callq 0x15e4be
movq %rax, %r15
movq 0x28(%rsp), %rbx
cmpq $-0x1, %rbx
je 0x15e913
incq 0x30(%rsp,%rbx,8)
cmpq $-0x1, %rbx
sete %al
cmpq $-0x1, %r15
sete %cl
orb %al, %cl
je 0x15e92f
movq 0x8(%rsp), %rsi
movq %r14, %rdx
jmp 0x15e97d
movq 0x10(%rsp), %rax
cmpq %rax, (%rsp)
jne 0x15e962
movq %r12, %rdi
leaq (%rax,%rax), %r12
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r12
leaq (,%r12,8), %rsi
callq 0x2370
movq %r12, 0x10(%rsp)
movq %rax, %r12
movq 0x8(%rsp), %rsi
movq %r14, %rdx
leaq (%rbx,%r15,2), %rax
movq (%rsp), %rcx
movq %rax, (%r12,%rcx,8)
incq %rcx
movq %rcx, (%rsp)
incq %rbp
addq $0x18, %r13
cmpq 0x18(%rsi), %rbp
jb 0x15e8e3
jmp 0x15e99b
xorl %r12d, %r12d
movq $0x0, (%rsp)
movq (%rsp), %rbx
leaq (%r12,%rbx,8), %rsi
movq %r12, %rdi
callq 0x13180d
testq %rbx, %rbx
jne 0x15e9c6
movq %r12, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1dbe4
jmp 0x15e9b0