#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char **realloc(char **, int);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char **stringtoarray(char *string, char delimiter, int *size) {
  char **array = NULL;
  char *ptr, *oldptr;
  int flag = 1;
  int count;
  *size = 0;
  ptr = string;
  for (count = 0; flag; count++) {
    for (oldptr = ptr; *ptr && *ptr != delimiter; (void)*ptr++)
      ;
    if (!*ptr)
      flag = 0;
    *ptr++ = 0x00;
    (*size)++;
    if (!(array = realloc(array, (count + 1) * sizeof(char *)))) {
      fprintf(stderr, "realloc failed\n");
      exit(1);
    }
    array[count] = strdup(oldptr);
  }
  return array;
}


x86 assembly (clang, -O0):
<stringtoarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1279 <stringtoarray+0x139>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11b8 <stringtoarray+0x78>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11c8 <stringtoarray+0x88>
jmp    11de <stringtoarray+0x9e>
jmp    11cd <stringtoarray+0x8d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <stringtoarray+0x50>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11f2 <stringtoarray+0xb2>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1253 <stringtoarray+0x113>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    117e <stringtoarray+0x3e>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringtoarray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdx,0x8(%rsp)
movl   $0x0,(%rdx)
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rdi,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%r14d
add    $0x1,%rbx
test   %r14b,%r14b
je     1192 <stringtoarray+0x52>
cmp    %bpl,%r14b
jne    1180 <stringtoarray+0x40>
movb   $0x0,-0x1(%rbx)
mov    0x8(%rsp),%rax
addl   $0x1,(%rax)
lea    0x1(%r15),%r12
lea    0x0(,%r12,8),%esi
mov    %r13,%rdi
call   1040 <realloc@plt>
test   %rax,%rax
je     11e6 <stringtoarray+0xa6>
mov    %rax,%r13
mov    0x10(%rsp),%rdi
call   1060 <strdup@plt>
mov    %rax,0x0(%r13,%r15,8)
mov    %r12,%r15
mov    %rbx,%rdi
test   %r14b,%r14b
jne    1170 <stringtoarray+0x30>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"realloc failed\0A\00"
define i8** @stringtoarray(i8* %0, i8 signext %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32* %2, i32** %6
store i8** null, i8*** %7
store i32 1, i32* %10
%12 = load i32*, i32** %6
store i32 0, i32* %12
%13 = load i8*, i8** %4
store i8* %13, i8** %8
store i32 0, i32* %11
br label %14
14: ; preds = %68, %3
%15 = load i32, i32* %10
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %71
17: ; preds = %14
%18 = load i8*, i8** %8
store i8* %18, i8** %9
br label %19
19: ; preds = %34, %17
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8, i8* %5
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %27, %29
br label %31
31: ; preds = %24, %19
%32 = phi i1 [ false, %19 ], [ %30, %24 ]
br i1 %32, label %33, label %38
33: ; preds = %31
br label %34
34: ; preds = %33
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %8
%37 = load i8, i8* %35
br label %19
38: ; preds = %31
%39 = load i8*, i8** %8
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %38
store i32 0, i32* %10
br label %43
43: ; preds = %42, %38
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %8
store i8 0, i8* %44
%46 = load i32*, i32** %6
%47 = load i32, i32* %46
%48 = add nsw i32 %47, 1
store i32 %48, i32* %46
%49 = load i8**, i8*** %7
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = mul i64 %52, 8
%54 = trunc i64 %53 to i32
%55 = call i8** @realloc(i8** %49, i32 %54)
store i8** %55, i8*** %7
%56 = icmp ne i8** %55, null
br i1 %56, label %61, label %57
57: ; preds = %43
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %43
%62 = load i8*, i8** %9
%63 = call i8* @strdup(i8* %62)
%64 = load i8**, i8*** %7
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
store i8* %63, i8** %67
br label %68
68: ; preds = %61
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
br label %14
71: ; preds = %14
%72 = load i8**, i8*** %7
ret i8** %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"realloc failed\0A\00"
define i8** @stringtoarray(i8* nocapture %0, i8 signext %1, i32* nocapture %2) {
store i32 0, i32* %2
br label %4
4: ; preds = %3, %27
%5 = phi i64 [ 0, %3 ], [ %18, %27 ]
%6 = phi i8** [ null, %3 ], [ %21, %27 ]
%7 = phi i8* [ %0, %3 ], [ %14, %27 ]
br label %8
8: ; preds = %8, %4
%9 = phi i8* [ %14, %8 ], [ %7, %4 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
%12 = icmp eq i8 %10, %1
%13 = or i1 %11, %12
%14 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %13, label %15, label %8
15: ; preds = %8
store i8 0, i8* %9
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
%18 = add nuw i64 %5, 1
%19 = trunc i64 %18 to i32
%20 = shl i32 %19, 3
%21 = tail call i8** @realloc(i8** %6, i32 %20)
%22 = icmp eq i8** %21, null
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %15
%28 = tail call i8* @strdup(i8* %7)
%29 = getelementptr inbounds i8*, i8** %21, i64 %5
store i8* %28, i8** %29
br i1 %11, label %30, label %4
30: ; preds = %27
ret i8** %21
}