// File: /workspace/github_c_makefile_star2_O3/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 0xfd4b2
movq %rax, %r12
movl $0x0, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xeb220
movl %eax, 0x18(%r12)
movq 0x18(%rbx), %rax
cmpq $0x0, 0x18(%rax)
jle 0x711c6
movl $0x1, %ebp
movq %rsp, %r14
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r12, 0x8(%rsp)
testq %r15, %r15
je 0x70efd
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfd460
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfd414
movq %rax, %r15
movq %r13, 0x18(%rax)
movq %rbp, 0x10(%rax)
movq %r13, (%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe8a1c
movq 0x18(%r15), %rdx
movq %rbx, %rdi
leaq 0xcac2b(%rip), %rsi     # 0x13bb5d
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeeb4b
movq %r12, %r14
movzbl %al, %r12d
movq %rbx, %rdi
leaq 0xadb51(%rip), %rsi     # 0x11eab4
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
testb %r12b, %r12b
je 0x7112e
cmpq %r12, 0x10(%r15)
jne 0x71138
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movq 0x58(%r15), %rcx
movq 0x8(%rsp), %r14
movl 0x18(%r14), %r9d
movl $0x8, %edx
movl $0x1, %r8d
callq 0xefbd7
addq $0x8, (%rsp)
movq 0x58(%r15), %rdi
callq 0xf64a0
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r12
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movl 0x18(%r14), %r9d
movl $0x3, %edx
movq %rax, %rcx
movl $0x1, %r8d
callq 0xefbd7
addq $0x3, (%rsp)
movq %r12, %rdi
callq 0xf64a0
movq %r12, %rdi
callq 0xf67a3
testl %eax, %eax
je 0x71010
movq 0x58(%r15), %rdi
movl $0x2e, %esi
callq 0xf6542
movq 0x58(%r15), %rdi
movq %r12, %rsi
callq 0xf6509
movq 0x58(%r15), %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0xcad2b(%rip), %rsi     # 0x13bd4e
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %rsp, %r14
movq %r14, %rsi
callq 0xeeb4b
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xa7143(%rip), %rsi     # 0x11818c
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeeb4b
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xb56ea(%rip), %rsi     # 0x126753
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeeb4b
cmpb $0x1, %al
jne 0x71195
movq 0x18(%rbx), %rdi
movq (%rsp), %rsi
movl $0x3, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xef0f6
movq %rax, 0x30(%r15)
addq $0x3, (%rsp)
movq (%r15), %rdi
leaq 0xad2ed(%rip), %rsi     # 0x11e39b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeeb4b
movzbl %al, %edx
movl %edx, 0x90(%r15)
movq %rbx, %rdi
leaq 0xb4dd4(%rip), %rsi     # 0x125eac
xorl %eax, %eax
callq 0xe8617
movq (%rsp), %rdx
movq %rdx, 0x40(%r15)
movq %rbx, %rdi
leaq 0xb5671(%rip), %rsi     # 0x126762
xorl %eax, %eax
callq 0xe8617
movq 0x30(%r15), %rax
addq 0x40(%r15), %rax
subq 0x18(%r15), %rax
movq %rax, 0x28(%r15)
movl 0x90(%r15), %edx
cmpl $0x2, %edx
jb 0x711a9
movq %rbx, %rdi
leaq 0xa2730(%rip), %rsi     # 0x113852
xorl %eax, %eax
callq 0xe9295
jmp 0x711bf
movl $0x1, 0x50(%r14)
jmp 0x7114a
movq 0x8(%rsp), %r14
movl $0x1, 0x38(%r14)
movb $0x1, 0x14(%r14)
xorl %r12d, %r12d
movq %r12, %rdi
callq 0xf6753
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpl $0x0, 0x50(%r14)
movq %r14, %r12
jne 0x711e6
cmpl $0x0, 0x38(%r12)
jne 0x711e6
movq 0x28(%r15), %rax
testq %rax, %rax
jle 0x711e6
addq %rax, %r13
movq 0x18(%rbx), %rax
incq %rbp
cmpq 0x18(%rax), %r13
movq %rsp, %r14
jl 0x70eed
jmp 0x711d7
movq 0x8(%rsp), %r14
movl $0x1, 0x38(%r14)
movb $0x1, 0x14(%r14)
jmp 0x7114d
leaq 0xccb(%rip), %rax       # 0x71e7b
movq %rax, 0xa8(%r15)
movq %r15, %rdi
callq 0xfd85e
movq 0x8(%rsp), %r14
jmp 0x7114d
movl $0x1, 0x38(%r12)
movb $0x1, 0x14(%r12)
jmp 0x711f1
movl $0x1, 0x38(%r12)
movb $0x1, 0x14(%r12)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfd460
cmpb $0x0, 0x14(%r12)
je 0x7120a
leaq 0xb5538(%rip), %rsi     # 0x126738
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
movq %r12, %rsi
callq 0xfd4cd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq