#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int file_count_line(char *filename) {
  unsigned long count_line;
  int c;
  FILE *fp;
  fp = fopen(filename, "r");
  if (!fp)
    return -1;
  count_line = 0;
  while ((c = fgetc(fp)) != EOF) {
    if (c == '\n')
      count_line++;
  }
  fclose(fp);
  return count_line;
}


x86 assembly (clang, -O0):
<file_count_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1167 <file_count_line+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <file_count_line+0x85>
movq   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%eax
je     11a5 <file_count_line+0x75>
cmpl   $0xa,-0x1c(%rbp)
jne    11a0 <file_count_line+0x70>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116f <file_count_line+0x3f>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_count_line>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1192 <file_count_line+0x62>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e90(%rip),%r15
xor    %ebx,%ebx
cmp    (%r15),%eax
je     1188 <file_count_line+0x58>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %rcx,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1170 <file_count_line+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1197 <file_count_line+0x67>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @file_count_line(i8* nocapture %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 %22, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %19, label %8
8: ; preds = %4, %8
%9 = phi i32 [ %14, %8 ], [ %5, %4 ]
%10 = phi i64 [ %13, %8 ], [ 0, %4 ]
%11 = icmp eq i32 %9, 10
%12 = zext i1 %11 to i64
%13 = add i64 %10, %12
%14 = tail call i32 @fgetc(i32* %2)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %8
17: ; preds = %8
%18 = trunc i64 %13 to i32
br label %19
19: ; preds = %17, %4
%20 = phi i32 [ 0, %4 ], [ %18, %17 ]
%21 = tail call i32 @fclose(i32* %2)
br label %22
22: ; preds = %1, %19
%23 = phi i32 [ %20, %19 ], [ -1, %1 ]
ret i32 %23
}