// File: /workspace/github_cpp_makefile_star2_O1/Alcaro[P]bridges/arlib/image.cpp
// Function: image::insert_rectangle(int, int, unsigned int, unsigned int, unsigned int)
void image::insert_rectangle(int32_t x, int32_t y, uint32_t width, uint32_t height, uint32_t argb)
{
	if (x<0) { if (width  < (uint32_t)-x) return; width  -= -x; x=0; }
	if (y<0) { if (height < (uint32_t)-y) return; height -= -y; y=0; }
	if (x+width  >= this->width)  { if ((uint32_t)x >= this->width)  return; width  = this->width  - x; }
	if (y+height >= this->height) { if ((uint32_t)y >= this->height) return; height = this->height - y; }
	
	if (argb >= 0xFF000000)
	{
		if (!height) return;
		
		if (fmt == ifmt_0rgb8888) argb &= 0x00FFFFFF;
		uint32_t* targetpx = this->pixels32 + y*this->stride/sizeof(uint32_t) + x;
		for (uint32_t xx=0;xx<width;xx++)
		{
			targetpx[xx] = argb;
		}
		for (uint32_t yy=1;yy<height;yy++)
		{
			memcpy(targetpx + yy*this->stride/sizeof(uint32_t), targetpx, width*sizeof(uint32_t));
		}
	}
	else
	{
		for (uint32_t yy=0;yy<height;yy++)
		{
			uint32_t* targetpx = this->pixels32 + (y+yy)*this->stride/sizeof(uint32_t) + x;
			for (uint32_t xx=0;xx<width;xx++)
			{
				targetpx[xx] = blend_8888_on_8888(targetpx[xx], argb);
				if (fmt == ifmt_0rgb8888) targetpx[xx] &= 0x00FFFFFF;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
testl %esi, %esi
jns 0xc9ad
movl %esi, %eax
negl %eax
cmpl %ecx, %eax
ja 0xcb43
addl %esi, %ecx
xorl %esi, %esi
testl %edx, %edx
jns 0xc9c3
movl %edx, %eax
negl %eax
cmpl %r8d, %eax
ja 0xcb43
addl %edx, %r8d
xorl %edx, %edx
leal (%rsi,%rcx), %edi
movl (%rbx), %eax
cmpl %eax, %edi
jb 0xc9d6
subl %esi, %eax
jbe 0xcb43
movl %eax, %ecx
leal (%rdx,%r8), %edi
movl 0x4(%rbx), %eax
cmpl %eax, %edi
jb 0xc9ec
subl %edx, %eax
jbe 0xcb43
movl %eax, %r8d
cmpl $0xfeffffff, %r9d       # imm = 0xFEFFFFFF
jbe 0xca80
testl %r8d, %r8d
je 0xcb43
movl %r9d, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
cmpl $0x7, 0x8(%rbx)
cmovnel %r9d, %eax
imull 0xc(%rbx), %edx
andl $-0x4, %edx
addq 0x10(%rbx), %rdx
movl %esi, %esi
leaq (%rdx,%rsi,4), %r14
testl %ecx, %ecx
je 0xca37
movl %ecx, %edx
xorl %esi, %esi
movl %eax, (%r14,%rsi,4)
incq %rsi
cmpq %rdx, %rsi
jb 0xca2b
cmpl $0x1, %r8d
je 0xcb43
movl %ecx, %r15d
shlq $0x2, %r15
cmpl $0x3, %r8d
movl $0x2, %ebp
cmovael %r8d, %ebp
movl $0x1, %r12d
movl 0xc(%rbx), %edi
imull %r12d, %edi
andl $-0x4, %edi
addq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3280
incl %r12d
cmpl %r12d, %ebp
jne 0xca5b
jmp 0xcb43
testl %r8d, %r8d
je 0xcb43
movd %r9d, %xmm0
shrl $0x18, %r9d
movd %r9d, %xmm1
pshuflw $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0,4,5,6,7]
pshufd $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
pxor 0x22ec7(%rip), %xmm1    # 0x2f970
movl %esi, %eax
movl 0x8(%rbx), %esi
movl %ecx, %edi
shlq $0x2, %rax
xorl %r9d, %r9d
pxor %xmm2, %xmm2
movdqa 0x22ebd(%rip), %xmm3    # 0x2f980
movdqa 0x22ec5(%rip), %xmm4    # 0x2f990
testl %ecx, %ecx
je 0xcb39
movq 0x10(%rbx), %r11
addq %rax, %r11
movl 0xc(%rbx), %r10d
imull %edx, %r10d
andl $-0x4, %r10d
addq %r11, %r10
xorl %r11d, %r11d
movd (%r10,%r11,4), %xmm5
punpckldq %xmm0, %xmm5    # xmm5 = xmm5[0],xmm0[0],xmm5[1],xmm0[1]
punpcklbw %xmm2, %xmm5    # xmm5 = xmm5[0],xmm2[0],xmm5[1],xmm2[1],xmm5[2],xmm2[2],xmm5[3],xmm2[3],xmm5[4],xmm2[4],xmm5[5],xmm2[5],xmm5[6],xmm2[6],xmm5[7],xmm2[7]
pmullw %xmm1, %xmm5
movdqa %xmm5, %xmm6
psrldq $0x8, %xmm6             # xmm6 = xmm6[8,9,10,11,12,13,14,15],zero,zero,zero,zero,zero,zero,zero,zero
paddw %xmm5, %xmm6
paddw %xmm3, %xmm6
pmulhuw %xmm4, %xmm6
psrlw $0x7, %xmm6
packuswb %xmm6, %xmm6
movd %xmm6, %ebp
movl %ebp, %r14d
andl $0xffffff, %r14d        # imm = 0xFFFFFF
cmpl $0x7, %esi
cmovnel %ebp, %r14d
movl %r14d, (%r10,%r11,4)
incq %r11
cmpq %rdi, %r11
jb 0xcae8
incl %r9d
incl %edx
cmpl %r8d, %r9d
jb 0xcacb
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq