decompiled_code:
void __fastcall my_send(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
emub_send(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func22(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
func10(a1, a2, a3);
}

original_code:
void my_send(emu_board* board, uint8_t id, uint32_t msg)
{
  emub_send(board, id, msg);
}

canonical_original_code:
void my_send(struct emu_device *(*board)[256], unsigned char id, unsigned int msg)
{
  emub_send(board, id, msg);
}


devicetest

repo: uberblah/emu

decompiled_code:
void devicetest()
{
unsigned int v0; // ebx
void *v1; // rbp
_QWORD *v2; // r13
_QWORD *v3; // r12
unsigned int v4; // esi
int v5; // ebx
unsigned __int8 v6; // si
unsigned int v7; // edx

v0 = 0;
v1 = emub_create();
v2 = create_pinger();
v3 = create_pinger();
printf(">>> we are connecting two pingers, in slots %d and %d\n", 0LL, 1LL);
my_connect((__int64)v1, (__int64)v2, 0);
my_connect((__int64)v1, (__int64)v3, 1u);
puts(">>> we will now broadcast the signals 0 through 10");
do
{
v4 = v0;
v0 += 10;
my_broadcast((__int64)v1, v4);
}
while ( v0 != 100 );
v5 = 0;
puts(">>> we will now send (255 - n) to each plug n");
do
{
v6 = v5;
v7 = 256 - v5++;
my_send((__int64)v1, v6, v7);
}
while ( v5 != 256 );
puts(">>> we will now free the board");
emub_free(v1);
}

canonical_decompiled_code:
void func23()
{
unsigned int v0; // ebx
void *v1; // rbp
_QWORD *v2; // r13
_QWORD *v3; // r12
unsigned int v4; // esi
int v5; // ebx
unsigned __int8 v6; // si
unsigned int v7; // edx

v0 = 0;
v1 = func7();
v2 = func19();
v3 = func19();
printf(">>> we are connecting two pingers, in slots %d and %d\n", 0LL, 1LL);
my_connect((__int64)v1, (__int64)v2, 0);
my_connect((__int64)v1, (__int64)v3, 1u);
puts(">>> we will now broadcast the signals 0 through 10");
do
{
v4 = v0;
v0 += 10;
func21((__int64)v1, v4);
}
while ( v0 != 100 );
v5 = 0;
puts(">>> we will now send (255 - n) to each plug n");
do
{
v6 = v5;
v7 = 256 - v5++;
func22((__int64)v1, v6, v7);
}
while ( v5 != 256 );
puts(">>> we will now free the board");
func9(v1);
}

original_code:
void devicetest()
{
  emu_board* b = emub_create();
  emu_device* d1 = create_pinger();
  emu_device* d2 = create_pinger();
  int i;
  int i1 = 0;
  int i2 = 1;
  printf(">>> we are connecting two pingers, in slots %d and %d\n", i1, i2);
  my_connect(b, d1, i1);
  my_connect(b, d2, i2);
  printf(">>> we will now broadcast the signals 0 through 10\n");
  for(i = 0; i < 100; i += 10) my_broadcast(b, i);
  printf(">>> we will now send (255 - n) to each plug n\n");
  for(i = 0; i < 0x100; i++) my_send(b, i, 0x100 - i);
  printf(">>> we will now free the board\n");
  emub_free(b);
}

canonical_original_code:
void devicetest()
{
  struct emu_device *(*b)[256] = emub_create();
  struct emu_device *d1 = create_pinger();
  struct emu_device *d2 = create_pinger();
  int i;
  int i1 = 0;
  int i2 = 1;
  printf(">>> we are connecting two pingers, in slots %d and %d\n", i1, i2);
  my_connect(b, d1, i1);
  my_connect(b, d2, i2);
  printf(">>> we will now broadcast the signals 0 through 10\n");
  for(i = 0; i < 100; i += 10) my_broadcast(b, i);
  printf(">>> we will now send (255 - n) to each plug n\n");
  for(i = 0; i < 0x100; i++) my_send(b, i, 0x100 - i);
  printf(">>> we will now free the board\n");
  emub_free(b);
}

variable_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *(*)[256]

variable_types: i int

return_type: void


freeram

decompiled_code:
// attributes: thunk
void __fastcall freeram(void *ptr)
{
free_pinger(ptr);
}

canonical_decompiled_code:
void __fastcall func24(void *ptr)
{
func16(ptr);
}

original_code:
void freeram(emu_device* ram)
{
  free(ram->mem);
  free(ram);
}

canonical_original_code:
void freeram(struct emu_device *ram)
{
  free(ram->mem);
  free(ram);
}

variable_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *


makeram

decompiled_code:
_DWORD *makeram()
{
_DWORD *v0; // r12
void *v1; // rax
_DWORD *result; // rax

v0 = malloc(0x40uLL);
v1 = malloc(0x80uLL);
v0[2] = 128;
*((_QWORD *)v0 + 2) = v1;
result = v0;
*((_QWORD *)v0 + 3) = 0LL;
*((_QWORD *)v0 + 4) = 0LL;
*((_QWORD *)v0 + 5) = ram_dc_cb;
*((_QWORD *)v0 + 6) = 0LL;
return result;
}

canonical_decompiled_code:
_DWORD *func25()
{
_DWORD *v0; // r12
void *v1; // rax
_DWORD *result; // rax

v0 = malloc(0x40uLL);
v1 = malloc(0x80uLL);
v0[2] = 128;
*((_QWORD *)v0 + 2) = v1;
result = v0;
*((_QWORD *)v0 + 3) = 0LL;
*((_QWORD *)v0 + 4) = 0LL;
*((_QWORD *)v0 + 5) = ram_dc_cb;
*((_QWORD *)v0 + 6) = 0LL;
return result;
}

original_code:
emu_device* makeram()
{
  emu_device* ram = (emu_device*)malloc(sizeof(emu_device));
  ram->mem = (uint8_t*)malloc(128);
  ram->memsize = 128;
  ram->irq_cb = ((void *)0);
  ram->cc_cb = ((void *)0);
  ram->dc_cb = ram_dc_cb;
  ram->data = ((void *)0);
  return ram;
}

canonical_original_code:
struct emu_device *makeram()
{
  struct emu_device *ram = (emu_device*)malloc(sizeof(emu_device));
  ram->mem = (unsigned char *)malloc(128);
  ram->memsize = 128;
  ram->irq_cb = ((void *)0);
  ram->cc_cb = ((void *)0);
  ram->dc_cb = ram_dc_cb;
  ram->data = ((void *)0);
  return ram;
}

return_type: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; } *


memorytest

decompiled_code:
void memorytest()
{
void *v0; // rbp
_BYTE *v1; // r12
_DWORD *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v0 = emub_create();
v1 = malloc(0x80uLL);
v2 = makeram();
emub_connect((__int64)v0, (__int64)v2, 0);
v3 = emub_write((__int64)v0, 0, 9, "uberblah");
printf("should be 9: %d\n", v3);
v4 = emub_write((__int64)v0, 8u, 9, "uberblah");
printf("should be 9: %d\n", v4);
v5 = emub_write((__int64)v0, 0x10u, 9, "uberblah");
printf("should be 9: %d\n", v5);
v6 = emub_read((__int64)v0, 0, 28, v1);
printf("should be 28: %d\n", v6);
printf("should be 'uberblahuberblahuberblah': %s\n", v1);
v7 = emub_write((__int64)v0, 0x7Cu, 9, "uberblah");
printf("should be 4: %d\n", v7);
v8 = emub_read((__int64)v0, 0x7Cu, 9, v1 + 4);
printf("should be 4: %d\n", v8);
printf("should be uberuberuberblahuberblah: %s\n", v1);
emub_free(v0);
free(v1);
}

canonical_decompiled_code:
void func26()
{
void *v0; // rbp
_BYTE *v1; // r12
_DWORD *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v0 = func7();
v1 = malloc(0x80uLL);
v2 = func25();
emub_connect((__int64)v0, (__int64)v2, 0);
v3 = func13((__int64)v0, 0, 9, "uberblah");
printf("should be 9: %d\n", v3);
v4 = func13((__int64)v0, 8u, 9, "uberblah");
printf("should be 9: %d\n", v4);
v5 = func13((__int64)v0, 0x10u, 9, "uberblah");
printf("should be 9: %d\n", v5);
v6 = func12((__int64)v0, 0, 28, v1);
printf("should be 28: %d\n", v6);
printf("should be 'uberblahuberblahuberblah': %s\n", v1);
v7 = func13((__int64)v0, 0x7Cu, 9, "uberblah");
printf("should be 4: %d\n", v7);
v8 = func12((__int64)v0, 0x7Cu, 9, v1 + 4);
printf("should be 4: %d\n", v8);
printf("should be uberuberuberblahuberblah: %s\n", v1);
func9(v0);
free(v1);
}

original_code:
void memorytest()
{
  emu_board* b = emub_create();
  const char* string = "uberblah";
  char* iobuffer = (char*)malloc(128);
  emu_device* ram = makeram();
  emub_connect(b, ram, 0);
  printf("should be 9: %d\n", emub_write(b, 0x000000, 9, (void*)string));
  printf("should be 9: %d\n", emub_write(b, 0x000008, 9, (void*)string));
  printf("should be 9: %d\n", emub_write(b, 0x000010, 9, (void*)string));
  printf("should be 28: %d\n", emub_read(b, 0x000000, 28, (void*)iobuffer));
  printf("should be 'uberblahuberblahuberblah': %s\n", iobuffer);
  printf("should be 4: %d\n", emub_write(b, 124, 9, (void*)string));
  printf("should be 4: %d\n", emub_read(b, 124, 9, (void*)(iobuffer + 4)));
  printf("should be uberuberuberblahuberblah: %s\n", iobuffer);
  emub_free(b);
  free(iobuffer);
}

canonical_original_code:
void memorytest()
{
  struct emu_device *(*b)[256] = emub_create();
  char *string = "uberblah";
  char *iobuffer = (char*)malloc(128);
  struct emu_device *ram = makeram();
  emub_connect(b, ram, 0);
  printf("should be 9: %d\n", emub_write(b, 0x000000, 9, (void *)string));
  printf("should be 9: %d\n", emub_write(b, 0x000008, 9, (void *)string));
  printf("should be 9: %d\n", emub_write(b, 0x000010, 9, (void *)string));
  printf("should be 28: %d\n", emub_read(b, 0x000000, 28, (void *)iobuffer));
  printf("should be 'uberblahuberblahuberblah': %s\n", iobuffer);
  printf("should be 4: %d\n", emub_write(b, 124, 9, (void *)string));
  printf("should be 4: %d\n", emub_read(b, 124, 9, (void *)(iobuffer + 4)));
  printf("should be uberuberuberblahuberblah: %s\n", iobuffer);
  emub_free(b);
  free(iobuffer);
}

variable_types:
string
char *

variable_types:
iobuffer
char *

user_defined_types: struct emu_device { struct emu_device *(*board)[256]; unsigned int memsize; void *mem; void (*irq_cb)(struct emu_device *dev, unsigned int code); void (*cc_cb)(struct emu_device *dev); void (*dc_cb)(struct emu_device *dev); void *data; unsigned char id; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
devicetest(argc, argv, envp);
memorytest();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func23(argc, argv, envp);
func26();
exit(0);
}

original_code:
int main(int argc, char** argv)
{
  devicetest();
  memorytest();
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  devicetest();
  memorytest();
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


repo: uffejakobsen/sysvbanner

original_code:
int main(int argc, char **argv)
{
  int a, b, c, len, ind;
  char line[80];
  for (argv++; --argc; argv++) {
    len = strlen(*argv);
    if (len > 10)
      len = 10;
    for (a = 0; a < 7; a++) {
      for (b = 0; b < len; b++) {
 if ((ind = (*argv)[b] - ' ') < 0)
   ind = 0;
 for (c = 0; c < 7; c++) {
   line[b * 8 + c] = glyphs[(ind / 8 * 7) + a][(ind % 8 * 7) + c];
 }
 line[b * 8 + 7] = ' ';
      }
      for (b = len * 8 - 1; b >= 0; b--) {
 if (line[b] != ' ')
   break;
 line[b] = '\0';
      }
      puts(line);
    }
    puts("");
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int a; int b; int c; int len; int ind;
  char line[80];
  for (argv++; --argc; argv++) {
    len = strlen(*argv);
    if (len > 10)
      len = 10;
    for (a = 0; a < 7; a++) {
      for (b = 0; b < len; b++) {
 if ((ind = (*argv)[b] - ' ') < 0)
   ind = 0;
 for (c = 0; c < 7; c++) {
   line[b * 8 + c] = glyphs[(ind / 8 * 7) + a][(ind % 8 * 7) + c];
 }
 line[b * 8 + 7] = ' ';
      }
      for (b = len * 8 - 1; b >= 0; b--) {
 if (line[b] != ' ')
   break;
 line[b] = '\0';
      }
      puts(line);
    }
    puts("");
  }
  return 0;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: len int

variable_types: ind int

variable_types:
line
char [80]


decompiled_code:
int imprime_mensagem()
{
return puts(s);
}

canonical_decompiled_code:
int func7()
{
return puts(s);
}

original_code:
void imprime_mensagem(){
   printf("Não sei, só sei que foi assim.\n");
}


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

if ( NUMERO_DE_ITERACOES <= 0 )
return 0;
v3 = 0;
do
{
++v3;
imprime_mensagem(argc, argv, envp);
}
while ( NUMERO_DE_ITERACOES > v3 );
return 0;
}

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

if ( NUMERO_DE_ITERACOES <= 0 )
return 0;
v3 = 0;
do
{
++v3;
func7(argc, argv, envp);
}
while ( NUMERO_DE_ITERACOES > v3 );
return 0;
}

original_code:
int main() {
  for (int i=0; i < NUMERO_DE_ITERACOES; i++ ){
    imprime_mensagem();
  }
  return 0;
}

canonical_original_code:
int main() {
  for (int i = 0; i < NUMERO_DE_ITERACOES; i++ ){
    imprime_mensagem();
  }
  return 0;
}


imprimeRecordistas

decompiled_code:
int __fastcall imprimeRecordistas(__int64 a1)
{
int result; // eax
const char *v2; // rbx
int v3; // ebp
__int64 v4; // rdx
const char *v5; // rsi

puts(s);
result = QUANTIDADE_DA_LISTA;
if ( QUANTIDADE_DA_LISTA > 0 )
{
v2 = (const char *)(a1 + 4);
v3 = 0;
do
{
v4 = *((unsigned int *)v2 - 1);
v5 = v2;
++v3;
v2 += 36;
result = printf("%s %d\n", v5, v4);
}
while ( QUANTIDADE_DA_LISTA > v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int result; // eax
const char *v2; // rbx
int v3; // ebp
__int64 v4; // rdx
const char *v5; // rsi

puts(s);
result = QUANTIDADE_DA_LISTA;
if ( QUANTIDADE_DA_LISTA > 0 )
{
v2 = (const char *)(a1 + 4);
v3 = 0;
do
{
v4 = *((unsigned int *)v2 - 1);
v5 = v2;
++v3;
v2 += 36;
result = printf("%s %d\n", v5, v4);
}
while ( QUANTIDADE_DA_LISTA > v3 );
}
return result;
}

original_code:
void imprimeRecordistas(Jogador* jogadores){
    printf("Os seguintes valores foram lidos do arquivo binário:\n");
    for(int i=0; i<QUANTIDADE_DA_LISTA; i++){
        printf("%s %d\n", jogadores[i].nome, jogadores[i].pontuacao);
    }
}

canonical_original_code:
void imprimeRecordistas(struct Jogador_ *jogadores){
    printf("Os seguintes valores foram lidos do arquivo binário:\n");
    for(int i = 0; i<QUANTIDADE_DA_LISTA; i++){
        printf("%s %d\n", jogadores[i].nome, jogadores[i].pontuacao);
    }
}

variable_types: struct Jogador_ { int pontuacao; char nome[32]; } *


main

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

criaArquivoDeRecordistasIniciais(argc, argv, envp);
v3 = lerArquivoDeRecordistas();
imprimeRecordistas(v3);
return 0;
}

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

func7(argc, argv, envp);
v3 = func8();
func9(v3);
return 0;
}

original_code:
int main(void) {
    criaArquivoDeRecordistasIniciais();
    Jogador* recordistas = lerArquivoDeRecordistas();
    imprimeRecordistas(recordistas);
}

canonical_original_code:
int main() {
    criaArquivoDeRecordistasIniciais();
    struct Jogador_ *recordistas = lerArquivoDeRecordistas();
    imprimeRecordistas(recordistas);
}

user_defined_types: struct Jogador_ { int pontuacao; char nome[32]; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
int *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi
__int64 v7; // rsi
unsigned int *v8; // rbx
unsigned int *v9; // rbp
__int64 v10; // rsi
int v12[8]; // [rsp+0h] [rbp-58h] BYREF
_DWORD v13[8]; // [rsp+20h] [rbp-38h] BYREF
char v14; // [rsp+40h] [rbp-18h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v12[i] = i;
v13[i] = i + 1;
}
v4 = v12;
v5 = soma_vet(v12, v13);
do
{
v6 = (unsigned int)*v4++;
printf("%d\t", v6);
}
while ( v4 != v13 );
putchar(10);
do
{
v7 = (unsigned int)*v4++;
printf("%d\t", v7);
}
while ( &v14 != (char *)v4 );
v8 = (unsigned int *)v5;
v9 = (unsigned int *)(v5 + 32);
putchar(10);
do
{
v10 = *v8++;
printf("%d\t", v10);
}
while ( v8 != v9 );
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
int *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi
__int64 v7; // rsi
unsigned int *v8; // rbx
unsigned int *v9; // rbp
__int64 v10; // rsi
int v12[8]; // [rsp+0h] [rbp-58h] BYREF
_DWORD v13[8]; // [rsp+20h] [rbp-38h] BYREF
char v14; // [rsp+40h] [rbp-18h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v12[i] = i;
v13[i] = i + 1;
}
v4 = v12;
v5 = func7(v12, v13);
do
{
v6 = (unsigned int)*v4++;
printf("%d\t", v6);
}
while ( v4 != v13 );
putchar(10);
do
{
v7 = (unsigned int)*v4++;
printf("%d\t", v7);
}
while ( &v14 != (char *)v4 );
v8 = (unsigned int *)v5;
v9 = (unsigned int *)(v5 + 32);
putchar(10);
do
{
v10 = *v8++;
printf("%d\t", v10);
}
while ( v8 != v9 );
putchar(10);
return 0;
}

canonical_original_code:
int main() {
  int i; int *ptr1;
  int va[8]; int vb[8];
  for(i=0; i<8; i++) {
    va[i]=i;
    vb[i]=i+1;
  }
  ptr1=soma_vet(va, vb);
  for(i=0; i<8; i++) {
    printf("%d\t", va[i]);
  }
  printf("\n");
  for(i=0; i<8; i++) {
    printf("%d\t", vb[i]);
  }
  printf("\n");
  for(i=0; i<8; i++) {
    printf("%d\t", ptr1[i]);
  }
  printf("\n");
  return 0;
}

variable_types:
va
int [8]

variable_types:
vb
int [8]


decompiled_code:
_QWORD *dynamic_string_init()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x18uLL);
v0[2] = 1024LL;
v1 = v0;
v0[1] = 0LL;
*v0 = malloc(0x400uLL);
return v1;
}

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

v0 = malloc(0x18uLL);
v0[2] = 1024LL;
v1 = v0;
v0[1] = 0LL;
*v0 = malloc(0x400uLL);
return v1;
}

original_code:
dynamic_string *dynamic_string_init() {
 dynamic_string *str = (dynamic_string *)malloc(sizeof(dynamic_string));
 str->alloc_size = 1024;
 str->size = 0;
 str->str = (char*)malloc(sizeof(char)*str->alloc_size);
 return str;
}

canonical_original_code:
struct dynamic_string *dynamic_string_init() {
 struct dynamic_string *str = (dynamic_string *)malloc(sizeof(dynamic_string));
 str->alloc_size = 1024;
 str->size = 0;
 str->str = (char *)malloc(sizeof(char)*str->alloc_size);
 return str;
}

variable_types: struct dynamic_string { char *str; unsigned long size; unsigned long alloc_size; } *


decompiled_code:
void __fastcall dynamic_string_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void dynamic_string_free(dynamic_string *str) {
 free(str->str);
 free(str);
}

canonical_original_code:
void dynamic_string_free(struct dynamic_string *str) {
 free(str->str);
 free(str);
}

user_defined_types: struct dynamic_string { char *str; unsigned long size; unsigned long alloc_size; }


decompiled_code:
void *__fastcall dynamic_string_append(char **a1, const void *a2, size_t a3)
{
char *v5; // rax
unsigned __int64 v7; // rsi
char *i; // rdi
char *v9; // rax
void *result; // rax

v5 = a1[1];
v7 = (unsigned __int64)a1[2];
for ( i = *a1; v7 < (unsigned __int64)&v5[a3]; a1[2] = (char *)v7 )
{
v9 = (char *)realloc(i, 2 * v7);
*a1 = v9;
i = v9;
v7 = 2LL * (_QWORD)a1[2];
v5 = a1[1];
}
result = memcpy(&i[(_QWORD)v5], a2, a3);
a1[1] += a3;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(char **a1, const void *a2, size_t a3)
{
char *v5; // rax
unsigned __int64 v7; // rsi
char *i; // rdi
char *v9; // rax
void *result; // rax

v5 = a1[1];
v7 = (unsigned __int64)a1[2];
for ( i = *a1; v7 < (unsigned __int64)&v5[a3]; a1[2] = (char *)v7 )
{
v9 = (char *)realloc(i, 2 * v7);
*a1 = v9;
i = v9;
v7 = 2LL * (_QWORD)a1[2];
v5 = a1[1];
}
result = memcpy(&i[(_QWORD)v5], a2, a3);
a1[1] += a3;
return result;
}

original_code:
void dynamic_string_append(dynamic_string *str, const char *append, size_t size) {
 while(str->size + size > str->alloc_size) {
  str->str = (char *)realloc((void *)str->str, str->alloc_size*2);
  str->alloc_size *= 2;
 }
 memcpy(((void*)str->str) + str->size, (void *)append, size);
 str->size += size;
}

canonical_original_code:
void dynamic_string_append(struct dynamic_string *str, char *append, unsigned long size) {
 while(str->size + size > str->alloc_size) {
  str->str = (char *)realloc((void *)str->str, str->alloc_size*2);
  str->alloc_size *= 2;
 }
 memcpy(((void *)str->str) + str->size, (void *)append, size);
 str->size += size;
}

variable_types:
append
char *

variable_types:
size
unsigned long


decompiled_code:
void __fastcall dynamic_string_join(char **a1, __int64 a2)
{
dynamic_string_append(a1, *(const void **)a2, *(_QWORD *)(a2 + 8));
dynamic_string_free((void *)a2);
}

canonical_decompiled_code:
void __fastcall func3(char **a1, __int64 a2)
{
func2(a1, *(const void **)a2, *(_QWORD *)(a2 + 8));
func1((void *)a2);
}

original_code:
void dynamic_string_join(dynamic_string *joinee, dynamic_string *joiner) {
 dynamic_string_append(joinee, joiner->str, joiner->size);
 dynamic_string_free(joiner);
}

canonical_original_code:
void dynamic_string_join(struct dynamic_string *joinee, struct dynamic_string *joiner) {
 dynamic_string_append(joinee, joiner->str, joiner->size);
 dynamic_string_free(joiner);
}

variable_types:
joiner
struct dynamic_string *


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

a1[1] = 0LL;
result = 1LL;
*a1 = 0LL;
return result;
}

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

a1[1] = 0LL;
result = 1LL;
*a1 = 0LL;
return result;
}

original_code:
char ini_linkedQueue(linked_queue* queue){
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

canonical_original_code:
char ini_linkedQueue(struct linked_queue *queue){
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

variable_types: struct linked_queue { struct queueNode { void *m_data; struct queueNode *m_next; } *m_front; struct queueNode *m_rear; } *

return_type: char

user_defined_types: struct linked_queue { struct queueNode *m_front; struct queueNode *m_rear; }


decompiled_code:
__int64 __fastcall destroy_linkedQueue(__int64 a1)
{
void **i; // rbp
void *v3; // rdi
__int64 result; // rax

for ( i = *(void ***)a1; *(_QWORD *)a1; i = *(void ***)a1 )
{
v3 = *i;
*(_QWORD *)a1 = i[1];
if ( v3 )
free(v3);
free(i);
}
*(_QWORD *)(a1 + 8) = 0LL;
result = 1LL;
*(_QWORD *)a1 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
void **i; // rbp
void *v3; // rdi
__int64 result; // rax

for ( i = *(void ***)a1; *(_QWORD *)a1; i = *(void ***)a1 )
{
v3 = *i;
*(_QWORD *)a1 = i[1];
if ( v3 )
free(v3);
free(i);
}
*(_QWORD *)(a1 + 8) = 0LL;
result = 1LL;
*(_QWORD *)a1 = 0LL;
return result;
}

original_code:
char destroy_linkedQueue(linked_queue* queue){
  queueNode* node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    if(node->m_data) free(node->m_data);
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

canonical_original_code:
char destroy_linkedQueue(struct linked_queue *queue){
  struct queueNode *node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    if(node->m_data) free(node->m_data);
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

variable_types: struct queueNode { void *m_data; struct queueNode *m_next; } *


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

v2 = *(_QWORD **)a1;
if ( v2 )
{
do
{
*(_QWORD *)a1 = v2[1];
free(v2);
v2 = *(_QWORD **)a1;
}
while ( *(_QWORD *)a1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
result = 1LL;
*(_QWORD *)a1 = 0LL;
return result;
}

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

v2 = *(_QWORD **)a1;
if ( v2 )
{
do
{
*(_QWORD *)a1 = v2[1];
free(v2);
v2 = *(_QWORD **)a1;
}
while ( *(_QWORD *)a1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
result = 1LL;
*(_QWORD *)a1 = 0LL;
return result;
}

original_code:
char clear_linkedQueue(linked_queue * queue){
  queueNode* node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

canonical_original_code:
char clear_linkedQueue(struct linked_queue *queue){
  struct queueNode *node = ((void *)0);
  while(queue->m_front != ((void *)0)){
    node = queue->m_front;
    queue->m_front = node->m_next;
    free(node);
  }
  queue->m_front = queue->m_rear = ((void *)0);
  return 1;
}

user_defined_types: struct queueNode { void *m_data; struct queueNode *m_next; }


decompiled_code:
__int64 __fastcall getHead_linkedQueue(_QWORD **a1, _QWORD *a2)
{
if ( !*a1 )
return 0LL;
*a2 = **a1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1, _QWORD *a2)
{
if ( !*a1 )
return 0LL;
*a2 = **a1;
return 1LL;
}

original_code:
char getHead_linkedQueue(linked_queue* queue,void** data){
  if(queue->m_front == ((void *)0)) return 0;
  *data = queue->m_front->m_data;
  return 1;
}

canonical_original_code:
char getHead_linkedQueue(struct linked_queue *queue, void **data){
  if(queue->m_front == ((void *)0)) return 0;
  *data = queue->m_front->m_data;
  return 1;
}

variable_types:
data
void **


decompiled_code:
__int64 __fastcall length_linkedQueue(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

original_code:
unsigned int length_linkedQueue(linked_queue* queue){
  unsigned int len = 0;
  queueNode* node = queue->m_front;
  while(node){
    node = node->m_next; ++len;
  }
  return len;
}

canonical_original_code:
unsigned int length_linkedQueue(struct linked_queue *queue){
  unsigned int len = 0;
  struct queueNode *node = queue->m_front;
  while(node){
    node = node->m_next; ++len;
  }
  return len;
}

variable_types:
len
unsigned int

return_type: unsigned int


decompiled_code:
bool __fastcall empty_linkedQueue(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
bool __fastcall func12(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
char empty_linkedQueue(linked_queue * queue){
  if(queue->m_front == ((void *)0)) return 1;
  return 0;
}

canonical_original_code:
char empty_linkedQueue(struct linked_queue *queue){
  if(queue->m_front == ((void *)0)) return 1;
  return 0;
}


decompiled_code:
__int64 __fastcall deQueue_linkedQueue(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // r8
__int64 v3; // rax

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
*a2 = *v2;
v3 = v2[1];
*(_QWORD *)a1 = v3;
if ( !v3 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v2);
return 1LL;
}

original_code:
char deQueue_linkedQueue(linked_queue* queue,void** data){
  if(queue->m_front == ((void *)0)) return 0;
  queueNode* node = queue->m_front;
  *data = node->m_data;
  queue->m_front = node->m_next;
  if(queue->m_front == ((void *)0)) queue->m_rear = ((void *)0);
  free(node);
  return 1;
}

canonical_original_code:
char deQueue_linkedQueue(struct linked_queue *queue, void **data){
  if(queue->m_front == ((void *)0)) return 0;
  struct queueNode *node = queue->m_front;
  *data = node->m_data;
  queue->m_front = node->m_next;
  if(queue->m_front == ((void *)0)) queue->m_rear = ((void *)0);
  free(node);
  return 1;
}


original_code:
char enQueue_linkedQueue(linked_queue* queue,void* data){
  queueNode* node = (queueNode*)malloc(sizeof(queueNode));
  if(node == ((void *)0)) return -2;
  node->m_data = data; node->m_next = ((void *)0);
  if(queue->m_front == ((void *)0)){
    queue->m_front = queue->m_rear = node;
    return 1;
  }
  queue->m_rear->m_next = node;
  queue->m_rear = node;
  return 1;
}

canonical_original_code:
char enQueue_linkedQueue(struct linked_queue *queue, void *data){
  struct queueNode *node = (queueNode*)malloc(sizeof(queueNode));
  if(node == ((void *)0)) return -2;
  node->m_data = data; node->m_next = ((void *)0);
  if(queue->m_front == ((void *)0)){
    queue->m_front = queue->m_rear = node;
    return 1;
  }
  queue->m_rear->m_next = node;
  queue->m_rear = node;
  return 1;
}

variable_types:
data
void *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_DWORD *v4; // rax
int v5; // ebx
unsigned int *v7; // [rsp+8h] [rbp-20h] BYREF
char v8[24]; // [rsp+10h] [rbp-18h] BYREF

v3 = 0;
ini_linkedQueue(v8, argv, envp);
do
{
v4 = malloc(4uLL);
*v4 = v3++;
enQueue_linkedQueue(v8, v4);
}
while ( v3 != 100 );
v5 = 110;
getHead_linkedQueue(v8, &v7);
printf("%d\n", *v7);
do
{
deQueue_linkedQueue(v8, &v7);
printf("%d\t", *v7);
--v5;
}
while ( v5 );
putchar(10);
destroy_linkedQueue(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_DWORD *v4; // rax
int v5; // ebx
unsigned int *v7; // [rsp+8h] [rbp-20h] BYREF
char v8[24]; // [rsp+10h] [rbp-18h] BYREF

v3 = 0;
func7(v8, argv, envp);
do
{
v4 = malloc(4uLL);
*v4 = v3++;
func14(v8, v4);
}
while ( v3 != 100 );
v5 = 110;
func10(v8, &v7);
printf("%d\n", *v7);
do
{
func13(v8, &v7);
printf("%d\t", *v7);
--v5;
}
while ( v5 );
putchar(10);
func8(v8);
return 0;
}

original_code:
int main(){
  linked_queue queue;
  ini_linkedQueue(&queue);
  int i = 0;
  for(i = 0;i < 100;i++){
    int * data = (int *) malloc(sizeof(int));
    *data = i;
    enQueue_linkedQueue(&queue,(void *)data);
  }
  int * data;
  getHead_linkedQueue(&queue,(void **)&data);
  printf("%d\n",*data);
  for(i = 0;i < 110;i++){
    deQueue_linkedQueue(&queue,(void **)&data);
    printf("%d\t",*data);
  }
  printf("\n");
  destroy_linkedQueue(&queue);
  return 0;
}

canonical_original_code:
int main(){
  struct linked_queue queue;
  ini_linkedQueue(&queue);
  int i = 0;
  for(i = 0;i < 100;i++){
    int *data = (int *) malloc(sizeof(int));
    *data = i;
    enQueue_linkedQueue(&queue,(void *)data);
  }
  int *data;
  getHead_linkedQueue(&queue,(void **)&data);
  printf("%d\n",*data);
  for(i = 0;i < 110;i++){
    deQueue_linkedQueue(&queue,(void **)&data);
    printf("%d\t",*data);
  }
  printf("\n");
  destroy_linkedQueue(&queue);
  return 0;
}

variable_types: struct linked_queue { struct queueNode { void *m_data; struct queueNode *m_next; } *m_front; struct queueNode *m_rear; }

variable_types: i int

variable_types:
data
int *


decompiled_code:
void __fastcall destroy_seqList(_QWORD *a1)
{
void *v2; // rdi

v2 = (void *)a1[1];
if ( v2 )
{
free(v2);
*a1 = 0LL;
a1[1] = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func7(_QWORD *a1)
{
void *v2; // rdi

v2 = (void *)a1[1];
if ( v2 )
{
free(v2);
*a1 = 0LL;
a1[1] = 0LL;
}
}

original_code:
char destroy_seqList(seq_list* list){
  if(list->m_pList == ((void *)0)) return 0;
  free(list->m_pList); list->m_pList = ((void *)0);
  list->m_listSize = list->m_maxListSize = 0;
}

canonical_original_code:
char destroy_seqList(struct seq_list *list){
  if(list->m_pList == ((void *)0)) return 0;
  free(list->m_pList); list->m_pList = ((void *)0);
  list->m_listSize = list->m_maxListSize = 0;
}

variable_types: struct seq_list { int m_listSize; int m_maxListSize; int *m_pList; } *


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

v1 = malloc(0x190uLL);
a1[1] = v1;
if ( v1 )
{
*a1 = 0x6400000000LL;
result = 1LL;
}
else
{
*a1 = 0LL;
result = 4294967294LL;
}
return result;
}

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

v1 = malloc(0x190uLL);
a1[1] = v1;
if ( v1 )
{
*a1 = 0x6400000000LL;
result = 1LL;
}
else
{
*a1 = 0LL;
result = 4294967294LL;
}
return result;
}

original_code:
char ini_seqList(seq_list* list){
  list->m_pList=(int *)malloc(sizeof(int) * 100);
  if(list->m_pList == ((void *)0)){
    list->m_listSize = list->m_maxListSize = 0;
    return -2;
  }
  list->m_listSize = 0;list->m_maxListSize = 100;
  return 1;
}

canonical_original_code:
char ini_seqList(struct seq_list *list){
  list->m_pList=(int *)malloc(sizeof(int) * 100);
  if(list->m_pList == ((void *)0)){
    list->m_listSize = list->m_maxListSize = 0;
    return -2;
  }
  list->m_listSize = 0;list->m_maxListSize = 100;
  return 1;
}

user_defined_types: struct seq_list { int m_listSize; int m_maxListSize; int *m_pList; }


original_code:
char ins_seqList(seq_list* list,const int i,const int ele){
  if(i < 0||i > (list->m_listSize))
  return 0;
  if(list->m_listSize >= list->m_maxListSize){
    int * pEle = (int*) realloc(list->m_pList,(list->m_maxListSize + 100)
    * sizeof(int));
    if(!pEle){
        return -2;
    }
    list->m_pList = pEle;
    list->m_maxListSize += 100;
  }
  int j;
  for(j = list->m_listSize;j > i;j--){
    list->m_pList[j] = list->m_pList[j-1];
  }
  list->m_pList[j]=ele;
  list->m_listSize++;
  return 1;
}

canonical_original_code:
char ins_seqList(struct seq_list *list, int i, int ele){
  if(i < 0||i > (list->m_listSize))
  return 0;
  if(list->m_listSize >= list->m_maxListSize){
    int *pEle = (int*) realloc(list->m_pList,(list->m_maxListSize + 100)
    * sizeof(int));
    if(!pEle){
        return -2;
    }
    list->m_pList = pEle;
    list->m_maxListSize += 100;
  }
  int j;
  for(j = list->m_listSize;j > i;j--){
    list->m_pList[j] = list->m_pList[j-1];
  }
  list->m_pList[j]=ele;
  list->m_listSize++;
  return 1;
}

variable_types: ele int

variable_types:
pEle
int *

variable_types: j int


decompiled_code:
__int64 __fastcall insBack_seqList(int *a1, int a2)
{
return ins_seqList(a1, *a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, int a2)
{
return func9(a1, *a1, a2);
}

original_code:
char insBack_seqList(seq_list* list,const int ele){
  return ins_seqList(list,list->m_listSize,ele);
}

canonical_original_code:
char insBack_seqList(struct seq_list *list, int ele){
  return ins_seqList(list,list->m_listSize,ele);
}


original_code:
char del_seqList(seq_list* list,const int i,int* ele){
  if(i < 0 || i >= list->m_listSize) return 0;
  int j=0;
  for(j = i;j < list->m_listSize;j++){
    *ele = list->m_pList[j];
    list->m_pList[j]=list->m_pList[j+1];
  }
  list->m_listSize--;
  return 1;
}

canonical_original_code:
char del_seqList(struct seq_list *list, int i, int *ele){
  if(i < 0 || i >= list->m_listSize) return 0;
  int j = 0;
  for(j = i;j < list->m_listSize;j++){
    *ele = list->m_pList[j];
    list->m_pList[j]=list->m_pList[j+1];
  }
  list->m_listSize--;
  return 1;
}

variable_types:
ele
int *


decompiled_code:
__int64 __fastcall delBack_seqList(unsigned int *a1, _DWORD *a2)
{
return del_seqList((__int64)a1, *a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, _DWORD *a2)
{
return func11((__int64)a1, *a1, a2);
}

original_code:
char delBack_seqList(seq_list* list,int* ele){
  return del_seqList(list,list->m_listSize,ele);
}

canonical_original_code:
char delBack_seqList(struct seq_list *list, int *ele){
  return del_seqList(list,list->m_listSize,ele);
}


decompiled_code:
__int64 __fastcall getEle_seqList(__int64 a1, int a2, _DWORD *a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)a1 > a2 )
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2, _DWORD *a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 >= 0 && *(_DWORD *)a1 > a2 )
{
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * a2);
result = 1LL;
}
return result;
}

original_code:
char getEle_seqList(const seq_list* list,const int i,int *ele){
  if(i < 0|| i >= list->m_listSize) return 0;
  *ele = list->m_pList[i];
  return 1;
}

canonical_original_code:
char getEle_seqList(struct seq_list *list, int i, int *ele){
  if(i < 0|| i >= list->m_listSize) return 0;
  *ele = list->m_pList[i];
  return 1;
}


decompiled_code:
__int64 __fastcall getBackEle_seqList(_DWORD *a1, _DWORD *a2)
{
return getEle_seqList((__int64)a1, *a1 - 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, _DWORD *a2)
{
return func13((__int64)a1, *a1 - 1, a2);
}

original_code:
char getBackEle_seqList(const seq_list* list,int *ele){
  return getEle_seqList(list,list->m_listSize-1,ele);
}

canonical_original_code:
char getBackEle_seqList(struct seq_list *list, int *ele){
  return getEle_seqList(list,list->m_listSize-1,ele);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int i; // ebx
unsigned int v5; // ebx
__int64 v6; // rsi
unsigned int v8; // [rsp+Ch] [rbp-1Ch] BYREF
char v9[24]; // [rsp+10h] [rbp-18h] BYREF

v3 = 0;
ini_seqList(v9, argv, envp);
do
{
if ( (unsigned __int8)ins_seqList(v9, v3, v3) != 1 )
LABEL_4:
exit(0);
++v3;
}
while ( v3 != 105 );
for ( i = 0; i != 105; ++i )
{
if ( (unsigned __int8)insBack_seqList(v9, i) != 1 )
goto LABEL_4;
}
v5 = 0;
del_seqList(v9, 20LL, &v8);
ins_seqList(v9, 12LL, 50LL);
do
{
v6 = v5++;
getEle_seqList(v9, v6, &v8);
printf("%d ", v8);
}
while ( v5 != 211 );
destroy_seqList(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int i; // ebx
unsigned int v5; // ebx
__int64 v6; // rsi
unsigned int v8; // [rsp+Ch] [rbp-1Ch] BYREF
char v9[24]; // [rsp+10h] [rbp-18h] BYREF

v3 = 0;
func8(v9, argv, envp);
do
{
if ( (unsigned __int8)func9(v9, v3, v3) != 1 )
LABEL_4:
exit(0);
++v3;
}
while ( v3 != 105 );
for ( i = 0; i != 105; ++i )
{
if ( (unsigned __int8)func10(v9, i) != 1 )
goto LABEL_4;
}
v5 = 0;
func11(v9, 20LL, &v8);
func9(v9, 12LL, 50LL);
do
{
v6 = v5++;
func13(v9, v6, &v8);
printf("%d ", v8);
}
while ( v5 != 211 );
func7(v9);
return 0;
}

original_code:
int main(){
  seq_list list;
  ini_seqList(&list);
  int i;
  for(i = 0;i < 105;i++){
    if(ins_seqList(&list,i,i) != 1){
        exit(0);
    }
  }
  for(i = 0;i < 105;i++){
    if(insBack_seqList(&list,i) != 1){
        exit(0);
    }
  }
  int ele;
  del_seqList(&list,20,&ele);
  ins_seqList(&list,12,50);
  for(i=0;i<211;i++){
    getEle_seqList(&list,i,&ele);
    printf("%d ",ele);
  }
  destroy_seqList(&list);
  return 0;
}

canonical_original_code:
int main(){
  struct seq_list list;
  ini_seqList(&list);
  int i;
  for(i = 0;i < 105;i++){
    if(ins_seqList(&list,i,i) != 1){
        exit(0);
    }
  }
  for(i = 0;i < 105;i++){
    if(insBack_seqList(&list,i) != 1){
        exit(0);
    }
  }
  int ele;
  del_seqList(&list,20,&ele);
  ins_seqList(&list,12,50);
  for(i=0;i<211;i++){
    getEle_seqList(&list,i,&ele);
    printf("%d ",ele);
  }
  destroy_seqList(&list);
  return 0;
}

variable_types: struct seq_list { int m_listSize; int m_maxListSize; int *m_pList; }


decompiled_code:
__int64 __fastcall ini_seqQueue(__int64 a1)
{
void *v1; // rax
__int64 result; // rax

v1 = malloc(0x320uLL);
if ( !v1 )
return 4294967294LL;
*(_QWORD *)a1 = v1;
result = 1LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 100;
return result;
}

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

v1 = malloc(0x320uLL);
if ( !v1 )
return 4294967294LL;
*(_QWORD *)a1 = v1;
result = 1LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 100;
return result;
}

original_code:
char ini_seqQueue(seqQueue* queue){
  void ** p = (void **) malloc(sizeof(void *) * 100);
  if(p == ((void *)0)) return -2;
  queue->m_base = p; queue->m_maxSize = 100;
  queue->m_front = queue->m_rear = 0;
  return 1;
}

canonical_original_code:
char ini_seqQueue(struct seqQueue *queue){
  void **p = (void **) malloc(sizeof(void *) * 100);
  if(p == ((void *)0)) return -2;
  queue->m_base = p; queue->m_maxSize = 100;
  queue->m_front = queue->m_rear = 0;
  return 1;
}

variable_types: struct seqQueue { void **m_base; unsigned int m_front; unsigned int m_rear; unsigned int m_maxSize; } *

variable_types:
p
void **


decompiled_code:
__int64 __fastcall destroy_seqQueue(__int64 a1)
{
_QWORD *v1; // r8
unsigned int i; // edx
void *v4; // rdi
__int64 result; // rax

v1 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
for ( i = *(_DWORD *)(a1 + 8); i != *(_DWORD *)(a1 + 12); *(_DWORD *)(a1 + 8) = i )
{
v4 = (void *)v1[i];
if ( v4 )
{
free(v4);
v1 = *(_QWORD **)a1;
}
i = (unsigned int)(*(_DWORD *)(a1 + 8) + 1) % *(_DWORD *)(a1 + 16);
}
free(v1);
*(_QWORD *)a1 = 0LL;
result = 1LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
return result;
}

original_code:
char destroy_seqQueue(seqQueue* queue){
  if(queue->m_base == ((void *)0)) return 0;
  while(queue->m_front != queue->m_rear){
    if(queue->m_base[queue->m_front] != ((void *)0)) free(queue->m_base[queue->m_front]);
    queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  }
  free(queue->m_base); queue->m_base = ((void *)0);
  queue->m_front = queue->m_rear = queue->m_maxSize = 0;
  return 1;
}

canonical_original_code:
char destroy_seqQueue(struct seqQueue *queue){
  if(queue->m_base == ((void *)0)) return 0;
  while(queue->m_front != queue->m_rear){
    if(queue->m_base[queue->m_front] != ((void *)0)) free(queue->m_base[queue->m_front]);
    queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  }
  free(queue->m_base); queue->m_base = ((void *)0);
  queue->m_front = queue->m_rear = queue->m_maxSize = 0;
  return 1;
}

user_defined_types: struct seqQueue { void **m_base; unsigned int m_front; unsigned int m_rear; unsigned int m_maxSize; }


decompiled_code:
__int64 __fastcall length_seqQueue(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx
unsigned int v3; // er8

v1 = a1[3];
v2 = a1[2];
v3 = v1 - v2;
if ( v2 > v1 )
v3 = a1[4] + v1 - v2;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx
unsigned int v3; // er8

v1 = a1[3];
v2 = a1[2];
v3 = v1 - v2;
if ( v2 > v1 )
v3 = a1[4] + v1 - v2;
return v3;
}

original_code:
unsigned int length_seqQueue(seqQueue* queue){
  if(queue->m_front > queue->m_rear){
    return queue->m_maxSize - queue->m_front + queue->m_rear;
  }else{
    return queue->m_rear - queue->m_front;
  }
}

canonical_original_code:
unsigned int length_seqQueue(struct seqQueue *queue){
  if(queue->m_front > queue->m_rear){
    return queue->m_maxSize - queue->m_front + queue->m_rear;
  }else{
    return queue->m_rear - queue->m_front;
  }
}


decompiled_code:
__int64 __fastcall getHead_seqQueue(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax
unsigned int v3; // er8

if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(unsigned int *)(a1 + 8);
v3 = 0;
if ( (_DWORD)v2 != *(_DWORD *)(a1 + 12) )
{
v3 = 1;
*a2 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax
unsigned int v3; // er8

if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(unsigned int *)(a1 + 8);
v3 = 0;
if ( (_DWORD)v2 != *(_DWORD *)(a1 + 12) )
{
v3 = 1;
*a2 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
}
return v3;
}

original_code:
char getHead_seqQueue(seqQueue* queue,void ** data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  return 1;
}

canonical_original_code:
char getHead_seqQueue(struct seqQueue *queue, void **data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  return 1;
}


decompiled_code:
__int64 __fastcall enQueue_seqQueue(__int64 a1, __int64 a2)
{
_QWORD *v3; // rdi
__int64 v4; // rcx
unsigned int v6; // esi
unsigned int v7; // edx
__int64 result; // rax
_QWORD *v9; // rax
unsigned int v10; // esi

v3 = *(_QWORD **)a1;
if ( !v3 )
return 0LL;
v4 = *(unsigned int *)(a1 + 12);
v6 = *(_DWORD *)(a1 + 16);
v7 = ((int)v4 + 1) % v6;
if ( v7 != *(_DWORD *)(a1 + 8) )
{
LABEL_3:
v3[v4] = a2;
result = 1LL;
*(_DWORD *)(a1 + 12) = v7;
return result;
}
v9 = realloc(v3, 8LL * (v6 + 100));
v3 = v9;
if ( v9 )
{
*(_QWORD *)a1 = v9;
v4 = *(unsigned int *)(a1 + 12);
v10 = *(_DWORD *)(a1 + 16) + 100;
v7 = ((int)v4 + 1) % v10;
*(_DWORD *)(a1 + 16) = v10;
goto LABEL_3;
}
return 4294967294LL;
}

original_code:
char enQueue_seqQueue(seqQueue* queue,void * data){
  if(queue->m_base == ((void *)0)) return 0;
  if((queue->m_rear + 1) % queue->m_maxSize == queue->m_front){
    void * p = (void *) realloc(queue->m_base,(queue->m_maxSize + 100) * sizeof(void *));
    if(p == ((void *)0)) return -2;
    queue->m_base = p; queue->m_maxSize += 100;
  }
  queue->m_base[queue->m_rear] = data;
  queue->m_rear = (queue->m_rear + 1) %queue->m_maxSize;
  return 1;
}

canonical_original_code:
char enQueue_seqQueue(struct seqQueue *queue, void *data){
  if(queue->m_base == ((void *)0)) return 0;
  if((queue->m_rear + 1) % queue->m_maxSize == queue->m_front){
    void *p = (void *) realloc(queue->m_base,(queue->m_maxSize + 100) * sizeof(void *));
    if(p == ((void *)0)) return -2;
    queue->m_base = p; queue->m_maxSize += 100;
  }
  queue->m_base[queue->m_rear] = data;
  queue->m_rear = (queue->m_rear + 1) %queue->m_maxSize;
  return 1;
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall deQueue_seqQueue(__int64 a1, _QWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // er8

if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(_DWORD *)(a1 + 8);
v3 = 0;
if ( v2 != *(_DWORD *)(a1 + 12) )
{
v3 = 1;
*a2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
*(_DWORD *)(a1 + 8) = (v2 + 1) % *(_DWORD *)(a1 + 16);
}
return v3;
}

original_code:
char deQueue_seqQueue(seqQueue* queue,void ** data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  return 1;
}

canonical_original_code:
char deQueue_seqQueue(struct seqQueue *queue, void **data){
  if(queue->m_base == ((void *)0) || queue->m_front == queue->m_rear) return 0;
  *data = queue->m_base[queue->m_front];
  queue->m_front = (queue->m_front + 1) % queue->m_maxSize;
  return 1;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_DWORD *v4; // rax
int v5; // ebx
int v6; // ebx
_DWORD *v7; // rax
int v8; // ebx
unsigned int *v10; // [rsp+8h] [rbp-30h] BYREF
char v11[40]; // [rsp+10h] [rbp-28h] BYREF

v3 = 0;
ini_seqQueue(v11, argv, envp);
do
{
v4 = malloc(4uLL);
*v4 = v3++;
enQueue_seqQueue(v11, v4);
}
while ( v3 != 111 );
v5 = 20;
v10 = 0LL;
getHead_seqQueue(v11, &v10);
printf("%d \n", *v10);
do
{
deQueue_seqQueue(v11, &v10);
printf("%d ", *v10);
--v5;
}
while ( v5 );
v6 = 0;
putchar(10);
do
{
v7 = malloc(4uLL);
*v7 = v6++;
enQueue_seqQueue(v11, v7);
}
while ( v6 != 101 );
v8 = 200;
do
{
deQueue_seqQueue(v11, &v10);
printf("%d ", *v10);
--v8;
}
while ( v8 );
destroy_seqQueue(v11);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_DWORD *v4; // rax
int v5; // ebx
int v6; // ebx
_DWORD *v7; // rax
int v8; // ebx
unsigned int *v10; // [rsp+8h] [rbp-30h] BYREF
char v11[40]; // [rsp+10h] [rbp-28h] BYREF

v3 = 0;
func7(v11, argv, envp);
do
{
v4 = malloc(4uLL);
*v4 = v3++;
func11(v11, v4);
}
while ( v3 != 111 );
v5 = 20;
v10 = 0LL;
func10(v11, &v10);
printf("%d \n", *v10);
do
{
func12(v11, &v10);
printf("%d ", *v10);
--v5;
}
while ( v5 );
v6 = 0;
putchar(10);
do
{
v7 = malloc(4uLL);
*v7 = v6++;
func11(v11, v7);
}
while ( v6 != 101 );
v8 = 200;
do
{
func12(v11, &v10);
printf("%d ", *v10);
--v8;
}
while ( v8 );
func8(v11);
return 0;
}

original_code:
int main(){
  seqQueue queue;
  ini_seqQueue(&queue);
  int i = 0;
  for(i = 0;i < 111; i++){
    int * p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  int * p = ((void *)0);
  getHead_seqQueue(&queue,(void **)&p);
  printf("%d \n",*p);
  for(i = 0;i<20;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  printf("\n");
  for(i = 0;i < 101; i++){
    int * p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  for(i = 0;i < 200;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  destroy_seqQueue(&queue);
  return 0;
}

canonical_original_code:
int main(){
  struct seqQueue queue;
  ini_seqQueue(&queue);
  int i = 0;
  for(i = 0;i < 111; i++){
    int *p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  int *p = ((void *)0);
  getHead_seqQueue(&queue,(void **)&p);
  printf("%d \n",*p);
  for(i = 0;i<20;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  printf("\n");
  for(i = 0;i < 101; i++){
    int *p = (int *) malloc(sizeof(int));
    *p = i;
    enQueue_seqQueue(&queue,(void *) p);
  }
  for(i = 0;i < 200;i++){
    deQueue_seqQueue(&queue,(void **)&p);
    printf("%d ",*p);
  }
  destroy_seqQueue(&queue);
  return 0;
}

variable_types: struct seqQueue { void **m_base; unsigned int m_front; unsigned int m_rear; unsigned int m_maxSize; }

variable_types:
p
int *


decompiled_code:
__int64 __fastcall ini_seqStack(_QWORD *a1)
{
void *v1; // rax

v1 = malloc(0x960uLL);
if ( !v1 )
return 4294967294LL;
a1[1] = v1;
*a1 = v1;
a1[2] = 0x6400000000LL;
return 1LL;
}

original_code:
char ini_seqStack(seqStack * stack){
  int* p = (int*) malloc(sizeof(seqStack)*100);
  if(p == ((void *)0)) return -2;
  stack->m_top = stack->m_base = p;
  stack->m_stackSize = 0;
  stack->m_maxStackSize = 100;
  return 1;
}

canonical_original_code:
char ini_seqStack(struct seqStack *stack){
  int *p = (int*) malloc(sizeof(seqStack)*100);
  if(p == ((void *)0)) return -2;
  stack->m_top = stack->m_base = p;
  stack->m_stackSize = 0;
  stack->m_maxStackSize = 100;
  return 1;
}

variable_types: struct seqStack { int *m_top; int *m_base; unsigned int m_stackSize; unsigned int m_maxStackSize; } *


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

v2 = (void *)a1[1];
result = 0LL;
if ( v2 )
{
free(v2);
*a1 = 0LL;
result = 1LL;
a1[1] = 0LL;
a1[2] = 0LL;
}
return result;
}

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

v2 = (void *)a1[1];
result = 0LL;
if ( v2 )
{
free(v2);
*a1 = 0LL;
result = 1LL;
a1[1] = 0LL;
a1[2] = 0LL;
}
return result;
}

original_code:
char destroy_seqStack(seqStack* stack){
  if(stack->m_base == ((void *)0)) return 0;
  free(stack->m_base);
  stack->m_base = stack->m_top = ((void *)0);
  stack->m_stackSize = stack->m_maxStackSize = 0;
  return 1;
}

canonical_original_code:
char destroy_seqStack(struct seqStack *stack){
  if(stack->m_base == ((void *)0)) return 0;
  free(stack->m_base);
  stack->m_base = stack->m_top = ((void *)0);
  stack->m_stackSize = stack->m_maxStackSize = 0;
  return 1;
}

user_defined_types: struct seqStack { int *m_top; int *m_base; unsigned int m_stackSize; unsigned int m_maxStackSize; }


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

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)a1 = result;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)a1 = result;
return result;
}

original_code:
char clear_seqStack(seqStack* stack){
  stack->m_stackSize = 0;
  stack->m_top = stack->m_base;
}

canonical_original_code:
char clear_seqStack(struct seqStack *stack){
  stack->m_stackSize = 0;
  stack->m_top = stack->m_base;
}


decompiled_code:
__int64 __fastcall getTop_seqStack(_QWORD *a1, _DWORD *a2)
{
if ( a1[1] == *a1 )
return 0LL;
*a2 = *(_DWORD *)(*a1 - 4LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, _DWORD *a2)
{
if ( a1[1] == *a1 )
return 0LL;
*a2 = *(_DWORD *)(*a1 - 4LL);
return 1LL;
}

original_code:
char getTop_seqStack(seqStack* stack,int* ele){
  if(stack->m_base == stack->m_top) return 0;
  int* p = stack->m_top;
  *ele = *--p;
  return 1;
}

canonical_original_code:
char getTop_seqStack(struct seqStack *stack, int *ele){
  if(stack->m_base == stack->m_top) return 0;
  int *p = stack->m_top;
  *ele = *--p;
  return 1;
}


decompiled_code:
__int64 __fastcall pop_seqStack(__int64 *a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rdx
int v4; // eax
__int64 result; // rax

v2 = *a1;
if ( a1[1] == *a1 )
return 0LL;
v3 = v2 - 4;
v4 = *(_DWORD *)(v2 - 4);
*a1 = v3;
*a2 = v4;
result = 1LL;
--*((_DWORD *)a1 + 4);
return result;
}

original_code:
char pop_seqStack(seqStack* stack,int* ele){
  if(stack->m_base == stack->m_top) return 0;
  stack->m_top--;
  *ele = *stack->m_top;
  --stack->m_stackSize;
  return 1;
}

canonical_original_code:
char pop_seqStack(struct seqStack *stack, int *ele){
  if(stack->m_base == stack->m_top) return 0;
  stack->m_top--;
  *ele = *stack->m_top;
  --stack->m_stackSize;
  return 1;
}


decompiled_code:
__int64 __fastcall length_seqStack(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
unsigned int length_seqStack(seqStack* stack){
  return stack->m_stackSize;
}

canonical_original_code:
unsigned int length_seqStack(struct seqStack *stack){
  return stack->m_stackSize;
}


original_code:
char push_seqStack(seqStack* stack,const int ele){
  if(stack->m_stackSize >= stack->m_maxStackSize){
    int* pTemp = (int*) realloc(stack->m_base,(stack->m_maxStackSize + 100) * sizeof(int));
    if(pTemp == ((void *)0)) return -2;
    stack->m_base = pTemp;
    stack->m_maxStackSize += 100;
  }
  *stack->m_top++ = ele;
  stack->m_stackSize += 1;
  return 1;
}

canonical_original_code:
char push_seqStack(struct seqStack *stack, int ele){
  if(stack->m_stackSize >= stack->m_maxStackSize){
    int *pTemp = (int*) realloc(stack->m_base,(stack->m_maxStackSize + 100) * sizeof(int));
    if(pTemp == ((void *)0)) return -2;
    stack->m_base = pTemp;
    stack->m_maxStackSize += 100;
  }
  *stack->m_top++ = ele;
  stack->m_stackSize += 1;
  return 1;
}

variable_types:
pTemp
int *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rsi
unsigned int i; // [rsp+8h] [rbp-30h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-2Ch] BYREF
char v8[40]; // [rsp+10h] [rbp-28h] BYREF

ini_seqStack(v8, argv, envp);
i = 0;
v3 = 0LL;
do
{
push_seqStack(v8, v3);
v3 = i + 1;
i = v3;
}
while ( (int)v3 <= 119 );
getTop_seqStack(v8, &i);
printf("%d \n", i);
i = 0;
v4 = 0LL;
do
{
push_seqStack(v8, v4);
v4 = i + 1;
i = v4;
}
while ( (int)v4 <= 119 );
v7 = 0;
for ( i = 0; (int)i <= 269; ++i )
{
pop_seqStack(v8, &v7);
printf("%d ", v7);
}
putchar(10);
clear_seqStack(v8);
destroy_seqStack();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
__int64 v4; // rsi
unsigned int i; // [rsp+8h] [rbp-30h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-2Ch] BYREF
char v8[40]; // [rsp+10h] [rbp-28h] BYREF

func7(v8, argv, envp);
i = 0;
v3 = 0LL;
do
{
func13(v8, v3);
v3 = i + 1;
i = v3;
}
while ( (int)v3 <= 119 );
func10(v8, &i);
printf("%d \n", i);
i = 0;
v4 = 0LL;
do
{
func13(v8, v4);
v4 = i + 1;
i = v4;
}
while ( (int)v4 <= 119 );
v7 = 0;
for ( i = 0; (int)i <= 269; ++i )
{
func11(v8, &v7);
printf("%d ", v7);
}
putchar(10);
func9(v8);
func8();
return 0;
}

original_code:
int main(){
  seqStack stack;
  ini_seqStack(&stack);
  int i = 0;
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  getTop_seqStack(&stack,&i);
  printf("%d \n",i);
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  int j = 0;
  for(i = 0;i < 270;i++){
    pop_seqStack(&stack,&j);
    printf("%d ",j);
  }
  printf("\n");
  clear_seqStack(&stack);
  destroy_seqStack(&stack);
  return 0;
}

canonical_original_code:
int main(){
  struct seqStack stack;
  ini_seqStack(&stack);
  int i = 0;
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  getTop_seqStack(&stack,&i);
  printf("%d \n",i);
  for(i = 0;i < 120;i++){
    push_seqStack(&stack,i);
  }
  int j = 0;
  for(i = 0;i < 270;i++){
    pop_seqStack(&stack,&j);
    printf("%d ",j);
  }
  printf("\n");
  clear_seqStack(&stack);
  destroy_seqStack(&stack);
  return 0;
}

variable_types: struct seqStack { int *m_top; int *m_base; unsigned int m_stackSize; unsigned int m_maxStackSize; }


decompiled_code:
__int64 __fastcall compare_for_int(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 3LL;
if ( *a1 <= *a2 )
{
LOBYTE(result) = *a1 != *a2;
result = (unsigned int)(2 * result + 2);
}
return result;
}

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

result = 3LL;
if ( *a1 <= *a2 )
{
LOBYTE(result) = *a1 != *a2;
result = (unsigned int)(2 * result + 2);
}
return result;
}

original_code:
char compare_for_int(void * a,void * b){
  int * pa = (int *) a;
  int * pb = (int *) b;
  if(*pa > *pb){
 return 3;
  }else if(*pa == *pb){
 return 2;
  }else{
 return 4;
  }
}

canonical_original_code:
char compare_for_int(void *a, void *b){
  int *pa = (int *) a;
  int *pb = (int *) b;
  if(*pa > *pb){
 return 3;
  }else if(*pa == *pb){
 return 2;
  }else{
 return 4;
  }
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
pa
int *

variable_types:
pb
int *


myPrint

decompiled_code:
int __fastcall myPrint(unsigned int *a1)
{
return printf("%d\t", *a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int *a1)
{
return printf("%d\t", *a1);
}

original_code:
void myPrint(void * a){
  int * pa = (int *) a;
  printf("%d\t",*pa);
}

canonical_original_code:
void myPrint(void *a){
  int *pa = (int *) a;
  printf("%d\t",*pa);
}


repo: ultramailman/iniparser

decompiled_code:
_QWORD *varstr_new()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = calloc(1uLL, 1uLL);
if ( v1 )
{
*v0 = 1LL;
v0[2] = v1;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = calloc(1uLL, 1uLL);
if ( v1 )
{
*v0 = 1LL;
v0[2] = v1;
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
struct varstr * varstr_new(void)
{
 struct varstr * newstr = calloc(1, sizeof *newstr);
 if(newstr != ((void *)0))
 {
  char * buf = calloc(1, 1);
  if(buf != ((void *)0))
  {
   newstr->buflen = 1;
   newstr->buf = buf;
  }
  else
  {
   free(newstr);
   newstr = ((void *)0);
  }
 }
 return newstr;
}

canonical_original_code:
struct varstr *varstr_new()
{
 struct varstr *newstr = calloc(1, sizeof *newstr);
 if(newstr != ((void *)0))
 {
  char *buf = calloc(1, 1);
  if(buf != ((void *)0))
  {
   newstr->buflen = 1;
   newstr->buf = buf;
  }
  else
  {
   free(newstr);
   newstr = ((void *)0);
  }
 }
 return newstr;
}

variable_types: struct varstr { unsigned long buflen; char *buf; } *

variable_types:
buf
char *


decompiled_code:
void __fastcall varstr_del(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void varstr_del(struct varstr * str)
{
 if(str != ((void *)0))
 {
  free(str->buf);
  free(str);
 }
}

canonical_original_code:
void varstr_del(struct varstr *str)
{
 if(str != ((void *)0))
 {
  free(str->buf);
  free(str);
 }
}

user_defined_types: struct varstr { unsigned long buflen; char *buf; }


decompiled_code:
__int64 __fastcall varstr_len(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
unsigned long varstr_len(struct varstr const * str)
{
 return str->len;
}

canonical_original_code:
unsigned long varstr_len(struct varstr *str)
{
 return str->len;
}

return_type: unsigned long


original_code:
int varstr_append(struct varstr * str, char c)
{
 if(str->len + 1 == str->buflen)
 {
  char * newbuf = realloc(str->buf, str->buflen * 2);
  if(newbuf != ((void *)0))
  {
   str->buf = newbuf;
   str->buflen *= 2;
  }
  else
   return -1;
 }
 str->buf[str->len] = c;
 str->len++;
 str->buf[str->len] = 0;
 return 0;
}

canonical_original_code:
int varstr_append(struct varstr *str, char c)
{
 if(str->len + 1 == str->buflen)
 {
  char *newbuf = realloc(str->buf, str->buflen * 2);
  if(newbuf != ((void *)0))
  {
   str->buf = newbuf;
   str->buflen *= 2;
  }
  else
   return -1;
 }
 str->buf[str->len] = c;
 str->len++;
 str->buf[str->len] = 0;
 return 0;
}

variable_types: c char

variable_types:
newbuf
char *


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

if ( *(_QWORD *)(a1 + 8) <= a2 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + a2);
return result;
}

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

if ( *(_QWORD *)(a1 + 8) <= a2 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + a2);
return result;
}

original_code:
int varstr_get(struct varstr * str, unsigned long i)
{
 if(i < str->len)
  return str->buf[i];
 else
  return -1;
}

canonical_original_code:
int varstr_get(struct varstr *str, unsigned long i)
{
 if(i < str->len)
  return str->buf[i];
 else
  return -1;
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall varstr_set(__int64 a1, unsigned __int64 a2, char a3)
{
if ( *(_QWORD *)(a1 + 8) <= a2 )
return 0xFFFFFFFFLL;
*(_BYTE *)(*(_QWORD *)(a1 + 16) + a2) = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int64 a2, char a3)
{
if ( *(_QWORD *)(a1 + 8) <= a2 )
return 0xFFFFFFFFLL;
*(_BYTE *)(*(_QWORD *)(a1 + 16) + a2) = a3;
return 0LL;
}

original_code:
int varstr_set(struct varstr * str, unsigned long i, char c)
{
 if(i < str->len)
 {
  str->buf[i] = c;
  return 0;
 }
 else
  return -1;
}

canonical_original_code:
int varstr_set(struct varstr *str, unsigned long i, char c)
{
 if(i < str->len)
 {
  str->buf[i] = c;
  return 0;
 }
 else
  return -1;
}


decompiled_code:
__int64 __fastcall varstr_view(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
char const * varstr_view(struct varstr * str)
{
 return str->buf;
}

canonical_original_code:
char *varstr_view(struct varstr *str)
{
 return str->buf;
}

return_type: char *


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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)(char)(a1 - 87);
result = (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = 0xFFFFFFFFLL;
return result;
}

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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
return (unsigned int)(char)(a1 - 87);
result = (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = 0xFFFFFFFFLL;
return result;
}


decompiled_code:
__int64 __fastcall cstr_has(_BYTE *a1, char a2)
{
__int64 result; // rax

LOBYTE(result) = *a1;
if ( !*a1 )
return 0LL;
while ( a2 != (_BYTE)result )
{
result = (unsigned __int8)*++a1;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, char a2)
{
__int64 result; // rax

LOBYTE(result) = *a1;
if ( !*a1 )
return 0LL;
while ( a2 != (_BYTE)result )
{
result = (unsigned __int8)*++a1;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

original_code:
_Bool cstr_has(char const * cstr, char c)
{
 while(*cstr != 0)
 {
  if(*cstr == c)
   return 1;
  cstr++;
 }
 return 0;
}

canonical_original_code:
_Bool cstr_has(char *cstr, char c)
{
 while(*cstr != 0)
 {
  if(*cstr == c)
   return 1;
  cstr++;
 }
 return 0;
}

variable_types:
cstr
char *


decompiled_code:
__int64 __fastcall cstr_remove_trailing(char *a1, _BYTE *a2)
{
char v4; // si
char v5; // cl
_BYTE *v6; // r8
_BYTE *v7; // r9
__int64 result; // rax
__int64 v9; // rdx
__int64 v10; // rdx
int v11; // ecx

while ( 1 )
{
v4 = *a1;
if ( !(unsigned __int8)cstr_has(a2, *a1) )
break;
a1 = v6 + 1;
}
result = 0LL;
if ( v6 == v7 )
{
if ( *v7 )
{
do
v9 = (int)result++;
while ( v7[result] );
goto LABEL_9;
}
}
else if ( v4 )
{
do
{
v7[result] = v5;
v9 = (int)result++;
v5 = v6[result];
}
while ( v5 );
v7[result] = 0;
LABEL_9:
while ( 1 )
{
result = cstr_has(a2, v7[v9]);
if ( !(_BYTE)result )
break;
v9 = v10 - 1;
if ( (_DWORD)v9 == -1 )
goto LABEL_11;
}
v7 += v11 + 1;
}
else
{
*v7 = 0;
}
LABEL_11:
*v7 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _BYTE *a2)
{
char v4; // si
char v5; // cl
_BYTE *v6; // r8
_BYTE *v7; // r9
__int64 result; // rax
__int64 v9; // rdx
__int64 v10; // rdx
int v11; // ecx

while ( 1 )
{
v4 = *a1;
if ( !(unsigned __int8)func1(a2, *a1) )
break;
a1 = v6 + 1;
}
result = 0LL;
if ( v6 == v7 )
{
if ( *v7 )
{
do
v9 = (int)result++;
while ( v7[result] );
goto LABEL_9;
}
}
else if ( v4 )
{
do
{
v7[result] = v5;
v9 = (int)result++;
v5 = v6[result];
}
while ( v5 );
v7[result] = 0;
LABEL_9:
while ( 1 )
{
result = func1(a2, v7[v9]);
if ( !(_BYTE)result )
break;
v9 = v10 - 1;
if ( (_DWORD)v9 == -1 )
goto LABEL_11;
}
v7 += v11 + 1;
}
else
{
*v7 = 0;
}
LABEL_11:
*v7 = 0;
return result;
}

original_code:
void cstr_remove_trailing(char * cstr, char const * charset)
{
 char * begin = cstr;
 while(cstr_has(charset, *begin))
  begin++;
 int i = 0;
 if(cstr != begin)
 {
  for(; begin[i] != 0; i++)
   cstr[i] = begin[i];
  cstr[i] = 0;
 }
 else
 {
  while(cstr[i] != 0)
   i++;
 }
 i--;
 while(i >= 0 && cstr_has(charset, cstr[i]))
  i--;
 cstr[i + 1] = 0;
}

canonical_original_code:
void cstr_remove_trailing(char *cstr, char *charset)
{
 char *begin = cstr;
 while(cstr_has(charset, *begin))
  begin++;
 int i = 0;
 if(cstr != begin)
 {
  for(; begin[i] != 0; i++)
   cstr[i] = begin[i];
  cstr[i] = 0;
 }
 else
 {
  while(cstr[i] != 0)
   i++;
 }
 i--;
 while(i >= 0 && cstr_has(charset, cstr[i]))
  i--;
 cstr[i + 1] = 0;
}

variable_types:
charset
char *

variable_types:
begin
char *

variable_types: i int


decompiled_code:
__int64 __fastcall cstr_chomp(char *a1)
{
return cstr_remove_trailing(a1, byte_4A5);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
return func2(a1, byte_4A5);
}

original_code:
void cstr_chomp(char * cstr)
{
 cstr_remove_trailing(cstr, " \t\n");
}

canonical_original_code:
void cstr_chomp(char *cstr)
{
 cstr_remove_trailing(cstr, " \t\n");
}


decompiled_code:
int __fastcall cstr_subst(char *s1, char *s2, void *src)
{
char *v3; // r15
int v5; // ebx
int v6; // eax
int v7; // edx
size_t v8; // r14
int result; // eax
size_t v10; // rax
char *v11; // rdi
size_t v12; // rax
int v13; // [rsp+Ch] [rbp-3Ch]

v3 = s1;
v5 = strlen(s2);
v6 = strlen((const char *)src);
v7 = v5 - v6;
v8 = v6;
result = (v5 - v6) >> 31;
v13 = (result ^ v7) - result;
while ( *v3 )
{
while ( 1 )
{
result = strncmp(v3, s2, v5);
if ( result )
{
++v3;
goto LABEL_4;
}
if ( v5 >= (int)v8 )
break;
v10 = strlen(v3);
memmove(&v3[v13], v3, v10 + 1);
result = (unsigned int)memcpy(v3, src, v8);
LABEL_4:
if ( !*v3 )
return result;
}
v11 = v3;
v3 += v8;
result = (unsigned int)memcpy(v11, src, v8);
if ( v5 == (_DWORD)v8 )
goto LABEL_4;
v12 = strlen(v3);
result = (unsigned int)memmove(v3, &v3[v13], v12 + 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *s1, char *s2, void *src)
{
char *v3; // r15
int v5; // ebx
int v6; // eax
int v7; // edx
size_t v8; // r14
int result; // eax
size_t v10; // rax
char *v11; // rdi
size_t v12; // rax
int v13; // [rsp+Ch] [rbp-3Ch]

v3 = s1;
v5 = strlen(s2);
v6 = strlen((const char *)src);
v7 = v5 - v6;
v8 = v6;
result = (v5 - v6) >> 31;
v13 = (result ^ v7) - result;
while ( *v3 )
{
while ( 1 )
{
result = strncmp(v3, s2, v5);
if ( result )
{
++v3;
goto LABEL_4;
}
if ( v5 >= (int)v8 )
break;
v10 = strlen(v3);
memmove(&v3[v13], v3, v10 + 1);
result = (unsigned int)memcpy(v3, src, v8);
LABEL_4:
if ( !*v3 )
return result;
}
v11 = v3;
v3 += v8;
result = (unsigned int)memcpy(v11, src, v8);
if ( v5 == (_DWORD)v8 )
goto LABEL_4;
v12 = strlen(v3);
result = (unsigned int)memmove(v3, &v3[v13], v12 + 1);
}
return result;
}

original_code:
void cstr_subst(char * restrict cstr,
 char const * restrict a, char const * restrict b)
{
 char * iter = cstr;
 int const a_len = strlen(a);
 int const b_len = strlen(b);
 int const gap = abs(a_len - b_len);
 while(*iter != 0)
 {
  if(strncmp(iter, a, a_len) != 0)
  {
   iter++;
   continue;
  }
  if(a_len < b_len)
  {
   memmove(iter + gap, iter, strlen(iter) + 1);
   memcpy(iter, b, b_len);
  }
  else
  {
   memcpy(iter, b, b_len);
   iter += b_len;
   if(gap > 0)
    memmove(iter, iter + gap, strlen(iter) + 1);
  }
 }
}

canonical_original_code:
void cstr_subst(char *cstr, char *a, char *b)
{
 char *iter = cstr;
 int a_len = strlen(a);
 int b_len = strlen(b);
 int gap = abs(a_len - b_len);
 while(*iter != 0)
 {
  if(strncmp(iter, a, a_len) != 0)
  {
   iter++;
   continue;
  }
  if(a_len < b_len)
  {
   memmove(iter + gap, iter, strlen(iter) + 1);
   memcpy(iter, b, b_len);
  }
  else
  {
   memcpy(iter, b, b_len);
   iter += b_len;
   if(gap > 0)
    memmove(iter, iter + gap, strlen(iter) + 1);
  }
 }
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
iter
char *

variable_types: gap int


decompiled_code:
__int64 __fastcall cstr2uint(_BYTE *a1, unsigned int *a2)
{
int v2; // edx
unsigned int v3; // eax
bool v4; // cf
unsigned int v5; // edx
int v6; // eax

v2 = (char)*a1;
if ( !*a1 )
return 4294967293LL;
v3 = 0;
while ( 1 )
{
v5 = v2 - 48;
v6 = 10 * v3;
if ( v5 > 9 )
return 0xFFFFFFFFLL;
v4 = __CFADD__(v5, v6);
v3 = v5 + v6;
if ( v4 )
break;
v2 = (char)*++a1;
if ( !(_BYTE)v2 )
{
*a2 = v3;
return 0LL;
}
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1, unsigned int *a2)
{
int v2; // edx
unsigned int v3; // eax
bool v4; // cf
unsigned int v5; // edx
int v6; // eax

v2 = (char)*a1;
if ( !*a1 )
return 4294967293LL;
v3 = 0;
while ( 1 )
{
v5 = v2 - 48;
v6 = 10 * v3;
if ( v5 > 9 )
return 0xFFFFFFFFLL;
v4 = __CFADD__(v5, v6);
v3 = v5 + v6;
if ( v4 )
break;
v2 = (char)*++a1;
if ( !(_BYTE)v2 )
{
*a2 = v3;
return 0LL;
}
}
return 4294967294LL;
}

original_code:
int cstr2uint(char const * cstr, unsigned * uintptr)
{
 unsigned sum = 0;
 if(*cstr == 0)
  return -3;
 while(*cstr)
 {
  sum *= 10;
  unsigned digit = *cstr - '0';
  if(digit > 9)
   return -1;
  unsigned new_sum = sum + digit;
  if(new_sum < sum)
   return -2;
  sum = new_sum;
  cstr++;
 }
 *uintptr = sum;
 return 0;
}

canonical_original_code:
int cstr2uint(char *cstr, unsigned int *uintptr)
{
 unsigned int sum = 0;
 if(*cstr == 0)
  return -3;
 while(*cstr)
 {
  sum *= 10;
  unsigned int digit = *cstr - '0';
  if(digit > 9)
   return -1;
  unsigned int new_sum = sum + digit;
  if(new_sum < sum)
   return -2;
  sum = new_sum;
  cstr++;
 }
 *uintptr = sum;
 return 0;
}

variable_types:
uintptr
unsigned int *

variable_types:
sum
unsigned int

variable_types:
digit
unsigned int


decompiled_code:
__int64 __fastcall cstr2int(_BYTE *a1)
{
__int64 result; // rax
int v2; // ecx
_DWORD *v3; // r8
int v4; // [rsp+0h] [rbp-4h] BYREF

if ( !*a1 )
return 4294967293LL;
if ( *a1 == 45 )
++a1;
result = cstr2uint(a1, (unsigned int *)&v4);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
if ( v4 < 0 )
return 4294967294LL;
*v3 = v4 * v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
__int64 result; // rax
int v2; // ecx
_DWORD *v3; // r8
int v4; // [rsp+0h] [rbp-4h] BYREF

if ( !*a1 )
return 4294967293LL;
if ( *a1 == 45 )
++a1;
result = func5(a1, (unsigned int *)&v4);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
if ( v4 < 0 )
return 4294967294LL;
*v3 = v4 * v2;
return result;
}

original_code:
int cstr2int(char const * cstr, int * intptr)
{
 if(*cstr == 0)
  return -3;
 int sign = 1;
 if(*cstr == '-')
 {
  sign = -1;
  cstr++;
 }
 unsigned magnitude;
 if(cstr2uint(cstr, &magnitude) != 0)
  return -1;
 int sum = (int)magnitude;
 if(sum < 0)
  return -2;
 *intptr = sum * sign;
 return 0;
}

canonical_original_code:
int cstr2int(char *cstr, int *intptr)
{
 if(*cstr == 0)
  return -3;
 int sign = 1;
 if(*cstr == '-')
 {
  sign = -1;
  cstr++;
 }
 unsigned int magnitude;
 if(cstr2uint(cstr, &magnitude) != 0)
  return -1;
 int sum = (int)magnitude;
 if(sum < 0)
  return -2;
 *intptr = sum * sign;
 return 0;
}

variable_types:
intptr
int *

variable_types: sign int

variable_types:
magnitude
unsigned int

variable_types: sum int


decompiled_code:
void *__fastcall cstr_dup(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // r8

if ( !src )
return 0LL;
v1 = strlen((const char *)src);
v2 = calloc(((_DWORD)v1 + 4) & 0xFFFFFFFC, 1uLL);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1 + 1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func8(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // r8

if ( !src )
return 0LL;
v1 = strlen((const char *)src);
v2 = calloc(((_DWORD)v1 + 4) & 0xFFFFFFFC, 1uLL);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1 + 1);
return v3;
}

original_code:
char * cstr_dup(char const * src)
{
 char * new_str = ((void *)0);
 if(src)
 {
  unsigned len =
   (strlen(src) + sizeof(int)) / sizeof(int) * sizeof(int);
  new_str = calloc(len , 1);
  if(new_str)
   strcpy(new_str, src);
 }
 return new_str;
}

canonical_original_code:
char *cstr_dup(char *src)
{
 char *new_str = ((void *)0);
 if(src)
 {
  unsigned int len = (strlen(src) + sizeof(int)) / sizeof(int) * sizeof(int);
  new_str = calloc(len , 1);
  if(new_str)
   strcpy(new_str, src);
 }
 return new_str;
}

variable_types:
src
char *

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall is_whitespace(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}

original_code:
int is_whitespace(char c)
{
 return (c == '\n') || (c == ' ') || (c == '\t');
}

variable_types: c char


decompiled_code:
_BOOL8 __fastcall is_int(_BYTE *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_BYTE *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 != 0;
else
result = 0LL;
return result;
}

original_code:
int is_int(char const * cstr)
{
 if(cstr == 0)
  return 0;
 if(*cstr == 0)
  return 0;
 for(int i = 0; cstr[i] == 0; i++)
 {
  if(cstr[i] < '0' || cstr[i] > '9')
  {
   if((i != 0) || (cstr[i] != '-' && cstr[i] != '+'))
    return 0;
  }
 }
 return 1;
}

canonical_original_code:
int is_int(char *cstr)
{
 if(cstr == 0)
  return 0;
 if(*cstr == 0)
  return 0;
 for(int i = 0; cstr[i] == 0; i++)
 {
  if(cstr[i] < '0' || cstr[i] > '9')
  {
   if((i != 0) || (cstr[i] != '-' && cstr[i] != '+'))
    return 0;
  }
 }
 return 1;
}

variable_types:
cstr
char *


decompiled_code:
__int64 __fastcall command_new(__int64 a1, int a2)
{
__int64 result; // rax

*(_DWORD *)a1 = a2;
result = a1;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax

*(_DWORD *)a1 = a2;
result = a1;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
return result;
}

original_code:
static struct command command_new(enum command_type type)
{
 return (struct command){
  .type = type,
  .arg1 = ((void *)0),
  .arg2 = ((void *)0)
 };
}

return_type: struct command { enum command_type { COMMAND_NONE=0, COMMAND_SET_SECTION=1, COMMAND_INSERT_PAIR=2 } type; char *arg1; char *arg2; }

user_defined_types: struct command { enum command_type type; char *arg1; char *arg2; }


decompiled_code:
__int64 __fastcall entry_hash(char **a1)
{
_BYTE *v1; // rdx
unsigned int v2; // er8
int i; // eax

v1 = *a1;
v2 = 0;
for ( i = **a1; *v1; i = (char)*v1 )
{
++v1;
v2 = i + 257 * v2;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char **a1)
{
_BYTE *v1; // rdx
unsigned int v2; // er8
int i; // eax

v1 = *a1;
v2 = 0;
for ( i = **a1; *v1; i = (char)*v1 )
{
++v1;
v2 = i + 257 * v2;
}
return v2;
}

original_code:
static unsigned entry_hash(void const * a)
{
 unsigned sum = 0;
 char const * s = ((struct entry *)a)->name;
 while(*s)
  sum = (sum * 257) + *s++;
 return sum;
}

canonical_original_code:
static unsigned int entry_hash(void *a)
{
 unsigned int sum = 0;
 char *s = ((struct entry *)a)->name;
 while(*s)
  sum = (sum * 257) + *s++;
 return sum;
}

variable_types:
a
void *

variable_types:
s
char *


decompiled_code:
int __fastcall entry_cmp(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func2(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
static int entry_cmp(void const * a, void const * b)
{
 struct entry const * e1 = a;
 struct entry const * e2 = b;
 return strcmp(e1->name, e2->name);
}

canonical_original_code:
static int entry_cmp(void *a, void *b)
{
 struct entry *e1 = a;
 struct entry *e2 = b;
 return strcmp(e1->name, e2->name);
}

variable_types:
b
void *

variable_types: struct entry { char *name; void *val; } *


grow

original_code:
static int grow(struct hashset * hs)
{
 struct hashset bigger = *hs;
 bigger.size *= 2;
 if(bigger.size > hs->size)
 {
  bigger.buk = calloc(bigger.size, sizeof(void*));
  if(bigger.buk != ((void *)0))
  {
   for(unsigned i = 0; i < hs->size; i++)
   {
    while(hs->buk[i])
    {
     struct entry * top = hs->buk[i];
     hs->buk[i] = top->next;
     unsigned hash = (*hs->hash)(top->item);
     hash = ((hash) & ((bigger.size) - 1));
     top->next = bigger.buk[hash];
     bigger.buk[hash] = top;
    }
   }
   *hs = bigger;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
static int grow(struct hashset *hs)
{
 struct hashset bigger = *hs;
 bigger.size *= 2;
 if(bigger.size > hs->size)
 {
  bigger.buk = calloc(bigger.size, sizeof(void *));
  if(bigger.buk != ((void *)0))
  {
   for(unsigned int i = 0; i < hs->size; i++)
   {
    while(hs->buk[i])
    {
     struct entry *top = hs->buk[i];
     hs->buk[i] = top->next;
     unsigned int hash = (*hs->hash)(top->item);
     hash = ((hash) & ((bigger.size) - 1));
     top->next = bigger.buk[hash];
     bigger.buk[hash] = top;
    }
   }
   *hs = bigger;
   return 0;
  }
 }
 return -1;
}

variable_types: struct hashset { unsigned int size; unsigned int ele_size; unsigned int nitem; struct entry { struct entry *next; char item[1]; } **buk; int (*cmp)(void *, void *); unsigned int (*hash)(void *); } *

variable_types:
i
unsigned int

variable_types:
hash
unsigned int

user_defined_types: struct hashset { unsigned int size; unsigned int ele_size; unsigned int nitem; struct entry **buk; int (*cmp)(void *, void *); unsigned int (*hash)(void *); }


decompiled_code:
void __fastcall hashset_del(void *ptr)
{
char *v2; // rbp
char *i; // rbx
_QWORD *v4; // rdi

if ( ptr )
{
v2 = (char *)*((_QWORD *)ptr + 2);
if ( *(_DWORD *)ptr )
{
for ( i = &v2[8 * (*(_DWORD *)ptr - 1)]; ; i -= 8 )
{
while ( 1 )
{
v4 = *(_QWORD **)i;
if ( !*(_QWORD *)i )
break;
*(_QWORD *)i = *v4;
free(v4);
}
if ( i == v2 )
break;
}
}
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
char *v2; // rbp
char *i; // rbx
_QWORD *v4; // rdi

if ( ptr )
{
v2 = (char *)*((_QWORD *)ptr + 2);
if ( *(_DWORD *)ptr )
{
for ( i = &v2[8 * (*(_DWORD *)ptr - 1)]; ; i -= 8 )
{
while ( 1 )
{
v4 = *(_QWORD **)i;
if ( !*(_QWORD *)i )
break;
*(_QWORD *)i = *v4;
free(v4);
}
if ( i == v2 )
break;
}
}
free(v2);
free(ptr);
}
}

original_code:
void hashset_del(struct hashset * hs)
{
 if(hs != ((void *)0))
 {
  struct entry ** buk = hs->buk;
  for(unsigned i = hs->size; i--;)
  {
   while(buk[i])
   {
    struct entry * deleted = buk[i];
    buk[i] = deleted->next;
    free(deleted);
   }
  }
  free(buk);
  hs->buk = ((void *)0);
  hs->nitem = 0;
  free(hs);
 }
}

canonical_original_code:
void hashset_del(struct hashset *hs)
{
 if(hs != ((void *)0))
 {
  struct entry **buk = hs->buk;
  for(unsigned int i = hs->size; i--;)
  {
   while(buk[i])
   {
    struct entry *deleted = buk[i];
    buk[i] = deleted->next;
    free(deleted);
   }
  }
  free(buk);
  hs->buk = ((void *)0);
  hs->nitem = 0;
  free(hs);
 }
}

variable_types: struct entry { struct entry *next; char item[1]; } **


decompiled_code:
__int64 __fastcall hashset_insert_s(__int64 a1, const void *a2, unsigned int a3)
{
size_t v3; // r12
_QWORD *v4; // r14
__int64 v5; // r13
_QWORD *v6; // rax
__int64 result; // rax

v3 = a3;
do
{
if ( (unsigned int)(2 * *(_DWORD *)(a1 + 8)) < *(_DWORD *)a1 )
{
v4 = calloc(1uLL, v3 + 8);
v5 = (*(unsigned int (__fastcall **)(const void *))(a1 + 32))(a2) & (*(_DWORD *)a1 - 1);
memcpy(v4 + 1, a2, v3);
v6 = (_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v5);
*v4 = *v6;
*v6 = v4;
result = 0LL;
++*(_DWORD *)(a1 + 8);
return result;
}
}
while ( !(unsigned int)grow(a1) );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, unsigned int a3)
{
size_t v3; // r12
_QWORD *v4; // r14
__int64 v5; // r13
_QWORD *v6; // rax
__int64 result; // rax

v3 = a3;
do
{
if ( (unsigned int)(2 * *(_DWORD *)(a1 + 8)) < *(_DWORD *)a1 )
{
v4 = calloc(1uLL, v3 + 8);
v5 = (*(unsigned int (__fastcall **)(const void *))(a1 + 32))(a2) & (*(_DWORD *)a1 - 1);
memcpy(v4 + 1, a2, v3);
v6 = (_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v5);
*v4 = *v6;
*v6 = v4;
result = 0LL;
++*(_DWORD *)(a1 + 8);
return result;
}
}
while ( !(unsigned int)func0(a1) );
return 1LL;
}

original_code:
int hashset_insert_s(struct hashset * hs, void const * item, unsigned size)
{
 if(hs->nitem * 2 < hs->size)
 {
  struct entry * new_node = calloc(1, sizeof(void*) + size);
  unsigned i = (((*hs->hash)(item)) & ((hs->size) - 1));
  memcpy(new_node->item, item, size);
  new_node->next = hs->buk[i];
  hs->buk[i] = new_node;
  hs->nitem++;
  return 0;
 }
 else
 {
  if(grow(hs) == 0)
   return hashset_insert_s(hs, item, size);
  else
   return 1;
 }
}

canonical_original_code:
int hashset_insert_s(struct hashset *hs, void *item, unsigned int size)
{
 if(hs->nitem * 2 < hs->size)
 {
  struct entry *new_node = calloc(1, sizeof(void*) + size);
  unsigned int i = (((*hs->hash)(item)) & ((hs->size) - 1));
  memcpy(new_node->item, item, size);
  new_node->next = hs->buk[i];
  hs->buk[i] = new_node;
  hs->nitem++;
  return 0;
 }
 else
 {
  if(grow(hs) == 0)
   return hashset_insert_s(hs, item, size);
  else
   return 1;
 }
}

variable_types:
item
void *

variable_types:
size
unsigned int

variable_types: struct entry { struct entry *next; char item[1]; } *


decompiled_code:
__int64 __fastcall hashset_insert(__int64 a1, const void *a2)
{
return hashset_insert_s(a1, a2, *(_DWORD *)(a1 + 4));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const void *a2)
{
return func2(a1, a2, *(_DWORD *)(a1 + 4));
}

original_code:
int hashset_insert(struct hashset * hs, void const * item)
{
 return hashset_insert_s(hs, item, hs->ele_size);
}

canonical_original_code:
int hashset_insert(struct hashset *hs, void *item)
{
 return hashset_insert_s(hs, item, hs->ele_size);
}

user_defined_types: struct entry { struct entry *next; char item[1]; }


original_code:
int hashset_remove(struct hashset * hs, void const * item)
{
 unsigned i = (((*hs->hash)(item)) & ((hs->size) - 1));
 struct entry * iter = hs->buk[i];
 struct entry head = {.next = iter};
 struct entry * prev = &head;
 while(iter)
 {
  if(0 != (*hs->cmp)(item, iter->item))
  {
   prev = iter;
   iter = iter->next;
  }
  else
  {
   prev->next = iter->next;
   hs->buk[i] = head.next;
   free(iter);
   hs->nitem--;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int hashset_remove(struct hashset *hs, void *item)
{
 unsigned int i = (((*hs->hash)(item)) & ((hs->size) - 1));
 struct entry *iter = hs->buk[i];
 struct entry head = {.next = iter};
 struct entry *prev = &head;
 while(iter)
 {
  if(0 != (*hs->cmp)(item, iter->item))
  {
   prev = iter;
   iter = iter->next;
  }
  else
  {
   prev->next = iter->next;
   hs->buk[i] = head.next;
   free(iter);
   hs->nitem--;
   return 0;
  }
 }
 return -1;
}

variable_types: struct entry { struct entry *next; char item[1]; }


decompiled_code:
// attributes: thunk
void hashset_iter_del(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func5(void *ptr)
{
free(ptr);
}

original_code:
void hashset_iter_del(struct hashset_iter * iter)
{
 free(iter);
}

canonical_original_code:
void hashset_iter_del(struct hashset_iter *iter)
{
 free(iter);
}

variable_types: struct hashset_iter { struct hashset { unsigned int size; unsigned int ele_size; unsigned int nitem; struct entry { struct entry *next; char item[1]; } **buk; int (*cmp)(void *, void *); unsigned int (*hash)(void *); } *hs; struct entry *current; struct entry *next; int i; } *

user_defined_types: struct hashset_iter { struct hashset *hs; struct entry *current; struct entry *next; int i; }


decompiled_code:
__int64 __fastcall hashset_iter_next(__int64 a1)
{
_QWORD *v1; // rax
unsigned int v3; // esi
unsigned int v4; // edx
_QWORD **i; // rcx

v1 = *(_QWORD **)(a1 + 16);
if ( v1 )
{
LABEL_2:
*(_QWORD *)(a1 + 8) = v1;
*(_QWORD *)(a1 + 16) = *v1;
return 1LL;
}
v3 = **(_DWORD **)a1;
v4 = *(_DWORD *)(a1 + 24) + 1;
if ( v3 > v4 )
{
for ( i = (_QWORD **)(*(_QWORD *)(*(_QWORD *)a1 + 16LL) + 8LL * v4); ; ++i )
{
v1 = *i;
if ( *i )
break;
if ( v3 <= ++v4 )
return 0LL;
}
*(_DWORD *)(a1 + 24) = v4;
goto LABEL_2;
}
return 0LL;
}

original_code:
int hashset_iter_next(struct hashset_iter * iter)
{
 if(iter->next == ((void *)0))
 {
  struct entry ** buk = iter->hs->buk;
  unsigned size = iter->hs->size;
  for(unsigned i = iter->i + 1; i < size; i++)
  {
   if(buk[i] != ((void *)0))
   {
    iter->i = i;
    iter->next = buk[i];
    break;
   }
  }
  if(iter->next == ((void *)0))
   return 0;
 }
 iter->current = iter->next;
 iter->next = iter->next->next;
 return 1;
}

canonical_original_code:
int hashset_iter_next(struct hashset_iter *iter)
{
 if(iter->next == ((void *)0))
 {
  struct entry **buk = iter->hs->buk;
  unsigned int size = iter->hs->size;
  for(unsigned int i = iter->i + 1; i < size; i++)
  {
   if(buk[i] != ((void *)0))
   {
    iter->i = i;
    iter->next = buk[i];
    break;
   }
  }
  if(iter->next == ((void *)0))
   return 0;
 }
 iter->current = iter->next;
 iter->next = iter->next->next;
 return 1;
}


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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
if ( result )
result += 8LL;
return result;
}

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
if ( result )
result += 8LL;
return result;
}

original_code:
void const * hashset_iter_get(struct hashset_iter * iter)
{
 if(iter != ((void *)0) && iter->current != ((void *)0))
  return iter->current->item;
 else
  return ((void *)0);
}

canonical_original_code:
void *hashset_iter_get(struct hashset_iter *iter)
{
 if(iter != ((void *)0) && iter->current != ((void *)0))
  return iter->current->item;
 else
  return ((void *)0);
}

return_type: void *


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

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

original_code:
static struct token token_new(enum token_type type)
{
 return (struct token){
  .type = type,
  .text = ((void *)0)
 };
}

return_type: struct token { enum token_type { TOKEN_TYPE_SECTION=0, TOKEN_TYPE_NAME=1, TOKEN_TYPE_ASSIGNMENT=2, TOKEN_TYPE_STRING=3, TOKEN_TYPE_NEWLINE=4, TOKEN_TYPE_END=5 } type; char *text; }

user_defined_types: struct token { enum token_type type; char *text; }


init

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

qword_4040A8 = (__int64)&qword_414090;
bot = (__int64)&arena;
result = (unsigned int)((_DWORD)&qword_414090 + 1);
arena = 0LL;
qword_414090 = (__int64)&arena;
LODWORD(qword_4040A8) = (_DWORD)&qword_414090 + 1;
qword_414098 = 0LL;
return result;
}

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

qword_4040A8 = (__int64)&qword_414090;
bot = (__int64)&arena;
result = (unsigned int)((_DWORD)&qword_414090 + 1);
arena = 0LL;
qword_414090 = (__int64)&arena;
LODWORD(qword_4040A8) = (_DWORD)&qword_414090 + 1;
qword_414098 = 0LL;
return result;
}

original_code:
static void init(void)
{
  bot = &arena[0]; top = &arena[(65536/sizeof(CHUNK))-1];
  bot->s.l = 0; bot->s.r = top;
  top->s.l = bot; top->s.r = 0;
  ( *(unsigned *)&(bot)->s.r |= 0x1 ); ( *(unsigned *)&(top)->s.r &= ~0x1 );
}

canonical_original_code:
static void init()
{
  bot = &arena[0]; top = &arena[(65536/sizeof(CHUNK))-1];
  bot->s.l = 0; bot->s.r = top;
  top->s.l = bot; top->s.r = 0;
  ( *(unsigned int *)&(bot)->s.r |= 0x1 ); ( *(unsigned int *)&(top)->s.r &= ~0x1 );
}


tmalloc

decompiled_code:
__int64 __fastcall tmalloc(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 **v3; // rax
__int64 v4; // rcx
unsigned int v5; // eax
int v7; // edi
__int64 *v8; // rcx

v1 = bot;
v2 = 16 * ((unsigned int)(((unsigned __int64)(unsigned int)a1 + 15) >> 4) + 1);
if ( !bot )
{
init(a1, v2);
v1 = bot;
if ( !bot )
return 0LL;
}
while ( 1 )
{
v3 = *(__int64 ***)(v1 + 8);
if ( ((unsigned __int8)v3 & 1) != 0 )
{
v4 = ((unsigned int)v3 & 0xFFFFFFFE) - (unsigned int)v1;
if ( (unsigned int)v4 >= (unsigned int)v2 )
break;
}
v5 = (unsigned int)v3 & 0xFFFFFFFE;
v1 = v5;
if ( !v5 )
return 0LL;
}
if ( (unsigned int)v4 > (unsigned int)v2 )
{
v7 = *(_DWORD *)(v1 + 8);
v8 = (__int64 *)(v1 + v4 - v2);
*v8 = v1;
v8[1] = (__int64)v3;
*(_QWORD *)(v1 + 8) = v8;
*v3 = v8;
*(_DWORD *)(v1 + 8) = v7 | 1;
v1 = (__int64)v8;
}
*(_DWORD *)(v1 + 8) &= 0xFFFFFFFE;
return v1 + 16;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 **v3; // rax
__int64 v4; // rcx
unsigned int v5; // eax
int v7; // edi
__int64 *v8; // rcx

v1 = bot;
v2 = 16 * ((unsigned int)(((unsigned __int64)(unsigned int)a1 + 15) >> 4) + 1);
if ( !bot )
{
func9(a1, v2);
v1 = bot;
if ( !bot )
return 0LL;
}
while ( 1 )
{
v3 = *(__int64 ***)(v1 + 8);
if ( ((unsigned __int8)v3 & 1) != 0 )
{
v4 = ((unsigned int)v3 & 0xFFFFFFFE) - (unsigned int)v1;
if ( (unsigned int)v4 >= (unsigned int)v2 )
break;
}
v5 = (unsigned int)v3 & 0xFFFFFFFE;
v1 = v5;
if ( !v5 )
return 0LL;
}
if ( (unsigned int)v4 > (unsigned int)v2 )
{
v7 = *(_DWORD *)(v1 + 8);
v8 = (__int64 *)(v1 + v4 - v2);
*v8 = v1;
v8[1] = (__int64)v3;
*(_QWORD *)(v1 + 8) = v8;
*v3 = v8;
*(_DWORD *)(v1 + 8) = v7 | 1;
v1 = (__int64)v8;
}
*(_DWORD *)(v1 + 8) &= 0xFFFFFFFE;
return v1 + 16;
}

original_code:
void *tmalloc(unsigned nbytes)
{
  CHUNK *p;
  unsigned size;
  if (bot == 0)
    init();
  size = sizeof(CHUNK) * ((nbytes+sizeof(CHUNK)-1)/sizeof(CHUNK) + 1);
  for (p = bot; p != 0; p = ((CHUNK *)(~0x1 & (unsigned)(p)->s.r)))
    if (( (unsigned)(p)->s.r & 0x1 ) && ((unsigned)((CHUNK *)(~0x1 & (unsigned)((p))->s.r)) - (unsigned)(p)) >= size)
      break;
  if (p == 0)
    return 0;
  if (((unsigned)((CHUNK *)(~0x1 & (unsigned)((p))->s.r)) - (unsigned)(p)) > size)
    {
      CHUNK *q, *pr;
      ( *(unsigned *)&(p)->s.r &= ~0x1 );
      q = (CHUNK *)((char *)p + ((unsigned)((CHUNK *)(~0x1 & (unsigned)((p))->s.r)) - (unsigned)(p)) - size);
      pr = p->s.r;
      q->s.l = p; q->s.r = pr;
      p->s.r = q; pr->s.l = q;
      ( *(unsigned *)&(p)->s.r |= 0x1 );
      p = q;
    }
  ( *(unsigned *)&(p)->s.r &= ~0x1 );
  return ((void *)(1 + (p)));
}

canonical_original_code:
void *tmalloc(unsigned int nbytes)
{
  union CHUNK_TAG *p;
  unsigned int size;
  if (bot == 0)
    init();
  size = sizeof(CHUNK) * ((nbytes+sizeof(CHUNK)-1)/sizeof(CHUNK) + 1);
  for (p = bot; p != 0; p = ((union CHUNK_TAG *)(~0x1 & (unsigned int)(p)->s.r)))
    if (( (unsigned int)(p)->s.r & 0x1 ) && ((unsigned int)((union CHUNK_TAG *)(~0x1 & (unsigned int)((p))->s.r)) - (unsigned int)(p)) >= size)
      break;
  if (p == 0)
    return 0;
  if (((unsigned int)((union CHUNK_TAG *)(~0x1 & (unsigned int)((p))->s.r)) - (unsigned int)(p)) > size)
    {
      union CHUNK_TAG *q; union CHUNK_TAG *pr;
      ( *(unsigned int *)&(p)->s.r &= ~0x1 );
      q = (union CHUNK_TAG *)((char *)p + ((unsigned int)((union CHUNK_TAG *)(~0x1 & (unsigned int)((p))->s.r)) - (unsigned int)(p)) - size);
      pr = p->s.r;
      q->s.l = p; q->s.r = pr;
      p->s.r = q; pr->s.l = q;
      ( *(unsigned int *)&(p)->s.r |= 0x1 );
      p = q;
    }
  ( *(unsigned int *)&(p)->s.r &= ~0x1 );
  return ((void *)(1 + (p)));
}

variable_types:
nbytes
unsigned int

variable_types: union CHUNK_TAG { struct { union CHUNK_TAG *l; union CHUNK_TAG *r; } s; double x; } *


tfree

canonical_original_code:
void tfree(void *vp)
{
  union CHUNK_TAG *p; union CHUNK_TAG *q;
  if (vp == 0)
    return;
  p = (-1 + (union CHUNK_TAG *)(vp));
  ( *(unsigned int *)&(p)->s.r &= ~0x1 );
  q = p->s.l;
  if (q != 0 && ( (unsigned int)(q)->s.r & 0x1 ))
    {
      ( *(unsigned int *)&(q)->s.r &= ~0x1 );
      q->s.r = p->s.r;
      p->s.r->s.l = q;
      ( *(unsigned int *)&(q)->s.r |= 0x1 );
      p = q;
    }
  q = ((union CHUNK_TAG *)(~0x1 & (unsigned int)(p)->s.r));
  if (q != 0 && ( (unsigned int)(q)->s.r & 0x1 ))
    {
      ( *(unsigned int *)&(q)->s.r &= ~0x1 );
      p->s.r = q->s.r;
      q->s.r->s.l = p;
      ( *(unsigned int *)&(q)->s.r |= 0x1 );
    }
  ( *(unsigned int *)&(p)->s.r |= 0x1 );
}

variable_types:
vp
void *

user_defined_types: union CHUNK_TAG { struct { union CHUNK_TAG *l; union CHUNK_TAG *r; } s; double x; }


trealloc

decompiled_code:
void *__fastcall trealloc(void *src, unsigned int a2)
{
void *v2; // r12
void *v4; // rax
size_t v5; // r8
size_t v6; // rdx

if ( src )
{
if ( a2 )
{
v4 = (void *)tmalloc(a2);
v2 = v4;
if ( !v4 )
return v2;
v6 = (*((_DWORD *)src - 2) & 0xFFFFFFFE) - (unsigned int)src;
if ( (unsigned int)v5 <= (unsigned int)v6 )
v6 = v5;
memcpy(v4, src, v6);
}
else
{
v2 = 0LL;
}
tfree((__int64)src);
return v2;
}
return (void *)tmalloc(a2);
}

canonical_decompiled_code:
void *__fastcall func12(void *src, unsigned int a2)
{
void *v2; // r12
void *v4; // rax
size_t v5; // r8
size_t v6; // rdx

if ( src )
{
if ( a2 )
{
v4 = (void *)func10(a2);
v2 = v4;
if ( !v4 )
return v2;
v6 = (*((_DWORD *)src - 2) & 0xFFFFFFFE) - (unsigned int)src;
if ( (unsigned int)v5 <= (unsigned int)v6 )
v6 = v5;
memcpy(v4, src, v6);
}
else
{
v2 = 0LL;
}
func11((__int64)src);
return v2;
}
return (void *)func10(a2);
}

original_code:
void *trealloc(void *vp, unsigned newbytes)
{
  void *newp = 0;
  if (vp == 0)
    return tmalloc(newbytes);
  if (newbytes != 0)
    {
      CHUNK *oldchunk;
      unsigned bytes;
      if ( (newp = tmalloc(newbytes)) == 0)
        return 0;
      oldchunk = (-1 + (CHUNK *)(vp));
      bytes = ((unsigned)((CHUNK *)(~0x1 & (unsigned)((oldchunk))->s.r)) - (unsigned)(oldchunk)) - sizeof(CHUNK);
      if (bytes > newbytes)
        bytes = newbytes;
      memcpy(newp, vp, bytes);
    }
  tfree(vp);
  return newp;
}

canonical_original_code:
void *trealloc(void *vp, unsigned int newbytes)
{
  void *newp = 0;
  if (vp == 0)
    return tmalloc(newbytes);
  if (newbytes != 0)
    {
      union CHUNK_TAG *oldchunk;
      unsigned int bytes;
      if ( (newp = tmalloc(newbytes)) == 0)
        return 0;
      oldchunk = (-1 + (union CHUNK_TAG *)(vp));
      bytes = ((unsigned int)((union CHUNK_TAG *)(~0x1 & (unsigned int)((oldchunk))->s.r)) - (unsigned int)(oldchunk)) - sizeof(CHUNK);
      if (bytes > newbytes)
        bytes = newbytes;
      memcpy(newp, vp, bytes);
    }
  tfree(vp);
  return newp;
}

variable_types:
newbytes
unsigned int

variable_types:
newp
void *

variable_types:
bytes
unsigned int


tcalloc

decompiled_code:
void *__fastcall tcalloc(int a1, int a2)
{
void *v2; // rax
unsigned int v3; // er8
void *v4; // r9

v2 = (void *)tmalloc((unsigned int)(a2 * a1));
v4 = v2;
if ( v2 )
v4 = memset(v2, 0, v3);
return v4;
}

canonical_decompiled_code:
void *__fastcall func13(int a1, int a2)
{
void *v2; // rax
unsigned int v3; // er8
void *v4; // r9

v2 = (void *)func10((unsigned int)(a2 * a1));
v4 = v2;
if ( v2 )
v4 = memset(v2, 0, v3);
return v4;
}

original_code:
void *tcalloc(unsigned nelem, unsigned elsize)
{
  void *vp;
  unsigned nbytes;
  nbytes = nelem * elsize;
  if ( (vp = tmalloc(nbytes)) == 0)
    return 0;
  memset(vp, '\0', nbytes);
  return vp;
}

canonical_original_code:
void *tcalloc(unsigned int nelem, unsigned int elsize)
{
  void *vp;
  unsigned int nbytes;
  nbytes = nelem * elsize;
  if ( (vp = tmalloc(nbytes)) == 0)
    return 0;
  memset(vp, '\0', nbytes);
  return vp;
}

variable_types:
nelem
unsigned int

variable_types:
elsize
unsigned int


nstrcpy

decompiled_code:
size_t __fastcall nstrcpy(__int64 a1, int a2, const char *a3)
{
size_t result; // rax
__int64 v5; // rdx
size_t v6; // rcx

result = strlen(a3);
if ( (int)result > a2 )
result = (unsigned int)a2;
if ( (result & 0x80000000) == 0LL )
{
v5 = (int)result;
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = a3[result];
v6 = result++;
}
while ( v6 != v5 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, int a2, const char *a3)
{
size_t result; // rax
__int64 v5; // rdx
size_t v6; // rcx

result = strlen(a3);
if ( (int)result > a2 )
result = (unsigned int)a2;
if ( (result & 0x80000000) == 0LL )
{
v5 = (int)result;
result = 0LL;
do
{
*(_BYTE *)(a1 + result) = a3[result];
v6 = result++;
}
while ( v6 != v5 );
}
return result;
}

original_code:
void nstrcpy(char *out, int outl, char *in)
{
  int i, len;
  len = strlen(in);
  if (len > outl)
    len = outl;
  for (i = 0; i <= len; i++)
    out[i] = in[i];
}

canonical_original_code:
void nstrcpy(char *out, int outl, char *in)
{
  int i; int len;
  len = strlen(in);
  if (len > outl)
    len = outl;
  for (i = 0; i <= len; i++)
    out[i] = in[i];
}

variable_types:
out
char *

variable_types: outl int

variable_types:
in
char *

variable_types: i int

variable_types: len int


bar

decompiled_code:
size_t __fastcall bar(const char *a1)
{
__int64 v2; // [rsp+0h] [rbp-D8h] BYREF

return nstrcpy((__int64)&v2, 200, a1);
}

canonical_decompiled_code:
size_t __fastcall func8(const char *a1)
{
__int64 v2; // [rsp+0h] [rbp-D8h] BYREF

return func7((__int64)&v2, 200, a1);
}

original_code:
void bar(char *arg)
{
  char buf[200];
  nstrcpy(buf, sizeof buf, arg);
}

variable_types:
arg
char *

variable_types:
buf
char [200]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc != 2 )
{
fwrite("target2: argc != 2\n", 1uLL, 0x13uLL, _bss_start);
exit(1);
}
foo(argv[1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc != 2 )
{
fwrite("target2: argc != 2\n", 1uLL, 0x13uLL, _bss_start);
exit(1);
}
func9(argv[1]);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  if (argc != 2)
    {
      fprintf(stderr, "target2: argc != 2\n");
      exit(1);
    }
  foo(argv[1]);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


foo

decompiled_code:
// attributes: thunk
size_t __fastcall foo(const char *a1)
{
return bar(a1);
}

canonical_decompiled_code:
size_t __fastcall func9(const char *a1)
{
return func8(a1);
}

original_code:
void foo(char *arg)
{
  bar(arg);
}

canonical_original_code:
void foo(char *arg)
{
  bar(arg);
}