// File: 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
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movss %xmm0, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x0, %eax
je 0xe896
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0xe8ad
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xe8bd
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0xe8c3
movl -0x34(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
cmpl -0x38(%rbp), %eax
jge 0xe8e7
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
movl %eax, -0x58(%rbp)
jmp 0xe8ed
movl -0x38(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0xe95b
movl -0x40(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0xe95b
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x44(%rbp), %ecx
subl %ecx, %eax
movl %eax, %ecx
cvtsi2ss %rcx, %xmm1
movl -0x3c(%rbp), %ecx
addl %ecx, %eax
movl -0x40(%rbp), %ecx
addl %ecx, %eax
cvtsi2ss %rax, %xmm0
mulss -0x20(%rbp), %xmm0
ucomiss %xmm1, %xmm0
ja 0xe95b
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
movl 0x14(%rax), %eax
subl %ecx, %eax
movl %eax, %ecx
cvtsi2ss %rcx, %xmm1
movl -0x3c(%rbp), %ecx
addl %ecx, %eax
movl -0x40(%rbp), %ecx
addl %ecx, %eax
cvtsi2ss %rax, %xmm0
mulss -0x20(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xe967
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xeb3f
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0xe98a
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
cmpl -0x38(%rbp), %eax
jg 0xe98a
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0xeb3f
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jl 0xe9ad
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
cmpl -0x38(%rbp), %eax
jl 0xe9ad
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0xeb3f
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0xe9e9
movl $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0xea20
movl $0x1, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4c(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0xea22
jmp 0xea24
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subl -0x44(%rbp), %eax
addl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0xea52
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x10(%rcx), %eax
addl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xea5e
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0xeb3f
movq -0x10(%rbp), %rax
movq (%rax), %rcx
shrq $0x20, %rcx
shlq %rcx
movl -0x48(%rbp), %eax
orq %rcx, %rax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
orl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
movl %eax, %ecx
shlq $0x20, %rcx
movl -0x50(%rbp), %eax
orq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl -0x4c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %edx
subl -0x50(%rbp), %edx
movq -0x30(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1e, %rax
andq $0x1, %rax
movw %ax, %dx
movq -0x30(%rbp), %rax
movw 0x10(%rax), %cx
andw $0x1, %dx
shlw $0xe, %dx
andw $0xbfff, %cx            # imm = 0xBFFF
orw %dx, %cx
movw %cx, 0x10(%rax)
movq -0x10(%rbp), %rax
movb 0x20(%rax), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x12(%rax)
movq -0x10(%rbp), %rax
movzbl 0x21(%rax), %eax
movw %ax, %dx
movq -0x30(%rbp), %rax
movw 0x10(%rax), %cx
andw $0x1, %dx
shlw $0xf, %dx
andw $0x7fff, %cx            # imm = 0x7FFF
orw %dx, %cx
movw %cx, 0x10(%rax)
movl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)