// File: /workspace/github_cpp_makefile_star2_O2/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 0x10(%rdi), %rax
movl %ecx, %r8d
imulq $0x48, %r8, %r9
leaq (%rax,%r9), %r11
movl 0x18(%rax,%r9), %r10d
xorpd %xmm1, %xmm1
movq %r10, -0x20(%rsp)
testq %r10, %r10
je 0x10e1a6
movl 0x24(%r11), %r8d
cmpl $0x1, %r8d
je 0x10e197
cmpl $-0x1, %r8d
jne 0x10e1a6
cvtsi2sd %r8d, %xmm0
mulsd 0x30(%r11), %xmm0
addsd %xmm0, %xmm1
movl 0x1c(%r11), %r8d
movq %r8, -0x18(%rsp)
testq %r8, %r8
je 0x10e1d3
movl 0x28(%r11), %r8d
cmpl $0x1, %r8d
je 0x10e1c4
cmpl $-0x1, %r8d
jne 0x10e1d3
cvtsi2sd %r8d, %xmm0
mulsd 0x38(%r11), %xmm0
addsd %xmm0, %xmm1
movq -0x20(%rsp), %r8
testq %r8, %r8
movsd 0x40(%rax,%r9), %xmm0
movq 0x10(%rax,%r9), %rbx
movq %rbx, -0x10(%rsp)
cmoveq %r8, %rbx
movq %r9, -0x8(%rsp)
movl 0x24(%rax,%r9), %ebp
xorpd %xmm2, %xmm2
xorl %r14d, %r14d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq -0x20(%rsp), %r14
je 0x10e297
movq 0x10(%rdx), %r8
movl (%rbx,%r14,4), %r9d
imulq $0x30, %r9, %r9
leaq (%r8,%r9), %r12
movq (%r8,%r9), %r13
xorl %r11d, %r11d
movl %r11d, %r11d
cmpq %r11, %r13
jbe 0x10e28f
movq 0x10(%r12), %r9
imulq $0x28, %r11, %r8
cmpb $0x0, 0x18(%r9,%r8)
js 0x10e28a
addq %r8, %r9
movl 0x8(%r9), %r8d
movq 0x18(%rdi), %r10
movl (%r10,%r8,4), %r10d
cmpq %r15, %r10
je 0x10e28a
movl %r10d, %r8d
shrl %r8d
cmpl %ecx, %r8d
je 0x10e28a
cmpb $0x0, (%rsi,%r8)
je 0x10e28a
andl $0x1, %r10d
imulq $0x48, %r8, %r8
addq %rax, %r8
movl 0x24(%r8,%r10,4), %r8d
imull %ebp, %r8d
cvtsi2sd %r8d, %xmm3
mulsd (%r9), %xmm3
addsd %xmm3, %xmm2
incl %r11d
jmp 0x10e229
incq %r14
jmp 0x10e207
movq -0x18(%rsp), %r8
testq %r8, %r8
movq -0x20(%rsp), %r9
movq -0x10(%rsp), %r10
leaq (%r10,%r9,4), %r10
cmoveq %r8, %r10
movq -0x8(%rsp), %r8
movl 0x28(%rax,%r8), %r9d
xorpd %xmm3, %xmm3
xorl %r11d, %r11d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq -0x18(%rsp), %r11
je 0x10e355
movq 0x10(%rdx), %r8
movl (%r10,%r11,4), %r14d
imulq $0x30, %r14, %r15
leaq (%r8,%r15), %r14
movq (%r8,%r15), %r15
xorl %r12d, %r12d
movl %r12d, %r12d
cmpq %r12, %r15
jbe 0x10e34d
movq 0x10(%r14), %r13
imulq $0x28, %r12, %r8
cmpb $0x0, 0x18(%r13,%r8)
js 0x10e348
addq %r8, %r13
movl 0x8(%r13), %r8d
movq 0x18(%rdi), %rbp
movl (%rbp,%r8,4), %r8d
cmpq %rbx, %r8
je 0x10e348
movl %r8d, %ebp
shrl %ebp
cmpl %ecx, %ebp
je 0x10e348
cmpb $0x0, (%rsi,%rbp)
je 0x10e348
andl $0x1, %r8d
imulq $0x48, %rbp, %rbp
addq %rax, %rbp
movl 0x24(%rbp,%r8,4), %r8d
imull %r9d, %r8d
cvtsi2sd %r8d, %xmm4
mulsd (%r13), %xmm4
addsd %xmm4, %xmm3
incl %r12d
jmp 0x10e2e9
incq %r11
jmp 0x10e2c7
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
addsd %xmm2, %xmm2
subsd %xmm2, %xmm0
addsd %xmm3, %xmm3
subsd %xmm3, %xmm0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq