#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 */
char **malloc(int);
int /*<<< orphan*/ memcpy(char **, char **, size_t);
char **__array_concat_at_end(void *v1, void *v2, int length) {
  char *last_text = (char *)v2;
  char **preceding_texts = (char **)v1;
  char **all_texts = malloc(sizeof(char *) * (length + 1));
  size_t char_ptr_size = sizeof(char *);
  *(all_texts + length) = last_text;
  memcpy(all_texts, preceding_texts, char_ptr_size * length);
  return all_texts;
}


x86 assembly (clang, -O0):
<__array_concat_at_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movq   $0x8,-0x38(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
movslq -0x14(%rbp),%rax
imul   %rax,%rdx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__array_concat_at_end>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(,%r12,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movslq %r12d,%rdx
mov    %r14,(%rax,%rdx,8)
shl    $0x3,%rdx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @__array_concat_at_end(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
store i8* %11, i8** %7
%12 = load i8*, i8** %4
%13 = bitcast i8* %12 to i8**
store i8** %13, i8*** %8
%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 i8** @malloc(i32 %18)
store i8** %19, i8*** %9
store i64 8, i64* %10
%20 = load i8*, i8** %7
%21 = load i8**, i8*** %9
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %20, i8** %24
%25 = load i8**, i8*** %9
%26 = load i8**, i8*** %8
%27 = load i64, i64* %10
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = mul i64 %27, %29
%31 = call i32 @memcpy(i8** %25, i8** %26, i64 %30)
%32 = load i8**, i8*** %9
ret i8** %32
}

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