#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 dist(double, double, double, double, double, double);
scalar_t__ malloc(int);
double *create_unit_vector(double *head_pos, double *tail_pos) {
  double *unit_vec = (double *)malloc(3 * sizeof(double));
  double length = dist(head_pos[0], head_pos[1], head_pos[2], tail_pos[0],
                       tail_pos[1], tail_pos[2]);
  unit_vec[0] = (head_pos[0] - tail_pos[0]) / length;
  unit_vec[1] = (head_pos[1] - tail_pos[1]) / length;
  unit_vec[2] = (head_pos[2] - tail_pos[2]) / length;
  return unit_vec;
}


x86 assembly (clang, -O0):
<create_unit_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x18,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm3
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm4
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm5
call   1040 <dist@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_unit_vector>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x18,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
movsd  0x10(%rbx),%xmm2
movsd  (%r14),%xmm3
movsd  0x8(%r14),%xmm4
movsd  0x10(%r14),%xmm5
call   1040 <dist@plt>
movsd  (%rbx),%xmm1
subsd  (%r14),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r15)
movsd  0x8(%rbx),%xmm1
subsd  0x8(%r14),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%r15)
movsd  0x10(%rbx),%xmm1
subsd  0x10(%r14),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%r15)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double* @create_unit_vector(double* nocapture %0, double* nocapture %1) {
%3 = tail call i64 @malloc(i32 24)
%4 = inttoptr i64 %3 to double*
%5 = load double, double* %0
%6 = getelementptr inbounds double, double* %0, i64 1
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = load double, double* %1
%11 = getelementptr inbounds double, double* %1, i64 1
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %1, i64 2
%14 = load double, double* %13
%15 = tail call double @dist(double %5, double %7, double %9, double %10, double %12, double %14)
%16 = load double, double* %0
%17 = load double, double* %1
%18 = fsub double %16, %17
%19 = fdiv double %18, %15
store double %19, double* %4
%20 = load double, double* %6
%21 = load double, double* %11
%22 = fsub double %20, %21
%23 = fdiv double %22, %15
%24 = getelementptr inbounds double, double* %4, i64 1
store double %23, double* %24
%25 = load double, double* %8
%26 = load double, double* %13
%27 = fsub double %25, %26
%28 = fdiv double %27, %15
%29 = getelementptr inbounds double, double* %4, i64 2
store double %28, double* %29
ret double* %4
}