// File: /workspace/github_cpp_makefile_star2_O1/kchan1[P]helloworld_test1/main2.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;
	}

	//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];
	unsigned char num_decomps_data;
	
	//secondary buffers for interpretting the header
	int bitmap_offset=0;
	int width =0;
	int image_width = 0;
	int height =0;
	int pixel_bits=0;
	int num_decomps=0;
	char char_reader[1];
	unsigned char uchar_reader[1];
	int total_char;
	int limit_char;
	int quant = 20;
	
	//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);
	}
	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];
	//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];
		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 number of Decompisition Loops:
	image_file.read(reinterpret_cast<char*>(uchar_reader),1);
	num_decomps=(int)uchar_reader[0];
	//cout<<num_decomps<<endl;
	
	image_file.read(reinterpret_cast<char*>(uchar_reader),1);
	quant=(int)uchar_reader[0];
	//cout<<num_decomps<<endl;

	//image_file.seekg(-2, std::ifstream::cur);
	total_char = 0;
	limit_char = width*height;
	int tempi = 0;
	int tempj = 0;
	//int cout_count = 0;

	while(tempi!=height){
		image_file.read(reinterpret_cast<char*>(uchar_reader),1);
		image_file.read(reinterpret_cast<char*>(char_reader),1);
		//if(cout_count <49927){
		//cout<<(int)uchar_reader[0]<<" "<<(int)char_reader[0]<<endl;
		//cout_count++;
		//cout<<cout_count<<endl;
		//}
		for(int k = 0; k<(int)uchar_reader[0]; k++){
			//cout<<"Trying to read..."<<endl;
			blue_data[tempi][tempj] = char_reader[0]*quant;
			total_char++;
			tempj++;
			if(tempj == width){
				tempj = 0;
				tempi++;
				if(tempi == height){
					break;
				}	
			}
			//cout<<tempi<<" "<<tempj<<endl;
		}
				
	}	
	//image_file.seekg(-2, std::ifstream::cur);
	total_char = 0;
	limit_char = width*height;
	tempi = 0;
	tempj = 0;

	while(tempi!=height){
		image_file.read(reinterpret_cast<char*>(uchar_reader),1);
		image_file.read(reinterpret_cast<char*>(char_reader),1);
		//cout<<(int)uchar_reader[0]<<" "<<(int)char_reader[0]<<endl;
		for(int k = 0; k<(int)uchar_reader[0]; k++){
			//cout<<"Trying to read..."<<endl;
			green_data[tempi][tempj] = char_reader[0]*quant;
			total_char++;
			tempj++;
			if(tempj == width){
				tempj = 0;
				tempi++;
				if(tempi == height){
					break;
				}	
			}
			//cout<<tempi<<" "<<tempj<<endl;
		}
				
	}	

	//image_file.seekg(-2, std::ifstream::cur);
	total_char = 0;
	limit_char = width*height;
	tempi = 0;
	tempj = 0;

	while(tempi!=height){
		image_file.read(reinterpret_cast<char*>(uchar_reader),1);
		image_file.read(reinterpret_cast<char*>(char_reader),1);
		//cout<<(int)uchar_reader[0]<<" "<<(int)char_reader[0]<<endl;
		for(int k = 0; k<(int)uchar_reader[0]; k++){
			//cout<<"Trying to read..."<<endl;
			red_data[tempi][tempj] = char_reader[0]*quant;
			//red_data[tempi][tempj] = 0;			
			total_char++;
			tempj++;
			if(tempj == width){
				tempj = 0;
				tempi++;
				if(tempi == height){
					break;
				}	
			}
			//cout<<tempi<<" "<<tempj<<endl;
		}
				
	}	

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

	//read in the raw image data
	//Read in the data from the zero-tree things.
	//reconstruct the zero tree into a matrix of values.

	


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

//	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<width*3; 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<width*3; j+=3){
			blue_data[i][j/3] = image_data[i][j];
		}
		for(int j = 1; j<width*3; j+=3){
			green_data[i][j/3] = image_data[i][j];
		}
		for(int j=2;j<width*3; j+=3){
			red_data[i][j/3] = image_data[i][j];
		}
	}*/

	for (int i = 0; i<height; i++){
		for(int j = 0; j<width; j++){
			imageData[i][j]=(unsigned char)0;
		}
	}


	//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:

 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 Recomposition
 *========================================================================
 */
	int recomp_height= height;
	int recomp_width = width;

	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,filename);


//	reconstruct((imageData),height,width*3,image_header_data,bitmap_offset,filename);


/*
 *	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 $0x2e8, %rsp            # imm = 0x2E8
cmpl $0x1, %edi
jne 0x2b2b
movq 0x34f2(%rip), %rbx      # 0x5fd8
leaq 0x1538(%rip), %rsi      # 0x4025
movl $0x34, %edx
movq %rbx, %rdi
callq 0x2140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20b0
movl $0x1, %ebx
jmp 0x3472
movq 0x8(%rsi), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x3500
leaq 0xe0(%rsp), %rdi
callq 0x2130
movq 0x90(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
movl $0xc, %edx
callq 0x20a0
leaq 0xe0(%rsp), %rdi
movl $0xa, %esi
xorl %edx, %edx
callq 0x2170
leaq 0xe0(%rsp), %rdi
leaq 0xbc(%rsp), %rbx
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2150
xorl %r14d, %r14d
xorl %ebp, %ebp
movzbl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %r14
incq %rbx
cmpq $0x20, %r14
jne 0x2ba1
movl %ebp, 0x44(%rsp)
leaq 0xe0(%rsp), %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x2170
leaq 0xe0(%rsp), %rdi
leaq 0xb8(%rsp), %rbx
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2150
xorl %r14d, %r14d
xorl %r15d, %r15d
movzbl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r15d
addq $0x8, %r14
incq %rbx
cmpq $0x20, %r14
jne 0x2c1b
movq %r15, 0x18(%rsp)
leal (,%r15,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 0xe0(%rsp), %rdi
leaq 0xb4(%rsp), %r15
movl $0x4, %edx
movq %r15, %rsi
callq 0x2150
sarl $0x5, %ebp
shll $0x2, %ebp
movslq %ebp, %rbx
imulq $0x55555556, %rbx, %r13 # imm = 0x55555556
movq %r13, %rax
shrq $0x3f, %rax
shrq $0x20, %r13
addl %eax, %r13d
xorl %r12d, %r12d
xorl %r14d, %r14d
movzbl (%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14d
addq $0x8, %r12
incq %r15
cmpq $0x20, %r12
jne 0x2cbb
leaq 0xe0(%rsp), %rdi
movl $0x1c, %esi
xorl %edx, %edx
callq 0x2170
leaq 0xe0(%rsp), %rdi
leaq 0x76(%rsp), %r15
movl $0x2, %edx
movq %r15, %rsi
callq 0x2150
movl %ebp, 0x70(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movzbl (%r15), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %r12
incq %r15
cmpq $0x8, %r12
je 0x2d34
cmpl $0x18, %ebp
jne 0x3178
movslq 0x44(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x2030
movq %rax, 0x58(%rsp)
movslq %r14d, %rax
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %r12
cmovnsq %rcx, %r12
movq %r12, %rdi
callq 0x2030
movq %rax, %r15
movq %r12, %rdi
callq 0x2030
movq %rax, 0x20(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x68(%rsp)
movq %rax, 0x88(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x50(%rsp)
movq %rax, 0x80(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x78(%rsp)
movl %r14d, %eax
movq %rax, 0x28(%rsp)
testl %r14d, %r14d
jle 0x2e99
leaq (,%rbx,8), %rcx
movslq %r13d, %r12
shlq $0x3, %r12
cmpl $-0x2, 0x18(%rsp)
movq $-0x1, %rax
cmovlq %rax, %rcx
movq %rcx, 0x30(%rsp)
cmovlq %rax, %r12
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x2030
movq %rax, (%r15,%rbp,8)
movq 0x30(%rsp), %rdi
callq 0x2030
movq 0x20(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq %r12, %rdi
callq 0x2030
movq 0x68(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq %r12, %rdi
callq 0x2030
movq 0x50(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
movq %r12, %rdi
callq 0x2030
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
cmpq %rbp, 0x28(%rsp)
jne 0x2e3d
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2170
leaq 0xe0(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x2150
leaq 0xe0(%rsp), %rdi
leaq 0xe(%rsp), %rsi
movl $0x1, %edx
callq 0x2150
leaq 0xe(%rsp), %rsi
movzbl (%rsi), %eax
movl %eax, 0x48(%rsp)
leaq 0xe0(%rsp), %rdi
movl $0x1, %edx
callq 0x2150
movl %r14d, 0x30(%rsp)
testl %r14d, %r14d
je 0x308e
movq %r15, 0x60(%rsp)
leaq 0xe(%rsp), %rax
movzbl (%rax), %eax
movl %eax, 0x38(%rsp)
xorl %ebp, %ebp
leaq 0xe0(%rsp), %r15
xorl %r12d, %r12d
movl 0x30(%rsp), %r14d
movl $0x1, %edx
movq %r15, %rdi
leaq 0xe(%rsp), %rsi
callq 0x2150
movl $0x1, %edx
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2150
movzbl 0xe(%rsp), %eax
testl %eax, %eax
je 0x2f8e
movsbl 0xf(%rsp), %ecx
imull 0x38(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movslq %r12d, %rcx
movq 0x68(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %ebp, %rbp
movsd %xmm0, (%rcx,%rbp,8)
incl %ebp
cmpl %r13d, %ebp
jne 0x2f8a
incl %r12d
xorl %ebp, %ebp
cmpl %r14d, %r12d
je 0x2f8e
decl %eax
jne 0x2f65
cmpl %r14d, %r12d
jne 0x2f27
xorl %ebp, %ebp
leaq 0xe0(%rsp), %r15
xorl %r12d, %r12d
movl $0x1, %edx
movq %r15, %rdi
leaq 0xe(%rsp), %rsi
callq 0x2150
movl $0x1, %edx
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2150
movzbl 0xe(%rsp), %eax
testl %eax, %eax
je 0x3007
movsbl 0xf(%rsp), %ecx
imull 0x38(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movslq %r12d, %rcx
movq 0x50(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %ebp, %rbp
movsd %xmm0, (%rcx,%rbp,8)
incl %ebp
cmpl %r13d, %ebp
jne 0x3003
incl %r12d
xorl %ebp, %ebp
cmpl %r14d, %r12d
je 0x3007
decl %eax
jne 0x2fde
cmpl %r14d, %r12d
jne 0x2fa0
xorl %ebp, %ebp
leaq 0xe0(%rsp), %r14
xorl %r12d, %r12d
movq 0x60(%rsp), %r15
movl $0x1, %edx
movq %r14, %rdi
leaq 0xe(%rsp), %rsi
callq 0x2150
movl $0x1, %edx
movq %r14, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2150
movzbl 0xe(%rsp), %eax
testl %eax, %eax
je 0x3087
movsbl 0xf(%rsp), %ecx
imull 0x38(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movslq %r12d, %rcx
movq 0x10(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %ebp, %rbp
movsd %xmm0, (%rcx,%rbp,8)
incl %ebp
cmpl %r13d, %ebp
jne 0x3083
incl %r12d
xorl %ebp, %ebp
cmpl 0x30(%rsp), %r12d
je 0x3087
decl %eax
jne 0x305c
cmpl 0x30(%rsp), %r12d
jne 0x301e
movl 0x30(%rsp), %r14d
testl %r14d, %r14d
jle 0x30ca
cmpl $0x2, %r13d
movl $0x1, %eax
cmovgel %r13d, %eax
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rsp)
jle 0x30c0
xorl %edx, %edx
movq (%r15,%rcx,8), %rsi
movb $0x0, (%rsi,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0x30b0
incq %rcx
cmpq 0x28(%rsp), %rcx
jne 0x30a7
leaq 0xe0(%rsp), %rdi
callq 0x2060
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x88(%rsp), %r12
movl 0x48(%rsp), %ebp
testl %ebp, %ebp
jle 0x31c8
decl %ebp
movsd 0xf07(%rip), %xmm0      # 0x4018
movl %ebp, %edi
callq 0x21a0
movsd 0x38(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r13d
movsd 0xee9(%rip), %xmm0      # 0x4018
movl %ebp, 0x48(%rsp)
movl %ebp, %edi
callq 0x21a0
movsd 0x60(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebp
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x255a
leaq 0x80(%rsp), %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x255a
leaq 0x78(%rsp), %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x255a
jmp 0x30fb
movq 0x2e59(%rip), %rbx      # 0x5fd8
leaq 0xed4(%rip), %rsi       # 0x405a
movl $0x4b, %edx
movq %rbx, %rdi
callq 0x2140
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq 0x2e27(%rip), %rdi      # 0x5fd8
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x20b0
jmp 0x3444
testl %r14d, %r14d
movl 0x70(%rsp), %ebp
movq 0x68(%rsp), %r13
jle 0x327f
xorl %eax, %eax
cmpl $0x0, 0x18(%rsp)
jle 0x3209
movq (%r13,%rax,8), %rcx
movq 0x20(%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 %rbx, %rsi
jl 0x31f3
cmpl $0x0, 0x18(%rsp)
jle 0x323d
movq 0x50(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x20(%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 %rbx, %rsi
jl 0x3227
cmpl $0x0, 0x18(%rsp)
jle 0x3271
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x20(%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 %rbx, %rsi
jl 0x325b
incq %rax
cmpq 0x28(%rsp), %rax
jne 0x31dc
testl %r14d, %r14d
jle 0x32e9
cmpl $0x2, %ebp
movl $0x1, %eax
cmovgel %ebp, %eax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movsd 0xd73(%rip), %xmm1      # 0x4010
movabsq $0x406fe00000000000, %rdx # imm = 0x406FE00000000000
cmpl $0x0, 0x18(%rsp)
jle 0x32df
movq 0x20(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
xorl %edi, %edi
ucomisd (%rsi,%rdi,8), %xmm0
jbe 0x32c8
movq $0x0, (%rsi,%rdi,8)
movsd (%rsi,%rdi,8), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x32d7
movq %rdx, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x32b9
incq %rcx
cmpq 0x28(%rsp), %rcx
jne 0x32a7
testl %r14d, %r14d
jle 0x332c
cmpl $0x2, %ebp
movl $0x1, %eax
cmovgel %ebp, %eax
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rsp)
jle 0x3322
movq 0x20(%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 0x330d
incq %rcx
cmpq 0x28(%rsp), %rcx
jne 0x32fb
leaq 0xd0(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x353e
leaq 0xc0(%rsp), %r9
movq %r15, %rdi
movl %r14d, %esi
movl %ebp, %edx
movq 0x58(%rsp), %rcx
movl 0x44(%rsp), %r8d
callq 0x29d9
movq 0xc0(%rsp), %rdi
cmpq %r12, %rdi
je 0x3395
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2120
movl $0x1, %esi
movq 0x58(%rsp), %rdi
callq 0x2120
testl %r14d, %r14d
movq 0x50(%rsp), %r14
jle 0x340c
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
testq %rdi, %rdi
je 0x33c3
movl $0x1, %esi
callq 0x2120
movq (%r13,%rbx,8), %rdi
testq %rdi, %rdi
je 0x33d7
movl $0x8, %esi
callq 0x2120
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x33ea
movl $0x8, %esi
callq 0x2120
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x3402
movl $0x8, %esi
callq 0x2120
incq %rbx
cmpq %rbx, 0x28(%rsp)
jne 0x33b0
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movl $0x8, %esi
movq %r13, %rdi
callq 0x2120
movl $0x8, %esi
movq %r14, %rdi
callq 0x2120
movl $0x8, %esi
movq 0x10(%rsp), %rdi
callq 0x2120
xorl %ebx, %ebx
leaq 0xe0(%rsp), %rdi
callq 0x2070
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3472
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2120
movl %ebx, %eax
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
cmpq %r12, %rdi
je 0x34ca
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2120
jmp 0x34ca
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
movq %rax, %rbx
jmp 0x34d7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
jmp 0x34c7
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2070
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x34f8
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21d0