#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ printf(char *);
char *strpbrk(char *, char *);
char *strtok(char *, char *);
int splitInput(char **buffer, char ***split_array, char delim[]) {
  unsigned int number_of_strings = 0;
  char *temp;
  temp = strpbrk(*buffer, delim);
  while (temp != NULL) {
    number_of_strings++;
    temp = strpbrk(temp + 1, delim);
  }
  *split_array = (char **)malloc(number_of_strings * sizeof(char *));
  if (*split_array == NULL) {
    printf("memory failure");
    exit(EXIT_FAILURE);
  }
  temp = strtok(*buffer, delim);
  int itr;
  for (itr = 0; temp != NULL; itr++) {
    (*split_array)[itr] = temp;
    temp = strtok(NULL, delim);
  }
  return number_of_strings;
}


x86 assembly (clang, -O0):
<splitInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ad <splitInput+0x5d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
jmp    117f <splitInput+0x2f>
mov    -0x1c(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ed <splitInput+0x9d>
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1245 <splitInput+0xf5>
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1208 <splitInput+0xb8>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splitInput>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%rdi
mov    %rdx,%rsi
call   1050 <strpbrk@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     1198 <splitInput+0x48>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r13d
add    $0x1,%rax
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strpbrk@plt>
test   %rax,%rax
jne    1180 <splitInput+0x30>
lea    0x0(,%r13,8),%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11e7 <splitInput+0x97>
mov    (%r12),%rdi
mov    %r15,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11da <splitInput+0x8a>
xor    %ebx,%ebx
mov    (%r14),%rcx
mov    %rax,(%rcx,%rbx,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1060 <strtok@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    11c0 <splitInput+0x70>
mov    %r13d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"memory failure\00"
@EXIT_FAILURE = global i32 0
define i32 @splitInput(i8** %0, i8*** %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8***
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8** %0, i8*** %4
store i8*** %1, i8**** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%10 = load i8**, i8*** %4
%11 = load i8*, i8** %10
%12 = load i8*, i8** %6
%13 = call i8* @strpbrk(i8* %11, i8* %12)
store i8* %13, i8** %8
br label %14
14: ; preds = %17, %3
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %7
%19 = add i32 %18, 1
store i32 %19, i32* %7
%20 = load i8*, i8** %8
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8*, i8** %6
%23 = call i8* @strpbrk(i8* %21, i8* %22)
store i8* %23, i8** %8
br label %14
24: ; preds = %14
%25 = load i32, i32* %7
%26 = zext i32 %25 to i64
%27 = mul i64 %26, 8
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8**
%31 = load i8***, i8**** %5
store i8** %30, i8*** %31
%32 = load i8***, i8**** %5
%33 = load i8**, i8*** %32
%34 = icmp eq i8** %33, null
br i1 %34, label %35, label %39
35: ; preds = %24
%36 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %24
%40 = load i8**, i8*** %4
%41 = load i8*, i8** %40
%42 = load i8*, i8** %6
%43 = call i8* @strtok(i8* %41, i8* %42)
store i8* %43, i8** %8
store i32 0, i32* %9
br label %44
44: ; preds = %56, %39
%45 = load i8*, i8** %8
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %59
47: ; preds = %44
%48 = load i8*, i8** %8
%49 = load i8***, i8**** %5
%50 = load i8**, i8*** %49
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
store i8* %48, i8** %53
%54 = load i8*, i8** %6
%55 = call i8* @strtok(i8* null, i8* %54)
store i8* %55, i8** %8
br label %56
56: ; preds = %47
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %44
59: ; preds = %44
%60 = load i32, i32* %7
ret i32 %60
}

LLVM IR (-O2):
@.str = [15 x i8] c"memory failure\00"
@EXIT_FAILURE = global i32 0
define i32 @splitInput(i8** nocapture %0, i8*** nocapture %1, i8* nocapture %2) {
%4 = load i8*, i8** %0
%5 = tail call i8* @strpbrk(i8* %4, i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %3, %7
%8 = phi i8* [ %12, %7 ], [ %5, %3 ]
%9 = phi i32 [ %10, %7 ], [ 0, %3 ]
%10 = add i32 %9, 1
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = tail call i8* @strpbrk(i8* %11, i8* %2)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %7
14: ; preds = %7, %3
%15 = phi i32 [ 0, %3 ], [ %10, %7 ]
%16 = shl i32 %15, 3
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8**
store i8** %18, i8*** %1
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = load i8*, i8** %0
%26 = tail call i8* @strtok(i8* %25, i8* %2)
%27 = icmp eq i8* %26, null
br i1 %27, label %36, label %28
28: ; preds = %24, %28
%29 = phi i64 [ %34, %28 ], [ 0, %24 ]
%30 = phi i8* [ %33, %28 ], [ %26, %24 ]
%31 = load i8**, i8*** %1
%32 = getelementptr inbounds i8*, i8** %31, i64 %29
store i8* %30, i8** %32
%33 = tail call i8* @strtok(i8* null, i8* %2)
%34 = add nuw i64 %29, 1
%35 = icmp eq i8* %33, null
br i1 %35, label %36, label %28
36: ; preds = %28, %24
ret i32 %15
}