#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 */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int num_words_with_delimiter(char *, char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
char *strtok(char *, char *);
char **split_on_delimiter(char *input, char *delimiters) {
  int num_words = num_words_with_delimiter(input, delimiters);
  char **output = (char **)malloc((num_words + 1) * sizeof(char **));
  char *input_copy = strdup(input);
  int count = 0;
  char *word = strtok(input_copy, delimiters);
  while (word != NULL) {
    if (strcmp(word, "") == 0) {
      word = NULL;
      continue;
    }
    *(output + count) = strdup(word);
    count++;
    word = strtok(NULL, delimiters);
  }
  *(output + count) = (char *)NULL;
  free(input_copy);
  return output;
}


x86 assembly (clang, -O0):
<split_on_delimiter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <num_words_with_delimiter@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1225 <split_on_delimiter+0xc5>
mov    -0x38(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ee <split_on_delimiter+0x8e>
movq   $0x0,-0x38(%rbp)
jmp    11bc <split_on_delimiter+0x5c>
mov    -0x38(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%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,-0x38(%rbp)
jmp    11bc <split_on_delimiter+0x5c>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_on_delimiter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <num_words_with_delimiter@plt>
lea    0x8(,%rax,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
xor    %ebp,%ebp
lea    0xe67(%rip),%r13
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strtok@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %rax,%rax
je     11e4 <split_on_delimiter+0x84>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
mov    $0x0,%eax
test   %rcx,%rcx
je     11b0 <split_on_delimiter+0x50>
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,(%r12,%rbp,8)
add    $0x1,%rbp
xor    %edi,%edi
jmp    119c <split_on_delimiter+0x3c>
mov    %ebp,%eax
movq   $0x0,(%r12,%rax,8)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8** @split_on_delimiter(i8* %0, i8* %1) {
%3 = tail call i32 @num_words_with_delimiter(i8* %0, i8* %1)
%4 = shl i32 %3, 3
%5 = add i32 %4, 8
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8**
%8 = tail call i8* @strdup(i8* %0)
br label %9
9: ; preds = %19, %2
%10 = phi i8* [ null, %19 ], [ %8, %2 ]
%11 = phi i64 [ %22, %19 ], [ 0, %2 ]
%12 = tail call i8* @strtok(i8* %10, i8* %1)
br label %13
13: ; preds = %9, %16
%14 = phi i8* [ null, %16 ], [ %12, %9 ]
%15 = icmp eq i8* %14, null
br i1 %15, label %23, label %16
16: ; preds = %13
%17 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %13, label %19
19: ; preds = %16
%20 = tail call i8* @strdup(i8* %14)
%21 = getelementptr inbounds i8*, i8** %7, i64 %11
store i8* %20, i8** %21
%22 = add nuw i64 %11, 1
br label %9
23: ; preds = %13
%24 = and i64 %11, 4294967295
%25 = getelementptr inbounds i8*, i8** %7, i64 %24
store i8* null, i8** %25
%26 = tail call i32 @free(i8* %8)
ret i8** %7
}