// File: chhylp123[P]hifiasm/hic.cpp
// Function: debug_hc_hits_v14(kvec_pe_hit_hap*, char const*, ha_ug_index const*)
void debug_hc_hits_v14(kvec_pe_hit_hap* i_hits, const char *fn, const ha_ug_index* idx)
{
    uint64_t flag = 0;
    char *buf = (char*)calloc(strlen(fn) + 25, 1);
	sprintf(buf, "%s.v14.hic.lk.bin", fn);
    kvec_pe_hit hits; 
    kv_init(hits.a);
    FILE* fp = NULL; 
    fp = fopen(buf, "r"); 

    kv_init(hits.a);
    flag += fread(&hits.a.n, sizeof(hits.a.n), 1, fp);
    hits.a.m = hits.a.n; MALLOC(hits.a.a, hits.a.n);
    flag += fread(hits.a.a, sizeof(pe_hit), hits.a.n, fp);

    radix_sort_pe_hit_id(hits.a.a, hits.a.a + hits.a.n);
    radix_sort_pe_hit_hap_id(i_hits->a, i_hits->a + i_hits->n_u);

    fprintf(stderr, "i_hits->n_u: %lu, hits.a.n: %lu\n", (uint64_t)i_hits->n_u, (uint64_t)hits.a.n);

    uint64_t i, k;
    uint64_t i_beg_utg, i_beg_pos, i_beg_rev;
    uint64_t i_end_utg, i_end_pos, i_end_rev;
    uint64_t k_beg_utg, k_beg_pos, k_beg_rev;
    uint64_t k_end_utg, k_end_pos, k_end_rev;
    uint64_t i_id, k_id;
    uint64_t same_occ = 0, diff_occ = 0, miss_occ = 0;
    for (i = 0, k = 0; i < i_hits->n_u; i++)
    {
        i_beg_rev = get_pe_s(i_hits->a[i])>>63;
        i_beg_utg = ((get_pe_s(i_hits->a[i])<<1)>>(64 - idx->uID_bits));
        i_beg_pos = get_pe_s(i_hits->a[i]) & idx->pos_mode;

        i_end_rev = get_pe_e(i_hits->a[i])>>63;
        i_end_utg = ((get_pe_e(i_hits->a[i])<<1)>>(64 - idx->uID_bits));
        i_end_pos = get_pe_e(i_hits->a[i]) & idx->pos_mode;

        i_id = i_hits->a[i].id;
        for (; k < hits.a.n; k++)
        {
            k_beg_rev = hits.a.a[k].s>>63;
            k_beg_utg = ((hits.a.a[k].s<<1)>>(64 - idx->uID_bits));
            k_beg_pos = hits.a.a[k].s & idx->pos_mode;

            k_end_rev = hits.a.a[k].e>>63;
            k_end_utg = ((hits.a.a[k].e<<1)>>(64 - idx->uID_bits));
            k_end_pos = hits.a.a[k].e & idx->pos_mode;

            k_id = hits.a.a[k].id;

            if(k_id > i_id)
            {
                miss_occ++;
                fprintf(stderr, "\n[MISS]rid=%lu\n", i_id);
                fprintf(stderr, "********v0.15********\n");
                fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n", 
                i_beg_rev, i_beg_utg, i_beg_pos);
                fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n", 
                i_end_rev, i_end_utg, i_end_pos);
                break;
            } 
            
            if(k_id == i_id)
            {
                if(get_pe_s(i_hits->a[i]) == hits.a.a[k].s && get_pe_e(i_hits->a[i]) == hits.a.a[k].e)
                {
                    same_occ++;
                    // fprintf(stderr, "\n[SAME]rid=%lu\n", i_id);
                    // fprintf(stderr, "********v0.15********\n");
                    // fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n", 
                    // i_beg_rev, i_beg_utg, i_beg_pos);
                    // fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n", 
                    // i_end_rev, i_end_utg, i_end_pos);
                    // fprintf(stderr, "********v0.14********\n");
                    // fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n", 
                    // k_beg_rev, k_beg_utg, k_beg_pos);
                    // fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n", 
                    // k_end_rev, k_end_utg, k_end_pos);
                }
                else
                {
                    diff_occ++;
                    fprintf(stderr, "\n[DIFF]rid=%lu\n", i_id);
                    fprintf(stderr, "********v0.15********\n");
                    fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n", 
                    i_beg_rev, i_beg_utg, i_beg_pos);
                    fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n", 
                    i_end_rev, i_end_utg, i_end_pos);
                    fprintf(stderr, "********v0.14********\n");
                    fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n", 
                    k_beg_rev, k_beg_utg, k_beg_pos);
                    fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n", 
                    k_end_rev, k_end_utg, k_end_pos);
                }
                break;
            }
        }
    }
    
    fprintf(stderr, "same_occ: %lu, diff_occ: %lu, miss_occ: %lu", same_occ, diff_occ, miss_occ);


    kv_destroy(hits.a);
    fclose(fp);
    free(buf);
    exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x19, %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1b71a2(%rip), %rsi    # 0x38c45e
movb $0x0, %al
callq 0x2050
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x1bb0e5(%rip), %rsi    # 0x3903d6
callq 0x2200
movq %rax, -0x88(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
leaq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rdi
shlq $0x5, %rdi
callq 0x2270
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x88(%rbp), %rcx
movl $0x20, %esi
callq 0x22e0
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x70(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x80(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rsi
callq 0x1d5210
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
imulq $0x18, 0x18(%rax), %rax
addq %rax, %rsi
callq 0x1d4cc0
movq 0x1eec31(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x80(%rbp), %rcx
leaq 0x1b70c9(%rip), %rsi    # 0x38c48e
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x110(%rbp)
movq $0x0, -0x118(%rbp)
movq $0x0, -0x120(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x90(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x1d592f
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq (%rax), %rax
shrq $0x3f, %rax
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq (%rax), %rax
shlq %rax
movq -0x18(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
andq 0x30(%rcx), %rax
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x90(%rbp), %rdx
addq %rdx, %rcx
movzwl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x3f, %rax
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x90(%rbp), %rdx
addq %rdx, %rcx
movzwl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
shlq %rax
movq -0x18(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x90(%rbp), %rdx
addq %rdx, %rcx
movzwl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
andq 0x30(%rcx), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x100(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x80(%rbp), %rax
jae 0x1d5916
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x3f, %rax
movq %rax, -0xe0(%rbp)
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0x18(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0xd0(%rbp)
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
andq 0x30(%rcx), %rax
movq %rax, -0xd8(%rbp)
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x3f, %rax
movq %rax, -0xf8(%rbp)
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x18(%rbp), %rdx
movl $0x40, %ecx
subq 0x18(%rdx), %rcx
shrq %cl, %rax
movq %rax, -0xe8(%rbp)
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
andq 0x30(%rcx), %rax
movq %rax, -0xf0(%rbp)
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
cmpq -0x100(%rbp), %rax
jbe 0x1d5745
movq -0x120(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x120(%rbp)
movq 0x1ee92a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x100(%rbp), %rdx
leaq 0x1b6de8(%rip), %rsi    # 0x38c4af
movb $0x0, %al
callq 0x22a0
movq 0x1ee90b(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1b6de0(%rip), %rsi    # 0x38c4bf
movb $0x0, %al
callq 0x22a0
movq 0x1ee8f3(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xb0(%rbp), %rdx
movq -0xa0(%rbp), %rcx
movq -0xa8(%rbp), %r8
leaq 0x1b6dca(%rip), %rsi    # 0x38c4d6
movb $0x0, %al
callq 0x22a0
movq 0x1ee8c6(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xc8(%rbp), %rdx
movq -0xb8(%rbp), %rcx
movq -0xc0(%rbp), %r8
leaq 0x1b6dc7(%rip), %rsi    # 0x38c500
movb $0x0, %al
callq 0x22a0
jmp 0x1d5916
movq -0x108(%rbp), %rax
cmpq -0x100(%rbp), %rax
jne 0x1d58fd
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movq -0x98(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jne 0x1d57e6
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x90(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x90(%rbp), %rdx
addq %rdx, %rcx
movzwl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq -0x70(%rbp), %rcx
movq -0x98(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jne 0x1d57e6
movq -0x110(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x110(%rbp)
jmp 0x1d58fb
movq -0x118(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x118(%rbp)
movq 0x1ee7e1(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x100(%rbp), %rdx
leaq 0x1b6d1a(%rip), %rsi    # 0x38c52a
movb $0x0, %al
callq 0x22a0
movq 0x1ee7c2(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1b6c97(%rip), %rsi    # 0x38c4bf
movb $0x0, %al
callq 0x22a0
movq 0x1ee7aa(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xb0(%rbp), %rdx
movq -0xa0(%rbp), %rcx
movq -0xa8(%rbp), %r8
leaq 0x1b6c81(%rip), %rsi    # 0x38c4d6
movb $0x0, %al
callq 0x22a0
movq 0x1ee77d(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xc8(%rbp), %rdx
movq -0xb8(%rbp), %rcx
movq -0xc0(%rbp), %r8
leaq 0x1b6c7e(%rip), %rsi    # 0x38c500
movb $0x0, %al
callq 0x22a0
movq 0x1ee750(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1b6ca0(%rip), %rsi    # 0x38c53a
movb $0x0, %al
callq 0x22a0
movq 0x1ee738(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xe0(%rbp), %rdx
movq -0xd0(%rbp), %rcx
movq -0xd8(%rbp), %r8
leaq 0x1b6c0f(%rip), %rsi    # 0x38c4d6
movb $0x0, %al
callq 0x22a0
movq 0x1ee70b(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xf8(%rbp), %rdx
movq -0xe8(%rbp), %rcx
movq -0xf0(%rbp), %r8
leaq 0x1b6c0c(%rip), %rsi    # 0x38c500
movb $0x0, %al
callq 0x22a0
jmp 0x1d5916
jmp 0x1d58ff
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x1d5572
jmp 0x1d5918
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x1d5403
movq 0x1ee6aa(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x110(%rbp), %rdx
movq -0x118(%rbp), %rcx
movq -0x120(%rbp), %r8
leaq 0x1b6bfc(%rip), %rsi    # 0x38c551
movb $0x0, %al
callq 0x22a0
movq -0x70(%rbp), %rdi
callq 0x2210
movq -0x88(%rbp), %rdi
callq 0x21a0
movq -0x28(%rbp), %rdi
callq 0x2210
movl $0x1, %edi
callq 0x2240
nopw %cs:(%rax,%rax)