#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_length(char **);
int /*<<< orphan*/ copy_array(char **, char **);
char **malloc(int);
char **concat_array(char **array1, char **array2) {
  int i = array_length(array1);
  int j = array_length(array2);
  int length = i + j + 1;
  char **result = malloc(sizeof(char *) * (length + 1));
  copy_array(result, array1);
  copy_array(&result[i], array2);
  return result;
}


x86 assembly (clang, -O0):
<concat_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <array_length@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <array_length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <copy_array@plt>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <copy_array@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <array_length@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <array_length@plt>
add    %ebp,%eax
lea    0x10(,%rax,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <copy_array@plt>
movslq %ebp,%rax
lea    (%rbx,%rax,8),%rdi
mov    %r14,%rsi
call   1050 <copy_array@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8** @concat_array(i8** %0, i8** %1) {
%3 = tail call i32 @array_length(i8** %0)
%4 = tail call i32 @array_length(i8** %1)
%5 = add nsw i32 %4, %3
%6 = shl i32 %5, 3
%7 = add i32 %6, 16
%8 = tail call i8** @malloc(i32 %7)
%9 = tail call i32 @copy_array(i8** %8, i8** %0)
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = tail call i32 @copy_array(i8** %11, i8** %1)
ret i8** %8
}