#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;
char **realloc(char **, int);
unsigned int strv_length(char **);
int strv_push(char ***l, char *value) {
  char **c;
  unsigned n;
  if (!value)
    return 0;
  n = strv_length(*l);
  c = realloc(*l, sizeof(char *) * (n + 2));
  if (!c)
    return -ENOMEM;
  c[n] = value;
  c[n + 1] = NULL;
  *l = c;
  return 0;
}


x86 assembly (clang, -O0):
<strv_push>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1147 <strv_push+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <strv_push+0xa7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strv_length@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1192 <strv_push+0x72>
xor    %eax,%eax
mov    0x2e58(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <strv_push+0xa7>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strv_push>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rsi,%rsi
je     1176 <strv_push+0x56>
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1030 <strv_length@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
lea    0x10(,%rbp,8),%esi
call   1040 <realloc@plt>
test   %rax,%rax
je     1169 <strv_push+0x49>
mov    %ebp,%ecx
mov    %r15,(%rax,%rcx,8)
add    $0x1,%ebp
movq   $0x0,(%rax,%rbp,8)
mov    %rax,(%rbx)
jmp    1176 <strv_push+0x56>
mov    0x2e70(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
define i32 @strv_push(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 %41
11: ; preds = %2
%12 = load i8***, i8**** %4
%13 = load i8**, i8*** %12
%14 = call i32 @strv_length(i8** %13)
store i32 %14, i32* %7
%15 = load i8***, i8**** %4
%16 = load i8**, i8*** %15
%17 = load i32, i32* %7
%18 = add i32 %17, 2
%19 = zext i32 %18 to i64
%20 = mul i64 8, %19
%21 = trunc i64 %20 to i32
%22 = call i8** @realloc(i8** %16, i32 %21)
store i8** %22, i8*** %6
%23 = load i8**, i8*** %6
%24 = icmp ne i8** %23, null
br i1 %24, label %28, label %25
25: ; preds = %11
%26 = load i32, i32* @ENOMEM
%27 = sub nsw i32 0, %26
store i32 %27, i32* %3
br label %41
28: ; preds = %11
%29 = load i8*, i8** %5
%30 = load i8**, i8*** %6
%31 = load i32, i32* %7
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
store i8* %29, i8** %33
%34 = load i8**, i8*** %6
%35 = load i32, i32* %7
%36 = add i32 %35, 1
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %34, i64 %37
store i8* null, i8** %38
%39 = load i8**, i8*** %6
%40 = load i8***, i8**** %4
store i8** %39, i8*** %40
store i32 0, i32* %3
br label %41
41: ; preds = %28, %25, %10
%42 = load i32, i32* %3
ret i32 %42
}

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