#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 getchar();
int /*<<< orphan*/ printf(char *, int, ...);
wc_1(void) {
  int c, nl, nw, nc, state;
  nl = nw = nc = 0;
  state = 0;
  printf("Say something %c\n", 42);
  while ((c = getchar()) != '~') {
    ++nc;
    if (c == '\n')
      ++nl;
    if (c == ' ' || c == '\t' || c == '\n')
      state = 0;
    else if (state == 0) {
      state == 1;
      ++nw;
    }
  }
  printf("You had %d words with %d characters, all on %d lines", nw, nc, nl);
}


x86 assembly (clang, -O0):
<wc_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x2a,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x7e,%eax
je     11cd <wc_1+0xad>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x8(%rbp)
jne    1186 <wc_1+0x66>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x20,-0x8(%rbp)
je     11a4 <wc_1+0x84>
cmpl   $0x9,-0x8(%rbp)
je     11a4 <wc_1+0x84>
cmpl   $0xa,-0x8(%rbp)
jne    11b0 <wc_1+0x90>
movl   $0x0,-0x18(%rbp)
jmp    11c8 <wc_1+0xa8>
cmpl   $0x0,-0x18(%rbp)
jne    11c3 <wc_1+0xa3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c8 <wc_1+0xa8>
jmp    1157 <wc_1+0x37>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wc_1>:
push   %rbp
push   %r14
push   %rbx
lea    0xed5(%rip),%rdi
xor    %r14d,%r14d
mov    $0x2a,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    $0x0,%ebx
mov    $0x0,%ebp
cmp    $0x7e,%eax
je     1190 <wc_1+0x70>
xor    %ebp,%ebp
xor    %ebx,%ebx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%r14d
cmp    $0x20,%eax
setne  %cl
add    $0xfffffff5,%eax
cmp    $0xfffffffe,%eax
setb   %al
and    %cl,%al
movzbl %al,%eax
add    %eax,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x7e,%eax
jne    1160 <wc_1+0x40>
lea    0xe7b(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Say something %c\0A\00"
@.str.1 = [53 x i8] c"You had %d words with %d characters, all on %d lines\00"
define i32 @wc_1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %6
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 42)
br label %8
8: ; preds = %39, %0
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = icmp ne i32 %9, 126
br i1 %10, label %11, label %40
11: ; preds = %8
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 32
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 9
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %2
%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 %39
29: ; preds = %25
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 1
%35 = zext i1 %34 to i32
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %38
38: ; preds = %32, %29
br label %39
39: ; preds = %38, %28
br label %8
40: ; preds = %8
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = load i32, i32* %3
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %41, i32 %42, i32 %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [18 x i8] c"Say something %c\0A\00"
@.str.1 = [53 x i8] c"You had %d words with %d characters, all on %d lines\00"
define i32 @wc_1() {
%1 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 42)
%2 = tail call i32 (...) @getchar()
%3 = icmp eq i32 %2, 126
br i1 %3, label %21, label %4
4: ; preds = %0, %4
%5 = phi i32 [ %19, %4 ], [ %2, %0 ]
%6 = phi i32 [ %9, %4 ], [ 0, %0 ]
%7 = phi i32 [ %18, %4 ], [ 0, %0 ]
%8 = phi i32 [ %12, %4 ], [ 0, %0 ]
%9 = add nuw nsw i32 %6, 1
%10 = icmp eq i32 %5, 10
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %8, %11
%13 = icmp ne i32 %5, 32
%14 = add i32 %5, -11
%15 = icmp ult i32 %14, -2
%16 = and i1 %13, %15
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %7, %17
%19 = tail call i32 (...) @getchar()
%20 = icmp eq i32 %19, 126
br i1 %20, label %21, label %4
21: ; preds = %4, %0
%22 = phi i32 [ 0, %0 ], [ %12, %4 ]
%23 = phi i32 [ 0, %0 ], [ %18, %4 ]
%24 = phi i32 [ 0, %0 ], [ %9, %4 ]
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24, i32 %22)
ret i32 undef
}