#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 **calloc(int, int);
char **realloc(char **, int);
char *strchr(char *, char);
char *strdup(char *);
int makeargs(char *args, int *argc, char ***aa) {
  char *buf = strdup(args);
  int c = 1;
  char *delim;
  char **argv = calloc(c, sizeof(char *));
  argv[0] = buf;
  while ((delim = strchr(argv[c - 1], ' '))) {
    argv = realloc(argv, (c + 1) * sizeof(char *));
    argv[c] = delim + 1;
    *delim = 0x00;
    c++;
  }
  *argc = c;
  *aa = argv;
  return c;
}


x86 assembly (clang, -O0):
<makeargs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11f1 <makeargs+0xb1>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdx
add    $0x1,%rdx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <makeargs+0x44>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeargs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r15
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    $0x1,%r14d
mov    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
mov    %rbx,(%rax)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11de <makeargs+0x9e>
mov    %rax,%rbx
mov    %rbp,(%rsp)
mov    $0x1,%r14d
mov    $0x10,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%r12
add    $0x1,%r14
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,%r13
lea    0x1(%rbx),%rax
mov    %rax,0x0(%r13,%r12,8)
movb   $0x0,(%rbx)
mov    0x0(%r13,%r12,8),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
add    $0x8,%ebp
test   %rax,%rax
jne    11a0 <makeargs+0x60>
mov    (%rsp),%rbp
mov    %r14d,(%r15)
mov    %r13,0x0(%rbp)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @makeargs(i8* %0, i32* %1, i8*** %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8***
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8**
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8*** %2, i8**** %6
%11 = load i8*, i8** %4
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %7
store i32 1, i32* %8
%13 = load i32, i32* %8
%14 = call i8** @calloc(i32 %13, i32 8)
store i8** %14, i8*** %10
%15 = load i8*, i8** %7
%16 = load i8**, i8*** %10
%17 = getelementptr inbounds i8*, i8** %16, i64 0
store i8* %15, i8** %17
br label %18
18: ; preds = %27, %3
%19 = load i8**, i8*** %10
%20 = load i32, i32* %8
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %19, i64 %22
%24 = load i8*, i8** %23
%25 = call i8* @strchr(i8* %24, i8 signext 32)
store i8* %25, i8** %9
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %44
27: ; preds = %18
%28 = load i8**, i8*** %10
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = call i8** @realloc(i8** %28, i32 %33)
store i8** %34, i8*** %10
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8**, i8*** %10
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
store i8* %36, i8** %40
%41 = load i8*, i8** %9
store i8 0, i8* %41
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %18
44: ; preds = %18
%45 = load i32, i32* %8
%46 = load i32*, i32** %5
store i32 %45, i32* %46
%47 = load i8**, i8*** %10
%48 = load i8***, i8**** %6
store i8** %47, i8*** %48
%49 = load i32, i32* %8
ret i32 %49
}

LLVM IR (-O2):
define i32 @makeargs(i8* nocapture %0, i32* nocapture writeonly %1, i8*** nocapture writeonly %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8** @calloc(i32 1, i32 8)
store i8* %4, i8** %5
%6 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %23, label %8
8: ; preds = %3, %8
%9 = phi i64 [ %12, %8 ], [ 1, %3 ]
%10 = phi i8* [ %19, %8 ], [ %6, %3 ]
%11 = phi i8** [ %15, %8 ], [ %5, %3 ]
%12 = add nuw i64 %9, 1
%13 = trunc i64 %12 to i32
%14 = shl i32 %13, 3
%15 = tail call i8** @realloc(i8** %11, i32 %14)
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = getelementptr inbounds i8*, i8** %15, i64 %9
store i8* %16, i8** %17
store i8 0, i8* %10
%18 = load i8*, i8** %17
%19 = tail call i8* @strchr(i8* dereferenceable(1) %18, i8 signext 32)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %8
21: ; preds = %8
%22 = trunc i64 %12 to i32
br label %23
23: ; preds = %21, %3
%24 = phi i32 [ 1, %3 ], [ %22, %21 ]
%25 = phi i8** [ %5, %3 ], [ %15, %21 ]
store i32 %24, i32* %1
store i8** %25, i8*** %2
ret i32 %24
}