#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*/ clog_error(char *, int, int /*<<< orphan*/, char *,
                              char const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ *readline(int /*<<< orphan*/ *);
int count_lines(const char *filename) {
  FILE *fp = fopen(filename, "r");
  int nseqs = 0;
  if (fp == NULL) {
    clog_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/Dongwon-Lee/lsgkm/refs/heads/"
               "master/src/gkmtrain_svr.c",
               181, 0, "can't open input file %s", filename);
    exit(1);
  }
  while (readline(fp) != NULL) {
    ++nseqs;
  }
  fclose(fp);
  return nseqs;
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11aa <count_lines+0x5a>
mov    -0x8(%rbp),%r8
lea    0xe75(%rip),%rdi
mov    $0xb5,%esi
xor    %edx,%edx
lea    0xef8(%rip),%rcx
call   1040 <clog_error@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11af <count_lines+0x5f>
mov    -0x10(%rbp),%rdi
call   1050 <readline@plt>
cmp    $0x0,%rax
je     11d0 <count_lines+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11af <count_lines+0x5f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118f <count_lines+0x3f>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1050 <readline@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1170 <count_lines+0x20>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6c(%rip),%rdi
lea    0xef6(%rip),%rcx
mov    $0xb5,%esi
xor    %edx,%edx
mov    %r14,%r8
call   1040 <clog_error@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Dongwon-Lee/lsgkm/refs/heads/master/src/gkmtrain_svr.c\00"
@.str.2 = [25 x i8] c"can't open input file %s\00"
define i32 @count_lines(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
store i32 0, i32* %4
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @clog_error(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 181, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
br label %14
14: ; preds = %18, %13
%15 = load i32*, i32** %3
%16 = call i32* @readline(i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %14
21: ; preds = %14
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Dongwon-Lee/lsgkm/refs/heads/master/src/gkmtrain_svr.c\00"
@.str.2 = [25 x i8] c"can't open input file %s\00"
define i32 @count_lines(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @clog_error(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 181, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1, %7
%8 = phi i32 [ %11, %7 ], [ 0, %1 ]
%9 = tail call i32* @readline(i32* %2)
%10 = icmp eq i32* %9, null
%11 = add nuw nsw i32 %8, 1
br i1 %10, label %12, label %7
12: ; preds = %7
%13 = tail call i32 @fclose(i32* %2)
ret i32 %8
}