isReserved

decompiled_code:
_BOOL8 __fastcall isReserved(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 1;
}

original_code:
int isReserved(BlockPtr block){
 return block->kval == 1;
}

canonical_original_code:
int isReserved(struct block *block){
 return block->kval == 1;
}


isNextBlockNull

repo: thomascampbelladams/dash

decompiled_code:
_BOOL8 __fastcall isNextBlockNull(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
int isNextBlockNull(BlockPtr block){
 return block->next == ((void *)0);
}

canonical_original_code:
int isNextBlockNull(struct block *block){
 return block->next == ((void *)0);
}

variable_types: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; } *

return_type: int


isBlockIndexNull

decompiled_code:
_BOOL8 __fastcall isBlockIndexNull(int a1)
{
return blockAddress[a1] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
return blockAddress[a1] == 0;
}

original_code:
int isBlockIndexNull(int index){
 return blockAddress[index] == ((void *)0);
}

variable_types: index int


nextFreeBlock

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

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

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

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

original_code:
BlockPtr nextFreeBlock(BlockPtr block){
 if(isNextBlockNull(block)) return ((void *)0);
 return block->next;
}

canonical_original_code:
struct block *nextFreeBlock(struct block *block){
 if(isNextBlockNull(block)) return ((void *)0);
 return block->next;
}

variable_types:
block
struct block *

return_type: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; } *


isKvalEmpty

decompiled_code:
_BOOL8 __fastcall isKvalEmpty(int a1)
{
return blockAddress[a1] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(int a1)
{
return blockAddress[a1] == 0;
}

original_code:
int isKvalEmpty(int kval){
 return blockAddress[kval] == ((void *)0);
}

variable_types: kval int


searchAndRemoveBlockFromFreeList

decompiled_code:
__int64 __fastcall searchAndRemoveBlockFromFreeList(__int64 a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 4);
result = blockAddress[v1];
if ( result == a1 )
{
result = *(_QWORD *)(a1 + 16);
blockAddress[v1] = result;
}
else
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result != a1 );
*(_QWORD *)(v3 + 16) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 4);
result = blockAddress[v1];
if ( result == a1 )
{
result = *(_QWORD *)(a1 + 16);
blockAddress[v1] = result;
}
else
{
do
{
v3 = result;
result = *(_QWORD *)(result + 16);
}
while ( result != a1 );
*(_QWORD *)(v3 + 16) = 0LL;
}
return result;
}

original_code:
void searchAndRemoveBlockFromFreeList(BlockPtr block){
 if(block == blockAddress[block->kval]) blockAddress[block->kval] = block->next;
 else {
  BlockPtr searchBlock = blockAddress[block->kval];
  while(searchBlock->next != block) searchBlock = searchBlock->next;
  searchBlock->next = ((void *)0);
 }
}

canonical_original_code:
void searchAndRemoveBlockFromFreeList(struct block *block){
 if(block == blockAddress[block->kval]) blockAddress[block->kval] = block->next;
 else {
  struct block *searchBlock = blockAddress[block->kval];
  while(searchBlock->next != block) searchBlock = searchBlock->next;
  searchBlock->next = ((void *)0);
 }
}

return_type: void

user_defined_types: struct block { int tag; int kval; char *blockStartingAddress; struct block *next; struct block *prev; }


isBlockFree

decompiled_code:
_BOOL8 __fastcall isBlockFree(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_DWORD *a1)
{
return *a1 == 0;
}

original_code: int isBlockFree(BlockPtr block){ return block->tag == 0; }

canonical_original_code: int isBlockFree(struct block *block){ return block->tag == 0; }


isKvalLessThanMin

decompiled_code:
_BOOL8 __fastcall isKvalLessThanMin(int a1)
{
return a1 <= 4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int a1)
{
return a1 <= 4;
}

original_code: int isKvalLessThanMin(int kval){ return kval < 5; }


isKvalAtMax

decompiled_code:
_BOOL8 __fastcall isKvalAtMax(__int64 a1)
{
return *(_DWORD *)(a1 + 4) > 25;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1)
{
return *(_DWORD *)(a1 + 4) > 25;
}

original_code: int isKvalAtMax(BlockPtr block) { return block->kval >= 26; }

canonical_original_code: int isKvalAtMax(struct block *block) { return block->kval >= 26; }


isBlockAddressValid

decompiled_code:
_BOOL8 __fastcall isBlockAddressValid(unsigned __int64 a1)
{
return initialBlockAddress <= a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(unsigned __int64 a1)
{
return initialBlockAddress <= a1;
}

original_code: int isBlockAddressValid(size_t blockAddress) { return blockAddress >= initialBlockAddress; }

canonical_original_code: int isBlockAddressValid(unsigned long blockAddress) { return blockAddress >= initialBlockAddress; }

variable_types:
blockAddress
unsigned long


isNextBuddyBlockReadyToJoin

decompiled_code:
_BOOL8 __fastcall isNextBuddyBlockReadyToJoin(__int64 a1, _DWORD *a2, unsigned __int64 a3)
{
_BOOL4 v4; // edx
_BOOL8 result; // rax

v4 = isKvalAtMax(a1);
result = 0LL;
if ( !v4 )
{
result = isBlockAddressValid(a3);
if ( result )
result = isBlockFree(a2);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1, _DWORD *a2, unsigned __int64 a3)
{
_BOOL4 v4; // edx
_BOOL8 result; // rax

v4 = func14(a1);
result = 0LL;
if ( !v4 )
{
result = func15(a3);
if ( result )
result = func12(a2);
}
return result;
}

original_code:
int isNextBuddyBlockReadyToJoin(BlockPtr block, BlockPtr buddyBlock, size_t buddyAddress){
 return !isKvalAtMax(block) && isBlockAddressValid(buddyAddress) && isBlockFree(buddyBlock);
}

canonical_original_code:
int isNextBuddyBlockReadyToJoin(struct block *block, struct block *buddyBlock, unsigned long buddyAddress){
 return !isKvalAtMax(block) && isBlockAddressValid(buddyAddress) && isBlockFree(buddyBlock);
}

variable_types:
buddyBlock
struct block *

variable_types:
buddyAddress
unsigned long


setNodeInFreeList

decompiled_code:
__int64 __fastcall setNodeInFreeList(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = blockAddress[*(int *)(a1 + 4)];
do
{
v2 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v2 + 16) = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = blockAddress[*(int *)(a1 + 4)];
do
{
v2 = result;
result = *(_QWORD *)(result + 16);
}
while ( result );
*(_QWORD *)(v2 + 16) = a1;
return result;
}

original_code:
void setNodeInFreeList(BlockPtr block){
 BlockPtr nextBlock = blockAddress[block->kval];
 while(nextBlock->next != ((void *)0)) nextBlock = nextBlock->next;
 nextBlock->next = block;
}

canonical_original_code:
void setNodeInFreeList(struct block *block){
 struct block *nextBlock = blockAddress[block->kval];
 while(nextBlock->next != ((void *)0)) nextBlock = nextBlock->next;
 nextBlock->next = block;
}


joinBlock

decompiled_code:
__int64 __fastcall joinBlock(_DWORD *a1, unsigned __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
unsigned __int64 v4; // rax
_DWORD *v5; // rbp
_DWORD *v6; // rax
int v7; // ebp
__int64 v8; // rax

v2 = (__int64)a1;
result = isKvalAtMax((__int64)a1);
if ( !(_DWORD)result )
{
if ( isBlockFree(a1) )
{
v4 = buddy((__int64)a1);
v5 = a1;
if ( v4 < a2 )
v5 = (_DWORD *)v4;
searchAndRemoveBlockFromFreeList(v4);
v5[1] = a1[1] + 1;
v2 = (__int64)v5;
}
*(_DWORD *)v2 = 0;
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(v2 + 24) = 0LL;
v6 = (_DWORD *)buddy(v2);
if ( isNextBuddyBlockReadyToJoin(v2, v6, (unsigned __int64)v6) )
{
v8 = addToAddress(v2, 0);
result = joinBlock(v2, v8);
}
else
{
v7 = *(_DWORD *)(v2 + 4);
result = isKvalEmpty(v7);
if ( (_DWORD)result )
blockAddress[v7] = v2;
else
result = setNodeInFreeList(v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(_DWORD *a1, unsigned __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
unsigned __int64 v4; // rax
_DWORD *v5; // rbp
_DWORD *v6; // rax
int v7; // ebp
__int64 v8; // rax

v2 = (__int64)a1;
result = func14((__int64)a1);
if ( !(_DWORD)result )
{
if ( func12(a1) )
{
v4 = func1((__int64)a1);
v5 = a1;
if ( v4 < a2 )
v5 = (_DWORD *)v4;
func11(v4);
v5[1] = a1[1] + 1;
v2 = (__int64)v5;
}
*(_DWORD *)v2 = 0;
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(v2 + 24) = 0LL;
v6 = (_DWORD *)func1(v2);
if ( func16(v2, v6, (unsigned __int64)v6) )
{
v8 = func0(v2, 0);
result = func18(v2, v8);
}
else
{
v7 = *(_DWORD *)(v2 + 4);
result = func10(v7);
if ( (_DWORD)result )
blockAddress[v7] = v2;
else
result = func17(v2);
}
}
return result;
}

original_code:
void joinBlock(BlockPtr block, size_t blocksAddress){
 size_t buddyAddress = buddy(block);
 BlockPtr buddyBlock = (BlockPtr) buddyAddress;
 BlockPtr reallocBlock;
 if(isKvalAtMax(block)) return;
 if(isBlockFree(block)){
  reallocBlock = (buddyAddress < blocksAddress) ? buddyBlock : block;
  searchAndRemoveBlockFromFreeList(buddyBlock);
  reallocBlock->kval = block->kval+1;
 }
 else reallocBlock = block;
 reallocBlock->tag = 0;
 reallocBlock->next = ((void *)0);
 reallocBlock->prev = ((void *)0);
 buddyAddress = buddy(reallocBlock);
 buddyBlock = (BlockPtr) buddyAddress;
 if(isNextBuddyBlockReadyToJoin(reallocBlock, buddyBlock, buddyAddress)){
  size_t reallocBlocksAddress = addToAddress(reallocBlock, 0);
  joinBlock(reallocBlock, reallocBlocksAddress);
 }
 else {
  if(isKvalEmpty(reallocBlock->kval)) blockAddress[reallocBlock->kval] = reallocBlock;
  else setNodeInFreeList(reallocBlock);
 }
}

canonical_original_code:
void joinBlock(struct block *block, unsigned long blocksAddress){
 unsigned long buddyAddress = buddy(block);
 struct block *buddyBlock = (BlockPtr) buddyAddress;
 struct block *reallocBlock;
 if(isKvalAtMax(block)) return;
 if(isBlockFree(block)){
  reallocBlock = (buddyAddress < blocksAddress) ? buddyBlock : block;
  searchAndRemoveBlockFromFreeList(buddyBlock);
  reallocBlock->kval = block->kval+1;
 }
 else reallocBlock = block;
 reallocBlock->tag = 0;
 reallocBlock->next = ((void *)0);
 reallocBlock->prev = ((void *)0);
 buddyAddress = buddy(reallocBlock);
 buddyBlock = (struct block *) buddyAddress;
 if(isNextBuddyBlockReadyToJoin(reallocBlock, buddyBlock, buddyAddress)){
  unsigned long reallocBlocksAddress = addToAddress(reallocBlock, 0);
  joinBlock(reallocBlock, reallocBlocksAddress);
 }
 else {
  if(isKvalEmpty(reallocBlock->kval)) blockAddress[reallocBlock->kval] = reallocBlock;
  else setNodeInFreeList(reallocBlock);
 }
}

variable_types:
blocksAddress
unsigned long

variable_types:
reallocBlocksAddress
unsigned long


decompiled_code:
__int64 __fastcall buddy_free(__int64 a1)
{
_DWORD *v1; // rax

v1 = (_DWORD *)addToAddress(a1, -9);
return joinBlock(v1, (unsigned __int64)v1);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
_DWORD *v1; // rax

v1 = (_DWORD *)func0(a1, -9);
return func18(v1, (unsigned __int64)v1);
}

original_code:
void buddy_free(void *address){
 size_t blocksAddress = addToAddress((BlockPtr)address, -9);
 BlockPtr block = (BlockPtr) blocksAddress;
 joinBlock(block, blocksAddress);
}

canonical_original_code:
void buddy_free(void *address){
 unsigned long blocksAddress = addToAddress((BlockPtr)address, -9);
 struct block *block = (BlockPtr) blocksAddress;
 joinBlock(block, blocksAddress);
}

variable_types:
address
void *


printBlock

decompiled_code:
void __fastcall printBlock(unsigned int *a1)
{
if ( a1 )
{
printf(
"Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->",
a1,
a1[1],
*a1,
*((const void **)a1 + 1),
*((const void **)a1 + 2),
*((const void **)a1 + 3));
if ( !isNextBlockNull((__int64)a1) )
printBlock(*((_QWORD *)a1 + 2));
}
}

canonical_decompiled_code:
void __fastcall func20(unsigned int *a1)
{
if ( a1 )
{
printf(
"Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->",
a1,
a1[1],
*a1,
*((const void **)a1 + 1),
*((const void **)a1 + 2),
*((const void **)a1 + 3));
if ( !func7((__int64)a1) )
func20(*((_QWORD *)a1 + 2));
}
}

original_code:
void printBlock(BlockPtr block){
 if(block == ((void *)0)) return;
 printf("Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->", block, block->kval, block->tag, block->blockStartingAddress, block->next, block->prev);
 if(!isNextBlockNull(block)) printBlock(block->next);
}

canonical_original_code:
void printBlock(struct block *block){
 if(block == ((void *)0)) return;
 printf("Address: %p kval:%d tag:%d blockStartingAddress:%p next:%p prev:%p -->", block, block->kval, block->tag, block->blockStartingAddress, block->next, block->prev);
 if(!isNextBlockNull(block)) printBlock(block->next);
}


printAddress

decompiled_code:
void __fastcall printAddress(__int64 a1)
{
unsigned int *v1; // rax

if ( a1 )
{
v1 = (unsigned int *)addToAddress(a1, -9);
printBlock(v1);
}
}

canonical_decompiled_code:
void __fastcall func21(__int64 a1)
{
unsigned int *v1; // rax

if ( a1 )
{
v1 = (unsigned int *)func0(a1, -9);
func20(v1);
}
}

original_code:
void printAddress(BlockPtr block){
 if(block == ((void *)0)) return;
 size_t blockHeaderAddress = addToAddress(block, -9);
 BlockPtr blockToPrint = (BlockPtr) blockHeaderAddress;
 printBlock(blockToPrint);
}

canonical_original_code:
void printAddress(struct block *block){
 if(block == ((void *)0)) return;
 unsigned long blockHeaderAddress = addToAddress(block, -9);
 struct block *blockToPrint = (BlockPtr) blockHeaderAddress;
 printBlock(blockToPrint);
}

variable_types:
blockHeaderAddress
unsigned long


printMemory

decompiled_code:
void printMemory()
{
__int64 i; // rbx

for ( i = 0LL; i != 27; ++i )
{
if ( !isBlockIndexNull(i) )
{
printf("\n\tBlock at index:%d ", (unsigned int)i);
printBlock((unsigned int *)blockAddress[i]);
}
}
}

canonical_decompiled_code:
void func22()
{
__int64 i; // rbx

for ( i = 0LL; i != 27; ++i )
{
if ( !func8(i) )
{
printf("\n\tBlock at index:%d ", (unsigned int)i);
func20((unsigned int *)blockAddress[i]);
}
}
}

original_code:
void printMemory(){
 int i = 0;
 for(; i <= 26; i++)
  if(!isBlockIndexNull(i)) {
   printf("\n\tBlock at index:%d ", i);
   printBlock(blockAddress[i]);
  }
}

variable_types: i int


decompiled_code:
__int64 __fastcall upper_power_of_two(unsigned int a1)
{
int v1; // esi
__int64 v2; // rdx
int v3; // eax
int v4; // ecx

v1 = a1;
v2 = 4LL;
v3 = 0;
do
{
if ( (b[v2] & a1) != 0 )
{
v4 = S[v2];
a1 >>= v4;
v3 |= v4;
}
--v2;
}
while ( v2 != -1 );
return (unsigned int)(1 << v3 < v1) + v3;
}

original_code:
int upper_power_of_two(uint v)
{
 int o = v;
 int i;
 register uint r = 0;
 for (i = 4; i >= 0; i--)
 {
   if (v & b[i])
   {
  v >>= S[i];
  r |= S[i];
   }
 }
 if(o > (1<<r)) r++;
 return r;
}

canonical_original_code:
int upper_power_of_two(unsigned int v)
{
 int o = v;
 int i;
 register unsigned int r = 0;
 for (i = 4; i >= 0; i--)
 {
   if (v & b[i])
   {
  v >>= S[i];
  r |= S[i];
   }
 }
 if(o > (1<<r)) r++;
 return r;
}

variable_types:
v
unsigned int

variable_types: o int

variable_types:
r
unsigned int


printNode

decompiled_code:
int __fastcall printNode(_QWORD *a1)
{
const char *v1; // rax

v1 = (const char *)toString(*a1);
return printf(" %s -->", v1);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1)
{
const char *v1; // rax

v1 = (const char *)toString(*a1);
return printf(" %s -->", v1);
}

original_code:
void printNode(NodePtr node)
{
 char* output = toString(node->data);
 printf(" %s -->",output);
}

canonical_original_code:
void printNode(struct node *node)
{
 char *output = toString(node->data);
 printf(" %s -->",output);
}

variable_types: struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *

variable_types:
output
char *

user_defined_types: struct node { struct job *data; struct node *next; struct node *prev; }


isNodeNull

decompiled_code:
_BOOL8 __fastcall isNodeNull(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return a1 == 0;
}

original_code:
int isNodeNull(NodePtr n){
        return n == ((void *)0);
}

canonical_original_code:
int isNodeNull(struct node *n){
        return n == ((void *)0);
}

user_defined_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; }


freeNode

decompiled_code:
__int64 __fastcall freeNode(_QWORD *a1)
{
__int64 result; // rax

result = isNodeNull((__int64)a1);
if ( !(_DWORD)result )
{
freeJob(*a1);
result = buddy_free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 result; // rax

result = func1((__int64)a1);
if ( !(_DWORD)result )
{
freeJob(*a1);
result = buddy_free(a1);
}
return result;
}

original_code:
void freeNode (NodePtr node)
{
 if (isNodeNull(node)) return;
 freeJob(node->data);
 buddy_free(node);
}

canonical_original_code:
void freeNode(struct node *node)
{
 if (isNodeNull(node)) return;
 freeJob(node->data);
 buddy_free(node);
}


reverse

original_code:
static NodePtr reverse(NodePtr L)
{
 NodePtr list = ((void *)0);
 while (L != ((void *)0)) {
  NodePtr tmp = L;
  L = L->next;
  if (L != ((void *)0)) L->prev = tmp;
  tmp->next = list;
  tmp->prev = L;
  list = tmp;
 }
 return list;
}

canonical_original_code:
static struct node *reverse(struct node *L)
{
 struct node *list = ((void *)0);
 while (L != ((void *)0)) {
  struct node *tmp = L;
  L = L->next;
  if (L != ((void *)0)) L->prev = tmp;
  tmp->next = list;
  tmp->prev = L;
  list = tmp;
 }
 return list;
}

variable_types:
L
struct node *

return_type: struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *


print

decompiled_code:
void __fastcall print(_QWORD *a1)
{
_QWORD *i; // rbp
const char *v2; // rbx

for ( i = a1; i; i = (_QWORD *)i[1] )
{
v2 = (const char *)toString(*i);
printf("%s", v2);
buddy_free(v2);
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
_QWORD *i; // rbp
const char *v2; // rbx

for ( i = a1; i; i = (_QWORD *)i[1] )
{
v2 = (const char *)toString(*i);
printf("%s", v2);
buddy_free(v2);
}
}

original_code:
static void print(NodePtr node)
{
 char *output;
 while (node) {
  output = toString(node->data);
  printf("%s",output);
  buddy_free(output);
  node = node->next;
 }
}

canonical_original_code:
static void print(struct node *node)
{
 char *output;
 while (node) {
  output = toString(node->data);
  printf("%s",output);
  buddy_free(output);
  node = node->next;
 }
}


createList

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

result = buddy_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
return result;
}

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

result = buddy_malloc(24LL);
*(_DWORD *)result = 0;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
return result;
}

original_code:
ListPtr createList()
{
 ListPtr list;
 list = (ListPtr) buddy_malloc(sizeof(List));
 list->size = 0;
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

canonical_original_code:
struct list *createList()
{
 struct list *list;
 list = (struct list *) buddy_malloc(sizeof(List));
 list->size = 0;
 list->head = ((void *)0);
 list->tail = ((void *)0);
 return list;
}

variable_types: struct list { int size; struct node { struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *data; struct node *next; struct node *prev; } *head; struct node *tail; } *

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


freeList

decompiled_code:
__int64 __fastcall freeList(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( *(_DWORD *)a1 )
{
v2 = *(_QWORD *)(a1 + 8);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
freeNode(v3);
}
result = buddy_free(a1);
}
else
{
result = buddy_free(a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( *(_DWORD *)a1 )
{
v2 = *(_QWORD *)(a1 + 8);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
freeNode(v3);
}
result = buddy_free(a1);
}
else
{
result = buddy_free(a1);
}
}
return result;
}

original_code:
void freeList(ListPtr L)
{
 if(L==((void *)0)) return;
 if(L->size == 0) buddy_free(L);
 else
 {
  NodePtr currentNode = L->head;
  while(currentNode != ((void *)0)){
   NodePtr temp = currentNode;
   currentNode = currentNode->next;
   freeNode(temp);
  }
  buddy_free(L);
 }
}

canonical_original_code:
void freeList(struct list *L)
{
 if(L==((void *)0)) return;
 if(L->size == 0) buddy_free(L);
 else
 {
  struct node *currentNode = L->head;
  while(currentNode != ((void *)0)){
   struct node *temp = currentNode;
   currentNode = currentNode->next;
   freeNode(temp);
  }
  buddy_free(L);
 }
}


getSize

decompiled_code:
__int64 __fastcall getSize(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
return *a1;
}

original_code:
int getSize(ListPtr L)
{
 return L->size;
}

canonical_original_code:
int getSize(struct list *L)
{
 return L->size;
}


isEmpty

decompiled_code:
_BOOL8 __fastcall isEmpty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
Boolean isEmpty(ListPtr L)
{
 if (L->size == 0)
  return 1;
 else
  return 0;
}

canonical_original_code:
int isEmpty(struct list *L)
{
 if (L->size == 0)
  return 1;
 else
  return 0;
}


addAtFront

original_code:
void addAtFront(ListPtr list, NodePtr node)
{
 if (list == ((void *)0)) return;
 if (node == ((void *)0)) return;
 list->size++;
 node->next = list->head;
 node->prev = ((void *)0);
 if (list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->head->prev = node;
  list->head = node;
 }
}

canonical_original_code:
void addAtFront(struct list *list, struct node *node)
{
 if (list == ((void *)0)) return;
 if (node == ((void *)0)) return;
 list->size++;
 node->next = list->head;
 node->prev = ((void *)0);
 if (list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->head->prev = node;
  list->head = node;
 }
}

variable_types:
node
struct node *


addAtRear

original_code:
void addAtRear(ListPtr list, NodePtr node)
{
 if(list == ((void *)0) || node == ((void *)0)) return;
 list->size++;
 node->next = ((void *)0);
 node->prev = list->tail;
 if(list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->tail->next = node;
  list->tail = node;
 }
}

canonical_original_code:
void addAtRear(struct list *list, struct node *node)
{
 if(list == ((void *)0) || node == ((void *)0)) return;
 list->size++;
 node->next = ((void *)0);
 node->prev = list->tail;
 if(list->head == ((void *)0))
 {
  list->head = node;
  list->tail = node;
 } else {
  list->tail->next = node;
  list->tail = node;
 }
}


removeFront

decompiled_code:
__int64 __fastcall removeFront(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
--*(_DWORD *)a1;
result = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(result + 8);
*(_QWORD *)(a1 + 8) = v2;
if ( v2 )
{
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
}
else
{
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
--*(_DWORD *)a1;
result = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(result + 8);
*(_QWORD *)(a1 + 8) = v2;
if ( v2 )
{
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
}
else
{
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

original_code:
NodePtr removeFront(ListPtr list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 NodePtr prevHeadNode = list->head;
 list->head = list->head->next;
 if(list->head != ((void *)0))
 {
  list->head->prev = ((void *)0);
  prevHeadNode->next = ((void *)0);
 } else {
  list->tail = ((void *)0);
 }
 return prevHeadNode;
}

canonical_original_code:
struct node *removeFront(struct list *list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 struct node *prevHeadNode = list->head;
 list->head = list->head->next;
 if(list->head != ((void *)0))
 {
  list->head->prev = ((void *)0);
  prevHeadNode->next = ((void *)0);
 } else {
  list->tail = ((void *)0);
 }
 return prevHeadNode;
}

variable_types: struct list { int size; struct node *head; struct node *tail; } *


removeRear

decompiled_code:
__int64 __fastcall removeRear(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
--*(_DWORD *)a1;
result = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(result + 16);
*(_QWORD *)(a1 + 16) = v2;
if ( v2 )
{
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
--*(_DWORD *)a1;
result = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(result + 16);
*(_QWORD *)(a1 + 16) = v2;
if ( v2 )
{
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)(result + 16) = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
}
return result;
}

original_code:
NodePtr removeRear(ListPtr list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 NodePtr prevTailNode = list->tail;
 list->tail = list->tail->prev;
 if(list->tail != ((void *)0))
 {
  list->tail->next = ((void *)0);
  prevTailNode->prev = ((void *)0);
 } else {
  list->head = ((void *)0);
 }
 return prevTailNode;
}

canonical_original_code:
struct node *removeRear(struct list *list)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 list->size--;
 struct node *prevTailNode = list->tail;
 list->tail = list->tail->prev;
 if(list->tail != ((void *)0))
 {
  list->tail->next = ((void *)0);
  prevTailNode->prev = ((void *)0);
 } else {
  list->head = ((void *)0);
 }
 return prevTailNode;
}


removeNode

original_code:
NodePtr removeNode(ListPtr list, NodePtr node)
{
 if(list == ((void *)0) || list->size == 0 || node == ((void *)0)) return ((void *)0);
 NodePtr currentNode = list->head;
 while (currentNode != node){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 if(currentNode != ((void *)0))
 {
  if(currentNode->next != ((void *)0))
   currentNode->next->prev = currentNode->prev;
  if(currentNode->prev != ((void *)0))
   currentNode->prev->next = currentNode->next;
  if(list->head == currentNode)
   list->head = currentNode->next;
  if(list->tail == currentNode)
   list->tail = currentNode->prev;
  currentNode->next = currentNode->prev = ((void *)0);
  list->size--;
 }
 return currentNode;
}

canonical_original_code:
struct node *removeNode(struct list *list, struct node *node)
{
 if(list == ((void *)0) || list->size == 0 || node == ((void *)0)) return ((void *)0);
 struct node *currentNode = list->head;
 while (currentNode != node){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 if(currentNode != ((void *)0))
 {
  if(currentNode->next != ((void *)0))
   currentNode->next->prev = currentNode->prev;
  if(currentNode->prev != ((void *)0))
   currentNode->prev->next = currentNode->next;
  if(list->head == currentNode)
   list->head = currentNode->next;
  if(list->tail == currentNode)
   list->tail = currentNode->prev;
  currentNode->next = currentNode->prev = ((void *)0);
  list->size--;
 }
 return currentNode;
}


search

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

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
do
{
if ( **(_DWORD **)result == a2 )
break;
result = *(_QWORD *)(result + 8);
}
while ( result );
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
do
{
if ( **(_DWORD **)result == a2 )
break;
result = *(_QWORD *)(result + 8);
}
while ( result );
return result;
}

original_code:
NodePtr search(ListPtr list, int key)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 NodePtr currentNode = list->head;
 while(currentNode->data->jobid != key){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 return currentNode;
}

canonical_original_code:
struct node *search(struct list *list, int key)
{
 if(list == ((void *)0) || list->size == 0) return ((void *)0);
 struct node *currentNode = list->head;
 while(currentNode->data->jobid != key){
  if(currentNode->next != ((void *)0))
   currentNode = currentNode->next;
  else{
   currentNode = ((void *)0);
   break;
  }
 }
 return currentNode;
}

variable_types: key int


reverseList

original_code:
void reverseList(ListPtr L)
{
 if (L == ((void *)0)) return;
 L->tail = L->head;
 L->head = reverse (L->head);
}

canonical_original_code:
void reverseList(struct list *L)
{
 if (L == ((void *)0)) return;
 L->tail = L->head;
 L->head = reverse (L->head);
}


printList

decompiled_code:
void __fastcall printList(__int64 a1)
{
if ( a1 )
print(*(_QWORD **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
if ( a1 )
func1(*(_QWORD **)(a1 + 8));
}

original_code:
void printList(ListPtr L)
{
 if (L) print(L->head);
}

canonical_original_code:
void printList(struct list *L)
{
 if (L) print(L->head);
}


decompiled_code:
int __fastcall err_doit(int a1, const char *a2, void *a3)
{
int v4; // er13
char *v6; // rbx
size_t v7; // rax
char s[2]; // [rsp+0h] [rbp-1028h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v6 = strerror(v4);
v7 = strlen(s);
sprintf(&s[v7], ": %s", v6);
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2, void *a3)
{
int v4; // er13
char *v6; // rbx
size_t v7; // rax
char s[2]; // [rsp+0h] [rbp-1028h] BYREF

v4 = *_errno_location();
vsprintf(s, a2, a3);
if ( a1 )
{
v6 = strerror(v4);
v7 = strlen(s);
sprintf(&s[v7], ": %s", v6);
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(0LL);
}

original_code:
static void
err_doit(int errnoflag, const char *fmt, va_list ap)
{
 int errno_save;
 char buf[4096];
 errno_save = (*__errno_location ());
 vsprintf(buf, fmt, ap);
 if (errnoflag)
  sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
 strcat(buf, "\n");
 fflush(stdout);
 fputs(buf, stderr);
 fflush(((void *)0));
 return;
}

canonical_original_code:
static void err_doit(int errnoflag, char *fmt, __builtin_va_list ap)
{
 int errno_save;
 char buf[4096];
 errno_save = (*__errno_location ());
 vsprintf(buf, fmt, ap);
 if (errnoflag)
  sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
 strcat(buf, "\n");
 fflush(stdout);
 fputs(buf, stderr);
 fflush(((void *)0));
 return;
}

variable_types: errnoflag int

variable_types:
fmt
char *

variable_types:
buf
char [4096]


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

va_start(va, a1);
return err_doit(1, a1, va);
}

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

va_start(va, a1);
return func0(1, a1, va);
}

original_code:
void
err_ret(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 return;
}

canonical_original_code:
void err_ret(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 return;
}


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

va_start(va, a1);
err_doit(1, a1, va);
exit(1);
}

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

va_start(va, a1);
func0(1, a1, va);
exit(1);
}

original_code:
void
err_sys(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void err_sys(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


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

va_start(va, a1);
err_doit(1, a1, va);
abort();
}

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

va_start(va, a1);
func0(1, a1, va);
abort();
}

original_code:
void
err_dump(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 abort();
 exit(1);
}

canonical_original_code:
void err_dump(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, fmt, ap);
 __builtin_va_end(ap);
 abort();
 exit(1);
}


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

va_start(va, a1);
return err_doit(0, a1, va);
}

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

va_start(va, a1);
return func0(0, a1, va);
}

original_code:
void
err_msg(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 return;
}

canonical_original_code:
void err_msg(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 return;
}


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

va_start(va, a1);
err_doit(0, a1, va);
exit(1);
}

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

va_start(va, a1);
func0(0, a1, va);
exit(1);
}

original_code:
void
err_quit(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void err_quit(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


jumpBack

decompiled_code:
void __noreturn jumpBack()
{
siglongjmp(env, 333333);
}

canonical_decompiled_code:
void __noreturn func0()
{
siglongjmp(env, 333333);
}

original_code: void jumpBack(){ siglongjmp(env,333333); }


initialize

decompiled_code:
__int64 initialize()
{
jobList = createList();
using_history();
bindKeys();
return initSignals(jumpBack);
}

canonical_decompiled_code:
__int64 func1()
{
jobList = createList();
using_history();
bindKeys();
return initSignals(jumpBack);
}

original_code:
void initialize()
{
 jobList = createList();
 using_history();
 bindKeys();
 initSignals(jumpBack);
}


createAndSetNode

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

v5 = createJob(a2, a3, (unsigned int)*a1);
if ( a4 == 1 )
*(_DWORD *)(v5 + 24) = 1;
++*a1;
v6 = createNode(v5);
setNode(v6);
return v6;
}

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

v5 = createJob(a2, a3, (unsigned int)*a1);
if ( a4 == 1 )
*(_DWORD *)(v5 + 24) = 1;
++*a1;
v6 = createNode(v5);
setNode(v6);
return v6;
}

original_code:
NodePtr createAndSetNode(int *jobNumber, int backgroundJob, char* bufCopy, int isBackground){
     JobPtr job = createJob((int)backgroundJob, bufCopy, *jobNumber);
  if(isBackground == 1) job->background = 1;
  (*jobNumber)++;
  NodePtr node = createNode(job);
  setNode(node);
  return node;
}

canonical_original_code:
struct node *createAndSetNode(int *jobNumber, int backgroundJob, char *bufCopy, int isBackground){
     struct job *job = createJob((int)backgroundJob, bufCopy, *jobNumber);
  if(isBackground == 1) job->background = 1;
  (*jobNumber)++;
  struct node *node = createNode(job);
  setNode(node);
  return node;
}

variable_types:
jobNumber
int *

variable_types: backgroundJob int

variable_types:
bufCopy
char *

variable_types: isBackground int

variable_types: struct job { int jobid; int jobNu; char *command; int status; int running; int background; } *


recordCommand

decompiled_code:
__int64 __fastcall recordCommand(unsigned int **a1, __int64 a2)
{
printf("[%i] %i %s\n", a2, **a1, *((const char **)*a1 + 1));
return addAtFront(jobList, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int **a1, __int64 a2)
{
printf("[%i] %i %s\n", a2, **a1, *((const char **)*a1 + 1));
return addAtFront(jobList, a1);
}

original_code:
void recordCommand(NodePtr n, int jobNumber, int isBackground)
{
 printf("[%i] %i %s\n", jobNumber, n->data->jobid, n->data->command);
 addAtFront(jobList, n);
}

canonical_original_code:
void recordCommand(struct node *n, int jobNumber, int isBackground)
{
 printf("[%i] %i %s\n", jobNumber, n->data->jobid, n->data->command);
 addAtFront(jobList, n);
}

variable_types: jobNumber int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
const char *v5; // rax
char *v6; // rbx
size_t v7; // rax
char *v8; // rbp
unsigned int v9; // eax
__pid_t v10; // ebx
unsigned int v11; // eax
unsigned int **v12; // rax
__int64 v13; // rsi
__int64 v14; // r12
__int64 v15; // [rsp+0h] [rbp-4038h]
int i; // [rsp+8h] [rbp-4030h]
int v17; // [rsp+Ch] [rbp-402Ch]
char v18[16388]; // [rsp+10h] [rbp-4028h] BYREF
unsigned int v19; // [rsp+4014h] [rbp-24h] BYREF
unsigned int v20; // [rsp+4018h] [rbp-20h] BYREF
int stat_loc[7]; // [rsp+401Ch] [rbp-1Ch] BYREF

if ( (unsigned int)isArgumentForShowingVersion(argv) )
showVersionAndExit();
getpid();
stat_loc[0] = 0;
v3 = getPrompt();
v20 = 1;
initialize();
putchar(10);
setPrompt(v3);
v4 = v3;
for ( i = 0; ; i = 1 )
{
v15 = v4;
do
{
while ( 1 )
{
v5 = (const char *)readline(v15);
v6 = (char *)v5;
if ( !v5 )
{
putchar(10);
exit(0);
}
if ( *v5 )
break;
printFinishedJobs(jobList);
free(v6);
}
v7 = strlen(v5);
v8 = (char *)buddy_malloc(v7 + 1);
strcpy(v8, v6);
add_history(v8);
free(v6);
if ( (unsigned int)isCommandNotEmpty(v8) )
v17 = isBackgroundCommand(v8);
getArgument(v18, v8, &v19);
if ( (unsigned int)isExitCommand(v8) )
{
buddy_free(v8);
freeList(jobList);
freeArguments(v19, v18, 0LL);
exit(0);
}
if ( (unsigned int)isCdCommand(v8, v18) )
{
changeDir(v18);
freeArguments(v19, v18, v8);
}
else if ( (unsigned int)isJobsCommand(v8) )
{
printList(jobList);
freeArguments(v19, v18, v8);
}
else if ( (unsigned int)isFgCommand(v8, v18) )
{
fg(v18, jobList, v19, v8);
}
else if ( (unsigned int)isBgCommand(v8, v18) )
{
bgS(v18, jobList, v19, v8);
}
else if ( (unsigned int)isCommandNotEmpty(v8) )
{
if ( v17 == 1 )
{
v11 = fork();
if ( v11 )
{
v12 = (unsigned int **)createAndSetNode(&v20, v11, (__int64)v8, 1);
recordCommand(v12, v20);
freeArguments(v19, v18, v8);
}
else
{
ignoreSignals(v8, 0LL);
runCommand(v18, v8);
}
}
else
{
v9 = fork();
v10 = v9;
if ( v9 )
{
v13 = v9;
v14 = createAndSetNode(&v20, v9, (__int64)v8, v17);
ignoreSignals(&v20, v13);
if ( waitpid(v10, stat_loc, 2) < 0 )
err_sys("waitpid error");
freeArguments(v19, v18, v8);
restoreSignalsAndDetermineStatus((unsigned int)stat_loc[0], jobList, v14);
}
else
{
runCommand(v18, v8);
}
}
}
else
{
freeArguments(v19, v18, v8);
}
}
while ( i );
_sigsetjmp(env, 1);
v4 = v15;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
const char *v5; // rax
char *v6; // rbx
size_t v7; // rax
char *v8; // rbp
unsigned int v9; // eax
__pid_t v10; // ebx
unsigned int v11; // eax
unsigned int **v12; // rax
__int64 v13; // rsi
__int64 v14; // r12
__int64 v15; // [rsp+0h] [rbp-4038h]
int i; // [rsp+8h] [rbp-4030h]
int v17; // [rsp+Ch] [rbp-402Ch]
char v18[16388]; // [rsp+10h] [rbp-4028h] BYREF
unsigned int v19; // [rsp+4014h] [rbp-24h] BYREF
unsigned int v20; // [rsp+4018h] [rbp-20h] BYREF
int stat_loc[7]; // [rsp+401Ch] [rbp-1Ch] BYREF

if ( (unsigned int)isArgumentForShowingVersion(argv) )
showVersionAndExit();
getpid();
stat_loc[0] = 0;
v3 = getPrompt();
v20 = 1;
func1();
putchar(10);
setPrompt(v3);
v4 = v3;
for ( i = 0; ; i = 1 )
{
v15 = v4;
do
{
while ( 1 )
{
v5 = (const char *)readline(v15);
v6 = (char *)v5;
if ( !v5 )
{
putchar(10);
exit(0);
}
if ( *v5 )
break;
printFinishedJobs(jobList);
free(v6);
}
v7 = strlen(v5);
v8 = (char *)buddy_malloc(v7 + 1);
strcpy(v8, v6);
add_history(v8);
free(v6);
if ( (unsigned int)isCommandNotEmpty(v8) )
v17 = isBackgroundCommand(v8);
getArgument(v18, v8, &v19);
if ( (unsigned int)isExitCommand(v8) )
{
buddy_free(v8);
freeList(jobList);
freeArguments(v19, v18, 0LL);
exit(0);
}
if ( (unsigned int)isCdCommand(v8, v18) )
{
changeDir(v18);
freeArguments(v19, v18, v8);
}
else if ( (unsigned int)isJobsCommand(v8) )
{
printList(jobList);
freeArguments(v19, v18, v8);
}
else if ( (unsigned int)isFgCommand(v8, v18) )
{
fg(v18, jobList, v19, v8);
}
else if ( (unsigned int)isBgCommand(v8, v18) )
{
bgS(v18, jobList, v19, v8);
}
else if ( (unsigned int)isCommandNotEmpty(v8) )
{
if ( v17 == 1 )
{
v11 = fork();
if ( v11 )
{
v12 = (unsigned int **)func2(&v20, v11, (__int64)v8, 1);
func3(v12, v20);
freeArguments(v19, v18, v8);
}
else
{
ignoreSignals(v8, 0LL);
runCommand(v18, v8);
}
}
else
{
v9 = fork();
v10 = v9;
if ( v9 )
{
v13 = v9;
v14 = func2(&v20, v9, (__int64)v8, v17);
ignoreSignals(&v20, v13);
if ( waitpid(v10, stat_loc, 2) < 0 )
err_sys("waitpid error");
freeArguments(v19, v18, v8);
restoreSignalsAndDetermineStatus((unsigned int)stat_loc[0], jobList, v14);
}
else
{
runCommand(v18, v8);
}
}
}
else
{
freeArguments(v19, v18, v8);
}
}
while ( i );
_sigsetjmp(env, 1);
v4 = v15;
}
}

original_code:
int main(int argc, char **argv)
{
 if(isArgumentForShowingVersion(argv)) showVersionAndExit();
 char *buf;
 char *bufCopy;
 pid_t pid = getpid();
 pid_t backgroundJob;
 int status = 0;
 char *prompt = getPrompt();
 int bg;
 int jobNumber = 1;
 int counts;
 int jumpSet = 0;
 char *arguments[2048];
 initialize();
 printf("\n");
 setPrompt(prompt);
 while ((buf = readline(prompt))) {
  if(strlen(buf) != 0) {
   bufCopy = buddy_malloc((strlen(buf)+1)*sizeof(char));
   strcpy(bufCopy, buf);
   add_history(bufCopy);
  }
  else
  {
    printFinishedJobs(jobList);
    free(buf);
    continue;
  }
  free(buf);
  if(isCommandNotEmpty(bufCopy)) bg = isBackgroundCommand(bufCopy);
  getArgument(arguments, bufCopy, &counts);
  if(isExitCommand(bufCopy)){
   buddy_free(bufCopy);
   freeList(jobList);
   if(arguments != ((void *)0)){
    freeArguments(counts, arguments, ((void *)0));
   }
   exit(0);
  }
  if(isCdCommand(bufCopy, arguments)){
   changeDir(arguments);
      freeArguments(counts, arguments, bufCopy);
  }
  else if(isJobsCommand(bufCopy)) {
   printList(jobList);
   freeArguments(counts, arguments, bufCopy);
  }
  else if(isFgCommand(bufCopy, arguments)){
   fg(arguments, jobList, counts, bufCopy);
  }
  else if(isBgCommand(bufCopy, arguments)){
   bgS(arguments, jobList, counts, bufCopy);
  }
  else if (isCommandNotEmpty(bufCopy))
  {
   if(bg == 1)
   {
    backgroundJob = fork();
    if(backgroundJob == 0) {
     ignoreSignals();
     runCommand(arguments, bufCopy);
    }
    else{
     NodePtr n = createAndSetNode(&jobNumber, backgroundJob, bufCopy, bg);
     recordCommand(n, jobNumber, bg);
     freeArguments(counts, arguments, bufCopy);
    }
   }
   else
   {
    pid = fork();
    if(pid == 0){
     runCommand(arguments, bufCopy);
    }
    else {
     NodePtr n = createAndSetNode(&jobNumber, pid, bufCopy, bg);
     ignoreSignals();
     if((waitpid(pid,&status,2))<0) err_sys("waitpid error");
     freeArguments(counts, arguments, bufCopy);
     restoreSignalsAndDetermineStatus(status, jobList, n);
    }
   }
  }
  else
  {
   freeArguments(counts, arguments, bufCopy);
  }
  if(jumpSet == 0){
   __sigsetjmp (env, 1);
   jumpSet = 1;
  }
  continue;
 }
 if(buf == ((void *)0)) printf("\n");
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 if(isArgumentForShowingVersion(argv)) showVersionAndExit();
 char *buf;
 char *bufCopy;
 int pid = getpid();
 int backgroundJob;
 int status = 0;
 char *prompt = getPrompt();
 int bg;
 int jobNumber = 1;
 int counts;
 int jumpSet = 0;
 char *arguments[2048];
 initialize();
 printf("\n");
 setPrompt(prompt);
 while ((buf = readline(prompt))) {
  if(strlen(buf) != 0) {
   bufCopy = buddy_malloc((strlen(buf)+1)*sizeof(char));
   strcpy(bufCopy, buf);
   add_history(bufCopy);
  }
  else
  {
    printFinishedJobs(jobList);
    free(buf);
    continue;
  }
  free(buf);
  if(isCommandNotEmpty(bufCopy)) bg = isBackgroundCommand(bufCopy);
  getArgument(arguments, bufCopy, &counts);
  if(isExitCommand(bufCopy)){
   buddy_free(bufCopy);
   freeList(jobList);
   if(arguments != ((void *)0)){
    freeArguments(counts, arguments, ((void *)0));
   }
   exit(0);
  }
  if(isCdCommand(bufCopy, arguments)){
   changeDir(arguments);
      freeArguments(counts, arguments, bufCopy);
  }
  else if(isJobsCommand(bufCopy)) {
   printList(jobList);
   freeArguments(counts, arguments, bufCopy);
  }
  else if(isFgCommand(bufCopy, arguments)){
   fg(arguments, jobList, counts, bufCopy);
  }
  else if(isBgCommand(bufCopy, arguments)){
   bgS(arguments, jobList, counts, bufCopy);
  }
  else if (isCommandNotEmpty(bufCopy))
  {
   if(bg == 1)
   {
    backgroundJob = fork();
    if(backgroundJob == 0) {
     ignoreSignals();
     runCommand(arguments, bufCopy);
    }
    else{
     struct node *n = createAndSetNode(&jobNumber, backgroundJob, bufCopy, bg);
     recordCommand(n, jobNumber, bg);
     freeArguments(counts, arguments, bufCopy);
    }
   }
   else
   {
    pid = fork();
    if(pid == 0){
     runCommand(arguments, bufCopy);
    }
    else {
     struct node *n = createAndSetNode(&jobNumber, pid, bufCopy, bg);
     ignoreSignals();
     if((waitpid(pid,&status,2))<0) err_sys("waitpid error");
     freeArguments(counts, arguments, bufCopy);
     restoreSignalsAndDetermineStatus(status, jobList, n);
    }
   }
  }
  else
  {
   freeArguments(counts, arguments, bufCopy);
  }
  if(jumpSet == 0){
   __sigsetjmp (env, 1);
   jumpSet = 1;
  }
  continue;
 }
 if(buf == ((void *)0)) printf("\n");
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char *

variable_types: pid int

variable_types: status int

variable_types:
prompt
char *

variable_types: bg int

variable_types: counts int

variable_types: jumpSet int

variable_types:
arguments
char *[2048]


bindUp

decompiled_code:
__int64 bindUp()
{
const char **v0; // rax

v0 = (const char **)previous_history();
printf(*v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
const char **v0; // rax

v0 = (const char **)previous_history();
printf(*v0);
return 0LL;
}

original_code:
int bindUp(int count, int key)
{
 HIST_ENTRY * prev = previous_history();
 printf(prev->line);
 return 0;
}

canonical_original_code:
int bindUp(int count, int key)
{
 struct _hist_entry *prev = previous_history();
 printf(prev->line);
 return 0;
}

variable_types: count int

variable_types: key int

variable_types: struct _hist_entry { char *line; char *timestamp; void *data; } *


bindDown

decompiled_code:
__int64 bindDown()
{
const char **v0; // rax

v0 = (const char **)next_history();
printf(*v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
const char **v0; // rax

v0 = (const char **)next_history();
printf(*v0);
return 0LL;
}

original_code:
int bindDown(int count, int key)
{
 HIST_ENTRY * next = next_history();
 printf(next->line);
 return 0;
}

canonical_original_code:
int bindDown(int count, int key)
{
 struct _hist_entry *next = next_history();
 printf(next->line);
 return 0;
}

user_defined_types: struct _hist_entry { char *line; char *timestamp; void *data; }


bindKeys

decompiled_code:
__int64 bindKeys()
{
rl_generic_bind(0LL, &unk_7D, bindUp, &vi_movement_keymap);
return rl_generic_bind(0LL, &unk_80, bindDown, &vi_movement_keymap);
}

canonical_decompiled_code:
__int64 func2()
{
rl_generic_bind(0LL, &unk_7D, bindUp, &vi_movement_keymap);
return rl_generic_bind(0LL, &unk_80, bindDown, &vi_movement_keymap);
}

original_code:
void bindKeys()
{
 rl_generic_bind(0, "\033k", (char*) bindUp, vi_movement_keymap);
 rl_generic_bind(0, "\033j", (char*) bindDown, vi_movement_keymap);
}

canonical_original_code:
void bindKeys()
{
 rl_generic_bind(0, "\033k", (char *) bindUp, vi_movement_keymap);
 rl_generic_bind(0, "\033j", (char *) bindDown, vi_movement_keymap);
}


reverseNumber

repo: thomasfrei/Project-Euler

decompiled_code:
__int64 __fastcall reverseNumber(int a1)
{
unsigned int v1; // edx
int v2; // ecx

v1 = 0;
do
{
v1 = a1 % 10 + 10 * v1;
v2 = a1;
a1 /= 10;
}
while ( v2 > 9 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // edx
int v2; // ecx

v1 = 0;
do
{
v1 = a1 % 10 + 10 * v1;
v2 = a1;
a1 /= 10;
}
while ( v2 > 9 );
return v1;
}

original_code:
int reverseNumber(int number){
    int reverse = 0 , remain = 0;
    do{
        remain = (number % 10);
        reverse = reverse * 10 + remain;
        number = number /10;
    } while(number > 0);
    return reverse;
}

canonical_original_code:
int reverseNumber(int number){
    int reverse = 0; int remain = 0;
    do{
        remain = (number % 10);
        reverse = reverse * 10 + remain;
        number = number /10;
    } while(number > 0);
    return reverse;
}

variable_types: number int

variable_types: reverse int

variable_types: remain int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
int v5; // ebx
int v6; // ebp

v3 = -999;
v4 = 0;
do
{
v5 = -999 * v3;
v6 = 900;
do
{
if ( (unsigned int)reverseNumber(v5) == v5 && v4 < v5 )
v4 = v5;
v5 += v3;
--v6;
}
while ( v6 );
++v3;
}
while ( v3 != -99 );
return printf("Result = %d\n", (unsigned int)v4);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
int v5; // ebx
int v6; // ebp

v3 = -999;
v4 = 0;
do
{
v5 = -999 * v3;
v6 = 900;
do
{
if ( (unsigned int)func7(v5) == v5 && v4 < v5 )
v4 = v5;
v5 += v3;
--v6;
}
while ( v6 );
++v3;
}
while ( v3 != -99 );
return printf("Result = %d\n", (unsigned int)v4);
}

original_code:
void main(void){
    int a = 999;
    int b = 999;
    int temp = 0;
    int number = 0;
    for (a = 999; a > 99; --a){
        for (b= 999; b > 99; --b){
            temp = a * b;
            if (temp == reverseNumber(temp)){
                if(temp > number){
                    number = temp;
                }
            }
        }
    }
    printf("Result = %d\n",number );
}

canonical_original_code:
void main(){
    int a = 999;
    int b = 999;
    int temp = 0;
    int number = 0;
    for (a = 999; a > 99; --a){
        for (b= 999; b > 99; --b){
            temp = a * b;
            if (temp == reverseNumber(temp)){
                if(temp > number){
                    number = temp;
                }
            }
        }
    }
    printf("Result = %d\n",number );
}

variable_types: a int

variable_types: b int

variable_types: temp int


decompiled_code:
__int64 __fastcall convert_string(char *a1, size_t a2, char *a3, size_t a4, const char *a5, const char *a6)
{
iconv_t v7; // rax
void *v8; // rbx
int v9; // edx
__int64 result; // rax
char *v11; // [rsp+0h] [rbp-38h] BYREF
char *inbuf; // [rsp+8h] [rbp-30h] BYREF
size_t outbytesleft; // [rsp+10h] [rbp-28h] BYREF
size_t inbytesleft[4]; // [rsp+18h] [rbp-20h] BYREF

inbytesleft[0] = a2;
outbytesleft = a4;
inbuf = a1;
v11 = a3;
v7 = iconv_open(a6, a5);
if ( v7 == (iconv_t)-1LL )
return -2LL;
v8 = v7;
v9 = iconv(v7, &inbuf, inbytesleft, &v11, &outbytesleft);
result = -3LL;
if ( v9 >= 0 )
{
iconv_close(v8);
*v11 = 0;
result = a4 - outbytesleft;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, size_t a2, char *a3, size_t a4, const char *a5, const char *a6)
{
iconv_t v7; // rax
void *v8; // rbx
int v9; // edx
__int64 result; // rax
char *v11; // [rsp+0h] [rbp-38h] BYREF
char *inbuf; // [rsp+8h] [rbp-30h] BYREF
size_t outbytesleft; // [rsp+10h] [rbp-28h] BYREF
size_t inbytesleft[4]; // [rsp+18h] [rbp-20h] BYREF

inbytesleft[0] = a2;
outbytesleft = a4;
inbuf = a1;
v11 = a3;
v7 = iconv_open(a6, a5);
if ( v7 == (iconv_t)-1LL )
return -2LL;
v8 = v7;
v9 = iconv(v7, &inbuf, inbytesleft, &v11, &outbytesleft);
result = -3LL;
if ( v9 >= 0 )
{
iconv_close(v8);
*v11 = 0;
result = a4 - outbytesleft;
}
return result;
}

original_code:
size_t convert_string(char *in, size_t in_length, char *out, size_t out_length, char *from, char *to)
{
 int res;
 size_t inbytesleft = in_length;
 size_t outbytesleft = out_length;
 char *in_ptr = &in[0];
 char *out_ptr = &out[0];
 iconv_t cd;
 if (out_length-in_length<0) {
  return -1;
 }
 if ((cd = iconv_open(to, from)) == (iconv_t)(-1)) {
  return -2;
 }
 res = iconv(cd, &in_ptr, &inbytesleft, &out_ptr, &outbytesleft);
 if (res < 0) {
  return -3;
 }
 iconv_close(cd);
 out_ptr[0]='\0';
 return (out_length-outbytesleft);
}

canonical_original_code:
unsigned long convert_string(char *in, unsigned long in_length, char *out, unsigned long out_length, char *from, char *to)
{
 int res;
 unsigned long inbytesleft = in_length;
 unsigned long outbytesleft = out_length;
 char *in_ptr = &in[0];
 char *out_ptr = &out[0];
 void *cd;
 if (out_length-in_length<0) {
  return -1;
 }
 if ((cd = iconv_open(to, from)) == (iconv_t)(-1)) {
  return -2;
 }
 res = iconv(cd, &in_ptr, &inbytesleft, &out_ptr, &outbytesleft);
 if (res < 0) {
  return -3;
 }
 iconv_close(cd);
 out_ptr[0]='\0';
 return (out_length-outbytesleft);
}

variable_types:
in
char *

variable_types:
out
char *

variable_types:
from
char *

variable_types:
to
char *

variable_types: res int

variable_types:
inbytesleft
unsigned long

variable_types:
outbytesleft
unsigned long

variable_types:
cd
void *

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall hexstr_to_ucs2char(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v6; // rbx
char s[3]; // [rsp+9h] [rbp-2Fh] BYREF
int v8; // [rsp+Ch] [rbp-2Ch] BYREF

v8 = 0;
strcpy(s, " ");
result = -1LL;
if ( 2 * a4 >= a2 )
{
if ( a2 <= 1 )
{
v6 = 0LL;
LABEL_6:
result = v6 & 0xFFFFFFFFFFFFFFFELL;
}
else
{
v6 = 0LL;
while ( 1 )
{
s[0] = *(_BYTE *)(a1 + 2 * v6);
s[1] = *(_BYTE *)(a1 + 2 * v6 + 1);
if ( sscanf(s, "%x", &v8) != 1 )
break;
*(_BYTE *)(a3 + v6++) = v8;
if ( v6 >= a2 >> 1 )
goto LABEL_6;
}
result = -1LL;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v6; // rbx
char s[3]; // [rsp+9h] [rbp-2Fh] BYREF
int v8; // [rsp+Ch] [rbp-2Ch] BYREF

v8 = 0;
strcpy(s, " ");
result = -1LL;
if ( 2 * a4 >= a2 )
{
if ( a2 <= 1 )
{
v6 = 0LL;
LABEL_6:
result = v6 & 0xFFFFFFFFFFFFFFFELL;
}
else
{
v6 = 0LL;
while ( 1 )
{
s[0] = *(_BYTE *)(a1 + 2 * v6);
s[1] = *(_BYTE *)(a1 + 2 * v6 + 1);
if ( sscanf(s, "%x", &v8) != 1 )
break;
*(_BYTE *)(a3 + v6++) = v8;
if ( v6 >= a2 >> 1 )
goto LABEL_6;
}
result = -1LL;
}
}
return result;
}

original_code:
size_t hexstr_to_ucs2char(char *in, size_t in_length, char *out, size_t out_length)
{
 size_t i = 0;
 size_t x = 0;
 int hexval = 0;
 char buf[] = "  ";
 if ((out_length*2)<in_length) return -1;
 for (i=0;i<in_length/2;i++) {
  buf[0] = in[(i*2)];
  buf[1] = in[(i*2)+1];
  if (sscanf(buf, "%x", &hexval) != 1) {
   return -1;
  }
  out[x] = hexval;
  x++;
 }
 x = (x - (x%2));
 return x;
}

canonical_original_code:
unsigned long hexstr_to_ucs2char(char *in, unsigned long in_length, char *out, unsigned long out_length)
{
 unsigned long i = 0;
 unsigned long x = 0;
 int hexval = 0;
 char buf[] = "  ";
 if ((out_length*2)<in_length) return -1;
 for (i=0;i<in_length/2;i++) {
  buf[0] = in[(i*2)];
  buf[1] = in[(i*2)+1];
  if (sscanf(buf, "%x", &hexval) != 1) {
   return -1;
  }
  out[x] = hexval;
  x++;
 }
 x = (x - (x%2));
 return x;
}

variable_types:
i
unsigned long

variable_types:
x
unsigned long

variable_types: hexval int

variable_types:
buf
char []


decompiled_code:
__int64 __fastcall ucs2char_to_hexstr(char *a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
char *v6; // rbp
_BYTE *v7; // rbx
char s[59]; // [rsp+Dh] [rbp-3Bh] BYREF

strcpy(s, " ");
result = -1LL;
if ( 4 * a4 >= a2 )
{
if ( a2 )
{
v6 = a1;
v7 = (_BYTE *)(a3 + 1);
do
{
snprintf(s, 3uLL, "%X", (unsigned int)*v6);
if ( !s[1] )
{
s[1] = s[0];
s[0] = 48;
}
*(v7 - 1) = s[0];
*v7 = s[1];
++v6;
v7 += 2;
}
while ( v6 != &a1[a2] );
result = 2 * a2;
}
else
{
result = 0LL;
}
*(_BYTE *)(a3 + result) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
char *v6; // rbp
_BYTE *v7; // rbx
char s[59]; // [rsp+Dh] [rbp-3Bh] BYREF

strcpy(s, " ");
result = -1LL;
if ( 4 * a4 >= a2 )
{
if ( a2 )
{
v6 = a1;
v7 = (_BYTE *)(a3 + 1);
do
{
snprintf(s, 3uLL, "%X", (unsigned int)*v6);
if ( !s[1] )
{
s[1] = s[0];
s[0] = 48;
}
*(v7 - 1) = s[0];
*v7 = s[1];
++v6;
v7 += 2;
}
while ( v6 != &a1[a2] );
result = 2 * a2;
}
else
{
result = 0LL;
}
*(_BYTE *)(a3 + result) = 0;
}
return result;
}

original_code:
size_t ucs2char_to_hexstr(char *in, size_t in_length, char *out, size_t out_length)
{
 size_t i = 0;
 size_t x = 0;
 char buf[] = "  ";
 if ((out_length*4)<in_length) return -1;
 for (i=0;i<in_length;i++) {
  snprintf(buf,sizeof(buf),"%X",in[i]);
  if (buf[1] == '\0') {
   buf[1] = buf[0];
   buf[0] = '0';
  }
  out[x] = buf[0];
  out[x+1] = buf[1];
  x=x+2;
 }
 out[x] = '\0';
 return x;
}

canonical_original_code:
unsigned long ucs2char_to_hexstr(char *in, unsigned long in_length, char *out, unsigned long out_length)
{
 unsigned long i = 0;
 unsigned long x = 0;
 char buf[] = "  ";
 if ((out_length*4)<in_length) return -1;
 for (i=0;i<in_length;i++) {
  snprintf(buf,sizeof(buf),"%X",in[i]);
  if (buf[1] == '\0') {
   buf[1] = buf[0];
   buf[0] = '0';
  }
  out[x] = buf[0];
  out[x+1] = buf[1];
  x=x+2;
 }
 out[x] = '\0';
 return x;
}


decompiled_code:
__int64 __fastcall hexstr_ucs2_to_utf8(__int64 a1, unsigned __int64 a2, char *a3, size_t a4)
{
void *v5; // rsp
__int64 result; // rax
unsigned __int64 v8; // rax
char v9[32]; // [rsp+0h] [rbp-20h] BYREF

v5 = alloca(a4);
result = -1LL;
if ( 2 * a4 >= a2 )
{
v8 = hexstr_to_ucs2char(a1, a2, (__int64)v9, a4);
result = convert_string(v9, v8, a3, a4, "UCS-2BE", "UTF-8");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2, char *a3, size_t a4)
{
void *v5; // rsp
__int64 result; // rax
unsigned __int64 v8; // rax
char v9[32]; // [rsp+0h] [rbp-20h] BYREF

v5 = alloca(a4);
result = -1LL;
if ( 2 * a4 >= a2 )
{
v8 = func1(a1, a2, (__int64)v9, a4);
result = func0(v9, v8, a3, a4, "UCS-2BE", "UTF-8");
}
return result;
}

original_code:
size_t hexstr_ucs2_to_utf8(char *in, size_t in_length, char *out, size_t out_length)
{
 char buf[out_length];
 size_t res;
 if ((out_length*2)<in_length) return -1;
 if ((res = hexstr_to_ucs2char(in, in_length, buf, out_length)) < 0) return res;
 res = convert_string(buf, res, out, out_length, "UCS-2BE", "UTF-8");
 return res;
}

canonical_original_code:
unsigned long hexstr_ucs2_to_utf8(char *in, unsigned long in_length, char *out, unsigned long out_length)
{
 char buf[-1];
 unsigned long res;
 if ((out_length*2)<in_length) return -1;
 if ((res = hexstr_to_ucs2char(in, in_length, buf, out_length)) < 0) return res;
 res = convert_string(buf, res, out, out_length, "UCS-2BE", "UTF-8");
 return res;
}

variable_types:
buf
char [-1]

variable_types:
res
unsigned long


decompiled_code:
__int64 __fastcall utf8_to_hexstr_ucs2(char *a1, size_t a2, __int64 a3, size_t a4)
{
void *v4; // rsp
__int64 result; // rax
__int64 v8; // rax
char v9[32]; // [rsp+0h] [rbp-20h] BYREF

v4 = alloca(a4);
result = -1LL;
if ( a4 >= a2 )
{
v8 = convert_string(a1, a2, v9, a4, "UTF-8", "UCS-2BE");
result = ucs2char_to_hexstr(v9, v8, a3, a4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, size_t a2, __int64 a3, size_t a4)
{
void *v4; // rsp
__int64 result; // rax
__int64 v8; // rax
char v9[32]; // [rsp+0h] [rbp-20h] BYREF

v4 = alloca(a4);
result = -1LL;
if ( a4 >= a2 )
{
v8 = func0(a1, a2, v9, a4, "UTF-8", "UCS-2BE");
result = func2(v9, v8, a3, a4);
}
return result;
}

original_code:
size_t utf8_to_hexstr_ucs2(char *in, size_t in_length, char *out, size_t out_length)
{
 char buf[out_length];
 size_t res;
 if (out_length<in_length) return -1;
 if ((res = convert_string(in, in_length, buf, out_length, "UTF-8", "UCS-2BE")) < 0) return res;
 res = ucs2char_to_hexstr(buf, res, out, out_length);
 return res;
}

canonical_original_code:
unsigned long utf8_to_hexstr_ucs2(char *in, unsigned long in_length, char *out, unsigned long out_length)
{
 char buf[-1];
 unsigned long res;
 if (out_length<in_length) return -1;
 if ((res = convert_string(in, in_length, buf, out_length, "UTF-8", "UCS-2BE")) < 0) return res;
 res = ucs2char_to_hexstr(buf, res, out, out_length);
 return res;
}


repo: thomasloven/dito

original_code:
CHS_t max_CHS_from_size(size_t size)
{
  CHS_t ret;
  ret.C = 1023;
  ret.H = 254;
  ret.S = 63;
  size_t real_size = ret.C*ret.H*ret.S;
  while(real_size > (size / 512))
  {
    ret.H -= 2;
    real_size = ret.C*ret.H*ret.S;
  }
  ret.H += 2;
  real_size = ret.C*ret.H*ret.S;
  while(real_size > (size / 512))
  {
    ret.C--;
    real_size = ret.C*ret.H*ret.S;
  }
  ret.C++;
  real_size = ret.C*ret.H*ret.S;
  while(real_size > (size / 512))
  {
    ret.S--;
    real_size = ret.C*ret.H*ret.S;
  }
  ret.S++;
  real_size = ret.C*ret.H*ret.S;
  if(real_size < (size/512 + ret.S + 1))
    ret.C++;
  return ret;
}

canonical_original_code:
struct CHS_t max_CHS_from_size(unsigned long size)
{
  struct CHS_t ret;
  ret.C = 1023;
  ret.H = 254;
  ret.S = 63;
  unsigned long real_size = ret.C*ret.H*ret.S;
  while(real_size > (size / 512))
  {
    ret.H -= 2;
    real_size = ret.C*ret.H*ret.S;
  }
  ret.H += 2;
  real_size = ret.C*ret.H*ret.S;
  while(real_size > (size / 512))
  {
    ret.C--;
    real_size = ret.C*ret.H*ret.S;
  }
  ret.C++;
  real_size = ret.C*ret.H*ret.S;
  while(real_size > (size / 512))
  {
    ret.S--;
    real_size = ret.C*ret.H*ret.S;
  }
  ret.S++;
  real_size = ret.C*ret.H*ret.S;
  if(real_size < (size/512 + ret.S + 1))
    ret.C++;
  return ret;
}

variable_types:
size
unsigned long

variable_types: struct CHS_t { unsigned int C; unsigned int H; unsigned int S; }


strcmp

decompiled_code:
__int64 __fastcall strcmp(char *a1, __int64 a2)
{
char v2; // al
int v3; // ecx
__int64 v4; // rdx
__int64 result; // rax

v2 = *a1;
if ( *a1 )
{
v3 = 0;
v4 = 0LL;
while ( *(_BYTE *)(a2 + v4) == v2 )
{
v4 = (unsigned int)++v3;
v2 = a1[v3];
if ( !v2 )
goto LABEL_5;
}
result = (unsigned int)(v3 + 1);
}
else
{
v3 = 0;
v4 = 0LL;
LABEL_5:
result = 0LL;
if ( *(_BYTE *)(a2 + v4) )
result = (unsigned int)(v3 + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
char v2; // al
int v3; // ecx
__int64 v4; // rdx
__int64 result; // rax

v2 = *a1;
if ( *a1 )
{
v3 = 0;
v4 = 0LL;
while ( *(_BYTE *)(a2 + v4) == v2 )
{
v4 = (unsigned int)++v3;
v2 = a1[v3];
if ( !v2 )
goto LABEL_5;
}
result = (unsigned int)(v3 + 1);
}
else
{
v3 = 0;
v4 = 0LL;
LABEL_5:
result = 0LL;
if ( *(_BYTE *)(a2 + v4) )
result = (unsigned int)(v3 + 1);
}
return result;
}

original_code:
uint32_t strcmp(char *str1, char *str2)
{
 uint32_t ret = 0;
 while(str1[ret] != '\0')
 {
  if(str1[ret] != str2[ret])
   return ret+1;
  ret++;
 }
 if(str2[ret] != '\0')
  return ret+1;
 return 0;
}

canonical_original_code:
unsigned int strcmp(char *str1, char *str2)
{
 unsigned int ret = 0;
 while(str1[ret] != '\0')
 {
  if(str1[ret] != str2[ret])
   return ret+1;
  ret++;
 }
 if(str2[ret] != '\0')
  return ret+1;
 return 0;
}

variable_types:
ret
unsigned int

return_type: unsigned int


strlen

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
__int64 result; // rax

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
result = (unsigned int)(result + 1);
while ( a1[(unsigned int)result] );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
__int64 result; // rax

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
result = (unsigned int)(result + 1);
while ( a1[(unsigned int)result] );
return result;
}

original_code:
uint32_t strlen(char *str)
{
 uint32_t i;
 for(i=0; str[i]; i++);
 return i;
}

canonical_original_code:
unsigned int strlen(char *str)
{
 unsigned int i;
 for(i=0; str[i]; i++);
 return i;
}

variable_types:
str
char *

variable_types:
i
unsigned int


original_code:
int num2str(uint32_t num, uint32_t base, char *buf)
{
 if(num == 0)
 {
  buf[0] = '0';
  buf[1] = '\0';
  return;
 }
 uint32_t i = 0, j=0;
  char c;
 while(num > 0)
 {
  if(num%base < 10)
   buf[i++] = (char)((uint32_t)'0' + num%base);
  else
   buf[i++] = (char)((uint32_t)'A' + num%base-10);
  num /= base;
 }
 for(i--, j=0; j<i; j++,i--)
 {
  char tmp = buf[i];
  buf[i] = buf[j];
  buf[j] = tmp;
 }
 buf[i+j+1] = '\0';
 return i+j+1;
}

canonical_original_code:
int num2str(unsigned int num, unsigned int base, char *buf)
{
 if(num == 0)
 {
  buf[0] = '0';
  buf[1] = '\0';
  return;
 }
 unsigned int i = 0; unsigned int j = 0;
  char c;
 while(num > 0)
 {
  if(num%base < 10)
   buf[i++] = (char)((unsigned int)'0' + num%base);
  else
   buf[i++] = (char)((unsigned int)'A' + num%base-10);
  num /= base;
 }
 for(i--, j=0; j<i; j++,i--)
 {
  char tmp = buf[i];
  buf[i] = buf[j];
  buf[j] = tmp;
 }
 buf[i+j+1] = '\0';
 return i+j+1;
}

variable_types:
num
unsigned int

variable_types:
base
unsigned int

variable_types:
buf
char *

variable_types:
j
unsigned int

variable_types: c char

variable_types: tmp char


repo: thomdixon/libmeh

decompiled_code:
__int64 __fastcall meh_reset_hmac(_QWORD *a1, const void *a2, size_t a3)
{
unsigned __int64 v4; // rax
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_reset_hmac", 4294967291LL);
memset((void *)a1[3], 0, a1[6]);
if ( a1[6] >= a3 )
memcpy((void *)a1[3], a2, a3);
else
meh_hash(*((unsigned int *)a1 + 14), a2, a3, a1[3]);
memcpy((void *)a1[2], (const void *)a1[3], a1[6]);
if ( a1[6] )
{
v4 = 0LL;
do
{
*(_BYTE *)(a1[3] + v4) ^= 0x36u;
*(_BYTE *)(a1[2] + v4++) ^= 0x5Cu;
}
while ( a1[6] > v4 );
}
result = meh_reset_hash(*a1);
if ( !(_DWORD)result )
{
result = meh_reset_hash(a1[1]);
if ( !(_DWORD)result )
result = meh_update_hash(*a1, a1[3], a1[6]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const void *a2, size_t a3)
{
unsigned __int64 v4; // rax
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_reset_hmac", 4294967291LL);
memset((void *)a1[3], 0, a1[6]);
if ( a1[6] >= a3 )
memcpy((void *)a1[3], a2, a3);
else
meh_hash(*((unsigned int *)a1 + 14), a2, a3, a1[3]);
memcpy((void *)a1[2], (const void *)a1[3], a1[6]);
if ( a1[6] )
{
v4 = 0LL;
do
{
*(_BYTE *)(a1[3] + v4) ^= 0x36u;
*(_BYTE *)(a1[2] + v4++) ^= 0x5Cu;
}
while ( a1[6] > v4 );
}
result = meh_reset_hash(*a1);
if ( !(_DWORD)result )
{
result = meh_reset_hash(a1[1]);
if ( !(_DWORD)result )
result = meh_update_hash(*a1, a1[3], a1[6]);
}
return result;
}

original_code:
meh_error_t meh_reset_hmac(MehHMAC hmac, const unsigned char* key, size_t len)
{
    int i;
    meh_error_t error;
    if (((void *)0) == hmac || ((void *)0) == key)
        return meh_error("invalid argument passed to meh_reset_hmac",
                         MEH_INVALID_ARGUMENT);
    memset(hmac->ipad, 0, hmac->block_size);
    if (len > hmac->block_size)
        meh_hash(hmac->id, key, len, hmac->ipad);
    else
        memcpy(hmac->ipad, key, len);
    memcpy(hmac->opad, hmac->ipad, hmac->block_size);
    for (i = 0; i < hmac->block_size; i++)
    {
        hmac->ipad[i] ^= 0x36;
        hmac->opad[i] ^= 0x5c;
    }
    if ((error = meh_reset_hash(hmac->inner)) != MEH_OK)
        return error;
    if ((error = meh_reset_hash(hmac->outer)) != MEH_OK)
        return error;
    error = meh_update_hash(hmac->inner, hmac->ipad, hmac->block_size);
    return error;
}

canonical_original_code:
enum meh_error_t meh_reset_hmac(struct meh_hmac_s *hmac, unsigned char *key, unsigned long len)
{
    int i;
    enum meh_error_t error;
    if (((void *)0) == hmac || ((void *)0) == key)
        return meh_error("invalid argument passed to meh_reset_hmac",
                         MEH_INVALID_ARGUMENT);
    memset(hmac->ipad, 0, hmac->block_size);
    if (len > hmac->block_size)
        meh_hash(hmac->id, key, len, hmac->ipad);
    else
        memcpy(hmac->ipad, key, len);
    memcpy(hmac->opad, hmac->ipad, hmac->block_size);
    for (i = 0; i < hmac->block_size; i++)
    {
        hmac->ipad[i] ^= 0x36;
        hmac->opad[i] ^= 0x5c;
    }
    if ((error = meh_reset_hash(hmac->inner)) != MEH_OK)
        return error;
    if ((error = meh_reset_hash(hmac->outer)) != MEH_OK)
        return error;
    error = meh_update_hash(hmac->inner, hmac->ipad, hmac->block_size);
    return error;
}

variable_types: struct meh_hmac_s { struct meh_hash_s { union meh_hash_state_u { struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; } *md5; struct meh_sha1_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha1; struct meh_sha256_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha256; struct meh_sha256_state_s *sha224; struct meh_sha512_state_s { unsigned int total[2]; unsigned long state[8]; unsigned char buffer[128]; } *sha384; struct meh_sha512_state_s *sha512; } state; enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 } id; unsigned long output_size; } *inner; unsigned char *opad; unsigned long output_size; enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 } id; } *

variable_types:
key
unsigned char *

variable_types:
len
unsigned long

variable_types: i int

variable_types: enum meh_error_t { MEH_FILE_NOT_FOUND=-16, MEH_READ_ERROR=-15, MEH_WRITE_ERROR=-14, MEH_SOURCE_EXHAUSTED=-13, MEH_INVALID_PRNG=-12, MEH_INVALID_KDF=-11, MEH_INVALID_HASH=-10, MEH_INVALID_CIPHER=-9, MEH_INVALID_KEY_SIZE=-8, MEH_INVALID_IV_SIZE=-7, MEH_INVALID_ROUNDS=-6, MEH_INVALID_ARGUMENT=-5, MEH_OUT_OF_MEMORY=-4, MEH_BUFFER_UNDERFLOW=-3, MEH_BUFFER_OVERFLOW=-2, MEH_ERROR=-1, MEH_OK=0 }

user_defined_types: struct meh_hmac_s { struct meh_hash_s *inner; unsigned char *opad; unsigned long output_size; enum meh_hash_id id; }

user_defined_types: struct meh_hash_s { union meh_hash_state_u state; enum meh_hash_id id; unsigned long output_size; }

user_defined_types: union meh_hash_state_u { struct meh_md5_state_s *md5; struct meh_sha1_state_s *sha1; struct meh_sha256_state_s *sha256; struct meh_sha256_state_s *sha224; struct meh_sha512_state_s *sha384; struct meh_sha512_state_s *sha512; }


decompiled_code:
__int64 __fastcall meh_update_hmac(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 )
result = meh_update_hash(*a1, a2, a3);
else
result = meh_error("invalid argument passed to meh_update_hmac", 4294967291LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 )
result = meh_update_hash(*a1, a2, a3);
else
result = meh_error("invalid argument passed to meh_update_hmac", 4294967291LL);
return result;
}

original_code:
meh_error_t meh_update_hmac(MehHMAC hmac, const unsigned char* data, size_t len)
{
    if (((void *)0) == hmac)
        return meh_error("invalid argument passed to meh_update_hmac",
                         MEH_INVALID_ARGUMENT);
    return meh_update_hash(hmac->inner, data, len);
}

canonical_original_code:
enum meh_error_t meh_update_hmac(struct meh_hmac_s *hmac, unsigned char *data, unsigned long len)
{
    if (((void *)0) == hmac)
        return meh_error("invalid argument passed to meh_update_hmac",
                         MEH_INVALID_ARGUMENT);
    return meh_update_hash(hmac->inner, data, len);
}

variable_types:
data
unsigned char *

return_type: enum meh_error_t { MEH_FILE_NOT_FOUND=-16, MEH_READ_ERROR=-15, MEH_WRITE_ERROR=-14, MEH_SOURCE_EXHAUSTED=-13, MEH_INVALID_PRNG=-12, MEH_INVALID_KDF=-11, MEH_INVALID_HASH=-10, MEH_INVALID_CIPHER=-9, MEH_INVALID_KEY_SIZE=-8, MEH_INVALID_IV_SIZE=-7, MEH_INVALID_ROUNDS=-6, MEH_INVALID_ARGUMENT=-5, MEH_OUT_OF_MEMORY=-4, MEH_BUFFER_UNDERFLOW=-3, MEH_BUFFER_OVERFLOW=-2, MEH_ERROR=-1, MEH_OK=0 }

user_defined_types: enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 }

user_defined_types: struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; }

user_defined_types: struct meh_sha1_state_s { unsigned int total[2]; unsigned char buffer[64]; }

user_defined_types: struct meh_sha256_state_s { unsigned int total[2]; unsigned char buffer[64]; }

user_defined_types: struct meh_sha512_state_s { unsigned int total[2]; unsigned long state[8]; unsigned char buffer[128]; }


decompiled_code:
__int64 __fastcall meh_finish_hmac(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 )
return meh_error("invalid argument passed to meh_update_hmac", 4294967291LL);
result = meh_finish_hash(*a1, a1[4]);
if ( !(_DWORD)result )
{
result = meh_update_hash(a1[1], a1[2], a1[6]);
if ( !(_DWORD)result )
{
result = meh_update_hash(a1[1], a1[4], a1[5]);
if ( !(_DWORD)result )
result = meh_finish_hash(a1[1], a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 )
return meh_error("invalid argument passed to meh_update_hmac", 4294967291LL);
result = meh_finish_hash(*a1, a1[4]);
if ( !(_DWORD)result )
{
result = meh_update_hash(a1[1], a1[2], a1[6]);
if ( !(_DWORD)result )
{
result = meh_update_hash(a1[1], a1[4], a1[5]);
if ( !(_DWORD)result )
result = meh_finish_hash(a1[1], a2);
}
}
return result;
}

original_code:
meh_error_t meh_finish_hmac(MehHMAC hmac, unsigned char* output)
{
    meh_error_t error;
    if (((void *)0) == hmac)
        return meh_error("invalid argument passed to meh_update_hmac",
                         MEH_INVALID_ARGUMENT);
    if ((error = meh_finish_hash(hmac->inner, hmac->tmp)) != MEH_OK)
        return error;
    if ((error = meh_update_hash(hmac->outer,
                                 hmac->opad, hmac->block_size)) != MEH_OK)
        return error;
    if ((error = meh_update_hash(hmac->outer,
                                 hmac->tmp, hmac->output_size)) != MEH_OK)
        return error;
    if ((error = meh_finish_hash(hmac->outer, output)) != MEH_OK)
        return error;
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_finish_hmac(struct meh_hmac_s *hmac, unsigned char *output)
{
    enum meh_error_t error;
    if (((void *)0) == hmac)
        return meh_error("invalid argument passed to meh_update_hmac",
                         MEH_INVALID_ARGUMENT);
    if ((error = meh_finish_hash(hmac->inner, hmac->tmp)) != MEH_OK)
        return error;
    if ((error = meh_update_hash(hmac->outer,
                                 hmac->opad, hmac->block_size)) != MEH_OK)
        return error;
    if ((error = meh_update_hash(hmac->outer,
                                 hmac->tmp, hmac->output_size)) != MEH_OK)
        return error;
    if ((error = meh_finish_hash(hmac->outer, output)) != MEH_OK)
        return error;
    return MEH_OK;
}

variable_types:
output
unsigned char *

user_defined_types: enum meh_error_t { MEH_FILE_NOT_FOUND=-16, MEH_READ_ERROR=-15, MEH_WRITE_ERROR=-14, MEH_SOURCE_EXHAUSTED=-13, MEH_INVALID_PRNG=-12, MEH_INVALID_KDF=-11, MEH_INVALID_HASH=-10, MEH_INVALID_CIPHER=-9, MEH_INVALID_KEY_SIZE=-8, MEH_INVALID_IV_SIZE=-7, MEH_INVALID_ROUNDS=-6, MEH_INVALID_ARGUMENT=-5, MEH_OUT_OF_MEMORY=-4, MEH_BUFFER_UNDERFLOW=-3, MEH_BUFFER_OVERFLOW=-2, MEH_ERROR=-1, MEH_OK=0 }


decompiled_code:
void __fastcall meh_destroy_hmac(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 3));
free(*((void **)ptr + 2));
meh_destroy_hash(*((_QWORD *)ptr + 1));
meh_destroy_hash(*(_QWORD *)ptr);
free(ptr);
}
else
{
meh_warn("invalid argument passed to meh_destroy_hmac");
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 3));
free(*((void **)ptr + 2));
meh_destroy_hash(*((_QWORD *)ptr + 1));
meh_destroy_hash(*(_QWORD *)ptr);
free(ptr);
}
else
{
meh_warn("invalid argument passed to meh_destroy_hmac");
}
}

original_code:
void meh_destroy_hmac(MehHMAC hmac)
{
    if (((void *)0) == hmac)
    {
        meh_warn("invalid argument passed to meh_destroy_hmac");
        return;
    }
    free(hmac->tmp);
    free(hmac->ipad);
    free(hmac->opad);
    meh_destroy_hash(hmac->outer);
    meh_destroy_hash(hmac->inner);
    free(hmac);
}

canonical_original_code:
void meh_destroy_hmac(struct meh_hmac_s *hmac)
{
    if (((void *)0) == hmac)
    {
        meh_warn("invalid argument passed to meh_destroy_hmac");
        return;
    }
    free(hmac->tmp);
    free(hmac->ipad);
    free(hmac->opad);
    meh_destroy_hash(hmac->outer);
    meh_destroy_hash(hmac->inner);
    free(hmac);
}


decompiled_code:
__int64 __fastcall meh_hmac(unsigned int a1, __int64 a2, __int64 a3, const void *a4, size_t a5, __int64 a6)
{
__int64 *v8; // rax
__int64 *v9; // rbp
unsigned int v10; // ebx

v8 = meh_get_hmac(a1, a4, a5);
if ( !v8 )
return (unsigned int)-1;
v9 = v8;
v10 = meh_update_hmac(v8, a2, a3);
if ( !v10 )
v10 = meh_finish_hmac(v9, a6);
meh_destroy_hmac(v9);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, __int64 a3, const void *a4, size_t a5, __int64 a6)
{
__int64 *v8; // rax
__int64 *v9; // rbp
unsigned int v10; // ebx

v8 = meh_get_hmac(a1, a4, a5);
if ( !v8 )
return (unsigned int)-1;
v9 = v8;
v10 = func1(v8, a2, a3);
if ( !v10 )
v10 = func2(v9, a6);
func3(v9);
return v10;
}

original_code:
meh_error_t meh_hmac(const meh_hash_id hash_id, const unsigned char* data,
                     size_t data_len, const unsigned char* key, size_t key_len,
                     unsigned char* output)
{
    meh_error_t error;
    MehHMAC t = meh_get_hmac(hash_id, key, key_len);
    if (((void *)0) == t)
        return MEH_ERROR;
    if ((error = meh_update_hmac(t, data, data_len)) != MEH_OK)
    {
        meh_destroy_hmac(t);
        return error;
    }
    if ((error = meh_finish_hmac(t, output)) != MEH_OK)
    {
        meh_destroy_hmac(t);
        return error;
    }
    meh_destroy_hmac(t);
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_hmac(enum meh_hash_id hash_id, unsigned char *data, unsigned long data_len, unsigned char *key, unsigned long key_len, unsigned char *output)
{
    enum meh_error_t error;
    struct meh_hmac_s *t = meh_get_hmac(hash_id, key, key_len);
    if (((void *)0) == t)
        return MEH_ERROR;
    if ((error = meh_update_hmac(t, data, data_len)) != MEH_OK)
    {
        meh_destroy_hmac(t);
        return error;
    }
    if ((error = meh_finish_hmac(t, output)) != MEH_OK)
    {
        meh_destroy_hmac(t);
        return error;
    }
    meh_destroy_hmac(t);
    return MEH_OK;
}

variable_types: enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 }


original_code:
void meh_reset_md5(MehMD5 ctx)
{
    ctx->total[0] = ctx->total[1] = 0;
    ctx->state[0] = 0x67452301;
    ctx->state[1] = 0xEFCDAB89;
    ctx->state[2] = 0x98BADCFE;
    ctx->state[3] = 0x10325476;
    memset(ctx->buffer, 0, 64);
}

canonical_original_code:
void meh_reset_md5(struct meh_md5_state_s *ctx)
{
    ctx->total[0] = ctx->total[1] = 0;
    ctx->state[0] = 0x67452301;
    ctx->state[1] = 0xEFCDAB89;
    ctx->state[2] = 0x98BADCFE;
    ctx->state[3] = 0x10325476;
    memset(ctx->buffer, 0, 64);
}

variable_types: struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; } *


decompiled_code:
void *meh_get_md5()
{
void *v0; // rax
void *v1; // rbx

v0 = malloc(0x58uLL);
v1 = v0;
if ( v0 )
meh_reset_md5((__int64)v0);
else
meh_warn("could not allocate hash context in meh_get_md5");
return v1;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // rax
void *v1; // rbx

v0 = malloc(0x58uLL);
v1 = v0;
if ( v0 )
func0((__int64)v0);
else
meh_warn("could not allocate hash context in meh_get_md5");
return v1;
}

original_code:
MehMD5 meh_get_md5(void)
{
    MehMD5 r = malloc(sizeof (meh_md5_state_t));
    if (((void *)0) == r)
    {
        meh_warn("could not allocate hash context in meh_get_md5");
        return ((void *)0);
    }
    meh_reset_md5(r);
    return r;
}

canonical_original_code:
struct meh_md5_state_s *meh_get_md5()
{
    struct meh_md5_state_s *r = malloc(sizeof (meh_md5_state_t));
    if (((void *)0) == r)
    {
        meh_warn("could not allocate hash context in meh_get_md5");
        return ((void *)0);
    }
    meh_reset_md5(r);
    return r;
}

return_type: struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; } *


original_code:
void meh_update_md5(MehMD5 ctx, const unsigned char* data, size_t len)
{
    uint32_t left, fill;
    if (!len)
        return;
    left = (ctx->total[0] >> 3) & 0x3F;
    fill = 64 - left;
    ctx->total[0] += len << 3;
    ctx->total[1] += len >> 29;
    ctx->total[1] += ctx->total[0] < (len << 3);
    if (left && len >= fill)
    {
        memcpy(ctx->buffer + left, data, fill);
        meh_process_md5(ctx, ctx->buffer);
        len -= fill;
        data += fill;
        left = 0;
    }
    while (len >= 64)
    {
        meh_process_md5(ctx, data);
        len -= 64;
        data += 64;
    }
    if (len)
        memcpy(ctx->buffer + left, data, len);
}

canonical_original_code:
void meh_update_md5(struct meh_md5_state_s *ctx, unsigned char *data, unsigned long len)
{
    unsigned int left; unsigned int fill;
    if (!len)
        return;
    left = (ctx->total[0] >> 3) & 0x3F;
    fill = 64 - left;
    ctx->total[0] += len << 3;
    ctx->total[1] += len >> 29;
    ctx->total[1] += ctx->total[0] < (len << 3);
    if (left && len >= fill)
    {
        memcpy(ctx->buffer + left, data, fill);
        meh_process_md5(ctx, ctx->buffer);
        len -= fill;
        data += fill;
        left = 0;
    }
    while (len >= 64)
    {
        meh_process_md5(ctx, data);
        len -= 64;
        data += 64;
    }
    if (len)
        memcpy(ctx->buffer + left, data, len);
}

variable_types:
left
unsigned int

variable_types:
fill
unsigned int


canonical_original_code:
void meh_finish_md5(struct meh_md5_state_s *ctx, unsigned char *output)
{
    unsigned int last; unsigned int padlen;
    unsigned char msglen[8];
    do { (msglen)[(0) ] = (unsigned char)((ctx->total[0]) ); (msglen)[(0)+1] = (unsigned char)((ctx->total[0]) >> 8); (msglen)[(0)+2] = (unsigned char)((ctx->total[0]) >> 16); (msglen)[(0)+3] = (unsigned char)((ctx->total[0]) >> 24); } while (0);
    do { (msglen)[(4) ] = (unsigned char)((ctx->total[1]) ); (msglen)[(4)+1] = (unsigned char)((ctx->total[1]) >> 8); (msglen)[(4)+2] = (unsigned char)((ctx->total[1]) >> 16); (msglen)[(4)+3] = (unsigned char)((ctx->total[1]) >> 24); } while (0);
    last = (ctx->total[0] >> 3) & 0x3F;
    padlen = ( 56 > last)?
             ( 56 - last):
             (120 - last);
    meh_update_md5(ctx, meh_md5_padding, padlen);
    meh_update_md5(ctx, msglen, 8);
    do { (output)[(0) ] = (unsigned char)((ctx->state[0]) ); (output)[(0)+1] = (unsigned char)((ctx->state[0]) >> 8); (output)[(0)+2] = (unsigned char)((ctx->state[0]) >> 16); (output)[(0)+3] = (unsigned char)((ctx->state[0]) >> 24); } while (0);
    do { (output)[(4) ] = (unsigned char)((ctx->state[1]) ); (output)[(4)+1] = (unsigned char)((ctx->state[1]) >> 8); (output)[(4)+2] = (unsigned char)((ctx->state[1]) >> 16); (output)[(4)+3] = (unsigned char)((ctx->state[1]) >> 24); } while (0);
    do { (output)[(8) ] = (unsigned char)((ctx->state[2]) ); (output)[(8)+1] = (unsigned char)((ctx->state[2]) >> 8); (output)[(8)+2] = (unsigned char)((ctx->state[2]) >> 16); (output)[(8)+3] = (unsigned char)((ctx->state[2]) >> 24); } while (0);
    do { (output)[(12) ] = (unsigned char)((ctx->state[3]) ); (output)[(12)+1] = (unsigned char)((ctx->state[3]) >> 8); (output)[(12)+2] = (unsigned char)((ctx->state[3]) >> 16); (output)[(12)+3] = (unsigned char)((ctx->state[3]) >> 24); } while (0);
}

variable_types:
last
unsigned int

variable_types:
padlen
unsigned int

variable_types:
msglen
unsigned char [8]


decompiled_code:
__int64 __fastcall meh_reset_rc4(_BYTE *a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rcx
int v6; // esi
char v7; // r8

if ( !a2 || !a1 )
return meh_error("null reference passed to meh_reset_rc4", 4294967291LL);
v4 = 0LL;
if ( a3 - 1 > 0xFF )
return meh_error("invalid key size passed to meh_reset_rc4", 4294967288LL);
do
{
a1[v4 + 2] = v4;
++v4;
}
while ( v4 != 256 );
v5 = 0LL;
v6 = 0;
do
{
v7 = a1[v5 + 2];
v6 += (unsigned __int8)(*(_BYTE *)(a2 + v5 % a3) + v7);
a1[v5 + 2] = a1[(unsigned __int8)v6 + 2];
a1[(unsigned __int8)v6 + 2] = v7;
++v5;
}
while ( v5 != 256 );
a1[1] = 0;
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rcx
int v6; // esi
char v7; // r8

if ( !a2 || !a1 )
return meh_error("null reference passed to meh_reset_rc4", 4294967291LL);
v4 = 0LL;
if ( a3 - 1 > 0xFF )
return meh_error("invalid key size passed to meh_reset_rc4", 4294967288LL);
do
{
a1[v4 + 2] = v4;
++v4;
}
while ( v4 != 256 );
v5 = 0LL;
v6 = 0;
do
{
v7 = a1[v5 + 2];
v6 += (unsigned __int8)(*(_BYTE *)(a2 + v5 % a3) + v7);
a1[v5 + 2] = a1[(unsigned __int8)v6 + 2];
a1[(unsigned __int8)v6 + 2] = v7;
++v5;
}
while ( v5 != 256 );
a1[1] = 0;
*a1 = 0;
return 0LL;
}

original_code:
meh_error_t meh_reset_rc4(MehRC4 rc4,
                          const unsigned char* key, size_t key_size)
{
    uint32_t i;
    uint8_t* state;
    uint8_t j, tmp;
    if (((void *)0) == key || ((void *)0) == rc4)
        return meh_error("null reference passed to meh_reset_rc4",
                         MEH_INVALID_ARGUMENT);
    if (key_size < 1 || key_size > 256)
        return meh_error("invalid key size passed to meh_reset_rc4",
                         MEH_INVALID_KEY_SIZE);
    state = rc4->state;
    for (i = 0; i < 256; i++)
        state[i] = i;
    for (i = j = 0; i < 256; i++)
    {
        j += key[i % key_size] + state[i];
        tmp = state[i];
        rc4->state[i] = state[j];
        rc4->state[j] = tmp;
    }
    rc4->x = rc4->y = 0;
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_reset_rc4(struct meh_rc4_state_s *rc4, unsigned char *key, unsigned long key_size)
{
    unsigned int i;
    unsigned char *state;
    unsigned char j; unsigned char tmp;
    if (((void *)0) == key || ((void *)0) == rc4)
        return meh_error("null reference passed to meh_reset_rc4",
                         MEH_INVALID_ARGUMENT);
    if (key_size < 1 || key_size > 256)
        return meh_error("invalid key size passed to meh_reset_rc4",
                         MEH_INVALID_KEY_SIZE);
    state = rc4->state;
    for (i = 0; i < 256; i++)
        state[i] = i;
    for (i = j = 0; i < 256; i++)
    {
        j += key[i % key_size] + state[i];
        tmp = state[i];
        rc4->state[i] = state[j];
        rc4->state[j] = tmp;
    }
    rc4->x = rc4->y = 0;
    return MEH_OK;
}

variable_types: struct meh_rc4_state_s { unsigned char x; } *

variable_types:
i
unsigned int

variable_types:
state
unsigned char *

variable_types:
j
unsigned char

variable_types:
tmp
unsigned char


original_code:
meh_error_t meh_update_rc4(MehRC4 rc4, const unsigned char* in,
                           unsigned char* out, size_t len, size_t* got)
{
    uint32_t i;
    uint8_t* state;
    uint8_t x, y, tmp;
    if (((void *)0) == in || ((void *)0) == got || ((void *)0) == out || ((void *)0) == rc4)
        return meh_error("null reference passed to meh_update_rc4",
                         MEH_INVALID_ARGUMENT);
    x = rc4->x;
    y = rc4->y;
    state = rc4->state;
    for (i = 0; i < len; i++)
    {
        y += state[++x];
        tmp = state[x];
        state[x] = state[y];
        state[y] = tmp;
        out[i] = in[i]^state[(uint8_t)(state[x]+state[y])];
    }
    rc4->x = x;
    rc4->y = y;
    *got = len;
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_update_rc4(struct meh_rc4_state_s *rc4, unsigned char *in, unsigned char *out, unsigned long len, unsigned long *got)
{
    unsigned int i;
    unsigned char *state;
    unsigned char x; unsigned char y; unsigned char tmp;
    if (((void *)0) == in || ((void *)0) == got || ((void *)0) == out || ((void *)0) == rc4)
        return meh_error("null reference passed to meh_update_rc4",
                         MEH_INVALID_ARGUMENT);
    x = rc4->x;
    y = rc4->y;
    state = rc4->state;
    for (i = 0; i < len; i++)
    {
        y += state[++x];
        tmp = state[x];
        state[x] = state[y];
        state[y] = tmp;
        out[i] = in[i]^state[(unsigned char)(state[x]+state[y])];
    }
    rc4->x = x;
    rc4->y = y;
    *got = len;
    return MEH_OK;
}

variable_types:
in
unsigned char *

variable_types:
out
unsigned char *

variable_types:
len
unsigned long

variable_types:
got
unsigned long *

variable_types:
x
unsigned char

variable_types:
y
unsigned char

user_defined_types: struct meh_rc4_state_s { unsigned char x; }


decompiled_code:
__int64 __fastcall meh_finish_rc4(__int64 a1, __int64 a2, _QWORD *a3)
{
*a3 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, _QWORD *a3)
{
*a3 = 0LL;
return 0LL;
}

original_code:
meh_error_t meh_finish_rc4(MehRC4 rc4, unsigned char* out, size_t* got)
{
    *got = 0;
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_finish_rc4(struct meh_rc4_state_s *rc4, unsigned char *out, unsigned long *got)
{
    *got = 0;
    return MEH_OK;
}


decompiled_code:
__int64 __fastcall meh_reset_hash(_QWORD *a1)
{
__int64 result; // rax

if ( !a1 )
return meh_error("invalid argument passed to meh_reset_hash", 4294967291LL);
switch ( *((_DWORD *)a1 + 2) )
{
case 0:
meh_reset_md5(*a1);
result = 0LL;
break;
case 1:
meh_reset_sha1(*a1);
result = 0LL;
break;
case 2:
meh_reset_sha224(*a1);
result = 0LL;
break;
case 3:
meh_reset_sha256(*a1);
result = 0LL;
break;
case 4:
meh_reset_sha384(*a1);
result = 0LL;
break;
case 5:
meh_reset_sha512(*a1);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_reset_hash", 4294967286LL);
break;
}
return result;
}

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

if ( !a1 )
return meh_error("invalid argument passed to meh_reset_hash", 4294967291LL);
switch ( *((_DWORD *)a1 + 2) )
{
case 0:
meh_reset_md5(*a1);
result = 0LL;
break;
case 1:
meh_reset_sha1(*a1);
result = 0LL;
break;
case 2:
meh_reset_sha224(*a1);
result = 0LL;
break;
case 3:
meh_reset_sha256(*a1);
result = 0LL;
break;
case 4:
meh_reset_sha384(*a1);
result = 0LL;
break;
case 5:
meh_reset_sha512(*a1);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_reset_hash", 4294967286LL);
break;
}
return result;
}

original_code:
meh_error_t meh_reset_hash(MehHash hash)
{
    if (((void *)0) == hash)
        return meh_error("invalid argument passed to meh_reset_hash",
                         MEH_INVALID_ARGUMENT);
    switch (hash->id)
    {
        case MEH_MD5: meh_reset_md5(hash->state.md5); break;
        case MEH_SHA1: meh_reset_sha1(hash->state.sha1); break;
        case MEH_SHA224: meh_reset_sha224(hash->state.sha224); break;
        case MEH_SHA256: meh_reset_sha256(hash->state.sha256); break;
        case MEH_SHA384: meh_reset_sha384(hash->state.sha384); break;
        case MEH_SHA512: meh_reset_sha512(hash->state.sha512); break;
        default:
            return meh_error("invalid hash id passed to meh_reset_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_reset_hash(struct meh_hash_s *hash)
{
    if (((void *)0) == hash)
        return meh_error("invalid argument passed to meh_reset_hash",
                         MEH_INVALID_ARGUMENT);
    switch (hash->id)
    {
        case MEH_MD5: meh_reset_md5(hash->state.md5); break;
        case MEH_SHA1: meh_reset_sha1(hash->state.sha1); break;
        case MEH_SHA224: meh_reset_sha224(hash->state.sha224); break;
        case MEH_SHA256: meh_reset_sha256(hash->state.sha256); break;
        case MEH_SHA384: meh_reset_sha384(hash->state.sha384); break;
        case MEH_SHA512: meh_reset_sha512(hash->state.sha512); break;
        default:
            return meh_error("invalid hash id passed to meh_reset_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

variable_types: struct meh_hash_s { union meh_hash_state_u { struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; } *md5; struct meh_sha1_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha1; struct meh_sha256_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha256; struct meh_sha256_state_s *sha224; struct meh_sha512_state_s { unsigned int total[2]; unsigned long state[8]; unsigned char buffer[128]; } *sha384; struct meh_sha512_state_s *sha512; } state; enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 } id; unsigned long output_size; } *


decompiled_code:
__int64 __fastcall meh_update_hash(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_update_hash", 4294967291LL);
result = 0LL;
if ( a3 )
{
switch ( *((_DWORD *)a1 + 2) )
{
case 0:
meh_update_md5(*a1);
result = 0LL;
break;
case 1:
meh_update_sha1(*a1);
result = 0LL;
break;
case 2:
case 3:
meh_update_sha256(*a1);
result = 0LL;
break;
case 4:
case 5:
meh_update_sha512(*a1);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_update_hash", 4294967286LL);
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_update_hash", 4294967291LL);
result = 0LL;
if ( a3 )
{
switch ( *((_DWORD *)a1 + 2) )
{
case 0:
meh_update_md5(*a1);
result = 0LL;
break;
case 1:
meh_update_sha1(*a1);
result = 0LL;
break;
case 2:
case 3:
meh_update_sha256(*a1);
result = 0LL;
break;
case 4:
case 5:
meh_update_sha512(*a1);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_update_hash", 4294967286LL);
break;
}
}
return result;
}

original_code:
meh_error_t meh_update_hash(MehHash hash, const unsigned char* data, size_t len)
{
    if (((void *)0) == hash || ((void *)0) == data)
        return meh_error("invalid argument passed to meh_update_hash",
                         MEH_INVALID_ARGUMENT);
    if (0 == len)
        return MEH_OK;
    switch (hash->id)
    {
        case MEH_MD5: meh_update_md5(hash->state.md5, data, len); break;
        case MEH_SHA1: meh_update_sha1(hash->state.sha1, data, len); break;
        case MEH_SHA224:
            meh_update_sha256((hash->state.sha224), (data), (len)); break;
        case MEH_SHA256:
            meh_update_sha256(hash->state.sha256, data, len); break;
        case MEH_SHA384:
            meh_update_sha512((hash->state.sha384), (data), (len)); break;
        case MEH_SHA512:
            meh_update_sha512(hash->state.sha512, data, len); break;
        default:
            return meh_error("invalid hash id passed to meh_update_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_update_hash(struct meh_hash_s *hash, unsigned char *data, unsigned long len)
{
    if (((void *)0) == hash || ((void *)0) == data)
        return meh_error("invalid argument passed to meh_update_hash",
                         MEH_INVALID_ARGUMENT);
    if (0 == len)
        return MEH_OK;
    switch (hash->id)
    {
        case MEH_MD5: meh_update_md5(hash->state.md5, data, len); break;
        case MEH_SHA1: meh_update_sha1(hash->state.sha1, data, len); break;
        case MEH_SHA224:
            meh_update_sha256((hash->state.sha224), (data), (len)); break;
        case MEH_SHA256:
            meh_update_sha256(hash->state.sha256, data, len); break;
        case MEH_SHA384:
            meh_update_sha512((hash->state.sha384), (data), (len)); break;
        case MEH_SHA512:
            meh_update_sha512(hash->state.sha512, data, len); break;
        default:
            return meh_error("invalid hash id passed to meh_update_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

variable_types:
data
unsigned char *