#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);
int strlen(char *);
char *strtok(char *, char *);
char **parse_line(char *line) {
  char **tokens = malloc((strlen(line) + 1) * sizeof(char *));
  int tokIdx = 0;
  tokens[tokIdx] = strtok(line, " ");
  while (tokens[tokIdx] != NULL) {
    tokIdx++;
    tokens[tokIdx] = strtok(NULL, " ");
  }
  return tokens;
}


x86 assembly (clang, -O0):
<parse_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <strtok@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
cmpq   $0x0,(%rax,%rcx,8)
je     11bf <parse_line+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe5a(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    117f <parse_line+0x4f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x8(,%rax,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1196 <parse_line+0x66>
mov    %r14,%rbx
add    $0x8,%rbx
lea    0xe8f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
test   %rax,%rax
jne    1180 <parse_line+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define noalias i8** @parse_line(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl i32 %2, 3
%4 = add i32 %3, 8
%5 = tail call i8** @malloc(i32 %4)
%6 = tail call i8* @strtok(i8* %0, 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
}