#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*/ getNext(char *, int *, int);
int indexKMP(char *, char *, int *);
int indexOf(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main(void) {
  char *s1 = "abertabc";
  char *s2 = "abc";
  int next[strlen(s2)];
  getNext(s2, next, strlen(s2));
  printf("index abc: %u\n", indexOf(s1, s2));
  printf("indexKMP abc: %u\n", indexKMP(s1, s2, next));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe94(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1060 <getNext@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <indexOf@plt>
mov    %eax,%esi
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <indexKMP@plt>
mov    %eax,%esi
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea4(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <getNext@plt>
lea    0xe64(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <indexOf@plt>
lea    0xe5b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <indexKMP@plt>
lea    0xe4e(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"abertabc\00"
@.str.1 = [4 x i8] c"abc\00"
@.str.2 = [15 x i8] c"index abc: %u\0A\00"
@.str.3 = [18 x i8] c"indexKMP abc: %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i32, i64 %8
store i64 %8, i64* %5
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @getNext(i8* %11, i32* %10, i32 %13)
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = call i32 @indexOf(i8* %15, i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %2
%20 = load i8*, i8** %3
%21 = call i32 @indexKMP(i8* %19, i8* %20, i32* %10)
%22 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %21)
store i32 0, i32* %1
%23 = load i8*, i8** %4
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [9 x i8] c"abertabc\00"
@.str.1 = [4 x i8] c"abc\00"
@.str.2 = [15 x i8] c"index abc: %u\0A\00"
@.str.3 = [18 x i8] c"indexKMP abc: %u\0A\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%2 = zext i32 %1 to i64
%3 = alloca i32, i64 %2
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @getNext(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32 %4)
%6 = call i32 @indexOf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = call i32 @indexKMP(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %8)
ret i32 0
}