// File: chhylp123[P]hifiasm/inter.cpp
// Function: extract_nccov(ma_hit_t*, uc_block_t*, asg_t const*, ul_ov_t*, unsigned int, long, long)
uint32_t extract_nccov(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 tn; int64_t os, oe, s_shift, e_shift, tt, qs, qe, ts, te; 
	tn = Get_tn((*in)); if(rg->seq[tn].del) return 0;	
	os = MAX(rovlp->ts, Get_qs((*in)));
	oe = MIN(rovlp->te, Get_qe((*in)));
	if(oe <= os) return 0;

	///[os, oe) -> rovlp->t*
	s_shift = get_offset_adjust(os-rovlp->ts, rovlp->te-rovlp->ts, rovlp->qe-rovlp->qs);
    e_shift = get_offset_adjust(rovlp->te-oe, rovlp->te-rovlp->ts, rovlp->qe-rovlp->qs);
	if(rovlp->rev) {
		tt = s_shift; s_shift = e_shift; e_shift = tt;
	}
	qs = rovlp->qs + s_shift; qe = ((int64_t)rovlp->qe)-e_shift; 
	if(qs >= qe) return 0;

	///[os, oe) -> in->q*
	s_shift = get_offset_adjust(os-Get_qs((*in)), Get_qe((*in))-Get_qs((*in)), Get_te((*in))-Get_ts((*in)));
	e_shift = get_offset_adjust(Get_qe((*in))-oe, Get_qe((*in))-Get_qs((*in)), Get_te((*in))-Get_ts((*in)));
	if(in->rev) {
		tt = s_shift; s_shift = e_shift; e_shift = tt;
	}
	ts = Get_ts((*in)) + s_shift; te = ((int64_t)Get_te((*in)))-e_shift;
	if(ts >= te) return 0;

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

	// fprintf(stderr, "\n[M::%s::id->%u::%c] q::[%u, %u), t::[%u, %u)\n", 
	// 			__func__, rovlp->hid, "+-"[rovlp->rev], rovlp->qs, rovlp->qe, rovlp->ts, rovlp->te);
	// fprintf(stderr, "+[M::%s::] qn::%u, q::[%u, %u), %c, tn::%u, t::[%u, %u)\n", 
	// 			__func__, Get_qn((*in)), Get_qs((*in)), in->qe, "+-"[in->rev], in->tn, in->ts, in->te);
	// fprintf(stderr, "-[M::%s::] qn::%u, q::[%u, %u), %c, tn::%u, t::[%u, %u)\n", 
	// 			__func__, res->qn, res->qs, res->qe, "+-"[res->rev], res->tn, res->ts, res->te);
	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)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e5635
movl $0x0, -0x4(%rbp)
jmp 0x2e5989
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl %ecx, %eax
jb 0x2e5656
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x8c(%rbp)
jmp 0x2e5663
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x2e568e
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x90(%rbp)
jmp 0x2e569b
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x2e56bd
movl $0x0, -0x4(%rbp)
jmp 0x2e5989
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0xc(%rcx), %ecx
subq %rcx, %rax
movl %eax, %edi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x18(%rbp), %rax
subl 0xc(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x18(%rbp), %rax
subl 0x4(%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
subq -0x50(%rbp), %rax
movl %eax, %edi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x18(%rbp), %rax
subl 0xc(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x18(%rbp), %rax
subl 0x4(%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
cmpb $0x0, %al
je 0x2e5750
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
subq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jl 0x2e5784
movl $0x0, -0x4(%rbp)
jmp 0x2e5989
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movl %eax, %edi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x10(%rbp), %rax
movq (%rax), %rax
subl %eax, %esi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rax
subl 0x10(%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subq -0x50(%rbp), %rax
movl %eax, %edi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x10(%rbp), %rax
movq (%rax), %rax
subl %eax, %esi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rax
subl 0x10(%rax), %edx
callq 0xc14d0
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x0, %eax
je 0x2e5822
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
addq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
subq -0x60(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x88(%rbp), %rax
jl 0x2e585c
movl $0x0, -0x4(%rbp)
jmp 0x2e5989
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x88(%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, %ecx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
movl %eax, %esi
movl $0x1, %edx
xorl %eax, %eax
cmpl %esi, %ecx
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 0x2e5982
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e5982
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x88(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%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, 0x14(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)