#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 distance(double *, int, int, int);
extern void _get_distances(double *points, int npoints, int ndim,
                           double *distances) {
  int i, j, o;
  for (i = 0; i < npoints - 1; ++i) {
    o = i * npoints;
    for (j = i + 1; j < npoints; ++j) {
      distances[o + j] = distance(points, i, j, ndim);
      distances[j * npoints + i] = distances[o + j];
    }
  }
}


x86 assembly (clang, -O0):
<_get_distances>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ca <_get_distances+0xba>
mov    -0x1c(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b7 <_get_distances+0xa7>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <distance@plt>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1151 <_get_distances+0x41>
jmp    11bc <_get_distances+0xac>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <_get_distances+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_distances>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x2,%esi
jl     11f7 <_get_distances+0xe7>
mov    %rcx,%rbp
mov    %edx,%r13d
mov    %rdi,%rbx
mov    %rsi,%rax
mov    %eax,%edx
add    $0xffffffff,%eax
mov    %rax,0x30(%rsp)
lea    (%rcx,%rdx,8),%rax
mov    %rax,0x8(%rsp)
lea    0x0(,%rdx,8),%r14
lea    0x8(,%rdx,8),%rax
mov    %rax,0x20(%rsp)
mov    %rdx,0x28(%rsp)
neg    %rdx
mov    %rdx,0x18(%rsp)
xor    %eax,%eax
jmp    1189 <_get_distances+0x79>
nopl   0x0(%rax)
mov    0x20(%rsp),%rax
add    %rax,0x8(%rsp)
add    %rax,%rbp
mov    0x38(%rsp),%rax
cmp    0x30(%rsp),%rax
je     11f7 <_get_distances+0xe7>
mov    %rax,%rdx
mov    %rax,0x10(%rsp)
add    $0x1,%rax
mov    %rax,0x38(%rsp)
cmp    0x28(%rsp),%rax
jae    1170 <_get_distances+0x60>
mov    0x18(%rsp),%rax
mov    0x10(%rsp),%rdx
add    %rdx,%rax
mov    %rax,0x40(%rsp)
mov    $0x1,%r15d
mov    0x8(%rsp),%r12
xchg   %ax,%ax
mov    0x10(%rsp),%rsi
lea    (%rsi,%r15,1),%edx
mov    %rbx,%rdi
mov    %r13d,%ecx
call   1030 <distance@plt>
movsd  %xmm0,0x0(%rbp,%r15,8)
movsd  %xmm0,(%r12)
add    %r14,%r12
add    $0x1,%r15
mov    0x40(%rsp),%rax
add    %r15,%rax
jne    11c0 <_get_distances+0xb0>
jmp    1170 <_get_distances+0x60>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @_get_distances(double* %0, i32 %1, i32 %2, double* nocapture writeonly %3) {
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %33
6: ; preds = %4
%7 = add nsw i32 %1, -1
%8 = zext i32 %1 to i64
%9 = zext i32 %7 to i64
%10 = zext i32 %1 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 %33, 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 = trunc i64 %15 to i32
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ %16, %20 ], [ %31, %22 ]
%24 = trunc i64 %23 to i32
%25 = tail call double @distance(double* %0, i32 %21, i32 %24, i32 %2)
%26 = add nuw nsw i64 %23, %17
%27 = getelementptr inbounds double, double* %3, i64 %26
store double %25, double* %27
%28 = mul nsw i64 %23, %8
%29 = add nuw nsw i64 %28, %15
%30 = getelementptr inbounds double, double* %3, i64 %29
store double %25, double* %30
%31 = add nuw nsw i64 %23, 1
%32 = icmp eq i64 %31, %10
br i1 %32, label %11, label %22
33: ; preds = %11, %4
ret void
}