// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %r8, %r13
movl %ecx, %ebp
movq %rdx, %r15
movq %rdi, %rax
testq %r8, %r8
je 0x1931f
movq (%r13), %r12
testq %r12, %r12
je 0x1931f
movslq %ebp, %r10
jmp 0x195c9
movl %esi, 0xc(%rsp)
movq %r13, 0x20(%rsp)
movq %rax, 0x10(%rsp)
leal 0x100(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x32e0
movq %rax, %r12
movslq %ebp, %rdi
leaq (%rax,%rdi,4), %rax
movd %edi, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
xorl %ecx, %ecx
movdqu %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x19355
leal -0x1(%rbp), %r13d
movl %r13d, %r14d
movslq %r13d, %rbx
cmpl $0x1, %ebp
movq %rdi, 0x18(%rsp)
jle 0x19427
movq %r15, %rcx
movq %r14, %rdx
movzbl (%rcx), %esi
movl %edx, (%rax,%rsi,4)
incq %rcx
decq %rdx
jne 0x19385
movl $0x4, %esi
callq 0x32e0
movl %ebp, (%rax,%rbx,4)
leal -0x2(%rbp), %ecx
leal -0x1(%rbp), %edx
xorl %edi, %edi
movslq %r13d, %rsi
cmpq %rsi, %rcx
jle 0x193ce
movl %edi, %r8d
notl %r8d
addl %ecx, %r8d
addl %ebp, %r8d
movslq %r8d, %r8
movl (%rax,%r8,4), %r8d
movl %ecx, %r9d
subl %r13d, %r9d
cmpl %r9d, %r8d
jl 0x19415
cmpl %r13d, %ecx
cmovll %ecx, %r13d
testl %r13d, %r13d
js 0x1940d
cmpq %rsi, %rcx
cmovlq %rcx, %rsi
movl %edx, %edi
subl %ecx, %edi
movb (%r15,%rsi), %r8b
leal (%rdi,%rsi), %r9d
movslq %r9d, %r9
cmpb (%r15,%r9), %r8b
jne 0x1940a
leaq -0x1(%rsi), %r8
testq %rsi, %rsi
movq %r8, %rsi
jg 0x193e5
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x1940d
movl %esi, %r13d
movl %ecx, %r8d
subl %r13d, %r8d
movl %ecx, %edi
movl %r8d, (%rax,%rcx,4)
leaq -0x1(%rcx), %rsi
testq %rcx, %rcx
movq %rsi, %rcx
jg 0x193a8
jmp 0x19434
movl $0x4, %esi
callq 0x32e0
movl %ebp, (%rax,%rbx,4)
testl %ebp, %ebp
movq 0x20(%rsp), %r13
jle 0x19593
movl %ebp, %ecx
leal 0x3(%rbp), %edx
leaq -0x1(%rcx), %rsi
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %edx
shlq $0x4, %rdx
movdqa 0xd3d(%rip), %xmm1      # 0x1a1a0
movdqa 0xd45(%rip), %xmm2      # 0x1a1b0
xorl %esi, %esi
movdqa 0xd4b(%rip), %xmm3      # 0x1a1c0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0xd4b(%rip), %xmm5      # 0x1a1d0
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %edi
notl %edi
testb $0x1, %dil
je 0x194be
movl %ebp, (%r12,%rsi)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x194d2
movl %ebp, 0x4(%r12,%rsi)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %edi
testb $0x1, %dil
je 0x1950f
movl %ebp, 0x8(%r12,%rsi)
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x1951f
movl %ebp, 0xc(%r12,%rsi)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x19485
xorl %edx, %edx
movq %r14, %rsi
xorl %edi, %edi
movl (%rax,%rsi,4), %r8d
leaq 0x1(%rsi), %r9
cmpq %r8, %r9
jne 0x1956a
movq %r14, %r8
subq %rsi, %r8
movslq %edi, %r9
cmpq %r9, %r8
jle 0x1956a
cmpl %ebp, (%r12,%r9,4)
jne 0x19560
movl %r8d, (%r12,%r9,4)
incq %r9
cmpq %r9, %rdx
jne 0x19556
movl %edx, %edi
decq %rsi
incq %rdx
cmpq %rcx, %rdx
jne 0x1953b
cmpl $0x1, %ebp
je 0x19593
movq %rax, %rcx
movslq (%rcx), %rdx
movq %rbx, %rsi
subq %rdx, %rsi
movl %r14d, (%r12,%rsi,4)
addq $0x4, %rcx
decq %r14
jne 0x1957d
movq %rax, %rdi
callq 0x3060
testq %r13, %r13
je 0x195bb
cmpq $0x0, (%r13)
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %r10
jne 0x195c9
movq %r12, (%r13)
jmp 0x195c9
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %r10
subl %ebp, %esi
js 0x19626
leaq (%r12,%r10,4), %rcx
movq %rcx, 0x10(%rsp)
movl %r10d, %ecx
subl %ebp, %ecx
incl %ecx
leaq -0x1(%rax), %rdx
xorl %ebp, %ebp
movslq %ebp, %r8
leaq (%rdx,%r8), %r9
movl %ecx, %edi
movq %r10, %r14
testq %r10, %r10
jle 0x19637
leaq -0x1(%r10), %r11
movzbl (%r9,%r10), %ebx
decl %edi
cmpb %bl, -0x1(%r15,%r10)
movq %r11, %r10
je 0x195ef
movq 0x10(%rsp), %r8
addl (%r8,%rbx,4), %edi
movl (%r12,%r11,4), %r8d
cmpl %r8d, %edi
cmovlel %r8d, %edi
addl %edi, %ebp
cmpl %esi, %ebp
movq %r14, %r10
jle 0x195e3
testq %r13, %r13
jne 0x19633
movq %r12, %rdi
callq 0x3060
xorl %eax, %eax
jmp 0x1963a
addq %r8, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq