#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 *am_malloc_realnums(int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ sort_realnums(double *, int, double *);
double doubles_median(double *farr, int size) {
  double *f2 = am_malloc_realnums(size);
  int med_index = size / 2;
  double result;
  sort_realnums(farr, size, f2);
  if ((size % 2) == 0)
    result = f2[med_index];
  else
    result = (f2[med_index] + f2[med_index + 1]) / 2.0;
  free(f2);
  return (result);
}


x86 assembly (clang, -O0):
<doubles_median>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <am_malloc_realnums@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <sort_realnums@plt>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1194 <doubles_median+0x64>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11c4 <doubles_median+0x94>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  0xe45(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_median>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
call   1050 <am_malloc_realnums@plt>
mov    %rax,%r15
mov    %ebx,%ebp
shr    $0x1f,%ebp
add    %ebx,%ebp
sar    %ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1040 <sort_realnums@plt>
movslq %ebp,%rax
movsd  (%r15,%rax,8),%xmm0
test   $0x1,%bl
je     1179 <doubles_median+0x49>
addsd  0x8(%r15,%rax,8),%xmm0
mulsd  0xe87(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @doubles_median(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = call double* @am_malloc_realnums(i32 %8)
store double* %9, double** %5
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 2
store i32 %11, i32* %6
%12 = load double*, double** %3
%13 = load i32, i32* %4
%14 = load double*, double** %5
%15 = call i32 @sort_realnums(double* %12, i32 %13, double* %14)
%16 = load i32, i32* %4
%17 = srem i32 %16, 2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load double*, double** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
store double %24, double* %7
br label %39
25: ; preds = %2
%26 = load double*, double** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %5
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %31, i64 %34
%36 = load double, double* %35
%37 = fadd double %30, %36
%38 = fdiv double %37, 2.000000e+00
store double %38, double* %7
br label %39
39: ; preds = %25, %19
%40 = load double*, double** %5
%41 = call i32 @free(double* %40)
%42 = load double, double* %7
ret double %42
}

LLVM IR (-O2):
define double @doubles_median(double* %0, i32 %1) {
%3 = tail call double* @am_malloc_realnums(i32 %1)
%4 = sdiv i32 %1, 2
%5 = tail call i32 @sort_realnums(double* %0, i32 %1, double* %3)
%6 = and i32 %1, 1
%7 = icmp eq i32 %6, 0
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds double, double* %3, i64 %8
%10 = load double, double* %9
br i1 %7, label %18, label %11
11: ; preds = %2
%12 = add nsw i32 %4, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %3, i64 %13
%15 = load double, double* %14
%16 = fadd double %10, %15
%17 = fmul double %16, 5.000000e-01
br label %18
18: ; preds = %2, %11
%19 = phi double [ %17, %11 ], [ %10, %2 ]
%20 = tail call i32 @free(double* %3)
ret double %19
}