// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, %r13
movq %rdx, 0x58(%rsp)
movq %rsi, 0x40(%rsp)
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq (%rcx), %rbp
movq (%rax), %r15
movq %r15, %rbx
subq %rbp, %rbx
cmpq $0x20, %r9
pushq $0x20
popq %r14
cmovlq %r9, %r14
movq %r14, %rax
sarq %rax
leaq (%r14,%rax), %rcx
leaq (%r14,%rax), %rdx
incq %rdx
movq %rbp, %rax
subq %rdx, %rax
movq %rdx, 0x50(%rsp)
cmovgeq %rdx, %rbp
xorl %edx, %edx
testq %rax, %rax
leaq 0x1(%r15,%rcx), %rcx
cmovleq %rdx, %rax
movq 0xa0(%rsp), %r12
cmpq %r12, %rcx
cmovlq %rcx, %r12
movq %rdi, 0x38(%rsp)
addq %rax, %r13
subq %rax, %r12
subq %rax, %r15
movq 0xd8(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x48(%rsp)
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0x2d6cd
xorl %edx, %edx
cmpq %rbx, %rax
jge 0x2db87
movq %rax, 0x28(%rsp)
pushq $0x1
popq %r9
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x2d6cd
cmpq %rbx, %rax
jge 0x2db85
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rsp)
addq %rcx, %rax
cmpq %rbx, %rax
movl $0x0, %edx
jge 0x2db87
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %r9
movq 0xa8(%rsp), %rcx
movq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rsi
subq %rdx, %rsi
xorl %ebp, %ebp
testq %rsi, %rsi
cmovgq %rsi, %rbp
movq 0x60(%rsp), %r13
addq %rdx, %r13
cmpq %rcx, %r13
cmovgeq %rcx, %r13
subq %rbp, %r13
movq 0x58(%rsp), %r8
testq %r8, %r8
je 0x2daa0
movzbl %al, %ecx
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x6c9e
movq %r15, %rdi
jmp 0x2dacc
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
movq %r9, (%rsp)
movzbl %al, %ecx
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x56ba5
movq %rax, %rdi
movq 0xd0(%rsp), %rax
movq (%rax), %r15
subq %rbp, %r15
movq 0xd8(%rsp), %rax
movq (%rax), %r12
subq %rbp, %r12
movq %rdi, 0x20(%rsp)
movq %r13, %rbp
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq %r14, %r13
movq %r14, %r8
xorl %r9d, %r9d
callq 0x2d6cd
xorl %edx, %edx
cmpq %rbx, %rax
movq 0x28(%rsp), %rcx
jge 0x2db87
cmpq %rcx, %rax
cmovgq %rax, %rcx
pushq $0x1
popq %r14
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %rcx, %r15
movq %r12, %rcx
movq %r13, %r8
movq %r14, %r9
callq 0x2d6cd
cmpq %rbx, %rax
jge 0x2db85
movq 0x30(%rsp), %rcx
cmpq %rcx, %rax
cmovgq %rax, %rcx
leaq (%rcx,%r15), %rax
cmpq %rbx, %rax
jge 0x2db85
movq 0xc0(%rsp), %rax
addq %r15, (%rax)
movq 0xd0(%rsp), %rax
addq %r15, (%rax)
movq 0xc8(%rsp), %rax
subq %rcx, (%rax)
movq 0xd8(%rsp), %rax
subq %rcx, (%rax)
movq %r14, %rdx
jmp 0x2db87
xorl %edx, %edx
movq %rdx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq