#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 /*<<< orphan*/ fatal_error(char *, char *, int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int get_line_num(FILE *fp) {
  int line_num;
  long pos;
  long end_pos;
  if ((1) <= 1 && !(fp != NULL))
    fatal_error("%s:%u: Assertion '"
                "fp != NULL"
                "' failed.",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/cutechess/sloppy/refs/heads/"
                "master/src/pgn.c",
                129);
  ;
  end_pos = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  pos = ftell(fp);
  line_num = 1;
  while (pos < end_pos) {
    int c = fgetc(fp);
    if (c == EOF || c == '\0')
      break;
    if (c == '\n')
      line_num++;
    pos++;
  }
  return line_num;
}


x86 assembly (clang, -O0):
<get_line_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116f <get_line_num+0x2f>
lea    0xea2(%rip),%rdi
lea    0xec1(%rip),%rsi
mov    $0x81,%edx
call   1050 <fatal_error@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1203 <get_line_num+0xc3>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%eax
je     11da <get_line_num+0x9a>
cmpl   $0x0,-0x24(%rbp)
jne    11df <get_line_num+0x9f>
jmp    1203 <get_line_num+0xc3>
cmpl   $0xa,-0x24(%rbp)
jne    11f2 <get_line_num+0xb2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a4 <get_line_num+0x64>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line_num>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
jne    1168 <get_line_num+0x28>
lea    0xea9(%rip),%rdi
lea    0xec8(%rip),%rsi
mov    $0x81,%edx
call   1050 <fatal_error@plt>
mov    %r14,%rdi
call   1040 <ftell@plt>
mov    %rax,%r15
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %r14,%rdi
call   1040 <ftell@plt>
mov    %rax,%rbx
add    $0xffffffffffffffff,%rbx
mov    $0x1,%ecx
mov    0x2e47(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%ebp
add    $0x1,%rbx
cmp    %r15,%rbx
jge    11d9 <get_line_num+0x99>
mov    %r14,%rdi
call   1030 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %dl
test   %eax,%eax
je     11d9 <get_line_num+0x99>
mov    %dl,%cl
add    %ebp,%ecx
cmp    (%r12),%eax
jne    11b0 <get_line_num+0x70>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"%s:%u: Assertion 'fp != NULL' failed.\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cutechess/sloppy/refs/heads/master/src/pgn.c\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @get_line_num(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @fatal_error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %11
11: ; preds = %9, %1
%12 = load i32*, i32** %2
%13 = call i64 @ftell(i32* %12)
store i64 %13, i64* %5
%14 = load i32*, i32** %2
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %2
%18 = call i64 @ftell(i32* %17)
store i64 %18, i64* %4
store i32 1, i32* %3
br label %19
19: ; preds = %39, %11
%20 = load i64, i64* %4
%21 = load i64, i64* %5
%22 = icmp slt i64 %20, %21
br i1 %22, label %23, label %42
23: ; preds = %19
%24 = load i32*, i32** %2
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %32, label %29
29: ; preds = %23
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29, %23
br label %42
33: ; preds = %29
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 10
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %39
39: ; preds = %36, %33
%40 = load i64, i64* %4
%41 = add nsw i64 %40, 1
store i64 %41, i64* %4
br label %19
42: ; preds = %32, %19
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [38 x i8] c"%s:%u: Assertion 'fp != NULL' failed.\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cutechess/sloppy/refs/heads/master/src/pgn.c\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @get_line_num(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @fatal_error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %5
5: ; preds = %3, %1
%6 = tail call i64 @ftell(i32* %0)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %0, i32 0, i32 %7)
%9 = tail call i64 @ftell(i32* %0)
br label %10
10: ; preds = %14, %5
%11 = phi i64 [ %9, %5 ], [ %23, %14 ]
%12 = phi i32 [ 1, %5 ], [ %22, %14 ]
%13 = icmp slt i64 %11, %6
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = tail call i32 @fgetc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
%18 = icmp eq i32 %15, 0
%19 = or i1 %18, %17
%20 = icmp eq i32 %15, 10
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %12, %21
%23 = add nsw i64 %11, 1
br i1 %19, label %24, label %10
24: ; preds = %14, %10
ret i32 %12
}