// File: /workspace/github_cpp_makefile_star2_O1/kchan1[P]helloworld_test1/main.cpp
// Function: main
int main(int argc, char * arg[])

{	
	if (argc == 1){
		std::cout<<"Error: No filename submitted. Please input filename."<<std::endl;
		return 1;
	}

	int quant;

	if (argc >= 3){
		int arg2i = atoi(arg[2]);
		if (arg2i>=1){
			quant = arg2i;	
		}
		else{
		std::cout<<"Error: Qunatization scale must be a positive non-zero number."<<std::endl;
		return 1;
		}
	}
	else{
		quant = 20;
	}

	int depth;

	if (argc >= 4){
		int arg3i = atoi(arg[3]);
		if (arg3i>=1){
			depth = arg3i;	
		}
		else{
		std::cout<<"Error: Depth scale must be a positive non-zero number."<<std::endl;
		return 1;
		}
	}
	else{
		depth = 1;
	}
	

	//for handling the file
	std::string filename = arg[1];
	std::ifstream image_file;
	
	//buffers for reading the header
	unsigned char begin_of_bitmap[4];
	unsigned char width_data[4];
	unsigned char height_data[4];
	unsigned char pixel_bit_data[2];
	
	//secondary buffers for interpretting the header
	int bitmap_offset=0;
	int width =0;
	int image_width = 0;
	int height =0;
	int pixel_bits=0;
	
	//start reading 10 bytes after the beginning of the file
	image_file.open(filename.c_str(), std::ifstream::in | std::ifstream::binary);
	image_file.seekg(10, std::ifstream::beg);

	//read the first 4 bytes of the file which are interpretted for the header size
	image_file.read(reinterpret_cast<char*>(begin_of_bitmap),4);
	//B0*2^0 + B1*2^8 + B2*2^16 + B3*2^24
	for (int i=0; i<4; i++){
		bitmap_offset+=(int)begin_of_bitmap[i]*pow(2,i*8);
	//	std::cout<<(int)begin_of_bitmap[i]<<" ";
	}
	//std::cout<<std::endl;

	//std::cout<<bitmap_offset<<std::endl;

	//start reading 18 bytes after the beginning of the file
	image_file.seekg(18, std::ifstream::beg);
	//read 4 bytes as the width
	image_file.read(reinterpret_cast<char*>(width_data),4);
	for(int i=0; i<4; i++){
		width+=(int)width_data[i]*pow(2,i*8);
	}
	//BMP pads their formats into 4 byte sizes.
	width = (int)((3*8*width+31)/(32))*4;
	image_width = width;
	width /= 3;
	
	//read 4 bytes as the height
	image_file.read(reinterpret_cast<char*>(height_data),4);
	for(int i=0; i<4; i++){
		height+=(int)height_data[i]*pow(2,i*8);
	}

	//std::cout<<width<<" "<<height<<std::endl;

	//start reading 28 bytes after the beginning of the file
	image_file.seekg(28, std::ifstream::beg);
	
	//read 2 bytes of data as the number of bits per pixel
	image_file.read(reinterpret_cast<char*>(pixel_bit_data),2);
	for(int i=0; i<2; i++){
		pixel_bits+=(int)pixel_bit_data[i]*pow(2,i*8);
	}

	//we are restricting the program to 24-bit bitmaps
	if(pixel_bits != 24){
		std::cout<<"Image is not a 24-bit bitmap file. Please submit a properly formatted file."<<std::endl;
		return 1;
	}
	
	//holds all the of the header information
	unsigned char* image_header_data= new unsigned char[bitmap_offset];
	//holds the raw input image data BUT also the raw input image output
	unsigned char** imageData=new unsigned char*[height];
	double** image_data = new double*[height];
	char** image_data_char = new char*[height];
	//holds the image data separated into colors
	double** blue_data=new double*[height];
	double** green_data=new double*[height];
	double** red_data=new double*[height];

	//further initialize 2D arrays
	for (int i = 0; i<height; i++){
		imageData[i] = new unsigned char[image_width];
		image_data[i] = new double[image_width];
		image_data_char[i] = new char[image_width];
		blue_data[i] = new double[width];
		green_data[i] = new double[width];
		red_data[i] = new double[width];
	}	

	//read the header information(again?) into image_header_data
	image_file.seekg(0, std::ifstream::beg);
	image_file.read(reinterpret_cast<char*>(image_header_data),bitmap_offset);

	//read in the raw image data
	for (int i=0; i<height; i++){
		image_file.read(reinterpret_cast<char*>(imageData[i]),image_width);
	}

//	for (int i=0; i<height; i++){
//		std::cout<<imageData[i]<<" ";
//	}
//	std::cout<<std::endl;

/*	for (int i=0; i<10; i++){
		std::cout<<"[ ";
		for(int j = 0; j<10; j++){
			std::cout<<(int)imageData[i][j]<<" ";
		}
		std::cout<<"]"<<std::endl;
	}*/

	for(int i = 0; i<height; i++){
		for(int j = 0; j<image_width; j++){
			image_data[i][j]=imageData[i][j];
		}
	}

	//separate imageData into the 3 colors
	for (int i = 0; i<height; i++){
		for(int j = 0; j<image_width; j+=3){
			blue_data[i][j/3] = image_data[i][j];
		}
		for(int j = 1; j<image_width; j+=3){
			green_data[i][j/3] = image_data[i][j];
		}
		for(int j=2;j<image_width; j+=3){
			red_data[i][j/3] = image_data[i][j];
		}
	}
	
	//don't need to read the image anymore
	image_file.close();

/*
 *At this point, the image is properly loaded into several char arrays. They can be 
 numerically manipulated like normal numbers (each individual array entry)
 The arrays are:

 imageData <- all the pixels of the image.
 image_data <- all pixels in double form.
 blue_data <- all the blue pixel values.
 green_data <- all the green pixel values.
 red_data <- all the red pixel values.

 height <- original image height.
 width <- original image width.
 
 image_header_data <- the original image header
 *
 *
 *                            Subband Decomposition
 *========================================================================
 */

//	reconstruct((imageData),height,width*3,image_header_data,bitmap_offset,filename);
	
	int decomp_height = height;
	int decomp_width = width;
	int decomposition_loops = depth;
	
	//for the number of loops (hardcoded 3) decompose the arrays
	//each iteration creates the quarter-subarays for LL, LH, HL, HH
	//the quarter subarray LL is then further decomposed for another loop
	for(int i=0; i<decomposition_loops; i++){

	subband_decomp(blue_data,decomp_height,decomp_width);
	subband_decomp(green_data,decomp_height,decomp_width);
	subband_decomp(red_data,decomp_height,decomp_width);
	
	decomp_height/=2;
	decomp_width/=2;

	}

	/*for (int i = 0 ; i <height; i++){
		for(int j = 0; j<width; j++){
		std::cout<< blue_data[i][j]<<" ";
		}
		std::cout<<std::endl;
	}*/

	//read the colors back into imageData
	for (int i = 0; i<height; i++){
		for(int j = 0; j<image_width; j+=3){
			image_data[i][j]=blue_data[i][j/3];
		}
		for(int j = 1; j<image_width; j+=3){
			image_data[i][j]=green_data[i][j/3];
		}
		for(int j=2;j<image_width; j+=3){
			image_data[i][j]=red_data[i][j/3];
		}
	}

	for (int i=0; i<height; i++){
		for(int j=0; j<image_width; j++){
			if (image_data[i][j]<0){
				image_data[i][j]=0;
			}
			if (image_data[i][j]>255){
				image_data[i][j]=255;
			}
		}
	}

	for(int i = 0; i<height; i++){
		for(int j = 0; j<image_width; j++){
			imageData[i][j]=image_data[i][j];
		}
	}

	/*for (int i = 0 ; i <height; i++){
		for(int j = 0; j<width; j++){
		std::cout<<(int)imageData[i][j]<<" ";
		}
		std::cout<<std::endl;
	}*/
	
	reconstruct(imageData,height,image_width,image_header_data,bitmap_offset,filename+"subband");

	
	int recomp_height= height;
	int recomp_width = width;
	int num_decomps = decomposition_loops;

	prepare(blue_data,height,width,quant);
	prepare(green_data,height,width,quant);
	prepare(red_data,height,width,quant);

	/*for(int i = 0; i<height; i++){
		for(int j = 0; j<width; j++){
			std::cout<<(int)blue_data[i][j]<<" ";
		}
	}*/

	//for (int i = 0; i<20; i++){
	//	std::cout<<red_data[2][i]*20<<std::endl;
	//}

	compress(blue_data,green_data,red_data,height,width,image_header_data,bitmap_offset,filename,decomposition_loops,quant);
	
	/*for (int i = 0; i<height; i++){
		for(int j = 0; j<image_width; j+=3){
			image_data_char[i][j]=blue_data[i][j/3];
		}
		for(int j = 1; j<image_width; j+=3){
			image_data_char[i][j]=green_data[i][j/3];
		}
		for(int j=2;j<image_width; j+=3){
			image_data_char[i][j]=red_data[i][j/3];
		}
		//for(int j=0; j<image_width; j++){
		//	std::cout<<(int)image_data_char[i][j]<<" ";
		//}
	}

	

	for (int i = num_decomps; i>=1; i--){
		recomp_height = height/pow(2,i-1);
		recomp_width = width/pow(2,i-1);
		subband_recomp(blue_data,recomp_height,recomp_width);
		subband_recomp(green_data,recomp_height,recomp_width);
		subband_recomp(red_data,recomp_height,recomp_width);
	}

	for (int i = 0; i<height; i++){
		for(int j = 0; j<image_width; j+=3){
			image_data[i][j]=blue_data[i][j/3];
		}
		for(int j = 1; j<image_width; j+=3){
			image_data[i][j]=green_data[i][j/3];
		}
		for(int j=2;j<image_width; j+=3){
			image_data[i][j]=red_data[i][j/3];
		}
	}

	for (int i=0; i<height; i++){
		for(int j=0; j<image_width; j++){
			if (image_data[i][j]<0){
				image_data[i][j]=0;
			}
			if (image_data[i][j]>255){
				image_data[i][j]=255;
			}
		}
	}

	for(int i = 0; i<height; i++){
		for(int j = 0; j<image_width; j++){
			imageData[i][j]=image_data[i][j];
		}
	}

	
	reconstruct(imageData,height,image_width,image_header_data,bitmap_offset,"Testout2.bmp");
*/

/*
 *	So now imageData has the Subband Decomposition of the oringal image (decomposed twice).
 *	the compression portion hasn't happened yet, that involves choosing the threshold and such.
 *
 *
 *
 *
 *
 *=================================================================================
 */
	//clean up memory
	delete image_header_data;
	for(int i=0;i<height;i++)
	{
	  delete imageData[i];
	  delete blue_data[i];
	  delete green_data[i];
	  delete red_data[i];  
	}
	delete imageData;
	delete blue_data;
	delete green_data;
	delete red_data;
   return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
cmpl $0x1, %edi
jne 0x3eea
movq 0x3133(%rip), %rbx      # 0x6fd8
leaq 0x11c6(%rip), %rsi      # 0x5072
movl $0x34, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl $0x1, %ebp
jmp 0x48e7
movq %rsi, %rbx
movl %edi, %r14d
cmpl $0x3, %edi
jl 0x3f5f
movq 0x10(%rbx), %rdi
callq 0x21e0
xorl %ebp, %ebp
testl %eax, %eax
jg 0x3f51
movq 0x30cd(%rip), %r15      # 0x6fd8
movq %rax, %r12
leaq 0x1192(%rip), %rsi      # 0x50a7
movl $0x3d, %edx
movq %r15, %rdi
callq 0x2160
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movq %r12, %rax
movl $0x1, %ebp
movq %rax, 0x78(%rsp)
testl %eax, %eax
jg 0x3f6b
jmp 0x48e7
xorl %ebp, %ebp
movl $0x14, %eax
movq %rax, 0x78(%rsp)
movl $0x1, %eax
movq %rax, 0x48(%rsp)
cmpl $0x4, %r14d
jl 0x3fe6
movq 0x18(%rbx), %rdi
callq 0x21e0
movl %eax, %r14d
testl %eax, %eax
jg 0x3fd8
movq %r14, %r15
movq 0x3043(%rip), %r14      # 0x6fd8
leaq 0x1149(%rip), %rsi      # 0x50e5
movl $0x36, %edx
movq %r14, %rdi
callq 0x2160
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r14, %rdi
movq %r15, %r14
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl $0x1, %ebp
movq %r14, 0x48(%rsp)
testl %r14d, %r14d
jle 0x48e7
movq 0x8(%rbx), %rsi
leaq 0xa0(%rsp), %rdi
leaq 0x100(%rsp), %rdx
callq 0x49e4
leaq 0x100(%rsp), %rdi
callq 0x2150
movl $0x0, 0x24(%rsp)
movq 0xa0(%rsp), %rsi
leaq 0x100(%rsp), %rdi
movl $0xc, %edx
callq 0x20a0
leaq 0x100(%rsp), %rdi
movl $0xa, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x100(%rsp), %rdi
leaq 0xdc(%rsp), %rbx
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2180
movl 0x24(%rsp), %ebp
xorl %r14d, %r14d
movzbl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
callq 0x2110
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %r14
incq %rbx
cmpq $0x20, %r14
jne 0x4066
movl %ebp, 0x24(%rsp)
leaq 0x100(%rsp), %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x100(%rsp), %rdi
leaq 0xd8(%rsp), %rbx
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2180
xorl %r14d, %r14d
xorl %r12d, %r12d
movzbl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
callq 0x2110
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12d
addq $0x8, %r14
incq %rbx
cmpq $0x20, %r14
jne 0x40e0
leal (,%r12,8), %eax
leal (%rax,%rax,2), %ecx
addl $0x1f, %ecx
leal (%rax,%rax,2), %ebp
addl $0x3e, %ebp
testl %ecx, %ecx
cmovnsl %ecx, %ebp
leaq 0x100(%rsp), %rdi
leaq 0xd4(%rsp), %rbx
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2180
sarl $0x5, %ebp
shll $0x2, %ebp
movl %ebp, 0x20(%rsp)
movslq %ebp, %r14
imulq $0x55555556, %r14, %r13 # imm = 0x55555556
movq %r13, %rax
shrq $0x3f, %rax
shrq $0x20, %r13
addl %eax, %r13d
xorl %r15d, %r15d
xorl %ebp, %ebp
movzbl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
callq 0x2110
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %r15
incq %rbx
cmpq $0x20, %r15
jne 0x417e
movl %ebp, 0x14(%rsp)
leaq 0x100(%rsp), %rdi
movl $0x1c, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x100(%rsp), %rdi
leaq 0x6e(%rsp), %rbx
movl $0x2, %edx
movq %rbx, %rsi
callq 0x2180
xorl %r15d, %r15d
xorl %ebp, %ebp
movzbl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
callq 0x2110
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %r15
incq %rbx
cmpq $0x8, %r15
je 0x41f4
cmpl $0x18, %ebp
jne 0x486e
movslq 0x24(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x2030
movq %rax, 0x40(%rsp)
movq %rax, 0xc8(%rsp)
movslq 0x14(%rsp), %rax
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %rbx
cmovnsq %rcx, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, %r15
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x38(%rsp)
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
movq %rax, 0x58(%rsp)
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x14(%rsp), %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
testl %eax, %eax
jle 0x4363
leaq (,%r14,8), %rcx
movslq %r13d, %rbx
shlq $0x3, %rbx
cmpl $-0x2, %r12d
movq $-0x1, %rax
cmovlq %rax, %rcx
movq %rcx, 0xc0(%rsp)
cmovlq %rax, %rbx
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x2030
movq %rax, (%r15,%rbp,8)
movq 0xc0(%rsp), %rdi
callq 0x2030
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq %rbx, %rdi
callq 0x2030
movq 0x38(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq %rbx, %rdi
callq 0x2030
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq %rbx, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
cmpq %rbp, 0x8(%rsp)
jne 0x4304
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x100(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x2180
cmpl $0x0, 0x14(%rsp)
jle 0x43b5
xorl %ebp, %ebp
leaq 0x100(%rsp), %rbx
movq (%r15,%rbp,8), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2180
incq %rbp
cmpq %rbp, 0x8(%rsp)
jne 0x439c
cmpl $0x0, 0x14(%rsp)
jle 0x4405
movl 0x20(%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
testl %r12d, %r12d
jle 0x43fb
movq (%r15,%rcx,8), %rdx
movq 0x18(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
xorl %edi, %edi
movzbl (%rdx,%rdi), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x43e1
incq %rcx
cmpq 0x8(%rsp), %rcx
jne 0x43cd
cmpl $0x0, 0x14(%rsp)
jle 0x44b3
xorl %eax, %eax
testl %r12d, %r12d
jle 0x4441
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x38(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx)
addq $0x3, %rsi
addq $0x8, %rdx
cmpq %r14, %rsi
jl 0x442b
testl %r12d, %r12d
jle 0x4473
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x28(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
movl $0x1, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx)
addq $0x3, %rsi
addq $0x8, %rdx
cmpq %r14, %rsi
jl 0x445d
testl %r12d, %r12d
jle 0x44a5
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x30(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
movl $0x2, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx)
addq $0x3, %rsi
addq $0x8, %rdx
cmpq %r14, %rsi
jl 0x448f
incq %rax
cmpq 0x8(%rsp), %rax
jne 0x4412
leaq 0x100(%rsp), %rdi
callq 0x2060
movq 0x48(%rsp), %rax
cmpl $0x1, %eax
movl %eax, %ebx
adcl $0x0, %ebx
movl 0x14(%rsp), %ebp
leaq 0x60(%rsp), %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x2f73
leaq 0x58(%rsp), %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x2f73
leaq 0x50(%rsp), %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x2f73
movl %ebp, %eax
shrl $0x1f, %eax
addl %ebp, %eax
sarl %eax
movl %r13d, %ecx
shrl $0x1f, %ecx
addl %r13d, %ecx
sarl %ecx
movl %ecx, %r13d
movl %eax, %ebp
decl %ebx
jne 0x44d1
movl 0x14(%rsp), %ebp
testl %ebp, %ebp
jle 0x45ca
xorl %eax, %eax
testl %r12d, %r12d
jle 0x4558
movq 0x38(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x18(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
xorl %esi, %esi
movsd (%rcx), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
addq $0x3, %rsi
addq $0x8, %rcx
cmpq %r14, %rsi
jl 0x4542
testl %r12d, %r12d
jle 0x458a
movq 0x28(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x18(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
movl $0x1, %esi
movsd (%rcx), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
addq $0x3, %rsi
addq $0x8, %rcx
cmpq %r14, %rsi
jl 0x4574
testl %r12d, %r12d
jle 0x45bc
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x18(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
movl $0x2, %esi
movsd (%rcx), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
addq $0x3, %rsi
addq $0x8, %rcx
cmpq %r14, %rsi
jl 0x45a6
incq %rax
cmpq 0x8(%rsp), %rax
jne 0x4529
testl %ebp, %ebp
jle 0x4635
movl 0x20(%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movsd 0xa4d(%rip), %xmm1      # 0x5038
movabsq $0x406fe00000000000, %rdx # imm = 0x406FE00000000000
testl %r12d, %r12d
jle 0x462b
movq 0x18(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
xorl %edi, %edi
ucomisd (%rsi,%rdi,8), %xmm0
jbe 0x4614
movq $0x0, (%rsi,%rdi,8)
movsd (%rsi,%rdi,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x4623
movq %rdx, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x4605
incq %rcx
cmpq 0x8(%rsp), %rcx
jne 0x45f5
testl %ebp, %ebp
jle 0x4679
movl 0x20(%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
testl %r12d, %r12d
jle 0x466f
movq 0x18(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
xorl %esi, %esi
cvttsd2si (%rdx,%rsi,8), %edi
movq (%r15,%rcx,8), %r8
movb %dil, (%r8,%rsi)
incq %rsi
cmpq %rsi, %rax
jne 0x465a
incq %rcx
cmpq 0x8(%rsp), %rcx
jne 0x464a
leaq 0x90(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0x4a22
leaq 0xabc(%rip), %rsi       # 0x5168
leaq 0x80(%rsp), %rdi
callq 0x2230
leaq 0x80(%rsp), %r9
movq %r15, %rdi
movl %ebp, %esi
movl 0x20(%rsp), %edx
movq 0x40(%rsp), %rcx
movq 0x70(%rsp), %r8
callq 0x3940
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x46f6
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2140
leaq 0x60(%rsp), %rdi
movl %ebp, %esi
movq 0x78(%rsp), %r12
movl %r12d, %ecx
callq 0x389c
leaq 0x58(%rsp), %rdi
movl %ebp, %esi
movl %r12d, %ecx
callq 0x389c
leaq 0x50(%rsp), %rdi
movl %ebp, %esi
movl %r12d, %ecx
callq 0x389c
leaq 0xf0(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x4a22
leaq 0x24(%rsp), %rax
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0xc8(%rsp), %r9
movl %ebp, %ecx
pushq %r12
pushq 0x50(%rsp)
pushq %rbx
pushq %rax
callq 0x3a30
addq $0x20, %rsp
movq 0xe0(%rsp), %rdi
cmpq %r14, %rdi
je 0x47a3
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x2140
movl $0x1, %esi
movq 0x40(%rsp), %rdi
callq 0x2140
testl %ebp, %ebp
movq 0x38(%rsp), %r14
movq 0x28(%rsp), %rax
jle 0x4831
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
testq %rdi, %rdi
je 0x47da
movl $0x1, %esi
callq 0x2140
movq 0x28(%rsp), %rax
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x47f2
movl $0x8, %esi
callq 0x2140
movq 0x28(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x480a
movl $0x8, %esi
callq 0x2140
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx,%rbx,8), %rdi
testq %rdi, %rdi
je 0x4827
movl $0x8, %esi
callq 0x2140
movq 0x28(%rsp), %rax
incq %rbx
cmpq %rbx, 0x8(%rsp)
jne 0x47c2
movl $0x8, %esi
movq %r15, %rdi
movq %rax, %rbx
callq 0x2140
movl $0x8, %esi
movq %r14, %rdi
callq 0x2140
movl $0x8, %esi
movq %rbx, %rdi
callq 0x2140
movl $0x8, %esi
movq 0x30(%rsp), %rdi
callq 0x2140
xorl %ebp, %ebp
jmp 0x48b9
movq 0x2763(%rip), %rbx      # 0x6fd8
leaq 0x8a0(%rip), %rsi       # 0x511c
movl $0x4b, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x2731(%rip), %rdi      # 0x6fd8
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x20c0
leaq 0x100(%rsp), %rdi
callq 0x2070
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x48e7
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2140
movl %ebp, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
cmpq %r14, %rdi
je 0x4957
movq 0xf0(%rsp), %rsi
jmp 0x4931
jmp 0x4954
jmp 0x4919
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x4957
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2140
jmp 0x4957
jmp 0x4954
jmp 0x4954
jmp 0x4954
jmp 0x4954
jmp 0x4954
jmp 0x4954
movq %rax, %rbx
jmp 0x4964
jmp 0x4954
jmp 0x4954
jmp 0x4954
jmp 0x4954
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x2070
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4985
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2210
nop