#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*/ crossVectorsNorm(float *, float *, float *);
float dotVectors(float const *, float *);
scalar_t__ magnitudeVector(float *);
int /*<<< orphan*/ normalizeVector(float *);
void projectPointReturnNorm(const float *point, const float *v0,
                            const float *v1, const float *v2,
                            float *projected_point, float *norm) {
  float v0v1[3], v0v2[3];
  float s;
  v0v1[0] = v1[0] - v0[0];
  v0v1[1] = v1[1] - v0[1];
  v0v1[2] = v1[2] - v0[2];
  v0v2[0] = v2[0] - v0[0];
  v0v2[1] = v2[1] - v0[1];
  v0v2[2] = v2[2] - v0[2];
  crossVectorsNorm(v0v1, v0v2, norm);
  if (magnitudeVector(norm) == 0) {
    norm[0] = v0[0];
    norm[1] = v0[1];
    norm[2] = v0[2];
    normalizeVector(norm);
  }
  s = dotVectors(v0, norm) / dotVectors(point, norm);
  projected_point[0] = s * point[0];
  projected_point[1] = s * point[1];
  projected_point[2] = s * point[2];
  return;
}


x86 assembly (clang, -O0):
<projectPointReturnNorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  (%rax),%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  0x4(%rax),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  0x8(%rax),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  (%rax),%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  0x4(%rax),%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x20(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subss  0x8(%rax),%xmm0
movss  %xmm0,-0x40(%rbp)
lea    -0x3c(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <crossVectorsNorm@plt>
mov    -0x30(%rbp),%rdi
call   1060 <magnitudeVector@plt>
cmp    $0x0,%rax
jne    1247 <projectPointReturnNorm+0x107>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,0x8(%rax)
mov    -0x30(%rbp),%rdi
call   1040 <normalizeVector@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <dotVectors@plt>
movss  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <dotVectors@plt>
movaps %xmm0,%xmm1
movss  -0x50(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x4c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  (%rax),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x4c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x4c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x8(%rax),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<projectPointReturnNorm>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r12
mov    %r8,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movss  (%rdx),%xmm0
movss  (%rsi),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,0x1c(%rsp)
movss  0x4(%rdx),%xmm0
movss  0x4(%rsi),%xmm2
subss  %xmm2,%xmm0
movss  %xmm0,0x20(%rsp)
movss  0x8(%rdx),%xmm0
movss  0x8(%rsi),%xmm3
subss  %xmm3,%xmm0
movss  %xmm0,0x24(%rsp)
movss  (%rcx),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,0x10(%rsp)
movss  0x4(%rcx),%xmm0
subss  %xmm2,%xmm0
movss  %xmm0,0x14(%rsp)
movss  0x8(%rcx),%xmm0
subss  %xmm3,%xmm0
movss  %xmm0,0x18(%rsp)
lea    0x1c(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r9,%rdx
call   1050 <crossVectorsNorm@plt>
mov    %r12,%rdi
call   1060 <magnitudeVector@plt>
test   %rax,%rax
jne    1206 <projectPointReturnNorm+0xc6>
movss  (%rbx),%xmm0
movss  %xmm0,(%r12)
movss  0x4(%rbx),%xmm0
movss  %xmm0,0x4(%r12)
movss  0x8(%rbx),%xmm0
movss  %xmm0,0x8(%r12)
mov    %r12,%rdi
call   1040 <normalizeVector@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <dotVectors@plt>
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <dotVectors@plt>
movss  0xc(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  (%r15),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,(%r14)
movss  0x4(%r15),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,0x4(%r14)
mulss  0x8(%r15),%xmm1
movss  %xmm1,0x8(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @projectPointReturnNorm(float* %0, float* %1, float* %2, float* %3, float* %4, float* %5) {
%7 = alloca float*
%8 = alloca float*
%9 = alloca float*
%10 = alloca float*
%11 = alloca float*
%12 = alloca float*
%13 = alloca [3 x float]
%14 = alloca [3 x float]
%15 = alloca float
store float* %0, float** %7
store float* %1, float** %8
store float* %2, float** %9
store float* %3, float** %10
store float* %4, float** %11
store float* %5, float** %12
%16 = load float*, float** %9
%17 = getelementptr inbounds float, float* %16, i64 0
%18 = load float, float* %17
%19 = load float*, float** %8
%20 = getelementptr inbounds float, float* %19, i64 0
%21 = load float, float* %20
%22 = fsub float %18, %21
%23 = getelementptr inbounds [3 x float], [3 x float]* %13, i64 0, i64 0
store float %22, float* %23
%24 = load float*, float** %9
%25 = getelementptr inbounds float, float* %24, i64 1
%26 = load float, float* %25
%27 = load float*, float** %8
%28 = getelementptr inbounds float, float* %27, i64 1
%29 = load float, float* %28
%30 = fsub float %26, %29
%31 = getelementptr inbounds [3 x float], [3 x float]* %13, i64 0, i64 1
store float %30, float* %31
%32 = load float*, float** %9
%33 = getelementptr inbounds float, float* %32, i64 2
%34 = load float, float* %33
%35 = load float*, float** %8
%36 = getelementptr inbounds float, float* %35, i64 2
%37 = load float, float* %36
%38 = fsub float %34, %37
%39 = getelementptr inbounds [3 x float], [3 x float]* %13, i64 0, i64 2
store float %38, float* %39
%40 = load float*, float** %10
%41 = getelementptr inbounds float, float* %40, i64 0
%42 = load float, float* %41
%43 = load float*, float** %8
%44 = getelementptr inbounds float, float* %43, i64 0
%45 = load float, float* %44
%46 = fsub float %42, %45
%47 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
store float %46, float* %47
%48 = load float*, float** %10
%49 = getelementptr inbounds float, float* %48, i64 1
%50 = load float, float* %49
%51 = load float*, float** %8
%52 = getelementptr inbounds float, float* %51, i64 1
%53 = load float, float* %52
%54 = fsub float %50, %53
%55 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 1
store float %54, float* %55
%56 = load float*, float** %10
%57 = getelementptr inbounds float, float* %56, i64 2
%58 = load float, float* %57
%59 = load float*, float** %8
%60 = getelementptr inbounds float, float* %59, i64 2
%61 = load float, float* %60
%62 = fsub float %58, %61
%63 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 2
store float %62, float* %63
%64 = getelementptr inbounds [3 x float], [3 x float]* %13, i64 0, i64 0
%65 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%66 = load float*, float** %12
%67 = call i32 @crossVectorsNorm(float* %64, float* %65, float* %66)
%68 = load float*, float** %12
%69 = call i64 @magnitudeVector(float* %68)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %89
71: ; preds = %6
%72 = load float*, float** %8
%73 = getelementptr inbounds float, float* %72, i64 0
%74 = load float, float* %73
%75 = load float*, float** %12
%76 = getelementptr inbounds float, float* %75, i64 0
store float %74, float* %76
%77 = load float*, float** %8
%78 = getelementptr inbounds float, float* %77, i64 1
%79 = load float, float* %78
%80 = load float*, float** %12
%81 = getelementptr inbounds float, float* %80, i64 1
store float %79, float* %81
%82 = load float*, float** %8
%83 = getelementptr inbounds float, float* %82, i64 2
%84 = load float, float* %83
%85 = load float*, float** %12
%86 = getelementptr inbounds float, float* %85, i64 2
store float %84, float* %86
%87 = load float*, float** %12
%88 = call i32 @normalizeVector(float* %87)
br label %89
89: ; preds = %71, %6
%90 = load float*, float** %8
%91 = load float*, float** %12
%92 = call float @dotVectors(float* %90, float* %91)
%93 = load float*, float** %7
%94 = load float*, float** %12
%95 = call float @dotVectors(float* %93, float* %94)
%96 = fdiv float %92, %95
store float %96, float* %15
%97 = load float, float* %15
%98 = load float*, float** %7
%99 = getelementptr inbounds float, float* %98, i64 0
%100 = load float, float* %99
%101 = fmul float %97, %100
%102 = load float*, float** %11
%103 = getelementptr inbounds float, float* %102, i64 0
store float %101, float* %103
%104 = load float, float* %15
%105 = load float*, float** %7
%106 = getelementptr inbounds float, float* %105, i64 1
%107 = load float, float* %106
%108 = fmul float %104, %107
%109 = load float*, float** %11
%110 = getelementptr inbounds float, float* %109, i64 1
store float %108, float* %110
%111 = load float, float* %15
%112 = load float*, float** %7
%113 = getelementptr inbounds float, float* %112, i64 2
%114 = load float, float* %113
%115 = fmul float %111, %114
%116 = load float*, float** %11
%117 = getelementptr inbounds float, float* %116, i64 2
store float %115, float* %117
ret void
}

LLVM IR (-O2):
define void @projectPointReturnNorm(float* %0, float* %1, float* nocapture %2, float* nocapture %3, float* nocapture writeonly %4, float* %5) {
%7 = alloca [3 x float]
%8 = alloca [3 x float]
%9 = bitcast [3 x float]* %7 to i8*
%10 = bitcast [3 x float]* %8 to i8*
%11 = load float, float* %2
%12 = load float, float* %1
%13 = fsub float %11, %12
%14 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
store float %13, float* %14
%15 = getelementptr inbounds float, float* %2, i64 1
%16 = load float, float* %15
%17 = getelementptr inbounds float, float* %1, i64 1
%18 = load float, float* %17
%19 = fsub float %16, %18
%20 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 1
store float %19, float* %20
%21 = getelementptr inbounds float, float* %2, i64 2
%22 = load float, float* %21
%23 = getelementptr inbounds float, float* %1, i64 2
%24 = load float, float* %23
%25 = fsub float %22, %24
%26 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 2
store float %25, float* %26
%27 = load float, float* %3
%28 = fsub float %27, %12
%29 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 0
store float %28, float* %29
%30 = getelementptr inbounds float, float* %3, i64 1
%31 = load float, float* %30
%32 = fsub float %31, %18
%33 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 1
store float %32, float* %33
%34 = getelementptr inbounds float, float* %3, i64 2
%35 = load float, float* %34
%36 = fsub float %35, %24
%37 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 2
store float %36, float* %37
%38 = call i32 @crossVectorsNorm(float* %14, float* %29, float* %5)
%39 = call i64 @magnitudeVector(float* %5)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %6
%42 = load float, float* %1
store float %42, float* %5
%43 = load float, float* %17
%44 = getelementptr inbounds float, float* %5, i64 1
store float %43, float* %44
%45 = load float, float* %23
%46 = getelementptr inbounds float, float* %5, i64 2
store float %45, float* %46
%47 = call i32 @normalizeVector(float* %5)
br label %48
48: ; preds = %41, %6
%49 = call float @dotVectors(float* %1, float* %5)
%50 = call float @dotVectors(float* %0, float* %5)
%51 = fdiv float %49, %50
%52 = load float, float* %0
%53 = fmul float %51, %52
store float %53, float* %4
%54 = getelementptr inbounds float, float* %0, i64 1
%55 = load float, float* %54
%56 = fmul float %51, %55
%57 = getelementptr inbounds float, float* %4, i64 1
store float %56, float* %57
%58 = getelementptr inbounds float, float* %0, i64 2
%59 = load float, float* %58
%60 = fmul float %51, %59
%61 = getelementptr inbounds float, float* %4, i64 2
store float %60, float* %61
ret void
}