#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char const *);
char **tokenize_str(char *str) {
  char **token_arr = (char **)(malloc((4 + 1) * sizeof(char *)));
  int i;
  for (i = 0; i < (4 + 1); i++) {
    token_arr[i] = NULL;
  }
  i = 0;
  char *token;
  static const char *DELIM_STR = " \t\r\n";
  token = strtok(str, DELIM_STR);
  while (NULL != token) {
    token_arr[i] = (char *)(malloc((strlen(token) + 1) * sizeof(char *)));
    strcpy(token_arr[i], token);
    token = strtok(NULL, DELIM_STR);
    i++;
  }
  return token_arr;
}


x86 assembly (clang, -O0):
<tokenize_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1189 <tokenize_str+0x49>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <tokenize_str+0x21>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea5(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     120f <tokenize_str+0xcf>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2e4c(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <tokenize_str+0x64>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xorps  %xmm0,%xmm0
movups %xmm0,(%rax)
movups %xmm0,0x10(%rax)
movq   $0x0,0x20(%rax)
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c8 <tokenize_str+0x88>
mov    %rax,%r12
lea    0xe78(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x8(,%rax,8),%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1060 <strtok@plt>
mov    %rax,%r12
add    $0x8,%rbx
test   %rax,%rax
jne    1190 <tokenize_str+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0D\0A\00"
define i8** @tokenize_str(i8* %0) {
%2 = tail call i64 @malloc(i32 40)
%3 = inttoptr i64 %2 to i8**
%4 = inttoptr i64 %2 to i8*
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %18, %7 ], [ 0, %1 ]
%9 = phi i8* [ %17, %7 ], [ %5, %1 ]
%10 = tail call i32 @strlen(i8* %9)
%11 = shl i32 %10, 3
%12 = add i32 %11, 8
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = getelementptr inbounds i8*, i8** %3, i64 %8
store i8* %14, i8** %15
%16 = tail call i32 @strcpy(i8* %14, i8* %9)
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = add nuw i64 %8, 1
%19 = icmp eq i8* %17, null
br i1 %19, label %20, label %7
20: ; preds = %7, %1
ret i8** %3
}