#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 *);
int CmpFloats(double a, double b) {
  double diff = fabs(a) - fabs(b);
  double absDiff = fabs(diff);
  double min, max;
  if (a > b)
    max = a, min = b;
  else
    max = b, min = a;
  double precision = 1e-12;
  double scaledPrecision = fabs((min + max) * precision);
  if (absDiff <= scaledPrecision)
    return 0;
  if (diff < scaledPrecision)
    return -1;
  if (diff > scaledPrecision)
    return 1;
  printf("suspicious behavior\n");
  return 0;
}


x86 assembly (clang, -O0):
<CmpFloats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xed2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movaps 0xec2(%rip),%xmm2
pand   %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movaps 0xea9(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1189 <CmpFloats+0x79>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    119d <CmpFloats+0x8d>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe6b(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movaps 0xe40(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11e9 <CmpFloats+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    1238 <CmpFloats+0x128>
movsd  -0x20(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1209 <CmpFloats+0xf9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <CmpFloats+0x128>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1225 <CmpFloats+0x115>
movl   $0x1,-0x4(%rbp)
jmp    1238 <CmpFloats+0x128>
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CmpFloats>:
push   %rax
movapd 0xee7(%rip),%xmm2
movapd %xmm1,%xmm3
movapd %xmm0,%xmm4
maxsd  %xmm1,%xmm4
minsd  %xmm0,%xmm1
andpd  %xmm2,%xmm0
andpd  %xmm2,%xmm3
subsd  %xmm3,%xmm0
movapd %xmm0,%xmm3
andpd  %xmm2,%xmm3
addsd  %xmm4,%xmm1
mulsd  0xec7(%rip),%xmm1
andpd  %xmm2,%xmm1
xor    %eax,%eax
ucomisd %xmm3,%xmm1
jae    1179 <CmpFloats+0x69>
mov    $0xffffffff,%eax
ucomisd %xmm0,%xmm1
ja     1179 <CmpFloats+0x69>
mov    $0x1,%eax
ucomisd %xmm1,%xmm0
ja     1179 <CmpFloats+0x69>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"suspicious behavior\0A\00"
define i32 @CmpFloats(double %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store double %1, double* %5
%12 = load double, double* %4
%13 = call double @llvm.fabs.f64(double %12)
%14 = load double, double* %5
%15 = call double @llvm.fabs.f64(double %14)
%16 = fsub double %13, %15
store double %16, double* %6
%17 = load double, double* %6
%18 = call double @llvm.fabs.f64(double %17)
store double %18, double* %7
%19 = load double, double* %4
%20 = load double, double* %5
%21 = fcmp ogt double %19, %20
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load double, double* %4
store double %23, double* %9
%24 = load double, double* %5
store double %24, double* %8
br label %28
25: ; preds = %2
%26 = load double, double* %5
store double %26, double* %9
%27 = load double, double* %4
store double %27, double* %8
br label %28
28: ; preds = %25, %22
store double 0x3D719799812DEA11, double* %10
%29 = load double, double* %8
%30 = load double, double* %9
%31 = fadd double %29, %30
%32 = load double, double* %10
%33 = fmul double %31, %32
%34 = call double @llvm.fabs.f64(double %33)
store double %34, double* %11
%35 = load double, double* %7
%36 = load double, double* %11
%37 = fcmp ole double %35, %36
br i1 %37, label %38, label %39
38: ; preds = %28
store i32 0, i32* %3
br label %51
39: ; preds = %28
%40 = load double, double* %6
%41 = load double, double* %11
%42 = fcmp olt double %40, %41
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 -1, i32* %3
br label %51
44: ; preds = %39
%45 = load double, double* %6
%46 = load double, double* %11
%47 = fcmp ogt double %45, %46
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 1, i32* %3
br label %51
49: ; preds = %44
%50 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %51
51: ; preds = %49, %48, %43, %38
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@str = [20 x i8] c"suspicious behavior\00"
define i32 @CmpFloats(double %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = tail call double @llvm.fabs.f64(double %1)
%5 = fsub double %3, %4
%6 = tail call double @llvm.fabs.f64(double %5)
%7 = fcmp ogt double %0, %1
%8 = select i1 %7, double %0, double %1
%9 = select i1 %7, double %1, double %0
%10 = fadd double %9, %8
%11 = fmul double %10, 0x3D719799812DEA11
%12 = tail call double @llvm.fabs.f64(double %11)
%13 = fcmp ugt double %6, %12
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = fcmp olt double %5, %12
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = fcmp ogt double %5, %12
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %16, %14, %2, %18
%21 = phi i32 [ 0, %18 ], [ 0, %2 ], [ -1, %14 ], [ 1, %16 ]
ret i32 %21
}