// File: codeandkey[P]neocortex/src/search.cpp
// Function: neocortex::search::Search::control_worker(neocortex::Position, std::function<void (neocortex::search::SearchInfo)>, std::function<void (neocortex::Move)>)
void search::Search::control_worker(Position root, std::function<void(SearchInfo)> info, std::function<void(Move)> bestmove) {
	int score;
	int cur_depth;
	int ourtime, ourinc;
	int iter_time;
	Move best_move;

	/* EBF variables, for depth time prediction */
	float ebf = -1.0f; /* effective branching factor, set after depth 3 */
	int ebf_nodes[MAX_DEPTH] = { 1 };
	int ebf_times[MAX_DEPTH] = { 0 }; /* we can assume depth 0 and 1 searches take effectively 1ms */

	/* Determine how much time we have */
	if (root.get_color_to_move() == piece::WHITE) {
		ourtime = wtime;
		ourinc = winc;
	} else {
		ourtime = btime;
		ourinc = binc;
	}

	/* Write depth 0 information */
	SearchInfo d0;

	d0.depth = 0;
	d0.nodes = 1;
	d0.score = root.evaluate();
	d0.seldepth = -1;

	info(d0);

	/* Search depth 1 with 1 thread */
	{
		std::lock_guard<std::mutex> dst_lock(depth_starttime_mutex);
		depth_starttime = util::time_now();
	}

	allocated_time = -1;

	SearchInfo d1;

	root.reset_eval_counter();
	max_ply_searched = 0;

	score = alphabeta(root, 1, score::CHECKMATED, score::CHECKMATE, 0, &d1.pv, control_should_stop);
	
	{
		std::lock_guard<std::mutex> dst_lock(depth_starttime_mutex);
		iter_time = util::time_elapsed_ms(depth_starttime);
	}

	d1.depth = 1;
	d1.nodes = root.get_eval_counter();
	d1.seldepth = max_ply_searched;
	d1.time = iter_time;
	d1.score = score;
	best_move = d1.pv.moves[0];

	info(d1);

	/* Set search start time */
	util::time_point search_starttime = util::time_now();

	cur_depth = 2;
	while (1) {
		if (!infinite && depth > 0 && cur_depth > depth) break;
		if (!infinite && movetime > 0 && util::time_elapsed_ms(search_starttime) >= movetime) break;
		if (control_should_stop) break;
		if (cur_depth >= MAX_DEPTH) break;

		/* Allocate time for the next depth if timed */
		allocated_time = -1;

		if (movetime > 0) {
			allocated_time = movetime.load();
		} else {
			if (ourtime > 0) {
				allocated_time = ourtime / search::ALLOC_FRACTION; /* TODO: actual time management */

				if (ourinc > 0) {
					allocated_time += ourinc;
				}
			}
		}

		/* Predict time for this depth */
		if (ebf > 0.0f) {
			if (allocated_time > 0) {
				if (util::time_elapsed_ms(search_starttime) + (int)(ebf * ebf_times[cur_depth - 1]) >= allocated_time) {
					break;
				}
			}
		}

		root.reset_eval_counter();

		/* Perform search (TODO: aspiration) */
		{
			std::lock_guard<std::mutex> dst_lock(depth_starttime_mutex);
			depth_starttime = util::time_now();
		}

		max_ply_searched = 0;

		/* Start n-1 SMP threads */
		smp_should_stop = false;

		int* smp_node_counts = new int[(size_t) num_threads - 1];

		for (int i = 0; i < num_threads - 1; ++i) {
			smp_node_counts[i] = 0;
			smp_threads.push_back(std::thread([=] { smp_worker(cur_depth + (i % 2), root, smp_node_counts + i); }));
		}

		/* Search on control thread */

		SearchInfo cur;
		cur.depth = cur_depth;

		cur.score = alphabeta(root, cur_depth, score::CHECKMATED, score::CHECKMATE, 0, &cur.pv, control_should_stop);

		cur.nodes = root.get_eval_counter();

		/* Join SMP threads */
		smp_should_stop = true;

		for (auto &i : smp_threads) {
			if (i.joinable()) {
				i.join();
			}
		}

		for (int i = 0; i < num_threads - 1; ++i) {
			cur.nodes += smp_node_counts[i];
		}

		smp_threads.clear();

		if (cur.score == score::INCOMPLETE) break;

		/* Search complete, store best move */
		best_move = cur.pv.moves[0];
		cur.seldepth = max_ply_searched;

		{
			std::lock_guard<std::mutex> dst_lock(depth_starttime_mutex);
			cur.time = util::time_elapsed_ms(depth_starttime);
		}

		/* Set EBF for next depth */
		ebf_nodes[cur_depth] = cur.nodes;
		ebf_times[cur_depth] = cur.time;
		ebf = sqrtf((float) ebf_nodes[cur_depth] / (float) ebf_nodes[cur_depth - 1]);

		/* Write depth result to uci */

		info(cur);
		++cur_depth;
	}

	/* Write bestmove */
	bestmove(best_move);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb1e0, %rsp           # imm = 0xB1E0
movq %rsi, -0xab50(%rbp)
movq %rdx, -0xab68(%rbp)
movq %rcx, -0xab60(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xab58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xa870
movss 0x11a20(%rip), %xmm0    # 0x27e9c
movss %xmm0, -0x5c(%rbp)
leaq -0x260(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x51f0
movl $0x1, -0x260(%rbp)
leaq -0x460(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x51f0
movq -0xab50(%rbp), %rdi
callq 0x19360
cmpl $0x0, %eax
jne 0x164f0
movq -0xab58(%rbp), %rdi
addq $0x81e8, %rdi           # imm = 0x81E8
callq 0x19380
movq -0xab58(%rbp), %rdi
movl %eax, -0x44(%rbp)
addq $0x81f0, %rdi           # imm = 0x81F0
callq 0x19380
movl %eax, -0x48(%rbp)
jmp 0x1651c
movq -0xab58(%rbp), %rdi
addq $0x81ec, %rdi           # imm = 0x81EC
callq 0x19380
movq -0xab58(%rbp), %rdi
movl %eax, -0x44(%rbp)
addq $0x81f4, %rdi           # imm = 0x81F4
callq 0x19380
movl %eax, -0x48(%rbp)
leaq -0xa78(%rbp), %rdi
movq %rdi, -0xab80(%rbp)
callq 0x19400
movq -0xab50(%rbp), %rdi
movl $0x0, -0xa74(%rbp)
movl $0x1, -0xa78(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x12400
movq -0xab80(%rbp), %rsi
movl %eax, -0xa70(%rbp)
movl $0xffffffff, -0xa68(%rbp) # imm = 0xFFFFFFFF
leaq -0x1090(%rbp), %rdi
movq %rdi, -0xab78(%rbp)
movl $0x618, %edx            # imm = 0x618
callq 0x5360
movq -0xab78(%rbp), %rsi
movq %rsp, %rdi
movl $0xc3, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq -0xab68(%rbp), %rdi
callq 0x19450
movq -0xab58(%rbp), %rsi
addq $0x81b0, %rsi           # imm = 0x81B0
leaq -0x1098(%rbp), %rdi
callq 0x19490
callq 0x21dc0
movq %rax, -0xab70(%rbp)
jmp 0x165c8
movq -0xab58(%rbp), %rax
movq -0xab70(%rbp), %rcx
movq %rcx, -0x10a0(%rbp)
movq -0x10a0(%rbp), %rcx
movq %rcx, 0x81d8(%rax)
leaq -0x1098(%rbp), %rdi
callq 0x194c0
movq -0xab58(%rbp), %rdi
addq $0x81e0, %rdi           # imm = 0x81E0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x190e0
leaq -0x16c4(%rbp), %rdi
callq 0x19400
movq -0xab50(%rbp), %rdi
callq 0x14970
movq -0xab58(%rbp), %rdi
addq $0x81e4, %rdi           # imm = 0x81E4
xorl %esi, %esi
movl %esi, -0xab88(%rbp)
callq 0x190e0
movq -0xab50(%rbp), %rsi
movl -0xab88(%rbp), %r9d
movq -0xab58(%rbp), %rdi
leaq -0x16b0(%rbp), %rcx
movq %rdi, %rdx
addq $0x81a8, %rdx           # imm = 0x81A8
movq %rsp, %rax
movq %rdx, 0x8(%rax)
movq %rcx, (%rax)
movl $0x1, %edx
movl $0xffc2f700, %ecx       # imm = 0xFFC2F700
movl $0x3d0900, %r8d         # imm = 0x3D0900
callq 0x16fe0
movq -0xab58(%rbp), %rsi
movl %eax, -0x3c(%rbp)
addq $0x81b0, %rsi           # imm = 0x81B0
leaq -0x16d0(%rbp), %rdi
callq 0x19490
movq -0xab58(%rbp), %rax
movq 0x81d8(%rax), %rax
movq %rax, -0x16d8(%rbp)
movq -0x16d8(%rbp), %rdi
callq 0x21e40
movl %eax, -0xab84(%rbp)
jmp 0x166cd
movl -0xab84(%rbp), %eax
movl %eax, -0x4c(%rbp)
leaq -0x16d0(%rbp), %rdi
callq 0x194c0
movq -0xab50(%rbp), %rdi
movl $0x1, -0x16c0(%rbp)
callq 0x14990
movq -0xab58(%rbp), %rdi
movl %eax, -0x16c4(%rbp)
addq $0x81e4, %rdi           # imm = 0x81E4
callq 0x19380
movl %eax, -0x16b4(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x16b8(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x16bc(%rbp)
movq -0x16ac(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x16a4(%rbp), %eax
movl %eax, -0x50(%rbp)
leaq -0x1cf0(%rbp), %rdi
leaq -0x16c4(%rbp), %rsi
movl $0x618, %edx            # imm = 0x618
callq 0x5360
movq %rsp, %rdi
movl $0xc3, %ecx
leaq -0x1cf0(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0xab68(%rbp), %rdi
callq 0x19450
callq 0x21dc0
movq %rax, -0x1cf8(%rbp)
movl $0x2, -0x40(%rbp)
movq -0xab58(%rbp), %rdi
addq $0x8200, %rdi           # imm = 0x8200
callq 0x194f0
testb $0x1, %al
jne 0x1682c
movq -0xab58(%rbp), %rdi
addq $0x81fc, %rdi           # imm = 0x81FC
callq 0x19380
cmpl $0x0, %eax
jle 0x1682c
movq -0xab58(%rbp), %rdi
movl -0x40(%rbp), %eax
movl %eax, -0xab8c(%rbp)
addq $0x81fc, %rdi           # imm = 0x81FC
callq 0x19380
movl %eax, %ecx
movl -0xab8c(%rbp), %eax
cmpl %ecx, %eax
jle 0x1682c
jmp 0x16f77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
leaq -0x1098(%rbp), %rdi
callq 0x194c0
jmp 0x16fc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
leaq -0x16d0(%rbp), %rdi
callq 0x194c0
jmp 0x16fc7
movq -0xab58(%rbp), %rdi
addq $0x8200, %rdi           # imm = 0x8200
callq 0x194f0
testb $0x1, %al
jne 0x1689f
movq -0xab58(%rbp), %rdi
addq $0x81f8, %rdi           # imm = 0x81F8
callq 0x19380
cmpl $0x0, %eax
jle 0x1689f
movq -0x1cf8(%rbp), %rax
movq %rax, -0x1d00(%rbp)
movq -0x1d00(%rbp), %rdi
callq 0x21e40
movq -0xab58(%rbp), %rdi
movl %eax, -0xab90(%rbp)
addq $0x81f8, %rdi           # imm = 0x81F8
callq 0x19380
movl %eax, %ecx
movl -0xab90(%rbp), %eax
cmpl %ecx, %eax
jl 0x1689f
jmp 0x16f77
movq -0xab58(%rbp), %rdi
addq $0x81a8, %rdi           # imm = 0x81A8
callq 0x194f0
testb $0x1, %al
jne 0x168b8
jmp 0x168bd
jmp 0x16f77
cmpl $0x80, -0x40(%rbp)
jl 0x168cb
jmp 0x16f77
movq -0xab58(%rbp), %rdi
addq $0x81e0, %rdi           # imm = 0x81E0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x190e0
movq -0xab58(%rbp), %rdi
addq $0x81f8, %rdi           # imm = 0x81F8
callq 0x19380
cmpl $0x0, %eax
jle 0x16991
movq -0xab58(%rbp), %rax
addq $0x81f8, %rax           # imm = 0x81F8
movq %rax, -0x8(%rbp)
movl $0x5, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xaba0(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x1a240
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xab94(%rbp)
decl %eax
subl $0x2, %eax
jb 0x1695f
jmp 0x16944
movl -0xab94(%rbp), %eax
subl $0x5, %eax
je 0x1696d
jmp 0x16951
movq -0xaba0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x16979
movq -0xaba0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x16979
movq -0xaba0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0xab58(%rbp), %rdi
movl -0x14(%rbp), %esi
addq $0x81e0, %rdi           # imm = 0x81E0
callq 0x190e0
jmp 0x169d7
cmpl $0x0, -0x44(%rbp)
jle 0x169d5
movq -0xab58(%rbp), %rdi
movl -0x44(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %esi
addq $0x81e0, %rdi           # imm = 0x81E0
callq 0x190e0
cmpl $0x0, -0x48(%rbp)
jle 0x169d3
movq -0xab58(%rbp), %rdi
movl -0x48(%rbp), %esi
addq $0x81e0, %rdi           # imm = 0x81E0
callq 0x19570
jmp 0x169d5
jmp 0x169d7
movss -0x5c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x16a69
movq -0xab58(%rbp), %rdi
addq $0x81e0, %rdi           # imm = 0x81E0
callq 0x19380
cmpl $0x0, %eax
jle 0x16a67
movq -0x1cf8(%rbp), %rax
movq %rax, -0x1d08(%rbp)
movq -0x1d08(%rbp), %rdi
callq 0x21e40
movq -0xab58(%rbp), %rdi
movss -0x5c(%rbp), %xmm0
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cvtsi2ssl -0x460(%rbp,%rcx,4), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
addl %ecx, %eax
movl %eax, -0xaba4(%rbp)
addq $0x81e0, %rdi           # imm = 0x81E0
callq 0x19380
movl %eax, %ecx
movl -0xaba4(%rbp), %eax
cmpl %ecx, %eax
jl 0x16a65
jmp 0x16f77
jmp 0x16a67
jmp 0x16a69
movq -0xab50(%rbp), %rdi
callq 0x14970
movq -0xab58(%rbp), %rsi
addq $0x81b0, %rsi           # imm = 0x81B0
leaq -0x1d10(%rbp), %rdi
callq 0x19490
callq 0x21dc0
movq %rax, -0xabb0(%rbp)
jmp 0x16a9d
movq -0xab58(%rbp), %rax
movq -0xabb0(%rbp), %rcx
movq %rcx, -0x1d18(%rbp)
movq -0x1d18(%rbp), %rcx
movq %rcx, 0x81d8(%rax)
leaq -0x1d10(%rbp), %rdi
callq 0x194c0
movq -0xab58(%rbp), %rdi
addq $0x81e4, %rdi           # imm = 0x81E4
xorl %esi, %esi
callq 0x190e0
movq -0xab58(%rbp), %rdi
addq $0x8198, %rdi           # imm = 0x8198
xorl %esi, %esi
callq 0x19170
movq -0xab58(%rbp), %rdi
addq $0x8178, %rdi           # imm = 0x8178
callq 0x19380
cltq
subq $0x1, %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x5030
movq %rax, -0x1d20(%rbp)
movl $0x0, -0x1d24(%rbp)
movq -0xab58(%rbp), %rdi
movl -0x1d24(%rbp), %eax
movl %eax, -0xabb4(%rbp)
addq $0x8178, %rdi           # imm = 0x8178
callq 0x19380
movl %eax, %ecx
movl -0xabb4(%rbp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x16c99
movq -0xab50(%rbp), %rsi
movq -0xab58(%rbp), %rax
movq -0x1d20(%rbp), %rcx
movslq -0x1d24(%rbp), %rdx
movl $0x0, (%rcx,%rdx,4)
movq %rax, %rcx
addq $0x8180, %rcx           # imm = 0x8180
movq %rcx, -0xabc0(%rbp)
movq %rax, -0x9ec0(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x9eb8(%rbp)
movl -0x1d24(%rbp), %eax
movl %eax, -0x9eb4(%rbp)
leaq -0x9eb0(%rbp), %rdi
callq 0x18f20
movq -0x1d20(%rbp), %rax
movq %rax, -0x1d38(%rbp)
leaq -0x1d30(%rbp), %rdi
leaq -0x9ec0(%rbp), %rsi
callq 0x17950
jmp 0x16bf2
movq -0xabc0(%rbp), %rdi
leaq -0x1d30(%rbp), %rsi
callq 0x195a0
jmp 0x16c07
leaq -0x1d30(%rbp), %rdi
callq 0x19020
leaq -0x9ec0(%rbp), %rdi
callq 0x17a10
movl -0x1d24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d24(%rbp)
jmp 0x16b41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
leaq -0x1d10(%rbp), %rdi
callq 0x194c0
jmp 0x16fc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
jmp 0x16c88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
leaq -0x1d30(%rbp), %rdi
callq 0x19020
leaq -0x9ec0(%rbp), %rdi
callq 0x17a10
jmp 0x16fc7
leaq -0xa4d8(%rbp), %rdi
callq 0x19400
movq -0xab50(%rbp), %rsi
movq -0xab58(%rbp), %rdi
movl -0x40(%rbp), %eax
movl %eax, -0xa4d4(%rbp)
movl -0x40(%rbp), %edx
leaq -0xa4d8(%rbp), %r10
addq $0x14, %r10
movq %rdi, %rax
addq $0x81a8, %rax           # imm = 0x81A8
movl $0xffc2f700, %ecx       # imm = 0xFFC2F700
movl $0x3d0900, %r8d         # imm = 0x3D0900
xorl %r9d, %r9d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x16fe0
movq -0xab50(%rbp), %rdi
movl %eax, -0xa4d0(%rbp)
callq 0x14990
movq -0xab58(%rbp), %rdi
movl %eax, -0xa4d8(%rbp)
addq $0x8198, %rdi           # imm = 0x8198
movl $0x1, %esi
callq 0x19170
movq -0xab58(%rbp), %rax
addq $0x8180, %rax           # imm = 0x8180
movq %rax, -0xa4e0(%rbp)
movq -0xa4e0(%rbp), %rdi
callq 0x195d0
movq %rax, -0xa4e8(%rbp)
movq -0xa4e0(%rbp), %rdi
callq 0x19600
movq %rax, -0xa4f0(%rbp)
leaq -0xa4e8(%rbp), %rdi
leaq -0xa4f0(%rbp), %rsi
callq 0x19630
testb $0x1, %al
jne 0x16d72
jmp 0x16db3
leaq -0xa4e8(%rbp), %rdi
callq 0x19670
movq %rax, -0xa4f8(%rbp)
movq -0xa4f8(%rbp), %rdi
callq 0x19690
testb $0x1, %al
jne 0x16d97
jmp 0x16da3
movq -0xa4f8(%rbp), %rdi
callq 0x5670
jmp 0x16da5
leaq -0xa4e8(%rbp), %rdi
callq 0x196d0
jmp 0x16d59
movl $0x0, -0xa4fc(%rbp)
movq -0xab58(%rbp), %rdi
movl -0xa4fc(%rbp), %eax
movl %eax, -0xabc4(%rbp)
addq $0x8178, %rdi           # imm = 0x8178
callq 0x19380
movl %eax, %ecx
movl -0xabc4(%rbp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x16e19
movq -0x1d20(%rbp), %rax
movslq -0xa4fc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0xa4d8(%rbp), %eax
movl %eax, -0xa4d8(%rbp)
movl -0xa4fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4fc(%rbp)
jmp 0x16dbd
movq -0xab58(%rbp), %rdi
addq $0x8180, %rdi           # imm = 0x8180
callq 0x196f0
cmpl $0x80000000, -0xa4d0(%rbp) # imm = 0x80000000
jne 0x16e3d
jmp 0x16f77
movq -0xab58(%rbp), %rdi
movl -0xa4b8(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0xa4c0(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x81e4, %rdi           # imm = 0x81E4
callq 0x19380
movq -0xab58(%rbp), %rsi
movl %eax, -0xa4c8(%rbp)
addq $0x81b0, %rsi           # imm = 0x81B0
leaq -0xa508(%rbp), %rdi
callq 0x19490
movq -0xab58(%rbp), %rax
movq 0x81d8(%rax), %rax
movq %rax, -0xa510(%rbp)
movq -0xa510(%rbp), %rdi
callq 0x21e40
movl %eax, -0xabc8(%rbp)
jmp 0x16ead
movl -0xabc8(%rbp), %eax
movl %eax, -0xa4cc(%rbp)
leaq -0xa508(%rbp), %rdi
callq 0x194c0
movl -0xa4d8(%rbp), %ecx
movslq -0x40(%rbp), %rax
movl %ecx, -0x260(%rbp,%rax,4)
movl -0xa4cc(%rbp), %ecx
movslq -0x40(%rbp), %rax
movl %ecx, -0x460(%rbp,%rax,4)
movslq -0x40(%rbp), %rax
cvtsi2ssl -0x260(%rbp,%rax,4), %xmm0
movl -0x40(%rbp), %eax
subl $0x1, %eax
cltq
cvtsi2ssl -0x260(%rbp,%rax,4), %xmm1
divss %xmm1, %xmm0
callq 0x5700
movss %xmm0, -0x5c(%rbp)
leaq -0xab28(%rbp), %rdi
leaq -0xa4d8(%rbp), %rsi
movl $0x618, %edx            # imm = 0x618
callq 0x5360
movq %rsp, %rdi
movl $0xc3, %ecx
leaq -0xab28(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0xab68(%rbp), %rdi
callq 0x19450
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x16786
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10a8(%rbp)
movl %eax, -0x10ac(%rbp)
leaq -0xa508(%rbp), %rdi
callq 0x194c0
jmp 0x16fc7
movq -0xab60(%rbp), %rdi
movq -0x58(%rbp), %rax
movq %rax, -0xab34(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0xab2c(%rbp)
movq -0xab34(%rbp), %rax
movq %rax, -0xab44(%rbp)
movl -0xab2c(%rbp), %eax
movl %eax, -0xab3c(%rbp)
movq -0xab44(%rbp), %rsi
movl -0xab3c(%rbp), %edx
callq 0x19710
addq $0xb1e0, %rsp           # imm = 0xB1E0
popq %rbp
retq
movq -0x10a8(%rbp), %rdi
callq 0x56c0
nopw %cs:(%rax,%rax)