rbInit

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

v2 = a2 + 1;
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(v2, 8uLL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

v2 = a2 + 1;
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(v2, 8uLL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void rbInit(RingBuffer *rb, int size) {
    rb->size = size + 1;
    rb->start = 0;
    rb->end = 0;
    rb->elems = (pthread_t *)calloc(rb->size, sizeof(pthread_t));
}

canonical_original_code:
void rbInit(struct RingBuffer *rb, int size) {
    rb->size = size + 1;
    rb->start = 0;
    rb->end = 0;
    rb->elems = (unsigned long *)calloc(rb->size, sizeof(pthread_t));
}

variable_types: struct RingBuffer { int size; int start; int end; unsigned long *elems; } *


rbFree

decompiled_code:
void __fastcall rbFree(__int64 a1)
{
free(*(void **)(a1 + 16));
}

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

original_code:
void rbFree(RingBuffer *rb) {
    free(rb->elems); }

canonical_original_code:
void rbFree(struct RingBuffer *rb) {
    free(rb->elems); }

return_type: void

user_defined_types: struct RingBuffer { int size; int start; int end; unsigned long *elems; }


rbIsFull

decompiled_code:
_BOOL8 __fastcall rbIsFull(_DWORD *a1)
{
return (a1[2] + 1) % *a1 == a1[1];
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1)
{
return (a1[2] + 1) % *a1 == a1[1];
}

original_code:
int rbIsFull(RingBuffer *rb) {
    return (rb->end + 1) % rb->size == rb->start; }

canonical_original_code:
int rbIsFull(struct RingBuffer *rb) {
    return (rb->end + 1) % rb->size == rb->start; }

return_type: int


rbIsEmpty

decompiled_code:
_BOOL8 __fastcall rbIsEmpty(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 4);
}

original_code:
int rbIsEmpty(RingBuffer *rb) {
    return rb->end == rb->start; }

canonical_original_code:
int rbIsEmpty(struct RingBuffer *rb) {
    return rb->end == rb->start; }


rbWrite

decompiled_code:
__int64 __fastcall rbWrite(int *a1, _QWORD *a2)
{
int v2; // eax
int v3; // ecx
int v4; // edx
__int64 result; // rax
int v6; // edx
__int64 v7; // rt2
int v8; // edx
unsigned int v9; // kr08_4

v2 = a1[2];
*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL * v2) = *a2;
v3 = *a1;
v4 = ++v2 >> 31;
v7 = __SPAIR64__(v4, v2) % *a1;
LODWORD(result) = __SPAIR64__(v4, v2) / *a1;
v6 = v7;
result = (unsigned int)result;
a1[2] = v7;
if ( (_DWORD)v7 == a1[1] )
{
v9 = v6 + 1;
v8 = (v6 + 1) >> 31;
result = (unsigned int)(__SPAIR64__(v8, v9) / v3);
a1[1] = __SPAIR64__(v8, v9) % v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, _QWORD *a2)
{
int v2; // eax
int v3; // ecx
int v4; // edx
__int64 result; // rax
int v6; // edx
__int64 v7; // rt2
int v8; // edx
unsigned int v9; // kr08_4

v2 = a1[2];
*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL * v2) = *a2;
v3 = *a1;
v4 = ++v2 >> 31;
v7 = __SPAIR64__(v4, v2) % *a1;
LODWORD(result) = __SPAIR64__(v4, v2) / *a1;
v6 = v7;
result = (unsigned int)result;
a1[2] = v7;
if ( (_DWORD)v7 == a1[1] )
{
v9 = v6 + 1;
v8 = (v6 + 1) >> 31;
result = (unsigned int)(__SPAIR64__(v8, v9) / v3);
a1[1] = __SPAIR64__(v8, v9) % v3;
}
return result;
}

original_code:
void rbWrite(RingBuffer *rb, pthread_t *elem) {
    rb->elems[rb->end] = *elem;
    rb->end = (rb->end + 1) % rb->size;
    if (rb->end == rb->start)
        rb->start = (rb->start + 1) % rb->size;
}

canonical_original_code:
void rbWrite(struct RingBuffer *rb, unsigned long *elem) {
    rb->elems[rb->end] = *elem;
    rb->end = (rb->end + 1) % rb->size;
    if (rb->end == rb->start)
        rb->start = (rb->start + 1) % rb->size;
}

variable_types:
elem
unsigned long *


rbRead

decompiled_code:
__int64 __fastcall rbRead(__int64 a1, _QWORD *a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx

v2 = *(_DWORD *)(a1 + 4) + 1;
*a2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * *(int *)(a1 + 4));
v4 = v2 % *(_DWORD *)a1;
result = (unsigned int)(v2 / *(_DWORD *)a1);
*(_DWORD *)(a1 + 4) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _QWORD *a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx

v2 = *(_DWORD *)(a1 + 4) + 1;
*a2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * *(int *)(a1 + 4));
v4 = v2 % *(_DWORD *)a1;
result = (unsigned int)(v2 / *(_DWORD *)a1);
*(_DWORD *)(a1 + 4) = v4;
return result;
}

original_code:
void rbRead(RingBuffer *rb, pthread_t *elem) {
    *elem = rb->elems[rb->start];
    rb->start = (rb->start + 1) % rb->size;
    }

canonical_original_code:
void rbRead(struct RingBuffer *rb, unsigned long *elem) {
    *elem = rb->elems[rb->start];
    rb->start = (rb->start + 1) % rb->size;
    }


decompiled_code:
__int64 __fastcall newfd_create_req(int fd)
{
char *v1; // rax
char *v2; // rbp
int v3; // ebx
__int64 v4; // rax
__int64 v5; // r12
__int64 v7; // rdi

v1 = (char *)malloc(0x400uLL);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = read(fd, v1, 0x400uLL);
if ( v3 >= 0 )
{
v4 = shttp_alloc_req((unsigned int)fd, v2);
v5 = v4;
if ( v4 )
{
if ( (unsigned int)shttp_get_path(v4) )
{
v2[v3] = 0;
printf("Incorrectly formatted HTTP request:\n\t%s\n", v2);
v7 = v5;
v5 = 0LL;
shttp_free_req(v7);
}
}
else
{
puts("Could not allocate request");
free(v2);
}
return v5;
}
perror("read off of new file descriptor");
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
char *v1; // rax
char *v2; // rbp
int v3; // ebx
__int64 v4; // rax
__int64 v5; // r12
__int64 v7; // rdi

v1 = (char *)malloc(0x400uLL);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = read(fd, v1, 0x400uLL);
if ( v3 >= 0 )
{
v4 = shttp_alloc_req((unsigned int)fd, v2);
v5 = v4;
if ( v4 )
{
if ( (unsigned int)shttp_get_path(v4) )
{
v2[v3] = 0;
printf("Incorrectly formatted HTTP request:\n\t%s\n", v2);
v7 = v5;
v5 = 0LL;
shttp_free_req(v7);
}
}
else
{
puts("Could not allocate request");
free(v2);
}
return v5;
}
perror("read off of new file descriptor");
free(v2);
return 0LL;
}

original_code:
struct http_req *
newfd_create_req(int new_fd)
{
 struct http_req *r;
 char *data;
 int amnt;
 data = malloc(1024 * sizeof(char));
 if (!data) return ((void *)0);
 amnt = read(new_fd, data, 1024);
 if (amnt < 0) {
  perror("read off of new file descriptor");
  free(data);
  return ((void *)0);
 }
 r = shttp_alloc_req(new_fd, data);
 if (!r) {
  printf("Could not allocate request\n");
  free(data);
  return ((void *)0);
 }
 if (shttp_get_path(r)) {
  data[amnt] = '\0';
  printf("Incorrectly formatted HTTP request:\n\t%s\n", data);
  shttp_free_req(r);
  return ((void *)0);
 }
 return r;
}

canonical_original_code:
struct http_req *newfd_create_req(int new_fd)
{
 struct http_req *r;
 char *data;
 int amnt;
 data = malloc(1024 * sizeof(char));
 if (!data) return ((void *)0);
 amnt = read(new_fd, data, 1024);
 if (amnt < 0) {
  perror("read off of new file descriptor");
  free(data);
  return ((void *)0);
 }
 r = shttp_alloc_req(new_fd, data);
 if (!r) {
  printf("Could not allocate request\n");
  free(data);
  return ((void *)0);
 }
 if (shttp_get_path(r)) {
  data[amnt] = '\0';
  printf("Incorrectly formatted HTTP request:\n\t%s\n", data);
  shttp_free_req(r);
  return ((void *)0);
 }
 return r;
}

variable_types: struct http_req { int fd; char *request; int req_len; char *path; char *resp_head; int resp_hd_len; } *

variable_types:
data
char *

variable_types: amnt int


decompiled_code:
__int64 __fastcall respond_and_free_req(__int64 a1)
{
int v1; // edx
int v2; // er12
int v3; // ebx
int v4; // eax
int v6; // edx
int v7; // eax

if ( !(unsigned int)shttp_alloc_response_head() )
{
v1 = *(_DWORD *)(a1 + 48);
v2 = 0;
v3 = 0;
if ( v1 )
{
while ( 1 )
{
v4 = write(*(_DWORD *)a1, (const void *)(*(_QWORD *)(a1 + 32) + v3), v1 - v3);
if ( v4 < 0 )
break;
v1 = *(_DWORD *)(a1 + 48);
v3 += v4;
if ( v1 == v3 )
goto LABEL_8;
}
}
else
{
LABEL_8:
v6 = *(_DWORD *)(a1 + 52);
if ( !v6 )
return shttp_free_req(a1);
while ( 1 )
{
v7 = write(*(_DWORD *)a1, (const void *)(*(_QWORD *)(a1 + 40) + v2), v6 - v2);
if ( v7 < 0 )
break;
v6 = *(_DWORD *)(a1 + 52);
v2 += v7;
if ( v6 == v2 )
return shttp_free_req(a1);
}
}
puts("Could not write the response to the fd");
return shttp_free_req(a1);
}
puts("Could not formulate HTTP response");
return shttp_free_req(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // edx
int v2; // er12
int v3; // ebx
int v4; // eax
int v6; // edx
int v7; // eax

if ( !(unsigned int)shttp_alloc_response_head() )
{
v1 = *(_DWORD *)(a1 + 48);
v2 = 0;
v3 = 0;
if ( v1 )
{
while ( 1 )
{
v4 = write(*(_DWORD *)a1, (const void *)(*(_QWORD *)(a1 + 32) + v3), v1 - v3);
if ( v4 < 0 )
break;
v1 = *(_DWORD *)(a1 + 48);
v3 += v4;
if ( v1 == v3 )
goto LABEL_8;
}
}
else
{
LABEL_8:
v6 = *(_DWORD *)(a1 + 52);
if ( !v6 )
return shttp_free_req(a1);
while ( 1 )
{
v7 = write(*(_DWORD *)a1, (const void *)(*(_QWORD *)(a1 + 40) + v2), v6 - v2);
if ( v7 < 0 )
break;
v6 = *(_DWORD *)(a1 + 52);
v2 += v7;
if ( v6 == v2 )
return shttp_free_req(a1);
}
}
puts("Could not write the response to the fd");
return shttp_free_req(a1);
}
puts("Could not formulate HTTP response");
return shttp_free_req(a1);
}

original_code:
void
respond_and_free_req(struct http_req *r, char *response, int len)
{
 int amnt_written = 0;
 if (shttp_alloc_response_head(r, response, len)) {
  printf("Could not formulate HTTP response\n");
  shttp_free_req(r);
  return;
 }
 while (amnt_written != r->resp_hd_len) {
  int ret = write(r->fd, r->resp_head + amnt_written,
    r->resp_hd_len - amnt_written);
  if (ret < 0) {
   printf("Could not write the response to the fd\n");
   goto done;
  }
  amnt_written += ret;
 }
 amnt_written = 0;
 while (amnt_written != r->resp_len) {
  int ret = write(r->fd, r->response + amnt_written,
    r->resp_len - amnt_written);
  if (ret < 0) {
   printf("Could not write the response to the fd\n");
   goto done;
  }
  amnt_written += ret;
 }
done:
 shttp_free_req(r);
 return;
}

variable_types:
response
char *

variable_types: len int

variable_types: ret int

user_defined_types: struct http_req { int fd; char *request; int req_len; char *path; char *resp_head; int resp_hd_len; }


decompiled_code:
int __fastcall client_process(int fd)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 v4; // rbp
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = newfd_create_req(fd);
if ( !v2 )
return close(fd);
v3 = *(_QWORD *)(v2 + 24);
v4 = v2;
if ( !v3 )
return close(fd);
if ( content_get(v3, v6) )
return respond_and_free_req(v4);
return shttp_free_req(v4);
}

canonical_decompiled_code:
int __fastcall func2(int fd)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 v4; // rbp
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = func0(fd);
if ( !v2 )
return close(fd);
v3 = *(_QWORD *)(v2 + 24);
v4 = v2;
if ( !v3 )
return close(fd);
if ( content_get(v3, v6) )
return func1(v4);
return shttp_free_req(v4);
}

original_code:
void
client_process(int fd)
{
 struct http_req *r;
 char *response;
 int len;
 r = newfd_create_req(fd);
 if (!r || !r->path) {
  close(fd);
  return;
 }
 ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "util.c", 131, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((r->path) ? 1 : 0), __extension__ ({ if (r->path) ; else __assert_fail ("r->path", "util.c", 132, __extension__ __PRETTY_FUNCTION__); }));
 response = content_get(r->path, &len);
 if (!response) {
  shttp_free_req(r);
  return;
 }
 respond_and_free_req(r, response, len);
}

variable_types: fd int


decompiled_code:
void __fastcall shttp_free_req(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

*((_QWORD *)ptr + 3) = 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 4);
if ( v4 )
free(v4);
close(*(_DWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

*((_QWORD *)ptr + 3) = 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 4);
if ( v4 )
free(v4);
close(*(_DWORD *)ptr);
free(ptr);
}

original_code:
void
shttp_free_req(struct http_req *r)
{
 r->path = ((void *)0);
 if (r->request) free(r->request);
 if (r->response) free(r->response);
 if (r->resp_head) free(r->resp_head);
 close(r->fd);
 free(r);
}


decompiled_code:
__int64 __fastcall shttp_get_path(__int64 a1)
{
_BYTE *v1; // r9
_BYTE *v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er8
__int64 v6; // r9

if ( !a1 )
_assert_fail("r", "simple_http.c", 0x3Fu, "shttp_get_path");
v1 = *(_BYTE **)(a1 + 8);
if ( !v1 )
_assert_fail("r->request", "simple_http.c", 0x40u, "shttp_get_path");
if ( memcmp(v1, "GET ", 4uLL) )
return (unsigned int)-1;
v2 = find_whitespace(v1 + 4);
if ( !*v2 )
return (unsigned int)-1;
*v2 = 0;
if ( *(_BYTE *)(v6 + 4) == 47 )
v4 = v6 + 5;
*(_QWORD *)(v3 + 24) = v4;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_BYTE *v1; // r9
_BYTE *v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er8
__int64 v6; // r9

if ( !a1 )
_assert_fail("r", "simple_http.c", 0x3Fu, "shttp_get_path");
v1 = *(_BYTE **)(a1 + 8);
if ( !v1 )
_assert_fail("r->request", "simple_http.c", 0x40u, "shttp_get_path");
if ( memcmp(v1, "GET ", 4uLL) )
return (unsigned int)-1;
v2 = find_whitespace(v1 + 4);
if ( !*v2 )
return (unsigned int)-1;
*v2 = 0;
if ( *(_BYTE *)(v6 + 4) == 47 )
v4 = v6 + 5;
*(_QWORD *)(v3 + 24) = v4;
return v5;
}

original_code:
int
shttp_get_path(struct http_req *r)
{
 char *curr, *end, *path;
 ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "simple_http.c", 63, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((r->request) ? 1 : 0), __extension__ ({ if (r->request) ; else __assert_fail ("r->request", "simple_http.c", 64, __extension__ __PRETTY_FUNCTION__); }));
 if (strncmp(r->request, "GET ", strlen("GET "))) return -1;
 path = curr = r->request + sizeof("GET ")-1;
 end = find_whitespace(curr);
 if (*end == '\0') return -1;
 *end = '\0';
 if (*path == '/') path++;
 r->path = path;
 return 0;
}

canonical_original_code:
int shttp_get_path(struct http_req *r)
{
 char *curr; char *end; char *path;
 ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "simple_http.c", 63, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((r->request) ? 1 : 0), __extension__ ({ if (r->request) ; else __assert_fail ("r->request", "simple_http.c", 64, __extension__ __PRETTY_FUNCTION__); }));
 if (strncmp(r->request, "GET ", strlen("GET "))) return -1;
 path = curr = r->request + sizeof("GET ")-1;
 end = find_whitespace(curr);
 if (*end == '\0') return -1;
 *end = '\0';
 if (*path == '/') path++;
 r->path = path;
 return 0;
}

variable_types:
curr
char *

variable_types:
end
char *

variable_types:
path
char *


original_code:
int
shttp_alloc_response_head(struct http_req *r, char *data, int dlen)
{
 int head_sz, pre_sz, len_sz;
 char len_str[128];
 char *resp_hd;
 r->response = data;
 r->resp_len = dlen;
 len_sz = snprintf(len_str, 128, "%d\r\n\r\n", r->resp_len);
 if (len_sz < 1) return -1;
 pre_sz = strlen(success_head);
 ((void) sizeof ((pre_sz > 0) ? 1 : 0), __extension__ ({ if (pre_sz > 0) ; else __assert_fail ("pre_sz > 0", "simple_http.c", 104, __extension__ __PRETTY_FUNCTION__); }));
 head_sz = pre_sz + len_sz;
 ((void) sizeof ((head_sz > 0) ? 1 : 0), __extension__ ({ if (head_sz > 0) ; else __assert_fail ("head_sz > 0", "simple_http.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 resp_hd = malloc(head_sz);
 if (!resp_hd) return -1;
 r->resp_head = resp_hd;
 r->resp_hd_len = head_sz;
 memcpy(resp_hd, success_head, pre_sz);
 memcpy(resp_hd + pre_sz, len_str, len_sz);
 return 0;
}

canonical_original_code:
int shttp_alloc_response_head(struct http_req *r, char *data, int dlen)
{
 int head_sz; int pre_sz; int len_sz;
 char len_str[128];
 char *resp_hd;
 r->response = data;
 r->resp_len = dlen;
 len_sz = snprintf(len_str, 128, "%d\r\n\r\n", r->resp_len);
 if (len_sz < 1) return -1;
 pre_sz = strlen(success_head);
 ((void) sizeof ((pre_sz > 0) ? 1 : 0), __extension__ ({ if (pre_sz > 0) ; else __assert_fail ("pre_sz > 0", "simple_http.c", 104, __extension__ __PRETTY_FUNCTION__); }));
 head_sz = pre_sz + len_sz;
 ((void) sizeof ((head_sz > 0) ? 1 : 0), __extension__ ({ if (head_sz > 0) ; else __assert_fail ("head_sz > 0", "simple_http.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 resp_hd = malloc(head_sz);
 if (!resp_hd) return -1;
 r->resp_head = resp_hd;
 r->resp_hd_len = head_sz;
 memcpy(resp_hd, success_head, pre_sz);
 memcpy(resp_hd + pre_sz, len_str, len_sz);
 return 0;
}

variable_types: dlen int


decompiled_code:
__int64 __fastcall server_create(__int16 a1)
{
unsigned int v1; // er12
socklen_t v2; // edx
struct sockaddr v4[2]; // [rsp+0h] [rbp-28h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
unsigned int v1; // er12
socklen_t v2; // edx
struct sockaddr v4[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
perror("Establishing socket");
}
else
{
v4[0].sa_family = 2;
*(_WORD *)v4[0].sa_data = func0(a1);
*(_DWORD *)&v4[0].sa_data[2] = func1(v1, v4);
if ( bind(v1, v4, v2) )
{
v1 = -1;
perror("binding receive socket");
}
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:
int __fastcall server_accept(int a1)
{
int result; // eax
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

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

canonical_decompiled_code:
int __fastcall func3(int a1)
{
int result; // eax
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

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

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:
len
unsigned int


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:
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 *file, int *a2)
{
char *v3; // r12
int v5; // er14
int v6; // er15
__off_t v7; // rdx
__int64 v8; // rax
__int64 v9; // rsi
int v10; // eax
__off_t v11; // [rsp+8h] [rbp-C0h]
struct stat v12; // [rsp+10h] [rbp-B8h] BYREF

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

canonical_decompiled_code:
char *__fastcall func2(char *file, int *a2)
{
char *v3; // r12
int v5; // er14
int v6; // er15
__off_t v7; // rdx
__int64 v8; // rax
__int64 v9; // rsi
int v10; // eax
__off_t v11; // [rsp+8h] [rbp-C0h]
struct stat v12; // [rsp+10h] [rbp-B8h] BYREF

if ( !func1(file) )
{
v5 = stat(file, &v12);
if ( !v5 && v12.st_size <= 10485760 )
{
v6 = open(file, 0);
if ( v6 >= 0 )
{
v11 = v12.st_size;
v3 = (char *)malloc(v12.st_size);
if ( v3 )
{
v7 = v11;
if ( v11 <= 0 )
{
LABEL_14:
*a2 = v7;
return v3;
}
v8 = 0LL;
v9 = 0LL;
while ( 1 )
{
v10 = read(v6, &v3[v9], v7 - v8);
if ( v10 < 0 )
break;
v5 += v10;
v7 = v12.st_size;
v9 = v5;
v8 = v5;
if ( v5 >= v12.st_size )
goto LABEL_14;
}
free(v3);
}
close(v6);
}
}
}
return func0(file, 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]; }

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 *


repo: jeffhammond/HPCInfo

decompiled_code:
_BOOL8 __fastcall heavy_calcs(int a1)
{
return a1 > 1000;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
return a1 > 1000;
}

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; // er13
void *v4; // r12
void *v5; // rbp
int v6; // er13

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

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

v3 = 1000;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = malloc(4LL * v3);
v5 = malloc(4LL * v3);
v6 = func7((unsigned int)v3, v4, v5);
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)
{
unsigned int i; // ebp
__int64 v5; // rbx
double v6; // xmm0_8
__int64 v7; // rdx
int result; // eax

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

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

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v5 = 0LL;
if ( a2 > 0 )
{
do
{
v6 = *(double *)(a3 + 8 * v5);
v7 = (unsigned int)v5++;
result = printf("*(%d,%d)=%lf\n", i, v7, v6);
}
while ( a2 != v5 );
}
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)
{
unsigned int i; // ebp
__int64 v5; // rbx
double v6; // xmm0_8
__int64 v7; // rdx
int result; // eax

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

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

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v5 = 0LL;
if ( a2 > 0 )
{
do
{
v6 = *(double *)(a3 + 8 * v5);
v7 = (unsigned int)v5++;
result = printf("(%d,%d)=%lf\n", i, v7, v6);
}
while ( a2 != v5 );
}
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]


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]


decompiled_code:
int __fastcall print1(int a1, int a2, __int64 a3)
{
int v3; // esi
__int64 v5; // rbp
__int64 i; // rbx
double v7; // xmm0_8
__int64 v8; // rsi
int result; // eax

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

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, __int64 a3)
{
int v3; // esi
__int64 v5; // rbp
__int64 i; // rbx
double v7; // xmm0_8
__int64 v8; // rsi
int result; // eax

v3 = a1 * a2;
if ( v3 > 0 )
{
v5 = v3;
for ( i = 0LL; i != v5; ++i )
{
v7 = *(double *)(a3 + 8 * i);
v8 = (unsigned int)i;
result = printf("(%d)=%lf\n", v8, v7);
}
}
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 []


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:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__int64 v4; // rdx
__int64 v5; // rdx
int v6; // ebx
double v7; // xmm1_8
double v8; // xmm0_8
double v10; // [rsp+8h] [rbp-20h]

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

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

if ( argc <= 1 )
{
v3 = 100000;
v10 = func7(argc, argv, envp);
}
else
{
*(_QWORD *)&argc = argv[1];
v3 = atoi(*(const char **)&argc);
v10 = func7(*(_QWORD *)&argc, argv, v4);
if ( v3 <= 0 )
{
v7 = 0.0;
goto LABEL_5;
}
}
v6 = 0;
v7 = 0.0;
do
{
++v6;
v7 = v7 + func7(*(_QWORD *)&argc, argv, v5);
}
while ( v6 < v3 );
LABEL_5:
v8 = func7(*(_QWORD *)&argc, argv, v5);
printf("dt = %lf s junk = %4.1e\n", (v8 - v10) * 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


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 __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // ebp
int v5; // er12
int v6; // er14
size_t v7; // rdi
double *v8; // r13
__int64 v9; // rax
char *v10; // rax
int v11; // er10
double *v12; // rbx
int i; // er11
int v14; // ecx
double *v15; // r8
int v16; // edi
int v17; // esi
double *v18; // rdx
int v19; // eax
double v20; // xmm0_8
void *size; // [rsp+8h] [rbp-50h]

if ( argc <= 1 )
{
v3 = 3;
v4 = 4;
v5 = 5;
v6 = 60;
v7 = 480LL;
v8 = (double *)malloc(0x1E0uLL);
LABEL_6:
v9 = 0LL;
do
{
v8[v9] = (double)(int)v9;
++v9;
}
while ( v6 > (int)v9 );
goto LABEL_8;
}
v3 = atoi(argv[1]);
if ( argc == 2 )
{
v4 = 4;
v5 = 5;
}
else
{
v4 = atoi(argv[2]);
if ( argc == 3 )
v5 = 5;
else
v5 = atoi(argv[3]);
}
v6 = v5 * v4 * v3;
v7 = 8LL * v6;
v8 = (double *)malloc(v7);
if ( v6 > 0 )
goto LABEL_6;
LABEL_8:
v10 = (char *)malloc(v7);
size = v10;
if ( v3 > 0 )
{
v11 = 0;
v12 = (double *)v10;
for ( i = 0; i != v3; ++i )
{
if ( v4 > 0 )
{
v14 = v11 + v5;
v15 = v12;
v16 = v11;
v17 = 0;
do
{
v18 = v15;
v19 = v16;
if ( v5 > 0 )
{
do
{
++v18;
v20 = (double)v19++;
*(v18 - 1) = v20;
}
while ( v19 != v14 );
}
++v17;
v16 += v5;
v15 += v5;
v14 += v5;
}
while ( v17 != v4 );
}
v11 += v5 * v4;
v12 += v5 * (__int64)v4;
}
}
print1((unsigned int)v6, v8);
print3((unsigned int)v3, (unsigned int)v4, (unsigned int)v5, v8);
print1((unsigned int)v6, size);
print3((unsigned int)v3, (unsigned int)v4, (unsigned int)v5, size);
free(size);
free(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // ebp
int v5; // er12
int v6; // er14
size_t v7; // rdi
double *v8; // r13
__int64 v9; // rax
char *v10; // rax
int v11; // er10
double *v12; // rbx
int i; // er11
int v14; // ecx
double *v15; // r8
int v16; // edi
int v17; // esi
double *v18; // rdx
int v19; // eax
double v20; // xmm0_8
void *size; // [rsp+8h] [rbp-50h]

if ( argc <= 1 )
{
v3 = 3;
v4 = 4;
v5 = 5;
v6 = 60;
v7 = 480LL;
v8 = (double *)malloc(0x1E0uLL);
LABEL_6:
v9 = 0LL;
do
{
v8[v9] = (double)(int)v9;
++v9;
}
while ( v6 > (int)v9 );
goto LABEL_8;
}
v3 = atoi(argv[1]);
if ( argc == 2 )
{
v4 = 4;
v5 = 5;
}
else
{
v4 = atoi(argv[2]);
if ( argc == 3 )
v5 = 5;
else
v5 = atoi(argv[3]);
}
v6 = v5 * v4 * v3;
v7 = 8LL * v6;
v8 = (double *)malloc(v7);
if ( v6 > 0 )
goto LABEL_6;
LABEL_8:
v10 = (char *)malloc(v7);
size = v10;
if ( v3 > 0 )
{
v11 = 0;
v12 = (double *)v10;
for ( i = 0; i != v3; ++i )
{
if ( v4 > 0 )
{
v14 = v11 + v5;
v15 = v12;
v16 = v11;
v17 = 0;
do
{
v18 = v15;
v19 = v16;
if ( v5 > 0 )
{
do
{
++v18;
v20 = (double)v19++;
*(v18 - 1) = v20;
}
while ( v19 != v14 );
}
++v17;
v16 += v5;
v15 += v5;
v14 += v5;
}
while ( v17 != v4 );
}
v11 += v5 * v4;
v12 += v5 * (__int64)v4;
}
}
func8((unsigned int)v6, v8);
func7((unsigned int)v3, (unsigned int)v4, (unsigned int)v5, v8);
func8((unsigned int)v6, size);
func7((unsigned int)v3, (unsigned int)v4, (unsigned int)v5, size);
free(size);
free(v8);
return 0;
}

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: i int


decompiled_code:
int __fastcall print1(int a1, __int64 a2)
{
__int64 v3; // rbx
double v4; // xmm0_8
__int64 v5; // rsi
int result; // eax

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

canonical_decompiled_code:
int __fastcall func8(int a1, __int64 a2)
{
__int64 v3; // rbx
double v4; // xmm0_8
__int64 v5; // rsi
int result; // eax

if ( a1 > 0 )
{
v3 = 0LL;
do
{
v4 = *(double *)(a2 + 8 * v3);
v5 = (unsigned int)v3++;
result = printf("(%d)=%lf\n", v5, v4);
}
while ( v3 != a1 );
}
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]);
}


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 *


decompiled_code:
void __fastcall build_commobj(__int64 a1)
{
int v1; // edx
int v2; // eax
int v3; // eax

*(_DWORD *)(a1 + 4) = 16;
*(_WORD *)(a1 + 10) = _bswap_16_constprop_0(a1, 2LL, 17LL);
*(_WORD *)(a1 + 8) = 2;
*(_DWORD *)(a1 + 12) = _bswap_32_constprop_0();
v2 = socket(2, 2, v1);
*(_DWORD *)a1 = v2;
do_or_die(v2, "socket()");
v3 = bind(*(_DWORD *)a1, (const struct sockaddr *)(a1 + 8), *(_DWORD *)(a1 + 4));
do_or_die(v3, "bind()");
}

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(int *a1)
{
socklen_t *v1; // r12
struct sockaddr *v2; // rbp
int v4; // edi
int v5; // eax
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

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

canonical_decompiled_code:
int __fastcall func4(int *a1)
{
socklen_t *v1; // r12
struct sockaddr *v2; // rbp
int v4; // edi
int v5; // eax
__int16 buf[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v1 = (socklen_t *)(a1 + 1);
v2 = (struct sockaddr *)(a1 + 6);
do
{
v4 = *a1;
buf[0] = 0;
v5 = recvfrom(v4, buf, 2uLL, 0, v2, v1);
func2(v5, "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)
{
const struct sockaddr *v6; // r8
unsigned int v7; // ebx
__int64 v8; // rax
__int64 v9; // rdx
int v10; // esi
bool v11; // cl
float v12; // xmm0_4
socklen_t v13; // er9
int v14; // edi
int v15; // eax
int v16; // eax
_DWORD v17[130]; // [rsp+0h] [rbp-240h] BYREF
const struct sockaddr *v18; // [rsp+208h] [rbp-38h]

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

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
const struct sockaddr *v6; // r8
unsigned int v7; // ebx
__int64 v8; // rax
__int64 v9; // rdx
int v10; // esi
bool v11; // cl
float v12; // xmm0_4
socklen_t v13; // er9
int v14; // edi
int v15; // eax
int v16; // eax
_DWORD v17[130]; // [rsp+0h] [rbp-240h] BYREF
const struct sockaddr *v18; // [rsp+208h] [rbp-38h]

if ( a2 )
{
v6 = (const struct sockaddr *)(a1 + 24);
v7 = 0;
while ( 1 )
{
v17[0] = v7;
if ( a2 <= v7 )
break;
v8 = 2LL;
do
{
v9 = v7++;
v10 = v8;
v11 = (int)v8 <= 126;
v12 = *(double *)(a3 + 8 * v9) * *(double *)(a3 + 8 * v9);
*(float *)&v17[v8++ - 1] = v12;
}
while ( v7 < a2 && v11 );
v13 = *(_DWORD *)(a1 + 4);
v14 = *(_DWORD *)a1;
v18 = v6;
v15 = sendto(v14, v17, 4 * v10, 0, v6, v13);
func2(v15, "sending datagram");
v6 = v18;
if ( v7 >= a2 )
return;
}
v16 = sendto(*(_DWORD *)a1, v17, 4uLL, 0, v6, *(_DWORD *)(a1 + 4));
func2(v16, "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; // er12
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;
v4 = 16;
if ( ioctl(v1, 0xC0045005uLL, &v4) == -1 )
{
perror("SNDCTL_DSP_SETFMT");
exit(-1);
}
if ( v4 != 16 )
{
fwrite("The device doesn't support the 16 bit sample format.\n", 1uLL, 0x35uLL, stderr);
exit(-1);
}
v4 = 1;
if ( ioctl(v2, 0xC0045006uLL, &v4) == -1 )
{
perror("SNDCTL_DSP_CHANNELS");
exit(-1);
}
if ( v4 != 1 )
{
fwrite("The device doesn't support mono mode.\n", 1uLL, 0x26uLL, stderr);
exit(-1);
}
v5[0] = 44100;
if ( ioctl(v2, 0xC0045002uLL, v5) == -1 )
{
perror("SNDCTL_DSP_SPEED");
exit(-1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s)
{
int v1; // eax
unsigned int v2; // er12
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;
v4 = 16;
if ( ioctl(v1, 0xC0045005uLL, &v4) == -1 )
{
perror("SNDCTL_DSP_SETFMT");
exit(-1);
}
if ( v4 != 16 )
{
fwrite("The device doesn't support the 16 bit sample format.\n", 1uLL, 0x35uLL, stderr);
exit(-1);
}
v4 = 1;
if ( ioctl(v2, 0xC0045006uLL, &v4) == -1 )
{
perror("SNDCTL_DSP_CHANNELS");
exit(-1);
}
if ( v4 != 1 )
{
fwrite("The device doesn't support mono mode.\n", 1uLL, 0x26uLL, stderr);
exit(-1);
}
v5[0] = 44100;
if ( ioctl(v2, 0xC0045002uLL, v5) == -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 func8(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; // ebp
int v4[14]; // [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(v4);
sense(v3, (__int64)v4);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4[14]; // [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(v4);
func9(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

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

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

v1 = 0;
if ( a1 > 1 )
{
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:
int *__fastcall mplite_link(int *a1, int a2, unsigned int a3)
{
int v3; // er9
int v4; // er8
__int64 v5; // r10
int v6; // ecx
int *result; // rax

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

canonical_decompiled_code:
int *__fastcall func1(int *a1, int a2, unsigned int a3)
{
int v3; // er9
int v4; // er8
__int64 v5; // r10
int v6; // ecx
int *result; // rax

if ( a2 < 0 || (v3 = a1[1], v3 <= a2) )
_assert_fail("i >= 0 && i < handle->nBlock", "../../src/mplite.c", 0x109u, "mplite_link");
if ( a3 > 0x1E )
_assert_fail("iLogsize >= 0 && iLogsize <= MPLITE_LOGMAX", "../../src/mplite.c", 0x10Au, "mplite_link");
if ( (*(_BYTE *)(*((_QWORD *)a1 + 26) + a2) & 0x1F) != a3 )
_assert_fail("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 0x10Bu, "mplite_link");
v4 = *a1;
v5 = *((_QWORD *)a1 + 1);
v6 = a1[(*(_BYTE *)(*((_QWORD *)a1 + 26) + a2) & 0x1F) + 21];
result = (int *)(v5 + a2 * *a1);
*result = v6;
result[1] = -1;
if ( v6 >= 0 )
{
if ( v3 <= v6 )
_assert_fail("x < handle->nBlock", "../../src/mplite.c", 0x110u, "mplite_link");
*(_DWORD *)(v5 + v6 * v4 + 4) = a2;
}
a1[a3 + 21] = 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(unsigned int *a1, int a2, unsigned int a3)
{
int v4; // edx
__int64 result; // rax
__int64 v6; // r8
int *v7; // rsi
int v8; // ecx
int v9; // esi

if ( a2 < 0 || (int)a1[1] <= 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");
v4 = *(_BYTE *)(*((_QWORD *)a1 + 26) + a2) & 0x1F;
if ( v4 != a3 )
_assert_fail("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 0x11Fu, "mplite_unlink");
result = *a1;
v6 = *((_QWORD *)a1 + 1);
v7 = (int *)(v6 + (int)result * a2);
v8 = *v7;
v9 = v7[1];
if ( v9 < 0 )
a1[v4 + 21] = v8;
else
*(_DWORD *)(v6 + v9 * (int)result) = v8;
if ( v8 >= 0 )
{
result = v8 * (int)result;
*(_DWORD *)(v6 + result + 4) = v9;
}
return result;
}

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

if ( a2 < 0 || (int)a1[1] <= 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");
v4 = *(_BYTE *)(*((_QWORD *)a1 + 26) + a2) & 0x1F;
if ( v4 != a3 )
_assert_fail("(handle->aCtrl[i] & MPLITE_CTRL_LOGSIZE) == iLogsize", "../../src/mplite.c", 0x11Fu, "mplite_unlink");
result = *a1;
v6 = *((_QWORD *)a1 + 1);
v7 = (int *)(v6 + (int)result * a2);
v8 = *v7;
v9 = v7[1];
if ( v9 < 0 )
a1[v4 + 21] = v8;
else
*(_DWORD *)(v6 + v9 * (int)result) = v8;
if ( v8 >= 0 )
{
result = v8 * (int)result;
*(_DWORD *)(v6 + result + 4) = v9;
}
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; // er12
int v3; // eax

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");
if ( v2 )
{
v3 = *(_DWORD *)(a1 + 4LL * a2 + 84);
do
{
if ( v2 > v3 )
v2 = v3;
v3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * v3);
}
while ( v3 > 0 );
}
mplite_unlink((unsigned int *)a1, v2, a2);
return (unsigned int)v2;
}

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

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");
if ( v2 )
{
v3 = *(_DWORD *)(a1 + 4LL * a2 + 84);
do
{
if ( v2 > v3 )
v2 = v3;
v3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + *(_DWORD *)a1 * v3);
}
while ( v3 > 0 );
}
func2((unsigned int *)a1, v2, a2);
return (unsigned int)v2;
}

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:
int *__fastcall mplite_free_unsafe(int *a1, __int64 a2)
{
__int64 v2; // rax
int v3; // er9
__int64 v5; // rsi
char *v6; // rdi
char v7; // dl
int v8; // er15
unsigned __int8 v9; // cl
int v10; // er13
__int64 v11; // rax
int v12; // er12
int v13; // eax
unsigned int v14; // edx
unsigned int v15; // edi
int v16; // eax
int v17; // edx
int v18; // ebx
unsigned int v19; // edx
__int64 v20; // rcx
__int64 v21; // rax
char v22; // dl

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

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

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

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; // r12
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; // r12
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 )
{
v4 = a2;
v5 = mplite_size((int *)a1, (__int64)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