#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int countLines() {
  int i = 0;
  char buffer[150];
  FILE *ifp;
  ifp = fopen("cykelloeb-2017.txt", "r");
  while (fgets(buffer, 150, ifp) != NULL) {
    i++;
  }
  fclose(ifp);
  return i;
}


x86 assembly (clang, -O0):
<countLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    $0x96,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     118c <countLines+0x5c>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115c <countLines+0x2c>
mov    -0xa8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLines>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
lea    0xebd(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    $0xffffffff,%ebx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x96,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1160 <countLines+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"cykelloeb-2017.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @countLines() {
%1 = alloca i32
%2 = alloca [150 x i8]
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
br label %5
5: ; preds = %10, %0
%6 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i32* @fgets(i8* %6, i32 150, i32* %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %1
br label %5
13: ; preds = %5
%14 = load i32*, i32** %3
%15 = call i32 @fclose(i32* %14)
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [19 x i8] c"cykelloeb-2017.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @countLines() {
%1 = alloca [150 x i8]
%2 = getelementptr inbounds [150 x i8], [150 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi i32 [ 0, %0 ], [ %8, %4 ]
%6 = call i32* @fgets(i8* %2, i32 150, i32* %3)
%7 = icmp eq i32* %6, null
%8 = add nuw nsw i32 %5, 1
br i1 %7, label %9, label %4
9: ; preds = %4
%10 = call i32 @fclose(i32* %3)
ret i32 %5
}