// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movl $0x430, %esi            # imm = 0x430
callq 0xdecaf
movq %rax, %r12
movabsq $0x6300000063, %rax     # imm = 0x6300000063
movq %rax, 0x4(%r12)
decl %r14d
cmpl $0x3, %r14d
ja 0x900c6
pushq $0x65
popq %rax
leaq 0x92e42(%rip), %rcx     # 0x122ee8
movslq (%rcx,%r14,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
pushq $0x6e
jmp 0x900b5
pushq $0x70
popq %rax
jmp 0x900c1
movl $0x78, 0x4(%r12)
movl %eax, 0x8(%r12)
leaq 0x92ee0(%rip), %rsi     # 0x122fad
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x900df
movsbl (%rax), %ebp
jmp 0x900e1
xorl %ebp, %ebp
leaq 0x92ecf(%rip), %rsi     # 0x122fb7
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x90117
movzbl (%rax), %eax
cmpl $0x68, %eax
je 0x9010f
cmpl $0x6c, %eax
je 0x9010b
cmpl $0x6d, %eax
jne 0x90117
pushq $0x65
jmp 0x90111
pushq $0x6e
jmp 0x90111
pushq $0x70
popq %rax
movl %eax, 0x8(%r12)
cmpl $0x6c, %ebp
je 0x90125
cmpl $0x6d, %ebp
jne 0x9012d
pushq $0x78
jmp 0x90127
pushq $0x64
popq %rax
movl %eax, 0x4(%r12)
movq 0x18(%rbx), %rdi
leaq 0x1e(%rsp), %r14
pushq $0xa
popq %r15
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0xe3cb7
leaq 0x92edc(%rip), %rsi     # 0x12302a
movq %r14, %rdi
movq %r15, %rdx
callq 0x18230
testl %eax, %eax
je 0x9019e
leaq 0x1e(%rsp), %rdi
callq 0xe404a
cmpl $0x6071963, %eax        # imm = 0x6071963
je 0x90253
cmpl $0x19861987, %eax       # imm = 0x19861987
jne 0x90274
leaq 0x92e4f(%rip), %rsi     # 0x122fd3
movq %rbx, %rdi
callq 0xe07f7
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x905ae
jmp 0x90594
movb $0x1, (%r12)
movq 0x18(%rbx), %rdi
pushq $0xa
popq %rsi
callq 0xe404f
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x9028a
leaq 0x92e06(%rip), %rsi     # 0x122fca
movq %rbx, %rdi
callq 0xe07f7
leaq 0x92e73(%rip), %rsi     # 0x123046
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl 0x10(%r12), %edx
leaq 0x92e61(%rip), %rsi     # 0x123057
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0xe
popq %rsi
callq 0xe404f
movq %rax, %rdx
shrq $0x18, %rdx
movb %dl, 0x18(%r12)
andl $0xffffff, %eax         # imm = 0xFFFFFF
movq %rax, 0x20(%r12)
movzbl %dl, %eax
leaq 0x8ecb5(%rip), %rcx     # 0x11eee1
leal -0x81(%rax), %esi
cmpl $0x4, %esi
ja 0x902b1
leaq 0x92cba(%rip), %rax     # 0x122ef8
movslq (%rax,%rsi,4), %rsi
addq %rax, %rsi
jmpq *%rsi
leaq 0x9cde3(%rip), %rcx     # 0x12d031
jmp 0x902e6
leaq 0x92d8a(%rip), %rsi     # 0x122fe4
movq %rbx, %rdi
callq 0xe07f7
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x90a20
jmp 0x90594
leaq 0x92d8d(%rip), %rsi     # 0x123008
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x90594
leaq 0x92d30(%rip), %rsi     # 0x122fc1
movq %rbx, %rdi
callq 0xe07f7
leaq 0x92d95(%rip), %rsi     # 0x123035
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
jmp 0x90594
cmpl $0x2, %eax
je 0x902df
cmpl $0x1, %eax
jne 0x902e6
leaq 0x92da5(%rip), %rcx     # 0x123067
jmp 0x902e6
leaq 0x92dac(%rip), %rcx     # 0x123077
jmp 0x902e6
leaq 0x92d98(%rip), %rcx     # 0x12306c
jmp 0x902e6
leaq 0x81834(%rip), %rcx     # 0x111b11
jmp 0x902e6
leaq 0x92ddf(%rip), %rcx     # 0x1230c5
movzbl %dl, %edx
leaq 0x92d94(%rip), %rsi     # 0x123084
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x20(%r12), %edx
leaq 0x92d95(%rip), %rsi     # 0x12309b
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
cmpb $-0x7f, 0x18(%r12)
jne 0x90594
leaq 0x92d7b(%rip), %rsi     # 0x1230a9
pushq $0x12
popq %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
pushq $0x12
popq %rsi
callq 0xe404f
movl %eax, 0x28(%r12)
cmpl $0x4d414553, %eax       # imm = 0x4D414553
je 0x903a7
cmpl $0x13490157, %eax       # imm = 0x13490157
je 0x90383
cmpl $0x19861987, %eax       # imm = 0x19861987
je 0x90395
cmpl $0x28091960, %eax       # imm = 0x28091960
je 0x9038c
cmpl $0x6071963, %eax        # imm = 0x6071963
jne 0x9039e
leaq 0x92d3d(%rip), %rcx     # 0x1230be
jmp 0x903ae
leaq 0x92d42(%rip), %rcx     # 0x1230cc
jmp 0x903ae
leaq 0x92d44(%rip), %rcx     # 0x1230d7
jmp 0x903ae
leaq 0x92d45(%rip), %rcx     # 0x1230e1
jmp 0x903ae
leaq 0x8eb3c(%rip), %rcx     # 0x11eee1
jmp 0x903ae
leaq 0x92d3f(%rip), %rcx     # 0x1230ed
leaq 0x92d41(%rip), %rsi     # 0x1230f6
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movl 0x28(%r12), %eax
cmpl $0x6071963, %eax        # imm = 0x6071963
movq %r12, (%rsp)
je 0x90577
cmpl $0x28091960, %eax       # imm = 0x28091960
je 0x903fb
cmpl $0x19861987, %eax       # imm = 0x19861987
jne 0x90585
pushq $0x12
popq %rdx
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x905ae
jmp 0x90585
movq 0x18(%rbx), %rdi
pushq $0x16
popq %rsi
callq 0xe3f46
movq %rax, %r15
leaq 0x92cff(%rip), %rsi     # 0x123110
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
testq %r15, %r15
cmovleq %r14, %r15
movq %r15, 0x10(%rsp)
pushq $0x24
popq %r12
xorl %eax, %eax
cmpq %rax, 0x10(%rsp)
je 0x90585
leal -0xc(%r12), %ecx
movq %rbx, %rdi
leaq 0x92cd7(%rip), %rsi     # 0x123124
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%rbx), %rdi
leaq -0x8(%r12), %rsi
callq 0xe3f46
movq %rbx, %rdi
leaq 0x92cb1(%rip), %rsi     # 0x123134
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq -0x6(%r12), %rsi
callq 0xe3f46
movq %rax, %r14
movq 0x18(%rbx), %rdi
leaq -0x4(%r12), %rsi
callq 0xe3f46
movq %rax, %r15
movq %rbx, %rdi
leaq 0x92c90(%rip), %rsi     # 0x123148
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0xde896
testq %r15, %r15
setne %al
testq %r14, %r14
sete %cl
orb %al, %cl
movzbl %cl, %r14d
movq %rbx, %rdi
pushq $0x10
popq %r13
movq %r13, %rsi
movq %r13, %rdx
pushq $0x2
popq %rcx
callq 0xe7437
movq %rax, %r15
movq %rbx, %rdi
movq %r13, %rsi
movq %r13, %rdx
movl %ebp, %ecx
callq 0xe7437
movq %rax, %r13
leaq -0x2(%r12), %rsi
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rbp
movq %rbp, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xe77b7
movq 0x18(%rbx), %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movl %r14d, %r8d
callq 0xe77b7
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xe83f8
movq %r15, %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
callq 0xe70b7
movq %r15, %rdi
callq 0xe7084
movq %r13, %rdi
callq 0xe7084
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x8(%rsp), %rax
incq %rax
addq $0x54, %r12
jmp 0x90433
pushq $0x12
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x90a20
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq (%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0xded32
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq