// File: /workspace/github_cpp_makefile_star2_O2/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, -0x10(%rsp)
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)
xorl %eax, %eax
testq %r8, %r8
cmovleq %rax, %r8
incq %r8
movq %r8, -0x8(%rsp)
movq %rdx, %rax
negq %rax
movq %rax, -0x30(%rsp)
movabsq $0x1, %r12
leaq 0x1be3d9(%rip), %r13    # 0x1ebb00
xorl %r14d, %r14d
cmpq -0x8(%rsp), %r12
je 0x2d914
movq %r12, %rax
shrq %rax
leaq (%rax,%r12), %rbp
leaq (%r12,%r12), %r15
leaq (%rax,%r12), %r9
incq %r9
cmpq $0x0, -0x10(%rsp)
je 0x2d7e6
addq %r10, %r9
movq %rbp, -0x38(%rsp)
cmpq %rbp, -0x20(%rsp)
cmovleq -0x18(%rsp), %r9
cmpq %r11, %r9
movq %r11, %rdx
cmovlq %r9, %rdx
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %r15, %rcx
incq %r9
movq %rbx, %r8
leaq -0x1(%r9), %rsi
cmpq %r11, %rsi
jle 0x2d85c
movzbl -0x2(%rdi,%r9), %eax
movzbl (%r13,%rax), %eax
cmpq $0x3, %rax
ja 0x2d7b1
cmpq %r12, %r8
jl 0x2d7c9
movq %rbp, %rbx
shrq %cl, %rbx
andl $0x3, %ebx
cmpl %eax, %ebx
je 0x2d7cf
movq %r10, %rax
movq %rsi, %r9
movl $0x0, %ebx
movq %r15, %rcx
subq %rsi, %rax
jle 0x2d77d
jmp 0x2d86c
leaq (%rax,%rbp,4), %rbp
jmp 0x2d7da
testq %rcx, %rcx
cmoveq %r15, %rcx
addq $-0x2, %rcx
incq %r8
addq $-0x2, %r9
movq %r8, %rbx
jmp 0x2d77a
movq %r11, %rdx
subq %r9, %rdx
cmpq %r11, %rbp
movl $0x0, %eax
cmovgeq %rax, %rdx
cmpq %r10, %rdx
movq %r10, %rsi
cmovgq %rdx, %rsi
xorl %ebx, %ebx
xorl %eax, %eax
movq %r15, %rcx
cmpq %r10, %rdx
jge 0x2d8ad
movzbl (%rdi,%rdx), %r8d
movzbl (%r13,%r8), %r8d
cmpq $0x3, %r8
ja 0x2d84d
cmpq %r12, %rbx
jge 0x2d82e
leaq (%r8,%rax,4), %rax
jmp 0x2d848
movq %rax, %r9
shrq %cl, %r9
andl $0x3, %r9d
cmpl %r8d, %r9d
jne 0x2d84d
testq %rcx, %rcx
cmoveq %r15, %rcx
addq $-0x2, %rcx
incq %rbx
jmp 0x2d857
cmpq %r11, %rdx
jg 0x2d8b5
xorl %ebx, %ebx
movq %r15, %rcx
incq %rdx
jmp 0x2d809
movq %r10, %rax
subq %rdx, %rax
movq %rdx, %rsi
movq -0x38(%rsp), %rdx
jmp 0x2d88c
cmpq %rax, %r14
movq %rax, %rcx
cmovgq %r14, %rcx
movq -0x38(%rsp), %rdx
cmpq %rdx, %r8
cmovgq %rcx, %r14
movabsq $-0x1, %r8
cmpq %r10, %rsi
jge 0x2d90c
cmpq $-0x1, %r8
je 0x2d90c
cmpq %rdx, %r8
jle 0x2d90c
cmpq %rax, %r14
jge 0x2d90c
movq %rax, %r14
cmpq -0x28(%rsp), %rax
jl 0x2d90c
jmp 0x2d917
movq %rsi, %rax
subq %r11, %rax
jmp 0x2d8db
movq -0x30(%rsp), %rax
addq %rdx, %rax
cmpq %rax, %r14
movq %rax, %rcx
cmovgq %r14, %rcx
cmpq %rbp, %rbx
cmovgq %rcx, %r14
movq %rdx, %rsi
movabsq $-0x1, %rbx
cmpq $-0x1, %rbx
sete %cl
cmpq %r11, %rsi
setle %sil
cmpq %rbp, %rbx
setle %r8b
orb %sil, %r8b
orb %cl, %r8b
cmpq %rax, %r14
setge %cl
orb %r8b, %cl
cmoveq %rax, %r14
cmpq %r10, %rdx
jl 0x2d90c
testb %cl, %cl
je 0x2d917
incq %r12
jmp 0x2d72a
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq