// File: Alcaro[P]bridges/arlib/image.cpp
// Function: image::insert_tile_with_border(int, int, unsigned int, unsigned int, image const&, unsigned int, unsigned int, unsigned int, unsigned int)
void image::insert_tile_with_border(int32_t x, int32_t y, uint32_t width, uint32_t height,
                                    const image& other, uint32_t x1, uint32_t x2, uint32_t y1, uint32_t y2)
{
	uint32_t x3 = other.width;
	uint32_t y3 = other.height;
	
	uint32_t w1 = x1-0;
	uint32_t w2 = x2-x1;
	uint32_t w3 = x3-x2;
	uint32_t h1 = y1-0;
	uint32_t h2 = y2-y1;
	uint32_t h3 = y3-y2;
	
	image sub;
	
	insert_sub(x,          y,           other, 0,  0,  x1, y1); // top left
	sub.init_ref_sub(other, x1, 0,  w2, h1); insert_tile(x+x1,       y,           width-w1-w3, h1,           sub); // top
	insert_sub(x+width-w3, y,           other, x2, 0,  w3, y1); // top right
	
	sub.init_ref_sub(other, 0,  y1, w1, h2); insert_tile(x,          y+y1,        w1,          height-h1-h3, sub); // left
	sub.init_ref_sub(other, x1, y1, w2, h2); insert_tile(x+x1,       y+y1,        width-w1-w3, height-h1-h3, sub); // middle
	sub.init_ref_sub(other, x2, y1, w3, h2); insert_tile(x+width-w3, y+y1,        w3,          height-h1-h3, sub); // right
	
	insert_sub(x,          y+height-h3, other, 0,  y2, x1, h3); // bottom left
	sub.init_ref_sub(other, x1, y2, w2, h3); insert_tile(x+x1,       y+height-h3, width-w1-w3, h3,           sub); // bottom
	insert_sub(x+width-w3, y+height-h3, other, x2, y2, w3, h3); // bottom right
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x28(%rbp)
movl 0x10(%rbp), %eax
subl $0x0, %eax
movl %eax, -0x2c(%rbp)
movl 0x18(%rbp), %eax
subl 0x10(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
subl 0x18(%rbp), %eax
movl %eax, -0x34(%rbp)
movl 0x20(%rbp), %eax
subl $0x0, %eax
movl %eax, -0x38(%rbp)
movl 0x28(%rbp), %eax
subl 0x20(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x28(%rbp), %eax
subl 0x28(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x20(%rbp), %rcx
movl 0x10(%rbp), %r10d
movl 0x20(%rbp), %eax
xorl %r9d, %r9d
movl %r9d, %r8d
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1af80
movq -0x20(%rbp), %rsi
movl 0x10(%rbp), %edx
movl -0x30(%rbp), %r8d
movl -0x38(%rbp), %r9d
leaq -0x58(%rbp), %rdi
xorl %ecx, %ecx
callq 0x1afe0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
addl 0x10(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
subl -0x2c(%rbp), %ecx
subl -0x34(%rbp), %ecx
movl -0x38(%rbp), %r8d
leaq -0x58(%rbp), %r9
callq 0x186b0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
addl -0x14(%rbp), %esi
subl -0x34(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x20(%rbp), %rcx
movl 0x18(%rbp), %r8d
movl -0x34(%rbp), %r10d
movl 0x20(%rbp), %eax
xorl %r9d, %r9d
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1af80
movq -0x20(%rbp), %rsi
movl 0x20(%rbp), %ecx
movl -0x2c(%rbp), %r8d
movl -0x3c(%rbp), %r9d
leaq -0x58(%rbp), %rdi
xorl %edx, %edx
callq 0x1afe0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
addl 0x20(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl -0x18(%rbp), %r8d
subl -0x38(%rbp), %r8d
subl -0x40(%rbp), %r8d
leaq -0x58(%rbp), %r9
callq 0x186b0
movq -0x20(%rbp), %rsi
movl 0x10(%rbp), %edx
movl 0x20(%rbp), %ecx
movl -0x30(%rbp), %r8d
movl -0x3c(%rbp), %r9d
leaq -0x58(%rbp), %rdi
callq 0x1afe0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
addl 0x10(%rbp), %esi
movl -0x10(%rbp), %edx
addl 0x20(%rbp), %edx
movl -0x14(%rbp), %ecx
subl -0x2c(%rbp), %ecx
subl -0x34(%rbp), %ecx
movl -0x18(%rbp), %r8d
subl -0x38(%rbp), %r8d
subl -0x40(%rbp), %r8d
leaq -0x58(%rbp), %r9
callq 0x186b0
movq -0x20(%rbp), %rsi
movl 0x18(%rbp), %edx
movl 0x20(%rbp), %ecx
movl -0x34(%rbp), %r8d
movl -0x3c(%rbp), %r9d
leaq -0x58(%rbp), %rdi
callq 0x1afe0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
addl -0x14(%rbp), %esi
subl -0x34(%rbp), %esi
movl -0x10(%rbp), %edx
addl 0x20(%rbp), %edx
movl -0x34(%rbp), %ecx
movl -0x18(%rbp), %r8d
subl -0x38(%rbp), %r8d
subl -0x40(%rbp), %r8d
leaq -0x58(%rbp), %r9
callq 0x186b0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
addl -0x18(%rbp), %edx
subl -0x40(%rbp), %edx
movq -0x20(%rbp), %rcx
movl 0x28(%rbp), %r9d
movl 0x10(%rbp), %r10d
movl -0x40(%rbp), %eax
xorl %r8d, %r8d
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1af80
movq -0x20(%rbp), %rsi
movl 0x10(%rbp), %edx
movl 0x28(%rbp), %ecx
movl -0x30(%rbp), %r8d
movl -0x40(%rbp), %r9d
leaq -0x58(%rbp), %rdi
callq 0x1afe0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
addl 0x10(%rbp), %esi
movl -0x10(%rbp), %edx
addl -0x18(%rbp), %edx
subl -0x40(%rbp), %edx
movl -0x14(%rbp), %ecx
subl -0x2c(%rbp), %ecx
subl -0x34(%rbp), %ecx
movl -0x40(%rbp), %r8d
leaq -0x58(%rbp), %r9
callq 0x186b0
movq -0x60(%rbp), %rdi
movl -0xc(%rbp), %esi
addl -0x14(%rbp), %esi
subl -0x34(%rbp), %esi
movl -0x10(%rbp), %edx
addl -0x18(%rbp), %edx
subl -0x40(%rbp), %edx
movq -0x20(%rbp), %rcx
movl 0x18(%rbp), %r8d
movl 0x28(%rbp), %r9d
movl -0x34(%rbp), %r10d
movl -0x40(%rbp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1af80
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)