// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x1ba520
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1de3bf
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl -0x40(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x1de389
jmp 0x1de3b4
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1de362
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1de456
movq 0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1de41b
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x58(%rbp)
jmp 0x1de426
movl $0x2, %eax
movq %rax, -0x58(%rbp)
jmp 0x1de426
movq -0x58(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x1c(%rbp), %edx
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x44(%rbp)
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x1de7f1
movq 0x10(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rcx
movq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1de4db
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1de4db
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1de654
movl -0x30(%rbp), %eax
movl -0x1c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1de654
cmpl $-0x1, -0x20(%rbp)
je 0x1de517
movl -0x30(%rbp), %eax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1de654
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x1de652
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1de58b
jmp 0x1de644
movq -0x28(%rbp), %rax
movq -0x50(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1de5ab
jmp 0x1de644
jmp 0x1de5ad
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1de615
movq 0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1de5da
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x1de5e5
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x1de5e5
movq -0x60(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x1de644
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1de561
jmp 0x1de654
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl -0x30(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1de7e1
movl -0x30(%rbp), %eax
movl -0x1c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1de7e1
cmpl $-0x1, -0x20(%rbp)
je 0x1de6a4
movl -0x30(%rbp), %eax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1de7e1
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x1de7df
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1de718
jmp 0x1de7d1
movq -0x28(%rbp), %rax
movq -0x50(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1de738
jmp 0x1de7d1
jmp 0x1de73a
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1de7a2
movq 0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1de767
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x1de772
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x1de772
movq -0x68(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x1de7d1
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1de6ee
jmp 0x1de7e1
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
movb $0x1, (%rax,%rcx)
jmp 0x1de47c
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
je 0x1de80a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x20(%rbp)
je 0x1de819
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jbe 0x1de883
cmpq $0x0, 0x18(%rbp)
je 0x1de87a
cmpq $0x0, 0x20(%rbp)
je 0x1de87a
cmpl $-0x1, -0x1c(%rbp)
je 0x1de87a
cmpl $-0x1, -0x20(%rbp)
je 0x1de87a
movq 0x20(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq 0x18(%rbp), %rdi
movq 0x20(%rbp), %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq 0x20(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0x1de8a0
movl $0x0, -0x4(%rbp)
jmp 0x1de88a
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)