#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(double *, int *, int, int, int *);
void recursesort(double *vals, int nvals, int *indices, int *space) {
  int length1, length2;
  int i;
  if (nvals <= 1)
    return;
  else if (nvals == 2) {
    if (vals[indices[0]] <= vals[indices[1]])
      return;
    else {
      i = indices[0];
      indices[0] = indices[1];
      indices[1] = i;
      return;
    }
  } else {
    length1 = nvals / 2;
    length2 = nvals - length1;
    recursesort(vals, length1, indices, space);
    recursesort(vals, length2, indices + length1, space);
    merge(vals, indices, length1, length2, space);
  }
}


x86 assembly (clang, -O0):
<recursesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     1146 <recursesort+0x26>
jmp    120b <recursesort+0xeb>
cmpl   $0x2,-0xc(%rbp)
jne    11a5 <recursesort+0x85>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq 0x4(%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1180 <recursesort+0x60>
jmp    120b <recursesort+0xeb>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    120b <recursesort+0xeb>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <recursesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x18(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rcx
call   1030 <recursesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1040 <merge@plt>
jmp    120b <recursesort+0xeb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursesort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%esi
jl     114f <recursesort+0x2f>
mov    %rdx,%r15
mov    %rdi,%rbx
jne    1158 <recursesort+0x38>
movslq (%r15),%rax
movslq 0x4(%r15),%rcx
movsd  (%rbx,%rcx,8),%xmm0
ucomisd (%rbx,%rax,8),%xmm0
jae    114f <recursesort+0x2f>
mov    %ecx,(%r15)
mov    %eax,0x4(%r15)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rcx,%r14
mov    %esi,%ebp
mov    %esi,%r12d
shr    %r12d
sub    %r12d,%ebp
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1030 <recursesort@plt>
lea    (%r15,%r12,4),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
call   1030 <recursesort@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
mov    %r14,%r8
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge@plt>

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

LLVM IR (-O2):
define void @recursesort(double* %0, i32 %1, i32* %2, i32* %3) {
%5 = icmp slt i32 %1, 2
br i1 %5, label %20, label %6
6: ; preds = %4
%7 = icmp eq i32 %1, 2
br i1 %7, label %8, label %21
8: ; preds = %6
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds double, double* %0, i64 %10
%12 = load double, double* %11
%13 = getelementptr inbounds i32, i32* %2, i64 1
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
%18 = fcmp ugt double %12, %17
br i1 %18, label %19, label %20
19: ; preds = %8
store i32 %14, i32* %2
store i32 %9, i32* %13
br label %20
20: ; preds = %19, %4, %8, %21
ret void
21: ; preds = %6
%22 = lshr i32 %1, 1
%23 = sub nsw i32 %1, %22
tail call void @recursesort(double* %0, i32 %22, i32* %2, i32* %3)
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds i32, i32* %2, i64 %24
tail call void @recursesort(double* %0, i32 %23, i32* %25, i32* %3)
%26 = tail call i32 @merge(double* %0, i32* %2, i32 %22, i32 %23, i32* %3)
br label %20
}