// File: /workspace/github_cpp_makefile_star2_O3/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, %r9
movq %rdi, %r8
movl 0x4(%rdi), %r11d
movl %r11d, %edi
xorl %ebx, %ebx
movq %rdi, %rax
xorl %edx, %edx
idivq %rsi
subq %rdx, %rdi
movq %r9, 0x8(%rsp)
subq %rdi, %r9
movq %r9, %rax
cqto
idivq %rsi
movq %rax, %r10
movq %rcx, %rax
subq %rdi, %rax
cqto
movq %rsi, 0x28(%rsp)
idivq %rsi
leaq -0x1(%rax), %rdx
movq 0x58(%r8), %rsi
movl $0x0, %r13d
cmpq %rdx, %r10
jge 0x1a8bcc
movq %r10, %r14
notq %r14
addq %rax, %r14
movq %r10, %rdx
shlq $0x5, %rdx
leaq (%rdx,%rsi), %r9
addq $0x34, %r9
xorl %r13d, %r13d
xorl %ebx, %ebx
movl -0x10(%r9), %edx
subl -0x14(%r9), %edx
incl %edx
movslq %edx, %rdx
cmpl $-0x1, -0x8(%r9)
movq %rdx, %rdi
je 0x1a8bbd
movswq (%r9), %rdi
addq %rdi, %rbx
addq %rdx, %r13
addq $0x20, %r9
decq %r14
jne 0x1a8ba2
movq %rax, 0x30(%rsp)
movq %r10, %r15
shlq $0x5, %r15
movslq (%rsi,%r15), %r14
movq 0x8(%rsp), %rdi
cmpq %rdi, %r14
movq %rdi, %rax
cmovgq %r14, %rax
movslq 0x4(%rsi,%r15), %r12
cmpq %rcx, %r12
movq %rcx, 0x38(%rsp)
cmovlq %r12, %rcx
xorl %ebp, %ebp
subq %rax, %rcx
leaq 0x1(%rcx), %rax
cmovgeq %rax, %rbp
testq %rbp, %rbp
je 0x1a8cd1
cmpl $-0x1, 0xc(%rsi,%r15)
movq %rbp, %r14
movq 0x30(%rsp), %r9
je 0x1a8c42
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, %r14
movq %r9, %r12
shlq $0x5, %r12
movslq (%rsi,%r12), %r10
cmpq %rdi, %r10
movq %rdi, %rax
cmovgq %r10, %rax
movslq 0x4(%rsi,%r12), %r11
movq 0x38(%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 0x1a8d42
cmpl $-0x1, 0xc(%rsi,%r12)
movq %r15, %rax
je 0x1a8ca8
addq %r12, %rsi
movswq 0x14(%rsi), %rax
imulq %r15, %rax
movl 0x4(%rsi), %ecx
subl (%rsi), %ecx
incl %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
addq %rbx, %r14
addq %rax, %r14
addq %r13, %rbp
addq %r15, %rbp
cvtsi2sd %r14, %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 0xec305(%rip), %rax     # 0x294fe0
movq (%rax), %rdi
movl 0x48(%r8), %edx
movl (%r8), %ecx
movl 0x8(%r8), %eax
movq %rax, 0x18(%rsp)
movl 0xc(%rsi), %eax
movq %rax, 0x10(%rsp)
subq $0x8, %rsp
leaq 0x97685(%rip), %rsi     # 0x240386
movq %r8, 0x28(%rsp)
movq 0x10(%rsp), %r8
movq 0x40(%rsp), %r9
xorl %eax, %eax
pushq 0x18(%rsp)
pushq %r10
pushq 0x30(%rsp)
pushq %r11
pushq 0x50(%rsp)
pushq %r12
pushq %r14
callq 0x22b0
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %r8
addq $0x40, %rsp
movq 0x58(%r8), %rsi
jmp 0x1a8c12
addq %r12, %rsi
movq 0xec294(%rip), %rax     # 0x294fe0
movq (%rax), %rdi
movl 0x48(%r8), %edx
movl (%r8), %ecx
movl 0x4(%r8), %eax
movq %rax, 0x18(%rsp)
movl 0x8(%r8), %eax
movq %rax, 0x10(%rsp)
movl 0xc(%rsi), %eax
movq %rax, 0x40(%rsp)
subq $0x8, %rsp
leaq 0x976a1(%rip), %rsi     # 0x24041c
movq %r8, 0x28(%rsp)
movq 0x10(%rsp), %r8
xorl %eax, %eax
pushq 0x48(%rsp)
pushq 0x40(%rsp)
pushq 0x28(%rsp)
pushq 0x38(%rsp)
pushq 0x50(%rsp)
pushq %r11
pushq %r10
callq 0x22b0
addq $0x40, %rsp
movq 0x20(%rsp), %rax
movq 0x58(%rax), %rsi
jmp 0x1a8c82