// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: addquad
static void addquad (int x0, int y0, int z0, int x1, int y1, int z1, int x2, int y2, int z2, int face)
{
	int i, j, x, y, z, xx, yy, nx = 0, ny = 0, nz = 0, *lptr;
	voxrect_t *qptr;

	x = abs(x2-x0); y = abs(y2-y0); z = abs(z2-z0);
	if (!x) { x = y; y = z; i = 0; } else if (!y) { y = z; i = 1; } else i = 2;
	if (x < y) { z = x; x = y; y = z; i += 3; }
	z = shcnt[y*shcntp+x]++;
	lptr = &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+(shp[z].x+VOXBORDWIDTH)];
	switch(face)
	{
		case 0: ny = y1; x2 = x0; x0 = x1; x1 = x2; break;
		case 1: ny = y0; y0++; y1++; y2++; break;
		case 2: nz = z1; y0 = y2; y2 = y1; y1 = y0; z0++; z1++; z2++; break;
		case 3: nz = z0; break;
		case 4: nx = x1; y2 = y0; y0 = y1; y1 = y2; x0++; x1++; x2++; break;
		case 5: nx = x0; break;
	}
	for(yy=0;yy<y;yy++,lptr+=gvox->mytexx)
		for(xx=0;xx<x;xx++)
		{
			switch(face)
			{
				case 0: if (i < 3) { nx = x1+x-1-xx; nz = z1+yy;   } //back
								  else { nx = x1+y-1-yy; nz = z1+xx;   } break;
				case 1: if (i < 3) { nx = x0+xx;     nz = z0+yy;   } //front
								  else { nx = x0+yy;     nz = z0+xx;   } break;
				case 2: if (i < 3) { nx = x1-x+xx;   ny = y1-1-yy; } //bot
								  else { nx = x1-1-yy;   ny = y1-1-xx; } break;
				case 3: if (i < 3) { nx = x0+xx;     ny = y0+yy;   } //top
								  else { nx = x0+yy;     ny = y0+xx;   } break;
				case 4: if (i < 3) { ny = y1+x-1-xx; nz = z1+yy;   } //right
								  else { ny = y1+y-1-yy; nz = z1+xx;   } break;
				case 5: if (i < 3) { ny = y0+xx;     nz = z0+yy;   } //left
								  else { ny = y0+yy;     nz = z0+xx;   } break;
			}
			lptr[xx] = getvox(nx,ny,nz);
		}

		//Extend borders horizontally
	for(yy=VOXBORDWIDTH;yy<y+VOXBORDWIDTH;yy++)
		for(xx=0;xx<VOXBORDWIDTH;xx++)
		{
			lptr = &gvox->mytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x];
			lptr[xx] = lptr[VOXBORDWIDTH]; lptr[xx+x+VOXBORDWIDTH] = lptr[x-1+VOXBORDWIDTH];
		}
		//Extend borders vertically
	for(yy=0;yy<VOXBORDWIDTH;yy++)
	{
		memcpy(&gvox->mytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x],
				 &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+shp[z].x],
				 (x+(VOXBORDWIDTH<<1))<<2);
		memcpy(&gvox->mytex[(shp[z].y+y+yy+VOXBORDWIDTH)*gvox->mytexx+shp[z].x],
				 &gvox->mytex[(shp[z].y+y-1+VOXBORDWIDTH)*gvox->mytexx+shp[z].x],
				 (x+(VOXBORDWIDTH<<1))<<2);
	}

	qptr = &gvox->quad[gvox->qcnt];
	qptr->v[0].x = x0; qptr->v[0].y = y0; qptr->v[0].z = z0;
	qptr->v[1].x = x1; qptr->v[1].y = y1; qptr->v[1].z = z1;
	qptr->v[2].x = x2; qptr->v[2].y = y2; qptr->v[2].z = z2;
	for(j=0;j<3;j++) { qptr->v[j].u = shp[z].x+VOXBORDWIDTH; qptr->v[j].v = shp[z].y+VOXBORDWIDTH; }
	if (i < 3) qptr->v[1].u += x; else qptr->v[1].v += y;
	qptr->v[2].u += x; qptr->v[2].v += y;

	qptr->v[3].u = qptr->v[0].u - qptr->v[1].u + qptr->v[2].u;
	qptr->v[3].v = qptr->v[0].v - qptr->v[1].v + qptr->v[2].v;
	qptr->v[3].x = qptr->v[0].x - qptr->v[1].x + qptr->v[2].x;
	qptr->v[3].y = qptr->v[0].y - qptr->v[1].y + qptr->v[2].y;
	qptr->v[3].z = qptr->v[0].z - qptr->v[1].z + qptr->v[2].z;
	if (gvox->qfacind[face] < 0) gvox->qfacind[face] = gvox->qcnt;
	gvox->qcnt++;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl 0xf8(%rsp), %r14d
movl %r14d, %eax
subl %esi, %eax
movl %eax, %r11d
negl %r11d
cmovsl %eax, %r11d
movl 0x100(%rsp), %ebx
movl %ebx, %eax
movq %rdx, 0x30(%rsp)
subl %edx, %eax
movl %eax, %r10d
negl %r10d
cmovsl %eax, %r10d
movq %r14, 0x28(%rsp)
cmpl %esi, %r14d
movl 0xf0(%rsp), %ebp
movl %r11d, %edx
cmovel %r10d, %edx
movl %ebp, %eax
subl %edi, %eax
cmovel %r10d, %edx
movl %eax, %r14d
negl %r14d
cmovsl %eax, %r14d
cmpl %edi, %ebp
cmovel %r11d, %r14d
cmpl %edx, %r14d
movl %edx, %r12d
cmoval %r14d, %r12d
movq %rcx, 0x8(%rsp)
movl %edx, 0x1c(%rsp)
cmovbl %r14d, %edx
movq 0x65230e(%rip), %rax    # 0x6ad0c0
movl 0x652300(%rip), %ecx    # 0x6ad0b8
movq %rdx, 0x58(%rsp)
imull %edx, %ecx
addl %r12d, %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %r10
leal 0x1(%r10), %edx
movl %edx, (%rax,%rcx,4)
movq 0x652390(%rip), %rdx    # 0x6ad168
movswq 0x2(%rdx,%r10,4), %rax
incq %rax
movq 0x6522c8(%rip), %r11    # 0x6ad0b0
movslq 0x50(%r11), %rcx
imulq %rax, %rcx
movq %r10, 0x50(%rsp)
movq %rdx, 0x38(%rsp)
movswq (%rdx,%r10,4), %rax
addq %rcx, %rax
movl 0x108(%rsp), %r15d
movq 0x48(%r11), %rcx
cmpq $0x5, %r15
movq %r11, 0x90(%rsp)
movq %r12, 0x80(%rsp)
ja 0x5af6f
leaq 0x153c1(%rip), %rdx     # 0x701f0
movslq (%rdx,%r15,4), %r10
addq %rdx, %r10
jmpq *%r10
movl %ebx, 0x18(%rsp)
movl %edi, %r11d
movl %r8d, %ebx
movq %r9, 0x20(%rsp)
movl %edi, 0x14(%rsp)
movl 0xf8(%rsp), %edx
movl %edx, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
xorl %edx, %edx
xorl %r9d, %r9d
jmp 0x5afa6
movl %ebx, 0x18(%rsp)
incl %edi
movq 0x8(%rsp), %r10
leal 0x1(%r10), %r11d
incl %ebp
movl %ebp, 0x14(%rsp)
movl %esi, %ebx
movq %r9, 0x20(%rsp)
movl %esi, 0x10(%rsp)
movl %r8d, %edx
movq %rdx, 0x28(%rsp)
movl %r10d, %edx
jmp 0x5af99
movl %ebp, 0x14(%rsp)
movq 0x30(%rsp), %rdx
incl %edx
movq %rdx, 0x30(%rsp)
leal 0x1(%r9), %edx
movq %rdx, 0x20(%rsp)
incl %ebx
movl %ebx, 0x18(%rsp)
movq 0x8(%rsp), %rdx
movl %edx, %r11d
movl 0xf8(%rsp), %edx
movl %edx, %ebx
movl %r8d, 0x10(%rsp)
xorl %edx, %edx
xorl %r8d, %r8d
jmp 0x5af9f
movl %ebp, 0x14(%rsp)
movl %ebx, 0x18(%rsp)
movq 0x8(%rsp), %rdx
movl %edx, %r11d
movl %r8d, %ebx
movq %r9, 0x20(%rsp)
movl 0xf8(%rsp), %edx
movl %edx, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
xorl %edx, %edx
xorl %r8d, %r8d
movq 0x30(%rsp), %r9
jmp 0x5af9f
movl %ebp, 0x14(%rsp)
movl %ebx, 0x18(%rsp)
leal 0x1(%rsi), %edx
incl %r8d
movl 0xf8(%rsp), %r10d
incl %r10d
movq 0x8(%rsp), %r11
movl %r8d, %ebx
movq %r9, 0x20(%rsp)
movl %r10d, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
xorl %edx, %edx
movl %esi, %r8d
jmp 0x5af9c
movl %ebp, 0x14(%rsp)
movl %ebx, 0x18(%rsp)
movq 0x8(%rsp), %rdx
movl %edx, %r11d
movl %r8d, %ebx
movq %r9, 0x20(%rsp)
movl 0xf8(%rsp), %edx
movl %edx, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
movl %edi, %edx
jmp 0x5af99
movl %ebp, 0x14(%rsp)
movl %ebx, 0x18(%rsp)
movq 0x8(%rsp), %rdx
movl %edx, %r11d
movl %r8d, %ebx
movq %r9, 0x20(%rsp)
movl 0xf8(%rsp), %edx
movl %edx, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
movl %edi, %esi
movq %rsi, 0x8(%rsp)
leaq (%rcx,%rax,4), %rsi
addq $0x4, %rsi
movq %rbx, 0x68(%rsp)
leal (%rbx,%r14), %eax
movq %rax, 0x98(%rsp)
movl %r11d, %eax
subl %r14d, %eax
movq %rax, 0xa8(%rsp)
movq %r14, %r13
leal (%r11,%r14), %eax
movl %eax, 0x40(%rsp)
movl 0x6520ce(%rip), %eax    # 0x6ad0ac
movq 0x6520b3(%rip), %r12    # 0x6ad098
movslq 0x6520bc(%rip), %rbx    # 0x6ad0a8
movq 0x65209d(%rip), %r14    # 0x6ad090
movl 0x80(%rsp), %ecx
leaq 0x15207(%rip), %rdi     # 0x70208
movq 0x38(%rsp), %r10
movq %r11, 0x88(%rsp)
xorl %ebp, %ebp
cmpl 0x58(%rsp), %ebp
je 0x5b22e
movq 0x30(%rsp), %r10
addl %ebp, %r10d
movl %r10d, 0x60(%rsp)
movq 0x28(%rsp), %r10
leal (%rbp,%r10), %r10d
movl %r10d, 0x4c(%rsp)
movq 0x20(%rsp), %r10
leal (%rbp,%r10), %r10d
movl %r10d, 0x48(%rsp)
movl %ebp, %r11d
notl %r11d
movq 0x98(%rsp), %r10
leal (%r10,%r11), %r10d
movl %r10d, 0x7c(%rsp)
movq 0x8(%rsp), %r10
movq %rbp, 0xa0(%rsp)
addl %ebp, %r10d
movl %r10d, 0x44(%rsp)
movq 0x68(%rsp), %r10
addl %r11d, %r10d
movl %r10d, 0x78(%rsp)
movq 0x88(%rsp), %r10
addl %r11d, %r10d
movl %r10d, 0x74(%rsp)
addl 0x40(%rsp), %r11d
movq %r11, 0xb0(%rsp)
xorl %r11d, %r11d
cmpq %rcx, %r11
je 0x5b20a
cmpl $0x5, %r15d
ja 0x5b1a5
movl %r15d, %r10d
movslq (%rdi,%r10,4), %r15
addq %rdi, %r15
movl %r11d, %r10d
notl %r10d
jmpq *%r15
cmpl 0x1c(%rsp), %r13d
jae 0x5b17f
movq 0x20(%rsp), %rdx
leal (%rdx,%r11), %r9d
movq 0xb0(%rsp), %rdx
jmp 0x5b1a5
cmpl 0x1c(%rsp), %r13d
jae 0x5b151
movq 0x20(%rsp), %r8
leal (%r8,%r11), %r9d
movl 0x7c(%rsp), %r8d
jmp 0x5b1a5
cmpl 0x1c(%rsp), %r13d
jae 0x5b15e
addl 0x68(%rsp), %r10d
movl 0x74(%rsp), %edx
movl %r10d, %r8d
jmp 0x5b1a5
cmpl 0x1c(%rsp), %r13d
jae 0x5b170
movq 0x28(%rsp), %rdx
leal (%rdx,%r11), %r8d
jmp 0x5b139
cmpl 0x1c(%rsp), %r13d
jae 0x5b18e
movq 0x30(%rsp), %rdx
leal (%rdx,%r11), %r9d
movl 0x44(%rsp), %edx
jmp 0x5b1a5
cmpl 0x1c(%rsp), %r13d
jae 0x5b198
movq 0x30(%rsp), %r8
leal (%r8,%r11), %r9d
jmp 0x5b178
addl 0x98(%rsp), %r10d
movl %r10d, %r8d
jmp 0x5b187
movq 0xa8(%rsp), %rdx
addl %r11d, %edx
movl 0x78(%rsp), %r8d
jmp 0x5b1a5
movq 0x8(%rsp), %rdx
addl %r11d, %edx
movl 0x4c(%rsp), %r8d
jmp 0x5b1a5
addl 0x40(%rsp), %r10d
movl %r10d, %edx
movl 0x48(%rsp), %r9d
jmp 0x5b1a5
movq 0x8(%rsp), %rdx
addl %r11d, %edx
jmp 0x5b1a0
movq 0x28(%rsp), %r8
addl %r11d, %r8d
movl 0x60(%rsp), %r9d
movl %eax, %r10d
imull %edx, %r10d
movl 0x651ebd(%rip), %r15d   # 0x6ad070
imull %r8d, %r15d
addl %r9d, %r10d
addl %r15d, %r10d
movslq %r10d, %r15
imulq $0x343fd, %r15, %r15    # imm = 0x343FD
andq %rbx, %r15
leaq (%r12,%r15,4), %r15
movslq (%r15), %r15
testq %r15, %r15
js 0x5b1ea
imulq $0xc, %r15, %rbp
leaq (%r14,%rbp), %r15
cmpl %r10d, (%r14,%rbp)
je 0x5b1f2
addq $0x8, %r15
jmp 0x5b1ce
movl $0x808080, %r10d        # imm = 0x808080
jmp 0x5b1f6
movl 0x4(%r15), %r10d
movl %r10d, (%rsi,%r11,4)
incq %r11
movl 0x108(%rsp), %r15d
jmp 0x5b09e
movq 0xa0(%rsp), %rbp
incl %ebp
movq 0x90(%rsp), %r10
movslq 0x50(%r10), %r10
leaq (%rsi,%r10,4), %rsi
movq 0x38(%rsp), %r10
jmp 0x5b010
movq 0x58(%rsp), %rax
negl %eax
pushq $0x1
popq %rdx
movl 0x18(%rsp), %ebp
movl 0x14(%rsp), %ebx
movq 0x90(%rsp), %r14
movq 0x80(%rsp), %r12
movq 0x50(%rsp), %r9
leal (%rax,%rdx), %edi
movq 0x48(%r14), %rsi
movswl 0x2(%r10,%r9,4), %r8d
cmpl $0x1, %edi
je 0x5b291
addl %edx, %r8d
movslq 0x50(%r14), %rdi
movslq %r8d, %r8
imulq %rdi, %r8
movswq (%r10,%r9,4), %rdi
addq %r8, %rdi
leaq (%rsi,%rdi,4), %rsi
movl 0x4(%rsi), %edi
movl %edi, (%rsi)
movl (%rsi,%rcx,4), %edi
movl %edi, 0x4(%rsi,%rcx,4)
incl %edx
jmp 0x5b255
movl 0x50(%r14), %eax
movl %eax, %ecx
imull %r8d, %ecx
movswl (%r10,%r9,4), %edx
addl %edx, %ecx
movslq %ecx, %rcx
leaq (%rsi,%rcx,4), %rdi
incl %r8d
imull %eax, %r8d
addl %edx, %r8d
movslq %r8d, %rax
leaq (%rsi,%rax,4), %rsi
leal 0x8(,%r12,4), %eax
movslq %eax, %rdx
movq %r13, 0x60(%rsp)
movl %ebx, %r13d
movq %rdx, %rbx
callq 0x60c0
movq 0x48(%r14), %rax
movq 0x50(%rsp), %rcx
movq 0x38(%rsp), %rdx
movswl 0x2(%rdx,%rcx,4), %ecx
movq 0x58(%rsp), %rsi
leal (%rsi,%rcx), %edx
addl %esi, %ecx
incl %ecx
movl 0x50(%r14), %esi
imull %esi, %ecx
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %r8
movswl (%r8,%rdi,4), %r8d
addl %r8d, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdi
imull %esi, %edx
addl %r8d, %edx
movslq %edx, %rcx
leaq (%rax,%rcx,4), %rsi
movq %rbx, %rdx
movl %ebp, %ebx
movl %r13d, %ebp
movq 0x60(%rsp), %r13
callq 0x60c0
movq 0x88(%rsp), %r9
movq 0x38(%rsp), %r8
movq 0x50(%rsp), %rdi
movq 0x20(%r14), %rcx
movslq 0x28(%r14), %rax
imulq $0x28, %rax, %rdx
leaq (%rcx,%rdx), %rax
addq %rdx, %rcx
addq $0x8, %rcx
movq 0x8(%rsp), %rdx
movw %dx, -0x8(%rcx)
movq 0x28(%rsp), %rdx
movw %dx, -0x6(%rcx)
movq 0x30(%rsp), %rdx
movw %dx, -0x4(%rcx)
movw %r9w, 0x2(%rcx)
movq 0x68(%rsp), %r10
movw %r10w, 0x4(%rcx)
movq 0x20(%rsp), %rdx
movw %dx, 0x6(%rcx)
movw %bp, 0xc(%rcx)
movl 0x10(%rsp), %r11d
movw %r11w, 0xe(%rcx)
movw %bx, 0x10(%rcx)
xorl %edx, %edx
cmpq $0x1e, %rdx
je 0x5b3c7
movzwl (%r8,%rdi,4), %esi
incl %esi
movw %si, -0x2(%rcx,%rdx)
movzwl 0x2(%r8,%rdi,4), %esi
incl %esi
movw %si, (%rcx,%rdx)
addq $0xa, %rdx
jmp 0x5b3a3
cmpl 0x1c(%rsp), %r13d
jae 0x5b3e4
addw 0x12(%rax), %r13w
movw %r13w, 0x12(%rax)
movl %r13d, %ecx
movzwl 0x10(%rax), %edx
movl %edx, %r13d
jmp 0x5b3f2
addw 0x10(%rax), %r13w
movw %r13w, 0x10(%rax)
movzwl 0x12(%rax), %ecx
addw 0x1a(%rax), %r12w
movw %r12w, 0x1a(%rax)
movq 0x58(%rsp), %rdx
addw 0x1c(%rax), %dx
movw %dx, 0x1c(%rax)
addw 0x6(%rax), %r12w
subl %r13d, %r12d
movw %r12w, 0x24(%rax)
addw 0x8(%rax), %dx
subl %ecx, %edx
movw %dx, 0x26(%rax)
movq 0x8(%rsp), %rcx
subl %r9d, %ecx
addl %ecx, %ebp
movw %bp, 0x1e(%rax)
movq 0x28(%rsp), %rcx
subl %r10d, %ecx
addl %ecx, %r11d
movw %r11w, 0x20(%rax)
movq 0x30(%rsp), %rcx
subl 0x20(%rsp), %ecx
addl %ecx, %ebx
movw %bx, 0x22(%rax)
movslq %r15d, %rcx
cmpl $0x0, 0x2c(%r14,%rcx,4)
movl 0x28(%r14), %eax
jns 0x5b461
movl %eax, 0x2c(%r14,%rcx,4)
incl %eax
movl %eax, 0x28(%r14)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq