decompiled_code:
__int64 __fastcall server_create(__int16 a1)
{
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
perror("Establishing socket");
}
else
{
v3.sa_family = 2;
*(_WORD *)v3.sa_data = _bswap_16(a1);
*(_DWORD *)&v3.sa_data[2] = _bswap_32(0);
if ( bind(v1, &v3, 0x10u) )
{
perror("binding receive socket");
v1 = -1;
}
else
{
listen(v1, 10);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
perror("Establishing socket");
}
else
{
v3.sa_family = 2;
*(_WORD *)v3.sa_data = func0(a1);
*(_DWORD *)&v3.sa_data[2] = func1(0);
if ( bind(v1, &v3, 0x10u) )
{
perror("binding receive socket");
v1 = -1;
}
else
{
listen(v1, 10);
}
}
return v1;
}

original_code:
int
server_create(short int port)
{
 int fd;
 struct sockaddr_in server;
 if ((fd = socket(2, SOCK_STREAM, 0)) == -1) {
  perror("Establishing socket");
  return -1;
 }
 server.sin_family = 2;
 server.sin_port = htons(port);
 server.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 if (bind(fd, (struct sockaddr *)&server, sizeof(server))) {
  perror("binding receive socket");
  return -1;
 }
 listen(fd, 10);
 return fd;
}

canonical_original_code:
int server_create(short port)
{
 int fd;
 struct sockaddr_in server;
 if ((fd = socket(2, SOCK_STREAM, 0)) == -1) {
  perror("Establishing socket");
  return -1;
 }
 server.sin_family = 2;
 server.sin_port = htons(port);
 server.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 if (bind(fd, (struct sockaddr *)&server, sizeof(server))) {
  perror("binding receive socket");
  return -1;
 }
 listen(fd, 10);
 return fd;
}

variable_types: port short

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

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

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


decompiled_code:
__int64 __fastcall server_accept(int a1)
{
unsigned int v1; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 == -1 )
perror("accept");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned int v1; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 == -1 )
perror("accept");
return v1;
}

original_code:
int
server_accept(int fd)
{
 struct sockaddr_in sai;
 int new_fd;
 unsigned int len = sizeof(sai);
 new_fd = accept(fd, (struct sockaddr *)&sai, &len);
 if (-1 == new_fd) {
  perror("accept");
  return -1;
 }
 return new_fd;
}

variable_types: fd int

variable_types:
len
unsigned int

return_type: int


decompiled_code:
char *__fastcall error_resp(char *s, int *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // rax
char *v5; // rbx
char v7[184]; // [rsp+0h] [rbp-B8h] BYREF

strcpy(
v7,
"<title>X-P</title>
X-P

Could not find content a"
"t %s.
");
v2 = strlen(v7);
v3 = strlen(s);
v4 = (char *)malloc(v2 + v3);
v5 = v4;
if ( v4 )
*a2 = sprintf(v4, v7, s);
return v5;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, int *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // rax
char *v5; // rbx
char v7[184]; // [rsp+0h] [rbp-B8h] BYREF

strcpy(
v7,
"<title>X-P</title>
X-P

Could not find content a"
"t %s.
");
v2 = strlen(v7);
v3 = strlen(s);
v4 = (char *)malloc(v2 + v3);
v5 = v4;
if ( v4 )
*a2 = sprintf(v4, v7, s);
return v5;
}

original_code:
char *
error_resp(char *path, int *len)
{
 const char eresponse[] = "<title>X-P</title>
X-P

Could not find content at %s.
";
 char *resp;
 int sz = strlen(eresponse) + strlen(path);
 resp = malloc(sz);
 if (!resp) return ((void *)0);
 *len = sprintf(resp, eresponse, path);
 return resp;
}

canonical_original_code:
char *error_resp(char *path, int *len)
{
 char eresponse[] = "<title>X-P</title>
X-P

Could not find content at %s.
";
 char *resp;
 int sz = strlen(eresponse) + strlen(path);
 resp = malloc(sz);
 if (!resp) return ((void *)0);
 *len = sprintf(resp, eresponse, path);
 return resp;
}

variable_types:
path
char *

variable_types:
len
int *

variable_types:
eresponse
char []

variable_types:
resp
char *

variable_types: sz int

return_type: char *


decompiled_code:
_BOOL8 __fastcall sanity_check(_BYTE *a1)
{
return (unsigned __int8)(*a1 - 46) <= 1u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_BYTE *a1)
{
return (unsigned __int8)(*a1 - 46) <= 1u;
}

original_code:
int
sanity_check(char *path)
{ return (path[0] == '.' || path[0] == '/'); }


decompiled_code:
char *__fastcall content_get(char *s, int *a2)
{
char *v2; // rbp
int v4; // er12
int v5; // er15
__off_t v6; // r13
__int64 v7; // rax
int v8; // eax
struct stat v9; // [rsp+0h] [rbp-C8h] BYREF

if ( !sanity_check(s) )
{
v4 = stat(s, &v9);
if ( !v4 && v9.st_size <= 10485760 )
{
v5 = open(s, 0);
if ( v5 >= 0 )
{
v6 = v9.st_size;
v2 = (char *)malloc(v9.st_size);
if ( v2 )
{
if ( v6 <= 0 )
{
LABEL_12:
*a2 = v6;
return v2;
}
v7 = 0LL;
while ( 1 )
{
v8 = read(v5, &v2[v4], v6 - v7);
if ( v8 < 0 )
break;
v4 += v8;
v7 = v4;
v6 = v9.st_size;
if ( v4 >= v9.st_size )
goto LABEL_12;
}
free(v2);
}
close(v5);
}
}
}
return error_resp(s, a2);
}

canonical_decompiled_code:
char *__fastcall func2(char *s, int *a2)
{
char *v2; // rbp
int v4; // er12
int v5; // er15
__off_t v6; // r13
__int64 v7; // rax
int v8; // eax
struct stat v9; // [rsp+0h] [rbp-C8h] BYREF

if ( !func1(s) )
{
v4 = stat(s, &v9);
if ( !v4 && v9.st_size <= 10485760 )
{
v5 = open(s, 0);
if ( v5 >= 0 )
{
v6 = v9.st_size;
v2 = (char *)malloc(v9.st_size);
if ( v2 )
{
if ( v6 <= 0 )
{
LABEL_12:
*a2 = v6;
return v2;
}
v7 = 0LL;
while ( 1 )
{
v8 = read(v5, &v2[v4], v6 - v7);
if ( v8 < 0 )
break;
v4 += v8;
v7 = v4;
v6 = v9.st_size;
if ( v4 >= v9.st_size )
goto LABEL_12;
}
free(v2);
}
close(v5);
}
}
}
return func0(s, a2);
}

original_code:
char *
content_get(char *path, int *content_len)
{
 char *resp;
 int content_fd, amnt_read = 0;
 struct stat s;
 if (sanity_check(path) ||
     stat(path, &s) ||
     s.st_size > (1024*1024*10)) goto err;
 content_fd = open(path, 00);
 if (content_fd < 0) goto err;
 resp = malloc(s.st_size);
 if (!resp) goto err_close;
 while (amnt_read < s.st_size) {
  int ret = read(content_fd, resp + amnt_read,
          s.st_size - amnt_read);
  if (ret < 0) goto err_free;
  amnt_read += ret;
 }
 *content_len = s.st_size;
 return resp;
err_free:
 free(resp);
err_close:
 close(content_fd);
err:
 return error_resp(path, content_len);
}

canonical_original_code:
char *content_get(char *path, int *content_len)
{
 char *resp;
 int content_fd; int amnt_read = 0;
 struct stat s;
 if (sanity_check(path) ||
     stat(path, &s) ||
     s.st_size > (1024*1024*10)) goto err;
 content_fd = open(path, 00);
 if (content_fd < 0) goto err;
 resp = malloc(s.st_size);
 if (!resp) goto err_close;
 while (amnt_read < s.st_size) {
  int ret = read(content_fd, resp + amnt_read,
          s.st_size - amnt_read);
  if (ret < 0) goto err_free;
  amnt_read += ret;
 }
 *content_len = s.st_size;
 return resp;
err_free:
 free(resp);
err_close:
 close(content_fd);
err:
 return error_resp(path, content_len);
}

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: 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]; }


repo: jeffhammond/HPCGloves

decompiled_code:
int __fastcall bli_foo(const void *a1)
{
return printf("thing=%p \n", a1);
}

canonical_decompiled_code:
int __fastcall func8(const void *a1)
{
return printf("thing=%p \n", a1);
}

original_code:
void bli_foo(obj_t * thing)
{
    printf("thing=%p \n", thing);
    return;
}

canonical_original_code:
void bli_foo(int *thing)
{
    printf("thing=%p \n", thing);
    return;
}

variable_types:
thing
int *

return_type: void


repo: jeffhammond/HPCInfo

decompiled_code:
__int64 __fastcall heavy_calcs(int a1)
{
__int64 result; // rax
int i; // eax

result = 1LL;
if ( a1 <= 1000 )
{
if ( a1 <= 0 )
{
result = 0LL;
}
else
{
for ( i = 0; i != a1; ++i )
;
result = 0LL;
}
}
return result;
}

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

result = 1LL;
if ( a1 <= 1000 )
{
if ( a1 <= 0 )
{
result = 0LL;
}
else
{
for ( i = 0; i != a1; ++i )
;
result = 0LL;
}
}
return result;
}

original_code:
int heavy_calcs(int n, float* restrict range1, float* restrict range2)
{
    if (n>1000) return 1;
    float tmpvalues[1000] = {0};
    {
        float * restrict ptv = tmpvalues;
        for (int i=0; i<n; i++) {
            ptv[i] = range1[i] + range2[i];
        }
    }
    return 0;
}

canonical_original_code:
int heavy_calcs(int n, float *range1, float *range2)
{
    if (n>1000) return 1;
    float tmpvalues[1000] = {0};
    {
        float *ptv = tmpvalues;
        for (int i = 0; i<n; i++) {
            ptv[i] = range1[i] + range2[i];
        }
    }
    return 0;
}

variable_types: n int

variable_types:
tmpvalues
float [1000]

variable_types:
ptv
float *

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
void *v4; // rbp
void *v5; // rbx
int v6; // er12

v3 = 1000;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = malloc(4LL * v3);
v5 = malloc(4LL * v3);
v6 = heavy_calcs(v3);
free(v4);
free(v5);
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
void *v4; // rbp
void *v5; // rbx
int v6; // er12

v3 = 1000;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = malloc(4LL * v3);
v5 = malloc(4LL * v3);
v6 = func7(v3);
free(v4);
free(v5);
return v6;
}

original_code:
int main(int argc, char * argv[])
{
    int n = (argc>1) ? atoi(argv[1]) : 1000;
    float * r1 = (float*)malloc(n*sizeof(float));
    float * r2 = (float*)malloc(n*sizeof(float));
    int rc = heavy_calcs(n,r1,r2);
    free(r1);
    free(r2);
    return rc;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int n = (argc>1) ? atoi(argv[1]) : 1000;
    float *r1 = (float*)malloc(n*sizeof(float));
    float *r2 = (float*)malloc(n*sizeof(float));
    int rc = heavy_calcs(n,r1,r2);
    free(r1);
    free(r2);
    return rc;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: rc int


myloc

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

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

original_code:
intptr_t myloc(void * address)
{
    return (intptr_t)address;
}

canonical_original_code:
long myloc(void *address)
{
    return (long)address;
}

variable_types:
address
void *

return_type: long


decompiled_code:
int __fastcall print2x(int a1, int a2, __int64 a3)
{
int result; // eax
unsigned int i; // ebp
__int64 v6; // rbx

if ( a1 > 0 )
{
result = 8 * a2;
for ( i = 0; i != a1; ++i )
{
v6 = 0LL;
if ( a2 > 0 )
{
do
{
result = printf("*(%d,%d)=%lf\n", i, (unsigned int)v6, *(double *)(a3 + 8 * v6));
++v6;
}
while ( v6 != a2 );
}
a3 += 8LL * a2;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2, __int64 a3)
{
int result; // eax
unsigned int i; // ebp
__int64 v6; // rbx

if ( a1 > 0 )
{
result = 8 * a2;
for ( i = 0; i != a1; ++i )
{
v6 = 0LL;
if ( a2 > 0 )
{
do
{
result = printf("*(%d,%d)=%lf\n", i, (unsigned int)v6, *(double *)(a3 + 8 * v6));
++v6;
}
while ( v6 != a2 );
}
a3 += 8LL * a2;
}
}
return result;
}

original_code:
void print2x(int m, int n, const double A[restrict m][n])
{
    for(int i=0; i<m; i++)
        for(int j=0; j<n; j++)
            printf("*(%d,%d)=%lf\n",i,j,A[i][j]);
}

canonical_original_code:
void print2x(int m, int n, double A[-1][-1])
{
    for(int i = 0; i<m; i++)
        for(int j = 0; j<n; j++)
            printf("*(%d,%d)=%lf\n",i,j,A[i][j]);
}

variable_types: m int

variable_types: j int


decompiled_code:
int __fastcall print2(int a1, int a2, __int64 a3)
{
int result; // eax
unsigned int i; // ebp
__int64 v6; // rbx

if ( a1 > 0 )
{
result = 8 * a2;
for ( i = 0; i != a1; ++i )
{
v6 = 0LL;
if ( a2 > 0 )
{
do
{
result = printf("(%d,%d)=%lf\n", i, (unsigned int)v6, *(double *)(a3 + 8 * v6));
++v6;
}
while ( v6 != a2 );
}
a3 += 8LL * a2;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2, __int64 a3)
{
int result; // eax
unsigned int i; // ebp
__int64 v6; // rbx

if ( a1 > 0 )
{
result = 8 * a2;
for ( i = 0; i != a1; ++i )
{
v6 = 0LL;
if ( a2 > 0 )
{
do
{
result = printf("(%d,%d)=%lf\n", i, (unsigned int)v6, *(double *)(a3 + 8 * v6));
++v6;
}
while ( v6 != a2 );
}
a3 += 8LL * a2;
}
}
return result;
}

original_code:
void print2(int m, int n, const double (* const restrict A)[n])
{
    for(int i=0; i<m; i++)
        for(int j=0; j<n; j++)
            printf("(%d,%d)=%lf\n",i,j,A[i][j]);
}

canonical_original_code:
void print2(int m, int n, double (*A)[-1])
{
    for(int i = 0; i<m; i++)
        for(int j = 0; j<n; j++)
            printf("(%d,%d)=%lf\n",i,j,A[i][j]);
}

variable_types:
A
double (*)[-1]


decompiled_code:
int __fastcall print1(int a1, int a2, __int64 a3)
{
int v3; // esi
__int64 i; // rbx
int result; // eax

v3 = a1 * a2;
if ( v3 > 0 )
{
for ( i = 0LL; i != v3; ++i )
result = printf("(%d)=%lf\n", (unsigned int)i, *(double *)(a3 + 8 * i));
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, __int64 a3)
{
int v3; // esi
__int64 i; // rbx
int result; // eax

v3 = a1 * a2;
if ( v3 > 0 )
{
for ( i = 0LL; i != v3; ++i )
result = printf("(%d)=%lf\n", (unsigned int)i, *(double *)(a3 + 8 * i));
}
return result;
}

original_code:
void print1(int m, int n, const double A[restrict])
{
    for(int i=0; i<(m*n); i++)
        printf("(%d)=%lf\n",i,A[i]);
}

canonical_original_code:
void print1(int m, int n, double A[])
{
    for(int i = 0; i<(m*n); i++)
        printf("(%d)=%lf\n",i,A[i]);
}

variable_types:
A
double []


main

original_code:
int main(int argc, char* argv[])
{
    int m = (argc>1) ? atoi(argv[1]) : 10;
    int n = (argc>2) ? atoi(argv[2]) : 5;
    double * restrict A = (double*)malloc(m*n*sizeof(double));
    for(int i=0; i<(m*n); i++)
        A[i] = (double)i;
    double (* const restrict B)[n] = (double (*)[n]) malloc(m*n*sizeof(double));
    for(int i=0; i<m; i++)
        for(int j=0; j<n; j++)
            B[i][j] = (double)(i*n+j);
    double (*C)[m][n] = malloc(m*n*sizeof(double));
    for(int i=0; i<m; i++)
        for(int j=0; j<n; j++)
            (*C)[i][j] = (double)(i*n+j);
    printf("A\n");
    print1(m,n,A);
    print2(m,n,(double (*)[n])A);
    printf("B\n");
    print1(m,n,(double * restrict)B);
    print2(m,n,B);
    printf("C\n");
    print1(m,n,(double * restrict)C);
    print2(m,n,(double (*)[n])C);
    print2x(m,n,(double (*)[n])C);
    free(C);
    free(B);
    free(A);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int m = (argc>1) ? atoi(argv[1]) : 10;
    int n = (argc>2) ? atoi(argv[2]) : 5;
    double *A = (double*)malloc(m*n*sizeof(double));
    for(int i = 0; i<(m*n); i++)
        A[i] = (double)i;
    double (*B)[-1] = (double (*)[n]) malloc(m*n*sizeof(double));
    for(int i = 0; i<m; i++)
        for(int j = 0; j<n; j++)
            B[i][j] = (double)(i*n+j);
    double (*C)[-1][-1] = malloc(m*n*sizeof(double));
    for(int i = 0; i<m; i++)
        for(int j = 0; j<n; j++)
            (*C)[i][j] = (double)(i*n+j);
    printf("A\n");
    print1(m,n,A);
    print2(m,n,(double (*)[-1])A);
    printf("B\n");
    print1(m,n,(double *)B);
    print2(m,n,B);
    printf("C\n");
    print1(m,n,(double *)C);
    print2(m,n,(double (*)[-1])C);
    print2x(m,n,(double (*)[-1])C);
    free(C);
    free(B);
    free(A);
    return 0;
}

variable_types:
A
double *

variable_types:
B
double (*)[-1]


getusec

decompiled_code:
double getusec()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_sec) * 1000000.0 + (double)SLODWORD(v1.tv_usec);
}

canonical_decompiled_code:
double func7()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_sec) * 1000000.0 + (double)SLODWORD(v1.tv_usec);
}

original_code:
double getusec(void)
{
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    double t = 1.e6 * tv.tv_sec + 1. * tv.tv_usec;
    return t;
}

canonical_original_code:
double getusec()
{
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    double t = 1.e6 * tv.tv_sec + 1. * tv.tv_usec;
    return t;
}

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

variable_types: t double

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
double v5; // xmm0_8
double v7; // [rsp+0h] [rbp-28h]
double v8; // [rsp+8h] [rbp-20h]

if ( argc <= 1 )
{
v8 = getusec();
v3 = 100000;
}
else
{
v3 = atoi(argv[1]);
v8 = getusec();
if ( v3 <= 0 )
{
v7 = 0.0;
goto LABEL_5;
}
}
v4 = 0;
v7 = 0.0;
do
{
v7 = getusec() + v7;
++v4;
}
while ( v4 < v3 );
LABEL_5:
v5 = getusec();
printf("dt = %lf s junk = %4.1e\n", (v5 - v8) * 0.000001, v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
double v5; // xmm0_8
double v7; // [rsp+0h] [rbp-28h]
double v8; // [rsp+8h] [rbp-20h]

if ( argc <= 1 )
{
v8 = func7();
v3 = 100000;
}
else
{
v3 = atoi(argv[1]);
v8 = func7();
if ( v3 <= 0 )
{
v7 = 0.0;
goto LABEL_5;
}
}
v4 = 0;
v7 = 0.0;
do
{
v7 = func7() + v7;
++v4;
}
while ( v4 < v3 );
LABEL_5:
v5 = func7();
printf("dt = %lf s junk = %4.1e\n", (v5 - v8) * 0.000001, v7);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
    int n = (argc>1) ? atoi(argv[1]) : 100000;
    double t0 = getusec();
    double junk = 0.0;
    for (int i=0; i<n; i++) {
        junk += getusec();
    }
    double t1 = getusec();
    printf("dt = %lf s junk = %4.1e\n", 1.e-6 * (t1-t0), junk);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int n = (argc>1) ? atoi(argv[1]) : 100000;
    double t0 = getusec();
    double junk = 0.0;
    for (int i = 0; i<n; i++) {
        junk += getusec();
    }
    double t1 = getusec();
    printf("dt = %lf s junk = %4.1e\n", 1.e-6 * (t1-t0), junk);
    return 0;
}

variable_types: junk double


decompiled_code:
int __fastcall print3(int a1, int a2, int a3, __int64 a4)
{
int result; // eax
unsigned int i; // er13
__int64 v7; // rbx
unsigned int v8; // ebp
__int64 v9; // r12

result = a3;
if ( a1 > 0 )
{
result = 8 * a2 * a3;
for ( i = 0; i != a1; ++i )
{
v9 = a4;
v8 = 0;
if ( a2 > 0 )
{
do
{
v7 = 0LL;
if ( a3 > 0 )
{
do
{
result = printf("(%d,%d,%d)=%lf\n", i, v8, (unsigned int)v7, *(double *)(v9 + 8 * v7));
++v7;
}
while ( a3 != v7 );
}
++v8;
v9 += 8LL * a3;
}
while ( a2 != v8 );
}
a4 += 8 * a2 * (__int64)a3;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2, int a3, __int64 a4)
{
int result; // eax
unsigned int i; // er13
__int64 v7; // rbx
unsigned int v8; // ebp
__int64 v9; // r12

result = a3;
if ( a1 > 0 )
{
result = 8 * a2 * a3;
for ( i = 0; i != a1; ++i )
{
v9 = a4;
v8 = 0;
if ( a2 > 0 )
{
do
{
v7 = 0LL;
if ( a3 > 0 )
{
do
{
result = printf("(%d,%d,%d)=%lf\n", i, v8, (unsigned int)v7, *(double *)(v9 + 8 * v7));
++v7;
}
while ( a3 != v7 );
}
++v8;
v9 += 8LL * a3;
}
while ( a2 != v8 );
}
a4 += 8 * a2 * (__int64)a3;
}
}
return result;
}

original_code:
void print3(int m, int n, int r, double (* const restrict A)[n][r])
{
    for(int i=0; i<m; i++)
        for(int j=0; j<n; j++)
            for(int k=0; k<r; k++)
                printf("(%d,%d,%d)=%lf\n",i,j,k,A[i][j][k]);
}

canonical_original_code:
void print3(int m, int n, int r, double (*A)[-1][-1])
{
    for(int i = 0; i<m; i++)
        for(int j = 0; j<n; j++)
            for(int k = 0; k<r; k++)
                printf("(%d,%d,%d)=%lf\n",i,j,k,A[i][j][k]);
}

variable_types: n int

variable_types: r int

variable_types: k int


decompiled_code:
int __fastcall print1(int a1, __int64 a2)
{
__int64 i; // rbx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
result = printf("(%d)=%lf\n", (unsigned int)i, *(double *)(a2 + 8 * i));
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, __int64 a2)
{
__int64 i; // rbx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
result = printf("(%d)=%lf\n", (unsigned int)i, *(double *)(a2 + 8 * i));
}
return result;
}

original_code:
void print1(int m, double A[])
{
    for(int i=0; i<m; i++)
        printf("(%d)=%lf\n",i,A[i]);
}

canonical_original_code:
void print1(int m, double A[])
{
    for(int i = 0; i<m; i++)
        printf("(%d)=%lf\n",i,A[i]);
}

variable_types: i int


original_code:
int main(int argc, char* argv[])
{
    int m = (argc>1) ? atoi(argv[1]) : 3;
    int n = (argc>2) ? atoi(argv[2]) : 4;
    int r = (argc>3) ? atoi(argv[3]) : 5;
    double * restrict A = (double*)malloc(m*n*r*sizeof(double));
    for(int i=0; i<(m*n*r); i++)
        A[i] = (double)i;
    double (* const restrict B)[n][r] = (double (*)[n][r]) malloc(m*n*r*sizeof(double));
    for(int i=0; i<m; i++)
        for(int j=0; j<n; j++)
            for(int k=0; k<r; k++)
                B[i][j][k] = (double)(i*n*r+j*r+k);
    print1(m*n*r,A);
    print3(m,n,r,(double (*)[n][r])A);
    print1(m*n*r,(double *)B);
    print3(m,n,r,B);
    free(B);
    free(A);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int m = (argc>1) ? atoi(argv[1]) : 3;
    int n = (argc>2) ? atoi(argv[2]) : 4;
    int r = (argc>3) ? atoi(argv[3]) : 5;
    double *A = (double*)malloc(m*n*r*sizeof(double));
    for(int i = 0; i<(m*n*r); i++)
        A[i] = (double)i;
    double (*B)[-1][-1] = (double (*)[n][r]) malloc(m*n*r*sizeof(double));
    for(int i = 0; i<m; i++)
        for(int j = 0; j<n; j++)
            for(int k = 0; k<r; k++)
                B[i][j][k] = (double)(i*n*r+j*r+k);
    print1(m*n*r,A);
    print3(m,n,r,(double (*)[-1][-1])A);
    print1(m*n*r,(double *)B);
    print3(m,n,r,B);
    free(B);
    free(A);
    return 0;
}

variable_types: argc int


repo: jeffkaufman/specserver

decompiled_code:
void __fastcall do_or_die(int a1, const char *a2)
{
if ( a1 == -1 )
{
perror(a2);
exit(-1);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, const char *a2)
{
if ( a1 == -1 )
{
perror(a2);
exit(-1);
}
}

original_code:
void do_or_die(int val, char* msg)
{
   if(val == -1)
   {
      perror(msg);
      exit(-1);
   }
}

canonical_original_code:
void do_or_die(int val, char *msg)
{
   if(val == -1)
   {
      perror(msg);
      exit(-1);
   }
}

variable_types: val int

variable_types:
msg
char *


original_code:
void build_commobj(struct spsv_commobj* sc)
{
   sc->slen = sizeof(struct sockaddr_in);
   sc->my_addr.sin_port = htons(8843);
   sc->my_addr.sin_family = 2;
   sc->my_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
   do_or_die(sc->fd = socket(2, SOCK_DGRAM, IPPROTO_UDP),
      "socket()");
   do_or_die(bind(sc->fd, (struct sockaddr*)&(sc->my_addr),
    sc->slen), "bind()");
}

canonical_original_code:
void build_commobj(struct spsv_commobj *sc)
{
   sc->slen = sizeof(struct sockaddr_in);
   sc->my_addr.sin_port = htons(8843);
   sc->my_addr.sin_family = 2;
   sc->my_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
   do_or_die(sc->fd = socket(2, SOCK_DGRAM, IPPROTO_UDP),
      "socket()");
   do_or_die(bind(sc->fd, (struct sockaddr *)&(sc->my_addr),
    sc->slen), "bind()");
}

variable_types: struct spsv_commobj { int fd; unsigned int slen; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } my_addr; struct sockaddr_in their_addr; } *

user_defined_types: struct spsv_commobj { int fd; unsigned int slen; struct sockaddr_in my_addr; struct sockaddr_in their_addr; }


decompiled_code:
int __fastcall wait_for_request_transmission(__int64 a1)
{
int v1; // eax
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

do
{
buf[0] = 0;
v1 = recvfrom(*(_DWORD *)a1, buf, 2uLL, 0, (struct sockaddr *)(a1 + 24), (socklen_t *)(a1 + 4));
do_or_die(v1, "server listen");
puts("Recieved data");
}
while ( buf[0] != 10998 );
return puts("Got good connection");
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
int v1; // eax
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

do
{
buf[0] = 0;
v1 = recvfrom(*(_DWORD *)a1, buf, 2uLL, 0, (struct sockaddr *)(a1 + 24), (socklen_t *)(a1 + 4));
func2(v1, "server listen");
puts("Recieved data");
}
while ( buf[0] != 10998 );
return puts("Got good connection");
}

original_code:
void wait_for_request_transmission(struct spsv_commobj* sc)
{
   short data;
   do
   {
      data = 0;
      do_or_die(recvfrom(sc->fd, (char*)&data,
       sizeof(data), 0,
       (struct sockaddr*)&(sc->their_addr),
       &(sc->slen)),
  "server listen");
      printf("Recieved data\n");
   } while(data != 0x2AF6);
   printf("Got good connection\n");
}

canonical_original_code:
void wait_for_request_transmission(struct spsv_commobj *sc)
{
   short data;
   do
   {
      data = 0;
      do_or_die(recvfrom(sc->fd, (char *)&data,
       sizeof(data), 0,
       (struct sockaddr *)&(sc->their_addr),
       &(sc->slen)),
  "server listen");
      printf("Recieved data\n");
   } while(data != 0x2AF6);
   printf("Got good connection\n");
}

variable_types: data short


decompiled_code:
void __fastcall send_data(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v5; // ebx
__int64 v6; // rax
float v7; // xmm0_4
int v8; // esi
bool v9; // cl
int v10; // eax
int v11; // eax
_DWORD v12[130]; // [rsp+0h] [rbp-240h] BYREF
struct sockaddr *addr; // [rsp+208h] [rbp-38h]

if ( a2 )
{
v5 = 0;
addr = (struct sockaddr *)(a1 + 24);
while ( 1 )
{
v12[0] = v5;
if ( a2 <= v5 )
break;
v6 = 2LL;
do
{
v7 = *(double *)(a3 + 8LL * v5) * *(double *)(a3 + 8LL * v5);
*(float *)&v12[v6 - 1] = v7;
v8 = v6;
++v5;
v9 = (int)v6++ <= 126;
}
while ( v5 < a2 && v9 );
v10 = sendto(*(_DWORD *)a1, v12, 4 * v8, 0, addr, *(_DWORD *)(a1 + 4));
do_or_die(v10, "sending datagram");
if ( v5 >= a2 )
return;
}
v11 = sendto(*(_DWORD *)a1, v12, 4uLL, 0, (const struct sockaddr *)(a1 + 24), *(_DWORD *)(a1 + 4));
do_or_die(v11, "sending datagram");
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v5; // ebx
__int64 v6; // rax
float v7; // xmm0_4
int v8; // esi
bool v9; // cl
int v10; // eax
int v11; // eax
_DWORD v12[130]; // [rsp+0h] [rbp-240h] BYREF
struct sockaddr *addr; // [rsp+208h] [rbp-38h]

if ( a2 )
{
v5 = 0;
addr = (struct sockaddr *)(a1 + 24);
while ( 1 )
{
v12[0] = v5;
if ( a2 <= v5 )
break;
v6 = 2LL;
do
{
v7 = *(double *)(a3 + 8LL * v5) * *(double *)(a3 + 8LL * v5);
*(float *)&v12[v6 - 1] = v7;
v8 = v6;
++v5;
v9 = (int)v6++ <= 126;
}
while ( v5 < a2 && v9 );
v10 = sendto(*(_DWORD *)a1, v12, 4 * v8, 0, addr, *(_DWORD *)(a1 + 4));
func2(v10, "sending datagram");
if ( v5 >= a2 )
return;
}
v11 = sendto(*(_DWORD *)a1, v12, 4uLL, 0, (const struct sockaddr *)(a1 + 24), *(_DWORD *)(a1 + 4));
func2(v11, "sending datagram");
}
}

original_code:
void send_data(struct spsv_commobj* sc,
        int len,
        double* data)
{
   int packet_len = 508/4;
   int packets_sent = 0;
   char buf[packet_len*4];
   unsigned int data_idx = 0;
   int i;
   for(packets_sent = 0 ; data_idx < len ; packets_sent++)
   {
      ((unsigned int*) buf)[0] = data_idx;
      for(i = 1; i < packet_len && data_idx < len; i++, data_idx++)
  ((float*)buf)[i]
     = (float)((data[data_idx])*(data[data_idx]));
      do_or_die(sendto(sc->fd, buf, i*4, 0,
         (struct sockaddr*)&(sc->their_addr),
         sc->slen),
  "sending datagram");
   }
}

canonical_original_code:
void send_data(struct spsv_commobj *sc, int len, double *data)
{
   int packet_len = 508/4;
   int packets_sent = 0;
   char buf[-1];
   unsigned int data_idx = 0;
   int i;
   for(packets_sent = 0 ; data_idx < len ; packets_sent++)
   {
      ((unsigned int *) buf)[0] = data_idx;
      for(i = 1; i < packet_len && data_idx < len; i++, data_idx++)
  ((float *)buf)[i]
     = (float)((data[data_idx])*(data[data_idx]));
      do_or_die(sendto(sc->fd, buf, i*4, 0,
         (struct sockaddr *)&(sc->their_addr),
         sc->slen),
  "sending datagram");
   }
}

variable_types: len int

variable_types:
data
double *

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall open_auddev(char *s)
{
int v1; // eax
unsigned int v2; // ebx
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = open(s, 0, 0LL);
if ( v1 == -1 )
{
perror(s);
exit(-1);
}
v2 = v1;
v5[0] = 16;
if ( ioctl(v1, 0xC0045005uLL, v5) == -1 )
{
perror("SNDCTL_DSP_SETFMT");
exit(-1);
}
if ( v5[0] != 16 )
{
fwrite("The device doesn't support the 16 bit sample format.\n", 1uLL, 0x35uLL, stderr);
exit(-1);
}
v5[0] = 1;
if ( ioctl(v2, 0xC0045006uLL, v5) == -1 )
{
perror("SNDCTL_DSP_CHANNELS");
exit(-1);
}
if ( v5[0] != 1 )
{
fwrite("The device doesn't support mono mode.\n", 1uLL, 0x26uLL, stderr);
exit(-1);
}
v4 = 44100;
if ( ioctl(v2, 0xC0045002uLL, &v4) == -1 )
{
perror("SNDCTL_DSP_SPEED");
exit(-1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s)
{
int v1; // eax
unsigned int v2; // ebx
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = open(s, 0, 0LL);
if ( v1 == -1 )
{
perror(s);
exit(-1);
}
v2 = v1;
v5[0] = 16;
if ( ioctl(v1, 0xC0045005uLL, v5) == -1 )
{
perror("SNDCTL_DSP_SETFMT");
exit(-1);
}
if ( v5[0] != 16 )
{
fwrite("The device doesn't support the 16 bit sample format.\n", 1uLL, 0x35uLL, stderr);
exit(-1);
}
v5[0] = 1;
if ( ioctl(v2, 0xC0045006uLL, v5) == -1 )
{
perror("SNDCTL_DSP_CHANNELS");
exit(-1);
}
if ( v5[0] != 1 )
{
fwrite("The device doesn't support mono mode.\n", 1uLL, 0x26uLL, stderr);
exit(-1);
}
v4 = 44100;
if ( ioctl(v2, 0xC0045002uLL, &v4) == -1 )
{
perror("SNDCTL_DSP_SPEED");
exit(-1);
}
return v2;
}

variable_types:
name
char *

variable_types: tmp int

variable_types: fd int


variable_types:
unwindowed
short *

variable_types:
windowed
double *


decompiled_code:
void __fastcall fill_buf(int fd, __int64 a2, int a3)
{
int v3; // er12
int i; // ebx
int v6; // eax

v3 = 22050 - a3;
if ( a3 > 0 )
{
for ( i = 0; i < a3; i += v6 )
{
v6 = read(fd, (void *)(a2 + 2 * (v3 + (__int64)i)), a3 - i);
if ( v6 == -1 )
{
perror("buffer fill fail");
exit(-1);
}
}
}
}

canonical_decompiled_code:
void __fastcall func9(int fd, __int64 a2, int a3)
{
int v3; // er12
int i; // ebx
int v6; // eax

v3 = 22050 - a3;
if ( a3 > 0 )
{
for ( i = 0; i < a3; i += v6 )
{
v6 = read(fd, (void *)(a2 + 2 * (v3 + (__int64)i)), a3 - i);
if ( v6 == -1 )
{
perror("buffer fill fail");
exit(-1);
}
}
}
}

original_code:
void fill_buf(int fd, short* buf, int num_samples)
{
   int amt = 0;
   int incr = 0;
   int offset = (44100>>1) - num_samples;
   while(amt < num_samples)
   {
      incr = read(fd, buf + offset + amt, num_samples - amt);
      if (incr == -1)
      {
  perror ("buffer fill fail");
  exit (-1);
      }
      amt += incr;
   }
}

canonical_original_code:
void fill_buf(int fd, short *buf, int num_samples)
{
   int amt = 0;
   int incr = 0;
   int offset = (44100>>1) - num_samples;
   while(amt < num_samples)
   {
      incr = read(fd, buf + offset + amt, num_samples - amt);
      if (incr == -1)
      {
  perror ("buffer fill fail");
  exit (-1);
      }
      amt += incr;
   }
}

variable_types:
buf
short *

variable_types: amt int

variable_types: incr int

variable_types: offset int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc != 2 )
{
puts("Usage: specserver <devname>");
exit(-1);
}
v3 = open_auddev((char *)argv[1]);
puts("Audio device opened, waiting for contact");
build_commobj((__int64)v4);
wait_for_request_transmission((__int64)v4);
sense(v3, (__int64)v4);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc != 2 )
{
puts("Usage: specserver <devname>");
exit(-1);
}
v3 = func6((char *)argv[1]);
puts("Audio device opened, waiting for contact");
func3((__int64)v4);
func4((__int64)v4);
func10(v3, (__int64)v4);
}

original_code:
int main(int argc, char** argv)
{
   char* dev_name;
   int aud_fd;
   struct spsv_commobj sc;
   if (argc != 2)
   {
      printf("Usage: specserver <devname>\n");
      exit(-1);
   }
   dev_name = argv[1];
   aud_fd = open_auddev(dev_name);
   printf("Audio device opened, waiting for contact\n");
   build_commobj(&sc);
   wait_for_request_transmission(&sc);
   sense(aud_fd, &sc);
   return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
   char *dev_name;
   int aud_fd;
   struct spsv_commobj sc;
   if (argc != 2)
   {
      printf("Usage: specserver <devname>\n");
      exit(-1);
   }
   dev_name = argv[1];
   aud_fd = open_auddev(dev_name);
   printf("Audio device opened, waiting for contact\n");
   build_commobj(&sc);
   wait_for_request_transmission(&sc);
   sense(aud_fd, &sc);
   return 1;
}

variable_types: argc int

variable_types:
argv
char **

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


repo: jeftyneg/mempoolite

decompiled_code:
__int64 __fastcall mplite_logarithm(int a1)
{
unsigned int v1; // ecx

if ( a1 <= 1 )
return 0;
v1 = 0;
do
++v1;
while ( 1 << v1 < a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // ecx

if ( a1 <= 1 )
return 0;
v1 = 0;
do
++v1;
while ( 1 << v1 < a1 );
return v1;
}

original_code:
static int mplite_logarithm(const int iValue)
{
    int iLog;
    for (iLog = 0; (1 << iLog) < iValue; iLog++);
    return iLog;
}

canonical_original_code:
static int mplite_logarithm(int iValue)
{
    int iLog;
    for (iLog = 0; (1 << iLog) < iValue; iLog++);
    return iLog;
}

variable_types: iValue int

variable_types: iLog int


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

if ( a2 < 0 || *(_DWORD *)(a1 + 4) <= a2 )
_assert_fail("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 0x109u, "mplite_link");
if ( (unsigned int)a3 > 0x1E )
_assert_fail("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 0x10Au, "mplite_link");
if ( (*(_BYTE *)(*(_QWORD *)(a1 + 208) + a2) & 0x1F) != a3 )
_assert_fail("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 0x10Bu, "mplite_link");
result = *(unsigned int *)(a1 + 4LL * a3 + 84);
*(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * a2) = result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * a2 + 4LL) = -1;
if ( (int)result >= 0 )
{
if ( (int)result >= *(_DWORD *)(a1 + 4) )
_assert_fail("x < handle->nBlock", "../../src/mplite.c", 0x110u, "mplite_link");
result = *(_DWORD *)a1 * (int)result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + result + 4) = a2;
}
*(_DWORD *)(a1 + 4LL * a3 + 84) = a2;
return result;
}

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

if ( a2 < 0 || *(_DWORD *)(a1 + 4) <= a2 )
_assert_fail("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 0x109u, "mplite_link");
if ( (unsigned int)a3 > 0x1E )
_assert_fail("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 0x10Au, "mplite_link");
if ( (*(_BYTE *)(*(_QWORD *)(a1 + 208) + a2) & 0x1F) != a3 )
_assert_fail("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 0x10Bu, "mplite_link");
result = *(unsigned int *)(a1 + 4LL * a3 + 84);
*(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * a2) = result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * a2 + 4LL) = -1;
if ( (int)result >= 0 )
{
if ( (int)result >= *(_DWORD *)(a1 + 4) )
_assert_fail("x < handle->nBlock", "../../src/mplite.c", 0x110u, "mplite_link");
result = *(_DWORD *)a1 * (int)result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + result + 4) = a2;
}
*(_DWORD *)(a1 + 4LL * a3 + 84) = a2;
return result;
}

original_code:
static void mplite_link(mplite_t *handle, const int i, const int iLogsize)
{
    int x;
    ((void) sizeof ((i >= 0 && i < handle->nBlock) ? 1 : 0), __extension__ ({ if (i >= 0 && i < handle->nBlock) ; else __assert_fail ("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 265, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((iLogsize >= 0 && iLogsize <= 30) ? 1 : 0), __extension__ ({ if (iLogsize >= 0 && iLogsize <= 30) ; else __assert_fail ("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 266, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((handle->aCtrl[i] & 0x1f) == iLogsize) ? 1 : 0), __extension__ ({ if ((handle->aCtrl[i] & 0x1f) == iLogsize) ; else __assert_fail ("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 267, __extension__ __PRETTY_FUNCTION__); }));
    x = ((mplite_link_t *) (&handle->zPool[(i) * handle->szAtom]))->next = handle->aiFreelist[iLogsize];
    ((mplite_link_t *) (&handle->zPool[(i) * handle->szAtom]))->prev = -1;
    if (x >= 0) {
        ((void) sizeof ((x < handle->nBlock) ? 1 : 0), __extension__ ({ if (x < handle->nBlock) ; else __assert_fail ("x < handle->nBlock", "../../src/mplite.c", 272, __extension__ __PRETTY_FUNCTION__); }));
        ((mplite_link_t *) (&handle->zPool[(x) * handle->szAtom]))->prev = i;
    }
    handle->aiFreelist[iLogsize] = i;
}

canonical_original_code:
static void mplite_link(struct mplite *handle, int i, int iLogsize)
{
    int x;
    ((void) sizeof ((i >= 0 && i < handle->nBlock) ? 1 : 0), __extension__ ({ if (i >= 0 && i < handle->nBlock) ; else __assert_fail ("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 265, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((iLogsize >= 0 && iLogsize <= 30) ? 1 : 0), __extension__ ({ if (iLogsize >= 0 && iLogsize <= 30) ; else __assert_fail ("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 266, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((handle->aCtrl[i] & 0x1f) == iLogsize) ? 1 : 0), __extension__ ({ if ((handle->aCtrl[i] & 0x1f) == iLogsize) ; else __assert_fail ("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 267, __extension__ __PRETTY_FUNCTION__); }));
    x = ((struct mplite_link *) (&handle->zPool[(i) * handle->szAtom]))->next = handle->aiFreelist[iLogsize];
    ((struct mplite_link *) (&handle->zPool[(i) * handle->szAtom]))->prev = -1;
    if (x >= 0) {
        ((void) sizeof ((x < handle->nBlock) ? 1 : 0), __extension__ ({ if (x < handle->nBlock) ; else __assert_fail ("x < handle->nBlock", "../../src/mplite.c", 272, __extension__ __PRETTY_FUNCTION__); }));
        ((struct mplite_link *) (&handle->zPool[(x) * handle->szAtom]))->prev = i;
    }
    handle->aiFreelist[iLogsize] = i;
}

variable_types: struct mplite { int szAtom; int nBlock; unsigned char *zPool; struct mplite_lock { void *arg; int (*acquire)(void *arg); int (*release)(void *arg); } lock; unsigned long nAlloc; unsigned long totalAlloc; unsigned long totalExcess; unsigned int currentOut; unsigned int currentCount; unsigned int maxOut; unsigned int maxCount; unsigned int maxRequest; int aiFreelist[-1]; unsigned char *aCtrl; } *

variable_types: i int

variable_types: iLogsize int

variable_types: x int

user_defined_types: struct mplite { int szAtom; int nBlock; unsigned char *zPool; struct mplite_lock lock; unsigned long nAlloc; unsigned long totalAlloc; unsigned long totalExcess; unsigned int currentOut; unsigned int currentCount; unsigned int maxOut; unsigned int maxCount; unsigned int maxRequest; int aiFreelist[-1]; unsigned char *aCtrl; }

user_defined_types: struct mplite_link { int next; int prev; }


decompiled_code:
__int64 __fastcall mplite_unlink(__int64 a1, int a2, unsigned int a3)
{
__int64 v3; // r8
unsigned int *v4; // rsi
__int64 result; // rax
int v6; // esi

if ( a2 < 0 || *(_DWORD *)(a1 + 4) <= a2 )
_assert_fail("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 0x11Du, "mplite_unlink");
if ( a3 > 0x1E )
_assert_fail("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 0x11Eu, "mplite_unlink");
if ( (*(_BYTE *)(*(_QWORD *)(a1 + 208) + a2) & 0x1F) != a3 )
_assert_fail("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 0x11Fu, "mplite_unlink");
v3 = *(_QWORD *)(a1 + 8);
v4 = (unsigned int *)(v3 + *(_DWORD *)a1 * a2);
result = *v4;
v6 = v4[1];
if ( v6 < 0 )
*(_DWORD *)(a1 + 4LL * (int)a3 + 84) = result;
else
*(_DWORD *)(v3 + v6 * *(_DWORD *)a1) = result;
if ( (int)result >= 0 )
{
result = *(_DWORD *)a1 * (int)result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + result + 4) = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, unsigned int a3)
{
__int64 v3; // r8
unsigned int *v4; // rsi
__int64 result; // rax
int v6; // esi

if ( a2 < 0 || *(_DWORD *)(a1 + 4) <= a2 )
_assert_fail("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 0x11Du, "mplite_unlink");
if ( a3 > 0x1E )
_assert_fail("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 0x11Eu, "mplite_unlink");
if ( (*(_BYTE *)(*(_QWORD *)(a1 + 208) + a2) & 0x1F) != a3 )
_assert_fail("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 0x11Fu, "mplite_unlink");
v3 = *(_QWORD *)(a1 + 8);
v4 = (unsigned int *)(v3 + *(_DWORD *)a1 * a2);
result = *v4;
v6 = v4[1];
if ( v6 < 0 )
*(_DWORD *)(a1 + 4LL * (int)a3 + 84) = result;
else
*(_DWORD *)(v3 + v6 * *(_DWORD *)a1) = result;
if ( (int)result >= 0 )
{
result = *(_DWORD *)a1 * (int)result;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + result + 4) = v6;
}
return result;
}

original_code:
static void mplite_unlink(mplite_t *handle, const int i, const int iLogsize)
{
    int next, prev;
    ((void) sizeof ((i >= 0 && i < handle->nBlock) ? 1 : 0), __extension__ ({ if (i >= 0 && i < handle->nBlock) ; else __assert_fail ("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 285, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((iLogsize >= 0 && iLogsize <= 30) ? 1 : 0), __extension__ ({ if (iLogsize >= 0 && iLogsize <= 30) ; else __assert_fail ("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 286, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((handle->aCtrl[i] & 0x1f) == iLogsize) ? 1 : 0), __extension__ ({ if ((handle->aCtrl[i] & 0x1f) == iLogsize) ; else __assert_fail ("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 287, __extension__ __PRETTY_FUNCTION__); }));
    next = ((mplite_link_t *) (&handle->zPool[(i) * handle->szAtom]))->next;
    prev = ((mplite_link_t *) (&handle->zPool[(i) * handle->szAtom]))->prev;
    if (prev < 0) {
        handle->aiFreelist[iLogsize] = next;
    }
    else {
        ((mplite_link_t *) (&handle->zPool[(prev) * handle->szAtom]))->next = next;
    }
    if (next >= 0) {
        ((mplite_link_t *) (&handle->zPool[(next) * handle->szAtom]))->prev = prev;
    }
}

canonical_original_code:
static void mplite_unlink(struct mplite *handle, int i, int iLogsize)
{
    int next; int prev;
    ((void) sizeof ((i >= 0 && i < handle->nBlock) ? 1 : 0), __extension__ ({ if (i >= 0 && i < handle->nBlock) ; else __assert_fail ("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 285, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((iLogsize >= 0 && iLogsize <= 30) ? 1 : 0), __extension__ ({ if (iLogsize >= 0 && iLogsize <= 30) ; else __assert_fail ("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 286, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((handle->aCtrl[i] & 0x1f) == iLogsize) ? 1 : 0), __extension__ ({ if ((handle->aCtrl[i] & 0x1f) == iLogsize) ; else __assert_fail ("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 287, __extension__ __PRETTY_FUNCTION__); }));
    next = ((struct mplite_link *) (&handle->zPool[(i) * handle->szAtom]))->next;
    prev = ((struct mplite_link *) (&handle->zPool[(i) * handle->szAtom]))->prev;
    if (prev < 0) {
        handle->aiFreelist[iLogsize] = next;
    }
    else {
        ((struct mplite_link *) (&handle->zPool[(prev) * handle->szAtom]))->next = next;
    }
    if (next >= 0) {
        ((struct mplite_link *) (&handle->zPool[(next) * handle->szAtom]))->prev = prev;
    }
}

variable_types: next int

variable_types: prev int

user_defined_types: struct mplite_lock { void *arg; int (*acquire)(void *arg); int (*release)(void *arg); }


decompiled_code:
__int64 __fastcall mplite_unlink_first(__int64 a1, signed int a2)
{
int v2; // eax
int i; // ebx

if ( (unsigned int)a2 > 0x1E )
_assert_fail("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 0x137u, "mplite_unlink_first");
v2 = *(_DWORD *)(a1 + 4LL * a2 + 84);
if ( v2 < 0 )
_assert_fail("iFirst >= 0", "../../src/mplite.c", 0x139u, "mplite_unlink_first");
for ( i = *(_DWORD *)(a1 + 4LL * a2 + 84); v2 > 0; v2 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * v2) )
{
if ( i > v2 )
i = v2;
}
mplite_unlink(a1, i, a2);
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, signed int a2)
{
int v2; // eax
int i; // ebx

if ( (unsigned int)a2 > 0x1E )
_assert_fail("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 0x137u, "mplite_unlink_first");
v2 = *(_DWORD *)(a1 + 4LL * a2 + 84);
if ( v2 < 0 )
_assert_fail("iFirst >= 0", "../../src/mplite.c", 0x139u, "mplite_unlink_first");
for ( i = *(_DWORD *)(a1 + 4LL * a2 + 84); v2 > 0; v2 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * v2) )
{
if ( i > v2 )
i = v2;
}
func2(a1, i, a2);
return (unsigned int)i;
}

original_code:
static int mplite_unlink_first(mplite_t *handle, const int iLogsize)
{
    int i;
    int iFirst;
    ((void) sizeof ((iLogsize >= 0 && iLogsize <= 30) ? 1 : 0), __extension__ ({ if (iLogsize >= 0 && iLogsize <= 30) ; else __assert_fail ("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 311, __extension__ __PRETTY_FUNCTION__); }));
    i = iFirst = handle->aiFreelist[iLogsize];
    ((void) sizeof ((iFirst >= 0) ? 1 : 0), __extension__ ({ if (iFirst >= 0) ; else __assert_fail ("iFirst >= 0", "../../src/mplite.c", 313, __extension__ __PRETTY_FUNCTION__); }));
    while (i > 0) {
        if (i < iFirst) iFirst = i;
        i = ((mplite_link_t *) (&handle->zPool[(i) * handle->szAtom]))->next;
    }
    mplite_unlink(handle, iFirst, iLogsize);
    return iFirst;
}

canonical_original_code:
static int mplite_unlink_first(struct mplite *handle, int iLogsize)
{
    int i;
    int iFirst;
    ((void) sizeof ((iLogsize >= 0 && iLogsize <= 30) ? 1 : 0), __extension__ ({ if (iLogsize >= 0 && iLogsize <= 30) ; else __assert_fail ("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 311, __extension__ __PRETTY_FUNCTION__); }));
    i = iFirst = handle->aiFreelist[iLogsize];
    ((void) sizeof ((iFirst >= 0) ? 1 : 0), __extension__ ({ if (iFirst >= 0) ; else __assert_fail ("iFirst >= 0", "../../src/mplite.c", 313, __extension__ __PRETTY_FUNCTION__); }));
    while (i > 0) {
        if (i < iFirst) iFirst = i;
        i = ((struct mplite_link *) (&handle->zPool[(i) * handle->szAtom]))->next;
    }
    mplite_unlink(handle, iFirst, iLogsize);
    return iFirst;
}

variable_types: iFirst int


original_code:
static void *mplite_malloc_unsafe(mplite_t *handle, const int nByte)
{
    int i;
    int iBin;
    int iFullSz;
    int iLogsize;
    ((void) sizeof ((nByte > 0) ? 1 : 0), __extension__ ({ if (nByte > 0) ; else __assert_fail ("nByte > 0", "../../src/mplite.c", 340, __extension__ __PRETTY_FUNCTION__); }));
    if ((uint32_t) nByte > handle->maxRequest) {
        handle->maxRequest = nByte;
    }
    if (nByte > 0x40000000) {
        return ((void *)0);
    }
    for (iFullSz = handle->szAtom, iLogsize = 0; iFullSz < nByte; iFullSz *= 2,
        iLogsize++) {
    }
    for (iBin = iLogsize; handle->aiFreelist[iBin] < 0 && iBin <= 30;
        iBin++) {
    }
    if (iBin > 30) {
        return ((void *)0);
    }
    i = mplite_unlink_first(handle, iBin);
    while (iBin > iLogsize) {
        int newSize;
        iBin--;
        newSize = 1 << iBin;
        handle->aCtrl[i + newSize] = (uint8_t) (0x20 | iBin);
        mplite_link(handle, i + newSize, iBin);
    }
    handle->aCtrl[i] = (uint8_t) iLogsize;
    handle->nAlloc++;
    handle->totalAlloc += iFullSz;
    handle->totalExcess += iFullSz - nByte;
    handle->currentCount++;
    handle->currentOut += iFullSz;
    if (handle->maxCount < handle->currentCount) {
        handle->maxCount = handle->currentCount;
    }
    if (handle->maxOut < handle->currentOut) {
        handle->maxOut = handle->currentOut;
    }
    return (void*) &handle->zPool[i * handle->szAtom];
}

canonical_original_code:
static void *mplite_malloc_unsafe(struct mplite *handle, int nByte)
{
    int i;
    int iBin;
    int iFullSz;
    int iLogsize;
    ((void) sizeof ((nByte > 0) ? 1 : 0), __extension__ ({ if (nByte > 0) ; else __assert_fail ("nByte > 0", "../../src/mplite.c", 340, __extension__ __PRETTY_FUNCTION__); }));
    if ((unsigned int) nByte > handle->maxRequest) {
        handle->maxRequest = nByte;
    }
    if (nByte > 0x40000000) {
        return ((void *)0);
    }
    for (iFullSz = handle->szAtom, iLogsize = 0; iFullSz < nByte; iFullSz *= 2,
        iLogsize++) {
    }
    for (iBin = iLogsize; handle->aiFreelist[iBin] < 0 && iBin <= 30;
        iBin++) {
    }
    if (iBin > 30) {
        return ((void *)0);
    }
    i = mplite_unlink_first(handle, iBin);
    while (iBin > iLogsize) {
        int newSize;
        iBin--;
        newSize = 1 << iBin;
        handle->aCtrl[i + newSize] = (unsigned char) (0x20 | iBin);
        mplite_link(handle, i + newSize, iBin);
    }
    handle->aCtrl[i] = (unsigned char) iLogsize;
    handle->nAlloc++;
    handle->totalAlloc += iFullSz;
    handle->totalExcess += iFullSz - nByte;
    handle->currentCount++;
    handle->currentOut += iFullSz;
    if (handle->maxCount < handle->currentCount) {
        handle->maxCount = handle->currentCount;
    }
    if (handle->maxOut < handle->currentOut) {
        handle->maxOut = handle->currentOut;
    }
    return (void *) &handle->zPool[i * handle->szAtom];
}

variable_types: nByte int

variable_types: iBin int

variable_types: iFullSz int

variable_types: newSize int

return_type: void *


decompiled_code:
__int64 __fastcall mplite_free_unsafe(int *a1, __int64 a2)
{
__int64 v2; // rsi
__int64 v3; // rcx
__int64 v5; // rdi
int v6; // er12
int v7; // er8
__int64 v8; // rsi
char *v9; // r9
char v10; // dl
char v11; // cl
unsigned int v12; // ebp
int v13; // er14
unsigned int v14; // eax
int v15; // eax
unsigned int v16; // edx
unsigned int v17; // edi
int v18; // eax
int v19; // edx
int v21; // ebx

v2 = a2 - *((_QWORD *)a1 + 1);
v3 = *a1;
if ( (int)(v2 / v3) < 0 || (v5 = v2 / *a1, v6 = v2 / v3, v7 = a1[1], v7 <= v6) )
_assert_fail("iBlock >= 0 && iBlock < handle->nBlock", "../../src/mplite.c", 0x19Cu, "mplite_free_unsafe");
if ( v2 % v3 )
_assert_fail(
"((uint8_t *) pOld - handle->zPool) % handle->szAtom == 0",
"../../src/mplite.c",
0x19Du,
"mplite_free_unsafe");
v8 = (int)v5;
v9 = (char *)(*((_QWORD *)a1 + 26) + (int)v5);
v10 = *v9;
if ( (*v9 & 0x20) != 0 )
_assert_fail("(handle->aCtrl[iBlock] & MPLITE_CTRL_FREE) == 0", "../../src/mplite.c", 0x19Eu, "mplite_free_unsafe");
v11 = v10 & 0x1F;
v12 = v10 & 0x1F;
v13 = 1 << (v10 & 0x1F);
v14 = v13 + v5 - 1;
if ( v14 >= v7 )
_assert_fail("iBlock + size - 1 < (uint32_t) handle->nBlock", "../../src/mplite.c", 0x1A2u, "mplite_free_unsafe");
*v9 = v10 | 0x20;
*(_BYTE *)(*((_QWORD *)a1 + 26) + v14) |= 0x20u;
v15 = a1[17];
if ( !v15 )
_assert_fail("handle->currentCount > 0", "../../src/mplite.c", 0x1A6u, "mplite_free_unsafe");
v16 = a1[16];
v17 = *a1 << v11;
if ( v16 < v17 )
_assert_fail("handle->currentOut >= (size * handle->szAtom)", "../../src/mplite.c", 0x1A7u, "mplite_free_unsafe");
v18 = v15 - 1;
a1[17] = v18;
v19 = v16 - v17;
a1[16] = v19;
if ( v18 && !v19 )
_assert_fail(
"handle->currentOut > 0 || handle->currentCount == 0",
"../../src/mplite.c",
0x1AAu,
"mplite_free_unsafe");
if ( v19 && !v18 )
_assert_fail(
"handle->currentCount > 0 || handle->currentOut == 0",
"../../src/mplite.c",
0x1ABu,
"mplite_free_unsafe");
*(_BYTE *)(*((_QWORD *)a1 + 26) + v8) = v11 | 0x20;
if ( v12 <= 0x1D )
{
do
{
v21 = v6 + v13;
if ( ((v6 >> v12) & 1) != 0 )
v21 = v6 - v13;
if ( v21 < 0 )
_assert_fail("iBuddy >= 0", "../../src/mplite.c", 0x1B6u, "mplite_free_unsafe");
if ( v21 + (1 << v12) > a1[1] || *(unsigned __int8 *)(*((_QWORD *)a1 + 26) + v21) != (v12 | 0x20) )
break;
mplite_unlink((__int64)a1, v21, v12++);
if ( v21 >= v6 )
{
*(_BYTE *)(*((_QWORD *)a1 + 26) + v6) = v12 | 0x20;
*(_BYTE *)(*((_QWORD *)a1 + 26) + v21) = 0;
}
else
{
*(_BYTE *)(*((_QWORD *)a1 + 26) + v21) = v12 | 0x20;
*(_BYTE *)(*((_QWORD *)a1 + 26) + v6) = 0;
v6 = v21;
}
v13 *= 2;
}
while ( v12 != 30 );
}
return mplite_link((__int64)a1, v6, v12);
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, __int64 a2)
{
__int64 v2; // rsi
__int64 v3; // rcx
__int64 v5; // rdi
int v6; // er12
int v7; // er8
__int64 v8; // rsi
char *v9; // r9
char v10; // dl
char v11; // cl
unsigned int v12; // ebp
int v13; // er14
unsigned int v14; // eax
int v15; // eax
unsigned int v16; // edx
unsigned int v17; // edi
int v18; // eax
int v19; // edx
int v21; // ebx

v2 = a2 - *((_QWORD *)a1 + 1);
v3 = *a1;
if ( (int)(v2 / v3) < 0 || (v5 = v2 / *a1, v6 = v2 / v3, v7 = a1[1], v7 <= v6) )
_assert_fail("iBlock >= 0 && iBlock < handle->nBlock", "../../src/mplite.c", 0x19Cu, "mplite_free_unsafe");
if ( v2 % v3 )
_assert_fail(
"((uint8_t *) pOld - handle->zPool) % handle->szAtom == 0",
"../../src/mplite.c",
0x19Du,
"mplite_free_unsafe");
v8 = (int)v5;
v9 = (char *)(*((_QWORD *)a1 + 26) + (int)v5);
v10 = *v9;
if ( (*v9 & 0x20) != 0 )
_assert_fail("(handle->aCtrl[iBlock] & MPLITE_CTRL_FREE) == 0", "../../src/mplite.c", 0x19Eu, "mplite_free_unsafe");
v11 = v10 & 0x1F;
v12 = v10 & 0x1F;
v13 = 1 << (v10 & 0x1F);
v14 = v13 + v5 - 1;
if ( v14 >= v7 )
_assert_fail("iBlock + size - 1 < (uint32_t) handle->nBlock", "../../src/mplite.c", 0x1A2u, "mplite_free_unsafe");
*v9 = v10 | 0x20;
*(_BYTE *)(*((_QWORD *)a1 + 26) + v14) |= 0x20u;
v15 = a1[17];
if ( !v15 )
_assert_fail("handle->currentCount > 0", "../../src/mplite.c", 0x1A6u, "mplite_free_unsafe");
v16 = a1[16];
v17 = *a1 << v11;
if ( v16 < v17 )
_assert_fail("handle->currentOut >= (size * handle->szAtom)", "../../src/mplite.c", 0x1A7u, "mplite_free_unsafe");
v18 = v15 - 1;
a1[17] = v18;
v19 = v16 - v17;
a1[16] = v19;
if ( v18 && !v19 )
_assert_fail(
"handle->currentOut > 0 || handle->currentCount == 0",
"../../src/mplite.c",
0x1AAu,
"mplite_free_unsafe");
if ( v19 && !v18 )
_assert_fail(
"handle->currentCount > 0 || handle->currentOut == 0",
"../../src/mplite.c",
0x1ABu,
"mplite_free_unsafe");
*(_BYTE *)(*((_QWORD *)a1 + 26) + v8) = v11 | 0x20;
if ( v12 <= 0x1D )
{
do
{
v21 = v6 + v13;
if ( ((v6 >> v12) & 1) != 0 )
v21 = v6 - v13;
if ( v21 < 0 )
_assert_fail("iBuddy >= 0", "../../src/mplite.c", 0x1B6u, "mplite_free_unsafe");
if ( v21 + (1 << v12) > a1[1] || *(unsigned __int8 *)(*((_QWORD *)a1 + 26) + v21) != (v12 | 0x20) )
break;
func2((__int64)a1, v21, v12++);
if ( v21 >= v6 )
{
*(_BYTE *)(*((_QWORD *)a1 + 26) + v6) = v12 | 0x20;
*(_BYTE *)(*((_QWORD *)a1 + 26) + v21) = 0;
}
else
{
*(_BYTE *)(*((_QWORD *)a1 + 26) + v21) = v12 | 0x20;
*(_BYTE *)(*((_QWORD *)a1 + 26) + v6) = 0;
v6 = v21;
}
v13 *= 2;
}
while ( v12 != 30 );
}
return func1((__int64)a1, v6, v12);
}

original_code:
static void mplite_free_unsafe(mplite_t *handle, const void *pOld)
{
    uint32_t size, iLogsize;
    int iBlock;
    iBlock = ((uint8_t *) pOld - handle->zPool) / handle->szAtom;
    ((void) sizeof ((iBlock >= 0 && iBlock < handle->nBlock) ? 1 : 0), __extension__ ({ if (iBlock >= 0 && iBlock < handle->nBlock) ; else __assert_fail ("iBlock >= 0 && iBlock < handle->nBlock", "../../src/mplite.c", 412, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((((uint8_t *) pOld - handle->zPool) % handle->szAtom == 0) ? 1 : 0), __extension__ ({ if (((uint8_t *) pOld - handle->zPool) % handle->szAtom == 0) ; else __assert_fail ("((uint8_t *) pOld - handle->zPool) % handle->szAtom == 0", "../../src/mplite.c", 413, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((handle->aCtrl[iBlock] & 0x20) == 0) ? 1 : 0), __extension__ ({ if ((handle->aCtrl[iBlock] & 0x20) == 0) ; else __assert_fail ("(handle->aCtrl[iBlock] & MPLITE_CTRL_FREE) == 0", "../../src/mplite.c", 414, __extension__ __PRETTY_FUNCTION__); }));
    iLogsize = handle->aCtrl[iBlock] & 0x1f;
    size = 1 << iLogsize;
    ((void) sizeof ((iBlock + size - 1 < (uint32_t) handle->nBlock) ? 1 : 0), __extension__ ({ if (iBlock + size - 1 < (uint32_t) handle->nBlock) ; else __assert_fail ("iBlock + size - 1 < (uint32_t) handle->nBlock", "../../src/mplite.c", 418, __extension__ __PRETTY_FUNCTION__); }));
    handle->aCtrl[iBlock] |= 0x20;
    handle->aCtrl[iBlock + size - 1] |= 0x20;
    ((void) sizeof ((handle->currentCount > 0) ? 1 : 0), __extension__ ({ if (handle->currentCount > 0) ; else __assert_fail ("handle->currentCount > 0", "../../src/mplite.c", 422, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((handle->currentOut >= (size * handle->szAtom)) ? 1 : 0), __extension__ ({ if (handle->currentOut >= (size * handle->szAtom)) ; else __assert_fail ("handle->currentOut >= (size * handle->szAtom)", "../../src/mplite.c", 423, __extension__ __PRETTY_FUNCTION__); }));
    handle->currentCount--;
    handle->currentOut -= size * handle->szAtom;
    ((void) sizeof ((handle->currentOut > 0 || handle->currentCount == 0) ? 1 : 0), __extension__ ({ if (handle->currentOut > 0 || handle->currentCount == 0) ; else __assert_fail ("handle->currentOut > 0 || handle->currentCount == 0", "../../src/mplite.c", 426, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((handle->currentCount > 0 || handle->currentOut == 0) ? 1 : 0), __extension__ ({ if (handle->currentCount > 0 || handle->currentOut == 0) ; else __assert_fail ("handle->currentCount > 0 || handle->currentOut == 0", "../../src/mplite.c", 427, __extension__ __PRETTY_FUNCTION__); }));
    handle->aCtrl[iBlock] = (uint8_t) (0x20 | iLogsize);
    while (iLogsize < 30) {
        int iBuddy;
        if ((iBlock >> iLogsize) & 1) {
            iBuddy = iBlock - size;
        }
        else {
            iBuddy = iBlock + size;
        }
        ((void) sizeof ((iBuddy >= 0) ? 1 : 0), __extension__ ({ if (iBuddy >= 0) ; else __assert_fail ("iBuddy >= 0", "../../src/mplite.c", 438, __extension__ __PRETTY_FUNCTION__); }));
        if ((iBuddy + (1 << iLogsize)) > handle->nBlock) break;
        if (handle->aCtrl[iBuddy] != (0x20 | iLogsize)) break;
        mplite_unlink(handle, iBuddy, iLogsize);
        iLogsize++;
        if (iBuddy < iBlock) {
            handle->aCtrl[iBuddy] = (uint8_t) (0x20 | iLogsize);
            handle->aCtrl[iBlock] = 0;
            iBlock = iBuddy;
        }
        else {
            handle->aCtrl[iBlock] = (uint8_t) (0x20 | iLogsize);
            handle->aCtrl[iBuddy] = 0;
        }
        size *= 2;
    }
    mplite_link(handle, iBlock, iLogsize);
}

canonical_original_code:
static void mplite_free_unsafe(struct mplite *handle, void *pOld)
{
    unsigned int size; unsigned int iLogsize;
    int iBlock;
    iBlock = ((unsigned char *) pOld - handle->zPool) / handle->szAtom;
    ((void) sizeof ((iBlock >= 0 && iBlock < handle->nBlock) ? 1 : 0), __extension__ ({ if (iBlock >= 0 && iBlock < handle->nBlock) ; else __assert_fail ("iBlock >= 0 && iBlock < handle->nBlock", "../../src/mplite.c", 412, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((((unsigned char *) pOld - handle->zPool) % handle->szAtom == 0) ? 1 : 0), __extension__ ({ if (((unsigned char *) pOld - handle->zPool) % handle->szAtom == 0) ; else __assert_fail ("((uint8_t *) pOld - handle->zPool) % handle->szAtom == 0", "../../src/mplite.c", 413, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((handle->aCtrl[iBlock] & 0x20) == 0) ? 1 : 0), __extension__ ({ if ((handle->aCtrl[iBlock] & 0x20) == 0) ; else __assert_fail ("(handle->aCtrl[iBlock] & MPLITE_CTRL_FREE) == 0", "../../src/mplite.c", 414, __extension__ __PRETTY_FUNCTION__); }));
    iLogsize = handle->aCtrl[iBlock] & 0x1f;
    size = 1 << iLogsize;
    ((void) sizeof ((iBlock + size - 1 < (unsigned int) handle->nBlock) ? 1 : 0), __extension__ ({ if (iBlock + size - 1 < (unsigned int) handle->nBlock) ; else __assert_fail ("iBlock + size - 1 < (uint32_t) handle->nBlock", "../../src/mplite.c", 418, __extension__ __PRETTY_FUNCTION__); }));
    handle->aCtrl[iBlock] |= 0x20;
    handle->aCtrl[iBlock + size - 1] |= 0x20;
    ((void) sizeof ((handle->currentCount > 0) ? 1 : 0), __extension__ ({ if (handle->currentCount > 0) ; else __assert_fail ("handle->currentCount > 0", "../../src/mplite.c", 422, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((handle->currentOut >= (size * handle->szAtom)) ? 1 : 0), __extension__ ({ if (handle->currentOut >= (size * handle->szAtom)) ; else __assert_fail ("handle->currentOut >= (size * handle->szAtom)", "../../src/mplite.c", 423, __extension__ __PRETTY_FUNCTION__); }));
    handle->currentCount--;
    handle->currentOut -= size * handle->szAtom;
    ((void) sizeof ((handle->currentOut > 0 || handle->currentCount == 0) ? 1 : 0), __extension__ ({ if (handle->currentOut > 0 || handle->currentCount == 0) ; else __assert_fail ("handle->currentOut > 0 || handle->currentCount == 0", "../../src/mplite.c", 426, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((handle->currentCount > 0 || handle->currentOut == 0) ? 1 : 0), __extension__ ({ if (handle->currentCount > 0 || handle->currentOut == 0) ; else __assert_fail ("handle->currentCount > 0 || handle->currentOut == 0", "../../src/mplite.c", 427, __extension__ __PRETTY_FUNCTION__); }));
    handle->aCtrl[iBlock] = (unsigned char) (0x20 | iLogsize);
    while (iLogsize < 30) {
        int iBuddy;
        if ((iBlock >> iLogsize) & 1) {
            iBuddy = iBlock - size;
        }
        else {
            iBuddy = iBlock + size;
        }
        ((void) sizeof ((iBuddy >= 0) ? 1 : 0), __extension__ ({ if (iBuddy >= 0) ; else __assert_fail ("iBuddy >= 0", "../../src/mplite.c", 438, __extension__ __PRETTY_FUNCTION__); }));
        if ((iBuddy + (1 << iLogsize)) > handle->nBlock) break;
        if (handle->aCtrl[iBuddy] != (0x20 | iLogsize)) break;
        mplite_unlink(handle, iBuddy, iLogsize);
        iLogsize++;
        if (iBuddy < iBlock) {
            handle->aCtrl[iBuddy] = (unsigned char) (0x20 | iLogsize);
            handle->aCtrl[iBlock] = 0;
            iBlock = iBuddy;
        }
        else {
            handle->aCtrl[iBlock] = (unsigned char) (0x20 | iLogsize);
            handle->aCtrl[iBuddy] = 0;
        }
        size *= 2;
    }
    mplite_link(handle, iBlock, iLogsize);
}

variable_types:
pOld
void *

variable_types:
size
unsigned int

variable_types:
iLogsize
unsigned int

variable_types: iBlock int

variable_types: iBuddy int


decompiled_code:
__int64 __fastcall mplite_size(int *a1, __int64 a2)
{
__int64 v2; // rax

if ( !a2 )
return 0LL;
v2 = (a2 - *((_QWORD *)a1 + 1)) / *a1;
if ( (int)v2 < 0 || a1[1] <= (int)v2 )
_assert_fail("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 0xFBu, "mplite_size");
return (unsigned int)(*a1 << *(_BYTE *)(*((_QWORD *)a1 + 26) + (int)v2));
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, __int64 a2)
{
__int64 v2; // rax

if ( !a2 )
return 0LL;
v2 = (a2 - *((_QWORD *)a1 + 1)) / *a1;
if ( (int)v2 < 0 || a1[1] <= (int)v2 )
_assert_fail("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 0xFBu, "mplite_size");
return (unsigned int)(*a1 << *(_BYTE *)(*((_QWORD *)a1 + 26) + (int)v2));
}

original_code:
static int mplite_size(const mplite_t *handle, const void *p)
{
    int iSize = 0;
    if (p) {
        int i = ((uint8_t *) p - handle->zPool) / handle->szAtom;
        ((void) sizeof ((i >= 0 && i < handle->nBlock) ? 1 : 0), __extension__ ({ if (i >= 0 && i < handle->nBlock) ; else __assert_fail ("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 251, __extension__ __PRETTY_FUNCTION__); }));
        iSize = handle->szAtom *
                (1 << (handle->aCtrl[i] & 0x1f));
    }
    return iSize;
}

canonical_original_code:
static int mplite_size(struct mplite *handle, void *p)
{
    int iSize = 0;
    if (p) {
        int i = ((uint8_t *) p - handle->zPool) / handle->szAtom;
        ((void) sizeof ((i >= 0 && i < handle->nBlock) ? 1 : 0), __extension__ ({ if (i >= 0 && i < handle->nBlock) ; else __assert_fail ("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 251, __extension__ __PRETTY_FUNCTION__); }));
        iSize = handle->szAtom *
                (1 << (handle->aCtrl[i] & 0x1f));
    }
    return iSize;
}

variable_types:
p
void *

variable_types: iSize int


original_code:
int mplite_init(mplite_t *handle, const void *buf,
                           const int buf_size, const int min_alloc,
                           const mplite_lock_t *lock)
{
    int ii;
    int nByte;
    uint8_t *zByte;
    int nMinLog;
    int iOffset;
    if ((((void *)0) == handle) || (((void *)0) == buf) || (buf_size <= 0) ||
        (min_alloc <= 0)) {
        return -1;
    }
    memset(handle, 0, sizeof (*handle));
    if (lock != ((void *)0)) {
        memcpy(&handle->lock, lock, sizeof (handle->lock));
    }
    ((void) sizeof (((sizeof (mplite_link_t)&(sizeof (mplite_link_t) - 1)) == 0) ? 1 : 0), __extension__ ({ if ((sizeof (mplite_link_t)&(sizeof (mplite_link_t) - 1)) == 0) ; else __assert_fail ("(sizeof (mplite_link_t)&(sizeof (mplite_link_t) - 1)) == 0", "../../src/mplite.c", 83, __extension__ __PRETTY_FUNCTION__); }));
    nByte = buf_size;
    zByte = (uint8_t*) buf;
    nMinLog = mplite_logarithm(min_alloc);
    handle->szAtom = (1 << nMinLog);
    while ((int) sizeof (mplite_link_t) > handle->szAtom) {
        handle->szAtom = handle->szAtom << 1;
    }
    handle->nBlock = (nByte / (handle->szAtom + sizeof (uint8_t)));
    handle->zPool = zByte;
    handle->aCtrl = (uint8_t *) & handle->zPool[handle->nBlock * handle->szAtom];
    for (ii = 0; ii <= 30; ii++) {
        handle->aiFreelist[ii] = -1;
    }
    iOffset = 0;
    for (ii = 30; ii >= 0; ii--) {
        int nAlloc = (1 << ii);
        if ((iOffset + nAlloc) <= handle->nBlock) {
            handle->aCtrl[iOffset] = (uint8_t) (ii | 0x20);
            mplite_link(handle, iOffset, ii);
            iOffset += nAlloc;
        }
        ((void) sizeof (((iOffset + nAlloc) > handle->nBlock) ? 1 : 0), __extension__ ({ if ((iOffset + nAlloc) > handle->nBlock) ; else __assert_fail ("(iOffset + nAlloc) > handle->nBlock", "../../src/mplite.c", 110, __extension__ __PRETTY_FUNCTION__); }));
    }
    return 0;
}

canonical_original_code:
int mplite_init(struct mplite *handle, void *buf, int buf_size, int min_alloc, struct mplite_lock *lock)
{
    int ii;
    int nByte;
    unsigned char *zByte;
    int nMinLog;
    int iOffset;
    if ((((void *)0) == handle) || (((void *)0) == buf) || (buf_size <= 0) ||
        (min_alloc <= 0)) {
        return -1;
    }
    memset(handle, 0, sizeof (*handle));
    if (lock != ((void *)0)) {
        memcpy(&handle->lock, lock, sizeof (handle->lock));
    }
    ((void) sizeof (((sizeof (mplite_link_t)&(sizeof (mplite_link_t) - 1)) == 0) ? 1 : 0), __extension__ ({ if ((sizeof (mplite_link_t)&(sizeof (mplite_link_t) - 1)) == 0) ; else __assert_fail ("(sizeof (mplite_link_t)&(sizeof (mplite_link_t) - 1)) == 0", "../../src/mplite.c", 83, __extension__ __PRETTY_FUNCTION__); }));
    nByte = buf_size;
    zByte = (unsigned char *) buf;
    nMinLog = mplite_logarithm(min_alloc);
    handle->szAtom = (1 << nMinLog);
    while ((int) sizeof (mplite_link_t) > handle->szAtom) {
        handle->szAtom = handle->szAtom << 1;
    }
    handle->nBlock = (nByte / (handle->szAtom + sizeof (unsigned char)));
    handle->zPool = zByte;
    handle->aCtrl = (unsigned char *) & handle->zPool[handle->nBlock * handle->szAtom];
    for (ii = 0; ii <= 30; ii++) {
        handle->aiFreelist[ii] = -1;
    }
    iOffset = 0;
    for (ii = 30; ii >= 0; ii--) {
        int nAlloc = (1 << ii);
        if ((iOffset + nAlloc) <= handle->nBlock) {
            handle->aCtrl[iOffset] = (unsigned char) (ii | 0x20);
            mplite_link(handle, iOffset, ii);
            iOffset += nAlloc;
        }
        ((void) sizeof (((iOffset + nAlloc) > handle->nBlock) ? 1 : 0), __extension__ ({ if ((iOffset + nAlloc) > handle->nBlock) ; else __assert_fail ("(iOffset + nAlloc) > handle->nBlock", "../../src/mplite.c", 110, __extension__ __PRETTY_FUNCTION__); }));
    }
    return 0;
}

variable_types: struct mplite { int szAtom; int nBlock; unsigned char *zPool; struct mplite_lock { void *arg; int (*acquire)(void *arg); int (*release)(void *arg); } lock; unsigned long nAlloc; unsigned long totalAlloc; unsigned long totalExcess; unsigned int currentOut; unsigned int currentCount; unsigned int maxOut; unsigned int maxCount; unsigned int maxRequest; int aiFreelist[-1]; unsigned char *aCtrl; } *

variable_types:
buf
void *

variable_types:
lock
struct mplite_lock *

variable_types: ii int

variable_types:
zByte
unsigned char *

variable_types: nMinLog int

variable_types: iOffset int

variable_types: nAlloc int


decompiled_code:
__int64 __fastcall mplite_malloc(_QWORD *a1, int a2)
{
void (__fastcall *v2)(_QWORD); // rax
__int64 v3; // rbp
void (__fastcall *v4)(_QWORD); // rax

if ( !a1 || a2 <= 0 )
return 0LL;
v2 = (void (__fastcall *)(_QWORD))a1[3];
if ( v2 )
v2(a1[2]);
v3 = mplite_malloc_unsafe((__int64)a1, a2);
v4 = (void (__fastcall *)(_QWORD))a1[4];
if ( v4 )
v4(a1[2]);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2)
{
void (__fastcall *v2)(_QWORD); // rax
__int64 v3; // rbp
void (__fastcall *v4)(_QWORD); // rax

if ( !a1 || a2 <= 0 )
return 0LL;
v2 = (void (__fastcall *)(_QWORD))a1[3];
if ( v2 )
v2(a1[2]);
v3 = func4((__int64)a1, a2);
v4 = (void (__fastcall *)(_QWORD))a1[4];
if ( v4 )
v4(a1[2]);
return v3;
}

original_code:
void *mplite_malloc(mplite_t *handle, const int nBytes)
{
    int64_t *p = 0;
    if ((((void *)0) == handle) || (nBytes <= 0)) {
        return ((void *)0);
    }
    if((handle != ((void *)0)) && ((handle)->lock.acquire != ((void *)0))) { (handle)->lock.acquire((handle)->lock.arg); };
    p = mplite_malloc_unsafe(handle, nBytes);
    if((handle != ((void *)0)) && ((handle)->lock.release != ((void *)0))) { (handle)->lock.release((handle)->lock.arg); };
    return (void*) p;
}

canonical_original_code:
void *mplite_malloc(struct mplite *handle, int nBytes)
{
    long *p = 0;
    if ((((void *)0) == handle) || (nBytes <= 0)) {
        return ((void *)0);
    }
    if((handle != ((void *)0)) && ((handle)->lock.acquire != ((void *)0))) { (handle)->lock.acquire((handle)->lock.arg); };
    p = mplite_malloc_unsafe(handle, nBytes);
    if((handle != ((void *)0)) && ((handle)->lock.release != ((void *)0))) { (handle)->lock.release((handle)->lock.arg); };
    return (void *) p;
}

variable_types: nBytes int

variable_types:
p
long *


decompiled_code:
void __fastcall mplite_free(__int64 a1, __int64 a2)
{
void (__fastcall *v2)(_QWORD); // rax
void (__fastcall *v3)(_QWORD); // rax

if ( a1 && a2 )
{
v2 = *(void (__fastcall **)(_QWORD))(a1 + 24);
if ( v2 )
v2(*(_QWORD *)(a1 + 16));
mplite_free_unsafe((int *)a1, a2);
v3 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v3 )
v3(*(_QWORD *)(a1 + 16));
}
}

original_code:
void mplite_free(mplite_t *handle, const void *pPrior)
{
    if ((((void *)0) == handle) || (((void *)0) == pPrior)) {
        return;
    }
    if((handle != ((void *)0)) && ((handle)->lock.acquire != ((void *)0))) { (handle)->lock.acquire((handle)->lock.arg); };
    mplite_free_unsafe(handle, pPrior);
    if((handle != ((void *)0)) && ((handle)->lock.release != ((void *)0))) { (handle)->lock.release((handle)->lock.arg); };
}

canonical_original_code:
void mplite_free(struct mplite *handle, void *pPrior)
{
    if ((((void *)0) == handle) || (((void *)0) == pPrior)) {
        return;
    }
    if((handle != ((void *)0)) && ((handle)->lock.acquire != ((void *)0))) { (handle)->lock.acquire((handle)->lock.arg); };
    mplite_free_unsafe(handle, pPrior);
    if((handle != ((void *)0)) && ((handle)->lock.release != ((void *)0))) { (handle)->lock.release((handle)->lock.arg); };
}

variable_types:
pPrior
void *


decompiled_code:
void *__fastcall mplite_realloc(__int64 a1, void *a2, int a3)
{
void *v4; // r13
int v5; // er14
void (__fastcall *v6)(_QWORD); // rax
void *v7; // rax
void (__fastcall *v8)(_QWORD); // rax

if ( a2 == 0LL || a1 == 0 || a3 <= 0 )
return 0LL;
v4 = 0LL;
if ( (a3 & (a3 - 1)) == 0 )
{
v5 = mplite_size((int *)a1, (__int64)a2);
v4 = a2;
if ( a3 > v5 )
{
v6 = *(void (__fastcall **)(_QWORD))(a1 + 24);
if ( v6 )
v6(*(_QWORD *)(a1 + 16));
v7 = (void *)mplite_malloc_unsafe(a1, a3);
v4 = v7;
if ( v7 )
{
memcpy(v7, a2, v5);
mplite_free_unsafe((int *)a1, (__int64)a2);
}
v8 = *(void (__fastcall **)(_QWORD))(a1 + 32);
if ( v8 )
v8(*(_QWORD *)(a1 + 16));
}
}
return v4;
}

original_code:
void *mplite_realloc(mplite_t *handle, const void *pPrior,
                                const int nBytes)
{
    int nOld;
    void *p;
    if ((((void *)0) == handle) || (((void *)0) == pPrior) || (nBytes <= 0) ||
        (nBytes & (nBytes - 1))) {
        return ((void *)0);
    }
    nOld = mplite_size(handle, pPrior);
    if (nBytes <= nOld) {
        return (void *) pPrior;
    }
    if((handle != ((void *)0)) && ((handle)->lock.acquire != ((void *)0))) { (handle)->lock.acquire((handle)->lock.arg); };
    p = mplite_malloc_unsafe(handle, nBytes);
    if (p) {
        memcpy(p, pPrior, nOld);
        mplite_free_unsafe(handle, pPrior);
    }
    if((handle != ((void *)0)) && ((handle)->lock.release != ((void *)0))) { (handle)->lock.release((handle)->lock.arg); };
    return p;
}

canonical_original_code:
void *mplite_realloc(struct mplite *handle, void *pPrior, int nBytes)
{
    int nOld;
    void *p;
    if ((((void *)0) == handle) || (((void *)0) == pPrior) || (nBytes <= 0) ||
        (nBytes & (nBytes - 1))) {
        return ((void *)0);
    }
    nOld = mplite_size(handle, pPrior);
    if (nBytes <= nOld) {
        return (void *) pPrior;
    }
    if((handle != ((void *)0)) && ((handle)->lock.acquire != ((void *)0))) { (handle)->lock.acquire((handle)->lock.arg); };
    p = mplite_malloc_unsafe(handle, nBytes);
    if (p) {
        memcpy(p, pPrior, nOld);
        mplite_free_unsafe(handle, pPrior);
    }
    if((handle != ((void *)0)) && ((handle)->lock.release != ((void *)0))) { (handle)->lock.release((handle)->lock.arg); };
    return p;
}

variable_types: nOld int


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

if ( !a1 || a2 > 0x40000000 )
return 0LL;
for ( result = *a1; a2 > (int)result; result = (unsigned int)(2 * result) )
;
return result;
}

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

if ( !a1 || a2 > 0x40000000 )
return 0LL;
for ( result = *a1; a2 > (int)result; result = (unsigned int)(2 * result) )
;
return result;
}

original_code:
int mplite_roundup(mplite_t *handle, const int n)
{
    int iFullSz;
    if ((((void *)0) == handle) || (n > 0x40000000)) {
        return 0;
    }
    for (iFullSz = handle->szAtom; iFullSz < n; iFullSz *= 2);
    return iFullSz;
}

canonical_original_code:
int mplite_roundup(struct mplite *handle, int n)
{
    int iFullSz;
    if ((((void *)0) == handle) || (n > 0x40000000)) {
        return 0;
    }
    for (iFullSz = handle->szAtom; iFullSz < n; iFullSz *= 2);
    return iFullSz;
}

variable_types: n int

variable_types: iFullSz int


decompiled_code:
__int64 __fastcall mplite_print_stats(unsigned int *a1, void (__fastcall *a2)(char *))
{
__int64 result; // rax
char v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( a1 )
{
if ( a2 )
{
snprintf(v3, 0x100uLL, "Total number of calls to malloc: %u", a1[10]);
a2(v3);
snprintf(v3, 0x100uLL, "Total of all malloc calls - includes internal fragmentation: %u", a1[12]);
a2(v3);
snprintf(v3, 0x100uLL, "Total internal fragmentation: %u", a1[14]);
a2(v3);
snprintf(v3, 0x100uLL, "Current checkout, including internal fragmentation: %u", a1[16]);
a2(v3);
snprintf(v3, 0x100uLL, "Current number of distinct checkouts: %u", a1[17]);
a2(v3);
snprintf(v3, 0x100uLL, "Maximum instantaneous currentOut: %u", a1[18]);
a2(v3);
snprintf(v3, 0x100uLL, "Maximum instantaneous currentCount: %u", a1[19]);
a2(v3);
snprintf(v3, 0x100uLL, "Largest allocation (exclusive of internal frag): %u", a1[20]);
result = ((__int64 (__fastcall *)(char *))a2)(v3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, void (__fastcall *a2)(char *))
{
__int64 result; // rax
char v3[280]; // [rsp-118h] [rbp-118h] BYREF

if ( a1 )
{
if ( a2 )
{
snprintf(v3, 0x100uLL, "Total number of calls to malloc: %u", a1[10]);
a2(v3);
snprintf(v3, 0x100uLL, "Total of all malloc calls - includes internal fragmentation: %u", a1[12]);
a2(v3);
snprintf(v3, 0x100uLL, "Total internal fragmentation: %u", a1[14]);
a2(v3);
snprintf(v3, 0x100uLL, "Current checkout, including internal fragmentation: %u", a1[16]);
a2(v3);
snprintf(v3, 0x100uLL, "Current number of distinct checkouts: %u", a1[17]);
a2(v3);
snprintf(v3, 0x100uLL, "Maximum instantaneous currentOut: %u", a1[18]);
a2(v3);
snprintf(v3, 0x100uLL, "Maximum instantaneous currentCount: %u", a1[19]);
a2(v3);
snprintf(v3, 0x100uLL, "Largest allocation (exclusive of internal frag): %u", a1[20]);
result = ((__int64 (__fastcall *)(char *))a2)(v3);
}
}
return result;
}

original_code:
void mplite_print_stats(const mplite_t * const handle,
                                   const mplite_putsfunc_t putsfunc)
{
    if ((handle != ((void *)0)) && (putsfunc != ((void *)0))) {
        char zStats[256];
        snprintf(zStats, sizeof (zStats), "Total number of calls to malloc: %u",
                (unsigned) handle->nAlloc);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Total of all malloc calls - includes "
                "internal fragmentation: %u", (unsigned) handle->totalAlloc);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Total internal fragmentation: %u",
                (unsigned) handle->totalExcess);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Current checkout, including internal "
                "fragmentation: %u", handle->currentOut);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Current number of distinct checkouts: %u",
                handle->currentCount);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Maximum instantaneous currentOut: %u",
                handle->maxOut);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Maximum instantaneous currentCount: %u",
                handle->maxCount);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Largest allocation (exclusive of "
                "internal frag): %u", handle->maxRequest);
        putsfunc(zStats);
    }
}

canonical_original_code:
void mplite_print_stats(struct mplite *handle, int (*putsfunc)(char *stats))
{
    if ((handle != ((void *)0)) && (putsfunc != ((void *)0))) {
        char zStats[256];
        snprintf(zStats, sizeof (zStats), "Total number of calls to malloc: %u",
                (unsigned int) handle->nAlloc);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Total of all malloc calls - includes "
                "internal fragmentation: %u", (unsigned int) handle->totalAlloc);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Total internal fragmentation: %u",
                (unsigned int) handle->totalExcess);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Current checkout, including internal "
                "fragmentation: %u", handle->currentOut);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Current number of distinct checkouts: %u",
                handle->currentCount);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Maximum instantaneous currentOut: %u",
                handle->maxOut);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Maximum instantaneous currentCount: %u",
                handle->maxCount);
        putsfunc(zStats);
        snprintf(zStats, sizeof (zStats), "Largest allocation (exclusive of "
                "internal frag): %u", handle->maxRequest);
        putsfunc(zStats);
    }
}

variable_types:
putsfunc
int (*)(char *stats)

variable_types:
zStats
char [256]


decompiled_code:
void *__fastcall multithreaded_main(void *a1)
{
unsigned int v1; // eax
const void *v2; // rdx

v1 = mplite_roundup(*((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
printf("index: %u requested size: %d round-up size: %d\n", *(_QWORD *)a1, *((unsigned int *)a1 + 4), v1);
while ( 1 )
{
v2 = (const void *)mplite_malloc(*((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
if ( !v2 )
break;
printf("index: %u address: %p size: %d\n", *(_QWORD *)a1, v2, *((unsigned int *)a1 + 4));
usleep(0x3E8u);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unsigned int v1; // eax
const void *v2; // rdx

v1 = mplite_roundup(*((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
printf("index: %u requested size: %d round-up size: %d\n", *(_QWORD *)a1, *((unsigned int *)a1 + 4), v1);
while ( 1 )
{
v2 = (const void *)mplite_malloc(*((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
if ( !v2 )
break;
printf("index: %u address: %p size: %d\n", *(_QWORD *)a1, v2, *((unsigned int *)a1 + 4));
usleep(0x3E8u);
}
return 0LL;
}

original_code:
void *
multithreaded_main(void *args)
{
    multithreaded_param_t *param;
    void *buffer;
    int round_size;
    param = (multithreaded_param_t *) args;
    round_size = mplite_roundup(param->pool, param->req_size);
    printf("index: %u requested size: %d round-up size: %d\n", param->index,
        param->req_size, round_size);
    while ((buffer = mplite_malloc(param->pool, param->req_size)) != ((void *)0)) {
        printf("index: %u address: %p size: %d\n", param->index, buffer,
            param->req_size);
        usleep(1000);
    }
    return ((void *)0);
}

canonical_original_code:
void *multithreaded_main(void *args)
{
    struct multithreaded_param *param;
    void *buffer;
    int round_size;
    param = (struct multithreaded_param *) args;
    round_size = mplite_roundup(param->pool, param->req_size);
    printf("index: %u requested size: %d round-up size: %d\n", param->index,
        param->req_size, round_size);
    while ((buffer = mplite_malloc(param->pool, param->req_size)) != ((void *)0)) {
        printf("index: %u address: %p size: %d\n", param->index, buffer,
            param->req_size);
        usleep(1000);
    }
    return ((void *)0);
}

variable_types:
args
void *

variable_types: struct multithreaded_param { unsigned long index; struct mplite { int szAtom; int nBlock; unsigned char *zPool; struct mplite_lock { void *arg; int (*acquire)(void *arg); int (*release)(void *arg); } lock; unsigned long nAlloc; unsigned long totalAlloc; unsigned long totalExcess; unsigned int currentOut; unsigned int currentCount; unsigned int maxOut; unsigned int maxCount; unsigned int maxRequest; int aiFreelist[-1]; unsigned char *aCtrl; } *pool; int req_size; } *

variable_types:
buffer
void *

user_defined_types: struct multithreaded_param { unsigned long index; struct mplite *pool; int req_size; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rbx
const void *v4; // rsi
unsigned __int64 v5; // rbx
pthread_t *v6; // r14
void *v7; // rax
_DWORD *v8; // rbx
pthread_t *v9; // r12
unsigned __int64 v10; // rbp
unsigned __int64 j; // rbx
size_t v12; // rbx
void *v13; // r15
void *ptr; // [rsp+8h] [rbp-190h]
int v16; // [rsp+1Ch] [rbp-17Ch] BYREF
pthread_mutex_t mutex; // [rsp+20h] [rbp-178h] BYREF
__int64 v18[4]; // [rsp+50h] [rbp-148h] BYREF
char v19[216]; // [rsp+70h] [rbp-128h] BYREF
unsigned __int64 v20; // [rsp+148h] [rbp-50h] BYREF
__int64 v21; // [rsp+150h] [rbp-48h] BYREF
size_t size[8]; // [rsp+158h] [rbp-40h] BYREF

pthread_mutex_init(&mutex, 0LL);
do
{
puts("Memory pool testing using mplite API");
printf("Enter the total memory block size: ");
_isoc99_scanf("%u", size);
printf("Enter the minimum memory allocation size: ");
_isoc99_scanf("%u", &v21);
printf("Enter the number of threads to run for multi-threaded test: ");
_isoc99_scanf("%u", &v20);
v12 = size[0];
v13 = malloc(size[0]);
printf("buffer = %p size = %u minimum alloc = %u\n", v13, v12, v21);
mplite_init(v19, v13, LODWORD(size[0]), (unsigned int)v21, 0LL);
puts("Single-threaded test...");
for ( i = 1LL; ; ++i )
{
v4 = (const void *)mplite_malloc(v19, (unsigned int)v21);
if ( !v4 )
break;
printf("malloc = %p counter = %u\n", v4, i);
}
mplite_print_stats(v19, &puts);
puts("Multi-threaded test...");
v18[0] = (__int64)&mutex;
v18[1] = (__int64)&pthread_mutex_lock;
v18[2] = (__int64)&pthread_mutex_unlock;
mplite_init(v19, v13, LODWORD(size[0]), (unsigned int)v21, v18);
v5 = v20;
v6 = (pthread_t *)malloc(8 * v20);
v7 = malloc(24 * v5);
ptr = v7;
if ( v5 )
{
v8 = v7;
v9 = v6;
v10 = 0LL;
do
{
*(_QWORD *)v8 = v10;
v8[4] = v21;
*((_QWORD *)v8 + 1) = v19;
pthread_create(v9, 0LL, multithreaded_main, v8);
++v10;
v8 += 6;
++v9;
}
while ( v20 > v10 );
if ( v20 )
{
for ( j = 0LL; j < v20; ++j )
pthread_join(v6[j], 0LL);
}
}
mplite_print_stats(v19, &puts);
free(ptr);
free(v6);
free(v13);
printf("Test again? <0:false, non-zero:true>: ");
_isoc99_scanf("%d", &v16);
}
while ( v16 );
pthread_mutex_destroy(&mutex);
return 0;
}

original_code:
int
main()
{
    size_t alloc_counter;
    size_t buffer_size;
    size_t min_alloc;
    size_t num_threads;
    char *large_buffer;
    char *alloc_ret;
    mplite_t mempool;
    pthread_t *threads;
    multithreaded_param_t *threads_param;
    mplite_lock_t pool_lock;
    pthread_mutex_t mutex;
    int test_again;
    int scanf_ret;
    pthread_mutex_init(&mutex, ((void *)0));
    do {
        printf("Memory pool testing using mplite API\n");
        printf("Enter the total memory block size: ");
        scanf_ret = scanf("%u", &buffer_size);
        printf("Enter the minimum memory allocation size: ");
        scanf_ret = scanf("%u", &min_alloc);
        printf("Enter the number of threads to run for multi-threaded test: ");
        scanf_ret = scanf("%u", &num_threads);
        large_buffer = malloc(buffer_size);
        printf("buffer = %p size = %u minimum alloc = %u\n", large_buffer,
            buffer_size, min_alloc);
        mplite_init(&mempool, large_buffer, (const int) buffer_size,
                        (const int) min_alloc, ((void *)0));
        printf("Single-threaded test...\n");
        alloc_counter = 1;
        while ((alloc_ret = mplite_malloc(&mempool, (const int) min_alloc)) != ((void *)0)) {
            printf("malloc = %p counter = %u\n", alloc_ret, alloc_counter);
            alloc_counter++;
        }
        mplite_print_stats(&mempool, puts);
        printf("Multi-threaded test...\n");
        pool_lock.arg = (void *) &mutex;
        pool_lock.acquire = (int (*)(void *))pthread_mutex_lock;
        pool_lock.release = (int (*)(void *))pthread_mutex_unlock;
        mplite_init(&mempool, large_buffer, (const int) buffer_size,
                        (const int) min_alloc, &pool_lock);
        threads = (pthread_t *) malloc(sizeof (*threads) * num_threads);
        threads_param = (multithreaded_param_t *) malloc(sizeof (*threads_param) * num_threads);
        for (alloc_counter = 0; alloc_counter < num_threads; alloc_counter++) {
            threads_param[alloc_counter].index = alloc_counter;
            threads_param[alloc_counter].req_size = (const int) min_alloc;
            threads_param[alloc_counter].pool = &mempool;
            pthread_create(&threads[alloc_counter], ((void *)0), multithreaded_main,
                        &threads_param[alloc_counter]);
        }
        for (alloc_counter = 0; alloc_counter < num_threads; alloc_counter++) {
            pthread_join(threads[alloc_counter], ((void *)0));
        }
        mplite_print_stats(&mempool, puts);
        free(threads_param);
        free(threads);
        free(large_buffer);
        printf("Test again? <0:false, non-zero:true>: ");
        scanf_ret = scanf("%d", &test_again);
    } while (test_again);
    pthread_mutex_destroy(&mutex);
    return 0;
}

canonical_original_code:
int main()
{
    unsigned long alloc_counter;
    unsigned long buffer_size;
    unsigned long min_alloc;
    unsigned long num_threads;
    char *large_buffer;
    char *alloc_ret;
    struct mplite mempool;
    unsigned long *threads;
    struct multithreaded_param *threads_param;
    struct mplite_lock pool_lock;
    union pthread_mutex_t mutex;
    int test_again;
    int scanf_ret;
    pthread_mutex_init(&mutex, ((void *)0));
    do {
        printf("Memory pool testing using mplite API\n");
        printf("Enter the total memory block size: ");
        scanf_ret = scanf("%u", &buffer_size);
        printf("Enter the minimum memory allocation size: ");
        scanf_ret = scanf("%u", &min_alloc);
        printf("Enter the number of threads to run for multi-threaded test: ");
        scanf_ret = scanf("%u", &num_threads);
        large_buffer = malloc(buffer_size);
        printf("buffer = %p size = %u minimum alloc = %u\n", large_buffer,
            buffer_size, min_alloc);
        mplite_init(&mempool, large_buffer, (int) buffer_size,
                        (int) min_alloc, ((void *)0));
        printf("Single-threaded test...\n");
        alloc_counter = 1;
        while ((alloc_ret = mplite_malloc(&mempool, (int) min_alloc)) != ((void *)0)) {
            printf("malloc = %p counter = %u\n", alloc_ret, alloc_counter);
            alloc_counter++;
        }
        mplite_print_stats(&mempool, puts);
        printf("Multi-threaded test...\n");
        pool_lock.arg = (void *) &mutex;
        pool_lock.acquire = (int (*)(void *))pthread_mutex_lock;
        pool_lock.release = (int (*)(void *))pthread_mutex_unlock;
        mplite_init(&mempool, large_buffer, (int) buffer_size,
                        (int) min_alloc, &pool_lock);
        threads = (unsigned long *) malloc(sizeof (*threads) * num_threads);
        threads_param = (struct multithreaded_param *) malloc(sizeof (*threads_param) * num_threads);
        for (alloc_counter = 0; alloc_counter < num_threads; alloc_counter++) {
            threads_param[alloc_counter].index = alloc_counter;
            threads_param[alloc_counter].req_size = (int) min_alloc;
            threads_param[alloc_counter].pool = &mempool;
            pthread_create(&threads[alloc_counter], ((void *)0), multithreaded_main,
                        &threads_param[alloc_counter]);
        }
        for (alloc_counter = 0; alloc_counter < num_threads; alloc_counter++) {
            pthread_join(threads[alloc_counter], ((void *)0));
        }
        mplite_print_stats(&mempool, puts);
        free(threads_param);
        free(threads);
        free(large_buffer);
        printf("Test again? <0:false, non-zero:true>: ");
        scanf_ret = scanf("%d", &test_again);
    } while (test_again);
    pthread_mutex_destroy(&mutex);
    return 0;
}

variable_types: struct mplite { int szAtom; int nBlock; unsigned char *zPool; struct mplite_lock { void *arg; int (*acquire)(void *arg); int (*release)(void *arg); } lock; unsigned long nAlloc; unsigned long totalAlloc; unsigned long totalExcess; unsigned int currentOut; unsigned int currentCount; unsigned int maxOut; unsigned int maxCount; unsigned int maxRequest; int aiFreelist[-1]; unsigned char *aCtrl; }

variable_types:
threads
unsigned long *

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; }

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

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


decompiled_code:
int __fastcall set_powersave(int a1)
{
if ( !a1 )
return system("cpufreq-set --min 1.4Ghz --max 1.92Ghz --governor ondemand");
system("cpufreq-set --min 200Mhz --max 200Mhz --governor ondemand");
system("echo 1 > /sys/devices/system/cpu/cpu1/online");
system("echo 1 > /sys/devices/system/cpu/cpu2/online");
return system("echo 1 > /sys/devices/system/cpu/cpu3/online");
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
if ( !a1 )
return system("cpufreq-set --min 1.4Ghz --max 1.92Ghz --governor ondemand");
system("cpufreq-set --min 200Mhz --max 200Mhz --governor ondemand");
system("echo 1 > /sys/devices/system/cpu/cpu1/online");
system("echo 1 > /sys/devices/system/cpu/cpu2/online");
return system("echo 1 > /sys/devices/system/cpu/cpu3/online");
}

original_code:
void set_powersave(int pws_flag){
 if (pws_flag){
  system("cpufreq-set --min 200Mhz --max 200Mhz --governor ondemand");
  system("echo 1 > /sys/devices/system/cpu/cpu1/online");
  system("echo 1 > /sys/devices/system/cpu/cpu2/online");
  system("echo 1 > /sys/devices/system/cpu/cpu3/online");
 } else{
  system("cpufreq-set --min 1.4Ghz --max 1.92Ghz --governor ondemand");
 }
}


unquote

repo: jelaas/eth-affinity

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

if ( *a1 == 92 )
{
do
{
result = (unsigned __int8)a1[1];
*a1++ = result;
}
while ( (_BYTE)result );
}
return result;
}

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

if ( *a1 == 92 )
{
do
{
result = (unsigned __int8)a1[1];
*a1++ = result;
}
while ( (_BYTE)result );
}
return result;
}

original_code:
static void unquote(char *s)
{
  char *p;
  if(*s != '\\')
    return;
  for(p=s;*p;p++)
    *p = *(p+1);
}

variable_types:
s
char *

variable_types:
p
char *


decompiled_code:
__int64 __fastcall find_short_arg(__int64 a1, int a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
unsigned int v5; // er12

v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
v4 = 1LL;
while ( 1 )
{
v5 = v4;
if ( *(_BYTE *)v3 == 45 )
{
if ( *(_BYTE *)(v3 + 1) == 45 )
{
if ( !*(_BYTE *)(v3 + 2) )
return (unsigned int)-1;
}
else if ( strchr((const char *)v3, a2) )
{
return v5;
}
}
++v4;
v3 = *(_QWORD *)(a1 + 8 * v4);
if ( !v3 )
return (unsigned int)-1;
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v3; // rdi
__int64 v4; // rbx
unsigned int v5; // er12

v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
v4 = 1LL;
while ( 1 )
{
v5 = v4;
if ( *(_BYTE *)v3 == 45 )
{
if ( *(_BYTE *)(v3 + 1) == 45 )
{
if ( !*(_BYTE *)(v3 + 2) )
return (unsigned int)-1;
}
else if ( strchr((const char *)v3, a2) )
{
return v5;
}
}
++v4;
v3 = *(_QWORD *)(a1 + 8 * v4);
if ( !v3 )
return (unsigned int)-1;
}
}
return (unsigned int)-1;
}

original_code:
static int find_short_arg(char **argv, int opt_short)
{
  int i;
  for(i=1;argv[i];i++)
    {
      char *a = argv[i];
      if(*a == '-')
 {
   if(*(a+1) == '-')
     {
       if(*(a+2) == 0)
  return -1;
       continue;
     }
   if(strchr(a, opt_short))
     return i;
 }
    }
  return -1;
}

variable_types:
argv
char **

variable_types: i int

variable_types:
a
char *


decompiled_code:
__int64 __fastcall find_long_arg(__int64 a1, const char *a2)
{
int v2; // eax
__int64 v3; // rbp
__int64 v4; // rbx
size_t v5; // r15
size_t v6; // r14
unsigned int v7; // er13
char v8; // al

v2 = strlen(a2);
v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
v4 = 1LL;
v5 = v2 + 2;
v6 = v2;
while ( 1 )
{
v7 = v4;
if ( *(_BYTE *)v3 == 45 && *(_BYTE *)(v3 + 1) == 45 )
{
if ( !*(_BYTE *)(v3 + 2) )
return (unsigned int)-1;
if ( strlen((const char *)v3) >= v5 )
{
v8 = *(_BYTE *)(v3 + v6 + 2);
if ( (!v8 || v8 == 61) && !strncmp((const char *)(v3 + 2), a2, v6) )
return v7;
}
}
++v4;
v3 = *(_QWORD *)(a1 + 8 * v4);
if ( !v3 )
return (unsigned int)-1;
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
int v2; // eax
__int64 v3; // rbp
__int64 v4; // rbx
size_t v5; // r15
size_t v6; // r14
unsigned int v7; // er13
char v8; // al

v2 = strlen(a2);
v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
v4 = 1LL;
v5 = v2 + 2;
v6 = v2;
while ( 1 )
{
v7 = v4;
if ( *(_BYTE *)v3 == 45 && *(_BYTE *)(v3 + 1) == 45 )
{
if ( !*(_BYTE *)(v3 + 2) )
return (unsigned int)-1;
if ( strlen((const char *)v3) >= v5 )
{
v8 = *(_BYTE *)(v3 + v6 + 2);
if ( (!v8 || v8 == 61) && !strncmp((const char *)(v3 + 2), a2, v6) )
return v7;
}
}
++v4;
v3 = *(_QWORD *)(a1 + 8 * v4);
if ( !v3 )
return (unsigned int)-1;
}
}
return (unsigned int)-1;
}

original_code:
static int find_long_arg(char **argv, char *opt_long)
{
  int i;
  int len = strlen(opt_long);
  for(i=1;argv[i];i++)
    {
      char *a = argv[i];
      if(*a == '-' && (*(a+1) == '-'))
 {
   if((*(a+2) == 0))
     return -1;
   if(strlen(a) < len+2)
     continue;
   if(a[len+2] != 0 && a[len+2] != '=')
     continue;
   if(strncmp(a+2, opt_long, len) == 0)
     return i;
 }
    }
  return -1;
}

variable_types: len int