#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 main() {
  int c, num_tabs, num_blanks, num_newlines;
  num_tabs = num_blanks = num_newlines = 0;
  printf("Enter text. Press CTRL-D when finished\n> ");
  while ((c = getchar()) != EOF) {
    if (c == '\n')
      printf("> ");
    switch (c) {
    case '\t':
      num_tabs++;
      break;
    case ' ':
      num_blanks++;
      break;
    case '\n':
      num_newlines++;
      break;
    }
  }
  printf("EOF sent\n");
  printf("num_tabs: %d\n", num_tabs);
  printf("num_blanks: %d\n", num_blanks);
  printf("num_newlines: %d\n", num_newlines);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
je     11e3 <main+0xc3>
cmpl   $0xa,-0x8(%rbp)
jne    1183 <main+0x63>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x9,%eax
je     11b9 <main+0x99>
jmp    1197 <main+0x77>
mov    -0x18(%rbp),%eax
sub    $0xa,%eax
je     11d5 <main+0xb5>
jmp    11a8 <main+0x88>
mov    -0x18(%rbp),%eax
sub    $0x20,%eax
je     11c7 <main+0xa7>
jmp    11de <main+0xbe>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11de <main+0xbe>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11de <main+0xbe>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <main+0x32>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xec1(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e91(%rip),%rbp
mov    $0x0,%ebx
mov    $0x0,%r14d
cmp    0x0(%rbp),%eax
jne    11b0 <main+0x80>
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe70(%rip),%r15
xor    %r14d,%r14d
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    11df <main+0xaf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    0x0(%rbp),%eax
je     1167 <main+0x37>
cmp    $0x9,%eax
je     1200 <main+0xd0>
cmp    $0x20,%eax
je     11d0 <main+0xa0>
cmp    $0xa,%eax
jne    11d3 <main+0xa3>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14d
jmp    11d3 <main+0xa3>
xchg   %ax,%ax
add    $0x1,%r12d
jmp    11d3 <main+0xa3>

LLVM IR (-O0):
@.str = [42 x i8] c"Enter text. Press CTRL-D when finished\0A> \00"
@EOF = global i32 0
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [10 x i8] c"EOF sent\0A\00"
@.str.3 = [14 x i8] c"num_tabs: %d\0A\00"
@.str.4 = [16 x i8] c"num_blanks: %d\0A\00"
@.str.5 = [18 x i8] c"num_newlines: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %27, %0
%8 = call i32 (...) @getchar()
store i32 %8, i32* %2
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %2
switch i32 %17, label %27 [
i32 9, label %18
i32 32, label %21
i32 10, label %24
]
18: ; preds = %16
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %27
21: ; preds = %16
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %27
24: ; preds = %16
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %27
27: ; preds = %16, %24, %21, %18
br label %7
28: ; preds = %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"Enter text. Press CTRL-D when finished\0A> \00"
@EOF = global i32 0
@.str.1 = [3 x i8] c"> \00"
@.str.3 = [14 x i8] c"num_tabs: %d\0A\00"
@.str.4 = [16 x i8] c"num_blanks: %d\0A\00"
@.str.5 = [18 x i8] c"num_newlines: %d\0A\00"
@str = [9 x i8] c"EOF sent\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %24, label %5
5: ; preds = %0, %17
%6 = phi i32 [ %21, %17 ], [ %2, %0 ]
%7 = phi i32 [ %20, %17 ], [ 0, %0 ]
%8 = phi i32 [ %19, %17 ], [ 0, %0 ]
%9 = phi i32 [ %18, %17 ], [ 0, %0 ]
switch i32 %6, label %17 [
i32 10, label %10
i32 9, label %13
i32 32, label %15
]
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = add nsw i32 %7, 1
br label %17
13: ; preds = %5
%14 = add nsw i32 %9, 1
br label %17
15: ; preds = %5
%16 = add nsw i32 %8, 1
br label %17
17: ; preds = %5, %10, %15, %13
%18 = phi i32 [ %9, %10 ], [ %9, %15 ], [ %14, %13 ], [ %9, %5 ]
%19 = phi i32 [ %8, %10 ], [ %16, %15 ], [ %8, %13 ], [ %8, %5 ]
%20 = phi i32 [ %12, %10 ], [ %7, %15 ], [ %7, %13 ], [ %7, %5 ]
%21 = tail call i32 (...) @getchar()
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %5
24: ; preds = %17, %0
%25 = phi i32 [ 0, %0 ], [ %18, %17 ]
%26 = phi i32 [ 0, %0 ], [ %19, %17 ]
%27 = phi i32 [ 0, %0 ], [ %20, %17 ]
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %27)
ret i32 0
}