// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movl %r8d, %ebx
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0x40(%rsp)
movl %ecx, %r14d
movl %edx, %r15d
movq %rsi, 0x18(%rsp)
movq %rdi, 0x48(%rsp)
movq 0xb0(%rsp), %rax
movq 0x90(%rsp), %rdi
testq %rax, %rax
je 0x105420
movl $0x1, (%rax)
movq 0x18(%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
andq $0x0, (%r8)
cmpq $0x0, 0x8(%r8)
je 0x105453
movq 0x10(%r8), %rax
xorl %ecx, %ecx
jmp 0x105476
movq $0x2, 0x8(%r8)
movq 0x10(%r8), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq 0x98(%rsp), %r8
movq %rax, 0x10(%r8)
movq (%r8), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r8)
movl %r15d, (%rax,%rcx,4)
movq 0xa0(%rsp), %rax
testq %rax, %rax
movq 0x90(%rsp), %rdi
je 0x10549a
andq $0x0, (%rax)
movl %r15d, %eax
shrl %eax
movl %eax, 0x24(%rsp)
movl %ebx, 0xc(%rsp)
movl %ebx, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x38(%rsp)
movl %r14d, %ecx
movl %ebp, 0x8(%rsp)
movl %ebp, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x28(%rsp)
shrl %ecx
movl %ecx, 0x20(%rsp)
xorl %ebp, %ebp
xorl %eax, %eax
movq (%r8), %rdx
testq %rdx, %rdx
je 0x10584f
cmpl $-0x1, %r14d
setne %cl
leaq -0x1(%rdx), %rsi
movq %rsi, (%r8)
movq 0x10(%r8), %rsi
movl -0x4(%rsi,%rdx,4), %r13d
cmpl %r15d, %r13d
sete %sil
cmpl %r14d, %r13d
sete %dl
testb %sil, %al
jne 0x1058a3
andb %dl, %cl
jne 0x1058a3
movl %r13d, %r12d
cmpb $0x0, (%rdi,%r12)
jne 0x10552e
movq %r12, %rax
xorq $0x1, %rax
cmpb $0x0, (%rdi,%rax)
je 0x105720
movl %ebp, %edx
movq %rdx, 0x50(%rsp)
movq %r12, 0x10(%rsp)
cmpb $0x0, (%rdi,%r12)
setne %al
movl %r13d, %ecx
xorl %r15d, %ecx
cmpl $0x1, %ecx
sete %cl
orb %al, %cl
jne 0x10556b
cmpl $-0x1, %r14d
je 0x10565b
movl %r13d, %eax
xorl %r14d, %eax
cmpl $0x1, %eax
jne 0x10565b
cmpl %r15d, %r13d
sete %al
movq 0x10(%rsp), %rbp
movb $0x1, (%rdi,%rbp)
xorq $0x1, %rbp
cmpb $0x0, (%rdi,%rbp)
setne %cl
orb %al, %cl
je 0x10559b
movb $0x1, (%rdi,%rbp)
movb $0x1, %al
movq 0x50(%rsp), %rcx
movl %ecx, %ebp
jmp 0x1054d2
movb $0x1, (%rdi,%rbp)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movq (%rax,%rbp,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %r12
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %rbx
addq $0x8, %rbx
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x105589
cmpl $0x0, 0x4(%rbx,%r13)
js 0x105652
cmpl $-0x1, %r14d
setne %al
movl (%rbx,%r13), %ecx
cmpl %r14d, %ecx
sete %dl
cmpl %r15d, %ecx
je 0x1058a3
andb %dl, %al
jne 0x1058a3
cmpb $0x0, (%rdi,%rcx)
jne 0x105652
movq (%r8), %rdx
movq 0x10(%r8), %rax
cmpq 0x8(%r8), %rdx
jne 0x105648
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %r8
movq %rax, 0x10(%r8)
movl (%rbx,%r13), %ecx
movq (%r8), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r8)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r13
jmp 0x1055cd
movq 0x10(%rsp), %rdx
movb $0x1, (%rdi,%rdx)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rax), %rax
movq (%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %r12
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %rbx
addq $0x8, %rbx
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x10556b
cmpl $0x0, 0x4(%rbx,%rbp)
js 0x105717
cmpl $-0x1, %r14d
setne %al
movl (%rbx,%rbp), %ecx
cmpl %r14d, %ecx
sete %dl
cmpl %r15d, %ecx
je 0x1058a3
andb %dl, %al
jne 0x1058a3
cmpb $0x0, (%rdi,%rcx)
jne 0x105717
movq (%r8), %rdx
movq 0x10(%r8), %rax
cmpq 0x8(%r8), %rdx
jne 0x10570d
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %r8
movq %rax, 0x10(%r8)
movl (%rbx,%rbp), %ecx
movq (%r8), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r8)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbp
jmp 0x105691
cmpl $-0x1, %r14d
setne %al
movl %r12d, %esi
shrl %esi
cmpl 0x20(%rsp), %esi
sete %cl
cmpl 0x24(%rsp), %esi
je 0x10552e
andb %cl, %al
jne 0x10552e
movq 0xa0(%rsp), %rbx
testq %rbx, %rbx
je 0x1057a1
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x105796
movq %rsi, 0x10(%rsp)
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %rsi
movq 0x98(%rsp), %r8
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movl %r13d, (%rax,%rcx,4)
cmpq $0x0, 0xa8(%rsp)
movq 0xb0(%rsp), %rax
je 0x1057ca
testq %rax, %rax
je 0x1057ca
movq 0xa8(%rsp), %rcx
cmpb $0x0, (%rcx,%rsi)
je 0x1057ca
andl $0x0, (%rax)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x105840
callq 0x10535b
movl %eax, %edx
addl %ebp, %edx
cvtsi2sd %rdx, %xmm0
movapd %xmm0, %xmm1
mulsd 0x40(%rsp), %xmm1
ucomisd 0x38(%rsp), %xmm1
jae 0x1058a3
xorl %eax, %eax
movl $0x0, %ecx
cmpl $-0x1, %r14d
movq 0x98(%rsp), %r8
movq 0x90(%rsp), %rdi
je 0x105825
ucomisd 0x28(%rsp), %xmm1
movl 0x8(%rsp), %ecx
jae 0x1058a5
mulsd 0x30(%rsp), %xmm0
addl 0xc(%rsp), %ecx
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jb 0x105530
jmp 0x1058a5
movl %ebp, %edx
movq 0x90(%rsp), %rdi
jmp 0x105530
cmpq $0x0, 0x48(%rsp)
je 0x10589e
movl %ebp, %eax
cvtsi2sd %rax, %xmm0
movsd 0x40(%rsp), %xmm2
mulsd %xmm0, %xmm2
ucomisd 0x38(%rsp), %xmm2
jae 0x1058a3
xorl %eax, %eax
movl $0x0, %ecx
cmpl $-0x1, %r14d
je 0x105889
ucomisd 0x28(%rsp), %xmm2
movl 0x8(%rsp), %ecx
jae 0x1058a3
mulsd 0x30(%rsp), %xmm0
addl 0xc(%rsp), %ecx
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jae 0x1058a5
pushq $0x1
popq %rax
jmp 0x1058a5
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq