#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ removeLF(char *);
int /*<<< orphan*/ stdin;
char *strstr(char *, char *);
int main(int argc, char *argv[]) {
  char word[500];
  printf("Enter the word to search for: ");
  if (fgets(word, 500 - 1, stdin) == NULL) {
    puts("Could not read word.");
    return 1;
  }
  removeLF(word);
  char text[500];
  printf("Enter the text to search: ");
  if (fgets(text, 500 - 1, stdin) == NULL) {
    puts("Could not read text.");
    return 1;
  }
  removeLF(text);
  if (strstr(text, word) == NULL) {
    printf("The word \"%s\" was not found in the text.\n", word, text);
    return 1;
  }
  printf("First index of \"%s\" in text: %ld\n", word,
         (long)(strstr(text, word) - text));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x210(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    $0x1f3,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11b3 <main+0x63>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x154>
lea    -0x210(%rbp),%rdi
call   1030 <removeLF@plt>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    $0x1f3,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1209 <main+0xb9>
lea    0xe57(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x154>
lea    -0x410(%rbp),%rdi
call   1030 <removeLF@plt>
lea    -0x410(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
jne    125a <main+0x10a>
lea    -0x210(%rbp),%rsi
lea    -0x410(%rbp),%rdx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x154>
lea    -0x210(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1070 <strstr@plt>
mov    -0x418(%rbp),%rsi
mov    %rax,%rdx
lea    -0x410(%rbp),%rax
sub    %rax,%rdx
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e7b(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%rdi
mov    $0x1f3,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11eb <main+0x9b>
mov    %rsp,%rdi
call   1030 <removeLF@plt>
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%edx
lea    0x200(%rsp),%rdi
mov    $0x1f3,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11f4 <main+0xa4>
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <removeLF@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     1202 <main+0xb2>
sub    %rbx,%rax
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1220 <main+0xd0>
lea    0xe2d(%rip),%rdi
jmp    11fb <main+0xab>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
jmp    121b <main+0xcb>
lea    0xe5b(%rip),%rdi
mov    %rsp,%rsi
lea    0x200(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Enter the word to search for: \00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"Could not read word.\00"
@.str.2 = [27 x i8] c"Enter the text to search: \00"
@.str.3 = [21 x i8] c"Could not read text.\00"
@.str.4 = [42 x i8] c"The word \22%s\22 was not found in the text.\0A\00"
@.str.5 = [34 x i8] c"First index of \22%s\22 in text: %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [500 x i8]
%7 = alloca [500 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %9, i32 499, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %46
15: ; preds = %2
%16 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%17 = call i32 @removeLF(i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i32* @fgets(i8* %19, i32 499, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %46
25: ; preds = %15
%26 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%27 = call i32 @removeLF(i8* %26)
%28 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%30 = call i8* @strstr(i8* %28, i8* %29)
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %34)
store i32 1, i32* %3
br label %46
36: ; preds = %25
%37 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%38 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%39 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%40 = call i8* @strstr(i8* %38, i8* %39)
%41 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %37, i64 %44)
store i32 0, i32* %3
br label %46
46: ; preds = %36, %32, %23, %13
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [31 x i8] c"Enter the word to search for: \00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"Could not read word.\00"
@.str.2 = [27 x i8] c"Enter the text to search: \00"
@.str.3 = [21 x i8] c"Could not read text.\00"
@.str.4 = [42 x i8] c"The word \22%s\22 was not found in the text.\0A\00"
@.str.5 = [34 x i8] c"First index of \22%s\22 in text: %ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [500 x i8]
%4 = alloca [500 x i8]
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %5, i32 499, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %34
12: ; preds = %2
%13 = call i32 @removeLF(i8* %5)
%14 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @stdin
%17 = call i32* @fgets(i8* %14, i32 499, i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %32
21: ; preds = %12
%22 = call i32 @removeLF(i8* %14)
%23 = call i8* @strstr(i8* %14, i8* %5)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %14)
br label %32
27: ; preds = %21
%28 = ptrtoint i8* %23 to i64
%29 = ptrtoint [500 x i8]* %4 to i64
%30 = sub i64 %28, %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %5, i64 %30)
br label %32
32: ; preds = %27, %25, %19
%33 = phi i32 [ 1, %19 ], [ 1, %25 ], [ 0, %27 ]
br label %34
34: ; preds = %32, %10
%35 = phi i32 [ 1, %10 ], [ %33, %32 ]
ret i32 %35
}