// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: trim_hpc(ul_idx_t const*, hpc_t*, All_reads*, char*, char*, long, long, long, long, long, long*, long*, long*, long*)
uint64_t trim_hpc(const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, char *tstr, int64_t hpc_max,
int64_t ql, int64_t tl, int64_t tid, int64_t trev, int64_t *rqs, int64_t *rqe, int64_t *rts, int64_t *rte)
{
    ///[qs, qe); [ts, te)
    int64_t qs = *rqs, qe = *rqe, ts = *rts, te = *rte, trim[2], hl, aux_l, subl = qe-qs; char *ss;
    if(hpc_max > 32) hpc_max = 32; trim[0] = trim[1] = 0; aux_l = gen_hpc_max_len(hpc_max);

    qs -= aux_l; if(qs < 0) qs = 0;
    qe += aux_l; if(qe > ql) qe = ql;
    ss = qstr + qs;
    hl = extract_mm_hpc(ss, qe - qs, (*rqs)-qs, (*rqe)-qs, hpc_max, 0);
    if(hl >= subl) return 0; trim[0] = hl;
    hl = extract_mm_hpc(ss, qe - qs, (*rqs)-qs, (*rqe)-qs, hpc_max, 1);
    if(hl >= subl) return 0; trim[1] = hl;
    if(trim[0] + trim[1] >= subl) return 0;

    ts -= aux_l; if(ts < 0) ts = 0;
    te += aux_l; if(te > tl) te = tl;
    if(rref) {
        fill_subregion(tstr, ts, te-ts, trev, rref, tid, 0, 0); ss = tstr;
    } else {
        ss = return_str_seq(tstr, ts, te-ts, trev, hpc_g, uref, tid, 0, 0);
    }
    hl = extract_mm_hpc(ss, te - ts, (*rts)-ts, (*rte)-ts, hpc_max, 0);
    if(hl >= subl) return 0; if(hl > trim[0]) trim[0] = hl;
    hl = extract_mm_hpc(ss, te - ts, (*rts)-ts, (*rte)-ts, hpc_max, 1);
    if(hl >= subl) return 0; if(hl > trim[1]) trim[1] = hl;
    if(trim[0] + trim[1] >= subl) return 0;

    (*rqs) += trim[0]; (*rts) += trim[0];
    (*rqe) -= trim[1]; (*rte) -= trim[1];
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, %rbp
movq %rdx, 0x48(%rsp)
movq %rsi, 0x30(%rsp)
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq (%rcx), %r13
movq (%rax), %r15
movq %r15, %r14
subq %r13, %r14
cmpq $0x20, %r9
movl $0x20, %ebx
cmovlq %r9, %rbx
movq %rbx, %rax
sarq %rax
leaq (%rbx,%rax), %rcx
leaq (%rbx,%rax), %rdx
incq %rdx
movq %r13, %rax
subq %rdx, %rax
movq %rdx, 0x40(%rsp)
cmovgeq %rdx, %r13
xorl %edx, %edx
testq %rax, %rax
leaq 0x1(%r15,%rcx), %rcx
cmovleq %rdx, %rax
movq 0x90(%rsp), %r12
cmpq %r12, %rcx
cmovlq %rcx, %r12
movq %rdi, 0x28(%rsp)
addq %rax, %rbp
subq %rax, %r12
subq %rax, %r15
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x38(%rsp)
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x5dc01
xorl %edx, %edx
cmpq %r14, %rax
jge 0x5e0d2
movq %rax, 0x8(%rsp)
movl $0x1, %r9d
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x5dc01
cmpq %r14, %rax
jge 0x5e0d0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rsp)
addq %rcx, %rax
cmpq %r14, %rax
movl $0x0, %edx
jge 0x5e0d2
movq %rbx, 0x20(%rsp)
movq 0xa8(%rsp), %rcx
movq 0xa0(%rsp), %r9
movq 0x98(%rsp), %rax
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rsi
subq %rdx, %rsi
xorl %ebx, %ebx
testq %rsi, %rsi
cmovgq %rsi, %rbx
movq 0x50(%rsp), %r15
addq %rdx, %r15
cmpq %rax, %r15
cmovgeq %rax, %r15
movq 0x48(%rsp), %r8
testq %r8, %r8
je 0x5dfa1
movq %r15, %rdx
subq %rbx, %rdx
movzbl %cl, %ecx
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x337f7
jmp 0x5e012
movq 0x30(%rsp), %rax
testq %rax, %rax
movq 0x10(%rsp), %r13
je 0x5dfd3
movq (%rax), %rax
movq 0x10(%rax), %rax
leaq (%r9,%r9,4), %rdx
movq 0x20(%rax,%rdx,8), %r13
testb %cl, %cl
je 0x5e00a
leaq (%rax,%rdx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x5e00c
movq %r15, %rax
subq %rbx, %rax
movq 0x28(%rsp), %rdx
movq (%rdx), %rsi
leaq (%r9,%r9,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rsi), %rdx
movq $0x0, (%rsp)
movzbl %cl, %ecx
xorl %edi, %edi
movq %r13, %rsi
movq %rbx, %r8
movq %rax, %r9
callq 0x36b0d
jmp 0x5e012
xorl %eax, %eax
addq %rbx, %rax
addq %rax, %r13
subq %rbx, %r15
movq 0xc0(%rsp), %rax
movq %r15, %rsi
movq (%rax), %r15
subq %rbx, %r15
movq 0xc8(%rsp), %rax
movq (%rax), %r12
subq %rbx, %r12
movq %r13, %rbp
movq %r13, %rdi
movq %rsi, %r13
movq %r15, %rdx
movq %r12, %rcx
movq 0x20(%rsp), %rbx
movq %rbx, %r8
xorl %r9d, %r9d
callq 0x5dc01
xorl %edx, %edx
cmpq %r14, %rax
movq 0x8(%rsp), %rcx
jge 0x5e0d2
cmpq %rcx, %rax
cmovgq %rax, %rcx
movl $0x1, %r9d
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rcx, %r15
movq %r12, %rcx
movq %rbx, %r8
callq 0x5dc01
cmpq %r14, %rax
jge 0x5e0d0
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
cmovgq %rax, %rcx
leaq (%rcx,%r15), %rax
cmpq %r14, %rax
jge 0x5e0d0
movq 0xb0(%rsp), %rax
addq %r15, (%rax)
movq 0xc0(%rsp), %rax
addq %r15, (%rax)
movq 0xb8(%rsp), %rax
subq %rcx, (%rax)
movq 0xc8(%rsp), %rax
subq %rcx, (%rax)
movl $0x1, %edx
jmp 0x5e0d2
xorl %edx, %edx
movq %rdx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq