ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p, /**< byte-code data */
                                      ecma_collection_t *lit_pool_p) /**< list of known values */
{
  ecma_value_t *literal_p;
  uint32_t argument_end;
  uint32_t register_end;
  uint32_t const_literal_end;
  uint32_t literal_end;

  JERRY_ASSERT (CBC_IS_FUNCTION (compiled_code_p->status_flags));

  if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
  {
    cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p;
    uint8_t *byte_p = (uint8_t *) compiled_code_p;

    literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint16_arguments_t));
    register_end = args_p->register_end;
    const_literal_end = args_p->const_literal_end - register_end;
    literal_end = args_p->literal_end - register_end;
    argument_end = args_p->argument_end;
  }
  else
  {
    cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p;
    uint8_t *byte_p = (uint8_t *) compiled_code_p;

    literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint8_arguments_t));
    register_end = args_p->register_end;
    const_literal_end = args_p->const_literal_end - register_end;
    literal_end = args_p->literal_end - register_end;
    argument_end = args_p->argument_end;
  }

  if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
  {
    for (uint32_t i = 0; i < argument_end; i++)
    {
      ecma_save_literals_append_value (literal_p[i], lit_pool_p);
    }
  }

  for (uint32_t i = 0; i < const_literal_end; i++)
  {
    ecma_save_literals_append_value (literal_p[i], lit_pool_p);
  }

  for (uint32_t i = const_literal_end; i < literal_end; i++)
  {
    ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
                                                                        literal_p[i]);

    if (CBC_IS_FUNCTION (bytecode_p->status_flags)
        && bytecode_p != compiled_code_p)
    {
      ecma_save_literals_add_compiled_code (bytecode_p, lit_pool_p);
    }
  }

  uint8_t *byte_p = ((uint8_t *) compiled_code_p) + (((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG);
  literal_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t *) compiled_code_p, byte_p);

  while (literal_p < (ecma_value_t *) byte_p)
  {
    ecma_save_literals_append_value (*literal_p, lit_pool_p);
    literal_p++;
  }
} /* ecma_save_literals_add_compiled_code */
ecma_save_literals_add_compiled_code (const ecma_compiled_code_t *compiled_code_p,  
                                      ecma_collection_t *lit_pool_p)  
{
  ecma_value_t *literal_p;
  uint32_t argument_end;
  uint32_t register_end;
  uint32_t const_literal_end;
  uint32_t literal_end;

  JERRY_ASSERT (CBC_IS_FUNCTION (compiled_code_p->status_flags));

  if (compiled_code_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
  {
    cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) compiled_code_p;
    uint8_t *byte_p = (uint8_t *) compiled_code_p;

    literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint16_arguments_t));
    register_end = args_p->register_end;
    const_literal_end = args_p->const_literal_end - register_end;
    literal_end = args_p->literal_end - register_end;
    argument_end = args_p->argument_end;
  }
  else
  {
    cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) compiled_code_p;
    uint8_t *byte_p = (uint8_t *) compiled_code_p;

    literal_p = (ecma_value_t *) (byte_p + sizeof (cbc_uint8_arguments_t));
    register_end = args_p->register_end;
    const_literal_end = args_p->const_literal_end - register_end;
    literal_end = args_p->literal_end - register_end;
    argument_end = args_p->argument_end;
  }

  if (compiled_code_p->status_flags & CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED)
  {
    for (uint32_t i = 0; i < argument_end; i++)
    {
      ecma_save_literals_append_value (literal_p[i], lit_pool_p);
    }
  }

  for (uint32_t i = 0; i < const_literal_end; i++)
  {
    ecma_save_literals_append_value (literal_p[i], lit_pool_p);
  }

  for (uint32_t i = const_literal_end; i < literal_end; i++)
  {
    ecma_compiled_code_t *bytecode_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_compiled_code_t,
                                                                        literal_p[i]);

    if (CBC_IS_FUNCTION (bytecode_p->status_flags)
        && bytecode_p != compiled_code_p)
    {
      ecma_save_literals_add_compiled_code (bytecode_p, lit_pool_p);
    }
  }

  uint8_t *byte_p = ((uint8_t *) compiled_code_p) + (((size_t) compiled_code_p->size) << JMEM_ALIGNMENT_LOG);
  literal_p = ecma_snapshot_resolve_serializable_values ((ecma_compiled_code_t *) compiled_code_p, byte_p);

  while (literal_p < (ecma_value_t *) byte_p)
  {
    ecma_save_literals_append_value (*literal_p, lit_pool_p);
    literal_p++;
  }
}  