#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 *, char const *, double, double, double const,
                          double);
int /*<<< orphan*/ test_failure();
bool _expect_within(double expected, double actual, double threshold,
                    const char *message) {
  const double difference = fabs(expected - actual);
  if (difference <= threshold)
    return true;
  test_failure();
  printf(" \x1b[1;31mFAILED:\x1b[m %s\n  %.20g vs. %.20g\n"
         "  (difference %.20g > %.20g)\n",
         message, expected, actual, difference, threshold);
  return false;
}


x86 assembly (clang, -O0):
<_expect_within>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xeb4(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1175 <_expect_within+0x55>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <_expect_within+0x87>
mov    $0x0,%al
call   1040 <test_failure@plt>
mov    -0x28(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_expect_within>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movapd %xmm0,%xmm3
subsd  %xmm1,%xmm3
andpd  0xec9(%rip),%xmm3
mov    $0x1,%ebx
ucomisd %xmm3,%xmm2
jae    118d <_expect_within+0x6d>
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
movsd  %xmm1,0x10(%rsp)
movapd %xmm3,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm2,0x18(%rsp)
call   1040 <test_failure@plt>
lea    0xea3(%rip),%rdi
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [70 x i8] c" \1B[1;31mFAILED:\1B[m %s\0A %.20g vs. %.20g\0A (difference %.20g > %.20g)\0A\00"
define i32 @_expect_within(double %0, double %1, double %2, i8* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i8*
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store i8* %3, i8** %9
%11 = load double, double* %6
%12 = load double, double* %7
%13 = fsub double %11, %12
%14 = call double @llvm.fabs.f64(double %13)
store double %14, double* %10
%15 = load double, double* %10
%16 = load double, double* %8
%17 = fcmp ole double %15, %16
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 1, i32* %5
br label %27
19: ; preds = %4
%20 = call i32 (...) @test_failure()
%21 = load i8*, i8** %9
%22 = load double, double* %6
%23 = load double, double* %7
%24 = load double, double* %10
%25 = load double, double* %8
%26 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %21, double %22, double %23, double %24, double %25)
store i32 0, i32* %5
br label %27
27: ; preds = %19, %18
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@.str = [70 x i8] c" \1B[1;31mFAILED:\1B[m %s\0A %.20g vs. %.20g\0A (difference %.20g > %.20g)\0A\00"
define i32 @_expect_within(double %0, double %1, double %2, i8* %3) {
%5 = fsub double %0, %1
%6 = tail call double @llvm.fabs.f64(double %5)
%7 = fcmp ugt double %6, %2
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i32 (...) @test_failure()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i8* %3, double %0, double %1, double %6, double %2)
br label %11
11: ; preds = %4, %8
%12 = phi i32 [ 0, %8 ], [ 1, %4 ]
ret i32 %12
}