// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq 0x48(%rdi), %rbp
testq %rbp, %rbp
jle 0x6bada
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movl $0x1c, %r13d
xorl %ebx, %ebx
movq 0x58(%r12), %r8
movl -0x1c(%r8,%r13), %r10d
movslq %r10d, %rsi
cmpq %r14, %rsi
jge 0x6badc
movslq -0x18(%r8,%r13), %rax
incq %rax
cmpq %r15, %rsi
cmovleq %r15, %rsi
cmpq %r14, %rax
movq %r14, %rdx
cmovlq %rax, %rdx
movq %rdx, %rcx
subq %rsi, %rcx
jle 0x6bacb
subl %r10d, %eax
movslq %eax, %rdi
movl -0x10(%r8,%r13), %r11d
subl -0x14(%r8,%r13), %r11d
movswq -0x8(%r8,%r13), %r9
cmpq $0x7fff, %r9            # imm = 0x7FFF
jne 0x6b9b3
cmpl $0x0, (%r8,%r13)
jne 0x6b9aa
cmpw $0x0, -0xa(%r8,%r13)
js 0x6ba2a
cmpl $0x7fff, %r9d           # imm = 0x7FFF
je 0x6b9ba
cmpl $0x0, (%r8,%r13)
je 0x6ba2a
cmpq %rdi, %rcx
je 0x6bac8
movl -0x4(%r8,%r13), %eax
addq %rax, %rax
addq 0x70(%r12), %rax
movq %rax, 0xb8(%rsp)
movl (%r8,%r13), %eax
movq %rax, 0xb0(%rsp)
movq %rax, 0xa8(%rsp)
movl %r10d, 0x1c(%rsp)
movl -0x18(%r8,%r13), %eax
movl %eax, 0x20(%rsp)
movl -0x14(%r8,%r13), %eax
movl %eax, 0x10(%rsp)
movl -0x10(%r8,%r13), %eax
movl %eax, 0x14(%rsp)
movswl -0x8(%r8,%r13), %eax
movl %eax, 0x2c(%rsp)
movl %eax, 0x28(%rsp)
movq %rsp, %rdi
callq 0x6b7b4
addq %rax, %rbx
jmp 0x6bacb
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0x6ba9f
cmpl $0x0, (%r8,%r13)
jne 0x6ba9f
cmpw $0x0, -0xa(%r8,%r13)
jns 0x6ba9f
incl %r11d
movslq %r11d, %rdx
cmpl $0x200, %eax            # imm = 0x200
jg 0x6ba60
cmpq %rdx, %rdi
cmovgq %rdi, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x6ba9a
cmpq %rdx, %rdi
cmovlq %rdi, %rdx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
mulsd 0x1b9acb(%rip), %xmm2   # 0x225548
addsd 0x1b97eb(%rip), %xmm2   # 0x225270
movapd %xmm2, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
cvttsd2si %xmm0, %r9
cmpq %rdi, %rcx
jge 0x6bac8
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r9, %xmm2
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %r9
addq %r9, %rbx
addq $0x20, %r13
decq %rbp
jne 0x6b93c
jmp 0x6badc
xorl %ebx, %ebx
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq