// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
addl %esi, %ebp
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x18(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x10(%rsp), %r13
movl %ebp, 0x8(%rsp)
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
movl %ebp, %edx
callq 0x1aa378
testq %rax, %rax
je 0x1aa540
cmpl $0x0, 0xc(%rax)
js 0x1aa415
movl 0x8(%rax), %eax
movq %rax, %rbx
xorq $0x1, %rbx
movq 0x30(%r15), %rcx
movq 0x30(%rcx), %r12
movb (%r12,%rbx), %r14b
testb %r14b, %r14b
js 0x1aa415
shrl %eax
testb $0x2, (%r12,%rax)
jne 0x1aa415
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movl $0x0, (%rsp)
movq %r15, %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x1aa378
testq %rax, %rax
je 0x1aa4bd
cmpl $0x0, 0xc(%rax)
js 0x1aa477
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 0x1aa4b7
movl (%rsp), %eax
cmpl %ecx, %eax
cmovbel %ecx, %eax
movl %eax, (%rsp)
jmp 0x1aa477
incl 0x4(%rsp)
jmp 0x1aa477
cmpl $0x0, 0x4(%rsp)
je 0x1aa685
movss 0xc(%rsp), %xmm2
ucomiss 0x4cec3(%rip), %xmm2    # 0x1f7398
jb 0x1aa4ed
cvtsi2ssl (%rsp), %xmm0
cvtsi2ss %ebp, %xmm1
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1aa685
orb $-0x80, %r14b
movb %r14b, (%r12,%rbx)
movq 0x20(%rsp), %r14
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x1aa52c
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movl 0x8(%rsp), %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movq %rbx, (%rax,%rcx,8)
jmp 0x1aa415
orl $0x1, %ebp
leaq 0x18(%rsp), %rcx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, (%rcx)
leaq 0x10(%rsp), %r13
movl %ebp, 0x8(%rsp)
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
movl %ebp, %edx
callq 0x1aa378
testq %rax, %rax
je 0x1aa681
cmpl $0x0, 0xc(%rax)
js 0x1aa55e
movl 0x8(%rax), %eax
movq %rax, %rbx
xorq $0x1, %rbx
movq 0x30(%r15), %rcx
movq 0x30(%rcx), %r12
movb (%r12,%rbx), %r14b
testb %r14b, %r14b
js 0x1aa55e
shrl %eax
testb $0x2, (%r12,%rax)
jne 0x1aa55e
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movl $0x0, (%rsp)
movq %r15, %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x1aa378
testq %rax, %rax
je 0x1aa606
cmpl $0x0, 0xc(%rax)
js 0x1aa5c0
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 0x1aa600
movl (%rsp), %eax
cmpl %ecx, %eax
cmovbel %ecx, %eax
movl %eax, (%rsp)
jmp 0x1aa5c0
incl 0x4(%rsp)
jmp 0x1aa5c0
cmpl $0x0, 0x4(%rsp)
je 0x1aa685
movss 0xc(%rsp), %xmm2
ucomiss 0x4cd7e(%rip), %xmm2    # 0x1f7398
jb 0x1aa62e
cvtsi2ssl (%rsp), %xmm0
cvtsi2ss %ebp, %xmm1
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1aa685
orb $-0x80, %r14b
movb %r14b, (%r12,%rbx)
movq 0x20(%rsp), %r14
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x1aa66d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movl 0x8(%rsp), %ebp
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movq %rbx, (%rax,%rcx,8)
jmp 0x1aa55e
xorl %eax, %eax
jmp 0x1aa688
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq