// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: check_bubble_tangle(bubble_type*, ma_ug_t*, unsigned int, unsigned int, double, double, unsigned int, unsigned int, unsigned char*, kvec_t_u32_warp*, kvec_t_u32_warp*, unsigned char*, unsigned int*)
int check_bubble_tangle(bubble_type* bub, ma_ug_t* ug, uint32_t beg, uint32_t sink, 
double side_rate, double total_rate, uint32_t beg_occ, uint32_t sink_occ, 
uint8_t* is_vis, kvec_t_u32_warp* stack, kvec_t_u32_warp* res, uint8_t* chain_flag,
uint32_t* extra_check)
{
    if(extra_check) (*extra_check) = 1;
    uint32_t cur, tan_occ = 0, ncur, i, no_first = 0;
    asg_arc_t *acur = NULL;
    memset(is_vis, 0, ug->g->n_seq<<1);
    stack->a.n = 0;
    kv_push(uint32_t, stack->a, beg);
    if(res) res->a.n = 0;
    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        
        if(no_first && cur == beg) return 0;
        if(sink != (uint32_t)-1 && cur == sink) return 0;


        if(is_vis[cur] == 0 && is_vis[cur^1] == 0)
        {
            if((cur>>1) != (beg>>1) && (sink == (uint32_t)-1 || (cur>>1) != (sink>>1)))
            {
                if(res) kv_push(uint32_t, res->a, cur);
                if(chain_flag && chain_flag[cur>>1] != 0 && extra_check)
                {
                    (*extra_check) = 0;
                } 
                
                if(bub)
                {
                    tan_occ += get_btg_occ(bub, cur>>1);
                    if(tan_occ*side_rate >= beg_occ) return 0;
                    if(sink != (uint32_t)-1 && (tan_occ*side_rate >= sink_occ)) return 0;
                    if(tan_occ*total_rate >= (beg_occ + ((sink != (uint32_t)-1)?sink_occ : 0))) return 0;
                }
            }
        }
        

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

                if(acur[i].v == beg) return 0;
                if(sink != (uint32_t)-1 && acur[i].v == sink) return 0;

                if(is_vis[acur[i].v]) continue;
                kv_push(uint32_t, stack->a, acur[i].v);
            }
        }
        is_vis[cur] = 1;
        

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

                if(acur[i].v == beg) return 0;
                if(sink != (uint32_t)-1 && acur[i].v == sink) return 0;

                if(is_vis[acur[i].v]) continue;
                kv_push(uint32_t, stack->a, acur[i].v);
            }
        }
        is_vis[cur] = 1;
        no_first = 1;
    }

    if(bub)
    {
        if(tan_occ*side_rate >= beg_occ) return 0;
        if(sink != (uint32_t)-1 && (tan_occ*side_rate >= sink_occ)) return 0;
        if(tan_occ*total_rate >= (beg_occ + ((sink != (uint32_t)-1)?sink_occ : 0))) return 0;
    }
    
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, 0x14(%rsp)
movl %r8d, 0x10(%rsp)
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0x38(%rsp)
movl %ecx, %r14d
movl %edx, 0xc(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x40(%rsp)
movq 0xb0(%rsp), %rax
movq 0x90(%rsp), %rdi
testq %rax, %rax
je 0x14d4ae
movl $0x1, (%rax)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x20e0
movq 0x98(%rsp), %r8
movq $0x0, (%r8)
cmpq $0x0, 0x8(%r8)
je 0x14d4e4
movq 0x10(%r8), %rax
xorl %edx, %edx
jmp 0x14d509
movq $0x2, 0x8(%r8)
movq 0x10(%r8), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x98(%rsp), %r8
movq %rax, 0x10(%r8)
movq (%r8), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%r8)
movl 0xc(%rsp), %edi
movl %edi, (%rax,%rdx,4)
movq 0xa0(%rsp), %rax
testq %rax, %rax
movq 0x90(%rsp), %r9
je 0x14d536
movq $0x0, (%rax)
movq (%r8), %rcx
testq %rcx, %rcx
je 0x14d92a
movl %edi, %eax
shrl %eax
movl %eax, 0x2c(%rsp)
movl 0x10(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x50(%rsp)
movl %r14d, %edx
movl 0x14(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x48(%rsp)
shrl %edx
movl %edx, 0x28(%rsp)
xorl %eax, %eax
movq $0x0, 0x18(%rsp)
cmpl $-0x1, %r14d
setne %dl
leaq -0x1(%rcx), %rsi
movq %rsi, (%r8)
movq 0x10(%r8), %rsi
movl -0x4(%rsi,%rcx,4), %r13d
cmpl %edi, %r13d
sete %sil
cmpl %r14d, %r13d
sete %cl
testb %sil, %al
jne 0x14d994
andb %cl, %dl
jne 0x14d994
movl %r13d, %ebp
cmpb $0x0, (%r9,%rbp)
jne 0x14d5d0
movq %rbp, %rax
xorq $0x1, %rax
cmpb $0x0, (%r9,%rax)
je 0x14d7e1
cmpb $0x0, (%r9,%rbp)
setne %al
movl %r13d, %ecx
xorl %edi, %ecx
cmpl $0x1, %ecx
sete %cl
orb %al, %cl
jne 0x14d6d5
cmpl $-0x1, %r14d
je 0x14d600
movl %r13d, %eax
xorl %r14d, %eax
cmpl $0x1, %eax
je 0x14d6d5
movb $0x1, (%r9,%rbp)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x28(%rcx), %rax
movq (%rax,%rbp,8), %rax
testl %eax, %eax
je 0x14d6d5
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r15
addq $0x8, %r15
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
xorl %r12d, %r12d
cmpl $0x0, 0x4(%r15,%r12)
js 0x14d6c8
cmpl $-0x1, %r14d
setne %al
movl (%r15,%r12), %ecx
cmpl %r14d, %ecx
sete %dl
cmpl %edi, %ecx
je 0x14d994
andb %dl, %al
jne 0x14d994
cmpb $0x0, (%r9,%rcx)
jne 0x14d6c8
movq (%r8), %rdx
movq 0x10(%r8), %rax
cmpq 0x8(%r8), %rdx
jne 0x14d6be
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x90(%rsp), %r9
movq 0x98(%rsp), %r8
movl 0xc(%rsp), %edi
movq %rax, 0x10(%r8)
movl (%r15,%r12), %ecx
movq (%r8), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r8)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r12
cmpq %r12, %rbx
jne 0x14d642
cmpl %edi, %r13d
sete %al
movb $0x1, (%r9,%rbp)
xorq $0x1, %rbp
cmpb $0x0, (%r9,%rbp)
setne %cl
orb %al, %cl
jne 0x14d7c9
movb $0x1, (%r9,%rbp)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x28(%rcx), %rax
movq (%rax,%rbp,8), %rax
testl %eax, %eax
je 0x14d7c9
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r15
addq $0x8, %r15
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
xorl %r12d, %r12d
cmpl $0x0, 0x4(%r15,%r12)
js 0x14d7bc
cmpl $-0x1, %r14d
setne %al
movl (%r15,%r12), %ecx
cmpl %r14d, %ecx
sete %dl
cmpl %edi, %ecx
je 0x14d994
andb %dl, %al
jne 0x14d994
cmpb $0x0, (%r9,%rcx)
jne 0x14d7bc
movq (%r8), %rdx
movq 0x10(%r8), %rax
cmpq 0x8(%r8), %rdx
jne 0x14d7b2
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x90(%rsp), %r9
movq 0x98(%rsp), %r8
movl 0xc(%rsp), %edi
movq %rax, 0x10(%r8)
movl (%r15,%r12), %ecx
movq (%r8), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r8)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r12
cmpq %r12, %rbx
jne 0x14d736
movb $0x1, (%r9,%rbp)
movq (%r8), %rcx
movb $0x1, %al
testq %rcx, %rcx
jne 0x14d57f
jmp 0x14d9a5
cmpl $-0x1, %r14d
setne %al
movl %ebp, %r12d
shrl %r12d
cmpl 0x28(%rsp), %r12d
sete %cl
cmpl 0x2c(%rsp), %r12d
je 0x14d5d0
andb %cl, %al
jne 0x14d5d0
movq 0xa0(%rsp), %r15
testq %r15, %r15
movq 0xb0(%rsp), %rbx
je 0x14d865
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x14d85a
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x98(%rsp), %r8
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movl %r13d, (%rax,%rcx,4)
cmpq $0x0, 0xa8(%rsp)
je 0x14d88a
testq %rbx, %rbx
je 0x14d88a
movq 0xa8(%rsp), %rax
cmpb $0x0, (%rax,%r12)
je 0x14d88a
movl $0x0, (%rbx)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x14d919
movl %r12d, %esi
callq 0x14d3d2
movq 0x18(%rsp), %rcx
addl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movapd %xmm0, %xmm1
mulsd 0x38(%rsp), %xmm1
ucomisd 0x50(%rsp), %xmm1
jae 0x14d994
movq %rcx, 0x18(%rsp)
xorl %eax, %eax
movl $0x0, %ecx
cmpl $-0x1, %r14d
movl 0xc(%rsp), %edi
movq 0x98(%rsp), %r8
movq 0x90(%rsp), %r9
je 0x14d8fb
ucomisd 0x48(%rsp), %xmm1
movl 0x14(%rsp), %ecx
jae 0x14d996
mulsd 0x30(%rsp), %xmm0
addl 0x10(%rsp), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jb 0x14d5d0
jmp 0x14d996
movl 0xc(%rsp), %edi
movq 0x90(%rsp), %r9
jmp 0x14d5d0
xorpd %xmm0, %xmm0
cmpq $0x0, 0x40(%rsp)
je 0x14d98d
movsd 0x38(%rsp), %xmm3
mulsd %xmm0, %xmm3
movl 0x10(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm3
jae 0x14d994
xorl %eax, %eax
movl $0x0, %ecx
cmpl $-0x1, %r14d
je 0x14d975
movl 0x14(%rsp), %edx
movl %edx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm3
movl %edx, %ecx
jae 0x14d994
mulsd 0x30(%rsp), %xmm0
addl 0x10(%rsp), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jae 0x14d996
movl $0x1, %eax
jmp 0x14d996
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x18(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
jmp 0x14d92e