#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 fabs(double);
int /*<<< orphan*/ printf(char *, ...);
void test_double(double expected, double actual, double tolerance,
                 const char *testname) {
  if (fabs(actual - expected) > tolerance) {
    printf("Test %s FAILED:\n", testname);
    printf("Expected result %g with tolerance %g, but got %g instead\n",
           expected, tolerance, actual);
  } else {
    printf("Test %s SUCCEEDED\n", testname);
  }
}


x86 assembly (clang, -O0):
<test_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movaps 0xec4(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    117f <test_double+0x6f>
mov    -0x20(%rbp),%rsi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
lea    0xeae(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    1191 <test_double+0x81>
mov    -0x20(%rbp),%rsi
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_double>:
sub    $0x18,%rsp
mov    %rdi,%rsi
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
andpd  0xed9(%rip),%xmm3
ucomisd %xmm2,%xmm3
jbe    116f <test_double+0x5f>
lea    0xedc(%rip),%rdi
xor    %eax,%eax
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,(%rsp)
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mov    $0x3,%al
add    $0x18,%rsp
jmp    1030 <printf@plt>
lea    0xee5(%rip),%rdi
xor    %eax,%eax
add    $0x18,%rsp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Test %s FAILED:\0A\00"
@.str.1 = [58 x i8] c"Expected result %g with tolerance %g, but got %g instead\0A\00"
@.str.2 = [19 x i8] c"Test %s SUCCEEDED\0A\00"
define void @test_double(double %0, double %1, double %2, i8* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i8*
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i8* %3, i8** %8
%9 = load double, double* %6
%10 = load double, double* %5
%11 = fsub double %9, %10
%12 = call double @llvm.fabs.f64(double %11)
%13 = load double, double* %7
%14 = fcmp ogt double %12, %13
br i1 %14, label %15, label %22
15: ; preds = %4
%16 = load i8*, i8** %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load double, double* %5
%19 = load double, double* %7
%20 = load double, double* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), double %18, double %19, double %20)
br label %25
22: ; preds = %4
%23 = load i8*, i8** %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %15
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Test %s FAILED:\0A\00"
@.str.1 = [58 x i8] c"Expected result %g with tolerance %g, but got %g instead\0A\00"
@.str.2 = [19 x i8] c"Test %s SUCCEEDED\0A\00"
define void @test_double(double %0, double %1, double %2, i8* %3) {
%5 = fsub double %1, %0
%6 = tail call double @llvm.fabs.f64(double %5)
%7 = fcmp ogt double %6, %2
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), double %0, double %2, double %1)
br label %13
11: ; preds = %4
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %13
13: ; preds = %11, %8
ret void
}