#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*/ kmp(char *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  int i;
  int next[20] = {0};
  char T[] = "ababxbababcadfdsss";
  char P[] = "abca";
  printf("%s\n", T);
  printf("%s\n", P);
  kmp(T, P, next);
  for (i = 0; i < strlen(P); ++i) {
    printf("%d ", next[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
mov    0xe97(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xe94(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0xe91(%rip),%ax
mov    %ax,-0x70(%rbp)
mov    0xe89(%rip),%al
mov    %al,-0x6e(%rbp)
mov    0xe81(%rip),%eax
mov    %eax,-0x85(%rbp)
mov    0xe79(%rip),%al
mov    %al,-0x81(%rbp)
lea    -0x80(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x85(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    -0x85(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1060 <kmp@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x85(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
cmp    %ecx,%eax
jge    122f <main+0xef>
movslq -0x8(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e6 <main+0xa6>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps 0xe81(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x737373,0x1f(%rsp)
movb   $0x0,0xc(%rsp)
movl   $0x61636261,0x8(%rsp)
61
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <kmp@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1201 <main+0xb1>
lea    0xe42(%rip),%r14
lea    0x8(%rsp),%r15
xor    %ebx,%ebx
nopl   (%rax)
mov    0x30(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11e0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.T = [19 x i8] c"ababxbababcadfdsss\00"
@__const.main.P = [5 x i8] c"abca\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i32]
%4 = alloca [19 x i8]
%5 = alloca [5 x i8]
store i32 0, i32* %1
%6 = bitcast [20 x i32]* %3 to i8*
%7 = bitcast [19 x i8]* %4 to i8*
%8 = bitcast [5 x i8]* %5 to i8*
%9 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%16 = call i32 @kmp(i8* %13, i8* %14, i32* %15)
store i32 0, i32* %2
br label %17
17: ; preds = %28, %0
%18 = load i32, i32* %2
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %17
31: ; preds = %17
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.T = [19 x i8] c"ababxbababcadfdsss\00"
@__const.main.P = [5 x i8] c"abca\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca [19 x i8]
%3 = alloca [5 x i8]
%4 = bitcast [20 x i32]* %1 to i8*
%5 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%7 = call i32 @puts(i8* %5)
%8 = call i32 @puts(i8* %6)
%9 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%10 = call i32 @kmp(i8* %5, i8* %6, i32* %9)
%11 = call i32 @strlen(i8* %6)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %0, %13
%14 = phi i64 [ %18, %13 ], [ 0, %0 ]
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %14, 1
%19 = call i32 @strlen(i8* %6)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %13, label %22
22: ; preds = %13, %0
%23 = call i32 @putchar(i32 10)
ret i32 0
}