// File: /workspace/github_cpp_makefile_star2_O2/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 0x1049f
movq %rdi, %rbx
callq 0x850a
testb %al, %al
je 0x103a8
leaq 0xc9da(%rip), %rdi      # 0x1cc90
movq %rbx, %rsi
xorl %eax, %eax
callq 0x89dc
leaq 0xbd01(%rip), %rsi      # 0x1bfc8
movq %rbx, %rdi
callq 0x43a0
movq %rax, %r14
movq %rax, %rdi
callq 0x4530
movl %eax, %ebp
movq %r14, %rdi
callq 0x4090
cmpb $0x28, %bpl
jne 0x103c7
leaq 0x1709b(%rip), %r13     # 0x27390
movq %rsp, %rbp
leaq 0x14(%rsp), %r15
xorl %r12d, %r12d
cmpq $0x4, %r12
je 0x10497
movq %r14, %rdi
leaq 0xc9ca(%rip), %rsi      # 0x1ccde
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 0x45f0
addq $0x10, %rsp
cmpl $0x6, %eax
je 0x10358
leaq 0xc9b0(%rip), %rdi      # 0x1ccf9
movq %rbx, %rsi
movl %r12d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x8d7b
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]
movss 0xc(%rsp), %xmm0
movss 0x10(%rsp), %xmm2
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
cvtps2pd %xmm1, %xmm0
cvtps2pd %xmm2, %xmm1
movaps %xmm0, -0x10(%r13)
movaps %xmm1, (%r13)
incq %r12
addq $0x30, %r13
jmp 0x10300
leaq 0xc905(%rip), %rdi      # 0x1ccb4
movq %rbx, %rsi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8d7b
pushq $0x58
popq %r12
pushq $0x1
popq %rbp
movq %rsp, %r15
leaq 0x16f98(%rip), %r13     # 0x27370
cmpq $0xe8, %r12
je 0x10497
movq %r14, %rdi
leaq 0xc843(%rip), %rsi      # 0x1cc32
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x45f0
cmpl $0x3, %eax
je 0x1041d
leaq 0xc922(%rip), %rdi      # 0x1cd31
movq %rbx, %rsi
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x8d7b
movss (%rsp), %xmm0
mulss 0xc84a(%rip), %xmm0     # 0x1cc74
movss %xmm0, (%rsp)
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
mulps 0xc83b(%rip), %xmm2     # 0x1cc80
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 0xbe0e(%rip), %xmm3     # 0x1c270
xorps %xmm3, %xmm2
cvtps2pd %xmm2, %xmm2
movaps %xmm2, -0x28(%r12,%r13)
cvtss2sd %xmm0, %xmm2
xorps %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%r12,%r13)
movups %xmm1, -0x10(%r12,%r13)
movsd %xmm2, (%r12,%r13)
addq $0x30, %r12
incl %ebp
jmp 0x103d8
movq %r14, %rdi
callq 0x4300
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop