<commit_before>#include "simplify_instructions.hpp"
#include "analyzation.hpp"
#include "local_constant_tracker.hpp"
#include <p0i/emitter.hpp>
#include <p0run/value.hpp>
#include <boost/foreach.hpp>
#include <boost/optional.hpp>
#include <unordered_map>

namespace p0
{
	p0::intermediate::function::instruction_vector simplify_instructions(p0::intermediate::function::instruction_vector const &original)
	{
		p0::intermediate::function::instruction_vector optimized = original;
		local_constant_tracker known_locals;
		auto const jump_destinations = find_all_jump_destinations(original);
		for (std::size_t i = 0; i < optimized.size(); ++i)
		{
			if (jump_destinations.find(i) != jump_destinations.end())
			{
				known_locals.handle_incoming_jump();
			}

			auto &instruction = optimized[i];

			switch (instruction.type())
			{
			case p0::intermediate::instruction_type::set_from_constant:
				{
					known_locals.update_value(static_cast<local_address>(instruction.arguments()[0]), instruction.arguments()[1]);
					break;
				}

			case p0::intermediate::instruction_type::copy:
				{
					auto const source = static_cast<local_address>(instruction.arguments()[1]);
					auto const value = known_locals.find_current_value(source);
					if (value)
					{
						auto const destination = static_cast<local_address>(instruction.arguments()[0]);
						instruction = intermediate::make_set_from_constant(destination, *value);
					}
					break;
				}

			case p0::intermediate::instruction_type::jump_if:
			case p0::intermediate::instruction_type::jump_if_not:
				{
					auto const condition = static_cast<local_address>(instruction.arguments()[1]);
					auto const value = known_locals.find_current_value(condition);
					if (value)
					{
						auto const destination = instruction.arguments()[0];
						bool const value_for_jump = (instruction.type() == p0::intermediate::instruction_type::jump_if);<commit_msg>fix copy in simplify_instructions<commit_after>#include "simplify_instructions.hpp"
#include "analyzation.hpp"
#include "local_constant_tracker.hpp"
#include <p0i/emitter.hpp>
#include <p0run/value.hpp>
#include <boost/foreach.hpp>
#include <boost/optional.hpp>
#include <unordered_map>

namespace p0
{
	p0::intermediate::function::instruction_vector simplify_instructions(p0::intermediate::function::instruction_vector const &original)
	{
		p0::intermediate::function::instruction_vector optimized = original;
		local_constant_tracker known_locals;
		auto const jump_destinations = find_all_jump_destinations(original);
		for (std::size_t i = 0; i < optimized.size(); ++i)
		{
			if (jump_destinations.find(i) != jump_destinations.end())
			{
				known_locals.handle_incoming_jump();
			}

			auto &instruction = optimized[i];

			switch (instruction.type())
			{
			case p0::intermediate::instruction_type::set_from_constant:
				{
					known_locals.update_value(static_cast<local_address>(instruction.arguments()[0]), instruction.arguments()[1]);
					break;
				}

			case p0::intermediate::instruction_type::copy:
				{
					auto const destination = static_cast<local_address>(instruction.arguments()[0]);
					auto const source = static_cast<local_address>(instruction.arguments()[1]);
					auto const value = known_locals.find_current_value(source);
					if (value)
					{
						instruction = intermediate::make_set_from_constant(destination, *value);
						known_locals.update_value(destination, *value);
					}
					else
					{
						known_locals.set_unknown(destination);
					}
					break;
				}

			case p0::intermediate::instruction_type::jump_if:
			case p0::intermediate::instruction_type::jump_if_not:
				{
					auto const condition = static_cast<local_address>(instruction.arguments()[1]);
					auto const value = known_locals.find_current_value(condition);
					if (value)
					{
						auto const destination = instruction.arguments()[0];
						bool const value_for_jump = (instruction.type() == p0::intermediate::instruction_type::jump_if);
{'fraction_non_alphanumeric': 0.12518853695324283, 'fraction_numerical': 0.00904977375565611, 'mean_word_length': 5.159442724458204, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5433174', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1202, 'n_words': 196}