#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 *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *strchrnul(char const *, char);
bool maybe_parse_word(const char **string, const char **result) {
  const char *start = *string;
  const char *end = strchrnul(start, ' ');
  if (end == start) {
    *result = NULL;
    return false;
  } else {
    size_t length = (size_t)(end - start);
    char *word = malloc(length + 1);
    memcpy(word, start, length);
    word[length] = '\0';
    *string = end;
    *result = word;
    return true;
  }
}


x86 assembly (clang, -O0):
<maybe_parse_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchrnul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1182 <maybe_parse_word+0x52>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11dc <maybe_parse_word+0xac>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maybe_parse_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <strchrnul@plt>
mov    %rax,%rbp
sub    %rbx,%rbp
je     1185 <maybe_parse_word+0x55>
mov    %rax,%r13
lea    0x1(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r12,%rbp,1)
mov    %r13,(%r15)
mov    $0x1,%eax
jmp    118a <maybe_parse_word+0x5a>
xor    %r12d,%r12d
xor    %eax,%eax
mov    %r12,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @maybe_parse_word(i8** nocapture %0, i8** nocapture writeonly %1) {
%3 = load i8*, i8** %0
%4 = tail call i8* @strchrnul(i8* %3, i8 signext 32)
%5 = icmp eq i8* %4, %3
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %3 to i64
%9 = sub i64 %7, %8
%10 = add i64 %9, 1
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call i32 @memcpy(i8* %11, i8* %3, i64 %9)
%13 = getelementptr inbounds i8, i8* %11, i64 %9
store i8 0, i8* %13
store i8* %4, i8** %0
br label %14
14: ; preds = %2, %6
%15 = phi i8* [ %11, %6 ], [ null, %2 ]
%16 = phi i32 [ 1, %6 ], [ 0, %2 ]
store i8* %15, i8** %1
ret i32 %16
}