#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*/ memcpy(void *, void const *, int);
int /*<<< orphan*/ qsort(double *, int, int,
                         int (*)(void const *, void const *));
double median_(double *arr, int lindex, int rindex) {
  double arr2[5];
  int compd(const void *a, const void *b);
  memcpy((void *)arr2, (const void *)((double *)arr + lindex),
         (rindex - lindex + 1) * sizeof(double));
  qsort(arr2, rindex - lindex + 1, sizeof(double), compd);
  return arr2[2];
}


x86 assembly (clang, -O0):
<median_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
add    $0x1,%esi
mov    $0x8,%edx
mov    0x2e6c(%rip),%rcx
call   1030 <qsort@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<median_>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movslq %esi,%rax
lea    (%rdi,%rax,8),%rsi
sub    %eax,%edx
lea    0x1(%rdx),%ebx
lea    0x8(,%rdx,8),%edx
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <memcpy@plt>
mov    0x2e94(%rip),%rcx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x8,%edx
call   1030 <qsort@plt>
movsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @median_(double* %0, i32 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x double]
store double* %0, double** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 0
%9 = bitcast double* %8 to i8*
%10 = load double*, double** %4
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %10, i64 %12
%14 = bitcast double* %13 to i8*
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = sub nsw i32 %15, %16
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call i32 @memcpy(i8* %9, i8* %14, i32 %21)
%23 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 0
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = sub nsw i32 %24, %25
%27 = add nsw i32 %26, 1
%28 = call i32 @qsort(double* %23, i32 %27, i32 8, i32 (i8*, i8*)* @compd)
%29 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 2
%30 = load double, double* %29
ret double %30
}

LLVM IR (-O2):
define double @median_(double* %0, i32 %1, i32 %2) {
%4 = alloca [5 x double]
%5 = bitcast [5 x double]* %4 to i8*
%6 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 0
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds double, double* %0, i64 %7
%9 = bitcast double* %8 to i8*
%10 = sub nsw i32 %2, %1
%11 = add nsw i32 %10, 1
%12 = shl i32 %11, 3
%13 = call i32 @memcpy(i8* %5, i8* %9, i32 %12)
%14 = call i32 @qsort(double* %6, i32 %11, i32 8, i32 (i8*, i8*)* @compd)
%15 = getelementptr inbounds [5 x double], [5 x double]* %4, i64 0, i64 2
%16 = load double, double* %15
ret double %16
}