// File: /workspace/github_cpp_makefile_star2_O3/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 0x27967(%rip), %rdi     # 0x316c2
leaq 0x298dc(%rip), %rsi     # 0x3363e
callq 0x54a0
movq %rax, %rbx
testq %rax, %rax
je 0x9d8c
leaq 0x2796b(%rip), %rdi     # 0x316e1
leaq 0x2796f(%rip), %rsi     # 0x316ec
callq 0x54a0
movq %rax, 0x38(%rsp)
jmp 0x9e21
movq 0x3320d(%rip), %r14     # 0x3cfa0
leaq 0x27933(%rip), %rsi     # 0x316cd
movl $0x13, %edx
movq %r14, %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 0x2790c(%rip), %rdi     # 0x316e1
leaq 0x27910(%rip), %rsi     # 0x316ec
callq 0x54a0
movq %rax, 0x38(%rsp)
leaq 0x27902(%rip), %rsi     # 0x316ef
movl $0x13, %edx
movq %r14, %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 0x210(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x278cf(%rip), %rsi     # 0x31703
leaq 0x27900(%rip), %rdx     # 0x3173b
leaq 0x200(%rsp), %rdi
callq 0xad16
leaq 0x3f8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1ccf2
movq 0x200(%rsp), %rdi
cmpq %r14, %rdi
je 0x9e7e
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x5400
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
movq %rbx, %rdi
callq 0x5650
testl %eax, %eax
jne 0x9f63
xorl %ebp, %ebp
leaq 0x2b5275(%rip), %r15    # 0x2bf120
movslq %ebp, %rax
imulq $0x1f4, %rax, %r12      # imm = 0x1F4
addq %r15, %r12
movq %r12, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %rbx, %r14
movq %rbx, %rdx
callq 0x5680
movq %r12, %rdi
movl $0x23, %esi
callq 0x5160
testq %rax, %rax
je 0x9ee0
movb $0x0, (%rax)
movq %r12, %rdi
movl $0xa, %esi
callq 0x5160
testq %rax, %rax
je 0x9ef5
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x5190
leaq (%r12,%rax), %r13
decq %r13
cmpq %r12, %r13
jb 0x9f27
movsbl (%r13), %ebx
movl %ebx, %edi
callq 0x50a0
testl %ebx, %ebx
je 0x9f1d
testl %eax, %eax
je 0x9f27
movb $0x0, (%r13)
decq %r13
jmp 0x9f04
cmpb $0x0, (%r12)
je 0x9f50
movl $0x18, %edi
callq 0x53f0
movq %r12, 0x10(%rax)
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x5090
incq 0x30(%rsp)
incl %ebp
movq %r14, %rbx
movq %r14, %rdi
callq 0x5650
testl %eax, %eax
je 0x9eab
movq %rbx, 0x68(%rsp)
movq 0x20(%rsp), %r15
leaq 0x20(%rsp), %rax
cmpq %rax, %r15
je 0x9ffb
movq 0x20(%rsp), %r14
cmpq %rax, %r14
je 0x9fe9
movq 0x10(%r15), %rbx
movq 0x10(%r14), %r12
cmpq %r12, %rbx
je 0x9fdf
movq %r12, %rdi
callq 0x5190
movq %rax, %r13
movq %rbx, %rdi
callq 0x5190
cmpq %rax, %r13
jae 0x9fdf
decq %r13
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x51a0
testl %eax, %eax
jne 0x9fdf
movq (%r14), %rbx
decq 0x30(%rsp)
movq %r14, %rdi
callq 0x56e0
movl $0x18, %esi
movq %r14, %rdi
callq 0x5400
movq %rbx, %r14
movq (%r14), %r14
leaq 0x20(%rsp), %rax
jmp 0x9f80
movq (%r15), %r15
leaq 0x20(%rsp), %rax
cmpq %rax, %r15
jne 0x9f7b
movq 0x20(%rsp), %r15
cmpq %rax, %r15
je 0xa3ea
leaq 0x12e70d(%rip), %r13    # 0x138718
leaq 0xd0(%rsp), %r14
movq 0x32f86(%rip), %rbp     # 0x3cfa0
leaq 0xc0(%rsp), %r12
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%r15), %rbx
testq %rbx, %rbx
je 0xa055
movq %rbx, %rdi
callq 0x5190
movq %rbp, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5460
jmp 0xa06d
movq (%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
movl 0x20(%rbp,%rax), %esi
orl $0x1, %esi
callq 0x5740
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x5270
movq %r14, 0xc0(%rsp)
movq %r12, %rdi
leaq 0x2765c(%rip), %rsi     # 0x31703
leaq 0x2768d(%rip), %rdx     # 0x3173b
callq 0xad16
movabsq $0x100000401, %rbx      # imm = 0x100000401
leaq 0x3f8(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x1cd22
movq 0xc0(%rsp), %rdi
cmpq %r14, %rdi
je 0xa0ec
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x10(%r15), %r14
movl $0x0, 0x8(%rsp)
movq %r13, 0x40(%rsp)
leaq 0x200(%rsp), %rax
movzbl (%r14), %ecx
testl %ecx, %ecx
je 0xa1f6
cmpl $0xa, %ecx
je 0xa1f6
movb %cl, (%rax)
incq %rax
movzbl 0x1(%r14), %ecx
incq %r14
cmpq $0x20, %rcx
ja 0xa105
btq %rcx, %rbx
jae 0xa105
movb $0x0, (%rax)
xorl %eax, %eax
cmpb $0x3f, 0x200(%rsp)
setne %bpl
sete %al
leaq (%rsp,%rax), %rsi
addq $0x200, %rsi            # imm = 0x200
leaq 0x3f8(%rsp), %rdi
callq 0x97cf
movl %eax, %ebx
testl %eax, %eax
je 0xa780
movslq 0x10(%rsp), %rax
leaq (%rax,%rax,4), %rdx
shlq $0x5, %rdx
leaq 0x11ad23(%rip), %rax    # 0x124ea0
addq %rax, %rdx
leaq 0x3f8(%rsp), %rdi
movl %ebx, %esi
callq 0x1f3d6
movl 0x8(%rsp), %esi
movl %esi, %eax
imulq $0x320, 0x18(%rsp), %rcx # imm = 0x320
leaq 0x12e57b(%rip), %rdx    # 0x138720
addq %rdx, %rcx
movl %ebx, (%rcx,%rax,8)
movb %bpl, 0x4(%rcx,%rax,8)
movq 0x10(%rsp), %rax
cmpl $0x1f3, %eax            # imm = 0x1F3
leal 0x1(%rax), %eax
movl $0x0, %ecx
cmovgel %ecx, %eax
incl %esi
movl %esi, 0x8(%rsp)
leaq 0x1(%r14), %rcx
cmpb $0x20, (%r14)
cmoveq %rcx, %r14
addq $0x8, %r13
movq %rax, 0x10(%rsp)
movq 0x32db9(%rip), %rbp     # 0x3cfa0
movabsq $0x100000401, %rbx      # imm = 0x100000401
jmp 0xa0fd
movl 0x8(%rsp), %ebx
leaq 0x3f8(%rsp), %r14
testl %ebx, %ebx
jle 0xa21a
movl (%r13), %esi
decl %ebx
addq $-0x8, %r13
movq %r14, %rdi
callq 0x2051a
jmp 0xa202
movl 0x8(%rsp), %eax
movq 0x18(%rsp), %rsi
imulq $0x320, %rsi, %rcx      # imm = 0x320
leaq 0x12e4ef(%rip), %rdx    # 0x138720
addq %rdx, %rcx
movl $0x0, (%rcx,%rax,8)
incq %rsi
movq %rsi, 0x18(%rsp)
movq (%r15), %r15
movq 0x40(%rsp), %r13
movl $0x320, %eax            # imm = 0x320
addq %rax, %r13
leaq 0x20(%rsp), %rax
cmpq %rax, %r15
leaq 0xd0(%rsp), %r14
jne 0xa034
xorl %edi, %edi
movq %rdi, 0x168(%rsp)
movl $0x0, 0x178(%rsp)
movq %rdi, 0xc0(%rsp)
movb $0x0, 0x17c(%rsp)
movl 0x18(%rsp), %r8d
leaq 0x12e48e(%rip), %r13    # 0x138728
xorl %ebp, %ebp
movq %r8, 0x48(%rsp)
leaq 0x1(%rdi), %rcx
imulq $0x320, %rdi, %rdx      # imm = 0x320
leaq 0x12e46d(%rip), %rax    # 0x138720
addq %rax, %rdx
cmpq %r8, %rcx
movq %rcx, 0x8(%rsp)
cmovbq %rcx, %rdi
movq %rdi, 0x40(%rsp)
movslq %ebp, %r15
movq %rdx, 0x18(%rsp)
movl (%rdx,%r15,8), %r14d
testl %r14d, %r14d
movq %r13, 0x10(%rsp)
je 0xa36e
incl %ebp
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 %ebp, 0xb8(%rax)
movq %r12, (%rax)
movq 0x8(%r12,%rcx,8), %rax
movl %r14d, 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), %r14d
addq $0x8, %r13
incl %ebp
movq %rax, %r12
testl %r14d, %r14d
jne 0xa2e3
jmp 0xa371
movq %r12, %rax
movq 0x18(%rsp), %rcx
movl (%rcx), %ecx
xorl %ebp, %ebp
testl %ecx, %ecx
je 0xa3b5
imulq $0x320, 0x40(%rsp), %rdx # imm = 0x320
leaq 0x12e392(%rip), %rsi    # 0x138720
addq %rsi, %rdx
xorl %esi, %esi
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %r8
movq 0x10(%rsp), %r13
cmpl (%rdx,%rsi,8), %ecx
jne 0xa3c6
movl (%r13,%rsi,8), %ecx
incq %rsi
testl %ecx, %ecx
jne 0xa3a2
jmp 0xa3cd
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %r8
movq 0x10(%rsp), %r13
jmp 0xa3cd
movl %esi, %ebp
jmp 0xa3cd
movq (%rax), %rax
cmpl %ebp, 0xb8(%rax)
jg 0xa3ca
addq $0x320, %r13            # imm = 0x320
movq %rax, %r12
cmpq %r8, %rdi
jne 0xa2a1
jmp 0xa40f
xorl %eax, %eax
movq %rax, 0x168(%rsp)
movl $0x0, 0x178(%rsp)
movq %rax, 0xc0(%rsp)
movb $0x0, 0x17c(%rsp)
leaq 0xc0(%rsp), %rdi
movl $0x1, 0xb0(%rdi)
callq 0x9a3d
movq 0x32b73(%rip), %rdi     # 0x3cfa0
leaq 0x27310(%rip), %rsi     # 0x31744
movl $0xb, %edx
callq 0x5460
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
callq 0x9bfc
movq 0x32b4b(%rip), %rdi     # 0x3cfa0
movl %eax, %esi
callq 0x5760
movq %rax, %rbx
movq (%rax), %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 0x50(%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 0xadac
leaq 0x180(%rsp), %rsi
movq %r14, (%rsi)
leaq 0x70(%rsp), %rdi
callq 0xaf22
movb $0x1, 0x17c(%rsp)
leaq 0x190(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x27211(%rip), %rsi     # 0x31703
leaq 0x27242(%rip), %rdx     # 0x3173b
leaq 0x180(%rsp), %rdi
callq 0xad16
leaq 0x3f8(%rsp), %rdi
leaq 0x180(%rsp), %rsi
xorl %edx, %edx
callq 0x1cd22
movq 0x180(%rsp), %rdi
cmpq %r14, %rdi
je 0xa53a
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x80(%rsp), %rax
cmpq %rax, 0xa0(%rsp)
je 0xa7ed
xorl %ebp, %ebp
leaq 0x3f8(%rsp), %r13
xorl %r14d, %r14d
xorl %r15d, %r15d
movq (%rax), %rbx
movq 0x90(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0xa57a
addq $0x8, %rax
jmp 0xa5bb
movq 0x88(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x5400
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)
movl %r14d, %r14d
movq %rax, 0x80(%rsp)
movq (%rbx), %rax
testq %rax, %rax
movq %rbx, 0x8(%rsp)
je 0xa65f
movl $0x1, %ecx
xorl %r12d, %r12d
movq %rbx, %rdx
movl %ecx, %ebx
movl 0xac(%rdx), %ecx
movl %ecx, 0x180(%rsp,%r12,4)
incq %r12
movq %rax, %rdx
movq (%rax), %rax
leal 0x1(%rbx), %ecx
testq %rax, %rax
jne 0xa5e2
testl %r12d, %r12d
jle 0xa653
addq %r12, %r14
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
incq %rbx
movl 0x178(%rsp,%rbx,4), %esi
movslq %r15d, %rax
leaq (%rax,%rax,4), %rdx
shlq $0x5, %rdx
leaq 0x11a873(%rip), %rax    # 0x124ea0
addq %rax, %rdx
movq %r13, %rdi
callq 0x1f3d6
cmpl $0x1f3, %r15d           # imm = 0x1F3
leal 0x1(%r15), %eax
movl %eax, %r15d
cmovgel %ebp, %r15d
decq %rbx
cmpq $0x1, %rbx
ja 0xa614
movq %r14, 0x10(%rsp)
movq 0x8(%rsp), %rbx
jmp 0xa667
movq %r14, 0x10(%rsp)
xorl %r12d, %r12d
movl 0xa8(%rbx), %eax
testl %eax, %eax
jle 0xa73b
leaq 0x8(%rbx), %r14
xorl %ebp, %ebp
movq (%r14), %rcx
cmpb $0x0, 0xbc(%rcx)
jne 0xa728
movq 0xa0(%rsp), %rax
movq 0xb0(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rax
je 0xa6b2
movq %rcx, (%rax)
addq $0x8, 0xa0(%rsp)
jmp 0xa6bf
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0xb184
movq (%r14), %rax
movb $0x1, 0xbc(%rax)
movl $0x10, %edi
callq 0x53f0
movq %rax, %rbx
movq %r13, %rdi
callq 0x8b78
movq %rax, (%rbx)
movq (%r14), %rax
movq 0xac(%rax), %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, 0x8(%rbx)
movl $0x0, 0xc(%rbx)
movl $0x18, %edi
callq 0x53f0
movq %rbx, 0x10(%rax)
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0x5090
incq 0x60(%rsp)
movq 0x8(%rsp), %rax
movl 0xa8(%rax), %eax
incq %rbp
movslq %eax, %rcx
addq $0x8, %r14
cmpq %rcx, %rbp
jl 0xa67b
testl %r12d, %r12d
movl $0x0, %ebp
je 0xa763
movl %r12d, %ebx
xorl %r14d, %r14d
movl 0x180(%rsp,%r14,4), %esi
movq %r13, %rdi
callq 0x2051a
incq %r14
cmpq %r14, %rbx
jne 0xa74b
movq 0x80(%rsp), %rax
cmpq %rax, 0xa0(%rsp)
movq 0x10(%rsp), %r14
jne 0xa560
jmp 0xa7f0
movq 0x32819(%rip), %rdi     # 0x3cfa0
leaq 0x26fae(%rip), %rsi     # 0x3173c
movl $0x7, %edx
callq 0x5460
leaq 0x200(%rsp), %r14
movq %r14, %rdi
callq 0x5190
movq 0x327f1(%rip), %rbx     # 0x3cfa0
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x5460
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x53c0
movsbl %al, %esi
movq 0x327c5(%rip), %rdi     # 0x3cfa0
callq 0x5050
movq %rax, %rdi
callq 0x5270
jmp 0xa8d7
xorl %r14d, %r14d
movq 0x327a9(%rip), %rdi     # 0x3cfa0
movl %r14d, %esi
callq 0x5760
movq %rax, %r14
leaq 0x26f47(%rip), %rsi     # 0x31750
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 -0xb0b(%rip), %rsi      # 0x9d39
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0xaa26
movq 0x50(%rsp), %rbx
cmpq %r14, %rbx
movq 0x68(%rsp), %r15
je 0xa88f
movq 0x10(%rbx), %rax
movq (%rax), %rsi
movzwl 0x8(%rax), %edx
movzwl 0xa(%rax), %ecx
movq 0x38(%rsp), %rdi
callq 0x9c4f
movq 0x10(%rbx), %rdi
movl $0x10, %esi
callq 0x5400
movq (%rbx), %rbx
cmpq %r14, %rbx
jne 0xa860
leaq 0xc0(%rsp), %rdi
callq 0x972c
movq %r15, %rdi
callq 0x53e0
movq 0x38(%rsp), %rdi
callq 0x53e0
leaq 0x70(%rsp), %rdi
callq 0xacbe
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
je 0xa8d7
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5400
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0xa8c2
movq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %r14
cmpq %r14, %rdi
je 0xa8fb
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x5400
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0xa8e6
addq $0x1d38, %rsp           # imm = 0x1D38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x180(%rsp), %rdi
cmpq %r14, %rdi
je 0xa9af
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xa9af
jmp 0xa9ac
jmp 0xa9ac
movq %rax, %rbx
jmp 0xa9b9
movq %rax, %rbx
movq 0x200(%rsp), %rdi
cmpq %r14, %rdi
je 0xaa06
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xaa06
movq %rax, %rbx
jmp 0xaa06
jmp 0xa9a7
jmp 0xa9ac
jmp 0xa9a7
jmp 0xa9a7
jmp 0xa9a7
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
cmpq %r14, %rdi
je 0xa9e2
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0xa9e2
jmp 0xa9ac
jmp 0xa9a7
jmp 0xa9a7
jmp 0xa9ac
jmp 0xa9ac
jmp 0xa9a7
jmp 0xa9ac
movq %rax, %rbx
jmp 0xa9e2
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xacbe
movq 0x50(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xa9e2
movq (%rdi), %r14
movl $0x18, %esi
callq 0x5400
movq %r14, %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %r14
jne 0xa9c8
movq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %r15
cmpq %r15, %rdi
je 0xaa06
movq (%rdi), %r14
movl $0x18, %esi
callq 0x5400
movq %r14, %rdi
cmpq %r15, %r14
jne 0xa9f1
movq %rbx, %rdi
callq 0x5790