// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
leaq -0x3c(%rbp), %rdx
leaq -0x40(%rbp), %rcx
leaq -0x48(%rbp), %r8
leaq -0x4c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
cmpl $-0x1, -0x3c(%rbp)
je 0x15557e
cmpl $-0x1, -0x40(%rbp)
jne 0x15558a
movl $0x0, -0x4(%rbp)
jmp 0x155bbd
movl -0x3c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1555b6
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1555d5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x40(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1555fe
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0x15561a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x54(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rdi
movl -0x70(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1556b6
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x15567b
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x155686
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x155686
movq -0x78(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x50(%rbp), %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x1556d7
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x1558a8
movq -0x30(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x64(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movl -0x64(%rbp), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x68(%rbp), %eax
jae 0x1558a3
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x155782
jmp 0x155895
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1557af
movl $0x0, -0x4(%rbp)
jmp 0x155bbd
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1557e1
movl $0x0, -0x4(%rbp)
jmp 0x155bbd
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0x1557fc
jmp 0x155895
jmp 0x1557fe
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x155866
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x15582b
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x155836
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x155836
movq -0x80(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x155895
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x155758
jmp 0x1556d7
movq -0x38(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x50(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x54(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x155959
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x155918
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0x155926
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0x155926
movq -0x88(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x50(%rbp), %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x15597a
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x155b81
movq -0x30(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x64(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movl -0x64(%rbp), %ecx
movzbl (%rax,%rcx), %edx
orl $0x2, %edx
movb %dl, (%rax,%rcx)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x68(%rbp), %eax
jae 0x155b7c
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x155a25
jmp 0x155b6e
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x155a52
movl $0x0, -0x4(%rbp)
jmp 0x155bbd
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x155a7f
movl $0x0, -0x4(%rbp)
jmp 0x155bbd
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movl -0x58(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x155ab1
movl $0x0, -0x4(%rbp)
jmp 0x155bbd
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0x155acc
jmp 0x155b6e
jmp 0x155ace
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x155b3f
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x155afe
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x155b0c
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x155b0c
movq -0x90(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x155b6e
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1559fb
jmp 0x15597a
movq -0x38(%rbp), %rax
movl -0x54(%rbp), %ecx
movzbl (%rax,%rcx), %edx
orl $0x2, %edx
movb %dl, (%rax,%rcx)
movl -0x50(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x54(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)