#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  FILE *arquivo;
  char nome[64];
  printf("Digite o nome do arquivo: ");
  scanf("%s", nome);
  arquivo = fopen(nome, "r");
  if (arquivo != NULL) {
    char c;
    int caracteres = 0;
    int linhas = 0;
    int palavras = 0;
    int tamanho = 0;
    int comecou_uma_palavra = 0;
    while ((c = getc(arquivo)) != EOF) {
      caracteres++;
      if (c == '\n' || c == ' ' || c == '	') {
        if (comecou_uma_palavra) {
          palavras++;
          comecou_uma_palavra = 0;
        }
      } else {
        if (!comecou_uma_palavra)
          comecou_uma_palavra = 1;
      }
      if (c == '\n') {
        linhas++;
        printf("[\\n] %i\n", c);
      } else {
        printf("[%c] %i\n", c, c);
      }
    }
    if (feof(arquivo)) {
      tamanho = caracteres * sizeof(char);
      printf("O arquivo '%s' contém %i linha(s), %i caractere(s), %i "
             "palavra(s) e %i byte(s).\n",
             nome, linhas, caracteres, palavras, tamanho);
    } else {
      printf("O programa não chegou ao final do arquivo com sucesso.\n");
      printf("O arquivo pode estar corrompido!\n");
      return 1;
    }
  } else {
    printf("Não foi possível abrir o arquivo!\n");
    return 1;
  }
  fclose(arquivo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     130d <main+0x1ad>
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x51(%rbp)
movsbl %al,%eax
mov    0x2e03(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     129d <main+0x13d>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
movsbl -0x51(%rbp),%eax
cmp    $0xa,%eax
je     1220 <main+0xc0>
movsbl -0x51(%rbp),%eax
cmp    $0x20,%eax
je     1220 <main+0xc0>
movsbl -0x51(%rbp),%eax
cmp    $0x9,%eax
jne    123f <main+0xdf>
cmpl   $0x0,-0x68(%rbp)
je     123a <main+0xda>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x68(%rbp)
jmp    1255 <main+0xf5>
cmpl   $0x0,-0x68(%rbp)
jne    1250 <main+0xf0>
movl   $0x1,-0x68(%rbp)
jmp    1255 <main+0xf5>
movsbl -0x51(%rbp),%eax
cmp    $0xa,%eax
jne    1282 <main+0x122>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
movsbl -0x51(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1298 <main+0x138>
movsbl -0x51(%rbp),%esi
movsbl -0x51(%rbp),%edx
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cf <main+0x6f>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     12e0 <main+0x180>
movslq -0x58(%rbp),%rax
shl    $0x0,%rax
mov    %eax,-0x64(%rbp)
lea    -0x50(%rbp),%rsi
mov    -0x5c(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x60(%rbp),%r8d
mov    -0x64(%rbp),%r9d
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1308 <main+0x1a8>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1337 <main+0x1d7>
jmp    1327 <main+0x1c7>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1337 <main+0x1d7>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe7b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
call   1070 <scanf@plt>
lea    0xe77(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1214 <main+0xa4>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <getc@plt>
mov    0x2e22(%rip),%r12
mov    $0x0,%r15d
mov    $0x0,%ebp
cmp    (%r12),%al
jne    1220 <main+0xb0>
mov    %r14,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     12a9 <main+0x139>
lea    0xe43(%rip),%rdi
xor    %r12d,%r12d
mov    %rsp,%rsi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    12c7 <main+0x157>
lea    0xe69(%rip),%rdi
jmp    12bc <main+0x14c>
xor    %r13d,%r13d
xor    %ebp,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1254 <main+0xe4>
nopl   0x0(%rax)
movsbl %al,%edx
lea    0xdef(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
add    $0x1,%ebx
cmp    (%r12),%al
je     11d7 <main+0x67>
cmp    $0x20,%al
ja     1280 <main+0x110>
movzbl %al,%ecx
movabs $0x100000600,%rdx
bt     %rcx,%rdx
jae    1280 <main+0x110>
cmp    $0x1,%r13d
sbb    $0xffffffff,%ebp
xor    %r13d,%r13d
cmp    $0xa,%al
jne    1230 <main+0xc0>
jmp    1290 <main+0x120>
nopl   0x0(%rax,%rax,1)
test   %r13d,%r13d
mov    $0x1,%ecx
cmove  %ecx,%r13d
cmp    $0xa,%al
jne    1230 <main+0xc0>
add    $0x1,%r15d
lea    0xd85(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1243 <main+0xd3>
lea    0xdf8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Digite o nome do arquivo: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [9 x i8] c"[\\n] %i\0A\00"
@.str.4 = [9 x i8] c"[%c] %i\0A\00"
@.str.5 = [82 x i8] c"O arquivo '%s' cont\C3\A9m %i linha(s), %i caractere(s), %i palavra(s) e %i byte(s).\0A\00"
@.str.6 = [57 x i8] c"O programa n\C3\A3o chegou ao final do arquivo com sucesso.\0A\00"
@.str.7 = [34 x i8] c"O arquivo pode estar corrompido!\0A\00"
@.str.8 = [37 x i8] c"N\C3\A3o foi poss\C3\ADvel abrir o arquivo!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [64 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %87
17: ; preds = %0
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %18
18: ; preds = %67, %17
%19 = load i32*, i32** %2
%20 = call signext i8 @getc(i32* %19)
store i8 %20, i8* %4
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %68
25: ; preds = %18
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %39, label %31
31: ; preds = %25
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 32
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 9
br i1 %38, label %39, label %46
39: ; preds = %35, %31, %25
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
store i32 0, i32* %9
br label %45
45: ; preds = %42, %39
br label %51
46: ; preds = %35
%47 = load i32, i32* %9
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %46
store i32 1, i32* %9
br label %50
50: ; preds = %49, %46
br label %51
51: ; preds = %50, %45
%52 = load i8, i8* %4
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %61
55: ; preds = %51
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
%58 = load i8, i8* %4
%59 = sext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %59)
br label %67
61: ; preds = %51
%62 = load i8, i8* %4
%63 = sext i8 %62 to i32
%64 = load i8, i8* %4
%65 = sext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %63, i32 %65)
br label %67
67: ; preds = %61, %55
br label %18
68: ; preds = %18
%69 = load i32*, i32** %2
%70 = call i64 @feof(i32* %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %83
72: ; preds = %68
%73 = load i32, i32* %5
%74 = sext i32 %73 to i64
%75 = mul i64 %74, 1
%76 = trunc i64 %75 to i32
store i32 %76, i32* %8
%77 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%78 = load i32, i32* %6
%79 = load i32, i32* %5
%80 = load i32, i32* %7
%81 = load i32, i32* %8
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.5, i64 0, i64 0), i8* %77, i32 %78, i32 %79, i32 %80, i32 %81)
br label %86
83: ; preds = %68
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0))
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %1
br label %92
86: ; preds = %72
br label %89
87: ; preds = %0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %1
br label %92
89: ; preds = %86
%90 = load i32*, i32** %2
%91 = call i32 @fclose(i32* %90)
store i32 0, i32* %1
br label %92
92: ; preds = %89, %87, %83
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
@.str = [27 x i8] c"Digite o nome do arquivo: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [9 x i8] c"[\\n] %i\0A\00"
@.str.4 = [9 x i8] c"[%c] %i\0A\00"
@.str.5 = [82 x i8] c"O arquivo '%s' cont\C3\A9m %i linha(s), %i caractere(s), %i palavra(s) e %i byte(s).\0A\00"
@str = [36 x i8] c"N\C3\A3o foi poss\C3\ADvel abrir o arquivo!\00"
@str.9 = [56 x i8] c"O programa n\C3\A3o chegou ao final do arquivo com sucesso.\00"
@str.10 = [33 x i8] c"O arquivo pode estar corrompido!\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %49, label %7
7: ; preds = %0
%8 = call signext i8 @getc(i32* %5)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %8, %9
br i1 %10, label %40, label %11
11: ; preds = %7, %35
%12 = phi i8 [ %37, %35 ], [ %8, %7 ]
%13 = phi i32 [ %29, %35 ], [ 0, %7 ]
%14 = phi i32 [ %28, %35 ], [ 0, %7 ]
%15 = phi i32 [ %36, %35 ], [ 0, %7 ]
%16 = phi i32 [ %18, %35 ], [ 0, %7 ]
%17 = sext i8 %12 to i32
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i8 %12, 10
switch i8 %12, label %24 [
i8 32, label %20
i8 10, label %20
i8 9, label %20
]
20: ; preds = %11, %11, %11
%21 = icmp ne i32 %13, 0
%22 = zext i1 %21 to i32
%23 = add nsw i32 %14, %22
br label %27
24: ; preds = %11
%25 = icmp eq i32 %13, 0
%26 = select i1 %25, i32 1, i32 %13
br label %27
27: ; preds = %20, %24
%28 = phi i32 [ %14, %24 ], [ %23, %20 ]
%29 = phi i32 [ %26, %24 ], [ 0, %20 ]
br i1 %19, label %30, label %33
30: ; preds = %27
%31 = add nsw i32 %15, 1
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 10)
br label %35
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %17)
br label %35
35: ; preds = %33, %30
%36 = phi i32 [ %31, %30 ], [ %15, %33 ]
%37 = call signext i8 @getc(i32* %5)
%38 = load i8, i8* @EOF
%39 = icmp eq i8 %37, %38
br i1 %39, label %40, label %11
40: ; preds = %35, %7
%41 = phi i32 [ 0, %7 ], [ %18, %35 ]
%42 = phi i32 [ 0, %7 ], [ %36, %35 ]
%43 = phi i32 [ 0, %7 ], [ %28, %35 ]
%44 = call i64 @feof(i32* %5)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.9, i64 0, i64 0))
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.10, i64 0, i64 0))
br label %54
49: ; preds = %0
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %54
51: ; preds = %40
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.5, i64 0, i64 0), i8* %2, i32 %42, i32 %41, i32 %43, i32 %41)
%53 = call i32 @fclose(i32* %5)
br label %54
54: ; preds = %46, %51, %49
%55 = phi i32 [ 0, %51 ], [ 1, %49 ], [ 1, %46 ]
ret i32 %55
}