#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 *);
void *MALLOC(int);
char *STRDUP(char const *);
char *quoted_string_parse(char *, char *, int, int, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void split_into_array(const char *str_in, char sep, int *nelem, char ***parr) {
  char *str = STRDUP(str_in);
  char *p = str;
  int i, n = 0;
  do {
    char val[512];
    p = quoted_string_parse(p, val, 512, -1, sep);
    ++n;
  } while (p);
  char **arr = MALLOC(sizeof(char *) * n);
  p = str;
  for (i = 0; i < n; ++i) {
    char val[512];
    p = quoted_string_parse(p, val, 512, -1, sep);
    arr[i] = MALLOC(sizeof(char) * (strlen(val) + 5));
    strcpy(arr[i], val);
  }
  *parr = arr;
  *nelem = n;
  FREE(str);
}


x86 assembly (clang, -O0):
<split_into_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <STRDUP@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
mov    $0xffffffff,%ecx
movsbl -0x9(%rbp),%r8d
call   1050 <quoted_string_parse@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1199 <split_into_array+0x39>
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <MALLOC@plt>
mov    %rax,-0x248(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    127b <split_into_array+0x11b>
mov    -0x30(%rbp),%rdi
lea    -0x450(%rbp),%rsi
mov    $0x200,%edx
mov    $0xffffffff,%ecx
movsbl -0x9(%rbp),%r8d
call   1050 <quoted_string_parse@plt>
mov    %rax,-0x30(%rbp)
lea    -0x450(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <MALLOC@plt>
mov    %rax,%rdx
mov    -0x248(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x248(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x450(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f5 <split_into_array+0x95>
mov    -0x248(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   1060 <FREE@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_into_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,0x18(%rsp)
mov    %esi,%ebp
call   1080 <STRDUP@plt>
xor    %ebx,%ebx
movsbl %bpl,%ebp
lea    0x20(%rsp),%r12
xor    %r15d,%r15d
mov    %rax,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x200,%edx
mov    $0xffffffff,%ecx
mov    %ebp,%r8d
call   1050 <quoted_string_parse@plt>
add    $0x1,%r15d
add    $0x8,%ebx
test   %rax,%rax
jne    11a0 <split_into_array+0x40>
mov    %ebx,%edi
call   1070 <MALLOC@plt>
mov    %rax,0x8(%rsp)
mov    %r15d,%r14d
xor    %r13d,%r13d
lea    0x20(%rsp),%rbx
mov    (%rsp),%r12
nop
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
mov    $0xffffffff,%ecx
mov    %ebp,%r8d
call   1050 <quoted_string_parse@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x5(%rax),%edi
call   1070 <MALLOC@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx,%r13,8)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    11e0 <split_into_array+0x80>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    %rcx,(%rax)
mov    0x18(%rsp),%rax
mov    %r15d,(%rax)
mov    (%rsp),%rdi
call   1060 <FREE@plt>
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @split_into_array(i8* %0, i8 signext %1, i32* %2, i8*** %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i8***
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca [512 x i8]
%14 = alloca i8**
%15 = alloca [512 x i8]
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32* %2, i32** %7
store i8*** %3, i8**** %8
%16 = load i8*, i8** %5
%17 = call i8* @STRDUP(i8* %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
store i8* %18, i8** %10
store i32 0, i32* %12
br label %19
19: ; preds = %26, %4
%20 = load i8*, i8** %10
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%22 = load i8, i8* %6
%23 = call i8* @quoted_string_parse(i8* %20, i8* %21, i32 512, i32 -1, i8 signext %22)
store i8* %23, i8** %10
%24 = load i32, i32* %12
%25 = add nsw i32 %24, 1
store i32 %25, i32* %12
br label %26
26: ; preds = %19
%27 = load i8*, i8** %10
%28 = icmp ne i8* %27, null
br i1 %28, label %19, label %29
29: ; preds = %26
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = mul i64 8, %31
%33 = trunc i64 %32 to i32
%34 = call i8* @MALLOC(i32 %33)
%35 = bitcast i8* %34 to i8**
store i8** %35, i8*** %14
%36 = load i8*, i8** %9
store i8* %36, i8** %10
store i32 0, i32* %11
br label %37
37: ; preds = %64, %29
%38 = load i32, i32* %11
%39 = load i32, i32* %12
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %67
41: ; preds = %37
%42 = load i8*, i8** %10
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%44 = load i8, i8* %6
%45 = call i8* @quoted_string_parse(i8* %42, i8* %43, i32 512, i32 -1, i8 signext %44)
store i8* %45, i8** %10
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = add nsw i32 %47, 5
%49 = sext i32 %48 to i64
%50 = mul i64 1, %49
%51 = trunc i64 %50 to i32
%52 = call i8* @MALLOC(i32 %51)
%53 = load i8**, i8*** %14
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
store i8* %52, i8** %56
%57 = load i8**, i8*** %14
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%63 = call i32 @strcpy(i8* %61, i8* %62)
br label %64
64: ; preds = %41
%65 = load i32, i32* %11
%66 = add nsw i32 %65, 1
store i32 %66, i32* %11
br label %37
67: ; preds = %37
%68 = load i8**, i8*** %14
%69 = load i8***, i8**** %8
store i8** %68, i8*** %69
%70 = load i32, i32* %12
%71 = load i32*, i32** %7
store i32 %70, i32* %71
%72 = load i8*, i8** %9
%73 = call i32 @FREE(i8* %72)
ret void
}

LLVM IR (-O2):
define void @split_into_array(i8* %0, i8 signext %1, i32* nocapture writeonly %2, i8*** nocapture writeonly %3) {
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = tail call i8* @STRDUP(i8* %0)
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
br label %9
9: ; preds = %9, %4
%10 = phi i32 [ 0, %4 ], [ %13, %9 ]
%11 = phi i8* [ %7, %4 ], [ %12, %9 ]
%12 = call i8* @quoted_string_parse(i8* %11, i8* %8, i32 512, i32 -1, i8 signext %1)
%13 = add nuw i32 %10, 1
%14 = icmp eq i8* %12, null
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = shl i32 %13, 3
%17 = call i8* @MALLOC(i32 %16)
%18 = bitcast i8* %17 to i8**
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%20 = zext i32 %13 to i64
br label %21
21: ; preds = %15, %21
%22 = phi i64 [ 0, %15 ], [ %30, %21 ]
%23 = phi i8* [ %7, %15 ], [ %24, %21 ]
%24 = call i8* @quoted_string_parse(i8* %23, i8* %19, i32 512, i32 -1, i8 signext %1)
%25 = call i32 @strlen(i8* %19)
%26 = add nsw i32 %25, 5
%27 = call i8* @MALLOC(i32 %26)
%28 = getelementptr inbounds i8*, i8** %18, i64 %22
store i8* %27, i8** %28
%29 = call i32 @strcpy(i8* %27, i8* %19)
%30 = add nuw nsw i64 %22, 1
%31 = icmp eq i64 %30, %20
br i1 %31, label %32, label %21
32: ; preds = %21
%33 = bitcast i8*** %3 to i8**
store i8* %17, i8** %33
store i32 %13, i32* %2
%34 = call i32 @FREE(i8* %7)
ret void
}