#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 *strcpy(int /*<<< orphan*/, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ xmalloc(scalar_t__);
char *word(char *p, char **s) {
  char buf[256];
  int i = 0;
  while (*p > ' ')
    buf[i++] = *p++;
  buf[i] = '\0';
  if (i > 0)
    *s = strcpy(xmalloc(strlen(buf) + 1), (buf));
  else
    *s = NULL;
  return (p);
}


x86 assembly (clang, -O0):
<word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x114(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jle    118d <word+0x5d>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x114(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x114(%rbp)
cltq
mov    %cl,-0x110(%rbp,%rax,1)
jmp    114d <word+0x1d>
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
cmpl   $0x0,-0x114(%rbp)
jle    11de <word+0xae>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %eax,%edi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11e9 <word+0xb9>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<word>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%cl
xor    %eax,%eax
cmp    $0x21,%cl
jl     1190 <word+0x60>
nopl   0x0(%rax,%rax,1)
mov    %cl,(%rsp,%rax,1)
movzbl 0x1(%rbx,%rax,1),%ecx
add    $0x1,%rax
cmp    $0x20,%cl
jg     1150 <word+0x20>
mov    %eax,%ecx
movb   $0x0,(%rsp,%rcx,1)
add    %rax,%rbx
test   %eax,%eax
je     118e <word+0x5e>
mov    %rsp,%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <xmalloc@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1030 <strcpy@plt>
jmp    1190 <word+0x60>
xor    %eax,%eax
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @word(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca [256 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %6
br label %7
7: ; preds = %12, %2
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp sgt i32 %10, 32
br i1 %11, label %12, label %20
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
%15 = load i8, i8* %13
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
store i32 %17, i32* %6
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %18
store i8 %15, i8* %19
br label %7
20: ; preds = %7
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %22
store i8 0, i8* %23
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @xmalloc(i64 %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%32 = call i8* @strcpy(i32 %30, i8* %31)
%33 = load i8**, i8*** %4
store i8* %32, i8** %33
br label %36
34: ; preds = %20
%35 = load i8**, i8*** %4
store i8* null, i8** %35
br label %36
36: ; preds = %34, %26
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
define i8* @word(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
%6 = icmp sgt i8 %5, 32
br i1 %6, label %7, label %26
7: ; preds = %2, %7
%8 = phi i64 [ %12, %7 ], [ 0, %2 ]
%9 = phi i8 [ %14, %7 ], [ %5, %2 ]
%10 = phi i8* [ %11, %7 ], [ %0, %2 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = add nuw i64 %8, 1
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %8
store i8 %9, i8* %13
%14 = load i8, i8* %11
%15 = icmp sgt i8 %14, 32
br i1 %15, label %7, label %16
16: ; preds = %7
%17 = trunc i64 %12 to i32
%18 = and i64 %12, 4294967295
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = icmp eq i32 %17, 0
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = call i64 @strlen(i8* %4)
%23 = add nsw i64 %22, 1
%24 = tail call i32 @xmalloc(i64 %23)
%25 = call i8* @strcpy(i32 %24, i8* %4)
br label %26
26: ; preds = %2, %16, %21
%27 = phi i8* [ %11, %21 ], [ %11, %16 ], [ %0, %2 ]
%28 = phi i8* [ %25, %21 ], [ null, %16 ], [ null, %2 ]
store i8* %28, i8** %1
ret i8* %27
}