// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %r8, %r14
movl %ecx, %r13d
movq %rdx, %r15
movq %rdi, %rax
testq %r8, %r8
je 0x4346d
movq (%r14), %r12
testq %r12, %r12
jne 0x435fa
movl %esi, 0xc(%rsp)
movq %rax, 0x10(%rsp)
leal 0x100(%r13), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x4360
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 0x43496
leal -0x1(%r13), %ebx
movl %ebx, %ebp
cmpl $0x2, %r13d
jl 0x434c6
movq %r15, %rcx
movq %rbp, %rdx
movzbl (%rcx), %esi
movl %edx, (%rax,%rsi,4)
incq %rcx
decq %rdx
jne 0x434b8
movl $0x4, %esi
callq 0x4360
movslq %ebx, %rcx
movl %r13d, (%rax,%rcx,4)
cmpl $0x2, %r13d
jl 0x4356c
leal -0x2(%r13), %esi
movslq %esi, %rdx
xorl %r8d, %r8d
movl $0x1, %edi
movslq %ebx, %r9
cmpq %r9, %rsi
jle 0x43516
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 0x43556
cmpl %ebx, %esi
cmovll %esi, %ebx
testl %ebx, %ebx
js 0x4354d
cmpq %r9, %rdx
cmovlq %rdx, %r9
movb (%r15,%r9), %r8b
leal (%rdi,%r9), %r10d
movslq %r10d, %r10
cmpb (%r15,%r10), %r8b
jne 0x4354a
leaq -0x1(%r9), %r8
testq %r9, %r9
movq %r8, %r9
jg 0x43526
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x4354d
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 0x434f0
testl %r13d, %r13d
jle 0x435ca
movl %r13d, %edx
xorl %esi, %esi
movl %r13d, (%r12,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x43576
testl %r13d, %r13d
jle 0x435ca
xorl %esi, %esi
movq %rbp, %rdi
xorl %r8d, %r8d
movl (%rax,%rdi,4), %r9d
leaq 0x1(%rdi), %r10
cmpq %r9, %r10
jne 0x435bf
movq %rbp, %r10
subq %rdi, %r10
movslq %r8d, %r9
cmpq %r9, %r10
jle 0x435bf
cmpl %r13d, (%r12,%r9,4)
jne 0x435b4
movl %r10d, (%r12,%r9,4)
incq %r9
cmpq %r9, %rsi
jne 0x435aa
movl %r9d, %r8d
decq %rdi
incq %rsi
cmpq %rdx, %rsi
jne 0x4358f
cmpl $0x2, %r13d
jl 0x435e9
movq %rax, %rdx
movslq (%rdx), %rsi
movq %rcx, %rdi
subq %rsi, %rdi
movl %ebp, (%r12,%rdi,4)
addq $0x4, %rdx
decq %rbp
jne 0x435d3
movq %rax, %rdi
callq 0x4610
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %esi
testq %r14, %r14
je 0x43608
cmpq $0x0, (%r14)
jne 0x43608
movq %r12, (%r14)
subl %r13d, %esi
js 0x43657
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 0x43668
leaq -0x1(%r10), %r11
movzbl (%r9,%r10), %ebx
decl %edi
cmpb %bl, -0x1(%r15,%r10)
movq %r11, %r10
je 0x43629
addl (%rcx,%rbx,4), %edi
movl (%r12,%r11,4), %r8d
cmpl %r8d, %edi
cmovlel %r8d, %edi
addl %edi, %ebp
cmpl %esi, %ebp
jle 0x4361a
testq %r14, %r14
jne 0x43664
movq %r12, %rdi
callq 0x4610
xorl %eax, %eax
jmp 0x4366b
addq %r8, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq