// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: loadkvx
static int loadkvx (const char *filnam)
{
	int i, j, k, x, y, z, pal[256], z0, z1, mip1leng, ysizp1, fil;
	unsigned short *xyoffs;
	unsigned char c[3], *tbuf, *cptr;

	fil = kopen4load((char *)filnam,0); if (fil < 0) return(-1);
	kread(fil,&mip1leng,4); mip1leng = B_LITTLE32(mip1leng);
	kread(fil,&xsiz,4);     xsiz = B_LITTLE32(xsiz);
	kread(fil,&ysiz,4);     ysiz = B_LITTLE32(ysiz);
	kread(fil,&zsiz,4);     zsiz = B_LITTLE32(zsiz);
	kread(fil,&i,4);        xpiv = ((float)B_LITTLE32(i))/256.0;
	kread(fil,&i,4);        ypiv = ((float)B_LITTLE32(i))/256.0;
	kread(fil,&i,4);        zpiv = ((float)B_LITTLE32(i))/256.0;
	klseek(fil,(xsiz+1)<<2,SEEK_CUR);
	ysizp1 = ysiz+1;
	i = xsiz*ysizp1*sizeof(short);
	xyoffs = (unsigned short *)malloc(i); if (!xyoffs) { kclose(fil); return(-1); }
	kread(fil,xyoffs,i); for (i=i/sizeof(short)-1; i>=0; i--) xyoffs[i] = B_LITTLE16(xyoffs[i]);

	klseek(fil,-768,SEEK_END);
	for(i=0;i<256;i++)
		{ kread(fil,c,3); pal[i] = B_LITTLE32((((int)c[0])<<18)+(((int)c[1])<<10)+(((int)c[2])<<2)+(i<<24)); }

	yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
	vbit = (int *)malloc(i); if (!vbit) { free(xyoffs); kclose(fil); return(-1); }
	memset(vbit,0,i);

	for(vcolhashsizm1=4096;vcolhashsizm1<(mip1leng>>1);vcolhashsizm1<<=1) ;
	vcolhashsizm1--; //approx to numvoxs!
	vcolhashead = (int *)malloc((vcolhashsizm1+1)*sizeof(int)); if (!vcolhashead) { free(xyoffs); kclose(fil); return(-1); }
	memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int));

	klseek(fil,28+((xsiz+1)<<2)+((ysizp1*xsiz)<<1),SEEK_SET);

	i = kfilelength(fil)-ktell(fil);
	tbuf = (unsigned char *)malloc(i); if (!tbuf) { free(xyoffs); kclose(fil); return(-1); }
	kread(fil,tbuf,i); kclose(fil);

	cptr = tbuf;
	for(x=0;x<xsiz;x++) //Set surface voxels to 1 else 0
		for(y=0,j=x*yzsiz;y<ysiz;y++,j+=zsiz)
		{
			i = xyoffs[x*ysizp1+y+1] - xyoffs[x*ysizp1+y]; if (!i) continue;
			z1 = 0;
			while (i)
			{
				z0 = (int)cptr[0]; k = (int)cptr[1]; cptr += 3;
				if (!(cptr[-1]&16)) setzrange1(vbit,j+z1,j+z0);
				i -= k+3; z1 = z0+k;
				setzrange1(vbit,j+z0,j+z1);
				for(z=z0;z<z1;z++) putvox(x,y,z,pal[*cptr++]);
			}
		}

	free(tbuf); free(xyoffs); return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2fee0
movl %eax, -0x444(%rbp)
cmpl $0x0, -0x444(%rbp)
jge 0x90bf5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9120d
movl -0x444(%rbp), %edi
leaq -0x43c(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
movl -0x43c(%rbp), %eax
movl %eax, -0x43c(%rbp)
movl -0x444(%rbp), %edi
leaq 0x616423(%rip), %rsi    # 0x6a7048
movl $0x4, %edx
callq 0x302b0
movl 0x616413(%rip), %eax    # 0x6a7048
movl %eax, 0x61640d(%rip)    # 0x6a7048
movl -0x444(%rbp), %edi
leaq 0x616404(%rip), %rsi    # 0x6a704c
movl $0x4, %edx
callq 0x302b0
movl 0x6163f4(%rip), %eax    # 0x6a704c
movl %eax, 0x6163ee(%rip)    # 0x6a704c
movl -0x444(%rbp), %edi
leaq 0x6163e5(%rip), %rsi    # 0x6a7050
movl $0x4, %edx
callq 0x302b0
movl 0x6163d5(%rip), %eax    # 0x6a7050
movl %eax, 0x6163cf(%rip)    # 0x6a7050
movl -0x444(%rbp), %edi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
cvtsi2ssl -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x22072(%rip), %xmm1    # 0xb2d18
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x61639e(%rip)   # 0x6a7054
movl -0x444(%rbp), %edi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
cvtsi2ssl -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x2203d(%rip), %xmm1    # 0xb2d18
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x61636d(%rip)   # 0x6a7058
movl -0x444(%rbp), %edi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
cvtsi2ssl -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x22008(%rip), %xmm1    # 0xb2d18
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x61633c(%rip)   # 0x6a705c
movl -0x444(%rbp), %edi
movl 0x61631c(%rip), %esi    # 0x6a7048
addl $0x1, %esi
shll $0x2, %esi
movl $0x1, %edx
callq 0x30590
movl 0x61630a(%rip), %eax    # 0x6a704c
addl $0x1, %eax
movl %eax, -0x440(%rbp)
movl 0x6162f7(%rip), %eax    # 0x6a7048
imull -0x440(%rbp), %eax
cltq
shlq %rax
movl %eax, -0x14(%rbp)
movslq -0x14(%rbp), %rdi
callq 0x68f0
movq %rax, -0x450(%rbp)
cmpq $0x0, -0x450(%rbp)
jne 0x90d91
movl -0x444(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9120d
movl -0x444(%rbp), %edi
movq -0x450(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x302b0
movslq -0x14(%rbp), %rax
shrq %rax
subq $0x1, %rax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x90de3
movq -0x450(%rbp), %rax
movslq -0x14(%rbp), %rcx
movw (%rax,%rcx,2), %dx
movq -0x450(%rbp), %rax
movslq -0x14(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x90db4
movl -0x444(%rbp), %edi
movl $0xfffffd00, %esi       # imm = 0xFFFFFD00
movl $0x2, %edx
callq 0x30590
movl $0x0, -0x14(%rbp)
cmpl $0x100, -0x14(%rbp)     # imm = 0x100
jge 0x90e5f
movl -0x444(%rbp), %edi
leaq -0x453(%rbp), %rsi
movl $0x3, %edx
callq 0x302b0
movzbl -0x453(%rbp), %ecx
shll $0x12, %ecx
movzbl -0x452(%rbp), %eax
shll $0xa, %eax
addl %eax, %ecx
movzbl -0x451(%rbp), %eax
shll $0x2, %eax
addl %eax, %ecx
movl -0x14(%rbp), %eax
shll $0x18, %eax
addl %eax, %ecx
movslq -0x14(%rbp), %rax
movl %ecx, -0x430(%rbp,%rax,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x90dff
movl 0x6161e7(%rip), %eax    # 0x6a704c
imull 0x6161e4(%rip), %eax    # 0x6a7050
movl %eax, 0x61621a(%rip)    # 0x6a708c
movl 0x6161d0(%rip), %eax    # 0x6a7048
imull 0x61620d(%rip), %eax    # 0x6a708c
addl $0x1f, %eax
sarl $0x3, %eax
movl %eax, -0x14(%rbp)
movslq -0x14(%rbp), %rdi
callq 0x68f0
movq %rax, 0x6161d0(%rip)    # 0x6a7068
cmpq $0x0, 0x6161c8(%rip)    # 0x6a7068
jne 0x90ec5
movq -0x450(%rbp), %rdi
callq 0x61c0
movl -0x444(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9120d
movq 0x61619c(%rip), %rdi    # 0x6a7068
movslq -0x14(%rbp), %rdx
xorl %esi, %esi
callq 0x62d0
movl $0x1000, 0x6161a7(%rip) # imm = 0x1000
movl 0x6161a1(%rip), %eax    # 0x6a7088
movl -0x43c(%rbp), %ecx
sarl %ecx
cmpl %ecx, %eax
jge 0x90f05
jmp 0x90ef5
movl 0x61618d(%rip), %eax    # 0x6a7088
shll %eax
movl %eax, 0x616185(%rip)    # 0x6a7088
jmp 0x90ee1
movl 0x61617d(%rip), %eax    # 0x6a7088
addl $-0x1, %eax
movl %eax, 0x616174(%rip)    # 0x6a7088
movl 0x61616e(%rip), %eax    # 0x6a7088
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x68f0
movq %rax, 0x616148(%rip)    # 0x6a7078
cmpq $0x0, 0x616140(%rip)    # 0x6a7078
jne 0x90f5d
movq -0x450(%rbp), %rdi
callq 0x61c0
movl -0x444(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9120d
movq 0x616114(%rip), %rdi    # 0x6a7078
movl 0x61611e(%rip), %eax    # 0x6a7088
addl $0x1, %eax
movslq %eax, %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x62d0
movl -0x444(%rbp), %edi
movl 0x6160be(%rip), %esi    # 0x6a7048
addl $0x1, %esi
shll $0x2, %esi
addl $0x1c, %esi
movl -0x440(%rbp), %eax
imull 0x6160a8(%rip), %eax    # 0x6a7048
shll %eax
addl %eax, %esi
xorl %edx, %edx
callq 0x30590
movl -0x444(%rbp), %edi
callq 0x30750
movl %eax, -0x46c(%rbp)
movl -0x444(%rbp), %edi
callq 0x30860
movl %eax, %ecx
movl -0x46c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movslq -0x14(%rbp), %rdi
callq 0x68f0
movq %rax, -0x460(%rbp)
cmpq $0x0, -0x460(%rbp)
jne 0x91011
movq -0x450(%rbp), %rdi
callq 0x61c0
movl -0x444(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9120d
movl -0x444(%rbp), %edi
movq -0x460(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x302b0
movl -0x444(%rbp), %edi
callq 0x30960
movq -0x460(%rbp), %rax
movq %rax, -0x468(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0x615ff9(%rip), %eax    # 0x6a7048
jge 0x911ee
movl $0x0, -0x24(%rbp)
movl -0x20(%rbp), %eax
imull 0x616026(%rip), %eax    # 0x6a708c
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %eax
cmpl 0x615fda(%rip), %eax    # 0x6a704c
jge 0x911de
movq -0x450(%rbp), %rax
movl -0x20(%rbp), %ecx
imull -0x440(%rbp), %ecx
addl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
movq -0x450(%rbp), %rcx
movl -0x20(%rbp), %edx
imull -0x440(%rbp), %edx
addl -0x24(%rbp), %edx
movslq %edx, %rdx
movzwl (%rcx,%rdx,2), %ecx
subl %ecx, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x910c1
jmp 0x911c4
movl $0x0, -0x438(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x911c2
movq -0x468(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x434(%rbp)
movq -0x468(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x468(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x468(%rbp)
movq -0x468(%rbp), %rax
movzbl -0x1(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x91136
movq 0x615f49(%rip), %rdi    # 0x6a7068
movl -0x18(%rbp), %esi
addl -0x438(%rbp), %esi
movl -0x18(%rbp), %edx
addl -0x434(%rbp), %edx
callq 0x97840
movl -0x1c(%rbp), %ecx
addl $0x3, %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x434(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x438(%rbp)
movq 0x615f0e(%rip), %rdi    # 0x6a7068
movl -0x18(%rbp), %esi
addl -0x434(%rbp), %esi
movl -0x18(%rbp), %edx
addl -0x438(%rbp), %edx
callq 0x97840
movl -0x434(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x438(%rbp), %eax
jge 0x911bd
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movq -0x468(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x468(%rbp)
movzbl (%rax), %eax
movl -0x430(%rbp,%rax,4), %ecx
callq 0x97720
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x9117a
jmp 0x910cb
jmp 0x911c4
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl 0x615e7d(%rip), %eax    # 0x6a7050
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x91069
jmp 0x911e0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x91046
movq -0x460(%rbp), %rdi
callq 0x61c0
movq -0x450(%rbp), %rdi
callq 0x61c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
nopl (%rax)