// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/fat.c
// Function: de_run_loaddskf
static void de_run_loaddskf(deark *c, de_module_params *mparams)
{
	struct skf_ctx *d = NULL;
	const char *subfmt_name;
	UI sig;

	d = de_malloc(c, sizeof(struct skf_ctx));
	d->to_raw = de_get_ext_option_bool(c, "loaddskf:toraw", 0);
	d->crco = de_crcobj_create(c, DE_CRCOBJ_SUM_U16LE);

	sig = (UI)de_getu16be(0);
	switch(sig) {
	case 0xaa58:
		subfmt_name = "old";
		break;
	case 0xaa59:
		subfmt_name = "new";
		d->new_fmt = 1;
		break;
	case 0xaa5a:
		subfmt_name = "new, compressed";
		d->new_fmt = 1;
		d->is_compressed = 1;
		break;
	default:
		de_err(c, "Not a LoadDskF file");
		goto done;
	}

	de_declare_fmtf(c, "LoadDskF (%s)", subfmt_name);
	if(!loaddskf_read_header(c, d)) goto done;
	if(d->is_compressed) {
		loaddskf_decompress(c, d);
	}
	else {
		loaddskf_calc_checksum_noncmpr(c, d);
		loaddskf_finish_checksum(c, d);
		if(d->to_raw) {
			loaddskf_convert_noncmpr_to_ima(c, d);
		}
		else {
			loaddskf_decode_as_fat(c, d);
		}
	}

done:
	if(d) {
		de_crcobj_destroy(d->crco);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
movl $0x38, %esi
callq 0xe969b
movq %rax, %r14
leaq 0xc61dc(%rip), %rsi     # 0x1228bd
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movl %eax, (%r14)
movq %rbx, %rdi
movl $0x31, %esi
callq 0xeba56
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef169
cmpl $0xaa58, %eax           # imm = 0xAA58
je 0x5c74b
cmpl $0xaa5a, %eax           # imm = 0xAA5A
je 0x5c734
cmpl $0xaa59, %eax           # imm = 0xAA59
jne 0x5c8c5
movl $0x1, 0x4(%r14)
leaq 0xc1b1b(%rip), %rdx     # 0x11e24d
jmp 0x5c752
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x4(%r14)
leaq 0xc6183(%rip), %rdx     # 0x1228cc
jmp 0x5c752
leaq 0xddd7c(%rip), %rdx     # 0x13a4ce
leaq 0xc6197(%rip), %rsi     # 0x1228f0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb703
leaq 0xb90ee(%rip), %rsi     # 0x115858
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xef1ca
leaq 0xc6168(%rip), %rsi     # 0x1228fe
movq %rbx, %rdi
movq %rax, 0x8(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x14, %esi
callq 0xef37e
movl %eax, 0xc(%r14)
leaq 0xc6153(%rip), %rsi     # 0x122913
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x18, %esi
callq 0xef1ca
movq %rax, %r12
leaq 0xc614b(%rip), %rsi     # 0x12292f
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x1a, %esi
callq 0xef1ca
movq %rax, %r13
leaq 0xc6134(%rip), %rsi     # 0x12293d
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xef1ca
movq %rax, %rbp
leaq 0xc6123(%rip), %rsi     # 0x122951
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x22, %esi
callq 0xef1ca
movq %rax, %r15
leaq 0xc6115(%rip), %rsi     # 0x122967
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x26, %esi
callq 0xef1ca
testq %rax, %rax
movl $0x200, %edx            # imm = 0x200
cmovneq %rax, %rdx
movq %rdx, 0x18(%r14)
leaq 0xbb6bd(%rip), %rsi     # 0x117f41
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rax
cmpq $0x28, %rax
jl 0x5c8a2
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x5c8db
leaq 0xc6138(%rip), %rsi     # 0x1229e1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
jmp 0x5cb49
leaq 0xc6010(%rip), %rsi     # 0x1228dc
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x5cb49
movq 0x8(%rsp), %rdx
leaq -0x801(%rdx), %rax
cmpq $-0x781, %rax           # imm = 0xF87F
jb 0x5c949
movq $-0xc9, %rax
leaq (%r12,%rax), %rcx
cmpq $-0xb5, %rcx
jb 0x5c949
leaq -0x3(%r13), %rcx
cmpq $-0x2, %rcx
jb 0x5c949
addq %rbp, %rax
cmpq $-0xc2, %rax
jbe 0x5c949
imulq %rdx, %r15
movq %r15, 0x20(%r14)
imulq %rdx, %r12
imulq %rbp, %r13
imulq %r12, %r13
movq %r13, 0x28(%r14)
leaq 0xc607e(%rip), %rsi     # 0x1229b5
movq %rbx, %rdi
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
jmp 0x5c95a
leaq 0xc6030(%rip), %rsi     # 0x122980
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpl $0x0, 0x8(%r14)
je 0x5c99b
cmpl $0x0, (%r14)
je 0x5ca20
leaq 0xc5e9d(%rip), %rsi     # 0x12281c
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r15
movq %rax, %rdi
callq 0xf0e3f
jmp 0x5ca6b
movq 0x18(%rbx), %rsi
movq 0x18(%rsi), %rax
movq 0x18(%r14), %rdx
movq 0x20(%r14), %rdi
subq %rdx, %rax
cmpq %rax, %rdi
movq %rax, %rcx
cmovlq %rdi, %rcx
testq %rdi, %rdi
cmoveq %rax, %rcx
movq 0x30(%r14), %rdi
callq 0xebf09
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5d95e
cmpl $0x0, (%r14)
je 0x5cb6f
leaq 0xc5e38(%rip), %rsi     # 0x12281c
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r15
leaq 0xc60a6(%rip), %rsi     # 0x122aa0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
movq %r15, %rcx
callq 0xefabc
jmp 0x5cb33
leaq 0xc5fd8(%rip), %rsi     # 0x1229ff
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r15
movq %rax, %rdi
callq 0xf0e3f
leaq 0xc5fc2(%rip), %rsi     # 0x122a07
movl $0x2, %edx
movq %r15, %rdi
callq 0xefb82
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rdx
addq $-0x2, %rdx
movl $0x2, %esi
movq %r15, %rcx
callq 0xefabc
leaq 0x28(%rsp), %rbp
leaq 0x10(%rsp), %r13
leaq 0x48(%rsp), %r12
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, (%rbp)
movq 0x18(%r14), %rcx
movq %rcx, 0x8(%rbp)
movq 0x18(%rax), %rax
subq %rcx, %rax
movq %rax, 0x10(%rbp)
movq %r15, (%r13)
movq 0x30(%r14), %rdx
leaq 0x94f9c(%rip), %rsi     # 0xf1a51
movq %r15, %rdi
callq 0xf1a12
leaq 0xc5f46(%rip), %rsi     # 0x122a0a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x103b56
movq (%r13), %rdi
callq 0xf0ea4
cmpl $0x0, (%r12)
je 0x5cb15
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa6a8
leaq 0xb766b(%rip), %rsi     # 0x114171
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0x5cb41
movq 0x30(%r14), %rdi
callq 0xebe2a
movl %eax, 0x10(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5d95e
cmpl $0x0, (%r14)
je 0x5cb41
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x5d9b4
movq %r15, %rdi
callq 0xf0b13
movq 0x30(%r14), %rdi
callq 0xebe1d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdi
subq 0x18(%r14), %rdi
movq 0x28(%r14), %rsi
callq 0xea79d
movq %rax, %r15
movq 0x18(%r14), %rdx
leaq 0xc5f18(%rip), %rsi     # 0x122aaa
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
testq %r15, %r15
jle 0x5cb49
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rcx
movq 0x18(%r14), %r8
leaq 0xb61c2(%rip), %rsi     # 0x112d82
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %r9
callq 0xea5fa
jmp 0x5c8b3