#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 */
double *malloc(int);
int /*<<< orphan*/ memcpy(double *, double const *, int);
double *trg_concatenate(int size, const double *k, const double *ps) {
  double *result = malloc(sizeof(double));
  result = malloc(2 * size * sizeof(double));
  memcpy(result, k, size * sizeof(double));
  memcpy(result + size, ps, size * sizeof(double));
  return result;
}


x86 assembly (clang, -O0):
<trg_concatenate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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