#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*/ SEEK_SET;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int getLineCount(FILE *fp) {
  int count = 0;
  long pos = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  while (!feof(fp)) {
    if (fgetc(fp) == '\n')
      count++;
  }
  fseek(fp, pos, SEEK_SET);
  return count;
}


x86 assembly (clang, -O0):
<getLineCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1194 <getLineCount+0x54>
jmp    11b7 <getLineCount+0x77>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
jne    11b2 <getLineCount+0x72>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <getLineCount+0x36>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLineCount>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <ftell@plt>
mov    %rax,%r14
mov    0x2e86(%rip),%r12
mov    (%r12),%edx
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %r15,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    119d <getLineCount+0x5d>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebx
mov    %r15,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1180 <getLineCount+0x40>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <fseek@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @getLineCount(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
store i32* %0, i32** %2
store i32 0, i32* %3
%5 = load i32*, i32** %2
%6 = call i64 @ftell(i32* %5)
store i64 %6, i64* %4
%7 = load i32*, i32** %2
%8 = load i32, i32* @SEEK_SET
%9 = call i32 @fseek(i32* %7, i64 0, i32 %8)
br label %10
10: ; preds = %23, %1
%11 = load i32*, i32** %2
%12 = call i32 @feof(i32* %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i32*, i32** %2
%17 = call signext i8 @fgetc(i32* %16)
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %23
23: ; preds = %20, %15
br label %10
24: ; preds = %10
%25 = load i32*, i32** %2
%26 = load i64, i64* %4
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %25, i64 %26, i32 %27)
%29 = load i32, i32* %3
ret i32 %29
}

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