// File: chhylp123[P]hifiasm/hic.cpp
// Function: renew_kv_u_trans(kv_u_trans_t*, hc_links*, kvec_pe_hit*, kv_u_trans_t*, ha_ug_index*, bubble_type*, signed char*, mc_gg_status*, unsigned int)
void renew_kv_u_trans(kv_u_trans_t *ta, hc_links *lk, kvec_pe_hit* hits, kv_u_trans_t *ref,
ha_ug_index* idx, bubble_type* bub, int8_t *s, mc_gg_status *sa, uint32_t ignore_dis)
{   
    uint64_t k, i, m, is_comples_weight = 0;
    trans_idx dis;
    kv_init(dis);
    if(bub->round_id > 0 && ignore_dis == 0)
    {
        is_comples_weight = get_trans_rate_function_advance(idx, hits, lk, bub, NULL, s, sa, &dis);
    }

    for (i = 0; i < lk->a.n; i++)
    {
        for (k = m = 0; k < lk->a.a[i].e.n; k++)
        {
            if(lk->a.a[i].e.a[k].del) continue;
            lk->a.a[i].e.a[m] = lk->a.a[i].e.a[k];
            lk->a.a[i].e.a[m].weight = 0;
            lk->a.a[i].e.a[m].occ = 0;
            m++;
        }
        lk->a.a[i].e.n = m;
    }

    if(hits->idx.n == 0) idx_hc_links(hits, idx, bub);

    weight_kv_u_trans(idx, hits, lk, bub, ta, is_comples_weight == 1? &dis : NULL, asm_opt.flag&HA_F_USKEW?0:1);
    // if(bub->round_id == bub->n_round-1)
    // {
    //     print_debug_hc_links(idx, bub, lk, ta, hits);
    // }
    // adjust_weight_kv_u_trans(idx, hits, lk, bub, ta, ref, is_comples_weight == 1? &dis : NULL);
    adjust_weight_kv_u_trans_advance(idx, hits, lk, bub, ta, ref, is_comples_weight == 1? &dis : NULL);
    kv_destroy(dis);
    // print_kv_weight(ta);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jbe 0x204483
cmpl $0x0, 0x20(%rbp)
jne 0x204483
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r10
xorl %eax, %eax
movl %eax, %r8d
leaq -0x78(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x1ea4b0
cltq
movq %rax, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2045c2
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x20459a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x2044f4
jmp 0x204589
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
imulq $0x28, -0x48(%rbp), %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2044ac
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x20448b
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x2045de
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x1d2bc0
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x1, -0x50(%rbp)
jne 0x204626
leaq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x204631
xorl %eax, %eax
movq %rax, -0xa8(%rbp)
jmp 0x204631
movq -0x80(%rbp), %r8
movq -0x88(%rbp), %rcx
movq -0x90(%rbp), %rdx
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %r9
leaq 0x1c0199(%rip), %rax    # 0x3c47f8
movl (%rax), %r11d
andl $0x2000, %r11d          # imm = 0x2000
movl $0x1, %eax
xorl %r10d, %r10d
cmpl $0x0, %r11d
cmovnel %r10d, %eax
movl %eax, (%rsp)
callq 0x201970
movq -0x28(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x1, -0x50(%rbp)
jne 0x2046d7
leaq -0x78(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x2046e2
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
jmp 0x2046e2
movq -0xb0(%rbp), %r9
movq -0xb8(%rbp), %r8
movq -0xc0(%rbp), %rcx
movq -0xc8(%rbp), %rdx
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movq %rax, (%rsp)
callq 0x203b00
movq -0x78(%rbp), %rdi
callq 0x2210
addq $0xf0, %rsp
popq %rbp
retq
nop