// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x38, %rsp
movl 0xc(%rdi), %ebp
movq 0x20(%rdx), %r14
movslq (%r14,%rbp,8), %rbx
xorl %r11d, %r11d
testq %rbx, %rbx
js 0x1d0b09
movq %rdi, %r13
movq %rsi, %r15
movl %r8d, 0xc(%rsp)
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq 0x70(%rsp), %rcx
movl 0x4(%rdi), %r12d
leaq 0xba8c4(%rip), %rax     # 0x28b230
movq 0x18(%rax), %rax
movl (%rax,%r12,8), %esi
movl (%rax,%rbp,8), %edx
leaq 0xb9dda(%rip), %rax     # 0x28a758
movss 0x158(%rax), %xmm0
leaq 0x20(%rsp), %rax
movl %r9d, %r8d
movq %rax, %r9
callq 0x19c0d3
cmpl $-0x2, %eax
jne 0x1d0b06
movl 0x18(%r13), %eax
shrl $0x1f, %eax
movl 0xc(%r15), %ecx
movl 0x10(%r15), %edx
je 0x1d09c3
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl (%r14,%r12,8), %esi
movl %esi, %edi
subl %edx, %edi
subl %ecx, %esi
movl %edi, %ecx
movl %esi, %edx
xorl %r11d, %r11d
cmpl %ecx, %edx
jbe 0x1d0b09
movl %edx, %esi
movl %ecx, %edx
movl 0x10(%r13), %ecx
movq %rsi, %rdi
subq %rdx, %rdi
movq %rdi, %xmm0
punpckldq 0x54857(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
addq %rcx, %rdx
subpd 0x5485c(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x5e5d8(%rip), %xmm1    # 0x22efe0
cvttsd2si %xmm1, %rdi
movq %rdi, %r8
sarq $0x3f, %r8
subsd 0x5484c(%rip), %xmm1    # 0x225268
cvttsd2si %xmm1, %r9
andq %r8, %r9
orq %rdi, %r9
cmpq $0x8, %r9
movl $0x8, %edi
cmovbq %r9, %rdi
addq %rbx, %rdi
cmpq %rdi, %rdx
jae 0x1d0b09
addq %rsi, %rcx
cmpq %rdi, %rcx
jae 0x1d0b09
cmpq %rbx, %rcx
cmovaeq %rbx, %rcx
cmpq %rcx, %rdx
jae 0x1d0b09
cmpq %rbx, %rdx
cmovbq %rdx, %rbx
xorpd %xmm0, %xmm0
movq 0x18(%rsp), %r8
movupd %xmm0, 0xc(%r8)
movupd %xmm0, (%r8)
movl 0x4(%r15), %edx
movl %edx, 0x4(%r8)
movl 0x8(%r15), %edx
movl %edx, 0x8(%r8)
movl %ebp, 0xc(%r8)
movl %ebx, 0x10(%r8)
movl %ecx, 0x14(%r8)
movl 0x20(%r15), %edx
shll $0x17, %edx
andl $0x40000000, %edx       # imm = 0x40000000
movl $0xbfffffff, %esi       # imm = 0xBFFFFFFF
andl 0x18(%r8), %esi
orl %edx, %esi
movl %esi, 0x18(%r8)
movzbl 0x20(%r15), %edx
shrl $0x5, %edx
andl $0x1, %edx
xorl %edi, %edi
cmpl %edx, %eax
setne %dil
shll $0x1f, %edi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orl %edi, %esi
movl %esi, 0x18(%r8)
movl $0x1, %r11d
cmpl $0x0, 0xc(%rsp)
je 0x1d0b09
cmpl %edx, %eax
je 0x1d0b09
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl (%rax,%rbp,8), %esi
andl %edx, %esi
subl %ecx, %esi
movl %esi, 0x10(%r8)
andl (%rax,%rbp,8), %edx
subl %ebx, %edx
movl %edx, 0x14(%r8)
jmp 0x1d0b09
xorl %r11d, %r11d
movl %r11d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq