#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sortd1(double *, int);
int /*<<< orphan*/ stderr;
void sortd2(double a[], int n) {
  double *p, *q, w;
  if (n <= 1) {
    fprintf(stderr, "Error : n <= 1  in sortd2()\n");
    return;
  }
  sortd1(a, n);
  p = a;
  q = a + n - 1;
  while (p < q) {
    w = *p;
    *p++ = *q;
    *q-- = w;
  }
  return;
}


x86 assembly (clang, -O0):
<sortd2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     1153 <sortd2+0x33>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11d6 <sortd2+0xb6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <sortd1@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11d1 <sortd2+0xb1>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffff8,%rcx
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,(%rax)
jmp    117e <sortd2+0x5e>
jmp    11d6 <sortd2+0xb6>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortd2>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%esi
jg     1143 <sortd2+0x23>
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    0xec8(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <sortd1@plt>
mov    %ebp,%eax
lea    (%rbx,%rax,8),%rax
add    $0xfffffffffffffff8,%rax
cmp    %rbx,%rax
jbe    1182 <sortd2+0x62>
add    $0x8,%rbx
movsd  -0x8(%rbx),%xmm0
movsd  (%rax),%xmm1
movsd  %xmm1,-0x8(%rbx)
movsd  %xmm0,(%rax)
add    $0xfffffffffffffff8,%rax
lea    0x8(%rbx),%rcx
cmp    %rax,%rbx
mov    %rcx,%rbx
jb     1160 <sortd2+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Error : n <= 1 in sortd2()\0A\00"
define void @sortd2(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %38
13: ; preds = %2
%14 = load double*, double** %3
%15 = load i32, i32* %4
%16 = call i32 @sortd1(double* %14, i32 %15)
%17 = load double*, double** %3
store double* %17, double** %5
%18 = load double*, double** %3
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = getelementptr inbounds double, double* %21, i64 -1
store double* %22, double** %6
br label %23
23: ; preds = %27, %13
%24 = load double*, double** %5
%25 = load double*, double** %6
%26 = icmp ult double* %24, %25
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load double*, double** %5
%29 = load double, double* %28
store double %29, double* %7
%30 = load double*, double** %6
%31 = load double, double* %30
%32 = load double*, double** %5
%33 = getelementptr inbounds double, double* %32, i32 1
store double* %33, double** %5
store double %31, double* %32
%34 = load double, double* %7
%35 = load double*, double** %6
%36 = getelementptr inbounds double, double* %35, i32 -1
store double* %36, double** %6
store double %34, double* %35
br label %23
37: ; preds = %23
br label %38
38: ; preds = %37, %10
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Error : n <= 1 in sortd2()\0A\00"
define void @sortd2(double* %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %21
7: ; preds = %2
%8 = tail call i32 @sortd1(double* %0, i32 %1)
%9 = zext i32 %1 to i64
%10 = getelementptr inbounds double, double* %0, i64 %9
%11 = getelementptr inbounds double, double* %10, i64 -1
%12 = icmp ugt double* %11, %0
br i1 %12, label %13, label %21
13: ; preds = %7, %13
%14 = phi double* [ %19, %13 ], [ %11, %7 ]
%15 = phi double* [ %18, %13 ], [ %0, %7 ]
%16 = load double, double* %15
%17 = load double, double* %14
%18 = getelementptr inbounds double, double* %15, i64 1
store double %17, double* %15
store double %16, double* %14
%19 = getelementptr inbounds double, double* %14, i64 -1
%20 = icmp ult double* %18, %19
br i1 %20, label %13, label %21
21: ; preds = %13, %7, %4
ret void
}