// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/polymost.c
// Function: polymost_drawtilescreen
int polymost_drawtilescreen (int tilex, int tiley, int wallnum, int dimen)
{
	float xdime, ydime, xdimepad, ydimepad, scx, scy;
	PTHead *pth;
	palette_t bgcolour;
	struct polymostdrawauxcall draw;
	struct polymostvboitem vboitem[4];

	if ((rendmode != 3) || (qsetmode != 200)) return(-1);

	xdime = (float)tilesizx[wallnum];
	ydime = (float)tilesizy[wallnum];

	if ((xdime <= dimen) && (ydime <= dimen)) {
		scx = xdime;
		scy = ydime;
	} else {
		scx = (float)dimen;
		scy = (float)dimen;
		if (xdime < ydime) {
			scx *= xdime/ydime;
		} else {
			scy *= ydime/xdime;
		}
	}

	pth = PT_GetHead(wallnum, 0, (usehightile ? PTH_HIGHTILE : 0) | PTH_CLAMPED, 0);

	if (pth) {
		xdimepad = (float)pth->pic[PTHPIC_BASE]->tsizx / (float)pth->pic[PTHPIC_BASE]->sizx;
		ydimepad = (float)pth->pic[PTHPIC_BASE]->tsizy / (float)pth->pic[PTHPIC_BASE]->sizy;
	} else {
		xdimepad = 1.0;
		ydimepad = 1.0;
	}

	bgcolour = curpalette[255];
	if (!usegammabrightness) {
		bgcolour.r = britable[curbrightness][bgcolour.r];
		bgcolour.g = britable[curbrightness][bgcolour.g];
		bgcolour.b = britable[curbrightness][bgcolour.b];
	}

	draw.mode = 1;	// Tile.

	draw.texture0 = nulltexture;
	if (pth) {
		if (pth->pic[PTHPIC_BASE]) {
			draw.texture0 = pth->pic[PTHPIC_BASE]->glpic;
		}
	}

	draw.bgcolour.r = bgcolour.r / 255.f;
	draw.bgcolour.g = bgcolour.g / 255.f;
	draw.bgcolour.b = bgcolour.b / 255.f;
	draw.bgcolour.a = 1.f;

	vboitem[0].v.x = (GLfloat)tilex;
	vboitem[0].v.y = (GLfloat)tiley;
	vboitem[0].v.z = 0.f;
	vboitem[0].t.s = 0.f;
	vboitem[0].t.t = 0.f;

	vboitem[1].v.x = (GLfloat)tilex+scx;
	vboitem[1].v.y = (GLfloat)tiley;
	vboitem[1].v.z = 0.f;
	vboitem[1].t.s = xdimepad;
	vboitem[1].t.t = 0.f;

	vboitem[2].v.x = (GLfloat)tilex+scx;
	vboitem[2].v.y = (GLfloat)tiley+scy;
	vboitem[2].v.z = 0.f;
	vboitem[2].t.s = xdimepad;
	vboitem[2].t.t = ydimepad;

	vboitem[3].v.x = (GLfloat)tilex;
	vboitem[3].v.y = (GLfloat)tiley+scy;
	vboitem[3].v.z = 0.f;
	vboitem[3].t.s = 0.f;
	vboitem[3].t.t = ydimepad;

	draw.indexcount = 4;
	draw.indexes = NULL;
	draw.elementcount = 4;
	draw.elementvbo = vboitem;

	polymost_drawaux_glcall(GL_TRIANGLE_FAN, &draw);

	return(0);
}

// Assembly:
cmpl $0x3, 0x5a06ae(%rip)    # 0x5f3950
pushq $-0x1
popq %rax
jne 0x534cb
pushq %rbp
pushq %rbx
subq $0xa8, %rsp
movl %esi, %ebx
leaq 0x15e76b(%rip), %rsi    # 0x1b1a28
cmpl $0xc8, (%rsi)
jne 0x534c2
movl %edi, %ebp
movslq %edx, %rax
leaq 0x3b5d4b(%rip), %rsi    # 0x409020
movswl (%rsi,%rax,2), %esi
cvtsi2ss %esi, %xmm2
leaq 0x3a74fc(%rip), %rsi    # 0x3fa7e0
movswl (%rsi,%rax,2), %eax
cvtsi2ss %eax, %xmm0
cvtsi2ss %ecx, %xmm1
ucomiss %xmm2, %xmm1
jb 0x53301
ucomiss %xmm0, %xmm1
jb 0x53301
movss %xmm2, (%rsp)
jmp 0x53328
ucomiss %xmm2, %xmm0
jbe 0x5331b
divss %xmm0, %xmm2
movss %xmm1, 0x4(%rsp)
mulss %xmm1, %xmm2
movss %xmm2, (%rsp)
jmp 0x5332e
divss %xmm2, %xmm0
mulss %xmm1, %xmm0
movss %xmm1, (%rsp)
movss %xmm0, 0x4(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x4b1dd(%rip)     # 0x9e514
setne %al
leal 0x1(,%rax,2), %eax
movl %edx, %edi
xorl %esi, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x5c910
testq %rax, %rax
je 0x5336b
movq (%rax), %rcx
movsd 0x10(%rcx), %xmm0
cvtdq2ps %xmm0, %xmm0
movsd 0x8(%rcx), %xmm1
cvtdq2ps %xmm1, %xmm1
divps %xmm1, %xmm0
jmp 0x53372
movaps 0x1c12e(%rip), %xmm0    # 0x6f4a0
leaq 0x3dc637(%rip), %rcx    # 0x42f9b0
movd 0x3fc(%rcx), %xmm1
movb 0x3fe(%rcx), %cl
leaq 0x4a3fe(%rip), %rdx     # 0x9d78c
cmpl $0x0, (%rdx)
jne 0x533d5
movzbl %cl, %ecx
leaq 0x15e667(%rip), %rdx    # 0x1b1a04
movslq (%rdx), %rdx
movd %xmm1, %esi
movl $0xff, %edi
movl %esi, %r8d
andl %edi, %r8d
shlq $0x8, %rdx
addq 0x38c16(%rip), %rdx     # 0x8bfd0
movzbl (%r8,%rdx), %r8d
shrl $0x8, %esi
andl %edi, %esi
movb (%rcx,%rdx), %cl
movzbl (%rsi,%rdx), %edx
shll $0x8, %edx
orl %r8d, %edx
movd %edx, %xmm1
movl $0x1, 0x2c(%rsp)
movl 0x5a0665(%rip), %edx    # 0x5f3a48
movl %edx, 0x8(%rsp)
testq %rax, %rax
je 0x533fa
movq (%rax), %rax
testq %rax, %rax
je 0x533fa
movl (%rax), %eax
movl %eax, 0x8(%rsp)
xorps %xmm2, %xmm2
punpcklbw %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3],xmm1[4],xmm2[4],xmm1[5],xmm2[5],xmm1[6],xmm2[6],xmm1[7],xmm2[7]
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
cvtdq2ps %xmm1, %xmm1
divps 0x1c0d1(%rip), %xmm1    # 0x6f4e0
movzbl %cl, %eax
cvtsi2ss %eax, %xmm2
cvtsi2ss %ebp, %xmm3
leaq 0x50(%rsp), %rax
movss %xmm3, (%rax)
cvtsi2ss %ebx, %xmm4
movss %xmm4, 0x4(%rax)
andq $0x0, 0x8(%rax)
leaq 0x8(%rsp), %rsi
andl $0x0, 0x10(%rax)
divss 0x1bede(%rip), %xmm2    # 0x6f320
movss (%rsp), %xmm5
addss %xmm3, %xmm5
movss %xmm5, 0x14(%rax)
movss %xmm4, 0x18(%rax)
andl $0x0, 0x1c(%rax)
movss %xmm0, 0x20(%rax)
andl $0x0, 0x24(%rax)
movlps %xmm1, 0x14(%rsi)
movss %xmm2, 0x1c(%rsi)
movss %xmm5, 0x28(%rax)
movss 0x4(%rsp), %xmm1
addss %xmm4, %xmm1
movss %xmm1, 0x2c(%rax)
andl $0x0, 0x30(%rax)
movl $0x3f800000, 0x20(%rsi) # imm = 0x3F800000
movlps %xmm0, 0x34(%rax)
movss %xmm3, 0x3c(%rax)
movss %xmm1, 0x40(%rax)
andq $0x0, 0x44(%rax)
pushq $0x4
popq %rcx
movl %ecx, 0x28(%rsi)
andq $0x0, 0x30(%rsi)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss %xmm0, 0x4c(%rax)
movl %ecx, 0x38(%rsi)
movq %rax, 0x40(%rsi)
pushq $0x6
popq %rdi
callq 0x534cc
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %rbp
retq