#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char **malloc(int);
int /*<<< orphan*/ stderr;
char *strtok(char *, char *);
char **split_line(char *line) {
  char *token;
  char **tokens = malloc(64 * sizeof(char *));
  int pos = 0;
  if (!tokens) {
    fprintf(stderr, "error\n");
    exit(EXIT_FAILURE);
  }
  token = strtok(line, " \t\r\n\a");
  while (token != NULL) {
    tokens[pos] = token;
    pos++;
    token = strtok(NULL, "\t\r\n\a");
  }
  tokens[pos] = NULL;
  return tokens;
}


x86 assembly (clang, -O0):
<split_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118f <split_line+0x4f>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e0 <split_line+0xa0>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe36(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x10(%rbp)
jmp    11a3 <split_line+0x63>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_line>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x200,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11ae <split_line+0x6e>
mov    %rax,%r15
lea    0xea6(%rip),%rsi
mov    %r14,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     119b <split_line+0x5b>
xor    %ebx,%ebx
lea    0xe91(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <split_line+0x40>
mov    %ebx,%eax
jmp    119d <split_line+0x5d>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"error\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c" \09\0D\0A\07\00"
@.str.2 = [5 x i8] c"\09\0D\0A\07\00"
define noalias i8** @split_line(i8* %0) {
%2 = tail call i8** @malloc(i32 512)
%3 = icmp eq i8** %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %9, %12
%13 = phi i64 [ %16, %12 ], [ 0, %9 ]
%14 = phi i8* [ %17, %12 ], [ %10, %9 ]
%15 = getelementptr inbounds i8*, i8** %2, i64 %13
store i8* %14, i8** %15
%16 = add nuw i64 %13, 1
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %12
19: ; preds = %12
%20 = and i64 %16, 4294967295
br label %21
21: ; preds = %19, %9
%22 = phi i64 [ 0, %9 ], [ %20, %19 ]
%23 = getelementptr inbounds i8*, i8** %2, i64 %22
store i8* null, i8** %23
ret i8** %2
}