// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq %rsi, (%rsp)
movq %rdi, %r15
leaq 0x7598d(%rip), %rsi     # 0x12c213
callq 0xdfa87
testq %rax, %rax
jne 0xb68a8
leaq 0x4cce5(%rip), %rsi     # 0x10357c
movq %r15, %rdi
callq 0xdfa87
testq %rax, %rax
je 0xb6b8b
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0xe600b
movq (%rsp), %rcx
movq %rax, 0x8(%rcx)
testq %rax, %rax
je 0xb68d7
leaq 0x75952(%rip), %rsi     # 0x12c21c
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xde896
movq (%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
cmpl $0x2, %eax
je 0xb68f4
xorl %r12d, %r12d
movq $0x0, 0x20(%rsp)
jmp 0xb691c
movq 0x18(%r15), %rdi
pushq $0x8
popq %rsi
callq 0xe3fa3
leaq 0x75929(%rip), %rsi     # 0x12c230
movq %r15, %rdi
movq %rax, 0x20(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
pushq $0xa
popq %r12
pushq $0x1
popq %r14
movq $0x0, 0x18(%rsp)
xorl %ebp, %ebp
movq %r15, 0x28(%rsp)
cmpl $0x2, 0xc(%rsp)
setne %al
cmpq 0x20(%rsp), %rbp
setl %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xb6b45
movq 0x18(%r15), %rdi
movq 0x18(%rdi), %rax
cmpq %rax, %r12
jge 0xb6b3e
movq (%rsp), %rcx
cmpl $0x3, (%rcx)
jne 0xb69d3
movq %r12, %rsi
callq 0xe3eb4
cmpb $0xb, %al
jne 0xb69c9
movq 0x18(%r15), %rdi
leaq 0x1(%r12), %rsi
callq 0xe3eb4
movl %eax, %ebx
movq 0x18(%r15), %rdi
leaq 0x2(%r12), %rsi
callq 0xe3eb4
testb %al, %al
sete %cl
testb %bl, %bl
sete %dl
orb %cl, %dl
jne 0xb69c9
movzbl %bl, %r9d
movzbl %al, %r8d
leal 0x7(%r8), %edi
shrl $0x3, %edi
movq %rdi, %rsi
imulq %r9, %rsi
leaq (%rsi,%r12), %rax
addq $0x5, %rax
movq 0x18(%r15), %rcx
cmpq 0x18(%rcx), %rax
jle 0xb6b31
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0xb6b0b
leaq 0x23c(%r12), %rcx
movl $0x23c, %esi            # imm = 0x23C
pushq $0xb
popq %rdi
movl $0x0, %r15d
pushq $0x34
popq %r9
pushq $0x58
popq %r8
movl $0x0, %r13d
movl $0x0, %ebx
cmpq %rax, %rcx
jg 0xb6b0b
movq %r15, 0x30(%rsp)
movq %rdi, 0x48(%rsp)
movq %rsi, 0x50(%rsp)
movq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x7586c(%rip), %rsi     # 0x12c28f
movl %ebp, %edx
movl %r12d, %ecx
movq %r8, 0x38(%rsp)
movq %r9, 0x40(%rsp)
xorl %eax, %eax
callq 0xde896
movq %r15, %rdi
movl %r14d, %r13d
movl %r14d, %esi
callq 0xdeba7
movq %r15, %rdi
callq 0xdfd1a
movq %rax, %rbx
movq (%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0xb6ad3
movq 0x18(%rsp), %rcx
addq $0x10, %rcx
cmpq %rcx, 0x18(%rax)
jl 0xb6ad3
movq %r15, %rdi
callq 0xeac74
movq %rax, %rcx
movq %rax, 0x10(%rsp)
movq (%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x18(%rsp), %rsi
pushq $0x10
popq %rdx
movl %r13d, %r8d
movl %r13d, %r9d
callq 0xe4c9a
movq 0x10(%rsp), %rdi
callq 0xeb7e4
movq %r15, %rdi
leaq 0x5eb0e(%rip), %rsi     # 0x1155bb
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0xdfd55
movq 0x10(%rsp), %rdi
callq 0xeaf3c
movq 0x18(%r15), %rdi
movq 0x30(%rsp), %rsi
addq %r12, %rsi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movl %r13d, %r9d
pushq $0x0
pushq %rbx
callq 0xe7804
popq %rax
popq %rcx
movq %r15, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x50(%rsp), %r13
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0xdfd24
testq %r13, %r13
je 0xb6b3e
addq %r13, %r12
incq %rbp
addq $0x10, 0x18(%rsp)
jmp 0xb6930
addq $0x5, %rsi
pushq $0x4
popq %r15
jmp 0xb6a05
cmpl $0x2, 0xc(%rsp)
jne 0xb6b6a
movq 0x18(%r15), %rax
movq 0x18(%rax), %rdx
subq %r12, %rdx
cmpq $0x80, %rdx
jl 0xb6b6a
leaq 0x756e5(%rip), %rsi     # 0x12c245
movq %r15, %rdi
xorl %eax, %eax
callq 0xdf05a
movq (%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0xe5591
andq $0x0, 0x8(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
movq 0x8(%rax), %rax
xorl %ebx, %ebx
jmp 0xb68be
nop