// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mbk.c
// Function: run_mbk_mbs_internal
static void run_mbk_mbs_internal(deark *c, de_module_params *mparams, UI mode)
{
	lctx *d = NULL;
	u32 id;
	const char *s;
	char opt_res0_c = '\0';
	char opt_res1_c = '\0';
	u8 buf[10];

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

	d->imgtype_of_res1 = PKPIC_IMGTYPE_UNKNOWN;
	d->imgtype_of_res0 = PKPIC_IMGTYPE_UNKNOWN;

	if(mode==1) { // .pp1 extension
		d->imgtype_of_res1 = PKPIC_IMGTYPE_PP1;
	}
	else if(mode==2) {
		d->imgtype_of_res1 = PKPIC_IMGTYPE_MED;
	}
	else if(mode==3) {
		d->imgtype_of_res1 = PKPIC_IMGTYPE_PP3;
	}
	else if(mode==4) { // .daj extension
		d->imgtype_of_res0 = PKPIC_IMGTYPE_M4P;
		d->imgtype_of_res1 = PKPIC_IMGTYPE_MED;
	}

	s = de_get_ext_option(c, "stos:res0");
	if(s) opt_res0_c = s[0];
	s = de_get_ext_option(c, "stos:res1");
	if(s) opt_res1_c = s[0];

	if(opt_res1_c=='l') {
		d->imgtype_of_res1 = PKPIC_IMGTYPE_PP1;
	}
	else if(opt_res1_c=='m') {
		d->imgtype_of_res1 = PKPIC_IMGTYPE_MED;
	}
	else if(opt_res1_c=='h') {
		d->imgtype_of_res1 = PKPIC_IMGTYPE_PP3;
	}

	if(opt_res0_c=='l') {
		d->imgtype_of_res0 = PKPIC_IMGTYPE_LOW;
	}
	else if(opt_res0_c=='m') {
		d->imgtype_of_res0 = PKPIC_IMGTYPE_M4P;
	}

	de_read(buf, 0, sizeof(buf));
	if(!de_memcmp(buf, g_lion_sig, 10)) {
		d->is_container_fmt = 1;
		d->banknum = de_getu32be(10);
		if(d->banknum==0) {
			de_declare_fmt(c, "STOS MBS");
			do_mbs(c, d);
		}
		else {
			de_declare_fmt(c, "STOS MBK");
			do_mbk(c, d);
		}
	}
	else {
		id = (u32)de_getu32be_direct(buf);

		if(id==BANKID_SPRITE) {
			de_declare_fmt(c, "STOS Sprite Bank");
			do_sprite_bank(c, d, 0);
		}
		else if(id==BANKID_PKSCREEN) {
			de_declare_fmt(c, "STOS Packed Screen / Picture Packer");
			do_pkscreen_bank(c, d, 0);
		}
		else {
			de_err(c, "Not a (supported) STOS/MBK format");
		}
	}

	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movb $0x0, -0x31(%rbp)
movb $0x0, -0x32(%rbp)
movq -0x8(%rbp), %rdi
movl $0x430, %esi            # imm = 0x430
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl $0x63, 0x8(%rax)
movq -0x20(%rbp), %rax
movl $0x63, 0x4(%rax)
cmpl $0x1, -0x14(%rbp)
jne 0xdbbfe
movq -0x20(%rbp), %rax
movl $0x6e, 0x8(%rax)
jmp 0xdbc46
cmpl $0x2, -0x14(%rbp)
jne 0xdbc11
movq -0x20(%rbp), %rax
movl $0x65, 0x8(%rax)
jmp 0xdbc44
cmpl $0x3, -0x14(%rbp)
jne 0xdbc24
movq -0x20(%rbp), %rax
movl $0x70, 0x8(%rax)
jmp 0xdbc42
cmpl $0x4, -0x14(%rbp)
jne 0xdbc40
movq -0x20(%rbp), %rax
movl $0x78, 0x4(%rax)
movq -0x20(%rbp), %rax
movl $0x65, 0x8(%rax)
jmp 0xdbc42
jmp 0xdbc44
jmp 0xdbc46
movq -0x8(%rbp), %rdi
leaq 0xe00e4(%rip), %rsi     # 0x1bbd35
callq 0x15cb30
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xdbc6a
movq -0x30(%rbp), %rax
movb (%rax), %al
movb %al, -0x31(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xe00ca(%rip), %rsi     # 0x1bbd3f
callq 0x15cb30
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xdbc8e
movq -0x30(%rbp), %rax
movb (%rax), %al
movb %al, -0x32(%rbp)
movsbl -0x32(%rbp), %eax
cmpl $0x6c, %eax
jne 0xdbca4
movq -0x20(%rbp), %rax
movl $0x6e, 0x8(%rax)
jmp 0xdbcd2
movsbl -0x32(%rbp), %eax
cmpl $0x6d, %eax
jne 0xdbcba
movq -0x20(%rbp), %rax
movl $0x65, 0x8(%rax)
jmp 0xdbcd0
movsbl -0x32(%rbp), %eax
cmpl $0x68, %eax
jne 0xdbcce
movq -0x20(%rbp), %rax
movl $0x70, 0x8(%rax)
jmp 0xdbcd0
jmp 0xdbcd2
movsbl -0x31(%rbp), %eax
cmpl $0x6c, %eax
jne 0xdbce8
movq -0x20(%rbp), %rax
movl $0x64, 0x4(%rax)
jmp 0xdbcfe
movsbl -0x31(%rbp), %eax
cmpl $0x6d, %eax
jne 0xdbcfc
movq -0x20(%rbp), %rax
movl $0x78, 0x4(%rax)
jmp 0xdbcfe
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x3c(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0xa, %ecx
callq 0x164d10
leaq -0x3c(%rbp), %rdi
movq 0x149b0d(%rip), %rsi    # 0x225830
movl $0xa, %edx
callq 0x19170
cmpl $0x0, %eax
jne 0xdbd9f
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xa, %esi
callq 0x165470
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xdbd80
movq -0x8(%rbp), %rdi
leaq 0xdffdd(%rip), %rsi     # 0x1bbd49
callq 0x15e380
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xdbe30
jmp 0xdbd9d
movq -0x8(%rbp), %rdi
leaq 0xdffc7(%rip), %rsi     # 0x1bbd52
callq 0x15e380
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xdbe70
jmp 0xdbe19
leaq -0x3c(%rbp), %rdi
callq 0x165430
movl %eax, -0x24(%rbp)
cmpl $0x19861987, -0x24(%rbp) # imm = 0x19861987
jne 0xdbdd7
movq -0x8(%rbp), %rdi
leaq 0xdff9c(%rip), %rsi     # 0x1bbd5b
callq 0x15e380
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xdc020
jmp 0xdbe17
cmpl $0x6071963, -0x24(%rbp) # imm = 0x6071963
jne 0xdbe03
movq -0x8(%rbp), %rdi
leaq 0xdff81(%rip), %rsi     # 0x1bbd6c
callq 0x15e380
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xdc1e0
jmp 0xdbe15
movq -0x8(%rbp), %rdi
leaq 0xdff82(%rip), %rsi     # 0x1bbd90
movb $0x0, %al
callq 0x15bfb0
jmp 0xdbe17
jmp 0xdbe19
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)