#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;
  int n_words = 0;
  int 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("charaters = %ld, words = %d, lines = %d, ", n_chars, n_words,
         n_lines);
  printf("partical lines = %d\n", p_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    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe19(%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    0xeed(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x7c,%al
jne    1172 <main+0x32>
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    11f3 <main+0xb3>
xor    %r15d,%r15d
xor    %r12d,%r12d
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   (%rax)
mov    %eax,%r13d
add    $0x1,%rbx
xor    %eax,%eax
cmp    $0xa,%r13b
sete   %al
add    %eax,%r14d
movsbl %r13b,%ebp
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %rax,%rax
setne  %al
test   %r15d,%r15d
setne  %cl
or     %al,%cl
mov    %ecx,%eax
xor    $0x1,%al
movzbl %al,%eax
add    %eax,%r12d
test   %cl,%cl
mov    $0x1,%eax
cmove  %eax,%r15d
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %r15d,%r15d
mov    %r15d,%ecx
mov    $0x0,%edx
cmovne %edx,%ecx
test   %rax,%rax
cmovne %ecx,%r15d
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x7c,%al
jne    1180 <main+0x40>
xor    %r15d,%r15d
cmp    $0xa,%r13b
setne  %r15b
lea    0xe06(%rip),%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe19(%rip),%rdi
mov    %r15d,%esi
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 = [46 x i8] c"Enter text to be analyzed (| to terminate): \0A\00"
@.str.1 = [42 x i8] c"charaters = %ld, words = %d, lines = %d, \00"
@.str.2 = [21 x i8] c"partical 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 ([46 x i8], [46 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 ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %49, i32 %50, i32 %51)
%53 = load i32, i32* %7
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %53)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [42 x i8] c"charaters = %ld, words = %d, lines = %d, \00"
@.str.2 = [21 x i8] c"partical lines = %d\0A\00"
@str = [45 x i8] c"Enter text to be analyzed (| to terminate): \00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 124
br i1 %3, label %32, 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
%30 = icmp ne i8 %5, 10
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %29, %0
%33 = phi i32 [ %31, %29 ], [ 0, %0 ]
%34 = phi i64 [ %10, %29 ], [ 0, %0 ]
%35 = phi i32 [ %13, %29 ], [ 0, %0 ]
%36 = phi i32 [ %20, %29 ], [ 0, %0 ]
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %34, i32 %36, i32 %35)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %33)
ret i32 0
}