// File: /workspace/github_cpp_makefile_star2_O3/ksherlock[P]wdc-utils/omf.cpp
// Function: save_omf(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<omf::segment, std::allocator<omf::segment>>&, unsigned int)
void save_omf(const std::string &path, std::vector<omf::segment> &segments, unsigned flags) {

	// expressload doesn't support links to other files. 
	// fortunately, we don't either.

	std::vector<uint8_t> expr_headers;
	std::vector<unsigned> expr_offsets;


	bool compress = !(flags & OMF_NO_COMPRESS);
	bool super = !(flags & OMF_NO_SUPER);
	bool expressload = !(flags & OMF_NO_EXPRESS);
	bool v1 = flags & OMF_V1;

	if (v1) {
		expressload = false;
		super = false;
	}

	int fd;
	fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
	if (fd < 0) {
		err(EX_CANTCREAT, "Unable to open %s", path.c_str());
	}


	uint32_t offset = 0;
	if (expressload) {
		for (auto &s : segments) {
			s.segnum++;
			for (auto &r : s.intersegs) r.segment++;
		}

		// calculate express load segment size.
		// sizeof includes the trailing 0, so no need to add in byte size.
		offset = sizeof(omf_header) + 10 + sizeof("~ExpressLoad");

		offset += 6; // lconst + end
		offset += 6;  // header.
		for (auto &s : segments) {
			offset += 8 + 2;
			offset += sizeof(omf_express_header) + 10;
			offset += s.segname.length() + 1;
		}

		lseek(fd, offset, SEEK_SET);
	}


	for (auto &s : segments) {
		omf_header h;
		h.length = s.data.size() + s.reserved_space;
		h.kind = s.kind;
		h.banksize = s.data.size() > 0xffff ? 0x0000 : 0x010000;
		h.segnum = s.segnum;
		h.alignment = s.alignment;
		h.reserved_space = s.reserved_space;
		h.org = s.org;

		uint32_t reserved_space = 0;
		if (expressload) {
			std::swap(reserved_space, h.reserved_space);
		}

		// length field INCLUDES reserved space.  Express expand reserved space.


		std::vector<uint8_t> data;

		// push segname and load name onto data.
		// data.insert(data.end(), 10, ' ');
		push(data, s.loadname, 10);
		push(data, s.segname);

		h.dispname = sizeof(omf_header);
		h.dispdata = sizeof(omf_header) + data.size();



		uint32_t lconst_offset = offset + sizeof(omf_header) + data.size() + 5;
		uint32_t lconst_size = s.data.size() + reserved_space;


		//lconst record
		push(data, (uint8_t)omf::LCONST);
		push(data, (uint32_t)lconst_size);

		size_t data_offset = data.size();

		data.insert(data.end(), s.data.begin(), s.data.end());

		if (reserved_space) {
			data.insert(data.end(), reserved_space, 0);
		}

		uint32_t reloc_offset = offset + sizeof(omf_header) + data.size();
		uint32_t reloc_size = 0;

		reloc_size = add_relocs(data, data_offset, s, compress, super);

		// end-of-record
		push(data, (uint8_t)omf::END);

		h.bytecount = data.size() + sizeof(omf_header);

		if (expressload) {

			expr_offsets.emplace_back(expr_headers.size());

			if (lconst_size == 0) lconst_offset = 0;
			if (reloc_size == 0) reloc_offset = 0;


			push(expr_headers, (uint32_t)lconst_offset);
			push(expr_headers, (uint32_t)lconst_size);
			push(expr_headers, (uint32_t)reloc_offset);
			push(expr_headers, (uint32_t)reloc_size);

			push(expr_headers, h.unused1);
			push(expr_headers, h.lablen);
			push(expr_headers, h.numlen);
			push(expr_headers, h.version);
			push(expr_headers, h.banksize);
			push(expr_headers, h.kind);
			push(expr_headers, h.unused2);
			push(expr_headers, h.org);
			push(expr_headers, h.alignment);
			push(expr_headers, h.numsex);
			push(expr_headers, h.unused3);
			push(expr_headers, h.segnum);
			push(expr_headers, h.entry);
			push(expr_headers, (uint16_t)(h.dispname));
			push(expr_headers, h.dispdata);

			expr_headers.insert(expr_headers.end(), 10, ' ');
			push(expr_headers, s.segname);
		}

		if (v1) to_v1(h);
		to_little(h);

		offset += write(fd, &h, sizeof(h));
		offset += write(fd, data.data(), data.size());

		// version 1 needs 512-byte padding for all but final segment.
		if (v1 && &s != &segments.back()) {
			static uint8_t zero[512];
			offset += write(fd, zero, 512 - (offset & 511) );
		}
	}

	if (expressload) {
		omf_header h;
		h.segnum = 1;
		h.banksize = 0x00010000;
		h.kind = 0x8001;
		h.dispname = 0x2c;
		h.dispdata = 0x43;

		unsigned fudge = 10 * segments.size();

		h.length = 6 + expr_headers.size() + fudge;

		std::vector<uint8_t> data;
		data.insert(data.begin(), 10, ' ');
		push(data, std::string("~ExpressLoad"));
		push(data, (uint8_t)0xf2); // lconst.
		push(data, (uint32_t)h.length);

		push(data, (uint32_t)0); // reserved
		push(data, (uint16_t)(segments.size() - 1)); // seg count - 1


		for (auto &offset : expr_offsets) {
			push(data, (uint16_t)(fudge + offset));
			push(data, (uint16_t)0);
			push(data, (uint32_t)0);
			fudge -= 8;
		}

		for (auto &s : segments) {
			push(data, (uint16_t)s.segnum);
		}

		data.insert(data.end(), expr_headers.begin(), expr_headers.end());
		push(data, (uint8_t)0); // end.

		h.bytecount = data.size() + sizeof(omf_header);

		to_little(h);
		lseek(fd, 0, SEEK_SET);
		write(fd, &h, sizeof(h));
		write(fd, data.data(), data.size());

	}

	close(fd);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %edx, %ebp
movq %rsi, 0xb0(%rsp)
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movq (%rdi), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x21f0
movl %eax, 0xc(%rsp)
testl %eax, %eax
js 0xd420
xorl %ebx, %ebx
testb $0x9, %bpl
jne 0xcbb2
movq 0xb0(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movl $0x4f, %ebx
cmpq %rcx, %rax
je 0xcba5
movq %rax, %rdx
incw (%rdx)
movq 0x68(%rdx), %rsi
movq 0x70(%rdx), %rdi
cmpq %rdi, %rsi
je 0xcb7c
incw 0xa(%rsi)
addq $0x10, %rsi
jmp 0xcb6d
addq $0x98, %rdx
cmpq %rcx, %rdx
jne 0xcb62
cmpq %rcx, %rax
je 0xcba5
movl $0x4f, %ebx
movl 0x38(%rax), %edx
addl %edx, %ebx
addl $0x45, %ebx
addq $0x98, %rax
cmpq %rcx, %rax
jne 0xcb92
movl %ebx, %esi
movl 0xc(%rsp), %edi
xorl %edx, %edx
callq 0x2420
movq 0xb0(%rsp), %rax
movq (%rax), %r13
movq 0x8(%rax), %rax
movq %rax, 0xe0(%rsp)
cmpq %rax, %r13
je 0xd103
leaq 0x50(%rsp), %r14
movl %ebp, 0x74(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x7e(%rsp)
movq %rcx, 0x78(%rsp)
movw $0x204, 0x86(%rsp)      # imm = 0x204
leaq 0x8e(%rsp), %rax
movq %rcx, 0xe(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x58(%r13), %rcx
subq 0x50(%r13), %rcx
xorl %edx, %edx
cmpq $0x10000, %rcx          # imm = 0x10000
setb %dl
movl 0x8(%r13), %eax
addl %eax, %ecx
shll $0x10, %edx
movl %ecx, 0x80(%rsp)
movzwl 0x2(%r13), %ecx
movw %cx, 0x8c(%rsp)
movl %edx, 0x88(%rsp)
movzwl (%r13), %ecx
movw %cx, 0x9a(%rsp)
movl 0x4(%r13), %ecx
movl %ecx, 0x94(%rsp)
movl %eax, 0x7c(%rsp)
movl 0xc(%r13), %ecx
movl %ecx, 0x90(%rsp)
movl $0x0, %r12d
testb $0x9, %bpl
jne 0xcc79
movl $0x0, 0x7c(%rsp)
movl %eax, %r12d
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
leaq 0x10(%r13), %rsi
movl $0xa, %edx
movq %r14, %rdi
callq 0xc0cb
leaq 0x30(%r13), %rsi
movq %r14, %rdi
movq %rsi, 0xe8(%rsp)
callq 0xc08b
movw $0x2c, 0xa0(%rsp)
movl 0x58(%rsp), %r15d
subl 0x50(%rsp), %r15d
leal 0x2c(%r15), %eax
movl %eax, 0xbc(%rsp)
movw %ax, 0xa2(%rsp)
movq %r13, %rax
movl 0x58(%r13), %r13d
movq %rax, 0xa8(%rsp)
subl 0x50(%rax), %r13d
movq %r14, %rdi
movl $0xf2, %esi
callq 0xbfe4
addl %r12d, %r13d
movq %r14, %rdi
movl %r13d, %esi
callq 0xc037
movq 0x58(%rsp), %rsi
movq %rsi, %rbp
subq 0x50(%rsp), %rbp
movq 0xa8(%rsp), %rax
movq 0x50(%rax), %rdx
movq 0x58(%rax), %rcx
movq %r14, %rdi
callq 0xdcf6
testl %r12d, %r12d
je 0xcd47
movq 0x58(%rsp), %rsi
movl %r12d, %edx
movb $0x0, 0x10(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rcx
callq 0x9122
movq %rbx, 0xf0(%rsp)
movl %ebx, %ebx
addq $0x2c, %rbx
xorl %r8d, %r8d
movl 0x74(%rsp), %eax
testb $0x3, %al
sete %r8b
xorl %ecx, %ecx
testb $0x4, %al
sete %cl
movl 0x58(%rsp), %r12d
addl %ebx, %r12d
subl 0x50(%rsp), %r12d
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
movq 0xa8(%rsp), %rdx
callq 0xc15f
movl %eax, %ebp
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0xbfe4
movl 0x58(%rsp), %eax
subl 0x50(%rsp), %eax
leal 0x2c(%rax), %ecx
movl %ecx, 0x78(%rsp)
movl 0x74(%rsp), %ecx
testb $0x9, %cl
je 0xcdeb
testb $0x1, %cl
je 0xd039
movb $0x1, 0x87(%rsp)
addl $0x22b, %eax            # imm = 0x22B
shrl $0x9, %eax
movl %eax, 0x78(%rsp)
movb 0x8c(%rsp), %al
movb %al, 0x84(%rsp)
movw $0x0, 0x8c(%rsp)
jmp 0xd039
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xc8(%rsp), %rsi
cmpq 0xd0(%rsp), %rsi
je 0xce1c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xc8(%rsp)
jmp 0xce2e
leaq 0xc0(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0xdede
leal (%r15,%rbx), %esi
addl $0x5, %esi
testl %r13d, %r13d
cmovel %r13d, %esi
testl %ebp, %ebp
cmovel %ebp, %r12d
leaq 0x30(%rsp), %rdi
callq 0xc037
leaq 0x30(%rsp), %rdi
movl %r13d, %esi
callq 0xc037
leaq 0x30(%rsp), %rdi
movl %r12d, %esi
callq 0xc037
leaq 0x30(%rsp), %rdi
movl %ebp, %esi
callq 0xc037
movzbl 0x84(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xbfe4
movzbl 0x85(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xbfe4
movzbl 0x86(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xbfe4
movzbl 0x87(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xbfe4
movl 0x88(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xc037
movzwl 0x8c(%rsp), %ebx
movb %bl, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movb %bh, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movzwl 0x8e(%rsp), %ebx
movb %bl, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movb %bh, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movl 0x90(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xc037
movl 0x94(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xc037
movzbl 0x98(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xbfe4
movzbl 0x99(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xbfe4
movzwl 0x9a(%rsp), %ebx
movb %bl, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movb %bh, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movl 0x9c(%rsp), %esi
leaq 0x30(%rsp), %rdi
callq 0xc037
movb $0x2c, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movb $0x0, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movl 0xbc(%rsp), %eax
movb %al, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movl 0xbc(%rsp), %eax
movb %ah, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xd724
movq 0x38(%rsp), %rsi
movb $0x20, 0x10(%rsp)
movl $0xa, %edx
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rcx
callq 0x9122
movq %rbx, %rdi
movq 0xe8(%rsp), %rsi
callq 0xc08b
movl $0x2c, %edx
movl 0xc(%rsp), %edi
leaq 0x78(%rsp), %rsi
callq 0x2100
movq %rax, %rbx
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
subq %rsi, %rdx
movl 0xc(%rsp), %edi
callq 0x2100
movq 0xf0(%rsp), %rcx
addl %ebx, %ecx
movl %eax, %ebx
addl %ecx, %ebx
movl 0x74(%rsp), %ebp
testb $0x1, %bpl
je 0xd0ca
movq 0xb0(%rsp), %rax
movq 0x8(%rax), %rax
movq $-0x98, %rcx
addq %rcx, %rax
movq 0xa8(%rsp), %r13
cmpq %rax, %r13
je 0xd0d2
movq %rbx, %r14
movl %ebx, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl $0x200, %edx            # imm = 0x200
subl %eax, %edx
movl 0xc(%rsp), %edi
leaq 0x8744(%rip), %rsi      # 0x15800
callq 0x2100
movq %r14, %rbx
addl %eax, %ebx
movl 0x74(%rsp), %ebp
movq 0xa8(%rsp), %r13
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
leaq 0x50(%rsp), %r14
je 0xd0ee
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
addq $0x98, %r13
cmpq 0xe0(%rsp), %r13
jne 0xcbdb
testb $0x9, %bpl
jne 0xd3d1
xorl %eax, %eax
movq %rax, 0x7e(%rsp)
movq %rax, 0x78(%rsp)
movw $0x204, 0x86(%rsp)      # imm = 0x204
xorps %xmm0, %xmm0
movups %xmm0, 0x8e(%rsp)
movw $0x0, 0x9e(%rsp)
movw $0x1, 0x9a(%rsp)
movl $0x10000, 0x88(%rsp) # imm = 0x10000
movw $0x8001, 0x8c(%rsp)     # imm = 0x8001
movl $0x43002c, 0xa0(%rsp) # imm = 0x43002C
movq 0xb0(%rsp), %rdx
movq 0x8(%rdx), %rcx
subq (%rdx), %rcx
sarq $0x3, %rcx
movabsq $-0x79435e50d79435e5, %r14 # imm = 0x86BCA1AF286BCA1B
imulq %rcx, %r14
leal (%r14,%r14), %ecx
movl 0x38(%rsp), %edx
subl 0x30(%rsp), %edx
leal (%rcx,%rcx,4), %r15d
leal (%rdx,%r15), %ebx
addl $0x6, %ebx
movl %ebx, 0x80(%rsp)
leaq 0x10(%rsp), %rdi
movq %rax, 0x10(%rdi)
movaps %xmm0, (%rdi)
leaq 0x50(%rsp), %rcx
movb $0x20, (%rcx)
movl $0xa, %edx
xorl %esi, %esi
callq 0x9122
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2847(%rip), %rsi      # 0xfa19
leaq 0x284c(%rip), %rdx      # 0xfa25
leaq 0x50(%rsp), %rdi
callq 0x7dd6
leaq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xc08b
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0xd209
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2260
leaq 0x10(%rsp), %rdi
movl $0xf2, %esi
callq 0xbfe4
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0xc037
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0xc037
movq 0xb0(%rsp), %rcx
movl 0x8(%rcx), %eax
subl (%rcx), %eax
shrl $0x3, %eax
imull $0xffffca1b, %eax, %ebx # imm = 0xFFFFCA1B
decl %ebx
leaq 0x50(%rsp), %rsi
movb %bl, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0xd724
movb %bh, 0x50(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xd724
movq 0xc0(%rsp), %r12
movq 0xc8(%rsp), %rax
movq %rax, 0xa8(%rsp)
cmpq %rax, %r12
je 0xd304
addl %r14d, %r14d
leal (%r14,%r14,4), %eax
movzbl %al, %ebp
leaq 0x10(%rsp), %r13
leaq 0x50(%rsp), %r14
movl (%r12), %ebx
leal (%rbx,%rbp), %eax
movb %al, 0x50(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xd724
addl %r15d, %ebx
movb %bh, 0x50(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xd724
movb $0x0, 0x50(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xd724
movb $0x0, 0x50(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xd724
movq %r13, %rdi
xorl %esi, %esi
callq 0xc037
addl $-0x8, %r15d
addq $0x4, %r12
addl $-0x8, %ebp
cmpq 0xa8(%rsp), %r12
jne 0xd29d
movq 0xb0(%rsp), %rax
movq (%rax), %r15
movq 0x8(%rax), %r12
cmpq %r12, %r15
je 0xd350
leaq 0x10(%rsp), %r13
leaq 0x50(%rsp), %r14
movzwl (%r15), %ebx
movb %bl, 0x50(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xd724
movb %bh, 0x50(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0xd724
addq $0x98, %r15
cmpq %r12, %r15
jne 0xd322
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
callq 0xdcf6
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0xbfe4
movl 0x18(%rsp), %eax
subl 0x10(%rsp), %eax
addl $0x2c, %eax
leaq 0x78(%rsp), %rbx
movl %eax, (%rbx)
movl 0xc(%rsp), %ebp
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2420
movl $0x2c, %edx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x2100
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
movl 0xc(%rsp), %edi
callq 0x2100
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xd3d1
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movl 0xc(%rsp), %edi
callq 0x2460
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0xd3f7
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xd40e
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdx
leaq 0x209b(%rip), %rsi      # 0xf4c5
movl $0x49, %edi
xorl %eax, %eax
callq 0x2240
jmp 0xd46b
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0xd46e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2260
jmp 0xd46e
jmp 0xd46b
jmp 0xd46b
jmp 0xd45a
movq %rax, %rbx
jmp 0xd49d
jmp 0xd483
jmp 0xd46b
jmp 0xd483
jmp 0xd483
jmp 0xd46b
jmp 0xd483
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xd49d
movq 0x20(%rsp), %rsi
jmp 0xd495
jmp 0xd483
jmp 0xd483
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xd49d
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0xd4ba
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xd4d1
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x23c0
nop