// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/abk.c
// Function: de_run_abk
static void de_run_abk(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 bytesused = 0;
	u8 is_raw_picture = 0;

	d = de_malloc(c, sizeof(lctx));
	d->opt_allownopal = de_get_ext_option_bool(c, "abk:allownopal", -1);

	d->sig1 = (UI)de_getu32be(0);

	if(d->sig1==CODE_AmBk) {
		de_declare_fmt(c, "AMOS Memory Bank");
	}
	else if(d->sig1==CODE_AmSp) {
		de_declare_fmt(c, "AMOS Sprite Bank");
	}
	else if(d->sig1==CODE_AmIc) {
		de_declare_fmt(c, "AMOS Icon Bank");
	}
	else if(d->sig1==CODE_AmBs) {
		de_declare_fmt(c, "AMOS AmBs format");
	}
	else if(is_scr_hdr_id(d->sig1)) {
		is_raw_picture = 1;
		de_declare_fmt(c, "AMOS picture, with screen header");
	}
	else if(d->sig1==AMOS_PIC_HDR_ID) {
		is_raw_picture = 1;
		de_declare_fmt(c, "AMOS picture, no screen header");
	}
	else {
		de_err(c, "Unsupported format");
		goto done;
	}

	if(is_raw_picture) {
		do_amos_picture_file(c, d);
	}
	else if(d->sig1==CODE_AmBk ||d->sig1==CODE_AmSp || d->sig1==CODE_AmIc) {
		do_read_bank(c, d, 0, &bytesused);
	}
	else if(d->sig1==CODE_AmBs) {
		do_read_AmBs(c, d);
	}

done:
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
pushq $0x8
popq %rsi
callq 0xdecaf
movq %rax, %r14
leaq 0xea878(%rip), %rsi     # 0x103db3
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0xdfae5
movl %eax, 0x4(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe404f
movl %eax, (%r14)
leaq 0xea8a5(%rip), %rsi     # 0x103e04
cmpl $0x31990, %eax          # imm = 0x31990
je 0x19611
cmpl $0x6071963, %eax        # imm = 0x6071963
je 0x1960a
cmpl $0x12030090, %eax       # imm = 0x12030090
je 0x19611
cmpl $0x12031990, %eax       # imm = 0x12031990
je 0x19611
cmpl $0x416d426b, %eax       # imm = 0x416D426B
je 0x195b4
cmpl $0x416d4273, %eax       # imm = 0x416D4273
je 0x195c6
cmpl $0x416d4963, %eax       # imm = 0x416D4963
je 0x195bd
cmpl $0x416d5370, %eax       # imm = 0x416D5370
jne 0x19675
leaq 0xea821(%rip), %rsi     # 0x103dd3
jmp 0x195cd
leaq 0xea807(%rip), %rsi     # 0x103dc2
jmp 0x195cd
leaq 0xea820(%rip), %rsi     # 0x103de4
jmp 0x195cd
leaq 0xea826(%rip), %rsi     # 0x103df3
movq %rbx, %rdi
callq 0xe07f7
movl (%r14), %eax
cmpl $0x416d426b, %eax       # imm = 0x416D426B
je 0x195f8
cmpl $0x416d4273, %eax       # imm = 0x416D4273
je 0x19688
cmpl $0x416d5370, %eax       # imm = 0x416D5370
je 0x195f8
cmpl $0x416d4963, %eax       # imm = 0x416D4963
jne 0x1965c
movq %rsp, %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x199a4
jmp 0x1965c
leaq 0xea814(%rip), %rsi     # 0x103e25
movq %rbx, %rdi
callq 0xe07f7
movl $0x4b8, %esi            # imm = 0x4B8
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
andq $0x0, 0x48(%rax)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xe6248
movq %rax, 0x50(%r15)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x19c5d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1a4d9
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xded32
leaq 0xea7c8(%rip), %rsi     # 0x103e44
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x1965c
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0xe3f46
movq %rax, %r15
leaq 0xeab17(%rip), %rsi     # 0x1041b5
xorl %r12d, %r12d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
testq %r15, %r15
cmovleq %r12, %r15
pushq $0x6
popq %r12
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x1965c
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jge 0x1965c
movq %rbx, %rdi
leaq 0xeaaf4(%rip), %rsi     # 0x1041c9
movl %r13d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0xde896
andq $0x0, (%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %rsp, %rcx
callq 0x199a4
movl %eax, %ebp
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
testl %ebp, %ebp
je 0x1965c
movq (%rsp), %rax
testq %rax, %rax
jle 0x1965c
addq %rax, %r12
incq %r13
jmp 0x196bc