// File: /workspace/github_c_makefile_star2_O1/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 0x5db75
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 0x5db64
addl $-0x1, %eax
jb 0x5db82
cmpl $0x0, 0x5d8089(%rip)    # 0x635c20
jne 0x5db9e
callq 0x5d92b
movl %r15d, %eax
leaq 0x5d8088(%rip), %rcx    # 0x635c30
leaq (%rcx,%rax,8), %r13
movq %r13, %r12
movq (%r12), %r12
testq %r12, %r12
je 0x5dbc7
movzbl 0x8(%r12), %eax
cmpl %ebp, %eax
jne 0x5dbaf
movq %r12, %r15
jmp 0x5dbe2
movl $0x1, %edi
movl $0x28, %esi
callq 0x6930
testq %rax, %rax
je 0x5db64
movq %rax, %r15
movb %bpl, 0x8(%rax)
cmpq $0x0, 0x20(%r15)
je 0x5dc08
movl $0x30, %ebp
movq 0x20(%r15), %rax
movq (%rax,%rbp), %rdi
testq %rdi, %rdi
je 0x5dc00
callq 0x61c0
addq $-0x8, %rbp
jne 0x5dbee
jmp 0x5dc24
movl $0x1, %edi
movl $0x38, %esi
callq 0x6930
movq %rax, 0x20(%r15)
testq %rax, %rax
je 0x5dca6
movl $0x1, %ebp
movq -0x8(%r14,%rbp,8), %rdi
callq 0x6060
movq 0x20(%r15), %rcx
movq %rax, (%rcx,%rbp,8)
movq 0x20(%r15), %rax
cmpq $0x0, (%rax,%rbp,8)
je 0x5dc75
incq %rbp
cmpq $0x7, %rbp
jne 0x5dc29
xorl %ebx, %ebx
movq 0x20(%r15), %rax
movq $0x0, (%rax)
testq %r12, %r12
jne 0x5db64
movq (%r13), %rax
movq %rax, (%r15)
movq %r15, (%r13)
jmp 0x5db64
cmpq $0x1, %rbp
je 0x5dc95
leal -0x2(%rbp), %eax
movq 0x20(%r15), %rcx
movq 0x8(%rcx,%rax,8), %rdi
callq 0x61c0
decq %rbp
cmpq $0x1, %rbp
jg 0x5dc7b
movq 0x20(%r15), %rdi
callq 0x61c0
movq $0x0, 0x20(%r15)
testq %r12, %r12
jne 0x5db64
movq %r15, %rdi
callq 0x61c0
jmp 0x5db64