#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 *strtok(char *, char *);
char **tokenise(char *cmd) {
  int size = 4096, num = 0;
  char **tokens = malloc(size * sizeof(char *));
  char *token;
  token = strtok(cmd, " \t\r\n\a");
  while (token != NULL) {
    tokens[num] = token;
    num++;
    token = strtok(NULL, " \t\r\n\a");
  }
  tokens[num] = NULL;
  return tokens;
}


x86 assembly (clang, -O0):
<tokenise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1000,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119e <tokenise+0x7e>
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe70(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1161 <tokenise+0x41>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenise>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x8000,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
lea    0xec4(%rip),%rsi
mov    %r14,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     117b <tokenise+0x5b>
xor    %ebx,%ebx
lea    0xeae(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1160 <tokenise+0x40>
mov    %ebx,%eax
jmp    117d <tokenise+0x5d>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c" \09\0D\0A\07\00"
define i8** @tokenise(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %2
store i32 4096, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %3
%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 = %17, %1
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i8*, i8** %6
%19 = load i8**, i8*** %5
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
store i8* %18, i8** %22
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %6
br label %14
26: ; preds = %14
%27 = load i8**, i8*** %5
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
store i8* null, i8** %30
%31 = load i8**, i8*** %5
ret i8** %31
}

LLVM IR (-O2):
@.str = [6 x i8] c" \09\0D\0A\07\00"
define noalias i8** @tokenise(i8* %0) {
%2 = tail call i8** @malloc(i32 32768)
%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 %14, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %9, %5 ], [ 0, %1 ]
%7 = phi i8* [ %10, %5 ], [ %3, %1 ]
%8 = getelementptr inbounds i8*, i8** %2, i64 %6
store i8* %7, i8** %8
%9 = add nuw i64 %6, 1
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = and i64 %9, 4294967295
br label %14
14: ; preds = %12, %1
%15 = phi i64 [ 0, %1 ], [ %13, %12 ]
%16 = getelementptr inbounds i8*, i8** %2, i64 %15
store i8* null, i8** %16
ret i8** %2
}