// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, %r13
xorl %eax, %eax
subq %rcx, %rdx
movl $0x0, %ebx
cmovgeq %rdx, %rbx
addq %r13, %rcx
cmpq %rsi, %rcx
movq %rsi, %r11
cmovlq %rcx, %r11
movq %r8, -0x8(%rsp)
testq %r8, %r8
jle 0x56dda
movq %rcx, -0x48(%rsp)
movq %rsi, -0x40(%rsp)
movq %r9, -0x60(%rsp)
leaq 0x1(%r13), %rcx
cmpq %rbx, %rcx
movq %rbx, %rax
movq %rcx, -0x50(%rsp)
cmovgq %rcx, %rax
movq %rax, -0x38(%rsp)
cmpq %r13, %r11
movq %r13, %rax
cmovlq %r11, %rax
movq %rax, -0x18(%rsp)
cmpq %rbx, %r13
movq %rbx, %rax
cmovlq %r13, %rax
movq %rax, -0x28(%rsp)
leaq (%rdi,%r13), %rax
movq %rax, -0x20(%rsp)
leaq 0x2(%r13), %rax
movq %rax, -0x30(%rsp)
leaq -0x1(%r13), %rax
movq %rax, -0x10(%rsp)
movl $0x1, %r15d
xorl %eax, %eax
movq %rdi, %r9
movq %rdi, %rbp
movq %r13, %rsi
leaq (%r15,%r13), %rdx
cmpq %r11, %rdx
jge 0x56b06
movq -0x20(%rsp), %rcx
cmpq %r13, %rbx
jg 0x56b06
movb (%rdi,%rdx), %r8b
cmpb (%rcx), %r8b
jne 0x56b06
incq %rdx
incq %rcx
cmpq %r11, %rdx
jl 0x56aea
movq %r11, %rdx
movq %r15, %rcx
imulq 0x48(%rsp), %rcx
movq %rcx, -0x58(%rsp)
cmpq %r11, %rdx
movq %r11, %r12
cmovlq %rdx, %r12
movq %r13, %r10
cmpq %rbx, %r10
jle 0x56b43
movq %r10, %r8
addq %rax, %r10
cmpq %r11, %r10
jge 0x56b48
movb -0x1(%rdi,%r8), %r14b
leaq -0x1(%r8), %r10
cmpb (%rbp,%r8), %r14b
je 0x56b21
jmp 0x56b48
movq -0x28(%rsp), %r8
cmpq %rbx, %r8
cmovleq %rbx, %r8
movq %r12, %r10
subq %r8, %r10
cmpq %r15, %r10
setle %r14b
cmpq -0x58(%rsp), %r10
setl %cl
orb %r14b, %cl
movq -0x50(%rsp), %r14
movq -0x30(%rsp), %r10
cmpb $0x1, %cl
jne 0x56cd6
movq %r10, %rdx
cmpq %r11, %r10
jge 0x56b9b
cmpq %rbx, %r14
jl 0x56b9b
movb (%rdi,%rdx), %cl
leaq 0x1(%rdx), %r10
leaq 0x1(%r14), %r8
cmpb (%rdi,%r14), %cl
movq %r8, %r14
je 0x56b7a
leaq -0x1(%rdx), %rcx
cmpq %r11, %rcx
cmovgeq %r11, %rdx
movq %rdx, %rcx
subq -0x38(%rsp), %rcx
cmpq %r15, %rcx
setle %r8b
cmpq -0x58(%rsp), %rcx
setl %cl
orb %r8b, %cl
je 0x56d37
movq %r13, %rdx
subq %r15, %rdx
movq %rdx, %r8
cmpq %rbx, %rdx
jl 0x56bfd
movq %r13, %r10
movq %rdx, %r14
cmpq %r13, %r11
jle 0x56bfa
movb (%rdi,%r14), %cl
cmpb (%rdi,%r10), %cl
jne 0x56bfa
leaq -0x1(%r14), %r8
decq %r10
cmpq %rbx, %r14
movq %r8, %r14
jg 0x56bda
jmp 0x56bfd
movq %r14, %r8
incq %r8
cmpq %rbx, %r8
cmovleq %rbx, %r8
movq -0x50(%rsp), %rcx
movq %rcx, %r12
cmpq %r11, %rcx
jge 0x56c34
movq -0x50(%rsp), %r12
cmpq %rbx, %rsi
jl 0x56c34
movb (%rdi,%r12), %cl
cmpb -0x1(%r9,%r12), %cl
jne 0x56c34
incq %r12
cmpq %r12, %r11
jne 0x56c19
movq %r11, %r12
cmpq %r11, %r12
movq %r11, %r14
cmovlq %r12, %r14
movq %r14, %rcx
subq %r8, %rcx
cmpq %r15, %rcx
setle %r10b
cmpq -0x58(%rsp), %rcx
setl %cl
orb %r10b, %cl
movq -0x10(%rsp), %r10
cmpb $0x1, %cl
jne 0x56d6f
movq %rdx, %r8
cmpq %rbx, %rdx
jle 0x56c87
cmpq %r11, %r10
jge 0x56c87
movb -0x1(%rdi,%r8), %cl
leaq -0x1(%r10), %r14
leaq -0x1(%r8), %rdx
cmpb (%rdi,%r10), %cl
movq %r14, %r10
je 0x56c64
cmpq %rbx, %r8
cmovleq %rbx, %r8
movq -0x18(%rsp), %rcx
subq %r8, %rcx
cmpq %r15, %rcx
setle %dl
cmpq -0x58(%rsp), %rcx
setl %cl
orb %dl, %cl
je 0x56dc1
leaq 0x1(%r15), %rcx
decq %rsi
incq %rbp
incq %rax
incq -0x30(%rsp)
decq %r9
cmpq -0x8(%rsp), %r15
movq %rcx, %r15
jne 0x56adc
xorl %eax, %eax
jmp 0x56dda
movq -0x60(%rsp), %rax
testq %rax, %rax
je 0x56dd8
cmpq %r13, %r8
cmovleq %r13, %r8
cmpq %r12, %r8
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %rsi
movq -0x40(%rsp), %rdi
jge 0x56dd0
cmpq %rdi, %rdx
cmovlq %rdx, %rdi
movq -0x48(%rsp), %rdx
cmpq %rdx, %rdi
cmovgeq %rdx, %rdi
subq %r8, %rdi
subq %rcx, %r8
cmpq %rsi, %r8
jge 0x56dd0
movb $0x0, (%rax,%r8)
incq %r8
decq %rdi
jne 0x56d1c
jmp 0x56dd0
movq -0x60(%rsp), %rax
testq %rax, %rax
je 0x56dd8
movq -0x38(%rsp), %rdi
subq %rdi, %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %rsi
jle 0x56dd0
subq %rcx, %rdi
cmpq %rsi, %rdi
jge 0x56dd0
movb $0x0, (%rax,%rdi)
incq %rdi
decq %rdx
jne 0x56d5c
jmp 0x56dd0
movq -0x60(%rsp), %rax
testq %rax, %rax
movq 0x40(%rsp), %rcx
je 0x56dd8
cmpq %r13, %r8
cmovleq %r13, %r8
cmpq %r14, %r8
movq 0x38(%rsp), %rdx
movq -0x40(%rsp), %rsi
jge 0x56dd0
cmpq %rsi, %r12
cmovlq %r12, %rsi
movq -0x48(%rsp), %rdi
cmpq %rdi, %rsi
cmovgeq %rdi, %rsi
subq %r8, %rsi
subq %rcx, %r8
cmpq %rdx, %r8
jge 0x56dd0
movb $0x0, (%rax,%r8)
incq %r8
decq %rsi
jne 0x56dad
jmp 0x56dd0
movq -0x60(%rsp), %rax
testq %rax, %rax
movq 0x40(%rsp), %rcx
je 0x56dd8
subq %rcx, %r13
movb $0x0, (%rax,%r13)
movb $0x1, %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq