#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 get_distance_periodic_sqr(double x1, double y1, double z1, double x2,
                                 double y2, double z2, double cell) {
  double dst[3];
  double val = 0.;
  dst[0] = x1 - x2;
  dst[1] = y1 - y2;
  dst[2] = z1 - z2;
  dst[0] -= cell * round(dst[0] / cell);
  dst[1] -= cell * round(dst[1] / cell);
  dst[2] -= cell * round(dst[2] / cell);
  val += dst[0] * dst[0];
  val += dst[1] * dst[1];
  val += dst[2] * dst[2];
  return val;
}


x86 assembly (clang, -O0):
<get_distance_periodic_sqr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
movsd  %xmm6,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x50(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
call   1030 <round@plt>
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
call   1030 <round@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
call   1030 <round@plt>
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_distance_periodic_sqr>:
sub    $0x28,%rsp
movsd  %xmm6,0x10(%rsp)
subsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
subsd  %xmm4,%xmm1
movsd  %xmm1,0x8(%rsp)
subsd  %xmm5,%xmm2
movsd  %xmm2,0x20(%rsp)
divsd  %xmm6,%xmm0
call   1030 <round@plt>
movsd  0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm0
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  %xmm2,%xmm0
call   1030 <round@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm2
subsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1030 <round@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm2
subsd  %xmm0,%xmm2
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @get_distance_periodic_sqr(double %0, double %1, double %2, double %3, double %4, double %5, double %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca [3 x double]
%16 = alloca double
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double %5, double* %13
store double %6, double* %14
store double 0.000000e+00, double* %16
%17 = load double, double* %8
%18 = load double, double* %11
%19 = fsub double %17, %18
%20 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
store double %19, double* %20
%21 = load double, double* %9
%22 = load double, double* %12
%23 = fsub double %21, %22
%24 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 1
store double %23, double* %24
%25 = load double, double* %10
%26 = load double, double* %13
%27 = fsub double %25, %26
%28 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 2
store double %27, double* %28
%29 = load double, double* %14
%30 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%31 = load double, double* %30
%32 = load double, double* %14
%33 = fdiv double %31, %32
%34 = call double @llvm.round.f64(double %33)
%35 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%36 = load double, double* %35
%37 = fneg double %29
%38 = call double @llvm.fmuladd.f64(double %37, double %34, double %36)
store double %38, double* %35
%39 = load double, double* %14
%40 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 1
%41 = load double, double* %40
%42 = load double, double* %14
%43 = fdiv double %41, %42
%44 = call double @llvm.round.f64(double %43)
%45 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 1
%46 = load double, double* %45
%47 = fneg double %39
%48 = call double @llvm.fmuladd.f64(double %47, double %44, double %46)
store double %48, double* %45
%49 = load double, double* %14
%50 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 2
%51 = load double, double* %50
%52 = load double, double* %14
%53 = fdiv double %51, %52
%54 = call double @llvm.round.f64(double %53)
%55 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 2
%56 = load double, double* %55
%57 = fneg double %49
%58 = call double @llvm.fmuladd.f64(double %57, double %54, double %56)
store double %58, double* %55
%59 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%60 = load double, double* %59
%61 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 0
%62 = load double, double* %61
%63 = load double, double* %16
%64 = call double @llvm.fmuladd.f64(double %60, double %62, double %63)
store double %64, double* %16
%65 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 1
%66 = load double, double* %65
%67 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 1
%68 = load double, double* %67
%69 = load double, double* %16
%70 = call double @llvm.fmuladd.f64(double %66, double %68, double %69)
store double %70, double* %16
%71 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 2
%72 = load double, double* %71
%73 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 0, i64 2
%74 = load double, double* %73
%75 = load double, double* %16
%76 = call double @llvm.fmuladd.f64(double %72, double %74, double %75)
store double %76, double* %16
%77 = load double, double* %16
ret double %77
}

LLVM IR (-O2):
define double @get_distance_periodic_sqr(double %0, double %1, double %2, double %3, double %4, double %5, double %6) {
%8 = fsub double %0, %3
%9 = fsub double %1, %4
%10 = fsub double %2, %5
%11 = fdiv double %8, %6
%12 = tail call double @llvm.round.f64(double %11)
%13 = fneg double %6
%14 = tail call double @llvm.fmuladd.f64(double %13, double %12, double %8)
%15 = fdiv double %9, %6
%16 = tail call double @llvm.round.f64(double %15)
%17 = tail call double @llvm.fmuladd.f64(double %13, double %16, double %9)
%18 = fdiv double %10, %6
%19 = tail call double @llvm.round.f64(double %18)
%20 = tail call double @llvm.fmuladd.f64(double %13, double %19, double %10)
%21 = tail call double @llvm.fmuladd.f64(double %14, double %14, double 0.000000e+00)
%22 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %21)
%23 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %22)
ret double %23
}