#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__ is_first_letter_of_word(char const, char const);
int count_words(const char phrase[]) {
  int count = 0;
  if (phrase != NULL)
    count = 1;
  else
    return count;
  for (size_t i = 1; phrase[i] != '\0'; ++i)
    if (is_first_letter_of_word(phrase[i], phrase[i - 1]))
      ++count;
  return count;
}


x86 assembly (clang, -O0):
<count_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113a <count_words+0x2a>
movl   $0x1,-0x14(%rbp)
jmp    1145 <count_words+0x35>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <count_words+0xa4>
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ae <count_words+0x9e>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl %dl,%edi
movsbl (%rax,%rcx,1),%esi
call   1030 <is_first_letter_of_word@plt>
cmp    $0x0,%rax
je     1198 <count_words+0x88>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <count_words+0x8d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114d <count_words+0x3d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_words>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1150 <count_words+0x40>
mov    %rdi,%rbx
mov    0x1(%rdi),%al
test   %al,%al
je     1154 <count_words+0x44>
add    $0x2,%rbx
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
movsbl -0x2(%rbx),%esi
movsbl %al,%edi
call   1030 <is_first_letter_of_word@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <count_words+0x20>
jmp    1159 <count_words+0x49>
xor    %ebp,%ebp
jmp    1159 <count_words+0x49>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_words(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %4
br label %11
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %40
11: ; preds = %8
store i64 1, i64* %5
br label %12
12: ; preds = %35, %11
%13 = load i8*, i8** %3
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = load i64, i64* %5
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %3
%25 = load i64, i64* %5
%26 = sub i64 %25, 1
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i64 @is_first_letter_of_word(i8 signext %23, i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %34
34: ; preds = %31, %19
br label %35
35: ; preds = %34
%36 = load i64, i64* %5
%37 = add i64 %36, 1
store i64 %37, i64* %5
br label %12
38: ; preds = %12
%39 = load i32, i32* %4
store i32 %39, i32* %2
br label %40
40: ; preds = %38, %9
%41 = load i32, i32* %2
ret i32 %41
}

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