// File: /workspace/github_cpp_makefile_star2_O2/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 0x5fc6
orl $-0x1, 0x68(%rbx)
leaq 0x30f9(%rip), %rsi      # 0xb3a0
leaq 0x28(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0x48d4
leaq 0x3a8e(%rip), %rsi      # 0xbd4b
leaq 0x8(%rsp), %rdi
leaq 0x2(%rsp), %rdx
callq 0x48d4
movl %ebp, 0x4(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x57e2
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x20d0
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x20d0
pushq $0xa
popq %rdi
callq 0x2280
movq 0x50(%rbx), %r12
movq 0x58(%rbx), %r13
leaq 0x2(%rsp), %rbp
cmpq %r13, %r12
je 0x839b
cmpb $0x0, 0x2c(%r12)
jne 0x8392
cmpb $0x1, 0x2d(%r12)
jne 0x8392
movq %r12, %rsi
callq 0x7c4a
movzbl 0x20(%r12), %esi
movq %rbx, %rdi
callq 0x7ed8
movzbl 0x20(%r12), %esi
movq %rbx, %rdi
callq 0x7ffe
movq %r15, %rdi
leaq 0x304b(%rip), %rsi      # 0xb3a0
leaq 0x3(%rsp), %rdx
callq 0x48d4
movq %r14, %rdi
leaq 0x39e2(%rip), %rsi      # 0xbd4b
movq %rbp, %rdx
callq 0x48d4
movq %r15, %rdi
movq %r14, %rsi
callq 0x57e2
movq %r14, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x20d0
movb $0x1, 0x2c(%r12)
addq $0x50, %r12
jmp 0x830e
testb $0x1, 0x4(%rsp)
je 0x8462
movq 0x9c1b(%rip), %r15      # 0x11fc8
movq (%r15), %rsi
leaq 0x3999(%rip), %rdi      # 0xbd50
callq 0x21f0
movq 0x50(%rbx), %r12
movq 0x58(%rbx), %r13
leaq 0x3991(%rip), %r14      # 0xbd5c
cmpq %r13, %r12
je 0x8402
cmpb $0x1, 0x2d(%r12)
jne 0x83fc
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
jmp 0x83cb
movq (%r15), %rsi
leaq 0x396d(%rip), %rdi      # 0xbd79
callq 0x21f0
movq (%r15), %rsi
leaq 0x3961(%rip), %rdi      # 0xbd7c
callq 0x21f0
movq 0x38(%rbx), %r14
movq 0x40(%rbx), %r15
leaq 0x3958(%rip), %rbx      # 0xbd87
cmpq %r15, %r14
je 0x845a
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
jmp 0x842f
pushq $0xa
popq %rdi
callq 0x2280
leaq 0x2f37(%rip), %rsi      # 0xb3a0
leaq 0x28(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0x48d4
leaq 0x3925(%rip), %rsi      # 0xbda4
leaq 0x8(%rsp), %rdi
leaq 0x2(%rsp), %rdx
callq 0x48d4
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x57e2
leaq 0x8(%rsp), %rdi
callq 0x20d0
leaq 0x28(%rsp), %rdi
callq 0x20d0
pushq $0xa
popq %rdi
callq 0x2280
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x84d4
jmp 0x84e3
jmp 0x84f2
jmp 0x84d4
jmp 0x84e3
jmp 0x84f2
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x20d0
jmp 0x84e6
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20d0
jmp 0x84f5
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2300