// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: extract_ccov(ma_hit_t*, uc_block_t*, asg_t const*, ul_ov_t*, unsigned int, long, long)
uint32_t extract_ccov(ma_hit_t *in, uc_block_t *rovlp, const asg_t *rg, ul_ov_t *res, uint32_t adjust_rev, int64_t min_ovlp, int64_t max_hang)
{
	uint64_t qn, tn; int32_t r = 1; asg_arc_t e; 
	qn = Get_qn((*in)); tn = Get_tn((*in));
	if(rg->seq[tn].del) return 0;	
	
	r = ma_hit2arc(in, Get_READ_LENGTH(R_INF, qn), Get_READ_LENGTH(R_INF, tn), max_hang, asm_opt.max_hang_rate, min_ovlp, &e);
	if(r != MA_HT_QCONT) return 0; ///qn is contained in tn

	uint64_t ori = in->rev, ts = rovlp->ts, te = rovlp->te, tl;
	if(ori) {
		ts = rg->seq[qn].len - rovlp->te;
        te = rg->seq[qn].len - rovlp->ts;
	}

	ts += in->ts; te += in->ts; 
	if(te <= ts) return 0;
	tl = te - ts; tl = tl*0.01; if(tl > 8) tl = 8;
	if((ts >= (rg->seq[tn].len+tl)) || (te >= (rg->seq[tn].len+tl))) return 0;
	if(ts > rg->seq[tn].len) ts = rg->seq[tn].len;
	if(te > rg->seq[tn].len) te = rg->seq[tn].len;
	if(te <= ts) return 0;

	memset(res, 0, sizeof(*res));
	res->qn = 0; res->qs = rovlp->qs; res->qe = rovlp->qe; 
	res->tn = tn; res->ts = ts; res->te = te; 
	res->el = rovlp->el; res->rev = (rovlp->rev == ori?0:1);
	if(adjust_rev && res->rev) {///for linear chaining
		res->ts = rg->seq[tn].len - te;
		res->te = rg->seq[tn].len - ts;
	}
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0xc(%rdi), %ebx
movq 0x20(%rdx), %r14
movslq (%r14,%rbx,8), %r10
xorl %eax, %eax
testq %r10, %r10
js 0x1daa5f
movq %rsi, -0x10(%rsp)
movq %r10, -0x18(%rsp)
movq 0x38(%rsp), %r10
movq (%rdi), %r12
movq %r12, %r15
shrq $0x20, %r15
leaq 0xbb898(%rip), %rsi     # 0x296230
movq 0x18(%rsi), %rsi
movl (%rsi,%r15,8), %r11d
movl (%rsi,%rbx,8), %ebp
movq 0x18(%rdi), %rsi
movq %rsi, -0x8(%rsp)
testl %esi, %esi
movq %rcx, -0x28(%rsp)
movq %rdx, -0x30(%rsp)
movq %rbx, -0x38(%rsp)
movl %r8d, -0x3c(%rsp)
movq %r9, -0x20(%rsp)
js 0x1da9d7
movl 0x10(%rdi), %ecx
movl 0x14(%rdi), %esi
subl %esi, %ebp
movl %ebp, %ebx
movl %ecx, %ebp
jmp 0x1da9e1
movl 0x10(%rdi), %ecx
movl 0x14(%rdi), %esi
subl %esi, %ebp
movl %ecx, %ebx
cmpl %r12d, %ebp
movl %r12d, %r9d
cmovll %ebp, %r9d
movl 0x8(%rdi), %edi
movl %r11d, %r13d
subl %edi, %r13d
cmpl %ebx, %r13d
movl %ebx, %r8d
cmovll %r13d, %r8d
cmpl %r10d, %r9d
jg 0x1daa5f
cmpl %r10d, %r8d
jg 0x1daa5f
leaq 0xbad49(%rip), %rax     # 0x295758
movl %edi, %edx
subl %r12d, %edx
cvtsi2ss %rdx, %xmm1
addl %r9d, %edx
addl %r8d, %edx
cvtsi2ss %rdx, %xmm2
movss 0x158(%rax), %xmm0
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1daa39
xorl %eax, %eax
jmp 0x1daa5f
subl %ecx, %esi
xorps %xmm1, %xmm1
cvtsi2ss %rsi, %xmm1
addl %r9d, %r8d
addl %esi, %r8d
xorps %xmm2, %xmm2
cvtsi2ss %r8, %xmm2
mulss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
movl $0x0, %eax
jbe 0x1daa6a
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %ebp, %r12d
jg 0x1dabed
cmpl %ebx, %r13d
jg 0x1dabed
movq -0x8(%rsp), %r10
shrl $0x1f, %r10d
movq -0x10(%rsp), %r11
movl 0xc(%r11), %eax
movl 0x10(%r11), %esi
je 0x1daaa7
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl (%r14,%r15,8), %edx
movl %edx, %edi
subl %esi, %edi
subl %eax, %edx
movl %edi, %eax
movl %edx, %esi
cmpl %eax, %esi
jbe 0x1daa35
movl %esi, %esi
movl %eax, %edx
movl %ecx, %r9d
movq %rsi, %rcx
subq %rdx, %rcx
movq %rcx, %xmm0
punpckldq 0x567bb(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
leaq (%r9,%rdx), %rdi
subpd 0x567bf(%rip), %xmm0    # 0x231290
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x6074b(%rip), %xmm1    # 0x23b230
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x5680f(%rip), %xmm1    # 0x231308
cvttsd2si %xmm1, %r8
andq %rdx, %r8
orq %rcx, %r8
cmpq $0x8, %r8
movl $0x8, %ecx
cmovbq %r8, %rcx
movq -0x18(%rsp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rdi
jae 0x1daa35
addq %rsi, %r9
cmpq %rcx, %r9
movl $0x0, %eax
jae 0x1daa5f
cmpq %rdx, %r9
cmovbq %r9, %rdx
cmpq %rdx, %rdi
jae 0x1daa5f
xorpd %xmm0, %xmm0
movq -0x28(%rsp), %r8
movupd %xmm0, 0xc(%r8)
movupd %xmm0, (%r8)
movq 0x4(%r11), %rax
movq %rax, 0x4(%r8)
movq -0x38(%rsp), %rax
movl %eax, 0xc(%r8)
movl %edi, 0x10(%r8)
movq %rdx, %r9
movl %edx, 0x14(%r8)
movl 0x20(%r11), %ecx
shll $0x17, %ecx
andl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x18(%r8)
movzbl 0x20(%r11), %esi
shrl $0x5, %esi
andl $0x1, %esi
xorl %edx, %edx
cmpl %esi, %r10d
setne %dl
shll $0x1f, %edx
orl %ecx, %edx
movl %edx, 0x18(%r8)
movl $0x1, %eax
cmpl $0x0, -0x3c(%rsp)
je 0x1daa5f
cmpl %esi, %r10d
je 0x1daa5f
movq -0x30(%rsp), %rax
movq 0x20(%rax), %rsi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x38(%rsp), %r10
movl (%rsi,%r10,8), %edx
andl %ecx, %edx
subl %r9d, %edx
movl %edx, 0x10(%r8)
movl $0x1, %eax
andl (%rsi,%r10,8), %ecx
subl %edi, %ecx
movl %ecx, 0x14(%r8)
jmp 0x1daa5f
cmpl %ebp, %r12d
jl 0x1dabfb
cmpl %ebx, %r13d
jge 0x1daa5f
movq -0x20(%rsp), %rsi
cmpl %esi, %edx
jl 0x1daa5f
cmpl %esi, %r8d
jl 0x1daa5f
addl %edi, %ebx
subl %ebx, %r11d
subl %ebp, %r12d
cmovlel %r11d, %r12d
cmpl $-0x2, %r12d
jne 0x1daa5f
jmp 0x1daa7c