// File: /workspace/github_c_makefile_star2_O3/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
movl $0x68, %esi
callq 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl $0x12, %edx
callq 0xeb220
movl %eax, (%r14)
leaq 0xf2652(%rip), %rsi     # 0x112c53
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9bd0
testl %eax, %eax
je 0x20619
movl $0x2, 0x4(%r14)
jmp 0x20640
leaq 0xf2640(%rip), %rsi     # 0x112c60
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9bd0
testl %eax, %eax
je 0x20638
movl $0x1, 0x4(%r14)
jmp 0x20640
movl $0x0, 0x4(%r14)
leaq 0x102d38(%rip), %rsi    # 0x12337f
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rsp, %r15
movq $0x2, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb91
movq %rax, 0x8(%r14)
leaq 0xf2635(%rip), %rsi     # 0x112cb6
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb91
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%r14)
leaq 0xf62de(%rip), %rsi     # 0x116986
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb91
movq %rax, 0x18(%r14)
leaq 0xf25ff(%rip), %rsi     # 0x112cc8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeeb91
movq %rax, 0x20(%r14)
leaq 0xf25ec(%rip), %rsi     # 0x112cd8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r14), %rdx
movq 0x20(%r14), %rax
subq 0x18(%r14), %rax
incq %rax
movq %rax, 0x28(%r14)
leaq -0x3(%rdx), %rcx
cmpq $-0x2, %rcx
jb 0x2073b
movq 0x8(%r14), %rcx
leaq -0x1f(%rcx), %rsi
cmpq $-0x1e, %rsi
jb 0x2073b
imulq %rdx, %rax
movq %rax, 0x30(%r14)
movq $-0xc9, %rdx
leaq (%rax,%rdx), %rsi
cmpq %rdx, %rsi
ja 0x20773
leaq 0xf25a5(%rip), %rsi     # 0x112ce7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shlq $0x9, %rcx
movq %rcx, 0x38(%r14)
imulq %rax, %rcx
movq %rcx, 0x40(%r14)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x40(%r14), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0xf09c5
movq %rax, %rbp
movq %rax, %rdi
callq 0xf0855
movq $0xa, 0x18(%rsp)
leaq 0xf254a(%rip), %rsi     # 0x112d06
movl $0xa, %r13d
movl $0xa, %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r14), %r12
movq 0x20(%r14), %rcx
cmpq %rcx, %r12
jle 0x20878
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%rbp), %rax
movq %rax, 0x60(%r14)
movl 0x48(%r14), %edx
movl 0x50(%r14), %ecx
leaq 0xf2457(%rip), %rsi     # 0x112c6a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x58(%r14), %rdx
movq 0x60(%r14), %rcx
leaq 0xf2464(%rip), %rsi     # 0x112c90
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movl 0x4(%r14), %eax
cmpl $0x2, %eax
je 0x20a96
cmpl $0x1, %eax
jne 0x20b01
leaq 0x1232df(%rip), %rsi    # 0x143b32
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r15
movq 0x40(%r14), %rdx
movq %rbp, %rdi
xorl %esi, %esi
movq %rax, %rcx
callq 0xef481
jmp 0x20af4
movq 0x10(%r14), %rax
movq %rbp, 0x8(%rsp)
testq %rax, %rax
jle 0x20a50
movq $0x0, 0x10(%rsp)
movq %r12, 0x28(%rsp)
leaq 0x2(%r13), %r15
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %r15
jge 0x20b84
leaq 0x18(%rsp), %rsi
callq 0xeeb91
movq 0x18(%rbp), %rcx
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
leaq 0xf2464(%rip), %rsi     # 0x112d2b
movl %r12d, %edx
movq 0x10(%rsp), %rcx
movq %r13, %r8
movq %rax, %r13
movq %rax, %r9
xorl %eax, %eax
callq 0xe87e4
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x38(%r14), %r12
cmpq %r13, %r12
jl 0x20b9a
setne %al
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x1178c3(%rip), %rsi    # 0x1381cc
xorl %eax, %eax
callq 0xe87e4
cmpq %r13, %r12
je 0x209dd
movq %r13, 0x20(%rsp)
movq %r15, (%rsp)
movq 0x38(%r14), %rsi
testq %rsi, %rsi
movq %rsp, %r13
jle 0x209cd
movq 0x20(%rsp), %r12
addq %r15, %r12
xorl %ebp, %ebp
cmpq %r12, (%rsp)
jge 0x20a66
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeeb4b
cmpb $-0x1b, %al
jne 0x209b0
movq (%rsp), %rax
addq $0x3, %rax
cmpq %r12, %rax
jg 0x20a66
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeeb4b
movl %eax, %r15d
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeeb91
leaq (%rax,%rbp), %rcx
movq 0x38(%r14), %rdx
movq %rdx, %r13
subq %rbp, %r13
cmpq %rdx, %rcx
cmovleq %rax, %r13
movzbl %r15b, %esi
movq 0x8(%rsp), %rdi
movq %r13, %rdx
callq 0xf0eba
addq %r13, %rbp
movq %rsp, %r13
jmp 0x209c0
movzbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0xf0bd6
incq %rbp
movq 0x38(%r14), %rsi
cmpq %rsi, %rbp
jl 0x2093c
incq 0x50(%r14)
movq 0x8(%rsp), %rbp
movq 0x20(%rsp), %r13
jmp 0x209f3
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0xef481
movq 0x38(%r14), %rsi
addq %r13, 0x58(%r14)
addq 0x30(%rsp), %rsi
incq 0x48(%r14)
movq %rbp, %rdi
callq 0xf0f27
movq %rbp, %rdi
callq 0xf08ba
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %r13, %rax
movq 0x18(%rsp), %r13
addq %rax, %r13
movq %r13, 0x18(%rsp)
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x10(%r14), %rax
movq %rdx, 0x10(%rsp)
cmpq %rax, %rdx
movq 0x28(%rsp), %r12
jl 0x20898
movq 0x20(%r14), %rcx
leaq 0x1(%r12), %rdx
cmpq %rcx, %r12
movq %rdx, %r12
jl 0x20881
jmp 0x207ef
leaq 0xf2300(%rip), %rsi     # 0x112d6d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0xf08ba
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
jmp 0x2074c
leaq 0xf21bf(%rip), %rsi     # 0x112c5c
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r15
movq 0x18(%rbx), %rdi
movl $0xa, %edx
xorl %esi, %esi
movq %rax, %rcx
callq 0xef481
cmpq $0x0, 0x30(%r14)
jle 0x20af4
xorl %r12d, %r12d
movq 0x38(%r14), %rsi
movq %r15, %rdi
callq 0xf0fad
movq 0x38(%r14), %rdx
movq %rdx, %rsi
imulq %r12, %rsi
movq %rbp, %rdi
movq %r15, %rcx
callq 0xef481
incq %r12
cmpq 0x30(%r14), %r12
jl 0x20ac9
movq %r15, %rdi
callq 0xf052b
jmp 0x20759
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
leaq 0xf226a(%rip), %rsi     # 0x112d82
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x11e7b3(%rip), %rax    # 0x13f2e9
movq %rax, (%r15)
movl (%r14), %eax
movl %eax, 0xc(%r15)
movq 0x18(%rbp), %r9
leaq 0xf2247(%rip), %rsi     # 0x112d92
movq %rbx, %rdi
movq %r15, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0xe9aa3
testb $0x1, 0x40(%r15)
je 0x20b74
leaq 0xf222c(%rip), %rsi     # 0x112d96
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9393
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe8be2
jmp 0x2074c
leaq 0xf2189(%rip), %rsi     # 0x112d14
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x207ef
leaq 0xf21ae(%rip), %rsi     # 0x112d4f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x20a7c