#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 round(double);
double gyrtensxy(double *posList, int N, int x, int y, double boxlx,
                 double boxly) {
  double gxy = 0;
  double U, V;
  for (int R = 0; R < N; R++) {
    for (int S = 0; S < N; S++) {
      V = posList[3 * R + x] - posList[3 * S + x];
      V = V - boxlx * round(V / boxlx);
      U = posList[3 * R + y] - posList[3 * S + y];
      U = U - boxly * round(U / boxly);
      gxy = gxy + V * U;
    }
  }
  gxy = gxy / (2 * N * N);
  return gxy;
}


x86 assembly (clang, -O0):
<gyrtensxy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1298 <gyrtensxy+0x188>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1285 <gyrtensxy+0x175>
mov    -0x8(%rbp),%rax
imul   $0x3,-0x44(%rbp),%ecx
add    -0x10(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
imul   $0x3,-0x48(%rbp),%ecx
add    -0x10(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <round@plt>
movsd  -0x68(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3,-0x44(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
imul   $0x3,-0x48(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
call   1030 <round@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1151 <gyrtensxy+0x41>
jmp    128a <gyrtensxy+0x17a>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    113e <gyrtensxy+0x2e>
movsd  -0x30(%rbp),%xmm0
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
imul   -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gyrtensxy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
test   %esi,%esi
mov    %esi,0x14(%rsp)
jle    1268 <gyrtensxy+0x158>
movapd %xmm0,%xmm2
mov    %rdi,%rbx
movapd 0xec4(%rip),%xmm3
xorpd  %xmm3,%xmm0
movapd %xmm0,0x50(%rsp)
movapd %xmm1,0x80(%rsp)
xorpd  %xmm1,%xmm3
movslq %edx,%rax
movslq %ecx,%rcx
mov    %esi,%edx
mov    %rcx,0x20(%rsp)
lea    (%rdi,%rcx,8),%rbp
mov    %rax,0x28(%rsp)
lea    (%rdi,%rax,8),%r14
mov    %rdx,0x18(%rsp)
lea    0x0(,%rdx,8),%rax
lea    (%rax,%rax,2),%r15
xorpd  %xmm1,%xmm1
xor    %r12d,%r12d
movapd %xmm2,0x70(%rsp)
movapd %xmm3,0x60(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r12,%r12,2),%rax
mov    0x28(%rsp),%rcx
add    %rax,%rcx
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x38(%rsp)
add    0x20(%rsp),%rax
movsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,0x30(%rsp)
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x48(%rsp)
movsd  0x38(%rsp),%xmm0
subsd  (%r14,%r13,1),%xmm0
movsd  %xmm0,0x8(%rsp)
divsd  %xmm2,%xmm0
call   1030 <round@plt>
mulsd  0x50(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x30(%rsp),%xmm0
subsd  0x0(%rbp,%r13,1),%xmm0
movsd  %xmm0,0x40(%rsp)
divsd  0x80(%rsp),%xmm0
call   1030 <round@plt>
movsd  0x48(%rsp),%xmm1
movapd 0x60(%rsp),%xmm3
movapd 0x70(%rsp),%xmm2
mulsd  %xmm3,%xmm0
addsd  0x40(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm1
add    $0x18,%r13
cmp    %r13,%r15
jne    11d0 <gyrtensxy+0xc0>
add    $0x1,%r12
cmp    0x18(%rsp),%r12
jne    11a0 <gyrtensxy+0x90>
jmp    126c <gyrtensxy+0x15c>
xorpd  %xmm1,%xmm1
mov    0x14(%rsp),%eax
imul   %eax,%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @gyrtensxy(double* %0, i32 %1, i32 %2, i32 %3, double %4, double %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca i32
store double* %0, double** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double %4, double* %11
store double %5, double* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %16
br label %18
18: ; preds = %86, %6
%19 = load i32, i32* %16
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %89
22: ; preds = %18
store i32 0, i32* %17
br label %23
23: ; preds = %82, %22
%24 = load i32, i32* %17
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %85
27: ; preds = %23
%28 = load double*, double** %7
%29 = load i32, i32* %16
%30 = mul nsw i32 3, %29
%31 = load i32, i32* %9
%32 = add nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %28, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %7
%37 = load i32, i32* %17
%38 = mul nsw i32 3, %37
%39 = load i32, i32* %9
%40 = add nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %36, i64 %41
%43 = load double, double* %42
%44 = fsub double %35, %43
store double %44, double* %15
%45 = load double, double* %15
%46 = load double, double* %11
%47 = load double, double* %15
%48 = load double, double* %11
%49 = fdiv double %47, %48
%50 = call double @llvm.round.f64(double %49)
%51 = fneg double %46
%52 = call double @llvm.fmuladd.f64(double %51, double %50, double %45)
store double %52, double* %15
%53 = load double*, double** %7
%54 = load i32, i32* %16
%55 = mul nsw i32 3, %54
%56 = load i32, i32* %10
%57 = add nsw i32 %55, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %53, i64 %58
%60 = load double, double* %59
%61 = load double*, double** %7
%62 = load i32, i32* %17
%63 = mul nsw i32 3, %62
%64 = load i32, i32* %10
%65 = add nsw i32 %63, %64
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %61, i64 %66
%68 = load double, double* %67
%69 = fsub double %60, %68
store double %69, double* %14
%70 = load double, double* %14
%71 = load double, double* %12
%72 = load double, double* %14
%73 = load double, double* %12
%74 = fdiv double %72, %73
%75 = call double @llvm.round.f64(double %74)
%76 = fneg double %71
%77 = call double @llvm.fmuladd.f64(double %76, double %75, double %70)
store double %77, double* %14
%78 = load double, double* %13
%79 = load double, double* %15
%80 = load double, double* %14
%81 = call double @llvm.fmuladd.f64(double %79, double %80, double %78)
store double %81, double* %13
br label %82
82: ; preds = %27
%83 = load i32, i32* %17
%84 = add nsw i32 %83, 1
store i32 %84, i32* %17
br label %23
85: ; preds = %23
br label %86
86: ; preds = %85
%87 = load i32, i32* %16
%88 = add nsw i32 %87, 1
store i32 %88, i32* %16
br label %18
89: ; preds = %18
%90 = load double, double* %13
%91 = load i32, i32* %8
%92 = mul nsw i32 2, %91
%93 = load i32, i32* %8
%94 = mul nsw i32 %92, %93
%95 = sitofp i32 %94 to double
%96 = fdiv double %90, %95
store double %96, double* %13
%97 = load double, double* %13
ret double %97
}

LLVM IR (-O2):
define double @gyrtensxy(double* nocapture %0, i32 %1, i32 %2, i32 %3, double %4, double %5) {
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %24
8: ; preds = %6
%9 = fneg double %4
%10 = fneg double %5
%11 = sext i32 %2 to i64
%12 = sext i32 %3 to i64
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %30, %8
%15 = phi i64 [ 0, %8 ], [ %31, %30 ]
%16 = phi double [ 0.000000e+00, %8 ], [ %51, %30 ]
%17 = mul nuw nsw i64 %15, 3
%18 = add nsw i64 %17, %11
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = add nsw i64 %17, %12
%22 = getelementptr inbounds double, double* %0, i64 %21
%23 = load double, double* %22
br label %33
24: ; preds = %30, %6
%25 = phi double [ 0.000000e+00, %6 ], [ %51, %30 ]
%26 = shl nsw i32 %1, 1
%27 = mul nsw i32 %26, %1
%28 = sitofp i32 %27 to double
%29 = fdiv double %25, %28
ret double %29
30: ; preds = %33
%31 = add nuw nsw i64 %15, 1
%32 = icmp eq i64 %31, %13
br i1 %32, label %24, label %14
33: ; preds = %14, %33
%34 = phi i64 [ 0, %14 ], [ %52, %33 ]
%35 = phi double [ %16, %14 ], [ %51, %33 ]
%36 = mul nuw nsw i64 %34, 3
%37 = add nsw i64 %36, %11
%38 = getelementptr inbounds double, double* %0, i64 %37
%39 = load double, double* %38
%40 = fsub double %20, %39
%41 = fdiv double %40, %4
%42 = tail call double @llvm.round.f64(double %41)
%43 = tail call double @llvm.fmuladd.f64(double %9, double %42, double %40)
%44 = add nsw i64 %36, %12
%45 = getelementptr inbounds double, double* %0, i64 %44
%46 = load double, double* %45
%47 = fsub double %23, %46
%48 = fdiv double %47, %5
%49 = tail call double @llvm.round.f64(double %48)
%50 = tail call double @llvm.fmuladd.f64(double %10, double %49, double %47)
%51 = tail call double @llvm.fmuladd.f64(double %43, double %50, double %35)
%52 = add nuw nsw i64 %34, 1
%53 = icmp eq i64 %52, %13
br i1 %53, label %30, label %33
}