// File: 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
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0xd970
movq -0x180(%rbp), %rax
movl $0xffffffff, 0x68(%rax) # imm = 0xFFFFFFFF
leaq -0x31(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x3460
movq -0x178(%rbp), %rdx
leaq 0x7cd6(%rip), %rsi      # 0x1b374
leaq -0x30(%rbp), %rdi
callq 0x8060
jmp 0x136a9
leaq -0x69(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x3460
movq -0x188(%rbp), %rdx
leaq 0x8600(%rip), %rsi      # 0x1bcc7
leaq -0x68(%rbp), %rdi
callq 0x8060
jmp 0x136d2
leaq -0x30(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xcd80
jmp 0x136e1
leaq -0x68(%rbp), %rdi
callq 0x3160
leaq -0x69(%rbp), %rdi
callq 0x32b0
leaq -0x30(%rbp), %rdi
callq 0x3160
leaq -0x31(%rbp), %rdi
callq 0x32b0
movl $0xa, %edi
callq 0x3390
movq -0x180(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x15d10
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x15d40
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x15d70
testb $0x1, %al
jne 0x13754
jmp 0x13933
leaq -0x80(%rbp), %rdi
callq 0x15db0
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
testb $0x1, 0x2c(%rax)
je 0x137c7
jmp 0x138c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x137b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x137a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3160
leaq -0x69(%rbp), %rdi
callq 0x32b0
leaq -0x30(%rbp), %rdi
callq 0x3160
leaq -0x31(%rbp), %rdi
callq 0x32b0
jmp 0x13c28
movq -0x90(%rbp), %rax
testb $0x1, 0x2d(%rax)
jne 0x137d9
jmp 0x138c8
movq -0x180(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x12a60
movq -0x180(%rbp), %rdi
movq -0x90(%rbp), %rax
movzbl 0x20(%rax), %esi
callq 0x12ed0
movq -0x180(%rbp), %rdi
movq -0x90(%rbp), %rax
movzbl 0x20(%rax), %esi
callq 0x13170
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x3460
movq -0x190(%rbp), %rdx
leaq 0x7b39(%rip), %rsi      # 0x1b374
leaq -0xb0(%rbp), %rdi
callq 0x8060
jmp 0x13849
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0x3460
movq -0x198(%rbp), %rdx
leaq 0x845d(%rip), %rsi      # 0x1bcc7
leaq -0xd8(%rbp), %rdi
callq 0x8060
jmp 0x13878
leaq -0xb0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xcd80
jmp 0x1388d
leaq -0xd8(%rbp), %rdi
callq 0x3160
leaq -0xd9(%rbp), %rdi
callq 0x32b0
leaq -0xb0(%rbp), %rdi
callq 0x3160
leaq -0xb1(%rbp), %rdi
callq 0x32b0
movq -0x90(%rbp), %rax
movb $0x1, 0x2c(%rax)
leaq -0x80(%rbp), %rdi
callq 0x15e10
jmp 0x1373b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x13922
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1390a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3160
leaq -0xd9(%rbp), %rdi
callq 0x32b0
leaq -0xb0(%rbp), %rdi
callq 0x3160
leaq -0xb1(%rbp), %rdi
callq 0x32b0
jmp 0x13c28
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x13b1a
movq 0x11677(%rip), %rax     # 0x24fc0
movq (%rax), %rsi
leaq 0x8379(%rip), %rdi      # 0x1bccc
callq 0x32e0
movq -0x180(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x15d10
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x15d40
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x15d70
testb $0x1, %al
jne 0x139a9
jmp 0x13a25
leaq -0xf0(%rbp), %rdi
callq 0x15db0
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
testb $0x1, 0x2d(%rax)
jne 0x139cb
jmp 0x13a14
movq -0x100(%rbp), %rdi
callq 0x30f0
movq %rax, %rsi
movq -0x100(%rbp), %rax
movzbl 0x20(%rax), %edx
movq -0x100(%rbp), %rax
movzbl 0x21(%rax), %ecx
movq -0x100(%rbp), %rax
movl 0x24(%rax), %r8d
movq -0x100(%rbp), %rax
movl 0x28(%rax), %r9d
leaq 0x82cb(%rip), %rdi      # 0x1bcd8
movb $0x0, %al
callq 0x3060
leaq -0xf0(%rbp), %rdi
callq 0x15e10
jmp 0x13990
movq 0x11594(%rip), %rax     # 0x24fc0
movq (%rax), %rsi
leaq 0x82bf(%rip), %rdi      # 0x1bcf5
callq 0x32e0
movq 0x1157e(%rip), %rax     # 0x24fc0
movq (%rax), %rsi
leaq 0x82ac(%rip), %rdi      # 0x1bcf8
callq 0x32e0
movq -0x180(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rdi
callq 0xa6a0
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
callq 0xa490
movq %rax, -0x118(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x15c30
testb $0x1, %al
jne 0x13aa2
jmp 0x13b10
leaq -0x110(%rbp), %rdi
callq 0xab10
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rdi
callq 0x30f0
movq %rax, %rsi
movq -0x120(%rbp), %rax
movzbl 0x20(%rax), %edx
movq -0x120(%rbp), %rax
movzbl 0x21(%rax), %ecx
movq -0x120(%rbp), %rax
movzbl 0x22(%rax), %r8d
movq -0x120(%rbp), %rax
movl 0x24(%rax), %r9d
leaq 0x820b(%rip), %rdi      # 0x1bd03
movb $0x0, %al
callq 0x3060
leaq -0x110(%rbp), %rdi
callq 0x15cf0
jmp 0x13a89
movl $0xa, %edi
callq 0x3390
leaq -0x141(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x3460
movq -0x1a0(%rbp), %rdx
leaq 0x7839(%rip), %rsi      # 0x1b374
leaq -0x140(%rbp), %rdi
callq 0x8060
jmp 0x13b49
leaq -0x169(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x3460
movq -0x1a8(%rbp), %rdx
leaq 0x81b6(%rip), %rsi      # 0x1bd20
leaq -0x168(%rbp), %rdi
callq 0x8060
jmp 0x13b78
leaq -0x140(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xcd80
jmp 0x13b8d
leaq -0x168(%rbp), %rdi
callq 0x3160
leaq -0x169(%rbp), %rdi
callq 0x32b0
leaq -0x140(%rbp), %rdi
callq 0x3160
leaq -0x141(%rbp), %rdi
callq 0x32b0
movl $0xa, %edi
callq 0x3390
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x13c1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x13c04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x3160
leaq -0x169(%rbp), %rdi
callq 0x32b0
leaq -0x140(%rbp), %rdi
callq 0x3160
leaq -0x141(%rbp), %rdi
callq 0x32b0
movq -0x40(%rbp), %rdi
callq 0x3440
nopw %cs:(%rax,%rax)