#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 count_arguments(char const *);
scalar_t__ malloc(int);
char *strtok(char *, char *);
char **parse_cmdline(const char *cmdline) {
  int arguments_count = count_arguments(cmdline);
  char **parsed_cmd = (char **)malloc(sizeof(char **) * arguments_count);
  char *cmdlinee = (char *)cmdline;
  parsed_cmd[0] = strtok(cmdlinee, " \n");
  int i = 1;
  while (parsed_cmd[i - 1] != NULL) {
    parsed_cmd[i] = (char *)malloc(sizeof(char *));
    parsed_cmd[i] = strtok(NULL, " \n");
    i++;
  }
  return parsed_cmd;
}


x86 assembly (clang, -O0):
<parse_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <count_arguments@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e2 <parse_cmdline+0xb2>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe40(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <parse_cmdline+0x54>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmdline>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <count_arguments@plt>
lea    0x0(,%rax,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11a3 <parse_cmdline+0x73>
mov    %r14,%rbx
add    $0x8,%rbx
lea    0xe8f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
test   %rax,%rax
jne    1180 <parse_cmdline+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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