// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/hightile.c
// Function: hicsetskybox
int hicsetskybox(int picnum, int palnum, char *faces[6])
{
	hicreplctyp *hr, *hrn;
	int j;

	if ((unsigned int)picnum >= (unsigned int)MAXTILES) return -1;
	if ((unsigned int)palnum >= (unsigned int)MAXPALOOKUPS) return -1;
	for (j=5;j>=0;j--) if (!faces[j]) return -1;
	if (!hicfirstinit) hicinit();

	for (hr = hicreplc[picnum]; hr; hr = hr->next) {
		if (hr->palnum == palnum)
			break;
	}

	if (!hr) {
		// no replacement yet defined
		hrn = (hicreplctyp *)calloc(1,sizeof(hicreplctyp));
		if (!hrn) return -1;

		hrn->palnum = palnum;
	} else hrn = hr;

	if (!hrn->skybox) {
		hrn->skybox = (struct hicskybox_t *)calloc(1,sizeof(struct hicskybox_t));
		if (!hrn->skybox) {
			if (hr == NULL) free(hrn);	// not yet a link in the chain
			return -1;
		}
	} else {
		for (j=5;j>=0;j--) {
			if (hrn->skybox->face[j])
				free(hrn->skybox->face[j]);
		}
	}

	// store each face's filename
	for (j=0;j<6;j++) {
		hrn->skybox->face[j] = strdup(faces[j]);
		if (!hrn->skybox->face[j]) {
			for (--j; j>=0; --j)	// free any previous faces
				free(hrn->skybox->face[j]);
			free(hrn->skybox);
			hrn->skybox = NULL;
			if (hr == NULL) free(hrn);
			return -1;
		}
	}
	hrn->skybox->ignore = 0;
	if (hr == NULL) {
		hrn->next = hicreplc[picnum];
		hicreplc[picnum] = hrn;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x2400, %edi           # imm = 0x2400
setae %al
cmpl $0x100, %esi            # imm = 0x100
setae %cl
orb %al, %cl
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
je 0x5fc2e
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %r15d
movl $0x5, %eax
movl %eax, %ecx
cmpq $0x0, (%r14,%rcx,8)
je 0x5fc1d
addl $-0x1, %eax
jb 0x5fc3b
cmpl $0x0, 0x5d6fc0(%rip)    # 0x636c10
jne 0x5fc57
callq 0x5f9e3
movl %r15d, %eax
leaq 0x5d6fbf(%rip), %rcx    # 0x636c20
leaq (%rcx,%rax,8), %r12
movq %r12, %r13
movq (%r13), %r13
testq %r13, %r13
je 0x5fc7f
movzbl 0x8(%r13), %eax
cmpl %ebp, %eax
jne 0x5fc68
movq %r13, %r15
jmp 0x5fc9a
movl $0x1, %edi
movl $0x28, %esi
callq 0x6930
testq %rax, %rax
je 0x5fc1d
movq %rax, %r15
movb %bpl, 0x8(%rax)
movq %r12, (%rsp)
cmpq $0x0, 0x20(%r15)
je 0x5fcc9
movl $0x30, %r12d
movq 0x20(%r15), %rax
movq (%rax,%r12), %rdi
testq %rdi, %rdi
je 0x5fcbd
callq 0x61c0
addq $-0x8, %r12
jne 0x5fcab
movq 0x20(%r15), %r12
jmp 0x5fce8
movl $0x1, %edi
movl $0x38, %esi
callq 0x6930
movq %rax, %r12
movq %rax, 0x20(%r15)
testq %rax, %rax
je 0x5fd68
movl $0x1, %ebp
movq -0x8(%r14,%rbp,8), %rdi
callq 0x6060
movq %rax, (%r12,%rbp,8)
movq 0x20(%r15), %r12
cmpq $0x0, (%r12,%rbp,8)
je 0x5fd34
incq %rbp
cmpq $0x7, %rbp
jne 0x5fced
xorl %ebx, %ebx
movq $0x0, (%r12)
testq %r13, %r13
jne 0x5fc1d
movq (%rsp), %rcx
movq (%rcx), %rax
movq %rax, (%r15)
movq %r15, (%rcx)
jmp 0x5fc1d
cmpq $0x1, %rbp
je 0x5fd58
leal -0x2(%rbp), %eax
movq 0x20(%r15), %rcx
movq 0x8(%rcx,%rax,8), %rdi
callq 0x61c0
decq %rbp
cmpq $0x1, %rbp
jg 0x5fd3a
movq 0x20(%r15), %r12
movq %r12, %rdi
callq 0x61c0
movq $0x0, 0x20(%r15)
testq %r13, %r13
jne 0x5fc1d
movq %r15, %rdi
callq 0x61c0
jmp 0x5fc1d