// File: /workspace/github_cpp_makefile_star2_O3/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 $0x318, %rsp            # imm = 0x318
cmpl $0x1, %edi
jne 0x4528
movq 0x3af5(%rip), %rbx      # 0x7fd8
leaq 0x1cb0(%rip), %rsi      # 0x619a
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, %ebx
jmp 0x4e9c
movq %rsi, %rbx
movl %edi, %ebp
movl $0x1, %r15d
movl $0x14, %eax
movq %rax, 0x80(%rsp)
cmpl $0x3, %edi
jl 0x4577
movq 0x10(%rbx), %rdi
callq 0x21e0
movq %rax, 0x80(%rsp)
testl %eax, %eax
jle 0x4eb0
cmpl $0x3, %ebp
je 0x4577
movq 0x18(%rbx), %rdi
callq 0x21e0
movl %eax, %r15d
testl %eax, %eax
jle 0x4ec8
movq 0x8(%rbx), %rsi
leaq 0xa8(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x4fc8
leaq 0x110(%rsp), %rdi
callq 0x2150
movq 0xa8(%rsp), %rsi
leaq 0x110(%rsp), %rdi
movl $0xc, %edx
callq 0x20a0
leaq 0x110(%rsp), %rdi
movl $0xa, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x110(%rsp), %rdi
leaq 0xec(%rsp), %rbx
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2180
xorl %r14d, %r14d
xorl %ecx, %ecx
movzbl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movl %ecx, %ebp
callq 0x2110
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
addq $0x8, %r14
incq %rbx
cmpq $0x20, %r14
jne 0x45ed
movl %ecx, 0x34(%rsp)
movl %ecx, 0x74(%rsp)
leaq 0x110(%rsp), %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x110(%rsp), %rdi
leaq 0xe8(%rsp), %rbx
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2180
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 0x2110
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 0x466c
leal (,%rbp,8), %eax
leal (%rax,%rax,2), %ecx
addl $0x1f, %ecx
leal (%rax,%rax,2), %ebx
addl $0x3e, %ebx
testl %ecx, %ecx
cmovnsl %ecx, %ebx
leaq 0x110(%rsp), %rdi
leaq 0xe4(%rsp), %r14
movl $0x4, %edx
movq %r14, %rsi
callq 0x2180
movq %r15, 0x78(%rsp)
sarl $0x5, %ebx
shll $0x2, %ebx
movl %ebx, 0x20(%rsp)
movslq %ebx, %r12
imulq $0x55555556, %r12, %rbx # imm = 0x55555556
movq %rbx, %rax
shrq $0x3f, %rax
shrq $0x20, %rbx
addl %eax, %ebx
xorl %r15d, %r15d
xorl %r13d, %r13d
movzbl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
callq 0x2110
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13d
addq $0x8, %r15
incq %r14
cmpq $0x20, %r15
jne 0x470c
movl %r13d, 0xc(%rsp)
leaq 0x110(%rsp), %rdi
movl $0x1c, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x110(%rsp), %rdi
leaq 0x26(%rsp), %r14
movl $0x2, %edx
movq %r14, %rsi
callq 0x2180
movq %rbp, 0xd0(%rsp)
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
movb $0x1, %r15b
leaq 0x27(%rsp), %rbp
movzbl (%r14), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x10(%rsp)
callq 0x2110
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13d
movq %rbp, %r14
movsd 0x1988(%rip), %xmm0     # 0x6158
testb $0x1, %r15b
movl $0x0, %r15d
jne 0x4798
cmpl $0x18, %r13d
jne 0x4e23
movslq 0x34(%rsp), %r15
movq %r15, %rdi
callq 0x2030
movq %rax, 0x50(%rsp)
movq %rax, 0xd8(%rsp)
movslq 0xc(%rsp), %rax
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %r14
cmovnsq %rcx, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
movq 0xd0(%rsp), %r13
movq %r14, %rdi
callq 0x2030
movq %rax, 0x18(%rsp)
movq %r14, %rdi
callq 0x2030
movq %r15, 0xc8(%rsp)
movq %rax, 0x48(%rsp)
movq %rax, 0x68(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x40(%rsp)
movq %rax, 0x60(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x38(%rsp)
movq %rax, 0x58(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
testl %eax, %eax
jle 0x4911
leaq (,%r12,8), %rbp
movslq %ebx, %r14
shlq $0x3, %r14
cmpl $-0x2, %r13d
movq $-0x1, %rax
cmovlq %rax, %rbp
cmovlq %rax, %r14
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x2030
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq %rbp, %rdi
callq 0x2030
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq %r14, %rdi
callq 0x2030
movq 0x48(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq %r14, %rdi
callq 0x2030
movq 0x40(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
movq %r14, %rdi
callq 0x2030
movq 0x38(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq %r15, 0x10(%rsp)
jne 0x48b2
leaq 0x110(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21a0
leaq 0x110(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0xc8(%rsp), %rdx
callq 0x2180
cmpl $0x0, 0xc(%rsp)
jle 0x4a7b
xorl %r15d, %r15d
leaq 0x110(%rsp), %r14
movq 0x28(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x2180
incq %r15
cmpq %r15, 0x10(%rsp)
jne 0x4952
cmpl $0x0, 0xc(%rsp)
movq 0x38(%rsp), %r9
jle 0x4a7b
movl 0x20(%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
testl %r13d, %r13d
jle 0x49c4
movq 0x28(%rsp), %rdx
movq (%rdx,%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 0x49aa
incq %rcx
cmpq 0x10(%rsp), %rcx
jne 0x4991
cmpl $0x0, 0xc(%rsp)
jle 0x4a7b
xorl %eax, %eax
testl %r13d, %r13d
jle 0x4a6d
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x48(%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 %r12, %rsi
jl 0x49f8
testl %r13d, %r13d
jle 0x4a6d
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x40(%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 %r12, %rsi
jl 0x4a2a
testl %r13d, %r13d
jle 0x4a6d
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq (%r9,%rax,8), %rdx
movl $0x2, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx)
addq $0x3, %rsi
addq $0x8, %rdx
cmpq %r12, %rsi
jl 0x4a57
incq %rax
cmpq 0x10(%rsp), %rax
jne 0x49db
leaq 0x110(%rsp), %rdi
callq 0x2060
movq 0x78(%rsp), %rax
cmpl $0x1, %eax
movl %eax, %r14d
adcl $0x0, %r14d
leaq 0x68(%rsp), %rbp
movl 0xc(%rsp), %r15d
movq %rbp, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0x359b
leaq 0x60(%rsp), %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0x359b
leaq 0x58(%rsp), %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0x359b
movl %r15d, %eax
shrl $0x1f, %eax
addl %r15d, %eax
sarl %eax
movl %ebx, %ecx
shrl $0x1f, %ecx
addl %ebx, %ecx
sarl %ecx
movl %ecx, %ebx
movl %eax, %r15d
decl %r14d
jne 0x4aa1
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
movq 0x38(%rsp), %rdi
jle 0x4c48
xorl %eax, %eax
testl %r13d, %r13d
jle 0x4b8f
movq 0x48(%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 %r12, %rsi
jl 0x4b1a
testl %r13d, %r13d
jle 0x4b8f
movq 0x40(%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 %r12, %rsi
jl 0x4b4c
testl %r13d, %r13d
jle 0x4b8f
movq (%rdi,%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 %r12, %rsi
jl 0x4b79
incq %rax
cmpq 0x10(%rsp), %rax
jne 0x4afd
testl %ebx, %ebx
jle 0x4c48
movl 0x20(%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
movsd 0x15a2(%rip), %xmm0     # 0x6160
testl %r13d, %r13d
jle 0x4bf4
movq 0x18(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
ja 0x4be7
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x4bec
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x4bce
incq %rcx
cmpq 0x10(%rsp), %rcx
jne 0x4bbe
testl %ebx, %ebx
jle 0x4c48
movl 0x20(%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
testl %r13d, %r13d
jle 0x4c3e
movq 0x18(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq 0x28(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
xorl %edi, %edi
cvttsd2si (%rdx,%rdi,8), %r8d
movb %r8b, (%rsi,%rdi)
incq %rdi
cmpq %rdi, %rax
jne 0x4c2c
incq %rcx
cmpq 0x10(%rsp), %rcx
jne 0x4c13
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x5006
leaq 0x1615(%rip), %rsi      # 0x6290
leaq 0x88(%rsp), %rdi
callq 0x2230
movq 0x80(%rsp), %r15
movq 0x28(%rsp), %rbp
movq 0x48(%rsp), %r12
leaq 0x88(%rsp), %r9
movq %rbp, %rdi
movl %ebx, %esi
movl 0x20(%rsp), %edx
movq 0x50(%rsp), %rcx
movl 0x34(%rsp), %r8d
callq 0x3f82
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x4cd7
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2140
leaq 0x68(%rsp), %rdi
movl %ebx, %esi
movl %r15d, %ecx
callq 0x3ed0
leaq 0x60(%rsp), %rdi
movl %ebx, %esi
movl %r15d, %ecx
callq 0x3ed0
leaq 0x58(%rsp), %rdi
movl %ebx, %esi
movl %r15d, %ecx
callq 0x3ed0
leaq 0x100(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
callq 0x5006
leaq 0x74(%rsp), %rax
leaq 0x68(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0xd8(%rsp), %r9
movl %ebx, %ecx
pushq %r15
pushq 0x80(%rsp)
pushq %r14
pushq %rax
callq 0x4072
addq $0x20, %rsp
movq 0xf0(%rsp), %rdi
cmpq %r13, %rdi
je 0x4d83
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2140
movl $0x1, %esi
movq 0x50(%rsp), %rdi
callq 0x2140
cmpl $0x0, 0xc(%rsp)
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %r15
movq 0x10(%rsp), %r13
jle 0x4deb
xorl %ebx, %ebx
movq (%rbp,%rbx,8), %rdi
movl $0x1, %esi
callq 0x2140
movq (%r12,%rbx,8), %rdi
movl $0x8, %esi
callq 0x2140
movq (%r14,%rbx,8), %rdi
movl $0x8, %esi
callq 0x2140
movq (%r15,%rbx,8), %rdi
movl $0x8, %esi
callq 0x2140
incq %rbx
cmpq %rbx, %r13
jne 0x4daa
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2140
movl $0x8, %esi
movq %r12, %rdi
callq 0x2140
movl $0x8, %esi
movq %r14, %rdi
callq 0x2140
movl $0x8, %esi
movq %r15, %rdi
callq 0x2140
xorl %ebx, %ebx
jmp 0x4e6e
movq 0x31ae(%rip), %rbx      # 0x7fd8
leaq 0x1413(%rip), %rsi      # 0x6244
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 0x317c(%rip), %rdi      # 0x7fd8
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x20c0
leaq 0x110(%rsp), %rdi
callq 0x2070
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4e9c
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2140
movl %ebx, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3121(%rip), %rbx      # 0x7fd8
leaq 0x1311(%rip), %rsi      # 0x61cf
movl $0x3d, %edx
jmp 0x44ef
movq 0x3109(%rip), %rbx      # 0x7fd8
leaq 0x1337(%rip), %rsi      # 0x620d
movl $0x36, %edx
jmp 0x44ef
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r13, %rdi
je 0x4f3c
movq 0x100(%rsp), %rsi
jmp 0x4f16
jmp 0x4f39
jmp 0x4efe
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x4f3c
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2140
jmp 0x4f3c
jmp 0x4f39
jmp 0x4f39
jmp 0x4f39
jmp 0x4f39
jmp 0x4f39
jmp 0x4f39
movq %rax, %rbx
jmp 0x4f49
jmp 0x4f39
jmp 0x4f39
jmp 0x4f39
jmp 0x4f39
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x2070
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f6a
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2210