// File: chhylp123[P]hifiasm/hic.cpp
// Function: flip_unitig(G_partition*, hc_links*, bubble_type*, unsigned int)
void flip_unitig(G_partition* g_p, hc_links* link, bubble_type* bub, uint32_t id)
{
    if(g_p->a[id].h[0] > 0 && g_p->a[id].status[0] != 1 && g_p->a[id].status[0] != -1) return;
    if(g_p->a[id].h[1] > 0 && g_p->a[id].status[1] != 1 && g_p->a[id].status[1] != -1) return;
    uint32_t k, j, m, *h0, h0_n, *h1, h1_n, uID, *h = NULL, h_n;
    int status;
    double weight;
    get_phased_block(g_p, NULL, id, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
    // fprintf(stderr, "h0_n: %u, h1_n: %u\n", h0_n, h1_n);
    if(h0_n > 0)
    {

        status = g_p->a[id].status[0];
        // fprintf(stderr, "+status: %d\n", status);
        h = h0; h_n = h0_n;
        for (j = 0; j < h_n; j++)
        {
            // fprintf(stderr, "+j: %u, h_n: %u\n", j, h_n);
            for (k = 0; k < link->a.a[h[j]].e.n; k++)
            {
                // fprintf(stderr, "+k: %u, e_n: %u\n", k, (uint32_t)link->a.a[h[j]].e.n);
                if(link->a.a[h[j]].e.a[k].del) continue;
                for (m = 0; m < h_n; m++)
                {
                    if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
                }
                // fprintf(stderr, "+m: %u, h_n: %u\n", m, h_n);
                if(m < h_n) continue;

                uID = link->a.a[h[j]].e.a[k].uID;

                weight = link->a.a[h[j]].e.a[k].weight;

                if(g_p->index[uID] == (uint32_t)-1) continue;
                

                g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1] -= (2*status*weight);

                
            }
        }
        g_p->a[id].status[0] *= -1;
    }

    // fprintf(stderr, "hehehe\n");
    if(h1_n > 0)
    {
        status = g_p->a[id].status[1];
        // fprintf(stderr, "-status: %d\n", status);
        h = h1; h_n = h1_n;
        for (j = 0; j < h_n; j++)
        {
            // fprintf(stderr, "-j: %u, h_n: %u\n", j, h_n);
            for (k = 0; k < link->a.a[h[j]].e.n; k++)
            {
                // fprintf(stderr, "-k: %u, e_n: %u\n", k, (uint32_t)link->a.a[h[j]].e.n);
                if(link->a.a[h[j]].e.a[k].del) continue;
                for (m = 0; m < h_n; m++)
                {
                    if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
                }
                // fprintf(stderr, "-m: %u, h_n: %u\n", m, h_n);
                if(m < h_n) continue;

                uID = link->a.a[h[j]].e.a[k].uID;
                // fprintf(stderr, "-uID: %u\n", uID);

                weight = link->a.a[h[j]].e.a[k].weight;

                if(g_p->index[uID] == (uint32_t)-1) continue;


                g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1] -= (2*status*weight);

            }
        }
        g_p->a[id].status[1] *= -1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%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 0x1f0397
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x24(%rax)
je 0x1f0397
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x24(%rax)
je 0x1f0397
jmp 0x1f0869
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x1f03e4
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x28(%rax)
je 0x1f03e4
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x28(%rax)
je 0x1f03e4
jmp 0x1f0869
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x30(%rbp), %r9
leaq -0x34(%rbp), %r11
leaq -0x40(%rbp), %r10
leaq -0x44(%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
cmpl $0x0, -0x34(%rbp)
jbe 0x1f064f
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, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1f0636
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x50(%rbp), %rdx
movl -0x24(%rbp), %esi
movl (%rdx,%rsi,4), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1f0626
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x24(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1f04da
jmp 0x1f0618
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1f052e
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x50(%rbp), %rdx
movl -0x24(%rbp), %esi
movl (%rdx,%rsi,4), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x20(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0x1f0521
jmp 0x1f052e
jmp 0x1f0523
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1f04e1
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1f053b
jmp 0x1f0618
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x24(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x24(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x48(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x1f05ab
jmp 0x1f0618
movl -0x58(%rbp), %eax
shll %eax
cvtsi2sd %eax, %xmm0
movsd -0x60(%rbp), %xmm2
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x48(%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 -0x48(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
movsd 0x30(%rax,%rcx,8), %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1f047f
jmp 0x1f0628
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1f046c
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
imull $-0x1, 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
cmpl $0x0, -0x44(%rbp)
jbe 0x1f0869
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, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1f0850
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x50(%rbp), %rdx
movl -0x24(%rbp), %esi
movl (%rdx,%rsi,4), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1f0840
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x24(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1f06f4
jmp 0x1f0832
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1f0748
movq -0x50(%rbp), %rax
movl -0x28(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x50(%rbp), %rdx
movl -0x24(%rbp), %esi
movl (%rdx,%rsi,4), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x20(%rbp), %edx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0x1f073b
jmp 0x1f0748
jmp 0x1f073d
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1f06fb
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1f0755
jmp 0x1f0832
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x24(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movl -0x24(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x48(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x1f07c5
jmp 0x1f0832
movl -0x58(%rbp), %eax
shll %eax
cvtsi2sd %eax, %xmm0
movsd -0x60(%rbp), %xmm2
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x48(%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 -0x48(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
movsd 0x30(%rax,%rcx,8), %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1f0699
jmp 0x1f0842
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1f0686
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
imull $-0x1, 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)