#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double);
double rsqrt(double);
double sqrt(double);
int /*<<< orphan*/ stderr;
double rsqrt_bias() {
  int i;
  union {
    int i;
    float f;
  } buf[2];
  double x0, x1, y0, y1;
  double weight;
  double err0, err1;
  double SumWeight, SumErr, SumSqrErr;
  double bias, mse;
  SumWeight = SumErr = SumSqrErr = 0.;
  for (i = 0; i < (1 << 23); i++) {
    buf[0].i = (127 << 23) + i;
    buf[1].i = (128 << 23) + i;
    x0 = (double)buf[0].f;
    x1 = (double)buf[1].f;
    y0 = rsqrt(x0);
    y1 = rsqrt(x1);
    err0 = y0 * y0 * x0 - 1.;
    err1 = y1 * y1 * x1 - 1.;
    weight = y0 * y0;
    SumWeight += weight;
    SumErr += weight * (err0 + err1);
    SumSqrErr += weight * (err0 * err0 + err1 * err1);
  }
  SumWeight *= 2.0;
  bias = 0.5 * SumErr / SumWeight;
  mse = 0.5 * sqrt(SumSqrErr / SumWeight);
  fprintf(stderr, "rsqrt: MSE = %e,  Bias = %e\n", mse, bias);
  return bias;
}


x86 assembly (clang, -O0):
<rsqrt_bias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x800000,-0x4(%rbp)
jge    127c <rsqrt_bias+0x14c>
mov    -0x4(%rbp),%eax
add    $0x3f800000,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40000000,%eax
mov    %eax,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <rsqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <rsqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe41(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe1d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
addsd  -0x48(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm3
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1157 <rsqrt_bias+0x27>
movsd  0xd84(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xd6a(%rip),%xmm0
mulsd  -0x58(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd41(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
lea    0xd36(%rip),%rsi
call   1040 <fprintf@plt>
movsd  -0x68(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsqrt_bias>:
push   %rbx
sub    $0x40,%rsp
xorpd  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
nop
movsd  %xmm2,0x18(%rsp)
movapd %xmm0,0x30(%rsp)
movd   %ebx,%xmm0
pshufd $0x50,%xmm0,%xmm0
paddd  0xea3(%rip),%xmm0
cvtps2pd %xmm0,%xmm0
movaps %xmm0,(%rsp)
call   1030 <rsqrt@plt>
movaps %xmm0,0x20(%rsp)
movapd (%rsp),%xmm0
unpckhpd %xmm0,%xmm0
call   1030 <rsqrt@plt>
movsd  0x18(%rsp),%xmm2
movapd 0x20(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
mulpd  %xmm1,%xmm1
movapd (%rsp),%xmm3
mulpd  %xmm1,%xmm3
addpd  0xe6f(%rip),%xmm3
addsd  %xmm1,%xmm2
movapd %xmm1,%xmm4
movapd %xmm3,%xmm0
unpckhpd %xmm3,%xmm0
movapd %xmm3,%xmm1
addsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm0
mulsd  %xmm3,%xmm3
addsd  %xmm0,%xmm3
unpcklpd %xmm1,%xmm3
movapd 0x30(%rsp),%xmm0
unpcklpd %xmm4,%xmm4
mulpd  %xmm3,%xmm4
addpd  %xmm4,%xmm0
add    $0x1,%ebx
cmp    $0x800000,%ebx
jne    1140 <rsqrt_bias+0x10>
addsd  %xmm2,%xmm2
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
mulsd  0xe22(%rip),%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,(%rsp)
divsd  %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     121b <rsqrt_bias+0xeb>
sqrtsd %xmm0,%xmm0
jmp    1220 <rsqrt_bias+0xf0>
call   1050 <sqrt@plt>
mulsd  0xdf8(%rip),%xmm0
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
movaps (%rsp),%xmm1
call   1040 <fprintf@plt>
movaps (%rsp),%xmm0
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"rsqrt: MSE = %e, Bias = %e\0A\00"
define double @rsqrt_bias() {
%1 = alloca i32
%2 = alloca [2 x %union.anon]
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %10
store i32 0, i32* %1
br label %15
15: ; preds = %70, %0
%16 = load i32, i32* %1
%17 = icmp slt i32 %16, 8388608
br i1 %17, label %18, label %73
18: ; preds = %15
%19 = load i32, i32* %1
%20 = add nsw i32 1065353216, %19
%21 = getelementptr inbounds [2 x %union.anon], [2 x %union.anon]* %2, i64 0, i64 0
%22 = bitcast %union.anon* %21 to i32*
store i32 %20, i32* %22
%23 = load i32, i32* %1
%24 = add nsw i32 1073741824, %23
%25 = getelementptr inbounds [2 x %union.anon], [2 x %union.anon]* %2, i64 0, i64 1
%26 = bitcast %union.anon* %25 to i32*
store i32 %24, i32* %26
%27 = getelementptr inbounds [2 x %union.anon], [2 x %union.anon]* %2, i64 0, i64 0
%28 = bitcast %union.anon* %27 to float*
%29 = load float, float* %28
%30 = fpext float %29 to double
store double %30, double* %3
%31 = getelementptr inbounds [2 x %union.anon], [2 x %union.anon]* %2, i64 0, i64 1
%32 = bitcast %union.anon* %31 to float*
%33 = load float, float* %32
%34 = fpext float %33 to double
store double %34, double* %4
%35 = load double, double* %3
%36 = call double @rsqrt(double %35)
store double %36, double* %5
%37 = load double, double* %4
%38 = call double @rsqrt(double %37)
store double %38, double* %6
%39 = load double, double* %5
%40 = load double, double* %5
%41 = fmul double %39, %40
%42 = load double, double* %3
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double -1.000000e+00)
store double %43, double* %8
%44 = load double, double* %6
%45 = load double, double* %6
%46 = fmul double %44, %45
%47 = load double, double* %4
%48 = call double @llvm.fmuladd.f64(double %46, double %47, double -1.000000e+00)
store double %48, double* %9
%49 = load double, double* %5
%50 = load double, double* %5
%51 = fmul double %49, %50
store double %51, double* %7
%52 = load double, double* %7
%53 = load double, double* %10
%54 = fadd double %53, %52
store double %54, double* %10
%55 = load double, double* %7
%56 = load double, double* %8
%57 = load double, double* %9
%58 = fadd double %56, %57
%59 = load double, double* %11
%60 = call double @llvm.fmuladd.f64(double %55, double %58, double %59)
store double %60, double* %11
%61 = load double, double* %7
%62 = load double, double* %8
%63 = load double, double* %8
%64 = load double, double* %9
%65 = load double, double* %9
%66 = fmul double %64, %65
%67 = call double @llvm.fmuladd.f64(double %62, double %63, double %66)
%68 = load double, double* %12
%69 = call double @llvm.fmuladd.f64(double %61, double %67, double %68)
store double %69, double* %12
br label %70
70: ; preds = %18
%71 = load i32, i32* %1
%72 = add nsw i32 %71, 1
store i32 %72, i32* %1
br label %15
73: ; preds = %15
%74 = load double, double* %10
%75 = fmul double %74, 2.000000e+00
store double %75, double* %10
%76 = load double, double* %11
%77 = fmul double 5.000000e-01, %76
%78 = load double, double* %10
%79 = fdiv double %77, %78
store double %79, double* %13
%80 = load double, double* %12
%81 = load double, double* %10
%82 = fdiv double %80, %81
%83 = call double @sqrt(double %82)
%84 = fmul double 5.000000e-01, %83
store double %84, double* %14
%85 = load i32, i32* @stderr
%86 = load double, double* %14
%87 = load double, double* %13
%88 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %86, double %87)
%89 = load double, double* %13
ret double %89
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"rsqrt: MSE = %e, Bias = %e\0A\00"
define double @rsqrt_bias() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %29, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %19, %1 ]
%4 = phi <2 x double> [ zeroinitializer, %0 ], [ %28, %1 ]
%5 = insertelement <2 x i32> poison, i32 %2, i64 0
%6 = shufflevector <2 x i32> %5, <2 x i32> poison, <2 x i32> zeroinitializer
%7 = add nuw nsw <2 x i32> %6, <i32 1065353216, i32 1073741824>
%8 = bitcast <2 x i32> %7 to <2 x float>
%9 = fpext <2 x float> %8 to <2 x double>
%10 = extractelement <2 x double> %9, i64 0
%11 = tail call double @rsqrt(double %10)
%12 = extractelement <2 x double> %9, i64 1
%13 = tail call double @rsqrt(double %12)
%14 = insertelement <2 x double> poison, double %11, i64 0
%15 = insertelement <2 x double> %14, double %13, i64 1
%16 = fmul <2 x double> %15, %15
%17 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %16, <2 x double> %9, <2 x double> <double -1.000000e+00, double -1.000000e+00>)
%18 = extractelement <2 x double> %16, i64 0
%19 = fadd double %3, %18
%20 = extractelement <2 x double> %17, i64 0
%21 = extractelement <2 x double> %17, i64 1
%22 = fadd double %20, %21
%23 = fmul double %21, %21
%24 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %23)
%25 = shufflevector <2 x double> %16, <2 x double> undef, <2 x i32> zeroinitializer
%26 = insertelement <2 x double> poison, double %24, i64 0
%27 = insertelement <2 x double> %26, double %22, i64 1
%28 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %27, <2 x double> %4)
%29 = add nuw nsw i32 %2, 1
%30 = icmp eq i32 %29, 8388608
br i1 %30, label %31, label %1
31: ; preds = %1
%32 = fmul double %19, 2.000000e+00
%33 = extractelement <2 x double> %28, i64 1
%34 = fmul double %33, 5.000000e-01
%35 = fdiv double %34, %32
%36 = extractelement <2 x double> %28, i64 0
%37 = fdiv double %36, %32
%38 = tail call double @sqrt(double %37)
%39 = fmul double %38, 5.000000e-01
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %39, double %35)
ret double %35
}