// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/abk.c
// Function: do_read_bank
static int do_read_bank(deark *c, lctx *d, i64 pos, i64 *bytesused)
{
	struct amosbank *bk = NULL;
	int ret;
	int retval = 0;

	bk = de_malloc(c, sizeof(struct amosbank));
	bk->f_offs = pos;
	bk->f = dbuf_open_input_subfile(c->infile, bk->f_offs, c->infile->len - bk->f_offs);

	dbuf_read_fourcc(bk->f, 0, &bk->banktype4cc, 4, 0x0);
	de_dbg(c, "bank type '%s'", bk->banktype4cc.id_dbgstr);

	switch(bk->banktype4cc.id) {
	case CODE_AmIc: bk->file_ext = "icon.abk"; break;
	case CODE_AmSp: bk->file_ext = "sprite.abk"; break;
	case CODE_AmBk: bk->file_ext = "AmBk.abk"; break;
	default: bk->file_ext = "abk";
	}

	if(bk->banktype4cc.id==CODE_AmIc || bk->banktype4cc.id==CODE_AmSp) {
		ret = do_read_sprite(c, d, bk);
		retval = ret;
		*bytesused = bk->bank_len;
	}
	else if(bk->banktype4cc.id==CODE_AmBk) {
		ret = do_read_AmBk(c, d, bk);
		retval = ret;
		*bytesused = bk->bank_len;
	}
	else {
		de_err(c, "Unsupported bank type: '%s'", bk->banktype4cc.id_sanitized_sz);
	}

	destroy_amosbank(c, bk);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x4b8, %esi            # imm = 0x4B8
callq 0x15b780
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
callq 0x1691b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x28(%rbp), %rdx
movq 0x50(%rdx), %rdi
xorl %r8d, %r8d
movl %r8d, -0x38(%rbp)
movl %r8d, %esi
movl $0x4, %ecx
callq 0x169860
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
addq $0x10, %rdx
leaq 0x1818ec(%rip), %rsi    # 0x19d09a
callq 0x15b0d0
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
subl $0x416d426b, %eax       # imm = 0x416D426B
je 0x1b800
jmp 0x1b7c6
movl -0x34(%rbp), %eax
subl $0x416d4963, %eax       # imm = 0x416D4963
je 0x1b7de
jmp 0x1b7d2
movl -0x34(%rbp), %eax
subl $0x416d5370, %eax       # imm = 0x416D5370
je 0x1b7ef
jmp 0x1b811
movq -0x28(%rbp), %rax
leaq 0x1818c0(%rip), %rcx    # 0x19d0a9
movq %rcx, 0x58(%rax)
jmp 0x1b820
movq -0x28(%rbp), %rax
leaq 0x1818b8(%rip), %rcx    # 0x19d0b2
movq %rcx, 0x58(%rax)
jmp 0x1b820
movq -0x28(%rbp), %rax
leaq 0x1818b2(%rip), %rcx    # 0x19d0bd
movq %rcx, 0x58(%rax)
jmp 0x1b820
movq -0x28(%rbp), %rax
leaq 0x181962(%rip), %rcx    # 0x19d17e
movq %rcx, 0x58(%rax)
movq -0x28(%rbp), %rax
cmpl $0x416d4963, 0x4(%rax)  # imm = 0x416D4963
je 0x1b83a
movq -0x28(%rbp), %rax
cmpl $0x416d5370, 0x4(%rax)  # imm = 0x416D5370
jne 0x1b865
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x1c9c0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1b8b9
movq -0x28(%rbp), %rax
cmpl $0x416d426b, 0x4(%rax)  # imm = 0x416D426B
jne 0x1b89d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x1caa0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1b8b7
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
addq $0x8, %rdx
leaq 0x181816(%rip), %rsi    # 0x19d0c6
movb $0x0, %al
callq 0x15bfb0
jmp 0x1b8b9
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x1bb40
movl -0x30(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop