decompiled_code:
char *__fastcall cns_str_ereplace(char *string, char *s1, char *src)
{
char *v4; // r12
char *i; // rbx
__int64 v6; // rax
int v7; // edx
size_t v9; // r14
char *v10; // r14
size_t v11; // rax
char *v12; // rax
int v13; // [rsp+8h] [rbp-60h]
int v14; // [rsp+14h] [rbp-54h]
int v15; // [rsp+14h] [rbp-54h]
size_t v16; // [rsp+18h] [rbp-50h]
int v17; // [rsp+28h] [rbp-40h]

v4 = string;
if ( strcmp(s1, src) )
{
v14 = 0;
for ( i = string; ; i = &v4[v14] )
{
v6 = cns_reg(i, s1);
v13 = v7;
v17 = HIDWORD(v6);
if ( (_DWORD)v6 )
break;
v9 = strlen(v4);
v16 = strlen(src);
v10 = (char *)calloc(1uLL, v16 + v9 + 1LL - (v13 - v17));
v15 = v17 + v14;
strncpy(v10, v4, v15);
v10[v15] = 0;
v11 = strlen(v10);
v12 = stpcpy(&v10[v11], src);
strcpy(v12, &i[v13]);
v4 = strdup(v10);
free(v10);
v14 = v15 + v16;
}
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func8(char *string, char *s1, char *src)
{
char *v4; // r12
char *i; // rbx
__int64 v6; // rax
int v7; // edx
size_t v9; // r14
char *v10; // r14
size_t v11; // rax
char *v12; // rax
int v13; // [rsp+8h] [rbp-60h]
int v14; // [rsp+14h] [rbp-54h]
int v15; // [rsp+14h] [rbp-54h]
size_t v16; // [rsp+18h] [rbp-50h]
int v17; // [rsp+28h] [rbp-40h]

v4 = string;
if ( strcmp(s1, src) )
{
v14 = 0;
for ( i = string; ; i = &v4[v14] )
{
v6 = func7(i, s1);
v13 = v7;
v17 = HIDWORD(v6);
if ( (_DWORD)v6 )
break;
v9 = strlen(v4);
v16 = strlen(src);
v10 = (char *)calloc(1uLL, v16 + v9 + 1LL - (v13 - v17));
v15 = v17 + v14;
strncpy(v10, v4, v15);
v10[v15] = 0;
v11 = strlen(v10);
v12 = stpcpy(&v10[v11], src);
strcpy(v12, &i[v13]);
v4 = strdup(v10);
free(v10);
v14 = v15 + v16;
}
}
return v4;
}

original_code:
char *cns_str_ereplace(char *src, const char *pattern, const char *newsubstr)
{
    if(!strcmp(pattern, newsubstr))
       return src;
    reg_rtn_struct reg_rtn_struct_var;
    int rtn = 0;
    int pstart = 0;
    int pend = 0;
    char *dest=src;
    char *pstr=src;
    char *tmp;
    char *new_tmp_str=dest;
    int new_tmp_str_len=0;
    while(!rtn)
    {
        reg_rtn_struct_var=cns_reg(new_tmp_str, pattern);
        rtn = reg_rtn_struct_var.rtn;
        pstart = reg_rtn_struct_var.pstart;
        pend = reg_rtn_struct_var.pend;
        if(!rtn)
        {
            tmp=(char*)calloc(sizeof(char), strlen(dest)+strlen(newsubstr)-(pend-pstart)+1 );
            strncpy(tmp, dest, new_tmp_str_len+pstart);
            tmp[new_tmp_str_len+pstart]='\0';
            strcat(tmp, newsubstr);
            strcat(tmp, new_tmp_str+pend);
            dest = strdup(tmp);
            free(tmp);
            new_tmp_str_len = new_tmp_str_len + pstart + strlen(newsubstr);
            new_tmp_str=dest+new_tmp_str_len;
        }
    }
    return dest;
}

canonical_original_code:
char *cns_str_ereplace(char *src, char *pattern, char *newsubstr)
{
    if(!strcmp(pattern, newsubstr))
       return src;
    struct _reg_rtn_struct reg_rtn_struct_var;
    int rtn = 0;
    int pstart = 0;
    int pend = 0;
    char *dest = src;
    char *pstr = src;
    char *tmp;
    char *new_tmp_str = dest;
    int new_tmp_str_len = 0;
    while(!rtn)
    {
        reg_rtn_struct_var=cns_reg(new_tmp_str, pattern);
        rtn = reg_rtn_struct_var.rtn;
        pstart = reg_rtn_struct_var.pstart;
        pend = reg_rtn_struct_var.pend;
        if(!rtn)
        {
            tmp=(char *)calloc(sizeof(char), strlen(dest)+strlen(newsubstr)-(pend-pstart)+1 );
            strncpy(tmp, dest, new_tmp_str_len+pstart);
            tmp[new_tmp_str_len+pstart]='\0';
            strcat(tmp, newsubstr);
            strcat(tmp, new_tmp_str+pend);
            dest = strdup(tmp);
            free(tmp);
            new_tmp_str_len = new_tmp_str_len + pstart + strlen(newsubstr);
            new_tmp_str=dest+new_tmp_str_len;
        }
    }
    return dest;
}

variable_types:
src
char *

variable_types:
pattern
char *

variable_types:
newsubstr
char *

variable_types: rtn int

variable_types: pstart int

variable_types: pend int

variable_types:
dest
char *

variable_types:
pstr
char *

variable_types:
tmp
char *

user_defined_types: struct _reg_rtn_struct { int rtn; int pstart; int pend; }


decompiled_code:
__int64 __fastcall string_comp(char *a1, char *a2)
{
char v2; // dl
char v3; // al

while ( 1 )
{
v3 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
v2 = *a2;
if ( !*a2 || v2 < v3 )
return 1LL;
if ( v2 > v3 )
break;
++a1;
++a2;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2)
{
char v2; // dl
char v3; // al

while ( 1 )
{
v3 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
v2 = *a2;
if ( !*a2 || v2 < v3 )
return 1LL;
if ( v2 > v3 )
break;
++a1;
++a2;
}
return 0xFFFFFFFFLL;
}

return_type: int


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

for ( result = 0LL; *a1; result = (unsigned int)(result + 1) )
++a1;
return result;
}

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

for ( result = 0LL; *a1; result = (unsigned int)(result + 1) )
++a1;
return result;
}

original_code:
int string_length(char* s)
{
    int len = 0;
    while(*s!='\0')
    {
        s++;
        len++;
    }
    return len;
}

canonical_original_code:
int string_length(char *s)
{
    int len = 0;
    while(*s!='\0')
    {
        s++;
        len++;
    }
    return len;
}

variable_types:
s
char *

variable_types: len int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
char v6[1032]; // [rsp+0h] [rbp-408h] BYREF

v3 = string_comp("Liheyuanxx", "liheyuan", envp);
printf("string_comp:%d\n", v3);
string_copy("Liheyuanxx", v6);
printf("copy result:%s\n", v6);
string_concat(v6, "liheyuan");
printf("concat result:%s\n", v6);
v4 = string_length(v6);
printf("length:%d\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
char v6[1032]; // [rsp+0h] [rbp-408h] BYREF

v3 = func7("Liheyuanxx", "liheyuan", envp);
printf("string_comp:%d\n", v3);
func8("Liheyuanxx", v6);
printf("copy result:%s\n", v6);
func9(v6, "liheyuan");
printf("concat result:%s\n", v6);
v4 = func10(v6);
printf("length:%d\n", v4);
return 0;
}

original_code:
int main()
{
    char* s1 = "Liheyuanxx";
    char* s2 = "liheyuan";
    char buf[1024];
    printf("string_comp:%d\n", string_comp(s1, s2));
    string_copy(s1, buf);
    printf("copy result:%s\n", buf);
    string_concat(buf, s2);
    printf("concat result:%s\n", buf);
    printf("length:%d\n", string_length(buf));
    return 0;
}

canonical_original_code:
int main()
{
    char *s1 = "Liheyuanxx";
    char *s2 = "liheyuan";
    char buf[1024];
    printf("string_comp:%d\n", string_comp(s1, s2));
    string_copy(s1, buf);
    printf("copy result:%s\n", buf);
    string_concat(buf, s2);
    printf("concat result:%s\n", buf);
    printf("length:%d\n", string_length(buf));
    return 0;
}

variable_types:
buf
char [1024]


decompiled_code:
__int64 __fastcall semaphore_p(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = -65536;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = -65536;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

original_code:
static int semaphore_p(int sem_id)
{
 struct sembuf sem_b;
 sem_b.sem_num = 0;
 sem_b.sem_op = -1;
 sem_b.sem_flg = 0x1000;
 if (semop(sem_id, &sem_b, 1) == -1)
  return -1;
 return 0;
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
__int64 __fastcall semaphore_v(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = 0x10000;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = 0x10000;
sops.sem_flg = 4096;
return (unsigned int)-(semop(a1, &sops, 1uLL) == -1);
}

original_code:
static int semaphore_v(int sem_id)
{
 struct sembuf sem_b;
 sem_b.sem_num = 0;
 sem_b.sem_op = +1;
 sem_b.sem_flg = 0x1000;
 if (semop(sem_id, &sem_b, 1) == -1)
  return -1;
 return 0;
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


ProcessUpdate

decompiled_code:
void __fastcall ProcessUpdate(__int64 a1)
{
unsigned int v1; // er12
__suseconds_t v2; // r13
struct timezone tz; // [rsp+8h] [rbp-150h] BYREF
struct timeval tv; // [rsp+10h] [rbp-148h] BYREF
struct timeval v5; // [rsp+20h] [rbp-138h] BYREF
char s[296]; // [rsp+30h] [rbp-128h] BYREF

if ( (*(_BYTE *)a1 & 0xC) == 0 )
{
gettimeofday(&tv, &tz);
v1 = UpdateDomainName(a1 + 5, *(unsigned int *)(a1 + 1), *(_BYTE *)a1 & 3);
gettimeofday(&v5, &tz);
v2 = v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec;
if ( v1 )
{
SaveToFile(a1 + 5, *(unsigned int *)(a1 + 1));
if ( (*(_BYTE *)a1 & 3) == 1 )
{
gettimeofday(&tv, &tz);
AddListToBTree();
gettimeofday(&v5, &tz);
memset(s, 0, 0x100uLL);
snprintf(
s,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2 + v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
else
{
memset(s, 0, 0x100uLL);
snprintf(
s,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: NORMAL\n \t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2);
}
}
else
{
snprintf(
s,
0x100uLL,
"Type: DOMAIN. <<FAILED>> Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec,
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
}
Logging("/home/shaw/Data/Logs/UpdateLog.txt", s);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
unsigned int v1; // er12
__suseconds_t v2; // r13
struct timezone tz; // [rsp+8h] [rbp-150h] BYREF
struct timeval tv; // [rsp+10h] [rbp-148h] BYREF
struct timeval v5; // [rsp+20h] [rbp-138h] BYREF
char s[296]; // [rsp+30h] [rbp-128h] BYREF

if ( (*(_BYTE *)a1 & 0xC) == 0 )
{
gettimeofday(&tv, &tz);
v1 = UpdateDomainName(a1 + 5, *(unsigned int *)(a1 + 1), *(_BYTE *)a1 & 3);
gettimeofday(&v5, &tz);
v2 = v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec;
if ( v1 )
{
SaveToFile(a1 + 5, *(unsigned int *)(a1 + 1));
if ( (*(_BYTE *)a1 & 3) == 1 )
{
gettimeofday(&tv, &tz);
AddListToBTree();
gettimeofday(&v5, &tz);
memset(s, 0, 0x100uLL);
snprintf(
s,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2 + v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
else
{
memset(s, 0, 0x100uLL);
snprintf(
s,
0x100uLL,
"Type: DOMAIN. Counts: %u. Update-Type: NORMAL\n \t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v1,
v2,
v2);
}
}
else
{
snprintf(
s,
0x100uLL,
"Type: DOMAIN. <<FAILED>> Update-Type: QUICK\n\t\t\t Time-Valid: %lu us Time-Total: %lu us\n",
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec,
v5.tv_usec + 1000000 * (v5.tv_sec - tv.tv_sec) - tv.tv_usec);
}
}
func2("/home/shaw/Data/Logs/UpdateLog.txt", s);
}

original_code:
static void ProcessUpdate(void *buffer)
{
 struct record_set_hdr *recdhdr;
 int sum=0;
        struct timeval t1,t2;
        struct timezone tz;
 unsigned long update_t, flush_t;
 char logString[256];
        recdhdr=(struct record_set_hdr *)buffer;
        if(recdhdr->data_type==0)
 {
  gettimeofday (&t1,&tz);
  sum=UpdateDomainName(buffer+sizeof(*recdhdr), recdhdr->recd_size,recdhdr->update_type);
  gettimeofday(&t2,&tz);
  update_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
  if(sum == 0)
  {
   snprintf(logString,256,"Type: DOMAIN.   <<FAILED>>   Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", update_t, update_t);
   goto out;
  }
         SaveToFile(buffer+sizeof(*recdhdr),recdhdr->recd_size);
  if(recdhdr->update_type==1)
  {
                 gettimeofday (&t1,&tz);
   AddListToBTree();
   gettimeofday (&t2,&tz);
   flush_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t+flush_t);
   goto out;
  }else{
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: NORMAL\n 			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t);
   goto out;
  }
 }
out:
 Logging("/home/shaw/Data/Logs/UpdateLog.txt", logString);
}

canonical_original_code:
static void ProcessUpdate(void *buffer)
{
 struct record_set_hdr *recdhdr;
 int sum = 0;
        struct timeval t1; struct timeval t2;
        struct timezone tz;
 unsigned long update_t; unsigned long flush_t;
 char logString[256];
        recdhdr=(struct record_set_hdr *)buffer;
        if(recdhdr->data_type==0)
 {
  gettimeofday (&t1,&tz);
  sum=UpdateDomainName(buffer+sizeof(*recdhdr), recdhdr->recd_size,recdhdr->update_type);
  gettimeofday(&t2,&tz);
  update_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
  if(sum == 0)
  {
   snprintf(logString,256,"Type: DOMAIN.   <<FAILED>>   Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", update_t, update_t);
   goto out;
  }
         SaveToFile(buffer+sizeof(*recdhdr),recdhdr->recd_size);
  if(recdhdr->update_type==1)
  {
                 gettimeofday (&t1,&tz);
   AddListToBTree();
   gettimeofday (&t2,&tz);
   flush_t = (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: QUICK\n			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t+flush_t);
   goto out;
  }else{
   memset(logString, 0, 256);
   snprintf(logString,256,"Type: DOMAIN.  Counts: %u.  Update-Type: NORMAL\n 			    Time-Valid:  %lu us   Time-Total:  %lu us\n", sum, update_t, update_t);
   goto out;
  }
 }
out:
 Logging("/home/shaw/Data/Logs/UpdateLog.txt", logString);
}

variable_types:
buffer
void *

variable_types: struct record_set_hdr { unsigned char update_type; unsigned int recd_size; } *

variable_types: sum int

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }

variable_types:
logString
char [256]

return_type: void


InitSem

decompiled_code:
__int64 __fastcall InitSem()
{
__int64 v0; // rbx
key_t v1; // er12
key_t v2; // eax
key_t v3; // ebp
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
char v13[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = ftok("/home/shaw/Data/", 11);
v2 = ftok("/home/shaw/Data/", 12);
if ( v1 == -1 || (v3 = v2, v2 == -1) )
{
memset(v13, 0, 0x100uLL);
v11 = _errno_location();
v12 = strerror(*v11);
snprintf(v13, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", v12);
goto LABEL_13;
}
sem_send = semget(v1, 1, 1968);
if ( sem_send == -1 )
{
sem_send = semget(v1, 1, 0);
if ( sem_send == -1 )
{
memset(v13, 0, 0x100uLL);
v5 = _errno_location();
v6 = strerror(*v5);
snprintf(v13, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semget --- %s", v6);
goto LABEL_13;
}
}
else
{
v0 = 1LL;
if ( semctl(sem_send, 0, 16, 1LL) == -1 )
{
LABEL_12:
memset(v13, 0, 0x100uLL);
v9 = _errno_location();
v10 = strerror(*v9);
snprintf(v13, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", v10);
goto LABEL_13;
}
}
sem_recv = semget(v3, 1, 1968);
if ( sem_recv != -1 )
{
if ( semctl(sem_recv, 0, 16, v0 & 0xFFFFFFFF00000000LL) != -1 )
return 0LL;
goto LABEL_12;
}
sem_recv = semget(v3, 1, 0);
if ( sem_send != -1 )
return 0LL;
memset(v13, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v13, 0x100uLL, "[ERROR] shareMem.c @ InitSem @ semget --- %s", v8);
LABEL_13:
Logging("/home/shaw/Data/Logs/ErrorLog.txt", v13);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4()
{
__int64 v0; // rbx
key_t v1; // er12
key_t v2; // eax
key_t v3; // ebp
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
char v13[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = ftok("/home/shaw/Data/", 11);
v2 = ftok("/home/shaw/Data/", 12);
if ( v1 == -1 || (v3 = v2, v2 == -1) )
{
memset(v13, 0, 0x100uLL);
v11 = _errno_location();
v12 = strerror(*v11);
snprintf(v13, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", v12);
goto LABEL_13;
}
sem_send = semget(v1, 1, 1968);
if ( sem_send == -1 )
{
sem_send = semget(v1, 1, 0);
if ( sem_send == -1 )
{
memset(v13, 0, 0x100uLL);
v5 = _errno_location();
v6 = strerror(*v5);
snprintf(v13, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semget --- %s", v6);
goto LABEL_13;
}
}
else
{
v0 = 1LL;
if ( semctl(sem_send, 0, 16, 1LL) == -1 )
{
LABEL_12:
memset(v13, 0, 0x100uLL);
v9 = _errno_location();
v10 = strerror(*v9);
snprintf(v13, 0x100uLL, "[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", v10);
goto LABEL_13;
}
}
sem_recv = semget(v3, 1, 1968);
if ( sem_recv != -1 )
{
if ( semctl(sem_recv, 0, 16, v0 & 0xFFFFFFFF00000000LL) != -1 )
return 0LL;
goto LABEL_12;
}
sem_recv = semget(v3, 1, 0);
if ( sem_send != -1 )
return 0LL;
memset(v13, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v13, 0x100uLL, "[ERROR] shareMem.c @ InitSem @ semget --- %s", v8);
LABEL_13:
func2("/home/shaw/Data/Logs/ErrorLog.txt", v13);
return 0xFFFFFFFFLL;
}

original_code:
static int InitSem(void)
{
 union semun sem_union;
 key_t sem_key1, sem_key2;
 char logString[256];
 sem_key1 = ftok("/home/shaw/Data/", 11);
 sem_key2 = ftok("/home/shaw/Data/", 12);
 if ((sem_key1 == -1)||(sem_key2 == -1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 sem_send = semget(sem_key1, num_sems, 01000|02000|0660);
 if(sem_send != -1)
 {
  sem_union.val = 1;
  if (semctl(sem_send, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_send = semget(sem_key1, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 sem_recv = semget(sem_key2, num_sems, 01000|02000|0660);
 if (sem_recv != -1)
 {
  sem_union.val = 0;
  if (semctl(sem_recv, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_recv = semget(sem_key2, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] shareMem.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return -1;
}

canonical_original_code:
static int InitSem()
{
 union semun sem_union;
 int sem_key1; int sem_key2;
 char logString[256];
 sem_key1 = ftok("/home/shaw/Data/", 11);
 sem_key2 = ftok("/home/shaw/Data/", 12);
 if ((sem_key1 == -1)||(sem_key2 == -1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 sem_send = semget(sem_key1, num_sems, 01000|02000|0660);
 if(sem_send != -1)
 {
  sem_union.val = 1;
  if (semctl(sem_send, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_send = semget(sem_key1, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 sem_recv = semget(sem_key2, num_sems, 01000|02000|0660);
 if (sem_recv != -1)
 {
  sem_union.val = 0;
  if (semctl(sem_recv, 0, 16, sem_union) == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] domainUpdate.c @ InitSem @ semctl --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }else{
  sem_recv = semget(sem_key2, num_sems, 0);
  if(sem_send == -1)
  {
   memset(logString, 0, 256);
   snprintf(logString,256,"[ERROR] shareMem.c @ InitSem @ semget --- %s", strerror((*__errno_location ())));
   goto err_out;
  }
 }
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return -1;
}

variable_types: union semun { int val; struct semid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; } *buf; unsigned short *array; struct seminfo { int semmap; int semmni; int semmns; int semmnu; int semmsl; int semopm; int semume; int semusz; int semvmx; int semaem; } *__buf; }

user_defined_types: union semun { int val; struct semid_ds *buf; unsigned short *array; struct seminfo *__buf; }

user_defined_types: struct semid_ds { struct ipc_perm sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; }


InitShm

decompiled_code:
__int64 InitShm()
{
key_t v0; // eax
int v1; // edi
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = ftok("/home/shaw/Data/", 10);
if ( v0 == -1 )
{
memset(v9, 0, 0x100uLL);
v3 = _errno_location();
v4 = strerror(*v3);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", v4);
}
else
{
v1 = shmget(v0, 0x100000uLL, 944);
if ( v1 == -1 )
{
memset(v9, 0, 0x100uLL);
v5 = _errno_location();
v6 = strerror(*v5);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", v6);
}
else
{
share_region = shmat(v1, 0LL, 0);
if ( share_region != (void *)-1LL )
return (unsigned int)-((unsigned int)InitSem() == -1);
memset(v9, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", v8);
}
}
Logging("/home/shaw/Data/Logs/ErrorLog.txt", v9);
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
key_t v0; // eax
int v1; // edi
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = ftok("/home/shaw/Data/", 10);
if ( v0 == -1 )
{
memset(v9, 0, 0x100uLL);
v3 = _errno_location();
v4 = strerror(*v3);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", v4);
}
else
{
v1 = shmget(v0, 0x100000uLL, 944);
if ( v1 == -1 )
{
memset(v9, 0, 0x100uLL);
v5 = _errno_location();
v6 = strerror(*v5);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", v6);
}
else
{
share_region = shmat(v1, 0LL, 0);
if ( share_region != (void *)-1LL )
return (unsigned int)-((unsigned int)func4() == -1);
memset(v9, 0, 0x100uLL);
v7 = _errno_location();
v8 = strerror(*v7);
snprintf(v9, 0x100uLL, "[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", v8);
}
}
func2("/home/shaw/Data/Logs/ErrorLog.txt", v9);
return 1LL;
}

original_code:
result_t InitShm(void)
{
 key_t mem_key;
 char logString[256];
 mem_key = ftok("/home/shaw/Data/", 10);
    if(mem_key==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 share_id=shmget(mem_key,1024*1024,01000|0660);
        if(share_id==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if((share_region=shmat(share_id, 0, 0))==(void *)(-1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if(InitSem() == -1)
  return -1;
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return 1;
}

canonical_original_code:
int InitShm()
{
 int mem_key;
 char logString[256];
 mem_key = ftok("/home/shaw/Data/", 10);
    if(mem_key==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ ftok --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 share_id=shmget(mem_key,1024*1024,01000|0660);
        if(share_id==-1)
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmget --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if((share_region=shmat(share_id, 0, 0))==(void *)(-1))
 {
  memset(logString, 0, 256);
  snprintf(logString,256,"[ERROR] domainUpdate.c @ InitShm @ shmat --- %s", strerror((*__errno_location ())));
  goto err_out;
 }
 if(InitSem() == -1)
  return -1;
 return 0;
err_out:
 Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
 return 1;
}


UpdateCreate

decompiled_code:
__int64 UpdateCreate()
{
int v0; // ebx
int oldtype; // [rsp+Ch] [rbp-11Ch] BYREF
__m128i v3[17]; // [rsp+10h] [rbp-118h] BYREF

v0 = 0;
pthread_setcanceltype(1, &oldtype);
while ( 1 )
{
while ( (unsigned int)semaphore_p(sem_recv) != -1 )
{
v0 = 0;
ProcessUpdate((__int64)share_region);
if ( (unsigned int)semaphore_v(sem_send) == -1 )
{
InitShm();
v0 = 1;
}
}
memset(v3, 0, 0x100uLL);
if ( v0 > 2 )
break;
InitShm();
++v0;
}
v3[0] = _mm_load_si128((const __m128i *)&LC18);
v3[1] = _mm_load_si128((const __m128i *)&LC19);
v3[2] = _mm_load_si128((const __m128i *)&LC20);
v3[3] = _mm_load_si128((const __m128i *)&LC21);
v3[4] = _mm_load_si128((const __m128i *)&LC22);
v3[5] = _mm_load_si128((const __m128i *)&LC23);
Logging("/home/shaw/Data/Logs/ErrorLog.txt", (const char *)v3);
return -1LL;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // ebx
int oldtype; // [rsp+Ch] [rbp-11Ch] BYREF
__m128i v3[17]; // [rsp+10h] [rbp-118h] BYREF

v0 = 0;
pthread_setcanceltype(1, &oldtype);
while ( 1 )
{
while ( (unsigned int)func0(sem_recv) != -1 )
{
v0 = 0;
func3((__int64)share_region);
if ( (unsigned int)func1(sem_send) == -1 )
{
func5();
v0 = 1;
}
}
memset(v3, 0, 0x100uLL);
if ( v0 > 2 )
break;
func5();
++v0;
}
v3[0] = _mm_load_si128((const __m128i *)&LC18);
v3[1] = _mm_load_si128((const __m128i *)&LC19);
v3[2] = _mm_load_si128((const __m128i *)&LC20);
v3[3] = _mm_load_si128((const __m128i *)&LC21);
v3[4] = _mm_load_si128((const __m128i *)&LC22);
v3[5] = _mm_load_si128((const __m128i *)&LC23);
func2("/home/shaw/Data/Logs/ErrorLog.txt", (const char *)v3);
return -1LL;
}

original_code:
void* UpdateCreate(void *arg)
{
 char logString[256];
        int oldtype, ret, retry=0;
 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&oldtype);
 while(1)
 {
  ret = semaphore_p(sem_recv);
  if(ret == -1)
  {
   memset(logString, 0, 256);
   if(retry < 3)
   {
    InitShm();
    retry++;
    continue;
   }else{
    snprintf(logString,256,"[ERROR] domainUpdate.c @ UpdateCreate @ semaphore_p --- semaphore maybe destory, resume failed!");
    Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
    return (void*)(-1);
   }
  }
  retry = 0;
  ProcessUpdate(share_region);
  ret = semaphore_v(sem_send);
  if(ret == -1)
  {
   InitShm();
   retry++;
  }
 }
 return arg;
}

canonical_original_code:
void *UpdateCreate(void *arg)
{
 char logString[256];
        int oldtype; int ret; int retry = 0;
 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&oldtype);
 while(1)
 {
  ret = semaphore_p(sem_recv);
  if(ret == -1)
  {
   memset(logString, 0, 256);
   if(retry < 3)
   {
    InitShm();
    retry++;
    continue;
   }else{
    snprintf(logString,256,"[ERROR] domainUpdate.c @ UpdateCreate @ semaphore_p --- semaphore maybe destory, resume failed!");
    Logging("/home/shaw/Data/Logs/ErrorLog.txt", logString);
    return (void *)(-1);
   }
  }
  retry = 0;
  ProcessUpdate(share_region);
  ret = semaphore_v(sem_send);
  if(ret == -1)
  {
   InitShm();
   retry++;
  }
 }
 return arg;
}

variable_types:
arg
void *

variable_types: oldtype int

variable_types: ret int

variable_types: retry int

return_type: void *


DetShm

decompiled_code:
__int64 DetShm()
{
if ( share_region )
shmdt(share_region);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
if ( share_region )
shmdt(share_region);
return 0LL;
}

original_code:
result_t DetShm(void)
{
 if(share_region!=((void *)0))
  shmdt(share_region);
 return 0;
}

canonical_original_code:
int DetShm()
{
 if(share_region!=((void *)0))
  shmdt(share_region);
 return 0;
}


hash

decompiled_code:
__int64 __fastcall hash(_BYTE *a1)
{
__int64 result; // rax
int v2; // eax

for ( result = 0LL; *a1; result = (unsigned int)(2 * v2) )
v2 = *(_DWORD *)a1++ ^ result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
__int64 result; // rax
int v2; // eax

for ( result = 0LL; *a1; result = (unsigned int)(2 * v2) )
v2 = *(_DWORD *)a1++ ^ result;
return result;
}

original_code:
static unsigned hash(char *string)
{
      unsigned ret_val = 0;
      int i;
      while (*string)
      {
            i = *( int *)string;
            ret_val ^= i;
            ret_val <<= 1;
            string ++;
      }
      return ret_val;
}

canonical_original_code:
static unsigned int hash(char *string)
{
      unsigned int ret_val = 0;
      int i;
      while (*string)
      {
            i = *( int *)string;
            ret_val ^= i;
            ret_val <<= 1;
            string ++;
      }
      return ret_val;
}

variable_types:
string
char *

variable_types: i int

return_type: unsigned int


printer

decompiled_code:
int __fastcall printer(const char *a1, const char *a2)
{
return printf("%s: %s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, const char *a2)
{
return printf("%s: %s\n", a1, a2);
}

original_code:
void printer(char *string, void *data)
{
      printf("%s: %s\n", string, (char *)data);
}

variable_types:
data
void *


lookup

decompiled_code:
__int64 __fastcall lookup(char *s1, unsigned __int64 *a2)
{
__int64 v2; // rdx
unsigned __int128 v3; // rtt
__int64 v4; // r12

*(_QWORD *)&v3 = (unsigned int)hash(s1);
*((_QWORD *)&v3 + 1) = v2;
v4 = *(_QWORD *)(a2[1] + 8 * (v3 % *a2));
if ( !v4 )
return v4;
while ( strcmp(s1, *(const char **)v4) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return v4;
}
return *(_QWORD *)(v4 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s1, unsigned __int64 *a2)
{
__int64 v2; // rdx
unsigned __int128 v3; // rtt
__int64 v4; // r12

*(_QWORD *)&v3 = (unsigned int)func7(s1);
*((_QWORD *)&v3 + 1) = v2;
v4 = *(_QWORD *)(a2[1] + 8 * (v3 % *a2));
if ( !v4 )
return v4;
while ( strcmp(s1, *(const char **)v4) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return v4;
}
return *(_QWORD *)(v4 + 8);
}

original_code:
void *lookup(char *key, hash_table *table)
{
      unsigned val = hash(key) % table->size;
      bucket *ptr;
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for ( ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr->next )
      {
            if (0 == strcmp(key, ptr -> key ) )
                  return ptr->data;
      }
      return ((void *)0);
}

canonical_original_code:
void *lookup(char *key, struct hash_table *table)
{
      unsigned int val = hash(key) % table->size;
      struct bucket *ptr;
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for ( ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr->next )
      {
            if (0 == strcmp(key, ptr -> key ) )
                  return ptr->data;
      }
      return ((void *)0);
}

variable_types:
key
char *

variable_types: struct hash_table { unsigned long size; struct bucket { char *key; void *data; struct bucket *next; } **table; } *

variable_types:
val
unsigned int

user_defined_types: struct hash_table { unsigned long size; struct bucket **table; }


del

decompiled_code:
__int64 __fastcall del(char *s1, unsigned __int64 *a2)
{
__int64 v2; // rdx
unsigned __int128 v3; // rtt
__int64 *v4; // r14
__int64 v5; // rbp
__int64 v6; // r13
char *v7; // r12
int v8; // er8
__int64 result; // rax
__int64 v10; // rbx

*(_QWORD *)&v3 = (unsigned int)hash(s1);
*((_QWORD *)&v3 + 1) = v2;
v4 = (__int64 *)(a2[1] + 8 * (v3 % *a2));
v5 = *v4;
if ( !*v4 )
return 0LL;
v6 = 0LL;
while ( 1 )
{
v7 = *(char **)v5;
v8 = strcmp(s1, *(const char **)v5);
result = *(_QWORD *)(v5 + 16);
if ( !v8 )
break;
v6 = v5;
if ( !result )
return result;
v5 = *(_QWORD *)(v5 + 16);
}
v10 = *(_QWORD *)(v5 + 8);
if ( v6 )
*(_QWORD *)(v6 + 16) = result;
else
*v4 = result;
free(v7);
free((void *)v5);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *s1, unsigned __int64 *a2)
{
__int64 v2; // rdx
unsigned __int128 v3; // rtt
__int64 *v4; // r14
__int64 v5; // rbp
__int64 v6; // r13
char *v7; // r12
int v8; // er8
__int64 result; // rax
__int64 v10; // rbx

*(_QWORD *)&v3 = (unsigned int)func7(s1);
*((_QWORD *)&v3 + 1) = v2;
v4 = (__int64 *)(a2[1] + 8 * (v3 % *a2));
v5 = *v4;
if ( !*v4 )
return 0LL;
v6 = 0LL;
while ( 1 )
{
v7 = *(char **)v5;
v8 = strcmp(s1, *(const char **)v5);
result = *(_QWORD *)(v5 + 16);
if ( !v8 )
break;
v6 = v5;
if ( !result )
return result;
v5 = *(_QWORD *)(v5 + 16);
}
v10 = *(_QWORD *)(v5 + 8);
if ( v6 )
*(_QWORD *)(v6 + 16) = result;
else
*v4 = result;
free(v7);
free((void *)v5);
return v10;
}

original_code:
void *del(char *key, hash_table *table)
{
      unsigned val = hash(key) % table->size;
      void *data;
      bucket *ptr, *last = ((void *)0);
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for (last = ((void *)0), ptr = (table->table)[val];((void *)0) != ptr;last = ptr, ptr = ptr->next)
      {
            if (0 == strcmp(key, ptr -> key))
            {
                  if (last != ((void *)0) )
                  {
                        data = ptr -> data;
                        last -> next = ptr -> next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
                  else
                  {
                        data = ptr->data;
                        (table->table)[val] = ptr->next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
            }
      }
      return ((void *)0);
}

canonical_original_code:
void *del(char *key, struct hash_table *table)
{
      unsigned int val = hash(key) % table->size;
      void *data;
      struct bucket *ptr; struct bucket *last = ((void *)0);
      if (((void *)0) == (table->table)[val])
            return ((void *)0);
      for (last = ((void *)0), ptr = (table->table)[val];((void *)0) != ptr;last = ptr, ptr = ptr->next)
      {
            if (0 == strcmp(key, ptr -> key))
            {
                  if (last != ((void *)0) )
                  {
                        data = ptr -> data;
                        last -> next = ptr -> next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
                  else
                  {
                        data = ptr->data;
                        (table->table)[val] = ptr->next;
                        free(ptr->key);
                        free(ptr);
                        return data;
                  }
            }
      }
      return ((void *)0);
}

variable_types: struct bucket { char *key; void *data; struct bucket *next; } *


decompiled_code:
__int64 __fastcall free_node(char *a1)
{
__int64 (__fastcall *v1)(__int64); // rbx
__int64 v2; // rdi

v1 = (__int64 (__fastcall *)(__int64))function;
if ( !function )
return del(a1, (unsigned __int64 *)the_table);
v2 = del(a1, (unsigned __int64 *)the_table);
return v1(v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
__int64 (__fastcall *v1)(__int64); // rbx
__int64 v2; // rdi

v1 = (__int64 (__fastcall *)(__int64))function;
if ( !function )
return func11(a1, (unsigned __int64 *)the_table);
v2 = func11(a1, (unsigned __int64 *)the_table);
return v1(v2);
}

original_code:
static void free_node(char *key, void *data)
{
    (void) data;
    if (function)
        function(del(key,the_table));
    else
        del(key,the_table);
}


enumerate

decompiled_code:
void __fastcall enumerate(_QWORD *a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
__int64 v2; // rax
unsigned int v3; // er12
_QWORD *i; // rbx

if ( *a1 )
{
v2 = 0LL;
v3 = 0;
do
{
for ( i = *(_QWORD **)(a1[1] + 8 * v2); i; i = (_QWORD *)i[2] )
a2(*i, i[1]);
v2 = ++v3;
}
while ( (unsigned __int64)v3 < *a1 );
}
}

canonical_decompiled_code:
void __fastcall func13(_QWORD *a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
__int64 v2; // rax
unsigned int v3; // er12
_QWORD *i; // rbx

if ( *a1 )
{
v2 = 0LL;
v3 = 0;
do
{
for ( i = *(_QWORD **)(a1[1] + 8 * v2); i; i = (_QWORD *)i[2] )
a2(*i, i[1]);
v2 = ++v3;
}
while ( (unsigned __int64)v3 < *a1 );
}
}

original_code:
void enumerate( hash_table *table, void (*func)(char *, void *))
{
      unsigned i;
      bucket *temp;
      for (i=0;i<table->size; i++)
      {
            if ((table->table)[i] != ((void *)0))
            {
                  for (temp = (table->table)[i];((void *)0) != temp;temp = temp -> next)
                  {
                        func(temp -> key, temp->data);
                  }
            }
      }
}

canonical_original_code:
void enumerate(struct hash_table *table, void (*func)(char *, void *))
{
      unsigned int i;
      struct bucket *temp;
      for (i=0;i<table->size; i++)
      {
            if ((table->table)[i] != ((void *)0))
            {
                  for (temp = (table->table)[i];((void *)0) != temp;temp = temp -> next)
                  {
                        func(temp -> key, temp->data);
                  }
            }
      }
}

variable_types:
func
void (*)(char *, void *)

variable_types:
i
unsigned int

user_defined_types: struct bucket { char *key; void *data; struct bucket *next; }


decompiled_code:
void __fastcall free_table(__int64 a1, __int64 a2)
{
function = a2;
the_table = a1;
enumerate((_QWORD *)a1, (void (__fastcall *)(_QWORD, _QWORD))free_node);
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
the_table = 0LL;
function = 0LL;
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2)
{
function = a2;
the_table = a1;
func13((_QWORD *)a1, (void (__fastcall *)(_QWORD, _QWORD))free_node);
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
the_table = 0LL;
function = 0LL;
}

original_code:
void free_table(hash_table *table, void (*func)(void *))
{
      function = func;
      the_table = table;
      enumerate( table, free_node);
      free(table->table);
      table->table = ((void *)0);
      table->size = 0;
      the_table = ((void *)0);
      function = (void (*)(void *))((void *)0);
}

canonical_original_code:
void free_table(struct hash_table *table, void (*func)(void *))
{
      function = func;
      the_table = table;
      enumerate( table, free_node);
      free(table->table);
      table->table = ((void *)0);
      table->size = 0;
      the_table = ((void *)0);
      function = (void (*)(void *))((void *)0);
}

variable_types:
func
void (*)(void *)


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // rdi
const char **v5; // rbx
char *v6; // rbp
__int64 *v7; // r12
const char *v8; // rbx
char *v9; // rbp
const char *v10; // rax
_QWORD v12[9]; // [rsp+0h] [rbp-98h] BYREF
const char *v13; // [rsp+48h] [rbp-50h] BYREF
__int64 v14[9]; // [rsp+50h] [rbp-48h] BYREF

v3 = 1LL;
v13 = "The second string";
v14[0] = (__int64)"The third string";
v14[1] = (__int64)"The fourth string";
v14[2] = (__int64)"A much longer string than the rest in this example.";
v14[3] = (__int64)"The last string";
v14[4] = 0LL;
v12[3] = "The second data";
v12[4] = "The third data";
v12[5] = "The fourth data";
v12[6] = "The fifth datum";
v12[7] = "The sixth piece of data";
construct_table(v12, 200LL, envp);
v4 = "The first string";
while ( 1 )
{
insert(v4);
v4 = (char *)v12[v3 + 8];
if ( !v4 )
break;
++v3;
}
v5 = &v13;
v6 = "The first string";
do
{
++v5;
putchar(10);
enumerate(v12, printer);
del(v6);
v6 = (char *)*(v5 - 1);
}
while ( v6 );
v7 = v14;
v8 = "The second string";
v9 = "The first string";
while ( lookup(v9) )
{
printf("\nERROR: %s was deleted but is still in table.", v9);
if ( !v8 )
goto LABEL_11;
LABEL_8:
v10 = (const char *)*v7;
v9 = (char *)v8;
++v7;
v8 = v10;
}
printf("\n'%s' is not in table", v9);
if ( v8 )
goto LABEL_8;
LABEL_11:
putchar(10);
free_table(v12, 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // rdi
const char **v5; // rbx
char *v6; // rbp
__int64 *v7; // r12
const char *v8; // rbx
char *v9; // rbp
const char *v10; // rax
_QWORD v12[9]; // [rsp+0h] [rbp-98h] BYREF
const char *v13; // [rsp+48h] [rbp-50h] BYREF
__int64 v14[9]; // [rsp+50h] [rbp-48h] BYREF

v3 = 1LL;
v13 = "The second string";
v14[0] = (__int64)"The third string";
v14[1] = (__int64)"The fourth string";
v14[2] = (__int64)"A much longer string than the rest in this example.";
v14[3] = (__int64)"The last string";
v14[4] = 0LL;
v12[3] = "The second data";
v12[4] = "The third data";
v12[5] = "The fourth data";
v12[6] = "The fifth datum";
v12[7] = "The sixth piece of data";
construct_table(v12, 200LL, envp);
v4 = "The first string";
while ( 1 )
{
func9(v4);
v4 = (char *)v12[v3 + 8];
if ( !v4 )
break;
++v3;
}
v5 = &v13;
v6 = "The first string";
do
{
++v5;
putchar(10);
func13(v12, printer);
func11(v6);
v6 = (char *)*(v5 - 1);
}
while ( v6 );
v7 = v14;
v8 = "The second string";
v9 = "The first string";
while ( func10(v9) )
{
printf("\nERROR: %s was deleted but is still in table.", v9);
if ( !v8 )
goto LABEL_11;
LABEL_8:
v10 = (const char *)*v7;
v9 = (char *)v8;
++v7;
v8 = v10;
}
printf("\n'%s' is not in table", v9);
if ( v8 )
goto LABEL_8;
LABEL_11:
putchar(10);
func14(v12, 0LL);
return 0;
}

original_code:
int main(void)
{
      hash_table table;
      char *strings[] = {
            "The first string",
            "The second string",
            "The third string",
            "The fourth string",
            "A much longer string than the rest in this example.",
            "The last string",
            ((void *)0)
            };
      char *junk[] = {
            "The first data",
            "The second data",
            "The third data",
            "The fourth data",
            "The fifth datum",
            "The sixth piece of data"
            };
      int i;
      void *j;
      construct_table(&table,200);
      for (i = 0; ((void *)0) != strings[i]; i++ )
            insert(strings[i], junk[i], &table);
      for (i=0;((void *)0) != strings[i];i++)
      {
            printf("\n");
            enumerate(&table, printer);
            del(strings[i],&table);
      }
      for (i=0;((void *)0) != strings[i];i++)
      {
            j = lookup(strings[i], &table);
            if (((void *)0) == j)
                  printf("\n'%s' is not in table",strings[i]);
            else
                printf("\nERROR: %s was deleted but is still in table.",strings[i]);
      }
      printf("\n");
      free_table(&table, ((void *)0));
      return 0;
}

canonical_original_code:
int main()
{
      struct hash_table table;
      char *strings[] = {
            "The first string",
            "The second string",
            "The third string",
            "The fourth string",
            "A much longer string than the rest in this example.",
            "The last string",
            ((void *)0)
            };
      char *junk[] = {
            "The first data",
            "The second data",
            "The third data",
            "The fourth data",
            "The fifth datum",
            "The sixth piece of data"
            };
      int i;
      void *j;
      construct_table(&table,200);
      for (i = 0; ((void *)0) != strings[i]; i++ )
            insert(strings[i], junk[i], &table);
      for (i=0;((void *)0) != strings[i];i++)
      {
            printf("\n");
            enumerate(&table, printer);
            del(strings[i],&table);
      }
      for (i=0;((void *)0) != strings[i];i++)
      {
            j = lookup(strings[i], &table);
            if (((void *)0) == j)
                  printf("\n'%s' is not in table",strings[i]);
            else
                printf("\nERROR: %s was deleted but is still in table.",strings[i]);
      }
      printf("\n");
      free_table(&table, ((void *)0));
      return 0;
}

variable_types: struct hash_table { unsigned long size; struct bucket { char *key; void *data; struct bucket *next; } **table; }

variable_types:
strings
char *[]

variable_types:
junk
char *[]

variable_types:
j
void *


insert

decompiled_code:
__int64 __fastcall insert(char *s, __int64 a2)
{
__int64 v2; // rdx
unsigned __int128 v3; // rtt
unsigned __int64 *v4; // rcx
unsigned __int64 v5; // r13
__int64 v6; // rbx
_QWORD *v7; // rbx
char *v8; // rax
__int64 result; // rax
char **v10; // rax
char **v11; // rbx
char *v12; // rax

*(_QWORD *)&v3 = (unsigned int)hash(s);
*((_QWORD *)&v3 + 1) = v2;
v5 = v4[1] + 8 * (v3 % *v4);
v6 = *(_QWORD *)v5;
if ( *(_QWORD *)v5 )
{
do
{
if ( !strcmp(s, *(const char **)v6) )
{
result = *(_QWORD *)(v6 + 8);
*(_QWORD *)(v6 + 8) = a2;
return result;
}
v6 = *(_QWORD *)(v6 + 16);
}
while ( v6 );
v7 = malloc(0x18uLL);
if ( !v7 )
goto LABEL_9;
v8 = strdup(s);
v7[1] = a2;
*v7 = v8;
v7[2] = *(_QWORD *)v5;
result = a2;
*(_QWORD *)v5 = v7;
}
else
{
v10 = (char **)malloc(0x18uLL);
*(_QWORD *)v5 = v10;
v11 = v10;
if ( v10 )
{
v12 = strdup(s);
v11[2] = 0LL;
*v11 = v12;
*(_QWORD *)(*(_QWORD *)v5 + 8LL) = a2;
result = *(_QWORD *)(*(_QWORD *)v5 + 8LL);
}
else
{
LABEL_9:
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s, __int64 a2)
{
__int64 v2; // rdx
unsigned __int128 v3; // rtt
unsigned __int64 *v4; // rcx
unsigned __int64 v5; // r13
__int64 v6; // rbx
_QWORD *v7; // rbx
char *v8; // rax
__int64 result; // rax
char **v10; // rax
char **v11; // rbx
char *v12; // rax

*(_QWORD *)&v3 = (unsigned int)func7(s);
*((_QWORD *)&v3 + 1) = v2;
v5 = v4[1] + 8 * (v3 % *v4);
v6 = *(_QWORD *)v5;
if ( *(_QWORD *)v5 )
{
do
{
if ( !strcmp(s, *(const char **)v6) )
{
result = *(_QWORD *)(v6 + 8);
*(_QWORD *)(v6 + 8) = a2;
return result;
}
v6 = *(_QWORD *)(v6 + 16);
}
while ( v6 );
v7 = malloc(0x18uLL);
if ( !v7 )
goto LABEL_9;
v8 = strdup(s);
v7[1] = a2;
*v7 = v8;
v7[2] = *(_QWORD *)v5;
result = a2;
*(_QWORD *)v5 = v7;
}
else
{
v10 = (char **)malloc(0x18uLL);
*(_QWORD *)v5 = v10;
v11 = v10;
if ( v10 )
{
v12 = strdup(s);
v11[2] = 0LL;
*v11 = v12;
*(_QWORD *)(*(_QWORD *)v5 + 8LL) = a2;
result = *(_QWORD *)(*(_QWORD *)v5 + 8LL);
}
else
{
LABEL_9:
result = 0LL;
}
}
return result;
}

original_code:
void *insert(char *key, void *data, hash_table *table)
{
      unsigned val = hash(key) % table->size;
      bucket *ptr;
      if (((void *)0) == (table->table)[val])
      {
            (table->table)[val] = (bucket *)malloc(sizeof(bucket));
            if (((void *)0)==(table->table)[val])
                  return ((void *)0);
            (table->table)[val] -> key = strdup(key);
            (table->table)[val] -> next = ((void *)0);
            (table->table)[val] -> data = data;
            return (table->table)[val] -> data;
      }
      for (ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr -> next)
            if (0 == strcmp(key, ptr->key))
            {
                  void *old_data;
                  old_data = ptr->data;
                  ptr -> data = data;
                  return old_data;
            }
      ptr = (bucket *)malloc(sizeof(bucket));
      if (((void *)0)==ptr)
            return ((void *)0);
      ptr -> key = strdup(key);
      ptr -> data = data;
      ptr -> next = (table->table)[val];
      (table->table)[val] = ptr;
      return data;
}

canonical_original_code:
void *insert(char *key, void *data, struct hash_table *table)
{
      unsigned int val = hash(key) % table->size;
      struct bucket *ptr;
      if (((void *)0) == (table->table)[val])
      {
            (table->table)[val] = (struct bucket *)malloc(sizeof(bucket));
            if (((void *)0)==(table->table)[val])
                  return ((void *)0);
            (table->table)[val] -> key = strdup(key);
            (table->table)[val] -> next = ((void *)0);
            (table->table)[val] -> data = data;
            return (table->table)[val] -> data;
      }
      for (ptr = (table->table)[val];((void *)0) != ptr; ptr = ptr -> next)
            if (0 == strcmp(key, ptr->key))
            {
                  void *old_data;
                  old_data = ptr->data;
                  ptr -> data = data;
                  return old_data;
            }
      ptr = (struct bucket *)malloc(sizeof(bucket));
      if (((void *)0)==ptr)
            return ((void *)0);
      ptr -> key = strdup(key);
      ptr -> data = data;
      ptr -> next = (table->table)[val];
      (table->table)[val] = ptr;
      return data;
}


decompiled_code:
__int64 rand_level()
{
unsigned int v0; // er12
int v1; // ebx

v0 = 0;
v1 = 19;
do
{
v0 += rand() % 38 > 18;
--v1;
}
while ( v1 );
return v0;
}

variable_types: level int


decompiled_code:
int *__fastcall skip_list_write(int *a1, int a2, int a3)
{
__int64 i; // rcx
int *v5; // rax
int *result; // rax
int v7; // ebx
int *v8; // rdi
__int64 v9; // rcx
__int64 v10; // rdx
int *v11; // rdx
_QWORD v12[23]; // [rsp+0h] [rbp-B8h]

for ( i = a1[2]; (int)i >= 0; --i )
{
v5 = a1;
do
{
a1 = v5;
v5 = *(int **)&v5[2 * (int)i + 4];
}
while ( v5 && *v5 < a2 );
v12[i] = a1;
}
result = (int *)*((_QWORD *)a1 + 2);
if ( !result )
result = a1;
if ( *result == a2 )
{
result[1] = a3;
}
else
{
v7 = rand_level();
result = init_skip_list_node(v7, a2, a3);
v8 = result;
if ( v7 >= 0 )
{
result = 0LL;
do
{
v9 = v12[(_QWORD)result];
v10 = (int)result + 2LL;
*(_QWORD *)&v8[2 * (_QWORD)result + 4] = *(_QWORD *)(v9 + 8 * v10);
*(_QWORD *)(v9 + 8 * v10) = v8;
v11 = result;
result = (int *)((char *)result + 1);
}
while ( v11 != (int *)v7 );
}
}
return result;
}

canonical_decompiled_code:
int *__fastcall func8(int *a1, int a2, int a3)
{
__int64 i; // rcx
int *v5; // rax
int *result; // rax
int v7; // ebx
int *v8; // rdi
__int64 v9; // rcx
__int64 v10; // rdx
int *v11; // rdx
_QWORD v12[23]; // [rsp+0h] [rbp-B8h]

for ( i = a1[2]; (int)i >= 0; --i )
{
v5 = a1;
do
{
a1 = v5;
v5 = *(int **)&v5[2 * (int)i + 4];
}
while ( v5 && *v5 < a2 );
v12[i] = a1;
}
result = (int *)*((_QWORD *)a1 + 2);
if ( !result )
result = a1;
if ( *result == a2 )
{
result[1] = a3;
}
else
{
v7 = func7();
result = init_skip_list_node(v7, a2, a3);
v8 = result;
if ( v7 >= 0 )
{
result = 0LL;
do
{
v9 = v12[(_QWORD)result];
v10 = (int)result + 2LL;
*(_QWORD *)&v8[2 * (_QWORD)result + 4] = *(_QWORD *)(v9 + 8 * v10);
*(_QWORD *)(v9 + 8 * v10) = v8;
v11 = result;
result = (int *)((char *)result + 1);
}
while ( v11 != (int *)v7 );
}
}
return result;
}

original_code:
int skip_list_write (skip_list_t *skip_list, int key, int value)
{
    skip_list_t *update_node[20];
    skip_list_t *node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
        update_node[i] = node;
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        node->value = value;
    }
    else
    {
        int level = rand_level();
        node = init_skip_list_node(level, key, value);
        for (i = 0; i <= level; ++i)
        {
            node->forward[i] = update_node[i]->forward[i];
            update_node[i]->forward[i] = node;
        }
    }
}

canonical_original_code:
int skip_list_write(struct skip_list_struct *skip_list, int key, int value)
{
    struct skip_list_struct *update_node[20];
    struct skip_list_struct *node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
        update_node[i] = node;
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        node->value = value;
    }
    else
    {
        int level = rand_level();
        node = init_skip_list_node(level, key, value);
        for (i = 0; i <= level; ++i)
        {
            node->forward[i] = update_node[i]->forward[i];
            update_node[i]->forward[i] = node;
        }
    }
}

variable_types: key int

variable_types: value int

variable_types: struct skip_list_struct { int key; int value; int level; struct skip_list_struct *forward[20]; } *[20]


original_code:
int skip_list_delete (skip_list_t* skip_list, int key)
{
    skip_list_t* update_node[20];
    skip_list_t* node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i]!= ((void *)0) && key> node->forward[i]->key)
        {
            node= node->forward[i];
        }
        update_node[i]= node;
    }
    node = node->forward[0] == ((void *)0) ? node: node->forward[0];
    if (key == node->key)
    {
        for (i = 0; i <= skip_list->level; ++i)
        {
            if (update_node[i]->forward[i] != node)
            {
                break;
            }
            update_node[i]->forward[i] = node->forward[i];
        }
        free(node);
        return 0;
    }
    else
    {
        return 1;
    }
}

canonical_original_code:
int skip_list_delete(struct skip_list_struct *skip_list, int key)
{
    struct skip_list_struct *update_node[20];
    struct skip_list_struct *node = skip_list;
    int i = skip_list->level;
    for(; i>=0; --i)
    {
        while (node->forward[i]!= ((void *)0) && key> node->forward[i]->key)
        {
            node= node->forward[i];
        }
        update_node[i]= node;
    }
    node = node->forward[0] == ((void *)0) ? node: node->forward[0];
    if (key == node->key)
    {
        for (i = 0; i <= skip_list->level; ++i)
        {
            if (update_node[i]->forward[i] != node)
            {
                break;
            }
            update_node[i]->forward[i] = node->forward[i];
        }
        free(node);
        return 0;
    }
    else
    {
        return 1;
    }
}

variable_types: struct skip_list_struct { int key; int value; int level; struct skip_list_struct *forward[20]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall skip_list_search(_DWORD *a1, int a2)
{
int v2; // ecx
_DWORD *v3; // rax
_DWORD *v5; // rax
__int64 result; // rax

v2 = a1[2];
if ( v2 >= 0 )
{
do
{
v3 = a1;
do
{
a1 = v3;
v3 = *(_DWORD **)&v3[2 * v2 + 4];
}
while ( v3 && *v3 < a2 );
}
while ( v2-- != 0 );
}
v5 = (_DWORD *)*((_QWORD *)a1 + 2);
if ( !v5 )
v5 = a1;
if ( *v5 == a2 )
result = (unsigned int)v5[1];
else
result = 0x80000000LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, int a2)
{
int v2; // ecx
_DWORD *v3; // rax
_DWORD *v5; // rax
__int64 result; // rax

v2 = a1[2];
if ( v2 >= 0 )
{
do
{
v3 = a1;
do
{
a1 = v3;
v3 = *(_DWORD **)&v3[2 * v2 + 4];
}
while ( v3 && *v3 < a2 );
}
while ( v2-- != 0 );
}
v5 = (_DWORD *)*((_QWORD *)a1 + 2);
if ( !v5 )
v5 = a1;
if ( *v5 == a2 )
result = (unsigned int)v5[1];
else
result = 0x80000000LL;
return result;
}

original_code:
int skip_list_search (skip_list_t* skip_list, int key)
{
    skip_list_t *node = skip_list;
    int level = node->level;
    int i = level;
    for (; i>= 0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        return node->value;
    }
    else
    {
        return (-0x7fffffff - 1);
    }
}

canonical_original_code:
int skip_list_search(struct skip_list_struct *skip_list, int key)
{
    struct skip_list_struct *node = skip_list;
    int level = node->level;
    int i = level;
    for (; i>= 0; --i)
    {
        while (node->forward[i] != ((void *)0) && key > node->forward[i]->key)
        {
            node = node->forward[i];
        }
    }
    node = node->forward[0] == ((void *)0) ? node : node->forward[0];
    if (key == node->key)
    {
        return node->value;
    }
    else
    {
        return (-0x7fffffff - 1);
    }
}

user_defined_types: struct skip_list_struct { int key; int value; int level; struct skip_list_struct *forward[20]; }


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

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

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

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

original_code:
int free_skip_list (skip_list_t* skip_list)
{
    skip_list_t *node = skip_list->forward[0];
    skip_list_t *next_node;
    while (node != ((void *)0))
    {
        next_node = node->forward[0];
        free(node);
        node = next_node;
    }
    free(skip_list);
}

canonical_original_code:
int free_skip_list(struct skip_list_struct *skip_list)
{
    struct skip_list_struct *node = skip_list->forward[0];
    struct skip_list_struct *next_node;
    while (node != ((void *)0))
    {
        next_node = node->forward[0];
        free(node);
        node = next_node;
    }
    free(skip_list);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // eax
void *v5; // rbp
__int64 v6; // rdx
__int64 v7; // rsi
__int64 v8; // rsi
unsigned int v9; // eax
int v10; // ebx
unsigned int v11; // er12
int v12; // eax
const char *v13; // rdx
unsigned int v14; // ebx
int v15; // er12
__int64 v16; // rdx
__int64 v17; // rsi
float v18; // xmm0_4
int v19; // er12
int v20; // eax
float v21; // xmm0_4

v3 = 0;
v4 = time(0LL);
srand(v4);
puts("#### Function Test ####");
puts("== Init Skip List ==");
v5 = (void *)init_skip_list_node(19LL, 0x80000000LL, 0x80000000LL);
do
{
v6 = v3;
v7 = v3++;
skip_list_write(v5, v7, v6);
}
while ( v3 != 20 );
puts("== Print Skip List ==");
print_skip_list(v5);
puts("== Search Key ==");
do
{
v8 = (unsigned int)(rand() % 25);
v9 = skip_list_search(v5, v8);
printf("Search [%d]: %d\n", v8, v9);
--v3;
}
while ( v3 );
v10 = 20;
puts("== Delete Key ==");
do
{
v11 = rand() % 25;
v12 = skip_list_delete(v5);
v13 = "SUCCESS";
if ( v12 )
v13 = "NO FOUND";
printf("Delete [%d]: %s\n", v11, v13);
--v10;
}
while ( v10 );
v14 = 0;
puts("== Print Skip List ==");
print_skip_list(v5);
puts("#### Performance Test ####");
printf("== Insert 10^6 Items (%d Level) ==\n", 20LL);
v15 = clock();
do
{
v16 = v14;
v17 = v14++;
skip_list_write(v5, v17, v16);
}
while ( v14 != 1000000 );
v18 = (double)(int)(clock() - v15) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v18, (float)((float)(1000000.0 / v18) * 1000.0));
printf("== Search 10^6 Items (%d Level) ==\n", 20LL);
v19 = clock();
do
{
v20 = rand();
skip_list_search(v5, (unsigned int)(v20 % 1000000));
--v14;
}
while ( v14 );
v21 = (double)(int)(clock() - v19) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v21, (float)((float)(1000000.0 / v21) * 1000.0));
puts("#### Clear Memory ####");
free_skip_list(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // eax
void *v5; // rbp
__int64 v6; // rdx
__int64 v7; // rsi
__int64 v8; // rsi
unsigned int v9; // eax
int v10; // ebx
unsigned int v11; // er12
int v12; // eax
const char *v13; // rdx
unsigned int v14; // ebx
int v15; // er12
__int64 v16; // rdx
__int64 v17; // rsi
float v18; // xmm0_4
int v19; // er12
int v20; // eax
float v21; // xmm0_4

v3 = 0;
v4 = time(0LL);
srand(v4);
puts("#### Function Test ####");
puts("== Init Skip List ==");
v5 = (void *)init_skip_list_node(19LL, 0x80000000LL, 0x80000000LL);
do
{
v6 = v3;
v7 = v3++;
func8(v5, v7, v6);
}
while ( v3 != 20 );
puts("== Print Skip List ==");
func11(v5);
puts("== Search Key ==");
do
{
v8 = (unsigned int)(rand() % 25);
v9 = func10(v5, v8);
printf("Search [%d]: %d\n", v8, v9);
--v3;
}
while ( v3 );
v10 = 20;
puts("== Delete Key ==");
do
{
v11 = rand() % 25;
v12 = func9(v5);
v13 = "SUCCESS";
if ( v12 )
v13 = "NO FOUND";
printf("Delete [%d]: %s\n", v11, v13);
--v10;
}
while ( v10 );
v14 = 0;
puts("== Print Skip List ==");
func11(v5);
puts("#### Performance Test ####");
printf("== Insert 10^6 Items (%d Level) ==\n", 20LL);
v15 = clock();
do
{
v16 = v14;
v17 = v14++;
func8(v5, v17, v16);
}
while ( v14 != 1000000 );
v18 = (double)(int)(clock() - v15) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v18, (float)((float)(1000000.0 / v18) * 1000.0));
printf("== Search 10^6 Items (%d Level) ==\n", 20LL);
v19 = clock();
do
{
v20 = rand();
func10(v5, (unsigned int)(v20 % 1000000));
--v14;
}
while ( v14 );
v21 = (double)(int)(clock() - v19) / 1000000.0 * 1000.0;
printf("Time: %f ms, Speed: %f Node/s\n", v21, (float)((float)(1000000.0 / v21) * 1000.0));
puts("#### Clear Memory ####");
func12(v5);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    srand((unsigned)time(0));
    int count = 0;
    int i = 0;
    printf("#### Function Test ####\n");
    count = 20;
    printf("== Init Skip List ==\n");
    skip_list_t *skip_list = init_skip_list_node(20 -1, (-0x7fffffff - 1), (-0x7fffffff - 1));
    for (i = 0; i<count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("== Search Key ==\n");
    for(i = 0; i<count; ++i)
    {
        int key = rand()%(count+5);
        printf("Search [%d]: %d\n", key, skip_list_search(skip_list, key));
    }
    printf("== Delete Key ==\n");
    for(i = 0; i < count; ++i)
    {
        int key = rand()%(count+5);
        printf("Delete [%d]: %s\n",key,skip_list_delete(skip_list, key) ? "NO FOUND" : "SUCCESS");
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("#### Performance Test ####\n");
    clock_t start, finish;
    float time = 0;
    count = 1000000;
    printf("== Insert 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i < count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    finish = clock();
    time = (double)(finish-start)/((__clock_t) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("== Search 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i<count; ++i)
    {
        skip_list_search(skip_list, rand()%count);
    }
    finish = clock();
    time = (double)(finish-start)/((__clock_t) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("#### Clear Memory ####\n");
    free_skip_list(skip_list);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    srand((unsigned int)time(0));
    int count = 0;
    int i = 0;
    printf("#### Function Test ####\n");
    count = 20;
    printf("== Init Skip List ==\n");
    struct skip_list_struct *skip_list = init_skip_list_node(20 -1, (-0x7fffffff - 1), (-0x7fffffff - 1));
    for (i = 0; i<count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("== Search Key ==\n");
    for(i = 0; i<count; ++i)
    {
        int key = rand()%(count+5);
        printf("Search [%d]: %d\n", key, skip_list_search(skip_list, key));
    }
    printf("== Delete Key ==\n");
    for(i = 0; i < count; ++i)
    {
        int key = rand()%(count+5);
        printf("Delete [%d]: %s\n",key,skip_list_delete(skip_list, key) ? "NO FOUND" : "SUCCESS");
    }
    printf("== Print Skip List ==\n");
    print_skip_list(skip_list);
    printf("#### Performance Test ####\n");
    long start; long finish;
    float time = 0;
    count = 1000000;
    printf("== Insert 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i < count; ++i)
    {
        skip_list_write(skip_list, i, i);
    }
    finish = clock();
    time = (double)(finish-start)/((long) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("== Search 10^6 Items (%d Level) ==\n", 20);
    start = clock();
    for(i = 0; i<count; ++i)
    {
        skip_list_search(skip_list, rand()%count);
    }
    finish = clock();
    time = (double)(finish-start)/((long) 1000000)*1000;
    printf ("Time: %f ms, Speed: %f Node/s\n", time, count/time*1000);
    printf("#### Clear Memory ####\n");
    free_skip_list(skip_list);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: count int

variable_types: start long

variable_types: finish long

variable_types: time float


decompiled_code:
int __fastcall print_skip_list(__int64 a1)
{
__int64 i; // r12
unsigned int *v2; // rbx
int result; // eax

for ( i = 0LL; i != 20; ++i )
{
v2 = *(unsigned int **)(a1 + 8 * i + 16);
printf("Level[%d]: ", (unsigned int)i);
for ( ; v2; v2 = *(unsigned int **)&v2[2 * (int)i + 4] )
printf("%d -> ", *v2);
result = puts("NULL");
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
__int64 i; // r12
unsigned int *v2; // rbx
int result; // eax

for ( i = 0LL; i != 20; ++i )
{
v2 = *(unsigned int **)(a1 + 8 * i + 16);
printf("Level[%d]: ", (unsigned int)i);
for ( ; v2; v2 = *(unsigned int **)&v2[2 * (int)i + 4] )
printf("%d -> ", *v2);
result = puts("NULL");
}
return result;
}

original_code:
int print_skip_list (skip_list_t *skip_list)
{
    skip_list_t *node;
    int i = 0;
    for(; i < 20; ++i)
    {
        node = skip_list->forward[i];
        printf("Level[%d]: ", i);
        while(node != ((void *)0))
        {
            printf("%d -> ", node->key);
            node = node->forward[i];
        }
        printf("NULL\n");
    }
}

canonical_original_code:
int print_skip_list(struct skip_list_struct *skip_list)
{
    struct skip_list_struct *node;
    int i = 0;
    for(; i < 20; ++i)
    {
        node = skip_list->forward[i];
        printf("Level[%d]: ", i);
        while(node != ((void *)0))
        {
            printf("%d -> ", node->key);
            node = node->forward[i];
        }
        printf("NULL\n");
    }
}


repo: NVIDIA/nvidia-settings

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

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

original_code:
int update_scf_depth(int depth)
{
    return 1;
}

variable_types: depth int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
gen_manpage_opts_helper(&_options, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(&_options, argv, envp);
return 0;
}

original_code:
int main(void)
{
    gen_manpage_opts_helper(__options);
    return 0;
}

canonical_original_code:
int main()
{
    gen_manpage_opts_helper(__options);
    return 0;
}


decompiled_code:
int __fastcall print_option(const char **a1)
{
const char *v2; // rsi
const unsigned __int16 **v3; // rax
__int64 v4; // rsi
int v5; // eax
const char *v6; // r14
int v7; // edi
int v8; // er12
int v9; // edx
int v10; // er15
int v11; // ebx
const char *v13; // rbx
int v14; // er12
const __int32_t *v15; // rsi
__int64 v16; // rax
__int64 v17; // rdx
char dest[112]; // [rsp+0h] [rbp-70h] BYREF

if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
{
v2 = a1[2];
if ( v2 )
{
strcpy(dest, v2);
}
else
{
v13 = *a1;
v14 = strlen(*a1);
if ( v14 > 0 )
{
v15 = *__ctype_toupper_loc();
v16 = 0LL;
do
{
dest[v16] = v15[v13[v16]];
v17 = v16++;
}
while ( v17 != v14 - 1 );
}
dest[v14] = 0;
}
}
printf(".TP\n.BI \"");
v3 = __ctype_b_loc();
v4 = *((int *)a1 + 2);
if ( ((*v3)[v4] & 0x400) != 0 )
{
printf("\\-%c", v4);
if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
printf(" \" \"%s\" \"", dest);
printf(", ");
}
printf("\\-\\-%s", *a1);
v5 = *((_DWORD *)a1 + 3);
if ( (v5 & 0xE) != 0 )
{
printf("=\" \"%s", dest);
v5 = *((_DWORD *)a1 + 3);
if ( (v5 & 0x11) != 0 )
{
printf("\" \"");
v5 = *((_DWORD *)a1 + 3);
}
}
if ( (v5 & 0xF) == 1 || (v5 & 0x10) != 0 )
printf(", \\-\\-no\\-%s", *a1);
puts("\"");
v6 = a1[3];
if ( v6 )
{
v7 = *v6;
v8 = 0;
v9 = 1;
v10 = 0;
v11 = 0;
if ( *v6 )
{
do
{
if ( (char)v7 > 46 )
{
if ( (_BYTE)v7 == 94 )
{
if ( v11 )
putchar(10);
else
printf("\n.B ");
v9 = v11;
v10 = v11;
v11 ^= 1u;
goto LABEL_15;
}
}
else if ( (char)v7 > 9 )
{
switch ( (char)v7 )
{
case 10:
v10 = 0;
putchar(10);
v9 = 1;
goto LABEL_15;
case 32:
if ( !v10 )
{
putchar(32);
v9 = 0;
}
goto LABEL_15;
case 38:
if ( v8 )
putchar(10);
else
printf("\n.I ");
v9 = v8;
v10 = v8;
v8 ^= 1u;
goto LABEL_15;
case 39:
if ( !v9 )
goto LABEL_14;
fprintf(
stderr,
"Error: *roff can't start a line with '''. If you started a line with ''' in the description of the '%s' "
"option, please add some text at the beginning of the sentence, so that a valid manpage can be generated.\n",
*a1);
break;
case 45:
v10 = 0;
printf("\\-");
v9 = 0;
goto LABEL_15;
case 46:
if ( !v9 )
goto LABEL_14;
fprintf(
stderr,
"Error: *roff can't start a line with '.' If you used '&' or '^' to format text in the description of the"
" '%s' option, please add some text before the end of the sentence, so that a valid manpage can be generated.\n",
*a1);
break;
default:
goto LABEL_14;
}
exit(1);
}
LABEL_14:
putchar(v7);
v10 = 0;
v9 = 0;
LABEL_15:
v7 = *++v6;
}
while ( (_BYTE)v7 );
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(const char **a1)
{
const char *v2; // rsi
const unsigned __int16 **v3; // rax
__int64 v4; // rsi
int v5; // eax
const char *v6; // r14
int v7; // edi
int v8; // er12
int v9; // edx
int v10; // er15
int v11; // ebx
const char *v13; // rbx
int v14; // er12
const __int32_t *v15; // rsi
__int64 v16; // rax
__int64 v17; // rdx
char dest[112]; // [rsp+0h] [rbp-70h] BYREF

if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
{
v2 = a1[2];
if ( v2 )
{
strcpy(dest, v2);
}
else
{
v13 = *a1;
v14 = strlen(*a1);
if ( v14 > 0 )
{
v15 = *__ctype_toupper_loc();
v16 = 0LL;
do
{
dest[v16] = v15[v13[v16]];
v17 = v16++;
}
while ( v17 != v14 - 1 );
}
dest[v14] = 0;
}
}
printf(".TP\n.BI \"");
v3 = __ctype_b_loc();
v4 = *((int *)a1 + 2);
if ( ((*v3)[v4] & 0x400) != 0 )
{
printf("\\-%c", v4);
if ( (*((_BYTE *)a1 + 12) & 0xE) != 0 )
printf(" \" \"%s\" \"", dest);
printf(", ");
}
printf("\\-\\-%s", *a1);
v5 = *((_DWORD *)a1 + 3);
if ( (v5 & 0xE) != 0 )
{
printf("=\" \"%s", dest);
v5 = *((_DWORD *)a1 + 3);
if ( (v5 & 0x11) != 0 )
{
printf("\" \"");
v5 = *((_DWORD *)a1 + 3);
}
}
if ( (v5 & 0xF) == 1 || (v5 & 0x10) != 0 )
printf(", \\-\\-no\\-%s", *a1);
puts("\"");
v6 = a1[3];
if ( v6 )
{
v7 = *v6;
v8 = 0;
v9 = 1;
v10 = 0;
v11 = 0;
if ( *v6 )
{
do
{
if ( (char)v7 > 46 )
{
if ( (_BYTE)v7 == 94 )
{
if ( v11 )
putchar(10);
else
printf("\n.B ");
v9 = v11;
v10 = v11;
v11 ^= 1u;
goto LABEL_15;
}
}
else if ( (char)v7 > 9 )
{
switch ( (char)v7 )
{
case 10:
v10 = 0;
putchar(10);
v9 = 1;
goto LABEL_15;
case 32:
if ( !v10 )
{
putchar(32);
v9 = 0;
}
goto LABEL_15;
case 38:
if ( v8 )
putchar(10);
else
printf("\n.I ");
v9 = v8;
v10 = v8;
v8 ^= 1u;
goto LABEL_15;
case 39:
if ( !v9 )
goto LABEL_14;
fprintf(
stderr,
"Error: *roff can't start a line with '''. If you started a line with ''' in the description of the '%s' "
"option, please add some text at the beginning of the sentence, so that a valid manpage can be generated.\n",
*a1);
break;
case 45:
v10 = 0;
printf("\\-");
v9 = 0;
goto LABEL_15;
case 46:
if ( !v9 )
goto LABEL_14;
fprintf(
stderr,
"Error: *roff can't start a line with '.' If you used '&' or '^' to format text in the description of the"
" '%s' option, please add some text before the end of the sentence, so that a valid manpage can be generated.\n",
*a1);
break;
default:
goto LABEL_14;
}
exit(1);
}
LABEL_14:
putchar(v7);
v10 = 0;
v9 = 0;
LABEL_15:
v7 = *++v6;
}
while ( (_BYTE)v7 );
}
}
return putchar(10);
}

original_code:
static void print_option(const NVGetoptOption *o)
{
    char scratch[64];
    const char *s;
    int j, len;
    int italics, bold, omitWhiteSpace, firstchar;
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        if (o->arg_name) {
            strcpy(scratch, o->arg_name);
        } else {
            len = strlen(o->name);
            for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]);
            scratch[len] = '\0';
        }
    }
    printf(".TP\n.BI \"");
    if (((*__ctype_b_loc ())[(int) ((o->val))] & (unsigned short int) _ISalpha)) {
        printf("\\-%c", o->val);
        if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
            printf(" \" \"%s\" \"", scratch);
        }
        printf(", ");
    }
    printf("\\-\\-%s", o->name);
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        printf("=\" \"%s", scratch);
        if ((o->flags & 0x0001) ||
            (o->flags & 0x0010)) {
            printf("\" \"");
        }
    }
    if (((o->flags & 0x0001) &&
         !(o->flags & (0x0002 | 0x0004 | 0x0008))) ||
        (o->flags & 0x0010)) {
        printf(", \\-\\-no\\-%s", o->name);
    }
    printf("\"\n");
    italics = 0;
    bold = 0;
    omitWhiteSpace = 0;
    firstchar = 1;
    for (s = o->description; s && *s; s++) {
        switch (*s) {
          case '&':
              if (italics) {
                  printf("\n");
              } else {
                  printf("\n.I ");
              }
              omitWhiteSpace = italics;
              firstchar = italics;
              italics = !italics;
              break;
          case '^':
              if (bold) {
                  printf("\n");
              } else {
                  printf("\n.B ");
              }
              omitWhiteSpace = bold;
              firstchar = bold;
              bold = !bold;
              break;
          case '-':
              printf("\\-");
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
          case ' ':
              if (!omitWhiteSpace) {
                  printf(" ");
                  firstchar = 0;
              }
              break;
          case '\n':
              printf("\n");
              omitWhiteSpace = 0;
              firstchar = 1;
              break;
          case '.':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '.' "
                          "If you used '&' or '^' to format text in the "
                          "description of the '%s' option, please add some "
                          "text before the end of the sentence, so that a "
                          "valid manpage can be generated.\n", o->name);
                  exit(1);
              }
          case '\'':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '\''. "
                          "If you started a line with '\'' in the description "
                          "of the '%s' option, please add some text at the "
                          "beginning of the sentence, so that a valid manpage "
                          "can be generated.\n", o->name);
                  exit(1);
              }
          default:
              printf("%c", *s);
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
        }
    }
    printf("\n");
}

canonical_original_code:
static void print_option(struct NVGetoptOption *o)
{
    char scratch[64];
    char *s;
    int j; int len;
    int italics; int bold; int omitWhiteSpace; int firstchar;
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        if (o->arg_name) {
            strcpy(scratch, o->arg_name);
        } else {
            len = strlen(o->name);
            for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]);
            scratch[len] = '\0';
        }
    }
    printf(".TP\n.BI \"");
    if (((*__ctype_b_loc ())[(int) ((o->val))] & (unsigned short) _ISalpha)) {
        printf("\\-%c", o->val);
        if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
            printf(" \" \"%s\" \"", scratch);
        }
        printf(", ");
    }
    printf("\\-\\-%s", o->name);
    if (o->flags & (0x0002 | 0x0004 | 0x0008)) {
        printf("=\" \"%s", scratch);
        if ((o->flags & 0x0001) ||
            (o->flags & 0x0010)) {
            printf("\" \"");
        }
    }
    if (((o->flags & 0x0001) &&
         !(o->flags & (0x0002 | 0x0004 | 0x0008))) ||
        (o->flags & 0x0010)) {
        printf(", \\-\\-no\\-%s", o->name);
    }
    printf("\"\n");
    italics = 0;
    bold = 0;
    omitWhiteSpace = 0;
    firstchar = 1;
    for (s = o->description; s && *s; s++) {
        switch (*s) {
          case '&':
              if (italics) {
                  printf("\n");
              } else {
                  printf("\n.I ");
              }
              omitWhiteSpace = italics;
              firstchar = italics;
              italics = !italics;
              break;
          case '^':
              if (bold) {
                  printf("\n");
              } else {
                  printf("\n.B ");
              }
              omitWhiteSpace = bold;
              firstchar = bold;
              bold = !bold;
              break;
          case '-':
              printf("\\-");
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
          case ' ':
              if (!omitWhiteSpace) {
                  printf(" ");
                  firstchar = 0;
              }
              break;
          case '\n':
              printf("\n");
              omitWhiteSpace = 0;
              firstchar = 1;
              break;
          case '.':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '.' "
                          "If you used '&' or '^' to format text in the "
                          "description of the '%s' option, please add some "
                          "text before the end of the sentence, so that a "
                          "valid manpage can be generated.\n", o->name);
                  exit(1);
              }
          case '\'':
              if (firstchar) {
                  fprintf(stderr, "Error: *roff can't start a line with '\''. "
                          "If you started a line with '\'' in the description "
                          "of the '%s' option, please add some text at the "
                          "beginning of the sentence, so that a valid manpage "
                          "can be generated.\n", o->name);
                  exit(1);
              }
          default:
              printf("%c", *s);
              omitWhiteSpace = 0;
              firstchar = 0;
              break;
        }
    }
    printf("\n");
}

variable_types: struct NVGetoptOption { char *name; int val; unsigned int flags; char *arg_name; char *description; } *

variable_types:
scratch
char [64]

variable_types:
s
char *

variable_types: j int

variable_types: len int

variable_types: italics int

variable_types: bold int

variable_types: omitWhiteSpace int

variable_types: firstchar int


decompiled_code:
int __fastcall gen_manpage_opts_helper(const char **a1)
{
const char **v1; // r12
int result; // eax
const char **v3; // rbx
int v4; // er13

v1 = a1;
result = puts(".SH OPTIONS");
if ( !*a1 )
return result;
v3 = a1;
v4 = 0;
do
{
while ( 1 )
{
if ( !v3[3] )
goto LABEL_4;
if ( (*((_BYTE *)v3 + 12) & 0x40) == 0 )
break;
result = print_option(v3);
LABEL_4:
v3 += 4;
if ( !*v3 )
goto LABEL_8;
}
v3 += 4;
v4 = 1;
}
while ( *v3 );
LABEL_8:
if ( v4 )
{
result = puts(".SH \"ADVANCED OPTIONS\"");
if ( *a1 )
{
do
{
if ( v1[3] )
{
if ( (*((_BYTE *)v1 + 12) & 0x40) == 0 )
result = print_option(v1);
}
v1 += 4;
}
while ( *v1 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char **a1)
{
const char **v1; // r12
int result; // eax
const char **v3; // rbx
int v4; // er13

v1 = a1;
result = puts(".SH OPTIONS");
if ( !*a1 )
return result;
v3 = a1;
v4 = 0;
do
{
while ( 1 )
{
if ( !v3[3] )
goto LABEL_4;
if ( (*((_BYTE *)v3 + 12) & 0x40) == 0 )
break;
result = func7(v3);
LABEL_4:
v3 += 4;
if ( !*v3 )
goto LABEL_8;
}
v3 += 4;
v4 = 1;
}
while ( *v3 );
LABEL_8:
if ( v4 )
{
result = puts(".SH \"ADVANCED OPTIONS\"");
if ( *a1 )
{
do
{
if ( v1[3] )
{
if ( (*((_BYTE *)v1 + 12) & 0x40) == 0 )
result = func7(v1);
}
v1 += 4;
}
while ( *v1 );
}
}
return result;
}

original_code:
void gen_manpage_opts_helper(const NVGetoptOption *options)
{
    int i;
    int has_advanced_options = 0;
    printf(".SH OPTIONS\n");
    for (i = 0; options[i].name; i++) {
        const NVGetoptOption *o = &options[i];
        if (!o->description) {
            continue;
        }
        if (!(o->flags & 0x0040)) {
            has_advanced_options = 1;
            continue;
        }
        print_option(o);
    }
    if (has_advanced_options) {
        printf(".SH \"ADVANCED OPTIONS\"\n");
        for (i = 0; options[i].name; i++) {
            const NVGetoptOption *o = &options[i];
            if (!o->description) {
                continue;
            }
            if (o->flags & 0x0040) {
                continue;
            }
            print_option(o);
        }
    }
}

canonical_original_code:
void gen_manpage_opts_helper(struct NVGetoptOption *options)
{
    int i;
    int has_advanced_options = 0;
    printf(".SH OPTIONS\n");
    for (i = 0; options[i].name; i++) {
        struct NVGetoptOption *o = &options[i];
        if (!o->description) {
            continue;
        }
        if (!(o->flags & 0x0040)) {
            has_advanced_options = 1;
            continue;
        }
        print_option(o);
    }
    if (has_advanced_options) {
        printf(".SH \"ADVANCED OPTIONS\"\n");
        for (i = 0; options[i].name; i++) {
            struct NVGetoptOption *o = &options[i];
            if (!o->description) {
                continue;
            }
            if (o->flags & 0x0040) {
                continue;
            }
            print_option(o);
        }
    }
}

variable_types: i int

user_defined_types: struct NVGetoptOption { char *name; int val; unsigned int flags; char *arg_name; char *description; }


decompiled_code:
__int64 open_libgl()
{
void **v0; // rbx
__int64 result; // rax
char *v2; // rax
void *v3; // rdi

v0 = (void **)_libGL;
if ( !_libGL )
{
_libGL = (void *)nvalloc(120LL);
v0 = (void **)_libGL;
}
if ( *v0 )
goto LABEL_4;
*v0 = dlopen("libGL.so.1", 1);
v0 = (void **)_libGL;
if ( *(_QWORD *)_libGL )
{
dlerror();
v0[2] = dlsym(*v0, "glGetString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[3] = dlsym(*v0, "glXQueryExtension");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[4] = dlsym(*v0, "glXQueryServerString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[5] = dlsym(*v0, "glXGetClientString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[6] = dlsym(*v0, "glXQueryExtensionsString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[7] = dlsym(*v0, "glXIsDirect");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[8] = dlsym(*v0, "glXMakeCurrent");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[9] = dlsym(*v0, "glXCreateContext");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[10] = dlsym(*v0, "glXDestroyContext");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[11] = dlsym(*v0, "glXChooseVisual");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[12] = dlsym(*v0, "glXGetFBConfigs");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[13] = dlsym(*v0, "glXGetFBConfigAttrib");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[14] = dlsym(*v0, "glXGetVisualFromFBConfig");
v2 = dlerror();
if ( !v2 )
{
LABEL_4:
++*((_DWORD *)v0 + 2);
return 1LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
LABEL_8:
nv_error_msg("libGL setup error : %s\n", v2);
v0 = (void **)_libGL;
result = 0LL;
if ( !_libGL )
return result;
goto LABEL_9;
}
v2 = dlerror();
if ( v2 )
goto LABEL_8;
LABEL_9:
if ( *v0 )
{
dlclose(*v0);
v3 = _libGL;
*(_QWORD *)_libGL = 0LL;
}
else
{
v3 = _libGL;
}
free(v3);
result = 0LL;
_libGL = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
void **v0; // rbx
__int64 result; // rax
char *v2; // rax
void *v3; // rdi

v0 = (void **)_libGL;
if ( !_libGL )
{
_libGL = (void *)nvalloc(120LL);
v0 = (void **)_libGL;
}
if ( *v0 )
goto LABEL_4;
*v0 = dlopen("libGL.so.1", 1);
v0 = (void **)_libGL;
if ( *(_QWORD *)_libGL )
{
dlerror();
v0[2] = dlsym(*v0, "glGetString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[3] = dlsym(*v0, "glXQueryExtension");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[4] = dlsym(*v0, "glXQueryServerString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[5] = dlsym(*v0, "glXGetClientString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[6] = dlsym(*v0, "glXQueryExtensionsString");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[7] = dlsym(*v0, "glXIsDirect");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[8] = dlsym(*v0, "glXMakeCurrent");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[9] = dlsym(*v0, "glXCreateContext");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[10] = dlsym(*v0, "glXDestroyContext");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[11] = dlsym(*v0, "glXChooseVisual");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[12] = dlsym(*v0, "glXGetFBConfigs");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[13] = dlsym(*v0, "glXGetFBConfigAttrib");
v2 = dlerror();
if ( !v2 )
{
dlerror();
v0[14] = dlsym(*v0, "glXGetVisualFromFBConfig");
v2 = dlerror();
if ( !v2 )
{
LABEL_4:
++*((_DWORD *)v0 + 2);
return 1LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
LABEL_8:
nv_error_msg("libGL setup error : %s\n", v2);
v0 = (void **)_libGL;
result = 0LL;
if ( !_libGL )
return result;
goto LABEL_9;
}
v2 = dlerror();
if ( v2 )
goto LABEL_8;
LABEL_9:
if ( *v0 )
{
dlclose(*v0);
v3 = _libGL;
*(_QWORD *)_libGL = 0LL;
}
else
{
v3 = _libGL;
}
free(v3);
result = 0LL;
_libGL = 0LL;
return result;
}

original_code:
static int open_libgl(void)
{
    const char *error_str = ((void *)0);
    if ( !__libGL ) {
        __libGL = nvalloc(sizeof(__libGLInfo));
    }
    if ( __libGL->handle ) {
        __libGL->ref_count++;
        return 1;
    }
    __libGL->handle = dlopen("libGL.so.1", 0x00001);
    if ( !__libGL->handle ) {
        error_str = dlerror();
        goto fail;
    }
    __libGL->glGetString =
        ({ dlerror(); dlsym(__libGL->handle, "glGetString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtension =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtension"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryServerString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryServerString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetClientString =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetClientString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtensionsString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtensionsString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXIsDirect =
        ({ dlerror(); dlsym(__libGL->handle, "glXIsDirect"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXMakeCurrent =
        ({ dlerror(); dlsym(__libGL->handle, "glXMakeCurrent"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXCreateContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXCreateContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXDestroyContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXDestroyContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXChooseVisual =
        ({ dlerror(); dlsym(__libGL->handle, "glXChooseVisual"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigs =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigs"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigAttrib =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigAttrib"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetVisualFromFBConfig =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetVisualFromFBConfig"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libGL setup error : %s\n", error_str);
    }
    if ( __libGL ) {
        if ( __libGL->handle ) {
            dlclose(__libGL->handle);
            __libGL->handle = ((void *)0);
        }
        free(__libGL);
        __libGL = ((void *)0);
    }
    return 0;
}

canonical_original_code:
static int open_libgl()
{
    char *error_str = ((void *)0);
    if ( !__libGL ) {
        __libGL = nvalloc(sizeof(__libGLInfo));
    }
    if ( __libGL->handle ) {
        __libGL->ref_count++;
        return 1;
    }
    __libGL->handle = dlopen("libGL.so.1", 0x00001);
    if ( !__libGL->handle ) {
        error_str = dlerror();
        goto fail;
    }
    __libGL->glGetString =
        ({ dlerror(); dlsym(__libGL->handle, "glGetString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtension =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtension"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryServerString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryServerString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetClientString =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetClientString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXQueryExtensionsString =
        ({ dlerror(); dlsym(__libGL->handle, "glXQueryExtensionsString"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXIsDirect =
        ({ dlerror(); dlsym(__libGL->handle, "glXIsDirect"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXMakeCurrent =
        ({ dlerror(); dlsym(__libGL->handle, "glXMakeCurrent"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXCreateContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXCreateContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXDestroyContext =
        ({ dlerror(); dlsym(__libGL->handle, "glXDestroyContext"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXChooseVisual =
        ({ dlerror(); dlsym(__libGL->handle, "glXChooseVisual"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigs =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigs"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetFBConfigAttrib =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetFBConfigAttrib"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->glXGetVisualFromFBConfig =
        ({ dlerror(); dlsym(__libGL->handle, "glXGetVisualFromFBConfig"); });
    if ((error_str = dlerror()) != ((void *)0)) goto fail;
    __libGL->ref_count++;
    return 1;
 fail:
    if ( error_str ) {
        nv_error_msg("libGL setup error : %s\n", error_str);
    }
    if ( __libGL ) {
        if ( __libGL->handle ) {
            dlclose(__libGL->handle);
            __libGL->handle = ((void *)0);
        }
        free(__libGL);
        __libGL = ((void *)0);
    }
    return 0;
}


decompiled_code:
void *close_libgl()
{
void *result; // rax
int v1; // edx
int v2; // edx

result = _libGL;
if ( _libGL )
{
if ( *(_QWORD *)_libGL )
{
v1 = *((_DWORD *)_libGL + 2);
if ( v1 )
{
v2 = v1 - 1;
*((_DWORD *)_libGL + 2) = v2;
if ( !v2 )
result = (void *)sub_2F8();
}
}
}
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax
int v1; // edx
int v2; // edx

result = _libGL;
if ( _libGL )
{
if ( *(_QWORD *)_libGL )
{
v1 = *((_DWORD *)_libGL + 2);
if ( v1 )
{
v2 = v1 - 1;
*((_DWORD *)_libGL + 2) = v2;
if ( !v2 )
result = (void *)sub_2F8();
}
}
}
return result;
}

original_code:
static void close_libgl(void)
{
    if ( __libGL && __libGL->handle && __libGL->ref_count ) {
        __libGL->ref_count--;
        if ( __libGL->ref_count == 0 ) {
            dlclose(__libGL->handle);
            __libGL->handle = ((void *)0);
            free(__libGL);
            __libGL = ((void *)0);
        }
    }
}

canonical_original_code:
static void close_libgl()
{
    if ( __libGL && __libGL->handle && __libGL->ref_count ) {
        __libGL->ref_count--;
        if ( __libGL->ref_count == 0 ) {
            dlclose(__libGL->handle);
            __libGL->handle = ((void *)0);
            free(__libGL);
            __libGL = ((void *)0);
        }
    }
}


decompiled_code:
int __fastcall print_target_indices(const char *a1, int *a2)
{
int result; // eax
__int64 v3; // rbx
__int64 v4; // rdx

result = *a2;
if ( *a2 > 0 )
{
v3 = 1LL;
while ( 1 )
{
v4 = (unsigned int)a2[v3++];
result = printf("%s-%d", a1, v4);
if ( *a2 < (int)v3 )
break;
printf(", ");
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, int *a2)
{
int result; // eax
__int64 v3; // rbx
__int64 v4; // rdx

result = *a2;
if ( *a2 > 0 )
{
v3 = 1LL;
while ( 1 )
{
v4 = (unsigned int)a2[v3++];
result = printf("%s-%d", a1, v4);
if ( *a2 < (int)v3 )
break;
printf(", ");
}
}
return result;
}

original_code:
static void print_target_indices(const char *prefix, const int *pData)
{
    int i, first = 1;
    for (i = 1; i <= pData[0]; i++) {
        if (!first) {
            printf(", ");
        }
        first = 0;
        printf("%s-%d", prefix, pData[i]);
    }
}

canonical_original_code:
static void print_target_indices(char *prefix, int *pData)
{
    int i; int first = 1;
    for (i = 1; i <= pData[0]; i++) {
        if (!first) {
            printf(", ");
        }
        first = 0;
        printf("%s-%d", prefix, pData[i]);
    }
}

variable_types:
prefix
char *

variable_types:
pData
int *

variable_types: first int


decompiled_code:
int __fastcall print_cooler_target_indices(int *a1)
{
return print_target_indices("COOLER", a1);
}

canonical_decompiled_code:
int __fastcall func1(int *a1)
{
return func0("COOLER", a1);
}

original_code:
static void print_cooler_target_indices(const int *pData)
{
    print_target_indices("COOLER", pData);
}

canonical_original_code:
static void print_cooler_target_indices(int *pData)
{
    print_target_indices("COOLER", pData);
}


decompiled_code:
int __fastcall print_thermal_sensor_target_indices(int *a1)
{
return print_target_indices("THERMAL-SENSOR", a1);
}

canonical_decompiled_code:
int __fastcall func2(int *a1)
{
return func0("THERMAL-SENSOR", a1);
}

original_code:
static void print_thermal_sensor_target_indices(const int *pData)
{
    print_target_indices("THERMAL-SENSOR", pData);
}

canonical_original_code:
static void print_thermal_sensor_target_indices(int *pData)
{
    print_target_indices("THERMAL-SENSOR", pData);
}


decompiled_code:
int __fastcall print_framelock_target_indices(int *a1)
{
return print_target_indices("FRAMELOCK", a1);
}

canonical_decompiled_code:
int __fastcall func3(int *a1)
{
return func0("FRAMELOCK", a1);
}

original_code:
static void print_framelock_target_indices(const int *pData)
{
    print_target_indices("FRAMELOCK", pData);
}

canonical_original_code:
static void print_framelock_target_indices(int *pData)
{
    print_target_indices("FRAMELOCK", pData);
}


decompiled_code:
int __fastcall print_display_device_target_indices(int *a1)
{
return print_target_indices("DPY", a1);
}

canonical_decompiled_code:
int __fastcall func4(int *a1)
{
return func0("DPY", a1);
}

original_code:
static void print_display_device_target_indices(const int *pData)
{
    print_target_indices("DPY", pData);
}

canonical_original_code:
static void print_display_device_target_indices(int *pData)
{
    print_target_indices("DPY", pData);
}