#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 */
void *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
char **get_arguments(char *command) {
  int index = 0;
  char *argument;
  char **args = malloc(100 * sizeof(char *));
  args[index] = malloc(sizeof(char *));
  args[0][0] = '\0';
  argument = strtok(command, " ");
  while (argument != NULL) {
    args[index] = malloc(sizeof(char *));
    strcpy(args[index], argument);
    index++;
    argument = strtok(NULL, " ");
  }
  args[index] = NULL;
  return args;
}


x86 assembly (clang, -O0):
<get_arguments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x320,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e3 <get_arguments+0xb3>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2b(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1188 <get_arguments+0x58>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arguments>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x320,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15)
movb   $0x0,(%rax)
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11b3 <get_arguments+0x83>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xe88(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1180 <get_arguments+0x50>
mov    %ebx,%eax
jmp    11b5 <get_arguments+0x85>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define noalias i8** @get_arguments(i8* %0) {
%2 = tail call dereferenceable_or_null(800) i8* @malloc(i32 800)
%3 = bitcast i8* %2 to i8**
%4 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
store i8* %4, i8** %3
store i8 0, i8* %4
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %13, %7 ], [ 0, %1 ]
%9 = phi i8* [ %14, %7 ], [ %5, %1 ]
%10 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%11 = getelementptr inbounds i8*, i8** %3, i64 %8
store i8* %10, i8** %11
%12 = tail call i32 @strcpy(i8* %10, i8* %9)
%13 = add nuw i64 %8, 1
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = and i64 %13, 4294967295
br label %18
18: ; preds = %16, %1
%19 = phi i64 [ 0, %1 ], [ %17, %16 ]
%20 = getelementptr inbounds i8*, i8** %3, i64 %19
store i8* null, i8** %20
ret i8** %3
}