// File: chhylp123[P]hifiasm/hic.cpp
// Function: get_weightest_node(kv_u_trans_t*, bubble_type*, ma_ug_t*, signed char*, unsigned char*)
uint32_t get_weightest_node(kv_u_trans_t *ta, bubble_type* bub, ma_ug_t* ug, int8_t *s, uint8_t *vis)
{
    double w_a, w_n, max_w_a, max_w_n;
    uint32_t i, occ, k, m, v, *a = NULL, a_n, e_n, max_w_a_i, max_w_n_i;
    u_trans_t *e = NULL;
    max_w_a = max_w_n = -1; max_w_a_i = max_w_n_i = (uint32_t)-1;
    for (i = 0; i < bub->f_bub; i++)
    {
        get_bubbles(bub, i, NULL, NULL, &a, &a_n, NULL);
        if(vis[i]) continue;
        for (k = 0, w_a = w_n = 0; k < a_n; k++)
        {
            v = a[k]>>1;
            if(s[v] != 0) break; 
            e = u_trans_a(*ta, v);
            e_n = u_trans_n(*ta, v);
            for (m = 0; m < e_n; m++)
            {
                if(s[e[m].tn] != 0)
                {
                    w_a += (e[m].nw>=0?e[m].nw:-e[m].nw);
                }
                else
                {
                    w_n += (e[m].nw>=0?e[m].nw:-e[m].nw);
                }
            }
        }

        if(k >= a_n && a_n > 0)//unset whole bubble
        {
            if(w_a > max_w_a)
            {
                max_w_a_i = i<<1;
                max_w_a = w_a;
            }

            if(w_n > max_w_n)
            {
                max_w_n_i = i<<1;
                max_w_n = w_n;
            }
        }
        else
        {
            for (k = occ = 0; k < a_n; k++)
            {
                v = a[k]>>1;
                if(s[v] != 0)
                {
                    occ++;
                    continue;
                } 
                
                e = u_trans_a(*ta, v);
                e_n = u_trans_n(*ta, v);
                for (m = 0, w_a = w_n = 0; m < e_n; m++)
                {
                    if(s[e[m].tn] != 0)
                    {
                        w_a += (e[m].nw>=0?e[m].nw:-e[m].nw);
                    }
                    else
                    {
                        w_n += (e[m].nw>=0?e[m].nw:-e[m].nw);
                    }
                }

                if(w_a > max_w_a)
                {
                    max_w_a_i = (v<<1)+1;
                    max_w_a = w_a;
                }

                if(w_n > max_w_n)
                {
                    max_w_n_i = (v<<1)+1;
                    max_w_n = w_n;
                }
            }

            if(occ == a_n) vis[i] = 1;
        }
    }

    for (i = 0; i < ug->g->n_seq; i++)
    {
        if(s[i] != 0 || (IF_BUB(i, *bub))) continue;
        v = i;
        e = u_trans_a(*ta, v);
        e_n = u_trans_n(*ta, v);
        for (m = 0, w_a = w_n = 0; m < e_n; m++)
        {
            if(s[e[m].tn] != 0)
            {
                w_a += (e[m].nw>=0?e[m].nw:-e[m].nw);
            }
            else
            {
                w_n += (e[m].nw>=0?e[m].nw:-e[m].nw);
            }
        }

        if(w_a > max_w_a)
        {
            max_w_a_i = (i<<1)+1;
            max_w_a = w_a;
        }

        if(w_n > max_w_n)
        {
            max_w_n_i = (i<<1)+1;
            max_w_n = w_n;
        }
    }
    
    if(max_w_a_i != (uint32_t)-1) return max_w_a_i;
    return max_w_n_i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x88(%rbp)
movsd 0x18b0ce(%rip), %xmm0   # 0x382278
movsd %xmm0, -0x50(%rbp)
movsd 0x18b0c1(%rip), %xmm0   # 0x382278
movsd %xmm0, -0x48(%rbp)
movl $0xffffffff, -0x80(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x7c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x80(%rcx), %rax
jae 0x1f76b8
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x70(%rbp), %r8
leaq -0x74(%rbp), %r9
movq %rcx, %rdx
movq $0x0, (%rsp)
callq 0x1c4b20
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1f721c
jmp 0x1f76aa
movl $0x0, -0x5c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x1f7407
movq -0x70(%rbp), %rax
movl -0x5c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1f7263
jmp 0x1f7407
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x64(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x78(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x78(%rbp), %eax
jae 0x1f73f7
movq -0x28(%rbp), %rax
movq -0x88(%rbp), %rcx
movl -0x60(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1f7361
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f7315
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
jmp 0x1f734a
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1f73e7
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f73a0
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
jmp 0x1f73d5
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x1f73e9
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f72a5
jmp 0x1f73f9
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1f7233
movl -0x5c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jb 0x1f7456
cmpl $0x0, -0x74(%rbp)
jbe 0x1f7456
movsd -0x38(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0x1f7433
movl -0x54(%rbp), %eax
shll %eax
movl %eax, -0x7c(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
ucomisd -0x50(%rbp), %xmm0
jbe 0x1f7451
movl -0x54(%rbp), %eax
shll %eax
movl %eax, -0x80(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x1f76a8
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x1f7693
movq -0x70(%rbp), %rax
movl -0x5c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rax
movl -0x64(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1f749d
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1f7685
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x64(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x78(%rbp)
movl $0x0, -0x60(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x78(%rbp), %eax
jae 0x1f7641
movq -0x28(%rbp), %rax
movq -0x88(%rbp), %rcx
movl -0x60(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1f75ab
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f755f
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
jmp 0x1f7594
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1f7631
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f75ea
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x1f761f
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x1f7633
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f74ef
movsd -0x38(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0x1f7662
movl -0x64(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
ucomisd -0x50(%rbp), %xmm0
jbe 0x1f7683
movl -0x64(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x1f7685
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1f7464
movl -0x58(%rbp), %eax
cmpl -0x74(%rbp), %eax
jne 0x1f76a6
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
movb $0x1, (%rax,%rcx)
jmp 0x1f76a8
jmp 0x1f76aa
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1f71d1
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x1f790d
movq -0x28(%rbp), %rax
movl -0x54(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1f770c
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x54(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1f7711
jmp 0x1f78ff
movl -0x54(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x64(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x78(%rbp)
movl $0x0, -0x60(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x78(%rbp), %eax
jae 0x1f78bb
movq -0x28(%rbp), %rax
movq -0x88(%rbp), %rcx
movl -0x60(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1f7825
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f77d9
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
jmp 0x1f780e
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1f78ab
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f7864
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
jmp 0x1f7899
movq -0x88(%rbp), %rax
movl -0x60(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x1f78ad
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f7769
movsd -0x38(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0x1f78dc
movl -0x54(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
ucomisd -0x50(%rbp), %xmm0
jbe 0x1f78fd
movl -0x54(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x1f78ff
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1f76bf
cmpl $-0x1, -0x7c(%rbp)
je 0x1f791b
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1f7921
movl -0x80(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)