decompiled_code:
__int64 __fastcall write_readint(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax

v1 = strformat(
"static void haris_read_int8(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int8_t *ptr = (haris_int8_t*)_ptr;\n"
" haris_uint8_t uint;\n"
" haris_read_uint8(b, &uint);\n"
" if (*b & 0x80) \n"
" *ptr = -(haris_int8_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int8_t)uint;\n"
"}\n"
"\n");
v2 = add_private_function(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = strformat(
"static void haris_read_int16(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int16_t *ptr = (haris_int16_t*)_ptr;\n"
" haris_uint16_t uint;\n"
" haris_read_uint16(b, &uint);\n"
" if (*b & 0x80)\n"
" *ptr = -(haris_int16_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int16_t)uint;\n"
"}\n"
"\n");
v5 = add_private_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v6 = strformat(
"static void haris_read_int32(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int32_t *ptr = (haris_int32_t*)_ptr;\n"
" haris_uint32_t uint;\n"
" haris_read_uint32(b, &uint);\n"
" if (*b & 0x80)\n"
" *ptr = -(haris_int32_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int32_t)uint;\n"
"}\n"
"\n");
v7 = add_private_function(a1, v6);
result = 4LL;
if ( !v7 )
{
v8 = strformat(
"static void haris_read_int64(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int64_t *ptr = (haris_int64_t*)_ptr;\n"
" haris_uint64_t uint;\n"
" haris_read_uint64(b, &uint);\n"
" if (*b & 0x80)\n"
" *ptr = -(haris_int64_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int64_t)uint;\n"
"}\n"
"\n");
result = add_private_function(a1, v8);
if ( (_DWORD)result )
result = 4LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax

v1 = strformat(
"static void haris_read_int8(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int8_t *ptr = (haris_int8_t*)_ptr;\n"
" haris_uint8_t uint;\n"
" haris_read_uint8(b, &uint);\n"
" if (*b & 0x80) \n"
" *ptr = -(haris_int8_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int8_t)uint;\n"
"}\n"
"\n");
v2 = add_private_function(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = strformat(
"static void haris_read_int16(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int16_t *ptr = (haris_int16_t*)_ptr;\n"
" haris_uint16_t uint;\n"
" haris_read_uint16(b, &uint);\n"
" if (*b & 0x80)\n"
" *ptr = -(haris_int16_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int16_t)uint;\n"
"}\n"
"\n");
v5 = add_private_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v6 = strformat(
"static void haris_read_int32(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int32_t *ptr = (haris_int32_t*)_ptr;\n"
" haris_uint32_t uint;\n"
" haris_read_uint32(b, &uint);\n"
" if (*b & 0x80)\n"
" *ptr = -(haris_int32_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int32_t)uint;\n"
"}\n"
"\n");
v7 = add_private_function(a1, v6);
result = 4LL;
if ( !v7 )
{
v8 = strformat(
"static void haris_read_int64(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_int64_t *ptr = (haris_int64_t*)_ptr;\n"
" haris_uint64_t uint;\n"
" haris_read_uint64(b, &uint);\n"
" if (*b & 0x80)\n"
" *ptr = -(haris_int64_t)~(uint - 1);\n"
" else\n"
" *ptr = (haris_int64_t)uint;\n"
"}\n"
"\n");
result = add_private_function(a1, v8);
if ( (_DWORD)result )
result = 4LL;
}
}
}
return result;
}

original_code:
static CJobStatus write_readint(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_read_int8(const unsigned char *b, void *_ptr)\n{\n  haris_int8_t *ptr = (haris_int8_t*)_ptr;\n  haris_uint8_t uint;\n  haris_read_uint8(b, &uint);\n  if (*b & 0x80) \n    *ptr = -(haris_int8_t)~(uint - 1);\n  else\n    *ptr = (haris_int8_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_int16(const unsigned char *b, void *_ptr)\n{\n  haris_int16_t *ptr = (haris_int16_t*)_ptr;\n  haris_uint16_t uint;\n  haris_read_uint16(b, &uint);\n  if (*b & 0x80)\n    *ptr = -(haris_int16_t)~(uint - 1);\n  else\n    *ptr = (haris_int16_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_int32(const unsigned char *b, void *_ptr)\n{\n  haris_int32_t *ptr = (haris_int32_t*)_ptr;\n  haris_uint32_t uint;\n  haris_read_uint32(b, &uint);\n  if (*b & 0x80)\n    *ptr = -(haris_int32_t)~(uint - 1);\n  else\n    *ptr = (haris_int32_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_int64(const unsigned char *b, void *_ptr)\n{\n  haris_int64_t *ptr = (haris_int64_t*)_ptr;\n  haris_uint64_t uint;\n  haris_read_uint64(b, &uint);\n  if (*b & 0x80)\n    *ptr = -(haris_int64_t)~(uint - 1);\n  else\n    *ptr = (haris_int64_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_readint(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_read_int8(const unsigned char *b, void *_ptr)\n{\n  haris_int8_t *ptr = (haris_int8_t*)_ptr;\n  haris_uint8_t uint;\n  haris_read_uint8(b, &uint);\n  if (*b & 0x80) \n    *ptr = -(haris_int8_t)~(uint - 1);\n  else\n    *ptr = (haris_int8_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_int16(const unsigned char *b, void *_ptr)\n{\n  haris_int16_t *ptr = (haris_int16_t*)_ptr;\n  haris_uint16_t uint;\n  haris_read_uint16(b, &uint);\n  if (*b & 0x80)\n    *ptr = -(haris_int16_t)~(uint - 1);\n  else\n    *ptr = (haris_int16_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_int32(const unsigned char *b, void *_ptr)\n{\n  haris_int32_t *ptr = (haris_int32_t*)_ptr;\n  haris_uint32_t uint;\n  haris_read_uint32(b, &uint);\n  if (*b & 0x80)\n    *ptr = -(haris_int32_t)~(uint - 1);\n  else\n    *ptr = (haris_int32_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_int64(const unsigned char *b, void *_ptr)\n{\n  haris_int64_t *ptr = (haris_int64_t*)_ptr;\n  haris_uint64_t uint;\n  haris_read_uint64(b, &uint);\n  if (*b & 0x80)\n    *ptr = -(haris_int64_t)~(uint - 1);\n  else\n    *ptr = (haris_int64_t)uint;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


repo: theseoafs/haris

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

v1 = strformat(
"static\n"
"void (* const haris_lib_scalar_writers[])(unsigned char *, const void *) = {\n"
" haris_write_uint8, haris_write_int8, haris_write_uint16, haris_write_int16,\n"
" haris_write_uint32, haris_write_int32, haris_write_uint64, haris_write_int64,\n"
" haris_write_float32, haris_write_float64\n"
"};\n"
"\n");
result = add_source_string(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

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

v1 = strformat(
"static\n"
"void (* const haris_lib_scalar_writers[])(unsigned char *, const void *) = {\n"
" haris_write_uint8, haris_write_int8, haris_write_uint16, haris_write_int16,\n"
" haris_write_uint32, haris_write_int32, haris_write_uint64, haris_write_int64,\n"
" haris_write_float32, haris_write_float64\n"
"};\n"
"\n");
result = add_source_string(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

original_code:
static CJobStatus write_scalar_writers(CJob *job)
{
  do { if (add_source_string(job, strformat("static\nvoid (* const haris_lib_scalar_writers[])(unsigned char *, const void *) = {\n  haris_write_uint8, haris_write_int8, haris_write_uint16, haris_write_int16,\n  haris_write_uint32, haris_write_int32, haris_write_uint64, haris_write_int64,\n  haris_write_float32, haris_write_float64\n};\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_scalar_writers(struct CJob *job)
{
  do { if (add_source_string(job, strformat("static\nvoid (* const haris_lib_scalar_writers[])(unsigned char *, const void *) = {\n  haris_write_uint8, haris_write_int8, haris_write_uint16, haris_write_int16,\n  haris_write_uint32, haris_write_int32, haris_write_uint64, haris_write_int64,\n  haris_write_float32, haris_write_float64\n};\n\n")) != 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; } *

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_scalar_readers(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = strformat(
"static\n"
"void (* const haris_lib_scalar_readers[])(const unsigned char *, void *) = {\n"
" haris_read_uint8, haris_read_int8, haris_read_uint16, haris_read_int16,\n"
" haris_read_uint32, haris_read_int32, haris_read_uint64, haris_read_int64,\n"
" haris_read_float32, haris_read_float64\n"
"};\n"
"\n");
result = add_source_string(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

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

v1 = strformat(
"static\n"
"void (* const haris_lib_scalar_readers[])(const unsigned char *, void *) = {\n"
" haris_read_uint8, haris_read_int8, haris_read_uint16, haris_read_int16,\n"
" haris_read_uint32, haris_read_int32, haris_read_uint64, haris_read_int64,\n"
" haris_read_float32, haris_read_float64\n"
"};\n"
"\n");
result = add_source_string(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

original_code:
static CJobStatus write_scalar_readers(CJob *job)
{
  do { if (add_source_string(job, strformat("static\nvoid (* const haris_lib_scalar_readers[])(const unsigned char *, void *) = {\n  haris_read_uint8, haris_read_int8, haris_read_uint16, haris_read_int16,\n  haris_read_uint32, haris_read_int32, haris_read_uint64, haris_read_int64,\n  haris_read_float32, haris_read_float64\n};\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_scalar_readers(struct CJob *job)
{
  do { if (add_source_string(job, strformat("static\nvoid (* const haris_lib_scalar_readers[])(const unsigned char *, void *) = {\n  haris_read_uint8, haris_read_int8, haris_read_uint16, haris_read_int16,\n  haris_read_uint32, haris_read_int32, haris_read_uint64, haris_read_int64,\n  haris_read_float32, haris_read_float64\n};\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  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 CJobProtocols { int buffer; int file; int fd; }

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

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; }

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; }


decompiled_code:
__int64 __fastcall write_utility_library(__int64 a1)
{
__int64 (__fastcall **v1)(); // rbx
__int64 result; // rax

v1 = util_writer_functions;
do
{
result = ((__int64 (__fastcall *)(__int64))*v1)(a1);
if ( (_DWORD)result )
break;
++v1;
}
while ( v1 != (__int64 (__fastcall **)())&unk_2430 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 (__fastcall **v1)(); // rbx
__int64 result; // rax

v1 = util_writer_functions;
do
{
result = ((__int64 (__fastcall *)(__int64))*v1)(a1);
if ( (_DWORD)result )
break;
++v1;
}
while ( v1 != (__int64 (__fastcall **)())&unk_2430 );
return result;
}

original_code:
CJobStatus write_utility_library(CJob *job)
{
  CJobStatus result;
  unsigned i;
  for (i = 0;
      i < sizeof util_writer_functions /
       sizeof util_writer_functions[0];
      i ++) {
   if ((result = util_writer_functions[i](job)) != CJOB_SUCCESS)
     return result;
  }
  return CJOB_SUCCESS;
}

canonical_original_code:
enum CJobStatus write_utility_library(struct CJob *job)
{
  enum CJobStatus result;
  unsigned int i;
  for (i = 0;
      i < sizeof util_writer_functions /
       sizeof util_writer_functions[0];
      i ++) {
   if ((result = util_writer_functions[i](job)) != 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
unsigned int


version

decompiled_code:
size_t version()
{
return fwrite("haris 0.0.0\n", 1uLL, 0xCuLL, stdout);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite("haris 0.0.0\n", 1uLL, 0xCuLL, stdout);
}

original_code:
static void version(void)
{
  fprintf(stdout, "haris 0.0.0\n");
}

canonical_original_code:
static void version()
{
  fprintf(stdout, "haris 0.0.0\n");
}

return_type: void


decompiled_code:
_BOOL8 delegate_to_c()
{
return (unsigned int)cgen_main() != 0;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return (unsigned int)cgen_main() != 0;
}

original_code:
static int delegate_to_c(int argc, char **argv)
{
  CJobStatus result = cgen_main(argc, argv);
  if (result == CJOB_SUCCESS) return 0;
  else return 1;
}

canonical_original_code:
static int delegate_to_c(int argc, char **argv)
{
  enum CJobStatus result = cgen_main(argc, argv);
  if (result == CJOB_SUCCESS) return 0;
  else return 1;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
_BOOL8 __fastcall delegate_compiler(int a1, __int64 a2)
{
const char *v2; // r8
_BOOL8 result; // rax

if ( a1 <= 2 )
{
fwrite("No language code included after -l option.\nRun `haris -h` for help.\n", 1uLL, 0x44uLL, stderr);
result = 1LL;
}
else
{
v2 = *(const char **)(a2 + 16);
if ( !strcmp(v2, "c") )
{
result = delegate_to_c();
}
else
{
fprintf(stderr, "Unrecognized language code %s.\nRun `haris -h` for help.\n", v2);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, __int64 a2)
{
const char *v2; // r8
_BOOL8 result; // rax

if ( a1 <= 2 )
{
fwrite("No language code included after -l option.\nRun `haris -h` for help.\n", 1uLL, 0x44uLL, stderr);
result = 1LL;
}
else
{
v2 = *(const char **)(a2 + 16);
if ( !strcmp(v2, "c") )
{
result = func2();
}
else
{
fprintf(stderr, "Unrecognized language code %s.\nRun `haris -h` for help.\n", v2);
result = 1LL;
}
}
return result;
}

original_code:
static int delegate_compiler(int argc, char **argv)
{
  if (argc <= 2) {
    fprintf(stderr, "No language code included after -l option.\nRun `haris -h` for help.\n");
    return 1;
  }
  if (!strcmp(argv[2], "c")) {
    return delegate_to_c(argc, argv);
  } else {
    fprintf(stderr, "Unrecognized language code %s.\nRun `haris -h` for help.\n", argv[2]);
    return 1;
  }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int result; // eax

if ( argc <= 1 )
{
fwrite("Not enough command line arguments provided.\nRun `haris -h` for help.\n", 1uLL, 0x45uLL, stderr);
result = 1;
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
{
usage();
result = 0;
}
else if ( !strcmp(v3, "-v") || !strcmp(v3, "--version") )
{
version();
result = 0;
}
else if ( !strcmp(v3, "-l") )
{
result = delegate_compiler(argc, (__int64)argv);
}
else
{
fprintf(
stderr,
"The first command line argument must be -h, -v, or -l; instead, received %s.\nRun `haris -h` for help.\n",
v3);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int result; // eax

if ( argc <= 1 )
{
fwrite("Not enough command line arguments provided.\nRun `haris -h` for help.\n", 1uLL, 0x45uLL, stderr);
result = 1;
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
{
func0();
result = 0;
}
else if ( !strcmp(v3, "-v") || !strcmp(v3, "--version") )
{
func1();
result = 0;
}
else if ( !strcmp(v3, "-l") )
{
result = func3(argc, (__int64)argv);
}
else
{
fprintf(
stderr,
"The first command line argument must be -h, -v, or -l; instead, received %s.\nRun `haris -h` for help.\n",
v3);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
  if (argc <= 1) {
    fprintf(stderr, "Not enough command line arguments provided.\nRun `haris -h` for help.\n");
    return 1;
  }
  if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
    usage();
    return 0;
  } else if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
    version();
    return 0;
  } else if (!strcmp(argv[1], "-l")) {
    return delegate_compiler(argc, argv);
  } else {
    fprintf(stderr,
"The first command line argument must be -h, -v, or -l; instead, received %s.\nRun `haris -h` for help.\n", argv[1]);
    return 1;
  }
  return 0;
}


usage

decompiled_code:
size_t usage()
{
return fwrite(
"Usage: haris -l [language] [options] file...\n"
"\n"
"The Haris tool is a collection of compilers. (The size of this collection, currently, is 1.) To show this mes"
"sage, run `haris -h`.\n"
"\n"
"To run a compiler, run `haris -l X` where X is an acceptable language code. Currently acceptable language cod"
"es at this point in time are:\n"
" c\n"
"\n"
"The compilers may each have different interfaces, and are expected to be called with different arguments and "
"options. To receive help about how to use a particular compiler, run `haris -l X -h` where X is the applicabl"
"e language code.\n",
1uLL,
0x22DuLL,
stdout);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"Usage: haris -l [language] [options] file...\n"
"\n"
"The Haris tool is a collection of compilers. (The size of this collection, currently, is 1.) To show this mes"
"sage, run `haris -h`.\n"
"\n"
"To run a compiler, run `haris -l X` where X is an acceptable language code. Currently acceptable language cod"
"es at this point in time are:\n"
" c\n"
"\n"
"The compilers may each have different interfaces, and are expected to be called with different arguments and "
"options. To receive help about how to use a particular compiler, run `haris -l X -h` where X is the applicabl"
"e language code.\n",
1uLL,
0x22DuLL,
stdout);
}

original_code:
static void usage(void)
{
  fprintf(stdout,
"Usage: haris -l [language] [options] file...\n\nThe Haris tool is a collection of compilers. (The size of this collection, currently, is 1.) To show this message, run `haris -h`.\n\nTo run a compiler, run `haris -l X` where X is an acceptable language code. Currently acceptable language codes at this point in time are:\n  c\n\nThe compilers may each have different interfaces, and are expected to be called with different arguments and options. To receive help about how to use a particular compiler, run `haris -l X -h` where X is the applicable language code.\n");
}

canonical_original_code:
static void usage()
{
  fprintf(stdout,
"Usage: haris -l [language] [options] file...\n\nThe Haris tool is a collection of compilers. (The size of this collection, currently, is 1.) To show this message, run `haris -h`.\n\nTo run a compiler, run `haris -l X` where X is an acceptable language code. Currently acceptable language codes at this point in time are:\n  c\n\nThe compilers may each have different interfaces, and are expected to be called with different arguments and options. To receive help about how to use a particular compiler, run `haris -l X -h` where X is the applicable language code.\n");
}


decompiled_code:
__int64 __fastcall write_fd_structures(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax

v1 = strformat("#include <unistd.h>\n#include<errno.h>\n\n");
v2 = add_header_string(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = strformat("typedef struct {\n int fd;\n haris_uint32_t curr;\n unsigned char buffer[1000];\n} HarisFdStream;\n\n");
result = add_header_string(a1, v4);
if ( (_DWORD)result )
result = 4LL;
}
return result;
}

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

v1 = strformat("#include <unistd.h>\n#include<errno.h>\n\n");
v2 = add_header_string(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = strformat("typedef struct {\n int fd;\n haris_uint32_t curr;\n unsigned char buffer[1000];\n} HarisFdStream;\n\n");
result = add_header_string(a1, v4);
if ( (_DWORD)result )
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_fd_structures(CJob *job)
{
  do { if (add_header_string(job, strformat("#include <unistd.h>\n#include<errno.h>\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_header_string(job, strformat("typedef struct {\n  int fd;\n  haris_uint32_t curr;\n  unsigned char buffer[1000];\n} HarisFdStream;\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

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


decompiled_code:
__int64 __fastcall write_static_fd_funcs(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax
int v9; // edx
__int64 v10; // rax

v1 = strformat(
"static HarisStatus read_from_fd_stream(void *_stream,\n"
" haris_uint32_t count,\n"
" const unsigned char **dest)\n"
"{\n"
" HarisFdStream *stream = (HarisFdStream*)_stream;\n"
" ssize_t result;\n"
" haris_uint32_t bytes_read = 0;\n"
" if (count == 0) return HARIS_SUCCESS;\n"
" HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" do {\n"
" result = read(stream->fd, stream->buffer + bytes_read, \n"
" count - bytes_read);\n"
" if (result < 0) {\n"
" if (errno != EINTR)\n"
" return HARIS_INPUT_ERROR;\n"
" else \n"
" continue;\n"
" } else if (result == 0) { /* EOF: error */\n"
" return HARIS_INPUT_ERROR;\n"
" } else {\n"
" bytes_read += result;\n"
" }\n"
" } while (bytes_read < count);\n"
" *dest = stream->buffer;\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
v2 = add_private_function(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = strformat(
"static HarisStatus force_write_to_fd_stream(int fd, \n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" ssize_t result;\n"
" haris_uint32_t bytes_written = 0;\n"
" if (count == 0) return HARIS_SUCCESS;\n"
" do {\n"
" result = write(fd, src + bytes_written, count - bytes_written);\n"
" if (result < 0) {\n"
" if (errno != EINTR)\n"
" return HARIS_INPUT_ERROR;\n"
" else\n"
" continue;\n"
" } else {\n"
" bytes_written += result;\n"
" }\n"
" } while (bytes_written < count);\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
v5 = add_private_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v6 = strformat(
"static HarisStatus write_to_fd_stream(void *_stream,\n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" HarisFdStream *stream = (HarisFdStream*)_stream;\n"
" HarisStatus result;\n"
" haris_uint32_t copy_size;\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" if (count == 0) return HARIS_SUCCESS;\n"
" if (count + stream->curr > 1000) {\n"
" copy_size = 1000 - stream->curr;\n"
" memcpy(stream->buffer + stream->curr, src, copy_size);\n"
" if ((result = force_write_to_fd_stream(stream->fd, stream->buffer,\n"
" 1000)) != HARIS_SUCCESS)\n"
" return result;\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");
v7 = add_private_function(a1, v6);
result = 4LL;
if ( !v7 )
{
v8 = strformat(
"static HarisStatus _public_to_fd(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" int fd,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFdStream fd_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"
" fd_stream.fd = fd;\n"
" fd_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &fd_stream,\n"
" write_to_fd_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" if ((result = force_write_to_fd_stream(fd, fd_stream.buffer, \n"
" fd_stream.curr)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_sz) *out_sz = encoded_size;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
v9 = add_private_function(a1, v8);
result = 4LL;
if ( !v9 )
{
v10 = strformat(
"static HarisStatus _public_from_fd(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" int fd,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFdStream fd_stream;\n"
" fd_stream.fd = fd;\n"
" fd_stream.curr = 0;\n"
" if ((result = _haris_from_stream(ptr, info, &fd_stream,\n"
" read_from_fd_stream, 0)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_sz) *out_sz = fd_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
result = add_private_function(a1, v10);
if ( (_DWORD)result )
result = 4LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax
int v9; // edx
__int64 v10; // rax

v1 = strformat(
"static HarisStatus read_from_fd_stream(void *_stream,\n"
" haris_uint32_t count,\n"
" const unsigned char **dest)\n"
"{\n"
" HarisFdStream *stream = (HarisFdStream*)_stream;\n"
" ssize_t result;\n"
" haris_uint32_t bytes_read = 0;\n"
" if (count == 0) return HARIS_SUCCESS;\n"
" HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" do {\n"
" result = read(stream->fd, stream->buffer + bytes_read, \n"
" count - bytes_read);\n"
" if (result < 0) {\n"
" if (errno != EINTR)\n"
" return HARIS_INPUT_ERROR;\n"
" else \n"
" continue;\n"
" } else if (result == 0) { /* EOF: error */\n"
" return HARIS_INPUT_ERROR;\n"
" } else {\n"
" bytes_read += result;\n"
" }\n"
" } while (bytes_read < count);\n"
" *dest = stream->buffer;\n"
" stream->curr += count;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
v2 = add_private_function(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = strformat(
"static HarisStatus force_write_to_fd_stream(int fd, \n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" ssize_t result;\n"
" haris_uint32_t bytes_written = 0;\n"
" if (count == 0) return HARIS_SUCCESS;\n"
" do {\n"
" result = write(fd, src + bytes_written, count - bytes_written);\n"
" if (result < 0) {\n"
" if (errno != EINTR)\n"
" return HARIS_INPUT_ERROR;\n"
" else\n"
" continue;\n"
" } else {\n"
" bytes_written += result;\n"
" }\n"
" } while (bytes_written < count);\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
v5 = add_private_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v6 = strformat(
"static HarisStatus write_to_fd_stream(void *_stream,\n"
" const unsigned char *src,\n"
" haris_uint32_t count)\n"
"{\n"
" HarisFdStream *stream = (HarisFdStream*)_stream;\n"
" HarisStatus result;\n"
" haris_uint32_t copy_size;\n"
" HARIS_ASSERT(count <= 1000, SIZE);\n"
" if (count == 0) return HARIS_SUCCESS;\n"
" if (count + stream->curr > 1000) {\n"
" copy_size = 1000 - stream->curr;\n"
" memcpy(stream->buffer + stream->curr, src, copy_size);\n"
" if ((result = force_write_to_fd_stream(stream->fd, stream->buffer,\n"
" 1000)) != HARIS_SUCCESS)\n"
" return result;\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");
v7 = add_private_function(a1, v6);
result = 4LL;
if ( !v7 )
{
v8 = strformat(
"static HarisStatus _public_to_fd(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" int fd,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFdStream fd_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"
" fd_stream.fd = fd;\n"
" fd_stream.curr = 0;\n"
" if ((result = _haris_to_stream(ptr, info, &fd_stream,\n"
" write_to_fd_stream)) != HARIS_SUCCESS)\n"
" return result;\n"
" if ((result = force_write_to_fd_stream(fd, fd_stream.buffer, \n"
" fd_stream.curr)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_sz) *out_sz = encoded_size;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
v9 = add_private_function(a1, v8);
result = 4LL;
if ( !v9 )
{
v10 = strformat(
"static HarisStatus _public_from_fd(void *ptr,\n"
" const HarisStructureInfo *info,\n"
" int fd,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" HarisStatus result;\n"
" HarisFdStream fd_stream;\n"
" fd_stream.fd = fd;\n"
" fd_stream.curr = 0;\n"
" if ((result = _haris_from_stream(ptr, info, &fd_stream,\n"
" read_from_fd_stream, 0)) != HARIS_SUCCESS)\n"
" return result;\n"
" if (out_sz) *out_sz = fd_stream.curr;\n"
" return HARIS_SUCCESS;\n"
"}\n"
"\n");
result = add_private_function(a1, v10);
if ( (_DWORD)result )
result = 4LL;
}
}
}
}
return result;
}

original_code:
static CJobStatus write_static_fd_funcs(CJob *job)
{
  do { if (add_private_function(job, strformat("static HarisStatus read_from_fd_stream(void *_stream,\n                                         haris_uint32_t count,\n                                         const unsigned char **dest)\n{\n  HarisFdStream *stream = (HarisFdStream*)_stream;\n  ssize_t result;\n  haris_uint32_t bytes_read = 0;\n  if (count == 0) return HARIS_SUCCESS;\n  HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  HARIS_ASSERT(count <= 1000, SIZE);\n  do {\n    result = read(stream->fd, stream->buffer + bytes_read, \n                  count - bytes_read);\n    if (result < 0) {\n      if (errno != EINTR)\n        return HARIS_INPUT_ERROR;\n      else \n        continue;\n    } else if (result == 0) { /* EOF: error */\n      return HARIS_INPUT_ERROR;\n    } else {\n      bytes_read += result;\n    }\n  } while (bytes_read < count);\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 force_write_to_fd_stream(int fd, \n                                             const unsigned char *src,\n                                             haris_uint32_t count)\n{\n  ssize_t result;\n  haris_uint32_t bytes_written = 0;\n  if (count == 0) return HARIS_SUCCESS;\n  do {\n    result = write(fd, src + bytes_written, count - bytes_written);\n    if (result < 0) {\n      if (errno != EINTR)\n        return HARIS_INPUT_ERROR;\n      else\n        continue;\n    } else {\n      bytes_written += result;\n    }\n  } while (bytes_written < 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_fd_stream(void *_stream,\n                                        const unsigned char *src,\n                                        haris_uint32_t count)\n{\n  HarisFdStream *stream = (HarisFdStream*)_stream;\n  HarisStatus result;\n  haris_uint32_t copy_size;\n  HARIS_ASSERT(count <= 1000, SIZE);\n  if (count == 0) return HARIS_SUCCESS;\n  if (count + stream->curr > 1000) {\n    copy_size = 1000 - stream->curr;\n    memcpy(stream->buffer + stream->curr, src, copy_size);\n    if ((result = force_write_to_fd_stream(stream->fd, stream->buffer,\n                                           1000)) != HARIS_SUCCESS)\n      return result;\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_fd(void *ptr,\n                                   const HarisStructureInfo *info,\n                                   int fd,\n                                   haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFdStream fd_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  fd_stream.fd = fd;\n  fd_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &fd_stream,\n                                 write_to_fd_stream)) != HARIS_SUCCESS)\n    return result;\n  if ((result = force_write_to_fd_stream(fd, fd_stream.buffer, \n                                         fd_stream.curr)) != HARIS_SUCCESS)\n    return result;\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_fd(void *ptr,\n                                     const HarisStructureInfo *info,\n                                     int fd,\n                                     haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFdStream fd_stream;\n  fd_stream.fd = fd;\n  fd_stream.curr = 0;\n  if ((result = _haris_from_stream(ptr, info, &fd_stream,\n                                   read_from_fd_stream, 0)) != HARIS_SUCCESS)\n    return result;\n  if (out_sz) *out_sz = fd_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_fd_funcs(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static HarisStatus read_from_fd_stream(void *_stream,\n                                         haris_uint32_t count,\n                                         const unsigned char **dest)\n{\n  HarisFdStream *stream = (HarisFdStream*)_stream;\n  ssize_t result;\n  haris_uint32_t bytes_read = 0;\n  if (count == 0) return HARIS_SUCCESS;\n  HARIS_ASSERT(count + stream->curr <= HARIS_MESSAGE_SIZE_LIMIT, SIZE);\n  HARIS_ASSERT(count <= 1000, SIZE);\n  do {\n    result = read(stream->fd, stream->buffer + bytes_read, \n                  count - bytes_read);\n    if (result < 0) {\n      if (errno != EINTR)\n        return HARIS_INPUT_ERROR;\n      else \n        continue;\n    } else if (result == 0) { /* EOF: error */\n      return HARIS_INPUT_ERROR;\n    } else {\n      bytes_read += result;\n    }\n  } while (bytes_read < count);\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 force_write_to_fd_stream(int fd, \n                                             const unsigned char *src,\n                                             haris_uint32_t count)\n{\n  ssize_t result;\n  haris_uint32_t bytes_written = 0;\n  if (count == 0) return HARIS_SUCCESS;\n  do {\n    result = write(fd, src + bytes_written, count - bytes_written);\n    if (result < 0) {\n      if (errno != EINTR)\n        return HARIS_INPUT_ERROR;\n      else\n        continue;\n    } else {\n      bytes_written += result;\n    }\n  } while (bytes_written < 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_fd_stream(void *_stream,\n                                        const unsigned char *src,\n                                        haris_uint32_t count)\n{\n  HarisFdStream *stream = (HarisFdStream*)_stream;\n  HarisStatus result;\n  haris_uint32_t copy_size;\n  HARIS_ASSERT(count <= 1000, SIZE);\n  if (count == 0) return HARIS_SUCCESS;\n  if (count + stream->curr > 1000) {\n    copy_size = 1000 - stream->curr;\n    memcpy(stream->buffer + stream->curr, src, copy_size);\n    if ((result = force_write_to_fd_stream(stream->fd, stream->buffer,\n                                           1000)) != HARIS_SUCCESS)\n      return result;\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_fd(void *ptr,\n                                   const HarisStructureInfo *info,\n                                   int fd,\n                                   haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFdStream fd_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  fd_stream.fd = fd;\n  fd_stream.curr = 0;\n  if ((result = _haris_to_stream(ptr, info, &fd_stream,\n                                 write_to_fd_stream)) != HARIS_SUCCESS)\n    return result;\n  if ((result = force_write_to_fd_stream(fd, fd_stream.buffer, \n                                         fd_stream.curr)) != HARIS_SUCCESS)\n    return result;\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_fd(void *ptr,\n                                     const HarisStructureInfo *info,\n                                     int fd,\n                                     haris_uint32_t *out_sz)\n{\n  HarisStatus result;\n  HarisFdStream fd_stream;\n  fd_stream.fd = fd;\n  fd_stream.curr = 0;\n  if ((result = _haris_from_stream(ptr, info, &fd_stream,\n                                   read_from_fd_stream, 0)) != HARIS_SUCCESS)\n    return result;\n  if (out_sz) *out_sz = fd_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_fd_funcs(__int64 a1, const char **a2)
{
const char *v2; // r12
const char *v3; // r13
__int64 v4; // rax
int v5; // edx
__int64 result; // rax
__int64 v7; // rax

v2 = *(const char **)(a1 + 8);
v3 = *a2;
v4 = strformat(
"HarisStatus %s%s_to_fd(%s%s *strct, int fd, \n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_to_fd(strct, &haris_lib_structures[%d],\n"
" fd, out_sz);\n"
"}\n"
"\n",
v2,
*a2,
v2,
*a2,
*((unsigned int *)a2 + 4));
v5 = add_public_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v7 = strformat(
"HarisStatus %s%s_from_fd(%s%s *strct, int fd,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_from_fd(strct, &haris_lib_structures[%d],\n"
" fd, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*((unsigned int *)a2 + 4));
result = add_public_function(a1, v7);
if ( (_DWORD)result )
result = 4LL;
}
return result;
}

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

v2 = *(const char **)(a1 + 8);
v3 = *a2;
v4 = strformat(
"HarisStatus %s%s_to_fd(%s%s *strct, int fd, \n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_to_fd(strct, &haris_lib_structures[%d],\n"
" fd, out_sz);\n"
"}\n"
"\n",
v2,
*a2,
v2,
*a2,
*((unsigned int *)a2 + 4));
v5 = add_public_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v7 = strformat(
"HarisStatus %s%s_from_fd(%s%s *strct, int fd,\n"
" haris_uint32_t *out_sz)\n"
"{\n"
" return _public_from_fd(strct, &haris_lib_structures[%d],\n"
" fd, out_sz);\n"
"}\n"
"\n",
v2,
v3,
v2,
v3,
*((unsigned int *)a2 + 4));
result = add_public_function(a1, v7);
if ( (_DWORD)result )
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_public_fd_funcs(CJob *job, ParsedStruct *strct)
{
  const char *prefix = job->prefix, *name = strct->name;
  do { if (add_public_function(job, strformat("HarisStatus %s%s_to_fd(%s%s *strct, int fd, \n                          haris_uint32_t *out_sz)\n{\n  return _public_to_fd(strct, &haris_lib_structures[%d],\n                         fd, 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_fd(%s%s *strct, int fd,\n                            haris_uint32_t *out_sz)\n{\n  return _public_from_fd(strct, &haris_lib_structures[%d],\n                           fd, 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_fd_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_fd(%s%s *strct, int fd, \n                          haris_uint32_t *out_sz)\n{\n  return _public_to_fd(strct, &haris_lib_structures[%d],\n                         fd, 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_fd(%s%s *strct, int fd,\n                            haris_uint32_t *out_sz)\n{\n  return _public_from_fd(strct, &haris_lib_structures[%d],\n                           fd, out_sz);\n}\n\n", prefix, name, prefix, name, strct->schema_index)) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

variable_types:
strct
struct _ParsedStruct *

variable_types:
prefix
char *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall write_fd_protocol_funcs(__int64 *a1)
{
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // r12
int v4; // er13

v1 = *a1;
result = write_fd_structures((__int64)a1);
if ( !(_DWORD)result )
{
result = write_static_fd_funcs((__int64)a1);
if ( !(_DWORD)result && *(int *)v1 > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
result = write_public_fd_funcs((__int64)a1, (const char **)(*(_QWORD *)(v1 + 8) + v3));
if ( (_DWORD)result )
break;
++v4;
v3 += 56LL;
}
while ( *(_DWORD *)v1 > v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // r12
int v4; // er13

v1 = *a1;
result = func0((__int64)a1);
if ( !(_DWORD)result )
{
result = func1((__int64)a1);
if ( !(_DWORD)result && *(int *)v1 > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
result = func2((__int64)a1, (const char **)(*(_QWORD *)(v1 + 8) + v3));
if ( (_DWORD)result )
break;
++v4;
v3 += 56LL;
}
while ( *(_DWORD *)v1 > v4 );
}
}
return result;
}

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

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

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; } *


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

v1 = strformat(
"typedef struct {\n"
" unsigned char *buffer;\n"
" haris_uint32_t curr;\n"
" haris_uint32_t sz;\n"
"} HarisBufferStream;\n"
"\n");
result = add_header_string(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

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

v1 = strformat(
"typedef struct {\n"
" unsigned char *buffer;\n"
" haris_uint32_t curr;\n"
" haris_uint32_t sz;\n"
"} HarisBufferStream;\n"
"\n");
result = add_header_string(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

original_code:
static CJobStatus write_buffer_structures(CJob *job)
{
  do { if (add_header_string(job, strformat("typedef struct {\n  unsigned char *buffer;\n  haris_uint32_t curr;\n  haris_uint32_t sz;\n} HarisBufferStream;\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_buffer_structures(struct CJob *job)
{
  do { if (add_header_string(job, strformat("typedef struct {\n  unsigned char *buffer;\n  haris_uint32_t curr;\n  haris_uint32_t sz;\n} HarisBufferStream;\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


decompiled_code:
__int64 __fastcall write_static_buffer_funcs(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax
int v9; // edx
__int64 v10; // 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");
v2 = add_private_function(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = 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");
v5 = add_private_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v6 = 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");
v7 = add_private_function(a1, v6);
result = 4LL;
if ( !v7 )
{
v8 = 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");
v9 = add_private_function(a1, v8);
result = 4LL;
if ( !v9 )
{
v10 = 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, v10);
if ( (_DWORD)result )
result = 4LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // rax
int v7; // edx
__int64 v8; // rax
int v9; // edx
__int64 v10; // 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");
v2 = add_private_function(a1, v1);
result = 4LL;
if ( !v2 )
{
v4 = 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");
v5 = add_private_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v6 = 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");
v7 = add_private_function(a1, v6);
result = 4LL;
if ( !v7 )
{
v8 = 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");
v9 = add_private_function(a1, v8);
result = 4LL;
if ( !v9 )
{
v10 = 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, v10);
if ( (_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;
}


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

v2 = *(const char **)(a1 + 8);
v3 = *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,
*a2,
v2,
*a2,
*((unsigned int *)a2 + 4));
v5 = add_public_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v7 = 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 + 4));
v8 = add_public_function(a1, v7);
result = 4LL;
if ( !v8 )
{
v9 = 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 + 4));
result = add_public_function(a1, v9);
if ( (_DWORD)result )
result = 4LL;
}
}
return result;
}

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

v2 = *(const char **)(a1 + 8);
v3 = *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,
*a2,
v2,
*a2,
*((unsigned int *)a2 + 4));
v5 = add_public_function(a1, v4);
result = 4LL;
if ( !v5 )
{
v7 = 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 + 4));
v8 = add_public_function(a1, v7);
result = 4LL;
if ( !v8 )
{
v9 = 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 + 4));
result = add_public_function(a1, v9);
if ( (_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;
}


decompiled_code:
__int64 __fastcall write_buffer_protocol_funcs(__int64 *a1)
{
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // r12
int v4; // er13

v1 = *a1;
result = write_buffer_structures((__int64)a1);
if ( !(_DWORD)result )
{
result = write_static_buffer_funcs((__int64)a1);
if ( !(_DWORD)result && *(int *)v1 > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
result = write_public_buffer_funcs((__int64)a1, (const char **)(*(_QWORD *)(v1 + 8) + v3));
if ( (_DWORD)result )
break;
++v4;
v3 += 56LL;
}
while ( *(_DWORD *)v1 > v4 );
}
}
return 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;
}


decompiled_code:
unsigned __int64 __fastcall hash_string(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 v2; // dl
unsigned __int64 v3; // rsi

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

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 v2; // dl
unsigned __int64 v3; // rsi

v1 = a1 + 1;
v2 = *a1;
if ( *a1 )
{
v3 = 5381LL;
do
{
v3 += 32 * v3 + v2;
v2 = *v1++;
}
while ( v2 );
}
else
{
v3 = 5381LL;
}
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


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 *

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; } *

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:
__int64 __fastcall add_text_to_hash(__int64 a1)
{
_QWORD *v1; // rbx
__int64 result; // rax
int v3; // eax

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

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

v1 = new_bucket((__int64)"Text");
result = 0LL;
if ( v1 )
{
*((_DWORD *)v1 + 2) = 3;
v3 = func0("Text");
func1(a1, (__int64)v1, 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: struct ScalarField { char *name; int offset; struct ScalarType type; }


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

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

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

result = func2(a1, "Uint8", 0);
if ( (_DWORD)result )
{
result = func2(a1, "Int8", 1);
if ( (_DWORD)result )
{
result = func2(a1, "Uint16", 2);
if ( (_DWORD)result )
{
result = func2(a1, "Int16", 3);
if ( (_DWORD)result )
{
result = func2(a1, "Uint32", 4);
if ( (_DWORD)result )
{
result = func2(a1, "Int32", 5);
if ( (_DWORD)result )
{
result = func2(a1, "Uint64", 6);
if ( (_DWORD)result )
{
result = func2(a1, "Int64", 7);
if ( (_DWORD)result )
{
result = func2(a1, "Bool", 10);
if ( (_DWORD)result )
{
result = func2(a1, "Float32", 8);
if ( (_DWORD)result )
{
result = func2(a1, "Float64", 9);
if ( (_DWORD)result )
result = (unsigned int)func3(a1) != 0;
}
}
}
}
}
}
}
}
}
}
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 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:
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;
}


decompiled_code:
void *create_typehash()
{
_QWORD *v0; // rax
void *v1; // rbx
_QWORD *v2; // rdx

v0 = malloc(0x158uLL);
v1 = v0;
if ( v0 )
{
v2 = v0 + 43;
do
*v0++ = 0LL;
while ( v0 != v2 );
if ( !(unsigned int)add_builtins_to_hash((__int64)v1) )
{
destroy_typehash(v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
void *func6()
{
_QWORD *v0; // rax
void *v1; // rbx
_QWORD *v2; // rdx

v0 = malloc(0x158uLL);
v1 = v0;
if ( v0 )
{
v2 = v0 + 43;
do
*v0++ = 0LL;
while ( v0 != v2 );
if ( !(unsigned int)func4((__int64)v1) )
{
func5(v1);
v1 = 0LL;
}
}
return v1;
}

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]; } *


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;
}


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)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 8LL * (int)hash_string(a2)); 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)
{
__int64 i; // rbx

for ( i = *(_QWORD *)(a1 + 8LL * (int)func0(a2)); 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(), !(_DWORD)result) )
{
if ( !a1[7] || (result = write_file_protocol_funcs(a1), !(_DWORD)result) )
{
result = 0LL;
if ( a1[8] )
result = 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(), !(_DWORD)result) )
{
if ( !a1[7] || (result = write_file_protocol_funcs(a1), !(_DWORD)result) )
{
result = 0LL;
if ( a1[8] )
result = 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;
}

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: 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; }


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: 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 CJobProtocols { int buffer; int file; int fd; }

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

user_defined_types: struct StructMetadata { unsigned long max_size; }

user_defined_types: struct ChildMetadata { int embeddable; }