// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: adjust_weight_kv_u_trans_advance(ha_ug_index*, kvec_pe_hit*, hc_links*, bubble_type*, kv_u_trans_t*, kv_u_trans_t*, trans_idx*)
void adjust_weight_kv_u_trans_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, 
kv_u_trans_t *ta, kv_u_trans_t *ref, trans_idx* dis)
{
    double index_time = yak_realtime();
    uint32_t k, l, m, h_occ;
    uint64_t shif = 64 - idx->uID_bits, qn, tn;
    double w;
    pe_hit *h_a = NULL;

    for (k = m = 0; k < ta->n; k++)
    {
        if(ta->a[k].nw == 0) continue;
        ta->a[k].occ = MIN(hits->occ.a[ta->a[k].qn], hits->occ.a[ta->a[k].tn]);
        if(ta->a[k].occ == 0) continue;
        ta->a[m] = ta->a[k];
        m++;
    }
    ta->n = m;

    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 tn
            {
                tn = ((h_a[l].e<<1)>>shif);
                if(!IF_HOM(tn, *bub))
                {
                    append_trans_hits(idx, link, bub, dis, h_a+l, k-l, hits->occ.a, ref, ta, qn, tn);
                }
                l = k;
            }
        }
    }
    
    radix_sort_u_trans_m(ta->a, ta->a + ta->n);

    for (k = 1, l = 0, m = 0; k <= ta->n; ++k) 
    {   
        if (k == ta->n || (ta->a[k].qn != ta->a[l].qn || ta->a[k].tn != ta->a[l].tn)) 
        {
            w = merge_u_trans_list(ta->a + l, k - l);
            if(w != 0)
            {
                ta->a[m] = ta->a[l];
                ta->a[m].nw = w;
                ta->a[m].occ = 0;
                m++;
            }
            l = k;
        }
    }
    ta->n = m;
    
    kt_u_trans_t_idx(ta, idx->ug->g->n_seq);
    fprintf(stderr, "[M::%s::%.3f] \n", __func__, yak_realtime()-index_time);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x30(%rsp)
movq %r8, %r14
movq %rcx, %r12
movq %rdx, 0x28(%rsp)
movq %rsi, (%rsp)
movq %rdi, %rbx
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0xefea7
movsd %xmm0, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x18(%rbx), %rax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movl %edx, %edx
movl %ecx, %esi
cmpq %rdx, (%r14)
jbe 0x118dad
movq 0x10(%r14), %rdi
imulq $0x30, %rdx, %r9
movsd 0x20(%rdi,%r9), %xmm1
ucomisd %xmm0, %xmm1
jne 0x118d58
jnp 0x118da9
leaq (%rdi,%r9), %r8
movq (%rsp), %r10
movq 0x40(%r10), %r10
movl 0x8(%r8), %r11d
movl 0x14(%r8), %ebx
movq (%r10,%r11,8), %r11
movq (%r10,%rbx,8), %r10
cmpq %r10, %r11
cmovbq %r11, %r10
movl %r10d, 0x18(%rdi,%r9)
testl %r10d, %r10d
je 0x118da9
imulq $0x30, %rsi, %rsi
movupd (%r8), %xmm1
movups 0x10(%r8), %xmm2
movups 0x20(%r8), %xmm3
movups %xmm3, 0x20(%rdi,%rsi)
movups %xmm2, 0x10(%rdi,%rsi)
movupd %xmm1, (%rdi,%rsi)
incl %ecx
incl %edx
jmp 0x118d38
pushq $0x40
popq %r15
subq %rax, %r15
movq %r14, 0x10(%rsp)
movq %rsi, (%r14)
xorl %r13d, %r13d
movq (%rsp), %rax
cmpq 0x18(%rax), %r13
jae 0x118ec1
movq (%r12), %rax
movq 0x80(%r12), %rcx
movl (%rax,%r13,4), %eax
incq %rcx
cmpq %rax, %rcx
jae 0x118dea
incq %r13
jmp 0x118dbf
movq (%rsp), %rcx
movq 0x28(%rcx), %rax
movq (%rax,%r13,8), %rbx
movq %rbx, %r14
shrq $0x1b, %r14
andq $-0x20, %r14
addq 0x10(%rcx), %r14
xorl %eax, %eax
pushq $0x1
popq %rbp
cmpl %ebx, %ebp
ja 0x118de5
movl %eax, %r8d
jne 0x118e2a
movq %r8, %rcx
shlq $0x5, %rcx
movq 0x8(%r14,%rcx), %r10
addq %r10, %r10
movl %r15d, %ecx
shrq %cl, %r10
jmp 0x118e5c
movl %ebp, %ecx
shlq $0x5, %rcx
movq 0x8(%r14,%rcx), %rdx
addq %rdx, %rdx
movl %r15d, %ecx
shrq %cl, %rdx
movq %r8, %rcx
shlq $0x5, %rcx
movq 0x8(%r14,%rcx), %r10
addq %r10, %r10
movl %r15d, %ecx
shrq %cl, %r10
cmpq %r10, %rdx
jne 0x118e5c
movl %eax, %ecx
jmp 0x118eb8
movq (%r12), %rcx
movq 0x80(%r12), %rdx
movl (%rcx,%r10,4), %esi
incq %rdx
movl %ebp, %ecx
cmpq %rsi, %rdx
jb 0x118eb8
shlq $0x5, %r8
addq %r14, %r8
movl %ebp, %r9d
subl %eax, %r9d
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rdx
movq 0x28(%rsp), %rcx
pushq %r10
pushq %r13
pushq 0x28(%rsp)
pushq 0x50(%rsp)
movq 0x28(%rsp), %rax
pushq 0x40(%rax)
callq 0x11871d
addq $0x30, %rsp
movl %ebp, %ecx
incl %ebp
movl %ecx, %eax
jmp 0x118e0a
movq 0x10(%rsp), %r12
movq 0x10(%r12), %rdi
imulq $0x30, (%r12), %rsi
addq %rdi, %rsi
callq 0xf0272
pushq $0x1
popq %rbx
xorl %ebp, %ebp
xorl %eax, %eax
movl %ebx, %edx
movl %ebp, %r14d
cmpq %rdx, (%r12)
jb 0x118f7a
movq 0x10(%r12), %rdi
movl %eax, %ecx
je 0x118f19
imulq $0x30, %rdx, %rdx
movl 0x8(%rdi,%rdx), %r8d
imulq $0x30, %rcx, %rsi
cmpl 0x8(%rdi,%rsi), %r8d
jne 0x118f19
addq %rdi, %rdx
addq %rdi, %rsi
movl 0x14(%rdx), %edx
cmpl 0x14(%rsi), %edx
je 0x118f73
imulq $0x30, %rcx, %r15
addq %r15, %rdi
movl %ebx, %esi
subl %eax, %esi
callq 0x118c7e
ucomisd 0xca637(%rip), %xmm0    # 0x1e3568
jne 0x118f35
jnp 0x118f71
movq 0x10(%r12), %rax
imulq $0x30, %r14, %rcx
movupd (%rax,%r15), %xmm1
movups 0x10(%rax,%r15), %xmm2
movups 0x20(%rax,%r15), %xmm3
movups %xmm3, 0x20(%rax,%rcx)
movups %xmm2, 0x10(%rax,%rcx)
movupd %xmm1, (%rax,%rcx)
movq 0x10(%r12), %rax
movsd %xmm0, 0x20(%rax,%rcx)
andl $0x0, 0x18(%rax,%rcx)
incl %ebp
movl %ebx, %eax
incl %ebx
jmp 0x118edf
movq %r14, (%r12)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
movq %r12, %rdi
callq 0x88a31
movq 0x13a03f(%rip), %rax    # 0x252fe0
movq (%rax), %rbx
callq 0xefea7
subsd 0x18(%rsp), %xmm0
leaq 0xd49d4(%rip), %rsi     # 0x1ed98a
leaq 0xd53dd(%rip), %rdx     # 0x1ee39a
movq %rbx, %rdi
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0