// File: ATOMIC-LICHESS[P]ATOMKRAFT/create_book.cpp
// Function: createBookEAO()
void createBookEAO() {

	FILE* rf;
	rf = fopen("d:/eao.txt", "r");
	if (rf == NULL) {
		cout << "ERROR: open eao.txt" << endl;
	}

	FILE* wf;
	wf = fopen("d:/eao.bin", "wb");
	if (rf == NULL) {
		cout << "ERROR: open eao.bin" << endl;
	}

	Position pos("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 0, 0);




	int st_index = 0;

	//Move pv[LINE_COUNT][BOOK_MAX_PLY];	// deepest variation has 22 plies
	int pv_index = 0;


	list<char*> strlist;
	char token[MAX_LINE_LENGTH];
	char* s;	// traverses str
	char* t;	// traverses token

	int lines = 0;
	while (!feof(rf)) {
		// read a line
		fgets(str[lines], MAX_LINE_LENGTH, rf);

		// clear the line of unwanted characters and comments
		char* c = strchr(str[lines], '#');
		if (c) *c = 0;
		c = strchr(str[lines], 10);
		if (c) *c = 0;

		for (c = str[lines] + strlen(str[lines]) - 1; c >= str[lines]; --c) {
			if (isspace(*c) || *c == 0) {
				*c = 0;
			} else {
				break;
			}
		}


		if (*str[lines]) {
			//cout << str[lines] << endl;

			strlist.push_back(str[lines]);
			++lines;
		}
	}


	// 1. clear the file of redundancies
	//    that way we guarantee that the position at the end of every pv is unique
	for (list<char*>::iterator it1 = strlist.begin(); it1 != strlist.end(); ++it1) {
		for (list<char*>::iterator it2 = strlist.begin(); it2 != strlist.end(); ++it2) {
			if (*it1 != *it2) {
				if (strlen(*it2) < strlen (*it1)) {
					if (strncmp(*it2, *it1, strlen(*it2) - 1) == 0) {
						// *it1 starts with of *it2 so delete *it2
						it2 = strlist.erase(it2);
					}
				}
			}
		}
	}

	// 2. fill the pv array
	for (list<char*>::iterator it = strlist.begin(); it != strlist.end(); ++it) {
		cout << *it << endl;

		pos.from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 0);

		// parse the string
		s = *it;
		t = token;

		Color color = WHITE;
		int move_count = 0;
		while (*s != 10 && *s != 0) {

			*t++ = *s++;

			if (*s == ' ' || *s == 10 || *s == 0) {
				*t = 0;

				// we have a new token
				bool playable = (*token != '?');

				Move m = san_to_move(pos, playable ? token : token+1);

				//cout << "  " << token << " ";
				if (m == MOVE_NONE) {
					cout << "ERROR: " << token << endl;
					return;
				} else {
					//cout << move_to_string(m) << endl;
				}

				pos.do_move(m, st[st_index]);
				pv[pv_index][move_count].move = m;
				pv[pv_index][move_count].playable = playable;


				++st_index;
				if (st_index >= STATEINFO_COUNT) st_index = 0;
				++move_count;
				color = opposite_color(color);
				t = token;
				if (*s == ' ') ++s;
			}
		}

		// undo all moves of the pv
		for (int k = move_count - 1; k >= 0; --k) {
			pos.undo_move(pv[pv_index][k].move );
		}
		pv[pv_index][move_count].move  = MOVE_NONE;
		++pv_index;
	}

	// 3. create a tree from the pvs
	//    note that it is important that the pvs are already sorted
	MoveTreeNode rootNode;
	MoveTreeNode* node = &rootNode;
	rootNode.ms.move = MOVE_NONE;
	rootNode.child_count = 0;
	rootNode.depth = 0;
	rootNode.parent = 0;
	rootNode.visited = false;

	BookPV* pv_curr;
	BookPV* pv_next;
	int depth = 0;
	int split_depth = 0;

	for (int i = 0; i < pv_index; ++i) {
		pv_curr = pv[i];

		if (i + 1 < pv_index) {
			pv_next = pv[i+1];
		} else {
			pv_next = pv_curr;
		}

		depth = split_depth;

		// correct indentation
		for (int k = 0; k < split_depth; ++k) {
			//cout << "     ";
		}

		while (pv_curr[depth].move != MOVE_NONE) {
			//cout << move_to_string(pv_curr[depth]) << " ";

			// create new node
			node->child[node->child_count] = new MoveTreeNode();
			node->child[node->child_count]->child_count = 0;
			node->child[node->child_count]->depth = depth + 1;
			node->child[node->child_count]->parent = node;
			node->child[node->child_count]->ms.move  = pv_curr[depth].move;
			node->child[node->child_count]->ms.score = pv_curr[depth].playable;
			node->child[node->child_count]->visited = false;
			++node->child_count;

			node = node->child[node->child_count-1];


			++depth;
		}
		//cout << endl;

		// find the split depth
		depth = 0;
		split_depth = 0;
		// the ending position of any pv is unique so the exit condition will never be reached
		while (pv_curr[depth].move != MOVE_NONE) {
			if (pv_curr[depth].move != pv_next[depth].move) {
				split_depth = depth;
				break;
			}
			++depth;
		}

		// move inside the tree such that node->depth == split_depth
		while (node->depth > split_depth) {
			node = node->parent;
		}

		assert(node->depth == split_depth);
	}



	// 4. score the nodes by the number of successors
	//    if ms.score == false holds, the move is considered not playable
	rootNode.ms.score = 1;

	printTree(&rootNode);
	cout << "positions: " << numberOfNodes(&rootNode) << endl;

//	// don't play bad openings as white
//	for (int k = 0; k < rootNode.child_count; ++k) {
//		Square to = move_to(rootNode.child[k]->ms.move);
//		if (   to == SQ_B4 || to == SQ_G3 || to == SQ_B4 || to == SQ_H3
//			|| to == SQ_E4 || to == SQ_A3 || to == SQ_C3 || to == SQ_D4) {
//			rootNode.child[k]->ms.score = 0;
//		}
//	}


	// 5. breadth-first search to write the moves into the book
	list<BookEntry*> book_entries;

	queue<MoveTreeNode*> qu;

	qu.push(&rootNode);
	rootNode.visited = true;

	pos.from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", 0);
	st_index = 0;
	Move pv_tree[30];
	int pv_len = 0;
	int moves_made = 0;

	while (!qu.empty()) {
		node = qu.front();
		qu.pop();

//		for (int k = 0; k < node->depth; ++k) {
//			cout << "     ";
//		}
//		cout << move_to_string(node->ms.move) << endl;


		// get the pv of our current node in reversed order
		pv_len = 0;
		MoveTreeNode* node_aux = node;
		while (node_aux->parent) {
			pv_tree[pv_len] = node_aux->ms.move;
			++pv_len;
			node_aux = node_aux->parent;
		}

		// do all moves of the pv
		for (int k = pv_len - 1; k >= 0; --k) {
			pos.do_move(pv_tree[k], st[st_index]);
			++st_index;
			if (st_index >= STATEINFO_COUNT) st_index = 0;
			++moves_made;
		}


		// the actual bfs
		for (int k = 0; k < node->child_count; ++k) {
			if(node->child[k]->visited == false) {
				qu.push(node->child[k]);
				node->child[k]->visited = true;

				// write the move to the book
//				write_entry(
//					wf,
//					book_key(pos),
//					node->child[k]->ms.move,
//					node->child[k]->ms.score
//				);
				BookEntry* be = new BookEntry;
				be->key = book_key(pos);
				be->move = uint16_t(node->child[k]->ms.move);
				be->count = node->child[k]->ms.score;
				be->learn = 0;
				book_entries.push_back(be);
			}
		}



		// undo all moves of the pv
		for (int k = 0; k < pv_len; ++k) {
			//cout << ".";
			pos.undo_move(pv_tree[k]);
		}
	}


	cout << moves_made << " moves made" << endl;

	book_entries.sort(compare_key);
	for (list<BookEntry*>::iterator it = book_entries.begin(); it != book_entries.end(); ++it) {
		//cout << (*it)->key << endl;
		write_entry(wf, (*it)->key, Move((*it)->move), (*it)->count);
		delete *it;
	}
	killChildren(&rootNode);

	fclose(rf);
	fclose(wf);

}

// Assembly:
subq $0x1f78, %rsp           # imm = 0x1F78
leaq 0x48e84(%rip), %rdi     # 0x59562
leaq 0x4ae99(%rip), %rsi     # 0x5b57e
callq 0x65f0
movq %rax, 0x1f70(%rsp)
cmpq $0x0, 0x1f70(%rsp)
jne 0x1071f
movq 0x5b8b4(%rip), %rdi     # 0x6bfb8
leaq 0x48e62(%rip), %rsi     # 0x5956d
callq 0x64b0
movq %rax, %rdi
movq 0x5b876(%rip), %rsi     # 0x6bf90
callq 0x6520
leaq 0x48e5b(%rip), %rdi     # 0x59581
leaq 0x48e5f(%rip), %rsi     # 0x5958c
callq 0x65f0
movq %rax, 0x1f68(%rsp)
cmpq $0x0, 0x1f70(%rsp)
jne 0x10767
movq 0x5b86c(%rip), %rdi     # 0x6bfb8
leaq 0x48e3c(%rip), %rsi     # 0x5958f
callq 0x64b0
movq %rax, %rdi
movq 0x5b82e(%rip), %rsi     # 0x6bf90
callq 0x6520
leaq 0x607(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
callq 0x6980
movq 0xf0(%rsp), %rdx
leaq 0x48e18(%rip), %rsi     # 0x595a3
leaq 0x608(%rsp), %rdi
callq 0x12070
jmp 0x1079a
leaq 0x628(%rsp), %rdi
leaq 0x608(%rsp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x36520
jmp 0x107b5
leaq 0x608(%rsp), %rdi
callq 0x6a78
leaq 0x607(%rsp), %rdi
callq 0x6550
movl $0x0, 0x5f0(%rsp)
movl $0x0, 0x5ec(%rsp)
leaq 0x5d0(%rsp), %rdi
callq 0x12130
movl $0x0, 0x3bc(%rsp)
movq 0x1f70(%rsp), %rdi
callq 0x67e0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1081b
jmp 0x10a65
movslq 0x3bc(%rsp), %rax
imulq $0x1f4, %rax, %rax      # imm = 0x1F4
leaq 0x2dd9ff(%rip), %rdi    # 0x2ee230
addq %rax, %rdi
movq 0x1f70(%rsp), %rdx
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x6820
jmp 0x10848
movslq 0x3bc(%rsp), %rax
leaq 0x2dd9d9(%rip), %rdi    # 0x2ee230
imulq $0x1f4, %rax, %rax      # imm = 0x1F4
addq %rax, %rdi
movl $0x23, %esi
callq 0x6190
movq %rax, 0x3b0(%rsp)
cmpq $0x0, 0x3b0(%rsp)
je 0x108ed
movq 0x3b0(%rsp), %rax
movb $0x0, (%rax)
jmp 0x108ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
jmp 0x108c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
leaq 0x608(%rsp), %rdi
callq 0x6a78
leaq 0x607(%rsp), %rdi
callq 0x6550
jmp 0x11b74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
jmp 0x11b67
movslq 0x3bc(%rsp), %rax
leaq 0x2dd934(%rip), %rdi    # 0x2ee230
imulq $0x1f4, %rax, %rax      # imm = 0x1F4
addq %rax, %rdi
movl $0xa, %esi
callq 0x6190
movq %rax, 0x3b0(%rsp)
cmpq $0x0, 0x3b0(%rsp)
je 0x1092e
movq 0x3b0(%rsp), %rax
movb $0x0, (%rax)
movslq 0x3bc(%rsp), %rcx
leaq 0x2dd8f3(%rip), %rax    # 0x2ee230
imulq $0x1f4, %rcx, %rcx      # imm = 0x1F4
addq %rcx, %rax
movq %rax, 0xe8(%rsp)
movslq 0x3bc(%rsp), %rax
leaq 0x2dd8d2(%rip), %rdi    # 0x2ee230
imulq $0x1f4, %rax, %rax      # imm = 0x1F4
addq %rax, %rdi
callq 0x61f0
movq %rax, %rcx
movq 0xe8(%rsp), %rax
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, 0x3b0(%rsp)
movq 0x3b0(%rsp), %rax
movslq 0x3bc(%rsp), %rdx
leaq 0x2dd892(%rip), %rcx    # 0x2ee230
imulq $0x1f4, %rdx, %rdx      # imm = 0x1F4
addq %rdx, %rcx
cmpq %rcx, %rax
jb 0x109f9
movq 0x3b0(%rsp), %rax
movsbl (%rax), %edi
callq 0x60c0
cmpl $0x0, %eax
jne 0x109d2
movq 0x3b0(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x109df
movq 0x3b0(%rsp), %rax
movb $0x0, (%rax)
jmp 0x109e1
jmp 0x109f9
jmp 0x109e3
movq 0x3b0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x3b0(%rsp)
jmp 0x10987
movslq 0x3bc(%rsp), %rcx
leaq 0x2dd828(%rip), %rax    # 0x2ee230
imulq $0x1f4, %rcx, %rcx      # imm = 0x1F4
addq %rcx, %rax
cmpb $0x0, (%rax)
je 0x10a60
movslq 0x3bc(%rsp), %rax
imulq $0x1f4, %rax, %rcx      # imm = 0x1F4
leaq 0x2dd803(%rip), %rax    # 0x2ee230
addq %rcx, %rax
movq %rax, 0x3a8(%rsp)
leaq 0x5d0(%rsp), %rdi
leaq 0x3a8(%rsp), %rsi
callq 0x12140
jmp 0x10a4f
movl 0x3bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3bc(%rsp)
jmp 0x107fd
leaq 0x5d0(%rsp), %rdi
callq 0x12180
movq %rax, 0x3a0(%rsp)
leaq 0x5d0(%rsp), %rdi
callq 0x121d0
movq %rax, 0x398(%rsp)
leaq 0x3a0(%rsp), %rdi
leaq 0x398(%rsp), %rsi
callq 0x121b0
testb $0x1, %al
jne 0x10aad
jmp 0x10c48
leaq 0x5d0(%rsp), %rdi
callq 0x12180
movq %rax, 0x390(%rsp)
leaq 0x5d0(%rsp), %rdi
callq 0x121d0
movq %rax, 0x388(%rsp)
leaq 0x390(%rsp), %rdi
leaq 0x388(%rsp), %rsi
callq 0x121b0
testb $0x1, %al
jne 0x10af5
jmp 0x10c34
leaq 0x3a0(%rsp), %rdi
callq 0x12200
movq (%rax), %rax
movq %rax, 0xe0(%rsp)
leaq 0x390(%rsp), %rdi
callq 0x12200
movq %rax, %rcx
movq 0xe0(%rsp), %rax
cmpq (%rcx), %rax
je 0x10c20
leaq 0x390(%rsp), %rdi
callq 0x12200
movq (%rax), %rdi
callq 0x61f0
movq %rax, 0xd8(%rsp)
leaq 0x3a0(%rsp), %rdi
callq 0x12200
movq (%rax), %rdi
callq 0x61f0
movq %rax, %rcx
movq 0xd8(%rsp), %rax
cmpq %rcx, %rax
jae 0x10c1e
leaq 0x390(%rsp), %rdi
callq 0x12200
movq (%rax), %rax
movq %rax, 0xc8(%rsp)
leaq 0x3a0(%rsp), %rdi
callq 0x12200
movq (%rax), %rax
movq %rax, 0xd0(%rsp)
leaq 0x390(%rsp), %rdi
callq 0x12200
movq (%rax), %rdi
callq 0x61f0
movq 0xc8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq %rax, %rdx
subq $0x1, %rdx
callq 0x6240
cmpl $0x0, %eax
jne 0x10c1c
leaq 0x378(%rsp), %rdi
leaq 0x390(%rsp), %rsi
callq 0x12270
movq 0x378(%rsp), %rsi
leaq 0x5d0(%rsp), %rdi
callq 0x12220
movq %rax, 0x380(%rsp)
movq 0x380(%rsp), %rax
movq %rax, 0x390(%rsp)
jmp 0x10c1e
jmp 0x10c20
jmp 0x10c22
leaq 0x390(%rsp), %rdi
callq 0x12290
jmp 0x10ac2
jmp 0x10c36
leaq 0x3a0(%rsp), %rdi
callq 0x12290
jmp 0x10a7a
leaq 0x5d0(%rsp), %rdi
callq 0x12180
movq %rax, 0x370(%rsp)
leaq 0x5d0(%rsp), %rdi
callq 0x121d0
movq %rax, 0x368(%rsp)
leaq 0x370(%rsp), %rdi
leaq 0x368(%rsp), %rsi
callq 0x121b0
testb $0x1, %al
jne 0x10c90
jmp 0x1111f
leaq 0x370(%rsp), %rdi
callq 0x12200
movq (%rax), %rsi
movq 0x5b311(%rip), %rdi     # 0x6bfb8
callq 0x64b0
movq %rax, 0xc0(%rsp)
jmp 0x10cb6
movq 0xc0(%rsp), %rdi
movq 0x5b2cb(%rip), %rsi     # 0x6bf90
callq 0x6520
jmp 0x10ccc
leaq 0x347(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x6980
movq 0xb8(%rsp), %rdx
leaq 0x488b3(%rip), %rsi     # 0x595a3
leaq 0x348(%rsp), %rdi
callq 0x12070
jmp 0x10cff
leaq 0x628(%rsp), %rdi
leaq 0x348(%rsp), %rsi
xorl %edx, %edx
callq 0x36580
jmp 0x10d18
leaq 0x348(%rsp), %rdi
callq 0x6a78
leaq 0x347(%rsp), %rdi
callq 0x6550
leaq 0x370(%rsp), %rdi
callq 0x12200
movq (%rax), %rax
movq %rax, 0x3c8(%rsp)
leaq 0x3d0(%rsp), %rax
movq %rax, 0x3c0(%rsp)
movl $0x0, 0x340(%rsp)
movl $0x0, 0x33c(%rsp)
movq 0x3c8(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, 0xb7(%rsp)
je 0x10da1
movq 0x3c8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0xb7(%rsp)
movb 0xb7(%rsp), %al
testb $0x1, %al
jne 0x10db1
jmp 0x11071
movq 0x3c8(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x3c8(%rsp)
movb (%rax), %cl
movq 0x3c0(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x3c0(%rsp)
movb %cl, (%rax)
movq 0x3c8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0x10e17
movq 0x3c8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
je 0x10e17
movq 0x3c8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x1106c
movq 0x3c0(%rsp), %rax
movb $0x0, (%rax)
movsbl 0x3d0(%rsp), %eax
cmpl $0x3f, %eax
setne %al
andb $0x1, %al
movb %al, 0x33b(%rsp)
testb $0x1, 0x33b(%rsp)
je 0x10e55
leaq 0x3d0(%rsp), %rax
movq %rax, 0xa8(%rsp)
jmp 0x10e69
leaq 0x3d0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rsi
leaq 0x628(%rsp), %rdi
callq 0x10020
movl %eax, 0xa4(%rsp)
jmp 0x10e87
movl 0xa4(%rsp), %eax
movl %eax, 0x334(%rsp)
cmpl $0x0, 0x334(%rsp)
jne 0x10f4e
movq 0x5b10e(%rip), %rdi     # 0x6bfb8
leaq 0x4872b(%rip), %rsi     # 0x595dc
callq 0x64b0
movq %rax, 0x98(%rsp)
jmp 0x10ec0
movq 0x98(%rsp), %rdi
leaq 0x3d0(%rsp), %rsi
callq 0x64b0
movq %rax, 0x90(%rsp)
jmp 0x10edf
movq 0x90(%rsp), %rdi
movq 0x5b0a2(%rip), %rsi     # 0x6bf90
callq 0x6520
jmp 0x10ef5
movl $0x1, 0x330(%rsp)
jmp 0x11b38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
jmp 0x10f3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
leaq 0x348(%rsp), %rdi
callq 0x6a78
leaq 0x347(%rsp), %rdi
callq 0x6550
jmp 0x11b67
jmp 0x10f50
movl 0x334(%rsp), %esi
movslq 0x5f0(%rsp), %rax
leaq (%rax,%rax,4), %rax
shlq $0x5, %rax
leaq 0x143042(%rip), %rdx    # 0x153fb0
addq %rax, %rdx
leaq 0x628(%rsp), %rdi
callq 0x3a390
jmp 0x10f80
movl 0x334(%rsp), %edx
movslq 0x5ec(%rsp), %rcx
leaq 0x15689a(%rip), %rax    # 0x167830
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movslq 0x33c(%rsp), %rcx
movl %edx, (%rax,%rcx,8)
movb 0x33b(%rsp), %dl
movslq 0x5ec(%rsp), %rcx
leaq 0x15686f(%rip), %rax    # 0x167830
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movslq 0x33c(%rsp), %rcx
andb $0x1, %dl
movb %dl, 0x4(%rax,%rcx,8)
movl 0x5f0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5f0(%rsp)
cmpl $0x1f4, 0x5f0(%rsp) # imm = 0x1F4
jl 0x11003
movl $0x0, 0x5f0(%rsp)
movl 0x33c(%rsp), %eax
incl %eax
movl %eax, 0x33c(%rsp)
movl 0x340(%rsp), %edi
callq 0x122b0
movl %eax, 0x8c(%rsp)
jmp 0x11028
movl 0x8c(%rsp), %eax
movl %eax, 0x340(%rsp)
leaq 0x3d0(%rsp), %rax
movq %rax, 0x3c0(%rsp)
movq 0x3c8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x1106a
movq 0x3c8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x3c8(%rsp)
jmp 0x1106c
jmp 0x10d70
movl 0x33c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x32c(%rsp)
cmpl $0x0, 0x32c(%rsp)
jl 0x110d4
movslq 0x5ec(%rsp), %rax
imulq $0x320, %rax, %rcx      # imm = 0x320
leaq 0x15678e(%rip), %rax    # 0x167830
addq %rcx, %rax
movslq 0x32c(%rsp), %rcx
movl (%rax,%rcx,8), %esi
leaq 0x628(%rsp), %rdi
callq 0x3c620
jmp 0x110bf
jmp 0x110c1
movl 0x32c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x32c(%rsp)
jmp 0x11082
movslq 0x5ec(%rsp), %rcx
leaq 0x15674d(%rip), %rax    # 0x167830
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movslq 0x33c(%rsp), %rcx
movl $0x0, (%rax,%rcx,8)
movl 0x5ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5ec(%rsp)
leaq 0x370(%rsp), %rdi
callq 0x12290
jmp 0x10c5d
leaq 0x268(%rsp), %rax
movq %rax, 0x260(%rsp)
movl $0x0, 0x314(%rsp)
movl $0x0, 0x310(%rsp)
movl $0x0, 0x320(%rsp)
movq $0x0, 0x268(%rsp)
movb $0x0, 0x324(%rsp)
movl $0x0, 0x24c(%rsp)
movl $0x0, 0x248(%rsp)
movl $0x0, 0x244(%rsp)
movl 0x244(%rsp), %eax
cmpl 0x5ec(%rsp), %eax
jge 0x114ca
movslq 0x244(%rsp), %rcx
leaq 0x156688(%rip), %rax    # 0x167830
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movq %rax, 0x258(%rsp)
movl 0x244(%rsp), %eax
addl $0x1, %eax
cmpl 0x5ec(%rsp), %eax
jge 0x111f5
movl 0x244(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x15664f(%rip), %rax    # 0x167830
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movq %rax, 0x250(%rsp)
jmp 0x11205
movq 0x258(%rsp), %rax
movq %rax, 0x250(%rsp)
movl 0x248(%rsp), %eax
movl %eax, 0x24c(%rsp)
movl $0x0, 0x240(%rsp)
movl 0x240(%rsp), %eax
cmpl 0x248(%rsp), %eax
jge 0x11243
jmp 0x11230
movl 0x240(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x240(%rsp)
jmp 0x1121e
jmp 0x11245
movq 0x258(%rsp), %rax
movslq 0x24c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,8)
je 0x1140d
movl $0xc0, %edi
callq 0x64d0
movq %rax, 0x80(%rsp)
jmp 0x11273
movq 0x80(%rsp), %rdi
xorl %esi, %esi
movl $0xc0, %edx
callq 0x6280
movq 0x80(%rsp), %rdx
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rcx
movslq 0xa8(%rcx), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rcx
movslq 0xa8(%rcx), %rcx
movq 0x8(%rax,%rcx,8), %rax
movl $0x0, 0xa8(%rax)
movl 0x24c(%rsp), %ecx
addl $0x1, %ecx
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rdx
movslq 0xa8(%rdx), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %ecx, 0xb8(%rax)
movq 0x260(%rsp), %rcx
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rdx
movslq 0xa8(%rdx), %rdx
movq 0x8(%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq 0x258(%rsp), %rax
movslq 0x24c(%rsp), %rcx
movl (%rax,%rcx,8), %ecx
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rdx
movslq 0xa8(%rdx), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %ecx, 0xac(%rax)
movq 0x258(%rsp), %rax
movslq 0x24c(%rsp), %rcx
movb 0x4(%rax,%rcx,8), %al
andb $0x1, %al
movzbl %al, %ecx
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rdx
movslq 0xa8(%rdx), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %ecx, 0xb0(%rax)
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rcx
movslq 0xa8(%rcx), %rcx
movq 0x8(%rax,%rcx,8), %rax
movb $0x0, 0xbc(%rax)
movq 0x260(%rsp), %rax
movl 0xa8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xa8(%rax)
movq 0x260(%rsp), %rax
movq 0x260(%rsp), %rcx
movl 0xa8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x260(%rsp)
movl 0x24c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24c(%rsp)
jmp 0x11245
movl $0x0, 0x24c(%rsp)
movl $0x0, 0x248(%rsp)
movq 0x258(%rsp), %rax
movslq 0x24c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,8)
je 0x11484
movq 0x258(%rsp), %rax
movslq 0x24c(%rsp), %rcx
movl (%rax,%rcx,8), %eax
movq 0x250(%rsp), %rcx
movslq 0x24c(%rsp), %rdx
cmpl (%rcx,%rdx,8), %eax
je 0x11471
movl 0x24c(%rsp), %eax
movl %eax, 0x248(%rsp)
jmp 0x11484
movl 0x24c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24c(%rsp)
jmp 0x11423
jmp 0x11486
movq 0x260(%rsp), %rax
movl 0xb8(%rax), %eax
cmpl 0x248(%rsp), %eax
jle 0x114b2
movq 0x260(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x260(%rsp)
jmp 0x11486
jmp 0x114b4
movl 0x244(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x244(%rsp)
jmp 0x11185
movl $0x1, 0x318(%rsp)
leaq 0x268(%rsp), %rdi
callq 0x10380
jmp 0x114e4
movq 0x5aacd(%rip), %rdi     # 0x6bfb8
leaq 0x480f2(%rip), %rsi     # 0x595e4
callq 0x64b0
movq %rax, 0x78(%rsp)
jmp 0x114fe
leaq 0x268(%rsp), %rdi
callq 0x10550
movl %eax, 0x74(%rsp)
jmp 0x11511
movl 0x74(%rsp), %esi
movq 0x78(%rsp), %rdi
callq 0x6940
movq %rax, 0x68(%rsp)
jmp 0x11526
movq 0x68(%rsp), %rdi
movq 0x5aa5e(%rip), %rsi     # 0x6bf90
callq 0x6520
jmp 0x11539
leaq 0x228(%rsp), %rdi
callq 0x122c0
leaq 0x1d8(%rsp), %rdi
callq 0x122d0
jmp 0x11555
leaq 0x268(%rsp), %rax
movq %rax, 0x1d0(%rsp)
leaq 0x1d8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x12300
jmp 0x1157c
movb $0x1, 0x324(%rsp)
leaq 0x1af(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x6980
movq 0x60(%rsp), %rdx
leaq 0x48001(%rip), %rsi     # 0x595a3
leaq 0x1b0(%rsp), %rdi
callq 0x12070
jmp 0x115b1
leaq 0x628(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
xorl %edx, %edx
callq 0x36580
jmp 0x115ca
leaq 0x1b0(%rsp), %rdi
callq 0x6a78
leaq 0x1af(%rsp), %rdi
callq 0x6550
movl $0x0, 0x5f0(%rsp)
movl $0x0, 0x12c(%rsp)
movl $0x0, 0x128(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x12330
movb %al, 0x5f(%rsp)
jmp 0x11618
movb 0x5f(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x11627
jmp 0x119a0
leaq 0x1d8(%rsp), %rdi
callq 0x12350
movq %rax, 0x50(%rsp)
jmp 0x1163b
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x260(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x12360
jmp 0x1165a
movl $0x0, 0x12c(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x120(%rsp), %rax
cmpq $0x0, (%rax)
je 0x11745
movq 0x120(%rsp), %rax
movl 0xac(%rax), %ecx
movslq 0x12c(%rsp), %rax
movl %ecx, 0x130(%rsp,%rax,4)
movl 0x12c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x12c(%rsp)
movq 0x120(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x120(%rsp)
jmp 0x11675
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
jmp 0x11b5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
jmp 0x11b4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
jmp 0x11733
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f8(%rsp)
movl %eax, 0x5f4(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x6a78
leaq 0x1af(%rsp), %rdi
callq 0x6550
jmp 0x11b4d
movl 0x12c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x11c(%rsp)
cmpl $0x0, 0x11c(%rsp)
jl 0x117ec
movslq 0x11c(%rsp), %rax
movl 0x130(%rsp,%rax,4), %esi
movslq 0x5f0(%rsp), %rax
leaq (%rax,%rax,4), %rax
shlq $0x5, %rax
leaq 0x142826(%rip), %rdx    # 0x153fb0
addq %rax, %rdx
leaq 0x628(%rsp), %rdi
callq 0x3a390
jmp 0x1179c
movl 0x5f0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5f0(%rsp)
cmpl $0x1f4, 0x5f0(%rsp) # imm = 0x1F4
jl 0x117c5
movl $0x0, 0x5f0(%rsp)
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
movl 0x11c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x11756
movl $0x0, 0x118(%rsp)
movl 0x118(%rsp), %eax
movq 0x260(%rsp), %rcx
cmpl 0xa8(%rcx), %eax
jge 0x1194d
movq 0x260(%rsp), %rax
movslq 0x118(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movb 0xbc(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x11935
movq 0x260(%rsp), %rax
movslq 0x118(%rsp), %rcx
leaq 0x8(%rax,%rcx,8), %rsi
leaq 0x1d8(%rsp), %rdi
callq 0x12370
jmp 0x1185f
movq 0x260(%rsp), %rax
movslq 0x118(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movb $0x1, 0xbc(%rax)
movl $0x10, %edi
callq 0x64d0
movq %rax, 0x48(%rsp)
jmp 0x1188c
movq 0x48(%rsp), %rax
movq %rax, 0x110(%rsp)
leaq 0x628(%rsp), %rdi
callq 0xe9e0
movq %rax, 0x40(%rsp)
jmp 0x118ad
movq 0x40(%rsp), %rcx
movq 0x110(%rsp), %rax
movq %rcx, (%rax)
movq 0x260(%rsp), %rax
movslq 0x118(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movw 0xac(%rax), %cx
movq 0x110(%rsp), %rax
movw %cx, 0x8(%rax)
movq 0x260(%rsp), %rax
movslq 0x118(%rsp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movw 0xb0(%rax), %cx
movq 0x110(%rsp), %rax
movw %cx, 0xa(%rax)
movq 0x110(%rsp), %rax
movl $0x0, 0xc(%rax)
leaq 0x228(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x123a0
jmp 0x11933
jmp 0x11935
jmp 0x11937
movl 0x118(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x118(%rsp)
jmp 0x117f7
movl $0x0, 0x10c(%rsp)
movl 0x10c(%rsp), %eax
cmpl 0x12c(%rsp), %eax
jge 0x1199b
movslq 0x10c(%rsp), %rax
movl 0x130(%rsp,%rax,4), %esi
leaq 0x628(%rsp), %rdi
callq 0x3c620
jmp 0x11986
jmp 0x11988
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x11958
jmp 0x11605
movl 0x128(%rsp), %esi
movq 0x5a60a(%rip), %rdi     # 0x6bfb8
callq 0x6940
movq %rax, 0x38(%rsp)
jmp 0x119ba
movq 0x38(%rsp), %rdi
leaq 0x47c2a(%rip), %rsi     # 0x595f0
callq 0x64b0
movq %rax, 0x30(%rsp)
jmp 0x119d2
movq 0x30(%rsp), %rdi
movq 0x5a5b2(%rip), %rsi     # 0x6bf90
callq 0x6520
jmp 0x119e5
leaq -0x133c(%rip), %rsi     # 0x106b0
leaq 0x228(%rsp), %rdi
callq 0x123e0
jmp 0x119fb
leaq 0x228(%rsp), %rdi
callq 0x127f0
movq %rax, 0x100(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x12840
movq %rax, 0xf8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x12820
testb $0x1, %al
jne 0x11a43
jmp 0x11ae6
movq 0x1f68(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x100(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x12870
movq 0x10(%rsp), %rdi
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
callq 0x12870
movq 0x10(%rsp), %rdi
movq (%rax), %rax
movzwl 0x8(%rax), %eax
movl %eax, 0x2c(%rsp)
callq 0x12870
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x2c(%rsp), %edx
movq (%rax), %rax
movzwl 0xa(%rax), %ecx
callq 0x105d0
jmp 0x11aa8
leaq 0x100(%rsp), %rdi
callq 0x12870
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x11ad2
movq 0x8(%rsp), %rdi
movl $0x10, %esi
callq 0x64e0
jmp 0x11ad4
leaq 0x100(%rsp), %rdi
callq 0x12890
jmp 0x11a10
leaq 0x268(%rsp), %rdi
callq 0xfeb0
jmp 0x11af5
movq 0x1f70(%rsp), %rdi
callq 0x64c0
jmp 0x11b04
movq 0x1f68(%rsp), %rdi
callq 0x64c0
jmp 0x11b13
leaq 0x1d8(%rsp), %rdi
callq 0x128b0
leaq 0x228(%rsp), %rdi
callq 0x128c0
movl $0x0, 0x330(%rsp)
leaq 0x5d0(%rsp), %rdi
callq 0x128d0
addq $0x1f78, %rsp           # imm = 0x1F78
retq
leaq 0x1d8(%rsp), %rdi
callq 0x128b0
leaq 0x228(%rsp), %rdi
callq 0x128c0
leaq 0x5d0(%rsp), %rdi
callq 0x128d0
movq 0x5f8(%rsp), %rdi
callq 0x6970
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)