// File: /workspace/github_cpp_makefile_star2_O3/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, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x18(%rdx), %r10
testq %r10, %r10
je 0x15ff4f
movq %r8, %r13
movl $0x40, %ecx
subq 0x18(%rdi), %rcx
xorl %r8d, %r8d
xorl %ebx, %ebx
xorl %edi, %edi
xorl %r11d, %r11d
xorl %eax, %eax
movq %rcx, 0x18(%rsp)
movq %r13, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq (%r13), %r9
movq 0x80(%r13), %rsi
movl (%r9,%r11,4), %r9d
incq %rsi
cmpq %r9, %rsi
jb 0x15ff41
movq 0x28(%rdx), %rsi
movq (%rsi,%r11,8), %r14
testl %r14d, %r14d
je 0x15ff41
movq %r14, %r10
shrq $0x1b, %r10
andq $-0x20, %r10
addq 0x10(%rdx), %r10
xorl %r12d, %r12d
movl $0x1, %r15d
movq %r11, 0x8(%rsp)
movq %rbx, %r9
movq %r14, 0x10(%rsp)
movq %r10, 0x20(%rsp)
cmpl %r15d, %r14d
jne 0x15fe15
movl %r12d, %edx
shlq $0x5, %rdx
movq 0x8(%r10,%rdx), %rbx
addq %rbx, %rbx
shrq %cl, %rbx
jmp 0x15fe42
movl %r15d, %edx
shlq $0x5, %rdx
movq 0x8(%r10,%rdx), %rdx
addq %rdx, %rdx
shrq %cl, %rdx
movl %r12d, %esi
shlq $0x5, %rsi
movq 0x8(%r10,%rsi), %rbx
addq %rbx, %rbx
shrq %cl, %rbx
cmpq %rbx, %rdx
je 0x15ff29
cmpq %r11, %rbx
je 0x15ff26
movq (%r13), %rsi
movq 0x80(%r13), %rdx
movl (%rsi,%rbx,4), %esi
incq %rdx
cmpq %rsi, %rdx
jb 0x15ff26
cmpq %r9, %r8
jne 0x15fe9b
leaq (%r8,%r8), %rbp
testq %r8, %r8
movl $0x2, %eax
cmoveq %rax, %rbp
movq %rbp, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r8, %r14
callq 0x2370
movq %rbp, %r9
movq 0x8(%rsp), %r11
movq %r14, %r8
movq %rax, %rdi
leaq 0x1(%r8), %r14
leaq (%r8,%r8,2), %rax
shlq $0x4, %rax
movl %r11d, 0x8(%rdi,%rax)
movl %ebx, 0x14(%rdi,%rax)
movl %r15d, %ebp
subl %r12d, %ebp
movl %ebp, 0x18(%rdi,%rax)
cmpq %r9, %r14
jne 0x15fef5
leaq (%r9,%r9), %r12
testq %r9, %r9
movl $0x2, %eax
cmoveq %rax, %r12
movq %r12, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r8, %r13
callq 0x2370
movq 0x8(%rsp), %r11
movq %r13, %r8
movq 0x50(%rsp), %r13
movq %rax, %rdi
movq %r12, %r9
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r10
addq $0x2, %r8
leaq (%r14,%r14,2), %rdx
shlq $0x4, %rdx
leaq (%rdi,%rdx), %rax
movl %ebx, 0x8(%rdi,%rdx)
movl %r11d, 0x14(%rdi,%rdx)
movl %ebp, 0x18(%rdi,%rdx)
movl %r15d, %r12d
movq 0x10(%rsp), %r14
jmp 0x15ff29
movl %r15d, %r12d
incl %r15d
cmpl %r14d, %r15d
jbe 0x15fdfc
movq %r9, %rbx
movq 0x48(%rsp), %rdx
movq 0x18(%rdx), %r10
incq %r11
cmpq %r10, %r11
jb 0x15fda6
jmp 0x15ff56
xorl %eax, %eax
xorl %edi, %edi
xorl %r8d, %r8d
movq %rax, 0x28(%rsp)
leaq (%r8,%r8,2), %rsi
shlq $0x4, %rsi
addq %rdi, %rsi
movq %rdi, %rbx
movq %r8, %r14
callq 0x136a91
testq %r14, %r14
movq %rbx, 0x8(%rsp)
je 0x16018d
movq %r14, %r11
leaq 0x18(%rbx), %rax
xorl %edx, %edx
movl $0x1, %ecx
movl $0x1, %esi
xorl %ebp, %ebp
movl %edx, %r8d
cmpq %rsi, %r11
je 0x15ffc8
leaq (%r8,%r8,2), %r10
shlq $0x4, %r10
movl 0x8(%rbx,%r10), %r9d
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
cmpl 0x8(%rbx,%rsi), %r9d
jne 0x15ffc8
addq %rbx, %r10
addq %rbx, %rsi
movl 0x14(%r10), %r9d
cmpl 0x14(%rsi), %r9d
je 0x16002a
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
leaq (%r8,%r8,2), %rsi
cmpl %ecx, %edx
jae 0x15fff7
movl %ecx, %edx
movq %rsi, %r9
shlq $0x4, %r9
addq %rax, %r9
subq %r8, %rdx
xorl %r10d, %r10d
addl (%r9), %r10d
addq $0x30, %r9
decq %rdx
jne 0x15ffe8
notl %r10d
shlq $0x4, %rsi
movl %ebp, %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movups (%rbx,%rsi), %xmm0
movups 0x10(%rbx,%rsi), %xmm1
movups 0x20(%rbx,%rsi), %xmm2
movups %xmm1, 0x10(%rbx,%rdx)
movups %xmm2, 0x20(%rbx,%rdx)
movups %xmm0, (%rbx,%rdx)
movl %r10d, 0x18(%rbx,%rdx)
incl %ebp
movl %ecx, %edx
incl %ecx
movq %rcx, %rsi
cmpq %rcx, %r11
jae 0x15ff94
movl %ebp, %eax
movq %rax, 0x10(%rsp)
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
addq %rbx, %rsi
movq %rbx, %rdi
callq 0x136dab
testl %ebp, %ebp
je 0x160198
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 0x38(%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 0x1600e3
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 0x1600c5
leaq (%rcx,%rsi,8), %rsi
cmpl %r14d, 0x8(%rsi)
je 0x1600d0
movl %edx, %esi
incl %edx
cmpq %rsi, %rax
ja 0x1600b0
jmp 0x1600e3
movq 0x10(%rsi), %rax
movq %rax, %r15
shrq $0x3, %r15
cmpq $-0x1, %rax
cmoveq %rax, %r15
addq %rdi, %r12
movq 0x30(%rsp), %rdi
movl %r13d, %esi
movl %r14d, %edx
leaq 0x28(%rsp), %rcx
xorl %r8d, %r8d
callq 0xcba40
movq 0x134edb(%rip), %rbx    # 0x294fe0
movq (%rbx), %rdi
movq 0x40(%rsp), %rax
movsbl (%rax,%r13), %ecx
incq %r13
movsbl (%rax,%r14), %r9d
incq %r14
movl 0x18(%r12), %eax
notl %eax
movl %eax, (%rsp)
leaq 0xdc4d0(%rip), %rsi     # 0x23c5fe
movq %r13, %rdx
movq %r14, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x28(%rsp), %rax
movq (%rbx), %rdi
testq %rax, %rax
jne 0x16014f
callq 0x1cda0
jmp 0x160162
movsd 0x20(%rax), %xmm0
leaq 0xdc4d9(%rip), %rsi     # 0x23c634
movb $0x1, %al
callq 0x22b0
movq 0x134e77(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0xdc4d7(%rip), %rsi     # 0x23c64a
movq %r15, %rdx
xorl %eax, %eax
callq 0x22b0
incq %rbp
cmpq 0x10(%rsp), %rbp
jne 0x16005c
jmp 0x160198
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x136dab
movq 0x8(%rsp), %rdi
callq 0x2220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq