#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 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;
    }
  }
  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   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%eax
je     11e1 <main+0xc1>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    1190 <main+0x70>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x20,-0x14(%rbp)
je     11ae <main+0x8e>
cmpl   $0xa,-0x14(%rbp)
je     11ae <main+0x8e>
cmpl   $0x9,-0x14(%rbp)
jne    11ba <main+0x9a>
movl   $0x0,-0x18(%rbp)
jmp    11dc <main+0xbc>
cmpl   $0x0,-0x18(%rbp)
jne    11d7 <main+0xb7>
movl   $0x1,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11dc <main+0xbc>
jmp    1155 <main+0x35>
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe0c(%rip),%rdi
call   1030 <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   1040 <getchar@plt>
mov    0x2eaf(%rip),%r12
cmp    (%r12),%eax
jne    116d <main+0x4d>
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %ebx,%ebx
lea    0xeb2(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
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    %r15d,%r15d
xor    %r14d,%r14d
xor    %edx,%edx
jmp    11b5 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x1,%edx
adc    $0x0,%r14
mov    $0x1,%ebp
mov    %sil,%cl
add    %rcx,%r15
xor    %eax,%eax
call   1040 <getchar@plt>
add    $0x1,%rbx
mov    %ebp,%edx
cmp    (%r12),%eax
je     1147 <main+0x27>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %sil
cmp    $0x20,%eax
ja     1190 <main+0x70>
xor    %ebp,%ebp
mov    %eax,%eax
bt     %rax,%r13
jb     119c <main+0x7c>
jmp    1190 <main+0x70>

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 = %40, %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 %41
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
br label %11
41: ; preds = %11
%42 = load i64, i64* %10
%43 = load i64, i64* %8
%44 = load i64, i64* %9
%45 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %42, i64 %43, i64 %44)
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 %26, label %6
6: ; preds = %2, %20
%7 = phi i32 [ %23, %20 ], [ %3, %2 ]
%8 = phi i64 [ %12, %20 ], [ 0, %2 ]
%9 = phi i64 [ %15, %20 ], [ 0, %2 ]
%10 = phi i64 [ %22, %20 ], [ 0, %2 ]
%11 = phi i32 [ %21, %20 ], [ 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 %20
i32 10, label %20
i32 9, label %20
]
16: ; preds = %6
%17 = icmp eq i32 %11, 0
%18 = zext i1 %17 to i64
%19 = add nsw i64 %10, %18
br label %20
20: ; preds = %16, %6, %6, %6
%21 = phi i32 [ 0, %6 ], [ 1, %16 ], [ 0, %6 ], [ 0, %6 ]
%22 = phi i64 [ %10, %6 ], [ %19, %16 ], [ %10, %6 ], [ %10, %6 ]
%23 = tail call i32 (...) @getchar()
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %6
26: ; preds = %20, %2
%27 = phi i64 [ 0, %2 ], [ %22, %20 ]
%28 = phi i64 [ 0, %2 ], [ %15, %20 ]
%29 = phi i64 [ 0, %2 ], [ %12, %20 ]
%30 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i64 %29, i64 %27, i64 %28)
ret i32 0
}