// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/printptnr.c
// Function: do_one_image
static int do_one_image(deark *c, lctx *d, i64 pos1, int img_idx, i64 *bytes_consumed)
{
	i64 namelen;
	i64 pos = pos1;
	i64 bytes_consumed2 = 0;
	int retval = 0;

	struct page_ctx *pg = NULL;

	pg = de_malloc(c, sizeof(struct page_ctx));

	de_dbg(c, "image #%d at %d", img_idx, (int)pos1);
	de_dbg_indent(c, 1);
	namelen = (i64)de_getbyte(pos++);
	if(namelen>20) {
		de_err(c, "Invalid image");
		goto done;
	}

	pg->imgname = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, pos, namelen, pg->imgname, 0, DE_ENCODING_ASCII);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz(pg->imgname));
	pos += 20;

	pg->cmpr_type = (i64)de_getbyte(pos++);
	de_dbg(c, "cmpr type: %d", (int)pg->cmpr_type);
	pg->height = (i64)de_getbyte(pos++);
	pg->width_raw = (i64)de_getbyte(pos++);
	pg->width = pg->width_raw*8;
	de_dbg_dimensions(c, pg->width, pg->height);

	if(pg->cmpr_type==1) {
		do_image_cmpr1(c, d, pg, pos, &bytes_consumed2);
		pos += bytes_consumed2;
	}
	else if(pg->cmpr_type==2) {
		do_image_cmpr2(c, d, pg, pos, &bytes_consumed2);
		pos += bytes_consumed2;
	}
	else if(pg->cmpr_type==3) {
		do_image_cmpr3(c, d, pg, pos, &bytes_consumed2);
		pos += bytes_consumed2;
	}
	else {
		de_err(c, "Unsupported compression type: %d", (int)pg->cmpr_type);
		goto done;
	}

	*bytes_consumed = pos - pos1;
	retval = 1;
done:
	de_dbg_indent(c, -1);
	if(pg) {
		ucstring_destroy(pg->imgname);
		de_free(c, pg);
	}
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl $0x28, %esi
callq 0x15b780
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rax
movl %eax, %ecx
leaq 0xb3bb2(%rip), %rsi     # 0x1c3982
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movzbl %al, %eax
movq %rax, -0x30(%rbp)
cmpq $0x14, -0x30(%rbp)
jle 0x10fe26
movq -0x8(%rbp), %rdi
leaq 0xb3b78(%rip), %rsi     # 0x1c3992
movb $0x0, %al
callq 0x15bfb0
jmp 0x11002a
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x172500
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0x9e34d(%rip), %rsi     # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movzbl %al, %eax
movb %al, %cl
movq -0x50(%rbp), %rax
movb %cl, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movzbl 0x18(%rax), %edx
leaq 0xb3acf(%rip), %rsi     # 0x1c39a0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rcx
shlq $0x3, %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movq (%rax), %rsi
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x15bba0
movq -0x50(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x1, %eax
jne 0x10ff8c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x110070
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x110014
movq -0x50(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x2, %eax
jne 0x10ffc0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x110100
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x110012
movq -0x50(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x3, %eax
jne 0x10fff4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x110270
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x110010
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movzbl 0x18(%rax), %edx
leaq 0x97fa0(%rip), %rsi     # 0x1a7fa7
movb $0x0, %al
callq 0x15bfb0
jmp 0x11002a
jmp 0x110012
jmp 0x110014
movq -0x38(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpq $0x0, -0x50(%rbp)
je 0x110059
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x15b820
movl -0x44(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)