// File: /workspace/github_cpp_makefile_star2_O3/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, 0x28(%rsp)
cmpq %r8, %rcx
jg 0x4eade
movl 0x1c(%rdi), %eax
movq $0x0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x4eade
movq %r8, %r13
movq %rcx, %rbx
movl 0x80(%rsp), %eax
movq 0x70(%rsp), %rsi
movslq 0x88(%rsp), %rcx
movq %rcx, 0x10(%rsp)
subq %r9, %rdx
xorl %r12d, %r12d
movzbl %al, %eax
movl %eax, 0x4(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
movq %rdi, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
cmpq %r13, %r12
jg 0x4eade
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rdi), %ecx
addl %r14d, %ecx
movzwl (%rax,%rcx,2), %r15d
movzwl %r15w, %eax
andl $0x3fff, %r15d          # imm = 0x3FFF
shrl $0xe, %eax
leaq 0x1e2cbf(%rip), %rcx    # 0x2316e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addq %r15, %r12
addq %r15, %rbp
jmp 0x4ead0
movzwl %r15w, %eax
addq %rax, %rbp
jmp 0x4ead0
movzwl %r15w, %eax
addq %rax, %r12
jmp 0x4ead0
testw %r15w, %r15w
je 0x4ead0
cmpq %rbx, %r12
setl %al
cmpq %r13, %r12
setg %cl
orb %al, %cl
jne 0x4eac5
movb (%rdx,%r12), %al
cmpb $0x7e, %al
ja 0x4eac5
testq %rsi, %rsi
je 0x4eabf
movq 0x78(%rsp), %rax
leaq (%rax,%rbp), %rcx
movq %rsi, %rdi
movq 0x10(%rsp), %rsi
movl 0x4(%rsp), %edx
movl %edx, %r8d
leaq 0x30(%rsp), %r9
callq 0x36265
movq 0x70(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rdx
movl %eax, %ecx
movzbl (%rdx,%r12), %eax
addq %rcx, %rax
cmpq $0x7f, %rax
movl $0x7f, %ecx
cmovaeq %rcx, %rax
jmp 0x4eac1
incb %al
movb %al, (%rdx,%r12)
incq %r12
incq %rbp
decl %r15d
jne 0x4ea58
incq %r14
cmpq 0x20(%rsp), %r14
jne 0x4e9f7
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq