// File: /workspace/github_cpp_makefile_star2_O2/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, 0x30(%rsp)
movq %r8, %rbx
movq %rcx, 0x28(%rsp)
pushq $0x40
popq %rcx
subq 0x18(%rdi), %rcx
movq %rsi, 0x20(%rsp)
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %edi, %edi
xorl %eax, %eax
xorl %r9d, %r9d
movq %rcx, 0x10(%rsp)
movq %r8, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
cmpq 0x18(%rdx), %r11
jae 0x119a0b
movq (%rbx), %r8
movq 0x80(%rbx), %rsi
movl (%r8,%r11,4), %r8d
incq %rsi
cmpq %r8, %rsi
jb 0x119a03
movq 0x28(%rdx), %rsi
movq (%rsi,%r11,8), %r13
movq %r13, %rbp
shrq $0x1b, %rbp
andq $-0x20, %rbp
addq 0x10(%rdx), %rbp
xorl %r12d, %r12d
pushq $0x1
popq %r15
movq %r11, 0x8(%rsp)
movq %r13, 0x50(%rsp)
movq %rbp, 0x48(%rsp)
cmpl %r13d, %r15d
ja 0x1199fe
movl %r12d, %esi
jne 0x1198fb
shlq $0x5, %rsi
movq 0x8(%rbp,%rsi), %r14
addq %r14, %r14
shrq %cl, %r14
jmp 0x119925
movl %r15d, %edx
shlq $0x5, %rdx
movq 0x8(%rbp,%rdx), %r8
addq %r8, %r8
shrq %cl, %r8
shlq $0x5, %rsi
movq 0x8(%rbp,%rsi), %r14
addq %r14, %r14
shrq %cl, %r14
cmpq %r14, %r8
je 0x1199f6
cmpq %r11, %r14
je 0x1199f3
movq (%rbx), %rdx
movq 0x80(%rbx), %rsi
movl (%rdx,%r14,4), %edx
incq %rsi
cmpq %rdx, %rsi
jb 0x1199f3
cmpq %rax, %r9
jne 0x119975
leaq (%rax,%rax), %r13
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r13
imulq $0x30, %r13, %rsi
movq %r9, %rbp
callq 0x2370
movq 0x8(%rsp), %r11
movq %rbp, %r9
movq %rax, %rdi
movq %r13, %rax
leaq 0x1(%r9), %rbp
imulq $0x30, %r9, %rcx
movl %r11d, 0x8(%rdi,%rcx)
movl %r14d, 0x14(%rdi,%rcx)
movl %r15d, %r13d
subl %r12d, %r13d
movl %r13d, 0x18(%rdi,%rcx)
cmpq %rax, %rbp
jne 0x1199c4
leaq (%rax,%rax), %r12
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r12
imulq $0x30, %r12, %rsi
movq %r9, %rbx
callq 0x2370
movq 0x8(%rsp), %r11
movq %rbx, %r9
movq 0x40(%rsp), %rbx
movq %rax, %rdi
movq %r12, %rax
movq 0x10(%rsp), %rcx
addq $0x2, %r9
imulq $0x30, %rbp, %rdx
leaq (%rdi,%rdx), %r10
movl %r14d, 0x8(%rdi,%rdx)
movl %r11d, 0x14(%rdi,%rdx)
movl %r13d, 0x18(%rdi,%rdx)
movl %r15d, %r12d
movq 0x50(%rsp), %r13
movq 0x48(%rsp), %rbp
jmp 0x1199f6
movl %r15d, %r12d
incl %r15d
jmp 0x1198dc
movq 0x38(%rsp), %rdx
incq %r11
jmp 0x11988b
movq %r10, 0x18(%rsp)
imulq $0x30, %r9, %rsi
addq %rdi, %rsi
movq %rdi, %r12
movq %r9, %r14
callq 0xf0272
movq %r14, %r8
movq %r12, %rdi
leaq 0x18(%r12), %rax
pushq $0x1
popq %rcx
xorl %edx, %edx
xorl %ebp, %ebp
movl %ecx, %esi
movl %edx, %ebx
cmpq %rsi, %r8
jb 0x119ac2
movl %ebp, %r8d
je 0x119a6d
imulq $0x30, %r8, %r9
movl 0x8(%r12,%r9), %r11d
imulq $0x30, %rsi, %r10
cmpl 0x8(%r12,%r10), %r11d
movq %r12, %rdi
jne 0x119a6d
addq %rdi, %r9
addq %rdi, %r10
movl 0x14(%r9), %r9d
cmpl 0x14(%r10), %r9d
je 0x119ab8
imulq $0x30, %r8, %r9
leaq (%rax,%r9), %r10
xorl %r11d, %r11d
cmpq %rsi, %r8
jae 0x119a89
addl (%r10), %r11d
incq %r8
addq $0x30, %r10
jmp 0x119a78
imulq $0x30, %rbx, %rsi
movups (%rdi,%r9), %xmm0
movups 0x10(%rdi,%r9), %xmm1
movups 0x20(%rdi,%r9), %xmm2
movups %xmm1, 0x10(%rdi,%rsi)
movups %xmm2, 0x20(%rdi,%rsi)
movups %xmm0, (%rdi,%rsi)
notl %r11d
movl %r11d, 0x18(%rdi,%rsi)
incl %edx
movl %ecx, %ebp
incl %ecx
movq %r14, %r8
jmp 0x119a34
imulq $0x30, %rbx, %rsi
addq %rdi, %rsi
callq 0xf0577
xorl %r15d, %r15d
cmpq %rbx, %r15
je 0x119bfb
imulq $0x30, %r15, %rax
leaq (%r12,%rax), %rdx
movq %rdx, 0x8(%rsp)
movl 0x8(%r12,%rax), %r14d
movl 0x14(%r12,%rax), %ebp
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rcx
imulq $0x30, %r14, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rcx
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0x119b2a
movq 0x10(%rax), %rsi
imulq $0x28, %rdx, %rdi
cmpb $0x0, 0x18(%rsi,%rdi)
js 0x119b26
addq %rdi, %rsi
cmpl %ebp, 0x8(%rsi)
je 0x119b30
incl %edx
jmp 0x119b08
pushq $-0x1
popq %r13
jmp 0x119b43
movq 0x10(%rsi), %rax
movq %rax, %r13
shrq $0x3, %r13
cmpq $-0x1, %rax
cmoveq %rax, %r13
movq 0x20(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
leaq 0x18(%rsp), %rcx
xorl %r8d, %r8d
callq 0x8feef
movq 0x13947f(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movq 0x30(%rsp), %rax
movsbl (%rax,%r14), %ecx
incq %r14
movsbl (%rax,%rbp), %r9d
incq %rbp
movq 0x8(%rsp), %rax
movl 0x18(%rax), %eax
notl %eax
movl %eax, (%rsp)
leaq 0xd4961(%rip), %rsi     # 0x1ee4ee
movq %r14, %rdx
movq %rbp, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %rax
movq 0x13943a(%rip), %rcx    # 0x252fe0
movq (%rcx), %rcx
testq %rax, %rax
jne 0x119bc2
leaq 0xd497a(%rip), %rdi     # 0x1ee52f
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0x119bd8
movsd 0x20(%rax), %xmm0
movq %rcx, %rdi
leaq 0xd4953(%rip), %rsi     # 0x1ee524
movb $0x1, %al
callq 0x22b0
movq 0x139401(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xd4951(%rip), %rsi     # 0x1ee53a
movq %r13, %rdx
xorl %eax, %eax
callq 0x22b0
incq %r15
jmp 0x119ad1
movq %r12, %rdi
callq 0x2220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq