// File: EnderGed[P]fast-random-walk/WeightedGraph.cpp
// Function: WeightedGraph::readGraph(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned long)
WeightedGraph WeightedGraph::readGraph(std::string const input, uint64_t const flags)
{
	bool isSorted = true;
	read_t numRows;
	uint * data;

	////	Read from file	////
	{
		char const * fileContent = input.c_str();
		char const * fileContentEnd = fileContent + input.size();

		// Trim file content
		while(fileContent < fileContentEnd && *fileContent <= ' ') ++fileContent;
		while(fileContent < fileContentEnd && *(fileContentEnd - 1) <= ' ') --fileContentEnd;

		// Count rows
		numRows = count(fileContent, fileContentEnd, '\n') + 1;

		// Malloc data array (3 dimensions)
		data = (uint *) malloc(numRows * 3 * sizeof(*data));

		// File content to array
		char const * pos = fileContent;
		read_t prev = 0;
		unsigned readLen = 0;

		// For every row/transition ...
		for(read_t i = 0; i < numRows; ++i)
		{
			// Read source node
			uint const from = readInt(pos, fileContentEnd, readLen);

			// Go to next number
			pos += readLen;
			pos += nonDigits(pos, fileContentEnd);

			// Read target node
			uint const to = readInt(pos, fileContentEnd, readLen);

			// Go to next number
			pos += readLen;
			pos += nonDigits(pos, fileContentEnd);

			// Read weight
			uint const weight = readInt(pos, fileContentEnd, readLen);

			// Go to next number/line (or end of file)
			pos += readLen;
			pos += nonDigits(pos, fileContentEnd);

			// Put into data array
			data[3 * i] = from;
			data[3 * i + 1] = to;
			data[3 * i + 2] = weight;

			if(from < prev) isSorted = false;

			prev = from;
		}
	}

	// Sort if necessary
	if(!isSorted) countSort2D(data, 3, numRows);

	////		Render node starts	////
	uint * weights = (uint*)malloc(numRows * sizeof(*weights));
	uint const numIndices = data[3 * numRows - 3] + 1;
	read_t * const indices = (read_t *) malloc((numIndices + 1) * sizeof(*indices));
	
	// Create adjacency list
	uint curr = 0;
	indices[0] = 0;

	for(read_t i = 0; i < numRows; ++i)
	{
		// Set target[curr] for all nodes until the start node of the i-th transition
		while(data[3 * i] > curr) indices[++curr] = i;

		// Copy target node id to new (shrinked) position
		data[i] = data[3 * i + 1];
		// Copy the weight of the transition to weights
		weights[i] = data[3 * i + 2];
	}

	// Set target[curr] to end of data-set for all remaining indices
	while(curr < numIndices) indices[++curr] = numRows;

	// Shrink the size of data to its real content
	data = (uint *) realloc(data, numRows * sizeof(*data));

	////		Convert the graph to an undirected graph	////
	if(flags & (flag_undirected | flag_reflect))
	{
		// Sort the transitions for each source node
		// (Target nodes in increasing order)
		for(uint i = 0; i < numIndices; ++i)
		{
			read_t const start = indices[i];
			read_t const count = indices[i + 1] - start;

			if(count > 1) countSort2D({data + start, weights + start}, count);
		}

		///		Count number of missing transitions for every node		///
		uint * const counters = (uint *) calloc(numIndices, sizeof(*counters));
		std::vector<bool> bitSet(numRows * 2, false);
		read_t acc = 0; // Sum of all counters

		// For every source node ...
		for(uint node = 0; node < numIndices; ++node)
		{
			// For every transition of the node ...
			for(read_t trans = indices[node]; trans < indices[node + 1]; ++trans)
			{
				uint const targetNode = data[trans];
				uint const * const from = data + indices[targetNode];
				uint const * const to = data + indices[targetNode + 1];
				uint const * const found = binaryFind(from, to, node);

				// If has no counterpart ...
				if(found == to || *found != node)
				{
					// Increment counter for target node
					++counters[targetNode];
					// Increment number of transitions
					++acc;
					// Set bit in bitSet
					bitSet[trans] = true;
				}
				else if(flags & flag_reflect)
				{
					read_t const other_trans = found - data;
					if(other_trans > trans) weights[trans] = weights[other_trans] = weights[other_trans] + weights[trans];
				}
			}
		}

		if(acc)
		{
			////	Adapt list (make it undirected)		////
			// Resize transitions lists (data and weights)
			numRows += acc;
			data = (uint *) realloc(data, numRows * sizeof(*data));
			weights = (uint *) realloc(weights, numRows * sizeof(*weights));

			// For every node (from last to first)
			for(uint node = numIndices - 1; node > 0; --node)
			{
				// Get number of transitions
				size_t const len = indices[node + 1] - indices[node];
				// Increase end by accumulative counter
				indices[node + 1] += acc;
				// Subtract own new transitions from accumulative counter
				acc -= counters[node];
				//Move transitions to new position
				memmove(data + indices[node] + acc, data + indices[node], len * sizeof(*data));
				memmove(weights + indices[node] + acc, weights + indices[node], len * sizeof(*weights));
				// Move bits in bitSet
				std::move_backward(bitSet.begin() + indices[node], bitSet.begin() + (indices[node] + len), bitSet.begin() + (indices[node] + len + acc));
				std::fill(bitSet.begin() + (indices[node] + acc - counters[node - 1]), bitSet.begin() + (indices[node] + acc), false);
			}

			// Node 0
			indices[1] += acc;

			////	Add new transitions		////
			// For every node ...
			for(uint node = 0; node < numIndices; ++node)
			{
				// For every transition of that node ...
				for(read_t trans = indices[node]; trans < indices[node + 1]; ++trans)
				{
					if(bitSet[trans])
					{
						uint const targetNode = data[trans];
						uint const weight = weights[trans];
						data[indices[targetNode + 1] - (counters[targetNode])] = node;
						weights[indices[targetNode + 1] - (counters[targetNode])] = weight;

						--counters[targetNode];
					}
				}
			}
		}
		else if(!(flags & flag_reflect)) printf("Graph is already undirected\n");

		free(counters);
	}

	////		Optimize transition order	////
	if((flags & flag_optiTransOrder) && numIndices > 0)
	{
		// Sort each node
		for(uint nodeId = 0; nodeId < numIndices; ++nodeId)
		{
			// Determine sort range
			read_t const start = indices[nodeId];
			read_t const count = indices[nodeId + 1] - start;

			// Sort node (lowest weight first)
			countSort2D({weights + start, data + start}, count);

			// Reverse order (highest weight first)
			std::reverse(data + start, data + start + count);
			std::reverse(weights + start, weights + start + count);
		}
	}

	////		Post-Processing		////
	bool errorFound = false;
	// Accumulate weights
	for(read_t const * posIndices = indices, * indicesEnd = indices + numIndices; posIndices < indicesEnd; ++posIndices)
	{ // For each node ...
		uint newWeight = weights[*posIndices];
	
		// Accumulate weights of this nodes transitions
		for(read_t posWeights = *posIndices + 1; posWeights < *(posIndices + 1); ++posWeights)
		{
			//if(__builtin_add_overflow(weights[posWeights], weights[posWeights - 1], &weights[posWeights])) std::cout << "!!!!!Problem!!!!!" << std::endl;
			newWeight = weights[posWeights] + weights[posWeights - 1];
			if(newWeight < weights[posWeights] || newWeight < weights[posWeights - 1])
			{
				printf("Integer Overflow!!!");
				exit(1);
			}
			weights[posWeights] = newWeight;
		}

		// Check whether sum of weights is 0
		if(newWeight == 0)
		{
			printf("Node %lu has an accumulative weight of 0!\n", posIndices - indices);
			errorFound = true;
		}
	}
	
	if(errorFound) exit(1);

	return WeightedGraph(numIndices, indices, data, weights);
}

// Assembly:
subq $0x458, %rsp            # imm = 0x458
movq %rsi, 0xc0(%rsp)
movq %rdi, %rax
movq 0xc0(%rsp), %rdi
movq %rax, 0xb0(%rsp)
movq %rax, %rcx
movq %rcx, 0xb8(%rsp)
movq %rax, 0x450(%rsp)
movq %rdi, 0x448(%rsp)
movq %rdx, 0x440(%rsp)
movb $0x1, 0x43f(%rsp)
callq 0x20a0
movq 0xc0(%rsp), %rdi
movq %rax, 0x420(%rsp)
movq 0x420(%rsp), %rax
movq %rax, 0xc8(%rsp)
callq 0x2140
movq %rax, %rcx
movq 0xc8(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x418(%rsp)
movq 0x420(%rsp), %rcx
xorl %eax, %eax
cmpq 0x418(%rsp), %rcx
movb %al, 0xaf(%rsp)
jae 0x7a10
movq 0x420(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
setle %al
movb %al, 0xaf(%rsp)
movb 0xaf(%rsp), %al
testb $0x1, %al
jne 0x7a1d
jmp 0x7a33
movq 0x420(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x420(%rsp)
jmp 0x79dd
jmp 0x7a35
movq 0x420(%rsp), %rcx
xorl %eax, %eax
cmpq 0x418(%rsp), %rcx
movb %al, 0xae(%rsp)
jae 0x7a69
movq 0x418(%rsp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x20, %eax
setle %al
movb %al, 0xae(%rsp)
movb 0xae(%rsp), %al
testb $0x1, %al
jne 0x7a76
jmp 0x7a8c
movq 0x418(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x418(%rsp)
jmp 0x7a35
movq 0x420(%rsp), %rdi
movq 0x418(%rsp), %rsi
movl $0xa, %edx
callq 0x62f0
addq $0x1, %rax
movq %rax, 0x430(%rsp)
imulq $0x3, 0x430(%rsp), %rdi
shlq $0x2, %rdi
callq 0x2240
movq %rax, 0x428(%rsp)
movq 0x420(%rsp), %rax
movq %rax, 0x410(%rsp)
movq $0x0, 0x408(%rsp)
movl $0x0, 0x404(%rsp)
movq $0x0, 0x3f8(%rsp)
movq 0x3f8(%rsp), %rax
cmpq 0x430(%rsp), %rax
jae 0x7ced
movq 0x410(%rsp), %rdi
movq 0x418(%rsp), %rsi
leaq 0x404(%rsp), %rdx
callq 0x28b0
movl %eax, 0x3f4(%rsp)
movl 0x404(%rsp), %ecx
movq 0x410(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x410(%rsp)
movq 0x410(%rsp), %rdi
movq 0x418(%rsp), %rsi
callq 0x2830
movl %eax, %ecx
movq 0x410(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x410(%rsp)
movq 0x410(%rsp), %rdi
movq 0x418(%rsp), %rsi
leaq 0x404(%rsp), %rdx
callq 0x28b0
movl %eax, 0x3f0(%rsp)
movl 0x404(%rsp), %ecx
movq 0x410(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x410(%rsp)
movq 0x410(%rsp), %rdi
movq 0x418(%rsp), %rsi
callq 0x2830
movl %eax, %ecx
movq 0x410(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x410(%rsp)
movq 0x410(%rsp), %rdi
movq 0x418(%rsp), %rsi
leaq 0x404(%rsp), %rdx
callq 0x28b0
movl %eax, 0x3ec(%rsp)
movl 0x404(%rsp), %ecx
movq 0x410(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x410(%rsp)
movq 0x410(%rsp), %rdi
movq 0x418(%rsp), %rsi
callq 0x2830
movl %eax, %ecx
movq 0x410(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x410(%rsp)
movl 0x3f4(%rsp), %edx
movq 0x428(%rsp), %rax
imulq $0x3, 0x3f8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x3f0(%rsp), %edx
movq 0x428(%rsp), %rax
imulq $0x3, 0x3f8(%rsp), %rcx
movl %edx, 0x4(%rax,%rcx,4)
movl 0x3ec(%rsp), %edx
movq 0x428(%rsp), %rax
imulq $0x3, 0x3f8(%rsp), %rcx
movl %edx, 0x8(%rax,%rcx,4)
movl 0x3f4(%rsp), %eax
cmpq 0x408(%rsp), %rax
jae 0x7cc5
movb $0x0, 0x43f(%rsp)
movl 0x3f4(%rsp), %eax
movq %rax, 0x408(%rsp)
movq 0x3f8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x3f8(%rsp)
jmp 0x7aff
testb $0x1, 0x43f(%rsp)
jne 0x7d15
movq 0x428(%rsp), %rdi
movq 0x430(%rsp), %rdx
movl $0x3, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x6700
movq 0x430(%rsp), %rdi
shlq $0x2, %rdi
callq 0x2240
movq %rax, 0x3e0(%rsp)
movq 0x428(%rsp), %rax
imulq $0x3, 0x430(%rsp), %rcx
subq $0x3, %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, 0x3dc(%rsp)
movl 0x3dc(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2240
movq %rax, 0x3d0(%rsp)
movl $0x0, 0x3cc(%rsp)
movq 0x3d0(%rsp), %rax
movq $0x0, (%rax)
movq $0x0, 0x3c0(%rsp)
movq 0x3c0(%rsp), %rax
cmpq 0x430(%rsp), %rax
jae 0x7e5c
jmp 0x7dad
movq 0x428(%rsp), %rax
imulq $0x3, 0x3c0(%rsp), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0x3cc(%rsp), %eax
jbe 0x7df3
movq 0x3c0(%rsp), %rdx
movq 0x3d0(%rsp), %rax
movl 0x3cc(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x3cc(%rsp)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x7dad
movq 0x428(%rsp), %rax
imulq $0x3, 0x3c0(%rsp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq 0x428(%rsp), %rax
movq 0x3c0(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x428(%rsp), %rax
imulq $0x3, 0x3c0(%rsp), %rcx
movl 0x8(%rax,%rcx,4), %edx
movq 0x3e0(%rsp), %rax
movq 0x3c0(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x3c0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x3c0(%rsp)
jmp 0x7d95
jmp 0x7e5e
movl 0x3cc(%rsp), %eax
cmpl 0x3dc(%rsp), %eax
jae 0x7e97
movq 0x430(%rsp), %rdx
movq 0x3d0(%rsp), %rax
movl 0x3cc(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x3cc(%rsp)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x7e5e
movq 0x428(%rsp), %rdi
movq 0x430(%rsp), %rsi
shlq $0x2, %rsi
callq 0x22c0
movq %rax, 0x428(%rsp)
movq 0x440(%rsp), %rax
andq $0x9, %rax
cmpq $0x0, %rax
je 0x8b18
movl $0x0, 0x3bc(%rsp)
movl 0x3bc(%rsp), %eax
cmpl 0x3dc(%rsp), %eax
jae 0x8063
movq 0x3d0(%rsp), %rax
movl 0x3bc(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x3b0(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x3bc(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
subq 0x3b0(%rsp), %rax
movq %rax, 0x3a8(%rsp)
cmpq $0x1, 0x3a8(%rsp)
jbe 0x804b
movq 0x428(%rsp), %rax
movq 0x3b0(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, 0x370(%rsp)
movq 0x3e0(%rsp), %rax
movq 0x3b0(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, 0x378(%rsp)
leaq 0x370(%rsp), %rax
movq %rax, 0x380(%rsp)
movq $0x2, 0x388(%rsp)
leaq 0x36f(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x9020
movq 0xa0(%rsp), %rcx
movq 0x380(%rsp), %rsi
movq 0x388(%rsp), %rdx
leaq 0x390(%rsp), %rdi
callq 0x9030
jmp 0x7fcf
movq 0x3a8(%rsp), %rsi
leaq 0x390(%rsp), %rdi
callq 0x6fa0
jmp 0x7fe6
leaq 0x390(%rsp), %rdi
callq 0x90c0
leaq 0x36f(%rsp), %rdi
callq 0x9120
jmp 0x804b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x360(%rsp)
movl %eax, 0x35c(%rsp)
jmp 0x8039
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x360(%rsp)
movl %eax, 0x35c(%rsp)
leaq 0x390(%rsp), %rdi
callq 0x90c0
leaq 0x36f(%rsp), %rdi
callq 0x9120
jmp 0x8f32
jmp 0x804d
movl 0x3bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3bc(%rsp)
jmp 0x7ed9
movl 0x3dc(%rsp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x2120
movq %rax, 0x350(%rsp)
movq 0x430(%rsp), %rax
addq %rax, %rax
movq %rax, 0x90(%rsp)
movb $0x0, 0x327(%rsp)
leaq 0x326(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x3a80
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rcx
leaq 0x328(%rsp), %rdi
leaq 0x327(%rsp), %rdx
callq 0x3a90
jmp 0x80d5
leaq 0x326(%rsp), %rdi
callq 0x3b10
movq $0x0, 0x318(%rsp)
movl $0x0, 0x314(%rsp)
movl 0x314(%rsp), %eax
cmpl 0x3dc(%rsp), %eax
jae 0x83a8
movq 0x3d0(%rsp), %rax
movl 0x314(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x308(%rsp)
movq 0x308(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x314(%rsp), %edx
addl $0x1, %edx
movl %edx, %edx
cmpq (%rcx,%rdx,8), %rax
jae 0x8390
movq 0x428(%rsp), %rax
movq 0x308(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x304(%rsp)
movq 0x428(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x304(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x2f8(%rsp)
movq 0x428(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x304(%rsp), %edx
addl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x2f0(%rsp)
movq 0x2f8(%rsp), %rdi
movq 0x2f0(%rsp), %rsi
movl 0x314(%rsp), %edx
callq 0x9130
movq %rax, 0x2e8(%rsp)
movq 0x2e8(%rsp), %rax
cmpq 0x2f0(%rsp), %rax
je 0x820e
movq 0x2e8(%rsp), %rax
movl (%rax), %eax
cmpl 0x314(%rsp), %eax
je 0x82e2
movq 0x350(%rsp), %rax
movl 0x304(%rsp), %ecx
movl (%rax,%rcx,4), %edx
incl %edx
movl %edx, (%rax,%rcx,4)
movq 0x318(%rsp), %rax
incq %rax
movq %rax, 0x318(%rsp)
movq 0x308(%rsp), %rsi
leaq 0x328(%rsp), %rdi
callq 0x3bb0
movq %rdx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
jmp 0x825f
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rcx
movq %rcx, 0x2d8(%rsp)
movq %rax, 0x2e0(%rsp)
leaq 0x2d8(%rsp), %rdi
movl $0x1, %esi
callq 0x3c10
jmp 0x8375
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x360(%rsp)
movl %eax, 0x35c(%rsp)
leaq 0x326(%rsp), %rdi
callq 0x3b10
jmp 0x8f32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x360(%rsp)
movl %eax, 0x35c(%rsp)
leaq 0x328(%rsp), %rdi
callq 0x3e90
jmp 0x8f32
movq 0x440(%rsp), %rax
andq $0x8, %rax
cmpq $0x0, %rax
je 0x8373
movq 0x2e8(%rsp), %rax
movq 0x428(%rsp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movq %rax, 0x2d0(%rsp)
movq 0x2d0(%rsp), %rax
cmpq 0x308(%rsp), %rax
jbe 0x8371
movq 0x3e0(%rsp), %rax
movq 0x2d0(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x3e0(%rsp), %rax
movq 0x308(%rsp), %rcx
addl (%rax,%rcx,4), %edx
movq 0x3e0(%rsp), %rax
movq 0x2d0(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x3e0(%rsp), %rax
movq 0x308(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x8373
jmp 0x8375
jmp 0x8377
movq 0x308(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x308(%rsp)
jmp 0x8128
jmp 0x8392
movl 0x314(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x314(%rsp)
jmp 0x80f9
cmpq $0x0, 0x318(%rsp)
je 0x8ad8
movq 0x318(%rsp), %rax
addq 0x430(%rsp), %rax
movq %rax, 0x430(%rsp)
movq 0x428(%rsp), %rdi
movq 0x430(%rsp), %rsi
shlq $0x2, %rsi
callq 0x22c0
movq %rax, 0x428(%rsp)
movq 0x3e0(%rsp), %rdi
movq 0x430(%rsp), %rsi
shlq $0x2, %rsi
callq 0x22c0
movq %rax, 0x3e0(%rsp)
movl 0x3dc(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x2cc(%rsp)
cmpl $0x0, 0x2cc(%rsp)
jbe 0x8910
movq 0x3d0(%rsp), %rcx
movl 0x2cc(%rsp), %eax
movl %eax, %edx
movl %edx, %eax
incl %eax
movq (%rcx,%rax,8), %rax
movq (%rcx,%rdx,8), %rcx
subq %rcx, %rax
movq %rax, 0x2c0(%rsp)
movq 0x318(%rsp), %rsi
movq 0x3d0(%rsp), %rax
movl 0x2cc(%rsp), %ecx
incl %ecx
movq (%rax,%rcx,8), %rdx
addq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x350(%rsp), %rax
movl 0x2cc(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
movq 0x318(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x318(%rsp)
movq 0x428(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x2cc(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
leaq (%rax,%rcx,4), %rsi
movq 0x318(%rsp), %rax
leaq (%rsi,%rax,4), %rdi
movq 0x2c0(%rsp), %rdx
shlq $0x2, %rdx
callq 0x22b0
movq 0x3e0(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x2cc(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
leaq (%rax,%rcx,4), %rsi
movq 0x318(%rsp), %rax
leaq (%rsi,%rax,4), %rdi
movq 0x2c0(%rsp), %rdx
shlq $0x2, %rdx
callq 0x22b0
leaq 0x328(%rsp), %rdi
callq 0x3db0
movl %edx, 0x298(%rsp)
movq %rax, 0x290(%rsp)
movl 0x298(%rsp), %eax
movl %eax, 0x2a8(%rsp)
movq 0x290(%rsp), %rax
movq %rax, 0x2a0(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x2cc(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x3d70
movl %edx, 0x74(%rsp)
movq %rax, 0x78(%rsp)
jmp 0x8580
movl 0x74(%rsp), %eax
movq 0x78(%rsp), %rcx
movq %rcx, 0x280(%rsp)
movl %eax, 0x288(%rsp)
movl 0x288(%rsp), %eax
movl %eax, 0x2b8(%rsp)
movq 0x280(%rsp), %rax
movq %rax, 0x2b0(%rsp)
leaq 0x328(%rsp), %rdi
callq 0x3db0
movl %edx, 0x258(%rsp)
movq %rax, 0x250(%rsp)
movl 0x258(%rsp), %eax
movl %eax, 0x268(%rsp)
movq 0x250(%rsp), %rax
movq %rax, 0x260(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x2cc(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
movq 0x2c0(%rsp), %rax
addq %rax, %rsi
leaq 0x260(%rsp), %rdi
callq 0x3d70
movl %edx, 0x64(%rsp)
movq %rax, 0x68(%rsp)
jmp 0x8626
movl 0x64(%rsp), %eax
movq 0x68(%rsp), %rcx
movq %rcx, 0x240(%rsp)
movl %eax, 0x248(%rsp)
movl 0x248(%rsp), %eax
movl %eax, 0x278(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0x270(%rsp)
leaq 0x328(%rsp), %rdi
callq 0x3db0
movl %edx, 0x218(%rsp)
movq %rax, 0x210(%rsp)
movl 0x218(%rsp), %eax
movl %eax, 0x228(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x220(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x2cc(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
movq 0x2c0(%rsp), %rax
addq %rax, %rsi
movq 0x318(%rsp), %rax
addq %rax, %rsi
leaq 0x220(%rsp), %rdi
callq 0x3d70
movl %edx, 0x54(%rsp)
movq %rax, 0x58(%rsp)
jmp 0x86d7
movl 0x54(%rsp), %eax
movq 0x58(%rsp), %rcx
movq %rcx, 0x200(%rsp)
movl %eax, 0x208(%rsp)
movl 0x208(%rsp), %eax
movl %eax, 0x238(%rsp)
movq 0x200(%rsp), %rax
movq %rax, 0x230(%rsp)
movq 0x2b0(%rsp), %rdi
movl 0x2b8(%rsp), %esi
movq 0x270(%rsp), %rdx
movl 0x278(%rsp), %ecx
movq 0x230(%rsp), %r8
movl 0x238(%rsp), %r9d
callq 0x3c60
movl %edx, 0x44(%rsp)
movq %rax, 0x48(%rsp)
jmp 0x874b
movl 0x44(%rsp), %eax
movq 0x48(%rsp), %rcx
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1f8(%rsp)
leaq 0x328(%rsp), %rdi
callq 0x3db0
movl %edx, 0x1c8(%rsp)
movq %rax, 0x1c0(%rsp)
movl 0x1c8(%rsp), %eax
movl %eax, 0x1d8(%rsp)
movq 0x1c0(%rsp), %rax
movq %rax, 0x1d0(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x2cc(%rsp), %ecx
movl %ecx, %edx
movl %edx, %ecx
movq (%rax,%rdx,8), %rsi
movq 0x318(%rsp), %rax
addq %rax, %rsi
movq 0x350(%rsp), %rax
decl %ecx
movl (%rax,%rcx,4), %eax
subq %rax, %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x3d70
movl %edx, 0x34(%rsp)
movq %rax, 0x38(%rsp)
jmp 0x87e7
movl 0x34(%rsp), %eax
movq 0x38(%rsp), %rcx
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1b8(%rsp)
movl 0x1b8(%rsp), %eax
movl %eax, 0x1e8(%rsp)
movq 0x1b0(%rsp), %rax
movq %rax, 0x1e0(%rsp)
leaq 0x328(%rsp), %rdi
callq 0x3db0
movl %edx, 0x188(%rsp)
movq %rax, 0x180(%rsp)
movl 0x188(%rsp), %eax
movl %eax, 0x198(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x2cc(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
movq 0x318(%rsp), %rax
addq %rax, %rsi
leaq 0x190(%rsp), %rdi
callq 0x3d70
movl %edx, 0x24(%rsp)
movq %rax, 0x28(%rsp)
jmp 0x888d
movl 0x24(%rsp), %eax
movq 0x28(%rsp), %rcx
movq %rcx, 0x170(%rsp)
movl %eax, 0x178(%rsp)
movl 0x178(%rsp), %eax
movl %eax, 0x1a8(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movb $0x0, 0x16f(%rsp)
movq 0x1e0(%rsp), %rdi
movl 0x1e8(%rsp), %esi
movq 0x1a0(%rsp), %rdx
movl 0x1a8(%rsp), %ecx
leaq 0x16f(%rsp), %r8
callq 0x3df0
jmp 0x88f8
jmp 0x88fa
movl 0x2cc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x2cc(%rsp)
jmp 0x8422
movq 0x318(%rsp), %rcx
movq 0x3d0(%rsp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, 0x168(%rsp)
movl 0x168(%rsp), %eax
cmpl 0x3dc(%rsp), %eax
jae 0x8ad6
movq 0x3d0(%rsp), %rax
movl 0x168(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x168(%rsp), %edx
addl $0x1, %edx
movl %edx, %edx
cmpq (%rcx,%rdx,8), %rax
jae 0x8abe
movq 0x160(%rsp), %rsi
leaq 0x328(%rsp), %rdi
callq 0x3bb0
movq %rdx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
jmp 0x89a9
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x150(%rsp)
movq %rax, 0x158(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x3e60
testb $0x1, %al
jne 0x89d9
jmp 0x8aa3
movq 0x428(%rsp), %rax
movq 0x160(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x14c(%rsp)
movq 0x3e0(%rsp), %rax
movq 0x160(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x148(%rsp)
movl 0x168(%rsp), %edx
movq 0x428(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x14c(%rsp), %esi
addl $0x1, %esi
movl %esi, %esi
movq (%rcx,%rsi,8), %rcx
movq 0x350(%rsp), %rsi
movl 0x14c(%rsp), %edi
movl (%rsi,%rdi,4), %esi
subq %rsi, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x148(%rsp), %edx
movq 0x3e0(%rsp), %rax
movq 0x3d0(%rsp), %rcx
movl 0x14c(%rsp), %esi
addl $0x1, %esi
movl %esi, %esi
movq (%rcx,%rsi,8), %rcx
movq 0x350(%rsp), %rsi
movl 0x14c(%rsp), %edi
movl (%rsi,%rdi,4), %esi
subq %rsi, %rcx
movl %edx, (%rax,%rcx,4)
movq 0x350(%rsp), %rax
movl 0x14c(%rsp), %ecx
movl (%rax,%rcx,4), %edx
addl $-0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x8aa5
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x8962
jmp 0x8ac0
movl 0x168(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x168(%rsp)
jmp 0x8933
jmp 0x8afe
movq 0x440(%rsp), %rax
andq $0x8, %rax
cmpq $0x0, %rax
jne 0x8afc
leaq 0x358b(%rip), %rdi      # 0xc07c
xorl %eax, %eax
callq 0x2040
jmp 0x8afa
jmp 0x8afc
jmp 0x8afe
movq 0x350(%rsp), %rdi
callq 0x2220
leaq 0x328(%rsp), %rdi
callq 0x3e90
movq 0x440(%rsp), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x8d3e
cmpl $0x0, 0x3dc(%rsp)
jbe 0x8d3e
movl $0x0, 0x144(%rsp)
movl 0x144(%rsp), %eax
cmpl 0x3dc(%rsp), %eax
jae 0x8d3c
movq 0x3d0(%rsp), %rax
movl 0x144(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x138(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x144(%rsp), %ecx
incl %ecx
movq (%rax,%rcx,8), %rax
movq 0x138(%rsp), %rcx
subq %rcx, %rax
movq %rax, 0x130(%rsp)
movq 0x3e0(%rsp), %rax
movq 0x138(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, 0xf8(%rsp)
movq 0x428(%rsp), %rax
movq 0x138(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, 0x100(%rsp)
leaq 0xf8(%rsp), %rax
movq %rax, 0x108(%rsp)
movq $0x2, 0x110(%rsp)
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x9020
movq 0x8(%rsp), %rcx
movq 0x108(%rsp), %rsi
movq 0x110(%rsp), %rdx
leaq 0x118(%rsp), %rdi
callq 0x9030
jmp 0x8c28
movq 0x130(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0x6fa0
jmp 0x8c3f
leaq 0x118(%rsp), %rdi
callq 0x90c0
leaq 0xf7(%rsp), %rdi
callq 0x9120
movq 0x428(%rsp), %rdi
movq 0x138(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x428(%rsp), %rsi
movq 0x138(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movq 0x130(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x9200
movq 0x3e0(%rsp), %rdi
movq 0x138(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x3e0(%rsp), %rsi
movq 0x138(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movq 0x130(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x9200
movl 0x144(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x144(%rsp)
jmp 0x8b47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x360(%rsp)
movl %eax, 0x35c(%rsp)
jmp 0x8d2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x360(%rsp)
movl %eax, 0x35c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x90c0
leaq 0xf7(%rsp), %rdi
callq 0x9120
jmp 0x8f32
jmp 0x8d3e
movb $0x0, 0xf6(%rsp)
movq 0x3d0(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0x3d0(%rsp), %rax
movl 0x3dc(%rsp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xe0(%rsp)
movq 0xe8(%rsp), %rax
cmpq 0xe0(%rsp), %rax
jae 0x8ee2
movq 0x3e0(%rsp), %rax
movq 0xe8(%rsp), %rcx
movq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xdc(%rsp)
movq 0xe8(%rsp), %rax
movq (%rax), %rax
addq $0x1, %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movq 0xe8(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x8e90
movq 0x3e0(%rsp), %rax
movq 0xd0(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq 0x3e0(%rsp), %rcx
movq 0xd0(%rsp), %rdx
subq $0x1, %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, 0xdc(%rsp)
movl 0xdc(%rsp), %eax
movq 0x3e0(%rsp), %rcx
movq 0xd0(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jb 0x8e45
movl 0xdc(%rsp), %eax
movq 0x3e0(%rsp), %rcx
movq 0xd0(%rsp), %rdx
subq $0x1, %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x8e5d
leaq 0x3377(%rip), %rdi      # 0xc1c3
movb $0x0, %al
callq 0x2040
movl $0x1, %edi
callq 0x2230
movl 0xdc(%rsp), %edx
movq 0x3e0(%rsp), %rax
movq 0xd0(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0xd0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xd0(%rsp)
jmp 0x8dbe
cmpl $0x0, 0xdc(%rsp)
jne 0x8ec7
movq 0xe8(%rsp), %rsi
movq 0x3d0(%rsp), %rax
subq %rax, %rsi
sarq $0x3, %rsi
leaq 0x331f(%rip), %rdi      # 0xc1d7
movb $0x0, %al
callq 0x2040
movb $0x1, 0xf6(%rsp)
jmp 0x8ec9
movq 0xe8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xe8(%rsp)
jmp 0x8d74
testb $0x1, 0xf6(%rsp)
je 0x8ef6
movl $0x1, %edi
callq 0x2230
movq 0xb0(%rsp), %rdi
movl 0x3dc(%rsp), %esi
movq 0x3d0(%rsp), %rdx
movq 0x428(%rsp), %rcx
movq 0x3e0(%rsp), %r8
callq 0x73d0
movq 0xb8(%rsp), %rax
addq $0x458, %rsp            # imm = 0x458
retq
movq 0x360(%rsp), %rdi
callq 0x22d0
nop