// File: 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:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x19f36
jmp 0x1a2cb
movq 0x40(%rsp), %rdi
callq 0xafd0
testb $0x1, %al
jne 0x19f46
jmp 0x19f5b
movq 0x40(%rsp), %rsi
leaq 0x13f16(%rip), %rdi     # 0x2de68
movb $0x0, %al
callq 0xb5d0
jmp 0x19f73
movq 0x40(%rsp), %rsi
leaq 0x13f25(%rip), %rdi     # 0x2de8c
movb $0x0, %al
callq 0xba80
jmp 0x1a2cb
movq 0x40(%rsp), %rdi
leaq 0x13169(%rip), %rsi     # 0x2d0e8
callq 0x4460
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x45e0
movb %al, 0x27(%rsp)
movq 0x18(%rsp), %rdi
callq 0x4090
movsbl 0x27(%rsp), %eax
cmpl $0x28, %eax
jne 0x1a102
movl $0x0, 0x10(%rsp)
cmpl $0x4, 0x10(%rsp)
jge 0x1a0fd
movq 0x18(%rsp), %rdi
leaq 0x13ee8(%rip), %rsi     # 0x2deb6
leaq 0x3c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x34(%rsp), %r8
leaq 0x30(%rsp), %r9
leaq 0x2c(%rsp), %r10
leaq 0x28(%rsp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x46d0
movl %eax, 0x14(%rsp)
cmpl $0x6, 0x14(%rsp)
je 0x1a022
movq 0x40(%rsp), %rsi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
leaq 0x13eb6(%rip), %rdi     # 0x2ded1
movb $0x0, %al
callq 0xba80
movss 0x3c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d3b8(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movss 0x38(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d397(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movss 0x34(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d375(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movss 0x30(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d353(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x18(%rax)
movss 0x2c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d331(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movss 0x28(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d30f(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x28(%rax)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x19fb7
jmp 0x1a2c1
movl $0x1, 0x10(%rsp)
cmpl $0x4, 0x10(%rsp)
jge 0x1a2bf
movq 0x18(%rsp), %rdi
leaq 0x13cc1(%rip), %rsi     # 0x2dde2
leaq 0x3c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x34(%rsp), %r8
movb $0x0, %al
callq 0x46d0
movl %eax, 0x14(%rsp)
cmpl $0x3, 0x14(%rsp)
je 0x1a15d
movq 0x40(%rsp), %rsi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
leaq 0x13db3(%rip), %rdi     # 0x2df09
movb $0x0, %al
callq 0xba80
movss 0x3c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x13311(%rip), %xmm1    # 0x2d480
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x3c(%rsp)
movss 0x38(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x132f1(%rip), %xmm1    # 0x2d480
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x38(%rsp)
movss 0x34(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x132d1(%rip), %xmm1    # 0x2d480
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x34(%rsp)
movss 0x3c(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d210(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movss 0x38(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d1e2(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movss 0x34(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d1b3(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movss 0x3c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d191(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x18(%rax)
movss 0x38(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d16f(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x20(%rax)
movss 0x34(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rcx
leaq 0x1d14d(%rip), %rax     # 0x373f0
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x28(%rax)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x1a10a
jmp 0x1a2c1
movq 0x18(%rsp), %rdi
callq 0x43a0
addq $0x48, %rsp
retq