// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x18(%rax)
jbe 0x1f0dba
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x24(%rax)
je 0x1f0d7a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x24(%rax)
jne 0x1f0dba
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd 0x30(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x24(%rax), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x1f0e42
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x28(%rax)
je 0x1f0e02
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x28(%rax)
jne 0x1f0e42
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd 0x38(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x28(%rax), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd 0x40(%rax), %xmm0
movsd -0x28(%rbp), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x40(%rbp), %r9
leaq -0x44(%rbp), %r11
leaq -0x50(%rbp), %r10
leaq -0x54(%rbp), %rax
movq %r8, %rsi
movq %r8, %rcx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x214690
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x1f1079
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x60(%rbp), %rdx
movl -0x68(%rbp), %esi
movl (%rdx,%rsi,4), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1f1069
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movl -0x68(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1f0f57
jmp 0x1f105b
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movl -0x68(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x70(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x1f0f9a
jmp 0x1f105b
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x70(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1f0fbe
jmp 0x1f105b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x70(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
cmpl -0x1c(%rbp), %eax
jne 0x1f0fd8
jmp 0x1f105b
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x70(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x70(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
movl 0x24(%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
imull -0x38(%rbp), %eax
cvtsi2sd %eax, %xmm0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movl -0x68(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1f0efc
jmp 0x1f106b
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1f0ee9
movsd -0x30(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x1f1255
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x60(%rbp), %rdx
movl -0x68(%rbp), %esi
movl (%rdx,%rsi,4), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1f1245
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movl -0x68(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1f1133
jmp 0x1f1237
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movl -0x68(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x70(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x1f1176
jmp 0x1f1237
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x70(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1f119a
jmp 0x1f1237
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x70(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
cmpl -0x1c(%rbp), %eax
jne 0x1f11b4
jmp 0x1f1237
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x70(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x70(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
movl 0x24(%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
imull -0x38(%rbp), %eax
cvtsi2sd %eax, %xmm0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movl -0x68(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1f10d8
jmp 0x1f1247
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1f10c5
movsd -0x30(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)