// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/eps.c
// Function: do_decode_epsi_image
static void do_decode_epsi_image(deark *c, lctx *d, i64 pos1)
{
	de_bitmap *img = NULL;
	dbuf *tmpf = NULL;
	i64 content_len, total_len;
	i64 pos;
	i64 i, k;
	UI createflags;

	pos = pos1;
	d->hex_digit_count = 0;

	tmpf = dbuf_create_membuf(c, d->pdwidth * d->h, 0);

	// Convert from hex-encoded (base16) to binary.
	for(i=0; i<d->lines; i++) {
		if(!dbuf_find_line(c->infile, pos, &content_len, &total_len))
			break;
		for(k=0; k<content_len; k++) {
			process_hex_digit(c, d, de_getbyte(pos+k), tmpf);
		}
		pos += total_len;
	}

	// Convert from binary to an image

	img = de_bitmap_create2(c, d->npwidth, d->pdwidth, d->h, 1);

	de_make_grayscale_palette(d->pal, 1ULL<<d->depth, 0x1);
	de_convert_image_paletted(tmpf, 0, d->depth, d->src_rowspan, d->pal, img, 0);

	createflags = DE_CREATEFLAG_IS_AUX;
	if(d->depth==1) {
		createflags |= DE_CREATEFLAG_IS_BWIMG;
	}
	else {
		createflags |= DE_CREATEFLAG_OPT_IMAGE;
	}
	de_bitmap_write_to_file(img, "preview", createflags);
	de_bitmap_destroy(img);
	dbuf_close(tmpf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
imulq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0x168020
movq %rax, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jge 0x5ecc8
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
leaq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x169640
cmpl $0x0, %eax
jne 0x5ec52
jmp 0x5ecc8
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x5ecab
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
addq -0x50(%rbp), %rsi
callq 0x165060
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x28(%rbp), %rcx
movzbl %al, %edx
callq 0x5eda0
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x5ec5a
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x5ec20
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %r8d
callq 0x16b7f0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
addq $0x4c, %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x1, %esi
shlq %cl, %rsi
movl $0x1, %edx
callq 0x16d580
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %r8
addq $0x4c, %r8
movq -0x20(%rbp), %r9
xorl %eax, %eax
movl %eax, %esi
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movl $0x1, -0x54(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x18(%rax)
jne 0x5ed63
movl -0x54(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x54(%rbp)
jmp 0x5ed6c
movl -0x54(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x54(%rbp)
movq -0x20(%rbp), %rdi
movl -0x54(%rbp), %edx
leaq 0x14278b(%rip), %rsi    # 0x1a1505
callq 0x16afd0
movq -0x20(%rbp), %rdi
callq 0x16af60
movq -0x28(%rbp), %rdi
callq 0x1676a0
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)