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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *openFileForReading(char const *);
unsigned getLineCountOfFile(const char *file) {
  FILE *filePtr = openFileForReading(file);
  unsigned lineCount = 0;
  char lineBuffer[BUFSIZ];
  while (fgets(lineBuffer, sizeof(lineBuffer), filePtr)) {
    ++lineCount;
  }
  fclose(filePtr);
  return lineCount;
}


x86 assembly (clang, -O0):
<getLineCountOfFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <openFileForReading@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11ab <getLineCountOfFile+0x7b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <getLineCountOfFile+0x50>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLineCountOfFile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
call   1050 <openFileForReading@plt>
mov    %rax,%r14
mov    0x2e96(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r12
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1170 <getLineCountOfFile+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define i32 @getLineCountOfFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @openFileForReading(i8* %7)
store i32* %8, i32** %3
store i32 0, i32* %4
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
br label %13
13: ; preds = %18, %1
%14 = trunc i64 %10 to i32
%15 = load i32*, i32** %3
%16 = call i64 @fgets(i8* %12, i32 %14, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* %4
%20 = add i32 %19, 1
store i32 %20, i32* %4
br label %13
21: ; preds = %13
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %4
%25 = load i8*, i8** %5
ret i32 %24
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define i32 @getLineCountOfFile(i8* %0) {
%2 = tail call i32* @openFileForReading(i8* %0)
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
br label %6
6: ; preds = %6, %1
%7 = phi i32 [ 0, %1 ], [ %10, %6 ]
%8 = call i64 @fgets(i8* %5, i32 %3, i32* %2)
%9 = icmp eq i64 %8, 0
%10 = add i32 %7, 1
br i1 %9, label %11, label %6
11: ; preds = %6
%12 = call i32 @fclose(i32* %2)
ret i32 %7
}