#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 character, character_count, newline_count, word_count, position;
  position = 0;
  character_count = newline_count = word_count = 0;
  printf("Input text below to count what's the amount of "
         "newlines, words and characters in it:\n");
  while ((character = getchar()) != EOF) {
    ++character_count;
    if (character == '\n') {
      ++newline_count;
    }
    if (character == '\n' || character == '\t' || character == ' ') {
      position = 0;
    } else if (position == 0) {
      ++word_count;
      position == 1;
    }
  }
  printf(
      "Amount of characters: %d\nAmount of newlines: %d\nAmount of words: %d\n",
      character_count, newline_count, word_count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
je     11d5 <main+0xb5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0x8(%rbp)
jne    118e <main+0x6e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x8(%rbp)
je     11ac <main+0x8c>
cmpl   $0x9,-0x8(%rbp)
je     11ac <main+0x8c>
cmpl   $0x20,-0x8(%rbp)
jne    11b8 <main+0x98>
movl   $0x0,-0x18(%rbp)
jmp    11d0 <main+0xb0>
cmpl   $0x0,-0x18(%rbp)
jne    11cb <main+0xab>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <main+0xb0>
jmp    1159 <main+0x39>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe71(%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   %rbx
push   %rax
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e94(%rip),%r15
mov    $0x0,%ebx
mov    $0x0,%ebp
cmp    (%r15),%eax
je     11a0 <main+0x70>
xor    %ebp,%ebp
xor    %ebx,%ebx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14d
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebx
lea    -0xb(%rax),%ecx
cmp    $0xfffffffe,%ecx
setb   %cl
cmp    $0x20,%eax
setne  %al
and    %cl,%al
movzbl %al,%eax
add    %eax,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%eax
jne    1170 <main+0x40>
lea    0xe59(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [86 x i8] c"Input text below to count what's the amount of newlines, words and characters in it:\0A\00"
@EOF = global i32 0
@.str.1 = [69 x i8] c"Amount of characters: %d\0AAmount of newlines: %d\0AAmount of words: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %40, %0
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %20
20: ; preds = %17, %12
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 10
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 9
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 32
br i1 %28, label %29, label %30
29: ; preds = %26, %23, %20
store i32 0, i32* %6
br label %40
30: ; preds = %26
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 1
%38 = zext i1 %37 to i32
br label %39
39: ; preds = %33, %30
br label %40
40: ; preds = %39, %29
br label %8
41: ; preds = %8
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43, i32 %44)
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [69 x i8] c"Amount of characters: %d\0AAmount of newlines: %d\0AAmount of words: %d\0A\00"
@str = [85 x i8] c"Input text below to count what's the amount of newlines, words and characters in it:\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 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 %23, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %20, %5 ], [ %2, %0 ]
%7 = phi i32 [ %19, %5 ], [ 0, %0 ]
%8 = phi i32 [ %13, %5 ], [ 0, %0 ]
%9 = phi i32 [ %10, %5 ], [ 0, %0 ]
%10 = add nuw nsw i32 %9, 1
%11 = icmp eq i32 %6, 10
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %8, %12
%14 = add i32 %6, -11
%15 = icmp ult i32 %14, -2
%16 = icmp ne i32 %6, 32
%17 = and i1 %16, %15
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %7, %18
%20 = tail call i32 (...) @getchar()
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %5
23: ; preds = %5, %0
%24 = phi i32 [ 0, %0 ], [ %10, %5 ]
%25 = phi i32 [ 0, %0 ], [ %13, %5 ]
%26 = phi i32 [ 0, %0 ], [ %19, %5 ]
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
ret i32 0
}