// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
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)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movl %r9d, -0x38(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x1e0950
movq 0x30(%rbp), %rax
movl $0x1, (%rax)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x4c(%rbp)
movq $0x0, -0x58(%rbp)
movq 0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x2100
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1e09f9
movq 0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1e09be
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x1e09c9
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x1e09c9
movq -0x60(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x1c(%rbp), %edx
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
cmpq $0x0, 0x20(%rbp)
je 0x1e0a2a
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0x1e0a2c
movq 0x18(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x1e105b
movq 0x18(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x1e0a77
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x1e0a77
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
cmpl $-0x1, -0x20(%rbp)
je 0x1e0a91
movl -0x3c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x1e0a91
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1e0c80
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1e0c80
movl -0x3c(%rbp), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0x1e0c7e
cmpl $-0x1, -0x20(%rbp)
je 0x1e0ae8
movl -0x3c(%rbp), %eax
shrl %eax
movl -0x20(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
je 0x1e0c7e
cmpq $0x0, 0x20(%rbp)
je 0x1e0b7e
jmp 0x1e0af5
movq 0x20(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1e0b5d
movq 0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1e0b22
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x1e0b2d
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x1e0b2d
movq -0x68(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x3c(%rbp), %edx
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x1e0b7e
cmpq $0x0, 0x28(%rbp)
je 0x1e0baa
movq 0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x1e0baa
cmpq $0x0, 0x30(%rbp)
je 0x1e0baa
movq 0x30(%rbp), %rax
movl $0x0, (%rax)
cmpq $0x0, -0x10(%rbp)
je 0x1e0c7c
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
shrl %esi
callq 0x1e0800
movl %eax, %ecx
movl -0x40(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movl -0x34(%rbp), %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e0bf8
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
cmpl $-0x1, -0x20(%rbp)
je 0x1e0c29
movl -0x40(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movl -0x38(%rbp), %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e0c29
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
movl -0x40(%rbp), %eax
cvtsi2sd %rax, %xmm0
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $-0x1, -0x20(%rbp)
je 0x1e0c4f
movl -0x38(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x1e0c56
xorl %eax, %eax
movl %eax, -0x7c(%rbp)
jmp 0x1e0c56
movsd -0x78(%rbp), %xmm0
movl -0x6c(%rbp), %eax
movl -0x7c(%rbp), %ecx
addl %ecx, %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e0c7a
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
jmp 0x1e0c7c
jmp 0x1e0c7e
jmp 0x1e0c80
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1e0e58
movl -0x3c(%rbp), %eax
movl -0x1c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1e0e58
cmpl $-0x1, -0x20(%rbp)
je 0x1e0cbc
movl -0x3c(%rbp), %eax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1e0e58
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x1e0e56
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1e0d3c
jmp 0x1e0e48
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x1e0d5e
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
cmpl $-0x1, -0x20(%rbp)
je 0x1e0d86
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x1e0d86
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
movq 0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1e0da6
jmp 0x1e0e48
jmp 0x1e0da8
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1e0e19
movq 0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1e0dd8
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0x1e0de6
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0x1e0de6
movq -0x88(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x1e0e48
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1e0d12
jmp 0x1e0e58
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl -0x3c(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1e1044
movl -0x3c(%rbp), %eax
movl -0x1c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1e1044
cmpl $-0x1, -0x20(%rbp)
je 0x1e0ea8
movl -0x3c(%rbp), %eax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x1e1044
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x1e1042
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1e0f28
jmp 0x1e1034
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x1e0f4a
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
cmpl $-0x1, -0x20(%rbp)
je 0x1e0f72
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x1e0f72
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
movq 0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1e0f92
jmp 0x1e1034
jmp 0x1e0f94
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1e1005
movq 0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1e0fc4
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x1e0fd2
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x1e0fd2
movq -0x90(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x1e1034
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1e0efe
jmp 0x1e1044
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl $0x1, -0x4c(%rbp)
jmp 0x1e0a2c
cmpq $0x0, -0x10(%rbp)
je 0x1e1124
movl -0x40(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movl -0x34(%rbp), %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e1091
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
cmpl $-0x1, -0x20(%rbp)
je 0x1e10bf
movl -0x40(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
movl -0x38(%rbp), %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e10bf
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
movl -0x40(%rbp), %eax
cvtsi2sd %rax, %xmm0
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpl $-0x1, -0x20(%rbp)
je 0x1e10ee
movl -0x38(%rbp), %eax
movl %eax, -0xa4(%rbp)
jmp 0x1e10f8
xorl %eax, %eax
movl %eax, -0xa4(%rbp)
jmp 0x1e10f8
movsd -0xa0(%rbp), %xmm0
movl -0x94(%rbp), %eax
movl -0xa4(%rbp), %ecx
addl %ecx, %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e1122
movl $0x0, -0x4(%rbp)
jmp 0x1e112b
jmp 0x1e1124
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)