// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
movl $0x8, %esi
callq 0xe969b
movq %rax, %r14
leaq 0xf780a(%rip), %rsi     # 0x110dc7
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xea727
movl %eax, 0x4(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef32a
movl %eax, (%r14)
cmpl $0x416d426a, %eax       # imm = 0x416D426A
jg 0x1960c
leaq 0xf782e(%rip), %rsi     # 0x110e18
cmpl $0x1203008f, %eax       # imm = 0x1203008F
jg 0x19639
cmpl $0x31990, %eax          # imm = 0x31990
je 0x1964b
cmpl $0x6071963, %eax        # imm = 0x6071963
jne 0x197c6
leaq 0xf782f(%rip), %rsi     # 0x110e39
jmp 0x1964b
cmpl $0x416d4962, %eax       # imm = 0x416D4962
jg 0x1969e
cmpl $0x416d426b, %eax       # imm = 0x416D426B
je 0x196b9
cmpl $0x416d4273, %eax       # imm = 0x416D4273
jne 0x197c6
leaq 0xf77d3(%rip), %rsi     # 0x110e07
jmp 0x196c9
cmpl $0x12030090, %eax       # imm = 0x12030090
je 0x1964b
cmpl $0x12031990, %eax       # imm = 0x12031990
jne 0x197c6
movq %rbx, %rdi
callq 0xeb6d6
movl $0x4b8, %esi            # imm = 0x4B8
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r15
movq $0x0, 0x48(%rax)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xf1988
movq %rax, 0x50(%r15)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x19d93
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1a676
jmp 0x197d7
cmpl $0x416d4963, %eax       # imm = 0x416D4963
je 0x196c2
cmpl $0x416d5370, %eax       # imm = 0x416D5370
jne 0x197c6
leaq 0xf7730(%rip), %rsi     # 0x110de7
jmp 0x196c9
leaq 0xf7716(%rip), %rsi     # 0x110dd6
jmp 0x196c9
leaq 0xf772f(%rip), %rsi     # 0x110df8
movq %rbx, %rdi
callq 0xeb6d6
movl (%r14), %eax
cmpl $0x416d4962, %eax       # imm = 0x416D4962
jg 0x197a4
cmpl $0x416d426b, %eax       # imm = 0x416D426B
je 0x197b2
cmpl $0x416d4273, %eax       # imm = 0x416D4273
jne 0x197d7
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef169
movq %rax, %r15
leaq 0xf7abc(%rip), %rsi     # 0x1111c9
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
testq %r15, %r15
jle 0x197d7
movl $0x6, %r12d
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jge 0x197d7
movq %rbx, %rdi
leaq 0xf7a99(%rip), %rsi     # 0x1111dd
movl %r13d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe9226
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
leaq 0x8(%rsp), %rcx
callq 0x19a9d
movl %eax, %ebp
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
testl %ebp, %ebp
je 0x197d7
movq 0x8(%rsp), %rax
testq %rax, %rax
jle 0x197d7
addq %rax, %r12
incq %r13
cmpq %r13, %r15
jne 0x1972c
jmp 0x197d7
cmpl $0x416d5370, %eax       # imm = 0x416D5370
je 0x197b2
cmpl $0x416d4963, %eax       # imm = 0x416D4963
jne 0x197d7
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x19a9d
jmp 0x197d7
leaq 0xf768b(%rip), %rsi     # 0x110e58
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9752