#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 array_count(char **);
char **xrealloc(char **, int);
int array_add(char ***array, char *string) {
  int count = array_count(*array);
  *array = xrealloc(*array, (count + 2) * sizeof(char *));
  (*array)[count + 1] = NULL;
  (*array)[count] = string;
  return count + 1;
}


x86 assembly (clang, -O0):
<array_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <array_count@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <xrealloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_add>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
call   1030 <array_count@plt>
mov    %eax,%ebx
mov    (%r15),%rdi
lea    0x10(,%rbx,8),%esi
call   1040 <xrealloc@plt>
mov    %rax,(%r15)
movslq %ebx,%rcx
add    $0x1,%ebx
movq   $0x0,0x8(%rax,%rcx,8)
mov    (%r15),%rax
mov    %r14,(%rax,%rcx,8)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @array_add(i8*** %0, i8* %1) {
%3 = alloca i8***
%4 = alloca i8*
%5 = alloca i32
store i8*** %0, i8**** %3
store i8* %1, i8** %4
%6 = load i8***, i8**** %3
%7 = load i8**, i8*** %6
%8 = call i32 @array_count(i8** %7)
store i32 %8, i32* %5
%9 = load i8***, i8**** %3
%10 = load i8**, i8*** %9
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call i8** @xrealloc(i8** %10, i32 %15)
%17 = load i8***, i8**** %3
store i8** %16, i8*** %17
%18 = load i8***, i8**** %3
%19 = load i8**, i8*** %18
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %19, i64 %22
store i8* null, i8** %23
%24 = load i8*, i8** %4
%25 = load i8***, i8**** %3
%26 = load i8**, i8*** %25
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* %24, i8** %29
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
ret i32 %31
}

LLVM IR (-O2):
define i32 @array_add(i8*** nocapture %0, i8* %1) {
%3 = load i8**, i8*** %0
%4 = tail call i32 @array_count(i8** %3)
%5 = load i8**, i8*** %0
%6 = shl i32 %4, 3
%7 = add i32 %6, 16
%8 = tail call i8** @xrealloc(i8** %5, i32 %7)
store i8** %8, i8*** %0
%9 = add nsw i32 %4, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
store i8* null, i8** %11
%12 = load i8**, i8*** %0
%13 = sext i32 %4 to i64
%14 = getelementptr inbounds i8*, i8** %12, i64 %13
store i8* %1, i8** %14
ret i32 %9
}