// File: /workspace/github_cpp_makefile_star2_O1/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, (%rsp)
movq %r9, 0x38(%rsp)
movq %rdx, %r10
movq %rsi, %rax
subq %rdi, %rax
incq %rax
cqto
idivq 0xa8(%rsp)
cmpq $0x1, %rdx
sbbq $-0x1, %rax
movq %rax, 0x40(%rsp)
cmpq %rdi, %rsi
jge 0x49c79
xorl %r14d, %r14d
jmp 0x49ebf
movq %r8, %r9
movq %rdi, %rbx
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %r8
addq 0xa0(%rsp), %r10
addq $0x50, %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq %rax, 0x18(%rsp)
movq %r9, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movq %rsi, %rcx
subq %rbx, %rcx
leaq 0x1(%rcx), %rax
movq 0x40(%rsp), %r13
cmpq %r13, %rcx
cmovlq %rax, %r13
xorps %xmm0, %xmm0
cvtsi2ss %r13, %xmm0
mulss (%rsp), %xmm0
cvttss2si %xmm0, %rcx
cmpq $0x1f, %rcx
movl $0x1f, %edx
cmovlq %rcx, %rdx
testq %rcx, %rcx
movq %rdx, %rbp
movl $0x1, %ecx
cmoveq %rcx, %rbp
cmpq $0x4, %r13
cmovlq %rdx, %rbp
leaq (,%rbp,2), %r15
addq %r13, %r15
movq 0x18(%r8), %rcx
movq (%rcx,%r9,8), %rcx
testq %r10, %r10
sets %r11b
cmpq %r10, %rcx
setle %dil
movb $0x1, %dl
orb %r11b, %dil
jne 0x49d83
leal (,%rbp,2), %edi
movslq %edi, %rdi
subq %r10, %rdi
addq %rcx, %rdi
addq $0x1f, %rdi
cmpq %r15, %rdi
jl 0x49d83
movslq %ebp, %rdx
subq %rdx, %r10
subq %r10, %rcx
cmpq %r15, %rcx
cmovgeq %r15, %rcx
movl %r15d, %edx
subl %ecx, %edx
movl %edx, 0x4(%rsp)
movl %r10d, %r11d
negl %r11d
xorl %edx, %edx
testq %r10, %r10
movl $0x0, %edi
cmovgq %r10, %rdi
sarq $0x3f, %r10
andl %r11d, %r10d
movq %r10, 0x18(%rsp)
subq %r10, %rcx
movq %rdi, %r10
movq %rcx, 0x48(%rsp)
testb %dl, %dl
jne 0x49e95
movss %xmm0, 0x8(%rsp)
movq %r14, 0x20(%rsp)
movq %r15, 0x50(%rsp)
movslq 0x18(%rsp), %r15
movq %r13, 0x60(%rsp)
movq 0x28(%rsp), %r12
movq %rbx, 0x58(%rsp)
leaq (%r12,%r15), %rbx
movzbl 0x38(%rsp), %ecx
movq %rbx, %rdi
movq %r10, %rsi
movq 0x48(%rsp), %r14
movq %r14, %rdx
movq %r10, %r13
callq 0x337f7
movq %r12, %rdi
movl $0x4e, %esi
movq %r15, %rdx
callq 0x20e0
addq %r14, %rbx
movslq 0x4(%rsp), %rdx
movq %rbx, %rdi
movq 0x58(%rsp), %rbx
movl $0x4e, %esi
callq 0x20e0
movq 0xc0(%rsp), %rax
movq (%rax), %rdx
addq %rbx, %rdx
movzwl %bp, %r8d
movq %r12, %rdi
movq 0x60(%rsp), %r12
movq 0x50(%rsp), %rsi
movl %r12d, %ecx
leaq 0xc(%rsp), %r9
callq 0x8578f
movl 0xc(%rsp), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
je 0x49e48
movq 0x20(%rsp), %r14
addq %rcx, %r14
cltq
subq %r15, %r13
leaq (%rax,%r13), %r10
incq %r10
jmp 0x49e75
xorps %xmm0, %xmm0
cvtsi2sdq 0x20(%rsp), %xmm0
cvtss2sd 0x8(%rsp), %xmm1
mulsd 0x1db610(%rip), %xmm1   # 0x225470
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %r14
addq %r12, %rbp
addq %r13, %rbp
subq %r15, %rbp
movq %rbp, %r10
movq 0x10(%rsp), %rsi
addq %r12, %rbx
cmpq %rsi, %rbx
movq 0x30(%rsp), %r9
movq 0xb0(%rsp), %r8
jle 0x49cb2
jmp 0x49ebf
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
mulss (%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x1db5ba(%rip), %xmm1   # 0x225470
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %r14
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq