#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 */
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long ftell(int /*<<< orphan*/ *);
int lang_eval_getLinePos(FILE *lang_in, char *filename) {
  long pos;
  FILE *nfile;
  long i;
  int nlcount;
  nlcount = 0;
  pos = ftell(lang_in);
  nfile = fopen(filename, "r");
  for (i = 0; i <= pos; ++i) {
    char c;
    c = fgetc(nfile);
    if (c == '\n') {
      ++nlcount;
    }
  }
  return nlcount;
}


x86 assembly (clang, -O0):
<lang_eval_getLinePos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     11b6 <lang_eval_getLinePos+0x86>
mov    -0x20(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x2d(%rbp)
movsbl -0x2d(%rbp),%eax
cmp    $0xa,%eax
jne    11a0 <lang_eval_getLinePos+0x70>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a5 <lang_eval_getLinePos+0x75>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1170 <lang_eval_getLinePos+0x40>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lang_eval_getLinePos>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
call   1040 <ftell@plt>
mov    %rax,%rbx
lea    0xeba(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fopen@plt>
test   %rbx,%rbx
js     1179 <lang_eval_getLinePos+0x49>
mov    %rax,%r14
add    $0x1,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
add    $0xffffffffffffffff,%rbx
jne    1160 <lang_eval_getLinePos+0x30>
jmp    117b <lang_eval_getLinePos+0x4b>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @lang_eval_getLinePos(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %8
%10 = load i32*, i32** %3
%11 = call i64 @ftell(i32* %10)
store i64 %11, i64* %5
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
store i64 0, i64* %7
br label %14
14: ; preds = %28, %2
%15 = load i64, i64* %7
%16 = load i64, i64* %5
%17 = icmp sle i64 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32*, i32** %6
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %9
%21 = load i8, i8* %9
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %27
27: ; preds = %24, %18
br label %28
28: ; preds = %27
%29 = load i64, i64* %7
%30 = add nsw i64 %29, 1
store i64 %30, i64* %7
br label %14
31: ; preds = %14
%32 = load i32, i32* %8
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @lang_eval_getLinePos(i32* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @ftell(i32* %0)
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp slt i64 %3, 0
br i1 %5, label %15, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %13, %6 ], [ 0, %2 ]
%8 = phi i32 [ %12, %6 ], [ 0, %2 ]
%9 = tail call signext i8 @fgetc(i32* %4)
%10 = icmp eq i8 %9, 10
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %8, %11
%13 = add nuw i64 %7, 1
%14 = icmp eq i64 %7, %3
br i1 %14, label %15, label %6
15: ; preds = %6, %2
%16 = phi i32 [ 0, %2 ], [ %12, %6 ]
ret i32 %16
}