// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: infer_utrans_ovlp_len(u_trans_t*, u_trans_t*, ma_ug_t*)
int64_t infer_utrans_ovlp_len(u_trans_t *li, u_trans_t *lj, ma_ug_t *ug)
{
	int64_t in, is, ie, irev, iqs, iqe, jn, js, je, jrev, jqs, jqe, ir, jr, ts, te, max_s, min_e, s_shift, e_shift;
	
    in = ug->u.a[li->tn].len; 
    is = li->ts; ie = li->te; irev = li->rev; iqs = li->qs; iqe = li->qe;
	jn = ug->u.a[lj->tn].len; 
    js = lj->ts; je = lj->te; jrev = lj->rev; jqs = lj->qs; jqe = lj->qe;

	max_s = MAX(iqs, jqs); min_e = MIN(iqe, jqe);
	if(min_e <= max_s) return 0;
	s_shift = get_offset_adjust(max_s - iqs, iqe-iqs, ie-is);
	e_shift = get_offset_adjust(iqe - min_e, iqe-iqs, ie-is);
	if(irev) {
		ts = s_shift; s_shift = e_shift; e_shift = ts;
	}
	is += s_shift; ie-= e_shift;

	s_shift = get_offset_adjust(max_s - jqs, jqe-jqs, je-js);
    e_shift = get_offset_adjust(jqe - min_e, jqe-jqs, je-js);
    if(jrev) {
        ts = s_shift; s_shift = e_shift; e_shift = ts;
    }
    js += s_shift; je-= e_shift;

	if(irev) {
		ts = in - ie; te = in - is;
		is = ts; ie = te;
	}

	if(jrev) {
		ts = jn - je; te = jn - js;
		js = ts; je = te;
	}
	
	if(is <= js) {
		js -= is; is = 0;
	} else {
		is -= js; js = 0;
	}

	ir = in - ie; jr = jn - je;

	if(ir <= jr){
        ie = in; je += ir;        
    }
    else {
		je = jn; ie += jr;
    }

	ir = ie - is; jr = je - js;
	return MAX(ir, jr);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl (%rdi), %r10d
movl 0x4(%rdi), %r8d
movl (%rsi), %ebp
movl 0x4(%rsi), %r12d
cmpl %ebp, %r10d
movl %ebp, %r11d
cmoval %r10d, %r11d
cmpl %r12d, %r8d
movl %r12d, %r9d
cmovbl %r8d, %r9d
cmpl %r11d, %r9d
jbe 0x87a6e
movl 0xc(%rsi), %eax
movl 0x10(%rsi), %ebx
movq 0x10(%rdx), %r14
movl 0x14(%rsi), %ecx
imulq $0x28, %rcx, %rcx
movl (%r14,%rcx), %ecx
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
andq %r15, %rcx
movl %r11d, %edx
subl %ebp, %edx
movl %r12d, %r13d
subl %ebp, %r13d
movl %ebx, %ebp
subl %eax, %ebp
cvtsi2sd %rdx, %xmm0
cvtsi2sd %r13, %xmm1
divsd %xmm1, %xmm0
cvtsi2sd %rbp, %xmm2
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rdx
movl %edx, %edx
subl %r9d, %r12d
cvtsi2sd %r12, %xmm0
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r12
movl %r12d, %r12d
movb 0x28(%rsi), %sil
testb $0x40, %sil
movq %r12, %r13
cmoveq %rdx, %r13
cmoveq %r12, %rdx
addq %rax, %r13
subq %rdx, %rbx
movq %rcx, %rdx
subq %rbx, %rdx
testb $0x40, %sil
cmoveq %r13, %rdx
movq %rcx, %rax
subq %r13, %rax
testb $0x40, %sil
movl 0xc(%rdi), %r13d
movl 0x10(%rdi), %r12d
movl 0x14(%rdi), %esi
cmoveq %rbx, %rax
imulq $0x28, %rsi, %rsi
movl (%r14,%rsi), %esi
andq %r15, %rsi
subl %r10d, %r11d
movl %r8d, %ebx
subl %r10d, %ebx
movl %r12d, %r10d
subl %r13d, %r10d
cvtsi2sd %r11, %xmm0
cvtsi2sd %rbx, %xmm1
cvtsi2sd %r10, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r10
movl %r10d, %r10d
subl %r9d, %r8d
cvtsi2sd %r8, %xmm0
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r8
movl %r8d, %r8d
movb 0x28(%rdi), %r9b
testb $0x40, %r9b
movq %r8, %r11
cmoveq %r10, %r11
cmoveq %r8, %r10
addq %r13, %r11
subq %r10, %r12
movq %rsi, %rdi
subq %r12, %rdi
testb $0x40, %r9b
cmoveq %r11, %rdi
movq %rsi, %r8
subq %r11, %r8
testb $0x40, %r9b
cmoveq %r12, %r8
movq %rdi, %r9
subq %rdx, %r9
negq %r9
xorl %r10d, %r10d
subq %rdx, %rdi
cmovgq %r10, %rdi
cmovleq %r10, %r9
movq %rsi, %rdx
subq %r8, %rdx
movq %rcx, %r10
subq %rax, %r10
addq %rdx, %rax
addq %r10, %r8
cmpq %r10, %rdx
cmovgq %rcx, %rax
cmovleq %rsi, %r8
addq %r9, %r8
addq %rdi, %rax
cmpq %rax, %r8
cmovgq %r8, %rax
jmp 0x87a70
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq