// File: /workspace/github_cpp_makefile_star2_O3/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, %r13
movq %rcx, %r12
movq %rdx, 0x28(%rsp)
movq %rsi, (%rsp)
movq %rdi, %rbx
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x1365ef
pushq $0x40
popq %r15
movq %rbx, 0x10(%rsp)
subq 0x18(%rbx), %r15
movsd %xmm0, 0x18(%rsp)
movq (%r13), %rdx
xorl %eax, %eax
testq %rdx, %rdx
je 0x19f0f
pushq $0x1
popq %rcx
xorpd %xmm0, %xmm0
xorl %edi, %edi
movq 0x10(%r13), %rsi
imulq $0x30, %rdi, %r8
movsd 0x20(%rsi,%r8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x19eb0
jnp 0x19f04
leaq (%rsi,%r8), %rdi
movq (%rsp), %r9
movq 0x40(%r9), %r9
movl 0x8(%rdi), %r10d
movl 0x14(%rdi), %r11d
movq (%r9,%r10,8), %r10
movq (%r9,%r11,8), %r9
cmpq %r9, %r10
cmovbq %r10, %r9
movl %r9d, 0x18(%rsi,%r8)
testl %r9d, %r9d
je 0x19f04
movl %eax, %edx
imulq $0x30, %rdx, %rdx
movupd (%rdi), %xmm1
movups 0x10(%rdi), %xmm2
movups 0x20(%rdi), %xmm3
movups %xmm3, 0x20(%rsi,%rdx)
movups %xmm2, 0x10(%rsi,%rdx)
movupd %xmm1, (%rsi,%rdx)
incl %eax
movq (%r13), %rdx
movl %ecx, %edi
incl %ecx
cmpq %rdi, %rdx
ja 0x19e99
movl %eax, %eax
movq %rax, (%r13)
movq (%rsp), %rcx
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x1a049
movq %r13, 0x8(%rsp)
xorl %r13d, %r13d
movq (%r12), %rax
movq 0x80(%r12), %rdx
movl (%rax,%r13,4), %eax
incq %rdx
cmpq %rax, %rdx
jb 0x1a034
movq (%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r13,8), %rbp
testl %ebp, %ebp
je 0x1a034
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
jne 0x19f92
movq %r8, %rcx
shlq $0x5, %rcx
movq 0x8(%r14,%rcx), %r10
addq %r10, %r10
movl %r15d, %ecx
shrq %cl, %r10
jmp 0x19fc4
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), %r10
addq %r10, %r10
movl %r15d, %ecx
shrq %cl, %r10
cmpq %r10, %rdx
jne 0x19fc4
movl %eax, %ecx
jmp 0x1a020
movq (%r12), %rcx
movq 0x80(%r12), %rdx
movl (%rcx,%r10,4), %esi
incq %rdx
movl %ebx, %ecx
cmpq %rsi, %rdx
jb 0x1a020
shlq $0x5, %r8
addq %r14, %r8
movl %ebx, %r9d
subl %eax, %r9d
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rdx
movq 0x28(%rsp), %rcx
pushq %r10
pushq %r13
pushq 0x20(%rsp)
pushq 0x50(%rsp)
movq 0x28(%rsp), %rax
pushq 0x40(%rax)
callq 0x15f2f7
addq $0x30, %rsp
movl %ebx, %ecx
incl %ebx
movl %ecx, %eax
cmpl %ebp, %ebx
jbe 0x19f74
movq (%rsp), %rax
movq 0x18(%rax), %rcx
incq %r13
cmpq %rcx, %r13
jb 0x19f2c
movq 0x8(%rsp), %r13
movq (%r13), %rax
movq 0x10(%r13), %rdi
imulq $0x30, %rax, %rsi
addq %rdi, %rsi
callq 0x136a91
movq (%r13), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x1a10b
pushq $0x1
popq %rbx
pushq $0x1
popq %rsi
xorl %ebp, %ebp
movq 0x10(%r13), %rdi
movl %eax, %edx
cmpq %rsi, %rcx
je 0x1a09d
imulq $0x30, %rsi, %rcx
movl 0x8(%rdi,%rcx), %r8d
imulq $0x30, %rdx, %rsi
cmpl 0x8(%rdi,%rsi), %r8d
jne 0x1a09d
addq %rdi, %rcx
addq %rdi, %rsi
movl 0x14(%rcx), %ecx
cmpl 0x14(%rsi), %ecx
je 0x1a0f7
imulq $0x30, %rdx, %r14
addq %r14, %rdi
movl %ebx, %esi
subl %eax, %esi
callq 0x15f8d0
ucomisd 0x217563(%rip), %xmm0   # 0x231618
jne 0x1a0b9
jnp 0x1a0f5
movq 0x10(%r13), %rax
movl %ebp, %ecx
imulq $0x30, %rcx, %rcx
movupd (%rax,%r14), %xmm1
movups 0x10(%rax,%r14), %xmm2
movups 0x20(%rax,%r14), %xmm3
movups %xmm3, 0x20(%rax,%rcx)
movups %xmm2, 0x10(%rax,%rcx)
movupd %xmm1, (%rax,%rcx)
movq 0x10(%r13), %rax
movsd %xmm0, 0x20(%rax,%rcx)
andl $0x0, 0x18(%rax,%rcx)
incl %ebp
movl %ebx, %eax
incl %ebx
movq (%r13), %rcx
movq %rbx, %rsi
cmpq %rbx, %rcx
jae 0x1a070
movl %ebp, %eax
movq %rax, (%r13)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
movq %r13, %rdi
callq 0xc4edd
movq 0x27aeae(%rip), %rax    # 0x294fe0
movq (%rax), %rbx
callq 0x1365ef
subsd 0x18(%rsp), %xmm0
leaq 0x221953(%rip), %rsi    # 0x23ba9a
leaq 0x22235c(%rip), %rdx    # 0x23c4aa
movq %rbx, %rdi
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0