// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movq %rdi, %r13
leaq 0x7b639(%rip), %rsi     # 0x139513
callq 0xe9b74
testq %rax, %rax
jne 0xbdefc
leaq 0x52691(%rip), %rsi     # 0x11057c
movq %r13, %rdi
callq 0xe9b74
testq %rax, %rax
je 0xbe1ea
movq %rax, %rbx
movq %r13, %rdi
movq %rax, %rsi
callq 0xf1114
movq 0x8(%rsp), %rcx
movq %rax, 0x8(%rcx)
testq %rax, %rax
je 0xbdf2c
leaq 0x7b5fd(%rip), %rsi     # 0x13951c
movq %r13, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
cmpl $0x2, %eax
je 0xbdf4a
movq $0x0, 0x18(%rsp)
xorl %r15d, %r15d
jmp 0xbdf8b
sete %bl
movq 0x18(%r13), %rdi
movl $0x8, %esi
callq 0xeebc8
movq %rax, %r15
leaq 0x7b5cb(%rip), %rsi     # 0x139530
movq %r13, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r15, 0x18(%rsp)
testq %r15, %r15
setle %al
movl $0xa, %r15d
testb %al, %bl
jne 0xbe1a0
movl $0x1, %ebp
xorl %r14d, %r14d
movq 0x18(%r13), %rdi
movq 0x18(%rdi), %rax
cmpq %rax, %r15
jge 0xbe199
movq 0x8(%rsp), %rcx
cmpl $0x3, (%rcx)
jne 0xbe027
movq %r15, %rsi
callq 0xeead3
cmpb $0xb, %al
jne 0xbe18f
movq 0x18(%r13), %rdi
leaq 0x1(%r15), %rsi
callq 0xeead3
movl %eax, %ebx
movq 0x18(%r13), %rdi
leaq 0x2(%r15), %rsi
callq 0xeead3
testb %al, %al
je 0xbe18f
testb %bl, %bl
je 0xbe18f
movzbl %bl, %r9d
movzbl %al, %r8d
leal 0x7(%r8), %r12d
shrl $0x3, %r12d
movq %r12, %rbx
imulq %r9, %rbx
leaq (%rbx,%r15), %rax
addq $0x5, %rax
movq 0x18(%r13), %rcx
cmpq 0x18(%rcx), %rax
jg 0xbe18f
addq $0x5, %rbx
movl $0x4, %eax
movq %rax, 0x20(%rsp)
jmp 0xbe057
leaq 0x23c(%r15), %rcx
cmpq %rax, %rcx
jg 0xbe18f
movl $0x58, %r8d
movl $0x34, %r9d
movl $0x23c, %ebx            # imm = 0x23C
movl $0xb, %r12d
movq $0x0, 0x20(%rsp)
movq %rbp, 0x40(%rsp)
leal -0x1(%rbp), %edx
movq %r13, %rdi
leaq 0x7b526(%rip), %rsi     # 0x13958f
movl %r15d, %ecx
movq %r8, 0x30(%rsp)
movq %r9, 0x38(%rsp)
xorl %eax, %eax
callq 0xe8617
movq %r13, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %r13, %rdi
callq 0xea504
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0xbe115
leaq 0x10(%r14), %rcx
cmpq %rcx, 0x18(%rax)
jl 0xbe115
movq %r13, %rdi
callq 0xf6410
movq %rax, %rbp
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movl $0x10, %edx
movq %r14, %rsi
movq %rbp, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0xefbd7
movq %rbp, %rdi
callq 0xf705c
movq %r13, %rdi
leaq 0x6468a(%rip), %rsi     # 0x12277b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0xea53f
movq %rbp, %rdi
callq 0xf6753
cmpl $0x2, 0x14(%rsp)
movq 0x28(%rsp), %rbp
setne 0x7(%rsp)
movq 0x18(%r13), %rdi
movq 0x20(%rsp), %rsi
addq %r15, %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %r12, %r8
movl $0x1, %r9d
pushq $0x0
pushq %rbp
callq 0xf2a98
addq $0x10, %rsp
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %r13, %rdi
movq %rbp, %rsi
callq 0xea50e
addq %rbx, %r15
movq 0x40(%rsp), %rcx
cmpq 0x18(%rsp), %rcx
setl %al
orb 0x7(%rsp), %al
movq %rcx, %rbp
incq %rbp
addq $0x10, %r14
testb %al, %al
jne 0xbdf93
jmp 0xbe1a0
movq %r13, %rdi
xorl %esi, %esi
callq 0xea50e
cmpl $0x2, 0x14(%rsp)
jne 0xbe1c5
movq 0x18(%r13), %rax
movq 0x18(%rax), %rdx
subq %r15, %rdx
cmpq $0x80, %rdx
jl 0xbe1c5
leaq 0x7b38a(%rip), %rsi     # 0x139545
movq %r13, %rdi
xorl %eax, %eax
callq 0xe8faa
movq 0x8(%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0xf052b
movq $0x0, 0x8(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
xorl %ebx, %ebx
jmp 0xbdf13
nop