// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/polymosttex.c
// Function: pt_findhash
static PTHash * pt_findhash(int picnum, int palnum, unsigned short flags, int create)
{
	int i = pt_gethashhead(picnum);
	PTHash * pth;

	unsigned short flagmask = flags & (PTH_HIGHTILE | PTH_CLAMPED | PTH_SKYBOX);

	// first, try and find an existing match for our parameters
	pth = pthashhead[i];
	while (pth) {
		if (pth->head.picnum == picnum &&
		    pth->head.palnum == palnum &&
		    (pth->head.flags & (PTH_HIGHTILE | PTH_CLAMPED | PTH_SKYBOX)) == flagmask
		   ) {
			while (pth->deferto) {
				pth = pth->deferto;	// find the end of the chain
			}
			return pth;
		}

		pth = pth->next;
	}

	if (!create) {
		return 0;
	} else {
		// we didn't find one, so we have to create one
		hicreplctyp * replc = 0;

		if ((flags & PTH_HIGHTILE)) {
			replc = hicfindsubst(picnum, palnum, (flags & PTH_SKYBOX));
		}

		pth = (PTHash *) malloc(sizeof(PTHash));
		if (!pth) {
			return 0;
		}
		memset(pth, 0, sizeof(PTHash));

		pth->next = pthashhead[i];
		pth->head.picnum  = picnum;
		pth->head.palnum  = palnum;
		pth->head.flags   = flagmask;
		pth->head.repldef = replc;

		pthashhead[i] = pth;

		if (replc && replc->palnum != palnum) {
			// we were given a substitute by hightile, so
			if (hictinting[palnum].f & HICEFFECTMASK) {
				// if effects are defined for the palette we actually want
				// we DO NOT defer immediately to the substitute. instead
				// we apply effects to the replacement and treat it as a
				// distinct texture
				;
			} else {
				// we defer to the substitute
				pth->deferto = pt_findhash(picnum, replc->palnum, flags, create);
				while (pth->deferto) {
					pth = pth->deferto;	// find the end of the chain
				}
			}
		} else if ((flags & PTH_HIGHTILE) && !replc) {
			// there is no replacement, so defer to ART
			if (flags & PTH_SKYBOX) {
				return 0;
			} else {
				pth->deferto = pt_findhash(picnum, palnum, (flags & ~PTH_HIGHTILE), create);
				while (pth->deferto) {
					pth = pth->deferto;	// find the end of the chain
				}
			}
		}
	}

	return pth;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %dx, %ax
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movl %ecx, -0x18(%rbp)
movl -0xc(%rbp), %edi
callq 0x9a940
movl %eax, -0x1c(%rbp)
movzwl -0x12(%rbp), %eax
andl $0x7, %eax
movw %ax, -0x2a(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x614fe7(%rip), %rax    # 0x6af160
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x9a1e8
movq -0x28(%rbp), %rax
movl 0x38(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x9a1db
movq -0x28(%rbp), %rax
movl 0x3c(%rax), %eax
cmpl -0x10(%rbp), %eax
jne 0x9a1db
movq -0x28(%rbp), %rax
movzwl 0x40(%rax), %eax
andl $0x7, %eax
movzwl -0x2a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9a1db
jmp 0x9a1b5
movq -0x28(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x9a1ce
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x9a1b5
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9a391
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x9a181
cmpl $0x0, -0x18(%rbp)
jne 0x9a1fb
movq $0x0, -0x8(%rbp)
jmp 0x9a391
movq $0x0, -0x38(%rbp)
movzwl -0x12(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x9a225
movl -0xc(%rbp), %edi
movl -0x10(%rbp), %esi
movzwl -0x12(%rbp), %edx
andl $0x4, %edx
callq 0x8df50
movq %rax, -0x38(%rbp)
movl $0x68, %edi
callq 0x68f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x9a247
movq $0x0, -0x8(%rbp)
jmp 0x9a391
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x62d0
movslq -0x1c(%rbp), %rcx
leaq 0x614efe(%rip), %rax    # 0x6af160
movq (%rax,%rcx,8), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x38(%rax)
movl -0x10(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x3c(%rax)
movw -0x2a(%rbp), %cx
movq -0x28(%rbp), %rax
movw %cx, 0x40(%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x28(%rbp), %rdx
movslq -0x1c(%rbp), %rcx
leaq 0x614eb8(%rip), %rax    # 0x6af160
movq %rdx, (%rax,%rcx,8)
cmpq $0x0, -0x38(%rbp)
je 0x9a31c
movq -0x38(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl -0x10(%rbp), %eax
je 0x9a31c
movslq -0x10(%rbp), %rcx
leaq 0x5a1935(%rip), %rax    # 0x63bc00
movzbl 0x3(%rax,%rcx,4), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x9a2da
jmp 0x9a31a
movl -0xc(%rbp), %edi
movq -0x38(%rbp), %rax
movzbl 0x8(%rax), %esi
movw -0x12(%rbp), %ax
movl -0x18(%rbp), %ecx
movzwl %ax, %edx
callq 0x9a140
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x9a318
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x9a2ff
jmp 0x9a31a
jmp 0x9a387
movzwl -0x12(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x9a385
cmpq $0x0, -0x38(%rbp)
jne 0x9a385
movzwl -0x12(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x9a345
movq $0x0, -0x8(%rbp)
jmp 0x9a391
movl -0xc(%rbp), %edi
movl -0x10(%rbp), %esi
movzwl -0x12(%rbp), %eax
andl $-0x3, %eax
movl -0x18(%rbp), %ecx
movzwl %ax, %edx
callq 0x9a140
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x9a381
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x9a368
jmp 0x9a383
jmp 0x9a385
jmp 0x9a387
jmp 0x9a389
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)