#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 *, long, long, long);
int /*<<< orphan*/ putchar(char);
int main(int argc, char *argv[]) {
  int ch, state;
  long words, lines, characters;
  state = 0;
  words = lines = characters = 0;
  while ((ch = getchar()) != EOF) {
    ++characters;
    if (ch == '\n')
      ++lines;
    if (ch == ' ' || ch == '\n' || ch == '\t')
      state = 0;
    else if (state == 0) {
      state = 1;
      ++words;
    }
    if (state == 1)
      putchar(ch);
    else if (state == 0)
      putchar('\n');
  }
  printf("characters = %ld, words = %ld, lines = %ld\n", characters, words,
         lines);
  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,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%eax
je     1224 <main+0xf4>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    11a0 <main+0x70>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x20,-0x14(%rbp)
je     11be <main+0x8e>
cmpl   $0xa,-0x14(%rbp)
je     11be <main+0x8e>
cmpl   $0x9,-0x14(%rbp)
jne    11ca <main+0x9a>
movl   $0x0,-0x18(%rbp)
jmp    11ec <main+0xbc>
cmpl   $0x0,-0x18(%rbp)
jne    11e7 <main+0xb7>
movl   $0x1,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ec <main+0xbc>
cmpl   $0x1,-0x18(%rbp)
jne    1206 <main+0xd6>
mov    -0x14(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    121f <main+0xef>
cmpl   $0x0,-0x18(%rbp)
jne    121a <main+0xea>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    121f <main+0xef>
jmp    1165 <main+0x35>
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdc9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%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
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e9f(%rip),%r12
cmp    (%r12),%eax
jne    117d <main+0x4d>
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %ebx,%ebx
lea    0xea2(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <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    %r15d,%r15d
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    11ca <main+0x9a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x1,%ebp
adc    $0x0,%r14
mov    $0x1,%ebp
mov    %dl,%cl
add    %rcx,%r15
movsbl %al,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x1,%rbx
cmp    (%r12),%eax
je     1157 <main+0x27>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %dl
cmp    $0x20,%eax
ja     11a0 <main+0x70>
mov    %eax,%esi
bt     %rsi,%r13
jae    11a0 <main+0x70>
xor    %ebp,%ebp
mov    $0xa,%al
jmp    11ac <main+0x7c>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [44 x i8] c"characters = %ld, words = %ld, lines = %ld\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 i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i64 0, i64* %10
store i64 0, i64* %9
store i64 0, i64* %8
br label %11
11: ; preds = %53, %2
%12 = call i32 (...) @getchar()
store i32 %12, i32* %6
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %54
15: ; preds = %11
%16 = load i64, i64* %10
%17 = add nsw i64 %16, 1
store i64 %17, i64* %10
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i64, i64* %9
%22 = add nsw i64 %21, 1
store i64 %22, i64* %9
br label %23
23: ; preds = %20, %15
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 32
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, 10
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 9
br i1 %31, label %32, label %33
32: ; preds = %29, %26, %23
store i32 0, i32* %7
br label %40
33: ; preds = %29
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
store i32 1, i32* %7
%37 = load i64, i64* %8
%38 = add nsw i64 %37, 1
store i64 %38, i64* %8
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39, %32
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* %6
%45 = trunc i32 %44 to i8
%46 = call i32 @putchar(i8 signext %45)
br label %53
47: ; preds = %40
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 @putchar(i8 signext 10)
br label %52
52: ; preds = %50, %47
br label %53
53: ; preds = %52, %43
br label %11
54: ; preds = %11
%55 = load i64, i64* %10
%56 = load i64, i64* %8
%57 = load i64, i64* %9
%58 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %55, i64 %56, i64 %57)
ret i32 0
}

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