// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: double_check_broken_bubble(asg_t*, kvec_t_u32_warp*, unsigned int, unsigned int, unsigned char*, unsigned int, kvec_t_u32_warp*, asg_t*, asg_arc_t*)
int double_check_broken_bubble(asg_t *g, kvec_t_u32_warp* broken, uint32_t beg, uint32_t sink, 
uint8_t* vis_flag, uint32_t vis_flag_n, kvec_t_u32_warp* stack, asg_t *bsg, asg_arc_t *p_t)
{
    uint32_t cur, ncur, i, n, pre, occ;
    radix_sort_u32(broken->a.a, broken->a.a + broken->a.n);
    for (i = n = 0, pre = (uint32_t)-1; i < broken->a.n; i++)
    {
        if((broken->a.a[i]>>1) == (pre>>1)) continue;///skip same node like v and v^1
        pre = broken->a.a[i];
        broken->a.a[n] = pre;
        n++;
    }
    broken->a.n = n;

    asg_arc_t *acur = NULL;
    memset(vis_flag, 0, vis_flag_n);
    stack->a.n = 0;
    kv_push(uint32_t, stack->a, beg);
    occ = 0;
    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        if(vis_flag[cur] == 0 && vis_flag[cur^1] == 0) occ++;
        if(vis_flag[cur] == 0 && cur != (beg^1) && (sink == (uint32_t)-1 || cur != (sink^1)))
        {
            vis_flag[cur] = 1;
            ncur = asg_arc_n(g, cur);
            acur = asg_arc_a(g, cur);
            for (i = 0; i < ncur; i++)
            {
                if(acur[i].del) continue;
                if(vis_flag[acur[i].v]) continue;
                kv_push(uint32_t, stack->a, acur[i].v);
            }
        }
        vis_flag[cur] = 1;
        

        cur^=1;
        if(vis_flag[cur] == 0 && cur != (beg^1) && (sink == (uint32_t)-1 || cur != (sink^1)))
        {
            vis_flag[cur] = 1;
            ncur = asg_arc_n(g, cur);
            acur = asg_arc_a(g, cur);
            for (i = 0; i < ncur; i++)
            {
                if(acur[i].del) continue;
                if(vis_flag[acur[i].v]) continue;
                kv_push(uint32_t, stack->a, acur[i].v);
            }
        }
        vis_flag[cur] = 1;
    }

    n = broken->a.n;
    if(beg != (uint32_t)-1) n++;
    if(sink != (uint32_t)-1) n++;

    if(occ > n)
    {
        ///fprintf(stderr, "\n+++++sb+++++beg-utg%.6ul, sink-utg%.6ul, occ: %u, n: %u\n", (beg>>1)+1, (sink>>1)+1, occ, n);
        if(bsg && p_t && beg != (uint32_t)-1 && sink != (uint32_t)-1)
        {
            p_t->del = 1;
            asg_arc_del(bsg, (p_t->v)^1, (p_t->ul>>32)^1, 1);
        }
        /*******************************for debug************************************/
        // memset(vis_flag, 0, vis_flag_n);
        // stack->a.n = 0;
        // kv_push(uint32_t, stack->a, beg);
        // occ = 0;
        // while (stack->a.n > 0)
        // {
        //     occ++;
        //     stack->a.n--;
        //     cur = stack->a.a[stack->a.n];

        //     fprintf(stderr, "cur-utg%.6ul\n", (cur>>1)+1);

        //     vis_flag[cur] = 1;
        //     if(cur == (beg^1) || cur == (sink^1)) continue;
        //     ncur = asg_arc_n(g, cur);
        //     acur = asg_arc_a(g, cur);
        //     for (i = 0; i < ncur; i++)
        //     {
        //         if(acur[i].del) continue;
        //         if(vis_flag[acur[i].v]) continue;
        //         kv_push(uint32_t, stack->a, acur[i].v);
        //     }

        //     cur^=1;
        //     if(vis_flag[cur]) continue;
        //     vis_flag[cur] = 1;
        //     if(cur == (beg^1) || cur == (sink^1)) continue;
        //     ncur = asg_arc_n(g, cur);
        //     acur = asg_arc_a(g, cur);
        //     for (i = 0; i < ncur; i++)
        //     {
        //         if(acur[i].del) continue;
        //         if(vis_flag[acur[i].v]) continue;
        //         kv_push(uint32_t, stack->a, acur[i].v);
        //     }
        // }

        // for (i = 0; i < broken->a.n; i++)
        // {
        //     fprintf(stderr, "*****cur-utg%.6ul\n", (broken->a.a[i]>>1)+1);
        // }
        /*******************************for debug************************************/
        return 0;
    }
     
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r13d
movq %r8, %r15
movl %ecx, %ebx
movl %edx, (%rsp)
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
movq 0x60(%rsp), %r14
movq (%rsi), %rax
movq 0x10(%rsi), %rdi
leaq (%rdi,%rax,4), %rsi
callq 0x137c5c
movq (%r12), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x14bf64
movq 0x10(%r12), %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
movl (%rdx,%rsi,4), %r8d
movl %r8d, %r9d
xorl %edi, %r9d
cmpl $0x2, %r9d
jb 0x14bf57
movl %eax, %edi
movl %r8d, (%rdx,%rdi,4)
incl %eax
movl %r8d, %edi
incq %rsi
movl %esi, %r8d
cmpq %r8, %rcx
ja 0x14bf3c
movl %eax, %eax
movq %r12, 0x18(%rsp)
movq %rax, (%r12)
movl %r13d, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
movq $0x0, (%r14)
cmpq $0x0, 0x8(%r14)
je 0x14bf98
movq 0x10(%r14), %rax
movl (%rsp), %ecx
movl %ecx, (%rax)
movl $0x1, %ecx
jmp 0x14bfd3
movq $0x0, 0x8(%rsp)
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, (%r14)
movl (%rsp), %esi
movl %esi, (%rax,%rdx,4)
je 0x14c1bf
movq $0x0, 0x8(%rsp)
movl %ebx, 0x4(%rsp)
leaq -0x1(%rcx), %rax
movq %rax, (%r14)
movq 0x10(%r14), %rax
movl -0x4(%rax,%rcx,4), %r12d
movq %r12, %r13
xorq $0x1, %r13
cmpb $0x0, (%r15,%r12)
jne 0x14c0dc
cmpb $0x1, (%r15,%r13)
movq 0x8(%rsp), %rax
adcl $0x0, %eax
movq %rax, 0x8(%rsp)
movl %r12d, %eax
xorl (%rsp), %eax
cmpl $0x1, %eax
je 0x14c0dc
cmpl $-0x1, %ebx
je 0x14c036
movl %r12d, %eax
xorl %ebx, %eax
cmpl $0x1, %eax
je 0x14c0dc
movb $0x1, (%r15,%r12)
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rax
movq (%rax,%r12,8), %rax
testl %eax, %eax
je 0x14c0dc
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rbx
addq $0x8, %rbx
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
xorl %ebp, %ebp
movq %rdi, 0x20(%rsp)
cmpl $0x0, 0x4(%rbx,%rbp)
js 0x14c0cf
movl (%rbx,%rbp), %ecx
cmpb $0x0, (%r15,%rcx)
jne 0x14c0cf
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x14c0c5
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 0x20(%rsp), %rdi
movq %rax, 0x10(%r14)
movl (%rbx,%rbp), %ecx
movq (%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbp
cmpq %rbp, %rdi
jne 0x14c078
movl 0x4(%rsp), %ebx
cmpl $-0x1, %ebx
setne %al
movb $0x1, (%r15,%r12)
cmpl %ebx, %r12d
sete %cl
cmpl (%rsp), %r12d
je 0x14c1aa
cmpb $0x0, (%r15,%r13)
jne 0x14c1aa
andb %cl, %al
jne 0x14c1aa
movb $0x1, (%r15,%r13)
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r13,8), %rax
testl %eax, %eax
je 0x14c1aa
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0x8, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
xorl %ebp, %ebp
cmpl $0x0, 0x4(%r12,%rbp)
js 0x14c1a1
movl (%r12,%rbp), %ecx
cmpb $0x0, (%r15,%rcx)
jne 0x14c1a1
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x14c197
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 (%r12,%rbp), %ecx
movq (%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbp
cmpq %rbp, %rbx
jne 0x14c14c
movb $0x1, (%r15,%r13)
movq (%r14), %rcx
testq %rcx, %rcx
movl 0x4(%rsp), %ebx
jne 0x14bfe0
xorl %eax, %eax
cmpl $-0x1, (%rsp)
setne %al
xorl %ecx, %ecx
cmpl $-0x1, %ebx
setne %cl
addl %eax, %ecx
movq 0x18(%rsp), %rax
addl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, 0x8(%rsp)
jbe 0x14c25e
xorl %eax, %eax
cmpl $-0x1, %ebx
je 0x14c25e
cmpl $-0x1, (%rsp)
je 0x14c25e
movq 0x68(%rsp), %rcx
testq %rcx, %rcx
je 0x14c25e
movq 0x70(%rsp), %rdx
testq %rdx, %rdx
je 0x14c25e
orb $-0x80, 0xf(%rdx)
movl 0x8(%rdx), %esi
xorq $0x1, %rsi
movq 0x28(%rcx), %rdi
movq (%rdi,%rsi,8), %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rsi, %rdi
je 0x14c25e
movl 0x4(%rdx), %eax
movq 0x8(%rcx), %rdx
shrq $0x20, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rcx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0xc, %rdx
xorl %esi, %esi
movl -0x4(%rdx,%rsi), %edi
xorl %eax, %edi
cmpl $0x1, %edi
jne 0x14c253
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x14c243
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq