// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: next_hap_label_id(block_phase_type*, G_partition*, bubble_type*, ma_utg_t*, int, long long*, long long*)
uint32_t next_hap_label_id(block_phase_type* b, G_partition* g_p, bubble_type* bub, ma_utg_t *u, 
int is_forward, long long* c_bid, long long* c_uid)
{
    uint32_t beg, sink, uid, *a, n, gid, pre_gid;
    while (1) ///while(b->bid < (long long)u->n)
    {
        if(is_forward == 1 && b->bid >= (long long)u->n) break;
        if(is_forward == 0 && b->bid < 0) break;

        get_bubbles(bub, u->a[b->bid]>>33, &beg, &sink, &a, &n, NULL);
        while (1) ///while (b->uid < (long long)n)
        {
            if(is_forward == 1 && b->uid >= (long long)n) break;
            if(is_forward == 0 && b->uid < 0) break;

            uid = a[b->uid]>>1;
            gid = (uint32_t)-1;
            if(g_p->index[uid] != (uint32_t)-1)
            {
                gid = g_p->index[uid]>>1;
            }
            if(c_bid) (*c_bid) = b->bid;
            if(c_uid) (*c_uid) = b->uid;

            if(is_forward == 1) b->uid++;
            if(is_forward == 0) b->uid--;
            if(gid == (uint32_t)-1) continue;


            pre_gid = uid = (uint32_t)-1;
            if(is_forward == 1 && (b->uid >= 2)) uid = a[b->uid - 2]>>1;
            if(is_forward == 0 && (b->uid + 2 < n)) uid = a[b->uid + 2]>>1;
            if(uid != (uint32_t)-1 && g_p->index[uid] != (uint32_t)-1) pre_gid = g_p->index[uid]>>1;

            if(pre_gid == gid) continue;

            return gid;
        }
        
        if(is_forward == 1) b->bid++, b->uid = 0;
        if(is_forward == 0) b->bid--, b->uid = (long long)n - (long long)1;
    }

    return (uint32_t)-1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x38(%rsp), %r10
movq 0x20(%rdi), %rax
cmpl $0x1, %r8d
je 0x155085
testl %r8d, %r8d
jne 0x155092
movb $0x1, %r11b
testq %rax, %rax
jns 0x155095
jmp 0x1551ba
movl 0x10(%rcx), %r11d
cmpq %r11, %rax
jge 0x1551ba
xorl %r11d, %r11d
movq 0x18(%rcx), %rbx
movq (%rbx,%rax,8), %rax
movq 0x28(%rdx), %r14
movq 0x40(%rdx), %rbx
shrq $0x21, %rax
movl (%rbx,%rax,4), %r15d
movl 0x4(%rbx,%rax,4), %ebx
subl %r15d, %ebx
addl $-0x2, %ebx
movq 0x28(%rdi), %rax
cmpl $0x1, %r8d
jne 0x1550ca
cmpq %rbx, %rax
jge 0x155184
leaq (%r14,%r15,4), %r14
testq %rax, %rax
sets %bpl
testb %bpl, %r11b
jne 0x1551a3
movl 0x8(%r14,%rax,4), %eax
shrl %eax
movq 0x18(%rsi), %r15
movl (%r15,%rax,4), %eax
testq %r9, %r9
je 0x1550f9
movq 0x20(%rdi), %r12
movq %r12, (%r9)
testq %r10, %r10
je 0x155105
movq 0x28(%rdi), %r12
movq %r12, (%r10)
cmpl $0x1, %r8d
jne 0x15510f
incq 0x28(%rdi)
testb %r11b, %r11b
je 0x155118
decq 0x28(%rdi)
cmpl $-0x1, %eax
je 0x15516d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x1, %r8d
jne 0x155138
movq 0x28(%rdi), %r12
cmpq $0x2, %r12
jl 0x155138
movl (%r14,%r12,4), %ebp
shrl %ebp
shrl %eax
testb %r11b, %r11b
je 0x155156
movq 0x28(%rdi), %r12
leaq 0x2(%r12), %r13
cmpq %rbx, %r13
jge 0x155156
movl 0x10(%r14,%r12,4), %ebp
shrl %ebp
jmp 0x15515b
cmpl $-0x1, %ebp
je 0x1551bf
movl %ebp, %r12d
movl (%r15,%r12,4), %ebp
cmpl $-0x1, %ebp
je 0x1551bf
shrl %ebp
cmpl %eax, %ebp
jne 0x1551bf
movq 0x28(%rdi), %rax
cmpl $0x1, %r8d
jne 0x1550ce
cmpq %rbx, %rax
jl 0x1550ce
movq 0x20(%rdi), %rax
leaq 0x1(%rax), %r14
movq %r14, 0x20(%rdi)
movq $0x0, 0x28(%rdi)
testb %r11b, %r11b
je 0x155069
jmp 0x1551aa
movq 0x20(%rdi), %rax
decq %rax
movq %rax, 0x20(%rdi)
decq %rbx
movq %rbx, 0x28(%rdi)
jmp 0x155069
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq