#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 glmComputeDistance3d(double const *, double *);
double glmDotProduct3d(double const *, double *);
int /*<<< orphan*/ glmMakeVector3d(double *, double const *, double const *);
double glmComputeDistanceToLine3d(const double lineOrigin[3],
                                  const double lineDirection[3],
                                  const double p[3]) {
  double c[3], temp[3];
  double t;
  glmMakeVector3d(c, lineOrigin, p);
  t = glmDotProduct3d(lineDirection, c);
  temp[0] = lineOrigin[0] + t * lineDirection[0];
  temp[1] = lineOrigin[1] + t * lineDirection[1];
  temp[2] = lineOrigin[2] + t * lineDirection[2];
  return glmComputeDistance3d(p, temp);
}


x86 assembly (clang, -O0):
<glmComputeDistanceToLine3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <glmMakeVector3d@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <glmDotProduct3d@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
movsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <glmComputeDistance3d@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmComputeDistanceToLine3d>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <glmMakeVector3d@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <glmDotProduct3d@plt>
movupd (%r15),%xmm1
movupd (%rbx),%xmm2
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
mulpd  %xmm2,%xmm3
addpd  %xmm1,%xmm3
movapd %xmm3,(%rsp)
mulsd  0x10(%rbx),%xmm0
addsd  0x10(%r15),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <glmComputeDistance3d@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @glmComputeDistanceToLine3d(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca [3 x double]
%8 = alloca [3 x double]
%9 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%10 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%11 = load double*, double** %4
%12 = load double*, double** %6
%13 = call i32 @glmMakeVector3d(double* %10, double* %11, double* %12)
%14 = load double*, double** %5
%15 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%16 = call double @glmDotProduct3d(double* %14, double* %15)
store double %16, double* %9
%17 = load double*, double** %4
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load double, double* %18
%20 = load double, double* %9
%21 = load double*, double** %5
%22 = getelementptr inbounds double, double* %21, i64 0
%23 = load double, double* %22
%24 = call double @llvm.fmuladd.f64(double %20, double %23, double %19)
%25 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
store double %24, double* %25
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i64 1
%28 = load double, double* %27
%29 = load double, double* %9
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
%33 = call double @llvm.fmuladd.f64(double %29, double %32, double %28)
%34 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 1
store double %33, double* %34
%35 = load double*, double** %4
%36 = getelementptr inbounds double, double* %35, i64 2
%37 = load double, double* %36
%38 = load double, double* %9
%39 = load double*, double** %5
%40 = getelementptr inbounds double, double* %39, i64 2
%41 = load double, double* %40
%42 = call double @llvm.fmuladd.f64(double %38, double %41, double %37)
%43 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
store double %42, double* %43
%44 = load double*, double** %6
%45 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%46 = call double @glmComputeDistance3d(double* %44, double* %45)
ret double %46
}

LLVM IR (-O2):
define double @glmComputeDistanceToLine3d(double* %0, double* %1, double* %2) {
%4 = alloca [3 x double]
%5 = alloca [3 x double]
%6 = bitcast [3 x double]* %4 to i8*
%7 = bitcast [3 x double]* %5 to i8*
%8 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%9 = call i32 @glmMakeVector3d(double* %8, double* %0, double* %2)
%10 = call double @glmDotProduct3d(double* %1, double* %8)
%11 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%12 = bitcast double* %0 to <2 x double>*
%13 = load <2 x double>, <2 x double>* %12
%14 = bitcast double* %1 to <2 x double>*
%15 = load <2 x double>, <2 x double>* %14
%16 = insertelement <2 x double> poison, double %10, i64 0
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
%18 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %17, <2 x double> %15, <2 x double> %13)
%19 = bitcast [3 x double]* %5 to <2 x double>*
store <2 x double> %18, <2 x double>* %19
%20 = getelementptr inbounds double, double* %0, i64 2
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %1, i64 2
%23 = load double, double* %22
%24 = call double @llvm.fmuladd.f64(double %10, double %23, double %21)
%25 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
store double %24, double* %25
%26 = call double @glmComputeDistance3d(double* %2, double* %11)
ret double %26
}