decompiled_code:
__int64 __fastcall tcp_get_adress(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 4) || *(_WORD *)(a1 + 8) )
{
result = *(_QWORD *)(a1 + 4);
*a2 = result;
}
else
{
*a2 = 0LL;
}
return result;
}

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

if ( *(_DWORD *)(a1 + 4) || *(_WORD *)(a1 + 8) )
{
result = *(_QWORD *)(a1 + 4);
*a2 = result;
}
else
{
*a2 = 0LL;
}
return result;
}

original_code:
void tcp_get_adress(TCP *sock, IP *res)
{
  if(!((sock)->ip.host == 0 && (sock)->ip.port == 0))
    memcpy(res, &sock->ip, sizeof(IP));
  else
    memset(res, 0, sizeof(IP));
  return;
}

canonical_original_code:
void tcp_get_adress(struct TCP *sock, struct IP *res)
{
  if(!((sock)->ip.host == 0 && (sock)->ip.port == 0))
    memcpy(res, &sock->ip, sizeof(IP));
  else
    memset(res, 0, sizeof(IP));
  return;
}

variable_types: struct TCP { int id; struct IP { unsigned int host; unsigned short port; } ip; } *

variable_types:
res
struct IP *


repo: Wescoeur/Reversi

decompiled_code:
ssize_t __fastcall tcp_send(__int64 a1, const void *a2, int a3)
{
ssize_t result; // rax

if ( *(_DWORD *)(a1 + 4) || *(_WORD *)(a1 + 8) )
result = send(*(_DWORD *)a1, a2, a3, 0);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func5(__int64 a1, const void *a2, int a3)
{
ssize_t result; // rax

if ( *(_DWORD *)(a1 + 4) || *(_WORD *)(a1 + 8) )
result = send(*(_DWORD *)a1, a2, a3, 0);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int tcp_send(TCP *sock, void *data, int len)
{
  if(((sock)->ip.host == 0 && (sock)->ip.port == 0))
    return -1;
  return send(sock->id, data, len, 0);
}

canonical_original_code:
int tcp_send(struct TCP *sock, void *data, int len)
{
  if(((sock)->ip.host == 0 && (sock)->ip.port == 0))
    return -1;
  return send(sock->id, data, len, 0);
}

variable_types:
data
void *

variable_types: len int

return_type: int

user_defined_types: struct IP { unsigned int host; unsigned short port; }


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

if ( *(_DWORD *)(a1 + 4) || *(_WORD *)(a1 + 8) )
result = recv(*(_DWORD *)a1, a2, a3, 0);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( *(_DWORD *)(a1 + 4) || *(_WORD *)(a1 + 8) )
result = recv(*(_DWORD *)a1, a2, a3, 0);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int tcp_recv(TCP *sock, void *data, int len)
{
  if(((sock)->ip.host == 0 && (sock)->ip.port == 0))
    return -1;
  return recv(sock->id, data, len, 0);
}

canonical_original_code:
int tcp_recv(struct TCP *sock, void *data, int len)
{
  if(((sock)->ip.host == 0 && (sock)->ip.port == 0))
    return -1;
  return recv(sock->id, data, len, 0);
}


decompiled_code:
void __fastcall tcp_close(void *ptr)
{
int v2; // edi

if ( ptr )
{
v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
int v2; // edi

if ( ptr )
{
v2 = *(_DWORD *)ptr;
if ( v2 != -1 )
close(v2);
free(ptr);
}
}

original_code:
void tcp_close(TCP *sock)
{
  if(sock == ((void *)0))
    return;
  if(sock->id != -1)
    close(sock->id);
  free(sock);
  return;
}

canonical_original_code:
void tcp_close(struct TCP *sock)
{
  if(sock == ((void *)0))
    return;
  if(sock->id != -1)
    close(sock->id);
  free(sock);
  return;
}

return_type: void


cleanbuf

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

do
result = getchar();
while ( result != 10 && result != -1 );
return result;
}

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

do
result = getchar();
while ( result != 10 && result != -1 );
return result;
}

original_code:
void cleanbuf()
{
  int c = 0;
  while(c != '\n' && c != (-1))
    c = getchar();
  return;
}

variable_types: c int


decompiled_code:
__int64 __fastcall ia_eval_max(const __m128i **a1, char a2, int a3)
{
int v3; // er13
unsigned int v4; // er12
int i; // ebp
__m128i **v7; // rbx
signed int v8; // eax
int v10[16]; // [rsp+18h] [rbp-40h] BYREF

if ( !a3 || (v3 = reversi_game_over()) != 0 )
return (unsigned int)ia_eval_grid(a1, (unsigned int)a2);
v4 = 0x80000000;
do
{
for ( i = 0; i != 8; ++i )
{
v10[0] = i;
v10[1] = v3;
v7 = _grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v7, (unsigned int)a2, v10) )
{
v8 = ia_eval_min(v7, 9 * (unsigned int)(a2 != 88) + 79, (unsigned int)(a3 - 1));
if ( (int)v4 < v8 )
v4 = v8;
}
reversi_free(v7);
}
++v3;
}
while ( v3 != 8 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const __m128i **a1, char a2, int a3)
{
int v3; // er13
unsigned int v4; // er12
int i; // ebp
__m128i **v7; // rbx
signed int v8; // eax
int v10[16]; // [rsp+18h] [rbp-40h] BYREF

if ( !a3 || (v3 = reversi_game_over()) != 0 )
return (unsigned int)ia_eval_grid(a1, (unsigned int)a2);
v4 = 0x80000000;
do
{
for ( i = 0; i != 8; ++i )
{
v10[0] = i;
v10[1] = v3;
v7 = _grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v7, (unsigned int)a2, v10) )
{
v8 = func1(v7, 9 * (unsigned int)(a2 != 88) + 79, (unsigned int)(a3 - 1));
if ( (int)v4 < v8 )
v4 = v8;
}
reversi_free(v7);
}
++v3;
}
while ( v3 != 8 );
return v4;
}

original_code:
int ia_eval_max(Reversi *reversi, Player player, int depth)
{
  int i, j, bestScore = (-0x7fffffff - 1), score;
  Pos playedPos;
  Reversi *reversiCpy = ((void *)0);
  if (depth == 0 || reversi_game_over(reversi))
  {
    return ia_eval_grid(reversi, player);
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        if((score = ia_eval_min(reversiCpy, (player == 'X' ? 'O' : 'X'), depth - 1)) > bestScore)
        {
          bestScore = score;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return bestScore;
}

canonical_original_code:
int ia_eval_max(struct Reversi *reversi, char player, int depth)
{
  int i; int j; int bestScore = (-0x7fffffff - 1); int score;
  struct Pos playedPos;
  struct Reversi *reversiCpy = ((void *)0);
  if (depth == 0 || reversi_game_over(reversi))
  {
    return ia_eval_grid(reversi, player);
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        if((score = ia_eval_min(reversiCpy, (player == 'X' ? 'O' : 'X'), depth - 1)) > bestScore)
        {
          bestScore = score;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return bestScore;
}

variable_types: struct Reversi { char *array; unsigned int n_moves; } *

variable_types: player char

variable_types: depth int

variable_types: i int

variable_types: j int

variable_types: bestScore int

variable_types: score int

variable_types:
playedPos
struct Pos { int x; int y; }


decompiled_code:
__int64 __fastcall ia_eval_min(const __m128i **a1, char a2, int a3)
{
int v3; // er13
int v4; // er12
int i; // ebp
__m128i **v7; // rbx
int v8; // eax
int v10[16]; // [rsp+18h] [rbp-40h] BYREF

if ( !a3 || (v3 = reversi_game_over()) != 0 )
{
v4 = ia_eval_grid(a1, (unsigned int)a2);
}
else
{
v4 = 0x7FFFFFFF;
do
{
for ( i = 0; i != 8; ++i )
{
v10[0] = i;
v10[1] = v3;
v7 = _grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v7, (unsigned int)a2, v10) )
{
v8 = ia_eval_max((const __m128i **)v7, 9 * (a2 != 88) + 79, a3 - 1);
if ( v4 > v8 )
v4 = v8;
}
reversi_free(v7);
}
++v3;
}
while ( v3 != 8 );
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const __m128i **a1, char a2, int a3)
{
int v3; // er13
int v4; // er12
int i; // ebp
__m128i **v7; // rbx
int v8; // eax
int v10[16]; // [rsp+18h] [rbp-40h] BYREF

if ( !a3 || (v3 = reversi_game_over()) != 0 )
{
v4 = ia_eval_grid(a1, (unsigned int)a2);
}
else
{
v4 = 0x7FFFFFFF;
do
{
for ( i = 0; i != 8; ++i )
{
v10[0] = i;
v10[1] = v3;
v7 = _grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v7, (unsigned int)a2, v10) )
{
v8 = func0((const __m128i **)v7, 9 * (a2 != 88) + 79, a3 - 1);
if ( v4 > v8 )
v4 = v8;
}
reversi_free(v7);
}
++v3;
}
while ( v3 != 8 );
}
return (unsigned int)v4;
}

original_code:
int ia_eval_min (Reversi *reversi, Player player, int depth)
{
  int i, j, minScore = 0x7fffffff, score;
  Pos playedPos;
  Reversi *reversiCpy = ((void *)0);
  if (depth == 0 || reversi_game_over(reversi))
  {
    return ia_eval_grid(reversi, player);
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        if((score = ia_eval_max(reversiCpy, (player == 'X' ? 'O' : 'X'), depth - 1)) < minScore)
        {
          minScore = score;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return minScore;
}

canonical_original_code:
int ia_eval_min(struct Reversi *reversi, char player, int depth)
{
  int i; int j; int minScore = 0x7fffffff; int score;
  struct Pos playedPos;
  struct Reversi *reversiCpy = ((void *)0);
  if (depth == 0 || reversi_game_over(reversi))
  {
    return ia_eval_grid(reversi, player);
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        if((score = ia_eval_max(reversiCpy, (player == 'X' ? 'O' : 'X'), depth - 1)) < minScore)
        {
          minScore = score;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return minScore;
}

variable_types: minScore int

user_defined_types: struct Reversi { char *array; unsigned int n_moves; }


decompiled_code:
__int64 __fastcall ia_eval(const __m128i **a1, char a2, int a3)
{
signed int v3; // er15
int i; // er12
int j; // ebp
__m128i **v6; // rbx
signed int v7; // eax
__int128 v9; // [rsp+0h] [rbp-58h]
int v10[16]; // [rsp+18h] [rbp-40h] BYREF

LODWORD(v9) = a3;
v3 = 0x80000000;
for ( i = 0; i != 8; ++i )
{
for ( j = 0; j != 8; ++j )
{
v10[0] = j;
v10[1] = i;
v6 = _grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v6, (unsigned int)a2, v10) )
{
v7 = ia_eval_min((const __m128i **)v6, a2, v9);
if ( v7 > v3 )
{
DWORD2(v9) = i;
DWORD1(v9) = j;
v3 = v7;
}
}
reversi_free(v6);
}
}
return v9 >> 32;
}

canonical_decompiled_code:
__int64 __fastcall func2(const __m128i **a1, char a2, int a3)
{
signed int v3; // er15
int i; // er12
int j; // ebp
__m128i **v6; // rbx
signed int v7; // eax
__int128 v9; // [rsp+0h] [rbp-58h]
int v10[16]; // [rsp+18h] [rbp-40h] BYREF

LODWORD(v9) = a3;
v3 = 0x80000000;
for ( i = 0; i != 8; ++i )
{
for ( j = 0; j != 8; ++j )
{
v10[0] = j;
v10[1] = i;
v6 = _grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v6, (unsigned int)a2, v10) )
{
v7 = func1((const __m128i **)v6, a2, v9);
if ( v7 > v3 )
{
DWORD2(v9) = i;
DWORD1(v9) = j;
v3 = v7;
}
}
reversi_free(v6);
}
}
return v9 >> 32;
}

original_code:
Pos ia_eval(Reversi *reversi, Player player, int depth)
{
  int i, j, bestScore = (-0x7fffffff - 1), score;
  Pos playedPos;
  Pos bestPos;
  Reversi *reversiCpy = ((void *)0);
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        if((score = ia_eval_min(reversiCpy, player, depth)) > bestScore)
        {
          bestScore = score;
          bestPos.x = i;
          bestPos.y = j;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return bestPos;
}

canonical_original_code:
struct Pos ia_eval(struct Reversi *reversi, char player, int depth)
{
  int i; int j; int bestScore = (-0x7fffffff - 1); int score;
  struct Pos playedPos;
  struct Pos bestPos;
  struct Reversi *reversiCpy = ((void *)0);
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if (reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        if((score = ia_eval_min(reversiCpy, player, depth)) > bestScore)
        {
          bestScore = score;
          bestPos.x = i;
          bestPos.y = j;
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return bestPos;
}

variable_types:
bestPos
struct Pos { int x; int y; }

return_type: struct Pos { int x; int y; }


decompiled_code:
__int64 __fastcall ia_negamax(__int64 a1, char a2, int a3, int a4, int a5, int *a6)
{
int v8; // er14
unsigned int v9; // er12
int i; // ebp
__int64 v12; // rbx
int v13; // eax
int v16[16]; // [rsp+28h] [rbp-40h] BYREF

if ( a3 <= 0 || (unsigned int)reversi_game_over() )
return (unsigned int)ia_eval_grid(a1, (unsigned int)a2);
if ( a3 == 7 )
{
*a6 = -1;
a6[1] = -1;
}
v8 = 0;
while ( 2 )
{
for ( i = 0; i != 8; ++i )
{
v16[0] = i;
v16[1] = v8;
v12 = _grid_copy(a1);
if ( (unsigned int)reversi_set_ia_move(v12, (unsigned int)a2, v16) )
{
v13 = -(int)ia_negamax(
v12,
9 * (unsigned int)(a2 != 88) + 79,
(unsigned int)(a3 - 1),
(unsigned int)-a5,
(unsigned int)-a4,
a6);
if ( v13 >= a4 )
{
if ( a3 == 7 )
{
*a6 = i;
a6[1] = v8;
}
if ( a5 <= v13 )
{
v9 = v13;
if ( a3 == 7 )
{
*a6 = i;
a6[1] = v8;
}
reversi_free(v12);
return v9;
}
a4 = v13;
}
}
reversi_free(v12);
}
if ( ++v8 != 8 )
continue;
break;
}
return (unsigned int)a4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, int a3, int a4, int a5, int *a6)
{
int v8; // er14
unsigned int v9; // er12
int i; // ebp
__int64 v12; // rbx
int v13; // eax
int v16[16]; // [rsp+28h] [rbp-40h] BYREF

if ( a3 <= 0 || (unsigned int)reversi_game_over() )
return (unsigned int)ia_eval_grid(a1, (unsigned int)a2);
if ( a3 == 7 )
{
*a6 = -1;
a6[1] = -1;
}
v8 = 0;
while ( 2 )
{
for ( i = 0; i != 8; ++i )
{
v16[0] = i;
v16[1] = v8;
v12 = func0(a1);
if ( (unsigned int)reversi_set_ia_move(v12, (unsigned int)a2, v16) )
{
v13 = -(int)func1(
v12,
9 * (unsigned int)(a2 != 88) + 79,
(unsigned int)(a3 - 1),
(unsigned int)-a5,
(unsigned int)-a4,
a6);
if ( v13 >= a4 )
{
if ( a3 == 7 )
{
*a6 = i;
a6[1] = v8;
}
if ( a5 <= v13 )
{
v9 = v13;
if ( a3 == 7 )
{
*a6 = i;
a6[1] = v8;
}
reversi_free(v12);
return v9;
}
a4 = v13;
}
}
reversi_free(v12);
}
if ( ++v8 != 8 )
continue;
break;
}
return (unsigned int)a4;
}

original_code:
int ia_negamax(Reversi *reversi, Player player, int depth, int alpha, int beta, Pos *pos)
{
  int i, j, temp;
  Reversi *reversiCpy = ((void *)0);
  Pos playedPos;
  static int lvl_max = 7;
  if(depth <= 0 || reversi_game_over(reversi))
    return ia_eval_grid(reversi, player);
  if(depth == lvl_max)
  {
    pos->x = -1;
    pos->y = -1;
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if(reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        temp = -ia_negamax(reversiCpy, (player == 'X' ? 'O' : 'X'), depth - 1, -beta, -alpha, pos);
        if(temp >= alpha)
        {
          alpha = temp;
          if(depth == lvl_max)
          {
            pos->x = i;
            pos->y = j;
          }
          if(alpha >= beta)
          {
            if(depth == lvl_max)
            {
              pos->x = i;
              pos->y = j;
            }
            reversi_free(reversiCpy);
            return alpha;
          }
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return alpha;
}

canonical_original_code:
int ia_negamax(struct Reversi *reversi, char player, int depth, int alpha, int beta, struct Pos *pos)
{
  int i; int j; int temp;
  struct Reversi *reversiCpy = ((void *)0);
  struct Pos playedPos;
  static int lvl_max = 7;
  if(depth <= 0 || reversi_game_over(reversi))
    return ia_eval_grid(reversi, player);
  if(depth == lvl_max)
  {
    pos->x = -1;
    pos->y = -1;
  }
  for(j = 0; j < 8; j++)
  {
    for(i = 0; i < 8; i++)
    {
      playedPos.x = i;
      playedPos.y = j;
      reversiCpy = __grid_copy(reversi);
      if(reversi_set_ia_move(reversiCpy, player, &playedPos))
      {
        temp = -ia_negamax(reversiCpy, (player == 'X' ? 'O' : 'X'), depth - 1, -beta, -alpha, pos);
        if(temp >= alpha)
        {
          alpha = temp;
          if(depth == lvl_max)
          {
            pos->x = i;
            pos->y = j;
          }
          if(alpha >= beta)
          {
            if(depth == lvl_max)
            {
              pos->x = i;
              pos->y = j;
            }
            reversi_free(reversiCpy);
            return alpha;
          }
        }
      }
      reversi_free(reversiCpy);
    }
  }
  return alpha;
}

variable_types: alpha int

variable_types: beta int

variable_types:
pos
struct Pos { int x; int y; } *

variable_types: temp int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
LoadScript("./example.script");
RunScript("./example.script", argv);
UnloadScript();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7("./example.script");
func12("./example.script", argv);
func8();
return 0;
}

original_code:
int main()
{
    LoadScript("./example.script");
    RunScript();
    UnloadScript();
    return 0;
}


repo: Wikinaut/agrep

decompiled_code:
_QWORD *parse_wildcard()
{
_BYTE *v0; // rax
_BYTE *v1; // rbx
_QWORD *v2; // rax

v0 = malloc(2uLL);
if ( !v0 )
{
fwrite("malloc failure in new_node\n", 1uLL, 0x1BuLL, stderr);
exit(2);
}
v1 = v0;
*v0 = 1;
v0[1] = -1;
v2 = malloc(0x10uLL);
if ( !v2 )
{
fwrite("malloc failure in new_node\n", 1uLL, 0x1BuLL, stderr);
exit(2);
}
v2[1] = 0LL;
*v2 = v1;
return mk_leaf(1, 1, 0, (__int64)v2);
}

canonical_decompiled_code:
_QWORD *func0()
{
_BYTE *v0; // rax
_BYTE *v1; // rbx
_QWORD *v2; // rax

v0 = malloc(2uLL);
if ( !v0 )
{
fwrite("malloc failure in new_node\n", 1uLL, 0x1BuLL, stderr);
exit(2);
}
v1 = v0;
*v0 = 1;
v0[1] = -1;
v2 = malloc(0x10uLL);
if ( !v2 )
{
fwrite("malloc failure in new_node\n", 1uLL, 0x1BuLL, stderr);
exit(2);
}
v2[1] = 0LL;
*v2 = v1;
return mk_leaf(1, 1, 0, (__int64)v2);
}

original_code:
Re_node parse_wildcard()
{
 Ch_Set s;
 Ch_Range r;
 { extern void *malloc(); (r) = (Ch_Range) malloc(sizeof(*(r))); if ((r) == ((void *)0)) { fprintf(stderr, "malloc failure in new_node\n"); exit(2); } memset((r), '\0', sizeof(*(r)));};
 r->low_bd = '\001';
 r->hi_bd = '\377';
 { extern void *malloc(); (s) = (Ch_Set) malloc(sizeof(*(s))); if ((s) == ((void *)0)) { fprintf(stderr, "malloc failure in new_node\n"); exit(2); } memset((s), '\0', sizeof(*(s)));};
 s->elt = r;
 s->rest = ((void *)0);
 return mk_leaf(1, 1, '\0', s);
}

canonical_original_code:
struct rnode *parse_wildcard()
{
 struct ch_set *s;
 struct { char low_bd; } *r;
 { extern void *malloc(); (r) = (struct { char low_bd; } *) malloc(sizeof(*(r))); if ((r) == ((void *)0)) { fprintf(stderr, "malloc failure in new_node\n"); exit(2); } memset((r), '\0', sizeof(*(r)));};
 r->low_bd = '\001';
 r->hi_bd = '\377';
 { extern void *malloc(); (s) = (struct ch_set *) malloc(sizeof(*(s))); if ((s) == ((void *)0)) { fprintf(stderr, "malloc failure in new_node\n"); exit(2); } memset((s), '\0', sizeof(*(s)));};
 s->elt = r;
 s->rest = ((void *)0);
 return mk_leaf(1, 1, '\0', s);
}

variable_types:
r
struct { char low_bd; } *

variable_types:
malloc
void *()

return_type: struct rnode { short op; union { struct { int pos; short l_type; union { char c; struct ch_set { struct { char low_bd; } *elt; struct ch_set *rest; } *cset; } val; } *lit; struct rnode *child; struct { struct rnode *l_child; struct rnode *r_child; } children; } refs; short nullable; struct pnode { int posnum; struct pnode *nextpos; } *firstposn; } *

user_defined_types: struct rnode { short op; union { struct { int pos; short l_type; union { char c; struct ch_set *cset; } val; } *lit; struct rnode *child; struct { struct rnode *l_child; struct rnode *r_child; } children; } refs; short nullable; struct pnode *firstposn; }


compat

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

if ( BESTMATCH )
{
if ( !(PAT_FILE | APPROX | FILENAMEONLY | COUNT) )
{
if ( PAT_BUFFER | PAT_FILE )
goto LABEL_11;
LABEL_37:
if ( MULTI_OUTPUT && LINENUM )
{
fprintf(stderr, "%s: -M and -n are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
goto LABEL_40;
}
goto LABEL_12;
}
BESTMATCH = 0;
fprintf(stderr, "%s: -B option ignored when -c, -l, -f, or -# is on\n", (const char *)&Progname);
}
if ( COUNT && LINENUM )
{
LINENUM = 0;
fprintf(stderr, "%s: -n option ignored with -c\n", (const char *)&Progname);
}
if ( !(PAT_BUFFER | PAT_FILE) )
goto LABEL_37;
if ( APPROX && D > 0 )
fprintf(stderr, "%s: approximate matching is not supported with -f option\n", (const char *)&Progname);
LABEL_11:
if ( LINENUM )
{
fprintf(stderr, "%s: -f and -n are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
goto LABEL_40;
}
LABEL_12:
if ( !JUMP )
goto LABEL_26;
if ( REGEX )
{
fprintf(stderr, "%s: -D#, -I#, or -S# option is ignored for regular expression pattern\n", (const char *)&Progname);
JUMP = 0;
}
if ( I && S && DD )
{
LABEL_26:
if ( DELIMITER && WHOLELINE )
{
fprintf(stderr, "%s: -d and -x are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
}
else
{
result = INVERSE;
if ( !INVERSE )
return result;
result = (unsigned int)(PAT_BUFFER | PAT_FILE);
if ( !(PAT_BUFFER | PAT_FILE) )
return result;
result = MULTI_OUTPUT;
if ( !MULTI_OUTPUT )
return result;
fprintf(stderr, "%s: -v and -M are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
}
LABEL_40:
*_errno_location() = 123;
return 0xFFFFFFFFLL;
}
fprintf(stderr, "%s: the error cost cannot be 0\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
*_errno_location() = 123;
return 0xFFFFFFFFLL;
}

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

if ( BESTMATCH )
{
if ( !(PAT_FILE | APPROX | FILENAMEONLY | COUNT) )
{
if ( PAT_BUFFER | PAT_FILE )
goto LABEL_11;
LABEL_37:
if ( MULTI_OUTPUT && LINENUM )
{
fprintf(stderr, "%s: -M and -n are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
goto LABEL_40;
}
goto LABEL_12;
}
BESTMATCH = 0;
fprintf(stderr, "%s: -B option ignored when -c, -l, -f, or -# is on\n", (const char *)&Progname);
}
if ( COUNT && LINENUM )
{
LINENUM = 0;
fprintf(stderr, "%s: -n option ignored with -c\n", (const char *)&Progname);
}
if ( !(PAT_BUFFER | PAT_FILE) )
goto LABEL_37;
if ( APPROX && D > 0 )
fprintf(stderr, "%s: approximate matching is not supported with -f option\n", (const char *)&Progname);
LABEL_11:
if ( LINENUM )
{
fprintf(stderr, "%s: -f and -n are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
goto LABEL_40;
}
LABEL_12:
if ( !JUMP )
goto LABEL_26;
if ( REGEX )
{
fprintf(stderr, "%s: -D#, -I#, or -S# option is ignored for regular expression pattern\n", (const char *)&Progname);
JUMP = 0;
}
if ( I && S && DD )
{
LABEL_26:
if ( DELIMITER && WHOLELINE )
{
fprintf(stderr, "%s: -d and -x are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
}
else
{
result = INVERSE;
if ( !INVERSE )
return result;
result = (unsigned int)(PAT_BUFFER | PAT_FILE);
if ( !(PAT_BUFFER | PAT_FILE) )
return result;
result = MULTI_OUTPUT;
if ( !MULTI_OUTPUT )
return result;
fprintf(stderr, "%s: -v and -M are not compatible\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
}
LABEL_40:
*_errno_location() = 123;
return 0xFFFFFFFFLL;
}
fprintf(stderr, "%s: the error cost cannot be 0\n", (const char *)&Progname);
if ( EXITONERROR )
exit(2);
*_errno_location() = 123;
return 0xFFFFFFFFLL;
}

original_code:
int
compat()
{
 if(BESTMATCH) if(COUNT || FILENAMEONLY || APPROX || PAT_FILE) {
  BESTMATCH = 0;
  fprintf(stderr, "%s: -B option ignored when -c, -l, -f, or -# is on\n", Progname);
 }
 if (COUNT && LINENUM) {
  LINENUM = 0;
  fprintf(stderr, "%s: -n option ignored with -c\n", Progname);
 }
 if(PAT_FILE || PAT_BUFFER) {
  if(APPROX && (D > 0)) {
   fprintf(stderr, "%s: approximate matching is not supported with -f option\n", Progname);
  }
  if(LINENUM) {
   fprintf(stderr, "%s: -f and -n are not compatible\n", Progname);
   if (!EXITONERROR) {
    (*__errno_location ()) = 123;
    return -1;
   }
   else exit(2);
  }
 }
 if (MULTI_OUTPUT && LINENUM) {
  fprintf(stderr, "%s: -M and -n are not compatible\n", Progname);
  if (!EXITONERROR) {
   (*__errno_location ()) = 123;
   return -1;
  }
  else exit(2);
 }
 if(JUMP) {
  if(REGEX) {
   fprintf(stderr, "%s: -D#, -I#, or -S# option is ignored for regular expression pattern\n", Progname);
   JUMP = 0;
  }
  if(I == 0 || S == 0 || DD == 0) {
   fprintf(stderr, "%s: the error cost cannot be 0\n", Progname);
   if (!EXITONERROR) {
    (*__errno_location ()) = 123;
    return -1;
   }
   else exit(2);
  }
 }
 if(DELIMITER) {
  if(WHOLELINE) {
   fprintf(stderr, "%s: -d and -x are not compatible\n", Progname);
   if (!EXITONERROR) {
    (*__errno_location ()) = 123;
    return -1;
   }
   else exit(2);
  }
 }
 if (INVERSE && (PAT_FILE || PAT_BUFFER) && MULTI_OUTPUT) {
  fprintf(stderr, "%s: -v and -M are not compatible\n", Progname);
  if (!EXITONERROR) {
   (*__errno_location ()) = 123;
   return -1;
  }
  else exit(2);
 }
 return 0;
}


Calloc

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

result = calloc(a1, a2);
if ( !result )
sys_err("calloc error");
return result;
}

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

result = calloc(a1, a2);
if ( !result )
func0("calloc error");
return result;
}

original_code:
void *Calloc(size_t n, size_t size) {
  void *p;
  if ((p = calloc(n, size)) == ((void *)0))
    sys_err("calloc error");
  return (p);
}

canonical_original_code:
void *Calloc(unsigned long n, unsigned long size) {
  void *p;
  if ((p = calloc(n, size)) == ((void *)0))
    sys_err("calloc error");
  return (p);
}

variable_types:
n
unsigned long

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


Socket

decompiled_code:
int __fastcall Socket(int a1, int a2, int a3)
{
int result; // eax

result = socket(a1, a2, a3);
if ( result < 0 )
sys_err("socket error");
return result;
}

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

result = socket(a1, a2, a3);
if ( result < 0 )
func0("socket error");
return result;
}

original_code:
int Socket(int family, int type, int protocol) {
  int n;
  if ((n = socket(family, type, protocol)) < 0)
    sys_err("socket error");
  return (n);
}

variable_types: family int

variable_types: type int

variable_types: protocol int

variable_types: n int


Accept

decompiled_code:
int __fastcall Accept(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = accept(a1, a2, a3);
if ( result < 0 )
sys_err("accept error");
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = accept(a1, a2, a3);
if ( result < 0 )
func0("accept error");
return result;
}

original_code:
int Accept(int fd, struct sockaddr *sa, socklen_t *addrlen) {
  int n;
  if ((n = accept(fd, sa, addrlen)) < 0) {
    sys_err("accept error");
  }
  return (n);
}

canonical_original_code:
int Accept(int fd, struct sockaddr *sa, unsigned int *addrlen) {
  int n;
  if ((n = accept(fd, sa, addrlen)) < 0) {
    sys_err("accept error");
  }
  return (n);
}

variable_types: fd int

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

variable_types:
addrlen
unsigned int *


Bind

decompiled_code:
int __fastcall Bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
sys_err("bind error");
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
func0("bind error");
return result;
}

original_code:
void Bind(int fd, const struct sockaddr *sa, socklen_t addrlen) {
  if (bind(fd, sa, addrlen) < 0)
    sys_err("bind error");
}

canonical_original_code:
void Bind(int fd, struct sockaddr *sa, unsigned int addrlen) {
  if (bind(fd, sa, addrlen) < 0)
    sys_err("bind error");
}

variable_types:
addrlen
unsigned int

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


Connect

decompiled_code:
int __fastcall Connect(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
sys_err("connect error");
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
func0("connect error");
return result;
}

original_code:
void Connect(int fd, const struct sockaddr *sa, socklen_t addrlen) {
  if (connect(fd, sa, addrlen) < 0)
    sys_err("connect error");
}

canonical_original_code:
void Connect(int fd, struct sockaddr *sa, unsigned int addrlen) {
  if (connect(fd, sa, addrlen) < 0)
    sys_err("connect error");
}


Listen

decompiled_code:
int __fastcall Listen(int a1, int a2)
{
int result; // eax

result = listen(a1, a2);
if ( result < 0 )
sys_err("listen error");
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1, int a2)
{
int result; // eax

result = listen(a1, a2);
if ( result < 0 )
func0("listen error");
return result;
}

original_code:
void Listen(int fd, int backlog) {
  if (listen(fd, backlog) < 0)
    sys_err("listen error");
}

variable_types: backlog int


Setsockopt

decompiled_code:
int __fastcall Setsockopt(int a1, int a2, int a3, const void *a4, socklen_t a5)
{
int result; // eax

result = setsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
sys_err("setsockopt error");
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2, int a3, const void *a4, socklen_t a5)
{
int result; // eax

result = setsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
func0("setsockopt error");
return result;
}

original_code:
void Setsockopt(int fd, int level, int optname, const void *optval,
                int optlen) {
  if (setsockopt(fd, level, optname, optval, optlen) < 0)
    sys_err("setsockopt error");
}

canonical_original_code:
void Setsockopt(int fd, int level, int optname, void *optval, int optlen) {
  if (setsockopt(fd, level, optname, optval, optlen) < 0)
    sys_err("setsockopt error");
}

variable_types: level int

variable_types: optname int

variable_types:
optval
void *

variable_types: optlen int


Close

decompiled_code:
int __fastcall Close(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
sys_err("close error");
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
func0("close error");
return result;
}

original_code:
void Close(int fd) {
  if (close(fd) == -1)
    sys_err("close error");
}


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

result = inet_pton(a1, a2, a3);
if ( result <= 0 )
{
fprintf(stderr, "inet error ->%s", a2);
exit(1);
}
return result;
}

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

result = inet_pton(a1, a2, a3);
if ( result <= 0 )
{
fprintf(stderr, "inet error ->%s", a2);
exit(1);
}
return result;
}

original_code:
void Inet_pton(int family, const char *strptr, void *addrptr) {
  int n;
  if ((n = inet_pton(family, strptr, addrptr)) <= 0) {
    fprintf(stderr, "inet error ->%s", strptr);
    exit(1);
  }
}

canonical_original_code:
void Inet_pton(int family, char *strptr, void *addrptr) {
  int n;
  if ((n = inet_pton(family, strptr, addrptr)) <= 0) {
    fprintf(stderr, "inet error ->%s", strptr);
    exit(1);
  }
}

variable_types:
strptr
char *

variable_types:
addrptr
void *


decompiled_code:
const char *__fastcall Inet_ntop(int a1, const void *a2, char *a3, socklen_t a4)
{
const char *result; // rax

result = inet_ntop(a1, a2, a3, a4);
if ( !result )
sys_err("inet_ntop error");
return result;
}

canonical_decompiled_code:
const char *__fastcall func10(int a1, const void *a2, char *a3, socklen_t a4)
{
const char *result; // rax

result = inet_ntop(a1, a2, a3, a4);
if ( !result )
func0("inet_ntop error");
return result;
}

original_code:
const char *Inet_ntop(int family, const void *addrptr, char *strptr,
                      size_t len) {
  const char *ptr;
  if ((ptr = inet_ntop(family, addrptr, strptr, len)) == ((void *)0))
    sys_err("inet_ntop error");
  return (ptr);
}

canonical_original_code:
char *Inet_ntop(int family, void *addrptr, char *strptr, unsigned long len) {
  char *ptr;
  if ((ptr = inet_ntop(family, addrptr, strptr, len)) == ((void *)0))
    sys_err("inet_ntop error");
  return (ptr);
}

variable_types:
len
unsigned long

variable_types:
ptr
char *

return_type: char *


Getaddrinfo

decompiled_code:
__int64 __fastcall Getaddrinfo(const char *a1, const char *a2, const struct addrinfo *a3, struct addrinfo **a4)
{
int v4; // eax
const char *v6; // rax

v4 = getaddrinfo(a1, a2, a3, a4);
if ( v4 )
{
v6 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo error: %s\n", v6);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, const char *a2, const struct addrinfo *a3, struct addrinfo **a4)
{
int v4; // eax
const char *v6; // rax

v4 = getaddrinfo(a1, a2, a3, a4);
if ( v4 )
{
v6 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo error: %s\n", v6);
exit(1);
}
return 0LL;
}

original_code:
int Getaddrinfo(const char *hostname, const char *servname,
                const struct addrinfo *hints, struct addrinfo **res) {
  int n;
  if ((n = getaddrinfo(hostname, servname, hints, res)) != 0) {
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(n));
    exit(1);
  }
  return (n);
}

canonical_original_code:
int Getaddrinfo(char *hostname, char *servname, struct addrinfo *hints, struct addrinfo **res) {
  int n;
  if ((n = getaddrinfo(hostname, servname, hints, res)) != 0) {
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(n));
    exit(1);
  }
  return (n);
}

variable_types:
hostname
char *

variable_types:
servname
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
res
struct addrinfo **

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


Read

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

LODWORD(result) = read(a1, a2, a3);
if ( (int)result < 0 )
sys_err("read error");
return (int)result;
}

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

LODWORD(result) = read(a1, a2, a3);
if ( (int)result < 0 )
func0("read error");
return (int)result;
}

original_code:
ssize_t Read(int fd, void *buf, size_t count) {
  int n;
  if ((n = read(fd, buf, count)) < 0)
    sys_err("read error");
  return (n);
}

canonical_original_code:
long Read(int fd, void *buf, unsigned long count) {
  int n;
  if ((n = read(fd, buf, count)) < 0)
    sys_err("read error");
  return (n);
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: n int

return_type: long


Write

decompiled_code:
__int64 __fastcall Write(int a1, const void *a2, size_t a3)
{
__int64 result; // rax

LODWORD(result) = write(a1, a2, a3);
if ( (int)result < 0 )
sys_err("write error");
return (int)result;
}

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

LODWORD(result) = write(a1, a2, a3);
if ( (int)result < 0 )
func0("write error");
return (int)result;
}

original_code:
ssize_t Write(int fd, const void *buf, size_t count) {
  int n;
  if ((n = write(fd, buf, count)) < 0)
    sys_err("write error");
  return (n);
}

canonical_original_code:
long Write(int fd, void *buf, unsigned long count) {
  int n;
  if ((n = write(fd, buf, count)) < 0)
    sys_err("write error");
  return (n);
}


Signal

decompiled_code:
__sighandler_t __fastcall Signal(int a1, void (*a2)(int))
{
__sighandler_t result; // rax

result = signal(a1, a2);
if ( result == (__sighandler_t)-1LL )
sys_err("signal child error");
return result;
}

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

result = signal(a1, a2);
if ( result == (__sighandler_t)-1LL )
func0("signal child error");
return result;
}

original_code:
sig_t Signal(int sig, sig_t func) {
  sig_t s;
  if ((s = signal(sig, func)) == ((__sighandler_t) -1))
    sys_err("signal child error");
  return (s);
}

canonical_original_code:
void (*Signal(int sig, void (*func)(int)))(int) {
  void (*s)(int);
  if ((s = signal(sig, func)) == ((__sighandler_t) -1))
    sys_err("signal child error");
  return (s);
}

variable_types: sig int

variable_types:
func
void (*)(int)

variable_types:
s
void (*)(int)

return_type: void (*)(int)


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

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

original_code:
void sys_err(const char *msg) {
  perror(msg);
  exit(1);
}

canonical_original_code:
void sys_err(char *msg) {
  perror(msg);
  exit(1);
}

variable_types:
msg
char *


tcp

decompiled_code:
__int64 __fastcall tcp(char *file, char *src)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // r13
int v5; // eax
int v6; // ebx
int v7; // ebp
int v8; // eax
int v9; // eax
struct stat v11; // [rsp+0h] [rbp-4B8h] BYREF
char buf[1064]; // [rsp+90h] [rbp-428h] BYREF

v2 = strlen(file);
v3 = strlen(src);
v4 = (char *)malloc(8 * (v2 + v3 + 1));
v5 = open(file, 0);
if ( v5 < 0 )
sys_err("Fail to open source_file");
v6 = v5;
fstat(v5, &v11);
if ( (unsigned int)is_dir(src) )
sprintf(v4, "%s/%s", src, file);
else
strcpy(v4, src);
v7 = open(v4, 577, v11.st_mode);
if ( v7 < 0 )
sys_err("Fail to open target_file");
while ( 1 )
{
v8 = read(v6, buf, 0x400uLL);
if ( v8 <= 0 )
break;
v9 = write(v7, buf, v8);
if ( !v9 )
sys_err("EOF while writing");
if ( v9 < 0 )
{
close(v6);
close(v7);
sys_err("Unable to write");
}
}
if ( v8 < 0 )
{
close(v6);
close(v7);
sys_err("Unable to read");
}
close(v6);
close(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *file, char *src)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // r13
int v5; // eax
int v6; // ebx
int v7; // ebp
int v8; // eax
int v9; // eax
struct stat v11; // [rsp+0h] [rbp-4B8h] BYREF
char buf[1064]; // [rsp+90h] [rbp-428h] BYREF

v2 = strlen(file);
v3 = strlen(src);
v4 = (char *)malloc(8 * (v2 + v3 + 1));
v5 = open(file, 0);
if ( v5 < 0 )
func8("Fail to open source_file");
v6 = v5;
func14(v5, &v11);
if ( (unsigned int)func9(src) )
sprintf(v4, "%s/%s", src, file);
else
strcpy(v4, src);
v7 = open(v4, 577, v11.st_mode);
if ( v7 < 0 )
func8("Fail to open target_file");
while ( 1 )
{
v8 = read(v6, buf, 0x400uLL);
if ( v8 <= 0 )
break;
v9 = write(v7, buf, v8);
if ( !v9 )
func8("EOF while writing");
if ( v9 < 0 )
{
close(v6);
close(v7);
func8("Unable to write");
}
}
if ( v8 < 0 )
{
close(v6);
close(v7);
func8("Unable to read");
}
close(v6);
close(v7);
return 0LL;
}

original_code:
int tcp(const char *src, const char *dst) {
  int sdf, ddf;
  int nr, nw;
  char buf[1024];
  struct stat per;
  char *ndst =
      (char *)malloc
      ((strlen(src) + strlen(dst) + 1) * sizeof(char *));
  if ((sdf = open(src, 00)) < 0)
    sys_err("Fail to open source_file");
  fstat(sdf, &per);
  if (is_dir(dst)) {
    (void)sprintf(ndst, "%s/%s", dst, src);
  } else {
    strcpy(ndst, dst);
  }
  if ((ddf = open(ndst, 01 | 0100 | 01000, per.st_mode)) < 0) {
    sys_err("Fail to open target_file");
  }
  while ((nr = read(sdf, buf, 1024)) > 0) {
    if ((nw = write(ddf, buf, nr)) > 0 && nw) {
                      ;
    } else if (nw == 0) {
      sys_err("EOF while writing");
    }
    if (nw < 0) {
      close(sdf);
      close(ddf);
      sys_err("Unable to write");
    }
  }
  if (nr < 0)
  {
    close(sdf);
    close(ddf);
    sys_err("Unable to read");
  }
  close(sdf);
  close(ddf);
  return 0;
}

canonical_original_code:
int tcp(char *src, char *dst) {
  int sdf; int ddf;
  int nr; int nw;
  char buf[1024];
  struct stat per;
  char *ndst = (char *)malloc
      ((strlen(src) + strlen(dst) + 1) * sizeof(char *));
  if ((sdf = open(src, 00)) < 0)
    sys_err("Fail to open source_file");
  fstat(sdf, &per);
  if (is_dir(dst)) {
    (void)sprintf(ndst, "%s/%s", dst, src);
  } else {
    strcpy(ndst, dst);
  }
  if ((ddf = open(ndst, 01 | 0100 | 01000, per.st_mode)) < 0) {
    sys_err("Fail to open target_file");
  }
  while ((nr = read(sdf, buf, 1024)) > 0) {
    if ((nw = write(ddf, buf, nr)) > 0 && nw) {
                      ;
    } else if (nw == 0) {
      sys_err("EOF while writing");
    }
    if (nw < 0) {
      close(sdf);
      close(ddf);
      sys_err("Unable to write");
    }
  }
  if (nr < 0)
  {
    close(sdf);
    close(ddf);
    sys_err("Unable to read");
  }
  close(sdf);
  close(ddf);
  return 0;
}

variable_types:
src
char *

variable_types:
dst
char *

variable_types: sdf int

variable_types: ddf int

variable_types: nr int

variable_types: nw int

variable_types:
buf
char [1024]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
ndst
char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


usage

decompiled_code:
void __noreturn usage()
{
const char *v0; // rax

v0 = (const char *)getprogname();
fprintf(_bss_start, "usage: %s source_file target_file\n", v0);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
const char *v0; // rax

v0 = (const char *)getprogname();
fprintf(_bss_start, "usage: %s source_file target_file\n", v0);
exit(1);
}

original_code:
void usage() {
  (void)fprintf(stderr, "usage: %s source_file target_file\n", getprogname());
  exit(1);
}


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


decompiled_code:
__int64 __fastcall is_dir(char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat(a1, &v2);
if ( (_DWORD)result )
return 0LL;
if ( (v2.st_mode & 0x4000) != 0 )
return 1LL;
if ( (v2.st_mode & 0x8000) == 0 )
sys_err("Neither directory nor regular file");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = func13(a1, &v2);
if ( (_DWORD)result )
return 0LL;
if ( (v2.st_mode & 0x4000) != 0 )
return 1LL;
if ( (v2.st_mode & 0x8000) == 0 )
func8("Neither directory nor regular file");
return result;
}

original_code:
int is_dir(const char *path) {
  struct stat st;
  if (stat(path, &st) == 0) {
    if (st.st_mode & 0040000)
      return 1;
    else if (st.st_mode & 0100000)
      return 0;
    else
      sys_err("Neither directory nor regular file");
  }
  return 0;
}

canonical_original_code:
int is_dir(char *path) {
  struct stat st;
  if (stat(path, &st) == 0) {
    if (st.st_mode & 0040000)
      return 1;
    else if (st.st_mode & 0100000)
      return 0;
    else
      sys_err("Neither directory nor regular file");
  }
  return 0;
}

variable_types:
path
char *

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


main

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

v4 = *argv;
setprogname();
if ( argc != 3 )
usage(v4);
if ( (unsigned int)tcp((char *)argv[1], (char *)argv[2]) )
exit(1);
return 0;
}

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

v4 = *argv;
setprogname();
if ( argc != 3 )
func7(v4);
if ( (unsigned int)func10((char *)argv[1], (char *)argv[2]) )
exit(1);
return 0;
}

original_code:
int main(int argc, char const *argv[]) {
  const char *src, *dst;
  int flag;
  setprogname(argv[0]);
  if (argc != 3)
    usage();
  src = argv[1], dst = argv[2];
  if ((flag = tcp(src, dst)) != 0)
    exit(1);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char *src; char *dst;
  int flag;
  setprogname(argv[0]);
  if (argc != 3)
    usage();
  src = argv[1], dst = argv[2];
  if ((flag = tcp(src, dst)) != 0)
    exit(1);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: flag int


decompiled_code:
__pid_t child_handler()
{
__pid_t result; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
result = waitpid(-1, stat_loc, 1);
while ( result != -1 );
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t result; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
result = waitpid(-1, stat_loc, 1);
while ( result != -1 );
return result;
}

original_code:
static void child_handler(int sig) {
  pid_t p;
  int status;
  while ((p = waitpid(-1, &status, 1)) != -1)
    ;
}

canonical_original_code:
static void child_handler(int sig) {
  int p;
  int status;
  while ((p = waitpid(-1, &status, 1)) != -1)
    ;
}

variable_types: sig int

variable_types: p int

variable_types: status int


decompiled_code:
void __fastcall __noreturn server_listen(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rbp
unsigned int v4; // ebx
int v5; // [rsp+Ch] [rbp-4FCh] BYREF
char v6[1032]; // [rsp+10h] [rbp-4F8h] BYREF
int v7; // [rsp+418h] [rbp-F0h] BYREF
int v8; // [rsp+41Ch] [rbp-ECh] BYREF
char v9[4]; // [rsp+420h] [rbp-E8h] BYREF
int v10; // [rsp+424h] [rbp-E4h]
char v11[24]; // [rsp+4A0h] [rbp-68h] BYREF
__int64 v12; // [rsp+4B8h] [rbp-50h] BYREF
__int64 v13[9]; // [rsp+4C0h] [rbp-48h] BYREF

v7 = 1;
v13[0] = 1LL;
v13[1] = 1LL;
v13[2] = 0LL;
v13[3] = 0LL;
v13[4] = 0LL;
v13[5] = 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
Getaddrinfo(v2, *(_QWORD *)(a1 + 24), v13, &v12);
else
Getaddrinfo(0LL, *(_QWORD *)(a1 + 24), v13, &v12);
v3 = (unsigned int)Socket(*(unsigned int *)(v12 + 4), *(unsigned int *)(v12 + 8), *(unsigned int *)(v12 + 12));
Setsockopt(v3, 1LL, 2LL, &v7, 4LL);
Bind((unsigned int)v3, *(_QWORD *)(v12 + 24), *(unsigned int *)(v12 + 16));
Listen((unsigned int)v3, 10LL);
while ( 1 )
{
v5 = v10;
v8 = 128;
v4 = Accept((unsigned int)v3, v9, &v8);
printf("Server is up on port:%s.\n", *(const char **)(a1 + 24));
if ( !fork() )
break;
Signal(17LL, child_handler);
Close(v4);
}
Close((unsigned int)v3);
Inet_ntop(2LL, &v5, v11, 16LL);
while ( Read(v4, v6, 1024LL) > 0 )
{
printf("Client %s --> %s", v11, v6);
memset(v6, 0, 0x400uLL);
}
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rbp
unsigned int v4; // ebx
int v5; // [rsp+Ch] [rbp-4FCh] BYREF
char v6[1032]; // [rsp+10h] [rbp-4F8h] BYREF
int v7; // [rsp+418h] [rbp-F0h] BYREF
int v8; // [rsp+41Ch] [rbp-ECh] BYREF
char v9[4]; // [rsp+420h] [rbp-E8h] BYREF
int v10; // [rsp+424h] [rbp-E4h]
char v11[24]; // [rsp+4A0h] [rbp-68h] BYREF
__int64 v12; // [rsp+4B8h] [rbp-50h] BYREF
__int64 v13[9]; // [rsp+4C0h] [rbp-48h] BYREF

v7 = 1;
v13[0] = 1LL;
v13[1] = 1LL;
v13[2] = 0LL;
v13[3] = 0LL;
v13[4] = 0LL;
v13[5] = 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
Getaddrinfo(v2, *(_QWORD *)(a1 + 24), v13, &v12);
else
Getaddrinfo(0LL, *(_QWORD *)(a1 + 24), v13, &v12);
v3 = (unsigned int)Socket(*(unsigned int *)(v12 + 4), *(unsigned int *)(v12 + 8), *(unsigned int *)(v12 + 12));
Setsockopt(v3, 1LL, 2LL, &v7, 4LL);
Bind((unsigned int)v3, *(_QWORD *)(v12 + 24), *(unsigned int *)(v12 + 16));
Listen((unsigned int)v3, 10LL);
while ( 1 )
{
v5 = v10;
v8 = 128;
v4 = Accept((unsigned int)v3, v9, &v8);
printf("Server is up on port:%s.\n", *(const char **)(a1 + 24));
if ( !fork() )
break;
Signal(17LL, child_handler);
Close(v4);
}
Close((unsigned int)v3);
Inet_ntop(2LL, &v5, v11, 16LL);
while ( Read(v4, v6, 1024LL) > 0 )
{
printf("Client %s --> %s", v11, v6);
memset(v6, 0, 0x400uLL);
}
exit(0);
}

original_code:
int server_listen(Arg_t *optInfo) {
  struct addrinfo hints, *res;
  char ipstr[16];
  int listenfd, connfd;
  struct sockaddr_storage client_addr;
  socklen_t clientlen;
  int ignore = 1;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if (optInfo->ipAddr == ((void *)0)) {
    hints.ai_flags = 0x0001;
    Getaddrinfo(((void *)0), optInfo->port, &hints, &res);
  } else {
    Getaddrinfo(optInfo->ipAddr, optInfo->port, &hints, &res);
  }
  listenfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  Setsockopt(listenfd, 1, 2, &ignore, sizeof(int));
  Bind(listenfd, res->ai_addr, res->ai_addrlen);
  Listen(listenfd, 10);
  while (1) {
    pid_t childpid;
    struct sockaddr_in *cliAdr = (struct sockaddr_in *)&client_addr;
    int ipAddr = cliAdr->sin_addr.s_addr;
    clientlen = sizeof(client_addr);
    connfd = Accept(listenfd, (struct sockaddr *)&client_addr, &clientlen);
    printf("Server is up on port:%s.\n", optInfo->port);
    if ((childpid = fork()) == 0) {
      Close(listenfd);
      char readbuf[1024];
      Inet_ntop(2, &ipAddr, ipstr,
                16);
      while (Read(connfd, readbuf, 1024) > 0) {
        printf("Client %s --> %s", ipstr, readbuf);
        bzero(readbuf, 1024);
      }
      exit(0);
    } else {
      Signal(17, child_handler);
    }
    Close(connfd);
  }
  freeaddrinfo(res);
  return connfd;
}

canonical_original_code:
int server_listen(struct arg_t *optInfo) {
  struct addrinfo hints; struct addrinfo *res;
  char ipstr[16];
  int listenfd; int connfd;
  struct sockaddr_storage client_addr;
  unsigned int clientlen;
  int ignore = 1;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if (optInfo->ipAddr == ((void *)0)) {
    hints.ai_flags = 0x0001;
    Getaddrinfo(((void *)0), optInfo->port, &hints, &res);
  } else {
    Getaddrinfo(optInfo->ipAddr, optInfo->port, &hints, &res);
  }
  listenfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  Setsockopt(listenfd, 1, 2, &ignore, sizeof(int));
  Bind(listenfd, res->ai_addr, res->ai_addrlen);
  Listen(listenfd, 10);
  while (1) {
    int childpid;
    struct sockaddr_in *cliAdr = (struct sockaddr_in *)&client_addr;
    int ipAddr = cliAdr->sin_addr.s_addr;
    clientlen = sizeof(client_addr);
    connfd = Accept(listenfd, (struct sockaddr *)&client_addr, &clientlen);
    printf("Server is up on port:%s.\n", optInfo->port);
    if ((childpid = fork()) == 0) {
      Close(listenfd);
      char readbuf[1024];
      Inet_ntop(2, &ipAddr, ipstr,
                16);
      while (Read(connfd, readbuf, 1024) > 0) {
        printf("Client %s --> %s", ipstr, readbuf);
        bzero(readbuf, 1024);
      }
      exit(0);
    } else {
      Signal(17, child_handler);
    }
    Close(connfd);
  }
  freeaddrinfo(res);
  return connfd;
}

variable_types: struct arg_t { char *cgiDir; char *ipAddr; char *logFile; char *port; } *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
ipstr
char [16]

variable_types: listenfd int

variable_types: connfd int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
clientlen
unsigned int

variable_types: ignore int

variable_types: childpid int

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: ipAddr int

variable_types:
readbuf
char [1024]

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


tcpm

decompiled_code:
__int64 __fastcall tcpm(char *file, char *src)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // r13
int v5; // eax
int v6; // ebx
int v7; // eax
int v8; // ebp
void *v9; // r13
void *v10; // rax
void *v11; // r12
struct stat v13; // [rsp+0h] [rbp-B8h] BYREF

v2 = strlen(file);
v3 = strlen(src);
v4 = (char *)malloc(8 * (v2 + v3 + 1));
v5 = open(file, 0);
if ( v5 < 0 )
sys_err("Fail to open source_file");
v6 = v5;
fstat(v5, &v13);
if ( (unsigned int)is_dir(src) )
sprintf(v4, "%s/%s", src, file);
else
strcpy(v4, src);
v7 = open(v4, 578, v13.st_mode);
v8 = v7;
if ( v7 < 0 )
sys_err("Fail to open target_file");
if ( ftruncate(v7, v13.st_size) < 0 )
sys_err("Fail to ftruncate");
v9 = mmap(0LL, v13.st_size, 1, 2, v6, 0LL);
if ( v9 == (void *)-1LL )
sys_err("source file mmap err");
v10 = mmap(0LL, v13.st_size, 3, 1, v8, 0LL);
v11 = v10;
if ( v10 == (void *)-1LL )
sys_err("target file mmap err");
memcpy(v10, v9, v13.st_size);
munmap(v9, v13.st_size);
munmap(v11, v13.st_size);
close(v6);
close(v8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *file, char *src)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // r13
int v5; // eax
int v6; // ebx
int v7; // eax
int v8; // ebp
void *v9; // r13
void *v10; // rax
void *v11; // r12
struct stat v13; // [rsp+0h] [rbp-B8h] BYREF

v2 = strlen(file);
v3 = strlen(src);
v4 = (char *)malloc(8 * (v2 + v3 + 1));
v5 = open(file, 0);
if ( v5 < 0 )
func8("Fail to open source_file");
v6 = v5;
func14(v5, &v13);
if ( (unsigned int)func9(src) )
sprintf(v4, "%s/%s", src, file);
else
strcpy(v4, src);
v7 = open(v4, 578, v13.st_mode);
v8 = v7;
if ( v7 < 0 )
func8("Fail to open target_file");
if ( ftruncate(v7, v13.st_size) < 0 )
func8("Fail to ftruncate");
v9 = mmap(0LL, v13.st_size, 1, 2, v6, 0LL);
if ( v9 == (void *)-1LL )
func8("source file mmap err");
v10 = mmap(0LL, v13.st_size, 3, 1, v8, 0LL);
v11 = v10;
if ( v10 == (void *)-1LL )
func8("target file mmap err");
memcpy(v10, v9, v13.st_size);
munmap(v9, v13.st_size);
munmap(v11, v13.st_size);
close(v6);
close(v8);
return 0LL;
}

original_code:
int tcpm(const char *src, const char *dst) {
  int sdf, ddf;
  void *mr, *mw;
  struct stat per;
  char *ndst =
      (char *)malloc
      ((strlen(src) + strlen(dst) + 1) * sizeof(char *));
  if ((sdf = open(src, 00)) < 0)
    sys_err("Fail to open source_file");
  fstat(sdf, &per);
  if (is_dir(dst)) {
    (void)sprintf(ndst, "%s/%s", dst, src);
  } else {
    strcpy(ndst, dst);
  }
  if ((ddf = open(ndst, 02 | 0100 | 01000, per.st_mode)) <
      0)
    sys_err("Fail to open target_file");
  if (ftruncate(ddf, per.st_size) < 0) {
    sys_err("Fail to ftruncate");
  }
  if ((mr = mmap(0, per.st_size, 0x1, 0x02, sdf, 0)) ==
      ((void *) -1)) {
    sys_err("source file mmap err");
  }
  if ((mw = mmap(0, per.st_size, 0x1 | 0x2, 0x01, ddf, 0)) ==
      ((void *) -1)) {
    sys_err("target file mmap err");
  }
  if (memcpy(mw, mr, per.st_size) == ((void *)0)) {
    sys_err("memory copy err");
  }
  munmap(mr, per.st_size);
  munmap(mw, per.st_size);
  close(sdf);
  close(ddf);
  return 0;
}

canonical_original_code:
int tcpm(char *src, char *dst) {
  int sdf; int ddf;
  void *mr; void *mw;
  struct stat per;
  char *ndst = (char *)malloc
      ((strlen(src) + strlen(dst) + 1) * sizeof(char *));
  if ((sdf = open(src, 00)) < 0)
    sys_err("Fail to open source_file");
  fstat(sdf, &per);
  if (is_dir(dst)) {
    (void)sprintf(ndst, "%s/%s", dst, src);
  } else {
    strcpy(ndst, dst);
  }
  if ((ddf = open(ndst, 02 | 0100 | 01000, per.st_mode)) <
      0)
    sys_err("Fail to open target_file");
  if (ftruncate(ddf, per.st_size) < 0) {
    sys_err("Fail to ftruncate");
  }
  if ((mr = mmap(0, per.st_size, 0x1, 0x02, sdf, 0)) ==
      ((void *) -1)) {
    sys_err("source file mmap err");
  }
  if ((mw = mmap(0, per.st_size, 0x1 | 0x2, 0x01, ddf, 0)) ==
      ((void *) -1)) {
    sys_err("target file mmap err");
  }
  if (memcpy(mw, mr, per.st_size) == ((void *)0)) {
    sys_err("memory copy err");
  }
  munmap(mr, per.st_size);
  munmap(mw, per.st_size);
  close(sdf);
  close(ddf);
  return 0;
}

variable_types:
src
char *

variable_types:
dst
char *

variable_types: sdf int

variable_types: ddf int

variable_types:
mr
void *

variable_types:
mw
void *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
ndst
char *


usage

decompiled_code:
void __noreturn usage()
{
const char *v0; // rax

v0 = (const char *)getprogname();
fprintf(stderr, "usage: %s source_file target_file\n", v0);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
const char *v0; // rax

v0 = (const char *)getprogname();
fprintf(stderr, "usage: %s source_file target_file\n", v0);
exit(1);
}

canonical_original_code:
void usage() {
  (void)fprintf(stderr, "usage: %s source_file target_file\n", getprogname());
  exit(1);
}


decompiled_code:
__int64 __fastcall is_dir(char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat(a1, &v2);
if ( (_DWORD)result )
return 0LL;
if ( (v2.st_mode & 0x4000) != 0 )
return 1LL;
if ( (v2.st_mode & 0x8000) == 0 )
sys_err("Neither directory nor regular file:");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
__int64 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = func13(a1, &v2);
if ( (_DWORD)result )
return 0LL;
if ( (v2.st_mode & 0x4000) != 0 )
return 1LL;
if ( (v2.st_mode & 0x8000) == 0 )
func8("Neither directory nor regular file:");
return result;
}

original_code:
int is_dir(const char *path) {
  struct stat st;
  if (stat(path, &st) == 0) {
    if (st.st_mode & 0040000)
      return 1;
    else if (st.st_mode & 0100000)
      return 0;
    else
      sys_err("Neither directory nor regular file:");
  }
  return 0;
}

canonical_original_code:
int is_dir(char *path) {
  struct stat st;
  if (stat(path, &st) == 0) {
    if (st.st_mode & 0040000)
      return 1;
    else if (st.st_mode & 0100000)
      return 0;
    else
      sys_err("Neither directory nor regular file:");
  }
  return 0;
}

variable_types:
path
char *


main

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

v4 = *argv;
setprogname();
if ( argc != 3 )
usage(v4);
if ( (unsigned int)tcpm((char *)argv[1], (char *)argv[2]) )
exit(1);
return 0;
}

original_code:
int main(int argc, char const *argv[]) {
  const char *src, *dst;
  int flag;
  setprogname(argv[0]);
  if (argc != 3)
    usage();
  src = argv[1], dst = argv[2];
  if ((flag = tcpm(src, dst)) != 0)
    exit(1);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char *src; char *dst;
  int flag;
  setprogname(argv[0]);
  if (argc != 3)
    usage();
  src = argv[1], dst = argv[2];
  if ((flag = tcpm(src, dst)) != 0)
    exit(1);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: flag int


repo: Wilbeibi/sws

decompiled_code:
void clean_up(void)
{
pidfile_remove(pfh);
}

canonical_decompiled_code:
void func0(void)
{
pidfile_remove(pfh);
}

original_code:
static void clean_up()
{
    (void)pidfile_remove(pfh);
    return;
}


decompiled_code:
void sig_term()
{
clean_up();
signal(15, 0LL);
raise(15);
}

canonical_decompiled_code:
void func1()
{
func0();
signal(15, 0LL);
raise(15);
}

original_code:
static void sig_term(int sig)
{
    clean_up();
    signal(15, ((__sighandler_t) 0));
    raise(15);
    return;
}

canonical_original_code:
static void sig_term(int sig)
{
    clean_up();
    signal(15, ((void (*)(int)) 0));
    raise(15);
    return;
}

variable_types: sig int


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"usage: %s <cdhilp> dir\n"
" -c dir Allow execution of CGIs from the given directory.\n"
" -d Enter debugging mode.\n"
" -h Print a short usage summary and exit.\n"
" -i address Bind to the given IPv4 or IPv6 address\n"
" -l file Log all requests to the given file.\n"
" -p port Listen on the given port.\n",
(const char *)progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
fprintf(
stderr,
"usage: %s <cdhilp> dir\n"
" -c dir Allow execution of CGIs from the given directory.\n"
" -d Enter debugging mode.\n"
" -h Print a short usage summary and exit.\n"
" -i address Bind to the given IPv4 or IPv6 address\n"
" -l file Log all requests to the given file.\n"
" -p port Listen on the given port.\n",
(const char *)progname);
exit(1);
}

original_code:
static void usage(){
    fprintf(stderr, "usage: %s <cdhilp> dir\n            -c dir Allow execution of CGIs from the given directory.\n            -d Enter debugging mode.\n            -h Print a short usage summary and exit.\n            -i address Bind to the given IPv4 or IPv6 address\n            -l file Log all requests to the given file.\n            -p port Listen on the given port.\n", progname);
    exit( 1 );
}


decompiled_code:
void __fastcall check_path(const char *a1)
{
char *v1; // rbx
struct stat v2; // [rsp-18h] [rbp-98h] BYREF

if ( a1 )
{
v1 = (char *)a1;
if ( lstat(a1, &v2) == -1 )
sys_err(a1);
if ( (v2.st_mode & 0x4000) == 0 )
sys_err("Invalid path. Not a dir");
if ( *a1 )
{
do
++v1;
while ( *v1 );
}
if ( *(v1 - 1) != 47 )
{
*v1 = 47;
v1[1] = 0;
}
}
}

canonical_decompiled_code:
void __fastcall func3(const char *a1)
{
char *v1; // rbx
struct stat v2; // [rsp-18h] [rbp-98h] BYREF

if ( a1 )
{
v1 = (char *)a1;
if ( lstat(a1, &v2) == -1 )
sys_err(a1);
if ( (v2.st_mode & 0x4000) == 0 )
sys_err("Invalid path. Not a dir");
if ( *a1 )
{
do
++v1;
while ( *v1 );
}
if ( *(v1 - 1) != 47 )
{
*v1 = 47;
v1[1] = 0;
}
}
}

original_code:
static void check_path(char * path)
{
    struct stat st;
    char * tmp;
    if (path != ((void *)0)){
        if (lstat(path, &st) == -1)
            sys_err(path);
        if ( !(st.st_mode & 0040000 ))
            sys_err("Invalid path. Not a dir");
        tmp = path;
        while (*tmp != '\0')
            tmp++;
        if (*(tmp-1) != '/') {
            *(tmp) = '/';
            *(tmp+1) = '\0';
        }
    }
}

canonical_original_code:
static void check_path(char *path)
{
    struct stat st;
    char *tmp;
    if (path != ((void *)0)){
        if (lstat(path, &st) == -1)
            sys_err(path);
        if ( !(st.st_mode & 0040000 ))
            sys_err("Invalid path. Not a dir");
        tmp = path;
        while (*tmp != '\0')
            tmp++;
        if (*(tmp-1) != '/') {
            *(tmp) = '/';
            *(tmp+1) = '\0';
        }
    }
}

variable_types:
tmp
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // eax
const char *v5; // rdi
char *v6; // rax
int v7; // eax
int v8; // eax
int v9; // eax
int result; // eax
int v11[66]; // [rsp+0h] [rbp-158h] BYREF
char *endptr; // [rsp+108h] [rbp-50h] BYREF
char *name; // [rsp+110h] [rbp-48h] BYREF
void *v14; // [rsp+118h] [rbp-40h]
char *src; // [rsp+120h] [rbp-38h]
void *ptr; // [rsp+128h] [rbp-30h]
void *v17; // [rsp+130h] [rbp-28h]

progname = (__int64)*argv;
logDir = 0LL;
name = 0LL;
v14 = 0LL;
src = 0LL;
ptr = "8080";
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "c:dhi:l:p:");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'c':
name = optarg;
break;
case 'd':
debug = 1;
src = "./tmp.log";
break;
case 'h':
usage();
return result;
case 'i':
v14 = optarg;
break;
case 'l':
src = optarg;
break;
case 'p':
v4 = strtol(optarg, &endptr, 10);
if ( *endptr || v4 > 0xFFFF )
{
fwrite("Please input Port Number between 0-65535\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
ptr = optarg;
break;
default:
usage();
return result;
}
}
if ( argc - optind <= 1 )
{
v5 = argv[optind];
if ( v5 )
{
v17 = (void *)argv[optind];
v17 = realpath(v5, 0LL);
check_path((const char *)v17);
name = realpath(name, 0LL);
check_path(name);
if ( src )
{
strcpy((char *)v11, src);
v6 = dirname((char *)v11);
check_path(v6);
logDir = strdup(src);
if ( !logDir )
sys_err("strdup failed");
log_fd = fopen(logDir, "a");
if ( !log_fd )
sys_err("open log failed");
if ( debug )
{
v7 = fileno(log_fd);
dup2(1, v7);
}
else
{
v8 = fileno(log_fd);
dup2(v8, 2);
v9 = fileno(log_fd);
dup2(v9, 1);
}
}
if ( !debug )
{
signal(15, (__sighandler_t)sig_term);
atexit(clean_up);
pfh = pidfile_open("/tmp/sws", 448LL, v11);
if ( !pfh )
{
if ( *_errno_location() == 17 )
errx(1, "already running, pid: %d", (unsigned int)v11[0]);
warn("can't open or create pidfile");
}
if ( daemon(1, 0) == -1 )
{
pidfile_remove(pfh);
err(1, "can't daemonize");
}
pidfile_write(pfh);
}
server_listen(&name);
free(ptr);
free(v14);
free(v17);
if ( logDir )
free(logDir);
if ( name )
free(name);
if ( src )
free(src);
exit(0);
}
usage();
}
usage();
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // eax
const char *v5; // rdi
char *v6; // rax
int v7; // eax
int v8; // eax
int v9; // eax
int result; // eax
int v11[66]; // [rsp+0h] [rbp-158h] BYREF
char *endptr; // [rsp+108h] [rbp-50h] BYREF
char *name; // [rsp+110h] [rbp-48h] BYREF
void *v14; // [rsp+118h] [rbp-40h]
char *src; // [rsp+120h] [rbp-38h]
void *ptr; // [rsp+128h] [rbp-30h]
void *v17; // [rsp+130h] [rbp-28h]

progname = (__int64)*argv;
logDir = 0LL;
name = 0LL;
v14 = 0LL;
src = 0LL;
ptr = "8080";
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "c:dhi:l:p:");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'c':
name = optarg;
break;
case 'd':
debug = 1;
src = "./tmp.log";
break;
case 'h':
func2();
return result;
case 'i':
v14 = optarg;
break;
case 'l':
src = optarg;
break;
case 'p':
v4 = strtol(optarg, &endptr, 10);
if ( *endptr || v4 > 0xFFFF )
{
fwrite("Please input Port Number between 0-65535\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
ptr = optarg;
break;
default:
func2();
return result;
}
}
if ( argc - optind <= 1 )
{
v5 = argv[optind];
if ( v5 )
{
v17 = (void *)argv[optind];
v17 = realpath(v5, 0LL);
func3((const char *)v17);
name = realpath(name, 0LL);
func3(name);
if ( src )
{
strcpy((char *)v11, src);
v6 = dirname((char *)v11);
func3(v6);
logDir = strdup(src);
if ( !logDir )
sys_err("strdup failed");
log_fd = fopen(logDir, "a");
if ( !log_fd )
sys_err("open log failed");
if ( debug )
{
v7 = fileno(log_fd);
dup2(1, v7);
}
else
{
v8 = fileno(log_fd);
dup2(v8, 2);
v9 = fileno(log_fd);
dup2(v9, 1);
}
}
if ( !debug )
{
signal(15, (__sighandler_t)sig_term);
atexit(clean_up);
pfh = pidfile_open("/tmp/sws", 448LL, v11);
if ( !pfh )
{
if ( *_errno_location() == 17 )
errx(1, "already running, pid: %d", (unsigned int)v11[0]);
warn("can't open or create pidfile");
}
if ( daemon(1, 0) == -1 )
{
pidfile_remove(pfh);
err(1, "can't daemonize");
}
pidfile_write(pfh);
}
server_listen(&name);
free(ptr);
free(v14);
free(v17);
if ( logDir )
free(logDir);
if ( name )
free(name);
if ( src )
free(src);
exit(0);
}
func2();
}
func2();
return result;
}

original_code:
int main(int argc, char *argv[])
{
    int opt = 0;
    Arg_t optInfo;
    progname = argv[0];
    logDir = ((void *)0);
    optInfo.cgiDir = ((void *)0);
    optInfo.ipAddr = ((void *)0);
    optInfo.logFile = ((void *)0);
    optInfo.port = "8080";
    const char *optString = "c:dhi:l:p:";
    char *endptr;
    int pt;
    while((opt = getopt(argc, argv, optString)) != -1){
        switch(opt){
        case 'c':
            optInfo.cgiDir = optarg;
            break;
        case 'd':
            debug=1;
            optInfo.logFile="./tmp.log";
            break;
        case 'h':
            usage();
            break;
        case 'i':
            optInfo.ipAddr = optarg;
            break;
        case 'l':
            optInfo.logFile = optarg;
            break;
        case 'p':
            pt = strtol(optarg, &endptr, 10);
            if(!*endptr && pt >= 0 && pt <= 65535)
                optInfo.port = optarg;
            else
                fprintf(stderr,"Please input Port Number between 0-65535\n"), exit(1);
            break;
        default:
            usage();
            break;
        }
    }
    argc -= optind;
    argv += optind;
    if (argc>1) {
        usage();
    }
    if (*argv == ((void *)0))
        usage();
    optInfo.dir= *argv;
    optInfo.dir = realpath(optInfo.dir,((void *)0));
    check_path(optInfo.dir);
    optInfo.cgiDir = realpath(optInfo.cgiDir,((void *)0));
    check_path(optInfo.cgiDir);
    if (optInfo.logFile) {
        char temp[256];
        strcpy(temp,optInfo.logFile);
        check_path(dirname(temp));
        logDir = strdup(optInfo.logFile);
        if (logDir == ((void *)0))
            sys_err("strdup failed");
        log_fd = fopen( logDir, "a" );
        if (log_fd == ((void *)0))
            sys_err("open log failed");
        if (debug) {
            dup2(1, fileno(log_fd));
        } else {
            dup2(fileno(log_fd), 2);
            dup2(fileno(log_fd), 1);
        }
    }
    if (!debug) {
        signal(15, sig_term);
        atexit(clean_up);
        int opid;
        pfh=pidfile_open("/tmp/sws", 0700, &opid);
        if (pfh==((void *)0)) {
            if ((*__errno_location ())==17)
                errx(1, "already running, pid: %d", opid);
            warn("can't open or create pidfile");
        }
        if (daemon(1, 0)==-1) {
            pidfile_remove(pfh);
            err(1, "can't daemonize");
        }
        pidfile_write(pfh);
    }
    server_listen(&optInfo);
    free(optInfo.port);
    free(optInfo.ipAddr);
    free(optInfo.dir);
    if (logDir) free(logDir);
    if (optInfo.cgiDir) free(optInfo.cgiDir);
    if (optInfo.logFile) free(optInfo.logFile);
    exit( 0 );
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int opt = 0;
    struct arg_t optInfo;
    progname = argv[0];
    logDir = ((void *)0);
    optInfo.cgiDir = ((void *)0);
    optInfo.ipAddr = ((void *)0);
    optInfo.logFile = ((void *)0);
    optInfo.port = "8080";
    char *optString = "c:dhi:l:p:";
    char *endptr;
    int pt;
    while((opt = getopt(argc, argv, optString)) != -1){
        switch(opt){
        case 'c':
            optInfo.cgiDir = optarg;
            break;
        case 'd':
            debug=1;
            optInfo.logFile="./tmp.log";
            break;
        case 'h':
            usage();
            break;
        case 'i':
            optInfo.ipAddr = optarg;
            break;
        case 'l':
            optInfo.logFile = optarg;
            break;
        case 'p':
            pt = strtol(optarg, &endptr, 10);
            if(!*endptr && pt >= 0 && pt <= 65535)
                optInfo.port = optarg;
            else
                fprintf(stderr,"Please input Port Number between 0-65535\n"), exit(1);
            break;
        default:
            usage();
            break;
        }
    }
    argc -= optind;
    argv += optind;
    if (argc>1) {
        usage();
    }
    if (*argv == ((void *)0))
        usage();
    optInfo.dir= *argv;
    optInfo.dir = realpath(optInfo.dir,((void *)0));
    check_path(optInfo.dir);
    optInfo.cgiDir = realpath(optInfo.cgiDir,((void *)0));
    check_path(optInfo.cgiDir);
    if (optInfo.logFile) {
        char temp[256];
        strcpy(temp,optInfo.logFile);
        check_path(dirname(temp));
        logDir = strdup(optInfo.logFile);
        if (logDir == ((void *)0))
            sys_err("strdup failed");
        log_fd = fopen( logDir, "a" );
        if (log_fd == ((void *)0))
            sys_err("open log failed");
        if (debug) {
            dup2(1, fileno(log_fd));
        } else {
            dup2(fileno(log_fd), 2);
            dup2(fileno(log_fd), 1);
        }
    }
    if (!debug) {
        signal(15, sig_term);
        atexit(clean_up);
        int opid;
        pfh=pidfile_open("/tmp/sws", 0700, &opid);
        if (pfh==((void *)0)) {
            if ((*__errno_location ())==17)
                errx(1, "already running, pid: %d", opid);
            warn("can't open or create pidfile");
        }
        if (daemon(1, 0)==-1) {
            pidfile_remove(pfh);
            err(1, "can't daemonize");
        }
        pidfile_write(pfh);
    }
    server_listen(&optInfo);
    free(optInfo.port);
    free(optInfo.ipAddr);
    free(optInfo.dir);
    if (logDir) free(logDir);
    if (optInfo.cgiDir) free(optInfo.cgiDir);
    if (optInfo.logFile) free(optInfo.logFile);
    exit( 0 );
}

variable_types: opt int

variable_types: struct arg_t { char *cgiDir; char *ipAddr; char *logFile; char *port; char *dir; }

variable_types:
optString
char *

variable_types:
endptr
char *

variable_types: pt int

variable_types:
temp
char [256]

variable_types: opid int


decompiled_code:
void __noreturn wt_timeout()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
exit(0);
}

original_code:
static void
wt_timeout(int sig)
{
    exit(0);
}


decompiled_code:
void __noreturn rd_timeout()
{
err_response((unsigned int)sock, 408LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
err_response((unsigned int)sock, 408LL);
exit(0);
}

original_code:
static void
rd_timeout(int sig)
{
    (void)err_response(_sock, 408);
    exit(0);
}


decompiled_code:
__int64 __fastcall read_req_line(unsigned int a1, __int64 a2, const char *a3)
{
__int64 result; // rax
bool v5; // zf

do
{
result = Readline(a1, a3);
if ( (_DWORD)result == -1 )
{
*(_DWORD *)(a2 + 4) = 500;
return 0xFFFFFFFFLL;
}
v5 = strcmp(a3, "\r") == 0;
}
while ( (_DWORD)result == 1 || v5 );
if ( (int)result > 0x2000 )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
if ( *(_DWORD *)(a2 + 4) != 200 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, const char *a3)
{
__int64 result; // rax
bool v5; // zf

do
{
result = Readline(a1, a3);
if ( (_DWORD)result == -1 )
{
*(_DWORD *)(a2 + 4) = 500;
return 0xFFFFFFFFLL;
}
v5 = strcmp(a3, "\r") == 0;
}
while ( (_DWORD)result == 1 || v5 );
if ( (int)result > 0x2000 )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
if ( *(_DWORD *)(a2 + 4) != 200 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int
read_req_line(int sock, Req_info *req, char *buf)
{
    int ret=0;
    while(1) {
        if ((ret=Readline(sock, buf))==-1) {
            req->status=500;
            break;
        } else if (!strcmp(buf,"\r") || ret==1){
            continue;
        } else if (ret > 8192) {
            req->status=400;
            break;
        } else
            break;
    }
    if (req->status != 200)
        return -1;
    return ret;
}

canonical_original_code:
static int read_req_line(int sock, struct req_info *req, char *buf)
{
    int ret = 0;
    while(1) {
        if ((ret=Readline(sock, buf))==-1) {
            req->status=500;
            break;
        } else if (!strcmp(buf,"\r") || ret==1){
            continue;
        } else if (ret > 8192) {
            req->status=400;
            break;
        } else
            break;
    }
    if (req->status != 200)
        return -1;
    return ret;
}

variable_types: sock int

variable_types: struct req_info { int method; int status; int cgi; int contLen; char uri[256]; char fstLine[256]; char clientIp[16]; char recvTime[256]; char ifModified[128]; char query[256]; char msg_body[1024]; } *

variable_types:
buf
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall read_rest(unsigned int a1, __int64 a2)
{
int v2; // ebx
int v3; // eax
bool v4; // zf
_BYTE savedregs[8232]; // [rsp+0h] [rbp+0h] BYREF

v2 = 0;
do
{
v3 = Readline(a1, savedregs);
if ( !v3 )
break;
if ( v3 == -1 )
{
*(_DWORD *)(a2 + 4) = 500;
return (unsigned int)-1;
}
if ( v3 > 0x1FFF )
{
*(_DWORD *)(a2 + 4) = 400;
return (unsigned int)-1;
}
v2 += v3;
if ( v2 > 0x1FFF )
{
*(_DWORD *)(a2 + 4) = 400;
return (unsigned int)-1;
}
v4 = strcmp(savedregs, "\r") == 0;
}
while ( v3 != 1 && !v4 );
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
int v2; // ebx
int v3; // eax
bool v4; // zf
_BYTE savedregs[8232]; // [rsp+0h] [rbp+0h] BYREF

v2 = 0;
do
{
v3 = Readline(a1, savedregs);
if ( !v3 )
break;
if ( v3 == -1 )
{
*(_DWORD *)(a2 + 4) = 500;
return (unsigned int)-1;
}
if ( v3 > 0x1FFF )
{
*(_DWORD *)(a2 + 4) = 400;
return (unsigned int)-1;
}
v2 += v3;
if ( v2 > 0x1FFF )
{
*(_DWORD *)(a2 + 4) = 400;
return (unsigned int)-1;
}
v4 = strcmp(savedregs, "\r") == 0;
}
while ( v3 != 1 && !v4 );
return (unsigned int)v2;
}

original_code:
static int
read_rest(int sock, Req_info *req)
{
    int ret;
    int tot=0;
    char tmp[8192];
    while ((ret=Readline(sock, tmp))) {
        if (ret==-1) {
            req->status=500;
            return -1;
        }
        if (ret>=8192) {
            req->status=400;
            return -1;
        }
        tot+=ret;
        if (tot>=8192) {
            req->status=400;
            return -1;
        }
        if (!strcmp(tmp, "\r") || ret==1)
            break;
    }
    return tot;
}

canonical_original_code:
static int read_rest(int sock, struct req_info *req)
{
    int ret;
    int tot = 0;
    char tmp[8192];
    while ((ret=Readline(sock, tmp))) {
        if (ret==-1) {
            req->status=500;
            return -1;
        }
        if (ret>=8192) {
            req->status=400;
            return -1;
        }
        tot+=ret;
        if (tot>=8192) {
            req->status=400;
            return -1;
        }
        if (!strcmp(tmp, "\r") || ret==1)
            break;
    }
    return tot;
}

variable_types: tot int

variable_types:
tmp
char [8192]

user_defined_types: struct req_info { int method; int status; int cgi; int contLen; char uri[256]; char fstLine[256]; char clientIp[16]; char recvTime[256]; char ifModified[128]; char query[256]; char msg_body[1024]; }


decompiled_code:
__int64 __fastcall init_req(__int64 a1)
{
int v1; // eax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v1 = a1;
*(_DWORD *)(a1 + 4) = 200;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)(a1 + 800) = 0LL;
*(_QWORD *)(a1 + 920) = 0LL;
v2 = (void *)((a1 + 808) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)(v1 - (_DWORD)v2 + 928) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v1 = a1;
*(_DWORD *)(a1 + 4) = 200;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 8) = 0;
*(_QWORD *)(a1 + 800) = 0LL;
*(_QWORD *)(a1 + 920) = 0LL;
v2 = (void *)((a1 + 808) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)(v1 - (_DWORD)v2 + 928) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

original_code:
void init_req(Req_info * req)
{
    req->status = 200;
    req->contLen = 0;
    req->method = 0;
    req->cgi = 0;
    memset(req->ifModified,0,128);
}

canonical_original_code:
void init_req(struct req_info *req)
{
    req->status = 200;
    req->contLen = 0;
    req->method = 0;
    req->cgi = 0;
    memset(req->ifModified,0,128);
}


original_code:
void process_path(char * uri)
{
    char buf[256];
    char temp[256];
    char *bufp=buf;
    int ind=0, i, j;
    int len=strlen(uri);
    buf[0]='/';
    buf[1]=0;
    for (i=0; i<len; i++) {
        while (i<len && uri[i]=='/') i++;
        while (i<len && uri[i]!='/') temp[ind++]=uri[i++];
        temp[ind]=0;
        if (temp[0]==0)
            continue;
        if (strcmp(temp, "..")!=0) {
            *bufp='/';
            bufp++;
            for (j=0; j<ind; j++) {
                *bufp=temp[j];
                bufp++;
            }
            *bufp=0;
        } else {
            while (*bufp!='/') bufp--;
            if (bufp==buf) {
                *bufp='/';
                *(bufp+1)=0;
            } else
                *bufp=0;
        }
        ind=0;
    }
    strcpy(uri, buf);
}

canonical_original_code:
void process_path(char *uri)
{
    char buf[256];
    char temp[256];
    char *bufp = buf;
    int ind = 0; int i; int j;
    int len = strlen(uri);
    buf[0]='/';
    buf[1]=0;
    for (i=0; i<len; i++) {
        while (i<len && uri[i]=='/') i++;
        while (i<len && uri[i]!='/') temp[ind++]=uri[i++];
        temp[ind]=0;
        if (temp[0]==0)
            continue;
        if (strcmp(temp, "..")!=0) {
            *bufp='/';
            bufp++;
            for (j=0; j<ind; j++) {
                *bufp=temp[j];
                bufp++;
            }
            *bufp=0;
        } else {
            while (*bufp!='/') bufp--;
            if (bufp==buf) {
                *bufp='/';
                *(bufp+1)=0;
            } else
                *bufp=0;
        }
        ind=0;
    }
    strcpy(uri, buf);
}

variable_types:
uri
char *

variable_types:
buf
char [256]

variable_types:
bufp
char *

variable_types: ind int

variable_types: i int

variable_types: j int

variable_types: len int


decompiled_code:
char *__fastcall get_GET_query(__int64 a1, const char *a2)
{
char *result; // rax
char *v3; // rbx

result = strchr(a2, 63);
if ( result )
{
v3 = result;
if ( *(_DWORD *)a1 == 1 )
result = strcpy((char *)(a1 + 928), result + 1);
*v3 = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, const char *a2)
{
char *result; // rax
char *v3; // rbx

result = strchr(a2, 63);
if ( result )
{
v3 = result;
if ( *(_DWORD *)a1 == 1 )
result = strcpy((char *)(a1 + 928), result + 1);
*v3 = 0;
}
return result;
}

original_code:
void get_GET_query(Req_info * req, char * source)
{
    char * tmp = strstr(source,"?");
    if (tmp != ((void *)0) && req->method == 1) {
        strcpy(req->query,tmp+1);
    }
    if (tmp != ((void *)0))
        *tmp = '\0';
}

canonical_original_code:
void get_GET_query(struct req_info *req, char *source)
{
    char *tmp = strstr(source,"?");
    if (tmp != ((void *)0) && req->method == 1) {
        strcpy(req->query,tmp+1);
    }
    if (tmp != ((void *)0))
        *tmp = '\0';
}

variable_types:
source
char *

variable_types:
tmp
char *


original_code:
int parse_uri(Req_info * req, Arg_t *optInfo)
{
    char _uri[256]; strcpy(_uri, req->uri);
    char *uri=strtok(_uri, "?");
    (void)strtok(((void *)0), "?");
    char *gar=strtok(((void *)0), "?");
    if (gar!=((void *)0)) {
        req->status=400;
        return -1;
    }
    char *tmp=uri;
    char usr[256];
    char rest[256];
    int i;
    req->cgi=0;
    if (strncmp(uri,"~",1) == 0) {
        tmp += 1;
        i = 0;
        while (*tmp != '/' ) {
            if ( *tmp == '\0') {
    req->status=404;
    return -1;
            }
            usr[i++] = *tmp++;
        }
        usr[i]='\0';
        struct passwd *pwd;
        if ((pwd=getpwnam(usr))==((void *)0)) {
            req->status=404;
            return -1;
        }
        strncpy(rest,tmp+1,256);
        process_path(rest);
            sprintf(req->uri,"/home/%s/sws/%s",usr,rest+1);
    }
    else if (strncmp(uri,"/cgi-bin/",9) == 0) {
        req->cgi=1;
        tmp = uri;
        tmp += 9;
        strncpy(rest,tmp,256);
        if (optInfo->cgiDir != ((void *)0)) {
            req->cgi=1;
            process_path(rest);
            get_GET_query(req,rest);
            sprintf(req->uri,"%s%s",optInfo->cgiDir,rest+1);
        }
        else {
            char tmp2[256];
            strcpy(tmp2,req->uri);
            process_path(req->uri);
            sprintf(req->uri,"%s%s",optInfo->dir, tmp2+1);
        }
    }
    else {
        char tmp2[256];
        strcpy(tmp2,req->uri);
        process_path(tmp2);
        sprintf(req->uri,"%s%s",optInfo->dir, tmp2+1);
    }
    return 0;
}

canonical_original_code:
int parse_uri(struct req_info *req, struct arg_t *optInfo)
{
    char _uri[256]; strcpy(_uri, req->uri);
    char *uri = strtok(_uri, "?");
    (void)strtok(((void *)0), "?");
    char *gar = strtok(((void *)0), "?");
    if (gar!=((void *)0)) {
        req->status=400;
        return -1;
    }
    char *tmp = uri;
    char usr[256];
    char rest[256];
    int i;
    req->cgi=0;
    if (strncmp(uri,"~",1) == 0) {
        tmp += 1;
        i = 0;
        while (*tmp != '/' ) {
            if ( *tmp == '\0') {
    req->status=404;
    return -1;
            }
            usr[i++] = *tmp++;
        }
        usr[i]='\0';
        struct passwd *pwd;
        if ((pwd=getpwnam(usr))==((void *)0)) {
            req->status=404;
            return -1;
        }
        strncpy(rest,tmp+1,256);
        process_path(rest);
            sprintf(req->uri,"/home/%s/sws/%s",usr,rest+1);
    }
    else if (strncmp(uri,"/cgi-bin/",9) == 0) {
        req->cgi=1;
        tmp = uri;
        tmp += 9;
        strncpy(rest,tmp,256);
        if (optInfo->cgiDir != ((void *)0)) {
            req->cgi=1;
            process_path(rest);
            get_GET_query(req,rest);
            sprintf(req->uri,"%s%s",optInfo->cgiDir,rest+1);
        }
        else {
            char tmp2[256];
            strcpy(tmp2,req->uri);
            process_path(req->uri);
            sprintf(req->uri,"%s%s",optInfo->dir, tmp2+1);
        }
    }
    else {
        char tmp2[256];
        strcpy(tmp2,req->uri);
        process_path(tmp2);
        sprintf(req->uri,"%s%s",optInfo->dir, tmp2+1);
    }
    return 0;
}

variable_types: struct arg_t { char *cgiDir; char *ipAddr; char *logFile; char *port; char *dir; } *

variable_types:
gar
char *

variable_types:
usr
char [256]

variable_types:
rest
char [256]

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 __fastcall parse_req_line(char *a1, __int64 a2)
{
char *v3; // rax
char *v4; // rsi
char *v5; // rbp
__int64 result; // rax
char *v7; // rax
char *v8; // rbp
unsigned int v9; // [rsp+8h] [rbp-20h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = strtok(a1, " ");
if ( !strcmp(v3, "GET") )
{
*(_DWORD *)a2 = 1;
}
else if ( !strcmp(v3, "POST") )
{
*(_DWORD *)a2 = 2;
}
else
{
if ( strcmp(v3, "HEAD") )
{
*(_DWORD *)(a2 + 4) = 501;
return 0xFFFFFFFFLL;
}
*(_DWORD *)a2 = 3;
head_response = 1;
}
v4 = strtok(0LL, " ");
if ( !v4 )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
strcpy((char *)(a2 + 16), v4);
v5 = strtok(0LL, " ");
if ( v5 )
{
if ( strtok(0LL, " ") )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
v7 = strstr(v5, "HTTP/");
if ( !v7 || v5 != v7 )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
v8 = strtok(v7 + 5, " ");
if ( strtok(0LL, " ") )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
v9 = -1;
v10 = -1;
_isoc99_sscanf(v8, "%d.%d", &v9, &v10);
result = v9;
if ( v9 == 1 )
{
result = v10;
if ( v10 )
{
LABEL_25:
*(_DWORD *)(a2 + 4) = 505;
return 0xFFFFFFFFLL;
}
}
else if ( v9 || v10 != 9 )
{
goto LABEL_25;
}
}
else if ( (*(_DWORD *)a2 & 0xFFFFFFFD) == 1 )
{
simple_response = 1;
result = 0LL;
}
else
{
*(_DWORD *)(a2 + 4) = 400;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, __int64 a2)
{
char *v3; // rax
char *v4; // rsi
char *v5; // rbp
__int64 result; // rax
char *v7; // rax
char *v8; // rbp
unsigned int v9; // [rsp+8h] [rbp-20h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = strtok(a1, " ");
if ( !strcmp(v3, "GET") )
{
*(_DWORD *)a2 = 1;
}
else if ( !strcmp(v3, "POST") )
{
*(_DWORD *)a2 = 2;
}
else
{
if ( strcmp(v3, "HEAD") )
{
*(_DWORD *)(a2 + 4) = 501;
return 0xFFFFFFFFLL;
}
*(_DWORD *)a2 = 3;
head_response = 1;
}
v4 = strtok(0LL, " ");
if ( !v4 )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
strcpy((char *)(a2 + 16), v4);
v5 = strtok(0LL, " ");
if ( v5 )
{
if ( strtok(0LL, " ") )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
v7 = strstr(v5, "HTTP/");
if ( !v7 || v5 != v7 )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
v8 = strtok(v7 + 5, " ");
if ( strtok(0LL, " ") )
{
*(_DWORD *)(a2 + 4) = 400;
return 0xFFFFFFFFLL;
}
v9 = -1;
v10 = -1;
_isoc99_sscanf(v8, "%d.%d", &v9, &v10);
result = v9;
if ( v9 == 1 )
{
result = v10;
if ( v10 )
{
LABEL_25:
*(_DWORD *)(a2 + 4) = 505;
return 0xFFFFFFFFLL;
}
}
else if ( v9 || v10 != 9 )
{
goto LABEL_25;
}
}
else if ( (*(_DWORD *)a2 & 0xFFFFFFFD) == 1 )
{
simple_response = 1;
result = 0LL;
}
else
{
*(_DWORD *)(a2 + 4) = 400;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int parse_req_line(char * buf, Req_info * req, Arg_t *optInfo)
{
    char *method;
    char *uri;
    char *version;
    char *gar;
    method=strtok(buf, " ");
    if (strcmp(method, "GET") == 0)
        req->method=1;
    else if (strcmp(method, "POST") == 0)
        req->method=2;
    else if (strcmp(method, "HEAD") == 0) {
        req->method=3;
        _head_response = 1;
    } else {
        req->status=501;
        return -1;
    }
    uri=strtok(((void *)0), " ");
    if (uri==((void *)0)) {
        req->status=400;
        return -1;
    }
    strcpy(req->uri, uri);
    version=strtok(((void *)0), " ");
    if (version==((void *)0)) {
        if (req->method == 1 || req->method==3)
            _simple_response = 1;
        else {
            req->status=400;
            return -1;
        }
    } else {
        gar=strtok(((void *)0), " ");
        if (gar!=((void *)0)) {
            req->status=400;
            return -1;
        }
        char *http=strstr(version, "HTTP/");
        if (http==((void *)0) || http!=version) {
            req->status=400;
            return -1;
        }
        http+=5;
        char *ver=strtok(http, " ");
        gar=strtok(((void *)0), " ");
        if (gar!=((void *)0)) {
            req->status=400;
            return -1;
        }
        int major=-1;
        int minor=-1;
        sscanf(ver, "%d.%d", &major, &minor);
        if ((major==1 && minor==0)
            || (major==0 && minor==9)) {
            return 0;
        }
        req->status=505;
        return -1;
    }
    return 0;
}

canonical_original_code:
int parse_req_line(char *buf, struct req_info *req, struct arg_t *optInfo)
{
    char *method;
    char *uri;
    char *version;
    char *gar;
    method=strtok(buf, " ");
    if (strcmp(method, "GET") == 0)
        req->method=1;
    else if (strcmp(method, "POST") == 0)
        req->method=2;
    else if (strcmp(method, "HEAD") == 0) {
        req->method=3;
        _head_response = 1;
    } else {
        req->status=501;
        return -1;
    }
    uri=strtok(((void *)0), " ");
    if (uri==((void *)0)) {
        req->status=400;
        return -1;
    }
    strcpy(req->uri, uri);
    version=strtok(((void *)0), " ");
    if (version==((void *)0)) {
        if (req->method == 1 || req->method==3)
            _simple_response = 1;
        else {
            req->status=400;
            return -1;
        }
    } else {
        gar=strtok(((void *)0), " ");
        if (gar!=((void *)0)) {
            req->status=400;
            return -1;
        }
        char *http = strstr(version, "HTTP/");
        if (http==((void *)0) || http!=version) {
            req->status=400;
            return -1;
        }
        http+=5;
        char *ver = strtok(http, " ");
        gar=strtok(((void *)0), " ");
        if (gar!=((void *)0)) {
            req->status=400;
            return -1;
        }
        int major = -1;
        int minor = -1;
        sscanf(ver, "%d.%d", &major, &minor);
        if ((major==1 && minor==0)
            || (major==0 && minor==9)) {
            return 0;
        }
        req->status=505;
        return -1;
    }
    return 0;
}

variable_types:
buf
char *

variable_types: struct req_info { int method; int status; int cgi; int contLen; char uri[256]; char fstLine[256]; char clientIp[16]; char recvTime[256]; char ifModified[128]; char query[256]; char msg_body[1024]; } *

variable_types:
method
char *

variable_types:
version
char *

variable_types:
http
char *

variable_types:
ver
char *

variable_types: major int

variable_types: minor int

user_defined_types: struct arg_t { char *cgiDir; char *ipAddr; char *logFile; char *port; char *dir; }


original_code:
void parse_rest(int sock, char * buf, Req_info * req)
{
    char * tmp = strstr(buf,"If-Modified-Since:");
    int i= 0;
    if (tmp != ((void *)0) && req->method == 1) {
        tmp += 18;
        while ( *tmp++ != '\r') {
            req->ifModified[i++] = *tmp;
        }
        req->ifModified[i] = '\0';
    }
    tmp = strstr(buf,"Content-Length:");
    i= 0;
    if (tmp != ((void *)0)) {
        char len[10];
        tmp += 15;
        while ( *tmp++ != '\r' && i<10) {
            len[i++] = *tmp;
        }
        req->contLen = atoi(len);
    }
}

canonical_original_code:
void parse_rest(int sock, char *buf, struct req_info *req)
{
    char *tmp = strstr(buf,"If-Modified-Since:");
    int i = 0;
    if (tmp != ((void *)0) && req->method == 1) {
        tmp += 18;
        while ( *tmp++ != '\r') {
            req->ifModified[i++] = *tmp;
        }
        req->ifModified[i] = '\0';
    }
    tmp = strstr(buf,"Content-Length:");
    i= 0;
    if (tmp != ((void *)0)) {
        char len[10];
        tmp += 15;
        while ( *tmp++ != '\r' && i<10) {
            len[i++] = *tmp;
        }
        req->contLen = atoi(len);
    }
}

variable_types: sock int

variable_types: i int

variable_types:
len
char [10]


decompiled_code:
__int64 __fastcall read_sock(unsigned int a1, __int64 a2, const char **a3)
{
int v4; // er13
int v5; // edx
char v7[8232]; // [rsp+0h] [rbp-2028h] BYREF

sock = a1;
signal(14, (__sighandler_t)rd_timeout);
alarm(0x3Cu);
init_req(a2);
v4 = read_req_line(a1, a2, v7);
strcpy((char *)(a2 + 272), v7);
*(_BYTE *)(a2 + strlen(v7) + 271) = 0;
get_timestamp(a2 + 544);
if ( v4 == -1
|| (unsigned int)parse_req_line(v7, a2) == -1
|| (unsigned int)parse_uri(a2, a3) == -1
|| (unsigned int)read_rest(a1, a2) == -1 )
{
return sws_response(a1, a2);
}
if ( *(_DWORD *)a2 == 2 )
parse_rest(a1, v7, (_DWORD *)a2);
v5 = *(_DWORD *)(a2 + 12);
if ( v5 > 0 )
Read(a1, a2 + 1184, v5);
alarm(0);
signal(14, (__sighandler_t)wt_timeout);
signal(14, (__sighandler_t)wt_timeout);
alarm(0x78u);
return serve_request(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, __int64 a2, const char **a3)
{
int v4; // er13
int v5; // edx
char v7[8232]; // [rsp+0h] [rbp-2028h] BYREF

sock = a1;
signal(14, (__sighandler_t)rd_timeout);
alarm(0x3Cu);
func4(a2);
v4 = func2(a1, a2, v7);
strcpy((char *)(a2 + 272), v7);
*(_BYTE *)(a2 + strlen(v7) + 271) = 0;
get_timestamp(a2 + 544);
if ( v4 == -1
|| (unsigned int)func8(v7, a2) == -1
|| (unsigned int)func7(a2, a3) == -1
|| (unsigned int)func3(a1, a2) == -1 )
{
return sws_response(a1, a2);
}
if ( *(_DWORD *)a2 == 2 )
func9(a1, v7, (_DWORD *)a2);
v5 = *(_DWORD *)(a2 + 12);
if ( v5 > 0 )
Read(a1, a2 + 1184, v5);
alarm(0);
signal(14, (__sighandler_t)wt_timeout);
signal(14, (__sighandler_t)wt_timeout);
alarm(0x78u);
return serve_request(a1, a2);
}

original_code:
void read_sock(int sock, Req_info *req, Arg_t *optInfo)
{
    _sock=sock;
    signal(14, rd_timeout);
    alarm(60);
    int ret;
    char buf[8192];
    init_req(req);
    ret=read_req_line(sock,req,buf);
    strcpy(req->fstLine,buf);
    req->fstLine[strlen(buf)-1]=0;
    get_timestamp(req->recvTime);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    ret=parse_req_line(buf,req,optInfo);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    ret=parse_uri(req, optInfo);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    ret=read_rest(sock,req);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    if (req->method == 2)
    parse_rest(sock,buf,req);
    if (req->contLen > 0)
        Read(sock, req->msg_body, req->contLen);
    alarm(0);
    signal(14, wt_timeout);
    signal(14, wt_timeout);
    alarm(120);
    serve_request(sock,req);
    return;
}

canonical_original_code:
void read_sock(int sock, struct req_info *req, struct arg_t *optInfo)
{
    _sock=sock;
    signal(14, rd_timeout);
    alarm(60);
    int ret;
    char buf[8192];
    init_req(req);
    ret=read_req_line(sock,req,buf);
    strcpy(req->fstLine,buf);
    req->fstLine[strlen(buf)-1]=0;
    get_timestamp(req->recvTime);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    ret=parse_req_line(buf,req,optInfo);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    ret=parse_uri(req, optInfo);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    ret=read_rest(sock,req);
    if (ret==-1) {
        sws_response(sock, req);
        return;
    }
    if (req->method == 2)
    parse_rest(sock,buf,req);
    if (req->contLen > 0)
        Read(sock, req->msg_body, req->contLen);
    alarm(0);
    signal(14, wt_timeout);
    signal(14, wt_timeout);
    alarm(120);
    serve_request(sock,req);
    return;
}

variable_types: ret int

variable_types:
buf
char [8192]


original_code:
void get_timestamp(char *buf)
{
    time_t t;
    struct tm * tmp;
    char *Wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
    char *Mth[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
    time(&t);
    tmp = gmtime(&t);
    sprintf(buf,"%s, %d %s %d %d:%d:%d GMT",Wday[tmp->tm_wday],(tmp->tm_mday),Mth[tmp->tm_mon],(1900+tmp->tm_year),(tmp->tm_hour),(tmp->tm_min),(tmp->tm_sec));
}

canonical_original_code:
void get_timestamp(char *buf)
{
    long t;
    struct tm *tmp;
    char *Wday[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
    char *Mth[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
    time(&t);
    tmp = gmtime(&t);
    sprintf(buf,"%s, %d %s %d %d:%d:%d GMT",Wday[tmp->tm_wday],(tmp->tm_mday),Mth[tmp->tm_mon],(1900+tmp->tm_year),(tmp->tm_hour),(tmp->tm_min),(tmp->tm_sec));
}

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
Wday
char *[]

variable_types:
Mth
char *[]