// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: flip_block(block_phase_type*, G_partition*, bubble_type*, ma_utg_t*, hc_links*, unsigned char*, long long, long long, long long, long long)
int flip_block(block_phase_type* i_buf, G_partition* g_p, bubble_type* bub, 
ma_utg_t *u, hc_links* link, uint8_t* lock, long long f_bid, long long f_uid, long long l_bid, long long l_uid)
{
    long long c_bid = l_bid, c_uid = l_uid;
    uint32_t gid, val = 0;
    block_phase_type b;
    b.bid = f_bid; b.uid = f_uid;
    memset(i_buf->vis.a, 0, g_p->n);
    val = 0;
    while (1)
    {
        gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
        ////fprintf(stderr, "+gid: %u\n", gid);
        if(gid == (uint32_t)-1) break;
        ///fprintf(stderr, "lock[gid]: %u\n", lock[gid]);
        if(lock[gid] == 0)
        {
            val = 1;
            break;
        } 
        if(c_bid == l_bid && c_uid == l_uid) break;
    }

    if(val == 0) return 0;

    b.bid = f_bid; b.uid = f_uid;
    while (1)
    {
        gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
        ///fprintf(stderr, "-gid: %u\n", gid);
        if(gid == (uint32_t)-1) break;
        ///fprintf(stderr, "vis[gid]: %u\n", i_buf->vis.a[gid]);
        if(i_buf->vis.a[gid] == 1) continue;
        lock[gid] = 1;
        i_buf->vis.a[gid] = 1;
        // if(f_bid == 689 && f_uid == 1)
        // {
        //     fprintf(stderr, "sssssssssssssssssssss\n");
        //     print_phase_group(g_p, bub, "Small-1");
        //     fprintf(stderr, "sbsbsbsb-gid: %u\n", gid);
        // }
        flip_unitig(g_p, link, bub, gid);
        ///flip_unitig_debug(g_p, link, bub, gid);
        // if(f_bid == 689 && f_uid == 1)
        // {
        //     fprintf(stderr, "sasasasa-gid: %u\n", gid);
        //     print_phase_group(g_p, bub, "Small-2");
        //     fprintf(stderr, "eeeeeeeeeeeeeeeeeeeeee\n");
        // }
        if(c_bid == l_bid && c_uid == l_uid) break;
    }

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbx
movq %r8, 0x18(%rsp)
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbp
movq 0xa8(%rsp), %rax
movq 0xa0(%rsp), %rcx
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rsi
leaq 0x10(%rsp), %rdi
movq %rcx, (%rdi)
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x20(%rsp), %r14
movq %rsi, 0x20(%r14)
movq %rdx, 0x28(%r14)
movq 0x10(%rbp), %rdi
movq (%r13), %rdx
xorl %esi, %esi
callq 0x20e0
leaq 0x8(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
pushq $0x1
popq %r8
leaq 0x10(%rsp), %r9
callq 0x10dfb2
cmpl $-0x1, %eax
je 0x10e828
movl %eax, %eax
cmpb $0x0, (%rbx,%rax)
je 0x10e82f
movq 0xa0(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x10e7da
movq 0xa8(%rsp), %rax
cmpq %rax, 0x8(%rsp)
jne 0x10e7da
xorl %eax, %eax
jmp 0x10e8c4
leaq 0x20(%rsp), %rcx
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rcx)
movq 0x98(%rsp), %rax
movq %rax, 0x28(%rcx)
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
pushq $0x1
popq %r8
movq %r14, %r9
callq 0x10dfb2
cmpl $-0x1, %eax
je 0x10e8c1
movq 0x10(%rbp), %rdx
movl %eax, %ecx
cmpb $0x1, (%rdx,%rcx)
je 0x10e851
movb $0x1, %sil
movb %sil, (%rbx,%rcx)
movq 0x10(%rbp), %rdx
movb %sil, (%rdx,%rcx)
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movl %eax, %ecx
callq 0x10dc0d
movq 0xa0(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x10e851
movq 0xa8(%rsp), %rax
cmpq %rax, 0x8(%rsp)
jne 0x10e851
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq