#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 */
float sqrtf(float);
void calc_distance(long num_points, float x[], float y[], float z[],
                   float distance[][32]) {
  long i, j;
  float xdiff, ydiff, zdiff;
  for (i = 0; i < num_points; i++)
    for (j = 0; j < num_points; j++) {
      xdiff = x[j] - x[i];
      ydiff = y[j] - y[i];
      zdiff = z[j] - z[i];
      distance[i][j] = sqrtf(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
    }
}


x86 assembly (clang, -O0):
<calc_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    1227 <calc_distance+0x117>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    1211 <calc_distance+0x101>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
subss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x3c(%rbp),%xmm1
movss  -0x3c(%rbp),%xmm2
movss  -0x40(%rbp),%xmm0
mulss  -0x40(%rbp),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x44(%rbp),%xmm0
movss  -0x44(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrtf@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x7,%rcx
add    %rcx,%rax
mov    -0x38(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    114a <calc_distance+0x3a>
jmp    1216 <calc_distance+0x106>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1134 <calc_distance+0x24>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_distance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
jle    11c0 <calc_distance+0xb0>
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%rbp
xor    %r14d,%r14d
xorps  %xmm3,%xmm3
mov    %rdi,(%rsp)
jmp    114d <calc_distance+0x3d>
nopl   0x0(%rax)
add    $0x1,%r14
sub    $0xffffffffffffff80,%r15
cmp    %rdi,%r14
je     11c0 <calc_distance+0xb0>
xor    %r13d,%r13d
jmp    117b <calc_distance+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <sqrtf@plt>
xorps  %xmm3,%xmm3
mov    (%rsp),%rdi
movss  %xmm0,(%r15,%r13,4)
add    $0x1,%r13
cmp    %r13,%rdi
je     1140 <calc_distance+0x30>
movss  0x0(%rbp,%r13,4),%xmm1
subss  0x0(%rbp,%r14,4),%xmm1
movss  (%rbx,%r13,4),%xmm2
subss  (%rbx,%r14,4),%xmm2
movss  (%r12,%r13,4),%xmm0
subss  (%r12,%r14,4),%xmm0
mulss  %xmm2,%xmm2
mulss  %xmm1,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss %xmm3,%xmm0
jb     1160 <calc_distance+0x50>
sqrtss %xmm0,%xmm0
jmp    116c <calc_distance+0x5c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @calc_distance(i64 %0, float* nocapture %1, float* nocapture %2, float* nocapture %3, [32 x float]* nocapture writeonly %4) {
%6 = icmp sgt i64 %0, 0
br i1 %6, label %7, label %36
7: ; preds = %5, %33
%8 = phi i64 [ %34, %33 ], [ 0, %5 ]
%9 = getelementptr inbounds float, float* %1, i64 %8
%10 = getelementptr inbounds float, float* %2, i64 %8
%11 = getelementptr inbounds float, float* %3, i64 %8
br label %12
12: ; preds = %7, %12
%13 = phi i64 [ 0, %7 ], [ %31, %12 ]
%14 = getelementptr inbounds float, float* %1, i64 %13
%15 = load float, float* %14
%16 = load float, float* %9
%17 = fsub float %15, %16
%18 = getelementptr inbounds float, float* %2, i64 %13
%19 = load float, float* %18
%20 = load float, float* %10
%21 = fsub float %19, %20
%22 = getelementptr inbounds float, float* %3, i64 %13
%23 = load float, float* %22
%24 = load float, float* %11
%25 = fsub float %23, %24
%26 = fmul float %21, %21
%27 = tail call float @llvm.fmuladd.f32(float %17, float %17, float %26)
%28 = tail call float @llvm.fmuladd.f32(float %25, float %25, float %27)
%29 = tail call float @sqrtf(float %28)
%30 = getelementptr inbounds [32 x float], [32 x float]* %4, i64 %8, i64 %13
store float %29, float* %30
%31 = add nuw nsw i64 %13, 1
%32 = icmp eq i64 %31, %0
br i1 %32, label %33, label %12
33: ; preds = %12
%34 = add nuw nsw i64 %8, 1
%35 = icmp eq i64 %34, %0
br i1 %35, label %36, label %7
36: ; preds = %33, %5
ret void
}