#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 strlist {
  int dummy;
};

/* Variables and functions */
size_t strcspn(char const *, char const *);
int /*<<< orphan*/ strlist_append_sz(struct strlist *, char const *, size_t);
struct strlist *strlist_new(int);
struct strlist *string_split_sz(const char *sz, const char *delimiters,
                                int include_empty) {
  const char *p = sz;
  struct strlist *list = strlist_new(5);
  while (*p != '\0') {
    size_t span = strcspn(p, delimiters);
    if (span == 0) {
      if (include_empty)
        strlist_append_sz(list, "", 0);
      p++;
      continue;
    }
    strlist_append_sz(list, p, span);
    p += span;
    if (*p == '\0')
      break;
    p++;
  }
  return list;
}


x86 assembly (clang, -O0):
<string_split_sz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x5,%edi
call   1050 <strlist_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f7 <string_split_sz+0xc7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcspn@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b4 <string_split_sz+0x84>
cmpl   $0x0,-0x14(%rbp)
je     11a3 <string_split_sz+0x73>
mov    -0x28(%rbp),%rdi
lea    0xe66(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <strlist_append_sz@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <string_split_sz+0x29>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <strlist_append_sz@plt>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e6 <string_split_sz+0xb6>
jmp    11f7 <string_split_sz+0xc7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <string_split_sz+0x29>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_split_sz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%rbp
mov    $0x5,%edi
call   1050 <strlist_new@plt>
mov    %rax,%r15
cmpb   $0x0,0x0(%rbp)
je     11c4 <string_split_sz+0x94>
lea    0xea2(%rip),%r12
jmp    116a <string_split_sz+0x3a>
add    $0x1,%rbp
cmpb   $0x0,0x0(%rbp)
je     11c4 <string_split_sz+0x94>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strcspn@plt>
test   %rax,%rax
je     11b0 <string_split_sz+0x80>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <strlist_append_sz@plt>
movzbl 0x0(%rbp,%rbx,1),%ecx
xor    %eax,%eax
test   %cl,%cl
setne  %cl
je     11c4 <string_split_sz+0x94>
add    %rbx,%rbp
mov    %cl,%al
add    %rax,%rbp
cmpb   $0x0,0x0(%rbp)
jne    116a <string_split_sz+0x3a>
jmp    11c4 <string_split_sz+0x94>
nopl   0x0(%rax)
test   %r14d,%r14d
je     1160 <string_split_sz+0x30>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1040 <strlist_append_sz@plt>
jmp    1160 <string_split_sz+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.strlist = type { i32 }
@.str = [1 x i8] zeroinitializer
define %struct.strlist* @string_split_sz(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.strlist*
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
%11 = call %struct.strlist* @strlist_new(i32 5)
store %struct.strlist* %11, %struct.strlist** %8
br label %12
12: ; preds = %45, %29, %3
%13 = load i8*, i8** %7
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %48
17: ; preds = %12
%18 = load i8*, i8** %7
%19 = load i8*, i8** %5
%20 = call i64 @strcspn(i8* %18, i8* %19)
store i64 %20, i64* %9
%21 = load i64, i64* %9
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %17
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load %struct.strlist*, %struct.strlist** %8
%28 = call i32 @strlist_append_sz(%struct.strlist* %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64 0)
br label %29
29: ; preds = %26, %23
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %7
br label %12
32: ; preds = %17
%33 = load %struct.strlist*, %struct.strlist** %8
%34 = load i8*, i8** %7
%35 = load i64, i64* %9
%36 = call i32 @strlist_append_sz(%struct.strlist* %33, i8* %34, i64 %35)
%37 = load i64, i64* %9
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 %37
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %32
br label %48
45: ; preds = %32
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %7
br label %12
48: ; preds = %44, %12
%49 = load %struct.strlist*, %struct.strlist** %8
ret %struct.strlist* %49
}

LLVM IR (-O2):
%struct.strlist = type { i32 }
@.str = [1 x i8] zeroinitializer
define %struct.strlist* @string_split_sz(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call %struct.strlist* @strlist_new(i32 5)
%5 = icmp eq i32 %2, 0
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %29, label %8
8: ; preds = %3, %25
%9 = phi i8* [ %26, %25 ], [ %0, %3 ]
%10 = tail call i64 @strcspn(i8* %9, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
br i1 %5, label %15, label %13
13: ; preds = %12
%14 = tail call i32 @strlist_append_sz(%struct.strlist* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64 0)
br label %15
15: ; preds = %13, %12
%16 = getelementptr inbounds i8, i8* %9, i64 1
br label %25
17: ; preds = %8
%18 = tail call i32 @strlist_append_sz(%struct.strlist* %4, i8* %9, i64 %10)
%19 = getelementptr inbounds i8, i8* %9, i64 %10
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
%22 = xor i1 %21, true
%23 = zext i1 %22 to i64
%24 = getelementptr i8, i8* %19, i64 %23
br i1 %21, label %29, label %25
25: ; preds = %17, %15
%26 = phi i8* [ %16, %15 ], [ %24, %17 ]
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %8
29: ; preds = %25, %17, %3
ret %struct.strlist* %4
}