#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char *);
int numberOfLines(const int LINESIZE, const char *FNANAME) {
  FILE *fnaPointer;
  char singleCharLine[256];
  fnaPointer = fopen(FNANAME, "r");
  if (fnaPointer == NULL) {
    printf("%s", "Error(numberOfLinesLib): fnaPointer is null\n");
    exit(EXIT_FAILURE);
  }
  int numberOfLines = 0;
  while (fgets(singleCharLine, 256, fnaPointer) != NULL) {
    numberOfLines++;
  }
  if (numberOfLines == 0) {
    printf("%s", "Error(numberOfLinesLib): No Lines in .fna file\n");
    exit(EXIT_FAILURE);
  }
  fclose(fnaPointer);
  return numberOfLines;
}


x86 assembly (clang, -O0):
<numberOfLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <numberOfLines+0x52>
lea    0xe7a(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1040 <printf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11df <numberOfLines+0x8f>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11ac <numberOfLines+0x5c>
cmpl   $0x0,-0x124(%rbp)
jne    120d <numberOfLines+0xbd>
lea    0xe0f(%rip),%rdi
lea    0xe38(%rip),%rsi
call   1040 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x124(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numberOfLines>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b2 <numberOfLines+0x62>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1180 <numberOfLines+0x30>
test   %ebp,%ebp
je     11c2 <numberOfLines+0x72>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe49(%rip),%rdi
lea    0xe45(%rip),%rsi
jmp    11d0 <numberOfLines+0x80>
lea    0xe39(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1040 <printf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [45 x i8] c"Error(numberOfLinesLib): fnaPointer is null\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [48 x i8] c"Error(numberOfLinesLib): No Lines in .fna file\0A\00"
define i32 @numberOfLines(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
store i32 0, i32* %7
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32* @fgets(i8* %18, i32 256, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %17
25: ; preds = %17
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %25
%33 = load i32*, i32** %5
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %7
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [45 x i8] c"Error(numberOfLinesLib): fnaPointer is null\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [48 x i8] c"Error(numberOfLinesLib): No Lines in .fna file\0A\00"
define i32 @numberOfLines(i32 %0, i8* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2, %11
%12 = phi i32 [ %15, %11 ], [ 0, %2 ]
%13 = call i32* @fgets(i8* %4, i32 256, i32* %5)
%14 = icmp eq i32* %13, null
%15 = add nuw nsw i32 %12, 1
br i1 %14, label %16, label %11
16: ; preds = %11
%17 = icmp eq i32 %12, 0
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %16
%23 = call i32 @fclose(i32* %5)
ret i32 %12
}