// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
xorl %esi, %esi
callq 0x2100
movl $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x88(%rbp), %rdi
movl $0x1, %r8d
leaq -0x40(%rbp), %r9
leaq -0x48(%rbp), %rax
movq %rax, (%rsp)
callq 0x1f0aa0
movl %eax, -0x4c(%rbp)
cmpl $-0x1, -0x4c(%rbp)
jne 0x1f175c
jmp 0x1f178d
movq -0x38(%rbp), %rax
movl -0x4c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1f1775
movl $0x1, -0x50(%rbp)
jmp 0x1f178d
movq -0x40(%rbp), %rax
cmpq 0x20(%rbp), %rax
jne 0x1f178b
movq -0x48(%rbp), %rax
cmpq 0x28(%rbp), %rax
jne 0x1f178b
jmp 0x1f178d
jmp 0x1f1727
cmpl $0x0, -0x50(%rbp)
jne 0x1f179f
movl $0x0, -0x4(%rbp)
jmp 0x1f184a
movq 0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x88(%rbp), %rdi
movl $0x1, %r8d
leaq -0x40(%rbp), %r9
leaq -0x48(%rbp), %rax
movq %rax, (%rsp)
callq 0x1f0aa0
movl %eax, -0x4c(%rbp)
cmpl $-0x1, -0x4c(%rbp)
jne 0x1f17e4
jmp 0x1f1843
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x1f17fa
jmp 0x1f17af
movq -0x38(%rbp), %rax
movl -0x4c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x4c(%rbp), %ecx
callq 0x1f0330
movq -0x40(%rbp), %rax
cmpq 0x20(%rbp), %rax
jne 0x1f183e
movq -0x48(%rbp), %rax
cmpq 0x28(%rbp), %rax
jne 0x1f183e
jmp 0x1f1843
jmp 0x1f17af
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)