// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: if_recoverable(asg_t*, ma_ug_t*, bubble_type*, unsigned int, kvec_t_u32_warp*, unsigned char*)
int if_recoverable(asg_t *sg, ma_ug_t *ug, bubble_type* bub, uint32_t bid, kvec_t_u32_warp* stack, uint8_t* vis_flag)
{
    uint32_t beg_utg, sink_utg, *a = NULL, n, begRid, sinkRid, i;
    get_bubbles(bub, bid, &beg_utg, &sink_utg, &a, &n, NULL);
    if(beg_utg == (uint32_t)-1 || sink_utg == (uint32_t)-1) return 0;
    if(beg_utg&1)
    {
        begRid = ug->u.a[beg_utg>>1].start^1;
    }
    else
    {
        begRid = ug->u.a[beg_utg>>1].end^1;
    }

    if(sink_utg&1)
    {
        sinkRid = ug->u.a[sink_utg>>1].start;
    }
    else
    {
        sinkRid = ug->u.a[sink_utg>>1].end;
    }

    asg_arc_t *acur = NULL;
    uint32_t cur, ncur, v, n_vx = sg->n_seq<<1;
    stack->a.n = 0; 
    memset(vis_flag, 0, n_vx);

    kv_push(uint32_t, stack->a, begRid);
    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        ncur = asg_arc_n(sg, cur);
        acur = asg_arc_a(sg, cur);
        vis_flag[cur] |= 1;
        for (i = 0; i < ncur; i++)
        {
            if(acur[i].del) continue;
            if(vis_flag[acur[i].v]&1) return 0;
            if(vis_flag[acur[i].v^1]&1) return 0;
            if(acur[i].v == sinkRid) continue;
            kv_push(uint32_t, stack->a, acur[i].v);
        }
    }
    vis_flag[sinkRid] |= 1;



    begRid ^= 1; sinkRid ^= 1; v = begRid; begRid = sinkRid; sinkRid = v;
    
    stack->a.n = 0; 
    kv_push(uint32_t, stack->a, begRid);
    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        ncur = asg_arc_n(sg, cur);
        acur = asg_arc_a(sg, cur);
        vis_flag[cur] |= 2;
        for (i = 0; i < ncur; i++)
        {
            if(acur[i].del) continue;
            if(vis_flag[acur[i].v]&2) return 0;
            if(vis_flag[acur[i].v]&1) return 0;
            if(vis_flag[acur[i].v^1]&2) return 0;
            if(acur[i].v == sinkRid) continue;
            kv_push(uint32_t, stack->a, acur[i].v);
        }
    }
    vis_flag[sinkRid] |= 2;



    begRid ^= 1; sinkRid ^= 1; v = begRid; begRid = sinkRid; sinkRid = v;

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rsi, %r13
movq %rdi, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0x30(%rsp), %r8
movq %r12, (%r8)
movl %ecx, %esi
movq %r12, (%rsp)
leaq 0x2c(%rsp), %rbp
leaq 0x28(%rsp), %r15
leaq 0x24(%rsp), %r9
movq %rdx, %rdi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x13df01
movl (%rbp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
sete %dl
movl (%r15), %ecx
cmpl $-0x1, %ecx
sete %sil
orb %dl, %sil
je 0xf7d9f
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, %ecx
xorl %edx, %edx
testb $0x1, %al
sete %dl
movq 0x10(%r13), %rsi
shrl %eax
leaq (%rax,%rax,4), %rax
leaq (%rsi,%rax,8), %rax
movl 0x4(%rax,%rdx,4), %edx
movq %rdx, 0x18(%rsp)
movl %edx, %ebp
xorl $0x1, %ebp
movl %ecx, %eax
shrl %eax
movl %ecx, %edx
shrl %edx
testb $0x1, %cl
leaq (%rax,%rax,4), %rax
leaq 0x4(%rsi,%rax,8), %rax
leaq (%rdx,%rdx,4), %rcx
leaq 0x8(%rsi,%rcx,8), %rcx
cmovneq %rax, %rcx
movl (%rcx), %eax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movl 0x14(%rax), %edx
addl %edx, %edx
movq $0x0, (%r14)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movq (%r14), %rcx
cmpq 0x8(%r14), %rcx
jne 0xf7e3a
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
jmp 0xf7e3e
movq 0x10(%r14), %rax
movq %rcx, %rdx
incq %rdx
movq %rdx, (%r14)
movl %ebp, (%rax,%rcx,4)
movq 0x10(%rsp), %r8
jne 0xf7e7d
orb $0x1, (%rbx,%r8)
xorl $0x1, %r8d
movq $0x0, (%r14)
cmpq $0x0, 0x8(%r14)
movq 0x10(%r14), %rdi
je 0xf7f5f
movl %r8d, (%rdi)
movl $0x1, %ecx
jmp 0xf7f9e
leaq -0x1(%rdx), %rax
movq %rax, (%r14)
movq 0x10(%r14), %rax
movl -0x4(%rax,%rdx,4), %edx
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%rdx,8), %rcx
orb $0x1, (%rbx,%rdx)
testl %ecx, %ecx
je 0xf7f4e
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rbp
addq $0x8, %rbp
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %r13d, %r13d
cmpl $0x0, 0x4(%rbp,%r13)
js 0xf7f41
movl (%rbp,%r13), %ecx
xorl %r12d, %r12d
testb $0x1, (%rbx,%rcx)
jne 0xf7d8d
movq %rcx, %rax
xorq $0x1, %rax
testb $0x1, (%rbx,%rax)
jne 0xf7d8d
cmpl %r8d, %ecx
je 0xf7f41
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0xf7f37
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %r8
movq %rax, 0x10(%r14)
movl (%rbp,%r13), %ecx
movq (%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r13
cmpq %r13, %r15
jne 0xf7ec9
movq (%r14), %rdx
testq %rdx, %rdx
jne 0xf7e7d
jmp 0xf7e51
movq $0x2, 0x8(%r14)
movl $0x8, %esi
movq %r8, %r15
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, (%r14)
movl %r15d, (%rax,%rdx,4)
jne 0xf7f9e
movq 0x18(%rsp), %rax
orb $0x2, (%rbx,%rax)
movl $0x1, %r12d
jmp 0xf7d8d
leaq -0x1(%rcx), %rax
movq %rax, (%r14)
movq 0x10(%r14), %rax
movl -0x4(%rax,%rcx,4), %edx
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%rdx,8), %rcx
orb $0x2, (%rbx,%rdx)
testl %ecx, %ecx
je 0xf8067
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rbp
addq $0x8, %rbp
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %r13d, %r13d
cmpl $0x0, 0x4(%rbp,%r13)
js 0xf805e
movl (%rbp,%r13), %ecx
xorl %r12d, %r12d
testb $0x3, (%rbx,%rcx)
jne 0xf7d8d
movq %rcx, %rax
xorq $0x1, %rax
testb $0x2, (%rbx,%rax)
jne 0xf7d8d
cmpl 0x18(%rsp), %ecx
je 0xf805e
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0xf8054
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movl (%rbp,%r13), %ecx
movq (%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r13
cmpq %r13, %r15
jne 0xf7fea
movq (%r14), %rcx
testq %rcx, %rcx
jne 0xf7f9e
jmp 0xf7f8a