#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 EOF;
int /*<<< orphan*/ SEEK_SET;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
long fgotol(FILE *stream, long idx_line) {
  int c;
  if (idx_line < 0)
    return -1;
  fseek(stream, 0, SEEK_SET);
  c = 0;
  while (idx_line > 0 && c != EOF) {
    c = fgetc(stream);
    if (c == '\n')
      idx_line--;
  }
  return ftell(stream);
}


x86 assembly (clang, -O0):
<fgotol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1158 <fgotol+0x28>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11d9 <fgotol+0xa9>
mov    -0x10(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jle    1195 <fgotol+0x65>
mov    -0x1c(%rbp),%eax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a5 <fgotol+0x75>
jmp    11cc <fgotol+0x9c>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    11c7 <fgotol+0x97>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1173 <fgotol+0x43>
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgotol>:
test   %rsi,%rsi
js     1197 <fgotol+0x67>
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
test   %rbx,%rbx
je     118a <fgotol+0x5a>
mov    0x2e8c(%rip),%r15
cmpl   $0x0,(%r15)
je     118a <fgotol+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
sub    %rcx,%rbx
je     118a <fgotol+0x5a>
cmp    (%r15),%eax
jne    1170 <fgotol+0x40>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <ftell@plt>
mov    $0xffffffffffffffff,%rax
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@EOF = global i32 0
define i64 @fgotol(i32* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i64 -1, i64* %3
br label %35
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @fseek(i32* %11, i32 0, i32 %12)
store i32 0, i32* %6
br label %14
14: ; preds = %31, %10
%15 = load i64, i64* %5
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %6
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br label %21
21: ; preds = %17, %14
%22 = phi i1 [ false, %14 ], [ %20, %17 ]
br i1 %22, label %23, label %32
23: ; preds = %21
%24 = load i32*, i32** %4
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i64, i64* %5
%30 = add nsw i64 %29, -1
store i64 %30, i64* %5
br label %31
31: ; preds = %28, %23
br label %14
32: ; preds = %21
%33 = load i32*, i32** %4
%34 = call i64 @ftell(i32* %33)
store i64 %34, i64* %3
br label %35
35: ; preds = %32, %9
%36 = load i64, i64* %3
ret i64 %36
}

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