// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1528, %rsp           # imm = 0x1528
callq 0x238c
xorpd %xmm0, %xmm0
movapd %xmm0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movl $0x600000, %edi         # imm = 0x600000
callq 0x2140
movq %rax, -0x80(%rbp)
movq %rax, -0x78(%rbp)
leaq 0x600000(%rax), %rbx
movq %rbx, -0x70(%rbp)
movl $0x600000, %edx         # imm = 0x600000
movq %rax, %rdi
xorl %esi, %esi
callq 0x2080
movq %rbx, -0x78(%rbp)
movabsq $0x20000000200, %rax    # imm = 0x20000000200
movq %rax, -0x68(%rbp)
movq 0x32ea(%rip), %rdi      # 0x5fd0
leaq 0x13f4(%rip), %rsi      # 0x40e1
movl $0x22, %edx
callq 0x2160
movq 0x32d2(%rip), %rdi      # 0x5fd0
leaq 0x13ff(%rip), %rsi      # 0x4104
movl $0x22, %edx
callq 0x2160
movq 0x32ba(%rip), %rdi      # 0x5fd0
leaq 0x140a(%rip), %rsi      # 0x4127
movl $0x22, %edx
callq 0x2160
movq 0x32a2(%rip), %rdi      # 0x5fd0
leaq 0x1415(%rip), %rsi      # 0x414a
movl $0x22, %edx
callq 0x2160
movq 0x328a(%rip), %rdi      # 0x5fd0
leaq 0x1394(%rip), %rsi      # 0x40e1
movl $0x22, %edx
callq 0x2160
movq 0x3272(%rip), %r12      # 0x5fd0
movq 0x327b(%rip), %r14      # 0x5fe0
leaq -0x1548(%rbp), %r13
leaq -0x1c0(%rbp), %rbx
movl $0x13, %edx
movq %r12, %rdi
leaq 0x13eb(%rip), %rsi      # 0x416d
callq 0x2160
movq %r14, %rdi
leaq -0x88(%rbp), %rsi
callq 0x20b0
movsd -0x88(%rbp), %xmm0
movsd 0x12aa(%rip), %xmm1     # 0x4050
minsd %xmm0, %xmm1
movsd 0x1266(%rip), %xmm3     # 0x4018
cmpltsd %xmm3, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movlpd %xmm0, -0x88(%rbp)
movl $0x13, %edx
movq %r12, %rdi
leaq 0x13a3(%rip), %rsi      # 0x4181
callq 0x2160
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2090
movl -0x30(%rbp), %eax
cmpl $0x10, %eax
movl $0x10, %ecx
cmovgel %ecx, %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovll %ecx, %eax
movl %eax, -0x30(%rbp)
movl $0x13, %edx
movq %r12, %rdi
leaq 0x137b(%rip), %rsi      # 0x4195
callq 0x2160
movq %r14, %rdi
leaq -0x34(%rbp), %rsi
callq 0x2210
movl -0x34(%rbp), %eax
movq %rax, -0x1548(%rbp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, -0x1548(%rbp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x2e3a
movq $0x270, -0x1c8(%rbp) # imm = 0x270
xorl %eax, %eax
movb %al, -0x1c0(%rbp,%rax)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x2e6c
movl $0x2, %r14d
movq %r13, %rdi
callq 0x3c82
xorl %edx, %edx
divq %r14
movb -0x1c1(%rbp,%r14), %al
movb -0x1c0(%rbp,%rdx), %cl
movb %cl, -0x1c1(%rbp,%r14)
movb %al, -0x1c0(%rbp,%rdx)
incq %r14
cmpq $0x101, %r14            # imm = 0x101
jne 0x2e84
movl -0x64(%rbp), %eax
testl %eax, %eax
jle 0x305b
movsd -0x88(%rbp), %xmm1
cvtsi2sdl -0x68(%rbp), %xmm0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, -0x98(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x90(%rbp)
xorl %r15d, %r15d
cmpl $0x0, -0x68(%rbp)
jle 0x304b
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd -0x90(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
xorl %r12d, %r12d
movl -0x30(%rbp), %r14d
xorpd %xmm1, %xmm1
testl %r14d, %r14d
jle 0x2fc7
xorps %xmm3, %xmm3
cvtsi2sd %r12d, %xmm3
mulsd -0x98(%rbp), %xmm3
movsd 0x10d9(%rip), %xmm4     # 0x4020
movsd -0xa0(%rbp), %xmm5
movsd %xmm5, -0xa8(%rbp)
movsd %xmm4, -0xb0(%rbp)
movsd %xmm3, -0xb8(%rbp)
movsd %xmm1, -0xc0(%rbp)
movq %rbx, %rdi
movapd %xmm3, %xmm0
movaps %xmm5, %xmm1
movsd 0x10af(%rip), %xmm2     # 0x4030
callq 0x371c
movsd -0xa8(%rbp), %xmm5
movsd -0xb0(%rbp), %xmm4
movsd -0xb8(%rbp), %xmm3
movsd 0x1082(%rip), %xmm2     # 0x4028
movsd -0xc0(%rbp), %xmm1
mulsd %xmm4, %xmm0
addsd %xmm0, %xmm1
addsd %xmm3, %xmm3
addsd %xmm5, %xmm5
mulsd %xmm2, %xmm4
decl %r14d
jne 0x2f4f
movsd 0x1069(%rip), %xmm0     # 0x4038
ucomisd %xmm1, %xmm0
xorpd %xmm0, %xmm0
jae 0x2ffb
movsd 0x103f(%rip), %xmm0     # 0x4020
ucomisd %xmm0, %xmm1
jae 0x2ffb
movsd 0x1039(%rip), %xmm0     # 0x4028
mulsd %xmm0, %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movslq -0x64(%rbp), %rax
cmpq %rax, %r15
setl %cl
movslq -0x68(%rbp), %rax
cmpq %rax, %r12
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x303b
imulq %r15, %rax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq -0x80(%rbp), %rax
leaq (%r12,%r12,2), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd %xmm0, 0x8(%rax,%rcx,8)
movsd %xmm0, 0x10(%rax,%rcx,8)
incq %r12
movslq -0x68(%rbp), %rax
cmpq %rax, %r12
jl 0x2f1e
incq %r15
movslq -0x64(%rbp), %rax
cmpq %rax, %r15
jl 0x2ef9
movq %r13, %rdi
callq 0x20d0
movb $0x66, -0x58(%rbp)
movl $0x1, %edx
leaq -0x1538(%rbp), %rdi
leaq -0x58(%rbp), %r14
movq %r14, %rsi
callq 0x2160
movq 0x2f4a(%rip), %r12      # 0x5fd0
movsd -0x88(%rbp), %xmm0
movq %rax, %rdi
callq 0x21d0
movb $0x6f, -0x58(%rbp)
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2160
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x2200
movb $0x5f, -0x58(%rbp)
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2160
movl -0x34(%rbp), %esi
movq %rax, %rdi
callq 0x20c0
movl $0x4, %edx
movq %rax, %rdi
leaq 0x10c6(%rip), %rsi      # 0x41a9
callq 0x2160
movq %r14, %rdi
leaq -0x1530(%rbp), %rsi
callq 0x21c0
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
callq 0x334c
movl %eax, %r15d
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x311f
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
testb %r15b, %r15b
je 0x318a
movl $0xa, %edx
movq %r12, %rdi
leaq 0x107b(%rip), %rsi      # 0x41ae
callq 0x2160
leaq -0x58(%rbp), %r15
movq %r15, %rdi
leaq -0x1530(%rbp), %rsi
callq 0x21c0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %r12, %rdi
callq 0x2160
movl $0x2, %edx
movq %rax, %rdi
leaq 0x104f(%rip), %rsi      # 0x41b9
callq 0x2160
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x31a2
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x31a2
movl $0xa, %edx
movq %r12, %rdi
leaq 0x1023(%rip), %rsi      # 0x41bc
callq 0x2160
leaq -0x58(%rbp), %r15
movl $0x11, %edx
movq %r12, %rdi
leaq 0x1016(%rip), %rsi      # 0x41c7
callq 0x2160
movq 0x2e23(%rip), %rdi      # 0x5fe0
leaq -0x29(%rbp), %rsi
callq 0x2180
movb -0x29(%rbp), %r14b
cmpb $0x79, %r14b
jne 0x3212
movb $0xa, -0x58(%rbp)
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2160
movq %r13, %rdi
movq 0x2dc2(%rip), %rsi      # 0x5fb0
callq 0x20f0
leaq -0x14c8(%rbp), %rdi
callq 0x2040
cmpb $0x79, %r14b
movq 0x2dd6(%rip), %r14      # 0x5fe0
je 0x2d73
jmp 0x3231
movq 0x2d97(%rip), %rsi      # 0x5fb0
leaq -0x1548(%rbp), %rdi
callq 0x20f0
leaq -0x14c8(%rbp), %rdi
callq 0x2040
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x3246
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
xorl %eax, %eax
addq $0x1528, %rsp           # imm = 0x1528
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x32ae
jmp 0x328a
jmp 0x3262
jmp 0x328a
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x328d
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x328d
jmp 0x32ae
jmp 0x32ae
jmp 0x32ae
jmp 0x32ae
jmp 0x328a
movq %rax, %rbx
movq 0x2d1c(%rip), %rsi      # 0x5fb0
leaq -0x1548(%rbp), %rdi
callq 0x20f0
leaq -0x14c8(%rbp), %rdi
callq 0x2040
jmp 0x32b1
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x32c6
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2220