decompiled_code:
int print_usage()
{
puts("mosquitto_sub is a simple mqtt client that will subscribe to a single topic and print all messages it receives.\n");
puts("Usage: mosquitto_sub [-c] [-i id] [-k keepalive] [-p port] [-q qos] [-v] -t topic ...");
puts(" [-u username [--pw password]]");
puts(" [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]\n");
puts(" -c : disable 'clean session' (store subscription and pending messages when client disconnects).");
puts(" -d : enable debug messages.");
puts(" -h : mqtt host to connect to. Defaults to localhost.");
puts(" -i : id to use for this client. Defaults to mosquitto_sub_ appended with the process id.");
puts(" -k : keep alive in seconds for this client. Defaults to 60.");
puts(" -p : network port to connect to. Defaults to 1883.");
puts(" -q : quality of service level to use for the subscription. Defaults to 0.");
puts(" -t : mqtt topic to subscribe to. May be repeated multiple times.");
puts(" -u : provide a username (requires MQTT 3.1 broker)");
puts(" -v : print published messages verbosely.");
puts(" --pw : provide a password (requires MQTT 3.1 broker)");
puts(" --will-payload : payload for the client Will, which is sent by the broker in case of");
puts(" unexpected disconnection. If not given and will-topic is set, a zero");
puts(" length message will be sent.");
puts(" --will-qos : QoS level for the client Will.");
puts(" --will-retain : if given, make the client Will retained.");
return puts(" --will-topic : the topic on which to publish the client Will.");
}

canonical_decompiled_code:
int func3()
{
puts("mosquitto_sub is a simple mqtt client that will subscribe to a single topic and print all messages it receives.\n");
puts("Usage: mosquitto_sub [-c] [-i id] [-k keepalive] [-p port] [-q qos] [-v] -t topic ...");
puts(" [-u username [--pw password]]");
puts(" [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]\n");
puts(" -c : disable 'clean session' (store subscription and pending messages when client disconnects).");
puts(" -d : enable debug messages.");
puts(" -h : mqtt host to connect to. Defaults to localhost.");
puts(" -i : id to use for this client. Defaults to mosquitto_sub_ appended with the process id.");
puts(" -k : keep alive in seconds for this client. Defaults to 60.");
puts(" -p : network port to connect to. Defaults to 1883.");
puts(" -q : quality of service level to use for the subscription. Defaults to 0.");
puts(" -t : mqtt topic to subscribe to. May be repeated multiple times.");
puts(" -u : provide a username (requires MQTT 3.1 broker)");
puts(" -v : print published messages verbosely.");
puts(" --pw : provide a password (requires MQTT 3.1 broker)");
puts(" --will-payload : payload for the client Will, which is sent by the broker in case of");
puts(" unexpected disconnection. If not given and will-topic is set, a zero");
puts(" length message will be sent.");
puts(" --will-qos : QoS level for the client Will.");
puts(" --will-retain : if given, make the client Will retained.");
return puts(" --will-topic : the topic on which to publish the client Will.");
}

original_code:
void print_usage(void)
{
 printf("mosquitto_sub is a simple mqtt client that will subscribe to a single topic and print all messages it receives.\n\n");
 printf("Usage: mosquitto_sub [-c] [-i id] [-k keepalive] [-p port] [-q qos] [-v] -t topic ...\n");
 printf("                     [-u username [--pw password]]\n");
 printf("                     [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]\n\n");
 printf(" -c : disable 'clean session' (store subscription and pending messages when client disconnects).\n");
 printf(" -d : enable debug messages.\n");
 printf(" -h : mqtt host to connect to. Defaults to localhost.\n");
 printf(" -i : id to use for this client. Defaults to mosquitto_sub_ appended with the process id.\n");
 printf(" -k : keep alive in seconds for this client. Defaults to 60.\n");
 printf(" -p : network port to connect to. Defaults to 1883.\n");
 printf(" -q : quality of service level to use for the subscription. Defaults to 0.\n");
 printf(" -t : mqtt topic to subscribe to. May be repeated multiple times.\n");
 printf(" -u : provide a username (requires MQTT 3.1 broker)\n");
 printf(" -v : print published messages verbosely.\n");
 printf(" --pw : provide a password (requires MQTT 3.1 broker)\n");
 printf(" --will-payload : payload for the client Will, which is sent by the broker in case of\n");
 printf("                  unexpected disconnection. If not given and will-topic is set, a zero\n");
 printf("                  length message will be sent.\n");
 printf(" --will-qos : QoS level for the client Will.\n");
 printf(" --will-retain : if given, make the client Will retained.\n");
 printf(" --will-topic : the topic on which to publish the client Will.\n");
}

canonical_original_code:
void print_usage()
{
 printf("mosquitto_sub is a simple mqtt client that will subscribe to a single topic and print all messages it receives.\n\n");
 printf("Usage: mosquitto_sub [-c] [-i id] [-k keepalive] [-p port] [-q qos] [-v] -t topic ...\n");
 printf("                     [-u username [--pw password]]\n");
 printf("                     [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]\n\n");
 printf(" -c : disable 'clean session' (store subscription and pending messages when client disconnects).\n");
 printf(" -d : enable debug messages.\n");
 printf(" -h : mqtt host to connect to. Defaults to localhost.\n");
 printf(" -i : id to use for this client. Defaults to mosquitto_sub_ appended with the process id.\n");
 printf(" -k : keep alive in seconds for this client. Defaults to 60.\n");
 printf(" -p : network port to connect to. Defaults to 1883.\n");
 printf(" -q : quality of service level to use for the subscription. Defaults to 0.\n");
 printf(" -t : mqtt topic to subscribe to. May be repeated multiple times.\n");
 printf(" -u : provide a username (requires MQTT 3.1 broker)\n");
 printf(" -v : print published messages verbosely.\n");
 printf(" --pw : provide a password (requires MQTT 3.1 broker)\n");
 printf(" --will-payload : payload for the client Will, which is sent by the broker in case of\n");
 printf("                  unexpected disconnection. If not given and will-topic is set, a zero\n");
 printf("                  length message will be sent.\n");
 printf(" --will-qos : QoS level for the client Will.\n");
 printf(" --will-retain : if given, make the client Will retained.\n");
 printf(" --will-topic : the topic on which to publish the client Will.\n");
}


repo: adamvr/mosquitto-homebrew-mods

decompiled_code:
const char *__fastcall mqtt3_command_to_string(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 == 0x80 )
return "SUBSCRIBE";
if ( a1 > 0x80u )
{
if ( a1 == 0xC0 )
{
result = "PINGREQ";
}
else if ( a1 <= 0xC0u )
{
result = "UNSUBSCRIBE";
if ( a1 != 0xA0 )
{
if ( a1 == 0xB0 )
{
result = "UNSUBACK";
}
else
{
result = "UNKNOWN";
if ( a1 == 0x90 )
result = "SUBACK";
}
}
}
else
{
result = "PINGRESP";
if ( a1 != 0xD0 )
{
result = "UNKNOWN";
if ( a1 == 0xE0 )
result = "DISCONNECT";
}
}
}
else if ( a1 == 64 )
{
result = "PUBACK";
}
else if ( a1 <= 0x40u )
{
result = "CONNACK";
if ( a1 != 32 )
{
if ( a1 == 48 )
{
result = "PUBLISH";
}
else
{
result = "UNKNOWN";
if ( a1 == 16 )
result = "CONNECT";
}
}
}
else
{
result = "PUBREL";
if ( a1 != 96 )
{
if ( a1 == 112 )
{
result = "PUBCOMP";
}
else
{
result = "UNKNOWN";
if ( a1 == 80 )
result = "PUBREC";
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 == 0x80 )
return "SUBSCRIBE";
if ( a1 > 0x80u )
{
if ( a1 == 0xC0 )
{
result = "PINGREQ";
}
else if ( a1 <= 0xC0u )
{
result = "UNSUBSCRIBE";
if ( a1 != 0xA0 )
{
if ( a1 == 0xB0 )
{
result = "UNSUBACK";
}
else
{
result = "UNKNOWN";
if ( a1 == 0x90 )
result = "SUBACK";
}
}
}
else
{
result = "PINGRESP";
if ( a1 != 0xD0 )
{
result = "UNKNOWN";
if ( a1 == 0xE0 )
result = "DISCONNECT";
}
}
}
else if ( a1 == 64 )
{
result = "PUBACK";
}
else if ( a1 <= 0x40u )
{
result = "CONNACK";
if ( a1 != 32 )
{
if ( a1 == 48 )
{
result = "PUBLISH";
}
else
{
result = "UNKNOWN";
if ( a1 == 16 )
result = "CONNECT";
}
}
}
else
{
result = "PUBREL";
if ( a1 != 96 )
{
if ( a1 == 112 )
{
result = "PUBCOMP";
}
else
{
result = "UNKNOWN";
if ( a1 == 80 )
result = "PUBREC";
}
}
}
return result;
}

original_code:
const char *mqtt3_command_to_string(uint8_t command)
{
 switch(command){
  case 0x20:
   return "CONNACK";
  case 0x10:
   return "CONNECT";
  case 0xE0:
   return "DISCONNECT";
  case 0xC0:
   return "PINGREQ";
  case 0xD0:
   return "PINGRESP";
  case 0x40:
   return "PUBACK";
  case 0x70:
   return "PUBCOMP";
  case 0x30:
   return "PUBLISH";
  case 0x50:
   return "PUBREC";
  case 0x60:
   return "PUBREL";
  case 0x90:
   return "SUBACK";
  case 0x80:
   return "SUBSCRIBE";
  case 0xB0:
   return "UNSUBACK";
  case 0xA0:
   return "UNSUBSCRIBE";
 }
 return "UNKNOWN";
}

canonical_original_code:
char *mqtt3_command_to_string(unsigned char command)
{
 switch(command){
  case 0x20:
   return "CONNACK";
  case 0x10:
   return "CONNECT";
  case 0xE0:
   return "DISCONNECT";
  case 0xC0:
   return "PINGREQ";
  case 0xD0:
   return "PINGRESP";
  case 0x40:
   return "PUBACK";
  case 0x70:
   return "PUBCOMP";
  case 0x30:
   return "PUBLISH";
  case 0x50:
   return "PUBREC";
  case 0x60:
   return "PUBREL";
  case 0x90:
   return "SUBACK";
  case 0x80:
   return "SUBSCRIBE";
  case 0xB0:
   return "UNSUBACK";
  case 0xA0:
   return "UNSUBSCRIBE";
 }
 return "UNKNOWN";
}

variable_types:
command
unsigned char

return_type: char *


decompiled_code:
void __fastcall mqtt3_check_keepalive(__int64 a1)
{
if ( a1 && *(_DWORD *)a1 != -1 && time(0LL) - *(_QWORD *)(a1 + 48) >= *(unsigned __int16 *)(a1 + 32) )
{
if ( *(_DWORD *)(a1 + 36) == 1 )
mqtt3_raw_pingreq(a1);
else
mqtt3_socket_close(a1);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
if ( a1 && *(_DWORD *)a1 != -1 && time(0LL) - *(_QWORD *)(a1 + 48) >= *(unsigned __int16 *)(a1 + 32) )
{
if ( *(_DWORD *)(a1 + 36) == 1 )
mqtt3_raw_pingreq(a1);
else
mqtt3_socket_close(a1);
}
}

original_code:
void mqtt3_check_keepalive(mqtt3_context *context)
{
 if(context && context->core.sock != -1 && time(((void *)0)) - context->core.last_msg_out >= context->core.keepalive){
  if(context->core.state == mosq_cs_connected){
   mqtt3_raw_pingreq(context);
  }else{
   mqtt3_socket_close(context);
  }
 }
}

canonical_original_code:
void mqtt3_check_keepalive(struct _mqtt3_context *context)
{
 if(context && context->core.sock != -1 && time(((void *)0)) - context->core.last_msg_out >= context->core.keepalive){
  if(context->core.state == mosq_cs_connected){
   mqtt3_raw_pingreq(context);
  }else{
   mqtt3_socket_close(context);
  }
 }
}

variable_types: struct _mqtt3_context { struct _mosquitto_core { int sock; char *id; char *username; char *password; unsigned short keepalive; enum mosquitto_client_state { mosq_cs_new=0, mosq_cs_connected=1, mosq_cs_disconnecting=2 } state; long last_msg_in; long last_msg_out; unsigned short last_mid; struct _mosquitto_packet { unsigned char command; unsigned char command_saved; unsigned char have_remaining; unsigned char remaining_count; unsigned short mid; unsigned int remaining_mult; unsigned int remaining_length; unsigned int to_process; unsigned int pos; unsigned char *payload; struct _mosquitto_packet *next; } in_packet; struct _mosquitto_packet *out_packet; struct mosquitto_message { unsigned short mid; char *topic; unsigned char *payload; unsigned int payloadlen; int qos; _Bool retain; } *will; } core; _Bool clean_session; _Bool duplicate; char *address; struct _mqtt3_bridge { char *name; char *address; unsigned short port; int keepalive; _Bool clean_session; struct _mqtt3_bridge_topic { char *topic; enum mqtt3_bridge_direction { bd_out=0, bd_in=1, bd_both=2 } direction; } *topics; int topic_count; long restart_t; char *username; char *password; } *bridge; struct _mosquitto_client_msg { struct _mosquitto_client_msg *next; struct mosquitto_msg_store { struct mosquitto_msg_store *next; unsigned long db_id; int ref_count; char *source_id; unsigned short source_mid; struct mosquitto_message msg; } *store; unsigned short mid; int qos; _Bool retain; long timestamp; enum mosquitto_msg_direction { mosq_md_in=0, mosq_md_out=1 } direction; enum mqtt3_msg_state { ms_invalid=0, ms_publish=1, ms_publish_puback=2, ms_wait_puback=3, ms_publish_pubrec=4, ms_wait_pubrec=5, ms_resend_pubrel=6, ms_wait_pubrel=7, ms_resend_pubcomp=8, ms_wait_pubcomp=9, ms_resend_pubrec=10, ms_queued=11 } state; _Bool dup; } *msgs; } *

return_type: void

user_defined_types: struct _mqtt3_context { struct _mosquitto_core core; _Bool clean_session; _Bool duplicate; char *address; struct _mqtt3_bridge *bridge; struct _mosquitto_client_msg *msgs; }

user_defined_types: struct _mosquitto_core { int sock; char *id; char *username; char *password; unsigned short keepalive; enum mosquitto_client_state state; long last_msg_in; long last_msg_out; unsigned short last_mid; struct _mosquitto_packet in_packet; struct _mosquitto_packet *out_packet; struct mosquitto_message *will; }

user_defined_types: struct _mqtt3_bridge { char *name; char *address; unsigned short port; int keepalive; _Bool clean_session; struct _mqtt3_bridge_topic *topics; int topic_count; long restart_t; char *username; char *password; }

user_defined_types: struct _mosquitto_client_msg { struct _mosquitto_client_msg *next; struct mosquitto_msg_store *store; unsigned short mid; int qos; _Bool retain; long timestamp; enum mosquitto_msg_direction direction; enum mqtt3_msg_state state; _Bool dup; }

user_defined_types: struct _mqtt3_bridge_topic { char *topic; enum mqtt3_bridge_direction direction; }


loop

decompiled_code:
__int64 __fastcall mosquittopp::loop(mosquittopp *this)
{
return mosquitto_loop();
}

canonical_decompiled_code:
__int64 __fastcall mosquittopp::func20(mosquittopp *this)
{
return mosquitto_loop();
}

original_code:
int loop(mqtt3_config *config, int *listensock, int listensock_count, int listener_max)
{
 time_t start_time = time(((void *)0));
 time_t last_backup = time(((void *)0));
 time_t last_store_clean = time(((void *)0));
 time_t now;
 int fdcount;
 sigset_t sigblock, origsig;
 int i;
 struct pollfd *pollfds = ((void *)0);
 unsigned int pollfd_count = 0;
 int new_clients = 1;
 int client_max = 0;
 unsigned int sock_max = 0;
 sigemptyset(&sigblock);
 sigaddset(&sigblock, 2);
 while(run){
  mqtt3_db_sys_update(&int_db, config->sys_interval, start_time);
  if(new_clients){
   client_max = -1;
   for(i=0; i<int_db.context_count; i++){
    if(int_db.contexts[i] && int_db.contexts[i]->core.sock != -1 && int_db.contexts[i]->core.sock > sock_max){
     client_max = int_db.contexts[i]->core.sock;
    }
   }
   new_clients = 0;
  }
  if(client_max > listener_max){
   sock_max = client_max;
  }else{
   sock_max = listener_max;
  }
  if(sock_max+1 > pollfd_count){
   pollfd_count = sock_max+1;
   pollfds = _mosquitto_realloc(pollfds, sizeof(struct pollfd)*pollfd_count);
   if(!pollfds){
    mqtt3_log_printf(0x08, "Error: Out of memory.");
    return 1;
   }
  }
  memset(pollfds, -1, sizeof(struct pollfd)*pollfd_count);
  for(i=0; i<listensock_count; i++){
   pollfds[listensock[i]].fd = listensock[i];
   pollfds[listensock[i]].events = 0x001;
   pollfds[listensock[i]].revents = 0;
  }
  now = time(((void *)0));
  for(i=0; i<int_db.context_count; i++){
   if(int_db.contexts[i]){
    if(int_db.contexts[i]->core.sock != -1){
     if(int_db.contexts[i]->bridge){
      mqtt3_check_keepalive(int_db.contexts[i]);
     }
     if(!(int_db.contexts[i]->core.keepalive) || now - int_db.contexts[i]->core.last_msg_in < (time_t)(int_db.contexts[i]->core.keepalive)*3/2){
      if(mqtt3_db_message_write(int_db.contexts[i])){
      }
      pollfds[int_db.contexts[i]->core.sock].fd = int_db.contexts[i]->core.sock;
      pollfds[int_db.contexts[i]->core.sock].events = 0x001;
      pollfds[int_db.contexts[i]->core.sock].revents = 0;
      if(int_db.contexts[i]->core.out_packet){
       pollfds[int_db.contexts[i]->core.sock].events |= 0x004;
      }
     }else{
      mqtt3_log_printf(0x02, "Client %s has exceeded timeout, disconnecting.", int_db.contexts[i]->core.id);
      if(int_db.contexts[i]->bridge || int_db.contexts[i]->clean_session == 0){
       mqtt3_socket_close(int_db.contexts[i]);
      }else{
       mqtt3_context_cleanup(&int_db, int_db.contexts[i], 1);
       int_db.contexts[i] = ((void *)0);
      }
     }
    }else{
     if(int_db.contexts[i]->bridge){
      if(!int_db.contexts[i]->bridge->restart_t){
       int_db.contexts[i]->bridge->restart_t = time(((void *)0))+30;
      }else{
       if(time(((void *)0)) > int_db.contexts[i]->bridge->restart_t){
        int_db.contexts[i]->bridge->restart_t = 0;
        mqtt3_bridge_connect(&int_db, int_db.contexts[i]);
       }
      }
     }else{
      if(int_db.contexts[i]->clean_session == 1){
       mqtt3_context_cleanup(&int_db, int_db.contexts[i], 1);
       int_db.contexts[i] = ((void *)0);
      }
     }
    }
   }
  }
  mqtt3_db_message_timeout_check(&int_db, config->retry_interval);
  sigprocmask(2, &sigblock, &origsig);
  fdcount = poll(pollfds, pollfd_count, 1000);
  sigprocmask(2, &origsig, ((void *)0));
  if(fdcount == -1){
   loop_handle_errors(pollfds);
  }else{
   loop_handle_reads_writes(pollfds);
   for(i=0; i<listensock_count; i++){
    if(pollfds[listensock[i]].revents & (0x001 | 0x002)){
     new_clients = 1;
     while(mqtt3_socket_accept(&int_db.contexts, &int_db.context_count, listensock[i]) != -1){
     }
    }
   }
  }
  if(config->persistence && config->autosave_interval){
   if(last_backup + config->autosave_interval < now){
    mqtt3_db_backup(&int_db, 0, 0);
    last_backup = time(((void *)0));
   }
  }
  if(!config->store_clean_interval || last_store_clean + config->store_clean_interval < now){
   mqtt3_db_store_clean(&int_db);
   last_store_clean = time(((void *)0));
  }
 }
 if(pollfds) _mosquitto_free(pollfds);
 return 0;
}

canonical_original_code:
int loop(struct mqtt3_config *config, int *listensock, int listensock_count, int listener_max)
{
 long start_time = time(((void *)0));
 long last_backup = time(((void *)0));
 long last_store_clean = time(((void *)0));
 long now;
 int fdcount;
 struct __sigset_t sigblock; struct __sigset_t origsig;
 int i;
 struct pollfd *pollfds = ((void *)0);
 unsigned int pollfd_count = 0;
 int new_clients = 1;
 int client_max = 0;
 unsigned int sock_max = 0;
 sigemptyset(&sigblock);
 sigaddset(&sigblock, 2);
 while(run){
  mqtt3_db_sys_update(&int_db, config->sys_interval, start_time);
  if(new_clients){
   client_max = -1;
   for(i=0; i<int_db.context_count; i++){
    if(int_db.contexts[i] && int_db.contexts[i]->core.sock != -1 && int_db.contexts[i]->core.sock > sock_max){
     client_max = int_db.contexts[i]->core.sock;
    }
   }
   new_clients = 0;
  }
  if(client_max > listener_max){
   sock_max = client_max;
  }else{
   sock_max = listener_max;
  }
  if(sock_max+1 > pollfd_count){
   pollfd_count = sock_max+1;
   pollfds = _mosquitto_realloc(pollfds, sizeof(struct pollfd)*pollfd_count);
   if(!pollfds){
    mqtt3_log_printf(0x08, "Error: Out of memory.");
    return 1;
   }
  }
  memset(pollfds, -1, sizeof(struct pollfd)*pollfd_count);
  for(i=0; i<listensock_count; i++){
   pollfds[listensock[i]].fd = listensock[i];
   pollfds[listensock[i]].events = 0x001;
   pollfds[listensock[i]].revents = 0;
  }
  now = time(((void *)0));
  for(i=0; i<int_db.context_count; i++){
   if(int_db.contexts[i]){
    if(int_db.contexts[i]->core.sock != -1){
     if(int_db.contexts[i]->bridge){
      mqtt3_check_keepalive(int_db.contexts[i]);
     }
     if(!(int_db.contexts[i]->core.keepalive) || now - int_db.contexts[i]->core.last_msg_in < (time_t)(int_db.contexts[i]->core.keepalive)*3/2){
      if(mqtt3_db_message_write(int_db.contexts[i])){
      }
      pollfds[int_db.contexts[i]->core.sock].fd = int_db.contexts[i]->core.sock;
      pollfds[int_db.contexts[i]->core.sock].events = 0x001;
      pollfds[int_db.contexts[i]->core.sock].revents = 0;
      if(int_db.contexts[i]->core.out_packet){
       pollfds[int_db.contexts[i]->core.sock].events |= 0x004;
      }
     }else{
      mqtt3_log_printf(0x02, "Client %s has exceeded timeout, disconnecting.", int_db.contexts[i]->core.id);
      if(int_db.contexts[i]->bridge || int_db.contexts[i]->clean_session == 0){
       mqtt3_socket_close(int_db.contexts[i]);
      }else{
       mqtt3_context_cleanup(&int_db, int_db.contexts[i], 1);
       int_db.contexts[i] = ((void *)0);
      }
     }
    }else{
     if(int_db.contexts[i]->bridge){
      if(!int_db.contexts[i]->bridge->restart_t){
       int_db.contexts[i]->bridge->restart_t = time(((void *)0))+30;
      }else{
       if(time(((void *)0)) > int_db.contexts[i]->bridge->restart_t){
        int_db.contexts[i]->bridge->restart_t = 0;
        mqtt3_bridge_connect(&int_db, int_db.contexts[i]);
       }
      }
     }else{
      if(int_db.contexts[i]->clean_session == 1){
       mqtt3_context_cleanup(&int_db, int_db.contexts[i], 1);
       int_db.contexts[i] = ((void *)0);
      }
     }
    }
   }
  }
  mqtt3_db_message_timeout_check(&int_db, config->retry_interval);
  sigprocmask(2, &sigblock, &origsig);
  fdcount = poll(pollfds, pollfd_count, 1000);
  sigprocmask(2, &origsig, ((void *)0));
  if(fdcount == -1){
   loop_handle_errors(pollfds);
  }else{
   loop_handle_reads_writes(pollfds);
   for(i=0; i<listensock_count; i++){
    if(pollfds[listensock[i]].revents & (0x001 | 0x002)){
     new_clients = 1;
     while(mqtt3_socket_accept(&int_db.contexts, &int_db.context_count, listensock[i]) != -1){
     }
    }
   }
  }
  if(config->persistence && config->autosave_interval){
   if(last_backup + config->autosave_interval < now){
    mqtt3_db_backup(&int_db, 0, 0);
    last_backup = time(((void *)0));
   }
  }
  if(!config->store_clean_interval || last_store_clean + config->store_clean_interval < now){
   mqtt3_db_store_clean(&int_db);
   last_store_clean = time(((void *)0));
  }
 }
 if(pollfds) _mosquitto_free(pollfds);
 return 0;
}

variable_types: struct mqtt3_config { int autosave_interval; _Bool daemon; struct _mqtt3_listener { int fd; char *host; unsigned short port; int max_connections; char *mount_point; } default_listener; struct _mqtt3_listener *listeners; int listener_count; int log_dest; int log_type; int max_connections; _Bool persistence; char *persistence_location; char *persistence_file; int retry_interval; int store_clean_interval; int sys_interval; char *pid_file; char *user; struct _mqtt3_bridge { char *name; char *address; unsigned short port; int keepalive; _Bool clean_session; struct _mqtt3_bridge_topic { char *topic; enum mqtt3_bridge_direction { bd_out=0, bd_in=1, bd_both=2 } direction; } *topics; int topic_count; long restart_t; char *username; char *password; } *bridges; int bridge_count; } *

variable_types:
listensock
int *

variable_types: now long

variable_types: fdcount int

variable_types: struct __sigset_t { unsigned long __val[-1]; }

variable_types: i int

variable_types: struct pollfd { int fd; short events; short revents; } *

return_type: int

user_defined_types: struct mqtt3_config { int autosave_interval; _Bool daemon; struct _mqtt3_listener default_listener; struct _mqtt3_listener *listeners; int listener_count; int log_dest; int log_type; int max_connections; _Bool persistence; char *persistence_location; char *persistence_file; int retry_interval; int store_clean_interval; int sys_interval; char *pid_file; char *user; struct _mqtt3_bridge *bridges; int bridge_count; }


repo: adanaila/ctrlinux

decompiled_code:
void timer_on_handler()
{
int v0; // ebx
char buf; // [rsp+Fh] [rbp-69h] BYREF
struct timespec tp; // [rsp+10h] [rbp-68h] BYREF
char s[88]; // [rsp+20h] [rbp-58h] BYREF

buf = 0;
if ( pthread_mutex_lock(&mtx) )
perror("pthread_mutex_lock");
if ( clock_gettime(1, &tp) == -1 )
perror("clock_gettime");
buf = gpio_val + 48;
sprintf(s, "TIMER_ON %ld s %ld ns \n", tp.tv_sec, tp.tv_nsec);
if ( (unsigned int)write(fd_gpio, &buf, 1uLL) == -1 )
perror("write");
v0 = gpio_val;
if ( gpio_val )
{
new_time.it_interval.tv_nsec = time_on;
new_time.it_value.tv_nsec = time_on;
}
else
{
new_time.it_interval.tv_nsec = time_off;
new_time.it_value.tv_nsec = time_off;
}
if ( timer_settime(on_timer, 0, &new_time, &old_time) == -1 )
{
perror("timer_setttime");
v0 = gpio_val;
}
gpio_val = v0 ^ 1;
if ( pthread_mutex_unlock(&mtx) )
perror("pthread_mutex_unlock");
}

canonical_decompiled_code:
void func7()
{
int v0; // ebx
char buf; // [rsp+Fh] [rbp-69h] BYREF
struct timespec tp; // [rsp+10h] [rbp-68h] BYREF
char s[88]; // [rsp+20h] [rbp-58h] BYREF

buf = 0;
if ( pthread_mutex_lock(&mtx) )
perror("pthread_mutex_lock");
if ( clock_gettime(1, &tp) == -1 )
perror("clock_gettime");
buf = gpio_val + 48;
sprintf(s, "TIMER_ON %ld s %ld ns \n", tp.tv_sec, tp.tv_nsec);
if ( (unsigned int)write(fd_gpio, &buf, 1uLL) == -1 )
perror("write");
v0 = gpio_val;
if ( gpio_val )
{
new_time.it_interval.tv_nsec = time_on;
new_time.it_value.tv_nsec = time_on;
}
else
{
new_time.it_interval.tv_nsec = time_off;
new_time.it_value.tv_nsec = time_off;
}
if ( timer_settime(on_timer, 0, &new_time, &old_time) == -1 )
{
perror("timer_setttime");
v0 = gpio_val;
}
gpio_val = v0 ^ 1;
if ( pthread_mutex_unlock(&mtx) )
perror("pthread_mutex_unlock");
}

original_code:
void timer_on_handler (int signum)
{
    struct timespec tp;
    char buffer [80];
    char gpio_out_val = 0;
    int ret_val = 0;
    ret_val = pthread_mutex_lock(&mtx);
    if (0 != ret_val)
        perror("pthread_mutex_lock");
    if (clock_gettime (1, &tp) == -1)
        perror ("clock_gettime");
    gpio_out_val = gpio_val + '0';
    sprintf (buffer, "TIMER_ON  %ld s %ld ns \n", tp.tv_sec, tp.tv_nsec );
    if(0)printf("%s", buffer);
    ret_val = write(fd_gpio,&gpio_out_val,1);
    if (ret_val == -1)
        perror("write");
    if (gpio_val)
    {
        if(0)printf("ON Cycle setting off interval to %lu\n",time_off);
        new_time.it_interval.tv_nsec = time_on;
        new_time.it_value.tv_nsec = time_on;
    }
    else
    {
        if(0)printf("OFF Cycle setting on interval to %lu\n",time_on);
        new_time.it_interval.tv_nsec = time_off;
        new_time.it_value.tv_nsec = time_off;
    }
    if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
        perror("timer_setttime");
    gpio_val ^= 1;
    ret_val = pthread_mutex_unlock(&mtx);
    if (0 != ret_val)
        perror("pthread_mutex_unlock");
}

canonical_original_code:
void timer_on_handler(int signum)
{
    struct timespec tp;
    char buffer[80];
    char gpio_out_val = 0;
    int ret_val = 0;
    ret_val = pthread_mutex_lock(&mtx);
    if (0 != ret_val)
        perror("pthread_mutex_lock");
    if (clock_gettime (1, &tp) == -1)
        perror ("clock_gettime");
    gpio_out_val = gpio_val + '0';
    sprintf (buffer, "TIMER_ON  %ld s %ld ns \n", tp.tv_sec, tp.tv_nsec );
    if(0)printf("%s", buffer);
    ret_val = write(fd_gpio,&gpio_out_val,1);
    if (ret_val == -1)
        perror("write");
    if (gpio_val)
    {
        if(0)printf("ON Cycle setting off interval to %lu\n",time_off);
        new_time.it_interval.tv_nsec = time_on;
        new_time.it_value.tv_nsec = time_on;
    }
    else
    {
        if(0)printf("OFF Cycle setting on interval to %lu\n",time_on);
        new_time.it_interval.tv_nsec = time_off;
        new_time.it_value.tv_nsec = time_off;
    }
    if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
        perror("timer_setttime");
    gpio_val ^= 1;
    ret_val = pthread_mutex_unlock(&mtx);
    if (0 != ret_val)
        perror("pthread_mutex_unlock");
}

variable_types: signum int

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

variable_types:
buffer
char [80]


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct sigevent evp; // [rsp+4h] [rbp-E8h] BYREF
struct sigaction v4; // [rsp+44h] [rbp-A8h] BYREF

*(_OWORD *)&evp.sigev_value.sival_int = 0LL;
memset(&v4, 0, sizeof(v4));
*(_OWORD *)evp._sigev_un._pad = 0LL;
*((_OWORD *)&evp._sigev_un._sigev_thread + 1) = 0LL;
*((_OWORD *)&evp._sigev_un._sigev_thread + 2) = 0LL;
fd_gpio = open("/sys/class/gpio/gpio38/value", 1052674, envp);
if ( fd_gpio < 0 )
perror("open");
*(_QWORD *)&evp.sigev_signo = 10LL;
v4.sa_handler = (__sighandler_t)timer_on_handler;
if ( sigaction(10, &v4, 0LL) == -1 )
perror("sigaction");
if ( timer_create(0, &evp, &on_timer) == -1 )
perror("timer_create");
new_time.it_interval.tv_nsec = time_on;
new_time.it_value.tv_nsec = time_on;
if ( timer_settime(on_timer, 0, &new_time, &old_time) == -1 )
perror("timer_setttime");
printf("Finished setting timer, starting PWM at 50 percent. Enter new val 1-100 for");
while ( 1 )
__isoc99_scanf();
}

original_code:
int main ()
{
    char user_input[10]= {0};
    int user_val = 0, ret_val = 0;
    struct timespec res;
    struct sigevent on_event = {0};
    struct sigaction on_action = {0};
    fd_gpio = open("/sys/class/gpio/gpio38/value",02 | 04010000);
    if ( fd_gpio < 0)
       perror("open");
    on_event.sigev_signo = 10;
    on_event.sigev_notify = SIGEV_SIGNAL;
    on_action.__sigaction_handler.sa_handler = timer_on_handler;
    if(-1 == sigaction(10,&on_action,((void *)0)))
        perror("sigaction");
    if (-1 == timer_create(0 ,&on_event, &on_timer))
        perror("timer_create");
    new_time.it_interval.tv_nsec = time_on;
    new_time.it_value.tv_nsec = time_on;
    if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
        perror("timer_setttime");
    printf("Finished setting timer, starting PWM at 50 percent. Enter new val 1-100 for",
   "new modulation value\n");
    while (1)
    {
        scanf("%d",&user_val);
        if (0 < user_val && user_val <= 100)
        {
   ret_val = pthread_mutex_lock(&mtx);
   gpio_val = 1;
   if (0 != ret_val)
    perror("pthread_mutex_lock");
            if(0)printf("User val is %d\n",user_val);
            time_on = (unsigned int)(1000000.0 * (user_val/100.0));
            time_off = (unsigned int)(1000000.0 * (1 - user_val/100.0));
            if(0)printf("Calculated time periods time_on: %lu, time_off %lu\n",time_on,time_off);
            if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
                perror("timer_setttime");
   ret_val = pthread_mutex_unlock(&mtx);
   if (0 != ret_val)
    perror("pthread_mutex_unlock");
        }
        user_val = 0;
    };
    return 0;
}

canonical_original_code:
int main()
{
    char user_input[10] = {0};
    int user_val = 0; int ret_val = 0;
    struct timespec res;
    struct sigevent on_event = {0};
    struct sigaction on_action = {0};
    fd_gpio = open("/sys/class/gpio/gpio38/value",02 | 04010000);
    if ( fd_gpio < 0)
       perror("open");
    on_event.sigev_signo = 10;
    on_event.sigev_notify = SIGEV_SIGNAL;
    on_action.__sigaction_handler.sa_handler = timer_on_handler;
    if(-1 == sigaction(10,&on_action,((void *)0)))
        perror("sigaction");
    if (-1 == timer_create(0 ,&on_event, &on_timer))
        perror("timer_create");
    new_time.it_interval.tv_nsec = time_on;
    new_time.it_value.tv_nsec = time_on;
    if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
        perror("timer_setttime");
    printf("Finished setting timer, starting PWM at 50 percent. Enter new val 1-100 for",
   "new modulation value\n");
    while (1)
    {
        scanf("%d",&user_val);
        if (0 < user_val && user_val <= 100)
        {
   ret_val = pthread_mutex_lock(&mtx);
   gpio_val = 1;
   if (0 != ret_val)
    perror("pthread_mutex_lock");
            if(0)printf("User val is %d\n",user_val);
            time_on = (unsigned int)(1000000.0 * (user_val/100.0));
            time_off = (unsigned int)(1000000.0 * (1 - user_val/100.0));
            if(0)printf("Calculated time periods time_on: %lu, time_off %lu\n",time_on,time_off);
            if (-1 == timer_settime(on_timer, 0, &new_time,&old_time))
                perror("timer_setttime");
   ret_val = pthread_mutex_unlock(&mtx);
   if (0 != ret_val)
    perror("pthread_mutex_unlock");
        }
        user_val = 0;
    };
    return 0;
}

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

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

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

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }

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

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


repo: addisonw/mrsync-mac

decompiled_code:
__int64 __fastcall init_missingPages(int a1)
{
int v1; // ebx
_BYTE *v2; // rdx
__int64 v3; // rax

v1 = a1;
nPages = a1;
if ( missingPages )
{
free(missingPages);
v1 = nPages;
}
missingPages = malloc(v1);
v2 = missingPages;
if ( v1 > 0 )
{
v3 = 0LL;
while ( 1 )
{
v2[v3++] = 0;
if ( nPages <= (int)v3 )
break;
v2 = missingPages;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ebx
_BYTE *v2; // rdx
__int64 v3; // rax

v1 = a1;
nPages = a1;
if ( missingPages )
{
free(missingPages);
v1 = nPages;
}
missingPages = malloc(v1);
v2 = missingPages;
if ( v1 > 0 )
{
v3 = 0LL;
while ( 1 )
{
v2[v3++] = 0;
if ( nPages <= (int)v3 )
break;
v2 = missingPages;
}
}
return 0LL;
}

original_code:
int init_missingPages(int n)
{
  int i;
  nPages = n;
  if (missingPages != ((void *)0)) free(missingPages);
  missingPages = malloc(sizeof(char) * nPages);
  for(i=0; i < nPages; ++i)
    missingPages[i] = '\0';
  return 0;
}

variable_types: n int


decompiled_code:
__int64 get_total_pages()
{
return (unsigned int)nPages;
}

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

original_code:
int get_total_pages()
{
  return nPages;
}


decompiled_code:
__int64 missing_pages()
{
_BYTE *v0; // rdx
unsigned int v1; // er8
char *i; // rax
bool v3; // cf

if ( nPages <= 0 )
return 0LL;
v0 = missingPages;
v1 = 0;
for ( i = (char *)missingPages + 1; ; ++i )
{
v3 = *v0 == 0;
v0 = i;
v1 += v3;
if ( i == (char *)missingPages + (unsigned int)(nPages - 1) + 1 )
break;
}
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
_BYTE *v0; // rdx
unsigned int v1; // er8
char *i; // rax
bool v3; // cf

if ( nPages <= 0 )
return 0LL;
v0 = missingPages;
v1 = 0;
for ( i = (char *)missingPages + 1; ; ++i )
{
v3 = *v0 == 0;
v0 = i;
v1 += v3;
if ( i == (char *)missingPages + (unsigned int)(nPages - 1) + 1 )
break;
}
return v1;
}

original_code:
int missing_pages()
{
  int result;
  int i;
  result = 0;
  for(i=0; i < nPages; ++i)
    if ((missingPages[i]) == '\0') ++result;
  return result;
}

variable_types: result int


decompiled_code:
_BOOL8 __fastcall is_missing(int a1)
{
return *((_BYTE *)missingPages + a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return *((_BYTE *)missingPages + a1) == 0;
}

original_code:
int is_missing(int page)
{
  return (missingPages[page] == '\0') ? 1 : 0;
}

variable_types: page int


decompiled_code:
__int64 ask_for_missing_page()
{
unsigned int v0; // er13
__int64 v1; // rbx
int i; // ebp
__int64 v3; // rdi

v0 = missing_pages();
if ( v0 )
{
v1 = 0LL;
for ( i = 0; nPages > (int)v1; ++v1 )
{
if ( !*((_BYTE *)missingPages + v1) )
{
++i;
v3 = 500LL;
if ( v0 == i )
v3 = 600LL;
send_complaint(v3, (unsigned int)(v1 + 1));
usleep(0x1F40u);
}
}
v0 = 1;
}
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // er13
__int64 v1; // rbx
int i; // ebp
__int64 v3; // rdi

v0 = func2();
if ( v0 )
{
v1 = 0LL;
for ( i = 0; nPages > (int)v1; ++v1 )
{
if ( !*((_BYTE *)missingPages + v1) )
{
++i;
v3 = 500LL;
if ( v0 == i )
v3 = 600LL;
send_complaint(v3, (unsigned int)(v1 + 1));
usleep(0x1F40u);
}
}
v0 = 1;
}
return v0;
}

original_code:
int ask_for_missing_page()
{
  int i;
  int n, count;
  n = missing_pages();
  if (n == 0) {
    return 0;
  }
  count = 0;
  for(i=0; i < nPages; ++i) {
    if ( missingPages[i] == '\0' ) {
      ++count;
      send_complaint((count==n) ? 600 : 500, i+1);
      usleep(8000);
    }
  }
  return 1;
}

canonical_original_code:
int ask_for_missing_page()
{
  int i;
  int n; int count;
  n = missing_pages();
  if (n == 0) {
    return 0;
  }
  count = 0;
  for(i=0; i < nPages; ++i) {
    if ( missingPages[i] == '\0' ) {
      ++count;
      send_complaint((count==n) ? 600 : 500, i+1);
      usleep(8000);
    }
  }
  return 1;
}

variable_types: count int


decompiled_code:
int __fastcall complaint_socket(__int64 a1, __int16 a2)
{
int v2; // edx
int result; // eax

if ( verbose > 1 )
fwrite("in send_socket_ip\n", 1uLL, 0x12uLL, stderr);
*(_OWORD *)a1 = 0LL;
*(_WORD *)a1 = 2;
*(_WORD *)(a1 + 2) = _bswap_16(a2);
result = socket(2, 2, v2);
if ( result < 0 )
{
perror("Send socket");
exit(1);
}
return result;
}

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

if ( verbose > 1 )
fwrite("in send_socket_ip\n", 1uLL, 0x12uLL, stderr);
*(_OWORD *)a1 = 0LL;
*(_WORD *)a1 = 2;
*(_WORD *)(a1 + 2) = func0(a2);
result = socket(2, 2, v2);
if ( result < 0 )
{
perror("Send socket");
exit(1);
}
return result;
}

original_code:
int complaint_socket(struct sockaddr_in *addr, int port)
{
  int fd, sockaddr_len;
  sa_family_t family;
  if (verbose>=2) fprintf(stderr, "in send_socket_ip\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  return fd;
}

canonical_original_code:
int complaint_socket(struct sockaddr_in *addr, int port)
{
  int fd; int sockaddr_len;
  unsigned short family;
  if (verbose>=2) fprintf(stderr, "in send_socket_ip\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  return fd;
}

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

variable_types: port int

variable_types: fd int

variable_types:
family
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]; }


decompiled_code:
__int64 __fastcall send_socket(struct sockaddr *addr, const char *a2, unsigned int a3)
{
void *v4; // rdx
int v5; // eax
unsigned int v6; // er12
char v8[104]; // [rsp+0h] [rbp-68h] BYREF

if ( verbose > 1 )
fwrite("in send_socket\n", 1uLL, 0xFuLL, stderr);
*addr = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = _bswap_16(a3);
inet_pton(2, a2, v4);
inet_ntop(2, &addr->sa_data[2], v8, 0x32u);
if ( verbose > 1 )
fprintf(stderr, "Creating a send socket to %s:%d\n", v8, a3);
v5 = socket(2, 2, 0);
v6 = v5;
if ( v5 < 0 )
{
perror("Send socket");
exit(1);
}
if ( bind(v5, addr, 0x10u) < 0 )
{
perror("in send_socket(): bind error (need to change MCAST_ADDR)");
exit(1);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(struct sockaddr *addr, const char *a2, unsigned int a3)
{
void *v4; // rdx
int v5; // eax
unsigned int v6; // er12
char v8[104]; // [rsp+0h] [rbp-68h] BYREF

if ( verbose > 1 )
fwrite("in send_socket\n", 1uLL, 0xFuLL, stderr);
*addr = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = func0(a3);
inet_pton(2, a2, v4);
inet_ntop(2, &addr->sa_data[2], v8, 0x32u);
if ( verbose > 1 )
fprintf(stderr, "Creating a send socket to %s:%d\n", v8, a3);
v5 = socket(2, 2, 0);
v6 = v5;
if ( v5 < 0 )
{
perror("Send socket");
exit(1);
}
if ( bind(v5, addr, 0x10u) < 0 )
{
perror("in send_socket(): bind error (need to change MCAST_ADDR)");
exit(1);
}
return v6;
}

original_code:
int send_socket(struct sockaddr_in *addr, char * cp, int port)
{
  int fd, sockaddr_len;
  sa_family_t family;
  char buf[50];
  if (verbose>=2) fprintf(stderr, "in send_socket\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  inet_pton(2, cp, &addr->sin_addr);
  inet_ntop(2, &addr->sin_addr, buf, 50);
  if (verbose>=2)
    fprintf(stderr, "Creating a send socket to %s:%d\n", buf, port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  if ((bind(fd, (const struct sockaddr *)addr, sockaddr_len)) < 0){
       perror("in send_socket(): bind error (need to change MCAST_ADDR)");
       exit(1);
     }
  return fd;
}

canonical_original_code:
int send_socket(struct sockaddr_in *addr, char *cp, int port)
{
  int fd; int sockaddr_len;
  unsigned short family;
  char buf[50];
  if (verbose>=2) fprintf(stderr, "in send_socket\n");
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  inet_pton(2, cp, &addr->sin_addr);
  inet_ntop(2, &addr->sin_addr, buf, 50);
  if (verbose>=2)
    fprintf(stderr, "Creating a send socket to %s:%d\n", buf, port);
  if ((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Send socket");
    exit(1);
  }
  if ((bind(fd, (struct sockaddr *)addr, sockaddr_len)) < 0){
       perror("in send_socket(): bind error (need to change MCAST_ADDR)");
       exit(1);
     }
  return fd;
}

variable_types:
cp
char *

variable_types:
buf
char [50]

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


decompiled_code:
__int64 __fastcall rec_socket(struct sockaddr *addr, unsigned int a2)
{
int v2; // edx
int v3; // eax
unsigned int v4; // er12

*(_QWORD *)&addr->sa_data[6] = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = _bswap_16(a2);
*(_DWORD *)&addr->sa_data[2] = _bswap_32_constprop_0(2LL, 2LL);
v3 = socket(2, 2, v2);
if ( v3 < 0 )
{
perror("Socket create");
exit(1);
}
v4 = v3;
setsockopt(v3, 1, 2, 0LL, 0);
if ( verbose > 1 )
fprintf(stderr, "Creating receive socket on port %d\n", a2);
if ( bind(v4, addr, 0x10u) < 0 )
{
perror("in rec_socket(): bind error (need to change PORT)");
exit(1);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(struct sockaddr *addr, unsigned int a2)
{
int v2; // edx
int v3; // eax
unsigned int v4; // er12

*(_QWORD *)&addr->sa_data[6] = 0LL;
addr->sa_family = 2;
*(_WORD *)addr->sa_data = func0(a2);
*(_DWORD *)&addr->sa_data[2] = func1(2LL, 2LL);
v3 = socket(2, 2, v2);
if ( v3 < 0 )
{
perror("Socket create");
exit(1);
}
v4 = v3;
setsockopt(v3, 1, 2, 0LL, 0);
if ( verbose > 1 )
fprintf(stderr, "Creating receive socket on port %d\n", a2);
if ( bind(v4, addr, 0x10u) < 0 )
{
perror("in rec_socket(): bind error (need to change PORT)");
exit(1);
}
return v4;
}

original_code:
int rec_socket(struct sockaddr_in *addr, int port)
{
  int fd, sockaddr_len;
  sa_family_t family;
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  addr->sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  if((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Socket create");
    exit(1);
  }
  setsockopt(fd, 1, 2, ((void *)0), 0);
  if (verbose>=2)
    fprintf(stderr, "Creating receive socket on port %d\n", port);
  if ((bind(fd, (const struct sockaddr *)addr, sockaddr_len)) < 0){
    perror("in rec_socket(): bind error (need to change PORT)");
    exit(1);
  }
  return fd;
}

canonical_original_code:
int rec_socket(struct sockaddr_in *addr, int port)
{
  int fd; int sockaddr_len;
  unsigned short family;
  sockaddr_len = sizeof(struct sockaddr_in);
  memset(addr, 0, sockaddr_len);
  addr->sin_family = 2;
  family = 2;
  addr->sin_port = htons(port);
  addr->sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  if((fd = socket(family, SOCK_DGRAM, 0)) < 0){
    perror("Socket create");
    exit(1);
  }
  setsockopt(fd, 1, 2, ((void *)0), 0);
  if (verbose>=2)
    fprintf(stderr, "Creating receive socket on port %d\n", port);
  if ((bind(fd, (struct sockaddr *)addr, sockaddr_len)) < 0){
    perror("in rec_socket(): bind error (need to change PORT)");
    exit(1);
  }
  return fd;
}


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

if ( verbose > 1 )
{
if ( a2 == -1 )
result = fwrite("Timeout: set to infinite\n", 1uLL, 0x19uLL, stderr);
else
result = fprintf(stderr, "Timeout: set to %d sec + %d usec\n", a1, a2);
}
delay_sec = a1;
delay_usec = a2;
return result;
}

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

if ( verbose > 1 )
{
if ( a2 == -1 )
result = fwrite("Timeout: set to infinite\n", 1uLL, 0x19uLL, stderr);
else
result = fprintf(stderr, "Timeout: set to %d sec + %d usec\n", a1, a2);
}
delay_sec = a1;
delay_usec = a2;
return result;
}

original_code:
void set_delay(int secs, int usecs)
{
  if (verbose>=2) {
    if (usecs == -1)
      fprintf(stderr, "Timeout: set to infinite\n");
    else
      fprintf(stderr, "Timeout: set to %d sec + %d usec\n", secs, usecs);
  }
  delay_sec = secs;
  delay_usec = usecs;
}

variable_types: secs int

variable_types: usecs int


readable

decompiled_code:
int __fastcall readable(int a1)
{
int v1; // edi
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v1 = a1 + 1;
if ( delay_usec == -1 )
return select(v1, &readfds, 0LL, 0LL, 0LL);
v3.tv_usec = delay_usec;
v3.tv_sec = delay_sec;
return select(v1, &readfds, 0LL, 0LL, &v3);
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
int v1; // edi
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v1 = a1 + 1;
if ( delay_usec == -1 )
return select(v1, &readfds, 0LL, 0LL, 0LL);
v3.tv_usec = delay_usec;
v3.tv_sec = delay_sec;
return select(v1, &readfds, 0LL, 0LL, &v3);
}

original_code:
int readable(int fd)
{
  struct timeval delay_tv;
  fd_set rset;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (delay_usec == -1){
    return(select(fd + 1, &rset, ((void *)0), ((void *)0), ((void *)0)));
  } else {
    delay_tv.tv_sec = delay_sec;
    delay_tv.tv_usec = delay_usec;
    return (select(fd + 1, &rset, ((void *)0), ((void *)0), &delay_tv));
  }
}

canonical_original_code:
int readable(int fd)
{
  struct timeval delay_tv;
  struct fd_set rset;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  if (delay_usec == -1){
    return(select(fd + 1, &rset, ((void *)0), ((void *)0), ((void *)0)));
  } else {
    delay_tv.tv_sec = delay_sec;
    delay_tv.tv_usec = delay_usec;
    return (select(fd + 1, &rset, ((void *)0), ((void *)0), &delay_tv));
  }
}

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

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


decompiled_code:
void refresh_timer()
{
usec_acc = 0LL;
sec_acc = 0LL;
}

canonical_decompiled_code:
void func0()
{
usec_acc = 0LL;
sec_acc = 0LL;
}

original_code:
void refresh_timer()
{
  usec_acc = 0;
  sec_acc = 0;
}


decompiled_code:
int start_timer()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv0, &tz);
}

canonical_decompiled_code:
int func1()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv0, &tz);
}

original_code:
void start_timer()
{
  struct timezone tz;
  gettimeofday(&tv0, &tz);
}

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


decompiled_code:
int end_timer()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv1, &tz);
}

canonical_decompiled_code:
int func2()
{
struct timezone tz; // [rsp+8h] [rbp-10h] BYREF

return gettimeofday(&tv1, &tz);
}

original_code:
void end_timer()
{
  struct timezone tz;
  gettimeofday(&tv1, &tz);
}

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


decompiled_code:
__int64 update_time_accumulator()
{
__suseconds_t v0; // rax
__suseconds_t v1; // rcx
__time_t v2; // rdx
__int64 v3; // rdx
__int64 result; // rax

v0 = tv1.tv_usec;
v1 = tv0.tv_usec;
v2 = tv1.tv_sec - tv0.tv_sec;
if ( v0 >= v1 )
{
v3 = sec_acc + v2;
result = usec_acc + v0 - v1;
}
else
{
v3 = v2 + sec_acc - 1;
result = v0 - v1 + usec_acc + 1000000;
}
sec_acc = v3;
usec_acc = result;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__suseconds_t v0; // rax
__suseconds_t v1; // rcx
__time_t v2; // rdx
__int64 v3; // rdx
__int64 result; // rax

v0 = tv1.tv_usec;
v1 = tv0.tv_usec;
v2 = tv1.tv_sec - tv0.tv_sec;
if ( v0 >= v1 )
{
v3 = sec_acc + v2;
result = usec_acc + v0 - v1;
}
else
{
v3 = v2 + sec_acc - 1;
result = v0 - v1 + usec_acc + 1000000;
}
sec_acc = v3;
usec_acc = result;
return result;
}

original_code:
void update_time_accumulator()
{
  if (tv1.tv_usec<tv0.tv_usec) {
    sec_acc += (tv1.tv_sec - tv0.tv_sec - 1);
    usec_acc += (1000000 + tv1.tv_usec - tv0.tv_usec);
  } else {
    sec_acc += (tv1.tv_sec - tv0.tv_sec);
    usec_acc += (tv1.tv_usec - tv0.tv_usec);
  }
}


decompiled_code:
double get_accumulated_time()
{
double v0; // xmm1_8
unsigned __int64 v1; // rax
double v3; // xmm0_8

if ( sec_acc < 0 )
{
v1 = usec_acc;
v3 = (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1));
v0 = v3 + v3;
if ( usec_acc >= 0 )
return (double)(int)v1 / 1000000.0 + v0;
}
else
{
v0 = (double)(int)sec_acc;
v1 = usec_acc;
if ( usec_acc >= 0 )
return (double)(int)v1 / 1000000.0 + v0;
}
return ((double)(int)(v1 & 1 | (v1 >> 1)) + (double)(int)(v1 & 1 | (v1 >> 1))) / 1000000.0 + v0;
}

canonical_decompiled_code:
double func4()
{
double v0; // xmm1_8
unsigned __int64 v1; // rax
double v3; // xmm0_8

if ( sec_acc < 0 )
{
v1 = usec_acc;
v3 = (double)(int)(sec_acc & 1 | ((unsigned __int64)sec_acc >> 1));
v0 = v3 + v3;
if ( usec_acc >= 0 )
return (double)(int)v1 / 1000000.0 + v0;
}
else
{
v0 = (double)(int)sec_acc;
v1 = usec_acc;
if ( usec_acc >= 0 )
return (double)(int)v1 / 1000000.0 + v0;
}
return ((double)(int)(v1 & 1 | (v1 >> 1)) + (double)(int)(v1 & 1 | (v1 >> 1))) / 1000000.0 + v0;
}

original_code:
double get_accumulated_time()
{
  double sec = sec_acc;
  sec += (usec_acc / 1e6);
  return sec;
}

variable_types: sec double

return_type: double


decompiled_code:
double get_accumulated_usec()
{
double v0; // xmm1_8
unsigned __int64 v1; // rax
double v3; // xmm0_8

if ( usec_acc < 0 )
{
v1 = sec_acc;
v3 = (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1));
v0 = v3 + v3;
if ( sec_acc >= 0 )
return (double)(int)v1 * 1000000.0 + v0;
}
else
{
v0 = (double)(int)usec_acc;
v1 = sec_acc;
if ( sec_acc >= 0 )
return (double)(int)v1 * 1000000.0 + v0;
}
return ((double)(int)(v1 & 1 | (v1 >> 1)) + (double)(int)(v1 & 1 | (v1 >> 1))) * 1000000.0 + v0;
}

canonical_decompiled_code:
double func5()
{
double v0; // xmm1_8
unsigned __int64 v1; // rax
double v3; // xmm0_8

if ( usec_acc < 0 )
{
v1 = sec_acc;
v3 = (double)(int)(usec_acc & 1 | ((unsigned __int64)usec_acc >> 1));
v0 = v3 + v3;
if ( sec_acc >= 0 )
return (double)(int)v1 * 1000000.0 + v0;
}
else
{
v0 = (double)(int)usec_acc;
v1 = sec_acc;
if ( sec_acc >= 0 )
return (double)(int)v1 * 1000000.0 + v0;
}
return ((double)(int)(v1 & 1 | (v1 >> 1)) + (double)(int)(v1 & 1 | (v1 >> 1))) * 1000000.0 + v0;
}

original_code:
double get_accumulated_usec()
{
  double usec = usec_acc;
  usec += (sec_acc*1e6);
  return usec;
}

variable_types: usec double


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

result = 0LL;
memset(rtt_hist, 0, 0x7D0uLL);
rtt_hist[500] = 0;
return result;
}

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

result = 0LL;
memset(rtt_hist, 0, 0x7D0uLL);
rtt_hist[500] = 0;
return result;
}

original_code:
void init_rtt_hist()
{
  int i;
  for(i=0; i<501; ++i) rtt_hist[i] = 0;
}

variable_types: i int


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

LODWORD(result) = 500;
if ( a1 <= 0x7A11F )
LODWORD(result) = a1 / 0x3E8;
result = (unsigned int)result;
++rtt_hist[(unsigned int)result];
return result;
}

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

LODWORD(result) = 500;
if ( a1 <= 0x7A11F )
LODWORD(result) = a1 / 0x3E8;
result = (unsigned int)result;
++rtt_hist[(unsigned int)result];
return result;
}

original_code:
void update_rtt_hist(unsigned int rtt)
{
  unsigned int index;
  index = rtt / 1000;
  if (index>(501 -2)) index = 501 -1;
  rtt_hist[index]++;
}

variable_types:
rtt
unsigned int

variable_types:
index
unsigned int


decompiled_code:
int pr_rtt_hist()
{
__int64 v0; // rbx
int result; // eax
__int64 v2; // rdx
__int64 v3; // rcx

v0 = 0LL;
fwrite("rtt histogram\n", 1uLL, 0xEuLL, stderr);
fwrite("msec counts\n", 1uLL, 0xCuLL, stderr);
result = fwrite("---- --------\n", 1uLL, 0xEuLL, stderr);
do
{
while ( 1 )
{
v2 = (unsigned int)v0;
if ( verbose > 1 || (int)v0 <= 10 )
{
v3 = (unsigned int)rtt_hist[v0];
if ( (_DWORD)v3 )
break;
}
if ( ++v0 == 501 )
return result;
}
++v0;
result = fprintf(stderr, "%4d %u\n", v2, v3);
}
while ( v0 != 501 );
return result;
}

canonical_decompiled_code:
int func8()
{
__int64 v0; // rbx
int result; // eax
__int64 v2; // rdx
__int64 v3; // rcx

v0 = 0LL;
fwrite("rtt histogram\n", 1uLL, 0xEuLL, stderr);
fwrite("msec counts\n", 1uLL, 0xCuLL, stderr);
result = fwrite("---- --------\n", 1uLL, 0xEuLL, stderr);
do
{
while ( 1 )
{
v2 = (unsigned int)v0;
if ( verbose > 1 || (int)v0 <= 10 )
{
v3 = (unsigned int)rtt_hist[v0];
if ( (_DWORD)v3 )
break;
}
if ( ++v0 == 501 )
return result;
}
++v0;
result = fprintf(stderr, "%4d %u\n", v2, v3);
}
while ( v0 != 501 );
return result;
}

original_code:
void pr_rtt_hist()
{
  int i;
  fprintf(stderr, "rtt histogram\n");
  fprintf(stderr, "msec counts\n");
  fprintf(stderr, "---- --------\n");
  for(i=0; i<501; ++i) {
    if (verbose<=1 && i>10) continue;
    if (rtt_hist[i] != 0) {
      fprintf(stderr, "%4d %u\n", i, rtt_hist[i]);
    }
  }
}


decompiled_code:
__int64 pages_wo_ack()
{
return (unsigned int)rtt_hist[500];
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)rtt_hist[500];
}

original_code:
unsigned int pages_wo_ack()
{
  return rtt_hist[501 -1];
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall init_synclist(char *filename, const char *a2)
{
FILE *v2; // rdx
__int64 result; // rax
char v4[4104]; // [rsp+0h] [rbp-1008h] BYREF

nEntries = 0;
strcpy(basedir, a2);
fd = fopen64(filename, "r");
v2 = fd;
if ( fd )
{
while ( fgets(v4, 4096, v2) )
{
++nEntries;
v2 = fd;
}
if ( nEntries )
{
rewind(fd);
result = 1LL;
cur_entry = 0;
total_pages = 0;
total_bytes = 0LL;
}
else
{
fclose(fd);
fprintf(stderr, "Empty entires in synclist file = %s\n", filename);
result = 1LL;
}
}
else
{
fprintf(stderr, "Cannot open synclist file = %s \n", filename);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *filename, const char *a2)
{
FILE *v2; // rdx
__int64 result; // rax
char v4[4104]; // [rsp+0h] [rbp-1008h] BYREF

nEntries = 0;
strcpy(basedir, a2);
fd = fopen64(filename, "r");
v2 = fd;
if ( fd )
{
while ( fgets(v4, 4096, v2) )
{
++nEntries;
v2 = fd;
}
if ( nEntries )
{
rewind(fd);
result = 1LL;
cur_entry = 0;
total_pages = 0;
total_bytes = 0LL;
}
else
{
fclose(fd);
fprintf(stderr, "Empty entires in synclist file = %s\n", filename);
result = 1LL;
}
}
else
{
fprintf(stderr, "Cannot open synclist file = %s \n", filename);
result = 0LL;
}
return result;
}

original_code:
int init_synclist(char * synclist_path, char *bdir)
{
  char line[4096];
  nEntries = 0;
  strcpy(basedir, bdir);
  if ((fd = fopen(synclist_path, "r")) == ((void *)0)) {
    fprintf(stderr, "Cannot open synclist file = %s \n", synclist_path);
    return (0);
  }
  while (fgets(line, 4096, fd) != ((void *)0)) nEntries++;
  if (nEntries == 0) {
    fclose(fd);
    fprintf(stderr, "Empty entires in synclist file = %s\n", synclist_path);
    return (1);
  }
  rewind(fd);
  cur_entry = 0;
  total_pages = 0;
  total_bytes = 0;
  return (1);
}

canonical_original_code:
int init_synclist(char *synclist_path, char *bdir)
{
  char line[4096];
  nEntries = 0;
  strcpy(basedir, bdir);
  if ((fd = fopen(synclist_path, "r")) == ((void *)0)) {
    fprintf(stderr, "Cannot open synclist file = %s \n", synclist_path);
    return (0);
  }
  while (fgets(line, 4096, fd) != ((void *)0)) nEntries++;
  if (nEntries == 0) {
    fclose(fd);
    fprintf(stderr, "Empty entires in synclist file = %s\n", synclist_path);
    return (1);
  }
  rewind(fd);
  cur_entry = 0;
  total_pages = 0;
  total_bytes = 0;
  return (1);
}

variable_types:
bdir
char *

variable_types:
line
char [4096]


decompiled_code:
__int64 pages_for_file()
{
unsigned int v0; // er8
__off_t v2; // rcx

v0 = isDelete;
if ( isDelete )
return (unsigned int)-1;
if ( (st.st_mode & 0xF000) == 0x8000 && st.st_nlink <= 1 )
{
v2 = st.st_size;
v0 = v2 / 64512;
if ( v2 == 64512 * (v2 / 64512) )
{
last_bytes = 64512;
}
else
{
v0 = v2 / 64512 + 1;
last_bytes = v2 % 64512;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er8
__off_t v2; // rcx

v0 = isDelete;
if ( isDelete )
return (unsigned int)-1;
if ( (st.st_mode & 0xF000) == 0x8000 && st.st_nlink <= 1 )
{
v2 = st.st_size;
v0 = v2 / 64512;
if ( v2 == 64512 * (v2 / 64512) )
{
last_bytes = 64512;
}
else
{
v0 = v2 / 64512 + 1;
last_bytes = v2 % 64512;
}
}
return v0;
}

original_code:
int pages_for_file()
{
  if (isDelete) {
    return (-1);
  }
  if (((((st.st_mode)) & 0170000) == (0100000))){
    int n;
    if (st.st_nlink > 1) return 0;
    n = (int)((st.st_size)/(off_t)64512);
    if ((st.st_size)%((off_t)64512) == 0) {
      last_bytes = (unsigned int)(64512);
      return n;
    } else {
      last_bytes = (unsigned int)(st.st_size - (off_t)n * (off_t)64512);
      return n+1;
    }
  }
  if (((((st.st_mode)) & 0170000) == (0120000))){
    return 0;
  }
  return 0;
}

canonical_original_code:
int pages_for_file()
{
  if (isDelete) {
    return (-1);
  }
  if (((((st.st_mode)) & 0170000) == (0100000))){
    int n;
    if (st.st_nlink > 1) return 0;
    n = (int)((st.st_size)/(long)64512);
    if ((st.st_size)%((long)64512) == 0) {
      last_bytes = (unsigned int)(64512);
      return n;
    } else {
      last_bytes = (unsigned int)(st.st_size - (long)n * (long)64512);
      return n+1;
    }
  }
  if (((((st.st_mode)) & 0170000) == (0120000))){
    return 0;
  }
  return 0;
}

variable_types: n int


decompiled_code:
__off_t bytes_for_file()
{
return st.st_size;
}

canonical_decompiled_code:
__off_t func2()
{
return st.st_size;
}

canonical_original_code:
long bytes_for_file()
{
  return st.st_size;
}

return_type: long


decompiled_code:
__int64 get_nPages()
{
return (unsigned int)nPages;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)nPages;
}

original_code:
unsigned int get_nPages()
{
  return nPages;
}


decompiled_code:
_BOOL8 same_stat_for_file()
{
bool v0; // sf
_BOOL8 result; // rax
struct stat64 buf; // [rsp+10h] [rbp-98h] BYREF

v0 = lstat64(fullname, &buf) < 0;
result = 0LL;
if ( v0 )
{
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else if ( buf.st_size == st.st_size && buf.st_mode == st.st_mode )
{
result = buf.st_mtim.tv_sec == st.st_mtim.tv_sec;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func5()
{
bool v0; // sf
_BOOL8 result; // rax
struct stat64 buf; // [rsp+10h] [rbp-98h] BYREF

v0 = lstat64(fullname, &buf) < 0;
result = 0LL;
if ( v0 )
{
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else if ( buf.st_size == st.st_size && buf.st_mode == st.st_mode )
{
result = buf.st_mtim.tv_sec == st.st_mtim.tv_sec;
}
return result;
}

original_code:
int same_stat_for_file()
{
  struct stat st1;
  if(lstat(fullname, &st1) < 0) {
    if (verbose >=1) perror(fullname);
    return (0);
  }
  if (st1.st_size != st.st_size || st1.st_mode != st.st_mode ||
      st1.st_mtim.tv_sec != st.st_mtim.tv_sec) {
    return (0);
  }
  return (1);
}

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

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


decompiled_code:
__int64 __fastcall is_hardlink_line(char *src)
{
char *v1; // rax
struct stat64 v3; // [rsp+0h] [rbp-1098h] BYREF
char dest[4104]; // [rsp+90h] [rbp-1008h] BYREF

v1 = stpcpy(dest, basedir);
*v1 = 47;
strcpy(v1 + 1, src);
return (unsigned int)lstat64(dest, &v3) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src)
{
char *v1; // rax
struct stat64 v3; // [rsp+0h] [rbp-1098h] BYREF
char dest[4104]; // [rsp+90h] [rbp-1008h] BYREF

v1 = stpcpy(dest, basedir);
*v1 = 47;
strcpy(v1 + 1, src);
return (unsigned int)lstat64(dest, &v3) >> 31;
}

original_code:
int is_hardlink_line(char * line)
{
  struct stat st;
  char fn[4096];
  strcpy(fn, basedir);
  strcat(fn, "/");
  strcat(fn, line);
  return (lstat(fn, &st) < 0);
}

canonical_original_code:
int is_hardlink_line(char *line)
{
  struct stat st;
  char fn[4096];
  strcpy(fn, basedir);
  strcat(fn, "/");
  strcat(fn, line);
  return (lstat(fn, &st) < 0);
}

variable_types:
line
char *

variable_types:
fn
char [4096]


decompiled_code:
__int64 __fastcall get_next_entry(int a1)
{
char *v1; // rax
char *v2; // rbx
int v3; // eax
__int64 result; // rax
int v5; // er8
char s[8]; // [rsp+10h] [rbp-2018h] BYREF
char v7; // [rsp+18h] [rbp-2010h]
char src[4087]; // [rsp+19h] [rbp-200Fh] BYREF
char dest[4120]; // [rsp+1010h] [rbp-1018h] BYREF

cur_entry = a1;
isDelete = 0;
isHardlink = 0;
fgets(s, 4096, fd);
strip(s);
if ( a1 == nEntries )
{
fclose(fd);
if ( verbose <= 1 )
goto LABEL_4;
fwrite("no more entry in synclist.\n", 1uLL, 0x1BuLL, stderr);
}
if ( verbose > 1 )
{
fprintf(stderr, "Got current entry = %d (total= %d)\n", (unsigned int)cur_entry, (unsigned int)nEntries);
fprintf(stderr, "%s\n", s);
}
LABEL_4:
v1 = stpcpy(fullname, basedir);
*(_WORD *)v1 = 47;
if ( *(_QWORD *)s == 0x676E6974656C6564LL && v7 == 32 )
{
isDelete = 1;
nPages = -1;
strcpy(v1 + 1, src);
strcpy(filename, src);
v5 = needBackup(fullname);
result = 1LL;
if ( v5 )
cur_entry = -cur_entry;
}
else
{
v2 = strchr(s, 32);
if ( v2 && (unsigned int)is_hardlink_line(s) )
{
isHardlink = 1;
strncpy(dest, s, v2 - s);
dest[v2 - s] = 0;
strcat(fullname, dest);
strcpy(filename, dest);
strcpy(linktar, v2 + 1);
}
else
{
strcat(fullname, s);
strcpy(filename, s);
}
if ( lstat64(fullname, &st) < 0 )
{
result = 0LL;
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else
{
if ( (st.st_mode & 0xF000) == 40960 )
{
linktar[(int)readlink(fullname, linktar, 0x1000uLL)] = 0;
}
else if ( st.st_nlink > 1 && !isHardlink )
{
st.st_nlink = 1LL;
}
v3 = pages_for_file();
nPages = v3;
if ( v3 )
{
total_pages += v3;
total_bytes += st.st_size;
}
if ( (unsigned int)needBackup(fullname) )
cur_entry = -cur_entry;
file_changed = 0;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
char *v1; // rax
char *v2; // rbx
int v3; // eax
__int64 result; // rax
int v5; // er8
char s[8]; // [rsp+10h] [rbp-2018h] BYREF
char v7; // [rsp+18h] [rbp-2010h]
char src[4087]; // [rsp+19h] [rbp-200Fh] BYREF
char dest[4120]; // [rsp+1010h] [rbp-1018h] BYREF

cur_entry = a1;
isDelete = 0;
isHardlink = 0;
fgets(s, 4096, fd);
func4(s);
if ( a1 == nEntries )
{
fclose(fd);
if ( verbose <= 1 )
goto LABEL_4;
fwrite("no more entry in synclist.\n", 1uLL, 0x1BuLL, stderr);
}
if ( verbose > 1 )
{
fprintf(stderr, "Got current entry = %d (total= %d)\n", (unsigned int)cur_entry, (unsigned int)nEntries);
fprintf(stderr, "%s\n", s);
}
LABEL_4:
v1 = stpcpy(fullname, basedir);
*(_WORD *)v1 = 47;
if ( *(_QWORD *)s == 0x676E6974656C6564LL && v7 == 32 )
{
isDelete = 1;
nPages = -1;
strcpy(v1 + 1, src);
strcpy(filename, src);
v5 = needBackup(fullname);
result = 1LL;
if ( v5 )
cur_entry = -cur_entry;
}
else
{
v2 = strchr(s, 32);
if ( v2 && (unsigned int)func6(s) )
{
isHardlink = 1;
strncpy(dest, s, v2 - s);
dest[v2 - s] = 0;
strcat(fullname, dest);
strcpy(filename, dest);
strcpy(linktar, v2 + 1);
}
else
{
strcat(fullname, s);
strcpy(filename, s);
}
if ( lstat64(fullname, &st) < 0 )
{
result = 0LL;
if ( verbose > 0 )
{
perror(fullname);
result = 0LL;
}
}
else
{
if ( (st.st_mode & 0xF000) == 40960 )
{
linktar[(int)readlink(fullname, linktar, 0x1000uLL)] = 0;
}
else if ( st.st_nlink > 1 && !isHardlink )
{
st.st_nlink = 1LL;
}
v3 = func1();
nPages = v3;
if ( v3 )
{
total_pages += v3;
total_bytes += st.st_size;
}
if ( (unsigned int)needBackup(fullname) )
cur_entry = -cur_entry;
file_changed = 0;
result = 1LL;
}
}
return result;
}

original_code:
int get_next_entry(int current_file_id)
{
  char *c;
  char line[4096];
  cur_entry = current_file_id;
  isDelete = 0;
  isHardlink = 0;
  fgets(line, 4096, fd);
  strip(line);
  if (current_file_id == nEntries) {
    fclose(fd);
    if (verbose>=2) fprintf(stderr, "no more entry in synclist.\n");
  }
  if (verbose>=2) {
    fprintf(stderr, "Got current entry = %d (total= %d)\n", cur_entry, nEntries);
    fprintf(stderr, "%s\n", line);
  }
  strcpy(fullname, basedir);
  strcat(fullname, "/");
  if (strncmp(line, "deleting ", 9)==0) {
    isDelete = 1;
    nPages = -1;
    strcat(fullname, &line[9]);
    strcpy(filename, &line[9]);
    if (needBackup(fullname)) cur_entry = -cur_entry;
    return (1);
  } else if ((c = strchr(line, ' '))!=((void *)0) && is_hardlink_line(line)) {
    char fn[4096];
    isHardlink = 1;
    strncpy(fn, line, (c - line));
    fn[c-line] = '\0';
    strcat(fullname, fn);
    strcpy(filename, fn);
    strcpy(linktar, c+1);
  } else {
    strcat(fullname, line);
    strcpy(filename, line);
  }
  if(lstat(fullname, &st) < 0) {
    if (verbose >=1) perror(fullname);
    return (0);
  }
  if (((((st.st_mode)) & 0170000) == (0120000))) {
    int linklen;
    linklen = readlink(fullname, linktar, 4096);
    *(linktar + linklen) = '\0';
  } else if (st.st_nlink>1 && !isHardlink) {
    st.st_nlink = 1;
  }
  nPages = pages_for_file();
  if (nPages > 0) {
    total_pages += nPages;
    total_bytes += st.st_size;
  }
  if (needBackup(fullname)) cur_entry = -cur_entry;
  file_changed = 0;
  return (1);
}

variable_types:
c
char *

variable_types: linklen int


decompiled_code:
__off_t adjust_totals()
{
__off_t result; // rax

result = (unsigned int)nPages;
if ( nPages )
{
total_pages -= nPages;
result = st.st_size;
total_bytes -= result;
}
return result;
}

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

result = (unsigned int)nPages;
if ( nPages )
{
total_pages -= nPages;
result = st.st_size;
total_bytes -= result;
}
return result;
}

original_code:
void adjust_totals()
{
  if (nPages > 0) {
    total_pages -= nPages;
    total_bytes -= st.st_size;
  }
}


decompiled_code:
__int64 total_entries()
{
return (unsigned int)nEntries;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)nEntries;
}

original_code: unsigned int total_entries() { return nEntries; }


decompiled_code:
__int64 current_entry()
{
return (unsigned int)cur_entry;
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned int)cur_entry;
}

original_code: int current_entry() { return cur_entry; }


decompiled_code:
_BOOL8 is_softlink()
{
return (st.st_mode & 0xF000) == 40960;
}


decompiled_code:
__int64 is_hardlink()
{
return (unsigned int)isHardlink;
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned int)isHardlink;
}

original_code: int is_hardlink() { return isHardlink; }


decompiled_code:
_BOOL8 is_directory()
{
return (st.st_mode & 0xF000) == 0x4000;
}

canonical_decompiled_code:
_BOOL8 func13()
{
return (st.st_mode & 0xF000) == 0x4000;
}


getFilename

decompiled_code:
char *getFilename()
{
return filename;
}

canonical_decompiled_code:
char *func14()
{
return filename;
}

original_code: char * getFilename() { return &filename[0]; }

canonical_original_code: char *getFilename() { return &filename[0]; }


getFullname

decompiled_code:
char *getFullname()
{
return fullname;
}

canonical_decompiled_code:
char *func15()
{
return fullname;
}

original_code: char * getFullname() { return &fullname[0]; }

canonical_original_code: char *getFullname() { return &fullname[0]; }


decompiled_code:
__int64 __fastcall fill_in_stat(char *s)
{
if ( isDelete )
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC8);
else
sprintf(
s,
"%u %u %u %u %llu %lu %lu %d",
st.st_mode,
st.st_nlink,
st.st_uid,
st.st_gid,
st.st_size,
st.st_atim.tv_sec,
st.st_mtim.tv_sec,
(unsigned int)toRmFirst);
return (unsigned int)strlen(s) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *s)
{
if ( isDelete )
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC8);
else
sprintf(
s,
"%u %u %u %u %llu %lu %lu %d",
st.st_mode,
st.st_nlink,
st.st_uid,
st.st_gid,
st.st_size,
st.st_atim.tv_sec,
st.st_mtim.tv_sec,
(unsigned int)toRmFirst);
return (unsigned int)strlen(s) + 1;
}

original_code:
unsigned int fill_in_stat(char *buf)
{
  if (isDelete)
    sprintf(buf, "0 0 0 0 0 0 0 0");
  else {
    sprintf(buf, "%u %u %u %u %llu %lu %lu %d", st.st_mode, st.st_nlink,
     st.st_uid, st.st_gid, st.st_size, st.st_atim.tv_sec, st.st_mtim.tv_sec,
     toRmFirst);
  }
  return strlen(buf)+1;
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall fill_in_filename(char *a1)
{
return (unsigned int)stpcpy(a1, filename) - (unsigned int)a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func17(char *a1)
{
return (unsigned int)stpcpy(a1, filename) - (unsigned int)a1 + 1;
}

original_code:
unsigned int fill_in_filename(char * buf)
{
  strcpy(buf, filename);
  return strlen(buf)+1;
}

canonical_original_code:
unsigned int fill_in_filename(char *buf)
{
  strcpy(buf, filename);
  return strlen(buf)+1;
}


decompiled_code:
__int64 __fastcall fill_in_linktar(char *a1)
{
return (unsigned int)stpcpy(a1, linktar) - (unsigned int)a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func18(char *a1)
{
return (unsigned int)stpcpy(a1, linktar) - (unsigned int)a1 + 1;
}

original_code:
unsigned int fill_in_linktar(char *buf)
{
  strcpy(buf, linktar);
  return strlen(buf)+1;
}


strip

decompiled_code:
const char *__fastcall strip(const char *a1)
{
const char *result; // rax
char v2; // dl

result = &a1[strlen(a1) - 1];
v2 = *result;
if ( *result != 32 )
goto LABEL_3;
do
{
do
{
v2 = *--result;
*((_BYTE *)result + 1) = 0;
}
while ( v2 == 32 );
LABEL_3:
;
}
while ( v2 == 10 );
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
const char *result; // rax
char v2; // dl

result = &a1[strlen(a1) - 1];
v2 = *result;
if ( *result != 32 )
goto LABEL_3;
do
{
do
{
v2 = *--result;
*((_BYTE *)result + 1) = 0;
}
while ( v2 == 32 );
LABEL_3:
;
}
while ( v2 == 10 );
return result;
}

original_code:
void strip(char * str)
{
  char *pc = &str[strlen(str)-1];
  while (*pc == ' ' || *pc == '\n') {
    *(pc--) = '\0';
  }
}

canonical_original_code:
void strip(char *str)
{
  char *pc = &str[strlen(str)-1];
  while (*pc == ' ' || *pc == '\n') {
    *(pc--) = '\0';
  }
}

variable_types:
str
char *

variable_types:
pc
char *


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

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

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

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

original_code:
void init_string_list(struct string_list * str_ptr, int n)
{
  str_ptr->str = malloc(n * sizeof(void*));
  str_ptr->capacity = n;
  str_ptr->endp = str_ptr->str;
}

canonical_original_code:
void init_string_list(struct string_list *str_ptr, int n)
{
  str_ptr->str = malloc(n * sizeof(void *));
  str_ptr->capacity = n;
  str_ptr->endp = str_ptr->str;
}

variable_types: struct string_list { int capacity; char **endp; char **str; } *


original_code:
void grow_string_list(struct string_list * slp)
{
  int new_capacity = 2 * slp->capacity;
  char ** old_ptrs = slp->str;
  char ** new_ptrs;
  char ** newp = malloc(new_capacity * sizeof(void *));
  new_ptrs = newp;
  while (old_ptrs < slp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(slp->str);
  slp->str = newp;
  slp->endp= new_ptrs;
  slp->capacity = new_capacity;
}

canonical_original_code:
void grow_string_list(struct string_list *slp)
{
  int new_capacity = 2 * slp->capacity;
  char **old_ptrs = slp->str;
  char **new_ptrs;
  char **newp = malloc(new_capacity * sizeof(void *));
  new_ptrs = newp;
  while (old_ptrs < slp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(slp->str);
  slp->str = newp;
  slp->endp= new_ptrs;
  slp->capacity = new_capacity;
}

variable_types:
newp
char **

user_defined_types: struct string_list { int capacity; char **endp; char **str; }


decompiled_code:
char *__fastcall append_string_list(char *s, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbp
char *result; // rax

v2 = *(_QWORD *)(a2 + 8);
if ( (v2 - *(_QWORD *)(a2 + 16)) >> 3 == *(_DWORD *)a2 )
{
grow_string_list(a2);
v2 = *(_QWORD *)(a2 + 8);
}
v3 = v2 + 8;
result = strdup(s);
*(_QWORD *)(v3 - 8) = result;
*(_QWORD *)(a2 + 8) = v3;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *s, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbp
char *result; // rax

v2 = *(_QWORD *)(a2 + 8);
if ( (v2 - *(_QWORD *)(a2 + 16)) >> 3 == *(_DWORD *)a2 )
{
func1(a2);
v2 = *(_QWORD *)(a2 + 8);
}
v3 = v2 + 8;
result = strdup(s);
*(_QWORD *)(v3 - 8) = result;
*(_QWORD *)(a2 + 8) = v3;
return result;
}

original_code:
void append_string_list(char * str, struct string_list * slp)
{
  if (slp->endp - slp->str == slp->capacity) grow_string_list(slp);
  *slp->endp = strdup(str);
  (slp->endp)++;
}

canonical_original_code:
void append_string_list(char *str, struct string_list *slp)
{
  if (slp->endp - slp->str == slp->capacity) grow_string_list(slp);
  *slp->endp = strdup(str);
  (slp->endp)++;
}


decompiled_code:
__int64 __fastcall find_string(char *s2, __int64 a2)
{
__int64 v2; // r14
__int64 v3; // rax
__int64 v4; // r12
__int64 i; // rbx

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return 0xFFFFFFFFLL;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; strcmp(*(const char **)(v2 + 8 * i), s2); ++i )
{
if ( i == v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, __int64 a2)
{
__int64 v2; // r14
__int64 v3; // rax
__int64 v4; // r12
__int64 i; // rbx

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return 0xFFFFFFFFLL;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; strcmp(*(const char **)(v2 + 8 * i), s2); ++i )
{
if ( i == v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)i;
}

original_code:
int find_string(char * str, struct string_list * slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strcmp((slp->str)[i], str)==0) return i;
  }
  return -1;
}

canonical_original_code:
int find_string(char *str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strcmp((slp->str)[i], str)==0) return i;
  }
  return -1;
}


decompiled_code:
__int64 __fastcall has_sub_string(char *s1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r14
__int64 i; // rbx
const char *v6; // r15
unsigned int v7; // er13
size_t v8; // rax

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = *(const char **)(v2 + 8 * i);
v7 = i;
v8 = strlen(v6);
if ( !strncmp(s1, v6, v8) )
break;
if ( v4 == i )
return (unsigned int)-1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r14
__int64 i; // rbx
const char *v6; // r15
unsigned int v7; // er13
size_t v8; // rax

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = *(const char **)(v2 + 8 * i);
v7 = i;
v8 = strlen(v6);
if ( !strncmp(s1, v6, v8) )
break;
if ( v4 == i )
return (unsigned int)-1;
}
return v7;
}

original_code:
int has_sub_string(char * str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strncmp(str, (slp->str)[i], strlen((slp->str)[i]))==0) return i;
  }
  return -1;
}

canonical_original_code:
int has_sub_string(char *str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strncmp(str, (slp->str)[i], strlen((slp->str)[i]))==0) return i;
  }
  return -1;
}


decompiled_code:
__int64 __fastcall has_newdir(char *s2, __int64 a2)
{
__int64 v2; // r15
__int64 v3; // rbx
__int64 v4; // r14
__int64 v5; // rbx
size_t v6; // r12
unsigned int v7; // er13

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
v5 = 0LL;
v6 = strlen(s2);
while ( 1 )
{
v7 = v5;
if ( !strncmp(*(const char **)(v2 + 8 * v5), s2, v6) )
break;
if ( v5 == v4 )
return (unsigned int)-1;
++v5;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2, __int64 a2)
{
__int64 v2; // r15
__int64 v3; // rbx
__int64 v4; // r14
__int64 v5; // rbx
size_t v6; // r12
unsigned int v7; // er13

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 3;
if ( (int)v3 <= 0 )
return (unsigned int)-1;
v4 = (unsigned int)(v3 - 1);
v5 = 0LL;
v6 = strlen(s2);
while ( 1 )
{
v7 = v5;
if ( !strncmp(*(const char **)(v2 + 8 * v5), s2, v6) )
break;
if ( v5 == v4 )
return (unsigned int)-1;
++v5;
}
return v7;
}

original_code:
int has_newdir(char *str, struct string_list *slp)
{
  int i;
  int n = slp->endp - slp->str;
  for(i=0; i<n; ++i) {
    if (strncmp((slp->str)[i],str, strlen(str))==0) return i;
  }
  return -1;
}


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

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

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

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

original_code:
void init_uint_list(struct uint_list * uil_ptr, int n)
{
  uil_ptr->d = malloc(n * sizeof(unsigned int));
  uil_ptr->capacity = n;
  uil_ptr->endp = uil_ptr->d;
}

canonical_original_code:
void init_uint_list(struct uint_list *uil_ptr, int n)
{
  uil_ptr->d = malloc(n * sizeof(unsigned int));
  uil_ptr->capacity = n;
  uil_ptr->endp = uil_ptr->d;
}

variable_types: struct uint_list { int capacity; unsigned int *endp; unsigned int *d; } *


original_code:
void grow_uint_list(struct uint_list * uilp)
{
  int new_capacity = 2 * uilp->capacity;
  unsigned int * old_ptrs = uilp->d;
  unsigned int * new_ptrs;
  unsigned int * newp = malloc(new_capacity * sizeof(unsigned int));
  new_ptrs = newp;
  while (old_ptrs < uilp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(uilp->d);
  uilp->d = newp;
  uilp->endp= new_ptrs;
  uilp->capacity = new_capacity;
}

canonical_original_code:
void grow_uint_list(struct uint_list *uilp)
{
  int new_capacity = 2 * uilp->capacity;
  unsigned int *old_ptrs = uilp->d;
  unsigned int *new_ptrs;
  unsigned int *newp = malloc(new_capacity * sizeof(unsigned int));
  new_ptrs = newp;
  while (old_ptrs < uilp->endp) {
    *new_ptrs++ = *old_ptrs++;
  }
  free(uilp->d);
  uilp->d = newp;
  uilp->endp= new_ptrs;
  uilp->capacity = new_capacity;
}

variable_types:
newp
unsigned int *

user_defined_types: struct uint_list { int capacity; unsigned int *endp; unsigned int *d; }


decompiled_code:
__int64 __fastcall find_unit(int a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rsi
__int64 result; // rax

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 2;
if ( (int)v3 <= 0 )
return 0xFFFFFFFFLL;
v4 = (unsigned int)(v3 - 1);
for ( result = 0LL; *(_DWORD *)(v2 + 4 * result) != a1; ++result )
{
if ( result == v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

v2 = *(_QWORD *)(a2 + 16);
v3 = (*(_QWORD *)(a2 + 8) - v2) >> 2;
if ( (int)v3 <= 0 )
return 0xFFFFFFFFLL;
v4 = (unsigned int)(v3 - 1);
for ( result = 0LL; *(_DWORD *)(v2 + 4 * result) != a1; ++result )
{
if ( result == v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int find_unit(unsigned int data, struct uint_list * uilp)
{
  int i;
  int n = uilp->endp - uilp->d;
  for(i=0; i<n; ++i) {
    if ((uilp->d)[i] == data) return i;
  }
  return -1;
}

canonical_original_code:
int find_unit(unsigned int data, struct uint_list *uilp)
{
  int i;
  int n = uilp->endp - uilp->d;
  for(i=0; i<n; ++i) {
    if ((uilp->d)[i] == data) return i;
  }
  return -1;
}

variable_types:
data
unsigned int

variable_types: i int


decompiled_code:
void output_subs()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void output_subs(char * str)
{
  return;
}

canonical_original_code:
void output_subs(char *str)
{
  return;
}


decompiled_code:
const char *__fastcall strip(const char *a1)
{
char *v1; // rbx
const char *v2; // rax
char v3; // dl
const char *result; // rax
char v5; // dl

v1 = (char *)a1;
v2 = &a1[strlen(a1) - 1];
v3 = *v2;
if ( *v2 != 32 )
goto LABEL_3;
do
{
do
{
v3 = *--v2;
*((_BYTE *)v2 + 1) = 0;
}
while ( v3 == 32 );
LABEL_3:
;
}
while ( v3 == 10 );
result = a1;
if ( *a1 == 32 )
{
do
v5 = *++result;
while ( v5 == 32 );
if ( a1 != result )
{
while ( v5 )
{
++result;
*v1++ = v5;
v5 = *result;
}
*v1 = 0;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(const char *a1)
{
char *v1; // rbx
const char *v2; // rax
char v3; // dl
const char *result; // rax
char v5; // dl

v1 = (char *)a1;
v2 = &a1[strlen(a1) - 1];
v3 = *v2;
if ( *v2 != 32 )
goto LABEL_3;
do
{
do
{
v3 = *--v2;
*((_BYTE *)v2 + 1) = 0;
}
while ( v3 == 32 );
LABEL_3:
;
}
while ( v3 == 10 );
result = a1;
if ( *a1 == 32 )
{
do
v5 = *++result;
while ( v5 == 32 );
if ( a1 != result )
{
while ( v5 )
{
++result;
*v1++ = v5;
v5 = *result;
}
*v1 = 0;
}
}
return result;
}

variable_types:
pt
char *


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

result = pArray_ptr;
fill_ptr = pArray_ptr;
return result;
}

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

result = pArray_ptr;
fill_ptr = pArray_ptr;
return result;
}

original_code:
void init_fill_ptr()
{
  fill_ptr = pArray_ptr;
}


decompiled_code:
__int64 __fastcall update_complaint_address(__int64 a1)
{
return sock_set_addr(&complaint_addr, 16LL, a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return sock_set_addr(&complaint_addr, 16LL, a1 + 4);
}

original_code:
void update_complaint_address(struct sockaddr_in *sa)
{
  sock_set_addr((struct sockaddr *) &complaint_addr,
  sizeof(complaint_addr), (void*)&sa->sin_addr);
}

canonical_original_code:
void update_complaint_address(struct sockaddr_in *sa)
{
  sock_set_addr((struct sockaddr *) &complaint_addr,
  sizeof(complaint_addr), (void *)&sa->sin_addr);
}

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


signal

decompiled_code:
__int64 __fastcall signal(int sig, void (*a2)(int))
{
int v2; // eax
bool v3; // sf
__int64 result; // rax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v2 = 0x10000000;
if ( sig == 14 )
v2 = 0x20000000;
v5.sa_flags = v2;
v3 = sigaction(sig, &v5, &v6) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v6.sa_handler;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int sig, void (*a2)(int))
{
int v2; // eax
bool v3; // sf
__int64 result; // rax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v2 = 0x10000000;
if ( sig == 14 )
v2 = 0x20000000;
v5.sa_flags = v2;
v3 = sigaction(sig, &v5, &v6) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v6.sa_handler;
return result;
}

original_code:
Sigfunc * signal(int signo, Sigfunc *func)
{
 struct sigaction act, oact;
 act.__sigaction_handler.sa_handler = func;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (signo == 14) {
  act.sa_flags |= 0x20000000;
 } else {
  act.sa_flags |= 0x10000000;
 }
 if (sigaction(signo, &act, &oact) < 0)
  return(((__sighandler_t) -1));
 return(oact.__sigaction_handler.sa_handler);
}

canonical_original_code:
void (*signal(int signo, void (*func)(int)))(int)
{
 struct sigaction act; struct sigaction oact;
 act.__sigaction_handler.sa_handler = func;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if (signo == 14) {
  act.sa_flags |= 0x20000000;
 } else {
  act.sa_flags |= 0x10000000;
 }
 if (sigaction(signo, &act, &oact) < 0)
  return(((__sighandler_t) -1));
 return(oact.__sigaction_handler.sa_handler);
}

variable_types: signo int

variable_types:
func
void (*)(int)

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

return_type: void (*)(int)


Signal

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

result = signal(a1, a2);
if ( result == -1 )
{
perror("signal error");
result = -1LL;
}
return result;
}

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

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

original_code:
Sigfunc * Signal(int signo, Sigfunc *func)
{
 Sigfunc *sigfunc;
 if ( (sigfunc = signal(signo, func)) == ((__sighandler_t) -1))
  perror("signal error");
 return(sigfunc);
}

canonical_original_code:
void (*Signal(int signo, void (*func)(int)))(int)
{
 void (*sigfunc)(int);
 if ( (sigfunc = signal(signo, func)) == ((__sighandler_t) -1))
  perror("signal error");
 return(sigfunc);
}

variable_types:
sigfunc
void (*)(int)


Fcntl

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

result = fcntl64();
if ( (_DWORD)result == -1 )
{
perror("fcntl error");
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = fcntl64();
if ( (_DWORD)result == -1 )
{
perror("fcntl error");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int Fcntl(int fd, int cmd, int arg)
{
 int n;
 if ( (n = fcntl(fd, cmd, arg)) == -1)
  perror("fcntl error");
 return(n);
}

variable_types: fd int

variable_types: cmd int

variable_types: arg int

variable_types: n int


Ioctl

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

result = ioctl(a1, a2);
if ( result == -1 )
{
perror("ioctl error");
result = -1;
}
return result;
}

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

result = ioctl(a1, a2);
if ( result == -1 )
{
perror("ioctl error");
result = -1;
}
return result;
}

original_code:
int Ioctl(int fd, int request, void *arg)
{
 int n;
 if ( (n = ioctl(fd, request, arg)) == -1)
  perror("ioctl error");
 return(n);
}

variable_types: request int

variable_types:
arg
void *


Sigemptyset

decompiled_code:
void __fastcall Sigemptyset(sigset_t *a1)
{
if ( sigemptyset(a1) == -1 )
perror("sigemptyset error");
}

canonical_decompiled_code:
void __fastcall func4(sigset_t *a1)
{
if ( sigemptyset(a1) == -1 )
perror("sigemptyset error");
}

original_code:
void Sigemptyset(sigset_t *set)
{
 if (sigemptyset(set) == -1)
  perror("sigemptyset error");
}

canonical_original_code:
void Sigemptyset(struct __sigset_t *set)
{
 if (sigemptyset(set) == -1)
  perror("sigemptyset error");
}

variable_types: struct __sigset_t { unsigned long __val[-1]; } *


Sigaddset

decompiled_code:
void __fastcall Sigaddset(sigset_t *a1, int a2)
{
if ( sigaddset(a1, a2) == -1 )
perror("sigaddset error");
}

canonical_decompiled_code:
void __fastcall func5(sigset_t *a1, int a2)
{
if ( sigaddset(a1, a2) == -1 )
perror("sigaddset error");
}

original_code:
void Sigaddset(sigset_t *set, int signo)
{
 if (sigaddset(set, signo) == -1)
  perror("sigaddset error");
}

canonical_original_code:
void Sigaddset(struct __sigset_t *set, int signo)
{
 if (sigaddset(set, signo) == -1)
  perror("sigaddset error");
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


Sigprocmask

decompiled_code:
void __fastcall Sigprocmask(int a1, const sigset_t *a2, sigset_t *a3)
{
if ( sigprocmask(a1, a2, a3) == -1 )
perror("sigprocmask error");
}

canonical_decompiled_code:
void __fastcall func6(int a1, const sigset_t *a2, sigset_t *a3)
{
if ( sigprocmask(a1, a2, a3) == -1 )
perror("sigprocmask error");
}

original_code:
void Sigprocmask(int how, const sigset_t *set, sigset_t *oset)
{
 if (sigprocmask(how, set, oset) == -1)
  perror("sigprocmask error");
}

canonical_original_code:
void Sigprocmask(int how, struct __sigset_t *set, struct __sigset_t *oset)
{
 if (sigprocmask(how, set, oset) == -1)
  perror("sigprocmask error");
}

variable_types: how int

variable_types:
oset
struct __sigset_t *


needBackup

decompiled_code:
__int64 __fastcall needBackup(__int64 a1)
{
int v1; // ebp
const char *v2; // r12
__int64 v3; // rbx

if ( !backup )
return 0LL;
v1 = nPattern;
if ( !nPattern )
return 1LL;
v2 = (const char *)(a1 + strlen(pattern_baseDir) + 1);
if ( v1 > 0 )
{
v3 = 0LL;
while ( regexec(*(const regex_t **)(fPatterns + 8 * v3), v2, 0LL, 0LL, 0) )
{
if ( nPattern <= (int)++v3 )
return 0LL;
}
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebp
const char *v2; // r12
__int64 v3; // rbx

if ( !backup )
return 0LL;
v1 = nPattern;
if ( !nPattern )
return 1LL;
v2 = (const char *)(a1 + strlen(pattern_baseDir) + 1);
if ( v1 > 0 )
{
v3 = 0LL;
while ( regexec(*(const regex_t **)(fPatterns + 8 * v3), v2, 0LL, 0LL, 0) )
{
if ( nPattern <= (int)++v3 )
return 0LL;
}
return 1LL;
}
return 0LL;
}

original_code:
int needBackup(char * filename)
{
  int i;
  char *p;
  if (!backup) return 0;
  if (nPattern==0) return 1;
  p = filename + strlen(pattern_baseDir) + 1;
  for(i=0; i<nPattern; ++i) {
    if (regexec(fPatterns[i], p, (size_t)0, ((void *)0), 0)!=0)
      continue;
    return 1;
  }
  return 0;
}

canonical_original_code:
int needBackup(char *filename)
{
  int i;
  char *p;
  if (!backup) return 0;
  if (nPattern==0) return 1;
  p = filename + strlen(pattern_baseDir) + 1;
  for(i=0; i<nPattern; ++i) {
    if (regexec(fPatterns[i], p, (unsigned long)0, ((void *)0), 0)!=0)
      continue;
    return 1;
  }
  return 0;
}

variable_types:
filename
char *

variable_types:
p
char *


decompiled_code:
char *__fastcall get_dirname_of_rtt(char *dest, const char *a2)
{
char *v2; // rax
char *result; // rax
char *v4; // rax
char v5[4104]; // [rsp+0h] [rbp-1008h] BYREF

strcpy(v5, a2);
v2 = dirname(v5);
result = strcpy(dest, v2);
if ( *dest == 46 && !dest[1] )
{
v4 = getcwd(v5, 0x1000uLL);
result = strcpy(dest, v4);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *dest, const char *a2)
{
char *v2; // rax
char *result; // rax
char *v4; // rax
char v5[4104]; // [rsp+0h] [rbp-1008h] BYREF

strcpy(v5, a2);
v2 = dirname(v5);
result = strcpy(dest, v2);
if ( *dest == 46 && !dest[1] )
{
v4 = getcwd(v5, 0x1000uLL);
result = strcpy(dest, v4);
}
return result;
}

original_code:
void get_dirname_of_rtt(char *dname, char *rtt_path)
{
  char path[4096];
  strcpy(path, rtt_path);
  strcpy(dname, dirname(path));
  if (strcmp(dname, ".")==0) {
    strcpy(dname, getcwd(path, 4096));
  }
}

variable_types:
dname
char *

variable_types:
path
char [4096]


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"rtt (to measure rount trip time to a target version %s\n"
" Option list:\n"
" [ -v flag to turn on verbose]\n"
" [ -r <remote shell, default=%s> ]\n"
" [ -p <PATH for remote rttcatcher, default=%s> ]\n"
" -------- essential options ----------------------------------\n"
" -m <destination machine_name>\n"
" -n <num Of Pages>\n"
" -s <page_size in bytes; max=64512>\n"
" -------- mcast options --------------------------------------\n"
" [ -A <my_mcast_address default=%s)> ]\n"
" [ -P <my_PORT default=%d> ]\n"
" [ -T <my_TTL default=%d> ]\n"
" [ -L flag turn on mcast_LOOP. default is off ]\n"
" [ -I <my_MCAST_IF default=NULL> ]\n",
"3.1.0",
reshell,
&catcher_path,
my_MCAST_ADDR,
(unsigned int)my_PORT,
(unsigned int)my_TTL);
}

canonical_decompiled_code:
int func0()
{
return fprintf(
stderr,
"rtt (to measure rount trip time to a target version %s\n"
" Option list:\n"
" [ -v flag to turn on verbose]\n"
" [ -r <remote shell, default=%s> ]\n"
" [ -p <PATH for remote rttcatcher, default=%s> ]\n"
" -------- essential options ----------------------------------\n"
" -m <destination machine_name>\n"
" -n <num Of Pages>\n"
" -s <page_size in bytes; max=64512>\n"
" -------- mcast options --------------------------------------\n"
" [ -A <my_mcast_address default=%s)> ]\n"
" [ -P <my_PORT default=%d> ]\n"
" [ -T <my_TTL default=%d> ]\n"
" [ -L flag turn on mcast_LOOP. default is off ]\n"
" [ -I <my_MCAST_IF default=NULL> ]\n",
"3.1.0",
reshell,
&catcher_path,
my_MCAST_ADDR,
(unsigned int)my_PORT,
(unsigned int)my_TTL);
}

original_code:
void usage()
{
  fprintf(stderr,
   "rtt (to measure rount trip time to a target version %s\n"
   "   Option list:\n"
   "   [ -v flag to turn on verbose]\n"
   "   [ -r <remote shell, default=%s> ]\n"
   "   [ -p <PATH for remote rttcatcher, default=%s> ]\n"
   "   -------- essential options ----------------------------------\n"
   "     -m <destination machine_name>\n"
   "     -n <num Of Pages>\n"
   "     -s <page_size in bytes; max=64512>\n"
   "   -------- mcast options --------------------------------------\n"
   "   [ -A <my_mcast_address default=%s)> ]\n"
   "   [ -P <my_PORT default=%d> ]\n"
   "   [ -T <my_TTL default=%d> ]\n"
   "   [ -L flag turn on mcast_LOOP. default is off ]\n"
   "   [ -I <my_MCAST_IF default=NULL> ]\n",
   "3.1.0", reshell, catcher_path, my_MCAST_ADDR, my_PORT, my_TTL);
}