// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/misc3.c
// Function: de_run_tc_trs80
static void de_run_tc_trs80(deark *c, de_module_params *mparams)
{
	de_arch_lctx *d = NULL;
	struct de_arch_member_data *md = NULL;
	i64 pos = 0;
	i64 seq_num = 0;

	d = de_arch_create_lctx(c);
	d->is_le = 0;
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_ASCII);

	while(1) {
		if(pos >= c->infile->len) {
			d->fatalerrflag = 1;
			d->need_errmsg = 1;
			goto done;
		}

		if(md) {
			de_arch_destroy_md(c, md);
			md = NULL;
		}

		seq_num++; // 1-based
		md = de_arch_create_md(c, d);
		md->member_hdr_pos = pos;
		md->member_idx = seq_num;
		do_tc_member(c, d, md);
		if(d->stop_flag || d->fatalerrflag || md->member_total_size<1) {
			goto done;
		}
		pos += md->member_total_size;
	}

done:

	if(md) {
		de_arch_destroy_md(c, md);
	}
	if(d) {
		if(d->need_errmsg) {
			de_err(c, "Bad or unsupported TC file");
		}
		de_arch_destroy_lctx(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
callq 0xf16ce
movq %rax, %r15
andl $0x0, 0x10(%rax)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%r15)
pushq $0x1
popq %rbp
movq %rsp, %r14
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r15, 0x8(%rsp)
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r13
jge 0x6d2e1
testq %r12, %r12
je 0x6d01f
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf1630
movq %rax, %r12
movq %r13, 0x18(%rax)
movq %rbp, 0x10(%rax)
movq %r13, (%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xdebae
movq 0x18(%r12), %rdx
movq %rbx, %rdi
leaq 0xc1818(%rip), %rsi     # 0x12e86d
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3f2a
movq %r15, %r14
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0xa4960(%rip), %rsi     # 0x1119e4
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
testb %r15b, %r15b
je 0x6d252
cmpq %r15, 0x10(%r12)
jne 0x6d25c
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movq 0x58(%r12), %rcx
movq 0x8(%rsp), %r14
movl 0x18(%r14), %r9d
pushq $0x8
popq %rdx
pushq $0x1
popq %r8
callq 0xe4c9a
addq $0x8, (%rsp)
movq 0x58(%r12), %rdi
callq 0xead03
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movl 0x18(%r14), %r9d
pushq $0x3
popq %rdx
movq %rax, %rcx
pushq $0x1
popq %r8
callq 0xe4c9a
addq $0x3, (%rsp)
movq %r15, %rdi
callq 0xead03
movq %r15, %rdi
callq 0xeaf8a
testl %eax, %eax
je 0x6d12c
movq 0x58(%r12), %rdi
pushq $0x2e
popq %rsi
callq 0xeada5
movq 0x58(%r12), %rdi
movq %r15, %rsi
callq 0xead71
movq 0x58(%r12), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xc191e(%rip), %rsi     # 0x12ea5e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %rsp, %r14
movq %r14, %rsi
callq 0xe3f2a
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x9df36(%rip), %rsi     # 0x10b09c
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3f2a
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xac3cd(%rip), %rsi     # 0x119553
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3f2a
cmpb $0x1, %al
jne 0x6d2af
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
pushq $0x3
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xe424b
movq %rax, 0x30(%r12)
addq $0x3, (%rsp)
movq (%r12), %rdi
leaq 0xa40fc(%rip), %rsi     # 0x1112c7
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3f2a
movzbl %al, %edx
movl %edx, 0x90(%r12)
movq %rbx, %rdi
leaq 0xabab6(%rip), %rsi     # 0x118cac
xorl %eax, %eax
callq 0xde896
movq (%rsp), %rdx
movq %rdx, 0x40(%r12)
movq %rbx, %rdi
leaq 0xac352(%rip), %rsi     # 0x119562
xorl %eax, %eax
callq 0xde896
movq 0x30(%r12), %rax
addq 0x40(%r12), %rax
subq 0x18(%r12), %rax
movq %rax, 0x28(%r12)
movl 0x90(%r12), %edx
cmpl $0x2, %edx
jb 0x6d2c3
movq %rbx, %rdi
leaq 0x995ac(%rip), %rsi     # 0x1067f2
xorl %eax, %eax
callq 0xdf2a5
jmp 0x6d2da
movl $0x1, 0x50(%r14)
jmp 0x6d26e
movq 0x8(%rsp), %r14
movl $0x1, 0x38(%r14)
movb $0x1, 0x14(%r14)
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xeaf3c
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpl $0x0, 0x50(%r14)
movq %r14, %r15
jne 0x6d2f3
cmpl $0x0, 0x38(%r15)
jne 0x6d2f3
movq 0x28(%r12), %rax
addq %rax, %r13
incq %rbp
testq %rax, %rax
movq %rsp, %r14
jg 0x6d001
jmp 0x6d2f3
movq 0x8(%rsp), %r14
movl $0x1, 0x38(%r14)
movb $0x1, 0x14(%r14)
jmp 0x6d271
leaq 0xd47(%rip), %rax       # 0x6e011
movq %rax, 0xa8(%r12)
movq %r12, %rdi
callq 0xf1a85
movq 0x8(%rsp), %r14
jmp 0x6d271
movl $0x1, 0x38(%r15)
movb $0x1, 0x14(%r15)
testq %r12, %r12
je 0x6d305
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
cmpb $0x0, 0x14(%r15)
je 0x6d316
leaq 0xac22c(%rip), %rsi     # 0x119538
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf16e7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq