#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);
scalar_t__ realloc(char **, int);
char *strdup(char *);
char *strtok(char *, char *);
char **split_by_space(char *str, int *num) {
  char **final = NULL;
  char *token = NULL;
  char *input = NULL;
  int n = 0;
  input = strdup(str);
  final = (char **)malloc(sizeof(char *));
  if (input != NULL) {
    token = strtok(input, " \t\n\v\f\r");
    while (token != NULL) {
      final = (char **)realloc(final, (sizeof(char *) * (n + 1)));
      final[n] = token;
      n++;
      token = strtok(NULL, " \t\n\v\f\r");
    }
  }
  if (num != NULL)
    *num = n;
  return final;
}


x86 assembly (clang, -O0):
<split_by_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1206 <split_by_space+0xc6>
mov    -0x28(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1201 <split_by_space+0xc1>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe0d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11a9 <split_by_space+0x69>
jmp    1206 <split_by_space+0xc6>
cmpq   $0x0,-0x10(%rbp)
je     121a <split_by_space+0xda>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_by_space>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
xor    %r14d,%r14d
test   %rbx,%rbx
je     11d1 <split_by_space+0x91>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11d1 <split_by_space+0x91>
mov    %rax,%rbx
mov    %rbp,(%rsp)
mov    $0x8,%ebp
xor    %r14d,%r14d
lea    0xe6b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%r13
add    $0x1,%r14
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,%r15
mov    %rbx,(%rax,%r13,8)
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%ebp
test   %rax,%rax
jne    11a0 <split_by_space+0x60>
mov    (%rsp),%rbp
test   %rbp,%rbp
je     11da <split_by_space+0x9a>
mov    %r14d,0x0(%rbp)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c" \09\0A\0B\0C\0D\00"
define i8** @split_by_space(i8* nocapture %0, i32* writeonly %1) {
%3 = tail call i8* @strdup(i8* %0)
%4 = tail call i64 @malloc(i32 8)
%5 = inttoptr i64 %4 to i8**
%6 = icmp eq i8* %3, null
br i1 %6, label %25, label %7
7: ; preds = %2
%8 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %7, %10
%11 = phi i64 [ %14, %10 ], [ 0, %7 ]
%12 = phi i8* [ %20, %10 ], [ %8, %7 ]
%13 = phi i8** [ %18, %10 ], [ %5, %7 ]
%14 = add nuw i64 %11, 1
%15 = trunc i64 %14 to i32
%16 = shl i32 %15, 3
%17 = tail call i64 @realloc(i8** %13, i32 %16)
%18 = inttoptr i64 %17 to i8**
%19 = getelementptr inbounds i8*, i8** %18, i64 %11
store i8* %12, i8** %19
%20 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %10
22: ; preds = %10
%23 = trunc i64 %14 to i32
%24 = inttoptr i64 %17 to i8**
br label %25
25: ; preds = %22, %7, %2
%26 = phi i8** [ %5, %2 ], [ %5, %7 ], [ %24, %22 ]
%27 = phi i32 [ 0, %2 ], [ 0, %7 ], [ %23, %22 ]
%28 = icmp eq i32* %1, null
br i1 %28, label %30, label %29
29: ; preds = %25
store i32 %27, i32* %1
br label %30
30: ; preds = %29, %25
ret i8** %26
}