decompiled_code:
__int64 __fastcall client_receive_msg_s(int a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

addr_len = 128;
v2 = recvfrom(a1, &buf_2, 0xC34FuLL, 0, &addr, &addr_len);
v3 = v2;
if ( v2 != -1 )
{
if ( v2 <= 0 )
{
LOBYTE(v3) = 0;
}
else
{
LOBYTE(v3) = buf_2;
if ( buf_2 == 10 )
{
if ( (unsigned int)(v2 - 1) <= 0x16D3 )
return (unsigned int)-1;
qmemcpy(msg_data_1, &unk_DF01, 0x16D4uLL);
client_process_msg_s_state(a2, msg_data_1);
}
}
v3 = (unsigned __int8)v3;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

addr_len = 128;
v2 = recvfrom(a1, &buf_2, 0xC34FuLL, 0, &addr, &addr_len);
v3 = v2;
if ( v2 != -1 )
{
if ( v2 <= 0 )
{
LOBYTE(v3) = 0;
}
else
{
LOBYTE(v3) = buf_2;
if ( buf_2 == 10 )
{
if ( (unsigned int)(v2 - 1) <= 0x16D3 )
return (unsigned int)-1;
qmemcpy(msg_data_1, &unk_DF01, 0x16D4uLL);
func2(a2, msg_data_1);
}
}
v3 = (unsigned __int8)v3;
}
return v3;
}

original_code:
int client_receive_msg_s (int sfd, struct state *st) {
  static uint8_t buf[50000];
  static struct msg_s_data msg_data;
  struct sockaddr_storage peer_addr;
  socklen_t peer_addr_len = sizeof(peer_addr);
  int nread = recvfrom(sfd, buf, 50000 -1, 0,
      (struct sockaddr *) &peer_addr, &peer_addr_len);
  if (nread == -1) return -1;
  uint8_t msg = 0;
  if (nread >= 1) {
    msg = buf[0];
    switch (msg) {
      case 10:
        if (nread-1 >= sizeof(struct msg_s_data)) {
          memcpy(&msg_data, buf+1, sizeof(struct msg_s_data));
          client_process_msg_s_state (st, &msg_data);
        }
        else {return -1;}
        break;
    }
  }
  return msg;
}

canonical_original_code:
int client_receive_msg_s(int sfd, struct state *st) {
  static unsigned char buf[50000];
  static struct msg_s_data msg_data;
  struct sockaddr_storage peer_addr;
  unsigned int peer_addr_len = sizeof(peer_addr);
  int nread = recvfrom(sfd, buf, 50000 -1, 0,
      (struct sockaddr *) &peer_addr, &peer_addr_len);
  if (nread == -1) return -1;
  unsigned char msg = 0;
  if (nread >= 1) {
    msg = buf[0];
    switch (msg) {
      case 10:
        if (nread-1 >= sizeof(struct msg_s_data)) {
          memcpy(&msg_data, buf+1, sizeof(struct msg_s_data));
          client_process_msg_s_state (st, &msg_data);
        }
        else {return -1;}
        break;
    }
  }
  return msg;
}

variable_types: sfd int

variable_types:
buf
unsigned char [50000]

variable_types: struct msg_s_data { unsigned char control; unsigned char pause_request; unsigned int gold[8]; unsigned int time; unsigned char width; unsigned char height; unsigned char flag[40][29]; unsigned char owner[40][29]; unsigned short pop[40][29]; unsigned char tile[40][29]; }

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

variable_types: nread int

variable_types:
msg
unsigned char

user_defined_types: struct timeline { float data[8][72]; unsigned long time[72]; int mark; }


repo: a-nikolaev/curseofwar

decompiled_code:
void __fastcall send_msg_c(int a1, __int64 a2, char a3, char a4, char a5, char a6)
{
buf_0 = a3;
byte_4C1 = a4;
byte_4C2 = a5;
byte_4C3 = a6;
if ( (unsigned int)sendto(a1, &buf_0, 4uLL, 0, *(const struct sockaddr **)(a2 + 24), *(_DWORD *)(a2 + 16)) == -1 )
perror("client: sendto");
}

canonical_decompiled_code:
void __fastcall func4(int a1, __int64 a2, char a3, char a4, char a5, char a6)
{
buf_0 = a3;
byte_4C1 = a4;
byte_4C2 = a5;
byte_4C3 = a6;
if ( (unsigned int)sendto(a1, &buf_0, 4uLL, 0, *(const struct sockaddr **)(a2 + 24), *(_DWORD *)(a2 + 16)) == -1 )
perror("client: sendto");
}

original_code:
void send_msg_c (int sfd, struct addrinfo *srv_addr, uint8_t msg, uint8_t i, uint8_t j, uint8_t info) {
  struct msg_c_data mcd = {i, j, info};
  static uint8_t buf[50000];
  buf[0] = msg;
  memcpy(buf+1, &mcd, sizeof(mcd));
  int nsent = sendto(sfd, buf, 1+sizeof(mcd), 0, srv_addr->ai_addr, srv_addr->ai_addrlen);
  if (nsent == -1) {
    perror("client: sendto");
  }
}

canonical_original_code:
void send_msg_c(int sfd, struct addrinfo *srv_addr, unsigned char msg, unsigned char i, unsigned char j, unsigned char info) {
  struct msg_c_data mcd = {i, j, info};
  static unsigned char buf[50000];
  buf[0] = msg;
  memcpy(buf+1, &mcd, sizeof(mcd));
  int nsent = sendto(sfd, buf, 1+sizeof(mcd), 0, srv_addr->ai_addr, srv_addr->ai_addrlen);
  if (nsent == -1) {
    perror("client: sendto");
  }
}

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:
i
unsigned char

variable_types:
j
unsigned char

variable_types:
info
unsigned char

variable_types: struct msg_c_data { unsigned char i; unsigned char j; unsigned char info; }

variable_types: nsent int

return_type: void

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; }


decompiled_code:
__int64 __fastcall client_process_input(__int64 a1, unsigned int *a2, char a3, int a4, __int64 a5)
{
unsigned int v5; // er12
unsigned int v6; // er13

v5 = *a2;
v6 = a2[1];
switch ( a3 )
{
case ' ':
if ( *(_DWORD *)(a1 + 4 * ((int)v6 + 29LL * (int)v5 + 2322LL * *(int *)(a1 + 160876) + 11600) + 16) )
send_msg_c(a4, a5, 22, v5, v6, 0);
else
send_msg_c(a4, a5, 21, v5, v6, 0);
goto LABEL_6;
case 'A':
case 'k':
v5 += (int)--v6 % 2 == 1;
goto LABEL_6;
case 'B':
case 'j':
v5 = (__PAIR64__(v5, ++v6 & 1) - 1) >> 32;
goto LABEL_6;
case 'C':
case 'l':
++v5;
goto LABEL_6;
case 'D':
case 'h':
--v5;
goto LABEL_6;
case 'Q':
case 'q':
return 1LL;
case 'c':
send_msg_c(a4, a5, 24, 0, 0, 0);
goto LABEL_6;
case 'p':
if ( *(_DWORD *)(a1 + 160888) )
send_msg_c(a4, a5, 41, 0, 0, 0);
else
send_msg_c(a4, a5, 40, 0, 0, 0);
goto LABEL_6;
case 'r':
case 'v':
send_msg_c(a4, a5, 20, v5, v6, 0);
goto LABEL_6;
case 'x':
send_msg_c(a4, a5, 23, 0, 0, 0);
goto LABEL_6;
default:
LABEL_6:
adjust_cursor(a1, a2, v5, v6);
return 0LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int *a2, char a3, int a4, __int64 a5)
{
unsigned int v5; // er12
unsigned int v6; // er13

v5 = *a2;
v6 = a2[1];
switch ( a3 )
{
case ' ':
if ( *(_DWORD *)(a1 + 4 * ((int)v6 + 29LL * (int)v5 + 2322LL * *(int *)(a1 + 160876) + 11600) + 16) )
func4(a4, a5, 22, v5, v6, 0);
else
func4(a4, a5, 21, v5, v6, 0);
goto LABEL_6;
case 'A':
case 'k':
v5 += (int)--v6 % 2 == 1;
goto LABEL_6;
case 'B':
case 'j':
v5 = (__PAIR64__(v5, ++v6 & 1) - 1) >> 32;
goto LABEL_6;
case 'C':
case 'l':
++v5;
goto LABEL_6;
case 'D':
case 'h':
--v5;
goto LABEL_6;
case 'Q':
case 'q':
return 1LL;
case 'c':
func4(a4, a5, 24, 0, 0, 0);
goto LABEL_6;
case 'p':
if ( *(_DWORD *)(a1 + 160888) )
func4(a4, a5, 41, 0, 0, 0);
else
func4(a4, a5, 40, 0, 0, 0);
goto LABEL_6;
case 'r':
case 'v':
func4(a4, a5, 20, v5, v6, 0);
goto LABEL_6;
case 'x':
func4(a4, a5, 23, 0, 0, 0);
goto LABEL_6;
default:
LABEL_6:
adjust_cursor(a1, a2, v5, v6);
return 0LL;
}
}

original_code:
int client_process_input (struct state *st, struct ui *ui, char c, int sfd, struct addrinfo *srv_addr) {
  int cursi = ui->cursor.i;
  int cursj = ui->cursor.j;
  switch (c) {
      case 'Q':
      case 'q':
        return 1;
      case 'p':
        if (st->speed == sp_pause)
          send_msg_c (sfd, srv_addr, 40, 0, 0, 0);
        else {
          send_msg_c (sfd, srv_addr, 41, 0, 0, 0);
        }
        break;
      case 'h': case 68:
        cursi--;
        break;
      case 'l': case 67:
        cursi++;
        break;
      case 'k': case 65:
        cursj--;
        if (cursj % 2 == 1)
          cursi++;
        break;
      case 'j': case 66:
        cursj++;
        if (cursj % 2 == 0)
          cursi--;
        break;
      case ' ':
        if (st->fg[st->controlled].flag[ui->cursor.i][ui->cursor.j] == 0)
          send_msg_c (sfd, srv_addr, 21, ui->cursor.i, ui->cursor.j, 0);
        else
          send_msg_c (sfd, srv_addr, 22, ui->cursor.i, ui->cursor.j, 0);
        break;
      case 'x':
        send_msg_c (sfd, srv_addr, 23, 0, 0, 0);
        break;
      case 'c':
        send_msg_c (sfd, srv_addr, 24, 0, 0, 0);
        break;
      case 'r':
      case 'v':
        send_msg_c (sfd, srv_addr, 20, ui->cursor.i, ui->cursor.j, 0);
        break;
      case '\033':
      case 91:
        break;
      }
  adjust_cursor(st, ui, cursi, cursj);
  return 0;
}

canonical_original_code:
int client_process_input(struct state *st, struct ui *ui, char c, int sfd, struct addrinfo *srv_addr) {
  int cursi = ui->cursor.i;
  int cursj = ui->cursor.j;
  switch (c) {
      case 'Q':
      case 'q':
        return 1;
      case 'p':
        if (st->speed == sp_pause)
          send_msg_c (sfd, srv_addr, 40, 0, 0, 0);
        else {
          send_msg_c (sfd, srv_addr, 41, 0, 0, 0);
        }
        break;
      case 'h': case 68:
        cursi--;
        break;
      case 'l': case 67:
        cursi++;
        break;
      case 'k': case 65:
        cursj--;
        if (cursj % 2 == 1)
          cursi++;
        break;
      case 'j': case 66:
        cursj++;
        if (cursj % 2 == 0)
          cursi--;
        break;
      case ' ':
        if (st->fg[st->controlled].flag[ui->cursor.i][ui->cursor.j] == 0)
          send_msg_c (sfd, srv_addr, 21, ui->cursor.i, ui->cursor.j, 0);
        else
          send_msg_c (sfd, srv_addr, 22, ui->cursor.i, ui->cursor.j, 0);
        break;
      case 'x':
        send_msg_c (sfd, srv_addr, 23, 0, 0, 0);
        break;
      case 'c':
        send_msg_c (sfd, srv_addr, 24, 0, 0, 0);
        break;
      case 'r':
      case 'v':
        send_msg_c (sfd, srv_addr, 20, ui->cursor.i, ui->cursor.j, 0);
        break;
      case '\033':
      case 91:
        break;
      }
  adjust_cursor(st, ui, cursi, cursj);
  return 0;
}

variable_types: struct state { struct grid { int width; int height; struct tile { enum tile_class { abyss=0, mountain=1, mine=2, grassland=3, village=4, town=5, castle=6 } cl; int pl; int units[8][1]; } tiles[40][29]; } grid; struct flag_grid { int width; int height; int flag[40][29]; int call[40][29]; } fg[8]; struct king { int value[40][29]; int pl; enum strategy { none=0, aggr_greedy=1, one_greedy=2, persistent_greedy=3, opportunist=4, noble=5, midas=6 } strategy; } king[8]; int kings_num; struct timeline { float data[8][72]; unsigned long time[72]; int mark; } timeline; int show_timeline; struct country { long gold; } country[8]; unsigned long time; int map_seed; int controlled; int conditions; int inequality; enum config_speed { sp_pause=0, sp_slowest=1, sp_slower=2, sp_slow=3, sp_normal=4, sp_fast=5, sp_faster=6, sp_fastest=7 } speed; enum config_speed { sp_pause=0, sp_slowest=1, sp_slower=2, sp_slow=3, sp_normal=4, sp_fast=5, sp_faster=6, sp_fastest=7 } prev_speed; enum config_dif { dif_easiest=0, dif_easy=1, dif_normal=2, dif_hard=3, dif_hardest=4 } dif; } *

variable_types: struct ui { struct loc { int i; int j; } cursor; int xskip; int xlength; } *

variable_types: c char

variable_types: cursi int

variable_types: cursj int

return_type: int

user_defined_types: struct state { struct grid grid; struct flag_grid fg[8]; struct king king[8]; int kings_num; struct timeline timeline; int show_timeline; struct country country[8]; unsigned long time; int map_seed; int controlled; int conditions; int inequality; enum config_speed speed; enum config_speed prev_speed; enum config_dif dif; }

user_defined_types: struct ui { struct loc cursor; int xskip; int xlength; }

user_defined_types: struct grid { int width; int height; struct tile tiles[40][29]; }

user_defined_types: struct king { int value[40][29]; int pl; enum strategy strategy; }

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

user_defined_types: struct tile { enum tile_class cl; int pl; int units[8][1]; }


original_code:
void server_send_msg_s_state (int sfd, struct client_record cl[], int cl_num, struct state *st) {
  static uint8_t buf[50000];
  static struct msg_s_data msg_data;
  int p, i, j;
  for (p=0; p<8; ++p) {
    msg_data.gold[p] = htonl( st->country[p].gold );
    msg_data.width = st->fg[p].width;
    msg_data.height =st->fg[p].height;
  }
  msg_data.time = htonl( st->time );
  msg_data.control = 0;
  msg_data.width = st->grid.width;
  msg_data.height = st->grid.height;
  for (i=0; i<40; ++i) {
    for (j=0; j<29; ++j) {
      msg_data.tile[i][j] = st->grid.tiles[i][j].cl;
      int owner = st->grid.tiles[i][j].pl;
      msg_data.owner[i][j] = owner;
      msg_data.pop[i][j] = htons( st->grid.tiles[i][j].units[owner][citizen] );
      msg_data.flag[i][j] = 0;
      for (p=0; p<8; ++p){
        if (st->fg[p].flag[i][j])
          msg_data.flag[i][j] |= (1<<p);
      }
    }
  }
  buf[0] = 10;
  int size = sizeof(msg_data);
  memcpy(buf+1, &msg_data, size);
  int n_to_send = size+1;
  socklen_t peer_addr_len;
  for (i=0; i<cl_num; ++i) {
    peer_addr_len = sizeof (cl[i].sa);
    buf[1] = cl[i].pl;
    sendto(sfd, buf, n_to_send, 0, (struct sockaddr *) &cl[i].sa, peer_addr_len);
  }
}

canonical_original_code:
void server_send_msg_s_state(int sfd, struct client_record cl[], int cl_num, struct state *st) {
  static unsigned char buf[50000];
  static struct msg_s_data msg_data;
  int p; int i; int j;
  for (p=0; p<8; ++p) {
    msg_data.gold[p] = htonl( st->country[p].gold );
    msg_data.width = st->fg[p].width;
    msg_data.height =st->fg[p].height;
  }
  msg_data.time = htonl( st->time );
  msg_data.control = 0;
  msg_data.width = st->grid.width;
  msg_data.height = st->grid.height;
  for (i=0; i<40; ++i) {
    for (j=0; j<29; ++j) {
      msg_data.tile[i][j] = st->grid.tiles[i][j].cl;
      int owner = st->grid.tiles[i][j].pl;
      msg_data.owner[i][j] = owner;
      msg_data.pop[i][j] = htons( st->grid.tiles[i][j].units[owner][citizen] );
      msg_data.flag[i][j] = 0;
      for (p=0; p<8; ++p){
        if (st->fg[p].flag[i][j])
          msg_data.flag[i][j] |= (1<<p);
      }
    }
  }
  buf[0] = 10;
  int size = sizeof(msg_data);
  memcpy(buf+1, &msg_data, size);
  int n_to_send = size+1;
  unsigned int peer_addr_len;
  for (i=0; i<cl_num; ++i) {
    peer_addr_len = sizeof (cl[i].sa);
    buf[1] = cl[i].pl;
    sendto(sfd, buf, n_to_send, 0, (struct sockaddr *) &cl[i].sa, peer_addr_len);
  }
}

variable_types: sfd int

variable_types: struct client_record { int pl; int id; char *name; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } sa; } []

variable_types: p int

variable_types: i int

variable_types: j int

variable_types: owner int

variable_types: size int

user_defined_types: struct msg_s_data { unsigned char control; unsigned char pause_request; unsigned int gold[8]; unsigned int time; unsigned char width; unsigned char height; unsigned char flag[40][29]; unsigned char owner[40][29]; unsigned short pop[40][29]; unsigned char tile[40][29]; }

user_defined_types: struct client_record { int pl; int id; char *name; struct sockaddr_storage sa; }

user_defined_types: enum config_speed { sp_pause=0, sp_slowest=1, sp_slower=2, sp_slow=3, sp_normal=4, sp_fast=5, sp_faster=6, sp_fastest=7 }

user_defined_types: enum config_dif { dif_easiest=0, dif_easy=1, dif_normal=2, dif_hard=3, dif_hardest=4 }

user_defined_types: struct flag_grid { int width; int height; int flag[40][29]; int call[40][29]; }

user_defined_types: enum strategy { none=0, aggr_greedy=1, one_greedy=2, persistent_greedy=3, opportunist=4, noble=5, midas=6 }

user_defined_types: enum tile_class { abyss=0, mountain=1, mine=2, grassland=3, village=4, town=5, castle=6 }


decompiled_code:
__int64 __fastcall process_msg_c(__int64 a1, unsigned int a2, char a3, unsigned __int8 *a4)
{
__int64 result; // rax

switch ( a3 )
{
case 20:
result = build(a1, a1 + 8LL * (int)a2 + 160800, a2, *a4, a4[1]);
break;
case 21:
result = add_flag(a1, a1 + 9288LL * (int)a2 + 46408, *a4, a4[1], 8LL);
break;
case 22:
result = remove_flag(a1, a1 + 9288LL * (int)a2 + 46408, *a4, a4[1], 8LL);
break;
case 23:
result = remove_flags_with_prob(a1, a1 + 9288LL * (int)a2 + 46408, 1.0);
break;
case 24:
result = remove_flags_with_prob(a1, a1 + 9288LL * (int)a2 + 46408, 0.5);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, char a3, unsigned __int8 *a4)
{
__int64 result; // rax

switch ( a3 )
{
case 20:
result = build(a1, a1 + 8LL * (int)a2 + 160800, a2, *a4, a4[1]);
break;
case 21:
result = add_flag(a1, a1 + 9288LL * (int)a2 + 46408, *a4, a4[1], 8LL);
break;
case 22:
result = remove_flag(a1, a1 + 9288LL * (int)a2 + 46408, *a4, a4[1], 8LL);
break;
case 23:
result = remove_flags_with_prob(a1, a1 + 9288LL * (int)a2 + 46408, 1.0);
break;
case 24:
result = remove_flags_with_prob(a1, a1 + 9288LL * (int)a2 + 46408, 0.5);
break;
default:
return result;
}
return result;
}

original_code:
void process_msg_c (struct state *st, int pl, uint8_t msg, struct msg_c_data *cm) {
  switch (msg) {
    case 20:
      build (&st->grid, &st->country[pl], pl, cm->i, cm->j);
      break;
    case 21:
      add_flag (&st->grid, &st->fg[pl], cm->i, cm->j, 8);
      break;
    case 22:
      remove_flag (&st->grid, &st->fg[pl], cm->i, cm->j, 8);
      break;
    case 23:
      remove_flags_with_prob (&st->grid, &st->fg[pl], 1.0);
      break;
    case 24:
      remove_flags_with_prob (&st->grid, &st->fg[pl], 0.5);
      break;
    case 30:
      break;
    case 40:
    case 41:
    default:
      break;
  }
}

canonical_original_code:
void process_msg_c(struct state *st, int pl, unsigned char msg, struct msg_c_data *cm) {
  switch (msg) {
    case 20:
      build (&st->grid, &st->country[pl], pl, cm->i, cm->j);
      break;
    case 21:
      add_flag (&st->grid, &st->fg[pl], cm->i, cm->j, 8);
      break;
    case 22:
      remove_flag (&st->grid, &st->fg[pl], cm->i, cm->j, 8);
      break;
    case 23:
      remove_flags_with_prob (&st->grid, &st->fg[pl], 1.0);
      break;
    case 24:
      remove_flags_with_prob (&st->grid, &st->fg[pl], 0.5);
      break;
    case 30:
      break;
    case 40:
    case 41:
    default:
      break;
  }
}

variable_types: pl int

variable_types:
msg
unsigned char

variable_types: struct msg_c_data { unsigned char i; unsigned char j; unsigned char info; } *


decompiled_code:
__int64 __fastcall server_process_msg_c(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // ebx

if ( a2 <= 3 )
return (unsigned int)-1;
LOBYTE(v4) = *(_BYTE *)a1;
msg_data_0 = *(_WORD *)(a1 + 1);
byte_3A2 = *(_BYTE *)(a1 + 3);
v4 = (unsigned __int8)v4;
process_msg_c(a3, a4, v4, (unsigned __int8 *)&msg_data_0);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // ebx

if ( a2 <= 3 )
return (unsigned int)-1;
LOBYTE(v4) = *(_BYTE *)a1;
msg_data_0 = *(_WORD *)(a1 + 1);
byte_3A2 = *(_BYTE *)(a1 + 3);
v4 = (unsigned __int8)v4;
func3(a3, a4, v4, (unsigned __int8 *)&msg_data_0);
return v4;
}

original_code:
int server_process_msg_c (uint8_t buf[50000], int nread, struct state *st, int pl) {
  uint8_t msg;
  static struct msg_c_data msg_data;
  if (nread >= 1 + sizeof(struct msg_c_data)) {
    msg = buf[0];
    memcpy(&msg_data, buf+1, sizeof(struct msg_c_data));
    process_msg_c(st, pl, msg, &msg_data);
  }
  else {return -1;}
  return msg;
}

canonical_original_code:
int server_process_msg_c(unsigned char buf[50000], int nread, struct state *st, int pl) {
  unsigned char msg;
  static struct msg_c_data msg_data;
  if (nread >= 1 + sizeof(struct msg_c_data)) {
    msg = buf[0];
    memcpy(&msg_data, buf+1, sizeof(struct msg_c_data));
    process_msg_c(st, pl, msg, &msg_data);
  }
  else {return -1;}
  return msg;
}

variable_types:
buf
unsigned char [50000]

variable_types: nread int

variable_types: struct msg_c_data { unsigned char i; unsigned char j; unsigned char info; }


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

result = 0LL;
if ( a2 > 0 )
result = *a1;
return result;
}

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

result = 0LL;
if ( a2 > 0 )
result = *a1;
return result;
}

original_code:
int server_get_msg (uint8_t buf[50000], int nread) {
  if (nread>=1) return buf[0]; else return 0;
}

canonical_original_code:
int server_get_msg(unsigned char buf[50000], int nread) {
  if (nread>=1) return buf[0]; else return 0;
}


decompiled_code:
__int64 __fastcall get_in_port(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 2);
}

original_code:
in_port_t get_in_port(struct sockaddr *sa) {
  if (sa->sa_family == 2) {
    return (((struct sockaddr_in*)sa)->sin_port);
  }
  return (((struct sockaddr_in6*)sa)->sin6_port);
}

canonical_original_code:
unsigned short get_in_port(struct sockaddr *sa) {
  if (sa->sa_family == 2) {
    return (((struct sockaddr_in *)sa)->sin_port);
  }
  return (((struct sockaddr_in6 *)sa)->sin6_port);
}

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

return_type: unsigned short

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


canonical_original_code:
int eq_6_addr(unsigned char s1[16], unsigned char s2[16]) {
  int i;
  for(i=0; i<16; ++i) {
    if (s1[i] != s2[i]) return 0;
  }
  return 1;
}


decompiled_code:
__int64 __fastcall sa_match(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int16 v3; // bx

if ( *(_WORD *)a1 == 2 )
{
result = 0LL;
if ( *(_WORD *)a2 == 2 )
{
if ( *(_DWORD *)(a1 + 4) != *(_DWORD *)(a2 + 4) )
return 0LL;
goto LABEL_9;
}
}
else
{
result = 0LL;
if ( *(_WORD *)a1 == 10 && *(_WORD *)a2 == 10 )
{
result = eq_6_addr(a1 + 8, a2 + 8);
if ( (_DWORD)result )
{
LABEL_9:
v3 = get_in_port(a1);
return v3 == (__int16)get_in_port(a2);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int16 v3; // bx

if ( *(_WORD *)a1 == 2 )
{
result = 0LL;
if ( *(_WORD *)a2 == 2 )
{
if ( *(_DWORD *)(a1 + 4) != *(_DWORD *)(a2 + 4) )
return 0LL;
goto LABEL_9;
}
}
else
{
result = 0LL;
if ( *(_WORD *)a1 == 10 && *(_WORD *)a2 == 10 )
{
result = func1(a1 + 8, a2 + 8);
if ( (_DWORD)result )
{
LABEL_9:
v3 = func0(a1);
return v3 == (__int16)func0(a2);
}
}
}
return result;
}

original_code:
int sa_match (struct sockaddr_storage *sa1, struct sockaddr_storage *sa2) {
  struct sockaddr *s1 = (struct sockaddr*) sa1;
  struct sockaddr *s2 = (struct sockaddr*) sa2;
  return (
      ( s1->sa_family == 2 && s2->sa_family == 2 &&
        ((struct sockaddr_in*)s1)->sin_addr.s_addr == ((struct sockaddr_in*)s2)->sin_addr.s_addr )
      ||
      ( s1->sa_family == 10 && s2->sa_family == 10 &&
        eq_6_addr (
          ((struct sockaddr_in6*)s1)->sin6_addr.__in6_u.__u6_addr8,
          ((struct sockaddr_in6*)s2)->sin6_addr.__in6_u.__u6_addr8 ) )
    )
    &&
    ( get_in_port(s1) == get_in_port(s2) );
}

canonical_original_code:
int sa_match(struct sockaddr_storage *sa1, struct sockaddr_storage *sa2) {
  struct sockaddr *s1 = (struct sockaddr*) sa1;
  struct sockaddr *s2 = (struct sockaddr*) sa2;
  return (
      ( s1->sa_family == 2 && s2->sa_family == 2 &&
        ((struct sockaddr_in *)s1)->sin_addr.s_addr == ((struct sockaddr_in *)s2)->sin_addr.s_addr )
      ||
      ( s1->sa_family == 10 && s2->sa_family == 10 &&
        eq_6_addr (
          ((struct sockaddr_in6 *)s1)->sin6_addr.__in6_u.__u6_addr8,
          ((struct sockaddr_in6 *)s2)->sin6_addr.__in6_u.__u6_addr8 ) )
    )
    &&
    ( get_in_port(s1) == get_in_port(s2) );
}

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


decompiled_code:
__int64 __fastcall server_init(int *a1, const char *a2)
{
int v2; // eax
struct addrinfo *i; // rbx
unsigned int v4; // ebp
const char *v5; // rax
int v6; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(0LL, a2, &req, &pai);
if ( v2 )
{
v5 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v5);
v4 = -1;
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v6 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
*a1 = v6;
if ( v6 != -1 )
{
v4 = bind(v6, i->ai_addr, i->ai_addrlen);
if ( !v4 )
{
freeaddrinfo(pai);
return v4;
}
close(*a1);
}
}
fwrite("Could not bind\n", 1uLL, 0xFuLL, stderr);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, const char *a2)
{
int v2; // eax
struct addrinfo *i; // rbx
unsigned int v4; // ebp
const char *v5; // rax
int v6; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(0LL, a2, &req, &pai);
if ( v2 )
{
v5 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v5);
v4 = -1;
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v6 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
*a1 = v6;
if ( v6 != -1 )
{
v4 = bind(v6, i->ai_addr, i->ai_addrlen);
if ( !v4 )
{
freeaddrinfo(pai);
return v4;
}
close(*a1);
}
}
fwrite("Could not bind\n", 1uLL, 0xFuLL, stderr);
v4 = -1;
}
return v4;
}

original_code:
int server_init (int *p_sfd, char*str_port) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int s;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  hints.ai_protocol = 0;
  hints.ai_canonname = ((void *)0);
  hints.ai_addr = ((void *)0);
  hints.ai_next = ((void *)0);
  s = getaddrinfo(((void *)0), str_port, &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    return -1;
  }
  for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
    *p_sfd = socket(rp->ai_family, rp->ai_socktype,
    rp->ai_protocol);
    if (*p_sfd == -1)
      continue;
    if (bind(*p_sfd, rp->ai_addr, rp->ai_addrlen) == 0)
    break;
    close(*p_sfd);
  }
  if (rp == ((void *)0)) {
    fprintf(stderr, "Could not bind\n");
    return -1;
  }
  freeaddrinfo(result);
  return 0;
}

canonical_original_code:
int server_init(int *p_sfd, char *str_port) {
  struct addrinfo hints;
  struct addrinfo *result; struct addrinfo *rp;
  int s;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  hints.ai_protocol = 0;
  hints.ai_canonname = ((void *)0);
  hints.ai_addr = ((void *)0);
  hints.ai_next = ((void *)0);
  s = getaddrinfo(((void *)0), str_port, &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    return -1;
  }
  for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
    *p_sfd = socket(rp->ai_family, rp->ai_socktype,
    rp->ai_protocol);
    if (*p_sfd == -1)
      continue;
    if (bind(*p_sfd, rp->ai_addr, rp->ai_addrlen) == 0)
    break;
    close(*p_sfd);
  }
  if (rp == ((void *)0)) {
    fprintf(stderr, "Could not bind\n");
    return -1;
  }
  freeaddrinfo(result);
  return 0;
}

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

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; }


decompiled_code:
int __fastcall client_init_session(int *a1, const char *a2, __m128i *a3, const char *a4, const char *a5)
{
int result; // eax
struct addrinfo *v9; // rbx
const char *v10; // rax
int v11; // eax
const __m128i *v12; // rdx
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
result = getaddrinfo(0LL, a2, &req, &pai);
if ( result )
goto LABEL_4;
v9 = pai;
if ( !pai )
{
LABEL_3:
fwrite("Could not bind\n", 1uLL, 0xFuLL, stderr);
return -1;
}
while ( 1 )
{
v11 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*a1 = v11;
if ( v11 != -1 )
break;
LABEL_5:
v9 = v9->ai_next;
if ( !v9 )
goto LABEL_3;
}
if ( bind(v11, v9->ai_addr, v9->ai_addrlen) )
{
close(*a1);
goto LABEL_5;
}
freeaddrinfo(pai);
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
result = getaddrinfo(a4, a5, &req, &pai);
if ( result )
{
LABEL_4:
v10 = gai_strerror(result);
fprintf(stderr, "getaddrinfo: %s\n", v10);
return -1;
}
v12 = (const __m128i *)pai;
if ( pai )
{
*a3 = _mm_loadu_si128((const __m128i *)pai);
a3[1] = _mm_loadu_si128(v12 + 1);
a3[2] = _mm_loadu_si128(v12 + 2);
}
else
{
fwrite("Could not connect\n", 1uLL, 0x12uLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int *a1, const char *a2, __m128i *a3, const char *a4, const char *a5)
{
int result; // eax
struct addrinfo *v9; // rbx
const char *v10; // rax
int v11; // eax
const __m128i *v12; // rdx
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
result = getaddrinfo(0LL, a2, &req, &pai);
if ( result )
goto LABEL_4;
v9 = pai;
if ( !pai )
{
LABEL_3:
fwrite("Could not bind\n", 1uLL, 0xFuLL, stderr);
return -1;
}
while ( 1 )
{
v11 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*a1 = v11;
if ( v11 != -1 )
break;
LABEL_5:
v9 = v9->ai_next;
if ( !v9 )
goto LABEL_3;
}
if ( bind(v11, v9->ai_addr, v9->ai_addrlen) )
{
close(*a1);
goto LABEL_5;
}
freeaddrinfo(pai);
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
result = getaddrinfo(a4, a5, &req, &pai);
if ( result )
{
LABEL_4:
v10 = gai_strerror(result);
fprintf(stderr, "getaddrinfo: %s\n", v10);
return -1;
}
v12 = (const __m128i *)pai;
if ( pai )
{
*a3 = _mm_loadu_si128((const __m128i *)pai);
a3[1] = _mm_loadu_si128(v12 + 1);
a3[2] = _mm_loadu_si128(v12 + 2);
}
else
{
fwrite("Could not connect\n", 1uLL, 0x12uLL, stderr);
result = -1;
}
return result;
}

original_code:
int client_init_session (int *p_sfd, char* str_my_port, struct addrinfo *srv, char *str_server_addr, char *str_server_port) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int s;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  hints.ai_protocol = 0;
  hints.ai_canonname = ((void *)0);
  hints.ai_addr = ((void *)0);
  hints.ai_next = ((void *)0);
  s = getaddrinfo(((void *)0), str_my_port, &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    return -1;
  }
  for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
    *p_sfd = socket(rp->ai_family, rp->ai_socktype,
    rp->ai_protocol);
    if (*p_sfd == -1)
      continue;
    if (bind(*p_sfd, rp->ai_addr, rp->ai_addrlen) == 0)
    break;
    close(*p_sfd);
  }
  if (rp == ((void *)0)) {
    fprintf(stderr, "Could not bind\n");
    return -1;
  }
  freeaddrinfo(result);
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  s = getaddrinfo(str_server_addr, str_server_port, &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    return -1;
  }
  rp = result;
  if (rp == ((void *)0)) {
    fprintf(stderr, "Could not connect\n");
    return -1;
  }
  *srv = *rp;
  return 0;
}

canonical_original_code:
int client_init_session(int *p_sfd, char *str_my_port, struct addrinfo *srv, char *str_server_addr, char *str_server_port) {
  struct addrinfo hints;
  struct addrinfo *result; struct addrinfo *rp;
  int s;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0x0001;
  hints.ai_protocol = 0;
  hints.ai_canonname = ((void *)0);
  hints.ai_addr = ((void *)0);
  hints.ai_next = ((void *)0);
  s = getaddrinfo(((void *)0), str_my_port, &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    return -1;
  }
  for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
    *p_sfd = socket(rp->ai_family, rp->ai_socktype,
    rp->ai_protocol);
    if (*p_sfd == -1)
      continue;
    if (bind(*p_sfd, rp->ai_addr, rp->ai_addrlen) == 0)
    break;
    close(*p_sfd);
  }
  if (rp == ((void *)0)) {
    fprintf(stderr, "Could not bind\n");
    return -1;
  }
  freeaddrinfo(result);
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  s = getaddrinfo(str_server_addr, str_server_port, &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    return -1;
  }
  rp = result;
  if (rp == ((void *)0)) {
    fprintf(stderr, "Could not connect\n");
    return -1;
  }
  *srv = *rp;
  return 0;
}

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; }


decompiled_code:
__int64 __fastcall find_node(int a1)
{
__int64 v1; // rdx
__int64 result; // rax

if ( total <= 0 )
return 0LL;
v1 = 0LL;
while ( 1 )
{
result = list[v1];
if ( result )
break;
LABEL_3:
if ( total == ++v1 )
return 0LL;
}
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
goto LABEL_3;
}
return result;
}

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

if ( total <= 0 )
return 0LL;
v1 = 0LL;
while ( 1 )
{
result = list[v1];
if ( result )
break;
LABEL_3:
if ( total == ++v1 )
return 0LL;
}
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
goto LABEL_3;
}
return result;
}

original_code:
Blocks *find_node(int block_num){
    int temp , check = 0;
    Blocks *ptr = ((void *)0);
    for(temp = 0 ; temp < total ; temp++){
        ptr = list[temp];
        while(ptr != ((void *)0)){
            if(ptr->num == block_num){
                check = 1;
                break;
            }else{
                ptr = ptr->next;
            }
        }
        if(check == 1){
            break;
        }
    }
    return ptr;
}

canonical_original_code:
struct Block_struct *find_node(int block_num){
    int temp; int check = 0;
    struct Block_struct *ptr = ((void *)0);
    for(temp = 0 ; temp < total ; temp++){
        ptr = list[temp];
        while(ptr != ((void *)0)){
            if(ptr->num == block_num){
                check = 1;
                break;
            }else{
                ptr = ptr->next;
            }
        }
        if(check == 1){
            break;
        }
    }
    return ptr;
}

variable_types: temp int

variable_types: check int

variable_types: struct Block_struct { int num; int cur_addr; struct Block_struct *next; struct Block_struct *before; } *


move

decompiled_code:
__int64 __fastcall move(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = list[a2];
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
*(_QWORD *)(v3 + 8) = a1;
result = *(_QWORD *)(a1 + 16);
if ( result )
{
*(_QWORD *)(result + 8) = 0LL;
}
else
{
result = *(int *)(a1 + 4);
list[result] = 0LL;
}
*(_QWORD *)(a1 + 16) = v3;
}
else
{
list[a2] = a1;
result = *(_QWORD *)(a1 + 16);
if ( result )
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
do
{
*(_DWORD *)(a1 + 4) = a2;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = list[a2];
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
*(_QWORD *)(v3 + 8) = a1;
result = *(_QWORD *)(a1 + 16);
if ( result )
{
*(_QWORD *)(result + 8) = 0LL;
}
else
{
result = *(int *)(a1 + 4);
list[result] = 0LL;
}
*(_QWORD *)(a1 + 16) = v3;
}
else
{
list[a2] = a1;
result = *(_QWORD *)(a1 + 16);
if ( result )
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
do
{
*(_DWORD *)(a1 + 4) = a2;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
void move(Blocks *node , int addr_num){
    Blocks *ptr = list[addr_num];
    if(ptr != ((void *)0)){
        while(ptr->next != ((void *)0)){
            ptr = ptr->next;
        }
        ptr->next = node;
        if(node->before != ((void *)0)){
            node->before->next = ((void *)0);
        }else{
            list[node->cur_addr] = ((void *)0);
        }
        node->before = ptr;
    }else{
        list[addr_num] = node;
        if(node->before != ((void *)0)){
            node->before->next = ((void *)0);
        }
        node->before = ((void *)0);
    }
    while(node != ((void *)0)){
        node->cur_addr = addr_num;
        node = node->next;
    }
}

canonical_original_code:
void move(struct Block_struct *node, int addr_num){
    struct Block_struct *ptr = list[addr_num];
    if(ptr != ((void *)0)){
        while(ptr->next != ((void *)0)){
            ptr = ptr->next;
        }
        ptr->next = node;
        if(node->before != ((void *)0)){
            node->before->next = ((void *)0);
        }else{
            list[node->cur_addr] = ((void *)0);
        }
        node->before = ptr;
    }else{
        list[addr_num] = node;
        if(node->before != ((void *)0)){
            node->before->next = ((void *)0);
        }
        node->before = ((void *)0);
    }
    while(node != ((void *)0)){
        node->cur_addr = addr_num;
        node = node->next;
    }
}

user_defined_types: struct Block_struct { int num; int cur_addr; struct Block_struct *next; struct Block_struct *before; }


rollback

decompiled_code:
__int64 __fastcall rollback(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 8) )
{
if ( *(_DWORD *)i != *(_DWORD *)(i + 4) )
result = move(i, *(_DWORD *)i);
}
return result;
}

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

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 8) )
{
if ( *(_DWORD *)i != *(_DWORD *)(i + 4) )
result = func8(i, *(_DWORD *)i);
}
return result;
}

original_code:
void rollback(Blocks *node){
    Blocks *ptr = node->next;
    while(ptr != ((void *)0)){
        if(ptr->num != ptr->cur_addr){
            move(ptr , ptr->num);
        }
        ptr = ptr->next;
    }
}

canonical_original_code:
void rollback(struct Block_struct *node){
    struct Block_struct *ptr = node->next;
    while(ptr != ((void *)0)){
        if(ptr->num != ptr->cur_addr){
            move(ptr , ptr->num);
        }
        ptr = ptr->next;
    }
}


original_code:
void init_list(){
    int i = 0 ;
    for(i = 0 ; i < total ; i++){
        Blocks *block = (Blocks *)malloc(sizeof(Blocks));
        block->num = i;
        block->cur_addr = i;
        block->next = ((void *)0);
        block->before = ((void *)0);
        list[i] = block;
    }
}

canonical_original_code:
void init_list(){
    int i = 0;
    for(i = 0 ; i < total ; i++){
        struct Block_struct *block = (Blocks *)malloc(sizeof(Blocks));
        block->num = i;
        block->cur_addr = i;
        block->next = ((void *)0);
        block->before = ((void *)0);
        list[i] = block;
    }
}

variable_types: i int


display

decompiled_code:
int display()
{
__int64 v0; // rbp
unsigned int *i; // rbx
int result; // eax

if ( total > 0 )
{
v0 = 0LL;
do
{
printf("%d:", (unsigned int)v0);
for ( i = (unsigned int *)list[v0]; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf(" %d", *i);
result = putchar(10);
++v0;
}
while ( total > (int)v0 );
}
return result;
}

canonical_decompiled_code:
int func11()
{
__int64 v0; // rbp
unsigned int *i; // rbx
int result; // eax

if ( total > 0 )
{
v0 = 0LL;
do
{
printf("%d:", (unsigned int)v0);
for ( i = (unsigned int *)list[v0]; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf(" %d", *i);
result = putchar(10);
++v0;
}
while ( total > (int)v0 );
}
return result;
}

original_code:
void display(){
    int temp , i;
    Blocks *ptr = ((void *)0);
    for(i = 0 ; i <total ; i++){
        printf("%d:" , i);
        ptr = list[i];
        while(ptr != ((void *)0)){
            printf(" %d" , ptr->num);
            ptr = ptr->next;
        }
        printf("\n");
    }
}

canonical_original_code:
void display(){
    int temp; int i;
    struct Block_struct *ptr = ((void *)0);
    for(i = 0 ; i <total ; i++){
        printf("%d:" , i);
        ptr = list[i];
        while(ptr != ((void *)0)){
            printf(" %d" , ptr->num);
            ptr = ptr->next;
        }
        printf("\n");
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
__int64 v5; // rbp
__int64 v6; // rbx
int v7; // eax
int v9; // [rsp+Ch] [rbp-2Ch] BYREF
int v10; // [rsp+10h] [rbp-28h] BYREF
char v11; // [rsp+16h] [rbp-22h] BYREF
char v12; // [rsp+17h] [rbp-21h]
char v13[29]; // [rsp+1Bh] [rbp-1Dh] BYREF

while ( scanf("%d", &total) == 1 && (unsigned int)total > 0x18 )
;
init_list();
while ( scanf("%s", v13) == 1 && v13[0] != 113 )
{
scanf("%d %s %d", &v10, &v11, &v9);
v3 = v9;
if ( v10 != v9 )
{
v4 = v9;
if ( v10 <= v9 )
v4 = v10;
if ( total >= v4 )
{
v5 = find_node(v10);
v6 = find_node(v3);
if ( *(_DWORD *)(v5 + 4) != *(_DWORD *)(v6 + 4) )
{
v7 = 10;
if ( v13[0] != 109 )
v7 = 20;
if ( v12 == 110 )
{
if ( v7 != 20 )
rollback(v5);
rollback(v6);
}
else if ( v7 == 10 )
{
rollback(v5);
}
move(v5, *(_DWORD *)(v6 + 4));
}
}
}
}
display();
return 0;
}

original_code:
int main(){
    while(scanf("%d" , &total) == 1){
        if((total >= 0) && (total < 25)){
            break;
        }
    }
    init_list();
    char act[5] , kind[5];
    int a , b , cmd;
    while(scanf("%s" , act) == 1){
        if(act[0] == 'q'){
            break;
        }else{
            scanf("%d %s %d" , &a , kind , &b);
            if((a == b ) || ((a > total) && (b > total))){
                continue;
            }
            Blocks *a_block = find_node(a);
            Blocks *b_block = find_node(b);
            if(a_block->cur_addr == b_block->cur_addr){
                continue;
            }
            if(act[0] == 'm'){
                cmd = 10;
            }else{
                cmd = 20;
            }
            if(kind[1] == 'n'){
                cmd += 1;
            }else{
                cmd += 2;
            }
            switch(cmd){
                case 11:
                    rollback(a_block);
                    rollback(b_block);
                    break;
                case 12:
                    rollback(a_block);
                    break;
                case 21:
                    rollback(b_block);
                    break;
                case 22:
                    break;
            }
            move(a_block , b_block->cur_addr);
        }
    }
    display();
    return 0;
}

canonical_original_code:
int main(){
    while(scanf("%d" , &total) == 1){
        if((total >= 0) && (total < 25)){
            break;
        }
    }
    init_list();
    char act[5]; char kind[5];
    int a; int b; int cmd;
    while(scanf("%s" , act) == 1){
        if(act[0] == 'q'){
            break;
        }else{
            scanf("%d %s %d" , &a , kind , &b);
            if((a == b ) || ((a > total) && (b > total))){
                continue;
            }
            struct Block_struct *a_block = find_node(a);
            struct Block_struct *b_block = find_node(b);
            if(a_block->cur_addr == b_block->cur_addr){
                continue;
            }
            if(act[0] == 'm'){
                cmd = 10;
            }else{
                cmd = 20;
            }
            if(kind[1] == 'n'){
                cmd += 1;
            }else{
                cmd += 2;
            }
            switch(cmd){
                case 11:
                    rollback(a_block);
                    rollback(b_block);
                    break;
                case 12:
                    rollback(a_block);
                    break;
                case 21:
                    rollback(b_block);
                    break;
                case 22:
                    break;
            }
            move(a_block , b_block->cur_addr);
        }
    }
    display();
    return 0;
}

variable_types:
act
char [5]

variable_types:
kind
char [5]

variable_types: a int

variable_types: b int

variable_types: cmd int


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

if ( a1 == 1 )
return 1LL;
LODWORD(result) = 1;
do
{
if ( (a1 & 1) != 0 )
a1 = 3 * a1 + 1;
else
a1 /= 2;
result = (unsigned int)(result + 1);
}
while ( a1 != 1 );
return result;
}

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

if ( a1 == 1 )
return 1LL;
LODWORD(result) = 1;
do
{
if ( (a1 & 1) != 0 )
a1 = 3 * a1 + 1;
else
a1 /= 2;
result = (unsigned int)(result + 1);
}
while ( a1 != 1 );
return result;
}

original_code:
int cycle_length(int num){
    int count = 1 ;
    while(num != 1){
        if(num % 2){
            num = (num * 3) + 1;
        }else{
            num = num / 2;
        }
        count += 1;
    }
    return count;
}

canonical_original_code:
int cycle_length(int num){
    int count = 1;
    while(num != 1){
        if(num % 2){
            num = (num * 3) + 1;
        }else{
            num = num / 2;
        }
        count += 1;
    }
    return count;
}

variable_types: num int

variable_types: count int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // er14
unsigned int v5; // er13
int v6; // ebx
int v7; // er12
int v8; // er12
int v9; // eax
int v11; // [rsp+8h] [rbp-30h] BYREF
int v12[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v12[0] = 0;
v11 = 0;
while ( scanf("%d %d", v12, &v11) == 2 )
{
v4 = v11;
v5 = v12[0];
v6 = v12[0];
if ( v11 <= v12[0] )
v6 = v11;
v7 = v12[0];
if ( v11 >= v12[0] )
v7 = v11;
if ( v6 > v7 )
{
v3 = 0;
}
else
{
v8 = v7 + 1;
v3 = 0;
do
{
v9 = cycle_length(v6);
if ( (int)v3 < v9 )
v3 = v9;
++v6;
}
while ( v8 != v6 );
}
printf("%d %d %d\n", v5, v4, v3);
}
return 0;
}

original_code:
int main(){
    int num1 = 0, num2 = 0 , i = 0 , bg = 0 , temp = 0;
    while(scanf("%d %d" , &num1 , &num2) == 2){
        bg = 0;
        for(i = (((num1) < (num2)) ? (num1) : (num2)) ; i <= (((num1) > (num2)) ? (num1) : (num2)) ; i++){
            temp = cycle_length(i);
            if(bg < temp){
                bg = temp;
            }
        }
        printf("%d %d %d\n" ,num1 , num2 , bg);
    }
    return 0;
}

canonical_original_code:
int main(){
    int num1 = 0; int num2 = 0; int i = 0; int bg = 0; int temp = 0;
    while(scanf("%d %d" , &num1 , &num2) == 2){
        bg = 0;
        for(i = (((num1) < (num2)) ? (num1) : (num2)) ; i <= (((num1) > (num2)) ? (num1) : (num2)) ; i++){
            temp = cycle_length(i);
            if(bg < temp){
                bg = temp;
            }
        }
        printf("%d %d %d\n" ,num1 , num2 , bg);
    }
    return 0;
}

variable_types: bg int


original_code:
double prior_prob (char state_i, char state_j) {
    return -1.3862943611198906;
}

canonical_original_code:
double prior_prob(char state_i, char state_j) {
    return -1.3862943611198906;
}

return_type: double


decompiled_code:
double __fastcall transition_prob(unsigned __int8 a1, unsigned __int8 a2)
{
double result; // xmm0_8

if ( !(a1 | a2) )
return *(double *)&transition_null_to_null;
if ( !a1 && a2 )
return *(double *)&transition_null_to_signal;
if ( !a2 && a1 )
return *(double *)&transition_signal_to_null;
if ( a1 == a2 && a1 )
return *(double *)&transition_signal_to_signal;
if ( a1 != a2 )
{
if ( a1 )
result = *(double *)&transition_signal_to_other_signal;
}
return result;
}

canonical_decompiled_code:
double __fastcall func8(unsigned __int8 a1, unsigned __int8 a2)
{
double result; // xmm0_8

if ( !(a1 | a2) )
return *(double *)&transition_null_to_null;
if ( !a1 && a2 )
return *(double *)&transition_null_to_signal;
if ( !a2 && a1 )
return *(double *)&transition_signal_to_null;
if ( a1 == a2 && a1 )
return *(double *)&transition_signal_to_signal;
if ( a1 != a2 )
{
if ( a1 )
result = *(double *)&transition_signal_to_other_signal;
}
return result;
}

original_code:
double transition_prob (char state_i, char state_j) {
    if (state_i == 0 && state_j == 0)
        return transition_null_to_null;
    else if (state_i == 0 && state_j != 0)
        return transition_null_to_signal;
    else if (state_i != 0 && state_j == 0)
        return transition_signal_to_null;
    else if (state_i != 0 && state_i == state_j)
        return transition_signal_to_signal;
    else if (state_i != 0 && state_i != state_j)
        return transition_signal_to_other_signal;
}

canonical_original_code:
double transition_prob(char state_i, char state_j) {
    if (state_i == 0 && state_j == 0)
        return transition_null_to_null;
    else if (state_i == 0 && state_j != 0)
        return transition_null_to_signal;
    else if (state_i != 0 && state_j == 0)
        return transition_signal_to_null;
    else if (state_i != 0 && state_i == state_j)
        return transition_signal_to_signal;
    else if (state_i != 0 && state_i != state_j)
        return transition_signal_to_other_signal;
}


decompiled_code:
double __fastcall emission_prob(char a1, char a2)
{
double result; // xmm0_8

if ( a1 == 88 && a2 == 88 )
return *(double *)&emission_null_to_null;
if ( a2 != 88 && a1 == 88 )
return *(double *)&emission_null_to_signal;
if ( a2 == 88 && a1 != 88 )
return *(double *)&emission_signal_to_null;
if ( a1 == a2 && a1 != 88 )
return *(double *)&emission_signal_to_signal;
if ( a1 != 88 )
result = *(double *)&emission_signal_to_other_signal;
return result;
}

canonical_decompiled_code:
double __fastcall func9(char a1, char a2)
{
double result; // xmm0_8

if ( a1 == 88 && a2 == 88 )
return *(double *)&emission_null_to_null;
if ( a2 != 88 && a1 == 88 )
return *(double *)&emission_null_to_signal;
if ( a2 == 88 && a1 != 88 )
return *(double *)&emission_signal_to_null;
if ( a1 == a2 && a1 != 88 )
return *(double *)&emission_signal_to_signal;
if ( a1 != 88 )
result = *(double *)&emission_signal_to_other_signal;
return result;
}

original_code:
double emission_prob (char observation, char state) {
    if (observation == 'X' && state == observation)
        return emission_null_to_null;
    if (observation == 'X' && state != 'X')
        return emission_null_to_signal;
    if (observation != 'X' && state == 'X')
        return emission_signal_to_null;
    if (observation != 'X' && state == observation)
        return emission_signal_to_signal;
    if (observation != 'X' && observation != 'X')
        return emission_signal_to_other_signal;
}

canonical_original_code:
double emission_prob(char observation, char state) {
    if (observation == 'X' && state == observation)
        return emission_null_to_null;
    if (observation == 'X' && state != 'X')
        return emission_null_to_signal;
    if (observation != 'X' && state == 'X')
        return emission_signal_to_null;
    if (observation != 'X' && state == observation)
        return emission_signal_to_signal;
    if (observation != 'X' && observation != 'X')
        return emission_signal_to_other_signal;
}

variable_types: observation char

variable_types: state char


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v5; // [rsp+8h] [rbp-10h] BYREF

v5 = 0LL;
if ( (unsigned int)(argc - 1) > 1 )
__assert_fail("argc == 2 || argc == 1", "main.c", 8u, "main");
if ( argc == 2 )
{
v5 = strtoull(argv[1], 0LL, 10);
}
else
{
while ( !(unsigned int)__isoc99_scanf() )
{
while ( getchar() != 10 )
;
puts("Bad Input\n");
}
}
if ( v5 <= 1 )
__assert_fail("temp >= 2", "main.c", 0x10u, "main");
printf("%llu=", v5);
while ( !(unsigned __int8)isprime(v5) )
{
prime(&v5, &v4);
printf("%llu*", v4);
}
printf("%llu\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v5; // [rsp+8h] [rbp-10h] BYREF

v5 = 0LL;
if ( (unsigned int)(argc - 1) > 1 )
__assert_fail("argc == 2 || argc == 1", "main.c", 8u, "main");
if ( argc == 2 )
{
v5 = strtoull(argv[1], 0LL, 10);
}
else
{
while ( !(unsigned int)__isoc99_scanf() )
{
while ( getchar() != 10 )
;
puts("Bad Input\n");
}
}
if ( v5 <= 1 )
__assert_fail("temp >= 2", "main.c", 0x10u, "main");
printf("%llu=", v5);
while ( !(unsigned __int8)func7(v5) )
{
func8(&v5, &v4);
printf("%llu*", v4);
}
printf("%llu\n", v5);
return 0;
}

original_code:
int main(int argc,char* argv[]){
 bigint temp=0,output;
 ((void) sizeof ((argc == 2 || argc == 1) ? 1 : 0), __extension__ ({ if (argc == 2 || argc == 1) ; else __assert_fail ("argc == 2 || argc == 1", "main.c", 8, __extension__ __PRETTY_FUNCTION__); }));
 if(argc == 2)
  temp=strtoull(argv[1],((void *)0),10);
 else
  while(!scanf("%llu",&temp)){
   while(getchar() != '\n');
   printf("Bad Input\n\n");
  }
 ((void) sizeof ((temp >= 2) ? 1 : 0), __extension__ ({ if (temp >= 2) ; else __assert_fail ("temp >= 2", "main.c", 16, __extension__ __PRETTY_FUNCTION__); }));
 printf("%llu=",temp);
 while(!isprime(temp)){
  prime(&temp,&output);
  printf("%llu*",output);
 }
 printf("%llu\n",temp);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 unsigned long long temp = 0; unsigned long long output;
 ((void) sizeof ((argc == 2 || argc == 1) ? 1 : 0), __extension__ ({ if (argc == 2 || argc == 1) ; else __assert_fail ("argc == 2 || argc == 1", "main.c", 8, __extension__ __PRETTY_FUNCTION__); }));
 if(argc == 2)
  temp=strtoull(argv[1],((void *)0),10);
 else
  while(!scanf("%llu",&temp)){
   while(getchar() != '\n');
   printf("Bad Input\n\n");
  }
 ((void) sizeof ((temp >= 2) ? 1 : 0), __extension__ ({ if (temp >= 2) ; else __assert_fail ("temp >= 2", "main.c", 16, __extension__ __PRETTY_FUNCTION__); }));
 printf("%llu=",temp);
 while(!isprime(temp)){
  prime(&temp,&output);
  printf("%llu*",output);
 }
 printf("%llu\n",temp);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
temp
unsigned long long

variable_types:
output
unsigned long long


repo: aHelmutSieber/test

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
myPrintHelloMake(argc, argv, envp);
return 0;
}

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

original_code:
int main(int argc, char *argv[])
{
 myPrintHelloMake();
 return 0;
}


myPrintHelloMake

decompiled_code:
int myPrintHelloMake()
{
puts("[Info] Testing Jenkins");
return puts("[Info] binary ok!");
}

canonical_decompiled_code:
int func7()
{
puts("[Info] Testing Jenkins");
return puts("[Info] binary ok!");
}

original_code:
void myPrintHelloMake(void) {
  printf("[Info] Testing Jenkins\n");
  printf("[Info] binary ok!\n");
  return;
}

canonical_original_code:
void myPrintHelloMake() {
  printf("[Info] Testing Jenkins\n");
  printf("[Info] binary ok!\n");
  return;
}


InitIDTDescriptor

repo: aaSSfxxx/MIAOS

decompiled_code:
void __fastcall InitIDTDescriptor(unsigned __int8 a1, int a2, __int16 a3, char a4)
{
kidt[4 * a1] = a2;
kidt[4 * a1 + 3] = HIWORD(a2);
kidt[4 * a1 + 1] = a3;
HIBYTE(kidt[4 * a1 + 2]) = a4;
LOBYTE(kidt[4 * a1 + 2]) = 0;
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int8 a1, int a2, __int16 a3, char a4)
{
kidt[4 * a1] = a2;
kidt[4 * a1 + 3] = HIWORD(a2);
kidt[4 * a1 + 1] = a3;
HIBYTE(kidt[4 * a1 + 2]) = a4;
LOBYTE(kidt[4 * a1 + 2]) = 0;
}

original_code:
void InitIDTDescriptor (BYTE index,
                        DWORD dwBase,
                        WORD wSelector,
                        BYTE bFlags)
{
    kidt[index].BaseLower = (dwBase & 0xFFFF);
    kidt[index].BaseHigher = (dwBase >> 16) & 0xFFFF;
    kidt[index].Selector = wSelector;
    kidt[index].Flags = bFlags;
    kidt[index].Reserved = 0;
}

canonical_original_code:
void InitIDTDescriptor(unsigned char index, unsigned int dwBase, unsigned short wSelector, unsigned char bFlags)
{
    kidt[index].BaseLower = (dwBase & 0xFFFF);
    kidt[index].BaseHigher = (dwBase >> 16) & 0xFFFF;
    kidt[index].Selector = wSelector;
    kidt[index].Flags = bFlags;
    kidt[index].Reserved = 0;
}

variable_types:
index
unsigned char

variable_types:
dwBase
unsigned int

variable_types:
wSelector
unsigned short

variable_types:
bFlags
unsigned char


LoadIDT

decompiled_code:
void LoadIDT()
{
int i; // ebx

for ( i = 0; i != 32; ++i )
InitIDTDescriptor(i, (int)&default_isr, 8, 142);
InitIDTDescriptor(8u, (int)&isr8, 8, 142);
InitIDTDescriptor(0xAu, (int)&isr10, 8, 142);
InitIDTDescriptor(0xBu, (int)&isr11, 8, 142);
InitIDTDescriptor(0xCu, (int)&isr12, 8, 142);
InitIDTDescriptor(0xDu, (int)&isr13, 8, 142);
InitIDTDescriptor(0xEu, (int)&isr14, 8, 142);
*(_WORD *)kidtr = 2047;
*(_DWORD *)&kidtr[2] = (_DWORD)kidt;
__lidt(kidtr);
InitIDTDescriptor(0x20u, (int)&isr32, 8, 142);
InitIDTDescriptor(0x80u, (int)&isr0x80, 8, 142);
__asm { int 80h; LINUX - }
}

original_code:
void LoadIDT (void)
{
    int i;
    for(i=0; i<32; i++) {
      InitIDTDescriptor(i, (DWORD)default_isr, 0x08, 0x8E);
    }
    InitIDTDescriptor( 8, (DWORD)isr8 , 0x08, 0x8E);
    InitIDTDescriptor( 10, (DWORD)isr10 , 0x08, 0x8E);
    InitIDTDescriptor( 11, (DWORD)isr11 , 0x08, 0x8E);
    InitIDTDescriptor( 12, (DWORD)isr12 , 0x08, 0x8E);
    InitIDTDescriptor( 13, (DWORD)isr13 , 0x08, 0x8E);
    InitIDTDescriptor( 14, (DWORD)isr14 , 0x08, 0x8E);
    kidtr.Limit = sizeof(IDT_DESCRIPTOR) * 256 -1;
    kidtr.Base = (DWORD)kidt;
    asm ("lidt (kidtr)");
 InitIDTDescriptor( 32, (DWORD)isr32 , 0x08, 0x8E);
    InitIDTDescriptor( 0x80, (DWORD)isr0x80 , 0x08, 0x8E);
 asm ("int $0x80");
}

canonical_original_code:
void LoadIDT()
{
    int i;
    for(i=0; i<32; i++) {
      InitIDTDescriptor(i, (unsigned int)default_isr, 0x08, 0x8E);
    }
    InitIDTDescriptor( 8, (unsigned int)isr8 , 0x08, 0x8E);
    InitIDTDescriptor( 10, (unsigned int)isr10 , 0x08, 0x8E);
    InitIDTDescriptor( 11, (unsigned int)isr11 , 0x08, 0x8E);
    InitIDTDescriptor( 12, (unsigned int)isr12 , 0x08, 0x8E);
    InitIDTDescriptor( 13, (unsigned int)isr13 , 0x08, 0x8E);
    InitIDTDescriptor( 14, (unsigned int)isr14 , 0x08, 0x8E);
    kidtr.Limit = sizeof(IDT_DESCRIPTOR) * 256 -1;
    kidtr.Base = (unsigned int)kidt;
    asm ("lidt (kidtr)");
 InitIDTDescriptor( 32, (unsigned int)isr32 , 0x08, 0x8E);
    InitIDTDescriptor( 0x80, (unsigned int)isr0x80 , 0x08, 0x8E);
 asm ("int $0x80");
}

variable_types: i int


UserInterrupt

decompiled_code:
__int64 __fastcall UserInterrupt(__int64 a1)
{
return printk("Interrupt %d called \n", *(unsigned int *)(a1 + 36));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return printk("Interrupt %d called \n", *(unsigned int *)(a1 + 36));
}

original_code:
void UserInterrupt (REGISTERS *pRegisters) {
  printk("Interrupt %d called \n", pRegisters->IntNum);
}

canonical_original_code:
void UserInterrupt(struct registers *pRegisters) {
  printk("Interrupt %d called \n", pRegisters->IntNum);
}

variable_types: struct registers { unsigned int DS; unsigned int EDI; unsigned int IntNum; unsigned int EIP; } *


ISRExceptHandler

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

result = printk("Error %d got \n", *(unsigned int *)(a1 + 36));
if ( *(_DWORD *)(a1 + 36) == 13 )
result = printk("Unhandled interrupt \n");
return result;
}

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

result = printk("Error %d got \n", *(unsigned int *)(a1 + 36));
if ( *(_DWORD *)(a1 + 36) == 13 )
result = printk("Unhandled interrupt \n");
return result;
}

original_code:
void ISRExceptHandler (REGISTERS *pRegisters)
{
    printk("Error %d got \n", pRegisters->IntNum);
    if (pRegisters->IntNum == 13) {
      printk ("Unhandled interrupt \n");
    }
}

canonical_original_code:
void ISRExceptHandler(struct registers *pRegisters)
{
    printk("Error %d got \n", pRegisters->IntNum);
    if (pRegisters->IntNum == 13) {
      printk ("Unhandled interrupt \n");
    }
}

user_defined_types: struct registers { unsigned int DS; unsigned int EDI; unsigned int IntNum; unsigned int EIP; }


ISRDispatcher

decompiled_code:
__int64 __fastcall ISRDispatcher(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, int a9, int a10, __int64 a11)
{
__int64 result; // rax

if ( HIDWORD(a11) <= 0x1F )
result = ISRExceptHandler((__int64)&a7);
else
result = UserInterrupt((__int64)&a7);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, int a9, int a10, __int64 a11)
{
__int64 result; // rax

if ( HIDWORD(a11) <= 0x1F )
result = func3((__int64)&a7);
else
result = func2((__int64)&a7);
return result;
}

original_code:
void ISRDispatcher (REGISTERS Registers)
{
  if(Registers.IntNum > 31) {
    UserInterrupt (&Registers);
  }
  else {
    ISRExceptHandler(&Registers);
  }
}

canonical_original_code:
void ISRDispatcher(struct registers Registers)
{
  if(Registers.IntNum > 31) {
    UserInterrupt (&Registers);
  }
  else {
    ISRExceptHandler(&Registers);
  }
}

variable_types: struct registers { unsigned int DS; unsigned int EDI; unsigned int IntNum; unsigned int EIP; }


ClockTick

decompiled_code:
__int64 ClockTick()
{
return printk(".");
}

canonical_decompiled_code:
__int64 func5()
{
return printk(".");
}

original_code:
void ClockTick(void) {
  printk (".");
}

canonical_original_code:
void ClockTick() {
  printk (".");
}


KeyboardHandler

decompiled_code:
__int64 KeyboardHandler()
{
return printk("Keyboard \n");
}

canonical_decompiled_code:
__int64 func6()
{
return printk("Keyboard \n");
}

original_code:
void KeyboardHandler (void) {
 printk ("Keyboard \n");
}

canonical_original_code:
void KeyboardHandler() {
 printk ("Keyboard \n");
}


OkMsg

decompiled_code:
__int64 OkMsg()
{
return printk(&unk_FF);
}

canonical_decompiled_code:
__int64 func0()
{
return printk(&unk_FF);
}

original_code:
void OkMsg(void)
{
 printk("OK\n");
}

canonical_original_code:
void OkMsg()
{
 printk("OK\n");
}


InitPIC

decompiled_code:
__int64 InitPIC()
{
printk("Initialize PIC\n");
__outbyte(0x20u, 0x11u);
__outbyte(0xA0u, 0x11u);
__outbyte(0x21u, 0x20u);
__outbyte(0xA1u, 0x70u);
__outbyte(0x21u, 4u);
__outbyte(0xA1u, 2u);
__outbyte(0x21u, 1u);
__outbyte(0xA1u, 1u);
__outbyte(0x21u, 0);
__outbyte(0xA1u, 0);
return printk("PIC configured (or not :') ) \n");
}

canonical_decompiled_code:
__int64 func1()
{
printk("Initialize PIC\n");
__outbyte(0x20u, 0x11u);
__outbyte(0xA0u, 0x11u);
__outbyte(0x21u, 0x20u);
__outbyte(0xA1u, 0x70u);
__outbyte(0x21u, 4u);
__outbyte(0xA1u, 2u);
__outbyte(0x21u, 1u);
__outbyte(0xA1u, 1u);
__outbyte(0x21u, 0);
__outbyte(0xA1u, 0);
return printk("PIC configured (or not :') ) \n");
}

original_code:
void InitPIC(void)
{
 printk ("Initialize PIC\n");
 asm volatile ("outb %%al, %%dx" :: "d" (0x20), "a" (0x11));;
 asm volatile ("outb %%al, %%dx" :: "d" (0xA0), "a" (0x11));;
 asm volatile ("outb %%al, %%dx" :: "d" (0x21), "a" (0x20));;
 asm volatile ("outb %%al, %%dx" :: "d" (0xA1), "a" (0x70));;
 asm volatile ("outb %%al, %%dx" :: "d" (0x21), "a" (0x04));;
 asm volatile ("outb %%al, %%dx" :: "d" (0xA1), "a" (0x02));;
 asm volatile ("outb %%al, %%dx" :: "d" (0x21), "a" (0x01));;
 asm volatile ("outb %%al, %%dx" :: "d" (0xA1), "a" (0x01));;
 asm volatile ("outb %%al, %%dx" :: "d" (0x21), "a" (0x0));;
 asm volatile ("outb %%al, %%dx" :: "d" (0xA1), "a" (0x0));;
 printk ("PIC configured (or not :') ) \n");
}


kmain

decompiled_code:
void __fastcall __noreturn kmain(__int64 a1)
{
printk("RAM detected : %uk (lower), %uk (upper)\n", *(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16));
printk("Command line got: %s \n", *(const char **)(a1 + 32));
printk("Initialize GDT ... ");
InitGDT();
OkMsg();
LoadIDT();
printk(aIdtLoaded);
InitPIC();
_enable();
while ( 1 )
;
}

canonical_decompiled_code:
void __fastcall __noreturn func2(__int64 a1)
{
printk("RAM detected : %uk (lower), %uk (upper)\n", *(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16));
printk("Command line got: %s \n", *(const char **)(a1 + 32));
printk("Initialize GDT ... ");
InitGDT();
func0();
LoadIDT();
printk(aIdtLoaded);
func1();
_enable();
while ( 1 )
;
}

original_code:
void kmain(struct mb_partial_info *mbi)
{
    printk("RAM detected : %uk (lower), %uk (upper)\n", mbi->low_mem, mbi->high_mem);
    printk("Command line got: %s \n", mbi->cmdline);
 printk ("Initialize GDT ... ");
 InitGDT();
    asm("   movw $0x18, %ax \n                 movw %ax, %ss \n                 movl $0x1FFF0, %esp");
 OkMsg();
 LoadIDT();
    printk ("IDT loaded  éè\n");
    InitPIC();
 asm("sti"::);
 while(1) { }
}

variable_types: struct mb_partial_info { unsigned long flags; unsigned long low_mem; unsigned long high_mem; unsigned long boot_device; unsigned long cmdline; } *


repo: aantn/littler-snitch

decompiled_code:
__int64 __fastcall write_data(const void *a1, size_t a2, size_t a3, FILE *a4)
{
return (int)fwrite(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, size_t a2, size_t a3, FILE *a4)
{
return (int)fwrite(a1, a2, a3, a4);
}

original_code:
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
    int written = fwrite(ptr, size, nmemb, (FILE *)stream);
    return written;
}

canonical_original_code:
static unsigned long write_data(void *ptr, unsigned long size, unsigned long nmemb, void *stream)
{
    int written = fwrite(ptr, size, nmemb, (FILE *)stream);
    return written;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
stream
void *

variable_types: written int

return_type: unsigned long


push

repo: aap/abc

decompiled_code:
int push()
{
return printf("\tpush\t%%eax\n");
}

canonical_decompiled_code:
int func0()
{
return printf("\tpush\t%%eax\n");
}

original_code:
void
push(void)
{
 printf("\tpush\t%%eax\n");
}

canonical_original_code:
void push()
{
 printf("\tpush\t%%eax\n");
}


pop

decompiled_code:
int __fastcall pop(const char *a1)
{
return printf("\tpop\t%%%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("\tpop\t%%%s\n", a1);
}

original_code:
void
pop(char *s)
{
 printf("\tpop\t%%%s\n", s);
}

variable_types:
s
char *


rcexpr

decompiled_code:
void __fastcall rcexpr(int *a1, __int64 a2, const char *a3)
{
int v3; // esi
const char *v4; // rax
const char *v5; // rdx
unsigned int v6; // ebp
const char *v7; // rax
unsigned int v8; // er12
unsigned int v9; // ebp

if ( a1 )
{
v3 = *a1;
if ( (*((_BYTE *)&opdope + 4 * *a1) & 2) != 0 )
{
lvalexp();
}
else
{
switch ( v3 )
{
case 16:
v6 = pushargs(*((_QWORD *)a1 + 2));
rcexpr(*((_QWORD *)a1 + 1));
printf("\tshl\t$2,%%eax\n");
printf("\tcall\t*%%eax\n");
if ( v6 )
printf("\tadd\t$%d,%%esp\n", v6);
break;
case 21:
rcexpr(*((_QWORD *)a1 + 1));
printf("\ttest\t%%eax,%%eax\n");
printf("\tsete\t%%al\n");
printf("\tmovzb\t%%al,%%eax\n");
break;
case 22:
rcexpr(*((_QWORD *)a1 + 1));
printf("\tneg\t%%eax\n");
break;
case 23:
v7 = *(const char **)(*((_QWORD *)a1 + 1) + 8LL);
v5 = (const char *)*(unsigned int *)v7;
if ( (_DWORD)v5 == 2 )
{
printf("\tmov\t$_%s,%%eax\n", v7 + 24);
printf("\tshr\t$2,%%eax\n");
}
else
{
if ( (_DWORD)v5 != 1 )
goto LABEL_40;
printf("\tlea\t%d(%%ebp),%%eax\n", *((unsigned int *)v7 + 1));
printf("\tshr\t$2,%%eax\n");
}
break;
case 24:
rcexpr(*((_QWORD *)a1 + 1));
printf("\tmov\t(,%%eax,4),%%eax\n");
break;
case 25:
v8 = isn++;
cbranch(*((_QWORD *)a1 + 1), v8, 0LL);
rcexpr(*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL));
v9 = isn++;
jump(v9);
label(v8);
rcexpr(*(_QWORD *)(*((_QWORD *)a1 + 2) + 16LL));
label(v9);
break;
case 30:
binary();
pop("ebx");
printf("\tadd\t%%ebx,%%eax\n");
break;
case 31:
binary();
printf("\tmov\t%%eax,%%ebx\n");
pop("eax");
printf("\tsub\t%%ebx,%%eax\n");
break;
case 32:
binary();
printf("\tmov\t%%eax,%%ebx\n");
pop("eax");
printf("\txor\t%%edx,%%edx\n");
printf("\tdiv\t%%ebx\n");
printf("\tmov\t%%edx,%%eax\n");
break;
case 33:
binary();
pop("ebx");
printf("\tmul\t%%ebx\n");
break;
case 34:
binary();
printf("\tmov\t%%eax,%%ebx\n");
pop("eax");
printf("\txor\t%%edx,%%edx\n");
printf("\tdiv\t%%ebx\n");
break;
case 35:
binary();
pop("ebx");
printf("\tor\t%%ebx,%%eax\n");
break;
case 36:
binary();
pop("ebx");
printf("\tand\t%%ebx,%%eax\n");
break;
case 37:
binary();
printf("\tmov\t%%eax,%%ecx\n");
pop("eax");
printf("\tshl\t%%cl,%%eax\n");
break;
case 38:
binary();
printf("\tmov\t%%eax,%%ecx\n");
pop("eax");
printf("\tshr\t%%cl,%%eax\n");
break;
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
binary();
pop("ebx");
printf("\tcmp\t%%eax,%%ebx\n");
switch ( *a1 )
{
case '\'':
printf("\tsete\t%%al\n");
break;
case '(':
printf("\tsetne\t%%al\n");
break;
case ')':
printf("\tsetle\t%%al\n");
break;
case '*':
printf("\tsetl\t%%al\n");
break;
case '+':
printf("\tsetge\t%%al\n");
break;
case ',':
printf("\tsetg\t%%al\n");
break;
default:
break;
}
printf("\tmovzb\t%%al,%%eax\n");
break;
case 65:
printf("\tmov\t$%d,%%eax\n", (unsigned int)a1[1]);
break;
case 66:
printf("\tmov\t$L%d,%%eax\n", (unsigned int)a1[1]);
printf("\tshr\t$2,%%eax\n");
break;
case 67:
v4 = (const char *)*((_QWORD *)a1 + 1);
v5 = (const char *)*(unsigned int *)v4;
if ( (_DWORD)v5 == 2 )
{
printf("\tmov\t_%s,%%eax\n", v4 + 24);
}
else
{
if ( (_DWORD)v5 != 1 )
goto LABEL_40;
printf("\tmov\t%d(%%ebp),%%eax\n", *((unsigned int *)v4 + 1));
}
break;
default:
error((int)"Can't print tree (op: %d)", v3, a3);
LABEL_40:
error((int)"Storage class", v3, v5);
break;
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(int *a1, __int64 a2, const char *a3)
{
int v3; // esi
const char *v4; // rax
const char *v5; // rdx
unsigned int v6; // ebp
const char *v7; // rax
unsigned int v8; // er12
unsigned int v9; // ebp

if ( a1 )
{
v3 = *a1;
if ( (*((_BYTE *)&opdope + 4 * *a1) & 2) != 0 )
{
func5();
}
else
{
switch ( v3 )
{
case 16:
v6 = func4(*((_QWORD *)a1 + 2));
func2(*((_QWORD *)a1 + 1));
printf("\tshl\t$2,%%eax\n");
printf("\tcall\t*%%eax\n");
if ( v6 )
printf("\tadd\t$%d,%%esp\n", v6);
break;
case 21:
func2(*((_QWORD *)a1 + 1));
printf("\ttest\t%%eax,%%eax\n");
printf("\tsete\t%%al\n");
printf("\tmovzb\t%%al,%%eax\n");
break;
case 22:
func2(*((_QWORD *)a1 + 1));
printf("\tneg\t%%eax\n");
break;
case 23:
v7 = *(const char **)(*((_QWORD *)a1 + 1) + 8LL);
v5 = (const char *)*(unsigned int *)v7;
if ( (_DWORD)v5 == 2 )
{
printf("\tmov\t$_%s,%%eax\n", v7 + 24);
printf("\tshr\t$2,%%eax\n");
}
else
{
if ( (_DWORD)v5 != 1 )
goto LABEL_40;
printf("\tlea\t%d(%%ebp),%%eax\n", *((unsigned int *)v7 + 1));
printf("\tshr\t$2,%%eax\n");
}
break;
case 24:
func2(*((_QWORD *)a1 + 1));
printf("\tmov\t(,%%eax,4),%%eax\n");
break;
case 25:
v8 = isn++;
cbranch(*((_QWORD *)a1 + 1), v8, 0LL);
func2(*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL));
v9 = isn++;
jump(v9);
label(v8);
func2(*(_QWORD *)(*((_QWORD *)a1 + 2) + 16LL));
label(v9);
break;
case 30:
func3();
func1("ebx");
printf("\tadd\t%%ebx,%%eax\n");
break;
case 31:
func3();
printf("\tmov\t%%eax,%%ebx\n");
func1("eax");
printf("\tsub\t%%ebx,%%eax\n");
break;
case 32:
func3();
printf("\tmov\t%%eax,%%ebx\n");
func1("eax");
printf("\txor\t%%edx,%%edx\n");
printf("\tdiv\t%%ebx\n");
printf("\tmov\t%%edx,%%eax\n");
break;
case 33:
func3();
func1("ebx");
printf("\tmul\t%%ebx\n");
break;
case 34:
func3();
printf("\tmov\t%%eax,%%ebx\n");
func1("eax");
printf("\txor\t%%edx,%%edx\n");
printf("\tdiv\t%%ebx\n");
break;
case 35:
func3();
func1("ebx");
printf("\tor\t%%ebx,%%eax\n");
break;
case 36:
func3();
func1("ebx");
printf("\tand\t%%ebx,%%eax\n");
break;
case 37:
func3();
printf("\tmov\t%%eax,%%ecx\n");
func1("eax");
printf("\tshl\t%%cl,%%eax\n");
break;
case 38:
func3();
printf("\tmov\t%%eax,%%ecx\n");
func1("eax");
printf("\tshr\t%%cl,%%eax\n");
break;
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
func3();
func1("ebx");
printf("\tcmp\t%%eax,%%ebx\n");
switch ( *a1 )
{
case '\'':
printf("\tsete\t%%al\n");
break;
case '(':
printf("\tsetne\t%%al\n");
break;
case ')':
printf("\tsetle\t%%al\n");
break;
case '*':
printf("\tsetl\t%%al\n");
break;
case '+':
printf("\tsetge\t%%al\n");
break;
case ',':
printf("\tsetg\t%%al\n");
break;
default:
break;
}
printf("\tmovzb\t%%al,%%eax\n");
break;
case 65:
printf("\tmov\t$%d,%%eax\n", (unsigned int)a1[1]);
break;
case 66:
printf("\tmov\t$L%d,%%eax\n", (unsigned int)a1[1]);
printf("\tshr\t$2,%%eax\n");
break;
case 67:
v4 = (const char *)*((_QWORD *)a1 + 1);
v5 = (const char *)*(unsigned int *)v4;
if ( (_DWORD)v5 == 2 )
{
printf("\tmov\t_%s,%%eax\n", v4 + 24);
}
else
{
if ( (_DWORD)v5 != 1 )
goto LABEL_40;
printf("\tmov\t%d(%%ebp),%%eax\n", *((unsigned int *)v4 + 1));
}
break;
default:
error((int)"Can't print tree (op: %d)", v3, a3);
LABEL_40:
error((int)"Storage class", v3, v5);
break;
}
}
}
}

original_code:
void
rcexpr(struct tnode *tr)
{
 int o1, o2;
 int stk;
 struct hshtab *bs;
 if (tr == ((void *)0))
  return;
 if (opdope[tr->op]&02) {
  lvalexp(tr);
  return;
 }
 switch (tr->op) {
 case 65:
  printf("\tmov\t$%d,%%eax\n", tr->value);
  return;
 case 66:
  printf("\tmov\t$L%d,%%eax\n", tr->value);
  printf("\tshr\t$2,%%eax\n");
  return;
 case 67:
  bs = (struct hshtab *) tr->tr1;
  if (bs->class == 2)
   printf("\tmov\t_%s,%%eax\n", bs->name);
  else if (bs->class == 1)
   printf("\tmov\t%d(%%ebp),%%eax\n", bs->offset);
  else
   goto classerror;
  return;
 case 16:
  stk = pushargs(tr->tr2);
  rcexpr(tr->tr1);
  printf("\tshl\t$2,%%eax\n");
  printf("\tcall\t*%%eax\n");
  if (stk)
   printf("\tadd\t$%d,%%esp\n",stk);
  return;
 case 23:
  bs = (struct hshtab *) tr->tr1->tr1;
  if (bs->class == 2) {
   printf("\tmov\t$_%s,%%eax\n", bs->name);
   printf("\tshr\t$2,%%eax\n");
  } else if (bs->class == 1) {
   printf("\tlea\t%d(%%ebp),%%eax\n", bs->offset);
   printf("\tshr\t$2,%%eax\n");
  } else
   goto classerror;
  return;
 case 24:
  rcexpr(tr->tr1);
  printf("\tmov\t(,%%eax,4),%%eax\n");
  return;
 case 30:
  binary(tr);
  pop("ebx");
  printf("\tadd\t%%ebx,%%eax\n");
  return;
 case 31:
  binary(tr);
  printf("\tmov\t%%eax,%%ebx\n");
  pop("eax");
  printf("\tsub\t%%ebx,%%eax\n");
  return;
 case 33:
  binary(tr);
  pop("ebx");
  printf("\tmul\t%%ebx\n");
  return;
 case 34:
  binary(tr);
  printf("\tmov\t%%eax,%%ebx\n");
  pop("eax");
  printf("\txor\t%%edx,%%edx\n");
  printf("\tdiv\t%%ebx\n");
  return;
 case 32:
  binary(tr);
  printf("\tmov\t%%eax,%%ebx\n");
  pop("eax");
  printf("\txor\t%%edx,%%edx\n");
  printf("\tdiv\t%%ebx\n");
  printf("\tmov\t%%edx,%%eax\n");
  return;
 case 36:
  binary(tr);
  pop("ebx");
  printf("\tand\t%%ebx,%%eax\n");
  return;
 case 35:
  binary(tr);
  pop("ebx");
  printf("\tor\t%%ebx,%%eax\n");
  return;
 case 37:
  binary(tr);
  printf("\tmov\t%%eax,%%ecx\n");
  pop("eax");
  printf("\tshl\t%%cl,%%eax\n");
  return;
 case 38:
  binary(tr);
  printf("\tmov\t%%eax,%%ecx\n");
  pop("eax");
  printf("\tshr\t%%cl,%%eax\n");
  return;
 case 39:
 case 40:
 case 42:
 case 41:
 case 44:
 case 43:
  binary(tr);
  pop("ebx");
  printf("\tcmp\t%%eax,%%ebx\n");
  switch (tr->op) {
  case 39:
   printf("\tsete\t%%al\n");
   break;
  case 40:
   printf("\tsetne\t%%al\n");
   break;
  case 42:
   printf("\tsetl\t%%al\n");
   break;
  case 41:
   printf("\tsetle\t%%al\n");
   break;
  case 44:
   printf("\tsetg\t%%al\n");
   break;
  case 43:
   printf("\tsetge\t%%al\n");
   break;
  }
  printf("\tmovzb\t%%al,%%eax\n");
  return;
 case 21:
  rcexpr(tr->tr1);
  printf("\ttest\t%%eax,%%eax\n");
  printf("\tsete\t%%al\n");
  printf("\tmovzb\t%%al,%%eax\n");
  return;
 case 22:
  rcexpr(tr->tr1);
  printf("\tneg\t%%eax\n");
  return;
 case 25:
  cbranch(tr->tr1, o1=isn++, 0);
  rcexpr(tr->tr2->tr1);
  jump(o2 = isn++);
  label(o1);
  rcexpr(tr->tr2->tr2);
  label(o2);
  return;
 default:
  error("Can't print tree (op: %d)", tr->op);
 }
classerror:
 error("Storage class");
}

canonical_original_code:
void rcexpr(struct tnode *tr)
{
 int o1; int o2;
 int stk;
 struct hshtab *bs;
 if (tr == ((void *)0))
  return;
 if (opdope[tr->op]&02) {
  lvalexp(tr);
  return;
 }
 switch (tr->op) {
 case 65:
  printf("\tmov\t$%d,%%eax\n", tr->value);
  return;
 case 66:
  printf("\tmov\t$L%d,%%eax\n", tr->value);
  printf("\tshr\t$2,%%eax\n");
  return;
 case 67:
  bs = (struct hshtab *) tr->tr1;
  if (bs->class == 2)
   printf("\tmov\t_%s,%%eax\n", bs->name);
  else if (bs->class == 1)
   printf("\tmov\t%d(%%ebp),%%eax\n", bs->offset);
  else
   goto classerror;
  return;
 case 16:
  stk = pushargs(tr->tr2);
  rcexpr(tr->tr1);
  printf("\tshl\t$2,%%eax\n");
  printf("\tcall\t*%%eax\n");
  if (stk)
   printf("\tadd\t$%d,%%esp\n",stk);
  return;
 case 23:
  bs = (struct hshtab *) tr->tr1->tr1;
  if (bs->class == 2) {
   printf("\tmov\t$_%s,%%eax\n", bs->name);
   printf("\tshr\t$2,%%eax\n");
  } else if (bs->class == 1) {
   printf("\tlea\t%d(%%ebp),%%eax\n", bs->offset);
   printf("\tshr\t$2,%%eax\n");
  } else
   goto classerror;
  return;
 case 24:
  rcexpr(tr->tr1);
  printf("\tmov\t(,%%eax,4),%%eax\n");
  return;
 case 30:
  binary(tr);
  pop("ebx");
  printf("\tadd\t%%ebx,%%eax\n");
  return;
 case 31:
  binary(tr);
  printf("\tmov\t%%eax,%%ebx\n");
  pop("eax");
  printf("\tsub\t%%ebx,%%eax\n");
  return;
 case 33:
  binary(tr);
  pop("ebx");
  printf("\tmul\t%%ebx\n");
  return;
 case 34:
  binary(tr);
  printf("\tmov\t%%eax,%%ebx\n");
  pop("eax");
  printf("\txor\t%%edx,%%edx\n");
  printf("\tdiv\t%%ebx\n");
  return;
 case 32:
  binary(tr);
  printf("\tmov\t%%eax,%%ebx\n");
  pop("eax");
  printf("\txor\t%%edx,%%edx\n");
  printf("\tdiv\t%%ebx\n");
  printf("\tmov\t%%edx,%%eax\n");
  return;
 case 36:
  binary(tr);
  pop("ebx");
  printf("\tand\t%%ebx,%%eax\n");
  return;
 case 35:
  binary(tr);
  pop("ebx");
  printf("\tor\t%%ebx,%%eax\n");
  return;
 case 37:
  binary(tr);
  printf("\tmov\t%%eax,%%ecx\n");
  pop("eax");
  printf("\tshl\t%%cl,%%eax\n");
  return;
 case 38:
  binary(tr);
  printf("\tmov\t%%eax,%%ecx\n");
  pop("eax");
  printf("\tshr\t%%cl,%%eax\n");
  return;
 case 39:
 case 40:
 case 42:
 case 41:
 case 44:
 case 43:
  binary(tr);
  pop("ebx");
  printf("\tcmp\t%%eax,%%ebx\n");
  switch (tr->op) {
  case 39:
   printf("\tsete\t%%al\n");
   break;
  case 40:
   printf("\tsetne\t%%al\n");
   break;
  case 42:
   printf("\tsetl\t%%al\n");
   break;
  case 41:
   printf("\tsetle\t%%al\n");
   break;
  case 44:
   printf("\tsetg\t%%al\n");
   break;
  case 43:
   printf("\tsetge\t%%al\n");
   break;
  }
  printf("\tmovzb\t%%al,%%eax\n");
  return;
 case 21:
  rcexpr(tr->tr1);
  printf("\ttest\t%%eax,%%eax\n");
  printf("\tsete\t%%al\n");
  printf("\tmovzb\t%%al,%%eax\n");
  return;
 case 22:
  rcexpr(tr->tr1);
  printf("\tneg\t%%eax\n");
  return;
 case 25:
  cbranch(tr->tr1, o1=isn++, 0);
  rcexpr(tr->tr2->tr1);
  jump(o2 = isn++);
  label(o1);
  rcexpr(tr->tr2->tr2);
  label(o2);
  return;
 default:
  error("Can't print tree (op: %d)", tr->op);
 }
classerror:
 error("Storage class");
}

variable_types: struct tnode { int op; int value; struct tnode *tr1; struct tnode *tr2; } *

variable_types: stk int

variable_types: struct hshtab { int class; int offset; int dim; struct hshtab *next; char name[-1]; } *


binary

decompiled_code:
void __fastcall binary(__int64 a1, __int64 a2, const char *a3)
{
const char *v3; // rdx

rcexpr(*(int **)(a1 + 8), a2, a3);
push();
rcexpr(*(int **)(a1 + 16), a2, v3);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2, const char *a3)
{
const char *v3; // rdx

func2(*(int **)(a1 + 8), a2, a3);
func0();
func2(*(int **)(a1 + 16), a2, v3);
}

original_code:
void
binary(struct tnode *tr)
{
 rcexpr(tr->tr1);
 push();
 rcexpr(tr->tr2);
}

user_defined_types: struct tnode { int op; int value; struct tnode *tr1; struct tnode *tr2; }


pushargs

decompiled_code:
__int64 __fastcall pushargs(__int64 a1, __int64 a2, const char *a3)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == 9 )
{
rcexpr(*(int **)(a1 + 16), a2, a3);
push();
result = (unsigned int)pushargs(*(_QWORD *)(a1 + 8)) + 4;
}
else
{
rcexpr((int *)a1, a2, a3);
push();
result = 4LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == 9 )
{
func2(*(int **)(a1 + 16), a2, a3);
func0();
result = (unsigned int)func4(*(_QWORD *)(a1 + 8)) + 4;
}
else
{
func2((int *)a1, a2, a3);
func0();
result = 4LL;
}
return result;
}

original_code:
int
pushargs(struct tnode *tr)
{
 int stk;
 if (tr == ((void *)0))
  return 0;
 if (tr->op == 9) {
  rcexpr(tr->tr2);
  push();
  stk = pushargs(tr->tr1);
  return stk+4;
 }
 rcexpr(tr);
 push();
 return 4;
}


lvalexp

decompiled_code:
void __fastcall lvalexp(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 v4; // rax
int *v5; // rax
const char *v6; // rdx
const char *v7; // rsi
const char *v8; // rsi
__int64 v9; // rax
const char *v10; // rdx
char v11[72]; // [rsp+0h] [rbp-48h] BYREF

v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 49 )
{
rcexpr(*(int **)(a1 + 16), a2, (const char *)a3);
v9 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)v9 == 24 )
{
push();
rcexpr(*(int **)(*(_QWORD *)(a1 + 8) + 8LL), a2, v10);
pop("ebx");
printf("\tmov\t%%ebx,(,%%eax,4)\n");
}
else
{
a2 = *(_QWORD *)(v9 + 8);
if ( *(_DWORD *)a2 == 2 )
{
printf("\tmov\t%%eax,_%s\n", (const char *)(a2 + 24));
}
else
{
if ( *(_DWORD *)a2 != 1 )
goto LABEL_7;
printf("\tmov\t%%eax,%d(%%ebp)\n", *(unsigned int *)(a2 + 4));
}
}
}
else if ( v3 > 49 )
{
a3 = (unsigned int)(v3 - 50);
if ( (unsigned int)a3 > 0xE )
goto LABEL_7;
*(_DWORD *)a1 = v3 - 20;
v5 = (int *)block(49LL, 0LL, *(_QWORD *)(a1 + 8), a1);
rcexpr(v5, 0LL, v6);
}
else
{
if ( (unsigned int)(v3 - 17) > 3 )
{
LABEL_7:
error((int)"Storage class", a2, (const char *)a3);
return;
}
v4 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)v4 == 24 )
{
rcexpr(*(int **)(v4 + 8), a2, (const char *)a3);
printf("\tmov\t%%eax,%%ebx\n");
sprintf(v11, "(,%%ebx,4)");
}
else
{
a3 = *(_QWORD *)(v4 + 8);
if ( *(_DWORD *)a3 == 2 )
{
sprintf(v11, "_%s", (const char *)(a3 + 24));
}
else
{
if ( *(_DWORD *)a3 != 1 )
goto LABEL_7;
sprintf(v11, "%d(%%ebp)", *(unsigned int *)(a3 + 4));
}
}
if ( (unsigned int)(*(_DWORD *)a1 - 17) > 1 )
{
printf("\tmov\t%s,%%eax\n", v11);
v8 = "decl";
if ( *(_DWORD *)a1 != 19 )
v8 = "incl";
printf("\t%s\t%s\n", v8, v11);
}
else
{
v7 = "decl";
if ( *(_DWORD *)a1 != 17 )
v7 = "incl";
printf("\t%s\t%s\n", v7, v11);
printf("\tmov\t%s,%%eax\n", v11);
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 v4; // rax
int *v5; // rax
const char *v6; // rdx
const char *v7; // rsi
const char *v8; // rsi
__int64 v9; // rax
const char *v10; // rdx
char v11[72]; // [rsp+0h] [rbp-48h] BYREF

v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 49 )
{
func2(*(int **)(a1 + 16), a2, (const char *)a3);
v9 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)v9 == 24 )
{
func0();
func2(*(int **)(*(_QWORD *)(a1 + 8) + 8LL), a2, v10);
func1("ebx");
printf("\tmov\t%%ebx,(,%%eax,4)\n");
}
else
{
a2 = *(_QWORD *)(v9 + 8);
if ( *(_DWORD *)a2 == 2 )
{
printf("\tmov\t%%eax,_%s\n", (const char *)(a2 + 24));
}
else
{
if ( *(_DWORD *)a2 != 1 )
goto LABEL_7;
printf("\tmov\t%%eax,%d(%%ebp)\n", *(unsigned int *)(a2 + 4));
}
}
}
else if ( v3 > 49 )
{
a3 = (unsigned int)(v3 - 50);
if ( (unsigned int)a3 > 0xE )
goto LABEL_7;
*(_DWORD *)a1 = v3 - 20;
v5 = (int *)block(49LL, 0LL, *(_QWORD *)(a1 + 8), a1);
func2(v5, 0LL, v6);
}
else
{
if ( (unsigned int)(v3 - 17) > 3 )
{
LABEL_7:
error((int)"Storage class", a2, (const char *)a3);
return;
}
v4 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)v4 == 24 )
{
func2(*(int **)(v4 + 8), a2, (const char *)a3);
printf("\tmov\t%%eax,%%ebx\n");
sprintf(v11, "(,%%ebx,4)");
}
else
{
a3 = *(_QWORD *)(v4 + 8);
if ( *(_DWORD *)a3 == 2 )
{
sprintf(v11, "_%s", (const char *)(a3 + 24));
}
else
{
if ( *(_DWORD *)a3 != 1 )
goto LABEL_7;
sprintf(v11, "%d(%%ebp)", *(unsigned int *)(a3 + 4));
}
}
if ( (unsigned int)(*(_DWORD *)a1 - 17) > 1 )
{
printf("\tmov\t%s,%%eax\n", v11);
v8 = "decl";
if ( *(_DWORD *)a1 != 19 )
v8 = "incl";
printf("\t%s\t%s\n", v8, v11);
}
else
{
v7 = "decl";
if ( *(_DWORD *)a1 != 17 )
v7 = "incl";
printf("\t%s\t%s\n", v7, v11);
printf("\tmov\t%s,%%eax\n", v11);
}
}
}

original_code:
void
lvalexp(struct tnode *tr)
{
 struct hshtab *bs;
 char memloc[64];
 switch (tr->op) {
 case 17:
 case 18:
 case 19:
 case 20:
  if (tr->tr1->op == 24) {
   rcexpr(tr->tr1->tr1);
   printf("\tmov\t%%eax,%%ebx\n");
   sprintf(memloc,"(,%%ebx,4)");
  } else {
   bs = (struct hshtab *) tr->tr1->tr1;
   if (bs->class == 2)
    sprintf(memloc,"_%s", bs->name);
   else if (bs->class == 1)
    sprintf(memloc,"%d(%%ebp)", bs->offset);
   else
    goto classerror;
  }
  if (tr->op == 17 || tr->op == 18) {
   printf("\t%s\t%s\n", tr->op == 17 ? "decl" : "incl",
          memloc);
   printf("\tmov\t%s,%%eax\n", memloc);
  } else {
   printf("\tmov\t%s,%%eax\n", memloc);
   printf("\t%s\t%s\n", tr->op == 19 ? "decl" : "incl",
          memloc);
  }
  return;
 case 49:
  rcexpr(tr->tr2);
  if (tr->tr1->op == 24) {
   push();
   rcexpr(tr->tr1->tr1);
   pop("ebx");
   printf("\tmov\t%%ebx,(,%%eax,4)\n");
  } else {
   bs = (struct hshtab *) tr->tr1->tr1;
   if (bs->class == 2)
    printf("\tmov\t%%eax,_%s\n", bs->name);
   else if (bs->class == 1)
    printf("\tmov\t%%eax,%d(%%ebp)\n", bs->offset);
   else
    goto classerror;
  }
  return;
 case 50:
 case 51:
 case 52:
 case 53:
 case 54:
 case 55:
 case 56:
 case 57:
 case 58:
 case 59:
 case 60:
 case 61:
 case 62:
 case 63:
 case 64:
  tr->op -= 50 -30;
  rcexpr(block(49,0,tr->tr1,tr));
  return;
 }
classerror:
 error("Storage class");
}

variable_types:
memloc
char [64]

user_defined_types: struct hshtab { int class; int offset; int dim; struct hshtab *next; char name[-1]; }


repo: aarzilli/minstrel

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

result = LOBYTE(queue[2 * a1]);
if ( (_BYTE)result )
result = BYTE1(queue[2 * a1]);
return result;
}

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

result = LOBYTE(queue[2 * a1]);
if ( (_BYTE)result )
result = BYTE1(queue[2 * a1]);
return result;
}

original_code:
static _Bool queue_could_be_prev(int idx) {
 if (!queue[idx].occupied) return 0;
 if (!queue[idx].played) return 0;
 return 1;
}

variable_types: idx int


decompiled_code:
__int64 clear_screen()
{
return putctlcod("cl", stdout);
}

canonical_decompiled_code:
__int64 func2()
{
return putctlcod("cl", stdout);
}

original_code:
static void clear_screen(void) {
 putctlcod("cl", stdout);
}

canonical_original_code:
static void clear_screen() {
 putctlcod("cl", stdout);
}


decompiled_code:
void queue_init()
{
bzero(queue, 0x8000uLL);
queue_position = 0;
queue_currently_playing_idx = -1;
}

canonical_decompiled_code:
void func3()
{
bzero(queue, 0x8000uLL);
queue_position = 0;
queue_currently_playing_idx = -1;
}

original_code:
void queue_init(void) {
 bzero(queue, sizeof(queue));
 queue_position = 0;
 queue_currently_playing_idx = -1;
}

canonical_original_code:
void queue_init() {
 bzero(queue, sizeof(queue));
 queue_position = 0;
 queue_currently_playing_idx = -1;
}


decompiled_code:
size_t __fastcall queue_append(__int64 a1)
{
int v1; // eax
__int64 v2; // rdx
size_t result; // rax

v1 = queue_position;
if ( queue_position > 2047 )
return fwrite("can not add anything anymore\n", 1uLL, 0x1DuLL, stderr);
v2 = 16LL * queue_position;
queue[v2] = 1;
queue[v2 + 1] = 0;
*(_QWORD *)&queue[v2 + 8] = a1;
result = (unsigned int)(v1 + 1);
queue_position = result;
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(__int64 a1)
{
int v1; // eax
__int64 v2; // rdx
size_t result; // rax

v1 = queue_position;
if ( queue_position > 2047 )
return fwrite("can not add anything anymore\n", 1uLL, 0x1DuLL, stderr);
v2 = 16LL * queue_position;
queue[v2] = 1;
queue[v2 + 1] = 0;
*(_QWORD *)&queue[v2 + 8] = a1;
result = (unsigned int)(v1 + 1);
queue_position = result;
return result;
}

original_code:
void queue_append(int64_t id) {
 if (queue_position >= 2048) {
  fprintf(stderr, "can not add anything anymore\n");
  return;
 }
 queue[queue_position].occupied = 1;
 queue[queue_position].played = 0;
 queue[queue_position].id = id;
 ++queue_position;
}

canonical_original_code:
void queue_append(long id) {
 if (queue_position >= 2048) {
  fprintf(stderr, "can not add anything anymore\n");
  return;
 }
 queue[queue_position].occupied = 1;
 queue[queue_position].played = 0;
 queue[queue_position].id = id;
 ++queue_position;
}

variable_types: id long


decompiled_code:
_BYTE *queue_currently_playing()
{
return &queue[16 * queue_currently_playing_idx];
}

canonical_decompiled_code:
_BYTE *func5()
{
return &queue[16 * queue_currently_playing_idx];
}

original_code:
struct item *queue_currently_playing(void) {
 return queue+queue_currently_playing_idx;
}

canonical_original_code:
struct item *queue_currently_playing() {
 return queue+queue_currently_playing_idx;
}

return_type: struct item { _Bool occupied; _Bool played; long id; } *


decompiled_code:
__int64 queue_to_prev()
{
int v0; // ebx
unsigned int v1; // ebp

v0 = (queue_currently_playing_idx - 1) % 2048;
v1 = queue_could_be_prev(v0);
if ( (_BYTE)v1 )
{
queue_currently_playing()[1] = 0;
queue_currently_playing_idx = v0;
}
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
unsigned int v1; // ebp

v0 = (queue_currently_playing_idx - 1) % 2048;
v1 = func0(v0);
if ( (_BYTE)v1 )
{
func5()[1] = 0;
queue_currently_playing_idx = v0;
}
return v1;
}

original_code:
_Bool queue_to_prev(void) {
 int prev_idx = (queue_currently_playing_idx - 1) % 2048;
 if (!queue_could_be_prev(prev_idx)) return 0;
 queue_currently_playing()->played = 0;
 queue_currently_playing_idx = prev_idx;
 return 1;
}

canonical_original_code:
_Bool queue_to_prev() {
 int prev_idx = (queue_currently_playing_idx - 1) % 2048;
 if (!queue_could_be_prev(prev_idx)) return 0;
 queue_currently_playing()->played = 0;
 queue_currently_playing_idx = prev_idx;
 return 1;
}


setaddr

decompiled_code:
int __fastcall setaddr(char *a1)
{
__uid_t v1; // eax

bzero(a1, 0x6EuLL);
*(_WORD *)a1 = 1;
v1 = getuid();
return snprintf(a1 + 2, 0x6BuLL, "/tmp/minstrel.%d", v1);
}

canonical_decompiled_code:
int __fastcall func0(char *a1)
{
__uid_t v1; // eax

bzero(a1, 0x6EuLL);
*(_WORD *)a1 = 1;
v1 = getuid();
return snprintf(a1 + 2, 0x6BuLL, "/tmp/minstrel.%d", v1);
}

original_code:
static void setaddr(struct sockaddr_un *address) {
 bzero(address, sizeof(*address));
 address->sun_family = 1;
 snprintf(address->sun_path, sizeof(address->sun_path) / sizeof(char) - sizeof(char), "/tmp/minstrel.%d", getuid());
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *


conn

decompiled_code:
__int64 conn()
{
int v0; // eax
unsigned int v1; // ebx
unsigned int v2; // eax
__int64 v4[2]; // [rsp+0h] [rbp-88h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF

setaddr((char *)&addr);
v0 = socket(1, 2, 0);
if ( v0 < 0 )
{
perror("Couldn't create a unix domain socket\n");
exit(1);
}
v1 = v0;
if ( connect(v0, &addr, 0x6Eu) )
{
close(v1);
v1 = -1;
}
else
{
v4[0] = 0LL;
v4[1] = 0LL;
v2 = send(v1, v4, 0x10uLL, 0);
if ( v2 != 16 )
{
fprintf(stderr, "Couldn't send handshake %d\n", v2);
close(v1);
v1 = -1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
unsigned int v1; // ebx
unsigned int v2; // eax
__int64 v4[2]; // [rsp+0h] [rbp-88h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF

func0((char *)&addr);
v0 = socket(1, 2, 0);
if ( v0 < 0 )
{
perror("Couldn't create a unix domain socket\n");
exit(1);
}
v1 = v0;
if ( connect(v0, &addr, 0x6Eu) )
{
close(v1);
v1 = -1;
}
else
{
v4[0] = 0LL;
v4[1] = 0LL;
v2 = send(v1, v4, 0x10uLL, 0);
if ( v2 != 16 )
{
fprintf(stderr, "Couldn't send handshake %d\n", v2);
close(v1);
v1 = -1;
}
}
return v1;
}

original_code:
int conn(void) {
 struct sockaddr_un address;
 setaddr(&address);
 int fd = socket(1, SOCK_DGRAM, 0);
 if (fd < 0) {
  perror("Couldn't create a unix domain socket\n");
  exit(1);
 }
 if (connect(fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0) {
  close(fd);
  return -1;
 }
 int64_t hs[2] = { CMD_HANDSHAKE, 0 };
 int r = send(fd, (void *)hs, sizeof(hs), 0);
 if (r != sizeof(hs)) {
  fprintf(stderr, "Couldn't send handshake %d\n", r);
  close(fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int conn() {
 struct sockaddr_un address;
 setaddr(&address);
 int fd = socket(1, SOCK_DGRAM, 0);
 if (fd < 0) {
  perror("Couldn't create a unix domain socket\n");
  exit(1);
 }
 if (connect(fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)) != 0) {
  close(fd);
  return -1;
 }
 long hs[2] = { CMD_HANDSHAKE, 0 };
 int r = send(fd, (void *)hs, sizeof(hs), 0);
 if (r != sizeof(hs)) {
  fprintf(stderr, "Couldn't send handshake %d\n", r);
  close(fd);
  return -1;
 }
 return fd;
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: fd int

variable_types:
hs
long [2]

variable_types: r int

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


serve

decompiled_code:
__int64 serve()
{
int v0; // eax
unsigned int v1; // ebx
struct sockaddr v3[7]; // [rsp+0h] [rbp-78h] BYREF

setaddr((char *)v3);
unlink(v3[0].sa_data);
v0 = socket(1, 2, 0);
if ( v0 < 0 )
{
perror("Couldn't create a unix domain socket\n");
exit(1);
}
v1 = v0;
if ( bind(v0, v3, 0x6Eu) )
{
perror("Couldn't open control socket");
exit(1);
}
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
unsigned int v1; // ebx
struct sockaddr v3[7]; // [rsp+0h] [rbp-78h] BYREF

func0((char *)v3);
unlink(v3[0].sa_data);
v0 = socket(1, 2, 0);
if ( v0 < 0 )
{
perror("Couldn't create a unix domain socket\n");
exit(1);
}
v1 = v0;
if ( bind(v0, v3, 0x6Eu) )
{
perror("Couldn't open control socket");
exit(1);
}
return v1;
}

original_code:
int serve(void) {
 struct sockaddr_un address;
 setaddr(&address);
 unlink(address.sun_path);
 int fd = socket(1, SOCK_DGRAM, 0);
 if (fd < 0) {
  perror("Couldn't create a unix domain socket\n");
  exit(1);
 }
 if (bind(fd, (struct sockaddr *) &address, sizeof(address)) != 0) {
  perror("Couldn't open control socket");
  exit(1);
 }
 return fd;
}

canonical_original_code:
int serve() {
 struct sockaddr_un address;
 setaddr(&address);
 unlink(address.sun_path);
 int fd = socket(1, SOCK_DGRAM, 0);
 if (fd < 0) {
  perror("Couldn't create a unix domain socket\n");
  exit(1);
 }
 if (bind(fd, (struct sockaddr *) &address, sizeof(address)) != 0) {
  perror("Couldn't open control socket");
  exit(1);
 }
 return fd;
}

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
int __fastcall conn_and_send(void *buf)
{
int result; // eax
int v2; // ebx

result = conn();
if ( result != -1 )
{
v2 = result;
send(result, buf, 0x10uLL, 0);
result = close(v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(void *buf)
{
int result; // eax
int v2; // ebx

result = func1();
if ( result != -1 )
{
v2 = result;
send(result, buf, 0x10uLL, 0);
result = close(v2);
}
return result;
}

original_code:
void conn_and_send(int64_t cmd[2]) {
 int fd = conn();
 if (fd == -1) return;
 send(fd, (void *)cmd, sizeof(int64_t)*2, 0);
 close(fd);
}

canonical_original_code:
void conn_and_send(long cmd[2]) {
 int fd = conn();
 if (fd == -1) return;
 send(fd, (void *)cmd, sizeof(long)*2, 0);
 close(fd);
}

variable_types:
cmd
long [2]


decompiled_code:
ssize_t __fastcall send_add(int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = 20LL;
v3[1] = a2;
return send(a1, v3, 0x10uLL, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = 20LL;
v3[1] = a2;
return send(a1, v3, 0x10uLL, 0);
}

original_code:
void send_add(int fd, int64_t idx) {
 int64_t cmd[] = { CMD_ADD, idx };
 send(fd, (void *)cmd, sizeof(cmd), 0);
 return;
}

canonical_original_code:
void send_add(int fd, long idx) {
 long cmd[] = { CMD_ADD, idx };
 send(fd, (void *)cmd, sizeof(cmd), 0);
 return;
}

variable_types: idx long

variable_types:
cmd
long []


oomp

decompiled_code:
void __fastcall oomp(__int64 a1)
{
if ( !a1 )
{
perror("Out of memory");
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
if ( !a1 )
{
perror("Out of memory");
exit(1);
}
}

original_code:
void oomp(void *ptr) {
 if (ptr == ((void *)0)) {
  perror("Out of memory");
  exit(1);
 }
}

variable_types:
ptr
void *


strstart

decompiled_code:
bool __fastcall strstart(char *s2, char *s1)
{
size_t v2; // rax

v2 = strlen(s1);
return strncmp(s1, s2, v2) == 0;
}

canonical_decompiled_code:
bool __fastcall func2(char *s2, char *s1)
{
size_t v2; // rax

v2 = strlen(s1);
return strncmp(s1, s2, v2) == 0;
}

original_code:
_Bool strstart(const char *haystack, const char *needle) {
    return strncmp(needle, haystack, strlen(needle)) == 0;
}

canonical_original_code:
_Bool strstart(char *haystack, char *needle) {
    return strncmp(needle, haystack, strlen(needle)) == 0;
}

variable_types:
haystack
char *

variable_types:
needle
char *