// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: get_new_weight(G_partition*, unsigned char*, hc_links*, unsigned int)
double get_new_weight(G_partition* g_p, uint8_t* flag, hc_links* link, uint32_t gid)
{
    double total_weight = 0, weight;
    int status, o_d;
    uint32_t *h0, h0_n, *h1, h1_n, *h, h_n, j, k, uID;

    if(g_p->a[gid].h[0] > 0 && (g_p->a[gid].status[0] == 1 || g_p->a[gid].status[0] == -1))
    {
        total_weight += (g_p->a[gid].weight[0] * g_p->a[gid].status[0]);
    }

    if(g_p->a[gid].h[1] > 0 && (g_p->a[gid].status[1] == 1 || g_p->a[gid].status[1] == -1))
    {
        total_weight += (g_p->a[gid].weight[1] * g_p->a[gid].status[1]);
    }
    total_weight += g_p->a[gid].weight_convex*2;



    get_phased_block(g_p, NULL, gid, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);

    h = h0; h_n = h0_n; status = g_p->a[gid].status[0];
    for (j = 0, weight = 0; j < h_n; j++)
    {
        for (k = 0; k < link->a.a[h[j]].e.n; k++)
        {
            if(link->a.a[h[j]].e.a[k].del) continue;
            uID = link->a.a[h[j]].e.a[k].uID;
            if(g_p->index[uID] == (uint32_t)-1) continue;
            if(flag[g_p->index[uID]>>1] == 0) continue;
            if((g_p->index[uID]>>1) == gid) continue;
            o_d = g_p->a[g_p->index[uID]>>1].status[g_p->index[uID]&1];
            weight += (status*o_d*link->a.a[h[j]].e.a[k].weight);
        }
    }
    total_weight -= (2*weight);




    h = h1; h_n = h1_n; status = g_p->a[gid].status[1];
    for (j = 0, weight = 0; j < h_n; j++)
    {
        for (k = 0; k < link->a.a[h[j]].e.n; k++)
        {
            if(link->a.a[h[j]].e.a[k].del) continue;
            uID = link->a.a[h[j]].e.a[k].uID;
            if(g_p->index[uID] == (uint32_t)-1) continue;
            if(flag[g_p->index[uID]>>1] == 0) continue;
            if((g_p->index[uID]>>1) == gid) continue;
            o_d = g_p->a[g_p->index[uID]>>1].status[g_p->index[uID]&1];
            weight += (status*o_d*link->a.a[h[j]].e.a[k].weight);
        }
    }
    total_weight -= (2*weight);



    return total_weight;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, -0x20(%rsp)
movq 0x10(%rdi), %rax
movl %ecx, %edx
leaq (%rdx,%rdx,8), %r10
leaq (%rax,%r10,8), %rdx
movl 0x18(%rdx), %r9d
xorpd %xmm1, %xmm1
testq %r9, %r9
je 0x14ecb9
movl 0x24(%rdx), %r8d
cmpl $0x1, %r8d
je 0x14ecab
cmpl $-0x1, %r8d
jne 0x14ecb9
cvtsi2sd %r8d, %xmm0
mulsd 0x30(%rdx), %xmm0
addsd %xmm0, %xmm1
cmpl $0x0, 0x1c(%rdx)
je 0x14ece0
movl 0x28(%rdx), %r8d
cmpl $0x1, %r8d
je 0x14eccf
cmpl $-0x1, %r8d
jne 0x14ece0
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
mulsd 0x38(%rdx), %xmm0
addsd %xmm0, %xmm1
movl 0x18(%rax,%r10,8), %r11d
movl 0x1c(%rax,%r10,8), %r8d
shlq $0x2, %r9
addq 0x10(%rdx), %r9
testq %r8, %r8
movq %r8, -0x10(%rsp)
cmoveq %r8, %r9
movq %r9, -0x8(%rsp)
movq %r11, %rbx
testq %r11, %r11
je 0x14ed10
movq 0x10(%rax,%r10,8), %rbx
movq %r10, -0x18(%rsp)
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
je 0x14edc9
movq -0x18(%rsp), %rdx
movl 0x24(%rax,%rdx,8), %ebp
movq -0x20(%rsp), %rdx
movq 0x10(%rdx), %r14
xorl %r15d, %r15d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl (%rbx,%r15,4), %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq (%r14,%rdx), %r13
testq %r13, %r13
je 0x14edbd
addq %r14, %rdx
movq 0x10(%rdx), %r10
movl $0x1, %edx
cmpb $0x0, 0x18(%r10)
js 0x14edaf
movl 0x8(%r10), %r8d
movq 0x18(%rdi), %r9
movl (%r9,%r8,4), %r9d
cmpq %r12, %r9
je 0x14edaf
movl %r9d, %r8d
shrl %r8d
cmpl %ecx, %r8d
je 0x14edaf
cmpb $0x0, (%rsi,%r8)
je 0x14edaf
andl $0x1, %r9d
leaq (%r8,%r8,8), %r8
leaq (%rax,%r8,8), %r8
movl 0x24(%r8,%r9,4), %r8d
imull %ebp, %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
mulsd (%r10), %xmm0
addsd %xmm0, %xmm3
movl %edx, %r8d
addq $0x28, %r10
incl %edx
cmpq %r8, %r13
ja 0x14ed5f
incq %r15
cmpq %r11, %r15
jne 0x14ed3e
movq -0x18(%rsp), %rdx
movsd 0x40(%rax,%rdx,8), %xmm0
movq -0x10(%rsp), %r13
testq %r13, %r13
movq -0x8(%rsp), %r12
je 0x14ee8c
movl 0x28(%rax,%rdx,8), %r10d
movq -0x20(%rsp), %rdx
movq 0x10(%rdx), %rdx
xorpd %xmm2, %xmm2
xorl %r11d, %r11d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl (%r12,%r11,4), %r8d
leaq (%r8,%r8,2), %r8
shlq $0x4, %r8
movq (%rdx,%r8), %r14
testq %r14, %r14
je 0x14ee80
addq %rdx, %r8
movq 0x10(%r8), %r15
movl $0x1, %ebp
cmpb $0x0, 0x18(%r15)
js 0x14ee72
movl 0x8(%r15), %r8d
movq 0x18(%rdi), %r9
movl (%r9,%r8,4), %r8d
cmpq %rbx, %r8
je 0x14ee72
movl %r8d, %r9d
shrl %r9d
cmpl %ecx, %r9d
je 0x14ee72
cmpb $0x0, (%rsi,%r9)
je 0x14ee72
andl $0x1, %r8d
leaq (%r9,%r9,8), %r9
leaq (%rax,%r9,8), %r9
movl 0x24(%r9,%r8,4), %r8d
imull %r10d, %r8d
xorps %xmm4, %xmm4
cvtsi2sd %r8d, %xmm4
mulsd (%r15), %xmm4
addsd %xmm4, %xmm2
movl %ebp, %r8d
addq $0x28, %r15
incl %ebp
cmpq %r8, %r14
ja 0x14ee22
incq %r11
cmpq %r13, %r11
jne 0x14ee01
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
addsd %xmm3, %xmm3
subsd %xmm3, %xmm0
addsd %xmm2, %xmm2
subsd %xmm2, %xmm0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq