#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int CountLines(char *fileName) {
  char tempBuffer[70];
  int lines = 0;
  FILE *fp = fopen(fileName, "r");
  if (fp == NULL)
    return -1;
  while (!feof(fp)) {
    if (fgets(tempBuffer, 70, fp) != NULL)
      lines++;
  }
  fclose(fp);
  fp = NULL;
  return lines;
}


x86 assembly (clang, -O0):
<CountLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    117e <CountLines+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <CountLines+0xa2>
jmp    1183 <CountLines+0x43>
mov    -0x70(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a1 <CountLines+0x61>
jmp    11cb <CountLines+0x8b>
lea    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%rdx
mov    $0x46,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11c6 <CountLines+0x86>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1183 <CountLines+0x43>
mov    -0x70(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x70(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountLines>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <CountLines+0x5d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    1193 <CountLines+0x53>
xor    %ebp,%ebp
mov    %rsp,%r14
nop
mov    %r14,%rdi
mov    $0x46,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1170 <CountLines+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11a2 <CountLines+0x62>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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