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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int getNumberOfLine(const char *fileName) {
  int i = 0;
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  fp = fopen(fileName, "r");
  if (fp == NULL)
    return -1;
  while ((read = getline(&line, &len, fp)) != -1) {
    i++;
  }
  free(line);
  fclose(fp);
  return i;
}


x86 assembly (clang, -O0):
<getNumberOfLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <getNumberOfLine+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <getNumberOfLine+0x96>
jmp    1193 <getNumberOfLine+0x53>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     11be <getNumberOfLine+0x7e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <getNumberOfLine+0x53>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumberOfLine>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe9c(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11aa <getNumberOfLine+0x6a>
mov    %rax,%r14
mov    $0xffffffff,%ebx
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <getline@plt>
add    $0x1,%ebx
cmp    $0xffffffff,%eax
jne    1180 <getNumberOfLine+0x40>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11af <getNumberOfLine+0x6f>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @getNumberOfLine(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %17, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %12, %8 ], [ 0, %1 ]
%10 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%11 = icmp eq i32 %10, -1
%12 = add nuw nsw i32 %9, 1
br i1 %11, label %13, label %8
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
%16 = call i32 @fclose(i32* %6)
br label %17
17: ; preds = %1, %13
%18 = phi i32 [ %9, %13 ], [ -1, %1 ]
ret i32 %18
}