// File: /workspace/github_cpp_makefile_star2_O1/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, 0xc(%rsp)
movl %edx, 0x8(%rsp)
movq %rsi, %rbx
movq %rdi, 0x18(%rsp)
movq 0x60(%rsp), %r14
movq (%rsi), %rax
movq 0x10(%rsi), %rdi
leaq (%rdi,%rax,4), %rsi
callq 0x131a70
movq (%rbx), %rcx
xorl %eax, %eax
testq %rcx, %rcx
movq %rbx, 0x20(%rsp)
je 0x145928
movq 0x10(%rbx), %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
movl (%rdx,%rsi,4), %r8d
movl %r8d, %r9d
xorl %edi, %r9d
cmpl $0x2, %r9d
jb 0x145916
movl %eax, %edi
movl %r8d, (%rdx,%rdi,4)
incl %eax
movl %r8d, %edi
incq %rsi
movl %esi, %r8d
cmpq %r8, %rcx
ja 0x1458fb
movl %eax, %eax
movq 0x20(%rsp), %rbx
movq %rax, (%rbx)
movl %r13d, %edx
movq $0x0, 0x10(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
movq $0x0, (%r14)
cmpq $0x0, 0x8(%r14)
jne 0x145969
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq 0x10(%r14), %rdx
movq %rcx, %rax
incq %rax
movq %rax, (%r14)
movl 0x8(%rsp), %esi
movl %esi, (%rdx,%rcx,4)
movl 0xc(%rsp), %edi
je 0x145b83
movq $0x0, 0x10(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, (%r14)
movq 0x10(%r14), %rcx
movl -0x4(%rcx,%rax,4), %r13d
movb (%r15,%r13), %al
testb %al, %al
jne 0x1459c4
movq %r13, %rcx
xorq $0x1, %rcx
cmpb $0x1, (%r15,%rcx)
movq 0x10(%rsp), %rcx
adcl $0x0, %ecx
movq %rcx, 0x10(%rsp)
testb %al, %al
setne %al
movl %r13d, %ecx
xorl 0x8(%rsp), %ecx
cmpl $0x1, %ecx
sete %cl
orb %al, %cl
jne 0x145a96
cmpl $-0x1, %edi
je 0x1459f1
movl %r13d, %eax
xorl %edi, %eax
cmpl $0x1, %eax
je 0x145a96
movb $0x1, (%r15,%r13)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r13,8), %rax
testl %eax, %eax
je 0x145a96
movq 0x18(%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 0x145a8d
movl (%r12,%rbp), %eax
cmpb $0x0, (%r15,%rax)
jne 0x145a8d
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x145a78
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movl 0xc(%rsp), %edi
movq %rax, 0x10(%r14)
movl (%r12,%rbp), %eax
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %rbp
cmpq %rbp, %rbx
jne 0x145a33
movl %r13d, %edx
movl %r13d, %ecx
cmpl $-0x1, %edi
setne %al
movb $0x1, (%r15,%r13)
xorq $0x1, %r13
cmpl %edi, %ecx
sete %cl
cmpl 0x8(%rsp), %edx
je 0x145b72
cmpb $0x0, (%r15,%r13)
jne 0x145b72
andb %cl, %al
jne 0x145b72
movb $0x1, (%r15,%r13)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r13,8), %rax
testl %eax, %eax
je 0x145b72
movq 0x18(%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 0x145b69
movl (%r12,%rbp), %eax
cmpb $0x0, (%r15,%rax)
jne 0x145b69
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x145b54
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movl 0xc(%rsp), %edi
movq %rax, 0x10(%r14)
movl (%r12,%rbp), %eax
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %rbp
cmpq %rbp, %rbx
jne 0x145b0f
movb $0x1, (%r15,%r13)
movq (%r14), %rax
testq %rax, %rax
jne 0x145993
xorl %eax, %eax
cmpl $-0x1, 0x8(%rsp)
setne %al
xorl %ecx, %ecx
cmpl $-0x1, %edi
setne %cl
addl %eax, %ecx
movq 0x20(%rsp), %rax
addl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, 0x10(%rsp)
jbe 0x145c24
xorl %eax, %eax
cmpl $-0x1, %edi
je 0x145c24
cmpl $-0x1, 0x8(%rsp)
je 0x145c24
movq 0x68(%rsp), %rcx
testq %rcx, %rcx
je 0x145c24
movq 0x70(%rsp), %rdx
testq %rdx, %rdx
je 0x145c24
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 0x145c24
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 0x145c19
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x145c09
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq