#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*/ cprnths_parseutil_is_wordchar(char const);
scalar_t__ memcmp(char const *, char const *const, size_t const);
size_t strlen(char const *const);
signed char cprnths_parseutil_startswith_word(char const **restrict const subj,
                                              char const *const end,
                                              char const *restrict const frag) {
  size_t const len = strlen(frag);
  if ((size_t)(end - *subj) < len || memcmp(*subj, frag, len))
    return -1;
  if ((*subj += len) == end)
    return 2;
  return !cprnths_parseutil_is_wordchar(**subj);
}


x86 assembly (clang, -O0):
<cprnths_parseutil_startswith_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
cmp    -0x28(%rbp),%rax
jb     1187 <cprnths_parseutil_startswith_word+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1190 <cprnths_parseutil_startswith_word+0x60>
movb   $0xff,-0x1(%rbp)
jmp    11d0 <cprnths_parseutil_startswith_word+0xa0>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    (%rcx),%rax
mov    %rax,(%rcx)
cmp    -0x18(%rbp),%rax
jne    11b1 <cprnths_parseutil_startswith_word+0x81>
movb   $0x2,-0x1(%rbp)
jmp    11d0 <cprnths_parseutil_startswith_word+0xa0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1040 <cprnths_parseutil_is_wordchar@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cprnths_parseutil_startswith_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
mov    (%r15),%rbx
mov    %r14,%rax
sub    %rbx,%rax
mov    $0xff,%r12b
cmp    %r13,%rax
jb     1191 <cprnths_parseutil_startswith_word+0x61>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1191 <cprnths_parseutil_startswith_word+0x61>
add    %r13,%rbx
mov    %rbx,(%r15)
cmp    %r14,%rbx
je     118e <cprnths_parseutil_startswith_word+0x5e>
movsbl (%rbx),%edi
call   1040 <cprnths_parseutil_is_wordchar@plt>
test   %eax,%eax
sete   %r12b
jmp    1191 <cprnths_parseutil_startswith_word+0x61>
mov    $0x2,%r12b
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @cprnths_parseutil_startswith_word(i8** noalias %0, i8* %1, i8* noalias %2) {
%4 = alloca i8
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %8
%11 = load i8*, i8** %6
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = ptrtoint i8* %11 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = load i64, i64* %8
%18 = icmp ult i64 %16, %17
br i1 %18, label %26, label %19
19: ; preds = %3
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = load i8*, i8** %7
%23 = load i64, i64* %8
%24 = call i64 @memcmp(i8* %21, i8* %22, i64 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19, %3
store i8 -1, i8* %4
br label %44
27: ; preds = %19
%28 = load i64, i64* %8
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 %28
store i8* %31, i8** %29
%32 = load i8*, i8** %6
%33 = icmp eq i8* %31, %32
br i1 %33, label %34, label %35
34: ; preds = %27
store i8 2, i8* %4
br label %44
35: ; preds = %27
%36 = load i8**, i8*** %5
%37 = load i8*, i8** %36
%38 = load i8, i8* %37
%39 = call i32 @cprnths_parseutil_is_wordchar(i8 signext %38)
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
%42 = zext i1 %41 to i32
%43 = trunc i32 %42 to i8
store i8 %43, i8* %4
br label %44
44: ; preds = %35, %34, %26
%45 = load i8, i8* %4
ret i8 %45
}

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