// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b80
movq 0x349d(%rip), %rbx      # 0x5fd8
leaq 0x15cb(%rip), %rsi      # 0x410d
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 0x3a09
movq 0x8(%rsi), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x3a98
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), %r14
movl $0x4, %edx
movq %r14, %rsi
callq 0x2150
xorl %ebx, %ebx
xorl %ebp, %ebp
movzbl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %rbx
incq %r14
cmpq $0x20, %rbx
jne 0x2bf5
movl %ebp, 0x44(%rsp)
leaq 0xe0(%rsp), %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x2170
leaq 0xe0(%rsp), %rdi
leaq 0xb8(%rsp), %r14
movl $0x4, %edx
movq %r14, %rsi
callq 0x2150
xorl %ebx, %ebx
xorl %ebp, %ebp
movzbl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %rbx
incq %r14
cmpq $0x20, %rbx
jne 0x2c6d
leal (,%rbp,8), %eax
leal (%rax,%rax,2), %ecx
addl $0x1f, %ecx
leal (%rax,%rax,2), %r13d
addl $0x3e, %r13d
testl %ecx, %ecx
cmovnsl %ecx, %r13d
leaq 0xe0(%rsp), %rdi
leaq 0xb4(%rsp), %r12
movl $0x4, %edx
movq %r12, %rsi
callq 0x2150
sarl $0x5, %r13d
shll $0x2, %r13d
movslq %r13d, %r15
imulq $0x55555556, %r15, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
movq %rcx, 0x20(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movzbl (%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14d
addq $0x8, %rbx
incq %r12
cmpq $0x20, %rbx
jne 0x2d0d
movl %r14d, 0xc(%rsp)
leaq 0xe0(%rsp), %rdi
movl $0x1c, %esi
xorl %edx, %edx
callq 0x2170
leaq 0xe0(%rsp), %rdi
leaq 0x2e(%rsp), %rbx
movl $0x2, %edx
movq %rbx, %rsi
callq 0x2150
movl %r13d, 0x6c(%rsp)
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
movb $0x1, %r12b
leaq 0x2f(%rsp), %r14
movzbl (%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x10(%rsp)
callq 0x2100
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13d
movq %r14, %rbx
movsd 0x132b(%rip), %xmm0     # 0x40f8
testb $0x1, %r12b
movl $0x0, %r12d
jne 0x2d96
cmpl $0x18, %r13d
movl 0xc(%rsp), %ebx
jne 0x3723
movslq 0x44(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x2030
movq %rax, 0x60(%rsp)
movslq %ebx, %rax
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %r12
cmovnsq %rcx, %r12
movq %r12, %rdi
callq 0x2030
movq %rax, 0x48(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x30(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x58(%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, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x78(%rsp)
testl %ebx, %ebx
jle 0x2efd
leaq (,%r15,8), %r14
movslq 0x20(%rsp), %r13
shlq $0x3, %r13
cmpl $-0x2, %ebp
movq $-0x1, %rax
cmovlq %rax, %r14
cmovlq %rax, %r13
movl 0xc(%rsp), %r12d
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x2030
movq 0x48(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r14, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r13, %rdi
callq 0x2030
movq 0x58(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r13, %rdi
callq 0x2030
movq 0x50(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r13, %rdi
callq 0x2030
movq 0x38(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, %r12
jne 0x2ea0
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2170
movl 0xc(%rsp), %r14d
leaq 0xe0(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x2150
leaq 0xe0(%rsp), %rdi
leaq 0xa(%rsp), %rsi
movl $0x1, %edx
callq 0x2150
leaq 0xa(%rsp), %rsi
movzbl (%rsi), %r12d
leaq 0xe0(%rsp), %rdi
movl $0x1, %edx
callq 0x2150
testl %r14d, %r14d
je 0x367d
leaq 0xa(%rsp), %rax
movzbl (%rax), %eax
movl %eax, 0x10(%rsp)
xorl %r13d, %r13d
leaq 0xe0(%rsp), %r14
xorl %ebx, %ebx
movl $0x1, %edx
movq %r14, %rdi
leaq 0xa(%rsp), %rsi
callq 0x2150
movl $0x1, %edx
movq %r14, %rdi
leaq 0xb(%rsp), %rsi
callq 0x2150
movzbl 0xa(%rsp), %eax
testl %eax, %eax
je 0x2fea
movsbl 0xb(%rsp), %ecx
imull 0x10(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movslq %ebx, %rcx
movq 0x58(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %r13d, %r13
movsd %xmm0, (%rcx,%r13,8)
incl %r13d
cmpl 0x20(%rsp), %r13d
jne 0x2fe6
incl %ebx
xorl %r13d, %r13d
cmpl 0xc(%rsp), %ebx
je 0x2ff0
decl %eax
jne 0x2fbc
cmpl 0xc(%rsp), %ebx
jne 0x2f7e
movl 0xc(%rsp), %r14d
testl %r14d, %r14d
je 0x367d
xorl %r13d, %r13d
leaq 0xe0(%rsp), %r14
xorl %ebx, %ebx
movl $0x1, %edx
movq %r14, %rdi
leaq 0xa(%rsp), %rsi
callq 0x2150
movl $0x1, %edx
movq %r14, %rdi
leaq 0xb(%rsp), %rsi
callq 0x2150
movzbl 0xa(%rsp), %eax
testl %eax, %eax
je 0x3077
movsbl 0xb(%rsp), %ecx
imull 0x10(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movslq %ebx, %rcx
movq 0x50(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %r13d, %r13
movsd %xmm0, (%rcx,%r13,8)
incl %r13d
cmpl 0x20(%rsp), %r13d
jne 0x3073
incl %ebx
xorl %r13d, %r13d
cmpl 0xc(%rsp), %ebx
je 0x307d
decl %eax
jne 0x3049
cmpl 0xc(%rsp), %ebx
jne 0x300b
movl 0xc(%rsp), %r14d
testl %r14d, %r14d
je 0x367d
xorl %r13d, %r13d
leaq 0xe0(%rsp), %r14
xorl %ebx, %ebx
movl $0x1, %edx
movq %r14, %rdi
leaq 0xa(%rsp), %rsi
callq 0x2150
movl $0x1, %edx
movq %r14, %rdi
leaq 0xb(%rsp), %rsi
callq 0x2150
movzbl 0xa(%rsp), %eax
testl %eax, %eax
je 0x3104
movsbl 0xb(%rsp), %ecx
imull 0x10(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movslq %ebx, %rcx
movq 0x38(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %r13d, %r13
movsd %xmm0, (%rcx,%r13,8)
incl %r13d
cmpl 0x20(%rsp), %r13d
jne 0x3100
incl %ebx
xorl %r13d, %r13d
cmpl 0xc(%rsp), %ebx
je 0x310a
decl %eax
jne 0x30d6
cmpl 0xc(%rsp), %ebx
jne 0x3098
movl 0xc(%rsp), %r14d
testl %r14d, %r14d
jle 0x367d
movq 0x20(%rsp), %rax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movl %r14d, %eax
leaq -0x1(%rcx), %rdx
addl $0xf, %ecx
andl $-0x10, %ecx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa %xmm0, 0x10(%rsp)
xorl %edx, %edx
movdqa 0xf80(%rip), %xmm9      # 0x40d0
pcmpeqd %xmm10, %xmm10
testl %ebp, %ebp
jle 0x3671
movq 0x48(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
xorl %edi, %edi
movdqa 0xf4f(%rip), %xmm12     # 0x40c0
movdqa 0xf36(%rip), %xmm13     # 0x40b0
movdqa 0xf1d(%rip), %xmm14     # 0x40a0
movdqa 0xf04(%rip), %xmm15     # 0x4090
movdqa 0xeec(%rip), %xmm4      # 0x4080
movdqa 0xed4(%rip), %xmm3      # 0x4070
movdqa 0xebc(%rip), %xmm2      # 0x4060
movdqa 0xea4(%rip), %xmm1      # 0x4050
movdqa 0x10(%rsp), %xmm0
pxor %xmm9, %xmm0
movdqa %xmm12, %xmm6
pxor %xmm9, %xmm6
movdqa %xmm6, %xmm8
pcmpgtd %xmm0, %xmm8
pshufd $0xa0, %xmm8, %xmm7     # xmm7 = xmm8[0,0,2,2]
pshuflw $0xe8, %xmm7, %xmm5     # xmm5 = xmm7[0,2,2,3,4,5,6,7]
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pshuflw $0xe8, %xmm6, %xmm11    # xmm11 = xmm6[0,2,2,3,4,5,6,7]
pand %xmm5, %xmm11
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm5     # xmm5 = xmm8[0,2,2,3,4,5,6,7]
por %xmm11, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
movd %xmm5, %r8d
testb $0x1, %r8b
je 0x3213
movb $0x0, (%rsi,%rdi)
pand %xmm7, %xmm6
por %xmm8, %xmm6
packssdw %xmm6, %xmm6
pxor %xmm10, %xmm6
packssdw %xmm6, %xmm6
packsswb %xmm6, %xmm6
movd %xmm6, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0x3241
movb $0x0, 0x1(%rsi,%rdi)
movdqa %xmm13, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm8
pcmpgtd %xmm0, %xmm8
pshufd $0xa0, %xmm8, %xmm6     # xmm6 = xmm8[0,0,2,2]
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
movdqa %xmm7, %xmm5
pand %xmm6, %xmm5
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
por %xmm8, %xmm5
packssdw %xmm5, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
packsswb %xmm5, %xmm5
movd %xmm5, %r8d
shrl $0x10, %r8d
testb $0x1, %r8b
je 0x329c
movb $0x0, 0x2(%rsi,%rdi)
pshufhw $0x84, %xmm6, %xmm5     # xmm5 = xmm6[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm7, %xmm6     # xmm6 = xmm7[0,1,2,3,4,5,4,6]
pand %xmm5, %xmm6
pshufhw $0x84, %xmm8, %xmm5     # xmm5 = xmm8[0,1,2,3,4,5,4,6]
por %xmm6, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
packsswb %xmm5, %xmm5
movd %xmm5, %r8d
shrl $0x18, %r8d
testb $0x1, %r8b
je 0x32d5
movb $0x0, 0x3(%rsi,%rdi)
movdqa %xmm14, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm8
pcmpgtd %xmm0, %xmm8
pshufd $0xa0, %xmm8, %xmm7     # xmm7 = xmm8[0,0,2,2]
pshuflw $0xe8, %xmm7, %xmm11    # xmm11 = xmm7[0,2,2,3,4,5,6,7]
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm6     # xmm6 = xmm5[1,1,3,3]
pshuflw $0xe8, %xmm6, %xmm5     # xmm5 = xmm6[0,2,2,3,4,5,6,7]
pand %xmm11, %xmm5
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm11    # xmm11 = xmm8[0,2,2,3,4,5,6,7]
por %xmm5, %xmm11
pxor %xmm10, %xmm11
packssdw %xmm11, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x2, %xmm5, %r8d
testb $0x1, %r8b
je 0x3338
movb $0x0, 0x4(%rsi,%rdi)
pand %xmm7, %xmm6
por %xmm8, %xmm6
packssdw %xmm6, %xmm6
pxor %xmm10, %xmm6
packssdw %xmm6, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x2, %xmm5, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0x3367
movb $0x0, 0x5(%rsi,%rdi)
movdqa %xmm15, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm8
pcmpgtd %xmm0, %xmm8
pshufd $0xa0, %xmm8, %xmm6     # xmm6 = xmm8[0,0,2,2]
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
movdqa %xmm7, %xmm5
pand %xmm6, %xmm5
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
por %xmm8, %xmm5
packssdw %xmm5, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x3, %xmm5, %r8d
testb $0x1, %r8b
je 0x33bf
movb $0x0, 0x6(%rsi,%rdi)
pshufhw $0x84, %xmm6, %xmm5     # xmm5 = xmm6[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm7, %xmm6     # xmm6 = xmm7[0,1,2,3,4,5,4,6]
pand %xmm5, %xmm6
pshufhw $0x84, %xmm8, %xmm5     # xmm5 = xmm8[0,1,2,3,4,5,4,6]
por %xmm6, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x3, %xmm5, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0x33f9
movb $0x0, 0x7(%rsi,%rdi)
movdqa %xmm4, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm8
pcmpgtd %xmm0, %xmm8
pshufd $0xa0, %xmm8, %xmm7     # xmm7 = xmm8[0,0,2,2]
pshuflw $0xe8, %xmm7, %xmm11    # xmm11 = xmm7[0,2,2,3,4,5,6,7]
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm6     # xmm6 = xmm5[1,1,3,3]
pshuflw $0xe8, %xmm6, %xmm5     # xmm5 = xmm6[0,2,2,3,4,5,6,7]
pand %xmm11, %xmm5
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm11    # xmm11 = xmm8[0,2,2,3,4,5,6,7]
por %xmm5, %xmm11
pxor %xmm10, %xmm11
packssdw %xmm11, %xmm11
packsswb %xmm11, %xmm5
pextrw $0x4, %xmm5, %r8d
testb $0x1, %r8b
je 0x345c
movb $0x0, 0x8(%rsi,%rdi)
pand %xmm7, %xmm6
por %xmm8, %xmm6
packssdw %xmm6, %xmm6
pxor %xmm10, %xmm6
packssdw %xmm6, %xmm6
packsswb %xmm6, %xmm5
pextrw $0x4, %xmm5, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0x348b
movb $0x0, 0x9(%rsi,%rdi)
movdqa %xmm3, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm8
pcmpgtd %xmm0, %xmm8
pshufd $0xa0, %xmm8, %xmm6     # xmm6 = xmm8[0,0,2,2]
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
movdqa %xmm7, %xmm5
pand %xmm6, %xmm5
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
por %xmm8, %xmm5
packssdw %xmm5, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x5, %xmm5, %r8d
testb $0x1, %r8b
je 0x34e2
movb $0x0, 0xa(%rsi,%rdi)
pshufhw $0x84, %xmm6, %xmm5     # xmm5 = xmm6[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm7, %xmm6     # xmm6 = xmm7[0,1,2,3,4,5,4,6]
pand %xmm5, %xmm6
pshufhw $0x84, %xmm8, %xmm5     # xmm5 = xmm8[0,1,2,3,4,5,4,6]
por %xmm6, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x5, %xmm5, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0x351c
movb $0x0, 0xb(%rsi,%rdi)
movdqa %xmm2, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm8
pcmpgtd %xmm0, %xmm8
pshufd $0xa0, %xmm8, %xmm7     # xmm7 = xmm8[0,0,2,2]
pshuflw $0xe8, %xmm7, %xmm11    # xmm11 = xmm7[0,2,2,3,4,5,6,7]
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm6     # xmm6 = xmm5[1,1,3,3]
pshuflw $0xe8, %xmm6, %xmm5     # xmm5 = xmm6[0,2,2,3,4,5,6,7]
pand %xmm11, %xmm5
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm11    # xmm11 = xmm8[0,2,2,3,4,5,6,7]
por %xmm5, %xmm11
pxor %xmm10, %xmm11
packssdw %xmm11, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x6, %xmm5, %r8d
testb $0x1, %r8b
je 0x357e
movb $0x0, 0xc(%rsi,%rdi)
pand %xmm7, %xmm6
por %xmm8, %xmm6
packssdw %xmm6, %xmm6
pxor %xmm10, %xmm6
packssdw %xmm6, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x6, %xmm5, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0x35ad
movb $0x0, 0xd(%rsi,%rdi)
movdqa %xmm1, %xmm5
pxor %xmm9, %xmm5
movdqa %xmm5, %xmm7
pcmpgtd %xmm0, %xmm7
pshufd $0xa0, %xmm7, %xmm6     # xmm6 = xmm7[0,0,2,2]
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm0     # xmm0 = xmm5[1,1,3,3]
movdqa %xmm0, %xmm5
pand %xmm6, %xmm5
pshufd $0xf5, %xmm7, %xmm7     # xmm7 = xmm7[1,1,3,3]
por %xmm7, %xmm5
packssdw %xmm5, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm5
packsswb %xmm5, %xmm5
pextrw $0x7, %xmm5, %r8d
testb $0x1, %r8b
je 0x35ff
movb $0x0, 0xe(%rsi,%rdi)
pshufhw $0x84, %xmm6, %xmm5     # xmm5 = xmm6[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm0, %xmm0     # xmm0 = xmm0[0,1,2,3,4,5,4,6]
pand %xmm5, %xmm0
pshufhw $0x84, %xmm7, %xmm5     # xmm5 = xmm7[0,1,2,3,4,5,4,6]
por %xmm0, %xmm5
pxor %xmm10, %xmm5
packssdw %xmm5, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x7, %xmm0, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0x3638
movb $0x0, 0xf(%rsi,%rdi)
addq $0x10, %rdi
movdqa 0xa9c(%rip), %xmm0      # 0x40e0
paddq %xmm0, %xmm12
paddq %xmm0, %xmm13
paddq %xmm0, %xmm14
paddq %xmm0, %xmm15
paddq %xmm0, %xmm4
paddq %xmm0, %xmm3
paddq %xmm0, %xmm2
paddq %xmm0, %xmm1
cmpq %rdi, %rcx
jne 0x31ac
incq %rdx
cmpq %rax, %rdx
jne 0x3155
leaq 0xe0(%rsp), %rdi
callq 0x2060
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x70(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
testl %r12d, %r12d
jle 0x3773
decl %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x2100
movsd 0x70(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebx
movsd 0x10(%rsp), %xmm0
callq 0x2100
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r13d
leaq 0x88(%rsp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x2544
leaq 0x80(%rsp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x2544
leaq 0x78(%rsp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x2544
jmp 0x36a7
movq 0x28ae(%rip), %rbx      # 0x5fd8
leaq 0xa11(%rip), %rsi       # 0x4142
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 0x287c(%rip), %rdi      # 0x5fd8
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x20b0
jmp 0x39db
testl %r14d, %r14d
movl 0x44(%rsp), %ebx
movl 0x6c(%rsp), %r12d
jle 0x38ce
movl %r14d, %eax
xorl %ecx, %ecx
testl %ebp, %ebp
jle 0x381e
movq 0x58(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x30(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
xorl %edi, %edi
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
addq $0x3, %rdi
addq $0x8, %rdx
cmpq %r15, %rdi
jl 0x37a6
testl %ebp, %ebp
jle 0x381e
movq 0x50(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x30(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
movl $0x1, %edi
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
addq $0x3, %rdi
addq $0x8, %rdx
cmpq %r15, %rdi
jl 0x37d7
testl %ebp, %ebp
jle 0x381e
movq 0x38(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x30(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
movl $0x2, %edi
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
addq $0x3, %rdi
addq $0x8, %rdx
cmpq %r15, %rdi
jl 0x3808
incq %rcx
cmpq %rax, %rcx
jne 0x378a
testl %r14d, %r14d
jle 0x38ce
cmpl $0x2, %r12d
movl $0x1, %ecx
cmovgel %r12d, %ecx
xorl %edx, %edx
movsd 0x8b6(%rip), %xmm0      # 0x4100
testl %ebp, %ebp
jle 0x387f
movq 0x30(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
xorl %edi, %edi
movsd (%rsi,%rdi,8), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
ja 0x3872
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x3877
movsd %xmm1, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x3859
incq %rdx
cmpq %rax, %rdx
jne 0x384a
testl %r14d, %r14d
jle 0x38ce
cmpl $0x2, %r12d
movl $0x1, %ecx
cmovgel %r12d, %ecx
xorl %edx, %edx
testl %ebp, %ebp
jle 0x38c6
movq 0x30(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
movq 0x48(%rsp), %rdi
movq (%rdi,%rdx,8), %rdi
xorl %r8d, %r8d
cvttsd2si (%rsi,%r8,8), %r9d
movb %r9b, (%rdi,%r8)
incq %r8
cmpq %r8, %rcx
jne 0x38b4
incq %rdx
cmpq %rax, %rdx
jne 0x389b
leaq 0xd0(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x3ad6
leaq 0xc0(%rsp), %r9
movq 0x48(%rsp), %r13
movq %r13, %rdi
movl %r14d, %esi
movl %r12d, %edx
movq 0x60(%rsp), %rcx
movl %ebx, %r8d
callq 0x2a2e
movq 0x50(%rsp), %r12
movq 0x38(%rsp), %rbp
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x3944
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2120
movl $0x1, %esi
movq 0x60(%rsp), %rdi
callq 0x2120
testl %r14d, %r14d
movq 0x58(%rsp), %r15
jle 0x39a5
movl %r14d, %ebx
xorl %r14d, %r14d
movq (%r13,%r14,8), %rdi
movl $0x1, %esi
callq 0x2120
movq (%r15,%r14,8), %rdi
movl $0x8, %esi
callq 0x2120
movq (%r12,%r14,8), %rdi
movl $0x8, %esi
callq 0x2120
movq (%rbp,%r14,8), %rdi
movl $0x8, %esi
callq 0x2120
incq %r14
cmpq %r14, %rbx
jne 0x3963
movl $0x8, %esi
movq %r13, %rdi
callq 0x2120
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movl $0x8, %esi
movq %r12, %rdi
callq 0x2120
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2120
xorl %ebx, %ebx
leaq 0xe0(%rsp), %rdi
callq 0x2070
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a09
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 %r15, %rdi
je 0x3a61
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2120
jmp 0x3a61
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
movq %rax, %rbx
jmp 0x3a6e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
jmp 0x3a5e
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2070
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a8f
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21c0
nop