#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 */
scalar_t__ malloc(size_t);
scalar_t__ realloc(void *, size_t);
char *strtok(char *, char *);
char **parse_cmd(char *cmd) {
  size_t args_size = sizeof(char **) * 5;
  char **args = (char **)malloc(args_size);
  int loop = 0;
  args[loop] = strtok(cmd, " ");
  do {
    loop++;
    if (sizeof(char **) * loop == args_size) {
      args_size += sizeof(char **) * 5;
      args = (char **)realloc((void *)args, args_size);
    }
    args[loop] = strtok(NULL, " ");
  } while (args[loop] != NULL);
  return args;
}


x86 assembly (clang, -O0):
<parse_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x28,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
cmp    -0x10(%rbp),%rax
jne    11af <parse_cmd+0x7f>
mov    -0x10(%rbp),%rax
add    $0x28,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe46(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1177 <parse_cmd+0x47>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmd>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
mov    $0x28,%r13d
mov    $0x28,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
lea    0xeaa(%rip),%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,(%r14)
mov    $0x8,%ebx
jmp    1187 <parse_cmd+0x57>
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,(%r14,%rbx,1)
add    $0x8,%rbx
test   %rax,%rax
je     11a0 <parse_cmd+0x70>
cmp    %r13,%rbx
jne    1170 <parse_cmd+0x40>
add    $0x28,%r13
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <realloc@plt>
mov    %rax,%r14
jmp    1170 <parse_cmd+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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