// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: md2load
static md2model *md2load (int fil, const char *filnam)
{
	md2model *m;
	md2head_t head;
	char st[BMAX_PATH];
	size_t i;

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

	kread(fil,(char *)&head,sizeof(md2head_t));
	head.id = B_LITTLE32(head.id);                 head.vers = B_LITTLE32(head.vers);
	head.skinxsiz = B_LITTLE32(head.skinxsiz);     head.skinysiz = B_LITTLE32(head.skinysiz);
	head.framebytes = B_LITTLE32(head.framebytes); head.numskins = B_LITTLE32(head.numskins);
	head.numverts = B_LITTLE32(head.numverts);     head.numuv = B_LITTLE32(head.numuv);
	head.numtris = B_LITTLE32(head.numtris);       head.numglcmds = B_LITTLE32(head.numglcmds);
	head.numframes = B_LITTLE32(head.numframes);   head.ofsskins = B_LITTLE32(head.ofsskins);
	head.ofsuv = B_LITTLE32(head.ofsuv);           head.ofstris = B_LITTLE32(head.ofstris);
	head.ofsframes = B_LITTLE32(head.ofsframes);   head.ofsglcmds = B_LITTLE32(head.ofsglcmds);
	head.ofseof = B_LITTLE32(head.ofseof);

	if ((head.id != 0x32504449) || (head.vers != 8)) { md2free(m); return(0); } //"IDP2"

	m->numskins = head.numskins;
	m->numframes = head.numframes;
	m->numverts = head.numverts;
	m->numuv = head.numuv;
	m->numtris = head.numtris;
	m->framebytes = head.framebytes;
	m->skinxsiz = head.skinxsiz;
	m->skinysiz = head.skinysiz;

	m->uvs = (md2uv_t *)calloc(m->numuv,sizeof(md2uv_t));
	if (!m->uvs) { md2free(m); return(0); }
	klseek(fil,head.ofsuv,SEEK_SET);
	if (kread(fil,(char *)m->uvs,m->numuv*sizeof(md2uv_t)) != m->numuv*sizeof(md2uv_t))
		{ md2free(m); return(0); }

	m->tris = (md2tri_t *)calloc(m->numtris,sizeof(md2tri_t));
	if (!m->tris) { md2free(m); return(0); }
	klseek(fil,head.ofstris,SEEK_SET);
	if (kread(fil,(char *)m->tris,m->numtris*sizeof(md2tri_t)) != m->numtris*sizeof(md2tri_t))
		{ md2free(m); return(0); }

	m->frames = (char *)calloc(m->numframes,m->framebytes);
	if (!m->frames) { md2free(m); return(0); }
	klseek(fil,head.ofsframes,SEEK_SET);
	if (kread(fil,(char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes)
		{ md2free(m); return(0); }

#if B_BIG_ENDIAN != 0
	{
		char *f = (char *)m->frames;
		int *l,j;
		md2frame_t *fr;

		///FIXME byteswap tris

		for (i = m->numframes-1; i>=0; i--) {
			fr = (md2frame_t *)f;
			l = (int *)&fr->mul;
			for (j=5;j>=0;j--) l[j] = B_LITTLE32(l[j]);
			f += m->framebytes;
		}
	}
#endif

	strcpy(st,filnam);
	for(i=strlen(st)-1;i>0;i--)
		if ((st[i] == '/') || (st[i] == '\\')) { i++; break; }
	if (i<0) i=0;
	st[i] = 0;
	m->basepath = (char *)malloc(i+1); if (!m->basepath) { md2free(m); return(0); }
	strcpy(m->basepath, st);

	m->skinfn = (char *)calloc(m->numskins,64); if (!m->skinfn) { md2free(m); return(0); }
	klseek(fil,head.ofsskins,SEEK_SET);
	if (kread(fil,m->skinfn,64*m->numskins) != 64*m->numskins)
		{ md2free(m); return(0); }

	m->tex = (PTMHead **)calloc(m->numskins, sizeof(PTMHead *) * (HICEFFECTMASK+1));
	if (!m->tex) { md2free(m); return(0); }

	maxmodelverts = max(maxmodelverts, m->numverts);
	maxelementvbo = max(maxelementvbo, m->numtris * 3);

	return(m);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x480, %rsp            # imm = 0x480
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x1, %edi
movl $0x98, %esi
callq 0x6880
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x93a39
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movq -0x20(%rbp), %rax
movl $0x2, (%rax)
movq -0x20(%rbp), %rax
movss 0x23729(%rip), %xmm0    # 0xb7178
movss %xmm0, 0x8(%rax)
movl -0xc(%rbp), %edi
leaq -0x64(%rbp), %rsi
movl $0x44, %edx
callq 0x302b0
movl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
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), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x32504449, -0x64(%rbp) # imm = 0x32504449
jne 0x93ada
cmpl $0x8, -0x60(%rbp)
je 0x93af0
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movl -0x50(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x50(%rax)
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x48(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x5c(%rax)
movl -0x44(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x60(%rax)
movl -0x54(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x64(%rax)
movl -0x5c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x68(%rax)
movl -0x58(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x20(%rbp), %rax
movslq 0x5c(%rax), %rdi
movl $0x4, %esi
callq 0x6880
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x78(%rax)
jne 0x93b7e
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movl -0xc(%rbp), %edi
movl -0x34(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rsi
movq -0x20(%rbp), %rax
movslq 0x5c(%rax), %rax
shlq $0x2, %rax
movl %eax, %edx
callq 0x302b0
cltq
movq -0x20(%rbp), %rcx
movslq 0x5c(%rcx), %rcx
shlq $0x2, %rcx
cmpq %rcx, %rax
je 0x93bd2
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movq -0x20(%rbp), %rax
movslq 0x60(%rax), %rdi
movl $0xc, %esi
callq 0x6880
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x80(%rax)
jne 0x93c16
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movl -0xc(%rbp), %edi
movl -0x30(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rsi
movq -0x20(%rbp), %rax
movslq 0x60(%rax), %rax
imulq $0xc, %rax, %rax
movl %eax, %edx
callq 0x302b0
cltq
movq -0x20(%rbp), %rcx
movslq 0x60(%rcx), %rcx
imulq $0xc, %rcx, %rcx
cmpq %rcx, %rax
je 0x93c6d
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movq -0x20(%rbp), %rax
movslq 0x20(%rax), %rdi
movq -0x20(%rbp), %rax
movslq 0x64(%rax), %rsi
callq 0x6880
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x70(%rax)
jne 0x93cae
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movl -0xc(%rbp), %edi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rsi
movq -0x20(%rbp), %rax
movl 0x20(%rax), %edx
movq -0x20(%rbp), %rax
imull 0x64(%rax), %edx
callq 0x302b0
movq -0x20(%rbp), %rcx
movl 0x20(%rcx), %ecx
movq -0x20(%rbp), %rdx
imull 0x64(%rdx), %ecx
cmpl %ecx, %eax
je 0x93d03
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
leaq -0x470(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x63e0
leaq -0x470(%rbp), %rdi
callq 0x63d0
subq $0x1, %rax
movq %rax, -0x478(%rbp)
cmpq $0x0, -0x478(%rbp)
jbe 0x93d86
movq -0x478(%rbp), %rax
movsbl -0x470(%rbp,%rax), %eax
cmpl $0x2f, %eax
je 0x93d5c
movq -0x478(%rbp), %rax
movsbl -0x470(%rbp,%rax), %eax
cmpl $0x5c, %eax
jne 0x93d70
movq -0x478(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x478(%rbp)
jmp 0x93d86
jmp 0x93d72
movq -0x478(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x478(%rbp)
jmp 0x93d2a
cmpq $0x0, -0x478(%rbp)
jae 0x93d9b
movq $0x0, -0x478(%rbp)
movq -0x478(%rbp), %rax
movb $0x0, -0x470(%rbp,%rax)
movq -0x478(%rbp), %rdi
addq $0x1, %rdi
callq 0x68f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x88(%rax)
jne 0x93dec
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rdi
leaq -0x470(%rbp), %rsi
callq 0x63e0
movq -0x20(%rbp), %rax
movslq 0x50(%rax), %rdi
movl $0x40, %esi
callq 0x6880
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0x93e47
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movl -0xc(%rbp), %edi
movl -0x38(%rbp), %esi
xorl %edx, %edx
callq 0x30590
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rsi
movq -0x20(%rbp), %rax
movl 0x50(%rax), %edx
shll $0x6, %edx
callq 0x302b0
movq -0x20(%rbp), %rcx
movl 0x50(%rcx), %ecx
shll $0x6, %ecx
cmpl %ecx, %eax
je 0x93e95
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movq -0x20(%rbp), %rax
movslq 0x50(%rax), %rdi
movl $0x20, %esi
callq 0x6880
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x93ed0
movq -0x20(%rbp), %rdi
callq 0x97460
movq $0x0, -0x8(%rbp)
jmp 0x93f48
movl 0x5c3152(%rip), %eax    # 0x657028
movq -0x20(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jle 0x93eed
movl 0x5c3143(%rip), %eax    # 0x657028
movl %eax, -0x47c(%rbp)
jmp 0x93efa
movq -0x20(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x47c(%rbp)
movl -0x47c(%rbp), %eax
movl %eax, 0x5c3122(%rip)    # 0x657028
movl 0x5c312c(%rip), %eax    # 0x657038
movq -0x20(%rbp), %rcx
imull $0x3, 0x60(%rcx), %ecx
cmpl %ecx, %eax
jle 0x93f26
movl 0x5c311a(%rip), %eax    # 0x657038
movl %eax, -0x480(%rbp)
jmp 0x93f34
movq -0x20(%rbp), %rax
imull $0x3, 0x60(%rax), %eax
movl %eax, -0x480(%rbp)
movl -0x480(%rbp), %eax
movl %eax, 0x5c30f8(%rip)    # 0x657038
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x480, %rsp            # imm = 0x480
popq %rbp
retq
nopw %cs:(%rax,%rax)