#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;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int get_line_number(FILE *f_source) {
  int line;
  long fp_start;
  fp_start = ftell(f_source);
  fseek(f_source, 0, SEEK_SET);
  line = 0;
  while (ftell(f_source) < fp_start) {
    if (fgetc(f_source) == '\n')
      line++;
  }
  return line;
}


x86 assembly (clang, -O0):
<get_line_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
cmp    -0x18(%rbp),%rax
jge    119a <get_line_number+0x6a>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
jne    1195 <get_line_number+0x65>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1164 <get_line_number+0x34>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line_number>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <ftell@plt>
mov    %rax,%r14
mov    0x2e9a(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %rbx,%rdi
call   1040 <ftell@plt>
cmp    %r14,%rax
jge    118e <get_line_number+0x5e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <ftell@plt>
cmp    %r14,%rax
jl     1170 <get_line_number+0x40>
mov    %ebp,%eax
pop    %rbx
pop    %r14
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 i64
store i32* %0, i32** %2
%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, i32 0, i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %23, %1
%11 = load i32*, i32** %2
%12 = call i64 @ftell(i32* %11)
%13 = load i64, i64* %4
%14 = icmp slt i64 %12, %13
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* %3
ret i32 %25
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @get_line_number(i32* nocapture %0) {
%2 = tail call i64 @ftell(i32* %0)
%3 = load i32, i32* @SEEK_SET
%4 = tail call i32 @fseek(i32* %0, i32 0, i32 %3)
%5 = tail call i64 @ftell(i32* %0)
%6 = icmp slt i64 %5, %2
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 i64 @ftell(i32* %0)
%14 = icmp slt i64 %13, %2
br i1 %14, label %7, label %15
15: ; preds = %7, %1
%16 = phi i32 [ 0, %1 ], [ %12, %7 ]
ret i32 %16
}