callback

decompiled_code:
void __fastcall callback(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__time_t v3; // rax
int v4; // ebx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
time_t timer; // [rsp+0h] [rbp-30h] BYREF
struct timeval tv; // [rsp+8h] [rbp-28h] BYREF
__int64 v10; // [rsp+20h] [rbp-10h]
__int64 v11; // [rsp+28h] [rbp-8h]

if ( (*(_BYTE *)a1 & 4) != 0 )
{
v11 = v2;
v10 = v1;
v3 = (unsigned int)(int)*(double *)(a1 + 24);
tv.tv_usec = 0LL;
tv.tv_sec = v3;
timer = v3;
v4 = settimeofday(&tv, 0LL);
gps_close();
if ( !v4 )
{
v5 = ctime(&timer);
syslog(5, "Successfully set RTC time to GPSD time: %s", v5);
closelog();
exit(0);
}
v6 = __errno_location();
v7 = strerror(*v6);
syslog(3, "Error setting RTC: %d (%s)\n", (unsigned int)*v6, v7);
closelog();
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__time_t v3; // rax
int v4; // ebx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
time_t timer; // [rsp+0h] [rbp-30h] BYREF
struct timeval tv; // [rsp+8h] [rbp-28h] BYREF
__int64 v10; // [rsp+20h] [rbp-10h]
__int64 v11; // [rsp+28h] [rbp-8h]

if ( (*(_BYTE *)a1 & 4) != 0 )
{
v11 = v2;
v10 = v1;
v3 = (unsigned int)(int)*(double *)(a1 + 24);
tv.tv_usec = 0LL;
tv.tv_sec = v3;
timer = v3;
v4 = settimeofday(&tv, 0LL);
gps_close();
if ( !v4 )
{
v5 = ctime(&timer);
syslog(5, "Successfully set RTC time to GPSD time: %s", v5);
closelog();
exit(0);
}
v6 = __errno_location();
v7 = strerror(*v6);
syslog(3, "Error setting RTC: %d (%s)\n", (unsigned int)*v6, v7);
closelog();
exit(1);
}
}

original_code:
static void callback(struct gps_data_t *gpsdata)
{
 struct timeval tv;
 time_t time;
 int rc;
 if (!(gpsdata->set & (1llu<<2)))
  return;
 tv.tv_sec = gpsdata->fix.time;
 tv.tv_usec = 0;
 time = tv.tv_sec;
 rc = settimeofday(&tv, ((void *)0));
 gps_close(gpsdata);
 if (rc == 0) {
  syslog(5, "Successfully set RTC time to GPSD time:"
   " %s", ctime(&time));
  closelog();
  exit(0);
 } else {
  syslog(3, "Error setting RTC: %d (%s)\n",
   (*__errno_location ()), strerror((*__errno_location ())));
  closelog();
  exit(1);
 }
}

canonical_original_code:
static void callback(struct gps_data_t *gpsdata)
{
 struct timeval tv;
 long time;
 int rc;
 if (!(gpsdata->set & (1llu<<2)))
  return;
 tv.tv_sec = gpsdata->fix.time;
 tv.tv_usec = 0;
 time = tv.tv_sec;
 rc = settimeofday(&tv, ((void *)0));
 gps_close(gpsdata);
 if (rc == 0) {
  syslog(5, "Successfully set RTC time to GPSD time:"
   " %s", ctime(&time));
  closelog();
  exit(0);
 } else {
  syslog(3, "Error setting RTC: %d (%s)\n",
   (*__errno_location ()), strerror((*__errno_location ())));
  closelog();
  exit(1);
 }
}

variable_types: struct gps_data_t { unsigned long set; double online; int gps_fd; struct gps_fix_t { double time; int mode; double ept; double latitude; double epy; double longitude; double epx; double altitude; double epv; double track; double epd; double speed; double eps; double climb; double epc; } fix; double separation; int status; int satellites_used; struct dop_t { double xdop; } dop; double epe; double skyview_time; int satellites_visible; struct satellite_t { double ss; _Bool used; short PRN; short elevation; short azimuth; } skyview[72]; struct devconfig_t { char path[128]; int flags; char driver[64]; char subtype[64]; double activated; unsigned int baudrate; char parity; double cycle; int driver_mode; } dev; struct policy_t { _Bool watcher; _Bool json; _Bool nmea; int raw; _Bool scaled; _Bool timing; _Bool split24; _Bool pps; int loglevel; char devpath[128]; char remote[128]; } policy; struct { double time; int ndevices; struct devconfig_t list[4]; } devices; union { struct rtcm2_t { unsigned int type; unsigned int length; double zcount; unsigned int refstaid; unsigned int seqnum; unsigned int stathlth; union { struct { unsigned int nentries; struct gps_rangesat_t { unsigned int ident; unsigned int udre; unsigned int iod; double prc; double rrc; } sat[18]; } gps_ranges; struct { _Bool valid; double x; } ecef; struct { _Bool valid; int system; int sense; char datum[6]; double dx; } reference; struct { unsigned int nentries; struct consat_t { unsigned int ident; _Bool iodl; unsigned int health; int snr; _Bool health_en; _Bool new_data; _Bool los_warning; unsigned int tou; } sat[-1]; } conhealth; struct { unsigned int nentries; struct station_t { double latitude; unsigned int range; double frequency; unsigned int health; unsigned int station_id; unsigned int bitrate; } station[10]; } almanac; struct { _Bool status; _Bool rangeflag; double lat; unsigned int range; } xmitter; struct { unsigned int week; unsigned int hour; unsigned int leapsecs; } gpstime; struct { unsigned int nentries; struct glonass_rangesat_t { unsigned int ident; unsigned int udre; unsigned int tod; _Bool change; double prc; double rrc; } sat[18]; } glonass_ranges; char message[-1]; unsigned int words[-1]; }; } rtcm2; struct rtcm3_t { unsigned int type; unsigned int length; union { struct { struct rtcm3_rtk_hdr { unsigned int station_id; long tow; _Bool sync; unsigned short satcount; _Bool smoothing; unsigned int interval; } header; struct rtcm3_1001_t { unsigned int ident; struct rtcm3_basic_rtk { unsigned char indicator; unsigned int channel; double pseudorange; double rangediff; unsigned char locktime; } L1; } rtk_data[64]; } rtcm3_1001; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1002_t { unsigned int ident; struct rtcm3_extended_rtk { unsigned char indicator; unsigned int channel; double pseudorange; double rangediff; unsigned char locktime; unsigned char ambiguity; double CNR; } L1; } rtk_data[64]; } rtcm3_1002; struct rtcm3_1003_t { struct rtcm3_rtk_hdr header; struct { unsigned int ident; struct rtcm3_basic_rtk L1; struct rtcm3_basic_rtk L2; } rtk_data[64]; } rtcm3_1003; struct rtcm3_1004_t { struct rtcm3_rtk_hdr header; struct { unsigned int ident; struct rtcm3_extended_rtk L1; struct rtcm3_extended_rtk L2; } rtk_data[64]; } rtcm3_1004; struct rtcm3_1005_t { unsigned int station_id; int system; _Bool reference_station; _Bool single_receiver; double ecef_x; } rtcm3_1005; struct rtcm3_1006_t { unsigned int station_id; int system; _Bool reference_station; _Bool single_receiver; double ecef_x; double height; } rtcm3_1006; struct { unsigned int station_id; char descriptor[-1]; unsigned int setup_id; } rtcm3_1007; struct { unsigned int station_id; char descriptor[-1]; unsigned int setup_id; char serial[-1]; } rtcm3_1008; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1009_t { unsigned int ident; struct rtcm3_basic_rtk L1; } rtk_data[64]; } rtcm3_1009; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1010_t { unsigned int ident; struct rtcm3_extended_rtk L1; } rtk_data[64]; } rtcm3_1010; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1011_t { unsigned int ident; struct rtcm3_extended_rtk L1; struct rtcm3_extended_rtk L2; } rtk_data[64]; } rtcm3_1011; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1012_t { unsigned int ident; struct rtcm3_extended_rtk L1; struct rtcm3_extended_rtk L2; } rtk_data[64]; } rtcm3_1012; struct { unsigned int station_id; unsigned short mjd; unsigned int sod; unsigned char leapsecs; unsigned char ncount; struct rtcm3_1013_t { unsigned short id; _Bool sync; unsigned short interval; } announcements[32]; } rtcm3_1013; struct rtcm3_1014_t { unsigned int network_id; unsigned int subnetwork_id; unsigned int stationcount; unsigned int master_id; unsigned int aux_id; double d_lat; } rtcm3_1014; struct rtcm3_1015_t { struct rtcm3_network_rtk_header { unsigned int network_id; unsigned int subnetwork_id; long time; _Bool multimesg; unsigned int master_id; unsigned int aux_id; unsigned char satcount; } header; struct rtcm3_correction_diff { unsigned char ident; enum { reserved=0, correct=1, widelane=2, uncertain=3 } ambiguity; unsigned char nonsync; double geometric_diff; unsigned char iode; double ionospheric_diff; } corrections[64]; } rtcm3_1015; struct rtcm3_1016_t { struct rtcm3_network_rtk_header header; struct rtcm3_correction_diff corrections[64]; } rtcm3_1016; struct rtcm3_1017_t { struct rtcm3_network_rtk_header header; struct rtcm3_correction_diff corrections[64]; } rtcm3_1017; struct rtcm3_1019_t { unsigned int ident; unsigned int week; unsigned char sv_accuracy; enum { reserved_code=0, p=1, ca=2, l2c=3 } code; double idot; unsigned char iode; unsigned int t_sub_oc; int a_sub_f2; int a_sub_f1; int a_sub_f0; unsigned int iodc; int C_sub_rs; int delta_sub_n; int M_sub_0; int C_sub_uc; unsigned int e; int C_sub_us; unsigned int sqrt_sub_A; unsigned int t_sub_oe; int C_sub_ic; int OMEGA_sub_0; int C_sub_is; int i_sub_0; int C_sub_rc; int argument_of_perigee; int omegadot; int t_sub_GD; unsigned char sv_health; _Bool p_data; _Bool fit_interval; } rtcm3_1019; struct rtcm3_1020_t { unsigned int ident; unsigned short channel; _Bool C_sub_n; _Bool health_avAilability_indicator; unsigned char P1; unsigned short t_sub_k; _Bool msb_of_B_sub_n; _Bool P2; _Bool t_sub_b; int x_sub_n_t_of_t_sub_b_prime; int x_sub_n_t_of_t_sub_b; int x_sub_n_t_of_t_sub_b_prime_prime; int y_sub_n_t_of_t_sub_b_prime; int y_sub_n_t_of_t_sub_b; int y_sub_n_t_of_t_sub_b_prime_prime; int z_sub_n_t_of_t_sub_b_prime; int z_sub_n_t_of_t_sub_b; int z_sub_n_t_of_t_sub_b_prime_prime; _Bool P3; int gamma_sub_n_of_t_sub_b; unsigned char MP; _Bool Ml_n; int tau_n_of_t_sub_b; int M_delta_tau_sub_n; unsigned int E_sub_n; _Bool MP4; unsigned char MF_sub_T; unsigned char MN_sub_T; unsigned char MM; _Bool additioinal_data_availability; unsigned int N_sup_A; unsigned int tau_sub_c; unsigned int M_N_sub_4; int M_tau_sub_GPS; _Bool M_l_sub_n; } rtcm3_1020; struct rtcm3_1029_t { unsigned int station_id; unsigned short mjd; unsigned int sod; unsigned long len; unsigned long unicode_units; unsigned char text[128]; } rtcm3_1029; struct rtcm3_1033_t { unsigned int station_id; char descriptor[-1]; unsigned int setup_id; char serial[-1]; char receiver[-1]; char firmware[-1]; } rtcm3_1033; unsigned char data[1024]; } rtcmtypes; } rtcm3; struct subframe_t { unsigned char subframe_num; unsigned char data_id; unsigned char pageid; unsigned char tSVID; unsigned int TOW17; long l_TOW17; _Bool integrity; _Bool alert; _Bool antispoof; int is_almanac; union { struct { unsigned short WN; unsigned short IODC; unsigned short toc; long l_toc; unsigned char l2; unsigned char l2p; unsigned int ura; unsigned int hlth; int af0; double d_af0; short af1; double d_af1; char af2; double d_af2; char Tgd; double d_Tgd; } sub1; struct { unsigned char IODE; unsigned char AODO; unsigned short u_AODO; unsigned char fit; unsigned short toe; long l_toe; short Crs; double d_Crs; short Cus; double d_Cus; short Cuc; double d_Cuc; short deltan; double d_deltan; int M0; double d_M0; unsigned int e; double d_eccentricity; unsigned int sqrtA; double d_sqrtA; } sub2; struct { unsigned char IODE; short IDOT; double d_IDOT; short Cic; double d_Cic; short Cis; double d_Cis; short Crc; double d_Crc; int i0; double d_i0; int Omega0; double d_Omega0; int omega; double d_omega; int Omegad; double d_Omegad; } sub3; struct { struct almanac_t { unsigned char sv; unsigned char toa; long l_toa; unsigned char svh; short deltai; double d_deltai; int M0; double d_M0; int Omega0; double d_Omega0; int omega; double d_omega; short af0; double d_af0; short af1; double d_af1; unsigned short e; double d_eccentricity; unsigned int sqrtA; double d_sqrtA; short Omegad; double d_Omegad; } almanac; } sub4; struct { char ERD[33]; unsigned char ai; } sub4_13; struct { char str[24]; } sub4_17; struct { int A0; double d_A0; int A1; double d_A1; char alpha0; double d_alpha0; char alpha1; double d_alpha1; char alpha2; double d_alpha2; char alpha3; double d_alpha3; char beta0; double d_beta0; char beta1; double d_beta1; char beta2; double d_beta2; char beta3; double d_beta3; char leap; char lsf; unsigned char tot; double d_tot; unsigned char WNt; unsigned char WNlsf; unsigned char DN; } sub4_18; struct { unsigned char svf[33]; unsigned char svhx[8]; } sub4_25; struct { struct almanac_t almanac; } sub5; struct { unsigned char toa; long l_toa; unsigned char WNa; unsigned char sv[25]; } sub5_25; }; } subframe; struct ais_t { unsigned int type; unsigned int repeat; unsigned int mmsi; union { struct { unsigned int status; int turn; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int heading; unsigned int second; unsigned int maneuver; _Bool raim; unsigned int radio; } type1; struct { unsigned int year; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int second; _Bool accuracy; int lon; int lat; unsigned int epfd; _Bool raim; unsigned int radio; } type4; struct { unsigned int ais_version; unsigned int imo; char callsign[-1]; char shipname[-1]; unsigned int shiptype; unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; unsigned int epfd; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int draught; char destination[-1]; unsigned int dte; } type5; struct { unsigned int seqno; unsigned int dest_mmsi; _Bool retransmit; unsigned int dac; unsigned int fid; _Bool structured; unsigned long bitcount; union { char bitdata[-1]; struct { char country[-1]; char locode[-1]; char section[-1]; char terminal[-1]; char hectometre[-1]; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int tugs; unsigned int airdraught; } dac200fid21; struct { char country[-1]; char locode[-1]; char section[-1]; char terminal[-1]; char hectometre[-1]; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int status; } dac200fid22; struct { unsigned int crew; unsigned int passengers; unsigned int personnel; } dac200fid55; struct { unsigned int ana_int; unsigned int ana_ext1; unsigned int ana_ext2; unsigned int racon; unsigned int light; _Bool alarm; unsigned int stat_ext; _Bool off_pos; } dac235fid10; struct { char lastport[-1]; unsigned int lmonth; unsigned int lday; unsigned int lhour; unsigned int lminute; char nextport[-1]; unsigned int nmonth; unsigned int nday; unsigned int nhour; unsigned int nminute; char dangerous[-1]; char imdcat[-1]; unsigned int unid; unsigned int amount; unsigned int unit; } dac1fid12; struct { unsigned int airdraught; } dac1fid15; struct { unsigned int persons; } dac1fid16; struct { unsigned int linkage; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; char portname[-1]; char destination[-1]; int lon; int lat; } dac1fid18; struct { unsigned int linkage; unsigned int berth_length; unsigned int berth_depth; unsigned int position; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int availability; unsigned int agent; unsigned int fuel; unsigned int chandler; unsigned int stevedore; unsigned int electrical; unsigned int water; unsigned int customs; unsigned int cartage; unsigned int crane; unsigned int lift; unsigned int medical; unsigned int navrepair; unsigned int provisions; unsigned int shiprepair; unsigned int surveyor; unsigned int steam; unsigned int tugs; unsigned int solidwaste; unsigned int liquidwaste; unsigned int hazardouswaste; unsigned int ballast; unsigned int additional; unsigned int regional1; unsigned int regional2; unsigned int future1; unsigned int future2; char berth_name[-1]; int berth_lon; int berth_lat; } dac1fid20; struct { _Bool wmo; union { struct { char location[-1]; int lon; int lat; unsigned int day; unsigned int hour; unsigned int minute; _Bool vislimit; unsigned int visibility; unsigned int humidity; unsigned int wspeed; unsigned int wgust; unsigned int wdir; unsigned int pressure; unsigned int pressuretend; int airtemp; unsigned int watertemp; unsigned int waveperiod; unsigned int wavedir; unsigned int swellheight; unsigned int swellperiod; unsigned int swelldir; } nonwmo_obs; struct { int lon; int lat; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int course; unsigned int speed; unsigned int heading; unsigned int pressure; unsigned int pdelta; unsigned int ptend; unsigned int twinddir; unsigned int twindspeed; unsigned int rwinddir; unsigned int rwindspeed; unsigned int mgustspeed; unsigned int mgustdir; unsigned int airtemp; unsigned int humidity; } wmo_obs; }; } dac1fid21; struct { unsigned int unit; unsigned int amount; int ncargos; struct cargo_t { unsigned int code; unsigned int subtype; } cargos[28]; } dac1fid25; struct route_info { unsigned int linkage; unsigned int sender; unsigned int rtype; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int duration; int waycount; struct waypoint_t { int lon; int lat; } waypoints[16]; } dac1fid28; struct { unsigned int linkage; char text[154]; } dac1fid30; struct { unsigned int month; unsigned int day; int ntidals; struct tidal_t { int lon; int lat; unsigned int from_hour; unsigned int from_min; unsigned int to_hour; unsigned int to_min; unsigned int cdir; unsigned int cspeed; } tidals[3]; } dac1fid32; }; } type6; struct { unsigned int mmsi1; unsigned int mmsi2; unsigned int mmsi3; unsigned int mmsi4; } type7; struct { unsigned int dac; unsigned int fid; unsigned long bitcount; _Bool structured; union { char bitdata[-1]; struct { char vin[-1]; unsigned int length; unsigned int beam; unsigned int shiptype; unsigned int hazard; unsigned int draught; unsigned int loaded; _Bool speed_q; _Bool course_q; _Bool heading_q; } dac200fid10; struct { unsigned int start_year; unsigned int start_month; unsigned int start_day; unsigned int end_year; unsigned int end_month; unsigned int end_day; unsigned int start_hour; unsigned int start_minute; unsigned int end_hour; unsigned int end_minute; int start_lon; int start_lat; int end_lon; int end_lat; unsigned int type; int min; int max; unsigned int intensity; unsigned int wind; } dac200fid23; struct { char country[-1]; int ngauges; struct gauge_t { unsigned int id; int level; } gauges[4]; } dac200fid24; struct { int lon; int lat; unsigned int form; unsigned int facing; unsigned int direction; unsigned int status; } dac200fid40; struct { int lon; int lat; unsigned int day; unsigned int hour; unsigned int minute; unsigned int wspeed; unsigned int wgust; unsigned int wdir; unsigned int wgustdir; unsigned int airtemp; unsigned int humidity; unsigned int dewpoint; unsigned int pressure; unsigned int pressuretend; unsigned int visibility; int waterlevel; unsigned int leveltrend; unsigned int cspeed; unsigned int cdir; unsigned int cspeed2; unsigned int cdir2; unsigned int cdepth2; unsigned int cspeed3; unsigned int cdir3; unsigned int cdepth3; unsigned int waveheight; unsigned int waveperiod; unsigned int wavedir; unsigned int swellheight; unsigned int swellperiod; unsigned int swelldir; unsigned int seastate; unsigned int watertemp; unsigned int preciptype; unsigned int salinity; unsigned int ice; } dac1fid11; struct { char reason[-1]; char closefrom[-1]; char closeto[-1]; unsigned int radius; unsigned int extunit; unsigned int fday; unsigned int fmonth; unsigned int fhour; unsigned int fminute; unsigned int tday; unsigned int tmonth; unsigned int thour; unsigned int tminute; } dac1fid13; struct { unsigned int airdraught; } dac1fid15; struct { unsigned int persons; } dac1fid16; struct { int ntargets; struct target_t { unsigned int idtype; union target_id { unsigned int mmsi; unsigned int imo; char callsign[-1]; char other[-1]; } id; int lat; int lon; unsigned int course; unsigned int second; unsigned int speed; } targets[4]; } dac1fid17; struct { unsigned int linkage; char station[-1]; int lon; int lat; unsigned int status; unsigned int signal; unsigned int hour; unsigned int minute; unsigned int nextsignal; } dac1fid19; struct route_info dac1fid27; struct { unsigned int linkage; char text[162]; } dac1fid29; struct { _Bool accuracy; int lon; int lat; unsigned int day; unsigned int hour; unsigned int minute; unsigned int wspeed; unsigned int wgust; unsigned int wdir; unsigned int wgustdir; int airtemp; unsigned int humidity; int dewpoint; unsigned int pressure; unsigned int pressuretend; _Bool visgreater; unsigned int visibility; int waterlevel; unsigned int leveltrend; unsigned int cspeed; unsigned int cdir; unsigned int cspeed2; unsigned int cdir2; unsigned int cdepth2; unsigned int cspeed3; unsigned int cdir3; unsigned int cdepth3; unsigned int waveheight; unsigned int waveperiod; unsigned int wavedir; unsigned int swellheight; unsigned int swellperiod; unsigned int swelldir; unsigned int seastate; int watertemp; unsigned int preciptype; unsigned int salinity; unsigned int ice; } dac1fid31; }; } type8; struct { unsigned int alt; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int second; unsigned int regional; unsigned int dte; _Bool assigned; _Bool raim; unsigned int radio; } type9; struct { unsigned int dest_mmsi; } type10; struct { unsigned int seqno; unsigned int dest_mmsi; _Bool retransmit; char text[157]; } type12; struct { char text[161]; } type14; struct { unsigned int mmsi1; unsigned int type1_1; unsigned int offset1_1; unsigned int type1_2; unsigned int offset1_2; unsigned int mmsi2; unsigned int type2_1; unsigned int offset2_1; } type15; struct { unsigned int mmsi1; unsigned int offset1; unsigned int increment1; unsigned int mmsi2; unsigned int offset2; unsigned int increment2; } type16; struct { int lon; int lat; unsigned long bitcount; char bitdata[-1]; } type17; struct { unsigned int reserved; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int heading; unsigned int second; unsigned int regional; _Bool cs; _Bool display; _Bool dsc; _Bool band; _Bool msg22; _Bool assigned; _Bool raim; unsigned int radio; } type18; struct { unsigned int reserved; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int heading; unsigned int second; unsigned int regional; char shipname[-1]; unsigned int shiptype; unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; unsigned int epfd; _Bool raim; unsigned int dte; _Bool assigned; } type19; struct { unsigned int offset1; unsigned int number1; unsigned int timeout1; unsigned int increment1; unsigned int offset2; unsigned int number2; unsigned int timeout2; unsigned int increment2; unsigned int offset3; unsigned int number3; unsigned int timeout3; unsigned int increment3; unsigned int offset4; unsigned int number4; unsigned int timeout4; unsigned int increment4; } type20; struct { unsigned int aid_type; char name[35]; _Bool accuracy; int lon; int lat; unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; unsigned int epfd; unsigned int second; _Bool off_position; unsigned int regional; _Bool raim; _Bool virtual_aid; _Bool assigned; } type21; struct { unsigned int channel_a; unsigned int channel_b; unsigned int txrx; _Bool power; union { struct { int ne_lon; int ne_lat; int sw_lon; int sw_lat; } area; struct { unsigned int dest1; unsigned int dest2; } mmsi; }; _Bool addressed; _Bool band_a; _Bool band_b; unsigned int zonesize; } type22; struct { int ne_lon; int ne_lat; int sw_lon; int sw_lat; unsigned int stationtype; unsigned int shiptype; unsigned int txrx; unsigned int interval; unsigned int quiet; } type23; struct { char shipname[-1]; enum { both=0, part_a=1, part_b=2 } part; unsigned int shiptype; char vendorid[8]; unsigned int model; unsigned int serial; char callsign[8]; union { unsigned int mothership_mmsi; struct { unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; } dim; }; } type24; struct { _Bool addressed; _Bool structured; unsigned int dest_mmsi; unsigned int app_id; unsigned long bitcount; char bitdata[-1]; } type25; struct { _Bool addressed; _Bool structured; unsigned int dest_mmsi; unsigned int app_id; unsigned long bitcount; char bitdata[-1]; unsigned int radio; } type26; struct { _Bool accuracy; _Bool raim; unsigned int status; int lon; int lat; unsigned int speed; unsigned int course; _Bool gnss; } type27; }; } ais; struct attitude_t { double heading; double pitch; double roll; double yaw; double dip; double mag_len; double mag_x; double mag_y; double mag_z; double acc_len; double acc_x; double acc_y; double acc_z; double gyro_x; double gyro_y; double temp; double depth; char mag_st; char pitch_st; char roll_st; char yaw_st; } attitude; struct navdata_t { unsigned int version; double compass_heading; double compass_deviation; double compass_variation; double air_temp; double air_pressure; double water_temp; double depth; double depth_offset; double wind_speed; double wind_dir; double crosstrack_error; unsigned int compass_status; unsigned int log_cumulative; unsigned int log_trip; unsigned int crosstrack_status; } navdata; struct rawdata_t { double codephase[72]; double carrierphase[72]; double pseudorange[72]; double deltarange[72]; double doppler[72]; double mtime[72]; unsigned int satstat[72]; } raw; struct gst_t { double utctime; double rms_deviation; double smajor_deviation; double sminor_deviation; double smajor_orientation; double lat_err_deviation; double lon_err_deviation; double alt_err_deviation; } gst; struct oscillator_t { _Bool running; _Bool reference; _Bool disciplined; int delta; } osc; struct version_t { char release[64]; char rev[64]; int proto_major; char remote[128]; } version; char error[256]; struct timedelta_t { struct timespec { long tv_sec; long tv_nsec; } real; struct timespec clock; } toff; struct timedelta_t pps; }; void *privdata; } *

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

variable_types: time long

user_defined_types: struct gps_data_t { unsigned long set; double online; int gps_fd; struct gps_fix_t fix; double separation; int status; int satellites_used; struct dop_t dop; double epe; double skyview_time; int satellites_visible; struct satellite_t skyview[72]; struct devconfig_t dev; struct policy_t policy; struct { double time; int ndevices; struct devconfig_t list[4]; } devices; union { struct rtcm2_t rtcm2; struct rtcm3_t rtcm3; struct subframe_t subframe; struct ais_t ais; struct attitude_t attitude; struct navdata_t navdata; struct rawdata_t raw; struct gst_t gst; struct oscillator_t osc; struct version_t version; char error[256]; struct timedelta_t toff; struct timedelta_t pps; }; void *privdata; }

user_defined_types: struct rtcm2_t { unsigned int type; unsigned int length; double zcount; unsigned int refstaid; unsigned int seqnum; unsigned int stathlth; union { struct { unsigned int nentries; struct gps_rangesat_t sat[18]; } gps_ranges; struct { _Bool valid; double x; } ecef; struct { _Bool valid; int system; int sense; char datum[6]; double dx; } reference; struct { unsigned int nentries; struct consat_t sat[-1]; } conhealth; struct { unsigned int nentries; struct station_t station[10]; } almanac; struct { _Bool status; _Bool rangeflag; double lat; unsigned int range; } xmitter; struct { unsigned int week; unsigned int hour; unsigned int leapsecs; } gpstime; struct { unsigned int nentries; struct glonass_rangesat_t sat[18]; } glonass_ranges; char message[-1]; unsigned int words[-1]; }; }

user_defined_types: struct rtcm3_t { unsigned int type; unsigned int length; union { struct { struct rtcm3_rtk_hdr header; struct rtcm3_1001_t rtk_data[64]; } rtcm3_1001; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1002_t rtk_data[64]; } rtcm3_1002; struct rtcm3_1003_t rtcm3_1003; struct rtcm3_1004_t rtcm3_1004; struct rtcm3_1005_t rtcm3_1005; struct rtcm3_1006_t rtcm3_1006; struct { unsigned int station_id; char descriptor[-1]; unsigned int setup_id; } rtcm3_1007; struct { unsigned int station_id; char descriptor[-1]; unsigned int setup_id; char serial[-1]; } rtcm3_1008; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1009_t rtk_data[64]; } rtcm3_1009; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1010_t rtk_data[64]; } rtcm3_1010; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1011_t rtk_data[64]; } rtcm3_1011; struct { struct rtcm3_rtk_hdr header; struct rtcm3_1012_t rtk_data[64]; } rtcm3_1012; struct { unsigned int station_id; unsigned short mjd; unsigned int sod; unsigned char leapsecs; unsigned char ncount; struct rtcm3_1013_t announcements[32]; } rtcm3_1013; struct rtcm3_1014_t rtcm3_1014; struct rtcm3_1015_t rtcm3_1015; struct rtcm3_1016_t rtcm3_1016; struct rtcm3_1017_t rtcm3_1017; struct rtcm3_1019_t rtcm3_1019; struct rtcm3_1020_t rtcm3_1020; struct rtcm3_1029_t rtcm3_1029; struct rtcm3_1033_t rtcm3_1033; unsigned char data[1024]; } rtcmtypes; }

user_defined_types: struct subframe_t { unsigned char subframe_num; unsigned char data_id; unsigned char pageid; unsigned char tSVID; unsigned int TOW17; long l_TOW17; _Bool integrity; _Bool alert; _Bool antispoof; int is_almanac; union { struct { unsigned short WN; unsigned short IODC; unsigned short toc; long l_toc; unsigned char l2; unsigned char l2p; unsigned int ura; unsigned int hlth; int af0; double d_af0; short af1; double d_af1; char af2; double d_af2; char Tgd; double d_Tgd; } sub1; struct { unsigned char IODE; unsigned char AODO; unsigned short u_AODO; unsigned char fit; unsigned short toe; long l_toe; short Crs; double d_Crs; short Cus; double d_Cus; short Cuc; double d_Cuc; short deltan; double d_deltan; int M0; double d_M0; unsigned int e; double d_eccentricity; unsigned int sqrtA; double d_sqrtA; } sub2; struct { unsigned char IODE; short IDOT; double d_IDOT; short Cic; double d_Cic; short Cis; double d_Cis; short Crc; double d_Crc; int i0; double d_i0; int Omega0; double d_Omega0; int omega; double d_omega; int Omegad; double d_Omegad; } sub3; struct { struct almanac_t almanac; } sub4; struct { char ERD[33]; unsigned char ai; } sub4_13; struct { char str[24]; } sub4_17; struct { int A0; double d_A0; int A1; double d_A1; char alpha0; double d_alpha0; char alpha1; double d_alpha1; char alpha2; double d_alpha2; char alpha3; double d_alpha3; char beta0; double d_beta0; char beta1; double d_beta1; char beta2; double d_beta2; char beta3; double d_beta3; char leap; char lsf; unsigned char tot; double d_tot; unsigned char WNt; unsigned char WNlsf; unsigned char DN; } sub4_18; struct { unsigned char svf[33]; unsigned char svhx[8]; } sub4_25; struct { struct almanac_t almanac; } sub5; struct { unsigned char toa; long l_toa; unsigned char WNa; unsigned char sv[25]; } sub5_25; }; }

user_defined_types: struct ais_t { unsigned int type; unsigned int repeat; unsigned int mmsi; union { struct { unsigned int status; int turn; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int heading; unsigned int second; unsigned int maneuver; _Bool raim; unsigned int radio; } type1; struct { unsigned int year; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int second; _Bool accuracy; int lon; int lat; unsigned int epfd; _Bool raim; unsigned int radio; } type4; struct { unsigned int ais_version; unsigned int imo; char callsign[-1]; char shipname[-1]; unsigned int shiptype; unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; unsigned int epfd; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int draught; char destination[-1]; unsigned int dte; } type5; struct { unsigned int seqno; unsigned int dest_mmsi; _Bool retransmit; unsigned int dac; unsigned int fid; _Bool structured; unsigned long bitcount; union { char bitdata[-1]; struct { char country[-1]; char locode[-1]; char section[-1]; char terminal[-1]; char hectometre[-1]; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int tugs; unsigned int airdraught; } dac200fid21; struct { char country[-1]; char locode[-1]; char section[-1]; char terminal[-1]; char hectometre[-1]; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int status; } dac200fid22; struct { unsigned int crew; unsigned int passengers; unsigned int personnel; } dac200fid55; struct { unsigned int ana_int; unsigned int ana_ext1; unsigned int ana_ext2; unsigned int racon; unsigned int light; _Bool alarm; unsigned int stat_ext; _Bool off_pos; } dac235fid10; struct { char lastport[-1]; unsigned int lmonth; unsigned int lday; unsigned int lhour; unsigned int lminute; char nextport[-1]; unsigned int nmonth; unsigned int nday; unsigned int nhour; unsigned int nminute; char dangerous[-1]; char imdcat[-1]; unsigned int unid; unsigned int amount; unsigned int unit; } dac1fid12; struct { unsigned int airdraught; } dac1fid15; struct { unsigned int persons; } dac1fid16; struct { unsigned int linkage; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; char portname[-1]; char destination[-1]; int lon; int lat; } dac1fid18; struct { unsigned int linkage; unsigned int berth_length; unsigned int berth_depth; unsigned int position; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int availability; unsigned int agent; unsigned int fuel; unsigned int chandler; unsigned int stevedore; unsigned int electrical; unsigned int water; unsigned int customs; unsigned int cartage; unsigned int crane; unsigned int lift; unsigned int medical; unsigned int navrepair; unsigned int provisions; unsigned int shiprepair; unsigned int surveyor; unsigned int steam; unsigned int tugs; unsigned int solidwaste; unsigned int liquidwaste; unsigned int hazardouswaste; unsigned int ballast; unsigned int additional; unsigned int regional1; unsigned int regional2; unsigned int future1; unsigned int future2; char berth_name[-1]; int berth_lon; int berth_lat; } dac1fid20; struct { _Bool wmo; union { struct { char location[-1]; int lon; int lat; unsigned int day; unsigned int hour; unsigned int minute; _Bool vislimit; unsigned int visibility; unsigned int humidity; unsigned int wspeed; unsigned int wgust; unsigned int wdir; unsigned int pressure; unsigned int pressuretend; int airtemp; unsigned int watertemp; unsigned int waveperiod; unsigned int wavedir; unsigned int swellheight; unsigned int swellperiod; unsigned int swelldir; } nonwmo_obs; struct { int lon; int lat; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int course; unsigned int speed; unsigned int heading; unsigned int pressure; unsigned int pdelta; unsigned int ptend; unsigned int twinddir; unsigned int twindspeed; unsigned int rwinddir; unsigned int rwindspeed; unsigned int mgustspeed; unsigned int mgustdir; unsigned int airtemp; unsigned int humidity; } wmo_obs; }; } dac1fid21; struct { unsigned int unit; unsigned int amount; int ncargos; struct cargo_t cargos[28]; } dac1fid25; struct route_info dac1fid28; struct { unsigned int linkage; char text[154]; } dac1fid30; struct { unsigned int month; unsigned int day; int ntidals; struct tidal_t tidals[3]; } dac1fid32; }; } type6; struct { unsigned int mmsi1; unsigned int mmsi2; unsigned int mmsi3; unsigned int mmsi4; } type7; struct { unsigned int dac; unsigned int fid; unsigned long bitcount; _Bool structured; union { char bitdata[-1]; struct { char vin[-1]; unsigned int length; unsigned int beam; unsigned int shiptype; unsigned int hazard; unsigned int draught; unsigned int loaded; _Bool speed_q; _Bool course_q; _Bool heading_q; } dac200fid10; struct { unsigned int start_year; unsigned int start_month; unsigned int start_day; unsigned int end_year; unsigned int end_month; unsigned int end_day; unsigned int start_hour; unsigned int start_minute; unsigned int end_hour; unsigned int end_minute; int start_lon; int start_lat; int end_lon; int end_lat; unsigned int type; int min; int max; unsigned int intensity; unsigned int wind; } dac200fid23; struct { char country[-1]; int ngauges; struct gauge_t gauges[4]; } dac200fid24; struct { int lon; int lat; unsigned int form; unsigned int facing; unsigned int direction; unsigned int status; } dac200fid40; struct { int lon; int lat; unsigned int day; unsigned int hour; unsigned int minute; unsigned int wspeed; unsigned int wgust; unsigned int wdir; unsigned int wgustdir; unsigned int airtemp; unsigned int humidity; unsigned int dewpoint; unsigned int pressure; unsigned int pressuretend; unsigned int visibility; int waterlevel; unsigned int leveltrend; unsigned int cspeed; unsigned int cdir; unsigned int cspeed2; unsigned int cdir2; unsigned int cdepth2; unsigned int cspeed3; unsigned int cdir3; unsigned int cdepth3; unsigned int waveheight; unsigned int waveperiod; unsigned int wavedir; unsigned int swellheight; unsigned int swellperiod; unsigned int swelldir; unsigned int seastate; unsigned int watertemp; unsigned int preciptype; unsigned int salinity; unsigned int ice; } dac1fid11; struct { char reason[-1]; char closefrom[-1]; char closeto[-1]; unsigned int radius; unsigned int extunit; unsigned int fday; unsigned int fmonth; unsigned int fhour; unsigned int fminute; unsigned int tday; unsigned int tmonth; unsigned int thour; unsigned int tminute; } dac1fid13; struct { unsigned int airdraught; } dac1fid15; struct { unsigned int persons; } dac1fid16; struct { int ntargets; struct target_t targets[4]; } dac1fid17; struct { unsigned int linkage; char station[-1]; int lon; int lat; unsigned int status; unsigned int signal; unsigned int hour; unsigned int minute; unsigned int nextsignal; } dac1fid19; struct route_info dac1fid27; struct { unsigned int linkage; char text[162]; } dac1fid29; struct { _Bool accuracy; int lon; int lat; unsigned int day; unsigned int hour; unsigned int minute; unsigned int wspeed; unsigned int wgust; unsigned int wdir; unsigned int wgustdir; int airtemp; unsigned int humidity; int dewpoint; unsigned int pressure; unsigned int pressuretend; _Bool visgreater; unsigned int visibility; int waterlevel; unsigned int leveltrend; unsigned int cspeed; unsigned int cdir; unsigned int cspeed2; unsigned int cdir2; unsigned int cdepth2; unsigned int cspeed3; unsigned int cdir3; unsigned int cdepth3; unsigned int waveheight; unsigned int waveperiod; unsigned int wavedir; unsigned int swellheight; unsigned int swellperiod; unsigned int swelldir; unsigned int seastate; int watertemp; unsigned int preciptype; unsigned int salinity; unsigned int ice; } dac1fid31; }; } type8; struct { unsigned int alt; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int second; unsigned int regional; unsigned int dte; _Bool assigned; _Bool raim; unsigned int radio; } type9; struct { unsigned int dest_mmsi; } type10; struct { unsigned int seqno; unsigned int dest_mmsi; _Bool retransmit; char text[157]; } type12; struct { char text[161]; } type14; struct { unsigned int mmsi1; unsigned int type1_1; unsigned int offset1_1; unsigned int type1_2; unsigned int offset1_2; unsigned int mmsi2; unsigned int type2_1; unsigned int offset2_1; } type15; struct { unsigned int mmsi1; unsigned int offset1; unsigned int increment1; unsigned int mmsi2; unsigned int offset2; unsigned int increment2; } type16; struct { int lon; int lat; unsigned long bitcount; char bitdata[-1]; } type17; struct { unsigned int reserved; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int heading; unsigned int second; unsigned int regional; _Bool cs; _Bool display; _Bool dsc; _Bool band; _Bool msg22; _Bool assigned; _Bool raim; unsigned int radio; } type18; struct { unsigned int reserved; unsigned int speed; _Bool accuracy; int lon; int lat; unsigned int course; unsigned int heading; unsigned int second; unsigned int regional; char shipname[-1]; unsigned int shiptype; unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; unsigned int epfd; _Bool raim; unsigned int dte; _Bool assigned; } type19; struct { unsigned int offset1; unsigned int number1; unsigned int timeout1; unsigned int increment1; unsigned int offset2; unsigned int number2; unsigned int timeout2; unsigned int increment2; unsigned int offset3; unsigned int number3; unsigned int timeout3; unsigned int increment3; unsigned int offset4; unsigned int number4; unsigned int timeout4; unsigned int increment4; } type20; struct { unsigned int aid_type; char name[35]; _Bool accuracy; int lon; int lat; unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; unsigned int epfd; unsigned int second; _Bool off_position; unsigned int regional; _Bool raim; _Bool virtual_aid; _Bool assigned; } type21; struct { unsigned int channel_a; unsigned int channel_b; unsigned int txrx; _Bool power; union { struct { int ne_lon; int ne_lat; int sw_lon; int sw_lat; } area; struct { unsigned int dest1; unsigned int dest2; } mmsi; }; _Bool addressed; _Bool band_a; _Bool band_b; unsigned int zonesize; } type22; struct { int ne_lon; int ne_lat; int sw_lon; int sw_lat; unsigned int stationtype; unsigned int shiptype; unsigned int txrx; unsigned int interval; unsigned int quiet; } type23; struct { char shipname[-1]; enum { both=0, part_a=1, part_b=2 } part; unsigned int shiptype; char vendorid[8]; unsigned int model; unsigned int serial; char callsign[8]; union { unsigned int mothership_mmsi; struct { unsigned int to_bow; unsigned int to_stern; unsigned int to_port; unsigned int to_starboard; } dim; }; } type24; struct { _Bool addressed; _Bool structured; unsigned int dest_mmsi; unsigned int app_id; unsigned long bitcount; char bitdata[-1]; } type25; struct { _Bool addressed; _Bool structured; unsigned int dest_mmsi; unsigned int app_id; unsigned long bitcount; char bitdata[-1]; unsigned int radio; } type26; struct { _Bool accuracy; _Bool raim; unsigned int status; int lon; int lat; unsigned int speed; unsigned int course; _Bool gnss; } type27; }; }

user_defined_types: struct timedelta_t { struct timespec real; struct timespec clock; }

user_defined_types: struct rtcm3_1015_t { struct rtcm3_network_rtk_header header; struct rtcm3_correction_diff corrections[64]; }

user_defined_types: struct rtcm3_1001_t { unsigned int ident; struct rtcm3_basic_rtk L1; }

user_defined_types: struct rtcm3_1002_t { unsigned int ident; struct rtcm3_extended_rtk L1; }

user_defined_types: struct route_info { unsigned int linkage; unsigned int sender; unsigned int rtype; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int duration; int waycount; struct waypoint_t waypoints[16]; }

user_defined_types: struct target_t { unsigned int idtype; union target_id id; int lat; int lon; unsigned int course; unsigned int second; unsigned int speed; }


main

canonical_name: main

repo: boltnev/minesweeper

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

if ( argc == 1 )
{
v4 = malloc(0x1D4CCuLL);
makeGame(v4, 10LL, 10LL, 10LL);
play(v4);
free(v4);
}
return 0;
}

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

if ( argc == 1 )
{
v4 = malloc(0x1D4CCuLL);
func8(v4, 10LL, 10LL, 10LL);
func22(v4);
free(v4);
}
return 0;
}

original_code:
int main(int argc, char* argv[]){
    if(argc == 1){
        Minefield *gameField = malloc(sizeof( Minefield ));
  makeGame(gameField, 10, 10, 10);
  play(gameField);
  free(gameField);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    if(argc == 1){
        struct t_Minefield *gameField = malloc(sizeof( Minefield ));
  makeGame(gameField, 10, 10, 10);
  play(gameField);
  free(gameField);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct t_Minefield { int xSize; int ySize; unsigned int minesNumber; struct t_Place { unsigned int numberOfMinesNear; int mine; int state; } places[100][100]; } *

return_type: int

user_defined_types: struct t_Minefield { int xSize; int ySize; unsigned int minesNumber; struct t_Place places[100][100]; }


initEmptyMinefield

original_code:
void initEmptyMinefield(Minefield *minefield, unsigned x, unsigned y){
    int i, j;
    for(i = 0; i < x; i++)
        for(j = 0; j < y; j++){
            minefield->places[i][j].mine = EMPTY;
            minefield->places[i][j].state = HIDDEN;
            minefield->places[i][j].numberOfMinesNear = 0;
        }
    minefield->xSize = x;
    minefield->ySize = y;
}

canonical_original_code:
void initEmptyMinefield(struct t_Minefield *minefield, unsigned int x, unsigned int y){
    int i; int j;
    for(i = 0; i < x; i++)
        for(j = 0; j < y; j++){
            minefield->places[i][j].mine = EMPTY;
            minefield->places[i][j].state = HIDDEN;
            minefield->places[i][j].numberOfMinesNear = 0;
        }
    minefield->xSize = x;
    minefield->ySize = y;
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types: i int

variable_types: j int

return_type: void

user_defined_types: struct t_Place { unsigned int numberOfMinesNear; int mine; int state; }


makeGame

decompiled_code:
void __fastcall makeGame(_DWORD *a1, unsigned int a2, unsigned int a3, int a4)
{
int v4; // er14
int v5; // er15
unsigned int v7; // eax
__int64 v8; // rbx
_DWORD *v9; // rax

v4 = a4;
v5 = a4;
initEmptyMinefield(a1, a2, a3);
v7 = time(0LL);
srand(v7);
while ( v5 )
{
while ( 1 )
{
v8 = (int)(rand() % a2);
v9 = &a1[300 * v8 + 3 * (int)(rand() % a3)];
if ( v9[4] )
break;
--v5;
v9[4] = 1;
if ( !v5 )
goto LABEL_5;
}
}
LABEL_5:
a1[2] = v4;
}

canonical_decompiled_code:
void __fastcall func8(_DWORD *a1, unsigned int a2, unsigned int a3, int a4)
{
int v4; // er14
int v5; // er15
unsigned int v7; // eax
__int64 v8; // rbx
_DWORD *v9; // rax

v4 = a4;
v5 = a4;
func7(a1, a2, a3);
v7 = time(0LL);
srand(v7);
while ( v5 )
{
while ( 1 )
{
v8 = (int)(rand() % a2);
v9 = &a1[300 * v8 + 3 * (int)(rand() % a3)];
if ( v9[4] )
break;
--v5;
v9[4] = 1;
if ( !v5 )
goto LABEL_5;
}
}
LABEL_5:
a1[2] = v4;
}

original_code:
void makeGame(Minefield *minefield, unsigned x, unsigned y, unsigned mines){
    int i, j;
    initEmptyMinefield(minefield,x, y);
    unsigned minesToPlace = mines;
    srand(time(((void *)0)));
    while(minesToPlace > 0){
      i = rand() % x;
      j = rand() % y;
      if(minefield->places[i][j].mine)
          continue;
      minefield->places[i][j].mine = MINE;
      minesToPlace--;
    }
    minefield->minesNumber = mines;
}

canonical_original_code:
void makeGame(struct t_Minefield *minefield, unsigned int x, unsigned int y, unsigned int mines){
    int i; int j;
    initEmptyMinefield(minefield,x, y);
    unsigned int minesToPlace = mines;
    srand(time(((void *)0)));
    while(minesToPlace > 0){
      i = rand() % x;
      j = rand() % y;
      if(minefield->places[i][j].mine)
          continue;
      minefield->places[i][j].mine = MINE;
      minesToPlace--;
    }
    minefield->minesNumber = mines;
}

variable_types:
mines
unsigned int

variable_types:
minesToPlace
unsigned int


increaseNumberOfMilesAround

decompiled_code:
__int64 __fastcall increaseNumberOfMilesAround(int *a1, int a2, int a3)
{
int v3; // ecx
int v5; // er11
int v6; // er9
int *v7; // rdi
int *v8; // rdx
__int64 result; // rax

v3 = a2 - 1;
v5 = a3 - 1;
v6 = a3 + 2;
v7 = &a1[300 * a2 - 300 + 3 * a3];
do
{
v8 = v7;
LODWORD(result) = v5;
do
{
if ( (int)result >= 0 && v3 >= 0 && *a1 > v3 && a1[1] > (int)result )
++*v8;
result = (unsigned int)(result + 1);
v8 += 3;
}
while ( (_DWORD)result != v6 );
++v3;
v7 += 300;
}
while ( v3 != a2 + 2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, int a2, int a3)
{
int v3; // ecx
int v5; // er11
int v6; // er9
int *v7; // rdi
int *v8; // rdx
__int64 result; // rax

v3 = a2 - 1;
v5 = a3 - 1;
v6 = a3 + 2;
v7 = &a1[300 * a2 - 300 + 3 * a3];
do
{
v8 = v7;
LODWORD(result) = v5;
do
{
if ( (int)result >= 0 && v3 >= 0 && *a1 > v3 && a1[1] > (int)result )
++*v8;
result = (unsigned int)(result + 1);
v8 += 3;
}
while ( (_DWORD)result != v6 );
++v3;
v7 += 300;
}
while ( v3 != a2 + 2 );
return result;
}

original_code:
void increaseNumberOfMilesAround(Minefield *field, int x, int y ){
    int s, t;
    for(s = x - 1; s <= x + 1; s++)
        for(t = y - 1; t <= y + 1; t++)
            if((s >= 0 && t >= 0) &&
               (s < field->xSize && t < field->ySize))
               field->places[s][t].numberOfMinesNear++;
}

canonical_original_code:
void increaseNumberOfMilesAround(struct t_Minefield *field, int x, int y){
    int s; int t;
    for(s = x - 1; s <= x + 1; s++)
        for(t = y - 1; t <= y + 1; t++)
            if((s >= 0 && t >= 0) &&
               (s < field->xSize && t < field->ySize))
               field->places[s][t].numberOfMinesNear++;
}

variable_types: x int

variable_types: y int

variable_types: s int

variable_types: t int


placeNumbers

decompiled_code:
__int64 __fastcall placeNumbers(int *a1)
{
_DWORD *v1; // r14
int v2; // er13
__int64 result; // rax
_DWORD *v4; // rbp
int v5; // ebx
int v6; // edx

if ( *a1 > 0 )
{
v1 = a1 + 4;
v2 = 0;
do
{
result = (unsigned int)a1[1];
v4 = v1;
v5 = 0;
if ( (int)result > 0 )
{
do
{
while ( !*v4 )
{
++v5;
v4 += 3;
if ( a1[1] <= v5 )
goto LABEL_8;
}
v6 = v5++;
result = increaseNumberOfMilesAround(a1, v2, v6);
v4 += 3;
}
while ( a1[1] > v5 );
}
LABEL_8:
++v2;
v1 += 300;
}
while ( *a1 > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1)
{
_DWORD *v1; // r14
int v2; // er13
__int64 result; // rax
_DWORD *v4; // rbp
int v5; // ebx
int v6; // edx

if ( *a1 > 0 )
{
v1 = a1 + 4;
v2 = 0;
do
{
result = (unsigned int)a1[1];
v4 = v1;
v5 = 0;
if ( (int)result > 0 )
{
do
{
while ( !*v4 )
{
++v5;
v4 += 3;
if ( a1[1] <= v5 )
goto LABEL_8;
}
v6 = v5++;
result = func9(a1, v2, v6);
v4 += 3;
}
while ( a1[1] > v5 );
}
LABEL_8:
++v2;
v1 += 300;
}
while ( *a1 > v2 );
}
return result;
}

original_code:
void placeNumbers(Minefield *field){
    int i, j, s, t;
    for(i = 0; i < field->xSize; i++)
        for(j = 0; j < field->ySize; j++)
            if(field->places[i][j].mine)
                increaseNumberOfMilesAround(field, i, j);
}

canonical_original_code:
void placeNumbers(struct t_Minefield *field){
    int i; int j; int s; int t;
    for(i = 0; i < field->xSize; i++)
        for(j = 0; j < field->ySize; j++)
            if(field->places[i][j].mine)
                increaseNumberOfMilesAround(field, i, j);
}


openPlace

original_code:
void openPlace(Minefield *field, int x, int y){
    if(x < 0 || x >= field->xSize || y < 0 || y >= field->ySize)
        return;
    if(field->places[x][y].state != VISIBLE){
       field->places[x][y].state = VISIBLE;
       if(field->places[x][y].numberOfMinesNear == 0)
            openNearbyPlaces(field, x, y);
    }
}

canonical_original_code:
void openPlace(struct t_Minefield *field, int x, int y){
    if(x < 0 || x >= field->xSize || y < 0 || y >= field->ySize)
        return;
    if(field->places[x][y].state != VISIBLE){
       field->places[x][y].state = VISIBLE;
       if(field->places[x][y].numberOfMinesNear == 0)
            openNearbyPlaces(field, x, y);
    }
}


openNearbyPlaces

decompiled_code:
void __fastcall openNearbyPlaces(int *a1, int a2, int a3)
{
openPlace(a1, a2 - 1, a3);
openPlace(a1, a2, a3 - 1);
openPlace(a1, a2 + 1, a3);
openPlace(a1, a2, a3 + 1);
}

original_code:
void openNearbyPlaces(Minefield *field, int x, int y){
    openPlace(field, x - 1, y);
    openPlace(field, x, y - 1);
    openPlace(field, x + 1, y );
    openPlace(field, x, y + 1);
}

canonical_original_code:
void openNearbyPlaces(struct t_Minefield *field, int x, int y){
    openPlace(field, x - 1, y);
    openPlace(field, x, y - 1);
    openPlace(field, x + 1, y );
    openPlace(field, x, y + 1);
}


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

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
*(_DWORD *)(a1 + 8) = 0;
}
else
{
*(_DWORD *)(a1 + 8) = 2;
}
return result;
}

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

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
*(_DWORD *)(a1 + 8) = 0;
}
else
{
*(_DWORD *)(a1 + 8) = 2;
}
return result;
}

original_code:
void switch_flag(Place *place){
 if(place->state == HIDDEN)
  place->state = FLAG;
 else if (place->state == FLAG)
  place->state = HIDDEN;
}

canonical_original_code:
void switch_flag(struct t_Place *place){
 if(place->state == HIDDEN)
  place->state = FLAG;
 else if (place->state == FLAG)
  place->state = HIDDEN;
}

variable_types: struct t_Place { unsigned int numberOfMinesNear; int mine; int state; } *


drawField

decompiled_code:
void __fastcall drawField(int *a1)
{
unsigned int *v1; // r14
int v2; // er13
unsigned int *v3; // rbx
int v4; // ebp
unsigned int v5; // eax

if ( *a1 > 0 )
{
v1 = (unsigned int *)(a1 + 3);
v2 = 0;
while ( 1 )
{
v3 = v1;
v4 = 0;
if ( a1[1] > 0 )
break;
LABEL_11:
++v2;
v1 += 300;
putchar(10);
if ( *a1 <= v2 )
return;
}
while ( 1 )
{
v5 = v3[2];
if ( v5 == 1 )
break;
if ( v5 == 2 )
{
++v4;
v3 += 3;
putchar(70);
if ( a1[1] <= v4 )
goto LABEL_11;
}
else
{
if ( !v5 )
putchar(63);
LABEL_7:
++v4;
v3 += 3;
if ( a1[1] <= v4 )
goto LABEL_11;
}
}
if ( v3[1] )
putchar(42);
else
printf("%d", *v3);
goto LABEL_7;
}
}

canonical_decompiled_code:
void __fastcall func15(int *a1)
{
unsigned int *v1; // r14
int v2; // er13
unsigned int *v3; // rbx
int v4; // ebp
unsigned int v5; // eax

if ( *a1 > 0 )
{
v1 = (unsigned int *)(a1 + 3);
v2 = 0;
while ( 1 )
{
v3 = v1;
v4 = 0;
if ( a1[1] > 0 )
break;
LABEL_11:
++v2;
v1 += 300;
putchar(10);
if ( *a1 <= v2 )
return;
}
while ( 1 )
{
v5 = v3[2];
if ( v5 == 1 )
break;
if ( v5 == 2 )
{
++v4;
v3 += 3;
putchar(70);
if ( a1[1] <= v4 )
goto LABEL_11;
}
else
{
if ( !v5 )
putchar(63);
LABEL_7:
++v4;
v3 += 3;
if ( a1[1] <= v4 )
goto LABEL_11;
}
}
if ( v3[1] )
putchar(42);
else
printf("%d", *v3);
goto LABEL_7;
}
}

original_code:
void drawField(Minefield *field){
    int i, j;
    for(i = 0; i < field->xSize; i++){
        for(j = 0; j < field->ySize; j++)
            switch(field->places[i][j].state){
                case VISIBLE:
                {
                     if(field->places[i][j].mine)
                         printf("*");
                     else
                        printf("%d", field->places[i][j].numberOfMinesNear);
                }break;
                case HIDDEN:
                {
                     printf("?");
                }break;
                case FLAG:
                {
                     printf("F");
                }break;
                default:
                break;
            }
        printf("\n");
    }
}

canonical_original_code:
void drawField(struct t_Minefield *field){
    int i; int j;
    for(i = 0; i < field->xSize; i++){
        for(j = 0; j < field->ySize; j++)
            switch(field->places[i][j].state){
                case VISIBLE:
                {
                     if(field->places[i][j].mine)
                         printf("*");
                     else
                        printf("%d", field->places[i][j].numberOfMinesNear);
                }break;
                case HIDDEN:
                {
                     printf("?");
                }break;
                case FLAG:
                {
                     printf("F");
                }break;
                default:
                break;
            }
        printf("\n");
    }
}


setGameState

decompiled_code:
void __fastcall setGameState(int a1)
{
g_gamestate = a1;
}

canonical_decompiled_code:
void __fastcall func16(int a1)
{
g_gamestate = a1;
}

original_code:
void setGameState(int state){
 g_gamestate = state;
}

variable_types: state int


checkGameState

original_code:
void checkGameState(Minefield *field){
    int i, j;
    int countOfVisibles = 0;
    int xSize = field->xSize;
    int ySize = field->ySize;
    for(i = 0; i < xSize; i++){
        for(j = 0; j < ySize; j++){
            if(field->places[i][j].state == VISIBLE && field->places[i][j].mine == MINE){
                setGameState(FAIL);
                updateMinesPlaces(field, VISIBLE);
                return;
            }
            if(field->places[i][j].state == VISIBLE)
                countOfVisibles++;
        }
    }
    if(countOfVisibles == xSize*ySize - field->minesNumber){
        setGameState(WIN);
        updateMinesPlaces(field, FLAG);
        return;
    }
}

canonical_original_code:
void checkGameState(struct t_Minefield *field){
    int i; int j;
    int countOfVisibles = 0;
    int xSize = field->xSize;
    int ySize = field->ySize;
    for(i = 0; i < xSize; i++){
        for(j = 0; j < ySize; j++){
            if(field->places[i][j].state == VISIBLE && field->places[i][j].mine == MINE){
                setGameState(FAIL);
                updateMinesPlaces(field, VISIBLE);
                return;
            }
            if(field->places[i][j].state == VISIBLE)
                countOfVisibles++;
        }
    }
    if(countOfVisibles == xSize*ySize - field->minesNumber){
        setGameState(WIN);
        updateMinesPlaces(field, FLAG);
        return;
    }
}

variable_types: countOfVisibles int

variable_types: xSize int

variable_types: ySize int


getGameState

decompiled_code:
__int64 getGameState()
{
return (unsigned int)g_gamestate;
}

canonical_decompiled_code:
__int64 func18()
{
return (unsigned int)g_gamestate;
}

original_code:
int getGameState(){
 return g_gamestate;
}


moveWith

decompiled_code:
_BOOL8 __fastcall moveWith(int *a1, int a2, int a3, int a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 >= 0 )
{
if ( *a1 > a2 && a3 >= 0 )
{
if ( a1[1] > a3 )
{
if ( a4 == 1 )
{
if ( a1[300 * a2 + 5 + 3 * a3] != 2 )
openPlace(a1, a2, a3);
}
else
{
switch_flag((__int64)&a1[300 * a2 + 3 + 3 * a3]);
}
checkGameState(a1);
result = (unsigned int)getGameState() == 2;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int moveWith(Minefield *field, int x, int y, int action){
    if(x >= 0 && x < field->xSize && y >= 0 && y < field->ySize){
        if(action == 1){
            if(field->places[x][y].state != FLAG)
    openPlace(field, x, y);
   }
  else{
         switch_flag(&field->places[x][y]);
  }
        checkGameState(field);
        if(getGameState() != PLAY)
            return 0;
        else
            return 1;
    }
    return 0;
}

canonical_original_code:
int moveWith(struct t_Minefield *field, int x, int y, int action){
    if(x >= 0 && x < field->xSize && y >= 0 && y < field->ySize){
        if(action == 1){
            if(field->places[x][y].state != FLAG)
    openPlace(field, x, y);
   }
  else{
         switch_flag(&field->places[x][y]);
  }
        checkGameState(field);
        if(getGameState() != PLAY)
            return 0;
        else
            return 1;
    }
    return 0;
}

variable_types: action int


makeMove

decompiled_code:
_BOOL8 __fastcall makeMove(int *a1)
{
int v2; // [rsp+4h] [rbp-14h]
int v3; // [rsp+8h] [rbp-10h]
int v4; // [rsp+Ch] [rbp-Ch]

printf(">> ");
__isoc99_scanf();
return moveWith(a1, v2, v3, v4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func20(int *a1)
{
int v2; // [rsp+4h] [rbp-14h]
int v3; // [rsp+8h] [rbp-10h]
int v4; // [rsp+Ch] [rbp-Ch]

printf(">> ");
__isoc99_scanf();
return func19(a1, v2, v3, v4);
}

original_code:
int makeMove(Minefield *field){
    int x, y, action;
    printf(">> ");
    scanf("%d %d %d", &x, &y, &action);
    return moveWith(field, x, y, action);
}

canonical_original_code:
int makeMove(struct t_Minefield *field){
    int x; int y; int action;
    printf(">> ");
    scanf("%d %d %d", &x, &y, &action);
    return moveWith(field, x, y, action);
}

variable_types: struct t_Minefield { int xSize; int ySize; unsigned int minesNumber; struct t_Place { unsigned int numberOfMinesNear; int mine; int state; } places[100][100]; } *


makeFirstMove

decompiled_code:
_BOOL8 __fastcall makeFirstMove(int *a1)
{
unsigned int v1; // eax
__int64 v2; // rbx
int v4; // [rsp+4h] [rbp-24h]
int v5; // [rsp+8h] [rbp-20h]
int v6; // [rsp+Ch] [rbp-1Ch]

printf(">> ");
__isoc99_scanf();
v1 = time(0LL);
srand(v1);
while ( a1[300 * v4 + 4 + 3 * v5] == 1 )
{
a1[300 * v4 + 4 + 3 * v5] = 0;
v2 = rand() % *a1;
a1[300 * v2 + 4 + 3 * (a1[1] & rand())] = 1;
}
placeNumbers(a1);
return moveWith(a1, v4, v5, v6);
}

original_code:
int makeFirstMove(Minefield *field){
    int x, y;
    int action;
    int i, j;
    printf(">> ");
    scanf("%d %d %d", &x, &y, &action);
    srand(time(((void *)0)));
    while(field->places[x][y].mine == MINE){
        field->places[x][y].mine = EMPTY;
        i = rand() % field->xSize;
        j = rand() & field->ySize;
        field->places[i][j].mine = MINE;
    }
    placeNumbers(field);
    return moveWith(field, x, y, action);
}

canonical_original_code:
int makeFirstMove(struct t_Minefield *field){
    int x; int y;
    int action;
    int i; int j;
    printf(">> ");
    scanf("%d %d %d", &x, &y, &action);
    srand(time(((void *)0)));
    while(field->places[x][y].mine == MINE){
        field->places[x][y].mine = EMPTY;
        i = rand() % field->xSize;
        j = rand() & field->ySize;
        field->places[i][j].mine = MINE;
    }
    placeNumbers(field);
    return moveWith(field, x, y, action);
}


play

decompiled_code:
__int64 __fastcall play(int *a1)
{
int v1; // eax
int v2; // eax
double v4; // [rsp+8h] [rbp-10h]

v4 = (double)(int)time(0LL);
setGameState(2);
drawField(a1);
makeFirstMove(a1);
while ( 1 )
{
v1 = getGameState();
if ( v1 != 2 )
break;
drawField(a1);
makeMove(a1);
}
if ( v1 == 1 )
{
puts("\n*****GAME OVER!*****");
drawField(a1);
v1 = getGameState();
}
if ( !v1 )
{
puts("\n*****YOU WIN!*****");
drawField(a1);
}
v2 = time(0LL);
printf("time: %f seconds\n", (double)v2 - v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func22(int *a1)
{
int v1; // eax
int v2; // eax
double v4; // [rsp+8h] [rbp-10h]

v4 = (double)(int)time(0LL);
func16(2);
func15(a1);
func21(a1);
while ( 1 )
{
v1 = func18();
if ( v1 != 2 )
break;
func15(a1);
func20(a1);
}
if ( v1 == 1 )
{
puts("\n*****GAME OVER!*****");
func15(a1);
v1 = func18();
}
if ( !v1 )
{
puts("\n*****YOU WIN!*****");
func15(a1);
}
v2 = time(0LL);
printf("time: %f seconds\n", (double)v2 - v4);
return 0LL;
}

original_code:
int play(Minefield *field){
    double startTime = time(((void *)0));
    double playTime;
 setGameState(PLAY);
    drawField(field);
    makeFirstMove(field);
    while( getGameState() == PLAY ){
        drawField(field);
        makeMove(field);
    };
    if( getGameState() == FAIL )
    {
        printf("\n*****GAME OVER!*****\n");
        drawField(field);
    }
    if( getGameState() == WIN )
    {
        printf("\n*****YOU WIN!*****\n");
        drawField(field);
    }
    playTime = time(((void *)0)) - startTime;
    printf("time: %f seconds\n", playTime);
    return 0;
}

canonical_original_code:
int play(struct t_Minefield *field){
    double startTime = time(((void *)0));
    double playTime;
 setGameState(PLAY);
    drawField(field);
    makeFirstMove(field);
    while( getGameState() == PLAY ){
        drawField(field);
        makeMove(field);
    };
    if( getGameState() == FAIL )
    {
        printf("\n*****GAME OVER!*****\n");
        drawField(field);
    }
    if( getGameState() == WIN )
    {
        printf("\n*****YOU WIN!*****\n");
        drawField(field);
    }
    playTime = time(((void *)0)) - startTime;
    printf("time: %f seconds\n", playTime);
    return 0;
}

variable_types: startTime double

variable_types: playTime double


main

repo: bomstrong/ash

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *i; // rax
char *v4; // rax
__int64 v5; // r15
int v6; // er14
__int64 v7; // rbp
char *v8; // rax
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
char *v14; // rsi
unsigned int v15; // eax
unsigned int v16; // ebp
const char *v17; // rdx
unsigned int v18; // eax
unsigned int v19; // er14
int stat_loc; // [rsp+Ch] [rbp-9DCh] BYREF
struct sigaction v21; // [rsp+10h] [rbp-9D8h] BYREF
char s; // [rsp+B0h] [rbp-938h] BYREF
char v23; // [rsp+B1h] [rbp-937h] BYREF
char v24; // [rsp+1AFh] [rbp-839h] BYREF
char *argva[263]; // [rsp+1B0h] [rbp-838h] BYREF

puts(" -- ASH - Awesome Shell -- ");
puts(" -- Copyright Jacob Pedersen & Andre Christensen 2013");
signal(17, sigchld_handler);
while ( 1 )
{
while ( 1 )
{
do
{
do
{
background = 0;
v21.sa_handler = (__sighandler_t)1;
sigaction(2, &v21, 0LL);
printf(">> ");
}
while ( !fgets(&s, 255, stdin) );
}
while ( !s || s == 10 );
for ( i = &v23; i != &v24; ++i )
{
if ( *i == 10 )
*i = 0;
}
v4 = strtok(&s, " ");
if ( v4 )
{
v5 = 0LL;
do
{
v6 = v5 + 1;
v7 = (int)v5;
argva[v5++] = v4;
v4 = strtok(0LL, " ");
}
while ( v4 );
}
else
{
v7 = -1LL;
v6 = 0;
}
v8 = argva[v7];
if ( *v8 != 38 || v8[1] )
{
argva[v6] = 0LL;
}
else
{
background = 1;
argva[v7] = 0LL;
}
v9 = strcmp(argva[0], "exit") != 0;
v10 = 0;
v11 = !v9;
if ( !v9 )
goto LABEL_33;
v12 = "killbg";
v13 = 7LL;
v14 = argva[0];
do
{
if ( !v13 )
break;
v10 = (unsigned __int8)*v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) != v10 )
break;
kill_bg(v12, v14, argva[0], v13);
}
v15 = fork();
v16 = v15;
if ( !v15 )
{
if ( execvp(argva[0], argva) == -1 )
perror("The following error occurred");
LABEL_33:
exit(0);
}
v17 = "background";
if ( background != 1 )
v17 = "foreground";
printf("PID %d started (%s)\n", v15, v17);
if ( background == 1 )
{
add_to_list_isra_0(v16, &stat_loc);
v18 = waitpid(v16, &stat_loc, 1);
v19 = v18;
if ( v18 == v16 )
{
printf("Background process %d exited\n", v18);
remove_from_list(v19);
}
}
else
{
fg_pid = v16;
v21.sa_handler = (__sighandler_t)sigint_handler;
sigaction(2, &v21, 0LL);
waitpid(v16, &stat_loc, 0);
printf("PID %d exited with return value: %d\n", v16, (unsigned int)stat_loc);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *i; // rax
char *v4; // rax
__int64 v5; // r15
int v6; // er14
__int64 v7; // rbp
char *v8; // rax
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
char *v14; // rsi
unsigned int v15; // eax
unsigned int v16; // ebp
const char *v17; // rdx
unsigned int v18; // eax
unsigned int v19; // er14
int stat_loc; // [rsp+Ch] [rbp-9DCh] BYREF
struct sigaction v21; // [rsp+10h] [rbp-9D8h] BYREF
char s; // [rsp+B0h] [rbp-938h] BYREF
char v23; // [rsp+B1h] [rbp-937h] BYREF
char v24; // [rsp+1AFh] [rbp-839h] BYREF
char *argva[263]; // [rsp+1B0h] [rbp-838h] BYREF

puts(" -- ASH - Awesome Shell -- ");
puts(" -- Copyright Jacob Pedersen & Andre Christensen 2013");
signal(17, sigchld_handler);
while ( 1 )
{
while ( 1 )
{
do
{
do
{
background = 0;
v21.sa_handler = (__sighandler_t)1;
sigaction(2, &v21, 0LL);
printf(">> ");
}
while ( !fgets(&s, 255, stdin) );
}
while ( !s || s == 10 );
for ( i = &v23; i != &v24; ++i )
{
if ( *i == 10 )
*i = 0;
}
v4 = strtok(&s, " ");
if ( v4 )
{
v5 = 0LL;
do
{
v6 = v5 + 1;
v7 = (int)v5;
argva[v5++] = v4;
v4 = strtok(0LL, " ");
}
while ( v4 );
}
else
{
v7 = -1LL;
v6 = 0;
}
v8 = argva[v7];
if ( *v8 != 38 || v8[1] )
{
argva[v6] = 0LL;
}
else
{
background = 1;
argva[v7] = 0LL;
}
v9 = strcmp(argva[0], "exit") != 0;
v10 = 0;
v11 = !v9;
if ( !v9 )
goto LABEL_33;
v12 = "killbg";
v13 = 7LL;
v14 = argva[0];
do
{
if ( !v13 )
break;
v10 = (unsigned __int8)*v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) != v10 )
break;
func10(v12, v14, argva[0], v13);
}
v15 = fork();
v16 = v15;
if ( !v15 )
{
if ( execvp(argva[0], argva) == -1 )
perror("The following error occurred");
LABEL_33:
exit(0);
}
v17 = "background";
if ( background != 1 )
v17 = "foreground";
printf("PID %d started (%s)\n", v15, v17);
if ( background == 1 )
{
func13(v16, &stat_loc);
v18 = waitpid(v16, &stat_loc, 1);
v19 = v18;
if ( v18 == v16 )
{
printf("Background process %d exited\n", v18);
func8(v19);
}
}
else
{
fg_pid = v16;
v21.sa_handler = (__sighandler_t)sigint_handler;
sigaction(2, &v21, 0LL);
waitpid(v16, &stat_loc, 0);
printf("PID %d exited with return value: %d\n", v16, (unsigned int)stat_loc);
}
}
}

original_code:
int main(int argc, char ** argv)
{
 char buffer[255];
 char * list[255];
 struct sigaction action;
 printf(" -- ASH - Awesome Shell -- \n");
 printf(" -- Copyright Jacob Pedersen & Andre Christensen 2013\n");
 signal(17, sigchld_handler);
 while(1)
 {
  int i, status;
  char * pch;
  background = 0;
  action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
  sigaction(2, &action, 0);
  printf(">> ");
  if (fgets(buffer, 255, stdin) != ((void *)0))
  {
   if (*buffer == '\0' || *buffer == '\n')
   {
    continue;
   }
   for (i = 0; i < 255; i++)
   {
    if (buffer[i] == '\n')
    {
     buffer[i] = '\0';
    }
   }
   i = 0;
   pch = strtok(buffer, " ");
   while (pch != ((void *)0))
   {
    list[i++] = pch;
    pch = strtok(((void *)0), " ");
   }
   if(strcmp(list[i-1], "&") == 0)
   {
    background = 1;
    list[i-1] = 0;
   }
   else
   {
    list[i] = (char *) 0;
   }
   if (strcmp(list[0], "exit") == 0)
   {
    exit(0);
   }
   else if (strcmp(list[0], "killbg") == 0)
   {
    kill_bg();
   }
   else
   {
    pid_t pid = fork();
    if (pid == 0)
    {
     if (execvp(list[0], list) == -1)
     {
      perror("The following error occurred");
     }
     exit(0);
    }
    else
    {
     printf("PID %d started (%s)\n", pid, (background != 1)
      ? "foreground" : "background");
     if(background == 1)
     {
      add_to_list(pid);
      if (waitpid(pid, &status, 1) == pid)
      {
       printf("Background process %d exited\n", pid);
       remove_from_list(pid);
      }
      else
      {
      }
     }
     else
     {
      fg_pid = pid;
      action.__sigaction_handler.sa_handler = sigint_handler;
      sigaction(2, &action, 0);
      waitpid(fg_pid, &status, 0);
      printf("PID %d exited with return value: %d\n", pid,
       status);
     }
    }
   }
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char buffer[255];
 char *list[255];
 struct sigaction action;
 printf(" -- ASH - Awesome Shell -- \n");
 printf(" -- Copyright Jacob Pedersen & Andre Christensen 2013\n");
 signal(17, sigchld_handler);
 while(1)
 {
  int i; int status;
  char *pch;
  background = 0;
  action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
  sigaction(2, &action, 0);
  printf(">> ");
  if (fgets(buffer, 255, stdin) != ((void *)0))
  {
   if (*buffer == '\0' || *buffer == '\n')
   {
    continue;
   }
   for (i = 0; i < 255; i++)
   {
    if (buffer[i] == '\n')
    {
     buffer[i] = '\0';
    }
   }
   i = 0;
   pch = strtok(buffer, " ");
   while (pch != ((void *)0))
   {
    list[i++] = pch;
    pch = strtok(((void *)0), " ");
   }
   if(strcmp(list[i-1], "&") == 0)
   {
    background = 1;
    list[i-1] = 0;
   }
   else
   {
    list[i] = (char *) 0;
   }
   if (strcmp(list[0], "exit") == 0)
   {
    exit(0);
   }
   else if (strcmp(list[0], "killbg") == 0)
   {
    kill_bg();
   }
   else
   {
    int pid = fork();
    if (pid == 0)
    {
     if (execvp(list[0], list) == -1)
     {
      perror("The following error occurred");
     }
     exit(0);
    }
    else
    {
     printf("PID %d started (%s)\n", pid, (background != 1)
      ? "foreground" : "background");
     if(background == 1)
     {
      add_to_list(pid);
      if (waitpid(pid, &status, 1) == pid)
      {
       printf("Background process %d exited\n", pid);
       remove_from_list(pid);
      }
      else
      {
      }
     }
     else
     {
      fg_pid = pid;
      action.__sigaction_handler.sa_handler = sigint_handler;
      sigaction(2, &action, 0);
      waitpid(fg_pid, &status, 0);
      printf("PID %d exited with return value: %d\n", pid,
       status);
     }
    }
   }
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buffer
char [255]

variable_types:
list
char *[255]

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

variable_types: i int

variable_types: status int

variable_types:
pch
char *

variable_types: pid int

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

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


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

for ( result = 0LL; result != 20; ++result )
{
if ( !pid_list[result] )
return (unsigned int)result;
}
return 0xFFFFFFFFLL;
}

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

for ( result = 0LL; result != 20; ++result )
{
if ( !pid_list[result] )
return (unsigned int)result;
}
return 0xFFFFFFFFLL;
}

original_code:
static int get_next_avail_index()
{
 int i;
 for (i = 0; i < 20; i++)
 {
  if (pid_list[i] == 0)
  {
   return i;
  }
 }
 return -1;
}


decompiled_code:
int *__fastcall remove_from_list(int a1)
{
int *result; // rax

result = pid_list;
do
{
if ( *result == a1 )
*result = 0;
++result;
}
while ( result != &fg_pid );
return result;
}

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

result = pid_list;
do
{
if ( *result == a1 )
*result = 0;
++result;
}
while ( result != &fg_pid );
return result;
}

original_code:
static void remove_from_list(pid_t pid)
{
 int i;
 for (i = 0; i < 20; i++)
 {
  if (pid_list[i] == pid)
  {
   pid_list[i] = 0;
  }
 }
}

canonical_original_code:
static void remove_from_list(int pid)
{
 int i;
 for (i = 0; i < 20; i++)
 {
  if (pid_list[i] == pid)
  {
   pid_list[i] = 0;
  }
 }
}


decompiled_code:
int sigint_handler()
{
return kill(fg_pid, 9);
}

canonical_decompiled_code:
int func9()
{
return kill(fg_pid, 9);
}

original_code:
static void sigint_handler(int sig)
{
 kill(fg_pid, 9);
}

variable_types: sig int


decompiled_code:
void kill_bg()
{
int *v0; // rbx
unsigned int v1; // ebp
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = pid_list;
do
{
while ( 1 )
{
v1 = *v0;
if ( *v0 > 0 )
break;
if ( ++v0 == &fg_pid )
return;
}
if ( kill(v1, 9) < 0 )
{
printf("Failed killing process %d\n", v1);
}
else
{
waitpid(v1, stat_loc, 0);
printf("Killed process %d - exited with %d\n", (unsigned int)*v0, (unsigned int)stat_loc[0]);
}
*v0++ = 0;
}
while ( v0 != &fg_pid );
}

canonical_decompiled_code:
void func10()
{
int *v0; // rbx
unsigned int v1; // ebp
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = pid_list;
do
{
while ( 1 )
{
v1 = *v0;
if ( *v0 > 0 )
break;
if ( ++v0 == &fg_pid )
return;
}
if ( kill(v1, 9) < 0 )
{
printf("Failed killing process %d\n", v1);
}
else
{
waitpid(v1, stat_loc, 0);
printf("Killed process %d - exited with %d\n", (unsigned int)*v0, (unsigned int)stat_loc[0]);
}
*v0++ = 0;
}
while ( v0 != &fg_pid );
}

original_code:
static void kill_bg()
{
 int i, r, status;
 for (i = 0; i < 20; i++)
 {
  if (pid_list[i] > 0)
  {
   r = kill(pid_list[i], 9);
   if (r < 0)
   {
    printf("Failed killing process %d\n", pid_list[i]);
   }
   else
   {
    waitpid(pid_list[i], &status, 0);
    printf("Killed process %d - exited with %d\n", pid_list[i],
     status);
   }
   pid_list[i] = 0;
  }
 }
}

canonical_original_code:
static void kill_bg()
{
 int i; int r; int status;
 for (i = 0; i < 20; i++)
 {
  if (pid_list[i] > 0)
  {
   r = kill(pid_list[i], 9);
   if (r < 0)
   {
    printf("Failed killing process %d\n", pid_list[i]);
   }
   else
   {
    waitpid(pid_list[i], &status, 0);
    printf("Killed process %d - exited with %d\n", pid_list[i],
     status);
   }
   pid_list[i] = 0;
  }
 }
}

variable_types: r int


decompiled_code:
void check_bg_status()
{
__pid_t *v0; // rbx
unsigned int v1; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = pid_list;
do
{
while ( 1 )
{
if ( *v0 > 0 )
{
v1 = waitpid(*v0, stat_loc, 1);
if ( v1 == *v0 )
break;
}
if ( ++v0 == &fg_pid )
return;
}
++v0;
printf("\nBackground process %d exited with status %d\n>> ", v1, (unsigned int)stat_loc[0]);
fflush(stdout);
remove_from_list(*(v0 - 1));
}
while ( v0 != &fg_pid );
}

canonical_decompiled_code:
void func11()
{
__pid_t *v0; // rbx
unsigned int v1; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = pid_list;
do
{
while ( 1 )
{
if ( *v0 > 0 )
{
v1 = waitpid(*v0, stat_loc, 1);
if ( v1 == *v0 )
break;
}
if ( ++v0 == &fg_pid )
return;
}
++v0;
printf("\nBackground process %d exited with status %d\n>> ", v1, (unsigned int)stat_loc[0]);
fflush(stdout);
func8(*(v0 - 1));
}
while ( v0 != &fg_pid );
}

original_code:
static void check_bg_status()
{
 int i;
 int status;
 for (i = 0; i < 20; i++)
 {
  if (pid_list[i] > 0)
  {
   if (waitpid(pid_list[i], &status, 1) == pid_list[i])
   {
    printf("\nBackground process %d exited with status %d\n>> ",
     pid_list[i], status);
    fflush(stdout);
    remove_from_list(pid_list[i]);
   }
  }
 }
}


decompiled_code:
void sigchld_handler()
{
check_bg_status();
}

canonical_decompiled_code:
void func12()
{
func11();
}

original_code:
static void sigchld_handler(int sig)
{
 check_bg_status();
}


usage

repo: bongo-project/bongo

decompiled_code:
void __noreturn usage()
{
fwrite(
"Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix "
"<url>] [--olson-dir <directory>]\n",
1uLL,
0x95uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite(
"Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix "
"<url>] [--olson-dir <directory>]\n",
1uLL,
0x95uLL,
stderr);
exit(1);
}

original_code:
static void
usage (void)
{
  fprintf (stderr, "Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix <url>] [--olson-dir <directory>]\n");
  exit (1);
}

canonical_original_code:
static void usage()
{
  fprintf (stderr, "Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix <url>] [--olson-dir <directory>]\n");
  exit (1);
}


decompiled_code:
__int64 __fastcall free_link_data(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v4; // rbx

((void (*)(void))g_free)();
if ( a3 )
{
v4 = a3;
do
{
g_free(*v4);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
return g_list_free(a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v4; // rbx

((void (*)(void))g_free)();
if ( a3 )
{
v4 = a3;
do
{
g_free(*v4);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
return g_list_free(a3);
}

original_code:
static void
free_link_data (gpointer key,
     gpointer value,
     gpointer data)
{
  GList *link = data;
  g_free (key);
  while (link) {
    g_free (link->data);
    link = link->next;
  }
  g_list_free (data);
}

canonical_original_code:
static void free_link_data(void *key, void *value, void *data)
{
  struct _GList *link = data;
  g_free (key);
  while (link) {
    g_free (link->data);
    link = link->next;
  }
  g_list_free (data);
}

variable_types:
key
void *

variable_types:
value
void *

variable_types:
data
void *

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *


decompiled_code:
__int64 __fastcall free_rule_array(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

if ( *(_DWORD *)(a2 + 8) )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = *(_QWORD *)a2 + (v2 << 6);
if ( !*(_DWORD *)(v3 + 56) )
break;
if ( *(_DWORD *)(a2 + 8) <= (unsigned int)++v2 )
goto LABEL_6;
}
++v2;
g_free(*(_QWORD *)(v3 + 8));
g_free(*(_QWORD *)(v3 + 48));
}
while ( *(_DWORD *)(a2 + 8) > (unsigned int)v2 );
}
LABEL_6:
g_array_free(a2, 1LL);
return g_free(a1);
}

original_code:
static void
free_rule_array (gpointer key,
     gpointer value,
     gpointer data)
{
  char *name = key;
  GArray *rule_array = value;
  RuleData *rule;
  int i;
  for (i = 0; i < rule_array->len; i++) {
    rule = &(((RuleData*) (void *) (rule_array)->data) [(i)]);
    if (!rule->is_shallow_copy) {
      g_free (rule->type);
      g_free (rule->letter_s);
    }
  }
  g_array_free (rule_array, (!(0)));
  g_free (name);
}

canonical_original_code:
static void free_rule_array(void *key, void *value, void *data)
{
  char *name = key;
  struct _GArray *rule_array = value;
  struct _RuleData *rule;
  int i;
  for (i = 0; i < rule_array->len; i++) {
    rule = &(((struct _RuleData *) (void *) (rule_array)->data) [(i)]);
    if (!rule->is_shallow_copy) {
      g_free (rule->type);
      g_free (rule->letter_s);
    }
  }
  g_array_free (rule_array, (!(0)));
  g_free (name);
}

variable_types:
name
char *

variable_types: struct _GArray { char *data; unsigned int len; } *

variable_types: struct _RuleData { int from_year; int to_year; char *type; int in_month; enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 } on_day_code; int on_day_number; int on_day_weekday; int at_time_seconds; enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 } at_time_code; int save_seconds; char *letter_s; int is_shallow_copy; } *

user_defined_types: struct _RuleData { int from_year; int to_year; char *type; int in_month; enum DayCode on_day_code; int on_day_number; int on_day_weekday; int at_time_seconds; enum TimeCode at_time_code; int save_seconds; char *letter_s; int is_shallow_copy; }


original_code:
static void
free_zone_data (GArray *zone_data)
{
  ZoneData *zone;
  ZoneLineData *zone_line;
  int i, j;
  for (i = 0; i < zone_data->len; i++) {
    zone = &(((ZoneData*) (void *) (zone_data)->data) [(i)]);
    g_free (zone->zone_name);
    for (j = 0; j < zone->zone_line_data->len; j++) {
      zone_line = &(((ZoneLineData*) (void *) (zone->zone_line_data)->data) [(j)]);
      g_free (zone_line->rules);
      g_free (zone_line->format);
    }
    g_array_free (zone->zone_line_data, (!(0)));
  }
  g_array_free (zone_data, (!(0)));
}

canonical_original_code:
static void free_zone_data(struct _GArray *zone_data)
{
  struct _ZoneData *zone;
  struct _ZoneLineData *zone_line;
  int i; int j;
  for (i = 0; i < zone_data->len; i++) {
    zone = &(((struct _ZoneData *) (void *) (zone_data)->data) [(i)]);
    g_free (zone->zone_name);
    for (j = 0; j < zone->zone_line_data->len; j++) {
      zone_line = &(((struct _ZoneLineData *) (void *) (zone->zone_line_data)->data) [(j)]);
      g_free (zone_line->rules);
      g_free (zone_line->format);
    }
    g_array_free (zone->zone_line_data, (!(0)));
  }
  g_array_free (zone_data, (!(0)));
}

variable_types: struct _ZoneData { char *zone_name; struct _GArray { char *data; unsigned int len; } *zone_line_data; } *

variable_types: struct _ZoneLineData { int stdoff_seconds; char *rules; int save_seconds; char *format; int until_set; int until_year; int until_month; enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 } until_day_code; int until_day_number; int until_day_weekday; int until_time_seconds; enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 } until_time_code; } *

variable_types: j int

user_defined_types: struct _ZoneData { char *zone_name; struct _GArray *zone_line_data; }

user_defined_types: struct _ZoneLineData { int stdoff_seconds; char *rules; int save_seconds; char *format; int until_set; int until_year; int until_month; enum DayCode until_day_code; int until_day_number; int until_day_weekday; int until_time_seconds; enum TimeCode until_time_code; }


decompiled_code:
int __fastcall dump_compare_strings(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int
dump_compare_strings (const void *arg1,
     const void *arg2)
{
  char **a, **b;
  a = (char**) arg1;
  b = (char**) arg2;
  return strcmp (*a, *b);
}

canonical_original_code:
static int dump_compare_strings(void *arg1, void *arg2)
{
  char **a; char **b;
  a = (char **) arg1;
  b = (char **) arg2;
  return strcmp (*a, *b);
}

variable_types:
a
char **

variable_types:
b
char **


decompiled_code:
__int64 __fastcall dump_add_rule(__int64 a1, __int64 a2, __int64 a3)
{
return g_ptr_array_add(a3, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return g_ptr_array_add(a3, a1);
}

original_code:
static void
dump_add_rule (char *name,
     GArray *rule_array,
     GPtrArray *name_array)
{
  g_ptr_array_add (name_array, name);
}

canonical_original_code:
static void dump_add_rule(char *name, struct _GArray *rule_array, struct _GPtrArray *name_array)
{
  g_ptr_array_add (name_array, name);
}

variable_types: struct _GPtrArray { void **pdata; unsigned int len; } *

user_defined_types: struct _GArray { char *data; unsigned int len; }


decompiled_code:
const char *__fastcall dump_time(unsigned int a1, int a2, int a3)
{
const char *v3; // r9
const char *v4; // r10
unsigned __int64 v5; // rcx
unsigned __int64 v6; // r8
unsigned int v7; // eax

v3 = (const char *)&unk_D68;
if ( a2 != 1 )
{
v3 = (const char *)&unk_D6C;
if ( a2 == 2 )
v3 = (const char *)&unk_D6A;
}
v4 = (const char *)&unk_D6C;
if ( (a1 & 0x80000000) != 0 )
{
a1 = -a1;
v4 = "-";
}
sign_4 = (__int64)v4;
v5 = a1 / 0xE10uLL;
v6 = a1 % 0xE10 / 0x3CuLL;
v7 = a1 % 0x3C;
if ( a3 && !((unsigned int)v6 | v7 | (unsigned int)v5) )
return "0";
if ( v7 )
sprintf(buffer_3, "%s%i:%02i:%02i%s", v4, v5, v6, v7, v3);
else
sprintf(buffer_3, "%s%i:%02i%s", v4, v5, v6, v3);
return buffer_3;
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned int a1, int a2, int a3)
{
const char *v3; // r9
const char *v4; // r10
unsigned __int64 v5; // rcx
unsigned __int64 v6; // r8
unsigned int v7; // eax

v3 = (const char *)&unk_D68;
if ( a2 != 1 )
{
v3 = (const char *)&unk_D6C;
if ( a2 == 2 )
v3 = (const char *)&unk_D6A;
}
v4 = (const char *)&unk_D6C;
if ( (a1 & 0x80000000) != 0 )
{
a1 = -a1;
v4 = "-";
}
sign_4 = (__int64)v4;
v5 = a1 / 0xE10uLL;
v6 = a1 % 0xE10 / 0x3CuLL;
v7 = a1 % 0x3C;
if ( a3 && !((unsigned int)v6 | v7 | (unsigned int)v5) )
return "0";
if ( v7 )
sprintf(buffer_3, "%s%i:%02i:%02i%s", v4, v5, v6, v7, v3);
else
sprintf(buffer_3, "%s%i:%02i%s", v4, v5, v6, v3);
return buffer_3;
}

original_code:
char*
dump_time (int seconds,
     TimeCode time_code,
     gboolean use_zero)
{
  static char buffer[256], *sign;
  int hours, minutes;
  char *code;
  if (time_code == TIME_STANDARD)
    code = "s";
  else if (time_code == TIME_UNIVERSAL)
    code = "u";
  else
    code = "";
  if (seconds < 0) {
    seconds = -seconds;
    sign = "-";
  } else {
    sign = "";
  }
  hours = seconds / 3600;
  minutes = (seconds % 3600) / 60;
  seconds = seconds % 60;
  if (use_zero && hours == 0 && minutes == 0 && seconds == 0)
    return "0";
  else if (seconds == 0)
    sprintf (buffer, "%s%i:%02i%s", sign, hours, minutes, code);
  else
    sprintf (buffer, "%s%i:%02i:%02i%s", sign, hours, minutes, seconds, code);
  return buffer;
}

canonical_original_code:
char *dump_time(int seconds, enum TimeCode time_code, int use_zero)
{
  static char buffer[256]; static char *sign;
  int hours; int minutes;
  char *code;
  if (time_code == TIME_STANDARD)
    code = "s";
  else if (time_code == TIME_UNIVERSAL)
    code = "u";
  else
    code = "";
  if (seconds < 0) {
    seconds = -seconds;
    sign = "-";
  } else {
    sign = "";
  }
  hours = seconds / 3600;
  minutes = (seconds % 3600) / 60;
  seconds = seconds % 60;
  if (use_zero && hours == 0 && minutes == 0 && seconds == 0)
    return "0";
  else if (seconds == 0)
    sprintf (buffer, "%s%i:%02i%s", sign, hours, minutes, code);
  else
    sprintf (buffer, "%s%i:%02i:%02i%s", sign, hours, minutes, seconds, code);
  return buffer;
}

variable_types: seconds int

variable_types: enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 }

variable_types:
buffer
char [256]

variable_types:
sign
char *

variable_types: hours int

variable_types: minutes int

variable_types:
code
char *

return_type: char *


decompiled_code:
char *__fastcall dump_day_coded(unsigned int a1, unsigned int a2, int a3)
{
char *result; // rax

if ( a1 == 2 )
{
sprintf(buffer_2, "%s<=%i", weekdays_1[a3], a2);
result = buffer_2;
}
else if ( a1 > 2 )
{
if ( a1 != 3 )
{
fprintf(stderr, "Invalid day code: %i\n", a1);
exit(1);
}
sprintf(buffer_2, "last%s", weekdays_1[a3]);
result = buffer_2;
}
else
{
if ( a1 )
sprintf(buffer_2, "%s>=%i", weekdays_1[a3], a2);
else
sprintf(buffer_2, "%i", a2);
result = buffer_2;
}
return result;
}

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

if ( a1 == 2 )
{
sprintf(buffer_2, "%s<=%i", weekdays_1[a3], a2);
result = buffer_2;
}
else if ( a1 > 2 )
{
if ( a1 != 3 )
{
fprintf(stderr, "Invalid day code: %i\n", a1);
exit(1);
}
sprintf(buffer_2, "last%s", weekdays_1[a3]);
result = buffer_2;
}
else
{
if ( a1 )
sprintf(buffer_2, "%s>=%i", weekdays_1[a3], a2);
else
sprintf(buffer_2, "%i", a2);
result = buffer_2;
}
return result;
}

original_code:
char*
dump_day_coded (DayCode day_code,
     int day_number,
     int day_weekday)
{
  static char buffer[256];
  static char *weekdays[] = { "Sun", "Mon", "Tue", "Wed",
         "Thu", "Fri", "Sat" };
  switch (day_code) {
  case DAY_SIMPLE:
    sprintf (buffer, "%i", day_number);
    break;
  case DAY_WEEKDAY_ON_OR_AFTER:
    sprintf (buffer, "%s>=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_WEEKDAY_ON_OR_BEFORE:
    sprintf (buffer, "%s<=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_LAST_WEEKDAY:
    sprintf (buffer, "last%s", weekdays[day_weekday]);
    break;
  default:
    fprintf (stderr, "Invalid day code: %i\n", day_code);
    exit (1);
  }
  return buffer;
}

canonical_original_code:
char *dump_day_coded(enum DayCode day_code, int day_number, int day_weekday)
{
  static char buffer[256];
  static char *weekdays[] = { "Sun", "Mon", "Tue", "Wed",
         "Thu", "Fri", "Sat" };
  switch (day_code) {
  case DAY_SIMPLE:
    sprintf (buffer, "%i", day_number);
    break;
  case DAY_WEEKDAY_ON_OR_AFTER:
    sprintf (buffer, "%s>=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_WEEKDAY_ON_OR_BEFORE:
    sprintf (buffer, "%s<=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_LAST_WEEKDAY:
    sprintf (buffer, "last%s", weekdays[day_weekday]);
    break;
  default:
    fprintf (stderr, "Invalid day code: %i\n", day_code);
    exit (1);
  }
  return buffer;
}

variable_types: enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 }

variable_types:
weekdays
char *[]


decompiled_code:
const char *__fastcall dump_year(unsigned int a1)
{
const char *result; // rax

result = "min";
if ( a1 != 0x80000000 )
{
result = "max";
if ( a1 != 0x7FFFFFFF )
{
sprintf(buffer_0, "%i", a1);
result = buffer_0;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned int a1)
{
const char *result; // rax

result = "min";
if ( a1 != 0x80000000 )
{
result = "max";
if ( a1 != 0x7FFFFFFF )
{
sprintf(buffer_0, "%i", a1);
result = buffer_0;
}
}
return result;
}

original_code:
char*
dump_year (int year)
{
  static char buffer[256];
  if (year == (-0x7fffffff - 1))
    return "min";
  if (year == 0x7fffffff)
    return "max";
  sprintf (buffer, "%i", year);
  return buffer;
}

canonical_original_code:
char *dump_year(int year)
{
  static char buffer[256];
  if (year == (-0x7fffffff - 1))
    return "min";
  if (year == 0x7fffffff)
    return "max";
  sprintf (buffer, "%i", year);
  return buffer;
}

variable_types: year int


main

repo: boopathi/cps

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v5; // eax
const char *v6; // r13
size_t v7; // r12
char *v8; // rdx
size_t i; // rax
char v10; // al
int v11; // esi
_BYTE *v12; // rcx
char v13; // al
char *v14; // rcx
_BYTE *v15; // rdx
int v16; // eax
char *v17; // rdi
int *v19; // rax

dword_484120 = 0;
args = 0LL;
dword_484148 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "akvs:");
if ( v5 == -1 )
break;
if ( v5 == 115 )
goto LABEL_9;
if ( v5 > 115 )
{
if ( v5 != 118 )
goto LABEL_30;
dword_484148 = 1;
LABEL_9:
v6 = argv[optind - 1];
v7 = strlen(v6);
v8 = (char *)malloc(v7 + 1);
for ( i = 0LL; v7 > i; ++i )
v8[i] = v6[i];
v10 = *v8;
v11 = dword_484120;
if ( *v8 && v10 != 47 )
{
v12 = (_BYTE *)(((__int64)dword_484120 << 9) + 4210976);
do
{
++v8;
*v12++ = v10;
v10 = *v8;
}
while ( *v8 != 47 && v10 );
}
v13 = v8[1];
v14 = v8 + 1;
if ( v13 != 47 && v13 )
{
v15 = (_BYTE *)(((__int64)v11 << 9) + 4211232);
do
{
++v14;
*v15++ = v13;
v13 = *v14;
}
while ( *v14 != 47 && v13 );
}
*v14 = 0;
dword_484120 = v11 + 1;
}
else if ( v5 == 97 )
{
LODWORD(args) = 1;
}
else
{
if ( v5 != 107 )
{
LABEL_30:
print_help();
abort();
}
HIDWORD(args) = 1;
}
}
v16 = optind;
if ( optind >= argc )
print_error(1, (char)"Source Directory/filename not specified");
v17 = (char *)argv[optind++];
qword_484150 = (__int64)v17;
if ( v16 + 1 >= argc )
print_error(2, (char)"Target linkname not specified");
optind = v16 + 2;
filename = (char *)argv[v16 + 1];
if ( (unsigned int)stat(v17, &stat_buf) )
{
v19 = __errno_location();
print_error(*v19, (char)"No such file/directory specified as SOURCE");
}
if ( !(unsigned int)stat(filename, &unk_4841F0) )
print_error(17, (char)"TARGET already exists.");
make_tree(qword_484150, filename);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v5; // eax
const char *v6; // r13
size_t v7; // r12
char *v8; // rdx
size_t i; // rax
char v10; // al
int v11; // esi
_BYTE *v12; // rcx
char v13; // al
char *v14; // rcx
_BYTE *v15; // rdx
int v16; // eax
char *v17; // rdi
int *v19; // rax

dword_484120 = 0;
args = 0LL;
dword_484148 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "akvs:");
if ( v5 == -1 )
break;
if ( v5 == 115 )
goto LABEL_9;
if ( v5 > 115 )
{
if ( v5 != 118 )
goto LABEL_30;
dword_484148 = 1;
LABEL_9:
v6 = argv[optind - 1];
v7 = strlen(v6);
v8 = (char *)malloc(v7 + 1);
for ( i = 0LL; v7 > i; ++i )
v8[i] = v6[i];
v10 = *v8;
v11 = dword_484120;
if ( *v8 && v10 != 47 )
{
v12 = (_BYTE *)(((__int64)dword_484120 << 9) + 4210976);
do
{
++v8;
*v12++ = v10;
v10 = *v8;
}
while ( *v8 != 47 && v10 );
}
v13 = v8[1];
v14 = v8 + 1;
if ( v13 != 47 && v13 )
{
v15 = (_BYTE *)(((__int64)v11 << 9) + 4211232);
do
{
++v14;
*v15++ = v13;
v13 = *v14;
}
while ( *v14 != 47 && v13 );
}
*v14 = 0;
dword_484120 = v11 + 1;
}
else if ( v5 == 97 )
{
LODWORD(args) = 1;
}
else
{
if ( v5 != 107 )
{
LABEL_30:
func7();
abort();
}
HIDWORD(args) = 1;
}
}
v16 = optind;
if ( optind >= argc )
func8(1, (char)"Source Directory/filename not specified");
v17 = (char *)argv[optind++];
qword_484150 = (__int64)v17;
if ( v16 + 1 >= argc )
func8(2, (char)"Target linkname not specified");
optind = v16 + 2;
filename = (char *)argv[v16 + 1];
if ( (unsigned int)func14(v17, &stat_buf) )
{
v19 = __errno_location();
func8(*v19, (char)"No such file/directory specified as SOURCE");
}
if ( !(unsigned int)func14(filename, &unk_4841F0) )
func8(17, (char)"TARGET already exists.");
func11(qword_484150, filename);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int c,i;
  char *s, *where, *tmp;
  rep.l = 0;
  args.absolute = 0;
  args.skip = 0;
  args.verbose = 0;
  while( (c = getopt(argc, argv, "akvs:")) != -1) {
    switch(c) {
    case 'a':
      args.absolute = 1;
      break;
    case 'k':
      args.skip = 1;
      break;
    case 'v':
      args.verbose = 1;
    case 's':
      optind--;
      tmp = argv[optind++];
      s = malloc(strlen(tmp) + 1);
      for(i=0;i<strlen(tmp);i++) s[i] = tmp[i];
      i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][0][i++] = *s++;
      s++; i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][1][i++] = *s++;
      rep.l++;
      *s = 0;
      break;
    default:
      print_help();
      abort();
    }
  }
  if(optind < argc) args.source = argv[optind++];
  else print_error(1,"Source Directory/filename not specified");
  if(optind < argc) args.target = argv[optind++];
  else print_error(2,"Target linkname not specified");
  if(stat(args.source, &(args.sstat)) != 0) print_error((*__errno_location ()), "No such file/directory specified as SOURCE");
  if(stat(args.target, &(args.tstat)) != 0)
    make_tree(args.source, args.target);
  else print_error(17, "TARGET already exists.");
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int c; int i;
  char *s; char *where; char *tmp;
  rep.l = 0;
  args.absolute = 0;
  args.skip = 0;
  args.verbose = 0;
  while( (c = getopt(argc, argv, "akvs:")) != -1) {
    switch(c) {
    case 'a':
      args.absolute = 1;
      break;
    case 'k':
      args.skip = 1;
      break;
    case 'v':
      args.verbose = 1;
    case 's':
      optind--;
      tmp = argv[optind++];
      s = malloc(strlen(tmp) + 1);
      for(i=0;i<strlen(tmp);i++) s[i] = tmp[i];
      i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][0][i++] = *s++;
      s++; i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][1][i++] = *s++;
      rep.l++;
      *s = 0;
      break;
    default:
      print_help();
      abort();
    }
  }
  if(optind < argc) args.source = argv[optind++];
  else print_error(1,"Source Directory/filename not specified");
  if(optind < argc) args.target = argv[optind++];
  else print_error(2,"Target linkname not specified");
  if(stat(args.source, &(args.sstat)) != 0) print_error((*__errno_location ()), "No such file/directory specified as SOURCE");
  if(stat(args.target, &(args.tstat)) != 0)
    make_tree(args.source, args.target);
  else print_error(17, "TARGET already exists.");
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: i int

variable_types:
s
char *

variable_types:
where
char *

variable_types:
tmp
char *