// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x48(%rbp)
movq -0x18(%rbp), %rcx
movl $0x40, %eax
subq 0x18(%rcx), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x203ca5
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x203b92
jp 0x203b92
jmp 0x203c97
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x4c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq -0x20(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq 0x10(%rdx), %rdx
movl -0x4c(%rbp), %esi
imulq $0x30, %rsi, %rsi
addq %rsi, %rdx
movl 0x14(%rdx), %edx
cmpq (%rcx,%rdx,8), %rax
ja 0x203c00
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x4c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
jmp 0x203c28
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x4c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x18(%rax)
jne 0x203c60
jmp 0x203c97
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x4c(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x54(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movl $0x30, %edx
callq 0x2180
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x203b5b
movl -0x54(%rbp), %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x203e5a
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x68(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x30(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x203cf2
jmp 0x203e49
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x68(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x58(%rbp)
movl $0x1, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x58(%rbp), %eax
ja 0x203e47
movl -0x4c(%rbp), %eax
cmpl -0x58(%rbp), %eax
je 0x203d92
movq -0x80(%rbp), %rax
movl -0x4c(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x60(%rbp), %rcx
shrq %cl, %rax
movq -0x80(%rbp), %rcx
movl -0x50(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rdx
shlq %rdx
movq -0x60(%rbp), %rcx
shrq %cl, %rdx
movq %rdx, %rcx
cmpq %rcx, %rax
je 0x203e37
movq -0x80(%rbp), %rax
movl -0x50(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x60(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x30(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x203e31
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x80(%rbp), %r8
movl -0x50(%rbp), %eax
shlq $0x5, %rax
addq %rax, %r8
movl -0x4c(%rbp), %r9d
subl -0x50(%rbp), %r9d
movq -0x20(%rbp), %rax
movq 0x40(%rax), %r14
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %r11
movq -0x68(%rbp), %rax
movl %eax, %r10d
movq -0x70(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x203200
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x203e39
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x203d3a
jmp 0x203e49
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x203cb9
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rax
imulq $0x30, (%rax), %rax
addq %rax, %rsi
callq 0x1b8260
movl $0x1, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x4c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x203fbd
movl -0x4c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
je 0x203f07
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x50(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0x203f07
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x50(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
je 0x203fad
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x50(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movl -0x4c(%rbp), %esi
subl -0x50(%rbp), %esi
callq 0x203a10
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x203f3b
jp 0x203f3b
jmp 0x203fa7
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x50(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x54(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movl $0x30, %edx
callq 0x2180
movsd -0x78(%rbp), %xmm0
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x54(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x54(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x18(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x203faf
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x203e8f
movl -0x54(%rbp), %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0x104540
movq 0x1bfff3(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x90(%rbp)
callq 0x1b7ca0
movq -0x90(%rbp), %rdi
subsd -0x48(%rbp), %xmm0
leaq 0x1886a8(%rip), %rsi    # 0x38c6b7
leaq 0x1890f5(%rip), %rdx    # 0x38d10b
movb $0x1, %al
callq 0x22a0
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)