#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__ realloc(char **, int);
char *strdup(char *);
char *strtok_r(char *, char const *, char **);
char **str2strlist(char **string, const char *sep, unsigned int *n) {
  int i = 0;
  char *str = (char *)NULL;
  char **list = (char **)NULL;
  char *orig_string = *string;
  ;
  while (1) {
    str = *string;
    str = strtok_r(str, sep, string);
    ;
    if (str == NULL)
      break;
    else {
      list = (char **)realloc(list, (i + 1) * sizeof(char *));
      list[i] = strdup(str);
      ;
    }
    i++;
  };
  if (n)
    *n = i;
  *string = orig_string;
  return list;
}


x86 assembly (clang, -O0):
<str2strlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1196 <str2strlist+0x66>
jmp    11d7 <str2strlist+0xa7>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <str2strlist+0x36>
cmpq   $0x0,-0x18(%rbp)
je     11eb <str2strlist+0xbb>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2strlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
mov    (%rdi),%rbp
mov    %rbp,%rdi
mov    %r13,%rdx
call   1030 <strtok_r@plt>
test   %rax,%rax
je     11e3 <str2strlist+0xb3>
mov    %rax,%r14
mov    %rbp,(%rsp)
mov    %r15,0x8(%rsp)
mov    $0x8,%ebp
xor    %r12d,%r12d
mov    %rbx,0x10(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r12,%r15
add    $0x1,%r12
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strdup@plt>
mov    %rax,(%rbx,%r15,8)
mov    0x0(%r13),%rdi
mov    0x10(%rsp),%rsi
mov    %r13,%rdx
call   1030 <strtok_r@plt>
mov    %rax,%r14
add    $0x8,%ebp
test   %rax,%rax
jne    1180 <str2strlist+0x50>
mov    0x8(%rsp),%r15
mov    (%rsp),%rbp
test   %r15,%r15
je     11cd <str2strlist+0x9d>
mov    %r12d,(%r15)
mov    %rbp,0x0(%r13)
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
xor    %r12d,%r12d
test   %r15,%r15
jne    11ca <str2strlist+0x9a>
jmp    11cd <str2strlist+0x9d>

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

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