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

if ( aq_data_buffer && aq_usb_dev )
{
if ( (int)aq_dev_poll(a3) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*((_BYTE *)aq_data_buffer + a1 + 198) = 255 * (unsigned int)a2 / 0x64;
result = (unsigned int)((int)aq_dev_push(103, a3) >> 31);
}
}
else
{
*a3 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( aq_data_buffer && aq_usb_dev )
{
if ( (int)func8(a3) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*((_BYTE *)aq_data_buffer + a1 + 198) = 255 * (unsigned int)a2 / 0x64;
result = (unsigned int)((int)func9(103, a3) >> 31);
}
}
else
{
*a3 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int aquaero_set_fan_duty(char fan_no, aq_byte duty, char **err_msg)
{
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_data_buffer[0x0c6 + (fan_no * 1)] = duty * 0xff
   / 100;
 if (aq_dev_push(AQ_REQ_RAM, err_msg) < 0)
   return -1;
  return 0;
}

canonical_original_code:
int aquaero_set_fan_duty(char fan_no, unsigned char duty, char **err_msg)
{
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_data_buffer[0x0c6 + (fan_no * 1)] = duty * 0xff
   / 100;
 if (aq_dev_push(AQ_REQ_RAM, err_msg) < 0)
   return -1;
  return 0;
}

variable_types:
duty
unsigned char


repo: lynix/aerotools

decompiled_code:
void aquaero_exit()
{
if ( aq_usb_dev )
{
libusb_unref_device(aq_usb_dev);
aq_usb_dev = 0LL;
}
libusb_exit(0LL);
if ( aq_data_buffer )
{
free(aq_data_buffer);
aq_data_buffer = 0LL;
}
}

canonical_decompiled_code:
void func15()
{
if ( aq_usb_dev )
{
libusb_unref_device(aq_usb_dev);
aq_usb_dev = 0LL;
}
libusb_exit(0LL);
if ( aq_data_buffer )
{
free(aq_data_buffer);
aq_data_buffer = 0LL;
}
}

original_code:
void aquaero_exit()
{
 if (aq_usb_dev != ((void *)0)) {
  libusb_unref_device(aq_usb_dev);
  aq_usb_dev = ((void *)0);
 }
 libusb_exit(((void *)0));
 if (aq_data_buffer != ((void *)0)) {
  free(aq_data_buffer);
  aq_data_buffer = ((void *)0);
 }
 return;
}

return_type: void


decompiled_code:
void *aquaero_get_buffer()
{
return aq_data_buffer;
}

canonical_decompiled_code:
void *func16()
{
return aq_data_buffer;
}

original_code:
unsigned char *aquaero_get_buffer()
{
 return aq_data_buffer;
}

return_type: unsigned char *


decompiled_code:
int __fastcall print_fans(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // rdx
const char *v4; // rsi
int result; // eax

v1 = a1 + 40;
puts(":: Fan readings");
do
{
v2 = *(unsigned __int16 *)(v1 + 10);
v3 = *(unsigned __int8 *)(v1 + 8);
v4 = *(const char **)v1;
v1 += 16LL;
result = printf(" %-10s %u%% @ %u rpm\n", v4, v3, v2);
}
while ( v1 != a1 + 104 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // rdx
const char *v4; // rsi
int result; // eax

v1 = a1 + 40;
puts(":: Fan readings");
do
{
v2 = *(unsigned __int16 *)(v1 + 10);
v3 = *(unsigned __int8 *)(v1 + 8);
v4 = *(const char **)v1;
v1 += 16LL;
result = printf(" %-10s %u%% @ %u rpm\n", v4, v3, v2);
}
while ( v1 != a1 + 104 );
return result;
}

original_code:
void print_fans(aquaero_data *data)
{
 int i;
 printf(":: Fan readings\n");
 for (i = 0; i < 4; i++)
  printf("  %-10s %u%% @ %u rpm\n", data->fans[i].name, data->fans[i].duty,
    data->fans[i].rpm);
}

canonical_original_code:
void print_fans(struct aquaero_data *data)
{
 int i;
 printf(":: Fan readings\n");
 for (i = 0; i < 4; i++)
  printf("  %-10s %u%% @ %u rpm\n", data->fans[i].name, data->fans[i].duty,
    data->fans[i].rpm);
}

variable_types: struct aquaero_data { struct aq_device { char *name; char *fw_name; char *language; unsigned char profile; unsigned char prod_year; unsigned char prod_month; unsigned char time_h; unsigned char time_m; unsigned char time_s; unsigned char time_d; unsigned short os_version; unsigned short serial; unsigned short flash_count; } device; struct aq_fan { char *name; unsigned char duty; unsigned short rpm; } fans[4]; struct aq_temp { char *name; double value; char connected; } temps[6]; struct aq_flow { char *name; double value; char connected; } flow; } *

variable_types: i int

user_defined_types: struct aquaero_data { struct aq_device device; struct aq_fan fans[4]; struct aq_temp temps[6]; struct aq_flow flow; }


decompiled_code:
int __fastcall print_temps(__int64 a1, char a2)
{
const char **v3; // rbx
const char **v4; // rbp
int result; // eax
double v6; // xmm0_8
const char *v7; // rsi

v3 = (const char **)(a1 + 104);
v4 = (const char **)(a1 + 248);
result = puts(":: Temperatures");
do
{
while ( *((_BYTE *)v3 + 16) )
{
v6 = *((double *)v3 + 1);
v7 = *v3;
v3 += 3;
result = printf(" %-10s %2.1f °C\n", v7, v6);
if ( v3 == v4 )
return result;
}
if ( a2 )
result = printf(" %-10s not connected\n", *v3);
v3 += 3;
}
while ( v3 != v4 );
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, char a2)
{
const char **v3; // rbx
const char **v4; // rbp
int result; // eax
double v6; // xmm0_8
const char *v7; // rsi

v3 = (const char **)(a1 + 104);
v4 = (const char **)(a1 + 248);
result = puts(":: Temperatures");
do
{
while ( *((_BYTE *)v3 + 16) )
{
v6 = *((double *)v3 + 1);
v7 = *v3;
v3 += 3;
result = printf(" %-10s %2.1f °C\n", v7, v6);
if ( v3 == v4 )
return result;
}
if ( a2 )
result = printf(" %-10s not connected\n", *v3);
v3 += 3;
}
while ( v3 != v4 );
return result;
}

original_code:
void print_temps(aquaero_data *data, char verbose)
{
 int i;
 printf(":: Temperatures\n");
 for (i = 0; i < 6; i++)
  if (data->temps[i].connected)
   printf("  %-10s %2.1f °C\n", data->temps[i].name,
     data->temps[i].value);
  else if (verbose)
   printf("  %-10s not connected\n", data->temps[i].name);
}

canonical_original_code:
void print_temps(struct aquaero_data *data, char verbose)
{
 int i;
 printf(":: Temperatures\n");
 for (i = 0; i < 6; i++)
  if (data->temps[i].connected)
   printf("  %-10s %2.1f °C\n", data->temps[i].name,
     data->temps[i].value);
  else if (verbose)
   printf("  %-10s not connected\n", data->temps[i].name);
}

variable_types: verbose char

user_defined_types: struct aq_device { char *name; char *fw_name; char *language; unsigned char profile; unsigned char prod_year; unsigned char prod_month; unsigned char time_h; unsigned char time_m; unsigned char time_s; unsigned char time_d; unsigned short os_version; unsigned short serial; unsigned short flash_count; }

user_defined_types: struct aq_flow { char *name; double value; char connected; }

user_defined_types: struct aq_fan { char *name; unsigned char duty; unsigned short rpm; }

user_defined_types: struct aq_temp { char *name; double value; char connected; }


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

puts(":: Flow sensor");
if ( *(_BYTE *)(a1 + 264) )
result = printf(" %-10s %2.2f l/h\n", *(const char **)(a1 + 248), *(double *)(a1 + 256));
else
result = printf(" %-10s not connected\n", *(const char **)(a1 + 248));
return result;
}

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

puts(":: Flow sensor");
if ( *(_BYTE *)(a1 + 264) )
result = printf(" %-10s %2.2f l/h\n", *(const char **)(a1 + 248), *(double *)(a1 + 256));
else
result = printf(" %-10s not connected\n", *(const char **)(a1 + 248));
return result;
}

original_code:
void print_flow(aquaero_data *data)
{
 printf(":: Flow sensor\n");
 if (data->flow.connected)
  printf("  %-10s %2.2f l/h\n", data->flow.name, data->flow.value);
 else
  printf("  %-10s not connected\n", data->flow.name);
}

canonical_original_code:
void print_flow(struct aquaero_data *data)
{
 printf(":: Flow sensor\n");
 if (data->flow.connected)
  printf("  %-10s %2.2f l/h\n", data->flow.name, data->flow.value);
 else
  printf("  %-10s not connected\n", data->flow.name);
}


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

print_fans(a1);
result = print_temps(a1, 0);
if ( *(_BYTE *)(a1 + 264) )
result = print_flow(a1);
return result;
}

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

func0(a1);
result = func1(a1, 0);
if ( *(_BYTE *)(a1 + 264) )
result = func2(a1);
return result;
}

original_code:
void print_summary(aquaero_data *data)
{
 print_fans(data);
 print_temps(data, 0);
 if (data->flow.connected)
  print_flow(data);
}

canonical_original_code:
void print_summary(struct aquaero_data *data)
{
 print_fans(data);
 print_temps(data, 0);
 if (data->flow.connected)
  print_flow(data);
}


decompiled_code:
int err_msg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: ", "aerocli");
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int func5(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: ", "aerocli");
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

original_code:
void err_msg(char *msg, ...)
{
 va_list argpointer;
 __builtin_va_start(argpointer,msg);
 fprintf(stderr, "%s: ", "aerocli");
 vfprintf(stderr, msg, argpointer);
 fprintf(stderr, "\n");
 fflush(stderr);
 return;
}

canonical_original_code:
void err_msg(char *msg, ...)
{
 __builtin_va_list argpointer;
 __builtin_va_start(argpointer,msg);
 fprintf(stderr, "%s: ", "aerocli");
 vfprintf(stderr, msg, argpointer);
 fprintf(stderr, "\n");
 fflush(stderr);
 return;
}

variable_types:
msg
char *


strday

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

result = "???";
if ( a1 <= 6u )
result = CSWTCH_21[a1];
return result;
}

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

result = "???";
if ( a1 <= 6u )
result = CSWTCH_21[a1];
return result;
}

original_code:
char *strday(aq_byte day)
{
 switch (day) {
  case 0:
   return "Sun";
  case 1:
   return "Mon";
  case 2:
   return "Tue";
  case 3:
   return "Wed";
  case 4:
   return "Thu";
  case 5:
   return "Fri";
  case 6:
   return "Sat";
  default:
   return "???";
 }
}

canonical_original_code:
char *strday(unsigned char day)
{
 switch (day) {
  case 0:
   return "Sun";
  case 1:
   return "Mon";
  case 2:
   return "Tue";
  case 3:
   return "Wed";
  case 4:
   return "Thu";
  case 5:
   return "Fri";
  case 6:
   return "Sat";
  default:
   return "???";
 }
}

variable_types:
day
unsigned char

return_type: char *


decompiled_code:
int __fastcall print_device(__int64 a1)
{
const char *v2; // rax

puts(":: Device data");
printf(" Name %s\n", *(const char **)a1);
printf(" Firmware %s\n", *(const char **)(a1 + 8));
printf(" OS Version %u\n", *(unsigned __int16 *)(a1 + 32));
printf(" Serial %u\n", *(unsigned __int16 *)(a1 + 34));
printf(" Produced 20%02u-%02u\n", *(unsigned __int8 *)(a1 + 25), *(unsigned __int8 *)(a1 + 26));
printf(" Flash count %u\n", *(unsigned __int16 *)(a1 + 36));
printf(" Profile %u\n", *(unsigned __int8 *)(a1 + 24));
printf(" Language %s\n", *(const char **)(a1 + 16));
v2 = strday(*(_BYTE *)(a1 + 30));
return printf(
" Time %s %02u:%02u:%02u\n",
v2,
*(unsigned __int8 *)(a1 + 27),
*(unsigned __int8 *)(a1 + 28),
*(unsigned __int8 *)(a1 + 29));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
const char *v2; // rax

puts(":: Device data");
printf(" Name %s\n", *(const char **)a1);
printf(" Firmware %s\n", *(const char **)(a1 + 8));
printf(" OS Version %u\n", *(unsigned __int16 *)(a1 + 32));
printf(" Serial %u\n", *(unsigned __int16 *)(a1 + 34));
printf(" Produced 20%02u-%02u\n", *(unsigned __int8 *)(a1 + 25), *(unsigned __int8 *)(a1 + 26));
printf(" Flash count %u\n", *(unsigned __int16 *)(a1 + 36));
printf(" Profile %u\n", *(unsigned __int8 *)(a1 + 24));
printf(" Language %s\n", *(const char **)(a1 + 16));
v2 = func6(*(_BYTE *)(a1 + 30));
return printf(
" Time %s %02u:%02u:%02u\n",
v2,
*(unsigned __int8 *)(a1 + 27),
*(unsigned __int8 *)(a1 + 28),
*(unsigned __int8 *)(a1 + 29));
}

original_code:
void print_device(aquaero_data *data)
{
 printf(":: Device data\n");
 printf("  Name          %s\n", data->device.name);
 printf("  Firmware      %s\n", data->device.fw_name);
 printf("  OS Version    %u\n", data->device.os_version);
 printf("  Serial        %u\n", data->device.serial);
 printf("  Produced      20%02u-%02u\n", data->device.prod_year,
   data->device.prod_month);
 printf("  Flash count   %u\n", data->device.flash_count);
 printf("  Profile       %u\n", data->device.profile);
 printf("  Language      %s\n", data->device.language);
 printf("  Time          %s %02u:%02u:%02u\n", strday(data->device.time_d),
   data->device.time_h, data->device.time_m, data->device.time_s);
}

canonical_original_code:
void print_device(struct aquaero_data *data)
{
 printf(":: Device data\n");
 printf("  Name          %s\n", data->device.name);
 printf("  Firmware      %s\n", data->device.fw_name);
 printf("  OS Version    %u\n", data->device.os_version);
 printf("  Serial        %u\n", data->device.serial);
 printf("  Produced      20%02u-%02u\n", data->device.prod_year,
   data->device.prod_month);
 printf("  Flash count   %u\n", data->device.flash_count);
 printf("  Profile       %u\n", data->device.profile);
 printf("  Language      %s\n", data->device.language);
 printf("  Time          %s %02u:%02u:%02u\n", strday(data->device.time_d),
   data->device.time_h, data->device.time_m, data->device.time_s);
}


decompiled_code:
int __fastcall print_all(__int64 a1)
{
print_device(a1);
print_fans(a1);
print_temps(a1, 1);
return print_flow(a1);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
func7(a1);
func0(a1);
func1(a1, 1);
return func2(a1);
}

original_code:
void print_all(aquaero_data *data)
{
 print_device(data);
 print_fans(data);
 print_temps(data, 1);
 print_flow(data);
}

canonical_original_code:
void print_all(struct aquaero_data *data)
{
 print_device(data);
 print_fans(data);
 print_temps(data, 1);
 print_flow(data);
}


decompiled_code:
__int64 __fastcall sync_time(__int64 a1)
{
unsigned __int8 *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = (unsigned __int8 *)localtime(&timer);
return aquaero_set_time(v1[8], v1[4], *v1, v1[24], a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned __int8 *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = (unsigned __int8 *)localtime(&timer);
return aquaero_set_time(v1[8], v1[4], *v1, v1[24], a1);
}

original_code:
int sync_time(char **err) {
 struct tm *ts;
 time_t now;
 now = time(0);
 ts = localtime(&now);
 return aquaero_set_time(ts->tm_hour, ts->tm_min, ts->tm_sec, ts->tm_wday,
   err);
}

canonical_original_code:
int sync_time(char **err) {
 struct tm *ts;
 long now;
 now = time(0);
 ts = localtime(&now);
 return aquaero_set_time(ts->tm_hour, ts->tm_min, ts->tm_sec, ts->tm_wday,
   err);
}

variable_types:
err
char **

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

variable_types: now long

return_type: int


decompiled_code:
__int64 __fastcall set_fan_duty(char a1, unsigned __int8 a2, _QWORD *a3)
{
__int64 result; // rax

printf("debug: setting fan %d to %d%%\n", (unsigned int)a1, a2);
if ( a2 > 0x64u )
{
*a3 = "invalid duty value, must be in [0,100]";
result = 1LL;
}
else if ( (unsigned __int8)(a1 - 1) <= 3u )
{
result = aquaero_set_fan_duty((unsigned __int8)(a1 - 1), a2, a3);
}
else
{
*a3 = "invalid fan number, must be in [1,4]";
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char a1, unsigned __int8 a2, _QWORD *a3)
{
__int64 result; // rax

printf("debug: setting fan %d to %d%%\n", (unsigned int)a1, a2);
if ( a2 > 0x64u )
{
*a3 = "invalid duty value, must be in [0,100]";
result = 1LL;
}
else if ( (unsigned __int8)(a1 - 1) <= 3u )
{
result = aquaero_set_fan_duty((unsigned __int8)(a1 - 1), a2, a3);
}
else
{
*a3 = "invalid fan number, must be in [1,4]";
result = 1LL;
}
return result;
}

original_code:
int set_fan_duty(char num, aq_byte duty, char **err_msg)
{
 printf("debug: setting fan %d to %d%%\n", num, duty);
 if (duty < 0 || duty > 100) {
  *err_msg = "invalid duty value, must be in [0,100]";
  return 1;
 }
 if (num < 1 || num > 4) {
  *err_msg = "invalid fan number, must be in [1,4]";
  return 1;
 }
 return aquaero_set_fan_duty(num-1, duty, err_msg);
}

canonical_original_code:
int set_fan_duty(char num, unsigned char duty, char **err_msg)
{
 printf("debug: setting fan %d to %d%%\n", num, duty);
 if (duty < 0 || duty > 100) {
  *err_msg = "invalid duty value, must be in [0,100]";
  return 1;
 }
 if (num < 1 || num > 4) {
  *err_msg = "invalid fan number, must be in [1,4]";
  return 1;
 }
 return aquaero_set_fan_duty(num-1, duty, err_msg);
}

variable_types: num char


decompiled_code:
void *__fastcall tcp_handler(void *a1)
{
char *v1; // r12
size_t v2; // rax
int v3; // ebp

while ( 1 )
{
v3 = accept(server_sock, 0LL, 0LL);
if ( v3 < 0 )
break;
pthread_mutex_lock(&data_lock);
v1 = data_str;
if ( data_str )
{
v2 = strlen(data_str);
send(v3, v1, v2 + 1, 0);
}
pthread_mutex_unlock(&data_lock);
close(v3);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
char *v1; // r12
size_t v2; // rax
int v3; // ebp

while ( 1 )
{
v3 = accept(server_sock, 0LL, 0LL);
if ( v3 < 0 )
break;
pthread_mutex_lock(&data_lock);
v1 = data_str;
if ( data_str )
{
v2 = strlen(data_str);
send(v3, v1, v2 + 1, 0);
}
pthread_mutex_unlock(&data_lock);
close(v3);
}
return 0LL;
}

original_code:
void *tcp_handler()
{
 int connection_sock;
 while ((connection_sock = accept(server_sock, ((void *)0), ((void *)0))) >= 0) {
  pthread_mutex_lock(&data_lock);
  if (data_str != ((void *)0))
   send(connection_sock, data_str, strlen(data_str)+1, 0);
  pthread_mutex_unlock(&data_lock);
  close(connection_sock);
 }
 return ((void *)0);
}

return_type: void *


decompiled_code:
__int64 tcp_start_server()
{
int v0; // eax
__int64 v1; // rdi
socklen_t v2; // edx
__int64 result; // rax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v5; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
v0 = socket(2, 1, 0);
server_sock = v0;
if ( v0 < 0
|| (v1 = (unsigned int)v0,
setsockopt(v0, 1, 2, &optval, 4u),
*(_QWORD *)&v5.sa_data[6] = 0LL,
v5.sa_family = 2,
*(_QWORD *)&v5.sa_data[2] = (unsigned int)_bswap_32_constprop_0(v1, &v5, 16LL),
*(_WORD *)v5.sa_data = _bswap_16(opts),
bind(server_sock, &v5, v2) < 0) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(listen(server_sock, 1024) >> 31);
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
__int64 v1; // rdi
socklen_t v2; // edx
__int64 result; // rax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v5; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
v0 = socket(2, 1, 0);
server_sock = v0;
if ( v0 < 0
|| (v1 = (unsigned int)v0,
setsockopt(v0, 1, 2, &optval, 4u),
*(_QWORD *)&v5.sa_data[6] = 0LL,
v5.sa_family = 2,
*(_QWORD *)&v5.sa_data[2] = (unsigned int)func2(v1, &v5, 16LL),
*(_WORD *)v5.sa_data = func0(opts),
bind(server_sock, &v5, v2) < 0) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(listen(server_sock, 1024) >> 31);
}
return result;
}

original_code:
int tcp_start_server()
{
 const int one = 1;
 struct sockaddr_in server_addr;
 if ((server_sock = socket(2, SOCK_STREAM, 0)) < 0 ) {
  return -1;
 }
 setsockopt(server_sock, 1, 2, &one, sizeof(one));
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 server_addr.sin_port = htons(opts.port);
 if (bind(server_sock, (struct sockaddr *)&server_addr,
   sizeof(server_addr)) < 0) {
  return -1;
 }
 if (listen(server_sock, 1024) < 0) {
  return -1;
 }
 return 0;
}

canonical_original_code:
int tcp_start_server()
{
 int one = 1;
 struct sockaddr_in server_addr;
 if ((server_sock = socket(2, SOCK_STREAM, 0)) < 0 ) {
  return -1;
 }
 setsockopt(server_sock, 1, 2, &one, sizeof(one));
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 server_addr.sin_port = htons(opts.port);
 if (bind(server_sock, (struct sockaddr *)&server_addr,
   sizeof(server_addr)) < 0) {
  return -1;
 }
 if (listen(server_sock, 1024) < 0) {
  return -1;
 }
 return 0;
}

variable_types: one int

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

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

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


original_code:
char *poll_aquaero(char **err_msg)
{
 aquaero_data aq_data;
 int i;
 char *aquaero_data_str, *position;
 if (aquaero_poll_data(&aq_data, err_msg) < 0)
  return ((void *)0);
 if ((aquaero_data_str = malloc(1024)) == ((void *)0))
  return ((void *)0);
 position = aquaero_data_str;
 for (i=0; i<4; i++) {
  sprintf(position, "|/dev/fan%d|%s|%d|C|", i+1, aq_data.fans[i].name,
    aq_data.fans[i].rpm);
  position = aquaero_data_str + strlen(aquaero_data_str);
 }
 for (i=0; i<4; i++) {
   sprintf(position, "|/dev/fan%dp|%s|%d|C|", i+1, aq_data.fans[i].name,
     aq_data.fans[i].duty);
   position = aquaero_data_str + strlen(aquaero_data_str);
  }
 for (i=0; i<6; i++) {
  if (!aq_data.temps[i].connected)
   continue;
  if (opts.precision)
   sprintf(position, "|/dev/temp%d|%s|%.1f|C|", i+1,
    aq_data.temps[i].name, aq_data.temps[i].value);
  else
   sprintf(position, "|/dev/temp%d|%s|%.0f|C|", i+1,
       aq_data.temps[i].name, aq_data.temps[i].value);
  position = aquaero_data_str + strlen(aquaero_data_str);
 }
 if (aq_data.flow.connected) {
  if (opts.precision)
   sprintf(position, "|/dev/flow|%s|%.1f|C|", aq_data.flow.name,
    aq_data.flow.value);
  else
   sprintf(position, "|/dev/flow|%s|%.0f|C|", aq_data.flow.name,
       aq_data.flow.value);
  position = aquaero_data_str + strlen(aquaero_data_str);
 }
 return aquaero_data_str;
}

canonical_original_code:
char *poll_aquaero(char **err_msg)
{
 struct aquaero_data aq_data;
 int i;
 char *aquaero_data_str; char *position;
 if (aquaero_poll_data(&aq_data, err_msg) < 0)
  return ((void *)0);
 if ((aquaero_data_str = malloc(1024)) == ((void *)0))
  return ((void *)0);
 position = aquaero_data_str;
 for (i=0; i<4; i++) {
  sprintf(position, "|/dev/fan%d|%s|%d|C|", i+1, aq_data.fans[i].name,
    aq_data.fans[i].rpm);
  position = aquaero_data_str + strlen(aquaero_data_str);
 }
 for (i=0; i<4; i++) {
   sprintf(position, "|/dev/fan%dp|%s|%d|C|", i+1, aq_data.fans[i].name,
     aq_data.fans[i].duty);
   position = aquaero_data_str + strlen(aquaero_data_str);
  }
 for (i=0; i<6; i++) {
  if (!aq_data.temps[i].connected)
   continue;
  if (opts.precision)
   sprintf(position, "|/dev/temp%d|%s|%.1f|C|", i+1,
    aq_data.temps[i].name, aq_data.temps[i].value);
  else
   sprintf(position, "|/dev/temp%d|%s|%.0f|C|", i+1,
       aq_data.temps[i].name, aq_data.temps[i].value);
  position = aquaero_data_str + strlen(aquaero_data_str);
 }
 if (aq_data.flow.connected) {
  if (opts.precision)
   sprintf(position, "|/dev/flow|%s|%.1f|C|", aq_data.flow.name,
    aq_data.flow.value);
  else
   sprintf(position, "|/dev/flow|%s|%.0f|C|", aq_data.flow.name,
       aq_data.flow.value);
  position = aquaero_data_str + strlen(aquaero_data_str);
 }
 return aquaero_data_str;
}

variable_types: struct aquaero_data { struct aq_device { char *name; char *fw_name; char *language; unsigned char profile; unsigned char prod_year; unsigned char prod_month; unsigned char time_h; unsigned char time_m; unsigned char time_s; unsigned char time_d; unsigned short os_version; unsigned short serial; unsigned short flash_count; } device; struct aq_fan { char *name; unsigned char duty; unsigned short rpm; } fans[4]; struct aq_temp { char *name; double value; char connected; } temps[6]; struct aq_flow { char *name; double value; char connected; } flow; }

variable_types:
position
char *


canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned __int8 *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = (unsigned __int8 *)localtime(&timer);
return aquaero_set_time(v1[8], v1[4], *v1, v1[24], a1);
}

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


die

decompiled_code:
void __noreturn die()
{
close(server_sock);
closelog();
unlink("/var/run/aerod.pid");
aquaero_exit();
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
close(server_sock);
closelog();
unlink("/var/run/aerod.pid");
aquaero_exit();
exit(0);
}

original_code:
void die()
{
 close(server_sock);
 closelog();
 unlink("/var/run/aerod.pid");
 aquaero_exit();
 exit(0);
}


decompiled_code:
__int64 poll_data()
{
const char *v0; // rax
char *v1; // rbp
char *v2; // r12
size_t v3; // rbx
size_t v4; // rax
char *v5; // rax
__int64 result; // rax
const char *v7; // [rsp+8h] [rbp-20h] BYREF

v0 = poll_aquaero((__int64)&v7);
if ( v0 )
{
v1 = (char *)v0;
if ( (*((_BYTE *)&opts + 6) & 2) == 0 )
{
LABEL_6:
pthread_mutex_lock(&data_lock);
free(data_str);
data_str = v1;
pthread_mutex_unlock(&data_lock);
return 0LL;
}
v2 = poll_hddtemp("127.0.0.1", 7634);
if ( !v2 )
{
log_msg(3, "failed to retrieve data from hddtemp");
goto LABEL_6;
}
v3 = strlen(v1);
v4 = strlen(v2);
v5 = (char *)realloc(v1, v3 + v4 + 1);
v1 = v5;
if ( v5 )
{
strcat(v5, v2);
free(v2);
goto LABEL_6;
}
log_msg(3, "out-of-memory joining data strings");
result = 0xFFFFFFFFLL;
}
else
{
log_msg(3, "error reading from aquaero(R): %s", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
const char *v0; // rax
char *v1; // rbp
char *v2; // r12
size_t v3; // rbx
size_t v4; // rax
char *v5; // rax
__int64 result; // rax
const char *v7; // [rsp+8h] [rbp-20h] BYREF

v0 = func4((__int64)&v7);
if ( v0 )
{
v1 = (char *)v0;
if ( (*((_BYTE *)&opts + 6) & 2) == 0 )
{
LABEL_6:
pthread_mutex_lock(&data_lock);
free(data_str);
data_str = v1;
pthread_mutex_unlock(&data_lock);
return 0LL;
}
v2 = poll_hddtemp("127.0.0.1", 7634);
if ( !v2 )
{
func8(3, "failed to retrieve data from hddtemp");
goto LABEL_6;
}
v3 = strlen(v1);
v4 = strlen(v2);
v5 = (char *)realloc(v1, v3 + v4 + 1);
v1 = v5;
if ( v5 )
{
strcat(v5, v2);
free(v2);
goto LABEL_6;
}
func8(3, "out-of-memory joining data strings");
result = 0xFFFFFFFFLL;
}
else
{
func8(3, "error reading from aquaero(R): %s", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int poll_data()
{
 char *poll_str, *hddtemp_data, *err_msg;
 if ((poll_str = poll_aquaero(&err_msg)) == ((void *)0)) {
  log_msg(3, "error reading from aquaero(R): %s", err_msg);
  return -1;
 }
 if (opts.hddtemp) {
  if ((hddtemp_data = poll_hddtemp("127.0.0.1", 7634)) == ((void *)0))
   log_msg(3, "failed to retrieve data from hddtemp");
  else {
   if (poll_str != ((void *)0)) {
    if ((poll_str = realloc(poll_str, strlen(poll_str) +
      strlen(hddtemp_data) + 1)) == ((void *)0)) {
     log_msg(3, "out-of-memory joining data strings");
     return -1;
    }
    strcat(poll_str, hddtemp_data);
    free(hddtemp_data);
   } else
    poll_str = hddtemp_data;
  }
 }
 pthread_mutex_lock(&data_lock);
 free(data_str);
 data_str = poll_str;
 pthread_mutex_unlock(&data_lock);
 return 0;
}

canonical_original_code:
int poll_data()
{
 char *poll_str; char *hddtemp_data; char *err_msg;
 if ((poll_str = poll_aquaero(&err_msg)) == ((void *)0)) {
  log_msg(3, "error reading from aquaero(R): %s", err_msg);
  return -1;
 }
 if (opts.hddtemp) {
  if ((hddtemp_data = poll_hddtemp("127.0.0.1", 7634)) == ((void *)0))
   log_msg(3, "failed to retrieve data from hddtemp");
  else {
   if (poll_str != ((void *)0)) {
    if ((poll_str = realloc(poll_str, strlen(poll_str) +
      strlen(hddtemp_data) + 1)) == ((void *)0)) {
     log_msg(3, "out-of-memory joining data strings");
     return -1;
    }
    strcat(poll_str, hddtemp_data);
    free(hddtemp_data);
   } else
    poll_str = hddtemp_data;
  }
 }
 pthread_mutex_lock(&data_lock);
 free(data_str);
 data_str = poll_str;
 pthread_mutex_unlock(&data_lock);
 return 0;
}


decompiled_code:
void __fastcall signal_handler(unsigned int a1)
{
if ( a1 == 2 )
{
log_msg(4, "received SIGINT, terminating");
goto LABEL_6;
}
if ( a1 == 15 )
{
log_msg(4, "received SIGTERM, terminating");
LABEL_6:
die();
}
if ( a1 == 1 )
{
log_msg(4, "received SIGHUP, terminating");
goto LABEL_6;
}
log_msg(4, "unhandled signal: %d", a1);
}

canonical_decompiled_code:
void __fastcall func10(unsigned int a1)
{
if ( a1 == 2 )
{
func8(4, "received SIGINT, terminating");
goto LABEL_6;
}
if ( a1 == 15 )
{
func8(4, "received SIGTERM, terminating");
LABEL_6:
func7();
}
if ( a1 == 1 )
{
func8(4, "received SIGHUP, terminating");
goto LABEL_6;
}
func8(4, "unhandled signal: %d", a1);
}

original_code:
void signal_handler(int signal)
{
 switch(signal) {
  case 15:
   log_msg(4, "received SIGTERM, terminating");
   die();
   break;
  case 1:
   log_msg(4, "received SIGHUP, terminating");
   die();
   break;
  case 2:
   log_msg(4, "received SIGINT, terminating");
   die();
   break;
  default:
   log_msg(4, "unhandled signal: %d", signal);
   break;
 }
 return;
}

variable_types: signal int


decompiled_code:
int __fastcall parse_cmdline(int argc, char **argv)
{
char v2; // al
int result; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

*((_WORD *)&opts + 2) = 7634;
v2 = *((_BYTE *)&opts + 6);
opts = 1973714;
*((_BYTE *)&opts + 6) = v2 & 0xE0 | 1;
while ( 1 )
{
result = getopt(argc, argv, "hFftsPp:i:T:");
if ( (_BYTE)result == 0xFF )
return result;
switch ( (char)result )
{
case '?':
if ( optopt == 112 || optopt == 105 )
fprintf(stderr, "option -%c requires an argument.\n", (unsigned int)optopt);
else
log_msg(3, "unknown option \"-%c\". Try -h for help.", (unsigned int)optopt);
goto LABEL_18;
case 'F':
*((_BYTE *)&opts + 6) &= 0xFEu;
continue;
case 'P':
*((_BYTE *)&opts + 6) |= 0x10u;
continue;
case 'T':
v6 = atoi(optarg);
if ( v6 - 1 > 0xFFFE )
{
log_msg(3, "invalid hddtemp port: %d", v6);
goto LABEL_24;
}
*((_WORD *)&opts + 2) = v6;
break;
case 'f':
*((_BYTE *)&opts + 6) |= 4u;
continue;
case 'h':
print_help();
exit(0);
case 'i':
v5 = atoi(optarg);
if ( v5 - 1 > 0xFFFE )
{
log_msg(3, "invalid interval: %d", v5);
LABEL_24:
exit(1);
}
HIWORD(opts) = v5;
break;
case 'p':
v4 = atoi(optarg);
if ( v4 - 1 > 0xFFFE )
{
log_msg(3, "invalid port: %d", v4);
goto LABEL_24;
}
LOWORD(opts) = v4;
continue;
case 's':
*((_BYTE *)&opts + 6) |= 8u;
continue;
case 't':
*((_BYTE *)&opts + 6) |= 2u;
continue;
default:
log_msg(3, "invalid arguments. Try -h for help.");
LABEL_18:
exit(1);
}
}
}

canonical_decompiled_code:
int __fastcall func13(int argc, char **argv)
{
char v2; // al
int result; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

*((_WORD *)&opts + 2) = 7634;
v2 = *((_BYTE *)&opts + 6);
opts = 1973714;
*((_BYTE *)&opts + 6) = v2 & 0xE0 | 1;
while ( 1 )
{
result = getopt(argc, argv, "hFftsPp:i:T:");
if ( (_BYTE)result == 0xFF )
return result;
switch ( (char)result )
{
case '?':
if ( optopt == 112 || optopt == 105 )
fprintf(stderr, "option -%c requires an argument.\n", (unsigned int)optopt);
else
func8(3, "unknown option \"-%c\". Try -h for help.", (unsigned int)optopt);
goto LABEL_18;
case 'F':
*((_BYTE *)&opts + 6) &= 0xFEu;
continue;
case 'P':
*((_BYTE *)&opts + 6) |= 0x10u;
continue;
case 'T':
v6 = atoi(optarg);
if ( v6 - 1 > 0xFFFE )
{
func8(3, "invalid hddtemp port: %d", v6);
goto LABEL_24;
}
*((_WORD *)&opts + 2) = v6;
break;
case 'f':
*((_BYTE *)&opts + 6) |= 4u;
continue;
case 'h':
func12();
exit(0);
case 'i':
v5 = atoi(optarg);
if ( v5 - 1 > 0xFFFE )
{
func8(3, "invalid interval: %d", v5);
LABEL_24:
exit(1);
}
HIWORD(opts) = v5;
break;
case 'p':
v4 = atoi(optarg);
if ( v4 - 1 > 0xFFFE )
{
func8(3, "invalid port: %d", v4);
goto LABEL_24;
}
LOWORD(opts) = v4;
continue;
case 's':
*((_BYTE *)&opts + 6) |= 8u;
continue;
case 't':
*((_BYTE *)&opts + 6) |= 2u;
continue;
default:
func8(3, "invalid arguments. Try -h for help.");
LABEL_18:
exit(1);
}
}
}

original_code:
void parse_cmdline(int argc, char *argv[])
{
 char c;
 int n;
 extern int optind, optopt, opterr;
 opts.port = 7634;
 opts.interval = 30;
 opts.fork = 1;
 opts.hddtemp = 0;
 opts.pidfile = 0;
 opts.sync_clock = 0;
 opts.hddtemp_port = 7634;
 opts.precision = 0;
 while ((c = getopt(argc, argv, "hFftsPp:i:T:")) != -1) {
  switch (c) {
   case 'h':
    print_help();
    exit(0);
    break;
   case 'F':
    opts.fork = 0;
    break;
   case 'f':
    opts.pidfile = 1;
    break;
   case 't':
    opts.hddtemp = 1;
    break;
   case 'T':
    n = atoi(optarg);
    if (n < 1 || n > 65535) {
     log_msg(3, "invalid hddtemp port: %d", n);
     exit(1);
    }
    opts.hddtemp_port = n;
    break;
   case 'p':
    n = atoi(optarg);
    if (n < 1 || n > 65535) {
     log_msg(3, "invalid port: %d", n);
     exit(1);
    }
    opts.port = n;
    break;
   case 'P':
    opts.precision = 1;
    break;
   case 's':
    opts.sync_clock = 1;
    break;
   case 'i':
    n = atoi(optarg);
    if (n < 1 || n > 65535) {
     log_msg(3, "invalid interval: %d", n);
     exit(1);
    }
    opts.interval = n;
    break;
         case '?':
          if (optopt == 'p'|| optopt == 'i') {
           fprintf (stderr, "option -%c requires an argument.\n",
             optopt);
          } else {
           log_msg(3, "unknown option \"-%c\". Try -h for help.",
             optopt);
    }
    exit(1);
   default:
    log_msg(3, "invalid arguments. Try -h for help.");
    exit(1);
  }
 }
 return;
}

canonical_original_code:
void parse_cmdline(int argc, char *argv[])
{
 char c;
 int n;
 extern int optind; extern int optopt; extern int opterr;
 opts.port = 7634;
 opts.interval = 30;
 opts.fork = 1;
 opts.hddtemp = 0;
 opts.pidfile = 0;
 opts.sync_clock = 0;
 opts.hddtemp_port = 7634;
 opts.precision = 0;
 while ((c = getopt(argc, argv, "hFftsPp:i:T:")) != -1) {
  switch (c) {
   case 'h':
    print_help();
    exit(0);
    break;
   case 'F':
    opts.fork = 0;
    break;
   case 'f':
    opts.pidfile = 1;
    break;
   case 't':
    opts.hddtemp = 1;
    break;
   case 'T':
    n = atoi(optarg);
    if (n < 1 || n > 65535) {
     log_msg(3, "invalid hddtemp port: %d", n);
     exit(1);
    }
    opts.hddtemp_port = n;
    break;
   case 'p':
    n = atoi(optarg);
    if (n < 1 || n > 65535) {
     log_msg(3, "invalid port: %d", n);
     exit(1);
    }
    opts.port = n;
    break;
   case 'P':
    opts.precision = 1;
    break;
   case 's':
    opts.sync_clock = 1;
    break;
   case 'i':
    n = atoi(optarg);
    if (n < 1 || n > 65535) {
     log_msg(3, "invalid interval: %d", n);
     exit(1);
    }
    opts.interval = n;
    break;
         case '?':
          if (optopt == 'p'|| optopt == 'i') {
           fprintf (stderr, "option -%c requires an argument.\n",
             optopt);
          } else {
           log_msg(3, "unknown option \"-%c\". Try -h for help.",
             optopt);
    }
    exit(1);
   default:
    log_msg(3, "invalid arguments. Try -h for help.");
    exit(1);
  }
 }
 return;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c char

variable_types: n int

variable_types: optind int

variable_types: optopt int

variable_types: opterr int


repo: lynix/vcp

decompiled_code:
void *__fastcall progress_thread(void *a1)
{
__int64 v1; // r12
__int64 v2; // rbp
unsigned int v3; // ebp
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rbp
float v8; // xmm0_4
time_t v9; // rax
unsigned __int64 v10; // r13
__int64 v11; // r14
__int64 v12; // r10
__int64 v13; // rcx
int v14; // eax
unsigned int v15; // er15
__int64 v16; // r9
unsigned int v17; // er12
__int64 v18; // r13
char v19; // al
float v20; // xmm0_4
float v21; // xmm0_4
__int64 v22; // r12
__int64 v23; // rax
__int64 v24; // rax
__int64 v25; // rax
__int64 v26; // [rsp+8h] [rbp-60h]
unsigned int v27; // [rsp+8h] [rbp-60h]
time_t timer; // [rsp+20h] [rbp-48h] BYREF
time_t v29; // [rsp+28h] [rbp-40h] BYREF

v1 = *(_QWORD *)(file_list + 32);
v2 = *(_QWORD *)(file_list + 24);
time(&timer);
if ( *(_QWORD *)(file_list + 8) <= 1uLL )
{
if ( (*(_BYTE *)options & 1) != 0 )
{
print_progr_bs(0LL, &unk_8E9, 0LL, 0LL, 0LL);
}
else
{
v25 = size_str(*((_QWORD *)a1 + 5));
print_progr_ps(0LL, v25, &unk_8E9, 0LL, 0LL, 0LL);
}
}
else
{
v3 = (char)(__int16)((long double)v1 / (long double)v2 * 100.0);
if ( (*(_BYTE *)options & 1) != 0 )
{
print_progr_bm(0LL, v3, &unk_8E9, 0LL, 0LL, 0LL);
}
else
{
v4 = size_str(*(_QWORD *)(file_list + 24));
v5 = size_str(*((_QWORD *)a1 + 5));
print_progr_pm(0LL, v3, v5, v4, &unk_8E9, 0LL, 0LL);
}
}
while ( progress_alive )
{
sleep(1u);
pthread_mutex_lock(&progress_lock);
v6 = progress_bytes;
pthread_mutex_unlock(&progress_lock);
if ( v6 )
{
while ( progress_alive )
{
pthread_mutex_lock(&progress_lock);
v22 = progress_bytes;
time(&v29);
pthread_mutex_unlock(&progress_lock);
v9 = v29 - timer;
if ( v22 >= 0 )
v8 = (float)(int)v22;
else
v8 = (float)(v22 & 1 | (unsigned int)((unsigned __int64)v22 >> 1))
+ (float)(v22 & 1 | (unsigned int)((unsigned __int64)v22 >> 1));
if ( v9 <= 0 )
LODWORD(v9) = 1;
v10 = (unsigned int)(int)(float)(v8 / (float)(int)v9);
v11 = size_str(v10);
v12 = *(_QWORD *)(file_list + 24);
v13 = v22 + *(_QWORD *)(file_list + 32);
v14 = (v12 - v13) / v10;
v15 = (char)(int)(float)((float)(v8 / (float)(int)*((_QWORD *)a1 + 5)) * 100.0);
v16 = (unsigned int)(char)(v14 / 3600);
v17 = v14 % 60;
v18 = (unsigned int)(v14 % 3600 / 60);
if ( (unsigned __int8)(v14 / 3600) >= 0x64u )
v16 = 99LL;
v19 = *(_BYTE *)options & 1;
if ( *(_QWORD *)(file_list + 8) <= 1uLL )
{
if ( v19 )
{
print_progr_bs(v15, v11, v17, (unsigned int)v18, (unsigned int)v16);
}
else
{
v27 = v16;
v24 = size_str(*((_QWORD *)a1 + 5));
print_progr_ps(v15, v24, v11, v17, (unsigned int)v18, v27);
}
}
else
{
if ( v13 < 0 )
v20 = (float)(v13 & 1 | (unsigned int)((unsigned __int64)v13 >> 1))
+ (float)(v13 & 1 | (unsigned int)((unsigned __int64)v13 >> 1));
else
v20 = (float)(int)v13;
v21 = (float)(v20 / (float)(int)v12) * 100.0;
if ( v19 )
{
print_progr_bm(v15, (unsigned int)(char)(int)v21, v11, v17, (unsigned int)v18, v16);
}
else
{
v26 = size_str(*(_QWORD *)(file_list + 24));
v23 = size_str(*((_QWORD *)a1 + 5));
print_progr_pm(v15, (unsigned int)(char)(int)v21, v23, v26, v11, v17, v18);
}
}
fflush(stdout);
if ( !progress_alive )
break;
sleep(1u);
}
break;
}
}
putchar(13);
putchar(10);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v1; // r12
__int64 v2; // rbp
unsigned int v3; // ebp
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rbp
float v8; // xmm0_4
time_t v9; // rax
unsigned __int64 v10; // r13
__int64 v11; // r14
__int64 v12; // r10
__int64 v13; // rcx
int v14; // eax
unsigned int v15; // er15
__int64 v16; // r9
unsigned int v17; // er12
__int64 v18; // r13
char v19; // al
float v20; // xmm0_4
float v21; // xmm0_4
__int64 v22; // r12
__int64 v23; // rax
__int64 v24; // rax
__int64 v25; // rax
__int64 v26; // [rsp+8h] [rbp-60h]
unsigned int v27; // [rsp+8h] [rbp-60h]
time_t timer; // [rsp+20h] [rbp-48h] BYREF
time_t v29; // [rsp+28h] [rbp-40h] BYREF

v1 = *(_QWORD *)(file_list + 32);
v2 = *(_QWORD *)(file_list + 24);
time(&timer);
if ( *(_QWORD *)(file_list + 8) <= 1uLL )
{
if ( (*(_BYTE *)options & 1) != 0 )
{
print_progr_bs(0LL, &unk_8E9, 0LL, 0LL, 0LL);
}
else
{
v25 = size_str(*((_QWORD *)a1 + 5));
print_progr_ps(0LL, v25, &unk_8E9, 0LL, 0LL, 0LL);
}
}
else
{
v3 = (char)(__int16)((long double)v1 / (long double)v2 * 100.0);
if ( (*(_BYTE *)options & 1) != 0 )
{
print_progr_bm(0LL, v3, &unk_8E9, 0LL, 0LL, 0LL);
}
else
{
v4 = size_str(*(_QWORD *)(file_list + 24));
v5 = size_str(*((_QWORD *)a1 + 5));
print_progr_pm(0LL, v3, v5, v4, &unk_8E9, 0LL, 0LL);
}
}
while ( progress_alive )
{
sleep(1u);
pthread_mutex_lock(&progress_lock);
v6 = progress_bytes;
pthread_mutex_unlock(&progress_lock);
if ( v6 )
{
while ( progress_alive )
{
pthread_mutex_lock(&progress_lock);
v22 = progress_bytes;
time(&v29);
pthread_mutex_unlock(&progress_lock);
v9 = v29 - timer;
if ( v22 >= 0 )
v8 = (float)(int)v22;
else
v8 = (float)(v22 & 1 | (unsigned int)((unsigned __int64)v22 >> 1))
+ (float)(v22 & 1 | (unsigned int)((unsigned __int64)v22 >> 1));
if ( v9 <= 0 )
LODWORD(v9) = 1;
v10 = (unsigned int)(int)(float)(v8 / (float)(int)v9);
v11 = size_str(v10);
v12 = *(_QWORD *)(file_list + 24);
v13 = v22 + *(_QWORD *)(file_list + 32);
v14 = (v12 - v13) / v10;
v15 = (char)(int)(float)((float)(v8 / (float)(int)*((_QWORD *)a1 + 5)) * 100.0);
v16 = (unsigned int)(char)(v14 / 3600);
v17 = v14 % 60;
v18 = (unsigned int)(v14 % 3600 / 60);
if ( (unsigned __int8)(v14 / 3600) >= 0x64u )
v16 = 99LL;
v19 = *(_BYTE *)options & 1;
if ( *(_QWORD *)(file_list + 8) <= 1uLL )
{
if ( v19 )
{
print_progr_bs(v15, v11, v17, (unsigned int)v18, (unsigned int)v16);
}
else
{
v27 = v16;
v24 = size_str(*((_QWORD *)a1 + 5));
print_progr_ps(v15, v24, v11, v17, (unsigned int)v18, v27);
}
}
else
{
if ( v13 < 0 )
v20 = (float)(v13 & 1 | (unsigned int)((unsigned __int64)v13 >> 1))
+ (float)(v13 & 1 | (unsigned int)((unsigned __int64)v13 >> 1));
else
v20 = (float)(int)v13;
v21 = (float)(v20 / (float)(int)v12) * 100.0;
if ( v19 )
{
print_progr_bm(v15, (unsigned int)(char)(int)v21, v11, v17, (unsigned int)v18, v16);
}
else
{
v26 = size_str(*(_QWORD *)(file_list + 24));
v23 = size_str(*((_QWORD *)a1 + 5));
print_progr_pm(v15, (unsigned int)(char)(int)v21, v23, v26, v11, v17, v18);
}
}
fflush(stdout);
if ( !progress_alive )
break;
sleep(1u);
}
break;
}
}
putchar(13);
putchar(10);
return 0LL;
}

original_code:
void *progress_thread(void *arg)
{
    file_t *item = (file_t *)arg;
    time_t start, now, elapsed;
    char perc_t, perc_f, *speed;
    off_t bytes_per_sec;
    size_t bytes_written;
    int remaining_s;
    char eta_h, eta_m, eta_s;
    perc_t = (long double)file_list->bytes_done / file_list->size * 100;
    bytes_written = 0;
    time(&start);
    if (file_list->count_f > 1) {
        if (options->bars) {
            print_progr_bm(0, perc_t, "0b", 0, 0, 0);
        } else {
            print_progr_pm(0, perc_t, size_str(item->size),
                           size_str(file_list->size), "0b", 0, 0, 0);
        }
    } else {
        if (options->bars) {
            print_progr_bs(0, "0b", 0, 0, 0);
        } else {
            print_progr_ps(0, size_str(item->size), "0b", 0, 0, 0);
        }
    }
    while (progress_alive) {
        sleep(1);
        pthread_mutex_lock(&progress_lock);
        bytes_written = progress_bytes;
        pthread_mutex_unlock(&progress_lock);
        if (bytes_written > 0) {
            break;
        }
    }
    while (progress_alive) {
        pthread_mutex_lock(&progress_lock);
        bytes_written = progress_bytes;
        time(&now);
        pthread_mutex_unlock(&progress_lock);
        elapsed = now - start;
        if (elapsed <= 0) {
            elapsed = 1;
        }
        bytes_per_sec = (float)bytes_written / elapsed;
        speed = size_str(bytes_per_sec);
        perc_f = (float)bytes_written / item->size * 100;
        perc_t = (float)(file_list->bytes_done + bytes_written) /
                 file_list->size * 100;
        remaining_s = (file_list->size - (file_list->bytes_done +
                                          bytes_written)) / bytes_per_sec;
        eta_s = remaining_s % 60;
        eta_m = (remaining_s % 3600) / 60;
        eta_h = remaining_s / 3600;
        if (eta_h > 99 || eta_h < 0) {
            eta_h = 99;
        }
        if (file_list->count_f > 1) {
            if (options->bars) {
                print_progr_bm(perc_f, perc_t, speed, eta_s, eta_m, eta_h);
            } else {
                print_progr_pm(perc_f, perc_t, size_str(item->size),
                               size_str(file_list->size), speed, eta_s, eta_m, eta_h);
            }
        } else {
            if (options->bars) {
                print_progr_bs(perc_f, speed, eta_s, eta_m, eta_h);
            } else {
                print_progr_ps(perc_f, size_str(item->size), speed, eta_s, eta_m, eta_h);
            }
        }
        fflush(stdout);
        if (!progress_alive) {
            break;
        }
        sleep(1);
    }
    putchar('\r');
    putchar('\n');
    return ((void *)0);
}

canonical_original_code:
void *progress_thread(void *arg)
{
    struct file_t *item = (file_t *)arg;
    long start; long now; long elapsed;
    char perc_t; char perc_f; char *speed;
    long bytes_per_sec;
    unsigned long bytes_written;
    int remaining_s;
    char eta_h; char eta_m; char eta_s;
    perc_t = (long double)file_list->bytes_done / file_list->size * 100;
    bytes_written = 0;
    time(&start);
    if (file_list->count_f > 1) {
        if (options->bars) {
            print_progr_bm(0, perc_t, "0b", 0, 0, 0);
        } else {
            print_progr_pm(0, perc_t, size_str(item->size),
                           size_str(file_list->size), "0b", 0, 0, 0);
        }
    } else {
        if (options->bars) {
            print_progr_bs(0, "0b", 0, 0, 0);
        } else {
            print_progr_ps(0, size_str(item->size), "0b", 0, 0, 0);
        }
    }
    while (progress_alive) {
        sleep(1);
        pthread_mutex_lock(&progress_lock);
        bytes_written = progress_bytes;
        pthread_mutex_unlock(&progress_lock);
        if (bytes_written > 0) {
            break;
        }
    }
    while (progress_alive) {
        pthread_mutex_lock(&progress_lock);
        bytes_written = progress_bytes;
        time(&now);
        pthread_mutex_unlock(&progress_lock);
        elapsed = now - start;
        if (elapsed <= 0) {
            elapsed = 1;
        }
        bytes_per_sec = (float)bytes_written / elapsed;
        speed = size_str(bytes_per_sec);
        perc_f = (float)bytes_written / item->size * 100;
        perc_t = (float)(file_list->bytes_done + bytes_written) /
                 file_list->size * 100;
        remaining_s = (file_list->size - (file_list->bytes_done +
                                          bytes_written)) / bytes_per_sec;
        eta_s = remaining_s % 60;
        eta_m = (remaining_s % 3600) / 60;
        eta_h = remaining_s / 3600;
        if (eta_h > 99 || eta_h < 0) {
            eta_h = 99;
        }
        if (file_list->count_f > 1) {
            if (options->bars) {
                print_progr_bm(perc_f, perc_t, speed, eta_s, eta_m, eta_h);
            } else {
                print_progr_pm(perc_f, perc_t, size_str(item->size),
                               size_str(file_list->size), speed, eta_s, eta_m, eta_h);
            }
        } else {
            if (options->bars) {
                print_progr_bs(perc_f, speed, eta_s, eta_m, eta_h);
            } else {
                print_progr_ps(perc_f, size_str(item->size), speed, eta_s, eta_m, eta_h);
            }
        }
        fflush(stdout);
        if (!progress_alive) {
            break;
        }
        sleep(1);
    }
    putchar('\r');
    putchar('\n');
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t { RFILE=0, RDIR=1, SLINK=2 } type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf { long actime; long modtime; } times; char done; } *

variable_types: start long

variable_types: elapsed long

variable_types:
speed
char *

user_defined_types: struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf times; char done; }


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

if ( !access(*(const char **)(a1 + 16), 0) && remove(*(const char **)(a1 + 16)) )
{
fail_append(a2, *(_QWORD *)(a1 + 16), "unable to delete link");
result = -1;
}
else
{
result = symlink(*(const char **)(a1 + 24), *(const char **)(a1 + 16));
if ( result )
{
fail_append(a2, *(_QWORD *)(a1 + 16), "unable to create symlink");
result = -1;
}
}
return result;
}

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

if ( !access(*(const char **)(a1 + 16), 0) && remove(*(const char **)(a1 + 16)) )
{
fail_append(a2, *(_QWORD *)(a1 + 16), "unable to delete link");
result = -1;
}
else
{
result = symlink(*(const char **)(a1 + 24), *(const char **)(a1 + 16));
if ( result )
{
fail_append(a2, *(_QWORD *)(a1 + 16), "unable to create symlink");
result = -1;
}
}
return result;
}

original_code:
int copy_link(file_t *file, strlist_t *fail_list)
{
    if ((access(file->dst, 0) == 0) && (remove(file->dst) != 0)) {
        fail_append(fail_list, file->dst, "unable to delete link");
        return -1;
    }
    if (symlink(file->ldst, file->dst) != 0) {
        fail_append(fail_list, file->dst, "unable to create symlink");
        return -1;
    }
    return 0;
}

canonical_original_code:
int copy_link(struct file_t *file, struct strlist_t *fail_list)
{
    if ((access(file->dst, 0) == 0) && (remove(file->dst) != 0)) {
        fail_append(fail_list, file->dst, "unable to delete link");
        return -1;
    }
    if (symlink(file->ldst, file->dst) != 0) {
        fail_append(fail_list, file->dst, "unable to create symlink");
        return -1;
    }
    return 0;
}

variable_types: struct strlist_t { unsigned long count; unsigned long arr_size; char **items; } *

user_defined_types: enum ftype_t { RFILE=0, RDIR=1, SLINK=2 }

user_defined_types: struct utimbuf { long actime; long modtime; }


decompiled_code:
__int64 __fastcall copy_dir(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( access(*(const char **)(a1 + 16), 0) && mkdir(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 56)) )
{
fail_append(a3, *(_QWORD *)(a1 + 16), "unable to create directory");
result = 0xFFFFFFFFLL;
}
else
{
result = f_clone_attrs(a1);
if ( (_DWORD)result )
{
if ( (*(_BYTE *)(a2 + 1) & 8) != 0 )
{
result = 0LL;
}
else
{
fail_append(a3, *(_QWORD *)(a1 + 16), "failed to apply attributes");
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

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

if ( access(*(const char **)(a1 + 16), 0) && mkdir(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 56)) )
{
fail_append(a3, *(_QWORD *)(a1 + 16), "unable to create directory");
result = 0xFFFFFFFFLL;
}
else
{
result = f_clone_attrs(a1);
if ( (_DWORD)result )
{
if ( (*(_BYTE *)(a2 + 1) & 8) != 0 )
{
result = 0LL;
}
else
{
fail_append(a3, *(_QWORD *)(a1 + 16), "failed to apply attributes");
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int copy_dir(file_t *file, opts_t *opts, strlist_t *fail_list)
{
    if (access(file->dst, 0) != 0 && mkdir(file->dst, file->mode) != 0) {
        fail_append(fail_list, file->dst, "unable to create directory");
        return -1;
    }
    if (f_clone_attrs(file) && !opts->ignore_uid_err) {
        fail_append(fail_list, file->dst, "failed to apply attributes");
        return -1;
    }
    return 0;
}

canonical_original_code:
int copy_dir(struct file_t *file, struct opts_t *opts, struct strlist_t *fail_list)
{
    if (access(file->dst, 0) != 0 && mkdir(file->dst, file->mode) != 0) {
        fail_append(fail_list, file->dst, "unable to create directory");
        return -1;
    }
    if (f_clone_attrs(file) && !opts->ignore_uid_err) {
        fail_append(fail_list, file->dst, "failed to apply attributes");
        return -1;
    }
    return 0;
}

variable_types: struct opts_t { unsigned int bars; unsigned int force; unsigned int filenames; unsigned int sync; unsigned int delete; unsigned int keep; unsigned int quiet; unsigned int update; unsigned int verbose; unsigned int pretend; unsigned int debug; unsigned int ignore_uid_err; } *

user_defined_types: struct strlist_t { unsigned long count; unsigned long arr_size; char **items; }


decompiled_code:
__int64 __fastcall work_list(unsigned __int64 *a1)
{
__int64 v1; // rax
unsigned __int64 *v2; // r13
void *v3; // rax
void *v4; // r14
unsigned __int64 v5; // r12
int v6; // eax
unsigned __int64 v7; // rbx
__int64 v8; // rbx
bool v9; // cf
unsigned __int64 v10; // rbx
unsigned __int64 v11; // rax
__int64 v12; // r12
__int64 result; // rax
unsigned __int64 v14; // rbx
const char *v15; // rsi

v1 = strlist_new();
if ( !v1 )
{
print_error("failed to create fail_list");
return 0xFFFFFFFFLL;
}
v2 = (unsigned __int64 *)v1;
v3 = malloc(0x100000uLL);
v4 = v3;
if ( !v3 )
{
print_error("failed to allocate I/O buffer");
strlist_delete(v2);
return 0xFFFFFFFFLL;
}
v5 = 0LL;
if ( !*a1 )
{
free(v3);
goto LABEL_21;
}
do
{
while ( 1 )
{
v8 = *(_QWORD *)(a1[5] + 8 * v5);
if ( *(_BYTE *)(v8 + 80) == 1 )
goto LABEL_8;
if ( (*(&opts + 1) & 1) != 0 )
{
puts(*(const char **)(v8 + 8));
v6 = *(_DWORD *)(v8 + 32);
if ( v6 == 1 )
{
LABEL_12:
if ( !(unsigned int)copy_dir(v8, &opts, v2) )
break;
goto LABEL_8;
}
}
else
{
v6 = *(_DWORD *)(v8 + 32);
if ( v6 == 1 )
goto LABEL_12;
}
if ( v6 != 2 )
{
if ( !v6 && !(unsigned int)copy_file(v8, a1, v2, &opts, v4, 0x100000LL) )
{
*(_BYTE *)(v8 + 80) = 1;
a1[4] += *(_QWORD *)(v8 + 40);
}
goto LABEL_8;
}
if ( !(unsigned int)copy_link(v8, v2) )
break;
LABEL_8:
v7 = *a1;
if ( *a1 <= ++v5 )
goto LABEL_14;
}
*(_BYTE *)(v8 + 80) = 1;
v7 = *a1;
++v5;
}
while ( *a1 > v5 );
LABEL_14:
free(v4);
v9 = v7 != 0;
v10 = v7 - 1;
if ( v9 )
{
do
{
while ( 1 )
{
v11 = a1[5];
v12 = *(_QWORD *)(v11 + 8 * v10);
if ( *(_BYTE *)(v12 + 80) == 1 )
break;
--v10;
print_debug("skipping failed item '%s'", *(const char **)v12);
if ( *a1 <= v10 )
goto LABEL_21;
}
if ( *(_DWORD *)(v12 + 32) == 1
&& (unsigned int)f_clone_attrs(*(_QWORD *)(v11 + 8 * v10))
&& (*(&opts + 1) & 8) == 0 )
{
fail_append(v2, *(_QWORD *)(v12 + 16), "unable to set attributes");
*(_BYTE *)(v12 + 80) = 0;
}
else if ( (opts & 0x10) != 0 && remove(*(const char **)(v12 + 8)) )
{
fail_append(v2, *(_QWORD *)(v12 + 8), "failed to delete");
*(_BYTE *)(v12 + 80) = 0;
}
--v10;
}
while ( *a1 > v10 );
}
LABEL_21:
if ( *v2 )
{
v14 = 0LL;
print_error("the following errors occured:");
if ( *v2 )
{
do
{
v15 = *(const char **)(v2[2] + 8 * v14++);
printf(" %s\n", v15);
}
while ( *v2 > v14 );
}
strlist_delete(v2);
result = 0xFFFFFFFFLL;
}
else
{
strlist_delete(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 *a1)
{
__int64 v1; // rax
unsigned __int64 *v2; // r13
void *v3; // rax
void *v4; // r14
unsigned __int64 v5; // r12
int v6; // eax
unsigned __int64 v7; // rbx
__int64 v8; // rbx
bool v9; // cf
unsigned __int64 v10; // rbx
unsigned __int64 v11; // rax
__int64 v12; // r12
__int64 result; // rax
unsigned __int64 v14; // rbx
const char *v15; // rsi

v1 = strlist_new();
if ( !v1 )
{
print_error("failed to create fail_list");
return 0xFFFFFFFFLL;
}
v2 = (unsigned __int64 *)v1;
v3 = malloc(0x100000uLL);
v4 = v3;
if ( !v3 )
{
print_error("failed to allocate I/O buffer");
strlist_delete(v2);
return 0xFFFFFFFFLL;
}
v5 = 0LL;
if ( !*a1 )
{
free(v3);
goto LABEL_21;
}
do
{
while ( 1 )
{
v8 = *(_QWORD *)(a1[5] + 8 * v5);
if ( *(_BYTE *)(v8 + 80) == 1 )
goto LABEL_8;
if ( (*(&opts + 1) & 1) != 0 )
{
puts(*(const char **)(v8 + 8));
v6 = *(_DWORD *)(v8 + 32);
if ( v6 == 1 )
{
LABEL_12:
if ( !(unsigned int)copy_dir(v8, &opts, v2) )
break;
goto LABEL_8;
}
}
else
{
v6 = *(_DWORD *)(v8 + 32);
if ( v6 == 1 )
goto LABEL_12;
}
if ( v6 != 2 )
{
if ( !v6 && !(unsigned int)copy_file(v8, a1, v2, &opts, v4, 0x100000LL) )
{
*(_BYTE *)(v8 + 80) = 1;
a1[4] += *(_QWORD *)(v8 + 40);
}
goto LABEL_8;
}
if ( !(unsigned int)copy_link(v8, v2) )
break;
LABEL_8:
v7 = *a1;
if ( *a1 <= ++v5 )
goto LABEL_14;
}
*(_BYTE *)(v8 + 80) = 1;
v7 = *a1;
++v5;
}
while ( *a1 > v5 );
LABEL_14:
free(v4);
v9 = v7 != 0;
v10 = v7 - 1;
if ( v9 )
{
do
{
while ( 1 )
{
v11 = a1[5];
v12 = *(_QWORD *)(v11 + 8 * v10);
if ( *(_BYTE *)(v12 + 80) == 1 )
break;
--v10;
print_debug("skipping failed item '%s'", *(const char **)v12);
if ( *a1 <= v10 )
goto LABEL_21;
}
if ( *(_DWORD *)(v12 + 32) == 1
&& (unsigned int)f_clone_attrs(*(_QWORD *)(v11 + 8 * v10))
&& (*(&opts + 1) & 8) == 0 )
{
fail_append(v2, *(_QWORD *)(v12 + 16), "unable to set attributes");
*(_BYTE *)(v12 + 80) = 0;
}
else if ( (opts & 0x10) != 0 && remove(*(const char **)(v12 + 8)) )
{
fail_append(v2, *(_QWORD *)(v12 + 8), "failed to delete");
*(_BYTE *)(v12 + 80) = 0;
}
--v10;
}
while ( *a1 > v10 );
}
LABEL_21:
if ( *v2 )
{
v14 = 0LL;
print_error("the following errors occured:");
if ( *v2 )
{
do
{
v15 = *(const char **)(v2[2] + 8 * v14++);
printf(" %s\n", v15);
}
while ( *v2 > v14 );
}
strlist_delete(v2);
result = 0xFFFFFFFFLL;
}
else
{
strlist_delete(v2);
result = 0LL;
}
return result;
}

original_code:
int work_list(flist_t *list)
{
    strlist_t *fail_list = strlist_new();
    if (fail_list == ((void *)0)) {
        print_error("failed to create fail_list");
        return -1;
    }
    char *buffer = malloc(1048576);
    if (buffer == ((void *)0)) {
        print_error("failed to allocate I/O buffer");
        strlist_delete(fail_list);
        return -1;
    }
    for (ulong i = 0; i < list->count; i++) {
        file_t *item = list->items[i];
        if (item->done == 1)
            continue;
        if (opts.verbose)
            printf("%s\n", item->src);
        if (item->type == RDIR) {
            if (copy_dir(item, &opts, fail_list) == 0)
                item->done = 1;
        } else if (item->type == SLINK) {
            if (copy_link(item, fail_list) == 0)
                item->done = 1;
        } else if (item->type == RFILE) {
            if (copy_file(item, list, fail_list, &opts, buffer, 1048576) == 0) {
                item->done = 1;
                list->bytes_done += item->size;
            }
        }
    }
    free(buffer);
    for (ulong i = list->count - 1; i < list->count; i--) {
        file_t *item = list->items[i];
        if (item->done != 1) {
            print_debug("skipping failed item '%s'", item->fname);
            continue;
        }
        if (item->type == RDIR) {
            if (f_clone_attrs(item) != 0 && !opts.ignore_uid_err) {
                fail_append(fail_list, item->dst, "unable to set attributes");
                item->done = 0;
                continue;
            }
        }
        if (opts.delete && (remove(item->src) != 0)) {
            fail_append(fail_list, item->src, "failed to delete");
            item->done = 0;
        }
    }
    if (fail_list->count > 0) {
        print_error("the following errors occured:");
        for (ulong i = 0; i < fail_list->count; i++) {
            printf("   %s\n", fail_list->items[i]);
        }
        strlist_delete(fail_list);
        return -1;
    }
    strlist_delete(fail_list);
    return 0;
}

canonical_original_code:
int work_list(struct flist_t *list)
{
    struct strlist_t *fail_list = strlist_new();
    if (fail_list == ((void *)0)) {
        print_error("failed to create fail_list");
        return -1;
    }
    char *buffer = malloc(1048576);
    if (buffer == ((void *)0)) {
        print_error("failed to allocate I/O buffer");
        strlist_delete(fail_list);
        return -1;
    }
    for (unsigned long i = 0; i < list->count; i++) {
        struct file_t *item = list->items[i];
        if (item->done == 1)
            continue;
        if (opts.verbose)
            printf("%s\n", item->src);
        if (item->type == RDIR) {
            if (copy_dir(item, &opts, fail_list) == 0)
                item->done = 1;
        } else if (item->type == SLINK) {
            if (copy_link(item, fail_list) == 0)
                item->done = 1;
        } else if (item->type == RFILE) {
            if (copy_file(item, list, fail_list, &opts, buffer, 1048576) == 0) {
                item->done = 1;
                list->bytes_done += item->size;
            }
        }
    }
    free(buffer);
    for (unsigned long i = list->count - 1; i < list->count; i--) {
        struct file_t *item = list->items[i];
        if (item->done != 1) {
            print_debug("skipping failed item '%s'", item->fname);
            continue;
        }
        if (item->type == RDIR) {
            if (f_clone_attrs(item) != 0 && !opts.ignore_uid_err) {
                fail_append(fail_list, item->dst, "unable to set attributes");
                item->done = 0;
                continue;
            }
        }
        if (opts.delete && (remove(item->src) != 0)) {
            fail_append(fail_list, item->src, "failed to delete");
            item->done = 0;
        }
    }
    if (fail_list->count > 0) {
        print_error("the following errors occured:");
        for (unsigned long i = 0; i < fail_list->count; i++) {
            printf("   %s\n", fail_list->items[i]);
        }
        strlist_delete(fail_list);
        return -1;
    }
    strlist_delete(fail_list);
    return 0;
}

variable_types: struct flist_t { unsigned long count; unsigned long count_f; unsigned long arr_size; long size; long bytes_done; struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t { RFILE=0, RDIR=1, SLINK=2 } type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf { long actime; long modtime; } times; char done; } **items; } *

variable_types:
buffer
char *

variable_types:
i
unsigned long

user_defined_types: struct flist_t { unsigned long count; unsigned long count_f; unsigned long arr_size; long size; long bytes_done; struct file_t **items; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
unsigned __int64 *v5; // rax
unsigned __int64 *v6; // rbp
char v7; // al
unsigned __int64 *v8; // rdi

init_opts(&opts, argv, envp);
umask(0);
v3 = parse_opts(&opts, (unsigned int)argc, argv);
if ( v3 >= 0 )
{
if ( argc > 2 )
{
v4 = v3;
if ( (*(&opts + 1) & 4) != 0 )
{
puts("Collecting file information...");
fflush(stdout);
}
v5 = build_list(argc, v4, (__int64)argv);
v6 = v5;
if ( v5 )
{
if ( *v5 )
{
v7 = *(&opts + 1);
if ( (v7 & 3) != 0 )
{
flist_print(v6, &opts);
v7 = *(&opts + 1);
}
v8 = v6;
if ( (v7 & 2) == 0 )
{
v8 = v6;
if ( (unsigned int)work_list(v6) )
{
flist_delete(v6);
exit(1);
}
}
flist_delete(v8);
exit(0);
}
puts("vcp: no items to copy.");
flist_delete(v6);
exit(0);
}
print_error("failed to build file list, aborting.");
exit(1);
}
print_error("insufficient arguments. Try -h for help.");
}
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
unsigned __int64 *v5; // rax
unsigned __int64 *v6; // rbp
char v7; // al
unsigned __int64 *v8; // rdi

init_opts(&opts, argv, envp);
umask(0);
v3 = parse_opts(&opts, (unsigned int)argc, argv);
if ( v3 >= 0 )
{
if ( argc > 2 )
{
v4 = v3;
if ( (*(&opts + 1) & 4) != 0 )
{
puts("Collecting file information...");
fflush(stdout);
}
v5 = build_list(argc, v4, (__int64)argv);
v6 = v5;
if ( v5 )
{
if ( *v5 )
{
v7 = *(&opts + 1);
if ( (v7 & 3) != 0 )
{
flist_print(v6, &opts);
v7 = *(&opts + 1);
}
v8 = v6;
if ( (v7 & 2) == 0 )
{
v8 = v6;
if ( (unsigned int)func1(v6) )
{
flist_delete(v6);
exit(1);
}
}
flist_delete(v8);
exit(0);
}
puts("vcp: no items to copy.");
flist_delete(v6);
exit(0);
}
print_error("failed to build file list, aborting.");
exit(1);
}
print_error("insufficient arguments. Try -h for help.");
}
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
    init_opts(&opts);
    umask(0);
    int argstart = parse_opts(&opts, argc, argv);
    if (argstart < 0)
        exit(1);
    if (argc < 3) {
        print_error("insufficient arguments. Try -h for help.");
        exit(1);
    }
    if (opts.debug) {
        puts("Collecting file information...");
        fflush(stdout);
    }
    flist_t *copy_list = build_list(argc, argstart, argv);
    if (copy_list == ((void *)0)) {
        print_error("failed to build file list, aborting.");
        exit(1);
    }
    if (copy_list->count == 0) {
        printf("vcp: no items to copy.\n");
        flist_delete(copy_list);
        exit(0);
    }
    if (opts.verbose || opts.pretend)
        flist_print(copy_list, &opts);
    if (opts.pretend) {
        flist_delete(copy_list);
        exit(0);
    }
    if (work_list(copy_list) != 0) {
        flist_delete(copy_list);
        exit(1);
    }
    flist_delete(copy_list);
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    init_opts(&opts);
    umask(0);
    int argstart = parse_opts(&opts, argc, argv);
    if (argstart < 0)
        exit(1);
    if (argc < 3) {
        print_error("insufficient arguments. Try -h for help.");
        exit(1);
    }
    if (opts.debug) {
        puts("Collecting file information...");
        fflush(stdout);
    }
    struct flist_t *copy_list = build_list(argc, argstart, argv);
    if (copy_list == ((void *)0)) {
        print_error("failed to build file list, aborting.");
        exit(1);
    }
    if (copy_list->count == 0) {
        printf("vcp: no items to copy.\n");
        flist_delete(copy_list);
        exit(0);
    }
    if (opts.verbose || opts.pretend)
        flist_print(copy_list, &opts);
    if (opts.pretend) {
        flist_delete(copy_list);
        exit(0);
    }
    if (work_list(copy_list) != 0) {
        flist_delete(copy_list);
        exit(1);
    }
    flist_delete(copy_list);
    exit(0);
}

variable_types: argc int

variable_types: argstart int


original_code:
file_t *f_new(char *src, char *dst)
{
    if (access(src, 0) != 0)
        return ((void *)0);
    struct stat fstat;
    if (lstat(src, &fstat) != 0)
        return ((void *)0);
    file_t *f_item = malloc(sizeof(file_t));
    if (f_item == ((void *)0))
        return ((void *)0);
    f_item->dst = (dst != ((void *)0)) ? strdup(dst) : ((void *)0);
    f_item->ldst = ((void *)0);
    f_item->size = 0;
    f_item->uid = 0;
    f_item->gid = 0;
    f_item->mode = 0;
    f_item->done = 0;
    f_item->src = strdup(src);
    f_item->fname = strdup(path_base(f_item->src));
    if (((((fstat.st_mode)) & 0170000) == (0120000))) {
        f_item->type = SLINK;
        f_item->ldst = malloc(fstat.st_size + 1);
        if (readlink(src, f_item->ldst, fstat.st_size) != fstat.st_size) {
            free(f_item->src);
            free(f_item->fname);
            free(f_item->ldst);
            free(f_item);
            return ((void *)0);
        }
        f_item->ldst[fstat.st_size] = '\0';
    } else {
        if (stat(src, &fstat) != 0) {
            free(f_item->src);
            free(f_item->fname);
            free(f_item);
            return ((void *)0);
        }
        f_item->uid = fstat.st_uid;
        f_item->gid = fstat.st_gid;
        f_item->mode = fstat.st_mode;
        f_item->times.actime = fstat.st_atime;
        f_item->times.modtime = fstat.st_mtime;
        if (((((fstat.st_mode)) & 0170000) == (0100000))) {
            f_item->type = RFILE;
            f_item->size = fstat.st_size;
        } else if (((((fstat.st_mode)) & 0170000) == (0040000))) {
            f_item->type = RDIR;
        } else {
            free(f_item->src);
            free(f_item->fname);
            free(f_item);
            return ((void *)0);
        }
    }
    return f_item;
}

canonical_original_code:
struct file_t *f_new(char *src, char *dst)
{
    if (access(src, 0) != 0)
        return ((void *)0);
    struct stat fstat;
    if (lstat(src, &fstat) != 0)
        return ((void *)0);
    struct file_t *f_item = malloc(sizeof(file_t));
    if (f_item == ((void *)0))
        return ((void *)0);
    f_item->dst = (dst != ((void *)0)) ? strdup(dst) : ((void *)0);
    f_item->ldst = ((void *)0);
    f_item->size = 0;
    f_item->uid = 0;
    f_item->gid = 0;
    f_item->mode = 0;
    f_item->done = 0;
    f_item->src = strdup(src);
    f_item->fname = strdup(path_base(f_item->src));
    if (((((fstat.st_mode)) & 0170000) == (0120000))) {
        f_item->type = SLINK;
        f_item->ldst = malloc(fstat.st_size + 1);
        if (readlink(src, f_item->ldst, fstat.st_size) != fstat.st_size) {
            free(f_item->src);
            free(f_item->fname);
            free(f_item->ldst);
            free(f_item);
            return ((void *)0);
        }
        f_item->ldst[fstat.st_size] = '\0';
    } else {
        if (stat(src, &fstat) != 0) {
            free(f_item->src);
            free(f_item->fname);
            free(f_item);
            return ((void *)0);
        }
        f_item->uid = fstat.st_uid;
        f_item->gid = fstat.st_gid;
        f_item->mode = fstat.st_mode;
        f_item->times.actime = fstat.st_atime;
        f_item->times.modtime = fstat.st_mtime;
        if (((((fstat.st_mode)) & 0170000) == (0100000))) {
            f_item->type = RFILE;
            f_item->size = fstat.st_size;
        } else if (((((fstat.st_mode)) & 0170000) == (0040000))) {
            f_item->type = RDIR;
        } else {
            free(f_item->src);
            free(f_item->fname);
            free(f_item);
            return ((void *)0);
        }
    }
    return f_item;
}

variable_types:
src
char *

variable_types:
dst
char *

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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

return_type: struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t { RFILE=0, RDIR=1, SLINK=2 } type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf { long actime; long modtime; } times; char done; } *


decompiled_code:
void __fastcall f_delete(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

free(*((void **)ptr + 1));
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 3);
if ( v3 )
free(v3);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

free(*((void **)ptr + 1));
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 3);
if ( v3 )
free(v3);
free(*(void **)ptr);
free(ptr);
}

original_code:
void f_delete(file_t *file)
{
    free(file->src);
    if (file->dst != ((void *)0))
        free(file->dst);
    if (file->ldst != ((void *)0))
        free(file->ldst);
    free(file->fname);
    free(file);
}

canonical_original_code:
void f_delete(struct file_t *file)
{
    free(file->src);
    if (file->dst != ((void *)0))
        free(file->dst);
    if (file->ldst != ((void *)0))
        free(file->ldst);
    free(file->fname);
    free(file);
}


original_code:
int f_equal(file_t *a, file_t *b)
{
    if (a->type != b->type)
        return 0;
    if (a->type == RFILE && a->size != b->size)
        return 0;
    if (a->uid != b->uid || a->gid != b->gid)
        return 0;
    if (a->type != SLINK && a->times.modtime != b->times.modtime)
        return 0;
    if (a->type == SLINK && strcmp(a->ldst, b->ldst) != 0)
        return 0;
    return 1;
}

canonical_original_code:
int f_equal(struct file_t *a, struct file_t *b)
{
    if (a->type != b->type)
        return 0;
    if (a->type == RFILE && a->size != b->size)
        return 0;
    if (a->uid != b->uid || a->gid != b->gid)
        return 0;
    if (a->type != SLINK && a->times.modtime != b->times.modtime)
        return 0;
    if (a->type == SLINK && strcmp(a->ldst, b->ldst) != 0)
        return 0;
    return 1;
}

variable_types:
b
struct file_t *


decompiled_code:
__int64 __fastcall f_clone_attrs(__int64 a1)
{
unsigned int v1; // er12

v1 = chown(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 48), *(_DWORD *)(a1 + 52));
if ( v1 )
{
v1 = -1;
print_debug("failed to set uid/gid");
if ( !chmod(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 56)) )
goto LABEL_3;
}
else if ( !chmod(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 56)) )
{
goto LABEL_3;
}
v1 = -1;
print_debug("failed to set mode");
LABEL_3:
if ( utime(*(const char **)(a1 + 16), (const struct utimbuf *)(a1 + 64)) )
{
v1 = -1;
print_debug("failed to set atime/mtime");
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // er12

v1 = chown(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 48), *(_DWORD *)(a1 + 52));
if ( v1 )
{
v1 = -1;
print_debug("failed to set uid/gid");
if ( !chmod(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 56)) )
goto LABEL_3;
}
else if ( !chmod(*(const char **)(a1 + 16), *(_DWORD *)(a1 + 56)) )
{
goto LABEL_3;
}
v1 = -1;
print_debug("failed to set mode");
LABEL_3:
if ( utime(*(const char **)(a1 + 16), (const struct utimbuf *)(a1 + 64)) )
{
v1 = -1;
print_debug("failed to set atime/mtime");
}
return v1;
}

original_code:
int f_clone_attrs(file_t *item)
{
    int retval = 0;
    if (chown(item->dst, item->uid, item->gid) != 0) {
        print_debug("failed to set uid/gid");
        retval = -1;
    }
    if (chmod(item->dst, item->mode) != 0) {
        print_debug("failed to set mode");
        retval = -1;
    }
    if (utime(item->dst, &(item->times)) != 0) {
        print_debug("failed to set atime/mtime");
        retval = -1;
    }
    return retval;
}

canonical_original_code:
int f_clone_attrs(struct file_t *item)
{
    int retval = 0;
    if (chown(item->dst, item->uid, item->gid) != 0) {
        print_debug("failed to set uid/gid");
        retval = -1;
    }
    if (chmod(item->dst, item->mode) != 0) {
        print_debug("failed to set mode");
        retval = -1;
    }
    if (utime(item->dst, &(item->times)) != 0) {
        print_debug("failed to set atime/mtime");
        retval = -1;
    }
    return retval;
}

variable_types: retval int


decompiled_code:
int __fastcall f_cmpr_dst(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(*(_QWORD *)a1 + 16LL), *(const char **)(*(_QWORD *)a2 + 16LL));
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(*(_QWORD *)a1 + 16LL), *(const char **)(*(_QWORD *)a2 + 16LL));
}

original_code:
int f_cmpr_dst(const void *a, const void *b)
{
    file_t *file_a = *(file_t **)a;
    file_t *file_b = *(file_t **)b;
    return strcmp(file_a->dst, file_b->dst);
}

canonical_original_code:
int f_cmpr_dst(void *a, void *b)
{
    struct file_t *file_a = *(file_t **)a;
    struct file_t *file_b = *(file_t **)b;
    return strcmp(file_a->dst, file_b->dst);
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall parse_opts(_BYTE *a1, int a2, char *const *a3)
{
char v4; // al

opterr = 0;
while ( 2 )
{
v4 = getopt(a2, a3, "bdfhkpqstuvDBQ");
if ( v4 == -1 )
return (unsigned int)optind;
switch ( v4 )
{
case '?':
if ( ((*_ctype_b_loc())[optopt] & 0x4000) != 0 )
{
print_error("unknown option \"-%c\".\nTry -h for help.", optopt);
}
else
{
print_error("unknown option character \"\\x%x\".", optopt);
print_error("Try -h for help.");
}
return 0xFFFFFFFFLL;
case 'B':
*a1 = *a1 & 0xFA | 1;
continue;
case 'D':
a1[1] |= 4u;
continue;
case 'Q':
*a1 = *a1 & 0xBB | 0x40;
continue;
case 'b':
*a1 |= 1u;
continue;
case 'd':
*a1 |= 0x10u;
continue;
case 'f':
if ( (*a1 & 0x20) != 0 )
goto LABEL_26;
*a1 |= 2u;
continue;
case 'h':
print_usage();
exit(0);
case 'k':
if ( (*a1 & 2) == 0 )
{
*a1 |= 0x20u;
continue;
}
LABEL_26:
print_error("no -f and -k at the same time\n");
return 0xFFFFFFFFLL;
case 'p':
a1[1] |= 2u;
continue;
case 'q':
*a1 |= 0x40u;
continue;
case 's':
*a1 |= 8u;
continue;
case 't':
a1[1] |= 8u;
continue;
case 'u':
*a1 |= 0x80u;
continue;
case 'v':
a1[1] |= 1u;
continue;
default:
return 0xFFFFFFFFLL;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, int a2, char *const *a3)
{
char v4; // al

opterr = 0;
while ( 2 )
{
v4 = getopt(a2, a3, "bdfhkpqstuvDBQ");
if ( v4 == -1 )
return (unsigned int)optind;
switch ( v4 )
{
case '?':
if ( ((*_ctype_b_loc())[optopt] & 0x4000) != 0 )
{
print_error("unknown option \"-%c\".\nTry -h for help.", optopt);
}
else
{
print_error("unknown option character \"\\x%x\".", optopt);
print_error("Try -h for help.");
}
return 0xFFFFFFFFLL;
case 'B':
*a1 = *a1 & 0xFA | 1;
continue;
case 'D':
a1[1] |= 4u;
continue;
case 'Q':
*a1 = *a1 & 0xBB | 0x40;
continue;
case 'b':
*a1 |= 1u;
continue;
case 'd':
*a1 |= 0x10u;
continue;
case 'f':
if ( (*a1 & 0x20) != 0 )
goto LABEL_26;
*a1 |= 2u;
continue;
case 'h':
print_usage();
exit(0);
case 'k':
if ( (*a1 & 2) == 0 )
{
*a1 |= 0x20u;
continue;
}
LABEL_26:
print_error("no -f and -k at the same time\n");
return 0xFFFFFFFFLL;
case 'p':
a1[1] |= 2u;
continue;
case 'q':
*a1 |= 0x40u;
continue;
case 's':
*a1 |= 8u;
continue;
case 't':
a1[1] |= 8u;
continue;
case 'u':
*a1 |= 0x80u;
continue;
case 'v':
a1[1] |= 1u;
continue;
default:
return 0xFFFFFFFFLL;
}
}
}

original_code:
int parse_opts(opts_t *opts, int argc, char *argv[])
{
    char c;
    extern int optind, optopt, opterr;
    opterr = 0;
    while ((c = getopt(argc, argv, "bdfhkpqstuvDBQ")) != -1) {
        switch (c) {
            case 'b':
                opts->bars = 1;
                break;
            case 'B':
                opts->bars = 1;
                opts->filenames = 0;
                break;
            case 'f':
                if (opts->keep == 0) {
                    opts->force = 1;
                } else {
                    print_error("no -f and -k at the same time\n");
                    return -1;
                }
                break;
            case 'k':
                if (opts->force == 0) {
                    opts->keep = 1;
                } else {
                    print_error("no -f and -k at the same time\n");
                    return -1;
                }
                break;
            case 's':
                opts->sync = 1;
                break;
            case 't':
                opts->ignore_uid_err = 1;
                break;
            case 'p':
                opts->pretend = 1;
                break;
            case 'q':
                opts->quiet = 1;
                break;
            case 'Q':
                opts->quiet = 1;
                opts->filenames = 0;
                break;
            case 'd':
                opts->delete = 1;
                break;
            case 'h':
                print_usage();
                exit(0);
            case 'u':
                opts->update = 1;
                break;
            case 'v':
                opts->verbose = 1;
                break;
            case 'D':
                opts->debug = 1;
                break;
            case '?':
                if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint)) {
                    print_error("unknown option \"-%c\".\nTry -h for help.",
                                optopt);
                } else {
                    print_error("unknown option character \"\\x%x\".", optopt);
                    print_error("Try -h for help.");
                }
                return -1;
            default:
                return -1;
        }
    }
    return optind;
}

canonical_original_code:
int parse_opts(struct opts_t *opts, int argc, char *argv[])
{
    char c;
    extern int optind; extern int optopt; extern int opterr;
    opterr = 0;
    while ((c = getopt(argc, argv, "bdfhkpqstuvDBQ")) != -1) {
        switch (c) {
            case 'b':
                opts->bars = 1;
                break;
            case 'B':
                opts->bars = 1;
                opts->filenames = 0;
                break;
            case 'f':
                if (opts->keep == 0) {
                    opts->force = 1;
                } else {
                    print_error("no -f and -k at the same time\n");
                    return -1;
                }
                break;
            case 'k':
                if (opts->force == 0) {
                    opts->keep = 1;
                } else {
                    print_error("no -f and -k at the same time\n");
                    return -1;
                }
                break;
            case 's':
                opts->sync = 1;
                break;
            case 't':
                opts->ignore_uid_err = 1;
                break;
            case 'p':
                opts->pretend = 1;
                break;
            case 'q':
                opts->quiet = 1;
                break;
            case 'Q':
                opts->quiet = 1;
                opts->filenames = 0;
                break;
            case 'd':
                opts->delete = 1;
                break;
            case 'h':
                print_usage();
                exit(0);
            case 'u':
                opts->update = 1;
                break;
            case 'v':
                opts->verbose = 1;
                break;
            case 'D':
                opts->debug = 1;
                break;
            case '?':
                if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint)) {
                    print_error("unknown option \"-%c\".\nTry -h for help.",
                                optopt);
                } else {
                    print_error("unknown option character \"\\x%x\".", optopt);
                    print_error("Try -h for help.");
                }
                return -1;
            default:
                return -1;
        }
    }
    return optind;
}

variable_types:
argv
char *[]

variable_types: c char

variable_types: optind int

variable_types: optopt int

variable_types: opterr int

user_defined_types: struct opts_t { unsigned int bars; unsigned int force; unsigned int filenames; unsigned int sync; unsigned int delete; unsigned int keep; unsigned int quiet; unsigned int update; unsigned int verbose; unsigned int pretend; unsigned int debug; unsigned int ignore_uid_err; }


decompiled_code:
int print_error(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("vcp: ", 1uLL, 5uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("vcp: ", 1uLL, 5uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

original_code:
void print_error(char *msg, ...)
{
    va_list argpointer;
    __builtin_va_start(argpointer,msg);
    fprintf(stderr, "vcp: ");
    vfprintf(stderr, msg, argpointer);
    fprintf(stderr, "\n");
    fflush(stderr);
    return;
}

canonical_original_code:
void print_error(char *msg, ...)
{
    __builtin_va_list argpointer;
    __builtin_va_start(argpointer,msg);
    fprintf(stderr, "vcp: ");
    vfprintf(stderr, msg, argpointer);
    fprintf(stderr, "\n");
    fflush(stderr);
    return;
}

variable_types:
msg
char *


decompiled_code:
int print_debug(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( (opts[1] & 4) != 0 )
{
va_start(arg, format);
printf("vcp (debug): ");
vprintf(format, arg);
putchar(10);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int func1(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( (opts[1] & 4) != 0 )
{
va_start(arg, format);
printf("vcp (debug): ");
vprintf(format, arg);
putchar(10);
result = fflush(stdout);
}
return result;
}

original_code:
void print_debug(char *msg, ...)
{
    extern opts_t opts;
    if (!opts.debug)
        return;
    va_list argpointer;
    __builtin_va_start(argpointer,msg);
    printf("vcp (debug): ");
    vprintf(msg, argpointer);
    printf("\n");
    fflush(stdout);
    return;
}

canonical_original_code:
void print_debug(char *msg, ...)
{
    extern struct opts_t opts;
    if (!opts.debug)
        return;
    __builtin_va_list argpointer;
    __builtin_va_start(argpointer,msg);
    printf("vcp (debug): ");
    vprintf(msg, argpointer);
    printf("\n");
    fflush(stdout);
    return;
}

variable_types: struct opts_t { unsigned int bars; unsigned int force; unsigned int filenames; unsigned int sync; unsigned int delete; unsigned int keep; unsigned int quiet; unsigned int update; unsigned int verbose; unsigned int pretend; unsigned int debug; unsigned int ignore_uid_err; }


decompiled_code:
char *__fastcall path_str(void *src, void *a2)
{
int v2; // ebx
int v3; // ebp
char *v4; // r12
char *result; // rax

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v3 + v2 + 2);
memcpy(v4, src, v2);
memcpy(&v4[v2 + 1], a2, v3);
v4[v2] = 47;
result = v4;
v4[v3 + 1 + v2] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(void *src, void *a2)
{
int v2; // ebx
int v3; // ebp
char *v4; // r12
char *result; // rax

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v3 + v2 + 2);
memcpy(v4, src, v2);
memcpy(&v4[v2 + 1], a2, v3);
v4[v2] = 47;
result = v4;
v4[v3 + 1 + v2] = 0;
return result;
}

original_code:
char *path_str(char *path, char *sub)
{
    int len_p = strlen(path);
    int len_s = strlen(sub);
    char *result = malloc(len_p + len_s + 2);
    memcpy(result, path, len_p);
    memcpy(result + len_p + 1, sub, len_s);
    result[len_p] = '/';
    result[len_p + len_s + 1] = '\0';
    return result;
}

variable_types:
path
char *

variable_types:
sub
char *

variable_types:
result
char *


decompiled_code:
char *__fastcall clean_path(char *name)
{
char *v1; // rbp
char *v2; // rax
char *v3; // rax
char *v4; // r12
char *v5; // rbp
char *v6; // r12

v1 = name;
v2 = &name[strlen(name) - 1];
if ( *v2 == 47 )
*v2 = 0;
v3 = path_base(name);
v4 = v3;
if ( name == v3 )
v1 = ".";
else
*(v3 - 1) = 0;
v5 = realpath(v1, 0LL);
v6 = path_str(v5, v4);
free(v5);
return v6;
}

canonical_decompiled_code:
char *__fastcall func4(char *name)
{
char *v1; // rbp
char *v2; // rax
char *v3; // rax
char *v4; // r12
char *v5; // rbp
char *v6; // r12

v1 = name;
v2 = &name[strlen(name) - 1];
if ( *v2 == 47 )
*v2 = 0;
v3 = path_base(name);
v4 = v3;
if ( name == v3 )
v1 = ".";
else
*(v3 - 1) = 0;
v5 = realpath(v1, 0LL);
v6 = func3(v5, v4);
free(v5);
return v6;
}

original_code:
char *clean_path(char *path)
{
    size_t len = strlen(path);
    if (path[len - 1] == '/')
        path[len - 1] = '\0';
    char *base = path_base(path);
    char *dir;
    if (base == path) {
        dir = ".";
    } else {
        dir = path;
        *(base - 1) = '\0';
    }
    dir = realpath(dir, ((void *)0));
    char *result = path_str(dir, base);
    free(dir);
    return result;
}

canonical_original_code:
char *clean_path(char *path)
{
    unsigned long len = strlen(path);
    if (path[len - 1] == '/')
        path[len - 1] = '\0';
    char *base = path_base(path);
    char *dir;
    if (base == path) {
        dir = ".";
    } else {
        dir = path;
        *(base - 1) = '\0';
    }
    dir = realpath(dir, ((void *)0));
    char *result = path_str(dir, base);
    free(dir);
    return result;
}

variable_types:
len
unsigned long

variable_types:
base
char *

variable_types:
dir
char *


original_code:
char *size_str(off_t bytes)
{
    double number = (double)bytes;
    char *unit = "B";
    if (number >= 1099511627776) {
        unit = "TiB";
        number = (double)bytes / 1099511627776;
    } else if (number >= 1073741824) {
        unit = "GiB";
        number = (double)bytes / 1073741824;
    } else if (number >= 1048576) {
        unit = "MiB";
        number = (double)bytes / 1048576;
    } else if (number >= 1024) {
        unit = "KiB";
        number = (double)bytes / 1024;
    }
    char *buffer = malloc(15);
    if (buffer == ((void *)0))
        return ((void *)0);
    snprintf(buffer, 15, "%.2f %s", number, unit);
    return buffer;
}

canonical_original_code:
char *size_str(long bytes)
{
    double number = (double)bytes;
    char *unit = "B";
    if (number >= 1099511627776) {
        unit = "TiB";
        number = (double)bytes / 1099511627776;
    } else if (number >= 1073741824) {
        unit = "GiB";
        number = (double)bytes / 1073741824;
    } else if (number >= 1048576) {
        unit = "MiB";
        number = (double)bytes / 1048576;
    } else if (number >= 1024) {
        unit = "KiB";
        number = (double)bytes / 1024;
    }
    char *buffer = malloc(15);
    if (buffer == ((void *)0))
        return ((void *)0);
    snprintf(buffer, 15, "%.2f %s", number, unit);
    return buffer;
}

variable_types: bytes long

variable_types: number double

variable_types:
unit
char *

variable_types:
buffer
char *


decompiled_code:
__int64 __fastcall ask_overwrite(__int64 a1, __int64 a2)
{
char *v2; // rax
char *v3; // rax
char v4; // bl
char v5; // al

while ( 1 )
{
printf("overwrite ");
if ( *(_DWORD *)(a1 + 32) == 2 )
{
printf("%s (symlink to %s)\n", *(const char **)(a1 + 16), *(const char **)(a1 + 24));
}
else
{
v2 = size_str(*(_QWORD *)(a1 + 40));
printf("%s (%s)\n", *(const char **)(a1 + 8), v2);
}
printf(" with ");
if ( *(_DWORD *)(a2 + 32) == 2 )
{
printf(" symlink to %s\n", *(const char **)(a2 + 24));
}
else
{
v3 = size_str(*(_QWORD *)(a2 + 40));
printf("%s (%s)\n", *(const char **)(a2 + 8), v3);
}
printf(" (Y/n)? ");
fflush(stdout);
v4 = getchar();
if ( v4 == 10 )
break;
while ( getchar() != 10 )
;
v5 = v4 & 0xDF;
if ( (v4 & 0xDF) == 89 || v4 == 110 )
return (v4 == 10) | (unsigned __int8)(v5 == 89);
}
v5 = 10;
return (v4 == 10) | (unsigned __int8)(v5 == 89);
}

original_code:
int ask_overwrite(file_t *old, file_t *new)
{
    char answer;
    do {
        printf("overwrite ");
        if (old->type != SLINK) {
            printf("%s (%s)\n", old->src, size_str(old->size));
        } else {
            printf("%s (symlink to %s)\n", old->dst, old->ldst);
        }
        printf("     with ");
        if (new->type != SLINK) {
            printf("%s (%s)\n", new->src, size_str(new->size));
        } else {
            printf(" symlink to %s\n", new->ldst);
        }
        printf(" (Y/n)? ");
        fflush(stdout);
        answer = getchar();
        if (answer != '\n') {
            while (getchar() != '\n') {
            }
        }
    } while (answer != 'Y' && answer != 'y' && answer != 'n' &&
             answer != '\n');
    if (answer == '\n' || answer == 'Y' || answer == 'y') {
        return 1;
    }
    return 0;
}

canonical_original_code:
int ask_overwrite(struct file_t *old, struct file_t *new)
{
    char answer;
    do {
        printf("overwrite ");
        if (old->type != SLINK) {
            printf("%s (%s)\n", old->src, size_str(old->size));
        } else {
            printf("%s (symlink to %s)\n", old->dst, old->ldst);
        }
        printf("     with ");
        if (new->type != SLINK) {
            printf("%s (%s)\n", new->src, size_str(new->size));
        } else {
            printf(" symlink to %s\n", new->ldst);
        }
        printf(" (Y/n)? ");
        fflush(stdout);
        answer = getchar();
        if (answer != '\n') {
            while (getchar() != '\n') {
            }
        }
    } while (answer != 'Y' && answer != 'y' && answer != 'n' &&
             answer != '\n');
    if (answer == '\n' || answer == 'Y' || answer == 'y') {
        return 1;
    }
    return 0;
}

variable_types: struct file_t { char *fname; char *src; char *dst; char *ldst; enum ftype_t { RFILE=0, RDIR=1, SLINK=2 } type; long size; unsigned int uid; unsigned int gid; unsigned int mode; struct utimbuf { long actime; long modtime; } times; char done; } *

variable_types:
new
struct file_t *

variable_types: answer char


decompiled_code:
int __fastcall fail_append(__int64 a1, __int64 a2, __int64 a3)
{
__int128 v4; // rdi
_BYTE *v6; // rax
char *v7; // rbp
int *v8; // rax
int result; // eax
__int128 v10; // rdi
int *v11; // rbx
_BYTE *v12; // rax

*(_QWORD *)&v4 = a2;
*((_QWORD *)&v4 + 1) = ": ";
v6 = strccat(v4);
*((_QWORD *)&v4 + 1) = a3;
*(_QWORD *)&v4 = v6;
v7 = strccat(v4);
v8 = _errno_location();
if ( !*v8 )
{
result = strlist_add(a1, v7);
if ( !result )
return result;
LABEL_5:
print_debug("failed to add to fail-list:");
return print_error(v7);
}
*((_QWORD *)&v10 + 1) = " (";
*(_QWORD *)&v10 = v7;
v11 = v8;
*(_QWORD *)&v10 = strccat(v10);
*((_QWORD *)&v10 + 1) = strerror(*v11);
v12 = strccat(v10);
*((_QWORD *)&v10 + 1) = ")";
*(_QWORD *)&v10 = v12;
v7 = strccat(v10);
result = strlist_add(a1, v7);
if ( result )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
__int128 v4; // rdi
_BYTE *v6; // rax
char *v7; // rbp
int *v8; // rax
int result; // eax
__int128 v10; // rdi
int *v11; // rbx
_BYTE *v12; // rax

*(_QWORD *)&v4 = a2;
*((_QWORD *)&v4 + 1) = ": ";
v6 = strccat(v4);
*((_QWORD *)&v4 + 1) = a3;
*(_QWORD *)&v4 = v6;
v7 = strccat(v4);
v8 = _errno_location();
if ( !*v8 )
{
result = strlist_add(a1, v7);
if ( !result )
return result;
LABEL_5:
func1("failed to add to fail-list:");
return func0(v7);
}
*((_QWORD *)&v10 + 1) = " (";
*(_QWORD *)&v10 = v7;
v11 = v8;
*(_QWORD *)&v10 = strccat(v10);
*((_QWORD *)&v10 + 1) = strerror(*v11);
v12 = strccat(v10);
*((_QWORD *)&v10 + 1) = ")";
*(_QWORD *)&v10 = v12;
v7 = strccat(v10);
result = strlist_add(a1, v7);
if ( result )
goto LABEL_5;
return result;
}

original_code:
void fail_append(strlist_t *fail_list, char *fname, char *error)
{
    char *errmsg;
    errmsg = strccat(fname, ": ");
    errmsg = strccat(errmsg, error);
    if ((*__errno_location ()) != 0) {
        errmsg = strccat(errmsg, " (");
        errmsg = strccat(errmsg, strerror((*__errno_location ())));
        errmsg = strccat(errmsg, ")");
    }
    if (strlist_add(fail_list, errmsg) != 0) {
        print_debug("failed to add to fail-list:");
        print_error(errmsg);
    }
    return;
}

canonical_original_code:
void fail_append(struct strlist_t *fail_list, char *fname, char *error)
{
    char *errmsg;
    errmsg = strccat(fname, ": ");
    errmsg = strccat(errmsg, error);
    if ((*__errno_location ()) != 0) {
        errmsg = strccat(errmsg, " (");
        errmsg = strccat(errmsg, strerror((*__errno_location ())));
        errmsg = strccat(errmsg, ")");
    }
    if (strlist_add(fail_list, errmsg) != 0) {
        print_debug("failed to add to fail-list:");
        print_error(errmsg);
    }
    return;
}

variable_types: struct strlist_t { unsigned long count; unsigned long arr_size; char **items; } *

variable_types:
fname
char *

variable_types:
error
char *

variable_types:
errmsg
char *


decompiled_code:
__int64 __fastcall print_progr_bs(char a1, const char *a2, char a3, char a4, char a5)
{
__int64 v7; // rbx
char *v8; // rax
__int64 v10; // [rsp-10h] [rbp-38h]

v7 = (unsigned int)a3;
v8 = bar_str(a1);
printf("\r %s %3d%% @ %s/s ETA %02d:%02d:%02d ", v8, (unsigned int)a1, a2, (unsigned int)a5, (unsigned int)a4, v7);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1, const char *a2, char a3, char a4, char a5)
{
__int64 v7; // rbx
char *v8; // rax
__int64 v10; // [rsp-10h] [rbp-38h]

v7 = (unsigned int)a3;
v8 = func6(a1);
printf("\r %s %3d%% @ %s/s ETA %02d:%02d:%02d ", v8, (unsigned int)a1, a2, (unsigned int)a5, (unsigned int)a4, v7);
return v10;
}

original_code:
inline void print_progr_bs(char perc, char *bps, char eta_s, char eta_m,
                           char eta_h)
{
    printf("\r %s %3d%% @ %s/s ETA %02d:%02d:%02d   ", bar_str(perc), perc,
           bps, eta_h, eta_m, eta_s);
    return;
}

variable_types: perc char

variable_types:
bps
char *


decompiled_code:
int __fastcall print_progr_bm(char a1, char a2, const char *a3, char a4, char a5, char a6)
{
__int64 v7; // r13
__int64 v8; // r12
__int64 v9; // rbp
char *v10; // rax
char *v12; // [rsp+8h] [rbp-40h]

v7 = (unsigned int)a4;
v8 = (unsigned int)a5;
v9 = (unsigned int)a6;
v12 = bar_str(a2);
v10 = bar_str(a1);
return printf(
"\rFile: %s %3d%% @ %s/s | Total: %s %3d%% ETA %02d:%02d:%02d ",
v10,
(unsigned int)a1,
a3,
v12,
(unsigned int)a2,
v9,
v8,
v7);
}

canonical_decompiled_code:
int __fastcall func10(char a1, char a2, const char *a3, char a4, char a5, char a6)
{
__int64 v7; // r13
__int64 v8; // r12
__int64 v9; // rbp
char *v10; // rax
char *v12; // [rsp+8h] [rbp-40h]

v7 = (unsigned int)a4;
v8 = (unsigned int)a5;
v9 = (unsigned int)a6;
v12 = func6(a2);
v10 = func6(a1);
return printf(
"\rFile: %s %3d%% @ %s/s | Total: %s %3d%% ETA %02d:%02d:%02d ",
v10,
(unsigned int)a1,
a3,
v12,
(unsigned int)a2,
v9,
v8,
v7);
}

original_code:
inline void print_progr_bm(char perc_f, char perc_t, char *bps, char eta_s,
                           char eta_m, char eta_h)
{
    printf("\rFile: %s %3d%% @ %s/s  |  Total: %s %3d%% ETA %02d:%02d:%02d   ",
           bar_str(perc_f), perc_f, bps, bar_str(perc_t), perc_t,
           eta_h, eta_m, eta_s);
    return;
}


decompiled_code:
int __fastcall print_progr_ps(char a1, const char *a2, const char *a3, char a4, char a5, char a6)
{
return printf(
"\r %3d%% of %s @ %s/s ETA %02d:%02d:%02d ",
(unsigned int)a1,
a2,
a3,
(unsigned int)a6,
(unsigned int)a5,
(unsigned int)a4);
}

canonical_decompiled_code:
int __fastcall func11(char a1, const char *a2, const char *a3, char a4, char a5, char a6)
{
return printf(
"\r %3d%% of %s @ %s/s ETA %02d:%02d:%02d ",
(unsigned int)a1,
a2,
a3,
(unsigned int)a6,
(unsigned int)a5,
(unsigned int)a4);
}

original_code:
inline void print_progr_ps(char perc, char *size, char *bps, char eta_s,
                           char eta_m, char eta_h)
{
    printf("\r %3d%% of %s @ %s/s ETA %02d:%02d:%02d   ", perc, size, bps,
           eta_h, eta_m, eta_s);
    return;
}

variable_types:
size
char *


decompiled_code:
int __fastcall print_progr_pm(char a1, char a2, const char *a3, const char *a4, const char *a5, char a6, char a7, char a8)
{
return printf(
"\rFile: %3d%% of %s @ %s/s | Total: %3d%% of %s ETA %02d:%02d:%02d ",
(unsigned int)a1,
a3,
a5,
(unsigned int)a2,
a4,
(unsigned int)a8,
(unsigned int)a7,
(unsigned int)a6);
}

canonical_decompiled_code:
int __fastcall func12(char a1, char a2, const char *a3, const char *a4, const char *a5, char a6, char a7, char a8)
{
return printf(
"\rFile: %3d%% of %s @ %s/s | Total: %3d%% of %s ETA %02d:%02d:%02d ",
(unsigned int)a1,
a3,
a5,
(unsigned int)a2,
a4,
(unsigned int)a8,
(unsigned int)a7,
(unsigned int)a6);
}

original_code:
inline void print_progr_pm(char perc_f, char perc_t, char *size_f, char *size_t,
                           char *bps, char eta_s, char eta_m, char eta_h)
{
    printf("\rFile: %3d%% of %s @ %s/s  |  Total: %3d%% of %s ETA %02d:%02d:%02d   ",
           perc_f, size_f, bps, perc_t, size_t, eta_h, eta_m, eta_s);
    return;
}