// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1518, %rsp           # imm = 0x1518
callq 0x238c
movl $0x600000, %edi         # imm = 0x600000
callq 0x2140
movq %rax, -0x80(%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 0x3316(%rip), %rdi      # 0x5fd0
leaq 0x1420(%rip), %rsi      # 0x40e1
movl $0x22, %edx
callq 0x2160
movq 0x32fe(%rip), %rdi      # 0x5fd0
leaq 0x142b(%rip), %rsi      # 0x4104
movl $0x22, %edx
callq 0x2160
movq 0x32e6(%rip), %rdi      # 0x5fd0
leaq 0x1436(%rip), %rsi      # 0x4127
movl $0x22, %edx
callq 0x2160
movq 0x32ce(%rip), %rdi      # 0x5fd0
leaq 0x1441(%rip), %rsi      # 0x414a
movl $0x22, %edx
callq 0x2160
movq 0x32b6(%rip), %rdi      # 0x5fd0
leaq 0x13c0(%rip), %rsi      # 0x40e1
movl $0x22, %edx
callq 0x2160
leaq -0x1540(%rbp), %r12
leaq -0x1b8(%rbp), %r14
leaq -0x60(%rbp), %r13
movl $0x13, %edx
movq 0x3287(%rip), %rdi      # 0x5fd0
leaq 0x141d(%rip), %rsi      # 0x416d
callq 0x2160
movq 0x3284(%rip), %rdi      # 0x5fe0
leaq -0x40(%rbp), %rsi
callq 0x20b0
movsd -0x40(%rbp), %xmm0
movsd 0x12de(%rip), %xmm1     # 0x4050
minsd %xmm0, %xmm1
movsd 0x129a(%rip), %xmm3     # 0x4018
cmpltsd %xmm3, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movlpd %xmm0, -0x40(%rbp)
movl $0x13, %edx
movq 0x322c(%rip), %rdi      # 0x5fd0
leaq 0x13d6(%rip), %rsi      # 0x4181
callq 0x2160
movq 0x3229(%rip), %rdi      # 0x5fe0
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 0x31e8(%rip), %rdi      # 0x5fd0
leaq 0x13a6(%rip), %rsi      # 0x4195
callq 0x2160
movq 0x31e5(%rip), %rdi      # 0x5fe0
leaq -0x34(%rbp), %rsi
callq 0x2210
movl -0x34(%rbp), %eax
movq %rax, -0x1540(%rbp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, -0x1540(%rbp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x2e13
movq $0x270, -0x1c0(%rbp) # imm = 0x270
xorl %eax, %eax
movb %al, -0x1b8(%rbp,%rax)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x2e45
movl $0x2, %ebx
movq %r12, %rdi
callq 0x3c52
xorl %edx, %edx
divq %rbx
movb -0x1b9(%rbp,%rbx), %al
movb -0x1b8(%rbp,%rdx), %cl
movb %cl, -0x1b9(%rbp,%rbx)
movb %al, -0x1b8(%rbp,%rdx)
incq %rbx
cmpq $0x101, %rbx            # imm = 0x101
jne 0x2e5c
movl -0x64(%rbp), %eax
testl %eax, %eax
jle 0x303d
movsd -0x40(%rbp), %xmm1
movl -0x68(%rbp), %ecx
cvtsi2sd %ecx, %xmm0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, -0x90(%rbp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x88(%rbp)
xorl %ebx, %ebx
testl %ecx, %ecx
jle 0x302e
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
xorl %r12d, %r12d
movl -0x30(%rbp), %r15d
testl %r15d, %r15d
jle 0x2fb3
xorps %xmm4, %xmm4
cvtsi2sd %r12d, %xmm4
mulsd -0x90(%rbp), %xmm4
xorpd %xmm2, %xmm2
movsd 0x1108(%rip), %xmm3     # 0x4020
movsd -0x98(%rbp), %xmm1
movsd %xmm1, -0xa0(%rbp)
movsd %xmm3, -0xa8(%rbp)
movsd %xmm4, -0xb0(%rbp)
movsd %xmm2, -0xb8(%rbp)
movq %r14, %rdi
movapd %xmm4, %xmm0
movsd 0x10e1(%rip), %xmm2     # 0x4030
callq 0x36ec
movsd -0xa0(%rbp), %xmm1
movsd -0xa8(%rbp), %xmm3
movsd -0xb0(%rbp), %xmm4
movsd -0xb8(%rbp), %xmm2
mulsd %xmm3, %xmm0
addsd %xmm0, %xmm2
addsd %xmm4, %xmm4
addsd %xmm1, %xmm1
mulsd 0x109c(%rip), %xmm3     # 0x4028
decl %r15d
jne 0x2f20
xorpd %xmm0, %xmm0
movsd 0x109b(%rip), %xmm1     # 0x4038
ucomisd %xmm2, %xmm1
jae 0x2fcb
movsd 0x1075(%rip), %xmm0     # 0x4020
ucomisd %xmm0, %xmm2
jb 0x2fb7
jmp 0x2fcb
xorpd %xmm2, %xmm2
movsd 0x1069(%rip), %xmm0     # 0x4028
mulsd %xmm0, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, %xmm0
movl -0x68(%rbp), %ecx
movl -0x64(%rbp), %eax
movslq %eax, %rdx
cmpq %rdx, %rbx
setl %dil
movslq %ecx, %rsi
cmpq %rsi, %r12
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x3019
movq %rbx, %rdi
imulq %rsi, %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x3, %rdi
addq -0x80(%rbp), %rdi
leaq (%r12,%r12,2), %r8
movsd %xmm0, (%rdi,%r8,8)
movsd %xmm0, 0x8(%rdi,%r8,8)
movsd %xmm0, 0x10(%rdi,%r8,8)
incq %r12
cmpq %rsi, %r12
jl 0x2eef
leaq -0x1540(%rbp), %r12
jmp 0x3031
movslq %eax, %rdx
incq %rbx
cmpq %rdx, %rbx
jl 0x2ecd
movq %r12, %rdi
callq 0x20d0
movb $0x66, -0x60(%rbp)
movl $0x1, %edx
leaq -0x1530(%rbp), %rdi
movq %r13, %rsi
callq 0x2160
movsd -0x40(%rbp), %xmm0
movq %rax, %rdi
callq 0x21d0
movb $0x6f, -0x60(%rbp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2160
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x2200
movb $0x5f, -0x60(%rbp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2160
movl -0x34(%rbp), %esi
movq %rax, %rdi
callq 0x20c0
movl $0x4, %edx
movq %rax, %rdi
leaq 0x10f2(%rip), %rsi      # 0x41a9
callq 0x2160
movq %r13, %rdi
leaq -0x1528(%rbp), %rsi
callq 0x21c0
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
callq 0x3318
movl %eax, %ebx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x30f2
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2150
testb %bl, %bl
je 0x3160
movl $0xa, %edx
movq 0x2ece(%rip), %rdi      # 0x5fd0
leaq 0x10a5(%rip), %rsi      # 0x41ae
callq 0x2160
movq %r13, %rdi
leaq -0x1528(%rbp), %rsi
callq 0x21c0
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x2ea4(%rip), %rdi      # 0x5fd0
callq 0x2160
movl $0x2, %edx
movq %rax, %rdi
leaq 0x1079(%rip), %rsi      # 0x41b9
callq 0x2160
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x3178
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x3178
movl $0xa, %edx
movq 0x2e64(%rip), %rdi      # 0x5fd0
leaq 0x1049(%rip), %rsi      # 0x41bc
callq 0x2160
movl $0x11, %edx
movq 0x2e4c(%rip), %rdi      # 0x5fd0
leaq 0x103c(%rip), %rsi      # 0x41c7
callq 0x2160
movq 0x2e49(%rip), %rdi      # 0x5fe0
leaq -0x29(%rbp), %rsi
callq 0x2180
cmpb $0x79, -0x29(%rbp)
jne 0x31de
movb $0xa, -0x60(%rbp)
movl $0x1, %edx
movq 0x2e1a(%rip), %rdi      # 0x5fd0
movq %r13, %rsi
callq 0x2160
movq %r12, %rdi
movq 0x2de8(%rip), %rsi      # 0x5fb0
callq 0x20f0
leaq -0x14c0(%rbp), %rdi
callq 0x2040
jmp 0x2d3d
movq 0x2dcb(%rip), %rsi      # 0x5fb0
leaq -0x1540(%rbp), %rdi
callq 0x20f0
leaq -0x14c0(%rbp), %rdi
callq 0x2040
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x3212
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
xorl %eax, %eax
addq $0x1518, %rsp           # imm = 0x1518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x327a
jmp 0x3256
jmp 0x322c
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x3259
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x3259
jmp 0x3256
jmp 0x327a
jmp 0x327a
jmp 0x327a
jmp 0x327a
jmp 0x3256
movq %rax, %rbx
movq 0x2d50(%rip), %rsi      # 0x5fb0
leaq -0x1540(%rbp), %rdi
callq 0x20f0
leaq -0x14c0(%rbp), %rdi
callq 0x2040
jmp 0x327d
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x3292
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2220