// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movq -0x8(%rbp), %rdi
movl $0x8, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x181cbe(%rip), %rsi    # 0x19cdaf
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x15cbc0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165470
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x416d426b, (%rax)     # imm = 0x416D426B
jne 0x1b13e
movq -0x8(%rbp), %rdi
leaq 0x181c8a(%rip), %rsi    # 0x19cdbe
callq 0x15e380
jmp 0x1b204
movq -0x18(%rbp), %rax
cmpl $0x416d5370, (%rax)     # imm = 0x416D5370
jne 0x1b15f
movq -0x8(%rbp), %rdi
leaq 0x181c7a(%rip), %rsi    # 0x19cdcf
callq 0x15e380
jmp 0x1b202
movq -0x18(%rbp), %rax
cmpl $0x416d4963, (%rax)     # imm = 0x416D4963
jne 0x1b180
movq -0x8(%rbp), %rdi
leaq 0x181c6a(%rip), %rsi    # 0x19cde0
callq 0x15e380
jmp 0x1b200
movq -0x18(%rbp), %rax
cmpl $0x416d4273, (%rax)     # imm = 0x416D4273
jne 0x1b19e
movq -0x8(%rbp), %rdi
leaq 0x181c58(%rip), %rsi    # 0x19cdef
callq 0x15e380
jmp 0x1b1fe
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x1b640
cmpl $0x0, %eax
je 0x1b1c4
movb $0x1, -0x21(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x181c43(%rip), %rsi    # 0x19ce00
callq 0x15e380
jmp 0x1b1fc
movq -0x18(%rbp), %rax
cmpl $0x6071963, (%rax)      # imm = 0x6071963
jne 0x1b1e6
movb $0x1, -0x21(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x181c42(%rip), %rsi    # 0x19ce21
callq 0x15e380
jmp 0x1b1fa
movq -0x8(%rbp), %rdi
leaq 0x181c4f(%rip), %rsi    # 0x19ce40
movb $0x0, %al
callq 0x15bfb0
jmp 0x1b273
jmp 0x1b1fc
jmp 0x1b1fe
jmp 0x1b200
jmp 0x1b202
jmp 0x1b204
cmpb $0x0, -0x21(%rbp)
je 0x1b219
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1b680
jmp 0x1b271
movq -0x18(%rbp), %rax
cmpl $0x416d426b, (%rax)     # imm = 0x416D426B
je 0x1b23d
movq -0x18(%rbp), %rax
cmpl $0x416d5370, (%rax)     # imm = 0x416D5370
je 0x1b23d
movq -0x18(%rbp), %rax
cmpl $0x416d4963, (%rax)     # imm = 0x416D4963
jne 0x1b254
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x20(%rbp), %rcx
callq 0x1b710
jmp 0x1b26f
movq -0x18(%rbp), %rax
cmpl $0x416d4273, (%rax)     # imm = 0x416D4273
jne 0x1b26d
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1b8d0
jmp 0x1b26f
jmp 0x1b271
jmp 0x1b273
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)