// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
andl $0x0, 0x4f577a4(%rip)   # 0x4f6e8f0
andq $0x0, 0x4f577cc(%rip)   # 0x4f6e920
andq $0x0, 0x4f57814(%rip)   # 0x4f6e970
movl $0x180030, %edi         # imm = 0x180030
callq 0x4420
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0x92cb
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, 0x18(%rbx)
andq $0x0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movq %rax, 0x38(%rbx)
movups %xmm0, 0x40(%rbx)
movq %rcx, 0x50(%rbx)
andq $0x0, 0x68(%rbx)
movups %xmm0, 0x58(%rbx)
movq %rax, 0x70(%rbx)
movups %xmm0, 0x78(%rbx)
movq %rcx, 0x88(%rbx)
movl $0x4fffb0, %edi         # imm = 0x4FFFB0
callq 0x4420
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl %ebp, %esi
callq 0x92cb
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, (%r14)
leaq 0x8(%r14), %rax
movq %rax, 0x68(%rsp)
xorl %ecx, %ecx
movb %cl, 0x8(%r14)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14(%r14)
movb %cl, 0x1c(%r14)
movabsq $0x300000001, %rax      # imm = 0x300000001
movq %rax, 0x28(%r14)
movb %cl, 0x30(%r14)
movq $0x3, 0x3c(%r14)
movb %cl, 0x44(%r14)
movabsq $0x400000002, %rax      # imm = 0x400000002
movq %rax, 0x50(%r14)
movb %cl, 0x58(%r14)
movabsq $0x300000004, %rax      # imm = 0x300000004
movq %rax, 0x64(%r14)
movb %cl, 0x6c(%r14)
movabsq $0x500000003, %rax      # imm = 0x500000003
movq %rax, 0x78(%r14)
movb %cl, 0x80(%r14)
movabsq $0x200000005, %rax      # imm = 0x200000005
movq %rax, 0x8c(%r14)
movb %cl, 0x94(%r14)
movq $0x4, 0xa0(%r14)
movb %cl, 0xa8(%r14)
movabsq $0x500000000, %rax      # imm = 0x500000000
movq %rax, 0xb4(%r14)
movb %cl, 0xbc(%r14)
movabsq $0x100000005, %rax      # imm = 0x100000005
movq %rax, 0xc8(%r14)
movb %cl, 0xd0(%r14)
movabsq $0x400000001, %rax      # imm = 0x400000001
movq %rax, 0xdc(%r14)
movb %cl, 0xe4(%r14)
movl $0x300000, %edi         # imm = 0x300000
callq 0x4420
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl %ebp, %esi
callq 0x92cb
movaps 0x1e7ad(%rip), %xmm0    # 0x35ab0
movups %xmm0, (%r15)
movaps 0x1e7b2(%rip), %xmm0    # 0x35ac0
movups %xmm0, 0x10(%r15)
movaps 0x1e7b6(%rip), %xmm0    # 0x35ad0
movups %xmm0, 0x20(%r15)
movaps 0x1e7ba(%rip), %xmm0    # 0x35ae0
movups %xmm0, 0x30(%r15)
movaps 0x1e7be(%rip), %xmm0    # 0x35af0
movups %xmm0, 0x40(%r15)
movaps 0x1e7c2(%rip), %xmm0    # 0x35b00
movups %xmm0, 0x50(%r15)
movaps 0x1e7c6(%rip), %xmm0    # 0x35b10
movups %xmm0, 0x60(%r15)
movaps 0x1e7ca(%rip), %xmm0    # 0x35b20
movups %xmm0, 0x70(%r15)
movaps 0x1e7ce(%rip), %xmm0    # 0x35b30
movups %xmm0, 0x80(%r15)
movaps 0x1e7cf(%rip), %xmm0    # 0x35b40
movups %xmm0, 0x90(%r15)
movaps 0x1e7d0(%rip), %xmm0    # 0x35b50
movups %xmm0, 0xa0(%r15)
movapd 0x1e7d0(%rip), %xmm0    # 0x35b60
movupd %xmm0, 0xb0(%r15)
movq %r15, (%rsp)
pushq $0x6
popq %rsi
pushq $0xc
popq %rcx
pushq $0x8
popq %r9
movl %ebp, %edi
movl %esi, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq %rbx, %rdx
movq %rcx, %r13
movq %r14, 0x8(%rsp)
movq %r14, %r8
movl %r9d, 0x14(%rsp)
callq 0x16e2e
leaq 0xc(%r15), %rax
movq %rax, 0x58(%rsp)
movq %r15, 0x20(%rsp)
leaq 0x14(%r15), %rax
movq %rax, 0x60(%rsp)
cmpl $0x8, %ebp
je 0x17753
movl %ebp, 0x3c(%rsp)
movq %r13, %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
imulq $0x14, %rax, %rbx
xorl %ebp, %ebp
movq 0x8(%rsp), %rdx
cmpq %rbp, %rbx
je 0x17597
cmpb $0x0, 0x8(%rdx,%rbp)
jne 0x1758e
xorl %edi, %edi
movl 0x10(%rsp), %r14d
cmpl $0x10002, %r14d         # imm = 0x10002
setl %dil
xorl %esi, %esi
callq 0x92cb
movq 0x8(%rsp), %rax
movslq (%rax,%rbp), %rax
imulq $0x18, %rax, %rax
movq 0x8(%rsp), %rcx
movslq 0x4(%rcx,%rbp), %rcx
imulq $0x18, %rcx, %rcx
movq 0x18(%rsp), %r15
movsd 0x10(%r15,%rax), %xmm0
addsd 0x10(%r15,%rcx), %xmm0
movapd %xmm0, %xmm2
movsd %xmm0, 0x30(%rsp)
movslq %r14d, %r12
imulq $0x18, %r12, %r14
movupd (%r15,%rax), %xmm0
movupd (%r15,%rcx), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x40(%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, 0x28(%rsp)
xorl %edi, %edi
ucomisd 0x1e5a4(%rip), %xmm0    # 0x35a60
seta %dil
xorl %esi, %esi
callq 0x92cb
movsd 0x1dbf9(%rip), %xmm0    # 0x350c8
divsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
mulsd %xmm0, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0x40(%rsp), %xmm0
movupd %xmm0, (%r15,%r14)
movsd %xmm1, 0x10(%r15,%r14)
leal 0x1(%r12), %eax
movl %eax, 0x10(%rsp)
xorl %edi, %edi
cmpl $0x3fffc, %r13d         # imm = 0x3FFFC
setl %dil
xorl %esi, %esi
callq 0x92cb
movq 0x8(%rsp), %rax
movl %r13d, 0xc(%rax,%rbp)
movslq %r13d, %r13
imulq $0x14, %r13, %rax
movq 0x8(%rsp), %rcx
xorl %r15d, %r15d
movb %r15b, 0x8(%rcx,%rax)
movq 0x8(%rsp), %rcx
movl (%rcx,%rbp), %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx,%rax)
movq 0x8(%rsp), %rcx
movl %r12d, 0x4(%rcx,%rax)
leal 0x1(%r13), %r14d
xorl %edi, %edi
cmpl $0x3fffb, %r13d         # imm = 0x3FFFB
setl %dil
xorl %esi, %esi
callq 0x92cb
movq 0x8(%rsp), %rdx
movl %r14d, 0x10(%rdx,%rbp)
movslq %r14d, %rax
imulq $0x14, %rax, %rax
movb %r15b, 0x8(%rdx,%rax)
movl %r12d, (%rdx,%rax)
movl 0x4(%rdx,%rbp), %ecx
movl %ecx, 0x4(%rdx,%rax)
addl $0x2, %r13d
movb $0x1, 0x8(%rdx,%rbp)
addq $0x14, %rbp
jmp 0x17406
movl 0x14(%rsp), %r9d
testl %r9d, %r9d
movl $0x0, %eax
cmovgl %r9d, %eax
movq %rax, 0x70(%rsp)
movq 0x58(%rsp), %rbx
xorl %eax, %eax
movq %r13, %rcx
cmpq 0x70(%rsp), %rax
movl %r9d, 0x14(%rsp)
je 0x17727
movq %rax, 0x30(%rsp)
imulq $0x18, %rax, %r15
addq 0x20(%rsp), %r15
movslq %r9d, %r13
movq %rcx, 0x40(%rsp)
movslq %ecx, %rax
movq %rax, 0x28(%rsp)
movl %eax, %r12d
imulq $0x18, %r13, %r14
addq 0x60(%rsp), %r14
xorl %ebp, %ebp
cmpq $0x3, %rbp
je 0x1769e
movq %r13, %rax
addq %rbp, %rax
xorl %edi, %edi
cmpq $0x20000, %rax          # imm = 0x20000
setl %dil
xorl %esi, %esi
callq 0x92cb
movslq -0xc(%rbx,%rbp,4), %rax
imulq $0x14, %rax, %rax
movq 0x8(%rsp), %rdi
leaq (%rdi,%rax), %rcx
movslq 0xc(%rdi,%rax), %rax
imulq $0x14, %rax, %rax
movl 0x4(%rdi,%rax), %eax
movl %eax, 0x7c(%rsp,%rbp,4)
movslq (%rbx,%rbp,4), %rax
pushq $0x1
popq %rdx
subq %rax, %rdx
movl 0xc(%rcx,%rdx,4), %eax
movl %eax, -0x14(%r14)
movl (%rbx,%rbp,4), %eax
movl %eax, -0x8(%r14)
leaq 0x1(%rbp), %rax
cmpq $0x2, %rbp
movl $0x0, %ecx
cmovneq %rax, %rcx
movslq (%r15,%rcx,4), %rdx
movslq 0xc(%r15,%rcx,4), %rsi
imulq $0x14, %rdx, %rdx
addq %rdi, %rdx
movl 0xc(%rdx,%rsi,4), %edx
movl %edx, -0x10(%r14)
movl 0xc(%r15,%rcx,4), %ecx
movl %ecx, -0x4(%r14)
addl %r12d, %ebp
movl %ebp, -0xc(%r14)
movl $0x1, (%r14)
addq $0x18, %r14
movq %rax, %rbp
jmp 0x175f3
movq 0x28(%rsp), %r13
imulq $0x14, %r13, %r14
addq 0x68(%rsp), %r14
xorl %r15d, %r15d
cmpq $0x3, %r15
je 0x17706
leaq (%r15,%r13), %rax
xorl %edi, %edi
cmpq $0x3fffc, %rax          # imm = 0x3FFFC
setl %dil
xorl %esi, %esi
callq 0x92cb
leal (%r12,%r15), %eax
movl %eax, -0xc(%rbx,%r15,4)
andl $0x0, (%rbx,%r15,4)
movb $0x0, (%r14)
movl 0x7c(%rsp,%r15,4), %eax
movl %eax, -0x8(%r14)
cmpq $0x2, %r15
leaq 0x1(%r15), %r15
movl $0x0, %eax
cmovneq %r15, %rax
movl 0x7c(%rsp,%rax,4), %eax
movl %eax, -0x4(%r14)
addq $0x14, %r14
jmp 0x176af
movl 0x14(%rsp), %r9d
addl %ebp, %r9d
movq 0x40(%rsp), %rcx
addl %r15d, %ecx
movq 0x30(%rsp), %rax
incq %rax
addq $0x18, %rbx
jmp 0x175b7
movl 0x3c(%rsp), %ebp
incl %ebp
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movl %ebp, %edi
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rdx
movq %rcx, %r13
movq 0x8(%rsp), %r8
callq 0x16e2e
jmp 0x173e1
movq 0x18(%rsp), %rdi
callq 0x4380
movq 0x8(%rsp), %rdi
callq 0x4380
movq 0x20(%rsp), %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4380