#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 exp(int /*<<< orphan*/);
int /*<<< orphan*/ sqr(double);
extern void _get_density(double kernel_size, double *distances, int npoints,
                         double *density) {
  int i, j, o;
  double rho;
  for (i = 0; i < npoints - 1; ++i) {
    o = i * npoints;
    for (j = i + 1; j < npoints; ++j) {
      rho = exp(-sqr(distances[o + j] / kernel_size));
      density[i] += rho;
      density[j] += rho;
    }
  }
}


x86 assembly (clang, -O0):
<_get_density>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e8 <_get_density+0xc8>
mov    -0x24(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d5 <_get_density+0xb5>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1030 <sqr@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1040 <exp@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1163 <_get_density+0x43>
jmp    11da <_get_density+0xba>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113f <_get_density+0x1f>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_density>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%esi
jl     11e7 <_get_density+0xc7>
mov    %rdx,%r13
mov    %rdi,%r15
movapd %xmm0,%xmm1
mov    %rsi,%rax
mov    %eax,%ebp
add    $0xffffffff,%eax
mov    %rax,0x10(%rsp)
lea    0x8(,%rbp,8),%rax
mov    %rax,(%rsp)
xor    %r12d,%r12d
mov    %rbp,0x8(%rsp)
mov    %rdx,%rbx
movsd  %xmm0,0x20(%rsp)
jmp    1188 <_get_density+0x68>
nopl   (%rax)
add    (%rsp),%r15
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
mov    0x18(%rsp),%r12
cmp    0x10(%rsp),%r12
je     11e7 <_get_density+0xc7>
lea    0x1(%r12),%rax
mov    %rax,0x18(%rsp)
cmp    0x8(%rsp),%rax
jae    1170 <_get_density+0x50>
mov    $0x1,%r14d
nop
movsd  (%r15,%r14,8),%xmm0
divsd  %xmm1,%xmm0
call   1030 <sqr@plt>
neg    %eax
mov    %eax,%edi
call   1040 <exp@plt>
movsd  0x0(%r13,%r12,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13,%r12,8)
movsd  0x20(%rsp),%xmm1
addsd  (%rbx,%r14,8),%xmm0
movsd  %xmm0,(%rbx,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbp
jne    11a0 <_get_density+0x80>
jmp    1170 <_get_density+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_get_density(double %0, double* %1, i32 %2, double* %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store double %0, double* %5
store double* %1, double** %6
store i32 %2, i32* %7
store double* %3, double** %8
store i32 0, i32* %9
br label %13
13: ; preds = %59, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %7
%16 = sub nsw i32 %15, 1
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %62
18: ; preds = %13
%19 = load i32, i32* %9
%20 = load i32, i32* %7
%21 = mul nsw i32 %19, %20
store i32 %21, i32* %11
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %10
br label %24
24: ; preds = %55, %18
%25 = load i32, i32* %10
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %58
28: ; preds = %24
%29 = load double*, double** %6
%30 = load i32, i32* %11
%31 = load i32, i32* %10
%32 = add nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %29, i64 %33
%35 = load double, double* %34
%36 = load double, double* %5
%37 = fdiv double %35, %36
%38 = call i32 @sqr(double %37)
%39 = sub nsw i32 0, %38
%40 = call double @exp(i32 %39)
store double %40, double* %12
%41 = load double, double* %12
%42 = load double*, double** %8
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = fadd double %46, %41
store double %47, double* %45
%48 = load double, double* %12
%49 = load double*, double** %8
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = fadd double %53, %48
store double %54, double* %52
br label %55
55: ; preds = %28
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %24
58: ; preds = %24
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %13
62: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @_get_density(double %0, double* nocapture %1, i32 %2, double* nocapture %3) {
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %38
6: ; preds = %4
%7 = add nsw i32 %2, -1
%8 = zext i32 %2 to i64
%9 = zext i32 %7 to i64
%10 = zext i32 %2 to i64
br label %14
11: ; preds = %22, %14
%12 = add nuw nsw i64 %16, 1
%13 = icmp eq i64 %18, %9
br i1 %13, label %38, label %14
14: ; preds = %6, %11
%15 = phi i64 [ 0, %6 ], [ %18, %11 ]
%16 = phi i64 [ 1, %6 ], [ %12, %11 ]
%17 = mul nsw i64 %15, %8
%18 = add nuw nsw i64 %15, 1
%19 = icmp ult i64 %18, %8
br i1 %19, label %20, label %11
20: ; preds = %14
%21 = getelementptr inbounds double, double* %3, i64 %15
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ %16, %20 ], [ %36, %22 ]
%24 = add nuw nsw i64 %23, %17
%25 = getelementptr inbounds double, double* %1, i64 %24
%26 = load double, double* %25
%27 = fdiv double %26, %0
%28 = tail call i32 @sqr(double %27)
%29 = sub nsw i32 0, %28
%30 = tail call double @exp(i32 %29)
%31 = load double, double* %21
%32 = fadd double %30, %31
store double %32, double* %21
%33 = getelementptr inbounds double, double* %3, i64 %23
%34 = load double, double* %33
%35 = fadd double %30, %34
store double %35, double* %33
%36 = add nuw nsw i64 %23, 1
%37 = icmp eq i64 %36, %10
br i1 %37, label %11, label %22
38: ; preds = %11, %4
ret void
}