// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/rosprite.c
// Function: de_run_rosprite
static void de_run_rosprite(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;
	i64 sprite_size;
	i64 first_sprite_offset_raw;
	i64 first_sprite_offset;
	i64 implied_file_size_raw;
	i64 implied_file_size;
	i64 k;
	i64 sprite_count = 0;

	d = de_malloc(c, sizeof(lctx));

	pos = 0;
	d->num_images = de_getu32le_p(&pos);
	de_dbg(c, "number of images: %"I64_FMT, d->num_images);
	first_sprite_offset_raw = de_getu32le_p(&pos);
	first_sprite_offset = first_sprite_offset_raw - 4;
	de_dbg(c, "first sprite offset: %"I64_FMT" ("DE_CHAR_RIGHTARROW"%"I64_FMT")",
		first_sprite_offset_raw, first_sprite_offset);
	implied_file_size_raw = de_getu32le_p(&pos);
	implied_file_size = implied_file_size_raw - 4;
	de_dbg(c, "reported file size: %"I64_FMT" ("DE_CHAR_RIGHTARROW"%"I64_FMT")",
		implied_file_size_raw, implied_file_size);
	if(implied_file_size != c->infile->len) {
		de_warn(c, "Reported and actual file sizes differ "
			"(%"I64_FMT", %"I64_FMT")", implied_file_size, c->infile->len);
	}

	pos = first_sprite_offset;
	for(k=0; k<d->num_images; k++) {
		if(pos>=c->infile->len) goto done;
		sprite_size = de_getu32le(pos);
		de_dbg(c, "image #%d at %"I64_FMT", size=%"I64_FMT, (int)k, pos, sprite_size);
		if(sprite_size<1) goto done;
		// We intentionally allow sprite_size to be set wrong, because
		// such files exist, and we don't need it for *this* sprite.
		de_dbg_indent(c, 1);
		do_sprite(c, d, k, pos, sprite_size);
		sprite_count++;
		de_dbg_indent(c, -1);
		if(sprite_size<40) goto done;
		pos += sprite_size;
	}

done:
	if(sprite_count < d->num_images) {
		de_warn(c, "Expected %"I64_FMT" images, only found %"I64_FMT,
			d->num_images, sprite_count);
	}
	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl $0x8, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
leaq 0x87702(%rip), %rsi     # 0x1a8009
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
subq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0xa55c9(%rip), %rsi     # 0x1c5f0b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
subq $0x4, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
leaq 0xa55b0(%rip), %rsi     # 0x1c5f2d
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
je 0x1209b8
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
leaq 0xa559d(%rip), %rsi     # 0x1c5f4e
movb $0x0, %al
callq 0x15bc10
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x120a95
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x1209f0
jmp 0x120a97
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165540
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
leaq 0xa5561(%rip), %rsi     # 0x1c5f7f
movb $0x0, %al
callq 0x15b0d0
cmpq $0x1, -0x28(%rbp)
jge 0x120a2e
jmp 0x120a97
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x120c60
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpq $0x28, -0x28(%rbp)
jge 0x120a78
jmp 0x120a97
movq -0x28(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1209c8
jmp 0x120a97
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x120ac1
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movq -0x58(%rbp), %rcx
leaq 0xa54e0(%rip), %rsi     # 0x1c5f9a
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)