// File: /workspace/github_cpp_makefile_star2_O1/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:
movl (%rdx), %r10d
testb $0x1, %r10b
jne 0x1cbde8
movl 0xc(%rcx), %eax
movl 0x10(%rcx), %edi
jmp 0x1cbe04
leaq 0xbf441(%rip), %rax     # 0x28b230
movq 0x18(%rax), %rax
movq (%rax,%rdi,8), %rax
movl 0xc(%rcx), %r11d
movq %rax, %rdi
subq %r11, %rdi
subl 0x10(%rcx), %eax
pushq %rbp
pushq %r14
pushq %rbx
movl 0x8(%rdx), %r11d
addq %r11, %rdi
movq (%rsi), %rbx
movq 0x18(%rbx), %rbx
movq 0x20(%rbx), %rbx
movl %r10d, %r14d
shrl %r14d
movl (%rbx,%r14,8), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
cmpq %rbx, %rdi
jbe 0x1cbe36
xorl %eax, %eax
jmp 0x1cbf1d
movl 0x20(%rsp), %ebx
andl $0x1, %r10d
xorps %xmm0, %xmm0
movups %xmm0, (%r8)
movups %xmm0, 0xc(%r8)
movl %r9d, (%r8)
movl 0x4(%rcx), %r9d
movl %r9d, 0x4(%r8)
movl 0x8(%rcx), %r9d
movl %r9d, 0x8(%r8)
movl (%rdx), %r9d
shrl %r9d
movl %r9d, 0xc(%r8)
addl %eax, %r11d
movl %r11d, 0x10(%r8)
movl %edi, 0x14(%r8)
movl 0x20(%rcx), %eax
shll $0x17, %eax
andl $0x40000000, %eax       # imm = 0x40000000
movl $0xbfffffff, %r9d       # imm = 0xBFFFFFFF
andl 0x18(%r8), %r9d
orl %eax, %r9d
movl %r9d, 0x18(%r8)
movl 0x20(%rcx), %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl %ecx, %r10d
setne %al
shll $0x1f, %eax
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
orl %eax, %r9d
movl %r9d, 0x18(%r8)
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
andl 0x4(%rdx), %eax
andl $0xc0000000, %r9d       # imm = 0xC0000000
orl %r9d, %eax
movl %eax, 0x18(%r8)
movl $0x1, %eax
testl %ebx, %ebx
je 0x1cbf1d
cmpl %ecx, %r10d
je 0x1cbf1d
movq (%rsi), %rcx
movq 0x18(%rcx), %rsi
movq 0x20(%rsi), %rsi
movl (%rdx), %r10d
shrl %r10d
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl (%rsi,%r10,8), %ebp
andl %ebx, %ebp
subl %edi, %ebp
movl %ebp, 0x10(%r8)
andl (%rsi,%r10,8), %ebx
subl %r11d, %ebx
movl %ebx, 0x14(%r8)
movq 0x10(%rcx), %rcx
leaq (%r10,%r10,4), %rsi
movl 0x10(%rcx,%rsi,8), %ecx
subl 0x4(%rdx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
orl %r9d, %ecx
movl %ecx, 0x18(%r8)
popq %rbx
popq %r14
popq %rbp
retq