#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 */
int /*<<< orphan*/ matCalcCross(double *, double *, double *);
double matCalcLen(double *);
double matCalcDistancePointToLine(double *l0, double *l1, double *p) {
  int i;
  double diff1[3], diff2[3], cross[3];
  for (i = 0; i < 3; i++) {
    diff1[i] = l1[i] - l0[i];
    diff2[i] = p[i] - l0[i];
  }
  matCalcCross(diff1, diff2, cross);
  return matCalcLen(cross) / matCalcLen(diff1);
}


x86 assembly (clang, -O0):
<matCalcDistancePointToLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    119e <matCalcDistancePointToLine+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movslq -0x1c(%rbp),%rax
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movslq -0x1c(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <matCalcDistancePointToLine+0x1e>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1030 <matCalcCross@plt>
lea    -0x80(%rbp),%rdi
call   1040 <matCalcLen@plt>
movsd  %xmm0,-0x88(%rbp)
ff
lea    -0x40(%rbp),%rdi
call   1040 <matCalcLen@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matCalcDistancePointToLine>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movupd (%rdi),%xmm0
movupd (%rsi),%xmm1
subpd  %xmm0,%xmm1
movapd %xmm1,0x30(%rsp)
movupd (%rdx),%xmm1
subpd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
movsd  0x10(%rsi),%xmm0
movsd  0x10(%rdi),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  0x10(%rdx),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0x30(%rsp),%r14
lea    0x10(%rsp),%rsi
lea    0x50(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <matCalcCross@plt>
mov    %rbx,%rdi
call   1040 <matCalcLen@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1040 <matCalcLen@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define double @matCalcDistancePointToLine(double* nocapture %0, double* nocapture %1, double* nocapture %2) {
%4 = alloca [3 x double]
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = bitcast [3 x double]* %4 to i8*
%8 = bitcast [3 x double]* %5 to i8*
%9 = bitcast [3 x double]* %6 to i8*
%10 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%11 = bitcast double* %0 to <2 x double>*
%12 = load <2 x double>, <2 x double>* %11
%13 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%14 = bitcast double* %1 to <2 x double>*
%15 = load <2 x double>, <2 x double>* %14
%16 = fsub <2 x double> %15, %12
%17 = bitcast [3 x double]* %4 to <2 x double>*
store <2 x double> %16, <2 x double>* %17
%18 = bitcast double* %2 to <2 x double>*
%19 = load <2 x double>, <2 x double>* %18
%20 = fsub <2 x double> %19, %12
%21 = bitcast [3 x double]* %5 to <2 x double>*
store <2 x double> %20, <2 x double>* %21
%22 = getelementptr inbounds double, double* %1, i64 2
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %0, i64 2
%25 = load double, double* %24
%26 = fsub double %23, %25
%27 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
store double %26, double* %27
%28 = getelementptr inbounds double, double* %2, i64 2
%29 = load double, double* %28
%30 = fsub double %29, %25
%31 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
store double %30, double* %31
%32 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%33 = call i32 @matCalcCross(double* %10, double* %13, double* %32)
%34 = call double @matCalcLen(double* %32)
%35 = call double @matCalcLen(double* %10)
%36 = fdiv double %34, %35
ret double %36
}