#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);
double *merge(double *, double *, int const, int const);
void merge_sort(double *list, const int size) {
  double *sort = malloc(sizeof(double));
  if (size <= 1)
    sort[0] = list[0];
  else {
    const int size_first = size / 2;
    const int size_second = size - size_first;
    double first[size_first];
    double second[size_second];
    int i = 0;
    for (; i < size_first; i++)
      first[i] = list[i];
    i = 0;
    for (; i < size_second; i++)
      second[i] = list[size_first + i];
    merge_sort(first, size_first);
    merge_sort(second, size_second);
    list = merge(first, second, size_first, size_second);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     116c <merge_sort+0x3c>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    127e <merge_sort+0x14e>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
sar    %eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1208 <merge_sort+0xd8>
mov    -0x50(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d4 <merge_sort+0xa4>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1248 <merge_sort+0x118>
mov    -0x48(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%edx
add    -0x3c(%rbp),%edx
movslq %edx,%rdx
movsd  (%rcx,%rdx,8),%xmm0
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    120f <merge_sort+0xdf>
mov    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <merge_sort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <merge_sort@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <merge@plt>
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
mov    $0x8,%edi
call   1050 <malloc@plt>
cmp    $0x1,%r15d
jg     1174 <merge_sort+0x34>
movsd  (%rbx),%xmm0
movsd  %xmm0,(%rax)
jmp    1211 <merge_sort+0xd1>
mov    %rsp,-0x38(%rbp)
mov    %rbx,%rsi
mov    %r15d,%ebx
shr    %ebx
mov    %r15d,%r14d
sub    %ebx,%r14d
mov    %rsp,%r13
lea    0xf(,%rbx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
lea    0x0(,%rbx,8),%rdx
mov    %r13,%rdi
mov    %rsi,-0x30(%rbp)
call   1030 <memcpy@plt>
test   %r14d,%r14d
jle    11e8 <merge_sort+0xa8>
mov    -0x30(%rbp),%rax
lea    (%rax,%rbx,8),%rsi
mov    %ebx,%eax
not    %eax
add    %r15d,%eax
lea    0x8(,%rax,8),%rdx
mov    %r12,%rdi
call   1030 <memcpy@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1060 <merge_sort@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <merge_sort@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1040 <merge@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @merge_sort(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%12 = call double* @malloc(i32 8)
store double* %12, double** %5
%13 = load i32, i32* %4
%14 = icmp sle i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load double*, double** %3
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
%19 = load double*, double** %5
%20 = getelementptr inbounds double, double* %19, i64 0
store double %18, double* %20
br label %76
21: ; preds = %2
%22 = load i32, i32* %4
%23 = sdiv i32 %22, 2
store i32 %23, i32* %6
%24 = load i32, i32* %4
%25 = load i32, i32* %6
%26 = sub nsw i32 %24, %25
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %8
%30 = alloca double, i64 %28
store i64 %28, i64* %9
%31 = load i32, i32* %7
%32 = zext i32 %31 to i64
%33 = alloca double, i64 %32
store i64 %32, i64* %10
store i32 0, i32* %11
br label %34
34: ; preds = %47, %21
%35 = load i32, i32* %11
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %50
38: ; preds = %34
%39 = load double*, double** %3
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %30, i64 %45
store double %43, double* %46
br label %47
47: ; preds = %38
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %34
50: ; preds = %34
store i32 0, i32* %11
br label %51
51: ; preds = %66, %50
%52 = load i32, i32* %11
%53 = load i32, i32* %7
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %69
55: ; preds = %51
%56 = load double*, double** %3
%57 = load i32, i32* %6
%58 = load i32, i32* %11
%59 = add nsw i32 %57, %58
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %56, i64 %60
%62 = load double, double* %61
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %33, i64 %64
store double %62, double* %65
br label %66
66: ; preds = %55
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %51
69: ; preds = %51
%70 = load i32, i32* %6
%71 = load i32, i32* %7
%72 = load i32, i32* %6
%73 = load i32, i32* %7
%74 = call double* @merge(double* %30, double* %33, i32 %72, i32 %73)
store double* %74, double** %3
%75 = load i8*, i8** %8
br label %76
76: ; preds = %69, %15
ret void
}

LLVM IR (-O2):
define void @merge_sort(double* nocapture %0, i32 %1) {
%3 = tail call double* @malloc(i32 8)
%4 = icmp slt i32 %1, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load double, double* %0
store double %6, double* %3
br label %33
7: ; preds = %2
%8 = bitcast double* %0 to i8*
%9 = lshr i32 %1, 1
%10 = sub nsw i32 %1, %9
%11 = zext i32 %9 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca double, i64 %11
%14 = zext i32 %10 to i64
%15 = alloca double, i64 %14
%16 = bitcast double* %13 to i8*
%17 = zext i32 %9 to i64
%18 = shl nuw nsw i64 %17, 3
%19 = icmp sgt i32 %10, 0
br i1 %19, label %20, label %31
20: ; preds = %7
%21 = bitcast double* %15 to i8*
%22 = lshr i32 %1, 1
%23 = zext i32 %22 to i64
%24 = getelementptr double, double* %0, i64 %23
%25 = bitcast double* %24 to i8*
%26 = xor i32 %9, -1
%27 = add i32 %26, %1
%28 = zext i32 %27 to i64
%29 = shl nuw nsw i64 %28, 3
%30 = add nuw nsw i64 %29, 8
br label %31
31: ; preds = %20, %7
%32 = call double* @merge(double* %13, double* %15, i32 %9, i32 %10)
br label %33
33: ; preds = %31, %5
ret void
}