// File: /workspace/github_cpp_makefile_star2_O2/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
imulq $0x48, %rcx, %r9
leaq (%rax,%r9), %rcx
movl 0x18(%rax,%r9), %ebx
testq %rbx, %rbx
je 0x115b16
movl 0x24(%rcx), %edx
cmpl $0x1, %edx
je 0x115b16
cmpl $-0x1, %edx
jne 0x115e73
movl 0x1c(%rcx), %ebp
testq %rbp, %rbp
je 0x115b2f
movl 0x28(%rcx), %ecx
cmpl $0x1, %ecx
je 0x115b2f
cmpl $-0x1, %ecx
jne 0x115e73
testq %rbp, %rbp
movq 0x10(%rax,%r9), %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 0x115cf4
movl 0x24(%rax,%r9), %eax
movq %rax, 0x50(%rsp)
addl %eax, %eax
cvtsi2sd %eax, %xmm1
xorpd 0xd7548(%rip), %xmm1    # 0x1ed0c0
xorl %r10d, %r10d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movapd %xmm1, 0x30(%rsp)
cmpq %rbx, %r10
je 0x115ce6
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x10(%rsi), %rax
movl (%r14,%r10,4), %ecx
imulq $0x30, %rcx, %rcx
cmpq %r15, (%rax,%rcx)
jbe 0x115cde
addq %rcx, %rax
movq 0x10(%rax), %rcx
imulq $0x28, %r15, %rdx
cmpb $0x0, 0x18(%rcx,%rdx)
js 0x115c1f
movl 0x8(%rcx,%rdx), %r13d
xorl %eax, %eax
cmpq %rax, %rbx
je 0x115bd9
leaq 0x1(%rax), %r9
cmpl %r13d, (%r14,%rax,4)
movq %r9, %rax
jne 0x115bc5
jmp 0x115c1f
movq 0x18(%rdi), %rax
movl (%rax,%r13,4), %eax
cmpq %r11, %rax
je 0x115c1f
movsd (%rcx,%rdx), %xmm0
movq 0x10(%rdi), %rdx
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x115c27
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
imulq $0x48, %rcx, %rcx
addq %rdx, %rcx
mulsd %xmm1, %xmm0
addsd 0x30(%rcx,%rax,8), %xmm0
movsd %xmm0, 0x30(%rcx,%rax,8)
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x115c9d
incl %r15d
jmp 0x115b93
movq 0x13d3b2(%rip), %rcx    # 0x252fe0
movq (%rcx), %rdi
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
imulq $0x48, %rcx, %rsi
addq %rsi, %rdx
movsd 0x30(%rdx,%rax,8), %xmm1
leaq 0xd84ef(%rip), %rsi     # 0x1ee13b
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 0x115bf8
movq 0x13d33c(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xd84e1(%rip), %rsi     # 0x1ee18f
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 0x115c1f
incq %r10
jmp 0x115b87
movq 0x10(%rdi), %rax
movq 0x48(%rsp), %r9
negl 0x24(%rax,%r9)
testq %rbp, %rbp
je 0x115e73
movl 0x28(%rax,%r9), %eax
movq %rax, 0x20(%rsp)
addl %eax, %eax
cvtsi2sd %eax, %xmm1
xorpd 0xd73ab(%rip), %xmm1    # 0x1ed0c0
xorl %ebx, %ebx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movapd %xmm1, 0x30(%rsp)
cmpq %rbp, %rbx
je 0x115e66
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x10(%rsi), %rax
movl (%r12,%rbx,4), %ecx
imulq $0x30, %rcx, %rcx
cmpq %r15, (%rax,%rcx)
jbe 0x115e5e
addq %rcx, %rax
movq 0x10(%rax), %rcx
imulq $0x28, %r15, %rdx
cmpb $0x0, 0x18(%rcx,%rdx)
js 0x115dbb
movl 0x8(%rcx,%rdx), %r13d
xorl %eax, %eax
cmpq %rax, %rbp
je 0x115d75
leaq 0x1(%rax), %r9
cmpl %r13d, (%r12,%rax,4)
movq %r9, %rax
jne 0x115d61
jmp 0x115dbb
movq 0x18(%rdi), %rax
movl (%rax,%r13,4), %eax
cmpq %r14, %rax
je 0x115dbb
movsd (%rcx,%rdx), %xmm0
movq 0x10(%rdi), %rdx
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x115dc3
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
imulq $0x48, %rcx, %rcx
addq %rdx, %rcx
mulsd %xmm1, %xmm0
addsd 0x30(%rcx,%rax,8), %xmm0
movsd %xmm0, 0x30(%rcx,%rax,8)
cmpl $0x4cdb, %r8d           # imm = 0x4CDB
je 0x115e29
incl %r15d
jmp 0x115d2f
movq 0x13d216(%rip), %rcx    # 0x252fe0
movq (%rcx), %rdi
movl %eax, %ecx
shrl %ecx
andl $0x1, %eax
imulq $0x48, %rcx, %rsi
addq %rsi, %rdx
movsd 0x30(%rdx,%rax,8), %xmm1
leaq 0xd83c6(%rip), %rsi     # 0x1ee1ae
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 0x115d94
movq 0x13d1b0(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xd83c8(%rip), %rsi     # 0x1ee202
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 0x115dbb
incq %rbx
jmp 0x115d23
movq 0x10(%rdi), %rax
movq 0x48(%rsp), %rcx
negl 0x28(%rax,%rcx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq