#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*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
FILE *abre_arquivo(char *nome, char modo, char extra) {
  FILE *auxiliar;
  if (modo == 'r')
    auxiliar = fopen(nome, "r");
  else if (modo == 'w')
    auxiliar = fopen(nome, "w");
  else
    auxiliar = fopen(nome, "a+");
  if (auxiliar == NULL && extra == 'l')
    printf("\nERRO ABERTURA ARQUIVO %s\n", nome);
  return auxiliar;
}


x86 assembly (clang, -O0):
<abre_arquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x72,%eax
jne    115d <abre_arquivo+0x3d>
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    119c <abre_arquivo+0x7c>
movsbl -0x9(%rbp),%eax
cmp    $0x77,%eax
jne    1183 <abre_arquivo+0x63>
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1197 <abre_arquivo+0x77>
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    119c <abre_arquivo+0x7c>
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <abre_arquivo+0xa4>
movsbl -0xa(%rbp),%eax
cmp    $0x6c,%eax
jne    11c4 <abre_arquivo+0xa4>
mov    -0x8(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abre_arquivo>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
cmp    $0x77,%sil
lea    0xece(%rip),%rax
lea    0xec9(%rip),%rcx
cmove  %rax,%rcx
cmp    $0x72,%sil
lea    0xeb6(%rip),%rsi
cmovne %rcx,%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
cmp    $0x6c,%bpl
jne    1170 <abre_arquivo+0x50>
test   %rbx,%rbx
jne    1170 <abre_arquivo+0x50>
lea    0xe9f(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"a+\00"
@.str.3 = [27 x i8] c"\0AERRO ABERTURA ARQUIVO %s\0A\00"
define i32* @abre_arquivo(i8* %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32*
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%8 = load i8, i8* %5
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 114
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
br label %25
14: ; preds = %3
%15 = load i8, i8* %5
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 119
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
br label %24
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %7
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %11
%26 = load i32*, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 108
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %28, %25
%36 = load i32*, i32** %7
ret i32* %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"a+\00"
@.str.3 = [27 x i8] c"\0AERRO ABERTURA ARQUIVO %s\0A\00"
define i32* @abre_arquivo(i8* %0, i8 signext %1, i8 signext %2) {
%4 = icmp eq i8 %1, 119
%5 = select i1 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%6 = icmp eq i8 %1, 114
%7 = select i1 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %5
%8 = tail call i32* @fopen(i8* %0, i8* %7)
%9 = icmp eq i32* %8, null
%10 = icmp eq i8 %2, 108
%11 = and i1 %10, %9
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %3
ret i32* %8
}