#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*/ echo_array(int *, int);
int /*<<< orphan*/ fail_func_p(char const *, int *);
int /*<<< orphan*/ printf(char *, char const *, char *);
int search(char const *, char const *);
int strlen(char const *);
int main(int argc, char *argv[]) {
  const char *s = "ababcabcacbab";
  const char *p = "aaaab";
  int m = strlen(p);
  int next[m];
  fail_func_p(p, next);
  echo_array(next, m);
  int idx = search(s, p);
  printf("%s %s\n", s, idx == -1 ? "not found" : s + idx);
  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)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x50(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <fail_func_p@plt>
mov    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <echo_array@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <search@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11f6 <main+0xa6>
lea    0xe2e(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1205 <main+0xb5>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x58(%rbp),%rdx
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%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    0xead(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
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
call   1060 <fail_func_p@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1070 <echo_array@plt>
lea    0xe60(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <search@plt>
cltq
lea    (%rbx,%rax,1),%rcx
cmp    $0xffffffff,%eax
lea    0xe60(%rip),%rdx
cmovne %rcx,%rdx
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"ababcabcacbab\00"
@.str.1 = [6 x i8] c"aaaab\00"
@.str.2 = [7 x i8] c"%s %s\0A\00"
@.str.3 = [10 x i8] c"not found\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i32, i64 %15
store i64 %15, i64* %10
%18 = load i8*, i8** %7
%19 = call i32 @fail_func_p(i8* %18, i32* %17)
%20 = load i32, i32* %8
%21 = call i32 @echo_array(i32* %17, i32 %20)
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = call i32 @search(i8* %22, i8* %23)
store i32 %24, i32* %11
%25 = load i8*, i8** %6
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %2
br label %34
29: ; preds = %2
%30 = load i8*, i8** %6
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
br label %34
34: ; preds = %29, %28
%35 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %28 ], [ %33, %29 ]
%36 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %35)
store i32 0, i32* %3
%37 = load i8*, i8** %9
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"ababcabcacbab\00"
@.str.1 = [6 x i8] c"aaaab\00"
@.str.2 = [7 x i8] c"%s %s\0A\00"
@.str.3 = [10 x i8] c"not found\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%4 = zext i32 %3 to i64
%5 = alloca i32, i64 %4
%6 = call i32 @fail_func_p(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%7 = call i32 @echo_array(i32* %5, i32 %3)
%8 = call i32 @search(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds [14 x i8], [14 x i8]* @.str, i64 0, i64 %10
%12 = select i1 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %12)
ret i32 0
}