#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*/ get_array(char *, int *, int);
scalar_t__ kmp(char *, char *, int *);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
void main() {
  char pat[] = "ABABCABAB";
  int len = strlen(pat);
  int a[len];
  get_array(pat, a, len);
  char text[] = "ABABDABACDABABCABAB";
  if (kmp(text, pat, a)) {
    printf("Pattern found");
  } else {
    printf("Pattern not found");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movabs $0x4142414342414241,%rax
41 42 41
mov    %rax,-0x10(%rbp)
movw   $0x42,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <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,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x48(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
call   1060 <get_array@plt>
mov    -0x48(%rbp),%rdx
mov    0xe8a(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe85(%rip),%eax
mov    %eax,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <kmp@plt>
cmp    $0x0,%rax
je     11e6 <main+0xa6>
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
jmp    11f2 <main+0xb2>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%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   %rbx
sub    $0x28,%rsp
movabs $0x4142414342414241,%rax
41 42 41
mov    %rax,-0x28(%rbp)
movw   $0x42,-0x20(%rbp)
lea    -0x28(%rbp),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r15
mov    %eax,%ecx
mov    %rsp,%rbx
lea    0xf(,%rcx,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <get_array@plt>
movaps 0xe95(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movl   $0x424142,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <kmp@plt>
test   %rax,%rax
lea    0xe59(%rip),%rax
lea    0xe44(%rip),%rdi
cmove  %rax,%rdi
call   1040 <printf@plt>
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.pat = [10 x i8] c"ABABCABAB\00"
@__const.main.text = [20 x i8] c"ABABDABACDABABCABAB\00"
@.str = [14 x i8] c"Pattern found\00"
@.str.1 = [18 x i8] c"Pattern not found\00"
define void @main() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [20 x i8]
%6 = bitcast [10 x i8]* %1 to i8*
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %3
%12 = alloca i32, i64 %10
store i64 %10, i64* %4
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%14 = load i32, i32* %2
%15 = call i32 @get_array(i8* %13, i32* %12, i32 %14)
%16 = bitcast [20 x i8]* %5 to i8*
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%19 = call i64 @kmp(i8* %17, i8* %18, i32* %12)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %25
23: ; preds = %0
%24 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
%26 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@__const.main.pat = [10 x i8] c"ABABCABAB\00"
@__const.main.text = [20 x i8] c"ABABDABACDABABCABAB\00"
@.str = [14 x i8] c"Pattern found\00"
@.str.1 = [18 x i8] c"Pattern not found\00"
define void @main() {
%1 = alloca [10 x i8]
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = call i32 @strlen(i8* %3)
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
%7 = alloca i32, i64 %5
%8 = call i32 @get_array(i8* %3, i32* %7, i32 %4)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%10 = call i64 @kmp(i8* %9, i8* %3, i32* %7)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0)
%13 = call i32 @printf(i8* dereferenceable(1) %12)
ret void
}