#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);
scalar_t__ isinf(double);
scalar_t__ isnan(double);
double pow(int, int);
int approxf(double actual, double expected, int bits) {
  if (isinf(actual) || isinf(expected) || isnan(actual) || isnan(expected)) {
    return 0;
  }
  if (expected == 0.0) {
    return fabs(actual) < (1 / pow(2, bits));
  }
  double epsilon = fabs(expected / pow(2, bits));
  return fabs(actual - expected) <= epsilon;
}


x86 assembly (clang, -O0):
<approxf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
jne    1195 <approxf+0x65>
movsd  -0x18(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
jne    1195 <approxf+0x65>
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
jne    1195 <approxf+0x65>
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     11a1 <approxf+0x71>
movl   $0x0,-0x4(%rbp)
jmp    125f <approxf+0x12f>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1203 <approxf+0xd3>
jp     1203 <approxf+0xd3>
movsd  -0x10(%rbp),%xmm0
movaps 0xe3b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  0xe25(%rip),%xmm0
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    125f <approxf+0x12f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movaps 0xdd3(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xdb9(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<approxf>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movapd %xmm1,0x10(%rsp)
movapd %xmm0,(%rsp)
call   1050 <isinf@plt>
test   %rax,%rax
jne    117b <approxf+0x4b>
movapd 0x10(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
jne    117b <approxf+0x4b>
movapd (%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
jne    117b <approxf+0x4b>
movapd 0x10(%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     1186 <approxf+0x56>
xor    %eax,%eax
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbx
ret
xorpd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    11cc <approxf+0x9c>
jp     11cc <approxf+0x9c>
movapd (%rsp),%xmm0
andpd  0xe5b(%rip),%xmm0
movapd %xmm0,(%rsp)
mov    $0x2,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
movsd  0xe52(%rip),%xmm1
divsd  %xmm0,%xmm1
ucomisd (%rsp),%xmm1
seta   %al
jmp    117d <approxf+0x4d>
mov    $0x2,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
movapd (%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm0,%xmm2
movapd 0xe0d(%rip),%xmm0
andpd  %xmm0,%xmm2
andpd  %xmm0,%xmm1
ucomisd %xmm1,%xmm2
setae  %al
jmp    117d <approxf+0x4d>

LLVM IR (-O0):
define i32 @approxf(double %0, double %1, i32 %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
%9 = load double, double* %5
%10 = call i64 @isinf(double %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %3
%13 = load double, double* %6
%14 = call i64 @isinf(double %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %12
%17 = load double, double* %5
%18 = call i64 @isnan(double %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load double, double* %6
%22 = call i64 @isnan(double %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20, %16, %12, %3
store i32 0, i32* %4
br label %49
25: ; preds = %20
%26 = load double, double* %6
%27 = fcmp oeq double %26, 0.000000e+00
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load double, double* %5
%30 = call double @llvm.fabs.f64(double %29)
%31 = load i32, i32* %7
%32 = call double @pow(i32 2, i32 %31)
%33 = fdiv double 1.000000e+00, %32
%34 = fcmp olt double %30, %33
%35 = zext i1 %34 to i32
store i32 %35, i32* %4
br label %49
36: ; preds = %25
%37 = load double, double* %6
%38 = load i32, i32* %7
%39 = call double @pow(i32 2, i32 %38)
%40 = fdiv double %37, %39
%41 = call double @llvm.fabs.f64(double %40)
store double %41, double* %8
%42 = load double, double* %5
%43 = load double, double* %6
%44 = fsub double %42, %43
%45 = call double @llvm.fabs.f64(double %44)
%46 = load double, double* %8
%47 = fcmp ole double %45, %46
%48 = zext i1 %47 to i32
store i32 %48, i32* %4
br label %49
49: ; preds = %36, %28, %24
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
define i32 @approxf(double %0, double %1, i32 %2) {
%4 = tail call i64 @isinf(double %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %29
6: ; preds = %3
%7 = tail call i64 @isinf(double %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %6
%10 = tail call i64 @isnan(double %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = tail call i64 @isnan(double %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = fcmp oeq double %1, 0.000000e+00
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = tail call double @llvm.fabs.f64(double %0)
%19 = tail call double @pow(i32 2, i32 %2)
%20 = fdiv double 1.000000e+00, %19
%21 = fcmp olt double %18, %20
br label %29
22: ; preds = %15
%23 = tail call double @pow(i32 2, i32 %2)
%24 = fdiv double %1, %23
%25 = tail call double @llvm.fabs.f64(double %24)
%26 = fsub double %0, %1
%27 = tail call double @llvm.fabs.f64(double %26)
%28 = fcmp ole double %27, %25
br label %29
29: ; preds = %3, %6, %9, %12, %22, %17
%30 = phi i1 [ %21, %17 ], [ %28, %22 ], [ false, %12 ], [ false, %9 ], [ false, %6 ], [ false, %3 ]
%31 = zext i1 %30 to i32
ret i32 %31
}