// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: deep_clean_u_trans(kv_u_trans_t*, u_trans_t*, ma_ug_t*, asg64_v*, unsigned int, double)
void deep_clean_u_trans(kv_u_trans_t *ta, u_trans_t *mz, ma_ug_t *ug, asg64_v *srt, uint32_t len_cut, double rate_cut)
{
    if(mz->qn > mz->tn) return;
    u_trans_t *r_a, *cz, *a; uint32_t r_k, r_n, n, k;
    r_a = u_trans_a(*ta, mz->tn); r_n = u_trans_n(*ta, mz->tn);
    for (r_k = 0; (r_k < r_n) && (r_a[r_k].tn != mz->qn); r_k++);
    assert(r_k < r_n); cz = &(r_a[r_k]);
    // if((mz->qn == 3924 && mz->tn == 160) || (mz->tn == 3924 && mz->qn == 160)) {
    //     fprintf(stderr, "[M::%s::]\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tnw::%f\tf::%u\tdel::%u\n", __func__,
    //                 mz->qn+1, "lc"[ug->u.a[mz->qn].circ], ug->u.a[mz->qn].len, mz->qs, mz->qe, "+-"[mz->rev],
    //                 mz->tn+1, "lc"[ug->u.a[mz->tn].circ], ug->u.a[mz->tn].len, mz->ts, mz->te, mz->nw, mz->f,
    //                 (mz->occ == ((uint32_t)-1))?1:0);
    //     fprintf(stderr, "[M::%s::]\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tnw::%f\tf::%u\tdel::%u\n", __func__,
    //                 cz->qn+1, "lc"[ug->u.a[cz->qn].circ], ug->u.a[cz->qn].len, cz->qs, cz->qe, "+-"[cz->rev],
    //                 cz->tn+1, "lc"[ug->u.a[cz->tn].circ], ug->u.a[cz->tn].len, cz->ts, cz->te, cz->nw, cz->f,
    //                 (cz->occ == ((uint32_t)-1))?1:0);
    // }
    if((mz->occ == ((uint32_t)-1)) && (cz->occ == ((uint32_t)-1))) return;
    if((mz->occ != ((uint32_t)-1)) && (cz->occ != ((uint32_t)-1))) return;

    if(!test_arc_rm(ug, r_a, r_n, r_k, ug->u.a[mz->tn].len, srt, len_cut, rate_cut)) {
        mz->occ = cz->occ = 0; return;
    } else {
        a = u_trans_a(*ta, mz->qn); n = u_trans_n(*ta, mz->qn);
        for (k = 0; (k < n) && (a[k].tn != mz->tn); k++); assert(k < n);
        if(!test_arc_rm(ug, a, n, k, ug->u.a[mz->qn].len, srt, len_cut, rate_cut)) {
            mz->occ = cz->occ = 0; return;
        }
    }
    mz->occ = cz->occ = ((uint32_t)-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r12
movl 0x8(%rsi), %edi
movl 0x14(%rsi), %eax
cmpl %eax, %edi
ja 0xc357e
movq %rcx, %r14
movq %rdx, %r15
movq 0x28(%r12), %rcx
movq (%rcx,%rax,8), %rdx
testl %edx, %edx
je 0xc346a
movl %r8d, %ebp
movq %rsi, %rbx
movq 0x10(%r12), %rcx
movq %rdx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %r8
shlq $0x4, %r8
leaq (%rcx,%r8), %rsi
leaq (%r8,%rcx), %r13
addq $0x18, %r13
xorl %ecx, %ecx
cmpl %edi, -0x4(%r13)
je 0xc3489
incl %ecx
addq $0x30, %r13
cmpl %ecx, %edx
jne 0xc345a
leaq 0x16756f(%rip), %rdi    # 0x22a9e0
leaq 0x166829(%rip), %rsi    # 0x229ca1
leaq 0x16756b(%rip), %rcx    # 0x22a9ea
movl $0x3b2f, %edx           # imm = 0x3B2F
callq 0x2110
movl 0x18(%rbx), %edi
cmpl $-0x1, %edi
je 0xc349e
cmpl $-0x1, (%r13)
jne 0xc357e
jmp 0xc34ae
cmpl $-0x1, (%r13)
je 0xc357e
cmpl $-0x1, %edi
jne 0xc3491
movq 0x10(%r15), %rdi
leaq (%rax,%rax,4), %rax
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl (%rdi,%rax,8), %r8d
movl %ebp, (%rsp)
movq %r14, %r9
movsd %xmm0, 0x10(%rsp)
callq 0xc31ff
testl %eax, %eax
je 0xc3571
movq 0x28(%r12), %rcx
movl 0x8(%rbx), %eax
movq (%rcx,%rax,8), %rdx
testl %edx, %edx
movsd 0x10(%rsp), %xmm0
je 0xc3522
movq 0x10(%r12), %rcx
movq %rdx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %r8
shlq $0x4, %r8
leaq (%rcx,%r8), %rsi
movl 0x14(%rbx), %edi
addq %rcx, %r8
addq $0x14, %r8
xorl %ecx, %ecx
cmpl %edi, (%r8)
je 0xc3541
incl %ecx
addq $0x30, %r8
cmpl %ecx, %edx
jne 0xc3513
leaq 0x16751e(%rip), %rdi    # 0x22aa47
leaq 0x166771(%rip), %rsi    # 0x229ca1
leaq 0x1674b3(%rip), %rcx    # 0x22a9ea
movl $0x3b41, %edx           # imm = 0x3B41
callq 0x2110
movq 0x10(%r15), %rdi
leaq (%rax,%rax,4), %rax
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl (%rdi,%rax,8), %r8d
movl %ebp, (%rsp)
movq %r14, %r9
callq 0xc31ff
testl %eax, %eax
je 0xc3571
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xc357b
movl $0x0, (%r13)
xorl %eax, %eax
movl %eax, 0x18(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq