decompiled_code:
__int64 __fastcall xtdb_firstkey(_QWORD *a1, void *a2, size_t *a3)
{
size_t v4; // rdx
void *v5; // rbp
__int64 result; // rax

v5 = (void *)tdb_firstkey(*a1);
result = 0LL;
if ( v5 )
{
*a3 = v4;
memcpy(a2, v5, v4);
free(v5);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, void *a2, size_t *a3)
{
size_t v4; // rdx
void *v5; // rbp
__int64 result; // rax

v5 = (void *)tdb_firstkey(*a1);
result = 0LL;
if ( v5 )
{
*a3 = v4;
memcpy(a2, v5, v4);
free(v5);
result = 1LL;
}
return result;
}

original_code:
int xtdb_firstkey(struct db_conn *db, unsigned char *key, size_t *ksize)
{
 TDB_DATA k;
 k = tdb_firstkey(db->conn);
 if (k.dptr == ((void *)0))
  return 0;
 *ksize = k.dsize;
 memcpy(key, k.dptr, k.dsize);
 free(k.dptr);
 return 1;
}

canonical_original_code:
int xtdb_firstkey(struct db_conn *db, unsigned char *key, unsigned long *ksize)
{
 struct TDB_DATA k;
 k = tdb_firstkey(db->conn);
 if (k.dptr == ((void *)0))
  return 0;
 *ksize = k.dsize;
 memcpy(key, k.dptr, k.dsize);
 free(k.dptr);
 return 1;
}

variable_types:
ksize
unsigned long *


repo: dolfly/nmdb

decompiled_code:
__int64 __fastcall xtdb_nextkey(_QWORD *a1, __int64 a2, __int64 a3, void *a4, size_t *a5)
{
size_t v7; // rdx
void *v8; // rbp
__int64 result; // rax

v8 = (void *)tdb_nextkey(*a1);
result = 0LL;
if ( v8 )
{
*a5 = v7;
memcpy(a4, v8, v7);
free(v8);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3, void *a4, size_t *a5)
{
size_t v7; // rdx
void *v8; // rbp
__int64 result; // rax

v8 = (void *)tdb_nextkey(*a1);
result = 0LL;
if ( v8 )
{
*a5 = v7;
memcpy(a4, v8, v7);
free(v8);
result = 1LL;
}
return result;
}

original_code:
int xtdb_nextkey(struct db_conn *db,
  const unsigned char *key, size_t ksize,
  unsigned char *nextkey, size_t *nksize)
{
 TDB_DATA pk, nk;
 pk.dptr = (unsigned char *) key;
 pk.dsize = ksize;
 nk = tdb_nextkey(db->conn, pk);
 if (nk.dptr == ((void *)0))
  return 0;
 *nksize = nk.dsize;
 memcpy(nextkey, nk.dptr, nk.dsize);
 free(nk.dptr);
 return 1;
}

canonical_original_code:
int xtdb_nextkey(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize)
{
 struct TDB_DATA pk; struct TDB_DATA nk;
 pk.dptr = (unsigned char *) key;
 pk.dsize = ksize;
 nk = tdb_nextkey(db->conn, pk);
 if (nk.dptr == ((void *)0))
  return 0;
 *nksize = nk.dsize;
 memcpy(nextkey, nk.dptr, nk.dsize);
 free(nk.dptr);
 return 1;
}

variable_types: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); } *

variable_types:
key
unsigned char *

variable_types:
ksize
unsigned long

variable_types:
nextkey
unsigned char *

variable_types:
nksize
unsigned long *

variable_types: struct TDB_DATA { unsigned char *dptr; unsigned long dsize; }

return_type: int


decompiled_code:
// attributes: thunk
ssize_t __fastcall udp_reply_err(__int64 a1, unsigned int a2)
{
return rep_send_error(a1, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func3(__int64 a1, unsigned int a2)
{
return func2(a1, a2);
}

original_code:
static void udp_reply_err(const struct req_info *req, uint32_t reply)
{
 rep_send_error(req, reply);
}

canonical_original_code:
static void udp_reply_err(struct req_info *req, unsigned int reply)
{
 rep_send_error(req, reply);
}

variable_types: struct req_info { int fd; int type; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); } *

variable_types:
reply
unsigned int

return_type: void

user_defined_types: struct req_info { int fd; int type; struct sockaddr *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); }


decompiled_code:
ssize_t __fastcall udp_reply_mini(__int64 a1, unsigned int a2)
{
ssize_t result; // rax
int v3; // eax
__int64 v4; // r8
int v5; // edx
int v6[4]; // [rsp+0h] [rbp-10h] BYREF

result = settings[15];
if ( !(_DWORD)result )
{
v3 = _bswap_32(a2);
v5 = *(_DWORD *)(v4 + 20);
v6[1] = v3;
v6[0] = v5;
result = rep_send_isra_0(v4, v6, 8uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func5(__int64 a1, unsigned int a2)
{
ssize_t result; // rax
int v3; // eax
__int64 v4; // r8
int v5; // edx
int v6[4]; // [rsp+0h] [rbp-10h] BYREF

result = settings[15];
if ( !(_DWORD)result )
{
v3 = func1(a2);
v5 = *(_DWORD *)(v4 + 20);
v6[1] = v3;
v6[0] = v5;
result = func4(v4, v6, 8uLL);
}
return result;
}

original_code:
static void udp_reply_mini(const struct req_info *req, uint32_t reply)
{
 unsigned char minibuf[8];
 if (settings.passive)
  return;
 reply = htonl(reply);
 memcpy(minibuf, &(req->id), 4);
 memcpy(minibuf + 4, &reply, 4);
 rep_send(req, minibuf, 8);
 return;
}

canonical_original_code:
static void udp_reply_mini(struct req_info *req, unsigned int reply)
{
 unsigned char minibuf[8];
 if (settings.passive)
  return;
 reply = htonl(reply);
 memcpy(minibuf, &(req->id), 4);
 memcpy(minibuf + 4, &reply, 4);
 rep_send(req, minibuf, 8);
 return;
}

variable_types:
minibuf
unsigned char [8]

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


decompiled_code:
void __fastcall udp_reply_long(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
size_t v4; // rcx
size_t v5; // r15
size_t v6; // r12
const void *v7; // rdx
const void *v8; // r14
int v9; // ebx
_DWORD *v10; // rbp
int v11; // eax
int v12; // edx

if ( a3 )
{
v3 = _bswap_32(a2);
v5 = v4 + 12;
v6 = v4;
v8 = v7;
v9 = v3;
v10 = malloc(v4 + 12);
v11 = _bswap_32(v6);
v12 = *(_DWORD *)(a1 + 20);
v10[1] = v9;
v10[2] = v11;
*v10 = v12;
memcpy(v10 + 3, v8, v6);
rep_send_isra_0(a1, v10, v5);
free(v10);
}
else
{
udp_reply_mini(a1, a2);
}
}

original_code:
static void udp_reply_long(const struct req_info *req, uint32_t reply,
   unsigned char *val, size_t vsize)
{
 if (val == ((void *)0)) {
  udp_reply_mini(req, reply);
 } else {
  unsigned char *buf;
  size_t bsize;
  uint32_t t;
  reply = htonl(reply);
  bsize = 4 + 4 + 4 + vsize;
  buf = malloc(bsize);
  t = htonl(vsize);
  memcpy(buf, &(req->id), 4);
  memcpy(buf + 4, &reply, 4);
  memcpy(buf + 8, &t, 4);
  memcpy(buf + 12, val, vsize);
  rep_send(req, buf, bsize);
  free(buf);
 }
 return;
}

canonical_original_code:
static void udp_reply_long(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize)
{
 if (val == ((void *)0)) {
  udp_reply_mini(req, reply);
 } else {
  unsigned char *buf;
  unsigned long bsize;
  unsigned int t;
  reply = htonl(reply);
  bsize = 4 + 4 + 4 + vsize;
  buf = malloc(bsize);
  t = htonl(vsize);
  memcpy(buf, &(req->id), 4);
  memcpy(buf + 4, &reply, 4);
  memcpy(buf + 8, &t, 4);
  memcpy(buf + 12, val, vsize);
  rep_send(req, buf, bsize);
  free(buf);
 }
 return;
}

variable_types:
val
unsigned char *

variable_types:
vsize
unsigned long

variable_types:
buf
unsigned char *

variable_types:
bsize
unsigned long

variable_types:
t
unsigned int


decompiled_code:
__int64 udp_init()
{
__int16 v0; // di
int v1; // edx
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+8h] [rbp-20h] BYREF
int buf; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = inet_pton(2, *(const char **)&settings[6], &buf);
if ( optval <= 0 )
goto LABEL_7;
v0 = settings[8];
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = buf;
*(_WORD *)addr.sa_data = _bswap_16(v0);
v2 = socket(2, 2, v1);
v3 = v2;
if ( v2 < 0 )
goto LABEL_7;
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 || (optval = bind(v3, &addr, 0x10u), optval < 0) )
{
close(v3);
LABEL_7:
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 func7()
{
__int16 v0; // di
int v1; // edx
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+8h] [rbp-20h] BYREF
int buf; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = inet_pton(2, *(const char **)&settings[6], &buf);
if ( optval <= 0 )
goto LABEL_7;
v0 = settings[8];
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = buf;
*(_WORD *)addr.sa_data = func0(v0);
v2 = socket(2, 2, v1);
v3 = v2;
if ( v2 < 0 )
goto LABEL_7;
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 || (optval = bind(v3, &addr, 0x10u), optval < 0) )
{
close(v3);
LABEL_7:
v3 = -1;
}
return v3;
}

original_code:
int udp_init(void)
{
 int fd, rv;
 struct sockaddr_in srvsa;
 struct in_addr ia;
 rv = inet_pton(2, settings.udp_addr, &ia);
 if (rv <= 0)
  return -1;
 srvsa.sin_family = 2;
 srvsa.sin_addr.s_addr = ia.s_addr;
 srvsa.sin_port = htons(settings.udp_port);
 fd = socket(2, SOCK_DGRAM, 0);
 if (fd < 0)
  return -1;
 rv = 1;
 if (setsockopt(fd, 1, 2, &rv, sizeof(rv)) < 0 ) {
  close(fd);
  return -1;
 }
 rv = bind(fd, (struct sockaddr *) &srvsa, sizeof(srvsa));
 if (rv < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int udp_init()
{
 int fd; int rv;
 struct sockaddr_in srvsa;
 struct in_addr ia;
 rv = inet_pton(2, settings.udp_addr, &ia);
 if (rv <= 0)
  return -1;
 srvsa.sin_family = 2;
 srvsa.sin_addr.s_addr = ia.s_addr;
 srvsa.sin_port = htons(settings.udp_port);
 fd = socket(2, SOCK_DGRAM, 0);
 if (fd < 0)
  return -1;
 rv = 1;
 if (setsockopt(fd, 1, 2, &rv, sizeof(rv)) < 0 ) {
  close(fd);
  return -1;
 }
 rv = bind(fd, (struct sockaddr *) &srvsa, sizeof(srvsa));
 if (rv < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

variable_types: fd int

variable_types: rv int

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

variable_types:
ia
struct in_addr { unsigned int s_addr; }

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


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

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

original_code:
void udp_close(int fd)
{
 close(fd);
}

canonical_original_code:
void udp_close(int fd)
{
 close(fd);
}


decompiled_code:
ssize_t __fastcall udp_recv(int a1)
{
ssize_t result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-6Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
int v4[2]; // [rsp+20h] [rbp-58h] BYREF
struct sockaddr *v5; // [rsp+28h] [rbp-50h]
socklen_t v6; // [rsp+30h] [rbp-48h]
ssize_t (__fastcall *v7)(__int64, unsigned int); // [rsp+50h] [rbp-28h]
ssize_t (__fastcall *v8)(__int64, unsigned int); // [rsp+58h] [rbp-20h]
void (__fastcall *v9)(__int64, unsigned int, __int64); // [rsp+60h] [rbp-18h]

addr_len = 16;
result = recvfrom(a1, &static_buf, (size_t)&unk_11000, 0, &addr, &addr_len);
if ( (int)result >= 0 )
{
if ( (int)result > 7 )
{
v4[0] = a1;
v6 = addr_len;
v4[1] = 3;
v5 = &addr;
v7 = udp_reply_mini;
v8 = udp_reply_err;
v9 = udp_reply_long;
++stats[16];
result = parse_message(v4, &static_buf, (int)result);
}
else
{
++stats[19];
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func9(int a1)
{
ssize_t result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-6Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
int v4[2]; // [rsp+20h] [rbp-58h] BYREF
struct sockaddr *v5; // [rsp+28h] [rbp-50h]
socklen_t v6; // [rsp+30h] [rbp-48h]
ssize_t (__fastcall *v7)(__int64, unsigned int); // [rsp+50h] [rbp-28h]
ssize_t (__fastcall *v8)(__int64, unsigned int); // [rsp+58h] [rbp-20h]
void (__fastcall *v9)(__int64, unsigned int, __int64); // [rsp+60h] [rbp-18h]

addr_len = 16;
result = recvfrom(a1, &static_buf, (size_t)&unk_11000, 0, &addr, &addr_len);
if ( (int)result >= 0 )
{
if ( (int)result > 7 )
{
v4[0] = a1;
v6 = addr_len;
v4[1] = 3;
v5 = &addr;
v7 = udp_reply_mini;
v8 = udp_reply_err;
v9 = udp_reply_long;
++stats[16];
result = parse_message(v4, &static_buf, (int)result);
}
else
{
++stats[19];
}
}
return result;
}

original_code:
void udp_recv(int fd, short event, void *arg)
{
 int rv;
 struct req_info req;
 struct sockaddr_in clisa;
 socklen_t clilen;
 clilen = sizeof(clisa);
 rv = recvfrom(fd, static_buf, (68 * 1024), 0, (struct sockaddr *) &clisa,
   &clilen);
 if (rv < 0) {
  goto exit;
 }
 if (rv < 8) {
  stats.net_broken_req++;
  goto exit;
 }
 stats.msg_udp++;
 req.fd = fd;
 req.type = 3;
 req.clisa = (struct sockaddr *) &clisa;
 req.clilen = clilen;
 req.reply_mini = udp_reply_mini;
 req.reply_err = udp_reply_err;
 req.reply_long = udp_reply_long;
 parse_message(&req, static_buf, rv);
exit:
 return;
}

canonical_original_code:
void udp_recv(int fd, short event, void *arg)
{
 int rv;
 struct req_info req;
 struct sockaddr_in clisa;
 unsigned int clilen;
 clilen = sizeof(clisa);
 rv = recvfrom(fd, static_buf, (68 * 1024), 0, (struct sockaddr *) &clisa,
   &clilen);
 if (rv < 0) {
  goto exit;
 }
 if (rv < 8) {
  stats.net_broken_req++;
  goto exit;
 }
 stats.msg_udp++;
 req.fd = fd;
 req.type = 3;
 req.clisa = (struct sockaddr *) &clisa;
 req.clilen = clilen;
 req.reply_mini = udp_reply_mini;
 req.reply_err = udp_reply_err;
 req.reply_long = udp_reply_long;
 parse_message(&req, static_buf, rv);
exit:
 return;
}

variable_types: event short

variable_types:
arg
void *

variable_types: struct req_info { int fd; int type; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); }

variable_types:
clilen
unsigned int


decompiled_code:
ssize_t __fastcall rep_send_error(__int64 a1, unsigned int a2)
{
ssize_t result; // rax
int v3; // eax
__int64 v4; // r10
int v5; // ecx
int v6; // edi
int v7; // edx
socklen_t v8; // er9
const struct sockaddr *v9; // r8
int buf[5]; // [rsp+0h] [rbp-14h] BYREF

result = settings[15];
if ( !(_DWORD)result )
{
_bswap_32(0x800u);
v3 = _bswap_32(a2);
v5 = *(_DWORD *)(v4 + 20);
v6 = *(_DWORD *)v4;
buf[1] = v7;
v8 = *(_DWORD *)(v4 + 16);
v9 = *(const struct sockaddr **)(v4 + 8);
buf[2] = v3;
buf[0] = v5;
result = sendto(v6, buf, 0xCuLL, 0, v9, v8);
if ( (int)result < 0 )
result = errlog("rep_send_error() failed");
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(__int64 a1, unsigned int a2)
{
ssize_t result; // rax
int v3; // eax
__int64 v4; // r10
int v5; // ecx
int v6; // edi
int v7; // edx
socklen_t v8; // er9
const struct sockaddr *v9; // r8
int buf[5]; // [rsp+0h] [rbp-14h] BYREF

result = settings[15];
if ( !(_DWORD)result )
{
func1(0x800u);
v3 = func1(a2);
v5 = *(_DWORD *)(v4 + 20);
v6 = *(_DWORD *)v4;
buf[1] = v7;
v8 = *(_DWORD *)(v4 + 16);
v9 = *(const struct sockaddr **)(v4 + 8);
buf[2] = v3;
buf[0] = v5;
result = sendto(v6, buf, 0xCuLL, 0, v9, v8);
if ( (int)result < 0 )
result = errlog("rep_send_error() failed");
}
return result;
}

original_code:
static void rep_send_error(const struct req_info *req, const unsigned int code)
{
 int r, c;
 unsigned char minibuf[3 * 4];
 if (settings.passive)
  return;
 r = htonl(0x800);
 c = htonl(code);
 memcpy(minibuf, &(req->id), 4);
 memcpy(minibuf + 4, &r, 4);
 memcpy(minibuf + 8, &c, 4);
 r = sendto(req->fd, minibuf, 3 * 4, 0, req->clisa, req->clilen);
 if (r < 0) {
  errlog("rep_send_error() failed");
 }
}

canonical_original_code:
static void rep_send_error(struct req_info *req, unsigned int code)
{
 int r; int c;
 unsigned char minibuf[-1];
 if (settings.passive)
  return;
 r = htonl(0x800);
 c = htonl(code);
 memcpy(minibuf, &(req->id), 4);
 memcpy(minibuf + 4, &r, 4);
 memcpy(minibuf + 8, &c, 4);
 r = sendto(req->fd, minibuf, 3 * 4, 0, req->clisa, req->clilen);
 if (r < 0) {
  errlog("rep_send_error() failed");
 }
}

variable_types:
code
unsigned int

variable_types: r int

variable_types: c int

variable_types:
minibuf
unsigned char [-1]


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

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

original_code:
int null_set(struct db_conn *db, const unsigned char *key, size_t ksize,
  unsigned char *val, size_t vsize)
{
 return 1;
}

canonical_original_code:
int null_set(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize)
{
 return 1;
}

variable_types: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); } *

variable_types:
key
unsigned char *

variable_types:
ksize
unsigned long

variable_types:
val
unsigned char *


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

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

original_code:
int null_get(struct db_conn *db, const unsigned char *key, size_t ksize,
  unsigned char *val, size_t *vsize)
{
 return 0;
}

canonical_original_code:
int null_get(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize)
{
 return 0;
}

variable_types:
vsize
unsigned long *

user_defined_types: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); }


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

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

original_code:
int null_del(struct db_conn *db, const unsigned char *key, size_t ksize)
{
 return 0;
}

canonical_original_code:
int null_del(struct db_conn *db, unsigned char *key, unsigned long ksize)
{
 return 0;
}


decompiled_code:
__int64 __fastcall null_close(void *a1)
{
free(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1)
{
free(a1);
return 1LL;
}

original_code:
int null_close(struct db_conn *db)
{
 free(db);
 return 1;
}


decompiled_code:
_QWORD *null_open()
{
_QWORD *result; // rax

result = malloc(0x38uLL);
if ( result )
{
*result = 0LL;
result[1] = null_set;
result[2] = null_get;
result[3] = null_del;
result[4] = 0LL;
result[5] = 0LL;
result[6] = null_close;
}
return result;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *result; // rax

result = malloc(0x38uLL);
if ( result )
{
*result = 0LL;
result[1] = null_set;
result[2] = null_get;
result[3] = null_del;
result[4] = 0LL;
result[5] = 0LL;
result[6] = null_close;
}
return result;
}

original_code:
struct db_conn *null_open(const char *name, int flags)
{
 struct db_conn *db;
 db = malloc(sizeof(struct db_conn));
 if (db == ((void *)0))
  return ((void *)0);
 db->conn = ((void *)0);
 db->set = null_set;
 db->get = null_get;
 db->del = null_del;
 db->firstkey = ((void *)0);
 db->nextkey = ((void *)0);
 db->close = null_close;
 return db;
}

canonical_original_code:
struct db_conn *null_open(char *name, int flags)
{
 struct db_conn *db;
 db = malloc(sizeof(struct db_conn));
 if (db == ((void *)0))
  return ((void *)0);
 db->conn = ((void *)0);
 db->set = null_set;
 db->get = null_get;
 db->del = null_del;
 db->firstkey = ((void *)0);
 db->nextkey = ((void *)0);
 db->close = null_close;
 return db;
}

variable_types:
name
char *

variable_types: flags int

return_type: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); } *


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

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

original_code:
int nmdb_add_tcp_server(nmdb_t *db, const char *addr, int port)
{
 return 0;
}

canonical_original_code:
int nmdb_add_tcp_server(struct nmdb_conn *db, char *addr, int port)
{
 return 0;
}

variable_types: struct nmdb_conn { unsigned int nservers; struct nmdb_srv { int fd; int type; union { struct { unsigned int port; struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr { unsigned int ref; unsigned int node; } id; struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; } nameseq; struct { struct tipc_service_addr { unsigned int type; unsigned int instance; } name; unsigned int domain; } name; } addr; } srvsa; unsigned int srvlen; } tipc; struct { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } srvsa; unsigned int srvlen; } in; } info; } *servers; } *

variable_types:
addr
char *

variable_types: port int

user_defined_types: struct nmdb_conn { unsigned int nservers; struct nmdb_srv *servers; }

user_defined_types: struct nmdb_srv { int fd; int type; union { struct { unsigned int port; struct sockaddr_tipc srvsa; unsigned int srvlen; } tipc; struct { struct sockaddr_in srvsa; unsigned int srvlen; } in; } info; }

user_defined_types: struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr id; struct tipc_service_range nameseq; struct { struct tipc_service_addr name; unsigned int domain; } name; } addr; }


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

original_code:
int tcp_srv_send(struct nmdb_srv *srv, unsigned char *buf, size_t bsize)
{
 return 0;
}

canonical_original_code:
int tcp_srv_send(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize)
{
 return 0;
}

variable_types: struct nmdb_srv { int fd; int type; union { struct { unsigned int port; struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr { unsigned int ref; unsigned int node; } id; struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; } nameseq; struct { struct tipc_service_addr { unsigned int type; unsigned int instance; } name; unsigned int domain; } name; } addr; } srvsa; unsigned int srvlen; } tipc; struct { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } srvsa; unsigned int srvlen; } in; } info; } *

variable_types:
buf
unsigned char *

variable_types:
bsize
unsigned long


decompiled_code:
__int64 tcp_get_rep()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0xFFFFFFFFLL;
}

original_code:
uint32_t tcp_get_rep(struct nmdb_srv *srv,
  unsigned char *buf, size_t bsize,
  unsigned char **payload, size_t *psize)
{
 return -1;
}

canonical_original_code:
unsigned int tcp_get_rep(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize, unsigned char **payload, unsigned long *psize)
{
 return -1;
}

variable_types:
payload
unsigned char **

variable_types:
psize
unsigned long *

return_type: unsigned int

user_defined_types: struct tipc_socket_addr { unsigned int ref; unsigned int node; }

user_defined_types: struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; }

user_defined_types: struct tipc_service_addr { unsigned int type; unsigned int instance; }


decompiled_code:
// attributes: thunk
ssize_t __fastcall tipc_reply_err(__int64 a1, unsigned int a2)
{
return rep_send_error(a1, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func2(__int64 a1, unsigned int a2)
{
return func1(a1, a2);
}

original_code:
static void tipc_reply_err(const struct req_info *req, uint32_t reply)
{
 rep_send_error(req, reply);
}

canonical_original_code:
static void tipc_reply_err(struct req_info *req, unsigned int reply)
{
 rep_send_error(req, reply);
}

variable_types: struct req_info { int fd; int type; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); } *

variable_types:
reply
unsigned int


decompiled_code:
ssize_t __fastcall tipc_reply_mini(__int64 a1, unsigned int a2)
{
ssize_t result; // rax
int v3; // eax
__int64 v4; // r8
int v5; // edx
int v6[4]; // [rsp+0h] [rbp-10h] BYREF

result = settings[15];
if ( !(_DWORD)result )
{
v3 = _bswap_32(a2);
v5 = *(_DWORD *)(v4 + 20);
v6[1] = v3;
v6[0] = v5;
result = rep_send_isra_0(v4, v6, 8uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(__int64 a1, unsigned int a2)
{
ssize_t result; // rax
int v3; // eax
__int64 v4; // r8
int v5; // edx
int v6[4]; // [rsp+0h] [rbp-10h] BYREF

result = settings[15];
if ( !(_DWORD)result )
{
v3 = func0(a2);
v5 = *(_DWORD *)(v4 + 20);
v6[1] = v3;
v6[0] = v5;
result = func3(v4, v6, 8uLL);
}
return result;
}

original_code:
static void tipc_reply_mini(const struct req_info *req, uint32_t reply)
{
 unsigned char minibuf[8];
 if (settings.passive)
  return;
 reply = htonl(reply);
 memcpy(minibuf, &(req->id), 4);
 memcpy(minibuf + 4, &reply, 4);
 rep_send(req, minibuf, 8);
 return;
}

canonical_original_code:
static void tipc_reply_mini(struct req_info *req, unsigned int reply)
{
 unsigned char minibuf[8];
 if (settings.passive)
  return;
 reply = htonl(reply);
 memcpy(minibuf, &(req->id), 4);
 memcpy(minibuf + 4, &reply, 4);
 rep_send(req, minibuf, 8);
 return;
}

variable_types:
minibuf
unsigned char [8]


decompiled_code:
void __fastcall tipc_reply_long(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
size_t v4; // rcx
size_t v5; // r15
size_t v6; // r12
const void *v7; // rdx
const void *v8; // r14
int v9; // ebx
_DWORD *v10; // rbp
int v11; // eax
int v12; // edx

if ( a3 )
{
v3 = _bswap_32(a2);
v5 = v4 + 12;
v6 = v4;
v8 = v7;
v9 = v3;
v10 = malloc(v4 + 12);
v11 = _bswap_32(v6);
v12 = *(_DWORD *)(a1 + 20);
v10[1] = v9;
v10[2] = v11;
*v10 = v12;
memcpy(v10 + 3, v8, v6);
rep_send_isra_0(a1, v10, v5);
free(v10);
}
else
{
tipc_reply_mini(a1, a2);
}
}

original_code:
static void tipc_reply_long(const struct req_info *req, uint32_t reply,
   unsigned char *val, size_t vsize)
{
 if (val == ((void *)0)) {
  tipc_reply_mini(req, reply);
 } else {
  unsigned char *buf;
  size_t bsize;
  uint32_t t;
  reply = htonl(reply);
  bsize = 4 + 4 + 4 + vsize;
  buf = malloc(bsize);
  t = htonl(vsize);
  memcpy(buf, &(req->id), 4);
  memcpy(buf + 4, &reply, 4);
  memcpy(buf + 8, &t, 4);
  memcpy(buf + 12, val, vsize);
  rep_send(req, buf, bsize);
  free(buf);
 }
 return;
}

canonical_original_code:
static void tipc_reply_long(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize)
{
 if (val == ((void *)0)) {
  tipc_reply_mini(req, reply);
 } else {
  unsigned char *buf;
  unsigned long bsize;
  unsigned int t;
  reply = htonl(reply);
  bsize = 4 + 4 + 4 + vsize;
  buf = malloc(bsize);
  t = htonl(vsize);
  memcpy(buf, &(req->id), 4);
  memcpy(buf + 4, &reply, 4);
  memcpy(buf + 8, &t, 4);
  memcpy(buf + 12, val, vsize);
  rep_send(req, buf, bsize);
  free(buf);
 }
 return;
}

variable_types:
vsize
unsigned long

variable_types:
t
unsigned int


decompiled_code:
__int64 tipc_init()
{
unsigned int v0; // eax
int v1; // eax
unsigned int v2; // er12
int v4; // edi
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v5.sa_family = 30;
v0 = settings[1];
*(_DWORD *)&v5.sa_data[2] = 26001;
v5.sa_data[1] = 2;
v5.sa_data[0] = (settings[0] == v0) + 1;
*(_QWORD *)&v5.sa_data[6] = *(_QWORD *)settings;
v1 = socket(30, 4, 0);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
if ( bind(v1, &v5, 0x10u) < 0 )
{
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
int v1; // eax
unsigned int v2; // er12
int v4; // edi
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v5.sa_family = 30;
v0 = settings[1];
*(_DWORD *)&v5.sa_data[2] = 26001;
v5.sa_data[1] = 2;
v5.sa_data[0] = (settings[0] == v0) + 1;
*(_QWORD *)&v5.sa_data[6] = *(_QWORD *)settings;
v1 = socket(30, 4, 0);
if ( v1 < 0 )
return (unsigned int)-1;
v2 = v1;
if ( bind(v1, &v5, 0x10u) < 0 )
{
v4 = v2;
v2 = -1;
close(v4);
}
return v2;
}

original_code:
int tipc_init(void)
{
 int fd, rv;
 struct sockaddr_tipc srvsa;
 srvsa.family = 30;
 if (settings.tipc_lower == settings.tipc_upper)
  srvsa.addrtype = 2;
 else
  srvsa.addrtype = 1;
 srvsa.addr.nameseq.type = 26001;
 srvsa.addr.nameseq.lower = settings.tipc_lower;
 srvsa.addr.nameseq.upper = settings.tipc_upper;
 srvsa.scope = TIPC_CLUSTER_SCOPE;
 fd = socket(30, SOCK_RDM, 0);
 if (fd < 0)
  return -1;
 rv = bind(fd, (struct sockaddr *) &srvsa, sizeof(srvsa));
 if (rv < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int tipc_init()
{
 int fd; int rv;
 struct sockaddr_tipc srvsa;
 srvsa.family = 30;
 if (settings.tipc_lower == settings.tipc_upper)
  srvsa.addrtype = 2;
 else
  srvsa.addrtype = 1;
 srvsa.addr.nameseq.type = 26001;
 srvsa.addr.nameseq.lower = settings.tipc_lower;
 srvsa.addr.nameseq.upper = settings.tipc_upper;
 srvsa.scope = TIPC_CLUSTER_SCOPE;
 fd = socket(30, SOCK_RDM, 0);
 if (fd < 0)
  return -1;
 rv = bind(fd, (struct sockaddr *) &srvsa, sizeof(srvsa));
 if (rv < 0) {
  close(fd);
  return -1;
 }
 return fd;
}

variable_types: fd int

variable_types: rv int

variable_types: struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr { unsigned int ref; unsigned int node; } id; struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; } nameseq; struct { struct tipc_service_addr { unsigned int type; unsigned int instance; } name; unsigned int domain; } name; } addr; }


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

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

original_code:
void tipc_close(int fd)
{
 close(fd);
}

canonical_original_code:
void tipc_close(int fd)
{
 close(fd);
}


decompiled_code:
ssize_t __fastcall tipc_recv(int a1)
{
ssize_t result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-6Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
int v4[2]; // [rsp+20h] [rbp-58h] BYREF
struct sockaddr *v5; // [rsp+28h] [rbp-50h]
socklen_t v6; // [rsp+30h] [rbp-48h]
ssize_t (__fastcall *v7)(__int64, unsigned int); // [rsp+50h] [rbp-28h]
ssize_t (__fastcall *v8)(__int64, unsigned int); // [rsp+58h] [rbp-20h]
void (__fastcall *v9)(__int64, unsigned int, __int64); // [rsp+60h] [rbp-18h]

addr_len = 16;
result = recvfrom(a1, &static_buf, (size_t)&unk_11000, 0, &addr, &addr_len);
if ( (int)result > 0 )
{
if ( (int)result > 7 )
{
v4[0] = a1;
v6 = addr_len;
v4[1] = 1;
v5 = &addr;
v7 = tipc_reply_mini;
v8 = tipc_reply_err;
v9 = tipc_reply_long;
++stats[14];
result = parse_message(v4, &static_buf, (int)result);
}
else
{
++stats[19];
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int a1)
{
ssize_t result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-6Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-68h] BYREF
int v4[2]; // [rsp+20h] [rbp-58h] BYREF
struct sockaddr *v5; // [rsp+28h] [rbp-50h]
socklen_t v6; // [rsp+30h] [rbp-48h]
ssize_t (__fastcall *v7)(__int64, unsigned int); // [rsp+50h] [rbp-28h]
ssize_t (__fastcall *v8)(__int64, unsigned int); // [rsp+58h] [rbp-20h]
void (__fastcall *v9)(__int64, unsigned int, __int64); // [rsp+60h] [rbp-18h]

addr_len = 16;
result = recvfrom(a1, &static_buf, (size_t)&unk_11000, 0, &addr, &addr_len);
if ( (int)result > 0 )
{
if ( (int)result > 7 )
{
v4[0] = a1;
v6 = addr_len;
v4[1] = 1;
v5 = &addr;
v7 = tipc_reply_mini;
v8 = tipc_reply_err;
v9 = tipc_reply_long;
++stats[14];
result = parse_message(v4, &static_buf, (int)result);
}
else
{
++stats[19];
}
}
return result;
}

original_code:
void tipc_recv(int fd, short event, void *arg)
{
 int rv;
 struct req_info req;
 struct sockaddr_tipc clisa;
 socklen_t clilen;
 clilen = sizeof(clisa);
 rv = recvfrom(fd, static_buf, (68 * 1024), 0, (struct sockaddr *) &clisa,
   &clilen);
 if (rv <= 0) {
  goto exit;
 }
 if (rv < 8) {
  stats.net_broken_req++;
  goto exit;
 }
 stats.msg_tipc++;
 req.fd = fd;
 req.type = 1;
 req.clisa = (struct sockaddr *) &clisa;
 req.clilen = clilen;
 req.reply_mini = tipc_reply_mini;
 req.reply_err = tipc_reply_err;
 req.reply_long = tipc_reply_long;
 parse_message(&req, static_buf, rv);
exit:
 return;
}

canonical_original_code:
void tipc_recv(int fd, short event, void *arg)
{
 int rv;
 struct req_info req;
 struct sockaddr_tipc clisa;
 unsigned int clilen;
 clilen = sizeof(clisa);
 rv = recvfrom(fd, static_buf, (68 * 1024), 0, (struct sockaddr *) &clisa,
   &clilen);
 if (rv <= 0) {
  goto exit;
 }
 if (rv < 8) {
  stats.net_broken_req++;
  goto exit;
 }
 stats.msg_tipc++;
 req.fd = fd;
 req.type = 1;
 req.clisa = (struct sockaddr *) &clisa;
 req.clilen = clilen;
 req.reply_mini = tipc_reply_mini;
 req.reply_err = tipc_reply_err;
 req.reply_long = tipc_reply_long;
 parse_message(&req, static_buf, rv);
exit:
 return;
}

variable_types: event short

variable_types:
arg
void *

variable_types: struct req_info { int fd; int type; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); }

variable_types:
clilen
unsigned int


canonical_decompiled_code:
ssize_t __fastcall func1(__int64 a1, unsigned int a2)
{
ssize_t result; // rax
int v3; // eax
__int64 v4; // r10
int v5; // ecx
int v6; // edi
int v7; // edx
socklen_t v8; // er9
const struct sockaddr *v9; // r8
int buf[5]; // [rsp+0h] [rbp-14h] BYREF

result = settings[15];
if ( !(_DWORD)result )
{
func0(0x800u);
v3 = func0(a2);
v5 = *(_DWORD *)(v4 + 20);
v6 = *(_DWORD *)v4;
buf[1] = v7;
v8 = *(_DWORD *)(v4 + 16);
v9 = *(const struct sockaddr **)(v4 + 8);
buf[2] = v3;
buf[0] = v5;
result = sendto(v6, buf, 0xCuLL, 0, v9, v8);
if ( (int)result < 0 )
result = errlog("rep_send_error() failed");
}
return result;
}

variable_types:
code
unsigned int

variable_types: r int

variable_types: c int

variable_types:
minibuf
unsigned char [-1]


htonll

decompiled_code:
__int64 __fastcall htonll(__int64 a1)
{
__int64 v1; // rdx
unsigned int v2; // edx
__int64 v3; // rax
unsigned int v4; // ecx
__int64 result; // rax

HIDWORD(v1) = HIDWORD(a1);
if ( endianness_0 )
{
if ( endianness_0 != 1 )
goto LABEL_4;
result = a1;
}
else
{
if ( (unsigned int)_bswap_32(1u) != 1 )
{
endianness_0 = -1;
LABEL_4:
_bswap_32(HIDWORD(v1));
v3 = _bswap_32(v2);
return (v3 << 32) | v4;
}
endianness_0 = 1;
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rdx
unsigned int v2; // edx
__int64 v3; // rax
unsigned int v4; // ecx
__int64 result; // rax

HIDWORD(v1) = HIDWORD(a1);
if ( endianness_0 )
{
if ( endianness_0 != 1 )
goto LABEL_4;
result = a1;
}
else
{
if ( (unsigned int)func0(1u) != 1 )
{
endianness_0 = -1;
LABEL_4:
func0(HIDWORD(v1));
v3 = func0(v2);
return (v3 << 32) | v4;
}
endianness_0 = 1;
result = v1;
}
return result;
}

original_code:
uint64_t htonll(uint64_t x)
{
 static int endianness = 0;
 if (endianness == 0) {
  if (htonl(1) == 1)
   endianness = 1;
  else
   endianness = -1;
 }
 if (endianness == 1) {
  return x;
 }
 return ( htonl( (x >> 32) & 0xFFFFFFFF ) | ( (uint64_t) htonl(x & 0xFFFFFFFF) ) << 32 );
}

canonical_original_code:
unsigned long htonll(unsigned long x)
{
 static int endianness = 0;
 if (endianness == 0) {
  if (htonl(1) == 1)
   endianness = 1;
  else
   endianness = -1;
 }
 if (endianness == 1) {
  return x;
 }
 return ( htonl( (x >> 32) & 0xFFFFFFFF ) | ( (unsigned long) htonl(x & 0xFFFFFFFF) ) << 32 );
}

variable_types:
x
unsigned long

variable_types: endianness int

return_type: unsigned long


decompiled_code:
__int64 __fastcall tc_close(void *ptr)
{
unsigned __int8 v1; // bl

v1 = tchdbclose(*(_QWORD *)ptr);
tchdbdel(*(_QWORD *)ptr);
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
unsigned __int8 v1; // bl

v1 = tchdbclose(*(_QWORD *)ptr);
tchdbdel(*(_QWORD *)ptr);
free(ptr);
return v1;
}

original_code:
int tc_close(struct db_conn *db)
{
 int r = tchdbclose(db->conn);
 tchdbdel(db->conn);
 free(db);
 return r;
}

variable_types: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); } *


decompiled_code:
__int64 __fastcall tc_set(_QWORD *a1)
{
return (unsigned __int8)tchdbput(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
return (unsigned __int8)tchdbput(*a1);
}

original_code:
int tc_set(struct db_conn *db, const unsigned char *key, size_t ksize,
  unsigned char *val, size_t vsize)
{
 return tchdbput(db->conn, key, ksize, val, vsize);
}

canonical_original_code:
int tc_set(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize)
{
 return tchdbput(db->conn, key, ksize, val, vsize);
}

variable_types:
key
unsigned char *

variable_types:
ksize
unsigned long

variable_types:
val
unsigned char *


decompiled_code:
__int64 __fastcall tc_get(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, _QWORD *a5)
{
int v6; // eax
unsigned int v7; // er8

v6 = tchdbget3(*a1, a2, a3, a4, *(unsigned int *)a5);
v7 = 0;
if ( v6 >= 0 )
{
v7 = 1;
*a5 = v6;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, _QWORD *a5)
{
int v6; // eax
unsigned int v7; // er8

v6 = tchdbget3(*a1, a2, a3, a4, *(unsigned int *)a5);
v7 = 0;
if ( v6 >= 0 )
{
v7 = 1;
*a5 = v6;
}
return v7;
}

original_code:
int tc_get(struct db_conn *db, const unsigned char *key, size_t ksize,
  unsigned char *val, size_t *vsize)
{
 int rv;
 rv = tchdbget3(db->conn, key, ksize, val, *vsize);
 if (rv >= 0) {
  *vsize = rv;
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
int tc_get(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize)
{
 int rv;
 rv = tchdbget3(db->conn, key, ksize, val, *vsize);
 if (rv >= 0) {
  *vsize = rv;
  return 1;
 } else {
  return 0;
 }
}

variable_types:
vsize
unsigned long *


decompiled_code:
__int64 __fastcall tc_del(_QWORD *a1)
{
return (unsigned __int8)tchdbout(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
return (unsigned __int8)tchdbout(*a1);
}

original_code:
int tc_del(struct db_conn *db, const unsigned char *key, size_t ksize)
{
 return tchdbout(db->conn, key, ksize);
}

canonical_original_code:
int tc_del(struct db_conn *db, unsigned char *key, unsigned long ksize)
{
 return tchdbout(db->conn, key, ksize);
}


original_code:
static void process_op(struct db_conn *db, struct queue_entry *e)
{
 int rv;
 if (e->operation == 0x102) {
  rv = db->set(db, e->key, e->ksize, e->val, e->vsize);
  if (!(e->req->flags & 2))
   return;
  if (!rv) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  e->req->reply_mini(e->req, 0x803);
 } else if (e->operation == 0x101) {
  unsigned char *val;
  size_t vsize = 64 * 1024;
  val = malloc(vsize);
  if (val == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->get(db, e->key, e->ksize, val, &vsize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(val);
   return;
  }
  e->req->reply_long(e->req, 0x803, val, vsize);
  free(val);
 } else if (e->operation == 0x103) {
  rv = db->del(db, e->key, e->ksize);
  if (!(e->req->flags & 2))
   return;
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   return;
  }
  e->req->reply_mini(e->req, 0x803);
 } else if (e->operation == 0x104) {
  unsigned char *dbval;
  size_t dbvsize = 64 * 1024;
  dbval = malloc(dbvsize);
  if (dbval == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->get(db, e->key, e->ksize, dbval, &dbvsize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(dbval);
   return;
  }
  if (e->vsize == dbvsize &&
    memcmp(e->val, dbval, dbvsize) == 0) {
   rv = db->set(db, e->key, e->ksize,
     e->newval, e->nvsize);
   if (!rv) {
    e->req->reply_err(e->req, 0x106);
    return;
   }
   e->req->reply_mini(e->req, 0x803);
   free(dbval);
   return;
  }
  e->req->reply_mini(e->req, 0x805);
  free(dbval);
 } else if (e->operation == 0x105) {
  unsigned char *dbval;
  size_t dbvsize = 64 * 1024;
  int64_t intval;
  dbval = malloc(dbvsize);
  if (dbval == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->get(db, e->key, e->ksize, dbval, &dbvsize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(dbval);
   return;
  }
  if (dbval && dbval[dbvsize - 1] != '\0') {
   e->req->reply_mini(e->req, 0x805);
   free(dbval);
   return;
  }
  intval = strtoll((char *) dbval, ((void *)0), 10);
  intval = intval + * (int64_t *) e->val;
  if (dbvsize < 24) {
   dbvsize = 24;
  }
  snprintf((char *) dbval, dbvsize, "%23lld",
    (long long int) intval);
  rv = db->set(db, e->key, e->ksize, dbval, dbvsize);
  if (!rv) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  intval = htonll(intval);
  e->req->reply_long(e->req, 0x803,
    (unsigned char *) &intval, sizeof(intval));
  free(dbval);
 } else if (e->operation == 0x107) {
  unsigned char *key;
  size_t ksize = 64 * 1024;
  if (db->firstkey == ((void *)0)) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  key = malloc(ksize);
  if (key == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->firstkey(db, key, &ksize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(key);
   return;
  }
  e->req->reply_long(e->req, 0x803, key, ksize);
  free(key);
 } else if (e->operation == 0x108) {
  unsigned char *newkey;
  size_t nksize = 64 * 1024;
  if (db->nextkey == ((void *)0)) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  newkey = malloc(nksize);
  if (newkey == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->nextkey(db, e->key, e->ksize, newkey, &nksize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(newkey);
   return;
  }
  e->req->reply_long(e->req, 0x803, newkey, nksize);
  free(newkey);
 } else {
  wlog("Unknown op 0x%x\n", e->operation);
 }
}

canonical_original_code:
static void process_op(struct db_conn *db, struct queue_entry *e)
{
 int rv;
 if (e->operation == 0x102) {
  rv = db->set(db, e->key, e->ksize, e->val, e->vsize);
  if (!(e->req->flags & 2))
   return;
  if (!rv) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  e->req->reply_mini(e->req, 0x803);
 } else if (e->operation == 0x101) {
  unsigned char *val;
  unsigned long vsize = 64 * 1024;
  val = malloc(vsize);
  if (val == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->get(db, e->key, e->ksize, val, &vsize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(val);
   return;
  }
  e->req->reply_long(e->req, 0x803, val, vsize);
  free(val);
 } else if (e->operation == 0x103) {
  rv = db->del(db, e->key, e->ksize);
  if (!(e->req->flags & 2))
   return;
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   return;
  }
  e->req->reply_mini(e->req, 0x803);
 } else if (e->operation == 0x104) {
  unsigned char *dbval;
  unsigned long dbvsize = 64 * 1024;
  dbval = malloc(dbvsize);
  if (dbval == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->get(db, e->key, e->ksize, dbval, &dbvsize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(dbval);
   return;
  }
  if (e->vsize == dbvsize &&
    memcmp(e->val, dbval, dbvsize) == 0) {
   rv = db->set(db, e->key, e->ksize,
     e->newval, e->nvsize);
   if (!rv) {
    e->req->reply_err(e->req, 0x106);
    return;
   }
   e->req->reply_mini(e->req, 0x803);
   free(dbval);
   return;
  }
  e->req->reply_mini(e->req, 0x805);
  free(dbval);
 } else if (e->operation == 0x105) {
  unsigned char *dbval;
  unsigned long dbvsize = 64 * 1024;
  long intval;
  dbval = malloc(dbvsize);
  if (dbval == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->get(db, e->key, e->ksize, dbval, &dbvsize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(dbval);
   return;
  }
  if (dbval && dbval[dbvsize - 1] != '\0') {
   e->req->reply_mini(e->req, 0x805);
   free(dbval);
   return;
  }
  intval = strtoll((char *) dbval, ((void *)0), 10);
  intval = intval + * (long *) e->val;
  if (dbvsize < 24) {
   dbvsize = 24;
  }
  snprintf((char *) dbval, dbvsize, "%23lld",
    (long long) intval);
  rv = db->set(db, e->key, e->ksize, dbval, dbvsize);
  if (!rv) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  intval = htonll(intval);
  e->req->reply_long(e->req, 0x803,
    (unsigned char *) &intval, sizeof(intval));
  free(dbval);
 } else if (e->operation == 0x107) {
  unsigned char *key;
  unsigned long ksize = 64 * 1024;
  if (db->firstkey == ((void *)0)) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  key = malloc(ksize);
  if (key == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->firstkey(db, key, &ksize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(key);
   return;
  }
  e->req->reply_long(e->req, 0x803, key, ksize);
  free(key);
 } else if (e->operation == 0x108) {
  unsigned char *newkey;
  unsigned long nksize = 64 * 1024;
  if (db->nextkey == ((void *)0)) {
   e->req->reply_err(e->req, 0x106);
   return;
  }
  newkey = malloc(nksize);
  if (newkey == ((void *)0)) {
   e->req->reply_err(e->req, 0x105);
   return;
  }
  rv = db->nextkey(db, e->key, e->ksize, newkey, &nksize);
  if (rv == 0) {
   e->req->reply_mini(e->req, 0x804);
   free(newkey);
   return;
  }
  e->req->reply_long(e->req, 0x803, newkey, nksize);
  free(newkey);
 } else {
  wlog("Unknown op 0x%x\n", e->operation);
 }
}

variable_types: struct queue_entry { unsigned int operation; struct req_info { int fd; int type; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); } *req; unsigned char *key; unsigned char *val; unsigned char *newval; unsigned long ksize; unsigned long vsize; unsigned long nvsize; struct queue_entry *prev; } *

variable_types: rv int

variable_types:
vsize
unsigned long

variable_types:
dbval
unsigned char *

variable_types:
dbvsize
unsigned long

variable_types: intval long

variable_types:
newkey
unsigned char *

variable_types:
nksize
unsigned long

user_defined_types: struct queue_entry { unsigned int operation; struct req_info *req; unsigned char *key; unsigned char *val; unsigned char *newval; unsigned long ksize; unsigned long vsize; unsigned long nvsize; struct queue_entry *prev; }


decompiled_code:
void *__fastcall db_loop(void *a1)
{
int v1; // ebx
int v2; // eax
unsigned int *v3; // rbp
struct timespec v5; // [rsp+0h] [rbp-28h] BYREF

do
{
while ( 1 )
{
while ( 1 )
{
v1 = 0;
clock_gettime(0, &v5);
++v5.tv_sec;
queue_lock(op_queue);
while ( 1 )
{
v2 = queue_isempty(op_queue);
if ( v1 )
break;
if ( !v2 )
goto LABEL_6;
v1 = queue_timedwait(op_queue, &v5);
}
if ( v1 == 110 )
break;
errlog("Error in queue_timedwait()");
}
LABEL_6:
v3 = (unsigned int *)queue_get(op_queue);
queue_unlock(op_queue);
if ( !v3 )
break;
process_op((__int64)a1, v3);
queue_entry_free(v3);
}
}
while ( !loop_should_stop );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
int v1; // ebx
int v2; // eax
unsigned int *v3; // rbp
struct timespec v5; // [rsp+0h] [rbp-28h] BYREF

do
{
while ( 1 )
{
while ( 1 )
{
v1 = 0;
clock_gettime(0, &v5);
++v5.tv_sec;
queue_lock(op_queue);
while ( 1 )
{
v2 = queue_isempty(op_queue);
if ( v1 )
break;
if ( !v2 )
goto LABEL_6;
v1 = queue_timedwait(op_queue, &v5);
}
if ( v1 == 110 )
break;
errlog("Error in queue_timedwait()");
}
LABEL_6:
v3 = (unsigned int *)queue_get(op_queue);
queue_unlock(op_queue);
if ( !v3 )
break;
func0((__int64)a1, v3);
queue_entry_free(v3);
}
}
while ( !loop_should_stop );
return 0LL;
}

original_code:
static void *db_loop(void *arg)
{
 int rv;
 struct timespec ts;
 struct queue_entry *e;
 struct db_conn *db;
 db = (struct db_conn *) arg;
 for (;;) {
  clock_gettime(0, &ts);
  ts.tv_sec += 1;
  rv = 0;
  queue_lock(op_queue);
  while (queue_isempty(op_queue) && rv == 0) {
   rv = queue_timedwait(op_queue, &ts);
  }
  if (rv != 0 && rv != 110) {
   errlog("Error in queue_timedwait()");
   (void)0;
   continue;
  }
  e = queue_get(op_queue);
  queue_unlock(op_queue);
  if (e == ((void *)0)) {
   if (loop_should_stop) {
    break;
   } else {
    continue;
   }
  }
  process_op(db, e);
  queue_entry_free(e);
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: void *


decompiled_code:
void __fastcall db_loop_stop(void *ptr)
{
pthread_t v2; // rdi

v2 = *(_QWORD *)ptr;
loop_should_stop = 1;
pthread_join(v2, 0LL);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
pthread_t v2; // rdi

v2 = *(_QWORD *)ptr;
loop_should_stop = 1;
pthread_join(v2, 0LL);
free(ptr);
}

original_code:
void db_loop_stop(pthread_t *thread)
{
 loop_should_stop = 1;
 pthread_join(*thread, ((void *)0));
 free(thread);
 return;
}

canonical_original_code:
void db_loop_stop(unsigned long *thread)
{
 loop_should_stop = 1;
 pthread_join(*thread, ((void *)0));
 free(thread);
 return;
}

variable_types:
thread
unsigned long *


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

original_code:
int nmdb_add_tipc_server(nmdb_t *db, int port)
{
 return 0;
}

canonical_original_code:
int nmdb_add_tipc_server(struct nmdb_conn *db, int port)
{
 return 0;
}

variable_types: struct nmdb_conn { unsigned int nservers; struct nmdb_srv { int fd; int type; union { struct { unsigned int port; struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr { unsigned int ref; unsigned int node; } id; struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; } nameseq; struct { struct tipc_service_addr { unsigned int type; unsigned int instance; } name; unsigned int domain; } name; } addr; } srvsa; unsigned int srvlen; } tipc; struct { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } srvsa; unsigned int srvlen; } in; } info; } *servers; } *

variable_types: port int


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

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

original_code:
int tipc_srv_send(struct nmdb_srv *srv,
  const unsigned char *buf, size_t bsize)
{
 return 0;
}

canonical_original_code:
int tipc_srv_send(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize)
{
 return 0;
}

variable_types: struct nmdb_srv { int fd; int type; union { struct { unsigned int port; struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr { unsigned int ref; unsigned int node; } id; struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; } nameseq; struct { struct tipc_service_addr { unsigned int type; unsigned int instance; } name; unsigned int domain; } name; } addr; } srvsa; unsigned int srvlen; } tipc; struct { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } srvsa; unsigned int srvlen; } in; } info; } *

variable_types:
buf
unsigned char *

variable_types:
bsize
unsigned long


decompiled_code:
__int64 tipc_get_rep()
{
return 0xFFFFFFFFLL;
}

original_code:
uint32_t tipc_get_rep(struct nmdb_srv *srv,
  unsigned char *buf, size_t bsize,
  unsigned char **payload, size_t *psize)
{
 return -1;
}

canonical_original_code:
unsigned int tipc_get_rep(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize, unsigned char **payload, unsigned long *psize)
{
 return -1;
}

variable_types:
payload
unsigned char **

variable_types:
psize
unsigned long *


original_code:
static uint32_t murmurhash2(const unsigned char *key, size_t len)
{
 const uint32_t m = 0x5bd1e995;
 const int r = 24;
 const uint32_t seed = 0x34a4b627;
 uint32_t h = seed ^ len;
 while (len >= 4) {
  uint32_t k = *(uint32_t *) key;
  k *= m;
  k ^= k >> r;
  k *= m;
  h *= m;
  h ^= k;
  key += 4;
  len -= 4;
 }
 switch (len) {
  case 3: h ^= key[2] << 16;
  case 2: h ^= key[1] << 8;
  case 1: h ^= key[0];
   h *= m;
 }
 h ^= h >> 13;
 h *= m;
 h ^= h >> 15;
 return h;
}

canonical_original_code:
static unsigned int murmurhash2(unsigned char *key, unsigned long len)
{
 unsigned int m = 0x5bd1e995;
 int r = 24;
 unsigned int seed = 0x34a4b627;
 unsigned int h = seed ^ len;
 while (len >= 4) {
  unsigned int k = *(uint32_t *) key;
  k *= m;
  k ^= k >> r;
  k *= m;
  h *= m;
  h ^= k;
  key += 4;
  len -= 4;
 }
 switch (len) {
  case 3: h ^= key[2] << 16;
  case 2: h ^= key[1] << 8;
  case 1: h ^= key[0];
   h *= m;
 }
 h ^= h >> 13;
 h *= m;
 h ^= h >> 15;
 return h;
}

variable_types:
key
unsigned char *

variable_types:
len
unsigned long

variable_types:
m
unsigned int

variable_types: r int

variable_types:
seed
unsigned int

variable_types:
h
unsigned int

variable_types:
k
unsigned int


decompiled_code:
__int64 __fastcall alloc_entry(__int64 a1)
{
_QWORD *v1; // rdx
int v2; // eax

v1 = (_QWORD *)(a1 + 24);
v2 = 0;
while ( *v1 != -1LL )
{
++v2;
v1 += 6;
if ( v2 == 4 )
return 0LL;
}
return a1 + 48LL * v2 + 8;
}

original_code:
static struct cache_entry *alloc_entry(struct cache_chain *c)
{
 int i;
 for (i = 0; i < 4; i++) {
  if (c->entries[i].ksize == -1)
   return &(c->entries[i]);
 }
 return ((void *)0);
}

variable_types: struct cache_chain { unsigned long len; struct cache_entry entries[4]; struct cache_entry *first; struct cache_entry *last; } *

variable_types: i int

return_type: struct cache_entry { unsigned char *key; unsigned char *val; unsigned long ksize; unsigned long vsize; struct cache_entry *prev; struct cache_entry *next; } *


original_code:
static int insert_in_full_chain(struct cache_chain *c,
  const unsigned char *key, size_t ksize,
  const unsigned char *val, size_t vsize)
{
 struct cache_entry *e = c->last;
 if (ksize == e->ksize) {
  memcpy(e->key, key, ksize);
 } else {
  free(e->key);
  e->key = malloc(ksize);
  if (e->key == ((void *)0)) {
   goto error;
  }
  e->ksize = ksize;
  memcpy(e->key, key, ksize);
 }
 if (vsize == e->vsize) {
  memcpy(e->val, val, vsize);
 } else {
  free(e->val);
  e->val = malloc(vsize);
  if (e->val == ((void *)0)) {
   goto error;
  }
  e->vsize = vsize;
  memcpy(e->val, val, vsize);
 }
 c->last = e->prev;
 c->last->next = ((void *)0);
 e->prev = ((void *)0);
 e->next = c->first;
 c->first->prev = e;
 c->first = e;
 return 0;
error:
 c->last = e->prev;
 c->last->next = ((void *)0);
 free(e->key);
 free(e->val);
 free_entry(e);
 return -1;
}

canonical_original_code:
static int insert_in_full_chain(struct cache_chain *c, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize)
{
 struct cache_entry *e = c->last;
 if (ksize == e->ksize) {
  memcpy(e->key, key, ksize);
 } else {
  free(e->key);
  e->key = malloc(ksize);
  if (e->key == ((void *)0)) {
   goto error;
  }
  e->ksize = ksize;
  memcpy(e->key, key, ksize);
 }
 if (vsize == e->vsize) {
  memcpy(e->val, val, vsize);
 } else {
  free(e->val);
  e->val = malloc(vsize);
  if (e->val == ((void *)0)) {
   goto error;
  }
  e->vsize = vsize;
  memcpy(e->val, val, vsize);
 }
 c->last = e->prev;
 c->last->next = ((void *)0);
 e->prev = ((void *)0);
 e->next = c->first;
 c->first->prev = e;
 c->first = e;
 return 0;
error:
 c->last = e->prev;
 c->last->next = ((void *)0);
 free(e->key);
 free(e->val);
 free_entry(e);
 return -1;
}

variable_types: struct cache_chain { unsigned long len; struct cache_entry { unsigned char *key; unsigned char *val; unsigned long ksize; unsigned long vsize; struct cache_entry *prev; struct cache_entry *next; } entries[4]; struct cache_entry *first; struct cache_entry *last; } *

variable_types:
ksize
unsigned long

variable_types:
val
unsigned char *

variable_types:
vsize
unsigned long

variable_types: struct cache_entry { unsigned char *key; unsigned char *val; unsigned long ksize; unsigned long vsize; struct cache_entry *prev; struct cache_entry *next; } *

user_defined_types: struct cache_chain { unsigned long len; struct cache_entry entries[4]; struct cache_entry *first; struct cache_entry *last; }


original_code:
int cache_free(struct cache *cd)
{
 size_t i;
 struct cache_chain *c;
 struct cache_entry *e, *n;
 for (i = 0; i < cd->hashlen; i++) {
  c = cd->table + i;
  if (c->first == ((void *)0))
   continue;
  e = c->first;
  while (e != ((void *)0)) {
   n = e->next;
   free(e->key);
   free(e->val);
   e = n;
  }
 }
 free(cd->table);
 free(cd);
 return 1;
}

canonical_original_code:
int cache_free(struct cache *cd)
{
 unsigned long i;
 struct cache_chain *c;
 struct cache_entry *e; struct cache_entry *n;
 for (i = 0; i < cd->hashlen; i++) {
  c = cd->table + i;
  if (c->first == ((void *)0))
   continue;
  e = c->first;
  while (e != ((void *)0)) {
   n = e->next;
   free(e->key);
   free(e->val);
   e = n;
  }
 }
 free(cd->table);
 free(cd);
 return 1;
}

variable_types: struct cache { unsigned long numobjs; unsigned int flags; unsigned long hashlen; struct cache_chain { unsigned long len; struct cache_entry { unsigned char *key; unsigned char *val; unsigned long ksize; unsigned long vsize; struct cache_entry *prev; struct cache_entry *next; } entries[4]; struct cache_entry *first; struct cache_entry *last; } *table; } *

variable_types:
i
unsigned long

user_defined_types: struct cache { unsigned long numobjs; unsigned int flags; unsigned long hashlen; struct cache_chain *table; }


decompiled_code:
__int64 __fastcall cache_get(__int64 a1, unsigned __int8 *a2, unsigned __int64 a3, _QWORD *a4, _QWORD *a5)
{
__int64 result; // rax
__int64 v8; // rdx
__int64 v9; // rax

result = find_in_cache_isra_0(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2, a3);
if ( result )
{
v8 = *(_QWORD *)(result + 8);
v9 = *(_QWORD *)(result + 24);
*a4 = v8;
*a5 = v9;
result = 1LL;
}
else
{
*a4 = 0LL;
*a5 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int8 *a2, unsigned __int64 a3, _QWORD *a4, _QWORD *a5)
{
__int64 result; // rax
__int64 v8; // rdx
__int64 v9; // rax

result = func6(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2, a3);
if ( result )
{
v8 = *(_QWORD *)(result + 8);
v9 = *(_QWORD *)(result + 24);
*a4 = v8;
*a5 = v9;
result = 1LL;
}
else
{
*a4 = 0LL;
*a5 = 0LL;
}
return result;
}

original_code:
int cache_get(struct cache *cd, const unsigned char *key, size_t ksize,
  unsigned char **val, size_t *vsize)
{
 struct cache_entry *e;
 e = find_in_cache(cd, key, ksize);
 if (e == ((void *)0)) {
  *val = ((void *)0);
  *vsize = 0;
  return 0;
 }
 *val = e->val;
 *vsize = e->vsize;
 return 1;
}

canonical_original_code:
int cache_get(struct cache *cd, unsigned char *key, unsigned long ksize, unsigned char **val, unsigned long *vsize)
{
 struct cache_entry *e;
 e = find_in_cache(cd, key, ksize);
 if (e == ((void *)0)) {
  *val = ((void *)0);
  *vsize = 0;
  return 0;
 }
 *val = e->val;
 *vsize = e->vsize;
 return 1;
}

variable_types:
val
unsigned char **

variable_types:
vsize
unsigned long *

user_defined_types: struct cache_entry { unsigned char *key; unsigned char *val; unsigned long ksize; unsigned long vsize; struct cache_entry *prev; struct cache_entry *next; }


original_code:
int cache_set(struct cache *cd, const unsigned char *key, size_t ksize,
  const unsigned char *val, size_t vsize)
{
 uint32_t h = 0;
 struct cache_chain *c;
 struct cache_entry *e, *new;
 unsigned char *v;
 h = murmurhash2(key, ksize) % cd->hashlen;
 c = cd->table + h;
 e = find_in_chain(c, key, ksize);
 if (e == ((void *)0)) {
  if (c->len == 4) {
   if (insert_in_full_chain(c, key, ksize,
     val, vsize) != 0)
    return -1;
  } else {
   new = new_entry(c, key, ksize, val, vsize);
   if (new == ((void *)0))
    return -1;
   if (c->len == 0) {
    c->first = new;
    c->last = new;
    c->len = 1;
   } else if (c->len < 4) {
    new->next = c->first;
    c->first->prev = new;
    c->first = new;
    c->len += 1;
   }
  }
 } else {
  if (vsize == e->vsize) {
   memcpy(e->val, val, vsize);
  } else {
   v = malloc(vsize);
   if (v == ((void *)0))
    return -1;
   free(e->val);
   e->val = v;
   e->vsize = vsize;
   memcpy(e->val, val, vsize);
  }
  if (c->first != e) {
   if (c->last == e)
    c->last = e->prev;
   e->prev->next = e->next;
   if (e->next != ((void *)0))
    e->next->prev = e->prev;
   e->prev = ((void *)0);
   e->next = c->first;
   c->first->prev = e;
   c->first = e;
  }
 }
 return 0;
}

canonical_original_code:
int cache_set(struct cache *cd, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize)
{
 unsigned int h = 0;
 struct cache_chain *c;
 struct cache_entry *e; struct cache_entry *new;
 unsigned char *v;
 h = murmurhash2(key, ksize) % cd->hashlen;
 c = cd->table + h;
 e = find_in_chain(c, key, ksize);
 if (e == ((void *)0)) {
  if (c->len == 4) {
   if (insert_in_full_chain(c, key, ksize,
     val, vsize) != 0)
    return -1;
  } else {
   new = new_entry(c, key, ksize, val, vsize);
   if (new == ((void *)0))
    return -1;
   if (c->len == 0) {
    c->first = new;
    c->last = new;
    c->len = 1;
   } else if (c->len < 4) {
    new->next = c->first;
    c->first->prev = new;
    c->first = new;
    c->len += 1;
   }
  }
 } else {
  if (vsize == e->vsize) {
   memcpy(e->val, val, vsize);
  } else {
   v = malloc(vsize);
   if (v == ((void *)0))
    return -1;
   free(e->val);
   e->val = v;
   e->vsize = vsize;
   memcpy(e->val, val, vsize);
  }
  if (c->first != e) {
   if (c->last == e)
    c->last = e->prev;
   e->prev->next = e->next;
   if (e->next != ((void *)0))
    e->next->prev = e->prev;
   e->prev = ((void *)0);
   e->next = c->first;
   c->first->prev = e;
   c->first = e;
  }
 }
 return 0;
}

variable_types:
key
unsigned char *

variable_types:
v
unsigned char *


original_code:
int cache_del(struct cache *cd, const unsigned char *key, size_t ksize)
{
 int rv = 1;
 uint32_t h = 0;
 struct cache_chain *c;
 struct cache_entry *e;
 h = murmurhash2(key, ksize) % cd->hashlen;
 c = cd->table + h;
 e = find_in_chain(c, key, ksize);
 if (e == ((void *)0)) {
  rv = 0;
  goto exit;
 }
 if (c->first == e) {
  c->first = e->next;
  if (e->next != ((void *)0))
   e->next->prev = ((void *)0);
 } else {
  e->prev->next = e->next;
  if (e->next != ((void *)0))
   e->next->prev = e->prev;
 }
 if (c->last == e) {
  c->last = e->prev;
 }
 free(e->key);
 free(e->val);
 free_entry(e);
 c->len -= 1;
exit:
 return rv;
}

canonical_original_code:
int cache_del(struct cache *cd, unsigned char *key, unsigned long ksize)
{
 int rv = 1;
 unsigned int h = 0;
 struct cache_chain *c;
 struct cache_entry *e;
 h = murmurhash2(key, ksize) % cd->hashlen;
 c = cd->table + h;
 e = find_in_chain(c, key, ksize);
 if (e == ((void *)0)) {
  rv = 0;
  goto exit;
 }
 if (c->first == e) {
  c->first = e->next;
  if (e->next != ((void *)0))
   e->next->prev = ((void *)0);
 } else {
  e->prev->next = e->next;
  if (e->next != ((void *)0))
   e->next->prev = e->prev;
 }
 if (c->last == e) {
  c->last = e->prev;
 }
 free(e->key);
 free(e->val);
 free_entry(e);
 c->len -= 1;
exit:
 return rv;
}

variable_types: rv int


decompiled_code:
__int64 __fastcall cache_cas(__int64 a1, unsigned __int8 *a2, unsigned __int64 a3, const void *a4, size_t a5, const void *a6, size_t size)
{
__int64 v10; // rax
__int64 v11; // rbx
void *v12; // r15
unsigned int v13; // er14
void *v14; // rax
void *v15; // r12

v10 = find_in_cache_isra_0(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2, a3);
if ( !v10 )
return (unsigned int)-2;
v11 = v10;
if ( *(_QWORD *)(v10 + 24) != a5 )
return (unsigned int)-1;
v12 = *(void **)(v10 + 8);
if ( (v13 = memcmp(v12, a4, a5)) != 0 )
return (unsigned int)-1;
if ( a5 == size )
{
memcpy(v12, a6, a5);
}
else
{
v14 = malloc(size);
v15 = v14;
if ( v14 )
{
memcpy(v14, a6, size);
free(*(void **)(v11 + 8));
*(_QWORD *)(v11 + 8) = v15;
*(_QWORD *)(v11 + 24) = size;
}
else
{
v13 = -3;
}
}
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned __int8 *a2, unsigned __int64 a3, const void *a4, size_t a5, const void *a6, size_t size)
{
__int64 v10; // rax
__int64 v11; // rbx
void *v12; // r15
unsigned int v13; // er14
void *v14; // rax
void *v15; // r12

v10 = func6(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2, a3);
if ( !v10 )
return (unsigned int)-2;
v11 = v10;
if ( *(_QWORD *)(v10 + 24) != a5 )
return (unsigned int)-1;
v12 = *(void **)(v10 + 8);
if ( (v13 = memcmp(v12, a4, a5)) != 0 )
return (unsigned int)-1;
if ( a5 == size )
{
memcpy(v12, a6, a5);
}
else
{
v14 = malloc(size);
v15 = v14;
if ( v14 )
{
memcpy(v14, a6, size);
free(*(void **)(v11 + 8));
*(_QWORD *)(v11 + 8) = v15;
*(_QWORD *)(v11 + 24) = size;
}
else
{
v13 = -3;
}
}
return v13;
}

original_code:
int cache_cas(struct cache *cd, const unsigned char *key, size_t ksize,
  const unsigned char *oldval, size_t ovsize,
  const unsigned char *newval, size_t nvsize)
{
 struct cache_entry *e;
 unsigned char *buf;
 e = find_in_cache(cd, key, ksize);
 if (e == ((void *)0))
  return -2;
 if (e->vsize != ovsize)
  return -1;
 if (memcmp(e->val, oldval, ovsize) != 0)
  return -1;
 if (ovsize == nvsize) {
  memcpy(e->val, newval, nvsize);
 } else {
  buf = malloc(nvsize);
  if (buf == ((void *)0))
   return -3;
  memcpy(buf, newval, nvsize);
  free(e->val);
  e->val = buf;
  e->vsize = nvsize;
 }
 return 0;
}

canonical_original_code:
int cache_cas(struct cache *cd, unsigned char *key, unsigned long ksize, unsigned char *oldval, unsigned long ovsize, unsigned char *newval, unsigned long nvsize)
{
 struct cache_entry *e;
 unsigned char *buf;
 e = find_in_cache(cd, key, ksize);
 if (e == ((void *)0))
  return -2;
 if (e->vsize != ovsize)
  return -1;
 if (memcmp(e->val, oldval, ovsize) != 0)
  return -1;
 if (ovsize == nvsize) {
  memcpy(e->val, newval, nvsize);
 } else {
  buf = malloc(nvsize);
  if (buf == ((void *)0))
   return -3;
  memcpy(buf, newval, nvsize);
  free(e->val);
  e->val = buf;
  e->vsize = nvsize;
 }
 return 0;
}

variable_types:
oldval
unsigned char *

variable_types:
ovsize
unsigned long

variable_types:
newval
unsigned char *

variable_types:
nvsize
unsigned long

variable_types:
buf
unsigned char *


original_code:
int cache_incr(struct cache *cd, const unsigned char *key, size_t ksize,
  int64_t increment, int64_t *newval)
{
 unsigned char *val;
 int64_t intval;
 size_t vsize;
 struct cache_entry *e;
 e = find_in_cache(cd, key, ksize);
 if (e == ((void *)0))
  return -1;
 val = e->val;
 vsize = e->vsize;
 if (val == ((void *)0) || val[vsize - 1] != '\0')
  return -2;
 intval = strtoll((char *) val, ((void *)0), 10);
 intval = intval + increment;
 if (vsize < 24) {
  unsigned char *nv = malloc(24);
  if (nv == ((void *)0))
   return -3;
  free(val);
  e->val = val = nv;
  e->vsize = vsize = 24;
 }
 snprintf((char *) val, vsize, "%23lld", (long long int) intval);
 *newval = intval;
 return 0;
}

canonical_original_code:
int cache_incr(struct cache *cd, unsigned char *key, unsigned long ksize, long increment, long *newval)
{
 unsigned char *val;
 long intval;
 unsigned long vsize;
 struct cache_entry *e;
 e = find_in_cache(cd, key, ksize);
 if (e == ((void *)0))
  return -1;
 val = e->val;
 vsize = e->vsize;
 if (val == ((void *)0) || val[vsize - 1] != '\0')
  return -2;
 intval = strtoll((char *) val, ((void *)0), 10);
 intval = intval + increment;
 if (vsize < 24) {
  unsigned char *nv = malloc(24);
  if (nv == ((void *)0))
   return -3;
  free(val);
  e->val = val = nv;
  e->vsize = vsize = 24;
 }
 snprintf((char *) val, vsize, "%23lld", (long long) intval);
 *newval = intval;
 return 0;
}

variable_types: increment long

variable_types:
newval
long *

variable_types: intval long

variable_types:
nv
unsigned char *


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

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

original_code:
int nmdb_add_udp_server(nmdb_t *db, const char *addr, int port)
{
 return 0;
}

canonical_original_code:
int nmdb_add_udp_server(struct nmdb_conn *db, char *addr, int port)
{
 return 0;
}

variable_types: struct nmdb_conn { unsigned int nservers; struct nmdb_srv { int fd; int type; union { struct { unsigned int port; struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr { unsigned int ref; unsigned int node; } id; struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; } nameseq; struct { struct tipc_service_addr { unsigned int type; unsigned int instance; } name; unsigned int domain; } name; } addr; } srvsa; unsigned int srvlen; } tipc; struct { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } srvsa; unsigned int srvlen; } in; } info; } *servers; } *

variable_types:
addr
char *

variable_types: port int


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

original_code:
int udp_srv_send(struct nmdb_srv *srv, unsigned char *buf, size_t bsize)
{
 return 0;
}

canonical_original_code:
int udp_srv_send(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize)
{
 return 0;
}

variable_types: struct nmdb_srv { int fd; int type; union { struct { unsigned int port; struct sockaddr_tipc { unsigned short family; unsigned char addrtype; char scope; union { struct tipc_socket_addr { unsigned int ref; unsigned int node; } id; struct tipc_service_range { unsigned int type; unsigned int lower; unsigned int upper; } nameseq; struct { struct tipc_service_addr { unsigned int type; unsigned int instance; } name; unsigned int domain; } name; } addr; } srvsa; unsigned int srvlen; } tipc; struct { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } srvsa; unsigned int srvlen; } in; } info; } *

variable_types:
bsize
unsigned long


decompiled_code:
__int64 udp_get_rep()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0xFFFFFFFFLL;
}

original_code:
uint32_t udp_get_rep(struct nmdb_srv *srv,
  unsigned char *buf, size_t bsize,
  unsigned char **payload, size_t *psize)
{
 return -1;
}

canonical_original_code:
unsigned int udp_get_rep(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize, unsigned char **payload, unsigned long *psize)
{
 return -1;
}

variable_types:
payload
unsigned char **

variable_types:
psize
unsigned long *


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

original_code:
int nmdb_add_sctp_server(nmdb_t *db, const char *addr, int port)
{
 return 0;
}

canonical_original_code:
int nmdb_add_sctp_server(struct nmdb_conn *db, char *addr, int port)
{
 return 0;
}


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

original_code:
int sctp_srv_send(struct nmdb_srv *srv, unsigned char *buf, size_t bsize)
{
 return 0;
}

canonical_original_code:
int sctp_srv_send(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize)
{
 return 0;
}


decompiled_code:
__int64 sctp_get_rep()
{
return 0xFFFFFFFFLL;
}

original_code:
uint32_t sctp_get_rep(struct nmdb_srv *srv,
  unsigned char *buf, size_t bsize,
  unsigned char **payload, size_t *psize)
{
 return -1;
}

canonical_original_code:
unsigned int sctp_get_rep(struct nmdb_srv *srv, unsigned char *buf, unsigned long bsize, unsigned char **payload, unsigned long *psize)
{
 return -1;
}


decompiled_code:
void free_settings()
{
free((void *)*(&settings + 9));
free((void *)*(&settings + 10));
free((void *)*(&settings + 12));
}

canonical_decompiled_code:
void func0()
{
free((void *)*(&settings + 9));
free((void *)*(&settings + 10));
free((void *)*(&settings + 12));
}

original_code:
static void free_settings()
{
 free(settings.dbname);
 free(settings.logfname);
 free(settings.pidfile);
}


decompiled_code:
__int64 __fastcall load_settings(int argc, char **argv)
{
unsigned int v2; // eax
__int64 result; // rax
int v4; // edx

settings = -1LL;
*(&settings + 1) = 0LL;
*((_DWORD *)&settings + 4) = -1;
*(&settings + 3) = 0LL;
*((_DWORD *)&settings + 8) = -1;
*(&settings + 5) = 0LL;
*(&settings + 6) = -1LL;
*(&settings + 7) = 0LL;
*((_DWORD *)&settings + 16) = 0;
*(&settings + 10) = 0LL;
*(&settings + 12) = 0LL;
*((_DWORD *)&settings + 22) = 4;
*(&settings + 9) = (__int64)strdup("database");
*(&settings + 10) = (__int64)strdup("-");
while ( 2 )
{
v2 = getopt(argc, argv, "b:d:l:L:t:T:u:U:s:S:c:o:i:fprh?");
if ( v2 == -1 )
{
if ( (_DWORD)settings == -1 )
LODWORD(settings) = 10;
if ( HIDWORD(settings) == -1 )
HIDWORD(settings) = settings;
if ( !*(&settings + 1) )
*(&settings + 1) = (__int64)"0.0.0.0";
if ( *((_DWORD *)&settings + 4) == -1 )
*((_DWORD *)&settings + 4) = 26010;
if ( !*(&settings + 3) )
*(&settings + 3) = (__int64)"0.0.0.0";
if ( *((_DWORD *)&settings + 8) == -1 )
*((_DWORD *)&settings + 8) = 26010;
if ( !*(&settings + 5) )
*(&settings + 5) = (__int64)"0.0.0.0";
if ( *((_DWORD *)&settings + 12) == -1 )
*((_DWORD *)&settings + 12) = 26010;
if ( *((_DWORD *)&settings + 13) == -1 )
*((_DWORD *)&settings + 13) = 0x20000;
v4 = *((_DWORD *)&settings + 22);
if ( v4 == -2 )
{
puts("Error: unknown backend");
result = 0LL;
}
else
{
result = 1LL;
if ( v4 == -1 )
{
puts("Error: unsupported backend");
result = 0LL;
}
}
}
else
{
switch ( v2 )
{
case '?':
case 'h':
help();
result = 0LL;
break;
case 'L':
HIDWORD(settings) = atoi(optarg);
continue;
case 'S':
*(&settings + 5) = (__int64)optarg;
continue;
case 'T':
*(&settings + 1) = (__int64)optarg;
continue;
case 'U':
*(&settings + 3) = (__int64)optarg;
continue;
case 'b':
*((_DWORD *)&settings + 22) = be_type_from_str(optarg);
continue;
case 'c':
*((_DWORD *)&settings + 13) = atoi(optarg) << 10;
continue;
case 'd':
free((void *)*(&settings + 9));
*(&settings + 9) = (__int64)strdup(optarg);
continue;
case 'f':
*((_DWORD *)&settings + 14) = 1;
continue;
case 'i':
free((void *)*(&settings + 12));
*(&settings + 12) = (__int64)strdup(optarg);
continue;
case 'l':
LODWORD(settings) = atoi(optarg);
continue;
case 'o':
free((void *)*(&settings + 10));
*(&settings + 10) = (__int64)strdup(optarg);
continue;
case 'p':
*((_DWORD *)&settings + 15) = 1;
continue;
case 'r':
*((_DWORD *)&settings + 16) = 1;
continue;
case 's':
*((_DWORD *)&settings + 12) = atoi(optarg);
continue;
case 't':
*((_DWORD *)&settings + 4) = atoi(optarg);
continue;
case 'u':
*((_DWORD *)&settings + 8) = atoi(optarg);
continue;
default:
printf("Unknown parameter '%c'\n", v2);
result = 0LL;
break;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
unsigned int v2; // eax
__int64 result; // rax
int v4; // edx

settings = -1LL;
*(&settings + 1) = 0LL;
*((_DWORD *)&settings + 4) = -1;
*(&settings + 3) = 0LL;
*((_DWORD *)&settings + 8) = -1;
*(&settings + 5) = 0LL;
*(&settings + 6) = -1LL;
*(&settings + 7) = 0LL;
*((_DWORD *)&settings + 16) = 0;
*(&settings + 10) = 0LL;
*(&settings + 12) = 0LL;
*((_DWORD *)&settings + 22) = 4;
*(&settings + 9) = (__int64)strdup("database");
*(&settings + 10) = (__int64)strdup("-");
while ( 2 )
{
v2 = getopt(argc, argv, "b:d:l:L:t:T:u:U:s:S:c:o:i:fprh?");
if ( v2 == -1 )
{
if ( (_DWORD)settings == -1 )
LODWORD(settings) = 10;
if ( HIDWORD(settings) == -1 )
HIDWORD(settings) = settings;
if ( !*(&settings + 1) )
*(&settings + 1) = (__int64)"0.0.0.0";
if ( *((_DWORD *)&settings + 4) == -1 )
*((_DWORD *)&settings + 4) = 26010;
if ( !*(&settings + 3) )
*(&settings + 3) = (__int64)"0.0.0.0";
if ( *((_DWORD *)&settings + 8) == -1 )
*((_DWORD *)&settings + 8) = 26010;
if ( !*(&settings + 5) )
*(&settings + 5) = (__int64)"0.0.0.0";
if ( *((_DWORD *)&settings + 12) == -1 )
*((_DWORD *)&settings + 12) = 26010;
if ( *((_DWORD *)&settings + 13) == -1 )
*((_DWORD *)&settings + 13) = 0x20000;
v4 = *((_DWORD *)&settings + 22);
if ( v4 == -2 )
{
puts("Error: unknown backend");
result = 0LL;
}
else
{
result = 1LL;
if ( v4 == -1 )
{
puts("Error: unsupported backend");
result = 0LL;
}
}
}
else
{
switch ( v2 )
{
case '?':
case 'h':
func1();
result = 0LL;
break;
case 'L':
HIDWORD(settings) = atoi(optarg);
continue;
case 'S':
*(&settings + 5) = (__int64)optarg;
continue;
case 'T':
*(&settings + 1) = (__int64)optarg;
continue;
case 'U':
*(&settings + 3) = (__int64)optarg;
continue;
case 'b':
*((_DWORD *)&settings + 22) = be_type_from_str(optarg);
continue;
case 'c':
*((_DWORD *)&settings + 13) = atoi(optarg) << 10;
continue;
case 'd':
free((void *)*(&settings + 9));
*(&settings + 9) = (__int64)strdup(optarg);
continue;
case 'f':
*((_DWORD *)&settings + 14) = 1;
continue;
case 'i':
free((void *)*(&settings + 12));
*(&settings + 12) = (__int64)strdup(optarg);
continue;
case 'l':
LODWORD(settings) = atoi(optarg);
continue;
case 'o':
free((void *)*(&settings + 10));
*(&settings + 10) = (__int64)strdup(optarg);
continue;
case 'p':
*((_DWORD *)&settings + 15) = 1;
continue;
case 'r':
*((_DWORD *)&settings + 16) = 1;
continue;
case 's':
*((_DWORD *)&settings + 12) = atoi(optarg);
continue;
case 't':
*((_DWORD *)&settings + 4) = atoi(optarg);
continue;
case 'u':
*((_DWORD *)&settings + 8) = atoi(optarg);
continue;
default:
printf("Unknown parameter '%c'\n", v2);
result = 0LL;
break;
}
}
break;
}
return result;
}

original_code:
static int load_settings(int argc, char **argv)
{
 int c;
 settings.tipc_lower = -1;
 settings.tipc_upper = -1;
 settings.tcp_addr = ((void *)0);
 settings.tcp_port = -1;
 settings.udp_addr = ((void *)0);
 settings.udp_port = -1;
 settings.sctp_addr = ((void *)0);
 settings.sctp_port = -1;
 settings.numobjs = -1;
 settings.foreground = 0;
 settings.passive = 0;
 settings.read_only = 0;
 settings.logfname = ((void *)0);
 settings.pidfile = ((void *)0);
 settings.backend = BE_TDB;
 settings.dbname = strdup("database");
 settings.logfname = strdup("-");
 while ((c = getopt(argc, argv,
    "b:d:l:L:t:T:u:U:s:S:c:o:i:fprh?")) != -1) {
  switch(c) {
  case 'b':
   settings.backend = be_type_from_str(optarg);
   break;
  case 'd':
   free(settings.dbname);
   settings.dbname = strdup(optarg);
   break;
  case 'l':
   settings.tipc_lower = atoi(optarg);
   break;
  case 'L':
   settings.tipc_upper = atoi(optarg);
   break;
  case 't':
   settings.tcp_port = atoi(optarg);
   break;
  case 'T':
   settings.tcp_addr = optarg;
   break;
  case 'u':
   settings.udp_port = atoi(optarg);
   break;
  case 'U':
   settings.udp_addr = optarg;
   break;
  case 's':
   settings.sctp_port = atoi(optarg);
   break;
  case 'S':
   settings.sctp_addr = optarg;
   break;
  case 'c':
   settings.numobjs = atoi(optarg) * 1024;
   break;
  case 'o':
   free(settings.logfname);
   settings.logfname = strdup(optarg);
   break;
  case 'i':
   free(settings.pidfile);
   settings.pidfile = strdup(optarg);
   break;
  case 'f':
   settings.foreground = 1;
   break;
  case 'p':
   settings.passive = 1;
   break;
  case 'r':
   settings.read_only = 1;
   break;
  case 'h':
  case '?':
   help();
   return 0;
  default:
   printf("Unknown parameter '%c'\n", c);
   return 0;
  }
 }
 if (settings.tipc_lower == -1)
  settings.tipc_lower = 10;
 if (settings.tipc_upper == -1)
  settings.tipc_upper = settings.tipc_lower;
 if (settings.tcp_addr == ((void *)0))
  settings.tcp_addr = "0.0.0.0";
 if (settings.tcp_port == -1)
  settings.tcp_port = 26010;
 if (settings.udp_addr == ((void *)0))
  settings.udp_addr = "0.0.0.0";
 if (settings.udp_port == -1)
  settings.udp_port = 26010;
 if (settings.sctp_addr == ((void *)0))
  settings.sctp_addr = "0.0.0.0";
 if (settings.sctp_port == -1)
  settings.sctp_port = 26010;
 if (settings.numobjs == -1)
  settings.numobjs = 128 * 1024;
 if (settings.backend == BE_UNKNOWN) {
  printf("Error: unknown backend\n");
  return 0;
 } else if (settings.backend == BE_UNSUPPORTED) {
  printf("Error: unsupported backend\n");
  return 0;
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // r13
__int64 v9; // rsi
__int64 v10; // rdi
__int64 v11; // rbx
const char *v12; // rax
__pid_t v13; // eax
__int64 v14; // r12
const char *v15; // rdi

v3 = 1;
if ( (unsigned int)load_settings(argc, (char **)argv) )
{
if ( !(unsigned int)log_init() )
{
perror("Error opening log file");
return v3;
}
stats_init(&stats);
v5 = cache_create(*((int *)&settings + 13), 0LL);
v6 = v5;
if ( !v5 )
{
errlog("Error creating cache");
return v3;
}
cache_table = v5;
v7 = queue_create();
v8 = v7;
if ( !v7 )
{
errlog("Error creating queue");
return v3;
}
v9 = *(&settings + 9);
v10 = *((unsigned int *)&settings + 22);
op_queue = v7;
v11 = db_open(v10, v9, 0LL);
if ( !v11 )
{
errlog("Error opening DB");
return v3;
}
v12 = (const char *)be_str_from_type(*((unsigned int *)&settings + 22));
wlog("Opened database \"%s\" with %s backend\n", (const char *)*(&settings + 9), v12);
v3 = *((_DWORD *)&settings + 14);
if ( !v3 )
{
v13 = fork();
if ( v13 > 0 )
return v3;
if ( v13 )
{
v3 = 1;
errlog("Error in fork()");
return v3;
}
close(0);
setsid();
}
wlog("Starting nmdb\n");
write_pid();
v14 = db_loop_start(v11);
net_loop();
db_loop_stop(v14);
(*(void (__fastcall **)(__int64))(v11 + 48))(v11);
queue_free(v8);
cache_free(v6);
v15 = (const char *)*(&settings + 12);
if ( v15 )
unlink(v15);
v3 = 0;
free_settings();
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // r13
__int64 v9; // rsi
__int64 v10; // rdi
__int64 v11; // rbx
const char *v12; // rax
__pid_t v13; // eax
__int64 v14; // r12
const char *v15; // rdi

v3 = 1;
if ( (unsigned int)func2(argc, (char **)argv) )
{
if ( !(unsigned int)log_init() )
{
perror("Error opening log file");
return v3;
}
stats_init(&stats);
v5 = cache_create(*((int *)&settings + 13), 0LL);
v6 = v5;
if ( !v5 )
{
errlog("Error creating cache");
return v3;
}
cache_table = v5;
v7 = queue_create();
v8 = v7;
if ( !v7 )
{
errlog("Error creating queue");
return v3;
}
v9 = *(&settings + 9);
v10 = *((unsigned int *)&settings + 22);
op_queue = v7;
v11 = db_open(v10, v9, 0LL);
if ( !v11 )
{
errlog("Error opening DB");
return v3;
}
v12 = (const char *)be_str_from_type(*((unsigned int *)&settings + 22));
wlog("Opened database \"%s\" with %s backend\n", (const char *)*(&settings + 9), v12);
v3 = *((_DWORD *)&settings + 14);
if ( !v3 )
{
v13 = fork();
if ( v13 > 0 )
return v3;
if ( v13 )
{
v3 = 1;
errlog("Error in fork()");
return v3;
}
close(0);
setsid();
}
wlog("Starting nmdb\n");
write_pid();
v14 = db_loop_start(v11);
net_loop();
db_loop_stop(v14);
(*(void (__fastcall **)(__int64))(v11 + 48))(v11);
queue_free(v8);
cache_free(v6);
v15 = (const char *)*(&settings + 12);
if ( v15 )
unlink(v15);
v3 = 0;
func0();
}
return v3;
}

original_code:
int main(int argc, char **argv)
{
 struct cache *cd;
 struct queue *q;
 struct db_conn *db;
 pid_t pid;
 pthread_t *dbthread;
 if (!load_settings(argc, argv))
  return 1;
 if (!log_init()) {
  perror("Error opening log file");
  return 1;
 }
 stats_init(&stats);
 cd = cache_create(settings.numobjs, 0);
 if (cd == ((void *)0)) {
  errlog("Error creating cache");
  return 1;
 }
 cache_table = cd;
 q = queue_create();
 if (q == ((void *)0)) {
  errlog("Error creating queue");
  return 1;
 }
 op_queue = q;
 db = db_open(settings.backend, settings.dbname, 0);
 if (db == ((void *)0)) {
  errlog("Error opening DB");
  return 1;
 }
 wlog("Opened database \"%s\" with %s backend\n", settings.dbname,
  be_str_from_type(settings.backend));
 if (!settings.foreground) {
  pid = fork();
  if (pid > 0) {
   return 0;
  } else if (pid < 0) {
   errlog("Error in fork()");
   return 1;
  }
  close(0);
  setsid();
 }
 wlog("Starting nmdb\n");
 write_pid();
 dbthread = db_loop_start(db);
 net_loop();
 db_loop_stop(dbthread);
 db->close(db);
 queue_free(q);
 cache_free(cd);
 if (settings.pidfile)
  unlink(settings.pidfile);
 free_settings();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct cache *cd;
 struct queue *q;
 struct db_conn *db;
 int pid;
 unsigned long *dbthread;
 if (!load_settings(argc, argv))
  return 1;
 if (!log_init()) {
  perror("Error opening log file");
  return 1;
 }
 stats_init(&stats);
 cd = cache_create(settings.numobjs, 0);
 if (cd == ((void *)0)) {
  errlog("Error creating cache");
  return 1;
 }
 cache_table = cd;
 q = queue_create();
 if (q == ((void *)0)) {
  errlog("Error creating queue");
  return 1;
 }
 op_queue = q;
 db = db_open(settings.backend, settings.dbname, 0);
 if (db == ((void *)0)) {
  errlog("Error opening DB");
  return 1;
 }
 wlog("Opened database \"%s\" with %s backend\n", settings.dbname,
  be_str_from_type(settings.backend));
 if (!settings.foreground) {
  pid = fork();
  if (pid > 0) {
   return 0;
  } else if (pid < 0) {
   errlog("Error in fork()");
   return 1;
  }
  close(0);
  setsid();
 }
 wlog("Starting nmdb\n");
 write_pid();
 dbthread = db_loop_start(db);
 net_loop();
 db_loop_stop(dbthread);
 db->close(db);
 queue_free(q);
 cache_free(cd);
 if (settings.pidfile)
  unlink(settings.pidfile);
 free_settings();
 return 0;
}

variable_types: struct cache { unsigned long numobjs; unsigned int flags; unsigned long hashlen; struct cache_chain { unsigned long len; struct cache_entry { unsigned char *key; unsigned char *val; unsigned long ksize; unsigned long vsize; struct cache_entry *prev; struct cache_entry *next; } entries[4]; struct cache_entry *first; struct cache_entry *last; } *table; } *

variable_types: struct queue { 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; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; unsigned long size; struct queue_entry { unsigned int operation; struct req_info { int fd; int type; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); } *req; unsigned char *key; unsigned char *val; unsigned char *newval; unsigned long ksize; unsigned long vsize; unsigned long nvsize; struct queue_entry *prev; } *top; } *

variable_types: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); } *

variable_types: pid int

variable_types:
dbthread
unsigned long *

user_defined_types: struct queue { union pthread_mutex_t lock; union pthread_cond_t cond; unsigned long size; struct queue_entry *top; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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; }


help

decompiled_code:
int help()
{
char v1[888]; // [rsp+0h] [rbp-378h] BYREF

strcpy(
v1,
"nmdb [options]\n"
"\n"
" -b backend\tbackend to use (tdb)\n"
" -d dbpath\tdatabase path ('database' by default)\n"
" -l lower\tTIPC lower port number (10)\n"
" -L upper\tTIPC upper port number (= lower)\n"
" -t port\tTCP listening port (26010)\n"
" -T addr\tTCP listening address (all local addresses)\n"
" -u port\tUDP listening port (26010)\n"
" -U addr\tUDP listening address (all local addresses)\n"
" -s port\tSCTP listening port (26010)\n"
" -S addr\tSCTP listening address (all local addresses)\n"
" -c nobj\tmax. number of objects to be cached, in thousands (128)\n"
" -o fname\tlog to the given file (stdout).\n"
" -i pidfile file to write the PID to (none).\n"
" -f\t\tdon't fork and stay in the foreground\n"
" -p\t\tenable passive mode, for redundancy purposes (read docs.)\n"
" -r\t\tread-only mode\n"
" -h\t\tshow this help\n"
"\n"
"Available backends: bdb tc tdb leveldb null \n"
"\n"
"Please report bugs to Alberto Bertogli (albertito@blitiri.com.ar)\n"
"\n");
return printf("%s", v1);
}

canonical_decompiled_code:
int func1()
{
char v1[888]; // [rsp+0h] [rbp-378h] BYREF

strcpy(
v1,
"nmdb [options]\n"
"\n"
" -b backend\tbackend to use (tdb)\n"
" -d dbpath\tdatabase path ('database' by default)\n"
" -l lower\tTIPC lower port number (10)\n"
" -L upper\tTIPC upper port number (= lower)\n"
" -t port\tTCP listening port (26010)\n"
" -T addr\tTCP listening address (all local addresses)\n"
" -u port\tUDP listening port (26010)\n"
" -U addr\tUDP listening address (all local addresses)\n"
" -s port\tSCTP listening port (26010)\n"
" -S addr\tSCTP listening address (all local addresses)\n"
" -c nobj\tmax. number of objects to be cached, in thousands (128)\n"
" -o fname\tlog to the given file (stdout).\n"
" -i pidfile file to write the PID to (none).\n"
" -f\t\tdon't fork and stay in the foreground\n"
" -p\t\tenable passive mode, for redundancy purposes (read docs.)\n"
" -r\t\tread-only mode\n"
" -h\t\tshow this help\n"
"\n"
"Available backends: bdb tc tdb leveldb null \n"
"\n"
"Please report bugs to Alberto Bertogli (albertito@blitiri.com.ar)\n"
"\n");
return printf("%s", v1);
}

original_code:
static void help(void) {
 char h[] = "nmdb [options]\n"
   "\n"
   "  -b backend	backend to use (" "tdb" ")\n"
   "  -d dbpath	database path ('database' by default)\n"
   "  -l lower	TIPC lower port number (10)\n"
   "  -L upper	TIPC upper port number (= lower)\n"
   "  -t port	TCP listening port (26010)\n"
   "  -T addr	TCP listening address (all local addresses)\n"
   "  -u port	UDP listening port (26010)\n"
   "  -U addr	UDP listening address (all local addresses)\n"
   "  -s port	SCTP listening port (26010)\n"
   "  -S addr	SCTP listening address (all local addresses)\n"
   "  -c nobj	max. number of objects to be cached, in thousands (128)\n"
   "  -o fname	log to the given file (stdout).\n"
   "  -i pidfile file to write the PID to (none).\n"
   "  -f		don't fork and stay in the foreground\n"
   "  -p		enable passive mode, for redundancy purposes (read docs.)\n"
   "  -r		read-only mode\n"
   "  -h		show this help\n"
   "\n"
   "Available backends: " "" "bdb " "tc " "tdb " "leveldb " "null " "\n"
   "\n"
   "Please report bugs to Alberto Bertogli (albertito@blitiri.com.ar)\n"
   "\n";
 printf("%s", h);
}

canonical_original_code:
static void help() {
 char h[] = "nmdb [options]\n"
   "\n"
   "  -b backend	backend to use (" "tdb" ")\n"
   "  -d dbpath	database path ('database' by default)\n"
   "  -l lower	TIPC lower port number (10)\n"
   "  -L upper	TIPC upper port number (= lower)\n"
   "  -t port	TCP listening port (26010)\n"
   "  -T addr	TCP listening address (all local addresses)\n"
   "  -u port	UDP listening port (26010)\n"
   "  -U addr	UDP listening address (all local addresses)\n"
   "  -s port	SCTP listening port (26010)\n"
   "  -S addr	SCTP listening address (all local addresses)\n"
   "  -c nobj	max. number of objects to be cached, in thousands (128)\n"
   "  -o fname	log to the given file (stdout).\n"
   "  -i pidfile file to write the PID to (none).\n"
   "  -f		don't fork and stay in the foreground\n"
   "  -p		enable passive mode, for redundancy purposes (read docs.)\n"
   "  -r		read-only mode\n"
   "  -h		show this help\n"
   "\n"
   "Available backends: " "" "bdb " "tc " "tdb " "leveldb " "null " "\n"
   "\n"
   "Please report bugs to Alberto Bertogli (albertito@blitiri.com.ar)\n"
   "\n";
 printf("%s", h);
}

variable_types:
h
char []


decompiled_code:
_BOOL8 passive_to_active_sighandler()
{
_BOOL8 result; // rax

wlog("Passive toggle!\n");
result = settings[15] == 0;
settings[15] = result;
return result;
}

canonical_decompiled_code:
_BOOL8 func0()
{
_BOOL8 result; // rax

wlog("Passive toggle!\n");
result = settings[15] == 0;
settings[15] = result;
return result;
}

original_code:
static void passive_to_active_sighandler(int fd, short event, void *arg)
{
 wlog("Passive toggle!\n");
 settings.passive = !settings.passive;
}

variable_types: fd int

variable_types: event short

variable_types:
arg
void *


decompiled_code:
__int64 enable_read_only_sighandler()
{
__int64 result; // rax

if ( settings[16] )
return wlog("Got signal, but already in read-only mode\n");
result = wlog("Changing to read-only mode\n");
settings[16] = 1;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

if ( settings[16] )
return wlog("Got signal, but already in read-only mode\n");
result = wlog("Changing to read-only mode\n");
settings[16] = 1;
return result;
}

original_code:
static void enable_read_only_sighandler(int fd, short event, void *arg)
{
 if (!settings.read_only) {
  wlog("Changing to read-only mode\n");
  settings.read_only = 1;
 } else {
  wlog("Got signal, but already in read-only mode\n");
 }
}


decompiled_code:
__int64 logfd_reopen_sighandler()
{
__int64 result; // rax

result = log_reopen();
if ( (_DWORD)result )
result = wlog("Log reopened\n");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

result = log_reopen();
if ( (_DWORD)result )
result = wlog("Log reopened\n");
return result;
}

original_code:
static void logfd_reopen_sighandler(int fd, short event, void *arg)
{
 if (log_reopen())
  wlog("Log reopened\n");
}


decompiled_code:
__int64 exit_sighandler()
{
wlog("Got signal! Puf!\n");
return event_loopexit(0LL);
}

canonical_decompiled_code:
__int64 func3()
{
wlog("Got signal! Puf!\n");
return event_loopexit(0LL);
}

original_code:
static void exit_sighandler(int fd, short event, void *arg)
{
 wlog("Got signal! Puf!\n");
 event_loopexit(((void *)0));
}