#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*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int get_line_number(FILE *file) {
  int count = 0;
  char c;
  int pos = ftell(file);
  fseek(file, 0, SEEK_SET);
  while (ftell(file) < pos - 1) {
    fread(&c, sizeof(char), 1, file);
    if (c == 10)
      count++;
  }
  fseek(file, pos, SEEK_SET);
  return count + 1;
}


x86 assembly (clang, -O0):
<get_line_number>:
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    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e86(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a9 <get_line_number+0x79>
mov    -0x8(%rbp),%rcx
lea    -0xd(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    11a4 <get_line_number+0x74>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <get_line_number+0x33>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line_number>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <ftell@plt>
mov    %eax,%r14d
mov    0x2e93(%rip),%r15
mov    (%r15),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %rbx,%rdi
call   1040 <ftell@plt>
mov    %r14d,%r13d
add    $0xffffffff,%r13d
mov    $0x1,%r12d
cmp    %r13d,%eax
jge    11b4 <get_line_number+0x84>
lea    0x7(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %eax,%eax
cmpb   $0xa,0x7(%rsp)
sete   %al
add    %eax,%ebp
mov    %rbx,%rdi
call   1040 <ftell@plt>
cmp    %r13d,%eax
jl     1180 <get_line_number+0x50>
add    $0x1,%ebp
mov    %ebp,%r12d
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <fseek@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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