#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 countWords(const char string[]) {
  int i, wordCount = 0;
  bool lookingForWord = true, alphabetic(const char c);
  for (i = 0; string[i] != '\0'; ++i)
    if (alphabetic(string[i])) {
      if (lookingForWord) {
        ++wordCount;
        lookingForWord = false;
      }
    } else
      lookingForWord = true;
  return wordCount;
}


x86 assembly (clang, -O0):
<countWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1199 <countWords+0x89>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <alphabetic@plt>
cmp    $0x0,%eax
je     117f <countWords+0x6f>
cmpl   $0x0,-0x14(%rbp)
je     117a <countWords+0x6a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    1186 <countWords+0x76>
movl   $0x1,-0x14(%rbp)
jmp    118b <countWords+0x7b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <countWords+0x21>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countWords>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1154 <countWords+0x44>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %r14d,%r14d
mov    $0x1,%ebp
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <alphabetic@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
cmove  %eax,%ebp
add    %ebp,%r14d
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %ecx,%ebp
test   %al,%al
jne    1130 <countWords+0x20>
jmp    1157 <countWords+0x47>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @countWords(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 1, i32* %5
store i32 0, i32* %3
br label %6
6: ; preds = %31, %1
%7 = load i8*, i8** %2
%8 = load i32, i32* %3
%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 %34
14: ; preds = %6
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @alphabetic(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %14
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
store i32 0, i32* %5
br label %28
28: ; preds = %25, %22
br label %30
29: ; preds = %14
store i32 1, i32* %5
br label %30
30: ; preds = %29, %28
br label %31
31: ; preds = %30
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %6
34: ; preds = %6
%35 = load i32, i32* %4
ret i32 %35
}

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