// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: extract_mm_hpc(char*, long, long, long, long, unsigned long)
uint64_t extract_mm_hpc(char *in, int64_t len, int64_t off_s, int64_t off_e, int64_t w, uint64_t rev)
{
    int64_t i, o, l, trim, k, tl; uint64_t m, sf; uint8_t c;
    ///forward
    for (k = 1, trim = 0; k <= w; k++) {
        m = 0; o = gen_hpc_max_len(k); sf = k<<1;
        if(!rev) {
            ///[off_s, off_e)
            for (i = ((off_s>=o)?(off_s-o):(0)), l = 0; i < off_e; i++) {
                c = seq_nt4_table[(uint8_t)in[i]]; 
                if((c < 4) && (((l >= k) && (((m>>sf)&3) == c)) || (l < k))) {
                    if(l < k) m = (m<<2) + c; 
                    else sf = (sf?(sf):(k<<1))-2;
                    l++;
                } else {
                    if(i > off_s) {
                        tl = i-off_s;
                        if((l >= o) && (trim < tl)) trim = tl;
                        l = -1;
                        break;
                    }
                    l = 0; sf = k<<1;
                }
            }
            tl = i-off_s;
            if((l!=-1) && (i > off_s) && (l >= o) && (trim < tl)) {
                trim = tl;
                if(trim >= (off_e-off_s)) break;
            }
        } else {
            ///[off_s, off_e)
            for (i = (((len-off_e)>=o)?(off_e+o):(len))-1, l = 0; i >= off_s; i--) {
                c = seq_nt4_table[(uint8_t)in[i]]; 
                if((c < 4) && (((l >= k) && (((m>>sf)&3) == c)) || (l < k))) {
                    if(l < k) m = (m<<2) + c; 
                    else sf = (sf?(sf):(k<<1))-2;
                    l++;
                } else {
                    if(i+1 < off_e) {
                        tl = off_e-i-1;
                        if((l >= o) && (trim < tl)) trim = tl;
                        l = -1;
                        break;
                    }
                    l = 0; sf = k<<1;
                }
            }
            tl = off_e-i-1;
            if((l!=-1) && (i+1 < off_e) && (l >= o) && (trim < tl)) {
                trim = tl;
                if(trim >= (off_e-off_s)) break;
            }
        }
    }
    return trim;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r9, -0x8(%rsp)
movq %r8, -0x10(%rsp)
testq %r8, %r8
jle 0x5de11
movq %rcx, %r10
movq %rdx, %r11
movq %rcx, %rax
subq %rdx, %rax
movq %rax, -0x28(%rsp)
movq %rsi, -0x18(%rsp)
subq %rcx, %rsi
movq %rsi, -0x20(%rsp)
movq %rdx, %rax
negq %rax
movq %rax, -0x30(%rsp)
movl $0x1, %r12d
leaq 0x1cfdbc(%rip), %r13    # 0x22da10
xorl %ebp, %ebp
movq %r12, %rax
shrq %rax
leaq (%rax,%r12), %r8
leaq (%r12,%r12), %r14
leaq (%rax,%r12), %rdx
incq %rdx
cmpq $0x0, -0x8(%rsp)
je 0x5dcf2
addq %r10, %rdx
cmpq %r8, -0x20(%rsp)
cmovleq -0x18(%rsp), %rdx
cmpq %r11, %rdx
jle 0x5dd6d
movq %r14, %rcx
xorl %eax, %eax
xorl %ebx, %ebx
movzbl -0x1(%rdi,%rdx), %esi
movzbl (%r13,%rsi), %esi
cmpq $0x3, %rsi
ja 0x5dcd1
cmpq %r12, %rbx
jge 0x5dcb0
leaq (%rsi,%rax,4), %rax
incq %rbx
jmp 0x5dce2
movq %rax, %r9
shrq %cl, %r9
andl $0x3, %r9d
cmpl %esi, %r9d
jne 0x5dcd1
cmpq %r12, %rbx
jl 0x5dca7
testq %rcx, %rcx
cmoveq %r14, %rcx
addq $-0x2, %rcx
jmp 0x5dcab
movq %r10, %rcx
subq %rdx, %rcx
jg 0x5dd75
xorl %ebx, %ebx
movq %r14, %rcx
decq %rdx
cmpq %r11, %rdx
jg 0x5dc91
movq %r11, %rdx
jmp 0x5dd8a
movq %r11, %rax
subq %rdx, %rax
cmpq %r11, %r8
movl $0x0, %ecx
cmovgeq %rcx, %rax
cmpq %r10, %rax
setl %bl
jge 0x5dd71
movq %r14, %rcx
xorl %r9d, %r9d
xorl %edx, %edx
movzbl (%rdi,%rax), %r15d
movzbl (%r13,%r15), %r15d
cmpq $0x3, %r15
ja 0x5dd53
cmpq %r12, %rdx
jge 0x5dd33
leaq (%r15,%r9,4), %r9
incq %rdx
jmp 0x5dd5d
movq %r9, %rsi
shrq %cl, %rsi
andl $0x3, %esi
cmpl %r15d, %esi
jne 0x5dd53
cmpq %r12, %rdx
jl 0x5dd2a
testq %rcx, %rcx
cmoveq %r14, %rcx
addq $-0x2, %rcx
jmp 0x5dd2e
cmpq %r11, %rax
jg 0x5ddae
xorl %edx, %edx
movq %r14, %rcx
incq %rax
cmpq %r10, %rax
setl %bl
jne 0x5dd14
movq %r10, %rax
jmp 0x5ddcb
xorl %ebx, %ebx
jmp 0x5dd8a
xorl %edx, %edx
jmp 0x5ddcb
cmpq %rcx, %rbp
cmovgq %rbp, %rcx
cmpq %r8, %rbx
cmovgq %rcx, %rbp
movq $-0x1, %rbx
movq %r10, %rax
subq %rdx, %rax
jle 0x5ddf9
cmpq $-0x1, %rbx
je 0x5ddf9
cmpq %r8, %rbx
jle 0x5ddf9
cmpq %rax, %rbp
jge 0x5ddf9
movq %rax, %rbp
cmpq -0x28(%rsp), %rax
jl 0x5ddf9
jmp 0x5de13
movq -0x30(%rsp), %rcx
addq %rax, %rcx
cmpq %rcx, %rbp
cmovgq %rbp, %rcx
cmpq %r8, %rdx
cmovgq %rcx, %rbp
movq $-0x1, %rdx
cmpq $-0x1, %rdx
sete %cl
subq %r11, %rax
setle %sil
cmpq %r8, %rdx
setle %dl
orb %cl, %dl
orb %sil, %dl
cmpq %rax, %rbp
setge %cl
orb %dl, %cl
cmoveq %rax, %rbp
testb $0x1, %bl
jne 0x5ddf9
testb %cl, %cl
je 0x5de13
leaq 0x1(%r12), %rcx
movq %rbp, %rax
cmpq -0x10(%rsp), %r12
movq %rcx, %r12
jne 0x5dc56
jmp 0x5de13
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq