#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 */
struct szl_obj {
  int dummy;
};
struct szl_interp {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ free(struct szl_obj **);
scalar_t__ realloc(struct szl_obj **, int);
int /*<<< orphan*/ szl_free(struct szl_obj *);
struct szl_obj *szl_new_str(struct szl_interp *, char *, int);
char *szl_next_item(struct szl_interp *, char *);
int /*<<< orphan*/ szl_set_last_strerror(struct szl_interp *,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ szl_trim(char *, char **, char **);
int szl_split(struct szl_interp *interp, char *s, struct szl_obj ***items,
              size_t *len) {
  struct szl_obj **mitems;
  char *tok, *next, *start, *end;
  size_t i;
  int mlen = 1;
  *len = 0;
  *items = NULL;
  if (s[0] == '\0')
    return 0;
  szl_trim(s, &start, &end);
  next = szl_next_item(interp, start);
  tok = start;
  do {
    mitems =
        (struct szl_obj **)realloc(*items, sizeof(struct szl_obj *) * mlen);
    if (!mitems) {
      if (*items) {
        for (i = 0; i < *len; ++i)
          szl_free(*items[i]);
        free(*items);
      }
      szl_set_last_strerror(interp, ENOMEM);
      return 0;
    }
    mitems[*len] = szl_new_str(interp, tok, -1);
    if (!mitems[*len]) {
      for (i = 0; i < *len; ++i)
        szl_free(mitems[i]);
      free(mitems);
      return 0;
    }
    *len = mlen;
    *items = mitems;
    if (!next)
      break;
    tok = next;
    ++mlen;
    next = szl_next_item(interp, tok);
  } while (1);
  return 1;
}


x86 assembly (clang, -O0):
<szl_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c1 <szl_split+0x51>
movl   $0x0,-0x4(%rbp)
jmp    136e <szl_split+0x1fe>
mov    -0x18(%rbp),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1070 <szl_trim@plt>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1090 <szl_next_item@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
movslq -0x5c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1286 <szl_split+0x116>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1268 <szl_split+0xf8>
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
jae    125c <szl_split+0xec>
mov    -0x20(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%rdi
call   1040 <szl_free@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1226 <szl_split+0xb6>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
call   1050 <szl_set_last_strerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    136e <szl_split+0x1fe>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0xffffffff,%edx
call   1060 <szl_new_str@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1310 <szl_split+0x1a0>
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
jae    12fb <szl_split+0x18b>
mov    -0x30(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <szl_free@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    12c8 <szl_split+0x158>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    136e <szl_split+0x1fe>
movslq -0x5c(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x40(%rbp)
jne    1336 <szl_split+0x1c6>
jmp    1367 <szl_split+0x1f7>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <szl_next_item@plt>
mov    %rax,-0x40(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    11eb <szl_split+0x7b>
jmp    1367 <szl_split+0x1f7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<szl_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,(%rcx)
movq   $0x0,(%rdx)
xor    %eax,%eax
cmpb   $0x0,(%rsi)
je     1303 <szl_split+0x193>
mov    %rdx,%r14
mov    %rdi,%r13
mov    %rcx,0x10(%rsp)
lea    0x18(%rsp),%rax
lea    0x20(%rsp),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
call   1070 <szl_trim@plt>
mov    0x18(%rsp),%rsi
mov    %r13,%rdi
call   1090 <szl_next_item@plt>
mov    %rax,%rbx
mov    0x18(%rsp),%rbp
mov    %r14,0x8(%rsp)
mov    (%r14),%rdi
mov    $0x8,%esi
call   1080 <realloc@plt>
test   %rax,%rax
je     1265 <szl_split+0xf5>
mov    %rax,%r15
mov    $0x1,%r12d
mov    $0x10,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rsi
mov    %rbx,%rbp
mov    %r13,%rdi
mov    $0xffffffff,%edx
call   1060 <szl_new_str@plt>
mov    0x10(%rsp),%rbx
mov    (%rbx),%rcx
mov    %rax,(%r15,%rcx,8)
test   %rax,%rax
je     12d3 <szl_split+0x163>
mov    %r12,(%rbx)
mov    0x8(%rsp),%rbx
mov    %r15,(%rbx)
test   %rbp,%rbp
je     12fe <szl_split+0x18e>
add    $0x1,%r12
mov    %r13,%rdi
mov    %rbp,%rsi
call   1090 <szl_next_item@plt>
mov    (%rbx),%rdi
mov    %rax,%rbx
mov    %r14d,%esi
call   1080 <realloc@plt>
mov    %rax,%r15
add    $0x8,%r14d
test   %rax,%rax
jne    1200 <szl_split+0x90>
mov    0x8(%rsp),%r14
mov    (%r14),%rdi
test   %rdi,%rdi
je     12be <szl_split+0x14e>
mov    0x10(%rsp),%rbp
cmpq   $0x0,0x0(%rbp)
je     12b9 <szl_split+0x149>
mov    (%rdi),%rdi
call   1040 <szl_free@plt>
cmpq   $0x2,0x0(%rbp)
jb     12b6 <szl_split+0x146>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rax
mov    (%rax),%rdi
call   1040 <szl_free@plt>
add    $0x1,%rbx
cmp    0x0(%rbp),%rbx
jb     12a0 <szl_split+0x130>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1050 <szl_set_last_strerror@plt>
xor    %eax,%eax
jmp    1303 <szl_split+0x193>
test   %rcx,%rcx
je     12f2 <szl_split+0x182>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%rdi
call   1040 <szl_free@plt>
add    $0x1,%rbp
cmp    (%rbx),%rbp
jb     12e0 <szl_split+0x170>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1303 <szl_split+0x193>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.szl_interp = type { i32 }
%struct.szl_obj = type { i32 }
@ENOMEM = global i32 0
define i32 @szl_split(%struct.szl_interp* %0, i8* %1, %struct.szl_obj*** %2, i64* %3) {
%5 = alloca i32
%6 = alloca %struct.szl_interp*
%7 = alloca i8*
%8 = alloca %struct.szl_obj***
%9 = alloca i64*
%10 = alloca %struct.szl_obj**
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
store %struct.szl_interp* %0, %struct.szl_interp** %6
store i8* %1, i8** %7
store %struct.szl_obj*** %2, %struct.szl_obj**** %8
store i64* %3, i64** %9
store i32 1, i32* %16
%17 = load i64*, i64** %9
store i64 0, i64* %17
%18 = load %struct.szl_obj***, %struct.szl_obj**** %8
store %struct.szl_obj** null, %struct.szl_obj*** %18
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 0, i32* %5
br label %121
25: ; preds = %4
%26 = load i8*, i8** %7
%27 = call i32 @szl_trim(i8* %26, i8** %13, i8** %14)
%28 = load %struct.szl_interp*, %struct.szl_interp** %6
%29 = load i8*, i8** %13
%30 = call i8* @szl_next_item(%struct.szl_interp* %28, i8* %29)
store i8* %30, i8** %12
%31 = load i8*, i8** %13
store i8* %31, i8** %11
br label %32
32: ; preds = %119, %25
%33 = load %struct.szl_obj***, %struct.szl_obj**** %8
%34 = load %struct.szl_obj**, %struct.szl_obj*** %33
%35 = load i32, i32* %16
%36 = sext i32 %35 to i64
%37 = mul i64 8, %36
%38 = trunc i64 %37 to i32
%39 = call i64 @realloc(%struct.szl_obj** %34, i32 %38)
%40 = inttoptr i64 %39 to %struct.szl_obj**
store %struct.szl_obj** %40, %struct.szl_obj*** %10
%41 = load %struct.szl_obj**, %struct.szl_obj*** %10
%42 = icmp ne %struct.szl_obj** %41, null
br i1 %42, label %71, label %43
43: ; preds = %32
%44 = load %struct.szl_obj***, %struct.szl_obj**** %8
%45 = load %struct.szl_obj**, %struct.szl_obj*** %44
%46 = icmp ne %struct.szl_obj** %45, null
br i1 %46, label %47, label %67
47: ; preds = %43
store i64 0, i64* %15
br label %48
48: ; preds = %60, %47
%49 = load i64, i64* %15
%50 = load i64*, i64** %9
%51 = load i64, i64* %50
%52 = icmp ult i64 %49, %51
br i1 %52, label %53, label %63
53: ; preds = %48
%54 = load %struct.szl_obj***, %struct.szl_obj**** %8
%55 = load i64, i64* %15
%56 = getelementptr inbounds %struct.szl_obj**, %struct.szl_obj*** %54, i64 %55
%57 = load %struct.szl_obj**, %struct.szl_obj*** %56
%58 = load %struct.szl_obj*, %struct.szl_obj** %57
%59 = call i32 @szl_free(%struct.szl_obj* %58)
br label %60
60: ; preds = %53
%61 = load i64, i64* %15
%62 = add i64 %61, 1
store i64 %62, i64* %15
br label %48
63: ; preds = %48
%64 = load %struct.szl_obj***, %struct.szl_obj**** %8
%65 = load %struct.szl_obj**, %struct.szl_obj*** %64
%66 = call i32 @free(%struct.szl_obj** %65)
br label %67
67: ; preds = %63, %43
%68 = load %struct.szl_interp*, %struct.szl_interp** %6
%69 = load i32, i32* @ENOMEM
%70 = call i32 @szl_set_last_strerror(%struct.szl_interp* %68, i32 %69)
store i32 0, i32* %5
br label %121
71: ; preds = %32
%72 = load %struct.szl_interp*, %struct.szl_interp** %6
%73 = load i8*, i8** %11
%74 = call %struct.szl_obj* @szl_new_str(%struct.szl_interp* %72, i8* %73, i32 -1)
%75 = load %struct.szl_obj**, %struct.szl_obj*** %10
%76 = load i64*, i64** %9
%77 = load i64, i64* %76
%78 = getelementptr inbounds %struct.szl_obj*, %struct.szl_obj** %75, i64 %77
store %struct.szl_obj* %74, %struct.szl_obj** %78
%79 = load %struct.szl_obj**, %struct.szl_obj*** %10
%80 = load i64*, i64** %9
%81 = load i64, i64* %80
%82 = getelementptr inbounds %struct.szl_obj*, %struct.szl_obj** %79, i64 %81
%83 = load %struct.szl_obj*, %struct.szl_obj** %82
%84 = icmp ne %struct.szl_obj* %83, null
br i1 %84, label %103, label %85
85: ; preds = %71
store i64 0, i64* %15
br label %86
86: ; preds = %97, %85
%87 = load i64, i64* %15
%88 = load i64*, i64** %9
%89 = load i64, i64* %88
%90 = icmp ult i64 %87, %89
br i1 %90, label %91, label %100
91: ; preds = %86
%92 = load %struct.szl_obj**, %struct.szl_obj*** %10
%93 = load i64, i64* %15
%94 = getelementptr inbounds %struct.szl_obj*, %struct.szl_obj** %92, i64 %93
%95 = load %struct.szl_obj*, %struct.szl_obj** %94
%96 = call i32 @szl_free(%struct.szl_obj* %95)
br label %97
97: ; preds = %91
%98 = load i64, i64* %15
%99 = add i64 %98, 1
store i64 %99, i64* %15
br label %86
100: ; preds = %86
%101 = load %struct.szl_obj**, %struct.szl_obj*** %10
%102 = call i32 @free(%struct.szl_obj** %101)
store i32 0, i32* %5
br label %121
103: ; preds = %71
%104 = load i32, i32* %16
%105 = sext i32 %104 to i64
%106 = load i64*, i64** %9
store i64 %105, i64* %106
%107 = load %struct.szl_obj**, %struct.szl_obj*** %10
%108 = load %struct.szl_obj***, %struct.szl_obj**** %8
store %struct.szl_obj** %107, %struct.szl_obj*** %108
%109 = load i8*, i8** %12
%110 = icmp ne i8* %109, null
br i1 %110, label %112, label %111
111: ; preds = %103
br label %120
112: ; preds = %103
%113 = load i8*, i8** %12
store i8* %113, i8** %11
%114 = load i32, i32* %16
%115 = add nsw i32 %114, 1
store i32 %115, i32* %16
%116 = load %struct.szl_interp*, %struct.szl_interp** %6
%117 = load i8*, i8** %11
%118 = call i8* @szl_next_item(%struct.szl_interp* %116, i8* %117)
store i8* %118, i8** %12
br label %119
119: ; preds = %112
br i1 true, label %32, label %120
120: ; preds = %119, %111
store i32 1, i32* %5
br label %121
121: ; preds = %120, %100, %67, %24
%122 = load i32, i32* %5
ret i32 %122
}

LLVM IR (-O2):
%struct.szl_interp = type { i32 }
%struct.szl_obj = type { i32 }
@ENOMEM = global i32 0
define i32 @szl_split(%struct.szl_interp* %0, i8* %1, %struct.szl_obj*** nocapture %2, i64* nocapture %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i8** %5 to i8*
%8 = bitcast i8** %6 to i8*
store i64 0, i64* %3
store %struct.szl_obj** null, %struct.szl_obj*** %2
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %80, label %11
11: ; preds = %4
%12 = call i32 @szl_trim(i8* %1, i8** %5, i8** %6)
%13 = load i8*, i8** %5
%14 = call i8* @szl_next_item(%struct.szl_interp* %0, i8* %13)
%15 = load i8*, i8** %5
%16 = load %struct.szl_obj**, %struct.szl_obj*** %2
%17 = call i64 @realloc(%struct.szl_obj** %16, i32 8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %47
19: ; preds = %72, %11
%20 = load %struct.szl_obj**, %struct.szl_obj*** %2
%21 = icmp eq %struct.szl_obj** %20, null
br i1 %21, label %44, label %22
22: ; preds = %19
%23 = load i64, i64* %3
%24 = icmp eq i64 %23, 0
br i1 %24, label %41, label %25
25: ; preds = %22
%26 = load %struct.szl_obj*, %struct.szl_obj** %20
%27 = call i32 @szl_free(%struct.szl_obj* %26)
%28 = load i64, i64* %3
%29 = icmp ugt i64 %28, 1
br i1 %29, label %30, label %39
30: ; preds = %25, %30
%31 = phi i64 [ %36, %30 ], [ 1, %25 ]
%32 = getelementptr inbounds %struct.szl_obj**, %struct.szl_obj*** %2, i64 %31
%33 = load %struct.szl_obj**, %struct.szl_obj*** %32
%34 = load %struct.szl_obj*, %struct.szl_obj** %33
%35 = call i32 @szl_free(%struct.szl_obj* %34)
%36 = add nuw i64 %31, 1
%37 = load i64, i64* %3
%38 = icmp ult i64 %36, %37
br i1 %38, label %30, label %39
39: ; preds = %30, %25
%40 = load %struct.szl_obj**, %struct.szl_obj*** %2
br label %41
41: ; preds = %39, %22
%42 = phi %struct.szl_obj** [ %40, %39 ], [ %20, %22 ]
%43 = call i32 @free(%struct.szl_obj** %42)
br label %44
44: ; preds = %41, %19
%45 = load i32, i32* @ENOMEM
%46 = call i32 @szl_set_last_strerror(%struct.szl_interp* %0, i32 %45)
br label %80
47: ; preds = %11, %72
%48 = phi i64 [ %73, %72 ], [ 1, %11 ]
%49 = phi i64 [ %78, %72 ], [ %17, %11 ]
%50 = phi i8* [ %74, %72 ], [ %14, %11 ]
%51 = phi i8* [ %50, %72 ], [ %15, %11 ]
%52 = inttoptr i64 %49 to %struct.szl_obj**
%53 = call %struct.szl_obj* @szl_new_str(%struct.szl_interp* %0, i8* %51, i32 -1)
%54 = load i64, i64* %3
%55 = getelementptr inbounds %struct.szl_obj*, %struct.szl_obj** %52, i64 %54
store %struct.szl_obj* %53, %struct.szl_obj** %55
%56 = icmp eq %struct.szl_obj* %53, null
br i1 %56, label %57, label %70
57: ; preds = %47
%58 = inttoptr i64 %49 to %struct.szl_obj**
%59 = icmp eq i64 %54, 0
br i1 %59, label %68, label %60
60: ; preds = %57, %60
%61 = phi i64 [ %65, %60 ], [ 0, %57 ]
%62 = getelementptr inbounds %struct.szl_obj*, %struct.szl_obj** %58, i64 %61
%63 = load %struct.szl_obj*, %struct.szl_obj** %62
%64 = call i32 @szl_free(%struct.szl_obj* %63)
%65 = add nuw i64 %61, 1
%66 = load i64, i64* %3
%67 = icmp ult i64 %65, %66
br i1 %67, label %60, label %68
68: ; preds = %60, %57
%69 = call i32 @free(%struct.szl_obj** %58)
br label %80
70: ; preds = %47
store i64 %48, i64* %3
store %struct.szl_obj** %52, %struct.szl_obj*** %2
%71 = icmp eq i8* %50, null
br i1 %71, label %80, label %72
72: ; preds = %70
%73 = add nuw i64 %48, 1
%74 = call i8* @szl_next_item(%struct.szl_interp* %0, i8* %50)
%75 = load %struct.szl_obj**, %struct.szl_obj*** %2
%76 = trunc i64 %73 to i32
%77 = shl i32 %76, 3
%78 = call i64 @realloc(%struct.szl_obj** %75, i32 %77)
%79 = icmp eq i64 %78, 0
br i1 %79, label %19, label %47
80: ; preds = %70, %4, %68, %44
%81 = phi i32 [ 0, %68 ], [ 0, %44 ], [ 0, %4 ], [ 1, %70 ]
ret i32 %81
}