// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %ebp
movq %r8, 0x8(%rsp)
testl %esi, %esi
movq %rdi, 0x10(%rsp)
jns 0xadce
movl %esi, %eax
negl %eax
cmpl %ecx, %eax
ja 0xaf18
addl %esi, %ecx
xorl %esi, %esi
movq 0x10(%rsp), %rdi
testl %edx, %edx
jns 0xadf3
movl %edx, %eax
negl %eax
cmpl 0x8(%rsp), %eax
ja 0xaf18
movq 0x8(%rsp), %rax
addl %edx, %eax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
movq 0x10(%rsp), %rdi
leal (%rsi,%rcx), %r8d
movl (%rdi), %eax
cmpl %eax, %r8d
jb 0xae0d
subl %esi, %eax
jbe 0xaf18
movl %eax, %ecx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rax
leal (%rdx,%rax), %r8d
movl 0x4(%rdi), %eax
cmpl %eax, %r8d
jb 0xae2b
subl %edx, %eax
jbe 0xaf18
movq %rax, 0x8(%rsp)
cmpl $0xfeffffff, %ebp       # imm = 0xFEFFFFFF
jbe 0xae75
cmpl $0x0, 0x8(%rsp)
je 0xaf18
movl %ebp, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movq 0x10(%rsp), %rdi
cmpl $0x7, 0x8(%rdi)
cmovnel %ebp, %eax
imull 0xc(%rdi), %edx
andl $-0x4, %edx
addq 0x10(%rdi), %rdx
movl %esi, %esi
leaq (%rdx,%rsi,4), %r15
movl %ecx, %r12d
xorl %ecx, %ecx
cmpq %rcx, %r12
je 0xaeeb
movl %eax, (%r15,%rcx,4)
incq %rcx
jmp 0xae67
movl %esi, %eax
movl %ecx, %r13d
shlq $0x2, %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
cmpl 0x8(%rsp), %r14d
je 0xaf18
movq 0x10(%rsp), %rcx
movl 0x8(%rcx), %r12d
movq 0x10(%rcx), %rax
addq 0x18(%rsp), %rax
movl 0xc(%rcx), %ebx
movq %rdx, 0x20(%rsp)
imull %edx, %ebx
andl $-0x4, %ebx
addq %rax, %rbx
xorl %r15d, %r15d
cmpq %r15, %r13
je 0xaedf
movl (%rbx,%r15,4), %edi
movl %ebp, %esi
callq 0xaf27
movl %eax, %ecx
andl $0xffffff, %ecx         # imm = 0xFFFFFF
cmpl $0x7, %r12d
cmovnel %eax, %ecx
movl %ecx, (%rbx,%r15,4)
incq %r15
jmp 0xaeb7
incl %r14d
movq 0x20(%rsp), %rdx
incl %edx
jmp 0xae86
shlq $0x2, %r12
pushq $0x1
popq %rbx
cmpl 0x8(%rsp), %ebx
jae 0xaf18
movq 0x10(%rsp), %rax
movl 0xc(%rax), %edi
imull %ebx, %edi
andl $-0x4, %edi
addq %r15, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3280
incl %ebx
jmp 0xaef2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq