// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Graphics/RLEBitmap.c
// Function: InitializeRLEBitmapFromPartialBitmap
void InitializeRLEBitmapFromPartialBitmap(RLEBitmap *self,const Bitmap *bitmap,int x0,int y0,int width,int height)
{
	self->width=width;
	self->height=height;
	Pixel *ptr=self->codes;

	for(int y=0;y<height;y++)
	{
		int x=0;
		while(x<width)
		{
			int emptystart=x;
			while(x<width && x-emptystart<0xff)
			{
				Pixel p=ReadPixel(bitmap,x+x0,y+y0);
				if(!IsPixelTransparent(p)) break;
				x++;
			}
			int empty=x-emptystart;

			int filledstart=x;
			while(x<width && x-filledstart<0xff)
			{
				Pixel p=ReadPixel(bitmap,x+x0,y+y0);
				if(IsPixelTransparent(p)) break;
				x++;
			}
			int filled=x-filledstart;

			#ifdef SingleBytePixels
			*ptr++=empty;
			if(x<width || filled!=0) *ptr++=filled;
			#else
			*ptr++=RLECode(empty,filled);
			memcpy(ptr,ConstBitmapPixelPointer(bitmap,filledstart+x0,y+y0),filled*sizeof(Pixel));
			ptr+=filled;
			#endif
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x60(%rsp), %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, (%rax)
movl -0x20(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd2f1
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xd2e1
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0x49(%rbp)
jge 0xd1b0
movl -0x30(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl $0xff, %eax
setl %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0xd1b9
jmp 0xd1fb
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x2c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0xad60
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xd1e6
xorl %eax, %eax
testb $0x1, %al
jne 0xd1f0
jmp 0xd1ee
movb $0x1, %al
testb $0x1, %al
jne 0xd1f0
jmp 0xd1ee
jmp 0xd1fb
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xd192
movl -0x30(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x30(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0x4a(%rbp)
jge 0xd228
movl -0x30(%rbp), %eax
subl -0x40(%rbp), %eax
cmpl $0xff, %eax
setl %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
testb $0x1, %al
jne 0xd231
jmp 0xd273
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x2c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0xad60
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xd25e
xorl %eax, %eax
testb $0x1, %al
jne 0xd266
jmp 0xd268
movb $0x1, %al
testb $0x1, %al
jne 0xd266
jmp 0xd268
jmp 0xd273
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xd20a
movl -0x30(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %ecx
shll $0x8, %ecx
orl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq %rdx, -0x28(%rbp)
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x2c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0xd300
movq -0x58(%rbp), %rdi
movq %rax, %rsi
movslq -0x48(%rbp), %rdx
shlq $0x2, %rdx
callq 0x1150
movl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0xd180
jmp 0xd2e3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd16d
leaq 0x60(%rsp), %rsp
popq %rbp
retq
nopl (%rax,%rax)