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


x86 assembly (clang, -O0):
<chebyshev_error_minvsqrt>:
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_minvsqrt+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    -0x18(%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_minvsqrt+0xf8>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%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    -0x30(%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_minvsqrt+0x86>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jb     1275 <chebyshev_error_minvsqrt+0x135>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
movsd  -0x48(%rbp),%xmm0
lea    0xddb(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movaps 0xd7a(%rip),%xmm1
pand   %xmm1,%xmm0
divsd  -0x48(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chebyshev_error_minvsqrt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbp
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r12d
lea    0x0(,%r12,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     126e <chebyshev_error_minvsqrt+0x12e>
mov    %rax,%r15
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
mov    %rbp,%rcx
call   *%r13
test   %r12d,%r12d
jle    128f <chebyshev_error_minvsqrt+0x14f>
mov    %r12d,%eax
cmp    $0x1,%r12d
jne    119f <chebyshev_error_minvsqrt+0x5f>
xorpd  %xmm6,%xmm6
xor    %ecx,%ecx
jmp    1202 <chebyshev_error_minvsqrt+0xc2>
mov    %eax,%edx
and    $0xfffffffe,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm1
movsd  0x8(%rbx,%rcx,8),%xmm2
movsd  (%r14,%rcx,8),%xmm3
movsd  0x8(%r14,%rcx,8),%xmm4
unpcklpd %xmm3,%xmm1
movsd  (%r15,%rcx,8),%xmm5
movsd  0x8(%r15,%rcx,8),%xmm6
unpcklpd %xmm3,%xmm5
mulpd  %xmm1,%xmm5
addpd  %xmm0,%xmm5
unpcklpd %xmm4,%xmm2
unpcklpd %xmm4,%xmm6
mulpd  %xmm2,%xmm6
addpd  %xmm5,%xmm6
add    $0x2,%rcx
movapd %xmm6,%xmm0
cmp    %rcx,%rdx
jne    11b0 <chebyshev_error_minvsqrt+0x70>
test   $0x1,%al
je     1227 <chebyshev_error_minvsqrt+0xe7>
movsd  (%rbx,%rcx,8),%xmm0
movsd  (%r14,%rcx,8),%xmm1
unpcklpd %xmm1,%xmm0
movsd  (%r15,%rcx,8),%xmm2
unpcklpd %xmm1,%xmm2
mulpd  %xmm0,%xmm2
addpd  %xmm2,%xmm6
movapd %xmm6,(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
movapd (%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jae    12a0 <chebyshev_error_minvsqrt+0x160>
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
andpd  0xda5(%rip),%xmm0
divsd  %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
movaps (%rsp),%xmm0
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"chebyshev_error_minvsqrt : malloc error for x\0A\00"
@.str.1 = [19 x i8] c"negative norm! %e\0A\00"
define double @chebyshev_error_minvsqrt(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 ([47 x i8], [47 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** %8
%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** %7
%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** %11
%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* %14
%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* %14
%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* %14
%77 = load double, double* %13
%78 = fsub double %76, %77
%79 = call double @llvm.fabs.f64(double %78)
%80 = load double, double* %14
%81 = fdiv double %79, %80
ret double %81
}

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