#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 */
char getchar();
scalar_t__ isspace(char);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char c;
  char prev;
  long n_chars = 0L;
  int n_lines = 0, n_words = 0, p_lines = 0;
  bool inword = false;
  printf("Enter text to be analyzed(| to terminate):\n");
  prev = '\n';
  while ((c = getchar()) != '|') {
    n_chars++;
    if (c == '\n') {
      n_lines++;
    }
    if (!isspace(c) && !inword) {
      inword = true;
      n_words++;
    }
    if (isspace(c) && inword) {
      inword = false;
    }
    prev = c;
  }
  if (prev != '\n') {
    p_lines = 1;
  }
  printf("characters = %ld, words = %d,lines = %d\n", n_chars, n_words,
         n_lines);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0xa,-0x6(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0x7c,%eax
je     1209 <main+0xd9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    11ad <main+0x7d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsbl -0x5(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
jne    11da <main+0xaa>
cmpl   $0x0,-0x20(%rbp)
jne    11da <main+0xaa>
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x5(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11fe <main+0xce>
cmpl   $0x0,-0x20(%rbp)
je     11fe <main+0xce>
movl   $0x0,-0x20(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x6(%rbp)
jmp    1175 <main+0x45>
movsbl -0x6(%rbp),%eax
cmp    $0xa,%eax
je     121d <main+0xed>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xdfe(%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   %r13
push   %r12
push   %rbx
push   %rax
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x7c,%al
jne    116c <main+0x2c>
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    11dd <main+0x9d>
mov    $0x1,%r13d
xor    %r12d,%r12d
xor    %r15d,%r15d
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   (%rax)
add    $0x1,%rbx
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%r14d
movsbl %al,%ebp
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %rax,%rax
setne  %al
test   %r12d,%r12d
setne  %cl
or     %al,%cl
mov    %ecx,%eax
xor    $0x1,%al
movzbl %al,%eax
add    %eax,%r15d
test   %cl,%cl
cmove  %r13d,%r12d
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %r12d,%r12d
mov    %r12d,%ecx
mov    $0x0,%edx
cmovne %edx,%ecx
test   %rax,%rax
cmovne %ecx,%r12d
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x7c,%al
jne    1180 <main+0x40>
lea    0xe1c(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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"characters = %ld, words = %d,lines = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8 10, i8* %3
br label %10
10: ; preds = %41, %0
%11 = call signext i8 (...) @getchar()
store i8 %11, i8* %2
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 124
br i1 %13, label %14, label %43
14: ; preds = %10
%15 = load i64, i64* %4
%16 = add nsw i64 %15, 1
store i64 %16, i64* %4
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %23
23: ; preds = %20, %14
%24 = load i8, i8* %2
%25 = call i64 @isspace(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %23
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
store i32 1, i32* %8
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %33
33: ; preds = %30, %27, %23
%34 = load i8, i8* %2
%35 = call i64 @isspace(i8 signext %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 0, i32* %8
br label %41
41: ; preds = %40, %37, %33
%42 = load i8, i8* %2
store i8 %42, i8* %3
br label %10
43: ; preds = %10
%44 = load i8, i8* %3
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 1, i32* %7
br label %48
48: ; preds = %47, %43
%49 = load i64, i64* %4
%50 = load i32, i32* %6
%51 = load i32, i32* %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %49, i32 %50, i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [41 x i8] c"characters = %ld, words = %d,lines = %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))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 124
br i1 %3, label %29, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %27, %4 ], [ %2, %0 ]
%6 = phi i32 [ %26, %4 ], [ 0, %0 ]
%7 = phi i32 [ %20, %4 ], [ 0, %0 ]
%8 = phi i32 [ %13, %4 ], [ 0, %0 ]
%9 = phi i64 [ %10, %4 ], [ 0, %0 ]
%10 = add nuw nsw i64 %9, 1
%11 = icmp eq i8 %5, 10
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %8, %12
%14 = tail call i64 @isspace(i8 signext %5)
%15 = icmp ne i64 %14, 0
%16 = icmp ne i32 %6, 0
%17 = select i1 %15, i1 true, i1 %16
%18 = xor i1 %17, true
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %7, %19
%21 = select i1 %17, i32 %6, i32 1
%22 = tail call i64 @isspace(i8 signext %5)
%23 = icmp ne i64 %22, 0
%24 = icmp ne i32 %21, 0
%25 = select i1 %23, i1 %24, i1 false
%26 = select i1 %25, i32 0, i32 %21
%27 = tail call signext i8 (...) @getchar()
%28 = icmp eq i8 %27, 124
br i1 %28, label %29, label %4
29: ; preds = %4, %0
%30 = phi i64 [ 0, %0 ], [ %10, %4 ]
%31 = phi i32 [ 0, %0 ], [ %13, %4 ]
%32 = phi i32 [ 0, %0 ], [ %20, %4 ]
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %30, i32 %32, i32 %31)
ret i32 0
}