gettimeticks

decompiled_code:
__int64 gettimeticks()
{
clock_t v0; // rbx
struct tms v2; // [rsp+0h] [rbp-28h] BYREF

v0 = times(&v2);
return 10000 * v0 / sysconf(2);
}

canonical_decompiled_code:
__int64 func0()
{
clock_t v0; // rbx
struct tms v2; // [rsp+0h] [rbp-28h] BYREF

v0 = times(&v2);
return 10000 * v0 / sysconf(2);
}

original_code:
long gettimeticks(void){
 struct tms t;
 return (long)((((long long)times(&t))*10000)/sysconf(_SC_CLK_TCK));
}

canonical_original_code:
long gettimeticks(){
 struct tms t;
 return (long)((((long long)times(&t))*10000)/sysconf(_SC_CLK_TCK));
}

variable_types: struct tms { long tms_utime; long tms_stime; long tms_cutime; long tms_cstime; }

return_type: long


decompiled_code:
__int64 __fastcall crc32_buf(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
unsigned int v3; // eax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = -1;
do
v3 = crc32tab[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( a1 != v2 );
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
unsigned int v3; // eax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = -1;
do
v3 = crc32tab[(unsigned __int8)(*a1++ ^ v3)] ^ (v3 >> 8);
while ( a1 != v2 );
return ~v3;
}

original_code:
uint32_t crc32_buf(const void *buf, size_t size)
{
    uint32_t crc = ~0;
    const uint8_t *p = buf;
    while (size--) crc = (crc >> 8) ^ crc32tab[(crc ^ (*p++)) & 0xFF];
    return ~crc;
}

canonical_original_code:
unsigned int crc32_buf(void *buf, unsigned long size)
{
    unsigned int crc = ~0;
    unsigned char *p = buf;
    while (size--) crc = (crc >> 8) ^ crc32tab[(crc ^ (*p++)) & 0xFF];
    return ~crc;
}

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types:
crc
unsigned int

variable_types:
p
unsigned char *

return_type: unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
bool v5; // r13
char *v6; // r14
char *v7; // rbp
__int64 v8; // r15
const char *v9; // rdi
bool v10; // r13
void *v11; // rax
void (__fastcall *v12)(void *, __int64, __int64); // r14
const char *v13; // rdi
int v14; // ebx
void *v15; // rdi
void *v17; // r13
struct timespec tp; // [rsp+10h] [rbp-58h] BYREF
struct timespec v19; // [rsp+20h] [rbp-48h] BYREF

v3 = 960LL;
getenv("DEBUG");
v5 = getenv("USE_MMAP") != 0LL;
v6 = getenv("XRES");
v7 = getenv("YRES");
if ( v6 )
v3 = strtol(v6, 0LL, 10);
v8 = 960LL;
if ( v7 )
v8 = strtol(v7, 0LL, 10);
v9 = 0LL;
v10 = argc > 2 || v5;
if ( argc > 1 )
v9 = argv[1];
v11 = dlopen(v9, 2);
v12 = (void (__fastcall *)(void *, __int64, __int64))dlsym(v11, "rgbfunc");
clock_gettime(0, &tp);
if ( !v10 )
{
v17 = malloc(6 * v8 * v3);
v12(v17, v3, v8);
write(1, v17, 6 * v8 * v3);
goto LABEL_12;
}
v13 = 0LL;
if ( argc > 2 )
v13 = argv[2];
v14 = open(v13, 66, 420LL);
ftruncate(v14, 6 * v8 * v3);
v15 = mmap(0LL, 6 * v8 * v3, 3, 1, v14, 0LL);
if ( v15 != (void *)-1LL )
{
v12(v15, v3, v8);
LABEL_12:
clock_gettime(0, &v19);
fprintf(
stderr,
"%s: Elapsed time, %g seconds.\n",
"main",
(double)SLODWORD(v19.tv_nsec) / 1000000000.0
+ (double)SLODWORD(v19.tv_sec)
- ((double)SLODWORD(tp.tv_nsec) / 1000000000.0
+ (double)SLODWORD(tp.tv_sec)));
return 0;
}
perror("mmap");
return -1;
}

original_code:
int main(int argc, char *argv[]) {
  long int debug = getenv("DEBUG") != ((void *)0);
  long int use_mmap = getenv("USE_MMAP") != ((void *)0);
  char *env_XRES = getenv("XRES");
  char *env_YRES = getenv("YRES");
  u_int16_t mono;
  long int xres = env_XRES != ((void *)0) ? strtol(env_XRES,((void *)0),10) : 960, yres = env_YRES != ((void *)0) ? strtol(env_YRES,((void *)0),10) : 960;
  size_t img_sz = xres*yres*sizeof(u_int16_t)*3;
  u_int16_t *rgb;
  void *handle;
  int (*rgbfunc)(u_int16_t *rgb, long int xres, long int yres);
  struct timespec before, after;
  use_mmap |= (argc>2);
  handle = dlopen(argc>1?argv[1]:((void *)0), 0x00002);
  rgbfunc = dlsym(handle, "rgbfunc");
  clock_gettime(0, &before);
  if (!use_mmap) {
    rgb = malloc(img_sz);
    rgbfunc(rgb, xres, yres);
    write(1,rgb,img_sz);
  }
  else {
    mode_t mode = 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3);
    char *filename = argc>2 ? argv[2] : ((void *)0);
    int fd = open(filename,02|0100,mode);
    int ftruncate_retval = ftruncate(fd,img_sz);
    void *m;
    m = mmap(((void *)0), img_sz, 0x1 | 0x2, 0x01, fd, 0);
    if (m==((void *) -1)) {
      perror("mmap");
      return -1;
    }
    rgb = (u_int16_t*) m;
    rgbfunc(rgb, xres, yres);
  }
  clock_gettime(0, &after);
  fprintf(stderr, "%s: Elapsed time, %g seconds.\n", __FUNCTION__, (after.tv_sec + after.tv_nsec / 1000000000.0) - (before.tv_sec + before.tv_nsec / 1000000000.0));
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  long debug = getenv("DEBUG") != ((void *)0);
  long use_mmap = getenv("USE_MMAP") != ((void *)0);
  char *env_XRES = getenv("XRES");
  char *env_YRES = getenv("YRES");
  unsigned int mono;
  long xres = env_XRES != ((void *)0) ? strtol(env_XRES,((void *)0),10) : 960; long yres = env_YRES != ((void *)0) ? strtol(env_YRES,((void *)0),10) : 960;
  unsigned long img_sz = xres*yres*sizeof(u_int16_t)*3;
  unsigned int *rgb;
  void *handle;
  int (*rgbfunc)(unsigned int *rgb, long xres, long yres);
  struct timespec before; struct timespec after;
  use_mmap |= (argc>2);
  handle = dlopen(argc>1?argv[1]:((void *)0), 0x00002);
  rgbfunc = dlsym(handle, "rgbfunc");
  clock_gettime(0, &before);
  if (!use_mmap) {
    rgb = malloc(img_sz);
    rgbfunc(rgb, xres, yres);
    write(1,rgb,img_sz);
  }
  else {
    unsigned int mode = 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3);
    char *filename = argc>2 ? argv[2] : ((void *)0);
    int fd = open(filename,02|0100,mode);
    int ftruncate_retval = ftruncate(fd,img_sz);
    void *m;
    m = mmap(((void *)0), img_sz, 0x1 | 0x2, 0x01, fd, 0);
    if (m==((void *) -1)) {
      perror("mmap");
      return -1;
    }
    rgb = (unsigned int *) m;
    rgbfunc(rgb, xres, yres);
  }
  clock_gettime(0, &after);
  fprintf(stderr, "%s: Elapsed time, %g seconds.\n", __FUNCTION__, (after.tv_sec + after.tv_nsec / 1000000000.0) - (before.tv_sec + before.tv_nsec / 1000000000.0));
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: debug long

variable_types:
mono
unsigned int

variable_types: xres long

variable_types: yres long

variable_types:
rgb
unsigned int *

variable_types:
handle
void *

variable_types: int (*)(unsigned int *rgb, long xres, long yres)

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

variable_types:
mode
unsigned int

variable_types:
filename
char *

variable_types: fd int

variable_types:
m
void *

return_type: int


repo: lvella/libestream

original_code:
static uint32_t
lfsr_step(sosemanuk_state *state)
{
  uint32_t *s = state->s;
  uint8_t t = state->t;
  uint32_t st0 = s[t];
  uint32_t st3 = s[(t+3)%10];
  s[t] = s[(t+9)%10]
    ^ (st3 >> 8) ^ div_a[st3 & 0xff]
    ^ (st0 << 8) ^ mul_a[st0 >> 24];
  state->t = (t+1) % 10;
  return st0;
}

canonical_original_code:
static unsigned int lfsr_step(struct sosemanuk_state *state)
{
  unsigned int *s = state->s;
  unsigned char t = state->t;
  unsigned int st0 = s[t];
  unsigned int st3 = s[(t+3)%10];
  s[t] = s[(t+9)%10]
    ^ (st3 >> 8) ^ div_a[st3 & 0xff]
    ^ (st0 << 8) ^ mul_a[st0 >> 24];
  state->t = (t+1) % 10;
  return st0;
}

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

variable_types:
s
unsigned int *

variable_types:
t
unsigned char


canonical_original_code:
static inline void sbox_apply(unsigned char sbox_idx, unsigned int *in, unsigned int *out)
{
  switch(sbox_idx)
    {
    case 0:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t6; register unsigned int t7; register unsigned int t8; register unsigned int t10; register unsigned int t11; register unsigned int t12; register unsigned int t14;
 t1 = in[0] ^ in[3]; t2 = in[0] & in[3]; t3 = in[2] ^ t1; t4 = in[1] ^ t3; out[3] = t2 ^ t4; t6 = in[1] & t1; t7 = in[0] ^ t6; t8 = in[2] | t7; out[2] = t4 ^ t8; t10 = ~t3; t11 = t3 ^ t7; t12 = out[3] & t11; out[1] = t10 ^ t12; t14 = ~t7; out[0] = t12 ^ t14;
 break;
      }
    case 1:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t7; register unsigned int t8; register unsigned int t9; register unsigned int t11; register unsigned int t13;
 t1 = ~in[0]; t2 = in[1] ^ t1; t3 = in[0] | t2; t4 = in[3] | t2; t5 = in[2] ^ t3; out[2] = in[3] ^ t5; t7 = in[1] ^ t4; t8 = t2 ^ out[2]; t9 = t5 & t7; out[3] = t8 ^ t9; t11 = t5 ^ t7; out[1] = out[3] ^ t11; t13 = t8 & t11; out[0] = t5 ^ t13;
 break;
      }
    case 2:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t5; register unsigned int t6; register unsigned int t7; register unsigned int t9; register unsigned int t10; register unsigned int t11; register unsigned int t13; register unsigned int t14; register unsigned int t15;
 t1 = ~in[0]; t2 = in[1] ^ in[3]; t3 = in[2] & t1; out[0] = t2 ^ t3; t5 = in[2] ^ t1; t6 = in[2] ^ out[0]; t7 = in[1] & t6; out[3] = t5 ^ t7; t9 = in[3] | t7; t10 = out[0] | t5; t11 = t9 & t10; out[2] = in[0] ^ t11; t13 = in[3] | t1; t14 = t2 ^ out[3]; t15 = out[2] ^ t13; out[1] = t14 ^ t15;
 break;
      }
    case 3:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t6; register unsigned int t8; register unsigned int t9; register unsigned int t10; register unsigned int t12; register unsigned int t14; register unsigned int t15;
 t1 = in[0] ^ in[1]; t2 = in[0] & in[2]; t3 = in[0] | in[3]; t4 = in[2] ^ in[3]; t5 = t1 & t3; t6 = t2 | t5; out[2] = t4 ^ t6; t8 = in[1] ^ t3; t9 = t6 ^ t8; t10 = t4 & t9; out[0] = t1 ^ t10; t12 = out[2] & out[0]; out[1] = t9 ^ t12; t14 = in[1] | in[3]; t15 = t4 ^ t12; out[3] = t14 ^ t15;
 break;
      }
    case 4:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t6; register unsigned int t7; register unsigned int t9; register unsigned int t10; register unsigned int t11; register unsigned int t13; register unsigned int t14;
 t1 = in[0] ^ in[3]; t2 = in[3] & t1; t3 = in[2] ^ t2; t4 = in[1] | t3; out[3] = t1 ^ t4; t6 = ~in[1]; t7 = t1 | t6; out[0] = t3 ^ t7; t9 = in[0] & out[0]; t10 = t1 ^ t6; t11 = t4 & t10; out[2] = t9 ^ t11; t13 = in[0] ^ t3; t14 = t10 & out[2]; out[1] = t13 ^ t14;
 break;
      }
    case 5:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t7; register unsigned int t8; register unsigned int t10; register unsigned int t11; register unsigned int t12; register unsigned int t14; register unsigned int t15;
 t1 = ~in[0]; t2 = in[0] ^ in[1]; t3 = in[0] ^ in[3]; t4 = in[2] ^ t1; t5 = t2 | t3; out[0] = t4 ^ t5; t7 = in[3] & out[0]; t8 = t2 ^ out[0]; out[1] = t7 ^ t8; t10 = t1 | out[0]; t11 = t2 | t7; t12 = t3 ^ t10; out[2] = t11 ^ t12; t14 = in[1] ^ t7; t15 = out[1] & t12; out[3] = t14 ^ t15;
 break;
      }
    case 6:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t7; register unsigned int t8; register unsigned int t9; register unsigned int t11; register unsigned int t13; register unsigned int t14;
 t1 = ~in[0]; t2 = in[0] ^ in[3]; t3 = in[1] ^ t2; t4 = t1 | t2; t5 = in[2] ^ t4; out[1] = in[1] ^ t5; t7 = t2 | out[1]; t8 = in[3] ^ t7; t9 = t5 & t8; out[2] = t3 ^ t9; t11 = t5 ^ t8; out[0] = out[2] ^ t11; t13 = ~t5; t14 = t3 & t11; out[3] = t13 ^ t14;
 break;
      }
    case 7:
      {
 register unsigned int t1; register unsigned int t2; register unsigned int t3; register unsigned int t4; register unsigned int t5; register unsigned int t6; register unsigned int t8; register unsigned int t9; register unsigned int t11; register unsigned int t12; register unsigned int t14; register unsigned int t15;
 t1 = in[1] ^ in[2]; t2 = in[2] & t1; t3 = in[3] ^ t2; t4 = in[0] ^ t3; t5 = in[3] | t1; t6 = t4 & t5; out[1] = in[1] ^ t6; t8 = t3 | out[1]; t9 = in[0] & t4; out[3] = t1 ^ t9; t11 = t4 ^ t8; t12 = out[3] & t11; out[2] = t3 ^ t12; t14 = ~t11; t15 = out[3] & out[2]; out[0] = t14 ^ t15;
 break;
      }
    }
}

variable_types:
in
unsigned int *

variable_types:
out
unsigned int *

return_type: void


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

for ( i = 0LL; i != 4; ++i )
v20[i] = *(_DWORD *)(a1 + 16LL * a2 + i * 4) ^ a3[i];
sbox_apply(a2 & 7, v20, a3);
v5 = rotl((unsigned int)*a3, 13LL);
v6 = (unsigned int)a3[2];
*a3 = v5;
v7 = rotl(v6, 3LL);
LODWORD(v6) = a3[1];
a3[2] = v7;
v8 = v7 ^ *a3 ^ (unsigned int)v6;
v9 = v7 ^ a3[3] ^ (8 * *a3);
a3[1] = v8;
a3[3] = v9;
v10 = rotl(v8, 1LL);
v11 = (unsigned int)a3[3];
a3[1] = v10;
v12 = rotl(v11, 7LL);
LODWORD(v11) = *a3;
v13 = v12;
a3[3] = v12;
v14 = a3[1];
v15 = v13 ^ v14 ^ (unsigned int)v11;
v16 = v13 ^ a3[2] ^ (v14 << 7);
*a3 = v15;
a3[2] = v16;
v17 = rotl(v15, 5LL);
v18 = (unsigned int)a3[2];
*a3 = v17;
result = rotl(v18, 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]


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:
r
unsigned int *

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


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

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_state { unsigned int r[2]; unsigned int s[10]; unsigned char t; } *

variable_types:
iv
unsigned char *

variable_types:
s
unsigned int *

variable_types:
data
unsigned int [4]

variable_types:
sk
unsigned int *


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

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

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

v2 = a2;
for ( i = 0LL; i != 4; ++i )
{
v7[i] = func3(a1);
v8[i] = func0((__int64)a1);
}
v4 = (char *)v8;
func1(2, v7, a2);
do
{
v5 = *(_DWORD *)v4 ^ (unsigned int)*v2;
v4 += 4;
result = unpack_littleendian(v5, v2++);
}
while ( v4 != &v9 );
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:
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; // eax

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; // eax

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; // eax

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; // eax

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
unsigned int v3; // eax
unsigned __int16 v5; // ax
__int64 v6; // rdx
__int64 v7; // r9

v2 = *(_WORD *)(a1 + 4096);
*(_WORD *)(a1 + 4096) = (v2 + 1) & 0x3FF;
if ( v2 > 0x1FFu )
{
v5 = m512(v2);
v3 = round_expression(v7, a1, v6, v5);
}
else
{
v3 = round_expression(a1, a1 + 2048, (__int64)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

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];
*(_BYTE *)(a1 + 8) = 0;
*(_QWORD *)a1 = result;
return result;
}

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

result = (&cipher_attributes_map)[a2];
*(_BYTE *)(a1 + 8) = 0;
*(_QWORD *)a1 = result;
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:
__int64 __fastcall buffered_skip(unsigned __int8 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rax
__int64 (__fastcall **v5)(__int64, unsigned __int8 *); // rcx
__int64 v6; // r15
unsigned __int64 v7; // rbx
__int64 v8; // r12
__int64 v9; // rdx
unsigned __int64 v10; // rdx
char v11; // r13
unsigned __int8 *v12; // r12
unsigned __int64 v13; // r14
int v14; // ebx

v2 = a1[8];
if ( v2 >= a2 )
{
result = (unsigned int)(v2 - a2);
a1[8] = v2 - a2;
return result;
}
v4 = buffered_get_cipher_state((__int64)a1);
v5 = *(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1;
v6 = v4;
v7 = *(unsigned __int8 *)(*(_QWORD *)a1 + 12LL);
v8 = *(unsigned __int16 *)(*(_QWORD *)a1 + 10LL);
a1[8] = 0;
result = (a2 - v9) / v7;
v10 = (a2 - v9) % v7;
v11 = v7;
v12 = &a1[v8];
v13 = v10;
v14 = result;
if ( (int)result > 0 )
{
while ( 1 )
{
result = (*v5)(v6, v12);
if ( !--v14 )
break;
v5 = *(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1;
}
if ( v13 )
goto LABEL_6;
}
else if ( v10 )
{
LABEL_6:
result = (**(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1)(v6, v12);
a1[8] = v11 - v13;
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rax
__int64 (__fastcall **v5)(__int64, unsigned __int8 *); // rcx
__int64 v6; // r15
unsigned __int64 v7; // rbx
__int64 v8; // r12
__int64 v9; // rdx
unsigned __int64 v10; // rdx
char v11; // r13
unsigned __int8 *v12; // r12
unsigned __int64 v13; // r14
int v14; // ebx

v2 = a1[8];
if ( v2 >= a2 )
{
result = (unsigned int)(v2 - a2);
a1[8] = v2 - a2;
return result;
}
v4 = func1((__int64)a1);
v5 = *(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1;
v6 = v4;
v7 = *(unsigned __int8 *)(*(_QWORD *)a1 + 12LL);
v8 = *(unsigned __int16 *)(*(_QWORD *)a1 + 10LL);
a1[8] = 0;
result = (a2 - v9) / v7;
v10 = (a2 - v9) % v7;
v11 = v7;
v12 = &a1[v8];
v13 = v10;
v14 = result;
if ( (int)result > 0 )
{
while ( 1 )
{
result = (*v5)(v6, v12);
if ( !--v14 )
break;
v5 = *(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1;
}
if ( v13 )
goto LABEL_6;
}
else if ( v10 )
{
LABEL_6:
result = (**(__int64 (__fastcall ***)(__int64, unsigned __int8 *))a1)(v6, v12);
a1[8] = v11 - v13;
return 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


rowround

decompiled_code:
__int64 __fastcall rowround(int *a1, _DWORD *a2)
{
int *v2; // rbp
__int64 result; // rax
__int64 v4; // [rsp+4h] [rbp-44h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch]
int v6[14]; // [rsp+10h] [rbp-38h] BYREF

quarterround(a1, a2);
v2 = (int *)&v4;
v4 = 0x9080B0A04070605LL;
v5 = 235736079;
do
{
permut_do_constprop_0((__int64)a1, (__int64)v6, (__int64)v2);
quarterround(v6, v6);
result = permut_undo_constprop_0((__int64)v6, (__int64)a2, (__int64)v2++);
}
while ( v2 != v6 );
return result;
}

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:
in
unsigned int *

variable_types:
out
unsigned int *

variable_types:
permut
unsigned char [3][4]

variable_types:
tmp
unsigned int [4]


columnround

decompiled_code:
__int64 __fastcall columnround(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 vars0[2]; // [rsp+0h] [rbp+0h] BYREF
int vars10[14]; // [rsp+10h] [rbp+10h] BYREF

vars0[0] = 0x10D09050C080400LL;
vars0[1] = 0xB07030F06020E0ALL;
do
{
permut_do_constprop_0(a1, (__int64)vars10, (__int64)vars0);
quarterround(vars10, vars10);
result = permut_undo_constprop_0((__int64)vars10, a2, (__int64)vars0);
}
while ( vars0 != (__int64 *)vars10 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 vars0[2]; // [rsp+0h] [rbp+0h] BYREF
int vars10[14]; // [rsp+10h] [rbp+10h] BYREF

vars0[0] = 0x10D09050C080400LL;
vars0[1] = 0xB07030F06020E0ALL;
do
{
func2(a1, (__int64)vars10, (__int64)vars0);
func0(vars10, vars10);
result = func1((__int64)vars10, a2, (__int64)vars0);
}
while ( vars0 != (__int64 *)vars10 );
return result;
}

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:
permut
unsigned char [4][4]


doubleround

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int *a2)
{
func4(a1, (__int64)a2);
return func3(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; // rbx
unsigned int *v4; // rbp
__int64 v5; // rdi
unsigned int *v6; // rsi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int *a2)
{
int *v2; // rbx
unsigned int *v4; // rbp
__int64 v5; // rdi
unsigned int *v6; // rsi
__int64 result; // rax

v2 = a2;
func6(*(_BYTE *)(a1 + 64), a1, a2);
if ( (*(_DWORD *)(a1 + 32))++ == -1 )
++*(_DWORD *)(a1 + 36);
v4 = (unsigned int *)(a2 + 16);
do
{
v5 = (unsigned int)*v2;
v6 = (unsigned int *)v2++;
result = unpack_littleendian(v5, v6);
}
while ( v4 != (unsigned int *)v2 );
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


decompiled_code:
__int64 __fastcall pack_littleendian(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return *a1;
}

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 *


decompiled_code:
_BOOL8 __fastcall mac_verify(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char s2[40]; // [rsp+10h] [rbp-28h] BYREF

v2 = (unsigned __int8)(4 * *(_BYTE *)(**(_QWORD **)(a1 + 16) + 6LL));
(*(void (__fastcall **)(__int64, _BYTE *, __int64))(a1 + 8))(a2, v4, v2);
buffered_action(*(_QWORD *)a1, v4, (unsigned __int8)v2, 1LL);
uhash_finish(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), s2);
return memcmp(v4, s2, (unsigned __int8)v2) == 0;
}

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)
{
unsigned __int8 v6; // bl
int v7; // eax
__int64 v8; // rbp
__int64 v9; // r8
unsigned int v10; // eax
__int64 v11; // rbp
__int64 v12; // rsi
unsigned __int16 v13; // r8
unsigned __int16 v14; // bx
unsigned int v15; // ebp
unsigned __int16 v16; // bx
__int64 v17; // r8
unsigned __int16 v18; // bx
__int64 result; // rax
__int64 v20; // rbp
unsigned int v21; // eax
unsigned int v22; // [rsp+8h] [rbp-1050h]
unsigned __int16 v24; // [rsp+18h] [rbp-1040h]
unsigned __int16 v25; // [rsp+1Ch] [rbp-103Ch]
unsigned __int8 v26; // [rsp+1Fh] [rbp-1039h]
int dest; // [rsp+20h] [rbp-1038h] BYREF
char v28[4148]; // [rsp+24h] [rbp-1034h] BYREF

v6 = 4 * *(_BYTE *)(*(_QWORD *)a1[2] + 6LL);
v26 = v6;
v7 = _uint32_identity(a4);
v8 = a1[3];
dest = v7;
v10 = uhash_get_type_from_key(v9);
uhash_init(v10, v8);
uhash_update(a1[2], a1[3], &dest, 4LL);
v25 = v6;
if ( a4 > 0x400 )
{
uhash_finish(a1[2], a1[3], v28);
v20 = a1[3];
v21 = uhash_get_type_from_key(a1[2]);
uhash_init(v21, v20);
v13 = v6 + 4;
v11 = v13;
v12 = 4096 - (unsigned int)v13;
}
else
{
v11 = 4LL;
v12 = 4092LL;
v13 = 4;
}
v24 = v13;
v14 = min(a4, v12);
memcpy((char *)&dest + v11, a3, v14);
v15 = v14;
uhash_update(a1[2], a1[3], a3, v14);
v16 = v24 + v14;
if ( v15 >= a4 )
{
v17 = v16;
}
else
{
do
{
buffered_action(*a1, &dest, v16, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v16);
v16 = min(a4 - v15, 4096LL);
memcpy(&dest, &a3[v15], v16);
uhash_update(a1[2], a1[3], &dest, v16);
v17 = v16;
v15 += v16;
}
while ( a4 > v15 );
}
if ( (unsigned __int16)(4096 - v16) < v25 )
{
v22 = v17;
buffered_action(*a1, &dest, v16, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v22);
uhash_finish(a1[2], a1[3], &dest);
buffered_action(*a1, &dest, v26, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v26);
}
else
{
v18 = v25 + v16;
uhash_finish(a1[2], a1[3], (char *)&dest + v17);
buffered_action(*a1, &dest, v18, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v18);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, char *a3, unsigned int a4)
{
unsigned __int8 v6; // bl
int v7; // eax
__int64 v8; // rbp
__int64 v9; // r8
unsigned int v10; // eax
__int64 v11; // rbp
__int64 v12; // rsi
unsigned __int16 v13; // r8
unsigned __int16 v14; // bx
unsigned int v15; // ebp
unsigned __int16 v16; // bx
__int64 v17; // r8
unsigned __int16 v18; // bx
__int64 result; // rax
__int64 v20; // rbp
unsigned int v21; // eax
unsigned int v22; // [rsp+8h] [rbp-1050h]
unsigned __int16 v24; // [rsp+18h] [rbp-1040h]
unsigned __int16 v25; // [rsp+1Ch] [rbp-103Ch]
unsigned __int8 v26; // [rsp+1Fh] [rbp-1039h]
int dest; // [rsp+20h] [rbp-1038h] BYREF
char v28[4148]; // [rsp+24h] [rbp-1034h] BYREF

v6 = 4 * *(_BYTE *)(*(_QWORD *)a1[2] + 6LL);
v26 = v6;
v7 = func0(a4);
v8 = a1[3];
dest = v7;
v10 = uhash_get_type_from_key(v9);
uhash_init(v10, v8);
uhash_update(a1[2], a1[3], &dest, 4LL);
v25 = v6;
if ( a4 > 0x400 )
{
uhash_finish(a1[2], a1[3], v28);
v20 = a1[3];
v21 = uhash_get_type_from_key(a1[2]);
uhash_init(v21, v20);
v13 = v6 + 4;
v11 = v13;
v12 = 4096 - (unsigned int)v13;
}
else
{
v11 = 4LL;
v12 = 4092LL;
v13 = 4;
}
v24 = v13;
v14 = min(a4, v12);
memcpy((char *)&dest + v11, a3, v14);
v15 = v14;
uhash_update(a1[2], a1[3], a3, v14);
v16 = v24 + v14;
if ( v15 >= a4 )
{
v17 = v16;
}
else
{
do
{
buffered_action(*a1, &dest, v16, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v16);
v16 = min(a4 - v15, 4096LL);
memcpy(&dest, &a3[v15], v16);
uhash_update(a1[2], a1[3], &dest, v16);
v17 = v16;
v15 += v16;
}
while ( a4 > v15 );
}
if ( (unsigned __int16)(4096 - v16) < v25 )
{
v22 = v17;
buffered_action(*a1, &dest, v16, 1LL);
((void (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v22);
uhash_finish(a1[2], a1[3], &dest);
buffered_action(*a1, &dest, v26, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v26);
}
else
{
v18 = v25 + v16;
uhash_finish(a1[2], a1[3], (char *)&dest + v17);
buffered_action(*a1, &dest, v18, 1LL);
result = ((__int64 (__fastcall *)(__int64, int *, _QWORD))a1[1])(a2, &dest, v18);
}
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 v6; // r12
unsigned int v7; // eax
unsigned int v8; // eax
_BOOL4 v9; // er8
__int64 result; // rax
unsigned int v11; // esi
char *v12; // r13
unsigned int v13; // er15
char *v14; // r13
unsigned __int16 v15; // ax
__int64 v16; // r12
_BOOL4 v17; // er8
__int64 v18; // r12
unsigned int v19; // eax
int v20; // [rsp+4h] [rbp-44h]

*a3 = 0LL;
((void (__fastcall *)(__int64, unsigned int *, __int64))a1[1])(a2, a4, 4LL);
buffered_action(*a1, a4, 4LL, 1LL);
v6 = a1[3];
v7 = uhash_get_type_from_key(a1[2]);
uhash_init(v7, v6);
uhash_update(a1[2], a1[3], a4, 4LL);
v8 = _uint32_identity(*a4);
*a4 = v8;
if ( v8 <= 0x400 )
{
v11 = v8;
}
else
{
v9 = mac_verify((__int64)a1, a2);
result = 1LL;
if ( !v9 )
return result;
v18 = a1[3];
v19 = uhash_get_type_from_key(a1[2]);
uhash_init(v19, v18);
v11 = *a4;
}
v12 = (char *)malloc(v11);
*a3 = v12;
if ( !v12 )
return 2LL;
if ( v11 )
{
v13 = 0;
while ( 1 )
{
v14 = &v12[v13];
v15 = min(4096LL, v11 - v13);
v20 = v15;
v16 = v15;
((void (__fastcall *)(__int64, char *, _QWORD))a1[1])(a2, v14, v15);
v13 += v20;
buffered_action(*a1, v14, v16, 1LL);
uhash_update(a1[2], a1[3], v14, v16);
v11 = *a4;
if ( *a4 <= v13 )
break;
v12 = (char *)*a3;
}
}
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 v6; // r12
unsigned int v7; // eax
unsigned int v8; // eax
_BOOL4 v9; // er8
__int64 result; // rax
unsigned int v11; // esi
char *v12; // r13
unsigned int v13; // er15
char *v14; // r13
unsigned __int16 v15; // ax
__int64 v16; // r12
_BOOL4 v17; // er8
__int64 v18; // r12
unsigned int v19; // eax
int v20; // [rsp+4h] [rbp-44h]

*a3 = 0LL;
((void (__fastcall *)(__int64, unsigned int *, __int64))a1[1])(a2, a4, 4LL);
buffered_action(*a1, a4, 4LL, 1LL);
v6 = a1[3];
v7 = uhash_get_type_from_key(a1[2]);
uhash_init(v7, v6);
uhash_update(a1[2], a1[3], a4, 4LL);
v8 = func0(*a4);
*a4 = v8;
if ( v8 <= 0x400 )
{
v11 = v8;
}
else
{
v9 = func1((__int64)a1, a2);
result = 1LL;
if ( !v9 )
return result;
v18 = a1[3];
v19 = uhash_get_type_from_key(a1[2]);
uhash_init(v19, v18);
v11 = *a4;
}
v12 = (char *)malloc(v11);
*a3 = v12;
if ( !v12 )
return 2LL;
if ( v11 )
{
v13 = 0;
while ( 1 )
{
v14 = &v12[v13];
v15 = min(4096LL, v11 - v13);
v20 = v15;
v16 = v15;
((void (__fastcall *)(__int64, char *, _QWORD))a1[1])(a2, v14, v15);
v13 += v20;
buffered_action(*a1, v14, v16, 1LL);
uhash_update(a1[2], a1[3], v14, v16);
v11 = *a4;
if ( *a4 <= v13 )
break;
v12 = (char *)*a3;
}
}
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 result; // rax
__int64 v3; // rbx
unsigned __int64 v4; // rax
unsigned __int64 v5; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rbx
unsigned __int64 v4; // rax
unsigned __int64 v5; // rdx

if ( !a1 )
return 0LL;
result = a1;
v3 = a1;
if ( a2 )
{
v4 = ((__int64 (*)(void))a2_string_len)();
if ( v4 >> *(_BYTE *)(a1 - 1) )
{
v3 = func0(a1 - 9) + 9;
v4 = a2_string_len(v3);
}
v5 = v4 + 1;
*(_BYTE *)(v3 + v4) = a2;
*(_BYTE *)(v3 + v4 + 1) = 0;
result = v3;
*(_QWORD *)(v3 - 9) = v5;
}
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
__int64 v4; // rax
__int64 v5; // r8

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

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; // rax
_QWORD *v1; // r12
_QWORD *result; // rax

v0 = (_QWORD *)lp_malloc(1928LL);
*v0 = 0LL;
v1 = v0;
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) && (unsigned int)get_parse_env(v1 + 88, v1 + 80) )
result = v1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
_QWORD *result; // rax

v0 = (_QWORD *)lp_malloc(1928LL);
*v0 = 0LL;
v1 = v0;
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) && (unsigned int)get_parse_env(v1 + 88, v1 + 80) )
result = v1;
else
result = 0LL;
return result;
}

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)
{
if ( !a1 )
return 0LL;
cls_lex_env();
free_parse_env(a1 + 704);
get_parse_env(a1 + 704, a1 + 640);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
return 0LL;
cls_lex_env();
free_parse_env(a1 + 704);
get_parse_env(a1 + 704, a1 + 640);
return 1LL;
}

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:
int __fastcall lp_arg(__int64 a1, const char **a2)
{
const char *v2; // rax
__int64 v3; // r8
__int64 *i; // rbx

v2 = a2[1];
if ( !v2 )
goto LABEL_7;
if ( *v2 != 45 )
goto LABEL_5;
if ( v2[1] == 104 && !v2[2] )
{
LABEL_7:
LODWORD(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 (int)v2;
}
if ( v2[1] == 118 && !v2[2] )
{
LODWORD(v2) = puts("lite-proto interpreter version:2.0");
return (int)v2;
}
if ( v2[1] == 111 && !v2[2] )
{
v3 = (__int64)a2[2];
for ( i = (__int64 *)(a2 + 3); v3; ++i )
{
LODWORD(v2) = lp_inter(a1, v3);
if ( !(_DWORD)v2 )
break;
v3 = *i;
}
}
else
{
LABEL_5:
LODWORD(v2) = printf("%s cmd is error! please input %s -h see help.\n", *a2, *a2);
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, const char **a2)
{
const char *v2; // rax
__int64 v3; // r8
__int64 *i; // rbx

v2 = a2[1];
if ( !v2 )
goto LABEL_7;
if ( *v2 != 45 )
goto LABEL_5;
if ( v2[1] == 104 && !v2[2] )
{
LABEL_7:
LODWORD(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 (int)v2;
}
if ( v2[1] == 118 && !v2[2] )
{
LODWORD(v2) = puts("lite-proto interpreter version:2.0");
return (int)v2;
}
if ( v2[1] == 111 && !v2[2] )
{
v3 = (__int64)a2[2];
for ( i = (__int64 *)(a2 + 3); v3; ++i )
{
LODWORD(v2) = func3(a1, v3);
if ( !(_DWORD)v2 )
break;
v3 = *i;
}
}
else
{
LABEL_5:
LODWORD(v2) = printf("%s cmd is error! please input %s -h see help.\n", *a2, *a2);
}
return (int)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

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

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; // rbp

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; // rax
size_t v2; // r8
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rdx
__int64 v5; // rsi

v1 = strlen(a1);
v2 = v1;
v3 = (v1 >> 5) + 1;
if ( v1 >= v3 )
{
v4 = v1;
do
{
v5 = a1[v4 - 1];
v4 -= v3;
v2 ^= v5 + (v2 >> 2) + 32 * v2;
}
while ( v3 <= v4 );
}
return v2;
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
size_t v1; // rax
size_t v2; // r8
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rdx
__int64 v5; // rsi

v1 = strlen(a1);
v2 = v1;
v3 = (v1 >> 5) + 1;
if ( v1 >= v3 )
{
v4 = v1;
do
{
v5 = a1[v4 - 1];
v4 -= v3;
v2 ^= v5 + (v2 >> 2) + 32 * v2;
}
while ( v3 <= v4 );
}
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; // rax
_QWORD *v1; // r12
_QWORD *v2; // rax

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

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

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

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 v2; // r14
const char *v4; // rsi
size_t v5; // rax
unsigned __int64 v6; // r12
size_t v7; // rbp
_QWORD *v8; // rbx
__int64 v9; // rbx

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

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

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v2 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = func1(a2);
v6 = a1[2];
v7 = v5;
v8 = (_QWORD *)(v6 + 32 * (v5 % v2));
v4 = (const char *)v8[1];
if ( v4 )
{
while ( *v8 != v7 || strcmp(a2, v4) )
{
v9 = v8[3];
if ( !v9 )
return 0LL;
v8 = (_QWORD *)(v6 + 32 * (v9 - 1));
v4 = (const char *)v8[1];
if ( !v4 )
return v4;
}
v4 = (const char *)(v8 + 2);
}
}
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)
{
__int64 v2; // rax
int v3; // eax
__int64 v4; // r8
const char *v6; // rax
bool v7; // zf
const char *v8; // [rsp+0h] [rbp-28h] BYREF
__int64 v9; // [rsp+8h] [rbp-20h]

v8 = a2;
v2 = lp_malloc(40LL);
*(_QWORD *)(v2 + 32) = 0LL;
v9 = v2;
*(_OWORD *)(v2 + 16) = 0LL;
*(_OWORD *)v2 = 0LL;
v3 = lib_map_add(a1, (__int64)&v8);
if ( !v3 )
{
lp_free(v9);
return 0LL;
}
v4 = v9;
if ( v3 != 3 )
return v4;
lp_free(v9);
v6 = lib_map_find(a1, a2);
v4 = *(_QWORD *)v6;
v7 = *(_QWORD *)(*(_QWORD *)v6 + 16LL) == 0LL;
v9 = *(_QWORD *)v6;
if ( v7 )
return v4;
if ( *(_QWORD *)(v4 + 24) )
v4 = 0LL;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 *a1, const char *a2)
{
__int64 v2; // rax
int v3; // eax
__int64 v4; // r8
const char *v6; // rax
bool v7; // zf
const char *v8; // [rsp+0h] [rbp-28h] BYREF
__int64 v9; // [rsp+8h] [rbp-20h]

v8 = a2;
v2 = lp_malloc(40LL);
*(_QWORD *)(v2 + 32) = 0LL;
v9 = v2;
*(_OWORD *)(v2 + 16) = 0LL;
*(_OWORD *)v2 = 0LL;
v3 = func5(a1, (__int64)&v8);
if ( !v3 )
{
lp_free(v9);
return 0LL;
}
v4 = v9;
if ( v3 != 3 )
return v4;
lp_free(v9);
v6 = func4(a1, a2);
v4 = *(_QWORD *)v6;
v7 = *(_QWORD *)(*(_QWORD *)v6 + 16LL) == 0LL;
v9 = *(_QWORD *)v6;
if ( v7 )
return v4;
if ( *(_QWORD *)(v4 + 24) )
v4 = 0LL;
return v4;
}

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:
__int64 __fastcall lib_Mmap_find(unsigned __int64 *a1, const char *a2)
{
const char *v2; // rax
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = lib_map_find(a1, a2);
if ( v2 )
result = *(_QWORD *)v2;
else
result = 0LL;
return result;
}

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

if ( !a1 || !a2 )
return 0LL;
v2 = func4(a1, a2);
if ( v2 )
result = *(_QWORD *)v2;
else
result = 0LL;
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; }