#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double, double, double, double);
int /*<<< orphan*/ stdout;
int float_eq(double a, double b, double tolerance) {
  if (fabs(a - b) < tolerance)
    return 1;
  printf("floats not equal: a = %f, b = %f, diff = %f, tolerance = %f\n", a, b,
         fabs(a - b), tolerance);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<float_eq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xeb8(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1167 <float_eq+0x47>
movl   $0x1,-0x4(%rbp)
jmp    11ac <float_eq+0x8c>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movaps 0xe7e(%rip),%xmm3
pand   %xmm3,%xmm2
movsd  -0x20(%rbp),%xmm3
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_eq>:
push   %rax
movapd %xmm0,%xmm3
subsd  %xmm1,%xmm3
andpd  0xecf(%rip),%xmm3
mov    $0x1,%eax
ucomisd %xmm3,%xmm2
ja     1164 <float_eq+0x44>
movapd %xmm2,%xmm4
lea    0xec9(%rip),%rdi
movapd %xmm3,%xmm2
movapd %xmm4,%xmm3
call   1030 <printf@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [61 x i8] c"floats not equal: a = %f, b = %f, diff = %f, tolerance = %f\0A\00"
@stdout = global i32 0
define i32 @float_eq(double %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%8 = load double, double* %5
%9 = load double, double* %6
%10 = fsub double %8, %9
%11 = call double @llvm.fabs.f64(double %10)
%12 = load double, double* %7
%13 = fcmp olt double %11, %12
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 1, i32* %4
br label %26
15: ; preds = %3
%16 = load double, double* %5
%17 = load double, double* %6
%18 = load double, double* %5
%19 = load double, double* %6
%20 = fsub double %18, %19
%21 = call double @llvm.fabs.f64(double %20)
%22 = load double, double* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), double %16, double %17, double %21, double %22)
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
store i32 0, i32* %4
br label %26
26: ; preds = %15, %14
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [61 x i8] c"floats not equal: a = %f, b = %f, diff = %f, tolerance = %f\0A\00"
@stdout = global i32 0
define i32 @float_eq(double %0, double %1, double %2) {
%4 = fsub double %0, %1
%5 = tail call double @llvm.fabs.f64(double %4)
%6 = fcmp olt double %5, %2
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), double %0, double %1, double %5, double %2)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
br label %11
11: ; preds = %3, %7
%12 = phi i32 [ 0, %7 ], [ 1, %3 ]
ret i32 %12
}