#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
int main() {
  FILE *file = fopen("cat_photo.png", "ab");
  FILE *clone = fopen("clone_das_sombras.png", "wb");
  int c;
  if (file == NULL) {
    fprintf(stderr, "Ocorreu um erro ao tentar abrir o arquivo.\n");
    exit(1);
  }
  fprintf(clone, (char *)file);
  fclose(file);
  fclose(clone);
  fprintf(stdout,
          "================= Arquivo aberto com sucesso! =================\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xeab(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a1 <main+0x61>
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
lea    0xe98(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%rdi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xea0(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
test   %rbx,%rbx
je     11ca <main+0x7a>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%rcx
lea    0xea5(%rip),%rdi
mov    $0x40,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e0f(%rip),%rax
mov    (%rax),%rcx
lea    0xe4f(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"cat_photo.png\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [22 x i8] c"clone_das_sombras.png\00"
@.str.3 = [3 x i8] c"wb\00"
@stderr = global i32* null
@.str.4 = [44 x i8] c"Ocorreu um erro ao tentar abrir o arquivo.\0A\00"
@stdout = global i32* null
@.str.5 = [65 x i8] c"================= Arquivo aberto com sucesso! =================\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32*, i32** @stderr
%10 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = load i32*, i32** %1
%15 = bitcast i32* %14 to i8*
%16 = call i32 @fprintf(i32* %13, i8* %15)
%17 = load i32*, i32** %1
%18 = call i32 @fclose(i32* %17)
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = load i32*, i32** @stdout
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"cat_photo.png\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [22 x i8] c"clone_das_sombras.png\00"
@.str.3 = [3 x i8] c"wb\00"
@stderr = global i32* null
@.str.4 = [44 x i8] c"Ocorreu um erro ao tentar abrir o arquivo.\0A\00"
@stdout = global i32* null
@.str.5 = [65 x i8] c"================= Arquivo aberto com sucesso! =================\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%3 = icmp eq i32* %1, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i64 43, i64 1, i32* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = bitcast i32* %1 to i8*
%10 = tail call i32 @fprintf(i32* %2, i8* %9)
%11 = tail call i32 @fclose(i32* %1)
%12 = tail call i32 @fclose(i32* %2)
%13 = load i32*, i32** @stdout
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), i64 64, i64 1, i32* %13)
ret i32 0
}