#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(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strspn(char *, char *);
char *get_word(char *string, char *list, char **endptr) {
  int len = strspn(string, list);
  if (!len)
    return NULL;
  char *ret = malloc(len + 1);
  memcpy(ret, string, len);
  ret[len] = '\0';
  *endptr = string + len;
  return ret;
}


x86 assembly (clang, -O0):
<get_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    116b <get_word+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <get_word+0x80>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rcx
movslq -0x24(%rbp),%rax
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r12
call   1030 <strspn@plt>
test   %eax,%eax
je     1171 <get_word+0x41>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
add    %rax,%r12
mov    %r12,(%r14)
jmp    1174 <get_word+0x44>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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