#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 */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, scalar_t__, char const *);
char *strerror(scalar_t__);
FILE *openDatabase(const char *name, char mode[3]) {
  FILE *db = fopen(name, mode);
  if (db == NULL) {
    if (errno == ENOENT) {
      printf("\n\a Erro %d: O arquivo [%s] nao foi localizado.\n", errno, name);
      exit(1);
    } else {
      printf("\n\a Erro %d: %s.\n", errno, strerror(errno));
    }
  }
  return db;
}


x86 assembly (clang, -O0):
<openDatabase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11df <openDatabase+0x9f>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <openDatabase+0x6a>
mov    0x2e53(%rip),%rax
mov    (%rax),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
jmp    11df <openDatabase+0x9f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openDatabase>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1185 <openDatabase+0x45>
mov    0x2e84(%rip),%rax
mov    (%rax),%r15
mov    0x2e6a(%rip),%rax
cmp    (%rax),%r15
je     118e <openDatabase+0x4e>
mov    %r15,%rdi
call   1060 <strerror@plt>
lea    0xeb6(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6b(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ENOENT = global i64 0
@.str = [48 x i8] c"\0A\07 Erro %d: O arquivo [%s] nao foi localizado.\0A\00"
@.str.1 = [17 x i8] c"\0A\07 Erro %d: %s.\0A\00"
define i32* @openDatabase(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %6, i8* %7)
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %26
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOENT
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 %16, i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = load i64, i64* @errno
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %21, i8* %23)
br label %25
25: ; preds = %20
br label %26
26: ; preds = %25, %2
%27 = load i32*, i32** %5
ret i32* %27
}

LLVM IR (-O2):
@errno = global i64 0
@ENOENT = global i64 0
@.str = [48 x i8] c"\0A\07 Erro %d: O arquivo [%s] nao foi localizado.\0A\00"
@.str.1 = [17 x i8] c"\0A\07 Erro %d: %s.\0A\00"
define noalias i32* @openDatabase(i8* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOENT
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i64 %6, i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5
%13 = tail call i8* @strerror(i64 %6)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %6, i8* %13)
br label %15
15: ; preds = %12, %2
ret i32* %3
}