// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r8d
movq 0x10(%rdi), %rax
movl %ecx, %ecx
leaq (%rcx,%rcx,8), %r9
leaq (%rax,%r9,8), %rcx
movl 0x18(%rcx), %ebx
testq %rbx, %rbx
je 0x15bec7
movl 0x24(%rcx), %edx
cmpl $0x1, %edx
je 0x15bec7
cmpl $-0x1, %edx
jne 0x15c279
movl 0x1c(%rcx), %ebp
testq %rbp, %rbp
je 0x15bee0
movl 0x28(%rcx), %ecx
cmpl $0x1, %ecx
je 0x15bee0
cmpl $-0x1, %ecx
jne 0x15c279
testq %rbp, %rbp
movq 0x10(%rax,%r9,8), %r14
leaq (%r14,%rbx,4), %r12
cmoveq %rbp, %r12
testq %rbx, %rbx
cmoveq %rbx, %r14
movl %r8d, 0xc(%rsp)
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %r9, 0x48(%rsp)
je 0x15c0ce
movl 0x24(%rax,%r9,8), %eax
movq %rax, 0x50(%rsp)
addl %eax, %eax
cvtsi2sd %eax, %xmm1
xorpd 0xdf2a7(%rip), %xmm1    # 0x23b1d0
movq 0x10(%rsi), %rax
xorl %r10d, %r10d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movapd %xmm1, 0x30(%rsp)
movl (%r14,%r10,4), %ecx
leaq (%rcx,%rcx,2), %rdx
shlq $0x4, %rdx
cmpq $0x0, (%rax,%rdx)
je 0x15c0b4
addq %rax, %rdx
xorl %r15d, %r15d
movq 0x10(%rdx), %r9
leaq (%r15,%r15,4), %rdx
cmpb $0x0, 0x18(%r9,%rdx,8)
js 0x15bfd6
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq 0x10(%rax,%rcx), %rcx
movl 0x8(%rcx,%rdx,8), %r13d
xorl %eax, %eax
cmpl %r13d, (%r14,%rax,4)
je 0x15bfd6
incq %rax
cmpq %rax, %rbx
jne 0x15bf7d
movq 0x18(%rdi), %rax
movl (%rax,%r13,4), %eax
cmpq %r11, %rax
je 0x15bfd6
movsd (%rcx,%rdx,8), %xmm0
movq 0x10(%rdi), %rdx
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x15bffc
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
leaq (%rcx,%rcx,8), %rcx
leaq (%rdx,%rcx,8), %rcx
mulsd %xmm1, %xmm0
addsd 0x30(%rcx,%rax,8), %xmm0
movsd %xmm0, 0x30(%rcx,%rax,8)
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x15c073
incl %r15d
movq 0x10(%rsi), %rax
movl (%r14,%r10,4), %ecx
leaq (%rcx,%rcx,2), %r9
shlq $0x4, %r9
leaq (%rax,%r9), %rdx
cmpq %r15, (%rax,%r9)
ja 0x15bf59
jmp 0x15c0b4
movq 0x138fdd(%rip), %rcx    # 0x294fe0
movq (%rcx), %rdi
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
leaq (%rcx,%rcx,8), %rsi
leaq (%rdx,%rsi,8), %rdx
movsd 0x30(%rdx,%rax,8), %xmm1
leaq 0xe0229(%rip), %rsi     # 0x23c24b
movl %r13d, %edx
movq 0x50(%rsp), %r8
movb $0x2, %al
movq %r10, 0x28(%rsp)
movsd %xmm0, 0x20(%rsp)
callq 0x22b0
movsd 0x20(%rsp), %xmm0
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq 0x28(%rsp), %r10
movapd 0x30(%rsp), %xmm1
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r8d
movq 0x10(%rdi), %rdx
movq 0x18(%rdi), %rax
movl (%rax,%r13,4), %eax
jmp 0x15bfaa
movq 0x138f66(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0xe021b(%rip), %rsi     # 0x23c29f
movl %r13d, %edx
movb $0x1, %al
movq %r10, %r13
callq 0x22b0
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movq %r13, %r10
movapd 0x30(%rsp), %xmm1
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r8d
jmp 0x15bfd6
incq %r10
cmpq %rbx, %r10
jne 0x15bf3c
movq 0x10(%rdi), %rax
movq 0x48(%rsp), %r9
negl 0x24(%rax,%r9,8)
testq %rbp, %rbp
je 0x15c279
movl 0x28(%rax,%r9,8), %eax
movq %rax, 0x20(%rsp)
addl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
xorpd 0xdf0de(%rip), %xmm1    # 0x23b1d0
movq 0x10(%rsi), %rax
xorl %ebx, %ebx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movapd %xmm1, 0x30(%rsp)
movl (%r12,%rbx,4), %ecx
leaq (%rcx,%rcx,2), %rdx
shlq $0x4, %rdx
cmpq $0x0, (%rax,%rdx)
je 0x15c260
addq %rax, %rdx
xorl %r15d, %r15d
movq 0x10(%rdx), %r9
leaq (%r15,%r15,4), %rdx
cmpb $0x0, 0x18(%r9,%rdx,8)
js 0x15c19e
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq 0x10(%rax,%rcx), %rcx
movl 0x8(%rcx,%rdx,8), %r13d
xorl %eax, %eax
cmpl %r13d, (%r12,%rax,4)
je 0x15c19e
incq %rax
cmpq %rax, %rbp
jne 0x15c145
movq 0x18(%rdi), %rax
movl (%rax,%r13,4), %eax
cmpq %r14, %rax
je 0x15c19e
movsd (%rcx,%rdx,8), %xmm0
movq 0x10(%rdi), %rdx
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x15c1c4
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
leaq (%rcx,%rcx,8), %rcx
leaq (%rdx,%rcx,8), %rcx
mulsd %xmm1, %xmm0
addsd 0x30(%rcx,%rax,8), %xmm0
movsd %xmm0, 0x30(%rcx,%rax,8)
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x15c22b
incl %r15d
movq 0x10(%rsi), %rax
movl (%r12,%rbx,4), %ecx
leaq (%rcx,%rcx,2), %r9
shlq $0x4, %r9
leaq (%rax,%r9), %rdx
cmpq %r15, (%rax,%r9)
ja 0x15c121
jmp 0x15c260
movq 0x138e15(%rip), %rcx    # 0x294fe0
movq (%rcx), %rdi
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
leaq (%rcx,%rcx,8), %rsi
leaq (%rdx,%rsi,8), %rdx
movsd 0x30(%rdx,%rax,8), %xmm1
leaq 0xe00d4(%rip), %rsi     # 0x23c2be
movl %r13d, %edx
movq 0x20(%rsp), %r8
movb $0x2, %al
movsd %xmm0, 0x28(%rsp)
callq 0x22b0
movsd 0x28(%rsp), %xmm0
movapd 0x30(%rsp), %xmm1
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r8d
movq 0x10(%rdi), %rdx
movq 0x18(%rdi), %rax
movl (%rax,%r13,4), %eax
jmp 0x15c172
movq 0x138dae(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0xe00d6(%rip), %rsi     # 0x23c312
movl %r13d, %edx
movb $0x1, %al
callq 0x22b0
movapd 0x30(%rsp), %xmm1
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %r8d
jmp 0x15c19e
incq %rbx
cmpq %rbp, %rbx
jne 0x15c104
movq 0x10(%rdi), %rax
movq 0x48(%rsp), %rcx
negl 0x28(%rax,%rcx,8)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq