// File: /workspace/github_cpp_makefile_star2_O2/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 $0x2d8, %rsp            # imm = 0x2D8
cmpl $0x1, %edi
jne 0x29c9
movq 0x362b(%rip), %rdi      # 0x5fd8
leaq 0x16b1(%rip), %rsi      # 0x4065
callq 0x20f0
movq %rax, %rdi
callq 0x2090
pushq $0x1
popq %rbx
jmp 0x31c5
movq 0x8(%rsi), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
callq 0x3230
leaq 0xd0(%rsp), %rdi
callq 0x2110
movq 0x90(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x20a0
leaq 0xd0(%rsp), %rdi
pushq $0xa
popq %rsi
xorl %edx, %edx
callq 0x2140
leaq 0xd0(%rsp), %rdi
leaq 0x8c(%rsp), %rbx
pushq $0x4
popq %rdx
movq %rbx, %rsi
callq 0x2120
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq $0x20, %r14
je 0x2a74
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r14d, %xmm0
callq 0x20e0
cvtsi2sd %r12d, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12d
addq $0x8, %r14
incq %rbx
jmp 0x2a3a
leaq 0xd0(%rsp), %rdi
pushq $0x12
popq %rsi
xorl %edx, %edx
callq 0x2140
leaq 0xd0(%rsp), %rdi
leaq 0x88(%rsp), %rbx
pushq $0x4
popq %rdx
movq %rbx, %rsi
callq 0x2120
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq $0x20, %r14
je 0x2ae1
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r14d, %xmm0
callq 0x20e0
cvtsi2sd %r13d, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13d
addq $0x8, %r14
incq %rbx
jmp 0x2aa7
imull $0x18, %r13d, %eax
addl $0x1f, %eax
pushq $0x20
popq %rcx
cltd
idivl %ecx
shll $0x2, %eax
pushq $0x3
popq %rcx
movl %eax, 0x24(%rsp)
cltd
idivl %ecx
movl %eax, 0x10(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x84(%rsp), %rbx
pushq $0x4
popq %rdx
movq %rbx, %rsi
callq 0x2120
xorl %r15d, %r15d
xorl %eax, %eax
cvtsi2sd %eax, %xmm0
cmpq $0x20, %r15
movsd %xmm0, 0x60(%rsp)
je 0x2b5f
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x8(%rsp)
cvtsi2sd %r15d, %xmm0
callq 0x20e0
mulsd 0x8(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
cvttsd2si %xmm0, %eax
addq $0x8, %r15
incq %rbx
jmp 0x2b1f
movl %eax, 0x4(%rsp)
leaq 0xd0(%rsp), %rdi
pushq $0x1c
popq %rsi
xorl %edx, %edx
callq 0x2140
leaq 0xd0(%rsp), %rdi
leaq 0x56(%rsp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rsi
callq 0x2120
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq $0x10, %r15
je 0x2bca
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r15d, %xmm0
callq 0x20e0
cvtsi2sd %ebp, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %r15
incq %rbx
jmp 0x2b92
cmpl $0x18, %ebp
jne 0x2ce7
movl %r12d, 0x50(%rsp)
movslq %r12d, %rdi
movq %rdi, 0x18(%rsp)
callq 0x2030
movq %rax, 0x58(%rsp)
movslq 0x4(%rsp), %rax
leaq (,%rax,8), %r12
testl %eax, %eax
pushq $-0x1
popq %rbp
cmovsq %rbp, %r12
movq %r12, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, %rbx
movq %r12, %rdi
callq 0x2030
movq %rax, 0x48(%rsp)
movq %rax, 0x78(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x38(%rsp)
movq %rax, 0x70(%rsp)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x30(%rsp)
movslq 0x24(%rsp), %r12
leaq (,%r12,8), %r14
movslq 0x10(%rsp), %r15
shlq $0x3, %r15
cmpl $-0x2, %r13d
cmovlq %rbp, %r14
movq 0x30(%rsp), %rax
movq %rax, 0x68(%rsp)
cmovlq %rbp, %r15
xorl %r13d, %r13d
movl 0x4(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0x28(%rsp)
cmpq %r13, 0x28(%rsp)
je 0x2d0a
movq %r12, %rdi
callq 0x2030
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %r14, %rdi
callq 0x2030
movq %rax, (%rbx,%r13,8)
movq %r15, %rdi
callq 0x2030
movq 0x48(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %r15, %rdi
callq 0x2030
movq 0x38(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %r15, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
jmp 0x2c8b
movq 0x32ea(%rip), %rdi      # 0x5fd8
leaq 0x13a5(%rip), %rsi      # 0x409a
callq 0x20f0
movq %rax, %rdi
callq 0x2090
pushq $0x1
popq %rbx
jmp 0x31ab
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2140
leaq 0xd0(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x2120
leaq 0xd0(%rsp), %rdi
leaq 0x2(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2120
leaq 0x2(%rsp), %rsi
movzbl (%rsi), %eax
movl %eax, 0x44(%rsp)
leaq 0xd0(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x2120
leaq 0x2(%rsp), %rax
movzbl (%rax), %eax
movl %eax, 0x18(%rsp)
xorl %r13d, %r13d
leaq 0xd0(%rsp), %r15
pushq $0x1
popq %r14
xorl %ebp, %ebp
cmpl 0x4(%rsp), %r13d
je 0x2dee
movq %r15, %rdi
leaq 0x2(%rsp), %rsi
movq %r14, %rdx
callq 0x2120
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movq %r14, %rdx
callq 0x2120
movzbl 0x2(%rsp), %eax
movsbl 0x3(%rsp), %ecx
imull 0x18(%rsp), %ecx
cvtsi2sd %ecx, %xmm0
subl $0x1, %eax
jb 0x2d80
movslq %r13d, %rcx
movq 0x48(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %ebp, %rbp
movsd %xmm0, (%rcx,%rbp,8)
incl %ebp
cmpl 0x10(%rsp), %ebp
jne 0x2dba
incl %r13d
xorl %ebp, %ebp
cmpl 0x4(%rsp), %r13d
jne 0x2dba
movl 0x4(%rsp), %r13d
jmp 0x2d80
xorl %r13d, %r13d
leaq 0xd0(%rsp), %r15
pushq $0x1
popq %r14
xorl %ebp, %ebp
cmpl 0x4(%rsp), %r13d
je 0x2e6d
movq %r15, %rdi
leaq 0x2(%rsp), %rsi
movq %r14, %rdx
callq 0x2120
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movq %r14, %rdx
callq 0x2120
movzbl 0x2(%rsp), %eax
movsbl 0x3(%rsp), %ecx
imull 0x18(%rsp), %ecx
cvtsi2sd %ecx, %xmm0
subl $0x1, %eax
jb 0x2dff
movslq %r13d, %rcx
movq 0x38(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %ebp, %rbp
movsd %xmm0, (%rcx,%rbp,8)
incl %ebp
cmpl 0x10(%rsp), %ebp
jne 0x2e39
incl %r13d
xorl %ebp, %ebp
cmpl 0x4(%rsp), %r13d
jne 0x2e39
movl 0x4(%rsp), %r13d
jmp 0x2dff
xorl %r13d, %r13d
leaq 0xd0(%rsp), %r15
xorl %ebp, %ebp
cmpl 0x4(%rsp), %r13d
je 0x2eeb
movq %r15, %rdi
leaq 0x2(%rsp), %rsi
pushq $0x1
popq %rdx
movq %rdx, %r14
callq 0x2120
movq %r15, %rdi
leaq 0x3(%rsp), %rsi
movq %r14, %rdx
callq 0x2120
movzbl 0x2(%rsp), %eax
movsbl 0x3(%rsp), %ecx
imull 0x18(%rsp), %ecx
cvtsi2sd %ecx, %xmm0
subl $0x1, %eax
jb 0x2e7a
movslq %r13d, %rcx
movq 0x30(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movslq %ebp, %rbp
movsd %xmm0, (%rcx,%rbp,8)
incl %ebp
cmpl 0x10(%rsp), %ebp
jne 0x2eb7
incl %r13d
xorl %ebp, %ebp
cmpl 0x4(%rsp), %r13d
jne 0x2eb7
movl 0x4(%rsp), %r13d
jmp 0x2e7a
xorl %eax, %eax
movl 0x10(%rsp), %edx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
pushq $0x1
popq %rbp
cmpq 0x28(%rsp), %rax
je 0x2f23
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2f1e
movq 0x8(%rsp), %rsi
movq (%rsi,%rax,8), %rsi
movb $0x0, (%rsi,%rdx)
incq %rdx
jmp 0x2f07
incq %rax
jmp 0x2efe
leaq 0xd0(%rsp), %rdi
callq 0x2050
cvtsi2sdl 0x10(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x78(%rsp), %r15
movl 0x44(%rsp), %eax
testl %eax, %eax
jle 0x2fb7
decl %eax
movl %eax, 0x44(%rsp)
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x20e0
movsd 0x60(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r14d
movsd 0x10(%rsp), %xmm0
callq 0x20e0
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r13d
movq %r15, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x2506
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x2506
leaq 0x68(%rsp), %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x2506
jmp 0x2f41
xorl %eax, %eax
movq 0x48(%rsp), %r13
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %r8
movq 0x58(%rsp), %r14
cmpq 0x28(%rsp), %rax
je 0x304b
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %r12, %rdx
jge 0x2ffa
movq (%r13,%rax,8), %rsi
movsd (%rsi,%rcx), %xmm0
movq (%rbx,%rax,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
addq $0x3, %rdx
addq $0x8, %rcx
jmp 0x2fd8
xorl %ecx, %ecx
movq %rbp, %rdx
cmpq %r12, %rdx
jge 0x3020
movq (%rdi,%rax,8), %rsi
movsd (%rsi,%rcx), %xmm0
movq (%rbx,%rax,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
addq $0x3, %rdx
addq $0x8, %rcx
jmp 0x2fff
xorl %ecx, %ecx
pushq $0x2
popq %rdx
cmpq %r12, %rdx
jge 0x3046
movq (%r8,%rax,8), %rsi
movsd (%rsi,%rcx), %xmm0
movq (%rbx,%rax,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
addq $0x3, %rdx
addq $0x8, %rcx
jmp 0x3025
incq %rax
jmp 0x2fcd
xorl %ecx, %ecx
movl 0x24(%rsp), %edx
testl %edx, %edx
movl $0x0, %eax
cmovgl %edx, %eax
movsd 0xff5(%rip), %xmm0      # 0x4058
movl 0x50(%rsp), %ebp
cmpq 0x28(%rsp), %rcx
je 0x30a1
xorl %edx, %edx
cmpq %rdx, %rax
je 0x309c
movq (%rbx,%rcx,8), %rsi
movsd (%rsi,%rdx,8), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
ja 0x3092
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x3097
movsd %xmm1, (%rsi,%rdx,8)
incq %rdx
jmp 0x3070
incq %rcx
jmp 0x3067
xorl %ecx, %ecx
cmpq 0x28(%rsp), %rcx
je 0x30d1
xorl %edx, %edx
cmpq %rdx, %rax
je 0x30cc
movq (%rbx,%rcx,8), %rsi
cvttsd2si (%rsi,%rdx,8), %esi
movq 0x8(%rsp), %rdi
movq (%rdi,%rcx,8), %rdi
movb %sil, (%rdi,%rdx)
incq %rdx
jmp 0x30ac
incq %rcx
jmp 0x30a3
leaq 0xb0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x2150
leaq 0xb0(%rsp), %r9
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %esi
movl 0x24(%rsp), %edx
movq %r14, %rcx
movl %ebp, %r8d
callq 0x28c9
leaq 0xb0(%rsp), %rdi
callq 0x2080
pushq $0x1
popq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2100
xorl %r12d, %r12d
pushq $0x8
popq %r14
cmpq %r12, 0x28(%rsp)
je 0x3174
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq %rbx, %rsi
callq 0x2100
movq (%r13,%r12,8), %rdi
movq %r14, %rsi
callq 0x2100
movq 0x38(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq %r14, %rsi
callq 0x2100
movq 0x30(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq %r14, %rsi
callq 0x2100
incq %r12
jmp 0x3128
pushq $0x8
popq %rbx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x2100
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2100
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x2100
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x2100
xorl %ebx, %ebx
leaq 0xd0(%rsp), %rdi
callq 0x2060
leaq 0x90(%rsp), %rdi
callq 0x2080
movl %ebx, %eax
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x2080
jmp 0x320d
jmp 0x320a
jmp 0x320a
jmp 0x320a
jmp 0x320a
jmp 0x320a
jmp 0x320a
jmp 0x320a
movq %rax, %rbx
jmp 0x321a
jmp 0x320a
jmp 0x320a
jmp 0x320a
jmp 0x320a
jmp 0x320a
jmp 0x320a
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x2060
leaq 0x90(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x21a0
nop