#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*/ printf(char *, ...);
int main(void) {
  FILE *file = NULL;
  file = fopen("bla.txt", "r");
  if (file == NULL) {
    printf("erro ao abrir arquivo!\n");
    return 1;
  }
  int c, count = 0;
  c = fgetc(file);
  while (c != EOF) {
    count++;
    c = fgetc(file);
  }
  printf("count=%d\n", count);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xea2(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <main+0x53>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f3 <main+0xb3>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
je     11d2 <main+0x92>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x66>
mov    -0x18(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
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   %rbx
push   %rax
lea    0xea2(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ba <main+0x6a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e67(%rip),%r15
xor    %r14d,%r14d
mov    $0x0,%ebp
cmp    (%r15),%eax
je     11a0 <main+0x50>
xor    %ebp,%ebp
add    $0x1,%ebp
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%eax
jne    1190 <main+0x40>
lea    0xe63(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11cc <main+0x7c>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"bla.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"erro ao abrir arquivo!\0A\00"
@EOF = global i32 0
@.str.3 = [10 x i8] c"count=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %27
10: ; preds = %0
store i32 0, i32* %4
%11 = load i32*, i32** %2
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %3
br label %13
13: ; preds = %17, %10
%14 = load i32, i32* %3
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = load i32*, i32** %2
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %3
br label %13
22: ; preds = %13
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
store i32 0, i32* %1
br label %27
27: ; preds = %22, %8
%28 = load i32, i32* %1
ret i32 %28
}

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