// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq 0xa8(%rsp), %rdx
movq 0xa0(%rsp), %rsi
leaq 0x10(%rsp), %rbp
movq %rcx, (%rbp)
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x30(%rsp), %rbx
movq %rsi, 0x20(%rbx)
movq %rdx, 0x28(%rbx)
movq %rdi, 0x18(%rsp)
movq 0x10(%rdi), %rdi
movq (%r13), %rdx
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x20e0
leaq 0x8(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
movq %rbp, %r9
callq 0x15505a
cmpl $-0x1, %eax
je 0x1559b2
movl %eax, %eax
movq 0x20(%rsp), %rcx
cmpb $0x0, (%rcx,%rax)
je 0x1558db
movq 0xb0(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15587f
movq 0xb8(%rsp), %rax
cmpq %rax, 0x8(%rsp)
jne 0x15587f
jmp 0x1559b2
leaq 0x30(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rdi)
movq 0xa8(%rsp), %rax
movq %rax, 0x28(%rdi)
leaq 0x8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x10(%rsp), %r9
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
callq 0x15505a
cmpl $-0x1, %eax
je 0x1559ac
movb $0x1, %bl
movq 0x28(%rsp), %rbp
movl $0x1, %r14d
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rdx
movl %eax, %ecx
cmpb $0x1, (%rdx,%rcx)
je 0x15597e
movq 0x20(%rsp), %rax
movb %bl, (%rax,%rcx)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movb %bl, (%rax,%rcx)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x154db7
movq 0xb0(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15597e
movq 0xb8(%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x1559ac
leaq 0x8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
leaq 0x10(%rsp), %r9
callq 0x15505a
cmpl $-0x1, %eax
jne 0x155930
jmp 0x1559b2
movl $0x1, %r14d
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq