main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
const char *v5; // rax
char *v6; // rbp
size_t v7; // rax
char *v8; // r12
unsigned int v9; // eax
__pid_t v10; // ebp
unsigned int v11; // eax
__int64 v12; // rsi
__int64 v13; // r13
unsigned int **v14; // rax
__int64 v15; // [rsp+0h] [rbp-4038h]
int v16; // [rsp+8h] [rbp-4030h]
int v17; // [rsp+Ch] [rbp-402Ch]
int stat_loc; // [rsp+14h] [rbp-4024h] BYREF
unsigned int v19; // [rsp+18h] [rbp-4020h] BYREF
unsigned int v20; // [rsp+1Ch] [rbp-401Ch] BYREF
char v21[16408]; // [rsp+20h] [rbp-4018h] BYREF

if ( (unsigned int)isArgumentForShowingVersion(argv) )
showVersionAndExit();
getpid();
stat_loc = 0;
v19 = 1;
v3 = getPrompt();
initialize();
putchar(10);
setPrompt(v3);
v16 = 0;
v4 = v3;
LABEL_4:
v15 = v4;
while ( 1 )
{
while ( 1 )
{
v5 = (const char *)readline(v15);
v6 = (char *)v5;
if ( !v5 )
{
putchar(10);
goto LABEL_9;
}
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(v21, v8, &v20);
if ( (unsigned int)isExitCommand(v8) )
{
buddy_free(v8);
freeList(jobList);
freeArguments(v20, v21, 0LL);
LABEL_9:
exit(0);
}
if ( (unsigned int)isCdCommand(v8, v21) )
{
changeDir(v21);
}
else
{
if ( (unsigned int)isJobsCommand(v8) )
{
printList(jobList);
freeArguments(v20, v21, v8);
goto LABEL_17;
}
if ( (unsigned int)isFgCommand(v8, v21) )
{
fg(v21, jobList, v20, v8);
goto LABEL_17;
}
if ( (unsigned int)isBgCommand(v8, v21) )
{
bgS(v21, jobList, v20, v8);
goto LABEL_17;
}
if ( (unsigned int)isCommandNotEmpty(v8) )
{
if ( v17 == 1 )
{
v11 = fork();
if ( v11 )
{
v14 = (unsigned int **)createAndSetNode(&v19, v11, (__int64)v8, 1);
recordCommand(v14, v19);
freeArguments(v20, v21, v8);
}
else
{
ignoreSignals(v8, 0LL);
runCommand(v21, v8);
}
}
else
{
v9 = fork();
v10 = v9;
if ( v9 )
{
v12 = v9;
v13 = createAndSetNode(&v19, v9, (__int64)v8, v17);
ignoreSignals(&v19, v12);
if ( waitpid(v10, &stat_loc, 2) < 0 )
err_sys("waitpid error");
freeArguments(v20, v21, v8);
restoreSignalsAndDetermineStatus((unsigned int)stat_loc, jobList, v13);
}
else
{
runCommand(v21, v8);
}
}
goto LABEL_17;
}
}
freeArguments(v20, v21, v8);
LABEL_17:
if ( !v16 )
{
v16 = 1;
_sigsetjmp(env, 1);
v4 = v15;
goto LABEL_4;
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
const char *v5; // rax
char *v6; // rbp
size_t v7; // rax
char *v8; // r12
unsigned int v9; // eax
__pid_t v10; // ebp
unsigned int v11; // eax
__int64 v12; // rsi
__int64 v13; // r13
unsigned int **v14; // rax
__int64 v15; // [rsp+0h] [rbp-4038h]
int v16; // [rsp+8h] [rbp-4030h]
int v17; // [rsp+Ch] [rbp-402Ch]
int stat_loc; // [rsp+14h] [rbp-4024h] BYREF
unsigned int v19; // [rsp+18h] [rbp-4020h] BYREF
unsigned int v20; // [rsp+1Ch] [rbp-401Ch] BYREF
char v21[16408]; // [rsp+20h] [rbp-4018h] BYREF

if ( (unsigned int)isArgumentForShowingVersion(argv) )
showVersionAndExit();
getpid();
stat_loc = 0;
v19 = 1;
v3 = getPrompt();
func1();
putchar(10);
setPrompt(v3);
v16 = 0;
v4 = v3;
LABEL_4:
v15 = v4;
while ( 1 )
{
while ( 1 )
{
v5 = (const char *)readline(v15);
v6 = (char *)v5;
if ( !v5 )
{
putchar(10);
goto LABEL_9;
}
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(v21, v8, &v20);
if ( (unsigned int)isExitCommand(v8) )
{
buddy_free(v8);
freeList(jobList);
freeArguments(v20, v21, 0LL);
LABEL_9:
exit(0);
}
if ( (unsigned int)isCdCommand(v8, v21) )
{
changeDir(v21);
}
else
{
if ( (unsigned int)isJobsCommand(v8) )
{
printList(jobList);
freeArguments(v20, v21, v8);
goto LABEL_17;
}
if ( (unsigned int)isFgCommand(v8, v21) )
{
fg(v21, jobList, v20, v8);
goto LABEL_17;
}
if ( (unsigned int)isBgCommand(v8, v21) )
{
bgS(v21, jobList, v20, v8);
goto LABEL_17;
}
if ( (unsigned int)isCommandNotEmpty(v8) )
{
if ( v17 == 1 )
{
v11 = fork();
if ( v11 )
{
v14 = (unsigned int **)func2(&v19, v11, (__int64)v8, 1);
func3(v14, v19);
freeArguments(v20, v21, v8);
}
else
{
ignoreSignals(v8, 0LL);
runCommand(v21, v8);
}
}
else
{
v9 = fork();
v10 = v9;
if ( v9 )
{
v12 = v9;
v13 = func2(&v19, v9, (__int64)v8, v17);
ignoreSignals(&v19, v12);
if ( waitpid(v10, &stat_loc, 2) < 0 )
err_sys("waitpid error");
freeArguments(v20, v21, v8);
restoreSignalsAndDetermineStatus((unsigned int)stat_loc, jobList, v13);
}
else
{
runCommand(v21, v8);
}
}
goto LABEL_17;
}
}
freeArguments(v20, v21, v8);
LABEL_17:
if ( !v16 )
{
v16 = 1;
_sigsetjmp(env, 1);
v4 = v15;
goto LABEL_4;
}
}
}

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

repo: thomascampbelladams/dash

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

return_type: int


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_76, bindUp, &vi_movement_keymap);
return rl_generic_bind(0LL, &unk_79, bindDown, &vi_movement_keymap);
}

canonical_decompiled_code:
__int64 func2()
{
rl_generic_bind(0LL, &unk_76, bindUp, &vi_movement_keymap);
return rl_generic_bind(0LL, &unk_79, 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);
}

return_type: void


reverseNumber

repo: thomasfrei/Project-Euler

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

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

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

v1 = 0;
do
{
v2 = a1 % 10;
v3 = a1;
a1 /= 10;
v1 = v2 + 10 * v1;
}
while ( v3 > 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

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er11
unsigned int v4; // ebp
unsigned int v5; // er9
int v6; // eax
int v7; // er9
int v8; // er10
int v9; // er11

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er11
unsigned int v4; // ebp
unsigned int v5; // er9
int v6; // eax
int v7; // er9
int v8; // er10
int v9; // er11

v3 = -999;
v4 = 0;
do
{
v5 = -999 * v3;
do
{
v6 = func7(v5, argv, envp);
if ( v6 == v7 && (int)v4 < v7 )
v4 = v7;
v5 = v9 + v7;
}
while ( v8 != 1 );
v3 = v9 + 1;
}
while ( v3 != -99 );
return printf("Result = %d\n", 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; // rbp
int v9; // er8
__int64 result; // rax
size_t v11; // [rsp+0h] [rbp-38h] BYREF
size_t outbytesleft; // [rsp+8h] [rbp-30h] BYREF
char *inbuf; // [rsp+10h] [rbp-28h] BYREF
char *outbuf; // [rsp+18h] [rbp-20h] BYREF

v11 = a2;
outbytesleft = a4;
inbuf = a1;
outbuf = a3;
v7 = iconv_open(a6, a5);
if ( v7 == (iconv_t)-1LL )
return -2LL;
v8 = v7;
v9 = iconv(v7, &inbuf, &v11, &outbuf, &outbytesleft);
result = -3LL;
if ( v9 >= 0 )
{
iconv_close(v8);
*outbuf = 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; // rbp
int v9; // er8
__int64 result; // rax
size_t v11; // [rsp+0h] [rbp-38h] BYREF
size_t outbytesleft; // [rsp+8h] [rbp-30h] BYREF
char *inbuf; // [rsp+10h] [rbp-28h] BYREF
char *outbuf; // [rsp+18h] [rbp-20h] BYREF

v11 = a2;
outbytesleft = a4;
inbuf = a1;
outbuf = a3;
v7 = iconv_open(a6, a5);
if ( v7 == (iconv_t)-1LL )
return -2LL;
v8 = v7;
v9 = iconv(v7, &inbuf, &v11, &outbuf, &outbytesleft);
result = -3LL;
if ( v9 >= 0 )
{
iconv_close(v8);
*outbuf = 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:
__int64 __fastcall hexstr_to_ucs2char(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r12
__int64 v5; // rbx
char s[3]; // [rsp+19h] [rbp-3Fh] BYREF
int v9; // [rsp+1Ch] [rbp-3Ch] BYREF

v9 = 0;
strcpy(s, " ");
if ( 2 * a4 < a2 )
return -1LL;
v4 = a2 >> 1;
if ( a2 >> 1 )
{
v5 = 0LL;
while ( 1 )
{
s[0] = *(_BYTE *)(a1 + 2 * v5);
s[1] = *(_BYTE *)(a1 + 2 * v5 + 1);
if ( sscanf(s, "%x", &v9) != 1 )
break;
*(_BYTE *)(a3 + v5++) = v9;
if ( v5 == v4 )
{
v4 &= 0xFFFFFFFFFFFFFFFELL;
return v4;
}
}
return -1LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r12
__int64 v5; // rbx
char s[3]; // [rsp+19h] [rbp-3Fh] BYREF
int v9; // [rsp+1Ch] [rbp-3Ch] BYREF

v9 = 0;
strcpy(s, " ");
if ( 2 * a4 < a2 )
return -1LL;
v4 = a2 >> 1;
if ( a2 >> 1 )
{
v5 = 0LL;
while ( 1 )
{
s[0] = *(_BYTE *)(a1 + 2 * v5);
s[1] = *(_BYTE *)(a1 + 2 * v5 + 1);
if ( sscanf(s, "%x", &v9) != 1 )
break;
*(_BYTE *)(a3 + v5++) = v9;
if ( v5 == v4 )
{
v4 &= 0xFFFFFFFFFFFFFFFELL;
return v4;
}
}
return -1LL;
}
return v4;
}

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 []


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
__int64 v8; // rax
char v9[16]; // [rsp+0h] [rbp-10h] 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
__int64 v8; // rax
char v9[16]; // [rsp+0h] [rbp-10h] 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, _BYTE *a3, size_t a4)
{
void *v4; // rsp
__int64 result; // rax
__int64 v8; // rax
char v9[16]; // [rsp+0h] [rbp-10h] 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, _BYTE *a3, size_t a4)
{
void *v4; // rsp
__int64 result; // rax
__int64 v8; // rax
char v9[16]; // [rsp+0h] [rbp-10h] 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, _BYTE *a2)
{
char v2; // dl
__int64 result; // rax
__int64 v4; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _BYTE *a2)
{
char v2; // dl
__int64 result; // rax
__int64 v4; // rcx

v2 = *a1;
LODWORD(result) = 0;
if ( *a1 )
{
v4 = 0LL;
while ( 1 )
{
result = (unsigned int)(result + 1);
if ( a2[v4] != v2 )
break;
v4 = (unsigned int)result;
v2 = a1[(unsigned int)result];
if ( !v2 )
{
a2 += (unsigned int)result;
goto LABEL_7;
}
}
}
else
{
LABEL_7:
result = (unsigned int)(result + 1);
if ( !*a2 )
result = 0LL;
}
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
__int64 v2; // rdx

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

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

result = 0LL;
if ( *a1 )
{
do
{
v2 = (unsigned int)(result + 1);
result = v2;
}
while ( a1[v2] );
}
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


decompiled_code:
__int64 __fastcall num2str(unsigned int a1, unsigned int a2, _WORD *a3)
{
unsigned int v5; // er10
__int64 v6; // r11
unsigned int v7; // ecx
int v8; // esi
unsigned int v9; // esi
__int64 v10; // rdx
__int64 v11; // rax
char *v12; // rdx
char *v13; // rax
char v14; // di
__int64 v15; // rdx
__int64 result; // rax

if ( a1 )
{
v5 = 0;
while ( 1 )
{
v6 = v5;
v7 = v5++;
v8 = a1 % a2 + 48;
if ( a1 % a2 >= 0xA )
LOBYTE(v8) = a1 % a2 + 55;
*((_BYTE *)a3 + v6) = v8;
if ( a2 > a1 )
break;
a1 /= a2;
}
if ( v7 )
{
v9 = 0;
do
{
v10 = v7;
v11 = v9;
--v7;
++v9;
v12 = (char *)a3 + v10;
v13 = (char *)a3 + v11;
v14 = *v12;
*v12 = *v13;
*v13 = v14;
}
while ( v9 < v7 );
v15 = v7 + v9 + 1;
result = v15;
}
else
{
result = 1LL;
v15 = 1LL;
}
*((_BYTE *)a3 + v15) = 0;
}
else
{
result = 48LL;
*a3 = 48;
}
return result;
}

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
_BYTE *v5; // rdx
__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 )
meh_hash(*((unsigned int *)a1 + 14), a2, a3, a1[3]);
else
memcpy((void *)a1[3], a2, a3);
memcpy((void *)a1[2], (const void *)a1[3], a1[6]);
if ( a1[6] )
{
v4 = 0LL;
do
{
*(_BYTE *)(v4 + a1[3]) ^= 0x36u;
v5 = (_BYTE *)(v4 + a1[2]);
++v4;
*v5 ^= 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
_BYTE *v5; // rdx
__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 )
meh_hash(*((unsigned int *)a1 + 14), a2, a3, a1[3]);
else
memcpy((void *)a1[3], a2, a3);
memcpy((void *)a1[2], (const void *)a1[3], a1[6]);
if ( a1[6] )
{
v4 = 0LL;
do
{
*(_BYTE *)(v4 + a1[3]) ^= 0x36u;
v5 = (_BYTE *)(v4 + a1[2]);
++v4;
*v5 ^= 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; // er12

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; // er12

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; // r12

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; // r12

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(_WORD *a1, __int64 a2, unsigned __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 v7; // rdx
__int64 v8; // rax
unsigned __int64 v9; // rcx
int v10; // esi
int v11; // er8

if ( !a2 || !a1 )
return meh_error("null reference passed to meh_reset_rc4", 4294967291LL, a3, a4, a5, a3);
v7 = a3 - 1;
v8 = 0LL;
if ( v7 > 0xFF )
return meh_error("invalid key size passed to meh_reset_rc4", 4294967288LL, v7, a4, a5, a3);
do
{
*((_BYTE *)a1 + v8 + 2) = v8;
++v8;
}
while ( v8 != 256 );
v9 = 0LL;
v10 = 0;
do
{
v11 = *((unsigned __int8 *)a1 + v9 + 2);
v10 += v11 + *(unsigned __int8 *)(a2 + v9 % a3);
*((_BYTE *)a1 + v9++ + 2) = *((_BYTE *)a1 + (unsigned __int8)v10 + 2);
*((_BYTE *)a1 + (unsigned __int8)v10 + 2) = v11;
}
while ( v9 != 256 );
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_WORD *a1, __int64 a2, unsigned __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 v7; // rdx
__int64 v8; // rax
unsigned __int64 v9; // rcx
int v10; // esi
int v11; // er8

if ( !a2 || !a1 )
return meh_error("null reference passed to meh_reset_rc4", 4294967291LL, a3, a4, a5, a3);
v7 = a3 - 1;
v8 = 0LL;
if ( v7 > 0xFF )
return meh_error("invalid key size passed to meh_reset_rc4", 4294967288LL, v7, a4, a5, a3);
do
{
*((_BYTE *)a1 + v8 + 2) = v8;
++v8;
}
while ( v8 != 256 );
v9 = 0LL;
v10 = 0;
do
{
v11 = *((unsigned __int8 *)a1 + v9 + 2);
v10 += v11 + *(unsigned __int8 *)(a2 + v9 % a3);
*((_BYTE *)a1 + v9++ + 2) = *((_BYTE *)a1 + (unsigned __int8)v10 + 2);
*((_BYTE *)a1 + (unsigned __int8)v10 + 2) = v11;
}
while ( v9 != 256 );
*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(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rdi
__int64 result; // rax

if ( !a1 )
return meh_error("invalid argument passed to meh_reset_hash", 4294967291LL);
v1 = *((unsigned int *)a1 + 2);
v2 = *a1;
switch ( v1 )
{
case 0LL:
meh_reset_md5(v2);
result = 0LL;
break;
case 1LL:
meh_reset_sha1(v2);
result = 0LL;
break;
case 2LL:
meh_reset_sha224(v2);
result = 0LL;
break;
case 3LL:
meh_reset_sha256(v2);
result = 0LL;
break;
case 4LL:
meh_reset_sha384(v2);
result = 0LL;
break;
case 5LL:
meh_reset_sha512(v2);
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(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // rdi
__int64 result; // rax

if ( !a1 )
return meh_error("invalid argument passed to meh_reset_hash", 4294967291LL);
v1 = *((unsigned int *)a1 + 2);
v2 = *a1;
switch ( v1 )
{
case 0LL:
meh_reset_md5(v2);
result = 0LL;
break;
case 1LL:
meh_reset_sha1(v2);
result = 0LL;
break;
case 2LL:
meh_reset_sha224(v2);
result = 0LL;
break;
case 3LL:
meh_reset_sha256(v2);
result = 0LL;
break;
case 4LL:
meh_reset_sha384(v2);
result = 0LL;
break;
case 5LL:
meh_reset_sha512(v2);
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(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rdi
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_update_hash", 4294967291LL);
if ( !a3 )
return 0LL;
v3 = *((unsigned int *)a1 + 2);
v4 = *a1;
switch ( v3 )
{
case 0LL:
meh_update_md5(v4);
goto LABEL_7;
case 1LL:
meh_update_sha1(v4);
goto LABEL_7;
case 2LL:
case 3LL:
meh_update_sha256(v4);
LABEL_7:
result = 0LL;
break;
case 4LL:
case 5LL:
meh_update_sha512(v4);
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(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rdi
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_update_hash", 4294967291LL);
if ( !a3 )
return 0LL;
v3 = *((unsigned int *)a1 + 2);
v4 = *a1;
switch ( v3 )
{
case 0LL:
meh_update_md5(v4);
goto LABEL_7;
case 1LL:
meh_update_sha1(v4);
goto LABEL_7;
case 2LL:
case 3LL:
meh_update_sha256(v4);
LABEL_7:
result = 0LL;
break;
case 4LL:
case 5LL:
meh_update_sha512(v4);
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 *


decompiled_code:
__int64 __fastcall meh_finish_hash(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_finish_hash", 4294967291LL);
v2 = *((unsigned int *)a1 + 2);
v3 = *a1;
switch ( v2 )
{
case 0LL:
meh_finish_md5(v3);
result = 0LL;
break;
case 1LL:
meh_finish_sha1(v3);
result = 0LL;
break;
case 2LL:
case 3LL:
meh_finish_sha256(v3);
result = 0LL;
break;
case 4LL:
case 5LL:
meh_finish_sha512(v3);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_finish_hash", 4294967286LL);
break;
}
return result;
}

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

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_finish_hash", 4294967291LL);
v2 = *((unsigned int *)a1 + 2);
v3 = *a1;
switch ( v2 )
{
case 0LL:
meh_finish_md5(v3);
result = 0LL;
break;
case 1LL:
meh_finish_sha1(v3);
result = 0LL;
break;
case 2LL:
case 3LL:
meh_finish_sha256(v3);
result = 0LL;
break;
case 4LL:
case 5LL:
meh_finish_sha512(v3);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_finish_hash", 4294967286LL);
break;
}
return result;
}

original_code:
meh_error_t meh_finish_hash(MehHash hash, unsigned char* output)
{
    if (((void *)0) == hash || ((void *)0) == output)
        return meh_error("invalid argument passed to meh_finish_hash",
                         MEH_INVALID_ARGUMENT);
    switch (hash->id)
    {
        case MEH_MD5: meh_finish_md5(hash->state.md5, output); break;
        case MEH_SHA1: meh_finish_sha1(hash->state.sha1, output); break;
        case MEH_SHA224: meh_finish_sha256((hash->state.sha224), (output)); break;
        case MEH_SHA256: meh_finish_sha256(hash->state.sha256, output); break;
        case MEH_SHA384: meh_finish_sha512((hash->state.sha384), (output)); break;
        case MEH_SHA512: meh_finish_sha512(hash->state.sha512, output); break;
        default:
            return meh_error("invalid hash id passed to meh_finish_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_finish_hash(struct meh_hash_s *hash, unsigned char *output)
{
    if (((void *)0) == hash || ((void *)0) == output)
        return meh_error("invalid argument passed to meh_finish_hash",
                         MEH_INVALID_ARGUMENT);
    switch (hash->id)
    {
        case MEH_MD5: meh_finish_md5(hash->state.md5, output); break;
        case MEH_SHA1: meh_finish_sha1(hash->state.sha1, output); break;
        case MEH_SHA224: meh_finish_sha256((hash->state.sha224), (output)); break;
        case MEH_SHA256: meh_finish_sha256(hash->state.sha256, output); break;
        case MEH_SHA384: meh_finish_sha512((hash->state.sha384), (output)); break;
        case MEH_SHA512: meh_finish_sha512(hash->state.sha512, output); break;
        default:
            return meh_error("invalid hash id passed to meh_finish_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

variable_types:
output
unsigned char *


decompiled_code:
void __fastcall meh_destroy_hash(void *ptr)
{
__int64 v2; // rax
void *v3; // rdi

if ( ptr )
{
v2 = *((unsigned int *)ptr + 2);
v3 = *(void **)ptr;
switch ( v2 )
{
case 0LL:
case 1LL:
case 2LL:
case 3LL:
case 4LL:
case 5LL:
free(v3);
free(ptr);
break;
default:
meh_warn("invalid hash id passed to meh_destroy_hash");
free(ptr);
break;
}
}
else
{
meh_warn("invalid argument passed to meh_destroy_hash");
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
__int64 v2; // rax
void *v3; // rdi

if ( ptr )
{
v2 = *((unsigned int *)ptr + 2);
v3 = *(void **)ptr;
switch ( v2 )
{
case 0LL:
case 1LL:
case 2LL:
case 3LL:
case 4LL:
case 5LL:
free(v3);
free(ptr);
break;
default:
meh_warn("invalid hash id passed to meh_destroy_hash");
free(ptr);
break;
}
}
else
{
meh_warn("invalid argument passed to meh_destroy_hash");
}
}

original_code:
void meh_destroy_hash(MehHash hash)
{
    if (((void *)0) == hash)
    {
        meh_warn("invalid argument passed to meh_destroy_hash");
        return;
    }
    switch (hash->id)
    {
        case MEH_MD5: free(hash->state.md5); break;
        case MEH_SHA1: free(hash->state.sha1); break;
        case MEH_SHA224: free(hash->state.sha224); break;
        case MEH_SHA256: free(hash->state.sha256); break;
        case MEH_SHA384: free(hash->state.sha384); break;
        case MEH_SHA512: free(hash->state.sha512); break;
        default:
            meh_warn("invalid hash id passed to meh_destroy_hash");
    }
    free(hash);
}

canonical_original_code:
void meh_destroy_hash(struct meh_hash_s *hash)
{
    if (((void *)0) == hash)
    {
        meh_warn("invalid argument passed to meh_destroy_hash");
        return;
    }
    switch (hash->id)
    {
        case MEH_MD5: free(hash->state.md5); break;
        case MEH_SHA1: free(hash->state.sha1); break;
        case MEH_SHA224: free(hash->state.sha224); break;
        case MEH_SHA256: free(hash->state.sha256); break;
        case MEH_SHA384: free(hash->state.sha384); break;
        case MEH_SHA512: free(hash->state.sha512); break;
        default:
            meh_warn("invalid hash id passed to meh_destroy_hash");
    }
    free(hash);
}


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

v1 = *(unsigned int *)(a1 + 8);
if ( (unsigned int)v1 > 5 )
result = (int)meh_error("invalid hash id passed to meh_hash_output_size", 0xFFFFFFFFLL);
else
result = CSWTCH_6[v1];
return result;
}

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

v1 = *(unsigned int *)(a1 + 8);
if ( (unsigned int)v1 > 5 )
result = (int)meh_error("invalid hash id passed to meh_hash_output_size", 0xFFFFFFFFLL);
else
result = CSWTCH_6[v1];
return result;
}

original_code:
size_t meh_hash_output_size(MehHash hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 16;
        case MEH_SHA1: return 20;
        case MEH_SHA224: return 28;
        case MEH_SHA256: return 32;
        case MEH_SHA384: return 48;
        case MEH_SHA512: return 64;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_output_size", -1);
    }
    return -1;
}

canonical_original_code:
unsigned long meh_hash_output_size(struct meh_hash_s *hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 16;
        case MEH_SHA1: return 20;
        case MEH_SHA224: return 28;
        case MEH_SHA256: return 32;
        case MEH_SHA384: return 48;
        case MEH_SHA512: return 64;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_output_size", -1);
    }
    return -1;
}


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

v1 = *(unsigned int *)(a1 + 8);
if ( (unsigned int)v1 > 5 )
result = (int)meh_error("invalid hash id passed to meh_hash_block_size", 0xFFFFFFFFLL);
else
result = CSWTCH_8[v1];
return result;
}

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

v1 = *(unsigned int *)(a1 + 8);
if ( (unsigned int)v1 > 5 )
result = (int)meh_error("invalid hash id passed to meh_hash_block_size", 0xFFFFFFFFLL);
else
result = CSWTCH_8[v1];
return result;
}

original_code:
size_t meh_hash_block_size(MehHash hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 64;
        case MEH_SHA1: return 64;
        case MEH_SHA224: return 64;
        case MEH_SHA256: return 64;
        case MEH_SHA384: return 128;
        case MEH_SHA512: return 128;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_block_size", -1);
    }
    return -1;
}

canonical_original_code:
unsigned long meh_hash_block_size(struct meh_hash_s *hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 64;
        case MEH_SHA1: return 64;
        case MEH_SHA224: return 64;
        case MEH_SHA256: return 64;
        case MEH_SHA384: return 128;
        case MEH_SHA512: return 128;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_block_size", -1);
    }
    return -1;
}


decompiled_code:
__int64 __fastcall meh_hash(int a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 *v6; // rax
__int64 *v7; // rbp
unsigned int v8; // er12

v6 = meh_get_hash(a1);
if ( !v6 )
return (unsigned int)-1;
v7 = v6;
v8 = meh_update_hash(v6, a2, a3);
if ( !v8 )
v8 = meh_finish_hash(v7, a4);
meh_destroy_hash(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 *v6; // rax
__int64 *v7; // rbp
unsigned int v8; // er12

v6 = meh_get_hash(a1);
if ( !v6 )
return (unsigned int)-1;
v7 = v6;
v8 = func1(v6, a2, a3);
if ( !v8 )
v8 = func2(v7, a4);
func3(v7);
return v8;
}

original_code:
meh_error_t meh_hash(meh_hash_id hash_id, const unsigned char* data,
                     size_t len, unsigned char* output)
{
    meh_error_t error;
    MehHash t;
    t = meh_get_hash(hash_id);
    if (((void *)0) == t)
        return MEH_ERROR;
    if ((error = meh_update_hash(t, data, len)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    if ((error = meh_finish_hash(t, output)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    meh_destroy_hash(t);
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_hash(enum meh_hash_id hash_id, unsigned char *data, unsigned long len, unsigned char *output)
{
    enum meh_error_t error;
    struct meh_hash_s *t;
    t = meh_get_hash(hash_id);
    if (((void *)0) == t)
        return MEH_ERROR;
    if ((error = meh_update_hash(t, data, len)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    if ((error = meh_finish_hash(t, output)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    meh_destroy_hash(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 }

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 }


original_code:
meh_error_t meh_reset_pbkdf2(MehPBKDF2 kdf,
                             const unsigned char* password, size_t pass_len,
                             const unsigned char* salt, size_t salt_len,
                             unsigned int iterations)
{
    if (((void *)0) == password || ((void *)0) == salt)
        return meh_error("invalid argument passed to meh_reset_pbkdf2",
                         MEH_INVALID_ARGUMENT);
    if (((void *)0) == kdf->password)
        kdf->password = malloc(pass_len);
    else if (kdf->pass_len < pass_len)
        kdf->password = realloc(kdf->password, pass_len);
    if (((void *)0) == kdf->password)
        return MEH_OUT_OF_MEMORY;
    kdf->pass_len = pass_len;
    memcpy(kdf->password, password, pass_len);
    if (((void *)0) == kdf->salt)
    {
        kdf->salt = malloc(salt_len);
        kdf->salt_len = salt_len;
    }
    else
        if (kdf->salt_len < salt_len)
            kdf->salt = realloc(kdf->salt, salt_len);
    if (((void *)0) == kdf->salt)
    {
        free(kdf->password);
        return MEH_OUT_OF_MEMORY;
    }
    memcpy(kdf->salt, salt, salt_len);
    kdf->iterations = iterations;
    kdf->index = kdf->hmac->output_size;
    memset(kdf->block_count, 0, sizeof (uint32_t));
    return meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
}

canonical_original_code:
enum meh_error_t meh_reset_pbkdf2(struct meh_pbkdf2_state_s *kdf, unsigned char *password, unsigned long pass_len, unsigned char *salt, unsigned long salt_len, unsigned int iterations)
{
    if (((void *)0) == password || ((void *)0) == salt)
        return meh_error("invalid argument passed to meh_reset_pbkdf2",
                         MEH_INVALID_ARGUMENT);
    if (((void *)0) == kdf->password)
        kdf->password = malloc(pass_len);
    else if (kdf->pass_len < pass_len)
        kdf->password = realloc(kdf->password, pass_len);
    if (((void *)0) == kdf->password)
        return MEH_OUT_OF_MEMORY;
    kdf->pass_len = pass_len;
    memcpy(kdf->password, password, pass_len);
    if (((void *)0) == kdf->salt)
    {
        kdf->salt = malloc(salt_len);
        kdf->salt_len = salt_len;
    }
    else
        if (kdf->salt_len < salt_len)
            kdf->salt = realloc(kdf->salt, salt_len);
    if (((void *)0) == kdf->salt)
    {
        free(kdf->password);
        return MEH_OUT_OF_MEMORY;
    }
    memcpy(kdf->salt, salt, salt_len);
    kdf->iterations = iterations;
    kdf->index = kdf->hmac->output_size;
    memset(kdf->block_count, 0, sizeof (unsigned int));
    return meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
}

variable_types: struct meh_pbkdf2_state_s { 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; } *hmac; unsigned char *salt; unsigned long salt_len; unsigned char *buffer; unsigned char block_count[4]; int iterations; } *

variable_types:
password
unsigned char *

variable_types:
salt
unsigned char *

variable_types:
iterations
unsigned int

user_defined_types: struct meh_pbkdf2_state_s { struct meh_hmac_s *hmac; unsigned char *salt; unsigned long salt_len; unsigned char *buffer; unsigned char block_count[4]; int iterations; }


original_code:
meh_error_t meh_update_pbkdf2(MehPBKDF2 kdf, unsigned char* output,
                              size_t want_len, size_t* get_len)
{
    meh_error_t error;
    int i, j, k;
    *get_len = 0;
    error = MEH_OK;
    for (i = 0; i < want_len; i++)
    {
        if (kdf->index == kdf->hmac->output_size)
        {
            _increment_counter(kdf->block_count, sizeof (uint32_t));
            if (0 == (((uint32_t)((kdf->block_count)[(0)]) << 24) | ((uint32_t)((kdf->block_count)[(0)+1]) << 16) | ((uint32_t)((kdf->block_count)[(0)+2]) << 8) | ((uint32_t)((kdf->block_count)[(0)+3]) )))
            {
                memset(kdf->block_count, 0xff, sizeof (uint32_t));
                return meh_error("source exhausted in meh_update_pbkdf2",
                                 MEH_SOURCE_EXHAUSTED);
            }
            memset(kdf->buffer, 0, kdf->hmac->output_size);
            for (j = 0; j < kdf->iterations; j++)
            {
                error = meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
                if (0 != j)
                    error = meh_update_hmac(kdf->hmac, kdf->tmp, kdf->hmac->output_size);
                else
                {
                    error = meh_update_hmac(kdf->hmac, kdf->salt, kdf->salt_len);
                    error = meh_update_hmac(kdf->hmac,
                                            kdf->block_count, sizeof (uint32_t));
                }
                error = meh_finish_hmac(kdf->hmac, kdf->tmp);
                for (k = 0; k < kdf->hmac->output_size; k++)
                    kdf->buffer[k] ^= kdf->tmp[k];
            }
            kdf->index = 0;
        }
        output[i] = kdf->buffer[kdf->index++];
        (*get_len)++;
    }
    return error;
}

canonical_original_code:
enum meh_error_t meh_update_pbkdf2(struct meh_pbkdf2_state_s *kdf, unsigned char *output, unsigned long want_len, unsigned long *get_len)
{
    enum meh_error_t error;
    int i; int j; int k;
    *get_len = 0;
    error = MEH_OK;
    for (i = 0; i < want_len; i++)
    {
        if (kdf->index == kdf->hmac->output_size)
        {
            _increment_counter(kdf->block_count, sizeof (unsigned int));
            if (0 == (((unsigned int)((kdf->block_count)[(0)]) << 24) | ((unsigned int)((kdf->block_count)[(0)+1]) << 16) | ((unsigned int)((kdf->block_count)[(0)+2]) << 8) | ((unsigned int)((kdf->block_count)[(0)+3]) )))
            {
                memset(kdf->block_count, 0xff, sizeof (unsigned int));
                return meh_error("source exhausted in meh_update_pbkdf2",
                                 MEH_SOURCE_EXHAUSTED);
            }
            memset(kdf->buffer, 0, kdf->hmac->output_size);
            for (j = 0; j < kdf->iterations; j++)
            {
                error = meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
                if (0 != j)
                    error = meh_update_hmac(kdf->hmac, kdf->tmp, kdf->hmac->output_size);
                else
                {
                    error = meh_update_hmac(kdf->hmac, kdf->salt, kdf->salt_len);
                    error = meh_update_hmac(kdf->hmac,
                                            kdf->block_count, sizeof (unsigned int));
                }
                error = meh_finish_hmac(kdf->hmac, kdf->tmp);
                for (k = 0; k < kdf->hmac->output_size; k++)
                    kdf->buffer[k] ^= kdf->tmp[k];
            }
            kdf->index = 0;
        }
        output[i] = kdf->buffer[kdf->index++];
        (*get_len)++;
    }
    return error;
}

variable_types: i int

variable_types: j int

variable_types: k int


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

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

original_code:
void meh_destroy_pbkdf2(MehPBKDF2 kdf)
{
    if (((void *)0) == kdf)
    {
        meh_warn("invalid argument passed to meh_destroy_pbkdf2");
        return;
    }
    meh_destroy_hmac(kdf->hmac);
    free(kdf->salt);
    free(kdf->password);
    free(kdf->buffer);
    free(kdf->tmp);
    free(kdf);
}

canonical_original_code:
void meh_destroy_pbkdf2(struct meh_pbkdf2_state_s *kdf)
{
    if (((void *)0) == kdf)
    {
        meh_warn("invalid argument passed to meh_destroy_pbkdf2");
        return;
    }
    meh_destroy_hmac(kdf->hmac);
    free(kdf->salt);
    free(kdf->password);
    free(kdf->buffer);
    free(kdf->tmp);
    free(kdf);
}


decompiled_code:
int __fastcall meh_warn(const char *a1)
{
return fprintf(stderr, "libmeh: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "libmeh: %s\n", a1);
}

original_code:
void meh_warn(const char* msg)
{
    fprintf(stderr, "libmeh: %s\n", msg);
}

canonical_original_code:
void meh_warn(char *msg)
{
    fprintf(stderr, "libmeh: %s\n", msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall meh_error(const char *a1, unsigned int a2)
{
meh_warn(a1);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2)
{
func0(a1);
return a2;
}

original_code:
meh_error_t meh_error(const char* msg, meh_error_t error)
{
    meh_warn(msg);
    return error;
}

canonical_original_code:
enum meh_error_t meh_error(char *msg, enum meh_error_t error)
{
    meh_warn(msg);
    return error;
}


shift

repo: thommey/plservices

decompiled_code:
void *__fastcall shift(unsigned __int8 *a1, int a2)
{
unsigned __int8 v2; // dl
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = a2 + *a1;
*a1 = v2;
if ( a2 > 0 )
return memmove(&a1[16 * a2 + 8], a1 + 8, 16LL * v2);
if ( a2 )
return memmove(a1 + 8, &a1[-16 * a2 + 8], 16LL * v2);
return (void *)(v4 - __readfsqword(0x28u));
}

canonical_decompiled_code:
void *__fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 v2; // dl
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = a2 + *a1;
*a1 = v2;
if ( a2 > 0 )
return memmove(&a1[16 * a2 + 8], a1 + 8, 16LL * v2);
if ( a2 )
return memmove(a1 + 8, &a1[-16 * a2 + 8], 16LL * v2);
return (void *)(v4 - __readfsqword(0x28u));
}

original_code:
void shift(struct args *arg, int offset) {
 arg->c += offset;
 if (offset > 0)
  memmove(arg->v + offset, arg->v, arg->c * sizeof(*arg->v));
 else if (offset < 0) {
  offset = -offset;
  memmove(arg->v, arg->v + offset, arg->c * sizeof(*arg->v));
 }
}

variable_types: struct args { unsigned char c; struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } v[20]; } *

variable_types: offset int

user_defined_types: struct args { unsigned char c; struct funcarg v[20]; }

user_defined_types: struct funcarg { enum argtype type; union argdata data; }


decompiled_code:
__int64 arg_int()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
struct funcarg arg_int(int i) {
 return (struct funcarg) {
  .type = ARGTYPE_INT, .data.i = i
 };
}

return_type: struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; }


decompiled_code:
__int64 arg_uint()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 2LL;
}

original_code:
struct funcarg arg_uint(unsigned int u) {
 return (struct funcarg) {
  .type = ARGTYPE_UINT, .data.u = u
 };
}

variable_types:
u
unsigned int

user_defined_types: enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 }

user_defined_types: union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; }


decompiled_code:
__int64 arg_long()
{
return 3LL;
}

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

original_code:
struct funcarg arg_long(long l) {
 return (struct funcarg) {
  .type = ARGTYPE_LONG, .data.l = l
 };
}

variable_types: l long


decompiled_code:
__int64 arg_ulong()
{
return 4LL;
}

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

original_code:
struct funcarg arg_ulong(unsigned long ul) {
 return (struct funcarg) {
  .type = ARGTYPE_ULONG, .data.ul = ul
 };
}

variable_types:
ul
unsigned long


decompiled_code:
__int64 arg_time()
{
return 5LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 5LL;
}

original_code:
struct funcarg arg_time(time_t t) {
 return (struct funcarg) {
  .type = ARGTYPE_TIME, .data.t = t
 };
}

canonical_original_code:
struct funcarg arg_time(long t) {
 return (struct funcarg) {
  .type = ARGTYPE_TIME, .data.t = t
 };
}

variable_types: t long


decompiled_code:
__int64 arg_str()
{
return 9LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 9LL;
}

original_code:
struct funcarg arg_str(char *s) {
 return (struct funcarg) {
  .type = ARGTYPE_STR, .data.p = s
 };
}

variable_types:
s
char *


decompiled_code:
__int64 arg_ptr()
{
return 10LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 10LL;
}

original_code:
struct funcarg arg_ptr(void *p) {
 return (struct funcarg) {
  .type = ARGTYPE_PTR, .data.p = p
 };
}

variable_types:
p
void *


decompiled_code:
void *__fastcall pack_empty(void *a1)
{
memset(a1, 0, 0x148uLL);
return a1;
}

canonical_decompiled_code:
void *__fastcall func12(void *a1)
{
memset(a1, 0, 0x148uLL);
return a1;
}

original_code:
struct args pack_empty(void) {
 return (struct args) {
  .c = 0
 };
}

canonical_original_code:
struct args pack_empty() {
 return (struct args) {
  .c = 0
 };
}

return_type: struct args { unsigned char c; struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } v[20]; }


decompiled_code:
__int64 __fastcall argdata_int(_DWORD *a1)
{
if ( *a1 != 1 )
_assert_fail("a->type == ARGTYPE_INT", "src/args.c", 0x90u, "argdata_int");
return (unsigned int)a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1)
{
if ( *a1 != 1 )
_assert_fail("a->type == ARGTYPE_INT", "src/args.c", 0x90u, "argdata_int");
return (unsigned int)a1[2];
}

original_code:
int argdata_int(struct funcarg *a) {
 ((a->type == ARGTYPE_INT) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_INT", "src/args.c", 144, __extension__ __PRETTY_FUNCTION__));
 return a->data.i;
}

variable_types: struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } *


decompiled_code:
__int64 __fastcall argdata_uint(_DWORD *a1)
{
if ( *a1 != 2 )
_assert_fail("a->type == ARGTYPE_UINT", "src/args.c", 0x95u, "argdata_uint");
return (unsigned int)a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1)
{
if ( *a1 != 2 )
_assert_fail("a->type == ARGTYPE_UINT", "src/args.c", 0x95u, "argdata_uint");
return (unsigned int)a1[2];
}

original_code:
unsigned int argdata_uint(struct funcarg *a) {
 ((a->type == ARGTYPE_UINT) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_UINT", "src/args.c", 149, __extension__ __PRETTY_FUNCTION__));
 return a->data.u;
}


decompiled_code:
__int64 __fastcall argdata_long(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
_assert_fail("a->type == ARGTYPE_LONG", "src/args.c", 0x9Au, "argdata_long");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
_assert_fail("a->type == ARGTYPE_LONG", "src/args.c", 0x9Au, "argdata_long");
return *(_QWORD *)(a1 + 8);
}

original_code:
long argdata_long(struct funcarg *a) {
 ((a->type == ARGTYPE_LONG) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_LONG", "src/args.c", 154, __extension__ __PRETTY_FUNCTION__));
 return a->data.l;
}

return_type: long


decompiled_code:
__int64 __fastcall argdata_time(__int64 a1)
{
if ( *(_DWORD *)a1 != 5 )
_assert_fail("a->type == ARGTYPE_TIME", "src/args.c", 0x9Fu, "argdata_time");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
if ( *(_DWORD *)a1 != 5 )
_assert_fail("a->type == ARGTYPE_TIME", "src/args.c", 0x9Fu, "argdata_time");
return *(_QWORD *)(a1 + 8);
}

original_code:
time_t argdata_time(struct funcarg *a) {
 ((a->type == ARGTYPE_TIME) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_TIME", "src/args.c", 159, __extension__ __PRETTY_FUNCTION__));
 return a->data.t;
}

canonical_original_code:
long argdata_time(struct funcarg *a) {
 ((a->type == ARGTYPE_TIME) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_TIME", "src/args.c", 159, __extension__ __PRETTY_FUNCTION__));
 return a->data.t;
}


decompiled_code:
__int64 __fastcall argdata_str(__int64 a1)
{
if ( *(_DWORD *)a1 != 9 )
_assert_fail("a->type == ARGTYPE_STR", "src/args.c", 0xB3u, "argdata_str");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
if ( *(_DWORD *)a1 != 9 )
_assert_fail("a->type == ARGTYPE_STR", "src/args.c", 0xB3u, "argdata_str");
return *(_QWORD *)(a1 + 8);
}

original_code:
char *argdata_str(struct funcarg *a) {
 ((a->type == ARGTYPE_STR) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_STR", "src/args.c", 179, __extension__ __PRETTY_FUNCTION__));
 return a->data.p;
}

return_type: char *


decompiled_code:
__int64 __fastcall argdata_ptr(__int64 a1)
{
if ( *(_DWORD *)a1 != 10 )
_assert_fail("a->type == ARGTYPE_PTR", "src/args.c", 0xB8u, "argdata_ptr");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
if ( *(_DWORD *)a1 != 10 )
_assert_fail("a->type == ARGTYPE_PTR", "src/args.c", 0xB8u, "argdata_ptr");
return *(_QWORD *)(a1 + 8);
}

original_code:
void *argdata_ptr(struct funcarg *a) {
 ((a->type == ARGTYPE_PTR) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_PTR", "src/args.c", 184, __extension__ __PRETTY_FUNCTION__));
 return a->data.p;
}

return_type: void *


decompiled_code:
unsigned __int64 __fastcall convert_nick(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_nick(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_nick(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_nick(struct funcarg *a, char *str) {
 a->data.p = get_user_by_nick(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}

variable_types:
str
char *


decompiled_code:
unsigned __int64 __fastcall convert_unum(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_unum(struct funcarg *a, char *str) {
 a->data.p = get_user_by_numericstr(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}


decompiled_code:
unsigned __int64 __fastcall convert_snum(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_server_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_server_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_snum(struct funcarg *a, char *str) {
 a->data.p = get_server_by_numericstr(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}


decompiled_code:
unsigned __int64 __fastcall convert_num(__int64 a1, const char *a2)
{
size_t v2; // rax
int v3; // eax
__int64 v5; // rax
unsigned __int64 v6; // [rsp+8h] [rbp-20h]

v6 = __readfsqword(0x28u);
v2 = strlen(a2);
if ( v2 == 2 )
{
v5 = get_server_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v5;
LABEL_6:
v3 = v5 != 0 ? 0xA : 0;
goto LABEL_4;
}
if ( v2 == 5 )
{
v5 = get_user_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v5;
goto LABEL_6;
}
*(_QWORD *)(a1 + 8) = 0LL;
v3 = 0;
LABEL_4:
*(_DWORD *)a1 = v3;
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, const char *a2)
{
size_t v2; // rax
int v3; // eax
__int64 v5; // rax
unsigned __int64 v6; // [rsp+8h] [rbp-20h]

v6 = __readfsqword(0x28u);
v2 = strlen(a2);
if ( v2 == 2 )
{
v5 = get_server_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v5;
LABEL_6:
v3 = v5 != 0 ? 0xA : 0;
goto LABEL_4;
}
if ( v2 == 5 )
{
v5 = get_user_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v5;
goto LABEL_6;
}
*(_QWORD *)(a1 + 8) = 0LL;
v3 = 0;
LABEL_4:
*(_DWORD *)a1 = v3;
return v6 - __readfsqword(0x28u);
}

original_code:
void convert_num(struct funcarg *a, char *str) {
 if (strlen(str) == 2)
  a->data.p = get_server_by_numericstr(str);
 else if (strlen(str) == 5)
  a->data.p = get_user_by_numericstr(str);
 else
  a->data.p = ((void *)0);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}


decompiled_code:
unsigned __int64 __fastcall convert_chan(__int64 a1, _BYTE *a2)
{
__int64 v2; // rax
int v3; // eax
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
if ( *a2 != 48 || a2[1] )
{
v2 = get_channel_by_name(a2);
*(_QWORD *)(a1 + 8) = v2;
v3 = v2 != 0 ? 0xA : 0;
}
else
{
*(_QWORD *)(a1 + 8) = &chan0_0;
v3 = 10;
}
*(_DWORD *)a1 = v3;
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, _BYTE *a2)
{
__int64 v2; // rax
int v3; // eax
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
if ( *a2 != 48 || a2[1] )
{
v2 = get_channel_by_name(a2);
*(_QWORD *)(a1 + 8) = v2;
v3 = v2 != 0 ? 0xA : 0;
}
else
{
*(_QWORD *)(a1 + 8) = &chan0_0;
v3 = 10;
}
*(_DWORD *)a1 = v3;
return v5 - __readfsqword(0x28u);
}

original_code:
void convert_chan(struct funcarg *a, char *str) {
 static struct channel chan0 = { 0x38B7 };
 a->data.p = !strcmp(str, "0") ? &chan0 : get_channel_by_name(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}

variable_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP { void *t; } ops; struct jtableS { void *t; } bans; }

user_defined_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP ops; struct jtableS bans; }


decompiled_code:
unsigned __int64 __fastcall convert_uint(_DWORD *a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*a1 = 0;
if ( *a2 )
{
a1[2] = strtoul(a2, &v3, 10);
if ( !*v3 )
*a1 = 2;
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_DWORD *a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*a1 = 0;
if ( *a2 )
{
a1[2] = strtoul(a2, &v3, 10);
if ( !*v3 )
*a1 = 2;
}
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_uint(struct funcarg *a, char *str) {
 char *endptr;
 a->type = ARGTYPE_NONE;
 if (!str[0])
  return;
 a->data.u = (unsigned int)strtoul(str, &endptr, 10);
 if (*endptr != '\0')
  return;
 a->type = ARGTYPE_UINT;
}

variable_types:
endptr
char *


decompiled_code:
unsigned __int64 __fastcall convert_long(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtol(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 3;
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtol(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 3;
}
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_long(struct funcarg *a, char *str) {
 char *endptr;
 a->type = ARGTYPE_NONE;
 if (!str[0])
  return;
 a->data.l = strtol(str, &endptr, 10);
 if (*endptr != '\0')
  return;
 a->type = ARGTYPE_LONG;
}


decompiled_code:
unsigned __int64 __fastcall convert_time(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtoull(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 5;
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtoull(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 5;
}
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_time(struct funcarg *a, char *str) {
 char *endptr;
 a->type = ARGTYPE_NONE;
 if (!str[0])
  return;
 a->data.t = strtoull(str, &endptr, 10);
 if (*endptr != '\0')
  return;
 a->type = ARGTYPE_TIME;
}


decompiled_code:
__int64 __fastcall print_key_value(const char *a1, const char *a2)
{
return logfmt(0x4000LL, "%s = %s\n", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
return logfmt(0x4000LL, "%s = %s\n", a1, a2);
}

original_code:
static void print_key_value(char *key, char *value, char *section) {
 logfmt(0x4000, "%s = %s" "\n", key, value);
}

variable_types:
key
char *

variable_types:
value
char *

variable_types:
section
char *


skip

decompiled_code:
unsigned __int64 __fastcall skip(const char **a1, const char *a2)
{
const char *v2; // rbx
unsigned __int64 v4; // [rsp+8h] [rbp-20h]

v4 = __readfsqword(0x28u);
if ( *a1 )
{
v2 = *a1;
*a1 = &v2[strspn(v2, a2)];
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(const char **a1, const char *a2)
{
const char *v2; // rbx
unsigned __int64 v4; // [rsp+8h] [rbp-20h]

v4 = __readfsqword(0x28u);
if ( *a1 )
{
v2 = *a1;
*a1 = &v2[strspn(v2, a2)];
}
return v4 - __readfsqword(0x28u);
}

original_code:
static void skip(char **str, char *delim) {
 if (!*str)
  return;
 *str += strspn(*str, delim);
}

variable_types:
str
char **

variable_types:
delim
char *