// File: /workspace/github_cpp_makefile_star2_O2/treroy13[P]Branch-Predictor/predictors.cpp
// Function: main
int main(int argc, char *argv[]) {

	unsigned long long addr1;
	string behavior1;
	int takenCount =0;
	int untakenCount =0;
	int numBranches = 0;


	//create a struct with addr and behavior
	struct branches{

		unsigned long long addr;
		int behavior;

	};

	branches br;

	//push structs into vector temp
	std::vector<branches>temp;

	
	//input file 
	ifstream infile(argv[1]);

	//placing values into struct/pushing back into vector
	while(infile >> std::hex >> addr1 >> behavior1) {
	
		numBranches++;	//get total count of file 

		br.addr = addr1;

		if(behavior1 == "T")
			br.behavior = 1;
		else
			br.behavior = 0;

		temp.push_back(br); //insert into vector	

	}

	infile.close();
	
//------------------------ALWAYS TAKEN & NON TAKEN--------------------------------------------

	
	for(int i = 0; i<temp.size(); i++){
		if(temp[i].behavior == 1)
			takenCount++;
		else
			untakenCount++;	
	}

	 
	//output file taken and nottaken
	ofstream outfile(argv[2]);
	outfile << takenCount<<","<<numBranches<<";\n";
	outfile << untakenCount<<","<<numBranches<<";\n";

//------------------------BIMODAL SINGLE BIT--------------------------------------------------

	
	int tableSize[] = {16,32,128,256,512,1024,2048};

	int singleCorrect16 = 0;
	int singleCorrect32 = 0;
	int singleCorrect128 = 0;
	int singleCorrect256 = 0;
	int singleCorrect512 = 0;
	int singleCorrect1024 = 0;
	int singleCorrect2048 = 0;	 

	//initialing vector to all takens (1)
	std::vector<int>bits(numBranches,1);	 
	
	int check;

	//loop through 7 different table sizes
	for(int i = 0 ; i < 7; i++){

		//reset branch for new table size
		std::fill(bits.begin(),bits.end(),1); 

		//loop through struct with values from the file
		for(int k =0; k < temp.size(); k++){
			
			//mod address with table size			
			check = temp[k].addr % tableSize[i];			
 
			//if prediction is correct, then increment counter
			if(bits[check] == temp[k].behavior){
				if (i==0){
					singleCorrect16++;
				}
				if (i ==1){
					singleCorrect32++;
				}
				if (i ==2){
					singleCorrect128++;
				}
				if (i ==3){
					singleCorrect256++;
				}
				if (i ==4){
					singleCorrect512++;
				}
				if (i ==5){
					singleCorrect1024++;
				}
				if(i==6){
					singleCorrect2048++;
				}
			}

			else{
				//wrong prediction so change to 0
				bits[check] = temp[k].behavior;
			}
			
		}			

	}

	outfile << singleCorrect16<<","<<numBranches<<"; "<< singleCorrect32<<","<<numBranches<<"; "<< singleCorrect128<<","<<numBranches<<"; "<< singleCorrect256<<","<<numBranches<<"; "<< singleCorrect512<<","<<numBranches<<"; "<< singleCorrect1024<<","<<numBranches<<"; "<< singleCorrect2048<<","<<numBranches<<";\n";



//------------------------BIMODAL 2 BIT--------------------------------------------------


	int twoCorrect16 = 0;
	int twoCorrect32 = 0;
	int twoCorrect128 = 0;
	int twoCorrect256 = 0;
	int twoCorrect512 = 0;
	int twoCorrect1024 = 0;
	int twoCorrect2048 = 0;

	int check2;
	unsigned int vecVal;	 

	//initialing vector to all takens (1)
	std::vector<unsigned int>bits2(numBranches,3);

	//looping through 7 different table sizes
	for(int j = 0 ; j < 7; j++){
	
		std::fill(bits2.begin(),bits2.end(),3); //reset vector with all 3

		for(unsigned long long n =0; n < temp.size(); n++){

			check2 = temp[n].addr % tableSize[j]; //index
			vecVal = bits2[check2]; //current state of vector


			//if prediction is correct then increment counter for each table size
                        if(((temp[n].behavior == 1) && ((vecVal == 3)||(vecVal == 2))) || ((temp[n].behavior == 0) && ((vecVal ==0) || (vecVal ==1)))){
				if (j==0){
					twoCorrect16++;
				}
				if (j ==1){
					twoCorrect32++;
				}
				if (j ==2){
					twoCorrect128++;
				}
				if (j ==3){
					twoCorrect256++;
				}
				if (j ==4){
					twoCorrect512++;
				}
				if (j ==5){
					twoCorrect1024++;
				}
				if (j ==6){
					twoCorrect2048++;
				}

			}			

			if(temp[n].behavior == 1){ //increment so closer to strongly taken
				if(vecVal != 3){
					vecVal++;
				}
			}
			if(temp[n].behavior == 0){
				if(vecVal != 0){ //decrement so closer to not taken
					vecVal--;
				}		
			}
			
			bits2[check2] = vecVal; //update vector with new value
		}

	}


	outfile << twoCorrect16<<","<<numBranches<<"; "<< twoCorrect32<<","<<numBranches<<"; "<< twoCorrect128<<","<<numBranches<<"; "<< twoCorrect256<<","<<numBranches<<"; "<< twoCorrect512<<","<<numBranches<<"; "<< twoCorrect1024<<","<<numBranches<<"; "<< twoCorrect2048<<","<<numBranches<<";\n";


//-----------------------------------------GSHARE--------------------------------------------------

	int p1 = 0;
	int p2 = 0;
	int p3 = 0;
	int p4 = 0;
	int p5 = 0;
	int p6 = 0;
	int p7 = 0;
	int p8 = 0;
	int p9 = 0;


	unsigned int size;

	unsigned long long hist;

	std::vector<unsigned int>table(2048,3);//vector initialized to strongly taken

	for(int i = 3; i<= 11; i++){

		hist = 0; //GHR

		std::fill(table.begin(),table.end(),3); //reset vector with all 3

		for(int d = 0; d < temp.size(); d++){

			int ck = (temp[d].addr ^ (hist & ((int) pow(2,i)-1))) % 2048; //XOR GHR with table size of 2048 (use pow to convert GHR to an int so its easier to xor with table size)

			unsigned int vecVal1 = table[ck];
			
			//if prediction is correct, then increment correct counter for each table size
			if(((temp[d].behavior == 1) && ((vecVal1 == 3)||(vecVal1 == 2))) || ((temp[d].behavior == 0) && ((vecVal1 ==0) || (vecVal1 ==1)))){
				if (i==3){
					p1++;
				}
				if (i ==4){
					p2++;
				}
				if (i ==5){
					p3++;
				}
				if (i ==6){
					p4++;
				}
				if (i ==7){
					p5++;
				}
				if (i ==8){
					p6++;
				}
				if (i ==9){
					p7++;
				}
				if (i ==10){
					p8++;
				}
				if (i ==11){
					p9++;
				}

			}

			if(temp[d].behavior == 1){ //increment so closer to strongly taken

				if(vecVal1 != 3)
					vecVal1++;
			}
			if(temp[d].behavior == 0){ //decrement so closer to not taken
				if(vecVal1 != 0)
					vecVal1--;
			}

			table[ck] = vecVal1; //update table with value

			//updating the GHR

			hist <<= 1; //shift the register
			
			hist |= temp[d].behavior; //bitwise OR (incrementing GHR) 			

		}	
		
	}

	outfile << p1<<","<<numBranches<<"; "<< p2<<","<<numBranches<<"; "<< p3<<","<<numBranches<<"; "<< p4<<","<<numBranches<<"; "<< p5<<","<<numBranches<<"; "<< p6<<","<<numBranches<<"; "<< p7<<","<<numBranches<<"; "<<p8<<","<<numBranches<<"; "<<p9<<","<<numBranches<<";\n";


//------------------------------------------TOURNAMENT------------------------------------------
	
	//counter for the number of times correct
	int tournCount = 0;

	//declaring GHR
	int hist2 = 0;

	//initializing gshare, bimodal, and tournament tables 
	std::vector<unsigned int> gs (2048, 3);
	std::vector<unsigned int> bi(2048, 3);
	std::vector<unsigned int> tourn(2048, 0); //tournament table initalized to prefer gshare

	for(int i = 0; i < temp.size(); i++){
                
		//using bimodal predictor index                                                                                         
		int index = temp[i].addr % 2048;

		//XORing GHR(use pow to convert to int) with table size
		int gIndex = (temp[i].addr ^ (hist2 & ((int) pow(2, 11) -1))) % 2048;

		//variables to keep track of state of each table 
		int biState = bi[index];	
		int gsState = gs[gIndex];
		int tournState = tourn[index];

		//predicted values
		int biVal = biState & 2;
		int gsVal = gsState & 2;		

		//if the predicted values are not equal, it means either bimodal or gshare is better so tournament table needs to be updated towards favored prediction 
		if(gsVal != biVal){

			//if tournament table prefers gshare
			if(tournState < 2){

				//if gshare predicted value is correct, then increment correct counter
				if(((temp[i].behavior == 1) && ((gsVal == 3)||(gsVal == 2))) || ((temp[i].behavior == 0) && ((gsVal ==0) || (gsVal ==1)))){
					tournCount++;
					
					//decrement tournament state value towards gshare since it was correct
					if(tournState != 0)
						tournState--;

				}

				//if gshare prediction was wrong, then increment tournament table towards bimodal
				else{
					if(tournState != 3)
						tournState++;
				}

			}

			else{ //tournament table prefers bimodal 

				
				//if bimodal predicted value is correct, then increment correct counter
				if(((temp[i].behavior == 1) && ((biVal == 3)||(biVal == 2))) || ((temp[i].behavior == 0) && ((biVal ==0) || (biVal ==1)))){
					tournCount++;

					//increment tournament table towards bimodal since it was correct
					if(tournState != 3)
						tournState++;

				}

				else{
					//since bimodal was wrong, then decrement tournament table towards gshare
					if(tournState != 0)
						tournState--;

				}

			}

		}


		//if predicted values are equal and its the correct prediction, then increment correct counter
		if(gsVal == biVal){

			if(((temp[i].behavior == 1) && ((gsVal == 3)||(gsVal == 2))) || ((temp[i].behavior == 0) && ((gsVal ==0) || (gsVal ==1)))){
				tournCount++;

			}

		}


		//update bimodal and gshare
		if(temp[i].behavior == 0){

			if(gsState != 0)
				gsState--;

			if(biState != 0)
				biState--;
		}
		
		if(temp[i].behavior == 1){


			if(gsState != 3)
				gsState++;

			if(biState != 3)
				biState++;


		}	

		gs[gIndex] = gsState;
		bi[index] = biState;

		//update GHR	
		hist2 <<= 1;
		hist2 |= temp[i].behavior;

		//update tournament table state value
		tourn[index] = tournState;

	}		

	outfile << tournCount<<","<<numBranches<<"; ";
	outfile.close();	

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x578, %rsp            # imm = 0x578
leaq -0x180(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %rbx
movb $0x0, (%rax)
xorpd %xmm0, %xmm0
movapd %xmm0, -0xc0(%rbp)
andq $0x0, -0xb0(%rbp)
movq 0x8(%rsi), %rsi
leaq -0x598(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x1180
movq %rbx, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x190(%rbp), %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %edx, %edx
movq -0xb8(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movq %r14, %rbx
subq %r15, %rbx
movl %edx, %edx
movq %rdx, -0x30(%rbp)
movq %r15, -0x68(%rbp)
movq -0x598(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x580(%rbp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, -0x580(%rbp,%rax)
leaq -0x598(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x1100
movq %rax, %rdi
movq %r12, %rsi
callq 0x1110
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x14d9
movq -0x158(%rbp), %r15
movq %r12, %r13
movq %r12, %rdi
leaq 0x1c62(%rip), %rsi      # 0x3018
callq 0x233e
movzbl %al, %r12d
cmpq -0x58(%rbp), %r14
je 0x13e8
movq %r15, (%r14)
movl %r12d, 0x8(%r14)
addq $0x10, %r14
addq $0x10, %rbx
incq -0x30(%rbp)
movq %r14, -0x38(%rbp)
movq -0x68(%rbp), %r15
movq %r13, %r12
jmp 0x1353
movq -0x38(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x58(%rbp), %rcx
movq %rcx, %r8
movq -0x68(%rbp), %rax
subq %rax, %r8
movabsq $0x7ffffffffffffff0, %rdx # imm = 0x7FFFFFFFFFFFFFF0
cmpq %rdx, %r8
je 0x2238
movq %r8, %r14
sarq $0x4, %r14
cmpq %rax, %rcx
movq %r14, %rax
pushq $0x1
popq %rcx
cmoveq %rcx, %rax
leaq (%rax,%r14), %rbx
movabsq $0x7ffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFF
cmpq %rcx, %rbx
cmovaeq %rcx, %rbx
addq %r14, %rax
cmovbq %rcx, %rbx
testq %rbx, %rbx
movq %r8, -0x38(%rbp)
je 0x1463
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x10e0
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %r8
jmp 0x1469
xorl %eax, %eax
movq -0x30(%rbp), %rdx
shlq $0x4, %r14
movq %r15, (%rax,%r14)
movl %r12d, 0x8(%rax,%r14)
testq %r8, %r8
movq -0x68(%rbp), %r14
movq %rax, %r15
jle 0x1498
movq %r15, %rdi
movq %r14, %rsi
movq %r8, %rdx
callq 0x1150
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %rdx
testq %r14, %r14
movq %r13, %r12
je 0x14b0
movq %r14, %rdi
callq 0x10c0
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %rdx
incq %rdx
leaq (%r15,%r8), %r14
addq $0x10, %r14
movq %r14, -0xb8(%rbp)
shlq $0x4, %rbx
addq %r15, %rbx
movq %rbx, -0x58(%rbp)
movq %rbx, -0xb0(%rbp)
jmp 0x1338
movq -0x38(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq %r15, -0xc0(%rbp)
leaq -0x598(%rbp), %rdi
callq 0x1030
sarq $0x4, %rbx
leaq 0x8(%r15), %rax
xorl %r14d, %r14d
movq %rbx, -0xa0(%rbp)
movq %rbx, %rcx
xorl %ebx, %ebx
subq $0x1, %rcx
jb 0x152d
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x1, (%rax)
sete %dl
setne %sil
addl %esi, %r14d
addl %edx, %ebx
addq $0x10, %rax
jmp 0x150e
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x390(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x10f0
leaq -0x390(%rbp), %rdi
movl %ebx, %esi
callq 0x1160
leaq 0x1ac1(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1aa8(%rip), %rsi      # 0x301c
movq %rax, %rdi
callq 0x10d0
leaq -0x390(%rbp), %rdi
movl %r14d, %esi
callq 0x1160
leaq 0x1a88(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1a6f(%rip), %rsi      # 0x301c
movq %rax, %rdi
callq 0x10d0
leaq -0x150(%rbp), %rdx
movl $0x1, (%rdx)
leaq -0x170(%rbp), %rdi
leaq -0xe8(%rbp), %rcx
movq -0x30(%rbp), %rsi
callq 0x234e
movq -0x170(%rbp), %rcx
movq -0x168(%rbp), %rdi
leaq 0x8(%r15), %rax
movq %rax, -0x78(%rbp)
xorl %r9d, %r9d
movl $0x0, -0x60(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
xorl %esi, %esi
movq %rcx, %rax
cmpq $0x7, %r9
jne 0x1636
jmp 0x16f1
movl $0x1, (%rax)
addq $0x4, %rax
cmpq %rdi, %rax
jne 0x162c
xorl %eax, %eax
testq %r9, %r9
sete %al
movl %eax, -0x38(%rbp)
xorl %eax, %eax
cmpq $0x1, %r9
sete %al
movl %eax, -0x58(%rbp)
xorl %r8d, %r8d
cmpq $0x2, %r9
sete %r8b
xorl %r14d, %r14d
cmpq $0x3, %r9
sete %r14b
xorl %r15d, %r15d
cmpq $0x4, %r9
sete %r15b
xorl %r12d, %r12d
cmpq $0x5, %r9
sete %r12b
xorl %r13d, %r13d
cmpq $0x6, %r9
sete %r13b
movq -0x78(%rbp), %r10
movq -0xa0(%rbp), %r11
subq $0x1, %r11
jb 0x16e5
movq -0x8(%r10), %rax
leaq 0x19cb(%rip), %rdx      # 0x3070
movslq (%rdx,%r9,4), %rbx
xorl %edx, %edx
divq %rbx
movslq %edx, %rax
movl (%r10), %edx
cmpl %edx, (%rcx,%rax,4)
jne 0x16d8
addl -0x38(%rbp), %esi
movl -0x58(%rbp), %eax
addl %eax, -0x3c(%rbp)
addl %r8d, -0x40(%rbp)
addl %r14d, -0x44(%rbp)
addl %r15d, -0x48(%rbp)
addl %r12d, -0x4c(%rbp)
addl %r13d, -0x60(%rbp)
jmp 0x16df
shlq $0x2, %rax
movl %edx, (%rcx,%rax)
addq $0x10, %r10
jmp 0x1694
incq %r9
movq -0x68(%rbp), %r15
jmp 0x161e
leaq -0x390(%rbp), %rdi
callq 0x1160
leaq 0x1916(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1900(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x3c(%rbp), %esi
callq 0x1160
leaq 0x18e1(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x18cb(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x40(%rbp), %esi
callq 0x1160
leaq 0x18ac(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1896(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x44(%rbp), %esi
callq 0x1160
leaq 0x1877(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1861(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x48(%rbp), %esi
callq 0x1160
leaq 0x1842(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x182c(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x4c(%rbp), %esi
callq 0x1160
leaq 0x180d(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x17f7(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x60(%rbp), %esi
callq 0x1160
leaq 0x17d8(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x17bf(%rip), %rsi      # 0x301c
movq %rax, %rdi
callq 0x10d0
leaq -0xe8(%rbp), %rdx
movl $0x3, (%rdx)
leaq -0x150(%rbp), %rdi
leaq -0x138(%rbp), %rcx
movq -0x30(%rbp), %rsi
callq 0x23ae
movq -0x150(%rbp), %rcx
movq -0x148(%rbp), %rdx
leaq 0x8(%r15), %rax
movq %rax, -0xa8(%rbp)
xorl %r9d, %r9d
xorl %esi, %esi
xorl %ebx, %ebx
movl $0x0, -0x78(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq %rdx, -0xc8(%rbp)
movq %rcx, %rax
cmpq $0x7, %r9
jne 0x18eb
jmp 0x1a01
movl $0x3, (%rax)
addq $0x4, %rax
cmpq %rdx, %rax
jne 0x18e1
xorl %eax, %eax
testq %r9, %r9
sete %al
movl %eax, -0x38(%rbp)
xorl %eax, %eax
cmpq $0x1, %r9
sete %al
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpq $0x2, %r9
sete %al
movl %eax, -0x60(%rbp)
xorl %eax, %eax
cmpq $0x3, %r9
sete %al
movl %eax, -0x4c(%rbp)
xorl %r15d, %r15d
cmpq $0x4, %r9
sete %r15b
xorl %r12d, %r12d
cmpq $0x5, %r9
sete %r12b
xorl %edi, %edi
cmpq $0x6, %r9
sete %dil
movq -0xa8(%rbp), %r10
movq -0xa0(%rbp), %r11
subq $0x1, %r11
jb 0x19ee
movq -0x8(%r10), %rax
leaq 0x170e(%rip), %rdx      # 0x3070
movslq (%rdx,%r9,4), %r13
xorl %edx, %edx
divq %r13
movslq %edx, %rax
movl (%rcx,%rax,4), %r8d
movl (%r10), %r13d
cmpl $0x1, %r13d
jne 0x1986
movl %r8d, %edx
andl $-0x2, %edx
cmpl $0x2, %edx
je 0x1991
testl %r13d, %r13d
jne 0x19ae
cmpl $0x1, %r8d
ja 0x19ae
addl -0x38(%rbp), %esi
addl -0x58(%rbp), %ebx
movl -0x60(%rbp), %edx
addl %edx, -0x78(%rbp)
movl -0x4c(%rbp), %edx
addl %edx, -0x3c(%rbp)
addl %r15d, -0x40(%rbp)
addl %r12d, -0x44(%rbp)
addl %edi, -0x48(%rbp)
shlq $0x2, %rax
cmpl $0x1, %r13d
sete %dl
cmpl $0x3, %r8d
setne %r14b
andb %dl, %r14b
movzbl %r14b, %edx
addl %r8d, %edx
testl %r13d, %r13d
sete %r8b
testl %edx, %edx
setne %r14b
andb %r8b, %r14b
movzbl %r14b, %r8d
subl %r8d, %edx
movl %edx, (%rcx,%rax)
addq $0x10, %r10
jmp 0x194d
incq %r9
movq -0x68(%rbp), %r15
movq -0xc8(%rbp), %rdx
jmp 0x18d3
leaq -0x390(%rbp), %rdi
callq 0x1160
leaq 0x1606(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x15f0(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x1160
leaq 0x15d2(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x15bc(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x78(%rbp), %esi
callq 0x1160
leaq 0x159d(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1587(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x3c(%rbp), %esi
callq 0x1160
leaq 0x1568(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1552(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x40(%rbp), %esi
callq 0x1160
leaq 0x1533(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x151d(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x44(%rbp), %esi
callq 0x1160
leaq 0x14fe(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x14e8(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x48(%rbp), %esi
callq 0x1160
leaq 0x14c9(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x14b0(%rip), %rsi      # 0x301c
movq %rax, %rdi
callq 0x10d0
leaq -0x138(%rbp), %rdx
movl $0x3, (%rdx)
leaq -0xe8(%rbp), %rdi
leaq -0x120(%rbp), %rcx
movl $0x800, %esi            # imm = 0x800
callq 0x23ae
leaq 0x8(%r15), %rax
movq %rax, -0xf0(%rbp)
pushq $0x3
popq %rdx
movsd 0x1459(%rip), %xmm0     # 0x3008
movsd %xmm0, -0x38(%rbp)
xorl %ebx, %ebx
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl $0x0, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
cmpl $0xc, %edx
je 0x1da1
movq -0xe8(%rbp), %rax
movq -0xe0(%rbp), %rcx
cmpq %rcx, %rax
je 0x1c28
movl $0x3, (%rax)
addq $0x4, %rax
jmp 0x1c17
xorl %eax, %eax
cmpl $0x3, %edx
sete %al
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x4, %edx
sete %al
movl %eax, -0x60(%rbp)
xorl %eax, %eax
cmpl $0x5, %edx
sete %al
movl %eax, -0x4c(%rbp)
xorl %eax, %eax
cmpl $0x6, %edx
sete %al
movl %eax, -0x48(%rbp)
xorl %eax, %eax
cmpl $0x7, %edx
sete %al
movl %eax, -0x44(%rbp)
xorl %eax, %eax
cmpl $0x8, %edx
sete %al
movl %eax, -0x40(%rbp)
xorl %eax, %eax
cmpl $0x9, %edx
sete %al
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0xa, %edx
sete %al
movl %eax, -0x78(%rbp)
xorl %eax, %eax
movl %edx, -0xcc(%rbp)
cmpl $0xb, %edx
sete %al
movl %eax, -0xc8(%rbp)
movq -0xf0(%rbp), %r12
movq -0xa0(%rbp), %r14
xorl %r15d, %r15d
subq $0x1, %r14
jb 0x1d7e
movl -0x8(%r12), %r13d
movsd -0x38(%rbp), %xmm0
callq 0x10b0
cvttsd2si %xmm0, %eax
decl %eax
andl %r15d, %eax
xorl %r13d, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movq -0xe8(%rbp), %rcx
movl (%rcx,%rax,4), %edx
movl (%r12), %esi
cmpl $0x1, %esi
jne 0x1cec
movl %edx, %edi
andl $-0x2, %edi
cmpl $0x2, %edi
je 0x1cf5
testl %esi, %esi
jne 0x1d3d
cmpl $0x1, %edx
ja 0x1d3d
addl -0x58(%rbp), %ebx
movl -0x60(%rbp), %edi
addl %edi, -0x84(%rbp)
movl -0x4c(%rbp), %edi
addl %edi, -0x88(%rbp)
movl -0x48(%rbp), %edi
addl %edi, -0x8c(%rbp)
movl -0x44(%rbp), %edi
addl %edi, -0x90(%rbp)
movl -0x40(%rbp), %edi
addl %edi, -0x94(%rbp)
movl -0x3c(%rbp), %edi
addl %edi, -0xa8(%rbp)
movl -0x78(%rbp), %edi
addl %edi, -0x7c(%rbp)
movl -0xc8(%rbp), %edi
addl %edi, -0x80(%rbp)
cmpl $0x1, %esi
sete %dil
cmpl $0x3, %edx
setne %r8b
andb %dil, %r8b
movzbl %r8b, %edi
addl %edx, %edi
testl %esi, %esi
sete %dl
testl %edi, %edi
setne %sil
andb %dl, %sil
movzbl %sil, %edx
subl %edx, %edi
movl %edi, (%rcx,%rax,4)
addq %r15, %r15
movl (%r12), %eax
orq %rax, %r15
addq $0x10, %r12
jmp 0x1ca5
movsd -0x38(%rbp), %xmm0
addsd 0x1285(%rip), %xmm0     # 0x3010
movsd %xmm0, -0x38(%rbp)
movl -0xcc(%rbp), %edx
incl %edx
movq -0x68(%rbp), %r15
jmp 0x1c00
leaq -0x390(%rbp), %rdi
movl %ebx, %esi
callq 0x1160
leaq 0x1264(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x124e(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x84(%rbp), %esi
callq 0x1160
leaq 0x122c(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1216(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x88(%rbp), %esi
callq 0x1160
leaq 0x11f4(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x11de(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x8c(%rbp), %esi
callq 0x1160
leaq 0x11bc(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x11a6(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x90(%rbp), %esi
callq 0x1160
leaq 0x1184(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x116e(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x94(%rbp), %esi
callq 0x1160
leaq 0x114c(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1136(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0xa8(%rbp), %esi
callq 0x1160
leaq 0x1114(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x10fe(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x7c(%rbp), %esi
callq 0x1160
leaq 0x10df(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x10c9(%rip), %rsi      # 0x301f
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movl -0x80(%rbp), %esi
callq 0x1160
leaq 0x10aa(%rip), %rsi      # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0x1091(%rip), %rsi      # 0x301c
movq %rax, %rdi
callq 0x10d0
leaq -0x120(%rbp), %rdx
movl $0x3, (%rdx)
leaq -0x138(%rbp), %rdi
leaq -0x108(%rbp), %rcx
movl $0x800, %esi            # imm = 0x800
callq 0x23ae
leaq -0x108(%rbp), %rdx
movl $0x3, (%rdx)
leaq -0x120(%rbp), %rdi
leaq -0xd0(%rbp), %rcx
movl $0x800, %esi            # imm = 0x800
callq 0x23ae
leaq -0xd0(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x108(%rbp), %rdi
leaq -0x69(%rbp), %rcx
movl $0x800, %esi            # imm = 0x800
callq 0x23ae
movq -0x120(%rbp), %rsi
movq -0x138(%rbp), %rcx
movq -0x108(%rbp), %rdx
addq $0x8, %r15
movl $0x0, -0x38(%rbp)
xorl %r8d, %r8d
subq $0x1, -0xa0(%rbp)
jb 0x2167
movq -0x8(%r15), %r9
movl %r8d, %r10d
xorl %r9d, %r10d
andl $0x7ff, %r9d            # imm = 0x7FF
andl $0x7ff, %r10d           # imm = 0x7FF
leal (,%r9,4), %edi
movl (%rsi,%rdi), %ebx
movl (%rcx,%r10,4), %r14d
movl (%rdx,%rdi), %r11d
movl %ebx, %r12d
andl $0x2, %r12d
movl %r14d, %r13d
andl $0x2, %r13d
movq %r15, %rax
cmpl %r12d, %r13d
jne 0x20b4
movl (%r15), %r15d
cmpl $0x1, %r15d
sete %dil
testl %r12d, %r12d
setne %r13b
andb %dil, %r13b
orl %r15d, %r12d
sete %dil
orb %r13b, %dil
movzbl %dil, %edi
addl %edi, -0x38(%rbp)
cmpl $0x1, %r15d
je 0x20db
testl %r15d, %r15d
jne 0x20f8
subl $0x1, %r14d
movl $0x0, %edi
cmovbl %edi, %r14d
subl $0x1, %ebx
cmovbl %edi, %ebx
jmp 0x20f8
movl (%r15), %r15d
cmpl $0x1, %r11d
jg 0x211a
cmpl $0x1, %r15d
setne %r12b
testl %r13d, %r13d
sete %dil
orl %r15d, %r13d
je 0x213b
orb %r12b, %dil
je 0x213b
incl %r11d
jmp 0x2094
leal 0x1(%r14), %edi
cmpl $0x3, %r14d
cmovel %r14d, %edi
leal 0x1(%rbx), %r14d
cmpl $0x3, %ebx
cmovel %ebx, %r14d
movl %r14d, %ebx
movl %edi, %r14d
movq %rax, %r15
movl %r14d, (%rcx,%r10,4)
shll $0x2, %r9d
movl %ebx, (%rsi,%r9)
addl %r8d, %r8d
orl (%rax), %r8d
movl %r11d, (%rdx,%r9)
addq $0x10, %r15
jmp 0x201f
cmpl $0x1, %r15d
setne %r13b
testl %r12d, %r12d
sete %dil
orl %r15d, %r12d
je 0x2150
orb %r13b, %dil
je 0x2150
decl %r11d
jmp 0x2094
incl -0x38(%rbp)
subl $0x1, %r11d
movl $0x0, %edi
cmovbl %edi, %r11d
jmp 0x2094
incl -0x38(%rbp)
leal 0x1(%r11), %edi
cmpl $0x3, %r11d
cmovel %r11d, %edi
movl %edi, %r11d
jmp 0x2094
leaq -0x390(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x1160
leaq 0xe9d(%rip), %rsi       # 0x301a
movq %rax, %rdi
callq 0x10d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x1160
leaq 0xe87(%rip), %rsi       # 0x301f
movq %rax, %rdi
callq 0x10d0
leaq -0x390(%rbp), %rdi
callq 0x1120
leaq -0x108(%rbp), %rdi
callq 0x2532
leaq -0x120(%rbp), %rdi
callq 0x2532
leaq -0x138(%rbp), %rdi
callq 0x2532
leaq -0xe8(%rbp), %rdi
callq 0x2532
leaq -0x150(%rbp), %rdi
callq 0x2532
leaq -0x170(%rbp), %rdi
callq 0x2448
leaq -0x390(%rbp), %rdi
callq 0x1130
leaq -0x598(%rbp), %rdi
callq 0x1040
leaq -0xc0(%rbp), %rdi
callq 0x232a
leaq -0x190(%rbp), %rdi
callq 0x1070
xorl %eax, %eax
addq $0x578, %rsp            # imm = 0x578
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, -0xc0(%rbp)
leaq 0xddc(%rip), %rdi       # 0x3022
callq 0x1080
movq %rax, %rbx
movq -0x68(%rbp), %r15
jmp 0x22f6
movq %rax, %rbx
jmp 0x228a
movq %rax, %rbx
jmp 0x2296
jmp 0x22b3
jmp 0x22a9
jmp 0x22ae
jmp 0x22a4
jmp 0x2273
movq %rax, %rbx
jmp 0x2309
movq %rax, %rbx
jmp 0x22fd
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x2532
leaq -0x120(%rbp), %rdi
callq 0x2532
leaq -0x138(%rbp), %rdi
callq 0x2532
jmp 0x22b6
movq %rax, %rbx
jmp 0x22da
movq %rax, %rbx
jmp 0x22c2
movq %rax, %rbx
jmp 0x22ce
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x2532
leaq -0x150(%rbp), %rdi
callq 0x2532
leaq -0x170(%rbp), %rdi
callq 0x2448
leaq -0x390(%rbp), %rdi
callq 0x1130
jmp 0x22fd
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq %r15, -0xc0(%rbp)
leaq -0x598(%rbp), %rdi
callq 0x1040
leaq -0xc0(%rbp), %rdi
callq 0x232a
leaq -0x190(%rbp), %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x1170
nop