// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: hpc_mask_ff(char*, long, long, long, long, unsigned char*, long, long, long)
uint8_t hpc_mask_ff(char *sa, int64_t sn, int64_t p, int64_t hpc_flk, int64_t hpc_rr, uint8_t *f, int64_t fn, int64_t fsift, int64_t hpc_cutoff)
{
    int64_t s = ((p>=hpc_flk)?(p-hpc_flk):0), e = (((p+hpc_flk)<=sn)?(p+hpc_flk):(sn)), k, r, rc, zs, ze; 

    for (r = 1; r <= hpc_rr; r++) {
        rc = r * hpc_cutoff/**HPC_CC**/;
        
        ///inlcuding p
        for (k = p + r; (k < e) && ((k-r) >= s) && (sa[k] == sa[k-r]); k++); ze = k; if(ze > e) ze = e; 
        for (k = p - 1; (k >= s) && ((k+r) < e) && (sa[k] == sa[k+r]); k--); zs = k + 1; if(zs < s) zs = s;
        if(((ze - zs) > r) && ((ze - zs) >= rc)) {
            // fprintf(stderr, "-0-[M::%s] p::%ld, hh::[%ld,%ld), f::%u, %.*s\n", __func__, p, zs, ze, f?1:0, (int32_t)(ze - zs), sa + zs);
            if(f) {
                for (k = MAX(p, zs); (k < ze) && (k - fsift < fn); k++) f[k - fsift] = 0; f[p - fsift] = 0;
            }
            return 1;
        } 

        ///do not inlcude p
        for (k = p + r + 1; (k < e) && ((k-r) >= s) && (sa[k] == sa[k-r]); k++); 
        zs = p + 1; if(zs < s) zs = s; ze = k; if(ze > e) ze = e; 
        if(((ze - zs) > r) && ((ze - zs) >= rc)) {
            // fprintf(stderr, "-1-[M::%s] p::%ld, hh::[%ld,%ld), f::%u, %.*s\n", __func__, p, zs, ze, f?1:0, (int32_t)(ze - zs), sa + zs);
            if(f) {
                for (k = MAX(p, zs); (k < ze) && (k - fsift < fn); k++) f[k - fsift] = 0; f[p - fsift] = 0;
            }
            return 1;
        }  

        ///inlcuding p
        for (k = p - r; (k >= s) && ((k+r) < e) && (sa[k] == sa[k+r]); k--); zs = k + 1; if(zs < s) zs = s; 
        for (k = p + 1; (k < e) && ((k-r) >= s) && (sa[k] == sa[k-r]); k++); ze = k; if(ze > e) ze = e; 
        if(((ze - zs) > r) && ((ze - zs) >= rc)) {
            // fprintf(stderr, "-2-[M::%s] p::%ld, hh::[%ld,%ld), f::%u, %.*s\n", __func__, p, zs, ze, f?1:0, (int32_t)(ze - zs), sa + zs);
            if(f) {
                for (k = MAX(p, zs); (k < ze) && (k - fsift < fn); k++) f[k - fsift] = 0; f[p - fsift] = 0;
            }
            return 1;
        } 

        ///do not inlcude p
        for (k = p - r - 1; (k >= s) && ((k+r) < e) && (sa[k] == sa[k+r]); k--); 
        zs = k + 1; if(zs < s) zs = s; ze = p; if(ze > e) ze = e; 
        if(((ze - zs) > r) && ((ze - zs) >= rc)) {
            // fprintf(stderr, "-3-[M::%s] p::%ld, hh::[%ld,%ld), f::%u, %.*s\n", __func__, p, zs, ze, f?1:0, (int32_t)(ze - zs), sa + zs);
            if(f) {
                for (k = MAX(p, zs); (k < ze) && (k - fsift < fn); k++) f[k - fsift] = 0; f[p - fsift] = 0;
            }
            return 1;
        } 
    }
    // fprintf(stderr, "-6-[M::%s] p::%ld, hh::[,), %.*s\n", __func__, p, (int32_t)(e - s), sa + s);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r9, -0x50(%rsp)
xorl %ebx, %ebx
movq %rdx, %r14
subq %rcx, %r14
cmovlq %rbx, %r14
addq %rdx, %rcx
cmpq %rsi, %rcx
cmovgeq %rsi, %rcx
leaq 0x1(%rdx), %rsi
cmpq %r14, %rsi
movq %r14, %rax
cmovgq %rsi, %rax
movq %rax, -0x18(%rsp)
cmpq %rdx, %rcx
movq %rdx, %rax
cmovlq %rcx, %rax
movq %rax, -0x28(%rsp)
cmpq %r14, %rdx
movq %r14, %rax
cmovlq %rdx, %rax
movq %rax, -0x30(%rsp)
cmpq %rsi, %rcx
movq %rsi, %rax
cmovgq %rcx, %rax
movq %rax, -0x38(%rsp)
testq %r8, %r8
cmovleq %rbx, %r8
incq %r8
movq %r8, -0x10(%rsp)
leaq 0x2(%rdx), %rax
movq %rax, -0x48(%rsp)
movq %rdx, -0x58(%rsp)
leaq -0x1(%rdx), %rax
movq %rax, -0x20(%rsp)
movabsq $0x1, %r9
movq %rdi, %r11
xorl %ebp, %ebp
movq %rdi, %r13
movq %rsi, -0x40(%rsp)
cmpq %rsi, %rcx
movq %rsi, %r15
cmovgq %rcx, %r15
cmpq -0x10(%rsp), %r9
je 0x27fa7
movq %rsi, -0x8(%rsp)
movq %r9, %r12
imulq 0x48(%rsp), %r12
movq -0x58(%rsp), %r8
leaq (%r9,%r8), %rdx
cmpq %rcx, %rdx
jge 0x27dd4
cmpq %r14, %r8
jl 0x27dd1
movb (%rdi,%rdx), %al
cmpb (%rdi,%r8), %al
jne 0x27dd1
incq %rdx
incq %r8
jmp 0x27db6
movq %rdx, %r15
cmpq %rcx, %r15
cmovgeq %rcx, %r15
movq -0x58(%rsp), %rax
cmpq %r14, %rax
jle 0x27e02
movq %rax, %rdx
addq %rbp, %rax
cmpq %rcx, %rax
jge 0x27e07
movb -0x1(%rdi,%rdx), %r8b
leaq -0x1(%rdx), %rax
cmpb (%r13,%rdx), %r8b
je 0x27de0
jmp 0x27e07
movq -0x30(%rsp), %rdx
cmpq %r14, %rdx
cmovleq %r14, %rdx
movq %r15, %rax
subq %rdx, %rax
cmpq %r9, %rax
setle %r8b
cmpq %r12, %rax
setl %sil
orb %r8b, %sil
movq -0x40(%rsp), %r10
movq -0x48(%rsp), %rax
cmpb $0x1, %sil
jne 0x27fb4
movq %rax, %rdx
cmpq %rcx, %rax
jge 0x27e5b
cmpq %r14, %r10
jl 0x27e5b
movb (%rdi,%rdx), %sil
leaq 0x1(%rdx), %rax
leaq 0x1(%r10), %r8
cmpb (%rdi,%r10), %sil
movq %r8, %r10
je 0x27e39
leaq -0x1(%rdx), %rax
cmpq %rcx, %rax
cmovgeq %rcx, %rdx
movq %rdx, %rax
movq -0x18(%rsp), %r10
subq %r10, %rax
cmpq %r9, %rax
setle %sil
cmpq %r12, %rax
setl %al
orb %sil, %al
je 0x27ff7
movq -0x58(%rsp), %r10
movq %r10, %rdx
subq %r9, %rdx
movq %rdx, %r15
cmpq %r14, %r15
jl 0x27eb1
cmpq %rcx, %r10
jge 0x27eb1
movb (%rdi,%r15), %al
cmpb (%rdi,%r10), %al
jne 0x27eb1
decq %r15
decq %r10
jmp 0x27e95
incq %r15
cmpq %r14, %r15
cmovleq %r14, %r15
movq -0x58(%rsp), %r10
movq -0x40(%rsp), %rax
leaq 0x1(%r10), %r8
cmpq %rcx, %r8
jge 0x27eea
leaq (%rbx,%r10), %rsi
cmpq %r14, %rsi
jl 0x27ef1
movb 0x1(%rdi,%r10), %sil
cmpb (%r11,%r10), %sil
jne 0x27ef7
incq %rax
movq %r8, %r10
jmp 0x27ec5
movq -0x38(%rsp), %rax
jmp 0x27ef7
incq %r10
movq %r10, %rax
cmpq %rcx, %rax
cmovgeq %rcx, %rax
movq %rax, %rsi
subq %r15, %rsi
cmpq %r9, %rsi
setle %r8b
cmpq %r12, %rsi
setl %sil
orb %r8b, %sil
movq -0x20(%rsp), %r8
cmpb $0x1, %sil
jne 0x28037
movq %rdx, %r10
cmpq %r14, %rdx
jle 0x27f47
cmpq %rcx, %r8
jge 0x27f47
movb -0x1(%rdi,%r10), %al
leaq -0x1(%r8), %rsi
leaq -0x1(%r10), %rdx
cmpb (%rdi,%r8), %al
movq %rsi, %r8
je 0x27f24
cmpq %r14, %r10
cmovleq %r14, %r10
movq -0x28(%rsp), %rax
subq %r10, %rax
cmpq %r9, %rax
setle %dl
cmpq %r12, %rax
setl %al
orb %dl, %al
incq %r9
movq -0x8(%rsp), %rsi
incq %rsi
incq %r13
incq %rbp
incq -0x48(%rsp)
decq %r11
decq %rbx
testb %al, %al
jne 0x27d8a
movq -0x50(%rsp), %rdi
testq %rdi, %rdi
movq 0x40(%rsp), %r8
je 0x27fa3
movq -0x58(%rsp), %rax
subq %r8, %rax
movb $0x0, (%rdi,%rax)
movb $0x1, %al
jmp 0x27fa9
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x27fa3
movq -0x58(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
movq 0x40(%rsp), %r8
movq %r8, %rax
negq %rax
movq %rdi, %rcx
subq %r8, %rcx
movq 0x38(%rsp), %r9
cmpq %r15, %rdx
jge 0x27f97
leaq (%rax,%rdx), %rsi
cmpq %r9, %rsi
jge 0x27f97
movb $0x0, (%rcx,%rdx)
incq %rdx
jmp 0x27fe0
movq -0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x27fa3
movq 0x40(%rsp), %r8
movq %r8, %rax
negq %rax
movq %rdi, %rcx
subq %r8, %rcx
movq 0x38(%rsp), %r9
cmpq %rdx, %r10
jge 0x27f97
leaq (%rax,%r10), %rsi
cmpq %r9, %rsi
jge 0x27f97
movb $0x0, (%rcx,%r10)
incq %r10
jmp 0x28017
movq -0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x27fa3
movq -0x58(%rsp), %rcx
cmpq %rcx, %r15
cmovleq %rcx, %r15
movq 0x40(%rsp), %r8
movq %r8, %rdx
negq %rdx
movq %rdi, %rcx
subq %r8, %rcx
movq 0x38(%rsp), %r9
cmpq %rax, %r15
jge 0x27f97
leaq (%rdx,%r15), %rsi
cmpq %r9, %rsi
jge 0x27f97
movb $0x0, (%rcx,%r15)
incq %r15
jmp 0x28067