#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 mpos(int, int);
int sqrt(double);
double Ddiff(int M, double *Da, double *Db, double *oldD) {
  double dD = 0.0;
  for (int u = 0; u < M; u++) {
    for (int v = u; v < M; v++) {
      int uv = mpos(u, v);
      double ab = Da[uv] + Db[uv];
      double d = oldD[uv] - ab;
      dD += d * d * (u == v ? 1 : 2);
      oldD[uv] = ab;
    }
  }
  return sqrt(dD) / M;
}


x86 assembly (clang, -O0):
<Ddiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1210 <Ddiff+0xf0>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fd <Ddiff+0xdd>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1030 <mpos@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%esi
mov    $0x2,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
cvtsi2sd %eax,%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1158 <Ddiff+0x38>
jmp    1202 <Ddiff+0xe2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1146 <Ddiff+0x26>
movsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
cltd
idivl  -0x4(%rbp)
cvtsi2sd %eax,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ddiff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
test   %edi,%edi
jle    11ce <Ddiff+0xae>
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
xor    %ebp,%ebp
xorpd  %xmm0,%xmm0
mov    %r14d,%r13d
mov    %r14d,0xc(%rsp)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,0x10(%rsp)
lea    (%r14,%rbp,1),%esi
mov    %ebp,%edi
call   1030 <mpos@plt>
cltq
movsd  (%r12,%rax,8),%xmm3
addsd  (%r15,%rax,8),%xmm3
movsd  (%rbx,%rax,8),%xmm1
subsd  %xmm3,%xmm1
cmp    $0x1,%r14d
mov    $0x2,%ecx
sbb    $0x0,%ecx
mulsd  %xmm1,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
mulsd  %xmm1,%xmm2
movsd  0x10(%rsp),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm3,(%rbx,%rax,8)
add    $0x1,%r14d
cmp    %r14d,%r13d
jne    1160 <Ddiff+0x40>
add    $0x1,%ebp
add    $0xffffffff,%r13d
mov    0xc(%rsp),%r14d
cmp    %r14d,%ebp
jne    1150 <Ddiff+0x30>
jmp    11d2 <Ddiff+0xb2>
xorpd  %xmm0,%xmm0
call   1040 <sqrt@plt>
cltd
idiv   %r14d
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @Ddiff(i32 %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
store double 0.000000e+00, double* %9
store i32 0, i32* %10
br label %15
15: ; preds = %67, %4
%16 = load i32, i32* %10
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %70
19: ; preds = %15
%20 = load i32, i32* %10
store i32 %20, i32* %11
br label %21
21: ; preds = %63, %19
%22 = load i32, i32* %11
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %66
25: ; preds = %21
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = call i32 @mpos(i32 %26, i32 %27)
store i32 %28, i32* %12
%29 = load double*, double** %6
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %7
%35 = load i32, i32* %12
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = fadd double %33, %38
store double %39, double* %13
%40 = load double*, double** %8
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double, double* %13
%46 = fsub double %44, %45
store double %46, double* %14
%47 = load double, double* %14
%48 = load double, double* %14
%49 = fmul double %47, %48
%50 = load i32, i32* %10
%51 = load i32, i32* %11
%52 = icmp eq i32 %50, %51
%53 = zext i1 %52 to i64
%54 = select i1 %52, i32 1, i32 2
%55 = sitofp i32 %54 to double
%56 = load double, double* %9
%57 = call double @llvm.fmuladd.f64(double %49, double %55, double %56)
store double %57, double* %9
%58 = load double, double* %13
%59 = load double*, double** %8
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
store double %58, double* %62
br label %63
63: ; preds = %25
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
br label %21
66: ; preds = %21
br label %67
67: ; preds = %66
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
br label %15
70: ; preds = %15
%71 = load double, double* %9
%72 = call i32 @sqrt(double %71)
%73 = load i32, i32* %5
%74 = sdiv i32 %72, %73
%75 = sitofp i32 %74 to double
ret double %75
}

LLVM IR (-O2):
define double @Ddiff(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %4, %14
%7 = phi double [ %34, %14 ], [ 0.000000e+00, %4 ]
%8 = phi i32 [ %15, %14 ], [ 0, %4 ]
br label %17
9: ; preds = %14, %4
%10 = phi double [ 0.000000e+00, %4 ], [ %34, %14 ]
%11 = tail call i32 @sqrt(double %10)
%12 = sdiv i32 %11, %0
%13 = sitofp i32 %12 to double
ret double %13
14: ; preds = %17
%15 = add nuw nsw i32 %8, 1
%16 = icmp eq i32 %15, %0
br i1 %16, label %9, label %6
17: ; preds = %6, %17
%18 = phi double [ %34, %17 ], [ %7, %6 ]
%19 = phi i32 [ %35, %17 ], [ %8, %6 ]
%20 = tail call i32 @mpos(i32 %8, i32 %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %1, i64 %21
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %2, i64 %21
%25 = load double, double* %24
%26 = fadd double %23, %25
%27 = getelementptr inbounds double, double* %3, i64 %21
%28 = load double, double* %27
%29 = fsub double %28, %26
%30 = fmul double %29, %29
%31 = icmp eq i32 %8, %19
%32 = select i1 %31, i32 1, i32 2
%33 = sitofp i32 %32 to double
%34 = tail call double @llvm.fmuladd.f64(double %30, double %33, double %18)
store double %26, double* %27
%35 = add nuw i32 %19, 1
%36 = icmp eq i32 %35, %0
br i1 %36, label %14, label %17
}