#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 ComputeA(double, int, double *, double *, double *);
void CalcError(int r, double ad[], double x[], double y[], int gridsize,
               double Grid[], double D[], double W[], double E[]) {
  int i;
  double A;
  for (i = 0; i < gridsize; i++) {
    A = ComputeA(Grid[i], r, ad, x, y);
    E[i] = W[i] * (D[i] - A);
  }
}


x86 assembly (clang, -O0):
<CalcError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11b2 <CalcError+0xa2>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <ComputeA@plt>
movsd  %xmm0,-0x40(%rbp)
mov    0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
subsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1142 <CalcError+0x32>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcError>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %r8d,%r8d
jle    1186 <CalcError+0x76>
mov    %r9,%r15
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r13d
mov    %r8d,%eax
mov    %rax,(%rsp)
xor    %r14d,%r14d
nopl   0x0(%rax)
movsd  (%r15,%r14,8),%xmm0
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1030 <ComputeA@plt>
mov    0x40(%rsp),%rax
movsd  (%rax,%r14,8),%xmm1
subsd  %xmm0,%xmm1
mov    0x48(%rsp),%rax
mulsd  (%rax,%r14,8),%xmm1
mov    0x50(%rsp),%rax
movsd  %xmm1,(%rax,%r14,8)
add    $0x1,%r14
cmp    %r14,(%rsp)
jne    1140 <CalcError+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @CalcError(i32 %0, double* %1, double* %2, double* %3, i32 %4, double* %5, double* %6, double* %7, double* %8) {
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca i32
%20 = alloca double
store i32 %0, i32* %10
store double* %1, double** %11
store double* %2, double** %12
store double* %3, double** %13
store i32 %4, i32* %14
store double* %5, double** %15
store double* %6, double** %16
store double* %7, double** %17
store double* %8, double** %18
store i32 0, i32* %19
br label %21
21: ; preds = %53, %9
%22 = load i32, i32* %19
%23 = load i32, i32* %14
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %56
25: ; preds = %21
%26 = load double*, double** %15
%27 = load i32, i32* %19
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load i32, i32* %10
%32 = load double*, double** %11
%33 = load double*, double** %12
%34 = load double*, double** %13
%35 = call double @ComputeA(double %30, i32 %31, double* %32, double* %33, double* %34)
store double %35, double* %20
%36 = load double*, double** %17
%37 = load i32, i32* %19
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load double*, double** %16
%42 = load i32, i32* %19
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = load double, double* %20
%47 = fsub double %45, %46
%48 = fmul double %40, %47
%49 = load double*, double** %18
%50 = load i32, i32* %19
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
store double %48, double* %52
br label %53
53: ; preds = %25
%54 = load i32, i32* %19
%55 = add nsw i32 %54, 1
store i32 %55, i32* %19
br label %21
56: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @CalcError(i32 %0, double* %1, double* %2, double* %3, i32 %4, double* nocapture %5, double* nocapture %6, double* nocapture %7, double* nocapture writeonly %8) {
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %27
11: ; preds = %9
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %25, %13 ]
%15 = getelementptr inbounds double, double* %5, i64 %14
%16 = load double, double* %15
%17 = tail call double @ComputeA(double %16, i32 %0, double* %1, double* %2, double* %3)
%18 = getelementptr inbounds double, double* %7, i64 %14
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %6, i64 %14
%21 = load double, double* %20
%22 = fsub double %21, %17
%23 = fmul double %19, %22
%24 = getelementptr inbounds double, double* %8, i64 %14
store double %23, double* %24
%25 = add nuw nsw i64 %14, 1
%26 = icmp eq i64 %25, %12
br i1 %26, label %27, label %13
27: ; preds = %13, %9
ret void
}