#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(void) {
  FILE *fp;
  char buf[1024];
  int n;
  char *p;
  int letter, number, blank;
  fp = fopen("test.txt", "rb");
  if (fp == NULL) {
    perror("fail to open");
    exit(1);
  }
  letter = 0;
  number = 0;
  blank = 0;
  while ((n = fread(buf, sizeof(char), 1024 - 1, fp)) > 0) {
    buf[n] = '\0';
    p = buf;
    while (*p != '\0') {
      if (('a' <= *p && *p <= 'z') || ('A' <= *p && *p <= 'Z'))
        letter++;
      if (*p == ' ')
        blank++;
      if ('0' <= *p && *p <= '9')
        number++;
      p++;
    }
  }
  if (n == -1) {
    perror("fail to read");
    exit(1);
  }
  printf("the sum of letter is : %d\nthe sum of number is : %d\nthe sum of "
         "blank is : %d\n",
         letter, number, blank);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119a <main+0x4a>
lea    0xe81(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
movl   $0x0,-0x42c(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3ff,%edx
call   1030 <fread@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jle    12eb <main+0x19b>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12e6 <main+0x196>
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x61,%eax
cmp    %ecx,%eax
jg     123b <main+0xeb>
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7a,%eax
jle    1265 <main+0x115>
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     1274 <main+0x124>
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5a,%eax
jg     1274 <main+0x124>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1296 <main+0x146>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     12cf <main+0x17f>
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     12cf <main+0x17f>
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
jmp    11fe <main+0xae>
jmp    11b8 <main+0x68>
cmpl   $0xffffffff,-0x414(%rbp)
jne    130e <main+0x1be>
lea    0xd1a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x424(%rbp),%esi
mov    -0x428(%rbp),%edx
mov    -0x42c(%rbp),%ecx
lea    0xcff(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe98(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     123f <main+0xef>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    120c <main+0xbc>
xor    %r15d,%r15d
lea    0x1(%rsp),%r13
mov    %rsp,%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    11c9 <main+0x79>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    1213 <main+0xc3>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    (%rsp),%al
test   %al,%al
je     11b0 <main+0x60>
mov    %r13,%rcx
nopl   0x0(%rax)
mov    %eax,%edx
and    $0xdf,%dl
add    $0xbf,%dl
cmp    $0x1a,%dl
adc    $0x0,%ebx
xor    %edx,%edx
cmp    $0x20,%al
sete   %dl
add    %edx,%r15d
add    $0xd0,%al
cmp    $0xa,%al
adc    $0x0,%ebp
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    11e0 <main+0x90>
jmp    11b0 <main+0x60>
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r15d,%r15d
cmp    $0xffffffff,%eax
je     1248 <main+0xf8>
lea    0xe07(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc6(%rip),%rdi
jmp    124f <main+0xff>
lea    0xdca(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fail to open\00"
@.str.3 = [13 x i8] c"fail to read\00"
@.str.4 = [78 x i8] c"the sum of letter is : %d\0Athe sum of number is : %d\0Athe sum of blank is : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %16
16: ; preds = %78, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i32*, i32** %2
%19 = call i32 @fread(i8* %17, i32 1, i32 1023, i32* %18)
store i32 %19, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %79
21: ; preds = %16
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8* %25, i8** %5
br label %26
26: ; preds = %75, %21
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %78
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp sle i32 97, %34
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sle i32 %39, 122
br i1 %40, label %51, label %41
41: ; preds = %36, %31
%42 = load i8*, i8** %5
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp sle i32 65, %44
br i1 %45, label %46, label %54
46: ; preds = %41
%47 = load i8*, i8** %5
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp sle i32 %49, 90
br i1 %50, label %51, label %54
51: ; preds = %46, %36
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %54
54: ; preds = %51, %46, %41
%55 = load i8*, i8** %5
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 32
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %62
62: ; preds = %59, %54
%63 = load i8*, i8** %5
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp sle i32 48, %65
br i1 %66, label %67, label %75
67: ; preds = %62
%68 = load i8*, i8** %5
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp sle i32 %70, 57
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
br label %75
75: ; preds = %72, %67, %62
%76 = load i8*, i8** %5
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %5
br label %26
78: ; preds = %26
br label %16
79: ; preds = %16
%80 = load i32, i32* %4
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %79
%86 = load i32, i32* %6
%87 = load i32, i32* %7
%88 = load i32, i32* %8
%89 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.4, i64 0, i64 0), i32 %86, i32 %87, i32 %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fail to open\00"
@.str.3 = [13 x i8] c"fail to read\00"
@.str.4 = [78 x i8] c"the sum of letter is : %d\0Athe sum of number is : %d\0Athe sum of blank is : %d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @fread(i8* %2, i32 1, i32 1023, i32* %3)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %17, label %47
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %26, %17
%12 = phi i32 [ %21, %17 ], [ %36, %26 ]
%13 = phi i32 [ %20, %17 ], [ %43, %26 ]
%14 = phi i32 [ %19, %17 ], [ %39, %26 ]
%15 = call i32 @fread(i8* %2, i32 1, i32 1023, i32* %3)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %47
17: ; preds = %5, %11
%18 = phi i32 [ %15, %11 ], [ %6, %5 ]
%19 = phi i32 [ %14, %11 ], [ 0, %5 ]
%20 = phi i32 [ %13, %11 ], [ 0, %5 ]
%21 = phi i32 [ %12, %11 ], [ 0, %5 ]
%22 = zext i32 %18 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %22
store i8 0, i8* %23
%24 = load i8, i8* %2
%25 = icmp eq i8 %24, 0
br i1 %25, label %11, label %26
26: ; preds = %17, %26
%27 = phi i8 [ %45, %26 ], [ %24, %17 ]
%28 = phi i32 [ %39, %26 ], [ %19, %17 ]
%29 = phi i32 [ %43, %26 ], [ %20, %17 ]
%30 = phi i32 [ %36, %26 ], [ %21, %17 ]
%31 = phi i8* [ %44, %26 ], [ %2, %17 ]
%32 = and i8 %27, -33
%33 = add i8 %32, -65
%34 = icmp ult i8 %33, 26
%35 = zext i1 %34 to i32
%36 = add nsw i32 %30, %35
%37 = icmp eq i8 %27, 32
%38 = zext i1 %37 to i32
%39 = add nsw i32 %28, %38
%40 = add i8 %27, -48
%41 = icmp ult i8 %40, 10
%42 = zext i1 %41 to i32
%43 = add nsw i32 %29, %42
%44 = getelementptr inbounds i8, i8* %31, i64 1
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
br i1 %46, label %11, label %26
47: ; preds = %11, %5
%48 = phi i32 [ 0, %5 ], [ %12, %11 ]
%49 = phi i32 [ 0, %5 ], [ %13, %11 ]
%50 = phi i32 [ 0, %5 ], [ %14, %11 ]
%51 = phi i32 [ %6, %5 ], [ %15, %11 ]
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %47
%57 = tail call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.4, i64 0, i64 0), i32 %48, i32 %49, i32 %50)
ret i32 0
}