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


x86 assembly (clang, -O0):
<nRows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    116e <nRows+0x3e>
jmp    11c7 <nRows+0x97>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1195 <nRows+0x65>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
jmp    11c2 <nRows+0x92>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11bd <nRows+0x8d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c2 <nRows+0x92>
jmp    114f <nRows+0x1f>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nRows>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <fgetc@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     115d <nRows+0x2d>
mov    %rbx,%rdi
call   1030 <rewind@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
jmp    1197 <nRows+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   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    114e <nRows+0x1e>
cmp    $0xa,%r14b
jne    1170 <nRows+0x40>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%r14d
jmp    118a <nRows+0x5a>

LLVM IR (-O0):
define i32 @nRows(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
%5 = load i32*, i32** %2
%6 = call signext i8 @fgetc(i32* %5)
store i8 %6, i8* %3
br label %7
7: ; preds = %31, %1
%8 = load i32*, i32** %2
%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* %3
%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* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = load i32*, i32** %2
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %3
br label %31
21: ; preds = %12
%22 = load i32*, i32** %2
%23 = call signext i8 @fgetc(i32* %22)
store i8 %23, i8* %3
%24 = load i32*, i32** %2
%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* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %21
br label %31
31: ; preds = %30, %16
br label %7
32: ; preds = %7
%33 = load i32*, i32** %2
%34 = call i32 @rewind(i32* %33)
%35 = load i32, i32* %4
ret i32 %35
}

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