#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 ENOMEM;
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
int strv_push(char ***, char *);
int strv_extend(char ***l, const char *value) {
  char *v;
  int r;
  if (!value)
    return 0;
  v = strdup(value);
  if (!v)
    return -ENOMEM;
  r = strv_push(l, v);
  if (r < 0)
    free(v);
  return r;
}


x86 assembly (clang, -O0):
<strv_extend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1157 <strv_extend+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11ab <strv_extend+0x7b>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1182 <strv_extend+0x52>
xor    %eax,%eax
mov    0x2e68(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <strv_extend+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strv_push@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a5 <strv_extend+0x75>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strv_extend>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1167 <strv_extend+0x37>
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <strdup@plt>
test   %rax,%rax
je     116b <strv_extend+0x3b>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strv_push@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1176 <strv_extend+0x46>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1176 <strv_extend+0x46>
xor    %ebx,%ebx
jmp    1176 <strv_extend+0x46>
mov    0x2e6e(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
define i32 @strv_extend(i8*** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8***
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8*** %0, i8**** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 0, i32* %3
br label %30
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = load i32, i32* @ENOMEM
%18 = sub nsw i32 0, %17
store i32 %18, i32* %3
br label %30
19: ; preds = %11
%20 = load i8***, i8**** %4
%21 = load i8*, i8** %6
%22 = call i32 @strv_push(i8*** %20, i8* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %25, %19
%29 = load i32, i32* %7
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %16, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@ENOMEM = global i32 0
define i32 @strv_extend(i8*** %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i8* @strdup(i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @ENOMEM
%9 = sub nsw i32 0, %8
br label %15
10: ; preds = %4
%11 = tail call i32 @strv_push(i8*** %0, i8* %5)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @free(i8* %5)
br label %15
15: ; preds = %10, %13, %2, %7
%16 = phi i32 [ %9, %7 ], [ 0, %2 ], [ %11, %13 ], [ %11, %10 ]
ret i32 %16
}