// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: md_defineskin
int md_defineskin (int modelid, const char *skinfn, int palnum, int skinnum, int surfnum)
{
	mdskinmap_t *sk, *skl;
	md2model *m;

	if (!mdinited) mdinit();

	if ((unsigned int)modelid >= (unsigned int)nextmodelid) return -1;
	if (!skinfn) return -2;
	if ((unsigned)palnum >= (unsigned)MAXPALOOKUPS) return -3;

	m = (md2model *)models[modelid];
	if (m->mdnum < 2) return 0;
	if (m->mdnum == 2) surfnum = 0;

	skl = NULL;
	for (sk = m->skinmap; sk; skl = sk, sk = sk->next)
		if (sk->palette == (unsigned char)palnum && skinnum == sk->skinnum && surfnum == sk->surfnum) break;
	if (!sk) {
		sk = (mdskinmap_t *)calloc(1,sizeof(mdskinmap_t));
		if (!sk) return -4;

		if (!skl) m->skinmap = sk;
		else skl->next = sk;
	} else if (sk->fn) free(sk->fn);

	sk->palette = (unsigned char)palnum;
	sk->skinnum = skinnum;
	sk->surfnum = surfnum;
	sk->fn = (char *)malloc(strlen(skinfn)+1);
	if (!sk->fn) return(-4);
	strcpy(sk->fn, skinfn);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
cmpb $0x0, 0x5accb0(%rip)    # 0x63c000
jne 0x8f357
callq 0x8ed00
movl -0x8(%rbp), %eax
cmpl 0x5acca4(%rip), %eax    # 0x63c004
jb 0x8f36e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f501
cmpq $0x0, -0x10(%rbp)
jne 0x8f381
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x8f501
cmpl $0x100, -0x14(%rbp)     # imm = 0x100
jb 0x8f396
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x8f501
movq 0x5acc6b(%rip), %rax    # 0x63c008
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jge 0x8f3be
movl $0x0, -0x4(%rbp)
jmp 0x8f501
movq -0x38(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x8f3ce
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x8f42c
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movl -0x14(%rbp), %ecx
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x8f414
movl -0x18(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x8f414
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x8f414
jmp 0x8f42c
jmp 0x8f416
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x8f3e2
cmpq $0x0, -0x28(%rbp)
jne 0x8f47c
movl $0x1, %edi
movl $0x40, %esi
callq 0x6880
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x8f459
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x8f501
cmpq $0x0, -0x30(%rbp)
jne 0x8f46e
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x8f47a
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0x8f496
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x8f494
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x61c0
jmp 0x8f496
movl -0x14(%rbp), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rdi
callq 0x63d0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x68f0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x8f4e9
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x8f501
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x63e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)