#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int lineCount, wordCount, byteCount;
  int isWord = 0;
  if (argc != 2) {
    printf("Not enough command line arguments\n");
    return 1;
  } else {
    FILE *fp = fopen(argv[1], "r");
    if (!fp) {
      printf("file doesnt exist\n");
      return 2;
    } else {
      wordCount = 0;
      int ch = 0;
      do {
        ch = fgetc(fp);
        if (!isspace(ch))
          isWord = 1;
        if (isspace(ch) && isWord == 1) {
          isWord = 0;
          wordCount++;
        }
        if (ch == '\n')
          lineCount++;
        if (ch != EOF)
          byteCount++;
      } while (ch != EOF);
    }
    printf(" %d %d %d %s \n", lineCount, wordCount, byteCount, argv[1]);
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a6 <main+0x156>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <main+0x7e>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12a6 <main+0x156>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
jne    1201 <main+0xb1>
movl   $0x1,-0x20(%rbp)
mov    -0x2c(%rbp),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     122d <main+0xdd>
cmpl   $0x1,-0x20(%rbp)
jne    122d <main+0xdd>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jne    1240 <main+0xf0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d9e(%rip),%rcx
cmp    (%rcx),%eax
je     125b <main+0x10b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1260 <main+0x110>
mov    -0x2c(%rbp),%eax
mov    0x2d7e(%rip),%rcx
cmp    (%rcx),%eax
jne    11dc <main+0x8c>
jmp    1277 <main+0x127>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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    1201 <main+0xa1>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     123e <main+0xde>
mov    %rax,%r15
mov    %rbx,(%rsp)
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    11c2 <main+0x62>
nop
movzbl %cl,%ecx
add    %ecx,%r12d
xor    %ecx,%ecx
cmp    $0xa,%ebx
sete   %cl
add    %ecx,%ebp
add    $0x1,%r13d
mov    %eax,%r14d
mov    0x2e2a(%rip),%rax
cmp    (%rax),%ebx
je     1214 <main+0xb4>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <isspace@plt>
test   %rax,%rax
mov    $0x1,%eax
cmove  %eax,%r14d
mov    %ebx,%edi
call   1070 <isspace@plt>
test   %rax,%rax
setne  %dl
cmp    $0x1,%r14d
sete   %cl
mov    $0x0,%eax
and    %dl,%cl
jne    11a0 <main+0x40>
mov    %r14d,%eax
jmp    11a0 <main+0x40>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    124f <main+0xef>
mov    (%rsp),%rax
mov    0x8(%rax),%r8
lea    0xddf(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    124f <main+0xef>
lea    0xdcc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Not enough command line arguments\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"file doesnt exist\0A\00"
@EOF = global i32 0
@.str.3 = [15 x i8] c" %d %d %d %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %73
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp ne i32* %21, null
br i1 %22, label %25, label %23
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %73
25: ; preds = %16
store i32 0, i32* %7
store i32 0, i32* %11
br label %26
26: ; preds = %57, %25
%27 = load i32*, i32** %10
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %11
%29 = load i32, i32* %11
%30 = call i64 @isspace(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %26
store i32 1, i32* %9
br label %33
33: ; preds = %32, %26
%34 = load i32, i32* %11
%35 = call i64 @isspace(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %43
40: ; preds = %37
store i32 0, i32* %9
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %43
43: ; preds = %40, %37, %33
%44 = load i32, i32* %11
%45 = icmp eq i32 %44, 10
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* %11
%51 = load i32, i32* @EOF
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %56
56: ; preds = %53, %49
br label %57
57: ; preds = %56
%58 = load i32, i32* %11
%59 = load i32, i32* @EOF
%60 = icmp ne i32 %58, %59
br i1 %60, label %26, label %61
61: ; preds = %57
br label %62
62: ; preds = %61
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %63, i32 %64, i32 %65, i8* %68)
%70 = load i32*, i32** %10
%71 = call i32 @fclose(i32* %70)
br label %72
72: ; preds = %62
store i32 0, i32* %3
br label %73
73: ; preds = %72, %23, %14
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.3 = [15 x i8] c" %d %d %d %s \0A\00"
@str = [18 x i8] c"file doesnt exist\00"
@str.4 = [34 x i8] c"Not enough command line arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0))
br label %39
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %39
13: ; preds = %6, %13
%14 = phi i32 [ %31, %13 ], [ undef, %6 ]
%15 = phi i32 [ %27, %13 ], [ 0, %6 ]
%16 = phi i32 [ %34, %13 ], [ undef, %6 ]
%17 = phi i32 [ %28, %13 ], [ 0, %6 ]
%18 = tail call i32 @fgetc(i32* %9)
%19 = tail call i64 @isspace(i32 %18)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i32 1, i32 %17
%22 = tail call i64 @isspace(i32 %18)
%23 = icmp ne i64 %22, 0
%24 = icmp eq i32 %21, 1
%25 = select i1 %23, i1 %24, i1 false
%26 = zext i1 %25 to i32
%27 = add nuw nsw i32 %15, %26
%28 = select i1 %25, i32 0, i32 %21
%29 = icmp eq i32 %18, 10
%30 = zext i1 %29 to i32
%31 = add nsw i32 %14, %30
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %18, %32
%34 = add nsw i32 %16, 1
br i1 %33, label %35, label %13
35: ; preds = %13
%36 = load i8*, i8** %7
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %27, i32 %16, i8* %36)
%38 = tail call i32 @fclose(i32* %9)
br label %39
39: ; preds = %11, %35, %4
%40 = phi i32 [ 1, %4 ], [ 0, %35 ], [ 2, %11 ]
ret i32 %40
}