#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 */
typedef size_t u_int;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freea(char **);
char *strdup(char const *);
char *strsep(char **, char *);
char **xalloc(size_t, char **);
char **expanda(const char *_str) {
  char **arr = NULL, *tok, *str;
  u_int i, ac;
  ac = i = 0;
  if ((str = strdup(_str)) == NULL)
    return (NULL);
  while ((tok = strsep(&str, " ")) != NULL) {
    if (*tok == '\0')
      continue;
    if ((arr = xalloc(i, arr)) == NULL)
      goto fail;
    if ((arr[i++] = strdup(tok)) == NULL)
      goto fail;
  }
  if ((arr = xalloc(i, arr)) == NULL)
    goto fail;
  arr[i] = NULL;
  return (arr);
fail:
  if (arr != NULL)
    freea(arr);
  free(str);
  return (NULL);
}


x86 assembly (clang, -O0):
<expanda>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1198 <expanda+0x48>
movq   $0x0,-0x8(%rbp)
jmp    1286 <expanda+0x136>
jmp    119d <expanda+0x4d>
lea    -0x28(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1224 <expanda+0xd4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d0 <expanda+0x80>
jmp    119d <expanda+0x4d>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <xalloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f0 <expanda+0xa0>
jmp    1261 <expanda+0x111>
mov    -0x20(%rbp),%rdi
call   1070 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    %rdx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x30(%rbp)
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    121f <expanda+0xcf>
jmp    1261 <expanda+0x111>
jmp    119d <expanda+0x4d>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <xalloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1244 <expanda+0xf4>
jmp    1261 <expanda+0x111>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1286 <expanda+0x136>
cmpq   $0x0,-0x18(%rbp)
je     1275 <expanda+0x125>
mov    -0x18(%rbp),%rdi
call   1060 <freea@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expanda>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
call   1070 <strdup@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11fe <expanda+0xae>
xor    %r14d,%r14d
lea    0xe86(%rip),%r12
lea    0x8(%rsp),%r13
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <strsep@plt>
test   %rax,%rax
je     11da <expanda+0x8a>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1190 <expanda+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <xalloc@plt>
test   %rax,%rax
je     11f4 <expanda+0xa4>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r14,%r15,8)
add    $0x1,%r15
test   %rax,%rax
jne    1190 <expanda+0x40>
mov    %r14,%rdi
call   1060 <freea@plt>
jmp    11f4 <expanda+0xa4>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <xalloc@plt>
test   %rax,%rax
je     11f4 <expanda+0xa4>
movq   $0x0,(%rax,%r15,8)
jmp    1200 <expanda+0xb0>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8** @expanda(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i8** null, i8*** %4
store i64 0, i64* %7
store i64 0, i64* %8
%9 = load i8*, i8** %3
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i8** null, i8*** %2
br label %59
13: ; preds = %1
br label %14
14: ; preds = %38, %22, %13
%15 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %14
23: ; preds = %17
%24 = load i64, i64* %7
%25 = load i8**, i8*** %4
%26 = call i8** @xalloc(i64 %24, i8** %25)
store i8** %26, i8*** %4
%27 = icmp eq i8** %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
br label %50
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = call i8* @strdup(i8* %30)
%32 = load i8**, i8*** %4
%33 = load i64, i64* %7
%34 = add i64 %33, 1
store i64 %34, i64* %7
%35 = getelementptr inbounds i8*, i8** %32, i64 %33
store i8* %31, i8** %35
%36 = icmp eq i8* %31, null
br i1 %36, label %37, label %38
37: ; preds = %29
br label %50
38: ; preds = %29
br label %14
39: ; preds = %14
%40 = load i64, i64* %7
%41 = load i8**, i8*** %4
%42 = call i8** @xalloc(i64 %40, i8** %41)
store i8** %42, i8*** %4
%43 = icmp eq i8** %42, null
br i1 %43, label %44, label %45
44: ; preds = %39
br label %50
45: ; preds = %39
%46 = load i8**, i8*** %4
%47 = load i64, i64* %7
%48 = getelementptr inbounds i8*, i8** %46, i64 %47
store i8* null, i8** %48
%49 = load i8**, i8*** %4
store i8** %49, i8*** %2
br label %59
50: ; preds = %44, %37, %28
%51 = load i8**, i8*** %4
%52 = icmp ne i8** %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i8**, i8*** %4
%55 = call i32 @freea(i8** %54)
br label %56
56: ; preds = %53, %50
%57 = load i8*, i8** %6
%58 = call i32 @free(i8* %57)
store i8** null, i8*** %2
br label %59
59: ; preds = %56, %45, %12
%60 = load i8**, i8*** %2
ret i8** %60
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8** @expanda(i8* nocapture %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8* @strdup(i8* %0)
store i8* %4, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %33, label %6
6: ; preds = %1, %18
%7 = phi i8** [ %16, %18 ], [ null, %1 ]
%8 = phi i64 [ %20, %18 ], [ 0, %1 ]
br label %9
9: ; preds = %6, %12
%10 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %9, label %15
15: ; preds = %12
%16 = call i8** @xalloc(i64 %8, i8** %7)
%17 = icmp eq i8** %16, null
br i1 %17, label %30, label %18
18: ; preds = %15
%19 = call i8* @strdup(i8* %10)
%20 = add i64 %8, 1
%21 = getelementptr inbounds i8*, i8** %16, i64 %8
store i8* %19, i8** %21
%22 = icmp eq i8* %19, null
br i1 %22, label %28, label %6
23: ; preds = %9
%24 = call i8** @xalloc(i64 %8, i8** %7)
%25 = icmp eq i8** %24, null
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = getelementptr inbounds i8*, i8** %24, i64 %8
store i8* null, i8** %27
br label %33
28: ; preds = %18
%29 = call i32 @freea(i8** %16)
br label %30
30: ; preds = %15, %23, %28
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %1, %30, %26
%34 = phi i8** [ null, %30 ], [ %24, %26 ], [ null, %1 ]
ret i8** %34
}