#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 /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char, ...);
int /*<<< orphan*/ stderr;
int main() {
  FILE *file = fopen("lusiadas.txt", "r");
  if (!file) {
    fprintf(stderr, "Erro a abrir ficheiro!\n");
    return 0;
  }
  int total = 0;
  int count['z' - 'a' + 1] = {0};
  for (;;) {
    int c = getc(file);
    if (c == EOF) {
      break;
    }
    char *converter =
        "aaaa---c-ee--i-----ooo----u-----aaaa---c-ee--i-----ooo----u-----";
    if (c >= 0xC0) {
      c = converter[c - 0xC0];
    }
    c |= 0x20;
    if (c >= 'a' && c <= 'z') {
      ++count[c - 'a'];
      ++total;
    }
  }
  printf("Número de letras no ficheiro: %d\n", total);
  for (int i = 0; i < ('z' - 'a' + 1); ++i) {
    float fraction = (float)(count[i] * 100.0f) / total;
    printf("Letra %c: %.2f%%\n", 'a' + i, fraction);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8b(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b5 <main+0x55>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    131f <main+0x1bf>
movl   $0x0,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x68,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%eax
jne    11f5 <main+0x95>
jmp    1280 <main+0x120>
lea    0xe2f(%rip),%rax
mov    %rax,-0x90(%rbp)
cmpl   $0xc0,-0x84(%rbp)
jl     1233 <main+0xd3>
mov    -0x90(%rbp),%rax
mov    -0x84(%rbp),%ecx
sub    $0xc0,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
or     $0x20,%eax
mov    %eax,-0x84(%rbp)
cmpl   $0x61,-0x84(%rbp)
jl     127b <main+0x11b>
cmpl   $0x7a,-0x84(%rbp)
jg     127b <main+0x11b>
mov    -0x84(%rbp),%eax
sub    $0x61,%eax
cltq
mov    -0x80(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x80(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <main+0x6c>
mov    -0x14(%rbp),%eax
lea    0xde2(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x1a,-0x94(%rbp)
jge    130f <main+0x1af>
movslq -0x94(%rbp),%rax
cvtsi2ssl -0x80(%rbp,%rax,4),%xmm0
movss  0xd40(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x98(%rbp)
ff
mov    -0x94(%rbp),%eax
add    $0x61,%eax
movss  -0x98(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xd9e(%rip),%rdi
movsbl %al,%esi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    129e <main+0x13e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122f <main+0xdf>
mov    %rax,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x70(%rsp)
mov    %rax,%rdi
call   1070 <getc@plt>
mov    0x2e31(%rip),%r15
xor    %ebp,%ebp
cmp    (%r15),%eax
jne    1256 <main+0x106>
movsbl %bpl,%esi
lea    0xe9f(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0xc(%rsp)
lea    0xea5(%rip),%r15
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ssl 0x10(%rsp,%rbx,4),%xmm0
mulss  0xdff(%rip),%xmm0
divss  0xc(%rsp),%xmm0
lea    0x61(%rbx),%eax
cvtss2sd %xmm0,%xmm0
movsbl %al,%esi
mov    %r15,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x1a,%rbx
jne    11f0 <main+0xa0>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1244 <main+0xf4>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    0xdcc(%rip),%r12
jmp    1281 <main+0x131>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <getc@plt>
cmp    (%r15),%eax
je     11c2 <main+0x72>
cmp    $0xc0,%eax
jl     1292 <main+0x142>
add    $0xffffff40,%eax
movsbl (%rax,%r12,1),%eax
or     $0x20,%eax
add    $0xffffff9f,%eax
cmp    $0x19,%eax
ja     1270 <main+0x120>
mov    %eax,%eax
addl   $0x1,0x10(%rsp,%rax,4)
add    $0x1,%ebp
jmp    1270 <main+0x120>

LLVM IR (-O0):
@.str = [13 x i8] c"lusiadas.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Erro a abrir ficheiro!\0A\00"
@EOF = global i32 0
@.str.3 = [65 x i8] c"aaaa---c-ee--i-----ooo----u-----aaaa---c-ee--i-----ooo----u-----\00"
@.str.4 = [35 x i8] c"N\C3\BAmero de letras no ficheiro: %d\0A\00"
@.str.5 = [18 x i8] c"Letra %c: %.2f%%\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [26 x i32]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca float
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %82
15: ; preds = %0
store i32 0, i32* %3
%16 = bitcast [26 x i32]* %4 to i8*
br label %17
17: ; preds = %52, %15
%18 = load i32*, i32** %2
%19 = call i32 @getc(i32* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %17
br label %53
24: ; preds = %17
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i8** %6
%25 = load i32, i32* %5
%26 = icmp sge i32 %25, 192
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load i8*, i8** %6
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 192
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
store i32 %34, i32* %5
br label %35
35: ; preds = %27, %24
%36 = load i32, i32* %5
%37 = or i32 %36, 32
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = icmp sge i32 %38, 97
br i1 %39, label %40, label %52
40: ; preds = %35
%41 = load i32, i32* %5
%42 = icmp sle i32 %41, 122
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = load i32, i32* %5
%45 = sub nsw i32 %44, 97
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [26 x i32], [26 x i32]* %4, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 1
store i32 %49, i32* %47
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %52
52: ; preds = %43, %40, %35
br label %17
53: ; preds = %23
%54 = load i32, i32* %3
%55 = trunc i32 %54 to i8
%56 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8 signext %55)
store i32 0, i32* %7
br label %57
57: ; preds = %76, %53
%58 = load i32, i32* %7
%59 = icmp slt i32 %58, 26
br i1 %59, label %60, label %79
60: ; preds = %57
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [26 x i32], [26 x i32]* %4, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = sitofp i32 %64 to float
%66 = fmul float %65, 1.000000e+02
%67 = load i32, i32* %3
%68 = sitofp i32 %67 to float
%69 = fdiv float %66, %68
store float %69, float* %8
%70 = load i32, i32* %7
%71 = add nsw i32 97, %70
%72 = trunc i32 %71 to i8
%73 = load float, float* %8
%74 = fpext float %73 to double
%75 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8 signext %72, double %74)
br label %76
76: ; preds = %60
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
store i32 %78, i32* %7
br label %57
79: ; preds = %57
%80 = load i32*, i32** %2
%81 = call i32 @fclose(i32* %80)
store i32 0, i32* %1
br label %82
82: ; preds = %79, %12
%83 = load i32, i32* %1
ret i32 %83
}

LLVM IR (-O2):
@.str = [13 x i8] c"lusiadas.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Erro a abrir ficheiro!\0A\00"
@EOF = global i32 0
@.str.3 = [65 x i8] c"aaaa---c-ee--i-----ooo----u-----aaaa---c-ee--i-----ooo----u-----\00"
@.str.4 = [35 x i8] c"N\C3\BAmero de letras no ficheiro: %d\0A\00"
@.str.5 = [18 x i8] c"Letra %c: %.2f%%\0A\00"
define i32 @main() {
%1 = alloca [26 x i32]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %58
7: ; preds = %0
%8 = bitcast [26 x i32]* %1 to i8*
%9 = tail call i32 @getc(i32* %2)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %38, label %12
12: ; preds = %7, %33
%13 = phi i32 [ %35, %33 ], [ %9, %7 ]
%14 = phi i32 [ %34, %33 ], [ 0, %7 ]
%15 = icmp sgt i32 %13, 191
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = add nsw i32 %13, -192
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [65 x i8], [65 x i8]* @.str.3, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
br label %22
22: ; preds = %16, %12
%23 = phi i32 [ %21, %16 ], [ %13, %12 ]
%24 = or i32 %23, 32
%25 = add i32 %24, -97
%26 = icmp ult i32 %25, 26
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = zext i32 %25 to i64
%29 = getelementptr inbounds [26 x i32], [26 x i32]* %1, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
%32 = add nsw i32 %14, 1
br label %33
33: ; preds = %22, %27
%34 = phi i32 [ %32, %27 ], [ %14, %22 ]
%35 = tail call i32 @getc(i32* %2)
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %12
38: ; preds = %33, %7
%39 = phi i32 [ 0, %7 ], [ %34, %33 ]
%40 = trunc i32 %39 to i8
%41 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8 signext %40)
%42 = sitofp i32 %39 to float
br label %45
43: ; preds = %45
%44 = tail call i32 @fclose(i32* %2)
br label %58
45: ; preds = %38, %45
%46 = phi i64 [ 0, %38 ], [ %56, %45 ]
%47 = getelementptr inbounds [26 x i32], [26 x i32]* %1, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = sitofp i32 %48 to float
%50 = fmul float %49, 1.000000e+02
%51 = fdiv float %50, %42
%52 = trunc i64 %46 to i8
%53 = add nuw nsw i8 %52, 97
%54 = fpext float %51 to double
%55 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8 signext %53, double %54)
%56 = add nuw nsw i64 %46, 1
%57 = icmp eq i64 %56, 26
br i1 %57, label %43, label %45
58: ; preds = %43, %4
ret i32 0
}