// File: /workspace/github_cpp_makefile_star2_O3/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 0x81ae
movl $0xffffffff, 0x68(%rbx) # imm = 0xFFFFFFFF
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x450b(%rip), %rdx      # 0xf344
leaq 0x20(%rsp), %rdi
movq %rdx, %rsi
callq 0x6a64
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4ea5(%rip), %rsi      # 0xfcfb
leaq 0x4ea2(%rip), %rdx      # 0xfcff
movq %rsp, %rdi
callq 0x6a64
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x752e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xae8d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movl %ebp, 0x44(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xaead
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 0xaf9a
leaq 0x4475(%rip), %r15      # 0xf344
leaq 0x20(%rsp), %r12
movq %rsp, %r13
cmpb $0x0, 0x2c(%r14)
jne 0xaf8d
cmpb $0x1, 0x2d(%r14)
jne 0xaf8d
movq %r14, %rsi
callq 0xa59e
movzbl 0x20(%r14), %esi
movq %rbx, %rdi
callq 0xa8c4
movzbl 0x20(%r14), %esi
movq %rbx, %rdi
callq 0xaa76
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x6a64
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rdi
leaq 0x4dc1(%rip), %rsi      # 0xfcfb
leaq 0x4dbe(%rip), %rdx      # 0xfcff
callq 0x6a64
movq %r12, %rdi
movq %r13, %rsi
callq 0x752e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xaf6c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xaf88
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
movb $0x1, 0x2c(%r14)
addq $0x50, %r14
cmpq %rbp, %r14
jne 0xaed7
testb $0x1, 0x44(%rsp)
je 0xb069
movq 0x901c(%rip), %r15      # 0x13fc8
movq (%r15), %rsi
leaq 0x4d4a(%rip), %rdi      # 0xfd00
callq 0x21e0
movq 0x50(%rbx), %r12
movq 0x58(%rbx), %r13
cmpq %r13, %r12
je 0xb004
leaq 0x4d3d(%rip), %r14      # 0xfd0c
cmpb $0x1, 0x2d(%r12)
jne 0xaffb
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 0xafcf
movq (%r15), %rsi
leaq 0x4d1b(%rip), %rdi      # 0xfd29
callq 0x21e0
movq (%r15), %rsi
leaq 0x4d0f(%rip), %rdi      # 0xfd2c
callq 0x21e0
movq 0x38(%rbx), %r14
movq 0x40(%rbx), %r15
cmpq %r15, %r14
je 0xb05f
leaq 0x4d01(%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 0xb036
movl $0xa, %edi
callq 0x2240
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
movq %rax, (%rdi)
leaq 0x42c7(%rip), %rdx      # 0xf344
movq %rdx, %rsi
callq 0x6a64
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
leaq 0x4cbd(%rip), %rsi      # 0xfd54
leaq 0x4cbc(%rip), %rdx      # 0xfd5a
callq 0x6a64
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x752e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb0cb
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xb0e7
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 0xb10c
jmp 0xb12c
jmp 0xb14d
jmp 0xb10c
jmp 0xb12c
jmp 0xb14d
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb12f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xb12f
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xb150
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0xb150
movq %rax, %rbx
movq %rbx, %rdi
callq 0x22c0