decompiled_code:
__int64 gps_start()
{
unsigned int v0; // ebx
int *v2; // rax
const char *v3; // rax

if ( (unsigned int)gps_open("shared memory", 0LL, &gpsdata) )
{
v2 = _errno_location();
v3 = (const char *)gps_errstr((unsigned int)*v2);
printf("couldn't connect to gpsd: %s\n", v3);
v0 = -1;
}
else
{
v0 = 0;
if ( (unsigned int)gps_stream(&gpsdata, 1LL, 0LL) == -1 )
perror("gps_stream()");
gps_available = 1;
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx
int *v2; // rax
const char *v3; // rax

if ( (unsigned int)gps_open("shared memory", 0LL, &gpsdata) )
{
v2 = _errno_location();
v3 = (const char *)gps_errstr((unsigned int)*v2);
printf("couldn't connect to gpsd: %s\n", v3);
v0 = -1;
}
else
{
v0 = 0;
if ( (unsigned int)gps_stream(&gpsdata, 1LL, 0LL) == -1 )
perror("gps_stream()");
gps_available = 1;
}
return v0;
}

original_code:
int
gps_start(void) {
    if (gps_open("shared memory", ((void *)0), &gpsdata) != 0) {
        printf("couldn't connect to gpsd: %s\n", gps_errstr((*__errno_location ())));
        return -1;
    }
    if (gps_stream((struct gps_data_t *) &gpsdata, 0x000001u, ((void *)0)) == -1)
        perror("gps_stream()");
    gps_available = 1;
    return 0;
}

canonical_original_code:
int gps_start() {
    if (gps_open("shared memory", ((void *)0), &gpsdata) != 0) {
        printf("couldn't connect to gpsd: %s\n", gps_errstr((*__errno_location ())));
        return -1;
    }
    if (gps_stream((struct gps_data_t *) &gpsdata, 0x000001u, ((void *)0)) == -1)
        perror("gps_stream()");
    gps_available = 1;
    return 0;
}

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

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

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

user_defined_types: struct satellite_t { double ss; _Bool used; short PRN; short elevation; short azimuth; }

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

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

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

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

user_defined_types: struct oscillator_t { _Bool running; _Bool reference; _Bool disciplined; int delta; }

user_defined_types: struct version_t { char release[64]; char rev[64]; int proto_major; char remote[128]; }

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

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

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

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

user_defined_types: struct rtcm3_1005_t { unsigned int station_id; int system; _Bool reference_station; _Bool single_receiver; double ecef_x; }

user_defined_types: struct rtcm3_1006_t { unsigned int station_id; int system; _Bool reference_station; _Bool single_receiver; double ecef_x; double height; }

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

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

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

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

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

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

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

user_defined_types: struct rtcm3_1033_t { unsigned int station_id; char descriptor[-1]; unsigned int setup_id; char serial[-1]; char receiver[-1]; char firmware[-1]; }

user_defined_types: struct rtcm3_rtk_hdr { unsigned int station_id; long tow; _Bool sync; unsigned short satcount; _Bool smoothing; unsigned int interval; }

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

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

user_defined_types: struct gps_rangesat_t { unsigned int ident; unsigned int udre; unsigned int iod; double prc; double rrc; }

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

user_defined_types: struct station_t { double latitude; unsigned int range; double frequency; unsigned int health; unsigned int station_id; unsigned int bitrate; }

user_defined_types: struct glonass_rangesat_t { unsigned int ident; unsigned int udre; unsigned int tod; _Bool change; double prc; double rrc; }


decompiled_code:
__int64 gps_reconnect()
{
fwrite("reconnecting to gpsd...\n", 1uLL, 0x18uLL, stderr);
gps_stop();
return gps_start();
}

canonical_decompiled_code:
__int64 func2()
{
fwrite("reconnecting to gpsd...\n", 1uLL, 0x18uLL, stderr);
func0();
return func1();
}

original_code:
void
gps_reconnect(void) {
    fprintf(stderr, "reconnecting to gpsd...\n");
    gps_stop();
    gps_start();
}

canonical_original_code:
void gps_reconnect() {
    fprintf(stderr, "reconnecting to gpsd...\n");
    gps_stop();
    gps_start();
}

return_type: void


decompiled_code:
__int64 __fastcall get_gps_data(__int64 a1)
{
unsigned int v1; // ebp

if ( !gps_available )
return (unsigned int)-1;
if ( (unsigned __int8)gps_waiting(&gpsdata, 2000000LL) )
{
*_errno_location() = 0;
v1 = gps_read(&gpsdata);
if ( v1 == -1 )
{
perror("gps_read()");
gps_reconnect();
}
else
{
*(__m128i *)a1 = _mm_loadu_si128((const __m128i *)&xmmword_238);
*(__m128i *)(a1 + 16) = _mm_loadu_si128((const __m128i *)&xmmword_248);
*(__m128i *)(a1 + 32) = _mm_loadu_si128((const __m128i *)&xmmword_258);
*(__m128i *)(a1 + 48) = _mm_loadu_si128((const __m128i *)&xmmword_268);
*(__m128i *)(a1 + 64) = _mm_loadu_si128((const __m128i *)&xmmword_278);
*(__m128i *)(a1 + 80) = _mm_loadu_si128((const __m128i *)&xmmword_288);
*(__m128i *)(a1 + 96) = _mm_loadu_si128((const __m128i *)&xmmword_298);
*(_QWORD *)(a1 + 112) = qword_2A8;
*(double *)(a1 + 88) = 3.6 * *(double *)(a1 + 88);
*(double *)(a1 + 96) = 3.6 * *(double *)(a1 + 96);
v1 = 0;
}
}
else
{
fwrite("no gps data available (timeout)\n", 1uLL, 0x20uLL, stderr);
gps_reconnect();
v1 = -1;
}
return v1;
}

original_code:
int
get_gps_data(struct gps_fix_t *g) {
    if (!gps_available)
        return -1;
    if (!gps_waiting(&gpsdata, 2000000)) {
        fprintf(stderr, "no gps data available (timeout)\n");
        gps_reconnect();
        return -1;
    }
    (*__errno_location ()) = 0;
    if (gps_read(&gpsdata) == -1) {
        perror("gps_read()");
        gps_reconnect();
        return -1;
    }
    memcpy(g, &gpsdata.fix, sizeof(struct gps_fix_t));
    g->speed = g->speed * 3.6;
    g->eps = g->eps * 3.6;
    return 0;
}

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

return_type: int


decompiled_code:
__int64 __fastcall tcp_listen(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("socket() failed");
}
else
{
setsockopt(v1, 1, 2, optval, 4u);
*(_DWORD *)&v4.sa_data[2] = 0;
v4.sa_family = 2;
*(_WORD *)v4.sa_data = _bswap_16(a1);
while ( bind(v2, &v4, 0x10u) == -1 )
{
perror("bind() failed");
usleep(0xC350u);
puts("retrying...");
}
if ( listen(v2, 3) == -1 )
{
perror("listen() failed");
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("socket() failed");
}
else
{
setsockopt(v1, 1, 2, optval, 4u);
*(_DWORD *)&v4.sa_data[2] = 0;
v4.sa_family = 2;
*(_WORD *)v4.sa_data = func0(a1);
while ( bind(v2, &v4, 0x10u) == -1 )
{
perror("bind() failed");
usleep(0xC350u);
puts("retrying...");
}
if ( listen(v2, 3) == -1 )
{
perror("listen() failed");
v2 = -1;
}
}
return v2;
}

original_code:
int
tcp_listen(int port) {
    int s;
    int on = 1;
    struct sockaddr_in servaddr;
    if ((s = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("socket() failed");
        return -1;
    }
    setsockopt(s, 1, 2, &on, sizeof(on));
    servaddr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    servaddr.sin_family = 2;
    servaddr.sin_port = htons(port);
    while (bind(s, (struct sockaddr *) &servaddr, sizeof(servaddr)) == -1) {
        perror("bind() failed");
        usleep(50000);
        printf("retrying...\n");
    }
    if (listen(s, 3) == -1) {
        perror("listen() failed");
        return -1;
    }
    return s;
}

canonical_original_code:
int tcp_listen(int port) {
    int s;
    int on = 1;
    struct sockaddr_in servaddr;
    if ((s = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("socket() failed");
        return -1;
    }
    setsockopt(s, 1, 2, &on, sizeof(on));
    servaddr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    servaddr.sin_family = 2;
    servaddr.sin_port = htons(port);
    while (bind(s, (struct sockaddr *) &servaddr, sizeof(servaddr)) == -1) {
        perror("bind() failed");
        usleep(50000);
        printf("retrying...\n");
    }
    if (listen(s, 3) == -1) {
        perror("listen() failed");
        return -1;
    }
    return s;
}

variable_types: port int

variable_types: s int

variable_types: on int

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

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

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


decompiled_code:
void __fastcall __noreturn tcp_loop_accept(int fd, void (__fastcall *a2)(_QWORD))
{
unsigned int v2; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

while ( 1 )
{
do
{
addr_len[0] = 16;
v2 = accept(fd, &v3, addr_len);
}
while ( v2 == -1 );
if ( !fork() )
{
signal(2, 0LL);
signal(15, 0LL);
close(fd);
a2(v2);
close(v2);
exit(0);
}
close(v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(int fd, void (__fastcall *a2)(_QWORD))
{
unsigned int v2; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

while ( 1 )
{
do
{
addr_len[0] = 16;
v2 = accept(fd, &v3, addr_len);
}
while ( v2 == -1 );
if ( !fork() )
{
signal(2, 0LL);
signal(15, 0LL);
close(fd);
a2(v2);
close(v2);
exit(0);
}
close(v2);
}
}

original_code:
void
tcp_loop_accept(int s, void (*callback) (int)) {
    int c, clisize;
    struct sockaddr_in cliaddr;
    for (;;) {
        clisize = sizeof(cliaddr);
        if ((c = accept(s, (struct sockaddr *) &cliaddr,
                        (socklen_t *) & clisize)) == -1)
            continue;
        if (fork() == 0) {
            signal(2, ((__sighandler_t) 0));
            signal(15, ((__sighandler_t) 0));
            close(s);
            callback(c);
            close(c);
            _exit(0);
        }
        close(c);
    }
}

canonical_original_code:
void tcp_loop_accept(int s, void (*callback)(int)) {
    int c; int clisize;
    struct sockaddr_in cliaddr;
    for (;;) {
        clisize = sizeof(cliaddr);
        if ((c = accept(s, (struct sockaddr *) &cliaddr,
                        (unsigned int *) & clisize)) == -1)
            continue;
        if (fork() == 0) {
            signal(2, ((void (*)(int)) 0));
            signal(15, ((void (*)(int)) 0));
            close(s);
            callback(c);
            close(c);
            _exit(0);
        }
        close(c);
    }
}

variable_types:
callback
void (*)(int)

variable_types: c int

variable_types: clisize int


end

decompiled_code:
void __noreturn end()
{
word_404170 &= 0xFEFFu;
ioctl(sock_ioctl, 0x8914uLL, &ifr);
close(sock_ioctl);
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
word_404170 &= 0xFEFFu;
ioctl(sock_ioctl, 0x8914uLL, &ifr);
close(sock_ioctl);
exit(0);
}

original_code:
void end() {
  ifr.ifr_ifru.ifru_flags &=~ IFF_PROMISC;
  ioctl(sock_ioctl, 0x8914, &ifr);
  close(sock_ioctl);
  exit(0);
}


decompiled_code:
int print_usage()
{
return puts("\nUsage: sniffit_tng -i <device> [-l logfile]\n");
}

canonical_decompiled_code:
int func11()
{
return puts("\nUsage: sniffit_tng -i <device> [-l logfile]\n");
}

original_code:
void print_usage(const char* exeName) {
  printf("\nUsage: sniffit_tng -i <device> [-l logfile]\n\n");
}

canonical_original_code:
void print_usage(char *exeName) {
  printf("\nUsage: sniffit_tng -i <device> [-l logfile]\n\n");
}

variable_types:
exeName
char *


original_code:
int isValidIp4 (const char *str) {
  int segs = 0;
  int chcnt = 0;
  int accum = 0;
  if (str == ((void *)0))
    return 0;
  while (*str != '\0') {
    if (*str == '.') {
      if (chcnt == 0)
        return 0;
      if (++segs == 4)
        return 0;
      chcnt = accum = 0;
      str++;
      continue;
    }
    if ((*str < '0') || (*str > '9'))
      return 0;
    if ((accum = accum * 10 + *str - '0') > 255)
      return 0;
    chcnt++;
    str++;
  }
  if (segs != 3)
    return 0;
  if (chcnt == 0)
    return 0;
  return 1;
}

canonical_original_code:
int isValidIp4(char *str) {
  int segs = 0;
  int chcnt = 0;
  int accum = 0;
  if (str == ((void *)0))
    return 0;
  while (*str != '\0') {
    if (*str == '.') {
      if (chcnt == 0)
        return 0;
      if (++segs == 4)
        return 0;
      chcnt = accum = 0;
      str++;
      continue;
    }
    if ((*str < '0') || (*str > '9'))
      return 0;
    if ((accum = accum * 10 + *str - '0') > 255)
      return 0;
    chcnt++;
    str++;
  }
  if (segs != 3)
    return 0;
  if (chcnt == 0)
    return 0;
  return 1;
}

variable_types:
str
char *

variable_types: segs int

variable_types: chcnt int

variable_types: accum int


unpackIP

decompiled_code:
__int16 unpackIP()
{
int v0; // eax
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
unsigned __int16 v3; // ax
char *v4; // rax
char *v5; // rax
unsigned __int16 v6; // ax
unsigned __int16 v7; // ax
__int16 v8; // ax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
unsigned int v11; // eax
unsigned int v12; // eax
char *v13; // rax
char *v14; // rax
unsigned __int16 v15; // ax
unsigned __int16 v16; // ax
char *v17; // rax
char *v18; // rax

LOBYTE(v0) = *((_BYTE *)off_4040C0 + 9);
if ( (unsigned __int8)v0 > 0x32u )
{
if ( (_BYTE)v0 == 119 )
{
puts("Spectralink packet detected");
v1 = _fswab16(*((_WORD *)ethernet + 6));
LOWORD(v0) = printf("Eth Protocol: %04X\n", v1);
return v0;
}
LABEL_14:
tcp = (__int64)&word_4041E2;
puts("\n---- Unknown protocol ----");
dword_404124 = *((_DWORD *)off_4040C0 + 4);
v17 = inet_ntoa((struct in_addr)dword_404124);
printf("Destination IP : %s\n", v17);
dword_404124 = *((_DWORD *)off_4040C0 + 3);
v18 = inet_ntoa((struct in_addr)dword_404124);
printf("Source IP : %s \n", v18);
printf("IP: Protocol : %d \n", *((unsigned __int8 *)off_4040C0 + 9));
payload_tcp = (__int64)malloc(0x14uLL);
payload_ip = (__int64)malloc(0x14uLL);
payload = tcp + 20;
LOWORD(v0) = printf("payload: %s\n\n\n", (const char *)(tcp + 20));
return v0;
}
if ( !(_BYTE)v0 )
goto LABEL_14;
LOWORD(v0) = (unsigned __int8)v0;
switch ( (char)v0 )
{
case 1:
case 2:
case 47:
case 50:
return v0;
case 6:
tcp = (__int64)&word_4041E2;
dword_404124 = *((_DWORD *)off_4040C0 + 4);
v4 = inet_ntoa((struct in_addr)dword_404124);
strcpy(src_ip, v4);
dword_404124 = *((_DWORD *)off_4040C0 + 3);
v5 = inet_ntoa((struct in_addr)dword_404124);
strcpy(dst_ip, v5);
if ( !(unsigned int)isValidIp4(src_ip) || (v0 = isValidIp4(dst_ip)) == 0 )
{
printf("IP source : %s\n", dst_ip);
printf("IP destination : %s\n", src_ip);
puts("\n----- IP Header -----");
printf("IP: Header length : %d bytes\n", 4 * (*(_BYTE *)off_4040C0 & 0xFu));
printf("IP: Version : %d \n", *(_BYTE *)off_4040C0 >> 4);
v6 = _bswap_16(*((_WORD *)off_4040C0 + 1));
printf("IP: Total length : %d \n", v6);
v7 = _bswap_16(*((_WORD *)off_4040C0 + 2));
printf("IP: Identification : %d \n", v7);
printf("IP: Flags : %.2x\n", *((_WORD *)off_4040C0 + 3) >> 12);
v8 = _bswap_16(*((_WORD *)off_4040C0 + 3));
printf("IP: Fragment offset : %d \n", v8 & 0xFFF);
printf("IP: Time to live : %d \n", *((unsigned __int8 *)off_4040C0 + 8));
printf("IP: Protocol : %d \n", *((unsigned __int8 *)off_4040C0 + 9));
puts("----TCP----");
v9 = _bswap_16(*(_WORD *)tcp);
printf("Source Port: %u\n", v9);
v10 = _bswap_16(*(_WORD *)(tcp + 2));
printf("Destination Port: %u\n", v10);
v11 = _bswap_32(*(_DWORD *)(tcp + 4));
printf("Sequence number : %u\n", v11);
v12 = _bswap_32(*(_DWORD *)(tcp + 8));
printf("ACK-SEQ : %u\n", v12);
printf("SYN : %u\n", (*(_BYTE *)(tcp + 13) & 2) != 0);
printf("ACK : %u\n", (*(_BYTE *)(tcp + 13) & 0x10) != 0);
printf("FIN : %u\n", *(_BYTE *)(tcp + 13) & 1);
printf("RST : %u\n", *(_BYTE *)(tcp + 13) & 1);
printf("ttl : %u\n", *((unsigned __int8 *)off_4040C0 + 8));
payload = tcp + 20;
LOWORD(v0) = printf("payload: %s\n", (const char *)(tcp + 20));
}
break;
case 16:
puts("Chaos Packet detected");
v2 = _fswab16(*((_WORD *)ethernet + 6));
LOWORD(v0) = printf("Eth Protocol: %04X\n", v2);
break;
case 17:
udp = (__int64)&word_4041E2;
LOWORD(v0) = _bswap_16(word_4041E2);
if ( !(_WORD)v0 )
{
puts("----UDP----");
puts("\n----IP----");
dword_404124 = *((_DWORD *)off_4040C0 + 4);
v13 = inet_ntoa((struct in_addr)dword_404124);
printf("Destination IP: %s\n", v13);
dword_404124 = *((_DWORD *)off_4040C0 + 3);
v14 = inet_ntoa((struct in_addr)dword_404124);
printf("Source IP: %s\n", v14);
v15 = _bswap_16(*(_WORD *)udp);
printf("Source Port: %u\n", v15);
v16 = _bswap_16(*(_WORD *)(udp + 2));
LOWORD(v0) = printf("Destination Port: %u\n", v16);
}
break;
case 22:
puts("Xerox IDP protocol detected");
v3 = _fswab16(*((_WORD *)ethernet + 6));
LOWORD(v0) = printf("Eth Protocol: %04X\n", v3);
break;
default:
goto LABEL_14;
}
return v0;
}

canonical_decompiled_code:
__int16 func13()
{
int v0; // eax
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
unsigned __int16 v3; // ax
char *v4; // rax
char *v5; // rax
unsigned __int16 v6; // ax
unsigned __int16 v7; // ax
__int16 v8; // ax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
unsigned int v11; // eax
unsigned int v12; // eax
char *v13; // rax
char *v14; // rax
unsigned __int16 v15; // ax
unsigned __int16 v16; // ax
char *v17; // rax
char *v18; // rax

LOBYTE(v0) = *((_BYTE *)off_4040C0 + 9);
if ( (unsigned __int8)v0 > 0x32u )
{
if ( (_BYTE)v0 == 119 )
{
puts("Spectralink packet detected");
v1 = func7(*((_WORD *)ethernet + 6));
LOWORD(v0) = printf("Eth Protocol: %04X\n", v1);
return v0;
}
LABEL_14:
tcp = (__int64)&word_4041E2;
puts("\n---- Unknown protocol ----");
dword_404124 = *((_DWORD *)off_4040C0 + 4);
v17 = inet_ntoa((struct in_addr)dword_404124);
printf("Destination IP : %s\n", v17);
dword_404124 = *((_DWORD *)off_4040C0 + 3);
v18 = inet_ntoa((struct in_addr)dword_404124);
printf("Source IP : %s \n", v18);
printf("IP: Protocol : %d \n", *((unsigned __int8 *)off_4040C0 + 9));
payload_tcp = (__int64)malloc(0x14uLL);
payload_ip = (__int64)malloc(0x14uLL);
payload = tcp + 20;
LOWORD(v0) = printf("payload: %s\n\n\n", (const char *)(tcp + 20));
return v0;
}
if ( !(_BYTE)v0 )
goto LABEL_14;
LOWORD(v0) = (unsigned __int8)v0;
switch ( (char)v0 )
{
case 1:
case 2:
case 47:
case 50:
return v0;
case 6:
tcp = (__int64)&word_4041E2;
dword_404124 = *((_DWORD *)off_4040C0 + 4);
v4 = inet_ntoa((struct in_addr)dword_404124);
strcpy(src_ip, v4);
dword_404124 = *((_DWORD *)off_4040C0 + 3);
v5 = inet_ntoa((struct in_addr)dword_404124);
strcpy(dst_ip, v5);
if ( !(unsigned int)func12(src_ip) || (v0 = func12(dst_ip)) == 0 )
{
printf("IP source : %s\n", dst_ip);
printf("IP destination : %s\n", src_ip);
puts("\n----- IP Header -----");
printf("IP: Header length : %d bytes\n", 4 * (*(_BYTE *)off_4040C0 & 0xFu));
printf("IP: Version : %d \n", *(_BYTE *)off_4040C0 >> 4);
v6 = func9(*((_WORD *)off_4040C0 + 1));
printf("IP: Total length : %d \n", v6);
v7 = func9(*((_WORD *)off_4040C0 + 2));
printf("IP: Identification : %d \n", v7);
printf("IP: Flags : %.2x\n", *((_WORD *)off_4040C0 + 3) >> 12);
v8 = func9(*((_WORD *)off_4040C0 + 3));
printf("IP: Fragment offset : %d \n", v8 & 0xFFF);
printf("IP: Time to live : %d \n", *((unsigned __int8 *)off_4040C0 + 8));
printf("IP: Protocol : %d \n", *((unsigned __int8 *)off_4040C0 + 9));
puts("----TCP----");
v9 = func9(*(_WORD *)tcp);
printf("Source Port: %u\n", v9);
v10 = func9(*(_WORD *)(tcp + 2));
printf("Destination Port: %u\n", v10);
v11 = func10(*(_DWORD *)(tcp + 4));
printf("Sequence number : %u\n", v11);
v12 = func10(*(_DWORD *)(tcp + 8));
printf("ACK-SEQ : %u\n", v12);
printf("SYN : %u\n", (*(_BYTE *)(tcp + 13) & 2) != 0);
printf("ACK : %u\n", (*(_BYTE *)(tcp + 13) & 0x10) != 0);
printf("FIN : %u\n", *(_BYTE *)(tcp + 13) & 1);
printf("RST : %u\n", *(_BYTE *)(tcp + 13) & 1);
printf("ttl : %u\n", *((unsigned __int8 *)off_4040C0 + 8));
payload = tcp + 20;
LOWORD(v0) = printf("payload: %s\n", (const char *)(tcp + 20));
}
break;
case 16:
puts("Chaos Packet detected");
v2 = func7(*((_WORD *)ethernet + 6));
LOWORD(v0) = printf("Eth Protocol: %04X\n", v2);
break;
case 17:
udp = (__int64)&word_4041E2;
LOWORD(v0) = func9(word_4041E2);
if ( !(_WORD)v0 )
{
puts("----UDP----");
puts("\n----IP----");
dword_404124 = *((_DWORD *)off_4040C0 + 4);
v13 = inet_ntoa((struct in_addr)dword_404124);
printf("Destination IP: %s\n", v13);
dword_404124 = *((_DWORD *)off_4040C0 + 3);
v14 = inet_ntoa((struct in_addr)dword_404124);
printf("Source IP: %s\n", v14);
v15 = func9(*(_WORD *)udp);
printf("Source Port: %u\n", v15);
v16 = func9(*(_WORD *)(udp + 2));
LOWORD(v0) = printf("Destination Port: %u\n", v16);
}
break;
case 22:
puts("Xerox IDP protocol detected");
v3 = func7(*((_WORD *)ethernet + 6));
LOWORD(v0) = printf("Eth Protocol: %04X\n", v3);
break;
default:
goto LABEL_14;
}
return v0;
}

original_code:
void unpackIP() {
  switch (ip->protocol) {
  case IPPROTO_CHAOS:
    printf("Chaos Packet detected\n");
    printf("Eth Protocol: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
    break;
  case IPPROTO_SRP:
    printf("Spectralink packet detected\n");
    printf("Eth Protocol: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
    break;
  case IPPROTO_IDP:
    printf("Xerox IDP protocol detected\n");
    printf("Eth Protocol: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
    break;
  case IPPROTO_GRE:
    break;
  case IPPROTO_ESP:
    break;
  case IPPROTO_IGMP:
    break;
  case IPPROTO_TCP:
    tcp = (struct tcphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    sin_in.sin_addr.s_addr = ip->daddr;
    sprintf(src_ip, "%s", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    sprintf(dst_ip, "%s", inet_ntoa(sin_in.sin_addr));
    if (isValidIp4(src_ip) && isValidIp4(dst_ip)) break;
    printf("IP source : %s\n", dst_ip);
    printf("IP destination : %s\n", src_ip);
    printf("\n----- IP Header -----\n");
    printf("IP: Header length    : %d bytes\n", ip->ihl*4);
    printf("IP: Version          : %d  \n", ip->version);
    printf("IP: Total length     : %d \n", ntohs(ip->tot_len));
    printf("IP: Identification   : %d \n", ntohs(ip->id));
    printf("IP: Flags            : %.2x\n", (unsigned char)((ip->frag_off)>>12));
    printf("IP: Fragment offset  : %d  \n", ntohs(ip->frag_off) & 0x0FFF);
    printf("IP: Time to live     : %d  \n", ip->ttl);
    printf("IP: Protocol         : %d  \n", ip->protocol);
    printf("----TCP----\n");
    printf("Source Port: %u\n", ntohs(tcp->source));
    printf("Destination Port: %u\n", ntohs(tcp->dest));
    printf("Sequence number : %u\n", ntohl(tcp->seq));
    printf("ACK-SEQ : %u\n", ntohl(tcp->ack_seq));
    printf("SYN : %u\n", tcp->syn);
    printf("ACK : %u\n", tcp->ack);
    printf("FIN : %u\n", tcp->fin);
    printf("RST : %u\n", tcp->fin);
    printf("ttl : %u\n", ip->ttl);
    payload = (u_char *)((char *)tcp + sizeof(struct tcphdr));
    printf("payload: %s\n", payload);
    break;
  case IPPROTO_UDP:
    udp = (struct udphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    if (ntohs(udp->source) != 0) break;
    printf("----UDP----\n");
    printf("\n----IP----\n");
    sin_in.sin_addr.s_addr = ip->daddr;
    printf("Destination IP: %s\n", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    printf("Source IP: %s\n", inet_ntoa(sin_in.sin_addr));
    printf("Source Port: %u\n", ntohs(udp->source));
    printf("Destination Port: %u\n", ntohs(udp->dest));
    break;
  case IPPROTO_ICMP:
    if(1) break;
    printf("\n----IP----\n");
    sin_in.sin_addr.s_addr = ip->daddr;
    printf("Destination IP: %s\n", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    printf("----ICMP----\n");
    icmp = (struct icmphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    printf("Source IP : %s\n", inet_ntoa(sin_in.sin_addr));
    printf("type : %u\n", icmp->type);
    printf("code : %u\n", icmp->code);
    break;
  default:
    tcp = (struct tcphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    printf("\n---- Unknown protocol      ----\n");
    sin_in.sin_addr.s_addr = ip->daddr;
    printf("Destination IP : %s\n", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    printf("Source IP : %s \n", inet_ntoa(sin_in.sin_addr));
    printf("IP: Protocol         : %d  \n", ip->protocol);
    payload_tcp = (char*)malloc(sizeof(struct tcphdr));
    payload_ip = (char*)malloc(sizeof(struct iphdr));
    payload = (u_char *)((char *)tcp + sizeof(struct tcphdr));
    printf("payload: %s\n\n\n", payload);
    break;
  }
}

canonical_original_code:
void unpackIP() {
  switch (ip->protocol) {
  case IPPROTO_CHAOS:
    printf("Chaos Packet detected\n");
    printf("Eth Protocol: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
    break;
  case IPPROTO_SRP:
    printf("Spectralink packet detected\n");
    printf("Eth Protocol: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
    break;
  case IPPROTO_IDP:
    printf("Xerox IDP protocol detected\n");
    printf("Eth Protocol: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
    break;
  case IPPROTO_GRE:
    break;
  case IPPROTO_ESP:
    break;
  case IPPROTO_IGMP:
    break;
  case IPPROTO_TCP:
    tcp = (struct tcphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    sin_in.sin_addr.s_addr = ip->daddr;
    sprintf(src_ip, "%s", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    sprintf(dst_ip, "%s", inet_ntoa(sin_in.sin_addr));
    if (isValidIp4(src_ip) && isValidIp4(dst_ip)) break;
    printf("IP source : %s\n", dst_ip);
    printf("IP destination : %s\n", src_ip);
    printf("\n----- IP Header -----\n");
    printf("IP: Header length    : %d bytes\n", ip->ihl*4);
    printf("IP: Version          : %d  \n", ip->version);
    printf("IP: Total length     : %d \n", ntohs(ip->tot_len));
    printf("IP: Identification   : %d \n", ntohs(ip->id));
    printf("IP: Flags            : %.2x\n", (unsigned char)((ip->frag_off)>>12));
    printf("IP: Fragment offset  : %d  \n", ntohs(ip->frag_off) & 0x0FFF);
    printf("IP: Time to live     : %d  \n", ip->ttl);
    printf("IP: Protocol         : %d  \n", ip->protocol);
    printf("----TCP----\n");
    printf("Source Port: %u\n", ntohs(tcp->source));
    printf("Destination Port: %u\n", ntohs(tcp->dest));
    printf("Sequence number : %u\n", ntohl(tcp->seq));
    printf("ACK-SEQ : %u\n", ntohl(tcp->ack_seq));
    printf("SYN : %u\n", tcp->syn);
    printf("ACK : %u\n", tcp->ack);
    printf("FIN : %u\n", tcp->fin);
    printf("RST : %u\n", tcp->fin);
    printf("ttl : %u\n", ip->ttl);
    payload = (unsigned char *)((char *)tcp + sizeof(struct tcphdr));
    printf("payload: %s\n", payload);
    break;
  case IPPROTO_UDP:
    udp = (struct udphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    if (ntohs(udp->source) != 0) break;
    printf("----UDP----\n");
    printf("\n----IP----\n");
    sin_in.sin_addr.s_addr = ip->daddr;
    printf("Destination IP: %s\n", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    printf("Source IP: %s\n", inet_ntoa(sin_in.sin_addr));
    printf("Source Port: %u\n", ntohs(udp->source));
    printf("Destination Port: %u\n", ntohs(udp->dest));
    break;
  case IPPROTO_ICMP:
    if(1) break;
    printf("\n----IP----\n");
    sin_in.sin_addr.s_addr = ip->daddr;
    printf("Destination IP: %s\n", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    printf("----ICMP----\n");
    icmp = (struct icmphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    printf("Source IP : %s\n", inet_ntoa(sin_in.sin_addr));
    printf("type : %u\n", icmp->type);
    printf("code : %u\n", icmp->code);
    break;
  default:
    tcp = (struct tcphdr *)&buffer[sizeof(struct ethhdr) + sizeof(struct iphdr)];
    printf("\n---- Unknown protocol      ----\n");
    sin_in.sin_addr.s_addr = ip->daddr;
    printf("Destination IP : %s\n", inet_ntoa(sin_in.sin_addr));
    sin_in.sin_addr.s_addr = ip->saddr;
    printf("Source IP : %s \n", inet_ntoa(sin_in.sin_addr));
    printf("IP: Protocol         : %d  \n", ip->protocol);
    payload_tcp = (char *)malloc(sizeof(struct tcphdr));
    payload_ip = (char *)malloc(sizeof(struct iphdr));
    payload = (unsigned char *)((char *)tcp + sizeof(struct tcphdr));
    printf("payload: %s\n\n\n", payload);
    break;
  }
}

user_defined_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; }

user_defined_types: struct iphdr { unsigned char ihl; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; }

user_defined_types: struct tcphdr { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short window; unsigned short check; unsigned short urg_ptr; }

user_defined_types: struct udphdr { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }

user_defined_types: struct icmphdr { unsigned char type; unsigned char code; unsigned short checksum; union { struct { unsigned short id; unsigned short sequence; } echo; unsigned int gateway; struct { unsigned short __unused; unsigned short mtu; } frag; unsigned char reserved[4]; } un; }


checkFileAccess

decompiled_code:
__int64 __fastcall checkFileAccess(char *name)
{
int v2; // eax
int v3; // eax

if ( !*name )
return 0LL;
if ( access(name, 0) )
{
v2 = *__errno_location();
if ( v2 == 2 )
{
printf("%s does not exist\n", name);
}
else if ( v2 == 13 )
{
printf("%s is not accessible\n", name);
}
}
else
{
printf("%s exists\n", name);
if ( access(name, 4) )
printf("%s is not readable (access denied)\n", name);
else
printf("%s is readable\n", name);
if ( access(name, 2) )
{
v3 = *__errno_location();
if ( v3 == 13 )
{
printf("%s is not writable (access denied)\n", name);
}
else if ( v3 == 30 )
{
printf("%s is not writable (read-only filesystem)\n", name);
}
}
else
{
printf("%s is writable\n", name);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *name)
{
int v2; // eax
int v3; // eax

if ( !*name )
return 0LL;
if ( access(name, 0) )
{
v2 = *__errno_location();
if ( v2 == 2 )
{
printf("%s does not exist\n", name);
}
else if ( v2 == 13 )
{
printf("%s is not accessible\n", name);
}
}
else
{
printf("%s exists\n", name);
if ( access(name, 4) )
printf("%s is not readable (access denied)\n", name);
else
printf("%s is readable\n", name);
if ( access(name, 2) )
{
v3 = *__errno_location();
if ( v3 == 13 )
{
printf("%s is not writable (access denied)\n", name);
}
else if ( v3 == 30 )
{
printf("%s is not writable (read-only filesystem)\n", name);
}
}
else
{
printf("%s is writable\n", name);
}
}
return 0LL;
}

original_code:
int checkFileAccess(const char* path) {
  int rval;
  if(!strlen(path)) {
    return 0;
  }
  rval = access (path, 0);
  if (rval == 0)
    printf ("%s exists\n", path);
  else {
    if ((*__errno_location ()) == 2)
      printf ("%s does not exist\n", path);
    else if ((*__errno_location ()) == 13)
      printf ("%s is not accessible\n", path);
    return 0;
  }
  rval = access (path, 4);
  if (rval == 0)
    printf ("%s is readable\n", path);
  else
    printf ("%s is not readable (access denied)\n", path);
  rval = access (path, 2);
  if (rval == 0)
    printf ("%s is writable\n", path);
  else if ((*__errno_location ()) == 13)
    printf ("%s is not writable (access denied)\n", path);
  else if ((*__errno_location ()) == 30)
    printf ("%s is not writable (read-only filesystem)\n", path);
  return 0;
}

canonical_original_code:
int checkFileAccess(char *path) {
  int rval;
  if(!strlen(path)) {
    return 0;
  }
  rval = access (path, 0);
  if (rval == 0)
    printf ("%s exists\n", path);
  else {
    if ((*__errno_location ()) == 2)
      printf ("%s does not exist\n", path);
    else if ((*__errno_location ()) == 13)
      printf ("%s is not accessible\n", path);
    return 0;
  }
  rval = access (path, 4);
  if (rval == 0)
    printf ("%s is readable\n", path);
  else
    printf ("%s is not readable (access denied)\n", path);
  rval = access (path, 2);
  if (rval == 0)
    printf ("%s is writable\n", path);
  else if ((*__errno_location ()) == 13)
    printf ("%s is not writable (access denied)\n", path);
  else if ((*__errno_location ()) == 30)
    printf ("%s is not writable (read-only filesystem)\n", path);
  return 0;
}

variable_types:
path
char *

variable_types: rval int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v4; // eax
__int64 v5; // rcx
char *v6; // rdi
const char *v7; // r14
size_t v8; // rax
char *v9; // r12
size_t v10; // rax
unsigned __int16 v11; // ax
unsigned __int16 v12; // ax

signal(2, (__sighandler_t)end);
if ( geteuid() )
{
fwrite("Must be root to run this program\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( argc <= 1 )
{
print_usage();
exit(1);
}
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:l:");
if ( v4 == -1 )
break;
if ( v4 == 105 )
{
v5 = 10LL;
v6 = 𝔦
while ( v5 )
{
*(_DWORD *)v6 = 0;
v6 += 4;
--v5;
}
strncpy(&ifr, optarg, 0x10uLL);
}
else
{
if ( v4 != 108 )
{
print_usage();
exit(1);
}
v7 = optarg;
v8 = strlen(optarg);
v9 = (char *)malloc(v8);
v10 = strlen(v7);
strncpy(v9, v7, v10);
if ( !(unsigned int)checkFileAccess(v9) )
exit(1);
}
}
if ( !ifr )
{
print_usage();
exit(1);
}
sock_ioctl = socket(2, 2, 0);
if ( sock_ioctl < 0 )
{
perror("Error calling socket()");
exit(1);
}
addr_len = 16;
printf("\nSniffing on device : ");
printf("%s\n\n", &ifr);
if ( ioctl(sock_ioctl, 0x8913uLL, &ifr) < 0 )
{
fwrite("ioctl() error, device probably does not exist or is not accessible.\n\n", 1uLL, 0x45uLL, stderr);
exit(1);
}
word_404170 |= 0x100u;
ioctl(sock_ioctl, 0x8914uLL, &ifr);
strncpy(from.sa_data, argv[1], 0xEuLL);
v11 = _bswap_16(3);
fd = socket(17, 3, v11);
if ( fd < 0 )
{
perror("socket() error");
exit(1);
}
while ( 1 )
{
while ( 1 )
{
do
{
recvfrom(fd, &buffer, 0x5DCuLL, 0, &from, &addr_len);
v12 = _fswab16(*((_WORD *)ethernet + 6));
}
while ( v12 == 0x8035 );
if ( v12 > 0x8035u )
break;
if ( v12 == 2048 )
{
unpackIP();
}
else if ( v12 != 2054 )
{
goto LABEL_31;
}
}
if ( v12 != 0x86DD )
{
if ( v12 == 0x88CC )
puts("LLDP Packet detected.");
else
LABEL_31:
printf("Another Ethertype detected: %04X\n", v12);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v4; // eax
__int64 v5; // rcx
char *v6; // rdi
const char *v7; // r14
size_t v8; // rax
char *v9; // r12
size_t v10; // rax
unsigned __int16 v11; // ax
unsigned __int16 v12; // ax

signal(2, (__sighandler_t)end);
if ( geteuid() )
{
fwrite("Must be root to run this program\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( argc <= 1 )
{
func11();
exit(1);
}
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:l:");
if ( v4 == -1 )
break;
if ( v4 == 105 )
{
v5 = 10LL;
v6 = 𝔦
while ( v5 )
{
*(_DWORD *)v6 = 0;
v6 += 4;
--v5;
}
strncpy(&ifr, optarg, 0x10uLL);
}
else
{
if ( v4 != 108 )
{
func11();
exit(1);
}
v7 = optarg;
v8 = strlen(optarg);
v9 = (char *)malloc(v8);
v10 = strlen(v7);
strncpy(v9, v7, v10);
if ( !(unsigned int)func14(v9) )
exit(1);
}
}
if ( !ifr )
{
func11();
exit(1);
}
sock_ioctl = socket(2, 2, 0);
if ( sock_ioctl < 0 )
{
perror("Error calling socket()");
exit(1);
}
addr_len = 16;
printf("\nSniffing on device : ");
printf("%s\n\n", &ifr);
if ( ioctl(sock_ioctl, 0x8913uLL, &ifr) < 0 )
{
fwrite("ioctl() error, device probably does not exist or is not accessible.\n\n", 1uLL, 0x45uLL, stderr);
exit(1);
}
word_404170 |= 0x100u;
ioctl(sock_ioctl, 0x8914uLL, &ifr);
strncpy(from.sa_data, argv[1], 0xEuLL);
v11 = func9(3);
fd = socket(17, 3, v11);
if ( fd < 0 )
{
perror("socket() error");
exit(1);
}
while ( 1 )
{
while ( 1 )
{
do
{
recvfrom(fd, &buffer, 0x5DCuLL, 0, &from, &addr_len);
v12 = func7(*((_WORD *)ethernet + 6));
}
while ( v12 == 0x8035 );
if ( v12 > 0x8035u )
break;
if ( v12 == 2048 )
{
func13();
}
else if ( v12 != 2054 )
{
goto LABEL_31;
}
}
if ( v12 != 0x86DD )
{
if ( v12 == 0x88CC )
puts("LLDP Packet detected.");
else
LABEL_31:
printf("Another Ethertype detected: %04X\n", v12);
}
}
}

original_code:
int main(int agc,char *agv[]) {
  char payloadBuffer[1500];
  char *logFilename;
  int option = 0;
  (void) signal(2, end);
  if (geteuid ()) {
    fprintf (stderr, "Must be root to run this program\n");
    exit(1);
  }
  if (agc < 2) {
    print_usage(agv[0]);
    exit(1);
  }
  while ((option = getopt(agc, agv, "i:l:")) != -1) {
    switch (option) {
    case 'i':
      memset(&ifr, 0, sizeof(ifr));
      strncpy(ifr.ifr_ifrn.ifrn_name, optarg, sizeof(ifr.ifr_ifrn.ifrn_name));
      break;
    case 'l':
      logFilename = (char*)malloc(strlen(optarg));
      strncpy(logFilename, optarg, strlen(optarg));
      if (!checkFileAccess(logFilename)) {
        exit(1);
      }
      break;
    default:
      print_usage(agv[0]);
      exit(1);
    }
  }
  if (strlen(ifr.ifr_ifrn.ifrn_name) == 0) {
    print_usage(agv[0]);
    exit(1);
  }
  if ((sock_ioctl = socket(2, SOCK_DGRAM, 0)) < 0) {
    perror("Error calling socket()");
    exit(1);
  }
  addr_len = sizeof(struct sockaddr);
  printf("\nSniffing on device : ");
  printf("%s\n\n", ifr.ifr_ifrn.ifrn_name);
  if ((ioctl(sock_ioctl, 0x8913, &ifr)) < 0) {
    fprintf(stderr, "%s", "ioctl() error, device probably does not exist or is not accessible.\n\n");
    exit(1);
  }
  ifr.ifr_ifru.ifru_flags |= IFF_PROMISC;
  ioctl(sock_ioctl, 0x8914, &ifr);
  strncpy(from.sa_data, agv[1], sizeof(from.sa_data));
  if ((fd = socket(17, SOCK_RAW, htons(0x0003))) < 0) {
    perror("socket() error");
    exit(1);
  }
  while(1) {
    recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr *)&from,&addr_len);
    switch ((__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto)))) {
    case 0x0800:
      unpackIP();
      break;
    case 0x0806:
      break;
    case 0x86DD:
      break;
    case 0x8035:
      break;
    case ETH_P_LLDP:
      printf("LLDP Packet detected.\n");
      break;
    default:
      printf("Another Ethertype detected: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (__u16)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
      break;
    }
  }
}

canonical_original_code:
int main(int agc, char *agv[]) {
  char payloadBuffer[1500];
  char *logFilename;
  int option = 0;
  (void) signal(2, end);
  if (geteuid ()) {
    fprintf (stderr, "Must be root to run this program\n");
    exit(1);
  }
  if (agc < 2) {
    print_usage(agv[0]);
    exit(1);
  }
  while ((option = getopt(agc, agv, "i:l:")) != -1) {
    switch (option) {
    case 'i':
      memset(&ifr, 0, sizeof(ifr));
      strncpy(ifr.ifr_ifrn.ifrn_name, optarg, sizeof(ifr.ifr_ifrn.ifrn_name));
      break;
    case 'l':
      logFilename = (char *)malloc(strlen(optarg));
      strncpy(logFilename, optarg, strlen(optarg));
      if (!checkFileAccess(logFilename)) {
        exit(1);
      }
      break;
    default:
      print_usage(agv[0]);
      exit(1);
    }
  }
  if (strlen(ifr.ifr_ifrn.ifrn_name) == 0) {
    print_usage(agv[0]);
    exit(1);
  }
  if ((sock_ioctl = socket(2, SOCK_DGRAM, 0)) < 0) {
    perror("Error calling socket()");
    exit(1);
  }
  addr_len = sizeof(struct sockaddr);
  printf("\nSniffing on device : ");
  printf("%s\n\n", ifr.ifr_ifrn.ifrn_name);
  if ((ioctl(sock_ioctl, 0x8913, &ifr)) < 0) {
    fprintf(stderr, "%s", "ioctl() error, device probably does not exist or is not accessible.\n\n");
    exit(1);
  }
  ifr.ifr_ifru.ifru_flags |= IFF_PROMISC;
  ioctl(sock_ioctl, 0x8914, &ifr);
  strncpy(from.sa_data, agv[1], sizeof(from.sa_data));
  if ((fd = socket(17, SOCK_RAW, htons(0x0003))) < 0) {
    perror("socket() error");
    exit(1);
  }
  while(1) {
    recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr *)&from,&addr_len);
    switch ((__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto)))) {
    case 0x0800:
      unpackIP();
      break;
    case 0x0806:
      break;
    case 0x86DD:
      break;
    case 0x8035:
      break;
    case ETH_P_LLDP:
      printf("LLDP Packet detected.\n");
      break;
    default:
      printf("Another Ethertype detected: %04X\n", (__builtin_constant_p((__u16)((__u16)(__be16)(ethernet->h_proto))) ? ((__u16)( (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0x00ffU) << 8) | (((__u16)((__u16)(__be16)(ethernet->h_proto)) & (unsigned short)0xff00U) >> 8))) : __fswab16((__u16)(__be16)(ethernet->h_proto))));
      break;
    }
  }
}

variable_types: agc int

variable_types:
agv
char *[]

variable_types:
payloadBuffer
char [1500]

variable_types:
logFilename
char *

variable_types: option int


repo: chrisabird/emLisp

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

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

original_code:
int main(int argc, char *argv[]) {
  test_lexer();
  test_parser();
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 should_lex_empty_as_empty()
{
unsigned int v0; // eax

v0 = findNextToken();
return assertIntegerEquals(v0, 0LL);
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // eax

v0 = func31();
return func34(v0, 0LL);
}

original_code:
_Bool should_lex_empty_as_empty() {
  Token t = findNextToken();
  return assertIntegerEquals(t.type, Empty);
}

canonical_original_code:
_Bool should_lex_empty_as_empty() {
  struct token t = findNextToken();
  return assertIntegerEquals(t.type, Empty);
}

variable_types: struct token { enum tokenType { Empty=0, LeftParen=1, RightParen=2, Integer=3, Symbol=4, Character=5 } type; union { int integer; int character; char symbol[7]; } val; }

user_defined_types: struct token { enum tokenType type; union { int integer; int character; char symbol[7]; } val; }


decompiled_code:
__int64 should_lex_space_char_as_empty()
{
unsigned int v0; // eax

handleChar(32LL);
v0 = findNextToken();
return assertIntegerEquals(v0, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // eax

func20(32LL);
v0 = func31();
return func34(v0, 0LL);
}

original_code:
_Bool should_lex_space_char_as_empty() {
  handleChar(' ');
  Token t = findNextToken();
  return assertIntegerEquals(t.type, Empty);
}

canonical_original_code:
_Bool should_lex_space_char_as_empty() {
  handleChar(' ');
  struct token t = findNextToken();
  return assertIntegerEquals(t.type, Empty);
}

user_defined_types: enum tokenType { Empty=0, LeftParen=1, RightParen=2, Integer=3, Symbol=4, Character=5 }


decompiled_code:
__int64 should_lex_left_paren_as_token()
{
unsigned int v0; // eax

handleChar(40LL);
v0 = findNextToken();
return assertIntegerEquals(v0, 1LL);
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // eax

func20(40LL);
v0 = func31();
return func34(v0, 1LL);
}

original_code:
_Bool should_lex_left_paren_as_token() {
  handleChar('(');
  Token t = findNextToken();
  return assertIntegerEquals(t.type, LeftParen);
}

canonical_original_code:
_Bool should_lex_left_paren_as_token() {
  handleChar('(');
  struct token t = findNextToken();
  return assertIntegerEquals(t.type, LeftParen);
}


decompiled_code:
__int64 should_lex_right_paren_as_token()
{
unsigned int v0; // eax

handleChar(41LL);
v0 = findNextToken();
return assertIntegerEquals(v0, 2LL);
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // eax

func20(41LL);
v0 = func31();
return func34(v0, 2LL);
}

original_code:
_Bool should_lex_right_paren_as_token() {
  handleChar(')');
  Token t = findNextToken();
  return assertIntegerEquals(t.type, RightParen);
}

canonical_original_code:
_Bool should_lex_right_paren_as_token() {
  handleChar(')');
  struct token t = findNextToken();
  return assertIntegerEquals(t.type, RightParen);
}


decompiled_code:
__int64 should_lex_integer_as_token()
{
unsigned int v0; // eax

handleChar(48LL);
handleChar(32LL);
v0 = findNextToken();
return assertIntegerEquals(v0, 3LL);
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // eax

func20(48LL);
func20(32LL);
v0 = func31();
return func34(v0, 3LL);
}

original_code:
_Bool should_lex_integer_as_token() {
  handleChar('0');
  handleChar(' ');
  Token t = findNextToken();
  return assertIntegerEquals(t.type, Integer);
}

canonical_original_code:
_Bool should_lex_integer_as_token() {
  handleChar('0');
  handleChar(' ');
  struct token t = findNextToken();
  return assertIntegerEquals(t.type, Integer);
}


decompiled_code:
__int64 should_lex_integer_as_token_with_value()
{
unsigned __int64 v0; // rax

handleChar(49LL);
handleChar(32LL);
v0 = findNextToken();
return assertIntegerEquals(HIDWORD(v0), 1LL);
}

canonical_decompiled_code:
__int64 func12()
{
unsigned __int64 v0; // rax

func20(49LL);
func20(32LL);
v0 = func31();
return func34(HIDWORD(v0), 1LL);
}

original_code:
_Bool should_lex_integer_as_token_with_value() {
  handleChar('1');
  handleChar(' ');
  Token t = findNextToken();
  return assertIntegerEquals(t.val.integer, 1);
}

canonical_original_code:
_Bool should_lex_integer_as_token_with_value() {
  handleChar('1');
  handleChar(' ');
  struct token t = findNextToken();
  return assertIntegerEquals(t.val.integer, 1);
}


decompiled_code:
__int64 should_lex_multi_digit_integer_as_token_with_value()
{
unsigned __int64 v0; // rax

handleChar(49LL);
handleChar(48LL);
handleChar(32LL);
v0 = findNextToken();
return assertIntegerEquals(HIDWORD(v0), 10LL);
}

canonical_decompiled_code:
__int64 func13()
{
unsigned __int64 v0; // rax

func20(49LL);
func20(48LL);
func20(32LL);
v0 = func31();
return func34(HIDWORD(v0), 10LL);
}

original_code:
_Bool should_lex_multi_digit_integer_as_token_with_value() {
  handleChar('1');
  handleChar('0');
  handleChar(' ');
  Token t = findNextToken();
  return assertIntegerEquals(t.val.integer, 10);
}

canonical_original_code:
_Bool should_lex_multi_digit_integer_as_token_with_value() {
  handleChar('1');
  handleChar('0');
  handleChar(' ');
  struct token t = findNextToken();
  return assertIntegerEquals(t.val.integer, 10);
}


decompiled_code:
__int64 should_lex_integer_terminated_with_non_space_charater()
{
unsigned __int64 v0; // rax

handleChar(49LL);
handleChar(48LL);
v0 = findNextToken();
return assertIntegerEquals(HIDWORD(v0), 10LL);
}

canonical_decompiled_code:
__int64 func14()
{
unsigned __int64 v0; // rax

func20(49LL);
func20(48LL);
v0 = func31();
return func34(HIDWORD(v0), 10LL);
}

original_code:
_Bool should_lex_integer_terminated_with_non_space_charater() {
  handleChar('1');
  handleChar('0');
  Token t = findNextToken();
  return assertIntegerEquals(t.val.integer, 10);
}

canonical_original_code:
_Bool should_lex_integer_terminated_with_non_space_charater() {
  handleChar('1');
  handleChar('0');
  struct token t = findNextToken();
  return assertIntegerEquals(t.val.integer, 10);
}


decompiled_code:
__int64 should_lex_symbol_as_token()
{
unsigned int v0; // eax

handleChar(97LL);
v0 = findNextToken();
return assertIntegerEquals(v0, 4LL);
}

canonical_decompiled_code:
__int64 func15()
{
unsigned int v0; // eax

func20(97LL);
v0 = func31();
return func34(v0, 4LL);
}

original_code:
_Bool should_lex_symbol_as_token() {
  handleChar('a');
  Token t = findNextToken();
  return assertIntegerEquals(t.type, Symbol);
}

canonical_original_code:
_Bool should_lex_symbol_as_token() {
  handleChar('a');
  struct token t = findNextToken();
  return assertIntegerEquals(t.type, Symbol);
}


decompiled_code:
__int64 should_lex_char()
{
__int64 v0; // rax

handleChar(39LL);
handleChar(99LL);
handleChar(39LL);
v0 = findNextToken();
return assertCharEquals((unsigned int)SBYTE4(v0), 99LL);
}

canonical_decompiled_code:
__int64 func16()
{
__int64 v0; // rax

func20(39LL);
func20(99LL);
func20(39LL);
v0 = func31();
return func33((unsigned int)SBYTE4(v0), 99LL);
}

original_code:
_Bool should_lex_char() {
  handleChar('\'');
  handleChar('c');
  handleChar('\'');
  Token t = findNextToken();
  return assertCharEquals(t.val.character, 'c');
}

canonical_original_code:
_Bool should_lex_char() {
  handleChar('\'');
  handleChar('c');
  handleChar('\'');
  struct token t = findNextToken();
  return assertCharEquals(t.val.character, 'c');
}


decompiled_code:
__int64 should_lex_symbol_as_token_with_value()
{
char v0; // dl
char v1; // al
char v3; // dl
__int64 v4; // [rsp+4h] [rbp-14h]

handleChar(97LL);
handleChar(98LL);
handleChar(99LL);
v4 = findNextToken();
v0 = assertCharEquals((unsigned int)SBYTE4(v4), 97LL);
v1 = 0;
if ( v0 )
{
v3 = assertCharEquals((unsigned int)SBYTE5(v4), 98LL);
v1 = 0;
if ( v3 )
v1 = assertCharEquals((unsigned int)SBYTE6(v4), 99LL);
}
return v1 & 1;
}

canonical_decompiled_code:
__int64 func17()
{
char v0; // dl
char v1; // al
char v3; // dl
__int64 v4; // [rsp+4h] [rbp-14h]

func20(97LL);
func20(98LL);
func20(99LL);
v4 = func31();
v0 = func33((unsigned int)SBYTE4(v4), 97LL);
v1 = 0;
if ( v0 )
{
v3 = func33((unsigned int)SBYTE5(v4), 98LL);
v1 = 0;
if ( v3 )
v1 = func33((unsigned int)SBYTE6(v4), 99LL);
}
return v1 & 1;
}

original_code:
_Bool should_lex_symbol_as_token_with_value() {
  handleChar('a');
  handleChar('b');
  handleChar('c');
  Token t = findNextToken();
  return assertCharEquals(t.val.symbol[0], 'a') && assertCharEquals(t.val.symbol[1], 'b') && assertCharEquals(t.val.symbol[2], 'c');
}

canonical_original_code:
_Bool should_lex_symbol_as_token_with_value() {
  handleChar('a');
  handleChar('b');
  handleChar('c');
  struct token t = findNextToken();
  return assertCharEquals(t.val.symbol[0], 'a') && assertCharEquals(t.val.symbol[1], 'b') && assertCharEquals(t.val.symbol[2], 'c');
}


decompiled_code:
__int64 test_lexer()
{
init();
test(should_lex_empty_as_empty, "should empty as empty token");
test(should_lex_space_char_as_empty, "should lex space char as empty token");
test(should_lex_left_paren_as_token, "should lex left paren as token");
test(should_lex_right_paren_as_token, "should lex right paren as token");
test(should_lex_integer_as_token, "should lex integer as token");
test(should_lex_integer_as_token_with_value, "should lex single integer as token with value");
test(should_lex_multi_digit_integer_as_token_with_value, "should lex single integer as token with value");
test(should_lex_integer_terminated_with_non_space_charater, "should lex integer terminated with non space character");
test(should_lex_char, "should lex char");
test(should_lex_symbol_as_token, "should lex symbol");
test(should_lex_symbol_as_token_with_value, "should lex symbol with value");
return 1LL;
}

canonical_decompiled_code:
__int64 func18()
{
func19();
func32(should_lex_empty_as_empty, "should empty as empty token");
func32(should_lex_space_char_as_empty, "should lex space char as empty token");
func32(should_lex_left_paren_as_token, "should lex left paren as token");
func32(should_lex_right_paren_as_token, "should lex right paren as token");
func32(should_lex_integer_as_token, "should lex integer as token");
func32(should_lex_integer_as_token_with_value, "should lex single integer as token with value");
func32(should_lex_multi_digit_integer_as_token_with_value, "should lex single integer as token with value");
func32(should_lex_integer_terminated_with_non_space_charater, "should lex integer terminated with non space character");
func32(should_lex_char, "should lex char");
func32(should_lex_symbol_as_token, "should lex symbol");
func32(should_lex_symbol_as_token_with_value, "should lex symbol with value");
return 1LL;
}

original_code:
_Bool test_lexer() {
  init();
  test(should_lex_empty_as_empty, "should empty as empty token");
  test(should_lex_space_char_as_empty, "should lex space char as empty token");
  test(should_lex_left_paren_as_token, "should lex left paren as token");
  test(should_lex_right_paren_as_token, "should lex right paren as token");
  test(should_lex_integer_as_token, "should lex integer as token");
  test(should_lex_integer_as_token_with_value, "should lex single integer as token with value");
  test(should_lex_multi_digit_integer_as_token_with_value, "should lex single integer as token with value");
  test(should_lex_integer_terminated_with_non_space_charater, "should lex integer terminated with non space character");
  test(should_lex_char, "should lex char");
  test(should_lex_symbol_as_token, "should lex symbol");
  test(should_lex_symbol_as_token_with_value, "should lex symbol with value");
  return 1;
}


init

decompiled_code:
void *init()
{
void *result; // rax

result = malloc(0x80uLL);
buffer = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func19()
{
void *result; // rax

result = malloc(0x80uLL);
buffer = (__int64)result;
return result;
}

original_code:
void init() {
  buffer = malloc(128 * sizeof(char));
}


handleChar

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

LODWORD(result) = bufferWritePosition++;
result = (int)result;
*(_BYTE *)(buffer + (int)result) = a1;
return result;
}

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

LODWORD(result) = bufferWritePosition++;
result = (int)result;
*(_BYTE *)(buffer + (int)result) = a1;
return result;
}

original_code:
void handleChar(char c) {
  buffer[bufferWritePosition++] = c;
}

variable_types: c char


isNul

decompiled_code:
_BOOL8 __fastcall isNul(char a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func21(char a1)
{
return a1 == 0;
}

original_code:
int isNul(char c) {
  return c == 0;
}

canonical_original_code:
int isNul(char c) {
  return c == 0;
}


isSingleQuote

decompiled_code:
_BOOL8 __fastcall isSingleQuote(char a1)
{
return a1 == 39;
}

canonical_decompiled_code:
_BOOL8 __fastcall func22(char a1)
{
return a1 == 39;
}

original_code:
int isSingleQuote(char c) {
  return c == '\'';
}


isOpenParen

decompiled_code:
_BOOL8 __fastcall isOpenParen(char a1)
{
return a1 == 40;
}

canonical_decompiled_code:
_BOOL8 __fastcall func23(char a1)
{
return a1 == 40;
}

original_code:
int isOpenParen(char c) {
  return c == '(';
}


isCloseParen

decompiled_code:
_BOOL8 __fastcall isCloseParen(char a1)
{
return a1 == 41;
}

canonical_decompiled_code:
_BOOL8 __fastcall func24(char a1)
{
return a1 == 41;
}

original_code:
int isCloseParen(char c) {
  return c == ')';
}


leftParen

decompiled_code:
__int64 leftParen()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func25()
{
return 1LL;
}

original_code:
Token leftParen() {
  Token t = {.type = LeftParen};
  return t;
}

canonical_original_code:
struct token leftParen() {
  struct token t = {.type = LeftParen};
  return t;
}

return_type: struct token { enum tokenType { Empty=0, LeftParen=1, RightParen=2, Integer=3, Symbol=4, Character=5 } type; union { int integer; int character; char symbol[7]; } val; }


rightParen

decompiled_code:
__int64 rightParen()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func26()
{
return 2LL;
}

original_code:
Token rightParen() {
  Token t = {.type = RightParen};
  return t;
}

canonical_original_code:
struct token rightParen() {
  struct token t = {.type = RightParen};
  return t;
}


integer

decompiled_code:
__int64 __fastcall integer(int a1)
{
__int64 v2; // [rsp+0h] [rbp-20h]

LODWORD(v2) = 3;
HIDWORD(v2) = a1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func27(int a1)
{
__int64 v2; // [rsp+0h] [rbp-20h]

LODWORD(v2) = 3;
HIDWORD(v2) = a1;
return v2;
}

original_code:
Token integer(int currentValue) {
  Token t = {.type = Integer, .val.integer = currentValue };
  return t;
}

canonical_original_code:
struct token integer(int currentValue) {
  struct token t = {.type = Integer, .val.integer = currentValue };
  return t;
}

variable_types: currentValue int


character

decompiled_code:
__int64 __fastcall character(char a1)
{
__int64 v2; // [rsp+0h] [rbp-20h]

LODWORD(v2) = 5;
HIDWORD(v2) = a1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func28(char a1)
{
__int64 v2; // [rsp+0h] [rbp-20h]

LODWORD(v2) = 5;
HIDWORD(v2) = a1;
return v2;
}

original_code:
Token character(char currentValue) {
  Token t = {.type = Character, .val.character = currentValue };
  return t;
}

canonical_original_code:
struct token character(char currentValue) {
  struct token t = {.type = Character, .val.character = currentValue };
  return t;
}

variable_types: currentValue char


symbol

decompiled_code:
__int64 __fastcall symbol(_DWORD *a1)
{
__int64 v2; // [rsp+0h] [rbp-20h]

HIDWORD(v2) = *a1;
LODWORD(v2) = 4;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func29(_DWORD *a1)
{
__int64 v2; // [rsp+0h] [rbp-20h]

HIDWORD(v2) = *a1;
LODWORD(v2) = 4;
return v2;
}

original_code:
Token symbol(char *currentSymbol) {
  Token t = {.type = Symbol};
  memcpy(t.val.symbol, currentSymbol, 7 * sizeof(char));
  return t;
}

canonical_original_code:
struct token symbol(char *currentSymbol) {
  struct token t = {.type = Symbol};
  memcpy(t.val.symbol, currentSymbol, 7 * sizeof(char));
  return t;
}

variable_types:
currentSymbol
char *


empty

decompiled_code:
__int64 empty()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func30()
{
return 0LL;
}

original_code:
Token empty() {
  Token t = {.type = Empty };
  return t;
}

canonical_original_code:
struct token empty() {
  struct token t = {.type = Empty };
  return t;
}


findNextToken

decompiled_code:
__int64 findNextToken()
{
int v0; // er14
__int64 v1; // r15
__int64 v2; // rbx
int v3; // er13
int v4; // edx
int v5; // edx
char v6; // bp
char v7; // r12
unsigned __int16 v8; // ax
int v9; // edx
int v10; // edx
int v11; // edx
int v12; // edx
int v14; // [rsp+0h] [rbp-78h]
__int16 v15; // [rsp+6h] [rbp-72h]
int v16; // [rsp+8h] [rbp-70h]
int v17; // [rsp+2Dh] [rbp-4Bh] BYREF
__int64 v18; // [rsp+34h] [rbp-44h]
int v19; // [rsp+3Ch] [rbp-3Ch]

v0 = bufferWritePosition;
if ( bufferReadPosition >= bufferWritePosition )
{
LABEL_33:
v18 = empty();
v19 = v12;
return v18;
}
v1 = buffer;
v2 = bufferReadPosition;
v16 = 0;
v14 = 0;
v3 = 0;
while ( 1 )
{
bufferReadPosition = v2 + 1;
v6 = *(_BYTE *)(v1 + v2);
v7 = 0;
if ( (int)v2 + 1 < v0 )
v7 = *(_BYTE *)(v1 + v2 + 1);
if ( !v3 )
break;
if ( v3 == 1 )
goto LABEL_10;
if ( v3 == 2 )
{
if ( isSingleQuote(v6) )
{
v18 = character(v14);
v19 = v10;
return v18;
}
v14 = v6;
goto LABEL_13;
}
LABEL_23:
if ( v3 == 3 )
goto LABEL_24;
LABEL_13:
if ( v0 <= (int)++v2 )
goto LABEL_33;
}
v8 = (*__ctype_b_loc())[v6];
v15 = v8;
if ( (v8 & 0x2000) != 0 )
goto LABEL_13;
if ( (v8 & 0x800) != 0 )
{
v14 = 0;
LABEL_10:
v14 = v6 + 10 * v14 - 48;
if ( isNul(v7) || ((*__ctype_b_loc())[v7] & 0x800) == 0 )
{
v18 = integer(v14);
v19 = v9;
return v18;
}
v3 = 1;
goto LABEL_13;
}
if ( isSingleQuote(v6) )
{
v14 = 0;
v3 = 2;
goto LABEL_13;
}
if ( isOpenParen(v6) )
{
v18 = leftParen();
v19 = v4;
return v18;
}
if ( isCloseParen(v6) )
{
v18 = rightParen();
v19 = v5;
return v18;
}
if ( v15 >= 0 )
goto LABEL_23;
LABEL_24:
*((_BYTE *)&v17 + v16) = v6;
if ( !isNul(v7) && !isOpenParen(v6) && !isCloseParen(v6) && ((*__ctype_b_loc())[v6] & 0x2000) == 0 )
{
++v16;
v3 = 3;
goto LABEL_13;
}
v18 = symbol(&v17);
v19 = v11;
return v18;
}

original_code:
Token findNextToken() {
  int currentlyLexing = Nothing;
  int currentValue = 0;
  int currentSymbolCharacter = 0;
  char currentSymbol[7];
  while(bufferReadPosition < bufferWritePosition) {
    char c = buffer[bufferReadPosition++];
    char la = 0;
    if(bufferReadPosition < bufferWritePosition) {
      la = buffer[bufferReadPosition];
    }
    if(currentlyLexing == Nothing) {
      if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
        continue;
      }
      else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
        currentValue = 0;
        currentlyLexing = AnInteger;
      }
      else if(isSingleQuote(c)) {
        currentValue = 0;
        currentlyLexing = ACharacter;
        continue;
      }
      else if(isOpenParen(c)) {
        return leftParen();
      }
      else if(isCloseParen(c)) {
        return rightParen();
      }
      else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISgraph)) {
        currentlyLexing = ASymbol;
      }
    }
    if(currentlyLexing == AnInteger) {
        currentValue = currentValue * 10;
        currentValue = currentValue + (c - '0');
      if(isNul(la) || !((*__ctype_b_loc ())[(int) ((la))] & (unsigned short int) _ISdigit)) {
        currentlyLexing = Nothing;
        return integer(currentValue);
      }
    }
    if(currentlyLexing == ACharacter) {
      if (isSingleQuote(c)) {
        return character(currentValue);
      } else {
        currentValue = c;
      }
    }
    if(currentlyLexing == ASymbol) {
      currentSymbol[currentSymbolCharacter++] = c;
      if(isNul(la) || isOpenParen(c) || isCloseParen(c) || ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
        return symbol(currentSymbol);
      }
    }
  }
  return empty();
}

canonical_original_code:
struct token findNextToken() {
  int currentlyLexing = Nothing;
  int currentValue = 0;
  int currentSymbolCharacter = 0;
  char currentSymbol[7];
  while(bufferReadPosition < bufferWritePosition) {
    char c = buffer[bufferReadPosition++];
    char la = 0;
    if(bufferReadPosition < bufferWritePosition) {
      la = buffer[bufferReadPosition];
    }
    if(currentlyLexing == Nothing) {
      if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
        continue;
      }
      else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
        currentValue = 0;
        currentlyLexing = AnInteger;
      }
      else if(isSingleQuote(c)) {
        currentValue = 0;
        currentlyLexing = ACharacter;
        continue;
      }
      else if(isOpenParen(c)) {
        return leftParen();
      }
      else if(isCloseParen(c)) {
        return rightParen();
      }
      else if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISgraph)) {
        currentlyLexing = ASymbol;
      }
    }
    if(currentlyLexing == AnInteger) {
        currentValue = currentValue * 10;
        currentValue = currentValue + (c - '0');
      if(isNul(la) || !((*__ctype_b_loc ())[(int) ((la))] & (unsigned short) _ISdigit)) {
        currentlyLexing = Nothing;
        return integer(currentValue);
      }
    }
    if(currentlyLexing == ACharacter) {
      if (isSingleQuote(c)) {
        return character(currentValue);
      } else {
        currentValue = c;
      }
    }
    if(currentlyLexing == ASymbol) {
      currentSymbol[currentSymbolCharacter++] = c;
      if(isNul(la) || isOpenParen(c) || isCloseParen(c) || ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
        return symbol(currentSymbol);
      }
    }
  }
  return empty();
}

variable_types: currentlyLexing int

variable_types: currentSymbolCharacter int

variable_types:
currentSymbol
char [7]

variable_types: la char


test

decompiled_code:
int __fastcall test(__int64 (*a1)(void), const char *a2)
{
int result; // eax

result = a1();
if ( !(_BYTE)result )
result = printf("FAIL: %s\r\n", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func32(__int64 (*a1)(void), const char *a2)
{
int result; // eax

result = a1();
if ( !(_BYTE)result )
result = printf("FAIL: %s\r\n", a2);
return result;
}

original_code:
void test(_Bool (*testFunc)(), char *testName) {
 if(!(*testFunc)()){
  printf("FAIL: %s\r\n", testName);
 }
}

variable_types:
testFunc
_Bool (*)()

variable_types:
testName
char *


assertCharEquals

decompiled_code:
__int64 __fastcall assertCharEquals(char a1, char a2)
{
__int64 result; // rax

result = 1LL;
if ( a1 != a2 )
{
printf("Expected '%c' but got '%c'\r\n", (unsigned int)a2, (unsigned int)a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func33(char a1, char a2)
{
__int64 result; // rax

result = 1LL;
if ( a1 != a2 )
{
printf("Expected '%c' but got '%c'\r\n", (unsigned int)a2, (unsigned int)a1);
result = 0LL;
}
return result;
}

original_code:
_Bool assertCharEquals(char value, char expected) {
  if(value != expected) {
    printf("Expected '%c' but got '%c'\r\n", expected, value);
    return 0;
  }
  return 1;
}

variable_types: value char

variable_types: expected char


assertIntegerEquals

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

result = 1LL;
if ( a1 != (_DWORD)a2 )
{
printf("Expected '%d' but got '%d'\r\n", a2, a1);
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( a1 != (_DWORD)a2 )
{
printf("Expected '%d' but got '%d'\r\n", a2, a1);
result = 0LL;
}
return result;
}

original_code:
_Bool assertIntegerEquals(int value, int expected) {
  if(value != expected) {
    printf("Expected '%d' but got '%d'\r\n", expected, value);
    return 0;
  }
  return 1;
}

variable_types: value int

variable_types: expected int


decompiled_code:
__int64 test_parser()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func35()
{
return 1LL;
}

original_code:
_Bool test_parser() {
  return 1;
}

canonical_original_code:
_Bool test_parser() {
  return 1;
}


repo: chrisbroome/chros

decompiled_code:
void gdt_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: void gdt_init() {}

canonical_original_code: void gdt_init() {}


decompiled_code:
void gdt_reinit()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code: void gdt_reinit() {}

canonical_original_code: void gdt_reinit() {}


decompiled_code:
__int64 __fastcall out_vid(__int64 a1, unsigned int a2)
{
return vga_out_line(a1, &c, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
return vga_out_line(a1, &c, a2);
}

original_code:
void out_vid( const char* msg, VGA_COLOR col )
{
  vga_out_line( msg, &_c, col );
}

canonical_original_code:
void out_vid(char *msg, enum VGA_COLOR col)
{
  vga_out_line( msg, &_c, col );
}

variable_types:
msg
char *

variable_types: enum VGA_COLOR { VGA_COLOR_FG_BLACK=0, VGA_COLOR_FG_BLUE=1, VGA_COLOR_FG_GREEN=2, VGA_COLOR_FG_CYAN=3, VGA_COLOR_FG_RED=4, VGA_COLOR_FG_MAGENTA=5, VGA_COLOR_FG_YELLOW=6, VGA_COLOR_FG_GRAY=7, VGA_COLOR_FG_INTENSE=8, VGA_COLOR_BG_BLACK=0, VGA_COLOR_BG_BLUE=16, VGA_COLOR_BG_GREEN=32, VGA_COLOR_BG_CYAN=48, VGA_COLOR_BG_RED=64, VGA_COLOR_BG_MAGENTA=80, VGA_COLOR_BG_YELLOW=96, VGA_COLOR_BG_GRAY=112, VGA_COLOR_BG_INTENSE=128, VGA_COLOR_DEFAULT=expr }


decompiled_code:
__int64 do_exit()
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 16; ++i )
result = out_vid((__int64)"exiting kernel", i);
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 16; ++i )
result = func0((__int64)"exiting kernel", i);
return result;
}

original_code:
void do_exit()
{
  for( uint8_t i=0; i < 16; ++i )
  {
    out_vid( "exiting kernel", i );
  }
}

canonical_original_code:
void do_exit()
{
  for( unsigned char i = 0; i < 16; ++i )
  {
    out_vid( "exiting kernel", i );
  }
}

variable_types:
i
unsigned char


decompiled_code:
__int64 kmain_init()
{
return cursor_init(&c);
}

canonical_decompiled_code:
__int64 func3()
{
return cursor_init(&c);
}

original_code:
void kmain_init()
{
  cursor_init( &_c );
}


decompiled_code:
__int64 __fastcall multiboot_check_flag(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(a1 + 4) & a2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(a1 + 4) & a2;
}

original_code:
int multiboot_check_flag( mb_header* x, MULTIBOOT_MAGIC_FLAG f )
{
  return ( x->magic.flags & f );
}

canonical_original_code:
int multiboot_check_flag(struct mb_header *x, enum MULTIBOOT_MAGIC_FLAG f)
{
  return ( x->magic.flags & f );
}

variable_types: struct mb_header { struct _mb_magic { unsigned int magic; unsigned int flags; unsigned int checksum; } magic; struct _mb_address { unsigned int header_addr; unsigned int load_addr; unsigned int load_end_addr; unsigned int bss_end_addr; unsigned int entry_addr; } address; struct _mb_graphics { unsigned int mode_type; unsigned int width; unsigned int height; unsigned int depth; } graphics; } *

variable_types: enum MULTIBOOT_MAGIC_FLAG { MULTIBOOT_MAGIC_FLAG_ALIGN=expr, MULTIBOOT_MAGIC_FLAG_MEMORY=expr, MULTIBOOT_MAGIC_FLAG_VIDEO_INFO=expr }

user_defined_types: struct mb_header { struct _mb_magic magic; struct _mb_address address; struct _mb_graphics graphics; }


repo: chrislipa/spider

original_code:
void find_sector_string()
{
 int i, sectr1, num_rays, sectr;
 double theta;
 theta = THETA = (double)num/(double)den;
 sectr1 = ((int)floor((double)d*THETA - THETA) + (int)d) % d;
 num_rays = Leading_Part[0]+Repeating_Part[0];
 sec_str[0] = ' ';
 sec_str[1] = ' ';
 for (i=1; i<=num_rays && i<127; ++i) {
  sectr = ((int)floor((double)d*theta - THETA) + (int)d) % d;
  sec_str[2*i] = '0' + sectr-sectr1;
  sec_str[2*i+1] = ',';
  if (i==Leading_Part[0]) sec_str[2*i+1] = ';';
  theta *= (double)d;
 }
 sec_str[2*i-1] = '\0';
}

canonical_original_code:
void find_sector_string()
{
 int i; int sectr1; int num_rays; int sectr;
 double theta;
 theta = THETA = (double)num/(double)den;
 sectr1 = ((int)floor((double)d*THETA - THETA) + (int)d) % d;
 num_rays = Leading_Part[0]+Repeating_Part[0];
 sec_str[0] = ' ';
 sec_str[1] = ' ';
 for (i=1; i<=num_rays && i<127; ++i) {
  sectr = ((int)floor((double)d*theta - THETA) + (int)d) % d;
  sec_str[2*i] = '0' + sectr-sectr1;
  sec_str[2*i+1] = ',';
  if (i==Leading_Part[0]) sec_str[2*i+1] = ';';
  theta *= (double)d;
 }
 sec_str[2*i-1] = '\0';
}

variable_types: i int

variable_types: sectr int

variable_types: theta double


repo: chrisoei/hashjson

decompiled_code:
void cko_types_test()
{
;
}

original_code:
void cko_types_test() {
  ((void) sizeof ((sizeof(cko_u8)==1) ? 1 : 0), __extension__ ({ if (sizeof(cko_u8)==1) ; else __assert_fail ("sizeof(cko_u8)==1", "cko_types.c", 5, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sizeof(cko_s8)==1) ? 1 : 0), __extension__ ({ if (sizeof(cko_s8)==1) ; else __assert_fail ("sizeof(cko_s8)==1", "cko_types.c", 6, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sizeof(cko_u16)==2) ? 1 : 0), __extension__ ({ if (sizeof(cko_u16)==2) ; else __assert_fail ("sizeof(cko_u16)==2", "cko_types.c", 7, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sizeof(cko_s16)==2) ? 1 : 0), __extension__ ({ if (sizeof(cko_s16)==2) ; else __assert_fail ("sizeof(cko_s16)==2", "cko_types.c", 8, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sizeof(cko_u32)==4) ? 1 : 0), __extension__ ({ if (sizeof(cko_u32)==4) ; else __assert_fail ("sizeof(cko_u32)==4", "cko_types.c", 9, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sizeof(cko_s32)==4) ? 1 : 0), __extension__ ({ if (sizeof(cko_s32)==4) ; else __assert_fail ("sizeof(cko_s32)==4", "cko_types.c", 10, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sizeof(cko_u64)==8) ? 1 : 0), __extension__ ({ if (sizeof(cko_u64)==8) ; else __assert_fail ("sizeof(cko_u64)==8", "cko_types.c", 11, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((sizeof(cko_s64)==8) ? 1 : 0), __extension__ ({ if (sizeof(cko_s64)==8) ; else __assert_fail ("sizeof(cko_s64)==8", "cko_types.c", 12, __extension__ __PRETTY_FUNCTION__); }));
}


repo: christetreault/dmp-photo-booth

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

if ( a1 )
{
status_handler = a1;
result = 0LL;
}
else
{
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 10LL, "dmp_tm_install_status_handler", "sh != NULL");
result = dmp_tm_show_error();
}
return result;
}

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

if ( a1 )
{
status_handler = a1;
result = 0LL;
}
else
{
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 10LL, "dmp_tm_install_status_handler", "sh != NULL");
result = func1();
}
return result;
}

original_code:
int dmp_tm_install_status_handler(void (*sh)(int status))
{
 do { if (sh != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_trigger_module.c", 10, ((const char*) (__func__)), "sh != NULL"); } while (0);
 status_handler = sh;
 return 0;
}

canonical_original_code:
int dmp_tm_install_status_handler(void (*sh)(int status))
{
 do { if (sh != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_trigger_module.c", 10, ((char *) (__func__)), "sh != NULL"); } while (0);
 status_handler = sh;
 return 0;
}

variable_types:
sh
void (*)(int status)


decompiled_code:
__int64 __fastcall dmp_tm_show_error(char a1)
{
dmp_tm_io_write_byte((unsigned int)(char)(a1 | 0x80));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
dmp_tm_io_write_byte((unsigned int)(char)(a1 | 0x80));
return 0LL;
}

original_code:
int dmp_tm_show_error(int value)
{
 dmp_tm_io_write_byte(value | IS_ERROR);
 return 0;
}


decompiled_code:
__int64 __fastcall dmp_tm_install_console(__int64 a1)
{
if ( !a1 )
return 1LL;
console_write = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
return 1LL;
console_write = a1;
return 0LL;
}

original_code:
int dmp_tm_install_console(int (*c_cb)(const char * message))
{
 if (c_cb == ((void *)0)) return 1;
 console_write = c_cb;
 return 0;
}

canonical_original_code:
int dmp_tm_install_console(int (*c_cb)(char *message))
{
 if (c_cb == ((void *)0)) return 1;
 console_write = c_cb;
 return 0;
}


decompiled_code:
__int64 __fastcall dmp_tm_add_trigger_handler(__int64 a1)
{
if ( !a1 )
return 1LL;
trigger_handler = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !a1 )
return 1LL;
trigger_handler = a1;
return 0LL;
}

original_code:
int dmp_tm_add_trigger_handler(void (*th)(void))
{
 if (th == ((void *)0)) return 1;
 trigger_handler = th;
 return 0;
}

canonical_original_code:
int dmp_tm_add_trigger_handler(void (*th)())
{
 if (th == ((void *)0)) return 1;
 trigger_handler = th;
 return 0;
}

variable_types:
th
void (*)()


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

if ( !trigger_handler )
return 1LL;
switch ( a1 )
{
case 0u:
dmp_tm_io_write_byte(1LL);
result = a1;
break;
case 1u:
dmp_tm_io_write_byte(2LL);
result = 0LL;
break;
case 2u:
dmp_tm_io_write_byte(4LL);
result = 0LL;
break;
case 3u:
dmp_tm_io_write_byte(8LL);
result = 0LL;
break;
default:
dmp_tm_io_write_byte(16LL);
result = 0LL;
break;
}
return result;
}

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

if ( !trigger_handler )
return 1LL;
switch ( a1 )
{
case 0u:
dmp_tm_io_write_byte(1LL);
result = a1;
break;
case 1u:
dmp_tm_io_write_byte(2LL);
result = 0LL;
break;
case 2u:
dmp_tm_io_write_byte(4LL);
result = 0LL;
break;
case 3u:
dmp_tm_io_write_byte(8LL);
result = 0LL;
break;
default:
dmp_tm_io_write_byte(16LL);
result = 0LL;
break;
}
return result;
}

original_code:
int dmp_tm_set_countdown(int current)
{
 if (trigger_handler == ((void *)0)) return 1;
 switch (current)
 {
  case 4:
   dmp_tm_io_write_byte(INPUT_COUNT_4);
   break;
  case 3:
   dmp_tm_io_write_byte(INPUT_COUNT_3);
   break;
  case 2:
   dmp_tm_io_write_byte(INPUT_COUNT_2);
   break;
  case 1:
   dmp_tm_io_write_byte(INPUT_COUNT_1);
   break;
  case 0:
   dmp_tm_io_write_byte(INPUT_COUNT_0);
   break;
  default:
   dmp_tm_io_write_byte(INPUT_COUNT_4);
   break;
 }
 return 0;
}

variable_types: current int


decompiled_code:
__int64 dmp_tm_initialize()
{
dmp_tm_config_init();
return dmp_tm_lifecycle_initialize();
}

canonical_decompiled_code:
__int64 func5()
{
dmp_tm_config_init();
return dmp_tm_lifecycle_initialize();
}

original_code:
int dmp_tm_initialize(void)
{
 dmp_tm_config_init();
 return dmp_tm_lifecycle_initialize();
}

canonical_original_code:
int dmp_tm_initialize()
{
 dmp_tm_config_init();
 return dmp_tm_lifecycle_initialize();
}


decompiled_code:
__int64 dmp_tm_finalize()
{
dmp_tm_config_finalize();
return dmp_tm_lifecycle_finalize();
}

canonical_decompiled_code:
__int64 func6()
{
dmp_tm_config_finalize();
return dmp_tm_lifecycle_finalize();
}

original_code:
int dmp_tm_finalize(void)
{
 dmp_tm_config_finalize();
 return dmp_tm_lifecycle_finalize();
}

canonical_original_code:
int dmp_tm_finalize()
{
 dmp_tm_config_finalize();
 return dmp_tm_lifecycle_finalize();
}