#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__ strdup(char *);
char *strtok(char *, char *);
int getCommandLine(char *completeLine, char **arguments) {
  char *tmp = (char *)strdup(completeLine);
  char *token;
  int narg = 0;
  token = strtok(tmp, " ");
  while (token != NULL) {
    arguments[narg] = (char *)strdup(token);
    narg++;
    token = strtok(NULL, " ");
  }
  free(tmp);
  arguments[narg] = NULL;
  return narg;
}


x86 assembly (clang, -O0):
<getCommandLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ad <getCommandLine+0x7d>
mov    -0x20(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe61(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1168 <getCommandLine+0x38>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCommandLine>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
call   1050 <strdup@plt>
mov    %rax,%r14
lea    0xeb6(%rip),%rsi
mov    %rax,%rdi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     117f <getCommandLine+0x4f>
lea    0xea0(%rip),%r12
mov    %rax,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1160 <getCommandLine+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
movq   $0x0,(%r15,%rax,8)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @getCommandLine(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i64 @strdup(i8* %0)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i8* @strtok(i8* %4, 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 = %2, %7
%8 = phi i64 [ %13, %7 ], [ 0, %2 ]
%9 = phi i8* [ %14, %7 ], [ %5, %2 ]
%10 = tail call i64 @strdup(i8* %9)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i8*, i8** %1, i64 %8
store i8* %11, i8** %12
%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 = trunc i64 %13 to i32
br label %18
18: ; preds = %16, %2
%19 = phi i32 [ 0, %2 ], [ %17, %16 ]
%20 = tail call i32 @free(i8* %4)
%21 = zext i32 %19 to i64
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
store i8* null, i8** %22
ret i32 %19
}