decompiled_code:
__int64 __fastcall write_static_buffer_funcs(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

v1 = strformat(
"static HarisStatus read_from_buffer_stream(void *_stream, \n"
" haris_uint32_t count,\n"
" const unsigned char **dest)\n"
"{\n"
" HarisBufferStream *stream = (HarisBufferStream*)_stream;\n"
" HARIS_ASSERT(count + stream->curr <= stream->sz, INPUT);\n"
" HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" *dest = stream->buffer + stream->curr;\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static HarisStatus write_to_buffer_stream(void *_stream,\n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" HarisBufferStream *stream = (HarisBufferStream*)_stream;\n"
" /* No error checking necessary; the size of the structure is verified\n"
" before serialization begins */\n"
" memcpy(stream->buffer + stream->curr, src, count);\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static HarisStatus _public_to_buffer_a(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" unsigned char **out_buf,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisBufferStream buffer_stream;\n"
" haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n"
" if (encoded_size == 0) return result;\n"
" HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" buffer_stream.buffer = (unsigned char *)malloc(encoded_size);\n"
" HARIS_ASSERT(buffer_stream.buffer, MEM);\n"
" buffer_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &buffer_stream, \n"
" write_to_buffer_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" *out_sz = encoded_size;\n"
" *out_buf = buffer_stream.buffer;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static HarisStatus _public_to_buffer(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" HarisStatus result;\n"
" HarisBufferStream buffer_stream;\n"
" haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n"
" if (encoded_size == 0) return result;\n"
" HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" HARIS_ASSERT(encoded_size <= sz, INPUT);\n"
" buffer_stream.buffer = buf;\n"
" buffer_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &buffer_stream,\n"
" write_to_buffer_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_addr) *out_addr = buf + buffer_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = strformat(
"static HarisStatus _public_from_buffer(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" HarisStatus result;\n"
" HarisBufferStream buffer_stream;\n"
" buffer_stream.buffer = buf;\n"
" buffer_stream.sz = sz;\n"
" buffer_stream.curr = 0;\n"
" if ((result = _haris_from_stream(ptr, info, &buffer_stream, \n"
" read_from_buffer_stream, 0)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_addr) *out_addr = buf + buffer_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
result = add_private_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

v1 = strformat(
"static HarisStatus read_from_buffer_stream(void *_stream, \n"
" haris_uint32_t count,\n"
" const unsigned char **dest)\n"
"{\n"
" HarisBufferStream *stream = (HarisBufferStream*)_stream;\n"
" HARIS_ASSERT(count + stream->curr <= stream->sz, INPUT);\n"
" HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" *dest = stream->buffer + stream->curr;\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static HarisStatus write_to_buffer_stream(void *_stream,\n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" HarisBufferStream *stream = (HarisBufferStream*)_stream;\n"
" /* No error checking necessary; the size of the structure is verified\n"
" before serialization begins */\n"
" memcpy(stream->buffer + stream->curr, src, count);\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static HarisStatus _public_to_buffer_a(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" unsigned char **out_buf,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisBufferStream buffer_stream;\n"
" haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n"
" if (encoded_size == 0) return result;\n"
" HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" buffer_stream.buffer = (unsigned char *)malloc(encoded_size);\n"
" HARIS_ASSERT(buffer_stream.buffer, MEM);\n"
" buffer_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &buffer_stream, \n"
" write_to_buffer_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" *out_sz = encoded_size;\n"
" *out_buf = buffer_stream.buffer;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static HarisStatus _public_to_buffer(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" HarisStatus result;\n"
" HarisBufferStream buffer_stream;\n"
" haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n"
" if (encoded_size == 0) return result;\n"
" HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" HARIS_ASSERT(encoded_size <= sz, INPUT);\n"
" buffer_stream.buffer = buf;\n"
" buffer_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &buffer_stream,\n"
" write_to_buffer_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_addr) *out_addr = buf + buffer_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = strformat(
"static HarisStatus _public_from_buffer(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" HarisStatus result;\n"
" HarisBufferStream buffer_stream;\n"
" buffer_stream.buffer = buf;\n"
" buffer_stream.sz = sz;\n"
" buffer_stream.curr = 0;\n"
" if ((result = _haris_from_stream(ptr, info, &buffer_stream, \n"
" read_from_buffer_stream, 0)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_addr) *out_addr = buf + buffer_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
result = add_private_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_static_buffer_funcs(CJob *job)
{
  do { if (add_private_function(job, strformat("static HarisStatus read_from_buffer_stream(void *_stream, \n                                           haris_uint32_t count,\n                                           const unsigned char **dest)\n{\n  HarisBufferStream *stream = (HarisBufferStream*)_stream;\n  HARIS_ASSERT(count + stream->curr <= stream->sz, INPUT);\n  HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  *dest = stream->buffer + stream->curr;\n  stream->curr += count;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus write_to_buffer_stream(void *_stream,\n                                          const unsigned char *src,\n                                          haris_uint32_t count)\n{\n  HarisBufferStream *stream = (HarisBufferStream*)_stream;\n  /* No error checking necessary; the size of the structure is verified\n     before serialization begins */\n  memcpy(stream->buffer + stream->curr, src, count);\n  stream->curr += count;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_to_buffer_a(void *ptr,\n                                        const HarisStructureInfo *info,\n                                        unsigned char **out_buf,\n                                        haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisBufferStream buffer_stream;\n  haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n  if (encoded_size == 0) return result;\n  HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  buffer_stream.buffer = (unsigned char *)malloc(encoded_size);\n  HARIS_ASSERT(buffer_stream.buffer, MEM);\n  buffer_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &buffer_stream, \n                                 write_to_buffer_stream)) != HARIS_SUCCESS)\n    return result;\n  *out_sz = encoded_size;\n  *out_buf = buffer_stream.buffer;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_to_buffer(void *ptr,\n                                      const HarisStructureInfo *info,\n                                      unsigned char *buf,\n                                      haris_uint32_t sz,\n                                      unsigned char **out_addr)\n{\n  HarisStatus result;\n  HarisBufferStream buffer_stream;\n  haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n  if (encoded_size == 0) return result;\n  HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  HARIS_ASSERT(encoded_size <= sz, INPUT);\n  buffer_stream.buffer = buf;\n  buffer_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &buffer_stream,\n                                 write_to_buffer_stream)) != HARIS_SUCCESS)\n    return result;\n  if (out_addr) *out_addr = buf + buffer_stream.curr;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_from_buffer(void *ptr,\n                                       const HarisStructureInfo *info,\n                                       unsigned char *buf,\n                                       haris_uint32_t sz,\n                                       unsigned char **out_addr)\n{\n  HarisStatus result;\n  HarisBufferStream buffer_stream;\n  buffer_stream.buffer = buf;\n  buffer_stream.sz = sz;\n  buffer_stream.curr = 0;\n  if ((result = _haris_from_stream(ptr, info, &buffer_stream, \n                                   read_from_buffer_stream, 0)) != HARIS_SUCCESS)\n    return result;\n  if (out_addr) *out_addr = buf + buffer_stream.curr;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_static_buffer_funcs(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static HarisStatus read_from_buffer_stream(void *_stream, \n                                           haris_uint32_t count,\n                                           const unsigned char **dest)\n{\n  HarisBufferStream *stream = (HarisBufferStream*)_stream;\n  HARIS_ASSERT(count + stream->curr <= stream->sz, INPUT);\n  HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  *dest = stream->buffer + stream->curr;\n  stream->curr += count;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus write_to_buffer_stream(void *_stream,\n                                          const unsigned char *src,\n                                          haris_uint32_t count)\n{\n  HarisBufferStream *stream = (HarisBufferStream*)_stream;\n  /* No error checking necessary; the size of the structure is verified\n     before serialization begins */\n  memcpy(stream->buffer + stream->curr, src, count);\n  stream->curr += count;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_to_buffer_a(void *ptr,\n                                        const HarisStructureInfo *info,\n                                        unsigned char **out_buf,\n                                        haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisBufferStream buffer_stream;\n  haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n  if (encoded_size == 0) return result;\n  HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  buffer_stream.buffer = (unsigned char *)malloc(encoded_size);\n  HARIS_ASSERT(buffer_stream.buffer, MEM);\n  buffer_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &buffer_stream, \n                                 write_to_buffer_stream)) != HARIS_SUCCESS)\n    return result;\n  *out_sz = encoded_size;\n  *out_buf = buffer_stream.buffer;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_to_buffer(void *ptr,\n                                      const HarisStructureInfo *info,\n                                      unsigned char *buf,\n                                      haris_uint32_t sz,\n                                      unsigned char **out_addr)\n{\n  HarisStatus result;\n  HarisBufferStream buffer_stream;\n  haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n  if (encoded_size == 0) return result;\n  HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  HARIS_ASSERT(encoded_size <= sz, INPUT);\n  buffer_stream.buffer = buf;\n  buffer_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &buffer_stream,\n                                 write_to_buffer_stream)) != HARIS_SUCCESS)\n    return result;\n  if (out_addr) *out_addr = buf + buffer_stream.curr;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_from_buffer(void *ptr,\n                                       const HarisStructureInfo *info,\n                                       unsigned char *buf,\n                                       haris_uint32_t sz,\n                                       unsigned char **out_addr)\n{\n  HarisStatus result;\n  HarisBufferStream buffer_stream;\n  buffer_stream.buffer = buf;\n  buffer_stream.sz = sz;\n  buffer_stream.curr = 0;\n  if ((result = _haris_from_stream(ptr, info, &buffer_stream, \n                                   read_from_buffer_stream, 0)) != HARIS_SUCCESS)\n    return result;\n  if (out_addr) *out_addr = buf + buffer_stream.curr;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


repo: theseoafs/haris

decompiled_code:
__int64 __fastcall write_public_buffer_funcs(__int64 a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // r13
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax

v2 = *(const char **)(a1 + 8);
v3 = *(const char **)a2;
v4 = strformat(
"HarisStatus %s%s_from_buffer(%s%s *strct, unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" return _public_from_buffer(strct, &haris_lib_structures[%d],\n"
" buf, sz, out_addr);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16));
if ( (unsigned int)add_public_function(a1, v4)
|| (v5 = strformat(
"HarisStatus %s%s_to_buffer_a(%s%s *strct, unsigned char **out_buf, \n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_to_buffer_a(strct, &haris_lib_structures[%d],\n"
" out_buf, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16)),
(unsigned int)add_public_function(a1, v5))
|| (v6 = strformat(
"HarisStatus %s%s_to_buffer(%s%s *strct, unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" return _public_to_buffer(strct, &haris_lib_structures[%d],\n"
" buf, sz, out_addr);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16)),
result = add_public_function(a1, v6),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // r13
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax

v2 = *(const char **)(a1 + 8);
v3 = *(const char **)a2;
v4 = strformat(
"HarisStatus %s%s_from_buffer(%s%s *strct, unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" return _public_from_buffer(strct, &haris_lib_structures[%d],\n"
" buf, sz, out_addr);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16));
if ( (unsigned int)add_public_function(a1, v4)
|| (v5 = strformat(
"HarisStatus %s%s_to_buffer_a(%s%s *strct, unsigned char **out_buf, \n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_to_buffer_a(strct, &haris_lib_structures[%d],\n"
" out_buf, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16)),
(unsigned int)add_public_function(a1, v5))
|| (v6 = strformat(
"HarisStatus %s%s_to_buffer(%s%s *strct, unsigned char *buf,\n"
" haris_uint32_t sz,\n"
" unsigned char **out_addr)\n"
"{\n"
" return _public_to_buffer(strct, &haris_lib_structures[%d],\n"
" buf, sz, out_addr);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16)),
result = add_public_function(a1, v6),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_public_buffer_funcs(CJob *job, ParsedStruct *strct)
{
  const char *prefix = job->prefix, *name = strct->name;
  do { if (add_public_function(job, strformat("HarisStatus %s%s_from_buffer(%s%s *strct, unsigned char *buf,\n                              haris_uint32_t sz,\n                              unsigned char **out_addr)\n{\n  return _public_from_buffer(strct, &haris_lib_structures[%d],\n                             buf, sz, out_addr);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_public_function(job, strformat("HarisStatus %s%s_to_buffer_a(%s%s *strct, unsigned char **out_buf, \n                              haris_uint32_t *out_sz)\n{\n  return _public_to_buffer_a(strct, &haris_lib_structures[%d],\n                             out_buf, out_sz);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_public_function(job, strformat("HarisStatus %s%s_to_buffer(%s%s *strct, unsigned char *buf,\n                            haris_uint32_t sz,\n                            unsigned char **out_addr)\n{\n  return _public_to_buffer(strct, &haris_lib_structures[%d],\n                           buf, sz, out_addr);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_public_buffer_funcs(struct CJob *job, struct _ParsedStruct *strct)
{
  char *prefix = job->prefix; char *name = strct->name;
  do { if (add_public_function(job, strformat("HarisStatus %s%s_from_buffer(%s%s *strct, unsigned char *buf,\n                              haris_uint32_t sz,\n                              unsigned char **out_addr)\n{\n  return _public_from_buffer(strct, &haris_lib_structures[%d],\n                             buf, sz, out_addr);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_public_function(job, strformat("HarisStatus %s%s_to_buffer_a(%s%s *strct, unsigned char **out_buf, \n                              haris_uint32_t *out_sz)\n{\n  return _public_to_buffer_a(strct, &haris_lib_structures[%d],\n                             out_buf, out_sz);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_public_function(job, strformat("HarisStatus %s%s_to_buffer(%s%s *strct, unsigned char *buf,\n                            haris_uint32_t sz,\n                            unsigned char **out_addr)\n{\n  return _public_to_buffer(strct, &haris_lib_structures[%d],\n                           buf, sz, out_addr);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

variable_types: struct CJob { struct ParsedSchema { int num_structs; int structs_alloc; struct _ParsedStruct { char *name; struct StructMetadata { unsigned long max_size; } meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField { char *name; int offset; struct ScalarType { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } tag; struct _ParsedEnum { char *name; int num_values; int values_alloc; char **values; } *enum_type; } type; } *scalars; int num_children; int children_alloc; struct ChildField { char *name; int nullable; struct ChildMetadata { int embeddable; } meta; enum ChildTag { CHILD_TEXT=0, CHILD_STRUCT=1, CHILD_SCALAR_LIST=2, CHILD_STRUCT_LIST=3 } tag; union ChildType { struct _ParsedStruct *strct; struct ScalarType scalar_list; struct _ParsedStruct *struct_list; } type; } *children; } *structs; int num_enums; int enums_alloc; struct _ParsedEnum *enums; } *schema; char *prefix; char *output; struct CJobProtocols { int buffer; int file; int fd; } protocols; struct CJobStrings { struct CJobStringStack { int num_strings; int strings_alloc; char **strings; } header_strings; struct CJobStringStack header_bottom_strings; struct CJobStringStack source_strings; struct CJobStringStack public_functions; struct CJobStringStack private_functions; } strings; } *

variable_types:
strct
struct _ParsedStruct *

variable_types:
prefix
char *

variable_types:
name
char *

return_type: enum CJobStatus { CJOB_SUCCESS=0, CJOB_SCHEMA_ERROR=1, CJOB_JOB_ERROR=2, CJOB_IO_ERROR=3, CJOB_MEM_ERROR=4, CJOB_PARSE_ERROR=5 }

user_defined_types: struct CJob { struct ParsedSchema *schema; char *prefix; char *output; struct CJobProtocols protocols; struct CJobStrings strings; }

user_defined_types: struct CJobStrings { struct CJobStringStack header_strings; struct CJobStringStack header_bottom_strings; struct CJobStringStack source_strings; struct CJobStringStack public_functions; struct CJobStringStack private_functions; }

user_defined_types: struct ParsedSchema { int num_structs; int structs_alloc; struct _ParsedStruct *structs; int num_enums; int enums_alloc; struct _ParsedEnum *enums; }

user_defined_types: struct _ParsedStruct { char *name; struct StructMetadata meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField *scalars; int num_children; int children_alloc; struct ChildField *children; }

user_defined_types: struct ScalarField { char *name; int offset; struct ScalarType type; }

user_defined_types: struct ChildField { char *name; int nullable; struct ChildMetadata meta; enum ChildTag tag; union ChildType type; }

user_defined_types: struct ScalarType { enum ScalarTag tag; struct _ParsedEnum *enum_type; }


decompiled_code:
__int64 __fastcall write_buffer_protocol_funcs(__int64 *a1)
{
__int64 v1; // r13
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // rbx
int v5; // ebp

v1 = *a1;
v2 = write_buffer_structures((__int64)a1);
if ( v2 )
return v2;
v2 = write_static_buffer_funcs((__int64)a1);
if ( v2 )
return v2;
v4 = 0LL;
v5 = 0;
if ( *(int *)v1 <= 0 )
return v2;
while ( 1 )
{
LODWORD(result) = write_public_buffer_funcs((__int64)a1, v4 + *(_QWORD *)(v1 + 8));
if ( (_DWORD)result )
break;
++v5;
v4 += 56LL;
if ( *(_DWORD *)v1 <= v5 )
return v2;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // r13
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // rbx
int v5; // ebp

v1 = *a1;
v2 = func0((__int64)a1);
if ( v2 )
return v2;
v2 = func1((__int64)a1);
if ( v2 )
return v2;
v4 = 0LL;
v5 = 0;
if ( *(int *)v1 <= 0 )
return v2;
while ( 1 )
{
LODWORD(result) = func2((__int64)a1, v4 + *(_QWORD *)(v1 + 8));
if ( (_DWORD)result )
break;
++v5;
v4 += 56LL;
if ( *(_DWORD *)v1 <= v5 )
return v2;
}
return (unsigned int)result;
}

original_code:
CJobStatus write_buffer_protocol_funcs(CJob *job)
{
  CJobStatus result;
  int i;
  ParsedSchema *schema = job->schema;
  if ((result = write_buffer_structures(job)) != CJOB_SUCCESS ||
      (result = write_static_buffer_funcs(job)) != CJOB_SUCCESS)
    return result;
  for (i = 0; i < schema->num_structs; i++) {
    if ((result = write_public_buffer_funcs(job, &schema->structs[i]))
        != CJOB_SUCCESS)
      return result;
  }
  return CJOB_SUCCESS;
}

canonical_original_code:
enum CJobStatus write_buffer_protocol_funcs(struct CJob *job)
{
  enum CJobStatus result;
  int i;
  struct ParsedSchema *schema = job->schema;
  if ((result = write_buffer_structures(job)) != CJOB_SUCCESS ||
      (result = write_static_buffer_funcs(job)) != CJOB_SUCCESS)
    return result;
  for (i = 0; i < schema->num_structs; i++) {
    if ((result = write_public_buffer_funcs(job, &schema->structs[i]))
        != CJOB_SUCCESS)
      return result;
  }
  return CJOB_SUCCESS;
}

variable_types: enum CJobStatus { CJOB_SUCCESS=0, CJOB_SCHEMA_ERROR=1, CJOB_JOB_ERROR=2, CJOB_IO_ERROR=3, CJOB_MEM_ERROR=4, CJOB_PARSE_ERROR=5 }

variable_types: i int

variable_types: struct ParsedSchema { int num_structs; int structs_alloc; struct _ParsedStruct { char *name; struct StructMetadata { unsigned long max_size; } meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField { char *name; int offset; struct ScalarType { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } tag; struct _ParsedEnum { char *name; int num_values; int values_alloc; char **values; } *enum_type; } type; } *scalars; int num_children; int children_alloc; struct ChildField { char *name; int nullable; struct ChildMetadata { int embeddable; } meta; enum ChildTag { CHILD_TEXT=0, CHILD_STRUCT=1, CHILD_SCALAR_LIST=2, CHILD_STRUCT_LIST=3 } tag; union ChildType { struct _ParsedStruct *strct; struct ScalarType scalar_list; struct _ParsedStruct *struct_list; } type; } *children; } *structs; int num_enums; int enums_alloc; struct _ParsedEnum *enums; } *

user_defined_types: struct CJobProtocols { int buffer; int file; int fd; }

user_defined_types: struct CJobStringStack { int num_strings; int strings_alloc; char **strings; }


decompiled_code:
unsigned __int64 __fastcall hash_string(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
_BYTE *v2; // rsi
unsigned __int64 v3; // rcx

v1 = *a1;
v2 = a1 + 1;
if ( !*a1 )
return 6LL;
v3 = 5381LL;
do
{
++v2;
v3 += 32 * v3 + v1;
v1 = *(v2 - 1);
}
while ( v1 );
return v3 % 0x2B;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
_BYTE *v2; // rsi
unsigned __int64 v3; // rcx

v1 = *a1;
v2 = a1 + 1;
if ( !*a1 )
return 6LL;
v3 = 5381LL;
do
{
++v2;
v3 += 32 * v3 + v1;
v1 = *(v2 - 1);
}
while ( v1 );
return v3 % 0x2B;
}

original_code:
static int hash_string(char *str)
{
  unsigned long hash = 5381;
  int c;
  while ((c = (unsigned char)(*str++)))
    hash = ((hash << 5UL) + hash) + (unsigned long)c;
  return (int)(hash % 43);
}

variable_types:
str
char *

variable_types:
hash
unsigned long

variable_types: c int

return_type: int


decompiled_code:
__int64 __fastcall add_bucket_at_index(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8LL * a3);
*(_QWORD *)(a2 + 24) = result;
*(_QWORD *)(a1 + 8LL * a3) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8LL * a3);
*(_QWORD *)(a2 + 24) = result;
*(_QWORD *)(a1 + 8LL * a3) = a2;
return result;
}

original_code:
static void add_bucket_at_index(TypeHash *hash, TypeHashBucket *bucket, int i)
{
  bucket->next = hash->buckets[i];
  hash->buckets[i] = bucket;
  return;
}

canonical_original_code:
static void add_bucket_at_index(struct TypeHash *hash, struct TypeHashBucket *bucket, int i)
{
  bucket->next = hash->buckets[i];
  hash->buckets[i] = bucket;
  return;
}

variable_types: struct TypeHash { struct TypeHashBucket { char *name; struct TaggedTypeUnion { enum TypeTag { TYPE_SCALAR_BUILTIN=0, TYPE_ENUM=1, TYPE_STRUCT=2, TYPE_TEXT=3 } tag; union TypeUnion { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } scalar_builtin; struct _ParsedEnum { char *name; int num_values; int values_alloc; char **values; } *enm; struct _ParsedStruct { char *name; struct StructMetadata { unsigned long max_size; } meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField { char *name; int offset; struct ScalarType { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } tag; struct _ParsedEnum *enum_type; } type; } *scalars; int num_children; int children_alloc; struct ChildField { char *name; int nullable; struct ChildMetadata { int embeddable; } meta; enum ChildTag { CHILD_TEXT=0, CHILD_STRUCT=1, CHILD_SCALAR_LIST=2, CHILD_STRUCT_LIST=3 } tag; union ChildType { struct _ParsedStruct *strct; struct ScalarType scalar_list; struct _ParsedStruct *struct_list; } type; } *children; } *strct; } type; } tu; struct TypeHashBucket *next; } *buckets[43]; } *

variable_types:
bucket
struct TypeHashBucket *

return_type: void

user_defined_types: struct TypeHash { struct TypeHashBucket *buckets[43]; }

user_defined_types: struct TypeHashBucket { char *name; struct TaggedTypeUnion tu; struct TypeHashBucket *next; }

user_defined_types: struct TaggedTypeUnion { enum TypeTag tag; union TypeUnion type; }

user_defined_types: union TypeUnion { enum ScalarTag scalar_builtin; struct _ParsedEnum *enm; struct _ParsedStruct *strct; }


decompiled_code:
__int64 __fastcall add_scalar_to_hash(__int64 a1, unsigned __int8 *a2, int a3)
{
int v4; // er12
_QWORD *v5; // rsi
__int64 result; // rax

v4 = hash_string(a2);
v5 = new_bucket((__int64)a2);
result = 0LL;
if ( v5 )
{
*((_DWORD *)v5 + 2) = 0;
*((_DWORD *)v5 + 4) = a3;
add_bucket_at_index(a1, (__int64)v5, v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 *a2, int a3)
{
int v4; // er12
_QWORD *v5; // rsi
__int64 result; // rax

v4 = func0(a2);
v5 = new_bucket((__int64)a2);
result = 0LL;
if ( v5 )
{
*((_DWORD *)v5 + 2) = 0;
*((_DWORD *)v5 + 4) = a3;
func1(a1, (__int64)v5, v4);
result = 1LL;
}
return result;
}

original_code:
static int add_scalar_to_hash(TypeHash *hash, char *name, ScalarTag tag)
{
  int i = hash_string(name);
  TypeHashBucket *bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_SCALAR_BUILTIN;
  bucket->tu.type.scalar_builtin = tag;
  add_bucket_at_index(hash, bucket, i);
  return 1;
}

canonical_original_code:
static int add_scalar_to_hash(struct TypeHash *hash, char *name, enum ScalarTag tag)
{
  int i = hash_string(name);
  struct TypeHashBucket *bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_SCALAR_BUILTIN;
  bucket->tu.type.scalar_builtin = tag;
  add_bucket_at_index(hash, bucket, i);
  return 1;
}

variable_types: struct TypeHashBucket { char *name; struct TaggedTypeUnion { enum TypeTag { TYPE_SCALAR_BUILTIN=0, TYPE_ENUM=1, TYPE_STRUCT=2, TYPE_TEXT=3 } tag; union TypeUnion { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } scalar_builtin; struct _ParsedEnum { char *name; int num_values; int values_alloc; char **values; } *enm; struct _ParsedStruct { char *name; struct StructMetadata { unsigned long max_size; } meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField { char *name; int offset; struct ScalarType { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } tag; struct _ParsedEnum *enum_type; } type; } *scalars; int num_children; int children_alloc; struct ChildField { char *name; int nullable; struct ChildMetadata { int embeddable; } meta; enum ChildTag { CHILD_TEXT=0, CHILD_STRUCT=1, CHILD_SCALAR_LIST=2, CHILD_STRUCT_LIST=3 } tag; union ChildType { struct _ParsedStruct *strct; struct ScalarType scalar_list; struct _ParsedStruct *struct_list; } type; } *children; } *strct; } type; } tu; struct TypeHashBucket *next; } *


decompiled_code:
__int64 __fastcall add_text_to_hash(__int64 a1)
{
_QWORD *v1; // r8
__int64 result; // rax
int v3; // eax
__int64 v4; // r8

v1 = new_bucket((__int64)"Text");
result = 0LL;
if ( v1 )
{
*((_DWORD *)v1 + 2) = 3;
v3 = hash_string("Text");
add_bucket_at_index(a1, v4, v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
_QWORD *v1; // r8
__int64 result; // rax
int v3; // eax
__int64 v4; // r8

v1 = new_bucket((__int64)"Text");
result = 0LL;
if ( v1 )
{
*((_DWORD *)v1 + 2) = 3;
v3 = func0("Text");
func1(a1, v4, v3);
result = 1LL;
}
return result;
}

original_code:
static int add_text_to_hash(TypeHash *hash)
{
  char *name = "Text";
  TypeHashBucket *bucket;
  bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_TEXT;
  add_bucket_at_index(hash, bucket, hash_string(name));
  return 1;
}

canonical_original_code:
static int add_text_to_hash(struct TypeHash *hash)
{
  char *name = "Text";
  struct TypeHashBucket *bucket;
  bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_TEXT;
  add_bucket_at_index(hash, bucket, hash_string(name));
  return 1;
}

user_defined_types: enum TypeTag { TYPE_SCALAR_BUILTIN=0, TYPE_ENUM=1, TYPE_STRUCT=2, TYPE_TEXT=3 }

user_defined_types: enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 }

user_defined_types: struct _ParsedEnum { char *name; int num_values; int values_alloc; char **values; }

user_defined_types: struct StructMetadata { unsigned long max_size; }

user_defined_types: struct ChildMetadata { int embeddable; }

user_defined_types: enum ChildTag { CHILD_TEXT=0, CHILD_STRUCT=1, CHILD_SCALAR_LIST=2, CHILD_STRUCT_LIST=3 }

user_defined_types: union ChildType { struct _ParsedStruct *strct; struct ScalarType scalar_list; struct _ParsedStruct *struct_list; }


decompiled_code:
_BOOL8 __fastcall add_builtins_to_hash(__int64 a1)
{
_BOOL8 result; // rax

if ( (unsigned int)add_scalar_to_hash(a1, "Uint8", 0)
&& (unsigned int)add_scalar_to_hash(a1, "Int8", 1)
&& (unsigned int)add_scalar_to_hash(a1, "Uint16", 2)
&& (unsigned int)add_scalar_to_hash(a1, "Int16", 3)
&& (unsigned int)add_scalar_to_hash(a1, "Uint32", 4)
&& (unsigned int)add_scalar_to_hash(a1, "Int32", 5)
&& (unsigned int)add_scalar_to_hash(a1, "Uint64", 6)
&& (unsigned int)add_scalar_to_hash(a1, "Int64", 7)
&& (unsigned int)add_scalar_to_hash(a1, "Bool", 10)
&& (unsigned int)add_scalar_to_hash(a1, "Float32", 8)
&& (unsigned int)add_scalar_to_hash(a1, "Float64", 9) )
{
result = (unsigned int)add_text_to_hash(a1) != 0;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
_BOOL8 result; // rax

if ( (unsigned int)func2(a1, "Uint8", 0)
&& (unsigned int)func2(a1, "Int8", 1)
&& (unsigned int)func2(a1, "Uint16", 2)
&& (unsigned int)func2(a1, "Int16", 3)
&& (unsigned int)func2(a1, "Uint32", 4)
&& (unsigned int)func2(a1, "Int32", 5)
&& (unsigned int)func2(a1, "Uint64", 6)
&& (unsigned int)func2(a1, "Int64", 7)
&& (unsigned int)func2(a1, "Bool", 10)
&& (unsigned int)func2(a1, "Float32", 8)
&& (unsigned int)func2(a1, "Float64", 9) )
{
result = (unsigned int)func3(a1) != 0;
}
else
{
result = 0LL;
}
return result;
}

original_code:
static int add_builtins_to_hash(TypeHash *hash)
{
  return add_scalar_to_hash(hash, "Uint8", SCALAR_UINT8) &&
    add_scalar_to_hash(hash, "Int8", SCALAR_INT8) &&
    add_scalar_to_hash(hash, "Uint16", SCALAR_UINT16) &&
    add_scalar_to_hash(hash, "Int16", SCALAR_INT16) &&
    add_scalar_to_hash(hash, "Uint32", SCALAR_UINT32) &&
    add_scalar_to_hash(hash, "Int32", SCALAR_INT32) &&
    add_scalar_to_hash(hash, "Uint64", SCALAR_UINT64) &&
    add_scalar_to_hash(hash, "Int64", SCALAR_INT64) &&
    add_scalar_to_hash(hash, "Bool", SCALAR_BOOL) &&
    add_scalar_to_hash(hash, "Float32", SCALAR_FLOAT32) &&
    add_scalar_to_hash(hash, "Float64", SCALAR_FLOAT64) &&
    add_text_to_hash(hash);
}

canonical_original_code:
static int add_builtins_to_hash(struct TypeHash *hash)
{
  return add_scalar_to_hash(hash, "Uint8", SCALAR_UINT8) &&
    add_scalar_to_hash(hash, "Int8", SCALAR_INT8) &&
    add_scalar_to_hash(hash, "Uint16", SCALAR_UINT16) &&
    add_scalar_to_hash(hash, "Int16", SCALAR_INT16) &&
    add_scalar_to_hash(hash, "Uint32", SCALAR_UINT32) &&
    add_scalar_to_hash(hash, "Int32", SCALAR_INT32) &&
    add_scalar_to_hash(hash, "Uint64", SCALAR_UINT64) &&
    add_scalar_to_hash(hash, "Int64", SCALAR_INT64) &&
    add_scalar_to_hash(hash, "Bool", SCALAR_BOOL) &&
    add_scalar_to_hash(hash, "Float32", SCALAR_FLOAT32) &&
    add_scalar_to_hash(hash, "Float64", SCALAR_FLOAT64) &&
    add_text_to_hash(hash);
}

user_defined_types: struct _ParsedStruct { char *name; struct StructMetadata meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField *scalars; int num_children; int children_alloc; struct ChildField *children; }


decompiled_code:
void __fastcall destroy_typehash(void *ptr)
{
__int64 *v1; // r12
__int64 v2; // rbx
void **v3; // rbp

v1 = (__int64 *)ptr;
do
{
v2 = *v1;
while ( v2 )
{
v3 = (void **)v2;
v2 = *(_QWORD *)(v2 + 24);
free(*v3);
free(v3);
}
++v1;
}
while ( v1 != (__int64 *)((char *)ptr + 344) );
free(ptr);
}

original_code:
void destroy_typehash(TypeHash *hash)
{
  int i;
  TypeHashBucket *bucket, *tmp;
  for (i = 0; i<43; i++) {
    bucket = hash->buckets[i];
    while (bucket) {
      tmp = bucket->next;
      free(bucket->name);
      free(bucket);
      bucket = tmp;
    }
  }
  free(hash);
  return;
}

canonical_original_code:
void destroy_typehash(struct TypeHash *hash)
{
  int i;
  struct TypeHashBucket *bucket; struct TypeHashBucket *tmp;
  for (i = 0; i<43; i++) {
    bucket = hash->buckets[i];
    while (bucket) {
      tmp = bucket->next;
      free(bucket->name);
      free(bucket);
      bucket = tmp;
    }
  }
  free(hash);
  return;
}

user_defined_types: struct ScalarField { char *name; int offset; struct ScalarType type; }


decompiled_code:
void *create_typehash()
{
void *v0; // rax
void *v1; // r12

v0 = calloc(0x158uLL, 1uLL);
v1 = v0;
if ( !v0 || add_builtins_to_hash((__int64)v0) )
return v1;
destroy_typehash(v1);
return 0LL;
}

canonical_decompiled_code:
void *func6()
{
void *v0; // rax
void *v1; // r12

v0 = calloc(0x158uLL, 1uLL);
v1 = v0;
if ( !v0 || func4((__int64)v0) )
return v1;
func5(v1);
return 0LL;
}

original_code:
TypeHash *create_typehash(void)
{
  int i;
  TypeHash *ret = (TypeHash*)malloc(sizeof *ret);
  if (!ret) return ((void *)0);
  for (i = 0; i<43; i++)
    ret->buckets[i] = ((void *)0);
  if (add_builtins_to_hash(ret))
    return ret;
  else {
    destroy_typehash(ret);
    return ((void *)0);
  }
}

canonical_original_code:
struct TypeHash *create_typehash()
{
  int i;
  struct TypeHash *ret = (TypeHash*)malloc(sizeof *ret);
  if (!ret) return ((void *)0);
  for (i = 0; i<43; i++)
    ret->buckets[i] = ((void *)0);
  if (add_builtins_to_hash(ret))
    return ret;
  else {
    destroy_typehash(ret);
    return ((void *)0);
  }
}

return_type: struct TypeHash { struct TypeHashBucket { char *name; struct TaggedTypeUnion { enum TypeTag { TYPE_SCALAR_BUILTIN=0, TYPE_ENUM=1, TYPE_STRUCT=2, TYPE_TEXT=3 } tag; union TypeUnion { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } scalar_builtin; struct _ParsedEnum { char *name; int num_values; int values_alloc; char **values; } *enm; struct _ParsedStruct { char *name; struct StructMetadata { unsigned long max_size; } meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField { char *name; int offset; struct ScalarType { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } tag; struct _ParsedEnum *enum_type; } type; } *scalars; int num_children; int children_alloc; struct ChildField { char *name; int nullable; struct ChildMetadata { int embeddable; } meta; enum ChildTag { CHILD_TEXT=0, CHILD_STRUCT=1, CHILD_SCALAR_LIST=2, CHILD_STRUCT_LIST=3 } tag; union ChildType { struct _ParsedStruct *strct; struct ScalarType scalar_list; struct _ParsedStruct *struct_list; } type; } *children; } *strct; } type; } tu; struct TypeHashBucket *next; } *buckets[43]; } *

user_defined_types: struct ChildField { char *name; int nullable; struct ChildMetadata meta; enum ChildTag tag; union ChildType type; }


decompiled_code:
__int64 __fastcall add_struct_to_hash(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
int v4; // er12
_QWORD *v5; // rsi
__int64 result; // rax

v4 = hash_string(a2);
v5 = new_bucket((__int64)a2);
result = 0LL;
if ( v5 )
{
*((_DWORD *)v5 + 2) = 2;
v5[2] = a3;
add_bucket_at_index(a1, (__int64)v5, v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
int v4; // er12
_QWORD *v5; // rsi
__int64 result; // rax

v4 = func0(a2);
v5 = new_bucket((__int64)a2);
result = 0LL;
if ( v5 )
{
*((_DWORD *)v5 + 2) = 2;
v5[2] = a3;
func1(a1, (__int64)v5, v4);
result = 1LL;
}
return result;
}

original_code:
int add_struct_to_hash(TypeHash *hash, char *name, ParsedStruct *strct)
{
  int i = hash_string(name);
  TypeHashBucket *bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_STRUCT;
  bucket->tu.type.strct = strct;
  add_bucket_at_index(hash, bucket, i);
  return 1;
}

canonical_original_code:
int add_struct_to_hash(struct TypeHash *hash, char *name, struct _ParsedStruct *strct)
{
  int i = hash_string(name);
  struct TypeHashBucket *bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_STRUCT;
  bucket->tu.type.strct = strct;
  add_bucket_at_index(hash, bucket, i);
  return 1;
}

user_defined_types: struct ScalarType { enum ScalarTag tag; struct _ParsedEnum *enum_type; }


decompiled_code:
__int64 __fastcall add_enum_to_hash(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
int v4; // er12
_QWORD *v5; // rsi
__int64 result; // rax

v4 = hash_string(a2);
v5 = new_bucket((__int64)a2);
result = 0LL;
if ( v5 )
{
*((_DWORD *)v5 + 2) = 1;
v5[2] = a3;
add_bucket_at_index(a1, (__int64)v5, v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
int v4; // er12
_QWORD *v5; // rsi
__int64 result; // rax

v4 = func0(a2);
v5 = new_bucket((__int64)a2);
result = 0LL;
if ( v5 )
{
*((_DWORD *)v5 + 2) = 1;
v5[2] = a3;
func1(a1, (__int64)v5, v4);
result = 1LL;
}
return result;
}

original_code:
int add_enum_to_hash(TypeHash *hash, char *name, ParsedEnum *enm)
{
  int i = hash_string(name);
  TypeHashBucket *bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_ENUM;
  bucket->tu.type.enm = enm;
  add_bucket_at_index(hash, bucket, i);
  return 1;
}

canonical_original_code:
int add_enum_to_hash(struct TypeHash *hash, char *name, struct _ParsedEnum *enm)
{
  int i = hash_string(name);
  struct TypeHashBucket *bucket = new_bucket(name);
  if (!bucket) return 0;
  bucket->tu.tag = TYPE_ENUM;
  bucket->tu.type.enm = enm;
  add_bucket_at_index(hash, bucket, i);
  return 1;
}

variable_types:
enm
struct _ParsedEnum *


decompiled_code:
__int64 __fastcall get_type(__int64 a1, unsigned __int8 *a2)
{
int v2; // eax
__int64 v3; // r8
__int64 i; // r12

v2 = hash_string(a2);
for ( i = *(_QWORD *)(v3 + 8LL * v2); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp((const char *)a2, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int8 *a2)
{
int v2; // eax
__int64 v3; // r8
__int64 i; // r12

v2 = func0(a2);
for ( i = *(_QWORD *)(v3 + 8LL * v2); i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp((const char *)a2, *(const char **)i) )
break;
}
return i;
}

original_code:
TypeHashBucket *get_type(TypeHash *hash, char *name)
{
  int i = hash_string(name);
  TypeHashBucket *bucket;
  for (bucket = hash->buckets[i]; bucket; bucket = bucket->next)
    if (!strcmp(name, bucket->name))
      return bucket;
  return ((void *)0);
}

canonical_original_code:
struct TypeHashBucket *get_type(struct TypeHash *hash, char *name)
{
  int i = hash_string(name);
  struct TypeHashBucket *bucket;
  for (bucket = hash->buckets[i]; bucket; bucket = bucket->next)
    if (!strcmp(name, bucket->name))
      return bucket;
  return ((void *)0);
}

variable_types: struct TypeHash { struct TypeHashBucket *buckets[43]; } *

return_type: struct TypeHashBucket { char *name; struct TaggedTypeUnion { enum TypeTag { TYPE_SCALAR_BUILTIN=0, TYPE_ENUM=1, TYPE_STRUCT=2, TYPE_TEXT=3 } tag; union TypeUnion { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } scalar_builtin; struct _ParsedEnum { char *name; int num_values; int values_alloc; char **values; } *enm; struct _ParsedStruct { char *name; struct StructMetadata { unsigned long max_size; } meta; int schema_index; int offset; int num_scalars; int scalars_alloc; struct ScalarField { char *name; int offset; struct ScalarType { enum ScalarTag { SCALAR_UINT8=0, SCALAR_INT8=1, SCALAR_UINT16=2, SCALAR_INT16=3, SCALAR_UINT32=4, SCALAR_INT32=5, SCALAR_UINT64=6, SCALAR_INT64=7, SCALAR_FLOAT32=8, SCALAR_FLOAT64=9, SCALAR_BOOL=10, SCALAR_ENUM=11 } tag; struct _ParsedEnum *enum_type; } type; } *scalars; int num_children; int children_alloc; struct ChildField { char *name; int nullable; struct ChildMetadata { int embeddable; } meta; enum ChildTag { CHILD_TEXT=0, CHILD_STRUCT=1, CHILD_SCALAR_LIST=2, CHILD_STRUCT_LIST=3 } tag; union ChildType { struct _ParsedStruct *strct; struct ScalarType scalar_list; struct _ParsedStruct *struct_list; } type; } *children; } *strct; } type; } tu; struct TypeHashBucket *next; } *


decompiled_code:
__int64 __fastcall write_source_protocol_funcs(_DWORD *a1)
{
__int64 result; // rax

if ( a1[6] )
{
result = write_buffer_protocol_funcs();
if ( (_DWORD)result )
return result;
if ( !a1[7] )
{
LABEL_3:
if ( !a1[8] )
return 0LL;
return write_fd_protocol_funcs(a1);
}
}
else if ( !a1[7] )
{
goto LABEL_3;
}
result = write_file_protocol_funcs(a1);
if ( !(_DWORD)result )
{
if ( !a1[8] )
return 0LL;
return write_fd_protocol_funcs(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 result; // rax

if ( a1[6] )
{
result = write_buffer_protocol_funcs();
if ( (_DWORD)result )
return result;
if ( !a1[7] )
{
LABEL_3:
if ( !a1[8] )
return 0LL;
return write_fd_protocol_funcs(a1);
}
}
else if ( !a1[7] )
{
goto LABEL_3;
}
result = write_file_protocol_funcs(a1);
if ( !(_DWORD)result )
{
if ( !a1[8] )
return 0LL;
return write_fd_protocol_funcs(a1);
}
return result;
}

original_code:
static CJobStatus write_source_protocol_funcs(CJob *job)
{
  CJobStatus result;
  if (job->protocols.buffer)
    if ((result = write_buffer_protocol_funcs(job)) != CJOB_SUCCESS)
      return result;
  if (job->protocols.file)
    if ((result = write_file_protocol_funcs(job)) != CJOB_SUCCESS)
      return result;
  if (job->protocols.fd)
    if ((result = write_fd_protocol_funcs(job)) != CJOB_SUCCESS)
      return result;
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_source_protocol_funcs(struct CJob *job)
{
  enum CJobStatus result;
  if (job->protocols.buffer)
    if ((result = write_buffer_protocol_funcs(job)) != CJOB_SUCCESS)
      return result;
  if (job->protocols.file)
    if ((result = write_file_protocol_funcs(job)) != CJOB_SUCCESS)
      return result;
  if (job->protocols.fd)
    if ((result = write_fd_protocol_funcs(job)) != CJOB_SUCCESS)
      return result;
  return CJOB_SUCCESS;
}

user_defined_types: enum CJobStatus { CJOB_SUCCESS=0, CJOB_SCHEMA_ERROR=1, CJOB_JOB_ERROR=2, CJOB_IO_ERROR=3, CJOB_MEM_ERROR=4, CJOB_PARSE_ERROR=5 }

user_defined_types: struct CJob { struct ParsedSchema *schema; char *prefix; char *output; struct CJobProtocols protocols; struct CJobStrings strings; }

user_defined_types: struct CJobProtocols { int buffer; int file; int fd; }

user_defined_types: struct CJobStrings { struct CJobStringStack header_strings; struct CJobStringStack header_bottom_strings; struct CJobStringStack source_strings; struct CJobStringStack public_functions; struct CJobStringStack private_functions; }

user_defined_types: struct ParsedSchema { int num_structs; int structs_alloc; struct _ParsedStruct *structs; int num_enums; int enums_alloc; struct _ParsedEnum *enums; }


decompiled_code:
__int64 __fastcall write_source_file(_DWORD *a1)
{
__int64 result; // rax

result = write_source_public_funcs();
if ( !(_DWORD)result )
{
result = write_source_core_funcs(a1);
if ( !(_DWORD)result )
result = write_source_protocol_funcs(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
__int64 result; // rax

result = write_source_public_funcs();
if ( !(_DWORD)result )
{
result = write_source_core_funcs(a1);
if ( !(_DWORD)result )
result = func0(a1);
}
return result;
}

original_code:
CJobStatus write_source_file(CJob *job)
{
  CJobStatus result;
  if ((result = write_source_public_funcs(job)) != CJOB_SUCCESS ||
      (result = write_source_core_funcs(job)) != CJOB_SUCCESS ||
      (result = write_source_protocol_funcs(job)) != CJOB_SUCCESS)
    return result;
  return CJOB_SUCCESS;
}

canonical_original_code:
enum CJobStatus write_source_file(struct CJob *job)
{
  enum CJobStatus result;
  if ((result = write_source_public_funcs(job)) != CJOB_SUCCESS ||
      (result = write_source_core_funcs(job)) != CJOB_SUCCESS ||
      (result = write_source_protocol_funcs(job)) != CJOB_SUCCESS)
    return result;
  return CJOB_SUCCESS;
}

user_defined_types: struct CJobStringStack { int num_strings; int strings_alloc; char **strings; }


decompiled_code:
__int64 __fastcall write_file_structures(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = strformat("#include <stdio.h>\n\n");
if ( (unsigned int)add_header_string(a1, v1)
|| (v2 = strformat(
"typedef struct {\n"
" FILE *file;\n"
" haris_uint32_t curr;\n"
" unsigned char buffer[1000];\n"
"} HarisFileStream;\n"
"\n"),
result = add_header_string(a1, v2),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = strformat("#include <stdio.h>\n\n");
if ( (unsigned int)add_header_string(a1, v1)
|| (v2 = strformat(
"typedef struct {\n"
" FILE *file;\n"
" haris_uint32_t curr;\n"
" unsigned char buffer[1000];\n"
"} HarisFileStream;\n"
"\n"),
result = add_header_string(a1, v2),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_file_structures(CJob *job)
{
  do { if (add_header_string(job, strformat("#include <stdio.h>\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_header_string(job, strformat("typedef struct {\n  FILE *file;\n  haris_uint32_t curr;\n  unsigned char buffer[1000];\n} HarisFileStream;\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_file_structures(struct CJob *job)
{
  do { if (add_header_string(job, strformat("#include <stdio.h>\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_header_string(job, strformat("typedef struct {\n  FILE *file;\n  haris_uint32_t curr;\n  unsigned char buffer[1000];\n} HarisFileStream;\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


decompiled_code:
__int64 __fastcall write_static_file_funcs(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v1 = strformat(
"static HarisStatus read_from_file_stream(void *_stream,\n"
" haris_uint32_t count,\n"
" const unsigned char **dest)\n"
"{\n"
" HarisFileStream *stream = (HarisFileStream*)_stream;\n"
" HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" HARIS_ASSERT(fread(stream->buffer, 1, count, stream->file) == count,\n"
" INPUT);\n"
" *dest = stream->buffer;\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static HarisStatus write_to_file_stream(void *_stream,\n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" HarisFileStream *stream = (HarisFileStream*)_stream;\n"
" haris_uint32_t copy_size;\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" if (count + stream->curr > 1000) {\n"
" copy_size = 1000 - stream->curr;\n"
" memcpy(stream->buffer + stream->curr, src, copy_size);\n"
" HARIS_ASSERT(fwrite(stream->buffer, 1, 1000, stream->file) == count, \n"
" INPUT);\n"
" memcpy(stream->buffer, src + copy_size, count - copy_size);\n"
" stream->curr = count - copy_size;\n"
" } else {\n"
" memcpy(stream->buffer + stream->curr, src, count);\n"
" stream->curr += count;\n"
" }\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static HarisStatus _public_to_file(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" FILE *f,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFileStream file_stream;\n"
" haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n"
" if (encoded_size == 0) return result;\n"
" HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" file_stream.file = f;\n"
" file_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &file_stream,\n"
" write_to_file_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" HARIS_ASSERT(fwrite(file_stream.buffer, 1, file_stream.curr, \n"
" file_stream.file) == file_stream.curr, INPUT);\n"
" if (out_sz) *out_sz = encoded_size;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static HarisStatus _public_from_file(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" FILE *f,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFileStream file_stream;\n"
" file_stream.file = f;\n"
" file_stream.curr = 0;\n"
" if ((result = _haris_from_stream(ptr, info, &file_stream,\n"
" read_from_file_stream, 0)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_sz) *out_sz = file_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
result = add_private_function(a1, v4),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v1 = strformat(
"static HarisStatus read_from_file_stream(void *_stream,\n"
" haris_uint32_t count,\n"
" const unsigned char **dest)\n"
"{\n"
" HarisFileStream *stream = (HarisFileStream*)_stream;\n"
" HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" HARIS_ASSERT(fread(stream->buffer, 1, count, stream->file) == count,\n"
" INPUT);\n"
" *dest = stream->buffer;\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static HarisStatus write_to_file_stream(void *_stream,\n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" HarisFileStream *stream = (HarisFileStream*)_stream;\n"
" haris_uint32_t copy_size;\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" if (count + stream->curr > 1000) {\n"
" copy_size = 1000 - stream->curr;\n"
" memcpy(stream->buffer + stream->curr, src, copy_size);\n"
" HARIS_ASSERT(fwrite(stream->buffer, 1, 1000, stream->file) == count, \n"
" INPUT);\n"
" memcpy(stream->buffer, src + copy_size, count - copy_size);\n"
" stream->curr = count - copy_size;\n"
" } else {\n"
" memcpy(stream->buffer + stream->curr, src, count);\n"
" stream->curr += count;\n"
" }\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static HarisStatus _public_to_file(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" FILE *f,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFileStream file_stream;\n"
" haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n"
" if (encoded_size == 0) return result;\n"
" HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" file_stream.file = f;\n"
" file_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &file_stream,\n"
" write_to_file_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" HARIS_ASSERT(fwrite(file_stream.buffer, 1, file_stream.curr, \n"
" file_stream.file) == file_stream.curr, INPUT);\n"
" if (out_sz) *out_sz = encoded_size;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static HarisStatus _public_from_file(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" FILE *f,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFileStream file_stream;\n"
" file_stream.file = f;\n"
" file_stream.curr = 0;\n"
" if ((result = _haris_from_stream(ptr, info, &file_stream,\n"
" read_from_file_stream, 0)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_sz) *out_sz = file_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n"),
result = add_private_function(a1, v4),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_static_file_funcs(CJob *job)
{
  do { if (add_private_function(job, strformat("static HarisStatus read_from_file_stream(void *_stream,\n                                         haris_uint32_t count,\n                                         const unsigned char **dest)\n{\n  HarisFileStream *stream = (HarisFileStream*)_stream;\n  HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  HARIS_ASSERT(count <= 1000, SIZE);\n  HARIS_ASSERT(fread(stream->buffer, 1, count, stream->file) == count,\n               INPUT);\n  *dest = stream->buffer;\n  stream->curr += count;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus write_to_file_stream(void *_stream,\n                                        const unsigned char *src,\n                                        haris_uint32_t count)\n{\n  HarisFileStream *stream = (HarisFileStream*)_stream;\n  haris_uint32_t copy_size;\n  HARIS_ASSERT(count <= 1000, SIZE);\n  if (count + stream->curr > 1000) {\n    copy_size = 1000 - stream->curr;\n    memcpy(stream->buffer + stream->curr, src, copy_size);\n    HARIS_ASSERT(fwrite(stream->buffer, 1, 1000, stream->file) == count, \n                        INPUT);\n    memcpy(stream->buffer, src + copy_size, count - copy_size);\n    stream->curr = count - copy_size;\n  } else {\n    memcpy(stream->buffer + stream->curr, src, count);\n    stream->curr += count;\n  }\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_to_file(void *ptr,\n                                   const HarisStructureInfo *info,\n                                   FILE *f,\n                                   haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFileStream file_stream;\n  haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n  if (encoded_size == 0) return result;\n  HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  file_stream.file = f;\n  file_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &file_stream,\n                                 write_to_file_stream)) != HARIS_SUCCESS)\n    return result;\n  HARIS_ASSERT(fwrite(file_stream.buffer, 1, file_stream.curr, \n                      file_stream.file) == file_stream.curr, INPUT);\n  if (out_sz) *out_sz = encoded_size;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_from_file(void *ptr,\n                                     const HarisStructureInfo *info,\n                                     FILE *f,\n                                     haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFileStream file_stream;\n  file_stream.file = f;\n  file_stream.curr = 0;\n  if ((result = _haris_from_stream(ptr, info, &file_stream,\n                                   read_from_file_stream, 0)) != HARIS_SUCCESS)\n    return result;\n  if (out_sz) *out_sz = file_stream.curr;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_static_file_funcs(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static HarisStatus read_from_file_stream(void *_stream,\n                                         haris_uint32_t count,\n                                         const unsigned char **dest)\n{\n  HarisFileStream *stream = (HarisFileStream*)_stream;\n  HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  HARIS_ASSERT(count <= 1000, SIZE);\n  HARIS_ASSERT(fread(stream->buffer, 1, count, stream->file) == count,\n               INPUT);\n  *dest = stream->buffer;\n  stream->curr += count;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus write_to_file_stream(void *_stream,\n                                        const unsigned char *src,\n                                        haris_uint32_t count)\n{\n  HarisFileStream *stream = (HarisFileStream*)_stream;\n  haris_uint32_t copy_size;\n  HARIS_ASSERT(count <= 1000, SIZE);\n  if (count + stream->curr > 1000) {\n    copy_size = 1000 - stream->curr;\n    memcpy(stream->buffer + stream->curr, src, copy_size);\n    HARIS_ASSERT(fwrite(stream->buffer, 1, 1000, stream->file) == count, \n                        INPUT);\n    memcpy(stream->buffer, src + copy_size, count - copy_size);\n    stream->curr = count - copy_size;\n  } else {\n    memcpy(stream->buffer + stream->curr, src, count);\n    stream->curr += count;\n  }\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_to_file(void *ptr,\n                                   const HarisStructureInfo *info,\n                                   FILE *f,\n                                   haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFileStream file_stream;\n  haris_uint32_t encoded_size = haris_lib_size(ptr, info, 0, &result);\n  if (encoded_size == 0) return result;\n  HARIS_ASSERT(encoded_size <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  file_stream.file = f;\n  file_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &file_stream,\n                                 write_to_file_stream)) != HARIS_SUCCESS)\n    return result;\n  HARIS_ASSERT(fwrite(file_stream.buffer, 1, file_stream.curr, \n                      file_stream.file) == file_stream.curr, INPUT);\n  if (out_sz) *out_sz = encoded_size;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static HarisStatus _public_from_file(void *ptr,\n                                     const HarisStructureInfo *info,\n                                     FILE *f,\n                                     haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFileStream file_stream;\n  file_stream.file = f;\n  file_stream.curr = 0;\n  if ((result = _haris_from_stream(ptr, info, &file_stream,\n                                   read_from_file_stream, 0)) != HARIS_SUCCESS)\n    return result;\n  if (out_sz) *out_sz = file_stream.curr;\n  return HARIS_SUCCESS;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


decompiled_code:
__int64 __fastcall write_public_file_funcs(__int64 a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // r13
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

v2 = *(const char **)(a1 + 8);
v3 = *(const char **)a2;
v4 = strformat(
"HarisStatus %s%s_to_file(%s%s *strct, FILE *f, \n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_to_file(strct, &haris_lib_structures[%d],\n"
" f, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16));
if ( (unsigned int)add_public_function(a1, v4)
|| (v5 = strformat(
"HarisStatus %s%s_from_file(%s%s *strct, FILE *f,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_from_file(strct, &haris_lib_structures[%d],\n"
" f, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16)),
result = add_public_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const char *v2; // r12
const char *v3; // r13
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

v2 = *(const char **)(a1 + 8);
v3 = *(const char **)a2;
v4 = strformat(
"HarisStatus %s%s_to_file(%s%s *strct, FILE *f, \n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_to_file(strct, &haris_lib_structures[%d],\n"
" f, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16));
if ( (unsigned int)add_public_function(a1, v4)
|| (v5 = strformat(
"HarisStatus %s%s_from_file(%s%s *strct, FILE *f,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_from_file(strct, &haris_lib_structures[%d],\n"
" f, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16)),
result = add_public_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_public_file_funcs(CJob *job, ParsedStruct *strct)
{
  const char *prefix = job->prefix, *name = strct->name;
  do { if (add_public_function(job, strformat("HarisStatus %s%s_to_file(%s%s *strct, FILE *f, \n                          haris_uint32_t *out_sz)\n{\n  return _public_to_file(strct, &haris_lib_structures[%d],\n                         f, out_sz);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_public_function(job, strformat("HarisStatus %s%s_from_file(%s%s *strct, FILE *f,\n                            haris_uint32_t *out_sz)\n{\n  return _public_from_file(strct, &haris_lib_structures[%d],\n                           f, out_sz);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_public_file_funcs(struct CJob *job, struct _ParsedStruct *strct)
{
  char *prefix = job->prefix; char *name = strct->name;
  do { if (add_public_function(job, strformat("HarisStatus %s%s_to_file(%s%s *strct, FILE *f, \n                          haris_uint32_t *out_sz)\n{\n  return _public_to_file(strct, &haris_lib_structures[%d],\n                         f, out_sz);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_public_function(job, strformat("HarisStatus %s%s_from_file(%s%s *strct, FILE *f,\n                            haris_uint32_t *out_sz)\n{\n  return _public_from_file(strct, &haris_lib_structures[%d],\n                           f, out_sz);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


decompiled_code:
__int64 __fastcall write_file_protocol_funcs(__int64 *a1)
{
__int64 v1; // r13
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // rbx
int v5; // ebp

v1 = *a1;
v2 = write_file_structures((__int64)a1);
if ( v2 )
return v2;
v2 = write_static_file_funcs((__int64)a1);
if ( v2 )
return v2;
v4 = 0LL;
v5 = 0;
if ( *(int *)v1 <= 0 )
return v2;
while ( 1 )
{
LODWORD(result) = write_public_file_funcs((__int64)a1, v4 + *(_QWORD *)(v1 + 8));
if ( (_DWORD)result )
break;
++v5;
v4 += 56LL;
if ( *(_DWORD *)v1 <= v5 )
return v2;
}
return (unsigned int)result;
}

original_code:
CJobStatus write_file_protocol_funcs(CJob *job)
{
  CJobStatus result;
  int i;
  ParsedSchema *schema = job->schema;
  if ((result = write_file_structures(job)) != CJOB_SUCCESS ||
      (result = write_static_file_funcs(job)) != CJOB_SUCCESS)
    return result;
  for (i = 0; i < schema->num_structs; i ++) {
    if ((result = write_public_file_funcs(job, &schema->structs[i]))
        != CJOB_SUCCESS)
      return result;
  }
  return CJOB_SUCCESS;
}

canonical_original_code:
enum CJobStatus write_file_protocol_funcs(struct CJob *job)
{
  enum CJobStatus result;
  int i;
  struct ParsedSchema *schema = job->schema;
  if ((result = write_file_structures(job)) != CJOB_SUCCESS ||
      (result = write_static_file_funcs(job)) != CJOB_SUCCESS)
    return result;
  for (i = 0; i < schema->num_structs; i ++) {
    if ((result = write_public_file_funcs(job, &schema->structs[i]))
        != CJOB_SUCCESS)
      return result;
  }
  return CJOB_SUCCESS;
}


decompiled_code:
__int64 __fastcall util_vasprintf(char **a1, const char *a2, __m128i *a3)
{
__int64 result; // rax
unsigned int v5; // er12
size_t v6; // r14
char *v7; // rax
char *v8; // rbp
char *v9; // rdi
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v11; // [rsp+18h] [rbp-30h]

arg = _mm_loadu_si128(a3);
v11 = a3[1].m128i_i64[0];
LODWORD(result) = vsnprintf(0LL, 0LL, a2, a3);
v5 = result;
if ( (int)result < 0 )
return (unsigned int)result;
v6 = (int)result + 1LL;
v7 = (char *)malloc(v6);
v8 = v7;
if ( v7 )
{
if ( vsnprintf(v7, v6, a2, &arg) < 0 )
{
v9 = v8;
v5 = -1;
v8 = 0LL;
free(v9);
}
}
*a1 = v8;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, const char *a2, __m128i *a3)
{
__int64 result; // rax
unsigned int v5; // er12
size_t v6; // r14
char *v7; // rax
char *v8; // rbp
char *v9; // rdi
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v11; // [rsp+18h] [rbp-30h]

arg = _mm_loadu_si128(a3);
v11 = a3[1].m128i_i64[0];
LODWORD(result) = vsnprintf(0LL, 0LL, a2, a3);
v5 = result;
if ( (int)result < 0 )
return (unsigned int)result;
v6 = (int)result + 1LL;
v7 = (char *)malloc(v6);
v8 = v7;
if ( v7 )
{
if ( vsnprintf(v7, v6, a2, &arg) < 0 )
{
v9 = v8;
v5 = -1;
v8 = 0LL;
free(v9);
}
}
*a1 = v8;
return v5;
}

original_code:
int util_vasprintf(char **out, const char *fmt, va_list args)
{
  char *ret;
  int alloc_size;
  va_list args_copy;
  __builtin_va_copy(args_copy,args);
  alloc_size = vsnprintf((char*)((void *)0), 0, fmt, args);
  if (alloc_size >= 0) {
    ret = (char*)malloc((size_t)alloc_size + 1);
    if (ret) {
      if (vsnprintf(ret, (size_t)alloc_size + 1, fmt, args_copy) < 0) {
       free(ret);
       alloc_size = -1;
       ret = ((void *)0);
      }
    }
    *out = ret;
  }
  __builtin_va_end(args_copy);
  return alloc_size;
}

canonical_original_code:
int util_vasprintf(char **out, char *fmt, __builtin_va_list args)
{
  char *ret;
  int alloc_size;
  __builtin_va_list args_copy;
  __builtin_va_copy(args_copy,args);
  alloc_size = vsnprintf((char *)((void *)0), 0, fmt, args);
  if (alloc_size >= 0) {
    ret = (char *)malloc((unsigned long)alloc_size + 1);
    if (ret) {
      if (vsnprintf(ret, (unsigned long)alloc_size + 1, fmt, args_copy) < 0) {
       free(ret);
       alloc_size = -1;
       ret = ((void *)0);
      }
    }
    *out = ret;
  }
  __builtin_va_end(args_copy);
  return alloc_size;
}

variable_types:
out
char **

variable_types:
fmt
char *

variable_types:
ret
char *


decompiled_code:
__int64 util_asprintf(char **a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return util_vasprintf(a1, a2, (__m128i *)va);
}

canonical_decompiled_code:
__int64 func1(char **a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func0(a1, a2, (__m128i *)va);
}

original_code:
int util_asprintf(char **out, const char *fmt, ...)
{
  int alloc_size;
  va_list ap;
  __builtin_va_start(ap,fmt);
  alloc_size = util_vasprintf(out, fmt, ap);
  __builtin_va_end(ap);
  return alloc_size;
}

canonical_original_code:
int util_asprintf(char **out, char *fmt, ...)
{
  int alloc_size;
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  alloc_size = util_vasprintf(out, fmt, ap);
  __builtin_va_end(ap);
  return alloc_size;
}


decompiled_code:
void *__fastcall util_strdup(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func2(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
char *util_strdup(const char *s)
{
  char *ret = (char*)malloc(strlen(s) + 1);
  if (!ret) return ret;
  strcpy(ret, s);
  return ret;
}

canonical_original_code:
char *util_strdup(char *s)
{
  char *ret = (char*)malloc(strlen(s) + 1);
  if (!ret) return ret;
  strcpy(ret, s);
  return ret;
}

variable_types:
s
char *

return_type: char *


LiberaNode

decompiled_code:
void __fastcall LiberaNode(void *ptr)
{
LiberaLista(*((_QWORD *)ptr + 5));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
LiberaLista(*((_QWORD *)ptr + 5));
free(ptr);
}

original_code:
void LiberaNode(nodeArvore *node)
{
    LiberaLista(node->lista);
    free(node);
}

canonical_original_code:
void LiberaNode(struct nodeArvore_t *node)
{
    LiberaLista(node->lista);
    free(node);
}

variable_types: struct nodeArvore_t { struct nodeArvore_t *q1; struct nodeArvore_t *q2; struct nodeArvore_t *q3; struct nodeArvore_t *q4; unsigned int numPontos; unsigned int numMaxPontos; struct listaPontos_t { double x; double y; struct listaPontos_t *prox; } *lista; double xMin; int estaFragmentado; } *

user_defined_types: struct nodeArvore_t { struct nodeArvore_t *q1; struct nodeArvore_t *q2; struct nodeArvore_t *q3; struct nodeArvore_t *q4; unsigned int numPontos; unsigned int numMaxPontos; struct listaPontos_t *lista; double xMin; int estaFragmentado; }


InserePontoAux

decompiled_code:
__int64 __fastcall InserePontoAux(__int64 a1, double *a2, double a3, double a4)
{
int v5; // eax
double v6; // xmm2_8
double v7; // xmm2_8
__int64 result; // rax

while ( 1 )
{
v5 = *((_DWORD *)a2 + 24);
if ( *((_DWORD *)a2 + 8) < *((_DWORD *)a2 + 9) )
break;
while ( 1 )
{
if ( v5 )
{
LABEL_3:
v6 = a2[10];
if ( a3 < v6 )
break;
}
else
{
DivideQuad(a1, (double **)a2);
v6 = a2[10];
if ( a3 < v6 )
break;
}
if ( a2[7] < a3 || a4 < a2[11] || a2[9] < a4 )
break;
a2 = *(double **)a2;
v5 = *((_DWORD *)a2 + 24);
if ( *((_DWORD *)a2 + 8) < *((_DWORD *)a2 + 9) )
goto LABEL_2;
}
if ( a3 < a2[6] || v6 <= a3 )
{
LABEL_15:
a2 = (double *)*((_QWORD *)a2 + 3);
}
else
{
v7 = a2[11];
if ( a4 < v7 || a2[9] < a4 )
{
if ( a4 < a2[8] || v7 <= a4 )
goto LABEL_15;
a2 = (double *)*((_QWORD *)a2 + 2);
}
else
{
a2 = (double *)*((_QWORD *)a2 + 1);
}
}
}
LABEL_2:
if ( v5 )
goto LABEL_3;
result = InserePontoLista(*((_QWORD *)a2 + 5));
++*((_DWORD *)a2 + 8);
*((_QWORD *)a2 + 5) = result;
return result;
}

original_code:
void InserePontoAux(quadTree *arvore, double x, double y, nodeArvore* node)
{
    if ((node->numPontos<node->numMaxPontos)&&(!node->estaFragmentado))
    {
        node->lista = InserePontoLista(node->lista,x,y);
        node->numPontos++;
    }
    else
    {
        if (!node->estaFragmentado) DivideQuad(arvore, node);
        if ((x>=node->xMed)&&
            (x<=node->xMax)&&
            (y>=node->yMed)&&
            (y<=node->yMax) )
        {
            InserePontoAux(arvore, x, y, node->q1);
        }
        else
            if ((x>=node->xMin) &&
                (x<node->xMed) &&
                (y>=node->yMed) &&
                (y<=node->yMax))
            {
                InserePontoAux(arvore,x,y,node->q2);
            }
            else
                if ((x>=node->xMin)&&
                    (x<node->xMed)&&
                     (y>=node->yMin)&&
                     (y<node->yMed))
                {
                    InserePontoAux(arvore,x,y,node->q3);
                }
                else
                {
                    InserePontoAux(arvore,x,y,node->q4);
                }
    }
}

canonical_original_code:
void InserePontoAux(struct quadTree_t *arvore, double x, double y, struct nodeArvore_t *node)
{
    if ((node->numPontos<node->numMaxPontos)&&(!node->estaFragmentado))
    {
        node->lista = InserePontoLista(node->lista,x,y);
        node->numPontos++;
    }
    else
    {
        if (!node->estaFragmentado) DivideQuad(arvore, node);
        if ((x>=node->xMed)&&
            (x<=node->xMax)&&
            (y>=node->yMed)&&
            (y<=node->yMax) )
        {
            InserePontoAux(arvore, x, y, node->q1);
        }
        else
            if ((x>=node->xMin) &&
                (x<node->xMed) &&
                (y>=node->yMed) &&
                (y<=node->yMax))
            {
                InserePontoAux(arvore,x,y,node->q2);
            }
            else
                if ((x>=node->xMin)&&
                    (x<node->xMed)&&
                     (y>=node->yMin)&&
                     (y<node->yMed))
                {
                    InserePontoAux(arvore,x,y,node->q3);
                }
                else
                {
                    InserePontoAux(arvore,x,y,node->q4);
                }
    }
}

variable_types: struct quadTree_t { struct nodeArvore_t { struct nodeArvore_t *q1; struct nodeArvore_t *q2; struct nodeArvore_t *q3; struct nodeArvore_t *q4; unsigned int numPontos; unsigned int numMaxPontos; struct listaPontos_t { double x; double y; struct listaPontos_t *prox; } *lista; double xMin; int estaFragmentado; } *raiz; unsigned int tamanho; unsigned int numQuad; unsigned int numMaxPontosQuad; double xMax; } *

variable_types: x double

variable_types: y double

variable_types:
node
struct nodeArvore_t *

user_defined_types: struct quadTree_t { struct nodeArvore_t *raiz; unsigned int tamanho; unsigned int numQuad; unsigned int numMaxPontosQuad; double xMax; }


Bind

repo: thewopr/WireFish

decompiled_code:
int __fastcall Bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
{
perror("Bind error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
{
perror("Bind error");
exit(-1);
}
return result;
}

original_code:
int Bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) {
 int retval;
 if( (retval = bind(sockfd,my_addr,addrlen)) < 0 ) {
  perror("Bind error");
  exit(-1);
 }
 return(retval);
}

canonical_original_code:
int Bind(int sockfd, struct sockaddr *my_addr, unsigned int addrlen) {
 int retval;
 if( (retval = bind(sockfd,my_addr,addrlen)) < 0 ) {
  perror("Bind error");
  exit(-1);
 }
 return(retval);
}

variable_types: sockfd int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; } *

variable_types:
addrlen
unsigned int

variable_types: retval int


Socket

decompiled_code:
int __fastcall Socket(int a1, int a2, int a3)
{
int result; // eax

result = socket(a1, a2, a3);
if ( result < 0 )
{
perror("Socket error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2, int a3)
{
int result; // eax

result = socket(a1, a2, a3);
if ( result < 0 )
{
perror("Socket error");
exit(-1);
}
return result;
}

original_code:
int Socket(int family, int type, int protocol) {
  int retval;
  if( (retval = socket(family, type, protocol)) < 0) {
   perror("Socket error");
   exit(-1);
  }
  return(retval);
}

variable_types: family int

variable_types: type int

variable_types: protocol int


Recvfrom

decompiled_code:
__int64 __fastcall Recvfrom(int a1, void *a2, size_t a3, int a4, struct sockaddr *a5, socklen_t *a6)
{
if ( recvfrom(a1, a2, a3, a4, a5, a6) < 0 )
{
perror("Recvfrom error");
exit(-1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, void *a2, size_t a3, int a4, struct sockaddr *a5, socklen_t *a6)
{
if ( recvfrom(a1, a2, a3, a4, a5, a6) < 0 )
{
perror("Recvfrom error");
exit(-1);
}
return 0LL;
}

original_code:
ssize_t Recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) {
  int retval;
  if( (retval = recvfrom(s,buf,len,flags,from,fromlen) < 0)) {
    perror("Recvfrom error");
    exit(-1);
   }
   return(retval);
}

canonical_original_code:
long Recvfrom(int s, void *buf, unsigned long len, int flags, struct sockaddr *from, unsigned int *fromlen) {
  int retval;
  if( (retval = recvfrom(s,buf,len,flags,from,fromlen) < 0)) {
    perror("Recvfrom error");
    exit(-1);
   }
   return(retval);
}

variable_types: s int

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types: flags int

variable_types:
fromlen
unsigned int *

return_type: long

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


Sendto

decompiled_code:
__int64 __fastcall Sendto(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
__int64 result; // rax

LODWORD(result) = sendto(a1, a2, a3, a4, a5, a6);
if ( (int)result < 0 )
{
perror("Sendto error");
exit(-1);
}
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const void *a2, size_t a3, int a4, const struct sockaddr *a5, socklen_t a6)
{
__int64 result; // rax

LODWORD(result) = sendto(a1, a2, a3, a4, a5, a6);
if ( (int)result < 0 )
{
perror("Sendto error");
exit(-1);
}
return (int)result;
}

original_code:
ssize_t Sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to,
       socklen_t tolen) {
 int retval;
 if( (retval = sendto(s,buf,len,flags,to,tolen)) < 0) {
  perror("Sendto error");
  exit(-1);
 }
 return(retval);
}

canonical_original_code:
long Sendto(int s, void *buf, unsigned long len, int flags, struct sockaddr *to, unsigned int tolen) {
 int retval;
 if( (retval = sendto(s,buf,len,flags,to,tolen)) < 0) {
  perror("Sendto error");
  exit(-1);
 }
 return(retval);
}

variable_types:
tolen
unsigned int


Select

decompiled_code:
int __fastcall Select(int a1, fd_set *a2, fd_set *a3, fd_set *a4, struct timeval *a5)
{
int result; // eax

result = select(a1, a2, a3, a4, a5);
if ( result < 0 )
{
perror("Select error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, fd_set *a2, fd_set *a3, fd_set *a4, struct timeval *a5)
{
int result; // eax

result = select(a1, a2, a3, a4, a5);
if ( result < 0 )
{
perror("Select error");
exit(-1);
}
return result;
}

original_code:
int Select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) {
 int retval;
  if( (retval = select(nfds,readfds,writefds,exceptfds,timeout)) < 0) {
   perror("Select error");
   exit(-1);
  }
 return(retval);
}

canonical_original_code:
int Select(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, struct timeval *timeout) {
 int retval;
  if( (retval = select(nfds,readfds,writefds,exceptfds,timeout)) < 0) {
   perror("Select error");
   exit(-1);
  }
 return(retval);
}

variable_types: nfds int

variable_types: struct fd_set { long __fds_bits[-1]; } *

variable_types:
writefds
struct fd_set *

variable_types:
exceptfds
struct fd_set *

variable_types: struct timeval { long tv_sec; long tv_usec; } *


Clock

decompiled_code:
clock_t Clock()
{
clock_t result; // rax

result = clock();
if ( result == -1 )
{
perror("Clock had an error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
clock_t func5()
{
clock_t result; // rax

result = clock();
if ( result == -1 )
{
perror("Clock had an error");
exit(-1);
}
return result;
}

original_code:
clock_t Clock() {
 clock_t retval;
 if( (retval = clock()) == -1) {
  perror("Clock had an error");
  exit(-1);
 }
 return retval;
}

canonical_original_code:
long Clock() {
 long retval;
 if( (retval = clock()) == -1) {
  perror("Clock had an error");
  exit(-1);
 }
 return retval;
}

variable_types: retval long


Readn

decompiled_code:
__int64 Readn()
{
__int64 result; // rax

result = readn();
if ( result < 0 )
{
puts("readn error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

result = readn();
if ( result < 0 )
{
puts("readn error");
exit(-1);
}
return result;
}

original_code:
ssize_t Readn(int fd, void *ptr, size_t nbytes)
{
     ssize_t n;
     if ( (n = readn(fd, ptr, nbytes)) < 0) {
   printf("readn error\n");
   exit(-1);
     }
     return(n);
}

canonical_original_code:
long Readn(int fd, void *ptr, unsigned long nbytes)
{
     long n;
     if ( (n = readn(fd, ptr, nbytes)) < 0) {
   printf("readn error\n");
   exit(-1);
     }
     return(n);
}

variable_types: fd int

variable_types:
ptr
void *

variable_types:
nbytes
unsigned long

variable_types: n long


Writen

decompiled_code:
__int64 __fastcall Writen(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = writen();
if ( result != a3 )
{
puts("writen error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = writen();
if ( result != a3 )
{
puts("writen error");
exit(-1);
}
return result;
}

original_code:
void Writen(int fd, void *ptr, size_t nbytes)
{
  if (writen(fd, ptr, nbytes) != nbytes) {
    printf("writen error\n");
    exit(-1);
  }
}

canonical_original_code:
void Writen(int fd, void *ptr, unsigned long nbytes)
{
  if (writen(fd, ptr, nbytes) != nbytes) {
    printf("writen error\n");
    exit(-1);
  }
}


Connect

decompiled_code:
int __fastcall Connect(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
{
perror("Connect error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
{
perror("Connect error");
exit(-1);
}
return result;
}

original_code:
int Connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) {
    int retval;
    if((retval = connect(sockfd,serv_addr, addrlen)) < 0) {
        perror("Connect error");
        exit(-1);
    }
    return retval;
}

canonical_original_code:
int Connect(int sockfd, struct sockaddr *serv_addr, unsigned int addrlen) {
    int retval;
    if((retval = connect(sockfd,serv_addr, addrlen)) < 0) {
        perror("Connect error");
        exit(-1);
    }
    return retval;
}

variable_types: sockfd int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; } *

variable_types:
addrlen
unsigned int

variable_types: retval int


Getaddrinfo

decompiled_code:
int __fastcall Getaddrinfo(const char *a1, const char *a2, const struct addrinfo *a3, struct addrinfo **a4)
{
int result; // eax

result = getaddrinfo(a1, a2, a3, a4);
if ( result < 0 )
{
perror("getaddrinfo error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, const char *a2, const struct addrinfo *a3, struct addrinfo **a4)
{
int result; // eax

result = getaddrinfo(a1, a2, a3, a4);
if ( result < 0 )
{
perror("getaddrinfo error");
exit(-1);
}
return result;
}

original_code:
int Getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
    int retval;
    if((retval = getaddrinfo(node,service, hints, res)) < 0) {
        perror("getaddrinfo error");
        exit(-1);
    }
    return retval;
}

canonical_original_code:
int Getaddrinfo(char *node, char *service, struct addrinfo *hints, struct addrinfo **res) {
    int retval;
    if((retval = getaddrinfo(node,service, hints, res)) < 0) {
        perror("getaddrinfo error");
        exit(-1);
    }
    return retval;
}

variable_types:
node
char *

variable_types:
service
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
res
struct addrinfo **

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


Close

decompiled_code:
int __fastcall Close(int a1)
{
int result; // eax

result = close(a1);
if ( result < 0 )
{
perror("close error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
int result; // eax

result = close(a1);
if ( result < 0 )
{
perror("close error");
exit(-1);
}
return result;
}

original_code:
int Close(int fd) {
    int retval;
    if((retval = close(fd)) < 0) {
        perror("close error");
        exit(-1);
    }
 return retval;
}


Accept

decompiled_code:
int __fastcall Accept(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = accept(a1, a2, a3);
if ( result < 0 )
{
perror("Accept error");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = accept(a1, a2, a3);
if ( result < 0 )
{
perror("Accept error");
exit(-1);
}
return result;
}

original_code:
int Accept(int sockfd, struct sockaddr * addr, socklen_t* addrlen) {
 int retval;
 if(( retval = accept(sockfd, addr, addrlen)) < 0) {
  perror("Accept error");
  exit(-1);
 }
 return retval;
}

canonical_original_code:
int Accept(int sockfd, struct sockaddr *addr, unsigned int *addrlen) {
 int retval;
 if(( retval = accept(sockfd, addr, addrlen)) < 0) {
  perror("Accept error");
  exit(-1);
 }
 return retval;
}

variable_types:
addrlen
unsigned int *


printsin

decompiled_code:
int __fastcall printsin(unsigned __int16 *a1, const char *a2, const char *a3)
{
unsigned __int16 v3; // ax
char v5[24]; // [rsp+0h] [rbp-18h] BYREF

printf("%s %s", a2, a3);
inet_ntop(*a1, a1 + 2, v5, 0x10u);
v3 = _bswap_16(a1[1]);
printf("ip= %s, port= %d\n", v5, v3);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int16 *a1, const char *a2, const char *a3)
{
unsigned __int16 v3; // ax
char v5[24]; // [rsp+0h] [rbp-18h] BYREF

printf("%s %s", a2, a3);
inet_ntop(*a1, a1 + 2, v5, 0x10u);
v3 = func0(a1[1]);
printf("ip= %s, port= %d\n", v5, v3);
return fflush(stdout);
}

original_code:
void printsin(struct sockaddr_in *s, char *str1, char *str2) {
     char ip[16];
     printf("%s %s", str1, str2);
     inet_ntop((*s).sin_family, &((*s).sin_addr.s_addr), ip, sizeof(ip));
     printf("ip= %s, port= %d\n", ip, ntohs(s->sin_port));
   fflush(stdout);
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
ip
char [16]

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


readn

decompiled_code:
size_t __fastcall readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
v5 = nbytes;
if ( nbytes )
{
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func2(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
v5 = nbytes;
if ( nbytes )
{
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

original_code:
ssize_t
readn(int fd, void *vptr, size_t n)
{
     size_t nleft;
     ssize_t nread;
     char *ptr;
     ptr = vptr;
     nleft = n;
     while (nleft > 0) {
   if ( (nread = read(fd, ptr, nleft)) < 0) {
        if ((*__errno_location ()) == 4)
      nread = 0;
        else
      return(-1);
   } else if (nread == 0)
        break;
   nleft -= nread;
   ptr += nread;
     }
     return(n - nleft);
}

canonical_original_code:
long readn(int fd, void *vptr, unsigned long n)
{
     unsigned long nleft;
     long nread;
     char *ptr;
     ptr = vptr;
     nleft = n;
     while (nleft > 0) {
   if ( (nread = read(fd, ptr, nleft)) < 0) {
        if ((*__errno_location ()) == 4)
      nread = 0;
        else
      return(-1);
   } else if (nread == 0)
        break;
   nleft -= nread;
   ptr += nread;
     }
     return(n - nleft);
}

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
ptr
char *


writen

decompiled_code:
size_t __fastcall writen(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( v6 && *_errno_location() == 4 );
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func3(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
v5 = n;
if ( !n )
return v3;
do
{
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 <= 0 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
}
while ( v6 && *_errno_location() == 4 );
return -1LL;
}

original_code:
ssize_t
writen(int fd, const void *vptr, size_t n)
{
  size_t nleft;
  ssize_t nwritten;
  const char *ptr;
 ptr = vptr;
 nleft = n;
 while (nleft > 0) {
  if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
   if (nwritten < 0 && (*__errno_location ()) == 4)
    nwritten = 0;
   else
    return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(n);
}

canonical_original_code:
long writen(int fd, void *vptr, unsigned long n)
{
  unsigned long nleft;
  long nwritten;
  char *ptr;
 ptr = vptr;
 nleft = n;
 while (nleft > 0) {
  if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
   if (nwritten < 0 && (*__errno_location ()) == 4)
    nwritten = 0;
   else
    return(-1);
    }
    nleft -= nwritten;
    ptr += nwritten;
  }
  return(n);
}

variable_types: fd int

variable_types: nwritten long


usage

repo: thexhr/dermob

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("Usage: \t%s [-cdhstux] <binary>\n", a1);
puts("\t-c: Display complete header");
puts("\t-d: Display __DATA,__data section");
puts("\t-h: Display mach-o header");
puts("\t-s: Display __TEXT,__csting section");
puts("\t-t: Display __TEXT,__text section");
puts("\t-u: Display universal header");
puts("\t-x: Display hexdump");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("Usage: \t%s [-cdhstux] <binary>\n", a1);
puts("\t-c: Display complete header");
puts("\t-d: Display __DATA,__data section");
puts("\t-h: Display mach-o header");
puts("\t-s: Display __TEXT,__csting section");
puts("\t-t: Display __TEXT,__text section");
puts("\t-u: Display universal header");
puts("\t-x: Display hexdump");
exit(1);
}

original_code:
void
usage(const char *file)
{
 printf("Usage: 	%s [-cdhstux] <binary>\n", file);
 printf("	-c:  Display complete header\n");
 printf("	-d:  Display __DATA,__data section\n");
 printf("	-h:  Display mach-o header\n");
 printf("	-s:  Display __TEXT,__csting section\n");
 printf("	-t:  Display __TEXT,__text section\n");
 printf("	-u:  Display universal header\n");
 printf("	-x:  Display hexdump\n");
 exit(1);
}

canonical_original_code:
void usage(char *file)
{
 printf("Usage: 	%s [-cdhstux] <binary>\n", file);
 printf("	-c:  Display complete header\n");
 printf("	-d:  Display __DATA,__data section\n");
 printf("	-h:  Display mach-o header\n");
 printf("	-s:  Display __TEXT,__csting section\n");
 printf("	-t:  Display __TEXT,__text section\n");
 printf("	-u:  Display universal header\n");
 printf("	-x:  Display hexdump\n");
 exit(1);
}

variable_types:
file
char *