// File: /workspace/github_cpp_makefile_star2_O3/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 0xc4472
movq %rcx, %r14
movq %rdx, %r15
movq 0x28(%r12), %rcx
movq (%rcx,%rax,8), %rdx
testl %edx, %edx
je 0xc4364
movl %r8d, %ebp
movq %rsi, %rbx
movq 0x10(%r12), %rcx
movq %rdx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %r9
shlq $0x4, %r9
leaq (%rcx,%r9), %rsi
movl %edx, %r8d
leaq (%r9,%rcx), %r13
addq $0x18, %r13
xorl %ecx, %ecx
cmpl %edi, -0x4(%r13)
je 0xc4383
incq %rcx
addq $0x30, %r13
cmpq %rcx, %r8
jne 0xc4352
leaq 0x172865(%rip), %rdi    # 0x236bd0
leaq 0x171b1f(%rip), %rsi    # 0x235e91
leaq 0x172861(%rip), %rcx    # 0x236bda
movl $0x3b2f, %edx           # imm = 0x3B2F
callq 0x2110
cmpl $-0x1, 0x18(%rbx)
sete %dil
cmpl $-0x1, (%r13)
sete %r8b
cmpb %r8b, %dil
je 0xc4472
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 0xc40f4
testl %eax, %eax
je 0xc4465
movq 0x28(%r12), %rcx
movl 0x8(%rbx), %eax
movq (%rcx,%rax,8), %rdx
testl %edx, %edx
movsd 0x10(%rsp), %xmm0
je 0xc4416
movq 0x10(%r12), %rcx
movq %rdx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %r9
shlq $0x4, %r9
leaq (%rcx,%r9), %rsi
movl 0x14(%rbx), %edi
movl %edx, %r8d
addq %rcx, %r9
addq $0x14, %r9
xorl %ecx, %ecx
cmpl %edi, (%r9)
je 0xc4435
incq %rcx
addq $0x30, %r9
cmpq %rcx, %r8
jne 0xc4405
leaq 0x17281a(%rip), %rdi    # 0x236c37
leaq 0x171a6d(%rip), %rsi    # 0x235e91
leaq 0x1727af(%rip), %rcx    # 0x236bda
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 0xc40f4
testl %eax, %eax
je 0xc4465
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xc446f
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