// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: weight_edges_advance(ha_ug_index*, kvec_pe_hit*, hc_links*, bubble_type*, trans_idx*)
void weight_edges_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, trans_idx* dis)
{
    uint64_t k, i, shif = 64 - idx->uID_bits, beg, end, t_d;
    hc_edge *e1 = NULL, *e2 = NULL;
    long double weight;

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

    for (k = 0; k < hits->a.n; ++k) 
    {
        beg = ((hits->a.a[k].s<<1)>>shif);
        end = ((hits->a.a[k].e<<1)>>shif);

        if(beg == end) continue;
        if(IF_HOM(beg, *bub)) continue;
        if(IF_HOM(end, *bub)) continue;
        
        t_d = get_hic_distance(&(hits->a.a[k]), link, idx, NULL);
        if(t_d == (uint64_t)-1) continue;

        e1 = get_hc_edge(link, beg, end, 0);
        e2 = get_hc_edge(link, end, beg, 0);
        if(e1 == NULL || e2 == NULL) continue;
        weight = 1;
        if(dis)
        {
            weight = get_trans_weight_advance(idx, t_d, dis);
        }
        
        e1->weight += weight; e1->occ++;
        e2->weight += weight; e2->occ++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r9
movq %rdx, %r10
movq %rsi, %r12
movl $0x40, %ebp
movq %rdi, 0x18(%rsp)
subq 0x18(%rdi), %rbp
movq (%rdx), %rax
testq %rax, %rax
je 0x1442a8
movq 0x10(%r10), %rcx
xorl %edx, %edx
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
movq (%rcx,%rdi), %rsi
testq %rsi, %rsi
je 0x1442a0
addq %rcx, %rdi
movq 0x10(%rdi), %rdi
cmpb $0x0, 0x18(%rdi)
js 0x144297
movq $0x0, (%rdi)
addq $0x28, %rdi
decq %rsi
jne 0x14428a
incq %rdx
cmpq %rax, %rdx
jne 0x144272
movq %r8, 0x30(%rsp)
cmpq $0x0, (%r12)
je 0x1445d5
xorl %ebx, %ebx
fld1
flds 0xead62(%rip)           # 0x22f024
fstpt 0x8c(%rsp)
fchs
fstpt 0x80(%rsp)
fldl 0xead20(%rip)           # 0x22eff8
fstpt 0x74(%rsp)
movq %r9, 0x28(%rsp)
movq %r10, 0x20(%rsp)
movq 0x10(%r12), %rdi
movq %rbx, %rax
shlq $0x5, %rax
movq (%rdi,%rax), %r14
addq %r14, %r14
movl %ebp, %ecx
shrq %cl, %r14
movq 0x8(%rdi,%rax), %r15
addq %r15, %r15
shrq %cl, %r15
cmpq %r15, %r14
je 0x1445c8
movq (%r9), %rdx
movq 0x80(%r9), %rcx
movl (%rdx,%r14,4), %esi
incq %rcx
cmpq %rsi, %rcx
jb 0x1445c8
movl (%rdx,%r15,4), %edx
cmpq %rdx, %rcx
jb 0x1445c8
addq %rax, %rdi
movq %r10, %rsi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0x143e3e
movq 0x20(%rsp), %r10
movq 0x28(%rsp), %r9
cmpq $-0x1, %rax
je 0x1445c8
movq (%r10), %rcx
cmpq %r14, %rcx
jbe 0x14439a
movq 0x10(%r10), %rsi
leaq (%r14,%r14,2), %rdi
shlq $0x4, %rdi
movq (%rsi,%rdi), %rdx
testq %rdx, %rdx
je 0x14439a
movq 0x10(%rsi,%rdi), %r13
cmpb $0x0, 0x18(%r13)
js 0x144391
movl 0x8(%r13), %esi
cmpq %rsi, %r15
je 0x14439d
addq $0x28, %r13
decq %rdx
jne 0x144381
xorl %r13d, %r13d
cmpq %r15, %rcx
jbe 0x1443d5
movq 0x10(%r10), %rdx
leaq (%r15,%r15,2), %rsi
shlq $0x4, %rsi
movq (%rdx,%rsi), %rcx
testq %rcx, %rcx
je 0x1443d5
movq 0x10(%rdx,%rsi), %r15
cmpb $0x0, 0x18(%r15)
js 0x1443cc
movl 0x8(%r15), %edx
cmpq %rdx, %r14
je 0x1443d8
addq $0x28, %r15
decq %rcx
jne 0x1443bc
xorl %r15d, %r15d
testq %r13, %r13
je 0x1445c8
testq %r15, %r15
je 0x1445c8
fld1
movq 0x30(%rsp), %rcx
testq %rcx, %rcx
je 0x1445b0
fstp %st(0)
cmpq %rax, 0x18(%rcx)
jbe 0x144450
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x1444ec
movq (%rcx), %rcx
movq %rdx, %rsi
negq %rsi
addq $0x20, %rcx
movb $0x1, %r8b
movl $0x1, %edi
cmpq %rax, -0x18(%rcx)
jbe 0x144430
cmpq %rax, -0x20(%rcx)
jbe 0x144497
cmpq %rdx, %rdi
setb %r8b
leaq (%rsi,%rdi), %r9
incq %r9
incq %rdi
addq $0x28, %rcx
cmpq $0x1, %r9
jne 0x144424
jmp 0x1444ec
movq 0x18(%rsp), %rdx
fldt 0x80(%rdx)
movq %rax, 0x68(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0x68(%rsp)
leaq 0xeab75(%rip), %rax     # 0x22efe8
fadds (%rax,%rcx,4)
fldt 0xa0(%rdx)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%rdx)
faddp %st, %st(1)
fstpl 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
jmp 0x14452e
testb $0x1, %r8b
je 0x1444ec
movq (%rcx), %rax
movq %rax, %xmm1
movq 0xe0d93(%rip), %xmm2    # 0x225240
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xe0d97(%rip), %xmm3    # 0x225250
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addq -0x8(%rcx), %rax
addsd %xmm1, %xmm0
movq %rax, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
jmp 0x14452e
movq 0x18(%rsp), %rdx
fldt 0x80(%rdx)
movq %rax, 0x58(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0x58(%rsp)
leaq 0xeaad9(%rip), %rax     # 0x22efe8
fadds (%rax,%rcx,4)
fldt 0xa0(%rdx)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%rdx)
faddp %st, %st(1)
fstpl 0x50(%rsp)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
fldl 0x48(%rsp)
fldz
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xeaa68(%rip)           # 0x22efb0
fldt 0x8c(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xeaa93(%rip)           # 0x22eff0
fld1
fdivp %st, %st(1)
fldt 0x80(%rsp)
faddp %st, %st(1)
fstpt (%rsp)
callq 0x20b0
fmuls 0xeaab0(%rip)           # 0x22f028
fldt 0x74(%rsp)
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
fldl 0xeaa76(%rip)           # 0x22f000
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
fstpl 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
fldl 0x38(%rsp)
movq 0x28(%rsp), %r9
movq 0x20(%rsp), %r10
fld %st(0)
faddl (%r13)
fstpl (%r13)
incq 0x20(%r13)
faddl (%r15)
fstpl (%r15)
incq 0x20(%r15)
incq %rbx
cmpq (%r12), %rbx
jb 0x1442e6
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq