#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);
char *strncpy(char *, char *, int);
char *strtok(char *, char *);
char **tokeniseUserCommand(char *command) {
  char *buff = malloc(sizeof(char) * 300);
  buff = strncpy(buff, command, sizeof(char) * 300);
  char **tokens = malloc(sizeof(char) * 300);
  char *token = malloc(50);
  int i = 0;
  token = strtok(buff, " ");
  tokens[i] = token;
  while (token != 0) {
    i++;
    token = strtok(NULL, " ");
    tokens[i] = token;
  }
  return tokens;
}


x86 assembly (clang, -O0):
<tokeniseUserCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x12c,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x12c,%edx
call   1030 <strncpy@plt>
mov    %rax,-0x10(%rbp)
mov    $0x12c,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x32,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x0,-0x20(%rbp)
je     11e4 <tokeniseUserCommand+0xb4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe3a(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11a7 <tokeniseUserCommand+0x77>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokeniseUserCommand>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x12c,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x12c,%edx
call   1030 <strncpy@plt>
mov    %rax,%rbx
mov    $0x12c,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11a6 <tokeniseUserCommand+0x76>
mov    %r14,%rbx
add    $0x8,%rbx
lea    0xe79(%rip),%r15
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
test   %rax,%rax
jne    1190 <tokeniseUserCommand+0x60>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8** @tokeniseUserCommand(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i8* @malloc(i32 300)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = load i8*, i8** %2
%10 = call i8* @strncpy(i8* %8, i8* %9, i32 300)
store i8* %10, i8** %3
%11 = call i8* @malloc(i32 300)
%12 = bitcast i8* %11 to i8**
store i8** %12, i8*** %4
%13 = call i8* @malloc(i32 50)
store i8* %13, i8** %5
store i32 0, i32* %6
%14 = load i8*, i8** %3
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i8**, i8*** %4
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
store i8* %16, i8** %20
br label %21
21: ; preds = %24, %1
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = load i8**, i8*** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
store i8* %28, i8** %32
br label %21
33: ; preds = %21
%34 = load i8**, i8*** %4
ret i8** %34
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define noalias i8** @tokeniseUserCommand(i8* %0) {
%2 = tail call dereferenceable_or_null(300) i8* @malloc(i32 300)
%3 = tail call i8* @strncpy(i8* %2, i8* %0, i32 300)
%4 = tail call dereferenceable_or_null(300) i8* @malloc(i32 300)
%5 = bitcast i8* %4 to i8**
%6 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %10, %8 ], [ 0, %1 ]
%10 = add nuw nsw i64 %9, 1
%11 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %5, i64 %10
store i8* %11, i8** %12
%13 = icmp eq i8* %11, null
br i1 %13, label %14, label %8
14: ; preds = %8, %1
ret i8** %5
}