// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d38, %rsp           # imm = 0x1D38
leaq 0x26dea(%rip), %rdi     # 0x30642
leaq 0x28d7f(%rip), %rsi     # 0x325de
callq 0x54a0
movq %rax, %r13
testq %rax, %rax
jne 0x98ae
movq 0x3272d(%rip), %rbx     # 0x3bfa0
leaq 0x26dd3(%rip), %rsi     # 0x3064d
movl $0x13, %edx
movq %rbx, %rdi
callq 0x5460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
leaq 0x26dac(%rip), %rdi     # 0x30661
leaq 0x26db0(%rip), %rsi     # 0x3066c
callq 0x54a0
movq %rax, %r15
testq %r13, %r13
jne 0x990b
movq 0x326d0(%rip), %rbx     # 0x3bfa0
leaq 0x26d98(%rip), %rsi     # 0x3066f
movl $0x13, %edx
movq %rbx, %rdi
callq 0x5460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
leaq 0x210(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x26d65(%rip), %rsi     # 0x30683
leaq 0x26d96(%rip), %rdx     # 0x306bb
leaq 0x200(%rsp), %rdi
callq 0xa7de
leaq 0x3f8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1c7c2
movq %r15, 0x60(%rsp)
movq 0x200(%rsp), %rdi
cmpq %rbx, %rdi
je 0x996d
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x5400
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
movq %r13, %rdi
callq 0x5650
testl %eax, %eax
jne 0x9a53
xorl %r15d, %r15d
leaq 0x2b4785(%rip), %r12    # 0x2be120
movslq %r15d, %rax
imulq $0x1f4, %rax, %r14      # imm = 0x1F4
addq %r12, %r14
movq %r14, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %r13, %rbx
movq %r13, %rdx
callq 0x5680
movq %r14, %rdi
movl $0x23, %esi
callq 0x5160
testq %rax, %rax
je 0x99d0
movb $0x0, (%rax)
movq %r14, %rdi
movl $0xa, %esi
callq 0x5160
testq %rax, %rax
je 0x99e5
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x5190
leaq (%r14,%rax), %r13
decq %r13
cmpq %r14, %r13
jb 0x9a17
movsbl (%r13), %ebp
movl %ebp, %edi
callq 0x50a0
testl %ebp, %ebp
je 0x9a0d
testl %eax, %eax
je 0x9a17
movb $0x0, (%r13)
decq %r13
jmp 0x99f4
cmpb $0x0, (%r14)
je 0x9a40
movl $0x18, %edi
callq 0x53f0
movq %r14, 0x10(%rax)
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x5090
incq 0x30(%rsp)
incl %r15d
movq %rbx, %r13
movq %rbx, %rdi
callq 0x5650
testl %eax, %eax
je 0x999b
movq %r13, 0x58(%rsp)
movq 0x20(%rsp), %r15
leaq 0x20(%rsp), %rax
cmpq %rax, %r15
je 0x9ada
movq 0x20(%rsp), %rbx
cmpq %rax, %rbx
je 0x9ad5
movq 0x10(%r15), %r14
movq 0x10(%rbx), %r12
cmpq %r12, %r14
je 0x9acb
movq %r12, %rdi
callq 0x5190
movq %rax, %r13
movq %r14, %rdi
callq 0x5190
cmpq %rax, %r13
jae 0x9acb
decq %r13
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x51a0
testl %eax, %eax
jne 0x9acb
movq (%rbx), %r14
decq 0x30(%rsp)
movq %rbx, %rdi
callq 0x56e0
movl $0x18, %esi
movq %rbx, %rdi
callq 0x5400
movq %r14, %rbx
movq (%rbx), %rbx
leaq 0x20(%rsp), %rax
jmp 0x9a6c
movq (%r15), %r15
jmp 0x9a5d
leaq 0x150(%rsp), %r14
leaq 0x140(%rsp), %r12
leaq 0x3f8(%rsp), %rbx
movq %rax, %r15
xorl %r13d, %r13d
movq $0x0, 0x18(%rsp)
movq (%r15), %r15
leaq 0x20(%rsp), %rax
cmpq %rax, %r15
je 0x9dc6
movq 0x10(%r15), %rbp
testq %rbp, %rbp
je 0x9b37
movq %rbp, %rdi
callq 0x5190
movq 0x32476(%rip), %rdi     # 0x3bfa0
movq %rbp, %rsi
movq %rax, %rdx
callq 0x5460
jmp 0x9b55
movq 0x32462(%rip), %rcx     # 0x3bfa0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x1, %esi
callq 0x5740
movq 0x32444(%rip), %rcx     # 0x3bfa0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq 0x32426(%rip), %rdi     # 0x3bfa0
callq 0x5050
movq %rax, %rdi
callq 0x5270
movq %r14, 0x140(%rsp)
movq %r12, %rdi
leaq 0x26aea(%rip), %rsi     # 0x30683
leaq 0x26b1b(%rip), %rdx     # 0x306bb
callq 0xa7de
movabsq $0x100000401, %rbp      # imm = 0x100000401
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x1c7f2
movq 0x140(%rsp), %rdi
cmpq %r14, %rdi
je 0x9bd9
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x10(%r15), %r14
movl %r13d, 0x10(%rsp)
movslq %r13d, %rax
movl $0x0, (%rsp)
imulq $0x320, %rax, %rcx      # imm = 0x320
leaq 0x12db26(%rip), %rax    # 0x137720
movq %rcx, 0x68(%rsp)
addq %rcx, %rax
movq %rax, 0x8(%rsp)
leaq 0x200(%rsp), %r13
movq %r15, 0x38(%rsp)
movzbl (%r14), %eax
testl %eax, %eax
je 0x9d68
cmpl $0xa, %eax
je 0x9d68
movb %al, (%r13)
incq %r13
movzbl 0x1(%r14), %eax
incq %r14
cmpq $0x20, %rax
ja 0x9c14
btq %rax, %rbp
jae 0x9c14
movb $0x0, (%r13)
xorl %eax, %eax
cmpb $0x3f, 0x200(%rsp)
setne %r15b
sete %al
leaq (%rsp,%rax), %rsi
addq $0x200, %rsi            # imm = 0x200
movq %rbx, %rdi
callq 0x92a7
movl %eax, %ebp
testl %eax, %eax
je 0x9cdc
movslq 0x18(%rsp), %rax
leaq (%rax,%rax,4), %rdx
shlq $0x5, %rdx
leaq 0x11a219(%rip), %rax    # 0x123ea0
addq %rax, %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1ef10
movl (%rsp), %edx
movslq %edx, %rax
movq 0x8(%rsp), %rcx
movl %ebp, (%rcx,%rax,8)
movb %r15b, 0x4(%rcx,%rax,8)
movq 0x18(%rsp), %rax
cmpl $0x1f3, %eax            # imm = 0x1F3
leal 0x1(%rax), %eax
movl $0x0, %ecx
cmovgel %ecx, %eax
incl %edx
movl %edx, (%rsp)
leaq 0x1(%r14), %rcx
cmpb $0x20, (%r14)
cmoveq %rcx, %r14
leaq 0x200(%rsp), %r13
movq %rax, 0x18(%rsp)
jmp 0x9d48
movl $0x7, %edx
movq 0x322b8(%rip), %rdi     # 0x3bfa0
leaq 0x269cd(%rip), %rsi     # 0x306bc
callq 0x5460
leaq 0x200(%rsp), %r15
movq %r15, %rdi
callq 0x5190
movq 0x32295(%rip), %rdi     # 0x3bfa0
movq %r15, %rsi
movq %rax, %rdx
callq 0x5460
movq 0x32283(%rip), %rcx     # 0x3bfa0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq 0x32265(%rip), %rdi     # 0x3bfa0
callq 0x5050
movq %rax, %rdi
callq 0x5270
testl %ebp, %ebp
movq 0x38(%rsp), %r15
movabsq $0x100000401, %rbp      # imm = 0x100000401
jne 0x9c14
xorl %eax, %eax
movl 0x10(%rsp), %r13d
jmp 0x9db6
movq %r15, %rbp
movl (%rsp), %r14d
leaq 0x12d9aa(%rip), %rax    # 0x137720
movq 0x68(%rsp), %rcx
leaq (%rcx,%rax), %r15
addq $-0x8, %r15
movl 0x10(%rsp), %r13d
testl %r14d, %r14d
jle 0x9d9e
movl (%r15,%r14,8), %esi
decq %r14
movq %rbx, %rdi
callq 0x20056
jmp 0x9d88
movslq (%rsp), %rax
movq 0x8(%rsp), %rcx
movl $0x0, (%rcx,%rax,8)
incl %r13d
movb $0x1, %al
movq %rbp, %r15
testb %al, %al
leaq 0x150(%rsp), %r14
jne 0x9b01
leaq 0x20(%rsp), %r14
cmpq %r14, %r15
jne 0xa3b2
xorl %r14d, %r14d
movq %r14, 0x1e8(%rsp)
movl $0x0, 0x1f8(%rsp)
movq %r14, 0x140(%rsp)
movb $0x0, 0x1fc(%rsp)
testl %r13d, %r13d
jle 0x9f59
movl %r13d, %edi
leaq 0x12d91b(%rip), %r13    # 0x137728
xorl %eax, %eax
movq %rdi, 0x10(%rsp)
movq %rax, %rdx
leaq 0x1(%rax), %rcx
imulq $0x320, %rax, %rsi      # imm = 0x320
leaq 0x12d8f7(%rip), %rax    # 0x137720
addq %rax, %rsi
cmpq %rdi, %rcx
movq %rcx, 0x8(%rsp)
cmovbq %rcx, %rdx
movq %rdx, 0x38(%rsp)
movslq %r14d, %r15
movq %rsi, 0x18(%rsp)
movl (%rsi,%r15,8), %ebp
testl %ebp, %ebp
movq %r13, (%rsp)
je 0x9ee3
incl %r14d
movl $0xc0, %edi
callq 0x53f0
movq %rax, %rbx
movl $0xc0, %edx
movq %rax, %rdi
xorl %esi, %esi
callq 0x5210
movslq 0xa8(%r12), %rax
movq %rbx, 0x8(%r12,%rax,8)
movl $0x0, 0xa8(%rbx)
movslq 0xa8(%r12), %rcx
movq 0x8(%r12,%rcx,8), %rax
movl %r14d, 0xb8(%rax)
movq %r12, (%rax)
movq 0x8(%r12,%rcx,8), %rax
movl %ebp, 0xac(%rax)
movzbl -0x4(%r13,%r15,8), %edx
movl %edx, 0xb0(%rax)
movb $0x0, 0xbc(%rax)
incl %ecx
movl %ecx, 0xa8(%r12)
movl (%r13,%r15,8), %ebp
addq $0x8, %r13
incl %r14d
movq %rax, %r12
testl %ebp, %ebp
jne 0x9e58
jmp 0x9ee6
movq %r12, %rax
movq 0x18(%rsp), %rcx
movl (%rcx), %ecx
xorl %r14d, %r14d
testl %ecx, %ecx
je 0x9f25
imulq $0x320, 0x38(%rsp), %rdx # imm = 0x320
leaq 0x12d81c(%rip), %rsi    # 0x137720
addq %rsi, %rdx
xorl %esi, %esi
movq 0x10(%rsp), %rdi
movq (%rsp), %r13
cmpl (%rdx,%rsi,8), %ecx
jne 0x9f30
movl (%r13,%rsi,8), %ecx
incq %rsi
testl %ecx, %ecx
jne 0x9f12
jmp 0x9f38
movq 0x10(%rsp), %rdi
movq (%rsp), %r13
jmp 0x9f38
movl %esi, %r14d
jmp 0x9f38
movq (%rax), %rax
cmpl %r14d, 0xb8(%rax)
jg 0x9f35
addq $0x320, %r13            # imm = 0x320
movq %rax, %r12
movq 0x8(%rsp), %rax
cmpq %rdi, %rax
jne 0x9e14
leaq 0x140(%rsp), %rdi
movl $0x1, 0xb0(%rdi)
callq 0x9542
movq 0x32029(%rip), %rdi     # 0x3bfa0
leaq 0x26746(%rip), %rsi     # 0x306c4
movl $0xb, %edx
callq 0x5460
leaq 0x140(%rsp), %r12
movq %r12, %rdi
callq 0x9701
movq 0x32001(%rip), %rdi     # 0x3bfa0
movl %eax, %esi
callq 0x5760
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
pxor %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movdqa %xmm0, 0x40(%rdi)
movdqa %xmm0, 0x30(%rdi)
movdqa %xmm0, 0x20(%rdi)
movdqa %xmm0, 0x10(%rdi)
movdqa %xmm0, (%rdi)
xorl %esi, %esi
callq 0xa86e
leaq 0xc0(%rsp), %rsi
movq %r12, (%rsi)
leaq 0x70(%rsp), %rdi
callq 0xa9e4
movb $0x1, 0x1fc(%rsp)
leaq 0xd0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x26647(%rip), %rsi     # 0x30683
leaq 0x26678(%rip), %rdx     # 0x306bb
leaq 0xc0(%rsp), %rdi
callq 0xa7de
leaq 0x3f8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
xorl %edx, %edx
callq 0x1c7f2
movq 0xc0(%rsp), %rdi
cmpq %rbx, %rdi
je 0xa084
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x80(%rsp), %rax
cmpq %rax, 0xa0(%rsp)
je 0xa2b7
xorl %r13d, %r13d
leaq 0x3f8(%rsp), %rbp
movl $0x0, 0x8(%rsp)
xorl %r12d, %r12d
movq (%rax), %rdx
movq 0x90(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
movq %rdx, (%rsp)
je 0xa0ce
addq $0x8, %rax
jmp 0xa113
movq 0x88(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x5400
movq (%rsp), %rdx
movq 0x98(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x98(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x88(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x90(%rsp)
movq %rax, 0x80(%rsp)
movq (%rdx), %rax
xorl %r15d, %r15d
testq %rax, %rax
je 0xa145
movq %rdx, %rcx
movl 0xac(%rcx), %ecx
movl %ecx, 0xc0(%rsp,%r15,4)
incq %r15
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0xa129
movl %r15d, %r14d
testl %r15d, %r15d
jle 0xa19a
addl %r15d, 0x8(%rsp)
leaq 0x1(%r14), %rbx
movl 0xb8(%rsp,%rbx,4), %esi
movslq %r12d, %rax
leaq (%rax,%rax,4), %rdx
shlq $0x5, %rdx
leaq 0x119d31(%rip), %rax    # 0x123ea0
addq %rax, %rdx
movq %rbp, %rdi
callq 0x1ef10
cmpl $0x1f3, %r12d           # imm = 0x1F3
leal 0x1(%r12), %eax
movl %eax, %r12d
cmovgel %r13d, %r12d
decq %rbx
cmpq $0x1, %rbx
jg 0xa156
movq (%rsp), %rdx
cmpl $0x0, 0xa8(%rdx)
jle 0xa27b
leaq 0x8(%rdx), %r13
xorl %ebx, %ebx
movq (%r13), %rax
cmpb $0x0, 0xbc(%rax)
jne 0xa264
movq 0xa0(%rsp), %rcx
movq 0xb0(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0xa1e5
movq %rax, (%rcx)
addq $0x8, 0xa0(%rsp)
jmp 0xa1f2
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0xac40
movq (%r13), %rax
movb $0x1, 0xbc(%rax)
movl $0x10, %edi
callq 0x53f0
movq %rax, %rbp
leaq 0x3f8(%rsp), %rdi
callq 0x8624
movq %rax, (%rbp)
movq (%r13), %rax
movq 0xac(%rax), %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, 0x8(%rbp)
movl $0x0, 0xc(%rbp)
movl $0x18, %edi
callq 0x53f0
movq %rbp, 0x10(%rax)
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x5090
incq 0x50(%rsp)
leaq 0x3f8(%rsp), %rbp
movq (%rsp), %rdx
incq %rbx
movslq 0xa8(%rdx), %rax
addq $0x8, %r13
cmpq %rax, %rbx
jl 0xa1ad
testl %r15d, %r15d
movl $0x0, %r13d
je 0xa29f
xorl %ebx, %ebx
movl 0xc0(%rsp,%rbx,4), %esi
movq %rbp, %rdi
callq 0x20056
incq %rbx
cmpq %rbx, %r14
jne 0xa288
movq 0x80(%rsp), %rax
cmpq %rax, 0xa0(%rsp)
jne 0xa0b0
jmp 0xa2bf
movl $0x0, 0x8(%rsp)
movq 0x31cda(%rip), %rdi     # 0x3bfa0
movl 0x8(%rsp), %esi
callq 0x5760
movq %rax, %r14
leaq 0x263f7(%rip), %rsi     # 0x306d0
movl $0xb, %edx
movq %rax, %rdi
callq 0x5460
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
leaq -0xade(%rip), %rsi      # 0x9836
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0xa4fe
movq 0x40(%rsp), %rbx
cmpq %r14, %rbx
movq 0x58(%rsp), %r15
movq 0x60(%rsp), %r12
je 0xa367
movq 0x10(%rbx), %rax
movq (%rax), %rsi
movzwl 0x8(%rax), %edx
movzwl 0xa(%rax), %ecx
movq %r12, %rdi
callq 0x9754
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0xa35f
movl $0x10, %esi
callq 0x5400
movq (%rbx), %rbx
cmpq %r14, %rbx
jne 0xa335
leaq 0x140(%rsp), %rdi
callq 0x91ff
movq %r15, %rdi
callq 0x53e0
movq %r12, %rdi
callq 0x53e0
leaq 0x70(%rsp), %rdi
callq 0xa78e
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0xa3ad
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5400
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0xa398
leaq 0x20(%rsp), %r14
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xa3d1
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5400
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0xa3bc
addq $0x1d38, %rsp           # imm = 0x1D38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0xc0(%rsp), %rdi
cmpq %rbx, %rdi
je 0xa481
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xa481
jmp 0xa47e
jmp 0xa47e
movq %rax, %r14
jmp 0xa48b
movq %rax, %r14
movq 0x200(%rsp), %rdi
cmpq %rbx, %rdi
je 0xa4dd
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xa4dd
movq %rax, %r14
jmp 0xa4dd
jmp 0xa47e
jmp 0xa4b6
jmp 0xa47e
jmp 0xa4b6
movq %r14, %rcx
movq %rax, %r14
movq 0x140(%rsp), %rdi
cmpq %rcx, %rdi
je 0xa4b9
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xa4b9
jmp 0xa4b6
jmp 0xa47e
jmp 0xa4b6
jmp 0xa4b6
jmp 0xa47e
jmp 0xa47e
jmp 0xa4b6
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0xa78e
movq 0x40(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xa4b9
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5400
movq %rbx, %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rbx
jne 0xa49a
jmp 0xa4b9
movq %rax, %r14
movq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %r15
cmpq %r15, %rdi
je 0xa4dd
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5400
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0xa4c8
movq %r14, %rdi
callq 0x5790
nop