#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 *, ...);
main() {
  int c, blanks, tabs, newlines;
  int done = 0;
  int lastchar = 0;
  blanks = 0;
  tabs = 0;
  newlines = 0;
  while (done == 0) {
    c = getchar();
    if (c == ' ') {
      ++blanks;
    }
    if (c == '\t') {
      ++tabs;
    }
    if (c == '\n') {
      ++newlines;
    }
    if (c == EOF) {
      if (lastchar != '\n') {
        ++newlines;
      }
      done = 1;
    }
    lastchar = c;
  }
  printf("Counting result:\n");
  printf("blanks: %d\n", blanks);
  printf("tabs: %d\n", tabs);
  printf("newlines: %d\n", newlines);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11d6 <main+0xb6>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jne    1179 <main+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x9,-0x8(%rbp)
jne    118c <main+0x6c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x8(%rbp)
jne    119f <main+0x7f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%eax
jne    11cb <main+0xab>
cmpl   $0xa,-0x1c(%rbp)
je     11c4 <main+0xa4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1152 <main+0x32>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
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   %r12
push   %rbx
mov    0x2ea9(%rip),%r15
xor    %r12d,%r12d
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x20,%eax
sete   %cl
add    %ecx,%ebp
xor    %ecx,%ecx
cmp    $0x9,%eax
sete   %cl
add    %ecx,%r14d
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ebx,%ecx
mov    (%r15),%edx
cmp    %edx,%eax
sete   %sil
cmp    $0xa,%r12d
setne  %bl
and    %sil,%bl
movzbl %bl,%ebx
add    %ecx,%ebx
mov    %eax,%r12d
cmp    %edx,%eax
jne    1150 <main+0x20>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
lea    0xe58(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe54(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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