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

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

	if(r_qs) (*r_qs) = qs; if(r_qe) (*r_qe) = qe + 1;
	if(r_rs) (*r_rs) = rs; if(r_re) (*r_re) = re + 1;
    if(ri->v&1) {
        if(r_rs) (*r_rs) = rlen - re - 1; 
		if(r_re) (*r_re) = rlen - rs;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
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 -0x8(%rbp), %rax
movslq 0x14(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movslq 0xc(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2876f1
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x10(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xc(%rcx), %rcx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x287714
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x28772b
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
subq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
subq -0x50(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jg 0x28776f
movq -0x10(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x287787
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x28779a
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x28(%rbp)
je 0x2877b1
movq -0x40(%rbp), %rax
addq $0x1, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x2877c4
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x10(%rbp)
je 0x2877db
movq -0x50(%rbp), %rax
addq $0x1, %rax
movl %eax, %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x28781e
cmpq $0x0, -0x30(%rbp)
je 0x287805
movq -0x18(%rbp), %rax
subq -0x50(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x10(%rbp)
je 0x28781c
movq -0x18(%rbp), %rax
subq -0x48(%rbp), %rax
movl %eax, %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x28781e
popq %rbp
retq