// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: verify_window(long long, long long, overlap_region_alloc*, Correct_dumy*, All_reads*, char*)
void verify_window(long long window_start, long long window_end, overlap_region_alloc* overlap_list,Correct_dumy* dumy, All_reads* R_INF,
char* r_string)
{
    long long i;
    long long currentID;
    long long x_start, y_start, o_len;
    long long Window_Len = WINDOW + (THRESHOLD << 1);
    char* x_string = NULL;
    char* y_string = NULL;
    long long x_end, x_len;
    int end_site;
    unsigned int error;
    int groupLen = 0;
    int return_sites[GROUP_SIZE];
	unsigned int return_sites_error[GROUP_SIZE];
    uint64_t overlapID[GROUP_SIZE];
    uint64_t y_startGroup[GROUP_SIZE];
    int y_extra_begin[GROUP_SIZE];
    int y_extra_end[GROUP_SIZE];
    int error_threshold[GROUP_SIZE];
    int extra_begin;
    int extra_end;

    ///here are overlaps fully covered by WINDOW
    for (i = 0; i < (long long)dumy->length; i++)
    {
        extra_begin = extra_end = 0;
        ///if the window has been fully covered, the interval at x is [window_start, window_end]
        x_len = WINDOW;
        currentID = dumy->overlapID[i];
        x_start = window_start;
        ///offset of y
        y_start = (x_start - overlap_list->list[currentID].x_pos_s) + overlap_list->list[currentID].y_pos_s;
        /****************************may have bugs********************************/
        y_start += y_start_offset(x_start, &(overlap_list->list[currentID].f_cigar));
        /****************************may have bugs********************************/
        
  
        if(!determine_overlap_region(THRESHOLD, y_start, overlap_list->list[currentID].y_id, Window_Len, Get_READ_LENGTH((*R_INF), overlap_list->list[currentID].y_id),
        &extra_begin, &extra_end, &y_start, &o_len)) {
            continue;
        }

        fill_subregion(dumy->overlap_region_group[groupLen], y_start, o_len, overlap_list->list[currentID].y_pos_strand, 
        R_INF, overlap_list->list[currentID].y_id, extra_begin, extra_end);

        y_extra_begin[groupLen] = extra_begin;
        y_extra_end[groupLen] = extra_end;
        overlapID[groupLen] = currentID;
        y_startGroup[groupLen] = y_start;
        error_threshold[groupLen] = THRESHOLD;
        x_string = r_string + x_start;
        groupLen++;
        

        if (groupLen == GROUP_SIZE)
        {
            Reserve_Banded_BPM_4_SSE_only(dumy->overlap_region_group[0], dumy->overlap_region_group[1], 
            dumy->overlap_region_group[2], dumy->overlap_region_group[3], Window_Len, x_string, WINDOW,
                return_sites, return_sites_error, THRESHOLD, dumy->Peq_SSE);
            groupLen = 0;

            
            if (return_sites_error[0]!=(unsigned int)-1) {
                overlap_list->list[overlapID[0]].align_length += x_len;

                append_window_list(&overlap_list->list[overlapID[0]], window_start, window_end, 
                            y_startGroup[0], y_startGroup[0] + return_sites[0], (int)return_sites_error[0],
                            y_extra_begin[0], y_extra_end[0], error_threshold[0], WINDOW, NULL);
            }
            

            if (return_sites_error[1]!=(unsigned int)-1) {
                overlap_list->list[overlapID[1]].align_length += x_len;

                append_window_list(&overlap_list->list[overlapID[1]], window_start, window_end, 
                            y_startGroup[1], y_startGroup[1] + return_sites[1], (int)return_sites_error[1],
                            y_extra_begin[1], y_extra_end[1], error_threshold[1], WINDOW, NULL);
            }
            

            if (return_sites_error[2]!=(unsigned int)-1) {
                overlap_list->list[overlapID[2]].align_length += x_len;

                append_window_list(&overlap_list->list[overlapID[2]], window_start, window_end, 
                            y_startGroup[2], y_startGroup[2] + return_sites[2], (int)return_sites_error[2],
                            y_extra_begin[2], y_extra_end[2], error_threshold[2], WINDOW, NULL);
            }
            

            if (return_sites_error[3]!=(unsigned int)-1) {
                overlap_list->list[overlapID[3]].align_length += x_len;

                append_window_list(&overlap_list->list[overlapID[3]], window_start, window_end, 
                            y_startGroup[3], y_startGroup[3] + return_sites[3], (int)return_sites_error[3],
                            y_extra_begin[3], y_extra_end[3], error_threshold[3], WINDOW, NULL);
            }  
        }
    }

    if (groupLen == 1)
    {
        end_site = Reserve_Banded_BPM(dumy->overlap_region_group[0], Window_Len, x_string, WINDOW, THRESHOLD, &error);

        if (error!=(unsigned int)-1) {
            overlap_list->list[overlapID[0]].align_length += x_len;

            append_window_list(&overlap_list->list[overlapID[0]], window_start, window_end, 
                                y_startGroup[0], y_startGroup[0] + end_site, (int)error,
                                y_extra_begin[0], y_extra_end[0], error_threshold[0], WINDOW, NULL);
        }
    }
    else if (groupLen > 1)
    {
        Reserve_Banded_BPM_4_SSE_only(dumy->overlap_region_group[0], dumy->overlap_region_group[1], 
                dumy->overlap_region_group[2], dumy->overlap_region_group[3], Window_Len, x_string, WINDOW,
			        return_sites, return_sites_error, THRESHOLD, dumy->Peq_SSE);

        for (i = 0; i < groupLen; i++)
        {
            if (return_sites_error[i]!=(unsigned int)-1) {
                overlap_list->list[overlapID[i]].align_length += x_len;
                append_window_list(&overlap_list->list[overlapID[i]], window_start, window_end, 
                                y_startGroup[i], y_startGroup[i] + return_sites[i], (int)return_sites_error[i],
                                y_extra_begin[i], y_extra_end[i], error_threshold[i], WINDOW, NULL);
            }
        }

        groupLen = 0;
    }

    long long reverse_i = dumy->size - 1;
    int threshold;
    
    ///here are overlaps partially covered by WINDOW
    for (i = 0; i < (long long)dumy->lengthNT; i++)
    {
        extra_begin = extra_end = 0;
        currentID = dumy->overlapID[reverse_i--];
        x_start = MAX(window_start, (long long)overlap_list->list[currentID].x_pos_s);
        x_end = MIN(window_end, (long long)overlap_list->list[currentID].x_pos_e);

        ///overlap length between [window_start, window_end]
        x_len = x_end - x_start + 1;
        threshold = x_len * asm_opt.max_ov_diff_ec;
        /****************************may have bugs********************************/
        threshold = Adjust_Threshold(threshold, x_len);
        if(threshold > THRESHOLD_MAX_SIZE) threshold = THRESHOLD_MAX_SIZE;
        /****************************may have bugs********************************/
        
        ///offset of y
        y_start = (x_start - overlap_list->list[currentID].x_pos_s) + overlap_list->list[currentID].y_pos_s;
        /****************************may have bugs********************************/
        y_start += y_start_offset(x_start, &(overlap_list->list[currentID].f_cigar));
        /****************************may have bugs********************************/

        Window_Len = x_len + (threshold << 1);

        if(!determine_overlap_region(threshold, y_start, overlap_list->list[currentID].y_id, Window_Len, Get_READ_LENGTH((*R_INF), overlap_list->list[currentID].y_id),
        &extra_begin, &extra_end, &y_start, &o_len)) {
            continue;
        }
        
        fill_subregion(dumy->overlap_region, y_start, o_len, overlap_list->list[currentID].y_pos_strand, 
        R_INF, overlap_list->list[currentID].y_id, extra_begin, extra_end);        

        x_string = r_string + x_start;
        y_string = dumy->overlap_region;

        end_site = Reserve_Banded_BPM(y_string, Window_Len, x_string, x_len, threshold, &error);

        if (error!=(unsigned int)-1) {
            overlap_list->list[currentID].align_length += x_len;
            append_window_list(&overlap_list->list[currentID], x_start, x_end, y_start, y_start + end_site, (int)error,
            extra_begin, extra_end, threshold, WINDOW, NULL);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, 0x10(%rsp)
movq %rsi, 0x30(%rsp)
leaq 0x244(%rcx), %rax
movq %rax, 0x40(%rsp)
movq %r9, 0xf8(%rsp)
movq %rdi, 0x18(%rsp)
leaq (%r9,%rdi), %rax
movq %rax, 0x48(%rsp)
leaq 0x438(%rcx), %rax
movq %rax, 0x70(%rsp)
leaq 0x62c(%rcx), %rax
movq %rax, 0xf0(%rsp)
leaq 0x820(%rcx), %rax
movq %rax, 0xe8(%rsp)
leaq 0x7d80(%rcx), %rax
movq %rax, 0x78(%rsp)
movq $0x0, 0x28(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x38(%rsp)
movq %r8, 0x88(%rsp)
movq %r12, 0x90(%rsp)
cmpq 0x30(%r12), %rcx
jge 0x1bb00
andl $0x0, 0x8(%rsp)
andl $0x0, 0xc(%rsp)
movq 0x28(%r12), %rax
movq %rcx, 0x80(%rsp)
movq (%rax,%rcx,8), %r14
movq 0x10(%rsp), %rbp
movq (%rbp), %rax
imulq $0xa8, %r14, %r13
leaq (%rax,%r13), %rsi
addq $0x38, %rsi
movl -0x34(%rsi), %eax
movl -0x24(%rsi), %r12d
movq 0x18(%rsp), %rdi
movq %rdi, %r15
subq %rax, %r15
callq 0x1bebf
addq %rax, %r12
addq %r15, %r12
movq %r12, 0x68(%rsp)
movq (%rbp), %rbp
movl 0x10(%rbp,%r13), %r15d
movq 0x18(%rbx), %rax
movq (%rax,%r15,8), %r8
subq $0x8, %rsp
movl $0x195, %ecx            # imm = 0x195
pushq $0xf
popq %rdi
movq %r12, %rsi
leaq 0x14(%rsp), %r9
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
callq 0x1b53a
addq $0x20, %rsp
testl %eax, %eax
je 0x1bae0
movq %r14, 0x28(%rsp)
movl 0x38(%rsp), %r14d
movslq %r14d, %r12
imulq $0x1f4, %r12, %rdi      # imm = 0x1F4
addq 0x40(%rsp), %rdi
movq 0x68(%rsp), %rbx
movq 0x98(%rsp), %rdx
movzbl 0x1c(%rbp,%r13), %ecx
movl 0xc(%rsp), %r13d
movl 0x8(%rsp), %ebp
movq %rbx, %rsi
movq 0x88(%rsp), %r8
movq %r15, %r9
pushq %rbp
pushq %r13
callq 0x1b475
popq %rax
popq %rcx
movl %r13d, 0xc0(%rsp,%r12,4)
movl %ebp, 0xb0(%rsp,%r12,4)
movq 0x28(%rsp), %rax
movq %rax, 0x120(%rsp,%r12,8)
movq %rbx, 0x100(%rsp,%r12,8)
movl $0xf, 0xa0(%rsp,%r12,4)
incl %r14d
movq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
movl %r14d, 0x38(%rsp)
cmpl $0x4, %r14d
movq 0x90(%rsp), %r12
jne 0x1bae8
subq $0x8, %rsp
movq 0x48(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0xf8(%rsp), %rdx
movq 0xf0(%rsp), %rcx
movl $0x195, %r8d            # imm = 0x195
movq 0x50(%rsp), %r9
pushq 0x80(%rsp)
pushq $0xf
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0xf0(%rsp), %rax
pushq %rax
pushq $0x177                  # imm = 0x177
callq 0x5197a
addq $0x30, %rsp
cmpl $-0x1, 0x50(%rsp)
movl $0x177, %ebx            # imm = 0x177
je 0x1b97c
imulq $0xa8, 0x120(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
addl %ebx, 0x28(%rcx,%rax)
leaq (%rcx,%rax), %rdi
movl 0x100(%rsp), %ecx
movl 0xd0(%rsp), %r8d
addl %ecx, %r8d
movl 0x50(%rsp), %r9d
movl 0xc0(%rsp), %eax
movl 0xb0(%rsp), %r10d
movl 0xa0(%rsp), %r11d
subq $0x8, %rsp
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
pushq $0x0
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0x13b3b
addq $0x30, %rsp
cmpl $-0x1, 0x54(%rsp)
je 0x1b9ec
imulq $0xa8, 0x128(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
addl %ebx, 0x28(%rcx,%rax)
leaq (%rcx,%rax), %rdi
movl 0x108(%rsp), %ecx
movl 0xd4(%rsp), %r8d
addl %ecx, %r8d
movl 0x54(%rsp), %r9d
movl 0xc4(%rsp), %eax
movl 0xb4(%rsp), %r10d
movl 0xa4(%rsp), %r11d
subq $0x8, %rsp
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
pushq $0x0
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0x13b3b
addq $0x30, %rsp
cmpl $-0x1, 0x58(%rsp)
je 0x1ba5c
imulq $0xa8, 0x130(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
addl %ebx, 0x28(%rcx,%rax)
leaq (%rcx,%rax), %rdi
movl 0x110(%rsp), %ecx
movl 0xd8(%rsp), %r8d
addl %ecx, %r8d
movl 0x58(%rsp), %r9d
movl 0xc8(%rsp), %eax
movl 0xb8(%rsp), %r10d
movl 0xa8(%rsp), %r11d
subq $0x8, %rsp
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
pushq $0x0
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0x13b3b
addq $0x30, %rsp
movl $0x0, 0x38(%rsp)
cmpl $-0x1, 0x5c(%rsp)
je 0x1bad4
imulq $0xa8, 0x138(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
addl %ebx, 0x28(%rcx,%rax)
leaq (%rcx,%rax), %rdi
movl 0x118(%rsp), %ecx
movl 0xdc(%rsp), %r8d
addl %ecx, %r8d
movl 0x5c(%rsp), %r9d
movl 0xcc(%rsp), %eax
movl 0xbc(%rsp), %r10d
movl 0xac(%rsp), %r11d
subq $0x8, %rsp
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
pushq $0x0
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0x13b3b
addq $0x30, %rsp
movq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x1bae8
movq 0x90(%rsp), %r12
movq 0x80(%rsp), %rcx
incq %rcx
movq 0x88(%rsp), %rbx
jmp 0x1b76b
movq 0x28(%rsp), %r9
cmpl $0x1, 0x38(%rsp)
jne 0x1bbac
movl $0x177, %r15d           # imm = 0x177
pushq $0xf
popq %r8
leaq 0x24(%rsp), %rbx
movq 0x40(%rsp), %rdi
movl $0x195, %esi            # imm = 0x195
movq %r9, %rdx
movl $0x177, %ecx            # imm = 0x177
movq %rbx, %r9
callq 0x516e4
cmpl $-0x1, (%rbx)
je 0x1bc8d
imulq $0xa8, 0x120(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
addl %r15d, 0x28(%rdx,%rcx)
leaq (%rdx,%rcx), %rdi
movl 0x100(%rsp), %ecx
addl %ecx, %eax
movl 0x24(%rsp), %r9d
movl 0xc0(%rsp), %r10d
movl 0xb0(%rsp), %r11d
movl 0xa0(%rsp), %ebx
subq $0x8, %rsp
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
movl %eax, %r8d
pushq $0x0
pushq %r15
pushq %rbx
pushq %r11
pushq %r10
callq 0x13b3b
addq $0x30, %rsp
jmp 0x1bc8d
jle 0x1bc8d
subq $0x8, %rsp
movq 0x48(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0xf8(%rsp), %rdx
movq 0xf0(%rsp), %rcx
movl $0x195, %r8d            # imm = 0x195
pushq 0x80(%rsp)
pushq $0xf
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0xf0(%rsp), %rax
pushq %rax
pushq $0x177                  # imm = 0x177
callq 0x5197a
addq $0x30, %rsp
movl 0x38(%rsp), %ebx
shlq $0x2, %rbx
xorl %r14d, %r14d
movl $0x177, %r15d           # imm = 0x177
cmpq %r14, %rbx
je 0x1bc8d
cmpl $-0x1, 0x50(%rsp,%r14)
je 0x1bc87
imulq $0xa8, 0x120(%rsp,%r14,2), %rax
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
addl %r15d, 0x28(%rcx,%rax)
leaq (%rcx,%rax), %rdi
movl 0x100(%rsp,%r14,2), %ecx
movl 0xd0(%rsp,%r14), %r8d
addl %ecx, %r8d
movl 0x50(%rsp,%r14), %r9d
movl 0xc0(%rsp,%r14), %eax
movl 0xb0(%rsp,%r14), %r10d
movl 0xa0(%rsp,%r14), %r11d
subq $0x8, %rsp
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
pushq $0x0
pushq %r15
pushq %r11
pushq %r10
pushq %rax
callq 0x13b3b
addq $0x30, %rsp
addq $0x4, %r14
jmp 0x1bc0d
movq 0x40(%r12), %rax
leaq 0x50(%r12), %rcx
movq %rcx, 0x70(%rsp)
leaq -0x8(,%rax,8), %rcx
xorl %eax, %eax
cmpq 0x38(%r12), %rax
jge 0x1bead
movq %rax, 0x48(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, 0xc(%rsp)
movq 0x28(%r12), %rax
movq %rcx, 0x38(%rsp)
imulq $0xa8, (%rax,%rcx), %r14
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl 0x4(%rax,%r14), %ecx
movq %rcx, %rbp
cmpq 0x18(%rsp), %rcx
jg 0x1bcee
movq 0x18(%rsp), %rbp
movl 0x8(%rax,%r14), %r15d
cmpq 0x30(%rsp), %r15
jl 0x1bcff
movq 0x30(%rsp), %r15
movq %r15, 0x40(%rsp)
subq %rbp, %r15
leaq 0x1(%r15), %rsi
movq %rsi, 0x80(%rsp)
cvtsi2sd %rsi, %xmm0
leaq 0x237a39(%rip), %rdx    # 0x253758
mulsd 0xc0(%rdx), %xmm0
cvttsd2si %xmm0, %edx
movl %edx, %esi
cmpl $0x1f, %edx
jl 0x1bd35
pushq $0x1f
popq %rsi
cmpq $0x3, %r15
movl %esi, %ebx
pushq $0x1
popq %rdi
cmovgel %edi, %ebx
testl %edx, %edx
cmovnel %esi, %ebx
movq %rbp, %rdx
subq %rcx, %rdx
leaq (%rax,%r14), %rsi
addq $0x38, %rsi
movl -0x24(%rsi), %r12d
addq %rdx, %r12
movq %rbp, %rdi
callq 0x1bebf
addq %rax, %r12
movq %r12, 0x68(%rsp)
leal (%rbx,%rbx), %eax
cltq
leaq (%r15,%rax), %rcx
incq %rcx
movq 0x10(%rsp), %rax
movq (%rax), %r13
movl 0x10(%r13,%r14), %r15d
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax,%r15,8), %r8
subq $0x8, %rsp
movl %ebx, %edi
movq %r12, %rsi
movq %rcx, 0x30(%rsp)
leaq 0x14(%rsp), %r9
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
callq 0x1b53a
addq $0x20, %rsp
testl %eax, %eax
je 0x1be8f
movq 0x68(%rsp), %r12
movq 0x98(%rsp), %rdx
movzbl 0x1c(%r13,%r14), %ecx
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %r10d
movq 0x70(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq 0x88(%rsp), %r8
movq %r15, %r9
movq %rax, %r15
movq %r10, 0x78(%rsp)
pushq %r10
pushq %rax
callq 0x1b475
popq %rax
popq %rcx
movq 0xf8(%rsp), %rax
leaq (%rax,%rbp), %rdx
movzwl %bx, %r8d
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movq 0x80(%rsp), %rcx
leaq 0x24(%rsp), %r9
callq 0x516e4
cmpl $-0x1, 0x24(%rsp)
je 0x1be8f
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq 0x80(%rsp), %rdx
addl %edx, 0x28(%rcx,%r14)
leaq (%rcx,%r14), %rdi
addl %r12d, %eax
movl 0x24(%rsp), %r9d
subq $0x8, %rsp
movq %rbp, %rsi
movq 0x48(%rsp), %rdx
movl %r12d, %ecx
movl %eax, %r8d
pushq $0x0
pushq $0x177                  # imm = 0x177
pushq %rbx
pushq 0x98(%rsp)
pushq %r15
callq 0x13b3b
addq $0x30, %rsp
movq 0x48(%rsp), %rax
incq %rax
movq 0x38(%rsp), %rcx
addq $-0x8, %rcx
movq 0x90(%rsp), %r12
jmp 0x1bca6
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq