decompiled_code:
_BOOL8 __fastcall My402ListEmpty(_DWORD *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 )
result = *a1 <= 0;
return result;
}

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

result = 1LL;
if ( a1 )
result = *a1 <= 0;
return result;
}

original_code:
int My402ListEmpty(My402List *pList){
 int isListEmpty = 1;
 if( pList != ((void *)0) && pList->num_members > 0){
  isListEmpty = 0;
 }
 return isListEmpty;
}

canonical_original_code:
int My402ListEmpty(struct tagMy402List *pList){
 int isListEmpty = 1;
 if( pList != ((void *)0) && pList->num_members > 0){
  isListEmpty = 0;
 }
 return isListEmpty;
}

variable_types: isListEmpty int

user_defined_types: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; }


decompiled_code:
__int64 __fastcall My402ListFirst(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = My402ListEmpty((_DWORD *)a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

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

v1 = func1((_DWORD *)a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
My402ListElem *My402ListFirst(My402List *pList){
 My402ListElem *pFirstElem = ((void *)0);
 if(My402ListEmpty(pList) == 0){
  pFirstElem = pList->anchor.next;
 }
 return pFirstElem;
}

canonical_original_code:
struct tagMy402ListElem *My402ListFirst(struct tagMy402List *pList){
 struct tagMy402ListElem *pFirstElem = ((void *)0);
 if(My402ListEmpty(pList) == 0){
  pFirstElem = pList->anchor.next;
 }
 return pFirstElem;
}

variable_types: struct tagMy402List { int num_members; struct tagMy402ListElem anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); void (*UnlinkAll)(struct tagMy402List *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); } *

variable_types: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } *


original_code:
int My402ListPrepend(My402List *pList, void *obj){
 int isSuccess = 0;
 My402ListElem *ptrToAnchor = &(pList->anchor);
 My402ListElem *pFirstElem = ((void *)0);
 My402ListElem *current = ((void *)0);
 current = (My402ListElem *)malloc(sizeof(My402ListElem));
 if(current == ((void *)0)){
  return isSuccess;
 }
 isSuccess = 1;
 current->obj = obj;
 current->prev = ((void *)0);
 current->next = ((void *)0);
 pFirstElem = My402ListFirst(pList);
 if(pFirstElem == ((void *)0) ){
  current->next = ptrToAnchor;
  ptrToAnchor->next = current;
  current->prev = ptrToAnchor;
  ptrToAnchor->prev = current;
 }else{
  current->next = pFirstElem;
  ptrToAnchor->next = current;
  pFirstElem->prev = current;
  current->prev = ptrToAnchor;
 }
 pList->num_members = pList->num_members+1;
 return isSuccess;
}

canonical_original_code:
int My402ListPrepend(struct tagMy402List *pList, void *obj){
 int isSuccess = 0;
 struct tagMy402ListElem *ptrToAnchor = &(pList->anchor);
 struct tagMy402ListElem *pFirstElem = ((void *)0);
 struct tagMy402ListElem *current = ((void *)0);
 current = (struct tagMy402ListElem *)malloc(sizeof(My402ListElem));
 if(current == ((void *)0)){
  return isSuccess;
 }
 isSuccess = 1;
 current->obj = obj;
 current->prev = ((void *)0);
 current->next = ((void *)0);
 pFirstElem = My402ListFirst(pList);
 if(pFirstElem == ((void *)0) ){
  current->next = ptrToAnchor;
  ptrToAnchor->next = current;
  current->prev = ptrToAnchor;
  ptrToAnchor->prev = current;
 }else{
  current->next = pFirstElem;
  ptrToAnchor->next = current;
  pFirstElem->prev = current;
  current->prev = ptrToAnchor;
 }
 pList->num_members = pList->num_members+1;
 return isSuccess;
}

variable_types: struct tagMy402List { int num_members; struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); void (*UnlinkAll)(struct tagMy402List *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); } *

variable_types:
obj
void *

variable_types: isSuccess int

return_type: int

user_defined_types: struct tagMy402List { int num_members; struct tagMy402ListElem anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); void (*UnlinkAll)(struct tagMy402List *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); }


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

if ( a2 == My402ListFirst(a1) )
result = 0LL;
else
result = *(_QWORD *)(a2 + 16);
return result;
}

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

if ( a2 == func2(a1) )
result = 0LL;
else
result = *(_QWORD *)(a2 + 16);
return result;
}

original_code:
My402ListElem *My402ListPrev(My402List *pList, My402ListElem *pElem){
 My402ListElem *pPrevElem = ((void *)0);
 if(My402ListFirst(pList) != pElem){
  pPrevElem = pElem->prev;
 }
 return pPrevElem;
}

canonical_original_code:
struct tagMy402ListElem *My402ListPrev(struct tagMy402List *pList, struct tagMy402ListElem *pElem){
 struct tagMy402ListElem *pPrevElem = ((void *)0);
 if(My402ListFirst(pList) != pElem){
  pPrevElem = pElem->prev;
 }
 return pPrevElem;
}

variable_types:
pElem
struct tagMy402ListElem *

return_type: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } *


decompiled_code:
__int64 __fastcall My402ListLast(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = My402ListEmpty((_DWORD *)a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 24);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = func1((_DWORD *)a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 24);
return result;
}

original_code:
My402ListElem *My402ListLast(My402List *pList){
 My402ListElem *pLastElem = ((void *)0);
 if(My402ListEmpty(pList) == 0){
  pLastElem = pList->anchor.prev;
 }
 return pLastElem;
}

canonical_original_code:
struct tagMy402ListElem *My402ListLast(struct tagMy402List *pList){
 struct tagMy402ListElem *pLastElem = ((void *)0);
 if(My402ListEmpty(pList) == 0){
  pLastElem = pList->anchor.prev;
 }
 return pLastElem;
}


original_code:
int My402ListAppend(My402List *pList, void *obj){
 int isSuccess = 0;
 My402ListElem *current = ((void *)0);
 My402ListElem *ptrToAnchor = &(pList->anchor);
 My402ListElem *pLastElem = ((void *)0);
 current = (My402ListElem *)malloc(sizeof(My402ListElem));
 if( current == ((void *)0)){
  return isSuccess;
 }
 isSuccess = 1;
 current->obj = obj;
 current->prev = ((void *)0);
 current->next = ((void *)0);
 pLastElem = My402ListLast(pList);
 if(pLastElem == ((void *)0)){
  current->next = ptrToAnchor;
  ptrToAnchor->next = current;
  current->prev = ptrToAnchor;
  ptrToAnchor->prev = current;
 }else{
  current->next = ptrToAnchor;
  pLastElem->next = current;
  current->prev = pLastElem;
  ptrToAnchor->prev = current;
 }
 pList->num_members = pList->num_members+1;
 return isSuccess;
}

canonical_original_code:
int My402ListAppend(struct tagMy402List *pList, void *obj){
 int isSuccess = 0;
 struct tagMy402ListElem *current = ((void *)0);
 struct tagMy402ListElem *ptrToAnchor = &(pList->anchor);
 struct tagMy402ListElem *pLastElem = ((void *)0);
 current = (struct tagMy402ListElem *)malloc(sizeof(My402ListElem));
 if( current == ((void *)0)){
  return isSuccess;
 }
 isSuccess = 1;
 current->obj = obj;
 current->prev = ((void *)0);
 current->next = ((void *)0);
 pLastElem = My402ListLast(pList);
 if(pLastElem == ((void *)0)){
  current->next = ptrToAnchor;
  ptrToAnchor->next = current;
  current->prev = ptrToAnchor;
  ptrToAnchor->prev = current;
 }else{
  current->next = ptrToAnchor;
  pLastElem->next = current;
  current->prev = pLastElem;
  ptrToAnchor->prev = current;
 }
 pList->num_members = pList->num_members+1;
 return isSuccess;
}


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

if ( a2 == My402ListLast(a1) )
result = 0LL;
else
result = *(_QWORD *)(a2 + 8);
return result;
}

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

if ( a2 == func5(a1) )
result = 0LL;
else
result = *(_QWORD *)(a2 + 8);
return result;
}

original_code:
My402ListElem *My402ListNext(My402List *pList, My402ListElem *pElem){
 My402ListElem *pNextElem = ((void *)0);
 if(My402ListLast(pList) != pElem){
  pNextElem = pElem->next;
 }
 return pNextElem;
}

canonical_original_code:
struct tagMy402ListElem *My402ListNext(struct tagMy402List *pList, struct tagMy402ListElem *pElem){
 struct tagMy402ListElem *pNextElem = ((void *)0);
 if(My402ListLast(pList) != pElem){
  pNextElem = pElem->next;
 }
 return pNextElem;
}


decompiled_code:
__int64 __fastcall My402ListInsertBefore(_DWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax

v4 = malloc(0x18uLL);
if ( !v4 )
return 0LL;
*v4 = a2;
if ( !a3 )
return My402ListPrepend((__int64)a1, a2);
v4[1] = a3;
*(_QWORD *)(*(_QWORD *)(a3 + 16) + 8LL) = v4;
v4[2] = *(_QWORD *)(a3 + 16);
*(_QWORD *)(a3 + 16) = v4;
++*a1;
return 1LL;
}

original_code:
int My402ListInsertBefore(My402List *pList,void *obj, My402ListElem *pElem){
 My402ListElem *current = ((void *)0);
 int isSuccess = 0;
 current = (My402ListElem *)malloc(sizeof(My402ListElem));
 if(current == ((void *)0)){
  return 0;
 }
 current->obj = obj;
 if(pElem == ((void *)0)){
  isSuccess = My402ListPrepend(pList,obj);
 }else{
  current->next = pElem;
  pElem->prev->next = current;
  current->prev = pElem->prev;
  pElem->prev = current;
  isSuccess = 1;
  pList->num_members = pList->num_members+1;
 }
 return isSuccess;
}

canonical_original_code:
int My402ListInsertBefore(struct tagMy402List *pList, void *obj, struct tagMy402ListElem *pElem){
 struct tagMy402ListElem *current = ((void *)0);
 int isSuccess = 0;
 current = (struct tagMy402ListElem *)malloc(sizeof(My402ListElem));
 if(current == ((void *)0)){
  return 0;
 }
 current->obj = obj;
 if(pElem == ((void *)0)){
  isSuccess = My402ListPrepend(pList,obj);
 }else{
  current->next = pElem;
  pElem->prev->next = current;
  current->prev = pElem->prev;
  pElem->prev = current;
  isSuccess = 1;
  pList->num_members = pList->num_members+1;
 }
 return isSuccess;
}


decompiled_code:
__int64 __fastcall My402ListInsertAfter(_DWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx

v4 = malloc(0x18uLL);
if ( !v4 )
return 0LL;
*v4 = a2;
if ( !a3 )
return My402ListAppend((__int64)a1, a2);
v5 = *(_QWORD *)(a3 + 8);
v4[1] = v5;
*(_QWORD *)(a3 + 8) = v4;
*(_QWORD *)(v5 + 16) = v4;
v4[2] = a3;
++*a1;
return 1LL;
}

original_code:
int My402ListInsertAfter(My402List *pList,void *obj, My402ListElem *pElem){
 My402ListElem *current = ((void *)0);
 int isSuccess = 0;
 current = (My402ListElem *)malloc(sizeof(My402ListElem));
 if(current == ((void *)0)){
  return 0;
 }
 current->obj = obj;
 if(pElem == ((void *)0)){
  isSuccess = My402ListAppend(pList,obj);
 }else{
  current->next = pElem->next;
  pElem->next =current;
  current->next->prev = current;
  current->prev = pElem;
  isSuccess = 1;
  pList->num_members = pList->num_members+1;
 }
 return isSuccess;
}

canonical_original_code:
int My402ListInsertAfter(struct tagMy402List *pList, void *obj, struct tagMy402ListElem *pElem){
 struct tagMy402ListElem *current = ((void *)0);
 int isSuccess = 0;
 current = (struct tagMy402ListElem *)malloc(sizeof(My402ListElem));
 if(current == ((void *)0)){
  return 0;
 }
 current->obj = obj;
 if(pElem == ((void *)0)){
  isSuccess = My402ListAppend(pList,obj);
 }else{
  current->next = pElem->next;
  pElem->next =current;
  current->next->prev = current;
  current->prev = pElem;
  isSuccess = 1;
  pList->num_members = pList->num_members+1;
 }
 return isSuccess;
}


decompiled_code:
__int64 __fastcall My402ListInit(_QWORD *a1)
{
*a1 = 0LL;
a1[16] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 136) >> 3));
a1[2] = a1 + 1;
a1[3] = a1 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
*a1 = 0LL;
a1[16] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 136) >> 3));
a1[2] = a1 + 1;
a1[3] = a1 + 1;
return 0LL;
}

original_code:
int My402ListInit(My402List *pList){
 int isSuccess = 0;
 memset(pList,0,sizeof(*pList));
 My402ListElem *ptrToAnchor = &(pList->anchor);
 ptrToAnchor->obj = ((void *)0);
 ptrToAnchor->next = ptrToAnchor;
 ptrToAnchor->prev = ptrToAnchor;
 return isSuccess;
}

canonical_original_code:
int My402ListInit(struct tagMy402List *pList){
 int isSuccess = 0;
 memset(pList,0,sizeof(*pList));
 struct tagMy402ListElem *ptrToAnchor = &(pList->anchor);
 ptrToAnchor->obj = ((void *)0);
 ptrToAnchor->next = ptrToAnchor;
 ptrToAnchor->prev = ptrToAnchor;
 return isSuccess;
}


original_code:
void My402ListUnlink(My402List *pList, My402ListElem *pElem){
 if(My402ListEmpty(pList) == 0){
  My402ListElem *pred = pElem->prev;
  My402ListElem *succ = pElem->next;
  pred->next = succ;
  succ->prev = pred;
  pElem->prev = ((void *)0);
  pElem->next = ((void *)0);
  free(pElem);
  pList->num_members = pList->num_members-1;
 }
}

canonical_original_code:
void My402ListUnlink(struct tagMy402List *pList, struct tagMy402ListElem *pElem){
 if(My402ListEmpty(pList) == 0){
  struct tagMy402ListElem *pred = pElem->prev;
  struct tagMy402ListElem *succ = pElem->next;
  pred->next = succ;
  succ->prev = pred;
  pElem->prev = ((void *)0);
  pElem->next = ((void *)0);
  free(pElem);
  pList->num_members = pList->num_members-1;
 }
}

return_type: void


decompiled_code:
void __fastcall My402ListUnlinkAll(_DWORD *a1)
{
__int64 v1; // rbx
_QWORD *v2; // r12

v1 = My402ListLast((__int64)a1);
while ( v1 )
{
v2 = (_QWORD *)v1;
v1 = My402ListPrev((__int64)a1, v1);
My402ListUnlink(a1, v2);
}
}

original_code:
void My402ListUnlinkAll(My402List *pList){
 My402ListElem *current = My402ListLast(pList);
 My402ListElem *currentPrev = current;
 while(currentPrev != ((void *)0)){
  currentPrev = My402ListPrev(pList,current);
  My402ListUnlink(pList, current);
  current = currentPrev;
 }
}

canonical_original_code:
void My402ListUnlinkAll(struct tagMy402List *pList){
 struct tagMy402ListElem *current = My402ListLast(pList);
 struct tagMy402ListElem *currentPrev = current;
 while(currentPrev != ((void *)0)){
  currentPrev = My402ListPrev(pList,current);
  My402ListUnlink(pList, current);
  current = currentPrev;
 }
}


printList

decompiled_code:
__int64 __fastcall printList(__int64 a1)
{
__int64 result; // rax
__int64 i; // rsi

result = My402ListFirst();
for ( i = result; result; i = result )
result = My402ListNext(a1, i);
return result;
}

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

result = My402ListFirst();
for ( i = result; result; i = result )
result = My402ListNext(a1, i);
return result;
}

original_code:
void printList(My402List *pList){
 My402ListElem *current = ((void *)0);
 for(current=My402ListFirst(pList); current != ((void *)0); current = My402ListNext(pList, current)){
  printObj((My402SortElem *)current->obj);
 }
}

canonical_original_code:
void printList(struct tagMy402List *pList){
 struct tagMy402ListElem *current = ((void *)0);
 for(current=My402ListFirst(pList); current != ((void *)0); current = My402ListNext(pList, current)){
  printObj((struct My402SortElem *)current->obj);
 }
}

user_defined_types: struct My402SortElem { char transType; long transTime; long long transAmount; char *transDesc; }


printObj

decompiled_code:
void printObj()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void printObj(My402SortElem *obj){
}

canonical_original_code:
void printObj(struct My402SortElem *obj){
}

variable_types: struct My402SortElem { char transType; long transTime; long long transAmount; char *transDesc; } *


isASCIIChar

decompiled_code:
_BOOL8 __fastcall isASCIIChar(unsigned __int8 a1)
{
return a1 <= 0x3Fu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned __int8 a1)
{
return a1 <= 0x3Fu;
}

original_code:
int isASCIIChar(char ch){
 int isSuccess = 1;
 if(! (0 <= ch && ch <= 63) ){
  isSuccess = 0;
 }
 return isSuccess;
}

variable_types: ch char


isASCIIFile

decompiled_code:
_BOOL8 __fastcall isASCIIFile(unsigned __int8 *a1)
{
unsigned __int8 v2; // di
unsigned __int8 *v3; // rbx
_BOOL8 result; // rax

v2 = *a1;
if ( !v2 )
return 1LL;
v3 = a1 + 1;
while ( 1 )
{
result = isASCIIChar(v2);
if ( !result )
break;
v2 = *v3++;
if ( !v2 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(unsigned __int8 *a1)
{
unsigned __int8 v2; // di
unsigned __int8 *v3; // rbx
_BOOL8 result; // rax

v2 = *a1;
if ( !v2 )
return 1LL;
v3 = a1 + 1;
while ( 1 )
{
result = func2(v2);
if ( !result )
break;
v2 = *v3++;
if ( !v2 )
return 1LL;
}
return result;
}

original_code:
int isASCIIFile(char *str){
 int i=0;
 while(str[i] != '\0'){
  if(isASCIIChar(str[i]) == 0){
   return 0;
  }
  i++;
 }
 return 1;
}

canonical_original_code:
int isASCIIFile(char *str){
 int i = 0;
 while(str[i] != '\0'){
  if(isASCIIChar(str[i]) == 0){
   return 0;
  }
  i++;
 }
 return 1;
}

variable_types:
str
char *

variable_types: i int


unlinkSortElements

decompiled_code:
__int64 __fastcall unlinkSortElements(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
void **v3; // rbp

result = My402ListLast();
for ( i = result; i; result = My402ListUnlink(a1, v3) )
{
v3 = (void **)i;
i = My402ListPrev(a1, i);
free(*v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
void **v3; // rbp

result = My402ListLast();
for ( i = result; i; result = My402ListUnlink(a1, v3) )
{
v3 = (void **)i;
i = My402ListPrev(a1, i);
free(*v3);
}
return result;
}

original_code:
void unlinkSortElements(My402List *pList){
        My402ListElem *current = My402ListLast(pList);
        My402ListElem *currentPrev = current;
        while(currentPrev != ((void *)0)){
                currentPrev = My402ListPrev(pList,current);
  free(current->obj);
                My402ListUnlink(pList, current);
                current = currentPrev;
        }
}

canonical_original_code:
void unlinkSortElements(struct tagMy402List *pList){
        struct tagMy402ListElem *current = My402ListLast(pList);
        struct tagMy402ListElem *currentPrev = current;
        while(currentPrev != ((void *)0)){
                currentPrev = My402ListPrev(pList,current);
  free(current->obj);
                My402ListUnlink(pList, current);
                current = currentPrev;
        }
}


verifySortElem

decompiled_code:
__int64 __fastcall verifySortElem(char **a1)
{
char v1; // dl
char *v2; // rbp
__int64 v3; // rbp
const char *v4; // r12
char *v5; // rax
size_t v6; // r13
__int64 v8; // rbp
const char *v9; // rdi

v1 = **a1;
if ( ((v1 - 43) & 0xFD) != 0 )
{
fprintf(stderr, "\nTransaction type is given incorrectly as %c.Transaction type must be + or -.", (unsigned int)v1);
LODWORD(v2) = 0;
}
else
{
LODWORD(v2) = myDigitCheck(a1[1]);
if ( (_DWORD)v2 )
{
v3 = atoll(a1[1]);
if ( v3 < 0 || v3 >= time(0LL) )
{
fprintf(
stderr,
"\n"
"Transaction time is given incorrectly as %s.\n"
"Transaction time must be a positive number less than the current time.",
a1[1]);
LODWORD(v2) = 0;
}
else
{
v4 = a1[2];
v5 = strchr(v4, 46);
v2 = v5;
if ( *v4 == 45 )
{
fprintf(
stderr,
"\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a positive numeral.",
v4);
LODWORD(v2) = 0;
}
else if ( v5 )
{
if ( v5 - v4 <= 7 && (v6 = strlen(v4), &v4[v6 - 1] - v2 == 2) )
{
if ( v6 )
{
v8 = 0LL;
while ( (_DWORD)v6 - 3 == (_DWORD)v8 || ((*_ctype_b_loc())[v4[v8]] & 0x800) != 0 )
{
if ( ++v8 == v6 )
goto LABEL_22;
}
fprintf(
stderr,
"\n"
"Transaction Amount is give incorrectly as %s. Transaction amount must not contain any non-numerals excep"
"t the single decimal point.",
v4);
LODWORD(v2) = 0;
}
else
{
LABEL_22:
if ( atoll(v4) )
{
v9 = a1[3];
if ( *v9 )
{
LODWORD(v2) = 1;
if ( strchr(v9, 9) )
{
fwrite("\nTransaction Description contains a tab.", 1uLL, 0x28uLL, stderr);
LODWORD(v2) = 0;
}
}
else
{
fwrite("\nTransaction Description can not be empty.", 1uLL, 0x2AuLL, stderr);
LODWORD(v2) = 0;
}
}
else
{
fprintf(
stderr,
"\nTransaction Amount is give incorrectly as %s. Transaction amount must be a positive number.",
v4);
LODWORD(v2) = 0;
}
}
}
else
{
fprintf(
stderr,
"\n"
"Transaction Amount is given incorrectly as %s.\n"
"Transaction amount must be a decimal number with two decimals and at most 7 digits before the decimal.",
v4);
LODWORD(v2) = 0;
}
}
else
{
fprintf(
stderr,
"\n"
"Transaction Amount is given incorrectly as %s.\n"
"Transaction amount must be a decimal number with two decimals.",
v4);
}
}
}
else
{
fprintf(
stderr,
"\nTransaction time is given incorrectly as %s.Transaction time must contain only numerics.",
a1[1]);
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char **a1)
{
char v1; // dl
char *v2; // rbp
__int64 v3; // rbp
const char *v4; // r12
char *v5; // rax
size_t v6; // r13
__int64 v8; // rbp
const char *v9; // rdi

v1 = **a1;
if ( ((v1 - 43) & 0xFD) != 0 )
{
fprintf(stderr, "\nTransaction type is given incorrectly as %c.Transaction type must be + or -.", (unsigned int)v1);
LODWORD(v2) = 0;
}
else
{
LODWORD(v2) = myDigitCheck(a1[1]);
if ( (_DWORD)v2 )
{
v3 = atoll(a1[1]);
if ( v3 < 0 || v3 >= time(0LL) )
{
fprintf(
stderr,
"\n"
"Transaction time is given incorrectly as %s.\n"
"Transaction time must be a positive number less than the current time.",
a1[1]);
LODWORD(v2) = 0;
}
else
{
v4 = a1[2];
v5 = strchr(v4, 46);
v2 = v5;
if ( *v4 == 45 )
{
fprintf(
stderr,
"\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a positive numeral.",
v4);
LODWORD(v2) = 0;
}
else if ( v5 )
{
if ( v5 - v4 <= 7 && (v6 = strlen(v4), &v4[v6 - 1] - v2 == 2) )
{
if ( v6 )
{
v8 = 0LL;
while ( (_DWORD)v6 - 3 == (_DWORD)v8 || ((*_ctype_b_loc())[v4[v8]] & 0x800) != 0 )
{
if ( ++v8 == v6 )
goto LABEL_22;
}
fprintf(
stderr,
"\n"
"Transaction Amount is give incorrectly as %s. Transaction amount must not contain any non-numerals excep"
"t the single decimal point.",
v4);
LODWORD(v2) = 0;
}
else
{
LABEL_22:
if ( atoll(v4) )
{
v9 = a1[3];
if ( *v9 )
{
LODWORD(v2) = 1;
if ( strchr(v9, 9) )
{
fwrite("\nTransaction Description contains a tab.", 1uLL, 0x28uLL, stderr);
LODWORD(v2) = 0;
}
}
else
{
fwrite("\nTransaction Description can not be empty.", 1uLL, 0x2AuLL, stderr);
LODWORD(v2) = 0;
}
}
else
{
fprintf(
stderr,
"\nTransaction Amount is give incorrectly as %s. Transaction amount must be a positive number.",
v4);
LODWORD(v2) = 0;
}
}
}
else
{
fprintf(
stderr,
"\n"
"Transaction Amount is given incorrectly as %s.\n"
"Transaction amount must be a decimal number with two decimals and at most 7 digits before the decimal.",
v4);
LODWORD(v2) = 0;
}
}
else
{
fprintf(
stderr,
"\n"
"Transaction Amount is given incorrectly as %s.\n"
"Transaction amount must be a decimal number with two decimals.",
v4);
}
}
}
else
{
fprintf(
stderr,
"\nTransaction time is given incorrectly as %s.Transaction time must contain only numerics.",
a1[1]);
}
}
return (unsigned int)v2;
}

original_code:
int verifySortElem(char **pSortElem){
 char *dotPos = 0;
 char *startPos = ((void *)0);
 char *lastPos = ((void *)0);
 int i=0;
 int len= 0;
 if (! (*pSortElem[0] == '+' || *pSortElem[0] == '-')){
  fprintf(stderr,"\nTransaction type is given incorrectly as %c.Transaction type must be + or -.",*pSortElem[0]);
  return 0;
 }
 if(myDigitCheck(pSortElem[1]) == 0){
  fprintf(stderr,"\nTransaction time is given incorrectly as %s.Transaction time must contain only numerics.",pSortElem[1]);
  return 0;
 }
 if(
  !(0<= atoll(pSortElem[1])
   && (long long)atoll(pSortElem[1])< (long long) time(((void *)0))
     )
   ) {
  fprintf(stderr,"\nTransaction time is given incorrectly as %s.\nTransaction time must be a positive number less than the current time.",pSortElem[1]);
  return 0;
 }
 startPos = &pSortElem[2][0];
 dotPos = strchr(pSortElem[2], '.');
 lastPos = startPos+strlen(pSortElem[2])-1;
 if(pSortElem[2][0] == '-'){
  fprintf(stderr, "\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a positive numeral.", pSortElem[2]);
  return 0;
 }
 if(dotPos == ((void *)0)){
  fprintf(stderr, "\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a decimal number with two decimals.", pSortElem[2]);
  return 0;
 }
 if(!( dotPos-startPos <=7 && lastPos-dotPos == 2) ){
  fprintf(stderr, "\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a decimal number with two decimals and at most 7 digits before the decimal.", pSortElem[2]);
  return 0;
 }
 len = strlen(pSortElem[2]);
 for(i=0; i<strlen(pSortElem[2]); i++){
  if(i == len-3){
   continue;
  }
  if(!((*__ctype_b_loc ())[(int) ((pSortElem[2][i]))] & (unsigned short int) _ISdigit)){
   fprintf(stderr,"\nTransaction Amount is give incorrectly as %s. Transaction amount must not contain any non-numerals except the single decimal point.", pSortElem[2]);
   return 0;
  }
 }
 if(atoll(pSortElem[2]) == 0){
  fprintf(stderr,"\nTransaction Amount is give incorrectly as %s. Transaction amount must be a positive number.", pSortElem[2]);
  return 0;
 }
 if(strlen(pSortElem[3]) == 0){
  fprintf(stderr,"\nTransaction Description can not be empty.");
  return 0;
 }
 if(strchr(pSortElem[3],'\t') != ((void *)0) ){
  fprintf(stderr,"\nTransaction Description contains a tab.");
  return 0;
 }
 return 1;
}

canonical_original_code:
int verifySortElem(char **pSortElem){
 char *dotPos = 0;
 char *startPos = ((void *)0);
 char *lastPos = ((void *)0);
 int i = 0;
 int len = 0;
 if (! (*pSortElem[0] == '+' || *pSortElem[0] == '-')){
  fprintf(stderr,"\nTransaction type is given incorrectly as %c.Transaction type must be + or -.",*pSortElem[0]);
  return 0;
 }
 if(myDigitCheck(pSortElem[1]) == 0){
  fprintf(stderr,"\nTransaction time is given incorrectly as %s.Transaction time must contain only numerics.",pSortElem[1]);
  return 0;
 }
 if(
  !(0<= atoll(pSortElem[1])
   && (long long)atoll(pSortElem[1])< (long long) time(((void *)0))
     )
   ) {
  fprintf(stderr,"\nTransaction time is given incorrectly as %s.\nTransaction time must be a positive number less than the current time.",pSortElem[1]);
  return 0;
 }
 startPos = &pSortElem[2][0];
 dotPos = strchr(pSortElem[2], '.');
 lastPos = startPos+strlen(pSortElem[2])-1;
 if(pSortElem[2][0] == '-'){
  fprintf(stderr, "\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a positive numeral.", pSortElem[2]);
  return 0;
 }
 if(dotPos == ((void *)0)){
  fprintf(stderr, "\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a decimal number with two decimals.", pSortElem[2]);
  return 0;
 }
 if(!( dotPos-startPos <=7 && lastPos-dotPos == 2) ){
  fprintf(stderr, "\nTransaction Amount is given incorrectly as %s.\nTransaction amount must be a decimal number with two decimals and at most 7 digits before the decimal.", pSortElem[2]);
  return 0;
 }
 len = strlen(pSortElem[2]);
 for(i=0; i<strlen(pSortElem[2]); i++){
  if(i == len-3){
   continue;
  }
  if(!((*__ctype_b_loc ())[(int) ((pSortElem[2][i]))] & (unsigned short) _ISdigit)){
   fprintf(stderr,"\nTransaction Amount is give incorrectly as %s. Transaction amount must not contain any non-numerals except the single decimal point.", pSortElem[2]);
   return 0;
  }
 }
 if(atoll(pSortElem[2]) == 0){
  fprintf(stderr,"\nTransaction Amount is give incorrectly as %s. Transaction amount must be a positive number.", pSortElem[2]);
  return 0;
 }
 if(strlen(pSortElem[3]) == 0){
  fprintf(stderr,"\nTransaction Description can not be empty.");
  return 0;
 }
 if(strchr(pSortElem[3],'\t') != ((void *)0) ){
  fprintf(stderr,"\nTransaction Description contains a tab.");
  return 0;
 }
 return 1;
}

variable_types:
pSortElem
char **

variable_types:
dotPos
char *

variable_types:
startPos
char *

variable_types:
lastPos
char *

variable_types: len int


getNoDigitsBeforeDecimal

decompiled_code:
__int64 __fastcall getNoDigitsBeforeDecimal(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // ecx
char v3; // dl

if ( *a1 == 46 || !*a1 )
return 0;
v1 = 1LL;
do
{
v2 = v1;
v3 = a1[v1++];
}
while ( v3 != 46 && v3 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // ecx
char v3; // dl

if ( *a1 == 46 || !*a1 )
return 0;
v1 = 1LL;
do
{
v2 = v1;
v3 = a1[v1++];
}
while ( v3 != 46 && v3 );
return v2;
}

original_code:
int getNoDigitsBeforeDecimal(char *str){
 int i=0;
 while(str[i] != '.' && str[i] != '\0'){
  i++;
 }
 return i;
}

canonical_original_code:
int getNoDigitsBeforeDecimal(char *str){
 int i = 0;
 while(str[i] != '.' && str[i] != '\0'){
  i++;
 }
 return i;
}


trim

original_code:
char *trim(char *input){
 if(input == ((void *)0)){
  return ((void *)0);
 }
 int descLen = (int)strlen(input);
 char *returnVal = (char *)malloc((descLen+1)*sizeof(char));
 memset(returnVal, '\0', (descLen+1)*sizeof(char));
 int i = strlen(input)-1;
 int j=0;
 if(input == ((void *)0)){
  return ((void *)0);
 }
 if(input[strlen(input)-1] == '\n'){
  input[strlen(input)-1] = '\0';
 }
 if(input[0] != ' '){
  return input;
 }else{
  i=0;
  while(input[i] == ' ' && i < strlen(input)){
   i++;
  }
  i=0;
  while(input[i] != '\0'){
   returnVal[j] = input[i];
   j++;
   i++;
  }
  return returnVal;
 }
}

canonical_original_code:
char *trim(char *input){
 if(input == ((void *)0)){
  return ((void *)0);
 }
 int descLen = (int)strlen(input);
 char *returnVal = (char *)malloc((descLen+1)*sizeof(char));
 memset(returnVal, '\0', (descLen+1)*sizeof(char));
 int i = strlen(input)-1;
 int j = 0;
 if(input == ((void *)0)){
  return ((void *)0);
 }
 if(input[strlen(input)-1] == '\n'){
  input[strlen(input)-1] = '\0';
 }
 if(input[0] != ' '){
  return input;
 }else{
  i=0;
  while(input[i] == ' ' && i < strlen(input)){
   i++;
  }
  i=0;
  while(input[i] != '\0'){
   returnVal[j] = input[i];
   j++;
   i++;
  }
  return returnVal;
 }
}

variable_types:
input
char *

variable_types: descLen int

variable_types:
returnVal
char *

variable_types: j int

return_type: char *


insertionSort

decompiled_code:
__int64 __fastcall insertionSort(__int64 a1, __int64 a2)
{
__int64 *v2; // rbx
__int64 v3; // rax
__int64 v4; // rcx
__int64 v5; // rax
__int64 result; // rax

v2 = (__int64 *)My402ListLast();
if ( v2 )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
goto LABEL_7;
v4 = *(_QWORD *)(a2 + 8);
if ( *(_QWORD *)(v3 + 8) <= v4 )
break;
v5 = My402ListPrev(a1, v2);
if ( !v5 )
goto LABEL_9;
v2 = (__int64 *)v5;
}
if ( *(_QWORD *)(v3 + 8) != v4 )
{
LABEL_7:
My402ListInsertAfter(a1, a2, v2);
return 1LL;
}
fprintf(stderr, "\nTime stamp %lld is repeated for some entries", *(_QWORD *)(a2 + 8));
unlinkSortElements(a1);
result = 0LL;
}
else
{
LABEL_9:
My402ListInsertBefore(a1, a2, v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 *v2; // rbx
__int64 v3; // rax
__int64 v4; // rcx
__int64 v5; // rax
__int64 result; // rax

v2 = (__int64 *)My402ListLast();
if ( v2 )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
goto LABEL_7;
v4 = *(_QWORD *)(a2 + 8);
if ( *(_QWORD *)(v3 + 8) <= v4 )
break;
v5 = My402ListPrev(a1, v2);
if ( !v5 )
goto LABEL_9;
v2 = (__int64 *)v5;
}
if ( *(_QWORD *)(v3 + 8) != v4 )
{
LABEL_7:
My402ListInsertAfter(a1, a2, v2);
return 1LL;
}
fprintf(stderr, "\nTime stamp %lld is repeated for some entries", *(_QWORD *)(a2 + 8));
func4(a1);
result = 0LL;
}
else
{
LABEL_9:
My402ListInsertBefore(a1, a2, v2);
result = 1LL;
}
return result;
}

original_code:
int insertionSort(My402List *pList, My402SortElem *pKey){
 My402ListElem *current = My402ListLast(pList);
 My402ListElem *prevCurrent = current;
 while(current != ((void *)0) &&
  current->obj != ((void *)0) &&
   ((My402SortElem *)current->obj)->transTime > pKey->transTime){
  prevCurrent = current;
  current = My402ListPrev(pList, current);
 }
 if(current != ((void *)0) && current->obj != ((void *)0)){
  if(((My402SortElem *)current->obj)->transTime == pKey->transTime){
   fprintf(stderr,"\nTime stamp %lld is repeated for some entries",(long long)pKey->transTime);
   unlinkSortElements(pList);
   return 0;
  }
 }
 if(current == ((void *)0)){
  My402ListInsertBefore(pList, pKey, prevCurrent);
 }else{
  My402ListInsertAfter(pList, pKey, current);
 }
 return 1;
}

canonical_original_code:
int insertionSort(struct tagMy402List *pList, struct My402SortElem *pKey){
 struct tagMy402ListElem *current = My402ListLast(pList);
 struct tagMy402ListElem *prevCurrent = current;
 while(current != ((void *)0) &&
  current->obj != ((void *)0) &&
   ((struct My402SortElem *)current->obj)->transTime > pKey->transTime){
  prevCurrent = current;
  current = My402ListPrev(pList, current);
 }
 if(current != ((void *)0) && current->obj != ((void *)0)){
  if(((struct My402SortElem *)current->obj)->transTime == pKey->transTime){
   fprintf(stderr,"\nTime stamp %lld is repeated for some entries",(long long)pKey->transTime);
   unlinkSortElements(pList);
   return 0;
  }
 }
 if(current == ((void *)0)){
  My402ListInsertBefore(pList, pKey, prevCurrent);
 }else{
  My402ListInsertAfter(pList, pKey, current);
 }
 return 1;
}

variable_types: struct tagMy402List { int num_members; struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); void (*UnlinkAll)(struct tagMy402List *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); } *

variable_types: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } *


isTabsOK

decompiled_code:
_BOOL8 __fastcall isTabsOK(char *a1)
{
char v1; // al
char *v2; // rdi
int v3; // edx

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1 == 9;
v1 = *v2++;
}
while ( v1 );
}
else
{
v3 = 0;
}
return v3 == 3;
}

original_code:
int isTabsOK(char *str){
 int i=0;
 int tabCount = 0;
 int isSuccess = 1;
 while(str[i] != '\0'){
  if(str[i] == '\t'){
   tabCount++;
  }
  i++;
 }
 if(tabCount !=3){
  isSuccess = 0;
 }
 return isSuccess;
}

canonical_original_code:
int isTabsOK(char *str){
 int i = 0;
 int tabCount = 0;
 int isSuccess = 1;
 while(str[i] != '\0'){
  if(str[i] == '\t'){
   tabCount++;
  }
  i++;
 }
 if(tabCount !=3){
  isSuccess = 0;
 }
 return isSuccess;
}

variable_types: tabCount int

variable_types: isSuccess int


reverse

decompiled_code:
const char *__fastcall reverse(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
char v3; // cl

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

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
char v3; // cl

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

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

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

variable_types:
dest
char *

variable_types: temp char


toCurrency

original_code:
char *toCurrency(long long num){
 int i=0;
 int j = 0;
 int count =1;
 int len = 0;
 long long intPart = num/100;
 int decimalPart = num%100;
 char *str = (char *) malloc(80*sizeof(char));
 char *dest = (char *) malloc(80*sizeof(char));
 if(str == ((void *)0)){
  fprintf(stderr, "\nUnable to allocate memory");
 }
 if(dest == ((void *)0)){
  fprintf(stderr, "\nUnable to allocate memory");
 }
 memset(str,'\0',80*sizeof(char));
 memset(dest,'\0',80*sizeof(char));
 if(num >= 1000000000){
  for(i=0; i<9; i++){
   str[i] = '?';
  }
  str[i] = '\0';
 }else{
  str = itoa(intPart);
 }
 i = strlen(str)-1;
 for(; i>=0; i--){
  dest[j++] = str[i];
  if( count%3 == 0 && i-1>=0 ){
   dest[j++] = ',';
  }
  count++;
 }
 dest[j] = '\0';
 dest = reverse(dest);
 if(num < 1000000000){
  len = strlen(dest);
  dest[len+1] = decimalPart%10+'0';
  decimalPart = decimalPart/10;
  dest[len] = decimalPart+'0';
  dest[len+2] = '\0';
 }
 len = strlen(dest);
 dest[len+1] = '\0';
 dest[len] = dest[len-1];
 dest[len-1] = dest[len-2];
 dest[len-2] = '.';
 return dest;
}

canonical_original_code:
char *toCurrency(long long num){
 int i = 0;
 int j = 0;
 int count = 1;
 int len = 0;
 long long intPart = num/100;
 int decimalPart = num%100;
 char *str = (char *) malloc(80*sizeof(char));
 char *dest = (char *) malloc(80*sizeof(char));
 if(str == ((void *)0)){
  fprintf(stderr, "\nUnable to allocate memory");
 }
 if(dest == ((void *)0)){
  fprintf(stderr, "\nUnable to allocate memory");
 }
 memset(str,'\0',80*sizeof(char));
 memset(dest,'\0',80*sizeof(char));
 if(num >= 1000000000){
  for(i=0; i<9; i++){
   str[i] = '?';
  }
  str[i] = '\0';
 }else{
  str = itoa(intPart);
 }
 i = strlen(str)-1;
 for(; i>=0; i--){
  dest[j++] = str[i];
  if( count%3 == 0 && i-1>=0 ){
   dest[j++] = ',';
  }
  count++;
 }
 dest[j] = '\0';
 dest = reverse(dest);
 if(num < 1000000000){
  len = strlen(dest);
  dest[len+1] = decimalPart%10+'0';
  decimalPart = decimalPart/10;
  dest[len] = decimalPart+'0';
  dest[len+2] = '\0';
 }
 len = strlen(dest);
 dest[len+1] = '\0';
 dest[len] = dest[len-1];
 dest[len-1] = dest[len-2];
 dest[len-2] = '.';
 return dest;
}

variable_types:
num
long long

variable_types: count int

variable_types:
intPart
long long

variable_types: decimalPart int

variable_types:
str
char *


myDigitCheck

decompiled_code:
__int64 __fastcall myDigitCheck(const char *a1)
{
size_t v2; // rdi
const char *v3; // rax
const char *v4; // rdi
char v5; // si

v2 = strlen(a1);
v3 = a1;
v4 = &a1[v2];
while ( v3 != v4 )
{
v5 = *v3++;
if ( (unsigned __int8)(v5 - 48) > 9u )
{
printf("\n Found a non-digit char:%c\n", (unsigned int)v5);
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
size_t v2; // rdi
const char *v3; // rax
const char *v4; // rdi
char v5; // si

v2 = strlen(a1);
v3 = a1;
v4 = &a1[v2];
while ( v3 != v4 )
{
v5 = *v3++;
if ( (unsigned __int8)(v5 - 48) > 9u )
{
printf("\n Found a non-digit char:%c\n", (unsigned int)v5);
return 0LL;
}
}
return 1LL;
}

original_code:
int myDigitCheck(char *a){
        int i=0;
        for(i=0; i<strlen(a); i++){
                if(! (0+'0'<=a[i] && a[i]<=9+'0')){
                        printf("\n Found a non-digit char:%c\n",a[i]);
                        return 0;
                }
        }
        return 1;
}

canonical_original_code:
int myDigitCheck(char *a){
        int i = 0;
        for(i=0; i<strlen(a); i++){
                if(! (0+'0'<=a[i] && a[i]<=9+'0')){
                        printf("\n Found a non-digit char:%c\n",a[i]);
                        return 0;
                }
        }
        return 1;
}

variable_types:
a
char *

variable_types: i int


formatEachField

decompiled_code:
__int64 __fastcall formatEachField(__int64 a1, _QWORD *a2, __int64 *a3)
{
char *v3; // rax
char *v4; // rbx
_BYTE *v5; // r13
_DWORD *v6; // rax
_BYTE *v7; // rbp
_DWORD *v8; // rax
_BYTE *v9; // r12
char *v10; // r15
char *v11; // r14
_QWORD *v12; // rax
char *v13; // rax
char v14; // dl
char *v15; // rax
int v16; // esi
int v17; // edi
_BYTE *v19; // rdx
_BYTE *v20; // rax
__int64 v21; // rax
int v22; // er13
size_t v23; // rax
int v24; // edx
char *v25; // rax
__int64 v26; // rdx
const char *v27; // rax
int v28; // eax
int v29; // edx
int v30; // esi
_BYTE *v31; // rax
__int64 v32; // rdx
int v33; // esi
char v34; // dl
int v35; // edi
__int64 v36; // rax
__int64 v37; // rax
const char *v38; // rax
int v39; // eax
__int64 v40; // rbx
int v41; // edx
int v42; // esi
_BYTE *v43; // rax
__int64 v44; // rdx
int v45; // esi
char v46; // dl
int v47; // edi
__int64 v48; // rax
const char *v49; // rsi
const char *v50; // rax
char *dest; // [rsp+10h] [rbp-68h]
int v54; // [rsp+24h] [rbp-54h]
__int64 v56; // [rsp+38h] [rbp-40h]

v3 = (char *)malloc(0x19uLL);
if ( !v3 )
goto LABEL_11;
v4 = v3;
v5 = malloc(0x10uLL);
if ( !v5 )
goto LABEL_11;
dest = (char *)malloc(4uLL);
if ( !dest )
goto LABEL_11;
*(_QWORD *)dest = 0LL;
*((_QWORD *)dest + 1) = 0LL;
*((_QWORD *)dest + 2) = 0LL;
dest[24] = 0;
v6 = malloc(4uLL);
v7 = v6;
if ( !v6 )
goto LABEL_11;
*(_QWORD *)v6 = 0LL;
v6[2] = 0;
*((_WORD *)v6 + 6) = 0;
*((_BYTE *)v6 + 14) = 0;
v8 = malloc(4uLL);
v9 = v8;
if ( !v8
|| (*(_QWORD *)v8 = 0LL,
v8[2] = 0,
*((_WORD *)v8 + 6) = 0,
*((_BYTE *)v8 + 14) = 0,
(v10 = (char *)malloc(0xFuLL)) == 0LL)
|| (v11 = (char *)malloc(0xFuLL)) == 0LL )
{
LABEL_11:
perror("\nUnable to allocate memory");
return 0LL;
}
v12 = malloc(0x1AuLL);
if ( !v12 )
{
perror("Unable to allocate memory");
return 0LL;
}
*v12 = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
*((_WORD *)v12 + 12) = 0;
v56 = *(_QWORD *)(a1 + 16);
v54 = 2 * (*(_BYTE *)a1 != 45) - 1;
v13 = ctime((const time_t *)(a1 + 8));
v14 = *v13;
if ( *v13 != 10 )
{
v15 = v13 + 1;
v16 = 0;
v17 = -10 - (_DWORD)v15;
do
{
if ( (unsigned int)(v17 + (_DWORD)v15) > 8 )
v5[v16++] = v14;
v14 = *v15++;
}
while ( v14 != 10 );
}
v5[15] = 0;
*a2 = v5;
strncpy(v4, *(const char **)(a1 + 24), 0x18uLL);
if ( !v4[24] )
{
v19 = v4 + 24;
do
{
*v19 = 32;
v20 = v19 - 1;
v19 = v20;
}
while ( (int)v20 - (int)v4 > 0 && !*v20 );
}
v4[24] = 0;
if ( *v4 == 32 )
{
v21 = 1LL;
do
v22 = v21++;
while ( v4[v21 - 1] == 32 );
}
else
{
v22 = 0;
}
v23 = strlen(&v4[v22]);
strncpy(dest, &v4[v22], v23);
v24 = strlen(v4);
if ( v24 - v22 <= 23 )
{
v25 = &dest[v24 - v22];
v26 = (__int64)&v25[v22 - v24 + 23 + 1];
do
*v25++ = 32;
while ( v25 != (char *)v26 );
}
strncpy(v4, dest, 0x18uLL);
a2[1] = v4;
v27 = (const char *)toCurrency(*(_QWORD *)(a1 + 16));
strncpy(v10, v27, 0xEuLL);
v28 = strlen(v10);
if ( v54 == -1 )
v29 = 11 - v28;
else
v29 = 12 - v28;
v30 = v29;
if ( v29 < 0 )
{
v34 = *v10;
v35 = 0;
v33 = 0;
if ( !*v10 )
goto LABEL_40;
}
else
{
v31 = v7;
v32 = (__int64)&v7[v29 + 1];
do
*v31++ = 32;
while ( v31 != (_BYTE *)v32 );
v33 = v30 + 1;
v34 = *v10;
if ( !*v10 )
goto LABEL_57;
v35 = 1;
}
v36 = v33;
do
{
v7[v36++] = v34;
v34 = v10[v36 - v33];
}
while ( v34 );
if ( v35 == 1 )
LABEL_57:
v7[13] = 32;
LABEL_40:
v7[14] = 0;
strncpy(v10, v7, 0xEuLL);
v10[14] = 0;
if ( v54 == -1 )
{
v49 = (const char *)representNegatives(v10);
strncpy(v10, v49, 0xEuLL);
}
v10[14] = 0;
a2[2] = v10;
v37 = *a3 + v56 * v54;
*a3 = v37;
v38 = (const char *)toCurrency(v37 * ((v37 >> 63) | 1));
strncpy(v11, v38, 0xEuLL);
v39 = strlen(v11);
v40 = *a3;
if ( *a3 < 0 )
v41 = 11 - v39;
else
v41 = 12 - v39;
v42 = v41;
if ( v41 < 0 )
{
v46 = *v11;
v47 = 0;
v45 = 0;
if ( !*v11 )
goto LABEL_52;
}
else
{
v43 = v9;
v44 = (__int64)&v9[v41 + 1];
do
*v43++ = 32;
while ( (_BYTE *)v44 != v43 );
v45 = v42 + 1;
v46 = *v11;
if ( !*v11 )
goto LABEL_59;
v47 = 1;
}
v48 = v45;
do
{
v9[v48++] = v46;
v46 = v11[v48 - v45];
}
while ( v46 );
if ( v47 == 1 )
LABEL_59:
v9[13] = 32;
LABEL_52:
v9[14] = 0;
strncpy(v11, v9, 0xEuLL);
v11[14] = 0;
if ( v40 < 0 )
{
v50 = (const char *)representNegatives(v11);
strncpy(v11, v50, 0xEuLL);
}
v11[14] = 0;
a2[3] = v11;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, __int64 *a3)
{
char *v3; // rax
char *v4; // rbx
_BYTE *v5; // r13
_DWORD *v6; // rax
_BYTE *v7; // rbp
_DWORD *v8; // rax
_BYTE *v9; // r12
char *v10; // r15
char *v11; // r14
_QWORD *v12; // rax
char *v13; // rax
char v14; // dl
char *v15; // rax
int v16; // esi
int v17; // edi
_BYTE *v19; // rdx
_BYTE *v20; // rax
__int64 v21; // rax
int v22; // er13
size_t v23; // rax
int v24; // edx
char *v25; // rax
__int64 v26; // rdx
const char *v27; // rax
int v28; // eax
int v29; // edx
int v30; // esi
_BYTE *v31; // rax
__int64 v32; // rdx
int v33; // esi
char v34; // dl
int v35; // edi
__int64 v36; // rax
__int64 v37; // rax
const char *v38; // rax
int v39; // eax
__int64 v40; // rbx
int v41; // edx
int v42; // esi
_BYTE *v43; // rax
__int64 v44; // rdx
int v45; // esi
char v46; // dl
int v47; // edi
__int64 v48; // rax
const char *v49; // rsi
const char *v50; // rax
char *dest; // [rsp+10h] [rbp-68h]
int v54; // [rsp+24h] [rbp-54h]
__int64 v56; // [rsp+38h] [rbp-40h]

v3 = (char *)malloc(0x19uLL);
if ( !v3 )
goto LABEL_11;
v4 = v3;
v5 = malloc(0x10uLL);
if ( !v5 )
goto LABEL_11;
dest = (char *)malloc(4uLL);
if ( !dest )
goto LABEL_11;
*(_QWORD *)dest = 0LL;
*((_QWORD *)dest + 1) = 0LL;
*((_QWORD *)dest + 2) = 0LL;
dest[24] = 0;
v6 = malloc(4uLL);
v7 = v6;
if ( !v6 )
goto LABEL_11;
*(_QWORD *)v6 = 0LL;
v6[2] = 0;
*((_WORD *)v6 + 6) = 0;
*((_BYTE *)v6 + 14) = 0;
v8 = malloc(4uLL);
v9 = v8;
if ( !v8
|| (*(_QWORD *)v8 = 0LL,
v8[2] = 0,
*((_WORD *)v8 + 6) = 0,
*((_BYTE *)v8 + 14) = 0,
(v10 = (char *)malloc(0xFuLL)) == 0LL)
|| (v11 = (char *)malloc(0xFuLL)) == 0LL )
{
LABEL_11:
perror("\nUnable to allocate memory");
return 0LL;
}
v12 = malloc(0x1AuLL);
if ( !v12 )
{
perror("Unable to allocate memory");
return 0LL;
}
*v12 = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
*((_WORD *)v12 + 12) = 0;
v56 = *(_QWORD *)(a1 + 16);
v54 = 2 * (*(_BYTE *)a1 != 45) - 1;
v13 = ctime((const time_t *)(a1 + 8));
v14 = *v13;
if ( *v13 != 10 )
{
v15 = v13 + 1;
v16 = 0;
v17 = -10 - (_DWORD)v15;
do
{
if ( (unsigned int)(v17 + (_DWORD)v15) > 8 )
v5[v16++] = v14;
v14 = *v15++;
}
while ( v14 != 10 );
}
v5[15] = 0;
*a2 = v5;
strncpy(v4, *(const char **)(a1 + 24), 0x18uLL);
if ( !v4[24] )
{
v19 = v4 + 24;
do
{
*v19 = 32;
v20 = v19 - 1;
v19 = v20;
}
while ( (int)v20 - (int)v4 > 0 && !*v20 );
}
v4[24] = 0;
if ( *v4 == 32 )
{
v21 = 1LL;
do
v22 = v21++;
while ( v4[v21 - 1] == 32 );
}
else
{
v22 = 0;
}
v23 = strlen(&v4[v22]);
strncpy(dest, &v4[v22], v23);
v24 = strlen(v4);
if ( v24 - v22 <= 23 )
{
v25 = &dest[v24 - v22];
v26 = (__int64)&v25[v22 - v24 + 23 + 1];
do
*v25++ = 32;
while ( v25 != (char *)v26 );
}
strncpy(v4, dest, 0x18uLL);
a2[1] = v4;
v27 = (const char *)toCurrency(*(_QWORD *)(a1 + 16));
strncpy(v10, v27, 0xEuLL);
v28 = strlen(v10);
if ( v54 == -1 )
v29 = 11 - v28;
else
v29 = 12 - v28;
v30 = v29;
if ( v29 < 0 )
{
v34 = *v10;
v35 = 0;
v33 = 0;
if ( !*v10 )
goto LABEL_40;
}
else
{
v31 = v7;
v32 = (__int64)&v7[v29 + 1];
do
*v31++ = 32;
while ( v31 != (_BYTE *)v32 );
v33 = v30 + 1;
v34 = *v10;
if ( !*v10 )
goto LABEL_57;
v35 = 1;
}
v36 = v33;
do
{
v7[v36++] = v34;
v34 = v10[v36 - v33];
}
while ( v34 );
if ( v35 == 1 )
LABEL_57:
v7[13] = 32;
LABEL_40:
v7[14] = 0;
strncpy(v10, v7, 0xEuLL);
v10[14] = 0;
if ( v54 == -1 )
{
v49 = (const char *)representNegatives(v10);
strncpy(v10, v49, 0xEuLL);
}
v10[14] = 0;
a2[2] = v10;
v37 = *a3 + v56 * v54;
*a3 = v37;
v38 = (const char *)toCurrency(v37 * ((v37 >> 63) | 1));
strncpy(v11, v38, 0xEuLL);
v39 = strlen(v11);
v40 = *a3;
if ( *a3 < 0 )
v41 = 11 - v39;
else
v41 = 12 - v39;
v42 = v41;
if ( v41 < 0 )
{
v46 = *v11;
v47 = 0;
v45 = 0;
if ( !*v11 )
goto LABEL_52;
}
else
{
v43 = v9;
v44 = (__int64)&v9[v41 + 1];
do
*v43++ = 32;
while ( (_BYTE *)v44 != v43 );
v45 = v42 + 1;
v46 = *v11;
if ( !*v11 )
goto LABEL_59;
v47 = 1;
}
v48 = v45;
do
{
v9[v48++] = v46;
v46 = v11[v48 - v45];
}
while ( v46 );
if ( v47 == 1 )
LABEL_59:
v9[13] = 32;
LABEL_52:
v9[14] = 0;
strncpy(v11, v9, 0xEuLL);
v11[14] = 0;
if ( v40 < 0 )
{
v50 = (const char *)representNegatives(v11);
strncpy(v11, v50, 0xEuLL);
}
v11[14] = 0;
a2[3] = v11;
return 1LL;
}

original_code:
int formatEachField(My402SortElem *currentElem, My402Output *pOutput, long long *pBalance){
 int sign = 1;
 int i=0;
 int j=0;
 int whiteSpaces = 0;
 int count = 0;
 int balanceSign = 1;
 int isEndingSpace = 0;
 char *printDesc = (char *)malloc(25*sizeof(char));
 if(printDesc == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *printDate = (char *)malloc(16*sizeof(char));
 if(printDate == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *desc = malloc(sizeof(25));
 if(desc == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(desc,'\0',25);
 char *amt = malloc(sizeof(15));
 if(amt == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(amt,'\0',15);
 char *bal = malloc(sizeof(15));
 if(bal == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(bal,'\0',15);
 char *printAmount = (char *)malloc(15*sizeof(char));
 if(printAmount == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *printBalance = (char *)malloc(15*sizeof(char));
 if(printBalance == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *cTime = (char *)malloc(26*sizeof(char));
 if(cTime == ((void *)0)){
  perror("Unable to allocate memory");
  return 0;
 }
 memset(cTime, '\0', 26*sizeof(char));
 long long currentAmount = currentElem->transAmount;
 if('-' == currentElem->transType){
  sign = -1;
 }
 cTime = ctime(&currentElem->transTime);
 while(cTime[i] != '\n'){
  if(! (i >= 10 && i<=18) ){
   printDate[j] = cTime[i];
   j++;
  }
  i++;
 }
 printDate[15] = '\0';
 pOutput->printDate = printDate;
 strncpy(printDesc, currentElem->transDesc,24);
 i=24;
 while(printDesc[i] == '\0' && i>0){
  printDesc[i] = ' ';
  i--;
 }
 printDesc[24] = '\0';
 whiteSpaces = 0;
 i=0;
 while(printDesc[i] == ' '&& printDesc[i]!= '\0'){
  whiteSpaces++;
  i++;
 }
 strncpy(desc, printDesc+whiteSpaces, strlen(printDesc+whiteSpaces));
 i=strlen(printDesc)-whiteSpaces;
 while(i<=23){
  desc[i++] = ' ';
 }
 strncpy(printDesc, desc, 24);
 printDesc[24] = '\0';
 pOutput->printDesc = printDesc;
 strncpy(printAmount,toCurrency(currentElem->transAmount),14);
 i=0;
 count = 12-strlen(printAmount);
 if(sign == -1){
  count = count-1;
 }
 while(count>=0){
  isEndingSpace = 1;
  amt[i] = ' ';
  i++;
  count--;
 }
 for(j=0;printAmount[j] != '\0'; j++,i++){
  amt[i] = printAmount[j];
 }
 if(isEndingSpace == 1){
  amt[13] = ' ';
 }
 amt[14] = '\0';
 strncpy(printAmount,amt,14);
 printAmount[14] = '\0';
 if(sign == -1){
  strncpy(printAmount, representNegatives(printAmount),14);
 }
 printAmount[14] = '\0';
 pOutput->printAmount = printAmount;
 *pBalance = (long long)sign*(long long)currentAmount + *pBalance;
 if(*pBalance < 0){
  balanceSign = -1;
 }
 strncpy(printBalance,toCurrency((*pBalance)*balanceSign),14);
 i=0;
 j=0;
 count = 12-strlen(printBalance);
 if(*pBalance <0 ){
  count = count-1;
 }
 isEndingSpace = 0;
 while(count>=0){
  bal[i] = ' ';
  i++;
  count--;
  isEndingSpace = 1;
 }
 j=0;
 while(printBalance[j] != '\0'){
  bal[i++] = printBalance[j++];
 }
 if(isEndingSpace == 1){
  bal[13] = ' ';
 }
 bal[14] = '\0';
 strncpy(printBalance, bal, 14);
 printBalance[14] = '\0';
 if(*pBalance < 0){
  strncpy(printBalance, representNegatives(printBalance),14);
 }
 printBalance[14] = '\0';
 pOutput->printBalance = printBalance;
 return 1;
}

canonical_original_code:
int formatEachField(struct My402SortElem *currentElem, struct My402Output *pOutput, long long *pBalance){
 int sign = 1;
 int i = 0;
 int j = 0;
 int whiteSpaces = 0;
 int count = 0;
 int balanceSign = 1;
 int isEndingSpace = 0;
 char *printDesc = (char *)malloc(25*sizeof(char));
 if(printDesc == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *printDate = (char *)malloc(16*sizeof(char));
 if(printDate == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *desc = malloc(sizeof(25));
 if(desc == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(desc,'\0',25);
 char *amt = malloc(sizeof(15));
 if(amt == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(amt,'\0',15);
 char *bal = malloc(sizeof(15));
 if(bal == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(bal,'\0',15);
 char *printAmount = (char *)malloc(15*sizeof(char));
 if(printAmount == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *printBalance = (char *)malloc(15*sizeof(char));
 if(printBalance == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 char *cTime = (char *)malloc(26*sizeof(char));
 if(cTime == ((void *)0)){
  perror("Unable to allocate memory");
  return 0;
 }
 memset(cTime, '\0', 26*sizeof(char));
 long long currentAmount = currentElem->transAmount;
 if('-' == currentElem->transType){
  sign = -1;
 }
 cTime = ctime(&currentElem->transTime);
 while(cTime[i] != '\n'){
  if(! (i >= 10 && i<=18) ){
   printDate[j] = cTime[i];
   j++;
  }
  i++;
 }
 printDate[15] = '\0';
 pOutput->printDate = printDate;
 strncpy(printDesc, currentElem->transDesc,24);
 i=24;
 while(printDesc[i] == '\0' && i>0){
  printDesc[i] = ' ';
  i--;
 }
 printDesc[24] = '\0';
 whiteSpaces = 0;
 i=0;
 while(printDesc[i] == ' '&& printDesc[i]!= '\0'){
  whiteSpaces++;
  i++;
 }
 strncpy(desc, printDesc+whiteSpaces, strlen(printDesc+whiteSpaces));
 i=strlen(printDesc)-whiteSpaces;
 while(i<=23){
  desc[i++] = ' ';
 }
 strncpy(printDesc, desc, 24);
 printDesc[24] = '\0';
 pOutput->printDesc = printDesc;
 strncpy(printAmount,toCurrency(currentElem->transAmount),14);
 i=0;
 count = 12-strlen(printAmount);
 if(sign == -1){
  count = count-1;
 }
 while(count>=0){
  isEndingSpace = 1;
  amt[i] = ' ';
  i++;
  count--;
 }
 for(j=0;printAmount[j] != '\0'; j++,i++){
  amt[i] = printAmount[j];
 }
 if(isEndingSpace == 1){
  amt[13] = ' ';
 }
 amt[14] = '\0';
 strncpy(printAmount,amt,14);
 printAmount[14] = '\0';
 if(sign == -1){
  strncpy(printAmount, representNegatives(printAmount),14);
 }
 printAmount[14] = '\0';
 pOutput->printAmount = printAmount;
 *pBalance = (long long)sign*(long long)currentAmount + *pBalance;
 if(*pBalance < 0){
  balanceSign = -1;
 }
 strncpy(printBalance,toCurrency((*pBalance)*balanceSign),14);
 i=0;
 j=0;
 count = 12-strlen(printBalance);
 if(*pBalance <0 ){
  count = count-1;
 }
 isEndingSpace = 0;
 while(count>=0){
  bal[i] = ' ';
  i++;
  count--;
  isEndingSpace = 1;
 }
 j=0;
 while(printBalance[j] != '\0'){
  bal[i++] = printBalance[j++];
 }
 if(isEndingSpace == 1){
  bal[13] = ' ';
 }
 bal[14] = '\0';
 strncpy(printBalance, bal, 14);
 printBalance[14] = '\0';
 if(*pBalance < 0){
  strncpy(printBalance, representNegatives(printBalance),14);
 }
 printBalance[14] = '\0';
 pOutput->printBalance = printBalance;
 return 1;
}

variable_types: struct My402SortElem { char transType; long transTime; long long transAmount; char *transDesc; } *

variable_types: struct My402Output { char *printDate; char *printDesc; char *printAmount; char *printBalance; } *

variable_types:
pBalance
long long *

variable_types: sign int

variable_types: whiteSpaces int

variable_types: balanceSign int

variable_types: isEndingSpace int

variable_types:
printDesc
char *

variable_types:
printDate
char *

variable_types:
desc
char *

variable_types:
amt
char *

variable_types:
bal
char *

variable_types:
printAmount
char *

variable_types:
printBalance
char *

variable_types:
cTime
char *

variable_types:
currentAmount
long long


printOutput

original_code:
int printOutput(My402List *pList){
 int line_number = 0;
 My402Output output;
 memset(&output, '\0', sizeof(My402Output));
 My402Output *pOutput = &output;
 long long *pBalance = (long long *)malloc(sizeof(long long));
 if(pBalance == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(pBalance, 0, sizeof(long long)) ;
 if(pBalance == ((void *)0)){
  fprintf(stderr, "\nUnable to allocate memory");
 }
 My402ListElem *current = ((void *)0);
 printf("+-----------------+--------------------------+----------------+----------------+\n");
 printf("|%7cDate%6c|%1cDescription%14c|%9cAmount%1c|%8cBalance%1c|\n",32,32,32,32,32,32,32,32);
 printf("+-----------------+--------------------------+----------------+----------------+\n");
 for(current=My402ListFirst(pList);
  current!=((void *)0);
  current=My402ListNext(pList, current)){
  if(formatEachField((My402SortElem *)current->obj, pOutput, pBalance) == 0){
   return 0;
  }
  line_number++;
  printf("|%1c%s%1c|%1c%s%1c|%1c%s%1c|%1c%s%1c|\n",32,pOutput->printDate,32,32,pOutput->printDesc,32,32,pOutput->printAmount,32,32,pOutput->printBalance,32);
 }
 printf("+-----------------+--------------------------+----------------+----------------+\n");
  if(pOutput->printDate != ((void *)0)){
                        free(pOutput->printDate);
                }
                if(pOutput->printDesc != ((void *)0)){
                        free(pOutput->printDesc);
                }
                if(pOutput->printAmount != ((void *)0)){
                        free(pOutput->printAmount);
                }
                if(pOutput->printBalance != ((void *)0)){
                        free(pOutput->printBalance);
                }
 return 1;
}

canonical_original_code:
int printOutput(struct tagMy402List *pList){
 int line_number = 0;
 struct My402Output output;
 memset(&output, '\0', sizeof(My402Output));
 struct My402Output *pOutput = &output;
 long long *pBalance = (long long *)malloc(sizeof(long long));
 if(pBalance == ((void *)0)){
  perror("\nUnable to allocate memory");
  return 0;
 }
 memset(pBalance, 0, sizeof(long long)) ;
 if(pBalance == ((void *)0)){
  fprintf(stderr, "\nUnable to allocate memory");
 }
 struct tagMy402ListElem *current = ((void *)0);
 printf("+-----------------+--------------------------+----------------+----------------+\n");
 printf("|%7cDate%6c|%1cDescription%14c|%9cAmount%1c|%8cBalance%1c|\n",32,32,32,32,32,32,32,32);
 printf("+-----------------+--------------------------+----------------+----------------+\n");
 for(current=My402ListFirst(pList);
  current!=((void *)0);
  current=My402ListNext(pList, current)){
  if(formatEachField((struct My402SortElem *)current->obj, pOutput, pBalance) == 0){
   return 0;
  }
  line_number++;
  printf("|%1c%s%1c|%1c%s%1c|%1c%s%1c|%1c%s%1c|\n",32,pOutput->printDate,32,32,pOutput->printDesc,32,32,pOutput->printAmount,32,32,pOutput->printBalance,32);
 }
 printf("+-----------------+--------------------------+----------------+----------------+\n");
  if(pOutput->printDate != ((void *)0)){
                        free(pOutput->printDate);
                }
                if(pOutput->printDesc != ((void *)0)){
                        free(pOutput->printDesc);
                }
                if(pOutput->printAmount != ((void *)0)){
                        free(pOutput->printAmount);
                }
                if(pOutput->printBalance != ((void *)0)){
                        free(pOutput->printBalance);
                }
 return 1;
}

variable_types: struct tagMy402List { int num_members; struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); void (*UnlinkAll)(struct tagMy402List *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); } *

variable_types: struct My402Output { char *printDate; char *printDesc; char *printAmount; char *printBalance; }

variable_types: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } *


repo: ncastro/File-System

decompiled_code:
void __fastcall sanity_check(int a1, __int64 a2)
{
if ( a1 < 0 )
{
printf("ERROR: blocknum (%d) is negative!\n", (unsigned int)a1);
abort();
}
if ( nblocks <= a1 )
{
printf("ERROR: blocknum (%d) is too big!\n", (unsigned int)a1);
abort();
}
if ( !a2 )
{
puts("ERROR: null data pointer!");
abort();
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2)
{
if ( a1 < 0 )
{
printf("ERROR: blocknum (%d) is negative!\n", (unsigned int)a1);
abort();
}
if ( nblocks <= a1 )
{
printf("ERROR: blocknum (%d) is too big!\n", (unsigned int)a1);
abort();
}
if ( !a2 )
{
puts("ERROR: null data pointer!");
abort();
}
}

original_code:
static void sanity_check( int blocknum, const void *data )
{
 if(blocknum<0) {
  printf("ERROR: blocknum (%d) is negative!\n",blocknum);
  abort();
 }
 if(blocknum>=nblocks) {
  printf("ERROR: blocknum (%d) is too big!\n",blocknum);
  abort();
 }
 if(!data) {
  printf("ERROR: null data pointer!\n");
  abort();
 }
}

canonical_original_code:
static void sanity_check(int blocknum, void *data)
{
 if(blocknum<0) {
  printf("ERROR: blocknum (%d) is negative!\n",blocknum);
  abort();
 }
 if(blocknum>=nblocks) {
  printf("ERROR: blocknum (%d) is too big!\n",blocknum);
  abort();
 }
 if(!data) {
  printf("ERROR: null data pointer!\n");
  abort();
 }
}

variable_types: blocknum int

variable_types:
data
void *


decompiled_code:
__int64 __fastcall disk_init(char *filename, int a2)
{
FILE *v2; // rax
int v3; // eax

v2 = fopen(filename, "r+");
diskfile = v2;
if ( !v2 )
{
v2 = fopen(filename, "w+");
diskfile = v2;
if ( !v2 )
return 0LL;
}
v3 = fileno(v2);
ftruncate(v3, a2 << 12);
nblocks = a2;
nreads = 0;
nwrites = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *filename, int a2)
{
FILE *v2; // rax
int v3; // eax

v2 = fopen(filename, "r+");
diskfile = v2;
if ( !v2 )
{
v2 = fopen(filename, "w+");
diskfile = v2;
if ( !v2 )
return 0LL;
}
v3 = fileno(v2);
ftruncate(v3, a2 << 12);
nblocks = a2;
nreads = 0;
nwrites = 0;
return 1LL;
}

original_code:
int disk_init( const char *filename, int n )
{
 diskfile = fopen(filename,"r+");
 if(!diskfile) diskfile = fopen(filename,"w+");
 if(!diskfile) return 0;
 ftruncate(fileno(diskfile),n*4096);
 nblocks = n;
 nreads = 0;
 nwrites = 0;
 return 1;
}

canonical_original_code:
int disk_init(char *filename, int n)
{
 diskfile = fopen(filename,"r+");
 if(!diskfile) diskfile = fopen(filename,"w+");
 if(!diskfile) return 0;
 ftruncate(fileno(diskfile),n*4096);
 nblocks = n;
 nreads = 0;
 nwrites = 0;
 return 1;
}

variable_types:
filename
char *

variable_types: n int


decompiled_code:
__int64 disk_size()
{
return (unsigned int)nblocks;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)nblocks;
}

original_code:
int disk_size()
{
 return nblocks;
}

canonical_original_code:
int disk_size()
{
 return nblocks;
}


decompiled_code:
size_t __fastcall disk_read(int a1, void *a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

sanity_check(a1, (__int64)a2);
fseek(diskfile, a1 << 12, 0);
result = fread(a2, 0x1000uLL, 1uLL, diskfile);
if ( result != 1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("ERROR: couldn't access simulated disk: %s\n", v4);
abort();
}
++nreads;
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(int a1, void *a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

func0(a1, (__int64)a2);
fseek(diskfile, a1 << 12, 0);
result = fread(a2, 0x1000uLL, 1uLL, diskfile);
if ( result != 1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("ERROR: couldn't access simulated disk: %s\n", v4);
abort();
}
++nreads;
return result;
}

original_code:
void disk_read( int blocknum, char *data )
{
 sanity_check(blocknum,data);
 fseek(diskfile,blocknum*4096,0);
 if(fread(data,4096,1,diskfile)==1) {
  nreads++;
 } else {
  printf("ERROR: couldn't access simulated disk: %s\n",strerror((*__errno_location ())));
  abort();
 }
}

canonical_original_code:
void disk_read(int blocknum, char *data)
{
 sanity_check(blocknum,data);
 fseek(diskfile,blocknum*4096,0);
 if(fread(data,4096,1,diskfile)==1) {
  nreads++;
 } else {
  printf("ERROR: couldn't access simulated disk: %s\n",strerror((*__errno_location ())));
  abort();
 }
}

variable_types:
data
char *


decompiled_code:
size_t __fastcall disk_write(int a1, const void *a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

sanity_check(a1, (__int64)a2);
fseek(diskfile, a1 << 12, 0);
result = fwrite(a2, 0x1000uLL, 1uLL, diskfile);
if ( result != 1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("ERROR: couldn't access simulated disk: %s\n", v4);
abort();
}
++nwrites;
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(int a1, const void *a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

func0(a1, (__int64)a2);
fseek(diskfile, a1 << 12, 0);
result = fwrite(a2, 0x1000uLL, 1uLL, diskfile);
if ( result != 1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("ERROR: couldn't access simulated disk: %s\n", v4);
abort();
}
++nwrites;
return result;
}

original_code:
void disk_write( int blocknum, const char *data )
{
 sanity_check(blocknum,data);
 fseek(diskfile,blocknum*4096,0);
 if(fwrite(data,4096,1,diskfile)==1) {
  nwrites++;
 } else {
  printf("ERROR: couldn't access simulated disk: %s\n",strerror((*__errno_location ())));
  abort();
 }
}

canonical_original_code:
void disk_write(int blocknum, char *data)
{
 sanity_check(blocknum,data);
 fseek(diskfile,blocknum*4096,0);
 if(fwrite(data,4096,1,diskfile)==1) {
  nwrites++;
 } else {
  printf("ERROR: couldn't access simulated disk: %s\n",strerror((*__errno_location ())));
  abort();
 }
}


decompiled_code:
int disk_close()
{
int result; // eax

if ( diskfile )
{
printf("%d disk block reads\n", (unsigned int)nreads);
printf("%d disk block writes\n", (unsigned int)nwrites);
result = fclose(diskfile);
diskfile = 0LL;
}
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

if ( diskfile )
{
printf("%d disk block reads\n", (unsigned int)nreads);
printf("%d disk block writes\n", (unsigned int)nwrites);
result = fclose(diskfile);
diskfile = 0LL;
}
return result;
}

original_code:
void disk_close()
{
 if(diskfile) {
  printf("%d disk block reads\n",nreads);
  printf("%d disk block writes\n",nwrites);
  fclose(diskfile);
  diskfile = 0;
 }
}


decompiled_code:
int deepx_mt_help()
{
return puts("deepx match options:\n[!] --xrule");
}

canonical_decompiled_code:
int func8()
{
return puts("deepx match options:\n[!] --xrule");
}

original_code:
static void deepx_mt_help(void) {
 printf("deepx match options:\n[!] --xrule\n");
}

canonical_original_code:
static void deepx_mt_help() {
 printf("deepx match options:\n[!] --xrule\n");
}


decompiled_code:
const char *__fastcall dbg_opname(int a1)
{
const char *result; // rax

result = "XT_DEEPX_NEWGRP";
if ( a1 != 1 )
{
result = "XT_DEEPX_SEARCH";
if ( a1 != 2 )
{
result = "XT_DEEPX_STRCMP";
if ( a1 != 3 )
{
result = "XT_DEEPX_READ";
if ( a1 != 4 )
{
result = "XT_DEEPX_SAVEPOS";
if ( a1 != 5 )
{
result = "XT_DEEPX_ARITH_END";
if ( a1 != 6 )
{
result = "XT_DEEPX_ARITH_BEGIN";
if ( a1 != 7 )
{
result = "XT_DEEPX_SKIP";
if ( a1 != 8 )
{
result = "XT_DEEPX_ADD";
if ( a1 != 43 )
{
result = "XT_DEEPX_SUB";
if ( a1 != 45 )
{
result = "XT_DEEPX_DIV";
if ( a1 != 47 )
{
result = "XT_DEEPX_MUL";
if ( a1 != 42 )
{
result = "XT_DEEPX_LSHIFT";
if ( a1 != 60 )
{
result = "XT_DEEPX_RSHIFT";
if ( a1 != 62 )
{
result = "XT_DEEPX_AND";
if ( a1 != 38 )
{
result = "XT_DEEPX_TEST_EQ";
if ( a1 != 39 )
{
result = "XT_DEEPX_TEST_MIN";
if ( a1 != 40 )
{
result = "<unknown>";
if ( a1 == 41 )
result = "XT_DEEPX_TEST_MAX";
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(int a1)
{
const char *result; // rax

result = "XT_DEEPX_NEWGRP";
if ( a1 != 1 )
{
result = "XT_DEEPX_SEARCH";
if ( a1 != 2 )
{
result = "XT_DEEPX_STRCMP";
if ( a1 != 3 )
{
result = "XT_DEEPX_READ";
if ( a1 != 4 )
{
result = "XT_DEEPX_SAVEPOS";
if ( a1 != 5 )
{
result = "XT_DEEPX_ARITH_END";
if ( a1 != 6 )
{
result = "XT_DEEPX_ARITH_BEGIN";
if ( a1 != 7 )
{
result = "XT_DEEPX_SKIP";
if ( a1 != 8 )
{
result = "XT_DEEPX_ADD";
if ( a1 != 43 )
{
result = "XT_DEEPX_SUB";
if ( a1 != 45 )
{
result = "XT_DEEPX_DIV";
if ( a1 != 47 )
{
result = "XT_DEEPX_MUL";
if ( a1 != 42 )
{
result = "XT_DEEPX_LSHIFT";
if ( a1 != 60 )
{
result = "XT_DEEPX_RSHIFT";
if ( a1 != 62 )
{
result = "XT_DEEPX_AND";
if ( a1 != 38 )
{
result = "XT_DEEPX_TEST_EQ";
if ( a1 != 39 )
{
result = "XT_DEEPX_TEST_MIN";
if ( a1 != 40 )
{
result = "<unknown>";
if ( a1 == 41 )
result = "XT_DEEPX_TEST_MAX";
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
const char * dbg_opname(int op){
 if(op == XT_DEEPX_NEWGRP) return "XT_DEEPX_NEWGRP"; if(op == XT_DEEPX_NEWGRP) return "XT_DEEPX_NEWGRP"; if(op == XT_DEEPX_SEARCH) return "XT_DEEPX_SEARCH";
 if(op == XT_DEEPX_STRCMP) return "XT_DEEPX_STRCMP"; if(op == XT_DEEPX_READ) return "XT_DEEPX_READ"; if(op == XT_DEEPX_SAVEPOS) return "XT_DEEPX_SAVEPOS";
 if(op == XT_DEEPX_ARITH_END) return "XT_DEEPX_ARITH_END"; if(op == XT_DEEPX_ARITH_BEGIN) return "XT_DEEPX_ARITH_BEGIN"; if(op == XT_DEEPX_SKIP) return "XT_DEEPX_SKIP";
 if(op == XT_DEEPX_ADD) return "XT_DEEPX_ADD"; if(op == XT_DEEPX_SUB) return "XT_DEEPX_SUB"; if(op == XT_DEEPX_DIV) return "XT_DEEPX_DIV";
 if(op == XT_DEEPX_MUL) return "XT_DEEPX_MUL"; if(op == XT_DEEPX_LSHIFT) return "XT_DEEPX_LSHIFT"; if(op == XT_DEEPX_RSHIFT) return "XT_DEEPX_RSHIFT";
 if(op == XT_DEEPX_AND) return "XT_DEEPX_AND"; if(op == XT_DEEPX_TEST_EQ) return "XT_DEEPX_TEST_EQ"; if(op == XT_DEEPX_TEST_MIN) return "XT_DEEPX_TEST_MIN";
 if(op == XT_DEEPX_TEST_MAX) return "XT_DEEPX_TEST_MAX";
 return "<unknown>";
}

canonical_original_code:
char *dbg_opname(int op){
 if(op == XT_DEEPX_NEWGRP) return "XT_DEEPX_NEWGRP"; if(op == XT_DEEPX_NEWGRP) return "XT_DEEPX_NEWGRP"; if(op == XT_DEEPX_SEARCH) return "XT_DEEPX_SEARCH";
 if(op == XT_DEEPX_STRCMP) return "XT_DEEPX_STRCMP"; if(op == XT_DEEPX_READ) return "XT_DEEPX_READ"; if(op == XT_DEEPX_SAVEPOS) return "XT_DEEPX_SAVEPOS";
 if(op == XT_DEEPX_ARITH_END) return "XT_DEEPX_ARITH_END"; if(op == XT_DEEPX_ARITH_BEGIN) return "XT_DEEPX_ARITH_BEGIN"; if(op == XT_DEEPX_SKIP) return "XT_DEEPX_SKIP";
 if(op == XT_DEEPX_ADD) return "XT_DEEPX_ADD"; if(op == XT_DEEPX_SUB) return "XT_DEEPX_SUB"; if(op == XT_DEEPX_DIV) return "XT_DEEPX_DIV";
 if(op == XT_DEEPX_MUL) return "XT_DEEPX_MUL"; if(op == XT_DEEPX_LSHIFT) return "XT_DEEPX_LSHIFT"; if(op == XT_DEEPX_RSHIFT) return "XT_DEEPX_RSHIFT";
 if(op == XT_DEEPX_AND) return "XT_DEEPX_AND"; if(op == XT_DEEPX_TEST_EQ) return "XT_DEEPX_TEST_EQ"; if(op == XT_DEEPX_TEST_MIN) return "XT_DEEPX_TEST_MIN";
 if(op == XT_DEEPX_TEST_MAX) return "XT_DEEPX_TEST_MAX";
 return "<unknown>";
}

variable_types: op int


decompiled_code:
__int64 __fastcall parse_num(__int64 a1, __int64 a2)
{
char v3; // [rsp+6h] [rbp-22h]
int v4; // [rsp+8h] [rbp-20h]

if ( (unsigned int)__isoc99_sscanf() == 1 )
{
*(_BYTE *)(a2 + 4) = 0;
*(_DWORD *)(a2 + 8) = v4;
}
else if ( (unsigned int)__isoc99_sscanf() == 1 )
{
*(_BYTE *)(a2 + 4) = 1;
*(_BYTE *)(a2 + 8) = v3 - 48;
}
(*(void (__fastcall **)(__int64, const char *))(xt_params + 40LL))(2LL, "DEEPX parameter error");
return parse_arith();
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
char v3; // [rsp+6h] [rbp-22h]
int v4; // [rsp+8h] [rbp-20h]

if ( (unsigned int)__isoc99_sscanf() == 1 )
{
*(_BYTE *)(a2 + 4) = 0;
*(_DWORD *)(a2 + 8) = v4;
}
else if ( (unsigned int)__isoc99_sscanf() == 1 )
{
*(_BYTE *)(a2 + 4) = 1;
*(_BYTE *)(a2 + 8) = v3 - 48;
}
(*(void (__fastcall **)(__int64, const char *))(xt_params + 40LL))(2LL, "DEEPX parameter error");
return func13();
}

original_code:
int parse_num(char *str, xt_deepx_test *t) {
 int64_t lval; char cval[2]; int n = 0;
 if (sscanf(str, "%li%n", &lval, &n)==1) {t->use_reg = 0; t->ival = (uint32_t) lval;}
 else if (sscanf(str, "%%%1[0-9]%n", cval, &n)==1) {t->use_reg = 1; t->reg = cval[0]-'0';}
 if (!(n)) (xt_params->exit_err)(PARAMETER_PROBLEM, "DEEPX parameter error"); return n;
}

canonical_original_code:
int parse_num(char *str, struct xt_deepx_test_t *t) {
 long lval; char cval[2]; int n = 0;
 if (sscanf(str, "%li%n", &lval, &n)==1) {t->use_reg = 0; t->ival = (unsigned int) lval;}
 else if (sscanf(str, "%%%1[0-9]%n", cval, &n)==1) {t->use_reg = 1; t->reg = cval[0]-'0';}
 if (!(n)) (xt_params->exit_err)(PARAMETER_PROBLEM, "DEEPX parameter error"); return n;
}

variable_types:
str
char *

variable_types: struct xt_deepx_test_t { unsigned char op; union { struct { unsigned char use_reg; union { unsigned int ival; unsigned char reg; }; }; struct { unsigned char strofst; }; struct { unsigned char big_endian; }; struct { unsigned char grp_invert; }; }; } *

variable_types: lval long

variable_types:
cval
char [2]


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
pthread_t *v5; // rdi
int v6; // eax
struct sockaddr v7; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v3 = socket(2, 1, 6);
if ( v3 < 0 )
die_with_error("socket() failed!");
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(4516);
if ( bind(v3, &addr, 0x10u) < 0 )
die_with_error("bind() failed!\n");
if ( listen(v3, 2) < 0 )
die_with_error("listen() failed!");
while ( 1 )
{
addr_len[0] = 16;
v4 = accept(v3, &v7, addr_len);
if ( v4 < 0 )
die_with_error("accept() failed!");
v5 = (pthread_t *)malloc(0x10uLL);
*((_DWORD *)v5 + 2) = v4;
v6 = curr_clients++;
if ( v6 <= 0 )
pthread_create(v5, 0LL, handle_client, v5);
else
printf("Client refused! Too many clients are connected!");
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
pthread_t *v5; // rdi
int v6; // eax
struct sockaddr v7; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v3 = socket(2, 1, 6);
if ( v3 < 0 )
die_with_error("socket() failed!");
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func0(0);
*(_WORD *)addr.sa_data = func1(4516);
if ( bind(v3, &addr, 0x10u) < 0 )
die_with_error("bind() failed!\n");
if ( listen(v3, 2) < 0 )
die_with_error("listen() failed!");
while ( 1 )
{
addr_len[0] = 16;
v4 = accept(v3, &v7, addr_len);
if ( v4 < 0 )
die_with_error("accept() failed!");
v5 = (pthread_t *)malloc(0x10uLL);
*((_DWORD *)v5 + 2) = v4;
v6 = curr_clients++;
if ( v6 <= 0 )
pthread_create(v5, 0LL, handle_client, v5);
else
printf("Client refused! Too many clients are connected!");
}
}

original_code:
int main(int argc, char *argv[])
{
    int srv_sock, clnt_sock = 0;
    unsigned int clnt_len;
    struct sockaddr_in srv_addr, clnt_addr;
    struct client_handler_data *next_clnt;
    if((srv_sock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
        die_with_error("socket() failed!");
    memset(&srv_addr, 0, sizeof(srv_addr));
    srv_addr.sin_family = 2;
    srv_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    srv_addr.sin_port = htons(4516);
    if((bind(srv_sock, (struct sockaddr *)(&srv_addr), sizeof(srv_addr)) < 0))
        die_with_error("bind() failed!\n");
    if((listen(srv_sock, 2) < 0))
        die_with_error("listen() failed!");
    for(;;)
    {
        clnt_len = sizeof(clnt_addr);
        if((clnt_sock = accept(srv_sock, (struct sockaddr *)(&clnt_addr), &clnt_len)) < 0)
        die_with_error("accept() failed!");
 next_clnt = (struct client_handler_data *)malloc(sizeof(struct client_handler_data));
 next_clnt->sock = clnt_sock;
        if(curr_clients++ < 1)
   {
            pthread_create(&(next_clnt->thread), ((void *)0), handle_client,
                            (void *)next_clnt);
   }
        else
            printf("Client refused!  Too many clients are connected!");
    }
    pthread_exit(((void *)0));
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int srv_sock; int clnt_sock = 0;
    unsigned int clnt_len;
    struct sockaddr_in srv_addr; struct sockaddr_in clnt_addr;
    struct client_handler_data *next_clnt;
    if((srv_sock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
        die_with_error("socket() failed!");
    memset(&srv_addr, 0, sizeof(srv_addr));
    srv_addr.sin_family = 2;
    srv_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    srv_addr.sin_port = htons(4516);
    if((bind(srv_sock, (struct sockaddr *)(&srv_addr), sizeof(srv_addr)) < 0))
        die_with_error("bind() failed!\n");
    if((listen(srv_sock, 2) < 0))
        die_with_error("listen() failed!");
    for(;;)
    {
        clnt_len = sizeof(clnt_addr);
        if((clnt_sock = accept(srv_sock, (struct sockaddr *)(&clnt_addr), &clnt_len)) < 0)
        die_with_error("accept() failed!");
 next_clnt = (struct client_handler_data *)malloc(sizeof(struct client_handler_data));
 next_clnt->sock = clnt_sock;
        if(curr_clients++ < 1)
   {
            pthread_create(&(next_clnt->thread), ((void *)0), handle_client,
                            (void *)next_clnt);
   }
        else
            printf("Client refused!  Too many clients are connected!");
    }
    pthread_exit(((void *)0));
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: struct client_handler_data { unsigned long thread; int sock; } *

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

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


decompiled_code:
ssize_t __fastcall return_error(__int64 a1, char a2, _WORD *a3, __int64 a4, __int64 a5, int a6)
{
int v7[68]; // [rsp+0h] [rbp-228h] BYREF
int v8[64]; // [rsp+110h] [rbp-118h] BYREF
int v9; // [rsp+210h] [rbp-18h] BYREF

BYTE2(v8[0]) = a2;
LOWORD(v8[0]) = *a3;
*a3 = LOWORD(v8[0]) + 1;
HIBYTE(v8[0]) = 0;
qmemcpy(v7, v8, 0x100uLL);
v7[64] = v9;
return send_packet(a1, (int)&v9, (int)a3, 0, a1, a6, v7[0]);
}

original_code:
void return_error(int pipes[], int error_code, uint16_t *cur_seq_num){
    struct packet p;
    p.opcode = error_code;
    p.seq_num = *cur_seq_num;
    (*cur_seq_num)++;
    p.length = 0;
    send_packet(pipes, p);
}

canonical_original_code:
void return_error(int pipes[], int error_code, unsigned short *cur_seq_num){
    struct packet p;
    p.opcode = error_code;
    p.seq_num = *cur_seq_num;
    (*cur_seq_num)++;
    p.length = 0;
    send_packet(pipes, p);
}

variable_types:
pipes
int []

variable_types: struct packet { unsigned short seq_num; unsigned char opcode; unsigned char length; char payload[256]; }


decompiled_code:
ssize_t __fastcall return_response(__int64 a1, const char *a2, __int16 *a3)
{
int v3; // edx
int v4; // er8
int v5; // er9
int v7[68]; // [rsp-110h] [rbp-238h] BYREF
__int16 v8[128]; // [rsp+0h] [rbp-128h] BYREF
int v9; // [rsp+100h] [rbp-28h] BYREF

LOBYTE(v8[1]) = 5;
v8[0] = *a3;
*a3 = v8[0] + 1;
strcpy((char *)&v8[2], a2);
HIBYTE(v8[1]) = strlen((const char *)&v8[2]);
qmemcpy(v7, v8, 0x100uLL);
v7[64] = v9;
return send_packet(a1, (int)&v9, v3, 0, v4, v5, v7[0]);
}

original_code:
void return_response(int pipes[], char *payload, uint16_t *cur_seq_num){
    struct packet p;
    p.opcode = 0x05;
    p.seq_num = *cur_seq_num;
    (*cur_seq_num)++;
    strcpy(p.payload, payload);
    p.length = strlen(p.payload);
    send_packet(pipes, p);
}

canonical_original_code:
void return_response(int pipes[], char *payload, unsigned short *cur_seq_num){
    struct packet p;
    p.opcode = 0x05;
    p.seq_num = *cur_seq_num;
    (*cur_seq_num)++;
    strcpy(p.payload, payload);
    p.length = strlen(p.payload);
    send_packet(pipes, p);
}

variable_types:
payload
char *

user_defined_types: struct packet { unsigned short seq_num; unsigned char opcode; unsigned char length; char payload[256]; }


decompiled_code:
ssize_t __fastcall send_packet(__int64 a1, int a2, int a3, int a4, int a5, int a6, int buf)
{
return write(*(_DWORD *)(a1 + 4), &buf, HIBYTE(buf) + 4LL);
}

canonical_decompiled_code:
ssize_t __fastcall func2(__int64 a1, int a2, int a3, int a4, int a5, int a6, int buf)
{
return write(*(_DWORD *)(a1 + 4), &buf, HIBYTE(buf) + 4LL);
}

original_code:
void send_packet(int pipes[], struct packet p){
    write((pipes[1]), &p, p.length + 4);
}


decompiled_code:
ssize_t __fastcall receive_packet(int *a1, void *a2)
{
return read(*a1, a2, 0x104uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int *a1, void *a2)
{
return read(*a1, a2, 0x104uLL);
}

original_code:
void receive_packet(int pipes[], struct packet *p){
    read((pipes[0]), p, sizeof(struct packet));
}

variable_types: struct packet { unsigned short seq_num; unsigned char opcode; unsigned char length; char payload[256]; } *