#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_char(char *OrigStr, char *delimeter) {
  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, delimeter);
    final[n] = buffer;
    n++;
    while (1) {
      buffer = strtok(NULL, delimeter);
      if (buffer == NULL)
        break;
      final = (char **)realloc(final, (sizeof(char *) * (n + 1)));
      final[n] = buffer;
      n++;
    }
  }
  return final;
}


x86 assembly (clang, -O0):
<split_by_char>:
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     124c <split_by_char+0xfc>
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
mov    -0x10(%rbp),%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)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    120e <split_by_char+0xbe>
jmp    1247 <split_by_char+0xf7>
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    11ed <split_by_char+0x9d>
jmp    124c <split_by_char+0xfc>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_by_char>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     11ed <split_by_char+0x9d>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strtok@plt>
mov    %rax,(%r15)
xor    %edi,%edi
mov    %r14,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11f0 <split_by_char+0xa0>
mov    %rax,%r13
mov    $0x8,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x8(%rbx),%r12
mov    %r15,%rdi
mov    %r12d,%esi
call   1060 <realloc@plt>
mov    %rax,%r15
mov    %r13,(%rax,%rbx,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1070 <strtok@plt>
mov    %rax,%r13
mov    %r12,%rbx
test   %rax,%rax
jne    11c0 <split_by_char+0x70>
jmp    11f0 <split_by_char+0xa0>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @split_by_char(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %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 %57
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 = load i8*, i8** %4
%26 = call i8* @strtok(i8* %24, i8* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = load i8**, i8*** %6
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
store i8* %27, i8** %31
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %34
34: ; preds = %11, %40
%35 = load i8*, i8** %4
%36 = call i8* @strtok(i8* null, i8* %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %34
br label %56
40: ; preds = %34
%41 = load i8**, i8*** %6
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = mul i64 8, %44
%46 = trunc i64 %45 to i32
%47 = call i64 @realloc(i8** %41, i32 %46)
%48 = inttoptr i64 %47 to i8**
store i8** %48, i8*** %6
%49 = load i8*, i8** %7
%50 = load i8**, i8*** %6
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
store i8* %49, i8** %53
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %34
56: ; preds = %39
br label %57
57: ; preds = %56, %2
%58 = load i8**, i8*** %6
ret i8** %58
}

LLVM IR (-O2):
define i8** @split_by_char(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %28, 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* %1)
store i8* %11, i8** %10
%12 = tail call i8* @strtok(i8* null, i8* %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %28, 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* %1)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %14
26: ; preds = %14
%27 = inttoptr i64 %21 to i8**
br label %28
28: ; preds = %26, %4, %2
%29 = phi i8** [ null, %2 ], [ %10, %4 ], [ %27, %26 ]
ret i8** %29
}