#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);
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *parser_copy_word(char **cur) {
  char *value = *cur;
  size_t i;
  for (i = 0; !isspace(value[i]) && value[i] != '\0'; i++) {
  }
  if (i == 0) {
    return NULL;
  }
  char *result = malloc(i + 1);
  if (!result) {
    return NULL;
  }
  *cur += i;
  memcpy(result, value, i);
  result[i] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<parser_copy_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isspace@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    1185 <parser_copy_word+0x55>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1195 <parser_copy_word+0x65>
jmp    11ab <parser_copy_word+0x7b>
jmp    119a <parser_copy_word+0x6a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114f <parser_copy_word+0x1f>
cmpq   $0x0,-0x20(%rbp)
jne    11c3 <parser_copy_word+0x93>
movq   $0x0,-0x8(%rbp)
jmp    121f <parser_copy_word+0xef>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ec <parser_copy_word+0xbc>
movq   $0x0,-0x8(%rbp)
jmp    121f <parser_copy_word+0xef>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parser_copy_word>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%r15
movsbl (%r15),%edi
call   1030 <isspace@plt>
test   %eax,%eax
je     115d <parser_copy_word+0x2d>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
nop
cmpb   $0x0,(%r15,%rbx,1)
je     117a <parser_copy_word+0x4a>
movsbl 0x1(%r15,%rbx,1),%edi
add    $0x1,%rbx
call   1030 <isspace@plt>
test   %eax,%eax
je     1160 <parser_copy_word+0x30>
test   %rbx,%rbx
je     114b <parser_copy_word+0x1b>
lea    0x1(%rbx),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     114b <parser_copy_word+0x1b>
mov    %rax,%r12
add    %rbx,(%r14)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r12,%rbx,1)
jmp    114e <parser_copy_word+0x1e>

LLVM IR (-O0):
define i8* @parser_copy_word(i8** %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8** %0, i8*** %3
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
store i8* %8, i8** %4
store i64 0, i64* %5
br label %9
9: ; preds = %26, %1
%10 = load i8*, i8** %4
%11 = load i64, i64* %5
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = load i8, i8* %12
%14 = call i32 @isspace(i8 signext %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %9
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %16, %9
%24 = phi i1 [ false, %9 ], [ %22, %16 ]
br i1 %24, label %25, label %29
25: ; preds = %23
br label %26
26: ; preds = %25
%27 = load i64, i64* %5
%28 = add i64 %27, 1
store i64 %28, i64* %5
br label %9
29: ; preds = %23
%30 = load i64, i64* %5
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29
store i8* null, i8** %2
br label %53
33: ; preds = %29
%34 = load i64, i64* %5
%35 = add i64 %34, 1
%36 = call i8* @malloc(i64 %35)
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %33
store i8* null, i8** %2
br label %53
40: ; preds = %33
%41 = load i64, i64* %5
%42 = load i8**, i8*** %3
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i64 %41
store i8* %44, i8** %42
%45 = load i8*, i8** %6
%46 = load i8*, i8** %4
%47 = load i64, i64* %5
%48 = call i32 @memcpy(i8* %45, i8* %46, i64 %47)
%49 = load i8*, i8** %6
%50 = load i64, i64* %5
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %6
store i8* %52, i8** %2
br label %53
53: ; preds = %40, %39, %32
%54 = load i8*, i8** %2
ret i8* %54
}

LLVM IR (-O2):
define i8* @parser_copy_word(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = tail call i32 @isspace(i8 signext %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %29
6: ; preds = %1, %11
%7 = phi i8* [ %13, %11 ], [ %2, %1 ]
%8 = phi i64 [ %12, %11 ], [ 0, %1 ]
%9 = load i8, i8* %7
%10 = icmp eq i8 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = add i64 %8, 1
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @isspace(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %6, label %17
17: ; preds = %6, %11
%18 = phi i64 [ %8, %6 ], [ %12, %11 ]
%19 = icmp eq i64 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = add i64 %18, 1
%22 = tail call i8* @malloc(i64 %21)
%23 = icmp eq i8* %22, null
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = load i8*, i8** %0
%26 = getelementptr inbounds i8, i8* %25, i64 %18
store i8* %26, i8** %0
%27 = tail call i32 @memcpy(i8* %22, i8* %2, i64 %18)
%28 = getelementptr inbounds i8, i8* %22, i64 %18
store i8 0, i8* %28
br label %29
29: ; preds = %1, %24, %20, %17
%30 = phi i8* [ null, %17 ], [ %22, %24 ], [ null, %20 ], [ null, %1 ]
ret i8* %30
}