#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*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
char **realloc(char **, size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
void concat_array(char ***dest_array, size_t *dest_size,
                  const char **copy_array, const size_t copy_size) {
  size_t total_size = *dest_size + copy_size;
  char **temp_ptr = *dest_array;
  temp_ptr = realloc(*dest_array, total_size * sizeof(char *));
  if (temp_ptr == NULL) {
    perror("realloc(): ");
    exit(errno);
  }
  *dest_array = temp_ptr;
  size_t length;
  char *dest_ptr = NULL;
  for (size_t i = 0; i < copy_size; ++i) {
    length = strlen(copy_array[i]);
    dest_ptr = (*dest_array)[*dest_size + i] =
        malloc((length + 1) * sizeof(char));
    strcpy(dest_ptr, copy_array[i]);
  }
  *dest_size = total_size;
}


x86 assembly (clang, -O0):
<concat_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
shl    $0x3,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11cf <concat_array+0x6f>
lea    0xe44(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    125e <concat_array+0xfe>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rdx
add    -0x48(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11ea <concat_array+0x8a>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rsi),%rax
add    %rcx,%rax
mov    (%rdi),%rdi
mov    %rax,(%rsp)
lea    0x0(,%rax,8),%rsi
call   1060 <realloc@plt>
test   %rax,%rax
je     11ff <concat_array+0x9f>
mov    %rax,%rbx
mov    %rax,(%r12)
test   %r15,%r15
je     11e9 <concat_array+0x89>
add    $0xffffffffffffffff,%r15
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbp,8),%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    (%r14),%rcx
add    %rbp,%rcx
mov    %rax,(%rbx,%rcx,8)
mov    0x0(%r13,%rbp,8),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
cmp    %rbp,%r15
je     11e9 <concat_array+0x89>
mov    (%r12),%rbx
add    $0x1,%rbp
jmp    11b0 <concat_array+0x50>
mov    (%rsp),%rax
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfa(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"realloc(): \00"
@errno = global i32 0
define void @concat_array(i8*** %0, i64* %1, i8** %2, i64 %3) {
%5 = alloca i8***
%6 = alloca i64*
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8**
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
store i8*** %0, i8**** %5
store i64* %1, i64** %6
store i8** %2, i8*** %7
store i64 %3, i64* %8
%14 = load i64*, i64** %6
%15 = load i64, i64* %14
%16 = load i64, i64* %8
%17 = add i64 %15, %16
store i64 %17, i64* %9
%18 = load i8***, i8**** %5
%19 = load i8**, i8*** %18
store i8** %19, i8*** %10
%20 = load i8***, i8**** %5
%21 = load i8**, i8*** %20
%22 = load i64, i64* %9
%23 = mul i64 %22, 8
%24 = call i8** @realloc(i8** %21, i64 %23)
store i8** %24, i8*** %10
%25 = load i8**, i8*** %10
%26 = icmp eq i8** %25, null
br i1 %26, label %27, label %31
27: ; preds = %4
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @errno
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %4
%32 = load i8**, i8*** %10
%33 = load i8***, i8**** %5
store i8** %32, i8*** %33
store i8* null, i8** %12
store i64 0, i64* %13
br label %34
34: ; preds = %61, %31
%35 = load i64, i64* %13
%36 = load i64, i64* %8
%37 = icmp ult i64 %35, %36
br i1 %37, label %38, label %64
38: ; preds = %34
%39 = load i8**, i8*** %7
%40 = load i64, i64* %13
%41 = getelementptr inbounds i8*, i8** %39, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @strlen(i8* %42)
store i64 %43, i64* %11
%44 = load i64, i64* %11
%45 = add i64 %44, 1
%46 = mul i64 %45, 1
%47 = call i8* @malloc(i64 %46)
%48 = load i8***, i8**** %5
%49 = load i8**, i8*** %48
%50 = load i64*, i64** %6
%51 = load i64, i64* %50
%52 = load i64, i64* %13
%53 = add i64 %51, %52
%54 = getelementptr inbounds i8*, i8** %49, i64 %53
store i8* %47, i8** %54
store i8* %47, i8** %12
%55 = load i8*, i8** %12
%56 = load i8**, i8*** %7
%57 = load i64, i64* %13
%58 = getelementptr inbounds i8*, i8** %56, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 @strcpy(i8* %55, i8* %59)
br label %61
61: ; preds = %38
%62 = load i64, i64* %13
%63 = add i64 %62, 1
store i64 %63, i64* %13
br label %34
64: ; preds = %34
%65 = load i64, i64* %9
%66 = load i64*, i64** %6
store i64 %65, i64* %66
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"realloc(): \00"
@errno = global i32 0
define void @concat_array(i8*** nocapture %0, i64* nocapture %1, i8** nocapture %2, i64 %3) {
%5 = load i64, i64* %1
%6 = add i64 %5, %3
%7 = load i8**, i8*** %0
%8 = shl i64 %6, 3
%9 = tail call i8** @realloc(i8** %7, i64 %8)
%10 = icmp eq i8** %9, null
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @errno
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %4
store i8** %9, i8*** %0
%16 = icmp eq i64 %3, 0
br i1 %16, label %17, label %18
17: ; preds = %18, %15
store i64 %6, i64* %1
ret void
18: ; preds = %15, %33
%19 = phi i8** [ %34, %33 ], [ %9, %15 ]
%20 = phi i64 [ %31, %33 ], [ 0, %15 ]
%21 = getelementptr inbounds i8*, i8** %2, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i64 @strlen(i8* dereferenceable(1) %22)
%24 = add i64 %23, 1
%25 = tail call i8* @malloc(i64 %24)
%26 = load i64, i64* %1
%27 = add i64 %26, %20
%28 = getelementptr inbounds i8*, i8** %19, i64 %27
store i8* %25, i8** %28
%29 = load i8*, i8** %21
%30 = tail call i32 @strcpy(i8* %25, i8* %29)
%31 = add nuw i64 %20, 1
%32 = icmp eq i64 %31, %3
br i1 %32, label %17, label %33
33: ; preds = %18
%34 = load i8**, i8*** %0
br label %18
}