// File: /workspace/github_c_makefile_star2_O3/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 0x67d45
movq %rdi, %rbx
movzwl 0x38(%rdi), %ecx
testb $0x4, %cl
jne 0x67d19
cmpb $0x0, 0x9(%rdx)
jne 0x67d45
movslq 0x34(%rbx), %rax
movzbl 0x8(%rdx), %esi
xorl %ebp, %ebp
cmpl %esi, %eax
je 0x67baa
leaq 0x5e107b(%rip), %rsi    # 0x648c20
movzbl 0x3(%rsi,%rax,4), %ebp
andl $0xffe7, %ecx           # imm = 0xFFE7
movw %cx, 0x38(%rbx)
testb $0x1, 0xa(%rdx)
je 0x67bc1
orl $0x10, %ecx
movw %cx, 0x38(%rbx)
movl $0x8, %r13d
leaq 0x20(%rsp), %r14
xorl %r15d, %r15d
testb $0x4, 0x38(%rbx)
jne 0x67be8
testl %r15d, %r15d
jne 0x67d06
movq 0x40(%rbx), %rax
addq $0x10, %rax
jmp 0x67bf3
movq 0x40(%rbx), %rax
movq 0x20(%rax), %rax
addq %r13, %rax
movq (%rax), %r12
testq %r12, %r12
je 0x67cf2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x66184
movl %r15d, 0x30(%rsp)
movq %r14, %rdi
callq 0x6624c
movq %rax, (%rbx,%r15,8)
movzwl 0x38(%rbx), %edx
movq %r12, %rdi
movq %rax, %rsi
movl %ebp, %ecx
callq 0x662f6
testl %eax, %eax
je 0x67c6a
cmpl $0x0, 0x3d955(%rip)     # 0xa558c
jle 0x67cf2
cltq
leaq 0x145f2(%rip), %rcx     # 0x7c238
movslq 0x14(%rcx,%rax,4), %r8
addq %rcx, %r8
movl 0x30(%rbx), %edx
movl 0x34(%rbx), %ecx
leaq 0x147a8(%rip), %rdi     # 0x7c403
movq %r12, %rsi
xorl %eax, %eax
callq 0x25221
jmp 0x67cf2
testl %r15d, %r15d
jne 0x67cea
testb $0x4, 0x38(%rbx)
movq (%rbx,%r15,8), %rax
xorps %xmm0, %xmm0
cvtsi2ssl 0x10(%rax), %xmm0
jne 0x67cc4
movslq 0x30(%rbx), %rax
leaq 0x3a8394(%rip), %rcx    # 0x410020
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 0x399b2d(%rip), %rcx    # 0x4017e0
movswl (%rcx,%rax,2), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
jmp 0x67ce5
movss 0x13784(%rip), %xmm1    # 0x7b450
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)
incq %r15
leal -0x1(%r15), %eax
addq $0x8, %r13
cmpl $0x5, %eax
jb 0x67bcf
movq %rbx, %rdi
callq 0x681eb
testb $0x4, 0x38(%rbx)
jne 0x67d2d
movl (%rsp), %eax
jmp 0x67d45
movq 0x20(%rdx), %rsi
testq %rsi, %rsi
je 0x67d45
cmpq $0x0, (%rsi)
jne 0x67d45
jmp 0x67b86
xorl %eax, %eax
xorl %ecx, %ecx
addl (%rsp,%rax,4), %ecx
incq %rax
cmpq $0x6, %rax
jne 0x67d31
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