// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, %r14
movq %rsi, %rax
subq %rdi, %rax
incq %rax
cqto
idivq 0xa8(%rsp)
cmpq $0x1, %rdx
sbbq $-0x1, %rax
movq %rax, 0x48(%rsp)
cmpq %rdi, %rsi
jge 0x492fe
xorl %edi, %edi
jmp 0x4952a
movq %r8, %r10
movq %rdi, %r15
movq 0xb8(%rsp), %rax
addq 0xa0(%rsp), %r14
movq 0xb0(%rsp), %r8
addq $0x50, %rax
movq %rax, 0x38(%rsp)
xorl %edi, %edi
movzbl %r9b, %eax
movl %eax, 0x10(%rsp)
movq %r10, 0x40(%rsp)
movq %rsi, 0x20(%rsp)
movq %rsi, %rcx
subq %r15, %rcx
leaq 0x1(%rcx), %rax
movq 0x48(%rsp), %r13
cmpq %r13, %rcx
cmovlq %rax, %r13
xorps %xmm0, %xmm0
cvtsi2ss %r13, %xmm0
mulss 0xc(%rsp), %xmm0
cvttss2si %xmm0, %rcx
cmpq $0x1f, %rcx
movl $0x1f, %edx
cmovlq %rcx, %rdx
testq %rcx, %rcx
movq %rdx, %r12
movl $0x1, %ecx
cmoveq %rcx, %r12
cmpq $0x4, %r13
cmovlq %rdx, %r12
testq %r14, %r14
js 0x494ff
movq 0x18(%r8), %rcx
movq (%rcx,%r10,8), %rbp
cmpq %r14, %rbp
jle 0x494ff
leaq (,%r12,2), %rbx
addq %r13, %rbx
leal (%r12,%r12), %ecx
movslq %ecx, %rcx
subq %r14, %rcx
addq %rbp, %rcx
addq $0x1f, %rcx
cmpq %rbx, %rcx
jl 0x494ff
movss %xmm0, 0x14(%rsp)
movq %rdi, 0x30(%rsp)
movslq %r12d, %rax
movq %rax, 0x58(%rsp)
subq %rax, %r14
subq %r14, %rbp
cmpq %rbx, %rbp
cmovgeq %rbx, %rbp
movl %ebx, %eax
subl %ebp, %eax
movl %eax, 0x18(%rsp)
movl %r14d, %eax
negl %eax
testq %r14, %r14
movl $0x0, %esi
cmovgq %r14, %rsi
cltq
sarq $0x3f, %r14
movl %eax, %ecx
andl %r14d, %ecx
subq %rcx, %rbp
andq %rax, %r14
movq %r15, 0x60(%rsp)
movq 0x38(%rsp), %r15
leaq (%r15,%r14), %rdi
movq %rdi, 0x50(%rsp)
movq %rsi, 0x28(%rsp)
movq %rbp, %rdx
movl 0x10(%rsp), %ecx
movq %r10, %r9
callq 0x32ef8
movq %r15, %rdi
movl $0x4e, %esi
movq %r14, %rdx
callq 0x20e0
addq 0x50(%rsp), %rbp
movq 0x60(%rsp), %r15
movslq 0x18(%rsp), %rdx
movq %rbp, %rdi
movl $0x4e, %esi
callq 0x20e0
movq 0xc0(%rsp), %rax
movq (%rax), %rdx
addq %r15, %rdx
movzwl 0x58(%rsp), %r8d
movq 0x38(%rsp), %rdi
movl %ebx, %esi
movl %r13d, %ecx
leaq 0x1c(%rsp), %r9
callq 0x84e99
movl 0x1c(%rsp), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
je 0x494b3
movq 0x30(%rsp), %rdi
addq %rcx, %rdi
cltq
movq 0x28(%rsp), %rcx
subq %r14, %rcx
leaq (%rcx,%rax), %r14
incq %r14
jmp 0x494df
cvtsi2sdq 0x30(%rsp), %xmm0
cvtss2sd 0x14(%rsp), %xmm1
mulsd 0x1e80a8(%rip), %xmm1   # 0x231570
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
addq %r13, %r12
addq 0x28(%rsp), %r12
subq %r14, %r12
movq %r12, %r14
movq 0x20(%rsp), %rsi
addq %r13, %r15
cmpq %rsi, %r15
movq 0x40(%rsp), %r10
movq 0xb0(%rsp), %r8
jle 0x49339
jmp 0x4952a
xorps %xmm0, %xmm0
cvtsi2sd %rdi, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
mulss 0xc(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x1e804f(%rip), %xmm1   # 0x231570
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movq %rdi, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq