#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 covariance(double *, double *, int);
double mean(double *, int);
scalar_t__ pow(double, int);
double sqrt(scalar_t__);
double standard_dev_mean(double *, double, int);
double kge_c(double *obs, double *sim, int n) {
  double obs_mean = mean(obs, n);
  double sim_mean = mean(sim, n);
  double obs_std = standard_dev_mean(obs, obs_mean, n);
  double sim_std = standard_dev_mean(sim, sim_mean, n);
  double beta = (sim_mean / obs_mean);
  double cov_so = covariance(sim, obs, n);
  double alpha = 0;
  double r = 0;
  if (sim_std != 0) {
    alpha = sim_std / obs_std;
    r = cov_so / (sim_std * obs_std);
  }
  return 1 - sqrt(pow(r - 1, 2) + pow(alpha - 1, 2) + pow(beta - 1, 2));
}


x86 assembly (clang, -O0):
<kge_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <mean@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <mean@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%esi
call   1030 <standard_dev_mean@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
mov    -0x14(%rbp),%esi
call   1030 <standard_dev_mean@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <covariance@plt>
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1202 <kge_c+0xb2>
jp     1202 <kge_c+0xb2>
jmp    1229 <kge_c+0xd9>
movsd  -0x38(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  0xdca(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %rax,-0x68(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xdab(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xd82(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
mov    -0x60(%rbp),%rdi
add    %rax,%rdi
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd5d(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kge_c>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%esi
call   1060 <mean@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <mean@plt>
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm0
mov    %ebx,%esi
call   1030 <standard_dev_mean@plt>
movaps %xmm0,0x20(%rsp)
mov    %r14,%rdi
movsd  (%rsp),%xmm0
mov    %ebx,%esi
call   1030 <standard_dev_mean@plt>
movapd %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <covariance@plt>
movapd 0x10(%rsp),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    11c6 <kge_c+0x76>
jnp    11ea <kge_c+0x9a>
movapd 0x20(%rsp),%xmm3
movapd %xmm3,%xmm1
mulsd  %xmm2,%xmm1
unpcklpd %xmm0,%xmm2
unpcklpd %xmm1,%xmm3
divpd  %xmm3,%xmm2
addpd  0xe18(%rip),%xmm2
jmp    11f2 <kge_c+0xa2>
movapd 0xe0e(%rip),%xmm2
movapd %xmm2,0x10(%rsp)
movsd  (%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %rax,%rbx
movaps 0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
add    %rax,%rbx
movsd  (%rsp),%xmm0
addsd  0xdd4(%rip),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   1070 <sqrt@plt>
movsd  0xdbf(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @kge_c(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%15 = load double*, double** %4
%16 = load i32, i32* %6
%17 = call double @mean(double* %15, i32 %16)
store double %17, double* %7
%18 = load double*, double** %5
%19 = load i32, i32* %6
%20 = call double @mean(double* %18, i32 %19)
store double %20, double* %8
%21 = load double*, double** %4
%22 = load double, double* %7
%23 = load i32, i32* %6
%24 = call double @standard_dev_mean(double* %21, double %22, i32 %23)
store double %24, double* %9
%25 = load double*, double** %5
%26 = load double, double* %8
%27 = load i32, i32* %6
%28 = call double @standard_dev_mean(double* %25, double %26, i32 %27)
store double %28, double* %10
%29 = load double, double* %8
%30 = load double, double* %7
%31 = fdiv double %29, %30
store double %31, double* %11
%32 = load double*, double** %5
%33 = load double*, double** %4
%34 = load i32, i32* %6
%35 = call double @covariance(double* %32, double* %33, i32 %34)
store double %35, double* %12
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
%36 = load double, double* %10
%37 = fcmp une double %36, 0.000000e+00
br i1 %37, label %38, label %47
38: ; preds = %3
%39 = load double, double* %10
%40 = load double, double* %9
%41 = fdiv double %39, %40
store double %41, double* %13
%42 = load double, double* %12
%43 = load double, double* %10
%44 = load double, double* %9
%45 = fmul double %43, %44
%46 = fdiv double %42, %45
store double %46, double* %14
br label %47
47: ; preds = %38, %3
%48 = load double, double* %14
%49 = fsub double %48, 1.000000e+00
%50 = call i64 @pow(double %49, i32 2)
%51 = load double, double* %13
%52 = fsub double %51, 1.000000e+00
%53 = call i64 @pow(double %52, i32 2)
%54 = add nsw i64 %50, %53
%55 = load double, double* %11
%56 = fsub double %55, 1.000000e+00
%57 = call i64 @pow(double %56, i32 2)
%58 = add nsw i64 %54, %57
%59 = call double @sqrt(i64 %58)
%60 = fsub double 1.000000e+00, %59
ret double %60
}

LLVM IR (-O2):
define double @kge_c(double* %0, double* %1, i32 %2) {
%4 = tail call double @mean(double* %0, i32 %2)
%5 = tail call double @mean(double* %1, i32 %2)
%6 = tail call double @standard_dev_mean(double* %0, double %4, i32 %2)
%7 = tail call double @standard_dev_mean(double* %1, double %5, i32 %2)
%8 = tail call double @covariance(double* %1, double* %0, i32 %2)
%9 = fcmp une double %7, 0.000000e+00
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = fmul double %6, %7
%12 = insertelement <2 x double> poison, double %7, i64 0
%13 = insertelement <2 x double> %12, double %8, i64 1
%14 = insertelement <2 x double> poison, double %6, i64 0
%15 = insertelement <2 x double> %14, double %11, i64 1
%16 = fdiv <2 x double> %13, %15
%17 = fadd <2 x double> %16, <double -1.000000e+00, double -1.000000e+00>
br label %18
18: ; preds = %10, %3
%19 = phi <2 x double> [ %17, %10 ], [ <double -1.000000e+00, double -1.000000e+00>, %3 ]
%20 = fdiv double %5, %4
%21 = extractelement <2 x double> %19, i64 1
%22 = tail call i64 @pow(double %21, i32 2)
%23 = extractelement <2 x double> %19, i64 0
%24 = tail call i64 @pow(double %23, i32 2)
%25 = add nsw i64 %24, %22
%26 = fadd double %20, -1.000000e+00
%27 = tail call i64 @pow(double %26, i32 2)
%28 = add nsw i64 %25, %27
%29 = tail call double @sqrt(i64 %28)
%30 = fsub double 1.000000e+00, %29
ret double %30
}