// File: chhylp123[P]hifiasm/inter.cpp
// Function: extend_end_coord(mg_lchain_t*, ul_ov_t*, long, long, long*, long*, long*, long*)
void extend_end_coord(mg_lchain_t *li, ul_ov_t *ui, const int64_t qlen, const int64_t rlen, int64_t *r_qs, int64_t *r_qe, int64_t *r_rs, int64_t *r_re)
{
    int64_t qs = 0, qe = 0, rs = 0, re = 0, rev = 0, qtail = 0, rtail = 0;
	if(li) {
		qs = li->qs; qe = li->qe; rs = li->rs; re = li->re; rev = li->v&1; 
		if(rev) {
			rs = rlen - li->re; re = rlen - li->rs;
		}
	}
	if(ui) {
		qs = ui->qs; qe = ui->qe; rs = ui->ts; re = ui->te; rev = ui->rev; 
		if(rev) {
        rs = rlen - ui->te; re = rlen - ui->ts;
    	}
	}
    
    
    
    if(qs <= rs) {
        rs -= qs; qs = 0;
    } else {
        qs -= rs; rs = 0;
    }

    qtail = qlen - qe; rtail = rlen - re;
    if(qtail <= rtail) {
        qe = qlen; re += qtail;
    }
    else {
        re = rlen; qe += rtail; 
    }

	if(r_qs) (*r_qs) = qs; if(r_qe) (*r_qe) = qe;
	if(r_rs) (*r_rs) = rs; if(r_re) (*r_re) = re;
    if(rev) {
        if(r_rs) (*r_rs) = rlen - re; 
		if(r_re) (*r_re) = rlen - rs;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x2d2c72
movq -0x8(%rbp), %rax
movslq 0x14(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movslq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movslq 0xc(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x2d2c70
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x10(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xc(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x2d2c72
cmpq $0x0, -0x10(%rbp)
je 0x2d2ce2
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x2d2ce0
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x2d2ce2
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x2d2d05
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x2d2d1c
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
subq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jg 0x2d2d54
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x2d2d68
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2d2d7a
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x2d2d8c
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, 0x10(%rbp)
je 0x2d2d9e
movq -0x48(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, 0x18(%rbp)
je 0x2d2db0
movq -0x50(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x58(%rbp)
je 0x2d2de5
cmpq $0x0, 0x10(%rbp)
je 0x2d2dcd
movq -0x20(%rbp), %rcx
subq -0x50(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, 0x18(%rbp)
je 0x2d2de3
movq -0x20(%rbp), %rcx
subq -0x48(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2d2de5
popq %rbp
retq
nopw (%rax,%rax)