handleLeaks

decompiled_code:
void __fastcall handleLeaks(__int64 a1)
{
if ( a1 && *(_QWORD *)a1 && *(_BYTE *)(a1 + 24) == 1 )
*(_QWORD *)(a1 + 16) = (*(_QWORD *)a1 - (a1 + 32)) & 0xFFFFFFFFFFFFFFFCLL;
}

original_code:
void handleLeaks(t_malloc *tmp)
{
  if (tmp && tmp->prev &&
      ((void*)tmp - ((void*)tmp->prev + MALLOC_BLOCK_SIZE + tmp->prev->size) == 0))
      tmp = memcpy((void*)tmp->prev + MALLOC_BLOCK_SIZE + tmp->prev->size, tmp, MALLOC_BLOCK_SIZE);
  if (tmp && tmp->next && tmp->isFree == 1)
    tmp->size = ((((((void*)tmp->next - ((void*)tmp + MALLOC_BLOCK_SIZE)))>>2)<<2));
}

canonical_original_code:
void handleLeaks(struct s_malloc *tmp)
{
  if (tmp && tmp->prev &&
      ((void *)tmp - ((void *)tmp->prev + MALLOC_BLOCK_SIZE + tmp->prev->size) == 0))
      tmp = memcpy((void *)tmp->prev + MALLOC_BLOCK_SIZE + tmp->prev->size, tmp, MALLOC_BLOCK_SIZE);
  if (tmp && tmp->next && tmp->isFree == 1)
    tmp->size = ((((((void *)tmp->next - ((void *)tmp + MALLOC_BLOCK_SIZE)))>>2)<<2));
}


free

repo: guillaumeBoufflers/malloc

decompiled_code:
int __fastcall free(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rdi

v1 = MALLOC_LIST;
pthread_mutex_lock(lock);
if ( v1 )
{
while ( a1 != v1 + 32 )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
return pthread_mutex_unlock(lock);
}
v2 = *(_QWORD *)(v1 + 8);
*(_BYTE *)(v1 + 24) = 1;
if ( v2 && *(_BYTE *)(v2 + 24) == 1 )
{
*(_QWORD *)(v2 + 16) += *(_QWORD *)(v1 + 16) + 32LL;
deleteNode((__int64 *)v1);
}
v3 = *(_QWORD *)v1;
if ( *(_QWORD *)v1 && *(_BYTE *)(v3 + 24) == 1 )
{
*(_QWORD *)(v1 + 16) += (*(_QWORD *)(v3 + 16) + 32LL) & 0xFFFFFFFFFFFFFFFCLL;
deleteNode((__int64 *)v3);
}
handleLeaks(v1);
freeMemory((_QWORD *)v1);
}
return pthread_mutex_unlock(lock);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rdi

v1 = MALLOC_LIST;
pthread_mutex_lock(lock);
if ( v1 )
{
while ( a1 != v1 + 32 )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
return pthread_mutex_unlock(lock);
}
v2 = *(_QWORD *)(v1 + 8);
*(_BYTE *)(v1 + 24) = 1;
if ( v2 && *(_BYTE *)(v2 + 24) == 1 )
{
*(_QWORD *)(v2 + 16) += *(_QWORD *)(v1 + 16) + 32LL;
deleteNode((__int64 *)v1);
}
v3 = *(_QWORD *)v1;
if ( *(_QWORD *)v1 && *(_BYTE *)(v3 + 24) == 1 )
{
*(_QWORD *)(v1 + 16) += (*(_QWORD *)(v3 + 16) + 32LL) & 0xFFFFFFFFFFFFFFFCLL;
deleteNode((__int64 *)v3);
}
func10(v1);
func7((_QWORD *)v1);
}
return pthread_mutex_unlock(lock);
}

original_code:
void free(void *ptr)
{
  t_malloc *tmp;
  tmp = MALLOC_LIST;
  pthread_mutex_lock(&lock[0]);
  while (tmp)
    {
      if ((void*)tmp + MALLOC_BLOCK_SIZE == ptr)
 {
   tmp->isFree = 1;
   if (tmp->prev && tmp->prev->isFree == 1)
     {
       tmp->prev->size += tmp->size + MALLOC_BLOCK_SIZE;
       deleteNode(tmp);
     }
   if (tmp->next && tmp->next->isFree == 1)
     {
       tmp->size += (((((tmp->next->size + MALLOC_BLOCK_SIZE))>>2)<<2));
       deleteNode(tmp->next);
     }
   handleLeaks(tmp);
   freeMemory(tmp);
   pthread_mutex_unlock(&lock[0]);
   return;
 }
      tmp = tmp->next;
    }
  pthread_mutex_unlock(&lock[0]);
}

canonical_original_code:
void free(void *ptr)
{
  struct s_malloc *tmp;
  tmp = MALLOC_LIST;
  pthread_mutex_lock(&lock[0]);
  while (tmp)
    {
      if ((void *)tmp + MALLOC_BLOCK_SIZE == ptr)
 {
   tmp->isFree = 1;
   if (tmp->prev && tmp->prev->isFree == 1)
     {
       tmp->prev->size += tmp->size + MALLOC_BLOCK_SIZE;
       deleteNode(tmp);
     }
   if (tmp->next && tmp->next->isFree == 1)
     {
       tmp->size += (((((tmp->next->size + MALLOC_BLOCK_SIZE))>>2)<<2));
       deleteNode(tmp->next);
     }
   handleLeaks(tmp);
   freeMemory(tmp);
   pthread_mutex_unlock(&lock[0]);
   return;
 }
      tmp = tmp->next;
    }
  pthread_mutex_unlock(&lock[0]);
}

variable_types:
ptr
void *

variable_types: struct s_malloc { struct s_malloc *next; struct s_malloc *prev; unsigned long size; char isFree; } *

return_type: void


doRealloc

decompiled_code:
void *__fastcall doRealloc(void *ptr, __int64 a2, size_t a3)
{
void *v3; // r12

v3 = malloc(a3);
memcpy(v3, ptr, *(_QWORD *)(a2 + 16));
free(ptr);
pthread_mutex_unlock(&lock[1]);
return v3;
}

canonical_decompiled_code:
void *__fastcall func12(void *ptr, __int64 a2, size_t a3)
{
void *v3; // r12

v3 = func8(a3);
memcpy(v3, ptr, *(_QWORD *)(a2 + 16));
func11(ptr);
pthread_mutex_unlock(&lock[1]);
return v3;
}

original_code:
static void *doRealloc(void *ptr, t_malloc *node, size_t size)
{
  t_malloc *next;
  void *s;
  s = ptr;
  ptr = malloc(size);
  memcpy(ptr, s, node->size);
  free(s);
  pthread_mutex_unlock(&lock[1]);
  return (ptr);
}

canonical_original_code:
static void *doRealloc(void *ptr, struct s_malloc *node, unsigned long size)
{
  struct s_malloc *next;
  void *s;
  s = ptr;
  ptr = malloc(size);
  memcpy(ptr, s, node->size);
  free(s);
  pthread_mutex_unlock(&lock[1]);
  return (ptr);
}

variable_types:
size
unsigned long

variable_types:
s
void *

return_type: void *

user_defined_types: struct s_malloc { struct s_malloc *next; struct s_malloc *prev; unsigned long size; char isFree; }


realloc

decompiled_code:
void *__fastcall realloc(void *ptr, __int64 a2)
{
size_t v2; // r12
void *result; // rax

v2 = ((a2 - 1) & 0xFFFFFFFFFFFFFFFCLL) + 4;
if ( !ptr )
return malloc(((a2 - 1) & 0xFFFFFFFFFFFFFFFCLL) + 4);
if ( ((a2 - 1) & 0xFFFFFFFFFFFFFFFCLL) == -4LL )
{
free(ptr);
result = 0LL;
}
else
{
pthread_mutex_lock(&lock[1]);
if ( *((_QWORD *)ptr - 2) < v2 )
{
result = doRealloc(ptr, (__int64)ptr - 32, v2);
}
else
{
*((_QWORD *)ptr - 2) = v2;
pthread_mutex_unlock(&lock[1]);
result = ptr;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func13(void *ptr, __int64 a2)
{
size_t v2; // r12
void *result; // rax

v2 = ((a2 - 1) & 0xFFFFFFFFFFFFFFFCLL) + 4;
if ( !ptr )
return func8(((a2 - 1) & 0xFFFFFFFFFFFFFFFCLL) + 4);
if ( ((a2 - 1) & 0xFFFFFFFFFFFFFFFCLL) == -4LL )
{
func11(ptr);
result = 0LL;
}
else
{
pthread_mutex_lock(&lock[1]);
if ( *((_QWORD *)ptr - 2) < v2 )
{
result = func12(ptr, (__int64)ptr - 32, v2);
}
else
{
*((_QWORD *)ptr - 2) = v2;
pthread_mutex_unlock(&lock[1]);
result = ptr;
}
}
return result;
}

original_code:
void *realloc(void *ptr, size_t size)
{
  t_malloc *node;
  size = (((((size) -1)>>2)<<2)+4);
  if (!ptr)
    return(malloc(size));
  else if (size == 0)
    {
      free(ptr);
      return (((void *)0));
    }
  else
    {
      pthread_mutex_lock(&lock[1]);
      node = ptr - MALLOC_BLOCK_SIZE;
      if (node->size < size)
 return(doRealloc(ptr, node, size));
      else
 node->size = size;
      pthread_mutex_unlock(&lock[1]);
      return (ptr);
    }
}

canonical_original_code:
void *realloc(void *ptr, unsigned long size)
{
  struct s_malloc *node;
  size = (((((size) -1)>>2)<<2)+4);
  if (!ptr)
    return(malloc(size));
  else if (size == 0)
    {
      free(ptr);
      return (((void *)0));
    }
  else
    {
      pthread_mutex_lock(&lock[1]);
      node = ptr - MALLOC_BLOCK_SIZE;
      if (node->size < size)
 return(doRealloc(ptr, node, size));
      else
 node->size = size;
      pthread_mutex_unlock(&lock[1]);
      return (ptr);
    }
}


decompiled_code:
int show_alloc_mem()
{
__int64 v0; // rbx
void *v1; // rax
int result; // eax

v0 = MALLOC_LIST;
v1 = sbrk(0LL);
for ( result = printf("break: %p\n", v1); v0; v0 = *(_QWORD *)v0 )
{
while ( *(_BYTE *)(v0 + 24) )
{
v0 = *(_QWORD *)v0;
if ( !v0 )
return result;
}
result = printf(
"%p - %p : %ld octets\n",
(const void *)(v0 + 32),
(const void *)(v0 + *(_QWORD *)(v0 + 16) + 32),
*(_QWORD *)(v0 + 16));
}
return result;
}

canonical_decompiled_code:
int func14()
{
__int64 v0; // rbx
void *v1; // rax
int result; // eax

v0 = MALLOC_LIST;
v1 = sbrk(0LL);
for ( result = printf("break: %p\n", v1); v0; v0 = *(_QWORD *)v0 )
{
while ( *(_BYTE *)(v0 + 24) )
{
v0 = *(_QWORD *)v0;
if ( !v0 )
return result;
}
result = printf(
"%p - %p : %ld octets\n",
(const void *)(v0 + 32),
(const void *)(v0 + *(_QWORD *)(v0 + 16) + 32),
*(_QWORD *)(v0 + 16));
}
return result;
}

original_code:
void show_alloc_mem()
{
  t_malloc *tmp;
  tmp = MALLOC_LIST;
  printf("break: %p\n", sbrk(0));
  while (tmp)
    {
      if (tmp->isFree == 0)
 printf("%p - %p : %ld octets\n",
        (void*)tmp + MALLOC_BLOCK_SIZE,
        (void*)tmp + MALLOC_BLOCK_SIZE + tmp->size,
        tmp->size);
      tmp = tmp->next;
    }
}

canonical_original_code:
void show_alloc_mem()
{
  struct s_malloc *tmp;
  tmp = MALLOC_LIST;
  printf("break: %p\n", sbrk(0));
  while (tmp)
    {
      if (tmp->isFree == 0)
 printf("%p - %p : %ld octets\n",
        (void *)tmp + MALLOC_BLOCK_SIZE,
        (void *)tmp + MALLOC_BLOCK_SIZE + tmp->size,
        tmp->size);
      tmp = tmp->next;
    }
}


repo: guillaumerose/checkout-base

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

tt_current_test_failed = 0;
result = a2();
if ( tt_current_test_failed )
{
result = printf(
"failure: %s:%d: In test %s():\n %s (%s)\n",
(const char *)tt_current_file,
(unsigned int)tt_current_line,
a1,
(const char *)tt_current_msg,
(const char *)tt_current_expression);
++tt_fails;
}
else
{
++tt_passes;
}
return result;
}

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

tt_current_test_failed = 0;
result = a2();
if ( tt_current_test_failed )
{
result = printf(
"failure: %s:%d: In test %s():\n %s (%s)\n",
(const char *)tt_current_file,
(unsigned int)tt_current_line,
a1,
(const char *)tt_current_msg,
(const char *)tt_current_expression);
++tt_fails;
}
else
{
++tt_passes;
}
return result;
}

original_code:
void tt_execute(const char* name, void (*test_function)())
{
  tt_current_test_failed = 0;
  test_function();
  if (tt_current_test_failed) {
    printf("failure: %s:%d: In test %s():\n    %s (%s)\n",
      tt_current_file, tt_current_line, name, tt_current_msg, tt_current_expression);
    tt_fails++;
  } else {
    tt_passes++;
  }
}

canonical_original_code:
void tt_execute(char *name, void (*test_function)())
{
  tt_current_test_failed = 0;
  test_function();
  if (tt_current_test_failed) {
    printf("failure: %s:%d: In test %s():\n    %s (%s)\n",
      tt_current_file, tt_current_line, name, tt_current_msg, tt_current_expression);
    tt_fails++;
  } else {
    tt_passes++;
  }
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall tt_assert(__int64 a1, int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

tt_current_msg = a3;
result = a5;
tt_current_expression = a4;
tt_current_file = a1;
tt_current_line = a2;
tt_current_test_failed = a5 ^ 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

tt_current_msg = a3;
result = a5;
tt_current_expression = a4;
tt_current_file = a1;
tt_current_line = a2;
tt_current_test_failed = a5 ^ 1;
return result;
}

original_code:
_Bool tt_assert(const char* file, int line, const char* msg, const char* expression, _Bool pass)
{
  tt_current_msg = msg;
  tt_current_expression = expression;
  tt_current_file = file;
  tt_current_line = line;
  tt_current_test_failed = !pass;
  return pass;
}

canonical_original_code:
_Bool tt_assert(char *file, int line, char *msg, char *expression, _Bool pass)
{
  tt_current_msg = msg;
  tt_current_expression = expression;
  tt_current_file = file;
  tt_current_line = line;
  tt_current_test_failed = !pass;
  return pass;
}

variable_types:
file
char *

variable_types: line int

variable_types:
msg
char *

variable_types:
expression
char *


decompiled_code:
__int64 test_upper_case()
{
__int64 vars0[2]; // [rsp+0h] [rbp+0h] BYREF
char vars10[1008]; // [rsp+10h] [rbp+10h] BYREF

vars0[0] = 6505057LL;
memset(vars10, 0, sizeof(vars10));
vars0[1] = 0LL;
process(vars0);
return tt_assert(
(__int64)"checkout_test.c",
8,
(__int64)"input",
(__int64)"strcmp((\"ABC\"),(input)) == 0",
strcmp("ABC", (const char *)vars0) == 0);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 vars0[2]; // [rsp+0h] [rbp+0h] BYREF
char vars10[1008]; // [rsp+10h] [rbp+10h] BYREF

vars0[0] = 6505057LL;
memset(vars10, 0, sizeof(vars10));
vars0[1] = 0LL;
func11(vars0);
return func8(
(__int64)"checkout_test.c",
8,
(__int64)"input",
(__int64)"strcmp((\"ABC\"),(input)) == 0",
strcmp("ABC", (const char *)vars0) == 0);
}

original_code:
void test_upper_case()
{
    char input[1024] = "aBc";
    process(input);
    if (!tt_assert("checkout_test.c", 8, (("input")), ("strcmp((\"ABC\"),(input)) == 0"), (strcmp(("ABC"),(input)) == 0) ? 1 : 0)) return;
}

variable_types:
input
char [1024]


decompiled_code:
__int64 tt_report()
{
unsigned int v0; // er12

v0 = tt_fails;
if ( tt_fails )
{
v0 = -1;
printf(
"%c%sFAILED%c%s [%s] (passed:%d, failed:%d, total:%d)\n",
27LL,
"[1;31m",
27LL,
"[0m",
(const char *)tt_current_file,
(unsigned int)tt_passes,
(unsigned int)tt_fails,
(unsigned int)(tt_fails + tt_passes));
}
else
{
printf(
"%c%sPASSED%c%s [%s] (total:%d)\n",
27LL,
"[1;32m",
27LL,
"[0m",
(const char *)tt_current_file,
(unsigned int)tt_passes);
}
return v0;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // er12

v0 = tt_fails;
if ( tt_fails )
{
v0 = -1;
printf(
"%c%sFAILED%c%s [%s] (passed:%d, failed:%d, total:%d)\n",
27LL,
"[1;31m",
27LL,
"[0m",
(const char *)tt_current_file,
(unsigned int)tt_passes,
(unsigned int)tt_fails,
(unsigned int)(tt_fails + tt_passes));
}
else
{
printf(
"%c%sPASSED%c%s [%s] (total:%d)\n",
27LL,
"[1;32m",
27LL,
"[0m",
(const char *)tt_current_file,
(unsigned int)tt_passes);
}
return v0;
}

original_code:
int tt_report(void)
{
  if (tt_fails) {
    printf("%c%sFAILED%c%s [%s] (passed:%d, failed:%d, total:%d)\n",
      0x1B, "[1;31m", 0x1B, "[0m",
      tt_current_file, tt_passes, tt_fails, tt_passes + tt_fails);
    return -1;
  } else {
    printf("%c%sPASSED%c%s [%s] (total:%d)\n",
      0x1B, "[1;32m", 0x1B, "[0m",
      tt_current_file, tt_passes);
    return 0;
  }
}

canonical_original_code:
int tt_report()
{
  if (tt_fails) {
    printf("%c%sFAILED%c%s [%s] (passed:%d, failed:%d, total:%d)\n",
      0x1B, "[1;31m", 0x1B, "[0m",
      tt_current_file, tt_passes, tt_fails, tt_passes + tt_fails);
    return -1;
  } else {
    printf("%c%sPASSED%c%s [%s] (total:%d)\n",
      0x1B, "[1;32m", 0x1B, "[0m",
      tt_current_file, tt_passes);
    return 0;
  }
}

return_type: int


process

decompiled_code:
void __fastcall process(char *a1)
{
_BYTE *v1; // rbx
int v2; // edi

v1 = a1;
v2 = *a1;
if ( (_BYTE)v2 )
{
do
{
*v1++ = toupper(v2);
v2 = (char)*v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void __fastcall func11(char *a1)
{
_BYTE *v1; // rbx
int v2; // edi

v1 = a1;
v2 = *a1;
if ( (_BYTE)v2 )
{
do
{
*v1++ = toupper(v2);
v2 = (char)*v1;
}
while ( *v1 );
}
}

original_code:
void process(char *chaine) {
 while(*chaine != '\0') {
  *chaine = toupper(*chaine);
  chaine++;
 }
}

variable_types:
chaine
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
tt_execute("test_upper_case", test_upper_case, envp);
return tt_report();
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7("test_upper_case", test_upper_case, envp);
return func10();
}

original_code:
int main()
{
  tt_execute(("test_upper_case"), (test_upper_case));
  return tt_report();
}


InitBitStream

repo: gunasekar/SpaceManager

decompiled_code:
void __fastcall InitBitStream(__int64 a1, __int64 a2)
{
*(_QWORD *)a1 = a2;
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
static void InitBitStream( BitStream *stream, unsigned char *buf ){
  stream->BytePtr = buf;
  stream->BitPos = 0;
}

canonical_original_code:
static void InitBitStream(struct BitStream *stream, unsigned char *buf){
  stream->BytePtr = buf;
  stream->BitPos = 0;
}

variable_types: struct BitStream { unsigned char *BytePtr; unsigned int BitPos; } *

variable_types:
buf
unsigned char *


ReadBitFromBitStream

decompiled_code:
__int64 __fastcall ReadBitFromBitStream(unsigned __int8 **a1)
{
__int64 v1; // rsi
int v2; // eax
char v3; // cl
int v4; // eax
int v5; // edx
unsigned __int8 *v6; // rsi
__int64 result; // rax

v1 = (__int64)*a1;
v2 = *((_DWORD *)a1 + 2);
v3 = 7 - v2;
v4 = ((_BYTE)v2 + 1) & 7;
v5 = (int)**a1 >> v3;
*((_DWORD *)a1 + 2) = v4;
v6 = (unsigned __int8 *)((v4 == 0) + v1);
result = v5 & 1;
*a1 = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 **a1)
{
__int64 v1; // rsi
int v2; // eax
char v3; // cl
int v4; // eax
int v5; // edx
unsigned __int8 *v6; // rsi
__int64 result; // rax

v1 = (__int64)*a1;
v2 = *((_DWORD *)a1 + 2);
v3 = 7 - v2;
v4 = ((_BYTE)v2 + 1) & 7;
v5 = (int)**a1 >> v3;
*((_DWORD *)a1 + 2) = v4;
v6 = (unsigned __int8 *)((v4 == 0) + v1);
result = v5 & 1;
*a1 = v6;
return result;
}

original_code:
static unsigned int ReadBitFromBitStream( BitStream *stream ){
  unsigned int x, bit;
  unsigned char *buf;
  buf = stream->BytePtr;
  bit = stream->BitPos;
  x = (*buf & (1<<(7-bit))) ? 1 : 0;
  bit = (bit+1) & 7;
  if( !bit ){
    ++ buf;
  }
  stream->BitPos = bit;
  stream->BytePtr = buf;
  return x;
}

canonical_original_code:
static unsigned int ReadBitFromBitStream(struct BitStream *stream){
  unsigned int x; unsigned int bit;
  unsigned char *buf;
  buf = stream->BytePtr;
  bit = stream->BitPos;
  x = (*buf & (1<<(7-bit))) ? 1 : 0;
  bit = (bit+1) & 7;
  if( !bit ){
    ++ buf;
  }
  stream->BitPos = bit;
  stream->BytePtr = buf;
  return x;
}

variable_types:
x
unsigned int

variable_types:
bit
unsigned int

return_type: unsigned int

user_defined_types: struct BitStream { unsigned char *BytePtr; unsigned int BitPos; }


ReadByteFromBitStream

decompiled_code:
__int64 __fastcall ReadByteFromBitStream(_DWORD *a1)
{
int v1; // er8
int v2; // eax
int v3; // esi

v1 = a1[2];
v2 = *(unsigned __int8 *)(*(_QWORD *)a1 + 1LL);
v3 = *(unsigned __int8 *)(*(_QWORD *)a1)++;
return (v3 << v1) | (unsigned int)(v2 >> (8 - v1));
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
int v1; // er8
int v2; // eax
int v3; // esi

v1 = a1[2];
v2 = *(unsigned __int8 *)(*(_QWORD *)a1 + 1LL);
v3 = *(unsigned __int8 *)(*(_QWORD *)a1)++;
return (v3 << v1) | (unsigned int)(v2 >> (8 - v1));
}

original_code:
static unsigned int ReadByteFromBitStream( BitStream *stream ){
  unsigned int x, bit;
  unsigned char *buf;
  buf = stream->BytePtr;
  bit = stream->BitPos;
  x = (*buf << bit) | (buf[1] >> (8-bit));
  ++ buf;
  stream->BytePtr = buf;
  return x;
}

canonical_original_code:
static unsigned int ReadByteFromBitStream(struct BitStream *stream){
  unsigned int x; unsigned int bit;
  unsigned char *buf;
  buf = stream->BytePtr;
  bit = stream->BitPos;
  x = (*buf << bit) | (buf[1] >> (8-bit));
  ++ buf;
  stream->BytePtr = buf;
  return x;
}


WriteBitsToBitStream

original_code:
static void WriteBitsToBitStream( BitStream *stream, unsigned int x, unsigned int bits ){
  unsigned int bit_pos, count;
  unsigned char *buf;
  unsigned int mask;
  buf = stream->BytePtr;
  bit_pos = stream->BitPos;
  mask = 1 << (bits-1);
  for( count = 0; count < bits; ++ count )
  {
    *buf = (*buf & (0xff^(1<<(7-bit_pos)))) + ((x & mask ? 1 : 0) << (7-bit_pos));
    x <<= 1;
    bit_pos = (bit_pos+1) & 7;
    if( !bit_pos )
    {
      ++ buf;
    }
  }
  stream->BytePtr = buf;
  stream->BitPos = bit_pos;
}

canonical_original_code:
static void WriteBitsToBitStream(struct BitStream *stream, unsigned int x, unsigned int bits){
  unsigned int bit_pos; unsigned int count;
  unsigned char *buf;
  unsigned int mask;
  buf = stream->BytePtr;
  bit_pos = stream->BitPos;
  mask = 1 << (bits-1);
  for( count = 0; count < bits; ++ count )
  {
    *buf = (*buf & (0xff^(1<<(7-bit_pos)))) + ((x & mask ? 1 : 0) << (7-bit_pos));
    x <<= 1;
    bit_pos = (bit_pos+1) & 7;
    if( !bit_pos )
    {
      ++ buf;
    }
  }
  stream->BytePtr = buf;
  stream->BitPos = bit_pos;
}

variable_types:
bits
unsigned int

variable_types:
count
unsigned int

variable_types:
mask
unsigned int


StoreHuffmanTree

decompiled_code:
__int64 __fastcall StoreHuffmanTree(__int64 a1, _DWORD *a2, __int64 a3, unsigned int a4, unsigned int a5)
{
__int64 v7; // r12
_DWORD *i; // rbx
unsigned int v10; // ebp
__int64 v11; // rcx
__int64 result; // rax

v7 = a1;
for ( i = a2; *(int *)(v7 + 20) < 0; v7 = *(_QWORD *)(v7 + 8) )
{
v10 = 2 * a4;
WriteBitsToBitStream(a3, 0, 1);
++a5;
v11 = v10;
a4 = v10 + 1;
StoreHuffmanTree(*(_QWORD *)v7, a2, a3, v11, a5);
}
WriteBitsToBitStream(a3, 1, 1);
WriteBitsToBitStream(a3, *(_DWORD *)(v7 + 20), 8);
result = *(unsigned int *)(v7 + 20);
do
{
if ( *a2 == (_DWORD)result )
break;
a2 += 4;
}
while ( a2 != i + 1024 );
a2[2] = a4;
a2[3] = a5;
return result;
}

original_code:
static void StoreHuffmanTree( HuffmanEncodeNode *node, freq_table *sym, BitStream *stream, unsigned int code, unsigned int bits )
{
  unsigned int sym_idx;
  if( node->Symbol >= 0 )
  {
    WriteBitsToBitStream( stream, 1, 1 );
    WriteBitsToBitStream( stream, node->Symbol, 8 );
    for( sym_idx = 0; sym_idx < 256; ++ sym_idx )
    {
      if( sym[sym_idx].Symbol == node->Symbol ) break;
    }
    sym[sym_idx].Code = code;
    sym[sym_idx].Bits = bits;
    return;
  }
  else
  {
    WriteBitsToBitStream( stream, 0, 1 );
  }
  StoreHuffmanTree( node->ChildA, sym, stream, (code<<1)+0, bits+1 );
  StoreHuffmanTree( node->ChildB, sym, stream, (code<<1)+1, bits+1 );
}

canonical_original_code:
static void StoreHuffmanTree(struct huff_encodenode_struct *node, struct freq_table *sym, struct BitStream *stream, unsigned int code, unsigned int bits)
{
  unsigned int sym_idx;
  if( node->Symbol >= 0 )
  {
    WriteBitsToBitStream( stream, 1, 1 );
    WriteBitsToBitStream( stream, node->Symbol, 8 );
    for( sym_idx = 0; sym_idx < 256; ++ sym_idx )
    {
      if( sym[sym_idx].Symbol == node->Symbol ) break;
    }
    sym[sym_idx].Code = code;
    sym[sym_idx].Bits = bits;
    return;
  }
  else
  {
    WriteBitsToBitStream( stream, 0, 1 );
  }
  StoreHuffmanTree( node->ChildA, sym, stream, (code<<1)+0, bits+1 );
  StoreHuffmanTree( node->ChildB, sym, stream, (code<<1)+1, bits+1 );
}

variable_types: struct huff_encodenode_struct { struct huff_encodenode_struct *ChildA; int Count; int Symbol; } *

variable_types: struct freq_table { int Symbol; unsigned int Count; unsigned int Code; unsigned int Bits; } *

variable_types:
code
unsigned int


CreateHuffmanTree

original_code:
static void CreateHuffmanTree( freq_table *sym, BitStream *stream )
{
  HuffmanEncodeNode nodes[511], *node_1, *node_2, *root;
  unsigned int k, num_symbols, nodes_left, next_idx;
  num_symbols = 0;
  for( k = 0; k < 256; ++ k )
  {
    if( sym[k].Count > 0 )
    {
      nodes[num_symbols].Symbol = sym[k].Symbol;
      nodes[num_symbols].Count = sym[k].Count;
      nodes[num_symbols].ChildA = (HuffmanEncodeNode *) 0;
      nodes[num_symbols].ChildB = (HuffmanEncodeNode *) 0;
      ++ num_symbols;
    }
  }
  root = (HuffmanEncodeNode *) 0;
  nodes_left = num_symbols;
  next_idx = num_symbols;
  while( nodes_left > 1 )
  {
    node_1 = (HuffmanEncodeNode *) 0;
    node_2 = (HuffmanEncodeNode *) 0;
    for( k = 0; k < next_idx; ++ k )
    {
      if( nodes[k].Count > 0 )
      {
        if( !node_1 || (nodes[k].Count <= node_1->Count) )
        {
          node_2 = node_1;
          node_1 = &nodes[k];
        }
        else if( !node_2 || (nodes[k].Count <= node_2->Count) )
        {
          node_2 = &nodes[k];
        }
      }
    }
    root = &nodes[next_idx];
    root->ChildA = node_1;
    root->ChildB = node_2;
    root->Count = node_1->Count + node_2->Count;
    root->Symbol = -1;
    node_1->Count = 0;
    node_2->Count = 0;
    ++ next_idx;
    -- nodes_left;
  }
  if( root )
  {
    StoreHuffmanTree( root, sym, stream, 0, 0 );
  }
  else
  {
    root = &nodes[0];
    StoreHuffmanTree( root, sym, stream, 0, 1 );
  }
}

canonical_original_code:
static void CreateHuffmanTree(struct freq_table *sym, struct BitStream *stream)
{
  struct huff_encodenode_struct nodes[511]; struct huff_encodenode_struct *node_1; struct huff_encodenode_struct *node_2; struct huff_encodenode_struct *root;
  unsigned int k; unsigned int num_symbols; unsigned int nodes_left; unsigned int next_idx;
  num_symbols = 0;
  for( k = 0; k < 256; ++ k )
  {
    if( sym[k].Count > 0 )
    {
      nodes[num_symbols].Symbol = sym[k].Symbol;
      nodes[num_symbols].Count = sym[k].Count;
      nodes[num_symbols].ChildA = (struct huff_encodenode_struct *) 0;
      nodes[num_symbols].ChildB = (struct huff_encodenode_struct *) 0;
      ++ num_symbols;
    }
  }
  root = (struct huff_encodenode_struct *) 0;
  nodes_left = num_symbols;
  next_idx = num_symbols;
  while( nodes_left > 1 )
  {
    node_1 = (struct huff_encodenode_struct *) 0;
    node_2 = (struct huff_encodenode_struct *) 0;
    for( k = 0; k < next_idx; ++ k )
    {
      if( nodes[k].Count > 0 )
      {
        if( !node_1 || (nodes[k].Count <= node_1->Count) )
        {
          node_2 = node_1;
          node_1 = &nodes[k];
        }
        else if( !node_2 || (nodes[k].Count <= node_2->Count) )
        {
          node_2 = &nodes[k];
        }
      }
    }
    root = &nodes[next_idx];
    root->ChildA = node_1;
    root->ChildB = node_2;
    root->Count = node_1->Count + node_2->Count;
    root->Symbol = -1;
    node_1->Count = 0;
    node_2->Count = 0;
    ++ next_idx;
    -- nodes_left;
  }
  if( root )
  {
    StoreHuffmanTree( root, sym, stream, 0, 0 );
  }
  else
  {
    root = &nodes[0];
    StoreHuffmanTree( root, sym, stream, 0, 1 );
  }
}

variable_types: struct huff_encodenode_struct { struct huff_encodenode_struct *ChildA; int Count; int Symbol; } [511]

variable_types:
k
unsigned int

user_defined_types: struct freq_table { int Symbol; unsigned int Count; unsigned int Code; unsigned int Bits; }


RecoverHuffmanTree

decompiled_code:
__int64 __fastcall RecoverHuffmanTree(__int64 a1, unsigned __int8 **a2, _DWORD *a3)
{
__int64 v4; // rdx
__int64 v5; // r12

v4 = (unsigned int)*a3;
v5 = a1 + 24 * v4;
*a3 = v4 + 1;
*(_DWORD *)(v5 + 16) = -1;
*(_QWORD *)v5 = 0LL;
*(_QWORD *)(v5 + 8) = 0LL;
if ( (unsigned int)ReadBitFromBitStream(a2) )
{
*(_DWORD *)(v5 + 16) = ReadByteFromBitStream(a2);
}
else
{
*(_QWORD *)v5 = RecoverHuffmanTree(a1, a2, a3);
*(_QWORD *)(v5 + 8) = RecoverHuffmanTree(a1, a2, a3);
}
return v5;
}

original_code:
static HuffmanDecodeNode * RecoverHuffmanTree( HuffmanDecodeNode *nodes, BitStream *stream, unsigned int *nodenum )
{
  HuffmanDecodeNode * this_node;
  this_node = &nodes[*nodenum];
  *nodenum = *nodenum + 1;
  this_node->Symbol = -1;
  this_node->ChildA = (HuffmanDecodeNode *) 0;
  this_node->ChildB = (HuffmanDecodeNode *) 0;
  if( ReadBitFromBitStream( stream ) )
  {
    this_node->Symbol = ReadByteFromBitStream( stream );
    return this_node;
  }
  this_node->ChildA = RecoverHuffmanTree( nodes, stream, nodenum );
  this_node->ChildB = RecoverHuffmanTree( nodes, stream, nodenum );
  return this_node;
}

canonical_original_code:
static struct huff_decodenode_struct *RecoverHuffmanTree(struct huff_decodenode_struct *nodes, struct BitStream *stream, unsigned int *nodenum)
{
  struct huff_decodenode_struct *this_node;
  this_node = &nodes[*nodenum];
  *nodenum = *nodenum + 1;
  this_node->Symbol = -1;
  this_node->ChildA = (struct huff_decodenode_struct *) 0;
  this_node->ChildB = (struct huff_decodenode_struct *) 0;
  if( ReadBitFromBitStream( stream ) )
  {
    this_node->Symbol = ReadByteFromBitStream( stream );
    return this_node;
  }
  this_node->ChildA = RecoverHuffmanTree( nodes, stream, nodenum );
  this_node->ChildB = RecoverHuffmanTree( nodes, stream, nodenum );
  return this_node;
}

variable_types:
nodes
struct huff_decodenode_struct *

variable_types:
nodenum
unsigned int *

variable_types: struct huff_decodenode_struct { struct huff_decodenode_struct *ChildA; int Symbol; } *


Compress

original_code:
int Compress( unsigned char *InputFileByteStream, unsigned char *OutputFileByteStream, unsigned int InputFileSize )
{
  freq_table sym[256], tmp;
  BitStream bitstream;
  unsigned int k, total_bytes, swaps, symbol;
  if( InputFileSize < 1 )
    return 0;
  InitBitStream( &bitstream, OutputFileByteStream );
  CreateFreq_Table( InputFileByteStream, sym, InputFileSize );
  CreateHuffmanTree( sym, &bitstream );
  do
  {
    swaps = 0;
    for( k = 0; k < 255; ++ k )
    {
      if( sym[k].Symbol > sym[k+1].Symbol )
      {
        tmp = sym[k];
        sym[k] = sym[k+1];
        sym[k+1] = tmp;
        swaps = 1;
      }
    }
  }
  while( swaps );
  for( k = 0; k < InputFileSize; ++ k )
  {
    symbol = InputFileByteStream[k];
    WriteBitsToBitStream( &bitstream, sym[symbol].Code, sym[symbol].Bits );
  }
  total_bytes = (int)(bitstream.BytePtr - OutputFileByteStream);
  if( bitstream.BitPos > 0 )
  {
    ++ total_bytes;
  }
  return total_bytes;
}

canonical_original_code:
int Compress(unsigned char *InputFileByteStream, unsigned char *OutputFileByteStream, unsigned int InputFileSize)
{
  struct freq_table sym[256]; struct freq_table tmp;
  struct BitStream bitstream;
  unsigned int k; unsigned int total_bytes; unsigned int swaps; unsigned int symbol;
  if( InputFileSize < 1 )
    return 0;
  InitBitStream( &bitstream, OutputFileByteStream );
  CreateFreq_Table( InputFileByteStream, sym, InputFileSize );
  CreateHuffmanTree( sym, &bitstream );
  do
  {
    swaps = 0;
    for( k = 0; k < 255; ++ k )
    {
      if( sym[k].Symbol > sym[k+1].Symbol )
      {
        tmp = sym[k];
        sym[k] = sym[k+1];
        sym[k+1] = tmp;
        swaps = 1;
      }
    }
  }
  while( swaps );
  for( k = 0; k < InputFileSize; ++ k )
  {
    symbol = InputFileByteStream[k];
    WriteBitsToBitStream( &bitstream, sym[symbol].Code, sym[symbol].Bits );
  }
  total_bytes = (int)(bitstream.BytePtr - OutputFileByteStream);
  if( bitstream.BitPos > 0 )
  {
    ++ total_bytes;
  }
  return total_bytes;
}

variable_types:
InputFileByteStream
unsigned char *

variable_types:
OutputFileByteStream
unsigned char *

variable_types:
InputFileSize
unsigned int

variable_types: struct freq_table { int Symbol; unsigned int Count; unsigned int Code; unsigned int Bits; } [256]

variable_types: struct BitStream { unsigned char *BytePtr; unsigned int BitPos; }

variable_types:
swaps
unsigned int

variable_types:
symbol
unsigned int


UnCompress

decompiled_code:
void __fastcall UnCompress(__int64 a1, __int64 a2, int a3)
{
_DWORD *v3; // rdx
int v4; // er9
_BYTE *v5; // r10
__int64 v6; // r11
_BYTE *v7; // rbx
int i; // eax
int v9; // eax
__int64 *v10; // r8
__int64 v11; // rdx
unsigned __int8 *v12[2]; // [rsp+4h] [rbp-3008h] BYREF
char v13[12280]; // [rsp+14h] [rbp-2FF8h] BYREF

if ( a3 )
{
InitBitStream((__int64)v12, a1);
v6 = RecoverHuffmanTree((__int64)v13, v12, v3);
if ( v4 )
{
v7 = &v5[v4];
do
{
for ( i = *(_DWORD *)(v6 + 16); i < 0; i = *(_DWORD *)(v11 + 16) )
{
v9 = ReadBitFromBitStream(v12);
v11 = *v10;
if ( v9 )
v11 = v10[1];
}
*v5++ = i;
}
while ( v5 != v7 );
}
}
}

original_code:
void UnCompress( unsigned char *in, unsigned char *out, unsigned int insize, unsigned int outsize )
{
  HuffmanDecodeNode nodes[511], *root, *node;
  BitStream stream;
  unsigned int k, node_count;
  unsigned char *buf;
  if( insize < 1 ) return;
  InitBitStream( &stream, in );
  node_count = 0;
  root = RecoverHuffmanTree( nodes, &stream, &node_count );
  buf = out;
  for( k = 0; k < outsize; ++ k )
  {
    node = root;
    while( node->Symbol < 0 )
    {
      if( ReadBitFromBitStream( &stream ) )
        node = node->ChildB;
      else
        node = node->ChildA;
    }
    *buf ++ = (unsigned char) node->Symbol;
  }
}

canonical_original_code:
void UnCompress(unsigned char *in, unsigned char *out, unsigned int insize, unsigned int outsize)
{
  struct huff_decodenode_struct nodes[511]; struct huff_decodenode_struct *root; struct huff_decodenode_struct *node;
  struct BitStream stream;
  unsigned int k; unsigned int node_count;
  unsigned char *buf;
  if( insize < 1 ) return;
  InitBitStream( &stream, in );
  node_count = 0;
  root = RecoverHuffmanTree( nodes, &stream, &node_count );
  buf = out;
  for( k = 0; k < outsize; ++ k )
  {
    node = root;
    while( node->Symbol < 0 )
    {
      if( ReadBitFromBitStream( &stream ) )
        node = node->ChildB;
      else
        node = node->ChildA;
    }
    *buf ++ = (unsigned char) node->Symbol;
  }
}

variable_types:
in
unsigned char *

variable_types:
out
unsigned char *

variable_types:
insize
unsigned int

variable_types:
outsize
unsigned int

variable_types: struct huff_decodenode_struct { struct huff_decodenode_struct *ChildA; int Symbol; } [511]

variable_types:
buf
unsigned char *


Help

decompiled_code:
int __fastcall Help(const char *a1)
{
printf("Usage: %s -Operation infile outfile\n\n", a1);
puts("Operations:");
puts(" c Compress");
return puts(" d Deompress\n");
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
printf("Usage: %s -Operation infile outfile\n\n", a1);
puts("Operations:");
puts(" c Compress");
return puts(" d Deompress\n");
}

original_code:
void Help( char *prgname ){
    printf( "Usage: %s -Operation infile outfile\n\n", prgname );
    printf( "Operations:\n" );
    printf( "  c       Compress\n" );
    printf( "  d       Deompress\n\n" );
}

canonical_original_code:
void Help(char *prgname){
    printf( "Usage: %s -Operation infile outfile\n\n", prgname );
    printf( "Operations:\n" );
    printf( "  c       Compress\n" );
    printf( "  d       Deompress\n\n" );
}

variable_types:
prgname
char *


repo: gundermanc/gunderscript

decompiled_code:
__int64 __fastcall resize_stack(__int64 a1, int a2)
{
void *v2; // rax
void *v3; // r13
void *v4; // rbp
__int64 result; // rax

v2 = calloc(a2, 9uLL);
if ( !v2 )
return 0LL;
v3 = *(void **)a1;
v4 = v2;
memcpy(v2, *(const void **)a1, 9LL * *(int *)(a1 + 16));
free(v3);
*(_QWORD *)a1 = v4;
result = 1LL;
*(_DWORD *)(a1 + 8) = a2;
return result;
}

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

v2 = calloc(a2, 9uLL);
if ( !v2 )
return 0LL;
v3 = *(void **)a1;
v4 = v2;
memcpy(v2, *(const void **)a1, 9LL * *(int *)(a1 + 16));
free(v3);
*(_QWORD *)a1 = v4;
result = 1LL;
*(_DWORD *)(a1 + 8) = a2;
return result;
}

original_code:
static int resize_stack(TypeStk * stack, int newSize) {
  TypeStkData * newBuffer = calloc(newSize, sizeof(TypeStkData));
  if(newBuffer != ((void *)0)) {
    memcpy(newBuffer, stack->stack, sizeof(TypeStkData) * stack->size);
    free(stack->stack);
    stack->stack = newBuffer;
    stack->depth = newSize;
    return 1;
  }
  return 0;
}

canonical_original_code:
static int resize_stack(struct TypeStk *stack, int newSize) {
  struct TypeStkData *newBuffer = calloc(newSize, sizeof(TypeStkData));
  if(newBuffer != ((void *)0)) {
    memcpy(newBuffer, stack->stack, sizeof(TypeStkData) * stack->size);
    free(stack->stack);
    stack->stack = newBuffer;
    stack->depth = newSize;
    return 1;
  }
  return 0;
}

variable_types: struct TypeStk { struct TypeStkData { char type; char data[-1]; } *stack; int depth; int blockSize; int size; } *

variable_types: newSize int

user_defined_types: struct TypeStk { struct TypeStkData *stack; int depth; int blockSize; int size; }


decompiled_code:
_BOOL8 __fastcall check_size(_DWORD *a1)
{
int v1; // esi
_BOOL8 result; // rax

v1 = a1[4];
if ( a1[2] == v1 )
result = (unsigned int)resize_stack((__int64)a1, a1[3] + v1) != 0;
else
result = 1LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
int v1; // esi
_BOOL8 result; // rax

v1 = a1[4];
if ( a1[2] == v1 )
result = (unsigned int)func0((__int64)a1, a1[3] + v1) != 0;
else
result = 1LL;
return result;
}

original_code:
static int check_size(TypeStk * stack) {
  if((stack->depth - stack->size) != 0) {
    return 1;
  }
  if(resize_stack(stack, stack->size + stack->blockSize)) {
    return 1;
  }
  return 0;
}

canonical_original_code:
static int check_size(struct TypeStk *stack) {
  if((stack->depth - stack->size) != 0) {
    return 1;
  }
  if(resize_stack(stack, stack->size + stack->blockSize)) {
    return 1;
  }
  return 0;
}

user_defined_types: struct TypeStkData { char type; char data[-1]; }


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

if ( !ptr )
_assert_fail("stack != NULL", "src/typestk.c", 0x49u, "typestk_free");
v2 = *(void **)ptr;
if ( !v2 )
_assert_fail("stack->stack != NULL", "src/typestk.c", 0x4Au, "typestk_free");
free(v2);
free(ptr);
}

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

if ( !ptr )
_assert_fail("stack != NULL", "src/typestk.c", 0x49u, "typestk_free");
v2 = *(void **)ptr;
if ( !v2 )
_assert_fail("stack->stack != NULL", "src/typestk.c", 0x4Au, "typestk_free");
free(v2);
free(ptr);
}

original_code:
void typestk_free(TypeStk * stack) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((stack->stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack->stack != ((void *)0)) ; else __assert_fail ("stack->stack != NULL", "src/typestk.c", 74, __extension__ __PRETTY_FUNCTION__); }));
  free(stack->stack);
  free(stack);
}

canonical_original_code:
void typestk_free(struct TypeStk *stack) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 73, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((stack->stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack->stack != ((void *)0)) ; else __assert_fail ("stack->stack != NULL", "src/typestk.c", 74, __extension__ __PRETTY_FUNCTION__); }));
  free(stack->stack);
  free(stack);
}


decompiled_code:
__int64 __fastcall typestk_push(_DWORD *a1, const void *a2, size_t a3, char a4)
{
__int64 v7; // rax
_BYTE *v9; // rdi

if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0x87u, "typestk_push");
if ( !a2 )
_assert_fail("data != NULL", "src/typestk.c", 0x88u, "typestk_push");
if ( !a3 )
_assert_fail("dataSize > 0", "src/typestk.c", 0x89u, "typestk_push");
if ( a1[3] && !check_size(a1) )
return 0LL;
v7 = (int)a1[4];
if ( (int)v7 >= a1[2] || a3 - 1 > 7 )
return 0LL;
v9 = (_BYTE *)(*(_QWORD *)a1 + 9 * v7);
*v9 = a4;
memcpy(v9 + 1, a2, a3);
++a1[4];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, const void *a2, size_t a3, char a4)
{
__int64 v7; // rax
_BYTE *v9; // rdi

if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0x87u, "typestk_push");
if ( !a2 )
_assert_fail("data != NULL", "src/typestk.c", 0x88u, "typestk_push");
if ( !a3 )
_assert_fail("dataSize > 0", "src/typestk.c", 0x89u, "typestk_push");
if ( a1[3] && !func1(a1) )
return 0LL;
v7 = (int)a1[4];
if ( (int)v7 >= a1[2] || a3 - 1 > 7 )
return 0LL;
v9 = (_BYTE *)(*(_QWORD *)a1 + 9 * v7);
*v9 = a4;
memcpy(v9 + 1, a2, a3);
++a1[4];
return 1LL;
}

original_code:
int typestk_push(TypeStk * stack, void * data, size_t dataSize, VarType type) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 135, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "src/typestk.c", 136, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((dataSize > 0) ? 1 : 0), __extension__ ({ if (dataSize > 0) ; else __assert_fail ("dataSize > 0", "src/typestk.c", 137, __extension__ __PRETTY_FUNCTION__); }));
  if(stack->blockSize != 0) {
    if(!check_size(stack)) {
      return 0;
    }
  }
  if((stack->size < stack->depth)
     && dataSize > 0 && dataSize <= sizeof(double)) {
    stack->stack[stack->size].type = type;
    memcpy(stack->stack[stack->size].data, data, dataSize);
    stack->size++;
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
int typestk_push(struct TypeStk *stack, void *data, unsigned long dataSize, enum VarType type) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 135, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "src/typestk.c", 136, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((dataSize > 0) ? 1 : 0), __extension__ ({ if (dataSize > 0) ; else __assert_fail ("dataSize > 0", "src/typestk.c", 137, __extension__ __PRETTY_FUNCTION__); }));
  if(stack->blockSize != 0) {
    if(!check_size(stack)) {
      return 0;
    }
  }
  if((stack->size < stack->depth)
     && dataSize > 0 && dataSize <= sizeof(double)) {
    stack->stack[stack->size].type = type;
    memcpy(stack->stack[stack->size].data, data, dataSize);
    stack->size++;
    return 1;
  } else {
    return 0;
  }
}

variable_types:
data
void *

variable_types:
dataSize
unsigned long

variable_types: enum VarType { TYPE_NULL=0, TYPE_BOOLEAN=1, TYPE_NUMBER=2, TYPE_LIBDATA=3 }


decompiled_code:
__int64 __fastcall typestk_peek(__int64 a1, void *a2, size_t a3, _DWORD *a4)
{
__int64 v5; // rax
unsigned int v6; // er8

if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0xB1u, "typestk_peek");
if ( !*(_QWORD *)a1 )
_assert_fail("stack->stack != NULL", "src/typestk.c", 0xB2u, "typestk_peek");
v5 = *(int *)(a1 + 16);
v6 = 0;
if ( (int)v5 <= 0 || a3 - 1 > 7 )
return v6;
if ( a2 )
memcpy(a2, (const void *)(*(_QWORD *)a1 + 9 * v5 - 9 + 1), a3);
v6 = 1;
if ( !a4 )
return v6;
*a4 = *(char *)(*(_QWORD *)a1 + 9LL * *(int *)(a1 + 16) - 9);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, void *a2, size_t a3, _DWORD *a4)
{
__int64 v5; // rax
unsigned int v6; // er8

if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0xB1u, "typestk_peek");
if ( !*(_QWORD *)a1 )
_assert_fail("stack->stack != NULL", "src/typestk.c", 0xB2u, "typestk_peek");
v5 = *(int *)(a1 + 16);
v6 = 0;
if ( (int)v5 <= 0 || a3 - 1 > 7 )
return v6;
if ( a2 )
memcpy(a2, (const void *)(*(_QWORD *)a1 + 9 * v5 - 9 + 1), a3);
v6 = 1;
if ( !a4 )
return v6;
*a4 = *(char *)(*(_QWORD *)a1 + 9LL * *(int *)(a1 + 16) - 9);
return 1LL;
}

original_code:
int typestk_peek(TypeStk * stack, void * value,
    size_t valueSize, VarType * type) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 177, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((stack->stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack->stack != ((void *)0)) ; else __assert_fail ("stack->stack != NULL", "src/typestk.c", 178, __extension__ __PRETTY_FUNCTION__); }));
  if(stack->size > 0 && valueSize > 0 && valueSize <= sizeof(double)) {
    if(value != ((void *)0)) {
      ((void) sizeof ((valueSize > 0) ? 1 : 0), __extension__ ({ if (valueSize > 0) ; else __assert_fail ("valueSize > 0", "src/typestk.c", 183, __extension__ __PRETTY_FUNCTION__); }));
      memcpy(value, &stack->stack[stack->size-1].data, valueSize);
    }
    if(type != ((void *)0)) {
      *type = stack->stack[stack->size-1].type;
    }
    return 1;
  }
  return 0;
}

canonical_original_code:
int typestk_peek(struct TypeStk *stack, void *value, unsigned long valueSize, enum VarType *type) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 177, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((stack->stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack->stack != ((void *)0)) ; else __assert_fail ("stack->stack != NULL", "src/typestk.c", 178, __extension__ __PRETTY_FUNCTION__); }));
  if(stack->size > 0 && valueSize > 0 && valueSize <= sizeof(double)) {
    if(value != ((void *)0)) {
      ((void) sizeof ((valueSize > 0) ? 1 : 0), __extension__ ({ if (valueSize > 0) ; else __assert_fail ("valueSize > 0", "src/typestk.c", 183, __extension__ __PRETTY_FUNCTION__); }));
      memcpy(value, &stack->stack[stack->size-1].data, valueSize);
    }
    if(type != ((void *)0)) {
      *type = stack->stack[stack->size-1].type;
    }
    return 1;
  }
  return 0;
}

variable_types:
value
void *

variable_types:
valueSize
unsigned long

variable_types: enum VarType { TYPE_NULL=0, TYPE_BOOLEAN=1, TYPE_NUMBER=2, TYPE_LIBDATA=3 } *


decompiled_code:
__int64 __fastcall typestk_pop(__int64 a1, void *a2, size_t a3, _DWORD *a4)
{
__int64 result; // rax

if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0xD4u, "typestk_pop");
if ( !a2 )
_assert_fail("value != NULL", "src/typestk.c", 0xD5u, "typestk_pop");
if ( !a3 )
_assert_fail("valueSize > 0", "src/typestk.c", 0xD6u, "typestk_pop");
result = typestk_peek(a1, a2, a3, a4);
if ( (_DWORD)result )
{
--*(_DWORD *)(a1 + 16);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, void *a2, size_t a3, _DWORD *a4)
{
__int64 result; // rax

if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0xD4u, "typestk_pop");
if ( !a2 )
_assert_fail("value != NULL", "src/typestk.c", 0xD5u, "typestk_pop");
if ( !a3 )
_assert_fail("valueSize > 0", "src/typestk.c", 0xD6u, "typestk_pop");
result = func4(a1, a2, a3, a4);
if ( (_DWORD)result )
{
--*(_DWORD *)(a1 + 16);
result = 1LL;
}
return result;
}

original_code:
int typestk_pop(TypeStk * stack, void * value,
   size_t valueSize, VarType * type) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 212, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((value != ((void *)0)) ? 1 : 0), __extension__ ({ if (value != ((void *)0)) ; else __assert_fail ("value != NULL", "src/typestk.c", 213, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((valueSize > 0) ? 1 : 0), __extension__ ({ if (valueSize > 0) ; else __assert_fail ("valueSize > 0", "src/typestk.c", 214, __extension__ __PRETTY_FUNCTION__); }));
  if(typestk_peek(stack, value, valueSize, type)) {
    stack->size--;
    return 1;
  }
  return 0;
}

canonical_original_code:
int typestk_pop(struct TypeStk *stack, void *value, unsigned long valueSize, enum VarType *type) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 212, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((value != ((void *)0)) ? 1 : 0), __extension__ ({ if (value != ((void *)0)) ; else __assert_fail ("value != NULL", "src/typestk.c", 213, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((valueSize > 0) ? 1 : 0), __extension__ ({ if (valueSize > 0) ; else __assert_fail ("valueSize > 0", "src/typestk.c", 214, __extension__ __PRETTY_FUNCTION__); }));
  if(typestk_peek(stack, value, valueSize, type)) {
    stack->size--;
    return 1;
  }
  return 0;
}

user_defined_types: enum VarType { TYPE_NULL=0, TYPE_BOOLEAN=1, TYPE_NUMBER=2, TYPE_LIBDATA=3 }


decompiled_code:
__int64 __fastcall typestk_size(__int64 a1)
{
if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0xE6u, "typestk_size");
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
_assert_fail("stack != NULL", "src/typestk.c", 0xE6u, "typestk_size");
return *(unsigned int *)(a1 + 16);
}

original_code:
int typestk_size(TypeStk * stack) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 230, __extension__ __PRETTY_FUNCTION__); }));
  return stack->size;
}

canonical_original_code:
int typestk_size(struct TypeStk *stack) {
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/typestk.c", 230, __extension__ __PRETTY_FUNCTION__); }));
  return stack->size;
}


decompiled_code:
__int64 __fastcall buffer_resize(__int64 a1, int a2)
{
void *v2; // rax
void *v3; // r13
void *v4; // rbp
__int64 result; // rax

v2 = calloc(a2 + 1, 1uLL);
if ( !v2 )
return 0LL;
v3 = *(void **)a1;
v4 = v2;
memcpy(v2, *(const void **)a1, *(int *)(a1 + 8));
free(v3);
*(_QWORD *)a1 = v4;
result = 1LL;
*(_DWORD *)(a1 + 16) = a2;
return result;
}

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

v2 = calloc(a2 + 1, 1uLL);
if ( !v2 )
return 0LL;
v3 = *(void **)a1;
v4 = v2;
memcpy(v2, *(const void **)a1, *(int *)(a1 + 8));
free(v3);
*(_QWORD *)a1 = v4;
result = 1LL;
*(_DWORD *)(a1 + 16) = a2;
return result;
}

original_code:
int buffer_resize(Buffer * buffer, int newSize) {
  void * newBuffer = calloc(newSize + 1, sizeof(char));
  if(newBuffer == ((void *)0)) {
    return 0;
  }
  memcpy(newBuffer, buffer->buffer, buffer->index);
  free(buffer->buffer);
  buffer->buffer = newBuffer;
  buffer->currentSize = newSize;
  return 1;
}

canonical_original_code:
int buffer_resize(struct Buffer *buffer, int newSize) {
  void *newBuffer = calloc(newSize + 1, sizeof(char));
  if(newBuffer == ((void *)0)) {
    return 0;
  }
  memcpy(newBuffer, buffer->buffer, buffer->index);
  free(buffer->buffer);
  buffer->buffer = newBuffer;
  buffer->currentSize = newSize;
  return 1;
}

variable_types: struct Buffer { char *buffer; int index; int blockSize; int currentSize; } *

variable_types:
newBuffer
void *


decompiled_code:
__int64 __fastcall buffer_get_buffer(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0x66u, "buffer_get_buffer");
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0x66u, "buffer_get_buffer");
return *(_QWORD *)a1;
}

original_code:
char * buffer_get_buffer(Buffer * buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  return buffer->buffer;
}

canonical_original_code:
char *buffer_get_buffer(struct Buffer *buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 102, __extension__ __PRETTY_FUNCTION__); }));
  return buffer->buffer;
}

return_type: char *

user_defined_types: struct Buffer { char *buffer; int index; int blockSize; int currentSize; }


decompiled_code:
__int64 __fastcall buffer_set_char(__int64 a1, char a2, int a3)
{
int v4; // esi
__int64 v5; // rbx
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 16);
v5 = a3;
if ( v4 > a3 || (result = buffer_resize(a1, *(_DWORD *)(a1 + 12) + v4), (_DWORD)result) )
{
if ( *(_DWORD *)(a1 + 8) <= (int)v5 )
*(_DWORD *)(a1 + 8) = v5 + 1;
*(_BYTE *)(*(_QWORD *)a1 + v5) = a2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2, int a3)
{
int v4; // esi
__int64 v5; // rbx
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 16);
v5 = a3;
if ( v4 > a3 || (result = func0(a1, *(_DWORD *)(a1 + 12) + v4), (_DWORD)result) )
{
if ( *(_DWORD *)(a1 + 8) <= (int)v5 )
*(_DWORD *)(a1 + 8) = v5 + 1;
*(_BYTE *)(*(_QWORD *)a1 + v5) = a2;
result = 1LL;
}
return result;
}

original_code:
int buffer_set_char(Buffer * buffer, char c, int index) {
  if(index >= buffer->currentSize) {
    if(!buffer_resize(buffer, buffer->currentSize + buffer->blockSize)) {
      return 0;
    }
  }
  if(index >= buffer->index) {
    buffer->index = index + 1;
  }
  buffer->buffer[index] = c;
  return 1;
}

canonical_original_code:
int buffer_set_char(struct Buffer *buffer, char c, int index) {
  if(index >= buffer->currentSize) {
    if(!buffer_resize(buffer, buffer->currentSize + buffer->blockSize)) {
      return 0;
    }
  }
  if(index >= buffer->index) {
    buffer->index = index + 1;
  }
  buffer->buffer[index] = c;
  return 1;
}

variable_types: c char

variable_types: index int


decompiled_code:
__int64 __fastcall buffer_append_char(__int64 a1, char a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0x5Cu, "buffer_append_char");
buffer_set_char(a1, a2, *(_DWORD *)(a1 + 8));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0x5Cu, "buffer_append_char");
func2(a1, a2, *(_DWORD *)(a1 + 8));
return 1LL;
}

original_code:
int buffer_append_char(Buffer * buffer, char c) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  buffer_set_char(buffer, c, buffer->index);
  return 1;
}

canonical_original_code:
int buffer_append_char(struct Buffer *buffer, char c) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  buffer_set_char(buffer, c, buffer->index);
  return 1;
}


decompiled_code:
__int64 __fastcall buffer_set_string(__int64 a1, char *a2, int a3, int a4)
{
int v4; // er13
__int64 v5; // r12
char *v6; // rbx
__int64 result; // rax

if ( a3 <= 0 )
return 1LL;
v4 = a4 - (_DWORD)a2;
v5 = (__int64)&a2[a3 - 1 + 1];
v6 = a2;
while ( 1 )
{
result = buffer_set_char(a1, *v6, v4 + (int)v6);
if ( !(_DWORD)result )
break;
if ( ++v6 == (char *)v5 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2, int a3, int a4)
{
int v4; // er13
__int64 v5; // r12
char *v6; // rbx
__int64 result; // rax

if ( a3 <= 0 )
return 1LL;
v4 = a4 - (_DWORD)a2;
v5 = (__int64)&a2[a3 - 1 + 1];
v6 = a2;
while ( 1 )
{
result = func2(a1, *v6, v4 + (int)v6);
if ( !(_DWORD)result )
break;
if ( ++v6 == (char *)v5 )
return 1LL;
}
return result;
}

original_code:
int buffer_set_string(Buffer * buffer, char * input,
         int inputLen, int index) {
  int i = index;
  for(i = 0; i < inputLen; i++) {
    if(!buffer_set_char(buffer, input[i], index + i)) {
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
int buffer_set_string(struct Buffer *buffer, char *input, int inputLen, int index) {
  int i = index;
  for(i = 0; i < inputLen; i++) {
    if(!buffer_set_char(buffer, input[i], index + i)) {
      return 0;
    }
  }
  return 1;
}

variable_types:
input
char *

variable_types: inputLen int

variable_types: i int


decompiled_code:
__int64 __fastcall buffer_append_string(__int64 a1, char *a2, int a3)
{
buffer_set_string(a1, a2, a3, *(_DWORD *)(a1 + 8));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2, int a3)
{
func4(a1, a2, a3, *(_DWORD *)(a1 + 8));
return 1LL;
}

original_code:
int buffer_append_string(Buffer * buffer, char * input, int inputLen) {
  buffer_set_string(buffer, input, inputLen, buffer->index);
  return 1;
}

canonical_original_code:
int buffer_append_string(struct Buffer *buffer, char *input, int inputLen) {
  buffer_set_string(buffer, input, inputLen, buffer->index);
  return 1;
}


decompiled_code:
__int64 __fastcall buffer_size(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0xA9u, "buffer_size");
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0xA9u, "buffer_size");
return *(unsigned int *)(a1 + 8);
}

original_code:
int buffer_size(Buffer * buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  return buffer->index;
}

canonical_original_code:
int buffer_size(struct Buffer *buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 169, __extension__ __PRETTY_FUNCTION__); }));
  return buffer->index;
}


decompiled_code:
__int64 __fastcall buffer_buffer_size(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0xB3u, "buffer_buffer_size");
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != NULL", "src/buffer.c", 0xB3u, "buffer_buffer_size");
return *(unsigned int *)(a1 + 16);
}

original_code:
int buffer_buffer_size(Buffer * buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 179, __extension__ __PRETTY_FUNCTION__); }));
  return buffer->currentSize;
}

canonical_original_code:
int buffer_buffer_size(struct Buffer *buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 179, __extension__ __PRETTY_FUNCTION__); }));
  return buffer->currentSize;
}


decompiled_code:
void __fastcall buffer_free(void *ptr)
{
if ( !ptr )
_assert_fail("buffer != NULL", "src/buffer.c", 0xBBu, "buffer_free");
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
if ( !ptr )
_assert_fail("buffer != NULL", "src/buffer.c", 0xBBu, "buffer_free");
free(*(void **)ptr);
free(ptr);
}

original_code:
void buffer_free(Buffer * buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 187, __extension__ __PRETTY_FUNCTION__); }));
  free(buffer->buffer);
  free(buffer);
}

canonical_original_code:
void buffer_free(struct Buffer *buffer) {
  ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "src/buffer.c", 187, __extension__ __PRETTY_FUNCTION__); }));
  free(buffer->buffer);
  free(buffer);
}


repo: guobamantou/loongson-uefi

decompiled_code:
void __fastcall __noreturn internal_error(char *format, __int64 a2, unsigned int a3)
{
fprintf(stderr, format, a2, a3);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *format, __int64 a2, unsigned int a3)
{
fprintf(stderr, format, a2, a3);
exit(1);
}

original_code:
void internal_error(char *s, char *file,int line)
{
 fprintf(stderr,s,file,line);
 exit(1);
}

canonical_original_code:
void internal_error(char *s, char *file, int line)
{
 fprintf(stderr,s,file,line);
 exit(1);
}

variable_types:
s
char *

variable_types:
file
char *

variable_types: line int


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

result = malloc(a1);
if ( !result )
internal_error("%s(%d): unable to allocate memory\n", a2, a3);
return result;
}

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

result = malloc(a1);
if ( !result )
func0("%s(%d): unable to allocate memory\n", a2, a3);
return result;
}

original_code:
char *dlg_malloc(int bytes,char *file,int line)
{
 char *t;
 t = (char *) malloc(bytes);
 if (!t){
  internal_error("%s(%d): unable to allocate memory\n",
   file,line);
 }
 return t;
}

canonical_original_code:
char *dlg_malloc(int bytes, char *file, int line)
{
 char *t;
 t = (char *) malloc(bytes);
 if (!t){
  internal_error("%s(%d): unable to allocate memory\n",
   file,line);
 }
 return t;
}

variable_types: bytes int

variable_types:
t
char *


decompiled_code:
void *__fastcall dlg_calloc(int a1, int a2, __int64 a3, unsigned int a4)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
internal_error("%s(%d): unable to allocate memory\n", a3, a4);
return result;
}

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

result = calloc(a1, a2);
if ( !result )
func0("%s(%d): unable to allocate memory\n", a3, a4);
return result;
}

original_code:
char *dlg_calloc(int n,int bytes,char *file,int line)
{
 char *t;
 t = (char *) calloc(n,bytes);
 if (!t){
  internal_error("%s(%d): unable to allocate memory\n",
   file,line);
 }
 return t;
}

canonical_original_code:
char *dlg_calloc(int n, int bytes, char *file, int line)
{
 char *t;
 t = (char *) calloc(n,bytes);
 if (!t){
  internal_error("%s(%d): unable to allocate memory\n",
   file,line);
 }
 return t;
}

variable_types: n int


warning

decompiled_code:
int __fastcall warning(const char *a1, unsigned int a2)
{
const char *v2; // rdx

v2 = (const char *)file_str;
if ( !file_str )
v2 = "stdin";
fprintf(stderr, "%s, line %d:", v2, a2);
return fprintf(stderr, " Warning: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, unsigned int a2)
{
const char *v2; // rdx

v2 = (const char *)file_str;
if ( !file_str )
v2 = "stdin";
fprintf(stderr, "%s, line %d:", v2, a2);
return fprintf(stderr, " Warning: %s\n", a1);
}

original_code:
void warning(char *message,int line_no)
{
 fprintf(stderr,"%s, line %d:",
  (file_str[0] ? file_str[0] : "stdin"), line_no);
 fprintf(stderr, " Warning: %s\n", message);
}

canonical_original_code:
void warning(char *message, int line_no)
{
 fprintf(stderr,"%s, line %d:",
  (file_str[0] ? file_str[0] : "stdin"), line_no);
 fprintf(stderr, " Warning: %s\n", message);
}

variable_types:
message
char *


fatal

decompiled_code:
void __fastcall __noreturn fatal(const char *a1, unsigned int a2)
{
const char *v2; // rdx

v2 = (const char *)file_str;
if ( !file_str )
v2 = "stdin";
fprintf(stderr, "%s, line %d:", v2, a2);
fprintf(stderr, " Fatal: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1, unsigned int a2)
{
const char *v2; // rdx

v2 = (const char *)file_str;
if ( !file_str )
v2 = "stdin";
fprintf(stderr, "%s, line %d:", v2, a2);
fprintf(stderr, " Fatal: %s\n", a1);
exit(1);
}

original_code:
void fatal(char *message,int line_no)
{
 fprintf(stderr,"%s, line %d:",
  (file_str[0] ? file_str[0] : "stdin"), line_no);
 fprintf(stderr, " Fatal: %s\n", message);
 exit(1);
}

canonical_original_code:
void fatal(char *message, int line_no)
{
 fprintf(stderr,"%s, line %d:",
  (file_str[0] ? file_str[0] : "stdin"), line_no);
 fprintf(stderr, " Fatal: %s\n", message);
 exit(1);
}


error

decompiled_code:
int __fastcall error(const char *a1, unsigned int a2)
{
const char *v2; // rdx
int result; // eax

v2 = (const char *)file_str;
if ( !file_str )
v2 = "stdin";
fprintf(stderr, "%s, line %d:", v2, a2);
result = fprintf(stderr, " Error: %s\n", a1);
err_found = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, unsigned int a2)
{
const char *v2; // rdx
int result; // eax

v2 = (const char *)file_str;
if ( !file_str )
v2 = "stdin";
fprintf(stderr, "%s, line %d:", v2, a2);
result = fprintf(stderr, " Error: %s\n", a1);
err_found = 1;
return result;
}

original_code:
void error(char *message,int line_no)
{
 fprintf(stderr,"%s, line %d:",
  (file_str[0] ? file_str[0] : "stdin"), line_no);
 fprintf(stderr, " Error: %s\n", message);
 err_found = 1;
}

canonical_original_code:
void error(char *message, int line_no)
{
 fprintf(stderr,"%s, line %d:",
  (file_str[0] ? file_str[0] : "stdin"), line_no);
 fprintf(stderr, " Error: %s\n", message);
 err_found = 1;
}


OutMetaName

decompiled_code:
char *__fastcall OutMetaName(char *s)
{
char *v1; // rbp
const char *v2; // r12
char *result; // rax
char *v4; // rax
char *v5; // rax

v1 = s;
v2 = OutputDirectory;
if ( *OutputDirectory != 46 || (result = s, OutputDirectory[1]) )
{
v4 = strrchr(s, 47);
if ( v4 )
v1 = v4 + 1;
v5 = stpcpy(newname_0, v2);
if ( *(v5 - 1) != 47 )
*(_WORD *)v5 = 47;
strcat(newname_0, v1);
result = newname_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *s)
{
char *v1; // rbp
const char *v2; // r12
char *result; // rax
char *v4; // rax
char *v5; // rax

v1 = s;
v2 = OutputDirectory;
if ( *OutputDirectory != 46 || (result = s, OutputDirectory[1]) )
{
v4 = strrchr(s, 47);
if ( v4 )
v1 = v4 + 1;
v5 = stpcpy(newname_0, v2);
if ( *(v5 - 1) != 47 )
*(_WORD *)v5 = 47;
strcat(newname_0, v1);
result = newname_0;
}
return result;
}

original_code:
char *OutMetaName(char *n)
{
    static char *dir_sym = "/";
    static char newname[300 +1];
    char *p;
    if (strcmp(OutputDirectory, ".") == 0)
  return n;
 if ((p = strrchr(n, *dir_sym)) != ((void *)0))
  p++;
 else
  p = n;
 strcpy(newname, OutputDirectory);
 if (newname[strlen(newname)-1] != *dir_sym)
  strcat(newname, dir_sym);
 strcat(newname, p);
 return newname;
}

canonical_original_code:
char *OutMetaName(char *n)
{
    static char *dir_sym = "/";
    static char newname[-1];
    char *p;
    if (strcmp(OutputDirectory, ".") == 0)
  return n;
 if ((p = strrchr(n, *dir_sym)) != ((void *)0))
  p++;
 else
  p = n;
 strcpy(newname, OutputDirectory);
 if (newname[strlen(newname)-1] != *dir_sym)
  strcat(newname, dir_sym);
 strcat(newname, p);
 return newname;
}

variable_types:
n
char *

variable_types:
newname
char [-1]

variable_types:
p
char *


original_code:
static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)
{
  SRes res = 0;
  CLookToRead *p = (CLookToRead *)pp;
  size_t size2 = p->size - p->pos;
  if (size2 == 0 && *size > 0)
  {
    p->pos = 0;
    size2 = (1 << 14);
    res = p->realStream->Read(p->realStream, p->buf, &size2);
    p->size = size2;
  }
  if (size2 < *size)
    *size = size2;
  *buf = p->buf + p->pos;
  return res;
}

canonical_original_code:
static int LookToRead_Look_Lookahead(void *pp, void **buf, unsigned long *size)
{
  int res = 0;
  struct CLookToRead *p = (CLookToRead *)pp;
  unsigned long size2 = p->size - p->pos;
  if (size2 == 0 && *size > 0)
  {
    p->pos = 0;
    size2 = (1 << 14);
    res = p->realStream->Read(p->realStream, p->buf, &size2);
    p->size = size2;
  }
  if (size2 < *size)
    *size = size2;
  *buf = p->buf + p->pos;
  return res;
}

variable_types:
pp
void *

variable_types:
buf
void **

variable_types:
size
unsigned long *

variable_types: res int

variable_types: struct CLookToRead { struct ILookInStream { int (*Look)(void *p, void **buf, unsigned long *size); int (*Skip)(void *p, unsigned long offset); int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 } origin); } s; struct ISeekInStream { int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 } origin); } *realStream; unsigned long pos; unsigned long size; unsigned char buf[-1]; } *

user_defined_types: struct CLookToRead { struct ILookInStream s; struct ISeekInStream *realStream; unsigned long pos; unsigned long size; unsigned char buf[-1]; }

user_defined_types: struct ILookInStream { int (*Look)(void *p, void **buf, unsigned long *size); int (*Skip)(void *p, unsigned long offset); int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek origin); }

user_defined_types: struct ISeekInStream { int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek origin); }


original_code:
static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)
{
  SRes res = 0;
  CLookToRead *p = (CLookToRead *)pp;
  size_t size2 = p->size - p->pos;
  if (size2 == 0 && *size > 0)
  {
    p->pos = 0;
    if (*size > (1 << 14))
      *size = (1 << 14);
    res = p->realStream->Read(p->realStream, p->buf, size);
    size2 = p->size = *size;
  }
  if (size2 < *size)
    *size = size2;
  *buf = p->buf + p->pos;
  return res;
}

canonical_original_code:
static int LookToRead_Look_Exact(void *pp, void **buf, unsigned long *size)
{
  int res = 0;
  struct CLookToRead *p = (CLookToRead *)pp;
  unsigned long size2 = p->size - p->pos;
  if (size2 == 0 && *size > 0)
  {
    p->pos = 0;
    if (*size > (1 << 14))
      *size = (1 << 14);
    res = p->realStream->Read(p->realStream, p->buf, size);
    size2 = p->size = *size;
  }
  if (size2 < *size)
    *size = size2;
  *buf = p->buf + p->pos;
  return res;
}

user_defined_types: enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 }


decompiled_code:
__int64 __fastcall LookToRead_Skip(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 40) += a2;
return 0LL;
}

original_code:
static SRes LookToRead_Skip(void *pp, size_t offset)
{
  CLookToRead *p = (CLookToRead *)pp;
  p->pos += offset;
  return 0;
}

canonical_original_code:
static int LookToRead_Skip(void *pp, unsigned long offset)
{
  struct CLookToRead *p = (CLookToRead *)pp;
  p->pos += offset;
  return 0;
}

variable_types:
offset
unsigned long


original_code:
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
{
  CLookToRead *p = (CLookToRead *)pp;
  p->pos = p->size = 0;
  return p->realStream->Seek(p->realStream, pos, origin);
}

canonical_original_code:
static int LookToRead_Seek(void *pp, long long *pos, enum ESzSeek origin)
{
  struct CLookToRead *p = (CLookToRead *)pp;
  p->pos = p->size = 0;
  return p->realStream->Seek(p->realStream, pos, origin);
}

variable_types:
pos
long long *

variable_types: enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 }


decompiled_code:
__int64 __fastcall SecToRead_Read(__int64 a1)
{
return (*(__int64 (**)(void))(*(_QWORD *)(a1 + 8) + 16LL))();
}

original_code:
static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
{
  CSecToRead *p = (CSecToRead *)pp;
  return p->realStream->Read(p->realStream, buf, size);
}

canonical_original_code:
static int SecToRead_Read(void *pp, void *buf, unsigned long *size)
{
  struct CSecToRead *p = (CSecToRead *)pp;
  return p->realStream->Read(p->realStream, buf, size);
}

variable_types:
buf
void *

variable_types: struct CSecToRead { struct ISeqInStream { int (*Read)(void *p, void *buf, unsigned long *size); } s; struct ILookInStream { int (*Look)(void *p, void **buf, unsigned long *size); int (*Skip)(void *p, unsigned long offset); int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 } origin); } *realStream; } *

user_defined_types: struct CSecToRead { struct ISeqInStream s; struct ILookInStream *realStream; }


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

v4 = *(_QWORD *)(a1 + 40);
v5 = *(_QWORD *)(a1 + 48) - v4;
if ( !v5 )
return (**(__int64 (__fastcall ***)(_QWORD, void *, size_t *))(a1 + 32))(*(_QWORD *)(a1 + 32), a2, a3);
if ( *a3 <= v5 )
v5 = *a3;
v7 = v5;
memcpy(a2, (const void *)(a1 + v4 + 56), v5);
*(_QWORD *)(a1 + 40) += v7;
result = 0LL;
*a3 = v7;
return result;
}

original_code:
static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
{
  CLookToRead *p = (CLookToRead *)pp;
  size_t rem = p->size - p->pos;
  if (rem == 0)
    return p->realStream->Read(p->realStream, buf, size);
  if (rem > *size)
    rem = *size;
  memcpy(buf, p->buf + p->pos, rem);
  p->pos += rem;
  *size = rem;
  return 0;
}

canonical_original_code:
static int LookToRead_Read(void *pp, void *buf, unsigned long *size)
{
  struct CLookToRead *p = (CLookToRead *)pp;
  unsigned long rem = p->size - p->pos;
  if (rem == 0)
    return p->realStream->Read(p->realStream, buf, size);
  if (rem > *size)
    rem = *size;
  memcpy(buf, p->buf + p->pos, rem);
  p->pos += rem;
  *size = rem;
  return 0;
}

variable_types:
rem
unsigned long


decompiled_code:
__int64 __fastcall SeqInStream_Read2(__int64 (__fastcall **a1)(_QWORD, __int64, __int64 *), __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // rbx
__int64 result; // rax
__int64 v8[6]; // [rsp+0h] [rbp-30h] BYREF

if ( !a3 )
return 0LL;
v6 = a3;
while ( 1 )
{
v8[0] = v6;
result = (*a1)(a1, a2, v8);
if ( (_DWORD)result )
break;
if ( !v8[0] )
return a4;
a2 += v8[0];
v6 -= v8[0];
if ( !v6 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 (__fastcall **a1)(_QWORD, __int64, __int64 *), __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // rbx
__int64 result; // rax
__int64 v8[6]; // [rsp+0h] [rbp-30h] BYREF

if ( !a3 )
return 0LL;
v6 = a3;
while ( 1 )
{
v8[0] = v6;
result = (*a1)(a1, a2, v8);
if ( (_DWORD)result )
break;
if ( !v8[0] )
return a4;
a2 += v8[0];
v6 -= v8[0];
if ( !v6 )
return 0LL;
}
return result;
}

original_code:
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
{
  while (size != 0)
  {
    size_t processed = size;
    { int __result__ = (stream->Read(stream, buf, &processed)); if (__result__ != 0) return __result__; };
    if (processed == 0)
      return errorType;
    buf = (void *)((Byte *)buf + processed);
    size -= processed;
  }
  return 0;
}

canonical_original_code:
int SeqInStream_Read2(struct ISeqInStream *stream, void *buf, unsigned long size, int errorType)
{
  while (size != 0)
  {
    unsigned long processed = size;
    { int __result__ = (stream->Read(stream, buf, &processed)); if (__result__ != 0) return __result__; };
    if (processed == 0)
      return errorType;
    buf = (void *)((unsigned char *)buf + processed);
    size -= processed;
  }
  return 0;
}

variable_types: struct ISeqInStream { int (*Read)(void *p, void *buf, unsigned long *size); } *

variable_types:
size
unsigned long

variable_types: errorType int

variable_types:
processed
unsigned long


decompiled_code:
__int64 __fastcall SeqInStream_Read(__int64 (__fastcall **a1)(_QWORD, __int64, __int64 *), __int64 a2, __int64 a3)
{
return SeqInStream_Read2(a1, a2, a3, 6u);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 (__fastcall **a1)(_QWORD, __int64, __int64 *), __int64 a2, __int64 a3)
{
return func6(a1, a2, a3, 6u);
}

original_code:
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
{
  return SeqInStream_Read2(stream, buf, size, 6);
}

canonical_original_code:
int SeqInStream_Read(struct ISeqInStream *stream, void *buf, unsigned long size)
{
  return SeqInStream_Read2(stream, buf, size, 6);
}

user_defined_types: struct ISeqInStream { int (*Read)(void *p, void *buf, unsigned long *size); }


decompiled_code:
__int64 __fastcall SeqInStream_ReadByte(__int64 (__fastcall **a1)(_QWORD, __int64, __int64 *), __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 1LL;
result = (*a1)(a1, a2, &v3);
if ( !(_DWORD)result && v3 != 1 )
result = 6LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 (__fastcall **a1)(_QWORD, __int64, __int64 *), __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = 1LL;
result = (*a1)(a1, a2, &v3);
if ( !(_DWORD)result && v3 != 1 )
result = 6LL;
return result;
}

original_code:
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
{
  size_t processed = 1;
  { int __result__ = (stream->Read(stream, buf, &processed)); if (__result__ != 0) return __result__; };
  return (processed == 1) ? 0 : 6;
}

canonical_original_code:
int SeqInStream_ReadByte(struct ISeqInStream *stream, unsigned char *buf)
{
  unsigned long processed = 1;
  { int __result__ = (stream->Read(stream, buf, &processed)); if (__result__ != 0) return __result__; };
  return (processed == 1) ? 0 : 6;
}

variable_types:
buf
unsigned char *


decompiled_code:
__int64 __fastcall LookInStream_SeekTo(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return (*(__int64 (__fastcall **)(__int64, __int64 *, _QWORD))(a1 + 24))(a1, &v3, 0LL);
}

original_code:
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
{
  Int64 t = offset;
  return stream->Seek(stream, &t, SZ_SEEK_SET);
}

canonical_original_code:
int LookInStream_SeekTo(struct ILookInStream *stream, unsigned long long offset)
{
  long long t = offset;
  return stream->Seek(stream, &t, SZ_SEEK_SET);
}

variable_types: struct ILookInStream { int (*Look)(void *p, void **buf, unsigned long *size); int (*Skip)(void *p, unsigned long offset); int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 } origin); } *

variable_types:
offset
unsigned long long

variable_types:
t
long long


decompiled_code:
__int64 __fastcall LookInStream_LookRead(__int64 (__fastcall **a1)(_QWORD, void **), void *a2, size_t *a3)
{
__int64 result; // rax
void *src; // [rsp+0h] [rbp-20h] BYREF

result = 0LL;
if ( *a3 )
{
result = (*a1)(a1, &src);
if ( !(_DWORD)result )
{
memcpy(a2, src, *a3);
result = a1[1](a1, (void **)*a3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 (__fastcall **a1)(_QWORD, void **), void *a2, size_t *a3)
{
__int64 result; // rax
void *src; // [rsp+0h] [rbp-20h] BYREF

result = 0LL;
if ( *a3 )
{
result = (*a1)(a1, &src);
if ( !(_DWORD)result )
{
memcpy(a2, src, *a3);
result = a1[1](a1, (void **)*a3);
}
}
return result;
}

original_code:
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
{
  void *lookBuf;
  if (*size == 0)
    return 0;
  { int __result__ = (stream->Look(stream, &lookBuf, size)); if (__result__ != 0) return __result__; };
  memcpy(buf, lookBuf, *size);
  return stream->Skip(stream, *size);
}

canonical_original_code:
int LookInStream_LookRead(struct ILookInStream *stream, void *buf, unsigned long *size)
{
  void *lookBuf;
  if (*size == 0)
    return 0;
  { int __result__ = (stream->Look(stream, &lookBuf, size)); if (__result__ != 0) return __result__; };
  memcpy(buf, lookBuf, *size);
  return stream->Skip(stream, *size);
}

variable_types:
size
unsigned long *

variable_types:
lookBuf
void *


decompiled_code:
__int64 __fastcall SecToLook_Read(__int64 a1, void *a2, size_t *a3)
{
return LookInStream_LookRead(*(__int64 (__fastcall ***)(_QWORD, void **))(a1 + 8), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, void *a2, size_t *a3)
{
return func10(*(__int64 (__fastcall ***)(_QWORD, void **))(a1 + 8), a2, a3);
}

original_code:
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
{
  CSecToLook *p = (CSecToLook *)pp;
  return LookInStream_LookRead(p->realStream, buf, size);
}

canonical_original_code:
static int SecToLook_Read(void *pp, void *buf, unsigned long *size)
{
  struct CSecToLook *p = (CSecToLook *)pp;
  return LookInStream_LookRead(p->realStream, buf, size);
}

variable_types:
pp
void *

variable_types: struct CSecToLook { struct ISeqInStream { int (*Read)(void *p, void *buf, unsigned long *size); } s; struct ILookInStream { int (*Look)(void *p, void **buf, unsigned long *size); int (*Skip)(void *p, unsigned long offset); int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 } origin); } *realStream; } *

user_defined_types: struct CSecToLook { struct ISeqInStream s; struct ILookInStream *realStream; }


decompiled_code:
__int64 __fastcall LookInStream_Read2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // rbx
__int64 result; // rax
__int64 v8[6]; // [rsp+0h] [rbp-30h] BYREF

if ( !a3 )
return 0LL;
v6 = a3;
while ( 1 )
{
v8[0] = v6;
result = (*(__int64 (__fastcall **)(__int64, __int64, __int64 *))(a1 + 16))(a1, a2, v8);
if ( (_DWORD)result )
break;
if ( !v8[0] )
return a4;
a2 += v8[0];
v6 -= v8[0];
if ( !v6 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // rbx
__int64 result; // rax
__int64 v8[6]; // [rsp+0h] [rbp-30h] BYREF

if ( !a3 )
return 0LL;
v6 = a3;
while ( 1 )
{
v8[0] = v6;
result = (*(__int64 (__fastcall **)(__int64, __int64, __int64 *))(a1 + 16))(a1, a2, v8);
if ( (_DWORD)result )
break;
if ( !v8[0] )
return a4;
a2 += v8[0];
v6 -= v8[0];
if ( !v6 )
return 0LL;
}
return result;
}

original_code:
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
{
  while (size != 0)
  {
    size_t processed = size;
    { int __result__ = (stream->Read(stream, buf, &processed)); if (__result__ != 0) return __result__; };
    if (processed == 0)
      return errorType;
    buf = (void *)((Byte *)buf + processed);
    size -= processed;
  }
  return 0;
}

canonical_original_code:
int LookInStream_Read2(struct ILookInStream *stream, void *buf, unsigned long size, int errorType)
{
  while (size != 0)
  {
    unsigned long processed = size;
    { int __result__ = (stream->Read(stream, buf, &processed)); if (__result__ != 0) return __result__; };
    if (processed == 0)
      return errorType;
    buf = (void *)((unsigned char *)buf + processed);
    size -= processed;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall LookInStream_Read(__int64 a1, __int64 a2, __int64 a3)
{
return LookInStream_Read2(a1, a2, a3, 6u);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, __int64 a3)
{
return func12(a1, a2, a3, 6u);
}

original_code:
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
{
  return LookInStream_Read2(stream, buf, size, 6);
}

canonical_original_code:
int LookInStream_Read(struct ILookInStream *stream, void *buf, unsigned long size)
{
  return LookInStream_Read2(stream, buf, size, 6);
}


decompiled_code:
void __fastcall LookToRead_Init(__int64 a1)
{
*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
}

original_code:
void LookToRead_Init(CLookToRead *p)
{
  p->pos = p->size = 0;
}

canonical_original_code:
void LookToRead_Init(struct CLookToRead *p)
{
  p->pos = p->size = 0;
}

variable_types: struct CLookToRead { struct ILookInStream { int (*Look)(void *p, void **buf, unsigned long *size); int (*Skip)(void *p, unsigned long offset); int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 } origin); } s; struct ISeekInStream { int (*Read)(void *p, void *buf, unsigned long *size); int (*Seek)(void *p, long long *pos, enum ESzSeek { SZ_SEEK_SET=0, SZ_SEEK_CUR=1, SZ_SEEK_END=2 } origin); } *realStream; unsigned long pos; unsigned long size; unsigned char buf[-1]; } *


decompiled_code:
void __fastcall r_intersect(__int64 a1, __int64 *a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
__int64 v4; // rdi
__int64 v5; // rax
void *v6; // rdx
void *v7; // r12
__int64 v8; // r13
void *v9; // rdi

if ( a1 )
{
v2 = a1;
do
{
if ( *(_DWORD *)(v2 + 4) == operation_no )
break;
v3 = *(unsigned int *)(v2 + 32);
v4 = *(unsigned int *)a2;
*(_DWORD *)(v2 + 4) = operation_no;
v5 = set_and(v4, a2[1], v3, *(_QWORD *)(v2 + 40));
v7 = v6;
v8 = v5;
if ( (unsigned int)set_nil((unsigned int)v5, v6) )
{
if ( v7 )
free(v7);
}
else
{
v9 = (void *)a2[1];
if ( v9 )
free(v9);
*a2 = v8;
a2[1] = (__int64)v7;
}
r_intersect(*(_QWORD *)(v2 + 16), a2);
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
}
}

original_code:
void r_intersect(struct _nfa_node* start,set* maximal_class)
{
 set temp;
 if(start && start->nfa_set != operation_no)
 {
  start->nfa_set = operation_no;
  temp = set_and(*maximal_class,start->label);
  if (!set_nil(temp))
  {
   {if ( (*maximal_class).setword != ((void *)0) ) free((char *)((*maximal_class).setword)); (*maximal_class) = empty;};
   *maximal_class = temp;
  }else{
   {if ( (temp).setword != ((void *)0) ) free((char *)((temp).setword)); (temp) = empty;};
  }
  r_intersect(start->trans[0],maximal_class);
  r_intersect(start->trans[1],maximal_class);
 }
}

canonical_original_code:
void r_intersect(struct _nfa_node *start, struct _set *maximal_class)
{
 struct _set temp;
 if(start && start->nfa_set != operation_no)
 {
  start->nfa_set = operation_no;
  temp = set_and(*maximal_class,start->label);
  if (!set_nil(temp))
  {
   {if ( (*maximal_class).setword != ((void *)0) ) free((char *)((*maximal_class).setword)); (*maximal_class) = empty;};
   *maximal_class = temp;
  }else{
   {if ( (temp).setword != ((void *)0) ) free((char *)((temp).setword)); (temp) = empty;};
  }
  r_intersect(start->trans[0],maximal_class);
  r_intersect(start->trans[1],maximal_class);
 }
}

variable_types: struct _nfa_node { int node_no; int nfa_set; int accept; struct _nfa_node *trans[2]; struct _set { unsigned int n; unsigned int *setword; } label; } *

user_defined_types: struct _nfa_node { int node_no; int nfa_set; int accept; struct _nfa_node *trans[2]; struct _set label; }


decompiled_code:
void __fastcall intersect_nfa_labels(__int64 a1, __int64 *a2)
{
++operation_no;
r_intersect(a1, a2);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 *a2)
{
++operation_no;
func0(a1, a2);
}

original_code:
void intersect_nfa_labels(struct _nfa_node* start,set* maximal_class)
{
 ++operation_no;
 r_intersect(start,maximal_class);
}

canonical_original_code:
void intersect_nfa_labels(struct _nfa_node *start, struct _set *maximal_class)
{
 ++operation_no;
 r_intersect(start,maximal_class);
}

user_defined_types: struct _set { unsigned int n; unsigned int *setword; }


partition

decompiled_code:
void __fastcall partition(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
void *v4; // rdx
void *i; // rbp
__int64 v6; // rdx
int v7; // eax
__m128i v8; // xmm0
__int64 v9; // rdx
int v10; // er8
__int64 v11; // rax
__int64 v12; // rcx
unsigned int v13; // eax
void *v14; // rdx
void *v15; // r14
unsigned int v16; // eax
__int64 v17; // rdx
__m128i v18; // [rsp+0h] [rbp-38h] BYREF

v2 = set_dup(used_chars, *((_QWORD *)&used_chars + 1));
class_no = 0;
v3 = v2;
for ( i = v4; !(unsigned int)set_nil(v3, i); i = v15 )
{
if ( a2 > 1 )
{
v18.m128i_i32[0] = set_dup(v3, i);
v18.m128i_i64[1] = v6;
intersect_nfa_labels(a1, v18.m128i_i64);
}
else
{
v16 = set_int(v3, i);
v18.m128i_i32[0] = set_of(v16);
v18.m128i_i64[1] = v17;
}
((void (__fastcall *)(_QWORD, void *))set_orel)((unsigned int)class_no, &used_classes);
v7 = set_int(v18.m128i_u32[0], v18.m128i_i64[1]);
v8 = _mm_loadu_si128(&v18);
v9 = v18.m128i_u32[0];
v10 = v7;
v11 = class_no;
v12 = v18.m128i_i64[1];
first_el[class_no] = v10;
class_sets[v11] = (__int128)v8;
v13 = set_dif(v3, i, v9, v12);
v15 = v14;
v3 = v13;
if ( i )
free(i);
++class_no;
}
if ( i )
free(i);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
void *v4; // rdx
void *i; // rbp
__int64 v6; // rdx
int v7; // eax
__m128i v8; // xmm0
__int64 v9; // rdx
int v10; // er8
__int64 v11; // rax
__int64 v12; // rcx
unsigned int v13; // eax
void *v14; // rdx
void *v15; // r14
unsigned int v16; // eax
__int64 v17; // rdx
__m128i v18; // [rsp+0h] [rbp-38h] BYREF

v2 = set_dup(used_chars, *((_QWORD *)&used_chars + 1));
class_no = 0;
v3 = v2;
for ( i = v4; !(unsigned int)set_nil(v3, i); i = v15 )
{
if ( a2 > 1 )
{
v18.m128i_i32[0] = set_dup(v3, i);
v18.m128i_i64[1] = v6;
func1(a1, v18.m128i_i64);
}
else
{
v16 = set_int(v3, i);
v18.m128i_i32[0] = set_of(v16);
v18.m128i_i64[1] = v17;
}
((void (__fastcall *)(_QWORD, void *))set_orel)((unsigned int)class_no, &used_classes);
v7 = set_int(v18.m128i_u32[0], v18.m128i_i64[1]);
v8 = _mm_loadu_si128(&v18);
v9 = v18.m128i_u32[0];
v10 = v7;
v11 = class_no;
v12 = v18.m128i_i64[1];
first_el[class_no] = v10;
class_sets[v11] = (__int128)v8;
v13 = set_dif(v3, i, v9, v12);
v15 = v14;
v3 = v13;
if ( i )
free(i);
++class_no;
}
if ( i )
free(i);
}

original_code:
void partition(struct _nfa_node* start,int level)
{
 set current_class;
 set unpart_chars;
 set temp;
 unpart_chars = set_dup(used_chars);
 class_no = 0;
 while (!set_nil(unpart_chars)){
  if (level <= 1){
   current_class = set_of(set_int(unpart_chars));
  }else{
   current_class = set_dup(unpart_chars);
   intersect_nfa_labels(start,&current_class);
  }
  set_orel(class_no,&used_classes);
  first_el[class_no] = set_int(current_class);
  class_sets[class_no] = current_class;
  temp = set_dif(unpart_chars,current_class);
  {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
  unpart_chars = temp;
  ++class_no;
 }
 {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
}

canonical_original_code:
void partition(struct _nfa_node *start, int level)
{
 struct _set current_class;
 struct _set unpart_chars;
 struct _set temp;
 unpart_chars = set_dup(used_chars);
 class_no = 0;
 while (!set_nil(unpart_chars)){
  if (level <= 1){
   current_class = set_of(set_int(unpart_chars));
  }else{
   current_class = set_dup(unpart_chars);
   intersect_nfa_labels(start,&current_class);
  }
  set_orel(class_no,&used_classes);
  first_el[class_no] = set_int(current_class);
  class_sets[class_no] = current_class;
  temp = set_dif(unpart_chars,current_class);
  {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
  unpart_chars = temp;
  ++class_no;
 }
 {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
}

variable_types: level int

variable_types: struct _set { unsigned int n; unsigned int *setword; }


decompiled_code:
void __fastcall label_node(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
void *v4; // rdi
__int64 v5; // rdi
__m128i v6[2]; // [rsp+0h] [rbp-28h] BYREF

if ( a1 && *(_DWORD *)(a1 + 4) != operation_no )
{
*(_DWORD *)(a1 + 4) = operation_no;
v6[0] = _mm_loadu_si128(&empty);
if ( class_no > 0 )
{
v2 = 0LL;
do
{
while ( !(unsigned int)set_el((unsigned int)first_el[v2], *(unsigned int *)(a1 + 32), *(_QWORD *)(a1 + 40)) )
{
if ( class_no <= (int)++v2 )
goto LABEL_8;
}
v3 = (unsigned int)v2++;
((void (__fastcall *)(__int64, __m128i *))set_orel)(v3, v6);
}
while ( class_no > (int)v2 );
}
LABEL_8:
v4 = *(void **)(a1 + 40);
if ( v4 )
free(v4);
v5 = *(_QWORD *)(a1 + 16);
*(__m128i *)(a1 + 32) = _mm_loadu_si128(v6);
label_node(v5);
label_node(*(_QWORD *)(a1 + 24));
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
void *v4; // rdi
__int64 v5; // rdi
__m128i v6[2]; // [rsp+0h] [rbp-28h] BYREF

if ( a1 && *(_DWORD *)(a1 + 4) != operation_no )
{
*(_DWORD *)(a1 + 4) = operation_no;
v6[0] = _mm_loadu_si128(&empty);
if ( class_no > 0 )
{
v2 = 0LL;
do
{
while ( !(unsigned int)set_el((unsigned int)first_el[v2], *(unsigned int *)(a1 + 32), *(_QWORD *)(a1 + 40)) )
{
if ( class_no <= (int)++v2 )
goto LABEL_8;
}
v3 = (unsigned int)v2++;
((void (__fastcall *)(__int64, __m128i *))set_orel)(v3, v6);
}
while ( class_no > (int)v2 );
}
LABEL_8:
v4 = *(void **)(a1 + 40);
if ( v4 )
free(v4);
v5 = *(_QWORD *)(a1 + 16);
*(__m128i *)(a1 + 32) = _mm_loadu_si128(v6);
func3(v5);
func3(*(_QWORD *)(a1 + 24));
}
}

original_code:
void label_node(struct _nfa_node *start)
{
 set new_label;
 register int i;
 if (start && start->nfa_set != operation_no){
  start->nfa_set = operation_no;
  new_label = empty;
  for (i = 0; i<class_no; ++i){
   if (set_el(first_el[i],start->label))
    set_orel(i,&new_label);
  }
  {if ( (start->label).setword != ((void *)0) ) free((char *)((start->label).setword)); (start->label) = empty;};
  start->label = new_label;
  label_node(start->trans[0]);
  label_node(start->trans[1]);
 }
}

canonical_original_code:
void label_node(struct _nfa_node *start)
{
 struct _set new_label;
 register int i;
 if (start && start->nfa_set != operation_no){
  start->nfa_set = operation_no;
  new_label = empty;
  for (i = 0; i<class_no; ++i){
   if (set_el(first_el[i],start->label))
    set_orel(i,&new_label);
  }
  {if ( (start->label).setword != ((void *)0) ) free((char *)((start->label).setword)); (start->label) = empty;};
  start->label = new_label;
  label_node(start->trans[0]);
  label_node(start->trans[1]);
 }
}

variable_types: i int


decompiled_code:
void __fastcall label_with_classes(__int64 a1)
{
++operation_no;
label_node(a1);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
++operation_no;
func3(a1);
}

original_code:
void label_with_classes(struct _nfa_node* start)
{
 ++operation_no;
 label_node(start);
}

canonical_original_code:
void label_with_classes(struct _nfa_node *start)
{
 ++operation_no;
 label_node(start);
}


relabel

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

if ( a2 )
{
v3 = (void *)*((_QWORD *)&used_classes + 1);
if ( v3 )
free(v3);
used_classes = _mm_loadu_si128(&empty);
partition(a1, a2);
label_with_classes(a1);
result = (unsigned int)class_no;
}
else
{
class_no = 257;
result = 257LL;
}
return result;
}

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

if ( a2 )
{
v3 = (void *)*((_QWORD *)&used_classes + 1);
if ( v3 )
free(v3);
used_classes = _mm_loadu_si128(&empty);
func2(a1, a2);
func4(a1);
result = (unsigned int)class_no;
}
else
{
class_no = 257;
result = 257LL;
}
return result;
}

original_code:
int relabel(struct _nfa_node* start,int level)
{
 if (level){
  {if ( (used_classes).setword != ((void *)0) ) free((char *)((used_classes).setword)); (used_classes) = empty;};
  partition(start,level);
  label_with_classes(start);
 }else{
  class_no = (1+(255) - ((-1)));
 }
 return class_no;
}

canonical_original_code:
int relabel(struct _nfa_node *start, int level)
{
 if (level){
  {if ( (used_classes).setword != ((void *)0) ) free((char *)((used_classes).setword)); (used_classes) = empty;};
  partition(start,level);
  label_with_classes(start);
 }else{
  class_no = (1+(255) - ((-1)));
 }
 return class_no;
}


PeiZeroMem

decompiled_code:
void *__fastcall PeiZeroMem(void *a1, size_t a2)
{
void *result; // rax

if ( a2 )
result = memset(a1, 0, a2);
return result;
}

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

if ( a2 )
result = memset(a1, 0, a2);
return result;
}

original_code:
void
PeiZeroMem (
  void *Buffer,
  UINTN Size
  )
{
  INT8 *Ptr;
  Ptr = Buffer;
  while (Size--) {
    *(Ptr++) = 0;
  }
}

canonical_original_code:
void PeiZeroMem(void *Buffer, unsigned long Size)
{
  char *Ptr;
  Ptr = Buffer;
  while (Size--) {
    *(Ptr++) = 0;
  }
}

variable_types:
Buffer
void *

variable_types:
Size
unsigned long

variable_types:
Ptr
char *


PeiCopyMem

original_code:
void
PeiCopyMem (
  void *Destination,
  void *Source,
  UINTN Length
  )
{
  CHAR8 *Destination8;
  CHAR8 *Source8;
  Destination8 = Destination;
  Source8 = Source;
  while (Length--) {
    *(Destination8++) = *(Source8++);
  }
}

canonical_original_code:
void PeiCopyMem(void *Destination, void *Source, unsigned long Length)
{
  char *Destination8;
  char *Source8;
  Destination8 = Destination;
  Source8 = Source;
  while (Length--) {
    *(Destination8++) = *(Source8++);
  }
}

variable_types:
Destination
void *

variable_types:
Source
void *

variable_types:
Length
unsigned long


ZeroMem

decompiled_code:
// attributes: thunk
void *__fastcall ZeroMem(void *a1, size_t a2)
{
return PeiZeroMem(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
return func0(a1, a2);
}

original_code:
void
ZeroMem (
  void *Buffer,
  UINTN Size
  )
{
  PeiZeroMem (Buffer, Size);
}

canonical_original_code:
void ZeroMem(void *Buffer, unsigned long Size)
{
  PeiZeroMem (Buffer, Size);
}


CopyMem

decompiled_code:
// attributes: thunk
void __fastcall CopyMem(__int64 a1, __int64 a2, __int64 a3)
{
PeiCopyMem(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
func1(a1, a2, a3);
}

original_code:
void
CopyMem (
  void *Destination,
  void *Source,
  UINTN Length
  )
{
  PeiCopyMem (Destination, Source, Length);
}

canonical_original_code:
void CopyMem(void *Destination, void *Source, unsigned long Length)
{
  PeiCopyMem (Destination, Source, Length);
}


CompareGuid

canonical_original_code:
long CompareGuid(struct EFI_GUID *Guid1, struct EFI_GUID *Guid2)
{
  int *g1;
  int *g2;
  int r;
  g1 = (int *) Guid1;
  g2 = (int *) Guid2;
  r = g1[0] - g2[0];
  r |= g1[1] - g2[1];
  r |= g1[2] - g2[2];
  r |= g1[3] - g2[3];
  return r;
}

variable_types: struct EFI_GUID { unsigned int Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8]; } *

variable_types: r int

return_type: long


decompiled_code:
char __fastcall CalculateSum8(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
char result; // al

if ( !a2 )
return 0;
v2 = &a1[a2];
result = 0;
do
result += *a1++;
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
char __fastcall func7(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
char result; // al

if ( !a2 )
return 0;
v2 = &a1[a2];
result = 0;
do
result += *a1++;
while ( a1 != v2 );
return result;
}

original_code:
UINT8
CalculateSum8 (
  UINT8 *Buffer,
  UINTN Size
  )
{
  UINTN Index;
  UINT8 Sum;
  Sum = 0;
  for (Index = 0; Index < Size; Index++) {
    Sum = (UINT8) (Sum + Buffer[Index]);
  }
  return Sum;
}

canonical_original_code:
unsigned char CalculateSum8(unsigned char *Buffer, unsigned long Size)
{
  unsigned long Index;
  unsigned char Sum;
  Sum = 0;
  for (Index = 0; Index < Size; Index++) {
    Sum = (UINT8) (Sum + Buffer[Index]);
  }
  return Sum;
}

variable_types:
Buffer
unsigned char *

variable_types:
Index
unsigned long

variable_types:
Sum
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall CalculateChecksum8(_BYTE *a1, __int64 a2)
{
int v2; // eax

LOBYTE(v2) = CalculateSum8(a1, a2);
return (unsigned int)-v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1, __int64 a2)
{
int v2; // eax

LOBYTE(v2) = func7(a1, a2);
return (unsigned int)-v2;
}

original_code:
UINT8
CalculateChecksum8 (
  UINT8 *Buffer,
  UINTN Size
  )
{
  return (UINT8) (0x100 - CalculateSum8 (Buffer, Size));
}

canonical_original_code:
unsigned char CalculateChecksum8(unsigned char *Buffer, unsigned long Size)
{
  return (UINT8) (0x100 - CalculateSum8 (Buffer, Size));
}


decompiled_code:
__int16 __fastcall CalculateSum16(_WORD *a1, __int64 a2)
{
_WORD *v2; // rdx
__int16 result; // ax

if ( !a2 )
return 0;
v2 = &a1[a2];
result = 0;
do
result += *a1++;
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int16 __fastcall func9(_WORD *a1, __int64 a2)
{
_WORD *v2; // rdx
__int16 result; // ax

if ( !a2 )
return 0;
v2 = &a1[a2];
result = 0;
do
result += *a1++;
while ( a1 != v2 );
return result;
}

original_code:
UINT16
CalculateSum16 (
  UINT16 *Buffer,
  UINTN Size
  )
{
  UINTN Index;
  UINT16 Sum;
  Sum = 0;
  for (Index = 0; Index < Size; Index++) {
    Sum = (UINT16) (Sum + Buffer[Index]);
  }
  return (UINT16) Sum;
}

canonical_original_code:
unsigned short CalculateSum16(unsigned short *Buffer, unsigned long Size)
{
  unsigned long Index;
  unsigned short Sum;
  Sum = 0;
  for (Index = 0; Index < Size; Index++) {
    Sum = (UINT16) (Sum + Buffer[Index]);
  }
  return (unsigned short) Sum;
}

variable_types:
Buffer
unsigned short *

variable_types:
Sum
unsigned short

return_type: unsigned short