// File: /workspace/github_cpp_makefile_star2_O3/sagarvare[P]reinforcement-learning-rock-paper-scissor/main.cpp
// Function: main
int main(){
	int R = 3;//Number of steps back you want to remember
	int tot_states = pow(3,R); //Note, the total states will increase if comps states are included
	int initialize_from_previous = 1;
	string filename_previous = "filename.txt";
	string filename_logs = "game_play.log";

	// char valid_input[] = {'R','P','S','E'};
	string valid_input = "EPRS";

	//valid game play input: PRS
	string valid_move = "PRS";


	// typedef pair<int, int> Key;
	map < pair<int,int> , float> graph_state; //Check syntax for mapping from pair to a single transition number
	vector<int> out2 = decimal_to_ternary(101);
	int break_flag = 0;
	int old_state, new_state;//These contain the state numbers
	int counter = 0;//Number of moves played

	deque<int>  state_queue; //Contains the current state , i.e. last R moves
	char user_input;
	//Maybe add an option of initializing the 
	// graph from an earlier saved graph if available
	
	if (initialize_from_previous == 1){
		//Start My graph from the previous
		//Read the input?? Figure out how to save a map to and from the filename.txt
		//Use this to check it out
		cout << "Initialization from stored logs **NOT SUPPORTED** .This is just a tester inplace. I will add initializing logic later on.";

		//Go through the files and initialize the state_vector and the graph state appropriately.
		//Also make sure that the counter is also set appropriately
		string line;
		ifstream gameFile (filename_logs);
		if (gameFile.is_open() ) {
			while (getline(gameFile,line) ){
				string move; //Move is the read in 
				vector<string> results;
				results = parse_CSV(line);
				for (vector<string>::iterator i = results.begin(); i != results.end(); ++i){
					string move = *i;
					size_t found = valid_move.find(move);
					if (found!=string::npos && move != ""){
						//Add things to state_queue and make the game graph
						cout << "\n\ngoing to add:" << move;
						if (counter < R){
							int num_user_input = convert_user_input_to_num(valid_input, move[0]);
							state_queue.push_back(num_user_input);
						}else{ //There are more than R number of moves already done
							old_state = convert_queue_to_state(state_queue,R);
							int num_user_input = convert_user_input_to_num(valid_input, move[0]);
							state_queue.push_back(num_user_input); 
							state_queue.pop_front();
							new_state = convert_queue_to_state(state_queue,R);

							//Update the current graph
							if (graph_state.count(make_pair(old_state,new_state)) == 0){//Check syntax
								//This is a state that has not been seen before
								graph_state[make_pair(old_state,new_state)] = 1; //Check syntax
							}else{
								//This key is present
								graph_state[make_pair(old_state,new_state)]= 1 + graph_state[make_pair(old_state,new_state)]; //Check syntax
							}
						}
						counter++;

  					}
				}

				cout << "\n\n";
			}
			gameFile.close();
		}
		else{
			cout << "Unable to  open the FIle\n\n";
		}
	}


	
	//For generating random numbers
    mt19937 rng;
    rng.seed(random_device()());
    std::uniform_int_distribution<mt19937::result_type> dist6(1,3); // distribution in range [1, 6]

	//Open a file for logging all the users moves
	string file_name = "game_play.log";
	ofstream outfile;
	outfile.open(file_name, ios_base::app);

	//Open a file for logging all the computers moves
	string file_name_computer = "game_play_computer.log";
	ofstream outfile_computer;
	outfile_computer.open(file_name_computer, ios_base::app);

	//Open a file for logging the W/L numbers
	string file_name_WL = "game_WL_numbers.log";
	ofstream outfile_WL;
	outfile_WL.open(file_name_WL, ios_base::app);

	if (initialize_from_previous ==0){
	}
	int AI_loss = 0;
	int AI_wins = 0;
	int AI_draws = 0;



	while(break_flag == 0){
		cout << "\nEnter what you wanna play : R,P,S";
		cin >> user_input;

		// if (find(valid_input.begin(), valid_input.end(), user_input) != valid_input.end() ){
		if (valid_input.find(user_input) != string::npos){
			//Element part of valid input
			if (user_input == 'E'){
				//User wants to end the game
				cout << "\n\nThanks for playing";

				//Write the W/L numbers to logs
				outfile_WL << "wins:" << AI_wins<<"\n";
				outfile_WL << "draws:" << AI_draws <<"\n";
				outfile_WL << "loss:" << AI_loss << "\n";

				break_flag = 1;
				break;
			}
			outfile << user_input << ",";
			int num_user_input = convert_user_input_to_num(valid_input, user_input);
			//Else continue with normal game
			//Log the play, computer plays something, log the graph state and log the result
			

			//The first R moves are random
			if (counter < R){
				cout << "\n\n\n--------------------------------------ENTERING THE RANDOM PHASE!\n\n\n";
				//Computer plays something randomly
				char comp_move = valid_input[dist6(rng)];
				outfile_computer << comp_move << ",";

			    cout << "--------------------------------------------The computer played:" << comp_move << endl;

			    int result = check_result(num_user_input,comp_move);
				//Add the move to the queue
				state_queue.push_back(num_user_input);


				//Update who won
				if (user_won(user_input, comp_move) == 1 ){
					AI_loss ++;

				}else if (computer_won(user_input, comp_move) == 1){
					AI_wins ++;

				}else{
					AI_draws ++;
				}





			}else{
				// Implement a queue for appending the moves 
				// i.e. keep popping oldest and add the latest
				// all the states from the queue --> state transition --> update graph
				old_state = convert_queue_to_state(state_queue,R);
				// state_queue.push_back(num_user_input);
				// state_queue.pop_front();

				//currently old_state=new_state is NOT wrong
				//Because of an old bug that I corrected horribly
				//Now the bug is gone, but I am left with horrible code

				new_state = convert_queue_to_state(state_queue,R); 


				//Draw a random element from the graph before updating
				string possible_inputs = "PRS";
				int transition_counts[3];//Counts the previously seen transitions

				for (int char_temp = 0;char_temp<= 2;++char_temp){
					// Somehow temporarily append a number to a queue and then remove it
					// TO DO - Add some logic here
					deque<int> temp_queue(state_queue);//Assume temp_queue holds this 
					temp_queue.pop_back();
					// int num_char_temp = convert_user_input_to_num(valid_input, valid_input[char_temp+ 1]);
					temp_queue.push_back(char_temp);
					int possible_new_state;
					possible_new_state = convert_queue_to_state(temp_queue,R);
					transition_counts[char_temp] = graph_state[make_pair(old_state,possible_new_state)];
				}

				//transition counts holds the three transitions
				//Draw a random sample based on these probabilities of transition
				//Maybe just simply draw a random uniform and then use cdf concept
				float prior_count = 0.5;
				cout << "\n\n";
				for (int it =0;it<3;it++){
					cout << "\nCounts for playing the next one as:" << valid_input[it+ 1] << " is:" << transition_counts[it];
				}
				int int_comp_move= draw_sample(transition_counts,prior_count);
				//int_comp_move stores the computers move in integer value
				char exp_move = valid_input[int_comp_move];
				char comp_move = beating_move(exp_move);
				cout << "\n\n----------------------------------Computer played:"<< comp_move << "\n";
				//Update the state queue to keep track of this

				//print the old state and the new state
				state_queue.push_back(num_user_input);
				state_queue.pop_front();

				//Update the new state
				new_state = convert_queue_to_state(state_queue,R); 


				//Log the comp_move? Maybe......No harm right? Useless data but still...Debugging purposes?
				outfile_computer << comp_move << ",";

				//Update the current graph
				if (graph_state.count(make_pair(old_state,new_state)) == 0){//Check syntax
					//This is a state that has not been seen before
					graph_state[make_pair(old_state,new_state)] = 1; //Check syntax
				}else{
					//This key is present
					graph_state[make_pair(old_state,new_state)]= 1 + graph_state[make_pair(old_state,new_state)]; //Check syntax
				}

				//Update who won
				if (user_won(user_input, comp_move) ){
					AI_loss ++;

				}else if (computer_won(user_input, comp_move) ){
					AI_wins ++;

				}else{
					AI_draws ++;
				}



			}
			counter++;




			//Write the input to user game data





			//After every 100 data inputs, 
			//Save current graph 






			//If in the playing mode, pick an action based on the graph






			//Note down the result and keep doing statistical analysis






		}else{
			//Element not part of valid input
			cout << "Please enter a valid move";

		}
		// break_flag = 1;
	}
	return 0; 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2fb8, %rsp           # imm = 0x2FB8
leaq -0x210(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3b1e(%rip), %rsi      # 0x6020
leaq 0x3b23(%rip), %rdx      # 0x602c
leaq -0x220(%rbp), %rdi
callq 0x3f3c
leaq -0x190(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3b06(%rip), %rsi      # 0x602d
leaq 0x3b0c(%rip), %rdx      # 0x603a
leaq -0x1a0(%rbp), %rdi
callq 0x3f3c
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3af2(%rip), %rsi      # 0x603b
leaq 0x3aef(%rip), %rdx      # 0x603f
leaq -0x90(%rbp), %rdi
callq 0x3f3c
leaq -0x250(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3ace(%rip), %rsi      # 0x603c
leaq 0x3aca(%rip), %rdx      # 0x603f
leaq -0x260(%rbp), %rdi
callq 0x3f3c
leaq -0x2a8(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x2d8(%rbp), %rdi
movl $0x65, %esi
callq 0x4cf1
xorps %xmm0, %xmm0
leaq -0xe0(%rbp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x3cb8
movq 0x69f4(%rip), %rdi      # 0x8fd0
leaq 0x3a5d(%rip), %rsi      # 0x6040
movl $0x79, %edx
callq 0x21f0
leaq -0x1c40(%rbp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq -0x2fd8(%rbp), %rbx
leaq -0x1a0(%rbp), %rsi
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2290
leaq -0x2f60(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x2b2e
leaq -0x270(%rbp), %r15
leaq -0x4e8(%rbp), %r13
movl $0x0, -0x34(%rbp)
movq -0x2fd8(%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %edx
movq %rbx, %rdi
leaq -0x1c50(%rbp), %rsi
callq 0x2330
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
leaq -0x280(%rbp), %rbx
jne 0x2b4f
leaq -0x868(%rbp), %rax
movq %rax, -0x878(%rbp)
xorl %eax, %eax
movq %rax, -0x870(%rbp)
movb $0x0, -0x868(%rbp)
movq %rax, -0x130(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x140(%rbp)
movq %r15, -0x280(%rbp)
movq -0x1c50(%rbp), %rsi
movq -0x1c48(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3e9e
leaq -0x70(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4afc
movaps -0x140(%rbp), %xmm0
movq -0x130(%rbp), %rax
movaps -0x70(%rbp), %xmm1
movaps %xmm1, -0x140(%rbp)
movq -0x60(%rbp), %rcx
movq %rcx, -0x130(%rbp)
movups %xmm0, -0x4e8(%rbp)
movq %rax, -0x4d8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq %r13, %rdi
callq 0x3a62
movq %r12, %rdi
callq 0x3a62
movq -0x280(%rbp), %rdi
cmpq %r15, %rdi
je 0x2755
movq -0x270(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x140(%rbp), %r15
cmpq -0x138(%rbp), %r15
je 0x2ad1
leaq -0x4d8(%rbp), %rax
movq %rax, -0x4e8(%rbp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x3e9e
movq -0x4e8(%rbp), %rsi
movq -0x4e0(%rbp), %rcx
leaq -0x260(%rbp), %rdi
xorl %edx, %edx
callq 0x22f0
cmpq $-0x1, %rax
je 0x2aa6
movq %r13, %rdi
leaq 0x3b69(%rip), %rsi      # 0x6322
callq 0x2090
testl %eax, %eax
je 0x2aa6
movl $0xf, %edx
movq 0x67fe(%rip), %rdi      # 0x8fd0
leaq 0x38e1(%rip), %rsi      # 0x60ba
callq 0x21f0
movq -0x4e8(%rbp), %rsi
movq -0x4e0(%rbp), %rdx
movq 0x67dd(%rip), %rdi      # 0x8fd0
callq 0x21f0
cmpl $0x2, -0x34(%rbp)
jg 0x289a
leaq -0x1f0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
leaq -0x200(%rbp), %rdi
callq 0x3e9e
movq -0x4e8(%rbp), %rax
movsbl (%rax), %esi
leaq -0x200(%rbp), %rdi
callq 0x5101
movl %eax, %r12d
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x2868
movq -0x1f0(%rbp), %rsi
incq %rsi
callq 0x21d0
movl %r12d, -0x70(%rbp)
movq -0xb0(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x295d
movl %r12d, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x2aa3
leaq -0x678(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ad0
leaq -0x678(%rbp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x4e08
movl %eax, %r12d
movq %rbx, %rdi
callq 0x3fda
leaq -0x1d0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1e0(%rbp), %rdi
callq 0x3e9e
movq -0x4e8(%rbp), %rax
movsbl (%rax), %esi
leaq -0x1e0(%rbp), %rdi
callq 0x5101
movl %eax, %ebx
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0x2931
movq -0x1d0(%rbp), %rsi
incq %rsi
callq 0x21d0
movl %ebx, -0x160(%rbp)
movq -0xb0(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x2972
movl %ebx, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x2985
leaq -0xe0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4040
jmp 0x2aa3
leaq -0xe0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x4040
movq -0xd0(%rbp), %rax
movq -0xc0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x29a2
addq $0x4, %rax
jmp 0x29de
movq -0xc8(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x21d0
movq -0xb8(%rbp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xc8(%rbp)
leaq 0x200(%rax), %rcx
movq %rcx, -0xc0(%rbp)
leaq -0x538(%rbp), %rdi
movq %rax, -0xd0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0x3ad0
leaq -0x538(%rbp), %r14
movq %r14, %rdi
movl $0x3, %esi
callq 0x4e08
movl %eax, %ebx
movq %r14, %rdi
callq 0x3fda
shlq $0x20, %rbx
movl %r12d, %r12d
orq %rbx, %r12
movq %r12, -0x70(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x45be
leaq -0x2a8(%rbp), %rcx
cmpq %rcx, %rax
je 0x2a89
movq %r12, -0x70(%rbp)
leaq -0x2b0(%rbp), %rbx
movq %rbx, %rdi
leaq -0x70(%rbp), %rsi
callq 0x3ba0
movss (%rax), %xmm0
movss %xmm0, -0x30(%rbp)
movq %r12, -0x180(%rbp)
movq %rbx, %rdi
leaq -0x180(%rbp), %rsi
callq 0x3ba0
movss -0x30(%rbp), %xmm0
addss 0x3585(%rip), %xmm0     # 0x6008
movss %xmm0, (%rax)
jmp 0x2aa3
movq %r12, -0x70(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3ba0
movl $0x3f800000, (%rax)     # imm = 0x3F800000
incl -0x34(%rbp)
movq -0x4e8(%rbp), %rdi
leaq -0x4d8(%rbp), %rax
cmpq %rax, %rdi
je 0x2ac8
movq -0x4d8(%rbp), %rsi
incq %rsi
callq 0x21d0
addq $0x20, %r15
jmp 0x275c
movl $0x2, %edx
movq 0x64f3(%rip), %rdi      # 0x8fd0
leaq 0x383c(%rip), %rsi      # 0x6320
callq 0x21f0
leaq -0x140(%rbp), %rdi
callq 0x3a62
movq -0x878(%rbp), %rdi
leaq -0x868(%rbp), %rax
cmpq %rax, %rdi
leaq -0x2fd8(%rbp), %rbx
leaq -0x270(%rbp), %r15
je 0x2648
movq -0x868(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x2648
movl $0x0, -0x34(%rbp)
movq 0x6494(%rip), %rdi      # 0x8fd0
leaq 0x3587(%rip), %rsi      # 0x60ca
movl $0x1a, %edx
callq 0x21f0
jmp 0x2b62
leaq -0x2fd8(%rbp), %rdi
leaq -0x1c40(%rbp), %r14
callq 0x2050
leaq -0x2fd8(%rbp), %rdi
callq 0x2070
movq -0x1c50(%rbp), %rdi
cmpq %r14, %rdi
je 0x2b89
movq -0x1c40(%rbp), %rsi
incq %rsi
callq 0x21d0
movq $0x1571, -0x2fd8(%rbp) # imm = 0x1571
movl $0x1, %eax
movl $0x1571, %ecx           # imm = 0x1571
movq %rcx, %rdx
shrq $0x1e, %rdx
xorl %ecx, %edx
imull $0x6c078965, %edx, %ecx # imm = 0x6C078965
addl %eax, %ecx
movq %rcx, -0x2fd8(%rbp,%rax,8)
incq %rax
cmpq $0x270, %rax            # imm = 0x270
jne 0x2b9e
movq $0x270, -0x1c58(%rbp) # imm = 0x270
leaq -0x1c50(%rbp), %rdi
callq 0x3c2c
leaq -0x1c50(%rbp), %rdi
callq 0x2230
movl %eax, %eax
movq %rax, -0x2fd8(%rbp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, -0x2fd8(%rbp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x2bf3
movq $0x270, -0x1c58(%rbp) # imm = 0x270
leaq -0x1c50(%rbp), %rdi
callq 0x2190
movq $0x1, -0x2e8(%rbp)
movq $0x3, -0x2e0(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x33d9(%rip), %rsi      # 0x602d
leaq 0x33df(%rip), %rdx      # 0x603a
leaq -0x70(%rbp), %rdi
callq 0x3f3c
leaq -0x1c50(%rbp), %rdi
callq 0x22d0
leaq -0x1c50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
leaq -0x170(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x344e(%rip), %rsi      # 0x60e5
leaq 0x345d(%rip), %rdx      # 0x60fb
leaq -0x180(%rbp), %rdi
callq 0x3f3c
leaq -0x878(%rbp), %rdi
callq 0x22d0
leaq -0x878(%rbp), %rdi
leaq -0x180(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
leaq -0x150(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x341c(%rip), %rsi      # 0x60fc
leaq 0x3428(%rip), %rdx      # 0x610f
leaq -0x160(%rbp), %rdi
callq 0x3f3c
leaq -0x4e8(%rbp), %rdi
callq 0x22d0
leaq -0x4e8(%rbp), %rdi
leaq -0x160(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
movq $0x0, -0x50(%rbp)
movq 0x62aa(%rip), %r15      # 0x8fd0
leaq -0x140(%rbp), %r12
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x22, %edx
movq %r15, %rdi
leaq 0x33c6(%rip), %rsi      # 0x6110
callq 0x21f0
movq 0x628a(%rip), %rdi      # 0x8fe0
leaq -0x29(%rbp), %rsi
callq 0x2220
movsbl -0x29(%rbp), %esi
leaq -0x90(%rbp), %rdi
xorl %edx, %edx
callq 0x2210
cmpq $-0x1, %rax
jne 0x2d8d
movl $0x19, %edx
movq %r15, %rdi
leaq 0x34bc(%rip), %rsi      # 0x6242
callq 0x21f0
jmp 0x2d3b
movb -0x29(%rbp), %al
cmpb $0x45, %al
je 0x33f9
movb %al, -0x140(%rbp)
movl $0x1, %edx
leaq -0x1c50(%rbp), %rdi
movq %r12, %rsi
callq 0x21f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x353e(%rip), %rsi      # 0x62ff
callq 0x21f0
leaq -0x1b0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1c0(%rbp), %rdi
callq 0x3e9e
movsbl -0x29(%rbp), %esi
leaq -0x1c0(%rbp), %rdi
callq 0x5101
movl %eax, %r14d
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x2e26
movq -0x1b0(%rbp), %rsi
incq %rsi
callq 0x21d0
movl %r14d, -0x3c(%rbp)
cmpl $0x2, -0x34(%rbp)
jg 0x2f2a
movl $0x46, %edx
movq %r15, %rdi
leaq 0x3318(%rip), %rsi      # 0x615b
callq 0x21f0
leaq -0x2e8(%rbp), %rdi
leaq -0x2fd8(%rbp), %rsi
movq %rdi, %rdx
callq 0x48a6
movq -0x90(%rbp), %rcx
movb (%rcx,%rax), %bl
movb %bl, -0x140(%rbp)
movl $0x1, %edx
leaq -0x878(%rbp), %rdi
movq %r12, %rsi
callq 0x21f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x346e(%rip), %rsi      # 0x62ff
callq 0x21f0
movl $0x40, %edx
movq %r15, %rdi
leaq 0x32fd(%rip), %rsi      # 0x61a2
callq 0x21f0
movb %bl, -0x140(%rbp)
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x21f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movsbl -0x3c(%rbp), %edi
movsbl %bl, %r14d
movl %r14d, %esi
callq 0x4dac
movq -0xb0(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x31db
movl -0x3c(%rbp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x31eb
leaq -0x628(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ad0
leaq -0x628(%rbp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x4e08
movl %eax, %r14d
movq %rbx, %rdi
callq 0x3fda
leaq -0x5d8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ad0
leaq -0x5d8(%rbp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x4e08
movq %rbx, %rdi
callq 0x3fda
leaq -0x230(%rbp), %rax
movq %rax, -0x240(%rbp)
leaq -0x240(%rbp), %rdi
leaq 0x3095(%rip), %rsi      # 0x603c
leaq 0x3091(%rip), %rdx      # 0x603f
callq 0x3f3c
movl $0x0, -0x38(%rbp)
movl %r14d, %ebx
movq %r12, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ad0
movq -0x110(%rbp), %rax
movq -0x108(%rbp), %rdi
cmpq %rdi, %rax
je 0x2fec
addq $-0x4, %rax
movq -0x100(%rbp), %rcx
jmp 0x3027
movl $0x200, %esi            # imm = 0x200
callq 0x21d0
movq -0xf8(%rbp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, -0xf8(%rbp)
movq -0x8(%rax), %rax
movq %rax, -0x108(%rbp)
leaq 0x200(%rax), %rcx
movq %rcx, -0x100(%rbp)
addq $0x1fc, %rax            # imm = 0x1FC
movq %rax, -0x110(%rbp)
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x3049
movl -0x38(%rbp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, -0x110(%rbp)
jmp 0x3055
movq %r12, %rdi
leaq -0x38(%rbp), %rsi
callq 0x4040
leaq -0x8c8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3ad0
movq %r13, %rdi
movl $0x3, %esi
callq 0x4e08
movl %eax, %r14d
movq %r13, %rdi
callq 0x3fda
shlq $0x20, %r14
orq %rbx, %r14
movq %r14, -0xe8(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3ba0
cvttss2si (%rax), %eax
movslq -0x38(%rbp), %rcx
movl %eax, -0x2bc(%rbp,%rcx,4)
movq %r12, %rdi
callq 0x3fda
movl -0x38(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x38(%rbp)
cmpl $0x2, %eax
jl 0x2fbd
movl $0x2, %edx
movq %r15, %rdi
leaq 0x3248(%rip), %rsi      # 0x6320
callq 0x21f0
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0x3148
movl $0x24, %edx
movq %r15, %rdi
leaq 0x30ee(%rip), %rsi      # 0x61e3
callq 0x21f0
movq -0x90(%rbp), %rax
movb 0x1(%rax,%r13), %al
movb %al, -0x140(%rbp)
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x21f0
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
leaq 0x30da(%rip), %rsi      # 0x6208
callq 0x21f0
movl -0x2bc(%rbp,%r13,4), %esi
incq %r13
movq %r14, %rdi
callq 0x22e0
jmp 0x30e0
leaq -0x2bc(%rbp), %rdi
movss 0x2ead(%rip), %xmm0     # 0x6004
callq 0x5144
cltq
movq -0x90(%rbp), %rcx
movsbl (%rcx,%rax), %edi
callq 0x52d2
movb %al, -0x30(%rbp)
movl $0x34, %edx
movq %r15, %rdi
leaq 0x308d(%rip), %rsi      # 0x620d
callq 0x21f0
movb -0x30(%rbp), %al
movb %al, -0x140(%rbp)
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x21f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3174(%rip), %rsi      # 0x6321
callq 0x21f0
movq -0xb0(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x3228
movl -0x3c(%rbp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x3238
leaq -0xe0(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x4040
movsbl -0x29(%rbp), %edi
movl %r14d, %esi
callq 0x5264
cmpl $0x1, %eax
jne 0x320b
movq -0x50(%rbp), %rax
incl %eax
movq %rax, -0x50(%rbp)
jmp 0x33f1
movsbl -0x29(%rbp), %edi
movl %r14d, %esi
callq 0x529b
cmpl $0x1, %eax
jne 0x33c7
incl -0x44(%rbp)
jmp 0x33f1
leaq -0xe0(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x4040
movq -0xd0(%rbp), %rax
movq -0xc0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x3255
addq $0x4, %rax
jmp 0x3291
movq -0xc8(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x21d0
movq -0xb8(%rbp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xc8(%rbp)
leaq 0x200(%rax), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xd0(%rbp)
leaq -0x588(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ad0
leaq -0x588(%rbp), %r13
movq %r13, %rdi
movl $0x3, %esi
callq 0x4e08
movl %eax, %r14d
movq %r13, %rdi
callq 0x3fda
movb -0x30(%rbp), %al
movb %al, -0x140(%rbp)
movl $0x1, %edx
leaq -0x878(%rbp), %rdi
movq %r12, %rsi
callq 0x21f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3009(%rip), %rsi      # 0x62ff
callq 0x21f0
shlq $0x20, %r14
orq %rbx, %r14
movq %r14, -0x140(%rbp)
leaq -0x2b0(%rbp), %rdi
movq %r12, %rsi
callq 0x45be
leaq -0x2a8(%rbp), %rcx
cmpq %rcx, %rax
je 0x3375
movq %r14, -0x140(%rbp)
leaq -0x2b0(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3ba0
movss (%rax), %xmm0
movss %xmm0, -0xec(%rbp)
movq %r14, -0xe8(%rbp)
movq %rbx, %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3ba0
movss -0xec(%rbp), %xmm0
addss 0x2c99(%rip), %xmm0     # 0x6008
movss %xmm0, (%rax)
jmp 0x3391
movq %r14, -0x140(%rbp)
leaq -0x2b0(%rbp), %rdi
movq %r12, %rsi
callq 0x3ba0
movl $0x3f800000, (%rax)     # imm = 0x3F800000
movsbl -0x29(%rbp), %edi
movsbl -0x30(%rbp), %r14d
movl %r14d, %esi
callq 0x5264
testl %eax, %eax
je 0x33b2
movq -0x50(%rbp), %rax
incl %eax
movq %rax, -0x50(%rbp)
jmp 0x33cf
movsbl -0x29(%rbp), %edi
movl %r14d, %esi
callq 0x529b
testl %eax, %eax
je 0x33cc
incl -0x44(%rbp)
jmp 0x33cf
incl -0x40(%rbp)
jmp 0x33f1
incl -0x40(%rbp)
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x33f1
movq -0x230(%rbp), %rsi
incq %rsi
callq 0x21d0
incl -0x34(%rbp)
jmp 0x2d3b
movq 0x5bd0(%rip), %rdi      # 0x8fd0
leaq 0x2d2c(%rip), %rsi      # 0x6133
movl $0x14, %edx
callq 0x21f0
leaq 0x2d30(%rip), %rsi      # 0x6148
leaq -0x4e8(%rbp), %rdi
movl $0x5, %edx
callq 0x21f0
leaq -0x4e8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x22e0
leaq 0x2ee2(%rip), %rsi      # 0x6321
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
leaq 0x2cfb(%rip), %rsi      # 0x614e
leaq -0x4e8(%rbp), %rdi
movl $0x6, %edx
callq 0x21f0
leaq -0x4e8(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x22e0
leaq 0x2ea7(%rip), %rsi      # 0x6321
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
leaq 0x2cc7(%rip), %rsi      # 0x6155
leaq -0x4e8(%rbp), %rdi
movl $0x5, %edx
callq 0x21f0
leaq -0x4e8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x22e0
leaq 0x2e6b(%rip), %rsi      # 0x6321
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
movq 0x5afe(%rip), %rax      # 0x8fc8
movq (%rax), %rbx
movq 0x18(%rax), %r14
leaq -0x4e0(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x4e8(%rbp,%rax)
callq 0x2170
leaq -0x3f0(%rbp), %rdi
callq 0x20a0
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x351b
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x870(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x878(%rbp,%rax)
callq 0x2170
leaq -0x780(%rbp), %rdi
callq 0x20a0
movq -0x180(%rbp), %rdi
leaq -0x170(%rbp), %rax
cmpq %rax, %rdi
je 0x3565
movq -0x170(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x1c48(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x1c50(%rbp,%rax)
callq 0x2170
leaq -0x1b58(%rbp), %rdi
callq 0x20a0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x35a6
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0xe0(%rbp), %rdi
callq 0x3fda
movq -0x2d8(%rbp), %rdi
testq %rdi, %rdi
je 0x35cd
movq -0x2c8(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq -0x2b0(%rbp), %rdi
callq 0x3e40
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x35fb
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3617
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x1a0(%rbp), %rdi
leaq -0x190(%rbp), %rax
cmpq %rax, %rdi
je 0x3639
movq -0x190(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x365b
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x21d0
xorl %eax, %eax
addq $0x2fb8, %rsp           # imm = 0x2FB8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3921
movq %rax, %rbx
jmp 0x3930
jmp 0x367e
movq %rax, %rbx
jmp 0x3952
movq %rax, %rbx
jmp 0x395e
jmp 0x3690
movq %rax, %rbx
jmp 0x3980
movq %rax, %rbx
jmp 0x398c
jmp 0x36d2
jmp 0x36b8
movq %rax, %rbx
leaq -0x1c50(%rbp), %rdi
callq 0x2190
jmp 0x39a5
movq %rax, %rdi
callq 0x3ca9
jmp 0x36d2
movq %rax, %rbx
jmp 0x38ac
movq %rax, %rbx
jmp 0x38b8
movq %rax, %rbx
jmp 0x39a5
movq %rax, %rbx
jmp 0x39b1
movq %rax, %rbx
jmp 0x39cc
movq %rax, %rbx
jmp 0x39fa
movq %rax, %rbx
jmp 0x3a16
movq %rax, %rbx
jmp 0x3a38
jmp 0x38fa
jmp 0x38fa
jmp 0x38fa
jmp 0x3921
movq %rax, %rbx
leaq -0x588(%rbp), %rdi
jmp 0x38f1
jmp 0x38fa
jmp 0x38fa
jmp 0x38fa
movq %rax, %rbx
leaq -0x628(%rbp), %rdi
jmp 0x374f
jmp 0x3921
movq %rax, %rbx
leaq -0x5d8(%rbp), %rdi
callq 0x3fda
jmp 0x3924
jmp 0x3874
movq %rax, %rbx
movq -0x280(%rbp), %rdi
cmpq %r15, %rdi
je 0x3877
movq -0x270(%rbp), %rsi
jmp 0x386a
jmp 0x3874
jmp 0x384d
movq %rax, %rbx
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x3924
movq -0x1b0(%rbp), %rsi
jmp 0x3917
movq %rax, %rbx
leaq -0x1c40(%rbp), %r14
jmp 0x38ac
jmp 0x384d
jmp 0x384d
jmp 0x3921
movq %rax, %rbx
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x3850
movq -0x1f0(%rbp), %rsi
jmp 0x3815
jmp 0x384d
movq %rax, %rbx
leaq -0x538(%rbp), %rdi
jmp 0x3829
movq %rax, %rbx
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0x3850
movq -0x1d0(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x3850
movq %rax, %rbx
leaq -0x678(%rbp), %rdi
callq 0x3fda
jmp 0x3850
jmp 0x3921
jmp 0x3921
jmp 0x384d
jmp 0x3921
jmp 0x38fa
jmp 0x384d
jmp 0x38e7
movq %rax, %rbx
movq -0x4e8(%rbp), %rdi
leaq -0x4d8(%rbp), %rax
cmpq %rax, %rdi
je 0x3877
movq -0x4d8(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x3877
movq %rax, %rbx
leaq -0x1c40(%rbp), %r14
leaq -0x140(%rbp), %rdi
callq 0x3a62
movq -0x878(%rbp), %rdi
leaq -0x868(%rbp), %rax
cmpq %rax, %rdi
je 0x38ac
movq -0x868(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x2fd8(%rbp), %rdi
callq 0x2070
movq -0x1c50(%rbp), %rdi
cmpq %r14, %rdi
je 0x39a5
movq -0x1c40(%rbp), %rsi
jmp 0x399d
movq %rax, %rbx
leaq -0x8c8(%rbp), %rdi
callq 0x3fda
jmp 0x38ea
jmp 0x38e7
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x3fda
jmp 0x38fd
jmp 0x38fa
movq %rax, %rbx
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x3924
movq -0x230(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x3924
movq %rax, %rbx
leaq -0x4e8(%rbp), %rdi
callq 0x2250
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x3952
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x878(%rbp), %rdi
callq 0x2250
movq -0x180(%rbp), %rdi
leaq -0x170(%rbp), %rax
cmpq %rax, %rdi
je 0x3980
movq -0x170(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x1c50(%rbp), %rdi
callq 0x2250
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x39a5
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0xe0(%rbp), %rdi
callq 0x3fda
movq -0x2d8(%rbp), %rdi
testq %rdi, %rdi
je 0x39cc
movq -0x2c8(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq -0x2b0(%rbp), %rdi
callq 0x3e40
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x39fa
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3a16
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x190(%rbp), %rax
movq -0x1a0(%rbp), %rdi
cmpq %rax, %rdi
je 0x3a38
movq -0x190(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x210(%rbp), %rax
movq -0x220(%rbp), %rdi
cmpq %rax, %rdi
je 0x3a5a
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x2310