#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int contarLineas(char dir[]) {
  int cont = 0;
  FILE *tmp;
  char buffer[1024];
  tmp = fopen(dir, "r");
  while (fgets(buffer, 1024, tmp) != NULL) {
    cont = cont + 1;
  }
  fclose(tmp);
  return cont;
}


x86 assembly (clang, -O0):
<contarLineas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1187 <contarLineas+0x57>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <contarLineas+0x2a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contarLineas>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xebd(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    $0xffffffff,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1160 <contarLineas+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @contarLineas(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
%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** %4
br label %8
8: ; preds = %13, %1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = load i32*, i32** %4
%11 = call i32* @fgets(i8* %9, i32 1024, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %8
16: ; preds = %8
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @contarLineas(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ 0, %1 ], [ %9, %5 ]
%7 = call i32* @fgets(i8* %3, i32 1024, i32* %4)
%8 = icmp eq i32* %7, null
%9 = add nuw nsw i32 %6, 1
br i1 %8, label %10, label %5
10: ; preds = %5
%11 = call i32 @fclose(i32* %4)
ret i32 %6
}