// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mbk.c
// Function: do_sprite_bank
static void do_sprite_bank(deark *c, lctx *d, i64 pos)
{
	i64 res;
	i64 paramoffs_raw[3]; // One for each resolution: low, med, hi
	i64 paramoffs[3];
	i64 nsprites[3];
	i64 nsprites_total = 0;
	i64 pal_pos;

	for(res=0; res<3; res++) {
		paramoffs_raw[res] = de_getu32be(pos+4+4*res);
		// paramoffs is relative to the first position after the ID.
		paramoffs[res] = pos + 4 + paramoffs_raw[res];
		nsprites[res] = de_getu16be(pos+16+2*res);
		de_dbg(c, "%s-res sprites: %d, param blk offset: %d ("DE_CHAR_RIGHTARROW" %d)", sprite_res_name[res],
			(int)nsprites[res], (int)paramoffs_raw[res], (int)paramoffs[res]);
		nsprites_total += nsprites[res];
	}

	// TODO: What's the right way to calculate the position of the palette?
	pal_pos = pos + 22 + (nsprites_total)*8;
	read_sprite_palette(c, d, pal_pos);

	for(res=0; res<3; res++) {
		if(nsprites[res]<1) continue;
		if(paramoffs[res]>(c->infile->len-8)) continue;
		do_sprite_param_blocks(c, d, res, nsprites[res], paramoffs[res]);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x20(%rbp)
cmpq $0x3, -0x20(%rbp)
jge 0xdc132
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
movq -0x20(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x165470
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, -0x40(%rbp,%rax,8)
movq -0x18(%rbp), %rcx
addq $0x4, %rcx
movq -0x20(%rbp), %rax
addq -0x40(%rbp,%rax,8), %rcx
movq -0x20(%rbp), %rax
movq %rcx, -0x60(%rbp,%rax,8)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
movq -0x20(%rbp), %rax
shlq %rax
addq %rax, %rsi
callq 0x1651d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, -0x80(%rbp,%rax,8)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rcx
leaq 0x14976b(%rip), %rax    # 0x225840
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq -0x80(%rbp,%rax,8), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rax
movl %eax, %r8d
movq -0x20(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movl %eax, %r9d
leaq 0xdfdea(%rip), %rsi     # 0x1bbeed
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
movq -0x80(%rbp,%rax,8), %rax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xdc04a
movq -0x18(%rbp), %rax
addq $0x16, %rax
movq -0x88(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x90(%rbp), %rdx
callq 0xdccf0
movq $0x0, -0x20(%rbp)
cmpq $0x3, -0x20(%rbp)
jge 0xdc1d1
movq -0x20(%rbp), %rax
cmpq $0x1, -0x80(%rbp,%rax,8)
jge 0xdc180
jmp 0xdc1c3
movq -0x20(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
subq $0x8, %rcx
cmpq %rcx, %rax
jle 0xdc1a0
jmp 0xdc1c3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x20(%rbp), %rax
movq -0x80(%rbp,%rax,8), %rcx
movq -0x20(%rbp), %rax
movq -0x60(%rbp,%rax,8), %r8
callq 0xdcdd0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xdc16b
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)