#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 */

/* Variables and functions */
int EOF;
int getchar();
int /*<<< orphan*/ printf(char *, int, int, int);
main() {
  int nc, nw, nl;
  int c, state;
  nc = nw = nl = 0;
  while ((c = getchar()) != EOF) {
    ++nc;
    if (c == '\n')
      ++nl;
    if (c == ' ' || c == '\t' || c == '\n')
      state = 0;
    else if (state == 0) {
      ++nw;
      state = 1;
    }
  }
  printf("There are %d characters, %d words and %d newlines\n", nc, nw, nl);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
je     11c7 <main+0xa7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    1179 <main+0x59>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x20,-0x14(%rbp)
je     1197 <main+0x77>
cmpl   $0x9,-0x14(%rbp)
je     1197 <main+0x77>
cmpl   $0xa,-0x14(%rbp)
jne    11a3 <main+0x83>
movl   $0x0,-0x18(%rbp)
jmp    11c2 <main+0xa2>
cmpl   $0x0,-0x18(%rbp)
jne    11bd <main+0x9d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x18(%rbp)
jmp    11c2 <main+0xa2>
jmp    1144 <main+0x24>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eac(%rip),%r15
mov    $0x0,%ebp
mov    $0x0,%ebx
cmp    (%r15),%eax
jne    116f <main+0x4f>
lea    0xeae(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0x100000600,%r13
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    11b7 <main+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
test   %r12d,%r12d
sete   %al
mov    $0x1,%esi
cmove  %esi,%r12d
add    %eax,%r14d
mov    %dl,%cl
add    %ecx,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0x1,%ebx
cmp    (%r15),%eax
je     114b <main+0x2b>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %dl
cmp    $0x20,%eax
ja     1190 <main+0x70>
mov    %eax,%eax
bt     %rax,%r13
jae    1190 <main+0x70>
xor    %r12d,%r12d
jmp    11a4 <main+0x84>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [51 x i8] c"There are %d characters, %d words and %d newlines\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %2
br label %7
7: ; preds = %36, %0
%8 = call i32 (...) @getchar()
store i32 %8, i32* %5
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %37
11: ; preds = %7
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
store i32 %13, i32* %2
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 32
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 9
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %25, %22, %19
store i32 0, i32* %6
br label %36
29: ; preds = %25
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
store i32 1, i32* %6
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35, %28
br label %7
37: ; preds = %7
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39, i32 %40)
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [51 x i8] c"There are %d characters, %d words and %d newlines\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %25, label %4
4: ; preds = %0, %19
%5 = phi i32 [ %22, %19 ], [ %1, %0 ]
%6 = phi i32 [ %21, %19 ], [ undef, %0 ]
%7 = phi i32 [ %10, %19 ], [ 0, %0 ]
%8 = phi i32 [ %13, %19 ], [ 0, %0 ]
%9 = phi i32 [ %20, %19 ], [ 0, %0 ]
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %5, 10
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %8, %12
switch i32 %5, label %14 [
i32 32, label %19
i32 10, label %19
i32 9, label %19
]
14: ; preds = %4
%15 = icmp eq i32 %6, 0
%16 = zext i1 %15 to i32
%17 = add nsw i32 %9, %16
%18 = select i1 %15, i32 1, i32 %6
br label %19
19: ; preds = %14, %4, %4, %4
%20 = phi i32 [ %9, %4 ], [ %17, %14 ], [ %9, %4 ], [ %9, %4 ]
%21 = phi i32 [ 0, %4 ], [ %18, %14 ], [ 0, %4 ], [ 0, %4 ]
%22 = tail call i32 (...) @getchar()
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %4
25: ; preds = %19, %0
%26 = phi i32 [ 0, %0 ], [ %20, %19 ]
%27 = phi i32 [ 0, %0 ], [ %13, %19 ]
%28 = phi i32 [ 0, %0 ], [ %10, %19 ]
%29 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %26, i32 %27)
ret i32 0
}