// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc2.c
// Function: do_lotus_mscr_rle
static void do_lotus_mscr_rle(deark *c, struct lotus_mscr_ctx *d)
{
	i64 npixels_expected;
	i64 npixels_found;
	i64 pos;
	dbuf *unc_pixels = NULL;
	de_bitmap *img = NULL;
	de_color pal[256];

	npixels_expected = d->w*d->h;
	unc_pixels = dbuf_create_membuf(c, npixels_expected, 0x1);
	dbuf_enable_wbuffer(unc_pixels);
	pos = 9;
	npixels_found = 0;

	while(1) {
		i64 count;
		u8 color;
		u8 x;

		if(npixels_found >= npixels_expected) break;
		if(pos >= c->infile->len) break;

		x = de_getbyte_p(&pos);
		color = x>>7;
		count = (i64)(x & 0x7f);
		if(count==0) count = 128;

		dbuf_write_run(unc_pixels, color, count);
		npixels_found += count;
	}

	dbuf_flush(unc_pixels);
	if(npixels_found != npixels_expected) {
		de_warn(c, "Expected %"I64_FMT" pixels, found %"I64_FMT, npixels_expected,
			npixels_found);
	}

	img = de_bitmap_create(c, d->w, d->h, 1);
	de_zeromem(pal, sizeof(pal));
	pal[0] = DE_STOCKCOLOR_WHITE;
	pal[1] = DE_STOCKCOLOR_BLACK;
	de_convert_image_paletted(unc_pixels, 0, 8, d->w, pal, img, 0);
	de_bitmap_write_to_file_finfo(img, d->fi, 0);

	dbuf_close(unc_pixels);
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x8(%rcx), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x167b90
movq $0x9, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jl 0x9b935
jmp 0x9b9c5
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x9b949
jmp 0x9b9c5
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x44a(%rbp)
movzbl -0x44a(%rbp), %eax
sarl $0x7, %eax
movb %al, -0x449(%rbp)
movzbl -0x44a(%rbp), %eax
andl $0x7f, %eax
cltq
movq %rax, -0x448(%rbp)
cmpq $0x0, -0x448(%rbp)
jne 0x9b998
movq $0x80, -0x448(%rbp)
movq -0x30(%rbp), %rdi
movb -0x449(%rbp), %al
movq -0x448(%rbp), %rdx
movzbl %al, %esi
callq 0x168800
movq -0x448(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x9b926
movq -0x30(%rbp), %rdi
callq 0x167c30
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x9b9f2
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x11523b(%rip), %rsi    # 0x1b0c26
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, -0x38(%rbp)
leaq -0x440(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x19140
movl $0xffffffff, -0x440(%rbp) # imm = 0xFFFFFFFF
movl $0xff000000, -0x43c(%rbp) # imm = 0xFF000000
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
leaq -0x440(%rbp), %r8
movq -0x38(%rbp), %r9
xorl %eax, %eax
movl %eax, %esi
movl $0x8, %edx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
xorl %edx, %edx
callq 0x16afa0
movq -0x30(%rbp), %rdi
callq 0x1676a0
movq -0x38(%rbp), %rdi
callq 0x16af60
addq $0x460, %rsp            # imm = 0x460
popq %rbp
retq
nopw %cs:(%rax,%rax)