// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0x3b750
jmp 0x3b950
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
movb $-0x1, -0x69(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x64(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x3b950
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq -0x69(%rbp), %rcx
leaq -0x68(%rbp), %r8
callq 0x2c960
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0x3b7d5
jmp 0x3b950
movzbl -0x69(%rbp), %eax
cmpl $0x0, %eax
jne 0x3b7f9
movl -0x68(%rbp), %eax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x68(%rbp), %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x3b93d
movzbl -0x69(%rbp), %eax
cmpl $0x1, %eax
jne 0x3b90d
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jae 0x3b90b
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0x3b8e5
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jg 0x3b8e5
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
subq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x7f, %eax
jge 0x3b8e5
cmpq $0x0, 0x10(%rbp)
je 0x3b8ce
movq 0x10(%rbp), %rdi
movslq 0x28(%rbp), %rsi
movl 0x20(%rbp), %eax
movb %al, %dl
movq 0x18(%rbp), %rcx
addq -0x40(%rbp), %rcx
movl 0x20(%rbp), %eax
leaq -0x58(%rbp), %r9
movzbl %dl, %edx
movzbl %al, %r8d
callq 0x10d80
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
subq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x7f, -0x60(%rbp)
jg 0x3b8ac
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x3b8b7
movl $0x7f, %eax
movq %rax, -0x78(%rbp)
jmp 0x3b8b7
movq -0x78(%rbp), %rax
movb %al, %dl
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
subq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x3b8e3
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
subq -0x30(%rbp), %rcx
movb (%rax,%rcx), %dl
addb $0x1, %dl
movb %dl, (%rax,%rcx)
jmp 0x3b8e5
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x3b80d
jmp 0x3b93b
movzbl -0x69(%rbp), %eax
cmpl $0x2, %eax
jne 0x3b923
movl -0x68(%rbp), %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x3b939
movzbl -0x69(%rbp), %eax
cmpl $0x3, %eax
jne 0x3b937
movl -0x68(%rbp), %eax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x3b939
jmp 0x3b93b
jmp 0x3b93d
jmp 0x3b93f
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3b79d
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)