// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_arc_cut_contain(flex_asg_t*, asg64_v*, asg64_v*, R_to_U*, float, unsigned int)
void asg_arc_cut_contain(flex_asg_t *fg, asg64_v *in, asg64_v *in0, R_to_U* rI, float ou_rat, uint32_t only_trans_nn)
{
    // fprintf(stderr, "+[M::%s]\n", __func__);
    asg64_v tx = {0,0,0}, tx0 = {0,0,0}, *b = NULL, *b0 = NULL; 
    uint32_t v, w = (uint32_t)-1, n_vtx = fg->g->n_seq<<1, cnt = 0; asg_arc_t *s;
    b = in?in:&tx; b0 = in0?in0:&tx0; b->n = b0->n = 0; 
    fg->pi.n = fg->n = 0; memset(fg->idx, -1, (fg->g->n_seq<<1)*sizeof(*(fg->idx)));
    fg->need_srt = 0;

    memset(fg->g->seq_vis, 0, sizeof(*(fg->g->seq_vis))*n_vtx);
    for (v = 0; v < n_vtx; ++v) {
        // if((v>>1) == 6236) {
        //     fprintf(stderr, "[M::%s] v>>1::%u(%c), del::%u, contain::%u, get_arcs(v)::%u, get_arcs(v^1)::%u\n", 
        //     __func__, (v>>1), "+-"[v&1], g->seq[v>>1].del, is_contain_r((*rI), (v>>1)), 
        //     get_arcs(g, v, NULL, 0), get_arcs(g, v^1, NULL, 0));
        // }  
        // if((v>>1) == 749651) {
        //     fprintf(stderr, "+[M::%s] v>>1::%u(%c), del::%u, contain::%u, fg->n::%u, fg->need_srt::%u\n", 
        //     __func__, (v>>1), "+-"[v&1], fg->g->seq[v>>1].del, is_contain_r((*rI), (v>>1)), (uint32_t)fg->n, (uint32_t)fg->need_srt);
        // }
        if (fg->g->seq[v>>1].del) continue;
        if(!is_contain_r((*rI), (v>>1))) continue;
        if(get_flex_arcs(fg, v^1, &w, 1) == 1) {
            flex_arcs0(s, (*fg), w);
            if(get_flex_arcs(fg, s->v^1, NULL, 0) == 1) continue;
        }
        // if((v>>1) == 12321 || (v>>1) == 12334) {
        //     fprintf(stderr, "-[M::%s] v>>1::%u(%c), del::%u, contain::%u, fg->n::%u, fg->need_srt::%u\n", 
        //     __func__, (v>>1), "+-"[v&1], fg->g->seq[v>>1].del, is_contain_r((*rI), (v>>1)), (uint32_t)fg->n, (uint32_t)fg->need_srt);
        // }
        
        cnt += iter_contain_g(rI, fg, v, b, b0, ou_rat, only_trans_nn);
        // if((v>>1) == 12321 || (v>>1) == 12334) {
        //     fprintf(stderr, "*[M::%s] v>>1::%u(%c), del::%u, contain::%u, fg->n::%u, fg->need_srt::%u\n", 
        //     __func__, (v>>1), "+-"[v&1], fg->g->seq[v>>1].del, is_contain_r((*rI), (v>>1)), (uint32_t)fg->n, (uint32_t)fg->need_srt);
        // }
    }
    // stats_sysm(g);
    if(!in) free(tx.a); if(!in0) free(tx0.a);
    if(cnt > 0) flex_asg_t_cleanup(fg);
    // fprintf(stderr, "-[M::%s]\n", __func__);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r8d, 0x14(%rsp)
movss %xmm0, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rcx
movaps %xmm0, (%rcx)
xorl %r13d, %r13d
movq %r13, 0x10(%rcx)
leaq 0x40(%rsp), %rdx
movq %r13, 0x10(%rdx)
movaps %xmm0, (%rdx)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq 0x30(%rdi), %rax
movl 0x14(%rax), %r15d
addl %r15d, %r15d
testq %rsi, %rsi
movq %rsi, 0x20(%rsp)
cmovneq %rsi, %rcx
testq %r14, %r14
cmovneq %r14, %rdx
movq %rdx, 0x30(%rsp)
movq %r13, (%rdx)
movq %rcx, 0x38(%rsp)
movq %r13, (%rcx)
movq %r13, 0x60(%rdi)
movq %r13, 0x40(%rdi)
movq 0x38(%rdi), %rdi
movl 0x14(%rax), %eax
addl %eax, %eax
movslq %eax, %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x20e0
movq %r13, 0x20(%rbx)
movq 0x30(%rbx), %rax
movq 0x30(%rax), %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x20e0
testl %r15d, %r15d
je 0x1f6d37
movq %r14, 0x18(%rsp)
leaq 0x58(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
movq 0x30(%rbx), %r14
movq 0x20(%r14), %rcx
movl %ebp, %eax
shrl %eax
cmpl $0x0, (%rcx,%rax,8)
js 0x1f6d1e
cmpq %rax, (%r12)
jbe 0x1f6d1e
movq 0x8(%r12), %rcx
cmpl $0x0, (%rcx,%rax,4)
js 0x1f6d1e
movl %ebp, %esi
xorl $0x1, %esi
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
movl $0x1, %ecx
callq 0x1efb23
cmpl $0x1, %eax
jne 0x1f6cf9
movl 0xc(%rsp), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq $0x8, %r14
testl %eax, %eax
cmovsq 0x28(%rsp), %r14
movq (%r14), %rax
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,8), %esi
xorl $0x1, %esi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1efb23
cmpl $0x1, %eax
je 0x1f6d1e
movq %r12, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movss 0x10(%rsp), %xmm0
movl 0x14(%rsp), %r9d
callq 0x1f645c
addl %eax, %r13d
incl %ebp
cmpl %ebp, %r15d
jne 0x1f6c7b
testl %r13d, %r13d
sete %bpl
movq 0x18(%rsp), %r14
jmp 0x1f6d3a
movb $0x1, %bpl
cmpq $0x0, 0x20(%rsp)
jne 0x1f6d4c
movq 0x70(%rsp), %rdi
callq 0x2220
testq %r14, %r14
jne 0x1f6d5b
movq 0x50(%rsp), %rdi
callq 0x2220
testb %bpl, %bpl
jne 0x1f6d68
movq %rbx, %rdi
callq 0x1f6aad
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq