// File: /workspace/github_cpp_makefile_star2_O1/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 0x12c55
movq %rdi, %rbx
callq 0x9ada
testb %al, %al
je 0x12b5c
leaq 0xd2d6(%rip), %rdi      # 0x1fd40
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9fb2
leaq 0xc5ed(%rip), %rsi      # 0x1f068
movq %rbx, %rdi
callq 0x4390
movq %rax, %r14
movq %rax, %rdi
callq 0x4510
movl %eax, %ebp
movq %r14, %rdi
callq 0x4090
cmpb $0x28, %bpl
jne 0x12b7b
leaq 0x168e7(%rip), %r13     # 0x29390
movq %rsp, %rbp
leaq 0x14(%rsp), %r15
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0xd2d0(%rip), %rsi      # 0x1fd8e
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 0x45e0
addq $0x10, %rsp
cmpl $0x6, %eax
je 0x12b02
leaq 0xd2b6(%rip), %rdi      # 0x1fda9
movq %rbx, %rsi
movl %r12d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xa2a0
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 0x12ab4
jmp 0x12c4d
leaq 0xd201(%rip), %rdi      # 0x1fd64
movq %rbx, %rsi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa2a0
movl $0x1, %ebp
movl $0x58, %r12d
movq %rsp, %r15
leaq 0x167e0(%rip), %r13     # 0x29370
movq %r14, %rdi
leaq 0xd108(%rip), %rsi      # 0x1fca2
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x45e0
cmpl $0x3, %eax
je 0x12bc8
leaq 0xd227(%rip), %rdi      # 0x1fde1
movq %rbx, %rsi
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xa2a0
movss (%rsp), %xmm0
mulss 0xd153(%rip), %xmm0     # 0x1fd28
movss %xmm0, (%rsp)
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
mulps 0xd140(%rip), %xmm2     # 0x1fd30
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 0x9483(%rip), %xmm3     # 0x1c090
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 0x12b90
movq %r14, %rdi
callq 0x4300
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq