#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 characterHash(char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int findPattern(char *pattern, char *input) {
  int k = strlen(pattern);
  int patternHashValue = characterHash(pattern, k);
  int tmpHashValue;
  int n = strlen(input);
  char tmp[k + 1];
  int i;
  for (i = 0; i + k <= n; i++) {
    strncpy(tmp, input + i, k);
    tmp[k] = '\0';
    tmpHashValue = characterHash(tmp, k);
    if (tmpHashValue == patternHashValue && !strcmp(tmp, pattern))
      return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<findPattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <characterHash@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     122b <findPattern+0xeb>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x48(%rbp),%rdi
movslq -0x1c(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x1c(%rbp),%esi
call   1040 <characterHash@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1218 <findPattern+0xd8>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1218 <findPattern+0xd8>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    1239 <findPattern+0xf9>
jmp    121d <findPattern+0xdd>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a7 <findPattern+0x67>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPattern>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <characterHash@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%r14),%ecx
mov    %rsp,%r13
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
mov    $0xffffffff,%ecx
cmp    %eax,%r14d
jg     1203 <findPattern+0xc3>
mov    %r12d,-0x2c(%rbp)
mov    %rbx,-0x38(%rbp)
mov    %r15,-0x40(%rbp)
mov    %r14d,%r14d
movslq %r14d,%r12
xor    %r15d,%r15d
jmp    11be <findPattern+0x7e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
lea    (%r14,%r15,1),%ecx
mov    %ebx,%eax
cmp    %ebx,%ecx
jg     11fe <findPattern+0xbe>
mov    %eax,%ebx
mov    -0x40(%rbp),%rax
lea    (%rax,%r15,1),%rsi
mov    %r13,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%r13,%r12,1)
mov    %r13,%rdi
mov    %r14d,%esi
call   1040 <characterHash@plt>
cmp    -0x2c(%rbp),%eax
jne    11b0 <findPattern+0x70>
mov    %r13,%rdi
mov    -0x38(%rbp),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11b0 <findPattern+0x70>
mov    %r15d,%ecx
jmp    1203 <findPattern+0xc3>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findPattern(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %6
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = call i32 @characterHash(i8* %16, i32 %17)
store i32 %18, i32* %7
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %9
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %10
%25 = alloca i8, i64 %23
store i64 %23, i64* %11
store i32 0, i32* %12
br label %26
26: ; preds = %54, %2
%27 = load i32, i32* %12
%28 = load i32, i32* %6
%29 = add nsw i32 %27, %28
%30 = load i32, i32* %9
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %57
32: ; preds = %26
%33 = load i8*, i8** %5
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i32, i32* %6
%38 = call i32 @strncpy(i8* %25, i8* %36, i32 %37)
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %25, i64 %40
store i8 0, i8* %41
%42 = load i32, i32* %6
%43 = call i32 @characterHash(i8* %25, i32 %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = load i32, i32* %7
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %53
47: ; preds = %32
%48 = load i8*, i8** %4
%49 = call i32 @strcmp(i8* %25, i8* %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %47
%52 = load i32, i32* %12
store i32 %52, i32* %3
store i32 1, i32* %13
br label %58
53: ; preds = %47, %32
br label %54
54: ; preds = %53
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %26
57: ; preds = %26
store i32 -1, i32* %3
store i32 1, i32* %13
br label %58
58: ; preds = %57, %51
%59 = load i8*, i8** %10
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
define i32 @findPattern(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @characterHash(i8* %0, i32 %3)
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %3, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = icmp sgt i32 %3, %5
br i1 %9, label %29, label %10
10: ; preds = %2
%11 = sext i32 %3 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
br label %13
13: ; preds = %10, %22
%14 = phi i64 [ 0, %10 ], [ %23, %22 ]
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = call i32 @strncpy(i8* %8, i8* %15, i32 %3)
store i8 0, i8* %12
%17 = call i32 @characterHash(i8* %8, i32 %3)
%18 = icmp eq i32 %17, %4
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @strcmp(i8* %8, i8* dereferenceable(1) %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %13, %19
%23 = add nuw i64 %14, 1
%24 = trunc i64 %23 to i32
%25 = add nsw i32 %3, %24
%26 = icmp sgt i32 %25, %5
br i1 %26, label %29, label %13
27: ; preds = %19
%28 = trunc i64 %14 to i32
br label %29
29: ; preds = %22, %27, %2
%30 = phi i32 [ -1, %2 ], [ %28, %27 ], [ -1, %22 ]
ret i32 %30
}