// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, %r14
leaq 0xc65c5(%rip), %rsi     # 0x122ac5
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9bd0
movl %eax, (%r14)
movq %rbx, %rdi
movl $0x31, %esi
callq 0xeb499
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeeb67
cmpl $0xaa58, %eax           # imm = 0xAA58
je 0x5c56a
cmpl $0xaa5a, %eax           # imm = 0xAA5A
je 0x5c553
cmpl $0xaa59, %eax           # imm = 0xAA59
jne 0x5c6e4
movl $0x1, 0x4(%r14)
leaq 0xc1e0c(%rip), %rdx     # 0x11e35d
jmp 0x5c571
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x4(%r14)
leaq 0xc656c(%rip), %rdx     # 0x122ad4
jmp 0x5c571
leaq 0xde2dd(%rip), %rdx     # 0x13a84e
leaq 0xc6580(%rip), %rsi     # 0x122af8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xeb152
leaq 0xb937f(%rip), %rsi     # 0x115908
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movl $0x4, %esi
callq 0xeebc8
leaq 0xc6551(%rip), %rsi     # 0x122b06
movq %rbx, %rdi
movq %rax, 0x8(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x14, %esi
callq 0xeed61
movl %eax, 0xc(%r14)
leaq 0xc653c(%rip), %rsi     # 0x122b1b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x18, %esi
callq 0xeebc8
movq %rax, %r12
leaq 0xc6534(%rip), %rsi     # 0x122b37
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x1a, %esi
callq 0xeebc8
movq %rax, %r13
leaq 0xc651d(%rip), %rsi     # 0x122b45
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x1c, %esi
callq 0xeebc8
movq %rax, %rbp
leaq 0xc650c(%rip), %rsi     # 0x122b59
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x22, %esi
callq 0xeebc8
movq %rax, %r15
leaq 0xc64fe(%rip), %rsi     # 0x122b6f
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x26, %esi
callq 0xeebc8
testq %rax, %rax
movl $0x200, %edx            # imm = 0x200
cmovneq %rax, %rdx
movq %rdx, 0x18(%r14)
leaq 0xbb9d6(%rip), %rsi     # 0x118079
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rax
cmpq $0x28, %rax
jl 0x5c6c1
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x5c6fa
leaq 0xc6521(%rip), %rsi     # 0x122be9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0x5c968
leaq 0xc63f9(%rip), %rsi     # 0x122ae4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x5c968
movq 0x8(%rsp), %rdx
leaq -0x801(%rdx), %rax
cmpq $-0x781, %rax           # imm = 0xF87F
jb 0x5c768
movq $-0xc9, %rax
leaq (%r12,%rax), %rcx
cmpq $-0xb5, %rcx
jb 0x5c768
leaq -0x3(%r13), %rcx
cmpq $-0x2, %rcx
jb 0x5c768
addq %rbp, %rax
cmpq $-0xc2, %rax
jbe 0x5c768
imulq %rdx, %r15
movq %r15, 0x20(%r14)
imulq %rdx, %r12
imulq %rbp, %r13
imulq %r12, %r13
movq %r13, 0x28(%r14)
leaq 0xc6467(%rip), %rsi     # 0x122bbd
movq %rbx, %rdi
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
jmp 0x5c779
leaq 0xc6419(%rip), %rsi     # 0x122b88
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
cmpl $0x0, 0x8(%r14)
je 0x5c7ba
cmpl $0x0, (%r14)
je 0x5c83f
leaq 0xc6286(%rip), %rsi     # 0x122a24
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r15
movq %rax, %rdi
callq 0xf0855
jmp 0x5c88a
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 0xeb944
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5d7a0
cmpl $0x0, (%r14)
je 0x5c98e
leaq 0xc6221(%rip), %rsi     # 0x122a24
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r15
leaq 0xc648f(%rip), %rsi     # 0x122ca8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
movq %r15, %rcx
callq 0xef481
jmp 0x5c952
leaq 0xc63c1(%rip), %rsi     # 0x122c07
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r15
movq %rax, %rdi
callq 0xf0855
leaq 0xc63ab(%rip), %rsi     # 0x122c0f
movl $0x2, %edx
movq %r15, %rdi
callq 0xef547
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rdx
addq $-0x2, %rdx
movl $0x2, %esi
movq %r15, %rcx
callq 0xef481
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 0xfa1dc
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 0x94b7d(%rip), %rsi     # 0xf1451
movq %r15, %rdi
callq 0xf1412
leaq 0xc632f(%rip), %rsi     # 0x122c12
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x103713
movq (%r13), %rdi
callq 0xf08ba
cmpl $0x0, (%r12)
je 0x5c934
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa1a4
leaq 0xb78fc(%rip), %rsi     # 0x114221
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9295
jmp 0x5c960
movq 0x30(%r14), %rdi
callq 0xeb865
movl %eax, 0x10(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5d7a0
cmpl $0x0, (%r14)
je 0x5c960
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x5d7f6
movq %r15, %rdi
callq 0xf052b
movq 0x30(%r14), %rdi
callq 0xeb858
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
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 0xe9c46
movq %rax, %r15
movq 0x18(%r14), %rdx
leaq 0xc6301(%rip), %rsi     # 0x122cb2
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
testq %r15, %r15
jle 0x5c968
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rcx
movq 0x18(%r14), %r8
leaq 0xb63b3(%rip), %rsi     # 0x112d92
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %r9
callq 0xe9aa3
jmp 0x5c6d2