// File: /workspace/github_cpp_makefile_star2_O1/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 0x3f46
leaq -0x190(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3b06(%rip), %rsi      # 0x602d
leaq 0x3b0c(%rip), %rdx      # 0x603a
leaq -0x1a0(%rbp), %rdi
callq 0x3f46
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3af2(%rip), %rsi      # 0x603b
leaq 0x3aef(%rip), %rdx      # 0x603f
leaq -0x90(%rbp), %rdi
callq 0x3f46
leaq -0x250(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3ace(%rip), %rsi      # 0x603c
leaq 0x3aca(%rip), %rdx      # 0x603f
leaq -0x260(%rbp), %rdi
callq 0x3f46
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 0x4d29
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 0x3cc6
movq 0x69f4(%rip), %rdi      # 0x8fd0
leaq 0x3a5d(%rip), %rsi      # 0x6040
movl $0x79, %edx
callq 0x21f0
leaq -0x1c48(%rbp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq -0x2fe0(%rbp), %rbx
leaq -0x1a0(%rbp), %rsi
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2290
leaq -0x2f68(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x2b3c
leaq -0x270(%rbp), %r15
leaq -0x4f0(%rbp), %r13
movl $0x0, -0x34(%rbp)
movq -0x2fe0(%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %edx
movq %rbx, %rdi
leaq -0x1c58(%rbp), %rsi
callq 0x2330
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
leaq -0x280(%rbp), %rbx
jne 0x2b5d
leaq -0x870(%rbp), %rax
movq %rax, -0x880(%rbp)
xorl %eax, %eax
movq %rax, -0x878(%rbp)
movb $0x0, -0x870(%rbp)
movq %rax, -0x130(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x140(%rbp)
movq %r15, -0x280(%rbp)
movq -0x1c58(%rbp), %rsi
movq -0x1c50(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3eac
leaq -0x70(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4b34
xorps %xmm0, %xmm0
movaps %xmm0, -0x4f0(%rbp)
movaps -0x140(%rbp), %xmm0
movq -0x130(%rbp), %rax
movups -0x70(%rbp), %xmm1
movaps %xmm1, -0x140(%rbp)
movq -0x60(%rbp), %rcx
movq %rcx, -0x130(%rbp)
movaps -0x4f0(%rbp), %xmm1
movaps %xmm0, -0x4f0(%rbp)
movq %rax, -0x4e0(%rbp)
movups %xmm1, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq %r13, %rdi
callq 0x3a70
movq %r12, %rdi
callq 0x3a70
movq -0x280(%rbp), %rdi
cmpq %r15, %rdi
je 0x2763
movq -0x270(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x140(%rbp), %r15
cmpq -0x138(%rbp), %r15
je 0x2adf
leaq -0x4e0(%rbp), %rax
movq %rax, -0x4f0(%rbp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x3eac
movq -0x4f0(%rbp), %rsi
movq -0x4e8(%rbp), %rcx
leaq -0x260(%rbp), %rdi
xorl %edx, %edx
callq 0x22f0
cmpq $-0x1, %rax
je 0x2ab4
movq %r13, %rdi
leaq 0x3b5b(%rip), %rsi      # 0x6322
callq 0x2090
testl %eax, %eax
je 0x2ab4
movl $0xf, %edx
movq 0x67f0(%rip), %rdi      # 0x8fd0
leaq 0x38d3(%rip), %rsi      # 0x60ba
callq 0x21f0
movq -0x4f0(%rbp), %rsi
movq -0x4e8(%rbp), %rdx
movq 0x67cf(%rip), %rdi      # 0x8fd0
callq 0x21f0
cmpl $0x2, -0x34(%rbp)
jg 0x28a8
leaq -0x1f0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
leaq -0x200(%rbp), %rdi
callq 0x3eac
movq -0x4f0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x200(%rbp), %rdi
callq 0x5136
movl %eax, %r12d
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x2876
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 0x296b
movl %r12d, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x2ab1
leaq -0x680(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ada
leaq -0x680(%rbp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x4e3d
movl %eax, %r12d
movq %rbx, %rdi
callq 0x3fe0
leaq -0x1d0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1e0(%rbp), %rdi
callq 0x3eac
movq -0x4f0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x1e0(%rbp), %rdi
callq 0x5136
movl %eax, %ebx
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0x293f
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 0x2980
movl %ebx, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x2993
leaq -0xe0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x403a
jmp 0x2ab1
leaq -0xe0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x403a
movq -0xd0(%rbp), %rax
movq -0xc0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x29b0
addq $0x4, %rax
jmp 0x29ec
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 -0x540(%rbp), %rdi
movq %rax, -0xd0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0x3ada
leaq -0x540(%rbp), %r14
movq %r14, %rdi
movl $0x3, %esi
callq 0x4e3d
movl %eax, %ebx
movq %r14, %rdi
callq 0x3fe0
shlq $0x20, %rbx
movl %r12d, %r12d
orq %rbx, %r12
movq %r12, -0x70(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x45c2
leaq -0x2a8(%rbp), %rcx
cmpq %rcx, %rax
je 0x2a97
movq %r12, -0x70(%rbp)
leaq -0x2b0(%rbp), %rbx
movq %rbx, %rdi
leaq -0x70(%rbp), %rsi
callq 0x3baa
movss (%rax), %xmm0
movss %xmm0, -0x30(%rbp)
movq %r12, -0x180(%rbp)
movq %rbx, %rdi
leaq -0x180(%rbp), %rsi
callq 0x3baa
movss -0x30(%rbp), %xmm0
addss 0x3577(%rip), %xmm0     # 0x6008
movss %xmm0, (%rax)
jmp 0x2ab1
movq %r12, -0x70(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3baa
movl $0x3f800000, (%rax)     # imm = 0x3F800000
incl -0x34(%rbp)
movq -0x4f0(%rbp), %rdi
leaq -0x4e0(%rbp), %rax
cmpq %rax, %rdi
je 0x2ad6
movq -0x4e0(%rbp), %rsi
incq %rsi
callq 0x21d0
addq $0x20, %r15
jmp 0x276a
movl $0x2, %edx
movq 0x64e5(%rip), %rdi      # 0x8fd0
leaq 0x382e(%rip), %rsi      # 0x6320
callq 0x21f0
leaq -0x140(%rbp), %rdi
callq 0x3a70
movq -0x880(%rbp), %rdi
leaq -0x870(%rbp), %rax
cmpq %rax, %rdi
leaq -0x2fe0(%rbp), %rbx
leaq -0x270(%rbp), %r15
je 0x2648
movq -0x870(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x2648
movl $0x0, -0x34(%rbp)
movq 0x6486(%rip), %rdi      # 0x8fd0
leaq 0x3579(%rip), %rsi      # 0x60ca
movl $0x1a, %edx
callq 0x21f0
jmp 0x2b70
leaq -0x2fe0(%rbp), %rdi
leaq -0x1c48(%rbp), %r14
callq 0x2050
leaq -0x2fe0(%rbp), %rdi
callq 0x2070
movq -0x1c58(%rbp), %rdi
cmpq %r14, %rdi
je 0x2b97
movq -0x1c48(%rbp), %rsi
incq %rsi
callq 0x21d0
movq $0x1571, -0x2fe0(%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, -0x2fe0(%rbp,%rax,8)
incq %rax
cmpq $0x270, %rax            # imm = 0x270
jne 0x2bac
movq $0x270, -0x1c60(%rbp) # imm = 0x270
leaq -0x1c58(%rbp), %rdi
callq 0x3c3a
leaq -0x1c58(%rbp), %rdi
callq 0x2230
movl %eax, %eax
movq %rax, -0x2fe0(%rbp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, -0x2fe0(%rbp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x2c01
movq $0x270, -0x1c60(%rbp) # imm = 0x270
leaq -0x1c58(%rbp), %rdi
callq 0x2190
movq $0x1, -0x2e8(%rbp)
movq $0x3, -0x2e0(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x33cb(%rip), %rsi      # 0x602d
leaq 0x33d1(%rip), %rdx      # 0x603a
leaq -0x70(%rbp), %rdi
callq 0x3f46
leaq -0x1c58(%rbp), %rdi
callq 0x22d0
leaq -0x1c58(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
leaq -0x170(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x3440(%rip), %rsi      # 0x60e5
leaq 0x344f(%rip), %rdx      # 0x60fb
leaq -0x180(%rbp), %rdi
callq 0x3f46
leaq -0x880(%rbp), %rdi
callq 0x22d0
leaq -0x880(%rbp), %rdi
leaq -0x180(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
leaq -0x150(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x340e(%rip), %rsi      # 0x60fc
leaq 0x341a(%rip), %rdx      # 0x610f
leaq -0x160(%rbp), %rdi
callq 0x3f46
leaq -0x4f0(%rbp), %rdi
callq 0x22d0
leaq -0x4f0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
movl $0x1, %edx
callq 0x20d0
movq $0x0, -0x50(%rbp)
movq 0x629c(%rip), %r15      # 0x8fd0
leaq -0x140(%rbp), %r12
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x22, %edx
movq %r15, %rdi
leaq 0x33b8(%rip), %rsi      # 0x6110
callq 0x21f0
movq 0x627c(%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 0x2d9b
movl $0x19, %edx
movq %r15, %rdi
leaq 0x34ae(%rip), %rsi      # 0x6242
callq 0x21f0
jmp 0x2d49
movb -0x29(%rbp), %al
cmpb $0x45, %al
je 0x3407
movb %al, -0x140(%rbp)
movl $0x1, %edx
leaq -0x1c58(%rbp), %rdi
movq %r12, %rsi
callq 0x21f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3530(%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 0x3eac
movsbl -0x29(%rbp), %esi
leaq -0x1c0(%rbp), %rdi
callq 0x5136
movl %eax, %r14d
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x2e34
movq -0x1b0(%rbp), %rsi
incq %rsi
callq 0x21d0
movl %r14d, -0x3c(%rbp)
cmpl $0x2, -0x34(%rbp)
jg 0x2f38
movl $0x46, %edx
movq %r15, %rdi
leaq 0x330a(%rip), %rsi      # 0x615b
callq 0x21f0
leaq -0x2e8(%rbp), %rdi
leaq -0x2fe0(%rbp), %rsi
movq %rdi, %rdx
callq 0x48da
movq -0x90(%rbp), %rcx
movb (%rcx,%rax), %bl
movb %bl, -0x140(%rbp)
movl $0x1, %edx
leaq -0x880(%rbp), %rdi
movq %r12, %rsi
callq 0x21f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3460(%rip), %rsi      # 0x62ff
callq 0x21f0
movl $0x40, %edx
movq %r15, %rdi
leaq 0x32ef(%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 0x4de1
movq -0xb0(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x31e9
movl -0x3c(%rbp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x31f9
leaq -0x630(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ada
leaq -0x630(%rbp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x4e3d
movl %eax, %r14d
movq %rbx, %rdi
callq 0x3fe0
leaq -0x5e0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ada
leaq -0x5e0(%rbp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x4e3d
movq %rbx, %rdi
callq 0x3fe0
leaq -0x230(%rbp), %rax
movq %rax, -0x240(%rbp)
leaq -0x240(%rbp), %rdi
leaq 0x3087(%rip), %rsi      # 0x603c
leaq 0x3083(%rip), %rdx      # 0x603f
callq 0x3f46
movl $0x0, -0x38(%rbp)
movl %r14d, %ebx
movq %r12, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ada
movq -0x110(%rbp), %rax
movq -0x108(%rbp), %rdi
cmpq %rdi, %rax
je 0x2ff3
addq $-0x4, %rax
jmp 0x302e
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)
movq -0x100(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x3057
movl -0x38(%rbp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, -0x110(%rbp)
jmp 0x3063
movq %r12, %rdi
leaq -0x38(%rbp), %rsi
callq 0x403a
leaq -0x8d0(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3ada
movq %r13, %rdi
movl $0x3, %esi
callq 0x4e3d
movl %eax, %r14d
movq %r13, %rdi
callq 0x3fe0
shlq $0x20, %r14
orq %rbx, %r14
movq %r14, -0xe8(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3baa
cvttss2si (%rax), %eax
movslq -0x38(%rbp), %rcx
movl %eax, -0x2bc(%rbp,%rcx,4)
movq %r12, %rdi
callq 0x3fe0
movl -0x38(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x38(%rbp)
cmpl $0x2, %eax
jl 0x2fcb
movl $0x2, %edx
movq %r15, %rdi
leaq 0x323a(%rip), %rsi      # 0x6320
callq 0x21f0
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0x3156
movl $0x24, %edx
movq %r15, %rdi
leaq 0x30e0(%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 0x30cc(%rip), %rsi      # 0x6208
callq 0x21f0
movl -0x2bc(%rbp,%r13,4), %esi
incq %r13
movq %r14, %rdi
callq 0x22e0
jmp 0x30ee
leaq -0x2bc(%rbp), %rdi
movss 0x2e9f(%rip), %xmm0     # 0x6004
callq 0x519c
cltq
movq -0x90(%rbp), %rcx
movsbl (%rcx,%rax), %edi
callq 0x532a
movb %al, -0x30(%rbp)
movl $0x34, %edx
movq %r15, %rdi
leaq 0x307f(%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 0x3166(%rip), %rsi      # 0x6321
callq 0x21f0
movq -0xb0(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x3236
movl -0x3c(%rbp), %ecx
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x3246
leaq -0xe0(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x403a
movsbl -0x29(%rbp), %edi
movl %r14d, %esi
callq 0x52bc
cmpl $0x1, %eax
jne 0x3219
movq -0x50(%rbp), %rax
incl %eax
movq %rax, -0x50(%rbp)
jmp 0x33ff
movsbl -0x29(%rbp), %edi
movl %r14d, %esi
callq 0x52f3
cmpl $0x1, %eax
jne 0x33d5
incl -0x44(%rbp)
jmp 0x33ff
leaq -0xe0(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x403a
movq -0xd0(%rbp), %rax
movq -0xc0(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
je 0x3263
addq $0x4, %rax
jmp 0x329f
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 -0x590(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x3ada
leaq -0x590(%rbp), %r13
movq %r13, %rdi
movl $0x3, %esi
callq 0x4e3d
movl %eax, %r14d
movq %r13, %rdi
callq 0x3fe0
movb -0x30(%rbp), %al
movb %al, -0x140(%rbp)
movl $0x1, %edx
leaq -0x880(%rbp), %rdi
movq %r12, %rsi
callq 0x21f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2ffb(%rip), %rsi      # 0x62ff
callq 0x21f0
shlq $0x20, %r14
orq %r14, %rbx
movq %rbx, -0x140(%rbp)
leaq -0x2b0(%rbp), %rdi
movq %r12, %rsi
callq 0x45c2
leaq -0x2a8(%rbp), %rcx
cmpq %rcx, %rax
je 0x3383
movq %rbx, -0x140(%rbp)
leaq -0x2b0(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x3baa
movss (%rax), %xmm0
movss %xmm0, -0xec(%rbp)
movq %rbx, -0xe8(%rbp)
movq %r14, %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3baa
movss -0xec(%rbp), %xmm0
addss 0x2c8b(%rip), %xmm0     # 0x6008
movss %xmm0, (%rax)
jmp 0x339f
movq %rbx, -0x140(%rbp)
leaq -0x2b0(%rbp), %rdi
movq %r12, %rsi
callq 0x3baa
movl $0x3f800000, (%rax)     # imm = 0x3F800000
movsbl -0x29(%rbp), %edi
movsbl -0x30(%rbp), %r14d
movl %r14d, %esi
callq 0x52bc
testl %eax, %eax
je 0x33c0
movq -0x50(%rbp), %rax
incl %eax
movq %rax, -0x50(%rbp)
jmp 0x33dd
movsbl -0x29(%rbp), %edi
movl %r14d, %esi
callq 0x52f3
testl %eax, %eax
je 0x33da
incl -0x44(%rbp)
jmp 0x33dd
incl -0x40(%rbp)
jmp 0x33ff
incl -0x40(%rbp)
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x33ff
movq -0x230(%rbp), %rsi
incq %rsi
callq 0x21d0
incl -0x34(%rbp)
jmp 0x2d49
movq 0x5bc2(%rip), %rdi      # 0x8fd0
leaq 0x2d1e(%rip), %rsi      # 0x6133
movl $0x14, %edx
callq 0x21f0
leaq 0x2d22(%rip), %rsi      # 0x6148
leaq -0x4f0(%rbp), %rdi
movl $0x5, %edx
callq 0x21f0
leaq -0x4f0(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x22e0
leaq 0x2ed4(%rip), %rsi      # 0x6321
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
leaq 0x2ced(%rip), %rsi      # 0x614e
leaq -0x4f0(%rbp), %rdi
movl $0x6, %edx
callq 0x21f0
leaq -0x4f0(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x22e0
leaq 0x2e99(%rip), %rsi      # 0x6321
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
leaq 0x2cb9(%rip), %rsi      # 0x6155
leaq -0x4f0(%rbp), %rdi
movl $0x5, %edx
callq 0x21f0
leaq -0x4f0(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x22e0
leaq 0x2e5d(%rip), %rsi      # 0x6321
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
movq 0x5af0(%rip), %rax      # 0x8fc8
movq (%rax), %rbx
movq 0x18(%rax), %r14
leaq -0x4e8(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x4f0(%rbp,%rax)
callq 0x2170
leaq -0x3f8(%rbp), %rdi
callq 0x20a0
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x3529
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x878(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x880(%rbp,%rax)
callq 0x2170
leaq -0x788(%rbp), %rdi
callq 0x20a0
movq -0x180(%rbp), %rdi
leaq -0x170(%rbp), %rax
cmpq %rax, %rdi
je 0x3573
movq -0x170(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x1c50(%rbp), %rdi
movq %rbx, -0x8(%rdi)
movq -0x18(%rbx), %rax
movq %r14, -0x1c58(%rbp,%rax)
callq 0x2170
leaq -0x1b60(%rbp), %rdi
callq 0x20a0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x35b4
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0xe0(%rbp), %rdi
callq 0x3fe0
movq -0x2d8(%rbp), %rdi
testq %rdi, %rdi
je 0x35db
movq -0x2c8(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq -0x2b0(%rbp), %rdi
callq 0x3e4e
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x3609
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3625
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x1a0(%rbp), %rdi
leaq -0x190(%rbp), %rax
cmpq %rax, %rdi
je 0x3647
movq -0x190(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x3669
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 0x392f
movq %rax, %rbx
jmp 0x393e
jmp 0x368c
movq %rax, %rbx
jmp 0x3960
movq %rax, %rbx
jmp 0x396c
jmp 0x369e
movq %rax, %rbx
jmp 0x398e
movq %rax, %rbx
jmp 0x399a
jmp 0x36e0
jmp 0x36c6
movq %rax, %rbx
leaq -0x1c58(%rbp), %rdi
callq 0x2190
jmp 0x39b3
movq %rax, %rdi
callq 0x3cb7
jmp 0x36e0
movq %rax, %rbx
jmp 0x38ba
movq %rax, %rbx
jmp 0x38c6
movq %rax, %rbx
jmp 0x39b3
movq %rax, %rbx
jmp 0x39bf
movq %rax, %rbx
jmp 0x39da
movq %rax, %rbx
jmp 0x3a08
movq %rax, %rbx
jmp 0x3a24
movq %rax, %rbx
jmp 0x3a46
jmp 0x3908
jmp 0x3908
jmp 0x3908
jmp 0x392f
movq %rax, %rbx
leaq -0x590(%rbp), %rdi
jmp 0x38ff
jmp 0x3908
jmp 0x3908
jmp 0x3908
movq %rax, %rbx
leaq -0x630(%rbp), %rdi
jmp 0x375d
jmp 0x392f
movq %rax, %rbx
leaq -0x5e0(%rbp), %rdi
callq 0x3fe0
jmp 0x3932
jmp 0x3882
movq %rax, %rbx
movq -0x280(%rbp), %rdi
cmpq %r15, %rdi
je 0x3885
movq -0x270(%rbp), %rsi
jmp 0x3878
jmp 0x3882
jmp 0x385b
movq %rax, %rbx
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x3932
movq -0x1b0(%rbp), %rsi
jmp 0x3925
movq %rax, %rbx
leaq -0x1c48(%rbp), %r14
jmp 0x38ba
jmp 0x385b
jmp 0x385b
jmp 0x392f
movq %rax, %rbx
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x385e
movq -0x1f0(%rbp), %rsi
jmp 0x3823
jmp 0x385b
movq %rax, %rbx
leaq -0x540(%rbp), %rdi
jmp 0x3837
movq %rax, %rbx
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0x385e
movq -0x1d0(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x385e
movq %rax, %rbx
leaq -0x680(%rbp), %rdi
callq 0x3fe0
jmp 0x385e
jmp 0x392f
jmp 0x392f
jmp 0x385b
jmp 0x392f
jmp 0x3908
jmp 0x385b
jmp 0x38f5
movq %rax, %rbx
movq -0x4f0(%rbp), %rdi
leaq -0x4e0(%rbp), %rax
cmpq %rax, %rdi
je 0x3885
movq -0x4e0(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x3885
movq %rax, %rbx
leaq -0x1c48(%rbp), %r14
leaq -0x140(%rbp), %rdi
callq 0x3a70
movq -0x880(%rbp), %rdi
leaq -0x870(%rbp), %rax
cmpq %rax, %rdi
je 0x38ba
movq -0x870(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x2fe0(%rbp), %rdi
callq 0x2070
movq -0x1c58(%rbp), %rdi
cmpq %r14, %rdi
je 0x39b3
movq -0x1c48(%rbp), %rsi
jmp 0x39ab
movq %rax, %rbx
leaq -0x8d0(%rbp), %rdi
callq 0x3fe0
jmp 0x38f8
jmp 0x38f5
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x3fe0
jmp 0x390b
jmp 0x3908
movq %rax, %rbx
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x3932
movq -0x230(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x3932
movq %rax, %rbx
leaq -0x4f0(%rbp), %rdi
callq 0x2250
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x3960
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x880(%rbp), %rdi
callq 0x2250
movq -0x180(%rbp), %rdi
leaq -0x170(%rbp), %rax
cmpq %rax, %rdi
je 0x398e
movq -0x170(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x1c58(%rbp), %rdi
callq 0x2250
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x39b3
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0xe0(%rbp), %rdi
callq 0x3fe0
movq -0x2d8(%rbp), %rdi
testq %rdi, %rdi
je 0x39da
movq -0x2c8(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq -0x2b0(%rbp), %rdi
callq 0x3e4e
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0x3a08
movq -0x250(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3a24
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x190(%rbp), %rax
movq -0x1a0(%rbp), %rdi
cmpq %rax, %rdi
je 0x3a46
movq -0x190(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x210(%rbp), %rax
movq -0x220(%rbp), %rdi
cmpq %rax, %rdi
je 0x3a68
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x2310