// File: chhylp123[P]hifiasm/inter.cpp
// Function: rov2uov_ctg(unsigned long, ul_idx_t const*, utg_rid_dt*, uc_block_t*, ul_ov_t*, unsigned int, unsigned int)
uint64_t rov2uov_ctg(uint64_t rid, const ul_idx_t *uref, utg_rid_dt *ru_map, uc_block_t *rovlp, ul_ov_t *res, uint32_t qidx, uint32_t adjust_rev)
{
    uint64_t ori = ru_map->u&1, ts, te;
    if(!ori) {
        ts = rovlp->ts; te = rovlp->te;
    } else {
        ts = Get_READ_LENGTH(R_INF, rid) - rovlp->te;
        te = Get_READ_LENGTH(R_INF, rid) - rovlp->ts;
    }
    
    ts += ru_map->pos; te += ru_map->pos;
    if(ts >= 0 && te <= uref->ug->g->seq[ru_map->u>>1].len) {
        memset(res, 0, sizeof(*res));
        res->qn = qidx; res->qs = rovlp->qs; res->qe = rovlp->qe; 
        res->tn = ru_map->u>>1; res->ts = ts; res->te = te; 
        res->el = rovlp->el; res->rev = (rovlp->rev == ori?0:1); res->sec = ru_map->off;
        if(adjust_rev && res->rev) {///for linear chaining
            res->ts = uref->ug->g->seq[ru_map->u>>1].len - te;
            res->te = uref->ug->g->seq[ru_map->u>>1].len - ts;
			res->sec = uref->ug->u.a[ru_map->u>>1].n - ru_map->off;
        }
        return 1;
    } 
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2dd3b1
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x50(%rbp)
jmp 0x2dd3f3
leaq 0xe7f18(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x28(%rbp), %rcx
movl 0x10(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
leaq 0xe7ef7(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x28(%rbp), %rcx
movl 0xc(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
jb 0x2dd5ee
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movl (%rdx), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
ja 0x2dd5ee
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
shrl %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
movzbl %al, %edx
movq -0x30(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1e, %edx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %ecx
movq -0x40(%rbp), %rsi
movl $0x1, %edx
xorl %eax, %eax
cmpq %rsi, %rcx
cmovel %eax, %edx
movq -0x30(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x30(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
cmpl $0x0, 0x10(%rbp)
je 0x2dd5e4
movq -0x30(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2dd5e4
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x50(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %edx
movq -0x20(%rbp), %rax
subl 0x4(%rax), %edx
movq -0x30(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq $0x1, -0x8(%rbp)
jmp 0x2dd5f6
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq