#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int nRows() {
  char c;
  int rowNum = 0;
  FILE *f;
  f = fopen("car.txt", "r");
  c = fgetc(f);
  while (!feof(f)) {
    if (c == '\n') {
      ++rowNum;
      c = fgetc(f);
    } else {
      c = fgetc(f);
      if (feof(f))
        ++rowNum;
    }
  }
  fclose(f);
  return rowNum;
}


x86 assembly (clang, -O0):
<nRows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1191 <nRows+0x51>
jmp    11ea <nRows+0xaa>
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    11b8 <nRows+0x78>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%rbp)
jmp    11e5 <nRows+0xa5>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11e0 <nRows+0xa0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e5 <nRows+0xa5>
jmp    1172 <nRows+0x32>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nRows>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1183 <nRows+0x43>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11b7 <nRows+0x77>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <feof@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    1174 <nRows+0x34>
cmp    $0xa,%r14b
jne    1190 <nRows+0x50>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%r14d
jmp    11aa <nRows+0x6a>

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

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