#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);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
void strToArr(char *s, char **dest) {
  char *temp = malloc(sizeof(char) * 256);
  strcpy(temp, s);
  char *next = malloc(sizeof(char) * 256);
  int count = 0;
  next = strtok(temp, " ");
  while (next != NULL) {
    dest[count] = malloc(sizeof(char) * 256);
    strcpy(dest[count], next);
    count++;
    next = strtok(NULL, " ");
  }
}


x86 assembly (clang, -O0):
<strToArr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11df <strToArr+0xaf>
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2f(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1184 <strToArr+0x54>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strToArr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11ae <strToArr+0x7e>
mov    %rax,%rbx
lea    0xe8f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%r15
test   %rax,%rax
jne    1180 <strToArr+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @strToArr(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 = call i8* @malloc(i32 256)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = call i8* @malloc(i32 256)
store i8* %12, i8** %6
store i32 0, i32* %7
%13 = load i8*, i8** %5
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
br label %15
15: ; preds = %18, %2
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = call i8* @malloc(i32 256)
%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 i8**, i8*** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = load i8*, i8** %6
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %33, i8** %6
br label %15
34: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @strToArr(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%4 = tail call i32 @strcpy(i8* %3, i8* %0)
%5 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %13, %7 ], [ 0, %2 ]
%9 = phi i8* [ %14, %7 ], [ %5, %2 ]
%10 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%11 = getelementptr inbounds i8*, i8** %1, i64 %8
store i8* %10, i8** %11
%12 = tail call i32 @strcpy(i8* %10, i8* %9)
%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, %2
ret void
}