// File: /workspace/github_c_makefile_star2_O2/aokad[P]sequeeze/seqtk.c
// Function: stk_mask
void stk_mask(kseq_t *seq, const khash_t(reg) *h, int is_complement, int mask_chr)
{
	unsigned i, j;
	khiter_t k;
	k = kh_get(reg, h, seq->name.s);
	if (k == kh_end(h)) { // not found in the hash table
		if (is_complement) {
			if (mask_chr) {
				for (j = 0; j < seq->seq.l; ++j)
					seq->seq.s[j] = mask_chr;
			} else {
				for (j = 0; j < seq->seq.l; ++j)
					seq->seq.s[j] = tolower(seq->seq.s[j]);
			}
		}
	} else {
		reglist_t *p = &kh_val(h, k);
		if (!is_complement) {
			for (i = 0; i < p->n; ++i) {
				unsigned beg = p->a[i]>>32, end = p->a[i];
				if (beg >= seq->seq.l) continue;
				if (end > seq->seq.l) end = seq->seq.l;
				if (!mask_chr) for (j = beg; j < end; ++j) seq->seq.s[j] = tolower(seq->seq.s[j]);
				else for (j = beg; j < end; ++j) seq->seq.s[j] = mask_chr;
			}
		} else {
			int8_t *mask = calloc(seq->seq.l, 1);
			for (i = 0; i < p->n; ++i) {
				unsigned beg = p->a[i]>>32, end = p->a[i];
				if (end >= seq->seq.l) end = seq->seq.l;
				for (j = beg; j < end; ++j) mask[j] = 1;
			}
			if (mask_chr) {
				for (j = 0; j < seq->seq.l; ++j)
					if (mask[j] == 0) seq->seq.s[j] = mask_chr;
			} else {
				for (j = 0; j < seq->seq.l; ++j)
					if (mask[j] == 0) seq->seq.s[j] = tolower(seq->seq.s[j]);
			}
			free(mask);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movq 0x10(%rdi), %rsi
movq %r15, %rdi
callq 0x266f
cmpl (%r15), %eax
jne 0x5e8b
testl %r14d, %r14d
je 0x5e7c
xorl %eax, %eax
testl %ebp, %ebp
je 0x5e73
movl %eax, %eax
cmpq %rax, 0x30(%rbx)
jbe 0x5e7c
movq 0x40(%rbx), %rcx
movb %bpl, (%rcx,%rax)
incl %eax
jmp 0x5e43
callq 0x2280
movq (%rax), %rax
movq 0x40(%rbx), %rcx
movsbq (%rcx,%r14), %rdx
movb (%rax,%rdx,4), %al
movb %al, (%rcx,%r14)
leal 0x1(%r14), %eax
movl %eax, %r14d
cmpq %r14, 0x30(%rbx)
ja 0x5e57
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r12d
shlq $0x4, %r12
addq 0x20(%r15), %r12
testl %r14d, %r14d
je 0x5f13
movq 0x30(%rbx), %r15
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x2160
movq %rax, %r14
movl (%r12), %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x5ee7
movq 0x8(%r12), %rdx
movq (%rdx,%rcx,8), %rsi
movq %rsi, %rdx
shrq $0x20, %rdx
movl %esi, %edi
cmpq %r15, %rdi
cmovaeq %r15, %rsi
movl %esi, %esi
cmpq %rsi, %rdx
jae 0x5ee2
movb $0x1, (%r14,%rdx)
incq %rdx
jmp 0x5ed3
incq %rcx
jmp 0x5eb3
testl %ebp, %ebp
je 0x5f83
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, %r15
jbe 0x5fb6
cmpb $0x0, (%r14,%rax)
jne 0x5f0f
movq 0x40(%rbx), %rcx
movb %bpl, (%rcx,%rax)
movq 0x30(%rbx), %r15
incl %eax
jmp 0x5ef1
xorl %r14d, %r14d
movl (%r12), %eax
cmpq %rax, %r14
jae 0x5e7c
movq 0x8(%r12), %rax
movq (%rax,%r14,8), %rax
movq %rax, %r15
shrq $0x20, %r15
movq 0x30(%rbx), %rcx
cmpq %rcx, %r15
jae 0x5f7e
movl %eax, %edx
cmpq %rcx, %rdx
cmovaq %rcx, %rax
movl %eax, %r13d
testl %ebp, %ebp
je 0x5f79
cmpq %r13, %r15
jae 0x5f7e
movq 0x40(%rbx), %rax
movb %bpl, (%rax,%r15)
incq %r15
jmp 0x5f4c
callq 0x2280
movq (%rax), %rax
movq 0x40(%rbx), %rcx
movsbq (%rcx,%r15), %rdx
movb (%rax,%rdx,4), %al
movb %al, (%rcx,%r15)
incq %r15
cmpq %r13, %r15
jb 0x5f5e
incq %r14
jmp 0x5f16
xorl %r12d, %r12d
movl %r12d, %r12d
cmpq %r12, %r15
jbe 0x5fb6
cmpb $0x0, (%r14,%r12)
jne 0x5fb1
callq 0x2280
movq (%rax), %rax
movq 0x40(%rbx), %rcx
movsbq (%rcx,%r12), %rdx
movb (%rax,%rdx,4), %al
movb %al, (%rcx,%r12)
movq 0x30(%rbx), %r15
incl %r12d
jmp 0x5f86
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2050