// File: /workspace/github_cpp_makefile_star2_O1/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, %ebx
movq %rdi, %r14
addl %esi, %ebx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movl %ebx, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1eaa22
leaq 0x10(%rsp), %r15
movl %ebx, 0x8(%rsp)
cmpl $0x0, 0xc(%rax)
js 0x1eaa0a
movl 0x8(%rax), %eax
movq %rax, %r13
xorq $0x1, %r13
movq 0x30(%r14), %rcx
movq 0x30(%rcx), %r12
movb (%r12,%r13), %bpl
testb %bpl, %bpl
js 0x1eaa0a
shrl %eax
testb $0x2, (%r12,%rax)
jne 0x1eaa0a
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ebx, %ebx
movl $0x0, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1ea97e
cmpl $0x0, 0xc(%rax)
js 0x1ea937
movzwl 0x10(%rax), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
cmpl %ecx, %ebx
cmovbel %ecx, %ebx
movl 0x8(%rax), %eax
shrl %eax
testb $0x2, (%r12,%rax)
je 0x1ea978
movl (%rsp), %eax
cmpl %ecx, %eax
cmovbel %ecx, %eax
movl %eax, (%rsp)
jmp 0x1ea937
incl 0x4(%rsp)
jmp 0x1ea937
movl $0x1, %eax
cmpl $0x0, 0x4(%rsp)
je 0x1eab92
movss 0xc(%rsp), %xmm2
ucomiss 0x4e865(%rip), %xmm2    # 0x239200
jb 0x1ea9b9
xorps %xmm0, %xmm0
cvtsi2ssl (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1eab92
orb $-0x80, %bpl
movb %bpl, (%r12,%r13)
movq 0x20(%rsp), %rbx
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1ea9f4
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %r13, (%rcx,%rax,8)
movl 0x8(%rsp), %ebx
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
movl %ebx, %edx
callq 0x1ea827
testq %rax, %rax
jne 0x1ea8e1
orl $0x1, %ebx
leaq 0x18(%rsp), %rsi
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, (%rsi)
movq %r14, %rdi
movl %ebx, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1eab90
leaq 0x10(%rsp), %r15
movl %ebx, 0x8(%rsp)
cmpl $0x0, 0xc(%rax)
js 0x1eab78
movl 0x8(%rax), %eax
movq %rax, %r13
xorq $0x1, %r13
movq 0x30(%r14), %rcx
movq 0x30(%rcx), %r12
movb (%r12,%r13), %bpl
testb %bpl, %bpl
js 0x1eab78
shrl %eax
testb $0x2, (%r12,%rax)
jne 0x1eab78
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ebx, %ebx
movl $0x0, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1eaaf0
cmpl $0x0, 0xc(%rax)
js 0x1eaaa9
movzwl 0x10(%rax), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
cmpl %ecx, %ebx
cmovbel %ecx, %ebx
movl 0x8(%rax), %eax
shrl %eax
testb $0x2, (%r12,%rax)
je 0x1eaaea
movl (%rsp), %eax
cmpl %ecx, %eax
cmovbel %ecx, %eax
movl %eax, (%rsp)
jmp 0x1eaaa9
incl 0x4(%rsp)
jmp 0x1eaaa9
movl $0x1, %eax
cmpl $0x0, 0x4(%rsp)
je 0x1eab92
movss 0xc(%rsp), %xmm2
ucomiss 0x4e6f3(%rip), %xmm2    # 0x239200
jb 0x1eab27
xorps %xmm0, %xmm0
cvtsi2ssl (%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1eab92
orb $-0x80, %bpl
movb %bpl, (%r12,%r13)
movq 0x20(%rsp), %rbx
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1eab62
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %r13, (%rcx,%rax,8)
movl 0x8(%rsp), %ebx
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
movl %ebx, %edx
callq 0x1ea827
testq %rax, %rax
jne 0x1eaa53
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq