// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: debug_output_disconnected_hits(ha_ug_index*, kv_u_trans_t*, kvec_pe_hit*, hc_links*, bubble_type*, signed char*)
void debug_output_disconnected_hits(ha_ug_index* idx, kv_u_trans_t *ta, kvec_pe_hit *hits, hc_links *link, bubble_type *bub, int8_t *s)
{
    uint32_t k, l, i, m, h_occ;
    uint64_t shif = 64 - idx->uID_bits, qn, tn, u_dis;
    pe_hit *h_a = NULL;
    hc_linkeage *t = NULL;
    u_trans_t *p = NULL;
    kv_u_trans_t k_trans; 
    kv_init(k_trans);


    for (qn = 0; qn < hits->idx.n; qn++)
    {
        if(IF_HOM(qn, *bub)) continue;
        h_a = hits->a.a + (hits->idx.a[qn]>>32);
        h_occ = (uint32_t)(hits->idx.a[qn]);

        for (k = 1, l = 0; k <= h_occ; ++k) ///same qn
        {
            if (k == h_occ || ((h_a[k].e<<1)>>shif) != ((h_a[l].e<<1)>>shif)) //same qn and tn
            {
                tn = ((h_a[l].e<<1)>>shif);
                if(!IF_HOM(tn, *bub) && tn != qn)
                {
                    // t = &(link->a.a[qn]);
                    // for (i = 0, u_dis = (uint64_t)-1; i < t->e.n; i++)
                    // {
                    //     if(t->e.a[i].del || t->e.a[i].uID != tn) continue;
                    //     u_dis = (t->e.a[i].dis ==(uint64_t)-1? (uint64_t)-1 : t->e.a[i].dis>>3);
                    //     break;
                    // }
                    
                    // if(u_dis == (uint64_t)-1)
                    {
                        kv_pushp(u_trans_t, k_trans, &p);
                        p->qn = qn; p->tn = tn; p->occ = (k-l);
                        kv_pushp(u_trans_t, k_trans, &p);
                        p->qn = tn; p->tn = qn; p->occ = (k-l);
                    }
                }
                l = k;
            }
        }
    }


    radix_sort_u_trans_m(k_trans.a, k_trans.a + k_trans.n);

    for (k = 1, l = 0, m = 0; k <= k_trans.n; ++k)
    {
        if (k == k_trans.n || k_trans.a[l].qn != k_trans.a[k].qn || k_trans.a[l].tn != k_trans.a[k].tn) //same qn and tn
        {
            for (i = l, h_occ = 0; i < k; i++)
            {
                h_occ += k_trans.a[i].occ;
            }

            k_trans.a[m] = k_trans.a[l];
            k_trans.a[m].occ = ((uint32_t)-1) - h_occ;
            m++;
            l = k;
        }
    }
    k_trans.n = m;

    radix_sort_u_trans_occ(k_trans.a, k_trans.a + k_trans.n);
    for (i = 0; i < k_trans.n; i++)
    {
        qn = k_trans.a[i].qn;
        tn = k_trans.a[i].tn;

        t = &(link->a.a[qn]);
        for (k = 0, u_dis = (uint64_t)-1; k < t->e.n; k++)
        {
            if(t->e.a[k].del || t->e.a[k].uID != tn) continue;
            u_dis = (t->e.a[k].dis ==(uint64_t)-1? (uint64_t)-1 : t->e.a[k].dis>>3);
            break;
        }
        get_u_trans_spec(ta, qn, tn, &p, NULL);

        fprintf(stderr, "s-utg%.6lul[hap-%d]<--->d-utg%.6lul[hap-%d](occ: %u, ",
        qn + 1, s[qn], tn + 1, s[tn], ((uint32_t)-1) - k_trans.a[i].occ);
        if(p) fprintf(stderr, "weight: %f", p->nw);
        else fprintf(stderr, "weight: NA");
        fprintf(stderr, "):(dis-%lu)\n", u_dis);
    }

    // fprintf(stderr, "########hits########\n");
    // char dir[2] = {'+', '-'};
    // for (k = 0; k < hits->a.n; ++k) 
    // { 
    //     fprintf(stderr, "%c\tutg%.6dl(len-%u)\t%lu\t%c\tutg%.6dl(len-%u)\t%lu\ti:%lu\n", 
    //     dir[hits->a.a[k].s>>63], (int)((hits->a.a[k].s<<1)>>shif)+1, 
    //     idx->ug->g->seq[((hits->a.a[k].s<<1)>>shif)].len, hits->a.a[k].s&idx->pos_mode,
    //     dir[hits->a.a[k].e>>63], (int)((hits->a.a[k].e<<1)>>shif)+1, 
    //     idx->ug->g->seq[((hits->a.a[k].e<<1)>>shif)].len, hits->a.a[k].e&idx->pos_mode,
    //     hits->a.a[k].id);        
    // }
    kv_destroy(k_trans);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl $0x40, %ecx
subq 0x18(%rdi), %rcx
movq $0x0, 0x18(%rsp)
cmpq $0x0, 0x18(%rdx)
je 0x1595e4
movq %r8, %r15
xorl %r9d, %r9d
xorl %eax, %eax
xorl %edi, %edi
xorl %r10d, %r10d
movq %rdx, 0x40(%rsp)
movq %rcx, 0x20(%rsp)
movq %r8, 0x48(%rsp)
movq (%r15), %r8
movq 0x80(%r15), %rsi
movl (%r8,%r10,4), %r8d
incq %rsi
cmpq %r8, %rsi
jb 0x1595d0
movq 0x28(%rdx), %rsi
movq (%rsi,%r10,8), %r11
testl %r11d, %r11d
je 0x1595d0
movq %r11, %r13
shrq $0x1b, %r13
andq $-0x20, %r13
addq 0x10(%rdx), %r13
xorl %r14d, %r14d
movl $0x1, %ebx
movq %r10, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r13, 0x50(%rsp)
movl %r14d, %edx
cmpl %ebx, %r11d
je 0x1594b6
movl %ebx, %esi
shlq $0x5, %rsi
movq 0x8(%r13,%rsi), %rsi
addq %rsi, %rsi
shrq %cl, %rsi
movq %rdx, %r8
shlq $0x5, %r8
movq 0x8(%r13,%r8), %r8
addq %r8, %r8
shrq %cl, %r8
cmpq %r8, %rsi
je 0x1595c5
shlq $0x5, %rdx
movq 0x8(%r13,%rdx), %r12
addq %r12, %r12
shrq %cl, %r12
cmpq %r10, %r12
je 0x1595c2
movq (%r15), %rsi
movq 0x80(%r15), %rdx
movl (%rsi,%r12,4), %esi
incq %rdx
cmpq %rsi, %rdx
jb 0x1595c2
cmpq %rax, %r9
jne 0x15951e
leaq (%rax,%rax), %r13
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r13
movq %r13, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r9, %rbp
callq 0x2370
movq 0x8(%rsp), %r10
movq %rbp, %r9
movq %rax, %rdi
movq %r13, %rax
leaq 0x1(%r9), %rbp
leaq (%r9,%r9,2), %rcx
shlq $0x4, %rcx
leaq (%rdi,%rcx), %rdx
movq %rdx, 0x18(%rsp)
movl %r10d, 0x8(%rdi,%rcx)
movl %r12d, 0x14(%rdi,%rcx)
movl %ebx, %r13d
subl %r14d, %r13d
movl %r13d, 0x18(%rdi,%rcx)
cmpq %rax, %rbp
jne 0x159583
leaq (%rax,%rax), %r14
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r14
movq %r14, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r9, %r15
callq 0x2370
movq 0x8(%rsp), %r10
movq %r15, %r9
movq 0x48(%rsp), %r15
movq %rax, %rdi
movq %r14, %rax
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %r11
addq $0x2, %r9
leaq (,%rbp,2), %rsi
addq %rbp, %rsi
shlq $0x4, %rsi
leaq (%rdi,%rsi), %rdx
movq %rdx, 0x18(%rsp)
movl %r12d, 0x8(%rdi,%rsi)
movl %r10d, 0x14(%rdi,%rsi)
movl %r13d, 0x18(%rdi,%rsi)
movl %ebx, %r14d
movq 0x50(%rsp), %r13
jmp 0x1595c5
movl %ebx, %r14d
incl %ebx
cmpl %r11d, %ebx
jbe 0x159482
incq %r10
movq 0x40(%rsp), %rdx
cmpq 0x18(%rdx), %r10
jb 0x159431
jmp 0x1595e9
xorl %edi, %edi
xorl %r9d, %r9d
movq %rdi, 0x8(%rsp)
leaq (%r9,%r9,2), %rsi
shlq $0x4, %rsi
addq %rdi, %rsi
movq %r9, %rbx
callq 0x130888
movq 0x8(%rsp), %rdi
testq %rbx, %rbx
movl $0x0, %r14d
je 0x1596d2
movq %rbx, %r11
leaq 0x18(%rdi), %rax
xorl %esi, %esi
movl $0x1, %ecx
movl $0x1, %r10d
xorl %r14d, %r14d
movl %esi, %edx
cmpq %r10, %r11
je 0x15965f
leaq (%rdx,%rdx,2), %r8
shlq $0x4, %r8
movl 0x8(%rdi,%r8), %r9d
leaq (%r10,%r10,2), %r10
shlq $0x4, %r10
cmpl 0x8(%rdi,%r10), %r9d
jne 0x15965f
addq %rdi, %r8
addq %rdi, %r10
movl 0x14(%r8), %r8d
cmpl 0x14(%r10), %r8d
je 0x1596c4
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpl %ecx, %esi
jae 0x15968b
movl %ecx, %esi
leaq (%rdx,%rdx,2), %r8
shlq $0x4, %r8
addq %rax, %r8
subq %rdx, %rsi
xorl %r9d, %r9d
addl (%r8), %r9d
addq $0x30, %r8
decq %rsi
jne 0x15967c
notl %r9d
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movl %r14d, %esi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movups (%rdi,%rdx), %xmm0
movups 0x10(%rdi,%rdx), %xmm1
movups 0x20(%rdi,%rdx), %xmm2
movups %xmm1, 0x10(%rdi,%rsi)
movups %xmm2, 0x20(%rdi,%rsi)
movups %xmm0, (%rdi,%rsi)
movl %r9d, 0x18(%rdi,%rsi)
incl %r14d
movl %ecx, %esi
incl %ecx
movq %rcx, %r10
cmpq %rcx, %r11
jae 0x15962c
movl %r14d, %eax
movq %rax, 0x10(%rsp)
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x130ba5
testl %r14d, %r14d
je 0x159824
xorl %ebp, %ebp
leaq (,%rbp,2), %r12
addq %rbp, %r12
shlq $0x4, %r12
movq 0x8(%rsp), %rdi
movl 0x8(%rdi,%r12), %r13d
movl 0x14(%rdi,%r12), %r14d
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rcx
leaq (,%r13,2), %rdx
addq %r13, %rdx
shlq $0x4, %rdx
movq (%rcx,%rdx), %rax
movq $-0x1, %r15
testq %rax, %rax
je 0x15977c
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl $0x1, %edx
xorl %esi, %esi
leaq (%rsi,%rsi,4), %rsi
cmpb $0x0, 0x18(%rcx,%rsi,8)
js 0x15975e
leaq (%rcx,%rsi,8), %rsi
cmpl %r14d, 0x8(%rsi)
je 0x159769
movl %edx, %esi
incl %edx
cmpq %rsi, %rax
ja 0x159749
jmp 0x15977c
movq 0x10(%rsi), %rax
movq %rax, %r15
shrq $0x3, %r15
cmpq $-0x1, %rax
cmoveq %rax, %r15
addq %rdi, %r12
movq 0x28(%rsp), %rdi
movl %r13d, %esi
movl %r14d, %edx
leaq 0x18(%rsp), %rcx
xorl %r8d, %r8d
callq 0xca79c
movq 0x130842(%rip), %rbx    # 0x289fe0
movq (%rbx), %rdi
movq 0x38(%rsp), %rax
movsbl (%rax,%r13), %ecx
incq %r13
movsbl (%rax,%r14), %r9d
incq %r14
movl 0x18(%r12), %eax
notl %eax
movl %eax, (%rsp)
leaq 0xd6c2b(%rip), %rsi     # 0x2303f2
movq %r13, %rdx
movq %r14, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %rax
movq (%rbx), %rdi
testq %rax, %rax
jne 0x1597e8
callq 0x1db26
jmp 0x1597fb
movsd 0x20(%rax), %xmm0
leaq 0xd6c34(%rip), %rsi     # 0x230428
movb $0x1, %al
callq 0x22b0
movq 0x1307de(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0xd6c32(%rip), %rsi     # 0x23043e
movq %r15, %rdx
xorl %eax, %eax
callq 0x22b0
incq %rbp
cmpq 0x10(%rsp), %rbp
jne 0x1596f5
movq 0x8(%rsp), %rdi
callq 0x2220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq