// File: /workspace/github_cpp_makefile_star2_O1/Alcaro[P]bridges/arlib/image.cpp
// Function: image::insert_tile(int, int, unsigned int, unsigned int, image const&, int, int)
void image::insert_tile(int32_t x, int32_t y, uint32_t width, uint32_t height,
                        const image& other, int32_t offx, int32_t offy)
{
	if (offx < 0) { offx = -offx; offx %= other.width;  offx = -offx; offx += other.width;  }
	if (offy < 0) { offy = -offy; offy %= other.height; offy = -offy; offx += other.height; }
	if ((uint32_t)offx > other.width)  { offx %= other.width;  }
	if ((uint32_t)offy > other.height) { offy %= other.height; }
	
	if (offy + height <= other.height)
	{
		image_insert_tile_row(*this, x, y, width, height, other, offx, offy);
		return;
	}
	
	if (offy != 0)
	{
		image_insert_tile_row(*this, x, y, width, other.height-offy, other, offx, offy);
		y += other.height-offy;
		height -= other.height-offy;
	}
	
	uint32_t yy = 0;
	if (height >= other.height)
	{
		for (yy = 0; yy < height-other.height; yy += other.height)
		{
			image_insert_tile_row(*this, x, y+yy, width, other.height, other, offx, 0);
		}
	}
	
	if (yy < height)
	{
		image_insert_tile_row(*this, x, y+yy, width, height-yy, other, offx, 0);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %r14d
movl %edx, %r11d
movq %rdi, %r15
movl 0x58(%rsp), %r12d
movl 0x50(%rsp), %r10d
testl %r10d, %r10d
jns 0xc33c
negl %r10d
movl (%r9), %edi
movl %r10d, %eax
xorl %edx, %edx
divl %edi
subl %edx, %edi
movl %edi, %r10d
testl %r12d, %r12d
jns 0xc358
negl %r12d
movl 0x4(%r9), %edi
movl %r12d, %eax
xorl %edx, %edx
divl %edi
movl %edx, %r12d
negl %r12d
addl %edi, %r10d
movl (%r9), %edi
cmpl %edi, %r10d
jbe 0xc36a
movl %r10d, %eax
xorl %edx, %edx
divl %edi
movl %edx, %r10d
movl 0x4(%r9), %r8d
cmpl %r8d, %r12d
jbe 0xc37e
movl %r12d, %eax
xorl %edx, %edx
divl %r8d
movl %edx, %r12d
leal (%r12,%r14), %eax
cmpl %r8d, %eax
jbe 0xc3cc
testl %r12d, %r12d
movl %esi, 0x4(%rsp)
movq %r10, 0x8(%rsp)
movq %r9, 0x10(%rsp)
je 0xc3de
subl %r12d, %r8d
movq %r15, %rdi
movl %r11d, %edx
movl %ecx, %ebp
movq %r11, %r13
pushq %r12
pushq %r10
callq 0xc479
movq 0x20(%rsp), %r9
movq %r13, %r11
addq $0x10, %rsp
movl 0x4(%r9), %eax
subl %r12d, %eax
addl %eax, %r11d
subl %eax, %r14d
jmp 0xc3e0
movq %r15, %rdi
movl %r11d, %edx
movl %r14d, %r8d
pushq %r12
pushq %r10
jmp 0xc45f
movl %ecx, %ebp
movl 0x4(%r9), %r8d
xorl %r12d, %r12d
cmpl %r8d, %r14d
movl %ebp, %r13d
movl 0x4(%rsp), %ebx
movq 0x8(%rsp), %rax
jbe 0xc441
xorl %r12d, %r12d
leal (%r12,%r11), %edx
movq %r15, %rdi
movl %ebx, %esi
movl %r13d, %ecx
movq %r15, %rbp
movq %r14, %r15
movq %r11, %r14
pushq $0x0
pushq %rax
callq 0xc479
movq 0x20(%rsp), %r9
movq %r14, %r11
movq %r15, %r14
movq %rbp, %r15
addq $0x10, %rsp
movl 0x4(%r9), %r8d
addl %r8d, %r12d
movl %r14d, %eax
subl %r8d, %eax
cmpl %eax, %r12d
movq 0x8(%rsp), %rax
jb 0xc3fb
subl %r12d, %r14d
jbe 0xc46a
addl %r11d, %r12d
movq %r15, %rdi
movl 0x4(%rsp), %esi
movl %r12d, %edx
movl %r13d, %ecx
movl %r14d, %r8d
pushq $0x0
pushq 0x10(%rsp)
callq 0xc479
addq $0x28, %rsp
jmp 0xc46e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq