// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x38
popq %rsi
callq 0xdecaf
movq %rax, %r14
leaq 0xbc532(%rip), %rsi     # 0x115905
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movl %eax, (%r14)
pushq $0x31
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
movq %rax, 0x30(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe3f46
cmpl $0xaa58, %eax           # imm = 0xAA58
je 0x5943b
cmpl $0xaa5a, %eax           # imm = 0xAA5A
je 0x59424
cmpl $0xaa59, %eax           # imm = 0xAA59
jne 0x595a3
movl $0x1, 0x4(%r14)
leaq 0xb7e67(%rip), %rdx     # 0x111289
jmp 0x59442
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x4(%r14)
leaq 0xbc4db(%rip), %rdx     # 0x115914
jmp 0x59442
leaq 0xd411c(%rip), %rdx     # 0x12d55e
leaq 0xbc4ef(%rip), %rsi     # 0x115938
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe0824
leaq 0xaf41e(%rip), %rsi     # 0x108878
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0xe3fa3
leaq 0xbc4c4(%rip), %rsi     # 0x115946
movq %rbx, %rdi
movq %rax, 0x8(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x14
popq %rsi
callq 0xe409f
movl %eax, 0xc(%r14)
leaq 0xbc4b1(%rip), %rsi     # 0x11595b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x18
popq %rsi
callq 0xe3fa3
movq %rax, %r12
leaq 0xbc4ab(%rip), %rsi     # 0x115977
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x1a
popq %rsi
callq 0xe3fa3
movq %rax, %r13
leaq 0xbc496(%rip), %rsi     # 0x115985
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x1c
popq %rsi
callq 0xe3fa3
movq %rax, %rbp
leaq 0xbc487(%rip), %rsi     # 0x115999
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x22
popq %rsi
callq 0xe3fa3
movq %rax, %r15
leaq 0xbc47b(%rip), %rsi     # 0x1159af
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x26
popq %rsi
callq 0xe3fa3
testq %rax, %rax
movl $0x200, %edx            # imm = 0x200
cmovneq %rax, %rdx
movq %rdx, 0x18(%r14)
leaq 0xb1a25(%rip), %rsi     # 0x10af89
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rax
cmpq $0x28, %rax
jl 0x59582
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x595b9
leaq 0xbc4a0(%rip), %rsi     # 0x115a29
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
jmp 0x59825
leaq 0xbc37a(%rip), %rsi     # 0x115924
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x59825
movq 0x8(%rsp), %rdx
leaq -0x801(%rdx), %rax
cmpq $-0x781, %rax           # imm = 0xF87F
jb 0x59627
movq $-0xc9, %rax
leaq (%r12,%rax), %rcx
cmpq $-0xb5, %rcx
jb 0x59627
leaq -0x3(%r13), %rcx
cmpq $-0x2, %rcx
jb 0x59627
addq %rbp, %rax
cmpq $-0xc2, %rax
jbe 0x59627
imulq %rdx, %r15
movq %r15, 0x20(%r14)
imulq %rdx, %r12
imulq %rbp, %r13
imulq %r12, %r13
movq %r13, 0x28(%r14)
leaq 0xbc3e8(%rip), %rsi     # 0x1159fd
movq %rbx, %rdi
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xde896
jmp 0x59638
leaq 0xbc39a(%rip), %rsi     # 0x1159c8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
cmpl $0x0, 0x8(%r14)
je 0x59677
cmpl $0x0, (%r14)
je 0x596fc
leaq 0xbc209(%rip), %rsi     # 0x115864
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r15
movq %rax, %rdi
callq 0xe589c
jmp 0x59747
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 0xe0f33
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5a5ef
cmpl $0x0, (%r14)
je 0x5984b
leaq 0xbc1a4(%rip), %rsi     # 0x115864
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r15
leaq 0xbc412(%rip), %rsi     # 0x115ae8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x18(%rdi), %rdx
subq %rsi, %rdx
movq %r15, %rcx
callq 0xe45f4
jmp 0x5980f
leaq 0xbc344(%rip), %rsi     # 0x115a47
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r15
movq %rax, %rdi
callq 0xe589c
leaq 0xbc32e(%rip), %rsi     # 0x115a4f
pushq $0x2
popq %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0xe46ba
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rdx
addq $-0x2, %rdx
movq %r12, %rsi
movq %r15, %rcx
callq 0xe45f4
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 0xee7ee
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 0x8cb30(%rip), %rsi     # 0xe62c1
movq %r15, %rdi
callq 0xe629a
leaq 0xbc2b2(%rip), %rsi     # 0x115a52
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0xf70f5
movq (%r13), %rdi
callq 0xe58e8
cmpl $0x0, (%r12)
je 0x597f1
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0xee7bc
leaq 0xad9df(%rip), %rsi     # 0x1071c1
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xdf2a5
jmp 0x5981d
movq 0x30(%r14), %rdi
callq 0xe0e95
movl %eax, 0x10(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5a5ef
cmpl $0x0, (%r14)
je 0x5981d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x5a645
movq %r15, %rdi
callq 0xe5591
movq 0x30(%r14), %rdi
callq 0xe0e8d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
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 0xdfb50
movq %rax, %r15
movq 0x18(%r14), %rdx
leaq 0xbc284(%rip), %rsi     # 0x115af2
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
testq %r15, %r15
jle 0x59825
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rcx
movq 0x18(%r14), %r8
leaq 0xac4d8(%rip), %rsi     # 0x105d72
movq %rbx, %rdi
xorl %edx, %edx
movq %r15, %r9
callq 0xdf9b8
jmp 0x59593