#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int **realloc(int **, int);
int **addArrayToArray(int **array, int *toAdd, int oldcount) {
  if (array == NULL) {
    printf("Array must be initialized");
    exit(1);
  } else
    array = realloc(array, sizeof(int *) * (oldcount + 1));
  array[oldcount] = toAdd;
  return array;
}


x86 assembly (clang, -O0):
<addArrayToArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1164 <addArrayToArray+0x34>
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addArrayToArray>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1159 <addArrayToArray+0x29>
mov    %edx,%ebx
mov    %rsi,%r14
lea    0x8(,%rbx,8),%esi
call   1040 <realloc@plt>
movslq %ebx,%rcx
mov    %r14,(%rax,%rcx,8)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Array must be initialized\00"
define i32** @addArrayToArray(i32** %0, i32* %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i32
store i32** %0, i32*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32**, i32*** %4
%8 = icmp eq i32** %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = load i32**, i32*** %4
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = mul i64 8, %16
%18 = trunc i64 %17 to i32
%19 = call i32** @realloc(i32** %13, i32 %18)
store i32** %19, i32*** %4
br label %20
20: ; preds = %12
%21 = load i32*, i32** %5
%22 = load i32**, i32*** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32*, i32** %22, i64 %24
store i32* %21, i32** %25
%26 = load i32**, i32*** %4
ret i32** %26
}

LLVM IR (-O2):
@.str = [26 x i8] c"Array must be initialized\00"
define i32** @addArrayToArray(i32** %0, i32* %1, i32 %2) {
%4 = icmp eq i32** %0, null
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %3
%9 = shl i32 %2, 3
%10 = add i32 %9, 8
%11 = tail call i32** @realloc(i32** %0, i32 %10)
%12 = sext i32 %2 to i64
%13 = getelementptr inbounds i32*, i32** %11, i64 %12
store i32* %1, i32** %13
ret i32** %11
}