// File: /workspace/github_cpp_makefile_star2_O2/soybin[P]idyll/src/main.cpp
// Function: main
int main(int argc, char* argv[]) {
	// base coordinates
	double y = 0.5, x = 0.5;

	// init gui
	gui::setup();

	// get config info
	int width = config::getInt("width");
	int height = config::getInt("height");
	int threadCount = config::getInt("threads");

	// pointer to seed object and parsing user input
	seed* s;
	if (argc > 2) {
		std::cout << "[-] The only permissible argument is a seed file's location.\n\n";
		return 0;
	} else if (argc == 2) {
		std::ifstream seedFile(argv[1]);
		if (!seedFile.good()) {
			std::cout << "[-] Couldn't find specified seed file.\n\n";
			return 0;
		}
		std::string seedData;
		std::getline(seedFile, seedData);
		s = new seed(seedData);
		if (!s->seedParsingSuccessful) {
			std::cout << "[-] Seed not valid.\n\n";
			delete s;
			return 0;
		}
		std::cout << "[+] Successfully read seed from '" << argv[1] << "'.\n";
	} else {
		s = new seed();
	}

	// pointer to fractal object
	fractal* f = new fractal(s);

	// pointer to renderer object
	renderer* r = new renderer(width, height, s, f);

	// pointer to 2d matrix of pixels. it'll be accessible
	// by every thread
	std::vector<std::vector<math::vec3>>* image = new std::vector<std::vector<math::vec3>>(height, std::vector<math::vec3>(width, math::vec3()));

	// thread array
	std::vector<std::thread> threads;

	// thread constants
	int chunk = width * height / threadCount;
	int lastY = 0;
	int lastX = 0;

	// thread assignment loop. this loop assigns to every thread
	// the render function with the right coordinates and stores
	// it on the thread array	
	for (int i = 0; i < threadCount; ++i) {
		int y = lastY;
		int x = lastX;
		int count = 0;
		for (; y < height && count < chunk; ) {
			for (; x < width && count < chunk; ) {
				if (++count == chunk) {
					break;
				}
				++x;
			}
			if (count < chunk) {
				x = 0;
				++y;
			}
		}

		// skip the first chunk because that one will be rendered
		// by the main thread later
		if (i > 0) {
			threads.push_back(std::thread{renderRange, lastY, y, lastX, x, width, height, chunk, r, image});
		}

		// advance one coordinate to set the starter coordinate
		// for the next loop, since this coordinate has already
		// been enqueued to be computed in the previously called
		// thread
		if (x + 1 == width) {
			x = 0;
			++y;
		} else {
			++x;
		}

		// save starter coordinates
		lastY = y;
		lastX = x;
	}

	// fill the remaining image portion which is smaller
	// than one chunk in case there's any
	if ((width * height) % threadCount != 0) {
		threads.push_back(std::thread{renderRange, lastY, height, lastX, width, width, height, chunk, r, image});
	}

	// render the first chunk in the main application thread
	// so that it can update the gui progress bar
	int count = 0;
	std::thread guiThread(gui::update, &count, chunk);
	for (int y = 0; y < height && count < chunk; ++y) {
		for (int x = 0; x < width && count < chunk; ++x) {
			(*image)[y][x] = r->render((double)height - ((double)y + 0.5f), (double)x + 0.5);
			++count;
		}
	}

	// wait for rendering threads to finish
	for (auto& thread : threads) {
		thread.join();
	}
	
	// wait for graphical user interface thread
	guiThread.join();

	//
	// define output file's path
	//
	int fileCount = 0;
	std::string fileCountStr;
	for (bool ok = true; ok & 1; ++fileCount) {
		fileCountStr = std::to_string(fileCount);
		std::ifstream pngFile("render" + fileCountStr + ".png");
		std::ifstream ppmFile("render" + fileCountStr + ".ppm");
		ok = pngFile.good() || ppmFile.good(); 
	}

	//
	// store seed inside new file
	//
	std::ofstream seedOut("seed" + fileCountStr + ".txt");
	seedOut << s->buildSeed();
	std::cout << "[+] Successfully stored seed at 'seed" << fileCountStr << ".txt'.\n";

	if (config::getInt("png")) {
		//
		// convert to portable network graphics format.
		// all credits for this functionality go to Nayuki for writing
		// the Tiny PNG Output library:
		// https://www.nayuki.io/page/tiny-png-output
		//
		try {
			// write image
			std::ofstream out("render" + fileCountStr + ".png", std::ios::binary);
			TinyPngOut pngout(static_cast<std::uint32_t>(width), static_cast<std::uint32_t>(height), out);
			std::vector<std::uint8_t> line(static_cast<size_t>(width) * 3);
			for (int y = 0; y < height; ++y) {
				for (int x = 0; x < width; ++x) {
					math::vec3 pixel = (*image)[y][x];
					line[(long long)x * 3 + 0] = static_cast<uint8_t>(pixel.x);
					line[(long long)x * 3 + 1] = static_cast<uint8_t>(pixel.y);
					line[(long long)x * 3 + 2] = static_cast<uint8_t>(pixel.z);
				}
				pngout.write(line.data(), static_cast<size_t>(width));
			}
			std::cout << "[+] Successfully stored png file to 'render" << fileCountStr << ".png'.\n\n";	
		} catch (const char* message) {
			std::cout << message << std::endl;
		}
	} else {
		//
		// write image data to ppm file
		//
		std::ofstream out("render" + fileCountStr + ".ppm");
		out << "P3\n" << width << ' ' << height << ' ' << 255 << '\n';
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {
				math::vec3 pixel = (*image)[i][j];
				out << (int)pixel.x << ' ' << (int)pixel.y << ' ' << (int)pixel.z << '\n';
			}
		}
		std::cout << "[+] Successfully store ppm file to 'render" << fileCountStr << ".ppm'.\n\n";
	}

	//
	// free heap allocated memory
	//
	delete s;
	delete f;
	delete r;
	delete image;

	// correct teminal color pallette
	std::cout << "\033[0m";
	
#ifdef _WIN32
	std::system("pause");
#endif

	// exit :D
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5a8, %rsp            # imm = 0x5A8
movq %rsi, %rbx
movl %edi, %r14d
callq 0x5a90
leaq 0x87db(%rip), %rsi      # 0xc010
leaq -0x1b8(%rbp), %rdi
leaq -0x5c8(%rbp), %rdx
callq 0x4676
leaq -0x1b8(%rbp), %rdi
callq 0x53e0
movl %eax, %r15d
leaq -0x1b8(%rbp), %rdi
callq 0x3100
movl %r15d, -0x30(%rbp)
leaq 0x93b0(%rip), %rsi      # 0xcc1e
leaq -0x198(%rbp), %rdi
leaq -0x5c8(%rbp), %rdx
callq 0x4676
leaq -0x198(%rbp), %rdi
callq 0x53e0
movl %eax, %r15d
leaq -0x198(%rbp), %rdi
callq 0x3100
movl %r15d, -0x2c(%rbp)
leaq 0x876f(%rip), %rsi      # 0xc016
leaq -0x178(%rbp), %rdi
leaq -0x5c8(%rbp), %rdx
callq 0x4676
leaq -0x178(%rbp), %rdi
callq 0x53e0
movl %eax, %r13d
leaq -0x178(%rbp), %rdi
callq 0x3100
cmpl $0x3, %r14d
jl 0x38f3
movq 0xe6ce(%rip), %rdi      # 0x11fb0
leaq 0x8735(%rip), %rsi      # 0xc01e
callq 0x3290
jmp 0x4399
cmpl $0x2, %r14d
jne 0x393b
movq 0x8(%rbx), %rsi
leaq -0x5c8(%rbp), %r14
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x3490
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x5a8(%rbp,%rax)
je 0x3956
movq 0xe689(%rip), %rdi      # 0x11fb0
leaq 0x872f(%rip), %rsi      # 0xc05d
callq 0x3290
xorl %r14d, %r14d
jmp 0x3a30
movl $0x2748, %edi           # imm = 0x2748
callq 0x32a0
movq %rax, -0x40(%rbp)
movq %rax, %rdi
callq 0x89ac
jmp 0x3a45
leaq -0x3b0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x5c8(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x3070
movl $0x2748, %edi           # imm = 0x2748
callq 0x32a0
movq %rax, -0x40(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x3350
leaq -0x158(%rbp), %rsi
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0x9730
leaq -0x158(%rbp), %rdi
callq 0x3100
movb 0x2710(%r14), %r14b
testb %r14b, %r14b
je 0x39f8
movq 0xe5e1(%rip), %rdi      # 0x11fb0
leaq 0x86c6(%rip), %rsi      # 0xc09c
callq 0x3290
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x3290
leaq 0x8704(%rip), %rsi      # 0xc0f2
movq %rax, %rdi
callq 0x3290
jmp 0x3a24
movq 0xe5b1(%rip), %rdi      # 0x11fb0
leaq 0x8680(%rip), %rsi      # 0xc086
callq 0x3290
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x9f26
movl $0x2748, %esi           # imm = 0x2748
movq %rbx, %rdi
callq 0x32b0
leaq -0x3c0(%rbp), %rdi
callq 0x3100
leaq -0x5c8(%rbp), %rdi
callq 0x30a0
testb %r14b, %r14b
je 0x4399
movl $0xa8, %edi
callq 0x32a0
movq %rax, %r12
movq %rax, %rdi
movq -0x40(%rbp), %r14
movq %r14, %rsi
callq 0x7e3c
movl $0xd0, %edi
callq 0x32a0
movq %rax, %rbx
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
movq %rax, %rdi
movq %r14, %rcx
movq %r12, -0x108(%rbp)
movq %r12, %r8
callq 0x688e
movq %rbx, -0x68(%rbp)
pushq $0x18
popq %rdi
callq 0x32a0
movq %rax, %rbx
movslq -0x2c(%rbp), %r14
movslq -0x30(%rbp), %r15
leaq -0x3c0(%rbp), %rdi
callq 0x5c20
leaq -0x5c8(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
leaq -0xc0(%rbp), %rcx
movq %r15, %rsi
callq 0x46b2
leaq -0x5c8(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4712
leaq -0x5c8(%rbp), %r14
movq %r14, %rdi
callq 0x4c12
leaq -0x58(%rbp), %rax
movq %rbx, (%rax)
xorpd %xmm0, %xmm0
leaq -0x100(%rbp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x30(%rbp), %rax
movl (%rax), %ecx
leaq -0x2c(%rbp), %rax
movl (%rax), %eax
imull %ecx, %eax
cltd
idivl %r13d
leaq -0x4c(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x48(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x34(%rbp), %rdx
xorl %r12d, %r12d
testl %r13d, %r13d
movl %r13d, -0x60(%rbp)
cmovlel %r12d, %r13d
movl %eax, (%rdx)
leaq -0xc0(%rbp), %r15
xorl %eax, %eax
xorl %edx, %edx
xorl %ebx, %ebx
cmpl %r13d, %ebx
je 0x3c37
movl %edx, -0x3c0(%rbp)
movl %eax, -0xc0(%rbp)
movl -0x2c(%rbp), %esi
movl -0x34(%rbp), %edi
leal -0x1(%rdi), %r8d
xorl %r9d, %r9d
cmpl %esi, %edx
jge 0x3bb1
cmpl %edi, %r9d
jge 0x3bb1
cmpl %ecx, %eax
jge 0x3b94
cmpl %edi, %r9d
jge 0x3b94
cmpl %r9d, %r8d
je 0x3bac
incl %eax
movl %eax, -0xc0(%rbp)
incl %r9d
jmp 0x3b79
cmpl %edi, %r9d
jge 0x3b70
andl $0x0, -0xc0(%rbp)
incl %edx
movl %edx, -0x3c0(%rbp)
xorl %eax, %eax
jmp 0x3b70
movl %edi, %r9d
jmp 0x3b70
testl %ebx, %ebx
je 0x3c17
subq $0x8, %rsp
movq %r14, %rdi
leaq -0x4b7(%rip), %rsi      # 0x370c
leaq -0x4c(%rbp), %rdx
leaq -0x3c0(%rbp), %rcx
leaq -0x48(%rbp), %r8
movq %r15, %r9
leaq -0x58(%rbp), %rax
pushq %rax
leaq -0x68(%rbp), %rax
pushq %rax
leaq -0x34(%rbp), %rax
pushq %rax
leaq -0x2c(%rbp), %rax
pushq %rax
leaq -0x30(%rbp), %rax
pushq %rax
callq 0x4772
addq $0x30, %rsp
leaq -0x100(%rbp), %rdi
movq %r14, %rsi
callq 0x50cc
movq %r14, %rdi
callq 0x4832
movl -0xc0(%rbp), %eax
movl -0x30(%rbp), %ecx
incl %eax
xorl %edx, %edx
cmpl %ecx, %eax
sete %dl
cmovel %r12d, %eax
addl -0x3c0(%rbp), %edx
movl %edx, -0x4c(%rbp)
movl %eax, -0x48(%rbp)
incl %ebx
jmp 0x3b4e
imull -0x2c(%rbp), %ecx
movl %ecx, %eax
cltd
idivl -0x60(%rbp)
testl %edx, %edx
je 0x3ca1
subq $0x8, %rsp
leaq -0x544(%rip), %rsi      # 0x370c
leaq -0x5c8(%rbp), %rdi
leaq -0x4c(%rbp), %rdx
leaq -0x48(%rbp), %r8
leaq -0x2c(%rbp), %rcx
leaq -0x30(%rbp), %r9
leaq -0x58(%rbp), %rax
pushq %rax
leaq -0x68(%rbp), %rax
pushq %rax
leaq -0x34(%rbp), %rax
pushq %rax
pushq %rcx
pushq %r9
callq 0x4772
addq $0x30, %rsp
leaq -0x100(%rbp), %rdi
leaq -0x5c8(%rbp), %rsi
callq 0x50cc
leaq -0x5c8(%rbp), %rdi
callq 0x4832
leaq -0x44(%rbp), %rax
andl $0x0, (%rax)
leaq -0x5c8(%rbp), %rdx
movq %rax, (%rdx)
leaq 0x1e26(%rip), %rsi      # 0x5adf
leaq -0x90(%rbp), %rdi
leaq -0x34(%rbp), %rcx
callq 0x4842
movl -0x44(%rbp), %eax
movl -0x34(%rbp), %ecx
xorl %r14d, %r14d
leaq -0x5c8(%rbp), %rbx
movslq -0x2c(%rbp), %rdx
cmpq %rdx, %r14
jge 0x3d68
cmpl %ecx, %eax
jge 0x3d68
cvtsi2sd %r14d, %xmm0
addsd 0x8311(%rip), %xmm0     # 0xc008
movsd %xmm0, -0x60(%rbp)
imulq $0x18, %r14, %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
movslq -0x30(%rbp), %rdx
cmpq %rdx, %r13
jge 0x3d60
cmpl %ecx, %eax
jge 0x3d60
movq -0x68(%rbp), %rsi
cvtsi2sdl -0x2c(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
cvtsi2sd %r13d, %xmm1
addsd 0x82da(%rip), %xmm1     # 0xc008
movq %rbx, %rdi
callq 0x724c
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r15), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x5d8a
movl -0x44(%rbp), %eax
incl %eax
movl %eax, -0x44(%rbp)
incq %r13
movl -0x34(%rbp), %ecx
addq $0x18, %r12
jmp 0x3d06
incq %r14
jmp 0x3cd9
movq -0x100(%rbp), %rbx
movq -0xf8(%rbp), %r14
cmpq %r14, %rbx
je 0x3d89
movq %rbx, %rdi
callq 0x3420
addq $0x8, %rbx
jmp 0x3d76
leaq -0x90(%rbp), %rdi
callq 0x3420
leaq -0xd0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movb $0x1, %r15b
xorl %esi, %esi
leaq -0x5c8(%rbp), %r14
testb $0x1, %r15b
je 0x3ed8
movq %r14, %rdi
movl %esi, %r13d
callq 0x48ca
leaq -0xe0(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x3320
movq %r14, %rbx
movq %r14, %rdi
callq 0x3100
leaq -0xc0(%rbp), %r14
movq %r14, %rdi
leaq 0x8324(%rip), %rsi      # 0xc11b
movq %r12, %rdx
callq 0x4953
leaq -0x3c0(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
leaq 0x82ab(%rip), %rdx      # 0xc0be
callq 0x492a
movq %rbx, %rdi
movq %r15, %rsi
pushq $0x8
popq %rdx
callq 0x33d0
movq %r15, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3100
leaq -0x88(%rbp), %r15
movq %r15, %rdi
leaq 0x82d4(%rip), %rsi      # 0xc11b
movq %r12, %rdx
callq 0x4953
movq %r14, %rdi
movq %r15, %rsi
leaq 0x8267(%rip), %rdx      # 0xc0c3
callq 0x492a
movq %r14, %r12
movq %rbx, %r14
leaq -0x3c0(%rbp), %rdi
movq %r12, %rsi
pushq $0x8
popq %rdx
callq 0x33d0
movq %r12, %rdi
callq 0x3100
movq %r15, %rdi
callq 0x3100
movq -0x5c8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x5a8(%rbp,%rax)
je 0x3eb7
movq -0x3c0(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x3a0(%rbp,%rax)
sete %r15b
jmp 0x3eba
movb $0x1, %r15b
leaq -0x3c0(%rbp), %rdi
callq 0x30a0
movq %r14, %rdi
callq 0x30a0
movl %r13d, %esi
incl %esi
jmp 0x3db4
leaq 0x820a(%rip), %rsi      # 0xc0e9
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0x4953
leaq 0x847a(%rip), %rdx      # 0xc373
leaq -0x3c0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x492a
leaq -0x5c8(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x34e0
leaq -0x3c0(%rbp), %rdi
callq 0x3100
leaq -0xc0(%rbp), %rdi
callq 0x3100
leaq -0x3c0(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x9f4a
leaq -0x5c8(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x3260
leaq -0x3c0(%rbp), %rdi
callq 0x3100
movq 0xe040(%rip), %rdi      # 0x11fb0
leaq 0x8151(%rip), %rsi      # 0xc0c8
callq 0x3290
leaq -0xe0(%rbp), %rsi
movq %rax, %rdi
callq 0x3260
leaq 0x815c(%rip), %rsi      # 0xc0ee
movq %rax, %rdi
callq 0x3290
leaq 0x811e(%rip), %rsi      # 0xc0bf
leaq -0x138(%rbp), %rdi
leaq -0x3c0(%rbp), %rdx
callq 0x4676
leaq -0x138(%rbp), %rdi
callq 0x53e0
movl %eax, %ebx
leaq -0x138(%rbp), %rdi
callq 0x3100
testl %ebx, %ebx
je 0x412b
leaq 0x813e(%rip), %rsi      # 0xc11b
leaq -0x88(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0x4953
leaq 0x80c7(%rip), %rdx      # 0xc0be
leaq -0xc0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x492a
leaq -0x3c0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
pushq $0x4
popq %rdx
callq 0x34e0
leaq -0xc0(%rbp), %rdi
callq 0x3100
leaq -0x88(%rbp), %rdi
callq 0x3100
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
leaq -0xc0(%rbp), %rdi
leaq -0x3c0(%rbp), %rcx
callq 0xb760
movslq -0x30(%rbp), %rax
leaq (%rax,%rax,2), %rsi
leaq -0x88(%rbp), %rdi
leaq -0x4d(%rbp), %rdx
callq 0x49ca
xorl %r14d, %r14d
leaq -0xc0(%rbp), %rbx
movslq -0x2c(%rbp), %rax
cmpq %rax, %r14
jge 0x40e9
imulq $0x18, %r14, %rax
xorl %ecx, %ecx
xorl %esi, %esi
movslq -0x30(%rbp), %rdx
cmpq %rdx, %rsi
jge 0x40d5
movq -0x58(%rbp), %rdx
movq (%rdx), %rdx
movq (%rdx,%rax), %rdx
cvttsd2si (%rdx,%rcx,8), %edi
cvttsd2si 0x8(%rdx,%rcx,8), %r8d
cvttsd2si 0x10(%rdx,%rcx,8), %edx
movq -0x88(%rbp), %r9
movb %dil, (%r9,%rcx)
movq -0x88(%rbp), %rdi
movb %r8b, 0x1(%rdi,%rcx)
movq -0x88(%rbp), %rdi
movb %dl, 0x2(%rdi,%rcx)
incq %rsi
addq $0x3, %rcx
jmp 0x4084
movq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0xb970
incq %r14
jmp 0x4073
movq 0xdec0(%rip), %rdi      # 0x11fb0
leaq 0x7fff(%rip), %rsi      # 0xc0f6
callq 0x3290
leaq -0xe0(%rbp), %rsi
movq %rax, %rdi
callq 0x3260
leaq 0x8010(%rip), %rsi      # 0xc122
movq %rax, %rdi
callq 0x3290
leaq -0x88(%rbp), %rdi
callq 0x534e
jmp 0x42db
leaq 0x7fe9(%rip), %rsi      # 0xc11b
leaq -0x88(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0x4953
leaq 0x7f77(%rip), %rdx      # 0xc0c3
leaq -0xc0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x492a
leaq -0x3c0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x34e0
leaq -0xc0(%rbp), %rdi
callq 0x3100
leaq -0x88(%rbp), %rdi
callq 0x3100
leaq 0x7f97(%rip), %rsi      # 0xc12b
leaq -0x3c0(%rbp), %rdi
callq 0x3290
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x3440
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x3310
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x3440
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x3310
movq %rax, %rdi
movl $0xff, %esi
callq 0x3440
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x3310
xorl %ecx, %ecx
pushq $0x20
popq %r14
pushq $0xa
popq %r15
movslq -0x2c(%rbp), %rax
cmpq %rax, %rcx
jge 0x42aa
movq %rcx, -0x110(%rbp)
imulq $0x18, %rcx, %r13
pushq $0x10
popq %r12
xorl %ebx, %ebx
movslq -0x30(%rbp), %rax
cmpq %rax, %rbx
jge 0x429b
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r13), %rax
movsd -0x8(%rax,%r12), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd (%rax,%r12), %xmm0
movsd %xmm0, -0x118(%rbp)
cvttsd2si -0x10(%rax,%r12), %esi
leaq -0x3c0(%rbp), %rdi
callq 0x3440
movq %rax, %rdi
movl %r14d, %esi
callq 0x3310
cvttsd2si -0x60(%rbp), %esi
movq %rax, %rdi
callq 0x3440
movq %rax, %rdi
movl %r14d, %esi
callq 0x3310
cvttsd2si -0x118(%rbp), %esi
movq %rax, %rdi
callq 0x3440
movq %rax, %rdi
movl %r15d, %esi
callq 0x3310
incq %rbx
addq $0x18, %r12
jmp 0x420c
movq -0x110(%rbp), %rcx
incq %rcx
jmp 0x41ee
movq 0xdcff(%rip), %rdi      # 0x11fb0
leaq 0x7e77(%rip), %rsi      # 0xc12f
callq 0x3290
leaq -0xe0(%rbp), %rsi
movq %rax, %rdi
callq 0x3260
leaq 0x7e87(%rip), %rsi      # 0xc15a
movq %rax, %rdi
callq 0x3290
leaq -0x3c0(%rbp), %rdi
callq 0x33a0
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x9f26
movl $0x2748, %esi           # imm = 0x2748
movq %rbx, %rdi
callq 0x32b0
movq -0x108(%rbp), %rbx
movq %rbx, %rdi
callq 0x82c8
movl $0xa8, %esi
movq %rbx, %rdi
callq 0x32b0
movq -0x68(%rbp), %rbx
testq %rbx, %rbx
je 0x432d
movq %rbx, %rdi
callq 0x7222
movl $0xd0, %esi
movq %rbx, %rdi
callq 0x32b0
movq -0x58(%rbp), %rbx
testq %rbx, %rbx
je 0x434b
movq %rbx, %rdi
callq 0x4a1c
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x32b0
movq 0xdc53(%rip), %rdi      # 0x11fb0
leaq 0x7dff(%rip), %rsi      # 0xc163
callq 0x3290
leaq -0x5c8(%rbp), %rdi
callq 0x33a0
leaq -0xe0(%rbp), %rdi
callq 0x3100
leaq -0x90(%rbp), %rdi
callq 0x4832
leaq -0x100(%rbp), %rdi
callq 0x4a48
xorl %eax, %eax
addq $0x5a8, %rsp            # imm = 0x5A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq -0x158(%rbp), %rdi
callq 0x3100
jmp 0x43c1
movq %rax, %r15
movl $0x2748, %esi           # imm = 0x2748
movq -0x40(%rbp), %rdi
callq 0x32b0
jmp 0x44df
movq %rax, %r15
leaq -0xc0(%rbp), %rdi
callq 0x3100
jmp 0x43e8
movq %rax, %r15
leaq -0x88(%rbp), %rdi
jmp 0x447a
jmp 0x4550
movq %rax, %r15
jmp 0x44eb
jmp 0x4403
movq %rdx, %rbx
movq %rax, %r15
jmp 0x456a
movq %rdx, %rbx
movq %rax, %r15
leaq -0xc0(%rbp), %rdi
callq 0x3100
jmp 0x4428
movq %rdx, %rbx
movq %rax, %r15
leaq -0x88(%rbp), %rdi
callq 0x3100
jmp 0x4576
movq %rdx, %rbx
movq %rax, %r15
jmp 0x4576
jmp 0x45b5
jmp 0x45c4
movq %rax, %r15
movl $0x2748, %esi           # imm = 0x2748
movq -0x40(%rbp), %rdi
jmp 0x4507
movq %rax, %r15
leaq -0x138(%rbp), %rdi
jmp 0x447a
jmp 0x4550
movq %rax, %r15
leaq -0x3c0(%rbp), %rdi
callq 0x3100
jmp 0x463e
jmp 0x4550
movq %rax, %r15
leaq -0x3c0(%rbp), %rdi
callq 0x3100
jmp 0x4613
movq %rax, %r15
jmp 0x4613
jmp 0x4623
jmp 0x462a
jmp 0x45c4
movq %rax, %r15
leaq -0x5c8(%rbp), %rdi
callq 0x4c12
jmp 0x44ca
jmp 0x44c7
movq %rax, %r15
pushq $0x18
popq %rsi
jmp 0x44d7
movq %rax, %r15
movl $0xd0, %esi
movq %rbx, %rdi
jmp 0x4507
movq %rax, %r15
leaq -0x3c0(%rbp), %rdi
callq 0x3100
leaq -0x5c8(%rbp), %rdi
callq 0x30a0
jmp 0x466e
movq %rax, %r15
movl $0xa8, %esi
movq %r12, %rdi
callq 0x32b0
jmp 0x466e
jmp 0x4558
movq %rax, %r15
leaq -0x178(%rbp), %rdi
jmp 0x4539
jmp 0x4543
movq %rax, %r15
leaq -0x198(%rbp), %rdi
jmp 0x4539
jmp 0x4543
movq %rax, %r15
leaq -0x1b8(%rbp), %rdi
callq 0x3100
jmp 0x466e
movq %rax, %r15
jmp 0x466e
jmp 0x462f
movq %rax, %r15
jmp 0x463e
movq %rdx, %rbx
movq %rax, %r15
leaq -0x88(%rbp), %rdi
callq 0x534e
leaq -0x3c0(%rbp), %rdi
callq 0x33a0
cmpl $0x1, %ebx
jne 0x463e
movq %r15, %rdi
callq 0x30e0
movq 0xda22(%rip), %rdi      # 0x11fb0
movq %rax, %rsi
callq 0x3290
movq %rax, %rdi
callq 0x3120
callq 0x33f0
jmp 0x42e7
movq %rax, %r15
callq 0x33f0
jmp 0x463e
movq %rax, %r15
leaq -0x5c8(%rbp), %rdi
jmp 0x465d
movq %rax, %r15
jmp 0x4662
movq %rax, %r15
leaq -0xc0(%rbp), %rdi
callq 0x3100
jmp 0x45e0
movq %rax, %r15
leaq -0x88(%rbp), %rdi
callq 0x3100
jmp 0x45f1
movq %rax, %r15
leaq -0x5c8(%rbp), %rdi
callq 0x30a0
jmp 0x464a
movq %rax, %r15
leaq -0x3c0(%rbp), %rdi
callq 0x3100
jmp 0x4613
movq %rax, %r15
leaq -0xc0(%rbp), %rdi
callq 0x3100
jmp 0x464a
jmp 0x4623
movq %rax, %r15
jmp 0x464a
jmp 0x462a
movq %rax, %r15
jmp 0x4656
movq %rax, %r15
leaq -0x3c0(%rbp), %rdi
callq 0x33a0
leaq -0x5c8(%rbp), %rdi
callq 0x33a0
leaq -0xe0(%rbp), %rdi
callq 0x3100
leaq -0x90(%rbp), %rdi
callq 0x4832
leaq -0x100(%rbp), %rdi
callq 0x4a48
movq %r15, %rdi
callq 0x3460