#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*/ build_array(char *, int *, int);
int /*<<< orphan*/ kmp(char *, char *, int, int *);
int /*<<< orphan*/ print(int *, int);
int strlen(char *);
void main() {
  char text[] = "hello atratreya";
  char pat[] = "atratr";
  int p_len = strlen(pat);
  int a[p_len];
  build_array(pat, a, p_len);
  print(a, p_len);
  kmp(text, pat, p_len, a);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,-0x10(%rbp)
movl   $0x727461,-0x15(%rbp)
movl   $0x61727461,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
call   1030 <build_array@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <print@plt>
mov    -0x38(%rbp),%rcx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <kmp@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movl   $0x727461,-0x25(%rbp)
movl   $0x61727461,-0x28(%rbp)
lea    -0x28(%rbp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rsp,%r12
mov    %eax,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <build_array@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <print@plt>
lea    -0x40(%rbp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1060 <kmp@plt>
mov    %r12,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.text = [16 x i8] c"hello atratreya\00"
@__const.main.pat = [7 x i8] c"atratr\00"
define void @main() {
%1 = alloca [16 x i8]
%2 = alloca [7 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast [16 x i8]* %1 to i8*
%7 = bitcast [7 x i8]* %2 to i8*
%8 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i32, i64 %11
store i64 %11, i64* %5
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @build_array(i8* %14, i32* %13, i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @print(i32* %13, i32 %17)
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @kmp(i8* %19, i8* %20, i32 %21, i32* %13)
%23 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@__const.main.text = [16 x i8] c"hello atratreya\00"
@__const.main.pat = [7 x i8] c"atratr\00"
define void @main() {
%1 = alloca [16 x i8]
%2 = alloca [7 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca i32, i64 %6
%9 = call i32 @build_array(i8* %4, i32* %8, i32 %5)
%10 = call i32 @print(i32* %8, i32 %5)
%11 = call i32 @kmp(i8* %3, i8* %4, i32 %5, i32* %8)
ret void
}