#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*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fidopen(int /*<<< orphan*/, char *);
scalar_t__ isblank(char);
int /*<<< orphan*/ printf(char *, size_t, size_t, size_t);
int WordCount(size_t argc, const char **argv) {
  size_t nchar, nword, nline;
  nchar = nword = nline = 0;
  int wspace = 1;
  char c;
  FILE *fin = fidopen(0, "r");
  while ((c = fgetc(fin)) != EOF) {
    nchar++;
    if (wspace && !isblank(c)) {
      wspace = 0;
      nword++;
    }
    if (c == '\n') {
      nline++;
      wspace = 1;
    }
    if (isblank(c))
      wspace = 1;
  }
  fclose(fin);
  printf("%8zd %8zd %8zd\n", nline, nword, nchar);
  return 0;
}


x86 assembly (clang, -O0):
<WordCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x2c(%rbp)
xor    %edi,%edi
lea    0xe78(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x2d(%rbp)
movsbl %al,%eax
mov    0x2e41(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     122d <WordCount+0xdd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ee <WordCount+0x9e>
movsbl -0x2d(%rbp),%edi
call   1050 <isblank@plt>
cmp    $0x0,%rax
jne    11ee <WordCount+0x9e>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movsbl -0x2d(%rbp),%eax
cmp    $0xa,%eax
jne    120e <WordCount+0xbe>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movsbl -0x2d(%rbp),%edi
call   1050 <isblank@plt>
cmp    $0x0,%rax
je     1228 <WordCount+0xd8>
movl   $0x1,-0x2c(%rbp)
jmp    1191 <WordCount+0x41>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdb9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WordCount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rsi
xor    %r15d,%r15d
xor    %edi,%edi
call   1070 <fidopen@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%al
jne    11b7 <WordCount+0x67>
xor    %r12d,%r12d
xor    %ebx,%ebx
mov    (%rsp),%rdi
call   1030 <fclose@plt>
lea    0xe6a(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r13d
xor    %ebx,%ebx
xor    %r12d,%r12d
mov    $0x1,%r14d
xor    %r15d,%r15d
jmp    1223 <WordCount+0xd3>
nopl   (%rax)
mov    %ebp,%edi
call   1050 <isblank@plt>
xor    %ecx,%ecx
xor    %r14d,%r14d
test   %rax,%rax
sete   %cl
setne  %r14b
add    %rcx,%r12
xor    %eax,%eax
cmp    $0xa,%bpl
sete   %al
cmove  %r13d,%r14d
add    %rax,%r15
mov    %ebp,%edi
call   1050 <isblank@plt>
test   %rax,%rax
cmovne %r13d,%r14d
mov    (%rsp),%rdi
call   1060 <fgetc@plt>
add    $0x1,%rbx
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%al
je     1188 <WordCount+0x38>
movsbl %al,%ebp
test   %r14d,%r14d
jne    11d0 <WordCount+0x80>
xor    %r14d,%r14d
jmp    11e9 <WordCount+0x99>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.1 = [16 x i8] c"%8zd %8zd %8zd\0A\00"
define i32 @WordCount(i64 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32*
store i64 %0, i64* %3
store i8** %1, i8*** %4
store i64 0, i64* %7
store i64 0, i64* %6
store i64 0, i64* %5
store i32 1, i32* %8
%11 = call i32* @fidopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %10
br label %12
12: ; preds = %43, %2
%13 = load i32*, i32** %10
%14 = call signext i8 @fgetc(i32* %13)
store i8 %14, i8* %9
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %44
19: ; preds = %12
%20 = load i64, i64* %5
%21 = add i64 %20, 1
store i64 %21, i64* %5
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i8, i8* %9
%26 = call i64 @isblank(i8 signext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
store i32 0, i32* %8
%29 = load i64, i64* %6
%30 = add i64 %29, 1
store i64 %30, i64* %6
br label %31
31: ; preds = %28, %24, %19
%32 = load i8, i8* %9
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i64, i64* %7
%37 = add i64 %36, 1
store i64 %37, i64* %7
store i32 1, i32* %8
br label %38
38: ; preds = %35, %31
%39 = load i8, i8* %9
%40 = call i64 @isblank(i8 signext %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
store i32 1, i32* %8
br label %43
43: ; preds = %42, %38
br label %12
44: ; preds = %12
%45 = load i32*, i32** %10
%46 = call i32 @fclose(i32* %45)
%47 = load i64, i64* %7
%48 = load i64, i64* %6
%49 = load i64, i64* %5
%50 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %47, i64 %48, i64 %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.1 = [16 x i8] c"%8zd %8zd %8zd\0A\00"
define i32 @WordCount(i64 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fidopen(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call signext i8 @fgetc(i32* %3)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %35, label %7
7: ; preds = %2, %22
%8 = phi i8 [ %32, %22 ], [ %4, %2 ]
%9 = phi i64 [ %13, %22 ], [ 0, %2 ]
%10 = phi i64 [ %24, %22 ], [ 0, %2 ]
%11 = phi i32 [ %31, %22 ], [ 1, %2 ]
%12 = phi i64 [ %27, %22 ], [ 0, %2 ]
%13 = add i64 %9, 1
%14 = icmp eq i32 %11, 0
br i1 %14, label %22, label %15
15: ; preds = %7
%16 = tail call i64 @isblank(i8 signext %8)
%17 = icmp eq i64 %16, 0
%18 = xor i1 %17, true
%19 = zext i1 %18 to i32
%20 = zext i1 %17 to i64
%21 = add i64 %10, %20
br label %22
22: ; preds = %15, %7
%23 = phi i32 [ 0, %7 ], [ %19, %15 ]
%24 = phi i64 [ %10, %7 ], [ %21, %15 ]
%25 = icmp eq i8 %8, 10
%26 = zext i1 %25 to i64
%27 = add i64 %12, %26
%28 = select i1 %25, i32 1, i32 %23
%29 = tail call i64 @isblank(i8 signext %8)
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i32 %28, i32 1
%32 = tail call signext i8 @fgetc(i32* %3)
%33 = load i8, i8* @EOF
%34 = icmp eq i8 %32, %33
br i1 %34, label %35, label %7
35: ; preds = %22, %2
%36 = phi i64 [ 0, %2 ], [ %27, %22 ]
%37 = phi i64 [ 0, %2 ], [ %24, %22 ]
%38 = phi i64 [ 0, %2 ], [ %13, %22 ]
%39 = tail call i32 @fclose(i32* %3)
%40 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %36, i64 %37, i64 %38)
ret i32 0
}