#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int dbsize(char *dbname) {
  char line[1500];
  int qtdl = 0;
  FILE *fp;
  if (!(fp = fopen(dbname, "r"))) {
    printf("Fail to open database %s.\n", dbname);
    exit(EXIT_FAILURE);
  }
  do {
    fgets(line, 1500, fp);
    qtdl++;
  } while (!feof(fp));
  fclose(fp);
  return --qtdl;
}


x86 assembly (clang, -O0):
<dbsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x600,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x5f4(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x600(%rbp)
cmp    $0x0,%rax
jne    11b8 <dbsize+0x58>
mov    -0x8(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11bd <dbsize+0x5d>
lea    -0x5f0(%rbp),%rdi
mov    -0x600(%rbp),%rdx
mov    $0x5dc,%esi
call   1050 <fgets@plt>
mov    -0x5f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5f4(%rbp)
mov    -0x600(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11bd <dbsize+0x5d>
mov    -0x600(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x5f4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x5f4(%rbp)
add    $0x600,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbsize>:
push   %rbp
push   %r14
push   %rbx
sub    $0x5e0,%rsp
mov    %rdi,%rbp
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c5 <dbsize+0x65>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x5dc,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
add    $0x1,%ebp
test   %eax,%eax
je     1190 <dbsize+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x5e0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe36(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Fail to open database %s.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @dbsize(i8* %0) {
%2 = alloca i8*
%3 = alloca [1500 x i8]
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %4
%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** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
br label %15
15: ; preds = %21, %14
%16 = getelementptr inbounds [1500 x i8], [1500 x i8]* %3, i64 0, i64 0
%17 = load i32*, i32** %5
%18 = call i32 @fgets(i8* %16, i32 1500, i32* %17)
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %15
%22 = load i32*, i32** %5
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %15, label %26
26: ; preds = %21
%27 = load i32*, i32** %5
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Fail to open database %s.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @dbsize(i8* %0) {
%2 = alloca [1500 x i8]
%3 = getelementptr inbounds [1500 x i8], [1500 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1, %10
%11 = phi i32 [ %13, %10 ], [ 0, %1 ]
%12 = call i32 @fgets(i8* %3, i32 1500, i32* %4)
%13 = add nuw nsw i32 %11, 1
%14 = call i32 @feof(i32* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %10, label %16
16: ; preds = %10
%17 = call i32 @fclose(i32* %4)
ret i32 %11
}