#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*/ *);
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);
  printf("Vamos ler o arquivo '%s'...\n", nome);
  arquivo = fopen(nome, "r");
  int contagemLetras[256] = {0};
  char c;
  while ((c = getc(arquivo)) != EOF) {
    contagemLetras[(int)c]++;
  }
  int i;
  int maior = 0;
  for (i = 32; i < 127; i++) {
    if (contagemLetras[i])
      printf("%5d ['%c'] = %i ocorrência(s)\n", i, i, contagemLetras[i]);
    if (contagemLetras[i] > contagemLetras[maior])
      maior = i;
  }
  printf("['%c'] é a letra que mais aparece no arquivo.\n", maior);
  fclose(arquivo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x451(%rbp)
movsbl %al,%eax
mov    0x2e06(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     120c <main+0xac>
movsbl -0x451(%rbp),%eax
cltq
mov    -0x450(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x450(%rbp,%rax,4)
jmp    11c9 <main+0x69>
movl   $0x0,-0x45c(%rbp)
movl   $0x20,-0x458(%rbp)
cmpl   $0x7f,-0x458(%rbp)
jge    12b1 <main+0x151>
movslq -0x458(%rbp),%rax
cmpl   $0x0,-0x450(%rbp,%rax,4)
je     126a <main+0x10a>
mov    -0x458(%rbp),%esi
mov    -0x458(%rbp),%edx
movslq -0x458(%rbp),%rax
mov    -0x450(%rbp,%rax,4),%ecx
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x458(%rbp),%rax
mov    -0x450(%rbp,%rax,4),%eax
movslq -0x45c(%rbp),%rcx
cmp    -0x450(%rbp,%rcx,4),%eax
jle    1298 <main+0x138>
mov    -0x458(%rbp),%eax
mov    %eax,-0x45c(%rbp)
jmp    129d <main+0x13d>
mov    -0x458(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
jmp    1220 <main+0xc0>
mov    -0x45c(%rbp),%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x440,%rsp
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0x40(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r14,%rdi
call   1080 <getc@plt>
mov    0x2e16(%rip),%rbx
cmp    (%rbx),%al
je     11f5 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
movsbq %al,%rax
addl   $0x1,0x40(%rsp,%rax,4)
mov    %r14,%rdi
call   1080 <getc@plt>
cmp    (%rbx),%al
jne    11e0 <main+0x80>
mov    $0x20,%ebx
lea    0xe3c(%rip),%r15
xor    %ebp,%ebp
jmp    121c <main+0xbc>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
mov    %esi,%ebp
cmp    $0x7f,%rbx
je     1247 <main+0xe7>
mov    0x40(%rsp,%rbx,4),%r12d
test   %r12d,%r12d
je     1237 <main+0xd7>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
movslq %ebp,%rax
mov    %ebx,%esi
cmp    0x40(%rsp,%rax,4),%r12d
jg     1210 <main+0xb0>
mov    %ebp,%esi
jmp    1210 <main+0xb0>
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbx
pop    %r12
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 = [29 x i8] c"Vamos ler o arquivo '%s'...\0A\00"
@.str.3 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.4 = [32 x i8] c"%5d ['%c'] = %i ocorr\C3\AAncia(s)\0A\00"
@.str.5 = [48 x i8] c"['%c'] \C3\A9 a letra que mais aparece no arquivo.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [64 x i8]
%4 = alloca [256 x i32]
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, 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.3, i64 0, i64 0))
store i32* %14, i32** %2
%15 = bitcast [256 x i32]* %4 to i8*
br label %16
16: ; preds = %23, %0
%17 = load i32*, i32** %2
%18 = call signext i8 @getc(i32* %17)
store i8 %18, i8* %5
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %30
23: ; preds = %16
%24 = load i8, i8* %5
%25 = sext i8 %24 to i32
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1
store i32 %29, i32* %27
br label %16
30: ; preds = %16
store i32 0, i32* %7
store i32 32, i32* %6
br label %31
31: ; preds = %61, %30
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 127
br i1 %33, label %34, label %64
34: ; preds = %31
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %48
40: ; preds = %34
%41 = load i32, i32* %6
%42 = load i32, i32* %6
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 %42, i32 %46)
br label %48
48: ; preds = %40, %34
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = icmp sgt i32 %52, %56
br i1 %57, label %58, label %60
58: ; preds = %48
%59 = load i32, i32* %6
store i32 %59, i32* %7
br label %60
60: ; preds = %58, %48
br label %61
61: ; preds = %60
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %31
64: ; preds = %31
%65 = load i32, i32* %7
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = load i32*, i32** %2
%68 = call i32 @fclose(i32* %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Digite o nome do arquivo: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [29 x i8] c"Vamos ler o arquivo '%s'...\0A\00"
@.str.3 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.4 = [32 x i8] c"%5d ['%c'] = %i ocorr\C3\AAncia(s)\0A\00"
@.str.5 = [48 x i8] c"['%c'] \C3\A9 a letra que mais aparece no arquivo.\0A\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca [256 x i32]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = bitcast [256 x i32]* %2 to i8*
%9 = call signext i8 @getc(i32* %7)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %21, label %12
12: ; preds = %0, %12
%13 = phi i8 [ %18, %12 ], [ %9, %0 ]
%14 = sext i8 %13 to i64
%15 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
%18 = call signext i8 @getc(i32* %7)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %12
21: ; preds = %12, %0
br label %22
22: ; preds = %21, %31
%23 = phi i64 [ %37, %31 ], [ 32, %21 ]
%24 = phi i32 [ %36, %31 ], [ 0, %21 ]
%25 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 %23
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
%28 = trunc i64 %23 to i32
br i1 %27, label %31, label %29
29: ; preds = %22
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %28, i32 %28, i32 %26)
br label %31
31: ; preds = %22, %29
%32 = sext i32 %24 to i64
%33 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp sgt i32 %26, %34
%36 = select i1 %35, i32 %28, i32 %24
%37 = add nuw nsw i64 %23, 1
%38 = icmp eq i64 %37, 127
br i1 %38, label %39, label %22
39: ; preds = %31
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %36)
%41 = call i32 @fclose(i32* %7)
ret i32 0
}