#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*/ glmAddVector3d(double *, double const *, double *);
int /*<<< orphan*/ glmCopyVector3d(double const *, double *);
double glmDotProduct3d(double *, double *);
int /*<<< orphan*/ glmMakeVector3d(double *, double const *, double const *);
int /*<<< orphan*/ glmMultVectorByScalar3d(double *, double);
double glmNormalizeVector3d(double *);
void glmClosestPointOnLineSegment3d(double result[3], const double a[3],
                                    const double b[3], const double p[3]) {
  double c[3], v[3];
  double d, t;
  glmMakeVector3d(c, a, p);
  glmMakeVector3d(v, a, b);
  d = glmNormalizeVector3d(v);
  t = glmDotProduct3d(v, c);
  if (t < 0) {
    glmCopyVector3d(a, result);
    return;
  }
  if (t > d) {
    glmCopyVector3d(b, result);
    return;
  }
  glmMultVectorByScalar3d(v, t);
  glmAddVector3d(result, a, v);
}


x86 assembly (clang, -O0):
<glmClosestPointOnLineSegment3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <glmMakeVector3d@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <glmMakeVector3d@plt>
lea    -0x60(%rbp),%rdi
call   1050 <glmNormalizeVector3d@plt>
movsd  %xmm0,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <glmDotProduct3d@plt>
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x70(%rbp),%xmm0
jbe    11da <glmClosestPointOnLineSegment3d+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <glmCopyVector3d@plt>
jmp    121b <glmClosestPointOnLineSegment3d+0xbb>
movsd  -0x70(%rbp),%xmm0
ucomisd -0x68(%rbp),%xmm0
jbe    11fc <glmClosestPointOnLineSegment3d+0x9c>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <glmCopyVector3d@plt>
jmp    121b <glmClosestPointOnLineSegment3d+0xbb>
lea    -0x60(%rbp),%rdi
movsd  -0x70(%rbp),%xmm0
call   1040 <glmMultVectorByScalar3d@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1080 <glmAddVector3d@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmClosestPointOnLineSegment3d>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
lea    0x30(%rsp),%r12
mov    %r12,%rdi
mov    %rcx,%rdx
call   1030 <glmMakeVector3d@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <glmMakeVector3d@plt>
mov    %rbx,%rdi
call   1050 <glmNormalizeVector3d@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <glmDotProduct3d@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11c1 <glmClosestPointOnLineSegment3d+0x61>
mov    %r13,%rdi
jmp    11cc <glmClosestPointOnLineSegment3d+0x6c>
ucomisd 0x8(%rsp),%xmm0
jbe    11d6 <glmClosestPointOnLineSegment3d+0x76>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <glmCopyVector3d@plt>
jmp    11f1 <glmClosestPointOnLineSegment3d+0x91>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <glmMultVectorByScalar3d@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <glmAddVector3d@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @glmClosestPointOnLineSegment3d(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca [3 x double]
%10 = alloca [3 x double]
%11 = alloca double
%12 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%13 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%14 = load double*, double** %6
%15 = load double*, double** %8
%16 = call i32 @glmMakeVector3d(double* %13, double* %14, double* %15)
%17 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%18 = load double*, double** %6
%19 = load double*, double** %7
%20 = call i32 @glmMakeVector3d(double* %17, double* %18, double* %19)
%21 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%22 = call double @glmNormalizeVector3d(double* %21)
store double %22, double* %11
%23 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%24 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%25 = call double @glmDotProduct3d(double* %23, double* %24)
store double %25, double* %12
%26 = load double, double* %12
%27 = fcmp olt double %26, 0.000000e+00
br i1 %27, label %28, label %32
28: ; preds = %4
%29 = load double*, double** %6
%30 = load double*, double** %5
%31 = call i32 @glmCopyVector3d(double* %29, double* %30)
br label %48
32: ; preds = %4
%33 = load double, double* %12
%34 = load double, double* %11
%35 = fcmp ogt double %33, %34
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load double*, double** %7
%38 = load double*, double** %5
%39 = call i32 @glmCopyVector3d(double* %37, double* %38)
br label %48
40: ; preds = %32
%41 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%42 = load double, double* %12
%43 = call i32 @glmMultVectorByScalar3d(double* %41, double %42)
%44 = load double*, double** %5
%45 = load double*, double** %6
%46 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%47 = call i32 @glmAddVector3d(double* %44, double* %45, double* %46)
br label %48
48: ; preds = %40, %36, %28
ret void
}

LLVM IR (-O2):
define void @glmClosestPointOnLineSegment3d(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = bitcast [3 x double]* %5 to i8*
%8 = bitcast [3 x double]* %6 to i8*
%9 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%10 = call i32 @glmMakeVector3d(double* %9, double* %1, double* %3)
%11 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%12 = call i32 @glmMakeVector3d(double* %11, double* %1, double* %2)
%13 = call double @glmNormalizeVector3d(double* %11)
%14 = call double @glmDotProduct3d(double* %11, double* %9)
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @glmCopyVector3d(double* %1, double* %0)
br label %25
18: ; preds = %4
%19 = fcmp ogt double %14, %13
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = call i32 @glmCopyVector3d(double* %2, double* %0)
br label %25
22: ; preds = %18
%23 = call i32 @glmMultVectorByScalar3d(double* %11, double %14)
%24 = call i32 @glmAddVector3d(double* %0, double* %1, double* %11)
br label %25
25: ; preds = %22, %20, %16
ret void
}