#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isalpha(char);
scalar_t__ isdigit(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  unsigned long cNum = 0;
  unsigned long sNum = 0;
  unsigned long rNum = 0;
  unsigned long oNum = 0;
  char ch;
  FILE *fp;
  if (argc != 2) {
    printf("Please specify the text file to continue\n");
    exit(0);
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    printf("Can't open %s to read\n", argv[1]);
    exit(0);
  }
  while ((ch = fgetc(fp)) != EOF) {
    if (isalpha(ch) || isdigit(ch))
      cNum++;
    else if (isspace(ch))
      sNum++;
    else
      oNum++;
  }
  fclose(fp);
  printf("total characters are: %u\nspace: %u\tother: %u\tcharacter: %u\n",
         sNum + cNum + oNum, sNum, oNum, cNum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d5 <main+0x55>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe46(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1214 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    1219 <main+0x99>
mov    -0x40(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%eax
mov    0x2db9(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12ab <main+0x12b>
movsbl -0x31(%rbp),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
jne    1260 <main+0xe0>
movsbl -0x31(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1271 <main+0xf1>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    12a6 <main+0x126>
movsbl -0x31(%rbp),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
je     1295 <main+0x115>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12a1 <main+0x121>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    12a6 <main+0x126>
jmp    1219 <main+0x99>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rsi
add    -0x18(%rbp),%rsi
add    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1275 <main+0xe5>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1288 <main+0xf8>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2e16(%rip),%r13
cmp    0x0(%r13),%al
jne    1217 <main+0x87>
xor    %r15d,%r15d
xor    %r12d,%r12d
xor    %ebx,%ebx
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    (%r12,%r15,1),%rsi
add    %rbx,%rsi
lea    0xe23(%rip),%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
xor    %r12d,%r12d
xor    %r15d,%r15d
jmp    1242 <main+0xb2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1070 <fgetc@plt>
cmp    0x0(%r13),%al
je     11e0 <main+0x50>
movsbl %al,%ebp
mov    %ebp,%edi
call   1090 <isalpha@plt>
test   %rax,%rax
jne    1230 <main+0xa0>
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1230 <main+0xa0>
mov    %ebp,%edi
call   1080 <isspace@plt>
test   %rax,%rax
je     126f <main+0xdf>
add    $0x1,%r15
jmp    1234 <main+0xa4>
add    $0x1,%r12
jmp    1234 <main+0xa4>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xd6f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Please specify the text file to continue\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Can't open %s to read\0A\00"
@EOF = global i8 0
@.str.3 = [60 x i8] c"total characters are: %u\0Aspace: %u\09other: %u\09character: %u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %11
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %17
br label %30
30: ; preds = %59, %29
%31 = load i32*, i32** %11
%32 = call signext i8 @fgetc(i32* %31)
store i8 %32, i8* %10
%33 = sext i8 %32 to i32
%34 = load i8, i8* @EOF
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %33, %35
br i1 %36, label %37, label %60
37: ; preds = %30
%38 = load i8, i8* %10
%39 = call i64 @isalpha(i8 signext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i8, i8* %10
%43 = call i64 @isdigit(i8 signext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41, %37
%46 = load i64, i64* %6
%47 = add i64 %46, 1
store i64 %47, i64* %6
br label %59
48: ; preds = %41
%49 = load i8, i8* %10
%50 = call i64 @isspace(i8 signext %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i64, i64* %7
%54 = add i64 %53, 1
store i64 %54, i64* %7
br label %58
55: ; preds = %48
%56 = load i64, i64* %9
%57 = add i64 %56, 1
store i64 %57, i64* %9
br label %58
58: ; preds = %55, %52
br label %59
59: ; preds = %58, %45
br label %30
60: ; preds = %30
%61 = load i32*, i32** %11
%62 = call i32 @fclose(i32* %61)
%63 = load i64, i64* %7
%64 = load i64, i64* %6
%65 = add i64 %63, %64
%66 = load i64, i64* %9
%67 = add i64 %65, %66
%68 = load i64, i64* %7
%69 = load i64, i64* %9
%70 = load i64, i64* %6
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i64 %67, i64 %68, i64 %69, i64 %70)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Can't open %s to read\0A\00"
@EOF = global i8 0
@.str.3 = [60 x i8] c"total characters are: %u\0Aspace: %u\09other: %u\09character: %u\0A\00"
@str = [41 x i8] c"Please specify the text file to continue\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = tail call signext i8 @fgetc(i32* %10)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %46, label %20
16: ; preds = %7
%17 = load i8*, i8** %8
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %12, %39
%21 = phi i8 [ %43, %39 ], [ %13, %12 ]
%22 = phi i64 [ %42, %39 ], [ 0, %12 ]
%23 = phi i64 [ %41, %39 ], [ 0, %12 ]
%24 = phi i64 [ %40, %39 ], [ 0, %12 ]
%25 = tail call i64 @isalpha(i8 signext %21)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = tail call i64 @isdigit(i8 signext %21)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27, %20
%31 = add i64 %22, 1
br label %39
32: ; preds = %27
%33 = tail call i64 @isspace(i8 signext %21)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = add i64 %24, 1
br label %39
37: ; preds = %32
%38 = add i64 %23, 1
br label %39
39: ; preds = %35, %37, %30
%40 = phi i64 [ %24, %30 ], [ %36, %35 ], [ %24, %37 ]
%41 = phi i64 [ %23, %30 ], [ %23, %35 ], [ %38, %37 ]
%42 = phi i64 [ %31, %30 ], [ %22, %35 ], [ %22, %37 ]
%43 = tail call signext i8 @fgetc(i32* %10)
%44 = load i8, i8* @EOF
%45 = icmp eq i8 %43, %44
br i1 %45, label %46, label %20
46: ; preds = %39, %12
%47 = phi i64 [ 0, %12 ], [ %40, %39 ]
%48 = phi i64 [ 0, %12 ], [ %41, %39 ]
%49 = phi i64 [ 0, %12 ], [ %42, %39 ]
%50 = tail call i32 @fclose(i32* %10)
%51 = add i64 %48, %47
%52 = add i64 %51, %49
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i64 %52, i64 %47, i64 %48, i64 %49)
ret i32 0
}