// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: markSNP_advance(long long, long long, long long, long long, long long, window_list*, window_list_alloc*, window_list*, window_list_alloc*, window_list*, window_list_alloc*, haplotype_evdience_alloc*, ul_idx_t const*, int, int)
void markSNP_advance(
long long window_offset,
long long x_total_start, long long x_length, 
long long y_total_start, long long y_length, 
window_list *current_cigar, window_list_alloc *current_cigar_s, 
window_list *beg_cigar, window_list_alloc *beg_cigar_s,
window_list *end_cigar, window_list_alloc *end_cigar_s,
haplotype_evdience_alloc* hap, const ul_idx_t *uref, int strand, int yid)
{   
    long long x_total_end = x_total_start + x_length - 1;
    ///mismatches based on the offset of x
    long long inner_offset = x_total_start - window_offset;
    ///long long useless_side, xleftLen, xrightLen, x_interval_beg, x_interval_end;
    long long L_useless_side, R_useless_side, xleftLen, xrightLen, x_interval_beg, x_interval_end;
    long long current_cigar_beg, current_cigar_end;

    ///for current_cigar, [current_cigar_beg, current_cigar_end]
    current_cigar_beg = 0;
    current_cigar_end = x_length - 1;
    ///if the beg_cigar is available
    if(beg_cigar != NULL && beg_cigar->y_end!=-1)
    {
        ///useless_side = beg_cigar->error_threshold;
        L_useless_side = beg_cigar->extra_begin;
        R_useless_side = beg_cigar->extra_end;
        ///again, xleftLen does not include x_total_start itself, but includes beg_cigar->x_start
        xleftLen = x_total_start - beg_cigar->x_start;
        ///xrightLen includes both x_total_start and beg_cigar->x_end
        xrightLen = beg_cigar->x_end - x_total_start + 1;
        ///actually xleftLen could be no larger than useless_side
        ///but such window has already been filtered out at calculate_boundary_cigars
        ///if(xleftLen > useless_side && xrightLen > useless_side)
        if(xleftLen > L_useless_side && xrightLen > R_useless_side)
        {
            ///[x_interval_beg, x_interval_end] are the offsets to beg_cigar->x_start
            ///they are local postions, instead of global positions

            x_interval_beg = xleftLen;
            //x_interval_end = x_interval_beg + (xrightLen - useless_side) - 1;
            x_interval_end = x_interval_beg + (xrightLen - R_useless_side) - 1;
            ///current_cigar_beg is the offset of the current cigar
            ///that is the beg of current_cigar_beg
            ///current_cigar_beg = xrightLen - useless_side;
            current_cigar_beg = xrightLen - R_useless_side;

            markSNP_detail(beg_cigar, beg_cigar_s, hap->flag + inner_offset, x_interval_beg, x_interval_end, 
            x_interval_beg, uref, beg_cigar->y_start, strand, yid);
        }
    }

    if(end_cigar!=NULL && end_cigar->y_end!=-1)
    {
        ///useless_side = end_cigar->error_threshold;
        L_useless_side = end_cigar->extra_begin;
        R_useless_side = end_cigar->extra_end;
        ///again, xleftLen does not include x_total_end, but includes end_cigar->x_start
        ///it seems to be not what we want
        xleftLen = x_total_end - end_cigar->x_start;
        ///xrightLen includes both x_total_end and end_cigar->x_end
        ///it is also not what we want
        xrightLen = end_cigar->x_end - x_total_end + 1;
        ///we hope that x_total_end should be included in xleftLen, instead of xrightLen
        ///that means xleftLen should + 1, while xrightLen should -1
        ///but it is fine here 

        ///actually xrightLen could be no larger than useless_side
        ///but such window has already been filtered out in calculate_boundary_cigars
        ///if(xleftLen > useless_side && xrightLen > useless_side)
        if(xleftLen > L_useless_side && xrightLen > R_useless_side)
        {
            ///[x_interval_beg, x_interval_end] are the offsets to beg_cigar->x_start
            ///they are local postions, instead of global positions
            x_interval_end = xleftLen;
            ///the real left part length is (xleftLen + 1)
            ///so the useful left part length is ((xleftLen + 1) - useless_side)
            ///x_interval_beg = x_interval_end - ((xleftLen + 1) - useless_side) + 1;
            x_interval_beg = x_interval_end - ((xleftLen + 1) - L_useless_side) + 1;
            ///current_cigar_end = (x_length - 1) - ((xleftLen + 1) - useless_side);
            current_cigar_end = (x_length - 1) - ((xleftLen + 1) - L_useless_side);
            
            markSNP_detail(end_cigar, end_cigar_s, hap->flag + end_cigar->x_start - window_offset, x_interval_beg, 
            x_interval_end, 0, uref, end_cigar->y_start, strand, yid);
        }
    }

    markSNP_detail(current_cigar, current_cigar_s, hap->flag + inner_offset, current_cigar_beg, 
    current_cigar_end, 0, uref, current_cigar->y_start, strand, yid);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r8
movl 0x78(%rsp), %r11d
movq 0x70(%rsp), %r10
movq 0x68(%rsp), %r9
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %r15
movq %rsi, %r12
subq %r8, %r12
testq %r15, %r15
je 0x20e05
cmpl $-0x1, 0xc(%r15)
je 0x20e05
movswq 0x10(%r15), %rax
movswq 0x12(%r15), %rdx
movslq (%r15), %rsi
movq %rbp, %rcx
subq %rsi, %rcx
movslq 0x4(%r15), %r14
subq %rbp, %r14
cmpq %rax, %rcx
setle %al
subq %rdx, %r14
setl %dl
orb %al, %dl
je 0x20ee4
xorl %r14d, %r14d
movq 0x40(%rsp), %rsi
leaq -0x1(%r13), %r15
testq %rdi, %rdi
je 0x20eab
cmpl $-0x1, 0xc(%rdi)
je 0x20eab
movq %r8, (%rsp)
leaq -0x1(,%rbp), %rax
addq %r13, %rax
movswq 0x10(%rdi), %rcx
movslq (%rdi), %rdx
movq %rax, %r8
subq %rdx, %r8
cmpq %rcx, %r8
jle 0x20eab
movslq 0x4(%rdi), %rsi
subq %rax, %rsi
movswq 0x12(%rdi), %rax
cmpq %rax, %rsi
jl 0x20ea6
movq 0x60(%rsp), %rsi
movq %r8, %rax
notq %rax
addq %rcx, %r15
addq %rax, %r15
addq %r9, %rdx
subq (%rsp), %rdx
addq $0x18, %rdx
movslq 0x8(%rdi), %rax
xorl %r9d, %r9d
movl 0x80(%rsp), %r13d
pushq %r13
pushq %r11
pushq %rax
pushq %r10
movq %r10, %r13
movq %r11, %rbp
callq 0x20c56
movq 0x88(%rsp), %r9
movq %rbp, %r11
movq %r13, %r10
addq $0x20, %rsp
movq 0x40(%rsp), %rsi
leaq (%r9,%r12), %rdx
addq $0x18, %rdx
movslq 0x8(%rbx), %rax
movq %rbx, %rdi
movq %r14, %rcx
movq %r15, %r8
xorl %r9d, %r9d
movl 0x80(%rsp), %ebx
pushq %rbx
pushq %r11
pushq %rax
pushq %r10
callq 0x20c56
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %rsi
movq %r8, (%rsp)
leaq (%rcx,%r14), %r8
incq %r14
leaq (%r9,%r12), %rdx
addq $0x18, %rdx
movslq 0x8(%r15), %rax
movq %r15, %rdi
movq %rcx, %r9
movl 0x80(%rsp), %r15d
pushq %r15
pushq %r11
pushq %rax
pushq %r10
movq %r11, %r15
callq 0x20c56
movq 0x20(%rsp), %r8
movq 0x88(%rsp), %r9
movq %r15, %r11
movq 0x90(%rsp), %r10
addq $0x20, %rsp
movq 0x58(%rsp), %rdi
jmp 0x20e08