// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/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 0x423c6
movq (%r13), %r12
testq %r12, %r12
je 0x423c6
movslq %ebp, %r10
jmp 0x42670
movl %esi, 0xc(%rsp)
movq %r13, 0x20(%rsp)
movq %rax, 0x10(%rsp)
leal 0x100(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x4360
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 0x423fc
leal -0x1(%rbp), %r13d
movl %r13d, %r14d
movslq %r13d, %rbx
cmpl $0x1, %ebp
movq %rdi, 0x18(%rsp)
jle 0x424ce
movq %r15, %rcx
movq %r14, %rdx
movzbl (%rcx), %esi
movl %edx, (%rax,%rsi,4)
incq %rcx
decq %rdx
jne 0x4242c
movl $0x4, %esi
callq 0x4360
movl %ebp, (%rax,%rbx,4)
leal -0x2(%rbp), %ecx
leal -0x1(%rbp), %edx
xorl %edi, %edi
movslq %r13d, %rsi
cmpq %rsi, %rcx
jle 0x42475
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 0x424bc
cmpl %r13d, %ecx
cmovll %ecx, %r13d
testl %r13d, %r13d
js 0x424b4
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 0x424b1
leaq -0x1(%rsi), %r8
testq %rsi, %rsi
movq %r8, %rsi
jg 0x4248c
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x424b4
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 0x4244f
jmp 0x424db
movl $0x4, %esi
callq 0x4360
movl %ebp, (%rax,%rbx,4)
testl %ebp, %ebp
movq 0x20(%rsp), %r13
jle 0x4263a
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 0xf916(%rip), %xmm1     # 0x51e20
movdqa 0xf91e(%rip), %xmm2     # 0x51e30
xorl %esi, %esi
movdqa 0xf924(%rip), %xmm3     # 0x51e40
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0xf924(%rip), %xmm5     # 0x51e50
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 0x42565
movl %ebp, (%r12,%rsi)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x42579
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 0x425b6
movl %ebp, 0x8(%r12,%rsi)
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x425c6
movl %ebp, 0xc(%r12,%rsi)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x4252c
xorl %edx, %edx
movq %r14, %rsi
xorl %edi, %edi
movl (%rax,%rsi,4), %r8d
leaq 0x1(%rsi), %r9
cmpq %r8, %r9
jne 0x42611
movq %r14, %r8
subq %rsi, %r8
movslq %edi, %r9
cmpq %r9, %r8
jle 0x42611
cmpl %ebp, (%r12,%r9,4)
jne 0x42607
movl %r8d, (%r12,%r9,4)
incq %r9
cmpq %r9, %rdx
jne 0x425fd
movl %edx, %edi
decq %rsi
incq %rdx
cmpq %rcx, %rdx
jne 0x425e2
cmpl $0x1, %ebp
je 0x4263a
movq %rax, %rcx
movslq (%rcx), %rdx
movq %rbx, %rsi
subq %rdx, %rsi
movl %r14d, (%r12,%rsi,4)
addq $0x4, %rcx
decq %r14
jne 0x42624
movq %rax, %rdi
callq 0x4610
testq %r13, %r13
je 0x42662
cmpq $0x0, (%r13)
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %r10
jne 0x42670
movq %r12, (%r13)
jmp 0x42670
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %r10
subl %ebp, %esi
js 0x426cd
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 0x426de
leaq -0x1(%r10), %r11
movzbl (%r9,%r10), %ebx
decl %edi
cmpb %bl, -0x1(%r15,%r10)
movq %r11, %r10
je 0x42696
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 0x4268a
testq %r13, %r13
jne 0x426da
movq %r12, %rdi
callq 0x4610
xorl %eax, %eax
jmp 0x426e1
addq %r8, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq