// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: tranfor_ovlp(u_trans_t*, u_trans_t*, asg_t*, ul_ov_t*, unsigned int)
uint32_t tranfor_ovlp(u_trans_t *qovlp, u_trans_t *tovlp, asg_t *g, ul_ov_t *res, uint32_t adjust_rev)
{
    int64_t os, oe, s_shift, e_shift, tt, qs, qe, ts, te; 
    os = MAX(qovlp->ts, tovlp->qs);
    oe = MIN(qovlp->te, tovlp->qe);
    if(oe <= os) return 0;

    ///[os, oe) -> qovlp->t*
    s_shift = get_offset_adjust(os-qovlp->ts, qovlp->te-qovlp->ts, qovlp->qe-qovlp->qs);
    e_shift = get_offset_adjust(qovlp->te-oe, qovlp->te-qovlp->ts, qovlp->qe-qovlp->qs);
    if(qovlp->rev) {
        tt = s_shift; s_shift = e_shift; e_shift = tt;
    }
    qs = qovlp->qs+s_shift; qe = ((int64_t)qovlp->qe)-e_shift; 
    if(qs >= qe) return 0;

    ///[os, oe) -> tovlp->q*
    s_shift = get_offset_adjust(os-tovlp->qs, tovlp->qe-tovlp->qs, tovlp->te-tovlp->ts);
    e_shift = get_offset_adjust(tovlp->qe-oe, tovlp->qe-tovlp->qs, tovlp->te-tovlp->ts);
    if(tovlp->rev) {
        tt = s_shift; s_shift = e_shift; e_shift = tt;
    }
    ts = tovlp->ts+s_shift; te = ((int64_t)tovlp->te)-e_shift;
    if(ts >= te) return 0;

    memset(res, 0, sizeof(*res));
    res->qn = qovlp->qn; res->qs = qs; res->qe = qe; 
    res->tn = tovlp->tn; res->ts = ts; res->te = te; 
    res->rev = ((qovlp->rev == tovlp->rev)?0:1);
    if(adjust_rev && res->rev) {///for linear chaining
        res->ts = g->seq[res->tn].len - te;
        res->te = g->seq[res->tn].len - ts;
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0xc(%rdi), %r9d
movl (%rsi), %r10d
cmpl %r10d, %r9d
movl %r10d, %r14d
cmoval %r9d, %r14d
movl 0x10(%rdi), %r15d
movl 0x4(%rsi), %r11d
cmpl %r11d, %r15d
movl %r11d, %ebx
cmovbl %r15d, %ebx
xorl %eax, %eax
cmpl %r14d, %ebx
jbe 0x1bd3e4
movq %rdx, -0x8(%rsp)
movl %r14d, %r13d
subl %r9d, %r13d
movl %r15d, %ebp
subl %r9d, %ebp
movl (%rdi), %r12d
movl 0x4(%rdi), %edx
movl %edx, %r9d
subl %r12d, %r9d
cvtsi2sd %r13, %xmm0
cvtsi2sd %rbp, %xmm1
cvtsi2sd %r9, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r9
movl %r9d, %r9d
subl %ebx, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r15
movl %r15d, %r15d
testb $0x40, 0x28(%rdi)
movq %r9, %r13
cmoveq %r15, %r13
cmoveq %r9, %r15
addq %r12, %r15
subq %r13, %rdx
cmpq %rdx, %r15
jge 0x1bd3e4
subl %r10d, %r14d
movl %r11d, %r9d
subl %r10d, %r9d
movl 0xc(%rsi), %r12d
movl 0x10(%rsi), %r10d
movl %r10d, %r13d
subl %r12d, %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r9, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r13, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r9
movl %r9d, %r9d
subl %ebx, %r11d
xorps %xmm0, %xmm0
cvtsi2sd %r11, %xmm0
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r11
movl %r11d, %r11d
testb $0x40, 0x28(%rsi)
movq %r9, %rbx
cmoveq %r11, %rbx
cmoveq %r9, %r11
addq %r12, %r11
subq %rbx, %r10
cmpq %r10, %r11
jge 0x1bd3e4
xorpd %xmm0, %xmm0
movupd %xmm0, 0xc(%rcx)
movupd %xmm0, (%rcx)
movl 0x8(%rdi), %eax
movl %eax, (%rcx)
movl %r15d, 0x4(%rcx)
movl %edx, 0x8(%rcx)
movl 0x14(%rsi), %r9d
movl %r9d, 0xc(%rcx)
movl %r11d, 0x10(%rcx)
movl %r10d, 0x14(%rcx)
movb 0x28(%rsi), %sil
xorb 0x28(%rdi), %sil
shrb $0x6, %sil
movzbl %sil, %eax
shll $0x1f, %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl 0x18(%rcx), %edx
orl %eax, %edx
movl %edx, 0x18(%rcx)
movl $0x1, %eax
testl %r8d, %r8d
je 0x1bd3e4
andb $0x1, %sil
je 0x1bd3e4
movq -0x8(%rsp), %rdx
movq 0x20(%rdx), %rdx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl (%rdx,%r9,8), %edi
andl %esi, %edi
subl %r10d, %edi
movl %edi, 0x10(%rcx)
andl (%rdx,%r9,8), %esi
subl %r11d, %esi
movl %esi, 0x14(%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq