#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 */
char *strchr(char const *, int /*<<< orphan*/);
scalar_t__ strv_extend(char ***, char const *);
int /*<<< orphan*/ strv_free(char **);
char **strv_new(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char **strv_split_nulstr(const char *s) {
  const char *i;
  char **r = NULL;
  for ((i) = (s); (i) && *(i); (i) = strchr((i), 0) + 1) {
    if (strv_extend(&r, i) < 0) {
      strv_free(r);
      return NULL;
    }
  }
  if (!r)
    return strv_new(NULL, NULL);
  return r;
}


x86 assembly (clang, -O0):
<strv_split_nulstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x21(%rbp)
je     117c <strv_split_nulstr+0x3c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    118c <strv_split_nulstr+0x4c>
jmp    11d6 <strv_split_nulstr+0x96>
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1050 <strv_extend@plt>
cmp    $0x0,%rax
jge    11b9 <strv_split_nulstr+0x79>
mov    -0x20(%rbp),%rdi
call   1030 <strv_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fe <strv_split_nulstr+0xbe>
jmp    11be <strv_split_nulstr+0x7e>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <strv_split_nulstr+0x1c>
cmpq   $0x0,-0x20(%rbp)
jne    11f6 <strv_split_nulstr+0xb6>
xor    %eax,%eax
mov    %eax,%esi
mov    %rsi,%rdi
call   1060 <strv_new@plt>
mov    %rax,-0x8(%rbp)
jmp    11fe <strv_split_nulstr+0xbe>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strv_split_nulstr>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
test   %rdi,%rdi
je     118d <strv_split_nulstr+0x4d>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1184 <strv_split_nulstr+0x44>
mov    %rsp,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strv_extend@plt>
test   %rax,%rax
js     1198 <strv_split_nulstr+0x58>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmpb   $0x0,0x1(%rbx,%rax,1)
lea    0x1(%rbx,%rax,1),%rbx
jne    1160 <strv_split_nulstr+0x20>
mov    (%rsp),%rax
test   %rax,%rax
jne    11a3 <strv_split_nulstr+0x63>
xor    %edi,%edi
xor    %esi,%esi
call   1060 <strv_new@plt>
jmp    11a3 <strv_split_nulstr+0x63>
mov    (%rsp),%rdi
call   1030 <strv_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8** @strv_split_nulstr(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
store i8* %0, i8** %3
store i8** null, i8*** %5
%6 = load i8*, i8** %3
store i8* %6, i8** %4
br label %7
7: ; preds = %25, %1
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %10, %7
%16 = phi i1 [ false, %7 ], [ %14, %10 ]
br i1 %16, label %17, label %29
17: ; preds = %15
%18 = load i8*, i8** %4
%19 = call i64 @strv_extend(i8*** %5, i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = call i32 @strv_free(i8** %22)
store i8** null, i8*** %2
br label %36
24: ; preds = %17
br label %25
25: ; preds = %24
%26 = load i8*, i8** %4
%27 = call i8* @strchr(i8* %26, i32 0)
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %4
br label %7
29: ; preds = %15
%30 = load i8**, i8*** %5
%31 = icmp ne i8** %30, null
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i8** @strv_new(i32* null, i32* null)
store i8** %33, i8*** %2
br label %36
34: ; preds = %29
%35 = load i8**, i8*** %5
store i8** %35, i8*** %2
br label %36
36: ; preds = %34, %32, %21
%37 = load i8**, i8*** %2
ret i8** %37
}

LLVM IR (-O2):
define i8** @strv_split_nulstr(i8* %0) {
%2 = alloca i8**
%3 = bitcast i8*** %2 to i8*
store i8** null, i8*** %2
%4 = icmp eq i8* %0, null
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %5, %15
%9 = phi i8* [ %18, %15 ], [ %0, %5 ]
%10 = call i64 @strv_extend(i8*** %2, i8* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i8**, i8*** %2
%14 = call i32 @strv_free(i8** %13)
br label %26
15: ; preds = %8
%16 = call i64 @strlen(i8* %9)
%17 = getelementptr i8, i8* %9, i64 1
%18 = getelementptr inbounds i8, i8* %17, i64 %16
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %8
21: ; preds = %15, %5
%22 = load i8**, i8*** %2
%23 = icmp eq i8** %22, null
br i1 %23, label %24, label %26
24: ; preds = %1, %21
%25 = call i8** @strv_new(i32* null, i32* null)
br label %26
26: ; preds = %21, %24, %12
%27 = phi i8** [ null, %12 ], [ %25, %24 ], [ %22, %21 ]
ret i8** %27
}