// File: /workspace/github_cpp_makefile_star2_O2/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 0x3c81
movq 0x3373(%rip), %rdi      # 0x6fd8
leaq 0x1486(%rip), %rsi      # 0x50f2
callq 0x2100
movq %rax, %rdi
callq 0x2090
pushq $0x1
popq %rbx
jmp 0x4467
movq %rsi, %rbx
movl %edi, %ebp
pushq $0x1
popq %r12
cmpl $0x3, %edi
jl 0x3cc8
movq 0x10(%rbx), %rdi
callq 0x21d0
testl %eax, %eax
jle 0x447b
movl %eax, %r15d
cmpl $0x3, %ebp
je 0x3ccc
movq 0x18(%rbx), %rdi
callq 0x21d0
movl %eax, %r12d
testl %eax, %eax
jg 0x3ccc
movq 0x3319(%rip), %rdi      # 0x6fd8
leaq 0x149f(%rip), %rsi      # 0x5165
jmp 0x3c6c
pushq $0x14
popq %r15
movq 0x8(%rbx), %rsi
leaq 0xa0(%rsp), %rdi
leaq 0x100(%rsp), %rdx
callq 0x45b4
leaq 0x100(%rsp), %rdi
callq 0x2130
movq 0xa0(%rsp), %rsi
leaq 0x100(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x20a0
leaq 0x100(%rsp), %rdi
pushq $0xa
popq %rsi
xorl %edx, %edx
callq 0x2180
leaq 0x100(%rsp), %rdi
leaq 0x9c(%rsp), %rbx
pushq $0x4
popq %rdx
movq %rbx, %rsi
callq 0x2160
xorl %r14d, %r14d
xorl %ecx, %ecx
cmpq $0x20, %r14
je 0x3d76
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r14d, %xmm0
movl %ecx, %ebp
callq 0x20f0
cvtsi2sd %ebp, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
addq $0x8, %r14
incq %rbx
jmp 0x3d3c
movl %ecx, 0x3c(%rsp)
movl %ecx, 0x68(%rsp)
leaq 0x100(%rsp), %rdi
pushq $0x12
popq %rsi
xorl %edx, %edx
callq 0x2180
leaq 0x100(%rsp), %rdi
leaq 0x98(%rsp), %rbx
pushq $0x4
popq %rdx
movq %rbx, %rsi
callq 0x2160
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq $0x20, %r14
je 0x3deb
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r14d, %xmm0
callq 0x20f0
cvtsi2sd %r13d, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13d
addq $0x8, %r14
incq %rbx
jmp 0x3db1
imull $0x18, %r13d, %eax
addl $0x1f, %eax
pushq $0x20
popq %rcx
cltd
idivl %ecx
shll $0x2, %eax
pushq $0x3
popq %rcx
movl %eax, 0x20(%rsp)
cltd
idivl %ecx
movl %eax, %ebp
leaq 0x100(%rsp), %rdi
leaq 0x94(%rsp), %rbx
pushq $0x4
popq %rdx
movq %rbx, %rsi
callq 0x2160
xorl %r14d, %r14d
movl $0x0, 0x14(%rsp)
cmpq $0x20, %r14
je 0x3e6b
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r14d, %xmm0
callq 0x20f0
cvtsi2sdl 0x14(%rsp), %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x14(%rsp)
addq $0x8, %r14
incq %rbx
jmp 0x3e2d
leaq 0x100(%rsp), %rdi
pushq $0x1c
popq %rsi
xorl %edx, %edx
callq 0x2180
leaq 0x100(%rsp), %rdi
leaq 0x6e(%rsp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rsi
callq 0x2160
movl %ebp, 0x24(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpq $0x10, %r14
je 0x3ed6
movzbl (%rbx), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r14d, %xmm0
callq 0x20f0
cvtsi2sd %ebp, %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
addq $0x8, %r14
incq %rbx
jmp 0x3e9e
cmpl $0x18, %ebp
jne 0x4008
movq %r15, 0x78(%rsp)
movslq 0x3c(%rsp), %r14
movq %r14, %rdi
callq 0x2030
movq %rax, %rbx
movq %rax, 0x88(%rsp)
movl 0x14(%rsp), %eax
movslq %eax, %r15
shlq $0x3, %r15
testl %eax, %eax
pushq $-0x1
popq %rax
cmovsq %rax, %r15
movq %r15, %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
movq %r15, %rdi
callq 0x2030
movq %rax, %rbp
movq %r14, 0x80(%rsp)
movq %rbx, 0x40(%rsp)
movq %r15, %rdi
callq 0x2030
movq %r12, 0x70(%rsp)
movq %rax, 0x30(%rsp)
movq %rax, 0x60(%rsp)
movq %r15, %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
movq %rax, 0x58(%rsp)
movq %r15, %rdi
callq 0x2030
movq %rax, %r12
movslq 0x20(%rsp), %r15
leaq (,%r15,8), %rax
movslq 0x24(%rsp), %rbx
shlq $0x3, %rbx
cmpl $-0x2, %r13d
pushq $-0x1
popq %rcx
cmovlq %rcx, %rax
movq %rax, 0x48(%rsp)
movq %r12, 0x50(%rsp)
cmovlq %rcx, %rbx
xorl %r13d, %r13d
movl 0x14(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0x18(%rsp)
cmpq %r13, 0x18(%rsp)
je 0x402b
movq %r15, %rdi
callq 0x2030
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x48(%rsp), %rdi
callq 0x2030
movq %rax, (%rbp,%r13,8)
movq %rbx, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %rbx, %rdi
callq 0x2030
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %rbx, %rdi
callq 0x2030
movq %rax, (%r12,%r13,8)
incq %r13
jmp 0x3fae
movq 0x2fc9(%rip), %rdi      # 0x6fd8
leaq 0x1186(%rip), %rsi      # 0x519c
callq 0x2100
movq %rax, %rdi
callq 0x2090
pushq $0x1
popq %rbx
jmp 0x444d
leaq 0x100(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2180
leaq 0x100(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x80(%rsp), %rdx
callq 0x2160
xorl %r13d, %r13d
leaq 0x100(%rsp), %rbx
cmpq %r13, 0x18(%rsp)
je 0x4081
movq 0x8(%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2160
incq %r13
jmp 0x4061
xorl %eax, %eax
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
movl $0x0, %r13d
cmovgl %ecx, %r13d
cmpq 0x18(%rsp), %rax
je 0x40c6
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0x40c1
movq 0x8(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
movzbl (%rdx,%rcx), %edx
cvtsi2sd %edx, %xmm0
movq (%rbp,%rax,8), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x409c
incq %rax
jmp 0x4093
xorl %eax, %eax
pushq $0x1
popq %rcx
cmpq 0x18(%rsp), %rax
je 0x415c
xorl %edx, %edx
xorl %esi, %esi
cmpq %r15, %rsi
jge 0x4101
movq (%rbp,%rax,8), %rdi
movsd (%rdi,%rsi,8), %xmm0
movq 0x30(%rsp), %rdi
movq (%rdi,%rax,8), %rdi
movsd %xmm0, (%rdi,%rdx)
addq $0x3, %rsi
addq $0x8, %rdx
jmp 0x40da
xorl %edx, %edx
movq %rcx, %rsi
cmpq %r15, %rsi
jge 0x412d
movq (%rbp,%rax,8), %rdi
movsd (%rdi,%rsi,8), %xmm0
movq 0x28(%rsp), %rdi
movq (%rdi,%rax,8), %rdi
movsd %xmm0, (%rdi,%rdx)
addq $0x3, %rsi
addq $0x8, %rdx
jmp 0x4106
xorl %edx, %edx
pushq $0x2
popq %rsi
cmpq %r15, %rsi
jge 0x4154
movq (%rbp,%rax,8), %rdi
movsd (%rdi,%rsi,8), %xmm0
movq (%r12,%rax,8), %rdi
movsd %xmm0, (%rdi,%rdx)
addq $0x3, %rsi
addq $0x8, %rdx
jmp 0x4132
incq %rax
jmp 0x40cb
leaq 0x100(%rsp), %rdi
callq 0x2050
movq 0x70(%rsp), %rax
movl %eax, 0x48(%rsp)
movl 0x14(%rsp), %r14d
subl $0x1, 0x48(%rsp)
jb 0x41c6
leaq 0x60(%rsp), %rdi
movl %r14d, %esi
movl 0x24(%rsp), %ebx
movl %ebx, %edx
callq 0x2ef1
leaq 0x58(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x2ef1
leaq 0x50(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x2ef1
movl %r14d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %r14d
movl %ebx, %eax
cltd
idivl %ecx
movl %eax, 0x24(%rsp)
jmp 0x4177
xorl %eax, %eax
pushq $0x1
popq %rcx
pushq $0x2
popq %rdx
cmpq 0x18(%rsp), %rax
je 0x4265
xorl %esi, %esi
xorl %edi, %edi
cmpq %r15, %rdi
jge 0x4206
movq 0x30(%rsp), %r8
movq (%r8,%rax,8), %r8
movsd (%r8,%rsi), %xmm0
movq (%rbp,%rax,8), %r8
movsd %xmm0, (%r8,%rdi,8)
addq $0x3, %rdi
addq $0x8, %rsi
jmp 0x41dd
xorl %esi, %esi
movq %rcx, %rdi
cmpq %r15, %rdi
jge 0x4234
movq 0x28(%rsp), %r8
movq (%r8,%rax,8), %r8
movsd (%r8,%rsi), %xmm0
movq (%rbp,%rax,8), %r8
movsd %xmm0, (%r8,%rdi,8)
addq $0x3, %rdi
addq $0x8, %rsi
jmp 0x420b
xorl %esi, %esi
movq %rdx, %rdi
cmpq %r15, %rdi
jge 0x425d
movq (%r12,%rax,8), %r8
movsd (%r8,%rsi), %xmm0
movq (%rbp,%rax,8), %r8
movsd %xmm0, (%r8,%rdi,8)
addq $0x3, %rdi
addq $0x8, %rsi
jmp 0x4239
incq %rax
jmp 0x41ce
xorl %eax, %eax
movsd 0xe49(%rip), %xmm0      # 0x50b8
movq 0x78(%rsp), %r15
cmpq 0x18(%rsp), %rax
je 0x42af
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0x42aa
movq (%rbp,%rax,8), %rdx
movsd (%rdx,%rcx,8), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
ja 0x42a0
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x42a5
movsd %xmm1, (%rdx,%rcx,8)
incq %rcx
jmp 0x427d
incq %rax
jmp 0x4274
xorl %eax, %eax
cmpq 0x18(%rsp), %rax
je 0x42df
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0x42da
movq (%rbp,%rax,8), %rdx
cvttsd2si (%rdx,%rcx,8), %edx
movq 0x8(%rsp), %rsi
movq (%rsi,%rax,8), %rsi
movb %dl, (%rsi,%rcx)
incq %rcx
jmp 0x42ba
incq %rax
jmp 0x42b1
leaq 0xf02(%rip), %rdx       # 0x51e8
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x45ef
leaq 0xc0(%rsp), %r9
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %ebp
movl %ebp, %esi
movl 0x20(%rsp), %edx
movq 0x40(%rsp), %rcx
movl 0x3c(%rsp), %r8d
callq 0x3754
leaq 0xc0(%rsp), %rdi
callq 0x2080
leaq 0x60(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %ecx
callq 0x36a3
leaq 0x58(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %ecx
callq 0x36a3
leaq 0x50(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %ecx
callq 0x36a3
movq %r15, %r13
leaq 0xe0(%rsp), %r15
leaq 0xa0(%rsp), %rsi
movq %r15, %rdi
callq 0x2190
leaq 0x68(%rsp), %rax
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x88(%rsp), %r9
movl %ebp, %ecx
pushq %r13
pushq 0x78(%rsp)
pushq %r15
pushq %rax
callq 0x381b
addq $0x20, %rsp
leaq 0xe0(%rsp), %rdi
callq 0x2080
pushq $0x1
popq %r15
movq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x2120
xorl %r13d, %r13d
pushq $0x8
popq %rbp
cmpq %r13, 0x18(%rsp)
je 0x4415
movq 0x8(%rsp), %rax
movq (%rax,%r13,8), %rdi
movq %r15, %rsi
callq 0x2120
movq 0x30(%rsp), %rax
movq (%rax,%r13,8), %rdi
movq %rbp, %rsi
callq 0x2120
movq 0x28(%rsp), %rax
movq (%rax,%r13,8), %rdi
movq %rbp, %rsi
callq 0x2120
movq (%r12,%r13,8), %rdi
movq %rbp, %rsi
callq 0x2120
incq %r13
jmp 0x43ca
pushq $0x8
popq %r15
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x2120
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x2120
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x2120
movq %r12, %rdi
movq %r15, %rsi
callq 0x2120
xorl %ebx, %ebx
leaq 0x100(%rsp), %rdi
callq 0x2060
leaq 0xa0(%rsp), %rdi
callq 0x2080
movl %ebx, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2b56(%rip), %rdi      # 0x6fd8
leaq 0xc9e(%rip), %rsi       # 0x5127
jmp 0x3c6c
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x44a8
jmp 0x44c8
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x2080
jmp 0x44cb
jmp 0x44c8
jmp 0x44c8
jmp 0x44c8
jmp 0x44c8
jmp 0x44c8
jmp 0x44c8
movq %rax, %rbx
jmp 0x44d8
jmp 0x44c8
jmp 0x44c8
jmp 0x44c8
jmp 0x44c8
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x2060
leaq 0xa0(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2200
nop