#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 */
char **malloc(int);
char *strdup(char *);
char *strdupa(char *);
char *strtok(char *, char *);
void parseCommandLine(char *cmdLineTxt, char ***argv, int *argc) {
  int count = 1;
  char *cmdLineCopy = strdupa(cmdLineTxt);
  char *match = strtok(cmdLineCopy, " ");
  while (match != NULL) {
    count++;
    match = strtok(NULL, " ");
  }
  *argv = malloc(sizeof(char *) * (count + 1));
  (*argv)[count] = 0;
  **argv = strdup("test");
  if (count > 1) {
    int i = 1;
    cmdLineCopy = strdupa(cmdLineTxt);
    match = strtok(cmdLineCopy, " ");
    do {
      (*argv)[i++] = strdup(match);
      match = strtok(NULL, " ");
    } while (match != NULL);
  }
  *argc = count;
}


x86 assembly (clang, -O0):
<parseCommandLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdupa@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a9 <parseCommandLine+0x69>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe65(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    117c <parseCommandLine+0x3c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
lea    0xe22(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
cmpl   $0x1,-0x1c(%rbp)
jle    126d <parseCommandLine+0x12d>
movl   $0x1,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdupa@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdac(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1224 <parseCommandLine+0xe4>
jmp    126d <parseCommandLine+0x12d>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseCommandLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
call   1040 <strdupa@plt>
lea    0xea0(%rip),%rsi
mov    %rax,%rdi
call   1050 <strtok@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1192 <parseCommandLine+0x52>
lea    0xe87(%rip),%r13
nopl   0x0(%rax)
add    $0x1,%ebp
xor    %edi,%edi
mov    %r13,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <parseCommandLine+0x40>
lea    0x8(,%rbp,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r13
mov    %rax,(%r12)
mov    %ebp,%eax
movq   $0x0,0x0(%r13,%rax,8)
lea    0xe4b(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,0x0(%r13)
cmp    $0x2,%ebp
jb     1213 <parseCommandLine+0xd3>
mov    %r15,%rdi
call   1040 <strdupa@plt>
lea    0xe2c(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    $0x8,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    (%r12),%rcx
mov    %rax,(%rcx,%rbx,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    11f0 <parseCommandLine+0xb0>
mov    %ebp,(%r14)
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"
@.str.1 = [5 x i8] c"test\00"
define void @parseCommandLine(i8* %0, i8*** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8***
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8*** %1, i8**** %5
store i32* %2, i32** %6
store i32 1, i32* %7
%11 = load i8*, i8** %4
%12 = call i8* @strdupa(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %9
br label %15
15: ; preds = %18, %3
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %9
br label %15
22: ; preds = %15
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 8, %25
%27 = trunc i64 %26 to i32
%28 = call i8** @malloc(i32 %27)
%29 = load i8***, i8**** %5
store i8** %28, i8*** %29
%30 = load i8***, i8**** %5
%31 = load i8**, i8*** %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
store i8* null, i8** %34
%35 = call i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8***, i8**** %5
%37 = load i8**, i8*** %36
store i8* %35, i8** %37
%38 = load i32, i32* %7
%39 = icmp sgt i32 %38, 1
br i1 %39, label %40, label %59
40: ; preds = %22
store i32 1, i32* %10
%41 = load i8*, i8** %4
%42 = call i8* @strdupa(i8* %41)
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = call i8* @strtok(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %44, i8** %9
br label %45
45: ; preds = %55, %40
%46 = load i8*, i8** %9
%47 = call i8* @strdup(i8* %46)
%48 = load i8***, i8**** %5
%49 = load i8**, i8*** %48
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
store i8* %47, i8** %53
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %54, i8** %9
br label %55
55: ; preds = %45
%56 = load i8*, i8** %9
%57 = icmp ne i8* %56, null
br i1 %57, label %45, label %58
58: ; preds = %55
br label %59
59: ; preds = %58, %22
%60 = load i32, i32* %7
%61 = load i32*, i32** %6
store i32 %60, i32* %61
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [5 x i8] c"test\00"
define void @parseCommandLine(i8* %0, i8*** nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @strdupa(i8* %0)
%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 %12, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %9, %7 ], [ 1, %3 ]
%9 = add nuw nsw i32 %8, 1
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %7
12: ; preds = %7, %3
%13 = phi i32 [ 1, %3 ], [ %9, %7 ]
%14 = shl i32 %13, 3
%15 = add i32 %14, 8
%16 = tail call i8** @malloc(i32 %15)
store i8** %16, i8*** %1
%17 = zext i32 %13 to i64
%18 = getelementptr inbounds i8*, i8** %16, i64 %17
store i8* null, i8** %18
%19 = tail call dereferenceable_or_null(5) i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %16
%20 = icmp ugt i32 %13, 1
br i1 %20, label %21, label %33
21: ; preds = %12
%22 = tail call i8* @strdupa(i8* %0)
%23 = tail call i8* @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %24, %21
%25 = phi i64 [ %29, %24 ], [ 1, %21 ]
%26 = phi i8* [ %31, %24 ], [ %23, %21 ]
%27 = tail call i8* @strdup(i8* %26)
%28 = load i8**, i8*** %1
%29 = add nuw i64 %25, 1
%30 = getelementptr inbounds i8*, i8** %28, i64 %25
store i8* %27, i8** %30
%31 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %24
33: ; preds = %24, %12
store i32 %13, i32* %2
ret void
}