// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
movl $0x68, %esi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0x12, %edx
callq 0xeb7d1
movl %eax, (%r14)
leaq 0xf270c(%rip), %rsi     # 0x112c43
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
testl %eax, %eax
je 0x2054f
movl $0x2, 0x4(%r14)
jmp 0x20576
leaq 0xf26fa(%rip), %rsi     # 0x112c50
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
testl %eax, %eax
je 0x2056e
movl $0x1, 0x4(%r14)
jmp 0x20576
movl $0x0, 0x4(%r14)
leaq 0x102c22(%rip), %rsi    # 0x12319f
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0x20(%rsp), %r15
movq $0x2, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef193
movq %rax, 0x8(%r14)
leaq 0xf26ed(%rip), %rsi     # 0x112ca6
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef193
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%r14)
leaq 0xf62f6(%rip), %rsi     # 0x1168d6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef193
movq %rax, 0x18(%r14)
leaq 0xf26b7(%rip), %rsi     # 0x112cb8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef193
movq %rax, 0x20(%r14)
leaq 0xf26a4(%rip), %rsi     # 0x112cc8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
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 0x20673
movq 0x8(%r14), %rdx
leaq -0x1f(%rdx), %rsi
cmpq $-0x1e, %rsi
jb 0x20673
imulq %rcx, %rax
movq %rax, 0x30(%r14)
leaq -0xc9(%rax), %rcx
cmpq $-0xc8, %rcx
jae 0x206ab
leaq 0xf265d(%rip), %rsi     # 0x112cd7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x48, %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)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x40(%r14), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf0faf
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0xf0e3f
movq $0xa, 0x30(%rsp)
leaq 0xf2600(%rip), %rsi     # 0x112cf6
xorl %ebp, %ebp
movl $0xa, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r14), %rax
movq %rax, 0x28(%rsp)
cmpq 0x20(%r14), %rax
jg 0x20974
cmpq $0x0, 0x10(%r14)
jle 0x20947
xorl %ebp, %ebp
movq 0x30(%rsp), %r15
leaq 0x2(%r15), %r12
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r12
jge 0x207cc
leaq 0x30(%rsp), %rsi
callq 0xef193
movq %rax, %r13
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
leaq 0xf25ab(%rip), %rsi     # 0x112d1b
movq 0x28(%rsp), %rdx
movl %ebp, %ecx
movq %r15, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0xe93cf
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x38(%r14), %r15
cmpq %r13, %r15
jge 0x207e7
movq %rbx, %rdi
leaq 0xf259b(%rip), %rsi     # 0x112d3f
xorl %eax, %eax
callq 0xe9df7
movq 0x10(%rsp), %rdi
callq 0xf0ea4
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl $0x9, %eax
jmp 0x20925
movq %rbx, %rdi
leaq 0xf252e(%rip), %rsi     # 0x112d04
xorl %eax, %eax
callq 0xe9df7
movl $0x8, %eax
jmp 0x20925
setne %al
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x117649(%rip), %rsi    # 0x137e40
xorl %eax, %eax
callq 0xe93cf
cmpq %r13, %r15
je 0x208d9
movq %r13, 0x38(%rsp)
addq %r12, %r13
movq %r12, 0x20(%rsp)
xorl %r15d, %r15d
xorl %eax, %eax
movb $0x1, %r12b
cmpq 0x38(%r14), %r15
jge 0x2089e
cmpq %r13, 0x20(%rsp)
jge 0x208bc
movl %eax, 0x1c(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x20(%rsp), %rsi
callq 0xef14d
cmpb $-0x1b, %al
jne 0x208a5
movq 0x20(%rsp), %rax
addq $0x3, %rax
cmpq %r13, %rax
jg 0x208b8
movq 0x18(%rbx), %rdi
leaq 0x20(%rsp), %r12
movq %r12, %rsi
callq 0xef14d
movb %al, 0xf(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef193
leaq (%rax,%r15), %rcx
movq 0x38(%r14), %rdx
movq %rdx, %r12
subq %r15, %r12
cmpq %rdx, %rcx
cmovleq %rax, %r12
movzbl 0xf(%rsp), %esi
movq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0xf14bd
addq %r12, %r15
jmp 0x208b5
movl $0x1, %eax
jmp 0x208bc
movzbl %al, %esi
movq 0x10(%rsp), %rdi
callq 0xf11be
incq %r15
xorl %r12d, %r12d
movl 0x1c(%rsp), %eax
testb %r12b, %r12b
je 0x20819
testl %eax, %eax
je 0x20938
incq 0x50(%r14)
movq 0x10(%rsp), %r15
movq 0x38(%rsp), %r13
jmp 0x208f0
movq 0x18(%rbx), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %r15
movq %r15, %rcx
callq 0xefabc
addq %r13, 0x58(%r14)
incq 0x48(%r14)
movq 0x40(%rsp), %rsi
addq 0x38(%r14), %rsi
movq %r15, %rdi
callq 0xf152a
movq %r15, %rdi
callq 0xf0ea4
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq %r13, 0x30(%rsp)
xorl %eax, %eax
testl %eax, %eax
jne 0x20961
incq %rbp
cmpq 0x10(%r14), %rbp
jl 0x20734
jmp 0x20947
movq %rbx, %rdi
leaq 0xf241b(%rip), %rsi     # 0x112d5d
jmp 0x207a4
movq 0x28(%rsp), %rcx
leaq 0x1(%rcx), %rax
cmpq 0x20(%r14), %rcx
movq %rax, 0x28(%rsp)
jl 0x20727
jmp 0x2096b
cmpl $0x1, %eax
je 0x2096f
cmpl $0x8, %eax
jne 0x20971
xorl %ebp, %ebp
jmp 0x20974
jmp 0x20981
movb $0x1, %bpl
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
testb $0x1, %bpl
jne 0x20691
movq 0x10(%rsp), %r13
movq 0x18(%r13), %rax
movq %rax, 0x60(%r14)
movl 0x48(%r14), %edx
movl 0x50(%r14), %ecx
leaq 0xf22b3(%rip), %rsi     # 0x112c5a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x58(%r14), %rdx
movq 0x60(%r14), %rcx
leaq 0xf22c0(%rip), %rsi     # 0x112c80
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movl 0x4(%r14), %eax
cmpl $0x2, %eax
je 0x20a08
cmpl $0x1, %eax
jne 0x20a73
leaq 0x122c6f(%rip), %rsi    # 0x143652
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r15
movq 0x40(%r14), %rdx
movq %r13, %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0xefabc
movq %r15, %rdi
jmp 0x20a69
leaq 0xf223d(%rip), %rsi     # 0x112c4c
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r12
movq 0x18(%rbx), %rdi
movl $0xa, %edx
xorl %esi, %esi
movq %rax, %rcx
callq 0xefabc
cmpq $0x0, 0x30(%r14)
jle 0x20a66
xorl %r15d, %r15d
movq 0x38(%r14), %rsi
movq %r12, %rdi
callq 0xf15b0
movq 0x38(%r14), %rdx
movq %rdx, %rsi
imulq %r15, %rsi
movq %r13, %rdi
movq %r12, %rcx
callq 0xefabc
incq %r15
cmpq 0x30(%r14), %r15
jl 0x20a3b
movq %r12, %rdi
callq 0xf0b13
jmp 0x20691
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r12
leaq 0xf22e8(%rip), %rsi     # 0x112d72
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0x11e441(%rip), %rax    # 0x13eee9
movq %rax, (%r12)
movl (%r14), %eax
movl %eax, 0xc(%r12)
movq 0x18(%r13), %r9
leaq 0xf22c3(%rip), %rsi     # 0x112d82
movq %rbx, %rdi
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xea5fa
testb $0x1, 0x40(%r12)
je 0x20ae9
leaq 0xf22a7(%rip), %rsi     # 0x112d86
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9ef5
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe9752
jmp 0x20684