// File: /workspace/github_cpp_makefile_star2_O1/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 $0x528, %rsp            # imm = 0x528
movq %rsi, %r14
leaq -0x118(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq $0x0, -0x8(%rbx)
movb $0x0, (%rbx)
movq 0x8(%rsi), %rsi
leaq -0x548(%rbp), %rdi
movl $0x8, %edx
callq 0x11a0
movq %r14, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
xorl %r14d, %r14d
movq $0x0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x548(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x530(%rbp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, -0x530(%rbp,%rax)
leaq -0x548(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x1120
movq %rax, %rdi
leaq -0x128(%rbp), %rsi
callq 0x1130
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x14bc
movq -0x108(%rbp), %rbx
leaq -0x128(%rbp), %rdi
leaq 0x1c43(%rip), %rsi      # 0x3018
callq 0x1050
xorl %r12d, %r12d
testl %eax, %eax
sete %r12b
movq -0x70(%rbp), %rcx
cmpq %r14, %rcx
movq -0x60(%rbp), %r13
je 0x13fc
movq %rbx, (%rcx)
movl %r12d, 0x8(%rcx)
jmp 0x14a7
movq %rbx, -0x40(%rbp)
movq %rcx, %rbx
subq %r13, %rbx
movabsq $0x7ffffffffffffff0, %rax # imm = 0x7FFFFFFFFFFFFFF0
cmpq %rax, %rbx
je 0x247c
movq %rbx, %r15
sarq $0x4, %r15
movl $0x1, %eax
cmpq %r13, %rcx
movabsq $0x7ffffffffffffff, %r14 # imm = 0x7FFFFFFFFFFFFFF
je 0x1437
movq %r15, %rax
leaq (%rax,%r15), %rcx
cmpq %r14, %rcx
jb 0x1443
movq %r14, %rcx
addq %r15, %rax
jb 0x144b
movq %rcx, %r14
testq %r14, %r14
je 0x1461
movq %r14, %rdi
shlq $0x4, %rdi
callq 0x10f0
movq %rax, %r13
jmp 0x1464
xorl %r13d, %r13d
shlq $0x4, %r15
movq -0x40(%rbp), %rax
movq %rax, (%r13,%r15)
movl %r12d, 0x8(%r13,%r15)
testq %rbx, %rbx
movq -0x60(%rbp), %r15
jle 0x148d
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1170
testq %r15, %r15
je 0x149a
movq %r15, %rdi
callq 0x10e0
addq %r13, %rbx
shlq $0x4, %r14
addq %r13, %r14
movq %rbx, %rcx
movq %r13, -0x60(%rbp)
addq $0x10, %rcx
movq %rcx, -0x70(%rbp)
incq -0x30(%rbp)
jmp 0x136d
leaq -0x548(%rbp), %rdi
movq -0x60(%rbp), %r15
callq 0x1030
movq -0x70(%rbp), %rax
movq %rax, %r12
subq %r15, %r12
sarq $0x4, %r12
cmpq %r15, %rax
je 0x1511
cmpq $0x1, %r12
movq %r12, %rax
adcq $0x0, %rax
leaq 0x8(%r15), %rcx
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x1, (%rcx)
sete %dl
setne %sil
addl %esi, %r14d
addl %edx, %ebx
addq $0x10, %rcx
decq %rax
jne 0x14f3
jmp 0x1516
xorl %r14d, %r14d
xorl %ebx, %ebx
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x340(%rbp), %rdi
movl $0x10, %edx
callq 0x1100
leaq -0x340(%rbp), %rdi
movl %ebx, %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1ad3(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1ab5(%rip), %rsi      # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0x340(%rbp), %rdi
movl %r14d, %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1a8d(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1a6f(%rip), %rsi      # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0x100(%rbp), %rdx
movl $0x1, (%rdx)
leaq -0x140(%rbp), %rdi
leaq -0xd8(%rbp), %rcx
movq -0x30(%rbp), %rsi
callq 0x2558
movq -0x140(%rbp), %rcx
movq -0x138(%rbp), %rdi
cmpq $0x1, %r12
movq %r12, %rax
adcq $0x0, %rax
movq %rax, -0x80(%rbp)
leaq 0x8(%r15), %rax
movq %rax, -0x90(%rbp)
xorl %edx, %edx
xorl %esi, %esi
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq %r12, -0xc0(%rbp)
cmpq %rdi, %rcx
je 0x1652
movq %rcx, %rax
movl $0x1, (%rax)
addq $0x4, %rax
cmpq %rdi, %rax
jne 0x1643
cmpq %r15, -0x70(%rbp)
movq %rdx, -0x88(%rbp)
je 0x1707
leaq 0x1a06(%rip), %rax      # 0x3070
movslq (%rax,%rdx,4), %r11
xorl %eax, %eax
testq %rdx, %rdx
sete %al
movl %eax, -0x40(%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 %r10d, %r10d
cmpq $0x4, %rdx
sete %r10b
xorl %r12d, %r12d
cmpq $0x5, %rdx
sete %r12b
xorl %r13d, %r13d
cmpq $0x6, %rdx
sete %r13b
movq -0x80(%rbp), %rbx
movq -0x90(%rbp), %r9
movq -0x8(%r9), %rax
xorl %edx, %edx
divq %r11
movslq %edx, %rax
movl (%r9), %edx
cmpl %edx, (%rcx,%rax,4)
jne 0x16f7
addl -0x40(%rbp), %esi
addl %r8d, -0x4c(%rbp)
addl %r14d, -0x58(%rbp)
addl %r15d, -0x68(%rbp)
addl %r10d, -0x38(%rbp)
addl %r12d, -0x44(%rbp)
addl %r13d, -0x48(%rbp)
jmp 0x16fe
shlq $0x2, %rax
movl %edx, (%rcx,%rax)
addq $0x10, %r9
decq %rbx
jne 0x16c6
movq -0x88(%rbp), %rdx
incq %rdx
cmpq $0x7, %rdx
movq -0x60(%rbp), %r15
movq -0xc0(%rbp), %r12
jne 0x163b
leaq -0x340(%rbp), %rdi
callq 0x1180
movq %rax, %rbx
leaq 0x18de(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x18c0(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x4c(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1899(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x187b(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x58(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1854(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1836(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x68(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x180f(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x17f1(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x38(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x17ca(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x17ac(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x44(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1785(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1767(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x48(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1740(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1722(%rip), %rsi      # 0x301c
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0xd8(%rbp), %rdx
movl $0x3, (%rdx)
leaq -0x100(%rbp), %rdi
leaq -0x71(%rbp), %rcx
movq -0x30(%rbp), %rsi
callq 0x25e0
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %rdx
cmpq $0x1, %r12
adcq $0x0, %r12
movq %r12, -0xc8(%rbp)
leaq 0x8(%r15), %rax
movq %rax, -0xb8(%rbp)
xorl %r8d, %r8d
movl $0x0, -0x80(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x88(%rbp)
xorl %ebx, %ebx
xorl %esi, %esi
movq %rdx, -0xd0(%rbp)
cmpq %rdx, %rcx
je 0x199b
movq %rcx, %rax
movl $0x3, (%rax)
addq $0x4, %rax
cmpq %rdx, %rax
jne 0x198c
cmpq %r15, -0x70(%rbp)
movq %r8, -0x90(%rbp)
je 0x1aa8
leaq 0x16bd(%rip), %rax      # 0x3070
movslq (%rax,%r8,4), %r11
xorl %eax, %eax
testq %r8, %r8
sete %al
movl %eax, -0x40(%rbp)
xorl %eax, %eax
cmpq $0x1, %r8
sete %al
movl %eax, -0x38(%rbp)
xorl %eax, %eax
cmpq $0x2, %r8
sete %al
movl %eax, -0x68(%rbp)
xorl %eax, %eax
cmpq $0x3, %r8
sete %al
movl %eax, -0x58(%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 -0xc8(%rbp), %r9
movq -0x8(%r13), %rax
xorl %edx, %edx
divq %r11
movslq %edx, %rax
movl (%rcx,%rax,4), %r10d
movl (%r13), %r8d
cmpl $0x1, %r8d
jne 0x1a39
movl %r10d, %edx
andl $-0x2, %edx
cmpl $0x2, %edx
je 0x1a44
testl %r8d, %r8d
jne 0x1a64
cmpl $0x1, %r10d
ja 0x1a64
addl -0x40(%rbp), %esi
addl -0x38(%rbp), %ebx
movl -0x68(%rbp), %edx
addl %edx, -0x88(%rbp)
movl -0x58(%rbp), %edx
addl %edx, -0x44(%rbp)
addl %r15d, -0x48(%rbp)
addl %r12d, -0x4c(%rbp)
addl %edi, -0x80(%rbp)
shlq $0x2, %rax
cmpl $0x1, %r8d
sete %dl
cmpl $0x3, %r10d
setne %r14b
andb %dl, %r14b
movzbl %r14b, %edx
addl %r10d, %edx
testl %r8d, %r8d
sete %r8b
testl %edx, %edx
setne %r10b
andb %r8b, %r10b
movzbl %r10b, %r8d
subl %r8d, %edx
movl %edx, (%rcx,%rax)
addq $0x10, %r13
decq %r9
jne 0x1a14
movq -0x90(%rbp), %r8
incq %r8
cmpq $0x7, %r8
movq -0x60(%rbp), %r15
movq -0xc0(%rbp), %r14
movq -0xd0(%rbp), %rdx
jne 0x1984
leaq -0x340(%rbp), %rdi
callq 0x1180
movq %rax, %r12
leaq 0x1536(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %r12
leaq 0x1518(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %r12, %rdi
movl %ebx, %esi
callq 0x1180
movq %rax, %rbx
leaq 0x14f2(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x14d4(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x88(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x14aa(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x148c(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x44(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1465(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1447(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x48(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1420(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1402(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x4c(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x13db(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x13bd(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x80(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1396(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0x1378(%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 0x1cc5
cmpq $0x1, %r14
adcq $0x0, %r14
movq %r14, -0xe8(%rbp)
leaq 0x8(%r15), %rax
movq %rax, -0xe0(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x3, %edx
movsd 0x1301(%rip), %xmm0     # 0x3008
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
movl $0x0, -0xb8(%rbp)
movl $0x0, -0xac(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa0(%rbp)
movl $0x0, -0x9c(%rbp)
xorl %eax, %eax
movq -0x68(%rbp), %rcx
movl $0x3, (%rcx,%rax)
addq $0x4, %rax
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x1d62
cmpq %r15, -0x70(%rbp)
movl %edx, -0xd4(%rbp)
je 0x1eea
xorl %eax, %eax
cmpl $0x3, %edx
sete %al
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x4, %edx
sete %al
movl %eax, -0x4c(%rbp)
xorl %eax, %eax
cmpl $0x5, %edx
sete %al
movl %eax, -0x48(%rbp)
xorl %eax, %eax
cmpl $0x6, %edx
sete %al
movl %eax, -0x44(%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, -0x90(%rbp)
xorl %eax, %eax
cmpl $0xa, %edx
sete %al
movl %eax, -0xd0(%rbp)
xorl %eax, %eax
cmpl $0xb, %edx
sete %al
movl %eax, -0xc8(%rbp)
movq -0xe8(%rbp), %r13
movq -0xe0(%rbp), %r15
xorl %ebx, %ebx
movq -0x68(%rbp), %r12
movl -0x8(%r15), %r14d
movsd -0x38(%rbp), %xmm0
callq 0x10d0
cvttsd2si %xmm0, %eax
decl %eax
andl %ebx, %eax
xorl %r14d, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movl (%r12,%rax,4), %ecx
movl (%r15), %edx
cmpl $0x1, %edx
jne 0x1e3c
movl %ecx, %esi
andl $-0x2, %esi
cmpl $0x2, %esi
je 0x1e45
testl %edx, %edx
jne 0x1ea4
cmpl $0x1, %ecx
ja 0x1ea4
movl -0x58(%rbp), %esi
addl %esi, -0x9c(%rbp)
movl -0x4c(%rbp), %esi
addl %esi, -0xa0(%rbp)
movl -0x48(%rbp), %esi
addl %esi, -0xa4(%rbp)
movl -0x44(%rbp), %esi
addl %esi, -0xa8(%rbp)
movl -0x88(%rbp), %esi
addl %esi, -0xac(%rbp)
movl -0x80(%rbp), %esi
addl %esi, -0xb8(%rbp)
movl -0x90(%rbp), %esi
addl %esi, -0x94(%rbp)
movl -0xd0(%rbp), %esi
addl %esi, -0x98(%rbp)
movq -0x40(%rbp), %rsi
addl -0xc8(%rbp), %esi
movq %rsi, -0x40(%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), %r12
movl %esi, (%r12,%rax,4)
addq %rbx, %rbx
movl (%r15), %eax
orq %rax, %rbx
addq $0x10, %r15
decq %r13
jne 0x1e08
movsd -0x38(%rbp), %xmm0
addsd 0x1119(%rip), %xmm0     # 0x3010
movsd %xmm0, -0x38(%rbp)
movl -0xd4(%rbp), %edx
incl %edx
cmpl $0xc, %edx
movq -0x60(%rbp), %r15
movq -0xc0(%rbp), %r13
jne 0x1d5c
leaq -0x340(%rbp), %rdi
movl -0x9c(%rbp), %esi
callq 0x1180
movq %rax, %r12
leaq 0x10e6(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %r12, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %r12
leaq 0x10c8(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %r12, %rdi
movl -0xa0(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x109e(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1080(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0xa4(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x1056(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0x1038(%rip), %rsi      # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0xa8(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0x100e(%rip), %rsi      # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xff0(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0xac(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xfc6(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xfa8(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0xb8(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xf7e(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xf60(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x94(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xf36(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xf18(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movl -0x98(%rbp), %esi
callq 0x1180
movq %rax, %rbx
leaq 0xeee(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xed0(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
callq 0x1180
movq %rax, %rbx
leaq 0xea8(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0xe8a(%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 0x21ae
movl $0x2000, %edi           # imm = 0x2000
movq %rbx, -0x58(%rbp)
callq 0x10f0
movq %rax, %r14
xorl %eax, %eax
movl $0x3, (%r14,%rax)
addq $0x4, %rax
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x21d4
movl $0x2000, %edi           # imm = 0x2000
callq 0x10f0
movq %rax, %r12
movl $0x0, -0x38(%rbp)
movl $0x2000, %edx           # imm = 0x2000
movq %rax, %rdi
xorl %esi, %esi
callq 0x1090
cmpq %r15, -0x70(%rbp)
je 0x236c
cmpq $0x1, %r13
adcq $0x0, %r13
leaq 0x8(%r15), %rax
xorl %edx, %edx
movl $0x0, -0x38(%rbp)
movq %r12, -0x40(%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 (%r12,%rcx), %r8d
movl %r9d, %r15d
andl $0x2, %r15d
movl %r10d, %r11d
andl $0x2, %r11d
cmpl %r15d, %r11d
je 0x22dc
movq %r13, %rbx
movl (%rax), %ecx
cmpl $0x1, %r8d
jg 0x2290
cmpl $0x1, %ecx
setne %r12b
testl %r11d, %r11d
sete %r13b
orl %r11d, %ecx
je 0x22ad
orb %r12b, %r13b
je 0x22ad
incl %r8d
jmp 0x22d1
cmpl $0x1, %ecx
setne %r12b
testl %r15d, %r15d
sete %r13b
orl %r15d, %ecx
je 0x22bf
orb %r12b, %r13b
je 0x22bf
decl %r8d
jmp 0x22d1
incl -0x38(%rbp)
subl $0x1, %r8d
movl $0x0, %ecx
cmovbl %ecx, %r8d
jmp 0x22d1
incl -0x38(%rbp)
leal 0x1(%r8), %ecx
cmpl $0x3, %r8d
cmovel %r8d, %ecx
movl %ecx, %r8d
movq %rbx, %r13
movq -0x58(%rbp), %rbx
movq -0x40(%rbp), %r12
cmpl %r15d, %r11d
jne 0x2307
movl (%rax), %ecx
cmpl $0x1, %ecx
sete %r15b
testl %r11d, %r11d
setne %r12b
andb %r15b, %r12b
orl %r11d, %ecx
sete %cl
orb %r12b, %cl
movq -0x40(%rbp), %r12
movzbl %cl, %ecx
addl %ecx, -0x38(%rbp)
movq -0x60(%rbp), %r15
movl (%rax), %r11d
testl %r11d, %r11d
jne 0x2328
subl $0x1, %r10d
movl $0x0, %ecx
cmovbl %ecx, %r10d
subl $0x1, %r9d
cmovbl %ecx, %r9d
cmpl $0x1, %r11d
jne 0x234c
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
movl %r10d, (%rbx,%rdi,4)
shll $0x2, %esi
movl %r9d, (%r14,%rsi)
addl %edx, %edx
orl (%rax), %edx
movl %r8d, (%r12,%rsi)
addq $0x10, %rax
decq %r13
jne 0x222e
leaq -0x340(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x1180
movq %rax, %r13
leaq 0xc95(%rip), %rsi       # 0x301a
movl $0x1, %edx
movq %rax, %rdi
callq 0x1110
movq %r13, %rdi
movq -0x30(%rbp), %rsi
callq 0x1180
leaq 0xc7a(%rip), %rsi       # 0x301f
movl $0x2, %edx
movq %rax, %rdi
callq 0x1110
leaq -0x340(%rbp), %rdi
callq 0x1140
movq %r12, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x10e0
movq %rbx, %rdi
callq 0x10e0
movq -0x68(%rbp), %rdi
callq 0x10e0
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x23f0
callq 0x10e0
movq -0x140(%rbp), %rdi
testq %rdi, %rdi
leaq -0x118(%rbp), %rbx
je 0x2408
callq 0x10e0
movq 0x2bc9(%rip), %rax      # 0x4fd8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x338(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x340(%rbp,%rcx)
callq 0x10b0
leaq -0x248(%rbp), %rdi
callq 0x1060
leaq -0x548(%rbp), %rdi
callq 0x1040
testq %r15, %r15
je 0x2457
movq %r15, %rdi
callq 0x10e0
movq -0x128(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2468
callq 0x10e0
xorl %eax, %eax
addq $0x528, %rsp            # imm = 0x528
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb9f(%rip), %rdi       # 0x3022
movq %r13, %r15
callq 0x1080
movq %rax, %r13
jmp 0x24b5
movq %rax, %r13
jmp 0x24bd
jmp 0x24dc
jmp 0x24d2
jmp 0x24d7
jmp 0x24c8
jmp 0x2518
movq %rax, %r13
xorl %r15d, %r15d
jmp 0x2532
movq %rax, %r13
movq %r12, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x10e0
movq -0x58(%rbp), %rdi
callq 0x10e0
jmp 0x24df
movq %rax, %r13
jmp 0x250a
movq %rax, %r13
jmp 0x251f
movq %rax, %r13
jmp 0x24e8
movq %rax, %r13
jmp 0x24f9
movq %rax, %r13
movq -0x68(%rbp), %rdi
callq 0x10e0
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x24f9
callq 0x10e0
movq -0x140(%rbp), %rdi
testq %rdi, %rdi
je 0x250a
callq 0x10e0
leaq -0x340(%rbp), %rdi
callq 0x1150
jmp 0x251b
movq %rax, %r13
movq -0x60(%rbp), %r15
leaq -0x548(%rbp), %rdi
callq 0x1040
leaq -0x118(%rbp), %rbx
testq %r15, %r15
je 0x253f
movq %r15, %rdi
callq 0x10e0
movq -0x128(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2550
callq 0x10e0
movq %r13, %rdi
callq 0x1190