#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 CountNumWordsInString(const char *InString) {
  bool prev_was_letter = false;
  int wordcount = 0;
  for (int i = 0; InString[i] != '\0'; i++) {
    if (InString[i] == ' ') {
      prev_was_letter = false;
    } else if (prev_was_letter) {
      prev_was_letter = true;
    } else {
      wordcount++;
      prev_was_letter = true;
    }
  }
  return wordcount;
}


x86 assembly (clang, -O0):
<CountNumWordsInString>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1191 <CountNumWordsInString+0x91>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1153 <CountNumWordsInString+0x53>
movl   $0x0,-0xc(%rbp)
jmp    117e <CountNumWordsInString+0x7e>
cmpl   $0x0,-0xc(%rbp)
je     1169 <CountNumWordsInString+0x69>
movl   $0x1,-0xc(%rbp)
jmp    1179 <CountNumWordsInString+0x79>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    117e <CountNumWordsInString+0x7e>
jmp    1183 <CountNumWordsInString+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111d <CountNumWordsInString+0x1d>
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountNumWordsInString>:
xor    %ecx,%ecx
xor    %eax,%eax
jmp    1116 <CountNumWordsInString+0x16>
cs nopw 0x0(%rax,%rax,1)
xor    %ecx,%ecx
add    $0x1,%rdi
movzbl (%rdi),%edx
cmp    $0x20,%dl
je     1110 <CountNumWordsInString+0x10>
test   %dl,%dl
je     1133 <CountNumWordsInString+0x33>
cmp    $0x1,%ecx
adc    $0x0,%eax
mov    $0x1,%ecx
add    $0x1,%rdi
jmp    1116 <CountNumWordsInString+0x16>
ret

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

LLVM IR (-O2):
define i32 @CountNumWordsInString(i8* nocapture %0) {
br label %2
2: ; preds = %13, %1
%3 = phi i64 [ %16, %13 ], [ 0, %1 ]
%4 = phi i32 [ %14, %13 ], [ 0, %1 ]
%5 = phi i32 [ %15, %13 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %3
%7 = load i8, i8* %6
switch i8 %7, label %9 [
i8 0, label %8
i8 32, label %13
]
8: ; preds = %2
ret i32 %5
9: ; preds = %2
%10 = icmp eq i32 %4, 0
%11 = zext i1 %10 to i32
%12 = add nsw i32 %5, %11
br label %13
13: ; preds = %9, %2
%14 = phi i32 [ 0, %2 ], [ 1, %9 ]
%15 = phi i32 [ %5, %2 ], [ %12, %9 ]
%16 = add nuw i64 %3, 1
br label %2
}