#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*/ assert(char ***);
scalar_t__ ensure_len(char ***, size_t *, size_t);
char *strdup(char const *);
int stringv_append(char ***s, size_t *s_len, const char *elem) {
  size_t i;
  if ((!s_len) || ensure_len(s, s_len, *s_len + 1))
    return -1;
  assert(s);
  i = *s_len - 1;
  (*s)[i] = strdup(elem);
  if (!(*s)[i])
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<stringv_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1171 <stringv_append+0x41>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
add    $0x1,%rdx
call   1030 <ensure_len@plt>
cmp    $0x0,%rax
je     117d <stringv_append+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <stringv_append+0xa9>
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11d2 <stringv_append+0xa2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <stringv_append+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringv_append>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rsi,%rsi
je     1181 <stringv_append+0x51>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%rdx
add    $0x1,%rdx
call   1030 <ensure_len@plt>
test   %rax,%rax
jne    1181 <stringv_append+0x51>
mov    %r15,%rdi
call   1040 <assert@plt>
mov    (%rbx),%rbx
mov    %r14,%rdi
call   1050 <strdup@plt>
mov    (%r15),%rcx
mov    %rax,-0x8(%rcx,%rbx,8)
mov    (%r15),%rax
cmpq   $0x1,-0x8(%rax,%rbx,8)
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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