#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  FILE *arq;
  int c;
  int n = 0;
  arq = fopen("file.txt", "r");
  if (arq == NULL) {
    perror("Erro, nao foi possivel abrir o arquivo\n");
    return (-1);
  }
  while ((c = fgetc(arq)) != EOF) {
    printf("%c", c);
    n++;
  }
  printf("bytes: %d", n);
  fclose(arq);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <main+0x50>
lea    0xe7c(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <main+0xac>
jmp    11a5 <main+0x55>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
je     11dd <main+0x8d>
mov    -0x14(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a5 <main+0x55>
mov    -0x18(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xea1(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11dd <main+0x8d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e66(%rip),%r12
xor    %r14d,%r14d
mov    $0x0,%ebp
cmp    (%r12),%eax
je     11bb <main+0x6b>
xor    %ebp,%ebp
lea    0xe9a(%rip),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%eax
jne    11a0 <main+0x50>
lea    0xe74(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r14d
jmp    11d1 <main+0x81>

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"Erro, nao foi possivel abrir o arquivo\0A\00"
@EOF = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [10 x i8] c"bytes: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %26
10: ; preds = %0
br label %11
11: ; preds = %16, %10
%12 = load i32*, i32** %2
%13 = call i32 @fgetc(i32* %12)
store i32 %13, i32* %3
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %11
21: ; preds = %11
%22 = load i32, i32* %4
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
store i32 0, i32* %1
br label %26
26: ; preds = %21, %8
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"Erro, nao foi possivel abrir o arquivo\0A\00"
@EOF = global i32 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [10 x i8] c"bytes: %d\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 %7, label %3
3: ; preds = %0
%4 = tail call i32 @fgetc(i32* %1)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %17, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %21
9: ; preds = %3, %9
%10 = phi i32 [ %14, %9 ], [ %4, %3 ]
%11 = phi i32 [ %13, %9 ], [ 0, %3 ]
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%13 = add nuw nsw i32 %11, 1
%14 = tail call i32 @fgetc(i32* %1)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %9
17: ; preds = %9, %3
%18 = phi i32 [ 0, %3 ], [ %13, %9 ]
%19 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = tail call i32 @fclose(i32* %1)
br label %21
21: ; preds = %17, %7
%22 = phi i32 [ -1, %7 ], [ 0, %17 ]
ret i32 %22
}