// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: loadkv6
static int loadkv6 (const char *filnam)
{
	int i, j, x, y, numvoxs, z0, z1, fil;
	float f;
	unsigned short *ylen;
	unsigned char c[8];

	fil = kopen4load((char *)filnam,0); if (fil < 0) return(-1);
	kread(fil,&i,4); if (B_LITTLE32(i) != 0x6c78764b) { kclose(fil); return(-1); } //Kvxl
	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,&f,4);       xpiv = B_LITTLEFLOAT(f);
    kread(fil,&f,4);       ypiv = B_LITTLEFLOAT(f);
    kread(fil,&f,4);       zpiv = B_LITTLEFLOAT(f);
	kread(fil,&numvoxs,4); numvoxs = B_LITTLE32(numvoxs);

	ylen = (unsigned short *)malloc(xsiz*ysiz*sizeof(unsigned short));
	if (!ylen) { kclose(fil); return(-1); }

	klseek(fil,32+(numvoxs<<3)+(xsiz<<2),SEEK_SET);
	kread(fil,ylen,xsiz*ysiz*sizeof(short)); for (i=xsiz*ysiz-1; i>=0; i--) ylen[i] = B_LITTLE16(ylen[i]);
	klseek(fil,32,SEEK_SET);

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

	for(vcolhashsizm1=4096;vcolhashsizm1<numvoxs;vcolhashsizm1<<=1) ;
	vcolhashsizm1--;
	vcolhashead = (int *)malloc((vcolhashsizm1+1)*sizeof(int)); if (!vcolhashead) { free(ylen); kclose(fil); return(-1); }
	memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int));

	for(x=0;x<xsiz;x++)
		for(y=0,j=x*yzsiz;y<ysiz;y++,j+=zsiz)
		{
			z1 = zsiz;
			for(i=ylen[x*ysiz+y];i>0;i--)
			{
				kread(fil,c,8); //b,g,r,a,z_lo,z_hi,vis,dir
				z0 = B_LITTLE16(*(unsigned short *)&c[4]);
				if (!(c[6]&16)) setzrange1(vbit,j+z1,j+z0);
				vbit[(j+z0)>>5] |= (1<<SHIFTMOD32(j+z0));
				putvox(x,y,z0,B_LITTLE32(*(int *)&c[0])&0xffffff);
				z1 = z0+1;
			}
		}
	free(ylen); kclose(fil); return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2fee0
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0x9124c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x91652
movl -0x30(%rbp), %edi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
cmpl $0x6c78764b, -0x14(%rbp) # imm = 0x6C78764B
je 0x9127a
movl -0x30(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x91652
movl -0x30(%rbp), %edi
leaq 0x615dc4(%rip), %rsi    # 0x6a7048
movl $0x4, %edx
callq 0x302b0
movl 0x615db4(%rip), %eax    # 0x6a7048
movl %eax, 0x615dae(%rip)    # 0x6a7048
movl -0x30(%rbp), %edi
leaq 0x615da8(%rip), %rsi    # 0x6a704c
movl $0x4, %edx
callq 0x302b0
movl 0x615d98(%rip), %eax    # 0x6a704c
movl %eax, 0x615d92(%rip)    # 0x6a704c
movl -0x30(%rbp), %edi
leaq 0x615d8c(%rip), %rsi    # 0x6a7050
movl $0x4, %edx
callq 0x302b0
movl 0x615d7c(%rip), %eax    # 0x6a7050
movl %eax, 0x615d76(%rip)    # 0x6a7050
movl -0x30(%rbp), %edi
leaq -0x34(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
movss -0x34(%rbp), %xmm0
movss %xmm0, 0x615d5c(%rip)   # 0x6a7054
movl -0x30(%rbp), %edi
leaq -0x34(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
movss -0x34(%rbp), %xmm0
movss %xmm0, 0x615d42(%rip)   # 0x6a7058
movl -0x30(%rbp), %edi
leaq -0x34(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
movss -0x34(%rbp), %xmm0
movss %xmm0, 0x615d28(%rip)   # 0x6a705c
movl -0x30(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
callq 0x302b0
movl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl 0x615cf7(%rip), %eax    # 0x6a7048
imull 0x615cf4(%rip), %eax    # 0x6a704c
movslq %eax, %rdi
shlq %rdi
callq 0x68f0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x91382
movl -0x30(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x91652
movl -0x30(%rbp), %edi
movl -0x24(%rbp), %esi
shll $0x3, %esi
addl $0x20, %esi
movl 0x615cb4(%rip), %eax    # 0x6a7048
shll $0x2, %eax
addl %eax, %esi
xorl %edx, %edx
callq 0x30590
movl -0x30(%rbp), %edi
movq -0x40(%rbp), %rsi
movl 0x615c9b(%rip), %eax    # 0x6a7048
imull 0x615c98(%rip), %eax    # 0x6a704c
cltq
shlq %rax
movl %eax, %edx
callq 0x302b0
movl 0x615c82(%rip), %eax    # 0x6a7048
imull 0x615c7f(%rip), %eax    # 0x6a704c
subl $0x1, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x913fc
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
movw (%rax,%rcx,2), %dx
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x913d3
movl -0x30(%rbp), %edi
movl $0x20, %esi
xorl %edx, %edx
callq 0x30590
movl 0x615c3b(%rip), %eax    # 0x6a704c
imull 0x615c38(%rip), %eax    # 0x6a7050
movl %eax, 0x615c6e(%rip)    # 0x6a708c
movl 0x615c24(%rip), %eax    # 0x6a7048
imull 0x615c61(%rip), %eax    # 0x6a708c
addl $0x1f, %eax
sarl $0x3, %eax
movl %eax, -0x14(%rbp)
movslq -0x14(%rbp), %rdi
callq 0x68f0
movq %rax, 0x615c24(%rip)    # 0x6a7068
cmpq $0x0, 0x615c1c(%rip)    # 0x6a7068
jne 0x9146b
movq -0x40(%rbp), %rdi
callq 0x61c0
movl -0x30(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x91652
movq 0x615bf6(%rip), %rdi    # 0x6a7068
movslq -0x14(%rbp), %rdx
xorl %esi, %esi
callq 0x62d0
movl $0x1000, 0x615c01(%rip) # imm = 0x1000
movl 0x615bfb(%rip), %eax    # 0x6a7088
cmpl -0x24(%rbp), %eax
jge 0x914a4
jmp 0x91494
movl 0x615bee(%rip), %eax    # 0x6a7088
shll %eax
movl %eax, 0x615be6(%rip)    # 0x6a7088
jmp 0x91487
movl 0x615bde(%rip), %eax    # 0x6a7088
addl $-0x1, %eax
movl %eax, 0x615bd5(%rip)    # 0x6a7088
movl 0x615bcf(%rip), %eax    # 0x6a7088
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x68f0
movq %rax, 0x615ba9(%rip)    # 0x6a7078
cmpq $0x0, 0x615ba1(%rip)    # 0x6a7078
jne 0x914f6
movq -0x40(%rbp), %rdi
callq 0x61c0
movl -0x30(%rbp), %edi
callq 0x30960
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x91652
movq 0x615b7b(%rip), %rdi    # 0x6a7078
movl 0x615b85(%rip), %eax    # 0x6a7088
addl $0x1, %eax
movslq %eax, %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x62d0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x615b21(%rip), %eax    # 0x6a7048
jge 0x9163a
movl $0x0, -0x20(%rbp)
movl -0x1c(%rbp), %eax
imull 0x615b4e(%rip), %eax    # 0x6a708c
movl %eax, -0x18(%rbp)
movl -0x20(%rbp), %eax
cmpl 0x615b02(%rip), %eax    # 0x6a704c
jge 0x9162a
movl 0x615afa(%rip), %eax    # 0x6a7050
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rax
movl -0x1c(%rbp), %ecx
imull 0x615ae5(%rip), %ecx    # 0x6a704c
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x9160e
movl -0x30(%rbp), %edi
leaq -0x48(%rbp), %rsi
movl $0x8, %edx
callq 0x302b0
movzwl -0x44(%rbp), %eax
movl %eax, -0x28(%rbp)
movzbl -0x42(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x915ba
movq 0x615abf(%rip), %rdi    # 0x6a7068
movl -0x18(%rbp), %esi
addl -0x2c(%rbp), %esi
movl -0x18(%rbp), %edx
addl -0x28(%rbp), %edx
callq 0x97840
movl -0x18(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movq 0x615a9a(%rip), %rax    # 0x6a7068
movl -0x18(%rbp), %ecx
addl -0x28(%rbp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x48(%rbp), %ecx
andl $0xffffff, %ecx         # imm = 0xFFFFFF
callq 0x97720
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x91574
jmp 0x91610
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl 0x615a31(%rip), %eax    # 0x6a7050
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x91541
jmp 0x9162c
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9151e
movq -0x40(%rbp), %rdi
callq 0x61c0
movl -0x30(%rbp), %edi
callq 0x30960
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)