// File: chhylp123[P]hifiasm/hic.cpp
// Function: calculate_chain_weight(ma_utg_t*, bubble_type*, ma_ug_t*, chain_w_type*)
uint64_t calculate_chain_weight(ma_utg_t *u, bubble_type* bub, ma_ug_t *unitig_ug, chain_w_type* x)
{
    x->b_occ = x->g_occ = 0;
    uint32_t i, j, *a, n;
    uint64_t occ, occ_n, thres;
    for (i = occ = occ_n = 0; i < u->n; i++)
    {
        if(bub->b_g->seq[u->a[i]>>33].c != HAP_LABLE)
        {
            get_bubbles(bub, u->a[i]>>33, NULL, NULL, &a, &n, NULL);
            for (j = 0; j < n; j++)
            {
                occ += unitig_ug->u.a[a[j]>>1].n;
            }
            occ_n++;
        }
    }

    thres = (uint64_t)-1;
    if(occ_n > 0) thres = (occ*6)/occ_n;

    for (i = 0; i < u->n; i++)
    {
        occ = 0;
        get_bubbles(bub, u->a[i]>>33, NULL, NULL, &a, &n, NULL);
        for (j = 0; j < n; j++)
        {
            occ += unitig_ug->u.a[a[j]>>1].n;
        }

        if(bub->b_g->seq[u->a[i]>>33].c != HAP_LABLE || occ < thres)
        {
            x->g_occ += occ;
        }
        else
        {
            x->b_occ += occ;
        }
    }

    return thres;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x1df957
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x2, %eax
je 0x1df947
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
shrq $0x21, %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x30(%rbp), %r8
leaq -0x34(%rbp), %r9
movq %rcx, %rdx
movq $0x0, (%rsp)
callq 0x1c4b20
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x1df93b
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movl -0x28(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1df900
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1df949
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1df886
movq $-0x1, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
jbe 0x1df977
imulq $0x6, -0x40(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x48(%rbp)
movq %rax, -0x50(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x1dfa71
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
shrq $0x21, %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x30(%rbp), %r8
leaq -0x34(%rbp), %r9
movq %rcx, %rdx
movq $0x0, (%rsp)
callq 0x1c4b20
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x1dfa0b
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movl -0x28(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1df9d0
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x21, %rcx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x2, %eax
jne 0x1dfa41
movq -0x40(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x1dfa51
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x1dfa61
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x1dfa63
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1df97e
movq -0x50(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)