decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int v5; // ebx
char *v7; // r12
size_t v8; // rax
__int64 v9; // rax
char *v10[6]; // [rsp+0h] [rbp-2788h] BYREF
char buf[10000]; // [rsp+30h] [rbp-2758h] BYREF
struct sockaddr v12; // [rsp+2740h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+2750h] [rbp-38h] BYREF
int optval; // [rsp+2768h] [rbp-20h] BYREF
socklen_t addr_len[7]; // [rsp+276Ch] [rbp-1Ch] BYREF

optval = 1;
v3 = socket(2, 1, 0);
v4 = v3;
if ( v3 == -1 )
{
puts("Error creating socket");
v5 = -1;
}
else
{
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 )
puts("Set reuse addr on socket failed");
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = _bswap_16(8000);
if ( bind(v4, &addr, 0x10u) < 0 )
{
puts("Error bind port");
v5 = -2;
}
else
{
printf("Bind port %d done\n", 8000LL);
listen(v4, 3);
puts("Waiting client connection");
addr_len[0] = 16;
while ( 1 )
{
v5 = accept(v4, &v12, addr_len);
if ( !v5 )
break;
puts("Connection accepted");
v9 = recv(v5, buf, 0x2710uLL, 0);
if ( v9 >= 0 )
{
parse_http_request(v10, v9, buf);
puts(v10[1]);
puts(v10[2]);
puts(v10[3]);
}
else
{
puts("Error recv");
}
v7 = response;
v8 = strlen(response);
send(v5, v7, v8, 0);
close(v5);
}
}
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int v5; // ebx
char *v7; // r12
size_t v8; // rax
__int64 v9; // rax
char *v10[6]; // [rsp+0h] [rbp-2788h] BYREF
char buf[10000]; // [rsp+30h] [rbp-2758h] BYREF
struct sockaddr v12; // [rsp+2740h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+2750h] [rbp-38h] BYREF
int optval; // [rsp+2768h] [rbp-20h] BYREF
socklen_t addr_len[7]; // [rsp+276Ch] [rbp-1Ch] BYREF

optval = 1;
v3 = socket(2, 1, 0);
v4 = v3;
if ( v3 == -1 )
{
puts("Error creating socket");
v5 = -1;
}
else
{
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 )
puts("Set reuse addr on socket failed");
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = func7(8000);
if ( bind(v4, &addr, 0x10u) < 0 )
{
puts("Error bind port");
v5 = -2;
}
else
{
printf("Bind port %d done\n", 8000LL);
listen(v4, 3);
puts("Waiting client connection");
addr_len[0] = 16;
while ( 1 )
{
v5 = accept(v4, &v12, addr_len);
if ( !v5 )
break;
puts("Connection accepted");
v9 = recv(v5, buf, 0x2710uLL, 0);
if ( v9 >= 0 )
{
parse_http_request(v10, v9, buf);
puts(v10[1]);
puts(v10[2]);
puts(v10[3]);
}
else
{
puts("Error recv");
}
v7 = response;
v8 = strlen(response);
send(v5, v7, v8, 0);
close(v5);
}
}
}
return v5;
}

original_code:
int main(int argc, char *argv[])
{
    int socket_fd, client_socket, addr_size;
    int yes = 1;
    struct sockaddr_in server, client;
    char buffer[10000];
    ssize_t msglen;
    int http_port = 8000;
    socket_fd = socket(2, SOCK_STREAM, 0);
    if (socket_fd == -1)
    {
        puts("Error creating socket");
        return -1;
    }
    if (setsockopt(socket_fd, 1, 2, &yes, sizeof(int)) == -1)
    {
        puts("Set reuse addr on socket failed");
    }
    server.sin_family = 2;
    server.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    server.sin_port = htons(http_port);
    if (bind(socket_fd, (struct sockaddr *) &server, sizeof(server)) < 0)
    {
        puts("Error bind port");
        return -2;
    }
    printf("Bind port %d done\n", http_port);
    listen(socket_fd, 3);
    puts("Waiting client connection");
    addr_size = sizeof(struct sockaddr_in);
    while ((client_socket = accept(socket_fd, (struct sockaddr *) &client, (socklen_t *) &addr_size)))
    {
        http_request request;
        puts("Connection accepted");
        msglen = recv(client_socket, (void *) buffer, sizeof(buffer), 0);
        if (msglen < 0) {
            puts("Error recv");
        }else{
            request = parse_http_request(msglen, buffer);
            puts(request.method);
            puts(request.path);
            puts(request.http_version);
        }
        send(client_socket, response, strlen(response), 0);
        close(client_socket);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int socket_fd; int client_socket; int addr_size;
    int yes = 1;
    struct sockaddr_in server; struct sockaddr_in client;
    char buffer[10000];
    long msglen;
    int http_port = 8000;
    socket_fd = socket(2, SOCK_STREAM, 0);
    if (socket_fd == -1)
    {
        puts("Error creating socket");
        return -1;
    }
    if (setsockopt(socket_fd, 1, 2, &yes, sizeof(int)) == -1)
    {
        puts("Set reuse addr on socket failed");
    }
    server.sin_family = 2;
    server.sin_addr.s_addr = ((unsigned int) 0x00000000);
    server.sin_port = htons(http_port);
    if (bind(socket_fd, (struct sockaddr *) &server, sizeof(server)) < 0)
    {
        puts("Error bind port");
        return -2;
    }
    printf("Bind port %d done\n", http_port);
    listen(socket_fd, 3);
    puts("Waiting client connection");
    addr_size = sizeof(struct sockaddr_in);
    while ((client_socket = accept(socket_fd, (struct sockaddr *) &client, (unsigned int *) &addr_size)))
    {
        struct http_request_data request;
        puts("Connection accepted");
        msglen = recv(client_socket, (void *) buffer, sizeof(buffer), 0);
        if (msglen < 0) {
            puts("Error recv");
        }else{
            request = parse_http_request(msglen, buffer);
            puts(request.method);
            puts(request.path);
            puts(request.http_version);
        }
        send(client_socket, response, strlen(response), 0);
        close(client_socket);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: yes int

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

variable_types:
buffer
char [10000]

variable_types: msglen long

variable_types: struct http_request_data { long len; char *method; char *path; char *http_version; char *host; char *body; }

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


repo: saljs/gspeech

original_code:
size_t parse_json( void *ptr, size_t size, size_t nmemb, void *stream)
{
    char* tmp = malloc(size * nmemb);
    if(tmp == ((void *)0))
        return 1;
    strcpy(tmp, ptr);
    char prev = tmp[0];
    char next = tmp[1];
    int i = 1;
    while(next != '\0')
    {
        if(prev == '[' && next == '{')
        {
            i = i + 14;
            char *message = malloc(size * nmemb);
            int j = 0;
            while(tmp[i] != '"')
            {
                message[j] = tmp[i];
                i++;
                j++;
            }
            message[j] = '\0';
            printf("%s\n", message);
            free(message);
            break;
        }
        prev = tmp[i];
        i++;
        next = tmp[i];
    }
    free(tmp);
}

canonical_original_code:
unsigned long parse_json(void *ptr, unsigned long size, unsigned long nmemb, void *stream)
{
    char *tmp = malloc(size * nmemb);
    if(tmp == ((void *)0))
        return 1;
    strcpy(tmp, ptr);
    char prev = tmp[0];
    char next = tmp[1];
    int i = 1;
    while(next != '\0')
    {
        if(prev == '[' && next == '{')
        {
            i = i + 14;
            char *message = malloc(size * nmemb);
            int j = 0;
            while(tmp[i] != '"')
            {
                message[j] = tmp[i];
                i++;
                j++;
            }
            message[j] = '\0';
            printf("%s\n", message);
            free(message);
            break;
        }
        prev = tmp[i];
        i++;
        next = tmp[i];
    }
    free(tmp);
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
stream
void *

variable_types:
tmp
char *

variable_types: prev char

variable_types: next char

variable_types: i int

variable_types:
message
char *

variable_types: j int

return_type: unsigned long


repo: salmanebah/veclang

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

result = malloc(8uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(8uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
queue queue_create(void){
  queue s = malloc (sizeof (queue));
  s->init = ((void *)0);
  s->current = ((void *)0);
  return s;
}

canonical_original_code:
struct queue_t *queue_create(){
  struct queue_t *s = malloc (sizeof (queue));
  s->init = ((void *)0);
  s->current = ((void *)0);
  return s;
}

variable_types: struct queue_t { struct _cellule { void *car; struct _cellule *cdr; } *init; struct _cellule *current; } *

user_defined_types: struct queue_t { struct _cellule *init; struct _cellule *current; }


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

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

original_code:
void queue_destroy(queue s){
  free(s);
}

canonical_original_code:
void queue_destroy(struct queue_t *s){
  free(s);
}

return_type: void

user_defined_types: struct _cellule { void *car; struct _cellule *cdr; }


decompiled_code:
_BOOL8 __fastcall queue_empty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int queue_empty(queue s){
  return s->init == ((void *)0);
}

canonical_original_code:
int queue_empty(struct queue_t *s){
  return s->init == ((void *)0);
}

return_type: int


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

v1 = queue_empty(a1);
result = 0LL;
if ( !v1 )
result = **a1;
return result;
}

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

v1 = func2(a1);
result = 0LL;
if ( !v1 )
result = **a1;
return result;
}

original_code:
void * queue_front(queue s){
  if (!queue_empty(s))
    return s->init->car;
  return ((void *)0);
}

canonical_original_code:
void *queue_front(struct queue_t *s){
  if (!queue_empty(s))
    return s->init->car;
  return ((void *)0);
}

return_type: void *


decompiled_code:
void __fastcall queue_pop(void **a1)
{
void *v1; // rbp

if ( !queue_empty(a1) )
{
v1 = (void *)*((_QWORD *)*a1 + 1);
free(*a1);
*a1 = v1;
}
}

canonical_decompiled_code:
void __fastcall func5(void **a1)
{
void *v1; // rbp

if ( !func2(a1) )
{
v1 = (void *)*((_QWORD *)*a1 + 1);
free(*a1);
*a1 = v1;
}
}

original_code:
void queue_pop(queue s){
  if (!queue_empty(s)) {
    cellule tmp = s->init->cdr;
    free(s->init);
    s->init = tmp;
  }
}

canonical_original_code:
void queue_pop(struct queue_t *s){
  if (!queue_empty(s)) {
    struct _cellule *tmp = s->init->cdr;
    free(s->init);
    s->init = tmp;
  }
}

variable_types: struct _cellule { void *car; struct _cellule *cdr; } *


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

result = malloc(8uLL);
if ( !result )
_assert_fail("this != NULL", "symtab_management.c", 0x32u, "create_symtable");
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( !result )
_assert_fail("this != NULL", "symtab_management.c", 0x32u, "create_symtable");
*result = 0LL;
return result;
}

original_code:
symtab create_symtable(void)
{
     symtab this = (symtab)malloc(sizeof(struct symtab_t));
     ((this != ((void *)0)) ? (void) (0) : __assert_fail ("this != NULL", "symtab_management.c", 50, __extension__ __PRETTY_FUNCTION__));
     this-> peek = ((void *)0);
     return this;
}

canonical_original_code:
struct symtab_t *create_symtable()
{
     struct symtab_t *this = (symtab)malloc(sizeof(struct symtab_t));
     ((this != ((void *)0)) ? (void) (0) : __assert_fail ("this != NULL", "symtab_management.c", 50, __extension__ __PRETTY_FUNCTION__));
     this-> peek = ((void *)0);
     return this;
}

variable_types: struct symtab_t { struct variable { char *name; _Bool init; int type; union { int scal_value; struct ast_t { enum node_type { NUMBER=0, VARIABLE=1, BINARY_OP=2, FUNCTION=3, INTERNAL=4 } type; union { char *node_name; int node_value; char operation; }; struct ast_t *right; struct ast_t *left; } *path_value; }; struct variable *next; } *peek; } *

user_defined_types: struct symtab_t { struct variable *peek; }

user_defined_types: struct variable { char *name; _Bool init; int type; union { int scal_value; struct ast_t *path_value; }; struct variable *next; }

user_defined_types: struct ast_t { enum node_type type; union { char *node_name; int node_value; char operation; }; struct ast_t *right; struct ast_t *left; }


decompiled_code:
void __fastcall free_symtable(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *i; // rbx

v2 = *(_QWORD **)ptr;
if ( v2 )
{
for ( i = (_QWORD *)v2[3]; i; i = (_QWORD *)i[3] )
{
free(v2);
v2 = i;
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *i; // rbx

v2 = *(_QWORD **)ptr;
if ( v2 )
{
for ( i = (_QWORD *)v2[3]; i; i = (_QWORD *)i[3] )
{
free(v2);
v2 = i;
}
}
free(ptr);
}

original_code:
void free_symtable(symtab self)
{
     variable current ;
     variable next_current;
     if (self-> peek == ((void *)0))
   free(self);
     else
     {
   for (current = self-> peek , next_current = current-> next;
        next_current != ((void *)0) ;
        current = next_current , next_current = next_current-> next)
        free(current);
   free(self);
     }
}

canonical_original_code:
void free_symtable(struct symtab_t *self)
{
     struct variable *current;
     struct variable *next_current;
     if (self-> peek == ((void *)0))
   free(self);
     else
     {
   for (current = self-> peek , next_current = current-> next;
        next_current != ((void *)0) ;
        current = next_current , next_current = next_current-> next)
        free(current);
   free(self);
     }
}

variable_types: struct variable { char *name; _Bool init; int type; union { int scal_value; struct ast_t { enum node_type { NUMBER=0, VARIABLE=1, BINARY_OP=2, FUNCTION=3, INTERNAL=4 } type; union { char *node_name; int node_value; char operation; }; struct ast_t *right; struct ast_t *left; } *path_value; }; struct variable *next; } *


lookup

decompiled_code:
__int64 __fastcall lookup(__int64 *a1, const char *a2)
{
__int64 i; // rbx

for ( i = *a1; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, const char *a2)
{
__int64 i; // rbx

for ( i = *a1; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

original_code:
variable lookup(symtab this , char* name)
{
     variable iterator;
     for(iterator = this-> peek ; iterator != ((void *)0) ; iterator = iterator-> next)
   if (strcmp(iterator-> name , name) == 0)
        return iterator;
     return ((void *)0);
}

canonical_original_code:
struct variable *lookup(struct symtab_t *this, char *name)
{
     struct variable *iterator;
     for(iterator = this-> peek ; iterator != ((void *)0) ; iterator = iterator-> next)
   if (strcmp(iterator-> name , name) == 0)
        return iterator;
     return ((void *)0);
}

variable_types: struct symtab_t { struct variable *peek; } *

variable_types:
name
char *

return_type: struct variable { char *name; _Bool init; int type; union { int scal_value; struct ast_t { enum node_type { NUMBER=0, VARIABLE=1, BINARY_OP=2, FUNCTION=3, INTERNAL=4 } type; union { char *node_name; int node_value; char operation; }; struct ast_t *right; struct ast_t *left; } *path_value; }; struct variable *next; } *


decompiled_code:
__int64 __fastcall get_scal_value(__int64 a1)
{
if ( !a1 || *(_DWORD *)(a1 + 12) )
_assert_fail("var != NULL && var-> type == SCAL_TYPE", "symtab_management.c", 0x5Eu, "get_scal_value");
if ( !*(_BYTE *)(a1 + 8) )
{
printf("\x1B[31msemantic error\x1B[0m: variable %s used but not assign\n", *(const char **)a1);
exit(1);
}
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !a1 || *(_DWORD *)(a1 + 12) )
_assert_fail("var != NULL && var-> type == SCAL_TYPE", "symtab_management.c", 0x5Eu, "get_scal_value");
if ( !*(_BYTE *)(a1 + 8) )
{
printf("\x1B[31msemantic error\x1B[0m: variable %s used but not assign\n", *(const char **)a1);
exit(1);
}
return *(unsigned int *)(a1 + 16);
}

original_code:
int get_scal_value (variable var)
{
     ((var != ((void *)0) && var-> type == 0) ? (void) (0) : __assert_fail ("var != NULL && var-> type == SCAL_TYPE", "symtab_management.c", 94, __extension__ __PRETTY_FUNCTION__));
     if (var-> init == 0)
     {
   printf("\033[31msemantic error\033[0m: variable %s used but not assign\n" , var-> name);
   exit(1);
     }
     return var-> scal_value;
}

canonical_original_code:
int get_scal_value(struct variable *var)
{
     ((var != ((void *)0) && var-> type == 0) ? (void) (0) : __assert_fail ("var != NULL && var-> type == SCAL_TYPE", "symtab_management.c", 94, __extension__ __PRETTY_FUNCTION__));
     if (var-> init == 0)
     {
   printf("\033[31msemantic error\033[0m: variable %s used but not assign\n" , var-> name);
   exit(1);
     }
     return var-> scal_value;
}

user_defined_types: enum node_type { NUMBER=0, VARIABLE=1, BINARY_OP=2, FUNCTION=3, INTERNAL=4 }


decompiled_code:
__int64 __fastcall get_path_value(__int64 a1)
{
if ( !a1 || (unsigned int)(*(_DWORD *)(a1 + 12) - 1) > 1 )
_assert_fail(
"var != NULL && (var-> type == PATH_TYPE || var-> type == PICT_TYPE)",
"symtab_management.c",
0x69u,
"get_path_value");
if ( !*(_BYTE *)(a1 + 8) )
{
printf("\x1B[31msemantic error\x1B[0m: variable %s used but not assign\n", *(const char **)a1);
exit(1);
}
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( !a1 || (unsigned int)(*(_DWORD *)(a1 + 12) - 1) > 1 )
_assert_fail(
"var != NULL && (var-> type == PATH_TYPE || var-> type == PICT_TYPE)",
"symtab_management.c",
0x69u,
"get_path_value");
if ( !*(_BYTE *)(a1 + 8) )
{
printf("\x1B[31msemantic error\x1B[0m: variable %s used but not assign\n", *(const char **)a1);
exit(1);
}
return *(_QWORD *)(a1 + 16);
}

original_code:
ast get_path_value (variable var)
{
     ((var != ((void *)0) && (var-> type == 1 || var-> type == 2)) ? (void) (0) : __assert_fail ("var != NULL && (var-> type == PATH_TYPE || var-> type == PICT_TYPE)", "symtab_management.c", 105, __extension__ __PRETTY_FUNCTION__));
     if (var-> init == 0)
     {
   printf("\033[31msemantic error\033[0m: variable %s used but not assign\n" , var-> name);
   exit(1);
     }
     return var-> path_value;
}

canonical_original_code:
struct ast_t *get_path_value(struct variable *var)
{
     ((var != ((void *)0) && (var-> type == 1 || var-> type == 2)) ? (void) (0) : __assert_fail ("var != NULL && (var-> type == PATH_TYPE || var-> type == PICT_TYPE)", "symtab_management.c", 105, __extension__ __PRETTY_FUNCTION__));
     if (var-> init == 0)
     {
   printf("\033[31msemantic error\033[0m: variable %s used but not assign\n" , var-> name);
   exit(1);
     }
     return var-> path_value;
}

variable_types: struct variable { char *name; _Bool init; int type; union { int scal_value; struct ast_t *path_value; }; struct variable *next; } *

return_type: struct ast_t { enum node_type { NUMBER=0, VARIABLE=1, BINARY_OP=2, FUNCTION=3, INTERNAL=4 } type; union { char *node_name; int node_value; char operation; }; struct ast_t *right; struct ast_t *left; } *


decompiled_code:
void __fastcall set_scal_value(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("var != NULL", "symtab_management.c", 0x74u, "set_scal_value");
*(_BYTE *)(a1 + 8) = 1;
*(_DWORD *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("var != NULL", "symtab_management.c", 0x74u, "set_scal_value");
*(_BYTE *)(a1 + 8) = 1;
*(_DWORD *)(a1 + 16) = a2;
}

original_code:
void set_scal_value(variable var , int val)
{
     ((var != ((void *)0)) ? (void) (0) : __assert_fail ("var != NULL", "symtab_management.c", 116, __extension__ __PRETTY_FUNCTION__));
     var-> init = 1;
     var-> scal_value = val;
}

canonical_original_code:
void set_scal_value(struct variable *var, int val)
{
     ((var != ((void *)0)) ? (void) (0) : __assert_fail ("var != NULL", "symtab_management.c", 116, __extension__ __PRETTY_FUNCTION__));
     var-> init = 1;
     var-> scal_value = val;
}

variable_types: val int


decompiled_code:
void __fastcall set_path_value(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("var != NULL", "symtab_management.c", 0x7Au, "set_path_value");
*(_BYTE *)(a1 + 8) = 1;
*(_QWORD *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("var != NULL", "symtab_management.c", 0x7Au, "set_path_value");
*(_BYTE *)(a1 + 8) = 1;
*(_QWORD *)(a1 + 16) = a2;
}

original_code:
void set_path_value(variable var , ast root)
{
     ((var != ((void *)0)) ? (void) (0) : __assert_fail ("var != NULL", "symtab_management.c", 122, __extension__ __PRETTY_FUNCTION__));
     var-> init = 1;
     var-> path_value = root;
}

canonical_original_code:
void set_path_value(struct variable *var, struct ast_t *root)
{
     ((var != ((void *)0)) ? (void) (0) : __assert_fail ("var != NULL", "symtab_management.c", 122, __extension__ __PRETTY_FUNCTION__));
     var-> init = 1;
     var-> path_value = root;
}

variable_types:
root
struct ast_t *


decompiled_code:
__int64 __fastcall get_var_type(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int get_var_type(variable var)
{
     return var-> type;
}

canonical_original_code:
int get_var_type(struct variable *var)
{
     return var-> type;
}


decompiled_code:
__int64 __fastcall get_var_name(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char* get_var_name(variable var)
{
     return var-> name;
}

canonical_original_code:
char *get_var_name(struct variable *var)
{
     return var-> name;
}

return_type: char *


decompiled_code:
__int64 __fastcall apply_translation_aux(__int64 a1, unsigned int a2, int a3)
{
__int64 result; // rax

if ( a1 )
{
if ( !strcmp(*(const char **)(a1 + 8), "cartesian_point") )
{
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 8LL) += a2;
result = *(_QWORD *)(a1 + 16);
*(_DWORD *)(result + 8) += a3;
}
else
{
apply_translation_aux(*(_QWORD *)(a1 + 24), a2);
result = apply_translation_aux(*(_QWORD *)(a1 + 16), a2);
}
}
return result;
}

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

if ( a1 )
{
if ( !strcmp(*(const char **)(a1 + 8), "cartesian_point") )
{
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 8LL) += a2;
result = *(_QWORD *)(a1 + 16);
*(_DWORD *)(result + 8) += a3;
}
else
{
func0(*(_QWORD *)(a1 + 24), a2);
result = func0(*(_QWORD *)(a1 + 16), a2);
}
}
return result;
}

original_code:
void apply_translation_aux(ast param , int dx , int dy)
{
     if (param == ((void *)0))
   return;
     else if (strcmp(param-> node_name , "cartesian_point") == 0)
     {
   param-> left-> node_value += dx;
   param-> right-> node_value += dy;
     }
     else
     {
   apply_translation_aux(param-> left , dx , dy);
   apply_translation_aux(param-> right, dx , dy);
     }
}

canonical_original_code:
void apply_translation_aux(struct ast_t *param, int dx, int dy)
{
     if (param == ((void *)0))
   return;
     else if (strcmp(param-> node_name , "cartesian_point") == 0)
     {
   param-> left-> node_value += dx;
   param-> right-> node_value += dy;
     }
     else
     {
   apply_translation_aux(param-> left , dx , dy);
   apply_translation_aux(param-> right, dx , dy);
     }
}

variable_types: struct ast_t { enum node_type { NUMBER=0, VARIABLE=1, BINARY_OP=2, FUNCTION=3, INTERNAL=4 } type; union { char *node_name; int node_value; char operation; }; struct ast_t *right; struct ast_t *left; } *

variable_types: dx int

variable_types: dy int


decompiled_code:
int __fastcall sim_mark(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(124);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(124);
}
return result;
}

original_code:
static void sim_mark(int n)
{
     int i;
     for( i = 0 ; i < n ; ++i)
   printf("|");
}

variable_types: n int


decompiled_code:
char *__fastcall different_node_name(const char *a1, unsigned int a2)
{
char *v2; // rax
char *v3; // rbx

v2 = (char *)malloc(0xAuLL);
if ( !v2 )
_assert_fail("to_return != NULL", "ast.c", 0xEBu, "different_node_name");
v3 = v2;
sprintf(v2, "%s_%d", a1, a2);
return v3;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, unsigned int a2)
{
char *v2; // rax
char *v3; // rbx

v2 = (char *)malloc(0xAuLL);
if ( !v2 )
_assert_fail("to_return != NULL", "ast.c", 0xEBu, "different_node_name");
v3 = v2;
sprintf(v2, "%s_%d", a1, a2);
return v3;
}

original_code:
char* different_node_name(char* node_name , int i)
{
     char* to_return = (char*)malloc(sizeof(strlen(node_name)) + 2);
     ((to_return != ((void *)0)) ? (void) (0) : __assert_fail ("to_return != NULL", "ast.c", 235, __extension__ __PRETTY_FUNCTION__));
     sprintf(to_return , "%s_%d" , node_name , i);
     return to_return;
}

canonical_original_code:
char *different_node_name(char *node_name, int i)
{
     char *to_return = (char*)malloc(sizeof(strlen(node_name)) + 2);
     ((to_return != ((void *)0)) ? (void) (0) : __assert_fail ("to_return != NULL", "ast.c", 235, __extension__ __PRETTY_FUNCTION__));
     sprintf(to_return , "%s_%d" , node_name , i);
     return to_return;
}


original_code:
void apply_rotation_aux(ast param , int cx , int cy , float angle)
{
     if (param == ((void *)0))
   return;
     else if (strcmp(param-> node_name , "cartesian_point") == 0)
     {
   int px = param-> left-> node_value;
   int py = param-> right-> node_value;
   int ppx = ceil(cos(angle) * (px - cx) - sin(angle) * (py - cy) + cx);
   int ppy = ceil(sin(angle) * (px - cx) + cos(angle) * (py - cy) + cy);
   param-> left-> node_value = ppx;
   param-> right-> node_value = ppy;
     }
     else
     {
   apply_rotation_aux(param-> left , cx , cy , angle);
   apply_rotation_aux(param-> right , cx , cy , angle);
     }
}

canonical_original_code:
void apply_rotation_aux(struct ast_t *param, int cx, int cy, float angle)
{
     if (param == ((void *)0))
   return;
     else if (strcmp(param-> node_name , "cartesian_point") == 0)
     {
   int px = param-> left-> node_value;
   int py = param-> right-> node_value;
   int ppx = ceil(cos(angle) * (px - cx) - sin(angle) * (py - cy) + cx);
   int ppy = ceil(sin(angle) * (px - cx) + cos(angle) * (py - cy) + cy);
   param-> left-> node_value = ppx;
   param-> right-> node_value = ppy;
     }
     else
     {
   apply_rotation_aux(param-> left , cx , cy , angle);
   apply_rotation_aux(param-> right , cx , cy , angle);
     }
}

variable_types: cx int

variable_types: cy int

variable_types: angle float

variable_types: px int

variable_types: py int

variable_types: ppx int

variable_types: ppy int


decompiled_code:
__int64 __fastcall eval_binary_ast(__int64 a1)
{
__int64 result; // rax
int v2; // ebp
int v3; // ebp
int v4; // ebp
int v5; // ebp
int v6; // ebp
int v7; // ebp
int v8; // ebp
int v9; // ebp
int v10; // ebp
int v11; // ebp

if ( !*(_DWORD *)a1 )
return *(unsigned int *)(a1 + 8);
switch ( *(_BYTE *)(a1 + 8) )
{
case '*':
v3 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v3 * (unsigned int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case '+':
v2 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v2 + (unsigned int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case '-':
v4 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v4 - (unsigned int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case '/':
v5 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = (unsigned int)(v5 / (int)eval_binary_ast(*(_QWORD *)(a1 + 16)));
break;
case '<':
v6 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v6 < (int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case '=':
v10 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v10 == (unsigned int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case '>':
v8 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v8 > (int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case 'd':
v11 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v11 != (unsigned int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case 'l':
v7 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v7 <= (int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
case 'm':
v9 = eval_binary_ast(*(_QWORD *)(a1 + 24));
result = v9 >= (int)eval_binary_ast(*(_QWORD *)(a1 + 16));
break;
default:
printf("error while node evaluation");
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
int v2; // ebp
int v3; // ebp
int v4; // ebp
int v5; // ebp
int v6; // ebp
int v7; // ebp
int v8; // ebp
int v9; // ebp
int v10; // ebp
int v11; // ebp

if ( !*(_DWORD *)a1 )
return *(unsigned int *)(a1 + 8);
switch ( *(_BYTE *)(a1 + 8) )
{
case '*':
v3 = func5(*(_QWORD *)(a1 + 24));
result = v3 * (unsigned int)func5(*(_QWORD *)(a1 + 16));
break;
case '+':
v2 = func5(*(_QWORD *)(a1 + 24));
result = v2 + (unsigned int)func5(*(_QWORD *)(a1 + 16));
break;
case '-':
v4 = func5(*(_QWORD *)(a1 + 24));
result = v4 - (unsigned int)func5(*(_QWORD *)(a1 + 16));
break;
case '/':
v5 = func5(*(_QWORD *)(a1 + 24));
result = (unsigned int)(v5 / (int)func5(*(_QWORD *)(a1 + 16)));
break;
case '<':
v6 = func5(*(_QWORD *)(a1 + 24));
result = v6 < (int)func5(*(_QWORD *)(a1 + 16));
break;
case '=':
v10 = func5(*(_QWORD *)(a1 + 24));
result = v10 == (unsigned int)func5(*(_QWORD *)(a1 + 16));
break;
case '>':
v8 = func5(*(_QWORD *)(a1 + 24));
result = v8 > (int)func5(*(_QWORD *)(a1 + 16));
break;
case 'd':
v11 = func5(*(_QWORD *)(a1 + 24));
result = v11 != (unsigned int)func5(*(_QWORD *)(a1 + 16));
break;
case 'l':
v7 = func5(*(_QWORD *)(a1 + 24));
result = v7 <= (int)func5(*(_QWORD *)(a1 + 16));
break;
case 'm':
v9 = func5(*(_QWORD *)(a1 + 24));
result = v9 >= (int)func5(*(_QWORD *)(a1 + 16));
break;
default:
printf("error while node evaluation");
exit(1);
}
return result;
}

original_code:
int eval_binary_ast(ast node)
{
     if (node-> type == NUMBER)
   return node-> node_value;
     else
     {
   switch(node-> operation)
   {
   case '+':
        return eval_binary_ast(node-> left) + eval_binary_ast(node-> right);
   case '*' :
        return eval_binary_ast(node-> left) * eval_binary_ast(node-> right);
   case '-':
        return eval_binary_ast(node-> left) - eval_binary_ast(node-> right);
   case '/':
        return eval_binary_ast(node-> left) / eval_binary_ast(node-> right);
   case '<':
        return eval_binary_ast(node-> left) < eval_binary_ast(node-> right);
   case 'l' :
        return eval_binary_ast(node-> left) <= eval_binary_ast(node-> right);
   case '>':
        return eval_binary_ast(node-> left) > eval_binary_ast(node-> right);
   case 'm':
        return eval_binary_ast(node-> left) >= eval_binary_ast(node-> right);
   case '=':
        return eval_binary_ast(node-> left) == eval_binary_ast(node-> right);
   case 'd' :
        return eval_binary_ast(node-> left) != eval_binary_ast(node-> right);
   default:
        printf("error while node evaluation");
        exit(1);
   }
     }
}

canonical_original_code:
int eval_binary_ast(struct ast_t *node)
{
     if (node-> type == NUMBER)
   return node-> node_value;
     else
     {
   switch(node-> operation)
   {
   case '+':
        return eval_binary_ast(node-> left) + eval_binary_ast(node-> right);
   case '*' :
        return eval_binary_ast(node-> left) * eval_binary_ast(node-> right);
   case '-':
        return eval_binary_ast(node-> left) - eval_binary_ast(node-> right);
   case '/':
        return eval_binary_ast(node-> left) / eval_binary_ast(node-> right);
   case '<':
        return eval_binary_ast(node-> left) < eval_binary_ast(node-> right);
   case 'l' :
        return eval_binary_ast(node-> left) <= eval_binary_ast(node-> right);
   case '>':
        return eval_binary_ast(node-> left) > eval_binary_ast(node-> right);
   case 'm':
        return eval_binary_ast(node-> left) >= eval_binary_ast(node-> right);
   case '=':
        return eval_binary_ast(node-> left) == eval_binary_ast(node-> right);
   case 'd' :
        return eval_binary_ast(node-> left) != eval_binary_ast(node-> right);
   default:
        printf("error while node evaluation");
        exit(1);
   }
     }
}


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

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

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

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

original_code:
int is_leaf (ast node)
{
     return (node-> right == ((void *)0) && node-> left == ((void *)0));
}

canonical_original_code:
int is_leaf(struct ast_t *node)
{
     return (node-> right == ((void *)0) && node-> left == ((void *)0));
}


decompiled_code:
void __fastcall free_ast(_QWORD *a1)
{
if ( !is_leaf((__int64)a1) )
{
if ( a1[2] )
free_ast();
if ( a1[3] )
free_ast();
}
free(a1);
}

canonical_decompiled_code:
void __fastcall func7(_QWORD *a1)
{
if ( !func6((__int64)a1) )
{
if ( a1[2] )
func7();
if ( a1[3] )
func7();
}
free(a1);
}

original_code:
void free_ast (ast node)
{
     if (is_leaf(node))
   free(node);
     else
     {
        if (node-> right != ((void *)0))
        free_ast(node-> right);
        if (node-> left != ((void *)0))
        free_ast(node-> left);
   free(node);
     }
}

canonical_original_code:
void free_ast(struct ast_t *node)
{
     if (is_leaf(node))
   free(node);
     else
     {
        if (node-> right != ((void *)0))
        free_ast(node-> right);
        if (node-> left != ((void *)0))
        free_ast(node-> left);
   free(node);
     }
}


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

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

original_code:
int get_node_type(ast node)
{
     return node-> type;
}

canonical_original_code:
int get_node_type(struct ast_t *node)
{
     return node-> type;
}


decompiled_code:
unsigned int __fastcall print_ast(__int64 a1, int a2)
{
unsigned int result; // eax
__int64 v4; // rdi
__int64 v5; // rdi

if ( is_leaf(a1) )
{
if ( *(_DWORD *)a1 )
result = puts(*(const char **)(a1 + 8));
else
result = printf("%d\n", *(unsigned int *)(a1 + 8));
}
else
{
if ( *(_DWORD *)a1 == 2 )
{
sim_mark(a2);
result = printf("%c\n", (unsigned int)*(char *)(a1 + 8));
}
else
{
result = *(_DWORD *)a1 - 3;
if ( result <= 1 )
{
sim_mark(a2);
result = puts(*(const char **)(a1 + 8));
}
}
v4 = *(_QWORD *)(a1 + 24);
if ( v4 )
result = print_ast(v4, (unsigned int)(a2 + 1));
v5 = *(_QWORD *)(a1 + 16);
if ( v5 )
result = print_ast(v5, (unsigned int)(a2 + 1));
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func9(__int64 a1, int a2)
{
unsigned int result; // eax
__int64 v4; // rdi
__int64 v5; // rdi

if ( func6(a1) )
{
if ( *(_DWORD *)a1 )
result = puts(*(const char **)(a1 + 8));
else
result = printf("%d\n", *(unsigned int *)(a1 + 8));
}
else
{
if ( *(_DWORD *)a1 == 2 )
{
func1(a2);
result = printf("%c\n", (unsigned int)*(char *)(a1 + 8));
}
else
{
result = *(_DWORD *)a1 - 3;
if ( result <= 1 )
{
func1(a2);
result = puts(*(const char **)(a1 + 8));
}
}
v4 = *(_QWORD *)(a1 + 24);
if ( v4 )
result = func9(v4, (unsigned int)(a2 + 1));
v5 = *(_QWORD *)(a1 + 16);
if ( v5 )
result = func9(v5, (unsigned int)(a2 + 1));
}
return result;
}

original_code:
void print_ast (ast node , int padding)
{
     if (!is_leaf (node))
     {
   if (node-> type == BINARY_OP)
   {
        sim_mark(padding);
        printf("%c\n" , node-> operation);
   }
   else if (node-> type == INTERNAL || node-> type == FUNCTION)
   {
        sim_mark(padding);
        printf("%s\n" , node-> node_name);
   }
   if (node-> left != ((void *)0))
        print_ast(node-> left , padding + 1);
   if (node-> right != ((void *)0))
        print_ast(node-> right , padding + 1);
     }
     else
     {
   if (node-> type == NUMBER)
        printf("%d\n" , node-> node_value);
   else
        printf("%s\n" , node-> node_name);
     }
}

canonical_original_code:
void print_ast(struct ast_t *node, int padding)
{
     if (!is_leaf (node))
     {
   if (node-> type == BINARY_OP)
   {
        sim_mark(padding);
        printf("%c\n" , node-> operation);
   }
   else if (node-> type == INTERNAL || node-> type == FUNCTION)
   {
        sim_mark(padding);
        printf("%s\n" , node-> node_name);
   }
   if (node-> left != ((void *)0))
        print_ast(node-> left , padding + 1);
   if (node-> right != ((void *)0))
        print_ast(node-> right , padding + 1);
     }
     else
     {
   if (node-> type == NUMBER)
        printf("%d\n" , node-> node_value);
   else
        printf("%s\n" , node-> node_name);
     }
}

variable_types: padding int


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

if ( !a1 )
_assert_fail("param != NULL", "ast.c", 0xF3u, "merge_param");
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
*(_QWORD *)(result + 16) = a2;
return result;
}

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

if ( !a1 )
_assert_fail("param != NULL", "ast.c", 0xF3u, "merge_param");
do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
*(_QWORD *)(result + 16) = a2;
return result;
}

original_code:
void merge_param (ast param , ast relative_param)
{
     ((param != ((void *)0)) ? (void) (0) : __assert_fail ("param != NULL", "ast.c", 243, __extension__ __PRETTY_FUNCTION__));
     ast merge_node = param;
     while(merge_node-> right != ((void *)0))
   merge_node = merge_node-> right;
     merge_node-> right = relative_param;
}

canonical_original_code:
void merge_param(struct ast_t *param, struct ast_t *relative_param)
{
     ((param != ((void *)0)) ? (void) (0) : __assert_fail ("param != NULL", "ast.c", 243, __extension__ __PRETTY_FUNCTION__));
     struct ast_t *merge_node = param;
     while(merge_node-> right != ((void *)0))
   merge_node = merge_node-> right;
     merge_node-> right = relative_param;
}


decompiled_code:
__int64 __fastcall binary_expr_to_number(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rax

v2 = eval_binary_ast();
v3 = create_number_node(v2);
if ( *(_QWORD *)(a2 + 24) == a1 )
*(_QWORD *)(a2 + 24) = v3;
else
*(_QWORD *)(a2 + 16) = v3;
return free_ast(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rax

v2 = eval_binary_ast();
v3 = create_number_node(v2);
if ( *(_QWORD *)(a2 + 24) == a1 )
*(_QWORD *)(a2 + 24) = v3;
else
*(_QWORD *)(a2 + 16) = v3;
return free_ast(a1);
}

original_code:
void binary_expr_to_number(ast root , ast parent)
{
     int val = eval_binary_ast(root);
     ast node = create_number_node(val);
     if (root == parent-> left)
   parent-> left = node;
     else
   parent-> right = node;
     free_ast(root);
}

canonical_original_code:
void binary_expr_to_number(struct ast_t *root, struct ast_t *parent)
{
     int val = eval_binary_ast(root);
     struct ast_t *node = create_number_node(val);
     if (root == parent-> left)
   parent-> left = node;
     else
   parent-> right = node;
     free_ast(root);
}

variable_types:
parent
struct ast_t *


decompiled_code:
__int64 __fastcall cartesian_expr_to_simple(__int64 a1)
{
binary_expr_to_number(*(_QWORD *)(a1 + 24), a1);
return binary_expr_to_number(*(_QWORD *)(a1 + 16), a1);
}

original_code:
void cartesian_expr_to_simple(ast root)
{
     binary_expr_to_number(root-> left , root);
     binary_expr_to_number(root-> right , root);
}

canonical_original_code:
void cartesian_expr_to_simple(struct ast_t *root)
{
     binary_expr_to_number(root-> left , root);
     binary_expr_to_number(root-> right , root);
}


decompiled_code:
__int64 __fastcall cycle_to_point(__int64 a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a3 + 24) = a2;
return free_ast(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a3 + 24) = a2;
return free_ast(a1);
}

original_code:
void cycle_to_point(ast root , ast first_param , ast parent)
{
     parent-> left = first_param;
     free_ast(root);
     return;
}

canonical_original_code:
void cycle_to_point(struct ast_t *root, struct ast_t *first_param, struct ast_t *parent)
{
     parent-> left = first_param;
     free_ast(root);
     return;
}


decompiled_code:
char *__fastcall veclang_name_to_c_name(char *string)
{
size_t v1; // rbx
char *result; // rax

v1 = (int)(strlen(string) - 1);
result = strndup(string, v1);
result[v1 - 1] = 99;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *string)
{
size_t v1; // rbx
char *result; // rax

v1 = (int)(strlen(string) - 1);
result = strndup(string, v1);
result[v1 - 1] = 99;
return result;
}

original_code:
char* veclang_name_to_c_name(char* file)
{
     int len = strlen(file) - 1;
     char* c_name = strndup(file , sizeof(char) * len);
     c_name[len - 1] = 'c';
     return c_name;
}

canonical_original_code:
char *veclang_name_to_c_name(char *file)
{
     int len = strlen(file) - 1;
     char *c_name = strndup(file , sizeof(char) * len);
     c_name[len - 1] = 'c';
     return c_name;
}

variable_types:
file
char *

variable_types: len int


decompiled_code:
__int64 __fastcall first_pass(_QWORD *a1)
{
bool v2; // cf
bool v3; // zf
const char *v4; // rdx
const char *v5; // rdi
__int64 v6; // rcx
const char *v7; // rsi
char v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
__int64 result; // rax

if ( a1 )
{
v2 = *(_DWORD *)a1 < 4u;
v3 = *(_DWORD *)a1 == 4;
if ( *(_DWORD *)a1 == 4 )
{
v4 = (const char *)a1[1];
v5 = "cartesian_point";
v6 = 16LL;
v7 = v4;
do
{
if ( !v6 )
break;
v2 = *v7 < (unsigned int)*v5;
v3 = *v7++ == *v5++;
--v6;
}
while ( v3 );
v8 = (!v2 && !v3) - v2;
v9 = 0;
v10 = v8 == 0;
if ( v8 )
{
v11 = "polar_point";
v12 = 12LL;
v7 = v4;
do
{
if ( !v12 )
break;
v9 = *v7 < (unsigned int)*v11;
v10 = *v7++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
polar_node_to_cartesian(a1);
}
else
{
cartesian_expr_to_simple((__int64)a1);
}
first_pass(a1[3], v7);
result = first_pass(a1[2], v7);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
bool v2; // cf
bool v3; // zf
const char *v4; // rdx
const char *v5; // rdi
__int64 v6; // rcx
const char *v7; // rsi
char v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
__int64 result; // rax

if ( a1 )
{
v2 = *(_DWORD *)a1 < 4u;
v3 = *(_DWORD *)a1 == 4;
if ( *(_DWORD *)a1 == 4 )
{
v4 = (const char *)a1[1];
v5 = "cartesian_point";
v6 = 16LL;
v7 = v4;
do
{
if ( !v6 )
break;
v2 = *v7 < (unsigned int)*v5;
v3 = *v7++ == *v5++;
--v6;
}
while ( v3 );
v8 = (!v2 && !v3) - v2;
v9 = 0;
v10 = v8 == 0;
if ( v8 )
{
v11 = "polar_point";
v12 = 12LL;
v7 = v4;
do
{
if ( !v12 )
break;
v9 = *v7 < (unsigned int)*v11;
v10 = *v7++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
func7(a1);
}
else
{
func5((__int64)a1);
}
func10(a1[3], v7);
result = func10(a1[2], v7);
}
}
return result;
}

original_code:
void first_pass (ast root)
{
          if (root != ((void *)0))
   {
        if (root-> type == INTERNAL)
        {
      if (strcmp(root-> node_name , "cartesian_point") == 0)
    cartesian_expr_to_simple(root);
      else if (strcmp(root-> node_name , "polar_point") == 0)
    polar_node_to_cartesian(root);
      first_pass(root-> left);
      first_pass(root-> right);
        }
   }
 }

canonical_original_code:
void first_pass(struct ast_t *root)
{
          if (root != ((void *)0))
   {
        if (root-> type == INTERNAL)
        {
      if (strcmp(root-> node_name , "cartesian_point") == 0)
    cartesian_expr_to_simple(root);
      else if (strcmp(root-> node_name , "polar_point") == 0)
    polar_node_to_cartesian(root);
      first_pass(root-> left);
      first_pass(root-> right);
        }
   }
 }


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

if ( a1 )
{
if ( *(_DWORD *)a1 == 3 && !strcmp(*(const char **)(a1 + 8), "cycle") )
cycle_to_point(a1, a2, a3);
second_pass_aux(*(_QWORD *)(a1 + 24), a2, a1);
result = second_pass_aux(*(_QWORD *)(a1 + 16), a2, a1);
}
return result;
}

original_code:
void second_pass_aux(ast root , ast first_param , ast parent)
{
     if (root != ((void *)0))
     {
   if (root-> type == FUNCTION)
        if (strcmp(root-> node_name , "cycle") == 0)
      cycle_to_point(root , first_param , parent);
   second_pass_aux(root-> left , first_param , root);
   second_pass_aux(root-> right , first_param , root);
     }
}

canonical_original_code:
void second_pass_aux(struct ast_t *root, struct ast_t *first_param, struct ast_t *parent)
{
     if (root != ((void *)0))
     {
   if (root-> type == FUNCTION)
        if (strcmp(root-> node_name , "cycle") == 0)
      cycle_to_point(root , first_param , parent);
   second_pass_aux(root-> left , first_param , root);
   second_pass_aux(root-> right , first_param , root);
     }
}


repo: salmito/C-fun

decompiled_code:
int __fastcall dump_graph(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 8) )
result = printf("%s -> %s\n", ***(const char ****)i, **(const char ***)(*(_QWORD *)i + 8LL));
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 8) )
result = printf("%s -> %s\n", ***(const char ****)i, **(const char ***)(*(_QWORD *)i + 8LL));
return result;
}

original_code:
void dump_graph(list g) {
 element cur=g->head;
 while(cur) {
  printf("%s -> %s\n",(char *)((node)((edge)cur->ptr)->begin)->ptr,(char *)((node)((edge)cur->ptr)->end)->ptr);
  cur = cur->next;
 }
}

canonical_original_code:
void dump_graph(struct list_t *g) {
 struct element_t *cur = g->head;
 while(cur) {
  printf("%s -> %s\n",(char *)((node)((struct edge_t *)cur->ptr)->begin)->ptr,(char *)((node)((struct edge_t *)cur->ptr)->end)->ptr);
  cur = cur->next;
 }
}

variable_types: struct list_t { struct element_t { void *ptr; struct element_t *next; struct element_t *prev; } *head; struct element_t *tail; unsigned long size; } *

user_defined_types: struct list_t { struct element_t *head; struct element_t *tail; unsigned long size; }

user_defined_types: struct edge_t { struct node_t *begin; struct node_t *end; }


decompiled_code:
void *create_list()
{
return calloc(1uLL, 0x18uLL);
}

canonical_decompiled_code:
void *func8()
{
return calloc(1uLL, 0x18uLL);
}

original_code:
list create_list() {
 return calloc(1,sizeof(struct list_t));
}

canonical_original_code:
struct list_t *create_list() {
 return calloc(1,sizeof(struct list_t));
}

return_type: struct list_t { struct element_t { void *ptr; struct element_t *next; struct element_t *prev; } *head; struct element_t *tail; unsigned long size; } *


original_code:
void * list_pop(list l) {
 struct element_t * el=l->tail;
 if(!el)
  return ((void *)0);
 void * ret=el->ptr;
 if(el->prev==((void *)0))
  l->head=((void *)0);
 l->tail=el->prev;
 free(el);
 l->size--;
 return ret;
}

canonical_original_code:
void *list_pop(struct list_t *l) {
 struct element_t *el = l->tail;
 if(!el)
  return ((void *)0);
 void *ret = el->ptr;
 if(el->prev==((void *)0))
  l->head=((void *)0);
 l->tail=el->prev;
 free(el);
 l->size--;
 return ret;
}

variable_types: struct element_t { void *ptr; struct element_t *next; struct element_t *prev; } *

variable_types:
ret
void *


decompiled_code:
int __fastcall dump_int_list(unsigned int **a1)
{
unsigned int *v1; // rbx
int result; // eax
unsigned int v3; // ebp

v1 = *a1;
result = printf("Numer of elements on the list: %zu\n", (size_t)a1[2]);
if ( v1 )
{
v3 = 1;
do
{
result = printf("Element %d: %d\n", v3++, *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int **a1)
{
unsigned int *v1; // rbx
int result; // eax
unsigned int v3; // ebp

v1 = *a1;
result = printf("Numer of elements on the list: %zu\n", (size_t)a1[2]);
if ( v1 )
{
v3 = 1;
do
{
result = printf("Element %d: %d\n", v3++, *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
return result;
}

original_code:
void dump_int_list(list l) {
 struct element_t * cur=l->head;
 printf("Numer of elements on the list: %zu\n",l->size);
 int i=1;
 while(cur) {
  printf("Element %d: %d\n",i,(int)cur->ptr);
  i++;
  cur=cur->next;
 }
}

canonical_original_code:
void dump_int_list(struct list_t *l) {
 struct element_t *cur = l->head;
 printf("Numer of elements on the list: %zu\n",l->size);
 int i = 1;
 while(cur) {
  printf("Element %d: %d\n",i,(int)cur->ptr);
  i++;
  cur=cur->next;
 }
}

variable_types: i int

user_defined_types: struct element_t { void *ptr; struct element_t *next; struct element_t *prev; }


decompiled_code:
int __fastcall dump_string_list(__int64 *a1)
{
__int64 v1; // rbx
int result; // eax
unsigned int v3; // ebp

v1 = *a1;
result = printf("Numer of elements on the list: %zu\n", a1[2]);
if ( v1 )
{
v3 = 1;
do
{
result = printf("Element %d: %s\n", v3++, *(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 *a1)
{
__int64 v1; // rbx
int result; // eax
unsigned int v3; // ebp

v1 = *a1;
result = printf("Numer of elements on the list: %zu\n", a1[2]);
if ( v1 )
{
v3 = 1;
do
{
result = printf("Element %d: %s\n", v3++, *(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

original_code:
void dump_string_list(list l) {
 struct element_t * cur=l->head;
 printf("Numer of elements on the list: %zu\n",l->size);
 int i=1;
 while(cur) {
  printf("Element %d: %s\n",i,(char*)cur->ptr);
  i++;
  cur=cur->next;
 }
}

canonical_original_code:
void dump_string_list(struct list_t *l) {
 struct element_t *cur = l->head;
 printf("Numer of elements on the list: %zu\n",l->size);
 int i = 1;
 while(cur) {
  printf("Element %d: %s\n",i,(char *)cur->ptr);
  i++;
  cur=cur->next;
 }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbp
__int64 v7; // r14
__int64 v8; // r13
__int64 v9; // rbp

v3 = (__int64 *)create_list(argc, argv, envp);
v4 = create_node("Node 1");
v5 = create_node("Node 2");
v6 = create_node("Node 3");
v7 = create_edge(v4, v5);
v8 = create_edge(v5, v6);
v9 = create_edge(v6, v4);
list_push(v3, v7);
list_push(v3, v8);
list_push(v3, v9);
dump_graph(v3);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // rbp
__int64 v7; // r14
__int64 v8; // r13
__int64 v9; // rbp

v3 = (__int64 *)func8(argc, argv, envp);
v4 = create_node("Node 1");
v5 = create_node("Node 2");
v6 = create_node("Node 3");
v7 = create_edge(v4, v5);
v8 = create_edge(v5, v6);
v9 = create_edge(v6, v4);
list_push(v3, v7);
list_push(v3, v8);
list_push(v3, v9);
func7(v3);
return 1;
}

original_code:
int main() {
 list graph=create_list();
 node n1=create_node("Node 1");
 node n2=create_node("Node 2");
 node n3=create_node("Node 3");
 edge e1=create_edge(n1,n2);
 edge e2=create_edge(n2,n3);
 edge e3=create_edge(n3,n1);
 list_push(graph,e1);
 list_push(graph,e2);
 list_push(graph,e3);
 dump_graph(graph);
 return 1;
}

canonical_original_code:
int main() {
 struct list_t *graph = create_list();
 struct node_t *n1 = create_node("Node 1");
 struct node_t *n2 = create_node("Node 2");
 struct node_t *n3 = create_node("Node 3");
 struct edge_t *e1 = create_edge(n1,n2);
 struct edge_t *e2 = create_edge(n2,n3);
 struct edge_t *e3 = create_edge(n3,n1);
 list_push(graph,e1);
 list_push(graph,e2);
 list_push(graph,e3);
 dump_graph(graph);
 return 1;
}

variable_types: struct edge_t { struct node_t { void *ptr; } *begin; struct node_t *end; } *


decompiled_code:
_BOOL8 __fastcall strcmp_v(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int strcmp_v(void * s1, void * s2) {
 return !strcmp((char *)s1,(char *)s2);
}

canonical_original_code:
int strcmp_v(void *s1, void *s2) {
 return !strcmp((char *)s1,(char *)s2);
}


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

v3 = create_list(argc, argv, envp);
list_push(v3, "String #1");
list_push(v3, "String #2");
list_push(v3, "String #3");
dump_string_list(v3);
list_pop(v3);
list_pop(v3);
list_pop(v3);
dump_string_list(v3);
list_push(v3, "Apples");
list_push(v3, "Oranges");
list_push(v3, "Grapes");
dump_string_list(v3);
if ( list_remove(v3, "Oranges", strcmp_v) )
{
puts("Oranges removed");
dump_string_list(v3);
}
list_push(v3, "Strawberries");
dump_string_list(v3);
if ( !list_remove(v3, "Oranges", strcmp_v) )
puts("Oranges not found");
dump_string_list(v3);
list_remove(v3, "Strawberries", 0LL);
dump_string_list(v3);
return 0;
}

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

v3 = func8(argc, argv, envp);
list_push(v3, "String #1");
list_push(v3, "String #2");
list_push(v3, "String #3");
func11(v3);
func9(v3);
func9(v3);
func9(v3);
func11(v3);
list_push(v3, "Apples");
list_push(v3, "Oranges");
list_push(v3, "Grapes");
func11(v3);
if ( list_remove(v3, "Oranges", strcmp_v) )
{
puts("Oranges removed");
func11(v3);
}
list_push(v3, "Strawberries");
func11(v3);
if ( !list_remove(v3, "Oranges", strcmp_v) )
puts("Oranges not found");
func11(v3);
list_remove(v3, "Strawberries", 0LL);
func11(v3);
return 0;
}

original_code:
int main(int argc, char ** argv) {
 list l=create_list();
 list_push(l,"String #1");
 list_push(l,"String #2");
 list_push(l,"String #3");
 dump_string_list(l);
 list_pop(l);
 list_pop(l);
 list_pop(l);
 dump_string_list(l);
 list_push(l,"Apples");
 list_push(l,"Oranges");
 list_push(l,"Grapes");
 dump_string_list(l);
 if(list_remove(l,"Oranges",(*strcmp_v))) {
  printf("Oranges removed\n");
  dump_string_list(l);
 }
 list_push(l,"Strawberries");
 dump_string_list(l);
 if(!list_remove(l,"Oranges",(*strcmp_v))) {
  printf("Oranges not found\n");
 }
 dump_string_list(l);
 list_remove(l,"Strawberries",((void *)0));
 dump_string_list(l);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 struct list_t *l = create_list();
 list_push(l,"String #1");
 list_push(l,"String #2");
 list_push(l,"String #3");
 dump_string_list(l);
 list_pop(l);
 list_pop(l);
 list_pop(l);
 dump_string_list(l);
 list_push(l,"Apples");
 list_push(l,"Oranges");
 list_push(l,"Grapes");
 dump_string_list(l);
 if(list_remove(l,"Oranges",(*strcmp_v))) {
  printf("Oranges removed\n");
  dump_string_list(l);
 }
 list_push(l,"Strawberries");
 dump_string_list(l);
 if(!list_remove(l,"Oranges",(*strcmp_v))) {
  printf("Oranges not found\n");
 }
 dump_string_list(l);
 list_remove(l,"Strawberries",((void *)0));
 dump_string_list(l);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


entrycmp

decompiled_code:
_BOOL8 __fastcall entrycmp(const char **a1, const char **a2)
{
return strcmp(*a1, *a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const char **a1, const char **a2)
{
return strcmp(*a1, *a2) == 0;
}

original_code:
int entrycmp(void * e1, void * e2) {
 return !strcmp(((entry) e1)->key,((entry) e2)->key);
}

canonical_original_code:
int entrycmp(void *e1, void *e2) {
 return !strcmp(((struct entry_t *) e1)->key,((struct entry_t *) e2)->key);
}

user_defined_types: struct entry_t { char *key; char *value; }


decompiled_code:
__int64 __fastcall hashtable_hash(_QWORD *a1, const char *a2)
{
size_t v2; // rax
const char *v3; // rdx
char *v4; // rsi
unsigned __int64 v5; // rax

v2 = strlen(a2);
v3 = a2;
v4 = (char *)&a2[v2];
v5 = 0LL;
while ( v3 != v4 )
v5 += *v3++;
return (unsigned int)(v5 % *a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, const char *a2)
{
size_t v2; // rax
const char *v3; // rdx
char *v4; // rsi
unsigned __int64 v5; // rax

v2 = strlen(a2);
v3 = a2;
v4 = (char *)&a2[v2];
v5 = 0LL;
while ( v3 != v4 )
v5 += *v3++;
return (unsigned int)(v5 % *a1);
}

original_code:
int hashtable_hash(hashtable h, char * key) {
 size_t hashval=0;
 int i;
 for(i=0;i<strlen(key);i++) {
  hashval<<8;
  hashval+=key[i];
 }
 return (hashval%h->size);
}

canonical_original_code:
int hashtable_hash(struct hashtable_t *h, char *key) {
 unsigned long hashval = 0;
 int i;
 for(i=0;i<strlen(key);i++) {
  hashval<<8;
  hashval+=key[i];
 }
 return (hashval%h->size);
}

variable_types: struct hashtable_t { unsigned long size; struct list_t { struct element_t { void *ptr; struct element_t *next; struct element_t *prev; } *head; struct element_t *tail; unsigned long size; } **table; } *

variable_types:
key
char *

variable_types:
hashval
unsigned long

user_defined_types: struct hashtable_t { unsigned long size; struct list_t **table; }


decompiled_code:
__int64 __fastcall hashtable_set(_QWORD *a1, const char *a2, __int64 a3)
{
__int64 v4; // r12
_QWORD *v5; // rax
__int64 v7[7]; // [rsp+0h] [rbp-38h] BYREF

v7[0] = (__int64)a2;
v7[1] = a3;
v4 = (int)hashtable_hash(a1, a2);
v5 = (_QWORD *)list_remove(*(_QWORD *)(a1[1] + 8 * v4), v7, entrycmp);
if ( !v5 )
{
v5 = malloc(0x10uLL);
*v5 = a2;
}
v5[1] = a3;
return list_push(*(_QWORD *)(a1[1] + 8 * v4), v5);
}

original_code:
void hashtable_set(hashtable h,char *key, char*value) {
 int bin=hashtable_hash(h,key);
 struct entry_t e_t={key,value};
 entry e=list_remove(h->table[bin],&e_t,(*entrycmp));
 if(e) {
  e->value=value;
  list_push(h->table[bin],e);
 } else {
  entry new=malloc(sizeof(struct entry_t));
  new->key=key;
  new->value=value;
  list_push(h->table[bin],new);
 }
}

canonical_original_code:
void hashtable_set(struct hashtable_t *h, char *key, char *value) {
 int bin = hashtable_hash(h,key);
 struct entry_t e_t = {key,value};
 struct entry_t *e = list_remove(h->table[bin],&e_t,(*entrycmp));
 if(e) {
  e->value=value;
  list_push(h->table[bin],e);
 } else {
  struct entry_t *new = malloc(sizeof(struct entry_t));
  new->key=key;
  new->value=value;
  list_push(h->table[bin],new);
 }
}

variable_types:
value
char *

variable_types: bin int

variable_types: struct entry_t { char *key; char *value; } *


decompiled_code:
const char *__fastcall hashtable_get(_QWORD *a1, const char *a2)
{
const char *v2; // rbx
const char **v3; // rbp

v2 = **(const char ***)(a1[1] + 8LL * (int)hashtable_hash(a1, a2));
if ( v2 )
{
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !strcmp(**(const char ***)v2, a2) )
break;
v2 = (const char *)*((_QWORD *)v2 + 1);
if ( !v2 )
return v2;
}
v2 = v3[1];
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func10(_QWORD *a1, const char *a2)
{
const char *v2; // rbx
const char **v3; // rbp

v2 = **(const char ***)(a1[1] + 8LL * (int)func8(a1, a2));
if ( v2 )
{
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !strcmp(**(const char ***)v2, a2) )
break;
v2 = (const char *)*((_QWORD *)v2 + 1);
if ( !v2 )
return v2;
}
v2 = v3[1];
}
return v2;
}

original_code:
char * hashtable_get(hashtable h,char *key) {
 int bin=hashtable_hash(h,key);
 element cur=h->table[bin]->head;
 while(cur) {
  if(!strcmp(((entry)cur->ptr)->key,key))
   return ((entry)cur->ptr)->value;
  cur=cur->next;
 }
 return ((void *)0);
}

canonical_original_code:
char *hashtable_get(struct hashtable_t *h, char *key) {
 int bin = hashtable_hash(h,key);
 struct element_t *cur = h->table[bin]->head;
 while(cur) {
  if(!strcmp(((struct entry_t *)cur->ptr)->key,key))
   return ((struct entry_t *)cur->ptr)->value;
  cur=cur->next;
 }
 return ((void *)0);
}


canonical_decompiled_code:
void *func11()
{
return calloc(1uLL, 0x18uLL);
}


canonical_decompiled_code:
int __fastcall func13(unsigned int **a1)
{
unsigned int *v1; // rbx
int result; // eax
unsigned int v3; // ebp

v1 = *a1;
result = printf("Numer of elements on the list: %zu\n", (size_t)a1[2]);
if ( v1 )
{
v3 = 1;
do
{
result = printf("Element %d: %d\n", v3++, *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
return result;
}


canonical_decompiled_code:
int __fastcall func14(__int64 *a1)
{
__int64 v1; // rbx
int result; // eax
unsigned int v3; // ebp

v1 = *a1;
result = printf("Numer of elements on the list: %zu\n", a1[2]);
if ( v1 )
{
v3 = 1;
do
{
result = printf("Element %d: %s\n", v3++, *(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}


repo: salmon/somethingmess

decompiled_code:
__int64 __fastcall write_buf(int fd, void *buf)
{
ssize_t v2; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

if ( lseek(fd, 0LL, 0) < 0 )
{
v4 = __errno_location();
v5 = strerror(*v4);
printf("write error, %s\n", v5);
}
v2 = write(fd, buf, 0x14uLL);
if ( v2 < 0 )
{
v6 = __errno_location();
v7 = strerror(*v6);
printf("write error, %s\n", v7);
exit(1);
}
if ( v2 != 20 )
printf("write %d bytes\n", v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf)
{
ssize_t v2; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

if ( lseek(fd, 0LL, 0) < 0 )
{
v4 = __errno_location();
v5 = strerror(*v4);
printf("write error, %s\n", v5);
}
v2 = write(fd, buf, 0x14uLL);
if ( v2 < 0 )
{
v6 = __errno_location();
v7 = strerror(*v6);
printf("write error, %s\n", v7);
exit(1);
}
if ( v2 != 20 )
printf("write %d bytes\n", v2);
return 0LL;
}

original_code:
int write_buf(int fd, char *buf)
{
 ssize_t size;
 size = lseek(fd, 0, 0);
 if (size < 0) {
  printf("write error, %s\n", strerror((*__errno_location ())));
 }
 size = write(fd, buf, 20);
 if (size < 0) {
  printf("write error, %s\n", strerror((*__errno_location ())));
  exit(1);
 } else if (size != 20)
  printf("write %d bytes\n", size);
 return 0;
}

canonical_original_code:
int write_buf(int fd, char *buf)
{
 long size;
 size = lseek(fd, 0, 0);
 if (size < 0) {
  printf("write error, %s\n", strerror((*__errno_location ())));
 }
 size = write(fd, buf, 20);
 if (size < 0) {
  printf("write error, %s\n", strerror((*__errno_location ())));
  exit(1);
 } else if (size != 20)
  printf("write %d bytes\n", size);
 return 0;
}

variable_types: fd int

variable_types:
buf
char *

variable_types: size long


decompiled_code:
__int64 __fastcall read_buf(int fd, void *buf)
{
int *v3; // rax
char *v4; // rax

*(_QWORD *)buf = 0LL;
*((_QWORD *)buf + 1) = 0LL;
*((_DWORD *)buf + 4) = 0;
lseek(fd, 0LL, 0);
if ( read(fd, buf, 0x14uLL) < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("read error, %s\n", v4);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, void *buf)
{
int *v3; // rax
char *v4; // rax

*(_QWORD *)buf = 0LL;
*((_QWORD *)buf + 1) = 0LL;
*((_DWORD *)buf + 4) = 0;
lseek(fd, 0LL, 0);
if ( read(fd, buf, 0x14uLL) < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("read error, %s\n", v4);
exit(1);
}
return 0LL;
}

original_code:
int read_buf(int fd, char *buf)
{
 ssize_t size;
 memset(buf, 0, 20);
 size = lseek(fd, 0, 0);
 size = read(fd, buf, 20);
 if (size < 0) {
  printf("read error, %s\n", strerror((*__errno_location ())));
  exit(1);
 }
 return 0;
}

canonical_original_code:
int read_buf(int fd, char *buf)
{
 long size;
 memset(buf, 0, 20);
 size = lseek(fd, 0, 0);
 size = read(fd, buf, 20);
 if (size < 0) {
  printf("read error, %s\n", strerror((*__errno_location ())));
  exit(1);
 }
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int *v5; // rax
char *v6; // rax
unsigned int seconds; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 buf[5]; // [rsp+10h] [rbp-28h] BYREF

seconds = 5;
v3 = open("tdrv", 2, envp);
qmemcpy(buf, "fill bufaaaaaaaaaaa", 19);
write_buf(v3, buf);
printf("write to tdrv, data is \"%s\"\n", (const char *)buf);
if ( ioctl(v3, 0x40046B01uLL, &seconds) )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("ioctl error, %s\n", v6);
exit(1);
}
printf("set %d seconds to clean buffer\n", seconds);
read_buf(v3, buf);
printf("read tdrv immadately, data is \"%s\"\n", (const char *)buf);
sleep(seconds);
read_buf(v3, buf);
if ( LOBYTE(buf[0]) )
printf("after %d seconds then read tdrv, data is \"%s\"\n", seconds, (const char *)buf);
else
printf("after %d seconds then read tdrv, data is \"NULL\"\n", seconds);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int *v5; // rax
char *v6; // rax
unsigned int seconds; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 buf[5]; // [rsp+10h] [rbp-28h] BYREF

seconds = 5;
v3 = open("tdrv", 2, envp);
qmemcpy(buf, "fill bufaaaaaaaaaaa", 19);
func7(v3, buf);
printf("write to tdrv, data is \"%s\"\n", (const char *)buf);
if ( ioctl(v3, 0x40046B01uLL, &seconds) )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("ioctl error, %s\n", v6);
exit(1);
}
printf("set %d seconds to clean buffer\n", seconds);
func8(v3, buf);
printf("read tdrv immadately, data is \"%s\"\n", (const char *)buf);
sleep(seconds);
func8(v3, buf);
if ( LOBYTE(buf[0]) )
printf("after %d seconds then read tdrv, data is \"%s\"\n", seconds, (const char *)buf);
else
printf("after %d seconds then read tdrv, data is \"NULL\"\n", seconds);
return 0;
}

original_code:
int main()
{
 char buf[20];
 int fd, ret, interval;
 interval = 5;
 fd = open("tdrv", 02);
 strncpy(buf, "fill bufaaaaaaaaaaaa", 20 - 1);
 write_buf(fd, buf);
 printf("write to tdrv, data is \"%s\"\n", buf);
 ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((1)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &interval);
 if (ret) {
  printf("ioctl error, %s\n", strerror((*__errno_location ())));
  exit(1);
 }
 printf("set %d seconds to clean buffer\n", interval);
 read_buf(fd, buf);
 printf("read tdrv immadately, data is \"%s\"\n", buf);
 sleep(interval);
 read_buf(fd, buf);
 if (!strlen(buf))
  printf("after %d seconds then read tdrv, data is \"NULL\"\n", interval);
 else
  printf("after %d seconds then read tdrv, data is \"%s\"\n", interval, buf);
 return 0;
}

canonical_original_code:
int main()
{
 char buf[20];
 int fd; int ret; int interval;
 interval = 5;
 fd = open("tdrv", 02);
 strncpy(buf, "fill bufaaaaaaaaaaaa", 20 - 1);
 write_buf(fd, buf);
 printf("write to tdrv, data is \"%s\"\n", buf);
 ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((1)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &interval);
 if (ret) {
  printf("ioctl error, %s\n", strerror((*__errno_location ())));
  exit(1);
 }
 printf("set %d seconds to clean buffer\n", interval);
 read_buf(fd, buf);
 printf("read tdrv immadately, data is \"%s\"\n", buf);
 sleep(interval);
 read_buf(fd, buf);
 if (!strlen(buf))
  printf("after %d seconds then read tdrv, data is \"NULL\"\n", interval);
 else
  printf("after %d seconds then read tdrv, data is \"%s\"\n", interval, buf);
 return 0;
}

variable_types:
buf
char [20]

variable_types: ret int

variable_types: interval int


decompiled_code:
__int64 __fastcall dump_block(unsigned int a1, void *a2, int a3)
{
__int64 result; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax

if ( lseek64(a3, (unsigned __int64)a1 << 12, 0) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
printf("%s llseek %lu error, %s\n", "dump_block", (unsigned __int64)a1 << 12, v6);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)read(a3, a2, 0x1000uLL) == 4096 )
{
result = 0LL;
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("%s read error, %s\n", "dump_block", v8);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, void *a2, int a3)
{
__int64 result; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax

if ( lseek64(a3, (unsigned __int64)a1 << 12, 0) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
printf("%s llseek %lu error, %s\n", "dump_block", (unsigned __int64)a1 << 12, v6);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)read(a3, a2, 0x1000uLL) == 4096 )
{
result = 0LL;
}
else
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("%s read error, %s\n", "dump_block", v8);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int dump_block(uint32_t blkno, char *blk_buf, int disk_fd)
{
 off64_t offset, ret;
 int len = 0;
 offset = (off64_t)blkno * 4096;
 ret = lseek64(disk_fd, offset, 0);
 if (ret < 0) {
  printf("%s llseek %lu error, %s\n", __func__, offset, strerror((*__errno_location ())));
  return -1;
 }
 len = read(disk_fd, blk_buf, 4096);
 if (len != 4096) {
  printf("%s read error, %s\n", __func__, strerror((*__errno_location ())));
  return -1;
 }
 return 0;
}

canonical_original_code:
static int dump_block(unsigned int blkno, char *blk_buf, int disk_fd)
{
 long offset; long ret;
 int len = 0;
 offset = (long)blkno * 4096;
 ret = lseek64(disk_fd, offset, 0);
 if (ret < 0) {
  printf("%s llseek %lu error, %s\n", __func__, offset, strerror((*__errno_location ())));
  return -1;
 }
 len = read(disk_fd, blk_buf, 4096);
 if (len != 4096) {
  printf("%s read error, %s\n", __func__, strerror((*__errno_location ())));
  return -1;
 }
 return 0;
}

variable_types:
blkno
unsigned int

variable_types: offset long

variable_types: ret long

variable_types: len int


decompiled_code:
__int64 __fastcall guess_dind_data(unsigned int *a1)
{
unsigned int *v1; // rbx
int v2; // eax
unsigned int v3; // esi
unsigned int v4; // edx
int v5; // ecx
unsigned int v6; // edi
unsigned int v7; // er8

v1 = a1;
v2 = memcmp(a1 + 640, &zero_buf, 0xA00uLL);
if ( v2 )
return (unsigned int)-1;
v3 = 0;
v4 = *a1;
if ( !*a1 )
return (unsigned int)-1;
v5 = 0;
v6 = 0;
while ( 1 )
{
if ( v4 > 0x747097F )
return (unsigned int)-1;
v5 -= (v6 < v4) - 1;
if ( v5 > 10 )
break;
++v1;
if ( ++v2 == 1024 )
return v3;
v7 = *v1;
if ( v2 > 29 && !v7 )
return v3;
v6 = v4;
if ( v2 <= 30 && !v7 )
return (unsigned int)-1;
v4 = *v1;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
unsigned int *v1; // rbx
int v2; // eax
unsigned int v3; // esi
unsigned int v4; // edx
int v5; // ecx
unsigned int v6; // edi
unsigned int v7; // er8

v1 = a1;
v2 = memcmp(a1 + 640, &zero_buf, 0xA00uLL);
if ( v2 )
return (unsigned int)-1;
v3 = 0;
v4 = *a1;
if ( !*a1 )
return (unsigned int)-1;
v5 = 0;
v6 = 0;
while ( 1 )
{
if ( v4 > 0x747097F )
return (unsigned int)-1;
v5 -= (v6 < v4) - 1;
if ( v5 > 10 )
break;
++v1;
if ( ++v2 == 1024 )
return v3;
v7 = *v1;
if ( v2 > 29 && !v7 )
return v3;
v6 = v4;
if ( v2 <= 30 && !v7 )
return (unsigned int)-1;
v4 = *v1;
}
return (unsigned int)-1;
}

original_code:
int guess_dind_data(char *blk_data)
{
 int i;
 uint32_t pre_num = 0;
 uint32_t *p_num = (uint32_t *)blk_data;
 int bad_cnt = 0, good_cnt = 0;
 int cost = 0;
 char *p = blk_data + 4096 - 384 * sizeof(uint32_t);
 if (memcmp(p, zero_buf, 4096 - 384 * sizeof(uint32_t))) {
  return -1;
 }
 for (i = 0; i < 4096 / sizeof(uint32_t); i ++) {
  if (*p_num == 0 && i >= 30) {
   break;
  } else if (*p_num == 0 && i <= 30) {
   return -1;
  }
  if (*p_num > 122095999) {
   return -1;
  }
  if (*p_num > pre_num) {
   good_cnt ++;
   cost = *p_num - pre_num;
  } else {
   bad_cnt ++;
  }
  if (bad_cnt > 10)
   return -1;
  pre_num = *p_num;
  p_num ++;
 }
 return 0;
}

canonical_original_code:
int guess_dind_data(char *blk_data)
{
 int i;
 unsigned int pre_num = 0;
 unsigned int *p_num = (uint32_t *)blk_data;
 int bad_cnt = 0; int good_cnt = 0;
 int cost = 0;
 char *p = blk_data + 4096 - 384 * sizeof(uint32_t);
 if (memcmp(p, zero_buf, 4096 - 384 * sizeof(unsigned int))) {
  return -1;
 }
 for (i = 0; i < 4096 / sizeof(unsigned int); i ++) {
  if (*p_num == 0 && i >= 30) {
   break;
  } else if (*p_num == 0 && i <= 30) {
   return -1;
  }
  if (*p_num > 122095999) {
   return -1;
  }
  if (*p_num > pre_num) {
   good_cnt ++;
   cost = *p_num - pre_num;
  } else {
   bad_cnt ++;
  }
  if (bad_cnt > 10)
   return -1;
  pre_num = *p_num;
  p_num ++;
 }
 return 0;
}

variable_types: i int

variable_types: cost int

variable_types:
p
char *


decompiled_code:
__int64 __fastcall dump_dind_data(unsigned int a1, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
unsigned int v5; // ebp
int *v7; // rax
char *v8; // rax
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v9, "%u_file.recovery", a1);
printf("DINT %u\n", a1);
v2 = open64(v9, 66, 438LL);
if ( v2 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("dump %u file open error, %s\n", a1, v8);
v5 = -1;
}
else
{
v3 = v2;
v4 = _dump_dind_data(a1, a2, v2);
close(v3);
v5 = 0;
if ( v4 < 0 )
{
v5 = access(v9, 0);
if ( v5 )
{
v5 = 0;
}
else
{
printf("%s is not a valid file. rm it\n", v9);
remove(v9);
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
unsigned int v5; // ebp
int *v7; // rax
char *v8; // rax
char v9[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v9, "%u_file.recovery", a1);
printf("DINT %u\n", a1);
v2 = open64(v9, 66, 438LL);
if ( v2 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("dump %u file open error, %s\n", a1, v8);
v5 = -1;
}
else
{
v3 = v2;
v4 = func5(a1, a2, v2);
close(v3);
v5 = 0;
if ( v4 < 0 )
{
v5 = access(v9, 0);
if ( v5 )
{
v5 = 0;
}
else
{
printf("%s is not a valid file. rm it\n", v9);
remove(v9);
}
}
}
return v5;
}

original_code:
int dump_dind_data(uint32_t blkno, int disk_fd)
{
 char filename[256];
 int fd, ret;
 sprintf(filename, "%u_file.recovery", blkno);
 printf("DINT %u\n", blkno);
 fd = open(filename, 0100 | 02, 0666);
 if (fd < 0) {
  printf("dump %u file open error, %s\n", blkno, strerror((*__errno_location ())));
  return -1;
 }
 ret = __dump_dind_data(blkno, disk_fd, fd);
 close(fd);
 if (ret < 0) {
  if (0 == access(filename, 0)) {
   printf("%s is not a valid file. rm it\n", filename);
   remove(filename);
  }
 }
 return 0;
}

canonical_original_code:
int dump_dind_data(unsigned int blkno, int disk_fd)
{
 char filename[256];
 int fd; int ret;
 sprintf(filename, "%u_file.recovery", blkno);
 printf("DINT %u\n", blkno);
 fd = open(filename, 0100 | 02, 0666);
 if (fd < 0) {
  printf("dump %u file open error, %s\n", blkno, strerror((*__errno_location ())));
  return -1;
 }
 ret = __dump_dind_data(blkno, disk_fd, fd);
 close(fd);
 if (ret < 0) {
  if (0 == access(filename, 0)) {
   printf("%s is not a valid file. rm it\n", filename);
   remove(filename);
  }
 }
 return 0;
}

variable_types:
filename
char [256]


decompiled_code:
void *__fastcall dump_file_thread(void *a1)
{
__int64 v1; // rbx
int v2; // er13
unsigned int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = *((_QWORD *)a1 + 2);
v2 = *((_DWORD *)a1 + 3);
printf("thread %d start\n", *((unsigned int *)a1 + 2));
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)(v1 + 8016));
if ( queue_empty(v1) )
break;
dequeue((int *)v1, v4);
if ( queue_full(v1) )
pthread_cond_signal((pthread_cond_t *)(v1 + 8056));
pthread_mutex_unlock((pthread_mutex_t *)(v1 + 8016));
printf("thread_num %d, now dumping %u DIND\n", *((unsigned int *)a1 + 2), v4[0]);
dump_dind_data(v4[0], v2);
printf("thread_num %d, finish dumping %u DIND\n", *((unsigned int *)a1 + 2), v4[0]);
}
if ( is_finish == 1 )
break;
if ( queue_full(v1) )
pthread_cond_signal((pthread_cond_t *)(v1 + 8056));
pthread_mutex_unlock((pthread_mutex_t *)(v1 + 8016));
sleep(1u);
}
pthread_mutex_unlock((pthread_mutex_t *)(v1 + 8016));
printf("thread %d exit\n", *((unsigned int *)a1 + 2));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
__int64 v1; // rbx
int v2; // er13
unsigned int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = *((_QWORD *)a1 + 2);
v2 = *((_DWORD *)a1 + 3);
printf("thread %d start\n", *((unsigned int *)a1 + 2));
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)(v1 + 8016));
if ( func1(v1) )
break;
func3((int *)v1, v4);
if ( func0(v1) )
pthread_cond_signal((pthread_cond_t *)(v1 + 8056));
pthread_mutex_unlock((pthread_mutex_t *)(v1 + 8016));
printf("thread_num %d, now dumping %u DIND\n", *((unsigned int *)a1 + 2), v4[0]);
func7(v4[0], v2);
printf("thread_num %d, finish dumping %u DIND\n", *((unsigned int *)a1 + 2), v4[0]);
}
if ( is_finish == 1 )
break;
if ( func0(v1) )
pthread_cond_signal((pthread_cond_t *)(v1 + 8056));
pthread_mutex_unlock((pthread_mutex_t *)(v1 + 8016));
sleep(1u);
}
pthread_mutex_unlock((pthread_mutex_t *)(v1 + 8016));
printf("thread %d exit\n", *((unsigned int *)a1 + 2));
return 0LL;
}

original_code:
void *dump_file_thread(void *args)
{
 uint32_t blk_no;
 int empty;
 struct dump_thread_info *pinfo = (struct dump_thread_info *)args;
 struct dumpdind_queue *queue = pinfo->queue;
 int disk_fd = pinfo->disk_fd;
 printf("thread %d start\n", pinfo->thread_num);
 while (1) {
  pthread_mutex_lock(&queue->mutex);
  if (queue_empty(queue)) {
   empty = 1;
   if (is_finish == 1) {
    pthread_mutex_unlock(&queue->mutex);
    break;
   }
  } else {
   empty = 0;
   dequeue(queue, &blk_no);
  }
  if (queue_full(queue))
   pthread_cond_signal(&queue->cond);
  pthread_mutex_unlock(&queue->mutex);
  if (empty) {
   sleep(1);
  } else {
   printf("thread_num %d, now dumping %u DIND\n", pinfo->thread_num, blk_no);
   dump_dind_data(blk_no, disk_fd);
   printf("thread_num %d, finish dumping %u DIND\n", pinfo->thread_num, blk_no);
  }
 }
 printf("thread %d exit\n", pinfo->thread_num);
 return ((void *)0);
}

canonical_original_code:
void *dump_file_thread(void *args)
{
 unsigned int blk_no;
 int empty;
 struct dump_thread_info *pinfo = (struct dump_thread_info *)args;
 struct dumpdind_queue *queue = pinfo->queue;
 int disk_fd = pinfo->disk_fd;
 printf("thread %d start\n", pinfo->thread_num);
 while (1) {
  pthread_mutex_lock(&queue->mutex);
  if (queue_empty(queue)) {
   empty = 1;
   if (is_finish == 1) {
    pthread_mutex_unlock(&queue->mutex);
    break;
   }
  } else {
   empty = 0;
   dequeue(queue, &blk_no);
  }
  if (queue_full(queue))
   pthread_cond_signal(&queue->cond);
  pthread_mutex_unlock(&queue->mutex);
  if (empty) {
   sleep(1);
  } else {
   printf("thread_num %d, now dumping %u DIND\n", pinfo->thread_num, blk_no);
   dump_dind_data(blk_no, disk_fd);
   printf("thread_num %d, finish dumping %u DIND\n", pinfo->thread_num, blk_no);
  }
 }
 printf("thread %d exit\n", pinfo->thread_num);
 return ((void *)0);
}

variable_types:
args
void *

variable_types: empty int

variable_types: struct dump_thread_info { unsigned long thread_id; int thread_num; int disk_fd; struct dumpdind_queue { int head; int tail; int size; unsigned int block_no[2000]; 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; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; } *queue; } *

user_defined_types: struct dump_thread_info { unsigned long thread_id; int thread_num; int disk_fd; struct dumpdind_queue *queue; }

user_defined_types: struct dumpdind_queue { int head; int tail; int size; unsigned int block_no[2000]; union pthread_mutex_t mutex; union pthread_cond_t cond; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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; }


decompiled_code:
__int64 __fastcall get_block_data(int fd, void *buf, unsigned int a3)
{
__off64_t v3; // rbx
int v4; // edx
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax

v3 = (unsigned __int64)a3 << 12;
if ( lseek64(fd, v3, 0) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("%s llseek %ld error, %s\n", "get_block_data", v3, v7);
v4 = -1;
}
else
{
v4 = read(fd, buf, 0x400000uLL);
if ( v4 < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
printf("%s read error, %s\n", "get_block_data", v9);
v4 = -1;
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, void *buf, unsigned int a3)
{
__off64_t v3; // rbx
int v4; // edx
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax

v3 = (unsigned __int64)a3 << 12;
if ( lseek64(fd, v3, 0) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("%s llseek %ld error, %s\n", "get_block_data", v3, v7);
v4 = -1;
}
else
{
v4 = read(fd, buf, 0x400000uLL);
if ( v4 < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
printf("%s read error, %s\n", "get_block_data", v9);
v4 = -1;
}
}
return (unsigned int)v4;
}

original_code:
int get_block_data(int fd, char *buf, uint32_t start_blk_no)
{
 off64_t offset, ret;
 int len = 0;
 offset = (off64_t)start_blk_no * 4096;
 ret = lseek64(fd, offset, 0);
 if (ret < 0) {
  printf("%s llseek %ld error, %s\n", __func__, offset, strerror((*__errno_location ())));
  return -1;
 }
 len = read(fd, buf, (1024 * 1024 * 4));
 if (len < 0) {
  printf("%s read error, %s\n", __func__, strerror((*__errno_location ())));
  return -1;
 }
 return len;
}

canonical_original_code:
int get_block_data(int fd, char *buf, unsigned int start_blk_no)
{
 long offset; long ret;
 int len = 0;
 offset = (long)start_blk_no * 4096;
 ret = lseek64(fd, offset, 0);
 if (ret < 0) {
  printf("%s llseek %ld error, %s\n", __func__, offset, strerror((*__errno_location ())));
  return -1;
 }
 len = read(fd, buf, (1024 * 1024 * 4));
 if (len < 0) {
  printf("%s read error, %s\n", __func__, strerror((*__errno_location ())));
  return -1;
 }
 return len;
}

variable_types: fd int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
void *v4; // rax
void *v5; // r14
pthread_t *v6; // rbx
unsigned int i; // ebp
unsigned int v8; // ebx
int result; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int v16; // er12
unsigned int *v17; // rbp
int v18; // eax
int v19; // er13
pthread_t *v20; // [rsp+8h] [rbp-2050h]
int v21[4]; // [rsp+10h] [rbp-2048h] BYREF
_DWORD v22[2000]; // [rsp+20h] [rbp-2038h] BYREF
pthread_mutex_t mutex; // [rsp+1F60h] [rbp-F8h] BYREF
pthread_cond_t cond; // [rsp+1F88h] [rbp-D0h] BYREF
pthread_t newthread[12]; // [rsp+1FC0h] [rbp-98h] BYREF
__int64 v26; // [rsp+2020h] [rbp-38h] BYREF

memset(&zero_buf, 0, 0xA00uLL);
newthread[0] = 0LL;
newthread[1] = 0LL;
newthread[2] = 0LL;
if ( argc == 2 )
{
v21[3] = 0;
v22[1998] = 0;
memset(v22, 0, 0x1F38uLL);
v21[0] = 0;
v21[1] = 0;
v21[2] = 0;
pthread_mutex_init(&mutex, 0LL);
pthread_cond_init(&cond, 0LL);
v3 = open64(argv[1], 0);
if ( v3 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
printf("%s: open error. %s\n", argv[1], v11);
result = -1;
}
else
{
v4 = malloc(0x400000uLL);
v5 = v4;
if ( v4 )
{
memset(v4, 0, 0x400000uLL);
v20 = newthread;
v6 = newthread;
for ( i = 0; i != 4; ++i )
{
*((_DWORD *)v6 + 2) = i;
*((_DWORD *)v6 + 3) = v3;
v6[2] = (pthread_t)v21;
if ( pthread_create(v6, 0LL, dump_file_thread, v6) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
printf("create thread %d error, %s\n", i, v13);
return -1;
}
v6 += 3;
}
v8 = 850;
do
{
LABEL_22:
v18 = get_block_data(v3, v5, v8);
if ( v18 < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
printf("%s read error, %s\n", "main", v15);
return -1;
}
v19 = v18 >> 12;
v17 = (unsigned int *)v5;
v16 = 0;
}
while ( v18 <= 4095 );
while ( 1 )
{
if ( !(unsigned int)guess_dind_data(v17) )
{
printf("find a DIND %u\n", v8);
pthread_mutex_lock(&mutex);
if ( queue_full((__int64)v21) )
pthread_cond_wait(&cond, &mutex);
enqueue((__int64)v21, v8);
pthread_mutex_unlock(&mutex);
}
++v8;
if ( v8 == 100000 * (v8 / 0x186A0) )
printf("Now Scan Block %u\n", v8);
if ( v8 > 0x747097F )
break;
++v16;
v17 += 1024;
if ( v16 >= v19 )
goto LABEL_22;
}
is_finish = 1;
puts("\nScan IND_DATA Finish!!");
do
{
pthread_join(*v20, 0LL);
v20 += 3;
}
while ( v20 != (pthread_t *)&v26 );
close(v3);
result = 0;
}
else
{
puts("malloc error");
result = -1;
}
}
}
else
{
printf("%s: <disk_name>\n", *argv);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
void *v4; // rax
void *v5; // r14
pthread_t *v6; // rbx
unsigned int i; // ebp
unsigned int v8; // ebx
int result; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int v16; // er12
unsigned int *v17; // rbp
int v18; // eax
int v19; // er13
pthread_t *v20; // [rsp+8h] [rbp-2050h]
int v21[4]; // [rsp+10h] [rbp-2048h] BYREF
_DWORD v22[2000]; // [rsp+20h] [rbp-2038h] BYREF
pthread_mutex_t mutex; // [rsp+1F60h] [rbp-F8h] BYREF
pthread_cond_t cond; // [rsp+1F88h] [rbp-D0h] BYREF
pthread_t newthread[12]; // [rsp+1FC0h] [rbp-98h] BYREF
__int64 v26; // [rsp+2020h] [rbp-38h] BYREF

memset(&zero_buf, 0, 0xA00uLL);
newthread[0] = 0LL;
newthread[1] = 0LL;
newthread[2] = 0LL;
if ( argc == 2 )
{
v21[3] = 0;
v22[1998] = 0;
memset(v22, 0, 0x1F38uLL);
v21[0] = 0;
v21[1] = 0;
v21[2] = 0;
pthread_mutex_init(&mutex, 0LL);
pthread_cond_init(&cond, 0LL);
v3 = open64(argv[1], 0);
if ( v3 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
printf("%s: open error. %s\n", argv[1], v11);
result = -1;
}
else
{
v4 = malloc(0x400000uLL);
v5 = v4;
if ( v4 )
{
memset(v4, 0, 0x400000uLL);
v20 = newthread;
v6 = newthread;
for ( i = 0; i != 4; ++i )
{
*((_DWORD *)v6 + 2) = i;
*((_DWORD *)v6 + 3) = v3;
v6[2] = (pthread_t)v21;
if ( pthread_create(v6, 0LL, dump_file_thread, v6) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
printf("create thread %d error, %s\n", i, v13);
return -1;
}
v6 += 3;
}
v8 = 850;
do
{
LABEL_22:
v18 = func9(v3, v5, v8);
if ( v18 < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
printf("%s read error, %s\n", "main", v15);
return -1;
}
v19 = v18 >> 12;
v17 = (unsigned int *)v5;
v16 = 0;
}
while ( v18 <= 4095 );
while ( 1 )
{
if ( !(unsigned int)func6(v17) )
{
printf("find a DIND %u\n", v8);
pthread_mutex_lock(&mutex);
if ( func0((__int64)v21) )
pthread_cond_wait(&cond, &mutex);
func2((__int64)v21, v8);
pthread_mutex_unlock(&mutex);
}
++v8;
if ( v8 == 100000 * (v8 / 0x186A0) )
printf("Now Scan Block %u\n", v8);
if ( v8 > 0x747097F )
break;
++v16;
v17 += 1024;
if ( v16 >= v19 )
goto LABEL_22;
}
is_finish = 1;
puts("\nScan IND_DATA Finish!!");
do
{
pthread_join(*v20, 0LL);
v20 += 3;
}
while ( v20 != (pthread_t *)&v26 );
close(v3);
result = 0;
}
else
{
puts("malloc error");
result = -1;
}
}
}
else
{
printf("%s: <disk_name>\n", *argv);
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int fd = 0, ret, i;
 char *buf = ((void *)0), *p = ((void *)0);
 uint32_t next_block = 850;
 struct dump_thread_info dti[4];
 struct dumpdind_queue dindqueue;
 memset(zero_buf, 0, sizeof(zero_buf));
 memset(&dti, 0, sizeof(struct dump_thread_info));
 if (argc != 2) {
  printf("%s: <disk_name>\n", argv[0]);
  return -1;
 }
 memset(dindqueue.block_no, 0, sizeof(dindqueue.block_no));
 dindqueue.head = 0;
 dindqueue.tail = 0;
 dindqueue.size = 0;
 pthread_mutex_init(&dindqueue.mutex, ((void *)0));
 pthread_cond_init(&dindqueue.cond, ((void *)0));
 fd = open(argv[1], 00 | 0);
 if (fd < 0) {
  printf("%s: open error. %s\n", argv[1], strerror((*__errno_location ())));
  return -1;
 }
 buf = malloc((1024 * 1024 * 4));
 if (((void *)0) == buf) {
  printf("malloc error\n");
  return -1;
 }
 memset(buf, 0, (1024 * 1024 * 4));
 for (i = 0; i < 4; i ++) {
  dti[i].thread_num = i;
  dti[i].disk_fd = fd;
  dti[i].queue = &dindqueue;
  ret = pthread_create(&dti[i].thread_id, ((void *)0), dump_file_thread, &dti[i]);
  if (ret < 0) {
   printf("create thread %d error, %s\n", i, strerror((*__errno_location ())));
   return -1;
  }
 }
 while (1) {
  ret = get_block_data(fd, buf, next_block);
  if (ret < 0) {
   printf("%s read error, %s\n", __func__, strerror((*__errno_location ())));
   return -1;
  }
  for (i = 0; i < (ret / 4096); i ++) {
   p = buf + i * 4096;
   if (0 == guess_dind_data(p)) {
    printf("find a DIND %u\n", next_block);
    pthread_mutex_lock(&dindqueue.mutex);
    if (queue_full(&dindqueue)) {
     pthread_cond_wait(&dindqueue.cond, &dindqueue.mutex);
     enqueue(&dindqueue, next_block);
    } else {
     enqueue(&dindqueue, next_block);
    }
    pthread_mutex_unlock(&dindqueue.mutex);
   }
   next_block ++;
   if (! (next_block % 100000)) {
    printf("Now Scan Block %u\n", next_block);
   }
   if (next_block > 122095999)
    break;
  }
  if (next_block > 122095999) {
   is_finish = 1;
   printf("\nScan IND_DATA Finish!!\n");
   break;
  }
 }
 for (i = 0; i < 4; i ++) {
  pthread_join(dti[i].thread_id, ((void *)0));
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fd = 0; int ret; int i;
 char *buf = ((void *)0); char *p = ((void *)0);
 unsigned int next_block = 850;
 struct dump_thread_info dti[4];
 struct dumpdind_queue dindqueue;
 memset(zero_buf, 0, sizeof(zero_buf));
 memset(&dti, 0, sizeof(struct dump_thread_info));
 if (argc != 2) {
  printf("%s: <disk_name>\n", argv[0]);
  return -1;
 }
 memset(dindqueue.block_no, 0, sizeof(dindqueue.block_no));
 dindqueue.head = 0;
 dindqueue.tail = 0;
 dindqueue.size = 0;
 pthread_mutex_init(&dindqueue.mutex, ((void *)0));
 pthread_cond_init(&dindqueue.cond, ((void *)0));
 fd = open(argv[1], 00 | 0);
 if (fd < 0) {
  printf("%s: open error. %s\n", argv[1], strerror((*__errno_location ())));
  return -1;
 }
 buf = malloc((1024 * 1024 * 4));
 if (((void *)0) == buf) {
  printf("malloc error\n");
  return -1;
 }
 memset(buf, 0, (1024 * 1024 * 4));
 for (i = 0; i < 4; i ++) {
  dti[i].thread_num = i;
  dti[i].disk_fd = fd;
  dti[i].queue = &dindqueue;
  ret = pthread_create(&dti[i].thread_id, ((void *)0), dump_file_thread, &dti[i]);
  if (ret < 0) {
   printf("create thread %d error, %s\n", i, strerror((*__errno_location ())));
   return -1;
  }
 }
 while (1) {
  ret = get_block_data(fd, buf, next_block);
  if (ret < 0) {
   printf("%s read error, %s\n", __func__, strerror((*__errno_location ())));
   return -1;
  }
  for (i = 0; i < (ret / 4096); i ++) {
   p = buf + i * 4096;
   if (0 == guess_dind_data(p)) {
    printf("find a DIND %u\n", next_block);
    pthread_mutex_lock(&dindqueue.mutex);
    if (queue_full(&dindqueue)) {
     pthread_cond_wait(&dindqueue.cond, &dindqueue.mutex);
     enqueue(&dindqueue, next_block);
    } else {
     enqueue(&dindqueue, next_block);
    }
    pthread_mutex_unlock(&dindqueue.mutex);
   }
   next_block ++;
   if (! (next_block % 100000)) {
    printf("Now Scan Block %u\n", next_block);
   }
   if (next_block > 122095999)
    break;
  }
  if (next_block > 122095999) {
   is_finish = 1;
   printf("\nScan IND_DATA Finish!!\n");
   break;
  }
 }
 for (i = 0; i < 4; i ++) {
  pthread_join(dti[i].thread_id, ((void *)0));
 }
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char *

variable_types: struct dump_thread_info { unsigned long thread_id; int thread_num; int disk_fd; struct dumpdind_queue { int head; int tail; int size; unsigned int block_no[2000]; 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; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; } *queue; } [4]


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

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

original_code:
static inline long PTR_ERR(const void *ptr)
{
 return (long) ptr;
}

canonical_original_code:
static inline long PTR_ERR(void *ptr)
{
 return (long) ptr;
}

variable_types:
ptr
void *

return_type: long


decompiled_code:
_BOOL8 __fastcall IS_ERR(unsigned __int64 a1)
{
return a1 > 0xFFFFFFFFFFFFF000LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 a1)
{
return a1 > 0xFFFFFFFFFFFFF000LL;
}

original_code:
static inline long IS_ERR(const void *ptr)
{
 return (((unsigned long)ptr) >= (unsigned long)-4095);
}

canonical_original_code:
static inline long IS_ERR(void *ptr)
{
 return (((unsigned long)ptr) >= (unsigned long)-4095);
}


decompiled_code:
__int64 __fastcall vbfs_create_obj(char *s, unsigned int a2)
{
char *v2; // rax
char *v3; // rbx
__int64 v4; // rbp
unsigned int v5; // ebx
char v7[464]; // [rsp+0h] [rbp-1F8h] BYREF
__int16 v8; // [rsp+1D0h] [rbp-28h]

memset(v7, 0, sizeof(v7));
v8 = 0;
v2 = strdup(s);
if ( !v2 )
return (unsigned int)-12;
v3 = v2;
if ( (unsigned int)get_lastname(v2, v7, 47LL) )
{
free(v3);
v5 = -22;
}
else if ( v7[0] )
{
v4 = pathname_to_inode(v3);
free(v3);
if ( IS_ERR(v4) )
{
v5 = PTR_ERR(v4);
}
else
{
v5 = vbfs_create(v4, v7, a2);
if ( !v5 )
vbfs_update_times(v4, 3LL);
vbfs_inode_close(v4);
}
}
else
{
free(v3);
v5 = -17;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *s, unsigned int a2)
{
char *v2; // rax
char *v3; // rbx
__int64 v4; // rbp
unsigned int v5; // ebx
char v7[464]; // [rsp+0h] [rbp-1F8h] BYREF
__int16 v8; // [rsp+1D0h] [rbp-28h]

memset(v7, 0, sizeof(v7));
v8 = 0;
v2 = strdup(s);
if ( !v2 )
return (unsigned int)-12;
v3 = v2;
if ( (unsigned int)get_lastname(v2, v7, 47LL) )
{
free(v3);
v5 = -22;
}
else if ( v7[0] )
{
v4 = pathname_to_inode(v3);
free(v3);
if ( func1(v4) )
{
v5 = func0(v4);
}
else
{
v5 = vbfs_create(v4, v7, a2);
if ( !v5 )
vbfs_update_times(v4, 3LL);
vbfs_inode_close(v4);
}
}
else
{
free(v3);
v5 = -17;
}
return v5;
}

original_code:
static int vbfs_create_obj(const char *path, uint32_t mode)
{
 int ret;
 struct inode_info *inode;
 char last_name[466];
 char *name = ((void *)0);
 char *pos = ((void *)0);
 memset(last_name, 0, sizeof(last_name));
 name = strdup(path);
 if (((void *)0) == name)
  return -12;
 pos = name;
 ret = get_lastname(pos, last_name, '/');
 if (ret) {
  free(name);
  return -22;
 }
 if (strlen(last_name) == 0) {
  free(name);
  return -17;
 }
 inode = pathname_to_inode(pos);
 free(name);
 if (IS_ERR(inode))
  return PTR_ERR(inode);
 ret = vbfs_create(inode, last_name, mode);
 if (ret) {
  vbfs_inode_close(inode);
  return ret;
 }
 vbfs_update_times(inode, UPDATE_ATIME | UPDATE_MTIME);
 vbfs_inode_close(inode);
 return 0;
}

canonical_original_code:
static int vbfs_create_obj(char *path, unsigned int mode)
{
 int ret;
 struct inode_info *inode;
 char last_name[466];
 char *name = ((void *)0);
 char *pos = ((void *)0);
 memset(last_name, 0, sizeof(last_name));
 name = strdup(path);
 if (((void *)0) == name)
  return -12;
 pos = name;
 ret = get_lastname(pos, last_name, '/');
 if (ret) {
  free(name);
  return -22;
 }
 if (strlen(last_name) == 0) {
  free(name);
  return -17;
 }
 inode = pathname_to_inode(pos);
 free(name);
 if (IS_ERR(inode))
  return PTR_ERR(inode);
 ret = vbfs_create(inode, last_name, mode);
 if (ret) {
  vbfs_inode_close(inode);
  return ret;
 }
 vbfs_update_times(inode, UPDATE_ATIME | UPDATE_MTIME);
 vbfs_inode_close(inode);
 return 0;
}

variable_types:
path
char *

variable_types:
mode
unsigned int

variable_types: ret int

variable_types: struct inode_info { struct vbfs_dirent { unsigned int i_ino; unsigned int i_pino; unsigned int i_mode; unsigned long i_size; unsigned int i_atime; unsigned int i_ctime; unsigned int i_mtime; char name[466]; } *dirent; unsigned int data_no; unsigned int position; int status; unsigned int flags; 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 hlist_node { struct hlist_node *next; } hash_list; struct list_head { struct list_head *next; } active_list; struct list_head extend_list; } *

variable_types:
name
char *

variable_types:
pos
char *

user_defined_types: struct inode_info { struct vbfs_dirent *dirent; unsigned int data_no; unsigned int position; int status; unsigned int flags; int ref; union pthread_mutex_t lock; struct hlist_node hash_list; struct list_head active_list; struct list_head extend_list; }