#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 /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strsep(char **, char *);
int strtoarray(char *str, char *sep, char ***list) {
  int len = strlen(str);
  char *copystr = (char *)malloc((len + 1) * sizeof(char));
  strcpy(copystr, str);
  int sizelist = 0;
  char *cur, *temp;
  temp = copystr;
  while ((cur = strsep(&temp, sep))) {
    sizelist++;
  }
  (*list) = (char **)malloc(sizelist * sizeof(char *));
  int i = 0;
  int curlen;
  strcpy(copystr, str);
  temp = copystr;
  while ((cur = strsep(&temp, sep))) {
    curlen = strlen(cur);
    (*list)[i] = (char *)malloc((curlen + 1) * sizeof(char));
    strcpy((*list)[i], cur);
    i++;
  }
  free(copystr);
  return sizelist;
}


x86 assembly (clang, -O0):
<strtoarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rdi
call   1070 <strsep@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11cc <strtoarray+0x7c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a3 <strtoarray+0x53>
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rdi
call   1070 <strsep@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1273 <strtoarray+0x123>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1201 <strtoarray+0xb1>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoarray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbp
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x10(%rsp)
mov    %rbx,0x8(%rsp)
mov    $0xfffffff8,%ebx
mov    $0xffffffff,%r12d
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <strsep@plt>
add    $0x8,%ebx
add    $0x1,%r12d
test   %rax,%rax
jne    11a0 <strtoarray+0x50>
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     123d <strtoarray+0xed>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    (%r14),%rcx
mov    %rax,(%rcx,%rbp,1)
mov    (%r14),%rax
mov    (%rax,%rbp,1),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <strsep@plt>
mov    %rax,%rbx
add    $0x8,%rbp
test   %rax,%rax
jne    1200 <strtoarray+0xb0>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @strtoarray(i8* %0, i8* %1, i8*** nocapture %2) {
%4 = alloca i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcpy(i8* %8, i8* %0)
%10 = bitcast i8** %4 to i8*
store i8* %8, i8** %4
br label %11
11: ; preds = %11, %3
%12 = phi i32 [ 0, %3 ], [ %15, %11 ]
%13 = call i8* @strsep(i8** %4, i8* %1)
%14 = icmp eq i8* %13, null
%15 = add nuw nsw i32 %12, 1
br i1 %14, label %16, label %11
16: ; preds = %11
%17 = shl i32 %12, 3
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8**
store i8** %19, i8*** %2
%20 = call i32 @strcpy(i8* %8, i8* %0)
store i8* %8, i8** %4
%21 = call i8* @strsep(i8** %4, i8* %1)
%22 = icmp eq i8* %21, null
br i1 %22, label %39, label %23
23: ; preds = %16, %23
%24 = phi i64 [ %36, %23 ], [ 0, %16 ]
%25 = phi i8* [ %37, %23 ], [ %21, %16 ]
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
%30 = load i8**, i8*** %2
%31 = getelementptr inbounds i8*, i8** %30, i64 %24
store i8* %29, i8** %31
%32 = load i8**, i8*** %2
%33 = getelementptr inbounds i8*, i8** %32, i64 %24
%34 = load i8*, i8** %33
%35 = call i32 @strcpy(i8* %34, i8* %25)
%36 = add nuw i64 %24, 1
%37 = call i8* @strsep(i8** %4, i8* %1)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %23
39: ; preds = %23, %16
%40 = call i32 @free(i8* %8)
ret i32 %12
}