#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*/ assert_file_exist(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int file_line_count(char *file) {
  int ch = 0;
  int linecnt = 0;
  assert_file_exist(file);
  FILE *fptr = fopen(file, "r");
  while ((ch = fgetc(fptr)) != EOF)
    if (ch == '\n')
      linecnt++;
  fclose(fptr);
  return linecnt;
}


x86 assembly (clang, -O0):
<file_line_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert_file_exist@plt>
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%eax
je     11aa <file_line_count+0x6a>
cmpl   $0xa,-0xc(%rbp)
jne    11a5 <file_line_count+0x65>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1177 <file_line_count+0x37>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_line_count>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <assert_file_exist@plt>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e7b(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%eax
je     1197 <file_line_count+0x57>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
jne    1180 <file_line_count+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @file_line_count(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = load i8*, i8** %2
%7 = call i32 @assert_file_exist(i8* %6)
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
br label %10
10: ; preds = %21, %1
%11 = load i32*, i32** %5
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %3
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %18, %15
br label %10
22: ; preds = %10
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %4
ret i32 %25
}

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