#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 *);
unsigned int nblines(char *fic) {
  unsigned int count = 0;
  FILE *file;
  int c;
  if (((file = fopen(fic, "r"))) == NULL) {
    return (-1);
  };
  while ((c = fgetc(file)) != EOF) {
    if (c == '\n')
      ++count;
  }
  fclose(file);
  return count;
}


x86 assembly (clang, -O0):
<nblines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116d <nblines+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <nblines+0x84>
jmp    1172 <nblines+0x42>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%eax
je     11a5 <nblines+0x75>
cmpl   $0xa,-0x24(%rbp)
jne    11a0 <nblines+0x70>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <nblines+0x42>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nblines>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1181 <nblines+0x51>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e91(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%eax
je     1177 <nblines+0x47>
xor    %ebp,%ebp
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r14),%eax
jne    1160 <nblines+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1186 <nblines+0x56>
mov    $0xffffffff,%ebp
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 @nblines(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%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** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %28
11: ; preds = %1
br label %12
12: ; preds = %23, %11
%13 = load i32*, i32** %5
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %6
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %4
%22 = add i32 %21, 1
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %17
br label %12
24: ; preds = %12
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %24, %10
%29 = load i32, i32* %2
ret i32 %29
}

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