// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: detect_tip2(flex_asg_t*, unsigned int, asg64_v*, float)
uint32_t detect_tip2(flex_asg_t *fg, uint32_t id, asg64_v *st, float ou_rat)
{
    uint32_t v, w, kw, ou_max, mm_ou; asg_arc_t *sv, *sw;
    flex_asg_e_retrive_t rv, rw;
    v = id<<1; rv.i[0] = 0; rv.i[1] = (uint32_t)-1;
    while(1) {
        sv = iter_flex_asg(fg, &rv, v);
        if(!sv) break;
        if(sv->del) continue;
        w = sv->v^1;
        if(fg->g->seq_vis[w]&128) continue;
        if(fg->g->seq_vis[w>>1]&2) continue;
        
        rw.i[0] = 0; rw.i[1] = (uint32_t)-1; kw = 0; ou_max = mm_ou = 0;
        while(1) {
            sw = iter_flex_asg(fg, &rw, w);
            if(!sw) break;
            if(sw->del) continue;
            if(ou_max < sw->ou) ou_max = sw->ou;
            if(fg->g->seq_vis[sw->v>>1]&2) {
                if(mm_ou < sw->ou) mm_ou = sw->ou;
                continue;
            }
            kw++;
        }
        if(kw < 1) return 1;
        if(ou_rat >= 0 && mm_ou > ou_max*ou_rat) return 1;
        fg->g->seq_vis[w] |= 128; kv_push(uint64_t, *st, w);
    }

    v = (id<<1)+1; rv.i[0] = 0; rv.i[1] = (uint32_t)-1;
    while(1) {
        sv = iter_flex_asg(fg, &rv, v);
        if(!sv) break;
        if(sv->del) continue;
        w = sv->v^1;
        if(fg->g->seq_vis[w]&128) continue;
        if(fg->g->seq_vis[w>>1]&2) continue;
        
        rw.i[0] = 0; rw.i[1] = (uint32_t)-1; kw = 0; ou_max = mm_ou = 0;
        while(1) {
            sw = iter_flex_asg(fg, &rw, w);
            if(!sw) break;
            if(sw->del) continue;
            if(ou_max < sw->ou) ou_max = sw->ou;
            if(fg->g->seq_vis[sw->v>>1]&2) {
                if(mm_ou < sw->ou) mm_ou = sw->ou;
                continue;
            }
            kw++;
        }
        if(kw < 1) return 1;
        if(ou_rat >= 0 && mm_ou > ou_max*ou_rat) return 1;
        fg->g->seq_vis[w] |= 128; kv_push(uint64_t, *st, w);
    }

    // av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
    // for (i = 0; i < nv; ++i) {
    //     if(av[i].del) continue;
    //     w = av[i].v^1;
    //     if(g->seq_vis[w]&128) continue;
    //     if((g->seq_vis[w>>1]&3)==2) continue;
    //     aw = asg_arc_a(g, w); nw = asg_arc_n(g, w);
    //     for (k = kw = 0; k < nw && kw < 1; k++) {
    //         if(aw[k].del) continue;
    //         if((g->seq_vis[aw[k].v>>1]&3)==2) continue;
    //         kw++;
    //     }
    //     if(kw < 1) return 1;
    //     g->seq_vis[w] |= 128; kv_push(uint64_t, *st, w);
    // }


    // v = (id<<1)+1;
    // av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
    // for (i = 0; i < nv; ++i) {
    //     if(av[i].del) continue;
    //     w = av[i].v^1;
    //     if(g->seq_vis[w]&128) continue;
    //     if((g->seq_vis[w>>1]&3)==2) continue;
    //     aw = asg_arc_a(g, w); nw = asg_arc_n(g, w);
    //     for (k = kw = 0; k < nw && kw < 1; k++) {
    //         if(aw[k].del) continue;
    //         if((g->seq_vis[aw[k].v>>1]&3)==2) continue;
    //         kw++;
    //     }
    //     if(kw < 1) return 1;
    //     g->seq_vis[w] |= 128; kv_push(uint64_t, *st, w);
    // }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movss %xmm0, 0xc(%rsp)
movq %rdx, 0x20(%rsp)
movl %esi, %ebp
movq %rdi, %r14
addl %esi, %ebp
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f553d
leaq 0x10(%rsp), %r15
movl %ebp, 0x8(%rsp)
cmpl $0x0, 0xc(%rax)
js 0x1f5525
movl 0x8(%rax), %eax
movq %rax, %r13
xorq $0x1, %r13
movq 0x30(%r14), %rcx
movq 0x30(%rcx), %r12
movb (%r12,%r13), %bl
testb %bl, %bl
js 0x1f5525
shrl %eax
testb $0x2, (%r12,%rax)
jne 0x1f5525
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movl $0x0, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f549b
cmpl $0x0, 0xc(%rax)
js 0x1f5454
movzwl 0x10(%rax), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
cmpl %ecx, %ebp
cmovbel %ecx, %ebp
movl 0x8(%rax), %eax
shrl %eax
testb $0x2, (%r12,%rax)
je 0x1f5495
movl (%rsp), %eax
cmpl %ecx, %eax
cmovbel %ecx, %eax
movl %eax, (%rsp)
jmp 0x1f5454
incl 0x4(%rsp)
jmp 0x1f5454
movl $0x1, %eax
cmpl $0x0, 0x4(%rsp)
je 0x1f56aa
movss 0xc(%rsp), %xmm2
ucomiss 0x50018(%rip), %xmm2    # 0x2454d0
jb 0x1f54d6
xorps %xmm0, %xmm0
cvtsi2ssl (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ebp, %xmm1
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1f56aa
orb $-0x80, %bl
movb %bl, (%r12,%r13)
movq 0x20(%rsp), %rbx
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x1f5516
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movl 0x8(%rsp), %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r13, (%rax,%rcx,8)
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
jne 0x1f53ff
orl $0x1, %ebp
leaq 0x18(%rsp), %rsi
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, (%rsi)
movq %r14, %rdi
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f56a8
leaq 0x10(%rsp), %r15
movl %ebp, 0x8(%rsp)
cmpl $0x0, 0xc(%rax)
js 0x1f5690
movl 0x8(%rax), %eax
movq %rax, %r13
xorq $0x1, %r13
movq 0x30(%r14), %rcx
movq 0x30(%rcx), %r12
movb (%r12,%r13), %bl
testb %bl, %bl
js 0x1f5690
shrl %eax
testb $0x2, (%r12,%rax)
jne 0x1f5690
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movl $0x0, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f560a
cmpl $0x0, 0xc(%rax)
js 0x1f55c3
movzwl 0x10(%rax), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
cmpl %ecx, %ebp
cmovbel %ecx, %ebp
movl 0x8(%rax), %eax
shrl %eax
testb $0x2, (%r12,%rax)
je 0x1f5604
movl (%rsp), %eax
cmpl %ecx, %eax
cmovbel %ecx, %eax
movl %eax, (%rsp)
jmp 0x1f55c3
incl 0x4(%rsp)
jmp 0x1f55c3
movl $0x1, %eax
cmpl $0x0, 0x4(%rsp)
je 0x1f56aa
movss 0xc(%rsp), %xmm2
ucomiss 0x4fea9(%rip), %xmm2    # 0x2454d0
jb 0x1f5641
xorps %xmm0, %xmm0
cvtsi2ssl (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ebp, %xmm1
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1f56aa
orb $-0x80, %bl
movb %bl, (%r12,%r13)
movq 0x20(%rsp), %rbx
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x1f5681
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movl 0x8(%rsp), %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r13, (%rax,%rcx,8)
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
jne 0x1f556e
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq