// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/trace.cpp
// Function: TestLine_r(int, float const*, float const*, int&, float*)
int             TestLine_r(const int node, const vec3_t start, const vec3_t stop
#ifdef HLRAD_WATERBLOCKLIGHT
						   , int &linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
						   , vec_t *skyhit
#endif
						   )
{
    tnode_t*        tnode;
    float           front, back;
    vec3_t          mid;
    float           frac;
    int             side;
    int             r;

#ifdef HLRAD_WATERBLOCKLIGHT
	if (node < 0)
	{
		if (node == linecontent)
			return CONTENTS_EMPTY;
#ifdef HLRAD_OPAQUEINSKY_FIX
		if (node == CONTENTS_SOLID)
		{
			return CONTENTS_SOLID;
		}
		if (node == CONTENTS_SKY)
		{
			if (skyhit)
			{
				VectorCopy (start, skyhit);
			}
			return CONTENTS_SKY;
		}
#else
		if (node == CONTENTS_SOLID || node == CONTENTS_SKY)
			return node;
#endif
		if (linecontent)
		{
			return CONTENTS_SOLID;
		}
		linecontent = node;
		return CONTENTS_EMPTY;
	}
#else
#ifdef HLRAD_OPAQUEINSKY_FIX
	if (node == CONTENTS_SKY)
	{
		VectorCopy (start, skyhit);
	}
#endif
	if (   (node == CONTENTS_SOLID) 
        || (node == CONTENTS_SKY  ) 
      /*|| (node == CONTENTS_NULL ) */
       )
		return node;

    if (node < 0)
        return CONTENTS_EMPTY; 
#endif

    tnode = &tnodes[node];
    switch (tnode->type)
    {
    case plane_x:
        front = start[0] - tnode->dist;
        back = stop[0] - tnode->dist;
        break;
    case plane_y:
        front = start[1] - tnode->dist;
        back = stop[1] - tnode->dist;
        break;
    case plane_z:
        front = start[2] - tnode->dist;
        back = stop[2] - tnode->dist;
        break;
    default:
        front = (start[0] * tnode->normal[0] + start[1] * tnode->normal[1] + start[2] * tnode->normal[2]) - tnode->dist;
        back = (stop[0] * tnode->normal[0] + stop[1] * tnode->normal[1] + stop[2] * tnode->normal[2]) - tnode->dist;
        break;
    }

#ifdef HLRAD_TestLine_EDGE_FIX
	if (front > ON_EPSILON/2 && back > ON_EPSILON/2)
	{
		return TestLine_r(tnode->children[0], start, stop
#ifdef HLRAD_WATERBLOCKLIGHT
			, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
			, skyhit
#endif
			);
	}
	if (front < -ON_EPSILON/2 && back < -ON_EPSILON/2)
	{
		return TestLine_r(tnode->children[1], start, stop
#ifdef HLRAD_WATERBLOCKLIGHT
			, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
			, skyhit
#endif
			);
	}
	if (fabs(front) <= ON_EPSILON && fabs(back) <= ON_EPSILON)
	{
		int r1 = TestLine_r(tnode->children[0], start, stop
#ifdef HLRAD_WATERBLOCKLIGHT
			, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
			, skyhit
#endif
			);
		if (r1 == CONTENTS_SOLID)
			return CONTENTS_SOLID;
		int r2 = TestLine_r(tnode->children[1], start, stop
#ifdef HLRAD_WATERBLOCKLIGHT
			, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
			, skyhit
#endif
			);
		if (r2 == CONTENTS_SOLID)
			return CONTENTS_SOLID;
		if (r1 == CONTENTS_SKY || r2 == CONTENTS_SKY)
			return CONTENTS_SKY;
		return CONTENTS_EMPTY;
	}
	side = (front - back) < 0;
	frac = front / (front - back);
	if (frac < 0) frac = 0;
	if (frac > 1) frac = 1;
	mid[0] = start[0] + (stop[0] - start[0]) * frac;
	mid[1] = start[1] + (stop[1] - start[1]) * frac;
	mid[2] = start[2] + (stop[2] - start[2]) * frac;
	r = TestLine_r(tnode->children[side], start, mid
#ifdef HLRAD_WATERBLOCKLIGHT
		, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
		, skyhit
#endif
		);
	if (r != CONTENTS_EMPTY)
		return r;
	return TestLine_r(tnode->children[!side], mid, stop
#ifdef HLRAD_WATERBLOCKLIGHT
		, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
		, skyhit
#endif
		);
#else //bug: light can go through edges of solid brushes
    if (front >= -ON_EPSILON && back >= -ON_EPSILON)
        return TestLine_r(tnode->children[0], start, stop
#ifdef HLRAD_WATERBLOCKLIGHT
		, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
		, skyhit
#endif
		);

    if (front < ON_EPSILON && back < ON_EPSILON)
        return TestLine_r(tnode->children[1], start, stop
#ifdef HLRAD_WATERBLOCKLIGHT
		, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
		, skyhit
#endif
		);

    side = front < 0;

    frac = front / (front - back);

    mid[0] = start[0] + (stop[0] - start[0]) * frac;
    mid[1] = start[1] + (stop[1] - start[1]) * frac;
    mid[2] = start[2] + (stop[2] - start[2]) * frac;

    r = TestLine_r(tnode->children[side], start, mid
#ifdef HLRAD_WATERBLOCKLIGHT
		, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
		, skyhit
#endif
		);
    if (r != CONTENTS_EMPTY)
        return r;
    return TestLine_r(tnode->children[!side], mid, stop
#ifdef HLRAD_WATERBLOCKLIGHT
		, linecontent
#endif
#ifdef HLRAD_OPAQUEINSKY_FIX
		, skyhit
#endif
		);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rsi, %r12
testl %edi, %edi
js 0x321a3
movq %rdx, %r15
movq 0x66c7955(%rip), %rax   # 0x66f9ac8
movl %edi, %ecx
shlq $0x5, %rcx
leaq (%rax,%rcx), %r13
movl (%rax,%rcx), %eax
cmpl $0x2, %eax
je 0x32209
cmpl $0x1, %eax
je 0x321fa
testl %eax, %eax
jne 0x32228
movss (%r12), %xmm1
movss (%r15), %xmm0
jmp 0x32216
movl (%r14), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %edi, %ecx
je 0x3243d
cmpl $-0x2, %edi
je 0x32428
cmpl $-0x6, %edi
jne 0x3242c
movl $0xfffffffa, %eax       # imm = 0xFFFFFFFA
testq %rbx, %rbx
je 0x3243d
movss (%r12), %xmm0
movss %xmm0, (%rbx)
movss 0x4(%r12), %xmm0
movss %xmm0, 0x4(%rbx)
movss 0x8(%r12), %xmm0
movss %xmm0, 0x8(%rbx)
jmp 0x3243d
movss 0x4(%r12), %xmm1
movss 0x4(%r15), %xmm0
jmp 0x32216
movss 0x8(%r12), %xmm1
movss 0x8(%r15), %xmm0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movss 0x10(%r13), %xmm1
shufps $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
subps %xmm1, %xmm0
jmp 0x32290
movss (%r12), %xmm0
movss 0x4(%r12), %xmm1
movss 0x8(%r12), %xmm2
movss (%r15), %xmm3
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
movss 0x4(%r15), %xmm4
unpcklps %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
movss 0x8(%r15), %xmm1
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movss 0x4(%r13), %xmm2
movss 0x8(%r13), %xmm5
movss 0xc(%r13), %xmm0
movss 0x10(%r13), %xmm6
shufps $0x0, %xmm5, %xmm5      # xmm5 = xmm5[0,0,0,0]
mulps %xmm4, %xmm5
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
mulps %xmm3, %xmm2
addps %xmm5, %xmm2
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
mulps %xmm1, %xmm0
addps %xmm2, %xmm0
shufps $0x0, %xmm6, %xmm6      # xmm6 = xmm6[0,0,0,0]
subps %xmm6, %xmm0
cvtps2pd %xmm0, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
ucomisd 0xc97d(%rip), %xmm2     # 0x3ec20
jbe 0x322b5
ucomisd 0xc973(%rip), %xmm1     # 0x3ec20
jbe 0x322b5
movl 0x14(%r13), %edi
jmp 0x322cb
cmpltpd 0xc622(%rip), %xmm1     # 0x3e8e0
movmskpd %xmm1, %eax
cmpl $0x3, %eax
jne 0x322ea
movl 0x18(%r13), %edi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3214e
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
movaps 0x8048(%rip), %xmm2     # 0x3a340
movaps %xmm1, %xmm3
andps %xmm2, %xmm3
xorps %xmm4, %xmm4
cvtss2sd %xmm3, %xmm4
movsd 0x82eb(%rip), %xmm3     # 0x3a5f8
ucomisd %xmm4, %xmm3
jb 0x3237d
andps %xmm0, %xmm2
cvtss2sd %xmm2, %xmm2
ucomisd %xmm2, %xmm3
jb 0x3237d
movl 0x14(%r13), %edi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x3214e
movl %eax, %ebp
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpl $-0x2, %ebp
je 0x3243d
movl 0x18(%r13), %edi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x3214e
movl %eax, %ecx
cmpl $-0x6, %ebp
setne %al
cmpl $-0x6, %ecx
setne %dl
andb %al, %dl
movzbl %dl, %eax
negl %eax
orl $-0x6, %eax
cmpl $-0x2, %ecx
cmovel %ecx, %eax
jmp 0x3243d
movaps %xmm1, %xmm2
subss %xmm0, %xmm2
xorps %xmm0, %xmm0
xorl %eax, %eax
ucomiss %xmm2, %xmm0
seta %al
movss %xmm2, 0x4(%rsp)
divss %xmm2, %xmm1
maxss %xmm1, %xmm0
movss 0x4cff(%rip), %xmm1     # 0x370a4
minss %xmm0, %xmm1
movsd (%r12), %xmm0
movsd (%r15), %xmm2
subps %xmm0, %xmm2
movaps %xmm1, %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
mulps %xmm2, %xmm3
addps %xmm0, %xmm3
leaq 0x8(%rsp), %rdx
movlps %xmm3, (%rdx)
movss 0x8(%r12), %xmm0
movss 0x8(%r15), %xmm2
subss %xmm0, %xmm2
mulss %xmm1, %xmm2
addss %xmm0, %xmm2
movss %xmm2, 0x8(%rdx)
movl 0x14(%r13,%rax,4), %edi
movq %r12, %rsi
movq %r14, %rcx
movq %rbx, %r8
callq 0x3214e
cmpl $-0x1, %eax
jne 0x3243d
xorl %eax, %eax
xorps %xmm0, %xmm0
ucomiss 0x4(%rsp), %xmm0
setbe %al
movl 0x14(%r13,%rax,4), %edi
leaq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x3214e
jmp 0x3243d
movl %edi, %eax
jmp 0x3243d
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
testl %ecx, %ecx
jne 0x3243d
movl %edi, (%r14)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq