// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: mark_telo_ends(void*, long, int)
static void mark_telo_ends(void *data, long i, int tid) // callback for kt_for()
{
    telo_end_pip_t *sl = (telo_end_pip_t *)data;
    int64_t k, l, rlen, tlen, sc, max_sc, pen = sl->penalty, max_drop = sl->max_drop, min_sc = sl->min_sc, z; 
    uint64_t rid = i, c, x, mask = sl->u->mask, hit, xz; 
    UC_Read *rr = &(sl->aux[tid]); rlen = Get_READ_LENGTH((*(sl->Rinf)), rid); sl->u->hh[rid] = 0;
    recover_UC_Read(rr, sl->Rinf, rid); assert((rr->length) == rlen); tlen = sl->u->tlen;

    for (k = l = 0, sc = max_sc = x = 0; k < rlen; k++) { // 5'-end, check CCCTAA
        hit = 0; c = seq_nt6_table[(uint8_t)rr->seq[k]];
        if (c >= 0 && c <= 3) { // not N
            x = (x<<2 | (c)) & mask;
            if (((++l) >= tlen) && (kh_get(64, sl->h, x) != kh_end(sl->h))) {// x is at least 6bp long and is a telomere motif
                hit = 1;
            }
        } else {l = 0, x = 0;} // N, ambiguous base
        if(k >= tlen) sc += ((hit)?(1):(-pen));
        if (sc > max_sc) {max_sc = sc;}
		else if ((max_sc - sc) > max_drop) {break;}

        if(max_sc >= min_sc) break;
    }

    if(max_sc >= min_sc) {
        for (k = l = 0, sc = max_sc = x = 0, xz = ((uint64_t)-1); k < rlen; k++) { // 5'-end, check CCCTAA
            hit = 0; c = seq_nt6_table[(uint8_t)rr->seq[k]];
            if (c >= 0 && c <= 3) { // not N
                x = (x<<2 | (c)) & mask;
                if (((++l) >= tlen) && (kh_get(64, sl->h, x) != kh_end(sl->h))) {// x is at least 6bp long and is a telomere motif
                    if((xz != ((uint64_t)-1)) && (xz == x)) {
                        hit = 1;
                    } else {
                        for (z = 0, xz = sl->u->tm; (z < tlen) && (xz != x); z++) {
                            xz = (((xz>>((tlen-1)<<1))&(3ULL))|(xz<<2))&mask;
                        }
                        if((z < tlen) && (xz == x)) hit = 1;
                    }
                }
            } else {l = 0, x = 0;} // N, ambiguous base

            if(!hit) {
                xz = ((uint64_t)-1);
            } else {
                xz = (((x>>((tlen-1)<<1))&(3ULL))|(x<<2))&mask;
            }
            if(k >= tlen) sc += ((hit)?(1):(-pen));
            if (sc > max_sc) {max_sc = sc;}
            else if ((max_sc - sc) > max_drop) {break;}

            if(max_sc >= min_sc) break;
        }

        if(max_sc >= min_sc) sl->u->hh[rid] |= 1;
    }






    for (k = rlen-1, l = 0, sc = max_sc = x = 0; k >= 0; --k) { // 3'-end
        hit = 0; c = seq_nt6_table[(uint8_t)(RC_CHAR(rr->seq[k]))];
        if (c >= 0 && c <= 3) { // not N
            x = (x<<2 | (c)) & mask;
            if (((++l) >= tlen) && (kh_get(64, sl->h, x) != kh_end(sl->h))) {// x is at least 6bp long and is a telomere motif
                hit = 1;
            }
        } else {l = 0, x = 0;} // N, ambiguous base
        if((rlen - k) >= tlen) sc += ((hit)?(1):(-pen));
        if (sc > max_sc) {max_sc = sc;}
		else if ((max_sc - sc) > max_drop) {break;}

        if(max_sc >= min_sc) break;
    }

    if(max_sc >= min_sc) {
        for (k = rlen-1, l = 0, sc = max_sc = x = 0, xz = ((uint64_t)-1); k >= 0 ; --k) { // 3'-end
            hit = 0; c = seq_nt6_table[(uint8_t)(RC_CHAR(rr->seq[k]))];
            if (c >= 0 && c <= 3) { // not N
                x = (x<<2 | (c)) & mask;
                if (((++l) >= tlen) && (kh_get(64, sl->h, x) != kh_end(sl->h))) {// x is at least 6bp long and is a telomere motif
                    if((xz != ((uint64_t)-1)) && (xz == x)) {
                        hit = 1;
                    } else {
                        for (z = 0, xz = sl->u->tm; (z < tlen) && (xz != x); z++) {
                            xz = (((xz>>((tlen-1)<<1))&(3ULL))|(xz<<2))&mask;
                        }
                        if((z < tlen) && (xz == x)) hit = 1;
                    }
                }
            } else {l = 0, x = 0;} // N, ambiguous base

            if(!hit) {
                xz = ((uint64_t)-1);
            } else {
                xz = (((x>>((tlen-1)<<1))&(3ULL))|(x<<2))&mask;
            }
            if((rlen - k) >= tlen) sc += ((hit)?(1):(-pen));
            if (sc > max_sc) {max_sc = sc;}
            else if ((max_sc - sc) > max_drop) {break;}

            if(max_sc >= min_sc) break;
        }

        if(max_sc >= min_sc) sl->u->hh[rid] |= 2;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r8
movq %rdi, %r15
movq 0x28(%rdi), %r13
movq 0x30(%rdi), %rax
movq %rax, 0x50(%rsp)
movq 0x20(%rdi), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%rdi), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq (%rdi), %rcx
movq 0x8(%rdi), %rbx
movslq %edx, %r14
shlq $0x5, %r14
leaq (%rbx,%r14), %rdi
movq 0x18(%rcx), %rcx
movq (%rcx,%rsi,8), %r12
movb $0x0, (%rax,%rsi)
movq (%r15), %rsi
movq %rdi, 0x18(%rsp)
movq %r8, 0x58(%rsp)
movq %r8, %rdx
callq 0x715e
cmpq %r12, 0x8(%rbx,%r14)
jne 0x68d60
movq %r15, 0x40(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x60(%rsp)
movq 0x18(%rax), %r11
negq %r13
xorl %ebx, %ebx
testq %r12, %r12
movl $0x0, %eax
movq %r12, 0x68(%rsp)
cmovgq %r12, %rax
movq %rax, 0x10(%rsp)
leaq 0x1eae38(%rip), %rdx    # 0x253630
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x28(%rsp), %rdi
movq %r13, %r8
movq %r13, 0x38(%rsp)
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq %r11, 0x30(%rsp)
cmpq %rbp, 0x10(%rsp)
je 0x688c8
movq (%r10), %rax
movzbl (%rax,%rbp), %eax
movzbl (%rdx,%rax), %eax
cmpq $0x3, %rax
ja 0x6888c
leaq (%rax,%r12,4), %r12
andq %r9, %r12
incq %r14
cmpq %r11, %r14
jl 0x68892
movq 0x40(%rsp), %rax
movq 0x18(%rax), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xc2c83
movq 0x38(%rsp), %r8
movq %r8, %rcx
cmpl (%r13), %eax
je 0x6886f
pushq $0x1
popq %rcx
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %r11
leaq 0x1eada6(%rip), %rdx    # 0x253630
jmp 0x68895
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %r8, %rcx
cmpq %r11, %rbp
movl $0x0, %eax
cmovgeq %rcx, %rax
addq %rax, %r15
movq %rbx, %rcx
movq %r15, %rax
subq %r15, %rcx
jl 0x688b9
movq %rbx, %rax
cmpq 0x50(%rsp), %rcx
jg 0x688c8
incq %rbp
movq %rax, %rbx
cmpq %rdi, %rax
jl 0x6881f
cmpq %rdi, %rbx
jl 0x68a86
pushq $-0x1
popq %rbp
leaq -0x2(,%r11,2), %rcx
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %rbp, 0x8(%rsp)
xorl %ebx, %ebx
movq %rcx, 0x70(%rsp)
cmpq 0x10(%rsp), %rbx
je 0x68a6f
movq (%r10), %rax
movzbl (%rax,%rbx), %eax
movzbl (%rdx,%rax), %eax
cmpq $0x3, %rax
ja 0x68926
leaq (%rax,%r13,4), %r13
andq %r9, %r13
incq %r15
cmpq %r11, %r15
jge 0x6896c
movq %rbp, 0x8(%rsp)
jmp 0x68931
movq %rbp, 0x8(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r8, %rax
cmpq %r11, %rbx
movl $0x0, %esi
cmovgeq %rax, %rsi
addq %rsi, %r12
movq %r14, %rsi
movq %r12, %rax
subq %r12, %rsi
jl 0x6895c
movq %r14, %rax
cmpq 0x50(%rsp), %rsi
jg 0x68a6f
incq %rbx
movq %rax, %r14
cmpq %rdi, %rax
jl 0x688f4
jmp 0x68a6f
movq %r15, 0x48(%rsp)
movq %rbp, %r15
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc2c83
cmpl (%rbp), %eax
jne 0x689c2
movq %r15, %rbp
movq %r15, 0x8(%rsp)
movq 0x38(%rsp), %r8
movq %r8, %rax
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %r11
leaq 0x1eac78(%rip), %rdx    # 0x253630
movq 0x48(%rsp), %r15
jmp 0x68934
movq 0x8(%rsp), %rax
cmpq $-0x1, %rax
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %r11
leaq 0x1eac45(%rip), %rdx    # 0x253630
movq %r15, %rbp
movq 0x70(%rsp), %rcx
movq 0x48(%rsp), %r15
je 0x689ff
cmpq %r13, %rax
je 0x68a3e
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
xorl %edx, %edx
cmpq %r11, %rdx
jge 0x68a29
cmpq %r13, %rax
je 0x68a29
movq %rax, %rsi
shrq %cl, %rsi
andl $0x3, %esi
leaq (%rsi,%rax,4), %rax
andq %r9, %rax
incq %rdx
jmp 0x68a0a
cmpq %r11, %rdx
jge 0x68a5b
cmpq %r13, %rax
leaq 0x1eabf8(%rip), %rdx    # 0x253630
jne 0x6891f
movq %r13, %rax
shrq %cl, %rax
andl $0x3, %eax
leaq (%rax,%r13,4), %rax
andq %r9, %rax
movq %rax, 0x8(%rsp)
pushq $0x1
popq %rax
jmp 0x68934
movq %rbp, 0x8(%rsp)
movq %r8, %rax
leaq 0x1eabc6(%rip), %rdx    # 0x253630
jmp 0x68934
cmpq %rdi, %r14
jl 0x68a86
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
orb $0x1, (%rax,%rcx)
movq 0x68(%rsp), %rax
leaq -0x1(%rax), %rbx
pushq $0x1
popq %rbp
xorl %r14d, %r14d
leaq 0x1eac99(%rip), %rsi    # 0x253735
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbx, 0x8(%rsp)
testq %rbx, %rbx
js 0x68b6d
movq (%r10), %rax
movzbl (%rax,%rbx), %eax
movzbl (%rdx,%rax), %eax
movzbl (%rsi,%rax), %eax
movzbl (%rdx,%rax), %eax
cmpq $0x3, %rax
ja 0x68b2e
leaq (%rax,%r12,4), %r12
andq %r9, %r12
incq %r13
cmpq %r11, %r13
jl 0x68b34
movq %r13, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xc2c83
movq 0x38(%rsp), %r8
movq %r8, %rcx
cmpl (%r13), %eax
je 0x68b05
pushq $0x1
popq %rcx
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %r11
leaq 0x1eab10(%rip), %rdx    # 0x253630
leaq 0x1eac0e(%rip), %rsi    # 0x253735
movq 0x10(%rsp), %r13
jmp 0x68b37
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r8, %rcx
cmpq %r11, %rbp
movl $0x0, %eax
cmovgeq %rcx, %rax
addq %rax, %r15
movq %r14, %rcx
movq %r15, %rax
subq %r15, %rcx
jl 0x68b5b
movq %r14, %rax
cmpq 0x50(%rsp), %rcx
jg 0x68b6d
decq %rbx
incq %rbp
movq %rax, %r14
cmpq %rdi, %rax
jl 0x68aaa
cmpq %rdi, %r14
jl 0x68d51
leaq -0x2(,%r11,2), %rbx
pushq $-0x1
popq %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
movq %r15, %rsi
movq 0x8(%rsp), %rbp
movq %rbx, 0x48(%rsp)
testq %rbp, %rbp
js 0x68d36
movq (%r10), %rax
movzbl (%rax,%rbp), %eax
movzbl (%rdx,%rax), %eax
leaq 0x1eab79(%rip), %rcx    # 0x253735
movzbl (%rcx,%rax), %eax
movzbl (%rdx,%rax), %eax
cmpq $0x3, %rax
ja 0x68be8
leaq (%rax,%r13,4), %r13
andq %r9, %r13
movq 0x10(%rsp), %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
cmpq %r11, %rcx
jge 0x68c3e
movq %r15, %rsi
jmp 0x68bf7
movq %r15, %rsi
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
movq %r8, %rax
movq 0x68(%rsp), %rcx
subq %rbp, %rcx
cmpq %r11, %rcx
movl $0x0, %ecx
cmovgeq %rax, %rcx
addq %rcx, %r14
movq %r12, %rcx
movq %r14, %rax
subq %r14, %rcx
jl 0x68c2a
movq %r12, %rax
cmpq 0x50(%rsp), %rcx
jg 0x68d36
decq %rbp
movq %rax, %r12
cmpq %rdi, %rax
jl 0x68ba1
jmp 0x68d36
movq %rsi, 0x8(%rsp)
movq %rbp, %rbx
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc2c83
cmpl (%rbp), %eax
jne 0x68c8d
movq %r15, %rsi
movq 0x38(%rsp), %r8
movq %r8, %rax
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %r11
leaq 0x1ea9ab(%rip), %rdx    # 0x253630
movq %rbx, %rbp
jmp 0x68bfa
movq 0x8(%rsp), %rax
cmpq $-0x1, %rax
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %r11
leaq 0x1ea97a(%rip), %rdx    # 0x253630
movq %rbx, %rbp
movq 0x48(%rsp), %rbx
je 0x68cc5
cmpq %r13, %rax
je 0x68d0a
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
xorl %edx, %edx
cmpq %r11, %rdx
jge 0x68cf5
cmpq %r13, %rax
je 0x68cf5
movq %rax, %rsi
movl %ebx, %ecx
shrq %cl, %rsi
andl $0x3, %esi
leaq (%rsi,%rax,4), %rax
andq %r9, %rax
incq %rdx
jmp 0x68cd4
cmpq %r11, %rdx
jge 0x68d24
cmpq %r13, %rax
leaq 0x1ea92c(%rip), %rdx    # 0x253630
jne 0x68be3
movq %r13, %rax
movl %ebx, %ecx
shrq %cl, %rax
andl $0x3, %eax
leaq (%rax,%r13,4), %rsi
andq %r9, %rsi
pushq $0x1
popq %rax
jmp 0x68bfa
movq %r15, %rsi
movq %r8, %rax
leaq 0x1ea8ff(%rip), %rdx    # 0x253630
jmp 0x68bfa
cmpq %rdi, %r12
jl 0x68d51
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
orb $0x2, (%rax,%rcx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x182277(%rip), %rdi    # 0x1eafde
leaq 0x17f023(%rip), %rsi    # 0x1e7d91
leaq 0x18227e(%rip), %rcx    # 0x1eaff3
movl $0xc5, %edx
callq 0x2110