// File: chhylp123[P]hifiasm/hic.cpp
// Function: flip_unitig_debug(G_partition*, hc_links*, bubble_type*, unsigned int)
void flip_unitig_debug(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;

                if(id == 19675)
                {
                    fprintf(stderr, "+uID+: %u, e-weight: %f, g_p->index[uID]>>1: %u, status[0]: %d, pre_uID_weight: %f\n", 
                                             uID, weight, g_p->index[uID]>>1, status, g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
                }
                

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

                if(id == 19675)
                {
                    fprintf(stderr, "+uID+: %u, new_uID_weight: %f\n", uID, 
                                     g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
                }   
                
            }
        }
        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;

                if(id == 19675)
                {
                    fprintf(stderr, "-uID-: %u, e-weight: %f, g_p->index[uID]>>1: %u, status[1]: %d, pre_uID_weight: %f\n", 
                                             uID, weight, g_p->index[uID]>>1, status, g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
                }

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

                if(id == 19675)
                {
                    fprintf(stderr, "-uID-: %u, new_uID_weight: %f\n", uID, 
                                     g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
                }   
            }
        }
        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 0x1fe687
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x24(%rax)
je 0x1fe687
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x24(%rax)
je 0x1fe687
jmp 0x1fed15
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x1fe6d4
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x28(%rax)
je 0x1fe6d4
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x28(%rax)
je 0x1fe6d4
jmp 0x1fed15
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 0x1fea1d
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 0x1fea04
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 0x1fe9f4
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 0x1fe7ca
jmp 0x1fe9e6
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1fe81e
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 0x1fe811
jmp 0x1fe81e
jmp 0x1fe813
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1fe7d1
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1fe82b
jmp 0x1fe9e6
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 0x1fe89e
jmp 0x1fe9e6
cmpl $0x4cdb, -0x1c(%rbp)    # imm = 0x4CDB
jne 0x1fe919
movq 0x1c5732(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x48(%rbp), %edx
movsd -0x60(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
shrl %ecx
movl -0x58(%rbp), %r8d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x18(%rsi), %rsi
movl -0x48(%rbp), %r9d
movl (%rsi,%r9,4), %esi
shrl %esi
movl %esi, %esi
imulq $0x48, %rsi, %rsi
addq %rsi, %rax
movq -0x8(%rbp), %rsi
movq 0x18(%rsi), %rsi
movl -0x48(%rbp), %r9d
movl (%rsi,%r9,4), %esi
andl $0x1, %esi
movl %esi, %esi
movsd 0x30(%rax,%rsi,8), %xmm1
leaq 0x18e59a(%rip), %rsi    # 0x38ceac
movb $0x2, %al
callq 0x22a0
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)
cmpl $0x4cdb, -0x1c(%rbp)    # imm = 0x4CDB
jne 0x1fe9e4
movq 0x1c564a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x48(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x48(%rbp), %esi
movl (%rcx,%rsi,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), %esi
movl (%rcx,%rsi,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
movsd 0x30(%rax,%rcx,8), %xmm0
leaq 0x18e523(%rip), %rsi    # 0x38cf00
movb $0x1, %al
callq 0x22a0
jmp 0x1fe9e6
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1fe76f
jmp 0x1fe9f6
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1fe75c
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 0x1fed15
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 0x1fecfc
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 0x1fecec
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 0x1feac2
jmp 0x1fecde
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1feb16
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 0x1feb09
jmp 0x1feb16
jmp 0x1feb0b
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1feac9
movl -0x28(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x1feb23
jmp 0x1fecde
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 0x1feb96
jmp 0x1fecde
cmpl $0x4cdb, -0x1c(%rbp)    # imm = 0x4CDB
jne 0x1fec11
movq 0x1c543a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x48(%rbp), %edx
movsd -0x60(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
shrl %ecx
movl -0x58(%rbp), %r8d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x18(%rsi), %rsi
movl -0x48(%rbp), %r9d
movl (%rsi,%r9,4), %esi
shrl %esi
movl %esi, %esi
imulq $0x48, %rsi, %rsi
addq %rsi, %rax
movq -0x8(%rbp), %rsi
movq 0x18(%rsi), %rsi
movl -0x48(%rbp), %r9d
movl (%rsi,%r9,4), %esi
andl $0x1, %esi
movl %esi, %esi
movsd 0x30(%rax,%rsi,8), %xmm1
leaq 0x18e315(%rip), %rsi    # 0x38cf1f
movb $0x2, %al
callq 0x22a0
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)
cmpl $0x4cdb, -0x1c(%rbp)    # imm = 0x4CDB
jne 0x1fecdc
movq 0x1c5352(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x48(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x48(%rbp), %esi
movl (%rcx,%rsi,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), %esi
movl (%rcx,%rsi,4), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
movsd 0x30(%rax,%rcx,8), %xmm0
leaq 0x18e29e(%rip), %rsi    # 0x38cf73
movb $0x1, %al
callq 0x22a0
jmp 0x1fecde
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1fea67
jmp 0x1fecee
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1fea54
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
nop