#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*/ free(double *);
double *merge(double *, int const, double *, int const, int *);
int /*<<< orphan*/ print_arr(double *, int const);
int /*<<< orphan*/ printf(char *);
int main(void) {
  const int arr1_size = 5;
  const int arr2_size = 4;
  double arr1[5] = {1.2, 2., 4.6, 10.125, 50};
  double arr2[4] = {0.1, 2., 6.9, 17.};
  int merged_size;
  double *merged = merge(arr1, arr1_size, arr2, arr2_size, &merged_size);
  printf("Array #1: ");
  print_arr(arr1, arr1_size);
  printf("\nArray #2: ");
  print_arr(arr2, arr2_size);
  printf("\nMerged array: ");
  print_arr(merged, merged_size);
  printf("\n");
  free(merged);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe71(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe5c(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe47(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0xe6b(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe68(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe65(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe62(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rdx
mov    $0x5,%esi
mov    $0x4,%ecx
lea    -0x64(%rbp),%r8
call   1070 <merge@plt>
mov    %rax,-0x70(%rbp)
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x5,%esi
call   1040 <print_arr@plt>
lea    0xe31(%rip),%rdi
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x4,%esi
call   1040 <print_arr@plt>
lea    0xe23(%rip),%rdi
call   1050 <printf@plt>
mov    -0x70(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1040 <print_arr@plt>
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%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,0x10(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0x4049000000000000,%rax
mov    %rax,0x30(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
lea    0x10(%rsp),%r14
lea    0x40(%rsp),%r15
lea    0xc(%rsp),%r8
mov    %r14,%rdi
mov    $0x5,%esi
mov    %r15,%rdx
mov    $0x4,%ecx
call   1070 <merge@plt>
mov    %rax,%rbx
lea    0xe7a(%rip),%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1050 <print_arr@plt>
lea    0xe6c(%rip),%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    $0x4,%esi
call   1050 <print_arr@plt>
lea    0xe5f(%rip),%rdi
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <print_arr@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.arr2 = [4 x double] [double 1.000000e-01, double 2.000000e+00, double 6.900000e+00, double 1.700000e+01]
@.str = [11 x i8] c"Array: \00"
@.str.1 = [12 x i8] c"\0AArray: \00"
@.str.2 = [16 x i8] c"\0AMerged array: \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [5 x double]
%5 = alloca [4 x double]
%6 = alloca i32
%7 = alloca double*
store i32 0, i32* %1
store i32 5, i32* %2
store i32 4, i32* %3
%8 = bitcast [5 x double]* %4 to i8*
%9 = bitcast i8* %8 to [5 x double]*
%10 = getelementptr inbounds [5 x double], [5 x double]* %9, i32 0, i32 0
store double 1.200000e+00, double* %10
%11 = getelementptr inbounds [5 x double], [5 x double]* %9, i32 0, i32 1
store double 2.000000e+00, double* %11
%12 = getelementptr inbounds [5 x double], [5 x double]* %9, i32 0, i32 2
store double 4.600000e+00, double* %12
%13 = getelementptr inbounds [5 x double], [5 x double]* %9, i32 0, i32 3
store double 1.012500e+01, double* %13
%14 = getelementptr inbounds [5 x double], [5 x double]* %9, i32 0, i32 4
store double 5.000000e+01, double* %14
%15 = bitcast [4 x double]* %5 to i8*
%16 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 0
%17 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%18 = call double* @merge(double* %16, i32 5, double* %17, i32 4, i32* %6)
store double* %18, double** %7
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 0
%21 = call i32 @print_arr(double* %20, i32 5)
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%24 = call i32 @print_arr(double* %23, i32 4)
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%26 = load double*, double** %7
%27 = load i32, i32* %6
%28 = call i32 @print_arr(double* %26, i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = load double*, double** %7
%31 = call i32 @free(double* %30)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr2 = [4 x double] [double 1.000000e-01, double 2.000000e+00, double 6.900000e+00, double 1.700000e+01]
@.str = [11 x i8] c"Array: \00"
@.str.1 = [12 x i8] c"\0AArray: \00"
@.str.2 = [16 x i8] c"\0AMerged array: \00"
define i32 @main() {
%1 = alloca [5 x double]
%2 = alloca [4 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.200000e+00, double 2.000000e+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 4.600000e+00, double 1.012500e+01>, <2 x double>* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 4
store double 5.000000e+01, double* %9
%10 = bitcast [4 x double]* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%13 = call double* @merge(double* %5, i32 5, double* %12, i32 4, i32* %3)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @print_arr(double* %5, i32 5)
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @print_arr(double* %12, i32 4)
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = call i32 @print_arr(double* %13, i32 %19)
%21 = call i32 @putchar(i32 10)
%22 = call i32 @free(double* %13)
ret i32 0
}