// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rcx
movl $0x40, %eax
subq 0x18(%rcx), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1dc196
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x38(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1dc183
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x30(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1dc152
jmp 0x1dc175
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x30(%rbp), %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1dc111
jmp 0x1dc185
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1dc0f8
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1dc353
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0x40(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x40(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x1dc207
jmp 0x1dc342
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1dc22e
jmp 0x1dc342
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1dc255
jmp 0x1dc342
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movq -0x8(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1db730
movq %rax, -0x58(%rbp)
cmpq $-0x1, -0x58(%rbp)
jne 0x1dc289
jmp 0x1dc342
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1d09c0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1d09c0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x1dc2c9
cmpq $0x0, -0x68(%rbp)
jne 0x1dc2cb
jmp 0x1dc342
fld1
fstpt -0x80(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1dc2f9
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x2148a0
movsd %xmm0, -0x88(%rbp)
fldl -0x88(%rbp)
fstpt -0x80(%rbp)
fldt -0x80(%rbp)
movq -0x60(%rbp), %rax
fldl (%rax)
faddp %st, %st(1)
fstpl (%rax)
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rcx
incq %rcx
movq %rcx, 0x20(%rax)
fldt -0x80(%rbp)
movq -0x68(%rbp), %rax
fldl (%rax)
faddp %st, %st(1)
fstpl -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1dc19e
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)