// File: /workspace/github_c_makefile_star2_O1/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, 0x59e465(%rip)    # 0x5f9950
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x5b726
leaq 0x15c52a(%rip), %rax    # 0x1b7a28
cmpl $0xc8, (%rax)
jne 0x5b726
movl %esi, %ebx
movl %edi, %ebp
movslq %edx, %rax
leaq 0x3b3b08(%rip), %rsi    # 0x40f020
movswl (%rsi,%rax,2), %esi
cvtsi2ss %esi, %xmm2
leaq 0x3a52b9(%rip), %rsi    # 0x4007e0
movswl (%rsi,%rax,2), %eax
cvtsi2ss %eax, %xmm0
cvtsi2ss %ecx, %xmm1
ucomiss %xmm2, %xmm1
jb 0x5b544
ucomiss %xmm0, %xmm1
jb 0x5b544
movss %xmm2, (%rsp)
jmp 0x5b56b
ucomiss %xmm2, %xmm0
jbe 0x5b55e
divss %xmm0, %xmm2
movss %xmm1, 0x4(%rsp)
mulss %xmm1, %xmm2
movss %xmm2, (%rsp)
jmp 0x5b571
divss %xmm2, %xmm0
mulss %xmm1, %xmm0
movss %xmm1, (%rsp)
movss %xmm0, 0x4(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x48f9a(%rip)     # 0xa4514
setne %al
leal 0x1(,%rax,2), %eax
movl %edx, %edi
xorl %esi, %esi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x657d2
testq %rax, %rax
je 0x5b5c3
movq (%rax), %rcx
xorps %xmm1, %xmm1
cvtsi2ssl 0x10(%rcx), %xmm1
xorps %xmm0, %xmm0
cvtsi2ssl 0x8(%rcx), %xmm0
divss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2ssl 0x14(%rcx), %xmm0
xorps %xmm2, %xmm2
cvtsi2ssl 0xc(%rcx), %xmm2
divss %xmm2, %xmm0
jmp 0x5b5ce
movss 0x1a9c9(%rip), %xmm0    # 0x75f94
movaps %xmm0, %xmm1
leaq 0x3da3db(%rip), %rcx    # 0x4359b0
movb 0x3fc(%rcx), %sil
movb 0x3fd(%rcx), %dl
movb 0x3fe(%rcx), %cl
leaq 0x4819d(%rip), %rdi     # 0xa378c
cmpl $0x0, (%rdi)
jne 0x5b61d
movzbl %sil, %esi
movzbl %dl, %edx
leaq 0x15c402(%rip), %rdi    # 0x1b7a04
movslq (%rdi), %rdi
shlq $0x8, %rdi
addq 0x369c8(%rip), %rdi     # 0x91fd8
movzbl %cl, %ecx
movb (%rsi,%rdi), %sil
movb (%rdx,%rdi), %dl
movb (%rcx,%rdi), %cl
movl $0x1, 0x2c(%rsp)
movl 0x59e41d(%rip), %edi    # 0x5f9a48
movl %edi, 0x8(%rsp)
testq %rax, %rax
je 0x5b642
movq (%rax), %rax
testq %rax, %rax
je 0x5b642
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movzbl %sil, %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
movss 0x1dc5f(%rip), %xmm3    # 0x792b4
divss %xmm3, %xmm2
movzbl %dl, %eax
cvtsi2ss %eax, %xmm4
leaq 0x8(%rsp), %rsi
movss %xmm2, 0x14(%rsi)
divss %xmm3, %xmm4
movss %xmm4, 0x18(%rsi)
movzbl %cl, %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
divss %xmm3, %xmm2
xorps %xmm3, %xmm3
cvtsi2ss %ebp, %xmm3
movss %xmm2, 0x1c(%rsi)
movl $0x3f800000, 0x20(%rsi) # imm = 0x3F800000
leaq 0x50(%rsp), %rax
movss %xmm3, (%rax)
xorps %xmm2, %xmm2
cvtsi2ss %ebx, %xmm2
movss %xmm2, 0x4(%rax)
xorl %r14d, %r14d
movq %r14, 0x8(%rax)
movl %r14d, 0x10(%rax)
movss (%rsp), %xmm4
addss %xmm3, %xmm4
movss %xmm4, 0x14(%rax)
movss %xmm2, 0x18(%rax)
movl %r14d, 0x1c(%rax)
movss %xmm1, 0x20(%rax)
movl %r14d, 0x24(%rax)
movss %xmm4, 0x28(%rax)
movss 0x4(%rsp), %xmm4
addss %xmm2, %xmm4
movss %xmm4, 0x2c(%rax)
movl %r14d, 0x30(%rax)
movss %xmm1, 0x34(%rax)
movss %xmm0, 0x38(%rax)
movss %xmm3, 0x3c(%rax)
movss %xmm4, 0x40(%rax)
movq %r14, 0x44(%rax)
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 0x5b735
movl %r14d, %eax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %rbp
retq