#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ preProcess(char *, int *, int);
int /*<<< orphan*/ printCharArray(char *);
int /*<<< orphan*/ printIntArray(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ searchAll(char *, char *, int *);
int strlen(char *);
void kmp(char *source, char *key) {
  int keyLength = strlen(key);
  int next[keyLength];
  memset(next, 0, keyLength * sizeof(int));
  printCharArray(source);
  printf("\n");
  printCharArray(key);
  preProcess(key, next, keyLength);
  printIntArray(next, keyLength);
  printf("\n");
  searchAll(source, key, next);
}


x86 assembly (clang, -O0):
<kmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1030 <printCharArray@plt>
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <printCharArray@plt>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
call   1070 <preProcess@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <printIntArray@plt>
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <searchAll@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kmp>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %eax,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0x0(,%r12,4),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %r14,%rdi
call   1040 <printCharArray@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1040 <printCharArray@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1070 <preProcess@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1090 <printIntArray@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <searchAll@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @kmp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i32, i64 %11
store i64 %11, i64* %7
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i32 @memset(i32* %13, i32 0, i32 %17)
%19 = load i8*, i8** %3
%20 = call i32 @printCharArray(i8* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %4
%23 = call i32 @printCharArray(i8* %22)
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = call i32 @preProcess(i8* %24, i32* %13, i32 %25)
%27 = load i32, i32* %5
%28 = call i32 @printIntArray(i32* %13, i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = load i8*, i8** %3
%31 = load i8*, i8** %4
%32 = call i32 @searchAll(i8* %30, i8* %31, i32* %13)
%33 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
define void @kmp(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = zext i32 %3 to i64
%5 = alloca i32, i64 %4
%6 = shl i32 %3, 2
%7 = call i32 @memset(i32* %5, i32 0, i32 %6)
%8 = call i32 @printCharArray(i8* %0)
%9 = call i32 @putchar(i32 10)
%10 = call i32 @printCharArray(i8* %1)
%11 = call i32 @preProcess(i8* %1, i32* %5, i32 %3)
%12 = call i32 @printIntArray(i32* %5, i32 %3)
%13 = call i32 @putchar(i32 10)
%14 = call i32 @searchAll(i8* %0, i8* %1, i32* %5)
ret void
}