// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlcsg/hullfile.cpp
// Function: LoadHullfile(char const*)
void        LoadHullfile(const char* filename)
{
    if (filename == NULL)
    {
        return;
    }

    if (q_exists(filename))
    {
        Log("Loading hull definitions from '%s'\n", filename);
    }
    else
    {
        Error("Could not find hull definition file '%s'\n", filename);
        return;
    }

    float x1,y1,z1;
	float x2,y2,z2;
	char magic;

    FILE* file = fopen(filename, "r");

    int count;
    int i;

	magic = (char)fgetc(file);
	rewind(file);

	if(magic == '(')
	{   // Test for old-style hull-file

		for (i=0; i < NUM_HULLS; i++)
		{
			count = fscanf(file, "( %f %f %f ) ( %f %f %f )\n", &x1, &y1, &z1, &x2, &y2, &z2);
			if (count != 6)
			{
				Error("Could not parse old hull definition file '%s' (%d, %d)\n", filename, i, count);
			}

			g_hull_size[i][0][0] = x1;
			g_hull_size[i][0][1] = y1;
			g_hull_size[i][0][2] = z1;

			g_hull_size[i][1][0] = x2;
			g_hull_size[i][1][1] = y2;
			g_hull_size[i][1][2] = z2;			

		}
		
	}
	else
	{
		// Skip hull 0 (visibile polygons)
		for (i=1; i<NUM_HULLS; i++)
		{
			count = fscanf(file, "%f %f %f\n", &x1, &y1, &z1);
			if (count != 3)
			{
				Error("Could not parse new hull definition file '%s' (%d, %d)\n", filename, i, count);
			}
			x1 *= 0.5;
			y1 *= 0.5;
			z1 *= 0.5;

			g_hull_size[i][0][0] = -x1;
			g_hull_size[i][0][1] = -y1;
			g_hull_size[i][0][2] = -z1;

			g_hull_size[i][1][0] = x1;
			g_hull_size[i][1][1] = y1;
			g_hull_size[i][1][2] = z1;
		}
    }

    fclose(file);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x126f5
movq %rdi, %rbx
callq 0x999b
testb %al, %al
je 0x125fc
leaq 0xd856(%rip), %rdi      # 0x1fd60
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9e76
leaq 0xcb3d(%rip), %rsi      # 0x1f058
movq %rbx, %rdi
callq 0x4380
movq %rax, %r14
movq %rax, %rdi
callq 0x4500
movl %eax, %ebp
movq %r14, %rdi
callq 0x4090
cmpb $0x28, %bpl
jne 0x1261b
leaq 0x16e37(%rip), %r13     # 0x29380
movq %rsp, %rbp
leaq 0x14(%rsp), %r15
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0xd850(%rip), %rsi      # 0x1fdae
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %rbp, %r8
movq %r15, %r9
xorl %eax, %eax
leaq 0xc(%rsp), %r10
pushq %r10
leaq 0x18(%rsp), %r10
pushq %r10
callq 0x45c0
addq $0x10, %rsp
cmpl $0x6, %eax
je 0x125a2
leaq 0xd836(%rip), %rdi      # 0x1fdc9
movq %rbx, %rsi
movl %r12d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xa164
movss 0x4(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtps2pd %xmm1, %xmm0
movaps %xmm0, -0x20(%r13)
movss 0x14(%rsp), %xmm0
movss (%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtps2pd %xmm1, %xmm0
movaps %xmm0, -0x10(%r13)
movss 0xc(%rsp), %xmm0
movss 0x10(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtps2pd %xmm1, %xmm0
movaps %xmm0, (%r13)
incq %r12
addq $0x30, %r13
cmpq $0x4, %r12
jne 0x12554
jmp 0x126ed
leaq 0xd781(%rip), %rdi      # 0x1fd84
movq %rbx, %rsi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa164
movl $0x1, %ebp
movl $0x58, %r12d
movq %rsp, %r15
leaq 0x16d30(%rip), %r13     # 0x29360
movq %r14, %rdi
leaq 0xd688(%rip), %rsi      # 0x1fcc2
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x45c0
cmpl $0x3, %eax
je 0x12668
leaq 0xd7a7(%rip), %rdi      # 0x1fe01
movq %rbx, %rsi
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xa164
movss (%rsp), %xmm0
mulss 0xd6d3(%rip), %xmm0     # 0x1fd48
movss %xmm0, (%rsp)
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
mulps 0xd6c0(%rip), %xmm2     # 0x1fd50
movss %xmm2, 0x8(%rsp)
movaps %xmm2, %xmm1
shufps $0x55, %xmm2, %xmm1     # xmm1 = xmm1[1,1],xmm2[1,1]
movss %xmm1, 0x4(%rsp)
cvtps2pd %xmm2, %xmm1
movaps 0x99d3(%rip), %xmm3     # 0x1c080
xorps %xmm3, %xmm2
cvtps2pd %xmm2, %xmm2
movaps %xmm2, -0x28(%r12,%r13)
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
xorps %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%r12,%r13)
movups %xmm1, -0x10(%r12,%r13)
movsd %xmm2, (%r12,%r13)
incl %ebp
addq $0x30, %r12
cmpq $0xe8, %r12
jne 0x12630
movq %r14, %rdi
callq 0x42f0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq