// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, %rbx
movq %rsi, %r8
movq %rdi, 0x18(%rsp)
movq 0x48(%rdi), %rbp
xorl %edi, %edi
testq %rbp, %rbp
cmovleq %rdi, %rbp
pushq $0x1c
popq %r13
movq %rsi, 0x10(%rsp)
subq $0x1, %rbp
jb 0x3a23c
movq 0x18(%rsp), %rax
movq 0x58(%rax), %r11
movl -0x1c(%r11,%r13), %r9d
movslq %r9d, %rsi
cmpq %rbx, %rsi
jge 0x3a23c
movslq -0x18(%r11,%r13), %r10
leaq 0x1(%r10), %rax
cmpq %r8, %rsi
cmovleq %r8, %rsi
cmpq %rbx, %rax
movq %rbx, %rdx
cmovlq %rax, %rdx
movq %rdx, %rcx
subq %rsi, %rcx
jle 0x3a233
movq %rdi, 0x8(%rsp)
subl %r9d, %eax
movslq %eax, %rdi
movl -0x14(%r11,%r13), %r15d
movl -0x10(%r11,%r13), %r12d
movswq -0x8(%r11,%r13), %r8
movl (%r11,%r13), %r14d
cmpq $0x7fff, %r8            # imm = 0x7FFF
jne 0x3a15d
testl %r14d, %r14d
jne 0x3a166
xorl %r14d, %r14d
cmpw $0x0, -0xa(%r11,%r13)
jns 0x3a166
subl %r15d, %r12d
incl %r12d
movslq %r12d, %rdx
cmpl $0x200, %eax            # imm = 0x200
jg 0x3a1cd
cmpq %rdx, %rdi
cmovgq %rdi, %rdx
cvtsi2sd %edx, %xmm0
jmp 0x3a201
testl %r14d, %r14d
je 0x3a206
cmpq %rdi, %rcx
je 0x3a226
movl -0x4(%r11,%r13), %eax
addq %rax, %rax
movq 0x18(%rsp), %rcx
addq 0x70(%rcx), %rax
movq %rax, 0xd8(%rsp)
movl %r14d, %eax
movq %rax, 0xd0(%rsp)
movq %rax, 0xc8(%rsp)
movl %r9d, 0x3c(%rsp)
movl %r10d, 0x40(%rsp)
movl %r15d, 0x30(%rsp)
movl %r12d, 0x34(%rsp)
movl %r8d, 0x4c(%rsp)
movl %r8d, 0x48(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x39f4b
movq 0x8(%rsp), %rdi
addq %rax, %rdi
jmp 0x3a22e
cmpq %rdx, %rdi
cmovlq %rdi, %rdx
cvtsi2sd %edx, %xmm1
cvtsi2sd %eax, %xmm2
mulsd 0x1a93b4(%rip), %xmm2   # 0x1e3598
addsd 0x1a90b4(%rip), %xmm2   # 0x1e32a0
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
cvttsd2si %xmm0, %r8
cmpq %rdi, %rcx
jge 0x3a226
cvtsi2sd %rcx, %xmm0
cvtsi2sd %eax, %xmm1
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
jmp 0x3a0b6
movq %rdi, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq