#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 **realloc(char **, int);
char *strtok(char *, char *);
char **andysh_tokenize(char *msg) {
  int position = 0;
  int bufferSize = 64;
  char **tokens = malloc(bufferSize * sizeof(char *));
  char *token = strtok(msg, " \r\n\t\a");
  while (token != NULL) {
    tokens[position] = token;
    position++;
    if (position >= 64) {
      bufferSize += 64;
      tokens = realloc(tokens, bufferSize * sizeof(char *));
    }
    token = strtok(NULL, " \r\n\t\a");
  }
  tokens[position] = NULL;
  return tokens;
}


x86 assembly (clang, -O0):
<andysh_tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x40,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d8 <andysh_tokenize+0xa8>
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x40,-0xc(%rbp)
jl     11bf <andysh_tokenize+0x8f>
mov    -0x10(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe36(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1171 <andysh_tokenize+0x41>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<andysh_tokenize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x200,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
lea    0xeb1(%rip),%rsi
mov    %r14,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11af <andysh_tokenize+0x7f>
mov    $0x40,%r12d
xor    %ebx,%ebx
lea    0xe95(%rip),%r14
jmp    1183 <andysh_tokenize+0x53>
nopl   (%rax)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
je     11ab <andysh_tokenize+0x7b>
mov    %rax,(%r15,%rbx,8)
cmp    $0x3f,%rbx
jb     1170 <andysh_tokenize+0x40>
mov    %r12d,%ebp
add    $0x40,%ebp
lea    0x200(,%r12,8),%esi
mov    %r15,%rdi
call   1040 <realloc@plt>
mov    %rax,%r15
mov    %ebp,%r12d
jmp    1170 <andysh_tokenize+0x40>
mov    %ebx,%eax
jmp    11b1 <andysh_tokenize+0x81>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c" \0D\0A\09\07\00"
define i8** @andysh_tokenize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 64, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = call i8** @malloc(i32 %10)
store i8** %11, i8*** %5
%12 = load i8*, i8** %2
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %6
br label %14
14: ; preds = %36, %1
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %38
17: ; preds = %14
%18 = load i8*, i8** %6
%19 = load i8**, i8*** %5
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
store i8* %18, i8** %22
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp sge i32 %25, 64
br i1 %26, label %27, label %36
27: ; preds = %17
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 64
store i32 %29, i32* %4
%30 = load i8**, i8*** %5
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 8
%34 = trunc i64 %33 to i32
%35 = call i8** @realloc(i8** %30, i32 %34)
store i8** %35, i8*** %5
br label %36
36: ; preds = %27, %17
%37 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %37, i8** %6
br label %14
38: ; preds = %14
%39 = load i8**, i8*** %5
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
store i8* null, i8** %42
%43 = load i8**, i8*** %5
ret i8** %43
}

LLVM IR (-O2):
@.str = [6 x i8] c" \0D\0A\09\07\00"
define i8** @andysh_tokenize(i8* %0) {
%2 = tail call i8** @malloc(i32 512)
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %24, label %5
5: ; preds = %1, %17
%6 = phi i64 [ %11, %17 ], [ 0, %1 ]
%7 = phi i8* [ %20, %17 ], [ %3, %1 ]
%8 = phi i8** [ %19, %17 ], [ %2, %1 ]
%9 = phi i32 [ %18, %17 ], [ 64, %1 ]
%10 = getelementptr inbounds i8*, i8** %8, i64 %6
store i8* %7, i8** %10
%11 = add nuw i64 %6, 1
%12 = icmp ugt i64 %6, 62
br i1 %12, label %13, label %17
13: ; preds = %5
%14 = add nsw i32 %9, 64
%15 = shl i32 %14, 3
%16 = tail call i8** @realloc(i8** %8, i32 %15)
br label %17
17: ; preds = %13, %5
%18 = phi i32 [ %14, %13 ], [ %9, %5 ]
%19 = phi i8** [ %16, %13 ], [ %8, %5 ]
%20 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %5
22: ; preds = %17
%23 = and i64 %11, 4294967295
br label %24
24: ; preds = %22, %1
%25 = phi i64 [ 0, %1 ], [ %23, %22 ]
%26 = phi i8** [ %2, %1 ], [ %19, %22 ]
%27 = getelementptr inbounds i8*, i8** %26, i64 %25
store i8* null, i8** %27
ret i8** %26
}