#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 distance(double *x, double *y, double *z, double *d, int n) {
  for (int i = 0; i < n; i++) {
    d[i] = sqrt(x[i] * x[i] + y[i] * y[i] + z[i] * z[i]);
  }
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11bd <distance+0xad>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1133 <distance+0x23>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %r8d,%r8d
jle    1246 <distance+0x136>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %r8d,%ebp
cmp    $0x1,%r8d
mov    %rbp,(%rsp)
jne    1187 <distance+0x77>
xor    %ebx,%ebx
testb  $0x1,(%rsp)
je     1246 <distance+0x136>
movsd  0x0(%r13,%rbx,8),%xmm1
movsd  (%r12,%rbx,8),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  (%r15,%rbx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     123b <distance+0x12b>
sqrtsd %xmm0,%xmm0
jmp    1240 <distance+0x130>
and    $0xfffffffe,%ebp
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
jmp    11b9 <distance+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x8(%r14,%rbx,8)
add    $0x2,%rbx
cmp    %rbx,%rbp
je     113f <distance+0x2f>
movsd  0x0(%r13,%rbx,8),%xmm1
movsd  (%r12,%rbx,8),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  (%r15,%rbx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     11f0 <distance+0xe0>
sqrtsd %xmm0,%xmm0
jmp    11f9 <distance+0xe9>
nopl   0x0(%rax)
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  %xmm0,(%r14,%rbx,8)
movsd  0x8(%r13,%rbx,8),%xmm1
movsd  0x8(%r12,%rbx,8),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%r15,%rbx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     11a0 <distance+0x90>
sqrtsd %xmm0,%xmm0
jmp    11a9 <distance+0x99>
call   1030 <sqrt@plt>
movsd  %xmm0,(%r14,%rbx,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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