initVolume

decompiled_code:
__int64 initVolume()
{
__m128i v0; // xmm0
int v1; // eax
__int64 v2; // rax
__int64 v4; // [rsp-10h] [rbp-18h]
__int64 v5; // [rsp-8h] [rbp-10h]

*((_QWORD *)&common_data + 12) = 0LL;
*((_QWORD *)&common_data + 13) = 0LL;
v0 = _mm_loadu_si128((const __m128i *)&common_data + 6);
*((_QWORD *)&common_data + 8) = LC8;
*((_QWORD *)&common_data + 5) = 0LL;
*((_QWORD *)&common_data + 6) = 0LL;
*((_QWORD *)&common_data + 3) = 0x6400000000LL;
*(&common_data + 5) = (struct timespec)v0;
if ( config_lookup(&config, "volume") )
{
validateConfigBool(&config, "volume.discrete", (unsigned int)((_DWORD)&common_data + 4), 1LL);
validateConfigInt(
&config,
"volume.timeout",
(unsigned int)((_DWORD)&common_data + 72),
0xFFFFFFFFLL,
0LL,
100LL,
0LL);
if ( HIDWORD(common_data.tv_sec) )
{
if ( (unsigned int)validateConfigInt(
&config,
"volume.min",
(unsigned int)((_DWORD)&common_data + 24),
0xFFFFFFFFLL,
0LL,
0LL,
-1LL) == 1 )
return 1LL;
v1 = validateConfigInt(
&config,
"volume.max",
(unsigned int)((_DWORD)&common_data + 28),
0xFFFFFFFFLL,
0LL,
0LL,
-1LL);
}
else
{
if ( strcmp("linear", *(const char **)(*((_QWORD *)&common_data + 18) + 24LL)) )
syslog(3, "[Error] Volume curve must be 'linear' when using relative volume control");
v1 = validateConfigInt(
&config,
"volume.multiplier",
(unsigned int)((_DWORD)&common_data + 76),
0xFFFFFFFFLL,
1LL,
100LL,
1LL);
}
if ( v1 != 1 )
{
if ( (unsigned int)validateConfigInt(
&config,
"volume.default",
(unsigned int)((_DWORD)&common_data + 168),
0xFFFFFFFFLL,
*((unsigned int *)&common_data + 6),
*((unsigned int *)&common_data + 7),
-2LL) == 1 )
{
*((_DWORD *)&common_data + 42) = *((_DWORD *)&common_data + 6) - 1;
v2 = *(_QWORD *)(*((_QWORD *)&common_data + 19) + 8LL);
if ( !v2 )
goto LABEL_10;
}
else
{
v2 = *(_QWORD *)(*((_QWORD *)&common_data + 19) + 8LL);
if ( !v2 )
{
LABEL_10:
*((_QWORD *)&common_data + 4) = *((_QWORD *)&common_data + 3);
return 0LL;
}
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64))(v2 + 16))(v5, v4) != 1 )
goto LABEL_10;
}
return 1LL;
}
syslog(3, "[Error] Category 'volume' is not present");
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
__m128i v0; // xmm0
int v1; // eax
__int64 v2; // rax
__int64 v4; // [rsp-10h] [rbp-18h]
__int64 v5; // [rsp-8h] [rbp-10h]

*((_QWORD *)&common_data + 12) = 0LL;
*((_QWORD *)&common_data + 13) = 0LL;
v0 = _mm_loadu_si128((const __m128i *)&common_data + 6);
*((_QWORD *)&common_data + 8) = LC8;
*((_QWORD *)&common_data + 5) = 0LL;
*((_QWORD *)&common_data + 6) = 0LL;
*((_QWORD *)&common_data + 3) = 0x6400000000LL;
*(&common_data + 5) = (struct timespec)v0;
if ( config_lookup(&config, "volume") )
{
validateConfigBool(&config, "volume.discrete", (unsigned int)((_DWORD)&common_data + 4), 1LL);
validateConfigInt(
&config,
"volume.timeout",
(unsigned int)((_DWORD)&common_data + 72),
0xFFFFFFFFLL,
0LL,
100LL,
0LL);
if ( HIDWORD(common_data.tv_sec) )
{
if ( (unsigned int)validateConfigInt(
&config,
"volume.min",
(unsigned int)((_DWORD)&common_data + 24),
0xFFFFFFFFLL,
0LL,
0LL,
-1LL) == 1 )
return 1LL;
v1 = validateConfigInt(
&config,
"volume.max",
(unsigned int)((_DWORD)&common_data + 28),
0xFFFFFFFFLL,
0LL,
0LL,
-1LL);
}
else
{
if ( strcmp("linear", *(const char **)(*((_QWORD *)&common_data + 18) + 24LL)) )
syslog(3, "[Error] Volume curve must be 'linear' when using relative volume control");
v1 = validateConfigInt(
&config,
"volume.multiplier",
(unsigned int)((_DWORD)&common_data + 76),
0xFFFFFFFFLL,
1LL,
100LL,
1LL);
}
if ( v1 != 1 )
{
if ( (unsigned int)validateConfigInt(
&config,
"volume.default",
(unsigned int)((_DWORD)&common_data + 168),
0xFFFFFFFFLL,
*((unsigned int *)&common_data + 6),
*((unsigned int *)&common_data + 7),
-2LL) == 1 )
{
*((_DWORD *)&common_data + 42) = *((_DWORD *)&common_data + 6) - 1;
v2 = *(_QWORD *)(*((_QWORD *)&common_data + 19) + 8LL);
if ( !v2 )
goto LABEL_10;
}
else
{
v2 = *(_QWORD *)(*((_QWORD *)&common_data + 19) + 8LL);
if ( !v2 )
{
LABEL_10:
*((_QWORD *)&common_data + 4) = *((_QWORD *)&common_data + 3);
return 0LL;
}
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64))(v2 + 16))(v5, v4) != 1 )
goto LABEL_10;
}
return 1LL;
}
syslog(3, "[Error] Category 'volume' is not present");
return 1LL;
}

original_code:
static int initVolume(void) {
    common_data.volume_level_status = -1;
    common_data.timestampLastRX = common_data.timestampLastTX = (struct timespec) { 0, 0 };
    common_data.alsa_volume_max = common_data.alsa_volume_min = 0;
    config_setting_t *conf_setting = ((void *)0);
    int int_setting = -1;
    common_data.volume_min = 0;
    common_data.volume_max = 100;
    if(config_lookup(&config, "volume") == ((void *)0)) {
        syslog(3, "[Error] Category 'volume' is not present");
        return 1;
    }
    validateConfigBool(&config, "volume.discrete", &common_data.discrete_volume, 1);
    validateConfigInt(&config, "volume.timeout", &common_data.volume_timeout, -1, 0, 100, 0);
    if(!common_data.discrete_volume) {
        if(strcmp("linear", common_data.volume->curve) != 0)
            syslog(3, "[Error] Volume curve must be 'linear' when using relative volume control");
        if(validateConfigInt(&config, "volume.multiplier", &common_data.nd_vol_multiplier, -1, 1, 100, 1) == 1)
            return 1;
    }
    else {
        if(validateConfigInt(&config, "volume.min", &common_data.volume_min, -1, 0, 0, -1) == 1)
            return 1;
        if(validateConfigInt(&config, "volume.max", &common_data.volume_max, -1, 0, 0, -1) == 1)
            return 1;
    }
    if(validateConfigInt(&config, "volume.default", &common_data.defaultExternalVolume, -1,
    common_data.volume_min, common_data.volume_max, -2) == 1)
        common_data.defaultExternalVolume = common_data.volume_min-1;
    if(common_data.mod->volumeResponse) {
        if(common_data.mod->volumeResponse->init() == 1)
            return 1;
    }
    common_data.initial_volume_min = common_data.volume_min;
    common_data.initial_volume_max = common_data.volume_max;
    return 0;
}

canonical_original_code:
static int initVolume() {
    common_data.volume_level_status = -1;
    common_data.timestampLastRX = common_data.timestampLastTX = (struct timespec) { 0, 0 };
    common_data.alsa_volume_max = common_data.alsa_volume_min = 0;
    struct config_setting_t *conf_setting = ((void *)0);
    int int_setting = -1;
    common_data.volume_min = 0;
    common_data.volume_max = 100;
    if(config_lookup(&config, "volume") == ((void *)0)) {
        syslog(3, "[Error] Category 'volume' is not present");
        return 1;
    }
    validateConfigBool(&config, "volume.discrete", &common_data.discrete_volume, 1);
    validateConfigInt(&config, "volume.timeout", &common_data.volume_timeout, -1, 0, 100, 0);
    if(!common_data.discrete_volume) {
        if(strcmp("linear", common_data.volume->curve) != 0)
            syslog(3, "[Error] Volume curve must be 'linear' when using relative volume control");
        if(validateConfigInt(&config, "volume.multiplier", &common_data.nd_vol_multiplier, -1, 1, 100, 1) == 1)
            return 1;
    }
    else {
        if(validateConfigInt(&config, "volume.min", &common_data.volume_min, -1, 0, 0, -1) == 1)
            return 1;
        if(validateConfigInt(&config, "volume.max", &common_data.volume_max, -1, 0, 0, -1) == 1)
            return 1;
    }
    if(validateConfigInt(&config, "volume.default", &common_data.defaultExternalVolume, -1,
    common_data.volume_min, common_data.volume_max, -2) == 1)
        common_data.defaultExternalVolume = common_data.volume_min-1;
    if(common_data.mod->volumeResponse) {
        if(common_data.mod->volumeResponse->init() == 1)
            return 1;
    }
    common_data.initial_volume_min = common_data.volume_min;
    common_data.initial_volume_max = common_data.volume_max;
    return 0;
}

variable_types: struct config_setting_t { char *name; short type; short format; union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t { unsigned int length; struct config_setting_t **elements; } *list; } value; struct config_setting_t *parent; struct config_t { struct config_setting_t *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t { CONFIG_ERR_NONE=0, CONFIG_ERR_FILE_IO=1, CONFIG_ERR_PARSE=2 } error_type; char **filenames; unsigned int num_filenames; } *config; void *hook; unsigned int line; char *file; } *


getInterface

repo: therealmuffin/synchronator

decompiled_code:
const char **__fastcall getInterface(const char **a1)
{
const char **v1; // r12
const char *v2; // rbp
void **v3; // rbx

v1 = (const char **)list_interfaces;
v2 = *a1;
if ( *a1 )
{
if ( !list_interfaces )
return 0LL;
}
else
{
v2 = (const char *)*((_QWORD *)list_interfaces + 1);
*a1 = v2;
}
v3 = &list_interfaces;
while ( strcasecmp(v2, v1[1]) )
{
v1 = (const char **)v3[1];
++v3;
if ( !v1 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
const char **__fastcall func0(const char **a1)
{
const char **v1; // r12
const char *v2; // rbp
void **v3; // rbx

v1 = (const char **)list_interfaces;
v2 = *a1;
if ( *a1 )
{
if ( !list_interfaces )
return 0LL;
}
else
{
v2 = (const char *)*((_QWORD *)list_interfaces + 1);
*a1 = v2;
}
v3 = &list_interfaces;
while ( strcasecmp(v2, v1[1]) )
{
v1 = (const char **)v3[1];
++v3;
if ( !v1 )
return 0LL;
}
return v1;
}

original_code:
interface_t *getInterface(const char **name) {
    interface_t **interface;
    if (!*name)
        *name = list_interfaces[0]->name;
    for (interface=list_interfaces; *interface; interface++)
        if (!strcasecmp(*name, (*interface)->name))
            return *interface;
    return ((void *)0);
}

canonical_original_code:
struct interface_t *getInterface(char **name) {
    struct interface_t **interface;
    if (!*name)
        *name = list_interfaces[0]->name;
    for (interface=list_interfaces; *interface; interface++)
        if (!strcasecmp(*name, (*interface)->name))
            return *interface;
    return ((void *)0);
}

variable_types:
name
char **

variable_types: struct interface_t { void (*help)(); char *name; int (*init)(); int (*deinit)(); int (*reply)(void *message, unsigned long messageLength); int (*send)(void *message, unsigned long messageLength); void *(*listen)(void *arg); } **


repo: theseoafs/haris

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

v1 = strformat(
"static void haris_lib_write_scalar(unsigned char *message, const void *src,\n"
" HarisScalarType type)\n"
"{\n"
" haris_lib_scalar_writers[type](message, src);\n"
"}\n"
"\n");
result = add_private_function(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(
"static void haris_lib_write_scalar(unsigned char *message, const void *src,\n"
" HarisScalarType type)\n"
"{\n"
" haris_lib_scalar_writers[type](message, src);\n"
"}\n"
"\n");
result = add_private_function(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

original_code:
static CJobStatus write_scalar_writer_function(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_lib_write_scalar(unsigned char *message, const void *src,\n                                    HarisScalarType type)\n{\n  haris_lib_scalar_writers[type](message, src);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_scalar_writer_function(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_lib_write_scalar(unsigned char *message, const void *src,\n                                    HarisScalarType type)\n{\n  haris_lib_scalar_writers[type](message, src);\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_reader_function(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = strformat(
"static void haris_lib_read_scalar(const unsigned char *message, void *src,\n"
" HarisScalarType type)\n"
"{\n"
" haris_lib_scalar_readers[type](message, src);\n"
"}\n"
"\n");
result = add_private_function(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

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

v1 = strformat(
"static void haris_lib_read_scalar(const unsigned char *message, void *src,\n"
" HarisScalarType type)\n"
"{\n"
" haris_lib_scalar_readers[type](message, src);\n"
"}\n"
"\n");
result = add_private_function(a1, v1);
if ( (_DWORD)result )
result = 4LL;
return result;
}

original_code:
static CJobStatus write_scalar_reader_function(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_lib_read_scalar(const unsigned char *message, void *src,\n                                   HarisScalarType type)\n{\n  haris_lib_scalar_readers[type](message, src);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_scalar_reader_function(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_lib_read_scalar(const unsigned char *message, void *src,\n                                   HarisScalarType type)\n{\n  haris_lib_scalar_readers[type](message, src);\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_writefloat(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = strformat(
"static void haris_write_float32(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_float32 f = *(const haris_float32*)_ptr;\n"
" haris_float64 fnorm;\n"
" int shift;\n"
" const int float32_sigbits = 23;\n"
" long sign, exp, significand;\n"
" haris_uint32_t result;\n"
"\n"
" if (f == 0.0) {\n"
" result = 0.0;\n"
" goto Finish;\n"
" } \n"
"\n"
" if (f < 0) {\n"
" sign = 1; \n"
" fnorm = -f; \n"
" } else { \n"
" sign = 0; \n"
" fnorm = f; \n"
" }\n"
"\n"
" shift = 0;\n"
" while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n"
" while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n"
" fnorm = fnorm - 1.0;\n"
"\n"
" significand = fnorm * (((haris_uint32_t)1 << float32_sigbits)\n"
" + 0.5f);\n"
"\n"
" exp = shift + ((1<<7) - 1); \n"
"\n"
" result = (sign<<31) | (exp<<23) | significand;\n"
" Finish:\n"
" haris_write_uint32(b, &result);\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_write_float64(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_float64 fnorm, f = *(const haris_float64*)_ptr;\n"
" const int float64_sigbits = 52;\n"
" int shift;\n"
" long sign, exp, significand;\n"
" haris_uint64_t result;\n"
"\n"
" if (f == 0.0) {\n"
" result = 0.0;\n"
" goto Finish;\n"
" }\n"
"\n"
" if (f < 0) {\n"
" sign = 1; \n"
" fnorm = -f; \n"
" } else { \n"
" sign = 0; \n"
" fnorm = f; \n"
" }\n"
"\n"
" shift = 0;\n"
" while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n"
" while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n"
" fnorm = fnorm - 1.0;\n"
"\n"
" significand = fnorm * (((haris_uint64_t)1<<float64_sigbits)\n"
" + 0.5f);\n"
"\n"
" exp = shift + ((1<<10) - 1); \n"
"\n"
" result = (sign<<63) | (exp<<52) | significand;\n"
" Finish:\n"
" haris_write_uint64(b, &result);\n"
"}\n"
"\n"),
result = add_private_function(a1, v2),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v1 = strformat(
"static void haris_write_float32(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_float32 f = *(const haris_float32*)_ptr;\n"
" haris_float64 fnorm;\n"
" int shift;\n"
" const int float32_sigbits = 23;\n"
" long sign, exp, significand;\n"
" haris_uint32_t result;\n"
"\n"
" if (f == 0.0) {\n"
" result = 0.0;\n"
" goto Finish;\n"
" } \n"
"\n"
" if (f < 0) {\n"
" sign = 1; \n"
" fnorm = -f; \n"
" } else { \n"
" sign = 0; \n"
" fnorm = f; \n"
" }\n"
"\n"
" shift = 0;\n"
" while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n"
" while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n"
" fnorm = fnorm - 1.0;\n"
"\n"
" significand = fnorm * (((haris_uint32_t)1 << float32_sigbits)\n"
" + 0.5f);\n"
"\n"
" exp = shift + ((1<<7) - 1); \n"
"\n"
" result = (sign<<31) | (exp<<23) | significand;\n"
" Finish:\n"
" haris_write_uint32(b, &result);\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_write_float64(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_float64 fnorm, f = *(const haris_float64*)_ptr;\n"
" const int float64_sigbits = 52;\n"
" int shift;\n"
" long sign, exp, significand;\n"
" haris_uint64_t result;\n"
"\n"
" if (f == 0.0) {\n"
" result = 0.0;\n"
" goto Finish;\n"
" }\n"
"\n"
" if (f < 0) {\n"
" sign = 1; \n"
" fnorm = -f; \n"
" } else { \n"
" sign = 0; \n"
" fnorm = f; \n"
" }\n"
"\n"
" shift = 0;\n"
" while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n"
" while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n"
" fnorm = fnorm - 1.0;\n"
"\n"
" significand = fnorm * (((haris_uint64_t)1<<float64_sigbits)\n"
" + 0.5f);\n"
"\n"
" exp = shift + ((1<<10) - 1); \n"
"\n"
" result = (sign<<63) | (exp<<52) | significand;\n"
" Finish:\n"
" haris_write_uint64(b, &result);\n"
"}\n"
"\n"),
result = add_private_function(a1, v2),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_writefloat(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_write_float32(unsigned char *b, const void *_ptr)\n{\n  haris_float32 f = *(const haris_float32*)_ptr;\n  haris_float64 fnorm;\n  int shift;\n  const int float32_sigbits = 23;\n  long sign, exp, significand;\n  haris_uint32_t result;\n\n  if (f == 0.0) {\n    result = 0.0;\n    goto Finish;\n  } \n\n  if (f < 0) {\n    sign = 1; \n    fnorm = -f; \n  } else { \n    sign = 0; \n    fnorm = f; \n  }\n\n  shift = 0;\n  while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n  while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n  fnorm = fnorm - 1.0;\n\n  significand = fnorm * (((haris_uint32_t)1 << float32_sigbits)\n                          + 0.5f);\n\n  exp = shift + ((1<<7) - 1); \n\n  result = (sign<<31) | (exp<<23) | significand;\n  Finish:\n  haris_write_uint32(b, &result);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_float64(unsigned char *b, const void *_ptr)\n{\n  haris_float64 fnorm, f = *(const haris_float64*)_ptr;\n  const int float64_sigbits = 52;\n  int shift;\n  long sign, exp, significand;\n  haris_uint64_t result;\n\n  if (f == 0.0) {\n    result = 0.0;\n    goto Finish;\n  }\n\n  if (f < 0) {\n    sign = 1; \n    fnorm = -f; \n  } else { \n    sign = 0; \n    fnorm = f; \n  }\n\n  shift = 0;\n  while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n  while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n  fnorm = fnorm - 1.0;\n\n  significand = fnorm * (((haris_uint64_t)1<<float64_sigbits)\n                         + 0.5f);\n\n  exp = shift + ((1<<10) - 1); \n\n  result = (sign<<63) | (exp<<52) | significand;\n  Finish:\n  haris_write_uint64(b, &result);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_writefloat(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_write_float32(unsigned char *b, const void *_ptr)\n{\n  haris_float32 f = *(const haris_float32*)_ptr;\n  haris_float64 fnorm;\n  int shift;\n  const int float32_sigbits = 23;\n  long sign, exp, significand;\n  haris_uint32_t result;\n\n  if (f == 0.0) {\n    result = 0.0;\n    goto Finish;\n  } \n\n  if (f < 0) {\n    sign = 1; \n    fnorm = -f; \n  } else { \n    sign = 0; \n    fnorm = f; \n  }\n\n  shift = 0;\n  while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n  while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n  fnorm = fnorm - 1.0;\n\n  significand = fnorm * (((haris_uint32_t)1 << float32_sigbits)\n                          + 0.5f);\n\n  exp = shift + ((1<<7) - 1); \n\n  result = (sign<<31) | (exp<<23) | significand;\n  Finish:\n  haris_write_uint32(b, &result);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_float64(unsigned char *b, const void *_ptr)\n{\n  haris_float64 fnorm, f = *(const haris_float64*)_ptr;\n  const int float64_sigbits = 52;\n  int shift;\n  long sign, exp, significand;\n  haris_uint64_t result;\n\n  if (f == 0.0) {\n    result = 0.0;\n    goto Finish;\n  }\n\n  if (f < 0) {\n    sign = 1; \n    fnorm = -f; \n  } else { \n    sign = 0; \n    fnorm = f; \n  }\n\n  shift = 0;\n  while (fnorm >= 2.0) { fnorm /= 2.0; shift++; }\n  while (fnorm < 1.0) { fnorm *= 2.0; shift--; }\n  fnorm = fnorm - 1.0;\n\n  significand = fnorm * (((haris_uint64_t)1<<float64_sigbits)\n                         + 0.5f);\n\n  exp = shift + ((1<<10) - 1); \n\n  result = (sign<<63) | (exp<<52) | significand;\n  Finish:\n  haris_write_uint64(b, &result);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


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

v1 = strformat(
"static void haris_read_float32(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_float32 *ptr = (haris_float32*)_ptr;\n"
" const int float32_sigbits = 23, float32_bias = 127;\n"
" haris_float64 result;\n"
" haris_int64_t shift;\n"
" haris_uint32_t i;\n"
" haris_read_uint32(b, &i);\n"
" \n"
" if (i == 0) { *ptr = 0.0; return; }\n"
" \n"
" result = (i & (((haris_uint32_t)1 << float32_sigbits) - 1));\n"
" result /= ((haris_uint32_t)1 << float32_sigbits); \n"
" result += 1.0;\n"
"\n"
" shift = ((i >> float32_sigbits) & 255) - float32_bias;\n"
" while (shift > 0) { result *= 2.0; shift--; }\n"
" while (shift < 0) { result /= 2.0; shift++; }\n"
"\n"
" result *= (i >> 31) & 1 ? -1.0: 1.0;\n"
"\n"
" *ptr = (haris_float32)result;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_read_float64(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_float64 result, *ptr = (haris_float64*)_ptr;\n"
" const int float64_sigbits = 52, float64_bias = 1023;\n"
" haris_int64_t shift;\n"
" haris_uint64_t i;\n"
" haris_read_uint64(b, &i);\n"
" \n"
" if (i == 0) { *ptr = 0.0; return; }\n"
" \n"
" result = (i & (((haris_uint64_t)1 << float64_sigbits) - 1));\n"
" result /= ((haris_uint64_t)1 << float64_sigbits); \n"
" result += 1.0;\n"
"\n"
" shift = ((i >> float64_sigbits) & 2047) - float64_bias;\n"
" while (shift > 0) { result *= 2.0; shift--; }\n"
" while (shift < 0) { result /= 2.0; shift++; }\n"
"\n"
" result *= (i >> 63) & 1 ? -1.0: 1.0;\n"
"\n"
" *ptr = result;\n"
"}\n"
"\n"),
result = add_private_function(a1, v2),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v1 = strformat(
"static void haris_read_float32(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_float32 *ptr = (haris_float32*)_ptr;\n"
" const int float32_sigbits = 23, float32_bias = 127;\n"
" haris_float64 result;\n"
" haris_int64_t shift;\n"
" haris_uint32_t i;\n"
" haris_read_uint32(b, &i);\n"
" \n"
" if (i == 0) { *ptr = 0.0; return; }\n"
" \n"
" result = (i & (((haris_uint32_t)1 << float32_sigbits) - 1));\n"
" result /= ((haris_uint32_t)1 << float32_sigbits); \n"
" result += 1.0;\n"
"\n"
" shift = ((i >> float32_sigbits) & 255) - float32_bias;\n"
" while (shift > 0) { result *= 2.0; shift--; }\n"
" while (shift < 0) { result /= 2.0; shift++; }\n"
"\n"
" result *= (i >> 31) & 1 ? -1.0: 1.0;\n"
"\n"
" *ptr = (haris_float32)result;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_read_float64(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_float64 result, *ptr = (haris_float64*)_ptr;\n"
" const int float64_sigbits = 52, float64_bias = 1023;\n"
" haris_int64_t shift;\n"
" haris_uint64_t i;\n"
" haris_read_uint64(b, &i);\n"
" \n"
" if (i == 0) { *ptr = 0.0; return; }\n"
" \n"
" result = (i & (((haris_uint64_t)1 << float64_sigbits) - 1));\n"
" result /= ((haris_uint64_t)1 << float64_sigbits); \n"
" result += 1.0;\n"
"\n"
" shift = ((i >> float64_sigbits) & 2047) - float64_bias;\n"
" while (shift > 0) { result *= 2.0; shift--; }\n"
" while (shift < 0) { result /= 2.0; shift++; }\n"
"\n"
" result *= (i >> 63) & 1 ? -1.0: 1.0;\n"
"\n"
" *ptr = result;\n"
"}\n"
"\n"),
result = add_private_function(a1, v2),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_readfloat(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_read_float32(const unsigned char *b, void *_ptr)\n{\n  haris_float32 *ptr = (haris_float32*)_ptr;\n  const int float32_sigbits = 23, float32_bias = 127;\n  haris_float64 result;\n  haris_int64_t shift;\n  haris_uint32_t i;\n  haris_read_uint32(b, &i);\n  \n  if (i == 0) { *ptr = 0.0; return; }\n  \n  result = (i & (((haris_uint32_t)1 << float32_sigbits) - 1));\n  result /= ((haris_uint32_t)1 << float32_sigbits); \n  result += 1.0;\n\n  shift = ((i >> float32_sigbits) & 255) - float32_bias;\n  while (shift > 0) { result *= 2.0; shift--; }\n  while (shift < 0) { result /= 2.0; shift++; }\n\n  result *= (i >> 31) & 1 ? -1.0: 1.0;\n\n  *ptr = (haris_float32)result;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_float64(const unsigned char *b, void *_ptr)\n{\n  haris_float64 result, *ptr = (haris_float64*)_ptr;\n  const int float64_sigbits = 52, float64_bias = 1023;\n  haris_int64_t shift;\n  haris_uint64_t i;\n  haris_read_uint64(b, &i);\n  \n  if (i == 0) { *ptr = 0.0; return; }\n  \n  result = (i & (((haris_uint64_t)1 << float64_sigbits) - 1));\n  result /= ((haris_uint64_t)1 << float64_sigbits); \n  result += 1.0;\n\n  shift = ((i >> float64_sigbits) & 2047) - float64_bias;\n  while (shift > 0) { result *= 2.0; shift--; }\n  while (shift < 0) { result /= 2.0; shift++; }\n\n  result *= (i >> 63) & 1 ? -1.0: 1.0;\n\n  *ptr = result;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_readfloat(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_read_float32(const unsigned char *b, void *_ptr)\n{\n  haris_float32 *ptr = (haris_float32*)_ptr;\n  const int float32_sigbits = 23, float32_bias = 127;\n  haris_float64 result;\n  haris_int64_t shift;\n  haris_uint32_t i;\n  haris_read_uint32(b, &i);\n  \n  if (i == 0) { *ptr = 0.0; return; }\n  \n  result = (i & (((haris_uint32_t)1 << float32_sigbits) - 1));\n  result /= ((haris_uint32_t)1 << float32_sigbits); \n  result += 1.0;\n\n  shift = ((i >> float32_sigbits) & 255) - float32_bias;\n  while (shift > 0) { result *= 2.0; shift--; }\n  while (shift < 0) { result /= 2.0; shift++; }\n\n  result *= (i >> 31) & 1 ? -1.0: 1.0;\n\n  *ptr = (haris_float32)result;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_float64(const unsigned char *b, void *_ptr)\n{\n  haris_float64 result, *ptr = (haris_float64*)_ptr;\n  const int float64_sigbits = 52, float64_bias = 1023;\n  haris_int64_t shift;\n  haris_uint64_t i;\n  haris_read_uint64(b, &i);\n  \n  if (i == 0) { *ptr = 0.0; return; }\n  \n  result = (i & (((haris_uint64_t)1 << float64_sigbits) - 1));\n  result /= ((haris_uint64_t)1 << float64_sigbits); \n  result += 1.0;\n\n  shift = ((i >> float64_sigbits) & 2047) - float64_bias;\n  while (shift > 0) { result *= 2.0; shift--; }\n  while (shift < 0) { result /= 2.0; shift++; }\n\n  result *= (i >> 63) & 1 ? -1.0: 1.0;\n\n  *ptr = result;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


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

v1 = strformat(
"static void haris_write_uint8(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint8_t i = *(const haris_uint8_t*)_ptr;\n"
" *b = i;\n"
" return;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_write_uint16(unsigned char *b, const void *_ptr)\n"
"{ \n"
" haris_uint16_t i = *(const haris_uint16_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static void haris_write_uint24(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" *(b+2) = i >> 16;\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static void haris_write_uint32(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" *(b+2) = i >> 16;\n"
" *(b+3) = i >> 24;\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = strformat(
"static void haris_write_uint64(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint64_t i = *(const haris_uint64_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" *(b+2) = i >> 16;\n"
" *(b+3) = i >> 24;\n"
" *(b+4) = i >> 32;\n"
" *(b+5) = i >> 40;\n"
" *(b+6) = i >> 48;\n"
" *(b+7) = i >> 56;\n"
" return;\n"
"}\n"
"\n"),
result = add_private_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v1 = strformat(
"static void haris_write_uint8(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint8_t i = *(const haris_uint8_t*)_ptr;\n"
" *b = i;\n"
" return;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_write_uint16(unsigned char *b, const void *_ptr)\n"
"{ \n"
" haris_uint16_t i = *(const haris_uint16_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static void haris_write_uint24(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" *(b+2) = i >> 16;\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static void haris_write_uint32(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" *(b+2) = i >> 16;\n"
" *(b+3) = i >> 24;\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = strformat(
"static void haris_write_uint64(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_uint64_t i = *(const haris_uint64_t*)_ptr;\n"
" *b = i;\n"
" *(b+1) = i >> 8;\n"
" *(b+2) = i >> 16;\n"
" *(b+3) = i >> 24;\n"
" *(b+4) = i >> 32;\n"
" *(b+5) = i >> 40;\n"
" *(b+6) = i >> 48;\n"
" *(b+7) = i >> 56;\n"
" return;\n"
"}\n"
"\n"),
result = add_private_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_writeuint(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_write_uint8(unsigned char *b, const void *_ptr)\n{\n  haris_uint8_t i = *(const haris_uint8_t*)_ptr;\n  *b = i;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint16(unsigned char *b, const void *_ptr)\n{  \n  haris_uint16_t i = *(const haris_uint16_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint24(unsigned char *b, const void *_ptr)\n{\n  haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  *(b+2) = i >> 16;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint32(unsigned char *b, const void *_ptr)\n{\n  haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  *(b+2) = i >> 16;\n  *(b+3) = i >> 24;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint64(unsigned char *b, const void *_ptr)\n{\n  haris_uint64_t i = *(const haris_uint64_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  *(b+2) = i >> 16;\n  *(b+3) = i >> 24;\n  *(b+4) = i >> 32;\n  *(b+5) = i >> 40;\n  *(b+6) = i >> 48;\n  *(b+7) = i >> 56;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_writeuint(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_write_uint8(unsigned char *b, const void *_ptr)\n{\n  haris_uint8_t i = *(const haris_uint8_t*)_ptr;\n  *b = i;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint16(unsigned char *b, const void *_ptr)\n{  \n  haris_uint16_t i = *(const haris_uint16_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint24(unsigned char *b, const void *_ptr)\n{\n  haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  *(b+2) = i >> 16;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint32(unsigned char *b, const void *_ptr)\n{\n  haris_uint32_t i = *(const haris_uint32_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  *(b+2) = i >> 16;\n  *(b+3) = i >> 24;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_uint64(unsigned char *b, const void *_ptr)\n{\n  haris_uint64_t i = *(const haris_uint64_t*)_ptr;\n  *b = i;\n  *(b+1) = i >> 8;\n  *(b+2) = i >> 16;\n  *(b+3) = i >> 24;\n  *(b+4) = i >> 32;\n  *(b+5) = i >> 40;\n  *(b+6) = i >> 48;\n  *(b+7) = i >> 56;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


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

v1 = strformat(
"static void haris_write_int8(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int8_t i = *(const haris_int8_t*)_ptr;\n"
" if (i >= 0)\n"
" *b = (unsigned char)i;\n"
" else\n"
" *b = ~(unsigned char)(-i) + (unsigned char)1;\n"
" return;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_write_int16(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int16_t i = *(const haris_int16_t*)_ptr;\n"
" haris_uint16_t ui;\n"
" if (i >= 0)\n"
" ui = (haris_uint16_t)i;\n"
" else\n"
" ui = ~(haris_uint16_t)(-i) + 1;\n"
" haris_write_uint16(b, &ui);\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static void haris_write_int32(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int32_t i = *(const haris_int32_t*)_ptr;\n"
" haris_uint32_t ui;\n"
" if (i >= 0)\n"
" ui = (haris_uint32_t)i;\n"
" else\n"
" ui = ~(haris_uint32_t)(-i) + 1;\n"
" haris_write_uint32(b, &ui);\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static void haris_write_int64(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int64_t i = *(const haris_int64_t*)_ptr;\n"
" haris_uint64_t ui;\n"
" if (i >= 0)\n"
" ui = (haris_uint64_t)i;\n"
" else\n"
" ui = ~(haris_uint64_t)(-i) + 1;\n"
" haris_write_uint64(b, &ui);\n"
" return;\n"
"}\n"
"\n"),
result = add_private_function(a1, v4),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v1 = strformat(
"static void haris_write_int8(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int8_t i = *(const haris_int8_t*)_ptr;\n"
" if (i >= 0)\n"
" *b = (unsigned char)i;\n"
" else\n"
" *b = ~(unsigned char)(-i) + (unsigned char)1;\n"
" return;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_write_int16(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int16_t i = *(const haris_int16_t*)_ptr;\n"
" haris_uint16_t ui;\n"
" if (i >= 0)\n"
" ui = (haris_uint16_t)i;\n"
" else\n"
" ui = ~(haris_uint16_t)(-i) + 1;\n"
" haris_write_uint16(b, &ui);\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static void haris_write_int32(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int32_t i = *(const haris_int32_t*)_ptr;\n"
" haris_uint32_t ui;\n"
" if (i >= 0)\n"
" ui = (haris_uint32_t)i;\n"
" else\n"
" ui = ~(haris_uint32_t)(-i) + 1;\n"
" haris_write_uint32(b, &ui);\n"
" return;\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static void haris_write_int64(unsigned char *b, const void *_ptr)\n"
"{\n"
" haris_int64_t i = *(const haris_int64_t*)_ptr;\n"
" haris_uint64_t ui;\n"
" if (i >= 0)\n"
" ui = (haris_uint64_t)i;\n"
" else\n"
" ui = ~(haris_uint64_t)(-i) + 1;\n"
" haris_write_uint64(b, &ui);\n"
" return;\n"
"}\n"
"\n"),
result = add_private_function(a1, v4),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_writeint(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_write_int8(unsigned char *b, const void *_ptr)\n{\n  haris_int8_t i = *(const haris_int8_t*)_ptr;\n  if (i >= 0)\n    *b = (unsigned char)i;\n  else\n    *b = ~(unsigned char)(-i) + (unsigned char)1;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_int16(unsigned char *b, const void *_ptr)\n{\n  haris_int16_t i = *(const haris_int16_t*)_ptr;\n  haris_uint16_t ui;\n  if (i >= 0)\n    ui = (haris_uint16_t)i;\n  else\n    ui = ~(haris_uint16_t)(-i) + 1;\n  haris_write_uint16(b, &ui);\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_int32(unsigned char *b, const void *_ptr)\n{\n  haris_int32_t i = *(const haris_int32_t*)_ptr;\n  haris_uint32_t ui;\n  if (i >= 0)\n    ui = (haris_uint32_t)i;\n  else\n    ui = ~(haris_uint32_t)(-i) + 1;\n  haris_write_uint32(b, &ui);\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_int64(unsigned char *b, const void *_ptr)\n{\n  haris_int64_t i = *(const haris_int64_t*)_ptr;\n  haris_uint64_t ui;\n  if (i >= 0)\n    ui = (haris_uint64_t)i;\n  else\n    ui = ~(haris_uint64_t)(-i) + 1;\n  haris_write_uint64(b, &ui);\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_writeint(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_write_int8(unsigned char *b, const void *_ptr)\n{\n  haris_int8_t i = *(const haris_int8_t*)_ptr;\n  if (i >= 0)\n    *b = (unsigned char)i;\n  else\n    *b = ~(unsigned char)(-i) + (unsigned char)1;\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_int16(unsigned char *b, const void *_ptr)\n{\n  haris_int16_t i = *(const haris_int16_t*)_ptr;\n  haris_uint16_t ui;\n  if (i >= 0)\n    ui = (haris_uint16_t)i;\n  else\n    ui = ~(haris_uint16_t)(-i) + 1;\n  haris_write_uint16(b, &ui);\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_int32(unsigned char *b, const void *_ptr)\n{\n  haris_int32_t i = *(const haris_int32_t*)_ptr;\n  haris_uint32_t ui;\n  if (i >= 0)\n    ui = (haris_uint32_t)i;\n  else\n    ui = ~(haris_uint32_t)(-i) + 1;\n  haris_write_uint32(b, &ui);\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_write_int64(unsigned char *b, const void *_ptr)\n{\n  haris_int64_t i = *(const haris_int64_t*)_ptr;\n  haris_uint64_t ui;\n  if (i >= 0)\n    ui = (haris_uint64_t)i;\n  else\n    ui = ~(haris_uint64_t)(-i) + 1;\n  haris_write_uint64(b, &ui);\n  return;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


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

v1 = strformat(
"static void haris_read_uint8(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint8_t *ptr = (haris_uint8_t*)_ptr;\n"
" *ptr = *b;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_read_uint16(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint16_t *ptr = (haris_uint16_t*)_ptr;\n"
" *ptr = ((haris_uint16_t)b[0]) | ((haris_uint16_t)b[1] << 8);\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static void haris_read_uint24(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n"
" *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n"
" ((haris_uint32_t)b[2] << 16);\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static void haris_read_uint32(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n"
" *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n"
" ((haris_uint32_t)b[2] << 16) | ((haris_uint32_t)b[3] << 24);\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = strformat(
"static void haris_read_uint64(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint64_t *ptr = (haris_uint64_t*)_ptr;\n"
" *ptr = ((haris_uint64_t)b[0]) | ((haris_uint64_t)b[1] << 8) |\n"
" ((haris_uint64_t)b[2] << 16) | ((haris_uint64_t)b[3] << 24) |\n"
" ((haris_uint64_t)b[4] << 32) | ((haris_uint64_t)b[5] << 40) |\n"
" ((haris_uint64_t)b[6] << 48) | ((haris_uint64_t)b[7] << 56);\n"
"}\n"
"\n"),
result = add_private_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v1 = strformat(
"static void haris_read_uint8(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint8_t *ptr = (haris_uint8_t*)_ptr;\n"
" *ptr = *b;\n"
"}\n"
"\n");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = strformat(
"static void haris_read_uint16(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint16_t *ptr = (haris_uint16_t*)_ptr;\n"
" *ptr = ((haris_uint16_t)b[0]) | ((haris_uint16_t)b[1] << 8);\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = strformat(
"static void haris_read_uint24(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n"
" *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n"
" ((haris_uint32_t)b[2] << 16);\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = strformat(
"static void haris_read_uint32(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n"
" *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n"
" ((haris_uint32_t)b[2] << 16) | ((haris_uint32_t)b[3] << 24);\n"
"}\n"
"\n"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = strformat(
"static void haris_read_uint64(const unsigned char *b, void *_ptr)\n"
"{\n"
" haris_uint64_t *ptr = (haris_uint64_t*)_ptr;\n"
" *ptr = ((haris_uint64_t)b[0]) | ((haris_uint64_t)b[1] << 8) |\n"
" ((haris_uint64_t)b[2] << 16) | ((haris_uint64_t)b[3] << 24) |\n"
" ((haris_uint64_t)b[4] << 32) | ((haris_uint64_t)b[5] << 40) |\n"
" ((haris_uint64_t)b[6] << 48) | ((haris_uint64_t)b[7] << 56);\n"
"}\n"
"\n"),
result = add_private_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

original_code:
static CJobStatus write_readuint(CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_read_uint8(const unsigned char *b, void *_ptr)\n{\n  haris_uint8_t *ptr = (haris_uint8_t*)_ptr;\n  *ptr = *b;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint16(const unsigned char *b, void *_ptr)\n{\n  haris_uint16_t *ptr = (haris_uint16_t*)_ptr;\n  *ptr = ((haris_uint16_t)b[0]) | ((haris_uint16_t)b[1] << 8);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint24(const unsigned char *b, void *_ptr)\n{\n  haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n  *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n    ((haris_uint32_t)b[2] << 16);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint32(const unsigned char *b, void *_ptr)\n{\n  haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n  *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n    ((haris_uint32_t)b[2] << 16) | ((haris_uint32_t)b[3] << 24);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint64(const unsigned char *b, void *_ptr)\n{\n  haris_uint64_t *ptr = (haris_uint64_t*)_ptr;\n  *ptr = ((haris_uint64_t)b[0]) | ((haris_uint64_t)b[1] << 8) |\n    ((haris_uint64_t)b[2] << 16) | ((haris_uint64_t)b[3] << 24) |\n    ((haris_uint64_t)b[4] << 32) | ((haris_uint64_t)b[5] << 40) |\n    ((haris_uint64_t)b[6] << 48) | ((haris_uint64_t)b[7] << 56);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}

canonical_original_code:
static enum CJobStatus write_readuint(struct CJob *job)
{
  do { if (add_private_function(job, strformat("static void haris_read_uint8(const unsigned char *b, void *_ptr)\n{\n  haris_uint8_t *ptr = (haris_uint8_t*)_ptr;\n  *ptr = *b;\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint16(const unsigned char *b, void *_ptr)\n{\n  haris_uint16_t *ptr = (haris_uint16_t*)_ptr;\n  *ptr = ((haris_uint16_t)b[0]) | ((haris_uint16_t)b[1] << 8);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint24(const unsigned char *b, void *_ptr)\n{\n  haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n  *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n    ((haris_uint32_t)b[2] << 16);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint32(const unsigned char *b, void *_ptr)\n{\n  haris_uint32_t *ptr = (haris_uint32_t*)_ptr;\n  *ptr = ((haris_uint32_t)b[0]) | ((haris_uint32_t)b[1] << 8) |\n    ((haris_uint32_t)b[2] << 16) | ((haris_uint32_t)b[3] << 24);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  do { if (add_private_function(job, strformat("static void haris_read_uint64(const unsigned char *b, void *_ptr)\n{\n  haris_uint64_t *ptr = (haris_uint64_t*)_ptr;\n  *ptr = ((haris_uint64_t)b[0]) | ((haris_uint64_t)b[1] << 8) |\n    ((haris_uint64_t)b[2] << 16) | ((haris_uint64_t)b[3] << 24) |\n    ((haris_uint64_t)b[4] << 32) | ((haris_uint64_t)b[5] << 40) |\n    ((haris_uint64_t)b[6] << 48) | ((haris_uint64_t)b[7] << 56);\n}\n\n")) != CJOB_SUCCESS) return CJOB_MEM_ERROR; } while (0);
  return CJOB_SUCCESS;
}


decompiled_code:
__int64 __fastcall write_readint(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // 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");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = 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"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = 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"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = 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, v4),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // 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");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = 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"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = 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"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = 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, v4),
(_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;
}


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


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


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

v1 = off_2368;
for ( result = write_readint(a1); !(_DWORD)result && v1 != (__int64 (__fastcall **)())&unk_23B0; result = v3(a1) )
v3 = (__int64 (__fastcall *)(__int64))*v1++;
return result;
}

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

v1 = off_2368;
for ( result = func7(a1); !(_DWORD)result && v1 != (__int64 (__fastcall **)())&unk_23B0; result = v3(a1) )
v3 = (__int64 (__fastcall *)(__int64))*v1++;
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)
{
__int64 v2; // rdx

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

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, __int64 a2)
{
__int64 v2; // rdx

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

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; // rbp
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 ( *(_WORD *)v3 == 26669 && !v3[2] || !strcmp(argv[1], "--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; // rbp
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 ( *(_WORD *)v3 == 26669 && !v3[2] || !strcmp(argv[1], "--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
__int64 v2; // rax
__int64 result; // rax

v1 = strformat("#include <unistd.h>\n#include<errno.h>\n\n");
if ( (unsigned int)add_header_string(a1, v1)
|| (v2 = 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, v2),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v1 = strformat("#include <unistd.h>\n#include<errno.h>\n\n");
if ( (unsigned int)add_header_string(a1, v1)
|| (v2 = 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, v2),
(_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
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // 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");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = 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"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = 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"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = 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"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = 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, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v1 = strformat(
"static HarisStatus read_from_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");
if ( (unsigned int)add_private_function(a1, v1)
|| (v2 = 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"),
(unsigned int)add_private_function(a1, v2))
|| (v3 = 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"),
(unsigned int)add_private_function(a1, v3))
|| (v4 = 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"),
(unsigned int)add_private_function(a1, v4))
|| (v5 = 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, v5),
(_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, __int64 a2)
{
const char *v2; // r12
const char *v3; // r13
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

v2 = *(const char **)(a1 + 8);
v3 = *(const char **)a2;
v4 = strformat(
"HarisStatus %s%s_to_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,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16));
if ( (unsigned int)add_public_function(a1, v4)
|| (v5 = 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 + 16)),
result = add_public_function(a1, v5),
(_DWORD)result) )
{
result = 4LL;
}
return result;
}

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

v2 = *(const char **)(a1 + 8);
v3 = *(const char **)a2;
v4 = strformat(
"HarisStatus %s%s_to_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,
v3,
v2,
v3,
*(unsigned int *)(a2 + 16));
if ( (unsigned int)add_public_function(a1, v4)
|| (v5 = 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 + 16)),
result = add_public_function(a1, v5),
(_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; // r13
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // rbx
int v5; // ebp

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

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

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

original_code:
CJobStatus write_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;
}