// File: /workspace/github_cpp_makefile_star2_O1/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, 0x4f58714(%rip)   # 0x4f728e0
xorl %r15d, %r15d
movq %r15, 0x4f5873a(%rip)   # 0x4f72910
movq %r15, 0x4f58783(%rip)   # 0x4f72960
movl $0x180030, %edi         # imm = 0x180030
callq 0x4410
movq %rax, %r13
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %ebx
movl $0x1, %esi
callq 0xa7c9
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r13)
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x18(%r13)
movups %xmm0, 0x20(%r13)
movq %r15, 0x30(%r13)
movq %rax, 0x38(%r13)
movups %xmm0, 0x40(%r13)
movq %rcx, 0x50(%r13)
movups %xmm0, 0x58(%r13)
movq %r15, 0x68(%r13)
movq %rax, 0x70(%r13)
movups %xmm0, 0x78(%r13)
movq %rcx, 0x88(%r13)
movl $0x4fffb0, %edi         # imm = 0x4FFFB0
callq 0x4410
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, (%r14)
leaq 0x8(%r14), %rax
movq %rax, 0x78(%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 0x4410
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movaps 0x217ef(%rip), %xmm0    # 0x3bb80
movups %xmm0, (%r15)
movaps 0x217f4(%rip), %xmm0    # 0x3bb90
movups %xmm0, 0x10(%r15)
movaps 0x217f8(%rip), %xmm0    # 0x3bba0
movups %xmm0, 0x20(%r15)
movaps 0x217fc(%rip), %xmm0    # 0x3bbb0
movups %xmm0, 0x30(%r15)
movaps 0x21800(%rip), %xmm0    # 0x3bbc0
movups %xmm0, 0x40(%r15)
movaps 0x21804(%rip), %xmm0    # 0x3bbd0
movups %xmm0, 0x50(%r15)
movaps 0x21808(%rip), %xmm0    # 0x3bbe0
movups %xmm0, 0x60(%r15)
movaps 0x2180c(%rip), %xmm0    # 0x3bbf0
movups %xmm0, 0x70(%r15)
movaps 0x21810(%rip), %xmm0    # 0x3bc00
movups %xmm0, 0x80(%r15)
movaps 0x21811(%rip), %xmm0    # 0x3bc10
movups %xmm0, 0x90(%r15)
movaps 0x21812(%rip), %xmm0    # 0x3bc20
movups %xmm0, 0xa0(%r15)
movapd 0x21812(%rip), %xmm0    # 0x3bc30
movupd %xmm0, 0xb0(%r15)
movq %r15, (%rsp)
movl $0x6, %r12d
movl $0xc, %ebp
movl $0x8, 0x20(%rsp)
movl $0x1, %edi
movl $0x6, %esi
movq %r13, %rdx
movl $0xc, %ecx
movq %r14, %r8
movl $0x8, %r9d
callq 0x19e6a
leaq 0x14(%r15), %rax
movq %rax, 0x70(%rsp)
movq %r15, 0x28(%rsp)
leaq 0xc(%r15), %rax
movq %rax, 0x60(%rsp)
movq %r14, 0x30(%rsp)
movq %r13, 0x48(%rsp)
movl %ebx, 0x1c(%rsp)
testl %ebp, %ebp
movq %rbp, 0x8(%rsp)
jle 0x1a646
movl %ebp, %eax
shlq $0x2, %rax
leaq (%rax,%rax,4), %rax
xorl %ebx, %ebx
movq %rax, 0x38(%rsp)
cmpb $0x0, 0x8(%r14,%rbx)
jne 0x1a639
xorl %edi, %edi
cmpl $0x10002, %r12d         # imm = 0x10002
setl %dil
xorl %esi, %esi
callq 0xa7c9
movslq (%r14,%rbx), %rax
leaq (%rax,%rax,2), %rax
movslq 0x4(%r14,%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movsd 0x10(%r13,%rax,8), %xmm2
addsd 0x10(%r13,%rcx,8), %xmm2
movupd (%r13,%rax,8), %xmm0
movupd (%r13,%rcx,8), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulpd %xmm1, %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm1, 0x50(%rsp)
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm2, 0x10(%rsp)
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x20de2(%rip), %xmm0    # 0x3b308
jb 0x1a52e
sqrtsd %xmm0, %xmm0
jmp 0x1a533
callq 0x4240
movsd %xmm0, 0x40(%rsp)
movslq %r12d, %rax
leaq (%rax,%rax,2), %rax
leaq (,%rax,8), %r14
addq %r13, %r14
xorl %edi, %edi
ucomisd 0x215cb(%rip), %xmm0    # 0x3bb20
seta %dil
xorl %esi, %esi
callq 0xa7c9
movsd 0x20c00(%rip), %xmm0    # 0x3b168
divsd 0x40(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd 0x50(%rsp), %xmm2
mulpd %xmm0, %xmm2
movupd %xmm2, (%r14)
movsd %xmm1, 0x10(%r14)
leal 0x1(%r12), %eax
movl %eax, 0x10(%rsp)
xorl %edi, %edi
movq 0x8(%rsp), %r13
cmpl $0x3fffc, %r13d         # imm = 0x3FFFC
setl %dil
xorl %esi, %esi
callq 0xa7c9
movq 0x30(%rsp), %r14
movl %r13d, 0xc(%r14,%rbx)
movslq %r13d, %r13
leaq (,%r13,4), %rax
addq %r13, %rax
xorl %ebp, %ebp
movb %bpl, 0x8(%r14,%rax,4)
movl (%r14,%rbx), %ecx
movl %ecx, (%r14,%rax,4)
movl %r12d, 0x4(%r14,%rax,4)
movq %r12, %r15
leal 0x1(%r13), %r12d
xorl %edi, %edi
cmpl $0x3fffb, %r13d         # imm = 0x3FFFB
setl %dil
xorl %esi, %esi
callq 0xa7c9
movl %r12d, 0x10(%r14,%rbx)
movslq %r12d, %rax
leaq (%rax,%rax,4), %rax
movb %bpl, 0x8(%r14,%rax,4)
movl %r15d, (%r14,%rax,4)
movl 0x4(%r14,%rbx), %ecx
movl %ecx, 0x4(%r14,%rax,4)
addl $0x2, %r13d
movq %r13, 0x8(%rsp)
movq 0x48(%rsp), %r13
movb $0x1, 0x8(%r14,%rbx)
movl 0x10(%rsp), %eax
movl %eax, %r12d
movq 0x38(%rsp), %rax
addq $0x14, %rbx
cmpq %rbx, %rax
jne 0x1a4a1
movl 0x20(%rsp), %r9d
testl %r9d, %r9d
jle 0x1a83d
movq %r12, 0x68(%rsp)
movl %r9d, %eax
movq %rax, 0x80(%rsp)
movq 0x60(%rsp), %r15
xorl %edi, %edi
movq 0x8(%rsp), %rdx
movl %r9d, %esi
movq %rdi, 0x38(%rsp)
leaq (%rdi,%rdi,2), %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movq %rdx, 0x8(%rsp)
movslq %edx, %rdx
movq %rsi, 0x40(%rsp)
movslq %esi, %rax
movq %rax, 0x50(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x70(%rsp), %rcx
leaq (%rcx,%rax,8), %r14
movq %rdx, 0x20(%rsp)
movl %edx, %eax
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
movq 0x30(%rsp), %rbp
movq %rbx, %r13
movq 0x50(%rsp), %rax
addq %rbx, %rax
xorl %edi, %edi
cmpq $0x20000, %rax          # imm = 0x20000
setl %dil
xorl %esi, %esi
callq 0xa7c9
movslq -0xc(%r15,%rbx,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,%rbx,4)
movslq (%r15,%rbx,4), %rax
movl $0x1, %edx
subq %rax, %rdx
movl 0xc(%rcx,%rdx,4), %eax
movl %eax, -0x14(%r14)
movl (%r15,%rbx,4), %eax
movl %eax, -0x8(%r14)
incq %rbx
cmpq $0x2, %r13
movl $0x0, %eax
cmovneq %rbx, %rax
movslq (%r12,%rax,4), %rcx
movslq 0xc(%r12,%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(%r12,%rax,4), %eax
movl %eax, -0x4(%r14)
addl 0x10(%rsp), %r13d
movl %r13d, -0xc(%r14)
movl $0x1, (%r14)
addq $0x18, %r14
cmpq $0x3, %rbx
jne 0x1a6ba
movq 0x20(%rsp), %rbp
leaq (,%rbp,4), %rax
addq %rbp, %rax
movq 0x78(%rsp), %rcx
leaq (%rcx,%rax,4), %r14
xorl %eax, %eax
movq 0x10(%rsp), %r13
movq %rax, %r12
addq %rbp, %rax
xorl %edi, %edi
cmpq $0x3fffc, %rax          # imm = 0x3FFFC
setl %dil
xorl %esi, %esi
callq 0xa7c9
leal (%r12,%r13), %eax
movl %eax, -0xc(%r15,%r12,4)
movl $0x0, (%r15,%r12,4)
movb $0x0, (%r14)
movl 0x8c(%rsp,%r12,4), %eax
movl %eax, -0x8(%r14)
leaq 0x1(%r12), %rax
cmpq $0x2, %r12
movl $0x0, %ecx
cmovneq %rax, %rcx
movl 0x8c(%rsp,%rcx,4), %ecx
movl %ecx, -0x4(%r14)
addq $0x14, %r14
cmpq $0x3, %rax
jne 0x1a793
movq 0x40(%rsp), %rcx
leal (%rcx,%rbx), %r9d
movq 0x8(%rsp), %rdx
addl %eax, %edx
movq 0x38(%rsp), %rdi
incq %rdi
addq $0x18, %r15
cmpq 0x80(%rsp), %rdi
jne 0x1a670
addl %ebx, %ecx
addl %r13d, %eax
movl %ecx, %r9d
movl %eax, %ebp
movq 0x48(%rsp), %r13
movl 0x1c(%rsp), %ebx
movq 0x30(%rsp), %r14
movq 0x68(%rsp), %r12
jmp 0x1a846
movl 0x1c(%rsp), %ebx
movq 0x8(%rsp), %rbp
incl %ebx
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movl %ebx, %edi
movl %r12d, %esi
movq %r13, %rdx
movl %ebp, %ecx
movq %r14, %r8
movl %r9d, 0x20(%rsp)
callq 0x19e6a
cmpl $0x8, %ebx
jne 0x1a47f
movq %r13, %rdi
callq 0x4380
movq %r14, %rdi
callq 0x4380
movq 0x28(%rsp), %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4380