// File: /workspace/github_cpp_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movq 0x48(%rdi), %r15
testq %r15, %r15
je 0x1c797c
movq %rdx, %r11
movq %rsi, %r14
movq %rdx, %rbx
subq %rsi, %rbx
movq %rdi, 0x38(%rsp)
movq 0x58(%rdi), %r13
testq %rcx, %rcx
movq %rdx, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
je 0x1c7986
movq %rcx, 0x30(%rsp)
movq %r15, %rax
shlq $0x5, %rax
leaq (%rax,%r13), %r12
addq $-0x4, %r12
movq $0x0, 0x10(%rsp)
movslq -0x18(%r12), %rdi
leaq 0x1(%rdi), %rcx
movq %rcx, (%rsp)
movl (%r12), %r9d
leal -0x1(%r9), %eax
movq %rax, 0x20(%rsp)
testq %r15, %r15
jle 0x1c7b44
movl -0x1c(%r12), %r10d
movslq %r10d, %rax
cmpq %r14, %rax
movq %r14, %rsi
cmovgq %rax, %rsi
cmpq %r11, %rcx
movq %r11, %rdx
cmovlq %rcx, %rdx
movq %rdx, %rbp
subq %rsi, %rbp
movl $0x0, %r8d
cmovleq %r8, %rbp
testq %rbp, %rbp
je 0x1c7879
subl %r10d, %ecx
movslq %ecx, %r14
movl -0x14(%r12), %r13d
movl -0x10(%r12), %r11d
movswq -0x8(%r12), %r8
cmpq $0x7fff, %r8            # imm = 0x7FFF
jne 0x1c7881
testq %r9, %r9
jne 0x1c788a
cmpw $0x0, -0xa(%r12)
jns 0x1c788a
subl %r13d, %r11d
incl %r11d
cmpl %r11d, %ecx
cmovgl %ecx, %r11d
movslq %r11d, %r8
jmp 0x1c7915
movq %rcx, %rax
jmp 0x1c795a
testq %r9, %r9
je 0x1c7915
cmpq %r14, %rbp
jne 0x1c78a3
addq %r8, 0x10(%rsp)
movq %rax, (%rsp)
movq $-0x1, 0x20(%rsp)
jmp 0x1c7909
movl -0x4(%r12), %eax
addq %rax, %rax
movq 0x38(%rsp), %rcx
addq 0x70(%rcx), %rax
movq %rax, 0xf8(%rsp)
movq %r9, 0xf0(%rsp)
movq %r9, 0xe8(%rsp)
movl %r10d, 0x5c(%rsp)
movl %edi, 0x60(%rsp)
movl %r13d, 0x50(%rsp)
movl %r11d, 0x54(%rsp)
movl %r8d, 0x6c(%rsp)
movl %r8d, 0x68(%rsp)
leaq 0x40(%rsp), %rdi
movq %rsp, %rcx
leaq 0x20(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x1c754f
addq %rax, 0x10(%rsp)
movq (%rsp), %rax
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r14
jmp 0x1c795a
movq 0x8(%rsp), %r11
cmpq %r14, %rbp
jge 0x1c7943
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r8d, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %r8
movq 0x18(%rsp), %r14
addq %r8, 0x10(%rsp)
movq %rax, (%rsp)
movq $-0x1, 0x20(%rsp)
subq %rbp, %rbx
cmpq $0x1, %r15
je 0x1c7b44
addq $-0x20, %r12
decq %r15
cmpq %r14, %rax
jg 0x1c77e3
jmp 0x1c7b44
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jmp 0x1c7b4e
testq %r15, %r15
movl $0x0, %eax
cmovgq %r15, %rax
negq %rax
movq %rax, 0x30(%rsp)
addq $0x1c, %r13
movl $0x1, %r12d
movq $0x0, 0x10(%rsp)
movq 0x30(%rsp), %rax
addq %r12, %rax
movl -0x1c(%r13), %edi
movslq %edi, %rcx
movq %rcx, (%rsp)
movq $0x0, 0x20(%rsp)
cmpq $0x1, %rax
je 0x1c7b44
movslq -0x18(%r13), %r8
leaq 0x1(%r8), %rax
cmpq %r14, %rcx
movq %r14, %rsi
cmovgq %rcx, %rsi
cmpq %r11, %rax
movq %r11, %rdx
cmovlq %rax, %rdx
movq %rdx, %rbp
subq %rsi, %rbp
movl $0x0, %r9d
cmovleq %r9, %rbp
testq %rbp, %rbp
je 0x1c7a52
movl %eax, %r11d
subl %edi, %r11d
movslq %r11d, %r10
movl -0x14(%r13), %ecx
movl %ecx, 0x2c(%rsp)
movl -0x10(%r13), %r9d
movswq -0x8(%r13), %rcx
movl (%r13), %r14d
cmpq $0x7fff, %rcx           # imm = 0x7FFF
jne 0x1c7a5a
testl %r14d, %r14d
jne 0x1c7a63
xorl %r14d, %r14d
cmpw $0x0, -0xa(%r13)
jns 0x1c7a63
subl 0x2c(%rsp), %r9d
incl %r9d
cmpl %r9d, %r11d
cmovgl %r11d, %r9d
movslq %r9d, %rcx
jmp 0x1c7aeb
movq %rcx, %rax
jmp 0x1c7b27
testl %r14d, %r14d
je 0x1c7aeb
movl %r14d, %r11d
cmpq %r10, %rbp
jne 0x1c7a7b
addq %rcx, 0x10(%rsp)
movq %rax, (%rsp)
movq %r11, 0x20(%rsp)
jmp 0x1c7adf
movl -0x4(%r13), %eax
addq %rax, %rax
movq 0x38(%rsp), %r10
addq 0x70(%r10), %rax
movq %rax, 0xf8(%rsp)
movq %r11, 0xf0(%rsp)
movq %r11, 0xe8(%rsp)
movl %edi, 0x5c(%rsp)
movl %r8d, 0x60(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x50(%rsp)
movl %r9d, 0x54(%rsp)
movl %ecx, 0x6c(%rsp)
movl %ecx, 0x68(%rsp)
leaq 0x40(%rsp), %rdi
movq %rsp, %rcx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x1c754f
addq %rax, 0x10(%rsp)
movq (%rsp), %rax
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r14
jmp 0x1c7b27
cmpq %r10, %rbp
movq 0x18(%rsp), %r14
jge 0x1c7b19
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r11d, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %rcx
movq 0x8(%rsp), %r11
addq %rcx, 0x10(%rsp)
movq %rax, (%rsp)
subq %rbp, %rbx
cmpq %r11, %rax
jge 0x1c7b44
leaq 0x1(%r12), %rax
addq $0x20, %r13
cmpq %r15, %r12
movq %rax, %r12
jl 0x1c79ad
testq %rbx, %rbx
movq 0x10(%rsp), %rax
jne 0x1c7b60
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6c000(%rip), %rdi     # 0x233b67
leaq 0x780ed(%rip), %rsi     # 0x23fc5b
leaq 0x7a1c2(%rip), %rcx     # 0x241d37
movl $0x2af9, %edx           # imm = 0x2AF9
callq 0x2110