// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/kstring.c
// Function: kmemmem
void *kmemmem(const void *_str, int n, const void *_pat, int m, int **_prep)
{
	int i, j, *prep = 0, *bmGs, *bmBc;
	const ubyte_t *str, *pat;
	str = (const ubyte_t*)_str; pat = (const ubyte_t*)_pat;
	prep = (_prep == 0 || *_prep == 0)? ksBM_prep(pat, m) : *_prep;
	if (_prep && *_prep == 0) *_prep = prep;
	bmGs = prep; bmBc = prep + m;
	j = 0;
	while (j <= n - m) {
		for (i = m - 1; i >= 0 && pat[i] == str[i+j]; --i);
		if (i >= 0) {
			int max = bmBc[str[i+j]] - m + 1 + i;
			if (max < bmGs[i]) max = bmGs[i];
			j += max;
		} else return (void*)(str + j);
	}
	if (_prep == 0) free(prep);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r14
movl %ecx, %r13d
movq %rdx, %r15
movq %rdi, %rax
testq %r8, %r8
je 0x18d23
movq (%r14), %r12
testq %r12, %r12
jne 0x18eb0
movl %esi, 0xc(%rsp)
movq %rax, 0x10(%rsp)
leal 0x100(%r13), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x32e0
movq %rax, %r12
movslq %r13d, %rdi
leaq (%rax,%rdi,4), %rax
xorl %ecx, %ecx
movl %r13d, (%rax,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x18d4c
leal -0x1(%r13), %ebx
movl %ebx, %ebp
cmpl $0x2, %r13d
jl 0x18d7c
movq %r15, %rcx
movq %rbp, %rdx
movzbl (%rcx), %esi
movl %edx, (%rax,%rsi,4)
incq %rcx
decq %rdx
jne 0x18d6e
movl $0x4, %esi
callq 0x32e0
movslq %ebx, %rcx
movl %r13d, (%rax,%rcx,4)
cmpl $0x2, %r13d
jl 0x18e22
leal -0x2(%r13), %esi
movslq %esi, %rdx
xorl %r8d, %r8d
movl $0x1, %edi
movslq %ebx, %r9
cmpq %r9, %rsi
jle 0x18dcc
movl %r8d, %r10d
notl %r10d
addl %esi, %r10d
addl %r13d, %r10d
movslq %r10d, %r10
movl (%rax,%r10,4), %r10d
movl %esi, %r11d
subl %ebx, %r11d
cmpl %r11d, %r10d
jl 0x18e0c
cmpl %ebx, %esi
cmovll %esi, %ebx
testl %ebx, %ebx
js 0x18e03
cmpq %r9, %rdx
cmovlq %rdx, %r9
movb (%r15,%r9), %r8b
leal (%rdi,%r9), %r10d
movslq %r10d, %r10
cmpb (%r15,%r10), %r8b
jne 0x18e00
leaq -0x1(%r9), %r8
testq %r9, %r9
movq %r8, %r9
jg 0x18ddc
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x18e03
movl %r9d, %ebx
movl %esi, %r10d
subl %ebx, %r10d
movl %esi, %r8d
movl %r10d, (%rax,%rsi,4)
leaq -0x1(%rsi), %r9
decq %rdx
incq %rdi
testq %rsi, %rsi
movq %r9, %rsi
jg 0x18da6
testl %r13d, %r13d
jle 0x18e80
movl %r13d, %edx
xorl %esi, %esi
movl %r13d, (%r12,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x18e2c
testl %r13d, %r13d
jle 0x18e80
xorl %esi, %esi
movq %rbp, %rdi
xorl %r8d, %r8d
movl (%rax,%rdi,4), %r9d
leaq 0x1(%rdi), %r10
cmpq %r9, %r10
jne 0x18e75
movq %rbp, %r10
subq %rdi, %r10
movslq %r8d, %r9
cmpq %r9, %r10
jle 0x18e75
cmpl %r13d, (%r12,%r9,4)
jne 0x18e6a
movl %r10d, (%r12,%r9,4)
incq %r9
cmpq %r9, %rsi
jne 0x18e60
movl %r9d, %r8d
decq %rdi
incq %rsi
cmpq %rdx, %rsi
jne 0x18e45
cmpl $0x2, %r13d
jl 0x18e9f
movq %rax, %rdx
movslq (%rdx), %rsi
movq %rcx, %rdi
subq %rsi, %rdi
movl %ebp, (%r12,%rdi,4)
addq $0x4, %rdx
decq %rbp
jne 0x18e89
movq %rax, %rdi
callq 0x3060
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %esi
testq %r14, %r14
je 0x18ebe
cmpq $0x0, (%r14)
jne 0x18ebe
movq %r12, (%r14)
subl %r13d, %esi
js 0x18f0d
movslq %r13d, %r13
leaq (%r12,%r13,4), %rcx
leaq -0x1(%rax), %rdx
xorl %ebp, %ebp
movslq %ebp, %r8
leaq (%rdx,%r8), %r9
movl $0x1, %edi
movq %r13, %r10
testq %r10, %r10
jle 0x18f1e
leaq -0x1(%r10), %r11
movzbl (%r9,%r10), %ebx
decl %edi
cmpb %bl, -0x1(%r15,%r10)
movq %r11, %r10
je 0x18edf
addl (%rcx,%rbx,4), %edi
movl (%r12,%r11,4), %r8d
cmpl %r8d, %edi
cmovlel %r8d, %edi
addl %edi, %ebp
cmpl %esi, %ebp
jle 0x18ed0
testq %r14, %r14
jne 0x18f1a
movq %r12, %rdi
callq 0x3060
xorl %eax, %eax
jmp 0x18f21
addq %r8, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq