#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) {
  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 && modo == 'r') {
    printf("\nERRO ABERTURA ARQUIVO %s\n", nome);
    return auxiliar;
  }
}


x86 assembly (clang, -O0):
<abre_arquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x72,%eax
jne    1158 <abre_arquivo+0x38>
mov    -0x10(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1197 <abre_arquivo+0x77>
movsbl -0x11(%rbp),%eax
cmp    $0x77,%eax
jne    117e <abre_arquivo+0x5e>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1192 <abre_arquivo+0x72>
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1197 <abre_arquivo+0x77>
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <abre_arquivo+0xa7>
movsbl -0x11(%rbp),%eax
cmp    $0x72,%eax
jne    11c7 <abre_arquivo+0xa7>
mov    -0x10(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abre_arquivo>:
push   %rbx
mov    %rdi,%rbx
cmp    $0x72,%sil
je     1139 <abre_arquivo+0x19>
cmp    $0x77,%sil
jne    114f <abre_arquivo+0x2f>
lea    0xecb(%rip),%rsi
jmp    1156 <abre_arquivo+0x36>
lea    0xec0(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     115f <abre_arquivo+0x3f>
pop    %rbx
ret
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <fopen@plt>
lea    0xea1(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
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) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32*
store i8* %0, i8** %4
store i8 %1, i8* %5
%7 = load i8, i8* %5
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 114
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
br label %24
13: ; preds = %2
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 119
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
br label %23
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %6
br label %23
23: ; preds = %20, %17
br label %24
24: ; preds = %23, %10
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load i8, i8* %5
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 114
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32*, i32** %6
store i32* %34, i32** %3
br label %35
35: ; preds = %31, %27, %24
%36 = load i32*, i32** %3
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) {
switch i8 %1, label %5 [
i8 114, label %7
i8 119, label %3
]
3: ; preds = %2
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %12
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %12
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %5, %3, %7, %10
%13 = phi i32* [ %8, %7 ], [ null, %10 ], [ %6, %5 ], [ %4, %3 ]
ret i32* %13
}