// File: /workspace/github_cpp_makefile_star2_O2/Reputeless[P]PerlinNoise/example.cpp
// Function: main
int main()
{
	Test();

	Image image{ 512, 512 };

	std::cout << "---------------------------------\n";
	std::cout << "* frequency [0.1 .. 8.0 .. 64.0] \n";
	std::cout << "* octaves   [1 .. 8 .. 16]       \n";
	std::cout << "* seed      [0 .. 2^32-1]        \n";
	std::cout << "---------------------------------\n";

	for (;;)
	{
		double frequency;
		std::cout << "double frequency = ";
		std::cin >> frequency;
		frequency = std::clamp(frequency, 0.1, 64.0);

		std::int32_t octaves;
		std::cout << "int32 octaves    = ";
		std::cin >> octaves;
		octaves = std::clamp(octaves, 1, 16);

		std::uint32_t seed;
		std::cout << "uint32 seed      = ";
		std::cin >> seed;

		const siv::PerlinNoise perlin{ seed };
		const double fx = (frequency / image.width());
		const double fy = (frequency / image.height());

		for (std::int32_t y = 0; y < image.height(); ++y)
		{
			for (std::int32_t x = 0; x < image.width(); ++x)
			{
				const RGB color(perlin.octave2D_01((x * fx), (y * fy), octaves));
				image.set(x, y, color);
			}
		}

		std::stringstream ss;
		ss << 'f' << frequency << 'o' << octaves << '_' << seed << ".bmp";

		if (image.saveBMP(ss.str()))
		{
			std::cout << "...saved \"" << ss.str() << "\"\n";
		}
		else
		{
			std::cout << "...failed\n";
		}

		char c;
		std::cout << "continue? [y/n] >";
		std::cin >> c;
		if (c != 'y') break;
		std::cout << '\n';
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
callq 0x23bc
leaq -0x70(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
movl $0x200, %edx            # imm = 0x200
callq 0x2bd0
movq 0x3880(%rip), %rdi      # 0x5fd0
leaq 0x198a(%rip), %rsi      # 0x40e1
callq 0x2160
movq 0x386d(%rip), %rdi      # 0x5fd0
leaq 0x199a(%rip), %rsi      # 0x4104
callq 0x2160
movq 0x385a(%rip), %rdi      # 0x5fd0
leaq 0x19aa(%rip), %rsi      # 0x4127
callq 0x2160
movq 0x3847(%rip), %rdi      # 0x5fd0
leaq 0x19ba(%rip), %rsi      # 0x414a
callq 0x2160
movq 0x3834(%rip), %rdi      # 0x5fd0
leaq 0x193e(%rip), %rsi      # 0x40e1
callq 0x2160
movq 0x3821(%rip), %r15      # 0x5fd0
leaq -0x318(%rbp), %r12
leaq -0x70(%rbp), %rbx
leaq -0x218(%rbp), %r14
movq %r15, %rdi
leaq 0x19a2(%rip), %rsi      # 0x416d
callq 0x2160
movq 0x3809(%rip), %rdi      # 0x5fe0
leaq -0x38(%rbp), %rsi
callq 0x20c0
movsd -0x38(%rbp), %xmm0
movsd 0x185b(%rip), %xmm1     # 0x4048
minsd %xmm0, %xmm1
movsd 0x180f(%rip), %xmm3     # 0x4008
cmpltsd %xmm3, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movlpd %xmm0, -0x38(%rbp)
movq %r15, %rdi
leaq 0x1964(%rip), %rsi      # 0x4181
callq 0x2160
movq 0x37b7(%rip), %rdi      # 0x5fe0
leaq -0x2c(%rbp), %rsi
callq 0x20a0
movl -0x2c(%rbp), %eax
cmpl $0x10, %eax
pushq $0x10
popq %rcx
cmovgel %ecx, %eax
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovll %ecx, %eax
movl %eax, -0x2c(%rbp)
movq %r15, %rdi
leaq 0x1941(%rip), %rsi      # 0x4195
callq 0x2160
movq 0x3780(%rip), %rdi      # 0x5fe0
leaq -0x30(%rbp), %rsi
callq 0x2240
movl -0x30(%rbp), %esi
movq %r12, %rdi
callq 0x2b30
movsd -0x38(%rbp), %xmm1
movl -0x58(%rbp), %eax
movl -0x54(%rbp), %ecx
cvtsi2sd %eax, %xmm0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, -0x48(%rbp)
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
xorl %r13d, %r13d
cmpl %ecx, %r13d
jge 0x2917
cvtsi2sd %r13d, %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
xorl %r15d, %r15d
cmpl %eax, %r15d
jge 0x290f
cvtsi2sd %r15d, %xmm0
mulsd -0x48(%rbp), %xmm0
movl -0x2c(%rbp), %esi
movq %r12, %rdi
movsd -0x50(%rbp), %xmm1
movsd 0x1747(%rip), %xmm2     # 0x4020
callq 0x2b8e
movsd %xmm0, -0x218(%rbp)
movsd %xmm0, -0x210(%rbp)
movsd %xmm0, -0x208(%rbp)
movq %rbx, %rdi
movl %r15d, %esi
movl %r13d, %edx
movq %r14, %rcx
callq 0x2c06
incl %r15d
movl -0x58(%rbp), %eax
jmp 0x28b7
incl %r13d
movl -0x54(%rbp), %ecx
jmp 0x28a0
movq %r14, %rdi
callq 0x20e0
leaq -0x208(%rbp), %rdi
pushq $0x66
popq %rsi
callq 0x2190
movsd -0x38(%rbp), %xmm0
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
pushq $0x6f
popq %rsi
callq 0x2190
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
pushq $0x5f
popq %rsi
callq 0x2190
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
leaq 0x1838(%rip), %rsi      # 0x41a9
callq 0x2160
leaq -0x90(%rbp), %r15
movq %r15, %rdi
leaq -0x200(%rbp), %rsi
callq 0x21f0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2c58
movq %r15, %rdi
movl %eax, %r15d
callq 0x2070
testb %r15b, %r15b
je 0x29f7
movq 0x3622(%rip), %rdi      # 0x5fd0
leaq 0x17f9(%rip), %rsi      # 0x41ae
callq 0x2160
movq %rax, %r15
leaq -0x90(%rbp), %r13
movq %r13, %rdi
leaq -0x200(%rbp), %rsi
callq 0x21f0
movq %r15, %rdi
movq %r13, %rsi
callq 0x2140
movq %rax, %rdi
leaq 0x17d1(%rip), %rsi      # 0x41b9
callq 0x2160
movq %r13, %rdi
callq 0x2070
jmp 0x2a0a
movq 0x35d2(%rip), %rdi      # 0x5fd0
leaq 0x17b7(%rip), %rsi      # 0x41bc
callq 0x2160
movq 0x35bf(%rip), %r15      # 0x5fd0
movq %r15, %rdi
leaq 0x17ac(%rip), %rsi      # 0x41c7
callq 0x2160
leaq -0x90(%rbp), %rsi
movq 0x35b2(%rip), %rdi      # 0x5fe0
callq 0x21b0
cmpb $0x79, -0x90(%rbp)
jne 0x2a54
movq %r15, %rdi
pushq $0xa
popq %rsi
callq 0x2190
movq %r14, %rdi
callq 0x2100
jmp 0x27c1
leaq -0x218(%rbp), %rdi
callq 0x2100
leaq -0x70(%rbp), %rdi
callq 0x3010
xorl %eax, %eax
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a9e
jmp 0x2aa5
jmp 0x2a85
jmp 0x2a9e
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x2070
jmp 0x2aa8
jmp 0x2aa5
jmp 0x2a9e
jmp 0x2a9e
jmp 0x2a9e
movq %rax, %rbx
jmp 0x2ab4
jmp 0x2aa5
movq %rax, %rbx
leaq -0x218(%rbp), %rdi
callq 0x2100
leaq -0x70(%rbp), %rdi
callq 0x3010
movq %rbx, %rdi
callq 0x2250
nop