// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, %rbx
xorps %xmm1, %xmm1
leaq 0x60(%rsp), %rdi
andq $0x0, 0x10(%rdi)
leaq 0x40(%rsp), %r9
andq $0x0, 0x10(%r9)
leaq 0xc(%rsp), %rax
orl $-0x1, (%rax)
movaps %xmm1, (%rdi)
movaps %xmm1, (%r9)
movq 0x30(%rbx), %rax
movl 0x14(%rax), %r14d
addl %r14d, %r14d
testq %rsi, %rsi
movq %rsi, 0x20(%rsp)
cmovneq %rsi, %rdi
testq %rdx, %rdx
movq %rdx, 0x18(%rsp)
cmovneq %rdx, %r9
movl %r8d, 0x14(%rsp)
movq %r9, 0x30(%rsp)
andq $0x0, (%r9)
movss %xmm0, 0x10(%rsp)
movq %rdi, 0x38(%rsp)
andq $0x0, (%rdi)
movq %rcx, %rbp
andq $0x0, 0x60(%rbx)
andq $0x0, 0x40(%rbx)
movq 0x38(%rbx), %rdi
movl 0x14(%rax), %eax
addl %eax, %eax
movslq %eax, %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x20e0
andq $0x0, 0x20(%rbx)
movq 0x30(%rbx), %rax
movq 0x30(%rax), %rdi
xorl %r13d, %r13d
xorl %esi, %esi
movq %r14, %rdx
callq 0x20e0
leaq 0x58(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
cmpl %r13d, %r14d
je 0x1ab733
movq 0x30(%rbx), %r12
movq 0x20(%r12), %rcx
movl %r13d, %eax
shrl %eax
cmpl $0x0, (%rcx,%rax,8)
js 0x1ab72b
cmpq %rax, (%rbp)
jbe 0x1ab72b
movq 0x8(%rbp), %rcx
cmpl $0x0, (%rcx,%rax,4)
js 0x1ab72b
movl %r13d, %esi
xorl $0x1, %esi
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
pushq $0x1
popq %rcx
callq 0x1a5473
cmpl $0x1, %eax
jne 0x1ab705
movl 0xc(%rsp), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq $0x8, %r12
testl %eax, %eax
cmovsq 0x28(%rsp), %r12
movq (%r12), %rax
imulq $0x18, %rcx, %rcx
movl 0x8(%rax,%rcx), %esi
xorl $0x1, %esi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5473
cmpl $0x1, %eax
je 0x1ab72b
movq %rbp, %rdi
movq %rbx, %rsi
movl %r13d, %edx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movss 0x10(%rsp), %xmm0
movl 0x14(%rsp), %r9d
callq 0x1ab025
addl %eax, %r15d
incl %r13d
jmp 0x1ab67d
cmpq $0x0, 0x20(%rsp)
jne 0x1ab745
movq 0x70(%rsp), %rdi
callq 0x2220
cmpq $0x0, 0x18(%rsp)
jne 0x1ab757
movq 0x50(%rsp), %rdi
callq 0x2220
testl %r15d, %r15d
je 0x1ab764
movq %rbx, %rdi
callq 0x1ab4cd
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq