#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 fabs(double);
int cor(int r, double *x, int n) {
  int result = 0;
  int i, j;
  double dx;
  i = n;
  while (i-- > 0) {
    j = i;
    while (j-- > 0) {
      dx = x[i] - x[j];
      if (r > fabs(dx)) {
        result++;
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<cor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11ac <cor+0x9c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
jle    11a7 <cor+0x97>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jle    11a2 <cor+0x92>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <cor+0x39>
jmp    112f <cor+0x1f>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    11b0 <cor+0xa0>
mov    %rsi,%rbx
mov    %edi,%r15d
lea    -0x2(%rdx),%eax
mov    %edx,%r13d
add    $0xffffffff,%edx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cmp    $0x2,%r13
jb     11b2 <cor+0xa2>
mov    %eax,0x4(%rsp)
mov    %eax,%eax
lea    (%rbx,%rax,8),%r14
mov    %r13,0x8(%rsp)
add    $0xffffffffffffffff,%r13
mov    %rdx,0x10(%rsp)
mov    %edx,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%r13,8),%xmm0
subsd  (%r14),%xmm0
call   1030 <fabs@plt>
xor    %ecx,%ecx
cmp    %r15d,%eax
setl   %cl
add    %ecx,%ebp
add    $0xffffffff,%r12d
add    $0xfffffffffffffff8,%r14
test   %r12d,%r12d
jg     1170 <cor+0x60>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
mov    0x10(%rsp),%rdx
add    $0xffffffff,%edx
cmpq   $0x2,0x8(%rsp)
jae    1140 <cor+0x30>
jmp    11b2 <cor+0xa2>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cor(i32 %0, double* %1, i32 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %6
store i32 %11, i32* %8
br label %12
12: ; preds = %42, %3
%13 = load i32, i32* %8
%14 = add nsw i32 %13, -1
store i32 %14, i32* %8
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %43
16: ; preds = %12
%17 = load i32, i32* %8
store i32 %17, i32* %9
br label %18
18: ; preds = %41, %16
%19 = load i32, i32* %9
%20 = add nsw i32 %19, -1
store i32 %20, i32* %9
%21 = icmp sgt i32 %19, 0
br i1 %21, label %22, label %42
22: ; preds = %18
%23 = load double*, double** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %5
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fsub double %27, %32
store double %33, double* %10
%34 = load i32, i32* %4
%35 = load double, double* %10
%36 = call i32 @fabs(double %35)
%37 = icmp sgt i32 %34, %36
br i1 %37, label %38, label %41
38: ; preds = %22
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %41
41: ; preds = %38, %22
br label %18
42: ; preds = %18
br label %12
43: ; preds = %12
%44 = load i32, i32* %7
ret i32 %44
}

LLVM IR (-O2):
define i32 @cor(i32 %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %33
5: ; preds = %3
%6 = add nsw i32 %2, -2
%7 = zext i32 %2 to i64
br label %10
8: ; preds = %19
%9 = add i32 %12, -1
br i1 %15, label %10, label %33
10: ; preds = %5, %8
%11 = phi i64 [ %7, %5 ], [ %14, %8 ]
%12 = phi i32 [ %6, %5 ], [ %9, %8 ]
%13 = phi i32 [ 0, %5 ], [ %29, %8 ]
%14 = add nsw i64 %11, -1
%15 = icmp ugt i64 %11, 1
br i1 %15, label %16, label %33
16: ; preds = %10
%17 = zext i32 %12 to i64
%18 = getelementptr inbounds double, double* %1, i64 %14
br label %19
19: ; preds = %16, %19
%20 = phi i64 [ %17, %16 ], [ %30, %19 ]
%21 = phi i32 [ %13, %16 ], [ %29, %19 ]
%22 = load double, double* %18
%23 = getelementptr inbounds double, double* %1, i64 %20
%24 = load double, double* %23
%25 = fsub double %22, %24
%26 = tail call i32 @fabs(double %25)
%27 = icmp slt i32 %26, %0
%28 = zext i1 %27 to i32
%29 = add nsw i32 %21, %28
%30 = add nsw i64 %20, -1
%31 = trunc i64 %20 to i32
%32 = icmp sgt i32 %31, 0
br i1 %32, label %19, label %8
33: ; preds = %8, %10, %3
%34 = phi i32 [ 0, %3 ], [ %13, %10 ], [ %29, %8 ]
ret i32 %34
}