decompiled_code:
__int64 __fastcall client_connect(char *name, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
struct hostent *v4; // rax
socklen_t v5; // edx
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("Creation socket failed");
exit(1);
}
v3 = v2;
v4 = gethostbyname(name);
if ( !v4 )
{
perror("Hostname error");
exit(1);
}
v7[0] = 0LL;
v7[0].sa_family = 2;
memmove(&v7[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)v7[0].sa_data = _bswap_16(a2);
if ( connect(v3, v7, v5) < 0 )
{
perror("Connection error");
exit(1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *name, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
struct hostent *v4; // rax
socklen_t v5; // edx
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("Creation socket failed");
exit(1);
}
v3 = v2;
v4 = gethostbyname(name);
if ( !v4 )
{
perror("Hostname error");
exit(1);
}
v7[0] = 0LL;
v7[0].sa_family = 2;
memmove(&v7[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)v7[0].sa_data = func7(a2);
if ( connect(v3, v7, v5) < 0 )
{
perror("Connection error");
exit(1);
}
return v3;
}

original_code:
int client_connect(const char * hostname, int port)
{
    struct sockaddr_in serv_addr;
    struct hostent *server;
    int sockfd = socket(2, SOCK_STREAM, 0);
    if (sockfd < 0) {
        do { perror("Creation socket failed"); exit(1); } while (0);
    }
    server = gethostbyname(hostname);
    if (server == ((void *)0)) {
        do { perror("Hostname error"); exit(1); } while (0);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    bcopy((char *)server->h_addr_list[0], (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(port);
    if (connect(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) {
        do { perror("Connection error"); exit(1); } while (0);
    }
    return sockfd;
}

canonical_original_code:
int client_connect(char *hostname, int port)
{
    struct sockaddr_in serv_addr;
    struct hostent *server;
    int sockfd = socket(2, SOCK_STREAM, 0);
    if (sockfd < 0) {
        do { perror("Creation socket failed"); exit(1); } while (0);
    }
    server = gethostbyname(hostname);
    if (server == ((void *)0)) {
        do { perror("Hostname error"); exit(1); } while (0);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    bcopy((char *)server->h_addr_list[0], (char *)&serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(port);
    if (connect(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) {
        do { perror("Connection error"); exit(1); } while (0);
    }
    return sockfd;
}

variable_types:
hostname
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
ssize_t __fastcall client_getfile(int fd, const char *a2, const char *a3)
{
int v3; // eax
FILE *v4; // rsi
ssize_t result; // rax
char v6[1032]; // [rsp+0h] [rbp-408h] BYREF

v3 = snprintf(v6, 0x3FFuLL, "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", a2, a3);
write(fd, v6, v3);
while ( 1 )
{
result = read(fd, v6, 0x3FFuLL);
if ( (int)result <= 0 )
break;
v4 = stdout;
v6[(int)result] = 0;
fputs(v6, v4);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func9(int fd, const char *a2, const char *a3)
{
int v3; // eax
FILE *v4; // rsi
ssize_t result; // rax
char v6[1032]; // [rsp+0h] [rbp-408h] BYREF

v3 = snprintf(v6, 0x3FFuLL, "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", a2, a3);
write(fd, v6, v3);
while ( 1 )
{
result = read(fd, v6, 0x3FFuLL);
if ( (int)result <= 0 )
break;
v4 = stdout;
v6[(int)result] = 0;
fputs(v6, v4);
}
return result;
}

original_code:
void client_getfile(int sock, const char* file, const char* hostname) {
    int n;
    char buf[1024];
    int writen = snprintf(buf, sizeof(buf) - 1, "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", file, hostname);
    write(sock, buf, writen);
    while ( (n = read(sock, buf, sizeof(buf) - 1) ) > 0 )
    {
        buf[n] = 0;
        fputs(buf, stdout);
    }
}

canonical_original_code:
void client_getfile(int sock, char *file, char *hostname) {
    int n;
    char buf[1024];
    int writen = snprintf(buf, sizeof(buf) - 1, "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", file, hostname);
    write(sock, buf, writen);
    while ( (n = read(sock, buf, sizeof(buf) - 1) ) > 0 )
    {
        buf[n] = 0;
        fputs(buf, stdout);
    }
}

variable_types: sock int

variable_types:
file
char *

variable_types: n int

variable_types:
buf
char [1024]

variable_types: writen int

return_type: void


decompiled_code:
// attributes: thunk
int client_disconnect(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func10(int fd)
{
return close(fd);
}

original_code:
void client_disconnect(int sockfd)
{
    close(sockfd);
}

variable_types: sockfd int


main

canonical_name: main

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

if ( argc <= 3 )
{
fwrite("Usage: get <hostname> <port> <file>", 1uLL, 0x23uLL, stderr);
exit(1);
}
atoi(argv[2]);
v3 = client_connect((char *)argv[1]);
client_getfile(v3);
client_disconnect(v3);
return 0;
}

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

if ( argc <= 3 )
{
fwrite("Usage: get <hostname> <port> <file>", 1uLL, 0x23uLL, stderr);
exit(1);
}
atoi(argv[2]);
v3 = func8((char *)argv[1]);
func9(v3);
func10(v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int sockfd;
    if (argc < 4) {
        fputs("Usage: get <hostname> <port> <file>", stderr);
        exit(1);
    }
    sockfd = client_connect(argv[1], atoi(argv[2]));
    client_getfile(sockfd, argv[3], argv[1]);
    client_disconnect(sockfd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


configureOptions

repo: qwc/cmdlineoptions

decompiled_code:
__int64 configureOptions()
{
CmdLO_Init();
CmdLO_Add();
CmdLO_Add();
return CmdLO_AddDescription();
}

canonical_decompiled_code:
__int64 func7()
{
CmdLO_Init();
CmdLO_Add();
CmdLO_Add();
return CmdLO_AddDescription();
}

original_code:
void configureOptions() {
 CmdLO_Init(1);
 CmdLO_Add("test","--test");
 CmdLO_Add("test","-t");
 CmdLO_AddDescription("test", "This is a test Option.");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
configureOptions(argc, argv, envp);
CmdLO_Parse();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
CmdLO_Parse();
return 0;
}

original_code:
int main(int argc, char** argv) {
 configureOptions();
 CmdLO_Parse(argc,argv);
}

canonical_original_code:
int main(int argc, char **argv) {
 configureOptions();
 CmdLO_Parse(argc,argv);
}

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall CmdLO_IsSet(char *a1)
{
return (unsigned int)*((char *)CmdLO_Create(a1)[1] + 76);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
return (unsigned int)*((char *)CmdLO_Create(a1)[1] + 76);
}

original_code:
int CmdLO_IsSet(char* name) {
 CONode* node = CmdLO_Create(name);
 return node->option->set;
}

canonical_original_code:
int CmdLO_IsSet(char *name) {
 struct _CONode *node = CmdLO_Create(name);
 return node->option->set;
}

variable_types:
name
char *

variable_types: struct _CONode { struct _CONode *next; struct _Option { char *name; char **options; unsigned int optionscount; char **possibleparameters; unsigned int possibleparametercount; char *description; char **defaultparameters; unsigned int defaultparametercount; char **values; unsigned int valuecount; char set; } *option; } *

user_defined_types: struct _CONode { struct _CONode *next; struct _Option *option; }


decompiled_code:
__int64 __fastcall CmdLO_Get(char *a1)
{
__int64 **v1; // rbx
int v2; // er8
__int64 result; // rax
__int64 *v4; // rdx

v1 = CmdLO_Create(a1);
v2 = CmdLO_IsSet(a1);
result = 0LL;
if ( v2 )
{
v4 = v1[1];
if ( *((_DWORD *)v4 + 18) )
result = *(_QWORD *)v4[8];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
__int64 **v1; // rbx
int v2; // er8
__int64 result; // rax
__int64 *v4; // rdx

v1 = CmdLO_Create(a1);
v2 = func0(a1);
result = 0LL;
if ( v2 )
{
v4 = v1[1];
if ( *((_DWORD *)v4 + 18) )
result = *(_QWORD *)v4[8];
}
return result;
}

original_code:
char* CmdLO_Get(char* name) {
 CONode* node = CmdLO_Create(name);
 if (CmdLO_IsSet(name) && node->option->valuecount > 0)
  return node->option->values[0];
 return 0;
}

canonical_original_code:
char *CmdLO_Get(char *name) {
 struct _CONode *node = CmdLO_Create(name);
 if (CmdLO_IsSet(name) && node->option->valuecount > 0)
  return node->option->values[0];
 return 0;
}

return_type: char *

user_defined_types: struct _Option { char *name; char **options; unsigned int optionscount; char **possibleparameters; unsigned int possibleparametercount; char *description; char **defaultparameters; unsigned int defaultparametercount; char **values; unsigned int valuecount; char set; }


decompiled_code:
int __fastcall CmdLO_GetInt(char *a1)
{
const char *v1; // rax

v1 = (const char *)CmdLO_Get(a1);
return atoi(v1);
}

canonical_decompiled_code:
int __fastcall func2(char *a1)
{
const char *v1; // rax

v1 = (const char *)func1(a1);
return atoi(v1);
}

original_code:
int CmdLO_GetInt(char* name) {
 return atoi(CmdLO_Get(name));
}

canonical_original_code:
int CmdLO_GetInt(char *name) {
 return atoi(CmdLO_Get(name));
}


decompiled_code:
__int64 __fastcall CmdLO_GetLong(char *a1)
{
const char *v1; // rax

v1 = (const char *)CmdLO_Get(a1);
return atol(v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
const char *v1; // rax

v1 = (const char *)func1(a1);
return atol(v1);
}

original_code:
long CmdLO_GetLong(char* name) {
 return atol(CmdLO_Get(name));
}

canonical_original_code:
long CmdLO_GetLong(char *name) {
 return atol(CmdLO_Get(name));
}

return_type: long


decompiled_code:
void __fastcall CmdLO_GetDouble(char *a1)
{
const char *v1; // rax

v1 = (const char *)CmdLO_Get(a1);
atof(v1);
}

canonical_decompiled_code:
void __fastcall func4(char *a1)
{
const char *v1; // rax

v1 = (const char *)func1(a1);
atof(v1);
}

original_code:
double CmdLO_GetDouble(char* name) {
 return atof(CmdLO_Get(name));
}

canonical_original_code:
double CmdLO_GetDouble(char *name) {
 return atof(CmdLO_Get(name));
}

return_type: double


decompiled_code:
__int64 __fastcall CmdLO_GetAll(char *a1, __int64 a2, _DWORD *a3)
{
__int64 **v4; // rax

v4 = CmdLO_Create(a1);
if ( !v4 )
return 1LL;
*a3 = *((_DWORD *)v4[1] + 18);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2, _DWORD *a3)
{
__int64 **v4; // rax

v4 = CmdLO_Create(a1);
if ( !v4 )
return 1LL;
*a3 = *((_DWORD *)v4[1] + 18);
return 0LL;
}

original_code:
int CmdLO_GetAll(char* name, char** values, unsigned int* count) {
 CONode* node = CmdLO_Create(name);
 if (node == 0)
  return 1;
 values = node->option->values;
 *count = node->option->valuecount;
 return 0;
}

canonical_original_code:
int CmdLO_GetAll(char *name, char **values, unsigned int *count) {
 struct _CONode *node = CmdLO_Create(name);
 if (node == 0)
  return 1;
 values = node->option->values;
 *count = node->option->valuecount;
 return 0;
}

variable_types:
values
char **

variable_types:
count
unsigned int *


decompiled_code:
void __fastcall CmdLO_AddElement(void **a1, _DWORD *a2, const char *a3)
{
__int64 v4; // rbx
void *v5; // r15
void *v6; // rax
_QWORD *v7; // r14
size_t v8; // r12
void *v9; // rax
size_t v10; // r12
void *v11; // rax

v4 = (unsigned int)*a2;
v5 = *a1;
v6 = malloc(8LL * (unsigned int)(v4 + 1));
*a1 = v6;
v7 = v6;
if ( v5 )
{
memcpy(v6, v5, 8 * v4);
v8 = strlen(a3) + 1;
v9 = malloc(v8);
v7[v4] = v9;
memcpy(v9, a3, v8);
free(v5);
}
else
{
v10 = strlen(a3) + 1;
v11 = malloc(v10);
v7[v4] = v11;
memcpy(v11, a3, v10);
}
*a2 = v4 + 1;
}

canonical_decompiled_code:
void __fastcall func6(void **a1, _DWORD *a2, const char *a3)
{
__int64 v4; // rbx
void *v5; // r15
void *v6; // rax
_QWORD *v7; // r14
size_t v8; // r12
void *v9; // rax
size_t v10; // r12
void *v11; // rax

v4 = (unsigned int)*a2;
v5 = *a1;
v6 = malloc(8LL * (unsigned int)(v4 + 1));
*a1 = v6;
v7 = v6;
if ( v5 )
{
memcpy(v6, v5, 8 * v4);
v8 = strlen(a3) + 1;
v9 = malloc(v8);
v7[v4] = v9;
memcpy(v9, a3, v8);
free(v5);
}
else
{
v10 = strlen(a3) + 1;
v11 = malloc(v10);
v7[v4] = v11;
memcpy(v11, a3, v10);
}
*a2 = v4 + 1;
}

original_code:
void CmdLO_AddElement(char*** target, unsigned int* counter, char* element) {
 unsigned int cnt = *counter;
 char** old = 0;
 if (*target != 0)
  old = *target;
 *target = malloc((cnt + 1) * sizeof(char*));
 if (old != 0)
  memcpy(*target, old, (cnt) * sizeof(char*));
 *(*target + cnt) = malloc((strlen(element) + 1) * sizeof(char));
 memcpy(*(*target + cnt), element, strlen(element) + 1);
 if (old != 0)
  free(old);
 *counter = cnt + 1;
}

canonical_original_code:
void CmdLO_AddElement(char ***target, unsigned int *counter, char *element) {
 unsigned int cnt = *counter;
 char **old = 0;
 if (*target != 0)
  old = *target;
 *target = malloc((cnt + 1) * sizeof(char *));
 if (old != 0)
  memcpy(*target, old, (cnt) * sizeof(char *));
 *(*target + cnt) = malloc((strlen(element) + 1) * sizeof(char));
 memcpy(*(*target + cnt), element, strlen(element) + 1);
 if (old != 0)
  free(old);
 *counter = cnt + 1;
}

variable_types:
target
char ***

variable_types:
counter
unsigned int *

variable_types:
element
char *

variable_types:
cnt
unsigned int

variable_types:
old
char **


decompiled_code:
void __fastcall CmdLO_Add(char *a1, const char *a2)
{
__int64 **v2; // rax

v2 = CmdLO_Create(a1);
CmdLO_AddElement((void **)v2[1] + 1, (_DWORD *)v2[1] + 4, a2);
}

canonical_decompiled_code:
void __fastcall func8(char *a1, const char *a2)
{
__int64 **v2; // rax

v2 = CmdLO_Create(a1);
func6((void **)v2[1] + 1, (_DWORD *)v2[1] + 4, a2);
}

original_code:
void CmdLO_Add(char* name, char* option) {
 CONode* node = CmdLO_Create(name);
 CmdLO_AddElement(&(node->option->options), &(node->option->optionscount),
   option);
}

canonical_original_code:
void CmdLO_Add(char *name, char *option) {
 struct _CONode *node = CmdLO_Create(name);
 CmdLO_AddElement(&(node->option->options), &(node->option->optionscount),
   option);
}

variable_types:
option
char *


decompiled_code:
void __fastcall CmdLO_InitCmd(char a1, char a2)
{
char v2; // al

if ( !cmdoptions )
{
v2 = a2;
cmdoptions = 1;
if ( !a2 )
v2 = 45;
*(&cmdoptions + 16) = v2;
if ( a1 )
{
CmdLO_Add("help", "--help");
CmdLO_Add("help", "-h");
CmdLO_Add("help", "-?");
CmdLO_AddDescription("help", (__int64)"Display the help text.");
}
}
}

canonical_decompiled_code:
void __fastcall func9(char a1, char a2)
{
char v2; // al

if ( !cmdoptions )
{
v2 = a2;
cmdoptions = 1;
if ( !a2 )
v2 = 45;
*(&cmdoptions + 16) = v2;
if ( a1 )
{
func8("help", "--help");
func8("help", "-h");
func8("help", "-?");
CmdLO_AddDescription("help", (__int64)"Display the help text.");
}
}
}

original_code:
void CmdLO_InitCmd(char addhelp, char cmdchar) {
 if (cmdoptions.init == 0) {
  cmdoptions.init = 1;
  if (cmdchar != 0)
   cmdoptions.cmdchar = cmdchar;
  else
   cmdoptions.cmdchar = '-';
  if (addhelp != 0) {
   CmdLO_Add("help", "--help");
   CmdLO_Add("help", "-h");
   CmdLO_Add("help", "-?");
   CmdLO_AddDescription("help", "Display the help text.");
  }
 }
}

variable_types: addhelp char

variable_types: cmdchar char


decompiled_code:
void __fastcall CmdLO_Init(char a1)
{
CmdLO_InitCmd(a1, 0);
}

canonical_decompiled_code:
void __fastcall func10(char a1)
{
func9(a1, 0);
}

original_code:
void CmdLO_Init(char addhelp) {
 CmdLO_InitCmd(addhelp, 0);
}


decompiled_code:
void __fastcall CmdLO_AddDefaultParameter(char *a1, const char *a2)
{
__int64 **v2; // rax

v2 = CmdLO_Create(a1);
CmdLO_AddElement((void **)v2[1] + 6, (_DWORD *)v2[1] + 14, a2);
}

canonical_decompiled_code:
void __fastcall func11(char *a1, const char *a2)
{
__int64 **v2; // rax

v2 = CmdLO_Create(a1);
func6((void **)v2[1] + 6, (_DWORD *)v2[1] + 14, a2);
}

original_code:
void CmdLO_AddDefaultParameter(char* name, char* defaultparameter) {
 CONode* node = CmdLO_Create(name);
 CmdLO_AddElement(&(node->option->defaultparameters),
   &(node->option->defaultparametercount), defaultparameter);
}

canonical_original_code:
void CmdLO_AddDefaultParameter(char *name, char *defaultparameter) {
 struct _CONode *node = CmdLO_Create(name);
 CmdLO_AddElement(&(node->option->defaultparameters),
   &(node->option->defaultparametercount), defaultparameter);
}

variable_types:
defaultparameter
char *


decompiled_code:
void __fastcall CmdLO_AddPossibleParameter(char *a1, const char *a2)
{
__int64 **v2; // rax

v2 = CmdLO_Create(a1);
CmdLO_AddElement((void **)v2[1] + 3, (_DWORD *)v2[1] + 8, a2);
}

canonical_decompiled_code:
void __fastcall func12(char *a1, const char *a2)
{
__int64 **v2; // rax

v2 = CmdLO_Create(a1);
func6((void **)v2[1] + 3, (_DWORD *)v2[1] + 8, a2);
}

original_code:
void CmdLO_AddPossibleParameter(char* name, char* possibleParameter) {
 CONode* node = CmdLO_Create(name);
 CmdLO_AddElement(&(node->option->possibleparameters),
   &(node->option->possibleparametercount), possibleParameter);
}

canonical_original_code:
void CmdLO_AddPossibleParameter(char *name, char *possibleParameter) {
 struct _CONode *node = CmdLO_Create(name);
 CmdLO_AddElement(&(node->option->possibleparameters),
   &(node->option->possibleparametercount), possibleParameter);
}

variable_types:
possibleParameter
char *


original_code:
void CmdLO_Destroy() {
 CONode * node = cmdoptions.options;
 int i = 0;
 while (node != 0) {
  if (node->option->optionscount > 0) {
   i = 0;
   for (; i < node->option->optionscount; ++i)
    free(node->option->options[i]);
   free(node->option->options);
  }
  if (node->option->defaultparametercount > 0) {
   i = 0;
   for (; i < node->option->defaultparametercount; ++i)
    free(node->option->defaultparameters[i]);
   free(node->option->defaultparameters);
  }
  if (node->option->possibleparametercount > 0) {
   i = 0;
   for (; i < node->option->possibleparametercount; ++i)
    free(node->option->possibleparameters[i]);
   free(node->option->possibleparameters);
  }
  if (node->option->valuecount > 0) {
   i = 0;
   for (; i < node->option->valuecount; ++i)
    free(node->option->values[i]);
   free(node->option->values);
  }
  free(node->option);
  CONode* old = node;
  node = node->next;
  free(old);
 }
 cmdoptions.options = 0;
 cmdoptions.init = 0;
}

canonical_original_code:
void CmdLO_Destroy() {
 struct _CONode *node = cmdoptions.options;
 int i = 0;
 while (node != 0) {
  if (node->option->optionscount > 0) {
   i = 0;
   for (; i < node->option->optionscount; ++i)
    free(node->option->options[i]);
   free(node->option->options);
  }
  if (node->option->defaultparametercount > 0) {
   i = 0;
   for (; i < node->option->defaultparametercount; ++i)
    free(node->option->defaultparameters[i]);
   free(node->option->defaultparameters);
  }
  if (node->option->possibleparametercount > 0) {
   i = 0;
   for (; i < node->option->possibleparametercount; ++i)
    free(node->option->possibleparameters[i]);
   free(node->option->possibleparameters);
  }
  if (node->option->valuecount > 0) {
   i = 0;
   for (; i < node->option->valuecount; ++i)
    free(node->option->values[i]);
   free(node->option->values);
  }
  free(node->option);
  struct _CONode *old = node;
  node = node->next;
  free(old);
 }
 cmdoptions.options = 0;
 cmdoptions.init = 0;
}

variable_types: i int


repo: qzchenwl/hashtable

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned __int64 v4; // rbx
_QWORD *v5; // r13
unsigned __int64 *v6; // r12
unsigned __int64 v7; // r14
unsigned int v8; // ebp
__int64 v9; // rsi
_BYTE *v10; // rax
unsigned __int64 v11; // rdx
int v12; // eax
unsigned __int64 v13; // r13
unsigned int v14; // ebp
__int64 v15; // rbx
size_t n[6]; // [rsp+4h] [rbp-34h] BYREF

*(size_t *)((char *)n + 4) = 0LL;
LODWORD(n[0]) = 0;
if ( argc )
{
if ( argc != 3 )
{
help(argc, argv, envp);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = malloc(0x18uLL);
v6 = (unsigned __int64 *)hashtbl_create(v3);
printf("tbl = %p\n", v6);
if ( v4 <= 1 )
{
v8 = 0;
goto LABEL_11;
}
}
else
{
v4 = 1000LL;
v5 = malloc(0x18uLL);
v6 = (unsigned __int64 *)hashtbl_create(0x3F5uLL);
printf("tbl = %p\n", v6);
}
v7 = 1LL;
v8 = 0;
do
{
while ( 1 )
{
v12 = getline((char **)((char *)n + 4), n, stdin);
if ( v12 != -1 )
break;
++v7;
fwrite("getline() failed\n", 1uLL, 0x11uLL, stderr);
if ( v7 >= v4 )
goto LABEL_11;
}
v9 = *(size_t *)((char *)n + 4);
if ( v12 > 0 )
{
v10 = (_BYTE *)(*(size_t *)((char *)n + 4) + v12 - 1);
if ( *v10 == 10 )
{
*v10 = 0;
v9 = *(size_t *)((char *)n + 4);
}
}
*v5 = v9;
v11 = v7++;
++v8;
hashtbl_insert(v6, v9, v11);
}
while ( v7 < v4 );
LABEL_11:
printf("insert %d elements\n", v8);
printf("ele cnt = %d\n", v6[1]);
hashtbl_remove(v6, "www.domain3912.com");
hashtbl_remove(v6, "www.domain92492.com");
hashtbl_remove(v6, "www.domain77224.com");
hashtbl_remove(v6, "www.domain68464.com");
hashtbl_remove(v6, "www.domain12497.com");
hashtbl_remove(v6, "www.domain43997.com");
printf("ele cnt = %d\n", v6[1]);
if ( *v6 )
{
v13 = 0LL;
v14 = 0;
do
{
v15 = *(_QWORD *)(v6[2] + 8 * v13);
if ( v15 )
{
--v14;
do
{
++v14;
fprintf(stderr, "%s:%d\n", *(const char **)v15, *(unsigned int *)(v15 + 8));
v15 = *(_QWORD *)(v15 + 16);
}
while ( v15 );
}
++v13;
}
while ( *v6 > v13 );
}
else
{
v14 = 0;
}
printf("tbl %d collisions\n", v14);
hashtbl_dump(v6, stdout);
if ( *(size_t *)((char *)n + 4) )
free(*(void **)((char *)n + 4));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned __int64 v4; // rbx
_QWORD *v5; // r13
unsigned __int64 *v6; // r12
unsigned __int64 v7; // r14
unsigned int v8; // ebp
__int64 v9; // rsi
_BYTE *v10; // rax
unsigned __int64 v11; // rdx
int v12; // eax
unsigned __int64 v13; // r13
unsigned int v14; // ebp
__int64 v15; // rbx
size_t n[6]; // [rsp+4h] [rbp-34h] BYREF

*(size_t *)((char *)n + 4) = 0LL;
LODWORD(n[0]) = 0;
if ( argc )
{
if ( argc != 3 )
{
func15(argc, argv, envp);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = malloc(0x18uLL);
v6 = (unsigned __int64 *)hashtbl_create(v3);
printf("tbl = %p\n", v6);
if ( v4 <= 1 )
{
v8 = 0;
goto LABEL_11;
}
}
else
{
v4 = 1000LL;
v5 = malloc(0x18uLL);
v6 = (unsigned __int64 *)hashtbl_create(0x3F5uLL);
printf("tbl = %p\n", v6);
}
v7 = 1LL;
v8 = 0;
do
{
while ( 1 )
{
v12 = getline((char **)((char *)n + 4), n, stdin);
if ( v12 != -1 )
break;
++v7;
fwrite("getline() failed\n", 1uLL, 0x11uLL, stderr);
if ( v7 >= v4 )
goto LABEL_11;
}
v9 = *(size_t *)((char *)n + 4);
if ( v12 > 0 )
{
v10 = (_BYTE *)(*(size_t *)((char *)n + 4) + v12 - 1);
if ( *v10 == 10 )
{
*v10 = 0;
v9 = *(size_t *)((char *)n + 4);
}
}
*v5 = v9;
v11 = v7++;
++v8;
func12(v6, v9, v11);
}
while ( v7 < v4 );
LABEL_11:
printf("insert %d elements\n", v8);
printf("ele cnt = %d\n", v6[1]);
func9(v6, "www.domain3912.com");
func9(v6, "www.domain92492.com");
func9(v6, "www.domain77224.com");
func9(v6, "www.domain68464.com");
func9(v6, "www.domain12497.com");
func9(v6, "www.domain43997.com");
printf("ele cnt = %d\n", v6[1]);
if ( *v6 )
{
v13 = 0LL;
v14 = 0;
do
{
v15 = *(_QWORD *)(v6[2] + 8 * v13);
if ( v15 )
{
--v14;
do
{
++v14;
fprintf(stderr, "%s:%d\n", *(const char **)v15, *(unsigned int *)(v15 + 8));
v15 = *(_QWORD *)(v15 + 16);
}
while ( v15 );
}
++v13;
}
while ( *v6 > v13 );
}
else
{
v14 = 0;
}
printf("tbl %d collisions\n", v14);
func13(v6, stdout);
if ( *(size_t *)((char *)n + 4) )
free(*(void **)((char *)n + 4));
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
    HASHTBL *tbl;
    ENTRY *entry;
    HSIZE tblsiz, elecnt;
    char *line = ((void *)0);
    int ret, i, cnt, len = 0;
    if (argc == 0) {
        tblsiz = 1013;
        elecnt = 1000;
    }
    else if (argc != 3) {
        help(argc, argv);
        exit(1);
    }
    else {
        tblsiz = atoi(argv[1]);
        elecnt = atoi(argv[2]);
    }
    entry = malloc(sizeof(ENTRY));
    tbl = hashtbl_create(tblsiz, ((void *)0));
    printf("tbl = %p\n", tbl);
    for (i = 1, cnt = 0; i < elecnt; ++i) {
        if ( (ret = getline(&line, &len, stdin)) == -1) {
            fprintf(stderr, "getline() failed\n");
            continue;
        }
        if ( ret > 0 && line[ret-1] == '\n')
            line[ret-1] = '\0';
        entry->key = line;
        hashtbl_insert(tbl, entry->key, (void*)i);
        ++cnt;
    }
    printf("insert %d elements\n", cnt);
    printf("ele cnt = %d\n", tbl->count);
    hashtbl_remove(tbl, "www.domain3912.com");
    hashtbl_remove(tbl, "www.domain92492.com");
    hashtbl_remove(tbl, "www.domain77224.com");
    hashtbl_remove(tbl, "www.domain68464.com");
    hashtbl_remove(tbl, "www.domain12497.com");
    hashtbl_remove(tbl, "www.domain43997.com");
    printf("ele cnt = %d\n", tbl->count);
    for (i = 0, cnt = 0; i < tbl->size; ++i) {
        entry = tbl->nodes[i];
        if (entry)
            --cnt;
        while (entry) {
            fprintf(stderr, "%s:%d\n", entry->key, (int)entry->data);
            ++cnt;
            entry = entry->next;
        }
    }
    printf("tbl %d collisions\n", cnt);
    hashtbl_dump(tbl, stdout);
    if (line)
        free(line);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct hashtbl *tbl;
    struct hashnode *entry;
    unsigned long tblsiz; unsigned long elecnt;
    char *line = ((void *)0);
    int ret; int i; int cnt; int len = 0;
    if (argc == 0) {
        tblsiz = 1013;
        elecnt = 1000;
    }
    else if (argc != 3) {
        help(argc, argv);
        exit(1);
    }
    else {
        tblsiz = atoi(argv[1]);
        elecnt = atoi(argv[2]);
    }
    entry = malloc(sizeof(ENTRY));
    tbl = hashtbl_create(tblsiz, ((void *)0));
    printf("tbl = %p\n", tbl);
    for (i = 1, cnt = 0; i < elecnt; ++i) {
        if ( (ret = getline(&line, &len, stdin)) == -1) {
            fprintf(stderr, "getline() failed\n");
            continue;
        }
        if ( ret > 0 && line[ret-1] == '\n')
            line[ret-1] = '\0';
        entry->key = line;
        hashtbl_insert(tbl, entry->key, (void *)i);
        ++cnt;
    }
    printf("insert %d elements\n", cnt);
    printf("ele cnt = %d\n", tbl->count);
    hashtbl_remove(tbl, "www.domain3912.com");
    hashtbl_remove(tbl, "www.domain92492.com");
    hashtbl_remove(tbl, "www.domain77224.com");
    hashtbl_remove(tbl, "www.domain68464.com");
    hashtbl_remove(tbl, "www.domain12497.com");
    hashtbl_remove(tbl, "www.domain43997.com");
    printf("ele cnt = %d\n", tbl->count);
    for (i = 0, cnt = 0; i < tbl->size; ++i) {
        entry = tbl->nodes[i];
        if (entry)
            --cnt;
        while (entry) {
            fprintf(stderr, "%s:%d\n", entry->key, (int)entry->data);
            ++cnt;
            entry = entry->next;
        }
    }
    printf("tbl %d collisions\n", cnt);
    hashtbl_dump(tbl, stdout);
    if (line)
        free(line);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct hashtbl { unsigned long size; unsigned long count; struct hashnode { char *key; void *data; struct hashnode *next; } **nodes; unsigned long (*hashfunc)(char *); } *

variable_types:
tblsiz
unsigned long

variable_types:
elecnt
unsigned long

variable_types:
line
char *

variable_types: ret int

variable_types: cnt int

variable_types: len int

user_defined_types: struct hashtbl { unsigned long size; unsigned long count; struct hashnode **nodes; unsigned long (*hashfunc)(char *); }


decompiled_code:
__int64 __fastcall bkdr_hash(char *a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *a1;
for ( result = 0LL; (_BYTE)v1; v1 = *a1 )
{
++a1;
result = v1 + 131 * result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *a1;
for ( result = 0LL; (_BYTE)v1; v1 = *a1 )
{
++a1;
result = v1 + 131 * result;
}
return result;
}

original_code:
static HSIZE bkdr_hash(const char *key)
{
    HSIZE seed = 131;
    HSIZE hash = 0;
    while (*key)
        hash = hash * seed + (*key++);
    return hash;
}

canonical_original_code:
static unsigned long bkdr_hash(char *key)
{
    unsigned long seed = 131;
    unsigned long hash = 0;
    while (*key)
        hash = hash * seed + (*key++);
    return hash;
}

variable_types:
key
char *

variable_types:
seed
unsigned long

variable_types:
hash
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall hashtbl_destroy(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // rbp
__int64 v5; // rbx
void *v6; // rdi

v2 = *(_QWORD *)ptr == 0LL;
v3 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = v3[v4];
if ( v5 )
{
do
{
free(*(void **)v5);
v6 = (void *)v5;
v5 = *(_QWORD *)(v5 + 16);
free(v6);
}
while ( v5 );
v3 = (_QWORD *)*((_QWORD *)ptr + 2);
}
++v4;
}
while ( *(_QWORD *)ptr > v4 );
}
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // rbp
__int64 v5; // rbx
void *v6; // rdi

v2 = *(_QWORD *)ptr == 0LL;
v3 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = v3[v4];
if ( v5 )
{
do
{
free(*(void **)v5);
v6 = (void *)v5;
v5 = *(_QWORD *)(v5 + 16);
free(v6);
}
while ( v5 );
v3 = (_QWORD *)*((_QWORD *)ptr + 2);
}
++v4;
}
while ( *(_QWORD *)ptr > v4 );
}
free(v3);
free(ptr);
}

original_code:
void hashtbl_destroy(HASHTBL *hashtbl)
{
    HSIZE n;
    ENTRY *node, *oldnode;
    for (n = 0; n < hashtbl->size; ++n) {
        node = hashtbl->nodes[n];
        while (node) {
            free(node->key);
            oldnode = node;
            node = node->next;
            free(oldnode);
        }
    }
    free(hashtbl->nodes);
    free(hashtbl);
}

canonical_original_code:
void hashtbl_destroy(struct hashtbl *hashtbl)
{
    unsigned long n;
    struct hashnode *node; struct hashnode *oldnode;
    for (n = 0; n < hashtbl->size; ++n) {
        node = hashtbl->nodes[n];
        while (node) {
            free(node->key);
            oldnode = node;
            node = node->next;
            free(oldnode);
        }
    }
    free(hashtbl->nodes);
    free(hashtbl);
}

variable_types:
n
unsigned long

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


decompiled_code:
__int64 __fastcall hashtbl_remove(__int64 a1, const char *a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // r15
unsigned __int64 v4; // r14
__int64 v5; // rbp
char *v6; // r12
__int64 v7; // rdx

v2 = (unsigned __int64)(*(__int64 (__fastcall **)(const char *))(a1 + 24))(a2) % *(_QWORD *)a1;
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v2);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = v2;
v5 = 0LL;
while ( 1 )
{
v6 = *(char **)v3;
if ( !strcmp(*(const char **)v3, a2) )
break;
v5 = v3;
if ( !*(_QWORD *)(v3 + 16) )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)(v3 + 16);
}
free(v6);
v7 = *(_QWORD *)(v3 + 16);
if ( v5 )
*(_QWORD *)(v5 + 16) = v7;
else
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v4) = v7;
free((void *)v3);
--*(_QWORD *)(a1 + 8);
return 0LL;
}

original_code:
int hashtbl_remove(HASHTBL *hashtbl, const char *key)
{
    ENTRY *node, *prevnode = ((void *)0);
    HSIZE hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            free(node->key);
            if (prevnode)
                prevnode->next = node->next;
            else
                hashtbl->nodes[hash] = node->next;
            free(node);
            hashtbl->count--;
            return 0;
        }
        prevnode = node;
        node = node->next;
    }
    return -1;
}

canonical_original_code:
int hashtbl_remove(struct hashtbl *hashtbl, char *key)
{
    struct hashnode *node; struct hashnode *prevnode = ((void *)0);
    unsigned long hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            free(node->key);
            if (prevnode)
                prevnode->next = node->next;
            else
                hashtbl->nodes[hash] = node->next;
            free(node);
            hashtbl->count--;
            return 0;
        }
        prevnode = node;
        node = node->next;
    }
    return -1;
}

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


original_code:
void *hashtbl_get(HASHTBL *hashtbl, const char *key)
{
    ENTRY *node;
    HSIZE hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            return node->data;
        }
        node = node->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *hashtbl_get(struct hashtbl *hashtbl, char *key)
{
    struct hashnode *node;
    unsigned long hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            return node->data;
        }
        node = node->next;
    }
    return ((void *)0);
}

return_type: void *


decompiled_code:
__int64 __fastcall hashtbl_resize(size_t *a1, size_t a2)
{
__int64 v3; // rax
_QWORD *v4; // rdi
size_t v5; // r13
__int64 v6; // rbx
const char **v7; // rbp
size_t v9; // [rsp+0h] [rbp-48h] BYREF
size_t v10; // [rsp+8h] [rbp-40h]
void *v11; // [rsp+10h] [rbp-38h]
__int64 v12; // [rsp+18h] [rbp-30h]

v3 = a1[3];
v9 = a2;
v10 = 0LL;
v12 = v3;
v11 = calloc(a2, 8uLL);
if ( !v11 )
return 0xFFFFFFFFLL;
v4 = (_QWORD *)a1[2];
if ( *a1 )
{
v5 = 0LL;
do
{
v6 = v4[v5];
if ( v6 )
{
do
{
v7 = (const char **)v6;
v6 = *(_QWORD *)(v6 + 16);
hashtbl_insert(&v9, *v7, v7[1]);
hashtbl_remove((__int64)a1, *v7);
}
while ( v6 );
v4 = (_QWORD *)a1[2];
}
++v5;
}
while ( *a1 > v5 );
}
free(v4);
*a1 = v9;
a1[1] = v10;
a1[2] = (size_t)v11;
return 0LL;
}

original_code:
int hashtbl_resize(HASHTBL *hashtbl, HSIZE size)
{
    HASHTBL newtbl;
    HSIZE n;
    ENTRY *node,*next;
    newtbl.size = size;
    newtbl.count = 0;
    newtbl.hashfunc = hashtbl->hashfunc;
    if (!(newtbl.nodes = calloc(size, sizeof(ENTRY*))))
        return -1;
    for (n = 0; n < hashtbl->size; ++n) {
        for (node = hashtbl->nodes[n]; node; node = next) {
            next = node->next;
            hashtbl_insert(&newtbl, node->key, node->data);
            hashtbl_remove(hashtbl, node->key);
        }
    }
    free(hashtbl->nodes);
    hashtbl->size = newtbl.size;
    hashtbl->count = newtbl.count;
    hashtbl->nodes = newtbl.nodes;
    return 0;
}

canonical_original_code:
int hashtbl_resize(struct hashtbl *hashtbl, unsigned long size)
{
    struct hashtbl newtbl;
    unsigned long n;
    struct hashnode *node; struct hashnode *next;
    newtbl.size = size;
    newtbl.count = 0;
    newtbl.hashfunc = hashtbl->hashfunc;
    if (!(newtbl.nodes = calloc(size, sizeof(struct hashnode *))))
        return -1;
    for (n = 0; n < hashtbl->size; ++n) {
        for (node = hashtbl->nodes[n]; node; node = next) {
            next = node->next;
            hashtbl_insert(&newtbl, node->key, node->data);
            hashtbl_remove(hashtbl, node->key);
        }
    }
    free(hashtbl->nodes);
    hashtbl->size = newtbl.size;
    hashtbl->count = newtbl.count;
    hashtbl->nodes = newtbl.nodes;
    return 0;
}

variable_types:
size
unsigned long

variable_types: struct hashtbl { unsigned long size; unsigned long count; struct hashnode { char *key; void *data; struct hashnode *next; } **nodes; unsigned long (*hashfunc)(char *); }


original_code:
int hashtbl_insert(HASHTBL *hashtbl, const char *key, void *data)
{
    ENTRY *node;
    HSIZE hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            node->data = data;
            return 0;
        }
        node = node->next;
    }
    if (hashtbl->count >= hashtbl->size * 0.75) {
        hashtbl_resize(hashtbl, hashtbl->size * 2 + 1);
    }
    if (!(node = malloc(sizeof(ENTRY))))
        return -1;
    if (!(node->key = strdup(key))) {
        free(node);
        return -1;
    }
    node->data = data;
    node->next = hashtbl->nodes[hash];
    hashtbl->nodes[hash] = node;
    hashtbl->count++;
    return 0;
}

canonical_original_code:
int hashtbl_insert(struct hashtbl *hashtbl, char *key, void *data)
{
    struct hashnode *node;
    unsigned long hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            node->data = data;
            return 0;
        }
        node = node->next;
    }
    if (hashtbl->count >= hashtbl->size * 0.75) {
        hashtbl_resize(hashtbl, hashtbl->size * 2 + 1);
    }
    if (!(node = malloc(sizeof(ENTRY))))
        return -1;
    if (!(node->key = strdup(key))) {
        free(node);
        return -1;
    }
    node->data = data;
    node->next = hashtbl->nodes[hash];
    hashtbl->nodes[hash] = node;
    hashtbl->count++;
    return 0;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall hash_func(char *a1)
{
__int64 v1; // rax
__int64 i; // r8

v1 = *a1;
for ( i = 0LL; (_BYTE)v1; v1 = *a1 )
{
++a1;
i += v1;
}
return i;
}

original_code:
HSIZE hash_func(const char *key) {
    HSIZE hash = 0;
    while (*key)
        hash += (*key++);
    return hash;
}

canonical_original_code:
unsigned long hash_func(char *key) {
    unsigned long hash = 0;
    while (*key)
        hash += (*key++);
    return hash;
}


help

decompiled_code:
int __fastcall help(__int64 a1, const char **a2)
{
return printf("%s <table size> <element count>\n", *a2);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, const char **a2)
{
return printf("%s <table size> <element count>\n", *a2);
}

original_code:
void help(int argc, char *argv[])
{
    printf("%s <table size> <element count>\n", argv[0]);
}

variable_types: argc int


decompiled_code:
int thread_setup()
{
_QWORD *v0; // rax
pthread_mutex_t *v1; // rdi

lock_cs = (pthread_mutex_t *)CRYPTO_malloc(40LL, "fuzz.c", 293LL);
v0 = (_QWORD *)CRYPTO_malloc(8LL, "fuzz.c", 294LL);
v1 = lock_cs;
*v0 = 0LL;
lock_count = (__int64)v0;
return pthread_mutex_init(v1, 0LL);
}

canonical_decompiled_code:
int func2()
{
_QWORD *v0; // rax
pthread_mutex_t *v1; // rdi

lock_cs = (pthread_mutex_t *)CRYPTO_malloc(40LL, "fuzz.c", 293LL);
v0 = (_QWORD *)CRYPTO_malloc(8LL, "fuzz.c", 294LL);
v1 = lock_cs;
*v0 = 0LL;
lock_count = (__int64)v0;
return pthread_mutex_init(v1, 0LL);
}

original_code:
void thread_setup(void)
{
 int i;
 lock_cs=CRYPTO_malloc((1) * sizeof(pthread_mutex_t), "fuzz.c", 293);
 lock_count=CRYPTO_malloc((1) * sizeof(long), "fuzz.c", 294);
 for (i=0; i<(1); i++)
 {
  lock_count[i]=0;
  pthread_mutex_init(&(lock_cs[i]),((void *)0));
 }
 ;
 ;
}

canonical_original_code:
void thread_setup()
{
 int i;
 lock_cs=CRYPTO_malloc((1) * sizeof(pthread_mutex_t), "fuzz.c", 293);
 lock_count=CRYPTO_malloc((1) * sizeof(long), "fuzz.c", 294);
 for (i=0; i<(1); i++)
 {
  lock_count[i]=0;
  pthread_mutex_init(&(lock_cs[i]),((void *)0));
 }
 ;
 ;
}

variable_types: i int


decompiled_code:
// attributes: thunk
pthread_t pthreads_thread_id(void)
{
return pthread_self();
}

canonical_decompiled_code:
pthread_t func3(void)
{
return pthread_self();
}

original_code:
unsigned long pthreads_thread_id(void)
{
 unsigned long ret;
 ret=(unsigned long)pthread_self();
 return(ret);
}

canonical_original_code:
unsigned long pthreads_thread_id()
{
 unsigned long ret;
 ret=(unsigned long)pthread_self();
 return(ret);
}

variable_types:
ret
unsigned long


decompiled_code:
int __fastcall pthreads_locking_callback(char a1, int a2)
{
bool v2; // zf
pthread_mutex_t *v3; // rdi
int result; // eax

v2 = (a1 & 1) == 0;
v3 = &lock_cs[a2];
if ( v2 )
return pthread_mutex_unlock(v3);
pthread_mutex_lock(v3);
result = lock_count;
++*(_QWORD *)(lock_count + 8LL * a2);
return result;
}

canonical_decompiled_code:
int __fastcall func4(char a1, int a2)
{
bool v2; // zf
pthread_mutex_t *v3; // rdi
int result; // eax

v2 = (a1 & 1) == 0;
v3 = &lock_cs[a2];
if ( v2 )
return pthread_mutex_unlock(v3);
pthread_mutex_lock(v3);
result = lock_count;
++*(_QWORD *)(lock_count + 8LL * a2);
return result;
}

original_code:
void pthreads_locking_callback(int mode, int type, char *file, int line)
{
 if (mode & 1)
 {
  pthread_mutex_lock(&(lock_cs[type]));
  lock_count[type]++;
 }
 else
  pthread_mutex_unlock(&(lock_cs[type]));
}

variable_types: mode int

variable_types: type int

variable_types:
file
char *

variable_types: line int


decompiled_code:
__int64 pthread_cleanup()
{
pthread_mutex_t *v0; // rbp

v0 = lock_cs;
pthread_mutex_destroy(lock_cs);
CRYPTO_free(v0, "fuzz.c", 331LL);
return CRYPTO_free(lock_count, "fuzz.c", 332LL);
}

canonical_decompiled_code:
__int64 func5()
{
pthread_mutex_t *v0; // rbp

v0 = lock_cs;
pthread_mutex_destroy(lock_cs);
CRYPTO_free(v0, "fuzz.c", 331LL);
return CRYPTO_free(lock_count, "fuzz.c", 332LL);
}

original_code:
void pthread_cleanup(void)
{
 int i;
 ;
 for (i=0; i<(1); i++)
  pthread_mutex_destroy(&(lock_cs[i]));
 CRYPTO_free(lock_cs, "fuzz.c", 331);
 CRYPTO_free(lock_count, "fuzz.c", 332);
}

canonical_original_code:
void pthread_cleanup()
{
 int i;
 ;
 for (i=0; i<(1); i++)
  pthread_mutex_destroy(&(lock_cs[i]));
 CRYPTO_free(lock_cs, "fuzz.c", 331);
 CRYPTO_free(lock_count, "fuzz.c", 332);
}


initssl

decompiled_code:
__int64 initssl()
{
CRYPTO_malloc_init();
OPENSSL_init_ssl(0LL, 0LL);
return OPENSSL_init_ssl(2097154LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
CRYPTO_malloc_init();
OPENSSL_init_ssl(0LL, 0LL);
return OPENSSL_init_ssl(2097154LL, 0LL);
}

original_code:
void initssl()
{
 CRYPTO_malloc_init();
 OPENSSL_init_ssl(0, ((void *)0));
 OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
}


original_code:
unsigned int base64decode(char *buffer)
{
 uint8_t car, i;
 char valcar[4];
 unsigned int pos_src, pos_dst;
 pos_src = 0;
 pos_dst = 0;
 while (buffer[pos_src] > ' ' && buffer[pos_src] != '=')
 {
  for (i = 0; i < 4 && buffer[pos_src] != '='; i++)
  {
   car = buffer[pos_src++];
   if ('A' <= car && car <= 'Z')
    valcar[i] = car - 'A';
   else if ('a' <= car && car <= 'z')
    valcar[i] = car + 26 - 'a';
   else if ('0' <= car && car <= '9')
    valcar[i] = car + 52 - '0';
   else if (car == '+')
    valcar[i] = 62;
   else if (car == '/')
    valcar[i] = 63;
  }
  buffer[pos_dst++] = (valcar[0] << 2) | (valcar[1] >> 4);
  if (i > 2)
  {
   buffer[pos_dst++] = (valcar[1] << 4) | (valcar[2] >> 2);
   if (i > 3)
    buffer[pos_dst++] = (valcar[2] << 6) | (valcar[3]);
  }
 }
 buffer[pos_dst] = '\0';
 return (pos_dst);
}

canonical_original_code:
unsigned int base64decode(char *buffer)
{
 unsigned char car; unsigned char i;
 char valcar[4];
 unsigned int pos_src; unsigned int pos_dst;
 pos_src = 0;
 pos_dst = 0;
 while (buffer[pos_src] > ' ' && buffer[pos_src] != '=')
 {
  for (i = 0; i < 4 && buffer[pos_src] != '='; i++)
  {
   car = buffer[pos_src++];
   if ('A' <= car && car <= 'Z')
    valcar[i] = car - 'A';
   else if ('a' <= car && car <= 'z')
    valcar[i] = car + 26 - 'a';
   else if ('0' <= car && car <= '9')
    valcar[i] = car + 52 - '0';
   else if (car == '+')
    valcar[i] = 62;
   else if (car == '/')
    valcar[i] = 63;
  }
  buffer[pos_dst++] = (valcar[0] << 2) | (valcar[1] >> 4);
  if (i > 2)
  {
   buffer[pos_dst++] = (valcar[1] << 4) | (valcar[2] >> 2);
   if (i > 3)
    buffer[pos_dst++] = (valcar[2] << 6) | (valcar[3]);
  }
 }
 buffer[pos_dst] = '\0';
 return (pos_dst);
}

variable_types:
buffer
char *

variable_types:
car
unsigned char

variable_types:
i
unsigned char

variable_types:
valcar
char [4]

return_type: unsigned int


urlencode

original_code:
void urlencode( char *src, char **dst, unsigned int size, int type )
{
 unsigned int i,j=0;
 unsigned char c;
 char newchar[4];
 char newdst[2048];
 if(type > 2)
  return;
 for(i=0; i< size && j<(2048 -1); i++)
 {
  c=src[i];
  if( (c < 48 ) || (c> 57 && c< 65) || (c > 90 && c < 97) || (c > 122 && c < 128))
  {
   if(type==2 && c==32)
   {
    newdst[j++]='+';
   }
   else
   {
    sprintf(newchar,"\%%%2x",c);
    newdst[j]=newchar[0];
    newdst[j+1]=newchar[1];
    newdst[j+2]=newchar[2];
    j=j+3;
   }
  }
  else
  {
   newdst[j]=c;
   j++;
  }
 }
 if(j<(2048 -1))
  newdst[j]='\0';
 else
  newdst[j-1]='\0';
 *dst=realloc(*dst, strlen(newdst)+1);
if(*dst==((void *)0))
{
 printf("\n Realloc failed \n");
 exit(0);
}
 strcpy(*dst,newdst);
}

canonical_original_code:
void urlencode(char *src, char **dst, unsigned int size, int type)
{
 unsigned int i; unsigned int j = 0;
 unsigned char c;
 char newchar[4];
 char newdst[2048];
 if(type > 2)
  return;
 for(i=0; i< size && j<(2048 -1); i++)
 {
  c=src[i];
  if( (c < 48 ) || (c> 57 && c< 65) || (c > 90 && c < 97) || (c > 122 && c < 128))
  {
   if(type==2 && c==32)
   {
    newdst[j++]='+';
   }
   else
   {
    sprintf(newchar,"\%%%2x",c);
    newdst[j]=newchar[0];
    newdst[j+1]=newchar[1];
    newdst[j+2]=newchar[2];
    j=j+3;
   }
  }
  else
  {
   newdst[j]=c;
   j++;
  }
 }
 if(j<(2048 -1))
  newdst[j]='\0';
 else
  newdst[j-1]='\0';
 *dst=realloc(*dst, strlen(newdst)+1);
if(*dst==((void *)0))
{
 printf("\n Realloc failed \n");
 exit(0);
}
 strcpy(*dst,newdst);
}

variable_types:
src
char *

variable_types:
dst
char **

variable_types:
size
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
c
unsigned char

variable_types:
newchar
char [4]

variable_types:
newdst
char [2048]


delnewline

decompiled_code:
char *__fastcall delnewline(char *s)
{
char *result; // rax

result = strchr(s, 13);
if ( result )
{
*result = 0;
LABEL_3:
*result = 0;
return result;
}
result = strchr(s, 10);
if ( result )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
char *result; // rax

result = strchr(s, 13);
if ( result )
{
*result = 0;
LABEL_3:
*result = 0;
return result;
}
result = strchr(s, 10);
if ( result )
goto LABEL_3;
return result;
}

original_code:
void delnewline(char *string)
{
   char *p = strchr(string, '\r');
   if (p)
        *p = 0;
 else
  p = strchr(string, '\n');
 if(p)
  *p = 0;
}

variable_types:
string
char *

variable_types:
p
char *


decompiled_code:
__time_t __fastcall path_mtime(char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = (unsigned int)stat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = v3.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func6(char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = (unsigned int)func10(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = v3.st_mtim.tv_sec;
return result;
}

original_code:
time_t path_mtime(const char *path)
{
     struct stat s;
     time_t mtime = 0;
     int ret;
     ret = stat(path, &s);
     if(ret == 0) {
        mtime = s.st_mtim.tv_sec;
     }
     return mtime;
}

canonical_original_code:
long path_mtime(char *path)
{
     struct stat s;
     long mtime = 0;
     int ret;
     ret = stat(path, &s);
     if(ret == 0) {
        mtime = s.st_mtim.tv_sec;
     }
     return mtime;
}

variable_types:
path
char *

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

variable_types: mtime long

variable_types: ret int

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


decompiled_code:
__int64 __fastcall cmp_mtime(const void *a1, const void *a2)
{
__int64 v2; // rbx
__int64 v3; // r8
__int64 result; // rax

v2 = path_mtime(*(_QWORD *)a1);
v3 = path_mtime(*(_QWORD *)a2);
result = (unsigned int)-(v2 < v3);
if ( v2 > v3 )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
__int64 v2; // rbx
__int64 v3; // r8
__int64 result; // rax

v2 = func6(*(_QWORD *)a1);
v3 = func6(*(_QWORD *)a2);
result = (unsigned int)-(v2 < v3);
if ( v2 > v3 )
result = 1LL;
return result;
}

original_code:
static int cmp_mtime(const void *p1, const void *p2)
{
       int ret = 0;
       time_t m1 = path_mtime(* (char * const *) p1);
       time_t m2 = path_mtime(* (char * const *) p2);
       if( m1 > m2)
           ret = 1;
       if( m1 < m2)
           ret = -1;
       return ret;
}

canonical_original_code:
static int cmp_mtime(void *p1, void *p2)
{
       int ret = 0;
       long m1 = path_mtime(* (char * const *) p1);
       long m2 = path_mtime(* (char * const *) p2);
       if( m1 > m2)
           ret = 1;
       if( m1 < m2)
           ret = -1;
       return ret;
}


getenv

decompiled_code:
__int64 __fastcall getenv(const char *a1)
{
bool v2; // cf
bool v3; // zf
__int64 (__fastcall *v4)(_QWORD); // rax
__int64 v5; // rcx
const char *v6; // rdi
const char *v7; // rsi
__int64 result; // rax

v4 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "getenv");
v5 = 14LL;
v6 = "SSH_AUTH_SOCK";
v7 = a1;
do
{
if ( !v5 )
break;
v2 = *v7 < (unsigned int)*v6;
v3 = *v7++ == *v6++;
--v5;
}
while ( v3 );
o_dl_0 = v4;
if ( (!v2 && !v3) != v2 )
return ((__int64 (__fastcall *)(const char *, const char *))v4)(a1, v7);
result = latest_ssh_auth_sock(v6, v7);
if ( !result )
result = o_dl_0(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
bool v2; // cf
bool v3; // zf
__int64 (__fastcall *v4)(_QWORD); // rax
__int64 v5; // rcx
const char *v6; // rdi
const char *v7; // rsi
__int64 result; // rax

v4 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "getenv");
v5 = 14LL;
v6 = "SSH_AUTH_SOCK";
v7 = a1;
do
{
if ( !v5 )
break;
v2 = *v7 < (unsigned int)*v6;
v3 = *v7++ == *v6++;
--v5;
}
while ( v3 );
o_dl_0 = v4;
if ( (!v2 && !v3) != v2 )
return ((__int64 (__fastcall *)(const char *, const char *))v4)(a1, v7);
result = func8(v6, v7);
if ( !result )
result = o_dl_0(a1);
return result;
}

original_code:
char *getenv(const char *name)
{
   static char* (*o_dl)(const char *name) = 0;
   char *new_sock;
   o_dl = (char*(*)(const char *name)) dlsym(((void *) -1l),"getenv");
   if(strcmp(name, "SSH_AUTH_SOCK") == 0) {
       new_sock = latest_ssh_auth_sock();
       if(new_sock != ((void *)0)) {
           return new_sock;
       }
   }
   return (*o_dl)(name);
}

canonical_original_code:
char *getenv(char *name)
{
   static char *(*o_dl)(char *name) = 0;
   char *new_sock;
   o_dl = (char *(*)(char *name)) dlsym(((void *) -1l),"getenv");
   if(strcmp(name, "SSH_AUTH_SOCK") == 0) {
       new_sock = latest_ssh_auth_sock();
       if(new_sock != ((void *)0)) {
           return new_sock;
       }
   }
   return (*o_dl)(name);
}

variable_types:
name
char *


odd

decompiled_code:
__int64 __fastcall odd(char a1)
{
return a1 & 1;
}

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

original_code:
int
odd(int n)
{
 return (n&1);
}

canonical_original_code:
int odd(int n)
{
 return (n&1);
}

variable_types: n int


even

decompiled_code:
_BOOL8 __fastcall even(char a1)
{
return (a1 & 1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
return (a1 & 1) == 0;
}

original_code:
int
even(int n)
{
 return (!(n&1));
}

canonical_original_code:
int even(int n)
{
 return (!(n&1));
}


decompiled_code:
__int64 __fastcall strstr_count(char *haystack, char *needle)
{
size_t v2; // rbp
char *v3; // rax
size_t v4; // rbp
unsigned int v5; // er12

if ( !needle )
return 0LL;
if ( !haystack )
return 0LL;
v2 = strlen(needle);
v3 = strstr(haystack, needle);
if ( !v3 )
return 0LL;
v4 = v2 - 1;
v5 = 0;
do
{
++v5;
v3 = strstr(&v3[v4], needle);
}
while ( v3 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *haystack, char *needle)
{
size_t v2; // rbp
char *v3; // rax
size_t v4; // rbp
unsigned int v5; // er12

if ( !needle )
return 0LL;
if ( !haystack )
return 0LL;
v2 = strlen(needle);
v3 = strstr(haystack, needle);
if ( !v3 )
return 0LL;
v4 = v2 - 1;
v5 = 0;
do
{
++v5;
v3 = strstr(&v3[v4], needle);
}
while ( v3 );
return v5;
}

original_code:
int
strstr_count(char *s, char *t)
{
 int n=0;
 size_t len;
 char *p;
 if (t==((void *)0) || s==((void *)0)) return n;
 len = strlen(t);
 p = strstr(s,t);
 while (p) {
  n++;
  p = strstr(p+len-1,t);
 }
 return n;
}

canonical_original_code:
int strstr_count(char *s, char *t)
{
 int n = 0;
 unsigned long len;
 char *p;
 if (t==((void *)0) || s==((void *)0)) return n;
 len = strlen(t);
 p = strstr(s,t);
 while (p) {
  n++;
  p = strstr(p+len-1,t);
 }
 return n;
}

variable_types:
s
char *

variable_types:
t
char *

variable_types:
len
unsigned long


decompiled_code:
char *__fastcall my_strndup(char *src, size_t n)
{
char *v2; // rax
char *v3; // r8

v2 = (char *)calloc(n + 1, 1uLL);
v3 = v2;
if ( v2 )
v3 = strncpy(v2, src, n);
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(char *src, size_t n)
{
char *v2; // rax
char *v3; // r8

v2 = (char *)calloc(n + 1, 1uLL);
v3 = v2;
if ( v2 )
v3 = strncpy(v2, src, n);
return v3;
}

original_code:
char *
my_strndup(char *src, size_t n)
{
 char *dst;
 dst = (char *) calloc(n+1,sizeof(char));
 if (dst==((void *)0)) return ((void *)0);
 strncpy(dst,src,n);
 return dst;
}

canonical_original_code:
char *my_strndup(char *src, unsigned long n)
{
 char *dst;
 dst = (char *) calloc(n+1,sizeof(char));
 if (dst==((void *)0)) return ((void *)0);
 strncpy(dst,src,n);
 return dst;
}

variable_types:
src
char *

variable_types:
n
unsigned long

variable_types:
dst
char *


decompiled_code:
char *__fastcall strdup_together(char *src, char *a2)
{
size_t v2; // r13
size_t v3; // rax
char *v4; // r13
char *v5; // rax
char *result; // rax

if ( src )
{
if ( a2 )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
if ( !v4 )
diagnostics(0LL, "Could not allocate memory for both strings.");
v5 = stpcpy(v4, src);
strcpy(v5, a2);
return v4;
}
result = (char *)my_strdup(src);
}
else
{
if ( !a2 )
return 0LL;
result = (char *)my_strdup(a2);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *src, char *a2)
{
size_t v2; // r13
size_t v3; // rax
char *v4; // r13
char *v5; // rax
char *result; // rax

if ( src )
{
if ( a2 )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
if ( !v4 )
diagnostics(0LL, "Could not allocate memory for both strings.");
v5 = stpcpy(v4, src);
strcpy(v5, a2);
return v4;
}
result = (char *)my_strdup(src);
}
else
{
if ( !a2 )
return 0LL;
result = (char *)my_strdup(a2);
}
return result;
}

original_code:
char *
strdup_together(char *s, char *t)
{
 char * both;
 if (s==((void *)0)) {
  if (t==((void *)0)) return ((void *)0);
  return my_strdup(t);
 }
 if (t==((void *)0))
  return my_strdup(s);
 both = malloc(strlen(s) + strlen(t) + 1);
 if (both == ((void *)0))
  diagnostics(0, "Could not allocate memory for both strings.");
 strcpy(both, s);
 strcat(both, t);
 return both;
}

canonical_original_code:
char *strdup_together(char *s, char *t)
{
 char *both;
 if (s==((void *)0)) {
  if (t==((void *)0)) return ((void *)0);
  return my_strdup(t);
 }
 if (t==((void *)0))
  return my_strdup(s);
 both = malloc(strlen(s) + strlen(t) + 1);
 if (both == ((void *)0))
  diagnostics(0, "Could not allocate memory for both strings.");
 strcpy(both, s);
 strcat(both, t);
 return both;
}

variable_types:
both
char *


decompiled_code:
char *__fastcall strdup_noblanks(char *s)
{
char v1; // al
char *v2; // rbx
size_t v3; // rax
char *v4; // r8
char v5; // al
char *i; // rdx

if ( !s )
return 0LL;
v1 = *s;
v2 = s;
if ( *s != 32 )
goto LABEL_4;
do
{
do
v1 = *++v2;
while ( v1 == 32 );
LABEL_4:
;
}
while ( v1 == 10 );
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 1);
v5 = *v2;
for ( i = v4; v5; ++v2 )
{
*i = v5;
if ( v5 != 32 )
i += -(v5 == 10) + 1;
v5 = v2[1];
}
*i = 0;
return v4;
}

canonical_decompiled_code:
char *__fastcall func6(char *s)
{
char v1; // al
char *v2; // rbx
size_t v3; // rax
char *v4; // r8
char v5; // al
char *i; // rdx

if ( !s )
return 0LL;
v1 = *s;
v2 = s;
if ( *s != 32 )
goto LABEL_4;
do
{
do
v1 = *++v2;
while ( v1 == 32 );
LABEL_4:
;
}
while ( v1 == 10 );
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 1);
v5 = *v2;
for ( i = v4; v5; ++v2 )
{
*i = v5;
if ( v5 != 32 )
i += -(v5 == 10) + 1;
v5 = v2[1];
}
*i = 0;
return v4;
}

original_code:
char *
strdup_noblanks(char *s)
{
char *p, *dup;
 if (s==((void *)0)) return ((void *)0);
 while (*s == ' ' || *s == '\n') s++;
 dup = malloc(strlen(s) + 1);
 p = dup;
 while (*s) {
  *p = *s;
  if (*p != ' ' && *p != '\n') p++;
  s++;
 }
 *p = '\0';
 return dup;
}

canonical_original_code:
char *strdup_noblanks(char *s)
{
char *p; char *dup;
 if (s==((void *)0)) return ((void *)0);
 while (*s == ' ' || *s == '\n') s++;
 dup = malloc(strlen(s) + 1);
 p = dup;
 while (*s) {
  *p = *s;
  if (*p != ' ' && *p != '\n') p++;
  s++;
 }
 *p = '\0';
 return dup;
}

variable_types:
dup
char *


decompiled_code:
char *__fastcall strdup_nobadchars(char *a1)
{
char *v1; // r8
char v2; // al
char *v3; // rcx

v1 = strdup_noblanks(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)((v2 & 0xDF) - 65) > 0x19u && (unsigned __int8)(v2 - 48) > 9u )
*v3 = 95;
v2 = *++v3;
}
while ( v2 );
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func7(char *a1)
{
char *v1; // r8
char v2; // al
char *v3; // rcx

v1 = func6(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)((v2 & 0xDF) - 65) > 0x19u && (unsigned __int8)(v2 - 48) > 9u )
*v3 = 95;
v2 = *++v3;
}
while ( v2 );
}
return v1;
}

original_code:
char *
strdup_nobadchars(char * text)
{
 char *dup, *s;
 dup = strdup_noblanks(text);
 s = dup;
 while (*s) {
  if (!('a' <= *s && *s <= 'z') &&
      !('A' <= *s && *s <= 'Z') &&
      !('0' <= *s && *s <= '9'))
   *s = '_';
  s++;
 }
 return dup;
}

canonical_original_code:
char *strdup_nobadchars(char *text)
{
 char *dup; char *s;
 dup = strdup_noblanks(text);
 s = dup;
 while (*s) {
  if (!('a' <= *s && *s <= 'z') &&
      !('A' <= *s && *s <= 'Z') &&
      !('0' <= *s && *s <= '9'))
   *s = '_';
  s++;
 }
 return dup;
}

variable_types:
text
char *


decompiled_code:
char *__fastcall strdup_noendblanks(char *src)
{
char v1; // al
char *v2; // rbp
char v3; // al
char *v4; // rsi
char *result; // rax

if ( !src )
return 0LL;
v1 = *src;
if ( !*src )
goto LABEL_14;
v2 = src;
if ( v1 == 10 || v1 == 32 )
{
do
{
do
v3 = *++v2;
while ( v3 == 32 );
}
while ( v3 == 10 );
}
v4 = &src[strlen(src) - 1];
if ( v4 < v2 )
goto LABEL_14;
while ( *v4 == 32 || *v4 == 10 )
{
if ( --v4 < v2 )
goto LABEL_14;
}
if ( v4 >= v2 )
result = my_strndup(v2, v4 - v2 + 1);
else
LABEL_14:
result = (char *)my_strdup(&unk_554);
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
char v1; // al
char *v2; // rbp
char v3; // al
char *v4; // rsi
char *result; // rax

if ( !src )
return 0LL;
v1 = *src;
if ( !*src )
goto LABEL_14;
v2 = src;
if ( v1 == 10 || v1 == 32 )
{
do
{
do
v3 = *++v2;
while ( v3 == 32 );
}
while ( v3 == 10 );
}
v4 = &src[strlen(src) - 1];
if ( v4 < v2 )
goto LABEL_14;
while ( *v4 == 32 || *v4 == 10 )
{
if ( --v4 < v2 )
goto LABEL_14;
}
if ( v4 >= v2 )
result = func3(v2, v4 - v2 + 1);
else
LABEL_14:
result = (char *)my_strdup(&unk_554);
return result;
}

original_code:
char *
strdup_noendblanks(char * s)
{
char *p, *t;
 if (s==((void *)0)) return ((void *)0);
 if (*s=='\0') return my_strdup("");
 t=s;
 while (*t == ' ' || *t == '\n') t++;
 p = s + strlen(s) -1;
 while (p >= t && (*p == ' ' || *p == '\n')) p--;
 if (t>p) return my_strdup("");
 return my_strndup(t,(size_t) (p-t+1));
}

canonical_original_code:
char *strdup_noendblanks(char *s)
{
char *p; char *t;
 if (s==((void *)0)) return ((void *)0);
 if (*s=='\0') return my_strdup("");
 t=s;
 while (*t == ' ' || *t == '\n') t++;
 p = s + strlen(s) -1;
 while (p >= t && (*p == ' ' || *p == '\n')) p--;
 if (t>p) return my_strdup("");
 return my_strndup(t,(unsigned long) (p-t+1));
}


ExtractLabelTag

decompiled_code:
char *__fastcall ExtractLabelTag(char *haystack)
{
char *v1; // r12
char *v2; // rbp
char *v3; // r12

v1 = strstr(haystack, "\\label{");
if ( !v1 )
{
v1 = strstr(haystack, "\\label ");
if ( !v1 )
return 0LL;
}
PushSource(0LL, v1 + 6);
v2 = (char *)getBraceParam();
PopSource();
v3 = strdup_nobadchars(v2);
free(v2);
diagnostics(4LL, "LabelTag = <%s>");
return v3;
}

canonical_decompiled_code:
char *__fastcall func9(char *haystack)
{
char *v1; // r12
char *v2; // rbp
char *v3; // r12

v1 = strstr(haystack, "\\label{");
if ( !v1 )
{
v1 = strstr(haystack, "\\label ");
if ( !v1 )
return 0LL;
}
PushSource(0LL, v1 + 6);
v2 = (char *)getBraceParam();
PopSource();
v3 = func7(v2);
free(v2);
diagnostics(4LL, "LabelTag = <%s>");
return v3;
}

original_code:
char *
ExtractLabelTag(char *text)
{
 char *s, *label_with_spaces, *label;
 s = strstr(text,"\\label{");
 if (!s) s = strstr(text,"\\label ");
 if (!s) return ((void *)0);
 s += strlen("\\label");
 PushSource(((void *)0),s);
 label_with_spaces = getBraceParam();
 PopSource();
 label = strdup_nobadchars(label_with_spaces);
 free(label_with_spaces);
 diagnostics(4, "LabelTag = <%s>", (label) ? label : "missing");
 return label;
}

canonical_original_code:
char *ExtractLabelTag(char *text)
{
 char *s; char *label_with_spaces; char *label;
 s = strstr(text,"\\label{");
 if (!s) s = strstr(text,"\\label ");
 if (!s) return ((void *)0);
 s += strlen("\\label");
 PushSource(((void *)0),s);
 label_with_spaces = getBraceParam();
 PopSource();
 label = strdup_nobadchars(label_with_spaces);
 free(label_with_spaces);
 diagnostics(4, "LabelTag = <%s>", (label) ? label : "missing");
 return label;
}

variable_types:
label
char *


ExtractAndRemoveTag

decompiled_code:
char *__fastcall ExtractAndRemoveTag(char *needle, char *haystack)
{
char *v2; // rbx
char *v3; // rbp
char *v4; // r12
char *v5; // rbp
char *v6; // rbp
char *v7; // r12
char v8; // al

v3 = haystack;
diagnostics(5LL, "target tag = <%s>", needle);
diagnostics(5LL, "original text = <%s>", haystack);
do
{
if ( !v3 )
break;
v2 = strstr(v3, needle);
if ( !v2 )
return 0LL;
v3 = &v2[strlen(needle)];
if ( *v3 == 32 )
break;
}
while ( *v3 != 123 );
PushSource(0LL, v3);
v4 = (char *)getBraceParam();
PopSource();
if ( !v4 )
return 0LL;
v5 = strstr(v3, v4);
v6 = &v5[strlen(v4) + 1];
free(v4);
v7 = my_strndup(v2, v6 - v2);
v8 = *v6;
do
{
++v6;
*v2++ = v8;
v8 = *v6;
}
while ( *v6 );
*v2 = 0;
diagnostics(5LL, "final contents = <%s>", v7);
diagnostics(5LL, "final text = <%s>", haystack);
return v7;
}

canonical_decompiled_code:
char *__fastcall func10(char *needle, char *haystack)
{
char *v2; // rbx
char *v3; // rbp
char *v4; // r12
char *v5; // rbp
char *v6; // rbp
char *v7; // r12
char v8; // al

v3 = haystack;
diagnostics(5LL, "target tag = <%s>", needle);
diagnostics(5LL, "original text = <%s>", haystack);
do
{
if ( !v3 )
break;
v2 = strstr(v3, needle);
if ( !v2 )
return 0LL;
v3 = &v2[strlen(needle)];
if ( *v3 == 32 )
break;
}
while ( *v3 != 123 );
PushSource(0LL, v3);
v4 = (char *)getBraceParam();
PopSource();
if ( !v4 )
return 0LL;
v5 = strstr(v3, v4);
v6 = &v5[strlen(v4) + 1];
free(v4);
v7 = func3(v2, v6 - v2);
v8 = *v6;
do
{
++v6;
*v2++ = v8;
v8 = *v6;
}
while ( *v6 );
*v2 = 0;
diagnostics(5LL, "final contents = <%s>", v7);
diagnostics(5LL, "final text = <%s>", haystack);
return v7;
}

original_code:
char *
ExtractAndRemoveTag(char *tag, char *text)
{
 char *s, *contents, *start, *end;
 s = text;
 diagnostics(5, "target tag = <%s>", tag);
 diagnostics(5, "original text = <%s>", text);
 while (s) {
  start = strstr(s,tag);
  if (!start) return ((void *)0);
  s = start+strlen(tag);
  if (*s == ' ' || *s == '{') break;
 }
 PushSource(((void *)0),s);
 contents = getBraceParam();
 PopSource();
    if (!contents) return ((void *)0);
    end = strstr(s,contents)+strlen(contents)+1;
 free(contents);
 contents = my_strndup(start,(size_t) (end-start));
    do *start++=*end++; while (*end);
 *start='\0';
 diagnostics(5, "final contents = <%s>", contents);
 diagnostics(5, "final text = <%s>", text);
 return contents;
}

canonical_original_code:
char *ExtractAndRemoveTag(char *tag, char *text)
{
 char *s; char *contents; char *start; char *end;
 s = text;
 diagnostics(5, "target tag = <%s>", tag);
 diagnostics(5, "original text = <%s>", text);
 while (s) {
  start = strstr(s,tag);
  if (!start) return ((void *)0);
  s = start+strlen(tag);
  if (*s == ' ' || *s == '{') break;
 }
 PushSource(((void *)0),s);
 contents = getBraceParam();
 PopSource();
    if (!contents) return ((void *)0);
    end = strstr(s,contents)+strlen(contents)+1;
 free(contents);
 contents = my_strndup(start,(unsigned long) (end-start));
    do *start++=*end++; while (*end);
 *start='\0';
 diagnostics(5, "final contents = <%s>", contents);
 diagnostics(5, "final text = <%s>", text);
 return contents;
}

variable_types:
tag
char *

variable_types:
contents
char *

variable_types:
start
char *

variable_types:
end
char *


existsCounter

decompiled_code:
__int64 __fastcall existsCounter(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

v1 = iCounterCount;
if ( iCounterCount <= 0 )
{
v3 = 0;
LABEL_7:
if ( v1 == v3 )
v3 = -1;
result = v3;
}
else
{
v2 = 0LL;
while ( !strstr((const char *)Counters[2 * v2], needle) )
{
v3 = ++v2;
if ( v2 == v1 )
goto LABEL_7;
}
result = (unsigned int)v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

v1 = iCounterCount;
if ( iCounterCount <= 0 )
{
v3 = 0;
LABEL_7:
if ( v1 == v3 )
v3 = -1;
result = v3;
}
else
{
v2 = 0LL;
while ( !strstr((const char *)Counters[2 * v2], needle) )
{
v3 = ++v2;
if ( v2 == v1 )
goto LABEL_7;
}
result = (unsigned int)v2;
}
return result;
}

original_code:
static int
existsCounter(char * s)
{
 int i=0;
 while(i < iCounterCount && strstr(Counters[i].name,s)==((void *)0))
  i++;
 if (i==iCounterCount)
  return -1;
 else
  return i;
}

canonical_original_code:
static int existsCounter(char *s)
{
 int i = 0;
 while(i < iCounterCount && strstr(Counters[i].name,s)==((void *)0))
  i++;
 if (i==iCounterCount)
  return -1;
 else
  return i;
}

variable_types: i int


newCounter

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

if ( iCounterCount == 50 )
return fprintf(stderr, "Too many counters, ignoring %s", a1);
v2 = 2LL * iCounterCount;
LODWORD(Counters[v2 + 1]) = a2;
v3 = my_strdup();
v4 = iCounterCount;
Counters[v2] = v3;
if ( !Counters[2 * v4] )
{
fprintf(stderr, "\nCannot allocate name for counter \\%s\n", a1);
exit(1);
}
result = v4 + 1;
iCounterCount = v4 + 1;
return result;
}

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

if ( iCounterCount == 50 )
return fprintf(stderr, "Too many counters, ignoring %s", a1);
v2 = 2LL * iCounterCount;
LODWORD(Counters[v2 + 1]) = a2;
v3 = my_strdup();
v4 = iCounterCount;
Counters[v2] = v3;
if ( !Counters[2 * v4] )
{
fprintf(stderr, "\nCannot allocate name for counter \\%s\n", a1);
exit(1);
}
result = v4 + 1;
iCounterCount = v4 + 1;
return result;
}

original_code:
static void
newCounter(char *s, int n)
{
 if (iCounterCount==50){
  fprintf(stderr,"Too many counters, ignoring %s", s);
  return;
 }
 Counters[iCounterCount].number=n;
 Counters[iCounterCount].name=my_strdup(s);
 if (Counters[iCounterCount].name==((void *)0)) {
  fprintf(stderr, "\nCannot allocate name for counter \\%s\n", s);
  exit(1);
 }
 iCounterCount++;
}


incrementCounter

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

v1 = existsCounter(a1);
if ( v1 < 0 )
{
LODWORD(v2) = newCounter(a1, 1);
}
else
{
v2 = 16LL * v1;
++LODWORD(Counters[v2 / 8 + 1]);
}
return v2;
}

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

v1 = func0(a1);
if ( v1 < 0 )
{
LODWORD(v2) = func1(a1, 1);
}
else
{
v2 = 16LL * v1;
++LODWORD(Counters[v2 / 8 + 1]);
}
return v2;
}

original_code:
void
incrementCounter(char * s)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, 1);
 else
  Counters[i].number++;
}

canonical_original_code:
void incrementCounter(char *s)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, 1);
 else
  Counters[i].number++;
}


setCounter

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

v2 = existsCounter(a1);
if ( v2 < 0 )
{
LODWORD(v3) = newCounter(a1, a2);
}
else
{
v3 = 16LL * v2;
LODWORD(Counters[v3 / 8 + 1]) = a2;
}
return v3;
}

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

v2 = func0(a1);
if ( v2 < 0 )
{
LODWORD(v3) = func1(a1, a2);
}
else
{
v3 = 16LL * v2;
LODWORD(Counters[v3 / 8 + 1]) = a2;
}
return v3;
}

original_code:
void
setCounter(char * s, int n)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, n);
 else
  Counters[i].number = n;
}

canonical_original_code:
void setCounter(char *s, int n)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, n);
 else
  Counters[i].number = n;
}


getCounter

decompiled_code:
__int64 __fastcall getCounter(char *a1)
{
int v1; // eax

v1 = existsCounter(a1);
if ( v1 >= 0 )
return LODWORD(Counters[2 * v1 + 1]);
fprintf(stderr, "No counter of type <%s>", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
int v1; // eax

v1 = func0(a1);
if ( v1 >= 0 )
return LODWORD(Counters[2 * v1 + 1]);
fprintf(stderr, "No counter of type <%s>", a1);
return 0LL;
}

original_code:
int
getCounter(char * s)
{
 int i;
 i = existsCounter(s);
 if (i<0) {
  fprintf(stderr, "No counter of type <%s>", s);
  return 0;
 }
 return Counters[i].number;
}

canonical_original_code:
int getCounter(char *s)
{
 int i;
 i = existsCounter(s);
 if (i<0) {
  fprintf(stderr, "No counter of type <%s>", s);
  return 0;
 }
 return Counters[i].number;
}


CallCommandFunc

decompiled_code:
int __fastcall CallCommandFunc(char *s2)
{
int v2; // eax
__int64 v3; // r12
const char **v4; // r15
unsigned int v5; // ebx
__int64 v6; // r14
const char *v7; // rdi
int result; // eax
const char *v9; // rcx
char *v10; // rbp

diagnostics(5LL, "CallCommandFunc <%s>, iEnvCount = %d", s2, (unsigned int)iEnvCount);
v2 = existsDefinition(s2);
if ( v2 >= 0 )
{
v10 = (char *)expandDefinition((unsigned int)v2);
diagnostics(3LL, "CallCommandFunc <%s> expanded to <%s>", s2, v10);
ConvertString(v10);
free(v10);
result = 1;
}
else
{
LODWORD(v3) = iEnvCount - 1;
if ( iEnvCount - 1 < 0 )
{
LABEL_14:
result = 0;
}
else
{
v3 = (int)v3;
while ( 1 )
{
v4 = (const char **)Environments[v3];
v5 = 0;
v6 = 0LL;
v7 = *v4;
if ( **v4 )
break;
LABEL_13:
if ( (int)--v3 < 0 )
goto LABEL_14;
}
while ( 1 )
{
result = strcmp(v7, s2);
if ( !result )
break;
v6 += 3LL;
++v5;
v7 = v4[v6];
if ( !*v7 )
goto LABEL_13;
}
v9 = v4[v6 + 1];
if ( v9 )
{
if ( v9 == (const char *)&CmdIgnoreParameter )
{
diagnostics(1LL, "Command \\%s ignored", s2);
v4 = (const char **)Environments[(int)v3];
}
diagnostics(5LL, "CallCommandFunc Found %s iEnvCount=%d number=%d", v4[v6], (unsigned int)v3, v5);
(*(void (__fastcall **)(_QWORD))(Environments[(int)v3] + v6 * 8 + 8))(*(unsigned int *)(Environments[(int)v3]
+ v6 * 8
+ 16));
result = 1;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s2)
{
int v2; // eax
__int64 v3; // r12
const char **v4; // r15
unsigned int v5; // ebx
__int64 v6; // r14
const char *v7; // rdi
int result; // eax
const char *v9; // rcx
char *v10; // rbp

diagnostics(5LL, "CallCommandFunc <%s>, iEnvCount = %d", s2, (unsigned int)iEnvCount);
v2 = existsDefinition(s2);
if ( v2 >= 0 )
{
v10 = (char *)expandDefinition((unsigned int)v2);
diagnostics(3LL, "CallCommandFunc <%s> expanded to <%s>", s2, v10);
ConvertString(v10);
free(v10);
result = 1;
}
else
{
LODWORD(v3) = iEnvCount - 1;
if ( iEnvCount - 1 < 0 )
{
LABEL_14:
result = 0;
}
else
{
v3 = (int)v3;
while ( 1 )
{
v4 = (const char **)Environments[v3];
v5 = 0;
v6 = 0LL;
v7 = *v4;
if ( **v4 )
break;
LABEL_13:
if ( (int)--v3 < 0 )
goto LABEL_14;
}
while ( 1 )
{
result = strcmp(v7, s2);
if ( !result )
break;
v6 += 3LL;
++v5;
v7 = v4[v6];
if ( !*v7 )
goto LABEL_13;
}
v9 = v4[v6 + 1];
if ( v9 )
{
if ( v9 == (const char *)&CmdIgnoreParameter )
{
diagnostics(1LL, "Command \\%s ignored", s2);
v4 = (const char **)Environments[(int)v3];
}
diagnostics(5LL, "CallCommandFunc Found %s iEnvCount=%d number=%d", v4[v6], (unsigned int)v3, v5);
(*(void (__fastcall **)(_QWORD))(Environments[(int)v3] + v6 * 8 + 8))(*(unsigned int *)(Environments[(int)v3]
+ v6 * 8
+ 16));
result = 1;
}
}
}
return result;
}

original_code:
bool
CallCommandFunc(char *cCommand)
{
 int i, j;
 char * macro_string;
 diagnostics(5,"CallCommandFunc <%s>, iEnvCount = %d",cCommand,iEnvCount);
 i=existsDefinition(cCommand);
 if (i>-1) {
  macro_string=expandDefinition(i);
     diagnostics(3,"CallCommandFunc <%s> expanded to <%s>", cCommand, macro_string);
  ConvertString(macro_string);
  free(macro_string);
  return 1;
 }
 for (j = iEnvCount - 1; j >= 0; j--) {
  i = 0;
  while (strcmp(Environments[j][i].cpCommand, "") != 0) {
   if (strcmp(Environments[j][i].cpCommand, cCommand) == 0) {
    if (Environments[j][i].func == ((void *)0))
     return 0;
    if (*Environments[j][i].func == CmdIgnoreParameter) {
     diagnostics(1, "Command \\%s ignored", cCommand);
    }
   diagnostics(5,"CallCommandFunc Found %s iEnvCount=%d number=%d",Environments[j][i].cpCommand, j, i);
    (*Environments[j][i].func) ((Environments[j][i].param));
    return 1;
   }
   ++i;
  }
 }
 return 0;
}

canonical_original_code:
int CallCommandFunc(char *cCommand)
{
 int i; int j;
 char *macro_string;
 diagnostics(5,"CallCommandFunc <%s>, iEnvCount = %d",cCommand,iEnvCount);
 i=existsDefinition(cCommand);
 if (i>-1) {
  macro_string=expandDefinition(i);
     diagnostics(3,"CallCommandFunc <%s> expanded to <%s>", cCommand, macro_string);
  ConvertString(macro_string);
  free(macro_string);
  return 1;
 }
 for (j = iEnvCount - 1; j >= 0; j--) {
  i = 0;
  while (strcmp(Environments[j][i].cpCommand, "") != 0) {
   if (strcmp(Environments[j][i].cpCommand, cCommand) == 0) {
    if (Environments[j][i].func == ((void *)0))
     return 0;
    if (*Environments[j][i].func == CmdIgnoreParameter) {
     diagnostics(1, "Command \\%s ignored", cCommand);
    }
   diagnostics(5,"CallCommandFunc Found %s iEnvCount=%d number=%d",Environments[j][i].cpCommand, j, i);
    (*Environments[j][i].func) ((Environments[j][i].param));
    return 1;
   }
   ++i;
  }
 }
 return 0;
}

variable_types:
cCommand
char *

variable_types: j int


CallParamFunc

decompiled_code:
int __fastcall CallParamFunc(char *s2, unsigned int a2)
{
const char *v3; // rdi
int v4; // ebp
const char **v5; // rbx
int result; // eax
char **v7; // rdx
char *v8; // rax
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = "center";
v4 = 0;
v5 = (const char **)&off_5158;
do
{
result = strcmp(v3, s2);
if ( !result )
{
v7 = &(&params)[3 * v4];
v8 = v7[1];
if ( !v8 )
_assert_fail("params[i].func != NULL", "commands.c", 0x31Bu, "CallParamFunc");
return ((__int64 (__fastcall *)(_QWORD))v8)(a2 | *((_DWORD *)v7 + 4));
}
v3 = *v5;
++v4;
v5 += 3;
}
while ( *v3 );
if ( a2 == 0x4000 )
{
snprintf(v9, 0x64uLL, "\\%s%s%s", "end{", s2, "}");
Ignore_Environment(s2);
result = diagnostics(1LL, "Environment <%s> ignored. Not defined in commands.c", s2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *s2, unsigned int a2)
{
const char *v3; // rdi
int v4; // ebp
const char **v5; // rbx
int result; // eax
char **v7; // rdx
char *v8; // rax
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = "center";
v4 = 0;
v5 = (const char **)&off_5158;
do
{
result = strcmp(v3, s2);
if ( !result )
{
v7 = &(&params)[3 * v4];
v8 = v7[1];
if ( !v8 )
_assert_fail("params[i].func != NULL", "commands.c", 0x31Bu, "CallParamFunc");
return ((__int64 (__fastcall *)(_QWORD))v8)(a2 | *((_DWORD *)v7 + 4));
}
v3 = *v5;
++v4;
v5 += 3;
}
while ( *v3 );
if ( a2 == 0x4000 )
{
snprintf(v9, 0x64uLL, "\\%s%s%s", "end{", s2, "}");
Ignore_Environment(s2);
result = diagnostics(1LL, "Environment <%s> ignored. Not defined in commands.c", s2);
}
return result;
}

original_code:
void
CallParamFunc(char *cCommand, int AddParam)
{
 int i = 0;
 char unknown_environment[100];
 while (strcmp(params[i].cpCommand, "") != 0) {
  if (strcmp(params[i].cpCommand, cCommand) == 0) {
   ((void) sizeof ((params[i].func != ((void *)0)) ? 1 : 0), __extension__ ({ if (params[i].func != ((void *)0)) ; else __assert_fail ("params[i].func != NULL", "commands.c", 795, __extension__ __PRETTY_FUNCTION__); }));
   (*params[i].func) ((params[i].param) | AddParam);
   return;
  }
  ++i;
 }
 if (AddParam == 0x4000) {
  snprintf(unknown_environment, 100, "\\%s%s%s", "end{", cCommand, "}");
  Ignore_Environment(cCommand);
  diagnostics(1, "Environment <%s> ignored.  Not defined in commands.c", cCommand);
 }
}

variable_types: AddParam int


CurrentEnvironmentCount

decompiled_code:
__int64 CurrentEnvironmentCount()
{
return (unsigned int)iEnvCount;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)iEnvCount;
}

original_code:
int
CurrentEnvironmentCount(void)
{
 return iEnvCount;
}

canonical_original_code:
int CurrentEnvironmentCount()
{
 return iEnvCount;
}


PushEnvironment

decompiled_code:
__int64 __fastcall PushEnvironment(int a1)
{
__int64 v1; // rbp
int v2; // eax
int v3; // edx
__int64 v4; // rax
__int64 v5; // rdx
int v6; // ecx
const char *v7; // rdx
__int64 v8; // rcx

v1 = iEnvCount;
v2 = getLength("parindent");
v3 = g_left_margin_indent;
g_par_indent_array[v1] = v2;
v4 = iEnvCount;
g_left_indent_array[iEnvCount] = v3;
v5 = g_right_margin_indent;
g_right_indent_array[v4] = g_right_margin_indent;
v6 = v4;
switch ( a1 )
{
case 1:
Environments[v4] = (__int64)&PreambleCommands;
v7 = "preamble";
break;
case 2:
Environments[v4] = (__int64)&commands;
v7 = "document";
break;
case 3:
Environments[v4] = (__int64)&ItemizeCommands;
v7 = "itemize";
break;
case 4:
Environments[v4] = (__int64)&EnumerateCommands;
v7 = "enumerate";
break;
case 5:
Environments[v4] = (__int64)&DescriptionCommands;
v7 = "description";
break;
case 8:
Environments[v4] = (__int64)&LetterCommands;
v7 = "letter";
break;
case 9:
Environments[v4] = (__int64)&commands;
v7 = "*latex2rtf ignored*";
break;
case 10:
Environments[v4] = (__int64)&hyperlatex;
v7 = "hyperlatex";
break;
case 11:
Environments[v4] = (__int64)&FigureCommands;
v7 = "figure";
break;
case 12:
Environments[v4] = (__int64)&GermanModeCommands;
v7 = "german";
break;
case 13:
Environments[v4] = (__int64)&FrenchModeCommands;
v7 = "french";
break;
case 14:
Environments[v4] = (__int64)&RussianModeCommands;
v7 = "french";
break;
case 15:
Environments[v4] = (__int64)&commands;
v7 = "Generic Environment";
break;
case 16:
Environments[v4] = (__int64)&CzechModeCommands;
v7 = "french";
break;
case 17:
Environments[v4] = (__int64)&apaciteCommands;
v7 = "apacite";
break;
case 18:
Environments[v4] = (__int64)&natbibCommands;
v7 = "natbib";
break;
default:
diagnostics(0LL, "assertion failed at function PushEnvironment", v5, v4);
v6 = iEnvCount;
v7 = (const char *)&unk_40A1;
break;
}
v8 = (unsigned int)(v6 + 1);
iEnvCount = v8;
return diagnostics(3LL, "Entered %s environment, iEnvCount now = %d", v7, v8);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rbp
int v2; // eax
int v3; // edx
__int64 v4; // rax
__int64 v5; // rdx
int v6; // ecx
const char *v7; // rdx
__int64 v8; // rcx

v1 = iEnvCount;
v2 = getLength("parindent");
v3 = g_left_margin_indent;
g_par_indent_array[v1] = v2;
v4 = iEnvCount;
g_left_indent_array[iEnvCount] = v3;
v5 = g_right_margin_indent;
g_right_indent_array[v4] = g_right_margin_indent;
v6 = v4;
switch ( a1 )
{
case 1:
Environments[v4] = (__int64)&PreambleCommands;
v7 = "preamble";
break;
case 2:
Environments[v4] = (__int64)&commands;
v7 = "document";
break;
case 3:
Environments[v4] = (__int64)&ItemizeCommands;
v7 = "itemize";
break;
case 4:
Environments[v4] = (__int64)&EnumerateCommands;
v7 = "enumerate";
break;
case 5:
Environments[v4] = (__int64)&DescriptionCommands;
v7 = "description";
break;
case 8:
Environments[v4] = (__int64)&LetterCommands;
v7 = "letter";
break;
case 9:
Environments[v4] = (__int64)&commands;
v7 = "*latex2rtf ignored*";
break;
case 10:
Environments[v4] = (__int64)&hyperlatex;
v7 = "hyperlatex";
break;
case 11:
Environments[v4] = (__int64)&FigureCommands;
v7 = "figure";
break;
case 12:
Environments[v4] = (__int64)&GermanModeCommands;
v7 = "german";
break;
case 13:
Environments[v4] = (__int64)&FrenchModeCommands;
v7 = "french";
break;
case 14:
Environments[v4] = (__int64)&RussianModeCommands;
v7 = "french";
break;
case 15:
Environments[v4] = (__int64)&commands;
v7 = "Generic Environment";
break;
case 16:
Environments[v4] = (__int64)&CzechModeCommands;
v7 = "french";
break;
case 17:
Environments[v4] = (__int64)&apaciteCommands;
v7 = "apacite";
break;
case 18:
Environments[v4] = (__int64)&natbibCommands;
v7 = "natbib";
break;
default:
diagnostics(0LL, "assertion failed at function PushEnvironment", v5, v4);
v6 = iEnvCount;
v7 = (const char *)&unk_40A1;
break;
}
v8 = (unsigned int)(v6 + 1);
iEnvCount = v8;
return diagnostics(3LL, "Entered %s environment, iEnvCount now = %d", v7, v8);
}

original_code:
void
PushEnvironment(int code)
{
 char *diag = "";
 g_par_indent_array[iEnvCount] = getLength("parindent");
 g_left_indent_array[iEnvCount] = g_left_margin_indent;
 g_right_indent_array[iEnvCount] = g_right_margin_indent;
 switch (code) {
 case 1:
  Environments[iEnvCount] = PreambleCommands;
  diag = "preamble";
  break;
 case 2:
  Environments[iEnvCount] = commands;
  diag = "document";
  break;
 case 3:
  Environments[iEnvCount] = ItemizeCommands;
  diag = "itemize";
  break;
 case 4:
  Environments[iEnvCount] = EnumerateCommands;
  diag = "enumerate";
  break;
 case 8:
  Environments[iEnvCount] = LetterCommands;
  diag = "letter";
  break;
 case 5:
  Environments[iEnvCount] = DescriptionCommands;
  diag = "description";
  break;
 case 12:
  Environments[iEnvCount] = GermanModeCommands;
  diag = "german";
  break;
 case 13:
  Environments[iEnvCount] = FrenchModeCommands;
  diag = "french";
  break;
 case 14:
  Environments[iEnvCount] = RussianModeCommands;
  diag = "french";
   break;
 case 16:
  Environments[iEnvCount] = CzechModeCommands;
  diag = "french";
  break;
 case 11:
  Environments[iEnvCount] = FigureCommands;
  diag = "figure";
  break;
 case 9:
  Environments[iEnvCount] = commands;
  diag = "*latex2rtf ignored*";
  break;
 case 10:
  Environments[iEnvCount] = hyperlatex;
  diag = "hyperlatex";
  break;
 case 17:
  Environments[iEnvCount] = apaciteCommands;
  diag = "apacite";
  break;
 case 18:
  Environments[iEnvCount] = natbibCommands;
  diag = "natbib";
  break;
 case 15:
  Environments[iEnvCount] = commands;
  diag = "Generic Environment";
  break;
 default:
  diagnostics(0,"assertion failed at function PushEnvironment");
 }
 iEnvCount++;
 diagnostics(3, "Entered %s environment, iEnvCount now = %d", diag, iEnvCount);
}

variable_types: code int

variable_types:
diag
char *


PopEnvironment

decompiled_code:
__int64 PopEnvironment()
{
__int64 v0; // rsi
int v1; // eax

v0 = (unsigned int)g_par_indent_array[--iEnvCount];
Environments[iEnvCount] = 0LL;
setLength("parindent", v0);
v1 = g_right_indent_array[iEnvCount];
g_left_margin_indent = g_left_indent_array[iEnvCount];
g_right_margin_indent = v1;
return diagnostics(3LL, "Exited environment, iEnvCount now = %d", iEnvCount);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rsi
int v1; // eax

v0 = (unsigned int)g_par_indent_array[--iEnvCount];
Environments[iEnvCount] = 0LL;
setLength("parindent", v0);
v1 = g_right_indent_array[iEnvCount];
g_left_margin_indent = g_left_indent_array[iEnvCount];
g_right_margin_indent = v1;
return diagnostics(3LL, "Exited environment, iEnvCount now = %d", iEnvCount);
}

original_code:
void
PopEnvironment()
{
 --iEnvCount;
 Environments[iEnvCount] = ((void *)0);
 setLength("parindent",g_par_indent_array[iEnvCount]);
 g_left_margin_indent=g_left_indent_array[iEnvCount];
 g_right_margin_indent=g_right_indent_array[iEnvCount];
 diagnostics(3, "Exited environment, iEnvCount now = %d", iEnvCount);
 return;
}


ClearEnvironment

decompiled_code:
void ClearEnvironment()
{
Environments[0] = 0LL;
iEnvCount = 0;
}

canonical_decompiled_code:
void func5()
{
Environments[0] = 0LL;
iEnvCount = 0;
}

original_code:
void
ClearEnvironment()
{
 Environments[0] = ((void *)0);
 iEnvCount = 0;
 return;
}


existsLength

decompiled_code:
__int64 __fastcall existsLength(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

v1 = iLengthCount;
if ( iLengthCount <= 0 )
{
v3 = 0;
LABEL_7:
if ( v1 == v3 )
v3 = -1;
result = v3;
}
else
{
v2 = 0LL;
while ( !strstr((const char *)Lengths[2 * v2], needle) )
{
v3 = ++v2;
if ( v2 == v1 )
goto LABEL_7;
}
result = (unsigned int)v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

v1 = iLengthCount;
if ( iLengthCount <= 0 )
{
v3 = 0;
LABEL_7:
if ( v1 == v3 )
v3 = -1;
result = v3;
}
else
{
v2 = 0LL;
while ( !strstr((const char *)Lengths[2 * v2], needle) )
{
v3 = ++v2;
if ( v2 == v1 )
goto LABEL_7;
}
result = (unsigned int)v2;
}
return result;
}

original_code:
static int
existsLength(char * s)
{
 int i=0;
 while(i < iLengthCount && strstr(Lengths[i].name,s)==((void *)0))
  i++;
 if (i==iLengthCount)
  return -1;
 else
  return i;
}

canonical_original_code:
static int existsLength(char *s)
{
 int i = 0;
 while(i < iLengthCount && strstr(Lengths[i].name,s)==((void *)0))
  i++;
 if (i==iLengthCount)
  return -1;
 else
  return i;
}

variable_types:
s
char *


newLength

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

if ( iLengthCount == 50 )
return diagnostics(1LL, "Too many lengths, ignoring %s", a1);
v2 = 2LL * iLengthCount;
LODWORD(Lengths[v2 + 1]) = a2;
v3 = my_strdup();
v4 = iLengthCount;
Lengths[v2] = v3;
if ( !Lengths[2 * v4] )
{
fprintf(stderr, "\nCannot allocate name for length \\%s\n", a1);
exit(1);
}
result = (unsigned int)(v4 + 1);
iLengthCount = v4 + 1;
return result;
}

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

if ( iLengthCount == 50 )
return diagnostics(1LL, "Too many lengths, ignoring %s", a1);
v2 = 2LL * iLengthCount;
LODWORD(Lengths[v2 + 1]) = a2;
v3 = my_strdup();
v4 = iLengthCount;
Lengths[v2] = v3;
if ( !Lengths[2 * v4] )
{
fprintf(stderr, "\nCannot allocate name for length \\%s\n", a1);
exit(1);
}
result = (unsigned int)(v4 + 1);
iLengthCount = v4 + 1;
return result;
}

original_code:
static void
newLength(char *s, int d)
{
 if (iLengthCount==50){
  diagnostics(1,"Too many lengths, ignoring %s", s);
  return;
 }
 Lengths[iLengthCount].distance=d;
 Lengths[iLengthCount].name=my_strdup(s);
 if (Lengths[iLengthCount].name==((void *)0)) {
  fprintf(stderr, "\nCannot allocate name for length \\%s\n", s);
  exit(1);
 }
 iLengthCount++;
}

variable_types: d int


setLength

decompiled_code:
__int64 __fastcall setLength(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax

v2 = existsLength(a1);
if ( v2 < 0 )
return newLength(a1, a2);
result = 2LL * v2;
LODWORD(Lengths[result + 1]) = a2;
return result * 8;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax

v2 = func0(a1);
if ( v2 < 0 )
return func1(a1, a2);
result = 2LL * v2;
LODWORD(Lengths[result + 1]) = a2;
return result * 8;
}

original_code:
void
setLength(char * s, int d)
{
 int i;
 i = existsLength(s);
 if (i<0)
  newLength(s, d);
 else
  Lengths[i].distance = d;
}

canonical_original_code:
void setLength(char *s, int d)
{
 int i;
 i = existsLength(s);
 if (i<0)
  newLength(s, d);
 else
  Lengths[i].distance = d;
}


getLength

decompiled_code:
__int64 __fastcall getLength(char *a1)
{
int v1; // eax

v1 = existsLength(a1);
if ( v1 >= 0 )
return LODWORD(Lengths[2 * v1 + 1]);
diagnostics(1LL, "No length of type %s", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
int v1; // eax

v1 = func0(a1);
if ( v1 >= 0 )
return LODWORD(Lengths[2 * v1 + 1]);
diagnostics(1LL, "No length of type %s", a1);
return 0LL;
}

original_code:
int
getLength(char * s)
{
 int i;
 i = existsLength(s);
 if (i<0) {
  diagnostics(1, "No length of type %s", s);
  return 0;
 }
 return Lengths[i].distance;
}

canonical_original_code:
int getLength(char *s)
{
 int i;
 i = existsLength(s);
 if (i<0) {
  diagnostics(1, "No length of type %s", s);
  return 0;
 }
 return Lengths[i].distance;
}


CmdSetTexLength

decompiled_code:
__int64 __fastcall CmdSetTexLength(int a1)
{
char v1; // al
__int64 v2; // rbp
__int64 result; // rax

v1 = getNonSpace();
if ( v1 == 61 )
skipSpaces();
else
ungetTexChar((unsigned int)v1);
v2 = (unsigned int)getDimension();
result = diagnostics(4LL, "CmdSetTexLength size = %d", v2);
switch ( a1 )
{
case 1:
result = setLength("hoffset", v2);
break;
case 2:
result = setLength("voffset", v2);
break;
case 3:
result = setLength("parindent", v2);
break;
case 4:
result = setLength("parskip", v2);
break;
case 5:
result = setLength("baselineskip", v2);
break;
case 6:
result = setLength("topmargin", v2);
break;
case 7:
result = setLength("textheight", v2);
break;
case 8:
result = setLength("headheight", v2);
break;
case 9:
result = setLength("headsep", v2);
break;
case 10:
result = setLength("textwidth", v2);
break;
case 11:
result = setLength("oddsidemargin", v2);
break;
case 12:
result = setLength("evensidemargin", v2);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
char v1; // al
__int64 v2; // rbp
__int64 result; // rax

v1 = getNonSpace();
if ( v1 == 61 )
skipSpaces();
else
ungetTexChar((unsigned int)v1);
v2 = (unsigned int)getDimension();
result = diagnostics(4LL, "CmdSetTexLength size = %d", v2);
switch ( a1 )
{
case 1:
result = func2("hoffset", v2);
break;
case 2:
result = func2("voffset", v2);
break;
case 3:
result = func2("parindent", v2);
break;
case 4:
result = func2("parskip", v2);
break;
case 5:
result = func2("baselineskip", v2);
break;
case 6:
result = func2("topmargin", v2);
break;
case 7:
result = func2("textheight", v2);
break;
case 8:
result = func2("headheight", v2);
break;
case 9:
result = func2("headsep", v2);
break;
case 10:
result = func2("textwidth", v2);
break;
case 11:
result = func2("oddsidemargin", v2);
break;
case 12:
result = func2("evensidemargin", v2);
break;
default:
return result;
}
return result;
}

original_code:
void
CmdSetTexLength(int code)
{
 int d;
 char c;
 c = getNonSpace();
 if (c == '=')
  skipSpaces();
 else
  ungetTexChar(c);
 d = getDimension();
 diagnostics(4, "CmdSetTexLength size = %d",d);
  switch (code){
  case 1:
   setLength("hoffset",d);
   break;
  case 2:
   setLength("voffset",d);
   break;
  case 3:
   setLength("parindent",d);
   break;
  case 4:
   setLength("parskip",d);
   break;
  case 5:
   setLength("baselineskip",d);
   break;
  case 6:
   setLength("topmargin",d);
   break;
  case 7:
   setLength("textheight",d);
   break;
  case 8:
   setLength("headheight",d);
   break;
  case 9:
   setLength("headsep",d);
   break;
  case 10:
   setLength("textwidth",d);
   break;
  case 11:
   setLength("oddsidemargin",d);
   break;
  case 12:
   setLength("evensidemargin",d);
   break;
 }
}

variable_types: c char


decompiled_code:
int __fastcall cfg_compare(const void *a1, const void *a2)
{
return strcmp(**(const char ***)a1, **(const char ***)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(**(const char ***)a1, **(const char ***)a2);
}

original_code:
static int cfg_compare(ConfigEntryT ** el1, ConfigEntryT ** el2)
{
 return strcmp((*el1)->TexCommand, (*el2)->TexCommand);
}

canonical_original_code:
static int cfg_compare(struct ConfigEntryT **el1, struct ConfigEntryT **el2)
{
 return strcmp((*el1)->TexCommand, (*el2)->TexCommand);
}

variable_types: struct ConfigEntryT { char *TexCommand; char *RtfCommand; } **


decompiled_code:
void *__fastcall search_rtf(__int64 a1, unsigned int a2)
{
char **v2; // rsi
__int64 *key; // [rsp+8h] [rbp-20h] BYREF
__int64 v5[3]; // [rsp+10h] [rbp-18h] BYREF

v5[0] = a1;
v5[1] = (__int64)&unk_9AD;
key = v5;
if ( a2 > 4 )
_assert_fail("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 0x12Bu, "search_rtf");
v2 = &(&configinfo)[4 * (int)a2];
if ( !v2[1] )
_assert_fail("configinfo[WhichCfg].config_info != NULL", "cfg.c", 0x12Cu, "search_rtf");
return bsearch(&key, v2[1], (size_t)v2[2], 8uLL, cfg_compare);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, unsigned int a2)
{
char **v2; // rsi
__int64 *key; // [rsp+8h] [rbp-20h] BYREF
__int64 v5[3]; // [rsp+10h] [rbp-18h] BYREF

v5[0] = a1;
v5[1] = (__int64)&unk_9AD;
key = v5;
if ( a2 > 4 )
_assert_fail("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 0x12Bu, "search_rtf");
v2 = &(&configinfo)[4 * (int)a2];
if ( !v2[1] )
_assert_fail("configinfo[WhichCfg].config_info != NULL", "cfg.c", 0x12Cu, "search_rtf");
return bsearch(&key, v2[1], (size_t)v2[2], 8uLL, cfg_compare);
}

original_code:
static ConfigEntryT **
search_rtf(const char *theTexCommand, int WhichCfg)
{
 ConfigEntryT compare_item;
 ConfigEntryT *compare_ptr;
 compare_item.TexCommand = theTexCommand;
 compare_item.RtfCommand = "";
 compare_ptr = &compare_item;
 ((void) sizeof ((WhichCfg >= 0 && (size_t) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ? 1 : 0), __extension__ ({ if (WhichCfg >= 0 && (size_t) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ; else __assert_fail ("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 299, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((configinfo[WhichCfg].config_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (configinfo[WhichCfg].config_info != ((void *)0)) ; else __assert_fail ("configinfo[WhichCfg].config_info != NULL", "cfg.c", 300, __extension__ __PRETTY_FUNCTION__); }));
 return (ConfigEntryT **) bsearch
  (&compare_ptr
   ,configinfo[WhichCfg].config_info
   ,configinfo[WhichCfg].config_info_size
   ,sizeof(compare_ptr)
   ,(fptr) cfg_compare
  );
}

canonical_original_code:
static struct ConfigEntryT **search_rtf(char *theTexCommand, int WhichCfg)
{
 struct ConfigEntryT compare_item;
 struct ConfigEntryT *compare_ptr;
 compare_item.TexCommand = theTexCommand;
 compare_item.RtfCommand = "";
 compare_ptr = &compare_item;
 ((void) sizeof ((WhichCfg >= 0 && (unsigned long) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ? 1 : 0), __extension__ ({ if (WhichCfg >= 0 && (unsigned long) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ; else __assert_fail ("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 299, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((configinfo[WhichCfg].config_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (configinfo[WhichCfg].config_info != ((void *)0)) ; else __assert_fail ("configinfo[WhichCfg].config_info != NULL", "cfg.c", 300, __extension__ __PRETTY_FUNCTION__); }));
 return (struct ConfigEntryT **) bsearch
  (&compare_ptr
   ,configinfo[WhichCfg].config_info
   ,configinfo[WhichCfg].config_info_size
   ,sizeof(compare_ptr)
   ,(int (*)(void *, void *)) cfg_compare
  );
}

variable_types:
theTexCommand
char *

variable_types: WhichCfg int

return_type: struct ConfigEntryT { char *TexCommand; char *RtfCommand; } **


SearchRtfIndex

decompiled_code:
__int64 __fastcall SearchRtfIndex(__int64 a1, unsigned int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = search_rtf(a1, a2);
if ( v2 )
result = ((__int64)v2 - qword_8E8[4 * (int)a2]) >> 3;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = func1(a1, a2);
if ( v2 )
result = ((__int64)v2 - qword_8E8[4 * (int)a2]) >> 3;
else
result = 0LL;
return result;
}

original_code:
int
SearchRtfIndex(const char *theTexCommand, int WhichCfg)
{
 ConfigEntryT **help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0)) {
  return 0;
 }
 return help - configinfo[WhichCfg].config_info;
}

canonical_original_code:
int SearchRtfIndex(char *theTexCommand, int WhichCfg)
{
 struct ConfigEntryT **help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0)) {
  return 0;
 }
 return help - configinfo[WhichCfg].config_info;
}

user_defined_types: struct ConfigEntryT { char *TexCommand; char *RtfCommand; }


SearchRtfCmd

decompiled_code:
void *__fastcall SearchRtfCmd(__int64 a1, unsigned int a2)
{
void *result; // rax

result = search_rtf(a1, a2);
if ( result )
result = *(void **)(*(_QWORD *)result + 8LL);
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, unsigned int a2)
{
void *result; // rax

result = func1(a1, a2);
if ( result )
result = *(void **)(*(_QWORD *)result + 8LL);
return result;
}

original_code:
char *
SearchRtfCmd(const char *theTexCommand, int WhichCfg)
{
 ConfigEntryT **help;
 help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0))
  return ((void *)0);
 else
  return (char *)(*help)->RtfCommand;
}

canonical_original_code:
char *SearchRtfCmd(char *theTexCommand, int WhichCfg)
{
 struct ConfigEntryT **help;
 help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0))
  return ((void *)0);
 else
  return (char *)(*help)->RtfCommand;
}


CfgStartIterate

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

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

original_code:
ConfigEntryT **
CfgStartIterate(int WhichCfg)
{
 return ((void *)0);
}

canonical_original_code:
struct ConfigEntryT **CfgStartIterate(int WhichCfg)
{
 return ((void *)0);
}