// File: Alcaro[P]bridges/arlib/image.cpp
// Function: oimage::init_clone(image const&, int, int)
void oimage::init_clone(const image& other, int32_t scalex, int32_t scaley)
{
	init_new(other.width * (scalex<0 ? -scalex : scalex), other.height * (scaley<0 ? -scaley : scaley), other.fmt);
	
	bool flipx = (scalex<0);
	bool flipy = (scaley<0);
	scalex = abs(scalex);
	scaley = abs(scaley);
	
	for (uint32_t sy=0;sy<other.height;sy++)
	{
		int ty = sy*scaley;
		if (flipy) ty = (height-1-sy)*scaley;
		uint32_t* targetpx = this->pixels32 + ty*this->stride/sizeof(uint32_t);
		uint32_t* sourcepx = other.pixels32 + sy*other.stride/sizeof(uint32_t);
		uint32_t* targetpxorg = targetpx;
		
		if (flipx)
		{
			sourcepx += width;
			for (uint32_t sx=0;sx<other.width;sx++)
			{
				sourcepx--;
				for (int32_t xx=0;xx<scalex;xx++)
				{
					*(targetpx++) = *sourcepx;
				}
			}
		}
		else
		{
			for (uint32_t sx=0;sx<other.width;sx++)
			{
				for (int32_t xx=0;xx<scalex;xx++)
				{
					*(targetpx++) = *sourcepx;
				}
				sourcepx++;
			}
		}
		
		for (int32_t yy=1;yy<scaley;yy++)
		{
			memcpy(targetpxorg+yy*stride/sizeof(uint32_t), targetpxorg, sizeof(uint32_t)*width);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x195e7
xorl %eax, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x195ed
movl -0x14(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x58(%rbp), %eax
movl -0x64(%rbp), %ecx
imull %ecx, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x19613
xorl %eax, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x19619
movl -0x18(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %esi
movq -0x60(%rbp), %rdi
movl -0x68(%rbp), %edx
movl -0x70(%rbp), %eax
imull %eax, %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
callq 0x18360
cmpl $0x0, -0x14(%rbp)
setl %al
andb $0x1, %al
movb %al, -0x19(%rbp)
cmpl $0x0, -0x18(%rbp)
setl %al
andb $0x1, %al
movb %al, -0x1a(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x1981c
movl -0x20(%rbp), %eax
imull -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
testb $0x1, -0x1a(%rbp)
je 0x196a2
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
subl -0x20(%rbp), %eax
imull -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x60(%rbp), %rdx
movq 0x10(%rdx), %rax
movl -0x24(%rbp), %ecx
imull 0xc(%rdx), %ecx
movl %ecx, %ecx
shrq $0x2, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0xc(%rdx), %ecx
movl %ecx, %ecx
shrq $0x2, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
testb $0x1, -0x19(%rbp)
je 0x19769
movq -0x60(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x19767
movq -0x38(%rbp), %rax
addq $-0x4, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1975a
movq -0x38(%rbp), %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq %rdx, -0x30(%rbp)
movl %ecx, (%rax)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x19730
jmp 0x1975c
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x19712
jmp 0x197c5
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x197c3
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x197ac
movq -0x38(%rbp), %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq %rdx, -0x30(%rbp)
movl %ecx, (%rax)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x19782
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x19770
jmp 0x197c5
movl $0x1, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x1980c
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rdi
movl -0x54(%rbp), %ecx
imull 0xc(%rax), %ecx
movl %ecx, %ecx
shrq $0x2, %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq -0x40(%rbp), %rsi
movl (%rax), %eax
movl %eax, %edx
shlq $0x2, %rdx
callq 0x4280
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x197cc
jmp 0x1980e
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1966e
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)