decompiled_code:
void __fastcall insertion_sort3(unsigned __int64 a1, __int64 a2, __int64 a3)
{
_DWORD *v3; // rsi
int v4; // ecx
_DWORD *i; // rax

if ( a2 != a3 )
{
v3 = (_DWORD *)(a2 - 4);
do
{
v4 = v3[1];
for ( i = v3; a1 <= (unsigned __int64)i; --i )
{
if ( *i <= v4 )
break;
i[1] = *i;
}
++v3;
i[1] = v4;
}
while ( v3 != (_DWORD *)(a3 - 4) );
}
}

original_code:
void insertion_sort3(int32_t *sorted_begin,int32_t *unsorted_begin,int32_t *unsorted_end)
{
 if(unsorted_begin != unsorted_end)
 {
  int32_t *scanner = ((void *)0);
  int32_t value = *unsorted_begin;
  for(scanner = unsorted_begin - 1; scanner >= sorted_begin &&
    *scanner > value; --scanner)
  {
   *(scanner + 1) = *scanner;
  }
  *++scanner = value;
  insertion_sort3(sorted_begin,unsorted_begin + 1,unsorted_end);
 }
}

canonical_original_code:
void insertion_sort3(int *sorted_begin, int *unsorted_begin, int *unsorted_end)
{
 if(unsorted_begin != unsorted_end)
 {
  int *scanner = ((void *)0);
  int value = *unsorted_begin;
  for(scanner = unsorted_begin - 1; scanner >= sorted_begin &&
    *scanner > value; --scanner)
  {
   *(scanner + 1) = *scanner;
  }
  *++scanner = value;
  insertion_sort3(sorted_begin,unsorted_begin + 1,unsorted_end);
 }
}

variable_types:
scanner
int *


repo: QMonkey/ACM-ICPC

decompiled_code:
void __fastcall insertion_sort(unsigned __int64 a1, __int64 a2)
{
insertion_sort3(a1, a1 + 4, a2);
}

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

original_code:
void insertion_sort(int32_t *begin,int32_t *end)
{
 insertion_sort3(begin,begin + 1,end);
}

canonical_original_code:
void insertion_sort(int *begin, int *end)
{
 insertion_sort3(begin,begin + 1,end);
}

variable_types:
begin
int *

variable_types:
end
int *

return_type: void


decompiled_code:
__int64 __fastcall dp_min_matrix_multiplication4(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4)
{
unsigned int v5; // er14
unsigned int v6; // er13
_DWORD *v7; // rbp
unsigned int v8; // er14
__int64 v9; // rbx
_DWORD *v10; // r12
int v11; // er12
unsigned int v12; // er12
unsigned int v14; // [rsp+4h] [rbp-64h]
_DWORD *v16; // [rsp+20h] [rbp-48h]
unsigned int v17; // [rsp+28h] [rbp-40h]

v5 = 0;
v6 = ((a3 - a1) >> 2) - 1;
v17 = ((__int64)a2 - a1) >> 2;
if ( (int)(v6 - v17) > 1 )
{
v7 = a2 + 1;
v5 = -1;
v16 = (_DWORD *)(a3 - 4);
if ( (_DWORD *)(a3 - 4) != a2 + 1 )
{
v14 = -1;
v8 = ((__int64)a2 - a1) >> 2;
do
{
v9 = ((__int64)v7 - a1) >> 2;
v10 = v7++;
if ( !(unsigned int)isset_resultset(a4, v8, (unsigned int)v9) )
dp_min_matrix_multiplication4(a1, a2, v7, a4);
if ( !(unsigned int)isset_resultset(a4, (unsigned int)v9, v6) )
dp_min_matrix_multiplication4(a1, v10, a3, a4);
v11 = get_resultset(a4, v8, (unsigned int)v9);
v12 = *(v7 - 1) * *(_DWORD *)(a3 - 4) * *a2 + get_resultset(a4, (unsigned int)v9, v6) + v11;
if ( v14 <= v12 )
v12 = v14;
v14 = v12;
}
while ( v16 != v7 );
v5 = v12;
}
set_resultset(a4, v17, v6, v5);
}
return v5;
}

original_code:
uint32_t dp_min_matrix_multiplication4(uint32_t *m_chain,uint32_t *begin,uint32_t *end,resultset_t *rs)
{
 int32_t x = begin - m_chain;
 int32_t y = end - m_chain - 1;
 if(y - x < 2)
 {
  return 0;
 }
 uint32_t min = (4294967295U);
 uint32_t *splitter = ((void *)0);
 uint32_t *splitter_end = end - 1;
 for(splitter = begin + 1; splitter != splitter_end; ++splitter)
 {
  int32_t splitter_index = splitter - m_chain;
  if(!isset_resultset(rs,x,splitter_index))
  {
   dp_min_matrix_multiplication4(m_chain,begin,splitter + 1,rs);
  }
  if(!isset_resultset(rs,splitter_index,y))
  {
   dp_min_matrix_multiplication4(m_chain,splitter,end,rs);
  }
  uint32_t left_times = get_resultset(rs,x,splitter_index);
  uint32_t right_times = get_resultset(rs,splitter_index,y);
  uint32_t times = left_times + right_times + *begin * *splitter * *(end - 1);
  if(min > times)
  {
   min = times;
  }
 }
 set_resultset(rs,x,y,min);
 return min;
}

canonical_original_code:
unsigned int dp_min_matrix_multiplication4(unsigned int *m_chain, unsigned int *begin, unsigned int *end, struct resultset_t *rs)
{
 int x = begin - m_chain;
 int y = end - m_chain - 1;
 if(y - x < 2)
 {
  return 0;
 }
 unsigned int min = (4294967295U);
 unsigned int *splitter = ((void *)0);
 unsigned int *splitter_end = end - 1;
 for(splitter = begin + 1; splitter != splitter_end; ++splitter)
 {
  int splitter_index = splitter - m_chain;
  if(!isset_resultset(rs,x,splitter_index))
  {
   dp_min_matrix_multiplication4(m_chain,begin,splitter + 1,rs);
  }
  if(!isset_resultset(rs,splitter_index,y))
  {
   dp_min_matrix_multiplication4(m_chain,splitter,end,rs);
  }
  unsigned int left_times = get_resultset(rs,x,splitter_index);
  unsigned int right_times = get_resultset(rs,splitter_index,y);
  unsigned int times = left_times + right_times + *begin * *splitter * *(end - 1);
  if(min > times)
  {
   min = times;
  }
 }
 set_resultset(rs,x,y,min);
 return min;
}

variable_types:
begin
unsigned int *

variable_types:
end
unsigned int *

variable_types: struct resultset_t { unsigned int *resultset; int *resultset_flag; unsigned int size; } *

variable_types: x int

variable_types: y int

variable_types:
min
unsigned int

variable_types:
splitter
unsigned int *

variable_types:
times
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall min_matrix_multiplication(_DWORD *a1, __int64 a2)
{
unsigned int v2; // er14
_DWORD *v3; // r13
_DWORD *v4; // rbp
int v5; // er12
unsigned int v6; // eax

v2 = 0;
if ( a2 - (__int64)a1 > 8 )
{
v3 = a1 + 1;
v2 = -1;
if ( (_DWORD *)(a2 - 4) != a1 + 1 )
{
do
{
v4 = v3++;
v5 = min_matrix_multiplication(a1, v3);
v6 = min_matrix_multiplication(v4, a2) + v5 + *(v3 - 1) * *(_DWORD *)(a2 - 4) * *a1;
if ( v2 > v6 )
v2 = v6;
}
while ( v3 != (_DWORD *)(a2 - 4) );
}
}
return v2;
}

original_code:
uint32_t min_matrix_multiplication(uint32_t *begin,uint32_t *end)
{
 if(end - begin < 3)
 {
  return 0;
 }
 uint32_t min = (4294967295U);
 uint32_t *splitter = ((void *)0);
 uint32_t *splitter_end = end - 1;
 for(splitter = begin + 1; splitter != splitter_end; ++splitter)
 {
  uint32_t times = min_matrix_multiplication(begin,splitter+1) +
   min_matrix_multiplication(splitter,end) + *begin * *splitter * *(end-1);
  if(min > times)
  {
   min = times;
  }
 }
 return min;
}

canonical_original_code:
unsigned int min_matrix_multiplication(unsigned int *begin, unsigned int *end)
{
 if(end - begin < 3)
 {
  return 0;
 }
 unsigned int min = (4294967295U);
 unsigned int *splitter = ((void *)0);
 unsigned int *splitter_end = end - 1;
 for(splitter = begin + 1; splitter != splitter_end; ++splitter)
 {
  unsigned int times = min_matrix_multiplication(begin,splitter+1) +
   min_matrix_multiplication(splitter,end) + *begin * *splitter * *(end-1);
  if(min > times)
  {
   min = times;
  }
 }
 return min;
}


decompiled_code:
__int64 __fastcall dp_min_matrix_multiplication(_DWORD *a1, __int64 a2)
{
void *v2; // r12
unsigned int v3; // er13

v2 = (void *)create_resultset((a2 - (__int64)a1) >> 2);
v3 = dp_min_matrix_multiplication4((__int64)a1, a1, a2, (__int64)v2);
destroy_resultset(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, __int64 a2)
{
void *v2; // r12
unsigned int v3; // er13

v2 = (void *)create_resultset((a2 - (__int64)a1) >> 2);
v3 = func7((__int64)a1, a1, a2, (__int64)v2);
func15(v2);
return v3;
}

original_code:
uint32_t dp_min_matrix_multiplication(uint32_t *begin,uint32_t *end)
{
 resultset_t *rs = create_resultset(end - begin);
 uint32_t res = dp_min_matrix_multiplication4(begin,begin,end,rs);
 destroy_resultset(rs);
 return res;
}

canonical_original_code:
unsigned int dp_min_matrix_multiplication(unsigned int *begin, unsigned int *end)
{
 struct resultset_t *rs = create_resultset(end - begin);
 unsigned int res = dp_min_matrix_multiplication4(begin,begin,end,rs);
 destroy_resultset(rs);
 return res;
}

variable_types:
res
unsigned int

user_defined_types: struct resultset_t { unsigned int *resultset; int *resultset_flag; unsigned int size; }


decompiled_code:
void *__fastcall init_resultset(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4 * *(unsigned int *)(a1 + 16) * (unsigned __int64)*(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, int a2)
{
return memset(*(void **)(a1 + 8), a2, 4 * *(unsigned int *)(a1 + 16) * (unsigned __int64)*(unsigned int *)(a1 + 16));
}

original_code:
void init_resultset(resultset_t *rs,int value)
{
 uint32_t size = rs->size;
 memset(rs->resultset_flag,value,sizeof(int) * size * size);
}

canonical_original_code:
void init_resultset(struct resultset_t *rs, int value)
{
 unsigned int size = rs->size;
 memset(rs->resultset_flag,value,sizeof(int) * size * size);
}

variable_types: value int

variable_types:
size
unsigned int


decompiled_code:
__int64 __fastcall index_resultset(__int64 a1, int a2, int a3)
{
return (unsigned int)(*(_DWORD *)(a1 + 16) * a2 + a3);
}

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

original_code:
int32_t index_resultset(resultset_t *rs,int32_t x,int32_t y)
{
 return x * rs->size + y;
}

canonical_original_code:
int index_resultset(struct resultset_t *rs, int x, int y)
{
 return x * rs->size + y;
}

return_type: int


decompiled_code:
__int64 __fastcall get_resultset(_QWORD *a1, int a2, int a3)
{
return *(unsigned int *)(*a1 + 4LL * (int)index_resultset((__int64)a1, a2, a3));
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, int a2, int a3)
{
return *(unsigned int *)(*a1 + 4LL * (int)func11((__int64)a1, a2, a3));
}

original_code:
uint32_t get_resultset(resultset_t *rs,int32_t x,int32_t y)
{
 return rs->resultset[index_resultset(rs,x,y)];
}

canonical_original_code:
unsigned int get_resultset(struct resultset_t *rs, int x, int y)
{
 return rs->resultset[index_resultset(rs,x,y)];
}


decompiled_code:
__int64 __fastcall isset_resultset(__int64 a1, int a2, int a3)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (int)index_resultset(a1, a2, a3));
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2, int a3)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 8) + 4LL * (int)func11(a1, a2, a3));
}

original_code:
int isset_resultset(resultset_t *rs,int32_t x,int32_t y)
{
 return rs->resultset_flag[index_resultset(rs,x,y)];
}

canonical_original_code:
int isset_resultset(struct resultset_t *rs, int x, int y)
{
 return rs->resultset_flag[index_resultset(rs,x,y)];
}


decompiled_code:
__int64 __fastcall destroy_resultset(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int destroy_resultset(resultset_t *rs)
{
 if(rs == ((void *)0))
 {
  return -1;
 }
 free(rs->resultset);
 free(rs->resultset_flag);
 free(rs);
 return 0;
}

canonical_original_code:
int destroy_resultset(struct resultset_t *rs)
{
 if(rs == ((void *)0))
 {
  return -1;
 }
 free(rs->resultset);
 free(rs->resultset_flag);
 free(rs);
 return 0;
}


permutation

decompiled_code:
int __fastcall permutation(_BYTE *a1, _BYTE *a2)
{
_BYTE *v3; // rbx
__int64 v4; // rdx
_BYTE *v5; // rsi
int result; // eax

v3 = a1;
if ( a1 == a2 )
return fprintf(_bss_start, "%s\n", a1 - 3);
do
{
swap(a1, v3);
permutation(a1 + 1, a2, v4);
v5 = v3++;
result = swap(a1, v5);
}
while ( a2 != v3 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(_BYTE *a1, _BYTE *a2)
{
_BYTE *v3; // rbx
__int64 v4; // rdx
_BYTE *v5; // rsi
int result; // eax

v3 = a1;
if ( a1 == a2 )
return fprintf(_bss_start, "%s\n", a1 - 3);
do
{
func7(a1, v3);
func8(a1 + 1, a2, v4);
v5 = v3++;
result = func7(a1, v5);
}
while ( a2 != v3 );
return result;
}

original_code:
extern void permutation(char *begin,char *end)
{
 if(begin == end)
 {
  begin -= 3;
  fprintf(stdout,"%s\n",begin);
  return;
 }
 char *current = begin;
 for( ; current != end; ++current)
 {
  swap(begin,current);
  permutation(begin+1,end);
  swap(begin,current);
 }
}

canonical_original_code:
extern void permutation(char *begin, char *end)
{
 if(begin == end)
 {
  begin -= 3;
  fprintf(stdout,"%s\n",begin);
  return;
 }
 char *current = begin;
 for( ; current != end; ++current)
 {
  swap(begin,current);
  permutation(begin+1,end);
  swap(begin,current);
 }
}

variable_types:
begin
char *

variable_types:
end
char *

variable_types:
current
char *


swap

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

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
static void swap(char *first,char *second)
{
 char ch = *first;
 *first = *second;
 *second = ch;
}

canonical_original_code:
static void swap(char *first, char *second)
{
 char ch = *first;
 *first = *second;
 *second = ch;
}

variable_types:
first
char *

variable_types:
second
char *

variable_types: ch char


decompiled_code:
void __fastcall chess_board(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // eax
__int64 v5; // rdx
__int64 v6; // [rsp+0h] [rbp-68h] BYREF
unsigned int v7; // [rsp+8h] [rbp-60h]
__int64 v8; // [rsp+10h] [rbp-58h] BYREF
__int64 v9; // [rsp+18h] [rbp-50h] BYREF
__int64 v10; // [rsp+20h] [rbp-48h] BYREF
__int64 v11; // [rsp+28h] [rbp-40h] BYREF
__int64 v12; // [rsp+30h] [rbp-38h] BYREF
unsigned int v13; // [rsp+38h] [rbp-30h]
__int64 v14; // [rsp+3Ch] [rbp-2Ch] BYREF
unsigned int v15; // [rsp+44h] [rbp-24h]
__int64 v16; // [rsp+48h] [rbp-20h] BYREF
unsigned int v17; // [rsp+50h] [rbp-18h]
__int64 v18; // [rsp+54h] [rbp-14h] BYREF
unsigned int v19; // [rsp+5Ch] [rbp-Ch]

v6 = a1;
v7 = a2;
if ( a2 != 1 )
{
center_pos_isra_0(v6, SHIDWORD(v6), a2, 0, &v8);
center_pos_isra_0(v6, SHIDWORD(v6), v7, 1, &v9);
center_pos_isra_0(v6, SHIDWORD(v6), v7, 2, &v10);
center_pos_isra_0(v6, SHIDWORD(v6), v7, 3, &v11);
v4 = point_pos_isra_0(v6, SHIDWORD(v6), v7, a3, HIDWORD(a3));
if ( v4 == 2 )
{
print_pos_isra_0(v8, HIDWORD(v8));
print_pos_isra_0(v9, HIDWORD(v9));
print_pos_isra_0(v11, HIDWORD(v11));
fputc(10, _bss_start);
subarea((int *)&v6, 0, (unsigned int *)&v12);
subarea((int *)&v6, 1, (unsigned int *)&v14);
subarea((int *)&v6, 2, (unsigned int *)&v16);
subarea((int *)&v6, 3, (unsigned int *)&v18);
chess_board(v12, v13, v8);
chess_board(v14, v15, v9);
v5 = a3;
LABEL_7:
chess_board(v16, v17, v5);
chess_board(v18, v19, v11);
return;
}
if ( v4 <= 2 )
{
if ( v4 )
{
print_pos_isra_0(v8, HIDWORD(v8));
print_pos_isra_0(v10, HIDWORD(v10));
print_pos_isra_0(v11, HIDWORD(v11));
fputc(10, _bss_start);
subarea((int *)&v6, 0, (unsigned int *)&v12);
subarea((int *)&v6, 1, (unsigned int *)&v14);
subarea((int *)&v6, 2, (unsigned int *)&v16);
subarea((int *)&v6, 3, (unsigned int *)&v18);
chess_board(v12, v13, v8);
chess_board(v14, v15, a3);
}
else
{
print_pos_isra_0(v9, HIDWORD(v9));
print_pos_isra_0(v10, HIDWORD(v10));
print_pos_isra_0(v11, HIDWORD(v11));
fputc(10, _bss_start);
subarea((int *)&v6, 0, (unsigned int *)&v12);
subarea((int *)&v6, 1, (unsigned int *)&v14);
subarea((int *)&v6, 2, (unsigned int *)&v16);
subarea((int *)&v6, 3, (unsigned int *)&v18);
chess_board(v12, v13, a3);
chess_board(v14, v15, v9);
}
v5 = v10;
goto LABEL_7;
}
if ( v4 == 3 )
{
print_pos_isra_0(v8, HIDWORD(v8));
print_pos_isra_0(v9, HIDWORD(v9));
print_pos_isra_0(v10, HIDWORD(v10));
fputc(10, _bss_start);
subarea((int *)&v6, 0, (unsigned int *)&v12);
subarea((int *)&v6, 1, (unsigned int *)&v14);
subarea((int *)&v6, 2, (unsigned int *)&v16);
subarea((int *)&v6, 3, (unsigned int *)&v18);
chess_board(v12, v13, v8);
chess_board(v14, v15, v9);
chess_board(v16, v17, v10);
chess_board(v18, v19, a3);
}
else
{
subarea((int *)&v6, 0, (unsigned int *)&v12);
subarea((int *)&v6, 1, (unsigned int *)&v14);
subarea((int *)&v6, 2, (unsigned int *)&v16);
subarea((int *)&v6, 3, (unsigned int *)&v18);
}
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // eax
__int64 v5; // rdx
__int64 v6; // [rsp+0h] [rbp-68h] BYREF
unsigned int v7; // [rsp+8h] [rbp-60h]
__int64 v8; // [rsp+10h] [rbp-58h] BYREF
__int64 v9; // [rsp+18h] [rbp-50h] BYREF
__int64 v10; // [rsp+20h] [rbp-48h] BYREF
__int64 v11; // [rsp+28h] [rbp-40h] BYREF
__int64 v12; // [rsp+30h] [rbp-38h] BYREF
unsigned int v13; // [rsp+38h] [rbp-30h]
__int64 v14; // [rsp+3Ch] [rbp-2Ch] BYREF
unsigned int v15; // [rsp+44h] [rbp-24h]
__int64 v16; // [rsp+48h] [rbp-20h] BYREF
unsigned int v17; // [rsp+50h] [rbp-18h]
__int64 v18; // [rsp+54h] [rbp-14h] BYREF
unsigned int v19; // [rsp+5Ch] [rbp-Ch]

v6 = a1;
v7 = a2;
if ( a2 != 1 )
{
func9(v6, SHIDWORD(v6), a2, 0, &v8);
func9(v6, SHIDWORD(v6), v7, 1, &v9);
func9(v6, SHIDWORD(v6), v7, 2, &v10);
func9(v6, SHIDWORD(v6), v7, 3, &v11);
v4 = func10(v6, SHIDWORD(v6), v7, a3, HIDWORD(a3));
if ( v4 == 2 )
{
func8(v8, HIDWORD(v8));
func8(v9, HIDWORD(v9));
func8(v11, HIDWORD(v11));
fputc(10, _bss_start);
func7((int *)&v6, 0, (unsigned int *)&v12);
func7((int *)&v6, 1, (unsigned int *)&v14);
func7((int *)&v6, 2, (unsigned int *)&v16);
func7((int *)&v6, 3, (unsigned int *)&v18);
func11(v12, v13, v8);
func11(v14, v15, v9);
v5 = a3;
LABEL_7:
func11(v16, v17, v5);
func11(v18, v19, v11);
return;
}
if ( v4 <= 2 )
{
if ( v4 )
{
func8(v8, HIDWORD(v8));
func8(v10, HIDWORD(v10));
func8(v11, HIDWORD(v11));
fputc(10, _bss_start);
func7((int *)&v6, 0, (unsigned int *)&v12);
func7((int *)&v6, 1, (unsigned int *)&v14);
func7((int *)&v6, 2, (unsigned int *)&v16);
func7((int *)&v6, 3, (unsigned int *)&v18);
func11(v12, v13, v8);
func11(v14, v15, a3);
}
else
{
func8(v9, HIDWORD(v9));
func8(v10, HIDWORD(v10));
func8(v11, HIDWORD(v11));
fputc(10, _bss_start);
func7((int *)&v6, 0, (unsigned int *)&v12);
func7((int *)&v6, 1, (unsigned int *)&v14);
func7((int *)&v6, 2, (unsigned int *)&v16);
func7((int *)&v6, 3, (unsigned int *)&v18);
func11(v12, v13, a3);
func11(v14, v15, v9);
}
v5 = v10;
goto LABEL_7;
}
if ( v4 == 3 )
{
func8(v8, HIDWORD(v8));
func8(v9, HIDWORD(v9));
func8(v10, HIDWORD(v10));
fputc(10, _bss_start);
func7((int *)&v6, 0, (unsigned int *)&v12);
func7((int *)&v6, 1, (unsigned int *)&v14);
func7((int *)&v6, 2, (unsigned int *)&v16);
func7((int *)&v6, 3, (unsigned int *)&v18);
func11(v12, v13, v8);
func11(v14, v15, v9);
func11(v16, v17, v10);
func11(v18, v19, a3);
}
else
{
func7((int *)&v6, 0, (unsigned int *)&v12);
func7((int *)&v6, 1, (unsigned int *)&v14);
func7((int *)&v6, 2, (unsigned int *)&v16);
func7((int *)&v6, 3, (unsigned int *)&v18);
}
}
}

original_code:
void chess_board(Area area,Pos pos)
{
 if(area.size == 1)
 {
  return;
 }
 Pos poslt,posrt,poslb,posrb;
 center_pos(&area,0,&poslt);
 center_pos(&area,1,&posrt);
 center_pos(&area,2,&poslb);
 center_pos(&area,3,&posrb);
 uint32_t pnum = point_pos(&area,&pos);
 switch(pnum)
 {
 case 0:
  print_pos(&posrt);
  print_pos(&poslb);
  print_pos(&posrb);
  fprintf(stdout,"\n");
  break;
 case 1:
  print_pos(&poslt);
  print_pos(&poslb);
  print_pos(&posrb);
  fprintf(stdout,"\n");
  break;
 case 2:
  print_pos(&poslt);
  print_pos(&posrt);
  print_pos(&posrb);
  fprintf(stdout,"\n");
  break;
 case 3:
  print_pos(&poslt);
  print_pos(&posrt);
  print_pos(&poslb);
  fprintf(stdout,"\n");
  break;
 default:
  break;
 }
 Area arealt,areart,arealb,arearb;
 subarea(&area,0,&arealt);
 subarea(&area,1,&areart);
 subarea(&area,2,&arealb);
 subarea(&area,3,&arearb);
 switch(pnum)
 {
 case 0:
  chess_board(arealt,pos);
  chess_board(areart,posrt);
  chess_board(arealb,poslb);
  chess_board(arearb,posrb);
  break;
 case 1:
  chess_board(arealt,poslt);
  chess_board(areart,pos);
  chess_board(arealb,poslb);
  chess_board(arearb,posrb);
  break;
 case 2:
  chess_board(arealt,poslt);
  chess_board(areart,posrt);
  chess_board(arealb,pos);
  chess_board(arearb,posrb);
  break;
 case 3:
  chess_board(arealt,poslt);
  chess_board(areart,posrt);
  chess_board(arealb,poslb);
  chess_board(arearb,pos);
  break;
 default:
  break;
 }
}

canonical_original_code:
void chess_board(struct Area area, struct Pos pos)
{
 if(area.size == 1)
 {
  return;
 }
 struct Pos poslt; struct Pos posrt; struct Pos poslb; struct Pos posrb;
 center_pos(&area,0,&poslt);
 center_pos(&area,1,&posrt);
 center_pos(&area,2,&poslb);
 center_pos(&area,3,&posrb);
 unsigned int pnum = point_pos(&area,&pos);
 switch(pnum)
 {
 case 0:
  print_pos(&posrt);
  print_pos(&poslb);
  print_pos(&posrb);
  fprintf(stdout,"\n");
  break;
 case 1:
  print_pos(&poslt);
  print_pos(&poslb);
  print_pos(&posrb);
  fprintf(stdout,"\n");
  break;
 case 2:
  print_pos(&poslt);
  print_pos(&posrt);
  print_pos(&posrb);
  fprintf(stdout,"\n");
  break;
 case 3:
  print_pos(&poslt);
  print_pos(&posrt);
  print_pos(&poslb);
  fprintf(stdout,"\n");
  break;
 default:
  break;
 }
 struct Area arealt; struct Area areart; struct Area arealb; struct Area arearb;
 subarea(&area,0,&arealt);
 subarea(&area,1,&areart);
 subarea(&area,2,&arealb);
 subarea(&area,3,&arearb);
 switch(pnum)
 {
 case 0:
  chess_board(arealt,pos);
  chess_board(areart,posrt);
  chess_board(arealb,poslb);
  chess_board(arearb,posrb);
  break;
 case 1:
  chess_board(arealt,poslt);
  chess_board(areart,pos);
  chess_board(arealb,poslb);
  chess_board(arearb,posrb);
  break;
 case 2:
  chess_board(arealt,poslt);
  chess_board(areart,posrt);
  chess_board(arealb,pos);
  chess_board(arearb,posrb);
  break;
 case 3:
  chess_board(arealt,poslt);
  chess_board(areart,posrt);
  chess_board(arealb,poslb);
  chess_board(arearb,pos);
  break;
 default:
  break;
 }
}

variable_types: struct Area { struct Pos { unsigned int x; unsigned int y; } begin; unsigned int size; }

variable_types:
pos
struct Pos

variable_types:
pnum
unsigned int

user_defined_types: struct Area { struct Pos begin; unsigned int size; }


decompiled_code:
__int64 __fastcall integer_division(unsigned int a1, unsigned int a2)
{
bool v4; // r12
int v5; // er13
__int64 v7; // rsi
__int64 v8; // rdi

v4 = a1 == 1;
v5 = 0;
LABEL_3:
if ( a2 != 1 )
{
while ( !v4 )
{
if ( a1 < a2 )
{
a2 = a1;
goto LABEL_3;
}
if ( a1 != a2 )
{
v7 = a2;
v8 = a1 - a2--;
v5 += integer_division(v8, v7);
goto LABEL_3;
}
a2 = a1 - 1;
++v5;
if ( a1 == 2 )
return (unsigned int)(v5 + 1);
}
}
return (unsigned int)(v5 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
bool v4; // r12
int v5; // er13
__int64 v7; // rsi
__int64 v8; // rdi

v4 = a1 == 1;
v5 = 0;
LABEL_3:
if ( a2 != 1 )
{
while ( !v4 )
{
if ( a1 < a2 )
{
a2 = a1;
goto LABEL_3;
}
if ( a1 != a2 )
{
v7 = a2;
v8 = a1 - a2--;
v5 += func7(v8, v7);
goto LABEL_3;
}
a2 = a1 - 1;
++v5;
if ( a1 == 2 )
return (unsigned int)(v5 + 1);
}
}
return (unsigned int)(v5 + 1);
}

original_code:
uint32_t integer_division(uint32_t number,uint32_t max)
{
 uint32_t result = 0;
 if(number == 1 || max == 1)
 {
  result = 1;
 }
 else if(max > number)
 {
  result = integer_division(number,number);
 }
 else if(max == number)
 {
  result = 1 + integer_division(number,number-1);
 }
 else
 {
  result = integer_division(number-max,max) + integer_division(number,max-1);
 }
 return result;
}

canonical_original_code:
unsigned int integer_division(unsigned int number, unsigned int max)
{
 unsigned int result = 0;
 if(number == 1 || max == 1)
 {
  result = 1;
 }
 else if(max > number)
 {
  result = integer_division(number,number);
 }
 else if(max == number)
 {
  result = 1 + integer_division(number,number-1);
 }
 else
 {
  result = integer_division(number-max,max) + integer_division(number,max-1);
 }
 return result;
}

variable_types:
number
unsigned int

variable_types:
max
unsigned int

variable_types:
result
unsigned int


repo: QMonkey/HTTP-Web-Server

decompiled_code:
void HTTP_URLTree_find_node()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
HTTP_URLTree_node* HTTP_URLTree_find_node(HTTP_URLTree_node *head,char *url)
{
}

canonical_original_code:
struct HTTP_Tree_node *HTTP_URLTree_find_node(struct HTTP_Tree_node *head, char *url)
{
}

variable_types:
head
struct HTTP_Tree_node *

variable_types:
url
char *

return_type: struct HTTP_Tree_node { struct HTTP_Tree_node *child; struct HTTP_Tree_node *sibling; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *key; int (*handler)(struct HTTP_Socket { int sfd; struct HTTP_String *buffer; } *, struct HTTP_Socket *); } *

user_defined_types: struct HTTP_Tree_node { struct HTTP_Tree_node *child; struct HTTP_Tree_node *sibling; struct HTTP_String *key; int (*handler)(struct HTTP_Socket *, struct HTTP_Socket *); }


decompiled_code:
__int64 __fastcall HTTP_URLTree_node_value(_QWORD *a1, _BYTE *a2)
{
_QWORD *v2; // r12
char v3; // al
_BYTE *v4; // r13
_BYTE *v5; // rbx
char v6; // dl
bool v7; // al
int v8; // ebp
unsigned int v9; // ebp

if ( !a2 )
return 0LL;
v2 = a1;
if ( a1 )
{
v3 = *a2;
v4 = a2;
while ( v3 )
{
v5 = v4;
if ( v3 == 47 )
{
v7 = 1;
v8 = 0;
}
else
{
do
{
v6 = *++v5;
v7 = v6 != 0;
}
while ( v6 != 47 && v6 );
v8 = (_DWORD)v5 - (_DWORD)v4;
}
v9 = v7 + v8;
while ( (unsigned int)HTTP_String_strcmp(v2[2], v4, v9) )
{
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
if ( !*v5 )
return v2[3];
v3 = v5[1];
if ( !v3 )
return v2[3];
v2 = (_QWORD *)*v2;
v4 = v5 + 1;
if ( !v2 )
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _BYTE *a2)
{
_QWORD *v2; // r12
char v3; // al
_BYTE *v4; // r13
_BYTE *v5; // rbx
char v6; // dl
bool v7; // al
int v8; // ebp
unsigned int v9; // ebp

if ( !a2 )
return 0LL;
v2 = a1;
if ( a1 )
{
v3 = *a2;
v4 = a2;
while ( v3 )
{
v5 = v4;
if ( v3 == 47 )
{
v7 = 1;
v8 = 0;
}
else
{
do
{
v6 = *++v5;
v7 = v6 != 0;
}
while ( v6 != 47 && v6 );
v8 = (_DWORD)v5 - (_DWORD)v4;
}
v9 = v7 + v8;
while ( (unsigned int)HTTP_String_strcmp(v2[2], v4, v9) )
{
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
if ( !*v5 )
return v2[3];
v3 = v5[1];
if ( !v3 )
return v2[3];
v2 = (_QWORD *)*v2;
v4 = v5 + 1;
if ( !v2 )
return 0LL;
}
}
return 0LL;
}

original_code:
HTTP_Handler HTTP_URLTree_node_value(HTTP_URLTree_node *node,char *url)
{
 if(node == ((void *)0) || url == ((void *)0) || *url == 0)
 {
  return ((void *)0);
 }
 char *ptr = url;
 while(*ptr != '/' && *ptr != 0)
 {
  ++ptr;
 }
 int32_t size = ptr - url + (*ptr ? 1 : 0);
 int (*handler)(HTTP_Socket*,HTTP_Socket*) = ((void *)0);
 int flag = 0;
 do
 {
  flag = 0;
  if(!HTTP_String_strcmp(node->key,url,size))
  {
   if(*ptr != 0 && *(ptr+1) != 0)
   {
    handler = HTTP_URLTree_node_value(node->child,ptr+1);
   }
   else
   {
    handler = node->handler;
   }
  }
  else
  {
   if(node->sibling != ((void *)0))
   {
    node = node->sibling;
    flag = 1;
   }
  }
 }
 while(flag);
 return handler;
}

canonical_original_code:
int (*HTTP_URLTree_node_value(struct HTTP_Tree_node *node, char *url))(struct HTTP_Socket *, struct HTTP_Socket *)
{
 if(node == ((void *)0) || url == ((void *)0) || *url == 0)
 {
  return ((void *)0);
 }
 char *ptr = url;
 while(*ptr != '/' && *ptr != 0)
 {
  ++ptr;
 }
 int size = ptr - url + (*ptr ? 1 : 0);
 int (*handler)(struct HTTP_Socket *, struct HTTP_Socket *) = ((void *)0);
 int flag = 0;
 do
 {
  flag = 0;
  if(!HTTP_String_strcmp(node->key,url,size))
  {
   if(*ptr != 0 && *(ptr+1) != 0)
   {
    handler = HTTP_URLTree_node_value(node->child,ptr+1);
   }
   else
   {
    handler = node->handler;
   }
  }
  else
  {
   if(node->sibling != ((void *)0))
   {
    node = node->sibling;
    flag = 1;
   }
  }
 }
 while(flag);
 return handler;
}

variable_types: struct HTTP_Tree_node { struct HTTP_Tree_node *child; struct HTTP_Tree_node *sibling; struct HTTP_String *key; int (*handler)(struct HTTP_Socket *, struct HTTP_Socket *); } *

variable_types:
ptr
char *

variable_types: size int

variable_types: int (*)(struct HTTP_Socket { int sfd; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *buffer; } *, struct HTTP_Socket *)

variable_types: flag int

user_defined_types: struct HTTP_Socket { int sfd; struct HTTP_String *buffer; }


decompiled_code:
__int64 __fastcall HTTP_URLTree_destroy_node(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_String_destroy(*((_QWORD *)ptr + 2));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_String_destroy(*((_QWORD *)ptr + 2));
free(ptr);
return 0LL;
}

original_code:
int HTTP_URLTree_destroy_node(HTTP_URLTree_node *node)
{
 if(node == ((void *)0))
 {
  return -1;
 }
 HTTP_String_destroy(node->key);
 free(node);
 return 0;
}

canonical_original_code:
int HTTP_URLTree_destroy_node(struct HTTP_Tree_node *node)
{
 if(node == ((void *)0))
 {
  return -1;
 }
 HTTP_String_destroy(node->key);
 free(node);
 return 0;
}

variable_types: struct HTTP_Tree_node { struct HTTP_Tree_node *child; struct HTTP_Tree_node *sibling; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *key; int (*handler)(struct HTTP_Socket { int sfd; struct HTTP_String *buffer; } *, struct HTTP_Socket *); } *


decompiled_code:
__int64 __fastcall HTTP_URLTree_destroy(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_URLTree_destroy(*(void **)ptr);
HTTP_URLTree_destroy(*((void **)ptr + 1));
HTTP_URLTree_destroy_node(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
func3(*(void **)ptr);
func3(*((void **)ptr + 1));
func2(ptr);
return 0LL;
}

original_code:
int HTTP_URLTree_destroy(HTTP_URLTree_node *head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_URLTree_destroy(head->child);
 HTTP_URLTree_destroy(head->sibling);
 HTTP_URLTree_destroy_node(head);
 return 0;
}

canonical_original_code:
int HTTP_URLTree_destroy(struct HTTP_Tree_node *head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_URLTree_destroy(head->child);
 HTTP_URLTree_destroy(head->sibling);
 HTTP_URLTree_destroy_node(head);
 return 0;
}

user_defined_types: struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; }


decompiled_code:
__int64 __fastcall HTTP_Request_init(__int64 a1)
{
int v1; // eax
__int128 v3; // [rsp+0h] [rbp-408h] BYREF
char v4[1008]; // [rsp+10h] [rbp-3F8h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
memset(v4, 0, sizeof(v4));
while ( 1 )
{
v1 = recv(*(_DWORD *)a1, &v3, 0x400uLL, 64);
if ( v1 <= 0 )
break;
HTTP_String_write(*(_QWORD *)(a1 + 8), &v3, (unsigned int)v1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
__int128 v3; // [rsp+0h] [rbp-408h] BYREF
char v4[1008]; // [rsp+10h] [rbp-3F8h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
memset(v4, 0, sizeof(v4));
while ( 1 )
{
v1 = recv(*(_DWORD *)a1, &v3, 0x400uLL, 64);
if ( v1 <= 0 )
break;
HTTP_String_write(*(_QWORD *)(a1 + 8), &v3, (unsigned int)v1);
}
return 0LL;
}

original_code:
int HTTP_Request_init(HTTP_Socket *request)
{
 if(request == ((void *)0))
 {
  return -1;
 }
 char buffer[1024] = {0};
 int rd = 0;
 while((rd = recv(request->sfd,buffer,1024,MSG_DONTWAIT)) > 0)
 {
  HTTP_String_write(request->buffer,buffer,rd);
 }
 return 0;
}

canonical_original_code:
int HTTP_Request_init(struct HTTP_Socket *request)
{
 if(request == ((void *)0))
 {
  return -1;
 }
 char buffer[1024] = {0};
 int rd = 0;
 while((rd = recv(request->sfd,buffer,1024,MSG_DONTWAIT)) > 0)
 {
  HTTP_String_write(request->buffer,buffer,rd);
 }
 return 0;
}

variable_types: struct HTTP_Socket { int sfd; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *buffer; } *

variable_types:
buffer
char [1024]

variable_types: rd int


decompiled_code:
__int64 __fastcall HTTP_Request_get_method(__int64 a1)
{
int v1; // eax
__int128 *v2; // rdx
__int128 *v3; // rbx
const char *v4; // r12
signed int v5; // ebx
unsigned int v6; // er12
const char *v7; // r13
unsigned int v9; // eax
__int128 v10; // [rsp+0h] [rbp-428h] BYREF
char v11[1008]; // [rsp+10h] [rbp-418h] BYREF

v10 = 0LL;
memset(v11, 0, sizeof(v11));
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
v1 = HTTP_String_readline(*(_QWORD *)(a1 + 8), &v10);
v2 = &v10;
v3 = (__int128 *)((char *)&v10 + v1);
if ( v3 == &v10 )
{
v9 = strlen(HTTP_Request_method);
v6 = v9;
if ( v9 )
v6 = (unsigned int)strlen(*(&HTTP_Request_method + 1)) == 0 ? 1 : -1;
}
else
{
while ( *(_BYTE *)v2 != 32 )
{
v2 = (__int128 *)((char *)v2 + 1);
if ( v3 == v2 )
goto LABEL_6;
}
LODWORD(v3) = (_DWORD)v2;
LABEL_6:
v4 = HTTP_Request_method;
v5 = (_DWORD)v3 - (unsigned int)&v10;
if ( v5 == (unsigned int)strlen(HTTP_Request_method) )
{
v6 = strncmp(v4, (const char *)&v10, v5);
if ( !v6 )
return v6;
}
else
{
v6 = -1;
}
v7 = *(&HTTP_Request_method + 1);
if ( v5 == (unsigned int)strlen(v7) )
{
v6 = strncmp(v7, (const char *)&v10, v5);
if ( !v6 )
v6 = 1;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
__int128 *v2; // rdx
__int128 *v3; // rbx
const char *v4; // r12
signed int v5; // ebx
unsigned int v6; // er12
const char *v7; // r13
unsigned int v9; // eax
__int128 v10; // [rsp+0h] [rbp-428h] BYREF
char v11[1008]; // [rsp+10h] [rbp-418h] BYREF

v10 = 0LL;
memset(v11, 0, sizeof(v11));
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
v1 = HTTP_String_readline(*(_QWORD *)(a1 + 8), &v10);
v2 = &v10;
v3 = (__int128 *)((char *)&v10 + v1);
if ( v3 == &v10 )
{
v9 = strlen(HTTP_Request_method);
v6 = v9;
if ( v9 )
v6 = (unsigned int)strlen(*(&HTTP_Request_method + 1)) == 0 ? 1 : -1;
}
else
{
while ( *(_BYTE *)v2 != 32 )
{
v2 = (__int128 *)((char *)v2 + 1);
if ( v3 == v2 )
goto LABEL_6;
}
LODWORD(v3) = (_DWORD)v2;
LABEL_6:
v4 = HTTP_Request_method;
v5 = (_DWORD)v3 - (unsigned int)&v10;
if ( v5 == (unsigned int)strlen(HTTP_Request_method) )
{
v6 = strncmp(v4, (const char *)&v10, v5);
if ( !v6 )
return v6;
}
else
{
v6 = -1;
}
v7 = *(&HTTP_Request_method + 1);
if ( v5 == (unsigned int)strlen(v7) )
{
v6 = strncmp(v7, (const char *)&v10, v5);
if ( !v6 )
v6 = 1;
}
}
return v6;
}

original_code:
int HTTP_Request_get_method(HTTP_Socket *request)
{
 char buff[1024] = {0};
 HTTP_String_seek(request->buffer,0,0);
 int32_t size = HTTP_String_readline(request->buffer,buff);
 char *end = buff + size;
 char *scanner = buff;
 while(scanner != end && *scanner != ' ')
 {
  ++scanner;
 }
 int msize = scanner - buff;
 int res = -1;
 int i;
 for(i = 0; i < 2; ++i)
 {
  int32_t rmsize = strlen(HTTP_Request_method[i]);
  if(msize != rmsize)
  {
   continue;
  }
  else
  {
   res = strncmp(HTTP_Request_method[i],buff,msize);
  }
  if(res == 0)
  {
   res = i;
   break;
  }
 }
 return res;
}

canonical_original_code:
int HTTP_Request_get_method(struct HTTP_Socket *request)
{
 char buff[1024] = {0};
 HTTP_String_seek(request->buffer,0,0);
 int size = HTTP_String_readline(request->buffer,buff);
 char *end = buff + size;
 char *scanner = buff;
 while(scanner != end && *scanner != ' ')
 {
  ++scanner;
 }
 int msize = scanner - buff;
 int res = -1;
 int i;
 for(i = 0; i < 2; ++i)
 {
  int rmsize = strlen(HTTP_Request_method[i]);
  if(msize != rmsize)
  {
   continue;
  }
  else
  {
   res = strncmp(HTTP_Request_method[i],buff,msize);
  }
  if(res == 0)
  {
   res = i;
   break;
  }
 }
 return res;
}

variable_types:
buff
char [1024]

variable_types:
end
char *

variable_types:
scanner
char *

variable_types: msize int

variable_types: res int

variable_types: i int

variable_types: rmsize int


decompiled_code:
__int64 __fastcall HTTP_Request_get_url(__int64 a1, _BYTE *a2)
{
void *v2; // rbp
_BYTE *v3; // rcx
_BYTE *v4; // rdx
unsigned int v5; // er12
unsigned int v7; // er12
size_t v8; // rdx

v2 = a2;
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
v3 = &a2[(int)HTTP_String_readline(*(_QWORD *)(a1 + 8), a2)];
if ( a2 == v3 )
goto LABEL_11;
while ( *a2 != 47 )
{
if ( v3 == ++a2 )
goto LABEL_11;
}
if ( v3 == a2 )
{
LABEL_11:
v7 = 0;
v8 = 0LL;
}
else
{
v4 = a2;
while ( v3 != ++v4 )
{
if ( *v4 == 32 || *v4 == 63 )
{
v5 = (_DWORD)v4 - (_DWORD)a2;
memmove(v2, a2, (int)v4 - (int)a2);
return v5;
}
}
v7 = (_DWORD)v3 - (_DWORD)a2;
v8 = (int)v3 - (int)a2;
}
memmove(v2, a2, v8);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _BYTE *a2)
{
void *v2; // rbp
_BYTE *v3; // rcx
_BYTE *v4; // rdx
unsigned int v5; // er12
unsigned int v7; // er12
size_t v8; // rdx

v2 = a2;
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
v3 = &a2[(int)HTTP_String_readline(*(_QWORD *)(a1 + 8), a2)];
if ( a2 == v3 )
goto LABEL_11;
while ( *a2 != 47 )
{
if ( v3 == ++a2 )
goto LABEL_11;
}
if ( v3 == a2 )
{
LABEL_11:
v7 = 0;
v8 = 0LL;
}
else
{
v4 = a2;
while ( v3 != ++v4 )
{
if ( *v4 == 32 || *v4 == 63 )
{
v5 = (_DWORD)v4 - (_DWORD)a2;
memmove(v2, a2, (int)v4 - (int)a2);
return v5;
}
}
v7 = (_DWORD)v3 - (_DWORD)a2;
v8 = (int)v3 - (int)a2;
}
memmove(v2, a2, v8);
return v7;
}

original_code:
int32_t HTTP_Request_get_url(HTTP_Socket *request,char *url)
{
 HTTP_String_seek(request->buffer,0,0);
 int32_t rd = HTTP_String_readline(request->buffer,url);
 char *scanner = url;
 char *end = scanner + rd;
 while(scanner != end && *scanner != '/')
 {
  ++scanner;
 }
 char *begin = scanner;
 while(scanner != end && *scanner != ' ' && *scanner != '?')
 {
  ++scanner;
 }
 int32_t size = scanner - begin;
 memmove(url,begin,size);
 return size;
}

canonical_original_code:
int HTTP_Request_get_url(struct HTTP_Socket *request, char *url)
{
 HTTP_String_seek(request->buffer,0,0);
 int rd = HTTP_String_readline(request->buffer,url);
 char *scanner = url;
 char *end = scanner + rd;
 while(scanner != end && *scanner != '/')
 {
  ++scanner;
 }
 char *begin = scanner;
 while(scanner != end && *scanner != ' ' && *scanner != '?')
 {
  ++scanner;
 }
 int size = scanner - begin;
 memmove(url,begin,size);
 return size;
}

variable_types:
url
char *

variable_types:
begin
char *


decompiled_code:
// attributes: thunk
__int64 HTTP_Request_get_header()
{
return HTTP_Socket_get_header();
}

canonical_decompiled_code:
__int64 func3()
{
return HTTP_Socket_get_header();
}

original_code:
int32_t HTTP_Request_get_header(HTTP_Socket *request,char *key,char *content)
{
 return HTTP_Socket_get_header(request,key,content);
}

canonical_original_code:
int HTTP_Request_get_header(struct HTTP_Socket *request, char *key, char *content)
{
 return HTTP_Socket_get_header(request,key,content);
}

variable_types:
key
char *

variable_types:
content
char *


decompiled_code:
__int64 __fastcall HTTP_Request_get_params(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
char *v3; // rdi
char *i; // rbp
char *v5; // rbx
__int64 v6; // r12
char j; // al
__int64 v8; // r13
__int64 v9; // rdi
__int64 v10; // rbp
char *v12; // rax
char v13; // dl
__int64 v14; // [rsp+0h] [rbp-430h] BYREF
char nptr[16]; // [rsp+8h] [rbp-428h] BYREF
char v16[1008]; // [rsp+18h] [rbp-418h] BYREF

*(_OWORD *)nptr = 0LL;
memset(v16, 0, sizeof(v16));
v1 = HTTP_Request_get_method(a1);
if ( v1 )
{
if ( v1 == 1 )
{
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
nptr[(int)HTTP_Request_get_header(a1, "Content-Length", nptr)] = 0;
v2 = atoi(nptr);
while ( (unsigned int)HTTP_String_readline(*(_QWORD *)(a1 + 8), nptr) )
;
v3 = *(char **)(*(_QWORD *)(a1 + 8) + 8LL);
i = &v3[v2];
}
else
{
i = 0LL;
v3 = 0LL;
}
}
else
{
v12 = **(char ***)(a1 + 8);
v13 = *v12;
if ( *v12 == 13 )
return 0LL;
while ( v13 != 63 )
{
v13 = *++v12;
if ( v13 == 13 )
return 0LL;
}
v3 = v12 + 1;
for ( i = v12 + 1; *i != 32; ++i )
;
}
v14 = 0LL;
v5 = v3;
v6 = 0LL;
while ( 1 )
{
for ( j = *v5; j != 61; j = *++v5 )
{
if ( j == 38 )
break;
if ( i == v5 )
goto LABEL_17;
}
if ( i == v5 )
break;
if ( j == 38 )
{
v8 = HTTP_String_create2(v3, v5 - v3);
HTTP_Param_insert(&v14, v6, v8);
v9 = v6;
v6 = 0LL;
HTTP_String_destroy(v9);
HTTP_String_destroy(v8);
}
else
{
v6 = HTTP_String_create2(v3, v5 - v3);
}
v3 = ++v5;
}
LABEL_17:
if ( v6 )
{
v10 = HTTP_String_create2(v3, v5 - v3);
HTTP_Param_insert(&v14, v6, v10);
HTTP_String_destroy(v6);
HTTP_String_destroy(v10);
}
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
char *v3; // rdi
char *i; // rbp
char *v5; // rbx
__int64 v6; // r12
char j; // al
__int64 v8; // r13
__int64 v9; // rdi
__int64 v10; // rbp
char *v12; // rax
char v13; // dl
__int64 v14; // [rsp+0h] [rbp-430h] BYREF
char nptr[16]; // [rsp+8h] [rbp-428h] BYREF
char v16[1008]; // [rsp+18h] [rbp-418h] BYREF

*(_OWORD *)nptr = 0LL;
memset(v16, 0, sizeof(v16));
v1 = func1(a1);
if ( v1 )
{
if ( v1 == 1 )
{
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
nptr[(int)func3(a1, "Content-Length", nptr)] = 0;
v2 = atoi(nptr);
while ( (unsigned int)HTTP_String_readline(*(_QWORD *)(a1 + 8), nptr) )
;
v3 = *(char **)(*(_QWORD *)(a1 + 8) + 8LL);
i = &v3[v2];
}
else
{
i = 0LL;
v3 = 0LL;
}
}
else
{
v12 = **(char ***)(a1 + 8);
v13 = *v12;
if ( *v12 == 13 )
return 0LL;
while ( v13 != 63 )
{
v13 = *++v12;
if ( v13 == 13 )
return 0LL;
}
v3 = v12 + 1;
for ( i = v12 + 1; *i != 32; ++i )
;
}
v14 = 0LL;
v5 = v3;
v6 = 0LL;
while ( 1 )
{
for ( j = *v5; j != 61; j = *++v5 )
{
if ( j == 38 )
break;
if ( i == v5 )
goto LABEL_17;
}
if ( i == v5 )
break;
if ( j == 38 )
{
v8 = HTTP_String_create2(v3, v5 - v3);
HTTP_Param_insert(&v14, v6, v8);
v9 = v6;
v6 = 0LL;
HTTP_String_destroy(v9);
HTTP_String_destroy(v8);
}
else
{
v6 = HTTP_String_create2(v3, v5 - v3);
}
v3 = ++v5;
}
LABEL_17:
if ( v6 )
{
v10 = HTTP_String_create2(v3, v5 - v3);
HTTP_Param_insert(&v14, v6, v10);
HTTP_String_destroy(v6);
HTTP_String_destroy(v10);
}
return v14;
}

original_code:
HTTP_Param_node* HTTP_Request_get_params(HTTP_Socket *request)
{
 char *begin = ((void *)0);
 char *end = ((void *)0);
 char buffer[1024] = {0};
 int32_t hsize = 0;
 int32_t size = 0;
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  begin = request->buffer->begin;
  while(*begin != '\r' && *begin != '?')
  {
   ++begin;
  }
  if(*begin == '\r')
  {
   return ((void *)0);
  }
  end = ++begin;
  while(*end != ' ')
  {
   ++end;
  }
  break;
 case 1:
  HTTP_String_seek(request->buffer,0,0);
  hsize = HTTP_Request_get_header(request,"Content-Length",buffer);
  buffer[hsize] = 0;
  size = atoi(buffer);
  while(HTTP_String_readline(request->buffer,buffer));
  begin = request->buffer->current;
  end = begin + size;
  break;
 default:
  break;
 }
 char *scanner = begin;
 HTTP_Param_node *head = ((void *)0);
 HTTP_String *key = ((void *)0);
 HTTP_String *value = ((void *)0);
 while(1)
 {
  while(*scanner != '=' && *scanner != '&' && scanner != end)
  {
   ++scanner;
  }
  if(scanner == end)
  {
   if(key != ((void *)0))
   {
    value = HTTP_String_create2(begin,scanner-begin);
    HTTP_Param_insert(&head,key,value);
    HTTP_String_destroy(key);
    HTTP_String_destroy(value);
   }
   break;
  }
  switch(*scanner)
  {
  case '=':
   key = HTTP_String_create2(begin,scanner-begin);
   break;
  case '&':
   value = HTTP_String_create2(begin,scanner-begin);
   HTTP_Param_insert(&head,key,value);
   HTTP_String_destroy(key);
   HTTP_String_destroy(value);
   key = ((void *)0);
   value = ((void *)0);
   break;
  default:
   break;
  }
  begin = ++scanner;
 }
 return head;
}

canonical_original_code:
struct HTTP_param_linkedlist_node *HTTP_Request_get_params(struct HTTP_Socket *request)
{
 char *begin = ((void *)0);
 char *end = ((void *)0);
 char buffer[1024] = {0};
 int hsize = 0;
 int size = 0;
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  begin = request->buffer->begin;
  while(*begin != '\r' && *begin != '?')
  {
   ++begin;
  }
  if(*begin == '\r')
  {
   return ((void *)0);
  }
  end = ++begin;
  while(*end != ' ')
  {
   ++end;
  }
  break;
 case 1:
  HTTP_String_seek(request->buffer,0,0);
  hsize = HTTP_Request_get_header(request,"Content-Length",buffer);
  buffer[hsize] = 0;
  size = atoi(buffer);
  while(HTTP_String_readline(request->buffer,buffer));
  begin = request->buffer->current;
  end = begin + size;
  break;
 default:
  break;
 }
 char *scanner = begin;
 struct HTTP_param_linkedlist_node *head = ((void *)0);
 struct HTTP_String *key = ((void *)0);
 struct HTTP_String *value = ((void *)0);
 while(1)
 {
  while(*scanner != '=' && *scanner != '&' && scanner != end)
  {
   ++scanner;
  }
  if(scanner == end)
  {
   if(key != ((void *)0))
   {
    value = HTTP_String_create2(begin,scanner-begin);
    HTTP_Param_insert(&head,key,value);
    HTTP_String_destroy(key);
    HTTP_String_destroy(value);
   }
   break;
  }
  switch(*scanner)
  {
  case '=':
   key = HTTP_String_create2(begin,scanner-begin);
   break;
  case '&':
   value = HTTP_String_create2(begin,scanner-begin);
   HTTP_Param_insert(&head,key,value);
   HTTP_String_destroy(key);
   HTTP_String_destroy(value);
   key = ((void *)0);
   value = ((void *)0);
   break;
  default:
   break;
  }
  begin = ++scanner;
 }
 return head;
}

variable_types: struct HTTP_Socket { int sfd; struct HTTP_String *buffer; } *

variable_types: hsize int

variable_types: size int

variable_types: struct HTTP_param_linkedlist_node { struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *key; struct HTTP_String *value; struct HTTP_param_linkedlist_node *next; } *

user_defined_types: struct HTTP_param_linkedlist_node { struct HTTP_String *key; struct HTTP_String *value; struct HTTP_param_linkedlist_node *next; }


decompiled_code:
// attributes: thunk
__int64 HTTP_Request_get_content()
{
return HTTP_Socket_get_content();
}

canonical_decompiled_code:
__int64 func5()
{
return HTTP_Socket_get_content();
}

original_code:
int32_t HTTP_Request_get_content(HTTP_Socket *request,char *content)
{
 return HTTP_Socket_get_content(request,content);
}

canonical_original_code:
int HTTP_Request_get_content(struct HTTP_Socket *request, char *content)
{
 return HTTP_Socket_get_content(request,content);
}

variable_types: struct HTTP_Socket { int sfd; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *buffer; } *


decompiled_code:
__int64 __fastcall HTTP_String_offset(_QWORD *a1)
{
return a1[1] - *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
return a1[1] - *a1;
}

original_code:
int32_t HTTP_String_offset(HTTP_String *str)
{
 return str->current - str->begin;
}

canonical_original_code:
int HTTP_String_offset(struct HTTP_String *str)
{
 return str->current - str->begin;
}

variable_types: struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *


decompiled_code:
__int64 __fastcall HTTP_String_size(_QWORD *a1)
{
return a1[3] - *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
return a1[3] - *a1;
}

original_code:
int32_t HTTP_String_size(HTTP_String *str)
{
 return str->end - str->begin;
}

canonical_original_code:
int HTTP_String_size(struct HTTP_String *str)
{
 return str->end - str->begin;
}


decompiled_code:
__int64 __fastcall HTTP_String_capacity(_QWORD *a1)
{
return a1[2] - *a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
return a1[2] - *a1;
}

original_code:
int32_t HTTP_String_capacity(HTTP_String *str)
{
 return str->capacity_end - str->begin;
}

canonical_original_code:
int HTTP_String_capacity(struct HTTP_String *str)
{
 return str->capacity_end - str->begin;
}


decompiled_code:
__int64 __fastcall HTTP_String_seek(__int64 *a1, int a2, int a3)
{
__int64 v3; // r8
__int64 v4; // rcx
int v5; // eax
int v6; // edx
bool v7; // cf
unsigned __int64 v8; // rdx

v3 = a1[1];
v4 = *a1;
if ( a2 == 1 )
{
a3 += v3 - v4;
}
else if ( a2 == 2 )
{
v5 = HTTP_String_capacity(a1);
a3 = v5 + v6;
}
v7 = __CFADD__(v4, a3);
v8 = v4 + a3;
a1[1] = v8;
if ( !v7 && v8 <= a1[2] )
return 0LL;
a1[1] = v3;
return 0xFFFFFFFFLL;
}

original_code:
int32_t HTTP_String_seek(HTTP_String *str,int32_t flag,int32_t offset)
{
 switch(flag)
 {
 case 0:
  break;
 case 1:
  offset += str->current - str->begin;
  break;
 case 2:
  offset += HTTP_String_capacity(str);
  break;
 default:
  break;
 }
 char *tmpptr = str->current;
 str->current = str->begin + offset;
 if(str->current < str->begin || str->current > str->capacity_end)
 {
  str->current = tmpptr;
  return -1;
 }
 return 0;
}

canonical_original_code:
int HTTP_String_seek(struct HTTP_String *str, int flag, int offset)
{
 switch(flag)
 {
 case 0:
  break;
 case 1:
  offset += str->current - str->begin;
  break;
 case 2:
  offset += HTTP_String_capacity(str);
  break;
 default:
  break;
 }
 char *tmpptr = str->current;
 str->current = str->begin + offset;
 if(str->current < str->begin || str->current > str->capacity_end)
 {
  str->current = tmpptr;
  return -1;
 }
 return 0;
}

variable_types: flag int

variable_types: offset int

variable_types:
tmpptr
char *


decompiled_code:
int __fastcall HTTP_String_strcmp(_QWORD *a1, char *a2, int a3)
{
__int64 v3; // rbp
int v4; // eax
size_t v5; // rdx
char *v6; // r13
__int64 v7; // rbx
int result; // eax

v3 = a3;
v4 = HTTP_String_size(a1);
v6 = (char *)a1[4];
v7 = v4;
if ( v4 <= (int)v3 )
v5 = v4;
result = memcmp(v6, a2, v5);
if ( !result && (_DWORD)v7 != (_DWORD)v3 )
{
if ( (int)v7 <= (int)v3 )
result = a2[v7];
else
result = v6[v3];
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(_QWORD *a1, char *a2, int a3)
{
__int64 v3; // rbp
int v4; // eax
size_t v5; // rdx
char *v6; // r13
__int64 v7; // rbx
int result; // eax

v3 = a3;
v4 = func1(a1);
v6 = (char *)a1[4];
v7 = v4;
if ( v4 <= (int)v3 )
v5 = v4;
result = memcmp(v6, a2, v5);
if ( !result && (_DWORD)v7 != (_DWORD)v3 )
{
if ( (int)v7 <= (int)v3 )
result = a2[v7];
else
result = v6[v3];
}
return result;
}

original_code:
int HTTP_String_strcmp(HTTP_String *str,char *cstr,int32_t size)
{
 int32_t ssize = HTTP_String_size(str);
 int res = memcmp(str->content,cstr,size < ssize ? size : ssize);
 res = (!res && ssize != size ?
  (ssize > size ? str->content[size] : cstr[ssize]) : res);
 return res;
}

canonical_original_code:
int HTTP_String_strcmp(struct HTTP_String *str, char *cstr, int size)
{
 int ssize = HTTP_String_size(str);
 int res = memcmp(str->content,cstr,size < ssize ? size : ssize);
 res = (!res && ssize != size ?
  (ssize > size ? str->content[size] : cstr[ssize]) : res);
 return res;
}

variable_types:
cstr
char *

variable_types: ssize int


decompiled_code:
int __fastcall HTTP_String_strcmp2(__int64 a1, __int64 a2)
{
int v2; // eax
_QWORD *v3; // r8

v2 = HTTP_String_capacity((_QWORD *)a2);
return HTTP_String_strcmp(v3, *(char **)(a2 + 32), v2);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // eax
_QWORD *v3; // r8

v2 = func2((_QWORD *)a2);
return func5(v3, *(char **)(a2 + 32), v2);
}

original_code:
int HTTP_String_strcmp2(HTTP_String *first,HTTP_String *second)
{
 return HTTP_String_strcmp(first,second->content,HTTP_String_capacity(second));
}

canonical_original_code:
int HTTP_String_strcmp2(struct HTTP_String *first, struct HTTP_String *second)
{
 return HTTP_String_strcmp(first,second->content,HTTP_String_capacity(second));
}

variable_types:
second
struct HTTP_String *


original_code:
int32_t HTTP_String_readline(HTTP_String *str,char *dest)
{
 if(str == ((void *)0) || dest == ((void *)0))
 {
  return -1;
 }
 int32_t size = 0;
 while(str->current != str->capacity_end)
 {
  char c = *str->current++;
  if(c != '\r' || c == '\r' && *str->current != '\n')
  {
   *dest++ = c;
   ++size;
  }
  else
  {
   ++str->current;
   break;
  }
 }
 return size;
}

canonical_original_code:
int HTTP_String_readline(struct HTTP_String *str, char *dest)
{
 if(str == ((void *)0) || dest == ((void *)0))
 {
  return -1;
 }
 int size = 0;
 while(str->current != str->capacity_end)
 {
  char c = *str->current++;
  if(c != '\r' || c == '\r' && *str->current != '\n')
  {
   *dest++ = c;
   ++size;
  }
  else
  {
   ++str->current;
   break;
  }
 }
 return size;
}

variable_types:
dest
char *

variable_types: c char


decompiled_code:
__int64 __fastcall HTTP_String_read(__int64 a1, void *a2)
{
const void *v4; // rsi
int v5; // er12

if ( a1 && a2 )
{
v4 = *(const void **)(a1 + 8);
v5 = *(_QWORD *)(a1 + 16) - (_DWORD)v4;
memcpy(a2, v4, v5);
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 16);
}
else
{
v5 = -1;
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, void *a2)
{
const void *v4; // rsi
int v5; // er12

if ( a1 && a2 )
{
v4 = *(const void **)(a1 + 8);
v5 = *(_QWORD *)(a1 + 16) - (_DWORD)v4;
memcpy(a2, v4, v5);
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 16);
}
else
{
v5 = -1;
}
return (unsigned int)v5;
}

original_code:
int32_t HTTP_String_read(HTTP_String *str,char *dest)
{
 if(str == ((void *)0) || dest == ((void *)0))
 {
  return -1;
 }
 int32_t size = str->capacity_end - str->current;
 memcpy(dest,str->current,size);
 str->current = str->capacity_end;
 return size;
}

canonical_original_code:
int HTTP_String_read(struct HTTP_String *str, char *dest)
{
 if(str == ((void *)0) || dest == ((void *)0))
 {
  return -1;
 }
 int size = str->capacity_end - str->current;
 memcpy(dest,str->current,size);
 str->current = str->capacity_end;
 return size;
}


decompiled_code:
__int64 __fastcall HTTP_String_insert(const void **a1, const void *a2, unsigned int a3)
{
size_t v3; // r12
int v5; // eax
int v6; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v3 = (int)a3;
while ( a1[3] < (char *)a1[2] + v3 )
{
v5 = HTTP_String_size(a1);
HTTP_String_resize_isra_0(a1, 2 * v5);
}
v6 = HTTP_String_capacity(a1);
memmove((char *)*a1 + v3, *a1, v6);
memcpy((void *)*a1, a2, v3);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func9(const void **a1, const void *a2, unsigned int a3)
{
size_t v3; // r12
int v5; // eax
int v6; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v3 = (int)a3;
while ( a1[3] < (char *)a1[2] + v3 )
{
v5 = func1(a1);
func3(a1, 2 * v5);
}
v6 = func2(a1);
memmove((char *)*a1 + v3, *a1, v6);
memcpy((void *)*a1, a2, v3);
return a3;
}

original_code:
int32_t HTTP_String_insert(HTTP_String *dest,char *src,int32_t size)
{
 if(dest == ((void *)0) || src == ((void *)0))
 {
  return -1;
 }
 while(dest->capacity_end + size > dest->end)
 {
  HTTP_String_resize(dest,HTTP_String_size(dest)<<1);
 }
 memmove(dest->begin+size,dest->begin,HTTP_String_capacity(dest));
 memcpy(dest->begin,src,size);
 return size;
}

canonical_original_code:
int HTTP_String_insert(struct HTTP_String *dest, char *src, int size)
{
 if(dest == ((void *)0) || src == ((void *)0))
 {
  return -1;
 }
 while(dest->capacity_end + size > dest->end)
 {
  HTTP_String_resize(dest,HTTP_String_size(dest)<<1);
 }
 memmove(dest->begin+size,dest->begin,HTTP_String_capacity(dest));
 memcpy(dest->begin,src,size);
 return size;
}

variable_types:
src
char *


decompiled_code:
__int64 __fastcall HTTP_String_write(_QWORD *a1, const void *a2, int a3)
{
void *i; // rdi
int v6; // eax

if ( a3 < 0 || a2 == 0LL || !a1 )
return 0xFFFFFFFFLL;
for ( i = (void *)a1[2]; a1[3] < (unsigned __int64)i + a3; i = (void *)a1[2] )
{
v6 = HTTP_String_size(a1);
HTTP_String_resize_isra_0(a1, 2 * v6);
}
memcpy(i, a2, a3);
a1[2] += a3;
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, const void *a2, int a3)
{
void *i; // rdi
int v6; // eax

if ( a3 < 0 || a2 == 0LL || !a1 )
return 0xFFFFFFFFLL;
for ( i = (void *)a1[2]; a1[3] < (unsigned __int64)i + a3; i = (void *)a1[2] )
{
v6 = func1(a1);
func3(a1, 2 * v6);
}
memcpy(i, a2, a3);
a1[2] += a3;
return (unsigned int)a3;
}

original_code:
int32_t HTTP_String_write(HTTP_String *str,char *src,int32_t size)
{
 if(str == ((void *)0) || src == ((void *)0) || size < 0)
 {
  return -1;
 }
 while(str->capacity_end + size > str->end)
 {
  HTTP_String_resize(str,HTTP_String_size(str)<<1);
 }
 memcpy(str->capacity_end,src,sizeof(char) * size);
 str->capacity_end += size;
 return size;
}

canonical_original_code:
int HTTP_String_write(struct HTTP_String *str, char *src, int size)
{
 if(str == ((void *)0) || src == ((void *)0) || size < 0)
 {
  return -1;
 }
 while(str->capacity_end + size > str->end)
 {
  HTTP_String_resize(str,HTTP_String_size(str)<<1);
 }
 memcpy(str->capacity_end,src,sizeof(char) * size);
 str->capacity_end += size;
 return size;
}


decompiled_code:
__int64 __fastcall HTTP_String_writeline(_QWORD *a1, const void *a2, int a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rax

if ( a3 < 0 || a2 == 0LL || !a1 )
return 0xFFFFFFFFLL;
HTTP_String_write(a1, a2, a3);
v4 = (_BYTE *)a1[2];
a1[2] = v4 + 1;
*v4 = 13;
v5 = (_BYTE *)a1[2];
a1[2] = v5 + 1;
*v5 = 10;
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, const void *a2, int a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rax

if ( a3 < 0 || a2 == 0LL || !a1 )
return 0xFFFFFFFFLL;
func10(a1, a2, a3);
v4 = (_BYTE *)a1[2];
a1[2] = v4 + 1;
*v4 = 13;
v5 = (_BYTE *)a1[2];
a1[2] = v5 + 1;
*v5 = 10;
return (unsigned int)a3;
}

original_code:
int32_t HTTP_String_writeline(HTTP_String *str,char *src,int32_t size)
{
 if(str == ((void *)0) || src == ((void *)0) || size < 0)
 {
  return -1;
 }
 HTTP_String_write(str,src,size);
 *str->capacity_end++ = '\r';
 *str->capacity_end++ = '\n';
 return size;
}

canonical_original_code:
int HTTP_String_writeline(struct HTTP_String *str, char *src, int size)
{
 if(str == ((void *)0) || src == ((void *)0) || size < 0)
 {
  return -1;
 }
 HTTP_String_write(str,src,size);
 *str->capacity_end++ = '\r';
 *str->capacity_end++ = '\n';
 return size;
}


decompiled_code:
__int64 __fastcall HTTP_String_clear(__int64 *a1)
{
__int64 v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
a1[2] = *a1;
a1[1] = v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1)
{
__int64 v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
a1[2] = *a1;
a1[1] = v1;
return 0LL;
}

original_code:
int HTTP_String_clear(HTTP_String *str)
{
 if(str == ((void *)0))
 {
  return -1;
 }
 str->current = str->capacity_end = str->begin;
 return 0;
}

canonical_original_code:
int HTTP_String_clear(struct HTTP_String *str)
{
 if(str == ((void *)0))
 {
  return -1;
 }
 str->current = str->capacity_end = str->begin;
 return 0;
}


decompiled_code:
__int64 __fastcall HTTP_String_destroy(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*((void **)ptr + 4));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*((void **)ptr + 4));
free(ptr);
return 0LL;
}

original_code:
int HTTP_String_destroy(HTTP_String *str)
{
 if(str == ((void *)0))
 {
  return -1;
 }
 free(str->content);
 free(str);
 return 0;
}

canonical_original_code:
int HTTP_String_destroy(struct HTTP_String *str)
{
 if(str == ((void *)0))
 {
  return -1;
 }
 free(str->content);
 free(str);
 return 0;
}


decompiled_code:
unsigned int *__fastcall par_parse_begining(unsigned int *a1)
{
unsigned int *result; // rax
__int64 i; // rdx
char *v3; // rcx
int v4; // esi
__int64 v5[2]; // [rsp+4h] [rbp-24h] BYREF
int v6; // [rsp+14h] [rbp-14h]
char v7; // [rsp+18h] [rbp-10h] BYREF

result = a1;
v5[0] = 0x80000000400LL;
v5[1] = 0x40000000080LL;
v6 = 2048;
for ( i = *a1; (((_DWORD)i - 2048) & 0xFFFFF7FF) == 0; i = *result )
result = (unsigned int *)*((_QWORD *)result + 2);
v3 = (char *)v5;
v4 = 64;
while ( (_DWORD)i == v4 )
{
result = (unsigned int *)*((_QWORD *)result + 2);
if ( &v7 == v3 )
return result;
i = *result;
v4 = *(_DWORD *)v3;
v3 += 4;
}
prt_err(1LL, result, i, v3);
return 0LL;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int *a1)
{
unsigned int *result; // rax
__int64 i; // rdx
char *v3; // rcx
int v4; // esi
__int64 v5[2]; // [rsp+4h] [rbp-24h] BYREF
int v6; // [rsp+14h] [rbp-14h]
char v7; // [rsp+18h] [rbp-10h] BYREF

result = a1;
v5[0] = 0x80000000400LL;
v5[1] = 0x40000000080LL;
v6 = 2048;
for ( i = *a1; (((_DWORD)i - 2048) & 0xFFFFF7FF) == 0; i = *result )
result = (unsigned int *)*((_QWORD *)result + 2);
v3 = (char *)v5;
v4 = 64;
while ( (_DWORD)i == v4 )
{
result = (unsigned int *)*((_QWORD *)result + 2);
if ( &v7 == v3 )
return result;
i = *result;
v4 = *(_DWORD *)v3;
v3 += 4;
}
prt_err(1LL, result, i, v3);
return 0LL;
}

original_code:
t_lexer *par_parse_begining(t_lexer *lst)
{
 t_type cod_lin[6] = {CMD_NAME, STR, ENDOFLINE, CMD_COM, STR, ENDOFLINE};
 int i;
 i = -1;
 while ((lst->token == ENDOFLINE) || (lst->token == COM))
  lst = lst->next;
 while (++i < 6)
 {
  if (lst->token != cod_lin[i])
  {
   prt_err(1, lst);
   return (((void *)0));
  }
  lst = lst->next;
 }
 return (lst);
}

canonical_original_code:
struct s_lexer *par_parse_begining(struct s_lexer *lst)
{
 enum e_type cod_lin[6] = {CMD_NAME, STR, ENDOFLINE, CMD_COM, STR, ENDOFLINE};
 int i;
 i = -1;
 while ((lst->token == ENDOFLINE) || (lst->token == COM))
  lst = lst->next;
 while (++i < 6)
 {
  if (lst->token != cod_lin[i])
  {
   prt_err(1, lst);
   return (((void *)0));
  }
  lst = lst->next;
 }
 return (lst);
}

variable_types:
lst
struct s_lexer *

variable_types: i int

return_type: struct s_lexer { enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 } token; char *value; struct s_lexer *next; } *

user_defined_types: struct s_lexer { enum e_type token; char *value; struct s_lexer *next; }


decompiled_code:
__int64 __fastcall par_clear_lst(_DWORD **a1)
{
_DWORD *i; // rbp
void *v3; // rdi
_DWORD *v4; // rbx
void *v6; // rdi
void *v7; // rdi

i = *a1;
if ( **a1 <= 0xFFFu )
goto LABEL_6;
do
{
v3 = (void *)*((_QWORD *)i + 1);
*a1 = (_DWORD *)*((_QWORD *)i + 2);
free(v3);
free(i);
i = *a1;
}
while ( **a1 > 0xFFFu );
v4 = *a1;
for ( i = (_DWORD *)*((_QWORD *)i + 2); i; i = (_DWORD *)*((_QWORD *)i + 2) )
{
if ( *i > 0xFFFu )
{
v6 = (void *)*((_QWORD *)i + 1);
*((_QWORD *)v4 + 2) = *((_QWORD *)i + 2);
free(v6);
v7 = i;
i = v4;
free(v7);
}
LABEL_6:
v4 = i;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD **a1)
{
_DWORD *i; // rbp
void *v3; // rdi
_DWORD *v4; // rbx
void *v6; // rdi
void *v7; // rdi

i = *a1;
if ( **a1 <= 0xFFFu )
goto LABEL_6;
do
{
v3 = (void *)*((_QWORD *)i + 1);
*a1 = (_DWORD *)*((_QWORD *)i + 2);
free(v3);
free(i);
i = *a1;
}
while ( **a1 > 0xFFFu );
v4 = *a1;
for ( i = (_DWORD *)*((_QWORD *)i + 2); i; i = (_DWORD *)*((_QWORD *)i + 2) )
{
if ( *i > 0xFFFu )
{
v6 = (void *)*((_QWORD *)i + 1);
*((_QWORD *)v4 + 2) = *((_QWORD *)i + 2);
free(v6);
v7 = i;
i = v4;
free(v7);
}
LABEL_6:
v4 = i;
}
return 0LL;
}

original_code:
int par_clear_lst(t_lexer **lst)
{
 t_lexer *tmp;
 t_lexer *tmp2;
 while ((*lst)->token > 4095)
 {
  tmp2 = *lst;
  *lst = (*lst)->next;
  free(tmp2->value);
  free(tmp2);
 }
 tmp = *lst;
 while (tmp->next)
 {
  if (tmp->next->token > 4095)
  {
   tmp2 = tmp->next;
   tmp->next = tmp->next->next;
   free(tmp2->value);
   free(tmp2);
  }
  else
   tmp = tmp->next;
 }
 return (0);
}

canonical_original_code:
int par_clear_lst(struct s_lexer **lst)
{
 struct s_lexer *tmp;
 struct s_lexer *tmp2;
 while ((*lst)->token > 4095)
 {
  tmp2 = *lst;
  *lst = (*lst)->next;
  free(tmp2->value);
  free(tmp2);
 }
 tmp = *lst;
 while (tmp->next)
 {
  if (tmp->next->token > 4095)
  {
   tmp2 = tmp->next;
   tmp->next = tmp->next->next;
   free(tmp2->value);
   free(tmp2);
  }
  else
   tmp = tmp->next;
 }
 return (0);
}

variable_types: struct s_lexer { enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 } token; char *value; struct s_lexer *next; } **


original_code:
int par_clear_empty_line(t_lexer **lst)
{
 t_lexer *tmp;
 t_lexer *tmp2;
 while ((*lst)->token == ENDOFLINE)
 {
  tmp = *lst;
  *lst = (*lst)->next;
  free(tmp->value);
  free(tmp);
 }
 tmp2 = *lst;
 while (tmp2->next)
 {
  if (tmp2->token == ENDOFLINE && tmp2->next->token == ENDOFLINE)
  {
   tmp = tmp2->next;
   tmp2->next = tmp2->next->next;
   free(tmp->value);
   free(tmp);
  }
  else
   tmp2 = tmp2->next;
 }
 return (0);
}

canonical_original_code:
int par_clear_empty_line(struct s_lexer **lst)
{
 struct s_lexer *tmp;
 struct s_lexer *tmp2;
 while ((*lst)->token == ENDOFLINE)
 {
  tmp = *lst;
  *lst = (*lst)->next;
  free(tmp->value);
  free(tmp);
 }
 tmp2 = *lst;
 while (tmp2->next)
 {
  if (tmp2->token == ENDOFLINE && tmp2->next->token == ENDOFLINE)
  {
   tmp = tmp2->next;
   tmp2->next = tmp2->next->next;
   free(tmp->value);
   free(tmp);
  }
  else
   tmp2 = tmp2->next;
 }
 return (0);
}

variable_types: struct s_lexer { enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 } token; char *value; struct s_lexer *next; } *


decompiled_code:
__int64 __fastcall par_parser(unsigned int *a1)
{
unsigned int *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
unsigned int *v4; // rbp
unsigned int i; // er12
unsigned int v6; // eax

v1 = par_parse_begining(a1);
if ( v1 )
{
v4 = v1;
for ( i = 3; ; ++i )
{
if ( *v4 == 8 )
{
v4 = (unsigned int *)*((_QWORD *)v4 + 2);
v6 = *v4;
if ( *v4 == 2048 )
goto LABEL_8;
if ( v6 != 16 )
return prt_err(i, v4, v2, v3);
}
if ( (unsigned int)tab_check_line(v4) == -1 )
return prt_err(i, v4, v2, v3);
v6 = *v4;
LABEL_8:
if ( v6 != 2048 )
{
do
v4 = (unsigned int *)*((_QWORD *)v4 + 2);
while ( *v4 != 2048 );
}
v4 = (unsigned int *)*((_QWORD *)v4 + 2);
if ( !v4 )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
unsigned int *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
unsigned int *v4; // rbp
unsigned int i; // er12
unsigned int v6; // eax

v1 = func0(a1);
if ( v1 )
{
v4 = v1;
for ( i = 3; ; ++i )
{
if ( *v4 == 8 )
{
v4 = (unsigned int *)*((_QWORD *)v4 + 2);
v6 = *v4;
if ( *v4 == 2048 )
goto LABEL_8;
if ( v6 != 16 )
return prt_err(i, v4, v2, v3);
}
if ( (unsigned int)tab_check_line(v4) == -1 )
return prt_err(i, v4, v2, v3);
v6 = *v4;
LABEL_8:
if ( v6 != 2048 )
{
do
v4 = (unsigned int *)*((_QWORD *)v4 + 2);
while ( *v4 != 2048 );
}
v4 = (unsigned int *)*((_QWORD *)v4 + 2);
if ( !v4 )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

original_code:
int par_parser(t_lexer *lst)
{
 int line;
 line = 2;
 if ((lst = par_parse_begining(lst)) == ((void *)0))
  return (-1);
 while (line++, lst)
 {
  if (lst->token == 8)
  {
   lst = lst->next;
   if (lst->token != ENDOFLINE && lst->token != OP)
    return (prt_err(line, lst));
   else if (lst->token == OP)
   {
    if (tab_check_line(lst) == -1)
     return (prt_err(line, lst));
   }
  }
  else if (tab_check_line(lst) == -1)
   return (prt_err(line, lst));
  while (lst->token != ENDOFLINE)
   lst = lst->next;
  lst = lst->next;
 }
 return (0);
}

canonical_original_code:
int par_parser(struct s_lexer *lst)
{
 int line;
 line = 2;
 if ((lst = par_parse_begining(lst)) == ((void *)0))
  return (-1);
 while (line++, lst)
 {
  if (lst->token == 8)
  {
   lst = lst->next;
   if (lst->token != ENDOFLINE && lst->token != OP)
    return (prt_err(line, lst));
   else if (lst->token == OP)
   {
    if (tab_check_line(lst) == -1)
     return (prt_err(line, lst));
   }
  }
  else if (tab_check_line(lst) == -1)
   return (prt_err(line, lst));
  while (lst->token != ENDOFLINE)
   lst = lst->next;
  lst = lst->next;
 }
 return (0);
}

variable_types: line int

user_defined_types: enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 }


decompiled_code:
int remove_left_symbole()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax

v0 = tgetstr("le", 0LL);
tputs(v0, 1, (int (*)(int))&out);
v1 = tgetstr("dm", 0LL);
tputs(v1, 1, (int (*)(int))&out);
v2 = tgetstr("dc", 0LL);
tputs(v2, 1, (int (*)(int))&out);
v3 = tgetstr("de", 0LL);
return tputs(v3, 1, (int (*)(int))&out);
}

canonical_decompiled_code:
int func2()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax

v0 = tgetstr("le", 0LL);
tputs(v0, 1, (int (*)(int))&out);
v1 = tgetstr("dm", 0LL);
tputs(v1, 1, (int (*)(int))&out);
v2 = tgetstr("dc", 0LL);
tputs(v2, 1, (int (*)(int))&out);
v3 = tgetstr("de", 0LL);
return tputs(v3, 1, (int (*)(int))&out);
}

original_code:
void remove_left_symbole(void)
{
 tputs(tgetstr("le", ((void *)0)), 1, out);
 tputs(tgetstr("dm", ((void *)0)), 1, out);
 tputs(tgetstr("dc", ((void *)0)), 1, out);
 tputs(tgetstr("de", ((void *)0)), 1, out);
}

canonical_original_code:
void remove_left_symbole()
{
 tputs(tgetstr("le", ((void *)0)), 1, out);
 tputs(tgetstr("dm", ((void *)0)), 1, out);
 tputs(tgetstr("dc", ((void *)0)), 1, out);
 tputs(tgetstr("de", ((void *)0)), 1, out);
}


decompiled_code:
int __fastcall re_print_line(__int64 a1)
{
char *v1; // rax
__int64 v2; // r12
int v3; // ebx
char *v4; // rax
int v5; // ebx
int v6; // ebx
size_t v7; // rax
char *v8; // rax
int i; // ebx
char *v10; // rax
char *v11; // rax

v1 = tgetstr("ei", 0LL);
tputs(v1, 1, (int (*)(int))&out);
v2 = retrieve_prompt(0LL);
v3 = ft_strlen(*(_QWORD *)(a1 + 16)) - *(_DWORD *)a1;
if ( v3 > 0 )
{
do
{
v4 = tgetstr("nd", 0LL);
tputs(v4, 1, (int (*)(int))&out);
--v3;
}
while ( v3 );
}
v5 = ft_strlen(*(_QWORD *)(a1 + 16));
v6 = v5 + ft_strlen(v2) + 3;
if ( v6 > 0 )
{
do
{
remove_left_symbole();
--v6;
}
while ( v6 );
}
print_prompt(v2);
v7 = ft_strlen(*(_QWORD *)(a1 + 16));
write(1, *(const void **)(a1 + 16), v7);
v8 = tgetstr("cd", 0LL);
tputs(v8, 1, (int (*)(int))&out);
for ( i = ft_strlen(*(_QWORD *)(a1 + 16)); *(_DWORD *)a1 != i; --i )
{
v10 = tgetstr("le", 0LL);
tputs(v10, 1, (int (*)(int))&out);
}
v11 = tgetstr("im", 0LL);
return tputs(v11, 1, (int (*)(int))&out);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
char *v1; // rax
__int64 v2; // r12
int v3; // ebx
char *v4; // rax
int v5; // ebx
int v6; // ebx
size_t v7; // rax
char *v8; // rax
int i; // ebx
char *v10; // rax
char *v11; // rax

v1 = tgetstr("ei", 0LL);
tputs(v1, 1, (int (*)(int))&out);
v2 = retrieve_prompt(0LL);
v3 = ft_strlen(*(_QWORD *)(a1 + 16)) - *(_DWORD *)a1;
if ( v3 > 0 )
{
do
{
v4 = tgetstr("nd", 0LL);
tputs(v4, 1, (int (*)(int))&out);
--v3;
}
while ( v3 );
}
v5 = ft_strlen(*(_QWORD *)(a1 + 16));
v6 = v5 + ft_strlen(v2) + 3;
if ( v6 > 0 )
{
do
{
func2();
--v6;
}
while ( v6 );
}
print_prompt(v2);
v7 = ft_strlen(*(_QWORD *)(a1 + 16));
write(1, *(const void **)(a1 + 16), v7);
v8 = tgetstr("cd", 0LL);
tputs(v8, 1, (int (*)(int))&out);
for ( i = ft_strlen(*(_QWORD *)(a1 + 16)); *(_DWORD *)a1 != i; --i )
{
v10 = tgetstr("le", 0LL);
tputs(v10, 1, (int (*)(int))&out);
}
v11 = tgetstr("im", 0LL);
return tputs(v11, 1, (int (*)(int))&out);
}

original_code:
void re_print_line(t_print *print)
{
 int i;
 int j;
 char *prompt;
 tputs(tgetstr("ei", ((void *)0)), 1, out);
 prompt = retrieve_prompt(((void *)0));
 j = ft_strlen(print->line) - print->pos + 1;
 while (j--, j > 0)
  tputs(tgetstr("nd", ((void *)0)), 1, out);
 i = ft_strlen(print->line) + ft_strlen(prompt) + 4;
 while (i--, i > 0)
  remove_left_symbole();
 print_prompt(prompt);
 write(1, print->line, ft_strlen(print->line));
 tputs(tgetstr("cd", ((void *)0)), 1, out);
 i = ft_strlen(print->line) + 1;
 while (i--, i != print->pos)
  tputs(tgetstr("le", ((void *)0)), 1, out);
 tputs(tgetstr("im", ((void *)0)), 1, out);
}

canonical_original_code:
void re_print_line(struct s_print *print)
{
 int i;
 int j;
 char *prompt;
 tputs(tgetstr("ei", ((void *)0)), 1, out);
 prompt = retrieve_prompt(((void *)0));
 j = ft_strlen(print->line) - print->pos + 1;
 while (j--, j > 0)
  tputs(tgetstr("nd", ((void *)0)), 1, out);
 i = ft_strlen(print->line) + ft_strlen(prompt) + 4;
 while (i--, i > 0)
  remove_left_symbole();
 print_prompt(prompt);
 write(1, print->line, ft_strlen(print->line));
 tputs(tgetstr("cd", ((void *)0)), 1, out);
 i = ft_strlen(print->line) + 1;
 while (i--, i != print->pos)
  tputs(tgetstr("le", ((void *)0)), 1, out);
 tputs(tgetstr("im", ((void *)0)), 1, out);
}

variable_types: struct s_print { int pos; int startsel; int endsel; int ins; char *line; char *select; struct s_history { char *line; struct s_history *prev; struct s_history *next; } *histo; } *

variable_types: j int

variable_types:
prompt
char *

user_defined_types: struct s_print { int pos; int startsel; int endsel; int ins; char *line; char *select; struct s_history *histo; }


variable_types:
c
char *

variable_types: struct s_print { int pos; int startsel; int endsel; int ins; int length; char *line; char *select; struct s_history { char *line; struct s_history *prev; struct s_history *next; } *histo; } *

user_defined_types: struct s_print { int pos; int startsel; int endsel; int ins; int length; char *line; char *select; struct s_history *histo; }


original_code:
int pressed_shift_up(char *c, t_print *print)
{
 int i;
 int j;
 int col;
 char *prompt;
 if (!(c[0] == 27 && c[1] == 91 && c[2] == 49 && c[3] == 59 && c[4] == 50 && c[5] == 65 && c[6] == 0))
  return (0);
 prompt = retrieve_prompt(((void *)0));
 i = ft_strlen(prompt);
 j = ft_strlen(print->line);
 col = tgetnum("co");
 if ((i + j) < col)
  ft_to_get_under_25_lines_1(print);
 else
 {
  while (print->pos > 0 && col > 0)
  {
   tputs(tgetstr("le", ((void *)0)), 1, out);
   col -= 1;
   print->pos -= 1;
  }
 }
 return (1);
}

canonical_original_code:
int pressed_shift_up(char *c, struct s_print *print)
{
 int i;
 int j;
 int col;
 char *prompt;
 if (!(c[0] == 27 && c[1] == 91 && c[2] == 49 && c[3] == 59 && c[4] == 50 && c[5] == 65 && c[6] == 0))
  return (0);
 prompt = retrieve_prompt(((void *)0));
 i = ft_strlen(prompt);
 j = ft_strlen(print->line);
 col = tgetnum("co");
 if ((i + j) < col)
  ft_to_get_under_25_lines_1(print);
 else
 {
  while (print->pos > 0 && col > 0)
  {
   tputs(tgetstr("le", ((void *)0)), 1, out);
   col -= 1;
   print->pos -= 1;
  }
 }
 return (1);
}

variable_types: col int

user_defined_types: struct s_history { char *line; struct s_history *prev; struct s_history *next; }


decompiled_code:
__int64 __fastcall pressed_shift_down(_BYTE *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // er14
int v5; // er13
int v6; // ebx
char *v7; // rax
int v8; // eax

result = 0LL;
if ( *a1 == 27 && a1[1] == 91 && a1[2] == 49 && a1[3] == 59 && a1[4] == 50 && a1[5] == 66 && !a1[6] )
{
v3 = retrieve_prompt(0LL);
v4 = ft_strlen(v3);
v5 = ft_strlen(*(_QWORD *)(a2 + 16));
v6 = tgetnum("co");
if ( (int)(v5 + v4) < v6 )
{
ft_to_get_under_25_lines_2(a2, v4, (unsigned int)v5);
}
else if ( *(_DWORD *)a2 < v5 && v6 > 0 )
{
do
{
--v6;
v7 = tgetstr("nd", 0LL);
tputs(v7, 1, (int (*)(int))&out);
v8 = *(_DWORD *)a2 + 1;
*(_DWORD *)a2 = v8;
}
while ( v6 > 0 && v8 < v5 );
}
result = 1LL;
}
return result;
}

original_code:
int pressed_shift_down(char *c, t_print *print)
{
 int i;
 int j;
 int col;
 char *prompt;
 if (!(c[0] == 27 && c[1] == 91 && c[2] == 49 && c[3] == 59 && c[4] == 50 && c[5] == 66 && c[6] == 0))
  return (0);
 prompt = retrieve_prompt(((void *)0));
 i = ft_strlen(prompt);
 j = ft_strlen(print->line);
 col = tgetnum("co");
 if ((i + j) < col)
  ft_to_get_under_25_lines_2(print, i, j);
 else
 {
  while (print->pos < j && col > 0)
  {
   tputs(tgetstr("nd", ((void *)0)), 1, out);
   col -= 1;
   print->pos += 1;
  }
 }
 return (1);
}

canonical_original_code:
int pressed_shift_down(char *c, struct s_print *print)
{
 int i;
 int j;
 int col;
 char *prompt;
 if (!(c[0] == 27 && c[1] == 91 && c[2] == 49 && c[3] == 59 && c[4] == 50 && c[5] == 66 && c[6] == 0))
  return (0);
 prompt = retrieve_prompt(((void *)0));
 i = ft_strlen(prompt);
 j = ft_strlen(print->line);
 col = tgetnum("co");
 if ((i + j) < col)
  ft_to_get_under_25_lines_2(print, i, j);
 else
 {
  while (print->pos < j && col > 0)
  {
   tputs(tgetstr("nd", ((void *)0)), 1, out);
   col -= 1;
   print->pos += 1;
  }
 }
 return (1);
}


decompiled_code:
__int64 __fastcall ft_compare_other_states(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v3; // r13
__int64 v5; // r14
__int64 v6; // rdx
_QWORD *v7; // rax
__int64 result; // rax

v3 = (_QWORD *)*a3;
v5 = a3[1];
if ( *a3 )
{
v6 = a3[1];
v7 = v3;
while ( v6 )
{
if ( !(unsigned int)ft_compare_lists(a1, *v7) && !(unsigned int)ft_compare_lists(a2, *(_QWORD *)a3[1]) )
return 0xFFFFFFFFLL;
v7 = *(_QWORD **)(*a3 + 8LL);
v6 = *(_QWORD *)(a3[1] + 8LL);
*a3 = v7;
a3[1] = v6;
if ( !v7 )
break;
}
}
*a3 = v3;
result = 0LL;
a3[1] = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v3; // r13
__int64 v5; // r14
__int64 v6; // rdx
_QWORD *v7; // rax
__int64 result; // rax

v3 = (_QWORD *)*a3;
v5 = a3[1];
if ( *a3 )
{
v6 = a3[1];
v7 = v3;
while ( v6 )
{
if ( !(unsigned int)ft_compare_lists(a1, *v7) && !(unsigned int)ft_compare_lists(a2, *(_QWORD *)a3[1]) )
return 0xFFFFFFFFLL;
v7 = *(_QWORD **)(*a3 + 8LL);
v6 = *(_QWORD *)(a3[1] + 8LL);
*a3 = v7;
a3[1] = v6;
if ( !v7 )
break;
}
}
*a3 = v3;
result = 0LL;
a3[1] = v5;
return result;
}

original_code:
int ft_compare_other_states(t_sort *lnk, t_sort *lnk_b, t_state *state)
{
 t_sort_head *save;
 t_sort_head *save_b;
 save = state->list;
 save_b = state->list_b;
 while (state->list && state->list_b)
 {
  if (ft_compare_lists(lnk, state->list->head) == 0
   && ft_compare_lists(lnk_b, state->list_b->head) == 0)
   return (-1);
  state->list = state->list->next;
  state->list_b = state->list_b->next;
 }
 state->list = save;
 state->list_b = save_b;
 return (0);
}

canonical_original_code:
int ft_compare_other_states(struct s_list_arg *lnk, struct s_list_arg *lnk_b, struct s_state *state)
{
 struct s_sort *save;
 struct s_sort *save_b;
 save = state->list;
 save_b = state->list_b;
 while (state->list && state->list_b)
 {
  if (ft_compare_lists(lnk, state->list->head) == 0
   && ft_compare_lists(lnk_b, state->list_b->head) == 0)
   return (-1);
  state->list = state->list->next;
  state->list_b = state->list_b->next;
 }
 state->list = save;
 state->list_b = save_b;
 return (0);
}

variable_types: struct s_state { struct s_sort { struct s_list_arg *head; struct s_sort *next; } *list; struct s_sort *list_b; struct s_list_arg *obj; char *op; } *

variable_types: struct s_sort { struct s_list_arg { int val; struct s_list_arg *next; } *head; struct s_sort *next; } *

user_defined_types: struct s_state { struct s_sort *list; struct s_sort *list_b; struct s_list_arg *obj; char *op; }


original_code:
int ft_update_state(t_state *state, t_sort *lnk, t_sort *lnk_b, int i)
{
 int j;
 t_sort_head *save;
 t_sort_head *save_b;
 t_func *g_funct[11] = {ft_swap_a, ft_swap_b, ft_pick_b_to_a, ft_pick_a_to_b, ft_rotate_a, ft_rotate_b, ft_rotate_rev_a, ft_rotate_rev_b, ft_swap_both, ft_rotate_both, ft_rotate_rev_both};
 j = 0;
 (void)i;
 save = state->list;
 while (state->list->next != ((void *)0))
  state->list = state->list->next;
 state->list->next = ft_create_tsorthead_struct(ft_lstmap_unmod(lnk));
 state->list = save;
 save_b = state->list_b;
 while (state->list_b->next != ((void *)0))
  state->list_b = state->list_b->next;
 state->list_b->next = ft_create_tsorthead_struct(ft_lstmap_unmod(lnk_b));
 state->list_b = save_b;
 if (ft_compare_lists(lnk, state->obj) == 0)
 {
  ft_print_operations(state->op);
  exit(1);
 }
 else if (ft_compare_other_states(lnk, lnk_b, state) == -1)
  return (1);
 while (j < 11)
 {
  ft_printf("______j = %d_______\n", j);
  if (j != i)
  {
   if (g_funct[j](&lnk, &lnk_b, state) == 0)
   {
    ft_printf("JE RENTRE DES FOIS ICI ?");
    return (0);
   }
  }
  j++;
 }
 return (1);
}

canonical_original_code:
int ft_update_state(struct s_state *state, struct s_list_arg *lnk, struct s_list_arg *lnk_b, int i)
{
 int j;
 struct s_sort *save;
 struct s_sort *save_b;
 int (*g_funct[11])(struct s_list_arg **, struct s_list_arg **, struct s_state *) = {ft_swap_a, ft_swap_b, ft_pick_b_to_a, ft_pick_a_to_b, ft_rotate_a, ft_rotate_b, ft_rotate_rev_a, ft_rotate_rev_b, ft_swap_both, ft_rotate_both, ft_rotate_rev_both};
 j = 0;
 (void)i;
 save = state->list;
 while (state->list->next != ((void *)0))
  state->list = state->list->next;
 state->list->next = ft_create_tsorthead_struct(ft_lstmap_unmod(lnk));
 state->list = save;
 save_b = state->list_b;
 while (state->list_b->next != ((void *)0))
  state->list_b = state->list_b->next;
 state->list_b->next = ft_create_tsorthead_struct(ft_lstmap_unmod(lnk_b));
 state->list_b = save_b;
 if (ft_compare_lists(lnk, state->obj) == 0)
 {
  ft_print_operations(state->op);
  exit(1);
 }
 else if (ft_compare_other_states(lnk, lnk_b, state) == -1)
  return (1);
 while (j < 11)
 {
  ft_printf("______j = %d_______\n", j);
  if (j != i)
  {
   if (g_funct[j](&lnk, &lnk_b, state) == 0)
   {
    ft_printf("JE RENTRE DES FOIS ICI ?");
    return (0);
   }
  }
  j++;
 }
 return (1);
}

variable_types: struct s_state { struct s_sort { struct s_list_arg { int val; struct s_list_arg *next; } *head; struct s_sort *next; } *list; struct s_sort *list_b; struct s_list_arg *obj; char *op; } *

variable_types:
lnk
struct s_list_arg *

variable_types: int (*[11])(struct s_list_arg { int val; struct s_list_arg *next; } **, struct s_list_arg **, struct s_state { struct s_sort { struct s_list_arg *head; struct s_sort *next; } *list; struct s_sort *list_b; struct s_list_arg *obj; char *op; } *)


decompiled_code:
__int64 __fastcall ft_strpad(__int64 a1, unsigned __int64 a2, int a3, char a4)
{
unsigned __int64 v6; // rax
__int64 result; // rax
unsigned __int64 v8; // r12
__int64 v9; // rax
__int64 v10; // rbp

v6 = ft_strlen();
if ( v6 >= a2 )
return a1;
v8 = a2 - v6;
v9 = ft_strnew(a2 - v6);
v10 = ft_memset(v9, (unsigned int)a4, v8);
if ( !v10 )
impossible_malloc("padding");
if ( a3 )
result = ft_strjoin(a1, v10);
else
result = ft_strjoin(v10, a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2, int a3, char a4)
{
unsigned __int64 v6; // rax
__int64 result; // rax
unsigned __int64 v8; // r12
__int64 v9; // rax
__int64 v10; // rbp

v6 = ft_strlen();
if ( v6 >= a2 )
return a1;
v8 = a2 - v6;
v9 = ft_strnew(a2 - v6);
v10 = ft_memset(v9, (unsigned int)a4, v8);
if ( !v10 )
impossible_malloc("padding");
if ( a3 )
result = ft_strjoin(a1, v10);
else
result = ft_strjoin(v10, a1);
return result;
}

original_code:
char *ft_strpad(const char *s, size_t size, t_paddir direction, char pad)
{
 size_t pad_size;
 char *pad_str;
 size_t s_len;
 s_len = ft_strlen(s);
 if (size > s_len)
 {
  pad_size = size - s_len;
  pad_str = ft_strnew(pad_size);
  if ((pad_str = (char *) ft_memset(pad_str, pad, pad_size)) == ((void *)0))
   impossible_malloc("padding");
  if (direction == PAD_LEFT)
   return (ft_strjoin(pad_str, s));
  return (ft_strjoin(s, pad_str));
 }
 return ((char *) s);
}

canonical_original_code:
char *ft_strpad(char *s, unsigned long size, enum e_paddir direction, char pad)
{
 unsigned long pad_size;
 char *pad_str;
 unsigned long s_len;
 s_len = ft_strlen(s);
 if (size > s_len)
 {
  pad_size = size - s_len;
  pad_str = ft_strnew(pad_size);
  if ((pad_str = (char *) ft_memset(pad_str, pad, pad_size)) == ((void *)0))
   impossible_malloc("padding");
  if (direction == PAD_LEFT)
   return (ft_strjoin(pad_str, s));
  return (ft_strjoin(s, pad_str));
 }
 return ((char *) s);
}

variable_types:
s
char *

variable_types:
size
unsigned long

variable_types: enum e_paddir { PAD_LEFT=0, PAD_RIGHT=1 }

variable_types: pad char

return_type: char *


decompiled_code:
void __fastcall ft_strpad2(__int64 *a1, unsigned __int64 a2, int a3, char a4)
{
__int64 v5; // rax
void *v6; // rdi
void *v7; // rbp

v5 = ft_strpad(*a1, a2, a3, a4);
v6 = (void *)*a1;
if ( v6 != (void *)v5 )
{
v7 = (void *)v5;
free(v6);
*a1 = ft_strdup(v7);
free(v7);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 *a1, unsigned __int64 a2, int a3, char a4)
{
__int64 v5; // rax
void *v6; // rdi
void *v7; // rbp

v5 = func0(*a1, a2, a3, a4);
v6 = (void *)*a1;
if ( v6 != (void *)v5 )
{
v7 = (void *)v5;
free(v6);
*a1 = ft_strdup(v7);
free(v7);
}
}

original_code:
void ft_strpad2(char **s, size_t size, t_paddir direction, char pad)
{
 char *tmp;
 tmp = ft_strpad(*s, size, direction, pad);
 if (tmp != *s)
 {
  free(*s);
  *s = ft_strdup(tmp);
  free(tmp);
 }
}

canonical_original_code:
void ft_strpad2(char **s, unsigned long size, enum e_paddir direction, char pad)
{
 char *tmp;
 tmp = ft_strpad(*s, size, direction, pad);
 if (tmp != *s)
 {
  free(*s);
  *s = ft_strdup(tmp);
  free(tmp);
 }
}

variable_types:
s
char **

variable_types:
tmp
char *

user_defined_types: enum e_paddir { PAD_LEFT=0, PAD_RIGHT=1 }


decompiled_code:
__int64 __fastcall ft_tolower(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( a1 - 65 < 0x1A )
result = a1 + 32;
return result;
}

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

result = a1;
if ( a1 - 65 < 0x1A )
result = a1 + 32;
return result;
}

original_code:
int ft_tolower(int c)
{
 if (c >= 65 && c <= 90)
  c += 32;
 return (c);
}

variable_types: c int


decompiled_code:
__int64 __fastcall swa_swap_char_by_params(__int64 a1, int a2, int a3)
{
signed int v3; // eax
int v4; // edx
unsigned __int32 v6; // er8
unsigned __int32 v7; // eax

if ( a3 )
v3 = ((__int64 (*)(void))ft_atoi)();
else
v3 = ft_atoi(a1 + 1);
if ( v3 >= 0 )
{
if ( a2 == 2 )
return (v3 << 8) | (unsigned int)(v3 >> 8);
}
else if ( a2 == 2 )
{
HIWORD(v4) = ~HIWORD(v3);
LOWORD(v4) = 0;
v3 += v4 + 0x10000;
return (v3 << 8) | (unsigned int)(v3 >> 8);
}
v6 = 0;
v7 = _byteswap_ulong(v3);
if ( a2 == 4 )
v6 = v7;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
signed int v3; // eax
int v4; // edx
unsigned __int32 v6; // er8
unsigned __int32 v7; // eax

if ( a3 )
v3 = ((__int64 (*)(void))ft_atoi)();
else
v3 = ft_atoi(a1 + 1);
if ( v3 >= 0 )
{
if ( a2 == 2 )
return (v3 << 8) | (unsigned int)(v3 >> 8);
}
else if ( a2 == 2 )
{
HIWORD(v4) = ~HIWORD(v3);
LOWORD(v4) = 0;
v3 += v4 + 0x10000;
return (v3 << 8) | (unsigned int)(v3 >> 8);
}
v6 = 0;
v7 = _byteswap_ulong(v3);
if ( a2 == 4 )
v6 = v7;
return v6;
}

variable_types: size int

variable_types: type int

variable_types: i int

variable_types: swap int


decompiled_code:
__int64 __fastcall swa_swap_int_by_params(signed int a1, int a2)
{
__int64 result; // rax
unsigned __int32 v3; // edi

if ( a2 == 2 )
return (a1 << 8) | (unsigned int)(a1 >> 8);
result = 0LL;
v3 = _byteswap_ulong(a1);
if ( a2 == 4 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(signed int a1, int a2)
{
__int64 result; // rax
unsigned __int32 v3; // edi

if ( a2 == 2 )
return (a1 << 8) | (unsigned int)(a1 >> 8);
result = 0LL;
v3 = _byteswap_ulong(a1);
if ( a2 == 4 )
result = v3;
return result;
}


decompiled_code:
void __fastcall ft_lstdelone(void **a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
a2(*(_QWORD *)*a1, *((_QWORD *)*a1 + 1));
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(void **a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
a2(*(_QWORD *)*a1, *((_QWORD *)*a1 + 1));
free(*a1);
*a1 = 0LL;
}

original_code:
void ft_lstdelone(t_list **alst, void (*del)(void*, size_t))
{
 (*del)((*alst)->content, (*alst)->content_size);
 free(*alst);
 *alst = ((void *)0);
}

canonical_original_code:
void ft_lstdelone(struct s_list **alst, void (*del)(void *, unsigned long))
{
 (*del)((*alst)->content, (*alst)->content_size);
 free(*alst);
 *alst = ((void *)0);
}

variable_types: struct s_list { void *content; unsigned long content_size; struct s_list *next; } **

variable_types:
del
void (*)(void *, unsigned long)


decompiled_code:
void __fastcall __noreturn kill_me(__int64 a1)
{
ft_putstr_fd(a1, 2LL);
ft_putstr_fd(&unk_4D, 2LL);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int64 a1)
{
ft_putstr_fd(a1, 2LL);
ft_putstr_fd(&unk_4D, 2LL);
exit(1);
}

original_code:
void kill_me(char *s)
{
 ft_putstr_fd(s, 2);
 ft_putstr_fd("\n", 2);
 exit(1);
}


decompiled_code:
void __fastcall __noreturn impossible_malloc(__int64 a1)
{
ft_putstr_fd("Unable to malloc : ", 2LL);
kill_me(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1)
{
ft_putstr_fd("Unable to malloc : ", 2LL);
func0(a1);
}

original_code:
void impossible_malloc(char *s)
{
 ft_putstr_fd("Unable to malloc : ", 2);
 kill_me(s);
}


decompiled_code:
_BOOL8 __fastcall is_operator(char a1)
{
return ((a1 - 43) & 0xFD) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return ((a1 - 43) & 0xFD) == 0;
}

original_code:
static int is_operator(char c)
{
 int out;
 out = (c == '-');
 out = (out || (c == '+'));
 return (out);
}

variable_types: c char

variable_types: out int


power

decompiled_code:
__int64 __fastcall power(char a1, int a2)
{
unsigned int v2; // er8
int v3; // esi
int v4; // edx
int v5; // eax

v2 = a1 - 48;
if ( a2 && a2 > 0 )
{
v3 = a2 + 1;
v4 = 1;
v5 = 1;
do
{
++v4;
v5 *= 10;
}
while ( v3 != v4 );
v2 *= v5;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, int a2)
{
unsigned int v2; // er8
int v3; // esi
int v4; // edx
int v5; // eax

v2 = a1 - 48;
if ( a2 && a2 > 0 )
{
v3 = a2 + 1;
v4 = 1;
v5 = 1;
do
{
++v4;
v5 *= 10;
}
while ( v3 != v4 );
v2 *= v5;
}
return v2;
}

original_code:
static int power(char c, int pow)
{
 int out;
 int i;
 int char_value;
 char_value = c - 48;
 out = 1;
 i = 1;
 if (pow == 0)
  return (char_value);
 while (i <= pow)
 {
  out = out * 10;
  i++;
 }
 return (out * char_value);
}

variable_types: pow int


powerize

decompiled_code:
__int64 __fastcall powerize(__int64 a1, int a2, int a3)
{
char v3; // bl
char *v4; // rcx
__int64 v5; // rcx
char v6; // r8
unsigned int v7; // er9
int v8; // er10
char *v9; // r11
int v10; // eax
int v11; // er9

v3 = *(_BYTE *)(a1 + a2);
if ( a2 > a3 )
{
v7 = 0;
}
else
{
v4 = (char *)(a1 + a3);
do
{
if ( !is_operator(*v4) )
{
v10 = power(v6, v8);
v7 = v10 + v11;
}
v4 = (char *)(v5 - 1);
}
while ( v4 != v9 );
}
if ( v3 == 45 )
v7 = -v7;
return v7;
}

original_code:
static int powerize(const char *str, int start, int end)
{
 int power_val;
 int out;
 int is_negative;
 power_val = 0;
 out = 0;
 is_negative = (str[start] == '-');
 while (end >= start)
 {
  if (!is_operator(str[end]))
  {
   out += power(str[end], power_val);
   power_val++;
  }
  end--;
 }
 if (is_negative)
  return (out * -1);
 return (out);
}

canonical_original_code:
static int powerize(char *str, int start, int end)
{
 int power_val;
 int out;
 int is_negative;
 power_val = 0;
 out = 0;
 is_negative = (str[start] == '-');
 while (end >= start)
 {
  if (!is_operator(str[end]))
  {
   out += power(str[end], power_val);
   power_val++;
  }
  end--;
 }
 if (is_negative)
  return (out * -1);
 return (out);
}

variable_types:
str
char *

variable_types: start int

variable_types: end int


decompiled_code:
__int64 __fastcall is_authorized(char a1)
{
char *v1; // rax
char v2; // dl
unsigned int v3; // er8
_BOOL4 v5; // er8

v1 = (char *)&unk_203;
v2 = 10;
v3 = 0;
while ( 1 )
{
v3 += a1 == v2;
if ( v1 == (char *)&unk_208 )
break;
v2 = *v1++;
}
if ( v3 )
return v3;
if ( !(unsigned int)ft_isalpha((unsigned int)a1) && (unsigned int)ft_isascii((unsigned int)a1) && is_operator(a1) )
v5 = 1;
else
v5 = ft_isdigit((unsigned int)a1) != 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
char *v1; // rax
char v2; // dl
unsigned int v3; // er8
_BOOL4 v5; // er8

v1 = (char *)&unk_203;
v2 = 10;
v3 = 0;
while ( 1 )
{
v3 += a1 == v2;
if ( v1 == (char *)&unk_208 )
break;
v2 = *v1++;
}
if ( v3 )
return v3;
if ( !(unsigned int)ft_isalpha((unsigned int)a1) && (unsigned int)ft_isascii((unsigned int)a1) && func0(a1) )
v5 = 1;
else
v5 = ft_isdigit((unsigned int)a1) != 0;
return v5;
}

original_code:
static int is_authorized(char c)
{
 static char authorized[6] = {'\n', '\v', '\t', '\r', '\f', ' '};
 int i;
 int valid;
 valid = 0;
 i = 0;
 while (i < 6)
 {
  if (c == authorized[i])
   valid++;
  i++;
 }
 if (!valid)
 {
  valid = (ft_isalpha(c) || !ft_isascii(c) || !is_operator(c));
  if (valid && !ft_isdigit(c))
   valid = 0;
  else
   valid = 1;
 }
 return (valid);
}

variable_types:
authorized
char [6]

variable_types: valid int


decompiled_code:
__int64 __fastcall ft_atoi(char *a1)
{
char v2; // di
char *v3; // rbx
int v4; // ebp
char v5; // r8
unsigned int v6; // er8
__int64 v8; // rbx
__int64 v9; // rdi
int v10; // er13
int v11; // edx

v2 = *a1;
if ( v2 )
{
v3 = a1;
v4 = 0;
while ( 1 )
{
if ( !(unsigned int)is_authorized(v2) )
return 0LL;
v5 = *v3++;
if ( is_operator(v5) || (unsigned int)ft_isdigit(v6) )
break;
v2 = *v3;
++v4;
if ( !*v3 )
{
v11 = -1;
return powerize((__int64)a1, v4, v11);
}
}
v8 = v4 + 1;
do
{
v9 = (unsigned int)a1[v8];
v10 = v8++;
}
while ( (unsigned int)ft_isdigit(v9) );
v11 = v10 - 1;
}
else
{
v11 = -1;
v4 = 0;
}
return powerize((__int64)a1, v4, v11);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char v2; // di
char *v3; // rbx
int v4; // ebp
char v5; // r8
unsigned int v6; // er8
__int64 v8; // rbx
__int64 v9; // rdi
int v10; // er13
int v11; // edx

v2 = *a1;
if ( v2 )
{
v3 = a1;
v4 = 0;
while ( 1 )
{
if ( !(unsigned int)func3(v2) )
return 0LL;
v5 = *v3++;
if ( func0(v5) || (unsigned int)ft_isdigit(v6) )
break;
v2 = *v3;
++v4;
if ( !*v3 )
{
v11 = -1;
return func2((__int64)a1, v4, v11);
}
}
v8 = v4 + 1;
do
{
v9 = (unsigned int)a1[v8];
v10 = v8++;
}
while ( (unsigned int)ft_isdigit(v9) );
v11 = v10 - 1;
}
else
{
v11 = -1;
v4 = 0;
}
return func2((__int64)a1, v4, v11);
}

original_code:
int ft_atoi(const char *str)
{
 int i;
 int j;
 int out;
 i = 0;
 j = 0;
 out = 0;
 while (str[i])
 {
  if (!is_authorized(str[i]))
   return (0);
  if (is_operator(str[i]) || ft_isdigit(str[i]))
  {
   j = i + 1;
   while (ft_isdigit(str[j]))
    j++;
   break ;
  }
  i++;
 }
 return (powerize(str, i, (j - 1)));
}

canonical_original_code:
int ft_atoi(char *str)
{
 int i;
 int j;
 int out;
 i = 0;
 j = 0;
 out = 0;
 while (str[i])
 {
  if (!is_authorized(str[i]))
   return (0);
  if (is_operator(str[i]) || ft_isdigit(str[i]))
  {
   j = i + 1;
   while (ft_isdigit(str[j]))
    j++;
   break ;
  }
  i++;
 }
 return (powerize(str, i, (j - 1)));
}

variable_types: j int


decompiled_code:
__int64 __fastcall lab_sanitizelexerlabel(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 v4; // r13
__int64 v5; // r12

v2 = ft_strlen(*(_QWORD *)(a1 + 8));
v3 = v2;
v4 = v2 - 1;
if ( *(_DWORD *)a1 == 256 )
{
v4 = v2 - 2;
v3 = v2 - 1;
}
v5 = ft_strnew(v3);
if ( !v5 )
impossible_malloc("char in lab_sanitizelexerlabel");
ft_memcpy(v5, *(_QWORD *)(a1 + 8) + 2LL, v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 v4; // r13
__int64 v5; // r12

v2 = ft_strlen(*(_QWORD *)(a1 + 8));
v3 = v2;
v4 = v2 - 1;
if ( *(_DWORD *)a1 == 256 )
{
v4 = v2 - 2;
v3 = v2 - 1;
}
v5 = ft_strnew(v3);
if ( !v5 )
impossible_malloc("char in lab_sanitizelexerlabel");
ft_memcpy(v5, *(_QWORD *)(a1 + 8) + 2LL, v4);
return v5;
}

original_code:
static char *lab_sanitizelexerlabel(t_lexer *lexer)
{
 size_t len;
 char *out;
 len = ft_strlen(lexer->value);
 len = (lexer->token == DIR_LAB ? len - 2 : len - 1);
 if ((out = ft_strnew(len + 1)) == ((void *)0))
  impossible_malloc("char in lab_sanitizelexerlabel");
 ft_memcpy(out, (lexer->value + 2), len);
 return (out);
}

canonical_original_code:
static char *lab_sanitizelexerlabel(struct s_lexer *lexer)
{
 unsigned long len;
 char *out;
 len = ft_strlen(lexer->value);
 len = (lexer->token == DIR_LAB ? len - 2 : len - 1);
 if ((out = ft_strnew(len + 1)) == ((void *)0))
  impossible_malloc("char in lab_sanitizelexerlabel");
 ft_memcpy(out, (lexer->value + 2), len);
 return (out);
}

variable_types: struct s_lexer { enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 } token; char *value; struct s_lexer *next; } *

variable_types:
len
unsigned long

variable_types:
out
char *


decompiled_code:
__int64 __fastcall lab_sanitizelabel(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12

v1 = ft_strlen(a1);
v2 = ft_strnew(v1);
if ( !v2 )
impossible_malloc("char in lab_sanitizelabel");
ft_memcpy(v2, a1, v1 - 1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12

v1 = ft_strlen(a1);
v2 = ft_strnew(v1);
if ( !v2 )
impossible_malloc("char in lab_sanitizelabel");
ft_memcpy(v2, a1, v1 - 1);
return v2;
}

original_code:
static char *lab_sanitizelabel(char *label)
{
 size_t len;
 char *out;
 len = ft_strlen(label);
 if ((out = ft_strnew(len)) == ((void *)0))
  impossible_malloc("char in lab_sanitizelabel");
 ft_memcpy(out, label, len - 1);
 return (out);
}

canonical_original_code:
static char *lab_sanitizelabel(char *label)
{
 unsigned long len;
 char *out;
 len = ft_strlen(label);
 if ((out = ft_strnew(len)) == ((void *)0))
  impossible_malloc("char in lab_sanitizelabel");
 ft_memcpy(out, label, len - 1);
 return (out);
}

variable_types:
label
char *


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

v2 = a2;
v3 = (void *)lab_sanitizelexerlabel(a1);
if ( a2 )
{
while ( 1 )
{
v4 = (void *)lab_sanitizelabel(*v2);
if ( !(unsigned int)ft_strcmp(v3, v4) )
break;
v2 = (__int64 *)v2[2];
if ( !v2 )
goto LABEL_6;
}
free(v4);
free(v3);
result = 0LL;
}
else
{
LABEL_6:
err_badlabel(v3);
free(v3);
result = 0xFFFFFFFFLL;
}
return result;
}

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

v2 = a2;
v3 = (void *)func0(a1);
if ( a2 )
{
while ( 1 )
{
v4 = (void *)func1(*v2);
if ( !(unsigned int)ft_strcmp(v3, v4) )
break;
v2 = (__int64 *)v2[2];
if ( !v2 )
goto LABEL_6;
}
free(v4);
free(v3);
result = 0LL;
}
else
{
LABEL_6:
err_badlabel(v3);
free(v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int lab_checkexistence(t_lexer *lexer, t_label *label)
{
 t_label *tmp;
 char *lex_label;
 char *lab_label;
 tmp = label;
 lex_label = lab_sanitizelexerlabel(lexer);
 while (tmp)
 {
  lab_label = lab_sanitizelabel(tmp->name);
  if (ft_strcmp(lex_label, lab_label) == 0)
  {
   free(lab_label);
   break ;
  }
  tmp = tmp->next;
 }
 if (tmp == ((void *)0))
 {
  err_badlabel(lex_label);
  free(lex_label);
  return (-1);
 }
 free(lex_label);
 return (0);
}

canonical_original_code:
static int lab_checkexistence(struct s_lexer *lexer, struct s_label *label)
{
 struct s_label *tmp;
 char *lex_label;
 char *lab_label;
 tmp = label;
 lex_label = lab_sanitizelexerlabel(lexer);
 while (tmp)
 {
  lab_label = lab_sanitizelabel(tmp->name);
  if (ft_strcmp(lex_label, lab_label) == 0)
  {
   free(lab_label);
   break ;
  }
  tmp = tmp->next;
 }
 if (tmp == ((void *)0))
 {
  err_badlabel(lex_label);
  free(lex_label);
  return (-1);
 }
 free(lex_label);
 return (0);
}

variable_types: struct s_label { char *name; int address; struct s_label *next; } *