#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 */
int fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, double, double);
int pow(double, int);
int /*<<< orphan*/ stderr;
int assert_almost_equal(double value, double target, int ndecimal,
                        char *cname) {
  if (fabs(value - target) / fabs((value + target) / 2.0) >
      pow(10.0, -ndecimal)) {
    fprintf(stderr, "Failed: %s: %f != %f\n", cname, value, target);
    return (-1);
  }
  return (1);
}


x86 assembly (clang, -O0):
<assert_almost_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
mov    %rsi,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %eax,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
sub    -0x1c(%rbp),%edi
movsd  0xe72(%rip),%xmm0
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jle    11cf <assert_almost_equal+0x9f>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe52(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <assert_almost_equal+0xa6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assert_almost_equal>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%ebx
movsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
mulsd  0xe9a(%rip),%xmm0
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
neg    %ebp
movsd  0xe8a(%rip),%xmm0
mov    %ebp,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%ebx
jle    11b8 <assert_almost_equal+0x88>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    %r14,%rdx
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Failed: %s: %f != %f\0A\00"
define i32 @assert_almost_equal(double %0, double %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i8*
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%10 = load double, double* %6
%11 = load double, double* %7
%12 = fsub double %10, %11
%13 = call i32 @fabs(double %12)
%14 = load double, double* %6
%15 = load double, double* %7
%16 = fadd double %14, %15
%17 = fdiv double %16, 2.000000e+00
%18 = call i32 @fabs(double %17)
%19 = sdiv i32 %13, %18
%20 = load i32, i32* %8
%21 = sub nsw i32 0, %20
%22 = call i32 @pow(double 1.000000e+01, i32 %21)
%23 = icmp sgt i32 %19, %22
br i1 %23, label %24, label %30
24: ; preds = %4
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %9
%27 = load double, double* %6
%28 = load double, double* %7
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %26, double %27, double %28)
store i32 -1, i32* %5
br label %31
30: ; preds = %4
store i32 1, i32* %5
br label %31
31: ; preds = %30, %24
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Failed: %s: %f != %f\0A\00"
define i32 @assert_almost_equal(double %0, double %1, i32 %2, i8* %3) {
%5 = fsub double %0, %1
%6 = tail call i32 @fabs(double %5)
%7 = fadd double %0, %1
%8 = fmul double %7, 5.000000e-01
%9 = tail call i32 @fabs(double %8)
%10 = sdiv i32 %6, %9
%11 = sub nsw i32 0, %2
%12 = tail call i32 @pow(double 1.000000e+01, i32 %11)
%13 = icmp sgt i32 %10, %12
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %3, double %0, double %1)
br label %17
17: ; preds = %4, %14
%18 = phi i32 [ -1, %14 ], [ 1, %4 ]
ret i32 %18
}