#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*/ escrever(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int main() {
  FILE *ponteiro_arquivo_de_saida;
  const char modo[] = "w";
  const char arquivo_de_saida[] = "saida.txt";
  ponteiro_arquivo_de_saida = fopen(arquivo_de_saida, modo);
  if (ponteiro_arquivo_de_saida == NULL) {
    fprintf(stderr, "Impossivel abrir o arquivo de saida %s\n",
            arquivo_de_saida);
    exit(1);
  }
  escrever(ponteiro_arquivo_de_saida);
  fclose(ponteiro_arquivo_de_saida);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xea1(%rip),%ax
mov    %ax,-0xa(%rbp)
mov    0xe98(%rip),%rax
mov    %rax,-0x14(%rbp)
mov    0xe95(%rip),%ax
mov    %ax,-0xc(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0xa(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11b8 <main+0x68>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <escrever@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movw   $0x77,0xe(%rsp)
movabs $0x78742e6164696173,%rax
2e 74 78
mov    %rax,0x10(%rsp)
movw   $0x74,0x18(%rsp)
lea    0x10(%rsp),%rdi
lea    0xe(%rsp),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a1 <main+0x51>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <escrever@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.main.modo = [2 x i8] c"w\00"
@__const.main.arquivo_de_saida = [10 x i8] c"saida.txt\00"
@stderr = global i32 0
@.str = [40 x i8] c"Impossivel abrir o arquivo de saida %s\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca [2 x i8]
%3 = alloca [10 x i8]
%4 = bitcast [2 x i8]* %2 to i8*
%5 = bitcast [10 x i8]* %3 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%8 = call i32* @fopen(i8* %6, i8* %7)
store i32* %8, i32** %1
%9 = load i32*, i32** %1
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32*, i32** %1
%18 = call i32 @escrever(i32* %17)
%19 = load i32*, i32** %1
%20 = call i32 @fclose(i32* %19)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arquivo_de_saida = [10 x i8] c"saida.txt\00"
@stderr = global i32 0
@.str = [40 x i8] c"Impossivel abrir o arquivo de saida %s\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = alloca [10 x i8]
%3 = bitcast i16* %1 to i8*
store i16 119, i16* %1
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = call i32* @fopen(i8* %4, i8* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32 @escrever(i32* %5)
%13 = tail call i32 @fclose(i32* %5)
ret i32 0
}