#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 *, int);
size_t strcspn(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
char **tokenize(char *line, char *delimiters) {
  char *current_token;
  int token_count = 0;
  char *copy1 = malloc(strlen(line));
  char *copy2 = malloc(strlen(line));
  memcpy(copy1, line, strlen(line));
  memcpy(copy2, line, strlen(line));
  current_token = strtok(copy1, delimiters);
  while (current_token != NULL) {
    token_count++;
    current_token = strtok(NULL, delimiters);
  }
  char **tokens = malloc(sizeof(char *) * (token_count + 1));
  int index = 0;
  current_token = strtok(copy2, delimiters);
  while (current_token != NULL) {
    current_token[strcspn(current_token, "\n")] = 0;
    tokens[index] = current_token;
    index++;
    current_token = strtok(NULL, delimiters);
  }
  tokens[index] = '\0';
  return tokens;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     121a <tokenize+0xca>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    11f0 <tokenize+0xa0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12a6 <tokenize+0x156>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1249 <tokenize+0xf9>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    $0x8,%ebx
test   %rax,%rax
je     11d2 <tokenize+0x82>
nop
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <strtok@plt>
add    $0x8,%ebx
test   %rax,%rax
jne    11c0 <tokenize+0x70>
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %r13,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     122e <tokenize+0xde>
mov    %rax,%rbx
xor    %r12d,%r12d
lea    0xe07(%rip),%r14
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,(%r15,%r12,8)
add    $0x1,%r12
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <tokenize+0xb0>
mov    %r12d,%eax
jmp    1230 <tokenize+0xe0>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define noalias i8** @tokenize(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 i8* @malloc(i32 %5)
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @memcpy(i8* %4, i8* %0, i32 %7)
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @memcpy(i8* %6, i8* %0, i32 %9)
%11 = tail call i8* @strtok(i8* %4, i8* %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %2, %13
%14 = phi i32 [ %16, %13 ], [ 1, %2 ]
%15 = tail call i8* @strtok(i8* null, i8* %1)
%16 = add i32 %14, 1
%17 = icmp eq i8* %15, null
br i1 %17, label %18, label %13
18: ; preds = %13
%19 = shl i32 %16, 3
br label %20
20: ; preds = %18, %2
%21 = phi i32 [ 8, %2 ], [ %19, %18 ]
%22 = tail call i8* @malloc(i32 %21)
%23 = bitcast i8* %22 to i8**
%24 = tail call i8* @strtok(i8* %6, i8* %1)
%25 = icmp eq i8* %24, null
br i1 %25, label %37, label %26
26: ; preds = %20, %26
%27 = phi i64 [ %32, %26 ], [ 0, %20 ]
%28 = phi i8* [ %33, %26 ], [ %24, %20 ]
%29 = tail call i64 @strcspn(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds i8*, i8** %23, i64 %27
store i8* %28, i8** %31
%32 = add nuw i64 %27, 1
%33 = tail call i8* @strtok(i8* null, i8* %1)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %26
35: ; preds = %26
%36 = and i64 %32, 4294967295
br label %37
37: ; preds = %35, %20
%38 = phi i64 [ 0, %20 ], [ %36, %35 ]
%39 = getelementptr inbounds i8*, i8** %23, i64 %38
store i8* null, i8** %39
ret i8** %23
}