#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  char ch;
  int dig = 0;
  int tot = 0;
  fp = fopen("english.txt", "r");
  if (fp == NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }
  while ((ch = fgetc(fp)) != EOF) {
    if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
      tot++;
    }
    if (ch >= 0 && ch <= 50) {
      dig++;
      tot++;
    }
  }
  if ((double)dig / tot > .20) {
    printf("Too many numbers!\n\n");
  }
  printf("Total: %d \n", tot);
  printf("Digits: %d \n", dig);
  printf("The percentage of Digits is: %f", (double)dig / tot);
  fclose(fp);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe84(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b7 <main+0x57>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11bc <main+0x5c>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e16(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     124b <main+0xeb>
movsbl -0x11(%rbp),%eax
cmp    $0x61,%eax
jl     11f7 <main+0x97>
movsbl -0x11(%rbp),%eax
cmp    $0x7a,%eax
jle    1211 <main+0xb1>
movsbl -0x11(%rbp),%eax
cmp    $0x41,%eax
jl     121a <main+0xba>
movsbl -0x11(%rbp),%eax
cmp    $0x5a,%eax
jg     121a <main+0xba>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jl     1246 <main+0xe6>
movsbl -0x11(%rbp),%eax
cmp    $0x32,%eax
jg     1246 <main+0xe6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bc <main+0x5c>
cvtsi2sdl -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd9f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1279 <main+0x119>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cvtsi2sdl -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xda6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe8a(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     125c <main+0xec>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e43(%rip),%r15
xor    %ebp,%ebp
mov    $0x0,%ebx
cmp    (%r15),%al
je     11e6 <main+0x76>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%ecx
and    $0xdf,%cl
add    $0xbf,%cl
xor    %edx,%edx
cmp    $0x33,%al
setb   %dl
add    %edx,%ebp
add    %edx,%ebx
cmp    $0x1a,%cl
adc    $0x0,%ebx
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%al
jne    11c0 <main+0x50>
cvtsi2sd %ebp,%xmm1
cvtsi2sd %ebx,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
ucomisd 0xe01(%rip),%xmm1
jbe    120d <main+0x9d>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
lea    0xe02(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdfe(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdfb(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdff(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"english.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Cannot open file.\0A\00"
@EOF = global i8 0
@.str.3 = [20 x i8] c"Too many numbers!\0A\0A\00"
@.str.4 = [12 x i8] c"Total: %d \0A\00"
@.str.5 = [13 x i8] c"Digits: %d \0A\00"
@.str.6 = [32 x i8] c"The percentage of Digits is: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
br label %13
13: ; preds = %52, %12
%14 = load i32*, i32** %2
%15 = call signext i8 @fgetc(i32* %14)
store i8 %15, i8* %3
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %53
20: ; preds = %13
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp sge i32 %22, 97
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = icmp sle i32 %26, 122
br i1 %27, label %36, label %28
28: ; preds = %24, %20
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = icmp sge i32 %30, 65
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp sle i32 %34, 90
br i1 %35, label %36, label %39
36: ; preds = %32, %24
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %39
39: ; preds = %36, %32, %28
%40 = load i8, i8* %3
%41 = sext i8 %40 to i32
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = load i8, i8* %3
%45 = sext i8 %44 to i32
%46 = icmp sle i32 %45, 50
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %52
52: ; preds = %47, %43, %39
br label %13
53: ; preds = %13
%54 = load i32, i32* %4
%55 = sitofp i32 %54 to double
%56 = load i32, i32* %5
%57 = sitofp i32 %56 to double
%58 = fdiv double %55, %57
%59 = fcmp ogt double %58, 2.000000e-01
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60, %53
%63 = load i32, i32* %5
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %4
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %4
%68 = sitofp i32 %67 to double
%69 = load i32, i32* %5
%70 = sitofp i32 %69 to double
%71 = fdiv double %68, %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), double %71)
%73 = load i32*, i32** %2
%74 = call i32 @fclose(i32* %73)
%75 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"english.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.4 = [12 x i8] c"Total: %d \0A\00"
@.str.5 = [13 x i8] c"Digits: %d \0A\00"
@.str.6 = [32 x i8] c"The percentage of Digits is: %f\00"
@str = [19 x i8] c"Too many numbers!\0A\00"
@str.7 = [18 x i8] c"Cannot open file.\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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 %26, label %10
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3, %10
%11 = phi i8 [ %23, %10 ], [ %4, %3 ]
%12 = phi i32 [ %22, %10 ], [ 0, %3 ]
%13 = phi i32 [ %20, %10 ], [ 0, %3 ]
%14 = and i8 %11, -33
%15 = add i8 %14, -65
%16 = icmp ult i8 %15, 26
%17 = zext i1 %16 to i32
%18 = icmp ult i8 %11, 51
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %13, %19
%21 = add i32 %12, %19
%22 = add i32 %21, %17
%23 = tail call signext i8 @fgetc(i32* %1)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %26, label %10
26: ; preds = %10, %3
%27 = phi i32 [ 0, %3 ], [ %20, %10 ]
%28 = phi i32 [ 0, %3 ], [ %22, %10 ]
%29 = sitofp i32 %27 to double
%30 = sitofp i32 %28 to double
%31 = fdiv double %29, %30
%32 = fcmp ogt double %31, 2.000000e-01
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), double %31)
%39 = tail call i32 @fclose(i32* %1)
%40 = tail call i32 (...) @getchar()
ret i32 0
}