#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 EOF;
int /*<<< orphan*/ getch();
int getchar();
scalar_t__ locate(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
main() {
  char inp[10000], searchstr[10000];
  int d, c, i;
  d = 0;
  i = 0;
  for (d = 0; d <= 10000 && (c = getchar()) != EOF; ++d)
    inp[d] = c;
  printf("What would you like to search?");
  for (i = 0; i <= 10000 && (c = getchar()) != EOF; ++i)
    searchstr[i] = c;
  for (i = 0; i < strlen(inp); i++)
    if (locate(inp, searchstr, i)) {
      printf("\n%s", searchstr);
      getch();
      break;
    }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x4e34(%rbp)
movl   $0x0,-0x4e3c(%rbp)
movl   $0x0,-0x4e34(%rbp)
xor    %eax,%eax
cmpl   $0x2710,-0x4e34(%rbp)
mov    %al,-0x4e3d(%rbp)
jg     11b7 <main+0x67>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x4e38(%rbp)
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x4e3d(%rbp)
mov    -0x4e3d(%rbp),%al
test   $0x1,%al
jne    11ca <main+0x7a>
jmp    11f4 <main+0xa4>
mov    -0x4e38(%rbp),%eax
mov    %al,%cl
movslq -0x4e34(%rbp),%rax
mov    %cl,-0x2720(%rbp,%rax,1)
mov    -0x4e34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e34(%rbp)
jmp    1180 <main+0x30>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4e3c(%rbp)
xor    %eax,%eax
cmpl   $0x2710,-0x4e3c(%rbp)
mov    %al,-0x4e3e(%rbp)
jg     1243 <main+0xf3>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x4e38(%rbp)
mov    0x2db0(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x4e3e(%rbp)
mov    -0x4e3e(%rbp),%al
test   $0x1,%al
jne    1256 <main+0x106>
jmp    1280 <main+0x130>
mov    -0x4e38(%rbp),%eax
mov    %al,%cl
movslq -0x4e3c(%rbp),%rax
mov    %cl,-0x4e30(%rbp,%rax,1)
mov    -0x4e3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e3c(%rbp)
jmp    120c <main+0xbc>
movl   $0x0,-0x4e3c(%rbp)
mov    -0x4e3c(%rbp),%eax
mov    %eax,-0x4e44(%rbp)
lea    -0x2720(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x4e44(%rbp),%eax
cmp    %ecx,%eax
jge    130f <main+0x1bf>
lea    -0x2720(%rbp),%rdi
lea    -0x4e30(%rbp),%rsi
mov    -0x4e3c(%rbp),%edx
call   1060 <locate@plt>
cmp    $0x0,%rax
je     12f6 <main+0x1a6>
lea    -0x4e30(%rbp),%rsi
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <getch@plt>
jmp    130f <main+0x1bf>
jmp    12fb <main+0x1ab>
mov    -0x4e3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e3c(%rbp)
jmp    128a <main+0x13a>
mov    -0x4(%rbp),%eax
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x4e20,%rsp
mov    0x2e85(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r14),%eax
je     1190 <main+0x40>
mov    %al,0x2710(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x2711,%rbx
jne    1170 <main+0x20>
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r14),%eax
je     11bc <main+0x6c>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x2711,%rbx
jne    11a0 <main+0x50>
lea    0x2710(%rsp),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    121b <main+0xcb>
xor    %ebx,%ebx
lea    0x2710(%rsp),%r14
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <locate@plt>
test   %rax,%rax
jne    1203 <main+0xb3>
add    $0x1,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jl     11e0 <main+0x90>
jmp    121b <main+0xcb>
lea    0xe15(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <getch@plt>
xor    %eax,%eax
add    $0x4e20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [31 x i8] c"What would you like to search?\00"
@.str.1 = [4 x i8] c"\0A%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i8]
%3 = alloca [10000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %6
store i32 0, i32* %4
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 10000
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = call i32 (...) @getchar()
store i32 %11, i32* %5
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %25
16: ; preds = %14
%17 = load i32, i32* %5
%18 = trunc i32 %17 to i8
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %16
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %7
25: ; preds = %14
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %27
27: ; preds = %42, %25
%28 = load i32, i32* %6
%29 = icmp sle i32 %28, 10000
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = call i32 (...) @getchar()
store i32 %31, i32* %5
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br label %34
34: ; preds = %30, %27
%35 = phi i1 [ false, %27 ], [ %33, %30 ]
br i1 %35, label %36, label %45
36: ; preds = %34
%37 = load i32, i32* %5
%38 = trunc i32 %37 to i8
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 %40
store i8 %38, i8* %41
br label %42
42: ; preds = %36
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %27
45: ; preds = %34
store i32 0, i32* %6
br label %46
46: ; preds = %62, %45
%47 = load i32, i32* %6
%48 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = icmp slt i32 %47, %49
br i1 %50, label %51, label %65
51: ; preds = %46
%52 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%53 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%54 = load i32, i32* %6
%55 = call i64 @locate(i8* %52, i8* %53, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %51
%58 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %58)
%60 = call i32 (...) @getch()
br label %65
61: ; preds = %51
br label %62
62: ; preds = %61
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %46
65: ; preds = %57, %46
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [31 x i8] c"What would you like to search?\00"
@.str.1 = [4 x i8] c"\0A%s\00"
define i32 @main() {
%1 = alloca [10000 x i8]
%2 = alloca [10000 x i8]
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %0, %10
%6 = phi i64 [ 0, %0 ], [ %13, %10 ]
%7 = tail call i32 (...) @getchar()
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = trunc i32 %7 to i8
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %6
store i8 %11, i8* %12
%13 = add nuw nsw i64 %6, 1
%14 = icmp eq i64 %13, 10001
br i1 %14, label %15, label %5
15: ; preds = %10, %5
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %22
%18 = phi i64 [ 0, %15 ], [ %25, %22 ]
%19 = tail call i32 (...) @getchar()
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = trunc i32 %19 to i8
%24 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %18
store i8 %23, i8* %24
%25 = add nuw nsw i64 %18, 1
%26 = icmp eq i64 %25, 10001
br i1 %26, label %27, label %17
27: ; preds = %22, %17
%28 = call i32 @strlen(i8* %3)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %33, label %41
30: ; preds = %33
%31 = call i32 @strlen(i8* %3)
%32 = icmp slt i32 %37, %31
br i1 %32, label %33, label %41
33: ; preds = %27, %30
%34 = phi i32 [ %37, %30 ], [ 0, %27 ]
%35 = call i64 @locate(i8* %3, i8* %4, i32 %34)
%36 = icmp eq i64 %35, 0
%37 = add nuw nsw i32 %34, 1
br i1 %36, label %30, label %38
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%40 = call i32 (...) @getch()
br label %41
41: ; preds = %30, %27, %38
ret i32 0
}