// File: bsaikiran618[P]mandelbrot-set-viewer/Window.cpp
// Function: Window::drawScreen(Cartesian2DPlane*)
void Window::drawScreen(Cartesian2DPlane *plane)
{
			clock_t start, end;

			start = clock();

			SDL_SetRenderDrawColor(screenRenderer, 0,0,0,SDL_ALPHA_OPAQUE);
			SDL_RenderClear(screenRenderer);

			for(uint64_t scr_x = 0; scr_x < plane->getWidth(); scr_x++)
			{
				for(uint64_t scr_y = 0; scr_y < plane->getHeight(); scr_y++)
				{
					//convert the screen coordinates to the cartesian plane coordinates
					Cartesian2DPoint p1(uint64_t(scr_x), uint64_t(scr_y), plane);
					//convert cartesian plane coordinates to complex plane coordinates
					//std::complex<double> p2(p1.getPlaneX(), p1.getPlaneY());
					std::complex<double> p2(-p1.getPlaneY(), p1.getPlaneX());
					int c;
					if((c = inMandelbrotSet(p2, 20)) != -1)
					{
						/*
						int r = int(c * 0.01 * 255)%255;
						int g = int(c * 0.03 * 255)%255;
						int b = int(c * 0.05 * 255)%255;
						*/
						long int r,g,b;
						if(c != 0)
						{
							r = (c) % 256;
							g = (c*c) % 256;
							b = (c*c+c) % 256;
						}else r = g = b = 0;
						SDL_SetRenderDrawColor(screenRenderer, r, g, b, SDL_ALPHA_OPAQUE);
					}
					else
						SDL_SetRenderDrawColor(screenRenderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
					SDL_RenderDrawPoint(screenRenderer, p1.getOnScreenX(), p1.getOnScreenY());
				}
			}
			//drawAxes(plane);
			SDL_RenderPresent(screenRenderer);
			end = clock();
			double elapsed_time = double(end - start)/CLOCKS_PER_SEC;
			std::cout << "\r" << elapsed_time << " secs/frame";
			fflush(stdout);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
callq 0x2130
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, -0x18(%rbp)
movq 0x10(%rax), %rdi
xorl %ecx, %ecx
movl $0xff, %r8d
movl %ecx, %esi
movl %ecx, %edx
callq 0x2280
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x21c0
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3110
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x2df7
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2de4
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq -0x48(%rbp), %rdi
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x3150
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3170
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
leaq -0x58(%rbp), %rdi
callq 0x3190
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movl $0x14, %edi
callq 0x3770
movl %eax, -0x5c(%rbp)
cmpl $-0x1, %eax
je 0x2d79
cmpl $0x0, -0x5c(%rbp)
je 0x2d2a
movl -0x5c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movslq %edx, %rax
movq %rax, -0x78(%rbp)
movl -0x5c(%rbp), %eax
imull -0x5c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movslq %edx, %rax
movq %rax, -0x80(%rbp)
movl -0x5c(%rbp), %eax
imull -0x5c(%rbp), %eax
addl -0x5c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movslq %edx, %rax
movq %rax, -0x88(%rbp)
jmp 0x2d45
movq $0x0, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x78(%rbp), %rax
movb %al, %dl
movq -0x80(%rbp), %rax
movb %al, %cl
movq -0x88(%rbp), %rax
movl $0xff, %r8d
movzbl %dl, %esi
movzbl %cl, %edx
movzbl %al, %ecx
callq 0x2280
jmp 0x2d95
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %ecx, %ecx
movl $0xff, %r8d
movl %ecx, %esi
movl %ecx, %edx
callq 0x2280
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xc0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3360
movl %eax, -0xb4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3410
movq -0xc0(%rbp), %rdi
movl -0xb4(%rbp), %esi
movl %eax, %edx
callq 0x21b0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x2c2d
jmp 0x2de6
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2bfe
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2050
callq 0x2130
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
subq -0x18(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x1283(%rip), %xmm1     # 0x40a8
divsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movq 0x3198(%rip), %rdi      # 0x5fd0
leaq 0x1279(%rip), %rsi      # 0x40b8
callq 0x21e0
movq %rax, %rdi
movsd -0x90(%rbp), %xmm0
callq 0x2310
movq %rax, %rdi
leaq 0x125c(%rip), %rsi      # 0x40ba
callq 0x21e0
movq 0x313e(%rip), %rax      # 0x5fa8
movq (%rax), %rdi
callq 0x2240
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)