decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // ebx
unsigned int v5; // ebp
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
unsigned int v10; // ebp
const char *v11; // rax
const char *v12; // rax
const char *v13; // rax
const char *v14; // rax
unsigned int v15; // ebx
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
const char *v19; // rax
const char *v20; // rax
const char *v21; // rax
_BYTE v22[32]; // [rsp+0h] [rbp-5D8h] BYREF
char v23[1328]; // [rsp+20h] [rbp-5B8h] BYREF
int v24; // [rsp+550h] [rbp-88h]
char v25; // [rsp+554h] [rbp-84h]
char v26[8]; // [rsp+560h] [rbp-78h] BYREF
char v27[12]; // [rsp+568h] [rbp-70h] BYREF
char v28[16]; // [rsp+574h] [rbp-64h] BYREF
char v29[8]; // [rsp+584h] [rbp-54h] BYREF
char v30[20]; // [rsp+58Ch] [rbp-4Ch] BYREF
char s[56]; // [rsp+5A0h] [rbp-38h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
if ( strncmp(v3, "sg", 2uLL) || strlen(v3) > 6 )
{
fwrite("bad format of sg arg\n", 1uLL, 0x15uLL, stderr);
exit(2);
}
sprintf(s, "/dev/%s", v3);
v4 = open(s, 2);
if ( v4 >= 0 )
{
puts("ESM/ERM:");
v5 = get_vpd_page(v4, 18, 1, (__int64)v26, 50);
if ( v5 )
{
perror("get_vpd_page");
fprintf(stderr, "result = %d\n", v5);
exit(4);
}
v6 = (const char *)strzcpy(v22, v27, 8uLL);
printf("FN=%s\n", v6);
v7 = (const char *)strzcpy(v22, v28, 0xCuLL);
printf("SN=%s\n", v7);
v8 = (const char *)strzcpy(v22, v29, 4uLL);
printf("CC=%s\n", v8);
v9 = (const char *)strzcpy(v22, v30, 5uLL);
printf("FL=%s\n", v9);
puts("\nmidplane:");
v10 = get_vpd_page(v4, 18, 5, (__int64)v26, 50);
if ( v10 )
{
perror("get_vpd_page");
fprintf(stderr, "result = %d\n", v10);
exit(4);
}
v11 = (const char *)strzcpy(v22, v27, 8uLL);
printf("FN=%s\n", v11);
v12 = (const char *)strzcpy(v22, v28, 0xCuLL);
printf("SN=%s\n", v12);
v13 = (const char *)strzcpy(v22, v29, 4uLL);
printf("CC=%s\n", v13);
v14 = (const char *)strzcpy(v22, v30, 5uLL);
printf("FL=%s\n", v14);
memset(v23, 0, sizeof(v23));
v24 = 0;
v25 = 0;
puts("\npower supply 0:");
v15 = get_vpd_page(v4, 28, 7, (__int64)v23, 1333);
if ( v15 )
{
perror("get_vpd_page");
fprintf(stderr, "result = %d\n", v15);
exit(5);
}
v16 = (const char *)strzcpy(v22, &v23[1079], 8uLL);
printf("FN=%s\n", v16);
v17 = (const char *)strzcpy(v22, &v23[1090], 0xCuLL);
printf("SN=%s\n", v17);
v18 = (const char *)strzcpy(v22, &v23[1129], 5uLL);
printf("FL=%s\n", v18);
puts("\npower supply 1:");
v19 = (const char *)strzcpy(v22, &v23[1141], 8uLL);
printf("FN=%s\n", v19);
v20 = (const char *)strzcpy(v22, &v23[1152], 0xCuLL);
printf("SN=%s\n", v20);
v21 = (const char *)strzcpy(v22, &v23[1191], 5uLL);
printf("FL=%s\n", v21);
exit(0);
}
perror(s);
exit(3);
}
fprintf(stderr, "usage: %s sgN\n", *argv);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // ebx
unsigned int v5; // ebp
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
unsigned int v10; // ebp
const char *v11; // rax
const char *v12; // rax
const char *v13; // rax
const char *v14; // rax
unsigned int v15; // ebx
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
const char *v19; // rax
const char *v20; // rax
const char *v21; // rax
_BYTE v22[32]; // [rsp+0h] [rbp-5D8h] BYREF
char v23[1328]; // [rsp+20h] [rbp-5B8h] BYREF
int v24; // [rsp+550h] [rbp-88h]
char v25; // [rsp+554h] [rbp-84h]
char v26[8]; // [rsp+560h] [rbp-78h] BYREF
char v27[12]; // [rsp+568h] [rbp-70h] BYREF
char v28[16]; // [rsp+574h] [rbp-64h] BYREF
char v29[8]; // [rsp+584h] [rbp-54h] BYREF
char v30[20]; // [rsp+58Ch] [rbp-4Ch] BYREF
char s[56]; // [rsp+5A0h] [rbp-38h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
if ( strncmp(v3, "sg", 2uLL) || strlen(v3) > 6 )
{
fwrite("bad format of sg arg\n", 1uLL, 0x15uLL, stderr);
exit(2);
}
sprintf(s, "/dev/%s", v3);
v4 = open(s, 2);
if ( v4 >= 0 )
{
puts("ESM/ERM:");
v5 = func8(v4, 18, 1, (__int64)v26, 50);
if ( v5 )
{
perror("get_vpd_page");
fprintf(stderr, "result = %d\n", v5);
exit(4);
}
v6 = (const char *)func7(v22, v27, 8uLL);
printf("FN=%s\n", v6);
v7 = (const char *)func7(v22, v28, 0xCuLL);
printf("SN=%s\n", v7);
v8 = (const char *)func7(v22, v29, 4uLL);
printf("CC=%s\n", v8);
v9 = (const char *)func7(v22, v30, 5uLL);
printf("FL=%s\n", v9);
puts("\nmidplane:");
v10 = func8(v4, 18, 5, (__int64)v26, 50);
if ( v10 )
{
perror("get_vpd_page");
fprintf(stderr, "result = %d\n", v10);
exit(4);
}
v11 = (const char *)func7(v22, v27, 8uLL);
printf("FN=%s\n", v11);
v12 = (const char *)func7(v22, v28, 0xCuLL);
printf("SN=%s\n", v12);
v13 = (const char *)func7(v22, v29, 4uLL);
printf("CC=%s\n", v13);
v14 = (const char *)func7(v22, v30, 5uLL);
printf("FL=%s\n", v14);
memset(v23, 0, sizeof(v23));
v24 = 0;
v25 = 0;
puts("\npower supply 0:");
v15 = func8(v4, 28, 7, (__int64)v23, 1333);
if ( v15 )
{
perror("get_vpd_page");
fprintf(stderr, "result = %d\n", v15);
exit(5);
}
v16 = (const char *)func7(v22, &v23[1079], 8uLL);
printf("FN=%s\n", v16);
v17 = (const char *)func7(v22, &v23[1090], 0xCuLL);
printf("SN=%s\n", v17);
v18 = (const char *)func7(v22, &v23[1129], 5uLL);
printf("FL=%s\n", v18);
puts("\npower supply 1:");
v19 = (const char *)func7(v22, &v23[1141], 8uLL);
printf("FN=%s\n", v19);
v20 = (const char *)func7(v22, &v23[1152], 0xCuLL);
printf("SN=%s\n", v20);
v21 = (const char *)func7(v22, &v23[1191], 5uLL);
printf("FL=%s\n", v21);
exit(0);
}
perror(s);
exit(3);
}
fprintf(stderr, "usage: %s sgN\n", *argv);
exit(1);
}

original_code:
int
main(int argc, char **argv)
{
 char *sg;
 char dev_sg[20];
 int fd;
 struct vpd_page vp;
 struct element_descriptor_page edp;
 int result;
 char temp[20];
 if (argc != 2) {
  fprintf(stderr, "usage: %s sgN\n", argv[0]);
  exit(1);
 }
 sg = argv[1];
 if (strncmp(sg, "sg", 2) != 0 || strlen(sg) > 6) {
  fprintf(stderr, "bad format of sg arg\n");
  exit(2);
 }
 sprintf(dev_sg, "/dev/%s", sg);
 fd = open(dev_sg, 02);
 if (fd < 0) {
  perror(dev_sg);
  exit(3);
 }
 printf("ESM/ERM:\n");
 result = get_vpd_page(fd, 0x12, 1, &vp, sizeof(vp));
 if (result != 0) {
  perror("get_vpd_page");
  fprintf(stderr, "result = %d\n", result);
  exit(4);
 }
 printf("FN=%s\n", strzcpy(temp, vp.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, vp.serial_number, 12));
 printf("CC=%s\n", strzcpy(temp, vp.model_number, 4));
 printf("FL=%s\n", strzcpy(temp, vp.fru_label, 5));
 printf("\nmidplane:\n");
 result = get_vpd_page(fd, 0x12, 5, &vp, sizeof(vp));
 if (result != 0) {
  perror("get_vpd_page");
  fprintf(stderr, "result = %d\n", result);
  exit(4);
 }
 printf("FN=%s\n", strzcpy(temp, vp.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, vp.serial_number, 12));
 printf("CC=%s\n", strzcpy(temp, vp.model_number, 4));
 printf("FL=%s\n", strzcpy(temp, vp.fru_label, 5));
 memset(&edp, 0, sizeof(edp));
 printf("\npower supply 0:\n");
 result = get_vpd_page(fd, 0x1c, 7, &edp, sizeof(edp));
 if (result != 0) {
  perror("get_vpd_page");
  fprintf(stderr, "result = %d\n", result);
  exit(5);
 }
 printf("FN=%s\n", strzcpy(temp, edp.ps0_vpd.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, edp.ps0_vpd.serial_number, 12));
 printf("FL=%s\n", strzcpy(temp, edp.ps0_vpd.fru_label, 5));
 printf("\npower supply 1:\n");
 printf("FN=%s\n", strzcpy(temp, edp.ps1_vpd.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, edp.ps1_vpd.serial_number, 12));
 printf("FL=%s\n", strzcpy(temp, edp.ps1_vpd.fru_label, 5));
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
sg
char *

variable_types: struct vpd_page { unsigned char peripheral_qualifier; unsigned char page_code; unsigned char reserved1; unsigned char page_length; unsigned char ascii_length; char fn[3]; char fru_number[8]; unsigned char reserved2; char sn[3]; char serial_number[12]; unsigned char reserved3; char cc[3]; char model_number[4]; unsigned char reserved4; char fl[3]; char fru_label[5]; unsigned char reserved5; }

variable_types: struct element_descriptor_page { char ignored1[1074]; struct power_supply_descriptor { unsigned short descriptor_length; char fn[3]; char fru_number[8]; char sn[3]; char serial_number[12]; char vendor[12]; char date_of_manufacture[12]; char fl[3]; char fru_label[5]; } ps0_vpd; unsigned short reserved; struct power_supply_descriptor ps1_vpd; char ignored2[137]; }

variable_types: result int

variable_types:
temp
char [20]

user_defined_types: struct element_descriptor_page { char ignored1[1074]; struct power_supply_descriptor ps0_vpd; unsigned short reserved; struct power_supply_descriptor ps1_vpd; char ignored2[137]; }


decompiled_code:
__int64 __fastcall add_element_status(unsigned int a1, _BYTE *a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl

result = a1;
v3 = *a2 >> 4;
if ( v3 != 5 && (a1 & 0xFFFFFFFD) == 1 && v3 > 1u )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, _BYTE *a2)
{
__int64 result; // rax
unsigned __int8 v3; // dl

result = a1;
v3 = *a2 >> 4;
if ( v3 != 5 && (a1 & 0xFFFFFFFD) == 1 && v3 > 1u )
result = v3;
return result;
}

original_code:
enum element_status_code
add_element_status(enum element_status_code cur,
    const struct element_status_byte0 *byte0)
{
 enum element_status_code s = (enum element_status_code) byte0->status;
 if (s == ES_OK || s == ES_NOT_INSTALLED)
  return cur;
 if ((cur == ES_OK || cur == ES_NONCRITICAL) && s > ES_OK)
  return s;
 return cur;
}

canonical_original_code:
enum element_status_code add_element_status(enum element_status_code cur, struct element_status_byte0 *byte0)
{
 enum element_status_code s = (enum element_status_code) byte0->status;
 if (s == ES_OK || s == ES_NOT_INSTALLED)
  return cur;
 if ((cur == ES_OK || cur == ES_NONCRITICAL) && s > ES_OK)
  return s;
 return cur;
}

variable_types: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

variable_types: struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; } *


decompiled_code:
__int64 __fastcall composite_status(_BYTE *a1, int a2)
{
_BYTE *v2; // rbx
_BYTE *v3; // rbp
unsigned int v4; // edi
__int64 result; // rax

if ( a2 <= 0 )
return 1LL;
v2 = a1;
v3 = &a1[4 * a2];
v4 = 1;
do
{
result = add_element_status(v4, v2);
v4 = result;
v2 += 4;
}
while ( v2 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, int a2)
{
_BYTE *v2; // rbx
_BYTE *v3; // rbp
unsigned int v4; // edi
__int64 result; // rax

if ( a2 <= 0 )
return 1LL;
v2 = a1;
v3 = &a1[4 * a2];
v4 = 1;
do
{
result = func8(v4, v2);
v4 = result;
v2 += 4;
}
while ( v2 != v3 );
return result;
}

original_code:
enum element_status_code
composite_status(const void* first_element, int nel)
{
 int i;
 const char *el = (const char*) first_element;
 enum element_status_code s = ES_OK;
 for (i = 0; i < nel; i++, el += 4)
  s = add_element_status(s,
   (const struct element_status_byte0*) el);
 return s;
}

canonical_original_code:
enum element_status_code composite_status(void *first_element, int nel)
{
 int i;
 char *el = (const char*) first_element;
 enum element_status_code s = ES_OK;
 for (i = 0; i < nel; i++, el += 4)
  s = add_element_status(s,
   (struct element_status_byte0 *) el);
 return s;
}

variable_types: nel int

variable_types: i int

variable_types:
el
char *

return_type: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

user_defined_types: struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; }


decompiled_code:
__int64 __fastcall roll_up_disk_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 12), 30);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func9((_BYTE *)(a1 + 12), 30);
}

original_code:
enum element_status_code
roll_up_disk_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->disk_status, 30);
}

canonical_original_code:
enum element_status_code roll_up_disk_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->disk_status, 30);
}

variable_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status { struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; } byte0; union { struct overall_disk_status_byte1 { unsigned char device_environment; unsigned char slot_address; } overall_status; struct disk_element_status_byte1 { unsigned char hot_swap; unsigned char slot_address; } element_status; } byte1; unsigned char app_client_bypassed_a; unsigned char do_not_remove; unsigned char enclosure_bypassed_a; unsigned char enclosure_bypassed_b; unsigned char ready_to_insert; unsigned char rmv; unsigned char ident; unsigned char report; unsigned char app_client_bypassed_b; unsigned char fault_sensed; unsigned char fail; unsigned char device_off; unsigned char bypassed_a; unsigned char bypassed_b; unsigned char device_bypassed_a; unsigned char device_bypassed_b; } overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char fail; unsigned char warning_indication; unsigned char reserved4; unsigned char failure_requested; unsigned char warning_requested; } overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char hot_swap; unsigned char reserved4; } overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; } overall_temp_sensor_status; struct temperature_sensor_set { struct temperature_sensor_status croc; struct temperature_sensor_status ppc; struct temperature_sensor_status expander; struct temperature_sensor_status ambient[2]; struct temperature_sensor_status power_supply[2]; } temp_sensor_sets[2]; struct fan_status { struct element_status_byte0 byte0; unsigned short ident; unsigned short reserved2; unsigned short fan_speed; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char reserved3; unsigned char speed_code; } overall_fan_status; struct fan_set { struct fan_status power_supply; struct fan_status fan_element[4]; } fan_sets[2]; struct power_supply_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char dc_over_voltage; unsigned char dc_under_voltage; unsigned char dc_over_current; unsigned char reserved4; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char ovrtmp_fail; unsigned char temp_warn; unsigned char ac_fail; unsigned char dc_fail; } overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char warn_over; unsigned char warn_under; unsigned char crit_over; unsigned char crit_under; short voltage; } overall_voltage_status; struct voltage_sensor_set { struct voltage_sensor_status sensor_12V; struct voltage_sensor_status sensor_3_3VA; } voltage_sensor_sets[2]; struct sas_connector_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char connector_type; unsigned char connector_physical_link; unsigned char reserved2; unsigned char fail; unsigned char reserved3; } overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; } overall_scc_controller_status; struct scc_controller_element_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char reserved4; } scc_controller_status[2]; struct midplane_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; } overall_midplane_status; struct midplane_status midplane_element_status; } *

user_defined_types: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

user_defined_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status overall_temp_sensor_status; struct temperature_sensor_set temp_sensor_sets[2]; struct fan_status overall_fan_status; struct fan_set fan_sets[2]; struct power_supply_status overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status overall_voltage_status; struct voltage_sensor_set voltage_sensor_sets[2]; struct sas_connector_status overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status overall_scc_controller_status; struct scc_controller_element_status scc_controller_status[2]; struct midplane_status overall_midplane_status; struct midplane_status midplane_element_status; }

user_defined_types: struct disk_status { struct element_status_byte0 byte0; union { struct overall_disk_status_byte1 overall_status; struct disk_element_status_byte1 element_status; } byte1; unsigned char app_client_bypassed_a; unsigned char do_not_remove; unsigned char enclosure_bypassed_a; unsigned char enclosure_bypassed_b; unsigned char ready_to_insert; unsigned char rmv; unsigned char ident; unsigned char report; unsigned char app_client_bypassed_b; unsigned char fault_sensed; unsigned char fail; unsigned char device_off; unsigned char bypassed_a; unsigned char bypassed_b; unsigned char device_bypassed_a; unsigned char device_bypassed_b; }


decompiled_code:
__int64 __fastcall roll_up_esm_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 144), 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return func9((_BYTE *)(a1 + 144), 2);
}

original_code:
enum element_status_code
roll_up_esm_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->esm_status, 2);
}

canonical_original_code:
enum element_status_code roll_up_esm_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->esm_status, 2);
}

user_defined_types: struct enclosure_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char fail; unsigned char warning_indication; unsigned char reserved4; unsigned char failure_requested; unsigned char warning_requested; }

user_defined_types: struct esm_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char hot_swap; unsigned char reserved4; }

user_defined_types: struct temperature_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; }

user_defined_types: struct fan_status { struct element_status_byte0 byte0; unsigned short ident; unsigned short reserved2; unsigned short fan_speed; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char reserved3; unsigned char speed_code; }

user_defined_types: struct power_supply_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char dc_over_voltage; unsigned char dc_under_voltage; unsigned char dc_over_current; unsigned char reserved4; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char ovrtmp_fail; unsigned char temp_warn; unsigned char ac_fail; unsigned char dc_fail; }

user_defined_types: struct voltage_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char warn_over; unsigned char warn_under; unsigned char crit_over; unsigned char crit_under; short voltage; }

user_defined_types: struct sas_connector_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char connector_type; unsigned char connector_physical_link; unsigned char reserved2; unsigned char fail; unsigned char reserved3; }

user_defined_types: struct scc_controller_overall_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }

user_defined_types: struct midplane_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }

user_defined_types: struct temperature_sensor_set { struct temperature_sensor_status croc; struct temperature_sensor_status ppc; struct temperature_sensor_status expander; struct temperature_sensor_status ambient[2]; struct temperature_sensor_status power_supply[2]; }

user_defined_types: struct fan_set { struct fan_status power_supply; struct fan_status fan_element[4]; }

user_defined_types: struct voltage_sensor_set { struct voltage_sensor_status sensor_12V; struct voltage_sensor_status sensor_3_3VA; }

user_defined_types: struct scc_controller_element_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char reserved4; }

user_defined_types: struct overall_disk_status_byte1 { unsigned char device_environment; unsigned char slot_address; }

user_defined_types: struct disk_element_status_byte1 { unsigned char hot_swap; unsigned char slot_address; }


decompiled_code:
__int64 __fastcall roll_up_temperature_sensor_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 156), 14);
}

original_code:
enum element_status_code
roll_up_temperature_sensor_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->temp_sensor_sets, 2 * 7);
}

canonical_original_code:
enum element_status_code roll_up_temperature_sensor_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->temp_sensor_sets, 2 * 7);
}

user_defined_types: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

user_defined_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status overall_temp_sensor_status; struct temperature_sensor_set temp_sensor_sets[2]; struct fan_status overall_fan_status; struct fan_set fan_sets[2]; struct power_supply_status overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status overall_voltage_status; struct voltage_sensor_set voltage_sensor_sets[2]; struct sas_connector_status overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status overall_scc_controller_status; struct scc_controller_element_status scc_controller_status[2]; struct midplane_status overall_midplane_status; struct midplane_status midplane_element_status; }

user_defined_types: struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; }


decompiled_code:
__int64 __fastcall roll_up_fan_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 216), 10);
}

original_code:
enum element_status_code
roll_up_fan_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->fan_sets, 2 * 5);
}

canonical_original_code:
enum element_status_code roll_up_fan_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->fan_sets, 2 * 5);
}

user_defined_types: struct disk_status { struct element_status_byte0 byte0; union { struct overall_disk_status_byte1 overall_status; struct disk_element_status_byte1 element_status; } byte1; unsigned char app_client_bypassed_a; unsigned char do_not_remove; unsigned char enclosure_bypassed_a; unsigned char enclosure_bypassed_b; unsigned char ready_to_insert; unsigned char rmv; unsigned char ident; unsigned char report; unsigned char app_client_bypassed_b; unsigned char fault_sensed; unsigned char fail; unsigned char device_off; unsigned char bypassed_a; unsigned char bypassed_b; unsigned char device_bypassed_a; unsigned char device_bypassed_b; }

user_defined_types: struct enclosure_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char fail; unsigned char warning_indication; unsigned char reserved4; unsigned char failure_requested; unsigned char warning_requested; }

user_defined_types: struct esm_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char hot_swap; unsigned char reserved4; }


decompiled_code:
__int64 __fastcall roll_up_power_supply_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 260), 2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func9((_BYTE *)(a1 + 260), 2);
}

original_code:
enum element_status_code
roll_up_power_supply_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->ps_status, 2);
}

canonical_original_code:
enum element_status_code roll_up_power_supply_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->ps_status, 2);
}

user_defined_types: struct temperature_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; }

user_defined_types: struct fan_status { struct element_status_byte0 byte0; unsigned short ident; unsigned short reserved2; unsigned short fan_speed; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char reserved3; unsigned char speed_code; }

user_defined_types: struct power_supply_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char dc_over_voltage; unsigned char dc_under_voltage; unsigned char dc_over_current; unsigned char reserved4; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char ovrtmp_fail; unsigned char temp_warn; unsigned char ac_fail; unsigned char dc_fail; }


decompiled_code:
__int64 __fastcall roll_up_voltage_sensor_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 272), 4);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func9((_BYTE *)(a1 + 272), 4);
}

original_code:
enum element_status_code
roll_up_voltage_sensor_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->voltage_sensor_sets, 2 * 2);
}

canonical_original_code:
enum element_status_code roll_up_voltage_sensor_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->voltage_sensor_sets, 2 * 2);
}

user_defined_types: struct voltage_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char warn_over; unsigned char warn_under; unsigned char crit_over; unsigned char crit_under; short voltage; }

user_defined_types: struct sas_connector_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char connector_type; unsigned char connector_physical_link; unsigned char reserved2; unsigned char fail; unsigned char reserved3; }

user_defined_types: struct scc_controller_overall_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }


decompiled_code:
__int64 __fastcall roll_up_sas_connector_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 292), 4);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return func9((_BYTE *)(a1 + 292), 4);
}

original_code:
enum element_status_code
roll_up_sas_connector_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->sas_connector_status, 4);
}

canonical_original_code:
enum element_status_code roll_up_sas_connector_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->sas_connector_status, 4);
}

user_defined_types: struct midplane_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }

user_defined_types: struct temperature_sensor_set { struct temperature_sensor_status croc; struct temperature_sensor_status ppc; struct temperature_sensor_status expander; struct temperature_sensor_status ambient[2]; struct temperature_sensor_status power_supply[2]; }

user_defined_types: struct fan_set { struct fan_status power_supply; struct fan_status fan_element[4]; }


decompiled_code:
__int64 __fastcall roll_up_scc_controller_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 312), 2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func9((_BYTE *)(a1 + 312), 2);
}

original_code:
enum element_status_code
roll_up_scc_controller_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->scc_controller_status, 2);
}

canonical_original_code:
enum element_status_code roll_up_scc_controller_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->scc_controller_status, 2);
}

user_defined_types: struct voltage_sensor_set { struct voltage_sensor_status sensor_12V; struct voltage_sensor_status sensor_3_3VA; }

user_defined_types: struct scc_controller_element_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char reserved4; }

user_defined_types: struct overall_disk_status_byte1 { unsigned char device_environment; unsigned char slot_address; }


decompiled_code:
__int64 __fastcall mean_temperature(__int64 a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rdi
int v3; // edx

v1 = (unsigned __int8 *)(a1 + 158);
v2 = (unsigned __int8 *)(a1 + 214);
v3 = 0;
do
{
v3 += *v1;
v1 += 4;
}
while ( v1 != v2 );
return (unsigned int)(v3 / 14);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rdi
int v3; // edx

v1 = (unsigned __int8 *)(a1 + 158);
v2 = (unsigned __int8 *)(a1 + 214);
v3 = 0;
do
{
v3 += *v1;
v1 += 4;
}
while ( v1 != v2 );
return (unsigned int)(v3 / 14);
}

original_code:
unsigned int
mean_temperature(const struct bluehawk_diag_page2 *pg)
{
 struct temperature_sensor_status *sensors =
    (struct temperature_sensor_status *)
    &pg->temp_sensor_sets;
 int sum = 0;
 int i;
 for (i = 0; i < 2*7; i++)
  sum += sensors[i].temperature;
 return sum / (2*7);
}

canonical_original_code:
unsigned int mean_temperature(struct bluehawk_diag_page2 *pg)
{
 struct temperature_sensor_status *sensors = (struct temperature_sensor_status *)
    &pg->temp_sensor_sets;
 int sum = 0;
 int i;
 for (i = 0; i < 2*7; i++)
  sum += sensors[i].temperature;
 return sum / (2*7);
}

variable_types: struct temperature_sensor_status { struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; } byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; } *

variable_types: sum int

return_type: unsigned int

user_defined_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status overall_temp_sensor_status; struct temperature_sensor_set temp_sensor_sets[2]; struct fan_status overall_fan_status; struct fan_set fan_sets[2]; struct power_supply_status overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status overall_voltage_status; struct voltage_sensor_set voltage_sensor_sets[2]; struct sas_connector_status overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status overall_scc_controller_status; struct scc_controller_element_status scc_controller_status[2]; struct midplane_status overall_midplane_status; struct midplane_status midplane_element_status; }

user_defined_types: struct disk_element_status_byte1 { unsigned char hot_swap; unsigned char slot_address; }


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf(
"Usage: %s --context <x> --from <y> --to <z> <value>\n"
"\t--context: currently, <x> must be cpu\n"
"\t--from and --to: allowed values for <y> and <z>:\n"
"\t\tinterrupt-server\n"
"\t\tdrc-index\n"
"\t\tdrc-name\n"
"\tif <value> is a drc-index or interrupt-server, it can be\n"
"\tspecified in decimal, hex (with a leading 0x), or octal\n"
"\t(with a leading 0); if it is a drc-name, it should be\n"
"\tspecified as a string in double quotes\n"
"\n",
a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf(
"Usage: %s --context <x> --from <y> --to <z> <value>\n"
"\t--context: currently, <x> must be cpu\n"
"\t--from and --to: allowed values for <y> and <z>:\n"
"\t\tinterrupt-server\n"
"\t\tdrc-index\n"
"\t\tdrc-name\n"
"\tif <value> is a drc-index or interrupt-server, it can be\n"
"\tspecified in decimal, hex (with a leading 0x), or octal\n"
"\t(with a leading 0); if it is a drc-name, it should be\n"
"\tspecified as a string in double quotes\n"
"\n",
a1);
}

original_code:
void
print_usage(char *command) {
 printf ("Usage: %s --context <x> --from <y> --to <z> <value>\n"
  "\t--context: currently, <x> must be cpu\n"
  "\t--from and --to: allowed values for <y> and <z>:\n"
  "\t\tinterrupt-server\n\t\tdrc-index\n\t\tdrc-name\n"
  "\tif <value> is a drc-index or interrupt-server, it can be\n"
  "\tspecified in decimal, hex (with a leading 0x), or octal\n"
  "\t(with a leading 0); if it is a drc-name, it should be\n"
  "\tspecified as a string in double quotes\n\n",
  command);
 return;
}

variable_types:
command
char *

return_type: void


decompiled_code:
__int64 __fastcall cpu_drcindex_to_drcname(int a1, __int64 a2, int a3)
{
int v4; // eax
int v5; // ebx
int i; // ebp
unsigned int v7; // ebp
int v9; // eax
__int64 v10; // r12
__int64 v11; // rbp
char v12; // al
char v13; // [rsp+Bh] [rbp-2Dh] BYREF
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
if ( v4 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
return 0;
}
v5 = v4;
read(v4, buf, 4uLL);
for ( i = 0; ; ++i )
{
if ( !read(v5, buf, 4uLL) )
{
close(v5);
v7 = 0;
LABEL_12:
close(v5);
return v7;
}
if ( buf[0] == a1 )
break;
}
close(v5);
v9 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
v5 = v9;
if ( v9 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
return 0;
}
read(v9, buf, 4uLL);
if ( i <= 0 )
{
LABEL_19:
v10 = i;
v11 = (unsigned int)(a3 - 1 - i) + (__int64)i;
do
{
if ( read(v5, &v13, 1uLL) != 1 )
{
v7 = 1;
goto LABEL_12;
}
if ( v10 == v11 )
{
*(_BYTE *)(a2 + (int)v10) = 0;
v7 = 1;
goto LABEL_12;
}
v12 = v13;
*(_BYTE *)(a2 + v10++) = v13;
}
while ( v12 );
v7 = 1;
goto LABEL_12;
}
while ( read(v5, &v13, 1uLL) == 1 )
{
if ( !v13 && !--i )
goto LABEL_19;
}
close(v5);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2, int a3)
{
int v4; // eax
int v5; // ebx
int i; // ebp
unsigned int v7; // ebp
int v9; // eax
__int64 v10; // r12
__int64 v11; // rbp
char v12; // al
char v13; // [rsp+Bh] [rbp-2Dh] BYREF
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
if ( v4 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
return 0;
}
v5 = v4;
read(v4, buf, 4uLL);
for ( i = 0; ; ++i )
{
if ( !read(v5, buf, 4uLL) )
{
close(v5);
v7 = 0;
LABEL_12:
close(v5);
return v7;
}
if ( buf[0] == a1 )
break;
}
close(v5);
v9 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
v5 = v9;
if ( v9 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
return 0;
}
read(v9, buf, 4uLL);
if ( i <= 0 )
{
LABEL_19:
v10 = i;
v11 = (unsigned int)(a3 - 1 - i) + (__int64)i;
do
{
if ( read(v5, &v13, 1uLL) != 1 )
{
v7 = 1;
goto LABEL_12;
}
if ( v10 == v11 )
{
*(_BYTE *)(a2 + (int)v10) = 0;
v7 = 1;
goto LABEL_12;
}
v12 = v13;
*(_BYTE *)(a2 + v10++) = v13;
}
while ( v12 );
v7 = 1;
goto LABEL_12;
}
while ( read(v5, &v13, 1uLL) == 1 )
{
if ( !v13 && !--i )
goto LABEL_19;
}
close(v5);
return 0;
}

original_code:
int
cpu_drcindex_to_drcname(uint32_t drc_idx, char *drc_name, int buf_size) {
 int fd, offset=0, found=0;
 uint32_t index;
 uint8_t ch;
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-indexes");
  return 0;
 }
 read(fd, &index, 4);
 while ((read(fd, &index, 4)) != 0) {
  if (index == drc_idx) {
   found = 1;
   break;
  }
  offset++;
 }
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-names");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   do {
    if ((read(fd, &ch, 1)) != 1) {
     close(fd);
     return 0;
    }
   } while (ch != 0);
   offset--;
  }
  while ((read(fd, &ch, 1)) == 1) {
   if (offset+1 == buf_size) {
    drc_name[offset] = '\0';
    break;
   }
   drc_name[offset++] = ch;
   if (ch == 0)
    break;
  }
 }
 close(fd);
 return found;
}

canonical_original_code:
int cpu_drcindex_to_drcname(unsigned int drc_idx, char *drc_name, int buf_size) {
 int fd; int offset = 0; int found = 0;
 unsigned int index;
 unsigned char ch;
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-indexes");
  return 0;
 }
 read(fd, &index, 4);
 while ((read(fd, &index, 4)) != 0) {
  if (index == drc_idx) {
   found = 1;
   break;
  }
  offset++;
 }
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-names");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   do {
    if ((read(fd, &ch, 1)) != 1) {
     close(fd);
     return 0;
    }
   } while (ch != 0);
   offset--;
  }
  while ((read(fd, &ch, 1)) == 1) {
   if (offset+1 == buf_size) {
    drc_name[offset] = '\0';
    break;
   }
   drc_name[offset++] = ch;
   if (ch == 0)
    break;
  }
 }
 close(fd);
 return found;
}

variable_types: fd int

variable_types: offset int

variable_types: found int

variable_types:
index
unsigned int

variable_types:
ch
unsigned char

return_type: int


decompiled_code:
__int64 __fastcall cpu_drcname_to_drcindex(char *s2, void *buf)
{
int v2; // eax
int v3; // ebp
int v4; // er13
unsigned int v5; // er12
char *v6; // rbx
char v7; // al
int v8; // eax
char v10[75]; // [rsp+0h] [rbp-88h] BYREF
char v11; // [rsp+4Bh] [rbp-3Dh] BYREF
char bufa[60]; // [rsp+4Ch] [rbp-3Ch] BYREF

v2 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
if ( v2 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
return 0;
}
v3 = v2;
read(v2, bufa, 4uLL);
v4 = 0;
LABEL_6:
while ( 2 )
{
v6 = v10;
do
{
v5 = read(v3, &v11, 1uLL);
if ( v5 != 1 )
{
if ( !strcmp(v10, s2) )
goto LABEL_13;
++v4;
if ( v5 )
goto LABEL_6;
close(v3);
LABEL_19:
close(v3);
return v5;
}
v7 = v11;
*v6++ = v11;
}
while ( v7 );
if ( strcmp(v10, s2) )
{
++v4;
continue;
}
break;
}
LABEL_13:
close(v3);
v8 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
v3 = v8;
if ( v8 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
return 0;
}
read(v8, bufa, 4uLL);
if ( v4 <= 0 )
{
LABEL_17:
v5 = read(v3, buf, 4uLL) == 4;
goto LABEL_19;
}
while ( read(v3, bufa, 4uLL) == 4 )
{
if ( !--v4 )
goto LABEL_17;
}
close(v3);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2, void *buf)
{
int v2; // eax
int v3; // ebp
int v4; // er13
unsigned int v5; // er12
char *v6; // rbx
char v7; // al
int v8; // eax
char v10[75]; // [rsp+0h] [rbp-88h] BYREF
char v11; // [rsp+4Bh] [rbp-3Dh] BYREF
char bufa[60]; // [rsp+4Ch] [rbp-3Ch] BYREF

v2 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
if ( v2 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
return 0;
}
v3 = v2;
read(v2, bufa, 4uLL);
v4 = 0;
LABEL_6:
while ( 2 )
{
v6 = v10;
do
{
v5 = read(v3, &v11, 1uLL);
if ( v5 != 1 )
{
if ( !strcmp(v10, s2) )
goto LABEL_13;
++v4;
if ( v5 )
goto LABEL_6;
close(v3);
LABEL_19:
close(v3);
return v5;
}
v7 = v11;
*v6++ = v11;
}
while ( v7 );
if ( strcmp(v10, s2) )
{
++v4;
continue;
}
break;
}
LABEL_13:
close(v3);
v8 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
v3 = v8;
if ( v8 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
return 0;
}
read(v8, bufa, 4uLL);
if ( v4 <= 0 )
{
LABEL_17:
v5 = read(v3, buf, 4uLL) == 4;
goto LABEL_19;
}
while ( read(v3, bufa, 4uLL) == 4 )
{
if ( !--v4 )
goto LABEL_17;
}
close(v3);
return 0;
}

original_code:
int
cpu_drcname_to_drcindex(char *drc_name, uint32_t *drc_idx) {
 int fd, offset=0, found=0, i, rc;
 uint32_t index;
 uint8_t ch;
 char buffer[64];
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-names");
  return 0;
 }
 read(fd, &index, 4);
 do {
  i = 0;
  while ((rc = read(fd, &ch, 1)) == 1) {
   buffer[i++] = ch;
   if (ch == 0)
    break;
  }
  if (!strcmp(buffer, drc_name)) {
   found = 1;
   break;
  }
  offset++;
 } while (rc);
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-indexes");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   if ((read(fd, &index, 4)) != 4) {
    close(fd);
    return 0;
   }
   offset--;
  }
  if ((read(fd, drc_idx, 4)) != 4)
   found = 0;
 }
 close(fd);
 return found;
}

canonical_original_code:
int cpu_drcname_to_drcindex(char *drc_name, unsigned int *drc_idx) {
 int fd; int offset = 0; int found = 0; int i; int rc;
 unsigned int index;
 unsigned char ch;
 char buffer[64];
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-names");
  return 0;
 }
 read(fd, &index, 4);
 do {
  i = 0;
  while ((rc = read(fd, &ch, 1)) == 1) {
   buffer[i++] = ch;
   if (ch == 0)
    break;
  }
  if (!strcmp(buffer, drc_name)) {
   found = 1;
   break;
  }
  offset++;
 } while (rc);
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-indexes");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   if ((read(fd, &index, 4)) != 4) {
    close(fd);
    return 0;
   }
   offset--;
  }
  if ((read(fd, drc_idx, 4)) != 4)
   found = 0;
 }
 close(fd);
 return found;
}

variable_types: rc int

variable_types:
buffer
char [64]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r13
char *v5; // r12
int v6; // eax
int v7; // er12
int v9; // eax
int v10; // ebp
__int64 i; // rbx
unsigned int v12; // ebx
int v13; // ebx
int v14; // eax
int v15; // ebp
__int64 j; // rbx
int v17; // ebp
int v18; // ebx
char v19[32]; // [rsp+0h] [rbp-98h] BYREF
int v20[18]; // [rsp+20h] [rbp-78h] BYREF
unsigned int buf; // [rsp+68h] [rbp-30h] BYREF
int longind[11]; // [rsp+6Ch] [rbp-2Ch] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
longind[0] = 0;
v6 = getopt_long(argc, (char *const *)argv, "hc:f:t:", &long_options, longind);
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
v4 = optarg;
}
else if ( v6 <= 102 )
{
if ( v6 == 63 )
{
print_usage(*argv);
return -1;
}
if ( v6 == 99 )
v5 = optarg;
else
LABEL_15:
puts("huh?");
}
else
{
if ( v6 == 104 )
{
print_usage(*argv);
return 0;
}
if ( v6 != 116 )
goto LABEL_15;
v3 = optarg;
}
}
if ( !v5 )
{
fwrite("--context not specified\n", 1uLL, 0x18uLL, stderr);
return 1;
}
if ( !v4 )
{
fwrite("--from not specified\n", 1uLL, 0x15uLL, stderr);
return 2;
}
if ( !v3 )
{
fwrite("--to not specified\n", 1uLL, 0x13uLL, stderr);
return 3;
}
if ( strcmp(v5, "cpu") )
{
if ( strcmp(v5, "mem") )
{
fprintf(stderr, "invalid --context flag: %s\n", v5);
return 1;
}
v7 = strcmp(v4, "drc-index");
if ( v7 )
goto LABEL_73;
v17 = strtoul(argv[argc - 1], 0LL, 0);
v18 = strcmp(v3, "drc-name");
if ( v18 )
return v7;
if ( (unsigned int)mem_drcindex_to_drcname(v17, (__int64)v19, 20) )
{
puts(v19);
return v18;
}
LABEL_51:
fprintf(stderr, "could not find the drc-name corresponding to drc-index 0x%08x\n", buf);
return 4;
}
if ( !strcmp(v4, "interrupt-server") )
{
v12 = strtol(argv[argc - 1], 0LL, 0);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
v7 = strcmp(v3, "drc-name");
if ( v7 )
{
LABEL_73:
fprintf(stderr, "invalid --to flag: %s\n", v3);
return 3;
}
if ( (unsigned int)cpu_interruptserver_to_drcindex(v12, &buf) )
{
if ( !(unsigned int)cpu_drcindex_to_drcname(buf, (__int64)v19, 20) )
goto LABEL_51;
goto LABEL_37;
}
}
else if ( (unsigned int)cpu_interruptserver_to_drcindex(v12, &buf) )
{
printf("0x%08x\n", buf);
return v7;
}
fprintf(stderr, "could not find the drc-index corresponding to interrupt-server 0x%08x\n", v12);
return 4;
}
if ( strcmp(v4, "drc-index") )
{
if ( strcmp(v4, "drc-name") )
{
fprintf(stderr, "invalid --from flag: %s\n", v4);
return 2;
}
strncpy(v19, argv[argc - 1], 0x14uLL);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
v7 = strcmp(v3, "interrupt-server");
if ( v7 )
{
fprintf(stderr, "invalid --to flag: %s\n", v3);
return 3;
}
if ( (unsigned int)cpu_drcname_to_drcindex(v19, &buf) )
{
v9 = cpu_drcindex_to_interruptserver(buf, (__int64)v20, 16);
v10 = v9;
if ( v9 )
{
if ( v9 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to re"
"trieve the entire list\n",
16LL,
(unsigned int)v9);
for ( i = 0LL; v10 > (int)i; ++i )
printf("0x%08x\n", (unsigned int)v20[i]);
}
else
{
fprintf(stderr, "could not find the interrupt-server corresponding to drc-index 0x%08x\n", buf);
v7 = 4;
}
return v7;
}
}
else if ( (unsigned int)cpu_drcname_to_drcindex(v19, &buf) )
{
printf("0x%08x\n", buf);
return v7;
}
fprintf(stderr, "could not find the drc-index corresponding to drc-name %s\n", v19);
return 4;
}
v13 = strtol(argv[argc - 1], 0LL, 0);
buf = v13;
v7 = strcmp(v3, "drc-name");
if ( !v7 )
{
if ( !(unsigned int)cpu_drcindex_to_drcname(v13, (__int64)v19, 20) )
goto LABEL_51;
LABEL_37:
puts(v19);
return v7;
}
v7 = strcmp(v3, "interrupt-server");
if ( v7 )
goto LABEL_73;
v14 = cpu_drcindex_to_interruptserver(v13, (__int64)v20, 16);
v15 = v14;
if ( v14 )
{
if ( v14 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to retrieve"
" the entire list\n",
16LL,
(unsigned int)v14);
for ( j = 0LL; v15 > (int)j; ++j )
printf("0x%08x\n", (unsigned int)v20[j]);
}
else
{
fprintf(stderr, "could not find the interrupt-server corresponding to drc-index 0x%08x\n", buf);
v7 = 4;
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r13
char *v5; // r12
int v6; // eax
int v7; // er12
int v9; // eax
int v10; // ebp
__int64 i; // rbx
unsigned int v12; // ebx
int v13; // ebx
int v14; // eax
int v15; // ebp
__int64 j; // rbx
int v17; // ebp
int v18; // ebx
char v19[32]; // [rsp+0h] [rbp-98h] BYREF
int v20[18]; // [rsp+20h] [rbp-78h] BYREF
unsigned int buf; // [rsp+68h] [rbp-30h] BYREF
int longind[11]; // [rsp+6Ch] [rbp-2Ch] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
longind[0] = 0;
v6 = getopt_long(argc, (char *const *)argv, "hc:f:t:", &long_options, longind);
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
v4 = optarg;
}
else if ( v6 <= 102 )
{
if ( v6 == 63 )
{
func1(*argv);
return -1;
}
if ( v6 == 99 )
v5 = optarg;
else
LABEL_15:
puts("huh?");
}
else
{
if ( v6 == 104 )
{
func1(*argv);
return 0;
}
if ( v6 != 116 )
goto LABEL_15;
v3 = optarg;
}
}
if ( !v5 )
{
fwrite("--context not specified\n", 1uLL, 0x18uLL, stderr);
return 1;
}
if ( !v4 )
{
fwrite("--from not specified\n", 1uLL, 0x15uLL, stderr);
return 2;
}
if ( !v3 )
{
fwrite("--to not specified\n", 1uLL, 0x13uLL, stderr);
return 3;
}
if ( strcmp(v5, "cpu") )
{
if ( strcmp(v5, "mem") )
{
fprintf(stderr, "invalid --context flag: %s\n", v5);
return 1;
}
v7 = strcmp(v4, "drc-index");
if ( v7 )
goto LABEL_73;
v17 = strtoul(argv[argc - 1], 0LL, 0);
v18 = strcmp(v3, "drc-name");
if ( v18 )
return v7;
if ( (unsigned int)func0(v17, (__int64)v19, 20) )
{
puts(v19);
return v18;
}
LABEL_51:
fprintf(stderr, "could not find the drc-name corresponding to drc-index 0x%08x\n", buf);
return 4;
}
if ( !strcmp(v4, "interrupt-server") )
{
v12 = strtol(argv[argc - 1], 0LL, 0);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
v7 = strcmp(v3, "drc-name");
if ( v7 )
{
LABEL_73:
fprintf(stderr, "invalid --to flag: %s\n", v3);
return 3;
}
if ( (unsigned int)func2(v12, &buf) )
{
if ( !(unsigned int)func3(buf, (__int64)v19, 20) )
goto LABEL_51;
goto LABEL_37;
}
}
else if ( (unsigned int)func2(v12, &buf) )
{
printf("0x%08x\n", buf);
return v7;
}
fprintf(stderr, "could not find the drc-index corresponding to interrupt-server 0x%08x\n", v12);
return 4;
}
if ( strcmp(v4, "drc-index") )
{
if ( strcmp(v4, "drc-name") )
{
fprintf(stderr, "invalid --from flag: %s\n", v4);
return 2;
}
strncpy(v19, argv[argc - 1], 0x14uLL);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
v7 = strcmp(v3, "interrupt-server");
if ( v7 )
{
fprintf(stderr, "invalid --to flag: %s\n", v3);
return 3;
}
if ( (unsigned int)func5(v19, &buf) )
{
v9 = func4(buf, (__int64)v20, 16);
v10 = v9;
if ( v9 )
{
if ( v9 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to re"
"trieve the entire list\n",
16LL,
(unsigned int)v9);
for ( i = 0LL; v10 > (int)i; ++i )
printf("0x%08x\n", (unsigned int)v20[i]);
}
else
{
fprintf(stderr, "could not find the interrupt-server corresponding to drc-index 0x%08x\n", buf);
v7 = 4;
}
return v7;
}
}
else if ( (unsigned int)func5(v19, &buf) )
{
printf("0x%08x\n", buf);
return v7;
}
fprintf(stderr, "could not find the drc-index corresponding to drc-name %s\n", v19);
return 4;
}
v13 = strtol(argv[argc - 1], 0LL, 0);
buf = v13;
v7 = strcmp(v3, "drc-name");
if ( !v7 )
{
if ( !(unsigned int)func3(v13, (__int64)v19, 20) )
goto LABEL_51;
LABEL_37:
puts(v19);
return v7;
}
v7 = strcmp(v3, "interrupt-server");
if ( v7 )
goto LABEL_73;
v14 = func4(v13, (__int64)v20, 16);
v15 = v14;
if ( v14 )
{
if ( v14 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to retrieve"
" the entire list\n",
16LL,
(unsigned int)v14);
for ( j = 0LL; v15 > (int)j; ++j )
printf("0x%08x\n", (unsigned int)v20[j]);
}
else
{
fprintf(stderr, "could not find the interrupt-server corresponding to drc-index 0x%08x\n", buf);
v7 = 4;
}
return v7;
}

original_code:
int
main(int argc, char *argv[]) {
 int option_index, rc, i;
 char *context=((void *)0), *from=((void *)0), *to=((void *)0);
 uint32_t interruptserver, drcindex;
 unsigned long drc_tmp_idx;
 uint32_t intservs_array[16];
 char drcname[20];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "hc:f:t:", long_options,
    &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'h':
   print_usage(argv[0]);
   return 0;
  case 'c':
   context = optarg;
   break;
  case 'f':
   from = optarg;
   break;
  case 't':
   to = optarg;
   break;
  case '?':
   print_usage(argv[0]);
   return -1;
   break;
  default:
   printf("huh?\n");
   break;
  }
 }
 if (!context) {
  fprintf(stderr, "--context not specified\n");
  return 1;
 }
 if (!from) {
  fprintf(stderr, "--from not specified\n");
  return 2;
 }
 if (!to) {
  fprintf(stderr, "--to not specified\n");
  return 3;
 }
 if (!strcmp(context, "cpu")) {
  if (!strcmp(from, "interrupt-server")) {
   interruptserver = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "drc-name")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-index")) {
   drcindex = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else if (!strcmp(to, "interrupt-server")) {
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-name")) {
   strncpy(drcname, argv[argc-1], 20);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "interrupt-server")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else {
   fprintf(stderr, "invalid --from flag: %s\n", from);
   return 2;
  }
 }
 else if (!strcmp(context, "mem")) {
  if (!strcmp(from, "drc-index")) {
   drc_tmp_idx = strtoul(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!mem_drcindex_to_drcname(drc_tmp_idx,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
  }
  else {
   fprintf(stderr, "invalid --to flag: %s\n", to);
   return 3;
  }
 }
 else {
  fprintf(stderr, "invalid --context flag: %s\n", context);
  return 1;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int option_index; int rc; int i;
 char *context = ((void *)0); char *from = ((void *)0); char *to = ((void *)0);
 unsigned int interruptserver; unsigned int drcindex;
 unsigned long drc_tmp_idx;
 unsigned int intservs_array[16];
 char drcname[20];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "hc:f:t:", long_options,
    &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'h':
   print_usage(argv[0]);
   return 0;
  case 'c':
   context = optarg;
   break;
  case 'f':
   from = optarg;
   break;
  case 't':
   to = optarg;
   break;
  case '?':
   print_usage(argv[0]);
   return -1;
   break;
  default:
   printf("huh?\n");
   break;
  }
 }
 if (!context) {
  fprintf(stderr, "--context not specified\n");
  return 1;
 }
 if (!from) {
  fprintf(stderr, "--from not specified\n");
  return 2;
 }
 if (!to) {
  fprintf(stderr, "--to not specified\n");
  return 3;
 }
 if (!strcmp(context, "cpu")) {
  if (!strcmp(from, "interrupt-server")) {
   interruptserver = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "drc-name")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-index")) {
   drcindex = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else if (!strcmp(to, "interrupt-server")) {
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-name")) {
   strncpy(drcname, argv[argc-1], 20);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "interrupt-server")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else {
   fprintf(stderr, "invalid --from flag: %s\n", from);
   return 2;
  }
 }
 else if (!strcmp(context, "mem")) {
  if (!strcmp(from, "drc-index")) {
   drc_tmp_idx = strtoul(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!mem_drcindex_to_drcname(drc_tmp_idx,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
  }
  else {
   fprintf(stderr, "invalid --to flag: %s\n", to);
   return 3;
  }
 }
 else {
  fprintf(stderr, "invalid --context flag: %s\n", context);
  return 1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
context
char *

variable_types:
from
char *

variable_types:
to
char *

variable_types:
interruptserver
unsigned int

variable_types:
drcindex
unsigned int

variable_types:
drcname
char [20]


decompiled_code:
time_t __fastcall compute_cur_year(time_t a1)
{
time_t result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
localtime_r(&timer, &tp);
cur_year = tp.tm_year;
tp.tm_mon = 0;
tp.tm_mday = 1;
++tp.tm_year;
tp.tm_hour = 0;
tp.tm_min = 0;
tp.tm_sec = 0;
tp.tm_isdst = -1;
result = mktime(&tp);
end_of_cur_year = result;
return result;
}

canonical_decompiled_code:
time_t __fastcall func0(time_t a1)
{
time_t result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
localtime_r(&timer, &tp);
cur_year = tp.tm_year;
tp.tm_mon = 0;
tp.tm_mday = 1;
++tp.tm_year;
tp.tm_hour = 0;
tp.tm_min = 0;
tp.tm_sec = 0;
tp.tm_isdst = -1;
result = mktime(&tp);
end_of_cur_year = result;
return result;
}

original_code:
static void
compute_cur_year(time_t now)
{
 struct tm tm;
 localtime_r(&now, &tm);
 cur_year = tm.tm_year;
 tm.tm_mon = 0;
 tm.tm_mday = 1;
 tm.tm_year++;
 tm.tm_hour = 0;
 tm.tm_min = 0;
 tm.tm_sec = 0;
 tm.tm_isdst = -1;
 end_of_cur_year = mktime(&tm);
}

canonical_original_code:
static void compute_cur_year(long now)
{
 struct tm tm;
 localtime_r(&now, &tm);
 cur_year = tm.tm_year;
 tm.tm_mon = 0;
 tm.tm_mday = 1;
 tm.tm_year++;
 tm.tm_hour = 0;
 tm.tm_min = 0;
 tm.tm_sec = 0;
 tm.tm_isdst = -1;
 end_of_cur_year = mktime(&tm);
}

variable_types: now long

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


decompiled_code:
time_t __fastcall parse_syslog_date(char *a1, char **a2)
{
return parse_date(a1, a2, "%b %d %T", 0);
}

canonical_decompiled_code:
time_t __fastcall func2(char *a1, char **a2)
{
return func1(a1, a2, "%b %d %T", 0);
}

original_code:
time_t
parse_syslog_date(const char *start, char **end)
{
 return parse_date(start, end, "%b %d %T", false);
}

canonical_original_code:
long parse_syslog_date(char *start, char **end)
{
 return parse_date(start, end, "%b %d %T", false);
}

variable_types:
start
char *

variable_types:
end
char **

return_type: long


decompiled_code:
void __noreturn too_many_settings()
{
fprintf(stderr, "%s: cannot set fault or ident multiple times.\n", (const char *)progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(stderr, "%s: cannot set fault or ident multiple times.\n", (const char *)progname);
exit(1);
}

original_code:
static void
too_many_settings(void)
{
 fprintf(stderr, "%s: cannot set fault or ident multiple times.\n",
        progname);
 exit(1);
}

canonical_original_code:
static void too_many_settings()
{
 fprintf(stderr, "%s: cannot set fault or ident multiple times.\n",
        progname);
 exit(1);
}


decompiled_code:
_BOOL8 __fastcall parse_on_off(const char *a1)
{
bool v1; // zf
_BOOL8 result; // rax

if ( !strcmp(a1, "on") )
return 1LL;
v1 = strcmp(a1, "off") == 0;
result = !v1;
if ( !v1 )
{
fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", (const char *)progname, a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
bool v1; // zf
_BOOL8 result; // rax

if ( !strcmp(a1, "on") )
return 1LL;
v1 = strcmp(a1, "off") == 0;
result = !v1;
if ( !v1 )
{
fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", (const char *)progname, a1);
exit(1);
}
return result;
}

original_code:
static int
parse_on_off(const char *on_off)
{
 if (!strcmp(on_off, "on"))
  return 1;
 else if (!strcmp(on_off, "off"))
  return 0;
 fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", progname,
        on_off);
 exit(1);
}

canonical_original_code:
static int parse_on_off(char *on_off)
{
 if (!strcmp(on_off, "on"))
  return 1;
 else if (!strcmp(on_off, "off"))
  return 0;
 fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", progname,
        on_off);
 exit(1);
}


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
"\t-l | --list : report settings\n"
"\t-v | --verbose : verbose report\n"
"\t-V | --version : print the version of the command and exit\n"
"\t-h | --help : print this usage message and exit\n"
"\tsettings: [ -f on|off ] [ -i on|off ]\n"
"\t -f | --fault: turn component's fault LED element on/off.\n"
"\t -i | --ident: turn component's ident LED element on/off.\n"
"\tenclosure: sgN device name or location code of enclosure\n"
"\tcomponent: component's location sub-code -- e.g., P1-E2\n",
(const char *)progname);
}

canonical_decompiled_code:
int func2()
{
return fprintf(
stderr,
"Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
"\t-l | --list : report settings\n"
"\t-v | --verbose : verbose report\n"
"\t-V | --version : print the version of the command and exit\n"
"\t-h | --help : print this usage message and exit\n"
"\tsettings: [ -f on|off ] [ -i on|off ]\n"
"\t -f | --fault: turn component's fault LED element on/off.\n"
"\t -i | --ident: turn component's ident LED element on/off.\n"
"\tenclosure: sgN device name or location code of enclosure\n"
"\tcomponent: component's location sub-code -- e.g., P1-E2\n",
(const char *)progname);
}

original_code:
static void
usage(void)
{
 fprintf(stderr,
  "Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
  "\t-l | --list    : report settings\n"
  "\t-v | --verbose : verbose report\n"
  "\t-V | --version : print the version of the command "
        "and exit\n"
  "\t-h | --help    : print this usage message and exit\n"
  "\tsettings: [ -f on|off ] [ -i on|off ]\n"
  "\t  -f | --fault: turn component's fault LED element on/off.\n"
  "\t  -i | --ident: turn component's ident LED element on/off.\n"
  "\tenclosure: sgN device name or location code of enclosure\n"
  "\tcomponent: component's location sub-code -- e.g., P1-E2\n",
  progname);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr,
  "Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
  "\t-l | --list    : report settings\n"
  "\t-v | --verbose : verbose report\n"
  "\t-V | --version : print the version of the command "
        "and exit\n"
  "\t-h | --help    : print this usage message and exit\n"
  "\tsettings: [ -f on|off ] [ -i on|off ]\n"
  "\t  -f | --fault: turn component's fault LED element on/off.\n"
  "\t  -i | --ident: turn component's ident LED element on/off.\n"
  "\tenclosure: sgN device name or location code of enclosure\n"
  "\tcomponent: component's location sub-code -- e.g., P1-E2\n",
  progname);
}


decompiled_code:
__int64 __fastcall open_sg_device(const char *a1)
{
int v1; // ebx
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v3, 0x20uLL, "/dev/%s", a1);
v1 = open(v3, 2);
if ( v1 < 0 )
perror(v3);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
int v1; // ebx
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

snprintf(v3, 0x20uLL, "/dev/%s", a1);
v1 = open(v3, 2);
if ( v1 < 0 )
perror(v3);
return (unsigned int)v1;
}

original_code:
int
open_sg_device(const char *encl)
{
 char dev_sg[32];
 int fd;
 snprintf(dev_sg, 32, "/dev/%s", encl);
 fd = open(dev_sg, 02);
 if (fd < 0)
  perror(dev_sg);
 return fd;
}

canonical_original_code:
int open_sg_device(char *encl)
{
 char dev_sg[32];
 int fd;
 snprintf(dev_sg, 32, "/dev/%s", encl);
 fd = open(dev_sg, 02);
 if (fd < 0)
  perror(dev_sg);
 return fd;
}

variable_types:
encl
char *

variable_types: fd int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // er13
int v6; // er12
int v7; // eax
int v8; // eax
char *v9; // r8
int v10; // er15
__int64 v11; // rcx
char *v12; // rdi
__int64 v13; // r14
const char *v14; // rsi
__int64 v15; // rcx
__int64 v16; // r8
int v18; // [rsp+4h] [rbp-364h]
const char *v19; // [rsp+8h] [rbp-360h]
char s1[656]; // [rsp+10h] [rbp-358h] BYREF
char dest[140]; // [rsp+2A0h] [rbp-C8h] BYREF
int longind[15]; // [rsp+32Ch] [rbp-3Ch] BYREF

progname = (__int64)*argv;
v3 = -1;
v4 = -1;
v5 = 0;
v6 = 0;
while ( 1 )
{
longind[0] = 0;
v7 = getopt_long(argc, (char *const *)argv, "f:hi:lvV", &long_options, longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'V':
printf("%s %s\n", *argv, (const char *)&unk_9B1);
exit(0);
case 'f':
if ( v4 != -1 )
too_many_settings();
v4 = parse_on_off(optarg);
break;
case 'h':
usage();
exit(0);
case 'i':
if ( v3 != -1 )
too_many_settings();
v3 = parse_on_off(optarg);
break;
case 'l':
v6 = 1;
break;
case 'v':
v5 = 1;
break;
default:
usage();
exit(1);
}
}
v8 = optind;
if ( optind < argc )
{
++optind;
v9 = (char *)argv[v8];
if ( v8 + 1 < argc )
{
optind = v8 + 2;
if ( v8 + 2 < argc )
{
usage();
exit(1);
}
v19 = argv[v8 + 1];
}
else
{
v19 = 0LL;
}
v10 = v3 & v4;
if ( v6 || v10 != -1 )
{
v11 = 32LL;
v12 = dest;
while ( v11 )
{
*(_DWORD *)v12 = 0;
v12 += 4;
--v11;
}
if ( (unsigned int)enclosure_dev_name(v9, dest, 128) )
exit(1);
memset(s1, 0, 0x288uLL);
v13 = 0LL;
if ( !(unsigned int)read_vpd_from_lscfg(s1, dest) )
{
while ( 1 )
{
v18 = v13;
v14 = (&encl_list)[3 * v13];
if ( !v14 )
break;
++v13;
if ( !strcmp(s1, v14) )
{
if ( v6 )
{
if ( v10 != -1 )
{
usage();
exit(1);
}
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, __int64, __int64))*(&off_B28 + 3 * v18))(
dest,
v19,
v5,
v15,
v16) )
{
exit(2);
}
}
else
{
if ( geteuid() )
{
fprintf(stderr, "%s: Turning LEDs on/off requires superuser privileges.\n", (const char *)progname);
exit(1);
}
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, _QWORD, _QWORD))*(&off_B30 + 3 * v18))(
dest,
v19,
v4,
v3,
v5) )
{
exit(2);
}
}
exit(0);
}
}
fprintf(stderr, "No indicator support for device type/model : %s\n", s1);
exit(0);
}
exit(1);
}
usage();
exit(1);
}
usage();
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // er13
int v6; // er12
int v7; // eax
int v8; // eax
char *v9; // r8
int v10; // er15
__int64 v11; // rcx
char *v12; // rdi
__int64 v13; // r14
const char *v14; // rsi
__int64 v15; // rcx
__int64 v16; // r8
int v18; // [rsp+4h] [rbp-364h]
const char *v19; // [rsp+8h] [rbp-360h]
char s1[656]; // [rsp+10h] [rbp-358h] BYREF
char dest[140]; // [rsp+2A0h] [rbp-C8h] BYREF
int longind[15]; // [rsp+32Ch] [rbp-3Ch] BYREF

progname = (__int64)*argv;
v3 = -1;
v4 = -1;
v5 = 0;
v6 = 0;
while ( 1 )
{
longind[0] = 0;
v7 = getopt_long(argc, (char *const *)argv, "f:hi:lvV", &long_options, longind);
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'V':
printf("%s %s\n", *argv, (const char *)&unk_9B1);
exit(0);
case 'f':
if ( v4 != -1 )
func0();
v4 = func1(optarg);
break;
case 'h':
func2();
exit(0);
case 'i':
if ( v3 != -1 )
func0();
v3 = func1(optarg);
break;
case 'l':
v6 = 1;
break;
case 'v':
v5 = 1;
break;
default:
func2();
exit(1);
}
}
v8 = optind;
if ( optind < argc )
{
++optind;
v9 = (char *)argv[v8];
if ( v8 + 1 < argc )
{
optind = v8 + 2;
if ( v8 + 2 < argc )
{
func2();
exit(1);
}
v19 = argv[v8 + 1];
}
else
{
v19 = 0LL;
}
v10 = v3 & v4;
if ( v6 || v10 != -1 )
{
v11 = 32LL;
v12 = dest;
while ( v11 )
{
*(_DWORD *)v12 = 0;
v12 += 4;
--v11;
}
if ( (unsigned int)func4(v9, dest, 128) )
exit(1);
memset(s1, 0, 0x288uLL);
v13 = 0LL;
if ( !(unsigned int)read_vpd_from_lscfg(s1, dest) )
{
while ( 1 )
{
v18 = v13;
v14 = (&encl_list)[3 * v13];
if ( !v14 )
break;
++v13;
if ( !strcmp(s1, v14) )
{
if ( v6 )
{
if ( v10 != -1 )
{
func2();
exit(1);
}
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, __int64, __int64))*(&off_B28 + 3 * v18))(
dest,
v19,
v5,
v15,
v16) )
{
exit(2);
}
}
else
{
if ( geteuid() )
{
fprintf(stderr, "%s: Turning LEDs on/off requires superuser privileges.\n", (const char *)progname);
exit(1);
}
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, _QWORD, _QWORD))*(&off_B30 + 3 * v18))(
dest,
v19,
v4,
v3,
v5) )
{
exit(2);
}
}
exit(0);
}
}
fprintf(stderr, "No indicator support for device type/model : %s\n", s1);
exit(0);
}
exit(1);
}
func2();
exit(1);
}
func2();
exit(1);
}

original_code:
int
main(int argc, char **argv)
{
 int rc, option_index, i;
 int list_opt = 0, verbose = 0, found = 0;
 int fault_setting = -1, ident_setting = -1;
 const char *enclosure = ((void *)0), *component = ((void *)0);
 char sg[128];
 struct dev_vpd vpd;
 progname = argv[0];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "f:hi:lvV", long_options,
       &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'f':
   if (fault_setting != -1)
    too_many_settings();
   fault_setting = parse_on_off(optarg);
   break;
  case 'h':
   usage();
   exit(0);
  case 'i':
   if (ident_setting != -1)
    too_many_settings();
   ident_setting = parse_on_off(optarg);
   break;
  case 'l':
   list_opt = 1;
   break;
  case 'v':
   verbose = 1;
   break;
  case 'V':
   printf("%s %s\n", argv[0], "");
   exit(0);
  case '?':
  default:
   usage();
   exit(1);
  }
 }
 if (optind < argc)
  enclosure = argv[optind++];
 else {
  usage();
  exit(1);
 }
 if (optind < argc)
  component = argv[optind++];
 if (optind < argc) {
  usage();
  exit(1);
 }
 if (!list_opt && fault_setting == -1 &&
        ident_setting == -1) {
  usage();
  exit(1);
 }
 memset(sg, 0, sizeof(sg));
 if (enclosure_dev_name(enclosure, sg, sizeof(sg)) != 0)
  exit(1);
 memset(&vpd, 0, sizeof(vpd));
 if (read_vpd_from_lscfg(&vpd, sg) != 0)
  exit(1);
 for (i = 0; encl_list[i].mtm; i++)
  if (!strcmp(vpd.mtm, encl_list[i].mtm)) {
   found = 1;
   break;
  }
 if (!found) {
  fprintf(stderr, "No indicator support for device type/model :"
    " %s\n", vpd.mtm);
  exit(0);
 }
 if (list_opt) {
  if (fault_setting != -1 || ident_setting != -1) {
   usage();
   exit(1);
  }
  if (encl_list[i].list_leds(sg, component, verbose) != 0)
   exit(2);
 } else {
  if (geteuid() != 0) {
   fprintf(stderr, "%s: Turning LEDs on/off requires "
     "superuser privileges.\n", progname);
   exit(1);
  }
  if (encl_list[i].set_led(sg, component, fault_setting,
      ident_setting, verbose) != 0)
   exit(2);
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int rc; int option_index; int i;
 int list_opt = 0; int verbose = 0; int found = 0;
 int fault_setting = -1; int ident_setting = -1;
 char *enclosure = ((void *)0); char *component = ((void *)0);
 char sg[128];
 struct dev_vpd vpd;
 progname = argv[0];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "f:hi:lvV", long_options,
       &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'f':
   if (fault_setting != -1)
    too_many_settings();
   fault_setting = parse_on_off(optarg);
   break;
  case 'h':
   usage();
   exit(0);
  case 'i':
   if (ident_setting != -1)
    too_many_settings();
   ident_setting = parse_on_off(optarg);
   break;
  case 'l':
   list_opt = 1;
   break;
  case 'v':
   verbose = 1;
   break;
  case 'V':
   printf("%s %s\n", argv[0], "");
   exit(0);
  case '?':
  default:
   usage();
   exit(1);
  }
 }
 if (optind < argc)
  enclosure = argv[optind++];
 else {
  usage();
  exit(1);
 }
 if (optind < argc)
  component = argv[optind++];
 if (optind < argc) {
  usage();
  exit(1);
 }
 if (!list_opt && fault_setting == -1 &&
        ident_setting == -1) {
  usage();
  exit(1);
 }
 memset(sg, 0, sizeof(sg));
 if (enclosure_dev_name(enclosure, sg, sizeof(sg)) != 0)
  exit(1);
 memset(&vpd, 0, sizeof(vpd));
 if (read_vpd_from_lscfg(&vpd, sg) != 0)
  exit(1);
 for (i = 0; encl_list[i].mtm; i++)
  if (!strcmp(vpd.mtm, encl_list[i].mtm)) {
   found = 1;
   break;
  }
 if (!found) {
  fprintf(stderr, "No indicator support for device type/model :"
    " %s\n", vpd.mtm);
  exit(0);
 }
 if (list_opt) {
  if (fault_setting != -1 || ident_setting != -1) {
   usage();
   exit(1);
  }
  if (encl_list[i].list_leds(sg, component, verbose) != 0)
   exit(2);
 } else {
  if (geteuid() != 0) {
   fprintf(stderr, "%s: Turning LEDs on/off requires "
     "superuser privileges.\n", progname);
   exit(1);
  }
  if (encl_list[i].set_led(sg, component, fault_setting,
      ident_setting, verbose) != 0)
   exit(2);
 }
 exit(0);
}

variable_types:
argv
char **

variable_types: i int

variable_types: verbose int

variable_types: found int

variable_types:
enclosure
char *

variable_types:
component
char *

variable_types:
sg
char [128]

variable_types: struct dev_vpd { char mtm[128]; char location[128]; char full_loc[128]; char sn[128]; char fru[128]; struct dev_vpd *next; }


usage

decompiled_code:
void __noreturn usage(void)
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

v0 = std::operator<<<std::char_traits<char>>(&std::cerr, "usage: ");
v1 = std::operator<<<std::char_traits<char>>(v0, progname);
v2 = std::operator<<<std::char_traits<char>>(v1, " [-C catalog_dir]");
std::ostream::operator<<(v2, &std::endl<char,std::char_traits<char>>);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(void)
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

v0 = std::operator<<<std::char_traits<char>>(&std::cerr, "usage: ");
v1 = std::operator<<<std::char_traits<char>>(v0, progname);
v2 = std::operator<<<std::char_traits<char>>(v1, " [-C catalog_dir]");
std::ostream::operator<<(v2, &std::endl<char,std::char_traits<char>>);
exit(1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v3; // bl
char v4[35]; // [rsp+10h] [rbp-40h] BYREF
char v5; // [rsp+33h] [rbp-1Dh] BYREF
int v6; // [rsp+34h] [rbp-1Ch]
char *v7; // [rsp+38h] [rbp-18h]

v7 = "/etc/ppc64-diag/message_catalog";
progname = (__int64)*argv;
opterr = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "C:");
if ( v6 == -1 )
break;
if ( v6 == 63 )
usage();
if ( v6 == 67 )
v7 = optarg;
}
if ( argc != optind )
usage();
regex_text_policy = 1;
std::allocator<char>::allocator(&v5);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v4, v7, &v5);
v3 = (unsigned int)EventCatalog::parse(v4) != 0;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v4);
std::allocator<char>::~allocator(&v5);
if ( v3 )
exit(2);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v3; // bl
char v4[35]; // [rsp+10h] [rbp-40h] BYREF
char v5; // [rsp+33h] [rbp-1Dh] BYREF
int v6; // [rsp+34h] [rbp-1Ch]
char *v7; // [rsp+38h] [rbp-18h]

v7 = "/etc/ppc64-diag/message_catalog";
progname = (__int64)*argv;
opterr = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "C:");
if ( v6 == -1 )
break;
if ( v6 == 63 )
func0();
if ( v6 == 67 )
v7 = optarg;
}
if ( argc != optind )
func0();
regex_text_policy = 1;
std::allocator<char>::allocator(&v5);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v4, v7, &v5);
v3 = (unsigned int)EventCatalog::parse(v4) != 0;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v4);
std::allocator<char>::~allocator(&v5);
if ( v3 )
exit(2);
exit(0);
}

variable_types: argc int

variable_types: rc int

user_defined_types: struct dev_vpd { char mtm[128]; char location[128]; char full_loc[128]; char sn[128]; char fru[128]; struct dev_vpd *next; }


usage

repo: tzcoolman/FACS-OLD

decompiled_code:
__int64 usage()
{
fputc(10, stderr);
fwrite("Program: facs (Sequence decontamination using bloom filters)\n", 1uLL, 0x3DuLL, stderr);
fprintf(stderr, "Version: %s\n", "0.1");
fwrite("Contact: Enze Liu <enze.liu@scilifelab.se>\n\n", 1uLL, 0x2CuLL, stderr);
fwrite("Usage: facs <command> [options]\n\n", 1uLL, 0x23uLL, stderr);
fwrite("Command: build build a bloom filter from a FASTA reference file\n", 1uLL, 0x48uLL, stderr);
fwrite(
" query query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n",
1uLL,
0x71uLL,
stderr);
fwrite(
" check query a bloom filter given a FASTQ/FASTA file. Faster than query\n",
1uLL,
0x58uLL,
stderr);
fwrite(" remove remove (contamination) sequences from FASTQ/FASTA file\n", 1uLL, 0x4EuLL, stderr);
fwrite(" classify classify reads to the most likely reference genomes\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
fputc(10, stderr);
fwrite("Program: facs (Sequence decontamination using bloom filters)\n", 1uLL, 0x3DuLL, stderr);
fprintf(stderr, "Version: %s\n", "0.1");
fwrite("Contact: Enze Liu <enze.liu@scilifelab.se>\n\n", 1uLL, 0x2CuLL, stderr);
fwrite("Usage: facs <command> [options]\n\n", 1uLL, 0x23uLL, stderr);
fwrite("Command: build build a bloom filter from a FASTA reference file\n", 1uLL, 0x48uLL, stderr);
fwrite(
" query query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n",
1uLL,
0x71uLL,
stderr);
fwrite(
" check query a bloom filter given a FASTQ/FASTA file. Faster than query\n",
1uLL,
0x58uLL,
stderr);
fwrite(" remove remove (contamination) sequences from FASTQ/FASTA file\n", 1uLL, 0x4EuLL, stderr);
fwrite(" classify classify reads to the most likely reference genomes\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
return 1LL;
}

original_code:
static int
usage(void)
{
    fprintf(stderr, "\n");
    fprintf(stderr, "Program: facs (Sequence decontamination using bloom filters)\n");
    fprintf(stderr, "Version: %s\n", "0.1");
    fprintf(stderr, "Contact: Enze Liu <enze.liu@scilifelab.se>\n\n");
    fprintf(stderr, "Usage:   facs <command> [options]\n\n");
    fprintf(stderr, "Command: build         build a bloom filter from a FASTA reference file\n");
    fprintf(stderr, "         query         query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n");
    fprintf(stderr, "         check         query a bloom filter given a FASTQ/FASTA file. Faster than query\n");
    fprintf(stderr, "         remove        remove (contamination) sequences from FASTQ/FASTA file\n");
    fprintf(stderr, "         classify      classify reads to the most likely reference genomes\n");
    fprintf(stderr, "\n");
    return 1;
}

canonical_original_code:
static int usage()
{
    fprintf(stderr, "\n");
    fprintf(stderr, "Program: facs (Sequence decontamination using bloom filters)\n");
    fprintf(stderr, "Version: %s\n", "0.1");
    fprintf(stderr, "Contact: Enze Liu <enze.liu@scilifelab.se>\n\n");
    fprintf(stderr, "Usage:   facs <command> [options]\n\n");
    fprintf(stderr, "Command: build         build a bloom filter from a FASTA reference file\n");
    fprintf(stderr, "         query         query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n");
    fprintf(stderr, "         check         query a bloom filter given a FASTQ/FASTA file. Faster than query\n");
    fprintf(stderr, "         remove        remove (contamination) sequences from FASTQ/FASTA file\n");
    fprintf(stderr, "         classify      classify reads to the most likely reference genomes\n");
    fprintf(stderr, "\n");
    return 1;
}


main

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

if ( argc <= 1 )
return usage(argc, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "build") )
return build_main((unsigned int)(argc - 1), argv + 1, envp);
if ( !strcmp(v3, "check") )
return check_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "query") )
return bq_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "remove") )
return remove_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "classify") )
return remove_l_main((unsigned int)(argc - 1), argv + 1);
usage(v3, "classify", v4);
return 0;
}

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

if ( argc <= 1 )
return func0(argc, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "build") )
return build_main((unsigned int)(argc - 1), argv + 1, envp);
if ( !strcmp(v3, "check") )
return check_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "query") )
return bq_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "remove") )
return remove_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "classify") )
return remove_l_main((unsigned int)(argc - 1), argv + 1);
func0(v3, "classify", v4);
return 0;
}

original_code:
int main (int argc, char **argv)
{
  int ret=0;
  if (argc < 2) return usage();
  if (strcmp(argv[1], "build") == 0) ret = build_main(argc-1, argv+1);
  else if (strcmp(argv[1], "check") == 0) ret = check_main(argc-1, argv+1);
  else if (strcmp(argv[1], "query") == 0) ret = bq_main(argc-1, argv+1);
  else if (strcmp(argv[1], "remove") == 0) ret = remove_main(argc-1, argv+1);
  else if (strcmp(argv[1], "classify") == 0) ret = remove_l_main(argc-1,argv+1);
  else usage();
  return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int ret = 0;
  if (argc < 2) return usage();
  if (strcmp(argv[1], "build") == 0) ret = build_main(argc-1, argv+1);
  else if (strcmp(argv[1], "check") == 0) ret = check_main(argc-1, argv+1);
  else if (strcmp(argv[1], "query") == 0) ret = bq_main(argc-1, argv+1);
  else if (strcmp(argv[1], "remove") == 0) ret = remove_main(argc-1, argv+1);
  else if (strcmp(argv[1], "classify") == 0) ret = remove_l_main(argc-1,argv+1);
  else usage();
  return ret;
}

variable_types: ret int


decompiled_code:
double __fastcall get_mu(__int64 a1, double a2)
{
double v3; // xmm0_8

if ( a1 < 0 )
v3 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v3 = (double)(int)a1;
return v3 * a2;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, double a2)
{
double v3; // xmm0_8

if ( a1 < 0 )
v3 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v3 = (double)(int)a1;
return v3 * a2;
}

original_code:
double get_mu (unsigned long long num_hit, double prob)
{
       return ((double)num_hit)*prob;
}

canonical_original_code:
double get_mu(unsigned long long num_hit, double prob)
{
       return ((double)num_hit)*prob;
}

variable_types: prob double

return_type: double


decompiled_code:
double __fastcall get_sigma(__int64 a1, double a2)
{
double v3; // xmm0_8

if ( a1 < 0 )
v3 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v3 = (double)(int)a1;
return v3 * a2 * (1.0 - a2);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, double a2)
{
double v3; // xmm0_8

if ( a1 < 0 )
v3 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v3 = (double)(int)a1;
return v3 * a2 * (1.0 - a2);
}

original_code:
double get_sigma (unsigned long long num_hit, double prob)
{
       return (double)num_hit*prob*(1-prob);
}

canonical_original_code:
double get_sigma(unsigned long long num_hit, double prob)
{
       return (double)num_hit*prob*(1-prob);
}


decompiled_code:
__off_t __fastcall get_size(const char *a1)
{
int v1; // eax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = open64(a1, 0);
if ( v1 < 0 )
{
puts("open file error...");
exit(-1);
}
fstat64(v1, &v3);
return v3.st_size;
}

canonical_decompiled_code:
__off_t __fastcall func2(const char *a1)
{
int v1; // eax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = open64(a1, 0);
if ( v1 < 0 )
{
puts("open file error...");
exit(-1);
}
fstat64(v1, &v3);
return v3.st_size;
}

original_code:
long long get_size (char *filename)
{
long long tim;
struct stat statbuf;
if ((tim=open(filename, 00))<0)
    {
     printf("open file error...\n");
     exit(-1);
    }
fstat (tim, &statbuf);
return statbuf.st_size;
}

canonical_original_code:
long long get_size(char *filename)
{
long long tim;
struct stat statbuf;
if ((tim=open(filename, 00))<0)
    {
     printf("open file error...\n");
     exit(-1);
    }
fstat (tim, &statbuf);
return statbuf.st_size;
}

variable_types:
filename
char *

variable_types:
tim
long long

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

return_type: long long

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


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

result = 15LL;
if ( a1 > 10485759 )
{
result = 16LL;
if ( a1 > 20971519 )
{
result = 17LL;
if ( a1 > 52428799 )
{
result = 18LL;
if ( a1 > 104857599 )
result = (unsigned int)(a1 > 524287999) + 19;
}
}
}
return result;
}

original_code:
int kmer_suggestion (long long size)
{
  if (size<10*1048576)
     {
      return 15;
     }
  else if (size<20*1048576)
     {
      return 16;
     }
  else if (size<50*1048576)
     {
      return 17;
     }
  else if (size<100*1048576)
     {
      return 18;
     }
  else if (size<500*1048576)
     {
      return 19;
     }
  else
     {
      return 20;
     }
}

canonical_original_code:
int kmer_suggestion(long long size)
{
  if (size<10*1048576)
     {
      return 15;
     }
  else if (size<20*1048576)
     {
      return 16;
     }
  else if (size<50*1048576)
     {
      return 17;
     }
  else if (size<100*1048576)
     {
      return 18;
     }
  else if (size<500*1048576)
     {
      return 19;
     }
  else
     {
      return 20;
     }
}

variable_types:
size
long long


decompiled_code:
float __fastcall mco_suggestion(int a1)
{
float result; // xmm0_4

if ( a1 <= 18 )
{
result = *(float *)&LC2;
if ( a1 > 15 )
result = *(float *)&LC3;
}
else if ( a1 == 20 )
{
result = *(float *)&LC3;
}
else
{
result = *(float *)&LC2;
}
return result;
}

canonical_decompiled_code:
float __fastcall func4(int a1)
{
float result; // xmm0_4

if ( a1 <= 18 )
{
result = *(float *)&LC2;
if ( a1 > 15 )
result = *(float *)&LC3;
}
else if ( a1 == 20 )
{
result = *(float *)&LC3;
}
else
{
result = *(float *)&LC2;
}
return result;
}

original_code:
float mco_suggestion (int k_mer)
{
switch (k_mer)
  {
    case 15:
     return 0.4;
    case 16:
        return 0.3;
    case 17:
        return 0.3;
    case 18:
        return 0.3;
    case 19:
        return 0.4;
    case 20:
        return 0.3;
    default:
        return 0.4;
  }
}

canonical_original_code:
float mco_suggestion(int k_mer)
{
switch (k_mer)
  {
    case 15:
     return 0.4;
    case 16:
        return 0.3;
    case 17:
        return 0.3;
    case 18:
        return 0.3;
    case 19:
        return 0.4;
    case 20:
        return 0.3;
    default:
        return 0.4;
  }
}

return_type: float


decompiled_code:
__int64 __fastcall is_prime(unsigned __int64 a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
unsigned __int64 v3; // r8
__int64 result; // rax
unsigned __int64 v5; // rcx
unsigned __int64 v6; // rsi

v1 = (double)a1;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
if ( v2 >= 9.223372036854776e18 )
v3 = (unsigned int)(int)(v2 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v3 = (unsigned int)(int)v2;
if ( (a1 & 1) != 0 || (result = 0LL, a1 == 2) )
{
if ( a1 == a1 / 3 + (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)a1) >> 64) & 0xFFFFFFFFFFFFFFFELL) || v3 <= 3 )
{
v5 = 3LL;
}
else
{
if ( a1 == a1 / 5 + (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)a1) >> 64) & 0xFFFFFFFFFFFFFFFCLL) )
return 0LL;
if ( a1 == 7 * (a1 / 7) )
return 0LL;
v5 = 3LL;
while ( 1 )
{
v6 = v5;
v5 += 8LL;
if ( !(a1 % v5) || v3 <= v5 )
break;
if ( !(a1 % (v6 + 10)) )
return 0LL;
if ( !(a1 % (v6 + 12)) )
return 0LL;
}
}
result = (unsigned int)((int)a1 % v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
unsigned __int64 v3; // r8
__int64 result; // rax
unsigned __int64 v5; // rcx
unsigned __int64 v6; // rsi

v1 = (double)a1;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
if ( v2 >= 9.223372036854776e18 )
v3 = (unsigned int)(int)(v2 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v3 = (unsigned int)(int)v2;
if ( (a1 & 1) != 0 || (result = 0LL, a1 == 2) )
{
if ( a1 == a1 / 3 + (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)a1) >> 64) & 0xFFFFFFFFFFFFFFFELL) || v3 <= 3 )
{
v5 = 3LL;
}
else
{
if ( a1 == a1 / 5 + (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)a1) >> 64) & 0xFFFFFFFFFFFFFFFCLL) )
return 0LL;
if ( a1 == 7 * (a1 / 7) )
return 0LL;
v5 = 3LL;
while ( 1 )
{
v6 = v5;
v5 += 8LL;
if ( !(a1 % v5) || v3 <= v5 )
break;
if ( !(a1 % (v6 + 10)) )
return 0LL;
if ( !(a1 % (v6 + 12)) )
return 0LL;
}
}
result = (unsigned int)((int)a1 % v5);
}
return result;
}

original_code:
int
is_prime (unsigned long long m)
{
  unsigned long long a = (unsigned long long) ((long double)sqrt((double)(long double) m));
  unsigned long long currval = 3;
  if (m % 2 == 0 && m != 2)
    return 0;
  while (m % currval != 0 && currval < a)
    {
      if (m % (currval + 2) == 0)
 return 0;
      if (m % (currval + 4) == 0)
 return 0;
      currval += 8;
    }
  return (int) m % currval;
}

canonical_original_code:
int is_prime(unsigned long long m)
{
  unsigned long long a = (unsigned long long) ((long double)sqrt((double)(long double) m));
  unsigned long long currval = 3;
  if (m % 2 == 0 && m != 2)
    return 0;
  while (m % currval != 0 && currval < a)
    {
      if (m % (currval + 2) == 0)
 return 0;
      if (m % (currval + 4) == 0)
 return 0;
      currval += 8;
    }
  return (int) m % currval;
}

variable_types:
m
unsigned long long

variable_types:
a
unsigned long long

variable_types:
currval
unsigned long long


decompiled_code:
unsigned __int64 __fastcall find_close_prime(__int64 a1)
{
unsigned __int64 i; // rbx

for ( i = ((a1 & 1) == 0) + a1; !(unsigned int)is_prime(i); i += 2LL )
;
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1)
{
unsigned __int64 i; // rbx

for ( i = ((a1 & 1) == 0) + a1; !(unsigned int)func5(i); i += 2LL )
;
return i;
}

original_code:
unsigned long long
find_close_prime (unsigned long long m)
{
  if ((m % 2) == 0)
    m += 1;
  while (!is_prime (m))
    {
      m += 2;
    }
  return m;
}

canonical_original_code:
unsigned long long find_close_prime(unsigned long long m)
{
  if ((m % 2) == 0)
    m += 1;
  while (!is_prime (m))
    {
      m += 2;
    }
  return m;
}

return_type: unsigned long long