// File: /workspace/github_cpp_makefile_star2_O1/ksherlock[P]wdc-utils/zrdz_disassembler.cpp
// Function: zrdz_disassembler::back_matter(unsigned int)
void zrdz_disassembler::back_matter(unsigned flags) {

	flush();
	_section = -1;


	// todo -- print remaining symbols.
	// todo -- print any empty sections?

	emit("", "ends");
	putchar('\n');

	for (auto &e : _sections) {
		if (e.processed) continue;
		if (!e.valid) continue;

		print_section(e);
		print_globals(e.number);
		print_equs(e.number);
		emit("","ends");
		e.processed = true;
		// ...check for symbols?
	}


	if (flags & 0x01) {
		fputs("; sections\n", stdout);
		for (const auto &e : _sections) {
			if (!e.valid) continue;
			printf("; %-20s %02x %02x %04x %04x\n",
				e.name.c_str(), e.number, e.flags, e.size, e.org);
		}

		fputs(";\n", stdout);

		fputs("; symbols\n", stdout);
		for (const auto &s : _symbols) {
			printf("; %-20s %02x %02x %02x %08x\n",
				s.name.c_str(), s.type, s.flags, s.section, s.offset);
		}
		putchar('\n');
	}


	emit("", "endmod");
	putchar('\n');
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0x82d4
movl $0xffffffff, 0x68(%rbx) # imm = 0xFFFFFFFF
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4377(%rip), %rdx      # 0xf344
leaq 0x20(%rsp), %rdi
movq %rdx, %rsi
callq 0x6b90
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4d11(%rip), %rsi      # 0xfcfb
leaq 0x4d0e(%rip), %rdx      # 0xfcff
movq %rsp, %rdi
callq 0x6b90
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x766e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb021
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movl %ebp, 0x44(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xb041
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
movl $0xa, %edi
callq 0x2240
movq 0x50(%rbx), %r14
movq 0x58(%rbx), %rbp
cmpq %rbp, %r14
je 0xb12e
leaq 0x42e1(%rip), %r15      # 0xf344
leaq 0x20(%rsp), %r12
movq %rsp, %r13
cmpb $0x0, 0x2c(%r14)
jne 0xb121
cmpb $0x1, 0x2d(%r14)
jne 0xb121
movq %r14, %rsi
callq 0xa720
movzbl 0x20(%r14), %esi
movq %rbx, %rdi
callq 0xaa60
movzbl 0x20(%r14), %esi
movq %rbx, %rdi
callq 0xac0e
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x6b90
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rdi
leaq 0x4c2d(%rip), %rsi      # 0xfcfb
leaq 0x4c2a(%rip), %rdx      # 0xfcff
callq 0x6b90
movq %r12, %rdi
movq %r13, %rsi
callq 0x766e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb100
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xb11c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
movb $0x1, 0x2c(%r14)
addq $0x50, %r14
cmpq %rbp, %r14
jne 0xb06b
testb $0x1, 0x44(%rsp)
je 0xb1fd
movq 0x9e88(%rip), %r15      # 0x14fc8
movq (%r15), %rsi
leaq 0x4bb6(%rip), %rdi      # 0xfd00
callq 0x21e0
movq 0x50(%rbx), %r12
movq 0x58(%rbx), %r13
cmpq %r13, %r12
je 0xb198
leaq 0x4ba9(%rip), %r14      # 0xfd0c
cmpb $0x1, 0x2d(%r12)
jne 0xb18f
movq (%r12), %rsi
movzbl 0x20(%r12), %edx
movzbl 0x21(%r12), %ecx
movl 0x24(%r12), %r8d
movl 0x28(%r12), %r9d
movq %r14, %rdi
xorl %eax, %eax
callq 0x2040
addq $0x50, %r12
cmpq %r13, %r12
jne 0xb163
movq (%r15), %rsi
leaq 0x4b87(%rip), %rdi      # 0xfd29
callq 0x21e0
movq (%r15), %rsi
leaq 0x4b7b(%rip), %rdi      # 0xfd2c
callq 0x21e0
movq 0x38(%rbx), %r14
movq 0x40(%rbx), %r15
cmpq %r15, %r14
je 0xb1f3
leaq 0x4b6d(%rip), %rbx      # 0xfd37
movq (%r14), %rsi
movzbl 0x20(%r14), %edx
movzbl 0x21(%r14), %ecx
movzbl 0x22(%r14), %r8d
movl 0x24(%r14), %r9d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2040
addq $0x28, %r14
cmpq %r15, %r14
jne 0xb1ca
movl $0xa, %edi
callq 0x2240
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
movq %rax, (%rdi)
leaq 0x4133(%rip), %rdx      # 0xf344
movq %rdx, %rsi
callq 0x6b90
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
leaq 0x4b29(%rip), %rsi      # 0xfd54
leaq 0x4b28(%rip), %rdx      # 0xfd5a
callq 0x6b90
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x766e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb25f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xb27b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
movl $0xa, %edi
callq 0x2240
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb2a0
jmp 0xb2c0
jmp 0xb2e1
jmp 0xb2a0
jmp 0xb2c0
jmp 0xb2e1
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb2c3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xb2c3
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xb2e4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xb2e4
movq %rax, %rbx
movq %rbx, %rdi
callq 0x22c0