#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*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int getNumberOfWordsInFile(char *fName) {
  printf("--> %s\n", fName);
  FILE *fpIn;
  fpIn = fopen(fName, "r");
  char tempChar;
  int charCount = 0;
  int wordCount = 0;
  while ((tempChar = fgetc(fpIn)) != EOF) {
    if (tempChar == '\n') {
      wordCount++;
      charCount = 0;
    } else {
      charCount++;
    }
  }
  fclose(fpIn);
  printf("number of words: [%d]\n", wordCount);
  return wordCount;
}


x86 assembly (clang, -O0):
<getNumberOfWordsInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e52(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d1 <getNumberOfWordsInFile+0x91>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    11c3 <getNumberOfWordsInFile+0x83>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    11cc <getNumberOfWordsInFile+0x8c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1180 <getNumberOfWordsInFile+0x40>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumberOfWordsInFile>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xeb1(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea6(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e6c(%rip),%r15
cmp    (%r15),%al
je     11a6 <getNumberOfWordsInFile+0x66>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebx
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    1190 <getNumberOfWordsInFile+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xe55(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"--> %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [23 x i8] c"number of words: [%d]\0A\00"
define i32 @getNumberOfWordsInFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
store i32 0, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %28, %1
%12 = load i32*, i32** %3
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %4
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i8, i8* %4
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
store i32 0, i32* %5
br label %28
25: ; preds = %18
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %28
28: ; preds = %25, %22
br label %11
29: ; preds = %11
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
@.str = [8 x i8] c"--> %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [23 x i8] c"number of words: [%d]\0A\00"
define i32 @getNumberOfWordsInFile(i8* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call signext i8 @fgetc(i32* %3)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %16, label %7
7: ; preds = %1, %7
%8 = phi i8 [ %13, %7 ], [ %4, %1 ]
%9 = phi i32 [ %12, %7 ], [ 0, %1 ]
%10 = icmp eq i8 %8, 10
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %9, %11
%13 = tail call signext i8 @fgetc(i32* %3)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %16, label %7
16: ; preds = %7, %1
%17 = phi i32 [ 0, %1 ], [ %12, %7 ]
%18 = tail call i32 @fclose(i32* %3)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %17)
ret i32 %17
}