// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: extract_sub_cigar_err_debug(overlap_region*, long, long)
int64_t extract_sub_cigar_err_debug(overlap_region *z, int64_t s, int64_t e)
{
    int64_t wk = 0, wn = z->w_list.n, ws, we, os, oe, ovlp; 
    window_list *m; int64_t xl, yl, werr, err; bit_extz_t ez;
    for (wk = err = 0; wk < wn; wk++) {
        m = &(z->w_list.a[wk]); 
        ws = m->x_start; we = m->x_end+1;
        if(ws >= e) break;
        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 = 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; 
            } else {
                if(ovlp == xl) {
                    //skip the whole window
                    err += m->error; 
                } else {
                    set_bit_extz_t(ez, (*z), wk); 
                    err += retrieve_cigar_err_debug(&ez, os, oe);
                }                
            }
        }
    }
    return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, 0x18(%rsp)
movq 0x48(%rdi), %rbp
testq %rbp, %rbp
jle 0x6b6bc
movq %rdx, %r14
movq %rsi, %r8
movl $0x1c, %r13d
xorl %edi, %edi
movq %rsi, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq 0x58(%rax), %r11
movl -0x1c(%r11,%r13), %r9d
movslq %r9d, %rsi
cmpq %r14, %rsi
jge 0x6b6be
movslq -0x18(%r11,%r13), %r10
leaq 0x1(%r10), %rax
cmpq %r8, %rsi
cmovleq %r8, %rsi
cmpq %r14, %rax
movq %r14, %rdx
cmovlq %rax, %rdx
movq %rdx, %rcx
subq %rsi, %rcx
jle 0x6b6ad
movq %rdi, 0x8(%rsp)
subl %r9d, %eax
movslq %eax, %rdi
movl -0x14(%r11,%r13), %r12d
movl -0x10(%r11,%r13), %ebx
movswq -0x8(%r11,%r13), %r8
movl (%r11,%r13), %r15d
cmpq $0x7fff, %r8            # imm = 0x7FFF
jne 0x6b5c9
testl %r15d, %r15d
jne 0x6b5d2
xorl %r15d, %r15d
cmpw $0x0, -0xa(%r11,%r13)
jns 0x6b5d2
subl %r12d, %ebx
incl %ebx
movslq %ebx, %rdx
cmpl $0x200, %eax            # imm = 0x200
jg 0x6b638
cmpq %rdx, %rdi
cmovgq %rdi, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x6b672
testl %r15d, %r15d
je 0x6b677
cmpq %rdi, %rcx
je 0x6b6a0
movl -0x4(%r11,%r13), %eax
addq %rax, %rax
movq 0x18(%rsp), %rcx
addq 0x70(%rcx), %rax
movq %rax, 0xd8(%rsp)
movl %r15d, %eax
movq %rax, 0xd0(%rsp)
movq %rax, 0xc8(%rsp)
movl %r9d, 0x3c(%rsp)
movl %r10d, 0x40(%rsp)
movl %r12d, 0x30(%rsp)
movl %ebx, 0x34(%rsp)
movl %r8d, 0x4c(%rsp)
movl %r8d, 0x48(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x6b394
movq 0x8(%rsp), %rdi
addq %rax, %rdi
jmp 0x6b6a8
cmpq %rdx, %rdi
cmovlq %rdi, %rdx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
mulsd 0x1c5ff3(%rip), %xmm2   # 0x231648
addsd 0x1c5cb3(%rip), %xmm2   # 0x231310
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
cvttsd2si %xmm0, %r8
cmpq %rdi, %rcx
jge 0x6b6a0
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r8, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %r8
movq 0x8(%rsp), %rdi
addq %r8, %rdi
movq 0x10(%rsp), %r8
addq $0x20, %r13
decq %rbp
jne 0x6b52a
jmp 0x6b6be
xorl %edi, %edi
movq %rdi, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq