// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movq %r8, %r12
movl %ecx, 0xc(%rsp)
movl %edx, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, 0x20(%rsp)
movq 0x60(%rsp), %rbx
movq (%rsi), %rax
movq 0x10(%rsi), %rdi
leaq (%rdi,%rax,4), %rsi
callq 0xf1352
movq %r14, 0x18(%rsp)
movq (%r14), %rax
pushq $-0x1
popq %rsi
xorl %ecx, %ecx
xorl %edx, %edx
movl %ecx, %ecx
movl %edx, %edi
cmpq %rcx, %rax
jbe 0x10409c
movq 0x18(%rsp), %r8
movq 0x10(%r8), %r9
movl (%r9,%rcx,4), %r8d
movl %r8d, %r10d
xorl %esi, %r10d
cmpl $0x2, %r10d
jb 0x104098
movl %r8d, (%r9,%rdi,4)
incl %edx
movl %r8d, %esi
incl %ecx
jmp 0x10406d
movq 0x18(%rsp), %rax
movq %rdi, (%rax)
movl %ebp, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x20e0
andq $0x0, (%rbx)
cmpq $0x0, 0x8(%rbx)
je 0x1040c3
movq 0x10(%rbx), %rax
xorl %edx, %edx
jmp 0x1040de
movq $0x2, 0x8(%rbx)
movq 0x10(%rbx), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%rbx)
movl 0x8(%rsp), %esi
movl %esi, (%rax,%rdx,4)
movq $0x0, 0x10(%rsp)
testq %rcx, %rcx
je 0x1042ca
leaq -0x1(%rcx), %rax
movq %rax, (%rbx)
movq 0x10(%rbx), %rax
movl -0x4(%rax,%rcx,4), %r13d
movb (%r12,%r13), %al
testb %al, %al
jne 0x10412f
movq %r13, %rcx
xorq $0x1, %rcx
cmpb $0x1, (%r12,%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 0x104160
cmpl $-0x1, 0xc(%rsp)
je 0x104237
movl %r13d, %eax
xorl 0xc(%rsp), %eax
cmpl $0x1, %eax
jne 0x104237
movl %r13d, %edx
movl %r13d, %ecx
movl 0xc(%rsp), %esi
cmpl $-0x1, %esi
setne %al
movb $0x1, (%r12,%r13)
xorq $0x1, %r13
cmpl %esi, %ecx
sete %cl
cmpl 0x8(%rsp), %edx
je 0x10422a
cmpb $0x0, (%r12,%r13)
jne 0x10422a
andb %cl, %al
jne 0x10422a
movb $0x1, (%r12,%r13)
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%r13,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x18, %rdx, %r15
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %rbp
addq $0x8, %rbp
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x10422a
cmpl $0x0, 0x4(%rbp,%r14)
js 0x104224
movl (%rbp,%r14), %ecx
cmpb $0x0, (%r12,%rcx)
jne 0x104224
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x10421a
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movl (%rbp,%r14), %ecx
movq (%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r14
jmp 0x1041ca
movb $0x1, (%r12,%r13)
movq (%rbx), %rcx
jmp 0x1040f5
movb $0x1, (%r12,%r13)
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%r13,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x18, %rdx, %r15
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %rbp
addq $0x8, %rbp
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x104160
cmpl $0x0, 0x4(%rbp,%r14)
js 0x1042c4
movl (%rbp,%r14), %ecx
cmpb $0x0, (%r12,%rcx)
jne 0x1042c4
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x1042ba
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movl (%rbp,%r14), %ecx
movq (%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r14
jmp 0x104266
xorl %eax, %eax
movl 0xc(%rsp), %edx
cmpl $-0x1, %edx
setne %al
xorl %ecx, %ecx
cmpl $-0x1, 0x8(%rsp)
setne %cl
addl %ecx, %eax
movq 0x18(%rsp), %rcx
addl (%rcx), %eax
cmpl %eax, 0x10(%rsp)
jbe 0x104328
xorl %ebx, %ebx
cmpl $-0x1, %edx
je 0x10432b
cmpl $-0x1, 0x8(%rsp)
je 0x10432b
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x10432b
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0x10432b
orb $-0x80, 0xf(%rax)
movl 0x4(%rax), %edx
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
callq 0x10433c
jmp 0x10432b
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq