// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movq %r8, 0x38(%rsp)
movq %rcx, %r8
movq %rdx, %r15
movl $0x40, %ebp
movq %rdi, 0x30(%rsp)
subq 0x18(%rdi), %rbp
movq (%rdx), %rax
testq %rax, %rax
je 0x14a912
movq 0x10(%r15), %rcx
xorl %edx, %edx
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
movq (%rcx,%rdi), %r9
testq %r9, %r9
je 0x14a90a
addq %rcx, %rdi
movq 0x10(%rdi), %rdi
cmpb $0x0, 0x18(%rdi)
js 0x14a901
movq $0x0, (%rdi)
addq $0x28, %rdi
decq %r9
jne 0x14a8f4
incq %rdx
cmpq %rax, %rdx
jne 0x14a8dc
movq (%rsi), %r12
testq %r12, %r12
je 0x14abf5
xorl %r14d, %r14d
fld1
flds 0xf094b(%rip)           # 0x23b274
fstpt 0x9c(%rsp)
fchs
fstpt 0x90(%rsp)
fldl 0xf0909(%rip)           # 0x23b248
fstpt 0x84(%rsp)
movq %r8, 0x18(%rsp)
movq %r15, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x10(%rsi), %rdi
movq %r14, %rax
shlq $0x5, %rax
movq (%rdi,%rax), %r13
addq %r13, %r13
movl %ebp, %ecx
shrq %cl, %r13
movq 0x8(%rdi,%rax), %rbx
addq %rbx, %rbx
shrq %cl, %rbx
cmpq %rbx, %r13
je 0x14ab95
movq (%r8), %rdx
movq 0x80(%r8), %rcx
movl (%rdx,%r13,4), %r9d
incq %rcx
cmpq %r9, %rcx
jb 0x14ab95
movl (%rdx,%rbx,4), %edx
cmpq %rdx, %rcx
jb 0x14ab95
addq %rax, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0x14a518
cmpq $-0x1, %rax
je 0x14aa95
movq %rax, 0x40(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x144201
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rbx
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x144201
testq %rbx, %rbx
je 0x14aa9c
movq %rax, %r13
testq %rax, %rax
movq 0x20(%rsp), %rsi
je 0x14ab8b
fld1
cmpq $0x0, 0x38(%rsp)
je 0x14ab75
fstp %st(0)
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rdx
cmpq %rdx, 0x18(%rax)
jbe 0x14aab0
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0x14aa51
movq (%rax), %rax
addq $0x20, %rax
cmpq %rdx, -0x18(%rax)
jbe 0x14aa48
cmpq %rdx, -0x20(%rax)
jbe 0x14aba3
addq $0x28, %rax
decq %rcx
jne 0x14aa38
movq 0x30(%rsp), %rcx
fldt 0x80(%rcx)
movq %rdx, 0x68(%rsp)
xorl %eax, %eax
testq %rdx, %rdx
sets %al
fildll 0x68(%rsp)
leaq 0xf07c4(%rip), %rdx     # 0x23b238
fadds (%rdx,%rax,4)
fldt 0xa0(%rcx)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%rcx)
faddp %st, %st(1)
fstpl 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
jmp 0x14aaf2
movq 0x18(%rsp), %r8
jmp 0x14aaa6
movq 0x18(%rsp), %r8
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rsi
jmp 0x14ab95
movq 0x30(%rsp), %rcx
fldt 0x80(%rcx)
movq %rdx, 0x78(%rsp)
xorl %eax, %eax
testq %rdx, %rdx
sets %al
fildll 0x78(%rsp)
leaq 0xf0765(%rip), %rdx     # 0x23b238
fadds (%rdx,%rax,4)
fldt 0xa0(%rcx)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%rcx)
faddp %st, %st(1)
fstpl 0x70(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
fldl 0x58(%rsp)
fldz
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xf06b4(%rip)           # 0x23b1c0
fldt 0x9c(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xf071f(%rip)           # 0x23b240
fld1
fdivp %st, %st(1)
fldt 0x90(%rsp)
faddp %st, %st(1)
fstpt (%rsp)
callq 0x20b0
fmuls 0xf073c(%rip)           # 0x23b278
fldt 0x84(%rsp)
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
fldl 0xf06ff(%rip)           # 0x23b250
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
fstpl 0x50(%rsp)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
fldl 0x48(%rsp)
movq 0x20(%rsp), %rsi
movq (%rsi), %r12
fld %st(0)
faddl (%rbx)
fstpl (%rbx)
incq 0x20(%rbx)
faddl (%r13)
fstpl (%r13)
incq 0x20(%r13)
movq 0x18(%rsp), %r8
movq 0x28(%rsp), %r15
incq %r14
cmpq %r12, %r14
jb 0x14a955
jmp 0x14abf5
movq (%rax), %rcx
movq %rcx, %xmm1
movq 0xe66cd(%rip), %xmm2    # 0x231280
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xe66d1(%rip), %xmm3    # 0x231290
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addq -0x8(%rax), %rcx
addsd %xmm1, %xmm0
movq %rcx, %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 0x14aaf2
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq