// File: 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
subq $0x3e0, %rsp            # imm = 0x3E0
movl $0x0, -0x4(%rbp)
callq 0x24a0
leaq -0x28(%rbp), %rdi
movl $0x200, %edx            # imm = 0x200
movq %rdx, %rsi
callq 0x3100
movq 0x6731(%rip), %rdi      # 0x8fd0
leaq 0x3823(%rip), %rsi      # 0x60c9
callq 0x21b0
jmp 0x28ad
movq 0x671c(%rip), %rdi      # 0x8fd0
leaq 0x3831(%rip), %rsi      # 0x60ec
callq 0x21b0
jmp 0x28c2
movq 0x6707(%rip), %rdi      # 0x8fd0
leaq 0x383f(%rip), %rsi      # 0x610f
callq 0x21b0
jmp 0x28d7
movq 0x66f2(%rip), %rdi      # 0x8fd0
leaq 0x384d(%rip), %rsi      # 0x6132
callq 0x21b0
jmp 0x28ec
movq 0x66dd(%rip), %rdi      # 0x8fd0
leaq 0x37cf(%rip), %rsi      # 0x60c9
callq 0x21b0
jmp 0x2901
jmp 0x2903
movq 0x66c6(%rip), %rdi      # 0x8fd0
leaq 0x3844(%rip), %rsi      # 0x6155
callq 0x21b0
jmp 0x2918
movq 0x66c1(%rip), %rdi      # 0x8fe0
leaq -0x40(%rbp), %rsi
callq 0x2140
jmp 0x292a
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, -0x48(%rbp)
movabsq $0x4050000000000000, %rax # imm = 0x4050000000000000
movq %rax, -0x50(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x3190
movq %rax, -0x368(%rbp)
jmp 0x2960
movq -0x368(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x6659(%rip), %rdi      # 0x8fd0
leaq 0x37eb(%rip), %rsi      # 0x6169
callq 0x21b0
jmp 0x2985
movq 0x6654(%rip), %rdi      # 0x8fe0
leaq -0x54(%rbp), %rsi
callq 0x20b0
jmp 0x2997
movl $0x1, -0x58(%rbp)
movl $0x10, -0x5c(%rbp)
leaq -0x54(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq 0x3200
movq %rax, -0x370(%rbp)
jmp 0x29bf
movq -0x370(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq 0x65fe(%rip), %rdi      # 0x8fd0
leaq 0x37a4(%rip), %rsi      # 0x617d
callq 0x21b0
jmp 0x29e0
movq 0x65f9(%rip), %rdi      # 0x8fe0
leaq -0x60(%rbp), %rsi
callq 0x2030
jmp 0x29f2
movl -0x60(%rbp), %eax
movl %eax, %esi
leaq -0x160(%rbp), %rdi
callq 0x3260
jmp 0x2a05
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x380(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3290
movsd -0x380(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x168(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x378(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x32b0
movsd -0x378(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x170(%rbp)
movl $0x0, -0x174(%rbp)
movl -0x174(%rbp), %eax
movl %eax, -0x384(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x32b0
movl %eax, %ecx
movl -0x384(%rbp), %eax
cmpl %ecx, %eax
jge 0x2b6c
movl $0x0, -0x178(%rbp)
movl -0x178(%rbp), %eax
movl %eax, -0x388(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3290
movl %eax, %ecx
movl -0x388(%rbp), %eax
cmpl %ecx, %eax
jge 0x2b56
cvtsi2sdl -0x178(%rbp), %xmm0
movsd -0x168(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x174(%rbp), %xmm1
movsd -0x170(%rbp), %xmm2
mulsd %xmm2, %xmm1
movl -0x54(%rbp), %esi
leaq -0x160(%rbp), %rdi
movsd 0x3527(%rip), %xmm2     # 0x6020
callq 0x30b0
leaq -0x190(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x32d0
movq -0x390(%rbp), %rcx
movl -0x178(%rbp), %esi
movl -0x174(%rbp), %edx
leaq -0x28(%rbp), %rdi
callq 0x3300
jmp 0x2b2f
jmp 0x2b31
movl -0x178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x178(%rbp)
jmp 0x2a9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2de2
jmp 0x2b58
movl -0x174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x174(%rbp)
jmp 0x2a6b
leaq -0x318(%rbp), %rdi
callq 0x20f0
jmp 0x2b7a
leaq -0x308(%rbp), %rdi
movl $0x66, %esi
callq 0x2220
movq %rax, -0x398(%rbp)
jmp 0x2b94
movq -0x398(%rbp), %rdi
movsd -0x40(%rbp), %xmm0
callq 0x2330
movq %rax, -0x3a0(%rbp)
jmp 0x2bae
movq -0x3a0(%rbp), %rdi
movl $0x6f, %esi
callq 0x2220
movq %rax, -0x3a8(%rbp)
jmp 0x2bc8
movq -0x3a8(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x22f0
movq %rax, -0x3b0(%rbp)
jmp 0x2be0
movq -0x3b0(%rbp), %rdi
movl $0x5f, %esi
callq 0x2220
movq %rax, -0x3b8(%rbp)
jmp 0x2bfa
movq -0x3b8(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x2270
movq %rax, -0x3c0(%rbp)
jmp 0x2c12
movq -0x3c0(%rbp), %rdi
leaq 0x3571(%rip), %rsi      # 0x6191
callq 0x21b0
jmp 0x2c27
leaq -0x338(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x21a0
jmp 0x2c3c
leaq -0x28(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x3380
movb %al, -0x3c1(%rbp)
jmp 0x2c54
leaq -0x338(%rbp), %rdi
callq 0x20c0
movb -0x3c1(%rbp), %al
testb $0x1, %al
jne 0x2c6f
jmp 0x2d2a
movq 0x635a(%rip), %rdi      # 0x8fd0
leaq 0x3519(%rip), %rsi      # 0x6196
callq 0x21b0
movq %rax, -0x3d0(%rbp)
jmp 0x2c8b
leaq -0x358(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x21a0
jmp 0x2ca0
movq -0x3d0(%rbp), %rdi
leaq -0x358(%rbp), %rsi
callq 0x2180
movq %rax, -0x3d8(%rbp)
jmp 0x2cbc
movq -0x3d8(%rbp), %rdi
leaq 0x34d7(%rip), %rsi      # 0x61a1
callq 0x21b0
jmp 0x2cd1
leaq -0x358(%rbp), %rdi
callq 0x20c0
jmp 0x2d41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2dbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x20c0
jmp 0x2dbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x20c0
jmp 0x2dbf
movq 0x629f(%rip), %rdi      # 0x8fd0
leaq 0x346c(%rip), %rsi      # 0x61a4
callq 0x21b0
jmp 0x2d3f
jmp 0x2d41
movq 0x6288(%rip), %rdi      # 0x8fd0
leaq 0x3460(%rip), %rsi      # 0x61af
callq 0x21b0
jmp 0x2d56
movq 0x6283(%rip), %rdi      # 0x8fe0
leaq -0x359(%rbp), %rsi
callq 0x2260
jmp 0x2d6b
movsbl -0x359(%rbp), %eax
cmpl $0x79, %eax
je 0x2d83
movl $0x2, -0x360(%rbp)
jmp 0x2da0
movq 0x6246(%rip), %rdi      # 0x8fd0
movl $0xa, %esi
callq 0x2220
jmp 0x2d96
movl $0x0, -0x360(%rbp)
leaq -0x318(%rbp), %rdi
callq 0x2110
movl -0x360(%rbp), %eax
testl %eax, %eax
je 0x2dba
jmp 0x2db8
jmp 0x2dcd
jmp 0x2903
leaq -0x318(%rbp), %rdi
callq 0x2110
jmp 0x2de2
leaq -0x28(%rbp), %rdi
callq 0x3730
movl -0x4(%rbp), %eax
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x3730
movq -0x30(%rbp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)
nop