#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 *);
char **realloc(char **, int);
char *strdup(char const *);
int _strlist_add(const char *str, char ***list, int *list_length) {
  char **new_list;
  char *new_str;
  new_str = strdup(str);
  if (!new_str)
    goto error_exit;
  new_list = realloc(*list, sizeof(char *) * (*list_length + 1));
  if (new_list == NULL)
    goto error_exit2;
  new_list[*list_length] = new_str;
  *list = new_list;
  *list_length = *list_length + 1;
  return 0;
error_exit2:
  free(new_str);
error_exit:
  return -1;
}


x86 assembly (clang, -O0):
<_strlist_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1161 <_strlist_add+0x31>
jmp    11d4 <_strlist_add+0xa4>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1192 <_strlist_add+0x62>
jmp    11cb <_strlist_add+0x9b>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11db <_strlist_add+0xab>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strlist_add>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
call   1050 <strdup@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1182 <_strlist_add+0x52>
mov    %rax,%rbx
mov    (%r14),%rdi
mov    (%r15),%eax
lea    0x8(,%rax,8),%esi
call   1040 <realloc@plt>
test   %rax,%rax
je     117a <_strlist_add+0x4a>
movslq (%r15),%rcx
mov    %rbx,(%rax,%rcx,8)
mov    %rax,(%r14)
lea    0x1(%rcx),%eax
mov    %eax,(%r15)
xor    %ebp,%ebp
jmp    1182 <_strlist_add+0x52>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @_strlist_add(i8* nocapture %0, i8*** nocapture %1, i32* nocapture %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = load i8**, i8*** %1
%8 = load i32, i32* %2
%9 = shl i32 %8, 3
%10 = add i32 %9, 8
%11 = tail call i8** @realloc(i8** %7, i32 %10)
%12 = icmp eq i8** %11, null
br i1 %12, label %18, label %13
13: ; preds = %6
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %11, i64 %15
store i8* %4, i8** %16
store i8** %11, i8*** %1
%17 = add nsw i32 %14, 1
store i32 %17, i32* %2
br label %20
18: ; preds = %6
%19 = tail call i32 @free(i8* %4)
br label %20
20: ; preds = %18, %3, %13
%21 = phi i32 [ 0, %13 ], [ -1, %3 ], [ -1, %18 ]
ret i32 %21
}