// File: /workspace/github_cpp_makefile_star2_O1/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 0x146e5b
movl $0x1, (%rax)
movq 0xa0(%rsp), %rbx
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)
jne 0x146eb3
movq $0x2, 0x8(%r8)
movq 0x10(%r8), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x98(%rsp), %r8
movq %rax, 0x10(%r8)
movq (%r8), %rax
movq 0x10(%r8), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r8)
movl 0xc(%rsp), %edi
movl %edi, (%rcx,%rax,4)
testq %rbx, %rbx
je 0x146ed4
movq $0x0, (%rbx)
movq (%r8), %rax
testq %rax, %rax
movq 0x90(%rsp), %r9
je 0x1472de
movl %edi, %ecx
shrl %ecx
movl %ecx, 0x2c(%rsp)
movl 0x10(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x50(%rsp)
movl %r14d, %edx
movl 0x14(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x48(%rsp)
shrl %edx
movl %edx, 0x28(%rsp)
xorl %ecx, %ecx
movq $0x0, 0x18(%rsp)
cmpl $-0x1, %r14d
setne %dl
leaq -0x1(%rax), %rsi
movq %rsi, (%r8)
movq 0x10(%r8), %rsi
movl -0x4(%rsi,%rax,4), %r13d
cmpl %edi, %r13d
sete %sil
cmpl %r14d, %r13d
sete %al
testb %sil, %cl
jne 0x147348
andb %al, %dl
jne 0x147348
movl %r13d, %ebp
cmpb $0x0, (%r9,%rbp)
jne 0x146f79
movq %rbp, %rax
xorq $0x1, %rax
cmpb $0x0, (%r9,%rax)
je 0x14718a
cmpb $0x0, (%r9,%rbp)
setne %al
movl %r13d, %ecx
xorl %edi, %ecx
cmpl $0x1, %ecx
sete %cl
orb %al, %cl
jne 0x14707e
cmpl $-0x1, %r14d
je 0x146fa9
movl %r13d, %eax
xorl %r14d, %eax
cmpl $0x1, %eax
je 0x14707e
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 0x14707e
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), %r12
xorl %ebx, %ebx
cmpl $0x0, 0x4(%r15,%rbx)
js 0x147071
cmpl $-0x1, %r14d
setne %cl
movl (%r15,%rbx), %eax
cmpl %r14d, %eax
sete %dl
cmpl %edi, %eax
je 0x147348
andb %dl, %cl
jne 0x147348
cmpb $0x0, (%r9,%rax)
jne 0x147071
movq 0x8(%r8), %rax
cmpq %rax, (%r8)
jne 0x14705c
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r8)
movq 0x10(%r8), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x90(%rsp), %r9
movq 0x98(%rsp), %r8
movl 0xc(%rsp), %edi
movq %rax, 0x10(%r8)
movl (%r15,%rbx), %eax
movq (%r8), %rcx
movq 0x10(%r8), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r8)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0x146fea
cmpl %edi, %r13d
sete %al
movb $0x1, (%r9,%rbp)
xorq $0x1, %rbp
cmpb $0x0, (%r9,%rbp)
setne %cl
orb %al, %cl
jne 0x147172
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 0x147172
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), %r12
xorl %ebx, %ebx
cmpl $0x0, 0x4(%r15,%rbx)
js 0x147165
cmpl $-0x1, %r14d
setne %cl
movl (%r15,%rbx), %eax
cmpl %r14d, %eax
sete %dl
cmpl %edi, %eax
je 0x147348
andb %dl, %cl
jne 0x147348
cmpb $0x0, (%r9,%rax)
jne 0x147165
movq 0x8(%r8), %rax
cmpq %rax, (%r8)
jne 0x147150
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r8)
movq 0x10(%r8), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x90(%rsp), %r9
movq 0x98(%rsp), %r8
movl 0xc(%rsp), %edi
movq %rax, 0x10(%r8)
movl (%r15,%rbx), %eax
movq (%r8), %rcx
movq 0x10(%r8), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r8)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %rbx
cmpq %rbx, %r12
jne 0x1470de
movb $0x1, (%r9,%rbp)
movq (%r8), %rax
movb $0x1, %cl
testq %rax, %rax
jne 0x146f28
jmp 0x147359
cmpl $-0x1, %r14d
setne %al
movl %ebp, %ebx
shrl %ebx
cmpl 0x28(%rsp), %ebx
sete %cl
cmpl 0x2c(%rsp), %ebx
je 0x146f79
andb %cl, %al
jne 0x146f79
movq 0xa0(%rsp), %rcx
testq %rcx, %rcx
je 0x14721b
movq 0x8(%rcx), %rax
cmpq %rax, (%rcx)
jne 0x147201
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rcx)
movq 0x10(%rcx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0xa0(%rsp), %rcx
movq 0x90(%rsp), %r9
movq 0x98(%rsp), %r8
movq %rax, 0x10(%rcx)
movq (%rcx), %rax
movq 0x10(%rcx), %rcx
leaq 0x1(%rax), %rdx
movq 0xa0(%rsp), %rsi
movq %rdx, (%rsi)
movl %r13d, (%rcx,%rax,4)
cmpq $0x0, 0xa8(%rsp)
movq 0xb0(%rsp), %rax
je 0x147247
testq %rax, %rax
je 0x147247
movq 0xa8(%rsp), %rcx
cmpb $0x0, (%rcx,%rbx)
je 0x147247
movl $0x0, (%rax)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1472d5
movl %ebx, %esi
callq 0x146d7f
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 0x147348
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 0x1472b7
ucomisd 0x48(%rsp), %xmm1
movl 0x14(%rsp), %ecx
jae 0x14734a
mulsd 0x30(%rsp), %xmm0
addl 0x10(%rsp), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jb 0x146f79
jmp 0x14734a
movl 0xc(%rsp), %edi
jmp 0x146f79
xorpd %xmm0, %xmm0
cmpq $0x0, 0x40(%rsp)
je 0x147341
movsd 0x38(%rsp), %xmm3
mulsd %xmm0, %xmm3
movl 0x10(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm3
jae 0x147348
xorl %eax, %eax
movl $0x0, %ecx
cmpl $-0x1, %r14d
je 0x147329
movl 0x14(%rsp), %edx
movl %edx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm3
movl %edx, %ecx
jae 0x147348
mulsd 0x30(%rsp), %xmm0
addl 0x10(%rsp), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jae 0x14734a
movl $0x1, %eax
jmp 0x14734a
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 0x1472e2