// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/hightile.c
// Function: hicsetsubsttex
int hicsetsubsttex(int picnum, int palnum, char *filen, float alphacut, unsigned char flags)
{
	hicreplctyp *hr, *hrn;

	if ((unsigned int)picnum >= (unsigned int)MAXTILES) return -1;
	if ((unsigned int)palnum >= (unsigned int)MAXPALOOKUPS) 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;

	// store into hicreplc the details for this replacement
	if (hrn->filename) free(hrn->filename);

	hrn->filename = strdup(filen);
	if (!hrn->filename) {
		if (hrn->skybox) return -1;	// don't free the base structure if there's a skybox defined
		if (hr == NULL) free(hrn);	// not yet a link in the chain
		return -1;
	}
	hrn->ignore = 0;
	hrn->alphacut = min(alphacut,1.0);
	hrn->flags = flags;
	if (hr == NULL) {
		hrn->next = hicreplc[picnum];
		hicreplc[picnum] = hrn;
	}

	//printf("Replacement [%d,%d]: %s\n", picnum, palnum, hicreplc[i]->filename);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %cl, %al
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movb %al, -0x1d(%rbp)
cmpl $0x2400, -0x8(%rbp)     # imm = 0x2400
jb 0x8e261
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8e3fa
cmpl $0x100, -0xc(%rbp)      # imm = 0x100
jb 0x8e276
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8e3fa
cmpl $0x0, 0x59b973(%rip)    # 0x629bf0
jne 0x8e284
callq 0x8e030
movslq -0x8(%rbp), %rcx
leaq 0x59b971(%rip), %rax    # 0x629c00
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x8e2bc
movq -0x28(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x8e2ad
jmp 0x8e2bc
jmp 0x8e2af
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x8e297
cmpq $0x0, -0x28(%rbp)
jne 0x8e2f7
movl $0x1, %edi
movl $0x28, %esi
callq 0x6880
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8e2e9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8e3fa
movl -0xc(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x8(%rax)
jmp 0x8e2ff
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x8e317
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x61c0
movq -0x18(%rbp), %rdi
callq 0x6060
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x8e369
movq -0x30(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x8e34d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8e3fa
cmpq $0x0, -0x28(%rbp)
jne 0x8e35d
movq -0x30(%rbp), %rdi
callq 0x61c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8e3fa
movq -0x30(%rbp), %rax
movb $0x0, 0x9(%rax)
movss -0x1c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2364e(%rip), %xmm0    # 0xb19d0
ucomisd %xmm1, %xmm0
jbe 0x8e398
movss -0x1c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x8e3a7
movsd 0x23630(%rip), %xmm0    # 0xb19d0
movsd %xmm0, -0x38(%rbp)
jmp 0x8e3a7
movsd -0x38(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x30(%rbp), %rax
movss %xmm0, 0x18(%rax)
movb -0x1d(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, 0xa(%rax)
cmpq $0x0, -0x28(%rbp)
jne 0x8e3f3
movslq -0x8(%rbp), %rcx
leaq 0x59b82b(%rip), %rax    # 0x629c00
movq (%rax,%rcx,8), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdx
movslq -0x8(%rbp), %rcx
leaq 0x59b811(%rip), %rax    # 0x629c00
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)