// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlrad/lightmap.cpp
// Function: CopyToSkynormals(int, int, double (*) [3], int, edge_t*, int, triangle_t*)
void CopyToSkynormals (int skylevel, int numpoints, point_t *points, int numedges, edge_t *edges, int numtriangles, triangle_t *triangles)
{
	hlassume (numpoints == (1 << (2 * skylevel)) + 2, assume_first);
	hlassume (numedges == (1 << (2 * skylevel)) * 4 - 4 , assume_first);
	hlassume (numtriangles == (1 << (2 * skylevel)) * 2, assume_first);
	g_numskynormals[skylevel] = numpoints;
	g_skynormals[skylevel] = (vec3_t *)malloc (numpoints * sizeof (vec3_t));
	g_skynormalsizes[skylevel] = (vec_t *)malloc (numpoints * sizeof (vec_t));
	hlassume (g_skynormals[skylevel] != NULL, assume_NoMemory);
	hlassume (g_skynormalsizes[skylevel] != NULL, assume_NoMemory);
	int j, k;
	for (j = 0; j < numpoints; j++)
	{
		VectorCopy (points[j], g_skynormals[skylevel][j]);
		g_skynormalsizes[skylevel][j] = 0;
	}
	double totalsize = 0;
	for (j = 0; j < numtriangles; j++)
	{
		int pt[3];
		for (k = 0; k < 3; k++)
		{
			pt[k] = edges[triangles[j].edge[k]].point[triangles[j].dir[k]];
		}
		double currentsize;
		double tmp[3];
		CrossProduct (points[pt[0]], points[pt[1]], tmp);
		currentsize = DotProduct (tmp, points[pt[2]]);
		hlassume (currentsize > 0, assume_first);
		g_skynormalsizes[skylevel][pt[0]] += currentsize / 3.0;
		g_skynormalsizes[skylevel][pt[1]] += currentsize / 3.0;
		g_skynormalsizes[skylevel][pt[2]] += currentsize / 3.0;
		totalsize += currentsize;
	}
	for (j = 0; j < numpoints; j++)
	{
		g_skynormalsizes[skylevel][j] /= totalsize;
	}
#if 0
	printf ("g_numskynormals[%i]=%i\n", skylevel, g_numskynormals[skylevel]);
	for (j = 0; j < numpoints; j += (numpoints / 20 + 1))
	{
		printf ("g_skynormals[%i][%i]=%1.3f,%1.3f,%1.3f g_skynormalsizes[%i][%i]=%f\n",
			skylevel, j, g_skynormals[skylevel][j][0], g_skynormals[skylevel][j][1], g_skynormals[skylevel][j][2],
			skylevel, j, g_skynormalsizes[skylevel][j]);
	}
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x8(%rsp)
movq %r8, %r14
movl %ecx, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movl %esi, %r15d
movq %rdi, (%rsp)
movq 0x80(%rsp), %rbp
leal (%rdi,%rdi), %r13d
pushq $0x2
popq %rbx
movl %ebx, %eax
btsl %r13d, %eax
xorl %edi, %edi
cmpl %esi, %eax
sete %dil
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x92cb
pushq $0x4
popq %rax
movl %r13d, %ecx
shll %cl, %eax
addl $-0x4, %eax
xorl %edi, %edi
cmpl 0x10(%rsp), %eax
sete %dil
xorl %esi, %esi
callq 0x92cb
movl %r13d, %ecx
shll %cl, %ebx
xorl %edi, %edi
cmpl 0x8(%rsp), %ebx
sete %dil
xorl %esi, %esi
callq 0x92cb
movslq (%rsp), %r13
leaq 0x4f57a38(%rip), %rax   # 0x4f6e8f0
movl %r15d, (%rax,%r13,4)
movslq %r15d, %r15
imulq $0xc, %r15, %rdi
callq 0x4420
movq %rax, (%rsp)
leaq 0x4f57a4d(%rip), %rbx   # 0x4f6e920
movq %rax, (%rbx,%r13,8)
leaq (,%r15,4), %rdi
callq 0x4420
leaq 0x4f57a85(%rip), %rcx   # 0x4f6e970
movq %rax, (%rcx,%r13,8)
xorl %edi, %edi
cmpq $0x0, (%rsp)
setne %dil
pushq $0x1
popq %rsi
callq 0x92cb
xorl %edi, %edi
leaq 0x4f57a65(%rip), %rax   # 0x4f6e970
cmpq $0x0, (%rax,%r13,8)
setne %dil
pushq $0x1
popq %rsi
callq 0x92cb
leaq 0x4f57a4d(%rip), %r8    # 0x4f6e970
movq %r13, %rsi
testl %r15d, %r15d
cmovlel %r12d, %r15d
movq %r15, 0x30(%rsp)
imulq $0xc, %r15, %rax
xorl %ecx, %ecx
movq 0x18(%rsp), %rdi
cmpq %rcx, %rax
je 0x16f83
cvtsd2ss (%rdi,%rcx,2), %xmm0
movq (%rbx,%rsi,8), %rdx
movss %xmm0, (%rdx,%rcx)
cvtsd2ss 0x8(%rdi,%rcx,2), %xmm0
movq (%rbx,%rsi,8), %rdx
movss %xmm0, 0x4(%rdx,%rcx)
cvtsd2ss 0x10(%rdi,%rcx,2), %xmm0
movq (%rbx,%rsi,8), %rdx
movss %xmm0, 0x8(%rdx,%rcx)
movq (%r8,%rsi,8), %rdx
andl $0x0, (%rdx,%r12)
addq $0xc, %rcx
addq $0x4, %r12
jmp 0x16f3d
xorl %eax, %eax
movq 0x8(%rsp), %r13
testl %r13d, %r13d
cmovlel %eax, %r13d
movq %r13, 0x8(%rsp)
addq $0xc, %rbp
xorpd %xmm1, %xmm1
cmpq 0x8(%rsp), %rax
je 0x170fe
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpq $0x3, %rax
je 0x16fd3
movslq -0xc(%rbp,%rax,4), %rcx
imulq $0x14, %rcx, %rcx
addq %r14, %rcx
movslq (%rbp,%rax,4), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x24(%rsp,%rax,4)
incq %rax
jmp 0x16fb0
movslq 0x24(%rsp), %r12
imulq $0x18, %r12, %rax
movq 0x18(%rsp), %rdx
movsd (%rdx,%rax), %xmm6
movsd 0x8(%rdx,%rax), %xmm2
movslq 0x28(%rsp), %rcx
movq %rcx, 0x40(%rsp)
imulq $0x18, %rcx, %rcx
movsd 0x10(%rdx,%rcx), %xmm3
movsd 0x10(%rdx,%rax), %xmm0
movsd (%rdx,%rcx), %xmm4
movsd 0x8(%rdx,%rcx), %xmm5
movsd %xmm1, (%rsp)
movapd %xmm2, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm6, %xmm3
mulsd %xmm5, %xmm6
mulsd %xmm0, %xmm5
subsd %xmm5, %xmm1
mulsd %xmm4, %xmm0
subsd %xmm3, %xmm0
mulsd %xmm2, %xmm4
movslq 0x2c(%rsp), %r13
imulq $0x18, %r13, %rax
mulsd 0x8(%rdx,%rax), %xmm0
subsd %xmm4, %xmm6
mulsd (%rdx,%rax), %xmm1
addsd %xmm0, %xmm1
mulsd 0x10(%rdx,%rax), %xmm6
addsd %xmm1, %xmm6
movsd %xmm6, 0x38(%rsp)
xorl %edi, %edi
ucomisd 0x1e5a8(%rip), %xmm6    # 0x35618
seta %dil
movq %rsi, %r15
xorl %esi, %esi
movq %r8, %rbx
callq 0x92cb
movq %rbx, %r8
movq %r15, %rsi
movsd 0x38(%rsp), %xmm2
movapd %xmm2, %xmm0
movq (%rbx,%r15,8), %rax
cvtss2sd (%rax,%r12,4), %xmm1
divsd 0x1e9b5(%rip), %xmm0    # 0x35a58
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rax,%r12,4)
movq (%rbx,%r15,8), %rax
movq 0x40(%rsp), %rcx
cvtss2sd (%rax,%rcx,4), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rax,%rcx,4)
movq (%rbx,%r15,8), %rax
cvtss2sd (%rax,%r13,4), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movsd (%rsp), %xmm1
movss %xmm0, (%rax,%r13,4)
addsd %xmm2, %xmm1
movq 0x10(%rsp), %rax
incq %rax
addq $0x18, %rbp
jmp 0x16f9e
xorl %eax, %eax
movq 0x30(%rsp), %rdx
cmpq %rax, %rdx
je 0x17125
movq (%r8,%rsi,8), %rcx
cvtss2sd (%rcx,%rax,4), %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rcx,%rax,4)
incq %rax
jmp 0x17105
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq