#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);
scalar_t__ realloc(char **, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
char **split_by_space(char *OrigStr, int *num) {
  char *str = NULL;
  char **final = NULL;
  char *buffer = NULL;
  int n = 0;
  if (OrigStr != NULL) {
    str = malloc(sizeof(char) * strlen(OrigStr) + 1);
    strcpy(str, OrigStr);
    final = (char **)malloc(sizeof(char *));
    buffer = strtok(str, " \t\n\v\f\r");
    final[n] = buffer;
    n++;
    while (1) {
      buffer = strtok(NULL, " \t\n\v\f\r");
      if (buffer == NULL)
        break;
      final = (char **)realloc(final, (sizeof(char *) * (n + 1)));
      final[n] = buffer;
      n++;
    }
  }
  *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)
cmpq   $0x0,-0x8(%rbp)
je     1252 <split_by_space+0x102>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x20(%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    0xe05(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1214 <split_by_space+0xc4>
jmp    124d <split_by_space+0xfd>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f0 <split_by_space+0xa0>
jmp    1252 <split_by_space+0x102>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%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,%r12
test   %rdi,%rdi
je     1203 <split_by_space+0xb3>
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe67(%rip),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <strtok@plt>
mov    %rax,(%r15)
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     120b <split_by_space+0xbb>
mov    %rax,%rbx
mov    %r12,(%rsp)
mov    $0x1,%r14d
mov    $0x10,%ebp
lea    0xe31(%rip),%r12
nop
mov    %r14,%r13
add    $0x1,%r14
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <realloc@plt>
mov    %rax,%r15
mov    %rbx,(%rax,%r13,8)
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%ebp
test   %rax,%rax
jne    11d0 <split_by_space+0x80>
mov    (%rsp),%r12
jmp    1211 <split_by_space+0xc1>
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    1211 <split_by_space+0xc1>
mov    $0x1,%r14d
mov    %r14d,(%r12)
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 = icmp ne i8* %9, null
br i1 %10, label %11, label %55
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = add i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = call i8* @malloc(i32 8)
%23 = bitcast i8* %22 to i8**
store i8** %23, i8*** %6
%24 = load i8*, i8** %5
%25 = call i8* @strtok(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = load i8**, i8*** %6
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
store i8* %26, i8** %30
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %33
33: ; preds = %11, %38
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %38
37: ; preds = %33
br label %54
38: ; preds = %33
%39 = load i8**, i8*** %6
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = mul i64 8, %42
%44 = trunc i64 %43 to i32
%45 = call i64 @realloc(i8** %39, i32 %44)
%46 = inttoptr i64 %45 to i8**
store i8** %46, i8*** %6
%47 = load i8*, i8** %7
%48 = load i8**, i8*** %6
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* %47, i8** %51
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %33
54: ; preds = %37
br label %55
55: ; preds = %54, %2
%56 = load i32, i32* %8
%57 = load i32*, i32** %4
store i32 %56, i32* %57
%58 = load i8**, i8*** %6
ret i8** %58
}

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