// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/dms.c
// Function: dms_read_and_decompress_track
static int dms_read_and_decompress_track(deark *c, struct dmsctx *d,
	i64 track_idx, dbuf *outf)
{
	i64 pos1, pos;
	struct dms_track_info *tri = NULL;
	de_ucstring *descr = NULL;
	int retval = 0;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	tri = de_malloc(c, sizeof(struct dms_track_info));
	pos1 = d->tracks_by_file_order[track_idx].file_pos;
	tri->track_num = (i64)d->tracks_by_file_order[track_idx].track_num;
	tri->is_real = d->tracks_by_file_order[track_idx].is_real;
	de_snprintf(tri->shortname, sizeof(tri->shortname), "%strack %d",
		(tri->is_real?"":"extra "), (int)tri->track_num);

	de_dbg(c, "%s at %"I64_FMT, tri->shortname, pos1);
	de_dbg_indent(c, 1);
	pos = pos1;
	pos += 2; // signature, already checked
	pos += 2; // reported track number, already read
	pos += 2; // Unknown field
	tri->cmpr_len = de_getu16be_p(&pos);
	de_dbg(c, "cmpr len: %"I64_FMT, tri->cmpr_len);
	tri->intermediate_len = de_getu16be_p(&pos);
	de_dbg(c, "intermediate len: %"I64_FMT, tri->intermediate_len);
	tri->uncmpr_len = de_getu16be_p(&pos);
	de_dbg(c, "uncmpr len: %"I64_FMT, tri->uncmpr_len);

	tri->track_flags = (UI)de_getbyte_p(&pos);
	tri->cmpr_type = (UI)de_getbyte_p(&pos);

	descr = ucstring_create(c);
	get_trackflags_descr(c, descr, tri->track_flags, tri->cmpr_type);
	de_dbg(c, "track flags: 0x%02x (%s)", tri->track_flags, ucstring_getpsz_d(descr));

	de_dbg(c, "track cmpr type: %u (%s)", tri->cmpr_type, dms_get_cmprtype_name(tri->cmpr_type));
	tri->cksum_reported = (u32)de_getu16be_p(&pos);
	de_dbg(c, "checksum (reported): 0x%04x", (UI)tri->cksum_reported);
	tri->crc_cmprdata_reported = (u32)de_getu16be_p(&pos);
	de_dbg(c, "crc of cmpr data (reported): 0x%04x", (UI)tri->crc_cmprdata_reported);
	tri->crc_header_reported = (u32)de_getu16be_p(&pos);
	de_dbg(c, "crc of header (reported): 0x%04x", (UI)tri->crc_header_reported);

	tri->dpos = pos1 + DMS_TRACK_HDR_LEN;
	de_dbg(c, "cmpr data at %"I64_FMT, tri->dpos);
	de_dbg_indent(c, 1);
	if(!dms_decompress_track(c, d, tri, outf)) goto done;
	de_dbg_indent(c, -1);

	tri->cksum_calc = dms_calc_checksum(c, d, outf);
	de_dbg(c, "checksum (calculated): 0x%04x", (UI)tri->cksum_calc);
	if(tri->cksum_calc != tri->cksum_reported) {
		de_err(c, "[%s] Checksum check failed", tri->shortname);
		goto done;
	}
	retval = 1;

done:
	ucstring_destroy(descr);
	de_free(c, tri);
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x98, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x30, %rax
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x30, %rax
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
addq $0x30, %rax
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movb 0xc(%rax), %cl
movq -0x38(%rbp), %rax
movb %cl, 0x30(%rax)
movq -0x38(%rbp), %rdi
addq $0x44, %rdi
movq -0x38(%rbp), %rax
movzbl 0x30(%rax), %edx
leaq 0x14448f(%rip), %rcx    # 0x1a9b8a
leaq 0x16b4ce(%rip), %rax    # 0x1d0bd0
cmpl $0x0, %edx
cmovneq %rax, %rcx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %eax, %r8d
movl $0x50, %esi
leaq 0x144460(%rip), %rdx    # 0x1a9b7f
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
addq $0x44, %rdx
movq -0x28(%rbp), %rcx
leaq 0x156fbf(%rip), %rsi    # 0x1bc6fc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x170eb4(%rip), %rsi    # 0x1d6661
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x1443ae(%rip), %rsi    # 0x1a9b91
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x1685da(%rip), %rsi    # 0x1cddf3
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movzbl %al, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movzbl %al, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x38(%rbp), %rax
movl 0x2c(%rax), %ecx
callq 0x65b20
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172650
movq -0x68(%rbp), %rdi
movl -0x5c(%rbp), %edx
movq %rax, %rcx
leaq 0x1442fd(%rip), %rsi    # 0x1a9ba7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movl 0x2c(%rax), %edi
callq 0x65590
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %edx
movq %rax, %rcx
leaq 0x1442e0(%rip), %rsi    # 0x1a9bc0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x34(%rax), %edx
leaq 0x170ecd(%rip), %rsi    # 0x1d67e0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x38(%rax), %edx
leaq 0x144293(%rip), %rsi    # 0x1a9bd9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x3c(%rax), %edx
leaq 0x144284(%rip), %rsi    # 0x1a9bfd
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rcx
addq $0x14, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x14bd10(%rip), %rsi    # 0x1b16b3
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x65be0
cmpl $0x0, %eax
jne 0x659d4
jmp 0x65a48
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x65f10
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x40(%rax), %edx
leaq 0x170e45(%rip), %rsi    # 0x1d6853
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
movl 0x40(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl 0x34(%rcx), %eax
je 0x65a41
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
addq $0x44, %rdx
leaq 0x1441e6(%rip), %rsi    # 0x1a9c1e
movb $0x0, %al
callq 0x15bfb0
jmp 0x65a48
movl $0x1, -0x44(%rbp)
movq -0x40(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x15b5a0
movl -0x44(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)