// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rcx, %r12
movq %rdx, 0x28(%rsp)
movq %rsi, (%rsp)
movq %rdi, %r14
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x1303c7
movsd %xmm0, 0x18(%rsp)
pushq $0x40
popq %r15
xorl %eax, %eax
movq %r14, 0x8(%rsp)
subq 0x18(%r14), %r15
cmpq $0x0, (%rbx)
je 0x1a62f
pushq $0x1
popq %rcx
xorpd %xmm0, %xmm0
xorl %esi, %esi
movq 0x10(%rbx), %rdx
imulq $0x30, %rsi, %rdi
movsd 0x20(%rdx,%rdi), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1a5d3
jnp 0x1a624
leaq (%rdx,%rdi), %rsi
movq (%rsp), %r8
movq 0x40(%r8), %r8
movl 0x8(%rsi), %r9d
movl 0x14(%rsi), %r10d
movq (%r8,%r9,8), %r9
movq (%r8,%r10,8), %r8
cmpq %r8, %r9
cmovbq %r9, %r8
movl %r8d, 0x18(%rdx,%rdi)
cmpl $0x0, 0x18(%rsi)
je 0x1a624
movl %eax, %edi
imulq $0x30, %rdi, %rdi
movupd (%rsi), %xmm1
movups 0x10(%rsi), %xmm2
movups 0x20(%rsi), %xmm3
movups %xmm3, 0x20(%rdx,%rdi)
movups %xmm2, 0x10(%rdx,%rdi)
movupd %xmm1, (%rdx,%rdi)
incl %eax
movl %ecx, %esi
incl %ecx
cmpq %rsi, (%rbx)
ja 0x1a5bd
movl %eax, %eax
movq %rbx, 0x10(%rsp)
movq %rax, (%rbx)
movq (%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x1a751
xorl %r13d, %r13d
movq (%r12), %rax
movq 0x80(%r12), %rcx
movl (%rax,%r13,4), %eax
incq %rcx
cmpq %rax, %rcx
jb 0x1a740
movq (%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r13,8), %rbp
testl %ebp, %ebp
je 0x1a740
movq %rbp, %r14
shrq $0x1b, %r14
andq $-0x20, %r14
movq (%rsp), %rax
addq 0x10(%rax), %r14
xorl %eax, %eax
pushq $0x1
popq %rbx
movl %eax, %r8d
cmpl %ebx, %ebp
je 0x1a6ca
movl %ebx, %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), %rsi
addq %rsi, %rsi
movl %r15d, %ecx
shrq %cl, %rsi
cmpq %rsi, %rdx
jne 0x1a6ca
movl %eax, %ecx
jmp 0x1a734
shlq $0x5, %r8
movq 0x8(%r14,%r8), %r10
addq %r10, %r10
movl %r15d, %ecx
shrq %cl, %r10
movq (%r12), %rcx
movq 0x80(%r12), %rdx
movl (%rcx,%r10,4), %esi
incq %rdx
movl %ebx, %ecx
cmpq %rsi, %rdx
jb 0x1a734
addq %r14, %r8
movl %ebx, %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 0x15896c
addq $0x30, %rsp
movl %ebx, %ecx
incl %ebx
movl %ecx, %eax
cmpl %ebp, %ebx
jbe 0x1a691
incq %r13
movq (%rsp), %rax
cmpq 0x18(%rax), %r13
jb 0x1a649
movq 0x10(%rsp), %r12
movq 0x10(%r12), %rdi
imulq $0x30, (%r12), %rsi
addq %rdi, %rsi
callq 0x130888
movq (%r12), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x1a826
pushq $0x1
popq %r14
pushq $0x1
popq %rdx
xorl %ebx, %ebx
movl %eax, %esi
cmpq %rdx, %rcx
je 0x1a7ae
movq 0x10(%r12), %rdi
imulq $0x30, %rdx, %rcx
movl 0x8(%rdi,%rcx), %r8d
imulq $0x30, %rsi, %rdx
cmpl 0x8(%rdi,%rdx), %r8d
jne 0x1a7ae
addq %rdi, %rcx
addq %rdi, %rdx
movl 0x14(%rcx), %ecx
cmpl 0x14(%rdx), %ecx
je 0x1a811
imulq $0x30, %rsi, %r15
movq 0x10(%r12), %rdi
addq %r15, %rdi
movl %r14d, %esi
subl %eax, %esi
callq 0x158f4b
ucomisd 0x20ad4c(%rip), %xmm0   # 0x225518
jne 0x1a7d0
jnp 0x1a80e
movq 0x10(%r12), %rax
movl %ebx, %ecx
imulq $0x30, %rcx, %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 %ebx
movl %r14d, %eax
incl %r14d
movq (%r12), %rcx
movq %r14, %rdx
cmpq %r14, %rcx
jae 0x1a780
movl %ebx, %eax
movq %rax, (%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 0xc405a
movq 0x26f793(%rip), %rax    # 0x289fe0
movq (%rax), %rbx
callq 0x1303c7
subsd 0x18(%rsp), %xmm0
leaq 0x214fe8(%rip), %rsi    # 0x22f84a
leaq 0x215a35(%rip), %rdx    # 0x23029e
movq %rbx, %rdi
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0