// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, %rbx
movl 0x18(%rdi), %eax
movl 0x1c(%rdi), %ecx
leal (%rax,%rax,2), %edx
leal 0x3(%rax), %edi
testl %eax, %eax
cmovnsl %eax, %edi
andl $-0x4, %edi
movl %eax, %r12d
subl %edi, %r12d
addl %edx, %r12d
movl %r12d, %edx
imull %ecx, %edx
movw $0x4d42, -0x7e(%rbp)    # imm = 0x4D42
leal 0x36(%rdx), %edi
movl %edi, -0x7c(%rbp)
movl $0x0, -0x78(%rbp)
movabsq $0x2800000036, %rdi     # imm = 0x2800000036
movq %rdi, -0x74(%rbp)
movl %eax, -0x6c(%rbp)
movl %ecx, -0x68(%rbp)
movq $0x180001, -0x64(%rbp)  # imm = 0x180001
movl %edx, -0x5c(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x58(%rbp)
leaq -0x280(%rbp), %r14
movq %r14, %rdi
movl $0x4, %edx
callq 0x2240
movq (%r14), %rax
movq -0x18(%rax), %rax
movl -0x260(%rbp,%rax), %r15d
testb $0x5, %r15b
jne 0x351a
leaq -0x280(%rbp), %rdi
leaq -0x7e(%rbp), %rsi
movl $0x36, %edx
callq 0x2170
movslq %r12d, %rsi
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x364a
movl 0x1c(%rbx), %r12d
leaq (%r12,%r12,2), %rax
leaq -0x18(,%rax,8), %r13
xorpd %xmm1, %xmm1
movsd 0xc25(%rip), %xmm2      # 0x4020
movsd 0xc55(%rip), %xmm3      # 0x4058
movsd 0xc1d(%rip), %xmm4      # 0x4028
testl %r12d, %r12d
jle 0x3505
movl 0x18(%rbx), %edx
testl %edx, %edx
jle 0x34ca
movl $0x1, %eax
xorl %ecx, %ecx
movslq %edx, %rdx
imulq %r13, %rdx
addq (%rbx), %rdx
movsd 0x8(%rdx,%rax,8), %xmm0
ucomisd %xmm0, %xmm1
jae 0x3453
movb $-0x1, %sil
ucomisd %xmm2, %xmm0
jae 0x3455
mulsd %xmm3, %xmm0
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %esi
jmp 0x3455
xorl %esi, %esi
movq -0x48(%rbp), %rdi
movb %sil, -0x1(%rdi,%rax)
movsd (%rdx,%rax,8), %xmm0
ucomisd %xmm0, %xmm1
jae 0x3480
movb $-0x1, %sil
ucomisd %xmm2, %xmm0
jae 0x3482
mulsd %xmm3, %xmm0
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %esi
jmp 0x3482
xorl %esi, %esi
movq -0x48(%rbp), %rdi
movb %sil, (%rdi,%rax)
movsd -0x8(%rdx,%rax,8), %xmm0
ucomisd %xmm0, %xmm1
jae 0x34ac
movb $-0x1, %dl
ucomisd %xmm2, %xmm0
jae 0x34ae
mulsd %xmm3, %xmm0
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %edx
jmp 0x34ae
xorl %edx, %edx
movq -0x48(%rbp), %rsi
movb %dl, 0x1(%rsi,%rax)
incq %rcx
movslq 0x18(%rbx), %rdx
addq $0x3, %rax
cmpq %rdx, %rcx
jl 0x3426
decq %r12
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
subq %rsi, %rdx
addq $-0x18, %r13
movq %r14, %rdi
callq 0x2170
movsd 0xb3c(%rip), %xmm4      # 0x4028
movsd 0xb64(%rip), %xmm3      # 0x4058
movsd 0xb24(%rip), %xmm2      # 0x4020
xorpd %xmm1, %xmm1
jmp 0x340b
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x351a
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
testb $0x5, %r15b
sete %bl
movq 0x2aa0(%rip), %rax      # 0x5fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x278(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x280(%rbp,%rcx)
callq 0x2110
leaq -0x188(%rbp), %rdi
callq 0x2040
movl %ebx, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x356d
movq %rax, %rbx
jmp 0x358a
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x358a
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
leaq -0x280(%rbp), %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x2220