// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/tovlp.cpp
// Function: get_utg_trans_hit(utg_trans_hit_idx*, utg_thit_t*)
uint32_t get_utg_trans_hit(utg_trans_hit_idx *t, utg_thit_t *hit)
{
    uint32_t r_beg, r_end, ovlp;
    uint32_t k, l, qn, v, w, nv;
    uint32_t *a = t->a, a_n = t->an;
    asg_arc_t *av  = NULL;
    hit->qs = hit->qe = hit->qn = hit->qus = hit->que = (uint32_t)-1;
    hit->ts = hit->te = hit->tn = hit->tus = hit->tue = (uint32_t)-1;
    
    while (t->ui < a_n)
    {
        qn = a[t->ui];
        l = t->ug->g->seq[qn>>1].len;
        if(t->ui + 1 < a_n)
        {
            v = a[t->ui]; w = a[t->ui+1];
            av = asg_arc_a(t->ug->g, v);
            nv = asg_arc_n(t->ug->g, v);
            for (k = 0; k < nv; k++)
            {
                if(av[k].del) continue;
                if(av[k].v == w) 
                {
                    l = asg_arc_len(av[k]);
                    break;
                }
            }
            if(k >= nv) fprintf(stderr, "ERROR-mc-1\n");
        }

        r_beg = t->len; r_end = t->len + t->ug->g->seq[qn>>1].len;
        t->len += l; t->ui++;

        ovlp = ((MIN(t->cEnd, r_end) > MAX(t->cBeg, r_beg))? (MIN(t->cEnd, r_end) - MAX(t->cBeg, r_beg)) : 0);
        if(ovlp == 0 && r_beg >= t->cEnd) return 0;
        if(ovlp == 0) continue;

        hit->qn = qn; hit->qs = r_beg; hit->qe = r_end; hit->qus = 0; hit->que = t->ug->g->seq[qn>>1].len;
        if(hit->qs < t->cBeg)
        {
            hit->qus += (t->cBeg - hit->qs);
            hit->qs = t->cBeg;
        } 
        
        if(hit->qe > t->cEnd)
        {
            hit->que -= (hit->qe - t->cEnd);
            hit->qe = t->cEnd;
        } 
        
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq 0x10(%rdi), %r11
movl 0x18(%rdi), %r12d
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x10(%rsi)
movdqu %xmm0, (%rsi)
movq $-0x1, 0x20(%rsi)
xorl %ebp, %ebp
movl (%r14), %eax
cmpl %r12d, %eax
jae 0x18ea42
movl (%r11,%rax,4), %r13d
movq 0x20(%r14), %rcx
movq 0x18(%rcx), %rdx
movq 0x20(%rdx), %rcx
movl %r13d, %ebx
shrl %ebx
movl (%rcx,%rbx,8), %r15d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %r15d
leal 0x1(%rax), %ecx
cmpl %r12d, %ecx
jae 0x18e990
movq 0x28(%rdx), %rax
movq (%rax,%r13,8), %r9
movq %r9, %rax
shlq $0x20, %rax
setne %al
je 0x18e98c
movl %ecx, %ecx
movl (%r11,%rcx,4), %ecx
movq 0x8(%rdx), %rdi
movq %r9, %r8
shrq $0x20, %r8
movl %r9d, %edx
leaq (%r8,%r8,2), %r8
leaq (%rdi,%r8,8), %r10
addq $0xc, %r10
movq %rdx, %rdi
negq %rdi
movl $0x1, %r8d
cmpl $0x0, (%r10)
js 0x18e96c
cmpl %ecx, -0x4(%r10)
je 0x18e988
cmpq %rdx, %r8
setb %al
addq $0x18, %r10
leaq (%rdi,%r8), %r9
incq %r9
incq %r8
cmpq $0x1, %r9
jne 0x18e960
jmp 0x18e98c
movl -0xc(%r10), %r15d
testb $0x1, %al
je 0x18e9e8
movl 0x4(%r14), %edx
movl 0x8(%r14), %ecx
movq 0x20(%r14), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rdi
movl (%rdi,%rbx,8), %eax
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %eax
addl %edx, %r15d
movl %r15d, 0x4(%r14)
incl (%r14)
addl %edx, %eax
movl 0xc(%r14), %r10d
cmpl %eax, %r10d
movl %eax, %r8d
cmovbl %r10d, %r8d
cmpl %edx, %ecx
movl %edx, %r9d
cmoval %ecx, %r9d
cmpl %r9d, %r8d
ja 0x18ea03
cmpl %r10d, %edx
jae 0x18ea42
cmpl %r9d, %r8d
jbe 0x18e8eb
jmp 0x18ea03
movq %rsi, 0x10(%rsp)
movq %r11, 0x8(%rsp)
callq 0x2457b
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %rsi
jmp 0x18e990
movl %r13d, 0x8(%rsi)
movl %edx, (%rsi)
movl %eax, 0x4(%rsi)
movl $0x0, 0xc(%rsi)
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl (%rdi,%rbx,8), %r8d
movl %r8d, 0x10(%rsi)
movl %ecx, %edi
subl %edx, %edi
jbe 0x18ea2c
movl %edi, 0xc(%rsi)
movl %ecx, (%rsi)
movl $0x1, %ebp
movl %r10d, %ecx
subl %eax, %ecx
jae 0x18ea42
addl %r8d, %ecx
movl %ecx, 0x10(%rsi)
movl %r10d, 0x4(%rsi)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq