// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/lightmap.cpp
// Function: BuildDiffuseNormals()
void BuildDiffuseNormals ()
{
	int i, j, k;
	g_numskynormals[0] = 0;
	g_skynormals[0] = NULL; //don't use this
	g_skynormalsizes[0] = NULL;
	int numpoints = 6;
	point_t *points = (point_t *)malloc (((1 << (2 * SKYLEVELMAX)) + 2) * sizeof (point_t));
	hlassume (points != NULL, assume_NoMemory);
	points[0][0] = 1, points[0][1] = 0, points[0][2] = 0;
	points[1][0] = -1,points[1][1] = 0, points[1][2] = 0;
	points[2][0] = 0, points[2][1] = 1, points[2][2] = 0;
	points[3][0] = 0, points[3][1] = -1,points[3][2] = 0;
	points[4][0] = 0, points[4][1] = 0, points[4][2] = 1;
	points[5][0] = 0, points[5][1] = 0, points[5][2] = -1;
	int numedges = 12;
	edge_t *edges = (edge_t *)malloc (((1 << (2 * SKYLEVELMAX)) * 4 - 4) * sizeof (edge_t));
	hlassume (edges != NULL, assume_NoMemory);
	edges[0].point[0] = 0, edges[0].point[1] = 2, edges[0].divided = false;
	edges[1].point[0] = 2, edges[1].point[1] = 1, edges[1].divided = false;
	edges[2].point[0] = 1, edges[2].point[1] = 3, edges[2].divided = false;
	edges[3].point[0] = 3, edges[3].point[1] = 0, edges[3].divided = false;
	edges[4].point[0] = 2, edges[4].point[1] = 4, edges[4].divided = false;
	edges[5].point[0] = 4, edges[5].point[1] = 3, edges[5].divided = false;
	edges[6].point[0] = 3, edges[6].point[1] = 5, edges[6].divided = false;
	edges[7].point[0] = 5, edges[7].point[1] = 2, edges[7].divided = false;
	edges[8].point[0] = 4, edges[8].point[1] = 0, edges[8].divided = false;
	edges[9].point[0] = 0, edges[9].point[1] = 5, edges[9].divided = false;
	edges[10].point[0] = 5, edges[10].point[1] = 1, edges[10].divided = false;
	edges[11].point[0] = 1, edges[11].point[1] = 4, edges[11].divided = false;
	int numtriangles = 8;
	triangle_t *triangles = (triangle_t *)malloc (((1 << (2 * SKYLEVELMAX)) * 2) * sizeof (triangle_t));
	hlassume (triangles != NULL, assume_NoMemory);
	triangles[0].edge[0] = 0, triangles[0].dir[0] = 0, triangles[0].edge[1] = 4, triangles[0].dir[1] = 0, triangles[0].edge[2] = 8, triangles[0].dir[2] = 0;
	triangles[1].edge[0] = 1, triangles[1].dir[0] = 0, triangles[1].edge[1] = 11, triangles[1].dir[1] = 0, triangles[1].edge[2] = 4, triangles[1].dir[2] = 1;
	triangles[2].edge[0] = 2, triangles[2].dir[0] = 0, triangles[2].edge[1] = 5, triangles[2].dir[1] = 1, triangles[2].edge[2] = 11, triangles[2].dir[2] = 1;
	triangles[3].edge[0] = 3, triangles[3].dir[0] = 0, triangles[3].edge[1] = 8, triangles[3].dir[1] = 1, triangles[3].edge[2] = 5, triangles[3].dir[2] = 0;
	triangles[4].edge[0] = 0, triangles[4].dir[0] = 1, triangles[4].edge[1] = 9, triangles[4].dir[1] = 0, triangles[4].edge[2] = 7, triangles[4].dir[2] = 0;
	triangles[5].edge[0] = 1, triangles[5].dir[0] = 1, triangles[5].edge[1] = 7, triangles[5].dir[1] = 1, triangles[5].edge[2] = 10, triangles[5].dir[2] = 0;
	triangles[6].edge[0] = 2, triangles[6].dir[0] = 1, triangles[6].edge[1] = 10, triangles[6].dir[1] = 1, triangles[6].edge[2] = 6, triangles[6].dir[2] = 1;
	triangles[7].edge[0] = 3, triangles[7].dir[0] = 1, triangles[7].edge[1] = 6, triangles[7].dir[1] = 0, triangles[7].edge[2] = 9, triangles[7].dir[2] = 1;
	CopyToSkynormals (1, numpoints, points, numedges, edges, numtriangles, triangles);
	for (i = 1; i < SKYLEVELMAX; i++)
	{
		int oldnumedges = numedges;
		for (j = 0; j < oldnumedges; j++)
		{
			if (!edges[j].divided)
			{
				hlassume (numpoints < (1 << (2 * SKYLEVELMAX)) + 2, assume_first);
				point_t mid;
				double len;
				VectorAdd (points[edges[j].point[0]], points[edges[j].point[1]], mid);
				len = sqrt (DotProduct (mid, mid));
				hlassume (len > 0.2, assume_first);
				VectorScale (mid, 1 / len, mid);
				int p2 = numpoints;
				VectorCopy (mid, points[numpoints]);
				numpoints++;
				hlassume (numedges < (1 << (2 * SKYLEVELMAX)) * 4 - 4, assume_first);
				edges[j].child[0] = numedges;
				edges[numedges].divided = false;
				edges[numedges].point[0] = edges[j].point[0];
				edges[numedges].point[1] = p2;
				numedges++;
				hlassume (numedges < (1 << (2 * SKYLEVELMAX)) * 4 - 4, assume_first);
				edges[j].child[1] = numedges;
				edges[numedges].divided = false;
				edges[numedges].point[0] = p2;
				edges[numedges].point[1] = edges[j].point[1];
				numedges++;
				edges[j].divided = true;
			}
		}
		int oldnumtriangles = numtriangles;
		for (j = 0; j < oldnumtriangles; j++)
		{
			int mid[3];
			for (k = 0; k < 3; k++)
			{
				hlassume (numtriangles < (1 << (2 * SKYLEVELMAX)) * 2, assume_first);
				mid[k] = edges[edges[triangles[j].edge[k]].child[0]].point[1];
				triangles[numtriangles].edge[0] = edges[triangles[j].edge[k]].child[1 - triangles[j].dir[k]];
				triangles[numtriangles].dir[0] = triangles[j].dir[k];
				triangles[numtriangles].edge[1] = edges[triangles[j].edge[(k+1)%3]].child[triangles[j].dir[(k+1)%3]];
				triangles[numtriangles].dir[1] = triangles[j].dir[(k+1)%3];
				triangles[numtriangles].edge[2] = numedges + k;
				triangles[numtriangles].dir[2] = 1;
				numtriangles++;
			}
			for (k = 0; k < 3; k++)
			{
				hlassume (numedges < (1 << (2 * SKYLEVELMAX)) * 4 - 4, assume_first);
				triangles[j].edge[k] = numedges;
				triangles[j].dir[k] = 0;
				edges[numedges].divided = false;
				edges[numedges].point[0] = mid[k];
				edges[numedges].point[1] = mid[(k+1)%3];
				numedges++;
			}
		}
		CopyToSkynormals (i + 1, numpoints, points, numedges, edges, numtriangles, triangles);
	}
	free (points);
	free (edges);
	free (triangles);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl $0x0, 0x4f580d8(%rip)   # 0x4f718e0
xorl %r15d, %r15d
movq %r15, 0x4f580fe(%rip)   # 0x4f71910
movq %r15, 0x4f58147(%rip)   # 0x4f71960
movl $0x180030, %edi         # imm = 0x180030
callq 0x4400
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %ebp
movl $0x1, %esi
callq 0xa6ed
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x18(%rbx)
movups %xmm0, 0x20(%rbx)
movq %r15, 0x30(%rbx)
movq %rax, 0x38(%rbx)
movups %xmm0, 0x40(%rbx)
movq %rcx, 0x50(%rbx)
movups %xmm0, 0x58(%rbx)
movq %r15, 0x68(%rbx)
movq %rax, 0x70(%rbx)
movups %xmm0, 0x78(%rbx)
movq %rcx, 0x88(%rbx)
movl $0x4fffb0, %edi         # imm = 0x4FFFB0
callq 0x4400
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, (%r14)
leaq 0x8(%r14), %rax
movq %rax, 0x70(%rsp)
movb %r15b, 0x8(%r14)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14(%r14)
movb %r15b, 0x1c(%r14)
movabsq $0x300000001, %rax      # imm = 0x300000001
movq %rax, 0x28(%r14)
movb %r15b, 0x30(%r14)
movq $0x3, 0x3c(%r14)
movb %r15b, 0x44(%r14)
movabsq $0x400000002, %rax      # imm = 0x400000002
movq %rax, 0x50(%r14)
movb %r15b, 0x58(%r14)
movabsq $0x300000004, %rax      # imm = 0x300000004
movq %rax, 0x64(%r14)
movb %r15b, 0x6c(%r14)
movabsq $0x500000003, %rax      # imm = 0x500000003
movq %rax, 0x78(%r14)
movb %r15b, 0x80(%r14)
movabsq $0x200000005, %rax      # imm = 0x200000005
movq %rax, 0x8c(%r14)
movb %r15b, 0x94(%r14)
movq $0x4, 0xa0(%r14)
movb %r15b, 0xa8(%r14)
movabsq $0x500000000, %rax      # imm = 0x500000000
movq %rax, 0xb4(%r14)
movb %r15b, 0xbc(%r14)
movabsq $0x100000005, %rax      # imm = 0x100000005
movq %rax, 0xc8(%r14)
movb %r15b, 0xd0(%r14)
movabsq $0x400000001, %rax      # imm = 0x400000001
movq %rax, 0xdc(%r14)
movb %r15b, 0xe4(%r14)
movl $0x300000, %edi         # imm = 0x300000
callq 0x4400
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movaps 0x21159(%rip), %xmm0    # 0x3ab20
movups %xmm0, (%r15)
movaps 0x2115e(%rip), %xmm0    # 0x3ab30
movups %xmm0, 0x10(%r15)
movaps 0x21162(%rip), %xmm0    # 0x3ab40
movups %xmm0, 0x20(%r15)
movaps 0x21166(%rip), %xmm0    # 0x3ab50
movups %xmm0, 0x30(%r15)
movaps 0x2116a(%rip), %xmm0    # 0x3ab60
movups %xmm0, 0x40(%r15)
movaps 0x2116e(%rip), %xmm0    # 0x3ab70
movups %xmm0, 0x50(%r15)
movaps 0x21172(%rip), %xmm0    # 0x3ab80
movups %xmm0, 0x60(%r15)
movaps 0x21176(%rip), %xmm0    # 0x3ab90
movups %xmm0, 0x70(%r15)
movaps 0x2117a(%rip), %xmm0    # 0x3aba0
movups %xmm0, 0x80(%r15)
movaps 0x2117b(%rip), %xmm0    # 0x3abb0
movups %xmm0, 0x90(%r15)
movaps 0x2117c(%rip), %xmm0    # 0x3abc0
movups %xmm0, 0xa0(%r15)
movapd 0x2117c(%rip), %xmm0    # 0x3abd0
movupd %xmm0, 0xb0(%r15)
movq %r15, (%rsp)
movl $0x6, 0x10(%rsp)
movl $0xc, %r12d
movl $0x8, 0x18(%rsp)
movl $0x1, %edi
movl $0x6, %esi
movq %rbx, 0x20(%rsp)
movq %rbx, %rdx
movl $0xc, %ecx
movq %r14, %r8
movl $0x8, %r9d
callq 0x194a6
leaq 0x14(%r15), %rax
movq %rax, 0x68(%rsp)
movq %r15, 0x28(%rsp)
leaq 0xc(%r15), %rax
movq %rax, 0x60(%rsp)
movq %r14, 0x30(%rsp)
testl %r12d, %r12d
movl %ebp, 0x14(%rsp)
jle 0x19c54
movq %r12, %r13
movl %r12d, %eax
shlq $0x2, %rax
leaq (%rax,%rax,4), %rax
xorl %r15d, %r15d
movq %rax, 0x38(%rsp)
cmpb $0x0, 0x8(%r14,%r15)
jne 0x19c45
xorl %edi, %edi
movl 0x10(%rsp), %ebx
cmpl $0x10002, %ebx          # imm = 0x10002
setl %dil
xorl %esi, %esi
callq 0xa6ed
movslq (%r14,%r15), %rax
leaq (%rax,%rax,2), %rax
movslq 0x4(%r14,%r15), %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x20(%rsp), %rbp
movsd 0x10(%rbp,%rax,8), %xmm0
addsd 0x10(%rbp,%rcx,8), %xmm0
movapd %xmm0, %xmm2
movsd %xmm0, 0x48(%rsp)
movslq %ebx, %r12
leaq (%r12,%r12,2), %r14
movupd (%rbp,%rax,8), %xmm0
movupd (%rbp,%rcx,8), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
movapd %xmm1, %xmm0
mulpd %xmm1, %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
xorl %edi, %edi
ucomisd 0x20f55(%rip), %xmm0    # 0x3aad0
seta %dil
xorl %esi, %esi
callq 0xa6ed
movsd 0x205da(%rip), %xmm0    # 0x3a168
divsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
mulsd %xmm0, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0x50(%rsp), %xmm0
movupd %xmm0, (%rbp,%r14,8)
movsd %xmm1, 0x10(%rbp,%r14,8)
movq 0x30(%rsp), %r14
leal 0x1(%r12), %eax
movl %eax, 0x10(%rsp)
xorl %edi, %edi
cmpl $0x3fffc, %r13d         # imm = 0x3FFFC
setl %dil
xorl %esi, %esi
callq 0xa6ed
movl %r13d, 0xc(%r14,%r15)
movslq %r13d, %r13
leaq (,%r13,4), %rax
addq %r13, %rax
xorl %ebx, %ebx
movb %bl, 0x8(%r14,%rax,4)
movl (%r14,%r15), %ecx
movl %ecx, (%r14,%rax,4)
movl %r12d, 0x4(%r14,%rax,4)
leal 0x1(%r13), %ebp
xorl %edi, %edi
cmpl $0x3fffb, %r13d         # imm = 0x3FFFB
setl %dil
xorl %esi, %esi
callq 0xa6ed
movl %ebp, 0x10(%r14,%r15)
movslq %ebp, %rax
leaq (%rax,%rax,4), %rax
movb %bl, 0x8(%r14,%rax,4)
movl %r12d, (%r14,%rax,4)
movl 0x4(%r14,%r15), %ecx
movl %ecx, 0x4(%r14,%rax,4)
movq 0x38(%rsp), %rax
addl $0x2, %r13d
movb $0x1, 0x8(%r14,%r15)
addq $0x14, %r15
cmpq %r15, %rax
jne 0x19adb
jmp 0x19c57
movq %r12, %r13
movl 0x18(%rsp), %r9d
testl %r9d, %r9d
jle 0x19e3c
movl %r9d, %eax
movq %rax, 0x78(%rsp)
movq 0x60(%rsp), %r15
xorl %edi, %edi
movq %r13, %rdx
movl %r9d, %esi
movq %rdi, 0x18(%rsp)
leaq (%rdi,%rdi,2), %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
movq %rdx, 0x40(%rsp)
movslq %edx, %rdx
movq %rsi, 0x38(%rsp)
movslq %esi, %rax
movq %rax, 0x48(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x68(%rsp), %rcx
leaq (%rcx,%rax,8), %r14
movq %rdx, 0x80(%rsp)
movl %edx, %eax
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
movq 0x30(%rsp), %rbp
movq %r13, %r12
movq 0x48(%rsp), %rax
addq %r13, %rax
xorl %edi, %edi
cmpq $0x20000, %rax          # imm = 0x20000
setl %dil
xorl %esi, %esi
callq 0xa6ed
movslq -0xc(%r15,%r13,4), %rax
leaq (%rax,%rax,4), %rax
leaq (,%rax,4), %rcx
addq %rbp, %rcx
movslq 0xc(%rbp,%rax,4), %rax
leaq (%rax,%rax,4), %rax
movl 0x4(%rbp,%rax,4), %eax
movl %eax, 0x8c(%rsp,%r13,4)
movslq (%r15,%r13,4), %rax
movl $0x1, %edx
subq %rax, %rdx
movl 0xc(%rcx,%rdx,4), %eax
movl %eax, -0x14(%r14)
movl (%r15,%r13,4), %eax
movl %eax, -0x8(%r14)
incq %r13
cmpq $0x2, %r12
movl $0x0, %eax
cmovneq %r13, %rax
movslq (%rbx,%rax,4), %rcx
movslq 0xc(%rbx,%rax,4), %rdx
leaq (%rcx,%rcx,4), %rcx
leaq (,%rcx,4), %rcx
addq %rbp, %rcx
movl 0xc(%rcx,%rdx,4), %ecx
movl %ecx, -0x10(%r14)
movl 0xc(%rbx,%rax,4), %eax
movl %eax, -0x4(%r14)
addl 0x50(%rsp), %r12d
movl %r12d, -0xc(%r14)
movl $0x1, (%r14)
addq $0x18, %r14
cmpq $0x3, %r13
jne 0x19cc5
movq 0x80(%rsp), %rbp
leaq (,%rbp,4), %rax
addq %rbp, %rax
movq 0x70(%rsp), %rcx
leaq (%rcx,%rax,4), %rbx
xorl %eax, %eax
movq 0x50(%rsp), %r12
movq %rax, %r14
addq %rbp, %rax
xorl %edi, %edi
cmpq $0x3fffc, %rax          # imm = 0x3FFFC
setl %dil
xorl %esi, %esi
callq 0xa6ed
leal (%r12,%r14), %eax
movl %eax, -0xc(%r15,%r14,4)
movl $0x0, (%r15,%r14,4)
movb $0x0, (%rbx)
movl 0x8c(%rsp,%r14,4), %eax
movl %eax, -0x8(%rbx)
leaq 0x1(%r14), %rax
cmpq $0x2, %r14
movl $0x0, %ecx
cmovneq %rax, %rcx
movl 0x8c(%rsp,%rcx,4), %ecx
movl %ecx, -0x4(%rbx)
addq $0x14, %rbx
cmpq $0x3, %rax
jne 0x19da1
movq 0x38(%rsp), %rcx
leal (%rcx,%r13), %r9d
movq 0x40(%rsp), %rdx
addl %eax, %edx
movq 0x18(%rsp), %rdi
incq %rdi
addq $0x18, %r15
cmpq 0x78(%rsp), %rdi
jne 0x19c77
addl %r13d, %ecx
addl %r12d, %eax
movl %ecx, %r9d
movl %eax, %r12d
movl 0x14(%rsp), %ebx
movq 0x30(%rsp), %r14
jmp 0x19e43
movl 0x14(%rsp), %ebx
movq %r13, %r12
incl %ebx
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movl %ebx, %edi
movl 0x10(%rsp), %esi
movq 0x20(%rsp), %rdx
movl %r12d, %ecx
movq %r14, %r8
movl %r9d, 0x18(%rsp)
callq 0x194a6
cmpl $0x8, %ebx
movl %ebx, %ebp
jne 0x19ab8
movq 0x20(%rsp), %rdi
callq 0x4370
movq %r14, %rdi
callq 0x4370
movq 0x28(%rsp), %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4370