#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 */
typedef int /*<<< orphan*/ arrSecond;
typedef int /*<<< orphan*/ arrFirst;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ free(double *);
double *mergeArray(double *, double *, int, int, int, int *);
int /*<<< orphan*/ printArray(double *, int);
int /*<<< orphan*/ printf(char *);
int main(void) {
  double arrFirst[5] = {-10.5, -1.8, 3.5, 6.3, 7.2};
  double arrSecond[3] = {-1.8, 3.1, 6.3};
  int worstCase = ((sizeof(arrFirst) + sizeof(arrSecond)) / sizeof(double));
  int arrFirstSize = sizeof(arrFirst) / sizeof(double);
  int arrSecondSize = sizeof(arrSecond) / sizeof(double);
  int arrMergeSize;
  double *arrMerge = mergeArray(arrFirst, arrSecond, worstCase, arrFirstSize,
                                arrSecondSize, &arrMergeSize);
  printf("Merging first array:\t");
  printArray(arrFirst, arrFirstSize);
  printf("\nand second array:\t");
  printArray(arrSecond, arrSecondSize);
  printf("\nyields merged array:\t");
  printArray(arrMerge, arrMergeSize);
  printf("\n");
  free(arrMerge);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe94(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe7f(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe6a(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe55(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0xe79(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe76(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x8,-0x54(%rbp)
movl   $0x5,-0x58(%rbp)
movl   $0x3,-0x5c(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x5c(%rbp),%r8d
lea    -0x60(%rbp),%r9
call   1030 <mergeArray@plt>
mov    %rax,-0x68(%rbp)
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x58(%rbp),%esi
call   1070 <printArray@plt>
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%esi
call   1070 <printArray@plt>
lea    0xe36(%rip),%rdi
call   1050 <printf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%esi
call   1070 <printArray@plt>
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
mov    -0x68(%rbp),%rdi
call   1040 <free@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
movaps 0xea0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movabs $0x401ccccccccccccd,%rax
cc 1c 40
mov    %rax,0x50(%rsp)
mov    0xea9(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x30(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r9
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
mov    $0x5,%ecx
mov    $0x3,%r8d
call   1030 <mergeArray@plt>
mov    %rax,%rbx
lea    0xe6c(%rip),%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1070 <printArray@plt>
lea    0xe69(%rip),%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    $0x3,%esi
call   1070 <printArray@plt>
lea    0xe64(%rip),%rdi
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1070 <printArray@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.arrSecond = [3 x double] [double -1.800000e+00, double 3.100000e+00, double 6.300000e+00]
@.str = [22 x i8] c"Merging first array:\09\00"
@.str.1 = [20 x i8] c"\0Aand second array:\09\00"
@.str.2 = [23 x i8] c"\0Ayields merged array:\09\00"
@.str.3 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x double]
%3 = alloca [3 x double]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
store i32 0, i32* %1
%9 = bitcast [5 x double]* %2 to i8*
%10 = bitcast i8* %9 to [5 x double]*
%11 = getelementptr inbounds [5 x double], [5 x double]* %10, i32 0, i32 0
store double -1.050000e+01, double* %11
%12 = getelementptr inbounds [5 x double], [5 x double]* %10, i32 0, i32 1
store double -1.800000e+00, double* %12
%13 = getelementptr inbounds [5 x double], [5 x double]* %10, i32 0, i32 2
store double 3.500000e+00, double* %13
%14 = getelementptr inbounds [5 x double], [5 x double]* %10, i32 0, i32 3
store double 6.300000e+00, double* %14
%15 = getelementptr inbounds [5 x double], [5 x double]* %10, i32 0, i32 4
store double 7.200000e+00, double* %15
%16 = bitcast [3 x double]* %3 to i8*
store i32 8, i32* %4
store i32 5, i32* %5
store i32 3, i32* %6
%17 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%18 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call double* @mergeArray(double* %17, double* %18, i32 %19, i32 %20, i32 %21, i32* %7)
store double* %22, double** %8
%23 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @printArray(double* %24, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%29 = load i32, i32* %6
%30 = call i32 @printArray(double* %28, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%32 = load double*, double** %8
%33 = load i32, i32* %7
%34 = call i32 @printArray(double* %32, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = load double*, double** %8
%37 = call i32 @free(double* %36)
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}

LLVM IR (-O2):
@__const.main.arrSecond = [3 x double] [double -1.800000e+00, double 3.100000e+00, double 6.300000e+00]
@.str = [22 x i8] c"Merging first array:\09\00"
@.str.1 = [20 x i8] c"\0Aand second array:\09\00"
@.str.2 = [23 x i8] c"\0Ayields merged array:\09\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [5 x double]
%2 = alloca [3 x double]
%3 = alloca i32
%4 = bitcast [5 x double]* %1 to i8*
%5 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 0
%6 = bitcast [5 x double]* %1 to <2 x double>*
store <2 x double> <double -1.050000e+01, double -1.800000e+00>, <2 x double>* %6
%7 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 2
%8 = bitcast double* %7 to <2 x double>*
store <2 x double> <double 3.500000e+00, double 6.300000e+00>, <2 x double>* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 4
store double 7.200000e+00, double* %9
%10 = bitcast [3 x double]* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
%13 = call double* @mergeArray(double* %5, double* %12, i32 8, i32 5, i32 3, i32* %3)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @printArray(double* %5, i32 5)
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @printArray(double* %12, i32 3)
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = call i32 @printArray(double* %13, i32 %19)
%21 = call i32 @putchar(i32 10)
%22 = call i32 @free(double* %13)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}