decompiled_code:
void __fastcall write_wchars(__int64 a1, unsigned __int64 a2, unsigned __int64 a3, char a4, char a5, char a6)
{
unsigned __int64 v8; // rbx
wchar_t *v10; // r13
wchar_t v11; // edi

v8 = a2;
if ( a4 )
{
if ( a5 )
{
putwchar(34);
if ( a2 <= a3 )
{
while ( 1 )
{
LABEL_12:
v10 = (wchar_t *)(a1 + 4 * (v8 & 0xFFF));
v11 = *v10;
if ( *v10 == 34 )
{
putwchar(34);
v11 = *v10;
}
if ( putwchar(v11) == -1 )
break;
if ( a3 < ++v8 )
goto LABEL_8;
}
LABEL_16:
fwrite("putwchar error", 1uLL, 0xEuLL, stderr);
exit(1);
}
}
else if ( a2 <= a3 )
{
goto LABEL_12;
}
LABEL_8:
if ( a6 )
putwchar(34);
}
else if ( a2 <= a3 )
{
while ( putwchar(*(_DWORD *)(a1 + 4 * (v8 & 0xFFF))) != -1 )
{
if ( a3 < ++v8 )
return;
}
goto LABEL_16;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, unsigned __int64 a2, unsigned __int64 a3, char a4, char a5, char a6)
{
unsigned __int64 v8; // rbx
wchar_t *v10; // r13
wchar_t v11; // edi

v8 = a2;
if ( a4 )
{
if ( a5 )
{
putwchar(34);
if ( a2 <= a3 )
{
while ( 1 )
{
LABEL_12:
v10 = (wchar_t *)(a1 + 4 * (v8 & 0xFFF));
v11 = *v10;
if ( *v10 == 34 )
{
putwchar(34);
v11 = *v10;
}
if ( putwchar(v11) == -1 )
break;
if ( a3 < ++v8 )
goto LABEL_8;
}
LABEL_16:
fwrite("putwchar error", 1uLL, 0xEuLL, stderr);
exit(1);
}
}
else if ( a2 <= a3 )
{
goto LABEL_12;
}
LABEL_8:
if ( a6 )
putwchar(34);
}
else if ( a2 <= a3 )
{
while ( putwchar(*(_DWORD *)(a1 + 4 * (v8 & 0xFFF))) != -1 )
{
if ( a3 < ++v8 )
return;
}
goto LABEL_16;
}
}

original_code:
static inline void
write_wchars(wchar_t buf[], size_t start, size_t end, _Bool escape,
             _Bool open_field, _Bool close_field) {
  size_t j;
  if (escape) {
    if (open_field)
      putwchar(L'"');
    for (j = start; j <= end; ++j) {
      if (buf[(j % 4096)] == L'"')
        putwchar(L'"');
      if (putwchar(buf[(j % 4096)]) == (0xffffffffu)) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
    if (close_field)
      putwchar(L'"');
  } else {
    for (j = start; j <= end; ++j) {
      if (putwchar(buf[(j % 4096)]) == (0xffffffffu)) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
  }
}

canonical_original_code:
static inline void write_wchars(int buf[], unsigned long start, unsigned long end, _Bool escape, _Bool open_field, _Bool close_field) {
  unsigned long j;
  if (escape) {
    if (open_field)
      putwchar(L'"');
    for (j = start; j <= end; ++j) {
      if (buf[(j % 4096)] == L'"')
        putwchar(L'"');
      if (putwchar(buf[(j % 4096)]) == (0xffffffffu)) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
    if (close_field)
      putwchar(L'"');
  } else {
    for (j = start; j <= end; ++j) {
      if (putwchar(buf[(j % 4096)]) == (0xffffffffu)) {
        fprintf(stderr, "putwchar error");
        exit(1);
      }
    }
  }
}

variable_types:
buf
int []

variable_types:
start
unsigned long

variable_types:
end
unsigned long

variable_types:
j
unsigned long


repo: claryaldringen/ZCUChess

original_code:
void load_position(Position position)
{
 memcpy(chessboard, position.chessboard, sizeof(chessboard));
 memcpy(castlings, position.castlings, sizeof(castlings));
 memcpy(en_passant, position.en_passant, sizeof(en_passant));
}

canonical_original_code:
void load_position(struct Position position)
{
 memcpy(chessboard, position.chessboard, sizeof(chessboard));
 memcpy(castlings, position.castlings, sizeof(castlings));
 memcpy(en_passant, position.en_passant, sizeof(en_passant));
}

variable_types: struct Position { int chessboard[8][8]; int castlings[4]; int en_passant[2]; }

return_type: void


decompiled_code:
void __fastcall free_moves(int a1, void *a2)
{
if ( a1 > 0 )
free(a2);
}

canonical_decompiled_code:
void __fastcall func2(int a1, void *a2)
{
if ( a1 > 0 )
free(a2);
}

original_code:
void free_moves(Moves moves)
{
 if(moves.count > 0)free(moves.move);
}

canonical_original_code:
void free_moves(struct Moves moves)
{
 if(moves.count > 0)free(moves.move);
}

variable_types: struct Moves { int count; struct Move { int from[2]; int to[2]; _Bool status; } *move; }

user_defined_types: struct Moves { int count; struct Move *move; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
char v5[6]; // [rsp+2Ah] [rbp-2Eh] BYREF
__int128 v6; // [rsp+30h] [rbp-28h] BYREF
int v7; // [rsp+40h] [rbp-18h]

show_header(argc, argv, envp);
init_chessboard();
LABEL_2:
if ( !(unsigned __int8)is_checkmate_or_stalemate() )
{
while ( 1 )
{
human_move = 1;
gets(v5);
if ( (unsigned __int8)is_exit(v5) )
break;
if ( (unsigned __int8)is_help(v5) )
goto LABEL_2;
parse_move((__int64)&v6, v5);
if ( !(_BYTE)v7 )
goto LABEL_2;
play_move(1LL);
if ( !(unsigned __int8)is_checkmate_or_stalemate() )
{
human_move = 0;
get_move(&v6);
play_move(1LL);
print_move(1LL, v5, v3);
show_check();
if ( !(unsigned __int8)is_checkmate_or_stalemate() )
continue;
}
return 0;
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
char v5[6]; // [rsp+2Ah] [rbp-2Eh] BYREF
__int128 v6; // [rsp+30h] [rbp-28h] BYREF
int v7; // [rsp+40h] [rbp-18h]

show_header(argc, argv, envp);
init_chessboard();
LABEL_2:
if ( !(unsigned __int8)is_checkmate_or_stalemate() )
{
while ( 1 )
{
human_move = 1;
gets(v5);
if ( (unsigned __int8)is_exit(v5) )
break;
if ( (unsigned __int8)is_help(v5) )
goto LABEL_2;
func0((__int64)&v6, v5);
if ( !(_BYTE)v7 )
goto LABEL_2;
play_move(1LL);
if ( !(unsigned __int8)is_checkmate_or_stalemate() )
{
human_move = 0;
get_move(&v6);
play_move(1LL);
print_move(1LL, v5, v3);
show_check();
if ( !(unsigned __int8)is_checkmate_or_stalemate() )
continue;
}
return 0;
}
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
 char input[6];
 Move move;
 show_header();
 init_chessboard();
 while(!is_checkmate_or_stalemate())
 {
  human_move = 1;
  gets(input);
  if(is_exit(input))break;
  if(is_help(input))continue;
  move = parse_move(input);
  if(move.status == 0)continue;
  play_move(move, 1);
  if(is_checkmate_or_stalemate())break;
  human_move = 0;
  move = get_move();
  play_move(move, 1);
  print_move(move);
  show_check();
 }
 return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char input[6];
 struct Move move;
 show_header();
 init_chessboard();
 while(!is_checkmate_or_stalemate())
 {
  human_move = 1;
  gets(input);
  if(is_exit(input))break;
  if(is_help(input))continue;
  move = parse_move(input);
  if(move.status == 0)continue;
  play_move(move, 1);
  if(is_checkmate_or_stalemate())break;
  human_move = 0;
  move = get_move();
  play_move(move, 1);
  print_move(move);
  show_check();
 }
 return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
input
char [6]

variable_types: struct Move { int from[2]; int to[2]; _Bool status; }

return_type: int


decompiled_code:
__int64 get_position_value()
{
__int64 v0; // r14
unsigned int v1; // er13
unsigned int i; // er12
__int64 j; // rbx
int v4; // eax
unsigned int v5; // ebp
int v6; // eax

v0 = 0LL;
v1 = 0;
for ( i = 0; i != 8; ++i )
{
for ( j = 0LL; j != 8; ++j )
{
v5 = abs32(chessboard[j + v0]);
v6 = get_side_coeficient(i, (unsigned int)j);
switch ( v5 )
{
case 1u:
v1 += -100 * v6;
break;
case 2u:
v1 += -400 * v6;
break;
case 3u:
v1 += -300 * v6;
break;
case 4u:
v1 += -350 * v6;
break;
case 5u:
v1 += -750 * v6;
break;
}
v4 = position_bonus[j + v0] * v6;
v1 -= v4;
}
v0 += 8LL;
}
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r14
unsigned int v1; // er13
unsigned int i; // er12
__int64 j; // rbx
int v4; // eax
unsigned int v5; // ebp
int v6; // eax

v0 = 0LL;
v1 = 0;
for ( i = 0; i != 8; ++i )
{
for ( j = 0LL; j != 8; ++j )
{
v5 = abs32(chessboard[j + v0]);
v6 = get_side_coeficient(i, (unsigned int)j);
switch ( v5 )
{
case 1u:
v1 += -100 * v6;
break;
case 2u:
v1 += -400 * v6;
break;
case 3u:
v1 += -300 * v6;
break;
case 4u:
v1 += -350 * v6;
break;
case 5u:
v1 += -750 * v6;
break;
}
v4 = position_bonus[j + v0] * v6;
v1 -= v4;
}
v0 += 8LL;
}
return v1;
}

original_code:
int get_position_value()
{
 int value = 0;
 int side = 0;
 int figure;
 for(int col=0; col<8; col++)
 {
  for(int row=0; row<8; row++)
  {
   figure = abs(chessboard[col][row]);
   side = get_side_coeficient(col, row);
   if(figure == 1)value = value - 100*side;
   if(figure == 2)value = value - 400*side;
   if(figure == 3)value = value - 300*side;
   if(figure == 4)value = value - 350*side;
   if(figure == 5)value = value - 750*side;
   value = value - position_bonus[col][row]*side;
  }
 }
 return value;
}

canonical_original_code:
int get_position_value()
{
 int value = 0;
 int side = 0;
 int figure;
 for(int col = 0; col<8; col++)
 {
  for(int row = 0; row<8; row++)
  {
   figure = abs(chessboard[col][row]);
   side = get_side_coeficient(col, row);
   if(figure == 1)value = value - 100*side;
   if(figure == 2)value = value - 400*side;
   if(figure == 3)value = value - 300*side;
   if(figure == 4)value = value - 350*side;
   if(figure == 5)value = value - 750*side;
   value = value - position_bonus[col][row]*side;
  }
 }
 return value;
}

variable_types: value int

variable_types: side int

variable_types: figure int

variable_types: col int

variable_types: row int


decompiled_code:
__int64 __fastcall near_checkmate(int a1)
{
if ( a1 > 15000 )
return (unsigned int)(a1 + 1);
if ( a1 >= -15000 )
return (unsigned int)a1;
return (unsigned int)(a1 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
if ( a1 > 15000 )
return (unsigned int)(a1 + 1);
if ( a1 >= -15000 )
return (unsigned int)a1;
return (unsigned int)(a1 - 1);
}

original_code:
int near_checkmate(int value)
{
 if(value > 15000)value++;
 if(value < -15000)value--;
 return value;
}


decompiled_code:
__int64 __fastcall far_checkmate(int a1)
{
if ( a1 > 15000 )
return (unsigned int)(a1 - 1);
if ( a1 >= -15000 )
return (unsigned int)a1;
return (unsigned int)(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
if ( a1 > 15000 )
return (unsigned int)(a1 - 1);
if ( a1 >= -15000 )
return (unsigned int)a1;
return (unsigned int)(a1 + 1);
}

original_code:
int far_checkmate(int value)
{
 if(value > 15000)value--;
 if(value < -15000)value++;
 return value;
}


alphabeta

decompiled_code:
__int64 __fastcall alphabeta(unsigned int a1, int a2, int a3, int a4)
{
__int64 v6; // r15
__int64 v7; // rdx
const __m128i *v8; // r12
int v9; // eax
const __m128i *v10; // r15
unsigned int v11; // eax
int v12; // eax
int v13; // er12
__int64 v14; // rcx
__int128 v16[18]; // [rsp-100h] [rbp-298h] BYREF
const __m128i *v17; // [rsp+28h] [rbp-170h]
__int64 v18; // [rsp+30h] [rbp-168h]
__int64 v19; // [rsp+38h] [rbp-160h]
char v20[344]; // [rsp+40h] [rbp-158h] BYREF

if ( (unsigned __int8)is_checkmate() )
return 16000 * a1;
if ( a2 > 0 )
{
v6 = get_all_moves(a1);
v18 = v7;
v8 = (const __m128i *)v7;
v19 = v6;
save_position(v20);
v9 = v6;
if ( (int)v6 <= 0 )
{
LABEL_12:
free_moves((unsigned int)v19, v18);
return (unsigned int)a3;
}
v10 = v8;
v17 = (const __m128i *)((char *)v8 + 20 * (unsigned int)(v9 - 1) + 20);
while ( 1 )
{
while ( 1 )
{
v16[16] = (__int128)_mm_loadu_si128(v10);
LODWORD(v16[17]) = v10[1].m128i_i32[0];
play_move(1LL);
if ( !(unsigned int)is_check(a1) )
break;
v10 = (const __m128i *)((char *)v10 + 20);
qmemcpy(v16, v20, 0x118uLL);
load_position();
if ( v17 == v10 )
goto LABEL_12;
}
near_checkmate(a3);
v11 = near_checkmate(a4);
v12 = alphabeta(-a1, (unsigned int)(a2 - 1), v11);
v13 = far_checkmate(v12);
qmemcpy(v16, v20, 8 * v14);
load_position();
if ( a1 == 1 && v13 < a3 )
{
if ( a4 >= v13 )
goto LABEL_16;
}
else
{
if ( a1 != -1 || v13 <= a3 )
goto LABEL_9;
if ( a4 <= v13 )
{
LABEL_16:
free_moves((unsigned int)v19, v18);
return (unsigned int)a4;
}
}
a3 = v13;
LABEL_9:
v10 = (const __m128i *)((char *)v10 + 20);
if ( v17 == v10 )
goto LABEL_12;
}
}
return get_position_value();
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2, int a3, int a4)
{
__int64 v6; // r15
__int64 v7; // rdx
const __m128i *v8; // r12
int v9; // eax
const __m128i *v10; // r15
unsigned int v11; // eax
int v12; // eax
int v13; // er12
__int64 v14; // rcx
__int128 v16[18]; // [rsp-100h] [rbp-298h] BYREF
const __m128i *v17; // [rsp+28h] [rbp-170h]
__int64 v18; // [rsp+30h] [rbp-168h]
__int64 v19; // [rsp+38h] [rbp-160h]
char v20[344]; // [rsp+40h] [rbp-158h] BYREF

if ( (unsigned __int8)is_checkmate() )
return 16000 * a1;
if ( a2 > 0 )
{
v6 = get_all_moves(a1);
v18 = v7;
v8 = (const __m128i *)v7;
v19 = v6;
save_position(v20);
v9 = v6;
if ( (int)v6 <= 0 )
{
LABEL_12:
free_moves((unsigned int)v19, v18);
return (unsigned int)a3;
}
v10 = v8;
v17 = (const __m128i *)((char *)v8 + 20 * (unsigned int)(v9 - 1) + 20);
while ( 1 )
{
while ( 1 )
{
v16[16] = (__int128)_mm_loadu_si128(v10);
LODWORD(v16[17]) = v10[1].m128i_i32[0];
play_move(1LL);
if ( !(unsigned int)is_check(a1) )
break;
v10 = (const __m128i *)((char *)v10 + 20);
qmemcpy(v16, v20, 0x118uLL);
load_position();
if ( v17 == v10 )
goto LABEL_12;
}
func1(a3);
v11 = func1(a4);
v12 = func3(-a1, (unsigned int)(a2 - 1), v11);
v13 = func2(v12);
qmemcpy(v16, v20, 8 * v14);
load_position();
if ( a1 == 1 && v13 < a3 )
{
if ( a4 >= v13 )
goto LABEL_16;
}
else
{
if ( a1 != -1 || v13 <= a3 )
goto LABEL_9;
if ( a4 <= v13 )
{
LABEL_16:
free_moves((unsigned int)v19, v18);
return (unsigned int)a4;
}
}
a3 = v13;
LABEL_9:
v10 = (const __m128i *)((char *)v10 + 20);
if ( v17 == v10 )
goto LABEL_12;
}
}
return func0();
}

original_code:
int alphabeta(int side, int depth, int alpha, int beta)
{
 Moves moves;
 Position position;
 int value;
 if(is_checkmate())return side*16000;
 if(depth <= 0)return get_position_value();
 moves = get_all_moves(side);
 position = save_position();
 for(int i=0; i<moves.count; i++)
 {
  play_move(moves.move[i], 1);
  if(is_check(side) != 0)
  {
   load_position(position);
   continue;
  }
  value = far_checkmate(alphabeta(side*(-1), depth-1, near_checkmate(beta), near_checkmate(alpha)));
  load_position(position);
  if((side == 1 && value < alpha) || (side == -1 && value > alpha))
  {
   alpha = value;
   if((side == 1 && value <= beta) || (side == -1 && value >= beta))
   {
    free_moves(moves);
    return beta;
   }
  }
 }
 free_moves(moves);
 return alpha;
}

canonical_original_code:
int alphabeta(int side, int depth, int alpha, int beta)
{
 struct Moves moves;
 struct Position position;
 int value;
 if(is_checkmate())return side*16000;
 if(depth <= 0)return get_position_value();
 moves = get_all_moves(side);
 position = save_position();
 for(int i = 0; i<moves.count; i++)
 {
  play_move(moves.move[i], 1);
  if(is_check(side) != 0)
  {
   load_position(position);
   continue;
  }
  value = far_checkmate(alphabeta(side*(-1), depth-1, near_checkmate(beta), near_checkmate(alpha)));
  load_position(position);
  if((side == 1 && value < alpha) || (side == -1 && value > alpha))
  {
   alpha = value;
   if((side == 1 && value <= beta) || (side == -1 && value >= beta))
   {
    free_moves(moves);
    return beta;
   }
  }
 }
 free_moves(moves);
 return alpha;
}

variable_types: depth int

variable_types: alpha int

variable_types: beta int

variable_types: i int

user_defined_types: struct Position { int chessboard[8][8]; int castlings[4]; int en_passant[2]; }

user_defined_types: struct Move { int from[2]; int to[2]; _Bool status; }


decompiled_code:
__int64 __fastcall is_exit(const char *a1)
{
if ( strcmp(a1, "exit") )
return 0LL;
puts("Nashledanou");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
if ( strcmp(a1, "exit") )
return 0LL;
puts("Nashledanou");
return 1LL;
}

original_code:
_Bool is_exit(char* input)
{
 if(strcmp(input, "exit") == 0)
 {
  printf("Nashledanou\n");
  return 1;
 }
 return 0;
}

canonical_original_code:
_Bool is_exit(char *input)
{
 if(strcmp(input, "exit") == 0)
 {
  printf("Nashledanou\n");
  return 1;
 }
 return 0;
}

variable_types:
input
char *


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

result = (unsigned int)(a1 - 97);
if ( (unsigned int)result > 7 )
result = 0xFFFFFFFFLL;
return result;
}

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

result = (unsigned int)(a1 - 97);
if ( (unsigned int)result > 7 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int translate_col(char character)
{
 int number = (int)(character - 97);
 if(number > 7 || number < 0)number = -1;
 return number;
}

variable_types: character char

variable_types: number int


decompiled_code:
int show_chessboard()
{
unsigned int *v0; // rbp
unsigned int *v1; // rbx
__int64 v2; // rsi
int result; // eax

v0 = (unsigned int *)(unsigned int)((_DWORD)&chessboard + 32);
do
{
v1 = v0 - 8;
do
{
v2 = *v1++;
printf("%d ", v2);
}
while ( v1 != v0 );
v0 = v1 + 8;
result = putchar(10);
}
while ( v1 != (unsigned int *)((char *)&chessboard + 256) );
return result;
}

canonical_decompiled_code:
int func2()
{
unsigned int *v0; // rbp
unsigned int *v1; // rbx
__int64 v2; // rsi
int result; // eax

v0 = (unsigned int *)(unsigned int)((_DWORD)&chessboard + 32);
do
{
v1 = v0 - 8;
do
{
v2 = *v1++;
printf("%d ", v2);
}
while ( v1 != v0 );
v0 = v1 + 8;
result = putchar(10);
}
while ( v1 != (unsigned int *)((char *)&chessboard + 256) );
return result;
}

original_code:
void show_chessboard()
{
 for(int col = 0; col < 8; col++)
 {
  for(int row = 0; row < 8; row++)
  {
   printf("%d ", chessboard[col][row]);
  }
  printf("\n");
 }
}


decompiled_code:
int __fastcall print_move(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
return printf(
"%c%d %c%d \n",
(unsigned int)(a7 + 97),
(unsigned int)(HIDWORD(a7) + 1),
(unsigned int)(a8 + 97),
(unsigned int)(HIDWORD(a8) + 1));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
return printf(
"%c%d %c%d \n",
(unsigned int)(a7 + 97),
(unsigned int)(HIDWORD(a7) + 1),
(unsigned int)(a8 + 97),
(unsigned int)(HIDWORD(a8) + 1));
}

original_code:
void print_move(Move move)
{
 printf("%c%d %c%d         \n", move.from[0]+97, move.from[1]+1, move.to[0]+97, move.to[1]+1);
}

canonical_original_code:
void print_move(struct Move move)
{
 printf("%c%d %c%d         \n", move.from[0]+97, move.from[1]+1, move.to[0]+97, move.to[1]+1);
}


decompiled_code:
int show_help()
{
return puts(
"Zadani tahu: <odkud> <kam> (napr.: e2 e3)\n"
"Mala rosada: e1 h1\n"
"Velka rosada: e1 a1\n"
"Konec programu: exit\n"
"Napoveda: help");
}

canonical_decompiled_code:
int func4()
{
return puts(
"Zadani tahu: <odkud> <kam> (napr.: e2 e3)\n"
"Mala rosada: e1 h1\n"
"Velka rosada: e1 a1\n"
"Konec programu: exit\n"
"Napoveda: help");
}

original_code:
void show_help()
{
 printf("Zadani tahu: <odkud> <kam> (napr.: e2 e3)\nMala rosada: e1 h1\nVelka rosada: e1 a1\nKonec programu: exit\nNapoveda: help\n");
}


decompiled_code:
__int64 __fastcall is_help(const char *a1)
{
if ( strcmp(a1, "help") )
return 0LL;
show_help();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
if ( strcmp(a1, "help") )
return 0LL;
func4();
return 1LL;
}

original_code:
_Bool is_help(char* input)
{
 if(strcmp(input, "help") == 0)
 {
  show_help();
  return 1;
 }
 return 0;
}

canonical_original_code:
_Bool is_help(char *input)
{
 if(strcmp(input, "help") == 0)
 {
  show_help();
  return 1;
 }
 return 0;
}


decompiled_code:
int show_header()
{
puts(
"ZCU Chess\n"
"\n"
"Jednoduche sachy, vytvorene pod licenci GNU/GPL jako semestralni prace do predmetu KIV/PC\n"
"Autor: Martin Zadrazil <zadram1@gmail.com> v roce 2012\n"
"Zdrojovy kod: https://github.com/ClaryAldringen/ZCUChess\n");
return show_help();
}

canonical_decompiled_code:
int func6()
{
puts(
"ZCU Chess\n"
"\n"
"Jednoduche sachy, vytvorene pod licenci GNU/GPL jako semestralni prace do predmetu KIV/PC\n"
"Autor: Martin Zadrazil <zadram1@gmail.com> v roce 2012\n"
"Zdrojovy kod: https://github.com/ClaryAldringen/ZCUChess\n");
return func4();
}

original_code:
void show_header()
{
 printf("ZCU Chess\n\nJednoduche sachy, vytvorene pod licenci GNU/GPL jako semestralni prace do predmetu KIV/PC\nAutor: Martin Zadrazil <zadram1@gmail.com> v roce 2012\nZdrojovy kod: https://github.com/ClaryAldringen/ZCUChess\n\n");
 show_help();
}


decompiled_code:
int show_check()
{
int result; // eax

if ( !(unsigned int)is_check(0xFFFFFFFFLL) )
{
result = is_check(1LL);
if ( !result )
return result;
return puts("Sach cerny");
}
puts("Sach bily");
result = is_check(1LL);
if ( result )
return puts("Sach cerny");
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax

if ( !(unsigned int)is_check(0xFFFFFFFFLL) )
{
result = is_check(1LL);
if ( !result )
return result;
return puts("Sach cerny");
}
puts("Sach bily");
result = is_check(1LL);
if ( result )
return puts("Sach cerny");
return result;
}

original_code:
void show_check()
{
 if(is_check(-1))printf("Sach bily\n");
 if(is_check(1))printf("Sach cerny\n");
}


decompiled_code:
int show_thinking()
{
return printf("Premyslim...\r");
}

canonical_decompiled_code:
int func8()
{
return printf("Premyslim...\r");
}

original_code:
void show_thinking()
{
 printf("Premyslim...\r");
}


main

repo: claudiughioc/KTracer

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // ebp
char v5; // al
unsigned int v6; // eax
unsigned int v7; // ebx

if ( argc <= 2 || (v3 = atoi(argv[2]), strlen(argv[1]) != 1) )
usage(*argv, argv, envp);
v4 = open("/dev/tracer", 0);
v5 = *argv[1];
if ( v5 == 97 )
{
printf("Add to trace process %d\n", v3);
v6 = ioctl(v4, 0x4004012AuLL, v3);
}
else
{
if ( v5 != 114 )
error("Wrong parameter");
printf("Remove from trace process %d\n", v3);
v6 = ioctl(v4, 0x4004012BuLL, v3);
}
v7 = v6;
printf("Ioctl code %d\n", v6);
if ( v7 )
error("Error on ioctl\n");
close(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // ebp
char v5; // al
unsigned int v6; // eax
unsigned int v7; // ebx

if ( argc <= 2 || (v3 = atoi(argv[2]), strlen(argv[1]) != 1) )
func7(*argv, argv, envp);
v4 = open("/dev/tracer", 0);
v5 = *argv[1];
if ( v5 == 97 )
{
printf("Add to trace process %d\n", v3);
v6 = ioctl(v4, 0x4004012AuLL, v3);
}
else
{
if ( v5 != 114 )
func8("Wrong parameter");
printf("Remove from trace process %d\n", v3);
v6 = ioctl(v4, 0x4004012BuLL, v3);
}
v7 = v6;
printf("Ioctl code %d\n", v6);
if ( v7 )
func8("Error on ioctl\n");
close(v4);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int fd, ret;
 pid_t pid;
 if (argc < 3)
  usage(argv[0]);
 pid = (int)atoi(argv[2]);
 if (strlen(argv[1]) != 1)
  usage(argv[0]);
 fd = open("/dev/tracer", 00);
 switch (argv[1][0]) {
 case 'a':
  printf("Add to trace process %d\n", pid);
  ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | (((1U)) << (0 +8)) | (((42)) << 0) | ((((sizeof(pid_t)))) << ((0 +8)+8))), pid);
  printf("Ioctl code %d\n", ret);
  if(ret)
   error("Error on ioctl\n");
  break;
 case 'r':
  printf("Remove from trace process %d\n", pid);
  ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | (((1U)) << (0 +8)) | (((43)) << 0) | ((((sizeof(pid_t)))) << ((0 +8)+8))), pid);
  printf("Ioctl code %d\n", ret);
  if(ret)
   error("Error on ioctl\n");
  break;
 default:
  error("Wrong parameter");
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fd; int ret;
 int pid;
 if (argc < 3)
  usage(argv[0]);
 pid = (int)atoi(argv[2]);
 if (strlen(argv[1]) != 1)
  usage(argv[0]);
 fd = open("/dev/tracer", 00);
 switch (argv[1][0]) {
 case 'a':
  printf("Add to trace process %d\n", pid);
  ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | (((1U)) << (0 +8)) | (((42)) << 0) | ((((sizeof(pid_t)))) << ((0 +8)+8))), pid);
  printf("Ioctl code %d\n", ret);
  if(ret)
   error("Error on ioctl\n");
  break;
 case 'r':
  printf("Remove from trace process %d\n", pid);
  ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | (((1U)) << (0 +8)) | (((43)) << 0) | ((((sizeof(pid_t)))) << ((0 +8)+8))), pid);
  printf("Ioctl code %d\n", ret);
  if(ret)
   error("Error on ioctl\n");
  break;
 default:
  error("Wrong parameter");
 }
 close(fd);
 return 0;
}

variable_types: fd int

variable_types: ret int

variable_types: pid int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf(
"Usage: %s <options>\n options:\n\tp - print\n\ts string - set buffer\n\tg - get buffer\n\td - down\n\tu - up\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
printf(
"Usage: %s <options>\n options:\n\tp - print\n\ts string - set buffer\n\tg - get buffer\n\td - down\n\tu - up\n",
a1);
exit(1);
}

original_code:
static void usage(const char *argv0)
{
 printf("Usage: %s <options>\n options:\n"
   "\tp - print\n"
   "\ts string - set buffer\n"
   "\tg - get buffer\n"
   "\td - down\n"
   "\tu - up\n", argv0);
 exit(1);
}

canonical_original_code:
static void usage(char *argv0)
{
 printf("Usage: %s <options>\n options:\n"
   "\tp - print\n"
   "\ts string - set buffer\n"
   "\tg - get buffer\n"
   "\td - down\n"
   "\tu - up\n", argv0);
 exit(1);
}


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
static void error(const char *message)
{
 perror(message);
 exit(1);
}

canonical_original_code:
static void error(char *message)
{
 perror(message);
 exit(1);
}

variable_types:
message
char *


main

repo: claudyus/picobgp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // edx
const void *v5; // rcx
socklen_t v6; // er8
int v7; // edi
int result; // eax
unsigned int v9; // eax
int v10; // [rsp+8h] [rbp-180h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-17Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-178h] BYREF
struct sockaddr v13; // [rsp+20h] [rbp-168h] BYREF
__int64 buf; // [rsp+30h] [rbp-158h] BYREF
__int64 v15; // [rsp+38h] [rbp-150h]
fd_set readfds; // [rsp+50h] [rbp-138h] BYREF
struct sigaction v17; // [rsp+D0h] [rbp-B8h] BYREF

sd = socket(2, 2, 0);
if ( sd == -1 )
{
perror("socket(SOCK_DGRAM)");
exit(1);
}
parse_opt((unsigned int)argc, argv);
v17.sa_handler = (__sighandler_t)&signal_handler;
memset(&v17.sa_mask, 0, 0x90uLL);
sigaction(2, &v17, 0LL);
sigaction(10, &v17, 0LL);
sigaction(14, &v17, 0LL);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16_constprop_0(14LL, 1LL, 6LL, &v10, 4LL);
v3 = _bswap_32_constprop_0();
v10 = 1;
*(_DWORD *)&addr.sa_data[2] = v3;
if ( setsockopt(sd, 1, v4, v5, v6) == -1 )
{
perror("setsockopt(SO_BROADCAST)");
exit(1);
}
*(_DWORD *)&addr.sa_data[2] = brd_ip;
if ( bind(sd, &addr, 0x10u) < 0 )
{
perror("bind(&server_sock)");
result = 1;
}
else
{
alarm(3u);
memset(&readfds, 0, sizeof(readfds));
while ( !one_shot )
{
v7 = sd;
readfds.fds_bits[sd / 64] |= 1LL << (sd % 64);
if ( select(v7 + 1, &readfds, 0LL, 0LL, 0LL) != -1 )
{
addr_len = 16;
v9 = recvfrom(sd, &buf, 0x18uLL, 0, &v13, &addr_len);
if ( v9 == -1 )
{
perror("read(&msg)");
exit(1);
}
if ( (_DWORD)v15 != loc_ip )
update_rt(v9);
}
}
let_me_spam();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // edx
const void *v5; // rcx
socklen_t v6; // er8
int v7; // edi
int result; // eax
unsigned int v9; // eax
int v10; // [rsp+8h] [rbp-180h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-17Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-178h] BYREF
struct sockaddr v13; // [rsp+20h] [rbp-168h] BYREF
__int64 buf; // [rsp+30h] [rbp-158h] BYREF
__int64 v15; // [rsp+38h] [rbp-150h]
fd_set readfds; // [rsp+50h] [rbp-138h] BYREF
struct sigaction v17; // [rsp+D0h] [rbp-B8h] BYREF

sd = socket(2, 2, 0);
if ( sd == -1 )
{
perror("socket(SOCK_DGRAM)");
exit(1);
}
parse_opt((unsigned int)argc, argv);
v17.sa_handler = (__sighandler_t)&signal_handler;
memset(&v17.sa_mask, 0, 0x90uLL);
sigaction(2, &v17, 0LL);
sigaction(10, &v17, 0LL);
sigaction(14, &v17, 0LL);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(14LL, 1LL, 6LL, &v10, 4LL);
v3 = func0();
v10 = 1;
*(_DWORD *)&addr.sa_data[2] = v3;
if ( setsockopt(sd, 1, v4, v5, v6) == -1 )
{
perror("setsockopt(SO_BROADCAST)");
exit(1);
}
*(_DWORD *)&addr.sa_data[2] = brd_ip;
if ( bind(sd, &addr, 0x10u) < 0 )
{
perror("bind(&server_sock)");
result = 1;
}
else
{
alarm(3u);
memset(&readfds, 0, sizeof(readfds));
while ( !one_shot )
{
v7 = sd;
readfds.fds_bits[sd / 64] |= 1LL << (sd % 64);
if ( select(v7 + 1, &readfds, 0LL, 0LL, 0LL) != -1 )
{
addr_len = 16;
v9 = recvfrom(sd, &buf, 0x18uLL, 0, &v13, &addr_len);
if ( v9 == -1 )
{
perror("read(&msg)");
exit(1);
}
if ( (_DWORD)v15 != loc_ip )
update_rt(v9);
}
}
let_me_spam();
result = 0;
}
return result;
}

original_code:
int main (int argc, char *argv[]) {
 sd = socket(2, SOCK_DGRAM, 0);
 if (sd == -1) {
  perror("socket(SOCK_DGRAM)");
  exit(1);
 }
 parse_opt(argc, argv);
 struct sigaction handler; memset(&handler, 0, sizeof(struct sigaction));
 handler.__sigaction_handler.sa_handler = signal_handler;
 sigaction(2, &handler, 0);
 sigaction(10, &handler, 0);
 sigaction(14, &handler, 0);
 struct sockaddr_in server_sock; memset(&server_sock, 0, sizeof(struct sockaddr_in));;
 server_sock.sin_family = 2;
 server_sock.sin_port = htons(9876);
 server_sock.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 int broadcast = 1;
 if (setsockopt(sd, 1, 6, &broadcast,
  sizeof(int)) == -1) {
  perror("setsockopt(SO_BROADCAST)");
  exit(1);
 }
 server_sock.sin_addr.s_addr = brd_ip.s_addr;
 if ( bind(sd, (struct sockaddr *) &server_sock, sizeof(server_sock)) < 0 ) {
  perror("bind(&server_sock)");
  return 1;
 }
 alarm(3);
 fd_set fds;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 for (;!one_shot;) {
  ((void) (((&fds)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
  int r = select (sd+1, &fds, ((void *)0), ((void *)0), ((void *)0));
  if (r != -1) {
   bgpmsg msg;
   struct sockaddr_in loc;
   int locl = sizeof(struct sockaddr_in);
   if ((r = recvfrom (sd, &msg, sizeof(bgpmsg), 0, (struct sockaddr *)&loc, &locl)) == -1) {
    perror("read(&msg)");
    exit(1);
   }
   if (msg.loc_addr.s_addr != loc_ip.s_addr)
    update_rt(msg, r);
  }
 }
 let_me_spam();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 sd = socket(2, SOCK_DGRAM, 0);
 if (sd == -1) {
  perror("socket(SOCK_DGRAM)");
  exit(1);
 }
 parse_opt(argc, argv);
 struct sigaction handler; memset(&handler, 0, sizeof(struct sigaction));
 handler.__sigaction_handler.sa_handler = signal_handler;
 sigaction(2, &handler, 0);
 sigaction(10, &handler, 0);
 sigaction(14, &handler, 0);
 struct sockaddr_in server_sock; memset(&server_sock, 0, sizeof(struct sockaddr_in));;
 server_sock.sin_family = 2;
 server_sock.sin_port = htons(9876);
 server_sock.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 int broadcast = 1;
 if (setsockopt(sd, 1, 6, &broadcast,
  sizeof(int)) == -1) {
  perror("setsockopt(SO_BROADCAST)");
  exit(1);
 }
 server_sock.sin_addr.s_addr = brd_ip.s_addr;
 if ( bind(sd, (struct sockaddr *) &server_sock, sizeof(server_sock)) < 0 ) {
  perror("bind(&server_sock)");
  return 1;
 }
 alarm(3);
 struct fd_set fds;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 for (;!one_shot;) {
  ((void) (((&fds)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
  int r = select (sd+1, &fds, ((void *)0), ((void *)0), ((void *)0));
  if (r != -1) {
   struct sbgpmsg msg;
   struct sockaddr_in loc;
   int locl = sizeof(struct sockaddr_in);
   if ((r = recvfrom (sd, &msg, sizeof(bgpmsg), 0, (struct sockaddr *)&loc, &locl)) == -1) {
    perror("read(&msg)");
    exit(1);
   }
   if (msg.loc_addr.s_addr != loc_ip.s_addr)
    update_rt(msg, r);
  }
 }
 let_me_spam();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: broadcast int

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

variable_types: r int

variable_types: struct sbgpmsg { struct in_addr { unsigned int s_addr; } addr; struct in_addr netmask; struct in_addr loc_addr; long l_update; }

variable_types: locl int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sbgpmsg { struct in_addr addr; struct in_addr netmask; struct in_addr loc_addr; long l_update; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
void *__fastcall annips_del(int a1)
{
__m128i *v1; // rax
const __m128i *v2; // roff
void *v3; // rdi
void *result; // rax

v1 = (__m128i *)((char *)ann_ips + 24 * ann_len - 24);
v2 = (const __m128i *)((char *)ann_ips + 24 * a1);
*v1 = _mm_loadu_si128(v2);
v3 = ann_ips;
v1[1].m128i_i64[0] = v2[1].m128i_i64[0];
result = realloc(v3, 24LL * (ann_len - 1));
--ann_len;
ann_ips = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
__m128i *v1; // rax
const __m128i *v2; // roff
void *v3; // rdi
void *result; // rax

v1 = (__m128i *)((char *)ann_ips + 24 * ann_len - 24);
v2 = (const __m128i *)((char *)ann_ips + 24 * a1);
*v1 = _mm_loadu_si128(v2);
v3 = ann_ips;
v1[1].m128i_i64[0] = v2[1].m128i_i64[0];
result = realloc(v3, 24LL * (ann_len - 1));
--ann_len;
ann_ips = result;
return result;
}

original_code:
void annips_del(int id){
 memcpy(&ann_ips[ann_len-1], &ann_ips[id], sizeof(bgpmsg));
 ann_ips = realloc(ann_ips, sizeof(bgpmsg)*(ann_len-1) );
 ann_len --;
}

variable_types: id int


decompiled_code:
__int64 get_if_info()
{
__int64 result; // rax
char v1[20]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v2; // [rsp+14h] [rbp-24h]

strncpy(v1, local_ifname, 0xFuLL);
if ( ioctl(sd, 0x8915uLL, v1) == -1 )
{
perror("ioctl(SIOCGIFADDR)");
exit(1);
}
loc_ip = v2;
ioctl(sd, 0x8919uLL, v1);
result = v2;
brd_ip = v2;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1[20]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v2; // [rsp+14h] [rbp-24h]

strncpy(v1, local_ifname, 0xFuLL);
if ( ioctl(sd, 0x8915uLL, v1) == -1 )
{
perror("ioctl(SIOCGIFADDR)");
exit(1);
}
loc_ip = v2;
ioctl(sd, 0x8919uLL, v1);
result = v2;
brd_ip = v2;
return result;
}

original_code:
void get_if_info(void) {
 struct ifreq ifr;
 strncpy(ifr.ifr_ifrn.ifrn_name, local_ifname, 16 -1);
 if (ioctl(sd, 0x8915, &ifr) == -1) {
  perror("ioctl(SIOCGIFADDR)");
  exit(1);
 }
 loc_ip.s_addr = (*(struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr).sin_addr.s_addr;
 ioctl(sd, 0x8919, &ifr);
 brd_ip.s_addr = (*(struct sockaddr_in *)&ifr.ifr_ifru.ifru_broadaddr).sin_addr.s_addr;
}

canonical_original_code:
void get_if_info() {
 struct ifreq ifr;
 strncpy(ifr.ifr_ifrn.ifrn_name, local_ifname, 16 -1);
 if (ioctl(sd, 0x8915, &ifr) == -1) {
  perror("ioctl(SIOCGIFADDR)");
  exit(1);
 }
 loc_ip.s_addr = (*(struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr).sin_addr.s_addr;
 ioctl(sd, 0x8919, &ifr);
 brd_ip.s_addr = (*(struct sockaddr_in *)&ifr.ifr_ifru.ifru_broadaddr).sin_addr.s_addr;
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
int __fastcall add_ips(char *cp)
{
char *v1; // rax
const char *v2; // r12
char v3; // al
in_addr_t v4; // eax
char *v5; // rax
__m128i v6; // xmm0
__m128i *v7; // rax
in_addr_t v8; // edi
char *v9; // rax
int result; // eax
struct in_addr in[4]; // [rsp+0h] [rbp-38h] BYREF
__int64 v12; // [rsp+10h] [rbp-28h]

v1 = index(cp, 47);
*v1 = 0;
v2 = v1 + 1;
v3 = atoi(v1 + 1);
in[1].s_addr = _bswap_32(-1 << (32 - v3));
inet_aton(cp, in);
v4 = loc_ip;
if ( !loc_ip )
{
get_if_info();
v4 = loc_ip;
}
in[2].s_addr = v4;
if ( (in[0].s_addr & ~in[1].s_addr) != 0 )
{
printf("skip the subnet %s/%s conflicts!\n", cp, v2);
result = 0;
}
else
{
v5 = (char *)realloc(ips, 24LL * (ips_len + 1));
v6 = _mm_loadu_si128((const __m128i *)in);
ips = v5;
v7 = (__m128i *)&v5[24 * ips_len];
*v7 = v6;
v8 = in[0].s_addr;
++ips_len;
v7[1].m128i_i64[0] = v12;
v9 = inet_ntoa((struct in_addr)v8);
result = fprintf(stderr, "add ip to ips %s\n", v9);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *cp)
{
char *v1; // rax
const char *v2; // r12
char v3; // al
in_addr_t v4; // eax
char *v5; // rax
__m128i v6; // xmm0
__m128i *v7; // rax
in_addr_t v8; // edi
char *v9; // rax
int result; // eax
struct in_addr in[4]; // [rsp+0h] [rbp-38h] BYREF
__int64 v12; // [rsp+10h] [rbp-28h]

v1 = index(cp, 47);
*v1 = 0;
v2 = v1 + 1;
v3 = atoi(v1 + 1);
in[1].s_addr = func0(-1 << (32 - v3));
inet_aton(cp, in);
v4 = loc_ip;
if ( !loc_ip )
{
func2();
v4 = loc_ip;
}
in[2].s_addr = v4;
if ( (in[0].s_addr & ~in[1].s_addr) != 0 )
{
printf("skip the subnet %s/%s conflicts!\n", cp, v2);
result = 0;
}
else
{
v5 = (char *)realloc(ips, 24LL * (ips_len + 1));
v6 = _mm_loadu_si128((const __m128i *)in);
ips = v5;
v7 = (__m128i *)&v5[24 * ips_len];
*v7 = v6;
v8 = in[0].s_addr;
++ips_len;
v7[1].m128i_i64[0] = v12;
v9 = inet_ntoa((struct in_addr)v8);
result = fprintf(stderr, "add ip to ips %s\n", v9);
}
return result;
}

original_code:
int add_ips(char *cidr) {
 char *slash = index(cidr, '/');
 *slash = '\0';
 bgpmsg n_ips;
 n_ips.netmask.s_addr =htonl(0xffffffff << (32-atoi(slash+1)));
 inet_aton(cidr, &(n_ips.addr));
 if (loc_ip.s_addr == 0)
  get_if_info();
 n_ips.loc_addr.s_addr = loc_ip.s_addr;
 if (n_ips.addr.s_addr & ~n_ips.netmask.s_addr) {
  printf ("skip the subnet %s/%s conflicts!\n", cidr, slash+1);
  return 0;
 }
 ips = realloc(ips, sizeof(bgpmsg)*(ips_len+1) );
 memcpy(&ips[ips_len], &n_ips, sizeof(bgpmsg));
 ips_len++;
 fprintf(stderr, "add ip to ips %s\n", inet_ntoa(n_ips.addr));
}

canonical_original_code:
int add_ips(char *cidr) {
 char *slash = index(cidr, '/');
 *slash = '\0';
 struct sbgpmsg n_ips;
 n_ips.netmask.s_addr =htonl(0xffffffff << (32-atoi(slash+1)));
 inet_aton(cidr, &(n_ips.addr));
 if (loc_ip.s_addr == 0)
  get_if_info();
 n_ips.loc_addr.s_addr = loc_ip.s_addr;
 if (n_ips.addr.s_addr & ~n_ips.netmask.s_addr) {
  printf ("skip the subnet %s/%s conflicts!\n", cidr, slash+1);
  return 0;
 }
 ips = realloc(ips, sizeof(bgpmsg)*(ips_len+1) );
 memcpy(&ips[ips_len], &n_ips, sizeof(bgpmsg));
 ips_len++;
 fprintf(stderr, "add ip to ips %s\n", inet_ntoa(n_ips.addr));
}

variable_types:
cidr
char *

variable_types:
slash
char *


decompiled_code:
int __fastcall parse_opt(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "i:s:c");
if ( result == -1 )
return result;
if ( result == 105 )
{
strcpy(local_ifname, optarg);
}
else if ( result > 105 )
{
if ( result != 115 )
goto LABEL_12;
add_ips(optarg);
}
else if ( result == 49 )
{
one_shot = 1;
}
else
{
if ( result != 99 )
{
LABEL_12:
fprintf(stderr, "Usage: %s <-i iface> [-1] [-c] [-s X.X.X.X/Y]\n\n", *argv);
fwrite(" -i iface\n", 1uLL, 0xBuLL, stderr);
fwrite(" listen and send routing advertisements on interface iface\n", 1uLL, 0x40uLL, stderr);
fwrite(" -s X.X.X.X/Y\n", 1uLL, 0xFuLL, stderr);
fwrite(" advertise the subnet X.X.X.X/Y\n", 1uLL, 0x25uLL, stderr);
fwrite(" -1\n", 1uLL, 5uLL, stderr);
fwrite(" one-shot: send one routing advertisement and die\n", 1uLL, 0x37uLL, stderr);
fwrite(" -c\n", 1uLL, 5uLL, stderr);
fwrite(" cascade: re-advertise received routes.\n", 1uLL, 0x2DuLL, stderr);
fwrite(" Handle with care: the -c option can lead to routing loops.\n", 1uLL, 0x41uLL, stderr);
exit(1);
}
cascade = 1;
puts("BEWARE! cascade (-c) option can lead to routing loops!");
}
}
}

canonical_decompiled_code:
int __fastcall func4(int argc, char **argv)
{
int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "i:s:c");
if ( result == -1 )
return result;
if ( result == 105 )
{
strcpy(local_ifname, optarg);
}
else if ( result > 105 )
{
if ( result != 115 )
goto LABEL_12;
func3(optarg);
}
else if ( result == 49 )
{
one_shot = 1;
}
else
{
if ( result != 99 )
{
LABEL_12:
fprintf(stderr, "Usage: %s <-i iface> [-1] [-c] [-s X.X.X.X/Y]\n\n", *argv);
fwrite(" -i iface\n", 1uLL, 0xBuLL, stderr);
fwrite(" listen and send routing advertisements on interface iface\n", 1uLL, 0x40uLL, stderr);
fwrite(" -s X.X.X.X/Y\n", 1uLL, 0xFuLL, stderr);
fwrite(" advertise the subnet X.X.X.X/Y\n", 1uLL, 0x25uLL, stderr);
fwrite(" -1\n", 1uLL, 5uLL, stderr);
fwrite(" one-shot: send one routing advertisement and die\n", 1uLL, 0x37uLL, stderr);
fwrite(" -c\n", 1uLL, 5uLL, stderr);
fwrite(" cascade: re-advertise received routes.\n", 1uLL, 0x2DuLL, stderr);
fwrite(" Handle with care: the -c option can lead to routing loops.\n", 1uLL, 0x41uLL, stderr);
exit(1);
}
cascade = 1;
puts("BEWARE! cascade (-c) option can lead to routing loops!");
}
}
}

original_code:
void parse_opt(int argc, char *argv[]) {
 int opt;
 while ((opt = getopt(argc, argv, "i:s:c")) != -1) {
  switch (opt) {
  case 'i':
   strcpy(local_ifname, optarg);
   break;
  case 's':
   add_ips(optarg);
   break;
  case 'c':
   cascade = 1;
   printf("BEWARE! cascade (-c) option can lead to routing loops!\n");
   break;
  case '1':
   one_shot = 1;
   break;
  default:
   fprintf(stderr, "Usage: %s <-i iface>  [-1] [-c] [-s X.X.X.X/Y]\n\n",
     argv[0]);
   fprintf(stderr, "  -i iface\n");
   fprintf(stderr, "      listen and send routing advertisements on interface iface\n");
   fprintf(stderr, "  -s X.X.X.X/Y\n");
   fprintf(stderr, "      advertise the subnet X.X.X.X/Y\n");
   fprintf(stderr, "  -1\n");
   fprintf(stderr, "      one-shot: send one routing advertisement and die\n");
   fprintf(stderr, "  -c\n");
   fprintf(stderr, "      cascade: re-advertise received routes.\n");
   fprintf(stderr, "      Handle with care: the -c option can lead to routing loops.\n");
   exit(1);
  }
 }
}

variable_types: opt int


decompiled_code:
ssize_t __fastcall let_me_spam(__int64 a1, __int64 a2)
{
ssize_t result; // rax
__int64 v3; // rbx
int v4; // ebp
char *v5; // r12
char *v6; // rax
__int64 v7; // rbx
int i; // ebp
char *v9; // rax
struct sockaddr v10[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v10[0].sa_data[6] = 0LL;
v10[0].sa_family = 2;
*(_DWORD *)&v10[0].sa_data[2] = brd_ip;
result = _bswap_16_constprop_0(a1, a2);
*(_WORD *)v10[0].sa_data = result;
if ( ips_len > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
v5 = inet_ntoa(*(struct in_addr *)(ips + v3 + 4));
v6 = inet_ntoa(*(struct in_addr *)(ips + v3));
fprintf(stderr, "advertising %s netmask %s\n", v6, v5);
result = sendto(sd, (const void *)(v3 + ips), 0x18uLL, 0, v10, 0x10u);
if ( result == -1 )
{
LABEL_11:
perror("sendto(&(ips[i]))");
exit(1);
}
++v4;
v3 += 24LL;
}
while ( ips_len > v4 );
}
v7 = 0LL;
for ( i = 0; ann_len > i; v7 += 24LL )
{
result = cascade;
if ( !cascade )
break;
v9 = inet_ntoa(*(struct in_addr *)(ann_ips + v7));
fprintf(stderr, "advertising cascade subnet %s\n", v9);
result = sendto(sd, (const void *)(v7 + ann_ips), 0x18uLL, 0, v10, 0x10u);
if ( result == -1 )
goto LABEL_11;
++i;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(__int64 a1, __int64 a2)
{
ssize_t result; // rax
__int64 v3; // rbx
int v4; // ebp
char *v5; // r12
char *v6; // rax
__int64 v7; // rbx
int i; // ebp
char *v9; // rax
struct sockaddr v10[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v10[0].sa_data[6] = 0LL;
v10[0].sa_family = 2;
*(_DWORD *)&v10[0].sa_data[2] = brd_ip;
result = func0(a1, a2);
*(_WORD *)v10[0].sa_data = result;
if ( ips_len > 0 )
{
v3 = 0LL;
v4 = 0;
do
{
v5 = inet_ntoa(*(struct in_addr *)(ips + v3 + 4));
v6 = inet_ntoa(*(struct in_addr *)(ips + v3));
fprintf(stderr, "advertising %s netmask %s\n", v6, v5);
result = sendto(sd, (const void *)(v3 + ips), 0x18uLL, 0, v10, 0x10u);
if ( result == -1 )
{
LABEL_11:
perror("sendto(&(ips[i]))");
exit(1);
}
++v4;
v3 += 24LL;
}
while ( ips_len > v4 );
}
v7 = 0LL;
for ( i = 0; ann_len > i; v7 += 24LL )
{
result = cascade;
if ( !cascade )
break;
v9 = inet_ntoa(*(struct in_addr *)(ann_ips + v7));
fprintf(stderr, "advertising cascade subnet %s\n", v9);
result = sendto(sd, (const void *)(v7 + ann_ips), 0x18uLL, 0, v10, 0x10u);
if ( result == -1 )
goto LABEL_11;
++i;
}
return result;
}

original_code:
void let_me_spam(void){
 int i;
 struct sockaddr_in raddr; memset(&raddr, 0, sizeof(struct sockaddr_in));;
 raddr.sin_family = 2;
 raddr.sin_addr.s_addr = brd_ip.s_addr;
 raddr.sin_port = htons(9876);
 for (i=0; i < ips_len; i++) {
  fprintf(stderr, "advertising %s netmask %s\n", inet_ntoa(ips[i].addr), inet_ntoa(ips[i].netmask));
  if (sendto(sd, &(ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
 for (i=0; i < ann_len && cascade; i++) {
  fprintf(stderr, "advertising cascade subnet %s\n", inet_ntoa(ann_ips[i].addr));
  if (sendto(sd, &(ann_ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
}

canonical_original_code:
void let_me_spam(){
 int i;
 struct sockaddr_in raddr; memset(&raddr, 0, sizeof(struct sockaddr_in));;
 raddr.sin_family = 2;
 raddr.sin_addr.s_addr = brd_ip.s_addr;
 raddr.sin_port = htons(9876);
 for (i=0; i < ips_len; i++) {
  fprintf(stderr, "advertising %s netmask %s\n", inet_ntoa(ips[i].addr), inet_ntoa(ips[i].netmask));
  if (sendto(sd, &(ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
 for (i=0; i < ann_len && cascade; i++) {
  fprintf(stderr, "advertising cascade subnet %s\n", inet_ntoa(ann_ips[i].addr));
  if (sendto(sd, &(ann_ips[i]), sizeof(bgpmsg), 0,
    (struct sockaddr *) &raddr, sizeof(struct sockaddr_in)) == -1) {
   perror("sendto(&(ips[i]))");
   exit(1);
  }
 }
}

variable_types: i int


decompiled_code:
unsigned int __fastcall signal_handler(__int64 a1, __int64 a2)
{
unsigned int result; // eax

if ( (_DWORD)a1 == 2 )
{
clean_rt(1LL);
puts("Exit due to SIGINT");
close(sd);
exit(0);
}
if ( (_DWORD)a1 == 14 )
{
let_me_spam(a1, a2);
clean_rt(0LL);
result = alarm(3u);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int result; // eax

if ( (_DWORD)a1 == 2 )
{
clean_rt(1LL);
puts("Exit due to SIGINT");
close(sd);
exit(0);
}
if ( (_DWORD)a1 == 14 )
{
func1(a1, a2);
clean_rt(0LL);
result = alarm(3u);
}
return result;
}

original_code:
void signal_handler (int type) {
 switch (type) {
  case 2:
   clean_rt(1);
   printf("Exit due to SIGINT\n");
   close(sd);
   exit(0);
   break;
  case 14:
   let_me_spam();
   clean_rt(0);
   alarm(3);
   break;
  case 10:
   break;
 }
}

canonical_original_code:
void signal_handler(int type) {
 switch (type) {
  case 2:
   clean_rt(1);
   printf("Exit due to SIGINT\n");
   close(sd);
   exit(0);
   break;
  case 14:
   let_me_spam();
   clean_rt(0);
   alarm(3);
   break;
  case 10:
   break;
 }
}

variable_types: type int


decompiled_code:
void __fastcall clean_rt(int a1)
{
__int64 v1; // rbp
time_t v2; // r15
time_t v3; // rax
int *v4; // rbx
int v5; // eax
int v6; // eax
__int64 v7[23]; // [rsp-8h] [rbp-B8h] BYREF

if ( ann_len > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(ann_ips + 24 * v1 + 16);
v3 = time(0LL);
if ( difftime(v3, v2) > 10.0 || a1 )
{
memset(v7, 0, 0x78uLL);
v4 = (int *)(ann_ips + 24 * v1);
LOWORD(v7[5]) = 2;
v5 = *v4;
LOWORD(v7[3]) = 2;
LOWORD(v7[1]) = 2;
HIDWORD(v7[1]) = v5;
v6 = v4[1];
v7[11] = (__int64)&local_ifname;
HIDWORD(v7[5]) = v6;
if ( ioctl(sd, 0x890CuLL, v7) == -1 )
perror("ioctl(SIOCDELRT)");
annips_del((unsigned int)v1);
}
++v1;
}
while ( ann_len > (int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
__int64 v1; // rbp
time_t v2; // r15
time_t v3; // rax
int *v4; // rbx
int v5; // eax
int v6; // eax
__int64 v7[23]; // [rsp-8h] [rbp-B8h] BYREF

if ( ann_len > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(ann_ips + 24 * v1 + 16);
v3 = time(0LL);
if ( difftime(v3, v2) > 10.0 || a1 )
{
memset(v7, 0, 0x78uLL);
v4 = (int *)(ann_ips + 24 * v1);
LOWORD(v7[5]) = 2;
v5 = *v4;
LOWORD(v7[3]) = 2;
LOWORD(v7[1]) = 2;
HIDWORD(v7[1]) = v5;
v6 = v4[1];
v7[11] = (__int64)&local_ifname;
HIDWORD(v7[5]) = v6;
if ( ioctl(sd, 0x890CuLL, v7) == -1 )
perror("ioctl(SIOCDELRT)");
annips_del((unsigned int)v1);
}
++v1;
}
while ( ann_len > (int)v1 );
}
}

original_code:
void clean_rt(int force) {
 int i;
 for (i = 0; i < ann_len; i++) {
  if (difftime(time(((void *)0)), ann_ips[i].l_update) > 10 || force) {
   struct rtentry rtentry; memset(&rtentry, 0, sizeof(struct rtentry));
   ((struct sockaddr_in *)&rtentry.rt_dst)->sin_family = ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_family = ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_family = 2;
   ((struct sockaddr_in *)&rtentry.rt_dst)->sin_addr.s_addr = ann_ips[i].addr.s_addr;
   ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_addr.s_addr = ann_ips[i].netmask.s_addr;
   ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr = 0;
   rtentry.rt_dev = local_ifname;
   if(ioctl (sd, 0x890C, &rtentry) == -1) {
    perror("ioctl(SIOCDELRT)");
   }
   annips_del(i);
  }
 }
}

variable_types: force int

variable_types: struct rtentry { unsigned long rt_pad1; struct sockaddr { unsigned short sa_family; char sa_data[14]; } rt_dst; struct sockaddr rt_gateway; struct sockaddr rt_genmask; unsigned short rt_flags; short rt_pad2; unsigned long rt_pad3; unsigned char rt_tos; unsigned char rt_class; short rt_pad4[3]; short rt_metric; char *rt_dev; unsigned long rt_mtu; unsigned long rt_window; unsigned short rt_irtt; }

user_defined_types: struct rtentry { unsigned long rt_pad1; struct sockaddr rt_dst; struct sockaddr rt_gateway; struct sockaddr rt_genmask; unsigned short rt_flags; short rt_pad2; unsigned long rt_pad3; unsigned char rt_tos; unsigned char rt_class; short rt_pad4[3]; short rt_metric; char *rt_dev; unsigned long rt_mtu; unsigned long rt_window; unsigned short rt_irtt; }


decompiled_code:
__int64 __fastcall update_rt(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
__int64 v8; // rdi
__int64 result; // rax
__int64 v10; // rcx
unsigned __int64 v11; // rdi
__int64 v12; // rdx
__int64 v13[17]; // [rsp+0h] [rbp-88h] BYREF

if ( ann_len <= 0 )
{
memset(v13, 0, 0x78uLL);
v10 = 0LL;
LOWORD(v13[5]) = 2;
LOWORD(v13[3]) = 2;
HIDWORD(v13[1]) = a7;
LOWORD(v13[1]) = 2;
HIDWORD(v13[5]) = HIDWORD(a7);
if ( HIDWORD(a7) == -1 )
{
LOWORD(v13[7]) = 1;
}
else
{
v10 = 3LL;
LOWORD(v13[7]) = 3;
HIDWORD(v13[3]) = a8;
}
v11 = (unsigned int)sd;
v13[11] = (__int64)&local_ifname;
if ( ioctl(sd, 0x890BuLL, v13, v10, 2LL) == -1 )
{
v11 = (unsigned __int64)"ioctl(SIOCADDRT) are you root?";
perror("ioctl(SIOCADDRT) are you root?");
}
result = annips_add(v11, 35083LL, v12);
}
else
{
v8 = ann_ips;
if ( *ann_ips == a7 && *(_DWORD *)(ann_ips + 8LL) == (_DWORD)a8 )
{
puts("update_rt: announce already in ann_ips");
v8 = ann_ips;
}
time((time_t *)(v8 + 16));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
__int64 v8; // rdi
__int64 result; // rax
__int64 v10; // rcx
unsigned __int64 v11; // rdi
__int64 v12; // rdx
__int64 v13[17]; // [rsp+0h] [rbp-88h] BYREF

if ( ann_len <= 0 )
{
memset(v13, 0, 0x78uLL);
v10 = 0LL;
LOWORD(v13[5]) = 2;
LOWORD(v13[3]) = 2;
HIDWORD(v13[1]) = a7;
LOWORD(v13[1]) = 2;
HIDWORD(v13[5]) = HIDWORD(a7);
if ( HIDWORD(a7) == -1 )
{
LOWORD(v13[7]) = 1;
}
else
{
v10 = 3LL;
LOWORD(v13[7]) = 3;
HIDWORD(v13[3]) = a8;
}
v11 = (unsigned int)sd;
v13[11] = (__int64)&local_ifname;
if ( ioctl(sd, 0x890BuLL, v13, v10, 2LL) == -1 )
{
v11 = (unsigned __int64)"ioctl(SIOCADDRT) are you root?";
perror("ioctl(SIOCADDRT) are you root?");
}
result = annips_add(v11, 35083LL, v12);
}
else
{
v8 = ann_ips;
if ( *ann_ips == a7 && *(_DWORD *)(ann_ips + 8LL) == (_DWORD)a8 )
{
puts("update_rt: announce already in ann_ips");
v8 = ann_ips;
}
time((time_t *)(v8 + 16));
result = 0LL;
}
return result;
}

original_code:
int update_rt (bgpmsg flood_msg, int len) {
 int i;
 for (i = 0; i < ann_len; i++) {
  if (memcmp(&ann_ips[i].addr, &(flood_msg.addr), sizeof(struct in_addr)*3) == 0)
   printf ("update_rt: announce already in ann_ips\n");
   time(&ann_ips[i].l_update);
   return 0;
 }
 struct rtentry rtentry; memset(&rtentry, 0, sizeof(struct rtentry));;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_family = ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_family = ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_family = 2;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_addr.s_addr = flood_msg.addr.s_addr;
 ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_addr.s_addr = flood_msg.netmask.s_addr;
 if (flood_msg.netmask.s_addr != 0xffffffff) {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr =flood_msg.loc_addr.s_addr;
  rtentry.rt_flags = 0x0001 | 0x0002;
 } else {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr = 0;
  rtentry.rt_flags = 0x0001;
 }
 rtentry.rt_dev = local_ifname;
 if(ioctl (sd, 0x890B, &rtentry) == -1) {
  perror("ioctl(SIOCADDRT) are you root?");
 }
 annips_add(flood_msg);
}

canonical_original_code:
int update_rt(struct sbgpmsg flood_msg, int len) {
 int i;
 for (i = 0; i < ann_len; i++) {
  if (memcmp(&ann_ips[i].addr, &(flood_msg.addr), sizeof(struct in_addr)*3) == 0)
   printf ("update_rt: announce already in ann_ips\n");
   time(&ann_ips[i].l_update);
   return 0;
 }
 struct rtentry rtentry; memset(&rtentry, 0, sizeof(struct rtentry));;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_family = ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_family = ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_family = 2;
 ((struct sockaddr_in *)&rtentry.rt_dst)->sin_addr.s_addr = flood_msg.addr.s_addr;
 ((struct sockaddr_in *)&rtentry.rt_genmask)->sin_addr.s_addr = flood_msg.netmask.s_addr;
 if (flood_msg.netmask.s_addr != 0xffffffff) {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr =flood_msg.loc_addr.s_addr;
  rtentry.rt_flags = 0x0001 | 0x0002;
 } else {
  ((struct sockaddr_in *)&rtentry.rt_gateway)->sin_addr.s_addr = 0;
  rtentry.rt_flags = 0x0001;
 }
 rtentry.rt_dev = local_ifname;
 if(ioctl (sd, 0x890B, &rtentry) == -1) {
  perror("ioctl(SIOCADDRT) are you root?");
 }
 annips_add(flood_msg);
}

variable_types: len int


repo: clibs/bench

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v4; // [rsp+0h] [rbp-18h]
float v5; // [rsp+4h] [rbp-14h]
float v6; // [rsp+8h] [rbp-10h]
float v7; // [rsp+Ch] [rbp-Ch]

puts("start");
v4 = wall("start", argv);
v5 = cpu();
sleep(5u);
v7 = wall(5LL, argv);
v6 = cpu();
printf(" creation time (wall): %2.2f\n", (float)(v7 - v4));
printf(" creation time (cpu): %2.2f\n", (float)(v6 - v5));
puts("end");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v4; // [rsp+0h] [rbp-18h]
float v5; // [rsp+4h] [rbp-14h]
float v6; // [rsp+8h] [rbp-10h]
float v7; // [rsp+Ch] [rbp-Ch]

puts("start");
v4 = func7("start", argv);
v5 = func8();
sleep(5u);
v7 = func7(5LL, argv);
v6 = func8();
printf(" creation time (wall): %2.2f\n", (float)(v7 - v4));
printf(" creation time (cpu): %2.2f\n", (float)(v6 - v5));
puts("end");
return 0;
}

original_code:
int
main(void) {
  printf("start\n");
  float t1_wall = wall();
  float t1_cpu = cpu();
  sleep(5);
  float t2_wall = wall();
  float t2_cpu = cpu();
  printf("     creation time (wall):   %2.2f\n", t2_wall - t1_wall);
  printf("     creation time (cpu):    %2.2f\n", t2_cpu - t1_cpu);
  printf("end\n");
  return 0;
}

canonical_original_code:
int main() {
  printf("start\n");
  float t1_wall = wall();
  float t1_cpu = cpu();
  sleep(5);
  float t2_wall = wall();
  float t2_cpu = cpu();
  printf("     creation time (wall):   %2.2f\n", t2_wall - t1_wall);
  printf("     creation time (cpu):    %2.2f\n", t2_cpu - t1_cpu);
  printf("end\n");
  return 0;
}


wall

decompiled_code:
float wall()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
float func7()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
float
wall(void) {
  struct timespec tp;
  clock_gettime(4, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

canonical_original_code:
float wall() {
  struct timespec tp;
  clock_gettime(4, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

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

return_type: float


cpu

decompiled_code:
float cpu()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(2, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
float func8()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(2, &v1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
float
cpu(void) {
  struct timespec tp;
  clock_gettime(2, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

canonical_original_code:
float cpu() {
  struct timespec tp;
  clock_gettime(2, &tp);
  return tp.tv_sec + 1e-9 * tp.tv_nsec;
}

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


main

repo: clibs/bytes

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_string_to_bytes(argc, argv, envp);
test_bytes_to_string();
puts(s);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(argc, argv, envp);
func9();
puts(s);
return 0;
}

original_code:
int
main(void) {
  test_string_to_bytes();
  test_bytes_to_string();
  printf("\n  \e[32m\u2713 \e[90mok\e[0m\n\n");
  return 0;
}

canonical_original_code:
int main() {
  test_string_to_bytes();
  test_bytes_to_string();
  printf("\n  \e[32m\u2713 \e[90mok\e[0m\n\n");
  return 0;
}


equal

decompiled_code:
void __fastcall equal(const char *a1, char *a2)
{
if ( strcmp(a1, a2) )
{
fprintf(stderr, "expected: %s\n", a1);
fprintf(stderr, "actual: %s\n", a2);
free(a2);
exit(1);
}
free(a2);
}

canonical_decompiled_code:
void __fastcall func7(const char *a1, char *a2)
{
if ( strcmp(a1, a2) )
{
fprintf(stderr, "expected: %s\n", a1);
fprintf(stderr, "actual: %s\n", a2);
free(a2);
exit(1);
}
free(a2);
}

original_code:
void
equal(char *a, char *b) {
  if (strcmp(a, b)) {
    fprintf(stderr, "expected: %s\n", a);
    fprintf(stderr, "actual: %s\n", b);
    free(b);
    exit(1);
  }
  free(b);
}

variable_types:
a
char *

variable_types:
b
char *


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

if ( string_to_bytes("100") != 100 )
__assert_fail("100 == string_to_bytes(\"100\")", "test.c", 0x15u, "test_string_to_bytes");
if ( string_to_bytes("100b") != 100 )
__assert_fail("100 == string_to_bytes(\"100b\")", "test.c", 0x16u, "test_string_to_bytes");
if ( string_to_bytes("100 bytes") != 100 )
__assert_fail("100 == string_to_bytes(\"100 bytes\")", "test.c", 0x17u, "test_string_to_bytes");
if ( string_to_bytes("1kb") != 1024 )
__assert_fail("1024 == string_to_bytes(\"1kb\")", "test.c", 0x18u, "test_string_to_bytes");
if ( string_to_bytes("1mb") != 0x100000 )
__assert_fail("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 0x19u, "test_string_to_bytes");
if ( string_to_bytes("1gb") != 0x40000000 )
__assert_fail("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 0x1Au, "test_string_to_bytes");
if ( string_to_bytes("2kb") != 2048 )
__assert_fail("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 0x1Bu, "test_string_to_bytes");
result = string_to_bytes("5mb");
if ( result != 5242880 )
__assert_fail("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 0x1Cu, "test_string_to_bytes");
return result;
}

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

if ( func10("100") != 100 )
__assert_fail("100 == string_to_bytes(\"100\")", "test.c", 0x15u, "test_string_to_bytes");
if ( func10("100b") != 100 )
__assert_fail("100 == string_to_bytes(\"100b\")", "test.c", 0x16u, "test_string_to_bytes");
if ( func10("100 bytes") != 100 )
__assert_fail("100 == string_to_bytes(\"100 bytes\")", "test.c", 0x17u, "test_string_to_bytes");
if ( func10("1kb") != 1024 )
__assert_fail("1024 == string_to_bytes(\"1kb\")", "test.c", 0x18u, "test_string_to_bytes");
if ( func10("1mb") != 0x100000 )
__assert_fail("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 0x19u, "test_string_to_bytes");
if ( func10("1gb") != 0x40000000 )
__assert_fail("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 0x1Au, "test_string_to_bytes");
if ( func10("2kb") != 2048 )
__assert_fail("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 0x1Bu, "test_string_to_bytes");
result = func10("5mb");
if ( result != 5242880 )
__assert_fail("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 0x1Cu, "test_string_to_bytes");
return result;
}

original_code:
void
test_string_to_bytes(void) {
  ((100 == string_to_bytes("100")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100\")", "test.c", 21, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100b")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100b\")", "test.c", 22, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100 bytes")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100 bytes\")", "test.c", 23, __extension__ __PRETTY_FUNCTION__));
  ((1024 == string_to_bytes("1kb")) ? (void) (0) : __assert_fail ("1024 == string_to_bytes(\"1kb\")", "test.c", 24, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 == string_to_bytes("1mb")) ? (void) (0) : __assert_fail ("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 25, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 * 1024 == string_to_bytes("1gb")) ? (void) (0) : __assert_fail ("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 26, __extension__ __PRETTY_FUNCTION__));
  ((2 * 1024 == string_to_bytes("2kb")) ? (void) (0) : __assert_fail ("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 27, __extension__ __PRETTY_FUNCTION__));
  ((5 * 1024 * 1024 == string_to_bytes("5mb")) ? (void) (0) : __assert_fail ("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 28, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void test_string_to_bytes() {
  ((100 == string_to_bytes("100")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100\")", "test.c", 21, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100b")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100b\")", "test.c", 22, __extension__ __PRETTY_FUNCTION__));
  ((100 == string_to_bytes("100 bytes")) ? (void) (0) : __assert_fail ("100 == string_to_bytes(\"100 bytes\")", "test.c", 23, __extension__ __PRETTY_FUNCTION__));
  ((1024 == string_to_bytes("1kb")) ? (void) (0) : __assert_fail ("1024 == string_to_bytes(\"1kb\")", "test.c", 24, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 == string_to_bytes("1mb")) ? (void) (0) : __assert_fail ("1024 * 1024 == string_to_bytes(\"1mb\")", "test.c", 25, __extension__ __PRETTY_FUNCTION__));
  ((1024 * 1024 * 1024 == string_to_bytes("1gb")) ? (void) (0) : __assert_fail ("1024 * 1024 * 1024 == string_to_bytes(\"1gb\")", "test.c", 26, __extension__ __PRETTY_FUNCTION__));
  ((2 * 1024 == string_to_bytes("2kb")) ? (void) (0) : __assert_fail ("2 * 1024 == string_to_bytes(\"2kb\")", "test.c", 27, __extension__ __PRETTY_FUNCTION__));
  ((5 * 1024 * 1024 == string_to_bytes("5mb")) ? (void) (0) : __assert_fail ("5 * 1024 * 1024 == string_to_bytes(\"5mb\")", "test.c", 28, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
void test_bytes_to_string()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rsi
char *v5; // rax

v0 = (char *)bytes_to_string(100LL);
equal("100b", v0);
v1 = (char *)bytes_to_string(1024LL);
equal("1kb", v1);
v2 = (char *)bytes_to_string(0x100000LL);
equal("1mb", v2);
v3 = (char *)bytes_to_string(5242880LL);
equal("5mb", v3);
v4 = (char *)bytes_to_string(0x40000000LL);
equal("1gb", v4);
v5 = (char *)bytes_to_string(0x140000000LL);
equal("5gb", v5);
}

original_code:
void
test_bytes_to_string(void) {
  equal("100b", bytes_to_string(100));
  equal("1kb", bytes_to_string(1024));
  equal("1mb", bytes_to_string(1024 * 1024));
  equal("5mb", bytes_to_string(1024 * 1024 * 5));
  equal("1gb", bytes_to_string(1024 * 1024 * 1024));
  equal("5gb", bytes_to_string((long long) 1024 * 1024 * 1024 * 5));
}

canonical_original_code:
void test_bytes_to_string() {
  equal("100b", bytes_to_string(100));
  equal("1kb", bytes_to_string(1024));
  equal("1mb", bytes_to_string(1024 * 1024));
  equal("5mb", bytes_to_string(1024 * 1024 * 5));
  equal("1gb", bytes_to_string(1024 * 1024 * 1024));
  equal("5gb", bytes_to_string((long long) 1024 * 1024 * 1024 * 5));
}


decompiled_code:
__int64 __fastcall string_to_bytes(char *haystack)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = strtoll(haystack, 0LL, 10);
if ( !v1 )
return -1LL;
v2 = v1;
if ( strstr(haystack, "kb") )
return v2 << 10;
if ( strstr(haystack, "mb") )
return v2 << 20;
if ( strstr(haystack, "gb") )
v2 <<= 30;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *haystack)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = strtoll(haystack, 0LL, 10);
if ( !v1 )
return -1LL;
v2 = v1;
if ( strstr(haystack, "kb") )
return v2 << 10;
if ( strstr(haystack, "mb") )
return v2 << 20;
if ( strstr(haystack, "gb") )
v2 <<= 30;
return v2;
}

original_code:
long long
string_to_bytes(const char *str) {
  long long val = strtoll(str, ((void *)0), 10);
  if (!val) return -1;
  if (strstr(str, "kb")) return val * 1024;
  if (strstr(str, "mb")) return val * 1024 * 1024;
  if (strstr(str, "gb")) return val * 1024 * 1024 * 1024;
  return val;
}

canonical_original_code:
long long string_to_bytes(char *str) {
  long long val = strtoll(str, ((void *)0), 10);
  if (!val) return -1;
  if (strstr(str, "kb")) return val * 1024;
  if (strstr(str, "mb")) return val * 1024 * 1024;
  if (strstr(str, "gb")) return val * 1024 * 1024 * 1024;
  return val;
}

variable_types:
str
char *

variable_types:
val
long long

return_type: long long


decompiled_code:
char *__fastcall bytes_to_string(__int64 a1)
{
__int64 v1; // rdx
const char *v2; // rsi
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = a1;
v2 = "%lldb";
if ( a1 <= 1023 )
goto LABEL_4;
if ( a1 <= 0xFFFFF )
{
v1 = a1 >> 10;
v2 = "%lldkb";
LABEL_4:
asprintf(ptr, v2, v1);
return ptr[0];
}
if ( a1 > 0x3FFFFFFF )
asprintf(ptr, "%lldgb", a1 >> 30);
else
asprintf(ptr, "%lldmb", a1 >> 20);
return ptr[0];
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1)
{
__int64 v1; // rdx
const char *v2; // rsi
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = a1;
v2 = "%lldb";
if ( a1 <= 1023 )
goto LABEL_4;
if ( a1 <= 0xFFFFF )
{
v1 = a1 >> 10;
v2 = "%lldkb";
LABEL_4:
asprintf(ptr, v2, v1);
return ptr[0];
}
if ( a1 > 0x3FFFFFFF )
asprintf(ptr, "%lldgb", a1 >> 30);
else
asprintf(ptr, "%lldmb", a1 >> 20);
return ptr[0];
}

original_code:
char *
bytes_to_string(long long bytes) {
  long div = 1;
  char *str, *fmt;
  if (bytes < 1024) { fmt = "%lldb"; }
  else if (bytes < 1024 * 1024) { fmt = "%lldkb"; div = 1024; }
  else if (bytes < 1024 * 1024 * 1024) { fmt = "%lldmb"; div = 1024 * 1024; }
  else { fmt = "%lldgb"; div = 1024 * 1024 * 1024; }
  asprintf(&str, fmt, bytes / div);
  return str;
}

canonical_original_code:
char *bytes_to_string(long long bytes) {
  long div = 1;
  char *str; char *fmt;
  if (bytes < 1024) { fmt = "%lldb"; }
  else if (bytes < 1024 * 1024) { fmt = "%lldkb"; div = 1024; }
  else if (bytes < 1024 * 1024 * 1024) { fmt = "%lldmb"; div = 1024 * 1024; }
  else { fmt = "%lldgb"; div = 1024 * 1024 * 1024; }
  asprintf(&str, fmt, bytes / div);
  return str;
}

variable_types:
bytes
long long

variable_types: div long

variable_types:
fmt
char *

return_type: char *


main

repo: clibs/timestamp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rdx
int v5; // eax

v3 = timestamp(argc, argv, envp);
sleep(5u);
v5 = timestamp(5LL, argv, v4) - v3;
if ( v5 <= 4999 )
__assert_fail("diff >= 5000", "test.c", 0xDu, "main");
if ( v5 > 5009 )
__assert_fail("diff < 5010", "test.c", 0xEu, "main");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rdx
int v5; // eax

v3 = func7(argc, argv, envp);
sleep(5u);
v5 = func7(5LL, argv, v4) - v3;
if ( v5 <= 4999 )
__assert_fail("diff >= 5000", "test.c", 0xDu, "main");
if ( v5 > 5009 )
__assert_fail("diff < 5010", "test.c", 0xEu, "main");
return 0;
}

original_code:
int
main(void) {
  int64_t start = timestamp();
  sleep(5);
  int64_t end = timestamp();
  int diff = end - start;
  ((diff >= 5000) ? (void) (0) : __assert_fail ("diff >= 5000", "test.c", 13, __extension__ __PRETTY_FUNCTION__));
  ((diff < 5010) ? (void) (0) : __assert_fail ("diff < 5010", "test.c", 14, __extension__ __PRETTY_FUNCTION__));
  return 0;
}

canonical_original_code:
int main() {
  long start = timestamp();
  sleep(5);
  long end = timestamp();
  int diff = end - start;
  ((diff >= 5000) ? (void) (0) : __assert_fail ("diff >= 5000", "test.c", 13, __extension__ __PRETTY_FUNCTION__));
  ((diff < 5010) ? (void) (0) : __assert_fail ("diff < 5010", "test.c", 14, __extension__ __PRETTY_FUNCTION__));
  return 0;
}

variable_types: start long

variable_types: end long

variable_types: diff int


timestamp

decompiled_code:
__time_t timestamp()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == -1 )
result = -1LL;
else
result = 1000 * v1.tv_sec + v1.tv_usec / 1000;
return result;
}

canonical_decompiled_code:
__time_t func7()
{
__time_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == -1 )
result = -1LL;
else
result = 1000 * v1.tv_sec + v1.tv_usec / 1000;
return result;
}

original_code:
int64_t
timestamp(void) {
  struct timeval tv;
  int ret = gettimeofday(&tv, ((void *)0));
  if (-1 == ret) return -1;
  return (int64_t) ((int64_t) tv.tv_sec * 1000 + (int64_t) tv.tv_usec / 1000);
}

canonical_original_code:
long timestamp() {
  struct timeval tv;
  int ret = gettimeofday(&tv, ((void *)0));
  if (-1 == ret) return -1;
  return (long) ((long) tv.tv_sec * 1000 + (long) tv.tv_usec / 1000);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: ret int

return_type: long


connectDevice

repo: clickok/iRobotInterface

decompiled_code:
__int64 __fastcall connectDevice(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
struct termios v4; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
perror("Failed to connect to device");
}
else
{
tcgetattr(v1, &v4);
tcgetattr(v2, &termios_p);
*(_QWORD *)&v4.c_iflag = 5LL;
*(_QWORD *)&v4.c_cflag = 2224LL;
cfsetispeed(&v4, 0x1001u);
cfsetospeed(&v4, 0x1001u);
tcsetattr(v2, 0, &v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
struct termios v4; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
perror("Failed to connect to device");
}
else
{
tcgetattr(v1, &v4);
tcgetattr(v2, &termios_p);
*(_QWORD *)&v4.c_iflag = 5LL;
*(_QWORD *)&v4.c_cflag = 2224LL;
cfsetispeed(&v4, 0x1001u);
cfsetospeed(&v4, 0x1001u);
tcsetattr(v2, 0, &v4);
}
return v2;
}

original_code:
int connectDevice(char * device)
{
 int fd;
 struct termios tty, tty_check;
    if(device == ((void *)0)) return -1;
    if((fd = open(device, 02 | 0400 | 04000)) == -1)
    {
     perror("Failed to connect to device");
        return -1;
    }
    tcgetattr(fd, &tty);
    tcgetattr(fd, &tty_check);
    tty.c_iflag = 0000001 | 0000004;
    tty.c_lflag = 0;
    tty.c_oflag = 0;
    tty.c_cflag = 0000200 | 0000060 | 0004000;
    cfsetispeed(&tty, 0010001);
    cfsetospeed(&tty, 0010001);
    tcsetattr(fd, 0, &tty);
    return fd;
}

canonical_original_code:
int connectDevice(char *device)
{
 int fd;
 struct termios tty; struct termios tty_check;
    if(device == ((void *)0)) return -1;
    if((fd = open(device, 02 | 0400 | 04000)) == -1)
    {
     perror("Failed to connect to device");
        return -1;
    }
    tcgetattr(fd, &tty);
    tcgetattr(fd, &tty_check);
    tty.c_iflag = 0000001 | 0000004;
    tty.c_lflag = 0;
    tty.c_oflag = 0;
    tty.c_cflag = 0000200 | 0000060 | 0004000;
    cfsetispeed(&tty, 0010001);
    cfsetospeed(&tty, 0010001);
    tcsetattr(fd, 0, &tty);
    return fd;
}

variable_types:
device
char *

variable_types: fd int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


disconnectDevice

decompiled_code:
__int64 __fastcall disconnectDevice(int a1)
{
if ( a1 < 0 )
return 0xFFFFFFFFLL;
if ( close(a1) != -1 )
return 0LL;
perror("Failed to close connection to device");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
if ( a1 < 0 )
return 0xFFFFFFFFLL;
if ( close(a1) != -1 )
return 0LL;
perror("Failed to close connection to device");
return 0xFFFFFFFFLL;
}

original_code:
int disconnectDevice(int fd)
{
    if(fd < 0) {
        return -1;
    }
    if(close(fd) == -1) {
     perror("Failed to close connection to device");
        return -1;
    }
    fd = -1;
    return 0;
}


askForSensors

decompiled_code:
__int64 __fastcall askForSensors(int fd)
{
char *v1; // rbx
char *v2; // rsi
unsigned int v3; // ebp
int v4; // ebx
ssize_t v5; // rax
unsigned __int8 v7; // [rsp+7h] [rbp-31h] BYREF
int buf; // [rsp+8h] [rbp-30h] BYREF
char v9; // [rsp+Ch] [rbp-2Ch]
char v10; // [rsp+Dh] [rbp-2Bh] BYREF

v9 = 0;
v1 = (char *)&buf;
buf = 691075;
do
{
v2 = v1++;
v3 = write(fd, v2, 1uLL);
usleep(0x2710u);
printf("res = %d\n", v3);
}
while ( v1 != &v10 );
v4 = 9;
do
{
v5 = read(fd, &v7, 1uLL);
printf("res = %d val = %d\n", v5, v7);
--v4;
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
char *v1; // rbx
char *v2; // rsi
unsigned int v3; // ebp
int v4; // ebx
ssize_t v5; // rax
unsigned __int8 v7; // [rsp+7h] [rbp-31h] BYREF
int buf; // [rsp+8h] [rbp-30h] BYREF
char v9; // [rsp+Ch] [rbp-2Ch]
char v10; // [rsp+Dh] [rbp-2Bh] BYREF

v9 = 0;
v1 = (char *)&buf;
buf = 691075;
do
{
v2 = v1++;
v3 = write(fd, v2, 1uLL);
usleep(0x2710u);
printf("res = %d\n", v3);
}
while ( v1 != &v10 );
v4 = 9;
do
{
v5 = read(fd, &v7, 1uLL);
printf("res = %d val = %d\n", v5, v7);
--v4;
}
while ( v4 );
return 0LL;
}

original_code:
int askForSensors(int fd, int * array)
{
 int i;
 int res,e;
 unsigned char buf;
 unsigned char cmd[8];
 int count = 0;
 cmd[count++] = 131;
 cmd[count++] = 139;
 cmd[count++] = 10;
 cmd[count++] = 0;
 cmd[count++] = 0;
 for (i = 0; i < count; ++i)
 {
  res = write(fd, cmd + i, 1);
  usleep(10000);
  printf("res = %d\n",res);
 }
 for (i = 0; i < 9; i++)
 {
  res = read(fd,&buf,1);
  printf("res = %d val = %d\n",res,(int) buf);
 }
 return 0;
}

canonical_original_code:
int askForSensors(int fd, int *array)
{
 int i;
 int res; int e;
 unsigned char buf;
 unsigned char cmd[8];
 int count = 0;
 cmd[count++] = 131;
 cmd[count++] = 139;
 cmd[count++] = 10;
 cmd[count++] = 0;
 cmd[count++] = 0;
 for (i = 0; i < count; ++i)
 {
  res = write(fd, cmd + i, 1);
  usleep(10000);
  printf("res = %d\n",res);
 }
 for (i = 0; i < 9; i++)
 {
  res = read(fd,&buf,1);
  printf("res = %d val = %d\n",res,(int) buf);
 }
 return 0;
}

variable_types:
array
int *

variable_types: i int

variable_types: res int

variable_types: e int

variable_types:
buf
unsigned char

variable_types:
cmd
unsigned char [8]

variable_types: count int


sendByte

decompiled_code:
__int64 __fastcall sendByte(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-(write(a1, buf, 1uLL) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (unsigned int)-(write(a1, buf, 1uLL) != 1);
}

original_code:
int sendByte(int fd, unsigned char byte) {
 int res;
 res = (write(fd, &byte, 1) == 1 ? 0 : -1);
    return res;
}

variable_types:
byte
unsigned char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char s[56]; // [rsp+30h] [rbp-38h] BYREF

puts("******************** iRobot Sensor Calibration **********************");
puts(
"* How this works: *\n"
"* 1) The program will attempt to connect to the device specified by *\n"
"* the command line argument... which you should've entered... *\n"
"* 2) Place Robot in the 'inner' region. The program will read the *\n"
"* infrared sensor values. When prompted, move the robot (while *\n"
"* keeping it in the same region) so it can collect an average. *\n"
"* 3) When prompted, move the robot to the 'outer' region, and *\n"
"* follow the same process as in Step (1). *\n"
"* 4) The program will then compute an average for the two regions *\n"
"* (allowing for some margin to account for variability) and save *\n"
"* the result as 'calibration.dat', or tell you if it's not *\n"
"* possible to distinguish the two regions. *\n"
"*********************************************************************");
puts("\nSTEP 1)");
v3 = connectDevice(argv[1]);
fd = v3;
if ( v3 >= 0 )
printf("Connected to device with file descriptor: %d\n", (unsigned int)v3);
puts("STEP 2)");
puts("Place Robot in region one.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(s, 40, _bss_start);
askForSensors(fd);
puts("STEP 3)");
puts("Place Robot in region two.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(s, 40, _bss_start);
puts("STEP 4)");
disconnectDevice((unsigned int)fd);
printf("Disconnected from device. File descriptor is now: %d\n", (unsigned int)fd);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char s[56]; // [rsp+30h] [rbp-38h] BYREF

puts("******************** iRobot Sensor Calibration **********************");
puts(
"* How this works: *\n"
"* 1) The program will attempt to connect to the device specified by *\n"
"* the command line argument... which you should've entered... *\n"
"* 2) Place Robot in the 'inner' region. The program will read the *\n"
"* infrared sensor values. When prompted, move the robot (while *\n"
"* keeping it in the same region) so it can collect an average. *\n"
"* 3) When prompted, move the robot to the 'outer' region, and *\n"
"* follow the same process as in Step (1). *\n"
"* 4) The program will then compute an average for the two regions *\n"
"* (allowing for some margin to account for variability) and save *\n"
"* the result as 'calibration.dat', or tell you if it's not *\n"
"* possible to distinguish the two regions. *\n"
"*********************************************************************");
puts("\nSTEP 1)");
v3 = func7(argv[1]);
fd = v3;
if ( v3 >= 0 )
printf("Connected to device with file descriptor: %d\n", (unsigned int)v3);
puts("STEP 2)");
puts("Place Robot in region one.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(s, 40, _bss_start);
func9(fd);
puts("STEP 3)");
puts("Place Robot in region two.");
printf("Collecting sample %d of %d\n", 1LL, 1LL);
puts("When ready to sample, press <return>");
fgets(s, 40, _bss_start);
puts("STEP 4)");
func8((unsigned int)fd);
printf("Disconnected from device. File descriptor is now: %d\n", (unsigned int)fd);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 int i,ret;
 int sensors[10];
 char line[40];
 char cmd[8];
 char * p;
 printf("******************** iRobot Sensor Calibration **********************\n");
 printf( "* How this works:                                                   *\n"
   "* 1) The program will attempt to connect to the device specified by *\n"
   "*    the command line argument... which you should've entered...    *\n"
   "* 2) Place Robot in the 'inner' region. The program will read the   *\n"
   "*    infrared sensor values. When prompted, move the robot (while   *\n"
   "*    keeping it in the same region) so it can collect an average.   *\n"
   "* 3) When prompted, move the robot to the 'outer' region, and       *\n"
   "*    follow the same process as in Step (1).                        *\n"
   "* 4) The program will then compute an average for the two regions   *\n"
   "*    (allowing for some margin to account for variability) and save *\n"
   "*    the result as 'calibration.dat', or tell you if it's not       *\n"
   "*    possible to distinguish the two regions.                       *\n"
   "*********************************************************************\n"
   );
 printf("\nSTEP 1)\n");
 fd = connectDevice(argv[1]);
 if (fd > -1) printf("Connected to device with file descriptor: %d\n",fd);
 printf("STEP 2)\n");
 printf("Place Robot in region one.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
  ret = askForSensors(fd,sensors);
 }
 printf("STEP 3)\n");
 printf("Place Robot in region two.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
 }
 printf("STEP 4)\n");
 cmd[0] = 150;
 cmd[1] = 0;
 disconnectDevice(fd);
 printf("Disconnected from device. File descriptor is now: %d\n",fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i; int ret;
 int sensors[10];
 char line[40];
 char cmd[8];
 char *p;
 printf("******************** iRobot Sensor Calibration **********************\n");
 printf( "* How this works:                                                   *\n"
   "* 1) The program will attempt to connect to the device specified by *\n"
   "*    the command line argument... which you should've entered...    *\n"
   "* 2) Place Robot in the 'inner' region. The program will read the   *\n"
   "*    infrared sensor values. When prompted, move the robot (while   *\n"
   "*    keeping it in the same region) so it can collect an average.   *\n"
   "* 3) When prompted, move the robot to the 'outer' region, and       *\n"
   "*    follow the same process as in Step (1).                        *\n"
   "* 4) The program will then compute an average for the two regions   *\n"
   "*    (allowing for some margin to account for variability) and save *\n"
   "*    the result as 'calibration.dat', or tell you if it's not       *\n"
   "*    possible to distinguish the two regions.                       *\n"
   "*********************************************************************\n"
   );
 printf("\nSTEP 1)\n");
 fd = connectDevice(argv[1]);
 if (fd > -1) printf("Connected to device with file descriptor: %d\n",fd);
 printf("STEP 2)\n");
 printf("Place Robot in region one.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
  ret = askForSensors(fd,sensors);
 }
 printf("STEP 3)\n");
 printf("Place Robot in region two.\n");
 for(i=0;i<1;++i)
 {
  printf("Collecting sample %d of %d\n",(i+1),1);
  printf("When ready to sample, press <return>\n");
  p = fgets(line,40,stdin);
 }
 printf("STEP 4)\n");
 cmd[0] = 150;
 cmd[1] = 0;
 disconnectDevice(fd);
 printf("Disconnected from device. File descriptor is now: %d\n",fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
sensors
int [10]

variable_types:
line
char [40]

variable_types:
cmd
char [8]

variable_types:
p
char *


repo: cliffeh/punky

decompiled_code:
const char *__fastcall type_to_string(int a1)
{
const char *result; // rax

if ( a1 == 64 )
return "FUN";
if ( a1 <= 64 )
{
if ( (unsigned int)(a1 - 1) > 0x1F )
{
LABEL_11:
result = "UNKNOWN";
}
else
{
switch ( a1 )
{
case 1:
result = "LIST";
break;
case 2:
result = "INTEGER";
break;
case 4:
result = "FLOAT";
break;
case 8:
result = "STRING";
break;
case 16:
result = "IDENT";
break;
case 32:
result = "OP";
break;
default:
goto LABEL_11;
}
}
}
else if ( a1 == 2048 )
{
result = "<<EOF>>";
}
else if ( a1 <= 2048 )
{
result = "RE";
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = "NIL";
}
else
{
result = "UNKNOWN";
if ( a1 == 128 )
result = "PORT";
}
}
}
else
{
result = "ERR";
if ( a1 != 4096 )
{
result = "UNKNOWN";
if ( a1 == 24576 )
result = "BOOL";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
const char *result; // rax

if ( a1 == 64 )
return "FUN";
if ( a1 <= 64 )
{
if ( (unsigned int)(a1 - 1) > 0x1F )
{
LABEL_11:
result = "UNKNOWN";
}
else
{
switch ( a1 )
{
case 1:
result = "LIST";
break;
case 2:
result = "INTEGER";
break;
case 4:
result = "FLOAT";
break;
case 8:
result = "STRING";
break;
case 16:
result = "IDENT";
break;
case 32:
result = "OP";
break;
default:
goto LABEL_11;
}
}
}
else if ( a1 == 2048 )
{
result = "<<EOF>>";
}
else if ( a1 <= 2048 )
{
result = "RE";
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = "NIL";
}
else
{
result = "UNKNOWN";
if ( a1 == 128 )
result = "PORT";
}
}
}
else
{
result = "ERR";
if ( a1 != 4096 )
{
result = "UNKNOWN";
if ( a1 == 24576 )
result = "BOOL";
}
}
return result;
}

original_code:
char *type_to_string(int t)
{
  switch(t) {
  case (1<<0): return "LIST";
  case ((1<<13)|(1<<14)): return "BOOL";
  case (1<<1): return "INTEGER";
  case (1<<2): return "FLOAT";
  case (1<<3): return "STRING";
  case (1<<4): return "IDENT";
  case (1<<5): return "OP";
  case (1<<6): return "FUN";
  case (1<<7): return "PORT";
  case (1<<9): return "RE";
  case (1<<10): return "NIL";
  case (1<<12): return "ERR";
  case (1<<11): return "<<EOF>>";
  default: return "UNKNOWN";
  }
}

variable_types: t int


yywrap

decompiled_code:
__int64 yywrap()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
int yywrap()
{
  return(1);
}

canonical_original_code:
int yywrap()
{
  return(1);
}


decompiled_code:
__int64 __fastcall redir_lenth(char *a1)
{
_BOOL8 v1; // rbp
__int64 v2; // r12
_BOOL8 v3; // rbp

v1 = byte_4F4[my_strilen(byte_4F4, (unsigned int)*a1)] != 0;
v2 = v1 + 1;
if ( a1[v1 + 1] != 38 || a1[v1] == 60 )
{
v2 -= (byte_4F8[my_strilen(byte_4F8, (unsigned int)a1[v1 + 1])] == 0) - 1LL;
}
else if ( byte_4F4[my_strilen(byte_4F4, (unsigned int)a1[v1 + 2])] )
{
v3 = v1 + 3;
if ( asc_4FB[my_strilen(" \t\"'|&;()`", (unsigned int)a1[v3])] )
{
v2 = v3;
}
else if ( !a1[v3] )
{
v2 = v3;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
_BOOL8 v1; // rbp
__int64 v2; // r12
_BOOL8 v3; // rbp

v1 = byte_4F4[my_strilen(byte_4F4, (unsigned int)*a1)] != 0;
v2 = v1 + 1;
if ( a1[v1 + 1] != 38 || a1[v1] == 60 )
{
v2 -= (byte_4F8[my_strilen(byte_4F8, (unsigned int)a1[v1 + 1])] == 0) - 1LL;
}
else if ( byte_4F4[my_strilen(byte_4F4, (unsigned int)a1[v1 + 2])] )
{
v3 = v1 + 3;
if ( asc_4FB[my_strilen(" \t\"'|&;()`", (unsigned int)a1[v3])] )
{
v2 = v3;
}
else if ( !a1[v3] )
{
v2 = v3;
}
}
return v2;
}

variable_types:
s
char *

variable_types:
n
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall work_on_quote(char *a1, _QWORD *a2)
{
__int64 v3; // rsi
char v5; // [rsp+Dh] [rbp-1Bh] BYREF
__int16 v6; // [rsp+Eh] [rbp-1Ah]

v3 = (unsigned int)*a1;
v6 = 39;
v5 = v3;
if ( !a1[my_strilen(a1 + 1, v3) + 1] )
*a2 = my_strcat("(sh): unexpected EOS while looking for matching `", &v5);
return my_strilen(a1 + 1, (unsigned int)v5) + 2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, _QWORD *a2)
{
__int64 v3; // rsi
char v5; // [rsp+Dh] [rbp-1Bh] BYREF
__int16 v6; // [rsp+Eh] [rbp-1Ah]

v3 = (unsigned int)*a1;
v6 = 39;
v5 = v3;
if ( !a1[my_strilen(a1 + 1, v3) + 1] )
*a2 = my_strcat("(sh): unexpected EOS while looking for matching `", &v5);
return my_strilen(a1 + 1, (unsigned int)v5) + 2;
}

original_code:
static size_t work_on_quote(char *s, char **bad_sintax)
{
  char quote[3];
  quote[0] = s[0];
  quote[1] = '\'';
  quote[2] = 0;
  if (!((s + 1)[my_strilen(s + 1, quote[0])] != 0))
    *bad_sintax = my_strcat("(sh): unexpected EOS while looking for matching `", quote);
  return (my_strilen(s + 1, quote[0]) + 2);
}

canonical_original_code:
static unsigned long work_on_quote(char *s, char **bad_sintax)
{
  char quote[3];
  quote[0] = s[0];
  quote[1] = '\'';
  quote[2] = 0;
  if (!((s + 1)[my_strilen(s + 1, quote[0])] != 0))
    *bad_sintax = my_strcat("(sh): unexpected EOS while looking for matching `", quote);
  return (my_strilen(s + 1, quote[0]) + 2);
}

variable_types:
quote
char [3]


subdiv

decompiled_code:
__int64 __fastcall subdiv(char *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned __int64 v6; // rbx
__int64 v7; // r8
__int64 result; // rax
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rax
unsigned __int64 v12; // rbx

if ( a1 )
{
v2 = my_strlen("||");
if ( !(unsigned int)my_strncmp("||", a1, v2) )
return 2LL;
v3 = my_strlen("&&");
if ( !(unsigned int)my_strncmp("&&", a1, v3) )
return 2LL;
v4 = my_strlen("<<");
if ( !(unsigned int)my_strncmp("<<", a1, v4) )
return 2LL;
v5 = my_strlen(">>");
if ( !(unsigned int)my_strncmp(">>", a1, v5) )
return 2LL;
}
v6 = my_sstrlen(a1, byte_4F8);
if ( v6 < my_sstrlen(a1, " \\\t\"'|&;()`") && (my_sstrlen(a1, byte_4F8) == 1 || !my_sstrlen(a1, byte_4F8)) )
return redir_lenth(a1);
if ( *a1 == 34 || *a1 == 39 )
return work_on_quote(a1, a2);
v7 = my_strilen(";|&<>()`", (unsigned int)*a1);
result = 1LL;
if ( !asc_515[v7] )
{
my_strilen(a1, 38LL);
v9 = my_strilen(a1, 38LL);
v10 = my_strlen(&a1[v9]);
v11 = my_strilen(a1, 38LL);
if ( (unsigned int)my_strncmp(&a1[v11], "&&", v10)
|| (v12 = my_strilen(a1, 38LL), v12 >= my_sstrlen(a1, " \\\t\"'|;<>()`")) )
{
result = my_sstrlen(a1, " \\\t\"'|&;<>()`");
}
else
{
result = my_strilen(a1, 38LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned __int64 v6; // rbx
__int64 v7; // r8
__int64 result; // rax
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rax
unsigned __int64 v12; // rbx

if ( a1 )
{
v2 = my_strlen("||");
if ( !(unsigned int)my_strncmp("||", a1, v2) )
return 2LL;
v3 = my_strlen("&&");
if ( !(unsigned int)my_strncmp("&&", a1, v3) )
return 2LL;
v4 = my_strlen("<<");
if ( !(unsigned int)my_strncmp("<<", a1, v4) )
return 2LL;
v5 = my_strlen(">>");
if ( !(unsigned int)my_strncmp(">>", a1, v5) )
return 2LL;
}
v6 = my_sstrlen(a1, byte_4F8);
if ( v6 < my_sstrlen(a1, " \\\t\"'|&;()`") && (my_sstrlen(a1, byte_4F8) == 1 || !my_sstrlen(a1, byte_4F8)) )
return func0(a1);
if ( *a1 == 34 || *a1 == 39 )
return func1(a1, a2);
v7 = my_strilen(";|&<>()`", (unsigned int)*a1);
result = 1LL;
if ( !asc_515[v7] )
{
my_strilen(a1, 38LL);
v9 = my_strilen(a1, 38LL);
v10 = my_strlen(&a1[v9]);
v11 = my_strilen(a1, 38LL);
if ( (unsigned int)my_strncmp(&a1[v11], "&&", v10)
|| (v12 = my_strilen(a1, 38LL), v12 >= my_sstrlen(a1, " \\\t\"'|;<>()`")) )
{
result = my_sstrlen(a1, " \\\t\"'|&;<>()`");
}
else
{
result = my_strilen(a1, 38LL);
}
}
return result;
}


subdivide

decompiled_code:
__int64 __fastcall subdivide(char *a1, _QWORD *a2, _QWORD *a3)
{
char *v4; // rbp
_QWORD *v5; // rax
_BYTE *v6; // r12
_QWORD *v7; // rax
__int64 v8; // rax
__int64 v9; // rsi
char v10; // si
__int64 v12; // rax
__int64 v13; // rax
_QWORD *v14; // rax
__int64 v15; // rcx
_QWORD *v16; // rdx

v4 = a1;
if ( (unsigned __int8)empty() )
return (__int64)a2;
if ( *a1 == 92 )
{
if ( a2 )
{
if ( !asc_542[my_strslen("\"'|;<>()`", *a2)] )
{
v15 = 0LL;
v16 = a3;
return echappment(v4, a2, v16, v15);
}
v5 = (_QWORD *)xmalloc(32LL);
v6 = v5;
if ( v5 )
{
v5[2] = 0LL;
*v5 = 0LL;
v5[3] = a2;
LABEL_9:
a2[2] = v6;
goto LABEL_10;
}
}
else
{
v14 = (_QWORD *)xmalloc(32LL);
v6 = v14;
if ( v14 )
{
v14[2] = 0LL;
*v14 = 0LL;
v14[3] = 0LL;
goto LABEL_10;
}
}
return 0LL;
}
v7 = (_QWORD *)xmalloc(32LL);
v6 = v7;
if ( !v7 )
return 0LL;
v7[2] = 0LL;
*v7 = 0LL;
v7[3] = a2;
if ( a2 )
goto LABEL_9;
LABEL_10:
v8 = hempty(a1);
v6[8] = 0;
v4 = &a1[v8];
if ( a1[v8] != 92 )
{
v9 = subdiv(v4, a3);
if ( *a3 || (v12 = my_strndup(v4, v9), (*(_QWORD *)v6 = v12) == 0LL) )
{
v10 = 0;
return nullify_link_constprop_0(v6, v10);
}
v13 = my_strlen(v12);
if ( !subdivide(&v4[v13], v6, a3) )
{
v10 = 1;
return nullify_link_constprop_0(v6, v10);
}
return (__int64)v6;
}
v15 = 1LL;
v16 = a3;
a2 = v6;
return echappment(v4, a2, v16, v15);
}

original_code:
t_get *subdivide(char *s, t_get *prev, char **bad_sintax)
{
  size_t l;
  t_get *link;
  if (empty(s))
    return (prev);
  if (s[0] == '\\' && prev)
    if ((!(("\"'|;<>()`")[my_strslen("\"'|;<>()`", prev->word)] != 0)))
      return (echappment(s, prev, bad_sintax, 0));
  if ((link = xmalloc(sizeof(*prev))) == ((void *)0))
    return (((void *)0));
  link->word = (void*)(link->next = ((void *)0));
  link->prev = prev;
  if (prev)
    prev->next = link;
  s += hempty(s);
  if (s[(link->inter = 0)] == '\\')
    return (echappment(s, link, bad_sintax, 1));
  l = subdiv(s, bad_sintax);
  if (*bad_sintax)
    return (nullify_link(link, 0, 1));
  if ((link->word = my_strndup(s, l)) == ((void *)0))
    return (nullify_link(link, 0, 1));
  if (subdivide(s + my_strlen(link->word), link, bad_sintax) == ((void *)0))
    return (nullify_link(link, 1, 1));
  return (link);
}

canonical_original_code:
struct s_get *subdivide(char *s, struct s_get *prev, char **bad_sintax)
{
  unsigned long l;
  struct s_get *link;
  if (empty(s))
    return (prev);
  if (s[0] == '\\' && prev)
    if ((!(("\"'|;<>()`")[my_strslen("\"'|;<>()`", prev->word)] != 0)))
      return (echappment(s, prev, bad_sintax, 0));
  if ((link = xmalloc(sizeof(*prev))) == ((void *)0))
    return (((void *)0));
  link->word = (void *)(link->next = ((void *)0));
  link->prev = prev;
  if (prev)
    prev->next = link;
  s += hempty(s);
  if (s[(link->inter = 0)] == '\\')
    return (echappment(s, link, bad_sintax, 1));
  l = subdiv(s, bad_sintax);
  if (*bad_sintax)
    return (nullify_link(link, 0, 1));
  if ((link->word = my_strndup(s, l)) == ((void *)0))
    return (nullify_link(link, 0, 1));
  if (subdivide(s + my_strlen(link->word), link, bad_sintax) == ((void *)0))
    return (nullify_link(link, 1, 1));
  return (link);
}

variable_types:
prev
struct s_get *

variable_types:
l
unsigned long

variable_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *


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

if ( a1 )
result = my_putstr(a2, a1);
else
result = my_putstr(a2, 1LL);
return result;
}

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

if ( a1 )
result = my_putstr(a2, a1);
else
result = my_putstr(a2, 1LL);
return result;
}

original_code:
static void aff_str_cmd(int fd, char *str)
{
  if (fd == 0)
    my_putstr(str, 1);
  else
    my_putstr(str, fd);
}

variable_types: fd int

variable_types:
str
char *


decompiled_code:
__int64 __fastcall aff_char_cmd(unsigned int a1, char a2)
{
__int64 v3; // rdi
__int64 result; // rax

v3 = (unsigned int)a2;
if ( a1 )
result = my_putchar(v3, a1);
else
result = my_putchar(v3, 1LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, char a2)
{
__int64 v3; // rdi
__int64 result; // rax

v3 = (unsigned int)a2;
if ( a1 )
result = my_putchar(v3, a1);
else
result = my_putchar(v3, 1LL);
return result;
}

original_code:
static void aff_char_cmd(int fd, char chr)
{
  if (fd == 0)
    my_putchar(chr, 1);
  else
    my_putchar(chr, fd);
}

variable_types: chr char