#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 *strtok(char *, char *);
char **split_by_space(char *str, int *num) {
  char **final = NULL;
  char *token = NULL;
  char *input = str;
  int n = 0;
  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)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e9 <split_by_space+0xb9>
mov    -0x28(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e4 <split_by_space+0xb4>
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    0xe2a(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    118c <split_by_space+0x5c>
jmp    11e9 <split_by_space+0xb9>
cmpq   $0x0,-0x10(%rbp)
je     11fd <split_by_space+0xcd>
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
mov    %rdi,%rbx
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
xor    %r14d,%r14d
test   %rbx,%rbx
je     11b1 <split_by_space+0x81>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11b1 <split_by_space+0x81>
mov    %rax,%rbx
mov    %rbp,(%rsp)
mov    $0x8,%ebp
xor    %r14d,%r14d
lea    0xe80(%rip),%r12
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    1180 <split_by_space+0x50>
mov    (%rsp),%rbp
test   %rbp,%rbp
je     11ba <split_by_space+0x8a>
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
%9 = load i8*, i8** %3
store i8* %9, i8** %7
store i32 0, i32* %8
%10 = call i64 @malloc(i32 8)
%11 = inttoptr i64 %10 to i8**
store i8** %11, i8*** %5
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %38
14: ; preds = %2
%15 = load i8*, i8** %7
%16 = call i8* @strtok(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %6
br label %17
17: ; preds = %20, %14
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 8, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @realloc(i8** %21, i32 %26)
%28 = inttoptr i64 %27 to i8**
store i8** %28, i8*** %5
%29 = load i8*, i8** %6
%30 = load i8**, i8*** %5
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
store i8* %29, i8** %33
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %36, i8** %6
br label %17
37: ; preds = %17
br label %38
38: ; preds = %37, %2
%39 = load i32*, i32** %4
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %8
%43 = load i32*, i32** %4
store i32 %42, i32* %43
br label %44
44: ; preds = %41, %38
%45 = load i8**, i8*** %5
ret i8** %45
}

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