#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 */
scalar_t__ safe_malloc(int);
scalar_t__ safe_realloc(char **, int);
void append(char ***array, int *num, char *value) {
  (*num)++;
  if (*array == NULL)
    *array = (char **)safe_malloc(sizeof(char *));
  else
    *array = (char **)safe_realloc(*array, sizeof(char *) * *num);
  (*array)[*num - 1] = value;
}


x86 assembly (clang, -O0):
<append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1166 <append+0x46>
mov    $0x8,%edi
call   1030 <safe_malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    1189 <append+0x69>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <safe_realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%esi
add    $0x1,%esi
mov    %esi,(%rbx)
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1147 <append+0x27>
shl    $0x3,%esi
call   1040 <safe_realloc@plt>
jmp    1151 <append+0x31>
mov    $0x8,%edi
call   1030 <safe_malloc@plt>
mov    %rax,(%r15)
movslq (%rbx),%rcx
mov    %r14,-0x8(%rax,%rcx,8)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @append(i8*** %0, i32* %1, i8* %2) {
%4 = alloca i8***
%5 = alloca i32*
%6 = alloca i8*
store i8*** %0, i8**** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%7 = load i32*, i32** %5
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1
store i32 %9, i32* %7
%10 = load i8***, i8**** %4
%11 = load i8**, i8*** %10
%12 = icmp eq i8** %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = call i64 @safe_malloc(i32 8)
%15 = inttoptr i64 %14 to i8**
%16 = load i8***, i8**** %4
store i8** %15, i8*** %16
br label %28
17: ; preds = %3
%18 = load i8***, i8**** %4
%19 = load i8**, i8*** %18
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = mul i64 8, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @safe_realloc(i8** %19, i32 %24)
%26 = inttoptr i64 %25 to i8**
%27 = load i8***, i8**** %4
store i8** %26, i8*** %27
br label %28
28: ; preds = %17, %13
%29 = load i8*, i8** %6
%30 = load i8***, i8**** %4
%31 = load i8**, i8*** %30
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %31, i64 %35
store i8* %29, i8** %36
ret void
}

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