#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__ calloc(int, int);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
char *strtok(char *, char const *);
char **split_string(char *string_in, const char *split_delim, int *num_out) {
  char *string = strdup(string_in);
  char *next;
  int count = 0;
  char **strings_out = NULL;
  *num_out = 0;
  next = strtok(string, split_delim);
  if (next == NULL)
    return NULL;
  while (next != NULL) {
    count++;
    next = strtok(NULL, split_delim);
  }
  strings_out = (char **)calloc(count, sizeof(char *));
  *num_out = count;
  count = 0;
  string = strdup(string_in);
  next = strtok(string, split_delim);
  while (next != NULL) {
    strings_out[count] = strdup(next);
    count++;
    next = strtok(NULL, split_delim);
  }
  free(string);
  return strings_out;
}


x86 assembly (clang, -O0):
<split_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a3 <split_string+0x63>
movq   $0x0,-0x8(%rbp)
jmp    1264 <split_string+0x124>
jmp    11a8 <split_string+0x68>
cmpq   $0x0,-0x30(%rbp)
je     11d2 <split_string+0x92>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11a8 <split_string+0x68>
mov    -0x34(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1253 <split_string+0x113>
mov    -0x30(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    1211 <split_string+0xd1>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r15
call   1060 <strdup@plt>
movl   $0x0,(%r12)
mov    %rax,%rdi
mov    %r13,%rsi
call   1050 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11f8 <split_string+0xb8>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
xor    %edi,%edi
mov    %r13,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1180 <split_string+0x40>
mov    %ebx,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    %ebx,(%r12)
mov    %r15,%rdi
call   1060 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     11ee <split_string+0xae>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,(%rbx)
xor    %edi,%edi
mov    %r13,%rsi
call   1050 <strtok@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    11d0 <split_string+0x90>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11fb <split_string+0xbb>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8** @split_string(i8* nocapture %0, i8* nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @strdup(i8* %0)
store i32 0, i32* %2
%5 = tail call i8* @strtok(i8* %4, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %28, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %9, %7 ], [ 0, %3 ]
%9 = add nuw nsw i32 %8, 1
%10 = tail call i8* @strtok(i8* null, i8* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = tail call i64 @calloc(i32 %9, i32 8)
%14 = inttoptr i64 %13 to i8**
store i32 %9, i32* %2
%15 = tail call i8* @strdup(i8* %0)
%16 = tail call i8* @strtok(i8* %15, i8* %1)
%17 = icmp eq i8* %16, null
br i1 %17, label %26, label %18
18: ; preds = %12, %18
%19 = phi i64 [ %23, %18 ], [ 0, %12 ]
%20 = phi i8* [ %24, %18 ], [ %16, %12 ]
%21 = tail call i8* @strdup(i8* %20)
%22 = getelementptr inbounds i8*, i8** %14, i64 %19
store i8* %21, i8** %22
%23 = add nuw i64 %19, 1
%24 = tail call i8* @strtok(i8* null, i8* %1)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %18
26: ; preds = %18, %12
%27 = tail call i32 @free(i8* %15)
br label %28
28: ; preds = %3, %26
%29 = phi i8** [ %14, %26 ], [ null, %3 ]
ret i8** %29
}