// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jb 0x2c20ea
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x7c(%rbp)
jmp 0x2c20f3
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x2c2118
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x80(%rbp)
jmp 0x2c2122
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jg 0x2c2141
movl $0x0, -0x4(%rbp)
jmp 0x2c23d2
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
subq %rcx, %rax
movl %eax, %edi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x10(%rbp), %rax
subl 0xc(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x10(%rbp), %rax
subl (%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
subq -0x40(%rbp), %rax
movl %eax, %edi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x10(%rbp), %rax
subl 0xc(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x10(%rbp), %rax
subl (%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movb 0x28(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
je 0x2c21d2
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
subq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jl 0x2c2205
movl $0x0, -0x4(%rbp)
jmp 0x2c23d2
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subq %rcx, %rax
movl %eax, %edi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x18(%rbp), %rax
subl (%rax), %esi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x18(%rbp), %rax
subl 0xc(%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
subq -0x40(%rbp), %rax
movl %eax, %edi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x18(%rbp), %rax
subl (%rax), %esi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x18(%rbp), %rax
subl 0xc(%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movb 0x28(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
je 0x2c2295
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
subq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jl 0x2c22c9
movl $0x0, -0x4(%rbp)
jmp 0x2c23d2
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movb 0x28(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x18(%rbp), %rax
movb 0x28(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %esi
movl $0x1, %edx
xorl %eax, %eax
cmpl %esi, %ecx
cmovel %eax, %edx
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x2c23cb
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2c23cb
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
movl 0xc(%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x78(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
movl 0xc(%rcx), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop