// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: cal_cigar_err(overlap_region*, long, long, long)
int64_t cal_cigar_err(overlap_region *z, int64_t s, int64_t e, int64_t is_back)///need debugging
{
	int64_t wn = z->w_list.n, wk, xk, ck; window_list *m; bit_extz_t ez; 
	int64_t ws, we, os, oe, ovlp, xl, yl, werr, err, tot;
	err = 0; tot = e - s; wk = xk = ck = -1;
	if(!wn) return INT32_MAX;

	if(!is_back) {
		wk = 0; 
		if(wn) {
			xk = z->w_list.a[wk].x_start; ck = 0;
		}
		while(wk < wn) {
			m = &(z->w_list.a[wk]); 
        	ws = m->x_start; we = m->x_end+1;
			os = MAX(s, ws); oe = MIN(e, we);
        	ovlp = ((oe>os)? (oe-os):0);
			if(ovlp) {
				xl = m->x_end+1-m->x_start;
				yl = m->y_end+1-m->y_start;
				if((is_ualn_win((*m))) || (is_est_aln((*m)))) {
					if(is_ualn_win((*m))) { //unmapped
						werr = MAX(xl, yl);///gen_err_unaligned(xl, yl);
					} else {
						werr = m->error;//shared window
					}
					if(ovlp < xl) {
						werr = (((double)ovlp)/((double)xl))*((double)werr);
					}
					//skip the whole window
					err += werr; xk = m->x_end+1; ck = m->clen;
				} else {
					if(ovlp == xl) { //skip the whole window
						err += m->error; xk = m->x_end+1; ck = m->clen;
					} else {
						set_bit_extz_t(ez, (*z), wk); 
						err += retrieve_cigar_err_dir(&ez, os, oe, &xk, &ck, is_back);
					}                
				}
			}
			tot -= ovlp; 
			if(xk >= e) break;//[min_w, max_w] && [s, e)
			wk++; if(wk >= wn) break;
			xk = z->w_list.a[wk].x_start; ck = 0;//reset
		}
	} else {
		wk = wn-1;
		if(wn) {
			xk = z->w_list.a[wk].x_end+1; ck = z->w_list.a[wk].clen-1;
		}
		while(wk >= 0) {
			m = &(z->w_list.a[wk]); 
        	ws = m->x_start; we = m->x_end+1;
			os = MAX(s, ws); oe = MIN(e, we);
        	ovlp = ((oe>os)? (oe-os):0);
			if(ovlp) {
				xl = m->x_end+1-m->x_start;
				yl = m->y_end+1-m->y_start;
				if((is_ualn_win((*m))) || (is_est_aln((*m)))) {
					if(is_ualn_win((*m))) { //unmapped
						werr = MAX(xl, yl);///gen_err_unaligned(xl, yl);
					} else {
						werr = m->error;//shared window
					}
					if(ovlp < xl) {
						werr = (((double)ovlp)/((double)xl))*((double)werr);
					}
					//skip the whole window
					err += werr; xk = m->x_start; ck = -1;
				} else {
					if(ovlp == xl) { //skip the whole window
						err += m->error; xk = m->x_start; ck = -1;
					} else {
						set_bit_extz_t(ez, (*z), wk); 
						err += retrieve_cigar_err_dir(&ez, os, oe, &xk, &ck, is_back);
					}                
				}
			}
			tot -= ovlp; 
			if(xk <= s) break;//[s, e)
			wk--; if(wk < 0) break;
			xk = z->w_list.a[wk].x_end+1; ck = z->w_list.a[wk].clen-1;//reset
		}
	}
	assert(!tot);
	return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq 0x48(%rdi), %r15
movq $-0x1, %rax
movq %rax, 0x8(%rsp)
movq %rax, (%rsp)
testq %r15, %r15
je 0x1bdb3c
movq %rdx, %r11
movq %rsi, %r14
movq %rdx, %rbx
subq %rsi, %rbx
movq %rdi, 0x18(%rsp)
movq 0x58(%rdi), %r13
testq %rcx, %rcx
movq %rdx, 0x20(%rsp)
je 0x1bdb46
movq %rcx, 0x10(%rsp)
movq %r15, %rax
shlq $0x5, %rax
addq %rax, %r13
addq $-0x4, %r13
xorl %ebp, %ebp
movslq -0x18(%r13), %rax
incq %rax
movq %rax, (%rsp)
movl (%r13), %eax
decl %eax
movq %rax, 0x8(%rsp)
testq %r15, %r15
jle 0x1bdd0e
movl -0x1c(%r13), %r8d
movslq %r8d, %rax
movslq -0x18(%r13), %rcx
incq %rcx
cmpq %r14, %rax
movq %r14, %rsi
cmovgq %rax, %rsi
cmpq %r11, %rcx
movq %r11, %rdx
cmovlq %rcx, %rdx
movq %rdx, %r12
subq %rsi, %r12
movl $0x0, %edi
cmovleq %rdi, %r12
testq %r12, %r12
je 0x1bdb19
subl %r8d, %ecx
movslq %ecx, %r9
movl -0x10(%r13), %r10d
subl -0x14(%r13), %r10d
movswq -0x8(%r13), %rdi
cmpq $0x7fff, %rdi           # imm = 0x7FFF
jne 0x1bda32
cmpl $0x0, (%r13)
jne 0x1bda2a
cmpw $0x0, -0xa(%r13)
js 0x1bdabd
cmpl $0x7fff, %edi           # imm = 0x7FFF
je 0x1bda3d
cmpl $0x0, (%r13)
je 0x1bdabd
cmpq %r9, %r12
je 0x1bdb09
movl -0x4(%r13), %eax
addq %rax, %rax
movq 0x18(%rsp), %rcx
addq 0x70(%rcx), %rax
movq %rax, 0xe8(%rsp)
movl (%r13), %eax
movq %rax, 0xe0(%rsp)
movq %rax, 0xd8(%rsp)
movl %r8d, 0x4c(%rsp)
movl -0x18(%r13), %eax
movl %eax, 0x50(%rsp)
movl -0x14(%r13), %eax
movl %eax, 0x40(%rsp)
movl -0x10(%r13), %eax
movl %eax, 0x44(%rsp)
movswl -0x8(%r13), %eax
movl %eax, 0x5c(%rsp)
movl %eax, 0x58(%rsp)
leaq 0x30(%rsp), %rdi
movq %rsp, %rcx
leaq 0x8(%rsp), %r8
movq 0x10(%rsp), %r9
callq 0x1bd713
movq 0x20(%rsp), %r11
addq %rax, %rbp
jmp 0x1bdb19
cmpl $0x7fff, %edi           # imm = 0x7FFF
jne 0x1bdae1
cmpl $0x0, (%r13)
jne 0x1bdae1
cmpw $0x0, -0xa(%r13)
jns 0x1bdae1
incl %r10d
cmpl %r10d, %ecx
cmovgl %ecx, %r10d
movslq %r10d, %rdi
cmpq %r9, %r12
jge 0x1bdb09
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %rdi
addq %rdi, %rbp
movq %rax, (%rsp)
movq $-0x1, 0x8(%rsp)
subq %r12, %rbx
cmpq $0x1, %r15
je 0x1bdd0e
addq $-0x20, %r13
decq %r15
cmpq %r14, (%rsp)
jg 0x1bd9a2
jmp 0x1bdd0e
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
jmp 0x1bdd13
testq %r15, %r15
movl $0x0, %eax
cmovgq %r15, %rax
negq %rax
movq %rax, 0x28(%rsp)
addq $0x1c, %r13
movl $0x1, %r12d
xorl %ebp, %ebp
movq 0x28(%rsp), %rax
addq %r12, %rax
movslq -0x1c(%r13), %rcx
movq %rcx, (%rsp)
movq $0x0, 0x8(%rsp)
cmpq $0x1, %rax
je 0x1bdd0e
movq %rbp, 0x10(%rsp)
movslq -0x1c(%r13), %rdi
movslq -0x18(%r13), %rax
incq %rax
cmpq %r14, %rdi
movq %r14, %rsi
cmovgq %rdi, %rsi
cmpq %r11, %rax
movq %r11, %rdx
cmovlq %rax, %rdx
movq %rdx, %rbp
subq %rsi, %rbp
movl $0x0, %ecx
cmovleq %rcx, %rbp
testq %rbp, %rbp
je 0x1bdce4
movl %eax, %r8d
subl %edi, %r8d
movslq %r8d, %r9
movl -0x10(%r13), %r10d
subl -0x14(%r13), %r10d
movswq -0x8(%r13), %rcx
cmpq $0x7fff, %rcx           # imm = 0x7FFF
jne 0x1bdbff
cmpl $0x0, (%r13)
jne 0x1bdbf7
cmpw $0x0, -0xa(%r13)
js 0x1bdc85
cmpl $0x7fff, %ecx           # imm = 0x7FFF
je 0x1bdc06
cmpl $0x0, (%r13)
je 0x1bdc85
cmpq %r9, %rbp
je 0x1bdcd2
movl -0x4(%r13), %eax
addq %rax, %rax
movq 0x18(%rsp), %rcx
addq 0x70(%rcx), %rax
movq %rax, 0xe8(%rsp)
movl (%r13), %eax
movq %rax, 0xe0(%rsp)
movq %rax, 0xd8(%rsp)
movl %edi, 0x4c(%rsp)
movl -0x18(%r13), %eax
movl %eax, 0x50(%rsp)
movl -0x14(%r13), %eax
movl %eax, 0x40(%rsp)
movl -0x10(%r13), %eax
movl %eax, 0x44(%rsp)
movswl -0x8(%r13), %eax
movl %eax, 0x5c(%rsp)
movl %eax, 0x58(%rsp)
leaq 0x30(%rsp), %rdi
movq %rsp, %rcx
leaq 0x8(%rsp), %r8
xorl %r9d, %r9d
callq 0x1bd713
movq 0x20(%rsp), %r11
addq %rax, 0x10(%rsp)
jmp 0x1bdce4
cmpl $0x7fff, %ecx           # imm = 0x7FFF
jne 0x1bdca9
cmpl $0x0, (%r13)
jne 0x1bdca9
cmpw $0x0, -0xa(%r13)
jns 0x1bdca9
incl %r10d
cmpl %r10d, %r8d
cmovgl %r8d, %r10d
movslq %r10d, %rcx
cmpq %r9, %rbp
jge 0x1bdcd2
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r8d, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %rcx
addq %rcx, 0x10(%rsp)
movq %rax, (%rsp)
movl (%r13), %eax
movq %rax, 0x8(%rsp)
subq %rbp, %rbx
cmpq %r11, (%rsp)
jge 0x1bdd09
leaq 0x1(%r12), %rax
addq $0x20, %r13
cmpq %r15, %r12
movq %rax, %r12
movq 0x10(%rsp), %rbp
jl 0x1bdb66
jmp 0x1bdd0e
movq 0x10(%rsp), %rbp
testq %rbx, %rbx
jne 0x1bdd28
movq %rbp, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x69d28(%rip), %rdi     # 0x227a57
leaq 0x75c55(%rip), %rsi     # 0x23398b
leaq 0x77d2a(%rip), %rcx     # 0x235a67
movl $0x2af9, %edx           # imm = 0x2AF9
callq 0x2110