// File: /workspace/github_cpp_makefile_star2_O3/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 0x5d633
movq %rcx, %r10
movq %rdx, %rbx
movq %rcx, %rax
subq %rdx, %rax
movq %rax, -0x30(%rsp)
movq %rsi, -0x18(%rsp)
subq %rcx, %rsi
movq %rsi, -0x20(%rsp)
movq %rdx, %rax
negq %rax
movq %rax, -0x28(%rsp)
movl $0x1, %r12d
leaq 0x1dc7c7(%rip), %r13    # 0x239c20
xorl %ebp, %ebp
movq %r12, %rax
shrq %rax
leaq (%rax,%r12), %r8
leaq (%r12,%r12), %r14
leaq (%rax,%r12), %r11
incq %r11
cmpq $0x0, -0x8(%rsp)
je 0x5d4fc
addq %r10, %r11
cmpq %r8, -0x20(%rsp)
cmovleq -0x18(%rsp), %r11
cmpq %rbx, %r11
jle 0x5d57a
movq %r14, %rcx
xorl %esi, %esi
xorl %edx, %edx
movzbl -0x1(%rdi,%r11), %eax
movzbl (%r13,%rax), %eax
cmpq $0x3, %rax
ja 0x5d4d6
cmpq %r12, %rdx
jge 0x5d4b7
leaq (%rax,%rsi,4), %rsi
jmp 0x5d4d1
movq %rsi, %r9
shrq %cl, %r9
andl $0x3, %r9d
cmpl %eax, %r9d
jne 0x5d4d6
testq %rcx, %rcx
cmoveq %r14, %rcx
addq $-0x2, %rcx
incq %rdx
jmp 0x5d4e7
movq %r10, %rax
subq %r11, %rax
jg 0x5d591
xorl %edx, %edx
movq %r14, %rcx
decq %r11
cmpq %rbx, %r11
jg 0x5d49a
movq -0x30(%rsp), %rax
movq %rbx, %r11
jmp 0x5d5a9
movq %rbx, %rdx
subq %r11, %rdx
cmpq %rbx, %r8
movl $0x0, %eax
cmovgeq %rax, %rdx
cmpq %r10, %rdx
jge 0x5d584
movb $0x1, %sil
movq %r14, %rcx
xorl %r9d, %r9d
xorl %r11d, %r11d
movzbl (%rdi,%rdx), %r15d
movzbl (%r13,%r15), %r15d
cmpq $0x3, %r15
ja 0x5d559
cmpq %r12, %r11
jge 0x5d53b
leaq (%r15,%r9,4), %r9
jmp 0x5d554
movq %r9, %rax
shrq %cl, %rax
andl $0x3, %eax
cmpl %r15d, %eax
jne 0x5d559
testq %rcx, %rcx
cmoveq %r14, %rcx
addq $-0x2, %rcx
incq %r11
jmp 0x5d564
cmpq %rbx, %rdx
jg 0x5d5ca
xorl %r11d, %r11d
movq %r14, %rcx
incq %rdx
cmpq %r10, %rdx
setl %sil
jne 0x5d51f
movq -0x30(%rsp), %rax
movq %r10, %rdx
jmp 0x5d5ea
movq %r10, %rax
subq %r11, %rax
xorl %edx, %edx
jmp 0x5d5a9
movq %rdx, %rax
subq %rbx, %rax
xorl %esi, %esi
xorl %r11d, %r11d
jmp 0x5d5ea
cmpq %rax, %rbp
movq %rax, %rcx
cmovgq %rbp, %rcx
cmpq %r8, %rdx
cmovgq %rcx, %rbp
movq $-0x1, %rdx
cmpq %r10, %r11
jge 0x5d61b
cmpq $-0x1, %rdx
je 0x5d61b
cmpq %r8, %rdx
jle 0x5d61b
cmpq %rax, %rbp
jge 0x5d61b
movq %rax, %rbp
cmpq -0x30(%rsp), %rax
jl 0x5d61b
jmp 0x5d635
movq -0x28(%rsp), %rax
addq %rdx, %rax
cmpq %rax, %rbp
movq %rax, %rcx
cmovgq %rbp, %rcx
cmpq %r8, %r11
cmovgq %rcx, %rbp
movq $-0x1, %r11
cmpq $-0x1, %r11
sete %cl
cmpq %rbx, %rdx
setle %dl
cmpq %r8, %r11
setle %r8b
orb %dl, %r8b
orb %cl, %r8b
cmpq %rax, %rbp
setge %cl
orb %r8b, %cl
cmoveq %rax, %rbp
testb $0x1, %sil
jne 0x5d61b
testb %cl, %cl
je 0x5d635
leaq 0x1(%r12), %rcx
movq %rbp, %rax
cmpq -0x10(%rsp), %r12
movq %rcx, %r12
jne 0x5d45b
jmp 0x5d635
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq