#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 /*<<< orphan*/ isspace(char);
int readWord(char *p) {
  int c, i = 0, w = 0;
  while ((c = *(p + i)) != '\0') {
    if (c == ' ' && !isspace(*(p + i + 1))) {
      w++;
    }
    i++;
  }
  return (w + 1);
}


x86 assembly (clang, -O0):
<readWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     117e <readWord+0x6e>
cmpl   $0x20,-0xc(%rbp)
jne    1170 <readWord+0x60>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
jne    1170 <readWord+0x60>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <readWord+0x1a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readWord>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
jmp    1132 <readWord+0x22>
xchg   %ax,%ax
movsbl (%rbx),%edi
call   1030 <isspace@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0x20,%al
je     1120 <readWord+0x10>
test   %al,%al
jne    112e <readWord+0x1e>
add    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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