// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: es_win_err(overlap_region*, long, long, long)
double es_win_err(overlap_region* o, int64_t winLen, int64_t s, int64_t e)
{
	int64_t si, ei, os, k, tErr = 0, tLen = 0, minE, maxS, ov;
	os = (o->x_pos_s/winLen)*winLen;
	si = (s-os)/winLen; ei = (e-os)/winLen;
	for (k = si+1; k <= ei-1; k++) {
		tLen += o->w_list.a[k].x_end+1-o->w_list.a[k].x_start;
		if(o->w_list.a[k].y_end != -1) {
			tErr += o->w_list.a[k].error;
		} else {
			tErr += o->w_list.a[k].x_end+1-o->w_list.a[k].x_start;
		}
	}

	k = si;
	maxS = MAX(s, (int64_t)(o->w_list.a[k].x_start)); minE = MIN(e, (int64_t)(o->w_list.a[k].x_end)) + 1;
	ov = minE > maxS? minE - maxS:0; 
	if(ov == 0) {
		fprintf(stderr, "WARNNING-1, o->w_list.n->%u, o->x_id->%u, s->%ld, e->%ld, w_list_s->%d, w_list_e->%d, winLen->%ld, o->x_pos_s->%u, o->x_pos_e->%u, si->%ld, flag->%d\n", 
		(uint32_t)o->w_list.n, o->x_id, s, e, o->w_list.a[k].x_start, o->w_list.a[k].x_end, winLen, o->x_pos_s, o->x_pos_e, si, o->w_list.a[k].y_end);
	}
	tLen += ov/**o->w_list[k].x_end+1-o->w_list[k].x_start**/;
	if(o->w_list.a[k].y_end != -1) {
		tErr += (ov*o->w_list.a[k].error)/(o->w_list.a[k].x_end+1-o->w_list.a[k].x_start);
	} else {
		tErr += ov/**o->w_list[k].x_end+1-o->w_list[k].x_start**/;
	}

	k = ei;
	maxS = MAX(s, (int64_t)(o->w_list.a[k].x_start)); minE = MIN(e, (int64_t)(o->w_list.a[k].x_end)) + 1;
	ov = minE > maxS? minE - maxS:0; 
	if(ov == 0) {
		fprintf(stderr, "WARNNING-2, o->w_list.n->%u, o->x_id->%u, s->%ld, e->%ld, w_list_s->%d, w_list_e->%d, winLen->%ld, o->x_pos_s->%u, o->x_pos_e->%u, ei->%ld, flag->%d\n", 
		(uint32_t)o->w_list.n, o->x_id, s, e, o->w_list.a[k].x_start, o->w_list.a[k].x_end, winLen, o->x_pos_s, o->x_pos_e, ei, o->w_list.a[k].y_end);
	}
	tLen += ov/**o->w_list[k].x_end+1-o->w_list[k].x_start**/;
	if(o->w_list.a[k].y_end != -1) {
		tErr += (ov*o->w_list.a[k].error)/(o->w_list.a[k].x_end+1-o->w_list.a[k].x_start);
	} else {
		tErr += ov/**o->w_list[k].x_end+1-o->w_list[k].x_start**/;
	}

	return ((double)tErr)/((double)tLen);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r8
movq %rdi, %rbx
movl 0x4(%rdi), %eax
movq %rax, 0x18(%rsp)
movl %eax, %edi
xorl %r14d, %r14d
movq %rdi, %rax
xorl %edx, %edx
idivq %rsi
subq %rdx, %rdi
movq %r8, 0x8(%rsp)
subq %rdi, %r8
movq %r8, %rax
cqto
idivq %rsi
movq %rax, %r10
movq %rcx, %rax
subq %rdi, %rax
cqto
movq %rsi, 0x28(%rsp)
idivq %rsi
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
decq %rax
movq %r10, %r15
shlq $0x5, %r15
leaq 0x34(%r15), %r9
movq %r10, %rdx
xorl %r12d, %r12d
cmpq %rax, %rdx
jge 0x160e3a
movq 0x58(%rbx), %rsi
movl -0x10(%rsi,%r9), %edi
subl -0x14(%rsi,%r9), %edi
incl %edi
movslq %edi, %rdi
cmpl $-0x1, -0x8(%rsi,%r9)
movq %rdi, %r8
je 0x160e2b
movswq (%rsi,%r9), %r8
addq %rdi, %r12
addq %r8, %r14
addq $0x20, %r9
incq %rdx
jmp 0x160e03
movq 0x58(%rbx), %rsi
movslq (%rsi,%r15), %r13
movq 0x8(%rsp), %r8
cmpq %r8, %r13
movq %r8, %rax
cmovgq %r13, %rax
movslq 0x4(%rsi,%r15), %r11
cmpq %rcx, %r11
movq %rcx, 0x30(%rsp)
cmovlq %r11, %rcx
xorl %ebp, %ebp
subq %rax, %rcx
leaq 0x1(%rcx), %rax
cmovgeq %rax, %rbp
testq %rbp, %rbp
je 0x160f33
cmpl $-0x1, 0xc(%rsi,%r15)
movq %rbp, %r13
je 0x160ea3
addq %rsi, %r15
movswq 0x14(%r15), %rax
imulq %rbp, %rax
movl 0x4(%r15), %ecx
subl (%r15), %ecx
incl %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movq %rax, %r13
movq 0x20(%rsp), %rdx
shlq $0x5, %rdx
movslq (%rsi,%rdx), %r10
cmpq %r8, %r10
movq %r8, %rax
cmovgq %r10, %rax
movslq 0x4(%rsi,%rdx), %r11
movq 0x30(%rsp), %r9
cmpq %r9, %r11
movq %r9, %rcx
cmovlq %r11, %rcx
xorl %r15d, %r15d
subq %rax, %rcx
leaq 0x1(%rcx), %rax
cmovgeq %rax, %r15
testq %r15, %r15
je 0x160f99
cmpl $-0x1, 0xc(%rsi,%rdx)
movq %r15, %rax
je 0x160f0a
addq %rdx, %rsi
movswq 0x14(%rsi), %rax
imulq %r15, %rax
movl 0x4(%rsi), %ecx
subl (%rsi), %ecx
incl %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
addq %r14, %r13
addq %rax, %r13
addq %r12, %rbp
addq %r15, %rbp
cvtsi2sd %r13, %xmm0
cvtsi2sd %rbp, %xmm1
divsd %xmm1, %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %r15, %rsi
movq 0xf20a3(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
movl 0x48(%rbx), %edx
movl (%rbx), %ecx
movl 0x8(%rbx), %eax
movq %rax, 0x10(%rsp)
movl 0xc(%rsi), %eax
movq %rax, 0x38(%rsp)
subq $0x8, %rsp
leaq 0x912ee(%rip), %rsi     # 0x1f224e
movq 0x10(%rsp), %r8
movq 0x38(%rsp), %r9
xorl %eax, %eax
pushq 0x40(%rsp)
pushq %r10
pushq 0x28(%rsp)
pushq 0x38(%rsp)
pushq 0x50(%rsp)
pushq %r11
pushq %r13
callq 0x22b0
movq 0x48(%rsp), %r8
addq $0x40, %rsp
movq 0x58(%rbx), %rsi
jmp 0x160e78
addq %rdx, %rsi
movq 0xf203d(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
movq %rdx, 0x20(%rsp)
movl 0x48(%rbx), %edx
movl (%rbx), %ecx
movl 0x4(%rbx), %eax
movq %rax, 0x8(%rsp)
movl 0x8(%rbx), %eax
movq %rax, 0x18(%rsp)
movl 0xc(%rsi), %eax
movq %rax, 0x10(%rsp)
subq $0x8, %rsp
leaq 0x91311(%rip), %rsi     # 0x1f22e4
xorl %eax, %eax
pushq 0x18(%rsp)
pushq 0x50(%rsp)
pushq 0x30(%rsp)
pushq 0x28(%rsp)
pushq 0x50(%rsp)
pushq %r11
pushq %r10
callq 0x22b0
movq 0x60(%rsp), %rdx
addq $0x40, %rsp
movq 0x58(%rbx), %rsi
jmp 0x160ee5