// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlrad/lightmap.cpp
// Function: AddPatchLights(int)
void AddPatchLights (int facenum)
{
	dface_t *f;
#ifndef HLRAD_LOCALTRIANGULATION
	lerpTriangulation_t *trian;
#endif
	facelightlist_t *item;
	dface_t *f_other;
	facelight_t *fl_other;
	int k;
	int i;
	sample_t *samp;

	f = &g_dfaces[facenum];

	if (g_texinfo[f->texinfo].flags & TEX_SPECIAL)
	{
		return;
	}

#ifndef HLRAD_LOCALTRIANGULATION
	trian = CreateTriangulation (facenum);
#endif
	
	for (item = g_dependentfacelights[facenum]; item != NULL; item = item->next)
	{
		f_other = &g_dfaces[item->facenum];
		fl_other = &facelight[item->facenum];
		for (k = 0; k < MAXLIGHTMAPS && f_other->styles[k] != 255; k++)
		{
			for (i = 0; i < fl_other->numsamples; i++)
			{
				samp = &fl_other->samples[k][i];
				if (samp->surface != facenum)
				{ // the sample is not in this surface
					continue;
				}

				{
					vec3_t v;
		#ifdef ZHLT_XASH
					vec3_t v_direction;
		#endif

#ifdef HLRAD_LOCALTRIANGULATION
					int style = f_other->styles[k];
					InterpolateSampleLight (samp->pos, samp->surface, 1, &style, &v
		#ifdef ZHLT_XASH
											, &v_direction
		#endif
											);
#else
					SampleTriangulation (trian, samp->pos, v, 
		#ifdef ZHLT_XASH
										v_direction, 
		#endif
										f_other->styles[k]); //LRC
#endif

	#ifdef HLRAD_STYLE_CORING
					VectorAdd (samp->light, v, v);
		#ifdef ZHLT_XASH
					VectorAdd (samp->light_direction, v_direction, v_direction);
		#endif
					if (VectorMaximum (v) >= g_corings[f_other->styles[k]])
					{
						VectorCopy (v, samp->light);
		#ifdef ZHLT_XASH
						VectorCopy (v_direction, samp->light_direction);
		#endif
					}
					else
					{
		#ifdef HLRAD_AUTOCORING
						if (VectorMaximum (v) > g_maxdiscardedlight + NORMAL_EPSILON)
						{
							ThreadLock ();
							if (VectorMaximum (v) > g_maxdiscardedlight + NORMAL_EPSILON)
							{
								g_maxdiscardedlight = VectorMaximum (v);
								VectorCopy (samp->pos, g_maxdiscardedpos);
							}
							ThreadUnlock ();
						}
		#endif
					}
	#else
					VectorAdd (samp->light, v, samp->light);
	#endif
				}
			} // loop samples
		}
	}

#ifndef HLRAD_LOCALTRIANGULATION
	FreeTriangulation (trian);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, 0x10(%rsp)
movslq %edi, %rax
imulq $0x14, %rax, %rcx
leaq 0x1b8f568(%rip), %rdx   # 0x1bad410
movswq 0xa(%rdx,%rcx), %rcx
imulq $0x28, %rcx, %rcx
leaq 0x118f547(%rip), %rdx   # 0x11ad400
testb $0x1, 0x24(%rdx,%rcx)
jne 0x1e0a2
leaq 0x51d0ad5(%rip), %rcx   # 0x51ee9a0
leaq (%rcx,%rax,8), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x1e0a2
movq %rax, 0x18(%rsp)
movslq (%rax), %rax
imulq $0x28, %rax, %r13
leaq 0x4f50ad2(%rip), %rcx   # 0x4f6e9c0
addq %rcx, %r13
imulq $0x14, %rax, %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
cmpq $0x4, %rbp
je 0x1e094
leaq 0x1b8f503(%rip), %rax   # 0x1bad410
movq 0x20(%rsp), %rcx
addq %rcx, %rax
cmpb $-0x1, 0xc(%rbp,%rax)
je 0x1e094
leaq (%rax,%rbp), %r14
addq $0xc, %r14
xorl %r12d, %r12d
xorl %r15d, %r15d
movslq (%r13), %rax
cmpq %rax, %r15
jge 0x1e08c
movq 0x8(%r13,%rbp,8), %rbx
movl 0x10(%rsp), %eax
cmpl %eax, 0x18(%rbx,%r12)
jne 0x1e080
leaq (%rbx,%r12), %rdi
movzbl (%r14), %eax
movl %eax, 0x14(%rsp)
movl 0x18(%rbx,%r12), %esi
pushq $0x1
popq %rdx
leaq 0x14(%rsp), %rcx
leaq 0x4(%rsp), %r8
callq 0xc628
movss 0xc(%rbx,%r12), %xmm0
addss 0x4(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x10(%rbx,%r12), %xmm2
addss 0x8(%rsp), %xmm2
movss %xmm2, 0x8(%rsp)
movss 0x14(%rbx,%r12), %xmm1
addss 0xc(%rsp), %xmm1
movss %xmm1, 0xc(%rsp)
maxss %xmm1, %xmm2
movaps %xmm0, %xmm1
maxss %xmm2, %xmm1
movzbl (%r14), %eax
leaq 0x54d8aaf(%rip), %rcx   # 0x54f6a70
ucomiss (%rcx,%rax,4), %xmm1
jae 0x1e05f
leaq 0x5518b8e(%rip), %rax   # 0x5536b60
cvtss2sd (%rax), %xmm0
cvtss2sd %xmm1, %xmm1
addsd 0x1409e(%rip), %xmm0    # 0x32080
ucomisd %xmm0, %xmm1
jbe 0x1e080
callq 0x9e0c
movss 0x8(%rsp), %xmm1
maxss 0xc(%rsp), %xmm1
movss 0x4(%rsp), %xmm0
maxss %xmm1, %xmm0
leaq 0x5518b52(%rip), %rax   # 0x5536b60
cvtss2sd (%rax), %xmm1
cvtss2sd %xmm0, %xmm2
addsd 0x14062(%rip), %xmm1    # 0x32080
ucomisd %xmm1, %xmm2
jbe 0x1e058
leaq 0x5518b35(%rip), %rax   # 0x5536b60
movss %xmm0, (%rax)
movss (%rbx,%r12), %xmm0
leaq 0x5518b28(%rip), %rax   # 0x5536b64
movss %xmm0, (%rax)
movss 0x4(%rbx,%r12), %xmm0
movss %xmm0, 0x4(%rax)
movss 0x8(%rbx,%r12), %xmm0
movss %xmm0, 0x8(%rax)
callq 0x9e1d
jmp 0x1e080
movss %xmm0, 0xc(%rbx,%r12)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0x10(%rbx,%r12)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x14(%rbx,%r12)
incq %r15
addq $0x1c, %r12
jmp 0x1df2e
incq %rbp
jmp 0x1defc
movq 0x18(%rsp), %rax
addq $0x8, %rax
jmp 0x1decf
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq