// File: /workspace/github_cpp_makefile_star2_O3/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 0xcd4f
movl %esi, %eax
negl %eax
cmpl %ecx, %eax
ja 0xcfe9
addl %esi, %ecx
xorl %esi, %esi
testl %edx, %edx
jns 0xcd65
movl %edx, %eax
negl %eax
cmpl %r8d, %eax
ja 0xcfe9
addl %edx, %r8d
xorl %edx, %edx
leal (%rsi,%rcx), %edi
movl (%rbx), %eax
cmpl %eax, %edi
jb 0xcd78
subl %esi, %eax
jbe 0xcfe9
movl %eax, %ecx
leal (%rdx,%r8), %edi
movl 0x4(%rbx), %eax
cmpl %eax, %edi
jb 0xcd8e
subl %edx, %eax
jbe 0xcfe9
movl %eax, %r8d
cmpl $0xfeffffff, %r9d       # imm = 0xFEFFFFFF
jbe 0xcf26
testl %r8d, %r8d
je 0xcfe9
movl %r9d, %edi
andl $0xffffff, %edi         # imm = 0xFFFFFF
cmpl $0x7, 0x8(%rbx)
cmovnel %r9d, %edi
movq 0x10(%rbx), %rax
imull 0xc(%rbx), %edx
movl %esi, %esi
testl %ecx, %ecx
je 0xced3
movl %edx, %r10d
shrl $0x2, %r10d
movl %ecx, %r11d
leaq 0x3(%r11), %r9
andq $-0x4, %r9
decq %r11
movq %r11, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq (,%rsi,4), %r11
leaq (%r11,%r10,4), %r10
addq %rax, %r10
addq $0xc, %r10
movdqa 0x22baf(%rip), %xmm1    # 0x2f9b0
movdqa 0x22567(%rip), %xmm2    # 0x2f370
xorl %r11d, %r11d
movdqa 0x22bac(%rip), %xmm3    # 0x2f9c0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x22bac(%rip), %xmm5    # 0x2f9d0
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %ebp
notl %ebp
testb $0x1, %bpl
je 0xce5e
movl %edi, -0xc(%r10,%r11,4)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %ebp
testb $0x1, %bpl
je 0xce72
movl %edi, -0x8(%r10,%r11,4)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %ebp
testb $0x1, %bpl
je 0xceaf
movl %edi, -0x4(%r10,%r11,4)
pextrw $0x4, %xmm6, %ebp
testb $0x1, %bpl
je 0xcebe
movl %edi, (%r10,%r11,4)
addq $0x4, %r11
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
cmpq %r11, %r9
jne 0xce24
cmpl $0x1, %r8d
je 0xcfe9
andl $-0x4, %edx
addq %rdx, %rax
leaq (%rax,%rsi,4), %r14
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 0xcf01
jmp 0xcfe9
testl %r8d, %r8d
je 0xcfe9
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 0x22a11(%rip), %xmm1    # 0x2f960
movl %esi, %eax
movl 0x8(%rbx), %esi
movl %ecx, %edi
shlq $0x2, %rax
xorl %r9d, %r9d
pxor %xmm2, %xmm2
movdqa 0x22a07(%rip), %xmm3    # 0x2f970
movdqa 0x22a0f(%rip), %xmm4    # 0x2f980
testl %ecx, %ecx
je 0xcfdf
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 0xcf8e
incl %r9d
incl %edx
cmpl %r8d, %r9d
jb 0xcf71
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq