#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 analyze (| to terminate):\n");
  prev = '\n';
  while ((c = getchar()) != '|') {
    n_chars++;
    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    $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     11f3 <main+0xc3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x5(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
jne    11c4 <main+0x94>
cmpl   $0x0,-0x20(%rbp)
jne    11c4 <main+0x94>
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     11e8 <main+0xb8>
cmpl   $0x0,-0x20(%rbp)
je     11e8 <main+0xb8>
movl   $0x0,-0x20(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x6(%rbp)
jmp    1175 <main+0x45>
movsbl -0x6(%rbp),%eax
cmp    $0xa,%eax
je     1207 <main+0xd7>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe2b(%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    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x7c,%al
jne    116c <main+0x2c>
xor    %r13d,%r13d
xor    %r15d,%r15d
jmp    11db <main+0x9b>
mov    $0x1,%r12d
xor    %ebx,%ebx
xor    %r15d,%r15d
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %eax,%r14d
add    $0x1,%r13
movsbl %al,%ebp
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %rax,%rax
setne  %al
test   %ebx,%ebx
setne  %cl
or     %al,%cl
mov    %ecx,%eax
xor    $0x1,%al
movzbl %al,%eax
add    %eax,%r15d
test   %cl,%cl
cmove  %r12d,%ebx
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %ebx,%ebx
mov    %ebx,%ecx
mov    $0x0,%edx
cmovne %edx,%ecx
test   %rax,%rax
cmovne %ecx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x7c,%al
jne    1180 <main+0x40>
xor    %ebx,%ebx
cmp    $0xa,%r14b
setne  %bl
lea    0xe1e(%rip),%rdi
mov    %r13,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe33(%rip),%rdi
mov    %ebx,%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 = [41 x i8] c"Enter text to analyze (| to terminate):\0A\00"
@.str.1 = [43 x i8] c"characters = %ld, words = %d, lines = %d, \00"
@.str.2 = [20 x i8] c"partial 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 ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i8 10, i8* %3
br label %10
10: ; preds = %34, %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 %36
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 = call i64 @isspace(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %14
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
store i32 1, i32* %8
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %26
26: ; preds = %23, %20, %14
%27 = load i8, i8* %2
%28 = call i64 @isspace(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 0, i32* %8
br label %34
34: ; preds = %33, %30, %26
%35 = load i8, i8* %2
store i8 %35, i8* %3
br label %10
36: ; preds = %10
%37 = load i8, i8* %3
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 10
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 1, i32* %7
br label %41
41: ; preds = %40, %36
%42 = load i64, i64* %4
%43 = load i32, i32* %6
%44 = load i32, i32* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %42, i32 %43, i32 %44)
%46 = load i32, i32* %7
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %46)
ret i32 0
}

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