#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
char **parseCommandAndFillArgs(char *command) {
  char *commandCopy = (char *)malloc((strlen(command) + 1) * sizeof(char));
  strcpy(commandCopy, command);
  char **args = NULL;
  int counter = 0;
  char *token;
  int i = 0;
  token = strtok(command, " ");
  while (token != NULL) {
    counter++;
    token = strtok(NULL, " ");
  }
  args = (char **)malloc((counter + 1) * sizeof(char *));
  token = strtok(commandCopy, " ");
  while (token != NULL) {
    *(args + i) = (char *)malloc((strlen(token) + 1) * sizeof(char));
    strcpy(*(args + i), token);
    token = strtok(NULL, " ");
    i++;
  }
  *(args + counter) = NULL;
  free(commandCopy);
  return args;
}


x86 assembly (clang, -O0):
<parseCommandAndFillArgs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11dd <parseCommandAndFillArgs+0x8d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe31(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11b0 <parseCommandAndFillArgs+0x60>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1272 <parseCommandAndFillArgs+0x122>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xda5(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1208 <parseCommandAndFillArgs+0xb8>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseCommandAndFillArgs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strtok@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     11b3 <parseCommandAndFillArgs+0x63>
lea    0xe69(%rip),%rbx
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    11a0 <parseCommandAndFillArgs+0x50>
lea    0x8(,%r13,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     1225 <parseCommandAndFillArgs+0xd5>
mov    %rax,%rbx
lea    0xe1f(%rip),%r12
mov    %r15,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,0x0(%rbp)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%rbp
test   %rax,%rax
jne    11f0 <parseCommandAndFillArgs+0xa0>
mov    %r13d,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8** @parseCommandAndFillArgs(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strcpy(i8* %5, i8* %0)
%7 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1, %9
%10 = phi i32 [ %11, %9 ], [ 0, %1 ]
%11 = add nuw nsw i32 %10, 1
%12 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %9
14: ; preds = %9, %1
%15 = phi i32 [ 0, %1 ], [ %11, %9 ]
%16 = shl i32 %15, 3
%17 = add i32 %16, 8
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8**
%20 = tail call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %34, label %22
22: ; preds = %14, %22
%23 = phi i64 [ %32, %22 ], [ 0, %14 ]
%24 = phi i8* [ %31, %22 ], [ %20, %14 ]
%25 = tail call i32 @strlen(i8* %24)
%26 = add nsw i32 %25, 1
%27 = tail call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds i8*, i8** %19, i64 %23
store i8* %28, i8** %29
%30 = tail call i32 @strcpy(i8* %28, i8* %24)
%31 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = add nuw i64 %23, 1
%33 = icmp eq i8* %31, null
br i1 %33, label %34, label %22
34: ; preds = %22, %14
%35 = zext i32 %15 to i64
%36 = getelementptr inbounds i8*, i8** %19, i64 %35
store i8* null, i8** %36
%37 = tail call i32 @free(i8* %5)
ret i8** %19
}