// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/epocimage.c
// Function: do_read_paint_data_section
static void do_read_paint_data_section(deark *c, lctx *d,
	struct phys_image_ctx *pi, i64 pos1)
{
	i64 pixel_data_offset;
	i64 pos;
	dbuf *unc_pixels = NULL;
	i64 compression_type;
	i64 cmpr_pixels_size;

	pos = pos1;
	de_dbg(c, "paint data section at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	pi->paint_data_section_size = de_getu32le(pos);
	de_dbg(c, "paint data section size: %"I64_FMT, pi->paint_data_section_size);

	// offset within "paint data section"
	pixel_data_offset = de_getu32le(pos+4);
	de_dbg(c, "pixel data offset: %"I64_FMT, pixel_data_offset);

	pi->width = de_getu16le(pos+8);
	pi->height = de_getu16le(pos+12);
	de_dbg(c, "picture dimensions: %d"DE_CHAR_TIMES"%d", (int)pi->width, (int)pi->height);

	pi->bits_per_pixel = de_getu32le(pos+24);
	de_dbg(c, "bits/pixel: %d", (int)pi->bits_per_pixel);

	pi->color_type = de_getu32le(pos+28);
	// 0=grayscale  1=color
	de_dbg(c, "color type: %d", (int)pi->color_type);

	compression_type = de_getu32le(pos+36);
	// 0=uncompressed  1=8-bit RLE  2=12-bit RLE  3=16-bit RLE  4=24-bit RLE
	de_dbg(c, "compression type: %d (%s)", (int)compression_type,
		get_cmpr_type_name(compression_type));

	if(pi->color_type==0) {
		if(pi->bits_per_pixel!=1 && pi->bits_per_pixel!=2 && pi->bits_per_pixel!=4 &&
			pi->bits_per_pixel!=8)
		{
			de_err(c, "Unsupported bits/pixel (%d) for grayscale image", (int)pi->bits_per_pixel);
			goto done;
		}
	}
	else {
		if(pi->bits_per_pixel!=4 && pi->bits_per_pixel!=8 && pi->bits_per_pixel!=12 &&
			pi->bits_per_pixel!=16 && pi->bits_per_pixel!=24)
		{
			de_err(c, "Unsupported bits/pixel (%d) for color image", (int)pi->bits_per_pixel);
			goto done;
		}
		if(pi->bits_per_pixel==12 && compression_type!=2) {
			de_err(c, "12 bits/pixel images are not supported with this compression type (%d)",
				(int)compression_type);
		}
		if(pi->bits_per_pixel==16 && !d->warned_exp) {
			de_warn(c, "Support for this type of 16-bit image is experimental, and may not be correct.");
			d->warned_exp = 1;
		}
	}

	pos += 40;
	cmpr_pixels_size = pi->paint_data_section_size-40;
	de_dbg(c, "pixel data at %"I64_FMT, pos);

	switch(compression_type) {
	case 0: // uncompressed
		unc_pixels = dbuf_open_input_subfile(c->infile, pos, c->infile->len - pos);
		break;
	case 1: // RLE8
		unc_pixels = dbuf_create_membuf(c, 16384, 0);
		do_rle8(c, d, unc_pixels, pos, cmpr_pixels_size);
		break;
	case 2: // RLE12
		unc_pixels = dbuf_create_membuf(c, 16384, 0);
		do_rle12(c, d, unc_pixels, pos, cmpr_pixels_size);
		break;
	case 3: // RLE16
		unc_pixels = dbuf_create_membuf(c, 16384, 0);
		do_rle16_24(c, d, unc_pixels, pos, cmpr_pixels_size, 2);
		break;
	case 4: // RLE24
		unc_pixels = dbuf_create_membuf(c, 16384, 0);
		do_rle16_24(c, d, unc_pixels, pos, cmpr_pixels_size, 3);
		break;
	default:
		de_err(c, "Unsupported compression type: %d", (int)compression_type);
		goto done;
	}

	do_read_phys_image(c, d, pi, unc_pixels);

done:
	if(unc_pixels) dbuf_close(unc_pixels);
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x14a9cc(%rip), %rsi    # 0x1a7e23
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdx
leaq 0x14a9a2(%rip), %rsi    # 0x1a7e3d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x4, %rsi
callq 0x165540
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x14a990(%rip), %rsi    # 0x1a7e5a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0xc, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
leaq 0x14a943(%rip), %rsi    # 0x1a7e71
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x18, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x17468a(%rip), %rsi    # 0x1d1bf4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x1c, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0x14a8e6(%rip), %rsi    # 0x1a7e8c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x24, %rsi
callq 0x165540
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5d900
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %edx
movq %rax, %rcx
leaq 0x14a8ac(%rip), %rsi    # 0x1a7e9b
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x5d653
movq -0x18(%rbp), %rax
cmpq $0x1, 0x18(%rax)
je 0x5d64e
movq -0x18(%rbp), %rax
cmpq $0x2, 0x18(%rax)
je 0x5d64e
movq -0x18(%rbp), %rax
cmpq $0x4, 0x18(%rax)
je 0x5d64e
movq -0x18(%rbp), %rax
cmpq $0x8, 0x18(%rax)
je 0x5d64e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x14a873(%rip), %rsi    # 0x1a7eb5
movb $0x0, %al
callq 0x15bfb0
jmp 0x5d888
jmp 0x5d709
movq -0x18(%rbp), %rax
cmpq $0x4, 0x18(%rax)
je 0x5d6ab
movq -0x18(%rbp), %rax
cmpq $0x8, 0x18(%rax)
je 0x5d6ab
movq -0x18(%rbp), %rax
cmpq $0xc, 0x18(%rax)
je 0x5d6ab
movq -0x18(%rbp), %rax
cmpq $0x10, 0x18(%rax)
je 0x5d6ab
movq -0x18(%rbp), %rax
cmpq $0x18, 0x18(%rax)
je 0x5d6ab
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x14a846(%rip), %rsi    # 0x1a7ee5
movb $0x0, %al
callq 0x15bfb0
jmp 0x5d888
movq -0x18(%rbp), %rax
cmpq $0xc, 0x18(%rax)
jne 0x5d6d5
cmpq $0x2, -0x40(%rbp)
je 0x5d6d5
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x14a843(%rip), %rsi    # 0x1a7f11
movb $0x0, %al
callq 0x15bfb0
movq -0x18(%rbp), %rax
cmpq $0x10, 0x18(%rax)
jne 0x5d707
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x5d707
movq -0x8(%rbp), %rdi
leaq 0x14a863(%rip), %rsi    # 0x1a7f58
movb $0x0, %al
callq 0x15bc10
movq -0x10(%rbp), %rax
movl $0x1, 0x10(%rax)
jmp 0x5d709
movq -0x30(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
addq $-0x28, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x15fc1d(%rip), %rsi    # 0x1bd351
xorl %eax, %eax
callq 0x15b0d0
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
subq $0x4, %rax
ja 0x5d859
movq -0x60(%rbp), %rax
leaq 0x14a418(%rip), %rcx    # 0x1a7b70
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
subq -0x30(%rbp), %rdx
callq 0x1691b0
movq %rax, -0x38(%rbp)
jmp 0x5d873
movq -0x8(%rbp), %rdi
movl $0x4000, %esi           # imm = 0x4000
xorl %edx, %edx
callq 0x168020
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %r8
callq 0x5d9a0
jmp 0x5d873
movq -0x8(%rbp), %rdi
movl $0x4000, %esi           # imm = 0x4000
xorl %edx, %edx
callq 0x168020
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %r8
callq 0x5da90
jmp 0x5d873
movq -0x8(%rbp), %rdi
movl $0x4000, %esi           # imm = 0x4000
xorl %edx, %edx
callq 0x168020
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x2, %r9d
callq 0x5db80
jmp 0x5d873
movq -0x8(%rbp), %rdi
movl $0x4000, %esi           # imm = 0x4000
xorl %edx, %edx
callq 0x168020
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x3, %r9d
callq 0x5db80
jmp 0x5d873
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x14a73d(%rip), %rsi    # 0x1a7fa7
movb $0x0, %al
callq 0x15bfb0
jmp 0x5d888
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x5dcc0
cmpq $0x0, -0x38(%rbp)
je 0x5d898
movq -0x38(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)