#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 */
void *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strtok(char *, char *);
int makeargv(const char *s, char ***argv) {
  char *t = malloc(strlen(s));
  memcpy(t, s, strlen(s));
  char *tmp = strtok(t, " ");
  int idx = 0;
  while (tmp != NULL) {
    idx++;
    tmp = strtok(NULL, " ");
  }
  *argv = malloc((idx + 1) * (sizeof(char *)));
  strcpy(t, s);
  **argv = strtok(t, " ");
  int i = 1;
  for (; i < idx; i++)
    *((*argv) + i) = strtok(NULL, " ");
  *((*argv) + idx) = NULL;
  return idx;
}


x86 assembly (clang, -O0):
<makeargv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e4 <makeargv+0x94>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11b7 <makeargv+0x67>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    126e <makeargv+0x11e>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb7(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1232 <makeargv+0xe2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeargv>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
lea    0xe76(%rip),%rsi
mov    %r15,%rdi
call   1070 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11b2 <makeargv+0x62>
lea    0xe60(%rip),%r13
add    $0x1,%ebx
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    11a0 <makeargv+0x50>
lea    0x8(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,(%r12)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe2c(%rip),%rsi
mov    %r15,%rdi
call   1070 <strtok@plt>
mov    (%r12),%rcx
mov    %rax,(%rcx)
mov    %ebx,%r15d
cmp    $0x2,%ebx
jb     121b <makeargv+0xcb>
mov    $0x1,%ebx
lea    0xe09(%rip),%r14
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1070 <strtok@plt>
mov    (%r12),%rcx
mov    %rax,(%rcx,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1200 <makeargv+0xb0>
mov    (%r12),%rax
movq   $0x0,(%rax,%r15,8)
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @makeargv(i8* %0, i8*** %1) {
%3 = alloca i8*
%4 = alloca i8***
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8*** %1, i8**** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @memcpy(i8* %12, i8* %13, i32 %15)
%17 = load i8*, i8** %5
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %6
store i32 0, i32* %7
br label %19
19: ; preds = %22, %2
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %6
br label %19
26: ; preds = %19
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = trunc i64 %30 to i32
%32 = call i8* @malloc(i32 %31)
%33 = bitcast i8* %32 to i8**
%34 = load i8***, i8**** %4
store i8** %33, i8*** %34
%35 = load i8*, i8** %5
%36 = load i8*, i8** %3
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %5
%39 = call i8* @strtok(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%40 = load i8***, i8**** %4
%41 = load i8**, i8*** %40
store i8* %39, i8** %41
store i32 1, i32* %8
br label %42
42: ; preds = %53, %26
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%48 = load i8***, i8**** %4
%49 = load i8**, i8*** %48
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
store i8* %47, i8** %52
br label %53
53: ; preds = %46
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %42
56: ; preds = %42
%57 = load i8***, i8**** %4
%58 = load i8**, i8*** %57
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
store i8* null, i8** %61
%62 = load i32, i32* %7
ret i32 %62
}

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