// File: /workspace/github_c_makefile_star2_O1/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
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x40(%rdi), %rdx
xorl %eax, %eax
testq %rdx, %rdx
je 0x6603a
movq %rdi, %rbx
movzwl 0x38(%rdi), %ecx
testb $0x4, %cl
jne 0x6600e
cmpb $0x0, 0x9(%rdx)
jne 0x6603a
movslq 0x34(%rbx), %rax
movzbl 0x8(%rdx), %esi
xorl %ebp, %ebp
cmpl %esi, %eax
je 0x65e9c
leaq 0x5e1d99(%rip), %rsi    # 0x647c30
movzbl 0x3(%rsi,%rax,4), %ebp
andl $0xffe7, %ecx           # imm = 0xFFE7
movw %cx, 0x38(%rbx)
testb $0x1, 0xa(%rdx)
je 0x65eb3
orl $0x10, %ecx
movw %cx, 0x38(%rbx)
leaq 0x20(%rsp), %r14
xorl %r13d, %r13d
testb $0x4, 0x38(%rbx)
jne 0x65ed9
movl $0x6, %eax
testl %r13d, %r13d
jne 0x65fee
movq 0x40(%rbx), %rax
addq $0x10, %rax
jmp 0x65eec
movq 0x40(%rbx), %rax
movq 0x20(%rax), %rax
movslq %r13d, %rcx
leaq (%rax,%rcx,8), %rax
addq $0x8, %rax
movq (%rax), %r12
testq %r12, %r12
je 0x65feb
movq %r14, %rdi
movq %rbx, %rsi
callq 0x64420
movl %r13d, 0x30(%rsp)
movq %r14, %rdi
callq 0x644ee
movslq %r13d, %r15
movq %rax, (%rbx,%r15,8)
movzwl 0x38(%rbx), %edx
movq %r12, %rdi
movq %rax, %rsi
movl %ebp, %ecx
callq 0x64591
testl %eax, %eax
je 0x65f63
cmpl $0x0, 0x3e659(%rip)     # 0xa458c
jle 0x65feb
cltq
leaq 0x2bc0e(%rip), %rcx     # 0x91b50
movq 0x28(%rcx,%rax,8), %r8
movl 0x30(%rbx), %edx
movl 0x34(%rbx), %ecx
leaq 0x14fc3(%rip), %rdi     # 0x7af17
movq %r12, %rsi
xorl %eax, %eax
callq 0x24cb4
jmp 0x65feb
testl %r13d, %r13d
jne 0x65fe3
testb $0x4, 0x38(%rbx)
movq (%rbx,%r15,8), %rax
xorps %xmm0, %xmm0
cvtsi2ssl 0x10(%rax), %xmm0
jne 0x65fbd
movslq 0x30(%rbx), %rax
leaq 0x3a909b(%rip), %rcx    # 0x40f020
movswl (%rcx,%rax,2), %ecx
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x48(%rbx)
movq (%rbx,%r15,8), %rcx
xorps %xmm0, %xmm0
cvtsi2ssl 0x14(%rcx), %xmm0
leaq 0x39a834(%rip), %rcx    # 0x4007e0
movswl (%rcx,%rax,2), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
jmp 0x65fde
movss 0x1400b(%rip), %xmm1    # 0x79fd0
mulss %xmm1, %xmm0
movss %xmm0, 0x48(%rbx)
movq (%rbx,%r15,8), %rax
xorps %xmm0, %xmm0
cvtsi2ssl 0x14(%rax), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0x4c(%rbx)
movl $0x1, (%rsp,%r15,4)
movl %r13d, %eax
leal 0x1(%rax), %r13d
cmpl $0x5, %eax
jl 0x65ebb
movq %rbx, %rdi
callq 0x664b7
testb $0x4, 0x38(%rbx)
jne 0x66022
movl (%rsp), %eax
jmp 0x6603a
movq 0x20(%rdx), %rsi
testq %rsi, %rsi
je 0x6603a
cmpq $0x0, (%rsi)
jne 0x6603a
jmp 0x65e78
xorl %eax, %eax
xorl %ecx, %ecx
addl (%rsp,%rax,4), %ecx
incq %rax
cmpq $0x6, %rax
jne 0x66026
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