// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x21120e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
imulq $0x18, -0x20(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rsi
addq $0x28, %rsi
movq -0x8(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0x2106a0
movq %rax, -0x28(%rbp)
cmpq $-0x1, -0x30(%rbp)
je 0x21117b
movq -0x30(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp,%rax,8)
cmpq $-0x1, -0x28(%rbp)
je 0x211189
cmpq $-0x1, -0x30(%rbp)
jne 0x21118b
jmp 0x2111fd
movq -0x28(%rbp), %rax
shlq %rax
addq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x2111e0
cmpq $0x0, -0x50(%rbp)
je 0x2111b8
movq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x2111c3
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x2111c3
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdx
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x58(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x2111fd
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x211124
movq -0x48(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x1ba0f0
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x21127d
movq 0x1b2da1(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shrq %rdx
movq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
andq $0x1, %rcx
leaq 0x17c5fb(%rip), %rsi    # 0x38d863
movb $0x0, %al
callq 0x22a0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x21122e
movq -0x48(%rbp), %rdi
callq 0x2210
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)