#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 */
struct lineFile {
  int dummy;
};

/* Variables and functions */
scalar_t__ chopByWhite(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ lineFileClose(struct lineFile **);
scalar_t__ lineFileNext(struct lineFile *, char **, int /*<<< orphan*/ *);
struct lineFile *lineFileOpen(char *, int);
int countWordsInFile(char *fileName) {
  struct lineFile *lf = lineFileOpen(fileName, 1);
  char *line;
  int wordCount = 0;
  while (lineFileNext(lf, &line, NULL))
    wordCount += chopByWhite(line, NULL, 0);
  lineFileClose(&lf);
  return wordCount;
}


x86 assembly (clang, -O0):
<countWordsInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1060 <lineFileOpen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <lineFileNext@plt>
cmp    $0x0,%rax
je     11a1 <countWordsInFile+0x61>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <chopByWhite@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
jmp    1165 <countWordsInFile+0x25>
lea    -0x10(%rbp),%rdi
call   1030 <lineFileClose@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countWordsInFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%esi
call   1060 <lineFileOpen@plt>
mov    %rax,%r14
mov    %rax,0x8(%rsp)
xor    %ebx,%ebx
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <lineFileNext@plt>
test   %rax,%rax
je     11a1 <countWordsInFile+0x61>
xor    %ebx,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <chopByWhite@plt>
add    %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <lineFileNext@plt>
test   %rax,%rax
jne    1180 <countWordsInFile+0x40>
lea    0x8(%rsp),%rdi
call   1030 <lineFileClose@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.lineFile = type { i32 }
define i32 @countWordsInFile(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.lineFile*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call %struct.lineFile* @lineFileOpen(i8* %6, i32 1)
store %struct.lineFile* %7, %struct.lineFile** %3
store i32 0, i32* %5
br label %8
8: ; preds = %12, %1
%9 = load %struct.lineFile*, %struct.lineFile** %3
%10 = call i64 @lineFileNext(%struct.lineFile* %9, i8** %4, i32* null)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = call i64 @chopByWhite(i8* %13, i32* null, i32 0)
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = add nsw i64 %16, %14
%18 = trunc i64 %17 to i32
store i32 %18, i32* %5
br label %8
19: ; preds = %8
%20 = call i32 @lineFileClose(%struct.lineFile** %3)
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
%struct.lineFile = type { i32 }
define i32 @countWordsInFile(i8* %0) {
%2 = alloca %struct.lineFile*
%3 = alloca i8*
%4 = bitcast %struct.lineFile** %2 to i8*
%5 = tail call %struct.lineFile* @lineFileOpen(i8* %0, i32 1)
store %struct.lineFile* %5, %struct.lineFile** %2
%6 = bitcast i8** %3 to i8*
%7 = call i64 @lineFileNext(%struct.lineFile* %5, i8** %3, i32* null)
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %1, %9
%10 = phi i32 [ %14, %9 ], [ 0, %1 ]
%11 = load i8*, i8** %3
%12 = call i64 @chopByWhite(i8* %11, i32* null, i32 0)
%13 = trunc i64 %12 to i32
%14 = add i32 %10, %13
%15 = call i64 @lineFileNext(%struct.lineFile* %5, i8** %3, i32* null)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %9
17: ; preds = %9, %1
%18 = phi i32 [ 0, %1 ], [ %14, %9 ]
%19 = call i32 @lineFileClose(%struct.lineFile** %2)
ret i32 %18
}