decompiled_code:
void __fastcall xml_builder_destroy(__int64 a1)
{
void (*v1)(void); // rax

if ( a1 )
{
v1 = *(void (**)(void))(a1 + 48);
if ( v1 )
v1();
}
}

original_code:
static inline void xml_builder_destroy(XmlBuilder* thiz)
{
 if(thiz != ((void *)0) && thiz->destroy != ((void *)0))
 {
  thiz->destroy(thiz);
 }
 return;
}

canonical_original_code:
static inline void xml_builder_destroy(struct _XmlBuilder *thiz)
{
 if(thiz != ((void *)0) && thiz->destroy != ((void *)0))
 {
  thiz->destroy(thiz);
 }
 return;
}

variable_types: struct _XmlBuilder { void (*on_start_element)(struct _XmlBuilder *thiz, char *tag, char **attrs); void (*on_end_element)(struct _XmlBuilder *thiz, char *tag); void (*on_text)(struct _XmlBuilder *thiz, char *text, unsigned long length); void (*on_comment)(struct _XmlBuilder *thiz, char *text, unsigned long length); void (*on_pi_element)(struct _XmlBuilder *thiz, char *tag, char **attrs); void (*on_error)(struct _XmlBuilder *thiz, int line, int row, char *message); void (*destroy)(struct _XmlBuilder *thiz); char priv[1]; } *


repo: ningyuwhut/SysProPlan

decompiled_code:
void __fastcall xml_builder_dump_destroy(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
static void xml_builder_dump_destroy(XmlBuilder* thiz)
{
 if(thiz != ((void *)0))
 {
  free(thiz);
 }
 return;
}

canonical_original_code:
static void xml_builder_dump_destroy(struct _XmlBuilder *thiz)
{
 if(thiz != ((void *)0))
 {
  free(thiz);
 }
 return;
}

return_type: void

user_defined_types: struct _XmlBuilder { void (*on_start_element)(struct _XmlBuilder *thiz, char *tag, char **attrs); void (*on_end_element)(struct _XmlBuilder *thiz, char *tag); void (*on_text)(struct _XmlBuilder *thiz, char *text, unsigned long length); void (*on_comment)(struct _XmlBuilder *thiz, char *text, unsigned long length); void (*on_pi_element)(struct _XmlBuilder *thiz, char *tag, char **attrs); void (*on_error)(struct _XmlBuilder *thiz, int line, int row, char *message); void (*destroy)(struct _XmlBuilder *thiz); char priv[1]; }


decompiled_code:
int __fastcall xml_builder_dump_on_error(__int64 a1, unsigned int a2, unsigned int a3, const char *a4)
{
return fprintf(stderr, "(%d,%d) %s\n", a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, unsigned int a2, unsigned int a3, const char *a4)
{
return fprintf(stderr, "(%d,%d) %s\n", a2, a3, a4);
}

original_code:
static void xml_builder_dump_on_error(XmlBuilder* thiz, int line, int row, const char* message)
{
 fprintf(stderr, "(%d,%d) %s\n", line, row, message);
 return;
}

canonical_original_code:
static void xml_builder_dump_on_error(struct _XmlBuilder *thiz, int line, int row, char *message)
{
 fprintf(stderr, "(%d,%d) %s\n", line, row, message);
 return;
}

variable_types: line int

variable_types: row int

variable_types:
message
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 (**v3)(void); // rbx

v3 = (__int64 (**)(void))xml_builder_dump_create(stdout);
xml_builder_on_pi_element((__int64)v3);
xml_builder_on_comment((__int64)v3);
xml_builder_on_start_element(v3);
xml_builder_on_text((__int64)v3);
xml_builder_on_end_element((__int64)v3);
xml_builder_destroy((__int64)v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 (**v3)(void); // rbx

v3 = (__int64 (**)(void))xml_builder_dump_create(stdout);
func15((__int64)v3);
func16((__int64)v3);
func17(v3);
func18((__int64)v3);
func19((__int64)v3);
func7((__int64)v3);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 const char* pi_attrs[] = {"version", "1.0", "encoding", "utf-8", ((void *)0)};
 const char* root_attrs[] = {"name", "lixianjing", "blog", "http://www.limodev.cn/blog",((void *)0)};
 XmlBuilder* thiz = xml_builder_dump_create(stdout);
 xml_builder_on_pi_element(thiz, "xml", pi_attrs);
 xml_builder_on_comment(thiz,"comment", 6);
 xml_builder_on_start_element(thiz, "programmer", root_attrs);
 xml_builder_on_text(thiz,"text", 4);
 xml_builder_on_end_element(thiz, "programmer");
 xml_builder_destroy(thiz);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *pi_attrs[] = {"version", "1.0", "encoding", "utf-8", ((void *)0)};
 char *root_attrs[] = {"name", "lixianjing", "blog", "http://www.limodev.cn/blog",((void *)0)};
 struct _XmlBuilder *thiz = xml_builder_dump_create(stdout);
 xml_builder_on_pi_element(thiz, "xml", pi_attrs);
 xml_builder_on_comment(thiz,"comment", 6);
 xml_builder_on_start_element(thiz, "programmer", root_attrs);
 xml_builder_on_text(thiz,"text", 4);
 xml_builder_on_end_element(thiz, "programmer");
 xml_builder_destroy(thiz);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


original_code:
int count_word(const char* text)
{
 enum _State
 {
  STAT_INIT,
  STAT_IN_WORD,
  STAT_OUT_WORD,
 }state = STAT_INIT;
 int count = 0;
 const char* p = text;
 for(p = text; *p != '\0'; p++)
 {
  switch(state)
  {
   case STAT_INIT:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)))
    {
     state = STAT_IN_WORD;
    }
    else
    {
     state = STAT_OUT_WORD;
    }
    break;
   }
   case STAT_IN_WORD:
   {
    if(!(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)))
    {
     count++;
     state = STAT_OUT_WORD;
    }
    break;
   }
   case STAT_OUT_WORD:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)))
    {
     state = STAT_IN_WORD;
    }
    break;
   }
   default:break;
  }
 }
 if(state == STAT_IN_WORD)
 {
  count++;
 }
 return count;
}

canonical_original_code:
int count_word(char *text)
{
 enum _State state = STAT_INIT;
 int count = 0;
 char *p = text;
 for(p = text; *p != '\0'; p++)
 {
  switch(state)
  {
   case STAT_INIT:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)))
    {
     state = STAT_IN_WORD;
    }
    else
    {
     state = STAT_OUT_WORD;
    }
    break;
   }
   case STAT_IN_WORD:
   {
    if(!(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)))
    {
     count++;
     state = STAT_OUT_WORD;
    }
    break;
   }
   case STAT_OUT_WORD:
   {
    if((((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)))
    {
     state = STAT_IN_WORD;
    }
    break;
   }
   default:break;
  }
 }
 if(state == STAT_IN_WORD)
 {
  count++;
 }
 return count;
}

variable_types:
text
char *

variable_types: enum _State { STAT_INIT=0, STAT_IN_WORD=1, STAT_OUT_WORD=2 }

variable_types: count int

variable_types:
p
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)count_word("") )
__assert_fail("count_word(\"\") == 0", "count_word.c", 0x44u, "main");
if ( (unsigned int)count_word(" ") )
__assert_fail("count_word(\" \") == 0", "count_word.c", 0x45u, "main");
if ( (unsigned int)count_word("it") != 1 )
__assert_fail("count_word(\"it\") == 1", "count_word.c", 0x46u, "main");
if ( (unsigned int)count_word("it ") != 1 )
__assert_fail("count_word(\"it \") == 1", "count_word.c", 0x47u, "main");
if ( (unsigned int)count_word("it is") != 2 )
__assert_fail("count_word(\"it is\") == 2", "count_word.c", 0x48u, "main");
if ( (unsigned int)count_word("it is used to count words.") != 6 )
__assert_fail("count_word(\"it is used to count words.\") == 6", "count_word.c", 0x49u, "main");
if ( (unsigned int)count_word("it is used to count words. is it easy?") != 9 )
__assert_fail("count_word(\"it is used to count words. is it easy?\") == 9", "count_word.c", 0x4Au, "main");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func7("") )
__assert_fail("count_word(\"\") == 0", "count_word.c", 0x44u, "main");
if ( (unsigned int)func7(" ") )
__assert_fail("count_word(\" \") == 0", "count_word.c", 0x45u, "main");
if ( (unsigned int)func7("it") != 1 )
__assert_fail("count_word(\"it\") == 1", "count_word.c", 0x46u, "main");
if ( (unsigned int)func7("it ") != 1 )
__assert_fail("count_word(\"it \") == 1", "count_word.c", 0x47u, "main");
if ( (unsigned int)func7("it is") != 2 )
__assert_fail("count_word(\"it is\") == 2", "count_word.c", 0x48u, "main");
if ( (unsigned int)func7("it is used to count words.") != 6 )
__assert_fail("count_word(\"it is used to count words.\") == 6", "count_word.c", 0x49u, "main");
if ( (unsigned int)func7("it is used to count words. is it easy?") != 9 )
__assert_fail("count_word(\"it is used to count words. is it easy?\") == 9", "count_word.c", 0x4Au, "main");
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 ((void) sizeof ((count_word("") == 0) ? 1 : 0), __extension__ ({ if (count_word("") == 0) ; else __assert_fail ("count_word(\"\") == 0", "count_word.c", 68, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word(" ") == 0) ? 1 : 0), __extension__ ({ if (count_word(" ") == 0) ; else __assert_fail ("count_word(\" \") == 0", "count_word.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it") == 1) ? 1 : 0), __extension__ ({ if (count_word("it") == 1) ; else __assert_fail ("count_word(\"it\") == 1", "count_word.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it ") == 1) ? 1 : 0), __extension__ ({ if (count_word("it ") == 1) ; else __assert_fail ("count_word(\"it \") == 1", "count_word.c", 71, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it is") == 2) ? 1 : 0), __extension__ ({ if (count_word("it is") == 2) ; else __assert_fail ("count_word(\"it is\") == 2", "count_word.c", 72, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it is used to count words.") == 6) ? 1 : 0), __extension__ ({ if (count_word("it is used to count words.") == 6) ; else __assert_fail ("count_word(\"it is used to count words.\") == 6", "count_word.c", 73, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it is used to count words. is it easy?") == 9) ? 1 : 0), __extension__ ({ if (count_word("it is used to count words. is it easy?") == 9) ; else __assert_fail ("count_word(\"it is used to count words. is it easy?\") == 9", "count_word.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 ((void) sizeof ((count_word("") == 0) ? 1 : 0), __extension__ ({ if (count_word("") == 0) ; else __assert_fail ("count_word(\"\") == 0", "count_word.c", 68, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word(" ") == 0) ? 1 : 0), __extension__ ({ if (count_word(" ") == 0) ; else __assert_fail ("count_word(\" \") == 0", "count_word.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it") == 1) ? 1 : 0), __extension__ ({ if (count_word("it") == 1) ; else __assert_fail ("count_word(\"it\") == 1", "count_word.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it ") == 1) ? 1 : 0), __extension__ ({ if (count_word("it ") == 1) ; else __assert_fail ("count_word(\"it \") == 1", "count_word.c", 71, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it is") == 2) ? 1 : 0), __extension__ ({ if (count_word("it is") == 2) ; else __assert_fail ("count_word(\"it is\") == 2", "count_word.c", 72, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it is used to count words.") == 6) ? 1 : 0), __extension__ ({ if (count_word("it is used to count words.") == 6) ; else __assert_fail ("count_word(\"it is used to count words.\") == 6", "count_word.c", 73, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((count_word("it is used to count words. is it easy?") == 9) ? 1 : 0), __extension__ ({ if (count_word("it is used to count words. is it easy?") == 9) ; else __assert_fail ("count_word(\"it is used to count words. is it easy?\") == 9", "count_word.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 return 0;
}


decompiled_code:
void *__fastcall allocator_normal_calloc(__int64 a1, size_t a2, size_t a3)
{
return calloc(a2, a3);
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, size_t a2, size_t a3)
{
return calloc(a2, a3);
}

original_code:
static void* allocator_normal_calloc(Allocator* thiz, size_t nmemb, size_t size)
{
 return calloc(nmemb, size);
}

canonical_original_code:
static void *allocator_normal_calloc(struct _Allocator *thiz, unsigned long nmemb, unsigned long size)
{
 return calloc(nmemb, size);
}

variable_types: struct _Allocator { void *(*calloc)(struct _Allocator *thiz, unsigned long nmemb, unsigned long size); void *(*alloc)(struct _Allocator *thiz, unsigned long size); void (*free)(struct _Allocator *thiz, void *ptr); void *(*realloc)(struct _Allocator *thiz, void *ptr, unsigned long size); void (*destroy)(struct _Allocator *thiz); char priv[]; } *

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

return_type: void *


decompiled_code:
void __fastcall allocator_normal_destroy(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
static void allocator_normal_destroy(Allocator* thiz)
{
 if(thiz != ((void *)0))
 {
  free(thiz);
 }
 return;
}

canonical_original_code:
static void allocator_normal_destroy(struct _Allocator *thiz)
{
 if(thiz != ((void *)0))
 {
  free(thiz);
 }
 return;
}

user_defined_types: struct _Allocator { void *(*calloc)(struct _Allocator *thiz, unsigned long nmemb, unsigned long size); void *(*alloc)(struct _Allocator *thiz, unsigned long size); void (*free)(struct _Allocator *thiz, void *ptr); void *(*realloc)(struct _Allocator *thiz, void *ptr, unsigned long size); void (*destroy)(struct _Allocator *thiz); char priv[]; }


decompiled_code:
void __fastcall allocator_normal_free(__int64 a1, void *a2)
{
free(a2);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, void *a2)
{
free(a2);
}

original_code:
static void allocator_normal_free(Allocator* thiz, void *ptr)
{
 free(ptr);
 return;
}

canonical_original_code:
static void allocator_normal_free(struct _Allocator *thiz, void *ptr)
{
 free(ptr);
 return;
}

variable_types:
ptr
void *


decompiled_code:
void *__fastcall allocator_normal_realloc(__int64 a1, void *a2, size_t a3)
{
return realloc(a2, a3);
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, void *a2, size_t a3)
{
return realloc(a2, a3);
}

original_code:
static void* allocator_normal_realloc(Allocator* thiz, void *ptr, size_t size)
{
 return realloc(ptr, size);
}

canonical_original_code:
static void *allocator_normal_realloc(struct _Allocator *thiz, void *ptr, unsigned long size)
{
 return realloc(ptr, size);
}


decompiled_code:
void *__fastcall allocator_normal_alloc(__int64 a1, size_t a2)
{
return malloc(a2);
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1, size_t a2)
{
return malloc(a2);
}

original_code:
static void* allocator_normal_alloc(Allocator* thiz, size_t size)
{
 return malloc(size);
}

canonical_original_code:
static void *allocator_normal_alloc(struct _Allocator *thiz, unsigned long size)
{
 return malloc(size);
}


decompiled_code:
__int64 __fastcall allocator_alloc(__int64 a1)
{
__int64 (*v1)(void); // rax

if ( a1 )
{
v1 = *(__int64 (**)(void))(a1 + 8);
if ( v1 )
return v1();
}
printf("%s:%d Warning: thiz != NULL && thiz->alloc != NULL failed.\n", "allocator_alloc", 38LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 (*v1)(void); // rax

if ( a1 )
{
v1 = *(__int64 (**)(void))(a1 + 8);
if ( v1 )
return v1();
}
printf("%s:%d Warning: thiz != NULL && thiz->alloc != NULL failed.\n", "allocator_alloc", 38LL);
return 0LL;
}

original_code:
static inline void* allocator_alloc(Allocator* thiz, size_t size)
{
 if(!(thiz != ((void *)0) && thiz->alloc != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->alloc != NULL"" failed.\n", __func__, 38); return (((void *)0));};
 return thiz->alloc(thiz, size);
}

canonical_original_code:
static inline void *allocator_alloc(struct _Allocator *thiz, unsigned long size)
{
 if(!(thiz != ((void *)0) && thiz->alloc != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->alloc != NULL"" failed.\n", __func__, 38); return (((void *)0));};
 return thiz->alloc(thiz, size);
}


decompiled_code:
__int64 __fastcall allocator_realloc(__int64 a1)
{
__int64 (*v1)(void); // rax

if ( a1 )
{
v1 = *(__int64 (**)(void))(a1 + 24);
if ( v1 )
return v1();
}
printf("%s:%d Warning: thiz != NULL && thiz->realloc != NULL failed.\n", "allocator_realloc", 54LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 (*v1)(void); // rax

if ( a1 )
{
v1 = *(__int64 (**)(void))(a1 + 24);
if ( v1 )
return v1();
}
printf("%s:%d Warning: thiz != NULL && thiz->realloc != NULL failed.\n", "allocator_realloc", 54LL);
return 0LL;
}

original_code:
static inline void* allocator_realloc(Allocator* thiz, void *ptr, size_t size)
{
 if(!(thiz != ((void *)0) && thiz->realloc != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->realloc != NULL"" failed.\n", __func__, 54); return (((void *)0));};
 return thiz->realloc(thiz, ptr, size);
}

canonical_original_code:
static inline void *allocator_realloc(struct _Allocator *thiz, void *ptr, unsigned long size)
{
 if(!(thiz != ((void *)0) && thiz->realloc != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->realloc != NULL"" failed.\n", __func__, 54); return (((void *)0));};
 return thiz->realloc(thiz, ptr, size);
}


decompiled_code:
int __fastcall allocator_free(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 16)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->free != NULL failed.\n", "allocator_free", 45LL);
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 16)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->free != NULL failed.\n", "allocator_free", 45LL);
return result;
}

original_code:
static inline void allocator_free(Allocator* thiz, void *ptr)
{
 if(!(thiz != ((void *)0) && thiz->free != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->free != NULL"" failed.\n", __func__, 45); return;};
 thiz->free(thiz, ptr);
 return;
}

canonical_original_code:
static inline void allocator_free(struct _Allocator *thiz, void *ptr)
{
 if(!(thiz != ((void *)0) && thiz->free != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->free != NULL"" failed.\n", __func__, 45); return;};
 thiz->free(thiz, ptr);
 return;
}


decompiled_code:
int __fastcall allocator_destroy(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 32)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->destroy != NULL failed.\n", "allocator_destroy", 61LL);
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 32)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->destroy != NULL failed.\n", "allocator_destroy", 61LL);
return result;
}

original_code:
static inline void allocator_destroy(Allocator* thiz)
{
 if(!(thiz != ((void *)0) && thiz->destroy != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->destroy != NULL"" failed.\n", __func__, 61); return;};
 return thiz->destroy(thiz);
}

canonical_original_code:
static inline void allocator_destroy(struct _Allocator *thiz)
{
 if(!(thiz != ((void *)0) && thiz->destroy != ((void *)0))) {printf("%s:%d Warning: ""thiz != NULL && thiz->destroy != NULL"" failed.\n", __func__, 61); return;};
 return thiz->destroy(thiz);
}


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

result = calloc(1uLL, 0x28uLL);
if ( result )
{
*result = allocator_normal_calloc;
result[1] = allocator_normal_alloc;
result[3] = allocator_normal_realloc;
result[2] = allocator_normal_free;
result[4] = allocator_normal_destroy;
}
return result;
}

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

result = calloc(1uLL, 0x28uLL);
if ( result )
{
*result = allocator_normal_calloc;
result[1] = allocator_normal_alloc;
result[3] = allocator_normal_realloc;
result[2] = allocator_normal_free;
result[4] = allocator_normal_destroy;
}
return result;
}

original_code:
Allocator* allocator_normal_create(void)
{
 Allocator* thiz = (Allocator*)calloc(1, sizeof(Allocator));
 if(thiz != ((void *)0))
 {
  thiz->calloc = allocator_normal_calloc;
  thiz->alloc = allocator_normal_alloc;
  thiz->realloc = allocator_normal_realloc;
  thiz->free = allocator_normal_free;
  thiz->destroy = allocator_normal_destroy;
 }
 return thiz;
}

canonical_original_code:
struct _Allocator *allocator_normal_create()
{
 struct _Allocator *thiz = (Allocator*)calloc(1, sizeof(Allocator));
 if(thiz != ((void *)0))
 {
  thiz->calloc = allocator_normal_calloc;
  thiz->alloc = allocator_normal_alloc;
  thiz->realloc = allocator_normal_realloc;
  thiz->free = allocator_normal_free;
  thiz->destroy = allocator_normal_destroy;
 }
 return thiz;
}

return_type: struct _Allocator { void *(*calloc)(struct _Allocator *thiz, unsigned long nmemb, unsigned long size); void *(*alloc)(struct _Allocator *thiz, unsigned long size); void (*free)(struct _Allocator *thiz, void *ptr); void *(*realloc)(struct _Allocator *thiz, void *ptr, unsigned long size); void (*destroy)(struct _Allocator *thiz); char priv[]; } *


accumlate

decompiled_code:
__int64 __fastcall accumlate(int a1)
{
int *v1; // rax
unsigned int v2; // edx
int v4; // [rsp+0h] [rbp-4h] BYREF
void *retaddr; // [rsp+4h] [rbp+0h] BYREF

v4 = a1;
if ( a1 <= 0 )
return 0;
v1 = (int *)&retaddr;
v2 = 0;
do
v2 += *v1++;
while ( v1 != &v4 + (unsigned int)(a1 + 1) );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int *v1; // rax
unsigned int v2; // edx
int v4; // [rsp+0h] [rbp-4h] BYREF
void *retaddr; // [rsp+4h] [rbp+0h] BYREF

v4 = a1;
if ( a1 <= 0 )
return 0;
v1 = (int *)&retaddr;
v2 = 0;
do
v2 += *v1++;
while ( v1 != &v4 + (unsigned int)(a1 + 1) );
return v2;
}

original_code:
int accumlate(int nr, ...)
{
    int i = 0;
    int result = 0;
    void* arg = ((void *)0);
    arg = (void*)(((char*)&(nr)) + sizeof(nr));
    for(i = 0; i < nr; i++)
    {
        result += *(int*)arg; arg = (char*)arg + sizeof(int);;
    }
    ;
    return result;
}

canonical_original_code:
int accumlate(int nr, ...)
{
    int i = 0;
    int result = 0;
    void *arg = ((void *)0);
    arg = (void *)(((char *)&(nr)) + sizeof(nr));
    for(i = 0; i < nr; i++)
    {
        result += *(int *)arg; arg = (char *)arg + sizeof(int);;
    }
    ;
    return result;
}

variable_types: nr int

variable_types: i int

variable_types: result int

variable_types:
arg
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

v3 = accumlate(1);
printf("%d\n", v3);
v4 = accumlate(2);
printf("%d\n", v4);
v5 = accumlate(3);
printf("%d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

v3 = func7(1);
printf("%d\n", v3);
v4 = func7(2);
printf("%d\n", v4);
v5 = func7(3);
printf("%d\n", v5);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
    printf("%d\n", accumlate(1, 100));
    printf("%d\n", accumlate(2, 100, 200));
    printf("%d\n", accumlate(3, 100, 200, 300));
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    printf("%d\n", accumlate(1, 100));
    printf("%d\n", accumlate(2, 100, 200));
    printf("%d\n", accumlate(3, 100, 200, 300));
    return 0;
}


canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 32)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->destroy != NULL failed.\n", "allocator_destroy", 61LL);
return result;
}


canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
__int64 (*v1)(void); // rax
int result; // eax

if ( a1 && (v1 = *(__int64 (**)(void))(a1 + 16)) != 0LL )
result = v1();
else
result = printf("%s:%d Warning: thiz != NULL && thiz->free != NULL failed.\n", "allocator_free", 45LL);
return result;
}


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

if ( a1 )
{
v1 = *(__int64 (**)(void))(a1 + 8);
if ( v1 )
return v1();
}
printf("%s:%d Warning: thiz != NULL && thiz->alloc != NULL failed.\n", "allocator_alloc", 38LL);
return 0LL;
}


canonical_decompiled_code:
void *__fastcall func14(__int64 a1, size_t a2, size_t a3)
{
return calloc(a2, a3);
}


canonical_decompiled_code:
void __fastcall func15(void *a1)
{
if ( a1 )
free(a1);
}


canonical_decompiled_code:
void __fastcall func16(__int64 a1, void *a2)
{
free(a2);
}


canonical_decompiled_code:
void *__fastcall func17(__int64 a1, void *a2, size_t a3)
{
return realloc(a2, a3);
}


canonical_decompiled_code:
void *__fastcall func18(__int64 a1, size_t a2)
{
return malloc(a2);
}


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

result = calloc(1uLL, 0x28uLL);
if ( result )
{
*result = allocator_normal_calloc;
result[1] = allocator_normal_alloc;
result[3] = allocator_normal_realloc;
result[2] = allocator_normal_free;
result[4] = allocator_normal_destroy;
}
return result;
}


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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

original_code:
DList* dlist_create(DataDestroyFunc data_destroy, void* ctx)
{
 DList* thiz = malloc(sizeof(DList));
 if(thiz != ((void *)0))
 {
  thiz->first = ((void *)0);
  thiz->data_destroy = data_destroy;
  thiz->data_destroy_ctx = ctx;
 }
 return thiz;
}

canonical_original_code:
struct _DList *dlist_create(void (*data_destroy)(void *ctx, void *data), void *ctx)
{
 struct _DList *thiz = malloc(sizeof(DList));
 if(thiz != ((void *)0))
 {
  thiz->first = ((void *)0);
  thiz->data_destroy = data_destroy;
  thiz->data_destroy_ctx = ctx;
 }
 return thiz;
}

variable_types:
ctx
void *

variable_types: struct _DList { struct _DListNode { struct _DListNode *prev; struct _DListNode *next; void *data; } *first; void *data_destroy_ctx; void (*data_destroy)(void *ctx, void *data); } *

user_defined_types: struct _DList { struct _DListNode *first; void *data_destroy_ctx; void (*data_destroy)(void *ctx, void *data); }


decompiled_code:
__int64 __fastcall dlist_prepend(__int64 *a1, __int64 a2)
{
return dlist_insert(a1, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 *a1, __int64 a2)
{
return func14(a1, 0LL, a2);
}

original_code:
Ret dlist_prepend(DList* thiz, void* data)
{
 return dlist_insert(thiz, 0, data);
}

canonical_original_code:
enum _Ret dlist_prepend(struct _DList *thiz, void *data)
{
 return dlist_insert(thiz, 0, data);
}

variable_types:
data
void *

return_type: enum _Ret { RET_OK=0, RET_OOM=1, RET_STOP=2, RET_INVALID_PARAMS=3, RET_FAIL=4 }

user_defined_types: struct _DListNode { struct _DListNode *prev; struct _DListNode *next; void *data; }


decompiled_code:
__int64 __fastcall dlist_append(__int64 *a1, __int64 a2)
{
return dlist_insert(a1, 0xFFFFFFFFFFFFFFFFLL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 *a1, __int64 a2)
{
return func14(a1, 0xFFFFFFFFFFFFFFFFLL, a2);
}

original_code:
Ret dlist_append(DList* thiz, void* data)
{
 return dlist_insert(thiz, -1, data);
}

canonical_original_code:
enum _Ret dlist_append(struct _DList *thiz, void *data)
{
 return dlist_insert(thiz, -1, data);
}

user_defined_types: enum _Ret { RET_OK=0, RET_OOM=1, RET_STOP=2, RET_INVALID_PARAMS=3, RET_FAIL=4 }


decompiled_code:
__int64 __fastcall print_int(__int64 a1, __int64 a2)
{
printf("%d ", a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, __int64 a2)
{
printf("%d ", a2);
return 0LL;
}

original_code:
static Ret print_int(void* ctx, void* data)
{
 printf("%d ", (int)data);
 return RET_OK;
}

canonical_original_code:
static enum _Ret print_int(void *ctx, void *data)
{
 printf("%d ", (int)data);
 return RET_OK;
}


return_type: struct _DList { struct _DListNode { struct _DListNode *prev; struct _DListNode *next; void *data; } *first; void *data_destroy_ctx; void (*data_destroy)(void *ctx, void *data); } *


decompiled_code:
__int64 __fastcall print_int(__int64 a1)
{
printf("%d ", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
printf("%d ", a1);
return 0LL;
}


decompiled_code:
__int64 __fastcall int_cmp(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

original_code:
int int_cmp(void* a, void* b)
{
 return (int)a - (int)b;
}

canonical_original_code:
int int_cmp(void *a, void *b)
{
 return (int)a - (int)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx

for ( i = 1LL; i != 1000; ++i )
search_test(i);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx

for ( i = 1LL; i != 1000; ++i )
func9(i);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 srand(100);
 sort_test(quick_sort);
 sort_test(merge_sort);
 sort_test(bubble_sort);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 srand(100);
 sort_test(quick_sort);
 sort_test(merge_sort);
 sort_test(bubble_sort);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


LoadSceneFromFile

repo: niofis/LightBend

decompiled_code:
_BOOL8 __fastcall LoadSceneFromFile(const char *a1)
{
return !MS3DLoadFromFile(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
return !func0(a1);
}

original_code:
int LoadSceneFromFile(const char* file)
{
 if(!MS3DLoadFromFile(file))
  return 1;
    return 0;
}

canonical_original_code:
int LoadSceneFromFile(char *file)
{
 if(!MS3DLoadFromFile(file))
  return 1;
    return 0;
}

variable_types:
file
char *


decompiled_code:
void MS3DClean()
{
__int64 v0; // rbp
int v1; // ebx

free(ms3d_arrVertices);
free(ms3d_arrTriangles);
free(ms3d_arrMaterials);
if ( ms3d_numGroups )
{
v0 = 0LL;
v1 = 0;
do
{
free(*(void **)((char *)ms3d_arrGroups + v0 + 40));
++v1;
v0 += 56LL;
}
while ( (unsigned __int16)ms3d_numGroups > v1 );
}
free(ms3d_arrGroups);
}

canonical_decompiled_code:
void func2()
{
__int64 v0; // rbp
int v1; // ebx

free(ms3d_arrVertices);
free(ms3d_arrTriangles);
free(ms3d_arrMaterials);
if ( ms3d_numGroups )
{
v0 = 0LL;
v1 = 0;
do
{
free(*(void **)((char *)ms3d_arrGroups + v0 + 40));
++v1;
v0 += 56LL;
}
while ( (unsigned __int16)ms3d_numGroups > v1 );
}
free(ms3d_arrGroups);
}

original_code:
void MS3DClean()
{
 int i;
 free(ms3d_arrVertices);
 free(ms3d_arrTriangles);
 free(ms3d_arrMaterials);
 for (i = 0; i < ms3d_numGroups; i++)
 {
  free(ms3d_arrGroups[i].triangleIndices);
 }
 free(ms3d_arrGroups);
}


decompiled_code:
__int64 MS3DGetNumVertices()
{
return (unsigned __int16)ms3d_numVertices;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int16)ms3d_numVertices;
}

original_code:
int MS3DGetNumVertices()
{
 return (int) ms3d_numVertices;
}


decompiled_code:
char *__fastcall MS3DGetVertexAt(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numVertices )
result = (char *)ms3d_arrVertices + 20 * (int)a1;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numVertices )
result = (char *)ms3d_arrVertices + 20 * (int)a1;
return result;
}

original_code:
ms3d_vertex_t* MS3DGetVertexAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int) ms3d_numVertices)
  return &ms3d_arrVertices[nIndex];
 return ((void *)0);
}

canonical_original_code:
struct ms3d_vertex_t *MS3DGetVertexAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int) ms3d_numVertices)
  return &ms3d_arrVertices[nIndex];
 return ((void *)0);
}

variable_types: nIndex int

return_type: struct ms3d_vertex_t { unsigned char flags; float vertex[3]; char boneId; unsigned char referenceCount; } *


decompiled_code:
__int64 MS3DGetNumTriangles()
{
return (unsigned __int16)ms3d_numTriangles;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned __int16)ms3d_numTriangles;
}

original_code:
int MS3DGetNumTriangles()
{
 return (int) ms3d_numTriangles;
}


decompiled_code:
char *__fastcall MS3DGetTriangleAt(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numTriangles )
result = (char *)ms3d_arrTriangles + 72 * (int)a1;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numTriangles )
result = (char *)ms3d_arrTriangles + 72 * (int)a1;
return result;
}

original_code:
ms3d_triangle_t* MS3DGetTriangleAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int)ms3d_numTriangles)
  return &ms3d_arrTriangles[nIndex];
 return ((void *)0);
}

canonical_original_code:
struct ms3d_triangle_t *MS3DGetTriangleAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int)ms3d_numTriangles)
  return &ms3d_arrTriangles[nIndex];
 return ((void *)0);
}

return_type: struct ms3d_triangle_t { unsigned short flags; unsigned short vertexIndices[3]; float vertexNormals[3][3]; float s[3]; float t[3]; unsigned char smoothingGroup; unsigned char groupIndex; } *


decompiled_code:
__int64 MS3DGetNumGroups()
{
return (unsigned __int16)ms3d_numGroups;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int16)ms3d_numGroups;
}

original_code:
int MS3DGetNumGroups()
{
 return (int) ms3d_numGroups;
}


decompiled_code:
char *__fastcall MS3DGetGroupAt(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numGroups )
result = (char *)ms3d_arrGroups + 56 * (int)a1;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numGroups )
result = (char *)ms3d_arrGroups + 56 * (int)a1;
return result;
}

original_code:
ms3d_group_t* MS3DGetGroupAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int) ms3d_numGroups)
  return &ms3d_arrGroups[nIndex];
 return ((void *)0);
}

canonical_original_code:
struct ms3d_group_t *MS3DGetGroupAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int) ms3d_numGroups)
  return &ms3d_arrGroups[nIndex];
 return ((void *)0);
}

return_type: struct ms3d_group_t { unsigned char flags; char name[32]; unsigned short numtriangles; unsigned short *triangleIndices; char materialIndex; } *


decompiled_code:
__int64 MS3DGetNumMaterials()
{
return (unsigned __int16)ms3d_numMaterials;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int16)ms3d_numMaterials;
}

original_code:
int MS3DGetNumMaterials()
{
 return (int) ms3d_numMaterials;
}


decompiled_code:
char *__fastcall MS3DGetMaterialAt(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numMaterials )
result = (char *)ms3d_arrMaterials + 364 * (int)a1;
return result;
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 < (unsigned __int16)ms3d_numMaterials )
result = (char *)ms3d_arrMaterials + 364 * (int)a1;
return result;
}

original_code:
ms3d_material_t* MS3DGetMaterialAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int) ms3d_numMaterials)
  return &ms3d_arrMaterials[nIndex];
 return ((void *)0);
}

canonical_original_code:
struct ms3d_material_t *MS3DGetMaterialAt(int nIndex)
{
 if (nIndex >= 0 && nIndex < (int) ms3d_numMaterials)
  return &ms3d_arrMaterials[nIndex];
 return ((void *)0);
}

return_type: struct ms3d_material_t { char name[32]; float ambient[4]; float diffuse[4]; float specular[4]; float emissive[4]; float shininess; float transparency; char mode; char texture[128]; char alphamap[128]; } *


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

last_frame = -1;
frame_count = 0;
max_time = 0LL;
result = LC1;
min_time = LC1;
acc_time = 0LL;
return result;
}

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

last_frame = -1;
frame_count = 0;
max_time = 0LL;
result = LC1;
min_time = LC1;
acc_time = 0LL;
return result;
}

original_code:
void reset_stats()
{
    last_frame=-1;
 frame_count=0;
 max_time=0.0;
 min_time=99999999999.0;
 acc_time=0.0;
}


original_code:
void process_args(int argc, char* args[])
{
 int i=0;
 job.width=1280;
 job.height=720;
 job.sector_y=0;
 job.sector_x=0;
 job.sector_width=job.width;
 job.sector_height=job.height;
 job.interactive=0;
 job.img_file="image.png";
 job.lua_script="script.lua";
 job.verbose=0;
 job.threads=0;
    job.run_script=0;
 for(i=0;i<argc;++i)
 {
  if(strcmp("-width",args[i])==0)
   job.width=abs(atoi(args[++i]));
  else if(strcmp("-height",args[i])==0)
   job.height=abs(atoi(args[++i]));
  else if(strcmp("-s ",args[i])==0)
  {
   job.sector_x=abs(atoi(args[++i]));
   job.sector_y=abs(atoi(args[++i]));
   job.sector_width=abs(atoi(args[++i]));
   job.sector_height=abs(atoi(args[++i]));
  }
  else if(strcmp("-i",args[i])==0)
   job.interactive=1;
  else if(strcmp("-v",args[i])==0)
   job.verbose=1;
  else if(strcmp("-png",args[i])==0)
   job.img_file=args[++i];
  else if(strcmp("-script",args[i])==0)
        {
   job.lua_script=args[++i];
            job.run_script=1;
        }
  else if(strcmp("-threads",args[i])==0)
   job.threads=abs(atoi(args[++i]));
 }
 if(job.width==0)
  job.width=640;
 if(job.height==0)
  job.height=480;
 if(job.sector_width==0)
  job.sector_width=job.width-job.sector_x;
 if(job.sector_height==0)
  job.sector_height=job.height-job.sector_y;
 if(argc==1)
  job.interactive=1;
}

canonical_original_code:
void process_args(int argc, char *args[])
{
 int i = 0;
 job.width=1280;
 job.height=720;
 job.sector_y=0;
 job.sector_x=0;
 job.sector_width=job.width;
 job.sector_height=job.height;
 job.interactive=0;
 job.img_file="image.png";
 job.lua_script="script.lua";
 job.verbose=0;
 job.threads=0;
    job.run_script=0;
 for(i=0;i<argc;++i)
 {
  if(strcmp("-width",args[i])==0)
   job.width=abs(atoi(args[++i]));
  else if(strcmp("-height",args[i])==0)
   job.height=abs(atoi(args[++i]));
  else if(strcmp("-s ",args[i])==0)
  {
   job.sector_x=abs(atoi(args[++i]));
   job.sector_y=abs(atoi(args[++i]));
   job.sector_width=abs(atoi(args[++i]));
   job.sector_height=abs(atoi(args[++i]));
  }
  else if(strcmp("-i",args[i])==0)
   job.interactive=1;
  else if(strcmp("-v",args[i])==0)
   job.verbose=1;
  else if(strcmp("-png",args[i])==0)
   job.img_file=args[++i];
  else if(strcmp("-script",args[i])==0)
        {
   job.lua_script=args[++i];
            job.run_script=1;
        }
  else if(strcmp("-threads",args[i])==0)
   job.threads=abs(atoi(args[++i]));
 }
 if(job.width==0)
  job.width=640;
 if(job.height==0)
  job.height=480;
 if(job.sector_width==0)
  job.sector_width=job.width-job.sector_x;
 if(job.sector_height==0)
  job.sector_height=job.height-job.sector_y;
 if(argc==1)
  job.interactive=1;
}

variable_types:
args
char *[]


decompiled_code:
__int64 offline_mode()
{
__int64 v0; // rbx
double v1; // r14
double v2; // xmm0_8

v0 = aligned_malloc16(4 * job[3] * job[2]);
runluascript(*(_QWORD *)&job[18]);
printf("Rendering...\n\r");
v1 = omp_get_wtime();
RenderFrame(v0, job[13]);
v2 = omp_get_wtime();
printf("Done in %8.4f s\n\r", v2 - v1);
save_image(*(_QWORD *)&job[16], job[2], job[3], v0);
CleanBVH();
CleanRenderer();
return aligned_free(v0);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
double v1; // r14
double v2; // xmm0_8

v0 = aligned_malloc16(4 * job[3] * job[2]);
runluascript(*(_QWORD *)&job[18]);
printf("Rendering...\n\r");
v1 = omp_get_wtime();
RenderFrame(v0, job[13]);
v2 = omp_get_wtime();
printf("Done in %8.4f s\n\r", v2 - v1);
save_image(*(_QWORD *)&job[16], job[2], job[3], v0);
CleanBVH();
CleanRenderer();
return aligned_free(v0);
}

original_code:
void offline_mode()
{
 double start;
 double finish;
    int* buffer=(int*) aligned_malloc16(job.width*job.height*4);
    runluascript(job.lua_script);
    printf("Rendering...\n\r");
 start=omp_get_wtime();
    RenderFrame(buffer,job.threads);
 finish=omp_get_wtime();
 printf("Done in %8.4f s\n\r",finish-start);
    save_image(job.img_file,job.width,job.height,(unsigned char*)buffer);
    CleanBVH();
    CleanRenderer();
    aligned_free(buffer);
}

canonical_original_code:
void offline_mode()
{
 double start;
 double finish;
    int *buffer = (int*) aligned_malloc16(job.width*job.height*4);
    runluascript(job.lua_script);
    printf("Rendering...\n\r");
 start=omp_get_wtime();
    RenderFrame(buffer,job.threads);
 finish=omp_get_wtime();
 printf("Done in %8.4f s\n\r",finish-start);
    save_image(job.img_file,job.width,job.height,(unsigned char *)buffer);
    CleanBVH();
    CleanRenderer();
    aligned_free(buffer);
}

variable_types: start double

variable_types: finish double

variable_types:
buffer
int *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bpp = 32;
GOMP_critical_start(argc, argv, envp);
cpu_count = omp_get_num_procs();
GOMP_critical_end();
process_args(argc, (__int64)argv);
if ( !job[13] )
job[13] = cpu_count;
omp_set_dynamic(0LL);
omp_set_num_threads(job[13]);
omp_set_nested(1LL);
if ( job[10] == 1 )
interactive_mode();
else
offline_mode();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bpp = 32;
GOMP_critical_start(argc, argv, envp);
cpu_count = omp_get_num_procs();
GOMP_critical_end();
func2(argc, (__int64)argv);
if ( !job[13] )
job[13] = cpu_count;
omp_set_dynamic(0LL);
omp_set_num_threads(job[13]);
omp_set_nested(1LL);
if ( job[10] == 1 )
func3();
else
func4();
return 0;
}

original_code:
int main(int argc, char* args[])
{
 bpp=32;

#pragma omp critical
    cpu_count=omp_get_num_procs();
    process_args(argc, args);
 if(job.threads==0)
  job.threads=cpu_count;
    omp_set_dynamic(0);
    omp_set_num_threads(job.threads);
    omp_set_nested(1);
 if(job.interactive==1)
  interactive_mode();
    else
        offline_mode();
 return 0;
}

canonical_original_code:
int main(int argc, char *args[])
{
 bpp=32;

#pragma omp critical
    cpu_count=omp_get_num_procs();
    process_args(argc, args);
 if(job.threads==0)
  job.threads=cpu_count;
    omp_set_dynamic(0);
    omp_set_num_threads(job.threads);
    omp_set_nested(1);
 if(job.interactive==1)
  interactive_mode();
    else
        offline_mode();
 return 0;
}


decompiled_code:
unsigned __int64 __fastcall aligned_malloc(int a1, int a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rcx

result = (unsigned __int64)malloc(a1 + (__int64)a2 + 8);
if ( result )
{
v3 = result;
result = a1 + result - result % a1;
*(_QWORD *)(result - 8) = v3;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, int a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rcx

result = (unsigned __int64)malloc(a1 + (__int64)a2 + 8);
if ( result )
{
v3 = result;
result = a1 + result - result % a1;
*(_QWORD *)(result - 8) = v3;
}
return result;
}

original_code:
void* aligned_malloc(int aligment, int size)
{
 size_t total;
 void* ptr;
 size_t pad;
 void* final;
 size_t t;
 pad=aligment+sizeof(size_t);
 total=size+pad;
 ptr=malloc(total);
 if(ptr==((void *)0))
  return ((void *)0);
 t=aligment - (size_t)ptr%aligment;
 final= (void*)((size_t)ptr + t);
 *((size_t*)final-1)=(size_t)ptr;
 return (void*)final;
}

canonical_original_code:
void *aligned_malloc(int aligment, int size)
{
 unsigned long total;
 void *ptr;
 unsigned long pad;
 void *final;
 unsigned long t;
 pad=aligment+sizeof(unsigned long);
 total=size+pad;
 ptr=malloc(total);
 if(ptr==((void *)0))
  return ((void *)0);
 t=aligment - (unsigned long)ptr%aligment;
 final= (void *)((unsigned long)ptr + t);
 *((unsigned long *)final-1)=(unsigned long)ptr;
 return (void *)final;
}

variable_types: aligment int

variable_types: size int

variable_types:
total
unsigned long

variable_types:
ptr
void *

variable_types:
pad
unsigned long

variable_types:
final
void *

variable_types:
t
unsigned long


decompiled_code:
unsigned __int64 __fastcall aligned_malloc16(int a1)
{
return aligned_malloc(16, a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(int a1)
{
return func0(16, a1);
}

original_code:
void* aligned_malloc16(int size)
{
 return aligned_malloc(16, size);
}

canonical_original_code:
void *aligned_malloc16(int size)
{
 return aligned_malloc(16, size);
}


decompiled_code:
void __fastcall aligned_free(__int64 a1)
{
free(*(void **)(a1 - 8));
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
free(*(void **)(a1 - 8));
}

original_code:
void aligned_free(void* mem)
{
 void* original;
 original=(void*)*((size_t*)mem-1);
 free(original);
}

canonical_original_code:
void aligned_free(void *mem)
{
 void *original;
 original=(void *)*((unsigned long *)mem-1);
 free(original);
}

variable_types:
mem
void *

variable_types:
original
void *


decompiled_code:
unsigned __int64 __fastcall aligned_realloc(_QWORD *a1, int a2, int a3)
{
unsigned __int64 result; // rax
unsigned __int64 v4; // rcx

if ( a1 )
a1 = (_QWORD *)*(a1 - 1);
result = (unsigned __int64)realloc(a1, a3);
if ( result )
{
v4 = result;
result = a2 + result - result % a2;
*(_QWORD *)(result - 8) = v4;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_QWORD *a1, int a2, int a3)
{
unsigned __int64 result; // rax
unsigned __int64 v4; // rcx

if ( a1 )
a1 = (_QWORD *)*(a1 - 1);
result = (unsigned __int64)realloc(a1, a3);
if ( result )
{
v4 = result;
result = a2 + result - result % a2;
*(_QWORD *)(result - 8) = v4;
}
return result;
}

original_code:
void* aligned_realloc(void* mem, int aligment, int size)
{
 void* original;
 size_t total;
 void* ptr;
 size_t pad;
 void* final;
 size_t t;
 pad=aligment+sizeof(size_t);
 total=size+pad;
 if(mem!=((void *)0))
  original=(void*)*((size_t*)mem-1);
 else
  original=((void *)0);
 ptr=realloc(original,size);
 if(ptr==((void *)0))
  return ((void *)0);
 t=aligment - (size_t)ptr%aligment;
 final= (void*)((size_t)ptr + t);
 *((size_t*)final-1)=(size_t)ptr;
 return (void*)final;
}

canonical_original_code:
void *aligned_realloc(void *mem, int aligment, int size)
{
 void *original;
 unsigned long total;
 void *ptr;
 unsigned long pad;
 void *final;
 unsigned long t;
 pad=aligment+sizeof(unsigned long);
 total=size+pad;
 if(mem!=((void *)0))
  original=(void *)*((unsigned long *)mem-1);
 else
  original=((void *)0);
 ptr=realloc(original,size);
 if(ptr==((void *)0))
  return ((void *)0);
 t=aligment - (unsigned long)ptr%aligment;
 final= (void *)((unsigned long)ptr + t);
 *((unsigned long *)final-1)=(unsigned long)ptr;
 return (void *)final;
}


decompiled_code:
unsigned __int64 __fastcall aligned_realloc16(_QWORD *a1, int a2)
{
return aligned_realloc(a1, 16, a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(_QWORD *a1, int a2)
{
return func3(a1, 16, a2);
}

original_code:
void* aligned_realloc16(void* mem, int size)
{
 return aligned_realloc(mem,16, size);
}

canonical_original_code:
void *aligned_realloc16(void *mem, int size)
{
 return aligned_realloc(mem,16, size);
}


decompiled_code:
void *db_init()
{
void *result; // rax

audit_db_name = (__int64)"auditdb";
user_name = (__int64)"lvaikunt";
password = (__int64)"sid2deb4.ux";
host_name = (__int64)"localhost";
result = malloc(0x1000uLL);
query = (__int64)result;
return result;
}

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

audit_db_name = (__int64)"auditdb";
user_name = (__int64)"lvaikunt";
password = (__int64)"sid2deb4.ux";
host_name = (__int64)"localhost";
result = malloc(0x1000uLL);
query = (__int64)result;
return result;
}

original_code:
void db_init ()
{
    audit_db_name = "auditdb";
    user_name = "lvaikunt";
    password = "sid2deb4.ux";
    host_name = "localhost";
    query = (char *) (malloc(sizeof(char) * 4096));
}

canonical_original_code:
void db_init()
{
    audit_db_name = "auditdb";
    user_name = "lvaikunt";
    password = "sid2deb4.ux";
    host_name = "localhost";
    query = (char *) (malloc(sizeof(char) * 4096));
}


decompiled_code:
__int64 get_auditdb_name()
{
return audit_db_name;
}

canonical_decompiled_code:
__int64 func1()
{
return audit_db_name;
}

original_code:
const char * get_auditdb_name()
{
    return audit_db_name;
}

canonical_original_code:
char *get_auditdb_name()
{
    return audit_db_name;
}

return_type: char *


decompiled_code:
__int64 get_user_name()
{
return user_name;
}

canonical_decompiled_code:
__int64 func2()
{
return user_name;
}

original_code:
const char * get_user_name()
{
    return user_name;
}

canonical_original_code:
char *get_user_name()
{
    return user_name;
}


decompiled_code:
__int64 get_password()
{
return password;
}

canonical_decompiled_code:
__int64 func3()
{
return password;
}

original_code:
const char * get_password()
{
    return password;
}

canonical_original_code:
char *get_password()
{
    return password;
}


decompiled_code:
__int64 get_host_name()
{
return host_name;
}

canonical_decompiled_code:
__int64 func4()
{
return host_name;
}

original_code:
const char * get_host_name()
{
    return host_name;
}

canonical_original_code:
char *get_host_name()
{
    return host_name;
}


decompiled_code:
__int64 allocate_query_space()
{
__int64 v0; // rcx

v0 = query;
*(_QWORD *)query = 0LL;
*(_QWORD *)(v0 + 4088) = 0LL;
memset(
(void *)((v0 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 4096) >> 3));
return query;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rcx

v0 = query;
*(_QWORD *)query = 0LL;
*(_QWORD *)(v0 + 4088) = 0LL;
memset(
(void *)((v0 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 4096) >> 3));
return query;
}

original_code:
char * allocate_query_space()
{
    memset(query, 0, 4096);
    return query;
}

canonical_original_code:
char *allocate_query_space()
{
    memset(query, 0, 4096);
    return query;
}


decompiled_code:
const char *get_workspacetable_name()
{
return "workspacetable";
}

canonical_decompiled_code:
const char *func9()
{
return "workspacetable";
}

original_code:
const char * get_workspacetable_name()
{
    return "workspacetable";
}


decompiled_code:
const char *get_dotable_name()
{
return "dotable";
}

canonical_decompiled_code:
const char *func10()
{
return "dotable";
}

original_code:
const char * get_dotable_name()
{
    return "dotable";
}


decompiled_code:
const char *get_deptable_name()
{
return "deptable";
}

canonical_decompiled_code:
const char *func11()
{
return "deptable";
}

original_code:
const char * get_deptable_name()
{
    return "deptable";
}


strrev

decompiled_code:
const char *__fastcall strrev(const char *a1)
{
int v1; // eax
int v2; // ecx
__int64 v3; // rdx
__int64 v4; // rax
char v5; // cl

v1 = strlen(a1);
if ( v1 )
{
v2 = v1 - 1;
v3 = v1 - 1;
v4 = 0LL;
if ( v2 >= 0 )
{
do
{
v5 = a1[v4];
a1[v4] = a1[v3];
a1[v3] = v5;
++v4;
--v3;
}
while ( (int)v4 <= (int)v3 );
}
}
else
{
*a1 = 0;
}
return a1;
}

original_code:
char * strrev(char * str)
{
    int len = strlen(str);
    int i = 0;
    int j = len - 1;
    if(len == 0)
    {
        str[0] = '\0';
        return str;
    }
    while(i<=j)
    {
        char temp = str[i];
        str[i] = str[j];
        str[j] = temp;
        i++;
        j--;
    }
    return str;
}

canonical_original_code:
char *strrev(char *str)
{
    int len = strlen(str);
    int i = 0;
    int j = len - 1;
    if(len == 0)
    {
        str[0] = '\0';
        return str;
    }
    while(i<=j)
    {
        char temp = str[i];
        str[i] = str[j];
        str[j] = temp;
        i++;
        j--;
    }
    return str;
}

variable_types:
str
char *

variable_types: len int

variable_types: i int

variable_types: j int

variable_types: temp char


decompiled_code:
__int64 __fastcall convert_uint_to_str(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax

v2 = malloc(0x14uLL);
*a2 = v2;
*v2 = 0LL;
v2[1] = 0LL;
*((_DWORD *)v2 + 4) = 0;
itoa(a1, (__int64)v2, 0xAu);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, _QWORD *a2)
{
_QWORD *v2; // rax

v2 = malloc(0x14uLL);
*a2 = v2;
*v2 = 0LL;
v2[1] = 0LL;
*((_DWORD *)v2 + 4) = 0;
func14(a1, (__int64)v2, 0xAu);
return 0LL;
}

original_code:
RETVAL convert_uint_to_str(unsigned int val, char ** result)
{
    *result = ((void *)0);
    *result = (char * ) (malloc (sizeof(char) * 20));
    memset(*result, 0, 20);
    itoa(val, *result, 10);
    return OK;
}

canonical_original_code:
enum RETVAL convert_uint_to_str(unsigned int val, char **result)
{
    *result = ((void *)0);
    *result = (char * ) (malloc (sizeof(char) * 20));
    memset(*result, 0, 20);
    itoa(val, *result, 10);
    return OK;
}

variable_types:
val
unsigned int

variable_types:
result
char **

return_type: enum RETVAL { NOTOK=-1, OK=0 }


decompiled_code:
void __fastcall free_resultset(void **a1)
{
void *v2; // rdi
void **v3; // rbx

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
}
}

canonical_decompiled_code:
void __fastcall func17(void **a1)
{
void *v2; // rdi
void **v3; // rbx

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
}
}

original_code:
void free_resultset(char ** result)
{
    int i = 0;
    if(result == ((void *)0))
        return;
    while(result[i] != ((void *)0))
    {
        if(result[i] != ((void *)0))
            free(result[i]);
        i++;
    }
}

canonical_original_code:
void free_resultset(char **result)
{
    int i = 0;
    if(result == ((void *)0))
        return;
    while(result[i] != ((void *)0))
    {
        if(result[i] != ((void *)0))
            free(result[i]);
        i++;
    }
}


hash

decompiled_code:
__int64 __fastcall hash(__int64 a1, int a2)
{
return (unsigned int)(a2 % *(_DWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return (unsigned int)(a2 % *(_DWORD *)(a1 + 8));
}

original_code:
int hash(struct hashtable *ht, int key)
{
    return (key % (ht->size));
}

variable_types: struct hashtable { struct hash_node { struct hash_node *next; int key; void *value; } **table; int size; } *

variable_types: key int

user_defined_types: struct hashtable { struct hash_node **table; int size; }


original_code:
int hashtable_insert(struct hashtable *ht, int key, void *v)
{
    int index = hash(ht,key);
    struct hash_node *prev= ((void *)0),*tmp = ((void *)0);
    struct hash_node *n = ((void *)0);
    tmp = ht->table[index];
    if (tmp == ((void *)0)) {
        n = malloc(sizeof(struct hash_node));
        n->value = v;
        n->key = key;
        n->next = ((void *)0);
 ht->table[index] = n;
 return 0;
    }
    while(tmp) {
 if (tmp->key == key) {
     tmp->value = v;
     return 0;
 }
        prev = tmp;
 tmp = tmp->next;
    }
    n = malloc(sizeof(struct hash_node));
    n->value = v;
    n->key = key;
    n->next = ((void *)0);
    prev->next = n;
    return 0;
}

canonical_original_code:
int hashtable_insert(struct hashtable *ht, int key, void *v)
{
    int index = hash(ht,key);
    struct hash_node *prev = ((void *)0); struct hash_node *tmp = ((void *)0);
    struct hash_node *n = ((void *)0);
    tmp = ht->table[index];
    if (tmp == ((void *)0)) {
        n = malloc(sizeof(struct hash_node));
        n->value = v;
        n->key = key;
        n->next = ((void *)0);
 ht->table[index] = n;
 return 0;
    }
    while(tmp) {
 if (tmp->key == key) {
     tmp->value = v;
     return 0;
 }
        prev = tmp;
 tmp = tmp->next;
    }
    n = malloc(sizeof(struct hash_node));
    n->value = v;
    n->key = key;
    n->next = ((void *)0);
    prev->next = n;
    return 0;
}

variable_types:
v
void *

variable_types: index int

variable_types: struct hash_node { struct hash_node *next; int key; void *value; } *


decompiled_code:
__int64 __fastcall hashtable_remove(_QWORD *a1, int a2)
{
_DWORD **v2; // rcx
_DWORD *v3; // rdi
__int64 result; // rax
_QWORD *v5; // rdx

v2 = (_DWORD **)(*a1 + 8LL * (int)hash((__int64)a1, a2));
v3 = *v2;
result = 0xFFFFFFFFLL;
if ( *v2 )
{
v5 = 0LL;
if ( v3[2] == a2 )
{
*v2 = *(_DWORD **)v3;
free(v3);
result = 0LL;
}
else
{
while ( v3[2] != a2 )
{
v5 = v3;
if ( !*(_QWORD *)v3 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD **)v3;
}
*v5 = *(_QWORD *)v3;
free(v3);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2)
{
_DWORD **v2; // rcx
_DWORD *v3; // rdi
__int64 result; // rax
_QWORD *v5; // rdx

v2 = (_DWORD **)(*a1 + 8LL * (int)func0((__int64)a1, a2));
v3 = *v2;
result = 0xFFFFFFFFLL;
if ( *v2 )
{
v5 = 0LL;
if ( v3[2] == a2 )
{
*v2 = *(_DWORD **)v3;
free(v3);
result = 0LL;
}
else
{
while ( v3[2] != a2 )
{
v5 = v3;
if ( !*(_QWORD *)v3 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD **)v3;
}
*v5 = *(_QWORD *)v3;
free(v3);
result = 0LL;
}
}
return result;
}

original_code:
int hashtable_remove(struct hashtable *ht, int key)
{
    int index = hash(ht,key);
    struct hash_node *tmp = ((void *)0), *prev = ((void *)0);
    tmp = ht->table[index];
    if(tmp && (tmp->key == key)) {
        ht->table[index] = tmp->next;
 free(tmp);
 return 0;
    }
    while(tmp) {
 if (tmp->key == key) {
     prev->next = tmp->next;
     free(tmp);
     return 0;
 }
        prev = tmp;
 tmp = tmp->next;
    }
    return -1;
}

canonical_original_code:
int hashtable_remove(struct hashtable *ht, int key)
{
    int index = hash(ht,key);
    struct hash_node *tmp = ((void *)0); struct hash_node *prev = ((void *)0);
    tmp = ht->table[index];
    if(tmp && (tmp->key == key)) {
        ht->table[index] = tmp->next;
 free(tmp);
 return 0;
    }
    while(tmp) {
 if (tmp->key == key) {
     prev->next = tmp->next;
     free(tmp);
     return 0;
 }
        prev = tmp;
 tmp = tmp->next;
    }
    return -1;
}

user_defined_types: struct hash_node { struct hash_node *next; int key; void *value; }


original_code:
int hashtable_foreach(struct hashtable *ht,
 int (*fn)(int key, void *value, void *data),
 void *data)
{
    int index = 0;
    struct hash_node *tmp = ((void *)0);
    for (index=0; index < ht->size; index++)
    {
        tmp = ht->table[index];
 while (tmp) {
            (*fn)(tmp->key, tmp->value, data);
     tmp = tmp->next;
 }
    }
    return 0;
}

variable_types: int (*)(int key, void *value, void *data)

variable_types:
data
void *


decompiled_code:
__int64 *byte_fill()
{
__int64 *result; // rax

result = (__int64 *)&buff;
do
{
result = (__int64 *)((char *)result + 1);
*((_BYTE *)result - 1) = 0;
}
while ( result != &end_time );
return result;
}

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

result = (__int64 *)&buff;
do
{
result = (__int64 *)((char *)result + 1);
*((_BYTE *)result - 1) = 0;
}
while ( result != &end_time );
return result;
}

original_code:
static void byte_fill(void)
{
 char *p = (void *)buff;
 int i;
 for (i = sizeof(buff); i > 0; i--)
  *p++ = 0;
}

canonical_original_code:
static void byte_fill()
{
 char *p = (void *)buff;
 int i;
 for (i = sizeof(buff); i > 0; i--)
  *p++ = 0;
}

variable_types:
p
char *


decompiled_code:
__int64 *word_fill()
{
__int64 *result; // rax

result = (__int64 *)&buff;
do
*result++ = 0LL;
while ( result != &end_time );
return result;
}

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

result = (__int64 *)&buff;
do
*result++ = 0LL;
while ( result != &end_time );
return result;
}

original_code:
static void word_fill(void)
{
 long *p = (void *)buff;
 int i;
 for (i = sizeof(buff) / sizeof(*p); i > 0; i--)
  *p++ = 0;
}

canonical_original_code:
static void word_fill()
{
 long *p = (void *)buff;
 int i;
 for (i = sizeof(buff) / sizeof(*p); i > 0; i--)
  *p++ = 0;
}

variable_types:
p
long *


decompiled_code:
char *byte_cpy()
{
char *result; // rax

result = (char *)&buff;
do
{
++result;
*(result - 1) = byte_3FFFFF[(_QWORD)result];
}
while ( result != &byte_400620 );
return result;
}

canonical_decompiled_code:
char *func2()
{
char *result; // rax

result = (char *)&buff;
do
{
++result;
*(result - 1) = byte_3FFFFF[(_QWORD)result];
}
while ( result != &byte_400620 );
return result;
}

original_code:
static void byte_cpy(void)
{
 char *d = (void *)buff;
 char *s = (void *)buff_mid;
 int i;
 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
  *d++ = *s++;
}

canonical_original_code:
static void byte_cpy()
{
 char *d = (void *)buff;
 char *s = (void *)buff_mid;
 int i;
 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
  *d++ = *s++;
}

variable_types:
d
char *

variable_types:
s
char *


decompiled_code:
char *word_cpy()
{
char *result; // rax

result = (char *)&buff;
do
{
result += 8;
*((_QWORD *)result - 1) = *(_QWORD *)((char *)&unk_3FFFF8 + (_QWORD)result);
}
while ( result != &byte_400620 );
return result;
}

canonical_decompiled_code:
char *func3()
{
char *result; // rax

result = (char *)&buff;
do
{
result += 8;
*((_QWORD *)result - 1) = *(_QWORD *)((char *)&unk_3FFFF8 + (_QWORD)result);
}
while ( result != &byte_400620 );
return result;
}

original_code:
static void word_cpy(void)
{
 long *d = (void *)buff;
 long *s = (void *)buff_mid;
 int i;
 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
  *d++ = *s++;
}

canonical_original_code:
static void word_cpy()
{
 long *d = (void *)buff;
 long *s = (void *)buff_mid;
 int i;
 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
  *d++ = *s++;
}

variable_types:
d
long *

variable_types:
s
long *


decompiled_code:
__int64 *word_inc()
{
__int64 *result; // rax

result = (__int64 *)&buff;
do
++*result++;
while ( result != &end_time );
return result;
}

canonical_decompiled_code:
__int64 *func4()
{
__int64 *result; // rax

result = (__int64 *)&buff;
do
++*result++;
while ( result != &end_time );
return result;
}

original_code:
static void word_inc(void)
{
 long *p = (void *)buff;
 int i;
 for (i = sizeof(buff) / sizeof(*p); i > 0; i--) {
  (*p)++;
  p++;
 }
}

canonical_original_code:
static void word_inc()
{
 long *p = (void *)buff;
 int i;
 for (i = sizeof(buff) / sizeof(*p); i > 0; i--) {
  (*p)++;
  p++;
 }
}

variable_types: i int


decompiled_code:
void *do_memset()
{
return memset(&buff, 0, (size_t)&unk_800000);
}

canonical_decompiled_code:
void *func6()
{
return memset(&buff, 0, (size_t)&unk_800000);
}

original_code:
static void do_memset(void)
{
 memset(buff, 0, sizeof(buff));
}

canonical_original_code:
static void do_memset()
{
 memset(buff, 0, sizeof(buff));
}


decompiled_code:
void *do_memcpy()
{
return memcpy(&buff, &byte_400620, (size_t)&unk_400000);
}

canonical_decompiled_code:
void *func7()
{
return memcpy(&buff, &byte_400620, (size_t)&unk_400000);
}

original_code:
static void do_memcpy(void)
{
 memcpy(buff, buff_mid, sizeof(buff) / 2);
}

canonical_original_code:
static void do_memcpy()
{
 memcpy(buff, buff_mid, sizeof(buff) / 2);
}


xtime

decompiled_code:
__suseconds_t xtime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func8()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static u64 xtime(void)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return (u64)tv.tv_sec * 1000000 + tv.tv_usec;
}

canonical_original_code:
static unsigned long long xtime()
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return (unsigned long long)tv.tv_sec * 1000000 + tv.tv_usec;
}

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

return_type: unsigned long long


decompiled_code:
__suseconds_t test_start()
{
__suseconds_t result; // rax

result = xtime();
start_time = result;
return result;
}

canonical_decompiled_code:
__suseconds_t func9()
{
__suseconds_t result; // rax

result = func8();
start_time = result;
return result;
}

original_code:
static void test_start(void)
{
 start_time = xtime();
}

canonical_original_code:
static void test_start()
{
 start_time = xtime();
}


decompiled_code:
__suseconds_t test_end()
{
__suseconds_t result; // rax

result = xtime();
end_time = result;
return result;
}

canonical_decompiled_code:
__suseconds_t func10()
{
__suseconds_t result; // rax

result = func8();
end_time = result;
return result;
}

original_code:
static void test_end(void)
{
 end_time = xtime();
}

canonical_original_code:
static void test_end()
{
 end_time = xtime();
}


tests

decompiled_code:
int tests()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx

test_start();
v0 = 64;
do
{
do_memset();
--v0;
}
while ( v0 );
test_end();
show_result("memset", 0x20000000);
test_start();
v1 = 64;
do
{
byte_fill();
--v1;
}
while ( v1 );
test_end();
show_result("byte fill", 0x20000000);
test_start();
v2 = 64;
do
{
word_fill();
--v2;
}
while ( v2 );
test_end();
show_result("word fill", 0x20000000);
test_start();
v3 = 128;
do
{
do_memcpy();
--v3;
}
while ( v3 );
test_end();
show_result("memcpy", 0x20000000);
test_start();
v4 = 128;
do
{
byte_cpy();
--v4;
}
while ( v4 );
test_end();
show_result("byte copy", 0x20000000);
test_start();
v5 = 128;
do
{
word_cpy();
--v5;
}
while ( v5 );
test_end();
show_result("word copy", 0x20000000);
test_start();
v6 = 64;
do
{
word_inc();
--v6;
}
while ( v6 );
test_end();
show_result("word inc", 0x20000000);
return usleep((__useconds_t)&unk_30D40);
}

original_code:
static void tests(void)
{
 int i;
 test_start(); for (i = 64; i > 0; i--) do_memset(); test_end();
 show_result("memset", sizeof(buff) * 64);
 test_start(); for (i = 64; i > 0; i--) byte_fill(); test_end();
 show_result("byte fill", sizeof(buff) * 64);
 test_start(); for (i = 64; i > 0; i--) word_fill(); test_end();
 show_result("word fill", sizeof(buff) * 64);
 test_start(); for (i = 128; i > 0; i--) do_memcpy(); test_end();
 show_result("memcpy", sizeof(buff) * 128 / 2);
 test_start(); for (i = 128; i > 0; i--) byte_cpy(); test_end();
 show_result("byte copy", sizeof(buff) * 128 / 2);
 test_start(); for (i = 128; i > 0; i--) word_cpy(); test_end();
 show_result("word copy", sizeof(buff) * 128 / 2);
 test_start(); for (i = 64; i > 0; i--) word_inc(); test_end();
 show_result("word inc", sizeof(buff) * 64);
 usleep(200000);
}

canonical_original_code:
static void tests()
{
 int i;
 test_start(); for (i = 64; i > 0; i--) do_memset(); test_end();
 show_result("memset", sizeof(buff) * 64);
 test_start(); for (i = 64; i > 0; i--) byte_fill(); test_end();
 show_result("byte fill", sizeof(buff) * 64);
 test_start(); for (i = 64; i > 0; i--) word_fill(); test_end();
 show_result("word fill", sizeof(buff) * 64);
 test_start(); for (i = 128; i > 0; i--) do_memcpy(); test_end();
 show_result("memcpy", sizeof(buff) * 128 / 2);
 test_start(); for (i = 128; i > 0; i--) byte_cpy(); test_end();
 show_result("byte copy", sizeof(buff) * 128 / 2);
 test_start(); for (i = 128; i > 0; i--) word_cpy(); test_end();
 show_result("word copy", sizeof(buff) * 128 / 2);
 test_start(); for (i = 64; i > 0; i--) word_inc(); test_end();
 show_result("word inc", sizeof(buff) * 64);
 usleep(200000);
}


decompiled_code:
void coherency_test()
{
unsigned int v0; // eax
__int64 v1; // r12
int v2; // eax
char *v3; // rax
__int64 v4; // rbx
char *v5; // rbp
__int64 v6; // rax
unsigned __int64 v7; // r14
char *v8; // r13
unsigned __int8 v9; // bl
unsigned __int8 v10; // [rsp+8h] [rbp-40h]
unsigned __int8 v11; // [rsp+9h] [rbp-3Fh]
unsigned __int8 v12; // [rsp+Ah] [rbp-3Eh]
unsigned __int8 v13; // [rsp+Bh] [rbp-3Dh]
unsigned __int8 v14; // [rsp+Ch] [rbp-3Ch]
unsigned __int8 v15; // [rsp+Dh] [rbp-3Bh]
unsigned __int8 v16; // [rsp+Eh] [rbp-3Ah]
unsigned __int8 v17; // [rsp+Fh] [rbp-39h]

v0 = time(0LL);
srand(v0);
v1 = warm_virt2phys(byte_400620);
v2 = open("/dev/mem", (int)&unk_101000);
if ( v2 < 0 )
{
perror("open /dev/mem");
}
else
{
v3 = (char *)mmap(0LL, 0x1000uLL, 1, 1, v2, v1 & 0xFFFFFFFFFFFFF000LL);
if ( v3 == (char *)-1LL )
{
perror("mmap buff");
}
else
{
v4 = v1 & 0xFFF;
v5 = &v3[v4];
v6 = warm_virt2phys(&v3[v4]);
if ( v1 != v6 )
printf("warning: mmap requested %08lx, got %08lx\n", v1, v6);
v7 = rand() % (unsigned __int64)(4096 - v4);
v10 = byte_400620[(int)v7];
v8 = &v5[(int)v7];
v11 = *v8;
byte_400620[(int)v7] = v10 + 1;
v12 = byte_400620[(int)v7];
v13 = *v8;
warm_cache_op_range(1LL, &byte_400620[(int)v7], 32LL);
v14 = byte_400620[(int)v7];
v15 = *v8;
byte_400620[(int)v7] = v14 + 1;
v16 = byte_400620[(int)v7];
v17 = *v8;
warm_cache_op_range(2LL, &byte_400620[(int)v7], 32LL);
v9 = byte_400620[(int)v7];
LOBYTE(v8) = *v8;
printf("buff is @ %p -> %lx, mapped %p, random offset %x\n", byte_400620, v1, v5, (unsigned int)v7);
printf("val: %02x, mmaped: %02x\n", v10, v11);
puts("incremented:");
printf("val: %02x, mmaped: %02x\n", v12, v13);
puts("cleaned:");
printf("val: %02x, mmaped: %02x\n", v14, v15);
puts("incremented:");
printf("val: %02x, mmaped: %02x\n", v16, v17);
puts("invalidated:");
printf("val: %02x, mmaped: %02x\n", v9, (unsigned __int8)v8);
}
}
}

canonical_decompiled_code:
void func12()
{
unsigned int v0; // eax
__int64 v1; // r12
int v2; // eax
char *v3; // rax
__int64 v4; // rbx
char *v5; // rbp
__int64 v6; // rax
unsigned __int64 v7; // r14
char *v8; // r13
unsigned __int8 v9; // bl
unsigned __int8 v10; // [rsp+8h] [rbp-40h]
unsigned __int8 v11; // [rsp+9h] [rbp-3Fh]
unsigned __int8 v12; // [rsp+Ah] [rbp-3Eh]
unsigned __int8 v13; // [rsp+Bh] [rbp-3Dh]
unsigned __int8 v14; // [rsp+Ch] [rbp-3Ch]
unsigned __int8 v15; // [rsp+Dh] [rbp-3Bh]
unsigned __int8 v16; // [rsp+Eh] [rbp-3Ah]
unsigned __int8 v17; // [rsp+Fh] [rbp-39h]

v0 = time(0LL);
srand(v0);
v1 = warm_virt2phys(byte_400620);
v2 = open("/dev/mem", (int)&unk_101000);
if ( v2 < 0 )
{
perror("open /dev/mem");
}
else
{
v3 = (char *)mmap(0LL, 0x1000uLL, 1, 1, v2, v1 & 0xFFFFFFFFFFFFF000LL);
if ( v3 == (char *)-1LL )
{
perror("mmap buff");
}
else
{
v4 = v1 & 0xFFF;
v5 = &v3[v4];
v6 = warm_virt2phys(&v3[v4]);
if ( v1 != v6 )
printf("warning: mmap requested %08lx, got %08lx\n", v1, v6);
v7 = rand() % (unsigned __int64)(4096 - v4);
v10 = byte_400620[(int)v7];
v8 = &v5[(int)v7];
v11 = *v8;
byte_400620[(int)v7] = v10 + 1;
v12 = byte_400620[(int)v7];
v13 = *v8;
warm_cache_op_range(1LL, &byte_400620[(int)v7], 32LL);
v14 = byte_400620[(int)v7];
v15 = *v8;
byte_400620[(int)v7] = v14 + 1;
v16 = byte_400620[(int)v7];
v17 = *v8;
warm_cache_op_range(2LL, &byte_400620[(int)v7], 32LL);
v9 = byte_400620[(int)v7];
LOBYTE(v8) = *v8;
printf("buff is @ %p -> %lx, mapped %p, random offset %x\n", byte_400620, v1, v5, (unsigned int)v7);
printf("val: %02x, mmaped: %02x\n", v10, v11);
puts("incremented:");
printf("val: %02x, mmaped: %02x\n", v12, v13);
puts("cleaned:");
printf("val: %02x, mmaped: %02x\n", v14, v15);
puts("incremented:");
printf("val: %02x, mmaped: %02x\n", v16, v17);
puts("invalidated:");
printf("val: %02x, mmaped: %02x\n", v9, (unsigned __int8)v8);
}
}
}

original_code:
void coherency_test(void)
{
 volatile unsigned char *buff_mapped;
 volatile unsigned char *buff_vol;
 unsigned long buff_phys, mapped_phys, align;
 unsigned char buff_mapped_vals[6];
 unsigned char buff_vals[5];
 int random_offs;
 int memdev;
 srand(time(((void *)0)));
 buff_phys = warm_virt2phys(buff_mid);
 align = buff_phys & 0xfff;
 memdev = open("/dev/mem", 00 | 04010000);
 if (memdev < 0) {
  perror("open /dev/mem");
  return;
 }
 buff_mapped = mmap(((void *)0), 0x1000, 0x1,
   0x01, memdev, buff_phys & ~0xfff);
 if (buff_mapped == ((void *) -1)) {
  perror("mmap buff");
  return;
 }
 buff_mapped += align;
 buff_mapped_vals[5] = buff_mapped[0];
 mapped_phys = warm_virt2phys((void *)buff_mapped);
 if (buff_phys != mapped_phys)
  printf("warning: mmap requested %08lx, got %08lx\n", buff_phys, mapped_phys);
 random_offs = rand() % (0x1000 - align);
 buff_vol = (volatile void *)buff_mid;
 buff_vals[0] = buff_vol[random_offs]; buff_mapped_vals[0] = buff_mapped[random_offs];
 buff_vol[random_offs]++;
 buff_vals[1] = buff_vol[random_offs]; buff_mapped_vals[1] = buff_mapped[random_offs];
 warm_cache_op_range((1 << 0), (char *)buff_vol + random_offs, 32);
 buff_vals[2] = buff_vol[random_offs]; buff_mapped_vals[2] = buff_mapped[random_offs];
 buff_vol[random_offs]++;
 buff_vals[3] = buff_vol[random_offs]; buff_mapped_vals[3] = buff_mapped[random_offs];
 warm_cache_op_range((1 << 1), (char *)buff_vol + random_offs, 32);
 buff_vals[4] = buff_vol[random_offs]; buff_mapped_vals[4] = buff_mapped[random_offs];
 printf("buff is @ %p -> %lx, mapped %p, random offset %x\n", buff_vol, buff_phys,
  buff_mapped, random_offs);
 printf("val: %02x, mmaped: %02x\n", buff_vals[0], buff_mapped_vals[0]);
 printf("incremented:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[1], buff_mapped_vals[1]);
 printf("cleaned:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[2], buff_mapped_vals[2]);
 printf("incremented:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[3], buff_mapped_vals[3]);
 printf("invalidated:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[4], buff_mapped_vals[4]);
}

canonical_original_code:
void coherency_test()
{
 unsigned char *buff_mapped;
 unsigned char *buff_vol;
 unsigned long buff_phys; unsigned long mapped_phys; unsigned long align;
 unsigned char buff_mapped_vals[6];
 unsigned char buff_vals[5];
 int random_offs;
 int memdev;
 srand(time(((void *)0)));
 buff_phys = warm_virt2phys(buff_mid);
 align = buff_phys & 0xfff;
 memdev = open("/dev/mem", 00 | 04010000);
 if (memdev < 0) {
  perror("open /dev/mem");
  return;
 }
 buff_mapped = mmap(((void *)0), 0x1000, 0x1,
   0x01, memdev, buff_phys & ~0xfff);
 if (buff_mapped == ((void *) -1)) {
  perror("mmap buff");
  return;
 }
 buff_mapped += align;
 buff_mapped_vals[5] = buff_mapped[0];
 mapped_phys = warm_virt2phys((void *)buff_mapped);
 if (buff_phys != mapped_phys)
  printf("warning: mmap requested %08lx, got %08lx\n", buff_phys, mapped_phys);
 random_offs = rand() % (0x1000 - align);
 buff_vol = (void *)buff_mid;
 buff_vals[0] = buff_vol[random_offs]; buff_mapped_vals[0] = buff_mapped[random_offs];
 buff_vol[random_offs]++;
 buff_vals[1] = buff_vol[random_offs]; buff_mapped_vals[1] = buff_mapped[random_offs];
 warm_cache_op_range((1 << 0), (char *)buff_vol + random_offs, 32);
 buff_vals[2] = buff_vol[random_offs]; buff_mapped_vals[2] = buff_mapped[random_offs];
 buff_vol[random_offs]++;
 buff_vals[3] = buff_vol[random_offs]; buff_mapped_vals[3] = buff_mapped[random_offs];
 warm_cache_op_range((1 << 1), (char *)buff_vol + random_offs, 32);
 buff_vals[4] = buff_vol[random_offs]; buff_mapped_vals[4] = buff_mapped[random_offs];
 printf("buff is @ %p -> %lx, mapped %p, random offset %x\n", buff_vol, buff_phys,
  buff_mapped, random_offs);
 printf("val: %02x, mmaped: %02x\n", buff_vals[0], buff_mapped_vals[0]);
 printf("incremented:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[1], buff_mapped_vals[1]);
 printf("cleaned:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[2], buff_mapped_vals[2]);
 printf("incremented:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[3], buff_mapped_vals[3]);
 printf("invalidated:\n");
 printf("val: %02x, mmaped: %02x\n", buff_vals[4], buff_mapped_vals[4]);
}

variable_types:
align
unsigned long

variable_types: memdev int


main

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

if ( (unsigned int)warm_init(argc, argv, envp) )
{
puts("init failed.");
v3 = 1;
}
else
{
v3 = 0;
printf("buff: %p - %p\n", &buff, &unk_80061F);
puts("-- default --");
tests();
puts("-- ncnb --");
warm_change_cb_range(3LL, 0LL, &buff, &unk_800000);
tests();
puts("-- nc b --");
warm_change_cb_range(2LL, 1LL, &buff, &unk_800000);
tests();
puts("-- cnb --");
warm_change_cb_range(1LL, 1LL, &buff, &unk_800000);
warm_change_cb_range(2LL, 0LL, &buff, &unk_800000);
tests();
warm_change_cb_range(3LL, 1LL, &buff, &unk_800000);
coherency_test();
warm_finish();
}
return v3;
}

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

if ( (unsigned int)warm_init(argc, argv, envp) )
{
puts("init failed.");
v3 = 1;
}
else
{
v3 = 0;
printf("buff: %p - %p\n", &buff, &unk_80061F);
puts("-- default --");
func11();
puts("-- ncnb --");
warm_change_cb_range(3LL, 0LL, &buff, &unk_800000);
func11();
puts("-- nc b --");
warm_change_cb_range(2LL, 1LL, &buff, &unk_800000);
func11();
puts("-- cnb --");
warm_change_cb_range(1LL, 1LL, &buff, &unk_800000);
warm_change_cb_range(2LL, 0LL, &buff, &unk_800000);
func11();
warm_change_cb_range(3LL, 1LL, &buff, &unk_800000);
func12();
warm_finish();
}
return v3;
}

original_code:
int main()
{
 int ret;
 ret = warm_init();
 if (ret != 0)
 {
  printf("init failed.\n");
  return 1;
 }
 printf("buff: %p - %p\n", buff, buff + sizeof(buff) - 1);
 printf("-- default --\n");
 tests();
 printf("-- ncnb --\n");
 warm_change_cb_range((1 << 0)|(1 << 1), 0, buff, sizeof(buff));
 tests();
 printf("-- nc b --\n");
 warm_change_cb_range((1 << 1), 1, buff, sizeof(buff));
 tests();
 printf("--  cnb --\n");
 warm_change_cb_range((1 << 0), 1, buff, sizeof(buff));
 warm_change_cb_range((1 << 1), 0, buff, sizeof(buff));
 tests();
 warm_change_cb_range((1 << 0)|(1 << 1), 1, buff, sizeof(buff));
 coherency_test();
 warm_finish();
 return 0;
}

variable_types: ret int


decompiled_code:
__int64 print_arm_registers()
{
__int64 i; // rbp
__int64 v1; // rbx
__int64 result; // rax

for ( i = 4LL; i != 20; i += 4LL )
{
v1 = i - 4;
debug_screen_printf(" ");
do
{
debug_screen_printf("R%02d %08x ", v1, *((_QWORD *)reg + v1));
++v1;
}
while ( i != v1 );
result = debug_screen_newline(1LL);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 i; // rbp
__int64 v1; // rbx
__int64 result; // rax

for ( i = 4LL; i != 20; i += 4LL )
{
v1 = i - 4;
debug_screen_printf(" ");
do
{
debug_screen_printf("R%02d %08x ", v1, *((_QWORD *)reg + v1));
++v1;
}
while ( i != v1 );
result = debug_screen_newline(1LL);
}
return result;
}

original_code:
void print_arm_registers()
{
  u32 i, i2, i3;
  for(i = 0, i3 = 0; i < 4; i++)
  {
    debug_screen_printf(" ");
    for(i2 = 0; i2 < 4; i2++, i3++)
    {
      debug_screen_printf("R%02d %08x ", i3, reg[i3]);
    }
    debug_screen_newline(1);
  }
}

canonical_original_code:
void print_arm_registers()
{
  unsigned long i; unsigned long i2; unsigned long i3;
  for(i = 0, i3 = 0; i < 4; i++)
  {
    debug_screen_printf(" ");
    for(i2 = 0; i2 < 4; i2++, i3++)
    {
      debug_screen_printf("R%02d %08x ", i3, reg[i3]);
    }
    debug_screen_newline(1);
  }
}

variable_types:
i
unsigned long


decompiled_code:
__int64 print_thumb_instruction()
{
__int64 v0; // rax

v0 = read_memory16(*((_QWORD *)reg + 15));
debug_screen_printf("Thumb instruction at PC: %04x", v0);
return debug_screen_newline(1LL);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax

v0 = read_memory16(*((_QWORD *)reg + 15));
debug_screen_printf("Thumb instruction at PC: %04x", v0);
return debug_screen_newline(1LL);
}

original_code:
void print_thumb_instruction()
{
  debug_screen_printf("Thumb instruction at PC: %04x",
   read_memory16(reg[REG_PC]));
  debug_screen_newline(1);
}


decompiled_code:
__int64 print_arm_instruction()
{
__int64 v0; // rax

v0 = read_memory32(*((_QWORD *)reg + 15));
debug_screen_printf("ARM instruction at PC: %08x", v0);
return debug_screen_newline(1LL);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax

v0 = read_memory32(*((_QWORD *)reg + 15));
debug_screen_printf("ARM instruction at PC: %08x", v0);
return debug_screen_newline(1LL);
}

original_code:
void print_arm_instruction()
{
  debug_screen_printf("ARM instruction at PC: %08x",
   read_memory32(reg[REG_PC]));
  debug_screen_newline(1);
}


decompiled_code:
__int64 print_flags()
{
unsigned __int64 v0; // rbx

v0 = *((_QWORD *)reg + 20);
debug_screen_newline(1LL);
debug_screen_printf(
" N: %d Z: %d C: %d V: %d CPSR: %08x SPSR: %08x mode: %s",
(v0 >> 31) & 1,
(v0 >> 30) & 1,
(v0 >> 29) & 1,
(v0 >> 28) & 1,
v0,
*((_QWORD *)&spsr + *((_QWORD *)reg + 29)),
cpu_mode_names[*((_QWORD *)reg + 29)]);
return debug_screen_newline(2LL);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int64 v0; // rbx

v0 = *((_QWORD *)reg + 20);
debug_screen_newline(1LL);
debug_screen_printf(
" N: %d Z: %d C: %d V: %d CPSR: %08x SPSR: %08x mode: %s",
(v0 >> 31) & 1,
(v0 >> 30) & 1,
(v0 >> 29) & 1,
(v0 >> 28) & 1,
v0,
*((_QWORD *)&spsr + *((_QWORD *)reg + 29)),
cpu_mode_names[*((_QWORD *)reg + 29)]);
return debug_screen_newline(2LL);
}

original_code:
void print_flags()
{
  u32 cpsr = reg[REG_CPSR];
  debug_screen_newline(1);
  debug_screen_printf(
   " N: %d  Z: %d  C: %d  V: %d  CPSR: %08x  SPSR: %08x  mode: %s",
   (cpsr >> 31) & 0x01, (cpsr >> 30) & 0x01, (cpsr >> 29) & 0x01,
   (cpsr >> 28) & 0x01, cpsr, spsr[reg[CPU_MODE]],
   cpu_mode_names[reg[CPU_MODE]]);
  debug_screen_newline(2);
}

canonical_original_code:
void print_flags()
{
  unsigned long cpsr = reg[REG_CPSR];
  debug_screen_newline(1);
  debug_screen_printf(
   " N: %d  Z: %d  C: %d  V: %d  CPSR: %08x  SPSR: %08x  mode: %s",
   (cpsr >> 31) & 0x01, (cpsr >> 30) & 0x01, (cpsr >> 29) & 0x01,
   (cpsr >> 28) & 0x01, cpsr, spsr[reg[CPU_MODE]],
   cpu_mode_names[reg[CPU_MODE]]);
  debug_screen_newline(2);
}

variable_types:
cpsr
unsigned long


decompiled_code:
__int64 print_stack()
{
__int64 v0; // r12
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax

debug_screen_printf("Stack:");
debug_screen_newline(1LL);
v0 = *((_QWORD *)reg + 13);
v1 = v0 + 20;
v2 = v0;
do
{
v3 = read_memory32(v2);
debug_screen_printf(" %08x", v3);
v2 += 4LL;
}
while ( v1 != v2 );
debug_screen_newline(1LL);
v4 = v0 + 40;
do
{
v5 = read_memory32(v1);
debug_screen_printf(" %08x", v5);
v1 += 4LL;
}
while ( v4 != v1 );
debug_screen_newline(1LL);
return debug_screen_newline(1LL);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // r12
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rax

debug_screen_printf("Stack:");
debug_screen_newline(1LL);
v0 = *((_QWORD *)reg + 13);
v1 = v0 + 20;
v2 = v0;
do
{
v3 = read_memory32(v2);
debug_screen_printf(" %08x", v3);
v2 += 4LL;
}
while ( v1 != v2 );
debug_screen_newline(1LL);
v4 = v0 + 40;
do
{
v5 = read_memory32(v1);
debug_screen_printf(" %08x", v5);
v1 += 4LL;
}
while ( v4 != v1 );
debug_screen_newline(1LL);
return debug_screen_newline(1LL);
}

original_code:
void print_stack()
{
  u32 i, i2, i3;
  debug_screen_printf("Stack:");
  debug_screen_newline(1);
  for(i = 0, i3 = reg[REG_SP]; i < stack_print_lines; i++)
  {
    for(i2 = 0; i2 < 5; i2++, i3 += 4)
    {
      debug_screen_printf(" %08x", read_memory32(i3));
    }
    if(i != stack_print_lines)
      debug_screen_newline(1);
  }
  debug_screen_newline(1);
}

canonical_original_code:
void print_stack()
{
  unsigned long i; unsigned long i2; unsigned long i3;
  debug_screen_printf("Stack:");
  debug_screen_newline(1);
  for(i = 0, i3 = reg[REG_SP]; i < stack_print_lines; i++)
  {
    for(i2 = 0; i2 < 5; i2++, i3 += 4)
    {
      debug_screen_printf(" %08x", read_memory32(i3));
    }
    if(i != stack_print_lines)
      debug_screen_newline(1);
  }
  debug_screen_newline(1);
}


decompiled_code:
__int64 debug_on()
{
current_debug_state = 0;
return debug_screen_start();
}

canonical_decompiled_code:
__int64 func5()
{
current_debug_state = 0;
return debug_screen_start();
}

original_code:
u32 debug_on()
{
  current_debug_state = STEP;
  debug_screen_start();
}

canonical_original_code:
unsigned long debug_on()
{
  current_debug_state = STEP;
  debug_screen_start();
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall debug_off(int a1)
{
current_debug_state = a1;
return debug_screen_end();
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
current_debug_state = a1;
return debug_screen_end();
}

original_code:
u32 debug_off(debug_state new_debug_state)
{
  current_debug_state = new_debug_state;
  debug_screen_end();
}

canonical_original_code:
unsigned long debug_off(enum debug_state new_debug_state)
{
  current_debug_state = new_debug_state;
  debug_screen_end();
}

variable_types: enum debug_state { STEP=0, PC_BREAKPOINT=1, VCOUNT_BREAKPOINT=2, Z_BREAKPOINT=3, COUNTDOWN_BREAKPOINT=4, COUNTDOWN_BREAKPOINT_B=5, COUNTDOWN_BREAKPOINT_C=6, STEP_RUN=7, RUN=8 }


decompiled_code:
__int64 __fastcall step_debug(__int64 a1, __int64 a2)
{
_QWORD *v3; // rdx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rdi
__int64 v7; // rbx
__int64 v9; // rax
void *v10; // r12
_BYTE v11[536]; // [rsp+0h] [rbp-218h] BYREF

v3 = reg;
*((_QWORD *)reg + 15) = a1;
v4 = v3[20] & 0x20LL;
v5 = ++instruction_count;
switch ( current_debug_state )
{
case 1:
if ( breakpoint_value == a1 )
goto LABEL_10;
goto LABEL_19;
case 2:
if ( io_registers[3] == breakpoint_value )
goto LABEL_10;
goto LABEL_19;
case 3:
if ( v3[17] == 1LL )
goto LABEL_10;
goto LABEL_19;
case 4:
if ( !breakpoint_value )
goto LABEL_10;
--breakpoint_value;
goto LABEL_19;
case 5:
if ( v5 == breakpoint_value )
{
LABEL_10:
debug_on();
goto LABEL_11;
}
goto LABEL_19;
case 6:
if ( a1 == 24 )
++in_interrupt;
if ( breakpoint_value )
{
if ( !in_interrupt )
{
--breakpoint_value;
goto LABEL_19;
}
}
else if ( !in_interrupt )
{
debug_on();
v9 = in_interrupt;
if ( a1 == 316 && in_interrupt )
goto LABEL_30;
LABEL_11:
if ( !current_debug_state || current_debug_state == 7 )
{
SDL_mutexP(sound_mutex);
SDL_PauseAudio(1LL);
if ( (unsigned __int64)output_field > 1 )
{
output_field = 0LL;
debug_screen_clear();
}
if ( v4 )
print_thumb_instruction(a2);
else
print_arm_instruction(a2);
print_arm_registers();
print_flags();
print_stack();
printf("%x instructions in, VCOUNT %d, cycles remaining: %d \n", instruction_count, io_registers[3], a2);
debug_screen_update();
++output_field;
if ( current_debug_state != 7 )
{
switch ( getchar() )
{
case 'a':
v10 = (void *)copy_screen();
get_savestate_filename_noshot(savestate_slot, v11);
save_state(v11, v10);
free(v10);
break;
case 'b':
debug_off(1);
break;
case 'c':
printf("break after N instructions (hex): ");
scanf("%08x", &breakpoint_value);
--breakpoint_value;
debug_off(4);
break;
case 'd':
dump_translation_cache();
break;
case 'f':
printf("break after N instructions, skip in IRQ (hex): ");
scanf("%08x", &breakpoint_value);
--breakpoint_value;
debug_off(6);
break;
case 'g':
printf("break after N instructions (since start): ");
scanf("%d", &breakpoint_value);
debug_off(5);
break;
case 'q':
quit();
break;
case 'r':
debug_off(8);
break;
case 's':
current_debug_state = 7;
break;
case 't':
global_cycles_per_instruction = 0LL;
debug_off(8);
break;
case 'v':
printf("break at VCOUNT: ");
scanf("%d", &breakpoint_value);
debug_off(2);
break;
case 'x':
printf("break at PC (hex): ");
scanf("%08x", &breakpoint_value);
debug_off(1);
break;
case 'z':
debug_off(3);
break;
default:
break;
}
}
SDL_PauseAudio(0LL);
SDL_mutexV(sound_mutex);
}
goto LABEL_19;
}
v9 = in_interrupt;
if ( a1 == 316 && in_interrupt )
{
LABEL_30:
in_interrupt = v9 - 1;
goto LABEL_11;
}
LABEL_19:
last_instruction = *((_QWORD *)reg + 15);
v6 = a1 + 2;
v7 = a1 + 4;
if ( v4 )
v7 = v6;
*((_QWORD *)reg + 15) = v7;
return 0LL;
default:
goto LABEL_11;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
_QWORD *v3; // rdx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rdi
__int64 v7; // rbx
__int64 v9; // rax
void *v10; // r12
_BYTE v11[536]; // [rsp+0h] [rbp-218h] BYREF

v3 = reg;
*((_QWORD *)reg + 15) = a1;
v4 = v3[20] & 0x20LL;
v5 = ++instruction_count;
switch ( current_debug_state )
{
case 1:
if ( breakpoint_value == a1 )
goto LABEL_10;
goto LABEL_19;
case 2:
if ( io_registers[3] == breakpoint_value )
goto LABEL_10;
goto LABEL_19;
case 3:
if ( v3[17] == 1LL )
goto LABEL_10;
goto LABEL_19;
case 4:
if ( !breakpoint_value )
goto LABEL_10;
--breakpoint_value;
goto LABEL_19;
case 5:
if ( v5 == breakpoint_value )
{
LABEL_10:
func5();
goto LABEL_11;
}
goto LABEL_19;
case 6:
if ( a1 == 24 )
++in_interrupt;
if ( breakpoint_value )
{
if ( !in_interrupt )
{
--breakpoint_value;
goto LABEL_19;
}
}
else if ( !in_interrupt )
{
func5();
v9 = in_interrupt;
if ( a1 == 316 && in_interrupt )
goto LABEL_30;
LABEL_11:
if ( !current_debug_state || current_debug_state == 7 )
{
SDL_mutexP(sound_mutex);
SDL_PauseAudio(1LL);
if ( (unsigned __int64)output_field > 1 )
{
output_field = 0LL;
debug_screen_clear();
}
if ( v4 )
func1(a2);
else
func2(a2);
func0();
func3();
func4();
printf("%x instructions in, VCOUNT %d, cycles remaining: %d \n", instruction_count, io_registers[3], a2);
debug_screen_update();
++output_field;
if ( current_debug_state != 7 )
{
switch ( getchar() )
{
case 'a':
v10 = (void *)copy_screen();
get_savestate_filename_noshot(savestate_slot, v11);
save_state(v11, v10);
free(v10);
break;
case 'b':
func6(1);
break;
case 'c':
printf("break after N instructions (hex): ");
scanf("%08x", &breakpoint_value);
--breakpoint_value;
func6(4);
break;
case 'd':
dump_translation_cache();
break;
case 'f':
printf("break after N instructions, skip in IRQ (hex): ");
scanf("%08x", &breakpoint_value);
--breakpoint_value;
func6(6);
break;
case 'g':
printf("break after N instructions (since start): ");
scanf("%d", &breakpoint_value);
func6(5);
break;
case 'q':
quit();
break;
case 'r':
func6(8);
break;
case 's':
current_debug_state = 7;
break;
case 't':
global_cycles_per_instruction = 0LL;
func6(8);
break;
case 'v':
printf("break at VCOUNT: ");
scanf("%d", &breakpoint_value);
func6(2);
break;
case 'x':
printf("break at PC (hex): ");
scanf("%08x", &breakpoint_value);
func6(1);
break;
case 'z':
func6(3);
break;
default:
break;
}
}
SDL_PauseAudio(0LL);
SDL_mutexV(sound_mutex);
}
goto LABEL_19;
}
v9 = in_interrupt;
if ( a1 == 316 && in_interrupt )
{
LABEL_30:
in_interrupt = v9 - 1;
goto LABEL_11;
}
LABEL_19:
last_instruction = *((_QWORD *)reg + 15);
v6 = a1 + 2;
v7 = a1 + 4;
if ( v4 )
v7 = v6;
*((_QWORD *)reg + 15) = v7;
return 0LL;
default:
goto LABEL_11;
}
}

original_code:
u32 __attribute__((regparm(2))) step_debug(u32 pc, u32 cycles)
{
  u32 thumb = 0;
  reg[REG_PC] = pc;
  if(reg[REG_CPSR] & 0x20)
    thumb = 1;
  instruction_count++;
  switch(current_debug_state)
  {
    case PC_BREAKPOINT:
      if(reg[REG_PC] == breakpoint_value)
        debug_on();
      break;
    case Z_BREAKPOINT:
      if(reg[REG_Z_FLAG] == 1)
        debug_on();
      break;
    case VCOUNT_BREAKPOINT:
      if(io_registers[REG_VCOUNT] == breakpoint_value)
        debug_on();
      break;
    case COUNTDOWN_BREAKPOINT:
      if(breakpoint_value == 0)
        debug_on();
      else
        breakpoint_value--;
      break;
    case COUNTDOWN_BREAKPOINT_B:
      if(breakpoint_value == instruction_count)
        debug_on();
      break;
    case COUNTDOWN_BREAKPOINT_C:
    {
      if(pc == 0x18)
        in_interrupt++;
      if((breakpoint_value == 0) && (in_interrupt == 0))
      {
        debug_on();
      }
      else
      if(in_interrupt == 0)
        breakpoint_value--;
      if(in_interrupt && (pc == 0x13c))
        in_interrupt--;
      break;
    }
  }
  if((current_debug_state == STEP) ||
   (current_debug_state == STEP_RUN))
  {
    u32 key = 0;
    SDL_mutexP(sound_mutex);
    SDL_PauseAudio(1);
    if(output_field >= num_output_fields)
    {
      output_field = 0;
      debug_screen_clear();
    }
    if(thumb)
      print_thumb_instruction(cycles);
    else
      print_arm_instruction(cycles);
    print_arm_registers();
    print_flags();
    print_stack();
    printf("%x instructions in, VCOUNT %d, cycles remaining: %d \n",
     instruction_count, io_registers[REG_VCOUNT], cycles);
    debug_screen_update();
    output_field++;
    if(current_debug_state != STEP_RUN)
    {
      key = getchar();
    }
    switch(key)
    {
      case 'd':
        dump_translation_cache();
        break;
      case 'z':
        debug_off(Z_BREAKPOINT);
        break;
      case 'x':
        printf("break at PC (hex): ");
        scanf("%08x", &breakpoint_value);
        debug_off(PC_BREAKPOINT);
        break;
      case 'c':
        printf("break after N instructions (hex): ");
        scanf("%08x", &breakpoint_value);
        breakpoint_value -= 1;
        debug_off(COUNTDOWN_BREAKPOINT);
        break;
      case 'f':
        printf("break after N instructions, skip in IRQ (hex): ");
        scanf("%08x", &breakpoint_value);
        breakpoint_value -= 1;
        debug_off(COUNTDOWN_BREAKPOINT_C);
        break;
      case 'g':
        printf("break after N instructions (since start): ");
        scanf("%d", &breakpoint_value);
        debug_off(COUNTDOWN_BREAKPOINT_B);
        break;
      case 'v':
        printf("break at VCOUNT: ");
        scanf("%d", &breakpoint_value);
        debug_off(VCOUNT_BREAKPOINT);
        break;
      case 's':
        current_debug_state = STEP_RUN;
        break;
      case 'r':
        debug_off(RUN);
        break;
      case 'b':
        debug_off(PC_BREAKPOINT);
        break;
      case 't':
        global_cycles_per_instruction = 0;
        debug_off(RUN);
        break;
      case 'a':
      {
        u8 current_savestate_filename[512];
        u16 *current_screen = copy_screen();
        get_savestate_filename_noshot(savestate_slot,
         current_savestate_filename);
        save_state(current_savestate_filename, current_screen);
        free(current_screen);
        break;
      }
      case 'q':
        quit();
    }
    SDL_PauseAudio(0);
    SDL_mutexV(sound_mutex);
  }
  last_instruction = reg[REG_PC];
  if(thumb)
    reg[REG_PC] = pc + 2;
  else
    reg[REG_PC] = pc + 4;
  return 0;
}

canonical_original_code:
unsigned long step_debug(unsigned long pc, unsigned long cycles)
{
  unsigned long thumb = 0;
  reg[REG_PC] = pc;
  if(reg[REG_CPSR] & 0x20)
    thumb = 1;
  instruction_count++;
  switch(current_debug_state)
  {
    case PC_BREAKPOINT:
      if(reg[REG_PC] == breakpoint_value)
        debug_on();
      break;
    case Z_BREAKPOINT:
      if(reg[REG_Z_FLAG] == 1)
        debug_on();
      break;
    case VCOUNT_BREAKPOINT:
      if(io_registers[REG_VCOUNT] == breakpoint_value)
        debug_on();
      break;
    case COUNTDOWN_BREAKPOINT:
      if(breakpoint_value == 0)
        debug_on();
      else
        breakpoint_value--;
      break;
    case COUNTDOWN_BREAKPOINT_B:
      if(breakpoint_value == instruction_count)
        debug_on();
      break;
    case COUNTDOWN_BREAKPOINT_C:
    {
      if(pc == 0x18)
        in_interrupt++;
      if((breakpoint_value == 0) && (in_interrupt == 0))
      {
        debug_on();
      }
      else
      if(in_interrupt == 0)
        breakpoint_value--;
      if(in_interrupt && (pc == 0x13c))
        in_interrupt--;
      break;
    }
  }
  if((current_debug_state == STEP) ||
   (current_debug_state == STEP_RUN))
  {
    unsigned long key = 0;
    SDL_mutexP(sound_mutex);
    SDL_PauseAudio(1);
    if(output_field >= num_output_fields)
    {
      output_field = 0;
      debug_screen_clear();
    }
    if(thumb)
      print_thumb_instruction(cycles);
    else
      print_arm_instruction(cycles);
    print_arm_registers();
    print_flags();
    print_stack();
    printf("%x instructions in, VCOUNT %d, cycles remaining: %d \n",
     instruction_count, io_registers[REG_VCOUNT], cycles);
    debug_screen_update();
    output_field++;
    if(current_debug_state != STEP_RUN)
    {
      key = getchar();
    }
    switch(key)
    {
      case 'd':
        dump_translation_cache();
        break;
      case 'z':
        debug_off(Z_BREAKPOINT);
        break;
      case 'x':
        printf("break at PC (hex): ");
        scanf("%08x", &breakpoint_value);
        debug_off(PC_BREAKPOINT);
        break;
      case 'c':
        printf("break after N instructions (hex): ");
        scanf("%08x", &breakpoint_value);
        breakpoint_value -= 1;
        debug_off(COUNTDOWN_BREAKPOINT);
        break;
      case 'f':
        printf("break after N instructions, skip in IRQ (hex): ");
        scanf("%08x", &breakpoint_value);
        breakpoint_value -= 1;
        debug_off(COUNTDOWN_BREAKPOINT_C);
        break;
      case 'g':
        printf("break after N instructions (since start): ");
        scanf("%d", &breakpoint_value);
        debug_off(COUNTDOWN_BREAKPOINT_B);
        break;
      case 'v':
        printf("break at VCOUNT: ");
        scanf("%d", &breakpoint_value);
        debug_off(VCOUNT_BREAKPOINT);
        break;
      case 's':
        current_debug_state = STEP_RUN;
        break;
      case 'r':
        debug_off(RUN);
        break;
      case 'b':
        debug_off(PC_BREAKPOINT);
        break;
      case 't':
        global_cycles_per_instruction = 0;
        debug_off(RUN);
        break;
      case 'a':
      {
        unsigned char current_savestate_filename[512];
        unsigned short *current_screen = copy_screen();
        get_savestate_filename_noshot(savestate_slot,
         current_savestate_filename);
        save_state(current_savestate_filename, current_screen);
        free(current_screen);
        break;
      }
      case 'q':
        quit();
    }
    SDL_PauseAudio(0);
    SDL_mutexV(sound_mutex);
  }
  last_instruction = reg[REG_PC];
  if(thumb)
    reg[REG_PC] = pc + 2;
  else
    reg[REG_PC] = pc + 4;
  return 0;
}

variable_types:
pc
unsigned long

variable_types:
cycles
unsigned long

variable_types:
thumb
unsigned long

variable_types:
key
unsigned long


original_code:
void init_cpu()
{
  u32 i;
  for(i = 0; i < 16; i++)
  {
    reg[i] = 0;
  }
  reg[REG_SP] = 0x03007F00;
  reg[REG_PC] = 0x08000000;
  reg[REG_CPSR] = 0x0000001F;
  reg[CPU_HALT_STATE] = CPU_ACTIVE;
  reg[CPU_MODE] = MODE_USER;
  reg[CHANGED_PC_STATUS] = 0;
  reg_mode[MODE_USER][5] = 0x03007F00;
  reg_mode[MODE_IRQ][5] = 0x03007FA0;
  reg_mode[MODE_FIQ][5] = 0x03007FA0;
  reg_mode[MODE_SUPERVISOR][5] = 0x03007FE0;
}

canonical_original_code:
void init_cpu()
{
  unsigned long i;
  for(i = 0; i < 16; i++)
  {
    reg[i] = 0;
  }
  reg[REG_SP] = 0x03007F00;
  reg[REG_PC] = 0x08000000;
  reg[REG_CPSR] = 0x0000001F;
  reg[CPU_HALT_STATE] = CPU_ACTIVE;
  reg[CPU_MODE] = MODE_USER;
  reg[CHANGED_PC_STATUS] = 0;
  reg_mode[MODE_USER][5] = 0x03007F00;
  reg_mode[MODE_IRQ][5] = 0x03007FA0;
  reg_mode[MODE_FIQ][5] = 0x03007FA0;
  reg_mode[MODE_SUPERVISOR][5] = 0x03007FE0;
}