#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 sqrt(double);
double rmscal(int atomnum, double gaschargep[], double gaschargea[]) {
  double total = 0.0;
  double rms;
  int i;
  for (i = 0; i < atomnum; i++) {
    total += (gaschargep[i] - gaschargea[i]) * (gaschargep[i] - gaschargea[i]);
    gaschargep[i] = gaschargea[i];
  }
  rms = total / atomnum;
  rms = sqrt(rms);
  return rms;
}


x86 assembly (clang, -O0):
<rmscal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ac <rmscal+0x9c>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1132 <rmscal+0x22>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmscal>:
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %edi,%edi
jle    11a7 <rmscal+0x97>
mov    %edi,%r8d
cmp    $0x1,%edi
jne    1130 <rmscal+0x20>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
jmp    1186 <rmscal+0x76>
mov    %r8d,%ecx
and    $0xfffffffe,%ecx
xorpd  %xmm2,%xmm2
xor    %eax,%eax
nopl   0x0(%rax)
movsd  (%rdx,%rax,8),%xmm3
movsd  (%rsi,%rax,8),%xmm4
movsd  0x8(%rsi,%rax,8),%xmm0
subsd  %xmm3,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm2,%xmm4
movsd  %xmm3,(%rsi,%rax,8)
movsd  0x8(%rdx,%rax,8),%xmm2
subsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm4,%xmm0
movsd  %xmm2,0x8(%rsi,%rax,8)
add    $0x2,%rax
movapd %xmm0,%xmm2
cmp    %rax,%rcx
jne    1140 <rmscal+0x30>
test   $0x1,%r8b
je     11a7 <rmscal+0x97>
movsd  (%rsi,%rax,8),%xmm2
movsd  (%rdx,%rax,8),%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm2,%xmm0
movsd  %xmm3,(%rsi,%rax,8)
xorps  %xmm2,%xmm2
cvtsi2sd %edi,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     11bd <rmscal+0xad>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

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

LLVM IR (-O2):
define double @rmscal(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %43
5: ; preds = %3
%6 = zext i32 %0 to i64
%7 = and i64 %6, 1
%8 = icmp eq i32 %0, 1
br i1 %8, label %31, label %9
9: ; preds = %5
%10 = and i64 %6, 4294967294
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %28, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %27, %11 ]
%14 = phi i64 [ 0, %9 ], [ %29, %11 ]
%15 = getelementptr inbounds double, double* %1, i64 %12
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %2, i64 %12
%18 = load double, double* %17
%19 = fsub double %16, %18
%20 = tail call double @llvm.fmuladd.f64(double %19, double %19, double %13)
store double %18, double* %15
%21 = or i64 %12, 1
%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 = fsub double %23, %25
%27 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %20)
store double %25, double* %22
%28 = add nuw nsw i64 %12, 2
%29 = add i64 %14, 2
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %11
31: ; preds = %11, %5
%32 = phi double [ undef, %5 ], [ %27, %11 ]
%33 = phi i64 [ 0, %5 ], [ %28, %11 ]
%34 = phi double [ 0.000000e+00, %5 ], [ %27, %11 ]
%35 = icmp eq i64 %7, 0
br i1 %35, label %43, label %36
36: ; preds = %31
%37 = getelementptr inbounds double, double* %1, i64 %33
%38 = load double, double* %37
%39 = getelementptr inbounds double, double* %2, i64 %33
%40 = load double, double* %39
%41 = fsub double %38, %40
%42 = tail call double @llvm.fmuladd.f64(double %41, double %41, double %34)
store double %40, double* %37
br label %43
43: ; preds = %36, %31, %3
%44 = phi double [ 0.000000e+00, %3 ], [ %32, %31 ], [ %42, %36 ]
%45 = sitofp i32 %0 to double
%46 = fdiv double %44, %45
%47 = tail call double @sqrt(double %46)
ret double %47
}