#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 */
scalar_t__ paper_is_start_of_first_word(size_t, char *);
scalar_t__ paper_is_start_of_subsequent_word(char *);
size_t paper_word_count(char *paper) {
  size_t count = 0;
  char *ptr = paper;
  do {
    if (!*ptr) {
      break;
    }
    if (paper_is_start_of_first_word(count, ptr) ||
        paper_is_start_of_subsequent_word(ptr)) {
      count += 1;
    }
  } while (*(++ptr));
  return count;
}


x86 assembly (clang, -O0):
<paper_word_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    114e <paper_word_count+0x2e>
jmp    11a2 <paper_word_count+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <paper_is_start_of_first_word@plt>
cmp    $0x0,%rax
jne    1178 <paper_word_count+0x58>
mov    -0x18(%rbp),%rdi
call   1030 <paper_is_start_of_subsequent_word@plt>
cmp    $0x0,%rax
je     1184 <paper_word_count+0x64>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1189 <paper_word_count+0x69>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,0x1(%rax)
jne    113c <paper_word_count+0x1c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paper_word_count>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%al
xor    %r14d,%r14d
jmp    1140 <paper_word_count+0x20>
xchg   %ax,%ax
add    $0x1,%r14
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1163 <paper_word_count+0x43>
test   %al,%al
je     1163 <paper_word_count+0x43>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <paper_is_start_of_first_word@plt>
test   %rax,%rax
jne    1130 <paper_word_count+0x10>
mov    %rbx,%rdi
call   1030 <paper_is_start_of_subsequent_word@plt>
test   %rax,%rax
jne    1130 <paper_word_count+0x10>
jmp    1134 <paper_word_count+0x14>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @paper_word_count(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* %3
%5 = load i8*, i8** %2
store i8* %5, i8** %4
br label %6
6: ; preds = %24, %1
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %6
br label %29
11: ; preds = %6
%12 = load i64, i64* %3
%13 = load i8*, i8** %4
%14 = call i64 @paper_is_start_of_first_word(i64 %12, i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = call i64 @paper_is_start_of_subsequent_word(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16, %11
%21 = load i64, i64* %3
%22 = add i64 %21, 1
store i64 %22, i64* %3
br label %23
23: ; preds = %20, %16
br label %24
24: ; preds = %23
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %6, label %29
29: ; preds = %24, %10
%30 = load i64, i64* %3
ret i64 %30
}

LLVM IR (-O2):
define i64 @paper_word_count(i8* %0) {
%2 = load i8, i8* %0
br label %3
3: ; preds = %16, %1
%4 = phi i8 [ %19, %16 ], [ %2, %1 ]
%5 = phi i64 [ %17, %16 ], [ 0, %1 ]
%6 = phi i8* [ %18, %16 ], [ %0, %1 ]
%7 = icmp eq i8 %4, 0
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = tail call i64 @paper_is_start_of_first_word(i64 %5, i8* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i64 @paper_is_start_of_subsequent_word(i8* %6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11, %8
%15 = add i64 %5, 1
br label %16
16: ; preds = %11, %14
%17 = phi i64 [ %15, %14 ], [ %5, %11 ]
%18 = getelementptr inbounds i8, i8* %6, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %3
21: ; preds = %3, %16
%22 = phi i64 [ %17, %16 ], [ %5, %3 ]
ret i64 %22
}