main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
socklen_t v4; // edx
unsigned int v5; // ebx
unsigned __int16 v6; // bp
char *v7; // rax
int result; // eax
socklen_t addr_len; // [rsp+0h] [rbp-23Ch] BYREF
pthread_t newthread; // [rsp+4h] [rbp-238h] BYREF
pthread_t th; // [rsp+Ch] [rbp-230h] BYREF
struct sockaddr v12; // [rsp+14h] [rbp-228h] BYREF
struct sockaddr addr; // [rsp+24h] [rbp-218h] BYREF
char *arg; // [rsp+34h] [rbp-208h] BYREF
unsigned int v15; // [rsp+3Ch] [rbp-200h]
char cp[16]; // [rsp+44h] [rbp-1F8h] BYREF
unsigned int v17; // [rsp+54h] [rbp-1E8h]
char s[16]; // [rsp+124h] [rbp-118h] BYREF
__int128 v19; // [rsp+134h] [rbp-108h]
__int128 v20; // [rsp+144h] [rbp-F8h]
__int128 v21; // [rsp+154h] [rbp-E8h]
__int128 v22; // [rsp+164h] [rbp-D8h]
__int128 v23; // [rsp+174h] [rbp-C8h]
__int128 v24; // [rsp+184h] [rbp-B8h]
__int128 v25; // [rsp+194h] [rbp-A8h]
__int128 v26; // [rsp+1A4h] [rbp-98h]
__int128 v27; // [rsp+1B4h] [rbp-88h]
__int128 v28; // [rsp+1C4h] [rbp-78h]
__int128 v29; // [rsp+1D4h] [rbp-68h]
__int128 v30; // [rsp+1E4h] [rbp-58h]
__int128 v31; // [rsp+1F4h] [rbp-48h]
__int128 v32; // [rsp+204h] [rbp-38h]
__int128 v33; // [rsp+214h] [rbp-28h]

addr_len = 16;
*(_OWORD *)s = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
v31 = 0LL;
v32 = 0LL;
v33 = 0LL;
if ( (unsigned int)read_configFile("siouxd.conf", cp, envp) == -1 )
{
perror(0LL);
fwrite("Erreur : Le fichier \"siouxd.conf\" est introuvable !\n", 1uLL, 0x34uLL, stderr);
result = 1;
}
else
{
arg = cp;
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror(0LL);
fwrite(&unk_D0, 1uLL, 0x33uLL, stderr);
result = 2;
}
else
{
v12 = 0LL;
*(_DWORD *)&v12.sa_data[2] = inet_addr(cp);
*(_WORD *)v12.sa_data = _bswap_16(v17);
v12.sa_family = 2;
if ( bind(v3, &v12, v4) == -1 )
{
perror(0LL);
fwrite("Erreur lors du bind entre la socket et l'adresse !\n", 1uLL, 0x33uLL, stderr);
fwrite(
"Vous devriez choisir probablement un autre port dans la configuration serveur.\n",
1uLL,
0x4FuLL,
stderr);
result = 3;
}
else if ( listen(v3, 5) == -1 )
{
perror(0LL);
fwrite("Erreur lors du listen !\n", 1uLL, 0x18uLL, stderr);
result = 4;
}
else
{
sprintf(s, aServeurLanc, cp, v17, 0.0);
write_log(cp, s);
pthread_create(&newthread, 0LL, (void *(*)(void *))&GPS_refresh, cp);
signal(15, (__sighandler_t)fermer);
signal(2, (__sighandler_t)fermer);
while ( global_stop != 1 )
{
while ( 1 )
{
v5 = accept(v3, &addr, &addr_len);
if ( v5 == -1 )
break;
v6 = _bswap_16(*(__int16 *)addr.sa_data);
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "connexion d'un client sur la socket %d depuis l'adresse %s avec le port %d", v5, v7, v6);
write_log(cp, s);
v15 = v5;
pthread_create(&th, 0LL, (void *(*)(void *))&traitement_client, &arg);
if ( global_stop == 1 )
goto LABEL_9;
}
fwrite("Erreur lors de l'ouverture d'une socket client", 1uLL, 0x2EuLL, stderr);
}
LABEL_9:
pthread_join(th, 0LL);
pthread_cancel(newthread);
close(v3);
write_log(cp, "arret du serveur");
result = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
socklen_t v4; // edx
unsigned int v5; // ebx
unsigned __int16 v6; // bp
char *v7; // rax
int result; // eax
socklen_t addr_len; // [rsp+0h] [rbp-23Ch] BYREF
pthread_t newthread; // [rsp+4h] [rbp-238h] BYREF
pthread_t th; // [rsp+Ch] [rbp-230h] BYREF
struct sockaddr v12; // [rsp+14h] [rbp-228h] BYREF
struct sockaddr addr; // [rsp+24h] [rbp-218h] BYREF
char *arg; // [rsp+34h] [rbp-208h] BYREF
unsigned int v15; // [rsp+3Ch] [rbp-200h]
char cp[16]; // [rsp+44h] [rbp-1F8h] BYREF
unsigned int v17; // [rsp+54h] [rbp-1E8h]
char s[16]; // [rsp+124h] [rbp-118h] BYREF
__int128 v19; // [rsp+134h] [rbp-108h]
__int128 v20; // [rsp+144h] [rbp-F8h]
__int128 v21; // [rsp+154h] [rbp-E8h]
__int128 v22; // [rsp+164h] [rbp-D8h]
__int128 v23; // [rsp+174h] [rbp-C8h]
__int128 v24; // [rsp+184h] [rbp-B8h]
__int128 v25; // [rsp+194h] [rbp-A8h]
__int128 v26; // [rsp+1A4h] [rbp-98h]
__int128 v27; // [rsp+1B4h] [rbp-88h]
__int128 v28; // [rsp+1C4h] [rbp-78h]
__int128 v29; // [rsp+1D4h] [rbp-68h]
__int128 v30; // [rsp+1E4h] [rbp-58h]
__int128 v31; // [rsp+1F4h] [rbp-48h]
__int128 v32; // [rsp+204h] [rbp-38h]
__int128 v33; // [rsp+214h] [rbp-28h]

addr_len = 16;
*(_OWORD *)s = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
v29 = 0LL;
v30 = 0LL;
v31 = 0LL;
v32 = 0LL;
v33 = 0LL;
if ( (unsigned int)read_configFile("siouxd.conf", cp, envp) == -1 )
{
perror(0LL);
fwrite("Erreur : Le fichier \"siouxd.conf\" est introuvable !\n", 1uLL, 0x34uLL, stderr);
result = 1;
}
else
{
arg = cp;
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror(0LL);
fwrite(&unk_D0, 1uLL, 0x33uLL, stderr);
result = 2;
}
else
{
v12 = 0LL;
*(_DWORD *)&v12.sa_data[2] = inet_addr(cp);
*(_WORD *)v12.sa_data = func0(v17);
v12.sa_family = 2;
if ( bind(v3, &v12, v4) == -1 )
{
perror(0LL);
fwrite("Erreur lors du bind entre la socket et l'adresse !\n", 1uLL, 0x33uLL, stderr);
fwrite(
"Vous devriez choisir probablement un autre port dans la configuration serveur.\n",
1uLL,
0x4FuLL,
stderr);
result = 3;
}
else if ( listen(v3, 5) == -1 )
{
perror(0LL);
fwrite("Erreur lors du listen !\n", 1uLL, 0x18uLL, stderr);
result = 4;
}
else
{
sprintf(s, aServeurLanc, cp, v17, 0.0);
write_log(cp, s);
pthread_create(&newthread, 0LL, (void *(*)(void *))&GPS_refresh, cp);
signal(15, (__sighandler_t)fermer);
signal(2, (__sighandler_t)fermer);
while ( global_stop != 1 )
{
while ( 1 )
{
v5 = accept(v3, &addr, &addr_len);
if ( v5 == -1 )
break;
v6 = func0(*(__int16 *)addr.sa_data);
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
sprintf(s, "connexion d'un client sur la socket %d depuis l'adresse %s avec le port %d", v5, v7, v6);
write_log(cp, s);
v15 = v5;
pthread_create(&th, 0LL, (void *(*)(void *))&traitement_client, &arg);
if ( global_stop == 1 )
goto LABEL_9;
}
fwrite("Erreur lors de l'ouverture d'une socket client", 1uLL, 0x2EuLL, stderr);
}
LABEL_9:
pthread_join(th, 0LL);
pthread_cancel(newthread);
close(v3);
write_log(cp, "arret du serveur");
result = 0;
}
}
}
return result;
}

original_code:
int main()
{
    int serv_sock = 0;
    config_list config;
    sockaddr_in serv_addr;
    int cli_sock = 0;
    sockaddr_in cli_addr;
    socklen_t taille_cli_addr = sizeof(cli_addr);
    pthread_t thread_gps;
    pthread_t thread_client;
    param_traitement_client config_and_socket;
    char buffer[256] = {0};
    int ret = 0;
    ret = read_configFile("siouxd.conf", &config);
    if (ret == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur : Le fichier \"siouxd.conf\" est introuvable !\n");
        return 1;
    }
    config_and_socket.config = &config;
    serv_sock = socket(2, SOCK_STREAM, 0);
    if (serv_sock == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur lors de la création de la socket serveur !\n");
        return 2;
    }
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_addr.s_addr = inet_addr(config.ip_address);
    serv_addr.sin_port = htons(config.port);
    serv_addr.sin_family = 2;
    ret = bind(serv_sock, (const sockaddr*)&serv_addr, sizeof(serv_addr));
    if (ret == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur lors du bind entre la socket et l'adresse !\n");
        fprintf(stderr, "Vous devriez choisir probablement un autre port dans la configuration serveur.\n");
        return 3;
    }
    ret = listen(serv_sock, 5);
    if (ret == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur lors du listen !\n");
        return 4;
    }
    sprintf(buffer, "serveur lancé avec l'adresse IP %s, en ecoute sur le port %d", config.ip_address, config.port);
    write_log(&config, buffer);
    pthread_create(&thread_gps, ((void *)0), GPS_refresh, (void*)&config);
    signal(15, fermer);
    signal(2, fermer);
    while (global_stop != 1)
    {
        cli_sock = accept(serv_sock, (sockaddr*)&cli_addr, &taille_cli_addr);
        if (cli_sock == -1)
        {
            fprintf(stderr, "Erreur lors de l'ouverture d'une socket client");
            continue;
        }
        sprintf(buffer, "connexion d'un client sur la socket %d depuis l'adresse %s avec le port %d", cli_sock, inet_ntoa(cli_addr.sin_addr), htons(cli_addr.sin_port));
        write_log(&config, buffer);
        config_and_socket.socket_client = cli_sock;
        pthread_create(&thread_client, ((void *)0), traitement_client, (void*)&config_and_socket);
    }
    pthread_join(thread_client, ((void *)0));
    pthread_cancel(thread_gps);
    close(serv_sock);
    write_log(&config, "arret du serveur");
    return 0;
}

canonical_original_code:
int main()
{
    int serv_sock = 0;
    struct config_list config;
    struct sockaddr_in serv_addr;
    int cli_sock = 0;
    struct sockaddr_in cli_addr;
    unsigned int taille_cli_addr = sizeof(cli_addr);
    unsigned long thread_gps;
    unsigned long thread_client;
    struct param_traitement_client config_and_socket;
    char buffer[256] = {0};
    int ret = 0;
    ret = read_configFile("siouxd.conf", &config);
    if (ret == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur : Le fichier \"siouxd.conf\" est introuvable !\n");
        return 1;
    }
    config_and_socket.config = &config;
    serv_sock = socket(2, SOCK_STREAM, 0);
    if (serv_sock == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur lors de la création de la socket serveur !\n");
        return 2;
    }
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_addr.s_addr = inet_addr(config.ip_address);
    serv_addr.sin_port = htons(config.port);
    serv_addr.sin_family = 2;
    ret = bind(serv_sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
    if (ret == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur lors du bind entre la socket et l'adresse !\n");
        fprintf(stderr, "Vous devriez choisir probablement un autre port dans la configuration serveur.\n");
        return 3;
    }
    ret = listen(serv_sock, 5);
    if (ret == -1)
    {
        perror(((void *)0));
        fprintf(stderr, "Erreur lors du listen !\n");
        return 4;
    }
    sprintf(buffer, "serveur lancé avec l'adresse IP %s, en ecoute sur le port %d", config.ip_address, config.port);
    write_log(&config, buffer);
    pthread_create(&thread_gps, ((void *)0), GPS_refresh, (void *)&config);
    signal(15, fermer);
    signal(2, fermer);
    while (global_stop != 1)
    {
        cli_sock = accept(serv_sock, (struct sockaddr *)&cli_addr, &taille_cli_addr);
        if (cli_sock == -1)
        {
            fprintf(stderr, "Erreur lors de l'ouverture d'une socket client");
            continue;
        }
        sprintf(buffer, "connexion d'un client sur la socket %d depuis l'adresse %s avec le port %d", cli_sock, inet_ntoa(cli_addr.sin_addr), htons(cli_addr.sin_port));
        write_log(&config, buffer);
        config_and_socket.socket_client = cli_sock;
        pthread_create(&thread_client, ((void *)0), traitement_client, (void *)&config_and_socket);
    }
    pthread_join(thread_client, ((void *)0));
    pthread_cancel(thread_gps);
    close(serv_sock);
    write_log(&config, "arret du serveur");
    return 0;
}

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

variable_types: struct param_traitement_client { struct config_list { char ip_address[16]; int port; char web_root_dir[64]; char log_file[64]; char gps_software[64]; int frequency; } *config; int socket_client; }

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

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


repo: coylz/Siouxd

decompiled_code:
void read_configFile()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void read_configFile(char *namefile){
}

canonical_original_code:
void read_configFile(char *namefile){
}

variable_types:
namefile
char *

return_type: void


decompiled_code:
char *__fastcall get_HTTPRequest(char *a1)
{
strtok(a1, " ");
return strtok(0LL, " ");
}

canonical_decompiled_code:
char *__fastcall func2(char *a1)
{
strtok(a1, " ");
return strtok(0LL, " ");
}

original_code:
void get_HTTPRequest(char * request){
  int fd = 0;
  int nb = 0;
  char *buffer;
  int nbCharLu = 0;
  int initStat = 0 ;
  char nb_caractere = ((void *)0);
  char request_cmd = ((void *)0);
  char request_htm = ((void *)0);
  request_cmd = (char *) strtok (request," ");
  request_htm = (char *) strtok (((void *)0)," ");
}

canonical_original_code:
void get_HTTPRequest(char *request){
  int fd = 0;
  int nb = 0;
  char *buffer;
  int nbCharLu = 0;
  int initStat = 0;
  char nb_caractere = ((void *)0);
  char request_cmd = ((void *)0);
  char request_htm = ((void *)0);
  request_cmd = (char *) strtok (request," ");
  request_htm = (char *) strtok (((void *)0)," ");
}

variable_types:
request
char *

variable_types: fd int

variable_types: nb int

variable_types:
buffer
char *

variable_types: nbCharLu int

variable_types: initStat int


log

decompiled_code:
void __fastcall log(double x)
{
;
}

canonical_decompiled_code:
void __fastcall func3(double x)
{
;
}

original_code:
void log(char * line_to_write) {
  int log_file_fd = 0;
  time_t time;
  char * message[1024];
}

canonical_original_code:
void log(char *line_to_write) {
  int log_file_fd = 0;
  long time;
  char *message[1024];
}

variable_types: time long

variable_types:
message
char *[1024]


decompiled_code:
void GPS_refresh()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void GPS_refresh (int frequency) {
}

canonical_original_code:
void GPS_refresh(int frequency) {
}

variable_types: frequency int


main

decompiled_code:
__int64 __fastcall main(int a1, char **a2, char **a3)
{
unsigned int v3; // eax
int v4; // ebx
int v5; // ebx
double v6; // xmm1_8
FILE *v7; // rax
FILE *v8; // rbp
float v10; // [rsp+8h] [rbp-420h]
float v11; // [rsp+8h] [rbp-420h]
float v12; // [rsp+Ch] [rbp-41Ch]
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

v3 = time(0LL);
srand(v3);
v4 = rand();
v10 = (float)(v4 % 80) + (float)((float)rand() * 4.6566129e-10);
v12 = (float)((rand() & 1) == 0 ? -1 : 1) * v10;
v5 = rand();
v11 = (float)(v5 % 180) + (float)((float)rand() * 4.6566129e-10);
v6 = (float)((float)((rand() & 1) == 0 ? -1 : 1) * v11);
sprintf(
s,
"  <title>GPS</title>

Latitu"
"de : %f

Longitude : %f

 "
"
 ",
v12,
v6,
v12,
v6);
v7 = fopen("position.html", "w");
if ( !v7 )
return 0xFFFFFFFFLL;
v8 = v7;
fputs(s, v7);
fclose(v8);
return 0LL;
}

variable_types: struct config_list { char ip_address[16]; int port; char web_root_dir[64]; char log_file[64]; char gps_software[64]; int frequency; }

variable_types:
buffer
char [256]

variable_types: ret int

return_type: int

user_defined_types: struct param_traitement_client { struct config_list *config; int socket_client; }


decompiled_code:
void *__fastcall checked_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("Call to malloc failed.\n", 1uLL, 0x17uLL, stderr);
fwrite("Terminating program.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("Call to malloc failed.\n", 1uLL, 0x17uLL, stderr);
fwrite("Terminating program.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

original_code:
void *checked_malloc(size_t size)
{
 void *mem = malloc( size );
 if( mem == ((void *)0) )
 {
  fprintf(stderr, "Call to malloc failed.\n");
  fprintf(stderr, "Terminating program.\n");
  exit(1);
 }
 else return mem;
}

canonical_original_code:
void *checked_malloc(unsigned long size)
{
 void *mem = malloc( size );
 if( mem == ((void *)0) )
 {
  fprintf(stderr, "Call to malloc failed.\n");
  fprintf(stderr, "Terminating program.\n");
  exit(1);
 }
 else return mem;
}

variable_types:
size
unsigned long

variable_types:
mem
void *

return_type: void *


decompiled_code:
void *__fastcall checked_realloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
fwrite("Call to realloc failed.\n", 1uLL, 0x18uLL, stderr);
fwrite("Terminating program.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

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

result = realloc(a1, a2);
if ( !result )
{
fwrite("Call to realloc failed.\n", 1uLL, 0x18uLL, stderr);
fwrite("Terminating program.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

original_code:
void *checked_realloc(void *ptr, size_t size)
{
 void *mem = realloc(ptr, size);
 if(mem == ((void *)0))
 {
  fprintf(stderr, "Call to realloc failed.\n");
  fprintf(stderr, "Terminating program.\n");
  exit(1);
 }
 return mem;
}

canonical_original_code:
void *checked_realloc(void *ptr, unsigned long size)
{
 void *mem = realloc(ptr, size);
 if(mem == ((void *)0))
 {
  fprintf(stderr, "Call to realloc failed.\n");
  fprintf(stderr, "Terminating program.\n");
  exit(1);
 }
 return mem;
}

variable_types:
ptr
void *


decompiled_code:
void *__fastcall checked_calloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
{
fwrite("Call to calloc failed.\n", 1uLL, 0x17uLL, stderr);
fwrite("Terminating program.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
{
fwrite("Call to calloc failed.\n", 1uLL, 0x17uLL, stderr);
fwrite("Terminating program.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

original_code:
void *checked_calloc(size_t nmemb, size_t size)
{
 void *mem = calloc(nmemb, size);
 if(mem == ((void *)0))
 {
  fprintf(stderr, "Call to calloc failed.\n");
  fprintf(stderr, "Terminating program.\n");
  exit(1);
 }
 return mem;
}

canonical_original_code:
void *checked_calloc(unsigned long nmemb, unsigned long size)
{
 void *mem = calloc(nmemb, size);
 if(mem == ((void *)0))
 {
  fprintf(stderr, "Call to calloc failed.\n");
  fprintf(stderr, "Terminating program.\n");
  exit(1);
 }
 return mem;
}

variable_types:
nmemb
unsigned long


setFaceNormal

decompiled_code:
void __fastcall setFaceNormal(float *a1, float a2, float a3, float a4)
{
a1[16] = a2;
a1[17] = a3;
a1[18] = a4;
}

canonical_decompiled_code:
void __fastcall func1(float *a1, float a2, float a3, float a4)
{
a1[16] = a2;
a1[17] = a3;
a1[18] = a4;
}

original_code:
void setFaceNormal(FACE *face, float x, float y, float z)
{
    face->faceNormal[0] = x;
    face->faceNormal[1] = y;
    face->faceNormal[2] = z;
    return;
}

canonical_original_code:
void setFaceNormal(struct FACE *face, float x, float y, float z)
{
    face->faceNormal[0] = x;
    face->faceNormal[1] = y;
    face->faceNormal[2] = z;
    return;
}

variable_types: struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; } *

variable_types: x float

variable_types: y float

variable_types: z float


updateMesh

original_code:
void updateMesh(MODL *model, MESH *mesh, GROUP *group, float meshOffset[3])
{
    mesh->numVertices = group->numVertices;
    free(mesh->vertices);
    mesh->vertices = group->vertices;
    group->vertices = ((void *)0);
    for(int i=0; i<mesh->numVertices; i++)
    {
 float *v = mesh->vertices[i];
 for(int j=0; j<3; j++)
 {
     v[j] -= meshOffset[j];
 }
    }
    mesh->numTexVertices = group->numTexVertices;
    free(mesh->texVertices);
    mesh->texVertices = group->texVertices;
    group->texVertices = ((void *)0);
    mesh->normals = checked_realloc(mesh->normals, sizeof(vector3)*mesh->numVertices);
    int *isUpdated = checked_calloc(mesh->numVertices, sizeof(int));
    for(int i=0; i<mesh->numFaces; i++)
    {
 freeFACE(mesh->faces[i]);
    }
    mesh->numFaces = group->numFaces;
    mesh->faces = checked_realloc(mesh->faces, sizeof(FACE *)*mesh->numFaces);
    for(int i=0; i<mesh->numFaces; i++)
    {
 mesh->faces[i] = createFACE();
 mesh->faces[i]->faceID = i;
 setFaceDefaults(mesh, mesh->faces[i]);
    }
    for(int i=0; i<mesh->numFaces; i++)
    {
 FACE *f = mesh->faces[i];
 OBJFACE *of = group->faces[i];
 f->numVertices = of->numVertices;
 f->vertexIndices = checked_malloc(sizeof(int)*f->numVertices);
 f->texVertexIndices = checked_malloc(sizeof(int)*f->numVertices);
 for(int j=0; j<f->numVertices; j++)
 {
     f->vertexIndices[j] = of->indices[j][0] - 1;
     f->texVertexIndices[j] = of->indices[j][1] - 1;
     int normalIndex = of->indices[j][2] - 1;
     if(isUpdated[f->vertexIndices[j]] != 1)
     {
  float *dn = mesh->normals[f->vertexIndices[j]];
  float *sn = group->normals[normalIndex];
  for(int k=0; k<3; k++) dn[k] = sn[k];
  isUpdated[f->vertexIndices[j]] = 1;
     }
 }
 if(f->hasMaterial != 0)
 {
     int found = 0;
     for(int i=0; i < model->numMaterials; i++)
     {
  if(strcmp(model->materialNames[i], of->materialName) == 0)
  {
      f->materialIndex = i;
      found = 1;
      break;
  }
     }
     if(found == 0)
     {
      char buffer[33];
      for(int i=0; i < model->numMaterials; i++)
      {
   strncpy(buffer, model->materialNames[i], 33);
   char *dot = strchr(buffer, '.');
   if(dot != ((void *)0))
   {
       *dot = '\0';
   }
       if(strstr(of->materialName, buffer) != ((void *)0))
   {
    f->materialIndex = i;
    found = 1;
    break;
   }
      }
     }
     if(found == 0)
     {
      fprintf(stderr, "Could not find a corresponding material for %s\n", of->materialName);
     }
 }
    }
    for(int i=0; i<mesh->numVertices; i++)
    {
 if(isUpdated[i] != 1)
 {
     printf("%d\n", isUpdated[i]);
     fprintf(stderr, "The normal for vertex %d was NOT updated in updateMESH()\n", i);
 }
    }
    free(isUpdated);
    mesh->lightData = checked_calloc(mesh->numVertices, sizeof(float));
    mesh->unknown2 = checked_calloc(mesh->numVertices, sizeof(int));
    return;
}

canonical_original_code:
void updateMesh(struct MODL *model, struct MESH *mesh, struct GROUP *group, float meshOffset[3])
{
    mesh->numVertices = group->numVertices;
    free(mesh->vertices);
    mesh->vertices = group->vertices;
    group->vertices = ((void *)0);
    for(int i = 0; i<mesh->numVertices; i++)
    {
 float *v = mesh->vertices[i];
 for(int j = 0; j<3; j++)
 {
     v[j] -= meshOffset[j];
 }
    }
    mesh->numTexVertices = group->numTexVertices;
    free(mesh->texVertices);
    mesh->texVertices = group->texVertices;
    group->texVertices = ((void *)0);
    mesh->normals = checked_realloc(mesh->normals, sizeof(vector3)*mesh->numVertices);
    int *isUpdated = checked_calloc(mesh->numVertices, sizeof(int));
    for(int i = 0; i<mesh->numFaces; i++)
    {
 freeFACE(mesh->faces[i]);
    }
    mesh->numFaces = group->numFaces;
    mesh->faces = checked_realloc(mesh->faces, sizeof(struct FACE *)*mesh->numFaces);
    for(int i = 0; i<mesh->numFaces; i++)
    {
 mesh->faces[i] = createFACE();
 mesh->faces[i]->faceID = i;
 setFaceDefaults(mesh, mesh->faces[i]);
    }
    for(int i = 0; i<mesh->numFaces; i++)
    {
 struct FACE *f = mesh->faces[i];
 struct OBJFACE *of = group->faces[i];
 f->numVertices = of->numVertices;
 f->vertexIndices = checked_malloc(sizeof(int)*f->numVertices);
 f->texVertexIndices = checked_malloc(sizeof(int)*f->numVertices);
 for(int j = 0; j<f->numVertices; j++)
 {
     f->vertexIndices[j] = of->indices[j][0] - 1;
     f->texVertexIndices[j] = of->indices[j][1] - 1;
     int normalIndex = of->indices[j][2] - 1;
     if(isUpdated[f->vertexIndices[j]] != 1)
     {
  float *dn = mesh->normals[f->vertexIndices[j]];
  float *sn = group->normals[normalIndex];
  for(int k = 0; k<3; k++) dn[k] = sn[k];
  isUpdated[f->vertexIndices[j]] = 1;
     }
 }
 if(f->hasMaterial != 0)
 {
     int found = 0;
     for(int i = 0; i < model->numMaterials; i++)
     {
  if(strcmp(model->materialNames[i], of->materialName) == 0)
  {
      f->materialIndex = i;
      found = 1;
      break;
  }
     }
     if(found == 0)
     {
      char buffer[33];
      for(int i = 0; i < model->numMaterials; i++)
      {
   strncpy(buffer, model->materialNames[i], 33);
   char *dot = strchr(buffer, '.');
   if(dot != ((void *)0))
   {
       *dot = '\0';
   }
       if(strstr(of->materialName, buffer) != ((void *)0))
   {
    f->materialIndex = i;
    found = 1;
    break;
   }
      }
     }
     if(found == 0)
     {
      fprintf(stderr, "Could not find a corresponding material for %s\n", of->materialName);
     }
 }
    }
    for(int i = 0; i<mesh->numVertices; i++)
    {
 if(isUpdated[i] != 1)
 {
     printf("%d\n", isUpdated[i]);
     fprintf(stderr, "The normal for vertex %d was NOT updated in updateMESH()\n", i);
 }
    }
    free(isUpdated);
    mesh->lightData = checked_calloc(mesh->numVertices, sizeof(float));
    mesh->unknown2 = checked_calloc(mesh->numVertices, sizeof(int));
    return;
}

variable_types: struct MODL { char fourcc[4]; int numMaterials; char **materialNames; char *modelName; int unknown1; int numGeosets; int numMeshes; struct MESH { char *meshName; int unknown1; int geometryMode; int lightingMode; int textureMode; int numVertices; int numTexVertices; int numFaces; float (*vertices)[3]; float (*texVertices)[2]; float *lightData; int *unknown2; struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; } **faces; float (*normals)[3]; int hasShadow; int unknown3; float meshRadius; float unknown4[3]; float unknown5[3]; } **meshes; int unknown2; int numNodes; struct NODE { char *name; int flags; int unknown1; int type; int meshID; int depth; int hasParent; int numChildren; int hasChildren; int hasSibling; float pivot[3]; float position[3]; float pitch; float yaw; float roll; int unknown2[12]; int parentID; int childID; int siblingID; } **nodes; float modelRadius; float insertionOffset[3]; float unknown3[3]; int unknown4[6]; } *

variable_types:
mesh
struct MESH *

variable_types: struct GROUP { char *groupName; int numVertices; int vertSize; float (*vertices)[3]; int numTexVertices; int texVertSize; float (*texVertices)[2]; int numNormals; int normSize; float (*normals)[3]; int numFaces; int faceSize; struct OBJFACE { int numVertices; int (*indices)[3]; char *materialName; } **faces; } *

variable_types:
meshOffset
float [3]

variable_types: i int

variable_types:
v
float *

variable_types: j int

variable_types:
isUpdated
int *

variable_types: normalIndex int

variable_types:
dn
float *

variable_types:
sn
float *

variable_types: k int

variable_types: found int

variable_types:
buffer
char [33]

variable_types:
dot
char *

user_defined_types: struct MODL { char fourcc[4]; int numMaterials; char **materialNames; char *modelName; int unknown1; int numGeosets; int numMeshes; struct MESH **meshes; int unknown2; int numNodes; struct NODE **nodes; float modelRadius; float insertionOffset[3]; float unknown3[3]; int unknown4[6]; }

user_defined_types: struct GROUP { char *groupName; int numVertices; int vertSize; float (*vertices)[3]; int numTexVertices; int texVertSize; float (*texVertices)[2]; int numNormals; int normSize; float (*normals)[3]; int numFaces; int faceSize; struct OBJFACE **faces; }

user_defined_types: struct MESH { char *meshName; int unknown1; int geometryMode; int lightingMode; int textureMode; int numVertices; int numTexVertices; int numFaces; float (*vertices)[3]; float (*texVertices)[2]; float *lightData; int *unknown2; struct FACE **faces; float (*normals)[3]; int hasShadow; int unknown3; float meshRadius; float unknown4[3]; float unknown5[3]; }


updateMeshes

original_code:
void updateMeshes(MODL *model, OBJ *obj, NODE *node, float parentOffset[3])
{
    float nodeOffset[3];
    for(int i=0; i<3; i++) nodeOffset[i] = parentOffset[i] + node->position[i];
    float meshOffset[3];
    for(int i=0; i<3; i++) meshOffset[i] = nodeOffset[i] + node->pivot[i];
    if(node->meshID != -1)
    {
 MESH *mesh = model->meshes[node->meshID];
 int found = 0;
 for(int i=0; i<obj->numGroups; i++)
 {
     GROUP *group = obj->groups[i];
     if(strstr(group->groupName, mesh->meshName) != ((void *)0))
     {
  updateMesh(model, mesh, group, meshOffset);
  found = 1;
  break;
     }
 }
 if(found == 0) fprintf(stderr, "Found no group corresponding to %s\n", mesh->meshName);
    }
    if(node->hasChildren != 0)
    {
 updateMeshes(model, obj, model->nodes[node->childID], nodeOffset);
    }
    if(node->hasSibling != 0)
    {
 updateMeshes(model, obj, model->nodes[node->siblingID], parentOffset);
    }
    return;
}

canonical_original_code:
void updateMeshes(struct MODL *model, struct OBJ *obj, struct NODE *node, float parentOffset[3])
{
    float nodeOffset[3];
    for(int i = 0; i<3; i++) nodeOffset[i] = parentOffset[i] + node->position[i];
    float meshOffset[3];
    for(int i = 0; i<3; i++) meshOffset[i] = nodeOffset[i] + node->pivot[i];
    if(node->meshID != -1)
    {
 struct MESH *mesh = model->meshes[node->meshID];
 int found = 0;
 for(int i = 0; i<obj->numGroups; i++)
 {
     struct GROUP *group = obj->groups[i];
     if(strstr(group->groupName, mesh->meshName) != ((void *)0))
     {
  updateMesh(model, mesh, group, meshOffset);
  found = 1;
  break;
     }
 }
 if(found == 0) fprintf(stderr, "Found no group corresponding to %s\n", mesh->meshName);
    }
    if(node->hasChildren != 0)
    {
 updateMeshes(model, obj, model->nodes[node->childID], nodeOffset);
    }
    if(node->hasSibling != 0)
    {
 updateMeshes(model, obj, model->nodes[node->siblingID], parentOffset);
    }
    return;
}

variable_types: struct OBJ { int numGroups; int groupSize; struct GROUP { char *groupName; int numVertices; int vertSize; float (*vertices)[3]; int numTexVertices; int texVertSize; float (*texVertices)[2]; int numNormals; int normSize; float (*normals)[3]; int numFaces; int faceSize; struct OBJFACE { int numVertices; int (*indices)[3]; char *materialName; } **faces; } **groups; } *

variable_types:
node
struct NODE *

variable_types:
parentOffset
float [3]

variable_types:
nodeOffset
float [3]

variable_types: struct MESH { char *meshName; int unknown1; int geometryMode; int lightingMode; int textureMode; int numVertices; int numTexVertices; int numFaces; float (*vertices)[3]; float (*texVertices)[2]; float *lightData; int *unknown2; struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; } **faces; float (*normals)[3]; int hasShadow; int unknown3; float meshRadius; float unknown4[3]; float unknown5[3]; } *

user_defined_types: struct OBJ { int numGroups; int groupSize; struct GROUP **groups; }

user_defined_types: struct NODE { char *name; int flags; int unknown1; int type; int meshID; int depth; int hasParent; int numChildren; int hasChildren; int hasSibling; float pivot[3]; float position[3]; float pitch; float yaw; float roll; int unknown2[12]; int parentID; int childID; int siblingID; }


decompiled_code:
size_t __fastcall update3do(__int64 a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // [rsp+Ch] [rbp-14h] BYREF
int v5; // [rsp+14h] [rbp-Ch]

if ( !a1 )
return fwrite("update3do() passed NULL MODL structure\n", 1uLL, 0x27uLL, stderr);
if ( !a2 )
return fwrite("update3do() passed NULL OBJ structure\n", 1uLL, 0x26uLL, stderr);
if ( !*(_DWORD *)(a1 + 52) )
return scaleTexVerts(a1, 1LL);
v3 = **(_QWORD **)(a1 + 56);
v5 = 0;
v4 = 0LL;
updateMeshes(a1, a2, v3, (float *)&v4);
return scaleTexVerts(a1, 1LL);
}

canonical_decompiled_code:
size_t __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // [rsp+Ch] [rbp-14h] BYREF
int v5; // [rsp+14h] [rbp-Ch]

if ( !a1 )
return fwrite("update3do() passed NULL MODL structure\n", 1uLL, 0x27uLL, stderr);
if ( !a2 )
return fwrite("update3do() passed NULL OBJ structure\n", 1uLL, 0x26uLL, stderr);
if ( !*(_DWORD *)(a1 + 52) )
return scaleTexVerts(a1, 1LL);
v3 = **(_QWORD **)(a1 + 56);
v5 = 0;
v4 = 0LL;
func3(a1, a2, v3, (float *)&v4);
return scaleTexVerts(a1, 1LL);
}

original_code:
void update3do(MODL *model, OBJ *obj)
{
    if(model == ((void *)0))
    {
 fprintf(stderr, "update3do() passed NULL MODL structure\n");
 return;
    }
    if(obj == ((void *)0))
    {
 fprintf(stderr, "update3do() passed NULL OBJ structure\n");
 return;
    }
    if(model->numNodes != 0)
    {
 float startingOffset[3] = {0.0, 0.0, 0.0};
 updateMeshes(model, obj, model->nodes[0], startingOffset);
    }
    scaleTexVerts(model, 1);
    return;
}

canonical_original_code:
void update3do(struct MODL *model, struct OBJ *obj)
{
    if(model == ((void *)0))
    {
 fprintf(stderr, "update3do() passed NULL MODL structure\n");
 return;
    }
    if(obj == ((void *)0))
    {
 fprintf(stderr, "update3do() passed NULL OBJ structure\n");
 return;
    }
    if(model->numNodes != 0)
    {
 float startingOffset[3] = {0.0, 0.0, 0.0};
 updateMeshes(model, obj, model->nodes[0], startingOffset);
    }
    scaleTexVerts(model, 1);
    return;
}

variable_types: struct MODL { char fourcc[4]; int numMaterials; char **materialNames; char *modelName; int unknown1; int numGeosets; int numMeshes; struct MESH { char *meshName; int unknown1; int geometryMode; int lightingMode; int textureMode; int numVertices; int numTexVertices; int numFaces; float (*vertices)[3]; float (*texVertices)[2]; float *lightData; int *unknown2; struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; } **faces; float (*normals)[3]; int hasShadow; int unknown3; float meshRadius; float unknown4[3]; float unknown5[3]; } **meshes; int unknown2; int numNodes; struct NODE { char *name; int flags; int unknown1; int type; int meshID; int depth; int hasParent; int numChildren; int hasChildren; int hasSibling; float pivot[3]; float position[3]; float pitch; float yaw; float roll; int unknown2[12]; int parentID; int childID; int siblingID; } **nodes; float modelRadius; float insertionOffset[3]; float unknown3[3]; int unknown4[6]; } *

variable_types:
startingOffset
float [3]

user_defined_types: struct OBJFACE { int numVertices; int (*indices)[3]; char *materialName; }


createMODL

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

result = (_QWORD *)checked_malloc(120LL);
result[1] = 0LL;
result[2] = 0LL;
result[5] = 0LL;
result[7] = 0LL;
return result;
}

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

result = (_QWORD *)checked_malloc(120LL);
result[1] = 0LL;
result[2] = 0LL;
result[5] = 0LL;
result[7] = 0LL;
return result;
}

original_code:
MODL *createMODL()
{
 MODL *model = checked_malloc( sizeof(MODL) );
 model->materialNames = ((void *)0);
 model->modelName = ((void *)0);
 model->meshes = ((void *)0);
 model->nodes = ((void *)0);
 return model;
}

canonical_original_code:
struct MODL *createMODL()
{
 struct MODL *model = checked_malloc( sizeof(MODL) );
 model->materialNames = ((void *)0);
 model->modelName = ((void *)0);
 model->meshes = ((void *)0);
 model->nodes = ((void *)0);
 return model;
}

return_type: struct MODL { char fourcc[4]; int numMaterials; char **materialNames; char *modelName; int unknown1; int numGeosets; int numMeshes; struct MESH { char *meshName; int unknown1; int geometryMode; int lightingMode; int textureMode; int numVertices; int numTexVertices; int numFaces; float (*vertices)[3]; float (*texVertices)[2]; float *lightData; int *unknown2; struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; } **faces; float (*normals)[3]; int hasShadow; int unknown3; float meshRadius; float unknown4[3]; float unknown5[3]; } **meshes; int unknown2; int numNodes; struct NODE { char *name; int flags; int unknown1; int type; int meshID; int depth; int hasParent; int numChildren; int hasChildren; int hasSibling; float pivot[3]; float position[3]; float pitch; float yaw; float roll; int unknown2[12]; int parentID; int childID; int siblingID; } **nodes; float modelRadius; float insertionOffset[3]; float unknown3[3]; int unknown4[6]; } *


createMESH

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

result = (_QWORD *)checked_malloc(128LL);
*result = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
result[8] = 0LL;
result[9] = 0LL;
result[10] = 0LL;
return result;
}

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

result = (_QWORD *)checked_malloc(128LL);
*result = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
result[8] = 0LL;
result[9] = 0LL;
result[10] = 0LL;
return result;
}

original_code:
MESH *createMESH()
{
 MESH *mesh = checked_malloc( sizeof(MESH) );
 mesh->meshName = ((void *)0);
 mesh->vertices = ((void *)0);
 mesh->texVertices = ((void *)0);
 mesh->lightData = ((void *)0);
 mesh->unknown2 = ((void *)0);
 mesh->faces = ((void *)0);
 mesh->normals = ((void *)0);
 return mesh;
}

canonical_original_code:
struct MESH *createMESH()
{
 struct MESH *mesh = checked_malloc( sizeof(MESH) );
 mesh->meshName = ((void *)0);
 mesh->vertices = ((void *)0);
 mesh->texVertices = ((void *)0);
 mesh->lightData = ((void *)0);
 mesh->unknown2 = ((void *)0);
 mesh->faces = ((void *)0);
 mesh->normals = ((void *)0);
 return mesh;
}

return_type: struct MESH { char *meshName; int unknown1; int geometryMode; int lightingMode; int textureMode; int numVertices; int numTexVertices; int numFaces; float (*vertices)[3]; float (*texVertices)[2]; float *lightData; int *unknown2; struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; } **faces; float (*normals)[3]; int hasShadow; int unknown3; float meshRadius; float unknown4[3]; float unknown5[3]; } *


createFACE

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

result = checked_malloc(104LL);
*(_QWORD *)(result + 80) = 0LL;
*(_QWORD *)(result + 88) = 0LL;
return result;
}

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

result = checked_malloc(104LL);
*(_QWORD *)(result + 80) = 0LL;
*(_QWORD *)(result + 88) = 0LL;
return result;
}

original_code:
FACE *createFACE()
{
 FACE *face = checked_malloc( sizeof(FACE) );
 face->vertexIndices = ((void *)0);
 face->texVertexIndices = ((void *)0);
 return face;
}

canonical_original_code:
struct FACE *createFACE()
{
 struct FACE *face = checked_malloc( sizeof(FACE) );
 face->vertexIndices = ((void *)0);
 face->texVertexIndices = ((void *)0);
 return face;
}

variable_types: struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; } *


createNODE

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

result = (_QWORD *)checked_malloc(144LL);
*result = 0LL;
return result;
}

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

result = (_QWORD *)checked_malloc(144LL);
*result = 0LL;
return result;
}

original_code:
NODE *createNODE()
{
 NODE *node = checked_malloc( sizeof(NODE) );
 node->name = ((void *)0);
 return node;
}

canonical_original_code:
struct NODE *createNODE()
{
 struct NODE *node = checked_malloc( sizeof(NODE) );
 node->name = ((void *)0);
 return node;
}

variable_types: struct NODE { char *name; int flags; int unknown1; int type; int meshID; int depth; int hasParent; int numChildren; int hasChildren; int hasSibling; float pivot[3]; float position[3]; float pitch; float yaw; float roll; int unknown2[12]; int parentID; int childID; int siblingID; } *


freeNODE

decompiled_code:
void __fastcall freeNODE(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void freeNODE( NODE *node )
{
 if( node == ((void *)0) ) return;
 free(node->name);
 free(node);
 return;
}

canonical_original_code:
void freeNODE(struct NODE *node)
{
 if( node == ((void *)0) ) return;
 free(node->name);
 free(node);
 return;
}


freeFACE

decompiled_code:
void __fastcall freeFACE(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 10));
free(*((void **)ptr + 11));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 10));
free(*((void **)ptr + 11));
free(ptr);
}
}

original_code:
void freeFACE( FACE *face )
{
 if( face == ((void *)0) ) return;
 free(face->vertexIndices);
 free(face->texVertexIndices);
 free(face);
 return;
}

canonical_original_code:
void freeFACE(struct FACE *face)
{
 if( face == ((void *)0) ) return;
 free(face->vertexIndices);
 free(face->texVertexIndices);
 free(face);
 return;
}

user_defined_types: struct FACE { int faceID; int faceType; int geometryMode; int lightingMode; int textureMode; int numVertices; int unknown1; int hasTexture; int hasMaterial; float unknown2[3]; float extraLight; float unknown3[3]; float faceNormal[3]; int *vertexIndices; int *texVertexIndices; int materialIndex; }


freeMESH

decompiled_code:
void __fastcall freeMESH(void *ptr)
{
_QWORD *v2; // rdi
__int64 v3; // rbx
void *v4; // rdi

if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 7));
free(*((void **)ptr + 8));
v2 = (_QWORD *)*((_QWORD *)ptr + 9);
if ( v2 )
{
if ( *((int *)ptr + 8) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3++];
freeFACE(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 9);
}
while ( *((_DWORD *)ptr + 8) > (int)v3 );
}
free(v2);
}
free(*((void **)ptr + 10));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v2; // rdi
__int64 v3; // rbx
void *v4; // rdi

if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 7));
free(*((void **)ptr + 8));
v2 = (_QWORD *)*((_QWORD *)ptr + 9);
if ( v2 )
{
if ( *((int *)ptr + 8) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3++];
func5(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 9);
}
while ( *((_DWORD *)ptr + 8) > (int)v3 );
}
free(v2);
}
free(*((void **)ptr + 10));
free(ptr);
}
}

original_code:
void freeMESH( MESH *mesh )
{
 if( mesh == ((void *)0) ) return;
 free(mesh->meshName);
 free(mesh->vertices);
 free(mesh->texVertices);
 free(mesh->lightData);
 free(mesh->unknown2);
 if( mesh->faces != ((void *)0) )
 {
  for(int i=0; i < mesh->numFaces; i++)
  {
   freeFACE(mesh->faces[i]);
  }
  free(mesh->faces);
 }
 free(mesh->normals);
 free(mesh);
 return;
}

canonical_original_code:
void freeMESH(struct MESH *mesh)
{
 if( mesh == ((void *)0) ) return;
 free(mesh->meshName);
 free(mesh->vertices);
 free(mesh->texVertices);
 free(mesh->lightData);
 free(mesh->unknown2);
 if( mesh->faces != ((void *)0) )
 {
  for(int i = 0; i < mesh->numFaces; i++)
  {
   freeFACE(mesh->faces[i]);
  }
  free(mesh->faces);
 }
 free(mesh->normals);
 free(mesh);
 return;
}

variable_types: i int


freeMODL

decompiled_code:
void __fastcall freeMODL(void *ptr)
{
_QWORD *v2; // rdi
__int64 v3; // rbx
void *v4; // rdi
_QWORD *v5; // rdi
__int64 v6; // rbx
void *v7; // rdi
_QWORD *v8; // rdi
__int64 v9; // rbx
void *v10; // rdi

if ( ptr )
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *((int *)ptr + 1) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3++];
free(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
}
while ( *((_DWORD *)ptr + 1) > (int)v3 );
}
free(v2);
}
free(*((void **)ptr + 2));
v5 = (_QWORD *)*((_QWORD *)ptr + 5);
if ( v5 )
{
if ( *((int *)ptr + 8) > 0 )
{
v6 = 0LL;
do
{
v7 = (void *)v5[v6++];
freeMESH(v7);
v5 = (_QWORD *)*((_QWORD *)ptr + 5);
}
while ( *((_DWORD *)ptr + 8) > (int)v6 );
}
free(v5);
}
v8 = (_QWORD *)*((_QWORD *)ptr + 7);
if ( v8 )
{
if ( *((int *)ptr + 13) > 0 )
{
v9 = 0LL;
do
{
v10 = (void *)v8[v9++];
freeNODE(v10);
v8 = (_QWORD *)*((_QWORD *)ptr + 7);
}
while ( *((_DWORD *)ptr + 13) > (int)v9 );
}
free(v8);
}
free(ptr);
}
else
{
printf("ALREADY FREED THIS MODL");
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
_QWORD *v2; // rdi
__int64 v3; // rbx
void *v4; // rdi
_QWORD *v5; // rdi
__int64 v6; // rbx
void *v7; // rdi
_QWORD *v8; // rdi
__int64 v9; // rbx
void *v10; // rdi

if ( ptr )
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *((int *)ptr + 1) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3++];
free(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
}
while ( *((_DWORD *)ptr + 1) > (int)v3 );
}
free(v2);
}
free(*((void **)ptr + 2));
v5 = (_QWORD *)*((_QWORD *)ptr + 5);
if ( v5 )
{
if ( *((int *)ptr + 8) > 0 )
{
v6 = 0LL;
do
{
v7 = (void *)v5[v6++];
func6(v7);
v5 = (_QWORD *)*((_QWORD *)ptr + 5);
}
while ( *((_DWORD *)ptr + 8) > (int)v6 );
}
free(v5);
}
v8 = (_QWORD *)*((_QWORD *)ptr + 7);
if ( v8 )
{
if ( *((int *)ptr + 13) > 0 )
{
v9 = 0LL;
do
{
v10 = (void *)v8[v9++];
func4(v10);
v8 = (_QWORD *)*((_QWORD *)ptr + 7);
}
while ( *((_DWORD *)ptr + 13) > (int)v9 );
}
free(v8);
}
free(ptr);
}
else
{
printf("ALREADY FREED THIS MODL");
}
}

original_code:
void freeMODL( MODL *model )
{
 if( model == ((void *)0) )
 {
  printf("ALREADY FREED THIS MODL");
  return;
 }
 if( model->materialNames != ((void *)0) )
 {
  for(int i=0; i < model->numMaterials; i++)
  {
   free(model->materialNames[i]);
  }
  free(model->materialNames);
 }
 free(model->modelName);
 if( model->meshes != ((void *)0) )
 {
  for(int i=0; i < model->numMeshes; i++)
  {
   freeMESH(model->meshes[i]);
  }
  free(model->meshes);
 }
 if( model->nodes != ((void *)0) )
 {
  for(int i=0; i < model->numNodes; i++)
  {
   freeNODE(model->nodes[i]);
  }
  free(model->nodes);
 }
 free(model);
 return;
}

canonical_original_code:
void freeMODL(struct MODL *model)
{
 if( model == ((void *)0) )
 {
  printf("ALREADY FREED THIS MODL");
  return;
 }
 if( model->materialNames != ((void *)0) )
 {
  for(int i = 0; i < model->numMaterials; i++)
  {
   free(model->materialNames[i]);
  }
  free(model->materialNames);
 }
 free(model->modelName);
 if( model->meshes != ((void *)0) )
 {
  for(int i = 0; i < model->numMeshes; i++)
  {
   freeMESH(model->meshes[i]);
  }
  free(model->meshes);
 }
 if( model->nodes != ((void *)0) )
 {
  for(int i = 0; i < model->numNodes; i++)
  {
   freeNODE(model->nodes[i]);
  }
  free(model->nodes);
 }
 free(model);
 return;
}


createOBJ

decompiled_code:
_QWORD *createOBJ()
{
_QWORD *v0; // r12

v0 = (_QWORD *)checked_malloc(16LL);
*v0 = 0x1000000000LL;
v0[1] = checked_malloc(128LL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = (_QWORD *)checked_malloc(16LL);
*v0 = 0x1000000000LL;
v0[1] = checked_malloc(128LL);
return v0;
}

original_code:
OBJ *createOBJ()
{
    OBJ *obj = checked_malloc(sizeof(OBJ));
    obj->numGroups = 0;
    obj->groupSize = 16;;
    obj->groups = checked_malloc(sizeof(GROUP *) * obj->groupSize);
    return obj;
}

canonical_original_code:
struct OBJ *createOBJ()
{
    struct OBJ *obj = checked_malloc(sizeof(OBJ));
    obj->numGroups = 0;
    obj->groupSize = 16;;
    obj->groups = checked_malloc(sizeof(struct GROUP *) * obj->groupSize);
    return obj;
}

return_type: struct OBJ { int numGroups; int groupSize; struct GROUP { char *groupName; int numVertices; int vertSize; float (*vertices)[3]; int numTexVertices; int texVertSize; float (*texVertices)[2]; int numNormals; int normSize; float (*normals)[3]; int numFaces; int faceSize; struct OBJFACE { int numVertices; int (*indices)[3]; char *materialName; } **faces; } **groups; } *


growGroups

decompiled_code:
__int64 __fastcall growGroups(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 4);
*(_DWORD *)(a1 + 4) = 2 * v1;
result = checked_realloc(*(_QWORD *)(a1 + 8), 16LL * v1);
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 4);
*(_DWORD *)(a1 + 4) = 2 * v1;
result = checked_realloc(*(_QWORD *)(a1 + 8), 16LL * v1);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void growGroups(OBJ *obj)
{
    obj->groupSize *= 2;
    obj->groups = checked_realloc(obj->groups, sizeof(GROUP *) * obj->groupSize);
    return;
}

canonical_original_code:
void growGroups(struct OBJ *obj)
{
    obj->groupSize *= 2;
    obj->groups = checked_realloc(obj->groups, sizeof(struct GROUP *) * obj->groupSize);
    return;
}


createGROUP

original_code:
GROUP *createGROUP()
{
    GROUP *group = checked_malloc(sizeof(GROUP));
    group->groupName = ((void *)0);
    group->numVertices = 0;
    group->numTexVertices = 0;
    group->numNormals = 0;
    group->numFaces = 0;
    group->vertSize = 16;;
    group->texVertSize = 16;;
    group->normSize = 16;;
    group->faceSize = 16;;
    group->vertices = checked_malloc(sizeof(vector3) * group->vertSize);
    group->texVertices = checked_malloc(sizeof(vector2) * group->texVertSize);
    group->normals = checked_malloc(sizeof(vector3) * group->normSize);
    group->faces = checked_malloc(sizeof(OBJFACE *) * group->faceSize);
    return group;
}

canonical_original_code:
struct GROUP *createGROUP()
{
    struct GROUP *group = checked_malloc(sizeof(GROUP));
    group->groupName = ((void *)0);
    group->numVertices = 0;
    group->numTexVertices = 0;
    group->numNormals = 0;
    group->numFaces = 0;
    group->vertSize = 16;;
    group->texVertSize = 16;;
    group->normSize = 16;;
    group->faceSize = 16;;
    group->vertices = checked_malloc(sizeof(vector3) * group->vertSize);
    group->texVertices = checked_malloc(sizeof(vector2) * group->texVertSize);
    group->normals = checked_malloc(sizeof(vector3) * group->normSize);
    group->faces = checked_malloc(sizeof(struct OBJFACE *) * group->faceSize);
    return group;
}

variable_types: struct GROUP { char *groupName; int numVertices; int vertSize; float (*vertices)[3]; int numTexVertices; int texVertSize; float (*texVertices)[2]; int numNormals; int normSize; float (*normals)[3]; int numFaces; int faceSize; struct OBJFACE { int numVertices; int (*indices)[3]; char *materialName; } **faces; } *


growVertices

decompiled_code:
__int64 __fastcall growVertices(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = 2 * *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = v1;
result = checked_realloc(*(_QWORD *)(a1 + 16), 12LL * v1);
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = 2 * *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = v1;
result = checked_realloc(*(_QWORD *)(a1 + 16), 12LL * v1);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void growVertices(GROUP *group)
{
    group->vertSize *= 2;
    group->vertices = checked_realloc(group->vertices, sizeof(vector3) * group->vertSize);
    return;
}

canonical_original_code:
void growVertices(struct GROUP *group)
{
    group->vertSize *= 2;
    group->vertices = checked_realloc(group->vertices, sizeof(vector3) * group->vertSize);
    return;
}


growTexVertices

decompiled_code:
__int64 __fastcall growTexVertices(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 28);
*(_DWORD *)(a1 + 28) = 2 * v1;
result = checked_realloc(*(_QWORD *)(a1 + 32), 16LL * v1);
*(_QWORD *)(a1 + 32) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 28);
*(_DWORD *)(a1 + 28) = 2 * v1;
result = checked_realloc(*(_QWORD *)(a1 + 32), 16LL * v1);
*(_QWORD *)(a1 + 32) = result;
return result;
}

original_code:
void growTexVertices(GROUP *group)
{
    group->texVertSize *= 2;
    group->texVertices = checked_realloc(group->texVertices, sizeof(vector2) * group->texVertSize);
    return;
}

canonical_original_code:
void growTexVertices(struct GROUP *group)
{
    group->texVertSize *= 2;
    group->texVertices = checked_realloc(group->texVertices, sizeof(vector2) * group->texVertSize);
    return;
}


growNormals

decompiled_code:
__int64 __fastcall growNormals(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = 2 * *(_DWORD *)(a1 + 44);
*(_DWORD *)(a1 + 44) = v1;
result = checked_realloc(*(_QWORD *)(a1 + 48), 12LL * v1);
*(_QWORD *)(a1 + 48) = result;
return result;
}

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

v1 = 2 * *(_DWORD *)(a1 + 44);
*(_DWORD *)(a1 + 44) = v1;
result = checked_realloc(*(_QWORD *)(a1 + 48), 12LL * v1);
*(_QWORD *)(a1 + 48) = result;
return result;
}

original_code:
void growNormals(GROUP *group)
{
    group->normSize *= 2;
    group->normals = checked_realloc(group->normals, sizeof(vector3) * group->normSize);
    return;
}

canonical_original_code:
void growNormals(struct GROUP *group)
{
    group->normSize *= 2;
    group->normals = checked_realloc(group->normals, sizeof(vector3) * group->normSize);
    return;
}


growFaces

decompiled_code:
__int64 __fastcall growFaces(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 60);
*(_DWORD *)(a1 + 60) = 2 * v1;
result = checked_realloc(*(_QWORD *)(a1 + 64), 16LL * v1);
*(_QWORD *)(a1 + 64) = result;
return result;
}

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

v1 = *(_DWORD *)(a1 + 60);
*(_DWORD *)(a1 + 60) = 2 * v1;
result = checked_realloc(*(_QWORD *)(a1 + 64), 16LL * v1);
*(_QWORD *)(a1 + 64) = result;
return result;
}

original_code:
void growFaces(GROUP *group)
{
    group->faceSize *= 2;
    group->faces = checked_realloc(group->faces, sizeof(OBJFACE *) * group->faceSize);
    return;
}

canonical_original_code:
void growFaces(struct GROUP *group)
{
    group->faceSize *= 2;
    group->faces = checked_realloc(group->faces, sizeof(struct OBJFACE *) * group->faceSize);
    return;
}


createOBJFACE

decompiled_code:
__int64 createOBJFACE()
{
__int64 v0; // rax
__int64 v1; // r12

v0 = checked_malloc(24LL);
*(_DWORD *)v0 = 0;
v1 = v0;
*(_QWORD *)(v0 + 8) = checked_malloc(96LL);
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
__int64 v1; // r12

v0 = checked_malloc(24LL);
*(_DWORD *)v0 = 0;
v1 = v0;
*(_QWORD *)(v0 + 8) = checked_malloc(96LL);
return v1;
}

original_code:
OBJFACE *createOBJFACE()
{
    OBJFACE *objface = checked_malloc(sizeof(OBJFACE));
    objface->numVertices = 0;
    objface->indices = checked_malloc(sizeof(indexTriplet) * 8);
    return objface;
}

canonical_original_code:
struct OBJFACE *createOBJFACE()
{
    struct OBJFACE *objface = checked_malloc(sizeof(OBJFACE));
    objface->numVertices = 0;
    objface->indices = checked_malloc(sizeof(indexTriplet) * 8);
    return objface;
}

variable_types: struct OBJFACE { int numVertices; int (*indices)[3]; char *materialName; } *


processGroupLine

decompiled_code:
__int64 __fastcall processGroupLine(int *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
_QWORD *v4; // r12
_QWORD *v5; // rax

if ( !a1 )
fwrite("NULL OBJ IN processGroupLine()\n", 1uLL, 0x1FuLL, stderr);
totalVertexCount += groupVertexCount;
groupVertexCount = 0;
totalTexVertexCount += groupTexVertexCount;
totalNormalCount += groupNormalCount;
v2 = *a1;
groupTexVertexCount = 0;
groupNormalCount = 0;
v3 = v2 + 1;
*a1 = v3;
if ( v3 > a1[1] )
{
growGroups(a1);
v3 = *a1;
}
v4 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * v3 - 8);
v5 = (_QWORD *)createGROUP();
*v4 = v5;
group = (__int64)v5;
*v5 = checked_malloc(33LL);
return _isoc99_sscanf(a2, "%*1[og] %32s", *(_QWORD *)group);
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
_QWORD *v4; // r12
_QWORD *v5; // rax

if ( !a1 )
fwrite("NULL OBJ IN processGroupLine()\n", 1uLL, 0x1FuLL, stderr);
totalVertexCount += groupVertexCount;
groupVertexCount = 0;
totalTexVertexCount += groupTexVertexCount;
totalNormalCount += groupNormalCount;
v2 = *a1;
groupTexVertexCount = 0;
groupNormalCount = 0;
v3 = v2 + 1;
*a1 = v3;
if ( v3 > a1[1] )
{
growGroups(a1);
v3 = *a1;
}
v4 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * v3 - 8);
v5 = (_QWORD *)createGROUP();
*v4 = v5;
group = (__int64)v5;
*v5 = checked_malloc(33LL);
return _isoc99_sscanf(a2, "%*1[og] %32s", *(_QWORD *)group);
}

original_code:
void processGroupLine(OBJ *obj, char *line)
{
    if(obj==((void *)0)) fprintf(stderr, "NULL OBJ IN processGroupLine()\n");
    totalVertexCount += groupVertexCount;
    groupVertexCount = 0;
    totalTexVertexCount += groupTexVertexCount;
    groupTexVertexCount = 0;
    totalNormalCount += groupNormalCount;
    groupNormalCount = 0;
    if(++obj->numGroups > obj->groupSize) growGroups(obj);
    group = obj->groups[obj->numGroups - 1] = createGROUP();
    group->groupName = checked_malloc(sizeof(char) * (32 + 1));
    sscanf(line, "%*1[og] %32s", group->groupName);
}

canonical_original_code:
void processGroupLine(struct OBJ *obj, char *line)
{
    if(obj==((void *)0)) fprintf(stderr, "NULL OBJ IN processGroupLine()\n");
    totalVertexCount += groupVertexCount;
    groupVertexCount = 0;
    totalTexVertexCount += groupTexVertexCount;
    groupTexVertexCount = 0;
    totalNormalCount += groupNormalCount;
    groupNormalCount = 0;
    if(++obj->numGroups > obj->groupSize) growGroups(obj);
    group = obj->groups[obj->numGroups - 1] = createGROUP();
    group->groupName = checked_malloc(sizeof(char) * (32 + 1));
    sscanf(line, "%*1[og] %32s", group->groupName);
}

variable_types:
line
char *


processVertexLine

decompiled_code:
void __fastcall processVertexLine(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // eax

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 8) + 1;
*(_DWORD *)(group + 8) = v3;
if ( v3 > *(_DWORD *)(v2 + 12) )
{
growVertices();
v2 = group;
v3 = *(_DWORD *)(group + 8);
}
v4 = _isoc99_sscanf(a1, "v %f %f %f", *(_QWORD *)(v2 + 16) + 12LL * v3 - 12);
if ( v4 == 3 )
{
++groupVertexCount;
}
else
{
fprintf(stderr, "sscanf() read %d values in processVertexLine()\n", v4);
++groupVertexCount;
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // eax

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 8) + 1;
*(_DWORD *)(group + 8) = v3;
if ( v3 > *(_DWORD *)(v2 + 12) )
{
growVertices();
v2 = group;
v3 = *(_DWORD *)(group + 8);
}
v4 = _isoc99_sscanf(a1, "v %f %f %f", *(_QWORD *)(v2 + 16) + 12LL * v3 - 12);
if ( v4 == 3 )
{
++groupVertexCount;
}
else
{
fprintf(stderr, "sscanf() read %d values in processVertexLine()\n", v4);
++groupVertexCount;
}
}
}

original_code:
void processVertexLine(char *line)
{
    if(group == ((void *)0)) return;
    if(++group->numVertices > group->vertSize) growVertices(group);
    float *v = group->vertices[group->numVertices - 1];
    int read = sscanf(line, "v %f %f %f", v, v+1, v+2);
    if(read != 3) fprintf(stderr, "sscanf() read %d values in processVertexLine()\n", read);
    groupVertexCount++;
}

variable_types:
v
float *

variable_types: read int


processTexVertexLine

decompiled_code:
void __fastcall processTexVertexLine(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
__int64 v4; // rbx
unsigned int v5; // eax

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 24) + 1;
*(_DWORD *)(group + 24) = v3;
if ( v3 > *(_DWORD *)(v2 + 28) )
{
growTexVertices();
v2 = group;
v3 = *(_DWORD *)(group + 24);
}
v4 = *(_QWORD *)(v2 + 32) + 8LL * v3 - 8;
v5 = _isoc99_sscanf(a1, "vt %f %f", v4);
*(_DWORD *)(v4 + 4) ^= LC5;
if ( v5 != 2 )
fprintf(stderr, "sscanf() read %d values in processTexVertexLine()\n", v5);
++groupTexVertexCount;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
__int64 v4; // rbx
unsigned int v5; // eax

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 24) + 1;
*(_DWORD *)(group + 24) = v3;
if ( v3 > *(_DWORD *)(v2 + 28) )
{
growTexVertices();
v2 = group;
v3 = *(_DWORD *)(group + 24);
}
v4 = *(_QWORD *)(v2 + 32) + 8LL * v3 - 8;
v5 = _isoc99_sscanf(a1, "vt %f %f", v4);
*(_DWORD *)(v4 + 4) ^= LC5;
if ( v5 != 2 )
fprintf(stderr, "sscanf() read %d values in processTexVertexLine()\n", v5);
++groupTexVertexCount;
}
}

original_code:
void processTexVertexLine(char *line)
{
    if(group == ((void *)0)) return;
    if(++group->numTexVertices > group->texVertSize) growTexVertices(group);
    float *vt = group->texVertices[group->numTexVertices - 1];
    int read = sscanf(line, "vt %f %f", vt, vt+1);
    *(vt+1) *= -1;
    if(read != 2) fprintf(stderr, "sscanf() read %d values in processTexVertexLine()\n", read);
    groupTexVertexCount++;
}

variable_types:
vt
float *


processNormalLine

decompiled_code:
void __fastcall processNormalLine(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // eax

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 40) + 1;
*(_DWORD *)(group + 40) = v3;
if ( v3 > *(_DWORD *)(v2 + 44) )
{
growNormals();
v2 = group;
v3 = *(_DWORD *)(group + 40);
}
v4 = _isoc99_sscanf(a1, "vn %f %f %f", *(_QWORD *)(v2 + 48) + 12LL * v3 - 12);
if ( v4 == 3 )
{
++groupNormalCount;
}
else
{
fprintf(stderr, "sscanf() read %d values in processNormalLine()\n", v4);
++groupNormalCount;
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
unsigned int v4; // eax

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 40) + 1;
*(_DWORD *)(group + 40) = v3;
if ( v3 > *(_DWORD *)(v2 + 44) )
{
growNormals();
v2 = group;
v3 = *(_DWORD *)(group + 40);
}
v4 = _isoc99_sscanf(a1, "vn %f %f %f", *(_QWORD *)(v2 + 48) + 12LL * v3 - 12);
if ( v4 == 3 )
{
++groupNormalCount;
}
else
{
fprintf(stderr, "sscanf() read %d values in processNormalLine()\n", v4);
++groupNormalCount;
}
}
}

original_code:
void processNormalLine(char *line)
{
    if(group == ((void *)0)) return;
    if(++group->numNormals > group->normSize) growNormals(group);
    float *vn = group->normals[group->numNormals - 1];
    int read = sscanf(line, "vn %f %f %f", vn, vn+1, vn+2);
    if(read != 3) fprintf(stderr, "sscanf() read %d values in processNormalLine()\n", read);
    groupNormalCount++;
}

variable_types:
vn
float *


processFaceLine

decompiled_code:
void __fastcall processFaceLine(char *a1)
{
__int64 v2; // rdi
int v3; // eax
__int64 *v4; // rbp
__int64 v5; // rax
char *v6; // rdi
int *v7; // r12
char v8; // al
bool v9; // zf
__int64 v10; // rax
int v11; // edx
__int64 i; // rbp
const char *v13; // r13
_DWORD *v14; // rbx
unsigned int v15; // eax
char *v16; // rax
__int64 v17[15]; // [rsp+0h] [rbp-78h]

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 56) + 1;
*(_DWORD *)(group + 56) = v3;
if ( v3 > *(_DWORD *)(v2 + 60) )
{
growFaces();
v2 = group;
v3 = *(_DWORD *)(group + 56);
}
v4 = (__int64 *)(*(_QWORD *)(v2 + 64) + 8LL * v3 - 8);
v5 = createOBJFACE();
v6 = a1 + 1;
*v4 = v5;
v7 = (int *)v5;
v8 = *a1;
if ( *a1 != 10 )
{
while ( 1 )
{
if ( v8 == 32 )
{
v9 = *v6 == 10;
*(v6 - 1) = 0;
if ( v9 )
{
v11 = *v7;
}
else
{
v10 = *v7;
v11 = v10 + 1;
v17[v10] = (__int64)v6;
*v7 = v10 + 1;
}
if ( v11 > 8 )
break;
}
v8 = *v6++;
if ( v8 == 10 )
goto LABEL_12;
}
fprintf(stderr, "More than %d vertices in this face.\n", 8LL);
}
LABEL_12:
for ( i = 0LL; *v7 > (int)i; v14[2] -= totalNormalCount )
{
v13 = (const char *)v17[i];
v14 = (_DWORD *)(*((_QWORD *)v7 + 1) + 12 * i);
v15 = _isoc99_sscanf(v13, "%d%*c%d%*c%d", v14);
if ( v15 != 3 )
{
fprintf(stderr, "sscanf() read %d values in processFaceLine()\n", v15);
fprintf(stderr, "reading from '%s'\n", v13);
}
++i;
*v14 -= totalVertexCount;
v14[1] -= totalTexVertexCount;
}
v16 = (char *)checked_malloc(32LL);
*((_QWORD *)v7 + 2) = v16;
strncpy(v16, matName, 0x20uLL);
}
}

canonical_decompiled_code:
void __fastcall func4(char *a1)
{
__int64 v2; // rdi
int v3; // eax
__int64 *v4; // rbp
__int64 v5; // rax
char *v6; // rdi
int *v7; // r12
char v8; // al
bool v9; // zf
__int64 v10; // rax
int v11; // edx
__int64 i; // rbp
const char *v13; // r13
_DWORD *v14; // rbx
unsigned int v15; // eax
char *v16; // rax
__int64 v17[15]; // [rsp+0h] [rbp-78h]

v2 = group;
if ( group )
{
v3 = *(_DWORD *)(group + 56) + 1;
*(_DWORD *)(group + 56) = v3;
if ( v3 > *(_DWORD *)(v2 + 60) )
{
growFaces();
v2 = group;
v3 = *(_DWORD *)(group + 56);
}
v4 = (__int64 *)(*(_QWORD *)(v2 + 64) + 8LL * v3 - 8);
v5 = createOBJFACE();
v6 = a1 + 1;
*v4 = v5;
v7 = (int *)v5;
v8 = *a1;
if ( *a1 != 10 )
{
while ( 1 )
{
if ( v8 == 32 )
{
v9 = *v6 == 10;
*(v6 - 1) = 0;
if ( v9 )
{
v11 = *v7;
}
else
{
v10 = *v7;
v11 = v10 + 1;
v17[v10] = (__int64)v6;
*v7 = v10 + 1;
}
if ( v11 > 8 )
break;
}
v8 = *v6++;
if ( v8 == 10 )
goto LABEL_12;
}
fprintf(stderr, "More than %d vertices in this face.\n", 8LL);
}
LABEL_12:
for ( i = 0LL; *v7 > (int)i; v14[2] -= totalNormalCount )
{
v13 = (const char *)v17[i];
v14 = (_DWORD *)(*((_QWORD *)v7 + 1) + 12 * i);
v15 = _isoc99_sscanf(v13, "%d%*c%d%*c%d", v14);
if ( v15 != 3 )
{
fprintf(stderr, "sscanf() read %d values in processFaceLine()\n", v15);
fprintf(stderr, "reading from '%s'\n", v13);
}
++i;
*v14 -= totalVertexCount;
v14[1] -= totalTexVertexCount;
}
v16 = (char *)checked_malloc(32LL);
*((_QWORD *)v7 + 2) = v16;
strncpy(v16, matName, 0x20uLL);
}
}

original_code:
void processFaceLine(char *line)
{
    if(group == ((void *)0)) return;
    if(++group->numFaces > group->faceSize) growFaces(group);
    OBJFACE *f = group->faces[group->numFaces-1] = createOBJFACE();
    char *triplets[8 + 1];
    char *current = line;
    while(*current != '\n')
    {
 if(*current == ' ')
 {
     *current = '\0';
     if(*(current+1) != '\n')
     {
  triplets[f->numVertices++] = current+1;
     }
     if(f->numVertices > 8)
     {
  fprintf(stderr, "More than %d vertices in this face.\n", 8);
  break;
     }
 }
 current++;
    }
    for(int i=0; i < f->numVertices; i++)
    {
 int *it = f->indices[i];
 int read = sscanf(triplets[i], "%d%*c%d%*c%d", it, it+1, it+2);
 if(read != 3) fprintf(stderr, "sscanf() read %d values in processFaceLine()\n", read);
 if(read != 3) fprintf(stderr, "reading from '%s'\n", triplets[i]);
 it[0] -= totalVertexCount;
 it[1] -= totalTexVertexCount;
 it[2] -= totalNormalCount;
    }
    f->materialName = checked_malloc(sizeof(matName));
    strncpy(f->materialName, matName, 32);
}

canonical_original_code:
void processFaceLine(char *line)
{
    if(group == ((void *)0)) return;
    if(++group->numFaces > group->faceSize) growFaces(group);
    struct OBJFACE *f = group->faces[group->numFaces-1] = createOBJFACE();
    char *triplets[-1];
    char *current = line;
    while(*current != '\n')
    {
 if(*current == ' ')
 {
     *current = '\0';
     if(*(current+1) != '\n')
     {
  triplets[f->numVertices++] = current+1;
     }
     if(f->numVertices > 8)
     {
  fprintf(stderr, "More than %d vertices in this face.\n", 8);
  break;
     }
 }
 current++;
    }
    for(int i = 0; i < f->numVertices; i++)
    {
 int *it = f->indices[i];
 int read = sscanf(triplets[i], "%d%*c%d%*c%d", it, it+1, it+2);
 if(read != 3) fprintf(stderr, "sscanf() read %d values in processFaceLine()\n", read);
 if(read != 3) fprintf(stderr, "reading from '%s'\n", triplets[i]);
 it[0] -= totalVertexCount;
 it[1] -= totalTexVertexCount;
 it[2] -= totalNormalCount;
    }
    f->materialName = checked_malloc(sizeof(matName));
    strncpy(f->materialName, matName, 32);
}

variable_types:
triplets
char *[-1]

variable_types:
current
char *

variable_types:
it
int *


processMaterialLine

decompiled_code:
void __fastcall processMaterialLine(__int64 a1)
{
unsigned int v1; // eax
char *v2; // rax

if ( group )
{
v1 = _isoc99_sscanf(a1, "usemtl %s", matName);
if ( v1 != 1 )
fprintf(stderr, "sscanf() read %d values in processMaterialLine()\n", v1);
v2 = strstr(matName, ".mat");
if ( v2 )
v2[4] = 0;
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
unsigned int v1; // eax
char *v2; // rax

if ( group )
{
v1 = _isoc99_sscanf(a1, "usemtl %s", matName);
if ( v1 != 1 )
fprintf(stderr, "sscanf() read %d values in processMaterialLine()\n", v1);
v2 = strstr(matName, ".mat");
if ( v2 )
v2[4] = 0;
}
}

original_code:
void processMaterialLine(char *line)
{
    if(group == ((void *)0)) return;
    int read = sscanf(line, "usemtl %s", matName);
    if(read != 1) fprintf(stderr, "sscanf() read %d values in processMaterialLine()\n", read);
    char *c = strstr(matName, ".mat");
    if( c != ((void *)0))
    {
 *(c+4) = '\0';
    }
    return;
}

variable_types:
c
char *


processLine

decompiled_code:
void __fastcall processLine(int *a1, char *a2)
{
char v2; // al

if ( *a2 != 10 )
{
switch ( *a2 )
{
case 'f':
processFaceLine(a2);
break;
case 'g':
case 'o':
processGroupLine(a1, (__int64)a2);
break;
case 'u':
processMaterialLine((__int64)a2);
break;
case 'v':
v2 = a2[1];
switch ( v2 )
{
case 'n':
processNormalLine((__int64)a2);
break;
case 't':
processTexVertexLine((__int64)a2);
break;
case ' ':
processVertexLine((__int64)a2);
break;
default:
goto LABEL_7;
}
break;
default:
LABEL_7:
fprintf(stderr, "Unhandled line: %s", a2);
break;
}
}
}

canonical_decompiled_code:
void __fastcall func6(int *a1, char *a2)
{
char v2; // al

if ( *a2 != 10 )
{
switch ( *a2 )
{
case 'f':
func4(a2);
break;
case 'g':
case 'o':
func0(a1, (__int64)a2);
break;
case 'u':
func5((__int64)a2);
break;
case 'v':
v2 = a2[1];
switch ( v2 )
{
case 'n':
func3((__int64)a2);
break;
case 't':
func2((__int64)a2);
break;
case ' ':
func1((__int64)a2);
break;
default:
goto LABEL_7;
}
break;
default:
LABEL_7:
fprintf(stderr, "Unhandled line: %s", a2);
break;
}
}
}

original_code:
void processLine(OBJ *obj, char *line)
{
    switch(line[0])
    {
 case 'o':
     processGroupLine(obj, line);
     break;
 case 'g':
     processGroupLine(obj, line);
     break;
 case 'v':
     switch(line[1])
     {
  case ' ':
      processVertexLine(line);
      break;
  case 't':
      processTexVertexLine(line);
      break;
  case 'n':
      processNormalLine(line);
      break;
  default:
      fprintf(stderr, "Unhandled line: %s", line);
      break;
     }
     break;
 case 'f':
     processFaceLine(line);
     break;
 case 'u':
     processMaterialLine(line);
     break;
 case '\n':
     break;
 default:
     fprintf(stderr, "Unhandled line: %s", line);
     break;
    }
}

canonical_original_code:
void processLine(struct OBJ *obj, char *line)
{
    switch(line[0])
    {
 case 'o':
     processGroupLine(obj, line);
     break;
 case 'g':
     processGroupLine(obj, line);
     break;
 case 'v':
     switch(line[1])
     {
  case ' ':
      processVertexLine(line);
      break;
  case 't':
      processTexVertexLine(line);
      break;
  case 'n':
      processNormalLine(line);
      break;
  default:
      fprintf(stderr, "Unhandled line: %s", line);
      break;
     }
     break;
 case 'f':
     processFaceLine(line);
     break;
 case 'u':
     processMaterialLine(line);
     break;
 case '\n':
     break;
 default:
     fprintf(stderr, "Unhandled line: %s", line);
     break;
    }
}

variable_types: struct OBJ { int numGroups; int groupSize; struct GROUP { char *groupName; int numVertices; int vertSize; float (*vertices)[3]; int numTexVertices; int texVertSize; float (*texVertices)[2]; int numNormals; int normSize; float (*normals)[3]; int numFaces; int faceSize; struct OBJFACE { int numVertices; int (*indices)[3]; char *materialName; } **faces; } **groups; } *


mystrndup

decompiled_code:
char *__fastcall mystrndup(char *src, size_t n)
{
char *v2; // rax
char *result; // rax

v2 = (char *)checked_malloc(n + 1);
result = strncpy(v2, src, n);
result[n] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *src, size_t n)
{
char *v2; // rax
char *result; // rax

v2 = (char *)checked_malloc(n + 1);
result = strncpy(v2, src, n);
result[n] = 0;
return result;
}

original_code:
char *mystrndup(const char *s, size_t n)
{
 char *r = checked_malloc(sizeof(char) * (n+1));
 strncpy(r, s, n);
 r[n] = '\0';
 return r;
}

canonical_original_code:
char *mystrndup(char *s, unsigned long n)
{
 char *r = checked_malloc(sizeof(char) * (n+1));
 strncpy(r, s, n);
 r[n] = '\0';
 return r;
}

variable_types:
s
char *

variable_types:
n
unsigned long

variable_types:
r
char *

return_type: char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // edx
int v5; // ebx
signed __int64 v6; // rax
void *v7; // rsp
void *v8; // rsp
__int64 v9; // r15
int v10; // er10
int v11; // er13
int v12; // eax
int result; // eax
__int64 v14; // r14
double v15; // rax
unsigned int v16; // ebx
__int64 v17; // r8
unsigned int v18; // er10
float v19; // xmm2_4
unsigned int v20; // er13
int v21; // ebx
float v22; // xmm0_4
float v23; // xmm4_4
_DWORD v24[2]; // [rsp+0h] [rbp-D0h] BYREF
__suseconds_t v25; // [rsp+8h] [rbp-C8h]
struct timeval *v26; // [rsp+10h] [rbp-C0h]
time_t v27; // [rsp+18h] [rbp-B8h]
_DWORD *v28; // [rsp+20h] [rbp-B0h]
_DWORD *v29; // [rsp+28h] [rbp-A8h]
double v30; // [rsp+30h] [rbp-A0h]
__int64 v31; // [rsp+38h] [rbp-98h]
socklen_t addr_len; // [rsp+4Ch] [rbp-84h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-80h] BYREF
struct sockaddr v34; // [rsp+60h] [rbp-70h] BYREF
struct timeval tv; // [rsp+70h] [rbp-60h] BYREF
char s[80]; // [rsp+80h] [rbp-50h] BYREF

v3 = 2;
if ( argc > 1 )
v3 = atoi(argv[1]);
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32_constprop_0(2LL, 1LL, 6LL);
*(_WORD *)addr.sa_data = _bswap_16_constprop_0();
v5 = socket(2, 1, v4);
if ( bind(v5, &addr, 0x10u) < 0 )
{
puts("Failed to bind server.");
result = -1;
}
else if ( listen(v5, v3) < 0 )
{
puts("Failed to set server socket to listen");
result = -1;
}
else
{
addr_len = 16;
v31 = v3;
v6 = 16 * ((unsigned __int64)(4LL * v3 + 15) >> 4);
v7 = alloca(v6);
v8 = alloca(v6);
printf("Waiting on %i clients to connect\n", (unsigned int)v3);
if ( v3 <= 0 )
{
v27 = time(0LL);
v26 = &tv;
gettimeofday(&tv, 0LL);
v18 = 0;
v28 = v24;
v23 = (double)SLODWORD(tv.tv_usec) * 0.001;
*(float *)&v31 = v23;
}
else
{
v9 = 0LL;
do
{
v11 = v9;
v12 = accept(v5, &v34, &addr_len);
v24[v9] = v12;
if ( v12 < 0 )
{
printf("Server failed to accept client");
return -1;
}
v24[v9] = *(_DWORD *)&v34.sa_data[2];
printf("Client %i has reported in\n", (unsigned int)v9);
v10 = ++v9;
}
while ( v31 != v9 );
LODWORD(v31) = v10;
v27 = time(0LL);
v26 = &tv;
gettimeofday(&tv, 0LL);
v29 = v24;
v14 = 0LL;
v28 = v24;
v25 = tv.tv_usec;
*(_QWORD *)&v15 = (unsigned int)v31;
LODWORD(v31) = v11;
v30 = v15;
v16 = LODWORD(v15);
do
{
v17 = 0LL;
if ( (int)v31 > (int)v14 )
v17 = (unsigned int)v29[(int)v14 + 1];
*(_QWORD *)&s[16] = 0LL;
*(_WORD *)&s[28] = 0;
*(_DWORD *)&s[24] = 0;
*(_OWORD *)s = 0LL;
sprintf(s, "%i+%i+%i", (unsigned int)v14, v16, v17);
if ( send(v24[v14], s, 0x1EuLL, 0) != 30 )
{
printf("Sending info to Client %i failed.\n", (unsigned int)v14);
return -1;
}
++v14;
}
while ( v14 != *(_QWORD *)&v30 );
v18 = v16;
v19 = (double)(int)v25 * 0.001;
*(float *)&v31 = v19;
}
memset(s, 0, 0x1EuLL);
v20 = v18 - 1;
v30 = 0.001;
if ( (int)recv(v24[v18 - 1], s, 0x1EuLL, 0) < 0 )
{
printf("Recieve from Client %i failed.\n", v20);
result = -1;
}
else
{
printf("\nRecieved result from Client %i:\n --- Size of LCS = %s\n", v20, s);
v21 = time(0LL);
gettimeofday(v26, 0LL);
v22 = (double)SLODWORD(tv.tv_usec) * v30;
printf("\nRuntime: %f ms\n\n", (float)((float)(v22 - *(float *)&v31) + (float)(1000 * (v21 - v27))));
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // edx
int v5; // ebx
signed __int64 v6; // rax
void *v7; // rsp
void *v8; // rsp
__int64 v9; // r15
int v10; // er10
int v11; // er13
int v12; // eax
int result; // eax
__int64 v14; // r14
double v15; // rax
unsigned int v16; // ebx
__int64 v17; // r8
unsigned int v18; // er10
float v19; // xmm2_4
unsigned int v20; // er13
int v21; // ebx
float v22; // xmm0_4
float v23; // xmm4_4
_DWORD v24[2]; // [rsp+0h] [rbp-D0h] BYREF
__suseconds_t v25; // [rsp+8h] [rbp-C8h]
struct timeval *v26; // [rsp+10h] [rbp-C0h]
time_t v27; // [rsp+18h] [rbp-B8h]
_DWORD *v28; // [rsp+20h] [rbp-B0h]
_DWORD *v29; // [rsp+28h] [rbp-A8h]
double v30; // [rsp+30h] [rbp-A0h]
__int64 v31; // [rsp+38h] [rbp-98h]
socklen_t addr_len; // [rsp+4Ch] [rbp-84h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-80h] BYREF
struct sockaddr v34; // [rsp+60h] [rbp-70h] BYREF
struct timeval tv; // [rsp+70h] [rbp-60h] BYREF
char s[80]; // [rsp+80h] [rbp-50h] BYREF

v3 = 2;
if ( argc > 1 )
v3 = atoi(argv[1]);
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func7(2LL, 1LL, 6LL);
*(_WORD *)addr.sa_data = func8();
v5 = socket(2, 1, v4);
if ( bind(v5, &addr, 0x10u) < 0 )
{
puts("Failed to bind server.");
result = -1;
}
else if ( listen(v5, v3) < 0 )
{
puts("Failed to set server socket to listen");
result = -1;
}
else
{
addr_len = 16;
v31 = v3;
v6 = 16 * ((unsigned __int64)(4LL * v3 + 15) >> 4);
v7 = alloca(v6);
v8 = alloca(v6);
printf("Waiting on %i clients to connect\n", (unsigned int)v3);
if ( v3 <= 0 )
{
v27 = time(0LL);
v26 = &tv;
gettimeofday(&tv, 0LL);
v18 = 0;
v28 = v24;
v23 = (double)SLODWORD(tv.tv_usec) * 0.001;
*(float *)&v31 = v23;
}
else
{
v9 = 0LL;
do
{
v11 = v9;
v12 = accept(v5, &v34, &addr_len);
v24[v9] = v12;
if ( v12 < 0 )
{
printf("Server failed to accept client");
return -1;
}
v24[v9] = *(_DWORD *)&v34.sa_data[2];
printf("Client %i has reported in\n", (unsigned int)v9);
v10 = ++v9;
}
while ( v31 != v9 );
LODWORD(v31) = v10;
v27 = time(0LL);
v26 = &tv;
gettimeofday(&tv, 0LL);
v29 = v24;
v14 = 0LL;
v28 = v24;
v25 = tv.tv_usec;
*(_QWORD *)&v15 = (unsigned int)v31;
LODWORD(v31) = v11;
v30 = v15;
v16 = LODWORD(v15);
do
{
v17 = 0LL;
if ( (int)v31 > (int)v14 )
v17 = (unsigned int)v29[(int)v14 + 1];
*(_QWORD *)&s[16] = 0LL;
*(_WORD *)&s[28] = 0;
*(_DWORD *)&s[24] = 0;
*(_OWORD *)s = 0LL;
sprintf(s, "%i+%i+%i", (unsigned int)v14, v16, v17);
if ( send(v24[v14], s, 0x1EuLL, 0) != 30 )
{
printf("Sending info to Client %i failed.\n", (unsigned int)v14);
return -1;
}
++v14;
}
while ( v14 != *(_QWORD *)&v30 );
v18 = v16;
v19 = (double)(int)v25 * 0.001;
*(float *)&v31 = v19;
}
memset(s, 0, 0x1EuLL);
v20 = v18 - 1;
v30 = 0.001;
if ( (int)recv(v24[v18 - 1], s, 0x1EuLL, 0) < 0 )
{
printf("Recieve from Client %i failed.\n", v20);
result = -1;
}
else
{
printf("\nRecieved result from Client %i:\n --- Size of LCS = %s\n", v20, s);
v21 = time(0LL);
gettimeofday(v26, 0LL);
v22 = (double)SLODWORD(tv.tv_usec) * v30;
printf("\nRuntime: %f ms\n\n", (float)((float)(v22 - *(float *)&v31) + (float)(1000 * (v21 - v27))));
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int max_connections = 2;
 if(argc>1)
 {
  max_connections = atoi(argv[1]);
 }
 struct sockaddr_in server_address;
 memset(&server_address, 0, sizeof(server_address));
 server_address.sin_family = 2;
 server_address.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 server_address.sin_port = htons(8000);
 int server_socket = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if(bind(server_socket, (const struct sockaddr *) &server_address,
      sizeof(server_address))<0)
 {
  printf("Failed to bind server.\n");
  return -1;
 }
 if(listen(server_socket, max_connections)<0)
 {
  printf("Failed to set server socket to listen\n");
  return -1;
 }
 int client_sockets[max_connections];
 struct sockaddr_in client_address;
 socklen_t sizeof_client_address = sizeof(client_address);
 int num_connected = 0;
 in_addr_t client_IPs[max_connections];
 printf("Waiting on %i clients to connect\n", max_connections);
 while (num_connected < max_connections)
 {
  if ((client_sockets[num_connected] = accept(server_socket,
     (struct sockaddr *) &client_address,
     &sizeof_client_address))<0)
  {
   printf("Server failed to accept client");
   return -1;
  }
  client_IPs[num_connected] = client_address.sin_addr.s_addr;
  printf("Client %i has reported in\n", num_connected);
  num_connected++;
 }
        struct timeval tv;
        long int timesec1 = time(((void *)0));
        gettimeofday(&tv, ((void *)0));
        float timems1 = tv.tv_usec*0.001;
 int i, j;
 int buffer_size = 30;
 char buffer[buffer_size];
 in_addr_t next_IP;
 for(i=0; i<num_connected; i++)
 {
  if(i<num_connected-1)
   next_IP = client_IPs[i+1];
  else
   next_IP = 0;
  for(j=0; j<buffer_size;j++)
   buffer[j] = '\0';
  sprintf(buffer, "%i+%i+%i", i, num_connected, next_IP);
  if (send(client_sockets[i], buffer, buffer_size, 0) != buffer_size)
  {
   printf("Sending info to Client %i failed.\n", i);
   return -1;
  }
 }
 int recieve_size;
 for(j=0; j<buffer_size;j++)
  buffer[j] = '\0';
 if((recieve_size = recv(client_sockets[num_connected-1], buffer, buffer_size, 0)) <0)
 {
  printf("Recieve from Client %i failed.\n", num_connected-1);
  return -1;
 }
 printf("\nRecieved result from Client %i:\n --- Size of LCS = %s\n", num_connected-1, buffer);
        long int timesec2 = time(((void *)0));
        gettimeofday(&tv, ((void *)0));
        float timems2 = tv.tv_usec*0.001;
        float runtime = (timesec2-timesec1)*1000 + (timems2-timems1);
        printf("\nRuntime: %f ms\n\n", runtime);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int max_connections = 2;
 if(argc>1)
 {
  max_connections = atoi(argv[1]);
 }
 struct sockaddr_in server_address;
 memset(&server_address, 0, sizeof(server_address));
 server_address.sin_family = 2;
 server_address.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 server_address.sin_port = htons(8000);
 int server_socket = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if(bind(server_socket, (struct sockaddr *) &server_address,
      sizeof(server_address))<0)
 {
  printf("Failed to bind server.\n");
  return -1;
 }
 if(listen(server_socket, max_connections)<0)
 {
  printf("Failed to set server socket to listen\n");
  return -1;
 }
 int client_sockets[-1];
 struct sockaddr_in client_address;
 unsigned int sizeof_client_address = sizeof(client_address);
 int num_connected = 0;
 unsigned int client_IPs[-1];
 printf("Waiting on %i clients to connect\n", max_connections);
 while (num_connected < max_connections)
 {
  if ((client_sockets[num_connected] = accept(server_socket,
     (struct sockaddr *) &client_address,
     &sizeof_client_address))<0)
  {
   printf("Server failed to accept client");
   return -1;
  }
  client_IPs[num_connected] = client_address.sin_addr.s_addr;
  printf("Client %i has reported in\n", num_connected);
  num_connected++;
 }
        struct timeval tv;
        long timesec1 = time(((void *)0));
        gettimeofday(&tv, ((void *)0));
        float timems1 = tv.tv_usec*0.001;
 int i; int j;
 int buffer_size = 30;
 char buffer[-1];
 unsigned int next_IP;
 for(i=0; i<num_connected; i++)
 {
  if(i<num_connected-1)
   next_IP = client_IPs[i+1];
  else
   next_IP = 0;
  for(j=0; j<buffer_size;j++)
   buffer[j] = '\0';
  sprintf(buffer, "%i+%i+%i", i, num_connected, next_IP);
  if (send(client_sockets[i], buffer, buffer_size, 0) != buffer_size)
  {
   printf("Sending info to Client %i failed.\n", i);
   return -1;
  }
 }
 int recieve_size;
 for(j=0; j<buffer_size;j++)
  buffer[j] = '\0';
 if((recieve_size = recv(client_sockets[num_connected-1], buffer, buffer_size, 0)) <0)
 {
  printf("Recieve from Client %i failed.\n", num_connected-1);
  return -1;
 }
 printf("\nRecieved result from Client %i:\n --- Size of LCS = %s\n", num_connected-1, buffer);
        long timesec2 = time(((void *)0));
        gettimeofday(&tv, ((void *)0));
        float timems2 = tv.tv_usec*0.001;
        float runtime = (timesec2-timesec1)*1000 + (timems2-timems1);
        printf("\nRuntime: %f ms\n\n", runtime);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: j int

variable_types:
buffer
char [-1]

variable_types: runtime float


readme

repo: cppkhartna/Khash

variable_types: struct TMemory { char *beg; char *end; } *

variable_types: c int

variable_types: prev int

variable_types: k int

variable_types:
s
char [100]

variable_types: quotes int

variable_types: spaces int


repo: cpsource/dibit

variable_types:
ctx
unsigned char (*)[36]

variable_types:
z
unsigned char

variable_types:
i
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall trivium_getbyte(unsigned __int8 *a1)
{
char v1; // bp
unsigned int v2; // ebx

v1 = 8;
v2 = 0;
do
{
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
v2 |= trivium_enc(a1);
--v1;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1)
{
char v1; // bp
unsigned int v2; // ebx

v1 = 8;
v2 = 0;
do
{
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
v2 |= func0(a1);
--v1;
}
while ( v1 );
return v2;
}

original_code:
uint8_t trivium_getbyte(trivium_ctx_t *ctx)
{
  uint8_t r=0, i=0;
  do{
    r>>=1;
    r |= trivium_enc(ctx);
  }while(++i<8);
  return r;
}

canonical_original_code:
unsigned char trivium_getbyte(unsigned char (*ctx)[36])
{
  unsigned char r = 0; unsigned char i = 0;
  do{
    r>>=1;
    r |= trivium_enc(ctx);
  }while(++i<8);
  return r;
}

variable_types:
r
unsigned char


original_code:
void trivium_init(const void* key, uint16_t keysize_b,
                  const void* iv, uint16_t ivsize_b,
                  trivium_ctx_t* ctx)
{
  uint16_t i;
  uint8_t c1,c2;
  uint8_t t1;
  memset((*ctx)+((keysize_b+7)/8), 0, 35-((keysize_b+7)/8));
  c2=0;
  c1=((keysize_b+7)/8);
  do{
    t1 = ((uint8_t*)key)[--c1];
    (*ctx)[c2++] = t1;
  }while(c1!=0);
  c2=12;
  c1=((ivsize_b +7)/8);
  do{
    t1 = ((uint8_t*)iv)[--c1];
    (*ctx)[c2++] = t1;
  }while(c1!=0);
  (*ctx)[35] = 0xE0;
  for(i=0; i<4*288; ++i){
    trivium_enc(ctx);
  }
}

canonical_original_code:
void trivium_init(void *key, unsigned short keysize_b, void *iv, unsigned short ivsize_b, unsigned char (*ctx)[36])
{
  unsigned short i;
  unsigned char c1; unsigned char c2;
  unsigned char t1;
  memset((*ctx)+((keysize_b+7)/8), 0, 35-((keysize_b+7)/8));
  c2=0;
  c1=((keysize_b+7)/8);
  do{
    t1 = ((unsigned char *)key)[--c1];
    (*ctx)[c2++] = t1;
  }while(c1!=0);
  c2=12;
  c1=((ivsize_b +7)/8);
  do{
    t1 = ((unsigned char *)iv)[--c1];
    (*ctx)[c2++] = t1;
  }while(c1!=0);
  (*ctx)[35] = 0xE0;
  for(i=0; i<4*288; ++i){
    trivium_enc(ctx);
  }
}

variable_types:
key
void *

variable_types:
iv
void *

variable_types:
i
unsigned short


decompiled_code:
__int64 rat_driver_init()
{
return libusb_init(&ctx);
}

canonical_decompiled_code:
__int64 func4()
{
return libusb_init(&ctx);
}

original_code:
int
rat_driver_init(void)
{
 int ret;
 ret = libusb_init(&ctx);
 if (ret < 0) {
  do{}while(0);
 }
 return ret;
}

canonical_original_code:
int rat_driver_init()
{
 int ret;
 ret = libusb_init(&ctx);
 if (ret < 0) {
  do{}while(0);
 }
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 rat_driver_fini()
{
return libusb_exit(ctx);
}

canonical_decompiled_code:
__int64 func5()
{
return libusb_exit(ctx);
}

original_code:
void
rat_driver_fini(void)
{
 libusb_exit(ctx);
}

canonical_original_code:
void rat_driver_fini()
{
 libusb_exit(ctx);
}


daemonize

decompiled_code:
FILE *daemonize()
{
__pid_t v0; // eax
__int64 v2; // [rsp+0h] [rbp-8h]

if ( getppid() == 1 )
return (FILE *)v2;
v0 = fork();
if ( v0 < 0 )
goto LABEL_8;
if ( v0 )
exit(0);
umask(0);
if ( setsid() < 0 )
LABEL_8:
exit(1);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
return freopen("/dev/null", "w", stderr);
}

canonical_decompiled_code:
FILE *func3()
{
__pid_t v0; // eax
__int64 v2; // [rsp+0h] [rbp-8h]

if ( getppid() == 1 )
return (FILE *)v2;
v0 = fork();
if ( v0 < 0 )
goto LABEL_8;
if ( v0 )
exit(0);
umask(0);
if ( setsid() < 0 )
LABEL_8:
exit(1);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
return freopen("/dev/null", "w", stderr);
}

original_code:
static void
daemonize(void)
{
 pid_t pid;
 pid_t sid;
 if (getppid() == 1)
  return;
 pid = fork();
 if (pid < 0)
  exit(1);
 if (pid > 0)
  exit(0);
 umask(0);
 sid = setsid();
 if (sid < 0)
  exit(1);
 freopen("/dev/null", "r", stdin);
 freopen("/dev/null", "w", stdout);
 freopen("/dev/null", "w", stderr);
}

canonical_original_code:
static void daemonize()
{
 int pid;
 int sid;
 if (getppid() == 1)
  return;
 pid = fork();
 if (pid < 0)
  exit(1);
 if (pid > 0)
  exit(0);
 umask(0);
 sid = setsid();
 if (sid < 0)
  exit(1);
 freopen("/dev/null", "r", stdin);
 freopen("/dev/null", "w", stdout);
 freopen("/dev/null", "w", stderr);
}

variable_types: pid int

variable_types: sid int


decompiled_code:
void *ll_new_list()
{
return calloc(0x20uLL, 1uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(0x20uLL, 1uLL);
}

original_code:
List*
ll_new_list(void)
{
 List *ret = (List*)malloc(sizeof(List));
 if (ret == ((void *)0))
  return ((void *)0);
 memset(ret, 0, sizeof(List));
 return ret;
}

canonical_original_code:
struct _llist *ll_new_list()
{
 struct _llist *ret = (List*)malloc(sizeof(List));
 if (ret == ((void *)0))
  return ((void *)0);
 memset(ret, 0, sizeof(List));
 return ret;
}

variable_types: struct _llist { struct _llist_node { void *data; struct _llist_node *next; } *head; struct _llist_node *tail; struct _llist_node *current; unsigned long size; } *

user_defined_types: struct _llist { struct _llist_node *head; struct _llist_node *tail; struct _llist_node *current; unsigned long size; }


original_code:
void
ll_push_node(List *ll, ListNode *n)
{
 if (ll == ((void *)0) || n == ((void *)0))
  return;
 if (ll->size == 0) {
  ll->head = n;
  ll->tail = n;
  goto walk;
 }
 ll->tail->next = n;
 ll->tail = ll->tail->next;
walk:
 ll->size++;
 while (ll->tail->next != ((void *)0)) {
  ll->tail = ll->tail->next;
  ll->size++;
 }
}

canonical_original_code:
void ll_push_node(struct _llist *ll, struct _llist_node *n)
{
 if (ll == ((void *)0) || n == ((void *)0))
  return;
 if (ll->size == 0) {
  ll->head = n;
  ll->tail = n;
  goto walk;
 }
 ll->tail->next = n;
 ll->tail = ll->tail->next;
walk:
 ll->size++;
 while (ll->tail->next != ((void *)0)) {
  ll->tail = ll->tail->next;
  ll->size++;
 }
}

variable_types:
n
struct _llist_node *

user_defined_types: struct _llist_node { void *data; struct _llist_node *next; }


original_code:
ListNode*
ll_pop_node(List *ll)
{
 ListNode *tmp;
 ListNode *ret;
 if (ll == ((void *)0))
  return ((void *)0);
 if (ll->size == 0)
  return ((void *)0);
 ret = ll->tail;
 if (ret == ll->head) {
  ll->tail = ((void *)0);
  ll->head = ((void *)0);
  ll->size = 0;
  return ret;
 }
 tmp = ll->head;
 while (tmp->next != ret)
  tmp = tmp->next;
 tmp->next = ((void *)0);
 ll->tail = tmp;
 ll->size--;
 return ret;
}

canonical_original_code:
struct _llist_node *ll_pop_node(struct _llist *ll)
{
 struct _llist_node *tmp;
 struct _llist_node *ret;
 if (ll == ((void *)0))
  return ((void *)0);
 if (ll->size == 0)
  return ((void *)0);
 ret = ll->tail;
 if (ret == ll->head) {
  ll->tail = ((void *)0);
  ll->head = ((void *)0);
  ll->size = 0;
  return ret;
 }
 tmp = ll->head;
 while (tmp->next != ret)
  tmp = tmp->next;
 tmp->next = ((void *)0);
 ll->tail = tmp;
 ll->size--;
 return ret;
}

variable_types: struct _llist { struct _llist_node *head; struct _llist_node *tail; struct _llist_node *current; unsigned long size; } *

variable_types: struct _llist_node { void *data; struct _llist_node *next; } *


decompiled_code:
void __fastcall ll_delete_node(void *ptr, void (*a2)(void))
{
void *v3; // rdi

if ( ptr )
{
v3 = *(void **)ptr;
if ( v3 )
{
if ( a2 )
a2();
else
free(v3);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr, void (*a2)(void))
{
void *v3; // rdi

if ( ptr )
{
v3 = *(void **)ptr;
if ( v3 )
{
if ( a2 )
a2();
else
free(v3);
}
free(ptr);
}
}

original_code:
void
ll_delete_node(ListNode *n, ll_free nfree)
{
 if (n == ((void *)0))
  return;
 if (n->data) {
  if (nfree)
   nfree(n->data);
  else
   free(n->data);
 }
 free(n);
}

canonical_original_code:
void ll_delete_node(struct _llist_node *n, void (*nfree)(void *))
{
 if (n == ((void *)0))
  return;
 if (n->data) {
  if (nfree)
   nfree(n->data);
  else
   free(n->data);
 }
 free(n);
}

variable_types:
nfree
void (*)(void *)


decompiled_code:
void __fastcall ll_delete_node_chain(void *ptr, void (*a2)(void))
{
void *v2; // rbx
void *v3; // rdi

if ( ptr )
{
v2 = ptr;
do
{
v3 = v2;
v2 = (void *)*((_QWORD *)v2 + 1);
ll_delete_node(v3, a2);
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr, void (*a2)(void))
{
void *v2; // rbx
void *v3; // rdi

if ( ptr )
{
v2 = ptr;
do
{
v3 = v2;
v2 = (void *)*((_QWORD *)v2 + 1);
func3(v3, a2);
}
while ( v2 );
}
}

original_code:
void
ll_delete_node_chain(ListNode *root, ll_free nfree)
{
 ListNode *cur;
 ListNode *nxt;
 if (root == ((void *)0))
  return;
 cur = root;
 while (cur) {
  nxt = cur->next;
  ll_delete_node(cur, nfree);
  cur = nxt;
 }
}

canonical_original_code:
void ll_delete_node_chain(struct _llist_node *root, void (*nfree)(void *))
{
 struct _llist_node *cur;
 struct _llist_node *nxt;
 if (root == ((void *)0))
  return;
 cur = root;
 while (cur) {
  nxt = cur->next;
  ll_delete_node(cur, nfree);
  cur = nxt;
 }
}


decompiled_code:
void __fastcall ll_delete_list(void *ptr, void (*a2)(void))
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 3) )
ll_delete_node_chain(*(void **)ptr, a2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr, void (*a2)(void))
{
if ( ptr )
{
if ( *((_QWORD *)ptr + 3) )
func4(*(void **)ptr, a2);
free(ptr);
}
}

original_code:
void
ll_delete_list(List *ll, ll_free nfree)
{
 if (ll == ((void *)0))
  return;
 if (ll->size == 0) {
  free(ll);
  return;
 }
 ll_delete_node_chain(ll->head, nfree);
 free(ll);
}

canonical_original_code:
void ll_delete_list(struct _llist *ll, void (*nfree)(void *))
{
 if (ll == ((void *)0))
  return;
 if (ll->size == 0) {
  free(ll);
  return;
 }
 ll_delete_node_chain(ll->head, nfree);
 free(ll);
}


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

if ( !a1 )
return 0LL;
result = a1[2];
if ( result == a1[1] )
return 0LL;
if ( result )
{
a1[2] = *(_QWORD *)(result + 8);
}
else
{
result = *a1;
a1[2] = *a1;
}
return result;
}

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

if ( !a1 )
return 0LL;
result = a1[2];
if ( result == a1[1] )
return 0LL;
if ( result )
{
a1[2] = *(_QWORD *)(result + 8);
}
else
{
result = *a1;
a1[2] = *a1;
}
return result;
}

original_code:
ListNode*
ll_get_next(List *ll)
{
 ListNode *ret;
 if (ll == ((void *)0))
  return ((void *)0);
 if (ll->current == ll->tail)
  return ((void *)0);
 if (ll->current == ((void *)0)) {
  ll->current = ll->head;
  return ll->current;
 }
 ret = ll->current;
 ll->current = ll->current->next;
 return ret;
}

canonical_original_code:
struct _llist_node *ll_get_next(struct _llist *ll)
{
 struct _llist_node *ret;
 if (ll == ((void *)0))
  return ((void *)0);
 if (ll->current == ll->tail)
  return ((void *)0);
 if (ll->current == ((void *)0)) {
  ll->current = ll->head;
  return ll->current;
 }
 ret = ll->current;
 ll->current = ll->current->next;
 return ret;
}

return_type: struct _llist_node { void *data; struct _llist_node *next; } *


decompiled_code:
void free_object_list()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: static void free_object_list(void *data){}

variable_types:
data
void *


decompiled_code:
void __fastcall add_fixup_anchor(const __m128i *a1)
{
__m128i *v1; // rax
__int64 v2; // rsi

if ( a1 )
{
if ( fixup_tree )
{
v1 = (__m128i *)bintree_search(fixup_tree, a1->m128i_i64[0]);
if ( v1 )
{
*v1 = _mm_loadu_si128(a1);
}
else
{
v2 = bintree_new_node(a1);
if ( v2 )
bintree_add_node(fixup_tree, v2);
}
}
else
{
fixup_tree = bintree_new_node(a1);
}
}
}

canonical_decompiled_code:
void __fastcall func1(const __m128i *a1)
{
__m128i *v1; // rax
__int64 v2; // rsi

if ( a1 )
{
if ( fixup_tree )
{
v1 = (__m128i *)bintree_search(fixup_tree, a1->m128i_i64[0]);
if ( v1 )
{
*v1 = _mm_loadu_si128(a1);
}
else
{
v2 = bintree_new_node(a1);
if ( v2 )
bintree_add_node(fixup_tree, v2);
}
}
else
{
fixup_tree = bintree_new_node(a1);
}
}
}

original_code:
void
add_fixup_anchor(Anchor *anchor)
{
 BinTree *tmp;
 if (anchor == ((void *)0))
  return;
 if (fixup_tree == ((void *)0)) {
  fixup_tree = bintree_new_node(anchor);
  if (fixup_tree == ((void *)0)) {
   do{}while(0);
   return;
  }
  return;
 }
 tmp = bintree_search(fixup_tree, anchor->name);
 if (tmp != ((void *)0)) {
  do{}while(0);
  memcpy(&tmp->anchor, anchor, sizeof(Anchor));
  return;
 }
 tmp = bintree_new_node(anchor);
 if (tmp == ((void *)0)) {
  do{}while(0);
  return;
 }
 (void)bintree_add_node(fixup_tree, tmp);
}

canonical_original_code:
void add_fixup_anchor(struct _anchor *anchor)
{
 struct _bintree *tmp;
 if (anchor == ((void *)0))
  return;
 if (fixup_tree == ((void *)0)) {
  fixup_tree = bintree_new_node(anchor);
  if (fixup_tree == ((void *)0)) {
   do{}while(0);
   return;
  }
  return;
 }
 tmp = bintree_search(fixup_tree, anchor->name);
 if (tmp != ((void *)0)) {
  do{}while(0);
  memcpy(&tmp->anchor, anchor, sizeof(Anchor));
  return;
 }
 tmp = bintree_new_node(anchor);
 if (tmp == ((void *)0)) {
  do{}while(0);
  return;
 }
 (void)bintree_add_node(fixup_tree, tmp);
}

variable_types: struct _anchor { char *name; void *symbol; } *

variable_types: struct _bintree { struct _anchor { char *name; void *symbol; } anchor; struct _bintree *left; struct _bintree *right; } *

user_defined_types: struct _bintree { struct _anchor anchor; struct _bintree *left; struct _bintree *right; }


original_code:
void
add_fixup_anchor_list(Anchor *anchor_list)
{
 Anchor *a;
 if (anchor_list == ((void *)0))
  return;
 a = anchor_list;
 while (a->symbol != ((void *)0) && a->name != ((void *)0))
  add_fixup_anchor(a++);
}

canonical_original_code:
void add_fixup_anchor_list(struct _anchor *anchor_list)
{
 struct _anchor *a;
 if (anchor_list == ((void *)0))
  return;
 a = anchor_list;
 while (a->symbol != ((void *)0) && a->name != ((void *)0))
  add_fixup_anchor(a++);
}

user_defined_types: struct _anchor { char *name; void *symbol; }