#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 getArgCount(char *);
int isspace(char);
char **malloc(int);
char *nextArg(char *);
void createArgsArray(int *argc, char ***args, char *argsBuffer) {
  *argc = getArgCount(argsBuffer);
  *args = malloc(sizeof(void *) * (*argc + 1));
  (*args)[*argc] = NULL;
  int i = 0;
  argsBuffer = nextArg(argsBuffer);
  while (*argsBuffer != 0) {
    (*args)[i] = argsBuffer;
    while (!(isspace(*argsBuffer) | *argsBuffer == 0)) {
      ++argsBuffer;
    }
    char *argEnd = argsBuffer;
    argsBuffer = nextArg(argsBuffer);
    *argEnd = 0;
    ++i;
  }
}


x86 assembly (clang, -O0):
<createArgsArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <getArgCount@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <nextArg@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1243 <createArgsArray+0x103>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    $0x0,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1208 <createArgsArray+0xc8>
jmp    1219 <createArgsArray+0xd9>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11d2 <createArgsArray+0x92>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <nextArg@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11af <createArgsArray+0x6f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createArgsArray>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1060 <getArgCount@plt>
mov    %eax,%ebx
mov    %eax,(%r15)
lea    0x8(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
movslq %ebx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    %r12,%rdi
call   1050 <nextArg@plt>
cmpb   $0x0,(%rax)
je     11d6 <createArgsArray+0x96>
mov    %rax,%r12
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rax
mov    %r12,(%rax,%r15,8)
add    $0xffffffffffffffff,%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rbx
add    $0x1,%r12
movsbl 0x1(%rbx),%edi
call   1030 <isspace@plt>
xor    %ecx,%ecx
cmpb   $0x0,0x1(%rbx)
sete   %cl
or     %eax,%ecx
je     11a0 <createArgsArray+0x60>
mov    %r12,%rdi
call   1050 <nextArg@plt>
movb   $0x0,(%r12)
add    $0x1,%r15
cmpb   $0x0,(%rax)
mov    %rax,%r12
jne    1190 <createArgsArray+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @createArgsArray(i32* %0, i8*** %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8***
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %4
store i8*** %1, i8**** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32 @getArgCount(i8* %9)
%11 = load i32*, i32** %4
store i32 %10, i32* %11
%12 = load i32*, i32** %4
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i8** @malloc(i32 %17)
%19 = load i8***, i8**** %5
store i8** %18, i8*** %19
%20 = load i8***, i8**** %5
%21 = load i8**, i8*** %20
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
store i8* null, i8** %25
store i32 0, i32* %7
%26 = load i8*, i8** %6
%27 = call i8* @nextArg(i8* %26)
store i8* %27, i8** %6
br label %28
28: ; preds = %55, %3
%29 = load i8*, i8** %6
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %62
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = load i8***, i8**** %5
%36 = load i8**, i8*** %35
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
store i8* %34, i8** %39
br label %40
40: ; preds = %52, %33
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = call i32 @isspace(i8 signext %42)
%44 = load i8*, i8** %6
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i32
%49 = or i32 %43, %48
%50 = icmp ne i32 %49, 0
%51 = xor i1 %50, true
br i1 %51, label %52, label %55
52: ; preds = %40
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %6
br label %40
55: ; preds = %40
%56 = load i8*, i8** %6
store i8* %56, i8** %8
%57 = load i8*, i8** %6
%58 = call i8* @nextArg(i8* %57)
store i8* %58, i8** %6
%59 = load i8*, i8** %8
store i8 0, i8* %59
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %28
62: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @createArgsArray(i32* nocapture writeonly %0, i8*** nocapture %1, i8* %2) {
%4 = tail call i32 @getArgCount(i8* %2)
store i32 %4, i32* %0
%5 = shl i32 %4, 3
%6 = add i32 %5, 8
%7 = tail call i8** @malloc(i32 %6)
store i8** %7, i8*** %1
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds i8*, i8** %7, i64 %8
store i8* null, i8** %9
%10 = tail call i8* @nextArg(i8* %2)
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %33, label %13
13: ; preds = %3, %28
%14 = phi i64 [ %30, %28 ], [ 0, %3 ]
%15 = phi i8* [ %29, %28 ], [ %10, %3 ]
%16 = load i8**, i8*** %1
%17 = getelementptr inbounds i8*, i8** %16, i64 %14
store i8* %15, i8** %17
br label %18
18: ; preds = %18, %13
%19 = phi i8* [ %15, %13 ], [ %27, %18 ]
%20 = load i8, i8* %19
%21 = tail call i32 @isspace(i8 signext %20)
%22 = load i8, i8* %19
%23 = icmp eq i8 %22, 0
%24 = zext i1 %23 to i32
%25 = or i32 %21, %24
%26 = icmp eq i32 %25, 0
%27 = getelementptr inbounds i8, i8* %19, i64 1
br i1 %26, label %18, label %28
28: ; preds = %18
%29 = tail call i8* @nextArg(i8* %19)
store i8 0, i8* %19
%30 = add nuw i64 %14, 1
%31 = load i8, i8* %29
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %13
33: ; preds = %28, %3
ret void
}