// File: Alcaro[P]bridges/arlib/image.cpp
// Function: image_insert_noov(image&, int, int, image const&)
static inline void image_insert_noov(image& target, int32_t x, int32_t y, const image& source)
{
	//dst\src  x  0  a   ba
	//  x      =  =  C0  ?=
	//  0      0  =  C0  ?=0
	//  a      1  1  Ca  ?=
	//  ba     1  1  C0  ?=
	// = - bitwise copy
	// 0 - bitwise copy, but set alpha to 0
	// 1 - bitwise copy, but set alpha to 1
	// ?= - bitwise copy if opaque, otherwise leave unchanged
	// ?=0 - if opaque, bitwise copy but set alpha to 0; otherwise leave unchanged
	// C0 - composite, but set output alpha to zero
	// Ca - composite
	// dst=ba src=a with non-ba-compliant src will yield shitty results,
	//  but there is no possible answer so the only real solution is banning it in the API.
	
	if (source.fmt == ifmt_bargb8888 && target.fmt == ifmt_0rgb8888)
		return image_insert_noov_8888_to_8888<true, 0x00000000>(target, x, y, source);
	if (source.fmt == ifmt_bargb8888)
		return image_insert_noov_8888_to_8888<true, (uint32_t)-1>(target, x, y, source);
	if (source.fmt == ifmt_argb8888 && target.fmt == ifmt_0rgb8888)
		return image_insert_noov_8888_to_8888_blend<0x00000000>(target, x, y, source);
	if (source.fmt == ifmt_argb8888)
		return image_insert_noov_8888_to_8888_blend<(uint32_t)-1>(target, x, y, source);
	if (target.fmt == ifmt_argb8888 || target.fmt == ifmt_bargb8888)
		return image_insert_noov_8888_to_8888<false, 0xFF000000>(target, x, y, source);
	if (target.fmt == ifmt_0rgb8888 && source.fmt == ifmt_xrgb8888)
		return image_insert_noov_8888_to_8888<false, 0x00000000>(target, x, y, source);
	else
		return image_insert_noov_8888_to_8888<false, (uint32_t)-1>(target, x, y, source);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x8, 0x8(%rax)
jne 0x185d2
movq -0x8(%rbp), %rax
cmpl $0x7, 0x8(%rax)
jne 0x185d2
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x19a10
jmp 0x186a4
movq -0x18(%rbp), %rax
cmpl $0x8, 0x8(%rax)
jne 0x185f4
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x19e10
jmp 0x186a4
movq -0x18(%rbp), %rax
cmpl $0x5, 0x8(%rax)
jne 0x18620
movq -0x8(%rbp), %rax
cmpl $0x7, 0x8(%rax)
jne 0x18620
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1a210
jmp 0x186a4
movq -0x18(%rbp), %rax
cmpl $0x5, 0x8(%rax)
jne 0x1863f
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1a350
jmp 0x186a4
movq -0x8(%rbp), %rax
cmpl $0x5, 0x8(%rax)
je 0x18653
movq -0x8(%rbp), %rax
cmpl $0x8, 0x8(%rax)
jne 0x18668
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1a470
jmp 0x186a4
movq -0x8(%rbp), %rax
cmpl $0x7, 0x8(%rax)
jne 0x18691
movq -0x18(%rbp), %rax
cmpl $0x6, 0x8(%rax)
jne 0x18691
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1a7c0
jmp 0x186a4
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x1ab10
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)