// File: /workspace/github_cpp_makefile_star2_O3/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 $0x518, %rsp            # imm = 0x518
movq %rsi, %r14
leaq -0x108(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq $0x0, -0x8(%rbx)
movb $0x0, (%rbx)
movq 0x8(%rsi), %rsi
leaq -0x538(%rbp), %rdi
movl $0x8, %edx
callq 0x11a0
movq %r14, -0x58(%rbp)
movq $0x0, -0x30(%rbp)
xorl %r13d, %r13d
movq $0x0, -0x60(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x538(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x520(%rbp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, -0x520(%rbp,%rax)
leaq -0x538(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x1120
movq %rax, %rdi
leaq -0x118(%rbp), %rsi
callq 0x1130
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x14b4
movq -0xf8(%rbp), %r14
leaq -0x118(%rbp), %rdi
leaq 0x1c43(%rip), %rsi      # 0x3018
callq 0x1050
xorl %r15d, %r15d
testl %eax, %eax
sete %r15b
movq -0x60(%rbp), %rax
cmpq %r13, %rax
movq -0x48(%rbp), %rbx
je 0x13fc
movq %r14, (%rax)
movl %r15d, 0x8(%rax)
jmp 0x149f
movq %r13, %r12
subq %rbx, %r12
movabsq $0x7ffffffffffffff0, %rax # imm = 0x7FFFFFFFFFFFFFF0
cmpq %rax, %r12
je 0x243b
movq %r12, -0x60(%rbp)
sarq $0x4, %r12
movl $0x1, %eax
cmpq %rbx, %r13
movabsq $0x7ffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFF
je 0x1434
movq %r12, %rax
leaq (%rax,%r12), %r13
cmpq %rcx, %r13
jb 0x1440
movq %rcx, %r13
addq %r12, %rax
cmovbq %rcx, %r13
testq %r13, %r13
je 0x145d
movq %r13, %rdi
shlq $0x4, %rdi
callq 0x10f0
movq %rax, %rbx
jmp 0x145f
xorl %ebx, %ebx
shlq $0x4, %r12
movq %r14, (%rbx,%r12)
movl %r15d, 0x8(%rbx,%r12)
movq -0x60(%rbp), %rdx
testq %rdx, %rdx
movq -0x48(%rbp), %r14
jle 0x1484
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1170
testq %r14, %r14
je 0x1491
movq %r14, %rdi
callq 0x10e0
movq -0x60(%rbp), %rax
addq %rbx, %rax
shlq $0x4, %r13
addq %rbx, %r13
movq %rbx, -0x48(%rbp)
addq $0x10, %rax
movq %rax, -0x60(%rbp)
incq -0x30(%rbp)
jmp 0x136d
leaq -0x538(%rbp), %rdi
movq -0x48(%rbp), %r12
callq 0x1030
movq -0x60(%rbp), %rax
movq %rax, %r13
subq %r12, %r13
sarq $0x4, %r13
cmpq %r12, %rax
je 0x150c
cmpq $0x1, %r13
movq %r13, %rax
adcq $0x0, %rax
leaq 0x8(%r12), %rcx
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x1, (%rcx)
sete %dl
setne %sil
addl %esi, %r14d
addl %edx, %r15d
addq $0x10, %rcx
decq %rax
jne 0x14ed
jmp 0x1512
xorl %r14d, %r14d
xorl %r15d, %r15d
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x330(%rbp), %rdi
movl $0x10, %edx
callq 0x1100
leaq -0x330(%rbp), %rdi
movl %r15d, %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1ad6(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1ab8(%rip), %rsi      # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0x330(%rbp), %rdi
movl %r14d, %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1a90(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1a72(%rip), %rsi      # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0xf0(%rbp), %rdx
movl $0x1, (%rdx)
leaq -0x130(%rbp), %rdi
leaq -0xd0(%rbp), %rcx
movq -0x30(%rbp), %rsi
callq 0x2514
movq -0x130(%rbp), %rcx
movq -0x128(%rbp), %rdi
cmpq $0x1, %r13
adcq $0x0, %r13
leaq 0x8(%r12), %rax
movq %rax, -0x80(%rbp)
xorl %edx, %edx
xorl %esi, %esi
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq %r13, -0xb0(%rbp)
cmpq %rdi, %rcx
je 0x1646
movq %rcx, %rax
movl $0x1, (%rax)
addq $0x4, %rax
cmpq %rdi, %rax
jne 0x1637
cmpq %r12, -0x60(%rbp)
movq %rdx, -0x88(%rbp)
je 0x16fb
leaq 0x1a12(%rip), %rax      # 0x3070
movslq (%rax,%rdx,4), %r10
xorl %eax, %eax
testq %rdx, %rdx
sete %al
movl %eax, -0x58(%rbp)
xorl %r8d, %r8d
cmpq $0x1, %rdx
sete %r8b
xorl %r14d, %r14d
cmpq $0x2, %rdx
sete %r14b
xorl %r15d, %r15d
cmpq $0x3, %rdx
sete %r15b
xorl %r9d, %r9d
cmpq $0x4, %rdx
sete %r9b
xorl %r12d, %r12d
cmpq $0x5, %rdx
sete %r12b
xorl %r13d, %r13d
cmpq $0x6, %rdx
sete %r13b
movq -0xb0(%rbp), %rbx
movq -0x80(%rbp), %r11
movq -0x8(%r11), %rax
xorl %edx, %edx
divq %r10
movslq %edx, %rax
movl (%r11), %edx
cmpl %edx, (%rcx,%rax,4)
jne 0x16eb
addl -0x58(%rbp), %esi
addl %r8d, -0x3c(%rbp)
addl %r14d, -0x4c(%rbp)
addl %r15d, -0x68(%rbp)
addl %r9d, -0x70(%rbp)
addl %r12d, -0x34(%rbp)
addl %r13d, -0x38(%rbp)
jmp 0x16f2
shlq $0x2, %rax
movl %edx, (%rcx,%rax)
addq $0x10, %r11
decq %rbx
jne 0x16ba
movq -0x88(%rbp), %rdx
incq %rdx
cmpq $0x7, %rdx
movq -0x48(%rbp), %r12
jne 0x162f
leaq -0x330(%rbp), %rdi
callq 0x1180
movq %rax, %rbx
leaq 0x18f1(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x18d3(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x3c(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x18ac(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x188e(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x4c(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1867(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1849(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x68(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1822(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1804(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x70(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x17dd(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x17bf(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x34(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1798(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x177a(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x38(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1753(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1735(%rip), %rsi      # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0xd0(%rbp), %rdx
movl $0x3, (%rdx)
leaq -0xf0(%rbp), %rdi
leaq -0x71(%rbp), %rcx
movq -0x30(%rbp), %rsi
callq 0x259c
movq -0x60(%rbp), %rdx
movq -0xf0(%rbp), %rcx
movq -0xe8(%rbp), %rdi
leaq 0x8(%r12), %rax
movq %rax, -0xb8(%rbp)
xorl %r8d, %r8d
movl $0x0, -0x80(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x88(%rbp)
xorl %ebx, %ebx
xorl %esi, %esi
movq %rdi, -0xc0(%rbp)
cmpq %rdi, %rcx
je 0x197e
movq %rcx, %rax
movl $0x3, (%rax)
addq $0x4, %rax
cmpq %rdi, %rax
jne 0x196f
cmpq %r12, %rdx
movq %r8, -0xc8(%rbp)
je 0x1a8a
leaq 0x16db(%rip), %rax      # 0x3070
movslq (%rax,%r8,4), %r10
xorl %eax, %eax
testq %r8, %r8
sete %al
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpq $0x1, %r8
sete %al
movl %eax, -0x70(%rbp)
xorl %eax, %eax
cmpq $0x2, %r8
sete %al
movl %eax, -0x68(%rbp)
xorl %eax, %eax
cmpq $0x3, %r8
sete %al
movl %eax, -0x4c(%rbp)
xorl %r15d, %r15d
cmpq $0x4, %r8
sete %r15b
xorl %r12d, %r12d
cmpq $0x5, %r8
sete %r12b
xorl %edi, %edi
cmpq $0x6, %r8
sete %dil
movq -0xb8(%rbp), %r13
movq -0xb0(%rbp), %r11
movq -0x8(%r13), %rax
xorl %edx, %edx
divq %r10
movslq %edx, %rax
movl (%rcx,%rax,4), %r9d
movl (%r13), %r8d
cmpl $0x1, %r8d
jne 0x1a1b
movl %r9d, %edx
andl $-0x2, %edx
cmpl $0x2, %edx
je 0x1a26
testl %r8d, %r8d
jne 0x1a46
cmpl $0x1, %r9d
ja 0x1a46
addl -0x58(%rbp), %esi
addl -0x70(%rbp), %ebx
movl -0x68(%rbp), %edx
addl %edx, -0x88(%rbp)
movl -0x4c(%rbp), %edx
addl %edx, -0x34(%rbp)
addl %r15d, -0x38(%rbp)
addl %r12d, -0x3c(%rbp)
addl %edi, -0x80(%rbp)
shlq $0x2, %rax
cmpl $0x1, %r8d
sete %dl
cmpl $0x3, %r9d
setne %r14b
andb %dl, %r14b
movzbl %r14b, %edx
addl %r9d, %edx
testl %r8d, %r8d
sete %r8b
testl %edx, %edx
setne %r9b
andb %r8b, %r9b
movzbl %r9b, %r8d
subl %r8d, %edx
movl %edx, (%rcx,%rax)
addq $0x10, %r13
decq %r11
jne 0x19f6
movq -0xc8(%rbp), %r8
incq %r8
cmpq $0x7, %r8
movq -0x48(%rbp), %r12
movq -0x60(%rbp), %rdx
movq -0xc0(%rbp), %rdi
jne 0x1967
leaq -0x330(%rbp), %rdi
callq 0x1180
movq %rax, %r14
leaq 0x1557(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %r14
leaq 0x1539(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %r14, %rdi
movl %ebx, %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1513(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x14f5(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x88(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x14cb(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x14ad(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x34(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1486(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1468(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x38(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1441(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1423(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x3c(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x13fc(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x13de(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x80(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x13b7(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1399(%rip), %rsi      # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movl $0x2000, %edi           # imm = 0x2000
callq 0x10f0
movq %rax, -0x68(%rbp)
xorl %eax, %eax
movq -0x68(%rbp), %rcx
movl $0x3, (%rcx,%rax)
addq $0x4, %rax
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x1ca4
leaq 0x8(%r12), %rax
movq %rax, -0xd8(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x3, %edx
movsd 0x1330(%rip), %xmm0     # 0x3008
movsd %xmm0, -0x70(%rbp)
movl $0x0, -0x90(%rbp)
movl $0x0, -0x8c(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa0(%rbp)
movl $0x0, -0x9c(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
xorl %eax, %eax
movq -0x68(%rbp), %rcx
movl $0x3, (%rcx,%rax)
addq $0x4, %rax
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x1d33
cmpq %r12, -0x60(%rbp)
movl %edx, -0xcc(%rbp)
je 0x1ec1
xorl %eax, %eax
cmpl $0x3, %edx
sete %al
movl %eax, -0x4c(%rbp)
xorl %eax, %eax
cmpl $0x4, %edx
sete %al
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x5, %edx
sete %al
movl %eax, -0x38(%rbp)
xorl %eax, %eax
cmpl $0x6, %edx
sete %al
movl %eax, -0x34(%rbp)
xorl %eax, %eax
cmpl $0x7, %edx
sete %al
movl %eax, -0x88(%rbp)
xorl %eax, %eax
cmpl $0x8, %edx
sete %al
movl %eax, -0x80(%rbp)
xorl %eax, %eax
cmpl $0x9, %edx
sete %al
movl %eax, -0xc8(%rbp)
xorl %eax, %eax
cmpl $0xa, %edx
sete %al
movl %eax, -0xc0(%rbp)
xorl %eax, %eax
cmpl $0xb, %edx
sete %al
movl %eax, -0xb8(%rbp)
movq -0xb0(%rbp), %r14
movq -0xd8(%rbp), %r12
xorl %r15d, %r15d
movq -0x68(%rbp), %r13
movl -0x8(%r12), %ebx
movsd -0x70(%rbp), %xmm0
callq 0x10d0
cvttsd2si %xmm0, %eax
decl %eax
andl %r15d, %eax
xorl %ebx, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movl (%r13,%rax,4), %ecx
movl (%r12), %edx
cmpl $0x1, %edx
jne 0x1e11
movl %ecx, %esi
andl $-0x2, %esi
cmpl $0x2, %esi
je 0x1e1a
testl %edx, %edx
jne 0x1e79
cmpl $0x1, %ecx
ja 0x1e79
movl -0x4c(%rbp), %esi
addl %esi, -0x94(%rbp)
movl -0x3c(%rbp), %esi
addl %esi, -0x98(%rbp)
movl -0x38(%rbp), %esi
addl %esi, -0x9c(%rbp)
movl -0x34(%rbp), %esi
addl %esi, -0xa0(%rbp)
movl -0x88(%rbp), %esi
addl %esi, -0xa4(%rbp)
movl -0x80(%rbp), %esi
addl %esi, -0xa8(%rbp)
movl -0xc8(%rbp), %esi
addl %esi, -0x8c(%rbp)
movl -0xc0(%rbp), %esi
addl %esi, -0x90(%rbp)
movq -0x58(%rbp), %rsi
addl -0xb8(%rbp), %esi
movq %rsi, -0x58(%rbp)
cmpl $0x1, %edx
sete %sil
cmpl $0x3, %ecx
setne %dil
andb %sil, %dil
movzbl %dil, %esi
addl %ecx, %esi
testl %edx, %edx
sete %cl
testl %esi, %esi
setne %dl
andb %cl, %dl
movzbl %dl, %ecx
subl %ecx, %esi
movq -0x68(%rbp), %r13
movl %esi, (%r13,%rax,4)
addq %r15, %r15
movl (%r12), %eax
orq %rax, %r15
addq $0x10, %r12
decq %r14
jne 0x1dda
movsd -0x70(%rbp), %xmm0
addsd 0x1142(%rip), %xmm0     # 0x3010
movsd %xmm0, -0x70(%rbp)
movl -0xcc(%rbp), %edx
incl %edx
cmpl $0xc, %edx
movq -0x48(%rbp), %r12
jne 0x1d2d
leaq -0x330(%rbp), %rdi
movl -0x94(%rbp), %esi
callq 0x1180
movq %rax, %r13
leaq 0x1116(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %r13, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %r13
leaq 0x10f8(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %r13, %rdi
movl -0x98(%rbp), %esi
callq 0x1180
movq %rax, %r15
leaq 0x10ce(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %r15
leaq 0x10b0(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %r15, %rdi
movl -0x9c(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1086(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1068(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0xa0(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x103e(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1020(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0xa4(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xff6(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xfd8(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0xa8(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xfae(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xf90(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x8c(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xf66(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xf48(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x90(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xf1e(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xf00(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x58(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xed8(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0xeba(%rip), %rsi       # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movl $0x2000, %edi           # imm = 0x2000
callq 0x10f0
movq %rax, %rbx
xorl %eax, %eax
movl $0x3, (%rbx,%rax)
addq $0x4, %rax
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x217e
movl $0x2000, %edi           # imm = 0x2000
callq 0x10f0
movq %rax, %r14
xorl %eax, %eax
movl $0x3, (%r14,%rax)
addq $0x4, %rax
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x21a0
movl $0x2000, %edi           # imm = 0x2000
callq 0x10f0
movq %rax, %r15
xorl %r13d, %r13d
movl $0x2000, %edx           # imm = 0x2000
movq %rax, %rdi
xorl %esi, %esi
callq 0x1090
cmpq %r12, -0x60(%rbp)
je 0x232b
leaq 0x8(%r12), %rax
xorl %edx, %edx
xorl %r13d, %r13d
movq %r15, -0x58(%rbp)
movq -0x8(%rax), %rsi
movl %edx, %edi
xorl %esi, %edi
andl $0x7ff, %esi            # imm = 0x7FF
andl $0x7ff, %edi            # imm = 0x7FF
leal (,%rsi,4), %ecx
movl (%r14,%rcx), %r9d
movl (%rbx,%rdi,4), %r10d
movl (%r15,%rcx), %r8d
movl %r9d, %r12d
andl $0x2, %r12d
movl %r10d, %ecx
andl $0x2, %ecx
cmpl %r12d, %ecx
jne 0x2271
movl (%rax), %r11d
cmpl $0x1, %r11d
sete %cl
testl %r12d, %r12d
setne %r15b
andb %cl, %r15b
orl %r11d, %r12d
sete %cl
orb %r15b, %cl
movzbl %cl, %ecx
addl %ecx, %r13d
movq -0x48(%rbp), %r12
cmpl $0x1, %r11d
je 0x2297
testl %r11d, %r11d
movq -0x58(%rbp), %r15
jne 0x22b9
subl $0x1, %r10d
movl $0x0, %ecx
cmovbl %ecx, %r10d
subl $0x1, %r9d
cmovbl %ecx, %r9d
jmp 0x22b9
movl (%rax), %r11d
cmpl $0x1, %r8d
jg 0x22df
cmpl $0x1, %r11d
setne %r12b
testl %ecx, %ecx
sete %r15b
orl %r11d, %ecx
je 0x22ff
orb %r12b, %r15b
je 0x22ff
incl %r8d
jmp 0x2247
leal 0x1(%r10), %ecx
cmpl $0x3, %r10d
cmovel %r10d, %ecx
leal 0x1(%r9), %r10d
cmpl $0x3, %r9d
cmovel %r9d, %r10d
movl %r10d, %r9d
movl %ecx, %r10d
movq -0x58(%rbp), %r15
movl %r10d, (%rbx,%rdi,4)
shll $0x2, %esi
movl %r9d, (%r14,%rsi)
addl %edx, %edx
orl (%rax), %edx
movl %r8d, (%r15,%rsi)
addq $0x10, %rax
decq -0xb0(%rbp)
jne 0x21eb
jmp 0x232b
cmpl $0x1, %r11d
setne %cl
testl %r12d, %r12d
sete %r15b
orl %r11d, %r12d
je 0x2314
orb %cl, %r15b
je 0x2314
decl %r8d
jmp 0x2247
incl %r13d
subl $0x1, %r8d
movl $0x0, %ecx
cmovbl %ecx, %r8d
jmp 0x2247
incl %r13d
leal 0x1(%r8), %ecx
cmpl $0x3, %r8d
cmovel %r8d, %ecx
movl %ecx, %r8d
jmp 0x2247
leaq -0x330(%rbp), %rdi
movl %r13d, %esi
callq 0x1180
movq %rax, %r13
leaq 0xcd6(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %r13, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0xcbb(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0x330(%rbp), %rdi
callq 0x1140
movq %r15, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x10e0
movq %rbx, %rdi
callq 0x10e0
movq -0x68(%rbp), %rdi
callq 0x10e0
movq -0xf0(%rbp), %rdi
testq %rdi, %rdi
je 0x23af
callq 0x10e0
movq -0x130(%rbp), %rdi
testq %rdi, %rdi
leaq -0x108(%rbp), %rbx
je 0x23c7
callq 0x10e0
movq 0x2c0a(%rip), %rax      # 0x4fd8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x328(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x330(%rbp,%rcx)
callq 0x10b0
leaq -0x238(%rbp), %rdi
callq 0x1060
leaq -0x538(%rbp), %rdi
callq 0x1040
testq %r12, %r12
je 0x2416
movq %r12, %rdi
callq 0x10e0
movq -0x118(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2427
callq 0x10e0
xorl %eax, %eax
addq $0x518, %rsp            # imm = 0x518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbe0(%rip), %rdi       # 0x3022
movq %rbx, %r12
callq 0x1080
movq %rax, %r13
jmp 0x2471
movq %rax, %r13
jmp 0x2479
jmp 0x2497
jmp 0x248d
jmp 0x2492
jmp 0x2483
jmp 0x24d3
movq %rax, %r13
jmp 0x24fa
movq %rax, %r13
movq %r15, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x10e0
movq %rbx, %rdi
callq 0x10e0
jmp 0x249a
movq %rax, %r13
jmp 0x24c5
movq %rax, %r13
jmp 0x24da
movq %rax, %r13
jmp 0x24a3
movq %rax, %r13
jmp 0x24b4
movq %rax, %r13
movq -0x68(%rbp), %rdi
callq 0x10e0
movq -0xf0(%rbp), %rdi
testq %rdi, %rdi
je 0x24b4
callq 0x10e0
movq -0x130(%rbp), %rdi
testq %rdi, %rdi
je 0x24c5
callq 0x10e0
leaq -0x330(%rbp), %rdi
callq 0x1150
jmp 0x24d6
movq %rax, %r13
movq -0x48(%rbp), %r12
leaq -0x538(%rbp), %rdi
callq 0x1040
testq %r12, %r12
leaq -0x108(%rbp), %rbx
je 0x24fa
movq %r12, %rdi
callq 0x10e0
movq -0x118(%rbp), %rdi
cmpq %rbx, %rdi
je 0x250b
callq 0x10e0
movq %r13, %rdi
callq 0x1190
nop