#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(int);
char **realloc(char **, int);
char *strtok(char *, char *);
char **split_into_tokens(char *input, char *delimiter) {
  char **res = NULL;
  char *p = strtok(input, delimiter);
  int n_spaces = 0;
  while (p) {
    res = realloc(res, sizeof(char *) * ++n_spaces);
    if (res == NULL)
      exit(-1);
    res[n_spaces - 1] = p;
    p = strtok(NULL, delimiter);
  }
  res = realloc(res, sizeof(char *) * (n_spaces + 1));
  res[n_spaces] = 0;
  return res;
}


x86 assembly (clang, -O0):
<split_into_tokens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c9 <split_into_tokens+0x99>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119e <split_into_tokens+0x6e>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1160 <split_into_tokens+0x30>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_into_tokens>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
call   1040 <strtok@plt>
test   %rax,%rax
je     1191 <split_into_tokens+0x61>
mov    %rax,%r15
mov    $0x8,%ebp
xor    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <realloc@plt>
test   %rax,%rax
je     11ba <split_into_tokens+0x8a>
mov    %rax,%rbx
mov    %r15,(%rax,%r12,8)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
mov    %rax,%r15
add    $0x8,%ebp
add    $0x1,%r12
test   %rax,%rax
jne    1160 <split_into_tokens+0x30>
jmp    1196 <split_into_tokens+0x66>
xor    %ebx,%ebx
xor    %r12d,%r12d
lea    0x8(,%r12,8),%esi
mov    %rbx,%rdi
call   1030 <realloc@plt>
mov    %r12d,%ecx
movq   $0x0,(%rax,%rcx,8)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define i8** @split_into_tokens(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8** null, i8*** %5
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = call i8* @strtok(i8* %8, i8* %9)
store i8* %10, i8** %6
store i32 0, i32* %7
br label %11
11: ; preds = %26, %2
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = load i8**, i8*** %5
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = sext i32 %17 to i64
%19 = mul i64 8, %18
%20 = trunc i64 %19 to i32
%21 = call i8** @realloc(i8** %15, i32 %20)
store i8** %21, i8*** %5
%22 = load i8**, i8*** %5
%23 = icmp eq i8** %22, null
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %14
%27 = load i8*, i8** %6
%28 = load i8**, i8*** %5
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
store i8* %27, i8** %32
%33 = load i8*, i8** %4
%34 = call i8* @strtok(i8* null, i8* %33)
store i8* %34, i8** %6
br label %11
35: ; preds = %11
%36 = load i8**, i8*** %5
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = mul i64 8, %39
%41 = trunc i64 %40 to i32
%42 = call i8** @realloc(i8** %36, i32 %41)
store i8** %42, i8*** %5
%43 = load i8**, i8*** %5
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
store i8* null, i8** %46
%47 = load i8**, i8*** %5
ret i8** %47
}

LLVM IR (-O2):
define i8** @split_into_tokens(i8* %0, i8* nocapture %1) {
%3 = tail call i8* @strtok(i8* %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %22, label %5
5: ; preds = %2, %16
%6 = phi i64 [ %9, %16 ], [ 0, %2 ]
%7 = phi i8* [ %18, %16 ], [ %3, %2 ]
%8 = phi i8** [ %12, %16 ], [ null, %2 ]
%9 = add nuw i64 %6, 1
%10 = trunc i64 %9 to i32
%11 = shl i32 %10, 3
%12 = tail call i8** @realloc(i8** %8, i32 %11)
%13 = icmp eq i8** %12, null
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %5
%17 = getelementptr inbounds i8*, i8** %12, i64 %6
store i8* %7, i8** %17
%18 = tail call i8* @strtok(i8* null, i8* %1)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %5
20: ; preds = %16
%21 = trunc i64 %9 to i32
br label %22
22: ; preds = %20, %2
%23 = phi i8** [ null, %2 ], [ %12, %20 ]
%24 = phi i32 [ 0, %2 ], [ %21, %20 ]
%25 = shl i32 %24, 3
%26 = add i32 %25, 8
%27 = tail call i8** @realloc(i8** %23, i32 %26)
%28 = zext i32 %24 to i64
%29 = getelementptr inbounds i8*, i8** %27, i64 %28
store i8* null, i8** %29
ret i8** %27
}