#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__ isalpha(char const);
int grab_word(const char *str, const char **word) {
  while (*str == ' ') {
    ++str;
  }
  *word = str;
  while (isalpha(*str) || *str == '_') {
    ++str;
  }
  return str - *word;
}


x86 assembly (clang, -O0):
<grab_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1141 <grab_word+0x31>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1120 <grab_word+0x10>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalpha@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
jne    117a <grab_word+0x6a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    118a <grab_word+0x7a>
jmp    119b <grab_word+0x8b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114c <grab_word+0x3c>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grab_word>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    -0x1(%rdi),%ebp
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1130 <grab_word+0x20>
mov    %rbx,(%r14)
jmp    1157 <grab_word+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0x1,%ebp
movsbl (%rbx),%edi
call   1030 <isalpha@plt>
test   %rax,%rax
jne    1150 <grab_word+0x40>
cmpb   $0x5f,(%rbx)
je     1150 <grab_word+0x40>
sub    (%r14),%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @grab_word(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
store i8* %0, i8** %3
store i8** %1, i8*** %4
br label %5
5: ; preds = %10, %2
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 32
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
br label %5
13: ; preds = %5
%14 = load i8*, i8** %3
%15 = load i8**, i8*** %4
store i8* %14, i8** %15
br label %16
16: ; preds = %28, %13
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = call i64 @isalpha(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 95
br label %26
26: ; preds = %21, %16
%27 = phi i1 [ true, %16 ], [ %25, %21 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
br label %16
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = load i8**, i8*** %4
%34 = load i8*, i8** %33
%35 = ptrtoint i8* %32 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
ret i32 %38
}

LLVM IR (-O2):
define i32 @grab_word(i8* %0, i8** nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %0, %2 ], [ %7, %3 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 32
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %3, label %8
8: ; preds = %3
store i8* %4, i8** %1
br label %9
9: ; preds = %17, %8
%10 = phi i8* [ %4, %8 ], [ %18, %17 ]
%11 = load i8, i8* %10
%12 = tail call i64 @isalpha(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8, i8* %10
%16 = icmp eq i8 %15, 95
br i1 %16, label %17, label %19
17: ; preds = %9, %14
%18 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
19: ; preds = %14
%20 = load i8*, i8** %1
%21 = ptrtoint i8* %10 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
ret i32 %24
}