#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 const *);
char **split_by_char(char *str, const char *delimeter, int *num) {
  char **final = NULL;
  char *token;
  char *input = str;
  int n = 0;
  final = (char **)malloc(sizeof(char *));
  if (input != NULL) {
    token = strtok(input, delimeter);
    while (token != NULL) {
      final = (char **)realloc(final, (sizeof(char *) * (n + 1)));
      final[n] = token;
      n++;
      token = strtok(NULL, delimeter);
    }
  }
  if (num != NULL)
    *num = n;
  return final;
}


x86 assembly (clang, -O0):
<split_by_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11df <split_by_char+0xaf>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11da <split_by_char+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1185 <split_by_char+0x55>
jmp    11df <split_by_char+0xaf>
cmpq   $0x0,-0x18(%rbp)
je     11f3 <split_by_char+0xc3>
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_by_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,%r12
xor    %r14d,%r14d
test   %rbx,%rbx
je     11b1 <split_by_char+0x81>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     11b1 <split_by_char+0x81>
mov    %rax,%rbx
mov    %rbp,(%rsp)
mov    $0x8,%ebp
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    %r14,%r13
add    $0x1,%r14
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,%r12
mov    %rbx,(%rax,%r13,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%ebp
test   %rax,%rax
jne    1180 <split_by_char+0x50>
mov    (%rsp),%rbp
test   %rbp,%rbp
je     11ba <split_by_char+0x8a>
mov    %r14d,0x0(%rbp)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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