// File: Reputeless[P]PerlinNoise/example.cpp
// Function: Image::saveBMP(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool saveBMP(const std::string& path)
	{
		const std::int32_t  rowSize = m_width * 3 + m_width % 4;
		const std::uint32_t bmpsize = rowSize * m_height;
		const BMPHeader header =
		{
			0x4d42,
			static_cast<std::uint32_t>(bmpsize + sizeof(BMPHeader)),
			0, 0, sizeof(BMPHeader), 40,
			m_width, m_height, 1, 24,
			0, bmpsize, 0, 0, 0, 0
		};

		if (std::ofstream ofs{ path, std::ios_base::binary })
		{
			ofs.write(reinterpret_cast<const char*>(&header), sizeof(header));

			std::vector<std::uint8_t> line(rowSize);

			for (std::int32_t y = m_height - 1; -1 < y; --y)
			{
				size_t pos = 0;

				for (std::int32_t x = 0; x < m_width; ++x)
				{
					const RGB& col = m_data[static_cast<std::size_t>(y) * m_width + x];
					line[pos++] = ToUint8(col.b);
					line[pos++] = ToUint8(col.g);
					line[pos++] = ToUint8(col.r);
				}

				ofs.write(reinterpret_cast<const char*>(line.data()), line.size());
			}

			return true;
		}
		else
		{
			return false;
		}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movl 0x18(%rax), %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
movl %edx, %edi
addl $0x3, %edi
testl %edx, %edx
movl %edx, %esi
cmovsl %edi, %esi
andl $-0x4, %esi
subl %esi, %edx
addl %edx, %ecx
movl %ecx, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
movl 0x1c(%rax), %edx
imull %edx, %ecx
movl %ecx, -0x20(%rbp)
movw $0x4d42, -0x56(%rbp)    # imm = 0x4D42
movl -0x20(%rbp), %ecx
addl $0x36, %ecx
movl %ecx, -0x54(%rbp)
movw $0x0, -0x50(%rbp)
movw $0x0, -0x4e(%rbp)
movl $0x36, -0x4c(%rbp)
movl $0x28, -0x48(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0x44(%rbp)
movl 0x1c(%rax), %eax
movl %eax, -0x40(%rbp)
movw $0x1, -0x3c(%rbp)
movw $0x18, -0x3a(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x258(%rbp), %rdi
movl $0x4, %edx
callq 0x2340
movq -0x258(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x258(%rbp,%rax), %rdi
callq 0x2240
movb %al, -0x2a5(%rbp)
jmp 0x3467
movb -0x2a5(%rbp), %al
testb $0x1, %al
jne 0x3476
jmp 0x36eb
leaq -0x258(%rbp), %rdi
leaq -0x56(%rbp), %rsi
movl $0x36, %edx
callq 0x2250
jmp 0x348d
movslq -0x1c(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x281(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x4290
movq -0x2c0(%rbp), %rsi
movq -0x2b8(%rbp), %rdx
leaq -0x280(%rbp), %rdi
callq 0x42b0
jmp 0x34c7
leaq -0x281(%rbp), %rdi
callq 0x4320
movq -0x2b0(%rbp), %rax
movl 0x1c(%rax), %eax
subl $0x1, %eax
movl %eax, -0x288(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x288(%rbp), %eax
jge 0x36cf
movq $0x0, -0x290(%rbp)
movl $0x0, -0x294(%rbp)
movq -0x2b0(%rbp), %rcx
movl -0x294(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x365b
movq -0x2b0(%rbp), %rdi
movslq -0x288(%rbp), %rsi
movslq 0x18(%rdi), %rax
imulq %rax, %rsi
movslq -0x294(%rbp), %rax
addq %rax, %rsi
callq 0x4270
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
movsd 0x10(%rax), %xmm0
callq 0x4340
movb %al, -0x2c3(%rbp)
movq -0x290(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x290(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x43b0
movb -0x2c3(%rbp), %cl
movb %cl, (%rax)
movq -0x2a0(%rbp), %rax
movsd 0x8(%rax), %xmm0
callq 0x4340
movb %al, -0x2c2(%rbp)
movq -0x290(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x290(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x43b0
movb -0x2c2(%rbp), %cl
movb %cl, (%rax)
movq -0x2a0(%rbp), %rax
movsd (%rax), %xmm0
callq 0x4340
movb %al, -0x2c1(%rbp)
movq -0x290(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x290(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x43b0
movb -0x2c1(%rbp), %cl
movb %cl, (%rax)
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
jmp 0x350c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x3713
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x281(%rbp), %rdi
callq 0x4320
jmp 0x3713
leaq -0x280(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x43d0
movq -0x2d8(%rbp), %rdi
movq %rax, -0x2d0(%rbp)
callq 0x43f0
movq -0x2d0(%rbp), %rsi
movq %rax, %rdx
leaq -0x258(%rbp), %rdi
callq 0x2250
jmp 0x3699
jmp 0x369b
movl -0x288(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x288(%rbp)
jmp 0x34e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x4410
jmp 0x3713
movb $0x1, -0x1(%rbp)
movl $0x1, -0x2a4(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x4410
jmp 0x36f9
movb $0x0, -0x1(%rbp)
movl $0x1, -0x2a4(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x22a0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x258(%rbp), %rdi
callq 0x22a0
movq -0x260(%rbp), %rdi
callq 0x2300
nopl (%rax,%rax)