// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl $0xffffffff, -0x70(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x31b24b
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x31b258
leaq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x31b258
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x31b277
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x31b284
leaq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x31b284
movq -0x90(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq $0x0, (%rax)
movq -0x60(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rdi
movl -0x74(%rbp), %eax
movl %eax, %edx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2100
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x31b456
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x20(%rax), %rax
movl -0x6c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31b346
jmp 0x31b448
movl -0x6c(%rbp), %eax
shrl %eax
movl %eax, %eax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x31b385
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x6c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x31b385
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x6c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31b38a
jmp 0x31b448
movq -0x8(%rbp), %rdi
movl -0x6c(%rbp), %esi
xorl $0x1, %esi
leaq -0x70(%rbp), %rdx
movl $0x1, %ecx
callq 0x311c60
cmpl $0x1, %eax
jne 0x31b421
movl -0x70(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x31b3d3
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movl -0x70(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
jmp 0x31b3f4
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x70(%rbp), %ecx
subl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311c60
cmpl $0x1, %eax
jne 0x31b41f
jmp 0x31b448
jmp 0x31b421
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x6c(%rbp), %edx
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %r8
movss -0x24(%rbp), %xmm0
movl -0x28(%rbp), %r9d
callq 0x31a750
addl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x31b317
cmpq $0x0, -0x10(%rbp)
jne 0x31b466
movq -0x30(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x18(%rbp)
jne 0x31b476
movq -0x48(%rbp), %rdi
callq 0x2210
cmpl $0x0, -0x78(%rbp)
jbe 0x31b485
movq -0x8(%rbp), %rdi
callq 0x31b000
addq $0xa0, %rsp
popq %rbp
retq
nop