// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movss %xmm0, -0x34(%rbp)
movq -0x10(%rbp), %rax
subq -0x8(%rbp), %rax
addq $0x1, %rax
cqto
idivq 0x18(%rbp)
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
subq -0x8(%rbp), %rax
addq $0x1, %rax
cqto
idivq 0x18(%rbp)
cmpq $0x0, %rdx
je 0x345d6
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq $0x1f, -0x58(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x18(%rbp), %rax
addq 0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpq -0x10(%rbp), %rax
jg 0x3481e
movq -0x10(%rbp), %rax
subq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jle 0x34622
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
cvtsi2ssq -0x48(%rbp), %xmm0
mulss -0x34(%rbp), %xmm0
cvttss2si %xmm0, %rax
movq %rax, -0x58(%rbp)
cmpq $0x1f, -0x58(%rbp)
jle 0x34645
movq $0x1f, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x34661
cmpq $0x4, -0x48(%rbp)
jl 0x34661
movl $0x1, %eax
movq %rax, -0x90(%rbp)
jmp 0x3466c
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movl %eax, %edi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq 0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %r8
movq (%rax,%r8,8), %r8
leaq -0x5c(%rbp), %r9
leaq -0x60(%rbp), %r11
leaq -0x18(%rbp), %r10
leaq -0x68(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x32290
cmpl $0x0, %eax
jne 0x34711
cvtsi2sdq -0x70(%rbp), %xmm1
movq -0x10(%rbp), %rax
subq -0x8(%rbp), %rax
addq $0x1, %rax
cvtsi2ss %rax, %xmm0
mulss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x34db05(%rip), %xmm2   # 0x382200
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x70(%rbp)
jmp 0x3481e
movq 0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0x18(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x30(%rbp), %rax
movb %al, %cl
movq 0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movl -0x5c(%rbp), %r10d
movl -0x60(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x32160
movq 0x30(%rbp), %rax
movq (%rax), %rax
addq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq 0x28(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %esi
movq -0x78(%rbp), %rdx
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x58(%rbp), %rax
leaq -0x88(%rbp), %r9
movzwl %ax, %r8d
callq 0x9c2b0
movl %eax, -0x84(%rbp)
cmpl $-0x1, -0x88(%rbp)
je 0x347c8
movq -0x70(%rbp), %rax
movl -0x88(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movslq -0x84(%rbp), %rcx
addq %rcx, %rax
movslq -0x5c(%rbp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3480d
cvtsi2sdq -0x70(%rbp), %xmm1
cvtsi2ssq -0x48(%rbp), %xmm0
mulss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x34da1b(%rip), %xmm2   # 0x382200
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
addq -0x58(%rbp), %rax
movslq -0x5c(%rbp), %rcx
subq %rcx, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x345f2
movq -0x70(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)