#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 */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int main() {
  FILE *fp;
  char ch;
  if ((fp = fopen("arqtext.txt", "r")) == NULL) {
    printf("\nO arquivo não pode ser aberto");
    exit(1);
  } else {
    printf("\nO arquivo foi aberto");
  }
  printf("\nConteúdo do arquivo:");
  ch = getc(fp);
  while (ch != EOF) {
    putchar(ch);
    ch = getc(fp);
  }
  fclose(fp);
  printf("\nFim do programa!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a6 <main+0x46>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe81(%rip),%rdi
call   1050 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2e13(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11fa <main+0x9a>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x11(%rbp)
jmp    11ca <main+0x6a>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe51(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e3 <main+0x83>
mov    %rax,%rbx
lea    0xea8(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb2(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
mov    0x2e42(%rip),%r14
cmp    (%r14),%al
je     11c5 <main+0x65>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r14),%al
jne    11b0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe87(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"arqtext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"\0AO arquivo n\C3\A3o pode ser aberto\00"
@.str.3 = [22 x i8] c"\0AO arquivo foi aberto\00"
@.str.4 = [23 x i8] c"\0AConte\C3\BAdo do arquivo:\00"
@EOF = global i8 0
@.str.5 = [18 x i8] c"\0AFim do programa!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %11
11: ; preds = %9
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%13 = load i32*, i32** %2
%14 = call signext i8 @getc(i32* %13)
store i8 %14, i8* %3
br label %15
15: ; preds = %21, %11
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i8, i8* %3
%23 = call i32 @putchar(i8 signext %22)
%24 = load i32*, i32** %2
%25 = call signext i8 @getc(i32* %24)
store i8 %25, i8* %3
br label %15
26: ; preds = %15
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"arqtext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"\0AO arquivo n\C3\A3o pode ser aberto\00"
@.str.3 = [22 x i8] c"\0AO arquivo foi aberto\00"
@.str.4 = [23 x i8] c"\0AConte\C3\BAdo do arquivo:\00"
@EOF = global i8 0
@.str.5 = [18 x i8] c"\0AFim do programa!\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call signext i8 @getc(i32* %1)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %6, %12
%13 = phi i8 [ %15, %12 ], [ %9, %6 ]
%14 = tail call i32 @putchar(i8 signext %13)
%15 = tail call signext i8 @getc(i32* %1)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %12
18: ; preds = %12, %6
%19 = tail call i32 @fclose(i32* %1)
%20 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}