original_code:
void sha1_final(struct sha1_ctx *ctx, u8 *out)
{
 const size_t offset = ctx->count & 0x3f;
 char *p = (char *)ctx->block + offset;
 int padding = ((16 * 4) - 8) - (offset + 1);
 int i;
 *p++ = 0x80;
 if (padding < 0) {
  memset(p, 0, (padding + 8));
  sha1_transform(ctx->digest, ctx->block);
  p = (char *)ctx->block;
  padding = ((16 * 4) - 8);
 }
 memset(p, 0, padding);
 ctx->block[14] = __bswap_32 (ctx->count >> 29);
 ctx->block[15] = __bswap_32 (ctx->count << 3);
 sha1_transform(ctx->digest, ctx->block);
 for (i = 0; i < 5; i++)
  ctx->digest[i] = __bswap_32 (ctx->digest[i]);
 memcpy(out, ctx->digest, (5 * 4));
 memset(ctx, 0, sizeof(*ctx));
}

canonical_original_code:
void sha1_final(struct sha1_ctx *ctx, unsigned int *out)
{
 unsigned long offset = ctx->count & 0x3f;
 char *p = (char *)ctx->block + offset;
 int padding = ((16 * 4) - 8) - (offset + 1);
 int i;
 *p++ = 0x80;
 if (padding < 0) {
  memset(p, 0, (padding + 8));
  sha1_transform(ctx->digest, ctx->block);
  p = (char *)ctx->block;
  padding = ((16 * 4) - 8);
 }
 memset(p, 0, padding);
 ctx->block[14] = __bswap_32 (ctx->count >> 29);
 ctx->block[15] = __bswap_32 (ctx->count << 3);
 sha1_transform(ctx->digest, ctx->block);
 for (i = 0; i < 5; i++)
  ctx->digest[i] = __bswap_32 (ctx->digest[i]);
 memcpy(out, ctx->digest, (5 * 4));
 memset(ctx, 0, sizeof(*ctx));
}

variable_types:
out
unsigned int *

variable_types: padding int

variable_types: i int


repo: quadstor/ietbsd

original_code:
void md5_init(struct md5_ctx *ctx)
{
 ctx->digest[0] = 0x67452301UL;
 ctx->digest[1] = 0xEFCDAB89UL;
 ctx->digest[2] = 0x98BADCFEUL;
 ctx->digest[3] = 0x10325476UL;
 ctx->count = 0;
}

variable_types: struct md5_ctx { unsigned int block[16]; unsigned int digest[4]; unsigned int count; } *

return_type: void


decompiled_code:
void *__fastcall md5_update(void *dest, _QWORD *a2, size_t a3)
{
__int64 v5; // r14
__int64 v6; // rbx
_QWORD *v7; // rax
void *result; // rax
unsigned __int64 v9; // rsi
char *v10; // rax
char *v11; // r8
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // edx
const __m128i *v15; // rbx
size_t v16; // r14
const __m128i *v17; // r13

v5 = *((_QWORD *)dest + 10) & 0x3FLL;
v6 = 64 - v5;
*((_QWORD *)dest + 10) += a3;
if ( 64 - v5 > a3 )
return memcpy((char *)dest + v5, a2, a3);
v7 = (char *)dest + v5;
if ( (unsigned int)v6 >= 8 )
{
*v7 = *a2;
*(_QWORD *)((char *)v7 + (unsigned int)v6 - 8) = *(_QWORD *)((char *)a2 + (unsigned int)v6 - 8);
v9 = (unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL;
v10 = (char *)v7 - v9;
v11 = (char *)((char *)a2 - v10);
v12 = (v6 + (_DWORD)v10) & 0xFFFFFFF8;
if ( v12 >= 8 )
{
v13 = v12 & 0xFFFFFFF8;
v14 = 0;
do
{
*(_QWORD *)(v9 + v14) = *(_QWORD *)&v11[v14];
v14 += 8;
}
while ( v14 < v13 );
}
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)v7 = *(_DWORD *)a2;
*(_DWORD *)((char *)v7 + (unsigned int)v6 - 4) = *(_DWORD *)((char *)a2 + (unsigned int)v6 - 4);
}
else if ( (_DWORD)v6 )
{
*(_BYTE *)v7 = *(_BYTE *)a2;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)v7 + (unsigned int)v6 - 2) = *(_WORD *)((char *)a2 + (unsigned int)v6 - 2);
}
result = (void *)md5_transform((_DWORD *)dest + 16, (int *)dest);
v15 = (const __m128i *)((char *)a2 + v6);
v16 = v5 + a3 - 64;
if ( v16 <= 0x3F )
{
v17 = v15;
}
else
{
v17 = (const __m128i *)((char *)v15 + ((v16 - 64) & 0xFFFFFFFFFFFFFFC0LL) + 64);
do
{
*(__m128i *)dest = _mm_loadu_si128(v15);
*((__m128i *)dest + 1) = _mm_loadu_si128(v15 + 1);
*((__m128i *)dest + 2) = _mm_loadu_si128(v15 + 2);
*((__m128i *)dest + 3) = _mm_loadu_si128(v15 + 3);
result = (void *)md5_transform((_DWORD *)dest + 16, (int *)dest);
v15 += 4;
}
while ( v15 != v17 );
v16 &= 0x3Fu;
}
if ( v16 )
result = memcpy(dest, v17, v16);
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *dest, _QWORD *a2, size_t a3)
{
__int64 v5; // r14
__int64 v6; // rbx
_QWORD *v7; // rax
void *result; // rax
unsigned __int64 v9; // rsi
char *v10; // rax
char *v11; // r8
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // edx
const __m128i *v15; // rbx
size_t v16; // r14
const __m128i *v17; // r13

v5 = *((_QWORD *)dest + 10) & 0x3FLL;
v6 = 64 - v5;
*((_QWORD *)dest + 10) += a3;
if ( 64 - v5 > a3 )
return memcpy((char *)dest + v5, a2, a3);
v7 = (char *)dest + v5;
if ( (unsigned int)v6 >= 8 )
{
*v7 = *a2;
*(_QWORD *)((char *)v7 + (unsigned int)v6 - 8) = *(_QWORD *)((char *)a2 + (unsigned int)v6 - 8);
v9 = (unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL;
v10 = (char *)v7 - v9;
v11 = (char *)((char *)a2 - v10);
v12 = (v6 + (_DWORD)v10) & 0xFFFFFFF8;
if ( v12 >= 8 )
{
v13 = v12 & 0xFFFFFFF8;
v14 = 0;
do
{
*(_QWORD *)(v9 + v14) = *(_QWORD *)&v11[v14];
v14 += 8;
}
while ( v14 < v13 );
}
}
else if ( (v6 & 4) != 0 )
{
*(_DWORD *)v7 = *(_DWORD *)a2;
*(_DWORD *)((char *)v7 + (unsigned int)v6 - 4) = *(_DWORD *)((char *)a2 + (unsigned int)v6 - 4);
}
else if ( (_DWORD)v6 )
{
*(_BYTE *)v7 = *(_BYTE *)a2;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)v7 + (unsigned int)v6 - 2) = *(_WORD *)((char *)a2 + (unsigned int)v6 - 2);
}
result = (void *)func1((_DWORD *)dest + 16, (int *)dest);
v15 = (const __m128i *)((char *)a2 + v6);
v16 = v5 + a3 - 64;
if ( v16 <= 0x3F )
{
v17 = v15;
}
else
{
v17 = (const __m128i *)((char *)v15 + ((v16 - 64) & 0xFFFFFFFFFFFFFFC0LL) + 64);
do
{
*(__m128i *)dest = _mm_loadu_si128(v15);
*((__m128i *)dest + 1) = _mm_loadu_si128(v15 + 1);
*((__m128i *)dest + 2) = _mm_loadu_si128(v15 + 2);
*((__m128i *)dest + 3) = _mm_loadu_si128(v15 + 3);
result = (void *)func1((_DWORD *)dest + 16, (int *)dest);
v15 += 4;
}
while ( v15 != v17 );
v16 &= 0x3Fu;
}
if ( v16 )
result = memcpy(dest, v17, v16);
return result;
}

original_code:
void md5_update(struct md5_ctx *ctx, const void *data_in, size_t len)
{
 const size_t offset = ctx->count & 0x3f;
 const size_t avail = (16 * 4) - offset;
 const u8 *data = data_in;
 ctx->count += len;
 if (avail > len) {
  memcpy((u8 *)ctx->block + offset, data, len);
  return;
 }
 memcpy((u8 *)ctx->block + offset, data, avail);
 md5_transform(ctx->digest, ctx->block);
 data += avail;
 len -= avail;
 while (len >= (16 * 4)) {
  memcpy(ctx->block, data, (16 * 4));
  md5_transform(ctx->digest, ctx->block);
  data += (16 * 4);
  len -= (16 * 4);
 }
 if (len)
  memcpy(ctx->block, data, len);
}

canonical_original_code:
void md5_update(struct md5_ctx *ctx, void *data_in, unsigned long len)
{
 unsigned long offset = ctx->count & 0x3f;
 unsigned long avail = (16 * 4) - offset;
 unsigned int *data = data_in;
 ctx->count += len;
 if (avail > len) {
  memcpy((unsigned int *)ctx->block + offset, data, len);
  return;
 }
 memcpy((unsigned int *)ctx->block + offset, data, avail);
 md5_transform(ctx->digest, ctx->block);
 data += avail;
 len -= avail;
 while (len >= (16 * 4)) {
  memcpy(ctx->block, data, (16 * 4));
  md5_transform(ctx->digest, ctx->block);
  data += (16 * 4);
  len -= (16 * 4);
 }
 if (len)
  memcpy(ctx->block, data, len);
}

variable_types:
len
unsigned long

variable_types:
offset
unsigned long

variable_types:
avail
unsigned long

variable_types:
data
unsigned int *

user_defined_types: struct md5_ctx { unsigned int block[16]; unsigned int digest[4]; unsigned int count; }


original_code:
void md5_final(struct md5_ctx *ctx, u8 *out)
{
 const size_t offset = ctx->count & 0x3f;
 char *p = (char *)ctx->block + offset;
 int padding = ((16 * 4) - 8) - (offset + 1);
 int i;
 *p++ = 0x80;
 if (padding < 0) {
  memset(p, 0, (padding + 8));
  md5_transform(ctx->digest, ctx->block);
  p = (char *)ctx->block;
  padding = ((16 * 4) - 8);
 }
 memset(p, 0, padding);
 ctx->block[14] = (ctx->count << 3);
 ctx->block[15] = (ctx->count >> 29);
 md5_transform(ctx->digest, ctx->block);
 for (i = 0; i < 4; i++)
  ctx->digest[i] = (ctx->digest[i]);
 memcpy(out, ctx->digest, (4 * 4));
 memset(ctx, 0, sizeof(*ctx));
}

canonical_original_code:
void md5_final(struct md5_ctx *ctx, unsigned int *out)
{
 unsigned long offset = ctx->count & 0x3f;
 char *p = (char *)ctx->block + offset;
 int padding = ((16 * 4) - 8) - (offset + 1);
 int i;
 *p++ = 0x80;
 if (padding < 0) {
  memset(p, 0, (padding + 8));
  md5_transform(ctx->digest, ctx->block);
  p = (char *)ctx->block;
  padding = ((16 * 4) - 8);
 }
 memset(p, 0, padding);
 ctx->block[14] = (ctx->count << 3);
 ctx->block[15] = (ctx->count >> 29);
 md5_transform(ctx->digest, ctx->block);
 for (i = 0; i < 4; i++)
  ctx->digest[i] = (ctx->digest[i]);
 memcpy(out, ctx->digest, (4 * 4));
 memset(ctx, 0, sizeof(*ctx));
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall ietadm_request_exec(unsigned int *a1, _DWORD *a2, void **a3, size_t *a4)
{
__int64 result; // rax
void *v7; // rax
size_t v8; // rdx

log_debug(1LL, "%u %u %lu %u %u", *a1, a1[1], *((_QWORD *)a1 + 1), a1[4], a1[5]);
switch ( *a1 )
{
case 0u:
result = (*(__int64 (__fastcall **)(unsigned int *, unsigned int *))(cops + 8LL))(a1 + 1, a1 + 6);
break;
case 1u:
result = (*(__int64 (__fastcall **)(_QWORD))(cops + 24LL))(a1[1]);
break;
case 2u:
if ( (a1[134] & 1) != 0 )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, unsigned int *))(cops + 56LL))(
a1[1],
*((_QWORD *)a1 + 1),
0LL,
a1[135],
a1 + 137);
if ( (int)result < 0 )
break;
}
else
{
result = 0LL;
}
if ( (a1[134] & 2) != 0 )
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD, unsigned int *))(cops + 56LL))(
a1[1],
*((_QWORD *)a1 + 1),
1LL,
a1[136],
a1 + 175);
break;
case 3u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, unsigned int *))(ki + 32LL))(
a1[1],
*((_QWORD *)a1 + 1),
1LL,
a1 + 175);
break;
case 4u:
result = (*(__int64 (__fastcall **)(_QWORD, unsigned int *, __int64))(cops + 112LL))(a1[1], a1 + 6, 1LL);
break;
case 6u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(ki + 72LL))(a1[1], *((_QWORD *)a1 + 1));
break;
case 8u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, unsigned int *))(ki + 32LL))(
a1[1],
*((_QWORD *)a1 + 1),
0LL,
a1 + 137);
break;
case 0xAu:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(ki + 96LL))(a1[1], *((_QWORD *)a1 + 1), a1[4]);
break;
case 0xDu:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *))(cops + 32LL))(a1[1], a1[5], a1 + 6);
break;
case 0xEu:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(cops + 48LL))(a1[1], a1[5]);
break;
case 0x11u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *))(cops + 64LL))(
a1[1],
a1[6],
a1 + 7,
a1 + 71);
break;
case 0x12u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *))(cops + 72LL))(a1[1], a1[6], a1 + 7);
break;
case 0x14u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *))(cops + 80LL))(
a1[1],
a1[6],
a1 + 7,
a1 + 71);
break;
case 0x16u:
isns_exit();
result = 0LL;
break;
case 0x19u:
v7 = malloc(a1[7]);
*a3 = v7;
if ( v7 )
{
v8 = a1[7];
*a4 = v8;
memset(*a3, 0, v8);
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *, void *, size_t))(cops + 88LL))(
a1[1],
a1[6],
a1 + 8,
a1 + 9,
*a3,
*a4);
}
else
{
result = 4294967284LL;
}
break;
default:
result = 0LL;
break;
}
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, _DWORD *a2, void **a3, size_t *a4)
{
__int64 result; // rax
void *v7; // rax
size_t v8; // rdx

log_debug(1LL, "%u %u %lu %u %u", *a1, a1[1], *((_QWORD *)a1 + 1), a1[4], a1[5]);
switch ( *a1 )
{
case 0u:
result = (*(__int64 (__fastcall **)(unsigned int *, unsigned int *))(cops + 8LL))(a1 + 1, a1 + 6);
break;
case 1u:
result = (*(__int64 (__fastcall **)(_QWORD))(cops + 24LL))(a1[1]);
break;
case 2u:
if ( (a1[134] & 1) != 0 )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, unsigned int *))(cops + 56LL))(
a1[1],
*((_QWORD *)a1 + 1),
0LL,
a1[135],
a1 + 137);
if ( (int)result < 0 )
break;
}
else
{
result = 0LL;
}
if ( (a1[134] & 2) != 0 )
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, _QWORD, unsigned int *))(cops + 56LL))(
a1[1],
*((_QWORD *)a1 + 1),
1LL,
a1[136],
a1 + 175);
break;
case 3u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64, unsigned int *))(ki + 32LL))(
a1[1],
*((_QWORD *)a1 + 1),
1LL,
a1 + 175);
break;
case 4u:
result = (*(__int64 (__fastcall **)(_QWORD, unsigned int *, __int64))(cops + 112LL))(a1[1], a1 + 6, 1LL);
break;
case 6u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(ki + 72LL))(a1[1], *((_QWORD *)a1 + 1));
break;
case 8u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, unsigned int *))(ki + 32LL))(
a1[1],
*((_QWORD *)a1 + 1),
0LL,
a1 + 137);
break;
case 0xAu:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(ki + 96LL))(a1[1], *((_QWORD *)a1 + 1), a1[4]);
break;
case 0xDu:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *))(cops + 32LL))(a1[1], a1[5], a1 + 6);
break;
case 0xEu:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(cops + 48LL))(a1[1], a1[5]);
break;
case 0x11u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *))(cops + 64LL))(
a1[1],
a1[6],
a1 + 7,
a1 + 71);
break;
case 0x12u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *))(cops + 72LL))(a1[1], a1[6], a1 + 7);
break;
case 0x14u:
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *))(cops + 80LL))(
a1[1],
a1[6],
a1 + 7,
a1 + 71);
break;
case 0x16u:
isns_exit();
result = 0LL;
break;
case 0x19u:
v7 = malloc(a1[7]);
*a3 = v7;
if ( v7 )
{
v8 = a1[7];
*a4 = v8;
memset(*a3, 0, v8);
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *, void *, size_t))(cops + 88LL))(
a1[1],
a1[6],
a1 + 8,
a1 + 9,
*a3,
*a4);
}
else
{
result = 4294967284LL;
}
break;
default:
result = 0LL;
break;
}
*a2 = result;
return result;
}

original_code:
static void ietadm_request_exec(struct ietadm_req *req, struct ietadm_rsp *rsp,
    void **rsp_data, size_t *rsp_data_sz)
{
 int err = 0;
 log_debug(1, "%u %u %" "l" "u" " %u %u", req->rcmnd, req->tid,
    req->sid, req->cid, req->lun);
 switch (req->rcmnd) {
 case C_TRGT_NEW:
  err = cops->target_add(&req->tid, req->u.trgt.name);
  break;
 case C_TRGT_DEL:
  err = cops->target_del(req->tid);
  break;
 case C_TRGT_UPDATE:
  if (req->u.trgt.type & (1 << key_session))
   err = cops->param_set(req->tid, req->sid,
           key_session,
           req->u.trgt.session_partial,
           req->u.trgt.session_param);
  if (err < 0)
   goto out;
  if (req->u.trgt.type & (1 << key_target))
   err = cops->param_set(req->tid, req->sid, key_target,
           req->u.trgt.target_partial,
           req->u.trgt.target_param);
  break;
 case C_TRGT_SHOW:
  err = ki->param_get(req->tid, req->sid, key_target,
        req->u.trgt.target_param);
  break;
        case C_TRGT_REDIRECT:
  err = cops->target_redirect(req->tid, req->u.redir.dest,
      0x01);
  break;
 case C_SESS_NEW:
  break;
 case C_SESS_DEL:
  err = ki->session_destroy(req->tid, req->sid);
  break;
 case C_SESS_UPDATE:
  break;
 case C_SESS_SHOW:
  err = ki->param_get(req->tid, req->sid, key_session,
        req->u.trgt.session_param);
  break;
 case C_LUNIT_NEW:
  err = cops->lunit_add(req->tid, req->lun, req->u.lunit.args);
  break;
 case C_LUNIT_DEL:
  err = cops->lunit_del(req->tid, req->lun);
  break;
 case C_LUNIT_UPDATE:
 case C_LUNIT_SHOW:
  break;
 case C_CONN_NEW:
  break;
 case C_CONN_DEL:
  err = ki->conn_destroy(req->tid, req->sid, req->cid);
  break;
 case C_CONN_UPDATE:
 case C_CONN_SHOW:
  break;
 case C_ACCT_NEW:
  err = cops->account_add(req->tid, req->u.acnt.auth_dir,
     req->u.acnt.u.user.name,
     req->u.acnt.u.user.pass);
  break;
 case C_ACCT_DEL:
  err = cops->account_del(req->tid, req->u.acnt.auth_dir,
     req->u.acnt.u.user.name);
  break;
 case C_ACCT_LIST:
  *rsp_data = malloc(req->u.acnt.u.list.alloc_len);
  if (!*rsp_data) {
   err = -12;
   break;
  }
  *rsp_data_sz = req->u.acnt.u.list.alloc_len;
  memset(*rsp_data, 0x0, *rsp_data_sz);
  err = cops->account_list(req->tid, req->u.acnt.auth_dir,
      &req->u.acnt.u.list.count,
      &req->u.acnt.u.list.overflow,
      *rsp_data, *rsp_data_sz);
  break;
 case C_ACCT_UPDATE:
  break;
 case C_ACCT_SHOW:
  err = cops->account_query(req->tid, req->u.acnt.auth_dir,
       req->u.acnt.u.user.name,
       req->u.acnt.u.user.pass);
  break;
 case C_SYS_NEW:
  break;
 case C_SYS_DEL:
  if (!err)
   isns_exit();
  break;
 case C_SYS_UPDATE:
 case C_SYS_SHOW:
  break;
 default:
  break;
 }
out:
 rsp->err = err;
}

canonical_original_code:
static void ietadm_request_exec(struct ietadm_req *req, struct ietadm_rsp *rsp, void **rsp_data, unsigned long *rsp_data_sz)
{
 int err = 0;
 log_debug(1, "%u %u %" "l" "u" " %u %u", req->rcmnd, req->tid,
    req->sid, req->cid, req->lun);
 switch (req->rcmnd) {
 case C_TRGT_NEW:
  err = cops->target_add(&req->tid, req->u.trgt.name);
  break;
 case C_TRGT_DEL:
  err = cops->target_del(req->tid);
  break;
 case C_TRGT_UPDATE:
  if (req->u.trgt.type & (1 << key_session))
   err = cops->param_set(req->tid, req->sid,
           key_session,
           req->u.trgt.session_partial,
           req->u.trgt.session_param);
  if (err < 0)
   goto out;
  if (req->u.trgt.type & (1 << key_target))
   err = cops->param_set(req->tid, req->sid, key_target,
           req->u.trgt.target_partial,
           req->u.trgt.target_param);
  break;
 case C_TRGT_SHOW:
  err = ki->param_get(req->tid, req->sid, key_target,
        req->u.trgt.target_param);
  break;
        case C_TRGT_REDIRECT:
  err = cops->target_redirect(req->tid, req->u.redir.dest,
      0x01);
  break;
 case C_SESS_NEW:
  break;
 case C_SESS_DEL:
  err = ki->session_destroy(req->tid, req->sid);
  break;
 case C_SESS_UPDATE:
  break;
 case C_SESS_SHOW:
  err = ki->param_get(req->tid, req->sid, key_session,
        req->u.trgt.session_param);
  break;
 case C_LUNIT_NEW:
  err = cops->lunit_add(req->tid, req->lun, req->u.lunit.args);
  break;
 case C_LUNIT_DEL:
  err = cops->lunit_del(req->tid, req->lun);
  break;
 case C_LUNIT_UPDATE:
 case C_LUNIT_SHOW:
  break;
 case C_CONN_NEW:
  break;
 case C_CONN_DEL:
  err = ki->conn_destroy(req->tid, req->sid, req->cid);
  break;
 case C_CONN_UPDATE:
 case C_CONN_SHOW:
  break;
 case C_ACCT_NEW:
  err = cops->account_add(req->tid, req->u.acnt.auth_dir,
     req->u.acnt.u.user.name,
     req->u.acnt.u.user.pass);
  break;
 case C_ACCT_DEL:
  err = cops->account_del(req->tid, req->u.acnt.auth_dir,
     req->u.acnt.u.user.name);
  break;
 case C_ACCT_LIST:
  *rsp_data = malloc(req->u.acnt.u.list.alloc_len);
  if (!*rsp_data) {
   err = -12;
   break;
  }
  *rsp_data_sz = req->u.acnt.u.list.alloc_len;
  memset(*rsp_data, 0x0, *rsp_data_sz);
  err = cops->account_list(req->tid, req->u.acnt.auth_dir,
      &req->u.acnt.u.list.count,
      &req->u.acnt.u.list.overflow,
      *rsp_data, *rsp_data_sz);
  break;
 case C_ACCT_UPDATE:
  break;
 case C_ACCT_SHOW:
  err = cops->account_query(req->tid, req->u.acnt.auth_dir,
       req->u.acnt.u.user.name,
       req->u.acnt.u.user.pass);
  break;
 case C_SYS_NEW:
  break;
 case C_SYS_DEL:
  if (!err)
   isns_exit();
  break;
 case C_SYS_UPDATE:
 case C_SYS_SHOW:
  break;
 default:
  break;
 }
out:
 rsp->err = err;
}

variable_types: struct ietadm_req { enum ietadm_cmnd { C_TRGT_NEW=0, C_TRGT_DEL=1, C_TRGT_UPDATE=2, C_TRGT_SHOW=3, C_TRGT_REDIRECT=4, C_SESS_NEW=5, C_SESS_DEL=6, C_SESS_UPDATE=7, C_SESS_SHOW=8, C_CONN_NEW=9, C_CONN_DEL=10, C_CONN_UPDATE=11, C_CONN_SHOW=12, C_LUNIT_NEW=13, C_LUNIT_DEL=14, C_LUNIT_UPDATE=15, C_LUNIT_SHOW=16, C_ACCT_NEW=17, C_ACCT_DEL=18, C_ACCT_UPDATE=19, C_ACCT_SHOW=20, C_SYS_NEW=21, C_SYS_DEL=22, C_SYS_UPDATE=23, C_SYS_SHOW=24, C_ACCT_LIST=25 } rcmnd; unsigned int tid; unsigned int sid; unsigned int cid; unsigned int lun; union { struct msg_trgt { char name[256]; char alias[256]; unsigned int type; unsigned int session_partial; unsigned int target_partial; struct iscsi_param { int state; unsigned int val; } session_param[-1]; struct iscsi_param target_param[-1]; } trgt; struct msg_acnt { unsigned int auth_dir; union { struct { char name[256]; char pass[256]; } user; struct { unsigned int alloc_len; unsigned int count; unsigned int overflow; } list; } u; } acnt; struct msg_lunit { char args[2048]; } lunit; struct msg_redir { char dest[-1]; } redir; } u; } *

variable_types:
rsp
struct ietadm_rsp { int err; } *

variable_types: err int

user_defined_types: struct ietadm_req { enum ietadm_cmnd rcmnd; unsigned int tid; unsigned int sid; unsigned int cid; unsigned int lun; union { struct msg_trgt trgt; struct msg_acnt acnt; struct msg_lunit lunit; struct msg_redir redir; } u; }

user_defined_types: struct msg_trgt { char name[256]; char alias[256]; unsigned int type; unsigned int session_partial; unsigned int target_partial; struct iscsi_param session_param[-1]; struct iscsi_param target_param[-1]; }


decompiled_code:
__int64 ietadm_request_listen()
{
int v0; // ebx
int v1; // eax
int v2; // eax
_BYTE v4[104]; // [rsp+0h] [rbp-78h] BYREF
int v5; // [rsp+68h] [rbp-10h]
__int16 v6; // [rsp+6Ch] [rbp-Ch]

v0 = socket(1, 1, 0);
if ( v0 >= 0 )
{
memset(v4, 0, sizeof(v4));
v5 = 0;
v6 = 0;
*(_WORD *)v4 = 1;
qmemcpy(&v4[3], "IET_ABSTRACT_NAMESPACE", 22);
v1 = bind(v0, (const struct sockaddr *)v4, 0x6Eu);
if ( v1 < 0 )
{
v0 = v1;
}
else
{
v2 = listen(v0, 32);
if ( v2 < 0 )
v0 = v2;
}
}
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
int v1; // eax
int v2; // eax
_BYTE v4[104]; // [rsp+0h] [rbp-78h] BYREF
int v5; // [rsp+68h] [rbp-10h]
__int16 v6; // [rsp+6Ch] [rbp-Ch]

v0 = socket(1, 1, 0);
if ( v0 >= 0 )
{
memset(v4, 0, sizeof(v4));
v5 = 0;
v6 = 0;
*(_WORD *)v4 = 1;
qmemcpy(&v4[3], "IET_ABSTRACT_NAMESPACE", 22);
v1 = bind(v0, (const struct sockaddr *)v4, 0x6Eu);
if ( v1 < 0 )
{
v0 = v1;
}
else
{
v2 = listen(v0, 32);
if ( v2 < 0 )
v0 = v2;
}
}
return (unsigned int)v0;
}

original_code:
int ietadm_request_listen(void)
{
 int fd, err;
 struct sockaddr_un addr;
 fd = socket(1, SOCK_STREAM, 0);
 if (fd < 0)
  return fd;
 memset(&addr, 0, sizeof(addr));
 addr.sun_family = 1;
 memcpy((char *) &addr.sun_path + 1, "IET_ABSTRACT_NAMESPACE", strlen("IET_ABSTRACT_NAMESPACE"));
 if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0)
  return err;
 if ((err = listen(fd, 32)) < 0)
  return err;
 return fd;
}

canonical_original_code:
int ietadm_request_listen()
{
 int fd; int err;
 struct sockaddr_un addr;
 fd = socket(1, SOCK_STREAM, 0);
 if (fd < 0)
  return fd;
 memset(&addr, 0, sizeof(addr));
 addr.sun_family = 1;
 memcpy((char *) &addr.sun_path + 1, "IET_ABSTRACT_NAMESPACE", strlen("IET_ABSTRACT_NAMESPACE"));
 if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0)
  return err;
 if ((err = listen(fd, 32)) < 0)
  return err;
 return fd;
}

variable_types: fd int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

return_type: int

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


decompiled_code:
__int64 __fastcall ietadm_request_handle(int a1)
{
int v1; // eax
int v2; // ebx
int v3; // edx
unsigned int v4; // ebp
int v6; // eax
__int64 v7; // [rsp+0h] [rbp-8A8h] BYREF
void *ptr; // [rsp+8h] [rbp-8A0h] BYREF
struct iovec iovec; // [rsp+10h] [rbp-898h] BYREF
int *v10; // [rsp+20h] [rbp-888h]
__int64 v11; // [rsp+28h] [rbp-880h]
void *v12; // [rsp+30h] [rbp-878h]
__int64 v13; // [rsp+38h] [rbp-870h]
int v14; // [rsp+4Ch] [rbp-85Ch] BYREF
unsigned int buf[520]; // [rsp+50h] [rbp-858h] BYREF
socklen_t addr_len; // [rsp+870h] [rbp-38h] BYREF
char optval[4]; // [rsp+874h] [rbp-34h] BYREF
__int64 v18; // [rsp+878h] [rbp-30h]
struct sockaddr addr; // [rsp+880h] [rbp-28h] BYREF

ptr = 0LL;
v14 = 0;
addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
{
v4 = (*_errno_location() == 4) - 5;
goto LABEL_12;
}
v2 = v1;
addr_len = 12;
if ( getsockopt(v1, 1, 17, optval, &addr_len) < 0 )
{
v14 = -1;
}
else if ( v18 )
{
v14 = -1;
}
else
{
v6 = read(v2, buf, 0x818uLL);
v4 = v6;
if ( v6 != 2072 )
{
if ( v6 >= 0 )
v4 = -5;
goto LABEL_9;
}
ietadm_request_exec(buf, &v14, &ptr, (size_t *)&v7);
}
iovec.iov_base = buf;
iovec.iov_len = 2072LL;
v10 = &v14;
v11 = 4LL;
if ( v14 )
{
v12 = 0LL;
goto LABEL_22;
}
v12 = ptr;
if ( !ptr )
{
LABEL_22:
v13 = 0LL;
v3 = 2;
goto LABEL_8;
}
v13 = v7;
v3 = 2 - ((v7 == 0) - 1);
LABEL_8:
v4 = writev(v2, &iovec, v3);
LABEL_9:
if ( v2 > 0 )
close(v2);
LABEL_12:
if ( ptr )
free(ptr);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // eax
int v2; // ebx
int v3; // edx
unsigned int v4; // ebp
int v6; // eax
__int64 v7; // [rsp+0h] [rbp-8A8h] BYREF
void *ptr; // [rsp+8h] [rbp-8A0h] BYREF
struct iovec iovec; // [rsp+10h] [rbp-898h] BYREF
int *v10; // [rsp+20h] [rbp-888h]
__int64 v11; // [rsp+28h] [rbp-880h]
void *v12; // [rsp+30h] [rbp-878h]
__int64 v13; // [rsp+38h] [rbp-870h]
int v14; // [rsp+4Ch] [rbp-85Ch] BYREF
unsigned int buf[520]; // [rsp+50h] [rbp-858h] BYREF
socklen_t addr_len; // [rsp+870h] [rbp-38h] BYREF
char optval[4]; // [rsp+874h] [rbp-34h] BYREF
__int64 v18; // [rsp+878h] [rbp-30h]
struct sockaddr addr; // [rsp+880h] [rbp-28h] BYREF

ptr = 0LL;
v14 = 0;
addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
{
v4 = (*_errno_location() == 4) - 5;
goto LABEL_12;
}
v2 = v1;
addr_len = 12;
if ( getsockopt(v1, 1, 17, optval, &addr_len) < 0 )
{
v14 = -1;
}
else if ( v18 )
{
v14 = -1;
}
else
{
v6 = read(v2, buf, 0x818uLL);
v4 = v6;
if ( v6 != 2072 )
{
if ( v6 >= 0 )
v4 = -5;
goto LABEL_9;
}
func0(buf, &v14, &ptr, (size_t *)&v7);
}
iovec.iov_base = buf;
iovec.iov_len = 2072LL;
v10 = &v14;
v11 = 4LL;
if ( v14 )
{
v12 = 0LL;
goto LABEL_22;
}
v12 = ptr;
if ( !ptr )
{
LABEL_22:
v13 = 0LL;
v3 = 2;
goto LABEL_8;
}
v13 = v7;
v3 = 2 - ((v7 == 0) - 1);
LABEL_8:
v4 = writev(v2, &iovec, v3);
LABEL_9:
if ( v2 > 0 )
close(v2);
LABEL_12:
if ( ptr )
free(ptr);
return v4;
}

original_code:
int ietadm_request_handle(int accept_fd)
{
 struct sockaddr addr;
 struct ucred cred;
 int fd, err;
 socklen_t len;
 struct ietadm_req req;
 struct ietadm_rsp rsp;
 struct iovec iov[3];
 void *rsp_data = ((void *)0);
 size_t rsp_data_sz;
 memset(&rsp, 0, sizeof(rsp));
 len = sizeof(addr);
 if ((fd = accept(accept_fd, (struct sockaddr *) &addr, &len)) < 0) {
  if ((*__errno_location ()) == 4)
   err = -4;
  else
   err = -5;
  goto out;
 }
 len = sizeof(cred);
 if ((err = getsockopt(fd, 1, 17, (void *) &cred, &len)) < 0) {
  rsp.err = -1;
  goto send;
 }
 if (cred.uid || cred.gid) {
  rsp.err = -1;
  goto send;
 }
 if ((err = read(fd, &req, sizeof(req))) != sizeof(req)) {
  if (err >= 0)
   err = -5;
  goto out;
 }
 ietadm_request_exec(&req, &rsp, &rsp_data, &rsp_data_sz);
send:
 iov[0].iov_base = &req;
 iov[0].iov_len = sizeof(req);
 iov[1].iov_base = &rsp;
 iov[1].iov_len = sizeof(rsp);
 iov[2].iov_base = rsp.err ? ((void *)0) : rsp_data;
 iov[2].iov_len = iov[2].iov_base ? rsp_data_sz : 0;
 err = writev(fd, iov, 2 + !!iov[2].iov_len);
out:
 if (fd > 0)
  close(fd);
 if (rsp_data)
  free(rsp_data);
 return err;
}

canonical_original_code:
int ietadm_request_handle(int accept_fd)
{
 struct sockaddr addr;
 struct ucred cred;
 int fd; int err;
 unsigned int len;
 struct ietadm_req req;
 struct ietadm_rsp rsp;
 struct iovec iov[3];
 void *rsp_data = ((void *)0);
 unsigned long rsp_data_sz;
 memset(&rsp, 0, sizeof(rsp));
 len = sizeof(addr);
 if ((fd = accept(accept_fd, (struct sockaddr *) &addr, &len)) < 0) {
  if ((*__errno_location ()) == 4)
   err = -4;
  else
   err = -5;
  goto out;
 }
 len = sizeof(cred);
 if ((err = getsockopt(fd, 1, 17, (void *) &cred, &len)) < 0) {
  rsp.err = -1;
  goto send;
 }
 if (cred.uid || cred.gid) {
  rsp.err = -1;
  goto send;
 }
 if ((err = read(fd, &req, sizeof(req))) != sizeof(req)) {
  if (err >= 0)
   err = -5;
  goto out;
 }
 ietadm_request_exec(&req, &rsp, &rsp_data, &rsp_data_sz);
send:
 iov[0].iov_base = &req;
 iov[0].iov_len = sizeof(req);
 iov[1].iov_base = &rsp;
 iov[1].iov_len = sizeof(rsp);
 iov[2].iov_base = rsp.err ? ((void *)0) : rsp_data;
 iov[2].iov_len = iov[2].iov_base ? rsp_data_sz : 0;
 err = writev(fd, iov, 2 + !!iov[2].iov_len);
out:
 if (fd > 0)
  close(fd);
 if (rsp_data)
  free(rsp_data);
 return err;
}

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

variable_types: struct ucred { int pid; unsigned int uid; unsigned int gid; }

variable_types:
len
unsigned int

variable_types: struct ietadm_req { enum ietadm_cmnd { C_TRGT_NEW=0, C_TRGT_DEL=1, C_TRGT_UPDATE=2, C_TRGT_SHOW=3, C_TRGT_REDIRECT=4, C_SESS_NEW=5, C_SESS_DEL=6, C_SESS_UPDATE=7, C_SESS_SHOW=8, C_CONN_NEW=9, C_CONN_DEL=10, C_CONN_UPDATE=11, C_CONN_SHOW=12, C_LUNIT_NEW=13, C_LUNIT_DEL=14, C_LUNIT_UPDATE=15, C_LUNIT_SHOW=16, C_ACCT_NEW=17, C_ACCT_DEL=18, C_ACCT_UPDATE=19, C_ACCT_SHOW=20, C_SYS_NEW=21, C_SYS_DEL=22, C_SYS_UPDATE=23, C_SYS_SHOW=24, C_ACCT_LIST=25 } rcmnd; unsigned int tid; unsigned int sid; unsigned int cid; unsigned int lun; union { struct msg_trgt { char name[256]; char alias[256]; unsigned int type; unsigned int session_partial; unsigned int target_partial; struct iscsi_param { int state; unsigned int val; } session_param[-1]; struct iscsi_param target_param[-1]; } trgt; struct msg_acnt { unsigned int auth_dir; union { struct { char name[256]; char pass[256]; } user; struct { unsigned int alloc_len; unsigned int count; unsigned int overflow; } list; } u; } acnt; struct msg_lunit { char args[2048]; } lunit; struct msg_redir { char dest[-1]; } redir; } u; }

variable_types:
rsp
struct ietadm_rsp { int err; }

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [3]


decompiled_code:
_BOOL8 __fastcall session_exist(int a1, __int64 a2)
{
__int64 v3[37]; // [rsp+0h] [rbp-128h] BYREF

memset(v3, 0, 0x118uLL);
LODWORD(v3[0]) = a1;
v3[1] = a2;
return (*(unsigned int (__fastcall **)(__int64 *))(ki + 80LL))(v3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1, __int64 a2)
{
__int64 v3[37]; // [rsp+0h] [rbp-128h] BYREF

memset(v3, 0, 0x118uLL);
LODWORD(v3[0]) = a1;
v3[1] = a2;
return (*(unsigned int (__fastcall **)(__int64 *))(ki + 80LL))(v3) == 0;
}

original_code:
int session_exist(u32 t_tid, u64 t_sid)
{
 struct session_info info;
 memset(&info, 0x0, sizeof(info));
 info.tid = t_tid;
 info.sid = t_sid;
 return !ki->session_info(&info);
}

canonical_original_code:
int session_exist(unsigned int t_tid, unsigned int t_sid)
{
 struct session_info info;
 memset(&info, 0x0, sizeof(info));
 info.tid = t_tid;
 info.sid = t_sid;
 return !ki->session_info(&info);
}

variable_types: struct session_info { unsigned int tid; unsigned long long sid; char initiator_name[256]; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; }


decompiled_code:
__int64 __fastcall session_create(__int64 a1)
{
_QWORD *v1; // rbx
unsigned int v2; // er12
int v3; // eax
char *v5; // r12
_QWORD *v6; // rax
int *v7; // rax
int *v8; // rax

v1 = *(_QWORD **)(a1 + 16);
if ( v1 )
{
*(_QWORD *)(a1 + 192) = v1[4];
v2 = 0;
if ( session_exist(*(_DWORD *)(a1 + 24), v1[4]) )
return v2;
}
else
{
v5 = strdup(*(const char **)(a1 + 184));
if ( !v5 )
return (unsigned int)-12;
v6 = session_alloc();
v1 = v6;
if ( !v6 )
{
free(v5);
return (unsigned int)-12;
}
v6[4] = *(_QWORD *)(a1 + 192);
*((_WORD *)v6 + 19) = tsih_0;
while ( session_exist(*(_DWORD *)(a1 + 24), v1[4]) )
++*((_WORD *)v1 + 19);
tsih_0 = *((_WORD *)v1 + 19) + 1;
v1[2] = v5;
*(_QWORD *)(a1 + 16) = v1;
*((_DWORD *)v1 + 10) = 1;
*(_QWORD *)(a1 + 192) = v1[4];
}
log_debug(1LL, "session_create: %#lx", v1[4]);
v3 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))(ki + 64LL))(
*(unsigned int *)(a1 + 24),
v1[4],
*(unsigned int *)(a1 + 224),
*(unsigned int *)(a1 + 228),
v1[2]);
v2 = v3;
if ( v3 >= 0 || v3 == -17 )
{
v2 = 0;
if ( (*(int (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))(ki + 40LL))(
*(unsigned int *)(a1 + 24),
v1[4],
0LL,
0LL,
a1 + 28) < 0 )
{
v8 = _errno_location();
log_warning(
"unable to set parameters for session %#lx in target %u: %d",
v1[4],
*(unsigned int *)(a1 + 24),
(unsigned int)*v8);
}
}
else
{
v7 = _errno_location();
log_error("unable to create session %#lx in target %u: %d", v1[4], *(unsigned int *)(a1 + 24), (unsigned int)*v7);
*(_QWORD *)(a1 + 16) = 0LL;
if ( v1[3] )
{
remque(v1);
--*(_DWORD *)(v1[3] + 1368LL);
}
free((void *)v1[2]);
free(v1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_QWORD *v1; // rbx
unsigned int v2; // er12
int v3; // eax
char *v5; // r12
_QWORD *v6; // rax
int *v7; // rax
int *v8; // rax

v1 = *(_QWORD **)(a1 + 16);
if ( v1 )
{
*(_QWORD *)(a1 + 192) = v1[4];
v2 = 0;
if ( func1(*(_DWORD *)(a1 + 24), v1[4]) )
return v2;
}
else
{
v5 = strdup(*(const char **)(a1 + 184));
if ( !v5 )
return (unsigned int)-12;
v6 = func0();
v1 = v6;
if ( !v6 )
{
free(v5);
return (unsigned int)-12;
}
v6[4] = *(_QWORD *)(a1 + 192);
*((_WORD *)v6 + 19) = tsih_0;
while ( func1(*(_DWORD *)(a1 + 24), v1[4]) )
++*((_WORD *)v1 + 19);
tsih_0 = *((_WORD *)v1 + 19) + 1;
v1[2] = v5;
*(_QWORD *)(a1 + 16) = v1;
*((_DWORD *)v1 + 10) = 1;
*(_QWORD *)(a1 + 192) = v1[4];
}
log_debug(1LL, "session_create: %#lx", v1[4]);
v3 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))(ki + 64LL))(
*(unsigned int *)(a1 + 24),
v1[4],
*(unsigned int *)(a1 + 224),
*(unsigned int *)(a1 + 228),
v1[2]);
v2 = v3;
if ( v3 >= 0 || v3 == -17 )
{
v2 = 0;
if ( (*(int (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))(ki + 40LL))(
*(unsigned int *)(a1 + 24),
v1[4],
0LL,
0LL,
a1 + 28) < 0 )
{
v8 = _errno_location();
log_warning(
"unable to set parameters for session %#lx in target %u: %d",
v1[4],
*(unsigned int *)(a1 + 24),
(unsigned int)*v8);
}
}
else
{
v7 = _errno_location();
log_error("unable to create session %#lx in target %u: %d", v1[4], *(unsigned int *)(a1 + 24), (unsigned int)*v7);
*(_QWORD *)(a1 + 16) = 0LL;
if ( v1[3] )
{
remque(v1);
--*(_DWORD *)(v1[3] + 1368LL);
}
free((void *)v1[2]);
free(v1);
}
return v2;
}

original_code:
int session_create(struct connection *conn)
{
 struct session *session;
 char *initiator;
 static u16 tsih = 1;
 int err;
 if (!conn->session) {
  initiator = strdup(conn->initiator);
  if (!initiator)
   return -12;
  session = session_alloc(conn->tid);
  if (!session) {
   free(initiator);
   return -12;
  }
  session->sid = conn->sid;
  session->sid.id.tsih = tsih;
  while (session_exist(conn->tid, session->sid.id64))
   session->sid.id.tsih++;
  tsih = session->sid.id.tsih + 1;
  session->initiator = initiator;
  conn->session = session;
  session->conn_cnt = 1;
  conn->sid = session->sid;
 } else {
  session = conn->session;
  conn->sid = session->sid;
  if (session_exist(conn->tid, session->sid.id64))
   return 0;
 }
 log_debug(1, "session_create: %#" "l" "x", session->sid.id64);
 err = ki->session_create(conn->tid, session->sid.id64, conn->exp_cmd_sn,
      conn->max_cmd_sn, session->initiator);
 if (err < 0 && err != -17) {
  log_error("unable to create session %#" "l" "x" " in target %u: %d",
   session->sid.id64, conn->tid, (*__errno_location ()));
  goto out;
 }
 err = ki->param_set(conn->tid, session->sid.id64, key_session, 0,
       conn->session_param);
 if (err < 0)
  log_warning("unable to set parameters for session %#" "l" "x" " in target %u: %d",
   session->sid.id64, conn->tid, (*__errno_location ()));
 return 0;
out:
 conn->session = ((void *)0);
 if (session->target) {
  remque(&session->slist);
  --session->target->nr_sessions;
 }
 free(session->initiator);
 free(session);
 return err;
}

canonical_original_code:
int session_create(struct connection *conn)
{
 struct session *session;
 char *initiator;
 static unsigned int tsih = 1;
 int err;
 if (!conn->session) {
  initiator = strdup(conn->initiator);
  if (!initiator)
   return -12;
  session = session_alloc(conn->tid);
  if (!session) {
   free(initiator);
   return -12;
  }
  session->sid = conn->sid;
  session->sid.id.tsih = tsih;
  while (session_exist(conn->tid, session->sid.id64))
   session->sid.id.tsih++;
  tsih = session->sid.id.tsih + 1;
  session->initiator = initiator;
  conn->session = session;
  session->conn_cnt = 1;
  conn->sid = session->sid;
 } else {
  session = conn->session;
  conn->sid = session->sid;
  if (session_exist(conn->tid, session->sid.id64))
   return 0;
 }
 log_debug(1, "session_create: %#" "l" "x", session->sid.id64);
 err = ki->session_create(conn->tid, session->sid.id64, conn->exp_cmd_sn,
      conn->max_cmd_sn, session->initiator);
 if (err < 0 && err != -17) {
  log_error("unable to create session %#" "l" "x" " in target %u: %d",
   session->sid.id64, conn->tid, (*__errno_location ()));
  goto out;
 }
 err = ki->param_set(conn->tid, session->sid.id64, key_session, 0,
       conn->session_param);
 if (err < 0)
  log_warning("unable to set parameters for session %#" "l" "x" " in target %u: %d",
   session->sid.id64, conn->tid, (*__errno_location ()));
 return 0;
out:
 conn->session = ((void *)0);
 if (session->target) {
  remque(&session->slist);
  --session->target->nr_sessions;
 }
 free(session->initiator);
 free(session);
 return err;
}

variable_types: struct connection { int state; int iostate; int fd; struct session { struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } slist; char *initiator; struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; } redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; } *target; union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; } sid; int conn_cnt; } *session; unsigned int tid; struct iscsi_param { int state; unsigned int val; } session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU { struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; } bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; } req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; } *

variable_types:
initiator
char *

variable_types:
tsih
unsigned int

user_defined_types: struct connection { int state; int iostate; int fd; struct session *session; unsigned int tid; struct iscsi_param session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; }

user_defined_types: struct session { struct __qelem slist; char *initiator; struct target *target; union iscsi_sid sid; int conn_cnt; }

user_defined_types: struct PDU { struct iscsi_hdr bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; }

user_defined_types: struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; }


decompiled_code:
__int64 __fastcall session_remove(void *elem)
{
int v1; // eax
unsigned int v2; // ebp
int *v4; // rax

log_debug(1LL, "session_remove: %#lx", *((_QWORD *)elem + 4));
v1 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(ki + 72LL))(
*(unsigned int *)(*((_QWORD *)elem + 3) + 32LL),
*((_QWORD *)elem + 4));
if ( v1 >= 0 || (v2 = v1, v1 == -2) )
{
if ( *((_QWORD *)elem + 3) )
{
remque(elem);
--*(_DWORD *)(*((_QWORD *)elem + 3) + 1368LL);
}
free(*((void **)elem + 2));
free(elem);
v2 = 0;
}
else
{
v4 = _errno_location();
log_error(
"unable to delete session %#lx in target %u: %d",
*((_QWORD *)elem + 4),
*(unsigned int *)(*((_QWORD *)elem + 3) + 32LL),
(unsigned int)*v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *elem)
{
int v1; // eax
unsigned int v2; // ebp
int *v4; // rax

log_debug(1LL, "session_remove: %#lx", *((_QWORD *)elem + 4));
v1 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(ki + 72LL))(
*(unsigned int *)(*((_QWORD *)elem + 3) + 32LL),
*((_QWORD *)elem + 4));
if ( v1 >= 0 || (v2 = v1, v1 == -2) )
{
if ( *((_QWORD *)elem + 3) )
{
remque(elem);
--*(_DWORD *)(*((_QWORD *)elem + 3) + 1368LL);
}
free(*((void **)elem + 2));
free(elem);
v2 = 0;
}
else
{
v4 = _errno_location();
log_error(
"unable to delete session %#lx in target %u: %d",
*((_QWORD *)elem + 4),
*(unsigned int *)(*((_QWORD *)elem + 3) + 32LL),
(unsigned int)*v4);
}
return v2;
}

original_code:
int session_remove(struct session *session)
{
 int err;
 log_debug(1, "session_remove: %#" "l" "x", session->sid.id64);
 err = ki->session_destroy(session->target->tid, session->sid.id64);
 if (err < 0 && err != -2) {
  log_error("unable to delete session %#" "l" "x" " in target %u: %d",
   session->sid.id64, session->target->tid, (*__errno_location ()));
  return err;
 }
 if (session->target) {
  remque(&session->slist);
  --session->target->nr_sessions;
 }
 free(session->initiator);
 free(session);
 return 0;
}

variable_types: struct session { struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } slist; char *initiator; struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; } redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; } *target; union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; } sid; int conn_cnt; } *


decompiled_code:
int *__fastcall handle_iscsi_events(int a1)
{
int *result; // rax
__int64 v2; // rsi
int v3; // ecx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
unsigned int v6; // [rsp+10h] [rbp-18h]
unsigned int v7; // [rsp+14h] [rbp-14h]

while ( (int)nl_read(a1, (__int64)&v4, 24) < 0 )
{
result = _errno_location();
v2 = (unsigned int)*result;
if ( (_DWORD)v2 == 11 )
return result;
if ( (_DWORD)v2 != 4 )
{
log_error("read netlink fd (%d)", v2);
exit(1);
}
}
log_debug(1LL, "conn %u session %llu target %u, state %u", v6, v5, HIDWORD(v4), v7);
if ( v7 )
{
log_error("%s(%d) %u\n", "handle_iscsi_events", 98LL, v7);
exit(-1);
}
result = (int *)session_find_id(HIDWORD(v4), v5);
if ( result )
{
v3 = result[10];
result[10] = v3 - 1;
if ( v3 - 1 <= 0 )
result = (int *)session_remove(result);
}
return result;
}

canonical_decompiled_code:
int *__fastcall func2(int a1)
{
int *result; // rax
__int64 v2; // rsi
int v3; // ecx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
unsigned int v6; // [rsp+10h] [rbp-18h]
unsigned int v7; // [rsp+14h] [rbp-14h]

while ( (int)func0(a1, (__int64)&v4, 24) < 0 )
{
result = _errno_location();
v2 = (unsigned int)*result;
if ( (_DWORD)v2 == 11 )
return result;
if ( (_DWORD)v2 != 4 )
{
log_error("read netlink fd (%d)", v2);
exit(1);
}
}
log_debug(1LL, "conn %u session %llu target %u, state %u", v6, v5, HIDWORD(v4), v7);
if ( v7 )
{
log_error("%s(%d) %u\n", "handle_iscsi_events", 98LL, v7);
exit(-1);
}
result = (int *)session_find_id(HIDWORD(v4), v5);
if ( result )
{
v3 = result[10];
result[10] = v3 - 1;
if ( v3 - 1 <= 0 )
result = (int *)session_remove(result);
}
return result;
}

original_code:
void handle_iscsi_events(int fd)
{
 struct session *session;
 struct iet_event event;
 int res;
retry:
 if ((res = nl_read(fd, &event, sizeof(event))) < 0) {
  if ((*__errno_location ()) == 11)
   return;
  if ((*__errno_location ()) == 4)
   goto retry;
  log_error("read netlink fd (%d)", (*__errno_location ()));
  exit(1);
 }
 log_debug(1, "conn %u session %llu target %u, state %u",
    event.cid, event.sid, event.tid, event.state);
 switch (event.state) {
 case E_CONN_CLOSE:
  if (!(session = session_find_id(event.tid, event.sid)))
   break;
  if (--session->conn_cnt <= 0)
   session_remove(session);
  break;
 default:
  log_error("%s(%d) %u\n", __FUNCTION__, 98, event.state);
  exit(-1);
  break;
 }
}

variable_types: struct iet_event { unsigned int inuse; unsigned int tid; unsigned long long sid; unsigned int cid; unsigned int state; }

variable_types: res int

user_defined_types: struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; }

user_defined_types: union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; }

user_defined_types: struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; }


decompiled_code:
__int64 nl_open()
{
unsigned int v0; // ebx
int v1; // eax
int v2; // ebp
int *v4; // rax

v0 = socket(16, 3, 21);
if ( v0 == -1 )
{
v4 = _errno_location();
log_error("%s %d\n", "nl_open", (unsigned int)*v4);
}
else
{
src_addr = 16LL;
dword_2D8 = 0;
HIDWORD(src_addr) = getpid();
dword_2D8 = 0;
dest_addr = 16LL;
dword_2C8 = 0;
v1 = nl_write(v0, 0LL, 0);
v2 = v1;
if ( v1 < 0 )
{
log_error("%s %d\n", "nl_open", (unsigned int)v1);
v0 = v2;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
int v1; // eax
int v2; // ebp
int *v4; // rax

v0 = socket(16, 3, 21);
if ( v0 == -1 )
{
v4 = _errno_location();
log_error("%s %d\n", "nl_open", (unsigned int)*v4);
}
else
{
src_addr = 16LL;
dword_2D8 = 0;
HIDWORD(src_addr) = getpid();
dword_2D8 = 0;
dest_addr = 16LL;
dword_2C8 = 0;
v1 = func1(v0, 0LL, 0);
v2 = v1;
if ( v1 < 0 )
{
log_error("%s %d\n", "nl_open", (unsigned int)v1);
v0 = v2;
}
}
return v0;
}

original_code:
int nl_open(void)
{
 int nl_fd, res;
 nl_fd = socket(16, SOCK_RAW, 21);
 if (nl_fd == -1) {
  log_error("%s %d\n", __FUNCTION__, (*__errno_location ()));
  return -1;
 }
 memset(&src_addr, 0, sizeof(src_addr));
 src_addr.nl_family = 16;
 src_addr.nl_pid = getpid();
 src_addr.nl_groups = 0;
 memset(&dest_addr, 0, sizeof(dest_addr));
 dest_addr.nl_family = 16;
 dest_addr.nl_pid = 0;
 dest_addr.nl_groups = 0;
 res = nl_write(nl_fd, ((void *)0), 0);
 if (res < 0) {
  log_error("%s %d\n", __FUNCTION__, res);
  return res;
 }
 return nl_fd;
}

canonical_original_code:
int nl_open()
{
 int nl_fd; int res;
 nl_fd = socket(16, SOCK_RAW, 21);
 if (nl_fd == -1) {
  log_error("%s %d\n", __FUNCTION__, (*__errno_location ()));
  return -1;
 }
 memset(&src_addr, 0, sizeof(src_addr));
 src_addr.nl_family = 16;
 src_addr.nl_pid = getpid();
 src_addr.nl_groups = 0;
 memset(&dest_addr, 0, sizeof(dest_addr));
 dest_addr.nl_family = 16;
 dest_addr.nl_pid = 0;
 dest_addr.nl_groups = 0;
 res = nl_write(nl_fd, ((void *)0), 0);
 if (res < 0) {
  log_error("%s %d\n", __FUNCTION__, res);
  return res;
 }
 return nl_fd;
}


main

canonical_name: main

repo: quakehead/mstring

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
const char *v4; // rsi
const char **v5; // rbx
const char *v6; // rdx
char *v7; // rbx

printf("String: %s\n", "a\tb\tword two\tsdd sdf fsdfs");
v3 = (const char **)split("t he quick brown fox jumped", (char *)" ");
printf("Split: ");
v4 = *v3;
if ( *v3 )
{
v5 = v3;
do
{
v6 = "String: %s\n" + 11;
if ( v5[1] )
v6 = (const char *)&unk_402004;
printf("%s%s", v4, v6);
v4 = *++v5;
}
while ( *v5 );
}
putchar(10);
v7 = (char *)join(v3, ":");
printf("Join: %s\n", v7);
free_parts(v3);
free(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
const char *v4; // rsi
const char **v5; // rbx
const char *v6; // rdx
char *v7; // rbx

printf("String: %s\n", "a\tb\tword two\tsdd sdf fsdfs");
v3 = (const char **)func7("t he quick brown fox jumped", (char *)" ");
printf("Split: ");
v4 = *v3;
if ( *v3 )
{
v5 = v3;
do
{
v6 = "String: %s\n" + 11;
if ( v5[1] )
v6 = (const char *)&unk_402004;
printf("%s%s", v4, v6);
v4 = *++v5;
}
while ( *v5 );
}
putchar(10);
v7 = (char *)func8(v3, ":");
printf("Join: %s\n", v7);
func9(v3);
free(v7);
return 0;
}

original_code:
int main(void) {
 char* cstr = "a\tb\tword two\tsdd sdf fsdfs";
 char* cstr2 = "t he quick   brown fox    jumped";
 char** parts;
 char** parts_orig;
 char* str;
 printf("String: %s\n", cstr);
 parts = split(cstr2, " ");
 parts_orig = parts;
 printf("Split: ");
 char* delim = ",";
 while (*parts != ((void *)0)) {
  printf("%s%s", *parts, *(parts+1)==((void *)0)?"":delim);
  parts++;
 }
 putchar('\n');
 parts = parts_orig;
 str = join((const char **) parts, ":");
 printf("Join: %s\n", str);
    free_parts(parts);
    free(str);
 return 0;
}

canonical_original_code:
int main() {
 char *cstr = "a\tb\tword two\tsdd sdf fsdfs";
 char *cstr2 = "t he quick   brown fox    jumped";
 char **parts;
 char **parts_orig;
 char *str;
 printf("String: %s\n", cstr);
 parts = split(cstr2, " ");
 parts_orig = parts;
 printf("Split: ");
 char *delim = ",";
 while (*parts != ((void *)0)) {
  printf("%s%s", *parts, *(parts+1)==((void *)0)?"":delim);
  parts++;
 }
 putchar('\n');
 parts = parts_orig;
 str = join((char **) parts, ":");
 printf("Join: %s\n", str);
    free_parts(parts);
    free(str);
 return 0;
}

variable_types:
cstr
char *

variable_types:
parts
char **

variable_types:
str
char *

variable_types:
delim
char *


join

decompiled_code:
char *__fastcall join(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // r14
const char *v4; // r12
int v5; // er15
int v6; // ebp
const char **v7; // r13
const char *v8; // rdi
char *v9; // rax
char *v10; // rbp

v2 = a1;
if ( !a1 )
return 0LL;
v3 = a2;
v4 = *a1;
if ( !*a1 )
return 0LL;
v5 = 0;
if ( a2 )
v5 = strlen(a2);
v6 = -v5;
v7 = a1;
v8 = v4;
do
{
v6 += strlen(v8) + v5;
v8 = *++v7;
}
while ( *v7 );
v9 = (char *)malloc(v6 + 1);
v10 = v9;
if ( v9 )
{
*v9 = 0;
if ( !a2 )
v3 = "";
do
{
if ( v2[1] )
{
strcat(v10, v4);
strcat(v10, v3);
}
else
{
strcat(v10, v4);
}
v4 = *++v2;
}
while ( *v2 );
}
else
{
fwrite("join(): Error allocating memory", 1uLL, 0x1FuLL, stderr);
}
return v10;
}

canonical_decompiled_code:
char *__fastcall func8(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // r14
const char *v4; // r12
int v5; // er15
int v6; // ebp
const char **v7; // r13
const char *v8; // rdi
char *v9; // rax
char *v10; // rbp

v2 = a1;
if ( !a1 )
return 0LL;
v3 = a2;
v4 = *a1;
if ( !*a1 )
return 0LL;
v5 = 0;
if ( a2 )
v5 = strlen(a2);
v6 = -v5;
v7 = a1;
v8 = v4;
do
{
v6 += strlen(v8) + v5;
v8 = *++v7;
}
while ( *v7 );
v9 = (char *)malloc(v6 + 1);
v10 = v9;
if ( v9 )
{
*v9 = 0;
if ( !a2 )
v3 = "";
do
{
if ( v2[1] )
{
strcat(v10, v4);
strcat(v10, v3);
}
else
{
strcat(v10, v4);
}
v4 = *++v2;
}
while ( *v2 );
}
else
{
fwrite("join(): Error allocating memory", 1uLL, 0x1FuLL, stderr);
}
return v10;
}

original_code:
char* join(const char** parts, const char* delim) {
 const char** part;
 char* result = ((void *)0);
 int delim_len;
 int result_len;
 if ((((void *)0) == parts) || (((void *)0) == *parts)) {
  return ((void *)0);
 }
 if (((void *)0) == delim) {
  delim_len = 0;
 }
 else {
  delim_len = strlen(delim);
 }
 result_len = -delim_len;
 for (part = parts; ((void *)0) != *part; part++) {
  result_len += delim_len + strlen(*part);
 }
 result = (char*) malloc((result_len+1) * sizeof(char));
 if (((void *)0) == result) {
  fprintf(stderr, "join(): Error allocating memory");
  return ((void *)0);
 }
    result[0] = '\0';
 for (part = parts; ((void *)0) != *part; part++) {
  if (*(part+1) != ((void *)0)) {
   strcat(result, *part);
   strcat(result, (delim != ((void *)0))? delim : "");
  }
  else {
   strcat(result, *part);
  }
 }
 return result;
}

canonical_original_code:
char *join(char **parts, char *delim) {
 char **part;
 char *result = ((void *)0);
 int delim_len;
 int result_len;
 if ((((void *)0) == parts) || (((void *)0) == *parts)) {
  return ((void *)0);
 }
 if (((void *)0) == delim) {
  delim_len = 0;
 }
 else {
  delim_len = strlen(delim);
 }
 result_len = -delim_len;
 for (part = parts; ((void *)0) != *part; part++) {
  result_len += delim_len + strlen(*part);
 }
 result = (char *) malloc((result_len+1) * sizeof(char));
 if (((void *)0) == result) {
  fprintf(stderr, "join(): Error allocating memory");
  return ((void *)0);
 }
    result[0] = '\0';
 for (part = parts; ((void *)0) != *part; part++) {
  if (*(part+1) != ((void *)0)) {
   strcat(result, *part);
   strcat(result, (delim != ((void *)0))? delim : "");
  }
  else {
   strcat(result, *part);
  }
 }
 return result;
}

variable_types:
part
char **

variable_types:
result
char *

return_type: char *


decompiled_code:
void __fastcall free_parts(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)ptr;
do
{
free(v2);
v2 = *++v3;
}
while ( *v3 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)ptr;
do
{
free(v2);
v2 = *++v3;
}
while ( *v3 );
}
free(ptr);
}

original_code:
void free_parts(char** parts) {
    char** part;
    for (part = parts; ((void *)0) != *part; part++) {
        free(*part);
    }
    free(parts);
}

canonical_original_code:
void free_parts(char **parts) {
    char **part;
    for (part = parts; ((void *)0) != *part; part++) {
        free(*part);
    }
    free(parts);
}


stdInput

repo: quickdudley/lineargp

decompiled_code:
__int64 __fastcall stdInput(FILE *stream)
{
unsigned int v1; // ebx

v1 = getc(stream);
if ( feof(stream) )
v1 = -1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(FILE *stream)
{
unsigned int v1; // ebx

v1 = getc(stream);
if ( feof(stream) )
v1 = -1;
return v1;
}

original_code:
int stdInput(void *file)
{
 int r = getc((FILE *)file);
 if(!feof(file))
  return r;
 else
  return -1;
}

variable_types:
file
void *

variable_types: r int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
_DWORD *v4; // r12
int v5; // ebx
int result; // eax
__int64 v7; // [rsp+0h] [rbp-398h] BYREF
int v8; // [rsp+Ch] [rbp-38Ch] BYREF
__int64 v9[113]; // [rsp+10h] [rbp-388h] BYREF

if ( argc <= 1 )
{
fwrite("usage: runvm file [index]\n", 1uLL, 0x1AuLL, stderr);
result = 1;
}
else
{
v3 = open(argv[1], 0, envp);
v4 = (_DWORD *)load_genepool(v3);
close(v3);
v5 = 0;
if ( argc > 2 )
{
v5 = _isoc99_sscanf(argv[2], "%d", &v8);
if ( v5 )
{
v5 = v8;
if ( v8 <= 0 )
{
v5 = 0;
}
else if ( v8 >= *v4 )
{
v5 = 0;
}
}
}
init_environment(v9);
v9[0] = (__int64)stdInput;
v9[1] = (__int64)stdin;
v9[48] = (__int64)stdOutput;
v9[49] = (__int64)stdout;
v7 = 200000LL;
vmRun(*(_QWORD *)&v4[8 * v5 + 2], v9, &v7);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **args)
{
 if(argc < 2) {
  fprintf(stderr, "usage: runvm file [index]\n");
  return 1;
 }
 genepool *e;
 environment env;
 int fd;
 int ri = 0;
 int si;
 long long int steps;
 fd = open(args[1], 00);
 e = load_genepool(fd);
 close(fd);
 if(argc >= 3 && sscanf(args[2], "%d", &si) && si > 0 && si < e->num_candidates) {
  ri = si;
 }
 init_environment(&env);
 env.ii[0].source = stdInput;
 env.ii[0].context = stdin;
 env.oo[0].sink = stdOutput;
 env.oo[0].context = stdout;
 steps = 200000;
 vmRun(e->candidates[ri].genome, &env, &steps);
}

canonical_original_code:
int main(int argc, char **args)
{
 if(argc < 2) {
  fprintf(stderr, "usage: runvm file [index]\n");
  return 1;
 }
 struct _genepool *e;
 struct _environment env;
 int fd;
 int ri = 0;
 int si;
 long long steps;
 fd = open(args[1], 00);
 e = load_genepool(fd);
 close(fd);
 if(argc >= 3 && sscanf(args[2], "%d", &si) && si > 0 && si < e->num_candidates) {
  ri = si;
 }
 init_environment(&env);
 env.ii[0].source = stdInput;
 env.ii[0].context = stdin;
 env.oo[0].sink = stdOutput;
 env.oo[0].context = stdout;
 steps = 200000;
 vmRun(e->candidates[ri].genome, &env, &steps);
}

variable_types: argc int

variable_types:
args
char **

variable_types: struct _genepool { int num_candidates; int num_criteria; struct _candidate { struct _genome { struct _gene { int crossover_position; int execution_position; unsigned char instructions[16]; } first; struct _genome *next; struct _genome *prev; } *genome; int *evaluations; double dominated; int age; } candidates[]; } *

variable_types: struct _environment { struct _input { int (*source)(void *); void *context; int exhausted; } ii[16]; struct _output { int (*sink)(void *, int); void *context; int closed; } oo[16]; struct _heapPage { int base; struct _heapPage *next; struct _heapPage *prev; int data[1024]; } *heap; int rgs[16]; int s1; int s2; int fd; unsigned int pc; unsigned int pcn; }

variable_types: fd int

variable_types: ri int

variable_types: si int

variable_types:
steps
long long

user_defined_types: struct _environment { struct _input ii[16]; struct _output oo[16]; struct _heapPage *heap; int rgs[16]; int s1; int s2; int fd; unsigned int pc; unsigned int pcn; }

user_defined_types: struct _genepool { int num_candidates; int num_criteria; struct _candidate candidates[]; }

user_defined_types: struct _candidate { struct _genome *genome; int *evaluations; double dominated; int age; }

user_defined_types: struct _genome { struct _gene first; struct _genome *next; struct _genome *prev; }


bufferInput

decompiled_code:
__int64 __fastcall bufferInput(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx

v1 = *(_DWORD *)(a1 + 12);
if ( v1 >= *(_DWORD *)(a1 + 8) )
return (unsigned int)-1;
v2 = *(char *)(*(_QWORD *)a1 + v1);
*(_DWORD *)(a1 + 12) = v1 + 1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx

v1 = *(_DWORD *)(a1 + 12);
if ( v1 >= *(_DWORD *)(a1 + 8) )
return (unsigned int)-1;
v2 = *(char *)(*(_QWORD *)a1 + v1);
*(_DWORD *)(a1 + 12) = v1 + 1;
return v2;
}

original_code:
static int bufferInput(void *context)
{
 if(((struct buffercontext*)context)->pos >= ((struct buffercontext*)context)->length)
  return -1;
 int r = ((struct buffercontext*)context)->buffer[((struct buffercontext*)context)->pos];
 ((struct buffercontext*)context)->pos++;
 return r;
}

canonical_original_code:
static int bufferInput(void *context)
{
 if(((struct buffercontext *)context)->pos >= ((struct buffercontext *)context)->length)
  return -1;
 int r = ((struct buffercontext*)context)->buffer[((struct buffercontext*)context)->pos];
 ((struct buffercontext *)context)->pos++;
 return r;
}

variable_types:
context
void *

user_defined_types: struct buffercontext { char *buffer; int length; int pos; }


bufferOutput

decompiled_code:
_BOOL8 __fastcall bufferOutput(__int64 a1, int a2)
{
_BOOL8 result; // rax
int v3; // eax

result = 1LL;
if ( (a2 & 0xFFFFFF00) == 0 )
{
*(_BYTE *)(*(_QWORD *)a1 + *(int *)(a1 + 12)) = a2;
v3 = *(_DWORD *)(a1 + 12) + 1;
*(_DWORD *)(a1 + 12) = v3;
result = *(_DWORD *)(a1 + 8) == v3;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, int a2)
{
_BOOL8 result; // rax
int v3; // eax

result = 1LL;
if ( (a2 & 0xFFFFFF00) == 0 )
{
*(_BYTE *)(*(_QWORD *)a1 + *(int *)(a1 + 12)) = a2;
v3 = *(_DWORD *)(a1 + 12) + 1;
*(_DWORD *)(a1 + 12) = v3;
result = *(_DWORD *)(a1 + 8) == v3;
}
return result;
}

original_code:
static int bufferOutput(void *context, int value)
{
 if(value & (~0xff))
  return 1;
 ((struct buffercontext*)context)->buffer[((struct buffercontext*)context)->pos] = (char)value;
 ((struct buffercontext*)context)->pos++;
 return ((struct buffercontext*)context)->pos == ((struct buffercontext*)context)->length;
}

canonical_original_code:
static int bufferOutput(void *context, int value)
{
 if(value & (~0xff))
  return 1;
 ((struct buffercontext *)context)->buffer[((struct buffercontext *)context)->pos] = (char)value;
 ((struct buffercontext *)context)->pos++;
 return ((struct buffercontext *)context)->pos == ((struct buffercontext *)context)->length;
}

variable_types: value int


sigfpeHandler

decompiled_code:
void __fastcall sigfpeHandler(int a1)
{
if ( a1 == 8 )
longjmp(jmpdst, 1);
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
if ( a1 == 8 )
longjmp(jmpdst, 1);
}

original_code:
void sigfpeHandler(int signum) {
 if(signum == 8) {
  longjmp(jmpdst, 1);
 }
}

variable_types: signum int


getMem

original_code:
int * getMem(heapPage ** m, unsigned int address) {
 int block = address / 1024;
 int offset = address % 1024;
 while((*m)->prev != ((void *)0) && (*m)->prev->base >= block) {
  *m = (*m)->prev;
 }
 while((*m)->next != ((void *)0) && (*m)->next->base <= block) {
  *m = (*m)->next;
 }
 if((*m)->prev == ((void *)0) && (*m)->base > block) {
  (*m)->prev = (heapPage *)malloc(sizeof(heapPage));
  memset((*m)->prev, 0, sizeof(heapPage));
  (*m)->prev->next = (*m);
  (*m)->prev->base = block;
  (*m)->prev->prev = ((void *)0);
  (*m) = (*m)->prev;
 } else if((*m)->next == ((void *)0) && (*m)->base < block) {
  (*m)->next = (heapPage *)malloc(sizeof(heapPage));
  memset((*m)->next, 0, sizeof(heapPage));
  (*m)->next->prev = (*m);
  (*m)->next->base = block;
  (*m)->next->next = ((void *)0);
  (*m) = (*m)->next;
 } else if((*m)->base > block) {
  heapPage * n = (heapPage *)malloc(sizeof(heapPage));
  memset(n, 0, sizeof(heapPage));
  n->base = block;
  n->next = *m;
  n->prev = (*m)->prev;
  n->prev->next = n;
  (*m)->prev = n;
  (*m) = n;
 } else if((*m)->base < block) {
  heapPage * n = (heapPage *)malloc(sizeof(heapPage));
  memset(n, 0, sizeof(heapPage));
  n->base = block;
  n->prev = *m;
  n->next = (*m)->next;
  n->next->prev = n;
  (*m)->next = n;
  (*m) = n;
 }
 return &((*m)->data[offset]);
}

canonical_original_code:
int *getMem(struct _heapPage **m, unsigned int address) {
 int block = address / 1024;
 int offset = address % 1024;
 while((*m)->prev != ((void *)0) && (*m)->prev->base >= block) {
  *m = (*m)->prev;
 }
 while((*m)->next != ((void *)0) && (*m)->next->base <= block) {
  *m = (*m)->next;
 }
 if((*m)->prev == ((void *)0) && (*m)->base > block) {
  (*m)->prev = (struct _heapPage *)malloc(sizeof(heapPage));
  memset((*m)->prev, 0, sizeof(heapPage));
  (*m)->prev->next = (*m);
  (*m)->prev->base = block;
  (*m)->prev->prev = ((void *)0);
  (*m) = (*m)->prev;
 } else if((*m)->next == ((void *)0) && (*m)->base < block) {
  (*m)->next = (struct _heapPage *)malloc(sizeof(heapPage));
  memset((*m)->next, 0, sizeof(heapPage));
  (*m)->next->prev = (*m);
  (*m)->next->base = block;
  (*m)->next->next = ((void *)0);
  (*m) = (*m)->next;
 } else if((*m)->base > block) {
  struct _heapPage *n = (heapPage *)malloc(sizeof(heapPage));
  memset(n, 0, sizeof(heapPage));
  n->base = block;
  n->next = *m;
  n->prev = (*m)->prev;
  n->prev->next = n;
  (*m)->prev = n;
  (*m) = n;
 } else if((*m)->base < block) {
  struct _heapPage *n = (heapPage *)malloc(sizeof(heapPage));
  memset(n, 0, sizeof(heapPage));
  n->base = block;
  n->prev = *m;
  n->next = (*m)->next;
  n->next->prev = n;
  (*m)->next = n;
  (*m) = n;
 }
 return &((*m)->data[offset]);
}

variable_types: struct _heapPage { int base; struct _heapPage *next; struct _heapPage *prev; int data[1024]; } **

variable_types:
address
unsigned int

variable_types: block int

variable_types: offset int

return_type: int *


vmFetch

original_code:
unsigned char vmFetch(genome **g, unsigned int *pc) {
 int block = *pc / 16;
 while((*g)->prev != ((void *)0) && (*g)->prev->first.execution_position >= block) {
  *g = (*g)->prev;
 }
 while((*g)->next != ((void *)0) && (*g)->next->first.execution_position <= block) {
  *g = (*g)->next;
 }
 while((*g)->prev != ((void *)0) && (*g)->prev->first.execution_position == block) {
  *g = (*g)->prev;
 }
 if((*g)->first.execution_position > block) {
  *pc = (*g)->first.execution_position * 16;
  return (*g)->first.instructions[0];
 } else if((*g)->first.execution_position < block) {
  *pc = (0x7fffffff * 2U + 1U) - 1;
  return 0x0F;
 } else {
  int x = *pc % 16;
  return (*g)->first.instructions[x];
 }
}

canonical_original_code:
unsigned char vmFetch(struct _genome **g, unsigned int *pc) {
 int block = *pc / 16;
 while((*g)->prev != ((void *)0) && (*g)->prev->first.execution_position >= block) {
  *g = (*g)->prev;
 }
 while((*g)->next != ((void *)0) && (*g)->next->first.execution_position <= block) {
  *g = (*g)->next;
 }
 while((*g)->prev != ((void *)0) && (*g)->prev->first.execution_position == block) {
  *g = (*g)->prev;
 }
 if((*g)->first.execution_position > block) {
  *pc = (*g)->first.execution_position * 16;
  return (*g)->first.instructions[0];
 } else if((*g)->first.execution_position < block) {
  *pc = (0x7fffffff * 2U + 1U) - 1;
  return 0x0F;
 } else {
  int x = *pc % 16;
  return (*g)->first.instructions[x];
 }
}

variable_types: struct _genome { struct _gene { int crossover_position; int execution_position; unsigned char instructions[16]; } first; struct _genome *next; struct _genome *prev; } **

variable_types:
pc
unsigned int *

variable_types: x int

return_type: unsigned char


vmStep

original_code:
int vmStep(genome **g, environment *env) {
 unsigned char instruction;
 unsigned char h, l;
 instruction = vmFetch(g, &(env->pc));
 env->pcn = env->pc + 1;
 h = instruction & 0xF0;
 l = instruction & 0x0F;
 if(h == 0) {
  if(l == 0x0F) {
   return 1;
  }
  return 0;
 }
 else if(h == 0x10) {
  env->rgs[env->s1] <<= 4;
  env->rgs[env->s1] |= l;
  return 0;
 }
 else if(h == 0x20) {
  env->s1 = l;
  return 0;
 }
 else if(h == 0x30) {
  env->s2 = l;
  return 0;
 }
 else if(h == 0x40) {
  env->rgs[l] = 0;
  return 0;
 }
 else if(h == 0x50) {
  env->rgs[l] = *(getMem(&(env->heap), env->rgs[env->s1]));
  return 0;
 }
 else if(h == 0x60) {
  *(getMem(&(env->heap), env->rgs[env->s2])) = env->rgs[l];
  return 0;
 }
 else if(h == 0x70) {
  env->rgs[l] = env->rgs[env->s1];
  return 0;
 }
 else if(h == 0x80 || (h == 0x90 && env->rgs[env->s1] > env->rgs[env->s2])
     || (h == 0xA0 && env->rgs[env->s1] == env->rgs[env->s2])) {
  env->rgs[0x0F] = env->pcn;
  env->pcn = env->rgs[l];
  return 0;
 }
 else if(h == 0xB0) {
  env->rgs[env->s1] = env->rgs[l];
  return 0;
 }
 else if(h == 0xC0) {
  if(env->ii[env->fd].source != ((void *)0) && env->ii[env->fd].exhausted == 0) {
   env->rgs[l] = env->ii[env->fd].source(env->ii[env->fd].context);
   if(env->rgs[l] == -1) {
    env->ii[env->fd].exhausted = 1;
   }
   return 0;
  } else {
   env->rgs[l] = -1;
  }
 }
 else if(h == 0xD0) {
  if(env->oo[env->fd].sink != ((void *)0)) {
   if(!env->oo[env->fd].closed) {
    int rv = env->oo[env->fd].sink(env->oo[env->fd].context, env->rgs[l]);
    if(env->rgs[l] == -1) {
     env->oo[env->fd].closed = 1;
    }
    return rv;
   }
   return -2;
  }
 }
 else if(h == 0xE0) {
  env->fd = l;
  return 0;
 }
 else if(h == 0xF0) {
  signal(8, sigfpeHandler);
  if(!_setjmp (jmpdst)) {
   switch(l) {
   case 0x0:
    env->rgs[env->s1] = env->rgs[env->s1] + env->rgs[env->s2];
    break;
   case 0x1:
    env->rgs[env->s1] = env->rgs[env->s1] - env->rgs[env->s2];
    break;
   case 0x2:
    env->rgs[env->s1] = env->rgs[env->s1] * env->rgs[env->s2];
    break;
   case 0x3:
    if(env->rgs[env->s2] == 0) {
     env->rgs[env->s1] = 0;
     return -1;
    }
    else {
     env->rgs[env->s1] = env->rgs[env->s1] / env->rgs[env->s2];
    }
    break;
   case 0x4:
    if(env->rgs[env->s2] == 0) {
     env->rgs[env->s1] = 0;
     return -1;
    }
    else {
     env->rgs[env->s1] = env->rgs[env->s1] % env->rgs[env->s2];
    }
    break;
   case 0x5:
    env->rgs[env->s1] = ~(env->rgs[env->s2]);
    break;
   case 0x6:
    env->rgs[env->s1] = env->rgs[env->s1] & env->rgs[env->s2];
    break;
   case 0x7:
    env->rgs[env->s1] = env->rgs[env->s1] | env->rgs[env->s2];
    break;
   case 0x8:
    env->rgs[env->s1] = env->rgs[env->s1] << env->rgs[env->s2];
    break;
   case 0x9:
    env->rgs[env->s1] = env->rgs[env->s1] >> env->rgs[env->s2];
    break;
   case 0xA:
   case 0xC:
   case 0xE:
    env->rgs[env->s1] = 0;
    break;
   case 0xB:
   case 0xD:
    env->rgs[env->s1] = 1;
    break;
   case 0xF:
    env->rgs[env->s1] = 0xFFFFFFFF;
    break;
   }
   return 0;
  } else {
   env->rgs[env->s1] = 0;
   sigset_t sigs;
   sigemptyset (&sigs);
   sigaddset (&sigs, 8);
   sigprocmask (1, &sigs, ((void *)0));
  }
 }
 return -1;
}

canonical_original_code:
int vmStep(struct _genome **g, struct _environment *env) {
 unsigned char instruction;
 unsigned char h; unsigned char l;
 instruction = vmFetch(g, &(env->pc));
 env->pcn = env->pc + 1;
 h = instruction & 0xF0;
 l = instruction & 0x0F;
 if(h == 0) {
  if(l == 0x0F) {
   return 1;
  }
  return 0;
 }
 else if(h == 0x10) {
  env->rgs[env->s1] <<= 4;
  env->rgs[env->s1] |= l;
  return 0;
 }
 else if(h == 0x20) {
  env->s1 = l;
  return 0;
 }
 else if(h == 0x30) {
  env->s2 = l;
  return 0;
 }
 else if(h == 0x40) {
  env->rgs[l] = 0;
  return 0;
 }
 else if(h == 0x50) {
  env->rgs[l] = *(getMem(&(env->heap), env->rgs[env->s1]));
  return 0;
 }
 else if(h == 0x60) {
  *(getMem(&(env->heap), env->rgs[env->s2])) = env->rgs[l];
  return 0;
 }
 else if(h == 0x70) {
  env->rgs[l] = env->rgs[env->s1];
  return 0;
 }
 else if(h == 0x80 || (h == 0x90 && env->rgs[env->s1] > env->rgs[env->s2])
     || (h == 0xA0 && env->rgs[env->s1] == env->rgs[env->s2])) {
  env->rgs[0x0F] = env->pcn;
  env->pcn = env->rgs[l];
  return 0;
 }
 else if(h == 0xB0) {
  env->rgs[env->s1] = env->rgs[l];
  return 0;
 }
 else if(h == 0xC0) {
  if(env->ii[env->fd].source != ((void *)0) && env->ii[env->fd].exhausted == 0) {
   env->rgs[l] = env->ii[env->fd].source(env->ii[env->fd].context);
   if(env->rgs[l] == -1) {
    env->ii[env->fd].exhausted = 1;
   }
   return 0;
  } else {
   env->rgs[l] = -1;
  }
 }
 else if(h == 0xD0) {
  if(env->oo[env->fd].sink != ((void *)0)) {
   if(!env->oo[env->fd].closed) {
    int rv = env->oo[env->fd].sink(env->oo[env->fd].context, env->rgs[l]);
    if(env->rgs[l] == -1) {
     env->oo[env->fd].closed = 1;
    }
    return rv;
   }
   return -2;
  }
 }
 else if(h == 0xE0) {
  env->fd = l;
  return 0;
 }
 else if(h == 0xF0) {
  signal(8, sigfpeHandler);
  if(!_setjmp (jmpdst)) {
   switch(l) {
   case 0x0:
    env->rgs[env->s1] = env->rgs[env->s1] + env->rgs[env->s2];
    break;
   case 0x1:
    env->rgs[env->s1] = env->rgs[env->s1] - env->rgs[env->s2];
    break;
   case 0x2:
    env->rgs[env->s1] = env->rgs[env->s1] * env->rgs[env->s2];
    break;
   case 0x3:
    if(env->rgs[env->s2] == 0) {
     env->rgs[env->s1] = 0;
     return -1;
    }
    else {
     env->rgs[env->s1] = env->rgs[env->s1] / env->rgs[env->s2];
    }
    break;
   case 0x4:
    if(env->rgs[env->s2] == 0) {
     env->rgs[env->s1] = 0;
     return -1;
    }
    else {
     env->rgs[env->s1] = env->rgs[env->s1] % env->rgs[env->s2];
    }
    break;
   case 0x5:
    env->rgs[env->s1] = ~(env->rgs[env->s2]);
    break;
   case 0x6:
    env->rgs[env->s1] = env->rgs[env->s1] & env->rgs[env->s2];
    break;
   case 0x7:
    env->rgs[env->s1] = env->rgs[env->s1] | env->rgs[env->s2];
    break;
   case 0x8:
    env->rgs[env->s1] = env->rgs[env->s1] << env->rgs[env->s2];
    break;
   case 0x9:
    env->rgs[env->s1] = env->rgs[env->s1] >> env->rgs[env->s2];
    break;
   case 0xA:
   case 0xC:
   case 0xE:
    env->rgs[env->s1] = 0;
    break;
   case 0xB:
   case 0xD:
    env->rgs[env->s1] = 1;
    break;
   case 0xF:
    env->rgs[env->s1] = 0xFFFFFFFF;
    break;
   }
   return 0;
  } else {
   env->rgs[env->s1] = 0;
   struct __sigset_t sigs;
   sigemptyset (&sigs);
   sigaddset (&sigs, 8);
   sigprocmask (1, &sigs, ((void *)0));
  }
 }
 return -1;
}

variable_types: struct _environment { struct _input { int (*source)(void *); void *context; int exhausted; } ii[16]; struct _output { int (*sink)(void *, int); void *context; int closed; } oo[16]; struct _heapPage { int base; struct _heapPage *next; struct _heapPage *prev; int data[1024]; } *heap; int rgs[16]; int s1; int s2; int fd; unsigned int pc; unsigned int pcn; } *

variable_types:
instruction
unsigned char

variable_types:
h
unsigned char

variable_types:
l
unsigned char

variable_types: rv int

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

user_defined_types: struct _gene { int crossover_position; int execution_position; unsigned char instructions[16]; }


vmRun

original_code:
int vmRun(genome *g, environment *env, long long int *steps){
 int penalty = 0;
 long long int s = 0;
 sort_execute(g);
 while(s < *steps) {
  int result = vmStep(&g, env);
  env->pc = env->pcn;
  if(result > 0) {
   *steps = s;
   penalty += result - 1;
  } else {
   penalty -= result;
  }
  s++;
 }
 return penalty;
}

canonical_original_code:
int vmRun(struct _genome *g, struct _environment *env, long long *steps){
 int penalty = 0;
 long long s = 0;
 sort_execute(g);
 while(s < *steps) {
  int result = vmStep(&g, env);
  env->pc = env->pcn;
  if(result > 0) {
   *steps = s;
   penalty += result - 1;
  } else {
   penalty -= result;
  }
  s++;
 }
 return penalty;
}

variable_types: struct _genome { struct _gene { int crossover_position; int execution_position; unsigned char instructions[16]; } first; struct _genome *next; struct _genome *prev; } *

variable_types:
steps
long long *

variable_types: penalty int

variable_types:
s
long long

variable_types: result int

user_defined_types: struct _input { int (*source)(void *); void *context; int exhausted; }

user_defined_types: struct _output { int (*sink)(void *, int); void *context; int closed; }

user_defined_types: struct _heapPage { int base; struct _heapPage *next; struct _heapPage *prev; int data[1024]; }


decompiled_code:
__int64 __fastcall init_environment(_QWORD *a1)
{
void *v1; // rax
void *v2; // rdi
__int64 result; // rax

*a1 = 0LL;
a1[107] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 864) >> 3));
v1 = malloc(0x1018uLL);
a1[96] = v1;
v2 = v1;
result = 0LL;
memset(v2, 0, 0x1018uLL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
void *v1; // rax
void *v2; // rdi
__int64 result; // rax

*a1 = 0LL;
a1[107] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 864) >> 3));
v1 = malloc(0x1018uLL);
a1[96] = v1;
v2 = v1;
result = 0LL;
memset(v2, 0, 0x1018uLL);
return result;
}

original_code:
void init_environment(environment *env)
{
 memset(env, 0, sizeof(environment));
 env->heap = malloc(sizeof(heapPage));
 memset(env->heap, 0, sizeof(heapPage));
}

canonical_original_code:
void init_environment(struct _environment *env)
{
 memset(env, 0, sizeof(environment));
 env->heap = malloc(sizeof(heapPage));
 memset(env->heap, 0, sizeof(heapPage));
}


decompiled_code:
__int64 __fastcall delete_heap(void *ptr)
{
void *v1; // rbx
unsigned int v2; // ebp
void *v3; // rdi

do
{
v1 = ptr;
ptr = (void *)*((_QWORD *)ptr + 2);
}
while ( ptr );
v2 = 0;
do
{
v3 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v3);
++v2;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
void *v1; // rbx
unsigned int v2; // ebp
void *v3; // rdi

do
{
v1 = ptr;
ptr = (void *)*((_QWORD *)ptr + 2);
}
while ( ptr );
v2 = 0;
do
{
v3 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v3);
++v2;
}
while ( v1 );
return v2;
}

original_code:
int delete_heap(heapPage *heap)
{
 while(heap->prev != ((void *)0))
  heap = heap->prev;
 int r = 0;
 heapPage* n;
 while(heap != ((void *)0)) {
  n = heap->next;
  free(heap);
  heap = n;
  r++;
 }
 return r;
}

canonical_original_code:
int delete_heap(struct _heapPage *heap)
{
 while(heap->prev != ((void *)0))
  heap = heap->prev;
 int r = 0;
 struct _heapPage *n;
 while(heap != ((void *)0)) {
  n = heap->next;
  free(heap);
  heap = n;
  r++;
 }
 return r;
}

variable_types: struct _heapPage { int base; struct _heapPage *next; struct _heapPage *prev; int data[1024]; } *

variable_types: r int


original_code:
void eval_run(genome *g, evalset *eval)
{
 if(g == eval->last_genome)
  return;
 eval->last_genome = g;
 environment env;
 struct buffercontext inputbuffer;
 struct buffercontext outputbuffer;
 init_environment(&env);
 inputbuffer.pos = 0;
 inputbuffer.length = eval->input_len;
 inputbuffer.buffer = eval->input;
 outputbuffer.pos = 0;
 outputbuffer.length = (int)(eval->target_len * 1.75) + 1;
 outputbuffer.buffer = malloc(outputbuffer.length + 1);
 memset(outputbuffer.buffer, 0, outputbuffer.length + 1);
 env.ii[0].source = bufferInput;
 env.ii[0].context = &inputbuffer;
 env.oo[0].sink = bufferOutput;
 env.oo[0].context = &outputbuffer;
 eval->steps = maxsteps;
 eval->illegal = vmRun(g, &env, &(eval->steps));
 eval->heap_pages = delete_heap(env.heap);
 eval->manhattan_error = alignedlevenshtein(outputbuffer.buffer, outputbuffer.pos, eval->target, eval->target_len);
 eval->suffix_error = errorfreeprogress(outputbuffer.buffer, outputbuffer.pos, eval->target, eval->target_len);
 free(outputbuffer.buffer);
}

canonical_original_code:
void eval_run(struct _genome *g, struct _evalset *eval)
{
 if(g == eval->last_genome)
  return;
 eval->last_genome = g;
 struct _environment env;
 struct buffercontext inputbuffer;
 struct buffercontext outputbuffer;
 init_environment(&env);
 inputbuffer.pos = 0;
 inputbuffer.length = eval->input_len;
 inputbuffer.buffer = eval->input;
 outputbuffer.pos = 0;
 outputbuffer.length = (int)(eval->target_len * 1.75) + 1;
 outputbuffer.buffer = malloc(outputbuffer.length + 1);
 memset(outputbuffer.buffer, 0, outputbuffer.length + 1);
 env.ii[0].source = bufferInput;
 env.ii[0].context = &inputbuffer;
 env.oo[0].sink = bufferOutput;
 env.oo[0].context = &outputbuffer;
 eval->steps = maxsteps;
 eval->illegal = vmRun(g, &env, &(eval->steps));
 eval->heap_pages = delete_heap(env.heap);
 eval->manhattan_error = alignedlevenshtein(outputbuffer.buffer, outputbuffer.pos, eval->target, eval->target_len);
 eval->suffix_error = errorfreeprogress(outputbuffer.buffer, outputbuffer.pos, eval->target, eval->target_len);
 free(outputbuffer.buffer);
}

variable_types: struct _evalset { struct _genome *last_genome; int heap_pages; long long steps; int manhattan_error; int suffix_error; int illegal; char *target; int target_len; char *input; int input_len; } *

variable_types: struct _environment { struct _input { int (*source)(void *); void *context; int exhausted; } ii[16]; struct _output { int (*sink)(void *, int); void *context; int closed; } oo[16]; struct _heapPage { int base; struct _heapPage *next; struct _heapPage *prev; int data[1024]; } *heap; int rgs[16]; int s1; int s2; int fd; unsigned int pc; unsigned int pcn; }

variable_types: struct buffercontext { char *buffer; int length; int pos; }


decompiled_code:
__int64 __fastcall eval_runtime(__int64 a1, __int64 a2)
{
eval_run(a1, a2);
return *(_QWORD *)(a2 + 16);
}

original_code:
int eval_runtime(genome *g, evalset *eval)
{
 eval_run(g, eval);
 return eval->steps;
}

canonical_original_code:
int eval_runtime(struct _genome *g, struct _evalset *eval)
{
 eval_run(g, eval);
 return eval->steps;
}

user_defined_types: struct _evalset { struct _genome *last_genome; int heap_pages; long long steps; int manhattan_error; int suffix_error; int illegal; char *target; int target_len; char *input; int input_len; }


decompiled_code:
__int64 __fastcall eval_memory(__int64 a1, __int64 a2)
{
eval_run(a1, a2);
return *(unsigned int *)(a2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
func9(a1, a2);
return *(unsigned int *)(a2 + 8);
}

original_code:
int eval_memory(genome *g, evalset *eval)
{
 eval_run(g, eval);
 return eval->heap_pages;
}

canonical_original_code:
int eval_memory(struct _genome *g, struct _evalset *eval)
{
 eval_run(g, eval);
 return eval->heap_pages;
}


decompiled_code:
__int64 __fastcall eval_illegal(__int64 a1, __int64 a2)
{
eval_run(a1, a2);
return *(unsigned int *)(a2 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
func9(a1, a2);
return *(unsigned int *)(a2 + 32);
}

original_code:
int eval_illegal(genome *g, evalset *eval)
{
 eval_run(g, eval);
 return eval->illegal;
}

canonical_original_code:
int eval_illegal(struct _genome *g, struct _evalset *eval)
{
 eval_run(g, eval);
 return eval->illegal;
}


decompiled_code:
__int64 __fastcall eval_manhattan(__int64 a1, __int64 a2)
{
eval_run(a1, a2);
return *(unsigned int *)(a2 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
func9(a1, a2);
return *(unsigned int *)(a2 + 24);
}

original_code:
int eval_manhattan(genome *g, evalset *eval)
{
 eval_run(g, eval);
 return eval->manhattan_error;
}

canonical_original_code:
int eval_manhattan(struct _genome *g, struct _evalset *eval)
{
 eval_run(g, eval);
 return eval->manhattan_error;
}


decompiled_code:
__int64 __fastcall eval_suffix(__int64 a1, __int64 a2)
{
eval_run(a1, a2);
return *(unsigned int *)(a2 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
func9(a1, a2);
return *(unsigned int *)(a2 + 28);
}

original_code:
int eval_suffix(genome *g, evalset *eval)
{
 eval_run(g,eval);
 return eval->suffix_error;
}

canonical_original_code:
int eval_suffix(struct _genome *g, struct _evalset *eval)
{
 eval_run(g,eval);
 return eval->suffix_error;
}


bitwiseLevenshtein

original_code:
int bitwiseLevenshtein(char *a, size_t asize, char *b, size_t bsize)
{
 if(asize > bsize) {
  char *t = a;
  size_t tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
 }
 int width = asize * 8;
 int height = bsize * 8;
 if(width == 0) {
  return height;
 }
 int *m[2];
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(width * sizeof(int));
 }
 for(int y = 0; y < height; y++) {
  for(int x = 0; x < width; x++) {
   int od, ou, ol;
   int cost, p, c;
   od = y == 0 ? x : (x == 0 ? y : m[y & 1][x - 1]);
   ou = y == 0 ? x + 1 : m[y & 1][x];
   ol = x == 0 ? y + 1 : m[!(y & 1)][x - 1];
   cost = (((a[x / 8]) >> (8 - x % 8)) & 1) != (((b[y / 8]) >> (8 - y % 8)) & 1);
   p = od + cost;
   ou++;
   ol++;
   if(p > ou)
    p = ou;
   if(p > ol)
    p = ol;
   m[!(y & 1)][x] = p;
  }
 }
 width = m[height & 1][width - 1];
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 return width;
}

canonical_original_code:
int bitwiseLevenshtein(char *a, unsigned long asize, char *b, unsigned long bsize)
{
 if(asize > bsize) {
  char *t = a;
  unsigned long tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
 }
 int width = asize * 8;
 int height = bsize * 8;
 if(width == 0) {
  return height;
 }
 int *m[2];
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(width * sizeof(int));
 }
 for(int y = 0; y < height; y++) {
  for(int x = 0; x < width; x++) {
   int od; int ou; int ol;
   int cost; int p; int c;
   od = y == 0 ? x : (x == 0 ? y : m[y & 1][x - 1]);
   ou = y == 0 ? x + 1 : m[y & 1][x];
   ol = x == 0 ? y + 1 : m[!(y & 1)][x - 1];
   cost = (((a[x / 8]) >> (8 - x % 8)) & 1) != (((b[y / 8]) >> (8 - y % 8)) & 1);
   p = od + cost;
   ou++;
   ol++;
   if(p > ou)
    p = ou;
   if(p > ol)
    p = ol;
   m[!(y & 1)][x] = p;
  }
 }
 width = m[height & 1][width - 1];
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 return width;
}

variable_types:
a
char *

variable_types:
asize
unsigned long

variable_types:
b
char *

variable_types:
bsize
unsigned long

variable_types:
t
char *

variable_types:
tsize
unsigned long

variable_types: width int

variable_types: height int

variable_types:
m
int *[2]

variable_types: i int

variable_types: y int

variable_types: x int

variable_types: od int

variable_types: ou int

variable_types: ol int

variable_types: cost int

variable_types: p int

variable_types: c int


bytewiseLevenshtein

original_code:
int bytewiseLevenshtein(char *a, size_t asize, char *b, size_t bsize)
{
 if(asize > bsize) {
  char *t = a;
  size_t tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
 }
 if(asize == 0) {
  return bsize;
 }
 int *m[2];
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(asize * sizeof(int));
 }
 for(int y = 0; y < bsize; y++) {
  for(int x = 0; x < asize; x++) {
   int od, ou, ol;
   int cost, p, c;
   od = y == 0 ? x : (x == 0 ? y : m[y & 1][x - 1]);
   ou = y == 0 ? x + 1 : m[y & 1][x];
   ol = x == 0 ? y + 1 : m[!(y & 1)][x - 1];
   cost = a[x] != b[y];
   p = od + cost;
   ou += 1;
   ol += 1;
   if(p > ou)
    p = ou;
   if(p > ol)
    p = ol;
   m[!(y & 1)][x] = p;
  }
 }
 asize = m[bsize & 1][asize - 1];
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 if(asize <= 12) {
  int x = 0;
 }
 return asize;
}

canonical_original_code:
int bytewiseLevenshtein(char *a, unsigned long asize, char *b, unsigned long bsize)
{
 if(asize > bsize) {
  char *t = a;
  unsigned long tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
 }
 if(asize == 0) {
  return bsize;
 }
 int *m[2];
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(asize * sizeof(int));
 }
 for(int y = 0; y < bsize; y++) {
  for(int x = 0; x < asize; x++) {
   int od; int ou; int ol;
   int cost; int p; int c;
   od = y == 0 ? x : (x == 0 ? y : m[y & 1][x - 1]);
   ou = y == 0 ? x + 1 : m[y & 1][x];
   ol = x == 0 ? y + 1 : m[!(y & 1)][x - 1];
   cost = a[x] != b[y];
   p = od + cost;
   ou += 1;
   ol += 1;
   if(p > ou)
    p = ou;
   if(p > ol)
    p = ol;
   m[!(y & 1)][x] = p;
  }
 }
 asize = m[bsize & 1][asize - 1];
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 if(asize <= 12) {
  int x = 0;
 }
 return asize;
}

variable_types:
a
char *

variable_types:
asize
unsigned long


alignedlevenshtein

original_code:
int alignedlevenshtein(char *a, size_t asize, char *b, size_t bsize)
{
 if(asize > bsize) {
  char *t = a;
  size_t tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
 }
 if(asize == 0) {
  return bsize * 8;
 }
 int *m[2];
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(asize * sizeof(int));
 }
 for(int y = 0; y < bsize; y++) {
  for(int x = 0; x < asize; x++) {
   int od, ou, ol;
   int cost, p, c;
   od = y == 0 ? x * 8 : (x == 0 ? y * 8 : m[y & 1][x - 1]);
   ou = y == 0 ? (x + 1) * 8 : m[y & 1][x];
   ol = x == 0 ? (y + 1) * 8 : m[!(y & 1)][x - 1];
   cost = 0;
   for(int bit = 0x80; bit != 0; bit = bit >> 1) {
    if((a[x] & bit) != (b[y] & bit)) {
     cost += 1;
    }
   }
   p = od + cost;
   ou += 8;
   ol += 8;
   if(p > ou)
    p = ou;
   if(p > ol)
    p = ol;
   m[!(y & 1)][x] = p;
  }
 }
 asize = m[bsize & 1][asize - 1];
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 if(asize <= 12) {
  int x = 0;
 }
 return asize;
}

canonical_original_code:
int alignedlevenshtein(char *a, unsigned long asize, char *b, unsigned long bsize)
{
 if(asize > bsize) {
  char *t = a;
  unsigned long tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
 }
 if(asize == 0) {
  return bsize * 8;
 }
 int *m[2];
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(asize * sizeof(int));
 }
 for(int y = 0; y < bsize; y++) {
  for(int x = 0; x < asize; x++) {
   int od; int ou; int ol;
   int cost; int p; int c;
   od = y == 0 ? x * 8 : (x == 0 ? y * 8 : m[y & 1][x - 1]);
   ou = y == 0 ? (x + 1) * 8 : m[y & 1][x];
   ol = x == 0 ? (y + 1) * 8 : m[!(y & 1)][x - 1];
   cost = 0;
   for(int bit = 0x80; bit != 0; bit = bit >> 1) {
    if((a[x] & bit) != (b[y] & bit)) {
     cost += 1;
    }
   }
   p = od + cost;
   ou += 8;
   ol += 8;
   if(p > ou)
    p = ou;
   if(p > ol)
    p = ol;
   m[!(y & 1)][x] = p;
  }
 }
 asize = m[bsize & 1][asize - 1];
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 if(asize <= 12) {
  int x = 0;
 }
 return asize;
}

variable_types:
b
char *

variable_types:
bsize
unsigned long

variable_types: bit int


errorfreeprogress

decompiled_code:
__int64 __fastcall errorfreeprogress(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4)
{
int v6; // edx
unsigned __int64 v7; // rax
char v8; // di
char v9; // r8
unsigned __int64 v10; // rdi
char v12; // r8
unsigned __int8 v13; // al

v6 = 8 * a4;
if ( a4 && a2 )
{
v7 = 0LL;
while ( 1 )
{
v8 = *(_BYTE *)(a1 + v7);
v9 = *(_BYTE *)(a3 + v7);
if ( v8 != v9 )
break;
v6 -= 8;
++v7;
v10 = a2;
if ( a4 <= a2 )
v10 = a4;
if ( v7 >= v10 )
goto LABEL_8;
}
v12 = v9 ^ v8;
if ( v12 >= 0 )
{
--v6;
v13 = 64;
do
{
if ( ((unsigned __int8)v12 & v13) != 0 )
break;
--v6;
v13 >>= 1;
}
while ( v13 );
}
}
LABEL_8:
if ( v6 <= 0 && a4 < a2 )
v6 = 1;
return (unsigned int)v6;
}

original_code:
int errorfreeprogress(char *a, size_t asize, char *b, size_t bsize)
{
 int count = bsize * 8;
 for(int i = 0; i < asize && i < bsize; i++) {
  if(a[i] == b[i]) {
   count -= 8;
  }
  else {
   for(unsigned char j = 0x80; j != 0; j = j >> 1) {
    if((a[i] & j) == (b[i] & j))
     count -= 1;
    else {
     break;
    }
   }
   break;
  }
 }
 if(count <= 0 && asize > bsize) {
  count = 1;
 }
 return count;
}

canonical_original_code:
int errorfreeprogress(char *a, unsigned long asize, char *b, unsigned long bsize)
{
 int count = bsize * 8;
 for(int i = 0; i < asize && i < bsize; i++) {
  if(a[i] == b[i]) {
   count -= 8;
  }
  else {
   for(unsigned char j = 0x80; j != 0; j = j >> 1) {
    if((a[i] & j) == (b[i] & j))
     count -= 1;
    else {
     break;
    }
   }
   break;
  }
 }
 if(count <= 0 && asize > bsize) {
  count = 1;
 }
 return count;
}

variable_types: count int

variable_types:
j
unsigned char


gcsDifference

original_code:
int gcsDifference(char *a, size_t asize, char *b, size_t bsize)
{
 int swapped = 0;
 if(asize > bsize) {
  char *t = a;
  size_t tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
  swapped = 1;
 }
 int width = asize * 8;
 int height = bsize * 8;
 if(width == 0) {
  return swapped ? 0 : height;
 }
 int *m[2];
 int gcs = 0;
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(width * sizeof(int));
 }
 for(int y = 0; y < height; y++) {
  for(int x = 0; x < width; x++) {
   int od;
   od = y == 0 ? 0 : (x == 0 ? 0 : m[y & 1][x - 1]);
   if((((a[x / 8]) >> (8 - x % 8)) & 1) == (((b[y / 8]) >> (8 - y % 8)) & 1)) {
    m[!(y & 1)][x] = od + 1;
   }
   else {
    m[!(y & 1)][x] = 0;
   }
   if(m[!(y & 1)][x] > gcs){
    gcs = m[!(y & 1)][x];
   }
  }
 }
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 return (swapped ? width : height) - gcs;
}

canonical_original_code:
int gcsDifference(char *a, unsigned long asize, char *b, unsigned long bsize)
{
 int swapped = 0;
 if(asize > bsize) {
  char *t = a;
  unsigned long tsize = asize;
  a = b;
  asize = bsize;
  b = t;
  bsize = tsize;
  swapped = 1;
 }
 int width = asize * 8;
 int height = bsize * 8;
 if(width == 0) {
  return swapped ? 0 : height;
 }
 int *m[2];
 int gcs = 0;
 for(int i = 0; i < 2; i++) {
  m[i] = malloc(width * sizeof(int));
 }
 for(int y = 0; y < height; y++) {
  for(int x = 0; x < width; x++) {
   int od;
   od = y == 0 ? 0 : (x == 0 ? 0 : m[y & 1][x - 1]);
   if((((a[x / 8]) >> (8 - x % 8)) & 1) == (((b[y / 8]) >> (8 - y % 8)) & 1)) {
    m[!(y & 1)][x] = od + 1;
   }
   else {
    m[!(y & 1)][x] = 0;
   }
   if(m[!(y & 1)][x] > gcs){
    gcs = m[!(y & 1)][x];
   }
  }
 }
 for(int i = 0; i < 2; i++) {
  free(m[i]);
 }
 return (swapped ? width : height) - gcs;
}

variable_types: swapped int

variable_types:
t
char *

variable_types:
tsize
unsigned long

variable_types: width int

variable_types: height int

variable_types:
m
int *[2]

variable_types: gcs int


manhattanDifference

original_code:
int manhattanDifference(char *a, size_t asize, char *b, size_t bsize)
{
 size_t l = asize > bsize ? asize : bsize;
 size_t s = asize < bsize ? asize : bsize;
 int total = 0;
 for(int i = 0; i < s; i++) {
  for(unsigned char j = 0x80; j != 0; j = j >> 1) {
   if((a[i] & j) == (b[i] & j)) {
    total++;
   }
  }
 }
 return l * 8 - total;
}

canonical_original_code:
int manhattanDifference(char *a, unsigned long asize, char *b, unsigned long bsize)
{
 unsigned long l = asize > bsize ? asize : bsize;
 unsigned long s = asize < bsize ? asize : bsize;
 int total = 0;
 for(int i = 0; i < s; i++) {
  for(unsigned char j = 0x80; j != 0; j = j >> 1) {
   if((a[i] & j) == (b[i] & j)) {
    total++;
   }
  }
 }
 return l * 8 - total;
}

variable_types:
l
unsigned long

variable_types:
s
unsigned long

variable_types: total int

variable_types: i int


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

Tabelle_intern = (__int64)malloc(8LL * a2);
if ( !Tabelle_intern )
{
fwrite("Fehler beim Allokieren der Tabelle\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
if ( a2 > 0 )
{
v2 = 0LL;
do
{
v3 = (_QWORD *)(Tabelle_intern + v2);
v4 = malloc(16LL * a1);
*v3 = v4;
if ( !v4 )
{
fwrite("Fehler beim Allokieren der Tabelle\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v2 += 8LL;
}
while ( v2 != 8LL * (unsigned int)a2 );
}
return 0LL;
}

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

Tabelle_intern = (__int64)malloc(8LL * a2);
if ( !Tabelle_intern )
{
fwrite("Fehler beim Allokieren der Tabelle\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
if ( a2 > 0 )
{
v2 = 0LL;
do
{
v3 = (_QWORD *)(Tabelle_intern + v2);
v4 = malloc(16LL * a1);
*v3 = v4;
if ( !v4 )
{
fwrite("Fehler beim Allokieren der Tabelle\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v2 += 8LL;
}
while ( v2 != 8LL * (unsigned int)a2 );
}
return 0LL;
}

original_code:
int malloc_Tabelle(int Anzahl_Zeichen, int Anzahl_Zustaende)
{
 int i;
 if(!(Tabelle_intern = malloc(Anzahl_Zustaende * sizeof(struct Tabelle_Eintrag*))))
 {
  fprintf(stderr,"Fehler beim Allokieren der Tabelle\n");
  exit(1);
 }
 for(i = 0; i < Anzahl_Zustaende; i++)
  if(!(Tabelle_intern[i] = malloc(Anzahl_Zeichen * sizeof(struct Tabelle_Eintrag))))
  {
   fprintf(stderr,"Fehler beim Allokieren der Tabelle\n");
   exit(1);
  }
 return 0;
}

canonical_original_code:
int malloc_Tabelle(int Anzahl_Zeichen, int Anzahl_Zustaende)
{
 int i;
 if(!(Tabelle_intern = malloc(Anzahl_Zustaende * sizeof(struct Tabelle_Eintrag *))))
 {
  fprintf(stderr,"Fehler beim Allokieren der Tabelle\n");
  exit(1);
 }
 for(i = 0; i < Anzahl_Zustaende; i++)
  if(!(Tabelle_intern[i] = malloc(Anzahl_Zeichen * sizeof(struct Tabelle_Eintrag))))
  {
   fprintf(stderr,"Fehler beim Allokieren der Tabelle\n");
   exit(1);
  }
 return 0;
}

user_defined_types: struct Tabelle_Eintrag { int Folgezustand; void (*Funktion)(int Zustand, char *Eingabe); }


Aktion

decompiled_code:
int __fastcall Aktion(unsigned int a1, const char *a2)
{
return printf("(Zustand %i) ---%s-->\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, const char *a2)
{
return printf("(Zustand %i) ---%s-->\n", a1, a2);
}

original_code:
void Aktion(int Zustand, char *Zeichen)
{
 printf("(Zustand %i) ---%s-->\n",Zustand, Zeichen);
}

variable_types: Zustand int

variable_types:
Zeichen
char *


Fehler

decompiled_code:
void __fastcall __noreturn Fehler(unsigned int a1, const char *a2)
{
if ( a2 )
fprintf(stderr, "Fehler: (Zustand %i), Zeichen '%s'. beende...\n", a1, a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(unsigned int a1, const char *a2)
{
if ( a2 )
fprintf(stderr, "Fehler: (Zustand %i), Zeichen '%s'. beende...\n", a1, a2);
exit(1);
}

original_code:
void Fehler(int Zustand, char *Zeichen)
{
 if(Zeichen != ((void *)0))
  fprintf(stderr,"Fehler: (Zustand %i), Zeichen '%s'. beende...\n", Zustand, Zeichen);
 exit(1);
}


ok

decompiled_code:
int __fastcall ok(unsigned int a1)
{
return printf("(Endzustand %i), Zeichenkette korrekt!\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
return printf("(Endzustand %i), Zeichenkette korrekt!\n", a1);
}

original_code:
void ok(int Zustand)
{
 printf("(Endzustand %i), Zeichenkette korrekt!\n", Zustand);
}


decompiled_code:
_BYTE *lesen_eingabe()
{
_BYTE *v0; // rbx
char v2; // al

if ( zeicheneingabe )
{
v0 = malloc(2uLL);
v2 = getchar();
*v0 = v2;
if ( v2 == 10 )
v0 = 0LL;
else
v0[1] = 0;
}
else
{
v0 = malloc(0x100uLL);
if ( (unsigned int)_isoc99_scanf("%s", v0) == -1 )
v0 = 0LL;
}
return v0;
}

canonical_decompiled_code:
_BYTE *func4()
{
_BYTE *v0; // rbx
char v2; // al

if ( zeicheneingabe )
{
v0 = malloc(2uLL);
v2 = getchar();
*v0 = v2;
if ( v2 == 10 )
v0 = 0LL;
else
v0[1] = 0;
}
else
{
v0 = malloc(0x100uLL);
if ( (unsigned int)_isoc99_scanf("%s", v0) == -1 )
v0 = 0LL;
}
return v0;
}

original_code:
char* lesen_eingabe(void)
{
 char *tmp;
 if(zeicheneingabe == 0)
 {
  tmp = (char *) malloc(sizeof(char)*256);
  if(scanf("%s",tmp) == (-1))
   return ((void *)0);
 }
 else
 {
  tmp = (char *) malloc(sizeof(char)*2);
  tmp[0] = getchar();
  if(tmp[0] == '\n')
   return ((void *)0);
  tmp[1] = '\0';
 }
 return tmp;
}

canonical_original_code:
char *lesen_eingabe()
{
 char *tmp;
 if(zeicheneingabe == 0)
 {
  tmp = (char *) malloc(sizeof(char)*256);
  if(scanf("%s",tmp) == (-1))
   return ((void *)0);
 }
 else
 {
  tmp = (char *) malloc(sizeof(char)*2);
  tmp[0] = getchar();
  if(tmp[0] == '\n')
   return ((void *)0);
  tmp[1] = '\0';
 }
 return tmp;
}

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall eingabe_ok(char *s2)
{
const char **v1; // rbx
__int64 result; // rax
int v3; // eax

v1 = (const char **)woerter;
if ( woerter )
{
while ( 1 )
{
while ( 1 )
{
v3 = strncmp(v1[1], s2, 0x100uLL);
if ( v3 >= 0 )
break;
v1 = (const char **)v1[2];
if ( !v1 )
goto LABEL_2;
}
if ( v3 <= 0 )
break;
v1 = (const char **)v1[3];
if ( !v1 )
goto LABEL_2;
}
result = *(unsigned int *)v1;
}
else
{
LABEL_2:
fprintf(stderr, "Wort '%s' nicht im Alphabet!\n", s2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
const char **v1; // rbx
__int64 result; // rax
int v3; // eax

v1 = (const char **)woerter;
if ( woerter )
{
while ( 1 )
{
while ( 1 )
{
v3 = strncmp(v1[1], s2, 0x100uLL);
if ( v3 >= 0 )
break;
v1 = (const char **)v1[2];
if ( !v1 )
goto LABEL_2;
}
if ( v3 <= 0 )
break;
v1 = (const char **)v1[3];
if ( !v1 )
goto LABEL_2;
}
result = *(unsigned int *)v1;
}
else
{
LABEL_2:
fprintf(stderr, "Wort '%s' nicht im Alphabet!\n", s2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int eingabe_ok(char *id)
{
 struct alphabaum *tmp;
 tmp = woerter;
 while(tmp != ((void *)0))
 {
  if(strncmp(tmp->id,id,256) < 0)
  {
   if(tmp->links != ((void *)0))
   {
    tmp = tmp->links;
    continue;
   }
   else
   {
    fprintf(stderr,"Wort '%s' nicht im Alphabet!\n", id);
    return -1;
   }
  }
  else if(strncmp(tmp->id,id,256) > 0)
  {
   if(tmp->rechts != ((void *)0))
   {
    tmp = tmp->rechts;
    continue;
   }
   else
   {
    fprintf(stderr,"Wort '%s' nicht im Alphabet!\n", id);
    return -1;
   }
  }
  else
   return tmp->idx;
 }
 fprintf(stderr,"Wort '%s' nicht im Alphabet!\n", id);
 return -1;
}

variable_types:
id
char *

variable_types: struct alphabaum { int idx; char *id; struct alphabaum *links; struct alphabaum *rechts; } *