#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 HashText(char *, int);
int MoveHash(int, int, char, char);
int strlen(char *);
int FindExpression(char *Text, char *Expression) {
  int CurrentIndex = 0;
  int TextLength = strlen(Text);
  int HashLength = strlen(Expression);
  int CurrentHash = HashText(Text, HashLength);
  int ExpressionHash = HashText(Expression, HashLength);
  while (CurrentIndex < TextLength) {
    if (CurrentHash == ExpressionHash) {
      return CurrentIndex;
    }
    CurrentHash = MoveHash(CurrentHash, HashLength, Text[CurrentIndex],
                           Text[CurrentIndex + HashLength]);
    CurrentIndex = CurrentIndex + 1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<FindExpression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <HashText@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <HashText@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11db <FindExpression+0xab>
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    11a0 <FindExpression+0x70>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <FindExpression+0xb2>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movsbl %dl,%edx
movsbl (%rax,%rcx,1),%ecx
call   1050 <MoveHash@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <FindExpression+0x4d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindExpression>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <HashText@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %r13d,%esi
call   1030 <HashText@plt>
mov    %eax,0x4(%rsp)
mov    $0xffffffff,%eax
test   %ebp,%ebp
jle    11bf <FindExpression+0x8f>
movslq %r13d,%r14
mov    %ebp,%ebp
mov    %r15,%r12
add    %r15,%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
cmp    0x4(%rsp),%ebx
je     11bc <FindExpression+0x8c>
movsbl (%r12,%r15,1),%edx
movsbl (%r14,%r15,1),%ecx
mov    %ebx,%edi
mov    %r13d,%esi
call   1050 <MoveHash@plt>
mov    %eax,%ebx
add    $0x1,%r15
cmp    %r15,%rbp
jne    1190 <FindExpression+0x60>
mov    $0xffffffff,%eax
jmp    11bf <FindExpression+0x8f>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FindExpression(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 i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %8
%15 = load i8*, i8** %4
%16 = load i32, i32* %8
%17 = call i32 @HashText(i8* %15, i32 %16)
store i32 %17, i32* %9
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = call i32 @HashText(i8* %18, i32 %19)
store i32 %20, i32* %10
br label %21
21: ; preds = %31, %2
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %49
25: ; preds = %21
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %50
31: ; preds = %25
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = load i8*, i8** %4
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %4
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = add nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
%45 = load i8, i8* %44
%46 = call i32 @MoveHash(i32 %32, i32 %33, i8 signext %38, i8 signext %45)
store i32 %46, i32* %9
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %21
49: ; preds = %21
store i32 -1, i32* %3
br label %50
50: ; preds = %49, %29
%51 = load i32, i32* %3
ret i32 %51
}

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