#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*/ exit(int);
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
double chebyshev_error_Rsqrt(int n, const double *y, const double *z,
                             void (*atimes)(int, const double *, double *,
                                            void *),
                             void *user_data) {
  double *x = (double *)malloc(sizeof(double) * n);
  if (x == NULL) {
    fprintf(stderr, "chebyshev_error_Rsqrt"
                    " : malloc error for "
                    "x"
                    "\n");
    exit(1);
  };
  atimes(n, y, x, user_data);
  int k;
  double yy = 0.0;
  double zz = 0.0;
  for (k = 0; k < n; k++) {
    yy += y[k] * x[k];
    zz += z[k] * z[k];
  }
  free(x);
  if (yy <= 0.0) {
    fprintf(stderr, "negative norm! %e\n", yy);
    exit(1);
  }
  return (fabs(yy - zz) / yy);
}


x86 assembly (clang, -O0):
<chebyshev_error_Rsqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119a <chebyshev_error_Rsqrt+0x5a>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   *%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1238 <chebyshev_error_Rsqrt+0xf8>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c6 <chebyshev_error_Rsqrt+0x86>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     1275 <chebyshev_error_Rsqrt+0x135>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
movsd  -0x40(%rbp),%xmm0
lea    0xdd8(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movaps 0xd7a(%rip),%xmm1
pand   %xmm1,%xmm0
divsd  -0x40(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_error_Rsqrt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbp
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%r12d
lea    0x0(,%r12,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1266 <chebyshev_error_Rsqrt+0x126>
mov    %rax,%rbx
mov    %r12d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbp,%rcx
call   *%r13
test   %r12d,%r12d
jle    1287 <chebyshev_error_Rsqrt+0x147>
mov    %r12d,%eax
cmp    $0x1,%r12d
jne    119f <chebyshev_error_Rsqrt+0x5f>
xorpd  %xmm3,%xmm3
xor    %ecx,%ecx
jmp    11fa <chebyshev_error_Rsqrt+0xba>
mov    %eax,%edx
and    $0xfffffffe,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movsd  (%r15,%rcx,8),%xmm1
movsd  0x8(%r15,%rcx,8),%xmm3
movapd %xmm1,%xmm2
movhpd (%r14,%rcx,8),%xmm2
movhpd (%rbx,%rcx,8),%xmm1
mulpd  %xmm2,%xmm1
addpd  %xmm0,%xmm1
movapd %xmm3,%xmm0
movhpd 0x8(%r14,%rcx,8),%xmm0
movhpd 0x8(%rbx,%rcx,8),%xmm3
mulpd  %xmm0,%xmm3
addpd  %xmm1,%xmm3
add    $0x2,%rcx
movapd %xmm3,%xmm0
cmp    %rcx,%rdx
jne    11b0 <chebyshev_error_Rsqrt+0x70>
test   $0x1,%al
je     121b <chebyshev_error_Rsqrt+0xdb>
movsd  (%r15,%rcx,8),%xmm0
movapd %xmm0,%xmm1
movhpd (%r14,%rcx,8),%xmm1
movhpd (%rbx,%rcx,8),%xmm0
mulpd  %xmm1,%xmm0
addpd  %xmm0,%xmm3
movapd %xmm3,(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movapd (%rsp),%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1293 <chebyshev_error_Rsqrt+0x153>
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
andpd  0xdb1(%rip),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xorpd  %xmm0,%xmm0
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"chebyshev_error_Rsqrt : malloc error for x\0A\00"
@.str.1 = [19 x i8] c"negative norm! %e\0A\00"
define double @chebyshev_error_Rsqrt(i32 %0, double* %1, double* %2, void (i32, double*, double*, i8*)* %3, i8* %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca void (i32, double*, double*, i8*)*
%10 = alloca i8*
%11 = alloca double*
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %6
store double* %1, double** %7
store double* %2, double** %8
store void (i32, double*, double*, i8*)* %3, void (i32, double*, double*, i8*)** %9
store i8* %4, i8** %10
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 8, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double*
store double* %20, double** %11
%21 = load double*, double** %11
%22 = icmp eq double* %21, null
br i1 %22, label %23, label %27
23: ; preds = %5
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %5
%28 = load void (i32, double*, double*, i8*)*, void (i32, double*, double*, i8*)** %9
%29 = load i32, i32* %6
%30 = load double*, double** %7
%31 = load double*, double** %11
%32 = load i8*, i8** %10
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
store i32 0, i32* %12
br label %33
33: ; preds = %62, %27
%34 = load i32, i32* %12
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %65
37: ; preds = %33
%38 = load double*, double** %7
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double*, double** %11
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = load double, double* %13
%49 = call double @llvm.fmuladd.f64(double %42, double %47, double %48)
store double %49, double* %13
%50 = load double*, double** %8
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = load double*, double** %8
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double, double* %14
%61 = call double @llvm.fmuladd.f64(double %54, double %59, double %60)
store double %61, double* %14
br label %62
62: ; preds = %37
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %33
65: ; preds = %33
%66 = load double*, double** %11
%67 = call i32 @free(double* %66)
%68 = load double, double* %13
%69 = fcmp ole double %68, 0.000000e+00
br i1 %69, label %70, label %75
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = load double, double* %13
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %65
%76 = load double, double* %13
%77 = load double, double* %14
%78 = fsub double %76, %77
%79 = call double @llvm.fabs.f64(double %78)
%80 = load double, double* %13
%81 = fdiv double %79, %80
ret double %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"chebyshev_error_Rsqrt : malloc error for x\0A\00"
@.str.1 = [19 x i8] c"negative norm! %e\0A\00"
define double @chebyshev_error_Rsqrt(i32 %0, double* %1, double* nocapture %2, void (i32, double*, double*, i8*)* nocapture %3, i8* %4) {
%6 = shl i32 %0, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
tail call void %3(i32 %0, double* %1, double* %8, i8* %4)
%15 = icmp sgt i32 %0, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @free(double* %8)
br label %73
18: ; preds = %14
%19 = zext i32 %0 to i64
%20 = and i64 %19, 1
%21 = icmp eq i32 %0, 1
br i1 %21, label %52, label %22
22: ; preds = %18
%23 = and i64 %19, 4294967294
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %49, %24 ]
%26 = phi <2 x double> [ zeroinitializer, %22 ], [ %48, %24 ]
%27 = phi i64 [ 0, %22 ], [ %50, %24 ]
%28 = getelementptr inbounds double, double* %1, i64 %25
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %8, i64 %25
%31 = load double, double* %30
%32 = getelementptr inbounds double, double* %2, i64 %25
%33 = load double, double* %32
%34 = insertelement <2 x double> poison, double %33, i64 0
%35 = insertelement <2 x double> %34, double %29, i64 1
%36 = insertelement <2 x double> %34, double %31, i64 1
%37 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %35, <2 x double> %36, <2 x double> %26)
%38 = or i64 %25, 1
%39 = getelementptr inbounds double, double* %1, i64 %38
%40 = load double, double* %39
%41 = getelementptr inbounds double, double* %8, i64 %38
%42 = load double, double* %41
%43 = getelementptr inbounds double, double* %2, i64 %38
%44 = load double, double* %43
%45 = insertelement <2 x double> poison, double %44, i64 0
%46 = insertelement <2 x double> %45, double %40, i64 1
%47 = insertelement <2 x double> %45, double %42, i64 1
%48 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %46, <2 x double> %47, <2 x double> %37)
%49 = add nuw nsw i64 %25, 2
%50 = add i64 %27, 2
%51 = icmp eq i64 %50, %23
br i1 %51, label %52, label %24
52: ; preds = %24, %18
%53 = phi <2 x double> [ undef, %18 ], [ %48, %24 ]
%54 = phi i64 [ 0, %18 ], [ %49, %24 ]
%55 = phi <2 x double> [ zeroinitializer, %18 ], [ %48, %24 ]
%56 = icmp eq i64 %20, 0
br i1 %56, label %68, label %57
57: ; preds = %52
%58 = getelementptr inbounds double, double* %1, i64 %54
%59 = load double, double* %58
%60 = getelementptr inbounds double, double* %8, i64 %54
%61 = load double, double* %60
%62 = getelementptr inbounds double, double* %2, i64 %54
%63 = load double, double* %62
%64 = insertelement <2 x double> poison, double %63, i64 0
%65 = insertelement <2 x double> %64, double %59, i64 1
%66 = insertelement <2 x double> %64, double %61, i64 1
%67 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %65, <2 x double> %66, <2 x double> %55)
br label %68
68: ; preds = %52, %57
%69 = phi <2 x double> [ %53, %52 ], [ %67, %57 ]
%70 = tail call i32 @free(double* %8)
%71 = extractelement <2 x double> %69, i64 1
%72 = fcmp ugt double %71, 0.000000e+00
br i1 %72, label %78, label %73
73: ; preds = %16, %68
%74 = phi double [ 0.000000e+00, %16 ], [ %71, %68 ]
%75 = load i32, i32* @stderr
%76 = tail call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %74)
%77 = tail call i32 @exit(i32 1)
unreachable
78: ; preds = %68
%79 = extractelement <2 x double> %69, i64 0
%80 = fsub double %71, %79
%81 = tail call double @llvm.fabs.f64(double %80)
%82 = fdiv double %81, %71
ret double %82
}