// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r14
pushq %rbx
subq $0xa0, %rsp
cmpl $0x3, 0x59d2f3(%rip)    # 0x5fa950
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x5d882
leaq 0x15b3b8(%rip), %rax    # 0x1b8a28
cmpl $0xc8, (%rax)
jne 0x5d882
movl %esi, %ebx
movl %edi, %ebp
movslq %edx, %rax
leaq 0x3b2996(%rip), %rsi    # 0x410020
movswl (%rsi,%rax,2), %esi
cvtsi2ss %esi, %xmm2
leaq 0x3a4147(%rip), %rsi    # 0x4017e0
movswl (%rsi,%rax,2), %eax
cvtsi2ss %eax, %xmm0
cvtsi2ss %ecx, %xmm1
ucomiss %xmm2, %xmm1
jb 0x5d6b6
ucomiss %xmm0, %xmm1
jb 0x5d6b6
movss %xmm2, (%rsp)
jmp 0x5d6dd
ucomiss %xmm2, %xmm0
jbe 0x5d6d0
divss %xmm0, %xmm2
movss %xmm1, 0x4(%rsp)
mulss %xmm1, %xmm2
movss %xmm2, (%rsp)
jmp 0x5d6e3
divss %xmm2, %xmm0
mulss %xmm1, %xmm0
movss %xmm1, (%rsp)
movss %xmm0, 0x4(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x47e28(%rip)     # 0xa5514
setne %al
leal 0x1(,%rax,2), %eax
movl %edx, %edi
xorl %esi, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x674d5
testq %rax, %rax
je 0x5d720
movq (%rax), %rcx
movsd 0x10(%rcx), %xmm0
cvtdq2ps %xmm0, %xmm0
movsd 0x8(%rcx), %xmm1
cvtdq2ps %xmm1, %xmm1
divps %xmm1, %xmm0
jmp 0x5d727
movaps 0x1d009(%rip), %xmm0    # 0x7a730
leaq 0x3d9282(%rip), %rcx    # 0x4369b0
movd 0x3fc(%rcx), %xmm1
movb 0x3fe(%rcx), %cl
leaq 0x47049(%rip), %rdx     # 0xa478c
cmpl $0x0, (%rdx)
jne 0x5d78a
movzbl %cl, %ecx
leaq 0x15b2b2(%rip), %rdx    # 0x1b8a04
movslq (%rdx), %rdx
movd %xmm1, %esi
movl $0xff, %edi
movl %esi, %r8d
andl %edi, %r8d
shlq $0x8, %rdx
addq 0x35869(%rip), %rdx     # 0x92fd8
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 0x59d2b0(%rip), %edx    # 0x5faa48
movl %edx, 0x8(%rsp)
testq %rax, %rax
je 0x5d7af
movq (%rax), %rax
testq %rax, %rax
je 0x5d7af
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 0x1cfdc(%rip), %xmm1    # 0x7a7a0
movzbl %cl, %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
leaq 0x8(%rsp), %rsi
divss 0x1cdc5(%rip), %xmm2    # 0x7a5a0
movlps %xmm1, 0x14(%rsi)
xorps %xmm1, %xmm1
cvtsi2ss %ebp, %xmm1
movss %xmm2, 0x1c(%rsi)
movl $0x3f800000, 0x20(%rsi) # imm = 0x3F800000
leaq 0x50(%rsp), %rax
movss %xmm1, (%rax)
xorps %xmm2, %xmm2
cvtsi2ss %ebx, %xmm2
movss %xmm2, 0x4(%rax)
xorl %r14d, %r14d
movq %r14, 0x8(%rax)
movl %r14d, 0x10(%rax)
movss (%rsp), %xmm3
addss %xmm1, %xmm3
movss %xmm3, 0x14(%rax)
movss %xmm2, 0x18(%rax)
movl %r14d, 0x1c(%rax)
movss %xmm0, 0x20(%rax)
movl %r14d, 0x24(%rax)
movss %xmm3, 0x28(%rax)
movss 0x4(%rsp), %xmm3
addss %xmm2, %xmm3
movss %xmm3, 0x2c(%rax)
movl %r14d, 0x30(%rax)
movlps %xmm0, 0x34(%rax)
movss %xmm1, 0x3c(%rax)
movss %xmm3, 0x40(%rax)
movq %r14, 0x44(%rax)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss %xmm0, 0x4c(%rax)
movl $0x4, %ecx
movl %ecx, 0x28(%rsi)
movq %r14, 0x30(%rsi)
movl %ecx, 0x38(%rsi)
movq %rax, 0x40(%rsi)
movl $0x6, %edi
callq 0x5d891
movl %r14d, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %rbp
retq