#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 kmp(char *, int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, const char *argv[]) {
  char target[] = "ABC ABCDAB ABCDABCDABDE";
  char *ch = target;
  char pattern[] = "ABCDABD";
  int i;
  i = kmp(target, strlen(target), pattern, strlen(pattern));
  if (i >= 0)
    printf("matched @: %s\n", ch + i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x54(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%rdx
mov    %eax,%ecx
call   1050 <kmp@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jl     11d5 <main+0xa5>
mov    -0x38(%rbp),%rsi
movslq -0x44(%rbp),%rax
add    %rax,%rsi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movaps 0xec1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x45444241444342,%rax
mov    %rax,0x20(%rsp)
movabs $0x44424144434241,%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1050 <kmp@plt>
test   %eax,%eax
js     11a7 <main+0x77>
mov    %eax,%eax
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.target = [24 x i8] c"ABC ABCDAB ABCDABCDABDE\00"
@__const.main.pattern = [8 x i8] c"ABCDABD\00"
@.str = [15 x i8] c"matched @: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [24 x i8]
%7 = alloca i8*
%8 = alloca [8 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [24 x i8]* %6 to i8*
%11 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
store i8* %11, i8** %7
%12 = bitcast [8 x i8]* %8 to i8*
%13 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @kmp(i8* %13, i32 %15, i8* %16, i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i8*, i8** %7
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %22, %2
ret i32 0
}

LLVM IR (-O2):
@__const.main.target = [24 x i8] c"ABC ABCDAB ABCDABCDABDE\00"
@.str = [15 x i8] c"matched @: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [24 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
store i64 19213146501890625, i64* %4
%7 = call i32 @strlen(i8* %5)
%8 = call i32 @strlen(i8* %6)
%9 = call i32 @kmp(i8* %5, i32 %7, i8* %6, i32 %8)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 %12
%14 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %2
ret i32 0
}