// File: /workspace/github_cpp_makefile_star2_O2/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), %r15d
movq 0x20(%rdx), %r14
movslq (%r14,%r15,8), %rbx
xorl %r11d, %r11d
testq %rbx, %rbx
js 0x18d7e6
movq %rdi, %r13
movq %rsi, %rbp
movl %r8d, 0xc(%rsp)
movq %rdx, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq 0x70(%rsp), %rcx
movl 0x4(%rdi), %r12d
leaq 0xc6bc2(%rip), %rax     # 0x254230
movq 0x18(%rax), %rax
movl (%rax,%r12,8), %esi
movl (%rax,%r15,8), %edx
leaq 0xc60d7(%rip), %rax     # 0x253758
movss 0x158(%rax), %xmm0
leaq 0x20(%rsp), %rax
movl %r9d, %r8d
movq %rax, %r9
callq 0x15d560
cmpl $-0x2, %eax
jne 0x18d7e3
movl 0x18(%r13), %eax
shrl $0x1f, %eax
movl 0xc(%rbp), %ecx
movl 0x10(%rbp), %edx
je 0x18d6c4
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 0x18d7e6
movl %edx, %esi
movl %ecx, %ecx
movl 0x10(%r13), %edx
movq %rsi, %rdi
subq %rcx, %rdi
movq %rdi, %xmm0
punpckldq 0x55b86(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
addq %rdx, %rcx
subpd 0x55b8b(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x5fa17(%rip), %xmm1    # 0x1ed120
cvttsd2si %xmm1, %rdi
movq %rdi, %r8
sarq $0x3f, %r8
subsd 0x55b7b(%rip), %xmm1    # 0x1e3298
cvttsd2si %xmm1, %r9
andq %r8, %r9
orq %rdi, %r9
cmpq $0x8, %r9
pushq $0x8
popq %rdi
cmovbq %r9, %rdi
addq %rbx, %rdi
cmpq %rdi, %rcx
jae 0x18d7e6
addq %rsi, %rdx
cmpq %rdi, %rdx
jae 0x18d7e6
cmpq %rbx, %rdx
cmovbq %rdx, %rbx
cmpq %rbx, %rcx
jae 0x18d7e6
xorpd %xmm0, %xmm0
movq 0x18(%rsp), %r8
movupd %xmm0, 0xc(%r8)
movupd %xmm0, (%r8)
movq 0x4(%rbp), %rdx
movq %rdx, 0x4(%r8)
movl %r15d, 0xc(%r8)
movl %ecx, 0x10(%r8)
movl %ebx, 0x14(%r8)
movl 0x20(%rbp), %esi
shll $0x17, %esi
andl $0x40000000, %esi       # imm = 0x40000000
movl %esi, 0x18(%r8)
movzbl 0x20(%rbp), %edx
shrl $0x5, %edx
andl $0x1, %edx
xorl %edi, %edi
cmpl %edx, %eax
setne %dil
shll $0x1f, %edi
orl %esi, %edi
movl %edi, 0x18(%r8)
pushq $0x1
popq %r11
cmpl $0x0, 0xc(%rsp)
je 0x18d7e6
cmpl %edx, %eax
je 0x18d7e6
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl (%rax,%r15,8), %esi
andl %edx, %esi
subl %ebx, %esi
movl %esi, 0x10(%r8)
andl (%rax,%r15,8), %edx
subl %ecx, %edx
movl %edx, 0x14(%r8)
jmp 0x18d7e6
xorl %r11d, %r11d
movl %r11d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq