#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++;
    }
  }
  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    0xe7c(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b7 <main+0x57>
lea    0xe68(%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>
mov    -0x1c(%rbp),%esi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cvtsi2sdl -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdb8(%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    0xe82(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     123c <main+0xcc>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e43(%rip),%r15
xor    %ebx,%ebx
mov    $0x0,%ebp
cmp    (%r15),%al
je     11e6 <main+0x76>
xor    %ebp,%ebp
xor    %ebx,%ebx
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,%ebx
add    %edx,%ebp
cmp    $0x1a,%cl
adc    $0x0,%ebp
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%al
jne    11c0 <main+0x50>
lea    0xe21(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cvtsi2sd %ebx,%xmm0
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
lea    0xe0e(%rip),%rdi
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    0xe04(%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 = [12 x i8] c"Total: %d \0A\00"
@.str.4 = [13 x i8] c"Digits: %d \0A\00"
@.str.5 = [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* %5
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %4
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %4
%59 = sitofp i32 %58 to double
%60 = load i32, i32* %5
%61 = sitofp i32 %60 to double
%62 = fdiv double %59, %61
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), double %62)
%64 = load i32*, i32** %2
%65 = call i32 @fclose(i32* %64)
%66 = 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.3 = [12 x i8] c"Total: %d \0A\00"
@.str.4 = [13 x i8] c"Digits: %d \0A\00"
@.str.5 = [32 x i8] c"The percentage of Digits is: %f\00"
@str = [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, 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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%31 = sitofp i32 %27 to double
%32 = sitofp i32 %28 to double
%33 = fdiv double %31, %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), double %33)
%35 = tail call i32 @fclose(i32* %1)
%36 = tail call i32 (...) @getchar()
ret i32 0
}