// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movl -0x14(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x50(%rbp)
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %edx
leaq -0x50(%rbp), %rsi
callq 0x3190c0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x31921e
jmp 0x319448
movq -0x40(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31922f
jmp 0x3191fe
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x31925b
jmp 0x3191fe
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x31927c
jmp 0x3191fe
movl $0x0, -0x58(%rbp)
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq -0x58(%rbp), %rsi
callq 0x3190c0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x3192bf
jmp 0x319358
movq -0x48(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x3192d0
jmp 0x31929f
movl -0x34(%rbp), %eax
movq -0x48(%rbp), %rcx
movw 0x10(%rcx), %cx
andw $0x3fff, %cx            # imm = 0x3FFF
movzwl %cx, %ecx
cmpl %ecx, %eax
jae 0x3192f9
movq -0x48(%rbp), %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x31934a
movl -0x38(%rbp), %eax
movq -0x48(%rbp), %rcx
movw 0x10(%rcx), %cx
andw $0x3fff, %cx            # imm = 0x3FFF
movzwl %cx, %ecx
cmpl %ecx, %eax
jae 0x319345
movq -0x48(%rbp), %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
movl %eax, -0x38(%rbp)
jmp 0x31929f
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x31929f
cmpl $0x1, -0x30(%rbp)
jae 0x31936a
movl $0x1, -0x4(%rbp)
jmp 0x3196b2
movss -0x24(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x31939d
movl -0x38(%rbp), %eax
cvtsi2ss %rax, %xmm0
movl -0x34(%rbp), %eax
cvtsi2ss %rax, %xmm1
mulss -0x24(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x31939d
movl $0x1, -0x4(%rbp)
jmp 0x3196b2
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
movzbl (%rax,%rcx), %edx
orl $0x80, %edx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x319421
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3193e6
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x3193f1
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x3193f1
movq -0x60(%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 $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x2c(%rbp), %eax
movl %eax, %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)
movq %rdx, (%rax,%rcx,8)
jmp 0x3191fe
movl -0x14(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x50(%rbp)
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %edx
leaq -0x50(%rbp), %rsi
callq 0x3190c0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x319481
jmp 0x3196ab
movq -0x40(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x319492
jmp 0x319461
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x3194be
jmp 0x319461
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3194df
jmp 0x319461
movl $0x0, -0x58(%rbp)
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq -0x58(%rbp), %rsi
callq 0x3190c0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x319522
jmp 0x3195bb
movq -0x48(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x319533
jmp 0x319502
movl -0x34(%rbp), %eax
movq -0x48(%rbp), %rcx
movw 0x10(%rcx), %cx
andw $0x3fff, %cx            # imm = 0x3FFF
movzwl %cx, %ecx
cmpl %ecx, %eax
jae 0x31955c
movq -0x48(%rbp), %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3195ad
movl -0x38(%rbp), %eax
movq -0x48(%rbp), %rcx
movw 0x10(%rcx), %cx
andw $0x3fff, %cx            # imm = 0x3FFF
movzwl %cx, %ecx
cmpl %ecx, %eax
jae 0x3195a8
movq -0x48(%rbp), %rax
movw 0x10(%rax), %ax
andw $0x3fff, %ax            # imm = 0x3FFF
movzwl %ax, %eax
movl %eax, -0x38(%rbp)
jmp 0x319502
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x319502
cmpl $0x1, -0x30(%rbp)
jae 0x3195cd
movl $0x1, -0x4(%rbp)
jmp 0x3196b2
movss -0x24(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x319600
movl -0x38(%rbp), %eax
cvtsi2ss %rax, %xmm0
movl -0x34(%rbp), %eax
cvtsi2ss %rax, %xmm1
mulss -0x24(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x319600
movl $0x1, -0x4(%rbp)
jmp 0x3196b2
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
movzbl (%rax,%rcx), %edx
orl $0x80, %edx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x319684
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x319649
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x319654
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x319654
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 $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x2c(%rbp), %eax
movl %eax, %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)
movq %rdx, (%rax,%rcx,8)
jmp 0x319461
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)