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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
void getFileLines(char **path, int *nLines) {
  FILE *fp = fopen(*path, "r");
  if (fp == NULL) {
    return;
  }
  *nLines = 0;
  char buf[256];
  while (fgets(buf, sizeof(buf), fp)) {
    *nLines = *nLines + 1;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<getFileLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116a <getFileLines+0x3a>
jmp    11b0 <getFileLines+0x80>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11a7 <getFileLines+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1174 <getFileLines+0x44>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileLines>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    (%rdi),%rdi
lea    0xeb7(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a1 <getFileLines+0x71>
mov    %rax,%rbx
movl   $0x0,(%r14)
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1199 <getFileLines+0x69>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
addl   $0x1,(%r14)
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1180 <getFileLines+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @getFileLines(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [256 x i8]
store i8** %0, i8*** %3
store i32* %1, i32** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
%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 %13
12: ; preds = %2
br label %28
13: ; preds = %2
%14 = load i32*, i32** %4
store i32 0, i32* %14
br label %15
15: ; preds = %20, %13
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %5
%18 = call i64 @fgets(i8* %16, i32 256, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
%24 = load i32*, i32** %4
store i32 %23, i32* %24
br label %15
25: ; preds = %15
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %12
ret void
}

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