// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movl $0x1, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e522d
movl $0x0, -0x4(%rbp)
jmp 0x2e55ca
movq -0x10(%rbp), %rdi
leaq 0xe0098(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0xe0083(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq 0x10(%rbp), %rax
movl %eax, %ecx
leaq 0xdf590(%rip), %rax     # 0x3c47f8
movss 0x158(%rax), %xmm0
movq -0x38(%rbp), %rax
movl %eax, %r8d
leaq -0x68(%rbp), %r9
callq 0x287f40
movl %eax, -0x4c(%rbp)
cmpl $-0x2, -0x4c(%rbp)
je 0x2e5295
movl $0x0, -0x4(%rbp)
jmp 0x2e55ca
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x2e530a
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
ja 0x2e533e
movl $0x0, -0x4(%rbp)
jmp 0x2e55ca
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x88(%rbp)
movaps 0x9ccb9(%rip), %xmm1    # 0x382010
movq -0x88(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x9ccb5(%rip), %xmm1    # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0xa64ae(%rip), %xmm1    # 0x38b830
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x9cc5b(%rip), %xmm1    # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x88(%rbp)
cmpq $0x8, -0x88(%rbp)
jbe 0x2e53c8
movq $0x8, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x48(%rbp), %rdx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq -0x88(%rbp), %rcx
cmpq %rcx, %rax
jae 0x2e5416
movq -0x80(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x48(%rbp), %rdx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq -0x88(%rbp), %rcx
cmpq %rcx, %rax
jb 0x2e5422
movl $0x0, -0x4(%rbp)
jmp 0x2e55ca
movq -0x78(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x48(%rbp), %rdx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x2e545c
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x48(%rbp), %rdx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x2e5496
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x78(%rbp), %rax
ja 0x2e54ac
movl $0x0, -0x4(%rbp)
jmp 0x2e55ca
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
movzbl %al, %edx
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1e, %edx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %ecx
movq -0x70(%rbp), %rsi
movl $0x1, %edx
xorl %eax, %eax
cmpq %rsi, %rcx
cmovel %eax, %edx
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x2e55c3
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e55c3
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x78(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)