#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 median(double *, int);
int /*<<< orphan*/ printf(char *, ...);
void test_median(double input[], int count, double expected) {
  double actual = median(input, count);
  printf("Testing median:\n");
  printf("Expecting %f and got %f.", expected, actual);
  if (expected == actual) {
    printf("\n* Pass *\n");
  } else {
    printf("\n* Fail *\n");
  }
}


x86 assembly (clang, -O0):
<test_median>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <median@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xead(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1194 <test_median+0x74>
jp     1194 <test_median+0x74>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a2 <test_median+0x82>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_median>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
call   1030 <median@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xecd(%rip),%rdi
call   1040 <puts@plt>
lea    0xea8(%rip),%rdi
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
lea    0xeab(%rip),%rax
lea    0xeae(%rip),%rdi
cmovne %rax,%rdi
cmovp  %rax,%rdi
add    $0x18,%rsp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Testing median:\0A\00"
@.str.1 = [25 x i8] c"Expecting %f and got %f.\00"
@.str.2 = [11 x i8] c"\0A* Pass *\0A\00"
@.str.3 = [11 x i8] c"\0A* Fail *\0A\00"
define void @test_median(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%8 = load double*, double** %4
%9 = load i32, i32* %5
%10 = call double @median(double* %8, i32 %9)
store double %10, double* %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%12 = load double, double* %6
%13 = load double, double* %7
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %12, double %13)
%15 = load double, double* %6
%16 = load double, double* %7
%17 = fcmp oeq double %15, %16
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
ret void
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"Expecting %f and got %f.\00"
@str = [16 x i8] c"Testing median:\00"
@str.4 = [10 x i8] c"\0A* Fail *\00"
@str.5 = [10 x i8] c"\0A* Pass *\00"
define void @test_median(double* %0, i32 %1, double %2) {
%4 = tail call double @median(double* %0, i32 %1)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %2, double %4)
%7 = fcmp oeq double %4, %2
%8 = select i1 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0)
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
ret void
}