#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 */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t getNumberOfLinesInFile(char *fileName) {
  FILE *file = fopen(fileName, "r");
  size_t lines = 0;
  int ch = 0;
  do {
    ch = fgetc(file);
    if (ch == '\n') {
      lines++;
    }
  } while (ch != EOF);
  fclose(file);
  return lines;
}


x86 assembly (clang, -O0):
<getNumberOfLinesInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    1181 <getNumberOfLinesInFile+0x51>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1186 <getNumberOfLinesInFile+0x56>
mov    -0x1c(%rbp),%eax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
jne    115f <getNumberOfLinesInFile+0x2f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumberOfLinesInFile>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
xor    %ebx,%ebx
mov    0x2e9b(%rip),%r15
nopl   (%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %rcx,%rbx
cmp    (%r15),%eax
jne    1150 <getNumberOfLinesInFile+0x20>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i64 @getNumberOfLinesInFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
store i64 0, i64* %4
store i32 0, i32* %5
br label %8
8: ; preds = %17, %1
%9 = load i32*, i32** %3
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i64, i64* %4
%15 = add i64 %14, 1
store i64 %15, i64* %4
br label %16
16: ; preds = %13, %8
br label %17
17: ; preds = %16
%18 = load i32, i32* %5
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %8, label %21
21: ; preds = %17
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
%24 = load i64, i64* %4
ret i64 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i64 @getNumberOfLinesInFile(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ 0, %1 ], [ %8, %3 ]
%5 = tail call i32 @fgetc(i32* %2)
%6 = icmp eq i32 %5, 10
%7 = zext i1 %6 to i64
%8 = add i64 %4, %7
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %5, %9
br i1 %10, label %11, label %3
11: ; preds = %3
%12 = tail call i32 @fclose(i32* %2)
ret i64 %8
}