// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: copytilepiece
void copytilepiece(int tilenume1, int sx1, int sy1, int xsiz, int ysiz,
		  int tilenume2, int sx2, int sy2)
{
	unsigned char *ptr1, *ptr2, dat;
	int xsiz1, ysiz1, xsiz2, ysiz2, i, j, x1, y1, x2, y2;

	xsiz1 = tilesizx[tilenume1]; ysiz1 = tilesizy[tilenume1];
	xsiz2 = tilesizx[tilenume2]; ysiz2 = tilesizy[tilenume2];
	if ((xsiz1 > 0) && (ysiz1 > 0) && (xsiz2 > 0) && (ysiz2 > 0))
	{
		if (waloff[tilenume1] == 0) loadtile(tilenume1);
		if (waloff[tilenume2] == 0) loadtile(tilenume2);

		x1 = sx1;
		for(i=0;i<xsiz;i++)
		{
			y1 = sy1;
			for(j=0;j<ysiz;j++)
			{
				x2 = sx2+i;
				y2 = sy2+j;
				if ((x2 >= 0) && (y2 >= 0) && (x2 < xsiz2) && (y2 < ysiz2))
				{
					ptr1 = (unsigned char *)(waloff[tilenume1] + x1*ysiz1 + y1);
					ptr2 = (unsigned char *)(waloff[tilenume2] + x2*ysiz2 + y2);
					dat = *ptr1;
					if (dat != 255)
						*ptr2 = *ptr1;
				}

				y1++; if (y1 >= ysiz1) y1 = 0;
			}
			x1++; if (x1 >= xsiz1) x1 = 0;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %r14d
movl %ecx, %r15d
movl %edx, 0x28(%rsp)
movslq %edi, %r13
leaq 0x3d63d3(%rip), %rax    # 0x409020
movswl (%rax,%r13,2), %ecx
movl %ecx, 0x24(%rsp)
testl %ecx, %ecx
setg %cl
leaq 0x3c7b7e(%rip), %rdx    # 0x3fa7e0
movzwl (%rdx,%r13,2), %r10d
movslq %r9d, %r8
movzwl (%rax,%r8,2), %ebp
movq %r8, 0x30(%rsp)
movzwl (%rdx,%r8,2), %ebx
testw %r10w, %r10w
setg %al
andb %cl, %al
testw %bp, %bp
setg %cl
testw %bx, %bx
setg %dl
andb %cl, %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x32e0f
leaq 0x35f63e(%rip), %r12    # 0x3922e0
cmpq $0x0, (%r12,%r13,8)
jne 0x32ccf
movswl %di, %edi
movl %esi, 0x10(%rsp)
movl %r9d, 0xc(%rsp)
movw %r10w, 0x18(%rsp)
callq 0x2cc4a
movzwl 0x18(%rsp), %r10d
movl 0xc(%rsp), %r9d
movl 0x10(%rsp), %esi
movl 0x88(%rsp), %r8d
movl 0x80(%rsp), %edx
movswl %bx, %edi
movq 0x30(%rsp), %rax
cmpq $0x0, (%r12,%rax,8)
movl %edi, 0x14(%rsp)
jne 0x32d17
movswl %r9w, %edi
movl %esi, %ebx
movl %r10d, %r12d
callq 0x2cc4a
movl 0x88(%rsp), %r8d
movl %r12d, %r10d
movl 0x14(%rsp), %edi
movl 0x80(%rsp), %edx
movl %ebx, %esi
movswl %r10w, %eax
movswl %bp, %ecx
movslq %r8d, %r8
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
movq %r14, 0x40(%rsp)
movslq %edi, %rdi
testl %r15d, %r15d
cmovlel %r12d, %r15d
movl %r15d, 0x2c(%rsp)
movl %edx, %r9d
imull %edi, %r9d
movq %r8, 0x38(%rsp)
addl %r8d, %r9d
xorl %r8d, %r8d
leaq 0x35f588(%rip), %r14    # 0x3922e0
cmpl 0x2c(%rsp), %r8d
je 0x32e0f
movq %r8, 0x18(%rsp)
leal (%r8,%rdx), %r10d
movl %esi, 0x10(%rsp)
movl %esi, %edx
imull %eax, %edx
movslq %edx, %r11
movq 0x38(%rsp), %rdx
movl %r9d, 0xc(%rsp)
movl %r9d, %r8d
movq 0x40(%rsp), %rbp
movl 0x28(%rsp), %ebx
movq 0x30(%rsp), %rsi
subq $0x1, %rbp
jb 0x32de3
testl %r10d, %r10d
js 0x32dd3
testq %rdx, %rdx
js 0x32dd3
cmpl %ecx, %r10d
jge 0x32dd3
cmpq %rdi, %rdx
jge 0x32dd3
movq (%r14,%r13,8), %r15
movslq %ebx, %r9
addq %r11, %r9
movb (%r15,%r9), %r15b
cmpb $-0x1, %r15b
je 0x32dd3
movq (%r14,%rsi,8), %r9
movl %r8d, %r14d
movb %r15b, (%r9,%r14)
leaq 0x35f50d(%rip), %r14    # 0x3922e0
incl %ebx
cmpl %eax, %ebx
cmovgel %r12d, %ebx
incl %r8d
incq %rdx
jmp 0x32d93
movl 0x10(%rsp), %esi
incl %esi
cmpl 0x24(%rsp), %esi
cmovgel %r12d, %esi
movq 0x18(%rsp), %r8
incl %r8d
movl 0xc(%rsp), %r9d
addl 0x14(%rsp), %r9d
movl 0x80(%rsp), %edx
jmp 0x32d58
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq