#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 somx(double **, long);
double somx2(double **, long);
double sompx(double **a, long stop) {
  double ret = 0;
  long N;
  double lsomx = somx(a, stop);
  double lsomx2 = somx2(a, stop);
  N = ((stop * (stop - 1)) / 2) + stop;
  ret = (lsomx2 - ((lsomx * lsomx) / N));
  return ret;
}


x86 assembly (clang, -O0):
<sompx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <somx@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <somx2@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
imul   %rcx,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
cvtsi2sdq -0x20(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sompx>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <somx@plt>
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <somx2@plt>
lea    -0x1(%rbx),%rax
imul   %rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rax,%rcx
sar    %rcx
add    %rbx,%rcx
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm2
cvtsi2sd %rcx,%xmm1
divsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @sompx(double** %0, i64 %1) {
%3 = alloca double**
%4 = alloca i64
%5 = alloca double
%6 = alloca i64
%7 = alloca double
%8 = alloca double
store double** %0, double*** %3
store i64 %1, i64* %4
store double 0.000000e+00, double* %5
%9 = load double**, double*** %3
%10 = load i64, i64* %4
%11 = call double @somx(double** %9, i64 %10)
store double %11, double* %7
%12 = load double**, double*** %3
%13 = load i64, i64* %4
%14 = call double @somx2(double** %12, i64 %13)
store double %14, double* %8
%15 = load i64, i64* %4
%16 = load i64, i64* %4
%17 = sub nsw i64 %16, 1
%18 = mul nsw i64 %15, %17
%19 = sdiv i64 %18, 2
%20 = load i64, i64* %4
%21 = add nsw i64 %19, %20
store i64 %21, i64* %6
%22 = load double, double* %8
%23 = load double, double* %7
%24 = load double, double* %7
%25 = fmul double %23, %24
%26 = load i64, i64* %6
%27 = sitofp i64 %26 to double
%28 = fdiv double %25, %27
%29 = fsub double %22, %28
store double %29, double* %5
%30 = load double, double* %5
ret double %30
}

LLVM IR (-O2):
define double @sompx(double** %0, i64 %1) {
%3 = tail call double @somx(double** %0, i64 %1)
%4 = tail call double @somx2(double** %0, i64 %1)
%5 = add nsw i64 %1, -1
%6 = mul nsw i64 %5, %1
%7 = sdiv i64 %6, 2
%8 = add nsw i64 %7, %1
%9 = fmul double %3, %3
%10 = sitofp i64 %8 to double
%11 = fdiv double %9, %10
%12 = fsub double %4, %11
ret double %12
}