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

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

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

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

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

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

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


repo: theseoafs/haris

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

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

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

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

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

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

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_public_file_funcs(__int64 a1, const char **a2)
{
const char *v2; // r12
const char *v3; // r13
__int64 v4; // rax
int v5; // edx
__int64 result; // rax
__int64 v7; // rax

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

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

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

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

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

variable_types:
strct
struct _ParsedStruct *

variable_types:
prefix
char *

variable_types:
name
char *

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


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

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

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

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

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

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

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

variable_types: i int

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


decompiled_code:
__int64 __fastcall util_vasprintf(char **a1, const char *a2, __m128i *a3)
{
int v3; // eax
unsigned int v4; // ebx
size_t v6; // r14
char *v7; // rax
char *v8; // r13
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v10; // [rsp+18h] [rbp-30h]

arg = _mm_loadu_si128(a3);
v10 = a3[1].m128i_i64[0];
v3 = vsnprintf(0LL, 0LL, a2, a3);
v4 = v3;
if ( v3 >= 0 )
{
v6 = v3 + 1LL;
v7 = (char *)malloc(v6);
v8 = v7;
if ( v7 && vsnprintf(v7, v6, a2, &arg) < 0 )
{
free(v8);
v4 = -1;
v8 = 0LL;
}
*a1 = v8;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, const char *a2, __m128i *a3)
{
int v3; // eax
unsigned int v4; // ebx
size_t v6; // r14
char *v7; // rax
char *v8; // r13
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v10; // [rsp+18h] [rbp-30h]

arg = _mm_loadu_si128(a3);
v10 = a3[1].m128i_i64[0];
v3 = vsnprintf(0LL, 0LL, a2, a3);
v4 = v3;
if ( v3 >= 0 )
{
v6 = v3 + 1LL;
v7 = (char *)malloc(v6);
v8 = v7;
if ( v7 && vsnprintf(v7, v6, a2, &arg) < 0 )
{
free(v8);
v4 = -1;
v8 = 0LL;
}
*a1 = v8;
}
return v4;
}

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

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

variable_types:
out
char **

variable_types:
fmt
char *

variable_types:
ret
char *

return_type: int


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

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

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

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

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

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


decompiled_code:
char *__fastcall util_strdup(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

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

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

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

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

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

variable_types:
s
char *

return_type: char *


LiberaNode

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

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

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

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

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

return_type: void

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


InserePontoAux

decompiled_code:
__int64 __fastcall InserePontoAux(__int64 a1, _QWORD *a2, double a3, double a4)
{
double v4; // xmm0_8
__int64 result; // rax

if ( *((_DWORD *)a2 + 8) >= *((_DWORD *)a2 + 9) )
{
if ( !*((_DWORD *)a2 + 24) )
DivideQuad(a1, a2);
}
else if ( !*((_DWORD *)a2 + 24) )
{
result = InserePontoLista(a2[5]);
a2[5] = result;
++*((_DWORD *)a2 + 8);
return result;
}
v4 = *((double *)a2 + 10);
if ( a3 >= v4 && *((double *)a2 + 7) >= a3 && a4 >= *((double *)a2 + 11) && *((double *)a2 + 9) >= a4 )
return InserePontoAux(a1, *a2, a3, a4);
if ( a3 >= *((double *)a2 + 6) && v4 > a3 )
{
if ( a4 >= *((double *)a2 + 11) && *((double *)a2 + 9) >= a4 )
return InserePontoAux(a1, a2[1], a3, a4);
if ( a4 >= *((double *)a2 + 8) && *((double *)a2 + 11) > a4 )
return InserePontoAux(a1, a2[2], a3, a4);
}
return InserePontoAux(a1, a2[3], a3, a4);
}

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

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

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

variable_types: x double

variable_types: y double

variable_types:
node
struct nodeArvore_t *

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


Bind

repo: thewopr/WireFish

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

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

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

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

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

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

variable_types: sockfd int

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

variable_types:
addrlen
unsigned int

variable_types: retval int


Socket

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

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

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

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

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

variable_types: family int

variable_types: type int

variable_types: protocol int


Recvfrom

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

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

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

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

variable_types: s int

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types: flags int

variable_types:
fromlen
unsigned int *

return_type: long

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


Sendto

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

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

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

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

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

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

variable_types:
tolen
unsigned int


Select

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

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

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

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

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

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

variable_types: nfds int

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

variable_types:
writefds
struct fd_set *

variable_types:
exceptfds
struct fd_set *

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


Clock

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

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

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

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

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

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

variable_types: retval long


Readn

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

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

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

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

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

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

variable_types: fd int

variable_types:
ptr
void *

variable_types:
nbytes
unsigned long

variable_types: n long


Writen

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

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

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

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

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

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


Connect

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

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

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

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

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

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

variable_types: sockfd int

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

variable_types:
addrlen
unsigned int

variable_types: retval int


Getaddrinfo

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

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

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

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

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

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

variable_types:
node
char *

variable_types:
service
char *

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

variable_types:
res
struct addrinfo **

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


Close

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

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

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

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

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


Accept

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

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

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

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

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

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

variable_types:
addrlen
unsigned int *


printsin

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

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

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

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

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

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

variable_types:
ip
char [16]

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


readn

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

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

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

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

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

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

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
ptr
char *


writen

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

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

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

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

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

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

variable_types: fd int

variable_types: nwritten long


usage

repo: thexhr/dermob

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

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

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

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

variable_types:
file
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
const char **v5; // rbp
int v6; // er12
__off_t v7; // r13
void *v8; // rax
void *v9; // rbp
unsigned int v10; // er13
__int64 v11; // rdi
int v13; // eax
const char *v14; // rsi
unsigned int v15; // [rsp+8h] [rbp-C0h] BYREF
int v16; // [rsp+Ch] [rbp-BCh] BYREF
struct stat v17; // [rsp+10h] [rbp-B8h] BYREF

v16 = 0;
v15 = 0;
trigger = 0;
dynamic = 0;
dyn_display = 0;
if ( argc <= 1 )
usage(*argv);
v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "uhctxds");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'c':
v3 |= 4u;
break;
case 'd':
v3 |= 0x32u;
break;
case 'h':
v3 |= 2u;
break;
case 's':
v3 |= 0x64u;
break;
case 't':
v3 |= 8u;
break;
case 'u':
v3 |= 1u;
break;
case 'x':
v3 |= 0x16u;
break;
default:
usage(*argv);
}
}
v5 = &argv[optind];
puts("dermob -- mach-o binary analyzer");
puts("\t(c) 2006-12 by xhr (@giessen.ccc.de)\n");
if ( stat(*v5, &v17) < 0 )
errx(1, "Cannot open %s", *v5);
v6 = open(*v5, 0, 0LL);
if ( v6 < 0 )
errx(1, "Cannot open %s", *v5);
v7 = v17.st_size;
v8 = malloc(v17.st_size);
v9 = v8;
if ( !v8 )
errx(1, "Cannot allocate memory");
size = v7;
v10 = read(v6, v8, v7);
cpu = get_cpu_information();
bo_a = get_bo_information();
v11 = list_create_list();
lst = v11;
if ( v3 > 50 )
{
if ( v3 == 100 )
{
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
display_buffer(v9, (unsigned int)cs_addr, (unsigned int)cs_offset, (unsigned int)cs_size);
goto LABEL_26;
}
goto LABEL_32;
}
if ( v3 <= 0 )
{
LABEL_32:
v13 = display_fat_header(v11, v9, &v16);
if ( v13 > 0 )
printf("- Universal Binary for %d architectures\n", (unsigned int)v13);
if ( (int)display_mo_header(lst, v9, &v16, &v15) <= 0 )
{
puts("No mach-o file");
exit(1);
}
puts("- Vaild mach-o binary");
dyn_display = 1;
display_load_commands(lst, v9, &v16, v15);
v14 = (const char *)&unk_6E9;
if ( !dynamic )
v14 = "- Statically linked\n";
printf("%s", v14);
goto LABEL_26;
}
switch ( v3 )
{
case 1:
display_fat_header(v11, v9, &v16);
list_traverse_list(lst);
break;
case 2:
case 3:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
list_traverse_list(lst);
break;
case 4:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
list_traverse_list(lst);
break;
case 8:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
display_buffer(v9, (unsigned int)text_addr, (unsigned int)text_offset, (unsigned int)text_size);
break;
case 22:
display_buffer(v9, 0LL, 0LL, v10);
break;
case 50:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
display_buffer(v9, (unsigned int)data_addr, (unsigned int)data_offset, (unsigned int)data_size);
break;
default:
goto LABEL_32;
}
LABEL_26:
list_free_list(lst);
close(v6);
free(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
const char **v5; // rbp
int v6; // er12
__off_t v7; // r13
void *v8; // rax
void *v9; // rbp
unsigned int v10; // er13
__int64 v11; // rdi
int v13; // eax
const char *v14; // rsi
unsigned int v15; // [rsp+8h] [rbp-C0h] BYREF
int v16; // [rsp+Ch] [rbp-BCh] BYREF
struct stat v17; // [rsp+10h] [rbp-B8h] BYREF

v16 = 0;
v15 = 0;
trigger = 0;
dynamic = 0;
dyn_display = 0;
if ( argc <= 1 )
func0(*argv);
v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "uhctxds");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'c':
v3 |= 4u;
break;
case 'd':
v3 |= 0x32u;
break;
case 'h':
v3 |= 2u;
break;
case 's':
v3 |= 0x64u;
break;
case 't':
v3 |= 8u;
break;
case 'u':
v3 |= 1u;
break;
case 'x':
v3 |= 0x16u;
break;
default:
func0(*argv);
}
}
v5 = &argv[optind];
puts("dermob -- mach-o binary analyzer");
puts("\t(c) 2006-12 by xhr (@giessen.ccc.de)\n");
if ( stat(*v5, &v17) < 0 )
errx(1, "Cannot open %s", *v5);
v6 = open(*v5, 0, 0LL);
if ( v6 < 0 )
errx(1, "Cannot open %s", *v5);
v7 = v17.st_size;
v8 = malloc(v17.st_size);
v9 = v8;
if ( !v8 )
errx(1, "Cannot allocate memory");
size = v7;
v10 = read(v6, v8, v7);
cpu = get_cpu_information();
bo_a = get_bo_information();
v11 = list_create_list();
lst = v11;
if ( v3 > 50 )
{
if ( v3 == 100 )
{
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
display_buffer(v9, (unsigned int)cs_addr, (unsigned int)cs_offset, (unsigned int)cs_size);
goto LABEL_26;
}
goto LABEL_32;
}
if ( v3 <= 0 )
{
LABEL_32:
v13 = display_fat_header(v11, v9, &v16);
if ( v13 > 0 )
printf("- Universal Binary for %d architectures\n", (unsigned int)v13);
if ( (int)display_mo_header(lst, v9, &v16, &v15) <= 0 )
{
puts("No mach-o file");
exit(1);
}
puts("- Vaild mach-o binary");
dyn_display = 1;
display_load_commands(lst, v9, &v16, v15);
v14 = (const char *)&unk_6E9;
if ( !dynamic )
v14 = "- Statically linked\n";
printf("%s", v14);
goto LABEL_26;
}
switch ( v3 )
{
case 1:
display_fat_header(v11, v9, &v16);
list_traverse_list(lst);
break;
case 2:
case 3:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
list_traverse_list(lst);
break;
case 4:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
list_traverse_list(lst);
break;
case 8:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
display_buffer(v9, (unsigned int)text_addr, (unsigned int)text_offset, (unsigned int)text_size);
break;
case 22:
display_buffer(v9, 0LL, 0LL, v10);
break;
case 50:
display_fat_header(v11, v9, &v16);
display_mo_header(lst, v9, &v16, &v15);
display_load_commands(lst, v9, &v16, v15);
display_buffer(v9, (unsigned int)data_addr, (unsigned int)data_offset, (unsigned int)data_size);
break;
default:
goto LABEL_32;
}
LABEL_26:
list_free_list(lst);
close(v6);
free(v9);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
 struct stat sb;
 char *buffer, ch;
 int fd, len=1, offset = 0, ncmds = 0, flag = 0, ret;
 trigger = 0;
 dynamic = 0;
 dyn_display = 0;
 if (argc < 2) {
  usage(argv[0]);
 }
 while ((ch = getopt(argc, argv, "uhctxds")) != -1) {
  switch (ch) {
  case 'u': flag |= 0x1; break;
  case 'h': flag |= 0x2; break;
  case 'c': flag |= 0x4; break;
  case 't': flag |= 0x8; break;
  case 'x': flag |= 0x16; break;
  case 'd': flag |= 0x32; break;
  case 's': flag |= 0x64; break;
  default: usage(argv[0]); break;
  }
 }
 argc -= optind;
 argv += optind;
 printf("dermob -- mach-o binary analyzer\n");
 printf("	(c) 2006-12 by xhr (@giessen.ccc.de)\n\n");
 if ((stat(argv[0], &sb)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((fd = open(argv[0], 00, 0)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((buffer = malloc(sb.st_size)) == ((void *)0))
  errx(1, "Cannot allocate memory");
 size = sb.st_size;
 len = read(fd, buffer, size);
 cpu = get_cpu_information();
 bo_a = get_bo_information();
 lst = list_create_list();
 switch (flag) {
  case 0x1:
   display_fat_header(lst, buffer, &offset);
   list_traverse_list(lst);
   break;
  case 0x2:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x3:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x4:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   list_traverse_list(lst);
   break;
  case 0x8:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, text_addr, text_offset, text_size);
   break;
  case 0x16:
   display_buffer(buffer, 0, 0, len);
   break;
  case 0x32:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, data_addr, data_offset, data_size);
   break;
  case 0x64:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, cs_addr, cs_offset, cs_size);
   break;
  default:
   ret = display_fat_header(lst, buffer, &offset);
   if (ret > 0)
    printf("- Universal Binary for %d architectures\n", ret);
   ret = display_mo_header(lst, buffer, &offset, &ncmds);
   if (ret > 0)
    printf("- Vaild mach-o binary\n");
   else {
    printf("No mach-o file\n");
    exit(1);
   }
   dyn_display = 1;
   display_load_commands(lst, buffer, &offset, ncmds);
   printf("%s", dynamic ? "" : "- Statically linked\n");
   break;
 }
 list_free_list(lst);
 close(fd);
 free(buffer);
 return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct stat sb;
 char *buffer; char ch;
 int fd; int len = 1; int offset = 0; int ncmds = 0; int flag = 0; int ret;
 trigger = 0;
 dynamic = 0;
 dyn_display = 0;
 if (argc < 2) {
  usage(argv[0]);
 }
 while ((ch = getopt(argc, argv, "uhctxds")) != -1) {
  switch (ch) {
  case 'u': flag |= 0x1; break;
  case 'h': flag |= 0x2; break;
  case 'c': flag |= 0x4; break;
  case 't': flag |= 0x8; break;
  case 'x': flag |= 0x16; break;
  case 'd': flag |= 0x32; break;
  case 's': flag |= 0x64; break;
  default: usage(argv[0]); break;
  }
 }
 argc -= optind;
 argv += optind;
 printf("dermob -- mach-o binary analyzer\n");
 printf("	(c) 2006-12 by xhr (@giessen.ccc.de)\n\n");
 if ((stat(argv[0], &sb)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((fd = open(argv[0], 00, 0)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((buffer = malloc(sb.st_size)) == ((void *)0))
  errx(1, "Cannot allocate memory");
 size = sb.st_size;
 len = read(fd, buffer, size);
 cpu = get_cpu_information();
 bo_a = get_bo_information();
 lst = list_create_list();
 switch (flag) {
  case 0x1:
   display_fat_header(lst, buffer, &offset);
   list_traverse_list(lst);
   break;
  case 0x2:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x3:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x4:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   list_traverse_list(lst);
   break;
  case 0x8:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, text_addr, text_offset, text_size);
   break;
  case 0x16:
   display_buffer(buffer, 0, 0, len);
   break;
  case 0x32:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, data_addr, data_offset, data_size);
   break;
  case 0x64:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, cs_addr, cs_offset, cs_size);
   break;
  default:
   ret = display_fat_header(lst, buffer, &offset);
   if (ret > 0)
    printf("- Universal Binary for %d architectures\n", ret);
   ret = display_mo_header(lst, buffer, &offset, &ncmds);
   if (ret > 0)
    printf("- Vaild mach-o binary\n");
   else {
    printf("No mach-o file\n");
    exit(1);
   }
   dyn_display = 1;
   display_load_commands(lst, buffer, &offset, ncmds);
   printf("%s", dynamic ? "" : "- Statically linked\n");
   break;
 }
 list_free_list(lst);
 close(fd);
 free(buffer);
 return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
buffer
char *

variable_types: ch char

variable_types: len int

variable_types: offset int

variable_types: ncmds int

variable_types: flag int

variable_types: ret int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


mprintf

decompiled_code:
int mprintf(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( trigger != 1 )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

canonical_decompiled_code:
int func0(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( trigger != 1 )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

original_code:
void
mprintf(const char *fmt, ...)
{
    va_list ap;
 if (trigger == 1)
  return;
 __builtin_va_start(ap,fmt);
 vfprintf(stdout, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void mprintf(char *fmt, ...)
{
    __builtin_va_list ap;
 if (trigger == 1)
  return;
 __builtin_va_start(ap,fmt);
 vfprintf(stdout, fmt, ap);
 __builtin_va_end(ap);
}

variable_types:
fmt
char *


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

switch ( a1 )
{
case 1:
result = mprintf("LC_SEGMENT\n");
break;
case 2:
result = mprintf("LC_SYMTAB\n");
break;
case 5:
result = mprintf("LC_UNIXTHREAD\n");
break;
case 11:
result = mprintf("LC_DYSYMTAB\n");
break;
case 12:
result = mprintf("LC_LOAD_DYLIB\n");
break;
case 14:
result = mprintf("LC_LOAD_DYLINKER\n");
break;
case 22:
result = mprintf("LC_TWOLEVEL_HINTS\n");
break;
default:
result = mprintf("\n");
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
result = func0("LC_SEGMENT\n");
break;
case 2:
result = func0("LC_SYMTAB\n");
break;
case 5:
result = func0("LC_UNIXTHREAD\n");
break;
case 11:
result = func0("LC_DYSYMTAB\n");
break;
case 12:
result = func0("LC_LOAD_DYLIB\n");
break;
case 14:
result = func0("LC_LOAD_DYLINKER\n");
break;
case 22:
result = func0("LC_TWOLEVEL_HINTS\n");
break;
default:
result = func0("\n");
break;
}
return result;
}

original_code:
void
display_cmd_name(int cmd)
{
 switch(cmd) {
  case 0x1:
   mprintf("LC_SEGMENT\n"); break;
  case 0x2:
   mprintf("LC_SYMTAB\n"); break;
  case 0xc:
   mprintf("LC_LOAD_DYLIB\n"); break;
  case 0xe:
   mprintf("LC_LOAD_DYLINKER\n"); break;
  case 0xb:
   mprintf("LC_DYSYMTAB\n"); break;
  case 0x5:
   mprintf("LC_UNIXTHREAD\n"); break;
  case 0x16:
   mprintf("LC_TWOLEVEL_HINTS\n"); break;
  default:
   mprintf("\n"); break;
 }
}

variable_types: cmd int


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

if ( a1 > 18 )
{
if ( a1 == 16777223 )
return mprintf("x86_64");
return mprintf("\n");
}
if ( a1 <= 5 )
return mprintf("\n");
switch ( a1 )
{
case 6:
result = mprintf("MC680x0");
break;
case 7:
result = mprintf("x86_32");
break;
case 11:
result = mprintf("HPPA");
break;
case 14:
result = mprintf("Sparc");
break;
case 18:
result = mprintf("PowerPC");
break;
default:
return mprintf("\n");
}
return result;
}

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

if ( a1 > 18 )
{
if ( a1 == 16777223 )
return func0("x86_64");
return func0("\n");
}
if ( a1 <= 5 )
return func0("\n");
switch ( a1 )
{
case 6:
result = func0("MC680x0");
break;
case 7:
result = func0("x86_32");
break;
case 11:
result = func0("HPPA");
break;
case 14:
result = func0("Sparc");
break;
case 18:
result = func0("PowerPC");
break;
default:
return func0("\n");
}
return result;
}

original_code:
void
display_cpu_arch(int cputype)
{
        switch (cputype) {
  case ((cpu_type_t) 6):
   mprintf("MC680x0"); break;
  case ((cpu_type_t) 7):
   mprintf("x86_32"); break;
  case (((cpu_type_t) 7) | 0x01000000):
   mprintf("x86_64"); break;
  case ((cpu_type_t) 18):
   mprintf("PowerPC"); break;
  case ((cpu_type_t) 11):
   mprintf("HPPA"); break;
  case ((cpu_type_t) 14):
   mprintf("Sparc"); break;
  default:
   mprintf("\n"); break;
 }
}

canonical_original_code:
void display_cpu_arch(int cputype)
{
        switch (cputype) {
  case ((int) 6):
   mprintf("MC680x0"); break;
  case ((int) 7):
   mprintf("x86_32"); break;
  case (((int) 7) | 0x01000000):
   mprintf("x86_64"); break;
  case ((int) 18):
   mprintf("PowerPC"); break;
  case ((int) 11):
   mprintf("HPPA"); break;
  case ((int) 14):
   mprintf("Sparc"); break;
  default:
   mprintf("\n"); break;
 }
}

variable_types: cputype int


decompiled_code:
__int64 get_cpu_information()
{
return 7LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 7LL;
}

original_code:
int
get_cpu_information()
{
  return(((cpu_type_t) 7));
 return(-1);
}

canonical_original_code:
int get_cpu_information()
{
  return(((int) 7));
 return(-1);
}


decompiled_code:
__int64 get_bo_information()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 0LL;
}

original_code:
int
get_bo_information()
{
  return(0);
 return(-1);
}


swapi

decompiled_code:
__int64 __fastcall swapi(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( bo_a == 1 )
{
if ( !bo_b )
result = (a1 >> 8) & 0xFF00 | (a1 << 24) | HIBYTE(a1) | (a1 << 8) & 0xFF0000;
}
else if ( !bo_a && bo_b == 1 )
{
result = (a1 >> 8) & 0xFF00 | (a1 << 24) | HIBYTE(a1) | (a1 << 8) & 0xFF0000;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( bo_a == 1 )
{
if ( !bo_b )
result = (a1 >> 8) & 0xFF00 | (a1 << 24) | HIBYTE(a1) | (a1 << 8) & 0xFF0000;
}
else if ( !bo_a && bo_b == 1 )
{
result = (a1 >> 8) & 0xFF00 | (a1 << 24) | HIBYTE(a1) | (a1 << 8) & 0xFF0000;
}
return result;
}

variable_types:
i
unsigned int

variable_types:
ret
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall display_fat_header(__int64 a1, __int64 a2, _DWORD *a3)
{
unsigned int *v4; // rbx
int v5; // eax
int v6; // er12
unsigned int v7; // ebp
unsigned int *v8; // rbx
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v10[0] = 0;
v4 = (unsigned int *)malloc(8uLL);
if ( (int)analyse_fat_header(a2, v10, v4) < 0 )
{
free(v4);
v7 = -1;
}
else
{
list_insert_node(a1, v4, 1LL);
v5 = swapi(v4[1]);
v6 = v5;
if ( v5 <= 0 )
{
v7 = v5;
}
else
{
v7 = 0;
do
{
v8 = (unsigned int *)malloc(0x14uLL);
analyse_fat_arch(a2, v10, v8);
list_insert_node(a1, v8, 2LL);
if ( (unsigned int)swapi(v8[3]) > (unsigned __int64)size )
{
puts("Malformed universal binary. Size for one Architecture is larger than the complete binary.");
exit(1);
}
if ( (unsigned int)swapi(*v8) == cpu )
*a3 = swapi(v8[2]);
++v7;
}
while ( v6 != v7 );
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, _DWORD *a3)
{
unsigned int *v4; // rbx
int v5; // eax
int v6; // er12
unsigned int v7; // ebp
unsigned int *v8; // rbx
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v10[0] = 0;
v4 = (unsigned int *)malloc(8uLL);
if ( (int)analyse_fat_header(a2, v10, v4) < 0 )
{
free(v4);
v7 = -1;
}
else
{
list_insert_node(a1, v4, 1LL);
v5 = func5(v4[1]);
v6 = v5;
if ( v5 <= 0 )
{
v7 = v5;
}
else
{
v7 = 0;
do
{
v8 = (unsigned int *)malloc(0x14uLL);
analyse_fat_arch(a2, v10, v8);
list_insert_node(a1, v8, 2LL);
if ( (unsigned int)func5(v8[3]) > (unsigned __int64)size )
{
puts("Malformed universal binary. Size for one Architecture is larger than the complete binary.");
exit(1);
}
if ( (unsigned int)func5(*v8) == cpu )
*a3 = func5(v8[2]);
++v7;
}
while ( v6 != v7 );
}
}
return v7;
}

original_code:
int
display_fat_header(struct list *lst, char *buffer, int *roffset)
{
 struct fat_header *fh;
 struct fat_arch *fa;
 int offset = 0, i, narch;
 fh = malloc(sizeof(*fh));
 if (analyse_fat_header(buffer, &offset, fh) < 0) {
  free(fh);
  return(-1);
 }
 list_insert_node(lst, fh, 0x1);
 narch = swapi(fh->nfat_arch);
 for (i = 0; i < narch; i++) {
  fa = malloc(sizeof(*fa));
  analyse_fat_arch(buffer, &offset, fa);
  list_insert_node(lst, fa, 0x2);
  if (swapi(fa->size) > size) {
   printf("Malformed universal binary.  Size for one " "Architecture is larger than the complete binary.\n");
   exit(1);
  }
  if (cpu == swapi(fa->cputype))
   *roffset = swapi(fa->offset);
 }
 return(narch);
}

canonical_original_code:
int display_fat_header(struct list *lst, char *buffer, int *roffset)
{
 struct fat_header *fh;
 struct fat_arch *fa;
 int offset = 0; int i; int narch;
 fh = malloc(sizeof(*fh));
 if (analyse_fat_header(buffer, &offset, fh) < 0) {
  free(fh);
  return(-1);
 }
 list_insert_node(lst, fh, 0x1);
 narch = swapi(fh->nfat_arch);
 for (i = 0; i < narch; i++) {
  fa = malloc(sizeof(*fa));
  analyse_fat_arch(buffer, &offset, fa);
  list_insert_node(lst, fa, 0x2);
  if (swapi(fa->size) > size) {
   printf("Malformed universal binary.  Size for one " "Architecture is larger than the complete binary.\n");
   exit(1);
  }
  if (cpu == swapi(fa->cputype))
   *roffset = swapi(fa->offset);
 }
 return(narch);
}

variable_types: struct list { struct node { void *content; unsigned int code; struct node *next; struct node *prev; } *head; struct node *tail; unsigned int len; } *

variable_types:
roffset
int *

variable_types: struct fat_header { unsigned int magic; unsigned int nfat_arch; } *

variable_types: struct fat_arch { int cputype; int cpusubtype; unsigned int offset; unsigned int size; unsigned int align; } *

variable_types: i int

variable_types: narch int

user_defined_types: struct list { struct node *head; struct node *tail; unsigned int len; }


decompiled_code:
__int64 __fastcall display_mo_header(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
unsigned int *v6; // rbx
__int64 result; // rax

v6 = (unsigned int *)malloc(0x1CuLL);
if ( (int)analyse_mo_header(a2, a3, v6) < 0 )
{
free(v6);
result = 0xFFFFFFFFLL;
}
else
{
*a4 = swapi(v6[4]);
list_insert_node(a1, v6, 3LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
unsigned int *v6; // rbx
__int64 result; // rax

v6 = (unsigned int *)malloc(0x1CuLL);
if ( (int)analyse_mo_header(a2, a3, v6) < 0 )
{
free(v6);
result = 0xFFFFFFFFLL;
}
else
{
*a4 = func5(v6[4]);
list_insert_node(a1, v6, 3LL);
result = 1LL;
}
return result;
}

original_code:
int
display_mo_header(struct list *lst, char *buffer, int *offset, int *ncmds)
{
 struct mach_header *mh;
 mh = malloc(sizeof(*mh));
 if (analyse_mo_header(buffer, offset, mh) < 0) {
  free(mh);
  return(-1);
 }
 *ncmds = swapi(mh->ncmds);
 list_insert_node(lst, mh, 0x3);
 return(1);
}

variable_types:
buffer
char *

variable_types:
offset
int *

variable_types:
ncmds
int *

variable_types: struct mach_header { unsigned int magic; int cputype; int cpusubtype; unsigned int filetype; unsigned int ncmds; unsigned int sizeofcmds; unsigned int flags; } *

user_defined_types: struct node { void *content; unsigned int code; struct node *next; struct node *prev; }


decompiled_code:
void __fastcall display_load_commands(__int64 a1, __int64 a2, _DWORD *a3, int a4)
{
int v5; // er12
void *v6; // rbx
unsigned int *v7; // rbx
unsigned int v8; // ebp
unsigned int v9; // eax
int i; // [rsp+4h] [rbp-54h]
int v11; // [rsp+8h] [rbp-50h]
int v13[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v13[0] = 0;
if ( a4 > 0 )
{
for ( i = 0; i != a4; ++i )
{
v7 = (unsigned int *)malloc(8uLL);
analyse_load_command(a2, a3, v7);
list_insert_node(a1, v7, 4LL);
v8 = swapi(v7[1]);
v9 = swapi(*v7);
v11 = examine_segmet(a2, a3, v9, v8, v13);
if ( v13[0] > 0 )
{
v5 = 0;
do
{
v6 = malloc(0x44uLL);
if ( !v5 )
*a3 += v11;
examine_section(a2, a3, v6);
if ( !strcmp((const char *)v6 + 16, "__TEXT") )
{
if ( strcmp((const char *)v6, "__text")
|| (text_addr = swapi(*((_DWORD *)v6 + 8)),
text_size = swapi(*((_DWORD *)v6 + 9)),
text_offset = swapi(*((_DWORD *)v6 + 10)),
!strcmp((const char *)v6 + 16, "__TEXT")) )
{
if ( !strcmp((const char *)v6, "__cstring") )
{
cs_addr = swapi(*((_DWORD *)v6 + 8));
cs_size = swapi(*((_DWORD *)v6 + 9));
cs_offset = swapi(*((_DWORD *)v6 + 10));
}
}
}
if ( !strcmp((const char *)v6 + 16, "__DATA") && !strcmp((const char *)v6, "__data") )
{
data_addr = swapi(*((_DWORD *)v6 + 8));
data_size = swapi(*((_DWORD *)v6 + 9));
data_offset = swapi(*((_DWORD *)v6 + 10));
}
list_insert_node(a1, v6, 5LL);
++v5;
}
while ( v13[0] > v5 );
v13[0] = 0;
}
else
{
*a3 += swapi(v7[1]);
}
}
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2, _DWORD *a3, int a4)
{
int v5; // er12
void *v6; // rbx
unsigned int *v7; // rbx
unsigned int v8; // ebp
unsigned int v9; // eax
int i; // [rsp+4h] [rbp-54h]
int v11; // [rsp+8h] [rbp-50h]
int v13[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v13[0] = 0;
if ( a4 > 0 )
{
for ( i = 0; i != a4; ++i )
{
v7 = (unsigned int *)malloc(8uLL);
analyse_load_command(a2, a3, v7);
list_insert_node(a1, v7, 4LL);
v8 = func5(v7[1]);
v9 = func5(*v7);
v11 = examine_segmet(a2, a3, v9, v8, v13);
if ( v13[0] > 0 )
{
v5 = 0;
do
{
v6 = malloc(0x44uLL);
if ( !v5 )
*a3 += v11;
examine_section(a2, a3, v6);
if ( !strcmp((const char *)v6 + 16, "__TEXT") )
{
if ( strcmp((const char *)v6, "__text")
|| (text_addr = func5(*((_DWORD *)v6 + 8)),
text_size = func5(*((_DWORD *)v6 + 9)),
text_offset = func5(*((_DWORD *)v6 + 10)),
!strcmp((const char *)v6 + 16, "__TEXT")) )
{
if ( !strcmp((const char *)v6, "__cstring") )
{
cs_addr = func5(*((_DWORD *)v6 + 8));
cs_size = func5(*((_DWORD *)v6 + 9));
cs_offset = func5(*((_DWORD *)v6 + 10));
}
}
}
if ( !strcmp((const char *)v6 + 16, "__DATA") && !strcmp((const char *)v6, "__data") )
{
data_addr = func5(*((_DWORD *)v6 + 8));
data_size = func5(*((_DWORD *)v6 + 9));
data_offset = func5(*((_DWORD *)v6 + 10));
}
list_insert_node(a1, v6, 5LL);
++v5;
}
while ( v13[0] > v5 );
v13[0] = 0;
}
else
{
*a3 += func5(v7[1]);
}
}
}
}

original_code:
void
display_load_commands(struct list *lst, char *buffer, int *offset, int ncmds)
{
 struct load_command *ld;
 struct section *sec;
 int i, nofx = 0, val = 0, j, offset_old;
 for (i = 0; i < ncmds; i++) {
  ld = malloc(sizeof(*ld));
  analyse_load_command(buffer, offset, ld);
  list_insert_node(lst, ld, 0x4);
  offset_old = *offset;
  val = examine_segmet(buffer, offset, swapi(ld->cmd), swapi(ld->cmdsize), &nofx);
  if (nofx > 0) {
   for (j = 0; j < nofx; j++) {
    sec = malloc(sizeof(*sec));
    if (j == 0) *offset += val;
    examine_section(buffer, offset, sec);
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__text") == 0)) {
     text_addr = swapi(sec->addr);
     text_size = swapi(sec->size);
     text_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__cstring") == 0)) {
     cs_addr = swapi(sec->addr);
     cs_size = swapi(sec->size);
     cs_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__DATA") == 0) &&
        (strcmp(sec->sectname, "__data") == 0)) {
     data_addr = swapi(sec->addr);
     data_size = swapi(sec->size);
     data_offset = swapi(sec->offset);
    }
    list_insert_node(lst, sec, 0x5);
   }
   nofx = 0;
  }
  else
   *offset += swapi(ld->cmdsize);
 }
}

canonical_original_code:
void display_load_commands(struct list *lst, char *buffer, int *offset, int ncmds)
{
 struct load_command *ld;
 struct section *sec;
 int i; int nofx = 0; int val = 0; int j; int offset_old;
 for (i = 0; i < ncmds; i++) {
  ld = malloc(sizeof(*ld));
  analyse_load_command(buffer, offset, ld);
  list_insert_node(lst, ld, 0x4);
  offset_old = *offset;
  val = examine_segmet(buffer, offset, swapi(ld->cmd), swapi(ld->cmdsize), &nofx);
  if (nofx > 0) {
   for (j = 0; j < nofx; j++) {
    sec = malloc(sizeof(*sec));
    if (j == 0) *offset += val;
    examine_section(buffer, offset, sec);
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__text") == 0)) {
     text_addr = swapi(sec->addr);
     text_size = swapi(sec->size);
     text_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__cstring") == 0)) {
     cs_addr = swapi(sec->addr);
     cs_size = swapi(sec->size);
     cs_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__DATA") == 0) &&
        (strcmp(sec->sectname, "__data") == 0)) {
     data_addr = swapi(sec->addr);
     data_size = swapi(sec->size);
     data_offset = swapi(sec->offset);
    }
    list_insert_node(lst, sec, 0x5);
   }
   nofx = 0;
  }
  else
   *offset += swapi(ld->cmdsize);
 }
}

variable_types: ncmds int

variable_types: struct load_command { unsigned int cmd; unsigned int cmdsize; } *

variable_types: struct section { char sectname[16]; char segname[16]; unsigned int addr; unsigned int size; unsigned int offset; unsigned int align; unsigned int reloff; unsigned int nreloc; unsigned int flags; unsigned int reserved1; unsigned int reserved2; } *

variable_types: nofx int

variable_types: val int

variable_types: j int


decompiled_code:
int __fastcall print_lc_towlevel_hints(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

v1 = swapi(*(_DWORD *)(a1 + 8));
mprintf(" Offset:\t\t%d\n", v1);
v2 = swapi(*(_DWORD *)(a1 + 12));
return mprintf(" No of 2level hints:\t%d\n", v2);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

v1 = func5(*(_DWORD *)(a1 + 8));
func0(" Offset:\t\t%d\n", v1);
v2 = func5(*(_DWORD *)(a1 + 12));
return func0(" No of 2level hints:\t%d\n", v2);
}

original_code:
void
print_lc_towlevel_hints(struct twolevel_hints_command *two)
{
 mprintf("  Offset:		%d\n", swapi(two->offset));
 mprintf("  No of 2level hints:	%d\n", swapi(two->nhints));
}

variable_types: struct twolevel_hints_command { unsigned int cmd; unsigned int cmdsize; unsigned int offset; unsigned int nhints; } *


decompiled_code:
int __fastcall print_lc_dysymtab(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax

v1 = swapi(a1[2]);
mprintf(" ilocalsym:\t\t%d\n", v1);
v2 = swapi(a1[3]);
mprintf(" nlocalsym:\t\t%d\n", v2);
v3 = swapi(a1[4]);
mprintf(" iextdefsym:\t%d\n", v3);
v4 = swapi(a1[5]);
mprintf(" nextdefsym:\t%d\n", v4);
v5 = swapi(a1[6]);
mprintf(" iundefsym:\t\t%d\n", v5);
v6 = swapi(a1[7]);
mprintf(" nundefsym:\t\t%d\n", v6);
v7 = swapi(a1[8]);
mprintf(" tocoff:\t\t%d\n", v7);
v8 = swapi(a1[9]);
mprintf(" ntoc:\t\t%d\n", v8);
v9 = swapi(a1[10]);
mprintf(" modtaboff:\t\t%d\n", v9);
v10 = swapi(a1[11]);
mprintf(" nmodtab:\t\t%d\n", v10);
v11 = swapi(a1[12]);
mprintf(" extrefsymoff:\t%d\n", v11);
v12 = swapi(a1[13]);
mprintf(" nextrefsyms:\t%d\n", v12);
v13 = swapi(a1[14]);
mprintf(" indirectsymoff:\t%d\n", v13);
v14 = swapi(a1[15]);
mprintf(" nindirectsyms:\t%d\n", v14);
v15 = swapi(a1[16]);
mprintf(" extreloff:\t\t%d\n", v15);
v16 = swapi(a1[17]);
mprintf(" nextrel:\t\t%d\n", v16);
v17 = swapi(a1[18]);
mprintf(" locreloff:\t\t%d\n", v17);
v18 = swapi(a1[19]);
return mprintf(" nlocrel:\t\t%d\n", v18);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax

v1 = func5(a1[2]);
func0(" ilocalsym:\t\t%d\n", v1);
v2 = func5(a1[3]);
func0(" nlocalsym:\t\t%d\n", v2);
v3 = func5(a1[4]);
func0(" iextdefsym:\t%d\n", v3);
v4 = func5(a1[5]);
func0(" nextdefsym:\t%d\n", v4);
v5 = func5(a1[6]);
func0(" iundefsym:\t\t%d\n", v5);
v6 = func5(a1[7]);
func0(" nundefsym:\t\t%d\n", v6);
v7 = func5(a1[8]);
func0(" tocoff:\t\t%d\n", v7);
v8 = func5(a1[9]);
func0(" ntoc:\t\t%d\n", v8);
v9 = func5(a1[10]);
func0(" modtaboff:\t\t%d\n", v9);
v10 = func5(a1[11]);
func0(" nmodtab:\t\t%d\n", v10);
v11 = func5(a1[12]);
func0(" extrefsymoff:\t%d\n", v11);
v12 = func5(a1[13]);
func0(" nextrefsyms:\t%d\n", v12);
v13 = func5(a1[14]);
func0(" indirectsymoff:\t%d\n", v13);
v14 = func5(a1[15]);
func0(" nindirectsyms:\t%d\n", v14);
v15 = func5(a1[16]);
func0(" extreloff:\t\t%d\n", v15);
v16 = func5(a1[17]);
func0(" nextrel:\t\t%d\n", v16);
v17 = func5(a1[18]);
func0(" locreloff:\t\t%d\n", v17);
v18 = func5(a1[19]);
return func0(" nlocrel:\t\t%d\n", v18);
}

original_code:
void
print_lc_dysymtab(struct dysymtab_command *dsym)
{
 mprintf("    ilocalsym:		%d\n", swapi(dsym->ilocalsym));
 mprintf("    nlocalsym:		%d\n", swapi(dsym->nlocalsym));
 mprintf("    iextdefsym:	%d\n", swapi(dsym->iextdefsym));
 mprintf("    nextdefsym:	%d\n", swapi(dsym->nextdefsym));
 mprintf("    iundefsym:		%d\n", swapi(dsym->iundefsym));
 mprintf("    nundefsym:		%d\n", swapi(dsym->nundefsym));
 mprintf("    tocoff:		%d\n", swapi(dsym->tocoff));
 mprintf("    ntoc:		%d\n", swapi(dsym->ntoc));
 mprintf("    modtaboff:		%d\n", swapi(dsym->modtaboff));
 mprintf("    nmodtab:		%d\n", swapi(dsym->nmodtab));
 mprintf("    extrefsymoff:	%d\n", swapi(dsym->extrefsymoff));
 mprintf("    nextrefsyms:	%d\n", swapi(dsym->nextrefsyms));
 mprintf("    indirectsymoff:	%d\n", swapi(dsym->indirectsymoff));
 mprintf("    nindirectsyms:	%d\n", swapi(dsym->nindirectsyms));
 mprintf("    extreloff:		%d\n", swapi(dsym->extreloff));
 mprintf("    nextrel:		%d\n", swapi(dsym->nextrel));
 mprintf("    locreloff:		%d\n", swapi(dsym->locreloff));
 mprintf("    nlocrel:		%d\n", swapi(dsym->nlocrel));
}

variable_types: struct dysymtab_command { unsigned int cmd; unsigned int cmdsize; unsigned int ilocalsym; unsigned int nlocalsym; unsigned int iextdefsym; unsigned int nextdefsym; unsigned int iundefsym; unsigned int nundefsym; unsigned int tocoff; unsigned int ntoc; unsigned int modtaboff; unsigned int nmodtab; unsigned int extrefsymoff; unsigned int nextrefsyms; unsigned int indirectsymoff; unsigned int nindirectsyms; unsigned int extreloff; unsigned int nextrel; unsigned int locreloff; unsigned int nlocrel; } *


decompiled_code:
void __fastcall print_lc_load_dylib(unsigned int *a1)
{
char *v1; // rax
unsigned int v2; // eax
unsigned int v3; // eax
time_t timer; // [rsp+0h] [rbp-10h] BYREF

if ( dyn_display <= 0 )
{
timer = (unsigned int)swapi(a1[3]);
v1 = ctime(&timer);
mprintf(" Timestamp:\t\t%s", v1);
v2 = swapi(a1[4]);
mprintf(" Current version:\t0x%x\n", v2);
v3 = swapi(a1[5]);
mprintf(" Compat version:\t0x%x\n", v3);
}
else
{
trigger = 1;
}
}

canonical_decompiled_code:
void __fastcall func11(unsigned int *a1)
{
char *v1; // rax
unsigned int v2; // eax
unsigned int v3; // eax
time_t timer; // [rsp+0h] [rbp-10h] BYREF

if ( dyn_display <= 0 )
{
timer = (unsigned int)func5(a1[3]);
v1 = ctime(&timer);
func0(" Timestamp:\t\t%s", v1);
v2 = func5(a1[4]);
func0(" Current version:\t0x%x\n", v2);
v3 = func5(a1[5]);
func0(" Compat version:\t0x%x\n", v3);
}
else
{
trigger = 1;
}
}

original_code:
void
print_lc_load_dylib(struct dylib_command *dly)
{
 time_t timev;
 if (dyn_display < 1) {
  timev = swapi(dly->dylib.timestamp);
  mprintf("    Timestamp:		%s", ctime(&timev));
  mprintf("    Current version:	0x%x\n", swapi(dly->dylib.current_version));
  mprintf("    Compat version:	0x%x\n", swapi(dly->dylib.compatibility_version));
 } else {
  trigger = 0;
  trigger = 1;
 }
}

canonical_original_code:
void print_lc_load_dylib(struct dylib_command *dly)
{
 long timev;
 if (dyn_display < 1) {
  timev = swapi(dly->dylib.timestamp);
  mprintf("    Timestamp:		%s", ctime(&timev));
  mprintf("    Current version:	0x%x\n", swapi(dly->dylib.current_version));
  mprintf("    Compat version:	0x%x\n", swapi(dly->dylib.compatibility_version));
 } else {
  trigger = 0;
  trigger = 1;
 }
}

variable_types: struct dylib_command { unsigned int cmd; unsigned int cmdsize; struct dylib { union lc_str { unsigned int offset; } name; unsigned int timestamp; unsigned int current_version; unsigned int compatibility_version; } dylib; } *

variable_types: timev long

user_defined_types: struct dylib_command { unsigned int cmd; unsigned int cmdsize; struct dylib dylib; }

user_defined_types: struct dylib { union lc_str name; unsigned int timestamp; unsigned int current_version; unsigned int compatibility_version; }


decompiled_code:
int __fastcall print_lc_symtab(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

v1 = swapi(a1[2]);
mprintf(" Symbol table offset:\t%d bytes\n", v1);
v2 = swapi(a1[3]);
mprintf(" Symbol table entries:\t%d\n", v2);
v3 = swapi(a1[4]);
mprintf(" String table offset:\t%d bytes\n", v3);
v4 = swapi(a1[5]);
return mprintf(" String table size:\t\t%d bytes\n", v4);
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

v1 = func5(a1[2]);
func0(" Symbol table offset:\t%d bytes\n", v1);
v2 = func5(a1[3]);
func0(" Symbol table entries:\t%d\n", v2);
v3 = func5(a1[4]);
func0(" String table offset:\t%d bytes\n", v3);
v4 = func5(a1[5]);
return func0(" String table size:\t\t%d bytes\n", v4);
}

original_code:
void
print_lc_symtab(struct symtab_command *symc)
{
 mprintf("    Symbol table offset:	%d bytes\n", swapi(symc->symoff));
 mprintf("    Symbol table entries:	%d\n", swapi(symc->nsyms));
 mprintf("    String table offset:	%d bytes\n", swapi(symc->stroff));
 mprintf("    String table size:		%d bytes\n", swapi(symc->strsize));
}

variable_types: struct symtab_command { unsigned int cmd; unsigned int cmdsize; unsigned int symoff; unsigned int nsyms; unsigned int stroff; unsigned int strsize; } *


decompiled_code:
int __fastcall print_lc_segment(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax

mprintf(" Name:\t\t%s\n", (const char *)(a1 + 8));
v1 = swapi(*(_DWORD *)(a1 + 24));
mprintf(" VM addr:\t\t0x%.08x\n", v1);
v2 = swapi(*(_DWORD *)(a1 + 28));
mprintf(" VM size:\t\t0x%.08x\n", v2);
v3 = swapi(*(_DWORD *)(a1 + 28));
mprintf(" VM size:\t\t0x%.08x\n", v3);
v4 = swapi(*(_DWORD *)(a1 + 32));
mprintf(" File offset:\t0x%.08x\n", v4);
v5 = swapi(*(_DWORD *)(a1 + 36));
mprintf(" File size:\t\t%d bytes\n", v5);
v6 = swapi(*(_DWORD *)(a1 + 40));
mprintf(" Max prot:\t\t0x%.08x\n", v6);
v7 = swapi(*(_DWORD *)(a1 + 44));
mprintf(" Init prot:\t\t0x%.08x\n", v7);
v8 = swapi(*(_DWORD *)(a1 + 48));
mprintf(" No of sects:\t%d\n", v8);
v9 = swapi(*(_DWORD *)(a1 + 52));
return mprintf(" Flags:\t\t0x%.08x\n", v9);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax

func0(" Name:\t\t%s\n", (const char *)(a1 + 8));
v1 = func5(*(_DWORD *)(a1 + 24));
func0(" VM addr:\t\t0x%.08x\n", v1);
v2 = func5(*(_DWORD *)(a1 + 28));
func0(" VM size:\t\t0x%.08x\n", v2);
v3 = func5(*(_DWORD *)(a1 + 28));
func0(" VM size:\t\t0x%.08x\n", v3);
v4 = func5(*(_DWORD *)(a1 + 32));
func0(" File offset:\t0x%.08x\n", v4);
v5 = func5(*(_DWORD *)(a1 + 36));
func0(" File size:\t\t%d bytes\n", v5);
v6 = func5(*(_DWORD *)(a1 + 40));
func0(" Max prot:\t\t0x%.08x\n", v6);
v7 = func5(*(_DWORD *)(a1 + 44));
func0(" Init prot:\t\t0x%.08x\n", v7);
v8 = func5(*(_DWORD *)(a1 + 48));
func0(" No of sects:\t%d\n", v8);
v9 = func5(*(_DWORD *)(a1 + 52));
return func0(" Flags:\t\t0x%.08x\n", v9);
}

original_code:
void
print_lc_segment(struct segment_command *sc)
{
 mprintf("    Name:		%s\n", sc->segname);
 mprintf("    VM addr:		0x%.08x\n", swapi(sc->vmaddr));
 mprintf("    VM size:		0x%.08x\n", swapi(sc->vmsize));
 mprintf("    VM size:		0x%.08x\n", swapi(sc->vmsize));
 mprintf("    File offset:	0x%.08x\n", swapi(sc->fileoff));
 mprintf("    File size:		%d bytes\n", swapi(sc->filesize));
 mprintf("    Max prot:		0x%.08x\n", swapi(sc->maxprot));
 mprintf("    Init prot:		0x%.08x\n", swapi(sc->initprot));
 mprintf("    No of sects:	%d\n", swapi(sc->nsects));
 mprintf("    Flags:		0x%.08x\n", swapi(sc->flags));
}

variable_types: struct segment_command { unsigned int cmd; unsigned int cmdsize; char segname[16]; unsigned int vmaddr; unsigned int vmsize; unsigned int fileoff; unsigned int filesize; int maxprot; int initprot; unsigned int nsects; unsigned int flags; } *


decompiled_code:
int __fastcall print_section(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax

mprintf(" Sectname:\t%s\n", (const char *)a1);
v1 = swapi(*(_DWORD *)(a1 + 32));
mprintf(" VM addr:\t0x%.08x\n", v1);
v2 = swapi(*(_DWORD *)(a1 + 36));
mprintf(" VM size:\t%d bytes\n", v2);
v3 = swapi(*(_DWORD *)(a1 + 40));
mprintf(" Offset:\t%d\n", v3);
return mprintf("\n");
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax

func0(" Sectname:\t%s\n", (const char *)a1);
v1 = func5(*(_DWORD *)(a1 + 32));
func0(" VM addr:\t0x%.08x\n", v1);
v2 = func5(*(_DWORD *)(a1 + 36));
func0(" VM size:\t%d bytes\n", v2);
v3 = func5(*(_DWORD *)(a1 + 40));
func0(" Offset:\t%d\n", v3);
return func0("\n");
}

original_code:
void
print_section(struct section *sec)
{
 mprintf("     Sectname:	%s\n", sec->sectname);
 mprintf("     VM addr:	0x%.08x\n", swapi(sec->addr));
 mprintf("     VM size:	%d bytes\n", swapi(sec->size));
 mprintf("     Offset:	%d\n", swapi(sec->offset));
 mprintf("\n");
}

user_defined_types: struct section { char sectname[16]; char segname[16]; unsigned int addr; unsigned int size; unsigned int offset; unsigned int align; unsigned int reloff; unsigned int nreloc; unsigned int flags; unsigned int reserved1; unsigned int reserved2; }


decompiled_code:
int __fastcall print_load_command(unsigned int *a1)
{
int v1; // eax
unsigned int v2; // eax

mprintf(" Command:\t");
v1 = swapi(*a1);
display_cmd_name(v1);
v2 = swapi(a1[1]);
return mprintf(" Command size:\t%d bytes\n", v2);
}

canonical_decompiled_code:
int __fastcall func15(unsigned int *a1)
{
int v1; // eax
unsigned int v2; // eax

func0(" Command:\t");
v1 = func5(*a1);
func1(v1);
v2 = func5(a1[1]);
return func0(" Command size:\t%d bytes\n", v2);
}

original_code:
void
print_load_command(struct load_command *ld)
{
 mprintf("    Command:	");
 display_cmd_name(swapi(ld->cmd));
 mprintf("    Command size:	%d bytes\n", swapi(ld->cmdsize));
}

user_defined_types: struct load_command { unsigned int cmd; unsigned int cmdsize; }


decompiled_code:
int __fastcall print_mo_header(unsigned int *a1)
{
unsigned int v1; // eax
int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax

v1 = swapi(*a1);
mprintf("Magic:\t\t0x%x\n", v1);
mprintf(" CPU Type:\t");
v2 = swapi(a1[1]);
display_cpu_arch(v2);
mprintf("\n");
v3 = swapi(a1[2]);
mprintf(" Subtype:\t%d\n", v3);
v4 = swapi(a1[3]);
mprintf(" Filetype:\t0x%x\n", v4);
v5 = swapi(a1[4]);
mprintf(" No load cmds:\t%d cmds\n", v5);
v6 = swapi(a1[5]);
mprintf(" Size of cmds:\t%d bytes\n", v6);
v7 = swapi(a1[6]);
mprintf(" Flags:\t\t0x%.08x\n", v7);
return mprintf("\n");
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1)
{
unsigned int v1; // eax
int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax

v1 = func5(*a1);
func0("Magic:\t\t0x%x\n", v1);
func0(" CPU Type:\t");
v2 = func5(a1[1]);
func2(v2);
func0("\n");
v3 = func5(a1[2]);
func0(" Subtype:\t%d\n", v3);
v4 = func5(a1[3]);
func0(" Filetype:\t0x%x\n", v4);
v5 = func5(a1[4]);
func0(" No load cmds:\t%d cmds\n", v5);
v6 = func5(a1[5]);
func0(" Size of cmds:\t%d bytes\n", v6);
v7 = func5(a1[6]);
func0(" Flags:\t\t0x%.08x\n", v7);
return func0("\n");
}

original_code:
void
print_mo_header(struct mach_header *mh)
{
 mprintf("Magic:		0x%x\n", swapi(mh->magic));
 mprintf(" CPU Type:	");
 display_cpu_arch(swapi(mh->cputype));
 mprintf("\n");
 mprintf(" Subtype:	%d\n", swapi(mh->cpusubtype));
 mprintf(" Filetype:	0x%x\n", swapi(mh->filetype));
 mprintf(" No load cmds:	%d cmds\n", swapi(mh->ncmds));
 mprintf(" Size of cmds:	%d bytes\n", swapi(mh->sizeofcmds));
 mprintf(" Flags:		0x%.08x\n", swapi(mh->flags));
 mprintf("\n");
}

user_defined_types: struct mach_header { unsigned int magic; int cputype; int cpusubtype; unsigned int filetype; unsigned int ncmds; unsigned int sizeofcmds; unsigned int flags; }


decompiled_code:
int __fastcall print_fat_header(unsigned int *a1)
{
unsigned int v1; // eax

v1 = swapi(*a1);
return mprintf("Magic:\t\t0x%x\n", v1);
}

canonical_decompiled_code:
int __fastcall func17(unsigned int *a1)
{
unsigned int v1; // eax

v1 = func5(*a1);
return func0("Magic:\t\t0x%x\n", v1);
}

original_code:
void
print_fat_header(struct fat_header *fh)
{
 mprintf("Magic:		0x%x\n", swapi(fh->magic));
}

variable_types: struct fat_header { unsigned int magic; unsigned int nfat_arch; } *


variable_types: struct fat_arch { int cputype; int cpusubtype; unsigned int offset; unsigned int size; unsigned int align; } *


decompiled_code:
_QWORD *list_create_list()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

original_code:
struct list *
list_create_list()
{
 struct list *list;
 list = malloc(sizeof(struct list));
 if (list != ((void *)0)) {
  list->head = list->tail = ((void *)0);
  list->len = 0;
  return (list);
 }
 return (((void *)0));
}

canonical_original_code:
struct list *list_create_list()
{
 struct list *list;
 list = malloc(sizeof(struct list));
 if (list != ((void *)0)) {
  list->head = list->tail = ((void *)0);
  list->len = 0;
  return (list);
 }
 return (((void *)0));
}

variable_types: struct list { struct node { void *content; unsigned int code; struct node *next; struct node *prev; } *head; struct node *tail; unsigned int len; } *