// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: markSNP_detail(window_list*, window_list_alloc*, unsigned char*, long long, long long, long long, ul_idx_t const*, long long, int, int)
void markSNP_detail(window_list *cigar_idx, window_list_alloc *cigar_s, uint8_t* flag, 
long long xBeg, long long xEnd, long long flag_offset, const ul_idx_t *uref, long long y_total_start, int y_strand, int yid)
{
    if(xBeg > xEnd) return;

    int64_t x_i, y_i, c_i, c_n = cigar_idx->clen, pi = 0, cc = 0;
    uint32_t i, operLen = (uint32_t)-1; uint8_t oper = (uint8_t)-1;
    i = c_i = x_i = y_i = 0;
    for (c_i = 0; c_i < c_n; c_i++) {
        get_cigar_cell(cigar_idx, cigar_s, c_i, &oper, &operLen);
        if(x_i > xEnd) break;

        if (oper == 0) {///match
            x_i += operLen; y_i += operLen;
        } 
        else if(oper == 1) {///mismatch
            for (i = 0; i < operLen; i++) {
                /// note we need to deal with flag_offset carefully
                ///if(flag[x_i - flag_offset] < 127 && x_i >= xBeg && x_i <= xEnd)
                if(x_i >= xBeg && x_i <= xEnd && flag[x_i - flag_offset] < 127) {///Fix-attention
                    if(uref) {
                        cc = retrieve_u_cov(uref, yid, y_strand, y_total_start + y_i, y_strand, &pi);
                        cc += flag[x_i - flag_offset];
                        flag[x_i - flag_offset] = (cc <= 127?cc:127);
                        // if(cc <= 127) flag[x_i - flag_offset] = cc;
                    } else {
                        flag[x_i - flag_offset]++;
                    }
                }
                x_i++; y_i++;
            }
        } else if (oper == 2) {///insertion, that means y has more bases than x
            y_i += operLen;
        }
        else if (oper == 3) {
            x_i += operLen;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x8(%rsp)
cmpq %r8, %rcx
jle 0x20c7d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %r14
movq %rcx, %rbx
movl 0x88(%rsp), %eax
movl 0x1c(%rdi), %ecx
movq %rcx, 0x10(%rsp)
leaq 0x30(%rsp), %rcx
andq $0x0, (%rcx)
movq 0x70(%rsp), %r15
cltq
movq %rax, 0x18(%rsp)
subq %r9, %rdx
xorl %r13d, %r13d
xorl %r9d, %r9d
xorl %ebp, %ebp
movq %rdi, (%rsp)
movq %rdx, 0x20(%rsp)
cmpq 0x10(%rsp), %r9
je 0x20c6e
cmpq %r14, %rbp
jg 0x20c6e
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rdi), %ecx
movq %r9, 0x28(%rsp)
addl %r9d, %ecx
movzwl (%rax,%rcx,2), %r12d
movzwl %r12w, %eax
andl $0x3fff, %r12d          # imm = 0x3FFF
shrl $0xe, %eax
leaq 0x1c2943(%rip), %rdi    # 0x1e3638
movslq (%rdi,%rax,4), %rcx
addq %rdi, %rcx
movzwl %r12w, %eax
jmpq *%rcx
addq %r12, %rbp
addq %r12, %r13
jmp 0x20d84
subl $0x1, %r12d
jb 0x20d84
cmpq %rbx, %rbp
setl %al
cmpq %r14, %rbp
setg %cl
orb %al, %cl
jne 0x20d74
movb (%rdx,%rbp), %al
cmpb $0x7e, %al
ja 0x20d74
testq %r15, %r15
je 0x20d6f
movq 0x78(%rsp), %rax
leaq (%rax,%r13), %rcx
movl 0x80(%rsp), %eax
movzbl %al, %edx
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movl %edx, %r8d
leaq 0x30(%rsp), %r9
callq 0xa105
movq 0x20(%rsp), %rdx
movl %eax, %ecx
movzbl (%rdx,%rbp), %eax
addq %rcx, %rax
cmpq $0x7f, %rax
pushq $0x7f
popq %rcx
cmovaeq %rcx, %rax
jmp 0x20d71
incb %al
movb %al, (%rdx,%rbp)
incq %rbp
incq %r13
jmp 0x20d0a
addq %rax, %r13
jmp 0x20d84
addq %rax, %rbp
movq 0x28(%rsp), %r9
incq %r9
movq (%rsp), %rdi
jmp 0x20cbb