#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(int argc, char const *argv[]) {
  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("characters = %ld, words = %d, lines = %d,", n_chars, n_words,
         n_lines);
  printf("partial lines = %d\n", p_lines);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0xa,-0x12(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x7c,%eax
je     1210 <main+0xe0>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    11b4 <main+0x84>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x11(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
jne    11e1 <main+0xb1>
cmpl   $0x0,-0x30(%rbp)
jne    11e1 <main+0xb1>
movl   $0x1,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
movsbl -0x11(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1205 <main+0xd5>
cmpl   $0x0,-0x30(%rbp)
je     1205 <main+0xd5>
movl   $0x0,-0x30(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x12(%rbp)
jmp    117c <main+0x4c>
movsbl -0x12(%rbp),%eax
cmp    $0xa,%eax
je     1224 <main+0xf4>
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeec(%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 = [45 x i8] c"Enter text to be analyzed(| to terminate): \0A\00"
@.str.1 = [42 x i8] c"characters = %ld, words = %d, lines = %d,\00"
@.str.2 = [20 x i8] c"partial lines = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i8 10, i8* %7
br label %14
14: ; preds = %45, %2
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 124
br i1 %17, label %18, label %47
18: ; preds = %14
%19 = load i64, i64* %8
%20 = add nsw i64 %19, 1
store i64 %20, i64* %8
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
br label %27
27: ; preds = %24, %18
%28 = load i8, i8* %6
%29 = call i64 @isspace(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %27
%32 = load i32, i32* %12
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
store i32 1, i32* %12
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %37
37: ; preds = %34, %31, %27
%38 = load i8, i8* %6
%39 = call i64 @isspace(i8 signext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %12
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 0, i32* %12
br label %45
45: ; preds = %44, %41, %37
%46 = load i8, i8* %6
store i8 %46, i8* %7
br label %14
47: ; preds = %14
%48 = load i8, i8* %7
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 10
br i1 %50, label %51, label %52
51: ; preds = %47
store i32 1, i32* %11
br label %52
52: ; preds = %51, %47
%53 = load i64, i64* %8
%54 = load i32, i32* %10
%55 = load i32, i32* %9
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %53, i32 %54, i32 %55)
%57 = load i32, i32* %11
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %57)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [42 x i8] c"characters = %ld, words = %d, lines = %d,\00"
@.str.2 = [20 x i8] c"partial lines = %d\0A\00"
@str = [44 x i8] c"Enter text to be analyzed(| to terminate): \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 124
br i1 %5, label %34, label %6
6: ; preds = %2, %6
%7 = phi i8 [ %29, %6 ], [ %4, %2 ]
%8 = phi i32 [ %28, %6 ], [ 0, %2 ]
%9 = phi i32 [ %22, %6 ], [ 0, %2 ]
%10 = phi i32 [ %15, %6 ], [ 0, %2 ]
%11 = phi i64 [ %12, %6 ], [ 0, %2 ]
%12 = add nuw nsw i64 %11, 1
%13 = icmp eq i8 %7, 10
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %10, %14
%16 = tail call i64 @isspace(i8 signext %7)
%17 = icmp ne i64 %16, 0
%18 = icmp ne i32 %8, 0
%19 = select i1 %17, i1 true, i1 %18
%20 = xor i1 %19, true
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %9, %21
%23 = select i1 %19, i32 %8, i32 1
%24 = tail call i64 @isspace(i8 signext %7)
%25 = icmp ne i64 %24, 0
%26 = icmp ne i32 %23, 0
%27 = select i1 %25, i1 %26, i1 false
%28 = select i1 %27, i32 0, i32 %23
%29 = tail call signext i8 (...) @getchar()
%30 = icmp eq i8 %29, 124
br i1 %30, label %31, label %6
31: ; preds = %6
%32 = icmp ne i8 %7, 10
%33 = zext i1 %32 to i32
br label %34
34: ; preds = %31, %2
%35 = phi i32 [ %33, %31 ], [ 0, %2 ]
%36 = phi i64 [ %12, %31 ], [ 0, %2 ]
%37 = phi i32 [ %15, %31 ], [ 0, %2 ]
%38 = phi i32 [ %22, %31 ], [ 0, %2 ]
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %36, i32 %38, i32 %37)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %35)
ret i32 0
}