#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*/ v_o;
typedef int /*<<< orphan*/ v_c;
typedef int /*<<< orphan*/ v_a;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ in_array(int, int *, int);
int /*<<< orphan*/ printf(char *, char, int);
int main() {
  FILE *f;
  int v_a[2] = {131, 163};
  int v_o[2] = {149, 181};
  int v_c[2] = {135, 167};
  f = fopen("enunciado/lusiadas-utf8.txt", "r");
  int c = 0;
  int freq[3] = {};
  char letras[3] = {'A', 'O', 'C'};
  int i;
  while (c != EOF) {
    c = getc(f);
    if (c == 195) {
      c = getc(f);
      if (in_array(c, v_a, sizeof(v_a) / sizeof(int))) {
        freq[0]++;
      } else if (in_array(c, v_o, sizeof(v_o) / sizeof(int))) {
        freq[1]++;
      } else if (in_array(c, v_c, sizeof(v_c) / sizeof(int))) {
        freq[2]++;
      }
    }
  };
  int nl = i;
  fclose(f);
  for (i = 0; i < 2; i++) {
    printf("Letra %c com til = %d\n", letras[i], freq[i]);
  }
  printf("Letra %c com cedilha = %d\n", letras[i], freq[2]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0xea3(%rip),%ax
mov    %ax,-0x3b(%rbp)
mov    0xe9b(%rip),%al
mov    %al,-0x39(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%eax
je     1293 <main+0x133>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xc3,-0x2c(%rbp)
jne    128e <main+0x12e>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1080 <in_array@plt>
cmp    $0x0,%rax
je     1232 <main+0xd2>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1289 <main+0x129>
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1080 <in_array@plt>
cmp    $0x0,%rax
je     125b <main+0xfb>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1284 <main+0x124>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x2,%edx
call   1080 <in_array@plt>
cmp    $0x0,%rax
je     127f <main+0x11f>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1284 <main+0x124>
jmp    1289 <main+0x129>
jmp    128e <main+0x12e>
jmp    11d2 <main+0x72>
mov    -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x40(%rbp)
cmpl   $0x2,-0x40(%rbp)
jge    12e0 <main+0x180>
movslq -0x40(%rbp),%rax
mov    -0x3b(%rbp,%rax,1),%al
movslq -0x40(%rbp),%rcx
mov    -0x38(%rbp,%rcx,4),%edx
lea    0xd6c(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12a9 <main+0x149>
movslq -0x40(%rbp),%rax
mov    -0x3b(%rbp,%rax,1),%al
mov    -0x30(%rbp),%edx
lea    0xd5b(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movabs $0xa300000083,%rax
mov    %rax,0x20(%rsp)
movabs $0xb500000095,%rax
mov    %rax,0x18(%rsp)
movabs $0xa700000087,%rax
mov    %rax,0x10(%rsp)
lea    0xe6e(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    0x2e40(%rip),%r14
cmpl   $0x0,(%r14)
je     1245 <main+0xf5>
movl   $0x0,0xc(%rsp)
lea    0x20(%rsp),%r12
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    11d8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%r13d
cmp    (%r14),%r13d
je     1252 <main+0x102>
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    $0xc3,%eax
jne    11d0 <main+0x80>
mov    %rbx,%rdi
call   1060 <getc@plt>
mov    %eax,%r13d
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x2,%edx
call   1070 <in_array@plt>
test   %rax,%rax
je     120b <main+0xbb>
add    $0x1,%ebp
jmp    11d3 <main+0x83>
mov    %r13d,%edi
lea    0x18(%rsp),%rsi
mov    $0x2,%edx
call   1070 <in_array@plt>
test   %rax,%rax
je     1228 <main+0xd8>
add    $0x1,%r15d
jmp    11d3 <main+0x83>
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
mov    $0x2,%edx
call   1070 <in_array@plt>
cmp    $0x1,%rax
sbbl   $0xffffffff,0xc(%rsp)
jmp    11d3 <main+0x83>
xor    %ebp,%ebp
xor    %r15d,%r15d
movl   $0x0,0xc(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xdbd(%rip),%rbx
mov    %rbx,%rdi
mov    $0x41,%esi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4f,%esi
mov    %r15d,%edx
call   1040 <printf@plt>
lea    0xdae(%rip),%rdi
mov    $0x43,%esi
mov    0xc(%rsp),%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.v_a = [2 x i32] [i32 131, i32 163]
@__const.main.v_o = [2 x i32] [i32 149, i32 181]
@__const.main.v_c = [2 x i32] [i32 135, i32 167]
@.str = [28 x i8] c"enunciado/lusiadas-utf8.txt\00"
@.str.1 = [2 x i8] c"r\00"
@__const.main.letras = [3 x i8] c"AOC"
@EOF = global i32 0
@.str.2 = [23 x i8] c"Letra %c com til = %d\0A\00"
@.str.3 = [27 x i8] c"Letra %c com cedilha = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca [3 x i32]
%8 = alloca [3 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = bitcast [2 x i32]* %3 to i8*
%12 = bitcast [2 x i32]* %4 to i8*
%13 = bitcast [2 x i32]* %5 to i8*
%14 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %2
store i32 0, i32* %6
%15 = bitcast [3 x i32]* %7 to i8*
%16 = bitcast [3 x i8]* %8 to i8*
br label %17
17: ; preds = %58, %0
%18 = load i32, i32* %6
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %59
21: ; preds = %17
%22 = load i32*, i32** %2
%23 = call i32 @getc(i32* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 195
br i1 %25, label %26, label %58
26: ; preds = %21
%27 = load i32*, i32** %2
%28 = call i32 @getc(i32* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%31 = call i64 @in_array(i32 %29, i32* %30, i32 2)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %34
br label %57
37: ; preds = %26
%38 = load i32, i32* %6
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%40 = call i64 @in_array(i32 %38, i32* %39, i32 2)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
%44 = load i32, i32* %43
%45 = add nsw i32 %44, 1
store i32 %45, i32* %43
br label %56
46: ; preds = %37
%47 = load i32, i32* %6
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%49 = call i64 @in_array(i32 %47, i32* %48, i32 2)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 2
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
store i32 %54, i32* %52
br label %55
55: ; preds = %51, %46
br label %56
56: ; preds = %55, %42
br label %57
57: ; preds = %56, %33
br label %58
58: ; preds = %57, %21
br label %17
59: ; preds = %17
%60 = load i32, i32* %9
store i32 %60, i32* %10
%61 = load i32*, i32** %2
%62 = call i32 @fclose(i32* %61)
store i32 0, i32* %9
br label %63
63: ; preds = %76, %59
%64 = load i32, i32* %9
%65 = icmp slt i32 %64, 2
br i1 %65, label %66, label %79
66: ; preds = %63
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %70, i32 %74)
br label %76
76: ; preds = %66
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %9
br label %63
79: ; preds = %63
%80 = load i32, i32* %9
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 2
%85 = load i32, i32* %84
%86 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8 signext %83, i32 %85)
%87 = load i32, i32* %1
ret i32 %87
}

LLVM IR (-O2):
@.str = [28 x i8] c"enunciado/lusiadas-utf8.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [23 x i8] c"Letra %c com til = %d\0A\00"
@.str.3 = [27 x i8] c"Letra %c com cedilha = %d\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
store i64 700079669379, i64* %1
%5 = bitcast i64* %2 to i8*
store i64 777389080725, i64* %2
%6 = bitcast i64* %3 to i8*
store i64 717259538567, i64* %3
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %8, 0
br i1 %9, label %43, label %10
10: ; preds = %0
%11 = bitcast i64* %1 to i32*
%12 = bitcast i64* %2 to i32*
%13 = bitcast i64* %3 to i32*
br label %14
14: ; preds = %10, %36
%15 = phi i32 [ 0, %10 ], [ %37, %36 ]
%16 = phi i32 [ 0, %10 ], [ %38, %36 ]
%17 = phi i32 [ 0, %10 ], [ %39, %36 ]
%18 = call i32 @getc(i32* %7)
%19 = icmp eq i32 %18, 195
br i1 %19, label %20, label %36
20: ; preds = %14
%21 = call i32 @getc(i32* %7)
%22 = call i64 @in_array(i32 %21, i32* %11, i32 2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = add nsw i32 %17, 1
br label %36
26: ; preds = %20
%27 = call i64 @in_array(i32 %21, i32* %12, i32 2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = add nsw i32 %16, 1
br label %36
31: ; preds = %26
%32 = call i64 @in_array(i32 %21, i32* %13, i32 2)
%33 = icmp ne i64 %32, 0
%34 = zext i1 %33 to i32
%35 = add nsw i32 %15, %34
br label %36
36: ; preds = %31, %24, %29, %14
%37 = phi i32 [ %15, %24 ], [ %15, %29 ], [ %15, %14 ], [ %35, %31 ]
%38 = phi i32 [ %16, %24 ], [ %30, %29 ], [ %16, %14 ], [ %16, %31 ]
%39 = phi i32 [ %25, %24 ], [ %17, %29 ], [ %17, %14 ], [ %17, %31 ]
%40 = phi i32 [ %21, %24 ], [ %21, %29 ], [ %18, %14 ], [ %21, %31 ]
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %14
43: ; preds = %36, %0
%44 = phi i32 [ 0, %0 ], [ %39, %36 ]
%45 = phi i32 [ 0, %0 ], [ %38, %36 ]
%46 = phi i32 [ 0, %0 ], [ %37, %36 ]
%47 = call i32 @fclose(i32* %7)
%48 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext 65, i32 %44)
%49 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext 79, i32 %45)
%50 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8 signext 67, i32 %46)
ret i32 0
}