// File: /workspace/github_c_makefile_star2_O3/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
movl $0x8, %esi
callq 0xe8b2b
movq %rax, %r14
leaq 0xf773d(%rip), %rsi     # 0x110dd6
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xe9bd0
movl %eax, 0x4(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeed0d
movl %eax, (%r14)
cmpl $0x416d426a, %eax       # imm = 0x416D426A
jg 0x196e8
leaq 0xf7761(%rip), %rsi     # 0x110e27
cmpl $0x1203008f, %eax       # imm = 0x1203008F
jg 0x19715
cmpl $0x31990, %eax          # imm = 0x31990
je 0x19727
cmpl $0x6071963, %eax        # imm = 0x6071963
jne 0x1989c
leaq 0xf7762(%rip), %rsi     # 0x110e48
jmp 0x19727
cmpl $0x416d4962, %eax       # imm = 0x416D4962
jg 0x1977a
cmpl $0x416d426b, %eax       # imm = 0x416D426B
je 0x19795
cmpl $0x416d4273, %eax       # imm = 0x416D4273
jne 0x1989c
leaq 0xf7706(%rip), %rsi     # 0x110e16
jmp 0x197a5
cmpl $0x12030090, %eax       # imm = 0x12030090
je 0x19727
cmpl $0x12031990, %eax       # imm = 0x12031990
jne 0x1989c
movq %rbx, %rdi
callq 0xeb125
movl $0x4b8, %esi            # imm = 0x4B8
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
movq $0x0, 0x48(%rax)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xf1388
movq %rax, 0x50(%r15)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x19e3c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1a71a
jmp 0x198ad
cmpl $0x416d4963, %eax       # imm = 0x416D4963
je 0x1979e
cmpl $0x416d5370, %eax       # imm = 0x416D5370
jne 0x1989c
leaq 0xf7663(%rip), %rsi     # 0x110df6
jmp 0x197a5
leaq 0xf7649(%rip), %rsi     # 0x110de5
jmp 0x197a5
leaq 0xf7662(%rip), %rsi     # 0x110e07
movq %rbx, %rdi
callq 0xeb125
movl (%r14), %eax
cmpl $0x416d4962, %eax       # imm = 0x416D4962
jg 0x1987c
cmpl $0x416d426b, %eax       # imm = 0x416D426B
je 0x1988a
cmpl $0x416d4273, %eax       # imm = 0x416D4273
jne 0x198ad
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xeeb67
movq %rax, %r15
leaq 0xf79ef(%rip), %rsi     # 0x1111d8
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
testq %r15, %r15
jle 0x198ad
movl $0x6, %r12d
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jge 0x198ad
movq %rbx, %rdi
leaq 0xf79cc(%rip), %rsi     # 0x1111ec
movl %r13d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe8617
movq $0x0, (%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %rsp, %rcx
callq 0x19b4e
movl %eax, %ebp
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
testl %ebp, %ebp
je 0x198ad
movq (%rsp), %rax
testq %rax, %rax
jle 0x198ad
addq %rax, %r12
incq %r13
cmpq %r13, %r15
jne 0x19808
jmp 0x198ad
cmpl $0x416d5370, %eax       # imm = 0x416D5370
je 0x1988a
cmpl $0x416d4963, %eax       # imm = 0x416D4963
jne 0x198ad
movq %rsp, %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x19b4e
jmp 0x198ad
leaq 0xf75c4(%rip), %rsi     # 0x110e67
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8be2