#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_multiply(char **, int, unsigned int);
unsigned int strv_length(char **);
int strv_push(char ***l, char *value) {
  char **c;
  unsigned n, m;
  if (!value)
    return 0;
  n = strv_length(*l);
  m = n + 2;
  if (m < n)
    return -ENOMEM;
  c = realloc_multiply(*l, sizeof(char *), m);
  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    11e9 <strv_push+0xc9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strv_length@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    117e <strv_push+0x5e>
xor    %eax,%eax
mov    0x2e6c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <strv_push+0xc9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%edx
mov    $0x8,%esi
call   1040 <realloc_multiply@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b4 <strv_push+0x94>
xor    %eax,%eax
mov    0x2e36(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <strv_push+0xc9>
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   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rsi,%rsi
je     117c <strv_push+0x5c>
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1030 <strv_length@plt>
cmp    $0xfffffffe,%eax
jae    1171 <strv_push+0x51>
mov    %eax,%r12d
lea    0x2(%r12),%edx
mov    (%r14),%rdi
mov    $0x8,%esi
call   1040 <realloc_multiply@plt>
test   %rax,%rax
je     1171 <strv_push+0x51>
mov    %r12d,%ecx
mov    %r15,(%rax,%rcx,8)
movq   $0x0,0x8(%rax,%rcx,8)
mov    %rax,(%r14)
jmp    117c <strv_push+0x5c>
mov    0x2e68(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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
%8 = alloca i32
store i8*** %0, i8**** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %47
12: ; preds = %2
%13 = load i8***, i8**** %4
%14 = load i8**, i8*** %13
%15 = call i32 @strv_length(i8** %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = add i32 %16, 2
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* @ENOMEM
%23 = sub nsw i32 0, %22
store i32 %23, i32* %3
br label %47
24: ; preds = %12
%25 = load i8***, i8**** %4
%26 = load i8**, i8*** %25
%27 = load i32, i32* %8
%28 = call i8** @realloc_multiply(i8** %26, i32 8, i32 %27)
store i8** %28, i8*** %6
%29 = load i8**, i8*** %6
%30 = icmp ne i8** %29, null
br i1 %30, label %34, label %31
31: ; preds = %24
%32 = load i32, i32* @ENOMEM
%33 = sub nsw i32 0, %32
store i32 %33, i32* %3
br label %47
34: ; preds = %24
%35 = load i8*, i8** %5
%36 = load i8**, i8*** %6
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
store i8* %35, i8** %39
%40 = load i8**, i8*** %6
%41 = load i32, i32* %7
%42 = add i32 %41, 1
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %40, i64 %43
store i8* null, i8** %44
%45 = load i8**, i8*** %6
%46 = load i8***, i8**** %4
store i8** %45, i8*** %46
store i32 0, i32* %3
br label %47
47: ; preds = %34, %31, %21, %11
%48 = load i32, i32* %3
ret i32 %48
}

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 %25, label %4
4: ; preds = %2
%5 = load i8**, i8*** %0
%6 = tail call i32 @strv_length(i8** %5)
%7 = icmp ugt i32 %6, -3
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @ENOMEM
%10 = sub nsw i32 0, %9
br label %25
11: ; preds = %4
%12 = add nuw i32 %6, 2
%13 = load i8**, i8*** %0
%14 = tail call i8** @realloc_multiply(i8** %13, i32 8, i32 %12)
%15 = icmp eq i8** %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @ENOMEM
%18 = sub nsw i32 0, %17
br label %25
19: ; preds = %11
%20 = zext i32 %6 to i64
%21 = getelementptr inbounds i8*, i8** %14, i64 %20
store i8* %1, i8** %21
%22 = add nuw i32 %6, 1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %14, i64 %23
store i8* null, i8** %24
store i8** %14, i8*** %0
br label %25
25: ; preds = %2, %19, %16, %8
%26 = phi i32 [ %10, %8 ], [ 0, %19 ], [ %18, %16 ], [ 0, %2 ]
ret i32 %26
}