#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__ isalnum(char const);
unsigned int count_words_in_sentence(const char *sentence) {
  int in_word = 0;
  unsigned int words = 0;
  while (*sentence != '\0') {
    if (isalnum(*sentence)) {
      if (!in_word) {
        in_word = 1;
        words++;
      }
    } else
      in_word = 0;
    sentence++;
  }
  return words;
}


x86 assembly (clang, -O0):
<count_words_in_sentence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1187 <count_words_in_sentence+0x77>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     116f <count_words_in_sentence+0x5f>
cmpl   $0x0,-0xc(%rbp)
jne    116a <count_words_in_sentence+0x5a>
movl   $0x1,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1176 <count_words_in_sentence+0x66>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112a <count_words_in_sentence+0x1a>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_words_in_sentence>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1159 <count_words_in_sentence+0x49>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <isalnum@plt>
xor    $0x1,%ebp
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
cmove  %r14d,%ebp
add    %ebp,%r15d
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %ecx,%ebp
test   %al,%al
jne    1130 <count_words_in_sentence+0x20>
jmp    115c <count_words_in_sentence+0x4c>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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