#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*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int countLines(FILE *file) {
  char x;
  int n = 0;
  x = fgetc(file);
  while (!feof(file)) {
    if (x == '\n')
      n++;
    x = fgetc(file);
  }
  rewind(file);
  return n;
}


x86 assembly (clang, -O0):
<countLines>:
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,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    116d <countLines+0x3d>
jmp    1194 <countLines+0x64>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1183 <countLines+0x53>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
jmp    114f <countLines+0x1f>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLines>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    1170 <countLines+0x40>
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
cmp    $0xa,%bl
sete   %al
add    %eax,%ebp
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1150 <countLines+0x20>
mov    %r14,%rdi
call   1030 <rewind@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @countLines(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 = %19, %1
%8 = load i32*, i32** %2
%9 = call i32 @feof(i32* %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %22
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 %19
16: ; preds = %12
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %19
19: ; preds = %16, %12
%20 = load i32*, i32** %2
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %3
br label %7
22: ; preds = %7
%23 = load i32*, i32** %2
%24 = call i32 @rewind(i32* %23)
%25 = load i32, i32* %4
ret i32 %25
}

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