// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: md3load
static md3model *md3load (int fil)
{
	int surfi, ofsurf, offs[4], leng[4];
	md3model *m;
	md3surf_t *s;

	md3filehead_t filehead;
	md3filesurf_t filesurf;

	m = (md3model *)calloc(1,sizeof(md3model)); if (!m) return(0);
	m->mdnum = 3; m->tex = 0; m->scale = .01;

	kread(fil,&filehead,sizeof(md3filehead_t));
	m->head.id = B_LITTLE32(filehead.id);
	m->head.vers = B_LITTLE32(filehead.vers);
	memcpy(m->head.nam, filehead.nam, sizeof(filehead.nam));
	m->head.flags = B_LITTLE32(filehead.flags);
	m->head.numframes = B_LITTLE32(filehead.numframes);
	m->head.numtags = B_LITTLE32(filehead.numtags);
	m->head.numsurfs = B_LITTLE32(filehead.numsurfs);
	m->head.numskins = B_LITTLE32(filehead.numskins);
	filehead.frames = B_LITTLE32(filehead.frames);
	filehead.tags = B_LITTLE32(filehead.tags);
	filehead.surfs = B_LITTLE32(filehead.surfs);
	m->head.eof = B_LITTLE32(filehead.eof);

	if ((m->head.id != 0x33504449) && (m->head.vers != 15)) { md3free(m); return(0); } //"IDP3"

	m->numskins = m->head.numskins; //<- dead code?
	m->numframes = m->head.numframes;

	klseek(fil,filehead.frames,SEEK_SET);
	m->head.frames = (md3frame_t *)calloc(m->head.numframes, sizeof(md3frame_t));
	if (!m->head.frames) { md3free(m); return(0); }
	kread(fil,m->head.frames,m->head.numframes*sizeof(md3frame_t));

	if (m->head.numtags == 0) m->head.tags = NULL;
	else {
		klseek(fil,filehead.tags,SEEK_SET);
		m->head.tags = (md3tag_t *)calloc(m->head.numtags, sizeof(md3tag_t));
		if (!m->head.tags) { md3free(m); return(0); }
		kread(fil,m->head.tags,m->head.numtags*sizeof(md3tag_t));
	}

	klseek(fil,filehead.surfs,SEEK_SET);
	m->head.surfs = (md3surf_t *)calloc(m->head.numsurfs, sizeof(md3surf_t));
	if (!m->head.surfs) { md3free(m); return(0); }

#if B_BIG_ENDIAN != 0
	{
		int i, j, *l;

		for (i = m->head.numframes-1; i>=0; i--) {
			l = (int *)&m->head.frames[i].min;
			for (j=3+3+3+1-1;j>=0;j--) l[j] = B_LITTLE32(l[j]);
		}

		for (i = m->head.numtags-1; i>=0; i--) {
			l = (int *)&m->head.tags[i].p;
			for (j=3+3+3+3-1;j>=0;j--) l[j] = B_LITTLE32(l[j]);
		}
	}
#endif

	ofsurf = filehead.surfs;

	for(surfi=0;surfi<m->head.numsurfs;surfi++)
	{
		s = &m->head.surfs[surfi];
		klseek(fil,ofsurf,SEEK_SET); kread(fil,&filesurf,sizeof(md3filesurf_t));

		s->id = B_LITTLE32(filesurf.id);
		memcpy(s->nam, filesurf.nam, sizeof(filesurf.nam));
		s->flags = B_LITTLE32(filesurf.flags);
		s->numframes = B_LITTLE32(filesurf.numframes);
		s->numshaders = B_LITTLE32(filesurf.numshaders);
		s->numverts = B_LITTLE32(filesurf.numverts);
		s->numtris = B_LITTLE32(filesurf.numtris);
		filesurf.tris = B_LITTLE32(filesurf.tris);
		filesurf.shaders = B_LITTLE32(filesurf.shaders);
		filesurf.uv = B_LITTLE32(filesurf.uv);
		filesurf.xyzn = B_LITTLE32(filesurf.xyzn);
		s->ofsend = B_LITTLE32(filesurf.ofsend);

		offs[0] = ofsurf+filesurf.tris   ; leng[0] = s->numtris*sizeof(md3tri_t);
		offs[1] = ofsurf+filesurf.shaders; leng[1] = s->numshaders*sizeof(md3shader_t);
		offs[2] = ofsurf+filesurf.uv     ; leng[2] = s->numverts*sizeof(md3uv_t);
		offs[3] = ofsurf+filesurf.xyzn   ; leng[3] = s->numframes*s->numverts*sizeof(md3xyzn_t);

		s->tris = (md3tri_t *)malloc(leng[0]+leng[1]+leng[2]+leng[3]);
		if (!s->tris)
		{
			md3free(m);
			return(0);
		}
		s->shaders = (md3shader_t *)(((intptr_t)s->tris   )+leng[0]);
		s->uv      = (md3uv_t     *)(((intptr_t)s->shaders)+leng[1]);
		s->xyzn    = (md3xyzn_t   *)(((intptr_t)s->uv     )+leng[2]);

		klseek(fil,offs[0],SEEK_SET); kread(fil,s->tris   ,leng[0]);
		klseek(fil,offs[1],SEEK_SET); kread(fil,s->shaders,leng[1]);
		klseek(fil,offs[2],SEEK_SET); kread(fil,s->uv     ,leng[2]);
		klseek(fil,offs[3],SEEK_SET); kread(fil,s->xyzn   ,leng[3]);

#if B_BIG_ENDIAN != 0
		{
			int i, j, *l;

			for (i=s->numtris-1;i>=0;i--) {
				for (j=2;j>=0;j--) s->tris[i].i[j] = B_LITTLE32(s->tris[i].i[j]);
			}
			for (i=s->numshaders-1;i>=0;i--) {
				s->shaders[i].i = B_LITTLE32(s->shaders[i].i);
			}
			for (i=s->numverts-1;i>=0;i--) {
				l = (int*)&s->uv[i];
				l[0] = B_LITTLE32(l[0]);
				l[1] = B_LITTLE32(l[1]);
			}
			for (i=s->numframes*s->numverts-1;i>=0;i--) {
				s->xyzn[i].x = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].x);
				s->xyzn[i].y = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].y);
				s->xyzn[i].z = (signed short)B_LITTLE16((unsigned short)s->xyzn[i].z);
			}
		}
#endif

		maxmodelverts = max(maxmodelverts, s->numverts);
		maxelementvbo = max(maxelementvbo, s->numtris * 3);
		ofsurf += s->ofsend;
	}

	return(m);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl %edi, -0xc(%rbp)
movl $0x1, %edi
movl $0xd8, %esi
callq 0x6880
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x93f95
movq $0x0, -0x8(%rbp)
jmp 0x9452b
movq -0x48(%rbp), %rax
movl $0x3, (%rax)
movq -0x48(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x48(%rbp), %rax
movss 0x231c1(%rip), %xmm0    # 0xb7178
movss %xmm0, 0x8(%rax)
movl -0xc(%rbp), %edi
leaq -0xbc(%rbp), %rsi
movl $0x6c, %edx
callq 0x302b0
movl -0xbc(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0xb8(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x48(%rbp), %rdi
addq $0x58, %rdi
addq $0x8, %rdi
leaq -0xbc(%rbp), %rsi
addq $0x8, %rsi
movl $0x40, %edx
callq 0x60c0
movl -0x74(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0xa0(%rax)
movl -0x70(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0xa4(%rax)
movl -0x6c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0xa8(%rax)
movl -0x68(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0xac(%rax)
movl -0x64(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0xb0(%rax)
movl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0xd0(%rax)
movq -0x48(%rbp), %rax
cmpl $0x33504449, 0x58(%rax) # imm = 0x33504449
je 0x94098
movq -0x48(%rbp), %rax
cmpl $0xf, 0x5c(%rax)
je 0x94098
movq -0x48(%rbp), %rdi
callq 0x975b0
movq $0x0, -0x8(%rbp)
jmp 0x9452b
movq -0x48(%rbp), %rax
movl 0xb0(%rax), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x48(%rbp), %rax
movl 0xa4(%rax), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x20(%rax)
movl -0xc(%rbp), %edi
movl -0x60(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movq -0x48(%rbp), %rax
movslq 0xa4(%rax), %rdi
movl $0x38, %esi
callq 0x6880
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0xb8(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0xb8(%rax)
jne 0x9410e
movq -0x48(%rbp), %rdi
callq 0x975b0
movq $0x0, -0x8(%rbp)
jmp 0x9452b
movl -0xc(%rbp), %edi
movq -0x48(%rbp), %rax
movq 0xb8(%rax), %rsi
movq -0x48(%rbp), %rax
movslq 0xa4(%rax), %rax
imulq $0x38, %rax, %rax
movl %eax, %edx
callq 0x302b0
movq -0x48(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0x94150
movq -0x48(%rbp), %rax
movq $0x0, 0xc0(%rax)
jmp 0x941c8
movl -0xc(%rbp), %edi
movl -0x5c(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movq -0x48(%rbp), %rax
movslq 0xa8(%rax), %rdi
movl $0x70, %esi
callq 0x6880
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0xc0(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0xc0(%rax)
jne 0x941a4
movq -0x48(%rbp), %rdi
callq 0x975b0
movq $0x0, -0x8(%rbp)
jmp 0x9452b
movl -0xc(%rbp), %edi
movq -0x48(%rbp), %rax
movq 0xc0(%rax), %rsi
movq -0x48(%rbp), %rax
movslq 0xa8(%rax), %rax
imulq $0x70, %rax, %rax
movl %eax, %edx
callq 0x302b0
movl -0xc(%rbp), %edi
movl -0x58(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movq -0x48(%rbp), %rax
movslq 0xac(%rax), %rdi
movl $0x80, %esi
callq 0x6880
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
jne 0x9421c
movq -0x48(%rbp), %rdi
callq 0x975b0
movq $0x0, -0x8(%rbp)
jmp 0x9452b
movl -0x58(%rbp), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0xac(%rcx), %eax
jge 0x94523
movq -0x48(%rbp), %rax
movq 0xc8(%rax), %rax
movslq -0x10(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0xc(%rbp), %edi
movl -0x14(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
leaq -0x128(%rbp), %rsi
movl $0x6c, %edx
callq 0x302b0
movl -0x128(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rdi
addq $0x4, %rdi
leaq -0x128(%rbp), %rsi
addq $0x4, %rsi
movl $0x40, %edx
callq 0x60c0
movl -0xe4(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x44(%rax)
movl -0xe0(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x48(%rax)
movl -0xdc(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x4c(%rax)
movl -0xd8(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x50(%rax)
movl -0xd4(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x54(%rax)
movl -0xd0(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0xc8(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xc0(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x78(%rax)
movl -0x14(%rbp), %eax
addl -0xd0(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x50(%rbp), %rax
movslq 0x54(%rax), %rax
imulq $0xc, %rax, %rax
movl %eax, -0x40(%rbp)
movl -0x14(%rbp), %eax
addl -0xcc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x50(%rbp), %rax
movslq 0x4c(%rax), %rax
imulq $0x44, %rax, %rax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
addl -0xc8(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x50(%rbp), %rax
movslq 0x50(%rax), %rax
shlq $0x3, %rax
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %eax
addl -0xc4(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x50(%rbp), %rax
movl 0x48(%rax), %eax
movq -0x50(%rbp), %rcx
imull 0x50(%rcx), %eax
cltq
shlq $0x3, %rax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
movslq %eax, %rdi
callq 0x68f0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x50(%rbp), %rax
cmpq $0x0, 0x58(%rax)
jne 0x943d3
movq -0x48(%rbp), %rdi
callq 0x975b0
movq $0x0, -0x8(%rbp)
jmp 0x9452b
movq -0x50(%rbp), %rax
movq 0x58(%rax), %rcx
movslq -0x40(%rbp), %rax
addq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x50(%rbp), %rax
movq 0x60(%rax), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x50(%rbp), %rax
movq 0x68(%rax), %rcx
movslq -0x38(%rbp), %rax
addq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x70(%rax)
movl -0xc(%rbp), %edi
movl -0x30(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x50(%rbp), %rax
movq 0x58(%rax), %rsi
movl -0x40(%rbp), %edx
callq 0x302b0
movl -0xc(%rbp), %edi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x50(%rbp), %rax
movq 0x60(%rax), %rsi
movl -0x3c(%rbp), %edx
callq 0x302b0
movl -0xc(%rbp), %edi
movl -0x28(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x50(%rbp), %rax
movq 0x68(%rax), %rsi
movl -0x38(%rbp), %edx
callq 0x302b0
movl -0xc(%rbp), %edi
movl -0x24(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x50(%rbp), %rax
movq 0x70(%rax), %rsi
movl -0x34(%rbp), %edx
callq 0x302b0
movl 0x5c2b8a(%rip), %eax    # 0x657028
movq -0x50(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jle 0x944b5
movl 0x5c2b7b(%rip), %eax    # 0x657028
movl %eax, -0x12c(%rbp)
jmp 0x944c2
movq -0x50(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x12c(%rbp)
movl -0x12c(%rbp), %eax
movl %eax, 0x5c2b5a(%rip)    # 0x657028
movl 0x5c2b64(%rip), %eax    # 0x657038
movq -0x50(%rbp), %rcx
imull $0x3, 0x54(%rcx), %ecx
cmpl %ecx, %eax
jle 0x944ee
movl 0x5c2b52(%rip), %eax    # 0x657038
movl %eax, -0x130(%rbp)
jmp 0x944fc
movq -0x50(%rbp), %rax
imull $0x3, 0x54(%rax), %eax
movl %eax, -0x130(%rbp)
movl -0x130(%rbp), %eax
movl %eax, 0x5c2b30(%rip)    # 0x657038
movq -0x50(%rbp), %rax
movl 0x78(%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x94229
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax,%rax)