decompiled_code:
__int64 __fastcall lmo_find_entry(__int64 a1)
{
__int64 v1; // r10
unsigned int v2; // esi
unsigned int v3; // edx
unsigned int v4; // eax
int v5; // edx
unsigned int v6; // ecx
__int64 v7; // r8
unsigned int v8; // er9
unsigned int v9; // ecx

v1 = *(_QWORD *)(a1 + 16);
v2 = *(_DWORD *)(a1 + 4) - 1;
v3 = v2 >> 1;
while ( 1 )
{
v4 = _bswap_32(*(_DWORD *)(v1 + 16LL * v3));
if ( v4 == v8 )
break;
if ( v4 > v8 )
{
if ( !v5 )
return 0LL;
v2 = v5 - 1;
v3 = v6 + ((v5 - 1 - v6) >> 1);
if ( v2 < v6 )
return 0LL;
}
else
{
v9 = v5 + 1;
v3 = v9 + ((v2 - v9) >> 1);
if ( v2 < v9 )
return 0LL;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r10
unsigned int v2; // esi
unsigned int v3; // edx
unsigned int v4; // eax
int v5; // edx
unsigned int v6; // ecx
__int64 v7; // r8
unsigned int v8; // er9
unsigned int v9; // ecx

v1 = *(_QWORD *)(a1 + 16);
v2 = *(_DWORD *)(a1 + 4) - 1;
v3 = v2 >> 1;
while ( 1 )
{
v4 = func0(*(_DWORD *)(v1 + 16LL * v3));
if ( v4 == v8 )
break;
if ( v4 > v8 )
{
if ( !v5 )
return 0LL;
v2 = v5 - 1;
v3 = v6 + ((v5 - 1 - v6) >> 1);
if ( v2 < v6 )
return 0LL;
}
else
{
v9 = v5 + 1;
v3 = v9 + ((v2 - v9) >> 1);
if ( v2 < v9 )
return 0LL;
}
}
return v7;
}

original_code:
static lmo_entry_t * lmo_find_entry(lmo_archive_t *ar, uint32_t hash)
{
 unsigned int m, l, r;
 uint32_t k;
 l = 0;
 r = ar->length - 1;
 while (1)
 {
  m = l + ((r - l) / 2);
  if (r < l)
   break;
  k = ntohl(ar->index[m].key_id);
  if (k == hash)
   return &ar->index[m];
  if (k > hash)
  {
   if (!m)
    break;
   r = m - 1;
  }
  else
  {
   l = m + 1;
  }
 }
 return ((void *)0);
}

canonical_original_code:
static struct lmo_entry *lmo_find_entry(struct lmo_archive *ar, unsigned int hash)
{
 unsigned int m; unsigned int l; unsigned int r;
 unsigned int k;
 l = 0;
 r = ar->length - 1;
 while (1)
 {
  m = l + ((r - l) / 2);
  if (r < l)
   break;
  k = ntohl(ar->index[m].key_id);
  if (k == hash)
   return &ar->index[m];
  if (k > hash)
  {
   if (!m)
    break;
   r = m - 1;
  }
  else
  {
   l = m + 1;
  }
 }
 return ((void *)0);
}

variable_types: struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry *index; char *mmap; char *end; struct lmo_archive *next; } *

variable_types:
hash
unsigned int

variable_types:
m
unsigned int

variable_types:
r
unsigned int

variable_types:
k
unsigned int

return_type: struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *


repo: nanpuyue/openwrt-extra

original_code:
uint32_t sfh_hash(const char *data, int len)
{
 uint32_t hash = len, tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
  tmp = (((((uint32_t)(((const uint8_t *)(data+2))[1])) << 8) +(uint32_t)(((const uint8_t *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof(uint16_t);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
   hash ^= hash << 16;
   hash ^= data[sizeof(uint16_t)] << 18;
   hash += hash >> 11;
   break;
  case 2: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
   hash ^= hash << 11;
   hash += hash >> 17;
   break;
  case 1: hash += *data;
   hash ^= hash << 10;
   hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

canonical_original_code:
unsigned int sfh_hash(char *data, int len)
{
 unsigned int hash = len; unsigned int tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
  tmp = (((((unsigned int)(((unsigned char *)(data+2))[1])) << 8) +(unsigned int)(((unsigned char *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof(unsigned short);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
   hash ^= hash << 16;
   hash ^= data[sizeof(unsigned short)] << 18;
   hash += hash >> 11;
   break;
  case 2: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
   hash ^= hash << 11;
   hash += hash >> 17;
   break;
  case 1: hash += *data;
   hash ^= hash << 10;
   hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

variable_types:
data
char *

variable_types: len int

variable_types:
tmp
unsigned int

variable_types: rem int

return_type: unsigned int


original_code:
uint32_t lmo_canon_hash(const char *str, int len)
{
 char res[4096];
 char *ptr, prev;
 int off;
 if (!str || len >= sizeof(res))
  return 0;
 for (prev = ' ', ptr = res, off = 0; off < len; prev = *str, off++, str++)
 {
  if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace))
    *ptr++ = ' ';
  }
  else
  {
   *ptr++ = *str;
  }
 }
 if ((ptr > res) && ((*__ctype_b_loc ())[(int) ((*(ptr-1)))] & (unsigned short int) _ISspace))
  ptr--;
 return sfh_hash(res, ptr - res);
}

canonical_original_code:
unsigned int lmo_canon_hash(char *str, int len)
{
 char res[4096];
 char *ptr; char prev;
 int off;
 if (!str || len >= sizeof(res))
  return 0;
 for (prev = ' ', ptr = res, off = 0; off < len; prev = *str, off++, str++)
 {
  if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace))
    *ptr++ = ' ';
  }
  else
  {
   *ptr++ = *str;
  }
 }
 if ((ptr > res) && ((*__ctype_b_loc ())[(int) ((*(ptr-1)))] & (unsigned short) _ISspace))
  ptr--;
 return sfh_hash(res, ptr - res);
}

variable_types:
str
char *

variable_types:
res
char [4096]

variable_types:
ptr
char *

variable_types: prev char

variable_types: off int


decompiled_code:
__int64 __fastcall lmo_open(char *file)
{
int v1; // ebp
_DWORD *v2; // rax
__int64 v3; // r12
int v4; // eax
char *v5; // rax
unsigned int v6; // eax
int v7; // edx
__int64 v8; // rcx
char *v9; // r8
__int64 result; // rax
__int64 v11; // rdx
__int64 v12; // rsi
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

if ( stat(file, &v13) == -1 )
return 0LL;
v1 = open(file, 0);
if ( v1 == -1 )
return 0LL;
v2 = calloc(0x30uLL, 1uLL);
v3 = (__int64)v2;
if ( !v2 )
{
if ( v1 >= 0 )
close(v1);
return 0LL;
}
*v2 = v1;
v2[2] = v13.st_size;
v4 = fcntl(v1, 1);
fcntl(*(_DWORD *)v3, 2, v4 | 1u);
v5 = (char *)mmap(0LL, *(unsigned int *)(v3 + 8), 1, 1, *(_DWORD *)v3, 0LL);
*(_QWORD *)(v3 + 24) = v5;
if ( v5 == (char *)-1LL )
{
if ( v1 < 0 )
{
LABEL_9:
free((void *)v3);
return 0LL;
}
LABEL_13:
close(v1);
v9 = *(char **)(v3 + 24);
LABEL_7:
if ( (unsigned __int64)(v9 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v9, *(unsigned int *)(v3 + 8));
goto LABEL_9;
}
v6 = _bswap_32(*(_DWORD *)&v5[*(unsigned int *)(v3 + 8) - 4]);
if ( (unsigned int)v8 <= v6 )
{
if ( v1 < 0 )
goto LABEL_7;
goto LABEL_13;
}
v11 = v7 - v6;
v12 = v6;
result = v3;
*(_QWORD *)(v3 + 32) = &v9[v8];
*(_QWORD *)(v3 + 16) = &v9[v12];
*(_DWORD *)(v3 + 4) = (unsigned __int64)(v11 - 4) >> 4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *file)
{
int v1; // ebp
_DWORD *v2; // rax
__int64 v3; // r12
int v4; // eax
char *v5; // rax
unsigned int v6; // eax
int v7; // edx
__int64 v8; // rcx
char *v9; // r8
__int64 result; // rax
__int64 v11; // rdx
__int64 v12; // rsi
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

if ( stat(file, &v13) == -1 )
return 0LL;
v1 = open(file, 0);
if ( v1 == -1 )
return 0LL;
v2 = calloc(0x30uLL, 1uLL);
v3 = (__int64)v2;
if ( !v2 )
{
if ( v1 >= 0 )
close(v1);
return 0LL;
}
*v2 = v1;
v2[2] = v13.st_size;
v4 = fcntl(v1, 1);
fcntl(*(_DWORD *)v3, 2, v4 | 1u);
v5 = (char *)mmap(0LL, *(unsigned int *)(v3 + 8), 1, 1, *(_DWORD *)v3, 0LL);
*(_QWORD *)(v3 + 24) = v5;
if ( v5 == (char *)-1LL )
{
if ( v1 < 0 )
{
LABEL_9:
free((void *)v3);
return 0LL;
}
LABEL_13:
close(v1);
v9 = *(char **)(v3 + 24);
LABEL_7:
if ( (unsigned __int64)(v9 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v9, *(unsigned int *)(v3 + 8));
goto LABEL_9;
}
v6 = func0(*(_DWORD *)&v5[*(unsigned int *)(v3 + 8) - 4]);
if ( (unsigned int)v8 <= v6 )
{
if ( v1 < 0 )
goto LABEL_7;
goto LABEL_13;
}
v11 = v7 - v6;
v12 = v6;
result = v3;
*(_QWORD *)(v3 + 32) = &v9[v8];
*(_QWORD *)(v3 + 16) = &v9[v12];
*(_DWORD *)(v3 + 4) = (unsigned __int64)(v11 - 4) >> 4;
return result;
}

original_code:
lmo_archive_t * lmo_open(const char *file)
{
 int in = -1;
 uint32_t idx_offset = 0;
 struct stat s;
 lmo_archive_t *ar = ((void *)0);
 if (stat(file, &s) == -1)
  goto err;
 if ((in = open(file, 00)) == -1)
  goto err;
 if ((ar = (lmo_archive_t *)malloc(sizeof(*ar))) != ((void *)0))
 {
  memset(ar, 0, sizeof(*ar));
  ar->fd = in;
  ar->size = s.st_size;
  fcntl(ar->fd, 2, fcntl(ar->fd, 1) | 1);
  if ((ar->mmap = mmap(((void *)0), ar->size, 0x1, 0x01, ar->fd, 0)) == ((void *) -1))
   goto err;
  idx_offset = ntohl(*((const uint32_t *)
                       (ar->mmap + ar->size - sizeof(uint32_t))));
  if (idx_offset >= ar->size)
   goto err;
  ar->index = (lmo_entry_t *)(ar->mmap + idx_offset);
  ar->length = (ar->size - idx_offset - sizeof(uint32_t)) / sizeof(lmo_entry_t);
  ar->end = ar->mmap + ar->size;
  return ar;
 }
err:
 if (in > -1)
  close(in);
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  free(ar);
 }
 return ((void *)0);
}

canonical_original_code:
struct lmo_archive *lmo_open(char *file)
{
 int in = -1;
 unsigned int idx_offset = 0;
 struct stat s;
 struct lmo_archive *ar = ((void *)0);
 if (stat(file, &s) == -1)
  goto err;
 if ((in = open(file, 00)) == -1)
  goto err;
 if ((ar = (struct lmo_archive *)malloc(sizeof(*ar))) != ((void *)0))
 {
  memset(ar, 0, sizeof(*ar));
  ar->fd = in;
  ar->size = s.st_size;
  fcntl(ar->fd, 2, fcntl(ar->fd, 1) | 1);
  if ((ar->mmap = mmap(((void *)0), ar->size, 0x1, 0x01, ar->fd, 0)) == ((void *) -1))
   goto err;
  idx_offset = ntohl(*((unsigned int *)
                       (ar->mmap + ar->size - sizeof(unsigned int))));
  if (idx_offset >= ar->size)
   goto err;
  ar->index = (struct lmo_entry *)(ar->mmap + idx_offset);
  ar->length = (ar->size - idx_offset - sizeof(unsigned int)) / sizeof(lmo_entry_t);
  ar->end = ar->mmap + ar->size;
  return ar;
 }
err:
 if (in > -1)
  close(in);
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  free(ar);
 }
 return ((void *)0);
}

variable_types:
file
char *

variable_types: in int

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

variable_types: struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *index; char *mmap; char *end; struct lmo_archive *next; } *

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

user_defined_types: struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry *index; char *mmap; char *end; struct lmo_archive *next; }


decompiled_code:
void __fastcall lmo_close(void *ptr)
{
char *v2; // rdi

if ( ptr )
{
v2 = (char *)*((_QWORD *)ptr + 3);
if ( (unsigned __int64)(v2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v2, *((unsigned int *)ptr + 2));
close(*(_DWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
char *v2; // rdi

if ( ptr )
{
v2 = (char *)*((_QWORD *)ptr + 3);
if ( (unsigned __int64)(v2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v2, *((unsigned int *)ptr + 2));
close(*(_DWORD *)ptr);
free(ptr);
}
}

original_code:
void lmo_close(lmo_archive_t *ar)
{
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  close(ar->fd);
  free(ar);
  ar = ((void *)0);
 }
}

canonical_original_code:
void lmo_close(struct lmo_archive *ar)
{
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  close(ar->fd);
  free(ar);
  ar = ((void *)0);
 }
}

return_type: void

user_defined_types: struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; }


decompiled_code:
int __fastcall lmo_change_catalog(char *s2)
{
__int64 v1; // rbx
int result; // eax

v1 = lmo_catalogs;
if ( !lmo_catalogs )
return -1;
while ( 1 )
{
result = strncmp((const char *)v1, s2, 6uLL);
if ( !result )
break;
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return -1;
}
lmo_active_catalog = v1;
return result;
}

canonical_decompiled_code:
int __fastcall func6(char *s2)
{
__int64 v1; // rbx
int result; // eax

v1 = lmo_catalogs;
if ( !lmo_catalogs )
return -1;
while ( 1 )
{
result = strncmp((const char *)v1, s2, 6uLL);
if ( !result )
break;
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return -1;
}
lmo_active_catalog = v1;
return result;
}

original_code:
int lmo_change_catalog(const char *lang)
{
 lmo_catalog_t *cat;
 for (cat = _lmo_catalogs; cat; cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   _lmo_active_catalog = cat;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int lmo_change_catalog(char *lang)
{
 struct lmo_catalog *cat;
 for (cat = _lmo_catalogs; cat; cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   _lmo_active_catalog = cat;
   return 0;
  }
 }
 return -1;
}

variable_types:
lang
char *

variable_types: struct lmo_catalog { char lang[6]; struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *index; char *mmap; char *end; struct lmo_archive *next; } *archives; struct lmo_catalog *next; } *

return_type: int

user_defined_types: struct lmo_catalog { char lang[6]; struct lmo_archive *archives; struct lmo_catalog *next; }


decompiled_code:
__int64 __fastcall lmo_translate(char *a1, unsigned int a2, _QWORD *a3, _DWORD *a4)
{
__int64 v6; // r11
__int64 v7; // rax
__int64 v8; // r11
unsigned int v9; // eax
__int64 v10; // rdx
unsigned int v11; // edi
__int64 v12; // r11

if ( !a1 )
return 4294967294LL;
if ( !lmo_active_catalog )
return 4294967294LL;
lmo_canon_hash(a1, a2);
v6 = *(_QWORD *)(lmo_active_catalog + 8LL);
if ( !v6 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v7 = lmo_find_entry(v6);
if ( v7 )
break;
v6 = *(_QWORD *)(v8 + 40);
if ( !v6 )
return 0xFFFFFFFFLL;
}
v9 = _bswap_32(*(_DWORD *)(v7 + 8));
v11 = *(_DWORD *)(v10 + 12);
*a3 = *(_QWORD *)(v12 + 24) + v9;
*a4 = _bswap_32(v11);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, unsigned int a2, _QWORD *a3, _DWORD *a4)
{
__int64 v6; // r11
__int64 v7; // rax
__int64 v8; // r11
unsigned int v9; // eax
__int64 v10; // rdx
unsigned int v11; // edi
__int64 v12; // r11

if ( !a1 )
return 4294967294LL;
if ( !lmo_active_catalog )
return 4294967294LL;
func3(a1, a2);
v6 = *(_QWORD *)(lmo_active_catalog + 8LL);
if ( !v6 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v7 = func1(v6);
if ( v7 )
break;
v6 = *(_QWORD *)(v8 + 40);
if ( !v6 )
return 0xFFFFFFFFLL;
}
v9 = func0(*(_DWORD *)(v7 + 8));
v11 = *(_DWORD *)(v10 + 12);
*a3 = *(_QWORD *)(v12 + 24) + v9;
*a4 = func0(v11);
return 0LL;
}

original_code:
int lmo_translate(const char *key, int keylen, char **out, int *outlen)
{
 uint32_t hash;
 lmo_entry_t *e;
 lmo_archive_t *ar;
 if (!key || !_lmo_active_catalog)
  return -2;
 hash = lmo_canon_hash(key, keylen);
 for (ar = _lmo_active_catalog->archives; ar; ar = ar->next)
 {
  if ((e = lmo_find_entry(ar, hash)) != ((void *)0))
  {
   *out = ar->mmap + ntohl(e->offset);
   *outlen = ntohl(e->length);
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int lmo_translate(char *key, int keylen, char **out, int *outlen)
{
 unsigned int hash;
 struct lmo_entry *e;
 struct lmo_archive *ar;
 if (!key || !_lmo_active_catalog)
  return -2;
 hash = lmo_canon_hash(key, keylen);
 for (ar = _lmo_active_catalog->archives; ar; ar = ar->next)
 {
  if ((e = lmo_find_entry(ar, hash)) != ((void *)0))
  {
   *out = ar->mmap + ntohl(e->offset);
   *outlen = ntohl(e->length);
   return 0;
  }
 }
 return -1;
}

variable_types:
key
char *

variable_types: keylen int

variable_types:
out
char **

variable_types:
outlen
int *

variable_types:
hash
unsigned int

variable_types: struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *


decompiled_code:
void __fastcall lmo_close_catalog(char *s2)
{
__int64 v1; // rbp
__int64 v2; // r12
int v3; // er8
__int64 v4; // rax
_QWORD *v5; // rbx
void *v6; // rdi

v1 = lmo_catalogs;
if ( lmo_catalogs )
{
v2 = 0LL;
while ( 1 )
{
v3 = strncmp((const char *)v1, s2, 6uLL);
v4 = *(_QWORD *)(v1 + 16);
if ( !v3 )
break;
v2 = v1;
if ( !v4 )
return;
v1 = *(_QWORD *)(v1 + 16);
}
if ( v2 )
*(_QWORD *)(v2 + 16) = v4;
else
lmo_catalogs = *(_QWORD *)(v1 + 16);
v5 = *(_QWORD **)(v1 + 8);
while ( v5 )
{
v6 = v5;
v5 = (_QWORD *)v5[5];
lmo_close(v6);
}
free((void *)v1);
}
}

canonical_decompiled_code:
void __fastcall func9(char *s2)
{
__int64 v1; // rbp
__int64 v2; // r12
int v3; // er8
__int64 v4; // rax
_QWORD *v5; // rbx
void *v6; // rdi

v1 = lmo_catalogs;
if ( lmo_catalogs )
{
v2 = 0LL;
while ( 1 )
{
v3 = strncmp((const char *)v1, s2, 6uLL);
v4 = *(_QWORD *)(v1 + 16);
if ( !v3 )
break;
v2 = v1;
if ( !v4 )
return;
v1 = *(_QWORD *)(v1 + 16);
}
if ( v2 )
*(_QWORD *)(v2 + 16) = v4;
else
lmo_catalogs = *(_QWORD *)(v1 + 16);
v5 = *(_QWORD **)(v1 + 8);
while ( v5 )
{
v6 = v5;
v5 = (_QWORD *)v5[5];
func5(v6);
}
free((void *)v1);
}
}

original_code:
void lmo_close_catalog(const char *lang)
{
 lmo_archive_t *ar, *next;
 lmo_catalog_t *cat, *prev;
 for (prev = ((void *)0), cat = _lmo_catalogs; cat; prev = cat, cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   if (prev)
    prev->next = cat->next;
   else
    _lmo_catalogs = cat->next;
   for (ar = cat->archives; ar; ar = next)
   {
    next = ar->next;
    lmo_close(ar);
   }
   free(cat);
   break;
  }
 }
}

canonical_original_code:
void lmo_close_catalog(char *lang)
{
 struct lmo_archive *ar; struct lmo_archive *next;
 struct lmo_catalog *cat; struct lmo_catalog *prev;
 for (prev = ((void *)0), cat = _lmo_catalogs; cat; prev = cat, cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   if (prev)
    prev->next = cat->next;
   else
    _lmo_catalogs = cat->next;
   for (ar = cat->archives; ar; ar = next)
   {
    next = ar->next;
    lmo_close(ar);
   }
   free(cat);
   break;
  }
 }
}


decompiled_code:
__int64 __fastcall cmp_index(const void *a1, const void *a2)
{
__int64 result; // rax

result = *(_DWORD *)a1 > *(_DWORD *)a2;
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
result = 0xFFFFFFFFLL;
return result;
}

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

result = *(_DWORD *)a1 > *(_DWORD *)a2;
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int cmp_index(const void *a, const void *b)
{
 uint32_t x = ((const lmo_entry_t *)a)->key_id;
 uint32_t y = ((const lmo_entry_t *)b)->key_id;
 if (x < y)
  return -1;
 else if (x > y)
  return 1;
 return 0;
}

canonical_original_code:
static int cmp_index(void *a, void *b)
{
 unsigned int x = ((const lmo_entry_t *)a)->key_id;
 unsigned int y = ((const lmo_entry_t *)b)->key_id;
 if (x < y)
  return -1;
 else if (x > y)
  return 1;
 return 0;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
x
unsigned int

variable_types:
y
unsigned int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s input.po output.lmo\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "Usage: %s input.po output.lmo\n", a1);
exit(1);
}

original_code:
static void usage(const char *name)
{
 fprintf(stderr, "Usage: %s input.po output.lmo\n", name);
 exit(1);
}

canonical_original_code:
static void usage(char *name)
{
 fprintf(stderr, "Usage: %s input.po output.lmo\n", name);
 exit(1);
}

variable_types:
name
char *


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
exit(1);
}

original_code:
static void die(const char *msg)
{
 fprintf(stderr, "Error: %s\n", msg);
 exit(1);
}

canonical_original_code:
static void die(char *msg)
{
 fprintf(stderr, "Error: %s\n", msg);
 exit(1);
}

variable_types:
msg
char *


KeyGenFunc

repo: naphthalene/tnetris

decompiled_code:
__int64 __fastcall KeyGenFunc(__int64 a1, __int64 a2)
{
return 2 * (unsigned int)((unsigned int)MyRead(*(unsigned int *)(a1 + 16), a2 + 8, 1LL) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return 2 * (unsigned int)((unsigned int)MyRead(*(unsigned int *)(a1 + 16), a2 + 8, 1LL) != 0);
}

original_code:
static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event)
{
 if (MyRead(gen->fd, &event->u.key, 1))
  return E_key;
 else
  return E_none;
}

canonical_original_code:
static enum _MyEventType KeyGenFunc(struct _EventGenRec *gen, struct _MyEvent *event)
{
 if (MyRead(gen->fd, &event->u.key, 1))
  return E_key;
 else
  return E_none;
}

variable_types: struct _EventGenRec { struct _EventGenRec *next; int ready; enum _FDType { FT_read=0, FT_write=1, FT_except=2, FT_len=3 } fdType; int fd; enum _MyEventType { E_none=0, E_alarm=1, E_key=2, E_net=3, E_lostConn=4, E_robot=5, E_lostRobot=6 } (*func)(struct _EventGenRec *gen, struct _MyEvent { enum _MyEventType { E_none=0, E_alarm=1, E_key=2, E_net=3, E_lostConn=4, E_robot=5, E_lostRobot=6 } type; union { char key; struct { enum _NetPacketType { NP_endConn=0, NP_giveJunk=1, NP_newPiece=2, NP_down=3, NP_left=4, NP_right=5, NP_rotate=6, NP_drop=7, NP_clear=8, NP_insertJunk=9, NP_startConn=10, NP_userName=11, NP_pause=12, NP_version=13, NP_byeBye=14 } type; int size; void *data; } net; struct { int size; char *data; } robot; } u; } *event); int mask; } *

variable_types:
event
struct _MyEvent *

user_defined_types: struct _EventGenRec { struct _EventGenRec *next; int ready; enum _FDType fdType; int fd; enum _MyEventType (*func)(struct _EventGenRec *gen, struct _MyEvent *event); int mask; }

user_defined_types: struct _MyEvent { enum _MyEventType type; union { char key; struct { enum _NetPacketType type; int size; void *data; } net; struct { int size; char *data; } robot; } u; }


decompiled_code:
int __fastcall PlotBlock1(int a1, int a2, int a3, char a4)
{
const char *v5; // rsi

wmove(stdscr, boardYPos[a1] - a2, boardXPos[a1] + 2 * a3);
if ( !a4 )
return waddnstr(stdscr, " ", -1);
if ( standoutEnable )
{
if ( haveColor )
wattrset(stdscr, abs8(a4) << 8);
else
wattrset(stdscr, 0x10000);
}
v5 = (const char *)&unk_AD8;
if ( a4 <= 0 )
v5 = "$$";
waddnstr(stdscr, v5, -1);
return wattrset(stdscr, 0);
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2, int a3, char a4)
{
const char *v5; // rsi

wmove(stdscr, boardYPos[a1] - a2, boardXPos[a1] + 2 * a3);
if ( !a4 )
return waddnstr(stdscr, " ", -1);
if ( standoutEnable )
{
if ( haveColor )
wattrset(stdscr, abs8(a4) << 8);
else
wattrset(stdscr, 0x10000);
}
v5 = (const char *)&unk_AD8;
if ( a4 <= 0 )
v5 = "$$";
waddnstr(stdscr, v5, -1);
return wattrset(stdscr, 0);
}

original_code:
static void PlotBlock1(int scr, int y, int x, BlockType type)
{
 int colorIndex = abs(type);
 wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * x));
 if (type == BT_none)
  waddnstr(stdscr,("  "),-1);
 else
 {
  if (standoutEnable)
  {
   if (haveColor)
    wattrset(stdscr,((((chtype)(((colorIndex))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
   else
    (wattrset(stdscr,((chtype)((1U)) << ((8) + 8))));
  }
  waddnstr(stdscr,(type > 0 ? "[]" : "$$"),-1);
  (wattrset(stdscr,(1U - 1U)));
 }
}

canonical_original_code:
static void PlotBlock1(int scr, int y, int x, char type)
{
 int colorIndex = abs(type);
 wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * x));
 if (type == BT_none)
  waddnstr(stdscr,("  "),-1);
 else
 {
  if (standoutEnable)
  {
   if (haveColor)
    wattrset(stdscr,((((chtype)(((colorIndex))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
   else
    (wattrset(stdscr,((chtype)((1U)) << ((8) + 8))));
  }
  waddnstr(stdscr,(type > 0 ? "[]" : "$$"),-1);
  (wattrset(stdscr,(1U - 1U)));
 }
}

variable_types: scr int

variable_types: y int

variable_types: x int

variable_types: type char

variable_types: colorIndex int


GetTermcapInfo

decompiled_code:
int GetTermcapInfo()
{
char *v0; // rax
const char *v1; // rbp
__int64 v2; // r12
const char **v3; // rbx
const char *v4; // rsi
char *v5; // r12
signed int v6; // eax
char *v7; // rsi
char *v9[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getenv("TERM");
if ( v0 )
{
v1 = v0;
LODWORD(v0) = tgetent(&scratch, v0);
if ( (_DWORD)v0 == 1 )
{
v9[0] = (char *)malloc(0x2800uLL);
v5 = v9[0];
term_vi = (int)tgetstr("vi", v9);
v6 = (unsigned int)tgetstr("ve", v9);
v7 = v9[0];
term_ve = v6;
if ( v9[0] > v5 + 10240 )
{
fatal("tgetstr overflow, you must have a very sick termcap");
v7 = v9[0];
}
LODWORD(v0) = (unsigned int)realloc(v5, v7 - v5);
}
v2 = term_vi;
if ( !term_vi || !term_ve )
{
v3 = (const char **)off_CA8;
v4 = "vt100";
do
{
LODWORD(v0) = strcmp(v1, v4);
if ( !(_DWORD)v0 )
{
term_vi = (__int64)"\x1B[?25l";
term_ve = (__int64)"\x1B[?25h";
return (int)v0;
}
v4 = *v3++;
}
while ( v4 );
if ( !v2 || !term_ve )
{
term_ve = 0LL;
term_vi = 0LL;
}
}
}
return (int)v0;
}

canonical_decompiled_code:
int func2()
{
char *v0; // rax
const char *v1; // rbp
__int64 v2; // r12
const char **v3; // rbx
const char *v4; // rsi
char *v5; // r12
signed int v6; // eax
char *v7; // rsi
char *v9[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getenv("TERM");
if ( v0 )
{
v1 = v0;
LODWORD(v0) = tgetent(&scratch, v0);
if ( (_DWORD)v0 == 1 )
{
v9[0] = (char *)malloc(0x2800uLL);
v5 = v9[0];
term_vi = (int)tgetstr("vi", v9);
v6 = (unsigned int)tgetstr("ve", v9);
v7 = v9[0];
term_ve = v6;
if ( v9[0] > v5 + 10240 )
{
fatal("tgetstr overflow, you must have a very sick termcap");
v7 = v9[0];
}
LODWORD(v0) = (unsigned int)realloc(v5, v7 - v5);
}
v2 = term_vi;
if ( !term_vi || !term_ve )
{
v3 = (const char **)off_CA8;
v4 = "vt100";
do
{
LODWORD(v0) = strcmp(v1, v4);
if ( !(_DWORD)v0 )
{
term_vi = (__int64)"\x1B[?25l";
term_ve = (__int64)"\x1B[?25h";
return (int)v0;
}
v4 = *v3++;
}
while ( v4 );
if ( !v2 || !term_ve )
{
term_ve = 0LL;
term_vi = 0LL;
}
}
}
return (int)v0;
}

original_code:
void GetTermcapInfo(void)
{
 char *term, *buf, *data;
 int bufSize = 10240;
 if (!(term = getenv("TERM")))
  return;
 if (tgetent(scratch, term) == 1) {
  data = buf = malloc(bufSize);
  term_vi = (char *)tgetstr("vi", &data);
  term_ve = (char *)tgetstr("ve", &data);
  if (data > buf + bufSize)
   fatal("tgetstr overflow, you must have a very sick termcap");
  buf = realloc(buf, data - buf);
 }
 if (!term_vi || !term_ve) {
  static char *vts[] = {
    "vt100", "vt101", "vt102",
    "vt200", "vt220", "vt300",
    "vt320", "vt400", "vt420",
    "screen", "xterm", ((void *)0) };
  int i;
  for (i = 0; vts[i]; i++)
   if (!strcmp(term, vts[i]))
   {
    term_vi = "\033[?25l";
    term_ve = "\033[?25h";
    break;
   }
 }
 if (!term_vi || !term_ve)
  term_vi = term_ve = ((void *)0);
}

canonical_original_code:
void GetTermcapInfo()
{
 char *term; char *buf; char *data;
 int bufSize = 10240;
 if (!(term = getenv("TERM")))
  return;
 if (tgetent(scratch, term) == 1) {
  data = buf = malloc(bufSize);
  term_vi = (char *)tgetstr("vi", &data);
  term_ve = (char *)tgetstr("ve", &data);
  if (data > buf + bufSize)
   fatal("tgetstr overflow, you must have a very sick termcap");
  buf = realloc(buf, data - buf);
 }
 if (!term_vi || !term_ve) {
  static char *vts[] = {
    "vt100", "vt101", "vt102",
    "vt200", "vt220", "vt300",
    "vt320", "vt400", "vt420",
    "screen", "xterm", ((void *)0) };
  int i;
  for (i = 0; vts[i]; i++)
   if (!strcmp(term, vts[i]))
   {
    term_vi = "\033[?25l";
    term_ve = "\033[?25h";
    break;
   }
 }
 if (!term_vi || !term_ve)
  term_vi = term_ve = ((void *)0);
}

variable_types:
term
char *

variable_types:
buf
char *

variable_types:
data
char *

variable_types: bufSize int

variable_types:
vts
char *[]

variable_types: i int


OutputTermStr

decompiled_code:
int __fastcall OutputTermStr(const char *a1, int a2)
{
int result; // eax

if ( a1 )
{
result = fputs(a1, stdout);
if ( a2 )
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, int a2)
{
int result; // eax

if ( a1 )
{
result = fputs(a1, stdout);
if ( a2 )
result = fflush(stdout);
}
return result;
}

original_code:
void OutputTermStr(char *str, int flush)
{
 if (str) {
  fputs(str, stdout);
  if (flush)
   fflush(stdout);
 }
}

variable_types:
str
char *

variable_types: flush int


InitScreens

decompiled_code:
int InitScreens()
{
int result; // eax
_WORD *v1; // rbx
__int16 v2; // dx
__int16 v3; // di
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

GetTermcapInfo();
BlockSignals(v4, 2LL, 0LL);
initscr();
if ( colorEnable && has_colors() )
{
haveColor = 1;
v1 = &unk_D04;
start_color();
v2 = 7;
v3 = 1;
while ( 1 )
{
v1 += 2;
init_pair(v3, 0, v2);
v3 = *((char *)v1 - 4);
if ( !*((_BYTE *)v1 - 4) )
break;
v2 = *(v1 - 1);
}
}
else
{
haveColor = 0;
}
AtExit(CleanupScreens);
RestoreSignals(0LL, v4);
cbreak();
noecho();
OutputTermStr((const char *)term_vi, 0);
AddEventGen(&keyGen);
wmove(stdscr, 0, 0);
waddnstr(stdscr, "Netris ", -1);
waddnstr(stdscr, version_string, -1);
result = waddnstr(stdscr, " (C) 1994-1996,1999 Mark H. Weaver \"netris -h\" for more info", -1);
statusYPos = 22;
statusXPos = 0;
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax
_WORD *v1; // rbx
__int16 v2; // dx
__int16 v3; // di
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

func2();
BlockSignals(v4, 2LL, 0LL);
initscr();
if ( colorEnable && has_colors() )
{
haveColor = 1;
v1 = &unk_D04;
start_color();
v2 = 7;
v3 = 1;
while ( 1 )
{
v1 += 2;
init_pair(v3, 0, v2);
v3 = *((char *)v1 - 4);
if ( !*((_BYTE *)v1 - 4) )
break;
v2 = *(v1 - 1);
}
}
else
{
haveColor = 0;
}
AtExit(CleanupScreens);
RestoreSignals(0LL, v4);
cbreak();
noecho();
func3((const char *)term_vi, 0);
AddEventGen(&keyGen);
wmove(stdscr, 0, 0);
waddnstr(stdscr, "Netris ", -1);
waddnstr(stdscr, version_string, -1);
result = waddnstr(stdscr, " (C) 1994-1996,1999 Mark H. Weaver \"netris -h\" for more info", -1);
statusYPos = 22;
statusXPos = 0;
return result;
}

original_code:
void InitScreens(void)
{
 MySigSet oldMask;
 GetTermcapInfo();
 BlockSignals(&oldMask, 2, 0);
 initscr();
 haveColor = colorEnable && has_colors();
 if (haveColor)
 {
  int i = 0;
  start_color();
  for (i = 0; myColorTable[i].type != BT_none; ++i)
   init_pair(myColorTable[i].type, 0,
     myColorTable[i].color);
 }
 AtExit(CleanupScreens);
 RestoreSignals(((void *)0), &oldMask);
 cbreak();
 noecho();
 OutputTermStr(term_vi, 0);
 AddEventGen(&keyGen);
 wmove(stdscr,(0),(0));
 waddnstr(stdscr,("Netris "),-1);
 waddnstr(stdscr,(version_string),-1);
 waddnstr(stdscr,(" (C) 1994-1996,1999  Mark H. Weaver     " "\"netris -h\" for more info"),-1);
 statusYPos = 22;
 statusXPos = 0;
}

canonical_original_code:
void InitScreens()
{
 struct __sigset_t oldMask;
 GetTermcapInfo();
 BlockSignals(&oldMask, 2, 0);
 initscr();
 haveColor = colorEnable && has_colors();
 if (haveColor)
 {
  int i = 0;
  start_color();
  for (i = 0; myColorTable[i].type != BT_none; ++i)
   init_pair(myColorTable[i].type, 0,
     myColorTable[i].color);
 }
 AtExit(CleanupScreens);
 RestoreSignals(((void *)0), &oldMask);
 cbreak();
 noecho();
 OutputTermStr(term_vi, 0);
 AddEventGen(&keyGen);
 wmove(stdscr,(0),(0));
 waddnstr(stdscr,("Netris "),-1);
 waddnstr(stdscr,(version_string),-1);
 waddnstr(stdscr,(" (C) 1994-1996,1999  Mark H. Weaver     " "\"netris -h\" for more info"),-1);
 statusYPos = 22;
 statusXPos = 0;
}

variable_types: struct __sigset_t { unsigned long __val[-1]; }


CleanupScreens

decompiled_code:
int CleanupScreens()
{
RemoveEventGen(&keyGen);
endwin();
return OutputTermStr((const char *)term_ve, 1);
}

canonical_decompiled_code:
int func5()
{
RemoveEventGen(&keyGen);
endwin();
return func3((const char *)term_ve, 1);
}

original_code:
void CleanupScreens(void)
{
 RemoveEventGen(&keyGen);
 endwin();
 OutputTermStr(term_ve, 1);
}

canonical_original_code:
void CleanupScreens()
{
 RemoveEventGen(&keyGen);
 endwin();
 OutputTermStr(term_ve, 1);
}


InitScreen

decompiled_code:
int __fastcall InitScreen(int a1)
{
int v1; // edx
__int64 v2; // rbp
int v3; // eax
int result; // eax
int v5; // er12
int v6; // ebx
int i; // esi
bool v8; // cf
int v9; // ebx

if ( a1 )
{
v2 = a1;
v1 = boardXPos[a1 - 1] + 2 * *((_DWORD *)&boardWidth + a1 - 1) + 3;
boardXPos[a1] = v1;
}
else
{
boardXPos[0] = 1;
v1 = 1;
v2 = 0LL;
}
v3 = *((_DWORD *)&boardWidth + v2);
boardYPos[v2] = 22;
result = v1 + 2 * v3;
if ( result + 2 >= statusXPos )
{
result += 3;
statusXPos = result;
}
v5 = *((_DWORD *)&boardVisible + v2);
v6 = v5 - 1;
if ( v5 - 1 >= 0 )
{
for ( i = 22; ; i = boardYPos[v2] )
{
wmove(stdscr, i - v6, v1 - 1);
waddch(stdscr, 0x7CuLL);
wmove(stdscr, boardYPos[v2] - v6, boardXPos[v2] + 2 * *((_DWORD *)&boardWidth + v2));
result = waddch(stdscr, 0x7CuLL);
v8 = v6-- == 0;
if ( v8 )
break;
v1 = boardXPos[v2];
}
v5 = *((_DWORD *)&boardVisible + v2);
}
for ( ; v5 >= -1; v5 -= result )
{
wmove(stdscr, boardYPos[v2] - v5, boardXPos[v2] - 1);
waddch(stdscr, 0x2BuLL);
v9 = *((_DWORD *)&boardWidth + v2) - 1;
if ( v9 >= 0 )
{
do
{
waddnstr(stdscr, "--", -1);
v8 = v9-- == 0;
}
while ( !v8 );
}
waddch(stdscr, 0x2BuLL);
result = *((_DWORD *)&boardVisible + v2) + 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
int v1; // edx
__int64 v2; // rbp
int v3; // eax
int result; // eax
int v5; // er12
int v6; // ebx
int i; // esi
bool v8; // cf
int v9; // ebx

if ( a1 )
{
v2 = a1;
v1 = boardXPos[a1 - 1] + 2 * *((_DWORD *)&boardWidth + a1 - 1) + 3;
boardXPos[a1] = v1;
}
else
{
boardXPos[0] = 1;
v1 = 1;
v2 = 0LL;
}
v3 = *((_DWORD *)&boardWidth + v2);
boardYPos[v2] = 22;
result = v1 + 2 * v3;
if ( result + 2 >= statusXPos )
{
result += 3;
statusXPos = result;
}
v5 = *((_DWORD *)&boardVisible + v2);
v6 = v5 - 1;
if ( v5 - 1 >= 0 )
{
for ( i = 22; ; i = boardYPos[v2] )
{
wmove(stdscr, i - v6, v1 - 1);
waddch(stdscr, 0x7CuLL);
wmove(stdscr, boardYPos[v2] - v6, boardXPos[v2] + 2 * *((_DWORD *)&boardWidth + v2));
result = waddch(stdscr, 0x7CuLL);
v8 = v6-- == 0;
if ( v8 )
break;
v1 = boardXPos[v2];
}
v5 = *((_DWORD *)&boardVisible + v2);
}
for ( ; v5 >= -1; v5 -= result )
{
wmove(stdscr, boardYPos[v2] - v5, boardXPos[v2] - 1);
waddch(stdscr, 0x2BuLL);
v9 = *((_DWORD *)&boardWidth + v2) - 1;
if ( v9 >= 0 )
{
do
{
waddnstr(stdscr, "--", -1);
v8 = v9-- == 0;
}
while ( !v8 );
}
waddch(stdscr, 0x2BuLL);
result = *((_DWORD *)&boardVisible + v2) + 1;
}
return result;
}

original_code:
void InitScreen(int scr)
{
 int y, x;
 if (scr == 0)
  boardXPos[scr] = 1;
 else
  boardXPos[scr] = boardXPos[scr - 1] +
     2 * boardWidth[scr - 1] + 3;
 boardYPos[scr] = 22;
 if (statusXPos < boardXPos[scr] + 2 * boardWidth[scr] + 3)
  statusXPos = boardXPos[scr] + 2 * boardWidth[scr] + 3;
 for (y = boardVisible[scr] - 1; y >= 0; --y) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('|'));
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * boardWidth[scr]));
  waddch(stdscr,('|'));
 }
 for (y = boardVisible[scr]; y >= -1; y -= boardVisible[scr] + 1) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('+'));
  for (x = boardWidth[scr] - 1; x >= 0; --x)
   waddnstr(stdscr,("--"),-1);
  waddch(stdscr,('+'));
 }
}

canonical_original_code:
void InitScreen(int scr)
{
 int y; int x;
 if (scr == 0)
  boardXPos[scr] = 1;
 else
  boardXPos[scr] = boardXPos[scr - 1] +
     2 * boardWidth[scr - 1] + 3;
 boardYPos[scr] = 22;
 if (statusXPos < boardXPos[scr] + 2 * boardWidth[scr] + 3)
  statusXPos = boardXPos[scr] + 2 * boardWidth[scr] + 3;
 for (y = boardVisible[scr] - 1; y >= 0; --y) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('|'));
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * boardWidth[scr]));
  waddch(stdscr,('|'));
 }
 for (y = boardVisible[scr]; y >= -1; y -= boardVisible[scr] + 1) {
  wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] - 1));
  waddch(stdscr,('+'));
  for (x = boardWidth[scr] - 1; x >= 0; --x)
   waddnstr(stdscr,("--"),-1);
  waddch(stdscr,('+'));
 }
}


CleanupScreen

decompiled_code:
void CleanupScreen()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void CleanupScreen(int scr)
{
}

canonical_original_code:
void CleanupScreen(int scr)
{
}


PlotBlock

decompiled_code:
int __fastcall PlotBlock(int a1, int a2, int a3, char a4)
{
int result; // eax

if ( a2 >= 0 )
{
result = a1;
if ( *((_DWORD *)&boardVisible + a1) > a2 && a3 >= 0 && *((_DWORD *)&boardWidth + a1) > a3 )
result = PlotBlock1(a1, a2, a3, a4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2, int a3, char a4)
{
int result; // eax

if ( a2 >= 0 )
{
result = a1;
if ( *((_DWORD *)&boardVisible + a1) > a2 && a3 >= 0 && *((_DWORD *)&boardWidth + a1) > a3 )
result = func1(a1, a2, a3, a4);
}
return result;
}

original_code:
void PlotBlock(int scr, int y, int x, BlockType type)
{
 if (y >= 0 && y < boardVisible[scr] && x >= 0 && x < boardWidth[scr])
  PlotBlock1(scr, y, x, type);
}

canonical_original_code:
void PlotBlock(int scr, int y, int x, char type)
{
 if (y >= 0 && y < boardVisible[scr] && x >= 0 && x < boardWidth[scr])
  PlotBlock1(scr, y, x, type);
}


PlotUnderline

decompiled_code:
int __fastcall PlotUnderline(int a1, int a2, int a3)
{
const char *v4; // rsi

wmove(stdscr, boardYPos[a1] + 1, boardXPos[a1] + 2 * a2);
v4 = "==";
if ( !a3 )
v4 = "--";
return waddnstr(stdscr, v4, -1);
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, int a3)
{
const char *v4; // rsi

wmove(stdscr, boardYPos[a1] + 1, boardXPos[a1] + 2 * a2);
v4 = "==";
if ( !a3 )
v4 = "--";
return waddnstr(stdscr, v4, -1);
}

original_code:
void PlotUnderline(int scr, int x, int flag)
{
 wmove(stdscr,(boardYPos[scr] + 1),(boardXPos[scr] + 2 * x));
 waddnstr(stdscr,(flag ? "==" : "--"),-1);
}

variable_types: flag int


ShowDisplayInfo

decompiled_code:
int ShowDisplayInfo()
{
int result; // eax

wmove(stdscr, statusYPos - 9, statusXPos);
printw("Seed: %d", initSeed);
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 8, statusXPos);
printw("Speed: %dms", speed / 1000LL);
result = wclrtoeol(stdscr);
if ( !robotEnable )
{
if ( (opponentFlags & 1) == 0 )
return result;
goto LABEL_7;
}
wmove(stdscr, statusYPos - 6, statusXPos);
if ( fairRobot )
waddnstr(stdscr, "Controlled by a fair robot", -1);
else
waddnstr(stdscr, "Controlled by a robot", -1);
result = wclrtoeol(stdscr);
if ( (opponentFlags & 1) != 0 )
{
LABEL_7:
wmove(stdscr, statusYPos - 5, statusXPos);
if ( (opponentFlags & 2) != 0 )
waddnstr(stdscr, "The opponent is a fair robot", -1);
else
waddnstr(stdscr, "The opponent is a robot", -1);
result = wclrtoeol(stdscr);
}
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax

wmove(stdscr, statusYPos - 9, statusXPos);
printw("Seed: %d", initSeed);
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 8, statusXPos);
printw("Speed: %dms", speed / 1000LL);
result = wclrtoeol(stdscr);
if ( !robotEnable )
{
if ( (opponentFlags & 1) == 0 )
return result;
goto LABEL_7;
}
wmove(stdscr, statusYPos - 6, statusXPos);
if ( fairRobot )
waddnstr(stdscr, "Controlled by a fair robot", -1);
else
waddnstr(stdscr, "Controlled by a robot", -1);
result = wclrtoeol(stdscr);
if ( (opponentFlags & 1) != 0 )
{
LABEL_7:
wmove(stdscr, statusYPos - 5, statusXPos);
if ( (opponentFlags & 2) != 0 )
waddnstr(stdscr, "The opponent is a fair robot", -1);
else
waddnstr(stdscr, "The opponent is a robot", -1);
result = wclrtoeol(stdscr);
}
return result;
}

original_code:
void ShowDisplayInfo(void)
{
 wmove(stdscr,(statusYPos - 9),(statusXPos));
 printw("Seed: %d", initSeed);
 wclrtoeol(stdscr);
 wmove(stdscr,(statusYPos - 8),(statusXPos));
 printw("Speed: %dms", speed / 1000);
 wclrtoeol(stdscr);
 if (robotEnable) {
  wmove(stdscr,(statusYPos - 6),(statusXPos));
  if (fairRobot)
   waddnstr(stdscr,("Controlled by a fair robot"),-1);
  else
   waddnstr(stdscr,("Controlled by a robot"),-1);
  wclrtoeol(stdscr);
 }
 if (opponentFlags & 000001) {
  wmove(stdscr,(statusYPos - 5),(statusXPos));
  if (opponentFlags & 000002)
   waddnstr(stdscr,("The opponent is a fair robot"),-1);
  else
   waddnstr(stdscr,("The opponent is a robot"),-1);
  wclrtoeol(stdscr);
 }
}

canonical_original_code:
void ShowDisplayInfo()
{
 wmove(stdscr,(statusYPos - 9),(statusXPos));
 printw("Seed: %d", initSeed);
 wclrtoeol(stdscr);
 wmove(stdscr,(statusYPos - 8),(statusXPos));
 printw("Speed: %dms", speed / 1000);
 wclrtoeol(stdscr);
 if (robotEnable) {
  wmove(stdscr,(statusYPos - 6),(statusXPos));
  if (fairRobot)
   waddnstr(stdscr,("Controlled by a fair robot"),-1);
  else
   waddnstr(stdscr,("Controlled by a robot"),-1);
  wclrtoeol(stdscr);
 }
 if (opponentFlags & 000001) {
  wmove(stdscr,(statusYPos - 5),(statusXPos));
  if (opponentFlags & 000002)
   waddnstr(stdscr,("The opponent is a fair robot"),-1);
  else
   waddnstr(stdscr,("The opponent is a robot"),-1);
  wclrtoeol(stdscr);
 }
}


UpdateOpponentDisplay

decompiled_code:
int UpdateOpponentDisplay()
{
wmove(stdscr, 1, 0);
printw("Playing %s@%s", (const char *)&opponentName, (const char *)&opponentHost);
return wclrtoeol(stdscr);
}

canonical_decompiled_code:
int func11()
{
wmove(stdscr, 1, 0);
printw("Playing %s@%s", (const char *)&opponentName, (const char *)&opponentHost);
return wclrtoeol(stdscr);
}

original_code:
void UpdateOpponentDisplay(void)
{
 wmove(stdscr,(1),(0));
 printw("Playing %s@%s", opponentName, opponentHost);
 wclrtoeol(stdscr);
}

canonical_original_code:
void UpdateOpponentDisplay()
{
 wmove(stdscr,(1),(0));
 printw("Playing %s@%s", opponentName, opponentHost);
 wclrtoeol(stdscr);
}


ShowPause

decompiled_code:
int __fastcall ShowPause(int a1, int a2)
{
int result; // eax

wmove(stdscr, statusYPos - 3, statusXPos);
if ( a2 )
waddnstr(stdscr, "Game paused by opponent", -1);
else
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 2, statusXPos);
if ( a1 )
result = waddnstr(stdscr, "Game paused by you", -1);
else
result = wclrtoeol(stdscr);
return result;
}

canonical_decompiled_code:
int __fastcall func12(int a1, int a2)
{
int result; // eax

wmove(stdscr, statusYPos - 3, statusXPos);
if ( a2 )
waddnstr(stdscr, "Game paused by opponent", -1);
else
wclrtoeol(stdscr);
wmove(stdscr, statusYPos - 2, statusXPos);
if ( a1 )
result = waddnstr(stdscr, "Game paused by you", -1);
else
result = wclrtoeol(stdscr);
return result;
}

original_code:
void ShowPause(int pausedByMe, int pausedByThem)
{
 wmove(stdscr,(statusYPos - 3),(statusXPos));
 if (pausedByThem)
  waddnstr(stdscr,("Game paused by opponent"),-1);
 else
  wclrtoeol(stdscr);
 wmove(stdscr,(statusYPos - 2),(statusXPos));
 if (pausedByMe)
  waddnstr(stdscr,("Game paused by you"),-1);
 else
  wclrtoeol(stdscr);
}

variable_types: pausedByMe int

variable_types: pausedByThem int


Message

decompiled_code:
int __fastcall Message(char *a1)
{
int v1; // esi

wmove(stdscr, statusYPos + line_1 - 20, statusXPos);
waddnstr(stdscr, a1, -1);
wclrtoeol(stdscr);
v1 = (line_1 + 1) % 10 + statusYPos - 20;
line_1 = (line_1 + 1) % 10;
wmove(stdscr, v1, statusXPos);
return wclrtoeol(stdscr);
}

canonical_decompiled_code:
int __fastcall func13(char *a1)
{
int v1; // esi

wmove(stdscr, statusYPos + line_1 - 20, statusXPos);
waddnstr(stdscr, a1, -1);
wclrtoeol(stdscr);
v1 = (line_1 + 1) % 10 + statusYPos - 20;
line_1 = (line_1 + 1) % 10;
wmove(stdscr, v1, statusXPos);
return wclrtoeol(stdscr);
}

original_code:
void Message(char *s)
{
 static int line = 0;
 wmove(stdscr,(statusYPos - 20 + line),(statusXPos));
 waddnstr(stdscr,(s),-1);
 wclrtoeol(stdscr);
 line = (line + 1) % 10;
 wmove(stdscr,(statusYPos - 20 + line),(statusXPos));
 wclrtoeol(stdscr);
}

variable_types:
s
char *

variable_types: line int


RefreshScreen

decompiled_code:
int RefreshScreen()
{
signed int v0; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = (unsigned int)localtime(&timer);
strftime(timeStr_0, 0x1EuLL, "%I:%M %p", (const struct tm *)v0);
if ( strcmp(timeStr_0, dest) )
{
wmove(stdscr, statusYPos, statusXPos);
waddnstr(stdscr, timeStr_0, -1);
strcpy(dest, timeStr_0);
}
wmove(stdscr, boardYPos[0] + 1, boardXPos[0] + 2 * boardWidth + 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func14()
{
signed int v0; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = (unsigned int)localtime(&timer);
strftime(timeStr_0, 0x1EuLL, "%I:%M %p", (const struct tm *)v0);
if ( strcmp(timeStr_0, dest) )
{
wmove(stdscr, statusYPos, statusXPos);
waddnstr(stdscr, timeStr_0, -1);
strcpy(dest, timeStr_0);
}
wmove(stdscr, boardYPos[0] + 1, boardXPos[0] + 2 * boardWidth + 1);
return wrefresh(stdscr);
}

original_code:
void RefreshScreen(void)
{
 static char timeStr[2][32];
 time_t theTime;
 time(&theTime);
 strftime(timeStr[0], 30, "%I:%M %p", localtime(&theTime));
 if (strcmp(timeStr[0], timeStr[1]))
 {
  wmove(stdscr,(statusYPos),(statusXPos));
  waddnstr(stdscr,(timeStr[0]),-1);
  strcpy(timeStr[1], timeStr[0]);
 }
 wmove(stdscr,(boardYPos[0] + 1),(boardXPos[0] + 2 * boardWidth[0] + 1));
 wrefresh(stdscr);
}

canonical_original_code:
void RefreshScreen()
{
 static char timeStr[2][32];
 long theTime;
 time(&theTime);
 strftime(timeStr[0], 30, "%I:%M %p", localtime(&theTime));
 if (strcmp(timeStr[0], timeStr[1]))
 {
  wmove(stdscr,(statusYPos),(statusXPos));
  waddnstr(stdscr,(timeStr[0]),-1);
  strcpy(timeStr[1], timeStr[0]);
 }
 wmove(stdscr,(boardYPos[0] + 1),(boardXPos[0] + 2 * boardWidth[0] + 1));
 wrefresh(stdscr);
}

variable_types:
timeStr
char [2][32]

variable_types: theTime long


ScheduleFullRedraw

decompiled_code:
int ScheduleFullRedraw()
{
int v0; // edx

v0 = -1;
if ( stdscr )
v0 = stdscr->_maxy + 1;
return wtouchln(stdscr, 0, v0, 1);
}

canonical_decompiled_code:
int func15()
{
int v0; // edx

v0 = -1;
if ( stdscr )
v0 = stdscr->_maxy + 1;
return wtouchln(stdscr, 0, v0, 1);
}

original_code:
void ScheduleFullRedraw(void)
{
 wtouchln((stdscr), 0, ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), 1);
}

canonical_original_code:
void ScheduleFullRedraw()
{
 wtouchln((stdscr), 0, ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), 1);
}


repo: nardinan/serenity

decompiled_code:
unsigned __int64 __fastcall p_object_compare(__int64 a1, __int64 a2)
{
return 0xCCCCCCCCCCCCCCCDLL * ((a1 - a2) >> 5);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
return 0xCCCCCCCCCCCCCCCDLL * ((a1 - a2) >> 5);
}

original_code:
int p_object_compare(struct o_object *object, struct o_object *other) {
  return (int)(object-other);
}

variable_types: struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } *

variable_types:
other
struct o_object *

user_defined_types: struct o_object { struct s_list_node head; char *kind; unsigned long size; long long hash; union pthread_mutex_t mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; }

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

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


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

result = a1;
if ( (*(_BYTE *)(a1 + 88) & 2) != 0 )
return *(_QWORD *)(a1 + 40);
*(_BYTE *)(a1 + 88) |= 2u;
*(_QWORD *)(a1 + 40) = a1;
return result;
}

original_code:
t_hash_value p_object_hash(struct o_object *object) {
  if (!object->s_flags.hashed) {
    object->hash = (t_hash_value)object;
    object->s_flags.hashed = 1;
  }
  return object->hash;
}

canonical_original_code:
long long p_object_hash(struct o_object *object) {
  if (!object->s_flags.hashed) {
    object->hash = (long long)object;
    object->s_flags.hashed = 1;
  }
  return object->hash;
}

return_type: long long

user_defined_types: struct s_list_node { struct s_list_node *next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


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

v4 = snprintf(a2, a3, "<%s size: %zu>", *(const char **)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( (int)v4 > a3 )
v4 = a3;
return &a2[v4];
}

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

v4 = snprintf(a2, a3, "<%s size: %zu>", *(const char **)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( (int)v4 > a3 )
v4 = a3;
return &a2[v4];
}

original_code:
char *p_object_string(struct o_object *object, char *data, size_t size) {
  size_t written = snprintf(data, size, "<%s size: %zu>", object->kind, object->size);
  return data+((written>size)?size:written);
}

canonical_original_code:
char *p_object_string(struct o_object *object, char *data, unsigned long size) {
  unsigned long written = snprintf(data, size, "<%s size: %zu>", object->kind, object->size);
  return data+((written>size)?size:written);
}

variable_types:
size
unsigned long

variable_types:
written
unsigned long

return_type: char *


decompiled_code:
_BOOL8 __fastcall p_object_trylock(__int64 a1)
{
_BOOL8 result; // rax

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_trylock((pthread_mutex_t *)(a1 + 48)) == 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
_BOOL8 result; // rax

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_trylock((pthread_mutex_t *)(a1 + 48)) == 0;
else
result = 0LL;
return result;
}

original_code:
int p_object_trylock(struct o_object *object) {
  int locked = 0;
  if (object->s_flags.mutexed)
    if (pthread_mutex_trylock(&(object->mutex)) == 0)
      locked = 1;
  return locked;
}

variable_types: locked int


decompiled_code:
int __fastcall p_object_lock(__int64 a1)
{
int result; // eax

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
return result;
}

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

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
return result;
}

original_code:
void p_object_lock(struct o_object *object) {
  if (object->s_flags.mutexed)
    pthread_mutex_lock(&(object->mutex));
}


decompiled_code:
int __fastcall p_object_unlock(__int64 a1)
{
int result; // eax

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
return result;
}

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

if ( (*(_BYTE *)(a1 + 88) & 8) != 0 )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
return result;
}

original_code:
void p_object_unlock(struct o_object *object) {
  if (object->s_flags.mutexed)
    pthread_mutex_unlock(&(object->mutex));
}


decompiled_code:
char *__fastcall f_object_new(__int64 a1, size_t a2, char *a3)
{
char *v3; // r12
void *v5; // rax
__int64 v6; // rax

if ( a3 )
{
v3 = a3;
memset(a3, 0, a2);
v3[88] |= 1u;
}
else
{
v5 = calloc(1uLL, a2);
v6 = p_memory_insert(v5, "o_object.c", "f_object_new", 39LL, 0LL);
v3 = (char *)v6;
if ( !v6 )
{
p_log_write(stderr, 0LL, "o_object.c", "f_object_new", 42LL, "out of memory! I'm dying: 'bleaaargh'");
exit(1);
}
*(_BYTE *)(v6 + 88) &= 0xFEu;
}
if ( !pthread_mutex_init((pthread_mutex_t *)(v3 + 48), 0LL) )
v3[88] |= 8u;
*((_QWORD *)v3 + 2) = a1;
*((_QWORD *)v3 + 3) = a2;
p_object_hooking(v3);
return v3;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, size_t a2, char *a3)
{
char *v3; // r12
void *v5; // rax
__int64 v6; // rax

if ( a3 )
{
v3 = a3;
memset(a3, 0, a2);
v3[88] |= 1u;
}
else
{
v5 = calloc(1uLL, a2);
v6 = p_memory_insert(v5, "o_object.c", "f_object_new", 39LL, 0LL);
v3 = (char *)v6;
if ( !v6 )
{
p_log_write(stderr, 0LL, "o_object.c", "f_object_new", 42LL, "out of memory! I'm dying: 'bleaaargh'");
exit(1);
}
*(_BYTE *)(v6 + 88) &= 0xFEu;
}
if ( !pthread_mutex_init((pthread_mutex_t *)(v3 + 48), 0LL) )
v3[88] |= 8u;
*((_QWORD *)v3 + 2) = a1;
*((_QWORD *)v3 + 3) = a2;
p_object_hooking(v3);
return v3;
}

original_code:
struct o_object *f_object_new(const char *kind, size_t size, struct o_object *supplied) {
  struct o_object *result = supplied;
  if (result) {
    memset(result, 0, size);
    result->s_flags.supplied = 1;
  } else if ((result = (struct o_object *) p_memory_insert(calloc((1),(size)),"o_object.c",__FUNCTION__,39,0)))
    result->s_flags.supplied = 0;
  else
    do{ p_log_write(stderr,e_log_level_ever,"o_object.c",__FUNCTION__,42,"out of memory! I'm dying: 'bleaaargh'"); exit(1); }while(0);;
  if (pthread_mutex_init(&(result->mutex), ((void *)0)) == 0)
    result->s_flags.mutexed = 1;
  result->kind = kind;
  result->size = size;
  p_object_hooking(result);
  return result;
}

canonical_original_code:
struct o_object *f_object_new(char *kind, unsigned long size, struct o_object *supplied) {
  struct o_object *result = supplied;
  if (result) {
    memset(result, 0, size);
    result->s_flags.supplied = 1;
  } else if ((result = (struct o_object *) p_memory_insert(calloc((1),(size)),"o_object.c",__FUNCTION__,39,0)))
    result->s_flags.supplied = 0;
  else
    do{ p_log_write(stderr,e_log_level_ever,"o_object.c",__FUNCTION__,42,"out of memory! I'm dying: 'bleaaargh'"); exit(1); }while(0);;
  if (pthread_mutex_init(&(result->mutex), ((void *)0)) == 0)
    result->s_flags.mutexed = 1;
  result->kind = kind;
  result->size = size;
  p_object_hooking(result);
  return result;
}

variable_types:
kind
char *

variable_types:
supplied
struct o_object *

return_type: struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } *


decompiled_code:
char *__fastcall f_object_new_pure(char *a1)
{
return f_object_new((__int64)"object", 0xA0uLL, a1);
}

canonical_decompiled_code:
char *__fastcall func7(char *a1)
{
return func6((__int64)"object", 0xA0uLL, a1);
}

original_code:
struct o_object *f_object_new_pure(struct o_object *supplied) {
  return f_object_new(v_object_kind, sizeof(struct o_object), supplied);
}


decompiled_code:
char *__fastcall p_object_clone(void *src)
{
char *v1; // rax
char *v2; // r12

v1 = f_object_new(*((_QWORD *)src + 2), *((_QWORD *)src + 3), 0LL);
v2 = v1;
if ( v1 )
{
memcpy(v1, src, *((_QWORD *)src + 3));
if ( !pthread_mutex_init((pthread_mutex_t *)(v2 + 48), 0LL) )
v2[88] |= 8u;
*((_QWORD *)v2 + 4) = 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func8(void *src)
{
char *v1; // rax
char *v2; // r12

v1 = func6(*((_QWORD *)src + 2), *((_QWORD *)src + 3), 0LL);
v2 = v1;
if ( v1 )
{
memcpy(v1, src, *((_QWORD *)src + 3));
if ( !pthread_mutex_init((pthread_mutex_t *)(v2 + 48), 0LL) )
v2[88] |= 8u;
*((_QWORD *)v2 + 4) = 0LL;
}
return v2;
}

original_code:
struct o_object *p_object_clone(struct o_object *object) {
  struct o_object *result;
  if ((result = f_object_new(object->kind, object->size, ((void *)0)))) {
    memcpy(result, object, object->size);
    if (pthread_mutex_init(&(result->mutex), ((void *)0)) == 0)
      result->s_flags.mutexed = 1;
    result->references = 0;
  }
  return result;
}

variable_types:
object
struct o_object *


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

result = a1;
if ( a1 )
++*(_QWORD *)(a1 + 32);
return result;
}

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

result = a1;
if ( a1 )
++*(_QWORD *)(a1 + 32);
return result;
}

original_code:
struct o_object *f_object_retain(struct o_object *object) {
  if (object)
    object->references++;
  return object;
}


decompiled_code:
void __fastcall p_object_delete(void *ptr)
{
char v1; // al

v1 = *((_BYTE *)ptr + 88);
if ( (v1 & 8) != 0 )
{
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
v1 = *((_BYTE *)ptr + 88);
}
if ( (v1 & 1) != 0 )
{
memset(ptr, 0, *((_QWORD *)ptr + 3));
}
else
{
p_memory_remove(ptr, "o_object.c", "p_object_delete", 72LL, 0LL);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
char v1; // al

v1 = *((_BYTE *)ptr + 88);
if ( (v1 & 8) != 0 )
{
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
v1 = *((_BYTE *)ptr + 88);
}
if ( (v1 & 1) != 0 )
{
memset(ptr, 0, *((_QWORD *)ptr + 3));
}
else
{
p_memory_remove(ptr, "o_object.c", "p_object_delete", 72LL, 0LL);
free(ptr);
}
}

original_code:
void p_object_delete(struct o_object *object) {
  if (object->s_flags.mutexed)
    pthread_mutex_destroy(&(object->mutex));
  if (!object->s_flags.supplied) {
    do{ p_memory_remove((object),"o_object.c",__FUNCTION__,72,0); free(object); }while(0);
    object = ((void *)0);
  } else
    memset(object, 0, object->size);
}


original_code:
void f_object_release(struct o_object *object) {
  if (object) {
    if ((object->references == 0) && (!object->s_flags.pooled)) {
      if (object->s_delegate.m_delete)
        object->s_delegate.m_delete(object);
      p_object_delete(object);
    } else
      object->references--;
  }
}


decompiled_code:
__int64 __fastcall p_dictionary_hash_hooker(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 112))();
}

original_code:
extern t_hash_value p_dictionary_hash_hooker(void *key) {
  struct o_object *object = (struct o_object *)key;
  t_hash_value val = object->s_delegate.m_hash(object);
  return val;
}

canonical_original_code:
extern long long p_dictionary_hash_hooker(void *key) {
  struct o_object *object = (struct o_object *)key;
  long long val = object->s_delegate.m_hash(object);
  return val;
}

variable_types:
key
void *

variable_types:
val
long long


decompiled_code:
__int64 __fastcall p_dictionary_compare_hooker(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a1 && a2 )
result = (*(__int64 (**)(void))(a1 + 104))();
else
result = (unsigned int)(a1 - a2);
return result;
}

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

if ( a1 && a2 )
result = (*(__int64 (**)(void))(a1 + 104))();
else
result = (unsigned int)(a1 - a2);
return result;
}

original_code:
extern int p_dictionary_compare_hooker(void *left, void *right) {
  struct o_object *object_left = (struct o_object *)left, *object_right = (struct o_object *)right;
  return (((object_left)&&(object_right))?((struct o_object *)object_left)->s_delegate.m_compare((struct o_object*)(object_left),(struct o_object*)(object_right)):((long long)(object_left))-((long long)(object_right)));
}

canonical_original_code:
extern int p_dictionary_compare_hooker(void *left, void *right) {
  struct o_object *object_left = (struct o_object *)left; struct o_object *object_right = (struct o_object *)right;
  return (((object_left)&&(object_right))?((struct o_object *)object_left)->s_delegate.m_compare((struct o_object *)(object_left),(struct o_object *)(object_right)):((long long)(object_left))-((long long)(object_right)));
}

variable_types:
left
void *

variable_types:
right
void *


decompiled_code:
__int64 __fastcall p_dictionary_get(__int64 a1, __int64 a2)
{
return f_hash_get(*(_QWORD *)(a1 + 160), a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return f_hash_get(*(_QWORD *)(a1 + 160), a2);
}

original_code:
struct o_object *p_dictionary_get(struct o_dictionary *object, struct o_object *key) {
  return (struct o_object *)f_hash_get(object->table, (void *)key);
}

variable_types: struct o_dictionary { struct o_object head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream { struct o_object head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *

variable_types:
key
struct o_object *

user_defined_types: struct o_dictionary { struct o_object head; struct s_hash_table *table; int (*m_load)(struct o_dictionary *, struct o_stream *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); }

user_defined_types: struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket *table; }

user_defined_types: struct s_hash_bucket { long long hash; void *key; enum e_hash_kind kind; }

user_defined_types: struct o_stream { struct o_object head; struct o_string *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek); void (*m_blocking)(struct o_stream *, int); }

user_defined_types: struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); }


decompiled_code:
struct __jmp_buf_tag __fastcall p_dictionary_clone[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // r14
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r13
unsigned __int64 v6; // r12
__int64 v7; // rsi
__int64 v8; // rax
void (__fastcall *v9)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64); // r15
__int64 v10; // rbp
__int64 v11; // rax
_BYTE v12[332]; // [rsp-150h] [rbp-188h] BYREF

if ( *(char **)(a1 + 16) == "dictionary" )
{
v3 = p_object_clone();
*(_QWORD *)(v3 + 160) = 0LL;
v1 = (struct __jmp_buf_tag *)v3;
f_hash_init(v3 + 160, p_dictionary_compare_hooker, p_dictionary_hash_hooker);
v4 = (*(__int64 (__fastcall **)(__int64))(a1 + 200))(a1);
v5 = v4;
if ( v4 )
{
if ( *(_QWORD *)(v4 + 168) )
{
v6 = 0LL;
do
{
v7 = v6++;
v8 = (*(__int64 (__fastcall **)(__int64, __int64))(v5 + 208))(v5, v7);
v9 = (void (__fastcall *)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64))v1->__saved_mask.__val[14];
v10 = v8;
v11 = f_hash_get(*(_QWORD *)(a1 + 160), v8);
v9(v1, v10, v11);
}
while ( *(_QWORD *)(v5 + 168) > v6 );
}
f_object_release(v5);
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v12, &v_exception_kind, sizeof(v12));
p_exception_fill("object is not an instance of o_dictionary", "o_dictionary.c", "p_dictionary_clone", 146LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

canonical_decompiled_code:
struct __jmp_buf_tag __fastcall func4[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // r14
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r13
unsigned __int64 v6; // r12
__int64 v7; // rsi
__int64 v8; // rax
void (__fastcall *v9)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64); // r15
__int64 v10; // rbp
__int64 v11; // rax
_BYTE v12[332]; // [rsp-150h] [rbp-188h] BYREF

if ( *(char **)(a1 + 16) == "dictionary" )
{
v3 = p_object_clone();
*(_QWORD *)(v3 + 160) = 0LL;
v1 = (struct __jmp_buf_tag *)v3;
f_hash_init(v3 + 160, p_dictionary_compare_hooker, p_dictionary_hash_hooker);
v4 = (*(__int64 (__fastcall **)(__int64))(a1 + 200))(a1);
v5 = v4;
if ( v4 )
{
if ( *(_QWORD *)(v4 + 168) )
{
v6 = 0LL;
do
{
v7 = v6++;
v8 = (*(__int64 (__fastcall **)(__int64, __int64))(v5 + 208))(v5, v7);
v9 = (void (__fastcall *)(struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))), __int64, __int64))v1->__saved_mask.__val[14];
v10 = v8;
v11 = f_hash_get(*(_QWORD *)(a1 + 160), v8);
v9(v1, v10, v11);
}
while ( *(_QWORD *)(v5 + 168) > v6 );
}
f_object_release(v5);
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v12, &v_exception_kind, sizeof(v12));
p_exception_fill("object is not an instance of o_dictionary", "o_dictionary.c", "p_dictionary_clone", 146LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

original_code:
struct o_object *p_dictionary_clone(struct o_object *object) {
  struct o_dictionary *result = ((void *)0), *local_object;
  struct o_array *keys;
  struct o_object *key;
  size_t index;
  if ((local_object = ((struct o_dictionary *)(((object)->kind==v_dictionary_kind)?(object):((void *)0))))) {
    result = (struct o_dictionary *)p_object_clone(object);
    result->table = ((void *)0);
    f_hash_init(&(result->table), p_dictionary_compare_hooker, p_dictionary_hash_hooker);
    if ((keys = local_object->m_keys(local_object))) {
      for (index = 0; index < keys->size; index++) {
        key = keys->m_get(keys, index);
        result->m_insert(result, key, f_hash_get(local_object->table, key));
      }
      f_object_release((struct o_object *)keys);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_dictionary"),"o_dictionary.c",__FUNCTION__,146); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (o_object *)result;
}

canonical_original_code:
struct o_object *p_dictionary_clone(struct o_object *object) {
  struct o_dictionary *result = ((void *)0); struct o_dictionary *local_object;
  struct o_array *keys;
  struct o_object *key;
  unsigned long index;
  if ((local_object = ((struct o_dictionary *)(((object)->kind==v_dictionary_kind)?(object):((void *)0))))) {
    result = (struct o_dictionary *)p_object_clone(object);
    result->table = ((void *)0);
    f_hash_init(&(result->table), p_dictionary_compare_hooker, p_dictionary_hash_hooker);
    if ((keys = local_object->m_keys(local_object))) {
      for (index = 0; index < keys->size; index++) {
        key = keys->m_get(keys, index);
        result->m_insert(result, key, f_hash_get(local_object->table, key));
      }
      f_object_release((struct o_object *)keys);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_dictionary"),"o_dictionary.c",__FUNCTION__,146); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (struct o_object *)result;
}

variable_types: struct o_dictionary { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream { struct o_object head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *

variable_types: struct o_array { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *

variable_types:
index
unsigned long


original_code:
int p_dictionary_save(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *buffer = f_string_new(((void *)0), 512, ((void *)0)), *current_string;
  struct s_hash_bucket *singleton;
  size_t index = 0, elements = (object->table->mask+1);
  int result = 1;
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      if ((current_string = f_string_new(buffer, 512, "%s=%s\n", singleton->key, singleton->value))) {
        if (stream->m_write_string(stream, current_string) == 0)
          result = 0;
        buffer = current_string;
        if (!result)
          break;
      }
  }
  if (buffer)
    do{ p_memory_remove((buffer),"o_dictionary.c",__FUNCTION__,188,0); free(buffer); }while(0);
  return result;
}

canonical_original_code:
int p_dictionary_save(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *buffer = f_string_new(((void *)0), 512, ((void *)0)); struct o_string *current_string;
  struct s_hash_bucket *singleton;
  unsigned long index = 0; unsigned long elements = (object->table->mask+1);
  int result = 1;
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      if ((current_string = f_string_new(buffer, 512, "%s=%s\n", singleton->key, singleton->value))) {
        if (stream->m_write_string(stream, current_string) == 0)
          result = 0;
        buffer = current_string;
        if (!result)
          break;
      }
  }
  if (buffer)
    do{ p_memory_remove((buffer),"o_dictionary.c",__FUNCTION__,188,0); free(buffer); }while(0);
  return result;
}

variable_types:
stream
struct o_stream *

variable_types: struct o_string { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *

variable_types: struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *

variable_types:
elements
unsigned long

variable_types: result int

user_defined_types: enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }


decompiled_code:
__int64 __fastcall p_dictionary_insert(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
__int64 v4; // rax
unsigned int v5; // er12
__int128 v7; // [rsp+0h] [rbp-38h] BYREF
__int128 v8; // [rsp+10h] [rbp-28h]

v7 = 0LL;
v8 = 0LL;
v3 = f_object_retain(a3);
v4 = f_object_retain(a2);
v5 = f_hash_insert(*(_QWORD *)(a1 + 160), v4, v3, s_true, &v7);
if ( (_QWORD)v8 )
{
f_object_release(a2);
f_object_release(v8);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
__int64 v4; // rax
unsigned int v5; // er12
__int128 v7; // [rsp+0h] [rbp-38h] BYREF
__int128 v8; // [rsp+10h] [rbp-28h]

v7 = 0LL;
v8 = 0LL;
v3 = f_object_retain(a3);
v4 = f_object_retain(a2);
v5 = f_hash_insert(*(_QWORD *)(a1 + 160), v4, v3, s_true, &v7);
if ( (_QWORD)v8 )
{
f_object_release(a2);
f_object_release(v8);
}
return v5;
}

original_code:
int p_dictionary_insert(struct o_dictionary *object, struct o_object *key, struct o_object *value) {
  struct s_hash_bucket replaced = {0};
  int result = f_hash_insert(object->table, (void*)f_object_retain((struct o_object *)key), (void*)f_object_retain((struct o_object *)value), s_true, &replaced);
  if (replaced.value) {
    f_object_release((struct o_object *)key);
    f_object_release((struct o_object *)(struct o_object *)replaced.value);
  }
  return result;
}

variable_types:
value
struct o_object *

variable_types: struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; }

user_defined_types: struct o_array { struct o_object head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); }


original_code:
int p_dictionary_load(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *singleton, *buffer = ((void *)0);
  struct o_array *values;
  int result = 1;
  while ((singleton = stream->m_read_line(stream, buffer, 512))) {
    buffer = singleton;
    if (buffer->m_length(buffer) > 0)
      if ((values = singleton->m_split(buffer, '='))) {
        if (values->filled >= 2)
          p_dictionary_insert(object, values->m_get(values, 0), values->m_get(values, 1));
        else
          result = 0;
        f_object_release((struct o_object *)values);
        if (!result)
          break;
      }
  }
  f_object_release((struct o_object *)buffer);
  return result;
}

canonical_original_code:
int p_dictionary_load(struct o_dictionary *object, struct o_stream *stream) {
  struct o_string *singleton; struct o_string *buffer = ((void *)0);
  struct o_array *values;
  int result = 1;
  while ((singleton = stream->m_read_line(stream, buffer, 512))) {
    buffer = singleton;
    if (buffer->m_length(buffer) > 0)
      if ((values = singleton->m_split(buffer, '='))) {
        if (values->filled >= 2)
          p_dictionary_insert(object, values->m_get(values, 0), values->m_get(values, 1));
        else
          result = 0;
        f_object_release((struct o_object *)values);
        if (!result)
          break;
      }
  }
  f_object_release((struct o_object *)buffer);
  return result;
}

user_defined_types: enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 }


original_code:
struct o_array *p_dictionary_keys(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  size_t index = 0, position = 0, elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->key, position++);
  }
  return result;
}

canonical_original_code:
struct o_array *p_dictionary_keys(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  unsigned long index = 0; unsigned long position = 0; unsigned long elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->key, position++);
  }
  return result;
}

variable_types: struct o_dictionary { struct o_object head; struct s_hash_table { long long mask; int (*compare)(void *left, void *right); long long (*calculate)(void *key); struct s_hash_bucket { long long hash; void *key; enum e_hash_kind { e_hash_kind_deleted=0, e_hash_kind_empty=1, e_hash_kind_fill=2 } kind; } *table; } *table; int (*m_load)(struct o_dictionary *, struct o_stream { struct o_object head; struct o_string { struct o_object head; struct { unsigned int constant; } s_flags; char *content; unsigned long size; void (*m_trim)(struct o_string *); void (*m_append)(struct o_string *, struct o_string *); unsigned long (*m_length)(struct o_string *); char (*m_character)(struct o_string *, unsigned long); struct o_string *(*m_substring)(struct o_string *, unsigned long, unsigned long); struct o_array *(*m_split)(struct o_string *, char); void (*m_truncate)(struct o_string *, unsigned long); } *name; int descriptor; struct { unsigned int supplied; unsigned int opened; unsigned int temporary; } s_flags; long (*m_write)(struct o_stream *, unsigned long, void *); long (*m_write_string)(struct o_stream *, struct o_string *); long (*m_write_stream)(struct o_stream *, struct o_stream *); long (*m_read_raw)(struct o_stream *, unsigned char *, unsigned long); struct o_string *(*m_read_line)(struct o_stream *, struct o_string *, unsigned long); struct o_string *(*m_read)(struct o_stream *, struct o_string *, unsigned long); long (*m_size)(struct o_stream *); long (*m_seek)(struct o_stream *, long, enum e_stream_seek { e_stream_seek_begin=0, e_stream_seek_current=1, e_stream_seek_end=2 }); void (*m_blocking)(struct o_stream *, int); } *); int (*m_save)(struct o_dictionary *, struct o_stream *); int (*m_insert)(struct o_dictionary *, struct o_object *, struct o_object *); struct o_object *(*m_get)(struct o_dictionary *, struct o_object *); struct o_array *(*m_keys)(struct o_dictionary *); struct o_array *(*m_values)(struct o_dictionary *); } *

variable_types:
position
unsigned long

return_type: struct o_array { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct o_object **content; unsigned long size; unsigned long (*m_insert)(struct o_array *, struct o_object *, unsigned long); int (*m_remove)(struct o_array *, unsigned long); struct o_object *(*m_get)(struct o_array *, unsigned long); } *


original_code:
struct o_array *p_dictionary_values(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  size_t index = 0, position = 0, elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->value, position++);
  }
  return result;
}

canonical_original_code:
struct o_array *p_dictionary_values(struct o_dictionary *object) {
  struct o_array *result = f_array_new(((void *)0), object->table->fill);
  struct s_hash_bucket *singleton;
  unsigned long index = 0; unsigned long position = 0; unsigned long elements = (object->table->mask+1);
  for (index = 0; index < elements; index++) {
    singleton = &(object->table->table[index]);
    if (singleton->kind == e_hash_kind_fill)
      result->m_insert(result, singleton->value, position++);
  }
  return result;
}


decompiled_code:
const char *__fastcall p_pool_delete(__int64 a1)
{
const char *result; // rax
_BYTE v2[332]; // [rsp-158h] [rbp-158h] BYREF

result = "pool";
if ( *(char **)(a1 + 16) == "pool" )
{
if ( *(_QWORD *)(a1 + 160) )
result = (const char *)f_list_destroy(a1 + 160);
}
else if ( v_exception_hook )
{
qmemcpy(v2, &v_exception_kind, sizeof(v2));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_delete", 46LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1)
{
const char *result; // rax
_BYTE v2[332]; // [rsp-158h] [rbp-158h] BYREF

result = "pool";
if ( *(char **)(a1 + 16) == "pool" )
{
if ( *(_QWORD *)(a1 + 160) )
result = (const char *)f_list_destroy(a1 + 160);
}
else if ( v_exception_hook )
{
qmemcpy(v2, &v_exception_kind, sizeof(v2));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_delete", 46LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
return result;
}

original_code:
void p_pool_delete(struct o_object *object) {
  struct o_pool *local_object;
  if ((local_object = ((struct o_pool *)(((object)->kind==v_pool_kind)?(object):((void *)0))))) {
    if (local_object->pool)
      f_list_destroy(&(local_object->pool));
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_pool"),"o_pool.c",__FUNCTION__,46); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
}

variable_types: struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } *

variable_types: struct o_pool { struct o_object { struct s_list_node { struct s_list_node *next; } head; char *kind; unsigned long size; long long hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct { unsigned int supplied; } s_flags; struct { void (*m_delete)(struct o_object *); int (*m_compare)(struct o_object *, struct o_object *); long long (*m_hash)(struct o_object *); char *(*m_string)(struct o_object *, char *, unsigned long); struct o_object *(*m_clone)(struct o_object *); int (*m_trylock)(struct o_object *); void (*m_lock)(struct o_object *); void (*m_unlock)(struct o_object *); } s_delegate; } head; struct s_list { struct s_list_node *head; unsigned long fill; } *pool; struct o_object *(*m_insert)(struct o_pool *, struct o_object *); void (*m_clean)(struct o_pool *, int); } *

user_defined_types: struct o_pool { struct o_object head; struct s_list *pool; struct o_object *(*m_insert)(struct o_pool *, struct o_object *); void (*m_clean)(struct o_pool *, int); }


decompiled_code:
struct __jmp_buf_tag __fastcall p_pool_clone[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // r12
__int64 v4; // rax
__int64 *v5; // rax
__int64 v6; // rdi
__int64 v7; // rax
__int64 v8; // rax
__int64 *v9; // rdx
__int64 v10; // rdi
_BYTE v11[332]; // [rsp-150h] [rbp-168h] BYREF

if ( *(char **)(a1 + 16) == "pool" )
{
v4 = p_object_clone();
v1 = (struct __jmp_buf_tag *)v4;
if ( *(_QWORD *)(a1 + 160) )
{
f_list_init(v4 + 160);
v5 = *(__int64 **)(a1 + 160);
v6 = *v5;
v5[2] = *v5;
if ( v6 )
{
do
{
v7 = f_object_retain();
f_list_append(v1->__saved_mask.__val[11], v7, 0LL);
v8 = *(_QWORD *)(a1 + 160);
v9 = *(__int64 **)(v8 + 16);
v10 = *v9;
*(_QWORD *)(v8 + 16) = *v9;
}
while ( v10 );
}
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v11, &v_exception_kind, sizeof(v11));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_clone", 92LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

canonical_decompiled_code:
struct __jmp_buf_tag __fastcall func1[1](__int64 a1)
{
struct __jmp_buf_tag *__attribute__((__org_arrdim(0,1))) v1; // r12
__int64 v4; // rax
__int64 *v5; // rax
__int64 v6; // rdi
__int64 v7; // rax
__int64 v8; // rax
__int64 *v9; // rdx
__int64 v10; // rdi
_BYTE v11[332]; // [rsp-150h] [rbp-168h] BYREF

if ( *(char **)(a1 + 16) == "pool" )
{
v4 = p_object_clone();
v1 = (struct __jmp_buf_tag *)v4;
if ( *(_QWORD *)(a1 + 160) )
{
f_list_init(v4 + 160);
v5 = *(__int64 **)(a1 + 160);
v6 = *v5;
v5[2] = *v5;
if ( v6 )
{
do
{
v7 = f_object_retain();
f_list_append(v1->__saved_mask.__val[11], v7, 0LL);
v8 = *(_QWORD *)(a1 + 160);
v9 = *(__int64 **)(v8 + 16);
v10 = *v9;
*(_QWORD *)(v8 + 16) = *v9;
}
while ( v10 );
}
}
}
else
{
v1 = v_exception_hook;
if ( v_exception_hook )
{
qmemcpy(v11, &v_exception_kind, sizeof(v11));
p_exception_fill("object is not an instance of o_pool", "o_pool.c", "p_pool_clone", 92LL);
longjmp(v_exception_hook, v_exception_raised[82]);
}
}
return v1;
}

original_code:
struct o_object *p_pool_clone(struct o_object *object) {
  struct o_pool *result = ((void *)0), *local_object;
  struct o_object *value;
  if ((local_object = ((struct o_pool *)(((object)->kind==v_pool_kind)?(object):((void *)0))))) {
    result = (struct o_pool *)p_object_clone(object);
    if (local_object->pool) {
      f_list_init(&result->pool);
      for((local_object->pool)->current=(local_object->pool)->head;(((value)=(struct o_object *)(local_object->pool)->current));(local_object->pool)->current=(local_object->pool)->current->next)
        f_list_append(result->pool, (struct s_list_node *)(struct o_object*)f_object_retain((struct o_object *)value), e_list_insert_head);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_pool"),"o_pool.c",__FUNCTION__,92); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (struct o_object *)result;
}

canonical_original_code:
struct o_object *p_pool_clone(struct o_object *object) {
  struct o_pool *result = ((void *)0); struct o_pool *local_object;
  struct o_object *value;
  if ((local_object = ((struct o_pool *)(((object)->kind==v_pool_kind)?(object):((void *)0))))) {
    result = (struct o_pool *)p_object_clone(object);
    if (local_object->pool) {
      f_list_init(&result->pool);
      for((local_object->pool)->current=(local_object->pool)->head;(((value)=(struct o_object *)(local_object->pool)->current));(local_object->pool)->current=(local_object->pool)->current->next)
        f_list_append(result->pool, (struct s_list_node *)(struct o_object *)f_object_retain((struct o_object *)value), e_list_insert_head);
    }
  } else
    do{ if(v_exception_hook){ p_exception_fill((v_exception_kind),("object is not an instance of o_pool"),"o_pool.c",__FUNCTION__,92); longjmp(*v_exception_hook,v_exception_raised.identificator); } }while(0);
  return (struct o_object *)result;
}

variable_types:
object
struct o_object *

user_defined_types: struct s_list { struct s_list_node *head; unsigned long fill; }


original_code:
struct o_object *p_pool_insert(struct o_pool *object, struct o_object *value) {
  if (object->pool) {
    f_list_append(object->pool, (struct s_list_node *)value, e_list_insert_head);
    value->s_flags.pooled = 1;
  }
  return value;
}

variable_types: struct o_pool { struct o_object head; struct s_list { struct s_list_node *head; unsigned long fill; } *pool; struct o_object *(*m_insert)(struct o_pool *, struct o_object *); void (*m_clean)(struct o_pool *, int); } *