// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/polymosttex.c
// Function: pt_load_hightile
static int pt_load_hightile(PTHead * pth)
{
	const char *filename = 0;
	int effects = 0;
	int err = 0;
	int texture = 0, loaded[PTHPIC_SIZE] = { 0,0,0,0,0,0, };
    PTMIdent id;

	if (!pth->repldef) {
		return 0;
	} else if ((pth->flags & PTH_SKYBOX) && (pth->repldef->skybox == 0 || pth->repldef->skybox->ignore)) {
		return 0;
	} else if (pth->repldef->ignore) {
		return 0;
	}

	effects = (pth->palnum != pth->repldef->palnum) ? hictinting[pth->palnum].f : 0;

	pth->flags &= ~(PTH_NOCOMPRESS | PTH_HASALPHA);
	if (pth->repldef->flags & HIC_NOCOMPRESS) {
		pth->flags |= PTH_NOCOMPRESS;
	}

	for (texture = 0; texture < PTHPIC_SIZE; texture++) {
		if (pth->flags & PTH_SKYBOX) {
			if (texture >= 6) {
				texture = PTHPIC_SIZE;
				continue;
			}
			filename = pth->repldef->skybox->face[texture];
		} else {
			switch (texture) {
				case PTHPIC_BASE:
					filename = pth->repldef->filename;
					break;
				default:
					// future developments may use the other indices
					texture = PTHPIC_SIZE;
					continue;
			}
		}

		if (!filename) {
			continue;
		}

        PTM_InitIdent(&id, pth);
        id.layer = texture;
        pth->pic[texture] = PTM_GetHead(&id);

		if ((err = PTM_LoadTextureFile(filename, pth->pic[texture], pth->flags, effects))) {
			if (polymosttexverbosity >= 1) {
				const char * errstr = PTM_GetLoadTextureFileErrorString(err);
				buildprintf("PolymostTex: %s (pic %d pal %d) %s\n",
						   filename, pth->picnum, pth->palnum, errstr);
			}
			continue;
		}

		if (texture == 0) {
			if (pth->flags & PTH_SKYBOX) {
				pth->scalex = (float)pth->pic[texture]->tsizx / 64.0;
				pth->scaley = (float)pth->pic[texture]->tsizy / 64.0;
			} else {
				pth->scalex = (float)pth->pic[texture]->tsizx / (float)tilesizx[pth->picnum];
				pth->scaley = (float)pth->pic[texture]->tsizy / (float)tilesizy[pth->picnum];
			}
		}

		loaded[texture] = 1;
	}

	pt_load_applyparameters(pth);

	if (pth->flags & PTH_SKYBOX) {
		int i = 0;
		for (texture = 0; texture < 6; texture++) i += loaded[texture];
		return (i == 6);
	} else {
		return loaded[PTHPIC_BASE];
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq 0x40(%rdi), %rdx
xorl %eax, %eax
testq %rdx, %rdx
je 0x5d154
movq %rdi, %rbx
movzwl 0x38(%rdi), %ecx
testb $0x4, %cl
jne 0x5d113
cmpb $0x0, 0x9(%rdx)
jne 0x5d154
movslq 0x34(%rbx), %rax
movzbl 0x8(%rdx), %esi
xorl %ebp, %ebp
cmpl %esi, %eax
je 0x5cfc8
leaq 0x5e4c5d(%rip), %rsi    # 0x641c20
movzbl 0x3(%rsi,%rax,4), %ebp
andl $0xffe7, %ecx           # imm = 0xFFE7
movw %cx, 0x38(%rbx)
testb $0x1, 0xa(%rdx)
je 0x5cfdf
orl $0x10, %ecx
movw %cx, 0x38(%rbx)
leaq 0x20(%rsp), %r14
xorl %r15d, %r15d
cmpl $0x5, %r15d
jg 0x5d127
testb $0x4, 0x38(%rbx)
movslq %r15d, %r13
jne 0x5d010
pushq $0x6
popq %rax
testl %r15d, %r15d
jne 0x5d109
movq 0x40(%rbx), %rax
addq $0x10, %rax
jmp 0x5d020
movq 0x40(%rbx), %rax
movq 0x20(%rax), %rax
leaq (%rax,%r13,8), %rax
addq $0x8, %rax
movq (%rax), %r12
testq %r12, %r12
je 0x5d106
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5b6e8
movl %r15d, 0x30(%rsp)
movq %r14, %rdi
callq 0x5b7b0
movq %rax, (%rbx,%r13,8)
movzwl 0x38(%rbx), %edx
movq %r12, %rdi
movq %rax, %rsi
movl %ebp, %ecx
callq 0x5b84a
testl %eax, %eax
je 0x5d08d
cmpl $0x0, 0x41528(%rip)     # 0x9e58c
jle 0x5d106
movl %eax, %edi
callq 0x5c526
movl 0x30(%rbx), %edx
movl 0x34(%rbx), %ecx
leaq 0x140b1(%rip), %rdi     # 0x7112f
movq %r12, %rsi
movq %rax, %r8
xorl %eax, %eax
callq 0x22427
jmp 0x5d106
testl %r15d, %r15d
jne 0x5d0fe
testb $0x4, 0x38(%rbx)
movq (%rbx,%r13,8), %rax
cvtsi2ssl 0x10(%rax), %xmm0
jne 0x5d0db
movslq 0x30(%rbx), %rax
leaq 0x3abf74(%rip), %rcx    # 0x409020
movswl (%rcx,%rax,2), %ecx
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x48(%rbx)
movq (%rbx,%r13,8), %rcx
cvtsi2ssl 0x14(%rcx), %xmm0
leaq 0x39d713(%rip), %rcx    # 0x3fa7e0
movswl (%rcx,%rax,2), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
jmp 0x5d0f9
movss 0x130ad(%rip), %xmm1    # 0x70190
mulss %xmm1, %xmm0
movss %xmm0, 0x48(%rbx)
movq (%rbx,%r13,8), %rax
cvtsi2ssl 0x14(%rax), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0x4c(%rbx)
movl $0x1, (%rsp,%r13,4)
movl %r15d, %eax
incl %eax
movl %eax, %r15d
jmp 0x5cfe7
movq 0x20(%rdx), %rsi
testq %rsi, %rsi
je 0x5d154
cmpq $0x0, (%rsi)
jne 0x5d154
jmp 0x5cfa4
movq %rbx, %rdi
callq 0x5d5dc
testb $0x4, 0x38(%rbx)
jne 0x5d13a
movl (%rsp), %eax
jmp 0x5d154
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x6, %rax
je 0x5d14c
addl (%rsp,%rax,4), %ecx
incq %rax
jmp 0x5d13e
xorl %eax, %eax
cmpl $0x6, %ecx
sete %al
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq