decompiled_code:
__int64 __fastcall serpent_round(__int64 a1, int a2, int *a3)
{
__int64 i; // rax
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rdi
unsigned int v8; // edx
unsigned int v9; // eax
__int64 v10; // rdi
__int64 result; // rax
int v12[6]; // [rsp+0h] [rbp-18h] BYREF

for ( i = 0LL; i != 4; ++i )
v12[i] = *(_DWORD *)(a1 + 16LL * a2 + i * 4) ^ a3[i];
sbox_apply(a2 % 8, v12, a3);
*a3 = rotl((unsigned int)*a3, 13LL);
v5 = rotl((unsigned int)a3[2], 3LL);
a3[2] = v5;
v6 = *a3;
v7 = v5 ^ a3[1] ^ *a3;
a3[1] = v7;
a3[3] ^= v5 ^ (8 * v6);
a3[1] = rotl(v7, 1LL);
v8 = rotl((unsigned int)a3[3], 7LL);
a3[3] = v8;
v9 = a3[1];
v10 = v8 ^ *a3 ^ v9;
*a3 = v10;
a3[2] ^= v8 ^ (v9 << 7);
*a3 = rotl(v10, 5LL);
result = rotl((unsigned int)a3[2], 22LL);
a3[2] = result;
return result;
}

original_code:
static void
serpent_round(const sosemanuk_master_state *master, int idx, uint32_t *data)
{
  int i;
  uint32_t tmp[4];
  for(i = 0; i < 4; ++i)
    tmp[i] = data[i] ^ master->k[idx*4 + i];
  sbox_apply(idx % 8, tmp, data);
  data[0] = rotl(data[0], 13);
  data[2] = rotl(data[2], 3);
  data[1] = data[1] ^ data[0] ^ data[2];
  data[3] = data[3] ^ data[2] ^ (data[0] << 3);
  data[1] = rotl(data[1], 1);
  data[3] = rotl(data[3], 7);
  data[0] = data[0] ^ data[1] ^ data[3];
  data[2] = data[2] ^ data[3] ^ (data[1] << 7);
  data[0] = rotl(data[0], 5);
  data[2] = rotl(data[2], 22);
}

canonical_original_code:
static void serpent_round(struct sosemanuk_master_state *master, int idx, unsigned int *data)
{
  int i;
  unsigned int tmp[4];
  for(i = 0; i < 4; ++i)
    tmp[i] = data[i] ^ master->k[idx*4 + i];
  sbox_apply(idx % 8, tmp, data);
  data[0] = rotl(data[0], 13);
  data[2] = rotl(data[2], 3);
  data[1] = data[1] ^ data[0] ^ data[2];
  data[3] = data[3] ^ data[2] ^ (data[0] << 3);
  data[1] = rotl(data[1], 1);
  data[3] = rotl(data[3], 7);
  data[0] = data[0] ^ data[1] ^ data[3];
  data[2] = data[2] ^ data[3] ^ (data[1] << 7);
  data[0] = rotl(data[0], 5);
  data[2] = rotl(data[2], 22);
}

variable_types: struct sosemanuk_master_state { unsigned int k[100]; } *

variable_types: idx int

variable_types:
data
unsigned int *

variable_types: i int

variable_types:
tmp
unsigned int [4]


repo: lvella/libestream

canonical_original_code:
static unsigned int automaton_step(struct sosemanuk_state *state)
{
  unsigned int *r = state->r;
  unsigned int *s = state->s;
  unsigned int r0_prev = r[0];
  unsigned char t = state->t;
  r[0] = r[1] + ((r0_prev & 1u) ? s[(t+1)%10] ^ s[(t+8)%10] : s[(t+1)%10]);
  r[1] = rotl(r0_prev * 0x54655307, 7);
  return (s[(t+9)%10] + r[0]) ^ r[1];
}

variable_types: struct sosemanuk_state { unsigned int r[2]; unsigned int s[10]; unsigned char t; } *

variable_types:
r
unsigned int *

variable_types:
s
unsigned int *

variable_types:
t
unsigned char

return_type: unsigned int


original_code:
void
sosemanuk_init_key(sosemanuk_master_state *state,
     const uint8_t *key, size_t bitlength)
{
  uint32_t w[108];
  uint32_t i;
  int fullwords = bitlength / 32;
  for(i = 0; i < fullwords; ++i)
    w[i] = pack_littleendian(&key[i*4]);
  int partial = bitlength % 32;
  if(partial)
    {
      uint32_t tmp = 0;
      int j;
      int fullbytes = partial / 8;
      for(j = 0; j < fullbytes; ++j)
 tmp |= (uint32_t)key[i*4 + j] << (j*8);
      int bitpartial = partial % 8;
      if(bitpartial)
 {
   uint8_t extra_bit = 1u << bitpartial;
   tmp |= (uint32_t)((key[i*4 + j] & (extra_bit - 1)) | extra_bit)
     << (j*8);
 }
      else
 {
   tmp |= 1u << partial;
 }
      w[i++] = tmp;
    }
  else if(bitlength < 256)
    w[i++] = 1u;
  for(; i < 8; ++i)
    w[i] = 0;
  for(; i < 108; ++i)
    w[i] = rotl(w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ 0x9e3779b9u ^ (i-8),
  11);
  for(i = 0; i < 8; ++i)
    {
      uint8_t sbox_idx = 7 - (i+4) % 8;
      int j;
      for(j = i; j < 25; j += 8)
 sbox_apply(sbox_idx, &w[8 + j*4], &state->k[j*4]);
    }
}

canonical_original_code:
void sosemanuk_init_key(struct sosemanuk_master_state *state, unsigned char *key, unsigned long bitlength)
{
  unsigned int w[108];
  unsigned int i;
  int fullwords = bitlength / 32;
  for(i = 0; i < fullwords; ++i)
    w[i] = pack_littleendian(&key[i*4]);
  int partial = bitlength % 32;
  if(partial)
    {
      unsigned int tmp = 0;
      int j;
      int fullbytes = partial / 8;
      for(j = 0; j < fullbytes; ++j)
 tmp |= (unsigned int)key[i*4 + j] << (j*8);
      int bitpartial = partial % 8;
      if(bitpartial)
 {
   unsigned char extra_bit = 1u << bitpartial;
   tmp |= (unsigned int)((key[i*4 + j] & (extra_bit - 1)) | extra_bit)
     << (j*8);
 }
      else
 {
   tmp |= 1u << partial;
 }
      w[i++] = tmp;
    }
  else if(bitlength < 256)
    w[i++] = 1u;
  for(; i < 8; ++i)
    w[i] = 0;
  for(; i < 108; ++i)
    w[i] = rotl(w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ 0x9e3779b9u ^ (i-8),
  11);
  for(i = 0; i < 8; ++i)
    {
      unsigned char sbox_idx = 7 - (i+4) % 8;
      int j;
      for(j = i; j < 25; j += 8)
 sbox_apply(sbox_idx, &w[8 + j*4], &state->k[j*4]);
    }
}

variable_types:
key
unsigned char *

variable_types:
bitlength
unsigned long

variable_types:
w
unsigned int [108]

variable_types:
i
unsigned int

variable_types: fullwords int

variable_types: partial int

variable_types:
tmp
unsigned int

variable_types: j int

variable_types: fullbytes int

variable_types: bitpartial int

return_type: void

user_defined_types: struct sosemanuk_master_state { unsigned int k[100]; }


original_code:
void
sosemanuk_init_iv(sosemanuk_state *iv_state,
    const sosemanuk_master_state *master,
    const uint8_t *iv)
{
  int i;
  uint32_t *s = iv_state->s;
  uint32_t *r = iv_state->r;
  iv_state->t = 0;
  uint32_t data[4];
  for(i = 0; i < 4; ++i)
    data[i] = pack_littleendian(&iv[i*4]);
  for(i = 0; i < 12; ++i)
    serpent_round(master, i, data);
  s[9] = data[0];
  s[8] = data[1];
  s[7] = data[2];
  s[6] = data[3];
  for(; i < 18; ++i)
    serpent_round(master, i, data);
  r[0] = data[0];
  r[1] = data[2];
  s[5] = data[3];
  s[4] = data[1];
  for(; i < 24; ++i)
    serpent_round(master, i, data);
  const uint32_t *sk = master->k;
  s[3] = data[0] ^ sk[96];
  s[2] = data[1] ^ sk[97];
  s[1] = data[2] ^ sk[98];
  s[0] = data[3] ^ sk[99];
}

canonical_original_code:
void sosemanuk_init_iv(struct sosemanuk_state *iv_state, struct sosemanuk_master_state *master, unsigned char *iv)
{
  int i;
  unsigned int *s = iv_state->s;
  unsigned int *r = iv_state->r;
  iv_state->t = 0;
  unsigned int data[4];
  for(i = 0; i < 4; ++i)
    data[i] = pack_littleendian(&iv[i*4]);
  for(i = 0; i < 12; ++i)
    serpent_round(master, i, data);
  s[9] = data[0];
  s[8] = data[1];
  s[7] = data[2];
  s[6] = data[3];
  for(; i < 18; ++i)
    serpent_round(master, i, data);
  r[0] = data[0];
  r[1] = data[2];
  s[5] = data[3];
  s[4] = data[1];
  for(; i < 24; ++i)
    serpent_round(master, i, data);
  unsigned int *sk = master->k;
  s[3] = data[0] ^ sk[96];
  s[2] = data[1] ^ sk[97];
  s[1] = data[2] ^ sk[98];
  s[0] = data[3] ^ sk[99];
}

variable_types: struct sosemanuk_master_state { unsigned int k[100]; } *

variable_types:
iv
unsigned char *

variable_types:
data
unsigned int [4]

variable_types:
sk
unsigned int *

user_defined_types: struct sosemanuk_state { unsigned int r[2]; unsigned int s[10]; unsigned char t; }


decompiled_code:
__int64 __fastcall sosemanuk_extract(int *a1, int *a2)
{
int *v2; // rbx
__int64 i; // rbp
int *v4; // rbp
__int64 result; // rax
int v6[4]; // [rsp+0h] [rbp-38h] BYREF
int v7[10]; // [rsp+10h] [rbp-28h] BYREF

v2 = a2;
for ( i = 0LL; i != 4; ++i )
{
v7[i] = automaton_step(a1);
v6[i] = lfsr_step((__int64)a1);
}
sbox_apply(2, v7, a2);
v4 = v6;
do
{
result = unpack_littleendian(*v4 ^ (unsigned int)*v2, v2);
++v2;
++v4;
}
while ( v4 != v7 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, int *a2)
{
int *v2; // rbx
__int64 i; // rbp
int *v4; // rbp
__int64 result; // rax
int v6[4]; // [rsp+0h] [rbp-38h] BYREF
int v7[10]; // [rsp+10h] [rbp-28h] BYREF

v2 = a2;
for ( i = 0LL; i != 4; ++i )
{
v7[i] = func3(a1);
v6[i] = func0((__int64)a1);
}
func1(2, v7, a2);
v4 = v6;
do
{
result = unpack_littleendian(*v4 ^ (unsigned int)*v2, v2);
++v2;
++v4;
}
while ( v4 != v7 );
return result;
}

original_code:
void
sosemanuk_extract(sosemanuk_state *state, uint8_t *stream)
{
  uint32_t f[4];
  uint32_t s[4];
  int i;
  for(i = 0; i < 4; ++i)
    {
      f[i] = automaton_step(state);
      s[i] = lfsr_step(state);
    }
  uint32_t *stream32 = (uint32_t*)stream;
  sbox_apply(2, f, stream32);
  for(i = 0; i < 4; ++i)
    {
      register uint32_t tmp = stream32[i] ^ s[i];
      unpack_littleendian(tmp, &stream[i*4]);
    }
}

canonical_original_code:
void sosemanuk_extract(struct sosemanuk_state *state, unsigned char *stream)
{
  unsigned int f[4];
  unsigned int s[4];
  int i;
  for(i = 0; i < 4; ++i)
    {
      f[i] = automaton_step(state);
      s[i] = lfsr_step(state);
    }
  unsigned int *stream32 = (uint32_t*)stream;
  sbox_apply(2, f, stream32);
  for(i = 0; i < 4; ++i)
    {
      register unsigned int tmp = stream32[i] ^ s[i];
      unpack_littleendian(tmp, &stream[i*4]);
    }
}

variable_types: struct sosemanuk_state { unsigned int r[2]; unsigned int s[10]; unsigned char t; } *

variable_types:
stream
unsigned char *

variable_types:
f
unsigned int [4]

variable_types:
s
unsigned int [4]

variable_types: i int


g

decompiled_code:
unsigned __int64 __fastcall g(int a1, int a2)
{
return (((unsigned int)(a1 + a2) * (unsigned __int64)(unsigned int)(a1 + a2)) >> 32) ^ (unsigned int)((a1 + a2) * (a1 + a2));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, int a2)
{
return (((unsigned int)(a1 + a2) * (unsigned __int64)(unsigned int)(a1 + a2)) >> 32) ^ (unsigned int)((a1 + a2) * (a1 + a2));
}

original_code:
static uint32_t
g(uint32_t u, uint32_t v)
{
  uint64_t square = (uint64_t)(u+v) * (uint64_t)(u+v);
  return (square >> 32) ^ square;
}

canonical_original_code:
static unsigned int g(unsigned int u, unsigned int v)
{
  unsigned long square = (uint64_t)(u+v) * (uint64_t)(u+v);
  return (square >> 32) ^ square;
}

variable_types:
u
unsigned int

variable_types:
v
unsigned int

variable_types:
square
unsigned long


decompiled_code:
__int64 __fastcall cat8(int a1, unsigned __int8 a2)
{
return (a1 << 8) | (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned __int8 a2)
{
return (a1 << 8) | (unsigned int)a2;
}

original_code:
static uint16_t
cat8(uint8_t a, uint8_t b)
{
  return ((uint16_t)a << 8) | b;
}

canonical_original_code:
static unsigned short cat8(unsigned char a, unsigned char b)
{
  return ((unsigned short)a << 8) | b;
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

return_type: unsigned short


decompiled_code:
__int64 __fastcall cat16(int a1, unsigned __int16 a2)
{
return (a1 << 16) | (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, unsigned __int16 a2)
{
return (a1 << 16) | (unsigned int)a2;
}

original_code:
static uint32_t
cat16(uint16_t a, uint16_t b)
{
  return ((uint32_t)a << 16) | b;
}

canonical_original_code:
static unsigned int cat16(unsigned short a, unsigned short b)
{
  return ((unsigned int)a << 16) | b;
}

variable_types:
a
unsigned short

variable_types:
b
unsigned short


decompiled_code:
__int64 __fastcall m512(__int16 a1)
{
return a1 & 0x1FF;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1)
{
return a1 & 0x1FF;
}

original_code:
static unsigned int
m512(unsigned int x)
{
  static const unsigned int mask = 0x1ff;
  return x & mask;
}

canonical_original_code:
static unsigned int m512(unsigned int x)
{
  static unsigned int mask = 0x1ff;
  return x & mask;
}

variable_types:
x
unsigned int

variable_types:
mask
unsigned int


h

decompiled_code:
__int64 __fastcall h(__int64 a1, int a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 4LL * (unsigned __int8)a2) + *(_DWORD *)(a1 + 4LL * BYTE2(a2) + 1024));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 4LL * (unsigned __int8)a2) + *(_DWORD *)(a1 + 4LL * BYTE2(a2) + 1024));
}

original_code:
static uint32_t
h(const uint32_t *qp, uint32_t x)
{
  return qp[x & 0xFFu] + qp[256 + ((x >> 16) & 0xFFu)];
}

canonical_original_code:
static unsigned int h(unsigned int *qp, unsigned int x)
{
  return qp[x & 0xFFu] + qp[256 + ((x >> 16) & 0xFFu)];
}

variable_types:
qp
unsigned int *


decompiled_code:
__int64 __fastcall g2(__int64 a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
int v5; // ebx

v4 = rotl(a1, 10LL);
v5 = rotl(a3, 23LL) ^ v4;
return v5 + (unsigned int)rotl(a2, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
int v5; // ebx

v4 = rotl(a1, 10LL);
v5 = rotl(a3, 23LL) ^ v4;
return v5 + (unsigned int)rotl(a2, 8LL);
}

original_code:
static uint32_t
g2(uint32_t x, uint32_t y, uint32_t z)
{
  return (rotl(x, 10) ^ rotl(z, 23)) + rotl(y, 8);
}

canonical_original_code:
static unsigned int g2(unsigned int x, unsigned int y, unsigned int z)
{
  return (rotl(x, 10) ^ rotl(z, 23)) + rotl(y, 8);
}

variable_types:
y
unsigned int

variable_types:
z
unsigned int


decompiled_code:
__int64 __fastcall g1(__int64 a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
int v5; // ebx

v4 = rotl(a1, 22LL);
v5 = rotl(a3, 9LL) ^ v4;
return v5 + (unsigned int)rotl(a2, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, unsigned int a3)
{
int v4; // ebx
int v5; // ebx

v4 = rotl(a1, 22LL);
v5 = rotl(a3, 9LL) ^ v4;
return v5 + (unsigned int)rotl(a2, 24LL);
}

original_code:
static uint32_t
g1(uint32_t x, uint32_t y, uint32_t z)
{
  return (rotl(x, 22) ^ rotl(z, 9)) + rotl(y, 24);
}

canonical_original_code:
static unsigned int g1(unsigned int x, unsigned int y, unsigned int z)
{
  return (rotl(x, 22) ^ rotl(z, 9)) + rotl(y, 24);
}


decompiled_code:
__int64 __fastcall f2(__int64 a1)
{
int v1; // ebx

v1 = rotl(a1, 15LL);
return ((unsigned int)a1 >> 10) ^ v1 ^ (unsigned int)rotl((unsigned int)a1, 13LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // ebx

v1 = rotl(a1, 15LL);
return ((unsigned int)a1 >> 10) ^ v1 ^ (unsigned int)rotl((unsigned int)a1, 13LL);
}

original_code:
static uint32_t
f2(uint32_t x)
{
  return rotl(x, 15) ^ rotl(x, 13) ^ (x >> 10);
}

canonical_original_code:
static unsigned int f2(unsigned int x)
{
  return rotl(x, 15) ^ rotl(x, 13) ^ (x >> 10);
}


decompiled_code:
__int64 __fastcall f1(__int64 a1)
{
int v1; // ebx

v1 = rotl(a1, 25LL);
return ((unsigned int)a1 >> 3) ^ v1 ^ (unsigned int)rotl((unsigned int)a1, 14LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // ebx

v1 = rotl(a1, 25LL);
return ((unsigned int)a1 >> 3) ^ v1 ^ (unsigned int)rotl((unsigned int)a1, 14LL);
}

original_code:
static uint32_t
f1(uint32_t x)
{
  return rotl(x, 25) ^ rotl(x, 14) ^ (x >> 3);
}

canonical_original_code:
static unsigned int f1(unsigned int x)
{
  return rotl(x, 25) ^ rotl(x, 14) ^ (x >> 3);
}


original_code:
void
hc128_init(hc128_state *state, const uint8_t *key, const uint8_t *iv)
{
  unsigned int i;
  uint32_t w[1280];
  for(i = 0; i < 4; ++i) {
    w[i] = w[i+4] = pack_littleendian(key + 4 * i);
    w[i+8] = w[i+12] = pack_littleendian(iv + 4 * i);
  }
  for(i = 16; i < 1280; ++i) {
    w[i] = f2(w[i-2]) + w[i-7] + f1(w[i-15]) + w[i-16] + i;
  }
  uint32_t *p = state->p;
  uint32_t *q = state->q;
  for(i = 0; i < 512; ++i)
    {
      p[i] = w[i+256];
      q[i] = w[i+768];
    }
  for(i = 0; i < 512; ++i)
    p[i] = round_expression(p, q, g1, i);
  for(i = 0; i < 512; ++i)
    q[i] = round_expression(q, p, g2, i);
  state->i = 0;
}

canonical_original_code:
void hc128_init(struct hc128_state *state, unsigned char *key, unsigned char *iv)
{
  unsigned int i;
  unsigned int w[1280];
  for(i = 0; i < 4; ++i) {
    w[i] = w[i+4] = pack_littleendian(key + 4 * i);
    w[i+8] = w[i+12] = pack_littleendian(iv + 4 * i);
  }
  for(i = 16; i < 1280; ++i) {
    w[i] = f2(w[i-2]) + w[i-7] + f1(w[i-15]) + w[i-16] + i;
  }
  unsigned int *p = state->p;
  unsigned int *q = state->q;
  for(i = 0; i < 512; ++i)
    {
      p[i] = w[i+256];
      q[i] = w[i+768];
    }
  for(i = 0; i < 512; ++i)
    p[i] = round_expression(p, q, g1, i);
  for(i = 0; i < 512; ++i)
    q[i] = round_expression(q, p, g2, i);
  state->i = 0;
}

variable_types: struct hc128_state { unsigned int p[512]; unsigned int q[512]; unsigned short i; } *

variable_types:
key
unsigned char *

variable_types:
iv
unsigned char *

variable_types:
i
unsigned int

variable_types:
w
unsigned int [1280]

variable_types:
p
unsigned int *

variable_types:
q
unsigned int *


decompiled_code:
__int64 __fastcall hc128_extract(__int64 a1, __int64 a2)
{
unsigned __int16 v2; // cx
__int64 v3; // rdi
unsigned __int16 v5; // ax

v2 = *(_WORD *)(a1 + 4096);
*(_WORD *)(a1 + 4096) = (v2 + 1) & 0x3FF;
if ( v2 > 0x1FFu )
{
v5 = m512(v2);
v3 = (unsigned int)round_expression(a1 + 2048, a1, (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))g2, v5);
}
else
{
v3 = (unsigned int)round_expression(a1, a1 + 2048, (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))g1, v2);
}
return unpack_littleendian(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
unsigned __int16 v2; // cx
__int64 v3; // rdi
unsigned __int16 v5; // ax

v2 = *(_WORD *)(a1 + 4096);
*(_WORD *)(a1 + 4096) = (v2 + 1) & 0x3FF;
if ( v2 > 0x1FFu )
{
v5 = func0(v2);
v3 = (unsigned int)func2(a1 + 2048, a1, (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))g2, v5);
}
else
{
v3 = (unsigned int)func2(a1, a1 + 2048, (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))g1, v2);
}
return unpack_littleendian(v3, a2);
}

original_code:
void
hc128_extract(hc128_state *state, uint8_t *stream)
{
  uint16_t i = state->i;
  state->i = (i + 1u) & 1023u;
  register uint32_t ret = (i < 512)
    ? round_expression(state->p, state->q, g1, i )
    : round_expression(state->q, state->p, g2, m512(i));
  unpack_littleendian(ret, stream);
}

canonical_original_code:
void hc128_extract(struct hc128_state *state, unsigned char *stream)
{
  unsigned short i = state->i;
  state->i = (i + 1u) & 1023u;
  register unsigned int ret = (i < 512)
    ? round_expression(state->p, state->q, g1, i )
    : round_expression(state->q, state->p, g2, m512(i));
  unpack_littleendian(ret, stream);
}

variable_types:
stream
unsigned char *

variable_types:
i
unsigned short

variable_types:
ret
unsigned int

user_defined_types: struct hc128_state { unsigned int p[512]; unsigned int q[512]; unsigned short i; }


memxor

decompiled_code:
__int64 __fastcall memxor(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v6; // rax
unsigned __int64 v8; // rax

v3 = a1;
v4 = a2;
if ( (unsigned int)((__int64 (*)(void))is_aligned)() && (unsigned int)is_aligned(a2) )
{
if ( a3 > 7 )
{
v8 = 0LL;
do
{
*(_QWORD *)(a1 + 8 * v8) ^= *(_QWORD *)(a2 + 8 * v8);
++v8;
}
while ( a3 >> 3 > v8 );
}
v3 = (a3 & 0xFFFFFFFFFFFFFFF8LL) + a1;
v4 = (a3 & 0xFFFFFFFFFFFFFFF8LL) + a2;
a3 &= 7u;
}
if ( a3 )
{
v6 = 0LL;
do
{
*(_BYTE *)(v3 + v6) ^= *(_BYTE *)(v4 + v6);
++v6;
}
while ( a3 != v6 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v6; // rax
unsigned __int64 v8; // rax

v3 = a1;
v4 = a2;
if ( (unsigned int)((__int64 (*)(void))is_aligned)() && (unsigned int)is_aligned(a2) )
{
if ( a3 > 7 )
{
v8 = 0LL;
do
{
*(_QWORD *)(a1 + 8 * v8) ^= *(_QWORD *)(a2 + 8 * v8);
++v8;
}
while ( a3 >> 3 > v8 );
}
v3 = (a3 & 0xFFFFFFFFFFFFFFF8LL) + a1;
v4 = (a3 & 0xFFFFFFFFFFFFFFF8LL) + a2;
a3 &= 7u;
}
if ( a3 )
{
v6 = 0LL;
do
{
*(_BYTE *)(v3 + v6) ^= *(_BYTE *)(v4 + v6);
++v6;
}
while ( a3 != v6 );
}
return 0LL;
}

original_code:
static uint8_t *
memxor(uint8_t *dest, const uint8_t *mask, size_t n)
{
  size_t i;
  if(0 || (is_aligned(dest) && is_aligned(mask)))
    {
      uint64_t *d64 = (uint64_t*)dest;
      uint64_t *m64 = (uint64_t*)mask;
      size_t wlen = n / 8;
      for(i = 0; i < wlen; ++i)
 d64[i] ^= m64[i];
      dest += wlen * 8;
      mask += wlen * 8;
      n %= 8;
    }
  for(i = 0; i < n; ++i)
    dest[i] ^= mask[i];
  return ((void *)0);
}

canonical_original_code:
static unsigned char *memxor(unsigned char *dest, unsigned char *mask, unsigned long n)
{
  unsigned long i;
  if(0 || (is_aligned(dest) && is_aligned(mask)))
    {
      unsigned long *d64 = (uint64_t*)dest;
      unsigned long *m64 = (uint64_t*)mask;
      unsigned long wlen = n / 8;
      for(i = 0; i < wlen; ++i)
 d64[i] ^= m64[i];
      dest += wlen * 8;
      mask += wlen * 8;
      n %= 8;
    }
  for(i = 0; i < n; ++i)
    dest[i] ^= mask[i];
  return ((void *)0);
}

variable_types:
dest
unsigned char *

variable_types:
mask
unsigned char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

variable_types:
wlen
unsigned long

return_type: unsigned char *


decompiled_code:
__int64 __fastcall buffered_get_cipher_state(__int64 a1)
{
return a1 + 16;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1 + 16;
}

original_code:
void *
buffered_get_cipher_state(buffered_state *full_state)
{
  return (uint8_t*)full_state + sizeof(buffered_state);
}

canonical_original_code:
void *buffered_get_cipher_state(struct buffered_state *full_state)
{
  return (unsigned char *)full_state + sizeof(buffered_state);
}

variable_types: struct buffered_state { struct cipher_attributes { void (*extract_func)(void *state, unsigned char *stream); unsigned short buffered_state_size; unsigned short buffer_offset; unsigned char chunk_size; } *cipher; unsigned char available_count; } *

return_type: void *

user_defined_types: struct buffered_state { struct cipher_attributes *cipher; unsigned char available_count; }


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

result = (&cipher_attributes_map)[a2];
*(_QWORD *)a1 = result;
*(_BYTE *)(a1 + 8) = 0;
return result;
}

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

result = (&cipher_attributes_map)[a2];
*(_QWORD *)a1 = result;
*(_BYTE *)(a1 + 8) = 0;
return result;
}

original_code:
void
buffered_init_header(buffered_state *state_header, cipher_type cipher)
{
  state_header->cipher = cipher_attributes_map[(int)cipher];
  state_header->available_count = 0;
}

canonical_original_code:
void buffered_init_header(struct buffered_state *state_header, enum cipher_type cipher)
{
  state_header->cipher = cipher_attributes_map[(int)cipher];
  state_header->available_count = 0;
}

variable_types: enum cipher_type { HC128=0, RABBIT=1, SALSA20=2, SOSEMANUK=3, LAST_CIPHER=expr }

user_defined_types: struct cipher_attributes { void (*extract_func)(void *state, unsigned char *stream); unsigned short buffered_state_size; unsigned short buffer_offset; unsigned char chunk_size; }


decompiled_code:
void __fastcall buffered_reset(__int64 a1)
{
*(_BYTE *)(a1 + 8) = 0;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
*(_BYTE *)(a1 + 8) = 0;
}

original_code:
void
buffered_reset(buffered_state *state_header)
{
  state_header->available_count = 0;
}

canonical_original_code:
void buffered_reset(struct buffered_state *state_header)
{
  state_header->available_count = 0;
}


decompiled_code:
unsigned __int64 __fastcall buffered_skip(unsigned __int8 *a1, unsigned __int64 a2)
{
int v2; // eax
__int64 v3; // r15
unsigned __int64 result; // rax
unsigned __int8 v5; // r14
unsigned __int8 *v6; // r13
__int64 v7; // r12
unsigned __int64 v8; // r15
int v9; // ebx

v2 = a1[8];
v3 = (unsigned __int8)v2;
if ( (unsigned __int8)v2 < a2 )
{
v5 = *(_BYTE *)(*(_QWORD *)a1 + 12LL);
v6 = &a1[*(unsigned __int16 *)(*(_QWORD *)a1 + 10LL)];
v7 = buffered_get_cipher_state((__int64)a1);
a1[8] = 0;
result = (a2 - v3) / v5;
v8 = (a2 - v3) % v5;
v9 = result;
if ( (int)result > 0 )
{
do
{
result = (**(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1)(v7, v6);
--v9;
}
while ( v9 );
}
if ( (_BYTE)v8 )
{
result = (**(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1)(v7, v6);
a1[8] = v5 - v8;
}
}
else
{
result = (unsigned int)(v2 - a2);
a1[8] = result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned __int8 *a1, unsigned __int64 a2)
{
int v2; // eax
__int64 v3; // r15
unsigned __int64 result; // rax
unsigned __int8 v5; // r14
unsigned __int8 *v6; // r13
__int64 v7; // r12
unsigned __int64 v8; // r15
int v9; // ebx

v2 = a1[8];
v3 = (unsigned __int8)v2;
if ( (unsigned __int8)v2 < a2 )
{
v5 = *(_BYTE *)(*(_QWORD *)a1 + 12LL);
v6 = &a1[*(unsigned __int16 *)(*(_QWORD *)a1 + 10LL)];
v7 = func1((__int64)a1);
a1[8] = 0;
result = (a2 - v3) / v5;
v8 = (a2 - v3) % v5;
v9 = result;
if ( (int)result > 0 )
{
do
{
result = (**(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1)(v7, v6);
--v9;
}
while ( v9 );
}
if ( (_BYTE)v8 )
{
result = (**(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1)(v7, v6);
a1[8] = v5 - v8;
}
}
else
{
result = (unsigned int)(v2 - a2);
a1[8] = result;
}
return result;
}

original_code:
void buffered_skip(buffered_state *full_state, size_t len)
{
  const uint8_t chunk_size = full_state->cipher->chunk_size;
  uint8_t *cbuffer = (uint8_t*)full_state + full_state->cipher->buffer_offset;
  void *cipher_state = buffered_get_cipher_state(full_state);
  if(len <= full_state->available_count)
    full_state->available_count -= len;
  else
    {
      len -= full_state->available_count;
      full_state->available_count = 0;
      int i;
      uint8_t remainder = len % chunk_size;
      for(i = len / chunk_size; i > 0; --i)
 full_state->cipher->extract_func(cipher_state, cbuffer);
      if(remainder)
 {
   full_state->cipher->extract_func(cipher_state, cbuffer);
   full_state->available_count = chunk_size - remainder;
 }
    }
}

canonical_original_code:
void buffered_skip(struct buffered_state *full_state, unsigned long len)
{
  unsigned char chunk_size = full_state->cipher->chunk_size;
  unsigned char *cbuffer = (uint8_t*)full_state + full_state->cipher->buffer_offset;
  void *cipher_state = buffered_get_cipher_state(full_state);
  if(len <= full_state->available_count)
    full_state->available_count -= len;
  else
    {
      len -= full_state->available_count;
      full_state->available_count = 0;
      int i;
      unsigned char remainder = len % chunk_size;
      for(i = len / chunk_size; i > 0; --i)
 full_state->cipher->extract_func(cipher_state, cbuffer);
      if(remainder)
 {
   full_state->cipher->extract_func(cipher_state, cbuffer);
   full_state->available_count = chunk_size - remainder;
 }
    }
}

variable_types:
len
unsigned long

variable_types:
cbuffer
unsigned char *

variable_types: i int

variable_types:
remainder
unsigned char


columnround

original_code:
static void
columnround(const uint32_t *in, uint32_t *out)
{
  const uint8_t permut[4][4] =
    {{0, 4, 8, 12},
     {5, 9, 13, 1},
     {10, 14, 2, 6},
     {15, 3, 7, 11}};
  int i;
  for(i = 0; i < 4; ++i)
    {
      uint32_t tmp[4];
      permut_do(in, tmp, permut[i], 4);
      quarterround(tmp, tmp);
      permut_undo(tmp, out, permut[i], 4);
    }
}

canonical_original_code:
static void columnround(unsigned int *in, unsigned int *out)
{
  unsigned char permut[4][4] = {{0, 4, 8, 12},
     {5, 9, 13, 1},
     {10, 14, 2, 6},
     {15, 3, 7, 11}};
  int i;
  for(i = 0; i < 4; ++i)
    {
      unsigned int tmp[4];
      permut_do(in, tmp, permut[i], 4);
      quarterround(tmp, tmp);
      permut_undo(tmp, out, permut[i], 4);
    }
}

variable_types:
in
unsigned int *

variable_types:
out
unsigned int *

variable_types:
permut
unsigned char [4][4]

variable_types:
tmp
unsigned int [4]


rowround

original_code:
static void
rowround(const uint32_t *in, uint32_t *out)
{
  quarterround(in, out);
  const uint8_t permut[3][4] =
    {{5, 6, 7, 4},
     {10, 11, 8, 9},
     {15, 12, 13, 14}};
  int i;
  for(i = 0; i < 3; ++i)
    {
      uint32_t tmp[4];
      permut_do(in, tmp, permut[i], 4);
      quarterround(tmp, tmp);
      permut_undo(tmp, out, permut[i], 4);
    }
}

canonical_original_code:
static void rowround(unsigned int *in, unsigned int *out)
{
  quarterround(in, out);
  unsigned char permut[3][4] = {{5, 6, 7, 4},
     {10, 11, 8, 9},
     {15, 12, 13, 14}};
  int i;
  for(i = 0; i < 3; ++i)
    {
      unsigned int tmp[4];
      permut_do(in, tmp, permut[i], 4);
      quarterround(tmp, tmp);
      permut_undo(tmp, out, permut[i], 4);
    }
}

variable_types:
permut
unsigned char [3][4]


doubleround

decompiled_code:
void __fastcall doubleround(__int64 a1, int *a2)
{
columnround(a1, (__int64)a2);
rowround(a2, a2);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int *a2)
{
func3(a1, (__int64)a2);
func4(a2, a2);
}

original_code:
static void
doubleround(const uint32_t *in, uint32_t *out)
{
  columnround(in, out);
  rowround(out, out);
}

canonical_original_code:
static void doubleround(unsigned int *in, unsigned int *out)
{
  columnround(in, out);
  rowround(out, out);
}


decompiled_code:
__int64 __fastcall salsa20_hash(char a1, __int64 a2, int *a3)
{
int i; // ebp
__int64 result; // rax

doubleround(a2, a3);
if ( a1 > 1 )
{
for ( i = 1; i != a1; ++i )
doubleround((__int64)a3, a3);
}
for ( result = 0LL; result != 16; ++result )
a3[result] += *(_DWORD *)(a2 + result * 4);
return result * 4;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, __int64 a2, int *a3)
{
int i; // ebp
__int64 result; // rax

func5(a2, a3);
if ( a1 > 1 )
{
for ( i = 1; i != a1; ++i )
func5((__int64)a3, a3);
}
for ( result = 0LL; result != 16; ++result )
a3[result] += *(_DWORD *)(a2 + result * 4);
return result * 4;
}

original_code:
static void
salsa20_hash(char drounds, const uint32_t *in, uint32_t *out)
{
  int i, j;
  doubleround(in, out);
  for(i = 1; i < drounds; ++i)
    doubleround(out, out);
  for(i = 0; i < 16; ++i)
    out[i] += in[i];
}

canonical_original_code:
static void salsa20_hash(char drounds, unsigned int *in, unsigned int *out)
{
  int i; int j;
  doubleround(in, out);
  for(i = 1; i < drounds; ++i)
    doubleround(out, out);
  for(i = 0; i < 16; ++i)
    out[i] += in[i];
}

variable_types: drounds char

variable_types: j int


original_code:
void
salsa20_init_key(salsa20_master_state *state, salsa20_variant variant,
   const uint8_t *key, salsa20_key_size key_size)
{
  int i;
  uint32_t k32[8];
  const size_t key_words = 4 + key_size * 4;
  for(i = 0; i < key_words; ++i)
    k32[i] = pack_littleendian(&key[i*4]);
  state->incomplete_state.variant = variant;
  uint32_t *s = state->incomplete_state.hash_input.bit32;
  static const uint32_t consts[2][4] =
    {{0x3120646e, 0x79622d36},
     {0x3320646e, 0x79622d32}};
  s[0] = 0x61707865;
  memcpy(s+1, k32, 16);
  s[5] = consts[key_size][0];
  s[10] = consts[key_size][1];
  memcpy(s+11, &k32[key_size * 4], 16);
  s[15] = 0x6b206574;
}

canonical_original_code:
void salsa20_init_key(struct salsa20_master_state *state, enum salsa20_variant variant, unsigned char *key, enum salsa20_key_size key_size)
{
  int i;
  unsigned int k32[8];
  unsigned long key_words = 4 + key_size * 4;
  for(i = 0; i < key_words; ++i)
    k32[i] = pack_littleendian(&key[i*4]);
  state->incomplete_state.variant = variant;
  unsigned int *s = state->incomplete_state.hash_input.bit32;
  static unsigned int consts[2][4] = {{0x3120646e, 0x79622d36},
     {0x3320646e, 0x79622d32}};
  s[0] = 0x61707865;
  memcpy(s+1, k32, 16);
  s[5] = consts[key_size][0];
  s[10] = consts[key_size][1];
  memcpy(s+11, &k32[key_size * 4], 16);
  s[15] = 0x6b206574;
}

variable_types: struct salsa20_master_state { struct salsa20_state { union { unsigned int bit32[16]; unsigned long bit64[8]; } hash_input; char variant; } incomplete_state; } *

variable_types: enum salsa20_variant { SALSA20_8=4, SALSA20_12=6, SALSA20_20=10 }

variable_types:
key
unsigned char *

variable_types: enum salsa20_key_size { SALSA20_128_BITS=0, SALSA20_256_BITS=1 }

variable_types:
s
unsigned int *

variable_types:
consts
unsigned int [2][4]

user_defined_types: struct salsa20_master_state { struct salsa20_state incomplete_state; }


original_code:
void
salsa20_init_iv(salsa20_state *iv_state, const salsa20_master_state *master,
  const uint8_t *iv)
{
  memcpy(iv_state, &master->incomplete_state, sizeof(salsa20_state));
  iv_state->hash_input.bit32[6] = pack_littleendian(iv );
  iv_state->hash_input.bit32[7] = pack_littleendian(iv + 4);
  iv_state->hash_input.bit64[4] = 0;
}

canonical_original_code:
void salsa20_init_iv(struct salsa20_state *iv_state, struct salsa20_master_state *master, unsigned char *iv)
{
  memcpy(iv_state, &master->incomplete_state, sizeof(salsa20_state));
  iv_state->hash_input.bit32[6] = pack_littleendian(iv );
  iv_state->hash_input.bit32[7] = pack_littleendian(iv + 4);
  iv_state->hash_input.bit64[4] = 0;
}

variable_types: struct salsa20_state { union { unsigned int bit32[16]; unsigned long bit64[8]; } hash_input; char variant; } *

variable_types: struct salsa20_master_state { struct salsa20_state incomplete_state; } *

variable_types:
iv
unsigned char *


decompiled_code:
void __fastcall salsa20_set_counter(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 32) = a2;
}

original_code:
void
salsa20_set_counter(salsa20_state *state, uint64_t counter)
{
  state->hash_input.bit32[8] = counter;
  state->hash_input.bit32[9] = counter >> 32;
}

canonical_original_code:
void salsa20_set_counter(struct salsa20_state *state, unsigned long counter)
{
  state->hash_input.bit32[8] = counter;
  state->hash_input.bit32[9] = counter >> 32;
}

variable_types:
counter
unsigned long

user_defined_types: struct salsa20_state { union { unsigned int bit32[16]; unsigned long bit64[8]; } hash_input; char variant; }


decompiled_code:
__int64 __fastcall salsa20_extract(__int64 a1, int *a2)
{
int v2; // eax
int *v3; // rbx
__int64 result; // rax

salsa20_hash(*(_BYTE *)(a1 + 64), a1, a2);
v2 = *(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 32) = v2 + 1;
if ( v2 == -1 )
++*(_DWORD *)(a1 + 36);
v3 = a2;
do
{
result = unpack_littleendian((unsigned int)*v3, v3);
++v3;
}
while ( v3 != a2 + 16 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int *a2)
{
int v2; // eax
int *v3; // rbx
__int64 result; // rax

func6(*(_BYTE *)(a1 + 64), a1, a2);
v2 = *(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 32) = v2 + 1;
if ( v2 == -1 )
++*(_DWORD *)(a1 + 36);
v3 = a2;
do
{
result = unpack_littleendian((unsigned int)*v3, v3);
++v3;
}
while ( v3 != a2 + 16 );
return result;
}

original_code:
void
salsa20_extract(salsa20_state *state, uint8_t *stream)
{
  salsa20_hash(state->variant, state->hash_input.bit32, (uint32_t*)stream);
  if(!++state->hash_input.bit32[8])
    ++state->hash_input.bit32[9];
  int i;
  for(i = 0; i < 16; ++i)
    {
      uint32_t tmp = ((uint32_t*)stream)[i];
      unpack_littleendian(tmp, &stream[i*4]);
    }
}

canonical_original_code:
void salsa20_extract(struct salsa20_state *state, unsigned char *stream)
{
  salsa20_hash(state->variant, state->hash_input.bit32, (unsigned int *)stream);
  if(!++state->hash_input.bit32[8])
    ++state->hash_input.bit32[9];
  int i;
  for(i = 0; i < 16; ++i)
    {
      unsigned int tmp = ((uint32_t*)stream)[i];
      unpack_littleendian(tmp, &stream[i*4]);
    }
}

variable_types:
stream
unsigned char *

variable_types: i int

variable_types:
tmp
unsigned int


rotl

decompiled_code:
__int64 __fastcall rotl(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

original_code:
uint32_t
rotl(uint32_t x, unsigned int n)
{
  return (x << n) | (x >> (32-n));
}

canonical_original_code:
unsigned int rotl(unsigned int x, unsigned int n)
{
  return (x << n) | (x >> (32-n));
}

variable_types:
x
unsigned int

variable_types:
n
unsigned int


original_code:
uint32_t
pack_littleendian(const uint8_t *v)
{
  return (uint32_t)v[3] << 24
      | (uint32_t)v[2] << 16
      | (uint32_t)v[1] << 8
      | (uint32_t)v[0];
}

canonical_original_code:
unsigned int pack_littleendian(unsigned char *v)
{
  return (unsigned int)v[3] << 24
      | (unsigned int)v[2] << 16
      | (unsigned int)v[1] << 8
      | (unsigned int)v[0];
}

variable_types:
v
unsigned char *


min

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

result = a1;
if ( a2 <= a1 )
result = a2;
return result;
}

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

result = a1;
if ( a2 <= a1 )
result = a2;
return result;
}

original_code:
size_t
min(size_t a, size_t b)
{
  return (a < b) ? a : b;
}

canonical_original_code:
unsigned long min(unsigned long a, unsigned long b)
{
  return (a < b) ? a : b;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long

return_type: unsigned long


decompiled_code:
_BOOL8 __fastcall is_aligned(char a1)
{
return (a1 & 3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char a1)
{
return (a1 & 3) == 0;
}

original_code:
int
is_aligned(const void *ptr)
{
  return ((unsigned)ptr & 3u) == 0;
}

canonical_original_code:
int is_aligned(void *ptr)
{
  return ((unsigned int)ptr & 3u) == 0;
}

variable_types:
ptr
void *

return_type: int


original_code:
static int
mac_verify(signer_context *ctx, void *recv_param)
{
  uint8_t mac_recv[16];
  uint8_t mac_calc[16];
  const uint8_t size = ctx->mac_key->attribs->iters * 4;
  ctx->io_callback(recv_param, mac_recv, size);
  buffered_action(ctx->cipher_state, mac_recv, size, BUFFERED_ENCDEC);
  uhash_finish(ctx->mac_key, ctx->mac_state, mac_calc);
  return memcmp(mac_recv, mac_calc, size) == 0;
}

canonical_original_code:
static int mac_verify(struct signer_context *ctx, void *recv_param)
{
  unsigned char mac_recv[16];
  unsigned char mac_calc[16];
  unsigned char size = ctx->mac_key->attribs->iters * 4;
  ctx->io_callback(recv_param, mac_recv, size);
  buffered_action(ctx->cipher_state, mac_recv, size, BUFFERED_ENCDEC);
  uhash_finish(ctx->mac_key, ctx->mac_state, mac_calc);
  return memcmp(mac_recv, mac_calc, size) == 0;
}

variable_types: struct signer_context { struct buffered_state { struct cipher_attributes { void (*extract_func)(void *state, unsigned char *stream); unsigned short buffered_state_size; unsigned short buffer_offset; unsigned char chunk_size; } *cipher; unsigned char available_count; } *cipher_state; void (*io_callback)(void *parameter, unsigned char *buffer, unsigned short len); struct uhash_key { struct uhash_key_attributes { unsigned short l2key_offset; unsigned short l3key1_offset; unsigned short l3key2_offset; unsigned char iters; } *attribs; } *mac_key; struct uhash_state { struct uhash_state_common { unsigned char iters; unsigned char buffer_len; unsigned int buffer[8]; unsigned long step_count; } common; struct uhash_iteration_state { unsigned long l1; struct l2_state { struct uint128 { unsigned long v[2]; } y; unsigned long tmp; } l2; } partial[]; } *mac_state; } *

variable_types:
size
unsigned char

user_defined_types: struct signer_context { struct buffered_state *cipher_state; void (*io_callback)(void *parameter, unsigned char *buffer, unsigned short len); struct uhash_key *mac_key; struct uhash_state *mac_state; }

user_defined_types: struct uhash_key { struct uhash_key_attributes *attribs; }

user_defined_types: struct uhash_state { struct uhash_state_common common; struct uhash_iteration_state partial[]; }

user_defined_types: struct uhash_iteration_state { unsigned long l1; struct l2_state l2; }

user_defined_types: struct l2_state { struct uint128 y; unsigned long tmp; }


decompiled_code:
__int64 __fastcall signed_send(_QWORD *a1, __int64 a2, char *a3, unsigned int a4)
{
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // eax
unsigned __int16 v8; // bp
unsigned __int16 v9; // r14
unsigned int v10; // er13
unsigned __int16 i; // bp
unsigned __int16 v12; // bx
__int64 result; // rax
__int64 v14; // rbx
unsigned int v15; // eax
unsigned __int8 v17; // [rsp+1Fh] [rbp-1039h]
int dest; // [rsp+20h] [rbp-1038h] BYREF
char v19[4148]; // [rsp+24h] [rbp-1034h] BYREF

v5 = a1[2];
v17 = 4 * *(_BYTE *)(*(_QWORD *)v5 + 6LL);
dest = _uint32_identity(a4);
v6 = a1[3];
v7 = uhash_get_type_from_key(v5);
uhash_init(v7, v6);
uhash_update(a1[2], a1[3], &dest, 4LL);
v8 = 4;
if ( a4 > 0x400 )
{
uhash_finish(a1[2], a1[3], v19);
v14 = a1[3];
v15 = uhash_get_type_from_key(a1[2]);
uhash_init(v15, v14);
v8 = v17 + 4;
}
v9 = min(a4, 4096 - (unsigned int)v8);
memcpy((char *)&dest + v8, a3, v9);
uhash_update(a1[2], a1[3], a3, v9);
v10 = v9;
for ( i = v9 + v8; a4 > v10; v10 += i )
{
buffered_action(*a1, &dest, i, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, i);
i = min(a4 - v10, 4096LL);
memcpy(&dest, &a3[v10], i);
uhash_update(a1[2], a1[3], &dest, i);
}
if ( v17 > (unsigned __int16)(4096 - i) )
{
buffered_action(*a1, &dest, i, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, i);
uhash_finish(a1[2], a1[3], &dest);
buffered_action(*a1, &dest, v17, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v17);
}
else
{
uhash_finish(a1[2], a1[3], (char *)&dest + i);
v12 = i + v17;
buffered_action(*a1, &dest, v12, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v12);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, char *a3, unsigned int a4)
{
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // eax
unsigned __int16 v8; // bp
unsigned __int16 v9; // r14
unsigned int v10; // er13
unsigned __int16 i; // bp
unsigned __int16 v12; // bx
__int64 result; // rax
__int64 v14; // rbx
unsigned int v15; // eax
unsigned __int8 v17; // [rsp+1Fh] [rbp-1039h]
int dest; // [rsp+20h] [rbp-1038h] BYREF
char v19[4148]; // [rsp+24h] [rbp-1034h] BYREF

v5 = a1[2];
v17 = 4 * *(_BYTE *)(*(_QWORD *)v5 + 6LL);
dest = func0(a4);
v6 = a1[3];
v7 = uhash_get_type_from_key(v5);
uhash_init(v7, v6);
uhash_update(a1[2], a1[3], &dest, 4LL);
v8 = 4;
if ( a4 > 0x400 )
{
uhash_finish(a1[2], a1[3], v19);
v14 = a1[3];
v15 = uhash_get_type_from_key(a1[2]);
uhash_init(v15, v14);
v8 = v17 + 4;
}
v9 = min(a4, 4096 - (unsigned int)v8);
memcpy((char *)&dest + v8, a3, v9);
uhash_update(a1[2], a1[3], a3, v9);
v10 = v9;
for ( i = v9 + v8; a4 > v10; v10 += i )
{
buffered_action(*a1, &dest, i, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, i);
i = min(a4 - v10, 4096LL);
memcpy(&dest, &a3[v10], i);
uhash_update(a1[2], a1[3], &dest, i);
}
if ( v17 > (unsigned __int16)(4096 - i) )
{
buffered_action(*a1, &dest, i, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, i);
uhash_finish(a1[2], a1[3], &dest);
buffered_action(*a1, &dest, v17, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v17);
}
else
{
uhash_finish(a1[2], a1[3], (char *)&dest + i);
v12 = i + v17;
buffered_action(*a1, &dest, v12, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v12);
}
return result;
}

original_code:
void
signed_send(signer_context *ctx, void *send_param, const uint8_t *msg_buff, uint32_t len)
{
  uint32_t processed_count = 0;
  uint32_t sent_msg_bytes = 0;
  uint8_t buffer[(4096)];
  uint16_t buff_used;
  const uint8_t tag_size = ctx->mac_key->attribs->iters * 4;
  {
    uint32_t ordered_len = __uint32_identity (len);
    memcpy(buffer, &ordered_len, 4);
    buff_used = 4;
  }
  uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
  uhash_update(ctx->mac_key, ctx->mac_state, buffer, buff_used);
  if(len > 1024) {
    uhash_finish(ctx->mac_key, ctx->mac_state, &buffer[buff_used]);
    uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
    buff_used += tag_size;
  }
  {
    uint16_t to_copy = min(len, (4096) - buff_used);
    memcpy(&buffer[buff_used], msg_buff, to_copy);
    uhash_update(ctx->mac_key, ctx->mac_state, msg_buff, to_copy);
    processed_count += to_copy;
    buff_used += to_copy;
  }
  while(processed_count < len) {
      buffered_action(ctx->cipher_state, buffer, buff_used, BUFFERED_ENCDEC);
      ctx->io_callback(send_param, buffer, buff_used);
      buff_used = min(len - processed_count, (4096));
      memcpy(buffer, msg_buff + processed_count, buff_used);
      uhash_update(ctx->mac_key, ctx->mac_state, buffer, buff_used);
      processed_count += buff_used;
  }
  {
    uint16_t space_left = (4096) - buff_used;
    if(space_left >= tag_size) {
 uhash_finish(ctx->mac_key, ctx->mac_state, &buffer[buff_used]);
 buff_used += tag_size;
 buffered_action(ctx->cipher_state, buffer, buff_used, BUFFERED_ENCDEC);
 ctx->io_callback(send_param, buffer, buff_used);
    } else {
 buffered_action(ctx->cipher_state, buffer, buff_used, BUFFERED_ENCDEC);
 ctx->io_callback(send_param, buffer, buff_used);
 uhash_finish(ctx->mac_key, ctx->mac_state, buffer);
 buffered_action(ctx->cipher_state, buffer, tag_size, BUFFERED_ENCDEC);
 ctx->io_callback(send_param, buffer, tag_size);
    }
  }
}

canonical_original_code:
void signed_send(struct signer_context *ctx, void *send_param, unsigned char *msg_buff, unsigned int len)
{
  unsigned int processed_count = 0;
  unsigned int sent_msg_bytes = 0;
  unsigned char buffer[-1];
  unsigned short buff_used;
  unsigned char tag_size = ctx->mac_key->attribs->iters * 4;
  {
    unsigned int ordered_len = __uint32_identity (len);
    memcpy(buffer, &ordered_len, 4);
    buff_used = 4;
  }
  uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
  uhash_update(ctx->mac_key, ctx->mac_state, buffer, buff_used);
  if(len > 1024) {
    uhash_finish(ctx->mac_key, ctx->mac_state, &buffer[buff_used]);
    uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
    buff_used += tag_size;
  }
  {
    unsigned short to_copy = min(len, (4096) - buff_used);
    memcpy(&buffer[buff_used], msg_buff, to_copy);
    uhash_update(ctx->mac_key, ctx->mac_state, msg_buff, to_copy);
    processed_count += to_copy;
    buff_used += to_copy;
  }
  while(processed_count < len) {
      buffered_action(ctx->cipher_state, buffer, buff_used, BUFFERED_ENCDEC);
      ctx->io_callback(send_param, buffer, buff_used);
      buff_used = min(len - processed_count, (4096));
      memcpy(buffer, msg_buff + processed_count, buff_used);
      uhash_update(ctx->mac_key, ctx->mac_state, buffer, buff_used);
      processed_count += buff_used;
  }
  {
    unsigned short space_left = (4096) - buff_used;
    if(space_left >= tag_size) {
 uhash_finish(ctx->mac_key, ctx->mac_state, &buffer[buff_used]);
 buff_used += tag_size;
 buffered_action(ctx->cipher_state, buffer, buff_used, BUFFERED_ENCDEC);
 ctx->io_callback(send_param, buffer, buff_used);
    } else {
 buffered_action(ctx->cipher_state, buffer, buff_used, BUFFERED_ENCDEC);
 ctx->io_callback(send_param, buffer, buff_used);
 uhash_finish(ctx->mac_key, ctx->mac_state, buffer);
 buffered_action(ctx->cipher_state, buffer, tag_size, BUFFERED_ENCDEC);
 ctx->io_callback(send_param, buffer, tag_size);
    }
  }
}

variable_types:
len
unsigned int

variable_types:
buffer
unsigned char [-1]

user_defined_types: struct uhash_state_common { unsigned char iters; unsigned char buffer_len; unsigned int buffer[8]; unsigned long step_count; }

user_defined_types: struct uhash_key_attributes { unsigned short l2key_offset; unsigned short l3key1_offset; unsigned short l3key2_offset; unsigned char iters; }


decompiled_code:
__int64 __fastcall signed_recv(_QWORD *a1, __int64 a2, void **a3, unsigned int *a4)
{
__int64 v5; // rbx
unsigned int v6; // eax
unsigned int v7; // eax
_BOOL4 v8; // edx
__int64 result; // rax
__int64 v10; // rbx
unsigned int v11; // eax
void *v12; // rax
unsigned int v13; // esi
unsigned int v14; // er13
char *v15; // rbp
unsigned __int16 v16; // bx
_BOOL4 v17; // edx

*a3 = 0LL;
((void (__fastcall *)(__int64, unsigned int *, __int64))a1[1])(a2, a4, 4LL);
buffered_action(*a1, a4, 4LL, 1LL);
v5 = a1[3];
v6 = uhash_get_type_from_key(a1[2]);
uhash_init(v6, v5);
uhash_update(a1[2], a1[3], a4, 4LL);
v7 = _uint32_identity(*a4);
*a4 = v7;
if ( v7 > 0x400 )
{
v8 = mac_verify((__int64)a1, a2);
result = 1LL;
if ( !v8 )
return result;
v10 = a1[3];
v11 = uhash_get_type_from_key(a1[2]);
uhash_init(v11, v10);
}
v12 = malloc(*a4);
*a3 = v12;
if ( !v12 )
return 2LL;
v13 = *a4;
if ( *a4 )
{
v14 = 0;
do
{
v15 = (char *)*a3 + v14;
v16 = min(4096LL, v13 - v14);
((void (__fastcall *)(__int64, char *, _QWORD))a1[1])(a2, v15, v16);
v14 += v16;
buffered_action(*a1, v15, v16, 1LL);
uhash_update(a1[2], a1[3], v15, v16);
v13 = *a4;
}
while ( *a4 > v14 );
}
v17 = mac_verify((__int64)a1, a2);
result = 0LL;
if ( !v17 )
{
free(*a3);
*a3 = 0LL;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, void **a3, unsigned int *a4)
{
__int64 v5; // rbx
unsigned int v6; // eax
unsigned int v7; // eax
_BOOL4 v8; // edx
__int64 result; // rax
__int64 v10; // rbx
unsigned int v11; // eax
void *v12; // rax
unsigned int v13; // esi
unsigned int v14; // er13
char *v15; // rbp
unsigned __int16 v16; // bx
_BOOL4 v17; // edx

*a3 = 0LL;
((void (__fastcall *)(__int64, unsigned int *, __int64))a1[1])(a2, a4, 4LL);
buffered_action(*a1, a4, 4LL, 1LL);
v5 = a1[3];
v6 = uhash_get_type_from_key(a1[2]);
uhash_init(v6, v5);
uhash_update(a1[2], a1[3], a4, 4LL);
v7 = func0(*a4);
*a4 = v7;
if ( v7 > 0x400 )
{
v8 = func1((__int64)a1, a2);
result = 1LL;
if ( !v8 )
return result;
v10 = a1[3];
v11 = uhash_get_type_from_key(a1[2]);
uhash_init(v11, v10);
}
v12 = malloc(*a4);
*a3 = v12;
if ( !v12 )
return 2LL;
v13 = *a4;
if ( *a4 )
{
v14 = 0;
do
{
v15 = (char *)*a3 + v14;
v16 = min(4096LL, v13 - v14);
((void (__fastcall *)(__int64, char *, _QWORD))a1[1])(a2, v15, v16);
v14 += v16;
buffered_action(*a1, v15, v16, 1LL);
uhash_update(a1[2], a1[3], v15, v16);
v13 = *a4;
}
while ( *a4 > v14 );
}
v17 = func1((__int64)a1, a2);
result = 0LL;
if ( !v17 )
{
free(*a3);
*a3 = 0LL;
result = 1LL;
}
return result;
}

original_code:
SignerReceiveStatus
signed_recv(signer_context *ctx, void *recv_param, uint8_t **buffer, uint32_t *size)
{
  const uint8_t tag_size = ctx->mac_key->attribs->iters * 4;
  *buffer = ((void *)0);
  ctx->io_callback(recv_param, (uint8_t*)size, 4);
  buffered_action(ctx->cipher_state, (uint8_t*)size, 4, BUFFERED_ENCDEC);
  uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
  uhash_update(ctx->mac_key, ctx->mac_state, (uint8_t*)size, 4);
  *size = __uint32_identity (*size);
  if(*size > 1024) {
      if(!mac_verify(ctx, recv_param))
 return SIGNER_RECV_VERIFY_FAILED;
      uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
  }
  *buffer = malloc(*size);
  if(!*buffer)
    return SIGNER_ALLOC_FAILED;
  {
      uint32_t received = 0;
      while(received < *size) {
   uint8_t *ptr = *buffer + received;
   uint16_t to_recv = min((4096), *size - received);
   ctx->io_callback(recv_param, ptr, to_recv);
   received += to_recv;
   buffered_action(ctx->cipher_state, ptr, to_recv, BUFFERED_ENCDEC);
   uhash_update(ctx->mac_key, ctx->mac_state, ptr, to_recv);
      }
  }
  if(!mac_verify(ctx, recv_param)) {
      free(*buffer);
      *buffer = ((void *)0);
      return SIGNER_RECV_VERIFY_FAILED;
  }
  return SIGNER_RECV_SUCCESS;
}

canonical_original_code:
enum SignerReceiveStatus signed_recv(struct signer_context *ctx, void *recv_param, unsigned char **buffer, unsigned int *size)
{
  unsigned char tag_size = ctx->mac_key->attribs->iters * 4;
  *buffer = ((void *)0);
  ctx->io_callback(recv_param, (unsigned char *)size, 4);
  buffered_action(ctx->cipher_state, (unsigned char *)size, 4, BUFFERED_ENCDEC);
  uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
  uhash_update(ctx->mac_key, ctx->mac_state, (unsigned char *)size, 4);
  *size = __uint32_identity (*size);
  if(*size > 1024) {
      if(!mac_verify(ctx, recv_param))
 return SIGNER_RECV_VERIFY_FAILED;
      uhash_init(uhash_get_type_from_key(ctx->mac_key), ctx->mac_state);
  }
  *buffer = malloc(*size);
  if(!*buffer)
    return SIGNER_ALLOC_FAILED;
  {
      unsigned int received = 0;
      while(received < *size) {
   unsigned char *ptr = *buffer + received;
   unsigned short to_recv = min((4096), *size - received);
   ctx->io_callback(recv_param, ptr, to_recv);
   received += to_recv;
   buffered_action(ctx->cipher_state, ptr, to_recv, BUFFERED_ENCDEC);
   uhash_update(ctx->mac_key, ctx->mac_state, ptr, to_recv);
      }
  }
  if(!mac_verify(ctx, recv_param)) {
      free(*buffer);
      *buffer = ((void *)0);
      return SIGNER_RECV_VERIFY_FAILED;
  }
  return SIGNER_RECV_SUCCESS;
}

variable_types:
buffer
unsigned char **

variable_types:
size
unsigned int *

variable_types:
received
unsigned int

variable_types:
ptr
unsigned char *

return_type: enum SignerReceiveStatus { SIGNER_RECV_SUCCESS=0, SIGNER_RECV_VERIFY_FAILED=1, SIGNER_ALLOC_FAILED=2 }


decompiled_code:
char *__fastcall a2_type2string(int a1)
{
return type_info[a1];
}

canonical_decompiled_code:
char *__fastcall func11(int a1)
{
return type_info[a1];
}

original_code:
const char* a2_type2string(int type){
 ((void)0);
 return type_info[type];
}

canonical_original_code:
char *a2_type2string(int type){
 ((void)0);
 return type_info[type];
}

variable_types: type int

return_type: char *


decompiled_code:
__int64 __fastcall a2_string_append(__int64 a1, char a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rax

v2 = a1;
if ( !a1 )
return 0LL;
result = a1;
if ( a2 )
{
if ( (unsigned __int64)((__int64 (*)(void))a2_string_len)() >> *(_BYTE *)(a1 - 1) )
v2 = resize_string(a1 - 9) + 9;
v4 = a2_string_len(v2);
*(_BYTE *)(v2 + v4) = a2;
*(_BYTE *)(v2 + v4 + 1) = 0;
*(_QWORD *)(v2 - 9) = v4 + 1;
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rax

v2 = a1;
if ( !a1 )
return 0LL;
result = a1;
if ( a2 )
{
if ( (unsigned __int64)((__int64 (*)(void))a2_string_len)() >> *(_BYTE *)(a1 - 1) )
v2 = func0(a1 - 9) + 9;
v4 = a2_string_len(v2);
*(_BYTE *)(v2 + v4) = a2;
*(_BYTE *)(v2 + v4 + 1) = 0;
*(_QWORD *)(v2 - 9) = v4 + 1;
result = v2;
}
return result;
}

original_code:
char* a2_string_append(char* a2_s, char c){
 size_t len =0;
 do{if((a2_s)==((void *)0)) return (0);}while(0);
 if(!c) return a2_s;
 if(a2_string_len(a2_s)>=(((size_t)1)<<((byte)(((struct a2_string*)((void*)(a2_s)-((size_t)(&(((struct a2_string*)0)->str[1])))))->str[0])))){
  a2_s = ((char*)((void*)(_resize_string(((struct a2_string*)((void*)(a2_s)-((size_t)(&(((struct a2_string*)0)->str[1])))))))+((size_t)(&(((struct a2_string*)0)->str[1])))));
 }
 len = a2_string_len(a2_s);
 a2_s[len]=c;
 a2_s[len+1]='\0';
 ((struct a2_string*)((void*)(a2_s)-((size_t)(&(((struct a2_string*)0)->str[1])))))->len = len+1;
 return a2_s;
}

canonical_original_code:
char *a2_string_append(char *a2_s, char c){
 unsigned long len = 0;
 do{if((a2_s)==((void *)0)) return (0);}while(0);
 if(!c) return a2_s;
 if(a2_string_len(a2_s)>=(((unsigned long)1)<<((byte)(((struct a2_string *)((void *)(a2_s)-((unsigned long)(&(((struct a2_string *)0)->str[1])))))->str[0])))){
  a2_s = ((char *)((void *)(_resize_string(((struct a2_string *)((void *)(a2_s)-((unsigned long)(&(((struct a2_string *)0)->str[1])))))))+((unsigned long)(&(((struct a2_string *)0)->str[1])))));
 }
 len = a2_string_len(a2_s);
 a2_s[len]=c;
 a2_s[len+1]='\0';
 ((struct a2_string *)((void *)(a2_s)-((unsigned long)(&(((struct a2_string *)0)->str[1])))))->len = len+1;
 return a2_s;
}

variable_types: c char

variable_types:
len
unsigned long

user_defined_types: struct a2_string { unsigned long len; char str[2]; }


decompiled_code:
__int64 __fastcall a2_string_new(char *a1)
{
__int64 v1; // rax
char v2; // si
char *v3; // rbx

if ( !a1 )
return 0LL;
v1 = resize_string(0LL);
v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
do
{
v1 = a2_string_append(v1 + 9, v2) - 9;
v2 = *v3++;
}
while ( v2 );
}
return v1 + 9;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
__int64 v1; // rax
char v2; // si
char *v3; // rbx

if ( !a1 )
return 0LL;
v1 = func0(0LL);
v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
do
{
v1 = func1(v1 + 9, v2) - 9;
v2 = *v3++;
}
while ( v2 );
}
return v1 + 9;
}

original_code:
char* a2_string_new(const char* s){
 int i=0;
 struct a2_string* ret = ((void *)0);
 do{if((s)==((void *)0)) return (((void *)0));}while(0);
 ret = _resize_string(((void *)0));
 while(s[i]){
  ret = ((struct a2_string*)((void*)(a2_string_append(((char*)((void*)(ret)+((size_t)(&(((struct a2_string*)0)->str[1]))))), s[i]))-((size_t)(&(((struct a2_string*)0)->str[1])))));
  i++;
 }
 return ((char*)((void*)(ret)+((size_t)(&(((struct a2_string*)0)->str[1])))));
}

canonical_original_code:
char *a2_string_new(char *s){
 int i = 0;
 struct a2_string *ret = ((void *)0);
 do{if((s)==((void *)0)) return (((void *)0));}while(0);
 ret = _resize_string(((void *)0));
 while(s[i]){
  ret = ((struct a2_string *)((void *)(a2_string_append(((char *)((void *)(ret)+((unsigned long)(&(((struct a2_string *)0)->str[1]))))), s[i]))-((unsigned long)(&(((struct a2_string *)0)->str[1])))));
  i++;
 }
 return ((char *)((void *)(ret)+((unsigned long)(&(((struct a2_string *)0)->str[1])))));
}

variable_types:
s
char *

variable_types: i int

variable_types: struct a2_string { unsigned long len; char str[2]; } *


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

if ( a1 )
result = a2_free(a1 - 9);
return result;
}

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

if ( a1 )
result = a2_free(a1 - 9);
return result;
}

original_code:
void a2_string_free(char* a2_s){
 if(a2_s==((void *)0))
  return;
 a2_free(((struct a2_string*)((void*)(a2_s)-((size_t)(&(((struct a2_string*)0)->str[1]))))));
}

canonical_original_code:
void a2_string_free(char *a2_s){
 if(a2_s==((void *)0))
  return;
 a2_free(((struct a2_string *)((void *)(a2_s)-((unsigned long)(&(((struct a2_string *)0)->str[1]))))));
}


repo: lvzixun/lite-proto

decompiled_code:
_QWORD *get_lp_env()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)lp_malloc(1928LL);
*v0 = 0LL;
v0[240] = 0LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1928) >> 3));
if ( !(unsigned int)get_lex_env(v0) )
return 0LL;
if ( !(unsigned int)get_parse_env(v0 + 88, v0 + 80) )
v0 = 0LL;
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)lp_malloc(1928LL);
*v0 = 0LL;
v0[240] = 0LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1928) >> 3));
if ( !(unsigned int)get_lex_env(v0) )
return 0LL;
if ( !(unsigned int)get_parse_env(v0 + 88, v0 + 80) )
v0 = 0LL;
return v0;
}

original_code:
lp_env* get_lp_env()
{
 lp_env* ret = (lp_env*)lp_malloc(sizeof(*ret));
 memset(ret, 0, sizeof(*ret));
 do{if((get_lex_env(&ret->lex_envV))==(LP_FAIL)) return ((((void *)0)));}while(0);
 do{if((get_parse_env(&ret->parse_envV, &ret->lex_envV.lex_list))==(LP_FAIL)) return ((((void *)0)));}while(0);
 return ret;
}

canonical_original_code:
struct _lp_env *get_lp_env()
{
 struct _lp_env *ret = (lp_env*)lp_malloc(sizeof(*ret));
 memset(ret, 0, sizeof(*ret));
 do{if((get_lex_env(&ret->lex_envV))==(LP_FAIL)) return ((((void *)0)));}while(0);
 do{if((get_parse_env(&ret->parse_envV, &ret->lex_envV.lex_list))==(LP_FAIL)) return ((((void *)0)));}while(0);
 return ret;
}

variable_types: struct _lp_env { struct _lp_lex_env { struct _lp_key { char *s_key; unsigned char s_tt; } lp_k[32]; unsigned char char_enum[128]; struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } lex_list; unsigned int line; } lex_envV; struct _lp_parse_env { struct _lp_list parse_out; struct _lp_table { struct _lp_table_one { int value; struct _lp_string { struct _lp_list str; } name; struct _lp_table_one *next; } *table_list[128]; unsigned long table_len; } parse_table; struct _lp_list *token_list; unsigned long read_inx; unsigned int line; struct _lp_list clo_stack; struct _lp_string mes_name; } parse_envV; } *

user_defined_types: struct _lp_env { struct _lp_lex_env lex_envV; struct _lp_parse_env parse_envV; }

user_defined_types: struct _lp_lex_env { struct _lp_key lp_k[32]; unsigned char char_enum[128]; struct _lp_list lex_list; unsigned int line; }

user_defined_types: struct _lp_parse_env { struct _lp_list parse_out; struct _lp_table parse_table; struct _lp_list *token_list; unsigned long read_inx; unsigned int line; struct _lp_list clo_stack; struct _lp_string mes_name; }

user_defined_types: struct _lp_table { struct _lp_table_one *table_list[128]; unsigned long table_len; }

user_defined_types: struct _lp_table_one { int value; struct _lp_string name; struct _lp_table_one *next; }


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

result = 0LL;
if ( a1 )
{
cls_lex_env();
free_parse_env(a1 + 704);
get_parse_env(a1 + 704, a1 + 640);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
cls_lex_env();
free_parse_env(a1 + 704);
get_parse_env(a1 + 704, a1 + 640);
result = 1LL;
}
return result;
}

original_code:
int clr_lp_env(lp_env* lp)
{
 do{if((lp)==(((void *)0))) return ((LP_FAIL));}while(0);
 cls_lex_env(&lp->lex_envV);
 free_parse_env(&lp->parse_envV);
 get_parse_env(&lp->parse_envV, &lp->lex_envV.lex_list);
 return LP_TRUE;
}

canonical_original_code:
int clr_lp_env(struct _lp_env *lp)
{
 do{if((lp)==(((void *)0))) return ((LP_FAIL));}while(0);
 cls_lex_env(&lp->lex_envV);
 free_parse_env(&lp->parse_envV);
 get_parse_env(&lp->parse_envV, &lp->lex_envV.lex_list);
 return LP_TRUE;
}

user_defined_types: struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; }

user_defined_types: struct _lp_key { char *s_key; unsigned char s_tt; }

user_defined_types: struct _lp_string { struct _lp_list str; }


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

if ( a1 )
{
free_lex_env();
free_parse_env(a1 + 704);
result = lp_free(a1);
}
return result;
}

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

if ( a1 )
{
free_lex_env();
free_parse_env(a1 + 704);
result = lp_free(a1);
}
return result;
}

original_code:
void free_lp_env(lp_env* lp)
{
 if(lp==((void *)0))
  return;
 free_lex_env(&lp->lex_envV);
 free_parse_env(&lp->parse_envV);
 lp_free(lp);
}

canonical_original_code:
void free_lp_env(struct _lp_env *lp)
{
 if(lp==((void *)0))
  return;
 free_lex_env(&lp->lex_envV);
 free_parse_env(&lp->parse_envV);
 lp_free(lp);
}


decompiled_code:
char __fastcall lp_arg(__int64 a1, const char **a2)
{
const char *v2; // rax
bool v4; // zf
__int64 v5; // rsi
const char **v6; // rbx

v2 = a2[1];
if ( v2 && strcmp(a2[1], "-h") )
{
if ( !strcmp(v2, "-v") )
{
LOBYTE(v2) = puts("lite-proto interpreter version:2.0");
}
else
{
v4 = strcmp(v2, "-o") == 0;
LOBYTE(v2) = !v4;
if ( v4 )
{
v5 = (__int64)a2[2];
if ( v5 )
{
v6 = a2 + 3;
do
{
LODWORD(v2) = lp_inter(a1, v5);
if ( !(_DWORD)v2 )
break;
v5 = (__int64)*v6++;
}
while ( v5 );
}
}
else
{
LOBYTE(v2) = printf("%s cmd is error! please input %s -h see help.\n", *a2, *a2);
}
}
}
else
{
LOBYTE(v2) = printf(
"%s\n%s%s\n%s\n%s\n",
"lp help:",
"-v : ",
"lite-proto interpreter version:2.0",
"-o : parse the .mes file into .mes.lpb data file. exp: lp mesfile[ mesfile[ mesfile[ ...]]]",
"-h : lp help, by zixunlv.");
}
return (char)v2;
}

canonical_decompiled_code:
char __fastcall func4(__int64 a1, const char **a2)
{
const char *v2; // rax
bool v4; // zf
__int64 v5; // rsi
const char **v6; // rbx

v2 = a2[1];
if ( v2 && strcmp(a2[1], "-h") )
{
if ( !strcmp(v2, "-v") )
{
LOBYTE(v2) = puts("lite-proto interpreter version:2.0");
}
else
{
v4 = strcmp(v2, "-o") == 0;
LOBYTE(v2) = !v4;
if ( v4 )
{
v5 = (__int64)a2[2];
if ( v5 )
{
v6 = a2 + 3;
do
{
LODWORD(v2) = func3(a1, v5);
if ( !(_DWORD)v2 )
break;
v5 = (__int64)*v6++;
}
while ( v5 );
}
}
else
{
LOBYTE(v2) = printf("%s cmd is error! please input %s -h see help.\n", *a2, *a2);
}
}
}
else
{
LOBYTE(v2) = printf(
"%s\n%s%s\n%s\n%s\n",
"lp help:",
"-v : ",
"lite-proto interpreter version:2.0",
"-o : parse the .mes file into .mes.lpb data file. exp: lp mesfile[ mesfile[ mesfile[ ...]]]",
"-h : lp help, by zixunlv.");
}
return (char)v2;
}

original_code:
void lp_arg(lp_env* lp, char* args[])
{
 if(args[1]==0 || strcmp(args[1], "-h")==0)
 {
  printf("%s\n%s%s\n%s\n%s\n",
     "lp    help:",
     "-v :  ", "lite-proto interpreter version:2.0",
     "-o :  parse the .mes file into .mes.lpb data file. exp: lp mesfile[ mesfile[ mesfile[ ...]]]",
     "-h :  lp help, by zixunlv."
    );
 }
 else if(strcmp(args[1], "-v")==0)
 {
  printf("%s\n", "lite-proto interpreter version:2.0");
 }
 else if(strcmp(args[1], "-o")==0)
 {
  int i;
  for(i=2; args[i]!=((void *)0); i++){
   if(lp_inter(lp, args[i])==LP_FAIL)
    return;
  }
 }
 else
  printf("%s cmd is error! please input %s -h  see help.\n", args[0], args[0]);
}

canonical_original_code:
void lp_arg(struct _lp_env *lp, char *args[])
{
 if(args[1]==0 || strcmp(args[1], "-h")==0)
 {
  printf("%s\n%s%s\n%s\n%s\n",
     "lp    help:",
     "-v :  ", "lite-proto interpreter version:2.0",
     "-o :  parse the .mes file into .mes.lpb data file. exp: lp mesfile[ mesfile[ mesfile[ ...]]]",
     "-h :  lp help, by zixunlv."
    );
 }
 else if(strcmp(args[1], "-v")==0)
 {
  printf("%s\n", "lite-proto interpreter version:2.0");
 }
 else if(strcmp(args[1], "-o")==0)
 {
  int i;
  for(i=2; args[i]!=((void *)0); i++){
   if(lp_inter(lp, args[i])==LP_FAIL)
    return;
  }
 }
 else
  printf("%s cmd is error! please input %s -h  see help.\n", args[0], args[0]);
}

variable_types:
args
char *[]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx

v3 = get_lp_env();
lp_arg((__int64)v3, argv);
free_lp_env((__int64)v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx

v3 = func0();
func4((__int64)v3, argv);
func2((__int64)v3);
return 0;
}

original_code:
int main(int argc, char* args[])
{
 lp_env* lp = get_lp_env();
 lp_arg(lp, args);
 free_lp_env(lp);
 return 0;
}

canonical_original_code:
int main(int argc, char *args[])
{
 struct _lp_env *lp = get_lp_env();
 lp_arg(lp, args);
 free_lp_env(lp);
 return 0;
}

variable_types: argc int


original_code:
static void lib_map_reflush(llp_map* l_map)
{
 size_t i, new_size=l_map->size+256, hash;
 llp_slot* new_slot = (llp_slot*)lp_malloc(sizeof(llp_slot)*new_size);
 memset(new_slot, 0, sizeof(llp_slot)*new_size);
 for(i=0; i<l_map->size; i++)
 {
  hash = l_map->table[i].hash % new_size;
  if(new_slot[hash].key == ((void *)0))
  {
   new_slot[hash].key = l_map->table[i].key;
   new_slot[hash].hash = l_map->table[i].hash;
   new_slot[hash].vp = l_map->table[i].vp;
  }
  else
  {
   size_t emp = hash;
   for(;new_slot[emp].key!=((void *)0);)
    emp = (emp + 1) % new_size;
   new_slot[emp].key = l_map->table[i].key;
   new_slot[emp].hash = l_map->table[i].hash;
   new_slot[emp].vp = l_map->table[i].vp;
   new_slot[emp].next = new_slot[hash].next;
   new_slot[hash].next = emp+1;
  }
 }
 lp_free(l_map->table);
 l_map->size = new_size;
 l_map->table = new_slot;
}

canonical_original_code:
static void lib_map_reflush(struct _llp_map *l_map)
{
 unsigned long i; unsigned long new_size = l_map->size+256; unsigned long hash;
 struct _llp_slot *new_slot = (llp_slot*)lp_malloc(sizeof(llp_slot)*new_size);
 memset(new_slot, 0, sizeof(llp_slot)*new_size);
 for(i=0; i<l_map->size; i++)
 {
  hash = l_map->table[i].hash % new_size;
  if(new_slot[hash].key == ((void *)0))
  {
   new_slot[hash].key = l_map->table[i].key;
   new_slot[hash].hash = l_map->table[i].hash;
   new_slot[hash].vp = l_map->table[i].vp;
  }
  else
  {
   unsigned long emp = hash;
   for(;new_slot[emp].key!=((void *)0);)
    emp = (emp + 1) % new_size;
   new_slot[emp].key = l_map->table[i].key;
   new_slot[emp].hash = l_map->table[i].hash;
   new_slot[emp].vp = l_map->table[i].vp;
   new_slot[emp].next = new_slot[hash].next;
   new_slot[hash].next = emp+1;
  }
 }
 lp_free(l_map->table);
 l_map->size = new_size;
 l_map->table = new_slot;
}

variable_types: struct _llp_map { unsigned long size; unsigned long cap; struct _llp_slot { unsigned long hash; char *key; void *vp; unsigned long next; } *table; } *

variable_types:
i
unsigned long

variable_types:
hash
unsigned long

variable_types:
emp
unsigned long

user_defined_types: struct _llp_map { unsigned long size; unsigned long cap; struct _llp_slot *table; }


decompiled_code:
size_t __fastcall calc_hash(const char *a1)
{
size_t v1; // rdx
size_t v2; // rcx
unsigned __int64 i; // rsi

v1 = strlen(a1);
v2 = v1;
for ( i = (v1 >> 5) + 1; i <= v1; v1 -= i )
v2 ^= a1[v1 - 1] + (v2 >> 2) + 32 * v2;
return v2;
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
size_t v1; // rdx
size_t v2; // rcx
unsigned __int64 i; // rsi

v1 = strlen(a1);
v2 = v1;
for ( i = (v1 >> 5) + 1; i <= v1; v1 -= i )
v2 ^= a1[v1 - 1] + (v2 >> 2) + 32 * v2;
return v2;
}

original_code:
static size_t calc_hash(const char* name)
{
 size_t len = strlen(name);
 size_t h = len;
 size_t step = (len>>5)+1;
 size_t i;
 for (i=len; i>=step; i-=step)
  h = h ^ ((h<<5)+(h>>2)+(size_t)name[i-1]);
 return h;
}

canonical_original_code:
static unsigned long calc_hash(char *name)
{
 unsigned long len = strlen(name);
 unsigned long h = len;
 unsigned long step = (len>>5)+1;
 unsigned long i;
 for (i=len; i>=step; i-=step)
  h = h ^ ((h<<5)+(h>>2)+(unsigned long)name[i-1]);
 return h;
}

variable_types:
name
char *

variable_types:
h
unsigned long

variable_types:
step
unsigned long


decompiled_code:
_QWORD *lib_map_new()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax

v0 = (_QWORD *)lp_malloc(24LL);
*v0 = 256LL;
v0[1] = 0LL;
v1 = (_QWORD *)lp_malloc(0x2000LL);
v0[2] = v1;
*v1 = 0LL;
v1[1023] = 0LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 0x2000) >> 3));
return v0;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax

v0 = (_QWORD *)lp_malloc(24LL);
*v0 = 256LL;
v0[1] = 0LL;
v1 = (_QWORD *)lp_malloc(0x2000LL);
v0[2] = v1;
*v1 = 0LL;
v1[1023] = 0LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 0x2000) >> 3));
return v0;
}

original_code:
llp_map* lib_map_new()
{
 llp_map* ret = (llp_map*)lp_malloc(sizeof(llp_map));
 ret->size = 256;
 ret->cap = 0;
 ret->table = (llp_slot*)lp_malloc(sizeof(llp_slot)*256);
 memset(ret->table, 0, sizeof(llp_slot)*256);
 return ret;
}

canonical_original_code:
struct _llp_map *lib_map_new()
{
 struct _llp_map *ret = (llp_map*)lp_malloc(sizeof(llp_map));
 ret->size = 256;
 ret->cap = 0;
 ret->table = (struct _llp_slot *)lp_malloc(sizeof(llp_slot)*256);
 memset(ret->table, 0, sizeof(llp_slot)*256);
 return ret;
}

return_type: struct _llp_map { unsigned long size; unsigned long cap; struct _llp_slot { unsigned long hash; char *key; void *vp; unsigned long next; } *table; } *


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

if ( a1 )
{
lp_free(*(_QWORD *)(a1 + 16));
result = lp_free(a1);
}
return result;
}

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

if ( a1 )
{
lp_free(*(_QWORD *)(a1 + 16));
result = lp_free(a1);
}
return result;
}

original_code:
void lib_map_free(llp_map* l_map)
{
 if(l_map)
 {
  lp_free(l_map->table);
  lp_free(l_map);
 }
}

canonical_original_code:
void lib_map_free(struct _llp_map *l_map)
{
 if(l_map)
 {
  lp_free(l_map->table);
  lp_free(l_map);
 }
}

user_defined_types: struct _llp_slot { unsigned long hash; char *key; void *vp; unsigned long next; }


decompiled_code:
const char *__fastcall lib_map_find(unsigned __int64 *a1, const char *a2)
{
unsigned __int64 v3; // rbx
const char *v4; // rsi
size_t v5; // rbp
unsigned __int64 v6; // r12
_QWORD *v7; // rbx
__int64 v8; // rbx

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v3 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = calc_hash(a2);
v6 = a1[2];
v7 = (_QWORD *)(v6 + 32 * (v5 % v3));
v4 = (const char *)v7[1];
if ( v4 )
{
while ( 1 )
{
if ( *v7 == v5 && !strcmp(a2, v4) )
return (const char *)(v7 + 2);
v8 = v7[3];
if ( !v8 )
break;
v7 = (_QWORD *)(v6 + 32 * (v8 - 1));
v4 = (const char *)v7[1];
if ( !v4 )
return v4;
}
v4 = 0LL;
}
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned __int64 *a1, const char *a2)
{
unsigned __int64 v3; // rbx
const char *v4; // rsi
size_t v5; // rbp
unsigned __int64 v6; // r12
_QWORD *v7; // rbx
__int64 v8; // rbx

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v3 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = func1(a2);
v6 = a1[2];
v7 = (_QWORD *)(v6 + 32 * (v5 % v3));
v4 = (const char *)v7[1];
if ( v4 )
{
while ( 1 )
{
if ( *v7 == v5 && !strcmp(a2, v4) )
return (const char *)(v7 + 2);
v8 = v7[3];
if ( !v8 )
break;
v7 = (_QWORD *)(v6 + 32 * (v8 - 1));
v4 = (const char *)v7[1];
if ( !v4 )
return v4;
}
v4 = 0LL;
}
}
return v4;
}

original_code:
void** lib_map_find(llp_map* l_map, const char* key)
{
 size_t hash_full, hash;
 do{if((l_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((key)==(((void *)0))) return ((((void *)0)));}while(0);
 if(!(l_map->size)) return ((void *)0);
 hash_full = calc_hash(key);
 hash = hash_full % l_map->size;
 for(;l_map->table[hash].key!=((void *)0);)
 {
  if(l_map->table[hash].hash==hash_full && strcmp(key, l_map->table[hash].key)==0)
   return &(l_map->table[hash].vp);
  if(l_map->table[hash].next==0)
   return ((void *)0);
  hash = l_map->table[hash].next -1;
 }
 return ((void *)0);
}

canonical_original_code:
void **lib_map_find(struct _llp_map *l_map, char *key)
{
 unsigned long hash_full; unsigned long hash;
 do{if((l_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((key)==(((void *)0))) return ((((void *)0)));}while(0);
 if(!(l_map->size)) return ((void *)0);
 hash_full = calc_hash(key);
 hash = hash_full % l_map->size;
 for(;l_map->table[hash].key!=((void *)0);)
 {
  if(l_map->table[hash].hash==hash_full && strcmp(key, l_map->table[hash].key)==0)
   return &(l_map->table[hash].vp);
  if(l_map->table[hash].next==0)
   return ((void *)0);
  hash = l_map->table[hash].next -1;
 }
 return ((void *)0);
}

variable_types:
key
char *

return_type: void **


original_code:
int lib_map_add(llp_map* l_map, llp_kv* kv)
{
 size_t hash, sh;
 do{if((l_map)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((kv)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((kv->key)==(((void *)0))) return ((LP_FAIL));}while(0);
 hash = calc_hash(kv->key);
 if(l_map->cap >= l_map->size)
  lib_map_reflush(l_map);
 sh = hash % l_map->size;
 if(l_map->table[sh].key == ((void *)0))
 {
  l_map->table[sh].key = kv->key;
  l_map->table[sh].hash = hash;
  l_map->table[sh].vp = kv->vp;
 }
 else
 {
  size_t emp = sh;
  size_t idx = sh;
  for( ;; )
  {
   if(l_map->table[idx].hash == hash && strcmp(l_map->table[idx].key, kv->key)==0)
    return LP_EXIST;
   if(l_map->table[idx].next==0)
    break;
   idx = l_map->table[idx].next -1;
  }
  for( ;l_map->table[emp].key!=((void *)0); )
   emp=(emp +1)%l_map->size;
  l_map->table[emp].hash = hash;
  l_map->table[emp].key = kv->key;
  l_map->table[emp].vp = kv->vp;
  l_map->table[emp].next = l_map->table[sh].next;
  l_map->table[sh].next = emp+1;
 }
 l_map->cap++;
 return LP_TRUE;
}

canonical_original_code:
int lib_map_add(struct _llp_map *l_map, struct _llp_kv *kv)
{
 unsigned long hash; unsigned long sh;
 do{if((l_map)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((kv)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((kv->key)==(((void *)0))) return ((LP_FAIL));}while(0);
 hash = calc_hash(kv->key);
 if(l_map->cap >= l_map->size)
  lib_map_reflush(l_map);
 sh = hash % l_map->size;
 if(l_map->table[sh].key == ((void *)0))
 {
  l_map->table[sh].key = kv->key;
  l_map->table[sh].hash = hash;
  l_map->table[sh].vp = kv->vp;
 }
 else
 {
  unsigned long emp = sh;
  unsigned long idx = sh;
  for( ;; )
  {
   if(l_map->table[idx].hash == hash && strcmp(l_map->table[idx].key, kv->key)==0)
    return LP_EXIST;
   if(l_map->table[idx].next==0)
    break;
   idx = l_map->table[idx].next -1;
  }
  for( ;l_map->table[emp].key!=((void *)0); )
   emp=(emp +1)%l_map->size;
  l_map->table[emp].hash = hash;
  l_map->table[emp].key = kv->key;
  l_map->table[emp].vp = kv->vp;
  l_map->table[emp].next = l_map->table[sh].next;
  l_map->table[sh].next = emp+1;
 }
 l_map->cap++;
 return LP_TRUE;
}

variable_types: struct _llp_kv { char *key; void *vp; } *

variable_types:
sh
unsigned long

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall lib_Mmap_add(unsigned __int64 *a1, const char *a2)
{
_QWORD *v2; // rax
int v3; // eax
__int64 result; // rax
__int64 v5; // rdx
const char *v6; // [rsp+0h] [rbp-28h] BYREF
_QWORD *v7; // [rsp+8h] [rbp-20h]

v6 = a2;
v2 = (_QWORD *)lp_malloc(40LL);
v7 = v2;
*v2 = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
v2[4] = 0LL;
v3 = lib_map_add(a1, (__int64)&v6);
if ( v3 )
{
if ( v3 != 3
|| (lp_free(v7), v5 = *(_QWORD *)lib_map_find(a1, a2), v7 = (_QWORD *)v5, !*(_QWORD *)(v5 + 16))
|| (result = 0LL, !*(_QWORD *)(v5 + 24)) )
{
result = (__int64)v7;
}
}
else
{
lp_free(v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 *a1, const char *a2)
{
_QWORD *v2; // rax
int v3; // eax
__int64 result; // rax
__int64 v5; // rdx
const char *v6; // [rsp+0h] [rbp-28h] BYREF
_QWORD *v7; // [rsp+8h] [rbp-20h]

v6 = a2;
v2 = (_QWORD *)lp_malloc(40LL);
v7 = v2;
*v2 = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
v2[4] = 0LL;
v3 = func5(a1, (__int64)&v6);
if ( v3 )
{
if ( v3 != 3
|| (lp_free(v7), v5 = *(_QWORD *)func4(a1, a2), v7 = (_QWORD *)v5, !*(_QWORD *)(v5 + 16))
|| (result = 0LL, !*(_QWORD *)(v5 + 24)) )
{
result = (__int64)v7;
}
}
else
{
lp_free(v7);
result = 0LL;
}
return result;
}

original_code:
t_def_mes* lib_Mmap_add(llp_map* l_map, char* message_name)
{
 int ret=0;
 llp_kv kv = {0};
 kv.key = message_name;
 kv.vp = lp_malloc(sizeof(t_def_mes));
 memset(kv.vp, 0, sizeof(t_def_mes));
 ret=lib_map_add(l_map, &kv);
 if(ret == LP_FAIL)
 {
  lp_free(kv.vp);
  return ((void *)0);
 }
 else if(ret==LP_EXIST)
 {
  t_def_mes* _vp = ((void *)0);
  lp_free(kv.vp);
  _vp = kv.vp=*(lib_map_find(l_map, message_name));
  if(_vp->message_field != ((void *)0) && _vp->message_tfl != ((void *)0))
   return ((void *)0);
 }
 return (t_def_mes*)kv.vp;
}

canonical_original_code:
struct _t_def_mes *lib_Mmap_add(struct _llp_map *l_map, char *message_name)
{
 int ret = 0;
 struct _llp_kv kv = {0};
 kv.key = message_name;
 kv.vp = lp_malloc(sizeof(t_def_mes));
 memset(kv.vp, 0, sizeof(t_def_mes));
 ret=lib_map_add(l_map, &kv);
 if(ret == LP_FAIL)
 {
  lp_free(kv.vp);
  return ((void *)0);
 }
 else if(ret==LP_EXIST)
 {
  struct _t_def_mes *_vp = ((void *)0);
  lp_free(kv.vp);
  _vp = kv.vp=*(lib_map_find(l_map, message_name));
  if(_vp->message_field != ((void *)0) && _vp->message_tfl != ((void *)0))
   return ((void *)0);
 }
 return (struct _t_def_mes *)kv.vp;
}

variable_types: ret int

variable_types:
kv
struct _llp_kv { char *key; void *vp; }

variable_types: struct _t_def_mes { unsigned int message_id; char *message_name; struct _field_map { unsigned long size; struct _field_slot { char *field_name; int id; unsigned long hash; unsigned long next; } *slot; } *message_field; struct _t_Mfield { unsigned char tag; char *field_name; struct _t_def_mes *tms; } *message_tfl; unsigned int message_count; } *

user_defined_types: struct _t_def_mes { unsigned int message_id; char *message_name; struct _field_map *message_field; struct _t_Mfield *message_tfl; unsigned int message_count; }

user_defined_types: struct _field_map { unsigned long size; struct _field_slot *slot; }


decompiled_code:
const char *__fastcall lib_Mmap_find(unsigned __int64 *a1, const char *a2)
{
const char *result; // rax

if ( !a2 || !a1 )
return 0LL;
result = lib_map_find(a1, a2);
if ( result )
result = *(const char **)result;
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(unsigned __int64 *a1, const char *a2)
{
const char *result; // rax

if ( !a2 || !a1 )
return 0LL;
result = func4(a1, a2);
if ( result )
result = *(const char **)result;
return result;
}

original_code:
t_def_mes* lib_Mmap_find(llp_map* l_map, char* message_name)
{
 void** ret = ((void *)0);
 do{if((l_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((message_name)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((ret = lib_map_find(l_map, message_name))==(((void *)0))) return ((((void *)0)));}while(0);
 return (t_def_mes*)(*ret);
}

canonical_original_code:
struct _t_def_mes *lib_Mmap_find(struct _llp_map *l_map, char *message_name)
{
 void **ret = ((void *)0);
 do{if((l_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((message_name)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((ret = lib_map_find(l_map, message_name))==(((void *)0))) return ((((void *)0)));}while(0);
 return (struct _t_def_mes *)(*ret);
}

variable_types:
ret
void **

return_type: struct _t_def_mes { unsigned int message_id; char *message_name; struct _field_map { unsigned long size; struct _field_slot { char *field_name; int id; unsigned long hash; unsigned long next; } *slot; } *message_field; struct _t_Mfield { unsigned char tag; char *field_name; struct _t_def_mes *tms; } *message_tfl; unsigned int message_count; } *


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

if ( a1 )
result = lp_free(a1);
return result;
}

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

if ( a1 )
result = lp_free(a1);
return result;
}

original_code:
void lib_Fmap_free(field_map* f_map)
{
 if(f_map)
  lp_free(f_map);
}

canonical_original_code:
void lib_Fmap_free(struct _field_map *f_map)
{
 if(f_map)
  lp_free(f_map);
}

variable_types: struct _field_map { unsigned long size; struct _field_slot { char *field_name; int id; unsigned long hash; unsigned long next; } *slot; } *


original_code:
void lib_Mmap_free(llp_map* l_map)
{
 size_t i;
 t_def_mes* temp = ((void *)0);
 if(l_map==((void *)0))
  return;
 for(i=0; i<l_map->size; i++)
 {
  if(l_map->table[i].key == ((void *)0))
   continue;
  temp = (t_def_mes*)l_map->table[i].vp;
  lib_Fmap_free(temp->message_field);
  lp_free(temp->message_tfl);
  lp_free(temp);
 }
 lib_map_free(l_map);
}

canonical_original_code:
void lib_Mmap_free(struct _llp_map *l_map)
{
 unsigned long i;
 struct _t_def_mes *temp = ((void *)0);
 if(l_map==((void *)0))
  return;
 for(i=0; i<l_map->size; i++)
 {
  if(l_map->table[i].key == ((void *)0))
   continue;
  temp = (struct _t_def_mes *)l_map->table[i].vp;
  lib_Fmap_free(temp->message_field);
  lp_free(temp->message_tfl);
  lp_free(temp);
 }
 lib_map_free(l_map);
}

user_defined_types: struct _t_Mfield { unsigned char tag; char *field_name; struct _t_def_mes *tms; }

user_defined_types: struct _field_slot { char *field_name; int id; unsigned long hash; unsigned long next; }


original_code:
int lib_Fmap_add(field_map* f_map, char* field_name, int id)
{
 size_t hash, emp, sh, hash_full;
 do{if((f_map)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((field_name)==(((void *)0))) return ((LP_FAIL));}while(0);
 hash_full =calc_hash(field_name);
 hash = hash_full % f_map->size;
 sh = hash;
 if(f_map->slot[hash].field_name == ((void *)0))
 {
  f_map->slot[hash].field_name = field_name;
  f_map->slot[hash].id = id;
  f_map->slot[hash].hash = hash_full;
 }
 else
 {
  for( ;; )
  {
   if(f_map->slot[sh].hash== hash_full && strcmp(f_map->slot[sh].field_name, field_name)==0)
    return LP_EXIST;
   if(f_map->slot[sh].next==0)
    break;
   sh = f_map->slot[sh].next -1;
  }
  emp = hash;
  for(;f_map->slot[emp].field_name!=((void *)0);)
   emp = (emp + 1)%f_map->size;
  f_map->slot[emp].next = f_map->slot[hash].next;
  f_map->slot[hash].next = emp + 1;
  f_map->slot[emp].field_name = field_name;
  f_map->slot[emp].id = id;
  f_map->slot[emp].hash = hash_full;
 }
 return LP_TRUE;
}

canonical_original_code:
int lib_Fmap_add(struct _field_map *f_map, char *field_name, int id)
{
 unsigned long hash; unsigned long emp; unsigned long sh; unsigned long hash_full;
 do{if((f_map)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((field_name)==(((void *)0))) return ((LP_FAIL));}while(0);
 hash_full =calc_hash(field_name);
 hash = hash_full % f_map->size;
 sh = hash;
 if(f_map->slot[hash].field_name == ((void *)0))
 {
  f_map->slot[hash].field_name = field_name;
  f_map->slot[hash].id = id;
  f_map->slot[hash].hash = hash_full;
 }
 else
 {
  for( ;; )
  {
   if(f_map->slot[sh].hash== hash_full && strcmp(f_map->slot[sh].field_name, field_name)==0)
    return LP_EXIST;
   if(f_map->slot[sh].next==0)
    break;
   sh = f_map->slot[sh].next -1;
  }
  emp = hash;
  for(;f_map->slot[emp].field_name!=((void *)0);)
   emp = (emp + 1)%f_map->size;
  f_map->slot[emp].next = f_map->slot[hash].next;
  f_map->slot[hash].next = emp + 1;
  f_map->slot[emp].field_name = field_name;
  f_map->slot[emp].id = id;
  f_map->slot[emp].hash = hash_full;
 }
 return LP_TRUE;
}

variable_types: id int


decompiled_code:
const char *__fastcall lib_Fmap_find(unsigned __int64 *a1, const char *a2)
{
unsigned __int64 v3; // rbx
const char *v4; // rsi
size_t v5; // rbp
unsigned __int64 v6; // r12
unsigned __int64 v7; // rbx
__int64 v8; // rbx

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v3 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = calc_hash(a2);
v6 = a1[1];
v7 = v6 + 32 * (v5 % v3);
v4 = *(const char **)v7;
if ( *(_QWORD *)v7 )
{
while ( 1 )
{
if ( *(_QWORD *)(v7 + 16) == v5 && !strcmp(a2, v4) )
return (const char *)(v7 + 8);
v8 = *(_QWORD *)(v7 + 24);
if ( !v8 )
break;
v7 = v6 + 32 * (v8 - 1);
v4 = *(const char **)v7;
if ( !*(_QWORD *)v7 )
return v4;
}
v4 = 0LL;
}
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func11(unsigned __int64 *a1, const char *a2)
{
unsigned __int64 v3; // rbx
const char *v4; // rsi
size_t v5; // rbp
unsigned __int64 v6; // r12
unsigned __int64 v7; // rbx
__int64 v8; // rbx

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v3 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = func1(a2);
v6 = a1[1];
v7 = v6 + 32 * (v5 % v3);
v4 = *(const char **)v7;
if ( *(_QWORD *)v7 )
{
while ( 1 )
{
if ( *(_QWORD *)(v7 + 16) == v5 && !strcmp(a2, v4) )
return (const char *)(v7 + 8);
v8 = *(_QWORD *)(v7 + 24);
if ( !v8 )
break;
v7 = v6 + 32 * (v8 - 1);
v4 = *(const char **)v7;
if ( !*(_QWORD *)v7 )
return v4;
}
v4 = 0LL;
}
}
return v4;
}

original_code:
int* lib_Fmap_find(field_map* f_map, char* field_name)
{
 size_t hash, hash_full;
 do{if((f_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((field_name)==(((void *)0))) return ((((void *)0)));}while(0);
 if(!(f_map->size)) return ((void *)0);
 hash_full = calc_hash(field_name);
 hash = hash_full % f_map->size;
 for(;f_map->slot[hash].field_name!= ((void *)0);)
 {
  if(f_map->slot[hash].hash==hash_full && strcmp(field_name, f_map->slot[hash].field_name)==0)
   return &f_map->slot[hash].id;
  if(f_map->slot[hash].next==0)
   return ((void *)0);
  hash = f_map->slot[hash].next -1;
 }
 return ((void *)0);
}

canonical_original_code:
int *lib_Fmap_find(struct _field_map *f_map, char *field_name)
{
 unsigned long hash; unsigned long hash_full;
 do{if((f_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((field_name)==(((void *)0))) return ((((void *)0)));}while(0);
 if(!(f_map->size)) return ((void *)0);
 hash_full = calc_hash(field_name);
 hash = hash_full % f_map->size;
 for(;f_map->slot[hash].field_name!= ((void *)0);)
 {
  if(f_map->slot[hash].hash==hash_full && strcmp(field_name, f_map->slot[hash].field_name)==0)
   return &f_map->slot[hash].id;
  if(f_map->slot[hash].next==0)
   return ((void *)0);
  hash = f_map->slot[hash].next -1;
 }
 return ((void *)0);
}

return_type: int *


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

result = 0LL;
if ( a1 )
{
lp_list_free(a1 + 8);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
lp_list_free(a1 + 8);
result = 1LL;
}
return result;
}

original_code:
int lp_lex_token_free(lp_token* tp)
{
 do{if((tp)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&tp->name.str);
 return LP_TRUE;
}

canonical_original_code:
int lp_lex_token_free(struct _lp_token *tp)
{
 do{if((tp)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&tp->name.str);
 return LP_TRUE;
}

variable_types: struct _lp_token { unsigned int line; enum _e_t { t_error=0, t_num=1, t_lb=2, t_rb=3, t_ass=4, t_ll=5, t_rl=6, t_ide=7, t_end=8, t_clo=9, t_ca=10, t_Kextern=11, t_Kinteger=12, t_Kreal=13, t_kstring=14, t_Kbytes=15, t_Kmessage=16, t_count=17 } type; struct _lp_string { struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } str; } name; } *

user_defined_types: struct _lp_token { unsigned int line; enum _e_t type; struct _lp_string name; }


decompiled_code:
__int64 __fastcall lp_look_key(__int64 a1, const char *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12

if ( !a2 || !a1 )
return 0;
v2 = 16LL * (int)BKDRHash(a2, 32LL) + a1;
v3 = *(unsigned __int8 *)(v2 + 8);
if ( (_BYTE)v3 && strcmp(*(const char **)v2, a2) )
v3 = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12

if ( !a2 || !a1 )
return 0;
v2 = 16LL * (int)BKDRHash(a2, 32LL) + a1;
v3 = *(unsigned __int8 *)(v2 + 8);
if ( (_BYTE)v3 && strcmp(*(const char **)v2, a2) )
v3 = 0;
return v3;
}

original_code:
static byte lp_look_key(lp_lex_env* env_p, char* str)
{
 int inx = 0;
 do{if((env_p)==(((void *)0))) return ((t_error));}while(0);
 do{if((str)==(((void *)0))) return ((t_error));}while(0);
 inx = _BKDRHash(str, 32);
 return (env_p->lp_k[inx].s_tt==t_error || strcmp(env_p->lp_k[inx].s_key, str))?(t_error):(env_p->lp_k[inx].s_tt);
}

canonical_original_code:
static unsigned char lp_look_key(struct _lp_lex_env *env_p, char *str)
{
 int inx = 0;
 do{if((env_p)==(((void *)0))) return ((t_error));}while(0);
 do{if((str)==(((void *)0))) return ((t_error));}while(0);
 inx = _BKDRHash(str, 32);
 return (env_p->lp_k[inx].s_tt==t_error || strcmp(env_p->lp_k[inx].s_key, str))?(t_error):(env_p->lp_k[inx].s_tt);
}

variable_types: struct _lp_lex_env { struct _lp_key { char *s_key; unsigned char s_tt; } lp_k[32]; unsigned char char_enum[128]; struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } lex_list; unsigned int line; } *

variable_types:
str
char *

variable_types: inx int

return_type: unsigned char


decompiled_code:
__int64 __fastcall lp_add_token(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return lp_list_add(a1 + 640, &a7);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return lp_list_add(a1 + 640, &a7);
}

original_code:
static void lp_add_token(lp_lex_env* env_p, lp_token lp_t)
{
 lp_list_add( &((env_p)->lex_list), (byte*)(&(lp_t)) );
}

canonical_original_code:
static void lp_add_token(struct _lp_lex_env *env_p, struct _lp_token lp_t)
{
 lp_list_add( &((env_p)->lex_list), (unsigned char *)(&(lp_t)) );
}

variable_types: struct _lp_token { unsigned int line; enum _e_t { t_error=0, t_num=1, t_lb=2, t_rb=3, t_ass=4, t_ll=5, t_rl=6, t_ide=7, t_end=8, t_clo=9, t_ca=10, t_Kextern=11, t_Kinteger=12, t_Kreal=13, t_kstring=14, t_Kbytes=15, t_Kmessage=16, t_count=17 } type; struct _lp_string { struct _lp_list str; } name; }


decompiled_code:
__int64 __fastcall next_char(_BYTE **a1)
{
__int64 result; // rax
_BYTE *v2; // rdx

result = 0LL;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( *v2 )
{
result = (unsigned __int8)*v2;
*a1 = v2 + 1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE **a1)
{
__int64 result; // rax
_BYTE *v2; // rdx

result = 0LL;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( *v2 )
{
result = (unsigned __int8)*v2;
*a1 = v2 + 1;
}
}
}
return result;
}

original_code:
char next_char(slice* p)
{
 char ret = 0;
 if(p&&p->sp&&*(p->sp))
 {
  ret = *((char*)(p->sp));
  (p->sp)++;
 }
 return ret;
}

canonical_original_code:
char next_char(struct _slice *p)
{
 char ret = 0;
 if(p&&p->sp&&*(p->sp))
 {
  ret = *((char *)(p->sp));
  (p->sp)++;
 }
 return ret;
}

variable_types: struct _slice { unsigned char *sp; unsigned char *b_sp; unsigned int sp_size; } *

variable_types: ret char

return_type: char


decompiled_code:
__int64 __fastcall free_lex_env(_QWORD *a1)
{
__int64 result; // rax

lp_list_free(a1 + 80);
*a1 = 0LL;
a1[87] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 704) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 result; // rax

lp_list_free(a1 + 80);
*a1 = 0LL;
a1[87] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 704) >> 3));
return result;
}

original_code:
void free_lex_env(lp_lex_env* le)
{
 if(le==((void *)0))
  return;
 lp_list_free(&le->lex_list);
 memset(le, 0, sizeof(*le));
}

canonical_original_code:
void free_lex_env(struct _lp_lex_env *le)
{
 if(le==((void *)0))
  return;
 lp_list_free(&le->lex_list);
 memset(le, 0, sizeof(*le));
}


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

result = 0LL;
if ( a1 )
{
lp_list_free(a1 + 640);
*(_DWORD *)(a1 + 696) = 1;
result = (unsigned int)lp_list_new(a1 + 640, 64LL, 128LL, 0LL, lp_lex_token_free) != 0;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
lp_list_free(a1 + 640);
*(_DWORD *)(a1 + 696) = 1;
result = (unsigned int)lp_list_new(a1 + 640, 64LL, 128LL, 0LL, lp_lex_token_free) != 0;
}
return result;
}

original_code:
int cls_lex_env(lp_lex_env* le)
{
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&le->lex_list);
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (list_Ffree)lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

canonical_original_code:
int cls_lex_env(struct _lp_lex_env *le)
{
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&le->lex_list);
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (int (*)(void *))lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}


original_code:
int get_lex_env(lp_lex_env* le)
{
 int i=0;
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; lp_sk[i].s_key; i++)
 {
  int inx = _BKDRHash(lp_sk[i].s_key, 32);
  if(le->lp_k[inx].s_key)
  {
   printf("[init error]lp_key is not null! key=\"%s\" \n", le->lp_k[inx].s_key);
   return LP_FAIL;
  }
  else
   le->lp_k[inx] = lp_sk[i];
 }
 memset(le->char_enum, 0, sizeof(le->char_enum));
 le->char_enum['\t']= l_skip;
 le->char_enum[' ']= l_skip;
 le->char_enum['\r'] = l_skip;
 le->char_enum['\n']= l_n;
 le->char_enum['_']= l_char;
 le->char_enum['{']= l_lb;
 le->char_enum['}']= l_rb;
 le->char_enum['=']= l_ass;
 le->char_enum['[']= l_ll;
 le->char_enum[']']= l_rl;
 le->char_enum[',']= l_ca;
 le->char_enum['#']= l_text;
 le->char_enum[';']= l_end;
 le->char_enum['.']= l_clo;
 for(i='a'; i<='z'; i++)
  le->char_enum[i] = l_char;
 for(i='A'; i<='Z'; i++)
  le->char_enum[i] = l_char;
 for(i='0'; i<='9'; i++)
  le->char_enum[i] = l_num;
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (list_Ffree)lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

canonical_original_code:
int get_lex_env(struct _lp_lex_env *le)
{
 int i = 0;
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; lp_sk[i].s_key; i++)
 {
  int inx = _BKDRHash(lp_sk[i].s_key, 32);
  if(le->lp_k[inx].s_key)
  {
   printf("[init error]lp_key is not null! key=\"%s\" \n", le->lp_k[inx].s_key);
   return LP_FAIL;
  }
  else
   le->lp_k[inx] = lp_sk[i];
 }
 memset(le->char_enum, 0, sizeof(le->char_enum));
 le->char_enum['\t']= l_skip;
 le->char_enum[' ']= l_skip;
 le->char_enum['\r'] = l_skip;
 le->char_enum['\n']= l_n;
 le->char_enum['_']= l_char;
 le->char_enum['{']= l_lb;
 le->char_enum['}']= l_rb;
 le->char_enum['=']= l_ass;
 le->char_enum['[']= l_ll;
 le->char_enum[']']= l_rl;
 le->char_enum[',']= l_ca;
 le->char_enum['#']= l_text;
 le->char_enum[';']= l_end;
 le->char_enum['.']= l_clo;
 for(i='a'; i<='z'; i++)
  le->char_enum[i] = l_char;
 for(i='A'; i<='Z'; i++)
  le->char_enum[i] = l_char;
 for(i='0'; i<='9'; i++)
  le->char_enum[i] = l_num;
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (int (*)(void *))lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

variable_types: i int