// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %rax
movq %rdi, %r15
movq 0x10(%rdi), %r12
movl 0x18(%rdi), %r13d
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x10(%rsi)
orq $-0x1, 0x20(%rsi)
movq %rsi, (%rsp)
movdqu %xmm0, (%rsi)
movl (%rdi), %eax
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
cmpl %r13d, %eax
jae 0x1505e2
movl %eax, %ecx
movl (%r12,%rcx,4), %ebx
movq 0x20(%r15), %rcx
movq 0x18(%rcx), %rdi
movq 0x20(%rdi), %rcx
movl %ebx, %r14d
shrl %r14d
movl (%rcx,%r14,8), %ebp
andl %r11d, %ebp
incl %eax
cmpl %r13d, %eax
jae 0x150558
movl %eax, %edx
movl (%r12,%rdx,4), %edx
movq 0x8(%rdi), %rsi
movq 0x28(%rdi), %rdi
movq (%rdi,%rbx,8), %rdi
movl %edi, %r8d
shrq $0x20, %rdi
imulq $0x18, %r8, %r9
imulq $0x18, %rdi, %r8
leaq (%rsi,%r8), %r10
addq $0xc, %r10
xorl %edi, %edi
cmpq %rdi, %r9
je 0x1505a6
cmpl $0x0, (%r10,%rdi)
js 0x150552
cmpl %edx, -0x4(%r10,%rdi)
je 0x15055c
addq $0x18, %rdi
jmp 0x15053f
movl %ebp, %edx
jmp 0x15056a
addq %r8, %rsi
movl %ebp, %edx
movl (%rdi,%rsi), %ebp
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl 0x4(%r15), %r8d
movl 0x8(%r15), %edi
addl %r8d, %edx
addl %r8d, %ebp
movl %ebp, 0x4(%r15)
movl %eax, (%r15)
movl 0xc(%r15), %esi
cmpl %edx, %esi
movl %edx, %r9d
cmovbl %esi, %r9d
cmpl %r8d, %edi
movl %r8d, %r10d
cmoval %edi, %r10d
cmpl %r10d, %r9d
ja 0x1505f3
cmpl %esi, %r8d
jb 0x1504e5
jmp 0x1505e2
movq 0x102a33(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xa1273(%rip), %rdi     # 0x1f182a
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x20(%r15), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rcx
movl (%r15), %eax
movl (%rcx,%r14,8), %edx
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
andl %r11d, %edx
incl %eax
jmp 0x15056a
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %r9
movl %ebx, 0x8(%r9)
movl %r8d, (%r9)
movl %edx, 0x4(%r9)
andl $0x0, 0xc(%r9)
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl (%rcx,%r14,8), %r10d
movl %r10d, 0x10(%r9)
movl %edi, %ecx
subl %r8d, %ecx
jbe 0x150623
movl %ecx, 0xc(%r9)
movl %edi, (%r9)
pushq $0x1
popq %rax
movl %esi, %ecx
subl %edx, %ecx
jae 0x1505e4
addl %r10d, %ecx
movl %ecx, 0x10(%r9)
movl %esi, 0x4(%r9)
jmp 0x1505e4