// File: FreeSlave[P]vhlt/hlrad/lerp.cpp
// Function: GetFrac(float const*, float const*, float const*, float const*)
static vec_t GetFrac (const vec3_t leftspot, const vec3_t rightspot, const vec3_t direction, const vec3_t normal)
{
	vec3_t v;
	vec_t dot1;
	vec_t dot2;
	vec_t frac;

	CrossProduct (direction, normal, v);
	dot1 = DotProduct (leftspot, v);
	dot2 = DotProduct (rightspot, v);
	
	// dot1 <= 0 < dot2
	if (dot1 >= -NORMAL_EPSILON)
	{
		if (g_drawlerp && dot1 > ON_EPSILON)
		{
			Developer (DEVELOPER_LEVEL_SPAM, "Debug: triangulation: internal error 1.\n");
		}
		frac = 0.0;
	}
	else if (dot2 <= NORMAL_EPSILON)
	{
		if (g_drawlerp && dot2 < -ON_EPSILON)
		{
			Developer (DEVELOPER_LEVEL_SPAM, "Debug: triangulation: internal error 2.\n");
		}
		frac = 1.0;
	}
	else
	{
		frac = dot1 / (dot1 - dot2);
		frac = qmax (0, qmin (frac, 1));
	}

	return frac;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq 0x30(%rsp), %rax
movss 0x4(%rax), %xmm0
movq 0x28(%rsp), %rax
movss 0x8(%rax), %xmm2
movq 0x30(%rsp), %rax
movss 0x8(%rax), %xmm1
movq 0x28(%rsp), %rax
mulss 0x4(%rax), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x28(%rsp), %rax
movss (%rax), %xmm2
movq 0x30(%rsp), %rax
movss (%rax), %xmm1
movq 0x28(%rsp), %rax
mulss 0x8(%rax), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x20(%rsp)
movq 0x30(%rsp), %rax
movss (%rax), %xmm0
movq 0x28(%rsp), %rax
movss 0x4(%rax), %xmm2
movq 0x30(%rsp), %rax
movss 0x4(%rax), %xmm1
movq 0x28(%rsp), %rax
mulss (%rax), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x24(%rsp)
movq 0x40(%rsp), %rax
movss (%rax), %xmm1
movss 0x1c(%rsp), %xmm2
movq 0x40(%rsp), %rax
movss 0x4(%rax), %xmm0
mulss 0x20(%rsp), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq 0x40(%rsp), %rax
movss 0x8(%rax), %xmm0
movss 0x24(%rsp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x18(%rsp)
movq 0x38(%rsp), %rax
movss (%rax), %xmm1
movss 0x1c(%rsp), %xmm2
movq 0x38(%rsp), %rax
movss 0x4(%rax), %xmm0
mulss 0x20(%rsp), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq 0x38(%rsp), %rax
movss 0x8(%rax), %xmm0
movss 0x24(%rsp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x18(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x54d07(%rip), %xmm1    # 0x6d7f0
ucomisd %xmm1, %xmm0
jb 0x18b34
leaq 0x5516f6b(%rip), %rax   # 0x552fa61
testb $0x1, (%rax)
je 0x18b26
movss 0x18(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x54cd3(%rip), %xmm1    # 0x6d7e0
ucomisd %xmm1, %xmm0
jbe 0x18b26
movl $0x5, %edi
leaq 0x54dcf(%rip), %rsi     # 0x6d8ee
movb $0x0, %al
callq 0xbbf0
xorps %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0x18c3f
movss 0x14(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x51522(%rip), %xmm0    # 0x6a068
ucomisd %xmm1, %xmm0
jb 0x18b96
leaq 0x5516f0e(%rip), %rax   # 0x552fa61
testb $0x1, (%rax)
je 0x18b83
movss 0x14(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x54cc6(%rip), %xmm0    # 0x6d830
ucomisd %xmm1, %xmm0
jbe 0x18b83
movl $0x5, %edi
leaq 0x54d9b(%rip), %rsi     # 0x6d917
movb $0x0, %al
callq 0xbbf0
movss 0x514c1(%rip), %xmm0    # 0x6a04c
movss %xmm0, 0x10(%rsp)
jmp 0x18c3d
movss 0x18(%rsp), %xmm0
movss 0x18(%rsp), %xmm1
subss 0x14(%rsp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x51492(%rip), %xmm0    # 0x6a04c
ucomiss 0x10(%rsp), %xmm0
jbe 0x18bcf
movss 0x10(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
jmp 0x18bdf
movss 0x51475(%rip), %xmm0    # 0x6a04c
movss %xmm0, 0xc(%rsp)
jmp 0x18bdf
movss 0xc(%rsp), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x18bf8
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
jmp 0x18c31
movss 0x5144c(%rip), %xmm0    # 0x6a04c
ucomiss 0x10(%rsp), %xmm0
jbe 0x18c15
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
jmp 0x18c25
movss 0x5142f(%rip), %xmm0    # 0x6a04c
movss %xmm0, 0x4(%rsp)
jmp 0x18c25
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0x18c3f
movss 0x10(%rsp), %xmm0
addq $0x48, %rsp
retq
nopw (%rax,%rax)