// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/./Overlaps.h
// Function: ma_hit2arc(ma_hit_t const*, int, int, int, float, int, asg_arc_t*)
static inline int ma_hit2arc(const ma_hit_t *h, int ql, int tl, int max_hang, float int_frac, int min_ovlp, asg_arc_t *p)
{
	int32_t tl5, tl3, ext5, ext3, qs = (int32_t)h->qns;
	uint32_t u, v, l; // u: query end; v: target end; l: length from u to v

	///if query and target are in different strand
	if (h->rev) tl5 = tl - h->te, tl3 = h->ts; // tl5: 5'-end overhang (on the query strand); tl3: similar
	else tl5 = h->ts, tl3 = tl - h->te;

	///ext5 and ext3 is the hang on left side and right side, respectively
	ext5 = qs < tl5? qs : tl5;
	ext3 = ql - (int)h->qe < tl3? ql - (int)h->qe : tl3;


	/**
	if (ext5 > max_hang || ext3 > max_hang || h->qe - qs < (h->qe - qs + ext5 + ext3) * int_frac)
		return MA_HT_INT;
	**/
	///ext3 and ext5 should be always 0
	if (ext5 > max_hang || ext3 > max_hang 
	|| h->qe - qs < (h->qe - qs + ext5 + ext3) * int_frac
	|| h->te - h->ts < (h->te - h->ts + ext5 + ext3) * int_frac)
	{
		return MA_HT_INT;
	}
		
	/**
	********************************query-to-target overlap****************************
	case 1: u = 0, rev = 0                           in the view of target: direction is 1 
	query: CCCCCCCCTAATTAAAAT                        target: TAATTAAAATGGGGGG (use ex-target as query)
	               ||||||||||         <--->                  ||||||||||
	       target: TAATTAAAATGGGGGG           query: CCCCCCCCTAATTAAAAT (use ex-query as target)

	case 2: u = 0, rev = 1                           in the view of target: direction is 0
	query: CCCCCCCCTAATTAAAAT					     target: CCCCCCATTTTAATTA  (use ex-target as query)
                   ||||||||||        <--->                         ||||||||||
	       target: TAATTAAAATGGGGGG                         query: ATTTTAATTAGGGGGGGG  (use ex-query as target)
	********************************query-to-target overlap****************************

	********************************target-to-query overlap****************************
	case 3: u = 1, rev = 0                           in the view of target: direction is 0
			 query: AAATAATATCCCCCCGCG                target: GGGCCGGCAAATAATAT (use ex-target as query)
					|||||||||          <--->                          |||||||||
	target: GGGCCGGCAAATAATAT                                  query: AAATAATATCCCCCCGCG (use ex-query as target)

	case 4: u = 1, rev = 1                          in the view of target: direction is 1
	         query: AAATAATATCCCCCCGCG                        target: ATATTATTTGCCGGCCC (use ex-target as query)
                    |||||||||             <--->                       |||||||||
	target: GGGCCGGCAAATAATAT                          query: CGCGGGGGATATTATTT (use ex-query as target)
	********************************target-to-query overlap****************************
	**/

	if (qs <= tl5 && ql - (int)h->qe <= tl3) return MA_HT_QCONT; // query contained in target
	else if (qs >= tl5 && ql - (int)h->qe >= tl3) return MA_HT_TCONT; // target contained in query 
	else if (qs > tl5) u = 0, v = !!h->rev, l = qs - tl5; ///u = 0 means query-to-target overlap, l is the length of node in string graph (not the overlap length)
	else u = 1, v = !h->rev, l = (ql - h->qe) - tl3; ///u = 1 means target-to-query overlaps, l is the length of node in string graph (not the overlap length)
	if ((int)h->qe - qs + ext5 + ext3 < min_ovlp || (int)h->te - (int)h->ts + ext5 + ext3 < min_ovlp) return MA_HT_SHORT_OVLP; // short overlap
	///u = 0 / 1 means query-to-target / target-to-query overlaps, 
	///l is the length of node in string graph (not the overlap length between two reads)
	u |= h->qns>>32<<1, v |= h->tn<<1;
	/**
	p->ul: |____________31__________|__________1___________|______________32_____________|
	                    qn            direction of overlap       length of this node (not overlap length)
						                (in the view of query)
	p->v : |___________31___________|__________1___________|
				        tn             reverse direction of overlap
						              (in the view of target)
	p->ol: overlap length
	**/
	p->ul = (uint64_t)u<<32 | l, p->v = v, p->ol = ql - l, p->del = 0;
	///l is the length of node in string graph (not the overlap length)

	p->strong = h->ml;
	p->el = h->el;
	p->no_l_indel = h->no_l_indel;
	return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdi), %r10
movq 0x18(%rdi), %r11
testl %r11d, %r11d
js 0x35cab
movl 0x10(%rdi), %eax
subl 0x14(%rdi), %edx
movl %edx, %ebx
movl %eax, %edx
jmp 0x35cb1
subl 0x14(%rdi), %edx
movl 0x10(%rdi), %ebx
cmpl %r10d, %edx
movl %r10d, %r12d
cmovll %edx, %r12d
movl 0x8(%rdi), %ebp
movl %esi, %r15d
subl %ebp, %r15d
cmpl %ebx, %r15d
movl %ebx, %r14d
cmovll %r15d, %r14d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %r12d
jg 0x35df6
cmpl %ecx, %r14d
jg 0x35df6
movl %ebp, %ecx
subl %r10d, %ecx
cvtsi2ss %rcx, %xmm1
addl %r12d, %ecx
addl %r14d, %ecx
cvtsi2ss %rcx, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0x35df6
movl 0x14(%rdi), %r13d
subl 0x10(%rdi), %r13d
xorps %xmm1, %xmm1
cvtsi2ss %r13, %xmm1
addl %r12d, %r14d
addl %r13d, %r14d
xorps %xmm2, %xmm2
cvtsi2ss %r14, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0x35df6
cmpl %edx, %r10d
jg 0x35d45
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpl %ebx, %r15d
jle 0x35df6
cmpl %edx, %r10d
jl 0x35d58
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpl %ebx, %r15d
jge 0x35df6
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmpl %r8d, %ecx
jl 0x35df6
cmpl %r8d, %r14d
jl 0x35df6
testl %r11d, %r11d
setns %cl
addl %ebp, %ebx
movl %esi, %r8d
subl %ebx, %r8d
xorl %r11d, %r11d
movl %r10d, %eax
subl %edx, %eax
setle %r11b
setg %dl
cmovlel %r8d, %eax
xorb %cl, %dl
movzbl %dl, %ecx
shrq $0x1f, %r10
andl $-0x2, %r10d
orl %r10d, %r11d
movl 0xc(%rdi), %edx
leal (%rcx,%rdx,2), %ecx
shlq $0x20, %r11
leaq (%rax,%r11), %rdx
movq %rdx, (%r9)
movl %ecx, 0x8(%r9)
subl %eax, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %esi, 0xc(%r9)
movzwl 0x1a(%rdi), %ecx
andl $0x4000, %ecx           # imm = 0x4000
movl $0xffffbfff, %edx       # imm = 0xFFFFBFFF
andl 0x10(%r9), %edx
orl %ecx, %edx
movw %dx, 0x10(%r9)
movb 0x20(%rdi), %cl
movb %cl, 0x12(%r9)
movzbl 0x21(%rdi), %ecx
shll $0xf, %ecx
andl $0x7fff, %edx           # imm = 0x7FFF
orl %ecx, %edx
movw %dx, 0x10(%r9)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq