// File: 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
movq %rsp, %rbp
subq $0x18, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x1, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x28(%rbp), %rax
jg 0x53cd0
movq $0x0, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq -0x58(%rbp), %rcx
sarq %rcx
addq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x53afa
movq -0x18(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x5396a
movq -0x18(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x53972
xorl %eax, %eax
movq %rax, -0x80(%rbp)
jmp 0x53972
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x53aa4
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x336e3b(%rip), %rax    # 0x38a7e0
movb (%rax,%rcx), %al
movb %al, -0x71(%rbp)
movzbl -0x71(%rbp), %eax
cmpl $0x4, %eax
jge 0x53a42
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jl 0x539da
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rcx
shrq %cl, %rax
andq $0x3, %rax
movzbl -0x71(%rbp), %ecx
cmpq %rcx, %rax
je 0x539e4
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x53a42
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x53a03
movq -0x68(%rbp), %rax
shlq $0x2, %rax
movzbl -0x71(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x53a34
cmpq $0x0, -0x70(%rbp)
je 0x53a17
movq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x53a25
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
subq $0x2, %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x53a91
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jle 0x53a7e
movq -0x38(%rbp), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x53a74
movq -0x50(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x53a74
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $-0x1, -0x48(%rbp)
jmp 0x53aa4
movq $0x0, -0x48(%rbp)
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x53a93
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x53982
movq -0x38(%rbp), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $-0x1, -0x48(%rbp)
je 0x53af5
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jle 0x53af5
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x53af5
movq -0x50(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x53af5
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
subq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jl 0x53af3
jmp 0x53cd0
jmp 0x53af5
jmp 0x53cbd
movq -0x10(%rbp), %rax
subq -0x20(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x53b19
movq -0x20(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x53b24
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jl 0x53c65
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x336c82(%rip), %rax    # 0x38a7e0
movb (%rax,%rcx), %al
movb %al, -0x71(%rbp)
movzbl -0x71(%rbp), %eax
cmpl $0x4, %eax
jge 0x53bfb
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jl 0x53b93
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rcx
shrq %cl, %rax
andq $0x3, %rax
movzbl -0x71(%rbp), %ecx
cmpq %rcx, %rax
je 0x53b9d
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x53bfb
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x53bbc
movq -0x68(%rbp), %rax
shlq $0x2, %rax
movzbl -0x71(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x53bed
cmpq $0x0, -0x70(%rbp)
je 0x53bd0
movq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x53bde
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
subq $0x2, %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x53c52
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x20(%rbp), %rax
jge 0x53c3f
movq -0x20(%rbp), %rax
subq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x53c35
movq -0x50(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x53c35
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $-0x1, -0x48(%rbp)
jmp 0x53c65
movq $0x0, -0x48(%rbp)
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x53c54
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x53b3b
movq -0x20(%rbp), %rax
subq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x60(%rbp)
cmpq $-0x1, -0x48(%rbp)
je 0x53cbb
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x20(%rbp), %rax
jge 0x53cbb
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x53cbb
movq -0x50(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x53cbb
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
subq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jl 0x53cb9
jmp 0x53cd0
jmp 0x53cbb
jmp 0x53cbd
jmp 0x53cbf
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x53910
movq -0x50(%rbp), %rax
addq $0x18, %rsp
popq %rbp
retq
nopw (%rax,%rax)