// File: /workspace/github_cpp_makefile_star2_O1/nyorain[P]bintoheader/bintoheader.cpp
// Function: outputData(std::vector<unsigned char, std::allocator<unsigned char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int)
void outputData(const std::vector<std::uint8_t>& data, const std::string& file,
	const std::string& name, int size)
{
	auto fname = file;
	std::ofstream ofs(fname);
	if(!ofs.is_open()) {
		std::cerr << "outputData: couldnt open output file " << file << "\n";
		std::cerr << "error: " << std::strerror(errno) << "\n";
		exit(EXIT_FAILURE);
	}

	auto byteSize = size / 8;
	if(data.size() % byteSize) {
		std::cerr << "outputData: file size is not a multiple of specified integer size\n";
		std::cerr << "\tfile size: " << data.size() << " bytes\n";
		std::cerr << "\tspecified size: " << size / 8 << " bytes\n";
		exit(EXIT_FAILURE);
	}

	std::string dataString;
	dataString.reserve(data.size() * 5); //approx.

	auto currColSize = 4u;
	for(auto i = 0u; i < data.size() / byteSize; ++i) {
		std::uint64_t value = 0;
		auto ptr = &data[i * byteSize];

		if(size == 8) value = *reinterpret_cast<const std::uint8_t*>(ptr);
		else if(size == 16) value = *reinterpret_cast<const std::uint16_t*>(ptr);
		else if(size == 32) value = *reinterpret_cast<const std::uint32_t*>(ptr);
		else if(size == 64) value = *reinterpret_cast<const std::uint64_t*>(ptr);

		auto str = std::to_string(value);
		if(currColSize + str.size() + 2 >= lineLength)
		{
			dataString.append(",\n    ");
			currColSize = 4u;
		}
		else if(i != 0)
		{
			dataString.append(", ");
			currColSize += 2;
		}

		currColSize += str.size();
		dataString.append(str);
	}

	std::string outputTypeName = "uint" + std::to_string(size) + "_t";
	std::string includeGuard = name;
	for(auto& ch : includeGuard) ch = std::toupper(ch);

	std::string txt = fileTemplate;
	replace(txt, "%t", outputTypeName);
	replace(txt, "%d", dataString);
	replace(txt, "%n", name);
	replace(txt, "%i", includeGuard);

	ofs << txt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movl %ecx, %r15d
movq %rdx, -0xc8(%rbp)
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x108(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%rsi), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x118(%rbp), %r14
movq %r14, %rdi
callq 0x44bc
leaq -0x318(%rbp), %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2360
leaq -0x2a8(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x2f8b
leal 0x7(%r15), %eax
testl %r15d, %r15d
cmovnsl %r15d, %eax
sarl $0x3, %eax
movq 0x8(%r12), %rcx
subq (%r12), %rcx
movl %eax, -0x6c(%rbp)
movslq %eax, %rsi
movq %rcx, %rax
xorl %edx, %edx
movq %rsi, -0xd0(%rbp)
divq %rsi
testq %rdx, %rdx
jne 0x3011
movq %r15, -0xc0(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq (%rcx,%rcx,4), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x22a0
movq (%r12), %rcx
movq 0x8(%r12), %rax
subq %rcx, %rax
cmpq -0xd0(%rbp), %rax
jb 0x2b8c
movq -0xc0(%rbp), %rax
addl $-0x8, %eax
roll $0x1d, %eax
xorl %r15d, %r15d
movl $0x4, %r13d
movl %eax, -0xb4(%rbp)
movl %eax, %eax
movq %rax, -0xf8(%rbp)
movabsq $0x346dc5d63886594b, %rbx # imm = 0x346DC5D63886594B
xorl %r14d, %r14d
cmpl $0x7, -0xb4(%rbp)
ja 0x2a79
movl %r15d, %eax
imull -0x6c(%rbp), %eax
movq -0xf8(%rbp), %rdx
leaq 0x25ac(%rip), %rsi      # 0x5004
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movzbl (%rcx,%rax), %r14d
jmp 0x2a79
movl (%rcx,%rax), %r14d
jmp 0x2a79
movzwl (%rcx,%rax), %r14d
jmp 0x2a79
movq (%rcx,%rax), %r14
movl $0x1, %esi
cmpq $0xa, %r14
jb 0x2ac9
movl $0x4, %esi
movq %r14, %rcx
cmpq $0x63, %rcx
jbe 0x2ac2
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x2ac7
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x2ac9
movq %rcx, %rax
mulq %rbx
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x2a8c
addl $-0x3, %esi
jmp 0x2ac9
addl $-0x2, %esi
jmp 0x2ac9
decl %esi
movl %esi, %esi
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rdi
xorl %edx, %edx
callq 0x21e0
movq -0x68(%rbp), %rdi
movl -0x60(%rbp), %esi
movq %r14, %rdx
callq 0x3caf
movl %r13d, %eax
movq -0x60(%rbp), %rcx
addq %rcx, %rax
addq $-0x4e, %rax
cmpq $-0x51, %rax
ja 0x2b1c
movl $0x4, %r13d
leaq -0xf0(%rbp), %rdi
leaq 0x25f1(%rip), %rsi      # 0x5106
callq 0x2350
jmp 0x2b38
testl %r15d, %r15d
je 0x2b38
leaq -0xf0(%rbp), %rdi
leaq 0x25de(%rip), %rsi      # 0x510d
callq 0x2350
addl $0x2, %r13d
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %r14
leaq -0xf0(%rbp), %rdi
movq %r14, %rdx
callq 0x2090
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2b68
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
addl %r14d, %r13d
incl %r15d
movq (%r12), %rcx
movq 0x8(%r12), %rax
subq %rcx, %rax
xorl %edx, %edx
divq -0xd0(%rbp)
cmpq %r15, %rax
ja 0x2a37
movq -0xc0(%rbp), %r15
movl %r15d, %ebx
negl %ebx
cmovsl %r15d, %ebx
movl $0x1, %r14d
cmpl $0xa, %ebx
jb 0x2bf0
movl $0x4, %r14d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x2be7
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x2bed
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x2bf0
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r14d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x2bb4
addl $-0x3, %r14d
jmp 0x2bf0
addl $-0x2, %r14d
jmp 0x2bf0
decl %r14d
shrl $0x1f, %r15d
leal (%r14,%r15), %esi
leaq -0x80(%rbp), %r12
movq %r12, -0x10(%r12)
leaq -0x90(%rbp), %rdi
movl $0x2d, %edx
callq 0x21e0
movl %r15d, %edi
leaq -0x90(%rbp), %r15
addq (%r15), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x3d2f
leaq 0x24e0(%rip), %rcx      # 0x5110
movl $0x4, %r8d
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21c0
leaq -0xa0(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2c6f
movq %rdx, -0xb0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xa0(%rbp)
jmp 0x2c76
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0xb0(%rbp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x247a(%rip), %rsi      # 0x5115
callq 0x2350
leaq -0x58(%rbp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2cc4
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x2cca
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0xb0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2cfc
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x2d14
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0xb0(%rbp), %rdi
movq %r14, (%rdi)
movq -0xc8(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
callq 0x44bc
movq -0xa8(%rbp), %rbx
testq %rbx, %rbx
je 0x2d62
movq -0xb0(%rbp), %r13
xorl %r15d, %r15d
movsbl (%r13,%r15), %edi
callq 0x2340
movb %al, (%r13,%r15)
incq %r15
cmpq %r15, %rbx
jne 0x2d4a
leaq -0x90(%rbp), %rdi
movq %r12, (%rdi)
leaq 0x23a6(%rip), %rsi      # 0x5119
leaq 0x2462(%rip), %rdx      # 0x51dc
callq 0x4556
leaq -0x38(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x244f(%rip), %rsi      # 0x51dd
leaq 0x244a(%rip), %rdx      # 0x51df
leaq -0x48(%rbp), %rdi
callq 0x4556
leaq -0x90(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x267e
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x2dc7
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x240b(%rip), %rsi      # 0x51e0
leaq 0x2406(%rip), %rdx      # 0x51e2
callq 0x4556
leaq -0x90(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x267e
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x2e0d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x23c8(%rip), %rsi      # 0x51e3
leaq 0x23c3(%rip), %rdx      # 0x51e5
callq 0x4556
leaq -0x90(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x267e
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x2e53
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x2385(%rip), %rsi      # 0x51e6
leaq 0x2380(%rip), %rdx      # 0x51e8
callq 0x4556
leaq -0x90(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x267e
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x2e99
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
leaq -0x318(%rbp), %rdi
callq 0x21d0
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x2ecb
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0xb0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ee6
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2eff
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x2f21
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2190
movq 0x5098(%rip), %rax      # 0x7fc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x310(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x318(%rbp,%rcx)
callq 0x2150
leaq -0x220(%rbp), %rdi
callq 0x20a0
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x2f79
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2190
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x505e(%rip), %rdi      # 0x7ff0
leaq 0x20dd(%rip), %rsi      # 0x5076
movl $0x25, %edx
callq 0x21d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x503f(%rip), %rdi      # 0x7ff0
callq 0x21d0
leaq 0x22f2(%rip), %rsi      # 0x52af
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movq 0x501f(%rip), %rdi      # 0x7ff0
leaq 0x2071(%rip), %rsi      # 0x5049
movl $0x7, %edx
callq 0x21d0
callq 0x2030
movl (%rax), %edi
callq 0x20b0
movq 0x4ffb(%rip), %rdi      # 0x7ff0
movq %rax, %rsi
callq 0x2170
leaq 0x22ab(%rip), %rsi      # 0x52af
movq %rax, %rdi
callq 0x2170
jmp 0x30a0
movq 0x4fd8(%rip), %rdi      # 0x7ff0
leaq 0x207d(%rip), %rsi      # 0x509c
movl $0x42, %edx
callq 0x21d0
movq 0x4fc0(%rip), %rdi      # 0x7ff0
leaq 0x20a8(%rip), %rsi      # 0x50df
movl $0xc, %edx
callq 0x21d0
movq 0x8(%r12), %rsi
subq (%r12), %rsi
movq 0x4f9f(%rip), %rdi      # 0x7ff0
callq 0x2110
leaq 0x208f(%rip), %rsi      # 0x50ec
movl $0x7, %edx
movq %rax, %rdi
callq 0x21d0
movq 0x4f7f(%rip), %rdi      # 0x7ff0
leaq 0x207c(%rip), %rsi      # 0x50f4
movl $0x11, %edx
callq 0x21d0
movq 0x4f67(%rip), %rdi      # 0x7ff0
movl -0x6c(%rbp), %esi
callq 0x22e0
leaq 0x2054(%rip), %rsi      # 0x50ec
movq %rax, %rdi
callq 0x2170
movl $0x1, %edi
callq 0x21f0
jmp 0x30ac
movq %rax, %rbx
jmp 0x319c
jmp 0x30dc
jmp 0x30c2
jmp 0x30dc
jmp 0x30c2
jmp 0x30dc
jmp 0x30c2
jmp 0x30dc
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x30df
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x30df
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x30f7
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0xb0(%rbp), %rdi
cmpq %r14, %rdi
je 0x3161
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x3161
movq %rax, %rbx
jmp 0x30f7
jmp 0x315e
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r14, %rdi
je 0x313e
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x313e
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x317a
movq -0x80(%rbp), %rsi
jmp 0x3172
jmp 0x3159
jmp 0x3159
movq %rax, %rbx
jmp 0x31a8
movq %rax, %rbx
jmp 0x317a
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x317a
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x319c
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x318(%rbp), %rdi
callq 0x2260
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x31ca
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x2320