// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movb 0x28(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movb 0x28(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %eax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x78(%rbp), %rax
jl 0x102340
movq -0x48(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x10234b
movq -0x78(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x80(%rbp), %rax
jg 0x102370
movq -0x50(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x10237b
movq -0x80(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jg 0x1023a6
movq $0x0, -0x8(%rbp)
jmp 0x10266b
movq -0xa8(%rbp), %rax
subq -0x48(%rbp), %rax
movl %eax, %edi
movq -0x50(%rbp), %rax
subq -0x48(%rbp), %rax
movl %eax, %esi
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movl %eax, %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0xb8(%rbp)
movq -0x50(%rbp), %rax
subq -0xb0(%rbp), %rax
movl %eax, %edi
movq -0x50(%rbp), %rax
subq -0x48(%rbp), %rax
movl %eax, %esi
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movl %eax, %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x102435
movq -0xb8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0xc0(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0xa8(%rbp), %rax
subq -0x78(%rbp), %rax
movl %eax, %edi
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movl %eax, %esi
movq -0x68(%rbp), %rax
subq -0x60(%rbp), %rax
movl %eax, %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0xb8(%rbp)
movq -0x80(%rbp), %rax
subq -0xb0(%rbp), %rax
movl %eax, %edi
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movl %eax, %esi
movq -0x68(%rbp), %rax
subq -0x60(%rbp), %rax
movl %eax, %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x1024e5
movq -0xb8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0xc0(%rbp), %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x102541
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x10257c
movq -0x58(%rbp), %rax
subq -0x68(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x58(%rbp), %rax
subq -0x60(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x60(%rbp), %rax
jg 0x10259f
movq -0x30(%rbp), %rcx
movq -0x60(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x30(%rbp)
jmp 0x1025b6
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %rax
subq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
jg 0x1025fd
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x88(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x102614
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x90(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rax
subq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x90(%rbp), %rax
jl 0x102652
movq -0x88(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0x102660
movq -0x90(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)