#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*/ crossvv(double *, double *, double *);
scalar_t__ dotvv(double *, double *);
int /*<<< orphan*/ mulvf(double *, int);
double sqrt(scalar_t__);
int /*<<< orphan*/ subvv(double *, double *, double *);
double ptlined(double *A, double *B, double *P) {
  double vtmp[3], vtmp2[3], vtmp3[3];
  double l;
  subvv(vtmp, P, B);
  subvv(vtmp2, A, B);
  if (dotvv(vtmp, vtmp2) <= 0) {
    l = sqrt(dotvv(vtmp, vtmp));
  } else {
    mulvf(vtmp2, -1);
    subvv(vtmp, P, A);
    if (dotvv(vtmp, vtmp2) <= 0) {
      l = sqrt(dotvv(vtmp, vtmp));
    } else {
      subvv(vtmp, B, A);
      subvv(vtmp2, B, P);
      crossvv(vtmp3, vtmp, vtmp2);
      l = sqrt(dotvv(vtmp3, vtmp3)) / sqrt(dotvv(vtmp, vtmp));
    }
  }
  return l;
}


x86 assembly (clang, -O0):
<ptlined>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <subvv@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <subvv@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <dotvv@plt>
cmp    $0x0,%rax
jg     11bf <ptlined+0x6f>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <dotvv@plt>
mov    %rax,%rdi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x78(%rbp)
jmp    128c <ptlined+0x13c>
lea    -0x50(%rbp),%rdi
mov    $0xffffffff,%esi
call   1070 <mulvf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <subvv@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <dotvv@plt>
cmp    $0x0,%rax
jg     1214 <ptlined+0xc4>
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <dotvv@plt>
mov    %rax,%rdi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x78(%rbp)
jmp    1287 <ptlined+0x137>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <subvv@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <subvv@plt>
lea    -0x70(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1050 <crossvv@plt>
lea    -0x70(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <dotvv@plt>
mov    %rax,%rdi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x80(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <dotvv@plt>
mov    %rax,%rdi
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    128c <ptlined+0x13c>
movsd  -0x78(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptlined>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %rdx,%rsi
mov    %r13,%rdx
call   1030 <subvv@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <subvv@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <dotvv@plt>
test   %rax,%rax
jle    124a <ptlined+0xfa>
lea    0x30(%rsp),%r12
mov    %r12,%rdi
mov    $0xffffffff,%esi
call   1070 <mulvf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <subvv@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <dotvv@plt>
test   %rax,%rax
jle    124a <ptlined+0xfa>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <subvv@plt>
lea    0x30(%rsp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1030 <subvv@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <crossvv@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <dotvv@plt>
mov    %rax,%rdi
call   1060 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r12,%rdi
mov    %r12,%rsi
call   1040 <dotvv@plt>
mov    %rax,%rdi
call   1060 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    125f <ptlined+0x10f>
lea    0x10(%rsp),%rdi
mov    %rdi,%rsi
call   1040 <dotvv@plt>
mov    %rax,%rdi
call   1060 <sqrt@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @ptlined(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 [3 x double]
%10 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%11 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%12 = load double*, double** %6
%13 = load double*, double** %5
%14 = call i32 @subvv(double* %11, double* %12, double* %13)
%15 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%16 = load double*, double** %4
%17 = load double*, double** %5
%18 = call i32 @subvv(double* %15, double* %16, double* %17)
%19 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%20 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%21 = call i64 @dotvv(double* %19, double* %20)
%22 = icmp sle i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %3
%24 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%25 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%26 = call i64 @dotvv(double* %24, double* %25)
%27 = call double @sqrt(i64 %26)
store double %27, double* %10
br label %67
28: ; preds = %3
%29 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%30 = call i32 @mulvf(double* %29, i32 -1)
%31 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%32 = load double*, double** %6
%33 = load double*, double** %4
%34 = call i32 @subvv(double* %31, double* %32, double* %33)
%35 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%36 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%37 = call i64 @dotvv(double* %35, double* %36)
%38 = icmp sle i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %28
%40 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%41 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%42 = call i64 @dotvv(double* %40, double* %41)
%43 = call double @sqrt(i64 %42)
store double %43, double* %10
br label %66
44: ; preds = %28
%45 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%46 = load double*, double** %5
%47 = load double*, double** %4
%48 = call i32 @subvv(double* %45, double* %46, double* %47)
%49 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%50 = load double*, double** %5
%51 = load double*, double** %6
%52 = call i32 @subvv(double* %49, double* %50, double* %51)
%53 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%54 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%55 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%56 = call i32 @crossvv(double* %53, double* %54, double* %55)
%57 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%58 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%59 = call i64 @dotvv(double* %57, double* %58)
%60 = call double @sqrt(i64 %59)
%61 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%62 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%63 = call i64 @dotvv(double* %61, double* %62)
%64 = call double @sqrt(i64 %63)
%65 = fdiv double %60, %64
store double %65, double* %10
br label %66
66: ; preds = %44, %39
br label %67
67: ; preds = %66, %23
%68 = load double, double* %10
ret double %68
}

LLVM IR (-O2):
define double @ptlined(double* %0, double* %1, double* %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 = call i32 @subvv(double* %10, double* %2, double* %1)
%12 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%13 = call i32 @subvv(double* %12, double* %0, double* %1)
%14 = call i64 @dotvv(double* %10, double* %12)
%15 = icmp slt i64 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = call i64 @dotvv(double* %10, double* %10)
%18 = call double @sqrt(i64 %17)
br label %37
19: ; preds = %3
%20 = call i32 @mulvf(double* %12, i32 -1)
%21 = call i32 @subvv(double* %10, double* %2, double* %0)
%22 = call i64 @dotvv(double* %10, double* %12)
%23 = icmp slt i64 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i64 @dotvv(double* %10, double* %10)
%26 = call double @sqrt(i64 %25)
br label %37
27: ; preds = %19
%28 = call i32 @subvv(double* %10, double* %1, double* %0)
%29 = call i32 @subvv(double* %12, double* %1, double* %2)
%30 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%31 = call i32 @crossvv(double* %30, double* %10, double* %12)
%32 = call i64 @dotvv(double* %30, double* %30)
%33 = call double @sqrt(i64 %32)
%34 = call i64 @dotvv(double* %10, double* %10)
%35 = call double @sqrt(i64 %34)
%36 = fdiv double %33, %35
br label %37
37: ; preds = %24, %27, %16
%38 = phi double [ %18, %16 ], [ %26, %24 ], [ %36, %27 ]
ret double %38
}