#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 distance(double x1, double y1, double x2, double y2, double arena) {
  double X = x1 - x2;
  double Y = y1 - y2;
  if (X + arena / 2 < 0) {
    X += arena;
  }
  if (X - arena / 2 > 0) {
    X -= arena;
  }
  if (Y + arena / 2 < 0) {
    Y += arena;
  }
  if (Y - arena / 2 > 0) {
    Y -= arena;
  }
  return sqrt(X * X + Y * Y);
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1185 <distance+0x75>
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe69(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11bf <distance+0xaf>
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xe2f(%rip),%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11f5 <distance+0xe5>
movsd  -0x28(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xdf9(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    122f <distance+0x11f>
movsd  -0x28(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
movapd %xmm0,%xmm5
subsd  %xmm2,%xmm5
subsd  %xmm3,%xmm1
movsd  0xedc(%rip),%xmm3
mulsd  %xmm4,%xmm3
movapd %xmm5,%xmm0
addsd  %xmm3,%xmm0
xorpd  %xmm2,%xmm2
cmpltsd %xmm2,%xmm0
movapd %xmm0,%xmm6
andpd  %xmm4,%xmm6
movsd  0xebf(%rip),%xmm7
andnpd %xmm7,%xmm0
orpd   %xmm6,%xmm0
addsd  %xmm5,%xmm0
movapd %xmm0,%xmm5
subsd  %xmm3,%xmm5
xorpd  %xmm6,%xmm6
cmpltsd %xmm5,%xmm6
andpd  %xmm4,%xmm6
subsd  %xmm6,%xmm0
movapd %xmm1,%xmm5
addsd  %xmm3,%xmm5
cmpltsd %xmm2,%xmm5
movapd %xmm5,%xmm6
andpd  %xmm4,%xmm6
andnpd %xmm7,%xmm5
orpd   %xmm6,%xmm5
addsd  %xmm1,%xmm5
movapd %xmm5,%xmm1
subsd  %xmm3,%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm4,%xmm3
subsd  %xmm3,%xmm5
mulsd  %xmm5,%xmm5
mulsd  %xmm0,%xmm0
addsd  %xmm5,%xmm0
ucomisd %xmm2,%xmm0
jb     11bf <distance+0xaf>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
define double @distance(double %0, double %1, double %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double %4, double* %10
%13 = load double, double* %6
%14 = load double, double* %8
%15 = fsub double %13, %14
store double %15, double* %11
%16 = load double, double* %7
%17 = load double, double* %9
%18 = fsub double %16, %17
store double %18, double* %12
%19 = load double, double* %11
%20 = load double, double* %10
%21 = fdiv double %20, 2.000000e+00
%22 = fadd double %19, %21
%23 = fcmp olt double %22, 0.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %5
%25 = load double, double* %10
%26 = load double, double* %11
%27 = fadd double %26, %25
store double %27, double* %11
br label %28
28: ; preds = %24, %5
%29 = load double, double* %11
%30 = load double, double* %10
%31 = fdiv double %30, 2.000000e+00
%32 = fsub double %29, %31
%33 = fcmp ogt double %32, 0.000000e+00
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = load double, double* %10
%36 = load double, double* %11
%37 = fsub double %36, %35
store double %37, double* %11
br label %38
38: ; preds = %34, %28
%39 = load double, double* %12
%40 = load double, double* %10
%41 = fdiv double %40, 2.000000e+00
%42 = fadd double %39, %41
%43 = fcmp olt double %42, 0.000000e+00
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load double, double* %10
%46 = load double, double* %12
%47 = fadd double %46, %45
store double %47, double* %12
br label %48
48: ; preds = %44, %38
%49 = load double, double* %12
%50 = load double, double* %10
%51 = fdiv double %50, 2.000000e+00
%52 = fsub double %49, %51
%53 = fcmp ogt double %52, 0.000000e+00
br i1 %53, label %54, label %58
54: ; preds = %48
%55 = load double, double* %10
%56 = load double, double* %12
%57 = fsub double %56, %55
store double %57, double* %12
br label %58
58: ; preds = %54, %48
%59 = load double, double* %11
%60 = load double, double* %11
%61 = load double, double* %12
%62 = load double, double* %12
%63 = fmul double %61, %62
%64 = call double @llvm.fmuladd.f64(double %59, double %60, double %63)
%65 = call double @sqrt(double %64)
ret double %65
}

LLVM IR (-O2):
define double @distance(double %0, double %1, double %2, double %3, double %4) {
%6 = fsub double %0, %2
%7 = fsub double %1, %3
%8 = fmul double %4, 5.000000e-01
%9 = fadd double %6, %8
%10 = fcmp olt double %9, 0.000000e+00
%11 = select i1 %10, double %4, double -0.000000e+00
%12 = fadd double %6, %11
%13 = fsub double %12, %8
%14 = fcmp ogt double %13, 0.000000e+00
%15 = select i1 %14, double %4, double 0.000000e+00
%16 = fsub double %12, %15
%17 = fadd double %7, %8
%18 = fcmp olt double %17, 0.000000e+00
%19 = select i1 %18, double %4, double -0.000000e+00
%20 = fadd double %7, %19
%21 = fsub double %20, %8
%22 = fcmp ogt double %21, 0.000000e+00
%23 = select i1 %22, double %4, double 0.000000e+00
%24 = fsub double %20, %23
%25 = fmul double %24, %24
%26 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %25)
%27 = tail call double @sqrt(double %26)
ret double %27
}