// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: get_high_error(long long, long long, long long, long long, long long, long long, long long, long long, float, All_reads*, Correct_dumy*, UC_Read*)
long long get_high_error(long long x_start, long long x_end, 
long long y_start, long long y_end, long long y_id, long long y_strand, long long pre_threshold,
long long n_steps, float error_rate, All_reads* R_INF, Correct_dumy* dumy,
UC_Read* g_read)
{
    long long stepLen = (x_end - x_start + 1) / n_steps;
    if((x_end - x_start + 1) % n_steps != 0)
    {
        stepLen++;
    }
    long long SubLen, SubWindowLen;
    long long SubThreshold = THRESHOLD_MAX_SIZE;
    int extra_begin, extra_end;
    long long o_len;
    long long T_error = 0;
    y_start = y_start + pre_threshold;

    while (x_start <= x_end)
    {
        SubLen = x_end - x_start + 1;
        if(SubLen > stepLen)
        {
            SubLen = stepLen;
        }


        SubThreshold = SubLen * error_rate;
        if(SubThreshold > THRESHOLD_MAX_SIZE)
        {
            SubThreshold = THRESHOLD_MAX_SIZE;
        }

        SubThreshold = Adjust_Threshold(SubThreshold, SubLen);


        SubWindowLen = SubLen + (SubThreshold << 1);
        if(determine_overlap_region(SubThreshold, y_start, y_id, SubWindowLen, Get_READ_LENGTH((*R_INF), y_id),
        &extra_begin, &extra_end, &y_start, &o_len) == 0)
        {
            T_error = T_error + (x_end - x_start + 1) * error_rate * 1.5;
            break;
        }

        fill_subregion(dumy->overlap_region, y_start, o_len, y_strand, R_INF, y_id, 
        extra_begin, extra_end);

        char* x_string = g_read->seq + x_start;
        char* y_string = dumy->overlap_region;
        int end_site;
        unsigned int error;

        end_site = Reserve_Banded_BPM(y_string, SubWindowLen, x_string, SubLen, SubThreshold, &error);
                    
        ///if error = -1, unmatched
        if (error!=(unsigned int)-1)
        {
            T_error = T_error + error;
            y_start = y_start + end_site - extra_begin + 1;
        }
        else
        {
            T_error = T_error + SubLen * error_rate * 1.5;
            y_start = y_start + SubThreshold - extra_begin + SubLen;
        }
        
        x_start = x_start + SubLen;
    }


    return T_error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movss %xmm0, 0xc(%rsp)
movq %r8, %r15
movq %rdx, %rcx
movq 0xb0(%rsp), %r12
movq %rsi, 0x50(%rsp)
movq %rsi, %rax
subq %rdi, %rax
incq %rax
cqto
idivq 0xa8(%rsp)
cmpq $0x1, %rdx
sbbq $-0x1, %rax
movq %rax, 0x48(%rsp)
movq 0xb8(%rsp), %rax
addq 0xa0(%rsp), %rcx
leaq 0x10(%rsp), %rdx
movq %rcx, (%rdx)
addq $0x50, %rax
movq %rax, 0x38(%rsp)
movq $0x0, (%rsp)
movzbl %r9b, %eax
movl %eax, 0x1c(%rsp)
movq %r8, 0x40(%rsp)
movq 0x50(%rsp), %rax
subq %rdi, %rax
jl 0x1cda4
movq %rdi, 0x30(%rsp)
leaq 0x1(%rax), %r14
movq 0x48(%rsp), %r13
cmpq %r13, %rax
cmovlq %r14, %r13
cvtsi2ss %r13, %xmm0
mulss 0xc(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
cvttss2si %xmm0, %rax
cmpq $0x1f, %rax
pushq $0x1f
popq %rdx
cmovlq %rax, %rdx
testq %rax, %rax
movq %rdx, %rbx
pushq $0x1
popq %rax
cmoveq %rax, %rbx
cmpq $0x4, %r13
cmovlq %rdx, %rbx
leaq (,%rbx,2), %rbp
addq %r13, %rbp
movq 0x18(%r12), %rax
movq (%rax,%r15,8), %r8
subq $0x8, %rsp
movl %ebx, %edi
movq %rcx, %rsi
movq %rbp, %rcx
leaq 0x34(%rsp), %r9
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x40(%rsp), %rax
pushq %rax
callq 0x1b53a
addq $0x20, %rsp
cvtsi2sdq (%rsp), %xmm1
testl %eax, %eax
je 0x1cd80
movsd %xmm1, 0x58(%rsp)
movq 0x10(%rsp), %r14
movq 0x60(%rsp), %rdx
movq %r15, %r9
movslq 0x2c(%rsp), %r10
movl 0x28(%rsp), %eax
movq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movl 0x1c(%rsp), %ecx
movq %r12, %r8
movq %r10, %r12
pushq %rax
pushq %r10
callq 0x1b475
popq %rax
popq %rcx
movq 0xc0(%rsp), %rax
movq (%rax), %rdx
addq 0x30(%rsp), %rdx
movzwl %bx, %r8d
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %ecx
leaq 0x24(%rsp), %r9
callq 0x516e4
movl 0x24(%rsp), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
je 0x1cd38
addq %rcx, (%rsp)
cltq
subq %r12, %r14
leaq (%r14,%rax), %rcx
incq %rcx
jmp 0x1cd61
cvtss2sd 0x20(%rsp), %xmm0
mulsd 0x1c677a(%rip), %xmm0   # 0x1e34c0
addsd 0x58(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, (%rsp)
addq %r13, %rbx
addq %r14, %rbx
subq %r12, %rbx
movq %rbx, %rcx
movq %rcx, 0x10(%rsp)
movq 0x30(%rsp), %rdi
addq %r13, %rdi
movq 0x40(%rsp), %r15
movq 0xb0(%rsp), %r12
jmp 0x1cc10
cvtsi2ss %r14, %xmm0
mulss 0xc(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x1c6729(%rip), %xmm0   # 0x1e34c0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, (%rsp)
movq (%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq