#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 main(void) {
  int c;
  int n_spaces = 0;
  int n_lines = 0;
  int n_characters = 0;
  printf("Enter text to be analyzed"
         "(# to terminate):\n");
  while ((c = getchar()) != '#') {
    switch (c) {
    case ' ':
      n_spaces++;
      break;
    case '\n':
      n_lines++;
      break;
    default:
      n_characters++;
    }
  }
  printf("spaces = %d, lines = %d,"
         "characters = %d\n",
         n_spaces, n_lines, n_characters);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x23,%eax
je     11b4 <main+0x94>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xa,%eax
je     1198 <main+0x78>
jmp    1179 <main+0x59>
mov    -0x18(%rbp),%eax
sub    $0x20,%eax
jne    11a6 <main+0x86>
jmp    118a <main+0x6a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11af <main+0x8f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11af <main+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <main+0x32>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe68(%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   %r14
push   %rbx
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     116b <main+0x3b>
cmp    $0x23,%eax
je     1176 <main+0x46>
cmp    $0x20,%eax
je     1170 <main+0x40>
add    $0x1,%ebp
jmp    1150 <main+0x20>
add    $0x1,%ebx
jmp    1150 <main+0x20>
add    $0x1,%r14d
jmp    1150 <main+0x20>
lea    0xe83(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Enter text to be analyzed(# to terminate):\0A\00"
@.str.1 = [41 x i8] c"spaces = %d, lines = %d,characters = %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* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %21, %0
%8 = call i32 (...) @getchar()
store i32 %8, i32* %2
%9 = icmp ne i32 %8, 35
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32, i32* %2
switch i32 %11, label %18 [
i32 32, label %12
i32 10, label %15
]
12: ; preds = %10
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %21
15: ; preds = %10
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %21
18: ; preds = %10
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %21
21: ; preds = %18, %15, %12
br label %7
22: ; preds = %7
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24, i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [41 x i8] c"spaces = %d, lines = %d,characters = %d\0A\00"
@str = [43 x i8] c"Enter text to be analyzed(# to terminate):\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %12, %0
%3 = phi i32 [ %13, %12 ], [ 0, %0 ]
%4 = phi i32 [ %7, %12 ], [ 0, %0 ]
%5 = phi i32 [ %10, %12 ], [ 0, %0 ]
br label %6
6: ; preds = %2, %14
%7 = phi i32 [ %4, %2 ], [ %15, %14 ]
%8 = phi i32 [ %5, %2 ], [ %10, %14 ]
br label %9
9: ; preds = %6, %16
%10 = phi i32 [ %17, %16 ], [ %8, %6 ]
%11 = tail call i32 (...) @getchar()
switch i32 %11, label %16 [
i32 35, label %18
i32 32, label %12
i32 10, label %14
]
12: ; preds = %9
%13 = add nuw nsw i32 %3, 1
br label %2
14: ; preds = %9
%15 = add nsw i32 %7, 1
br label %6
16: ; preds = %9
%17 = add nsw i32 %10, 1
br label %9
18: ; preds = %9
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %7, i32 %10)
ret i32 0
}