#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*/ fgets(char *, int, int /*<<< orphan*/);
int naiveMatch(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strtok(char *, char *);
int main() {
  int result = 0;
  char needle[10], haystack[140];
  printf("Please enter the text.\n");
  fgets(haystack, 140, stdin);
  strtok(haystack, "\n");
  printf("Please enter the pattern to search for.\n");
  fgets(needle, 10, stdin);
  strtok(needle, "\n");
  result = naiveMatch(needle, haystack);
  if (result == -1)
    printf("The given pattern was not found in the given text.\n");
  else
    printf("Pattern found at position %d of the text.\n", result + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    $0x8c,%esi
call   1040 <fgets@plt>
lea    -0xa0(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1050 <strtok@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x12(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1040 <fgets@plt>
lea    -0x12(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strtok@plt>
lea    -0x12(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1060 <naiveMatch@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11f9 <main+0xb9>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120d <main+0xcd>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e79(%rip),%rbx
mov    (%rbx),%edx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x8c,%esi
call   1050 <fgets@plt>
lea    0xe9f(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strtok@plt>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%edx
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <naiveMatch@plt>
cmp    $0xffffffff,%eax
je     11e5 <main+0x95>
add    $0x1,%eax
lea    0xe26(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f1 <main+0xa1>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Please enter the text.\0A\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [41 x i8] c"Please enter the pattern to search for.\0A\00"
@.str.3 = [52 x i8] c"The given pattern was not found in the given text.\0A\00"
@.str.4 = [43 x i8] c"Pattern found at position %d of the text.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca [140 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [140 x i8], [140 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 140, i32 %7)
%9 = getelementptr inbounds [140 x i8], [140 x i8]* %4, i64 0, i64 0
%10 = call i32 @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 10, i32 %13)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%16 = call i32 @strtok(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [140 x i8], [140 x i8]* %4, i64 0, i64 0
%19 = call i32 @naiveMatch(i8* %17, i8* %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
br label %28
24: ; preds = %0
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %22
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.4 = [43 x i8] c"Pattern found at position %d of the text.\0A\00"
@str = [23 x i8] c"Please enter the text.\00"
@str.5 = [40 x i8] c"Please enter the pattern to search for.\00"
@str.6 = [51 x i8] c"The given pattern was not found in the given text.\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca [140 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [140 x i8], [140 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 140, i32 %6)
%8 = call i32 @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.5, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %3, i32 10, i32 %10)
%12 = call i32 @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @naiveMatch(i8* %3, i8* %4)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.6, i64 0, i64 0))
br label %20
17: ; preds = %0
%18 = add nuw nsw i32 %13, 1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %15
ret i32 0
}