#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*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int cuenta_lineas(char *nombre_fichero) {
  FILE *fp = fopen(nombre_fichero, "r");
  char ch;
  int n_lineas = 0;
  while (!feof(fp)) {
    ch = fgetc(fp);
    if (ch == '\n')
      n_lineas++;
  }
  return n_lineas;
}


x86 assembly (clang, -O0):
<cuenta_lineas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1175 <cuenta_lineas+0x45>
jmp    119c <cuenta_lineas+0x6c>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    1197 <cuenta_lineas+0x67>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1157 <cuenta_lineas+0x27>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cuenta_lineas>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    117d <cuenta_lineas+0x4d>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %eax,%eax
je     1160 <cuenta_lineas+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @cuenta_lineas(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 = tail call i32 @feof(i32* %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1, %5
%6 = phi i32 [ %10, %5 ], [ 0, %1 ]
%7 = tail call signext i8 @fgetc(i32* %2)
%8 = icmp eq i8 %7, 10
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
%11 = tail call i32 @feof(i32* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %5, label %13
13: ; preds = %5, %1
%14 = phi i32 [ 0, %1 ], [ %10, %5 ]
ret i32 %14
}