#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();
scalar_t__ is_word_separator(int);
int /*<<< orphan*/ printf(char *);
void get_word_lengths(int word_lengths[], size_t n) {
  int c, status, length, i;
  printf("Type words! CTRL-D to exit.\n");
  printf("> ");
  status = 0;
  length = 0;
  while ((c = getchar()) != EOF) {
    if (status) {
      if (is_word_separator(c)) {
        status = 0;
        ++word_lengths[length];
        length = 0;
        if (c == '\n')
          printf("> ");
      } else {
        length++;
      }
    } else {
      if (is_word_separator(c)) {
        if (c == '\n')
          printf("> ");
      } else {
        status = 1;
        length = 1;
      }
    }
  }
}


x86 assembly (clang, -O0):
<get_word_lengths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%eax
je     1228 <get_word_lengths+0xf8>
cmpl   $0x0,-0x18(%rbp)
je     11e3 <get_word_lengths+0xb3>
mov    -0x14(%rbp),%edi
call   1050 <is_word_separator@plt>
cmp    $0x0,%rax
je     11d5 <get_word_lengths+0xa5>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    11d0 <get_word_lengths+0xa0>
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
jmp    11de <get_word_lengths+0xae>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1223 <get_word_lengths+0xf3>
mov    -0x14(%rbp),%edi
call   1050 <is_word_separator@plt>
cmp    $0x0,%rax
je     1210 <get_word_lengths+0xe0>
cmpl   $0xa,-0x14(%rbp)
jne    120b <get_word_lengths+0xdb>
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
jmp    121e <get_word_lengths+0xee>
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    1223 <get_word_lengths+0xf3>
jmp    1166 <get_word_lengths+0x36>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word_lengths>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e74(%rip),%r12
cmp    (%r12),%eax
jne    1189 <get_word_lengths+0x49>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe6e(%rip),%r14
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    11b9 <get_word_lengths+0x79>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
je     117a <get_word_lengths+0x3a>
mov    %ebp,%edi
call   1060 <is_word_separator@plt>
test   %ebx,%ebx
je     11e0 <get_word_lengths+0xa0>
test   %rax,%rax
je     1200 <get_word_lengths+0xc0>
movslq %r13d,%rax
addl   $0x1,(%r15,%rax,4)
xor    %r13d,%r13d
cmp    $0xa,%ebp
je     11a0 <get_word_lengths+0x60>
xor    %ebx,%ebx
jmp    11aa <get_word_lengths+0x6a>
nopl   (%rax)
test   %rax,%rax
je     1206 <get_word_lengths+0xc6>
xor    %ebx,%ebx
cmp    $0xa,%ebp
jne    11aa <get_word_lengths+0x6a>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    11aa <get_word_lengths+0x6a>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13d
jmp    120c <get_word_lengths+0xcc>
mov    $0x1,%r13d
mov    $0x1,%ebx
jmp    11aa <get_word_lengths+0x6a>

LLVM IR (-O0):
@.str = [29 x i8] c"Type words! CTRL-D to exit.\0A\00"
@.str.1 = [3 x i8] c"> \00"
@EOF = global i32 0
define void @get_word_lengths(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%9 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
store i32 0, i32* %7
br label %11
11: ; preds = %50, %2
%12 = call i32 (...) @getchar()
store i32 %12, i32* %5
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %51
15: ; preds = %11
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = load i32, i32* %5
%20 = call i64 @is_word_separator(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %18
store i32 0, i32* %6
%23 = load i32*, i32** %3
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
store i32 0, i32* %7
%29 = load i32, i32* %5
%30 = icmp eq i32 %29, 10
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %22
br label %37
34: ; preds = %18
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %37
37: ; preds = %34, %33
br label %50
38: ; preds = %15
%39 = load i32, i32* %5
%40 = call i64 @is_word_separator(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 10
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
br label %49
48: ; preds = %38
store i32 1, i32* %6
store i32 1, i32* %7
br label %49
49: ; preds = %48, %47
br label %50
50: ; preds = %49, %37
br label %11
51: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@EOF = global i32 0
@str = [28 x i8] c"Type words! CTRL-D to exit.\00"
define void @get_word_lengths(i32* nocapture %0, i64 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (...) @getchar()
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %37, label %8
8: ; preds = %2, %31
%9 = phi i32 [ %34, %31 ], [ %5, %2 ]
%10 = phi i32 [ %33, %31 ], [ 0, %2 ]
%11 = phi i32 [ %32, %31 ], [ 0, %2 ]
%12 = icmp eq i32 %10, 0
%13 = tail call i64 @is_word_separator(i32 %9)
%14 = icmp eq i64 %13, 0
br i1 %12, label %26, label %15
15: ; preds = %8
br i1 %14, label %24, label %16
16: ; preds = %15
%17 = sext i32 %11 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
%21 = icmp eq i32 %9, 10
br i1 %21, label %22, label %31
22: ; preds = %16
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %31
24: ; preds = %15
%25 = add nsw i32 %11, 1
br label %31
26: ; preds = %8
br i1 %14, label %31, label %27
27: ; preds = %26
%28 = icmp eq i32 %9, 10
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %26, %29, %27, %24, %22, %16
%32 = phi i32 [ 0, %22 ], [ 0, %16 ], [ %25, %24 ], [ %11, %29 ], [ %11, %27 ], [ 1, %26 ]
%33 = phi i32 [ 0, %22 ], [ 0, %16 ], [ 1, %24 ], [ 0, %29 ], [ 0, %27 ], [ 1, %26 ]
%34 = tail call i32 (...) @getchar()
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %8
37: ; preds = %31, %2
ret void
}