// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: rotatesprite
void rotatesprite(int sx, int sy, int z, short a, short picnum, signed char dashade,
	unsigned char dapalnum, unsigned char dastat, int cx1, int cy1, int cx2, int cy2)
{
	int i, gap = -1;
	permfifotype *per, *per2;

	if ((cx1 > cx2) || (cy1 > cy2)) return;
	if (z <= 16) return;
	if (picanm[picnum]&192) picnum += animateoffs(picnum,(short)0xc000);
	if ((tilesizx[picnum] <= 0) || (tilesizy[picnum] <= 0)) return;

	if (((dastat&128) == 0) || (numpages < 2) || (beforedrawrooms != 0)) {
		dorotatesprite(sx,sy,z,a,picnum,dashade,dapalnum,dastat,cx1,cy1,cx2,cy2,guniqhudid);
	}

	if ((dastat&64) && (cx1 <= 0) && (cy1 <= 0) && (cx2 >= xdim-1) && (cy2 >= ydim-1) &&
		 (sx == (160<<16)) && (sy == (100<<16)) && (z == 65536L) && (a == 0) && ((dastat&1) == 0))
		permhead = permtail = 0;

	if ((dastat&128) == 0) return;
	if (numpages >= 2)
	{
		if (((permhead+1)&(MAXPERMS-1)) == permtail)
		{
			for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
			{
				if ((permfifo[i].pagesleft&127) == 0)
					{ if (gap < 0) gap = i; }
				else if (gap >= 0)
				{
					copybufbyte(&permfifo[i], &permfifo[gap], sizeof(permfifotype));
					permfifo[i].pagesleft = 0;
					for (;gap!=i;gap=((gap+1)&(MAXPERMS-1)))
						if ((permfifo[gap].pagesleft&127) == 0)
							break;
					if (gap==i) gap = -1;
				}
			}
			if (gap >= 0) permhead = gap;
			else permtail = ((permtail+1)&(MAXPERMS-1));
		}
		per = &permfifo[permhead];
		per->sx = sx; per->sy = sy; per->z = z; per->a = a;
		per->picnum = picnum;
		per->dashade = dashade; per->dapalnum = dapalnum;
		per->dastat = dastat;
		per->pagesleft = numpages+((beforedrawrooms&1)<<7);
		per->cx1 = cx1; per->cy1 = cy1; per->cx2 = cx2; per->cy2 = cy2;
		per->uniqid = guniqhudid;	//JF extension

			//Would be better to optimize out true bounding boxes
		if (dastat&64)  //If non-masking write, checking for overlapping cases
		{
			for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
			{
				per2 = &permfifo[i];
				if ((per2->pagesleft&127) == 0) continue;
				if (per2->sx != per->sx) continue;
				if (per2->sy != per->sy) continue;
				if (per2->z != per->z) continue;
				if (per2->a != per->a) continue;
				if (tilesizx[per2->picnum] > tilesizx[per->picnum]) continue;
				if (tilesizy[per2->picnum] > tilesizy[per->picnum]) continue;
				if (per2->cx1 < per->cx1) continue;
				if (per2->cy1 < per->cy1) continue;
				if (per2->cx2 > per->cx2) continue;
				if (per2->cy2 > per->cy2) continue;
				per2->pagesleft = 0;
			}
			if (per->a == 0)
				for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
				{
					per2 = &permfifo[i];
					if ((per2->pagesleft&127) == 0) continue;
					if (per2->z != per->z) continue;
					if (per2->a != 0) continue;
					if (per2->cx1 < per->cx1) continue;
					if (per2->cy1 < per->cy1) continue;
					if (per2->cx2 > per->cx2) continue;
					if (per2->cy2 > per->cy2) continue;
					if ((per2->sx>>16) < (per->sx>>16)) continue;
					if ((per2->sy>>16) < (per->sy>>16)) continue;
					if (per2->sx+(tilesizx[per2->picnum]*per2->z) > per->sx+(tilesizx[per->picnum]*per->z)) continue;
					if (per2->sy+(tilesizy[per2->picnum]*per2->z) > per->sy+(tilesizy[per->picnum]*per->z)) continue;
					per2->pagesleft = 0;
				}
		}

		permhead = ((permhead+1)&(MAXPERMS-1));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movl %r8d, -0x60(%rbp)
movl %ecx, %eax
movl -0x60(%rbp), %ecx
movl %eax, -0x5c(%rbp)
movl %edx, %eax
movl -0x5c(%rbp), %edx
movl %eax, -0x58(%rbp)
movl %esi, %eax
movl -0x58(%rbp), %esi
movl %eax, -0x54(%rbp)
movl %edi, %r8d
movl -0x54(%rbp), %edi
movb %r9b, %al
movl 0x38(%rbp), %r9d
movl 0x30(%rbp), %r9d
movl 0x28(%rbp), %r9d
movl 0x20(%rbp), %r9d
movb 0x18(%rbp), %r9b
movb 0x10(%rbp), %r9b
movl %r8d, -0x24(%rbp)
movl %edi, -0x28(%rbp)
movl %esi, -0x2c(%rbp)
movw %dx, -0x2e(%rbp)
movw %cx, -0x30(%rbp)
movb %al, -0x31(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movl 0x20(%rbp), %eax
cmpl 0x30(%rbp), %eax
jg 0x56f7b
movl 0x28(%rbp), %eax
cmpl 0x38(%rbp), %eax
jle 0x56f80
jmp 0x5764d
cmpl $0x10, -0x2c(%rbp)
jg 0x56f8b
jmp 0x5764d
movswq -0x30(%rbp), %rcx
leaq 0x220629(%rip), %rax    # 0x2775c0
movl (%rax,%rcx,4), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
je 0x56fbe
movl $0xffffc000, %esi       # imm = 0xFFFFC000
movswl -0x30(%rbp), %edi
callq 0x361e0
movl %eax, %ecx
movswl -0x30(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x30(%rbp)
movswq -0x30(%rbp), %rcx
leaq 0x3f3db6(%rip), %rax    # 0x44ad80
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jle 0x56fe8
movswq -0x30(%rbp), %rcx
leaq 0x3e5561(%rip), %rax    # 0x43c540
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jg 0x56fed
jmp 0x5764d
movzbl 0x18(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x5700d
cmpl $0x2, 0x4066be(%rip)    # 0x45d6c0
jl 0x5700d
cmpl $0x0, 0x89c6d(%rip)     # 0xe0c78
je 0x57078
movl -0x24(%rbp), %edi
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
movw -0x2e(%rbp), %cx
movw -0x30(%rbp), %r8w
movb -0x31(%rbp), %r9b
movb 0x10(%rbp), %r12b
movb 0x18(%rbp), %r15b
movl 0x20(%rbp), %r14d
movl 0x28(%rbp), %ebx
movl 0x30(%rbp), %r11d
movl 0x38(%rbp), %r10d
movl 0x3fa98c(%rip), %eax    # 0x4519cc
movswl %cx, %ecx
movswl %r8w, %r8d
movsbl %r9b, %r9d
movzbl %r12b, %r12d
movl %r12d, (%rsp)
movzbl %r15b, %r15d
movl %r15d, 0x8(%rsp)
movl %r14d, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movl %r11d, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl %eax, 0x30(%rsp)
callq 0x4d1f0
movzbl 0x18(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x570f7
cmpl $0x0, 0x20(%rbp)
jg 0x570f7
cmpl $0x0, 0x28(%rbp)
jg 0x570f7
movl 0x30(%rbp), %eax
movl 0x3ebcb3(%rip), %ecx    # 0x442d4c
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x570f7
movl 0x38(%rbp), %eax
movl 0x3ebca7(%rip), %ecx    # 0x442d50
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x570f7
cmpl $0xa00000, -0x24(%rbp)  # imm = 0xA00000
jne 0x570f7
cmpl $0x640000, -0x28(%rbp)  # imm = 0x640000
jne 0x570f7
movslq -0x2c(%rbp), %rax
cmpq $0x10000, %rax          # imm = 0x10000
jne 0x570f7
movswl -0x2e(%rbp), %eax
cmpl $0x0, %eax
jne 0x570f7
movzbl 0x18(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x570f7
movl $0x0, 0x3fc5bf(%rip)    # 0x4536ac
movl $0x0, 0x3fc5b9(%rip)    # 0x4536b0
movzbl 0x18(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x5710a
jmp 0x5764d
cmpl $0x2, 0x4065af(%rip)    # 0x45d6c0
jl 0x5764d
movl 0x3fc593(%rip), %eax    # 0x4536b0
addl $0x1, %eax
andl $0x3ff, %eax            # imm = 0x3FF
cmpl 0x3fc581(%rip), %eax    # 0x4536ac
jne 0x5724f
movl 0x3fc575(%rip), %eax    # 0x4536ac
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x3fc56d(%rip), %eax    # 0x4536b0
je 0x57228
movslq -0x38(%rbp), %rcx
leaq 0x3fc56c(%rip), %rax    # 0x4536c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movzbl 0x13(%rax), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x57178
cmpl $0x0, -0x3c(%rbp)
jge 0x57173
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x57213
cmpl $0x0, -0x3c(%rbp)
jl 0x57211
movslq -0x38(%rbp), %rax
leaq 0x3fc533(%rip), %rdi    # 0x4536c0
imulq $0x28, %rax, %rax
addq %rax, %rdi
movslq -0x3c(%rbp), %rax
leaq 0x3fc521(%rip), %rsi    # 0x4536c0
imulq $0x28, %rax, %rax
addq %rax, %rsi
movl $0x28, %edx
callq 0x6ef00
movslq -0x38(%rbp), %rcx
leaq 0x3fc505(%rip), %rax    # 0x4536c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x13(%rax)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x57200
movslq -0x3c(%rbp), %rcx
leaq 0x3fc4e7(%rip), %rax    # 0x4536c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movzbl 0x13(%rax), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x571ee
jmp 0x57200
jmp 0x571f0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x3c(%rbp)
jmp 0x571c6
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x5720f
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
jmp 0x57211
jmp 0x57213
jmp 0x57215
movl -0x38(%rbp), %eax
addl $0x1, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x38(%rbp)
jmp 0x5713a
cmpl $0x0, -0x3c(%rbp)
jl 0x57239
movl -0x3c(%rbp), %eax
movl %eax, 0x3fc479(%rip)    # 0x4536b0
jmp 0x5724d
movl 0x3fc46d(%rip), %eax    # 0x4536ac
addl $0x1, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, 0x3fc45f(%rip)    # 0x4536ac
jmp 0x5724f
movslq 0x3fc45a(%rip), %rcx    # 0x4536b0
leaq 0x3fc463(%rip), %rax    # 0x4536c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x24(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x2c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x8(%rax)
movw -0x2e(%rbp), %cx
movq -0x48(%rbp), %rax
movw %cx, 0xc(%rax)
movw -0x30(%rbp), %cx
movq -0x48(%rbp), %rax
movw %cx, 0xe(%rax)
movb -0x31(%rbp), %cl
movq -0x48(%rbp), %rax
movb %cl, 0x10(%rax)
movb 0x10(%rbp), %cl
movq -0x48(%rbp), %rax
movb %cl, 0x11(%rax)
movb 0x18(%rbp), %cl
movq -0x48(%rbp), %rax
movb %cl, 0x12(%rax)
movl 0x4063ff(%rip), %eax    # 0x45d6c0
movl 0x899b1(%rip), %ecx     # 0xe0c78
andl $0x1, %ecx
shll $0x7, %ecx
addl %ecx, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x13(%rax)
movl 0x20(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x14(%rax)
movl 0x28(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x18(%rax)
movl 0x30(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl 0x38(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x20(%rax)
movl 0x3fa6c6(%rip), %ecx    # 0x4519cc
movq -0x48(%rbp), %rax
movl %ecx, 0x24(%rax)
movzbl 0x18(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x57639
movl 0x3fc389(%rip), %eax    # 0x4536ac
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x3fc381(%rip), %eax    # 0x4536b0
je 0x57475
movslq -0x38(%rbp), %rcx
leaq 0x3fc380(%rip), %rax    # 0x4536c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movzbl 0x13(%rax), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x57360
jmp 0x57462
movq -0x50(%rbp), %rax
movl (%rax), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
je 0x57373
jmp 0x57462
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x57388
jmp 0x57462
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x5739d
jmp 0x57462
movq -0x50(%rbp), %rax
movswl 0xc(%rax), %eax
movq -0x48(%rbp), %rcx
movswl 0xc(%rcx), %ecx
cmpl %ecx, %eax
je 0x573b6
jmp 0x57462
movq -0x50(%rbp), %rax
movswq 0xe(%rax), %rcx
leaq 0x3f39ba(%rip), %rax    # 0x44ad80
movswl (%rax,%rcx,2), %eax
movq -0x48(%rbp), %rcx
movswq 0xe(%rcx), %rdx
leaq 0x3f39a6(%rip), %rcx    # 0x44ad80
movswl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jle 0x573e4
jmp 0x57462
movq -0x50(%rbp), %rax
movswq 0xe(%rax), %rcx
leaq 0x3e514c(%rip), %rax    # 0x43c540
movswl (%rax,%rcx,2), %eax
movq -0x48(%rbp), %rcx
movswq 0xe(%rcx), %rdx
leaq 0x3e5138(%rip), %rcx    # 0x43c540
movswl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jle 0x57412
jmp 0x57462
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x57424
jmp 0x57462
movq -0x50(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x57436
jmp 0x57462
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jle 0x57448
jmp 0x57462
movq -0x50(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jle 0x5745a
jmp 0x57462
movq -0x50(%rbp), %rax
movb $0x0, 0x13(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x38(%rbp)
jmp 0x57326
movq -0x48(%rbp), %rax
movswl 0xc(%rax), %eax
cmpl $0x0, %eax
jne 0x57637
movl 0x3fc220(%rip), %eax    # 0x4536ac
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x3fc218(%rip), %eax    # 0x4536b0
je 0x57635
movslq -0x38(%rbp), %rcx
leaq 0x3fc217(%rip), %rax    # 0x4536c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movzbl 0x13(%rax), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x574c9
jmp 0x57622
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x574de
jmp 0x57622
movq -0x50(%rbp), %rax
movswl 0xc(%rax), %eax
cmpl $0x0, %eax
je 0x574f0
jmp 0x57622
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x57505
jmp 0x57622
movq -0x50(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x5751a
jmp 0x57622
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jle 0x5752f
jmp 0x57622
movq -0x50(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jle 0x57544
jmp 0x57622
movq -0x50(%rbp), %rax
movl (%rax), %eax
sarl $0x10, %eax
movq -0x48(%rbp), %rcx
movl (%rcx), %ecx
sarl $0x10, %ecx
cmpl %ecx, %eax
jge 0x5755f
jmp 0x57622
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
sarl $0x10, %eax
movq -0x48(%rbp), %rcx
movl 0x4(%rcx), %ecx
sarl $0x10, %ecx
cmpl %ecx, %eax
jge 0x5757c
jmp 0x57622
movq -0x50(%rbp), %rax
movl (%rax), %eax
movq -0x50(%rbp), %rcx
movswq 0xe(%rcx), %rdx
leaq 0x3f37ee(%rip), %rcx    # 0x44ad80
movswl (%rcx,%rdx,2), %ecx
movq -0x50(%rbp), %rdx
imull 0x8(%rdx), %ecx
addl %ecx, %eax
movq -0x48(%rbp), %rcx
movl (%rcx), %ecx
movq -0x48(%rbp), %rdx
movswq 0xe(%rdx), %rsi
leaq 0x3f37ca(%rip), %rdx    # 0x44ad80
movswl (%rdx,%rsi,2), %edx
movq -0x48(%rbp), %rsi
imull 0x8(%rsi), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x575ca
jmp 0x57622
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x50(%rbp), %rcx
movswq 0xe(%rcx), %rdx
leaq 0x3e4f5f(%rip), %rcx    # 0x43c540
movswl (%rcx,%rdx,2), %ecx
movq -0x50(%rbp), %rdx
imull 0x8(%rdx), %ecx
addl %ecx, %eax
movq -0x48(%rbp), %rcx
movl 0x4(%rcx), %ecx
movq -0x48(%rbp), %rdx
movswq 0xe(%rdx), %rsi
leaq 0x3e4f3a(%rip), %rdx    # 0x43c540
movswl (%rdx,%rsi,2), %edx
movq -0x48(%rbp), %rsi
imull 0x8(%rsi), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x5761a
jmp 0x57622
movq -0x50(%rbp), %rax
movb $0x0, 0x13(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x38(%rbp)
jmp 0x5748f
jmp 0x57637
jmp 0x57639
movl 0x3fc071(%rip), %eax    # 0x4536b0
addl $0x1, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, 0x3fc063(%rip)    # 0x4536b0
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)