// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: addSNPtohaplotype_details(window_list*, window_list_alloc*, unsigned char*, char*, char*, long long, long long, long long, long long, int, long long, haplotype_evdience_alloc*, long long, ul_idx_t const*, int, int, void*)
void addSNPtohaplotype_details(window_list *cigar_idx, window_list_alloc *cigar_s, uint8_t* flag, 
char* x_string, char* y_string, long long x_total_start, long long y_total_start,
long long xBeg, long long xEnd, int overlapID, long long flag_offset, 
haplotype_evdience_alloc* hap, long long snp_threshold, const ul_idx_t *uref, int y_strand, int yid, void *km)
{
    if(xBeg > xEnd) return;
    int64_t x_i, y_i, c_i, pi = 0, c_n = cigar_idx->clen; 
    uint32_t i, operLen = (uint32_t)-1; uint8_t oper = (uint8_t)-1; i = c_i = x_i = y_i = 0;
    haplotype_evdience ev;

    ///note that node 0 is the start node
    ///0 is match, 1 is mismatch, 2 is up, 3 is left
    ///2 represents thre are more bases at y
    ///3 represents thre are more bases at x
    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) { ///matches
            for (i = 0; i < operLen; i++) {
                ///should be at least 2 mismatches
                /// note we need to deal with flag_offset carefully
                ///if(flag[x_i - flag_offset] > snp_threshold && x_i >= xBeg && x_i <= xEnd)
                if(x_i >= xBeg && x_i <= xEnd && flag[x_i - flag_offset] > snp_threshold) {
                    ev.misBase =  y_string[y_i];
                    ev.overlapID = overlapID;
                    ev.site = x_total_start + x_i;
                    ev.overlapSite = y_total_start + y_i;
                    ev.type = 0;
                    ev.cov = uref?retrieve_u_cov(uref, yid, y_strand, y_total_start + y_i, y_strand, &pi):1;
                    addHaplotypeEvdience(hap, &ev, km);
                }
                ///inner_offset++;
                x_i++; y_i++;
            }
        }
        else if(oper == 1) {
            for (i = 0; i < operLen; i++) {
                /// should be at least 2 mismatches
                /// note we need to deal with flag_offset carefully
                ///if(flag[x_i - flag_offset] > snp_threshold && x_i >= xBeg && x_i <= xEnd)
                if(x_i >= xBeg && x_i <= xEnd && flag[x_i - flag_offset] > snp_threshold) {
                    ev.misBase =  y_string[y_i];
                    ev.overlapID = overlapID;
                    ev.site = x_total_start + x_i;
                    ev.overlapSite = y_total_start + y_i;
                    ev.type = 1;
                    ev.cov = uref?retrieve_u_cov(uref, yid, y_strand, y_total_start + y_i, y_strand, &pi):1;
                    addHaplotypeEvdience(hap, &ev, km);
                }
                ///inner_offset++;
                x_i++; y_i++;
            }
        }///insertion, 2 represents thre are more bases at y
        else if (oper == 2) {
            y_i += operLen;
        }///3 represents thre are more bases at x
        else if (oper == 3) {
            /****************************may have bugs********************************/
            for (i = 0; i < operLen; i++) {
                ///if(hap->flag[inner_offset] > snp_threshold)
                /// should be at least 2 mismatches
                /// note we need to deal with flag_offset carefully
                ///if(flag[x_i - flag_offset] > snp_threshold && x_i >= xBeg && x_i <= xEnd)
                if(x_i >= xBeg && x_i <= xEnd && flag[x_i - flag_offset] > snp_threshold) {
                    ev.misBase =  'N';
                    ev.overlapID = overlapID;
                    ev.site = x_total_start + x_i;
                    ev.overlapSite = y_total_start + y_i;
                    ev.type = 2;
                    ev.cov = uref?retrieve_u_cov(uref, yid, y_strand, y_total_start + y_i, y_strand, &pi):1;
                    addHaplotypeEvdience(hap, &ev, km);
                }

                ///inner_offset++;
                x_i++;
            }
            /****************************may have bugs********************************/
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x40(%rsp)
movq %r8, 0x60(%rsp)
movq 0xb0(%rsp), %r8
movq 0xa8(%rsp), %r9
cmpq %r8, %r9
jg 0x500a3
movq $0x0, 0x58(%rsp)
movl 0x1c(%rdi), %r10d
testq %r10, %r10
je 0x500a3
movq 0xd8(%rsp), %r11
movq 0xd0(%rsp), %r13
movslq 0xe8(%rsp), %rax
movq %rax, 0x48(%rsp)
subq 0xc0(%rsp), %rdx
xorl %r15d, %r15d
leaq 0x1d5a4e(%rip), %rbx    # 0x2255f8
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %rdx, 0x50(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
movq %r10, 0x28(%rsp)
cmpq %r8, %r15
jg 0x500a3
movq 0x28(%rsi), %rax
movl 0x18(%rdi), %ecx
addl %r14d, %ecx
movzwl (%rax,%rcx,2), %ebp
movzwl %bp, %eax
andl $0x3fff, %ebp           # imm = 0x3FFF
shrl $0xe, %eax
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
testw %bp, %bp
je 0x50097
movq %r14, 0x18(%rsp)
movq 0x40(%rsp), %rax
leal (%rax,%r15), %ebx
movq 0x60(%rsp), %rax
leaq (%rax,%r12), %r14
movq 0xa0(%rsp), %rax
movq %r12, %rcx
addq %rax, %r12
leal -0x1(%rbp), %eax
leaq 0x1(%rcx,%rax), %rcx
movq %rcx, 0x10(%rsp)
addq %r15, %rax
incq %rax
movq %rax, 0x20(%rsp)
movq 0xc8(%rsp), %rsi
cmpq %r9, %r15
setl %al
cmpq %r8, %r15
setg %cl
orb %al, %cl
jne 0x4fd63
movzbl (%rdx,%r15), %eax
cmpq %r13, %rax
jle 0x4fd63
movb (%r14), %al
movb %al, 0xf(%rsp)
testq %r11, %r11
je 0x4fc9b
movl 0xe0(%rsp), %eax
movzbl %al, %edx
movq %r11, %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rcx
movl %edx, %r8d
leaq 0x58(%rsp), %r9
callq 0x36d17
movq 0xc8(%rsp), %rsi
movl %eax, %r13d
jmp 0x4fca1
movl $0x1, %r13d
movl 0x10(%rsi), %eax
leal 0x1(%rax), %ecx
cmpl 0x14(%rsi), %ecx
jbe 0x4fd0c
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
incl %ecx
leaq (,%rcx,8), %rax
movl %ecx, 0x14(%rsi)
movq (%rsi), %rsi
leaq (%rax,%rax,2), %rdx
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x4fcf6
callq 0x1e3800
jmp 0x4fd01
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x2370
movq 0xc8(%rsp), %rsi
movq %rax, (%rsi)
movq (%rsi), %rax
movl 0x10(%rsi), %ecx
leaq (%rcx,%rcx,2), %rcx
movl %ebx, (%rax,%rcx,8)
movl 0xb8(%rsp), %edx
movl %edx, 0x4(%rax,%rcx,8)
movl %r12d, 0x8(%rax,%rcx,8)
movb $0x0, 0xc(%rax,%rcx,8)
movl %r13d, 0x10(%rax,%rcx,8)
movb 0xf(%rsp), %dl
movb %dl, 0x14(%rax,%rcx,8)
incl 0x10(%rsi)
movq 0x50(%rsp), %rdx
movq 0xb0(%rsp), %r8
movq 0xa8(%rsp), %r9
movq 0xd8(%rsp), %r11
movq 0xd0(%rsp), %r13
incq %r15
incl %ebx
incq %r14
incq %r12
decl %ebp
jne 0x4fc3e
jmp 0x50072
addq %rbp, %r12
jmp 0x50097
testw %bp, %bp
je 0x50097
movq %r14, 0x18(%rsp)
movq 0xa0(%rsp), %rax
movq %r12, 0x10(%rsp)
addq %rax, %r12
movq 0x40(%rsp), %rax
leal (%rax,%r15), %ebx
leal -0x1(%rbp), %eax
leaq (%r15,%rax), %r14
incq %r14
movq 0xc8(%rsp), %rsi
cmpq %r9, %r15
setl %al
cmpq %r8, %r15
setg %cl
orb %al, %cl
jne 0x4fed7
movzbl (%rdx,%r15), %eax
cmpq %r13, %rax
jle 0x4fed7
testq %r11, %r11
je 0x4fe12
movl 0xe0(%rsp), %eax
movzbl %al, %edx
movq %r11, %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rcx
movl %edx, %r8d
leaq 0x58(%rsp), %r9
callq 0x36d17
movq 0xc8(%rsp), %rsi
movl %eax, %r13d
jmp 0x4fe18
movl $0x1, %r13d
movl 0x10(%rsi), %eax
leal 0x1(%rax), %ecx
cmpl 0x14(%rsi), %ecx
jbe 0x4fe83
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
incl %ecx
leaq (,%rcx,8), %rax
movl %ecx, 0x14(%rsi)
movq (%rsi), %rsi
leaq (%rax,%rax,2), %rdx
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x4fe6d
callq 0x1e3800
jmp 0x4fe78
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x2370
movq 0xc8(%rsp), %rsi
movq %rax, (%rsi)
movq (%rsi), %rax
movl 0x10(%rsi), %ecx
leaq (%rcx,%rcx,2), %rcx
movl %ebx, (%rax,%rcx,8)
movl 0xb8(%rsp), %edx
movl %edx, 0x4(%rax,%rcx,8)
movl %r12d, 0x8(%rax,%rcx,8)
movb $0x2, 0xc(%rax,%rcx,8)
movl %r13d, 0x10(%rax,%rcx,8)
movb $0x4e, 0x14(%rax,%rcx,8)
incl 0x10(%rsi)
movq 0x50(%rsp), %rdx
movq 0xb0(%rsp), %r8
movq 0xa8(%rsp), %r9
movq 0xd8(%rsp), %r11
movq 0xd0(%rsp), %r13
incq %r15
incl %ebx
decl %ebp
jne 0x4fdbc
movq %r14, %r15
jmp 0x50077
testw %bp, %bp
je 0x50097
movq %r14, 0x18(%rsp)
movq 0x40(%rsp), %rax
leal (%rax,%r15), %ebx
movq 0x60(%rsp), %rax
leaq (%rax,%r12), %r14
movq 0xa0(%rsp), %rax
movq %r12, %rcx
addq %rax, %r12
leal -0x1(%rbp), %eax
leaq 0x1(%rcx,%rax), %rcx
movq %rcx, 0x10(%rsp)
addq %r15, %rax
incq %rax
movq %rax, 0x20(%rsp)
movq 0xc8(%rsp), %rsi
cmpq %r9, %r15
setl %al
cmpq %r8, %r15
setg %cl
orb %al, %cl
jne 0x5005f
movzbl (%rdx,%r15), %eax
cmpq %r13, %rax
jle 0x5005f
movb (%r14), %al
movb %al, 0xf(%rsp)
testq %r11, %r11
je 0x4ff97
movl 0xe0(%rsp), %eax
movzbl %al, %edx
movq %r11, %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rcx
movl %edx, %r8d
leaq 0x58(%rsp), %r9
callq 0x36d17
movq 0xc8(%rsp), %rsi
movl %eax, %r13d
jmp 0x4ff9d
movl $0x1, %r13d
movl 0x10(%rsi), %eax
leal 0x1(%rax), %ecx
cmpl 0x14(%rsi), %ecx
jbe 0x50008
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
incl %ecx
leaq (,%rcx,8), %rax
movl %ecx, 0x14(%rsi)
movq (%rsi), %rsi
leaq (%rax,%rax,2), %rdx
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x4fff2
callq 0x1e3800
jmp 0x4fffd
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x2370
movq 0xc8(%rsp), %rsi
movq %rax, (%rsi)
movq (%rsi), %rax
movl 0x10(%rsi), %ecx
leaq (%rcx,%rcx,2), %rcx
movl %ebx, (%rax,%rcx,8)
movl 0xb8(%rsp), %edx
movl %edx, 0x4(%rax,%rcx,8)
movl %r12d, 0x8(%rax,%rcx,8)
movb $0x1, 0xc(%rax,%rcx,8)
movl %r13d, 0x10(%rax,%rcx,8)
movb 0xf(%rsp), %dl
movb %dl, 0x14(%rax,%rcx,8)
incl 0x10(%rsi)
movq 0x50(%rsp), %rdx
movq 0xb0(%rsp), %r8
movq 0xa8(%rsp), %r9
movq 0xd8(%rsp), %r11
movq 0xd0(%rsp), %r13
incq %r15
incl %ebx
incq %r14
incq %r12
decl %ebp
jne 0x4ff3a
movq 0x20(%rsp), %r15
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %r10
leaq 0x1d556b(%rip), %rbx    # 0x2255f8
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r12
incq %r14
cmpq %r10, %r14
jne 0x4fbc4
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq