// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/printshop.c
// Function: do_printshop_etc
static void do_printshop_etc(deark *c, lctx *d)
{
	i64 headersize = 0;
	const char *namefile_fn = NULL;
	i64 bytes_consumed;
	i64 pos;
	i64 img_count;
	i64 num_images = 0;
	int num_images_is_known = 0;

	namefile_fn = de_get_ext_option(c, "namefile");
	if(!namefile_fn) namefile_fn = de_get_ext_option(c, "file2");

	if(namefile_fn) {
		d->namefile = dbuf_open_input_file(c, namefile_fn);
	}
	if(d->namefile) {
		de_dbg(c, "Using name file: %s", namefile_fn);
	}

	if(d->fmt == PRINTSHOP_FMT_POG) {
		num_images = de_getu16le(8);
		de_dbg(c, "number of images: %d", (int)num_images);
		num_images_is_known = 1;
		headersize = 10;
	}
	else {
		headersize = 0;
	}

	pos = headersize;
	img_count = 0;
	while(1) {
		if(num_images_is_known && (img_count >= num_images)) break;
		if(pos >= c->infile->len) break;
		do_printshop_etc_image(c, d, img_count, pos, &bytes_consumed);
		if(bytes_consumed<1) break;
		pos += bytes_consumed;
		img_count++;
	}

	if(num_images_is_known && (c->infile->len - pos)>=128) {
		de_warn(c, "%d bytes of data were ignored. This file may not have "
			"been fully decoded.", (int)(c->infile->len - pos));
	}

	dbuf_close(d->namefile);
	d->namefile = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r13
movq %rdi, %r14
leaq 0x7a5d8(%rip), %rsi     # 0x139188
callq 0xea6cb
movq %rax, %rbx
testq %rax, %rax
jne 0xbebcf
leaq 0x519cc(%rip), %rsi     # 0x110590
movq %r14, %rdi
callq 0xea6cb
movq %rax, %rbx
testq %rbx, %rbx
je 0xbebe3
movq %r14, %rdi
movq %rbx, %rsi
callq 0xf1717
movq %rax, 0x8(%r13)
cmpq $0x0, 0x8(%r13)
je 0xbebfe
leaq 0x7a5a0(%rip), %rsi     # 0x139191
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xe9226
movl (%r13), %eax
movl %eax, 0xc(%rsp)
cmpl $0x2, %eax
je 0xbec12
xorl %r15d, %r15d
xorl %ebx, %ebx
jmp 0xbec3c
movq 0x18(%r14), %rdi
movl $0x8, %esi
callq 0xef1ca
movq %rax, %rbx
leaq 0x7a57b(%rip), %rsi     # 0x1391a5
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xe9226
movl $0xa, %r15d
cmpl $0x2, 0xc(%rsp)
sete %al
testq %rbx, %rbx
setle %cl
testb %cl, %al
jne 0xbee63
movl $0x1, %r12d
xorl %ebp, %ebp
movq %r13, 0x10(%rsp)
movq %rbx, 0x40(%rsp)
movq 0x18(%r14), %rdi
movq 0x18(%rdi), %rax
cmpq %rax, %r15
jge 0xbee63
cmpl $0x3, (%r13)
jne 0xbecef
movq %r15, %rsi
callq 0xef0d5
cmpb $0xb, %al
jne 0xbecfb
movq 0x18(%r14), %rdi
leaq 0x1(%r15), %rsi
callq 0xef0d5
movl %eax, %ebx
movq 0x18(%r14), %rdi
leaq 0x2(%r15), %rsi
callq 0xef0d5
testb %al, %al
sete %cl
testb %bl, %bl
sete %dl
orb %cl, %dl
jne 0xbecfb
movzbl %bl, %r9d
movzbl %al, %r8d
leal 0x7(%r8), %edx
shrl $0x3, %edx
movq %rdx, %rbx
imulq %r9, %rbx
leaq (%rbx,%r15), %rax
addq $0x5, %rax
movq 0x18(%r14), %rcx
cmpq 0x18(%rcx), %rax
jg 0xbecfb
movq %rdx, 0x28(%rsp)
addq $0x5, %rbx
movl $0x4, %eax
movq %rax, 0x20(%rsp)
jmp 0xbed29
leaq 0x23c(%r15), %rcx
cmpq %rax, %rcx
jle 0xbed05
xorl %ebx, %ebx
xorl %r13d, %r13d
jmp 0xbee23
movl $0x58, %r8d
movl $0x34, %r9d
movl $0x23c, %ebx            # imm = 0x23C
movl $0xb, %eax
movq %rax, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
leal -0x1(%r12), %edx
movq %r14, %rdi
leaq 0x7a4cc(%rip), %rsi     # 0x139204
movl %r15d, %ecx
movq %r8, 0x30(%rsp)
movq %r9, 0x38(%rsp)
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq %r14, %rdi
callq 0xea9a9
movq %rax, %r13
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0xbede8
leaq 0x10(%rbp), %rcx
cmpq %rcx, 0x18(%rax)
jl 0xbede8
movq %r14, %rdi
callq 0xf6870
movq %rax, %rcx
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movl $0x10, %edx
movq %rbp, %rsi
movl $0x1, %r8d
movl $0x1, %r9d
callq 0xf01b0
movq 0x18(%rsp), %rdi
callq 0xf74bd
movq %r14, %rdi
leaq 0x637b1(%rip), %rsi     # 0x122573
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0xea9e4
movq 0x18(%rsp), %rdi
callq 0xf6bb0
movq 0x18(%r14), %rdi
movq 0x20(%rsp), %rsi
addq %r15, %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x28(%rsp), %r8
movl $0x1, %r9d
pushq $0x0
pushq %r13
callq 0xf30d9
addq $0x10, %rsp
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r14, %rdi
movq %r13, %rsi
callq 0xea9b3
testq %rbx, %rbx
jle 0xbee5e
cmpl $0x2, 0xc(%rsp)
setne %al
addq %rbx, %r15
cmpq 0x40(%rsp), %r12
setl %cl
orb %al, %cl
incq %r12
addq $0x10, %rbp
testb %cl, %cl
movq 0x10(%rsp), %r13
jne 0xbec64
jmp 0xbee63
movq 0x10(%rsp), %r13
cmpl $0x2, 0xc(%rsp)
jne 0xbee8f
movq 0x18(%r14), %rax
movq 0x18(%rax), %rdx
subq %r15, %rdx
cmpq $0x80, %rdx
jl 0xbee8f
leaq 0x7a335(%rip), %rsi     # 0x1391ba
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9b27
movq 0x8(%r13), %rdi
callq 0xf0b13
movq $0x0, 0x8(%r13)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop