#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 */
char *find_word_end_termchar(char const *, char const *, char);
int get_word_index(const char *str, int pos) {
  const char *maxend = str + pos;
  int index;
  for (index = 0;; index++) {
    str = find_word_end_termchar(str, maxend, '\0');
    if (str >= maxend || *str == '\0')
      return index;
  }
}


x86 assembly (clang, -O0):
<get_word_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <find_word_end_termchar@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1166 <get_word_index+0x56>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116f <get_word_index+0x5f>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1174 <get_word_index+0x64>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <get_word_index+0x25>

x86 assembly (clang, -O2):
<get_word_index>:
push   %rbp
push   %rbx
push   %rax
movslq %esi,%rbx
add    %rdi,%rbx
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <find_word_end_termchar@plt>
cmp    %rbx,%rax
jae    114a <get_word_index+0x3a>
xor    %ebp,%ebp
nopl   0x0(%rax)
cmpb   $0x0,(%rax)
je     114a <get_word_index+0x3a>
add    $0x1,%ebp
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <find_word_end_termchar@plt>
cmp    %rbx,%rax
jb     1130 <get_word_index+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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