// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rsi, %r9
movq %rdi, %r11
movq %rcx, %rdi
movl 0x4(%r11), %eax
movq %rax, 0x38(%rsp)
movl %eax, %ecx
xorl %r13d, %r13d
movq %rcx, %rax
xorl %edx, %edx
idivq %rsi
subq %rdx, %rcx
movq %r12, %rax
subq %rcx, %rax
cqto
idivq %rsi
movq %rax, %r10
movq %rdi, %rax
subq %rcx, %rax
cqto
idivq %rsi
movq %rax, %r8
decq %rax
movl $0x0, %r14d
cmpq %rax, %r10
jge 0x19fe4a
movq 0x58(%r11), %rcx
movq %r10, %rax
notq %rax
addq %r8, %rax
movq %r10, %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
addq $0x34, %rcx
xorl %r14d, %r14d
xorl %r13d, %r13d
movl -0x10(%rcx), %edx
subl -0x14(%rcx), %edx
incl %edx
movslq %edx, %rdx
cmpl $-0x1, -0x8(%rcx)
movq %rdx, %rsi
je 0x19fe3b
movswq (%rcx), %rsi
addq %rsi, %r13
addq %rdx, %r14
addq $0x20, %rcx
decq %rax
jne 0x19fe23
movq 0x58(%r11), %rax
movq %r10, %r15
shlq $0x5, %r15
movslq (%rax,%r15), %rbx
cmpq %r12, %rbx
movq %r12, %rcx
cmovgq %rbx, %rcx
movslq 0x4(%rax,%r15), %rdx
cmpq %rdi, %rdx
cmovgeq %rdi, %rdx
xorl %ebp, %ebp
subq %rcx, %rdx
leaq 0x1(%rdx), %rcx
cmovgeq %rcx, %rbp
testq %rbp, %rbp
movq %r12, 0x40(%rsp)
je 0x19ff4c
movq 0x58(%r11), %rsi
cmpl $-0x1, 0xc(%rsi,%r15)
movq %rbp, %rbx
je 0x19feb9
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, %rbx
movq %r8, %r12
shlq $0x5, %r12
movslq (%rsi,%r12), %r10
movq %r8, %rdx
movq 0x40(%rsp), %r8
cmpq %r8, %r10
movq %r8, %rax
cmovgq %r10, %rax
movslq 0x4(%rsi,%r12), %rcx
cmpq %rdi, %rcx
cmovgeq %rdi, %rcx
xorl %r15d, %r15d
subq %rax, %rcx
leaq 0x1(%rcx), %rax
cmovgeq %rax, %r15
testq %r15, %r15
je 0x19ffd5
movq 0x58(%r11), %rcx
cmpl $-0x1, 0xc(%rcx,%r12)
movq %r15, %rax
je 0x19ff23
addq %r12, %rcx
movswq 0x14(%rcx), %rax
imulq %r15, %rax
movl 0x4(%rcx), %edx
subl (%rcx), %edx
incl %edx
movslq %edx, %rcx
cqto
idivq %rcx
addq %r13, %rbx
addq %rax, %rbx
addq %r14, %rbp
addq %r15, %rbp
cvtsi2sd %rbx, %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, %rax
movq 0xea08a(%rip), %rcx     # 0x289fe0
movq %rdi, 0x8(%rsp)
movq (%rcx), %rdi
movl 0x48(%r11), %edx
movl (%r11), %ecx
movl 0x8(%r11), %esi
movq %rsi, 0x18(%rsp)
movl 0x4(%rax), %esi
movq %rsi, 0x20(%rsp)
movl 0xc(%rax), %eax
movq %rax, 0x10(%rsp)
subq $0x8, %rsp
leaq 0x9412d(%rip), %rsi     # 0x2340b6
movq %r11, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq %r12, %r8
movq %r9, %r12
movq 0x10(%rsp), %r9
xorl %eax, %eax
pushq 0x18(%rsp)
pushq %r10
pushq 0x30(%rsp)
pushq 0x58(%rsp)
pushq %r12
pushq 0x50(%rsp)
pushq %rbx
callq 0x22b0
movq 0x68(%rsp), %r8
movq 0x48(%rsp), %rdi
movq %r12, %r9
movq 0x70(%rsp), %r11
addq $0x40, %rsp
jmp 0x19fe8a
addq %r12, %rsi
movq 0xea001(%rip), %rax     # 0x289fe0
movq %rdi, 0x8(%rsp)
movq (%rax), %rdi
movq %rdx, 0x28(%rsp)
movl 0x48(%r11), %edx
movl (%r11), %ecx
movl 0x4(%r11), %eax
movq %rax, 0x20(%rsp)
movl 0x8(%r11), %eax
movq %rax, 0x18(%rsp)
movl 0x4(%rsi), %eax
movq %rax, 0x38(%rsp)
movl 0xc(%rsi), %eax
movq %rax, 0x10(%rsp)
subq $0x8, %rsp
leaq 0x9412c(%rip), %rsi     # 0x23414c
movq %r11, 0x38(%rsp)
movq %r9, %r11
movq 0x10(%rsp), %r9
xorl %eax, %eax
pushq 0x18(%rsp)
pushq 0x38(%rsp)
pushq 0x30(%rsp)
pushq 0x40(%rsp)
pushq %r11
pushq 0x68(%rsp)
pushq %r10
callq 0x22b0
movq 0x70(%rsp), %r11
addq $0x40, %rsp
jmp 0x19fef9