#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 /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int fLineCounter(int lineCount) {
  FILE *sFile;
  int readCharacters;
  sFile = fopen("students.txt", "r");
  if (sFile == NULL) {
    printf("Cannot open 'students.txt' for reading\n");
    return lineCount;
  }
  readCharacters = getc(sFile);
  while (readCharacters != EOF) {
    if (readCharacters == '\n')
      lineCount++;
    readCharacters = getc(sFile);
  }
  fclose(sFile);
  return lineCount;
}


x86 assembly (clang, -O0):
<fLineCounter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <fLineCounter+0x44>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <fLineCounter+0x95>
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%eax
je     11c6 <fLineCounter+0x86>
cmpl   $0xa,-0x14(%rbp)
jne    11b5 <fLineCounter+0x75>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x14(%rbp)
jmp    1190 <fLineCounter+0x50>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fLineCounter>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xeb2(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a1 <fLineCounter+0x61>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <getc@plt>
mov    0x2e77(%rip),%r15
cmp    (%r15),%eax
je     1197 <fLineCounter+0x57>
cs nopw 0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebx
mov    %r14,%rdi
call   1060 <getc@plt>
cmp    (%r15),%eax
jne    1180 <fLineCounter+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11ad <fLineCounter+0x6d>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"students.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"Cannot open 'students.txt' for reading\0A\00"
@EOF = global i32 0
define i32 @fLineCounter(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %3
store i32 %11, i32* %2
br label %32
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = call i32 @getc(i32* %13)
store i32 %14, i32* %5
br label %15
15: ; preds = %25, %12
%16 = load i32, i32* %5
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %19
%26 = load i32*, i32** %4
%27 = call i32 @getc(i32* %26)
store i32 %27, i32* %5
br label %15
28: ; preds = %15
%29 = load i32*, i32** %4
%30 = call i32 @fclose(i32* %29)
%31 = load i32, i32* %3
store i32 %31, i32* %2
br label %32
32: ; preds = %28, %9
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [13 x i8] c"students.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [39 x i8] c"Cannot open 'students.txt' for reading\00"
define i32 @fLineCounter(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %1
%7 = tail call i32 @getc(i32* %2)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %6, %10
%11 = phi i32 [ %16, %10 ], [ %7, %6 ]
%12 = phi i32 [ %15, %10 ], [ %0, %6 ]
%13 = icmp eq i32 %11, 10
%14 = zext i1 %13 to i32
%15 = add nsw i32 %12, %14
%16 = tail call i32 @getc(i32* %2)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %10
19: ; preds = %10, %6
%20 = phi i32 [ %0, %6 ], [ %15, %10 ]
%21 = tail call i32 @fclose(i32* %2)
br label %22
22: ; preds = %19, %4
%23 = phi i32 [ %0, %4 ], [ %20, %19 ]
ret i32 %23
}