#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 sqrt(double);
void grid_distances(double *center, double *points, double *distances, int n) {
  int i;
  double d, tmp;
  for (i = 0; i < n; i++) {
    d = *points - center[0];
    tmp = d * d;
    points++;
    d = *points - center[1];
    tmp += d * d;
    points++;
    d = *points - center[2];
    *distances = sqrt(tmp + d * d);
    points++;
    distances++;
  }
}


x86 assembly (clang, -O0):
<grid_distances>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1208 <grid_distances+0xf8>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <grid_distances+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_distances>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %ecx,%ecx
jle    119b <grid_distances+0x8b>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %ecx,%r12d
xor    %r13d,%r13d
xorpd  %xmm2,%xmm2
jmp    115c <grid_distances+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%r14,%r13,8)
add    $0x1,%r13
add    $0x18,%rbx
cmp    %r13d,%r12d
je     119b <grid_distances+0x8b>
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
subsd  (%r15),%xmm0
mulsd  %xmm0,%xmm0
subsd  0x8(%r15),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rbx),%xmm0
subsd  0x10(%r15),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1140 <grid_distances+0x30>
sqrtsd %xmm0,%xmm0
jmp    1149 <grid_distances+0x39>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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