#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 */
int sqrt(double);
int cor3(int r, double *x, double *y, double *z, int n) {
  int result = 0;
  int i, j;
  double dx, dy, dz;
  i = n;
  while (i-- > 0) {
    j = i;
    while (j-- > 0) {
      dx = (x[i] - x[j]);
      dy = (y[i] - y[j]);
      dz = (z[i] - z[j]);
      if (r > sqrt(dx * dx + dy * dy + dz * dz)) {
        result++;
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<cor3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x0,%eax
jle    121c <cor3+0x10c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x30(%rbp)
cmp    $0x0,%eax
jle    1217 <cor3+0x107>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x4c(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jle    1212 <cor3+0x102>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1152 <cor3+0x42>
jmp    1138 <cor3+0x28>
mov    -0x28(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cor3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
test   %r8d,%r8d
jle    1220 <cor3+0x110>
mov    %r8d,%r14d
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%r15d
lea    -0x2(%r14),%eax
mov    %r8d,%r9d
add    $0xffffffff,%r14d
xor    %r10d,%r10d
mov    %rcx,0x18(%rsp)
cs nopw 0x0(%rax,%rax,1)
cmp    $0x2,%r9
jb     1223 <cor3+0x113>
mov    %eax,0x4(%rsp)
mov    %eax,%eax
lea    (%rcx,%rax,8),%rbx
mov    %rbx,0x30(%rsp)
lea    (%r12,%rax,8),%rbp
mov    %rbp,0x28(%rsp)
lea    0x0(%r13,%rax,8),%rax
mov    %rax,0x20(%rsp)
mov    %r9,0x10(%rsp)
lea    -0x1(%r9),%rax
mov    %rax,0x8(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
movsd  0x0(%r13,%rax,8),%xmm1
mov    0x20(%rsp),%rbp
subsd  0x0(%rbp,%rbx,8),%xmm1
movsd  (%r12,%rax,8),%xmm2
mov    0x28(%rsp),%rbp
subsd  0x0(%rbp,%rbx,8),%xmm2
movsd  (%rcx,%rax,8),%xmm0
mov    0x30(%rsp),%rax
subsd  (%rax,%rbx,8),%xmm0
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    %r10,%rbp
call   1030 <sqrt@plt>
mov    %rbp,%r10
xor    %ecx,%ecx
cmp    %r15d,%eax
setl   %cl
add    %ecx,%r10d
mov    0x18(%rsp),%rcx
add    $0xffffffffffffffff,%rbx
lea    (%rbx,%r14,1),%eax
test   %eax,%eax
jg     1190 <cor3+0x80>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
add    $0xffffffffffffffff,%r14
cmpq   $0x2,0x10(%rsp)
mov    0x8(%rsp),%r9
jae    1150 <cor3+0x40>
jmp    1223 <cor3+0x113>
xor    %r10d,%r10d
mov    %r10d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cor3(i32 %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32 %0, i32* %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
store i32 0, i32* %11
%17 = load i32, i32* %10
store i32 %17, i32* %12
br label %18
18: ; preds = %78, %5
%19 = load i32, i32* %12
%20 = add nsw i32 %19, -1
store i32 %20, i32* %12
%21 = icmp sgt i32 %19, 0
br i1 %21, label %22, label %79
22: ; preds = %18
%23 = load i32, i32* %12
store i32 %23, i32* %13
br label %24
24: ; preds = %77, %22
%25 = load i32, i32* %13
%26 = add nsw i32 %25, -1
store i32 %26, i32* %13
%27 = icmp sgt i32 %25, 0
br i1 %27, label %28, label %78
28: ; preds = %24
%29 = load double*, double** %7
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %7
%35 = load i32, i32* %13
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = fsub double %33, %38
store double %39, double* %14
%40 = load double*, double** %8
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double*, double** %8
%46 = load i32, i32* %13
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = fsub double %44, %49
store double %50, double* %15
%51 = load double*, double** %9
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double, double* %54
%56 = load double*, double** %9
%57 = load i32, i32* %13
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = fsub double %55, %60
store double %61, double* %16
%62 = load i32, i32* %6
%63 = load double, double* %14
%64 = load double, double* %14
%65 = load double, double* %15
%66 = load double, double* %15
%67 = fmul double %65, %66
%68 = call double @llvm.fmuladd.f64(double %63, double %64, double %67)
%69 = load double, double* %16
%70 = load double, double* %16
%71 = call double @llvm.fmuladd.f64(double %69, double %70, double %68)
%72 = call i32 @sqrt(double %71)
%73 = icmp sgt i32 %62, %72
br i1 %73, label %74, label %77
74: ; preds = %28
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
br label %77
77: ; preds = %74, %28
br label %24
78: ; preds = %24
br label %18
79: ; preds = %18
%80 = load i32, i32* %11
ret i32 %80
}

LLVM IR (-O2):
define i32 @cor3(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4) {
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %48
7: ; preds = %5
%8 = add nsw i32 %4, -2
%9 = zext i32 %4 to i64
br label %12
10: ; preds = %23
%11 = add i32 %14, -1
br i1 %17, label %12, label %48
12: ; preds = %7, %10
%13 = phi i64 [ %9, %7 ], [ %16, %10 ]
%14 = phi i32 [ %8, %7 ], [ %11, %10 ]
%15 = phi i32 [ 0, %7 ], [ %44, %10 ]
%16 = add nsw i64 %13, -1
%17 = icmp ugt i64 %13, 1
br i1 %17, label %18, label %48
18: ; preds = %12
%19 = zext i32 %14 to i64
%20 = getelementptr inbounds double, double* %1, i64 %16
%21 = getelementptr inbounds double, double* %2, i64 %16
%22 = getelementptr inbounds double, double* %3, i64 %16
br label %23
23: ; preds = %18, %23
%24 = phi i64 [ %19, %18 ], [ %45, %23 ]
%25 = phi i32 [ %15, %18 ], [ %44, %23 ]
%26 = load double, double* %20
%27 = getelementptr inbounds double, double* %1, i64 %24
%28 = load double, double* %27
%29 = fsub double %26, %28
%30 = load double, double* %21
%31 = getelementptr inbounds double, double* %2, i64 %24
%32 = load double, double* %31
%33 = fsub double %30, %32
%34 = load double, double* %22
%35 = getelementptr inbounds double, double* %3, i64 %24
%36 = load double, double* %35
%37 = fsub double %34, %36
%38 = fmul double %33, %33
%39 = tail call double @llvm.fmuladd.f64(double %29, double %29, double %38)
%40 = tail call double @llvm.fmuladd.f64(double %37, double %37, double %39)
%41 = tail call i32 @sqrt(double %40)
%42 = icmp slt i32 %41, %0
%43 = zext i1 %42 to i32
%44 = add nsw i32 %25, %43
%45 = add nsw i64 %24, -1
%46 = trunc i64 %24 to i32
%47 = icmp sgt i32 %46, 0
br i1 %47, label %23, label %10
48: ; preds = %10, %12, %5
%49 = phi i32 [ 0, %5 ], [ %15, %12 ], [ %44, %10 ]
ret i32 %49
}