#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char **realloc(char **, int);
char *strtok(char *, char *);
char **parse_command(char *str) {
  char **result = NULL;
  char *p = strtok(str, " ");
  int spaces = 0, i;
  while (p) {
    result = realloc(result, sizeof(char *) * ++spaces);
    if (result == NULL)
      exit(EXIT_FAILURE);
    result[spaces - 1] = p;
    p = strtok(NULL, " ");
  }
  result = realloc(result, sizeof(char *) * (spaces + 1));
  result[spaces] = 0;
  return result;
}


x86 assembly (clang, -O0):
<parse_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cf <parse_command+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a1 <parse_command+0x71>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe3f(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    115f <parse_command+0x2f>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_command>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xec1(%rip),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1191 <parse_command+0x61>
mov    %rax,%r14
mov    $0x8,%ebp
xor    %r12d,%r12d
lea    0xea5(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <realloc@plt>
test   %rax,%rax
je     11ba <parse_command+0x8a>
mov    %rax,%rbx
mov    %r14,(%rax,%r12,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,%r14
add    $0x8,%ebp
add    $0x1,%r12
test   %rax,%rax
jne    1160 <parse_command+0x30>
jmp    1196 <parse_command+0x66>
xor    %r12d,%r12d
xor    %ebx,%ebx
lea    0x8(,%r12,8),%esi
mov    %rbx,%rdi
call   1030 <realloc@plt>
mov    %r12d,%ecx
movq   $0x0,(%rax,%rcx,8)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@EXIT_FAILURE = global i32 0
define i8** @parse_command(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i8** null, i8*** %3
%7 = load i8*, i8** %2
%8 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
store i32 0, i32* %5
br label %9
9: ; preds = %25, %1
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = load i8**, i8*** %3
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
%16 = sext i32 %15 to i64
%17 = mul i64 8, %16
%18 = trunc i64 %17 to i32
%19 = call i8** @realloc(i8** %13, i32 %18)
store i8** %19, i8*** %3
%20 = load i8**, i8*** %3
%21 = icmp eq i8** %20, null
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %12
%26 = load i8*, i8** %4
%27 = load i8**, i8*** %3
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
store i8* %26, i8** %31
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %32, i8** %4
br label %9
33: ; preds = %9
%34 = load i8**, i8*** %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 8, %37
%39 = trunc i64 %38 to i32
%40 = call i8** @realloc(i8** %34, i32 %39)
store i8** %40, i8*** %3
%41 = load i8**, i8*** %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
store i8* null, i8** %44
%45 = load i8**, i8*** %3
ret i8** %45
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@EXIT_FAILURE = global i32 0
define i8** @parse_command(i8* %0) {
%2 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %22, label %4
4: ; preds = %1, %16
%5 = phi i64 [ %8, %16 ], [ 0, %1 ]
%6 = phi i8** [ %11, %16 ], [ null, %1 ]
%7 = phi i8* [ %18, %16 ], [ %2, %1 ]
%8 = add nuw i64 %5, 1
%9 = trunc i64 %8 to i32
%10 = shl i32 %9, 3
%11 = tail call i8** @realloc(i8** %6, i32 %10)
%12 = icmp eq i8** %11, null
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %4
%17 = getelementptr inbounds i8*, i8** %11, i64 %5
store i8* %7, i8** %17
%18 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %4
20: ; preds = %16
%21 = trunc i64 %8 to i32
br label %22
22: ; preds = %20, %1
%23 = phi i32 [ 0, %1 ], [ %21, %20 ]
%24 = phi i8** [ null, %1 ], [ %11, %20 ]
%25 = shl i32 %23, 3
%26 = add i32 %25, 8
%27 = tail call i8** @realloc(i8** %24, i32 %26)
%28 = zext i32 %23 to i64
%29 = getelementptr inbounds i8*, i8** %27, i64 %28
store i8* null, i8** %29
ret i8** %27
}