#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 */
typedef int uint_fast16_t;

/* Variables and functions */
double M_PI;
double fabs(double);
double sqrt(double);
double circularMvDistance(int p, double *a, double *b) {
  uint_fast16_t i;
  double dist = 0;
  for (i = 0; i < p; i++) {
    if (fabs(a[i] - b[i]) > M_PI) {
      if (a[i] > M_PI)
        dist += (a[i] - b[i] - 2 * M_PI) * (a[i] - b[i] - 2 * M_PI);
      else
        dist += (a[i] - b[i] + 2 * M_PI) * (a[i] - b[i] + 2 * M_PI);
    } else
      dist += (a[i] - b[i]) * (a[i] - b[i]);
  }
  return (sqrt(dist));
}


x86 assembly (clang, -O0):
<circularMvDistance>:
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,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12cd <circularMvDistance+0x1bd>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movaps 0xea1(%rip),%xmm1
pand   %xmm1,%xmm0
mov    0x2e7e(%rip),%rax
ucomisd (%rax),%xmm0
jbe    1274 <circularMvDistance+0x164>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    0x2e60(%rip),%rax
ucomisd (%rax),%xmm0
jbe    1203 <circularMvDistance+0xf3>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    0x2e35(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
mov    0x2e08(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    126f <circularMvDistance+0x15f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
mov    0x2dc4(%rip),%rax
movsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
mov    0x2d97(%rip),%rax
movsd  (%rax),%xmm2
addsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12ba <circularMvDistance+0x1aa>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12bf <circularMvDistance+0x1af>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1132 <circularMvDistance+0x22>
movsd  -0x28(%rbp),%xmm0
call   1030 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<circularMvDistance>:
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %edi,%edi
jle    118d <circularMvDistance+0x7d>
mov    0x2ec5(%rip),%rax
movsd  (%rax),%xmm2
mov    %edi,%eax
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
movapd 0xec9(%rip),%xmm3
movapd %xmm2,%xmm4
addsd  %xmm2,%xmm4
jmp    1165 <circularMvDistance+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addsd  %xmm4,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm5,%xmm0
add    $0x1,%rcx
cmp    %rcx,%rax
je     118d <circularMvDistance+0x7d>
movsd  (%rsi,%rcx,8),%xmm6
movapd %xmm6,%xmm5
subsd  (%rdx,%rcx,8),%xmm5
movapd %xmm5,%xmm7
andpd  %xmm3,%xmm7
ucomisd %xmm2,%xmm7
jbe    1154 <circularMvDistance+0x44>
ucomisd %xmm2,%xmm6
jbe    1150 <circularMvDistance+0x40>
subsd  %xmm4,%xmm5
jmp    1154 <circularMvDistance+0x44>
ucomisd %xmm1,%xmm0
jb     1198 <circularMvDistance+0x88>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @circularMvDistance(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store double 0.000000e+00, double* %8
store i32 0, i32* %7
br label %9
9: ; preds = %121, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %124
13: ; preds = %9
%14 = load double*, double** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fsub double %18, %23
%25 = call double @llvm.fabs.f64(double %24)
%26 = load double, double* @M_PI
%27 = fcmp ogt double %25, %26
br i1 %27, label %28, label %95
28: ; preds = %13
%29 = load double*, double** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double, double* @M_PI
%35 = fcmp ogt double %33, %34
br i1 %35, label %36, label %65
36: ; preds = %28
%37 = load double*, double** %5
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = load double*, double** %6
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = fsub double %41, %46
%48 = load double, double* @M_PI
%49 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %48, double %47)
%50 = load double*, double** %5
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = load double*, double** %6
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = fsub double %54, %59
%61 = load double, double* @M_PI
%62 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %61, double %60)
%63 = load double, double* %8
%64 = call double @llvm.fmuladd.f64(double %49, double %62, double %63)
store double %64, double* %8
br label %94
65: ; preds = %28
%66 = load double*, double** %5
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
%70 = load double, double* %69
%71 = load double*, double** %6
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = fsub double %70, %75
%77 = load double, double* @M_PI
%78 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %77, double %76)
%79 = load double*, double** %5
%80 = load i32, i32* %7
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %79, i64 %81
%83 = load double, double* %82
%84 = load double*, double** %6
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
%88 = load double, double* %87
%89 = fsub double %83, %88
%90 = load double, double* @M_PI
%91 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %90, double %89)
%92 = load double, double* %8
%93 = call double @llvm.fmuladd.f64(double %78, double %91, double %92)
store double %93, double* %8
br label %94
94: ; preds = %65, %36
br label %120
95: ; preds = %13
%96 = load double*, double** %5
%97 = load i32, i32* %7
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = load double*, double** %6
%102 = load i32, i32* %7
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %101, i64 %103
%105 = load double, double* %104
%106 = fsub double %100, %105
%107 = load double*, double** %5
%108 = load i32, i32* %7
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %110
%112 = load double*, double** %6
%113 = load i32, i32* %7
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double, double* %112, i64 %114
%116 = load double, double* %115
%117 = fsub double %111, %116
%118 = load double, double* %8
%119 = call double @llvm.fmuladd.f64(double %106, double %117, double %118)
store double %119, double* %8
br label %120
120: ; preds = %95, %94
br label %121
121: ; preds = %120
%122 = load i32, i32* %7
%123 = add nsw i32 %122, 1
store i32 %123, i32* %7
br label %9
124: ; preds = %9
%125 = load double, double* %8
%126 = call double @sqrt(double %125)
ret double %126
}

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