#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 EOF;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ my_err(char *, char *, int);
long util_fcount_lines(FILE *fh) {
  long line_count;
  char c;
  if (fseek(fh, 0L, SEEK_SET) != 0) {
    my_err("%s:%d: could not rewind filehandle",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           78);
  }
  line_count = 0;
  while ((c = getc(fh)) != EOF) {
    if (c == '\n') {
      line_count++;
    }
  }
  if (fseek(fh, 0L, SEEK_SET) != 0) {
    my_err("%s:%d: could not rewind filehandle",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           89);
  }
  return line_count;
}


x86 assembly (clang, -O0):
<util_fcount_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <fseek@plt>
cmp    $0x0,%rax
je     1174 <util_fcount_lines+0x44>
lea    0xe9d(%rip),%rdi
lea    0xeb9(%rip),%rsi
mov    $0x4e,%edx
call   1040 <my_err@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e56(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11bb <util_fcount_lines+0x8b>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    11b6 <util_fcount_lines+0x86>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    117c <util_fcount_lines+0x4c>
mov    -0x8(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <fseek@plt>
cmp    $0x0,%rax
je     11f3 <util_fcount_lines+0xc3>
lea    0xe1e(%rip),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x59,%edx
call   1040 <my_err@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_fcount_lines>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e96(%rip),%r15
mov    (%r15),%edx
xor    %esi,%esi
call   1030 <fseek@plt>
test   %rax,%rax
je     1169 <util_fcount_lines+0x39>
lea    0xea8(%rip),%rdi
lea    0xec4(%rip),%rsi
mov    $0x4e,%edx
call   1040 <my_err@plt>
mov    %r14,%rdi
call   1050 <getc@plt>
mov    0x2e70(%rip),%r12
cmp    (%r12),%al
jne    1182 <util_fcount_lines+0x52>
xor    %ebx,%ebx
jmp    11a8 <util_fcount_lines+0x78>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %rcx,%rbx
mov    %r14,%rdi
call   1050 <getc@plt>
cmp    (%r12),%al
jne    1190 <util_fcount_lines+0x60>
mov    (%r15),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <fseek@plt>
test   %rax,%rax
je     11d2 <util_fcount_lines+0xa2>
lea    0xe3f(%rip),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x59,%edx
call   1040 <my_err@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [35 x i8] c"%s:%d: could not rewind filehandle\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
@EOF = global i8 0
define i64 @util_fcount_lines(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = load i32, i32* @SEEK_SET
%7 = call i64 @fseek(i32* %5, i64 0, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 78)
br label %11
11: ; preds = %9, %1
store i64 0, i64* %3
br label %12
12: ; preds = %26, %11
%13 = load i32*, i32** %2
%14 = call signext i8 @getc(i32* %13)
store i8 %14, i8* %4
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %27
19: ; preds = %12
%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 = %19
%24 = load i64, i64* %3
%25 = add nsw i64 %24, 1
store i64 %25, i64* %3
br label %26
26: ; preds = %23, %19
br label %12
27: ; preds = %12
%28 = load i32*, i32** %2
%29 = load i32, i32* @SEEK_SET
%30 = call i64 @fseek(i32* %28, i64 0, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 89)
br label %34
34: ; preds = %32, %27
%35 = load i64, i64* %3
ret i64 %35
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [35 x i8] c"%s:%d: could not rewind filehandle\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
@EOF = global i8 0
define i64 @util_fcount_lines(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_SET
%3 = tail call i64 @fseek(i32* %0, i64 0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 78)
br label %7
7: ; preds = %5, %1
%8 = tail call signext i8 @getc(i32* %0)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %8, %9
br i1 %10, label %20, label %11
11: ; preds = %7, %11
%12 = phi i8 [ %17, %11 ], [ %8, %7 ]
%13 = phi i64 [ %16, %11 ], [ 0, %7 ]
%14 = icmp eq i8 %12, 10
%15 = zext i1 %14 to i64
%16 = add nuw nsw i64 %13, %15
%17 = tail call signext i8 @getc(i32* %0)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %20, label %11
20: ; preds = %11, %7
%21 = phi i64 [ 0, %7 ], [ %16, %11 ]
%22 = load i32, i32* @SEEK_SET
%23 = tail call i64 @fseek(i32* %0, i64 0, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 89)
br label %27
27: ; preds = %25, %20
ret i64 %21
}