// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/atari-dsk.c
// Function: de_run_msa
static void de_run_msa(deark *c, de_module_params *mparams)
{
	struct msactx *d = NULL;
	dbuf *diskbuf = NULL;

	d = de_malloc(c, sizeof(struct msactx));
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_ATARIST);

	if(de_get_ext_option_bool(c, "msa:touncmsa", 0)) {
		d->outfmt = ATARIST_OUTFMT_UNCMSA;
	}
	else if(de_get_ext_option_bool(c, "msa:toraw", 0)) {
		d->outfmt = ATARIST_OUTFMT_ST;
	}
	else {
		d->outfmt = ATARIST_OUTFMT_FILES;
	}

	if(!do_msa_header(c, d, 0)) goto done;

	diskbuf = dbuf_create_membuf(c, d->disk_size, 0x1);
	dbuf_enable_wbuffer(diskbuf);

	if(!do_msa_tracks(c, d, 10, diskbuf)) goto done;

	d->total_uncmpr_bytes = diskbuf->len;
	de_dbg(c, "totals: %u track-sides, %u compressed",
		(UI)d->total_track_sides, (UI)d->total_track_sides_cmpr);
	de_dbg(c, "totals: decompressed %"I64_FMT" bytes to %"I64_FMT,
		d->total_cmpr_bytes, d->total_uncmpr_bytes);

	if(d->outfmt==ATARIST_OUTFMT_ST) {
		msa_extract_to_raw(c, d, diskbuf);
	}
	else if(d->outfmt==ATARIST_OUTFMT_UNCMSA) {
		msa_extract_to_uncmsa(c, d, diskbuf);
	}
	else {
		msa_decode_fat(c, d, diskbuf);
	}

done:
	de_free(c, d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
pushq $0x68
popq %rsi
callq 0xdecaf
movq %rax, %r14
pushq $0x12
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, (%r14)
leaq 0xe5bf0(%rip), %rsi     # 0x105c33
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
testl %eax, %eax
je 0x2005b
movl $0x2, 0x4(%r14)
jmp 0x2007f
leaq 0xe5bde(%rip), %rsi     # 0x105c40
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
testl %eax, %eax
je 0x2007a
movl $0x1, 0x4(%r14)
jmp 0x2007f
andl $0x0, 0x4(%r14)
leaq 0xf6139(%rip), %rsi     # 0x1161bf
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
leaq 0x8(%rsp), %r15
movq $0x2, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f6e
movq %rax, 0x8(%r14)
leaq 0xe5bd6(%rip), %rsi     # 0x105c96
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f6e
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%r14)
leaq 0xe980f(%rip), %rsi     # 0x1098f6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f6e
movq %rax, 0x18(%r14)
leaq 0xe5ba0(%rip), %rsi     # 0x105ca8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3f6e
movq %rax, 0x20(%r14)
leaq 0xe5b8d(%rip), %rsi     # 0x105cb8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x10(%r14), %rcx
movq 0x20(%r14), %rax
subq 0x18(%r14), %rax
incq %rax
movq %rax, 0x28(%r14)
leaq -0x3(%rcx), %rdx
cmpq $-0x2, %rdx
jb 0x2017a
movq 0x8(%r14), %rdx
leaq -0x1f(%rdx), %rsi
cmpq $-0x1e, %rsi
jb 0x2017a
imulq %rcx, %rax
movq %rax, 0x30(%r14)
leaq -0xc9(%rax), %rcx
cmpq $-0xc8, %rcx
jae 0x201b0
leaq 0xe5b46(%rip), %rsi     # 0x105cc7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shlq $0x9, %rdx
movq %rdx, 0x38(%r14)
imulq %rax, %rdx
movq %rdx, 0x40(%r14)
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x40(%r14), %rsi
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %edx
callq 0xe59cd
movq %rax, %r15
movq %rax, %rdi
callq 0xe589c
leaq 0x10(%rsp), %rax
movq $0xa, (%rax)
leaq 0xe5aec(%rip), %rsi     # 0x105ce6
pushq $0xa
popq %r12
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%r14), %rbp
movq %r15, (%rsp)
cmpq 0x20(%r14), %rbp
jg 0x20429
xorl %r13d, %r13d
movq %rbp, 0x20(%rsp)
cmpq 0x10(%r14), %r13
jge 0x203dc
leaq 0x2(%r12), %r15
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r15
jge 0x20414
leaq 0x10(%rsp), %rsi
callq 0xe3f6e
movq %rax, %rcx
movq (%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
leaq 0xe5a9b(%rip), %rsi     # 0x105d0b
movl %ebp, %edx
movq %rcx, %rbp
movq %r13, 0x30(%rsp)
movl %r13d, %ecx
movq %r12, %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0xde9f1
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x38(%r14), %r12
cmpq %rbp, %r12
jl 0x204b5
setne %al
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x10ac1a(%rip), %rsi    # 0x12aecc
xorl %eax, %eax
callq 0xde9f1
cmpq %rbp, %r12
je 0x20370
movq %rbp, 0x18(%rsp)
addq %r15, %rbp
movq %r15, 0x8(%rsp)
xorl %r13d, %r13d
movq (%rsp), %r15
leaq 0x8(%rsp), %r12
movq 0x38(%r14), %rsi
cmpq %rsi, %r13
jge 0x2038c
cmpq %rbp, 0x8(%rsp)
jge 0x203e4
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3f2a
cmpb $-0x1b, %al
je 0x20313
movzbl %al, %esi
movq %r15, %rdi
callq 0xe5bc5
incq %r13
jmp 0x202db
movq 0x8(%rsp), %rax
addq $0x3, %rax
cmpq %rbp, %rax
jg 0x203e4
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3f2a
movl %eax, %r15d
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3f6e
leaq (%rax,%r13), %rcx
movq 0x38(%r14), %rdx
movq %rdx, %r12
subq %r13, %r12
cmpq %rdx, %rcx
cmovleq %rax, %r12
movzbl %r15b, %esi
movq (%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
callq 0xe5e40
addq %r12, %r13
jmp 0x202d6
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq (%rsp), %r15
movq %r15, %rcx
callq 0xe45f4
movq 0x38(%r14), %rsi
jmp 0x20395
incq 0x50(%r14)
movq 0x18(%rsp), %rbp
addq %rbp, 0x58(%r14)
addq 0x28(%rsp), %rsi
incq 0x48(%r14)
movq %r15, %rdi
callq 0xe5eb2
movq %r15, %rdi
callq 0xe58e8
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x10(%rsp), %r12
addq %rbp, %r12
movq %r12, 0x10(%rsp)
movq 0x30(%rsp), %r13
incq %r13
movq 0x20(%rsp), %rbp
jmp 0x2022f
incq %rbp
jmp 0x2021d
leaq 0xe5962(%rip), %rsi     # 0x105d4d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %r15, %rdi
callq 0xe58e8
pushq $-0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq %rbx, %rdi
movl %ebp, %esi
jmp 0x20191
leaq 0xe58d9(%rip), %rsi     # 0x105cf4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq (%rsp), %r15
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%r15), %rax
movq %rax, 0x60(%r14)
movl 0x48(%r14), %edx
movl 0x50(%r14), %ecx
leaq 0xe57ff(%rip), %rsi     # 0x105c4a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x58(%r14), %rdx
movq 0x60(%r14), %rcx
leaq 0xe580c(%rip), %rsi     # 0x105c70
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl 0x4(%r14), %eax
cmpl $0x2, %eax
je 0x204cf
cmpl $0x1, %eax
jne 0x20527
leaq 0x11625b(%rip), %rsi    # 0x1366e2
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r15
movq 0x40(%r14), %rdx
movq (%rsp), %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0xe45f4
movq %r15, %rdi
callq 0xe5591
jmp 0x20196
leaq 0xe5873(%rip), %rsi     # 0x105d2f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq (%rsp), %r15
jmp 0x203f5
leaq 0xe5766(%rip), %rsi     # 0x105c3c
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r15
movq 0x18(%rbx), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
movq %rax, %rcx
callq 0xe45f4
cmpq 0x30(%r14), %r12
jge 0x204a8
movq 0x38(%r14), %rsi
movq %r15, %rdi
callq 0xe5f1e
movq 0x38(%r14), %rdx
movq %rdx, %rsi
imulq %r12, %rsi
movq (%rsp), %rdi
movq %r15, %rcx
callq 0xe45f4
incq %r12
jmp 0x204f9
pushq $0x70
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
leaq 0xe5826(%rip), %rsi     # 0x105d62
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
leaq 0x111a61(%rip), %rax    # 0x131fb9
movq %rax, (%r15)
movl (%r14), %eax
movl %eax, 0xc(%r15)
movq (%rsp), %rcx
movq 0x18(%rcx), %r9
leaq 0xe5801(%rip), %rsi     # 0x105d72
movq %rbx, %rdi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0xdf9b8
testb $0x1, 0x40(%r15)
je 0x20597
leaq 0xe57e9(%rip), %rsi     # 0x105d76
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf37f
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
jmp 0x2018b