#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ is_letter(char);
scalar_t__ is_vowel(char);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char c;
  int consonants = 0, vowels = 0;
  FILE *dat;
  if ((dat = fopen("text.txt", "r")) == NULL) {
    printf("The file `text.txt` can not be opened.\n");
    return -1;
  }
  while ((c = fgetc(dat)) != EOF) {
    if (is_letter(c)) {
      if (is_vowel(c))
        vowels++;
      else
        consonants++;
    }
  }
  fclose(dat);
  printf("Ratio vowels/consonants: %d/%d = %5.2f\n", vowels, consonants,
         (float)vowels / consonants);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b8 <main+0x58>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <main+0xfb>
jmp    11bd <main+0x5d>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2e15(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1225 <main+0xc5>
movsbl -0x5(%rbp),%edi
call   1060 <is_letter@plt>
cmp    $0x0,%rax
je     1220 <main+0xc0>
movsbl -0x5(%rbp),%edi
call   1070 <is_vowel@plt>
cmp    $0x0,%rax
je     1212 <main+0xb2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    121b <main+0xbb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1220 <main+0xc0>
jmp    11bd <main+0x5d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
cvtsi2ssl -0x10(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@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   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11ea <main+0x7a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e43(%rip),%r13
xor    %r14d,%r14d
mov    $0x0,%r15d
mov    $0x0,%r12d
cmp    0x0(%r13),%al
jne    120e <main+0x9e>
mov    %rbx,%rdi
call   1040 <fclose@plt>
cvtsi2ss %r12d,%xmm0
cvtsi2ss %r15d,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe30(%rip),%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    $0x1,%al
call   1050 <printf@plt>
jmp    11fc <main+0x8c>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
xor    %r15d,%r15d
jmp    1232 <main+0xc2>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15d
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%al
je     11ba <main+0x4a>
movsbl %al,%ebp
mov    %ebp,%edi
call   1070 <is_letter@plt>
test   %rax,%rax
je     1224 <main+0xb4>
mov    %ebp,%edi
call   1080 <is_vowel@plt>
test   %rax,%rax
je     1220 <main+0xb0>
add    $0x1,%r12d
jmp    1224 <main+0xb4>

LLVM IR (-O0):
@.str = [9 x i8] c"text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"The file `text.txt` can not be opened.\0A\00"
@EOF = global i8 0
@.str.3 = [40 x i8] c"Ratio vowels/consonants: %d/%d = %5.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
10: ; preds = %0
br label %11
11: ; preds = %33, %10
%12 = load i32*, i32** %5
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %2
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %34
18: ; preds = %11
%19 = load i8, i8* %2
%20 = call i64 @is_letter(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i8, i8* %2
%24 = call i64 @is_vowel(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %32
29: ; preds = %22
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %32
32: ; preds = %29, %26
br label %33
33: ; preds = %32, %18
br label %11
34: ; preds = %11
%35 = load i32*, i32** %5
%36 = call i32 @fclose(i32* %35)
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = sitofp i32 %39 to float
%41 = load i32, i32* %3
%42 = sitofp i32 %41 to float
%43 = fdiv float %40, %42
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %38, double %44)
store i32 0, i32* %1
br label %46
46: ; preds = %34, %8
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [9 x i8] c"text.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [40 x i8] c"Ratio vowels/consonants: %d/%d = %5.2f\0A\00"
@str = [39 x i8] c"The file `text.txt` can not be opened.\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 %7, label %3
3: ; preds = %0
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %28, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %37
9: ; preds = %3, %22
%10 = phi i8 [ %25, %22 ], [ %4, %3 ]
%11 = phi i32 [ %24, %22 ], [ 0, %3 ]
%12 = phi i32 [ %23, %22 ], [ 0, %3 ]
%13 = tail call i64 @is_letter(i8 signext %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %9
%16 = tail call i64 @is_vowel(i8 signext %10)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = add nsw i32 %11, 1
br label %22
20: ; preds = %15
%21 = add nsw i32 %12, 1
br label %22
22: ; preds = %18, %20, %9
%23 = phi i32 [ %12, %18 ], [ %21, %20 ], [ %12, %9 ]
%24 = phi i32 [ %19, %18 ], [ %11, %20 ], [ %11, %9 ]
%25 = tail call signext i8 @fgetc(i32* %1)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %28, label %9
28: ; preds = %22, %3
%29 = phi i32 [ 0, %3 ], [ %23, %22 ]
%30 = phi i32 [ 0, %3 ], [ %24, %22 ]
%31 = tail call i32 @fclose(i32* %1)
%32 = sitofp i32 %30 to float
%33 = sitofp i32 %29 to float
%34 = fdiv float %32, %33
%35 = fpext float %34 to double
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %29, double %35)
br label %37
37: ; preds = %28, %7
%38 = phi i32 [ -1, %7 ], [ 0, %28 ]
ret i32 %38
}