#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*/ glmAddVector3f(float *, float const *, float *);
int /*<<< orphan*/ glmCopyVector3f(float const *, float *);
float glmDotProduct3f(float *, float *);
int /*<<< orphan*/ glmMakeVector3f(float *, float const *, float const *);
int /*<<< orphan*/ glmMultVectorByScalar3f(float *, float);
float glmNormalizeVector3f(float *);
void glmClosestPointOnLineSegment3f(float result[3], const float a[3],
                                    const float b[3], const float p[3]) {
  float c[3], v[3];
  float d, t;
  glmMakeVector3f(c, a, p);
  glmMakeVector3f(v, a, b);
  d = glmNormalizeVector3f(v);
  t = glmDotProduct3f(v, c);
  if (t < 0) {
    glmCopyVector3f(a, result);
    return;
  }
  if (t > d) {
    glmCopyVector3f(b, result);
    return;
  }
  glmMultVectorByScalar3f(v, t);
  glmAddVector3f(result, a, v);
}


x86 assembly (clang, -O0):
<glmClosestPointOnLineSegment3f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x2c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <glmMakeVector3f@plt>
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <glmMakeVector3f@plt>
lea    -0x38(%rbp),%rdi
call   1040 <glmNormalizeVector3f@plt>
movss  %xmm0,-0x3c(%rbp)
lea    -0x38(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <glmDotProduct3f@plt>
movss  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x40(%rbp),%xmm0
jbe    11d9 <glmClosestPointOnLineSegment3f+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <glmCopyVector3f@plt>
jmp    1219 <glmClosestPointOnLineSegment3f+0xb9>
movss  -0x40(%rbp),%xmm0
ucomiss -0x3c(%rbp),%xmm0
jbe    11fa <glmClosestPointOnLineSegment3f+0x9a>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <glmCopyVector3f@plt>
jmp    1219 <glmClosestPointOnLineSegment3f+0xb9>
lea    -0x38(%rbp),%rdi
movss  -0x40(%rbp),%xmm0
call   1050 <glmMultVectorByScalar3f@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1080 <glmAddVector3f@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmClosestPointOnLineSegment3f>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
lea    0x14(%rsp),%r12
mov    %r12,%rdi
mov    %rcx,%rdx
call   1030 <glmMakeVector3f@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1030 <glmMakeVector3f@plt>
mov    %rbx,%rdi
call   1040 <glmNormalizeVector3f@plt>
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <glmDotProduct3f@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    11bf <glmClosestPointOnLineSegment3f+0x5f>
mov    %r13,%rdi
jmp    11c9 <glmClosestPointOnLineSegment3f+0x69>
ucomiss 0x4(%rsp),%xmm0
jbe    11d3 <glmClosestPointOnLineSegment3f+0x73>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <glmCopyVector3f@plt>
jmp    11ee <glmClosestPointOnLineSegment3f+0x8e>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <glmMultVectorByScalar3f@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <glmAddVector3f@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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