// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: mdloadskin
PTMHead * mdloadskin (md2model *m, int number, int pal, int surf)
{
	int i, err = 0;
	char *skinfile = 0, fn[BMAX_PATH+65];
	PTMHead **tex = 0;
	mdskinmap_t *sk, *skzero = 0;
    PTMIdent id;

	if (m->mdnum == 2) {
		surf = 0;
	}

	if ((unsigned)pal >= (unsigned)MAXPALOOKUPS) {
		return 0;
	}

	i = -1;
	for (sk = m->skinmap; sk; sk = sk->next) {
		if ((int)sk->palette == pal && sk->skinnum == number && sk->surfnum == surf) {
			tex = &sk->tex[ hictinting[pal].f ];
			skinfile = sk->fn;
			strcpy(fn,skinfile);
			//buildprintf("Using exact match skin (pal=%d,skinnum=%d,surfnum=%d) %s\n",pal,number,surf,skinfile);
			break;
		}
		//If no match, give highest priority to number, then pal.. (Parkar's request, 02/27/2005)
		else if (((int)sk->palette ==   0) && (sk->skinnum == number) && (sk->surfnum == surf) && (i < 5)) { i = 5; skzero = sk; }
		else if (((int)sk->palette == pal) && (sk->skinnum ==      0) && (sk->surfnum == surf) && (i < 4)) { i = 4; skzero = sk; }
		else if (((int)sk->palette ==   0) && (sk->skinnum ==      0) && (sk->surfnum == surf) && (i < 3)) { i = 3; skzero = sk; }
		else if (((int)sk->palette ==   0) && (sk->skinnum == number) && (i < 2)) { i = 2; skzero = sk; }
		else if (((int)sk->palette == pal) && (sk->skinnum ==      0) && (i < 1)) { i = 1; skzero = sk; }
		else if (((int)sk->palette ==   0) && (sk->skinnum ==      0) && (i < 0)) { i = 0; skzero = sk; }
	}
	if (!sk) {
		if (skzero) {
			tex = &skzero->tex[ hictinting[pal].f ];
			skinfile = skzero->fn;
			strcpy(fn,skinfile);
			//buildprintf("Using def skin 0,0 as fallback, pal=%d\n", pal);
		} else {
			if ((unsigned)number >= (unsigned)m->numskins) {
				number = 0;
			}
			tex = &m->tex[ number * (HICEFFECTMASK+1) + hictinting[pal].f ];
			skinfile = m->skinfn + number*64;
			strcpy(fn,m->basepath);
			strcat(fn,skinfile);
			//buildprintf("Using MD2/MD3 skin (%d) %s, pal=%d\n",number,skinfile,pal);
		}
	}

	if (!skinfile[0]) {
		return 0;
	}

	if (*tex && (*tex)->glpic) {
		// texture already loaded
		return *tex;
	}

	if (!(*tex)) {
		// no PTMHead referenced yet at *tex
		md_initident(&id, skinfile, hictinting[pal].f);
		*tex = PTM_GetHead(&id);
		if (!(*tex)) {
			return 0;
		}
	}

	if (!(*tex)->glpic) {
		// no texture loaded in the PTMHead yet
		if ((err = PTM_LoadTextureFile(skinfile, *tex, PTH_CLAMPED, hictinting[pal].f))) {
			if (polymosttexverbosity >= 1) {
				const char * errstr = PTM_GetLoadTextureFileErrorString(err);
				buildprintf("MDSprite: %s %s\n",
						   skinfile, errstr);
			}
			return 0;
		}
		m->usesalpha = (((*tex)->flags & PTH_HASALPHA) == PTH_HASALPHA);
	}

	if (!m->skinloaded)
	{
		if ((*tex)->sizx != (*tex)->tsizx || (*tex)->sizy != (*tex)->tsizy)
		{
			float fx, fy;
			fx = ((float)(*tex)->tsizx)/((float)(*tex)->sizx);
			fy = ((float)(*tex)->tsizy)/((float)(*tex)->sizy);
			if (m->mdnum == 2)
			{
				//FIXME correct uvs for non-2^x textures
			}
			else if (m->mdnum == 3)
			{
				md3model *m3 = (md3model *)m;
				md3surf_t *s;
				int surfi;
				for (surfi=0;surfi<m3->head.numsurfs;surfi++)
				{
					s = &m3->head.surfs[surfi];
					for(i=s->numverts-1;i>=0;i--)
					{
						s->uv[i].u *= fx;
						s->uv[i].v *= fy;
					}
				}
			}
		}
		m->skinloaded = 1+number;
	}

	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag);
	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min);
#ifdef GL_EXT_texture_filter_anisotropic
	if (glinfo.maxanisotropy > 1.0)
		glfunc.glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy);
#endif
	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

	return (*tex);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8e0, %rsp            # imm = 0x8E0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x488(%rbp)
movq $0x0, -0x498(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x8f7ed
movl $0x0, -0x1c(%rbp)
cmpl $0x100, -0x18(%rbp)     # imm = 0x100
jb 0x8f803
movq $0x0, -0x8(%rbp)
jmp 0x8ff19
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x490(%rbp)
cmpq $0x0, -0x490(%rbp)
je 0x8fa54
movq -0x490(%rbp), %rax
movzbl (%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x8f8a1
movq -0x490(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x8f8a1
movq -0x490(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x8f8a1
movq -0x490(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rdx
leaq 0x5ac396(%rip), %rcx    # 0x63bc00
movzbl 0x3(%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x488(%rbp)
movq -0x490(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
leaq -0x480(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x63e0
jmp 0x8fa54
movq -0x490(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x8f8ee
movq -0x490(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x8f8ee
movq -0x490(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x8f8ee
cmpl $0x5, -0x20(%rbp)
jge 0x8f8ee
movl $0x5, -0x20(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x498(%rbp)
jmp 0x8fa39
movq -0x490(%rbp), %rax
movzbl (%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x8f939
movq -0x490(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x8f939
movq -0x490(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x8f939
cmpl $0x4, -0x20(%rbp)
jge 0x8f939
movl $0x4, -0x20(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x498(%rbp)
jmp 0x8fa37
movq -0x490(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x8f984
movq -0x490(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x8f984
movq -0x490(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x8f984
cmpl $0x3, -0x20(%rbp)
jge 0x8f984
movl $0x3, -0x20(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x498(%rbp)
jmp 0x8fa35
movq -0x490(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x8f9bf
movq -0x490(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x8f9bf
cmpl $0x2, -0x20(%rbp)
jge 0x8f9bf
movl $0x2, -0x20(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x498(%rbp)
jmp 0x8fa33
movq -0x490(%rbp), %rax
movzbl (%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x8f9f8
movq -0x490(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x8f9f8
cmpl $0x1, -0x20(%rbp)
jge 0x8f9f8
movl $0x1, -0x20(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x498(%rbp)
jmp 0x8fa31
movq -0x490(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x8fa2f
movq -0x490(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x8fa2f
cmpl $0x0, -0x20(%rbp)
jge 0x8fa2f
movl $0x0, -0x20(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x498(%rbp)
jmp 0x8fa31
jmp 0x8fa33
jmp 0x8fa35
jmp 0x8fa37
jmp 0x8fa39
jmp 0x8fa3b
jmp 0x8fa3d
movq -0x490(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x490(%rbp)
jmp 0x8f819
cmpq $0x0, -0x490(%rbp)
jne 0x8fb41
cmpq $0x0, -0x498(%rbp)
je 0x8fab9
movq -0x498(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rdx
leaq 0x5ac17e(%rip), %rcx    # 0x63bc00
movzbl 0x3(%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x488(%rbp)
movq -0x498(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
leaq -0x480(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x63e0
jmp 0x8fb3f
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jb 0x8facc
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
movslq -0x18(%rbp), %rsi
leaq 0x5ac11b(%rip), %rdx    # 0x63bc00
movzbl 0x3(%rdx,%rsi,4), %edx
addl %edx, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x488(%rbp)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
shll $0x6, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0x480(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rsi
callq 0x63e0
leaq -0x480(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6690
jmp 0x8fb41
movq -0x30(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x8fb57
movq $0x0, -0x8(%rbp)
jmp 0x8ff19
movq -0x488(%rbp), %rax
cmpq $0x0, (%rax)
je 0x8fb86
movq -0x488(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, (%rax)
je 0x8fb86
movq -0x488(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x8ff19
movq -0x488(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x8fbe8
movq -0x30(%rbp), %rsi
movslq -0x18(%rbp), %rcx
leaq 0x5ac05e(%rip), %rax    # 0x63bc00
movzbl 0x3(%rax,%rcx,4), %edx
leaq -0x8b0(%rbp), %rdi
callq 0x8ff30
leaq -0x8b0(%rbp), %rdi
callq 0x98a80
movq %rax, %rcx
movq -0x488(%rbp), %rax
movq %rcx, (%rax)
movq -0x488(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x8fbe6
movq $0x0, -0x8(%rbp)
jmp 0x8ff19
jmp 0x8fbe8
movq -0x488(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, (%rax)
jne 0x8fc8e
movq -0x30(%rbp), %rdi
movq -0x488(%rbp), %rax
movq (%rax), %rsi
movslq -0x18(%rbp), %rcx
leaq 0x5abfec(%rip), %rax    # 0x63bc00
movzbl 0x3(%rax,%rcx,4), %ecx
movl $0x1, %edx
callq 0x98bb0
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x8fc6c
leaq 0x51f9e(%rip), %rax     # 0xe1bd0
cmpl $0x1, (%rax)
jl 0x8fc5f
movl -0x24(%rbp), %edi
callq 0x99fe0
movq %rax, -0x8b8(%rbp)
movq -0x30(%rbp), %rsi
movq -0x8b8(%rbp), %rdx
leaq 0x27554(%rip), %rdi     # 0xb71ac
movb $0x0, %al
callq 0x37c90
movq $0x0, -0x8(%rbp)
jmp 0x8ff19
movq -0x488(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %eax
andl $0x8, %eax
cmpl $0x8, %eax
sete %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jne 0x8fe26
movq -0x488(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
movq -0x488(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jne 0x8fcd8
movq -0x488(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %eax
movq -0x488(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x14(%rcx), %eax
je 0x8fe19
movq -0x488(%rbp), %rax
movq (%rax), %rax
cvtsi2ssl 0x10(%rax), %xmm0
movq -0x488(%rbp), %rax
movq (%rax), %rax
cvtsi2ssl 0x8(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x8bc(%rbp)
movq -0x488(%rbp), %rax
movq (%rax), %rax
cvtsi2ssl 0x14(%rax), %xmm0
movq -0x488(%rbp), %rax
movq (%rax), %rax
cvtsi2ssl 0xc(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x8c0(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x8fd3a
jmp 0x8fe17
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x8fe15
movq -0x10(%rbp), %rax
movq %rax, -0x8c8(%rbp)
movl $0x0, -0x8d4(%rbp)
movl -0x8d4(%rbp), %eax
movq -0x8c8(%rbp), %rcx
cmpl 0xac(%rcx), %eax
jge 0x8fe13
movq -0x8c8(%rbp), %rax
movq 0xc8(%rax), %rax
movslq -0x8d4(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x8d0(%rbp)
movq -0x8d0(%rbp), %rax
movl 0x50(%rax), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jl 0x8fdfd
movss -0x8bc(%rbp), %xmm0
movq -0x8d0(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x20(%rbp), %rcx
mulss (%rax,%rcx,8), %xmm0
movss %xmm0, (%rax,%rcx,8)
movss -0x8c0(%rbp), %xmm0
movq -0x8d0(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x20(%rbp), %rcx
mulss 0x4(%rax,%rcx,8), %xmm0
movss %xmm0, 0x4(%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x8fda8
jmp 0x8fdff
movl -0x8d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8d4(%rbp)
jmp 0x8fd5c
jmp 0x8fe15
jmp 0x8fe17
jmp 0x8fe19
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
leaq 0x55d8e3(%rip), %rax    # 0x5ed710
movq 0xe8(%rax), %rax
leaq 0x51d89(%rip), %rcx     # 0xe1bc4
movslq (%rcx), %rdx
leaq 0x51d1b(%rip), %rcx     # 0xe1b60
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %edx
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
callq *%rax
leaq 0x55d8ae(%rip), %rax    # 0x5ed710
movq 0xe8(%rax), %rax
leaq 0x51d54(%rip), %rcx     # 0xe1bc4
movslq (%rcx), %rdx
leaq 0x51ce6(%rip), %rcx     # 0xe1b60
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %edx
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
callq *%rax
leaq 0x12af19(%rip), %rax    # 0x1badb0
movss 0x14(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x21b28(%rip), %xmm1    # 0xb19d0
ucomisd %xmm1, %xmm0
jbe 0x8fed3
leaq 0x55d85b(%rip), %rax    # 0x5ed710
movq 0xe0(%rax), %rax
leaq 0x55da91(%rip), %rcx    # 0x5ed954
cvtsi2ssl (%rcx), %xmm0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x84fe, %esi           # imm = 0x84FE
callq *%rax
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
movl $0x2901, %edx           # imm = 0x2901
leaq 0x55d827(%rip), %rax    # 0x5ed710
callq *0xe8(%rax)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
movl $0x2901, %edx           # imm = 0x2901
leaq 0x55d80b(%rip), %rax    # 0x5ed710
callq *0xe8(%rax)
movq -0x488(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x8e0, %rsp            # imm = 0x8E0
popq %rbp
retq
nopw %cs:(%rax,%rax)