#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gets(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  char c;
  int occurrences = 0;
  FILE *file;
  if ((file = fopen("dat.txt", "r")) == NULL) {
    printf("The file `dat.txt` can not be opened!\n");
    exit(-1);
  }
  char word[50];
  printf("Enter word for searching:");
  gets(word);
  int i = 0, counter = 0;
  while ((c = fgetc(file)) != EOF) {
    if (isdigit(c)) {
      if (c != word[i++]) {
        if (counter == strlen(word)) {
          occurrences++;
        }
        counter = 0;
        i = 0;
      } else {
        counter++;
      }
    } else {
      if (counter == strlen(word)) {
        occurrences++;
      }
      counter = 0;
      i = 0;
    }
  }
  printf("The word `%s` occurs %d times in the file\n", word, occurrences);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bf <main+0x4f>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x50(%rbp),%rdi
call   1070 <gets@plt>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2dee(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12b5 <main+0x145>
movsbl -0x5(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     127d <main+0x10d>
movsbl -0x5(%rbp),%eax
mov    -0x54(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x54(%rbp)
movslq %ecx,%rcx
movsbl -0x50(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
je     126f <main+0xff>
mov    -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jne    125c <main+0xec>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
jmp    1278 <main+0x108>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12b0 <main+0x140>
mov    -0x58(%rbp),%eax
mov    %eax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
cmp    %ecx,%eax
jne    12a2 <main+0x132>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
jmp    11e4 <main+0x74>
lea    -0x50(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1255 <main+0xd5>
mov    %rax,%r15
lea    0xe56(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rdi
call   1080 <gets@plt>
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    0x2e13(%rip),%r12
cmp    (%r12),%al
jne    1200 <main+0x80>
lea    0xe42(%rip),%rdi
mov    %rsp,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
xor    %ebp,%ebp
xor    %r14d,%r14d
xor    %r13d,%r13d
jmp    1237 <main+0xb7>
nopl   0x0(%rax)
mov    %rsp,%rdi
call   1050 <strlen@plt>
xor    %ecx,%ecx
cmp    %eax,%ebp
sete   %cl
add    %ecx,%r13d
xor    %r14d,%r14d
xor    %ebp,%ebp
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebx
cmp    (%r12),%al
je     11db <main+0x5b>
movsbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1210 <main+0x90>
movslq %r14d,%rax
cmp    (%rsp,%rax,1),%bl
jne    1210 <main+0x90>
add    $0x1,%r14d
add    $0x1,%ebp
jmp    1227 <main+0xa7>
lea    0xdf3(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"dat.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [39 x i8] c"The file `dat.txt` can not be opened!\0A\00"
@.str.3 = [26 x i8] c"Enter word for searching:\00"
@EOF = global i8 0
@.str.4 = [43 x i8] c"The word `%s` occurs %d times in the file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [50 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%16 = call i32 @gets(i8* %15)
store i32 0, i32* %6
store i32 0, i32* %7
br label %17
17: ; preds = %60, %13
%18 = load i32*, i32** %4
%19 = call signext i8 @fgetc(i32* %18)
store i8 %19, i8* %2
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %61
24: ; preds = %17
%25 = load i8, i8* %2
%26 = call i64 @isdigit(i8 signext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %51
28: ; preds = %24
%29 = load i8, i8* %2
%30 = sext i8 %29 to i32
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %30, %36
br i1 %37, label %38, label %47
38: ; preds = %28
%39 = load i32, i32* %7
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = icmp eq i32 %39, %41
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %46
46: ; preds = %43, %38
store i32 0, i32* %7
store i32 0, i32* %6
br label %50
47: ; preds = %28
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %50
50: ; preds = %47, %46
br label %60
51: ; preds = %24
%52 = load i32, i32* %7
%53 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
%55 = icmp eq i32 %52, %54
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %59
59: ; preds = %56, %51
store i32 0, i32* %7
store i32 0, i32* %6
br label %60
60: ; preds = %59, %50
br label %17
61: ; preds = %17
%62 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%63 = load i32, i32* %3
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %62, i32 %63)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"dat.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"Enter word for searching:\00"
@EOF = global i8 0
@.str.4 = [43 x i8] c"The word `%s` occurs %d times in the file\0A\00"
@str = [38 x i8] c"The file `dat.txt` can not be opened!\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @gets(i8* %8)
%11 = call signext i8 @fgetc(i32* %2)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %46, label %14
14: ; preds = %7, %39
%15 = phi i8 [ %43, %39 ], [ %11, %7 ]
%16 = phi i32 [ %42, %39 ], [ 0, %7 ]
%17 = phi i32 [ %41, %39 ], [ 0, %7 ]
%18 = phi i32 [ %40, %39 ], [ 0, %7 ]
%19 = call i64 @isdigit(i8 signext %15)
%20 = icmp eq i64 %19, 0
br i1 %20, label %34, label %21
21: ; preds = %14
%22 = sext i32 %17 to i64
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %15, %24
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = call i32 @strlen(i8* %8)
%28 = icmp eq i32 %16, %27
%29 = zext i1 %28 to i32
%30 = add nsw i32 %18, %29
br label %39
31: ; preds = %21
%32 = add nsw i32 %17, 1
%33 = add nsw i32 %16, 1
br label %39
34: ; preds = %14
%35 = call i32 @strlen(i8* %8)
%36 = icmp eq i32 %16, %35
%37 = zext i1 %36 to i32
%38 = add nsw i32 %18, %37
br label %39
39: ; preds = %26, %31, %34
%40 = phi i32 [ %30, %26 ], [ %18, %31 ], [ %38, %34 ]
%41 = phi i32 [ 0, %26 ], [ %32, %31 ], [ 0, %34 ]
%42 = phi i32 [ 0, %26 ], [ %33, %31 ], [ 0, %34 ]
%43 = call signext i8 @fgetc(i32* %2)
%44 = load i8, i8* @EOF
%45 = icmp eq i8 %43, %44
br i1 %45, label %46, label %14
46: ; preds = %39, %7
%47 = phi i32 [ 0, %7 ], [ %40, %39 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %8, i32 %47)
ret i32 0
}