#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*/ Merge(int, int, int, double const *, int *);
void Mergesortd(int p, int q, const double *key, int *order) {
  int m;
  if (p >= q)
    return;
  m = (p + q) / 2;
  if (p < m)
    Mergesortd(p, m, key, order);
  if (m + 1 < q)
    Mergesortd(m + 1, q, key, order);
  Merge(p, m, q, key, order);
}


x86 assembly (clang, -O0):
<Mergesortd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1147 <Mergesortd+0x27>
jmp    11b2 <Mergesortd+0x92>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1177 <Mergesortd+0x57>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <Mergesortd@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    119c <Mergesortd+0x7c>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <Mergesortd@plt>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <Merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Mergesortd>:
cmp    %esi,%edi
jge    118c <Mergesortd+0x6c>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%r13d
lea    (%r12,%r13,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
cmp    %edi,%ebx
jle    115a <Mergesortd+0x3a>
mov    %r13d,%edi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <Mergesortd@plt>
lea    0x1(%rbx),%edi
cmp    %r12d,%edi
jge    1170 <Mergesortd+0x50>
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <Mergesortd@plt>
mov    %r13d,%edi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14,%r8
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <Merge@plt>
ret

LLVM IR (-O0):
define void @Mergesortd(i32 %0, i32 %1, double* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store i32* %3, i32** %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %4
br label %45
14: ; preds = %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %17, 2
store i32 %18, i32* %9
%19 = load i32, i32* %5
%20 = load i32, i32* %9
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %14
%23 = load i32, i32* %5
%24 = load i32, i32* %9
%25 = load double*, double** %7
%26 = load i32*, i32** %8
br label %27
27: ; preds = %22, %14
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
%35 = load i32, i32* %6
%36 = load double*, double** %7
%37 = load i32*, i32** %8
br label %38
38: ; preds = %32, %27
%39 = load i32, i32* %5
%40 = load i32, i32* %9
%41 = load i32, i32* %6
%42 = load double*, double** %7
%43 = load i32*, i32** %8
%44 = call i32 @Merge(i32 %39, i32 %40, i32 %41, double* %42, i32* %43)
br label %45
45: ; preds = %38, %13
ret void
}

LLVM IR (-O2):
define void @Mergesortd(i32 %0, i32 %1, double* %2, i32* %3) {
%5 = icmp slt i32 %0, %1
br i1 %5, label %6, label %17
6: ; preds = %4
%7 = add nsw i32 %1, %0
%8 = sdiv i32 %7, 2
%9 = icmp sgt i32 %8, %0
br i1 %9, label %10, label %11
10: ; preds = %6
tail call void @Mergesortd(i32 %0, i32 %8, double* %2, i32* %3)
br label %11
11: ; preds = %10, %6
%12 = add nsw i32 %8, 1
%13 = icmp slt i32 %12, %1
br i1 %13, label %14, label %15
14: ; preds = %11
tail call void @Mergesortd(i32 %12, i32 %1, double* %2, i32* %3)
br label %15
15: ; preds = %14, %11
%16 = tail call i32 @Merge(i32 %0, i32 %8, i32 %1, double* %2, i32* %3)
br label %17
17: ; preds = %4, %15
ret void
}