#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 */
unsigned long count_words(const char *sentence) {
  int count = 0;
  int inword = 0;
  if (sentence == NULL)
    return 0;
  do
    switch (*sentence) {
    case '\0':
    case ' ':
    case '\t':
    case '\n':
    case '\r': {
      if (inword) {
        inword = 0;
        count++;
      }
      break;
    }
    default:
      inword = 1;
    }
  while (*sentence++);
  return count;
}


x86 assembly (clang, -O0):
<count_words>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    112e <count_words+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    11cb <count_words+0xcb>
jmp    1133 <count_words+0x33>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     1180 <count_words+0x80>
jmp    114a <count_words+0x4a>
mov    -0x1c(%rbp),%eax
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     1180 <count_words+0x80>
jmp    115e <count_words+0x5e>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     1180 <count_words+0x80>
jmp    116f <count_words+0x6f>
mov    -0x1c(%rbp),%eax
sub    $0x20,%eax
jne    119f <count_words+0x9f>
jmp    1180 <count_words+0x80>
cmpl   $0x0,-0x18(%rbp)
je     119a <count_words+0x9a>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <count_words+0xa6>
movl   $0x1,-0x18(%rbp)
jmp    11ab <count_words+0xab>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,(%rax)
jne    1133 <count_words+0x33>
movslq -0x14(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_words>:
xor    %eax,%eax
test   %rdi,%rdi
je     1149 <count_words+0x49>
movabs $0x100002601,%r8
xor    %esi,%esi
jmp    112a <count_words+0x2a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rdi
mov    %ecx,%esi
test   %dl,%dl
je     1147 <count_words+0x47>
movsbl (%rdi),%edx
mov    $0x1,%ecx
cmp    $0x20,%edx
ja     1120 <count_words+0x20>
bt     %rdx,%r8
jae    1120 <count_words+0x20>
cmp    $0x1,%esi
sbb    $0xffffffff,%eax
xor    %ecx,%ecx
jmp    1120 <count_words+0x20>
cltq
ret

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

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