decompiled_code:
__int64 get_password()
{
int v0; // eax
int v1; // ebx
__int64 v2; // rbp
__int64 result; // rax
char buf; // [rsp+Fh] [rbp-59h] BYREF
char v5[88]; // [rsp+10h] [rbp-58h] BYREF

buf = 0;
v0 = open("/home/tesian/Prog/kikoo/lock/.password", 0);
if ( v0 == -1 )
return 0LL;
v1 = v0;
v2 = -1LL;
while ( read(v1, &buf, 1uLL) == 1 && buf != 10 )
{
if ( (int)v2 <= 61 )
v5[++v2] = buf;
}
v5[(int)v2 + 1] = 0;
if ( close(v1) == -1 )
result = 0LL;
else
result = my_strdup(v5);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v1; // ebx
__int64 v2; // rbp
__int64 result; // rax
char buf; // [rsp+Fh] [rbp-59h] BYREF
char v5[88]; // [rsp+10h] [rbp-58h] BYREF

buf = 0;
v0 = open("/home/tesian/Prog/kikoo/lock/.password", 0);
if ( v0 == -1 )
return 0LL;
v1 = v0;
v2 = -1LL;
while ( read(v1, &buf, 1uLL) == 1 && buf != 10 )
{
if ( (int)v2 <= 61 )
v5[++v2] = buf;
}
v5[(int)v2 + 1] = 0;
if ( close(v1) == -1 )
result = 0LL;
else
result = my_strdup(v5);
return result;
}

original_code:
char *get_password()
{
  int fd;
  char str[64];
  char c = '\0';
  int i = -1;
  if ((fd = open("/home/tesian/Prog/kikoo/lock/.password", 00)) == -1)
    return (((void *)0));
  while (read(fd, &c, 1) == 1 && c != '\n')
    if (i < 62)
      str[++i] = c;
  str[++i] = '\0';
  if (close(fd) == -1)
    return (((void *)0));
  return (my_strdup(str));
}

variable_types: fd int

variable_types:
str
char [64]

variable_types: c char

variable_types: i int


repo: Tesian/lock

decompiled_code:
char *__fastcall my_crypt(char *a1)
{
char v1; // al
char *v2; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
*v2++ = v1 ^ 0x15;
v1 = *v2;
}
while ( *v2 );
}
else
{
v2 = a1;
}
*v2 = 0;
return a1;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
char v1; // al
char *v2; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
*v2++ = v1 ^ 0x15;
v1 = *v2;
}
while ( *v2 );
}
else
{
v2 = a1;
}
*v2 = 0;
return a1;
}

original_code:
char *my_crypt(char *password)
{
  int i = -1;
  while (password[++i])
    password[i] = password[i] ^ 21;
  password[i] = '\0';
  return (password);
}

variable_types:
password
char *

return_type: char *


decompiled_code:
__int64 __fastcall make_password(char *a1)
{
unsigned int v1; // ebx
char *v2; // rbp
int v3; // eax

v1 = open("/home/tesian/Prog/kikoo/lock/.password", 577, 420LL);
if ( v1 == -1 )
{
my_putstr_error(&unk_178);
}
else
{
v2 = my_crypt(a1);
v3 = my_strlen(v2);
write(v1, v2, v3);
write(v1, &unk_1B1, 1uLL);
v1 = close(v1);
if ( v1 != -1 )
{
my_putstr("Change password done.\n");
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
unsigned int v1; // ebx
char *v2; // rbp
int v3; // eax

v1 = open("/home/tesian/Prog/kikoo/lock/.password", 577, 420LL);
if ( v1 == -1 )
{
my_putstr_error(&unk_178);
}
else
{
v2 = func1(a1);
v3 = my_strlen(v2);
write(v1, v2, v3);
write(v1, &unk_1B1, 1uLL);
v1 = close(v1);
if ( v1 != -1 )
{
my_putstr("Change password done.\n");
v1 = 0;
}
}
return v1;
}

original_code:
int make_password(char *password)
{
  int fd;
  char *encrypt_password;
  if ((fd = open("/home/tesian/Prog/kikoo/lock/.password", 0100 | 01000 | 01,
   0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3))) == -1)
    {
      my_putstr_error("Une erreur a empêché la modification du mot de passe.\n");
      return (-1);
    }
  encrypt_password = my_crypt(password);
  write(fd, encrypt_password, my_strlen(encrypt_password));
  write(fd, "\n", 1);
  if (close(fd) == -1)
    return (-1);
  my_putstr("Change password done.\n");
  return (0);
}

return_type: int


decompiled_code:
__int64 __fastcall my_pars_sort(_QWORD *a1)
{
while ( 1 )
{
if ( !*a1 )
return 0LL;
if ( !(unsigned int)my_strcmp("-t.rand") )
return 1LL;
if ( !(unsigned int)my_strcmp("-t.alpha") )
break;
++a1;
if ( !(unsigned int)my_strcmp("-t.numeric") )
return 3LL;
}
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
while ( 1 )
{
if ( !*a1 )
return 0LL;
if ( !(unsigned int)my_strcmp("-t.rand") )
return 1LL;
if ( !(unsigned int)my_strcmp("-t.alpha") )
break;
++a1;
if ( !(unsigned int)my_strcmp("-t.numeric") )
return 3LL;
}
return 2LL;
}

original_code:
char my_pars_sort(char **av)
{
  int i = -1;
  while (av[++i])
    if (my_strcmp("-t.rand", av[i]) == 0)
      return (1);
    else if (my_strcmp("-t.alpha", av[i]) == 0)
      return (2);
    else if (my_strcmp("-t.numeric", av[i]) == 0)
      return (3);
  return (0);
}

variable_types:
av
char **

return_type: char


decompiled_code:
__int64 __fastcall my_manage_sort(__int64 a1)
{
return a1;
}

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

original_code:
t_list *my_manage_sort(t_list *list, char sort)
{
  return (list);
}

canonical_original_code:
struct s_list *my_manage_sort(struct s_list *list, char sort)
{
  return (list);
}

variable_types:
list
struct s_list *

variable_types: sort char

return_type: struct s_list { char *str; struct s_list *next; } *


original_code:
int my_check_is_bmp(char *filename)
{
  int strlen = my_strlen(filename);
  if (filename[strlen - 4] == '.' &&
      filename[strlen - 3] == 'b' &&
      filename[strlen - 2] == 'm' &&
      filename[strlen - 1] == 'p')
    return (1);
  return (0);
}

variable_types:
filename
char *

variable_types: strlen int


repo: Tethik/arp-failover

decompiled_code:
void *__fastcall allocate_strmem(int a1)
{
void *v1; // rax

if ( a1 <= 0 )
{
fprintf(_bss_start, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", (unsigned int)a1);
exit(1);
}
v1 = malloc(a1);
if ( !v1 )
{
fwrite("ERROR: Cannot allocate memory for array allocate_strmem().\n", 1uLL, 0x3BuLL, _bss_start);
exit(1);
}
return memset(v1, 0, a1);
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
void *v1; // rax

if ( a1 <= 0 )
{
fprintf(_bss_start, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", (unsigned int)a1);
exit(1);
}
v1 = malloc(a1);
if ( !v1 )
{
fwrite("ERROR: Cannot allocate memory for array allocate_strmem().\n", 1uLL, 0x3BuLL, _bss_start);
exit(1);
}
return memset(v1, 0, a1);
}

original_code:
char * allocate_strmem (int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", len);
    exit (1);
  }
  tmp = (char *) malloc (len * sizeof (char));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (char));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_strmem().\n");
    exit (1);
  }
}

canonical_original_code:
char *allocate_strmem(int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", len);
    exit (1);
  }
  tmp = (char *) malloc (len * sizeof (char));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (char));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_strmem().\n");
    exit (1);
  }
}

variable_types: len int

variable_types:
tmp
void *


decompiled_code:
void *__fastcall allocate_ustrmem(int a1)
{
void *v1; // rax

if ( a1 <= 0 )
{
fprintf(_bss_start, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", (unsigned int)a1);
exit(1);
}
v1 = malloc(a1);
if ( !v1 )
{
fwrite("ERROR: Cannot allocate memory for array allocate_ustrmem().\n", 1uLL, 0x3CuLL, _bss_start);
exit(1);
}
return memset(v1, 0, a1);
}

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

if ( a1 <= 0 )
{
fprintf(_bss_start, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", (unsigned int)a1);
exit(1);
}
v1 = malloc(a1);
if ( !v1 )
{
fwrite("ERROR: Cannot allocate memory for array allocate_ustrmem().\n", 1uLL, 0x3CuLL, _bss_start);
exit(1);
}
return memset(v1, 0, a1);
}

original_code:
uint8_t * allocate_ustrmem (int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", len);
    exit (1);
  }
  tmp = (uint8_t *) malloc (len * sizeof (uint8_t));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (uint8_t));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_ustrmem().\n");
    exit (1);
  }
}

canonical_original_code:
unsigned char *allocate_ustrmem(int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", len);
    exit (1);
  }
  tmp = (unsigned char *) malloc (len * sizeof (unsigned char));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (unsigned char));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_ustrmem().\n");
    exit (1);
  }
}

return_type: unsigned char *


printDirectory

decompiled_code:
int printDirectory()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

getcwd(v1, 0xC8uLL);
return printf("Current Directory: %s\n", v1);
}

canonical_decompiled_code:
int func7()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

getcwd(v1, 0xC8uLL);
return printf("Current Directory: %s\n", v1);
}

original_code:
void printDirectory() {
    char s[256];
    getcwd(s, 200);
    printf("Current Directory: %s\n", s);
}

variable_types:
s
char [256]

return_type: void


printTime

decompiled_code:
int printTime()
{
char *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
return printf("Current time: %s\n", v0);
}

canonical_decompiled_code:
int func8()
{
char *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
return printf("Current time: %s\n", v0);
}

original_code:
void printTime() {
    time_t t;
    t = time(((void *)0));
    printf( "Current time: %s\n", ctime( &t ));
}

canonical_original_code:
void printTime() {
    long t;
    t = time(((void *)0));
    printf( "Current time: %s\n", ctime( &t ));
}

variable_types: t long


freeMem

decompiled_code:
void __fastcall freeMem(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void freeMem(char **files, int size) {
    int i;
    for (i = 0; i < size; i++) {
        free(files[i]);
    }
    free(files);
}

variable_types:
files
char **

variable_types: size int


printMenu

decompiled_code:
void printMenu()
{
const char **v0; // r12
const char **v1; // r13
int i; // ebx
int v3; // ebp
char v4; // r15
int v5; // eax
int j; // ebx
int v7; // ebp
char v8; // r15
int v9; // eax
int v10; // [rsp+8h] [rbp-40h] BYREF
int v11[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v10 = 0;
printDirectory();
printTime();
v0 = (const char **)getFilesInDir(8, v11);
v1 = (const char **)getFilesInDir(4, &v10);
if ( v10 + v11[0] > 1024 )
{
printf(
"ERROR! Number of files and directories in the\ncurrent directory exceed the max of %d.\n\nExiting program...\n\n",
1024LL);
exit(1);
}
if ( v11[0] )
{
puts("\n====================================\n Files\n====================================");
if ( v11[0] > 0 )
{
printf("%d. %s\n", 0LL, *v0);
for ( i = 1; v11[0] > i; i = v3 )
{
printf("%d. %s\n", (unsigned int)i, v0[i]);
v3 = i + 1;
if ( v3 == 10 * (v3 / 10) )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v4 = getchar();
do
v5 = getchar();
while ( v4 != -1 && v5 != 10 );
if ( v4 == 112 )
{
v3 = i - 19;
if ( i - 19 < 0 )
v3 = 0;
}
else if ( v4 == 115 )
{
break;
}
}
}
}
}
else
{
puts("Files: There is no file in current directory.");
}
printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
while ( getchar() != 10 )
;
if ( v10 )
{
puts("\n====================================\n Directories\n====================================");
if ( v10 > 0 )
{
printf("%d. %s\n", 0LL, *v1);
for ( j = 1; j < v10; j = v7 )
{
printf("%d. %s\n", (unsigned int)j, v1[j]);
v7 = j + 1;
if ( v7 == 10 * (v7 / 10) )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v8 = getchar();
do
v9 = getchar();
while ( v8 != -1 && v9 != 10 );
if ( v8 == 112 )
{
v7 = j - 19;
if ( j - 19 < 0 )
v7 = 0;
}
else if ( v8 == 115 )
{
break;
}
}
}
}
}
else
{
printf("\nDirectory: There is no sub-directory in current directory.");
}
puts("------------------------------------");
puts(
"\n"
"Operation: 'e' Edit\n"
" 'r' Run\n"
" 'c' Change directory\n"
" 'p' Print directory\n"
" 'q' Quit\n");
puts("------------------------------------");
freeMem(v0, v11[0]);
freeMem(v1, v10);
}

canonical_decompiled_code:
void func11()
{
const char **v0; // r12
const char **v1; // r13
int i; // ebx
int v3; // ebp
char v4; // r15
int v5; // eax
int j; // ebx
int v7; // ebp
char v8; // r15
int v9; // eax
int v10; // [rsp+8h] [rbp-40h] BYREF
int v11[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v10 = 0;
func7();
func8();
v0 = (const char **)func10(8, v11);
v1 = (const char **)func10(4, &v10);
if ( v10 + v11[0] > 1024 )
{
printf(
"ERROR! Number of files and directories in the\ncurrent directory exceed the max of %d.\n\nExiting program...\n\n",
1024LL);
exit(1);
}
if ( v11[0] )
{
puts("\n====================================\n Files\n====================================");
if ( v11[0] > 0 )
{
printf("%d. %s\n", 0LL, *v0);
for ( i = 1; v11[0] > i; i = v3 )
{
printf("%d. %s\n", (unsigned int)i, v0[i]);
v3 = i + 1;
if ( v3 == 10 * (v3 / 10) )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v4 = getchar();
do
v5 = getchar();
while ( v4 != -1 && v5 != 10 );
if ( v4 == 112 )
{
v3 = i - 19;
if ( i - 19 < 0 )
v3 = 0;
}
else if ( v4 == 115 )
{
break;
}
}
}
}
}
else
{
puts("Files: There is no file in current directory.");
}
printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
while ( getchar() != 10 )
;
if ( v10 )
{
puts("\n====================================\n Directories\n====================================");
if ( v10 > 0 )
{
printf("%d. %s\n", 0LL, *v1);
for ( j = 1; j < v10; j = v7 )
{
printf("%d. %s\n", (unsigned int)j, v1[j]);
v7 = j + 1;
if ( v7 == 10 * (v7 / 10) )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v8 = getchar();
do
v9 = getchar();
while ( v8 != -1 && v9 != 10 );
if ( v8 == 112 )
{
v7 = j - 19;
if ( j - 19 < 0 )
v7 = 0;
}
else if ( v8 == 115 )
{
break;
}
}
}
}
}
else
{
printf("\nDirectory: There is no sub-directory in current directory.");
}
puts("------------------------------------");
puts(
"\n"
"Operation: 'e' Edit\n"
" 'r' Run\n"
" 'c' Change directory\n"
" 'p' Print directory\n"
" 'q' Quit\n");
puts("------------------------------------");
func9(v0, v11[0]);
func9(v1, v10);
}

original_code:
void printMenu() {
    char **files;
    char **directories;
    int fileCounter, dirCounter = 0;
    int i;
    printDirectory();
    printTime();
    files = getFilesInDir(DT_REG, &fileCounter);
    directories = getFilesInDir(DT_DIR, &dirCounter);
    if ((fileCounter + dirCounter) > 1024) {
        printf("ERROR! Number of files and directories in the\n"
                "current directory exceed the max of %d.\n\nExiting program...\n\n", 1024);
        exit(1);
    }
    if (fileCounter == 0) {
        printf("Files:        There is no file in current directory.\n");
    } else {
         printf( "\n====================================\n"
                "               Files"
                "\n====================================\n");
        i = 0;
        while (i < fileCounter) {
            printf("%d. %s\n", i, files[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = fileCounter;
                        break;
                }
            }
        }
    }
    printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
    while (getchar() != '\n');
    if (dirCounter == 0) {
        printf("\nDirectory:     There is no sub-directory in current directory.");
    } else {
        printf( "\n====================================\n"
                "             Directories"
                "\n====================================\n");
        i = 0;
        while (i < dirCounter) {
            printf("%d. %s\n", i, directories[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = dirCounter;
                        break;
                }
            }
        }
    }
    printf("------------------------------------\n");
    printf( "\n"
            "Operation:     'e'  Edit\n"
            "               'r'  Run\n"
            "               'c'  Change directory\n"
            "               'p'  Print directory\n"
            "               'q'  Quit\n"
            "\n");
    printf("------------------------------------\n");
    freeMem(files, fileCounter);
    freeMem(directories, dirCounter);
}

canonical_original_code:
void printMenu() {
    char **files;
    char **directories;
    int fileCounter; int dirCounter = 0;
    int i;
    printDirectory();
    printTime();
    files = getFilesInDir(DT_REG, &fileCounter);
    directories = getFilesInDir(DT_DIR, &dirCounter);
    if ((fileCounter + dirCounter) > 1024) {
        printf("ERROR! Number of files and directories in the\n"
                "current directory exceed the max of %d.\n\nExiting program...\n\n", 1024);
        exit(1);
    }
    if (fileCounter == 0) {
        printf("Files:        There is no file in current directory.\n");
    } else {
         printf( "\n====================================\n"
                "               Files"
                "\n====================================\n");
        i = 0;
        while (i < fileCounter) {
            printf("%d. %s\n", i, files[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = fileCounter;
                        break;
                }
            }
        }
    }
    printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
    while (getchar() != '\n');
    if (dirCounter == 0) {
        printf("\nDirectory:     There is no sub-directory in current directory.");
    } else {
        printf( "\n====================================\n"
                "             Directories"
                "\n====================================\n");
        i = 0;
        while (i < dirCounter) {
            printf("%d. %s\n", i, directories[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = dirCounter;
                        break;
                }
            }
        }
    }
    printf("------------------------------------\n");
    printf( "\n"
            "Operation:     'e'  Edit\n"
            "               'r'  Run\n"
            "               'c'  Change directory\n"
            "               'p'  Print directory\n"
            "               'q'  Quit\n"
            "\n");
    printf("------------------------------------\n");
    freeMem(files, fileCounter);
    freeMem(directories, dirCounter);
}

variable_types:
directories
char **

variable_types: fileCounter int

variable_types: dirCounter int


findFile

decompiled_code:
char *__fastcall findFile(char a1)
{
char *v1; // rbp
const char **v2; // rbx
int v3; // er12
int v5; // [rsp+8h] [rbp-120h] BYREF
int v6; // [rsp+Ch] [rbp-11Ch]
char s[280]; // [rsp+10h] [rbp-118h] BYREF

v1 = (char *)malloc(8uLL);
v2 = (const char **)getFilesInDir(a1, &v5);
if ( fgets(s, 256, _bss_start) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v3 = v5;
if ( v6 < v5 )
{
strcpy(v1, v2[v6]);
freeMem(v2, v3);
return v1;
}
}
strtok(s, "\n");
strcpy(v1, s);
}
freeMem(v2, v5);
return v1;
}

canonical_decompiled_code:
char *__fastcall func12(char a1)
{
char *v1; // rbp
const char **v2; // rbx
int v3; // er12
int v5; // [rsp+8h] [rbp-120h] BYREF
int v6; // [rsp+Ch] [rbp-11Ch]
char s[280]; // [rsp+10h] [rbp-118h] BYREF

v1 = (char *)malloc(8uLL);
v2 = (const char **)func10(a1, &v5);
if ( fgets(s, 256, _bss_start) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v3 = v5;
if ( v6 < v5 )
{
strcpy(v1, v2[v6]);
func9(v2, v3);
return v1;
}
}
strtok(s, "\n");
strcpy(v1, s);
}
func9(v2, v5);
return v1;
}

original_code:
char *findFile(unsigned char type) {
    char *input = malloc(sizeof(char *));
    char buffer[256];
    int i ,counter;
    char **files;
    files = getFilesInDir(type, &counter);
    if (fgets(buffer, sizeof(buffer), stdin)) {
        if (1 == sscanf(buffer, "%d", &i)) {
            if (i < counter) {
                strcpy(input, files[i]);
                freeMem(files, counter);
                return input;
            }
        }
        strtok(buffer, "\n");
        strcpy(input, buffer);
    }
    freeMem(files, counter);
    return input;
}

canonical_original_code:
char *findFile(unsigned char type) {
    char *input = malloc(sizeof(char *));
    char buffer[256];
    int i; int counter;
    char **files;
    files = getFilesInDir(type, &counter);
    if (fgets(buffer, sizeof(buffer), stdin)) {
        if (1 == sscanf(buffer, "%d", &i)) {
            if (i < counter) {
                strcpy(input, files[i]);
                freeMem(files, counter);
                return input;
            }
        }
        strtok(buffer, "\n");
        strcpy(input, buffer);
    }
    freeMem(files, counter);
    return input;
}

variable_types:
type
unsigned char

variable_types:
input
char *

variable_types:
buffer
char [256]

variable_types: counter int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebx
int v5; // eax
char src[6]; // [rsp+Ah] [rbp-10Eh] BYREF
char dest[264]; // [rsp+10h] [rbp-108h] BYREF

strcpy(src, "nano ");
system("clear");
printMenu();
printf("Choose an Operation:> ");
while ( 1 )
{
v4 = getchar();
do
v5 = getchar();
while ( v4 != -1 && v5 != 10 );
switch ( v4 )
{
case 'c':
printf("Change To?: ");
v3 = findFile(4);
strcpy(dest, v3);
if ( chdir(dest) == -1 )
{
puts("No such directory.Try again.\n");
}
else
{
system("clear");
printMenu();
}
printf("Choose an Operation:> ");
goto LABEL_6;
case 'e':
printf("Edit what?: ");
v3 = findFile(8);
strcpy(dest, src);
strcat(dest, v3);
system(dest);
printf("Choose an Operation:> ");
goto LABEL_6;
case 'p':
system("clear");
printMenu();
printf("Choose an Operation:> ");
goto LABEL_15;
case 'q':
exit(0);
case 'r':
printf("Run what?: ");
v3 = findFile(8);
strcpy(dest, "./");
strcat(dest, v3);
system(dest);
printf("Choose an Operation:> ");
LABEL_6:
free(v3);
break;
default:
LABEL_15:
puts("Invalid operation! Try again...");
printf("Choose an Operation:> ");
break;
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebx
int v5; // eax
char src[6]; // [rsp+Ah] [rbp-10Eh] BYREF
char dest[264]; // [rsp+10h] [rbp-108h] BYREF

strcpy(src, "nano ");
system("clear");
func11();
printf("Choose an Operation:> ");
while ( 1 )
{
v4 = getchar();
do
v5 = getchar();
while ( v4 != -1 && v5 != 10 );
switch ( v4 )
{
case 'c':
printf("Change To?: ");
v3 = func12(4);
strcpy(dest, v3);
if ( chdir(dest) == -1 )
{
puts("No such directory.Try again.\n");
}
else
{
system("clear");
func11();
}
printf("Choose an Operation:> ");
goto LABEL_6;
case 'e':
printf("Edit what?: ");
v3 = func12(8);
strcpy(dest, src);
strcat(dest, v3);
system(dest);
printf("Choose an Operation:> ");
goto LABEL_6;
case 'p':
system("clear");
func11();
printf("Choose an Operation:> ");
goto LABEL_15;
case 'q':
exit(0);
case 'r':
printf("Run what?: ");
v3 = func12(8);
strcpy(dest, "./");
strcat(dest, v3);
system(dest);
printf("Choose an Operation:> ");
LABEL_6:
free(v3);
break;
default:
LABEL_15:
puts("Invalid operation! Try again...");
printf("Choose an Operation:> ");
break;
}
}
}

original_code:
int main(void)
{
    int c, l;
    char *s;
    char cmd[256];
    const char EDITOR[] = "nano ";
    system("clear");
    printMenu();
    printf("Choose an Operation:> ");
    while (1) {
        c = getchar();
        while (getchar() != '\n' && c != (-1));
        switch (c) {
            case 'q': exit(0);
            case 'c': printf("Change To?: ");
                      s = findFile(DT_DIR);
                      strcpy(cmd, s);
                      if (chdir(cmd) == -1) {
                          printf("No such directory.Try again.\n\n");
                      } else {
                          system("clear");
                          printMenu();
                      }
                      printf("Choose an Operation:> ");
                      break;
            case 'e': printf("Edit what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, EDITOR);
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'r': printf("Run what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, "./");
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'p': system("clear");
                      printMenu();
                      printf("Choose an Operation:> ");
            default: printf("Invalid operation! Try again...\n");
                      printf("Choose an Operation:> ");
                      continue;
        }
        free(s);
    }
    return 0;
}

canonical_original_code:
int main()
{
    int c; int l;
    char *s;
    char cmd[256];
    char EDITOR[] = "nano ";
    system("clear");
    printMenu();
    printf("Choose an Operation:> ");
    while (1) {
        c = getchar();
        while (getchar() != '\n' && c != (-1));
        switch (c) {
            case 'q': exit(0);
            case 'c': printf("Change To?: ");
                      s = findFile(DT_DIR);
                      strcpy(cmd, s);
                      if (chdir(cmd) == -1) {
                          printf("No such directory.Try again.\n\n");
                      } else {
                          system("clear");
                          printMenu();
                      }
                      printf("Choose an Operation:> ");
                      break;
            case 'e': printf("Edit what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, EDITOR);
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'r': printf("Run what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, "./");
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'p': system("clear");
                      printMenu();
                      printf("Choose an Operation:> ");
            default: printf("Invalid operation! Try again...\n");
                      printf("Choose an Operation:> ");
                      continue;
        }
        free(s);
    }
    return 0;
}

variable_types: c int

variable_types: l int

variable_types:
s
char *

variable_types:
cmd
char [256]

variable_types:
EDITOR
char []


genRandNum

decompiled_code:
__int64 __fastcall genRandNum(__int64 a1)
{
time_t v1; // rax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

_gmp_randinit_mt(v3);
v1 = time(0LL);
_gmp_randseed_ui(v3, v1);
return _gmpz_urandomb(a1, v3, 512LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
time_t v1; // rax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

_gmp_randinit_mt(v3);
v1 = time(0LL);
_gmp_randseed_ui(v3, v1);
return _gmpz_urandomb(a1, v3, 512LL);
}

original_code:
void genRandNum(mpz_t rop) {
  gmp_randstate_t state;
  __gmp_randinit_mt(state);
  unsigned long int seed = time(((void *)0));
  __gmp_randseed_ui(state, seed);
  mp_bitcnt_t n = 512;
  __gmpz_urandomb (rop, state, n);
}

canonical_original_code:
void genRandNum(struct __mpz_struct rop[1]) {
  struct __gmp_randstate_struct state[1];
  __gmp_randinit_mt(state);
  unsigned long seed = time(((void *)0));
  __gmp_randseed_ui(state, seed);
  unsigned long n = 512;
  __gmpz_urandomb (rop, state, n);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types:
seed
unsigned long

variable_types:
n
unsigned long

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


isPrime

decompiled_code:
__int64 __fastcall isPrime(__int64 a1)
{
return _gmpz_probab_prime_p(a1, 50LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return _gmpz_probab_prime_p(a1, 50LL);
}

original_code:
int isPrime(mpz_t rop) {
  return __gmpz_probab_prime_p (rop, 50);
}

canonical_original_code:
int isPrime(struct __mpz_struct rop[1]) {
  return __gmpz_probab_prime_p (rop, 50);
}

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


getRandomPrime

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

do
{
genRandNum(a1);
result = isPrime(a1);
}
while ( !(_DWORD)result );
return result;
}

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

do
{
func0(a1);
result = func1(a1);
}
while ( !(_DWORD)result );
return result;
}

original_code:
int getRandomPrime(mpz_t rop) {
  do {
    genRandNum(rop);
  } while(!isPrime(rop));
}

canonical_original_code:
int getRandomPrime(struct __mpz_struct rop[1]) {
  do {
    genRandNum(rop);
  } while(!isPrime(rop));
}


printMPZ

decompiled_code:
__int64 __fastcall printMPZ(__int64 a1)
{
return _gmp_printf("%Zd\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return _gmp_printf("%Zd\n", a1);
}

original_code:
void printMPZ(mpz_t rop) {
  __gmp_printf("%Zd\n", rop);
}

canonical_original_code:
void printMPZ(struct __mpz_struct rop[1]) {
  __gmp_printf("%Zd\n", rop);
}


addMPZ

decompiled_code:
__int64 __fastcall addMPZ(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_add(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_add(a3, a1, a2);
}

original_code:
void addMPZ(mpz_t rop1, mpz_t rop2, mpz_t result) {
  __gmpz_add(result, rop1, rop2);
}

canonical_original_code:
void addMPZ(struct __mpz_struct rop1[1], struct __mpz_struct rop2[1], struct __mpz_struct result[1]) {
  __gmpz_add(result, rop1, rop2);
}

variable_types:
result
struct __mpz_struct [1]


subtractMPZ

decompiled_code:
__int64 __fastcall subtractMPZ(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_sub(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_sub(a3, a1, a2);
}

original_code:
void subtractMPZ(mpz_t rop1, mpz_t rop2, mpz_t result) {
  __gmpz_sub(result, rop1, rop2);
}

canonical_original_code:
void subtractMPZ(struct __mpz_struct rop1[1], struct __mpz_struct rop2[1], struct __mpz_struct result[1]) {
  __gmpz_sub(result, rop1, rop2);
}


multMPZ

decompiled_code:
__int64 __fastcall multMPZ(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_mul(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_mul(a3, a1, a2);
}

original_code:
void multMPZ(mpz_t rop1, mpz_t rop2, mpz_t result) {
  __gmpz_mul(result, rop1, rop2);
}

canonical_original_code:
void multMPZ(struct __mpz_struct rop1[1], struct __mpz_struct rop2[1], struct __mpz_struct result[1]) {
  __gmpz_mul(result, rop1, rop2);
}


modExponentMPZ

decompiled_code:
__int64 __fastcall modExponentMPZ(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return _gmpz_powm(a4, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return _gmpz_powm(a4, a1, a2, a3);
}

original_code:
void modExponentMPZ(mpz_t base, mpz_t exp, mpz_t mod, mpz_t result) {
  __gmpz_powm (result, base, exp, mod);
}

canonical_original_code:
void modExponentMPZ(struct __mpz_struct base[1], struct __mpz_struct exp[1], struct __mpz_struct mod[1], struct __mpz_struct result[1]) {
  __gmpz_powm (result, base, exp, mod);
}

variable_types:
exp
struct __mpz_struct [1]

variable_types:
mod
struct __mpz_struct [1]


gcd

decompiled_code:
unsigned __int64 __fastcall gcd(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx

v2 = a2;
if ( !a1 )
return a2;
while ( 1 )
{
v3 = v2 % a1;
v2 = a1;
if ( !v3 )
break;
a1 = v3;
}
return a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx

v2 = a2;
if ( !a1 )
return a2;
while ( 1 )
{
v3 = v2 % a1;
v2 = a1;
if ( !v3 )
break;
a1 = v3;
}
return a1;
}

original_code:
unsigned long int gcd (unsigned long int a, unsigned long int b)
{
  unsigned long int c;
  while (a != 0) {
    c = a;
    a = b%a;
    b = c;
  }
  return b;
}

canonical_original_code:
unsigned long gcd(unsigned long a, unsigned long b)
{
  unsigned long c;
  while (a != 0) {
    c = a;
    a = b%a;
    b = c;
  }
  return b;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
c
unsigned long

return_type: unsigned long


repo: Thirdhuku/TreeDB

decompiled_code:
int begin_timer()
{
return gettimeofday(&g_begin, 0LL);
}

canonical_decompiled_code:
int func3()
{
return gettimeofday(&g_begin, 0LL);
}

original_code:
void begin_timer()
{
 gettimeofday(&g_begin, ((void *)0));
}


decompiled_code:
int end_timer()
{
return gettimeofday(&g_end, 0LL);
}

canonical_decompiled_code:
int func4()
{
return gettimeofday(&g_end, 0LL);
}

original_code:
void end_timer()
{
 gettimeofday(&g_end, ((void *)0));
}


decompiled_code:
__int64 Diff_timer()
{
return 1000 * LODWORD(g_end.tv_sec)
+ (int)g_end.tv_usec / 1000
- 1000 * LODWORD(g_begin.tv_sec)
- (unsigned int)(g_begin.tv_usec / 1000);
}

canonical_decompiled_code:
__int64 func5()
{
return 1000 * LODWORD(g_end.tv_sec)
+ (int)g_end.tv_usec / 1000
- 1000 * LODWORD(g_begin.tv_sec)
- (unsigned int)(g_begin.tv_usec / 1000);
}

original_code:
int Diff_timer()
{
 return (g_end.tv_sec * 1000 + g_end.tv_usec / 1000) -
  (g_begin.tv_sec * 1000 + g_begin.tv_usec / 1000);
}


decompiled_code:
char **__fastcall stp_btree_open(char *file, char a2)
{
char v3; // bl
int v4; // esi
int v5; // edi
char **result; // rax
char **v7; // [rsp+8h] [rbp-B0h] BYREF
struct stat v8; // [rsp+10h] [rbp-A8h] BYREF

v3 = a2 & 0xF7;
if ( stat(file, &v8) < 0 )
{
v3 |= 8u;
fwrite("[WARNING] can't find the index file.\n", 1uLL, 0x25uLL, stderr);
}
v4 = 2;
if ( (v3 & 8) != 0 )
{
v3 |= 4u;
v4 = 66;
}
v5 = open(file, v4, 484LL);
result = 0LL;
if ( v5 >= 0 )
{
v7 = 0LL;
if ( (int)read_btree_info(v5, (void ***)&v7, v3) < 0 )
{
result = 0LL;
}
else
{
*v7 = file;
result = v7;
}
}
return result;
}

canonical_decompiled_code:
char **__fastcall func7(char *file, char a2)
{
char v3; // bl
int v4; // esi
int v5; // edi
char **result; // rax
char **v7; // [rsp+8h] [rbp-B0h] BYREF
struct stat v8; // [rsp+10h] [rbp-A8h] BYREF

v3 = a2 & 0xF7;
if ( stat(file, &v8) < 0 )
{
v3 |= 8u;
fwrite("[WARNING] can't find the index file.\n", 1uLL, 0x25uLL, stderr);
}
v4 = 2;
if ( (v3 & 8) != 0 )
{
v3 |= 4u;
v4 = 66;
}
v5 = open(file, v4, 484LL);
result = 0LL;
if ( v5 >= 0 )
{
v7 = 0LL;
if ( (int)func6(v5, (void ***)&v7, v3) < 0 )
{
result = 0LL;
}
else
{
*v7 = file;
result = v7;
}
}
return result;
}

original_code:
struct stp_btree_info* stp_btree_open(const char *btree_file, unsigned int mode)
{
    int bfd;
    mode_t m = 02;
    struct stat st;
    unsigned int flags = 0;
    mode &= ~(1<<3);
    if(stat(btree_file, &st) < 0) {
        mode |= (1<<3);
        fprintf(stderr,"[WARNING] can't find the index file.\n");
    }
    if(mode & (1<<3)) {
        m |= 0100;
        mode |= (1<<2);
    }
    if((bfd = open(btree_file, m, (0400|0200|0100) | (0400 >> 3) | ((0400 >> 3) >> 3))) < 0) {
        return ((void *)0);
    }
    struct stp_btree_info *tree = ((void *)0);
    if(read_btree_info(bfd, &tree, mode) < 0) {
        return ((void *)0);
    }
    tree->filename = btree_file;
    return tree;
}

canonical_original_code:
struct stp_btree_info *stp_btree_open(char *btree_file, unsigned int mode)
{
    int bfd;
    unsigned int m = 02;
    struct stat st;
    unsigned int flags = 0;
    mode &= ~(1<<3);
    if(stat(btree_file, &st) < 0) {
        mode |= (1<<3);
        fprintf(stderr,"[WARNING] can't find the index file.\n");
    }
    if(mode & (1<<3)) {
        m |= 0100;
        mode |= (1<<2);
    }
    if((bfd = open(btree_file, m, (0400|0200|0100) | (0400 >> 3) | ((0400 >> 3) >> 3))) < 0) {
        return ((void *)0);
    }
    struct stp_btree_info *tree = ((void *)0);
    if(read_btree_info(bfd, &tree, mode) < 0) {
        return ((void *)0);
    }
    tree->filename = btree_file;
    return tree;
}

variable_types:
mode
unsigned int

variable_types: bfd int

variable_types:
m
unsigned int

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

variable_types:
flags
unsigned int

variable_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *

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

user_defined_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations *ops; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header root; }

user_defined_types: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item *item; struct stp_bnode_operations *ops; }

user_defined_types: struct stp_bnode_item { struct stp_header location; struct stp_bnode_key key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; }


decompiled_code:
__int64 __fastcall insert_into_btree(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
char v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+9h] [rbp-1Fh]
__int64 v7; // [rsp+11h] [rbp-17h]

v4 = a2;
v5 = 0;
v7 = a3;
v6 = 10LL;
return do_btree_super_insert(a1, &v4, 0LL);
}

original_code:
int insert_into_btree(struct stp_btree_info *btree, u64 ino, u64 offset)
{
    struct stp_bnode_off off;
    off.ino = ino;
    off.flags = 0;
    off.offset = offset;
    off.len = 10;
    return do_btree_super_insert(btree, &off, 0);
}

canonical_original_code:
int insert_into_btree(struct stp_btree_info *btree, unsigned long ino, unsigned long offset)
{
    struct stp_bnode_off off;
    off.ino = ino;
    off.flags = 0;
    off.offset = offset;
    off.len = 10;
    return do_btree_super_insert(btree, &off, 0);
}

variable_types:
ino
unsigned long

variable_types:
offset
unsigned long

variable_types: struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; }

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; }

user_defined_types: struct list { struct list *next; struct list *prev; }

user_defined_types: struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); }

user_defined_types: struct stp_bnode_key { unsigned long ino; unsigned char flags; }


decompiled_code:
__int64 search_in_btree()
{
return do_btree_super_search();
}

canonical_decompiled_code:
__int64 func9()
{
return do_btree_super_search();
}

original_code:
int search_in_btree(struct stp_btree_info *btree, u64 ino, struct stp_bnode_off *off)
{
    return do_btree_super_search(btree, ino, off);
}

canonical_original_code:
int search_in_btree(struct stp_btree_info *btree, unsigned long ino, struct stp_bnode_off *off)
{
    return do_btree_super_search(btree, ino, off);
}

variable_types:
off
struct stp_bnode_off *

user_defined_types: struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; }


decompiled_code:
__int64 delete_from_btree()
{
return do_btree_super_rm();
}

canonical_decompiled_code:
__int64 func10()
{
return do_btree_super_rm();
}

original_code:
int delete_from_btree(struct stp_btree_info *btree, u64 ino)
{
    return do_btree_super_rm(btree, ino);
}

canonical_original_code:
int delete_from_btree(struct stp_btree_info *btree, unsigned long ino)
{
    return do_btree_super_rm(btree, ino);
}


decompiled_code:
void __fastcall stp_btree_close(void *ptr)
{
(*(void (**)(void))(*((_QWORD *)ptr + 22) + 88LL))();
fsync(*((_DWORD *)ptr + 2));
msync(*((void **)ptr + 14), 0x2000uLL, 4);
munmap(*((void **)ptr + 14), 0x2000uLL);
close(*((_DWORD *)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
(*(void (**)(void))(*((_QWORD *)ptr + 22) + 88LL))();
fsync(*((_DWORD *)ptr + 2));
msync(*((void **)ptr + 14), 0x2000uLL, 4);
munmap(*((void **)ptr + 14), 0x2000uLL);
close(*((_DWORD *)ptr + 2));
free(ptr);
}

original_code:
void stp_btree_close(struct stp_btree_info *btree)
{
    btree->ops->destroy(btree);
    fsync(btree->fd);
    msync(btree->super,(1024*8),4);
    munmap(btree->super,(1024*8));
    close(btree->fd);
    free(btree);
}


decompiled_code:
int __fastcall test_insert(__int64 a1, int a2, int a3)
{
unsigned int v3; // ebx
int result; // eax
int v6; // er12
__int64 i; // rbp
int v8; // eax

v3 = a2;
result = begin_timer();
v6 = a2 + a3;
if ( a2 <= v6 )
{
for ( i = a2; (int)insert_into_btree(a1, i, i) >= 0; ++i )
{
result = 10000 * ((int)v3 / 10000);
if ( v3 == result )
{
end_timer();
v8 = Diff_timer();
printf("1ms insert %d\n", (unsigned int)(10000 / v8));
result = begin_timer();
}
if ( (int)++v3 > v6 )
return result;
}
result = fprintf(stderr, "insert error, %d\n", v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, int a2, int a3)
{
unsigned int v3; // ebx
int result; // eax
int v6; // er12
__int64 i; // rbp
int v8; // eax

v3 = a2;
result = func3();
v6 = a2 + a3;
if ( a2 <= v6 )
{
for ( i = a2; (int)func8(a1, i, i) >= 0; ++i )
{
result = 10000 * ((int)v3 / 10000);
if ( v3 == result )
{
func4();
v8 = func5();
printf("1ms insert %d\n", (unsigned int)(10000 / v8));
result = func3();
}
if ( (int)++v3 > v6 )
return result;
}
result = fprintf(stderr, "insert error, %d\n", v3);
}
return result;
}

original_code:
void test_insert(struct stp_btree_info *btree, int start, int num)
{
    int rc = 0;
    int i = 0;
    begin_timer();
    for (i = start; i <= start + num; ++i) {
        rc = insert_into_btree(btree, i, i);
        if (rc < 0) {
            fprintf(stderr, "insert error, %d\n", i);
            break;
        }
        if(i % 10000 == 0){
       end_timer();
       printf("1ms insert %d\n", 10000 / Diff_timer());
       begin_timer();
        }
    }
}

variable_types: start int

variable_types: num int

variable_types: rc int

variable_types: i int


decompiled_code:
void __fastcall test_delete(__int64 a1, signed int a2, int a3)
{
int v3; // er12
unsigned int v4; // ebx
__int64 i; // rbp

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)delete_from_btree(a1, i) >= 0; ++i )
{
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "delete error, %d\n", v4);
}
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, signed int a2, int a3)
{
int v3; // er12
unsigned int v4; // ebx
__int64 i; // rbp

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)func10(a1, i) >= 0; ++i )
{
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "delete error, %d\n", v4);
}
}

original_code:
void test_delete(struct stp_btree_info *btree, int start, int num)
{
    int rc = 0;
    int i = 0;
    for (i = start; i < start + num; ++i) {
        rc = delete_from_btree(btree, i);
        if (rc < 0) {
            fprintf(stderr, "delete error, %d\n", i);
            break;
        }
    }
}


decompiled_code:
void __fastcall test_search(__int64 a1, signed int a2, int a3)
{
int v3; // er12
unsigned int v4; // ebp
__int64 i; // rbx
__int64 v6[9]; // [rsp+0h] [rbp-48h] BYREF

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)search_in_btree(a1, i, v6) >= 0; ++i )
{
if ( v6[0] != i || *(__int64 *)((char *)&v6[2] + 1) != i )
_assert_fail("i == off.ino && i == off.offset", "test_btree.c", 0xFBu, "test_search");
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "search error, %d\n", v4);
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, signed int a2, int a3)
{
int v3; // er12
unsigned int v4; // ebp
__int64 i; // rbx
__int64 v6[9]; // [rsp+0h] [rbp-48h] BYREF

v3 = a2 + a3;
if ( a2 < a2 + a3 )
{
v4 = a2;
for ( i = a2; (int)func9(a1, i, v6) >= 0; ++i )
{
if ( v6[0] != i || *(__int64 *)((char *)&v6[2] + 1) != i )
_assert_fail("i == off.ino && i == off.offset", "test_btree.c", 0xFBu, "test_search");
if ( ++v4 == v3 )
return;
}
fprintf(stderr, "search error, %d\n", v4);
}
}

original_code:
void test_search(struct stp_btree_info *btree, int start, int num)
{
    int rc = 0;
    int i = 0;
    struct stp_bnode_off off;
    for (i = start; i < start + num; ++i) {
        rc = search_in_btree(btree, i, &off);
        if (rc < 0) {
            fprintf(stderr, "search error, %d\n", i);
            break;
        }
        ((void) sizeof ((i == off.ino && i == off.offset) ? 1 : 0), __extension__ ({ if (i == off.ino && i == off.offset) ; else __assert_fail ("i == off.ino && i == off.offset", "test_btree.c", 251, __extension__ __PRETTY_FUNCTION__); }));
    }
}


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

result = sync_btree(a1);
if ( result < 0 )
result = fwrite("sync error\n", 1uLL, 0xBuLL, stderr);
return result;
}

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

result = func11(a1);
if ( result < 0 )
result = fwrite("sync error\n", 1uLL, 0xBuLL, stderr);
return result;
}

original_code:
void test_sync(struct stp_btree_info *btree)
{
    int rc = 0;
    rc = sync_btree(btree);
    if (rc < 0) {
        fprintf(stderr, "sync error\n");
    }
}


main

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

v3 = stp_btree_open("sw.idx", 0);
if ( v3 )
{
v4 = v3;
test_insert((__int64)v3, 1, 90000000);
puts(L"12345678");
test_sync((__int64)v4);
puts(L"2345678");
test_search((__int64)v4, 1, 900000);
puts(L"345678");
test_delete((__int64)v4, 1, 10);
puts(L"45678");
test_sync((__int64)v4);
puts(L"5678");
test_search((__int64)v4, 100000, 800000);
puts(L"678");
test_search((__int64)v4, 12, 2);
puts(L"78");
test_search((__int64)v4, 1, 2);
puts(L"8");
stp_btree_close(v4);
result = 0;
}
else
{
fwrite("open index file error\n", 1uLL, 0x16uLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    struct stp_btree_info *btree = ((void *)0);
    btree = stp_btree_open("sw.idx", 0);
    if (btree == ((void *)0)) {
        fprintf(stderr, "open index file error\n");
        return -1;
    }
    test_insert(btree, 1, 90000000);
    printf("1\n");
    test_sync(btree);
    printf("2\n");
    test_search(btree, 1, 900000);
    printf("3\n");
    test_delete(btree, 1, 10);
    printf("4\n");
    test_sync(btree);
    printf("5\n");
    test_search(btree, 100000, 800000);
    printf("6\n");
    test_search(btree, 12, 2);
    printf("7\n");
    test_search(btree, 1, 2);
    printf("8\n");
    stp_btree_close(btree);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 do_bnode_init()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
static int do_bnode_init(struct stp_bnode *bnode)
{
    return -1;
}

variable_types: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *


decompiled_code:
__int64 do_bnode_insert()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0xFFFFFFFFLL;
}

original_code:
static int do_bnode_insert(struct stp_bnode * node,u64 ino,size_t start,off_t offset)
{
    return -1;
}

canonical_original_code:
static int do_bnode_insert(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset)
{
    return -1;
}

variable_types:
start
unsigned long

variable_types: offset long


decompiled_code:
__int64 do_bnode_update()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0xFFFFFFFFLL;
}

original_code:
static int do_bnode_update(struct stp_bnode * node,u64 ino,size_t start,off_t offset)
{
    return -1;
}

canonical_original_code:
static int do_bnode_update(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset)
{
    return -1;
}


decompiled_code:
__int64 do_bnode_delete()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0xFFFFFFFFLL;
}

original_code:
static int do_bnode_delete(struct stp_bnode *node,u64 ino)
{
    return -1;
}

canonical_original_code:
static int do_bnode_delete(struct stp_bnode *node, unsigned long ino)
{
    return -1;
}


decompiled_code:
__int64 do_bnode_destroy()
{
return 0xFFFFFFFFLL;
}

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

original_code:
static int do_bnode_destroy(struct stp_bnode * node)
{
    return -1;
}

canonical_original_code:
static int do_bnode_destroy(struct stp_bnode *node)
{
    return -1;
}


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

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

original_code:
static struct stp_bnode* do_bnode_search(struct stp_bnode *node,u64 ino,struct stp_bnode_off *off)
{
    return ((void *)0);
}

canonical_original_code:
static struct stp_bnode *do_bnode_search(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off)
{
    return ((void *)0);
}

variable_types:
node
struct stp_bnode *

return_type: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *


original_code:
int stp_stat(STP_FILE pfile,u64 ino,struct stat *buf)
{
    struct stp_fs_info * fs = pfile->fs;
    struct stp_btree_info *btree = pfile->tree;
    struct stp_bnode_off off;
    struct stp_inode *inode;
    int ret;
    if(!buf) {
        stp_errno = 33;
        return -1;
    }
    memset(&off,0,sizeof(off));
    if(ino == 1) {
        __copy_stat(buf,&fs->super->root);
        return 0;
    }
    ret = btree->ops->search(btree,ino,&off);
    if(ret < 0) return ret;
    if(fs->ops->lookup(fs,&inode,off.ino,off.offset) < 0)
        return -1;
    printf("%s:%d,ino:%llu(%llu),offset:%llu,size:%llu,ret:%d\n",__FUNCTION__,50,off.ino,ino,off.offset,off.len,ret);
    __copy_stat(buf,inode->item);
    return 0;
}

canonical_original_code:
int stp_stat(struct STP_FILE_INFO *pfile, unsigned long ino, struct stat *buf)
{
    struct stp_fs_info *fs = pfile->fs;
    struct stp_btree_info *btree = pfile->tree;
    struct stp_bnode_off off;
    struct stp_inode *inode;
    int ret;
    if(!buf) {
        stp_errno = 33;
        return -1;
    }
    memset(&off,0,sizeof(off));
    if(ino == 1) {
        __copy_stat(buf,&fs->super->root);
        return 0;
    }
    ret = btree->ops->search(btree,ino,&off);
    if(ret < 0) return ret;
    if(fs->ops->lookup(fs,&inode,off.ino,off.offset) < 0)
        return -1;
    printf("%s:%d,ino:%llu(%llu),offset:%llu,size:%llu,ret:%d\n",__FUNCTION__,50,off.ino,ino,off.offset,off.len,ret);
    __copy_stat(buf,inode->item);
    return 0;
}

variable_types: struct STP_FILE_INFO { struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t { char __size[32]; long __align; } sem; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item { struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution { char ip[32]; unsigned char padding[64]; } extend; }; char checksum[32]; char address[32]; } root; } *super; struct rb_root { struct rb_node { struct rb_node *parent; struct rb_node *left; struct rb_node *right; unsigned int color; unsigned long key; } *root; unsigned long len; } root; struct list { struct list *next; struct list *prev; } inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t lock; struct rb_node node; struct list lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item { unsigned long ino; unsigned int name_len; char name[-1]; unsigned char flags; unsigned char padding[115]; } *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); } *ops; } *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations { int (*alloc)(struct stp_fs_info *, struct stp_inode *, struct stp_fs_entry *); int (*read)(struct stp_fs_info *, struct stp_fs_entry *); int (*rm)(struct stp_fs_info *, struct stp_fs_entry *); int (*release)(struct stp_fs_info *, struct stp_fs_entry *); int (*sync)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy)(struct stp_fs_info *, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*free)(struct stp_fs_info *, struct stp_fs_entry *); } *ops; } *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); } *ops; } *fs; struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header root; } *super; struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *tree; } *

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

variable_types: struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct rb_node { struct rb_node *parent; struct rb_node *left; struct rb_node *right; unsigned int color; unsigned long key; } node; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t { char __size[32]; long __align; } sem; union pthread_mutex_t mutex; struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item { struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution { char ip[32]; unsigned char padding[64]; } extend; }; char checksum[32]; char address[32]; } root; } *super; struct rb_root { struct rb_node *root; unsigned long len; } root; struct list inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations { int (*alloc)(struct stp_fs_info *, struct stp_inode *, struct stp_fs_entry *); int (*read)(struct stp_fs_info *, struct stp_fs_entry *); int (*rm)(struct stp_fs_info *, struct stp_fs_entry *); int (*release)(struct stp_fs_info *, struct stp_fs_entry *); int (*sync)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy)(struct stp_fs_info *, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*free)(struct stp_fs_info *, struct stp_fs_entry *); } *ops; } *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); } *ops; } *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item { unsigned long ino; unsigned int name_len; char name[-1]; unsigned char flags; unsigned char padding[115]; } *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); } *ops; } *

variable_types: ret int

user_defined_types: struct STP_FILE_INFO { struct stp_fs_info *fs; struct stp_btree_info *tree; }

user_defined_types: struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t sem; union pthread_mutex_t mutex; struct stp_fs_super *super; struct rb_root root; struct list inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations *ops; }

user_defined_types: struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t lock; struct rb_node node; struct list lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations *ops; }

user_defined_types: struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item root; }

user_defined_types: struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); }

user_defined_types: struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); }

user_defined_types: struct stp_inode_item { struct stp_header location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution extend; }; char checksum[32]; char address[32]; }

user_defined_types: struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations *ops; }


original_code:
int stp_readdir(STP_FILE file,u64 ino,dir_t *items,u32 len)
{
    struct stp_fs_info *fs;
    struct stp_btree_info *tree;
    struct stp_inode *inode;
    int i;
    if(!file) {
        stp_errno = 33;
        return -1;
    }
    fs = file->fs;
    tree = file->tree;
    inode = ((void *)0);
    if((!(tree->mode & (1<<2))) && (!(tree->mode & (1<<0)))) {
        stp_errno = 10;
        return -1;
    }
    if(__fs_read_inode(fs,ino,tree,&inode) < 0)
        return -1;
    if(!(inode->item->mode & 0040000)) {
        stp_errno = 44;
        return -1;
    }
    struct stp_dir_item *item;
    if(!(item = calloc(inode->item->nritem,sizeof(struct stp_dir_item)))) {
        stp_errno = 31;
        return -1;
    }
    if(inode->ops->readdir(inode,item) < 0)
    {
        free(item);
        return -1;
    }
    if(!item || !len) {
        free(item);
        return 0;
    }
    for(i = 0;i < inode->item->nritem && i < len;++i) {
        memcpy(&items[i],&item[i],sizeof(*items));
    }
    free(item);
    return 0;
}

canonical_original_code:
int stp_readdir(struct STP_FILE_INFO *file, unsigned long ino, struct stp_dir_item *items, unsigned int len)
{
    struct stp_fs_info *fs;
    struct stp_btree_info *tree;
    struct stp_inode *inode;
    int i;
    if(!file) {
        stp_errno = 33;
        return -1;
    }
    fs = file->fs;
    tree = file->tree;
    inode = ((void *)0);
    if((!(tree->mode & (1<<2))) && (!(tree->mode & (1<<0)))) {
        stp_errno = 10;
        return -1;
    }
    if(__fs_read_inode(fs,ino,tree,&inode) < 0)
        return -1;
    if(!(inode->item->mode & 0040000)) {
        stp_errno = 44;
        return -1;
    }
    struct stp_dir_item *item;
    if(!(item = calloc(inode->item->nritem,sizeof(struct stp_dir_item)))) {
        stp_errno = 31;
        return -1;
    }
    if(inode->ops->readdir(inode,item) < 0)
    {
        free(item);
        return -1;
    }
    if(!item || !len) {
        free(item);
        return 0;
    }
    for(i = 0;i < inode->item->nritem && i < len;++i) {
        memcpy(&items[i],&item[i],sizeof(*items));
    }
    free(item);
    return 0;
}

variable_types:
ino
unsigned long

variable_types:
items
struct stp_dir_item *

variable_types:
len
unsigned int

variable_types: struct stp_fs_info { char *filename; int fd; unsigned int mode; unsigned int magic; unsigned int active; unsigned long transid; long offset; union sem_t { char __size[32]; long __align; } sem; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_fs_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned long bytes_used; unsigned long bytes_hole; unsigned long ino; unsigned int nritems; unsigned int nrdelete; struct stp_inode_item { struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } location; unsigned long ino; unsigned long size; unsigned char nlink; unsigned int uid; unsigned int gid; unsigned int mode; unsigned short flags; unsigned long atime; unsigned long ctime; unsigned long mtime; unsigned long otime; unsigned long transid; unsigned int nritem; union { struct stp_header entry[3]; struct extend_attribution { char ip[32]; unsigned char padding[64]; } extend; }; char checksum[32]; char address[32]; } root; } *super; struct rb_root { struct rb_node { struct rb_node *parent; struct rb_node *left; struct rb_node *right; unsigned int color; unsigned long key; } *root; unsigned long len; } root; struct list { struct list *next; struct list *prev; } inode_list; struct list inode_lru; struct list dirty_list; struct list entry_dirty_list; struct list entry_list; struct stp_fs_operations { int (*init)(struct stp_fs_info *); struct stp_inode { unsigned char flags; unsigned int ref; union pthread_mutex_t lock; struct rb_node node; struct list lru; struct list dirty; struct list list; struct list entry_list; struct stp_fs_info *fs; struct stp_inode_item *item; struct stp_inode *parent; struct rb_root root; struct list child; struct list sibling; struct stp_inode_operations { int (*init)(struct stp_inode *); int (*setattr)(struct stp_inode *); int (*mkdir)(struct stp_inode *, char *, unsigned long, struct stp_inode *); int (*lookup)(struct stp_inode *, char *, unsigned long, unsigned long); int (*rm)(struct stp_inode *, char *name, unsigned long len, unsigned long *ino); int (*creat)(struct stp_inode *, char *, unsigned long, struct stp_inode *, unsigned int); int (*readdir)(struct stp_inode *, struct stp_dir_item { unsigned long ino; unsigned int name_len; char name[-1]; unsigned char flags; unsigned char padding[115]; } *); int (*destroy)(struct stp_inode *); int (*sync)(struct stp_inode *); int (*free)(struct stp_inode *); int (*unlink)(struct stp_inode *); struct stp_dir_item *(*find_entry)(struct stp_inode *parent, char *filename, unsigned long len); } *ops; } *(*allocate)(struct stp_fs_info *, long); int (*free_inode)(struct stp_fs_info *, struct stp_inode *); int (*destroy_inode)(struct stp_fs_info *, struct stp_inode *); struct stp_fs_entry { unsigned int flags; struct stp_inode *inode; struct stp_fs_entry *parent; void *entry; unsigned long size; long offset; struct rb_node node; struct list list; struct list lru; struct list dirty; struct list sibling; struct list child; struct stp_fs_entry_operations { int (*alloc)(struct stp_fs_info *, struct stp_inode *, struct stp_fs_entry *); int (*read)(struct stp_fs_info *, struct stp_fs_entry *); int (*rm)(struct stp_fs_info *, struct stp_fs_entry *); int (*release)(struct stp_fs_info *, struct stp_fs_entry *); int (*sync)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy)(struct stp_fs_info *, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*free)(struct stp_fs_info *, struct stp_fs_entry *); } *ops; } *(*alloc_entry)(struct stp_fs_info *, struct stp_inode *, long, unsigned long, struct stp_fs_entry *); int (*free_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*destroy_entry)(struct stp_fs_info *, struct stp_fs_entry *); int (*lookup)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino, long offset); int (*find)(struct stp_fs_info *sb, struct stp_inode **inode, unsigned long ino); int (*free)(struct stp_fs_info *); int (*read)(struct stp_fs_info *, struct stp_inode *, long offset); int (*sync)(struct stp_fs_info *); int (*write)(struct stp_fs_info *, struct stp_inode *); int (*destroy)(struct stp_fs_info *); } *ops; } *

variable_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *

user_defined_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations *ops; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct rb_root { struct rb_node *root; unsigned long len; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header root; }

user_defined_types: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item *item; struct stp_bnode_operations *ops; }

user_defined_types: struct stp_bnode_item { struct stp_header location; struct stp_bnode_key key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; }


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

result = "Unknown error";
if ( a1 <= 0x2E )
result = stp_errlist[a1];
return result;
}

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

result = "Unknown error";
if ( a1 <= 0x2E )
result = stp_errlist[a1];
return result;
}

original_code:
const char * stp_strerror(stp_error error)
{
    if((((int) error) < 0) || ((int)error > 46))
        return ((const char *)"Unknown error");
    else
        return ((const char *)stp_errlist[(int)error]);
}

canonical_original_code:
char *stp_strerror(unsigned int error)
{
    if((((int) error) < 0) || ((int)error > 46))
        return ((char *)"Unknown error");
    else
        return ((char *)stp_errlist[(int)error]);
}

variable_types:
error
unsigned int


repo: ThomasAdam/tmux-ARCHIVED

decompiled_code:
__int64 __fastcall buf_realloc(__int64 a1, __int64 a2)
{
size_t v3; // rsi
void *v4; // rax
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 40) + a2;
if ( v3 > *(_QWORD *)(a1 + 32) )
{
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
else
{
v4 = realloc(*(void **)(a1 + 16), v3);
if ( v4 )
{
*(_QWORD *)(a1 + 16) = v4;
*(_QWORD *)(a1 + 24) = *(_QWORD *)(a1 + 40) + a2;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
size_t v3; // rsi
void *v4; // rax
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 40) + a2;
if ( v3 > *(_QWORD *)(a1 + 32) )
{
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
else
{
v4 = realloc(*(void **)(a1 + 16), v3);
if ( v4 )
{
*(_QWORD *)(a1 + 16) = v4;
*(_QWORD *)(a1 + 24) = *(_QWORD *)(a1 + 40) + a2;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
buf_realloc(struct buf *buf, size_t len)
{
 u_char *b;
 if (buf->wpos + len > buf->max) {
  (*__errno_location ()) = 12;
  return (-1);
 }
 b = realloc(buf->buf, buf->wpos + len);
 if (b == ((void *)0))
  return (-1);
 buf->buf = b;
 buf->size = buf->wpos + len;
 return (0);
}

canonical_original_code:
int buf_realloc(struct buf *buf, unsigned long len)
{
 unsigned char *b;
 if (buf->wpos + len > buf->max) {
  (*__errno_location ()) = 12;
  return (-1);
 }
 b = realloc(buf->buf, buf->wpos + len);
 if (b == ((void *)0))
  return (-1);
 buf->buf = b;
 buf->size = buf->wpos + len;
 return (0);
}

variable_types: struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *

variable_types:
len
unsigned long

variable_types:
b
unsigned char *


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

if ( a1[5] + a3 <= a1[3] || (result = buf_realloc((__int64)a1, a3), (_DWORD)result != -1) )
{
memcpy((void *)(a1[2] + a1[5]), a2, a3);
a1[5] += a3;
result = 0LL;
}
return result;
}

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

if ( a1[5] + a3 <= a1[3] || (result = func0((__int64)a1, a3), (_DWORD)result != -1) )
{
memcpy((void *)(a1[2] + a1[5]), a2, a3);
a1[5] += a3;
result = 0LL;
}
return result;
}

original_code:
int
buf_add(struct buf *buf, const void *data, size_t len)
{
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (-1);
 memcpy(buf->buf + buf->wpos, data, len);
 buf->wpos += len;
 return (0);
}

canonical_original_code:
int buf_add(struct buf *buf, void *data, unsigned long len)
{
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (-1);
 memcpy(buf->buf + buf->wpos, data, len);
 buf->wpos += len;
 return (0);
}

variable_types:
data
void *

user_defined_types: struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; }


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

if ( (unsigned __int64)(a1[5] + a2) > a1[3] && (unsigned int)buf_realloc((__int64)a1, a2) == -1 )
return 0LL;
result = a1[2] + a1[5];
a1[5] += a2;
return result;
}

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

if ( (unsigned __int64)(a1[5] + a2) > a1[3] && (unsigned int)func0((__int64)a1, a2) == -1 )
return 0LL;
result = a1[2] + a1[5];
a1[5] += a2;
return result;
}

original_code:
void *
buf_reserve(struct buf *buf, size_t len)
{
 void *b;
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (((void *)0));
 b = buf->buf + buf->wpos;
 buf->wpos += len;
 return (b);
}

canonical_original_code:
void *buf_reserve(struct buf *buf, unsigned long len)
{
 void *b;
 if (buf->wpos + len > buf->size)
  if (buf_realloc(buf, len) == -1)
   return (((void *)0));
 b = buf->buf + buf->wpos;
 buf->wpos += len;
 return (b);
}

variable_types:
b
void *

return_type: void *


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

if ( (unsigned __int64)(a2 + a3) > *(_QWORD *)(a1 + 40) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16) + a2;
return result;
}

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

if ( (unsigned __int64)(a2 + a3) > *(_QWORD *)(a1 + 40) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16) + a2;
return result;
}

original_code:
void *
buf_seek(struct buf *buf, size_t pos, size_t len)
{
 if (pos + len > buf->wpos)
  return (((void *)0));
 return (buf->buf + pos);
}

canonical_original_code:
void *buf_seek(struct buf *buf, unsigned long pos, unsigned long len)
{
 if (pos + len > buf->wpos)
  return (((void *)0));
 return (buf->buf + pos);
}

variable_types:
pos
unsigned long


decompiled_code:
__int64 __fastcall buf_size(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

original_code:
size_t
buf_size(struct buf *buf)
{
 return (buf->wpos);
}

canonical_original_code:
unsigned long buf_size(struct buf *buf)
{
 return (buf->wpos);
}


decompiled_code:
__int64 __fastcall buf_left(__int64 a1)
{
return *(_QWORD *)(a1 + 32) - *(_QWORD *)(a1 + 40);
}

original_code:
size_t
buf_left(struct buf *buf)
{
 return (buf->max - buf->wpos);
}

canonical_original_code:
unsigned long buf_left(struct buf *buf)
{
 return (buf->max - buf->wpos);
}


decompiled_code:
void __fastcall buf_free(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
buf_free(struct buf *buf)
{
 free(buf->buf);
 free(buf);
}


original_code:
void
msgbuf_init(struct msgbuf *msgbuf)
{
 msgbuf->queued = 0;
 msgbuf->fd = -1;
 do { (&msgbuf->bufs)->tqh_first = ((void *)0); (&msgbuf->bufs)->tqh_last = &(&msgbuf->bufs)->tqh_first; } while (0);
}

variable_types: struct msgbuf { struct { struct ibuf { struct { struct ibuf *tqe_next; struct ibuf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *tqh_first; struct ibuf **tqh_last; } bufs; unsigned int queued; int fd; } *

user_defined_types: struct msgbuf { struct { struct ibuf *tqh_first; struct ibuf **tqh_last; } bufs; unsigned int queued; int fd; }


original_code:
void
buf_dequeue(struct msgbuf *msgbuf, struct buf *buf)
{
 do { if (((buf)->entry.tqe_next) != ((void *)0)) (buf)->entry.tqe_next->entry.tqe_prev = (buf)->entry.tqe_prev; else (&msgbuf->bufs)->tqh_last = (buf)->entry.tqe_prev; *(buf)->entry.tqe_prev = (buf)->entry.tqe_next; ; ; } while (0);
 if (buf->fd != -1)
  close(buf->fd);
 msgbuf->queued--;
 buf_free(buf);
}

variable_types: struct msgbuf { struct { struct buf { struct { struct buf *tqe_next; struct buf **tqe_prev; } entry; unsigned char *buf; unsigned long size; unsigned long max; unsigned long wpos; unsigned long rpos; int fd; } *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; } *

variable_types:
buf
struct buf *

user_defined_types: struct msgbuf { struct { struct buf *tqh_first; struct buf **tqh_last; } bufs; unsigned int queued; int fd; }