// File: 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:
subq $0x68, %rsp
movq 0x70(%rsp), %rax
movl %edi, 0x64(%rsp)
movl %esi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movl %ecx, 0x54(%rsp)
movq %r8, 0x48(%rsp)
movl %r9d, 0x44(%rsp)
movl 0x60(%rsp), %eax
movl 0x64(%rsp), %ecx
shll %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
sete %al
movzbl %al, %edi
andl $0x1, %edi
xorl %esi, %esi
callq 0xbf00
movl 0x54(%rsp), %eax
movl 0x64(%rsp), %ecx
shll %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
shll $0x2, %ecx
subl $0x4, %ecx
cmpl %ecx, %eax
sete %al
movzbl %al, %edi
andl $0x1, %edi
xorl %esi, %esi
callq 0xbf00
movl 0x44(%rsp), %eax
movl 0x64(%rsp), %ecx
shll %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
shll %ecx
cmpl %ecx, %eax
sete %al
movzbl %al, %edi
andl $0x1, %edi
xorl %esi, %esi
callq 0xbf00
movl 0x60(%rsp), %edx
movslq 0x64(%rsp), %rcx
leaq 0x4f76302(%rip), %rax   # 0x4fa7900
movl %edx, (%rax,%rcx,4)
movslq 0x60(%rsp), %rax
imulq $0xc, %rax, %rdi
callq 0x4430
movq %rax, %rdx
movslq 0x64(%rsp), %rcx
leaq 0x4f76312(%rip), %rax   # 0x4fa7930
movq %rdx, (%rax,%rcx,8)
movslq 0x60(%rsp), %rdi
shlq $0x2, %rdi
callq 0x4430
movq %rax, %rdx
movslq 0x64(%rsp), %rcx
leaq 0x4f76341(%rip), %rax   # 0x4fa7980
movq %rdx, (%rax,%rcx,8)
movslq 0x64(%rsp), %rcx
leaq 0x4f762e1(%rip), %rax   # 0x4fa7930
cmpq $0x0, (%rax,%rcx,8)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbf00
movslq 0x64(%rsp), %rcx
leaq 0x4f7630d(%rip), %rax   # 0x4fa7980
cmpq $0x0, (%rax,%rcx,8)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbf00
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x60(%rsp), %eax
jge 0x3177d
movq 0x58(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movslq 0x64(%rsp), %rcx
leaq 0x4f7626a(%rip), %rax   # 0x4fa7930
movq (%rax,%rcx,8), %rax
movslq 0x40(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
movq 0x58(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movslq 0x64(%rsp), %rcx
leaq 0x4f76230(%rip), %rax   # 0x4fa7930
movq (%rax,%rcx,8), %rax
movslq 0x40(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
movq 0x58(%rsp), %rax
movslq 0x40(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movslq 0x64(%rsp), %rcx
leaq 0x4f761f5(%rip), %rax   # 0x4fa7930
movq (%rax,%rcx,8), %rax
movslq 0x40(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
movslq 0x64(%rsp), %rcx
leaq 0x4f76224(%rip), %rax   # 0x4fa7980
movq (%rax,%rcx,8), %rax
movslq 0x40(%rsp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x31693
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x31ad5
movl $0x0, 0x3c(%rsp)
cmpl $0x3, 0x3c(%rsp)
jge 0x31805
movq 0x48(%rsp), %rax
movq 0x70(%rsp), %rcx
movslq 0x40(%rsp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movslq 0x3c(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq 0x70(%rsp), %rcx
movslq 0x40(%rsp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movslq 0x3c(%rsp), %rdx
movslq 0xc(%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %ecx
movslq 0x3c(%rsp), %rax
movl %ecx, 0x24(%rsp,%rax,4)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x317a4
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq 0x58(%rsp), %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm2
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm1
movq 0x58(%rsp), %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
mulsd 0x8(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movq 0x58(%rsp), %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm1
movq 0x58(%rsp), %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
mulsd 0x10(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq 0x58(%rsp), %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm2
movq 0x58(%rsp), %rax
movslq 0x24(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq 0x58(%rsp), %rax
movslq 0x28(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
mulsd (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd (%rsp), %xmm1
movq 0x58(%rsp), %rax
movslq 0x2c(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movsd 0x8(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x2c(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
mulsd 0x8(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
movq 0x58(%rsp), %rax
movslq 0x2c(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
movzbl %al, %edi
andl $0x1, %edi
xorl %esi, %esi
callq 0xbf00
movsd 0x18(%rsp), %xmm1
movsd 0x3c206(%rip), %xmm0    # 0x6dc10
divsd %xmm0, %xmm1
movslq 0x64(%rsp), %rcx
leaq 0x4f75f66(%rip), %rax   # 0x4fa7980
movq (%rax,%rcx,8), %rax
movslq 0x24(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movsd 0x18(%rsp), %xmm1
movsd 0x3c1c9(%rip), %xmm0    # 0x6dc10
divsd %xmm0, %xmm1
movslq 0x64(%rsp), %rcx
leaq 0x4f75f29(%rip), %rax   # 0x4fa7980
movq (%rax,%rcx,8), %rax
movslq 0x28(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movsd 0x18(%rsp), %xmm1
movsd 0x3c18c(%rip), %xmm0    # 0x6dc10
divsd %xmm0, %xmm1
movslq 0x64(%rsp), %rcx
leaq 0x4f75eec(%rip), %rax   # 0x4fa7980
movq (%rax,%rcx,8), %rax
movslq 0x2c(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movsd 0x18(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x3178e
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x60(%rsp), %eax
jge 0x31b25
movsd 0x30(%rsp), %xmm1
movslq 0x64(%rsp), %rcx
leaq 0x4f75e87(%rip), %rax   # 0x4fa7980
movq (%rax,%rcx,8), %rax
movslq 0x40(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x31add
addq $0x68, %rsp
retq
nopw (%rax,%rax)