void dir_and_dist(double a[3], double b[3], double dir[3], double *dist) {
  int k;
  for (k = 0; k < 3; k++)
    dir[k] = b[k] - a[k];
  *dist = sqrt(((dir[0]) * (dir[0])) + ((dir[1]) * (dir[1])) +
               ((dir[2]) * (dir[2])));
  for (k = 0; k < 3; k++)
    dir[k] = dir[k] / (*dist);
}


x86 assembly (clang, -O0):
<dir_and_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    116e <dir_and_dist+0x5e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112f <dir_and_dist+0x1f>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1200 <dir_and_dist+0xf0>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
divsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c6 <dir_and_dist+0xb6>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_and_dist>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
movsd  (%rsi),%xmm1
subsd  (%rdi),%xmm1
movsd  %xmm1,(%rdx)
movsd  0x8(%rsi),%xmm2
subsd  0x8(%rdi),%xmm2
movsd  %xmm2,0x8(%rdx)
movsd  0x10(%rsi),%xmm0
subsd  0x10(%rdi),%xmm0
movsd  %xmm0,0x10(%rdx)
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1168 <dir_and_dist+0x58>
sqrtsd %xmm0,%xmm0
jmp    116d <dir_and_dist+0x5d>
call   1030 <sqrt@plt>
movsd  %xmm0,(%r14)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm2
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
divsd  (%r14),%xmm2
movsd  %xmm2,0x8(%rbx)
movsd  0x10(%rbx),%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x10(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @dir_and_dist(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3) {
%5 = load double, double* %1
%6 = load double, double* %0
%7 = fsub double %5, %6
store double %7, double* %2
%8 = getelementptr inbounds double, double* %1, i64 1
%9 = load double, double* %8
%10 = getelementptr inbounds double, double* %0, i64 1
%11 = load double, double* %10
%12 = fsub double %9, %11
%13 = getelementptr inbounds double, double* %2, i64 1
store double %12, double* %13
%14 = getelementptr inbounds double, double* %1, i64 2
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %0, i64 2
%17 = load double, double* %16
%18 = fsub double %15, %17
%19 = getelementptr inbounds double, double* %2, i64 2
store double %18, double* %19
%20 = fmul double %12, %12
%21 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %20)
%22 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %21)
%23 = tail call double @sqrt(double %22)
store double %23, double* %3
%24 = load double, double* %2
%25 = fdiv double %24, %23
store double %25, double* %2
%26 = load double, double* %13
%27 = load double, double* %3
%28 = fdiv double %26, %27
store double %28, double* %13
%29 = load double, double* %19
%30 = load double, double* %3
%31 = fdiv double %29, %30
store double %31, double* %19
ret void
}