scramAzZatoRaDec

original_code:
void scramAzZatoRaDec(long int AGC_SysTime, long int AGC_Time, double AGC_Az, double AGC_Za, double AlfaMotorPosition, int Beam, int DoNotPrecess, double * ra, double * dec, struct tm * hittime) {
static const double AST_TO_UTC_HOURS=4;
static const double D2R=(3.1415926535897932384626/180.0);
long timeMs = AGC_Time;
time_t now = AGC_SysTime;
double secs_past_midnight, encoder_read_secs_past_midnight,fnow;
struct tm * now_tm;
fnow=now;
fnow-=AST_TO_UTC_HOURS*3600;
now=(time_t)floor(fnow);
now_tm = gmtime(&now);
*hittime = *now_tm;
secs_past_midnight = now_tm->tm_hour*3600 + now_tm->tm_min*60 + now_tm->tm_sec;
encoder_read_secs_past_midnight = (timeMs * 0.001);
fnow -= secs_past_midnight;
fnow += encoder_read_secs_past_midnight;
fnow += AST_TO_UTC_HOURS*3600;
double coord_unixtime = fnow;
double zen_corr_coeff[13] = {-57.55,-95.56,-4.13,141.69,677.51,-10.41,-7.71,-10.39,0.08,0.43,-0.62, 0.03,-0.36};
double az_corr_coeff[13] = {-37,-6.05,92.35,-731.21,-1013.97,-24.53,-11.19,9.18,106.04,3.02,-1.74,-3.46,1.29};
double array_angle[7] = {0.0, 120.0, 180.0, -120.0, -60.0, 0.0, 60.0};
double Za = AGC_Za;
double Az = AGC_Az;
double Rotation = AlfaMotorPosition;
double CosAz, SinAz, SinZen, Cos2Az, Sin2Az, Cos3Az, Sin3Az, Cos6Az, Sin6Az, SinZen2, Cos3Imb, Sin3Imb, AzRadians, ZenRadians, ZenCorrection, AzCorrection;
AzRadians = Az * D2R;
ZenRadians = Za * D2R;
CosAz = cos(AzRadians);
SinAz = sin(AzRadians);
Cos2Az = cos(2.0 * AzRadians);
Sin2Az = sin(2.0 * AzRadians);
Cos3Az = cos(3.0 * AzRadians);
Sin3Az = sin(3.0 * AzRadians);
Cos6Az = cos(6.0 * AzRadians);
Sin6Az = sin(6.0 * AzRadians);
SinZen = sin(ZenRadians);
SinZen2 = SinZen * SinZen;
Cos3Imb = sin(ZenRadians - 0.1596997627) * Cos3Az;
Sin3Imb = sin(ZenRadians - 0.1596997627) * Sin3Az;
ZenCorrection = zen_corr_coeff[ 0] + zen_corr_coeff[ 1] * CosAz + zen_corr_coeff[ 2] * SinAz + zen_corr_coeff[ 3] * SinZen + zen_corr_coeff[ 4] * SinZen2 + zen_corr_coeff[ 5] * Cos3Az + zen_corr_coeff[ 6] * Sin3Az + zen_corr_coeff[ 7] * Cos3Imb + zen_corr_coeff[ 8] * Sin3Imb + zen_corr_coeff[ 9] * Cos2Az + zen_corr_coeff[10] * Sin2Az + zen_corr_coeff[11] * Cos6Az + zen_corr_coeff[12] * Sin6Az;
AzCorrection = az_corr_coeff[ 0] + az_corr_coeff[ 1] * CosAz + az_corr_coeff[ 2] * SinAz + az_corr_coeff[ 3] * SinZen + az_corr_coeff[ 4] * SinZen2 + az_corr_coeff[ 5] * Cos3Az + az_corr_coeff[ 6] * Sin3Az + az_corr_coeff[ 7] * Cos3Imb + az_corr_coeff[ 8] * Sin3Imb + az_corr_coeff[ 9] * Cos2Az + az_corr_coeff[10] * Sin2Az + az_corr_coeff[11] * Cos6Az + az_corr_coeff[12] * Sin6Az;
  double array_az_ellipse;
  double array_za_ellipse;
  if(Beam != 0) {
   array_az_ellipse = 329.06;
   array_za_ellipse = 384.005;
   } else {
   array_az_ellipse = 0;
   array_za_ellipse = 0;
   }
  double posrot=(array_angle[Beam] - Rotation)*D2R;
  AzCorrection+=array_az_ellipse*cos(posrot);
  ZenCorrection+=array_za_ellipse*sin(posrot);
  Za -= ZenCorrection / 3600.0;
  Az -= (AzCorrection / 3600.0) / sin(Za * D2R);
  Az += 180.0;
  if(Za < 0.0)
    {
    Za = 0.0 - Za;
    Az += 180.0;
    }
  Az = wrap(Az, 0, 360, 1);
seti_AzZaToRaDec(Az, Za, coord_unixtime, ra, dec, DoNotPrecess);
}

canonical_original_code:
void scramAzZatoRaDec(long AGC_SysTime, long AGC_Time, double AGC_Az, double AGC_Za, double AlfaMotorPosition, int Beam, int DoNotPrecess, double *ra, double *dec, struct tm *hittime) {
static double AST_TO_UTC_HOURS = 4;
static double D2R = (3.1415926535897932384626/180.0);
long timeMs = AGC_Time;
long now = AGC_SysTime;
double secs_past_midnight; double encoder_read_secs_past_midnight; double fnow;
struct tm *now_tm;
fnow=now;
fnow-=AST_TO_UTC_HOURS*3600;
now=(long)floor(fnow);
now_tm = gmtime(&now);
*hittime = *now_tm;
secs_past_midnight = now_tm->tm_hour*3600 + now_tm->tm_min*60 + now_tm->tm_sec;
encoder_read_secs_past_midnight = (timeMs * 0.001);
fnow -= secs_past_midnight;
fnow += encoder_read_secs_past_midnight;
fnow += AST_TO_UTC_HOURS*3600;
double coord_unixtime = fnow;
double zen_corr_coeff[13] = {-57.55,-95.56,-4.13,141.69,677.51,-10.41,-7.71,-10.39,0.08,0.43,-0.62, 0.03,-0.36};
double az_corr_coeff[13] = {-37,-6.05,92.35,-731.21,-1013.97,-24.53,-11.19,9.18,106.04,3.02,-1.74,-3.46,1.29};
double array_angle[7] = {0.0, 120.0, 180.0, -120.0, -60.0, 0.0, 60.0};
double Za = AGC_Za;
double Az = AGC_Az;
double Rotation = AlfaMotorPosition;
double CosAz; double SinAz; double SinZen; double Cos2Az; double Sin2Az; double Cos3Az; double Sin3Az; double Cos6Az; double Sin6Az; double SinZen2; double Cos3Imb; double Sin3Imb; double AzRadians; double ZenRadians; double ZenCorrection; double AzCorrection;
AzRadians = Az * D2R;
ZenRadians = Za * D2R;
CosAz = cos(AzRadians);
SinAz = sin(AzRadians);
Cos2Az = cos(2.0 * AzRadians);
Sin2Az = sin(2.0 * AzRadians);
Cos3Az = cos(3.0 * AzRadians);
Sin3Az = sin(3.0 * AzRadians);
Cos6Az = cos(6.0 * AzRadians);
Sin6Az = sin(6.0 * AzRadians);
SinZen = sin(ZenRadians);
SinZen2 = SinZen * SinZen;
Cos3Imb = sin(ZenRadians - 0.1596997627) * Cos3Az;
Sin3Imb = sin(ZenRadians - 0.1596997627) * Sin3Az;
ZenCorrection = zen_corr_coeff[ 0] + zen_corr_coeff[ 1] * CosAz + zen_corr_coeff[ 2] * SinAz + zen_corr_coeff[ 3] * SinZen + zen_corr_coeff[ 4] * SinZen2 + zen_corr_coeff[ 5] * Cos3Az + zen_corr_coeff[ 6] * Sin3Az + zen_corr_coeff[ 7] * Cos3Imb + zen_corr_coeff[ 8] * Sin3Imb + zen_corr_coeff[ 9] * Cos2Az + zen_corr_coeff[10] * Sin2Az + zen_corr_coeff[11] * Cos6Az + zen_corr_coeff[12] * Sin6Az;
AzCorrection = az_corr_coeff[ 0] + az_corr_coeff[ 1] * CosAz + az_corr_coeff[ 2] * SinAz + az_corr_coeff[ 3] * SinZen + az_corr_coeff[ 4] * SinZen2 + az_corr_coeff[ 5] * Cos3Az + az_corr_coeff[ 6] * Sin3Az + az_corr_coeff[ 7] * Cos3Imb + az_corr_coeff[ 8] * Sin3Imb + az_corr_coeff[ 9] * Cos2Az + az_corr_coeff[10] * Sin2Az + az_corr_coeff[11] * Cos6Az + az_corr_coeff[12] * Sin6Az;
  double array_az_ellipse;
  double array_za_ellipse;
  if(Beam != 0) {
   array_az_ellipse = 329.06;
   array_za_ellipse = 384.005;
   } else {
   array_az_ellipse = 0;
   array_za_ellipse = 0;
   }
  double posrot = (array_angle[Beam] - Rotation)*D2R;
  AzCorrection+=array_az_ellipse*cos(posrot);
  ZenCorrection+=array_za_ellipse*sin(posrot);
  Za -= ZenCorrection / 3600.0;
  Az -= (AzCorrection / 3600.0) / sin(Za * D2R);
  Az += 180.0;
  if(Za < 0.0)
    {
    Za = 0.0 - Za;
    Az += 180.0;
    }
  Az = wrap(Az, 0, 360, 1);
seti_AzZaToRaDec(Az, Za, coord_unixtime, ra, dec, DoNotPrecess);
}

variable_types: AlfaMotorPosition double

variable_types: Beam int

variable_types:
ra
double *

variable_types:
dec
double *

variable_types: timeMs long

variable_types: now long

variable_types: fnow double

variable_types: Rotation double

variable_types: CosAz double

variable_types: SinAz double

variable_types: SinZen double

variable_types: AzRadians double

variable_types: ZenRadians double

variable_types: ZenCorrection double

variable_types: AzCorrection double

variable_types: posrot double

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


repo: UCBerkeleySETI/aocoord

decompiled_code:
__int64 __fastcall rotationY_M(int a1, __int64 *a2, double a3)
{
double v3; // xmm0_8
__int64 v4; // xmm1_8
double v5; // xmm2_8
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a3, sinx, (double *)&v7);
v3 = sinx[0];
v4 = v7;
*(_QWORD *)&v5 = *(_QWORD *)&sinx[0] ^ LC0;
if ( !a1 )
{
*(_QWORD *)&v3 = *(_QWORD *)&sinx[0] ^ LC0;
v5 = sinx[0];
}
result = LC2;
a2[1] = 0LL;
a2[3] = 0LL;
a2[4] = LC2;
a2[5] = 0LL;
a2[7] = 0LL;
*a2 = v4;
*((double *)a2 + 2) = v5;
*((double *)a2 + 6) = v3;
a2[8] = v4;
return result;
}

original_code:
void rotationY_M
        (
          double thetaRd,
          int rightHanded,
          double* pm
        )
{
        double costh,sinth;
        costh=cos(thetaRd);
        sinth=sin(thetaRd);
        sinth=(rightHanded)?sinth:-sinth;
        pm[0]=costh;
        pm[1]=0.;
        pm[2]=-sinth;
        pm[3]=0.;
        pm[4]=1.;
        pm[5]=0.;
        pm[6]=sinth;
        pm[7]=0.;
        pm[8]=costh;
        return;
}

canonical_original_code:
void rotationY_M(double thetaRd, int rightHanded, double *pm)
{
        double costh; double sinth;
        costh=cos(thetaRd);
        sinth=sin(thetaRd);
        sinth=(rightHanded)?sinth:-sinth;
        pm[0]=costh;
        pm[1]=0.;
        pm[2]=-sinth;
        pm[3]=0.;
        pm[4]=1.;
        pm[5]=0.;
        pm[6]=sinth;
        pm[7]=0.;
        pm[8]=costh;
        return;
}

variable_types: thetaRd double

variable_types: rightHanded int

variable_types:
pm
double *

variable_types: costh double

variable_types: sinth double

return_type: void


fmtRdToDms

decompiled_code:
__int64 __fastcall fmtRdToDms(unsigned int a1, __int64 a2)
{
unsigned int v3; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v4; // [rsp+10h] [rbp-28h] BYREF
unsigned int v5; // [rsp+14h] [rbp-24h] BYREF
double v6[4]; // [rsp+18h] [rbp-20h] BYREF

rad_dms3(&v5, &v3, &v4, v6);
return fmtDms(v5, v3, v4, a1, a2, v6[0]);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
unsigned int v3; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v4; // [rsp+10h] [rbp-28h] BYREF
unsigned int v5; // [rsp+14h] [rbp-24h] BYREF
double v6[4]; // [rsp+18h] [rbp-20h] BYREF

rad_dms3(&v5, &v3, &v4, v6);
return fmtDms(v5, v3, v4, a1, a2, v6[0]);
}

original_code:
void fmtRdToDms
        (
         double dmsRd,
         int secFracDig,
         char *cformatted
        )
{
        int deg,min;
        double sec;
        int sgn;
        rad_dms3(dmsRd,&sgn,&deg,&min,&sec);
        fmtDms(sgn,deg,min,sec,secFracDig,cformatted);
        return;
}

canonical_original_code:
void fmtRdToDms(double dmsRd, int secFracDig, char *cformatted)
{
        int deg; int min;
        double sec;
        int sgn;
        rad_dms3(dmsRd,&sgn,&deg,&min,&sec);
        fmtDms(sgn,deg,min,sec,secFracDig,cformatted);
        return;
}

variable_types: dmsRd double

variable_types: secFracDig int

variable_types:
cformatted
char *

variable_types: deg int

variable_types: min int

variable_types: sec double

variable_types: sgn int


fmtHmsD

original_code:
void fmtHmsD
        (
         int sgn,
         int hour,
         int min,
         double sec,
         int secFracDig,
         char *cformatted
        )
{
        char c;
        double mval;
        if (secFracDig > 0){
          mval=pow(10.,(double)(-secFracDig))*.5;
        }
        else {
           mval=.5;
        }
        if ((mval+sec)>=60.){
            sec=sec-60. + mval;
            min+=1;
            if (min >=60){
               min-=60;
               hour+=1;
            }
        }
        c=(sgn<0)?'-':' ';
        sprintf(cformatted,"%c%02d:%02d:%0*.*f",c,hour,min,
                ((secFracDig>0)?3+secFracDig:2),secFracDig,sec);
 return;
}

canonical_original_code:
void fmtHmsD(int sgn, int hour, int min, double sec, int secFracDig, char *cformatted)
{
        char c;
        double mval;
        if (secFracDig > 0){
          mval=pow(10.,(double)(-secFracDig))*.5;
        }
        else {
           mval=.5;
        }
        if ((mval+sec)>=60.){
            sec=sec-60. + mval;
            min+=1;
            if (min >=60){
               min-=60;
               hour+=1;
            }
        }
        c=(sgn<0)?'-':' ';
        sprintf(cformatted,"%c%02d:%02d:%0*.*f",c,hour,min,
                ((secFracDig>0)?3+secFracDig:2),secFracDig,sec);
 return;
}

variable_types: hour int

variable_types: c char

variable_types: mval double


variable_types: ih int

variable_types: im int

variable_types: s double

return_type: double


gregToMjd

decompiled_code:
__int64 __fastcall gregToMjd(__int64 a1, __int64 a2, int a3)
{
int v4; // eax

v4 = dmToDayNo() + (int)((double)(a3 - 1) * 365.25);
if ( a3 > 1900 )
return (unsigned int)(v4 - 678591);
if ( a3 > 1800 )
return (unsigned int)(v4 - 678590);
if ( a3 > 1700 )
return (unsigned int)(v4 - 678589);
return (unsigned int)(v4 - 678588);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
int v4; // eax

v4 = dmToDayNo() + (int)((double)(a3 - 1) * 365.25);
if ( a3 > 1900 )
return (unsigned int)(v4 - 678591);
if ( a3 > 1800 )
return (unsigned int)(v4 - 678590);
if ( a3 > 1700 )
return (unsigned int)(v4 - 678589);
return (unsigned int)(v4 - 678588);
}

original_code:
int gregToMjd
        (
        int day,
        int month,
        int year
        )
{
 int ival;
 ival=( (int)((year-1)*365.25) + dmToDayNo(day,month,year)
                + -678956 + 365);
 if (year <= 1900)ival++;
 if (year <= 1800)ival++;
 if (year <= 1700)ival++;
 return(ival);
}

canonical_original_code:
int gregToMjd(int day, int month, int year)
{
 int ival;
 ival=( (int)((year-1)*365.25) + dmToDayNo(day,month,year)
                + -678956 + 365);
 if (year <= 1900)ival++;
 if (year <= 1800)ival++;
 if (year <= 1700)ival++;
 return(ival);
}

variable_types: day int

variable_types: month int

variable_types: year int

variable_types: ival int

return_type: int


decompiled_code:
__int64 __fastcall rad_dms3(int *a1, int *a2, _DWORD *a3, double *a4, double a5)
{
int v5; // eax
double v8; // xmm0_8
int v9; // eax
__int64 result; // rax
double v11; // [rsp+0h] [rbp-20h]

v5 = 1;
v8 = a5 * 57.29577951308232;
if ( v8 < 0.0 )
{
*(_QWORD *)&v8 ^= LC2;
v5 = -1;
}
*a1 = v5;
v9 = truncDtoI();
*a2 = v9;
v11 = (v8 - (double)v9) * 60.0;
result = truncDtoI();
*a3 = result;
*a4 = (v11 - (double)(int)result) * 60.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int *a2, _DWORD *a3, double *a4, double a5)
{
int v5; // eax
double v8; // xmm0_8
int v9; // eax
__int64 result; // rax
double v11; // [rsp+0h] [rbp-20h]

v5 = 1;
v8 = a5 * 57.29577951308232;
if ( v8 < 0.0 )
{
*(_QWORD *)&v8 ^= LC2;
v5 = -1;
}
*a1 = v5;
v9 = truncDtoI();
*a2 = v9;
v11 = (v8 - (double)v9) * 60.0;
result = truncDtoI();
*a3 = result;
*a4 = (v11 - (double)(int)result) * 60.0;
return result;
}

original_code:
void rad_dms3
 (
  double rad,
  int *sgn,
  int *dd,
  int *mm,
  double *ss
 )
{
        double xm,xd;
        xd=rad*57.29577951308232087720;
        *sgn= xd < 0. ? -1:1;
        xd *= (*sgn);
        *dd = truncDtoI(xd);
        xm = (xd - (*dd))*60.;
        *mm = truncDtoI(xm);
        *ss= (xm - (*mm))*60.;
        return;
}

canonical_original_code:
void rad_dms3(double rad, int *sgn, int *dd, int *mm, double *ss)
{
        double xm; double xd;
        xd=rad*57.29577951308232087720;
        *sgn= xd < 0. ? -1:1;
        xd *= (*sgn);
        *dd = truncDtoI(xd);
        xm = (xd - (*dd))*60.;
        *mm = truncDtoI(xm);
        *ss= (xm - (*mm))*60.;
        return;
}

variable_types: rad double

variable_types:
sgn
int *

variable_types:
dd
int *

variable_types:
mm
int *

variable_types:
ss
double *

variable_types: xm double

variable_types: xd double


original_code:
void vec3ToAngles
        (
          double* pvec3,
          int c1Pos,
          double* pc1,
          double* pc2
        )
{
        double c1Rad;
        c1Rad=atan2(pvec3[1],pvec3[0]);
        if (c1Pos && (c1Rad < 0.)){
           c1Rad = c1Rad+6.28318530717958647692;
        }
        *pc1=c1Rad;
        *pc2=asin(pvec3[2]);
        return;
}

canonical_original_code:
void vec3ToAngles(double *pvec3, int c1Pos, double *pc1, double *pc2)
{
        double c1Rad;
        c1Rad=atan2(pvec3[1],pvec3[0]);
        if (c1Pos && (c1Rad < 0.)){
           c1Rad = c1Rad+6.28318530717958647692;
        }
        *pc1=c1Rad;
        *pc2=asin(pvec3[2]);
        return;
}


decompiled_code:
// attributes: thunk
__int64 azElToHa_V()
{
return haToAzEl_V();
}

canonical_decompiled_code:
__int64 func0()
{
return haToAzEl_V();
}

original_code:
void azElToHa_V
        (
         double* pazEl,
         double latitude,
         double* phaDec
        )
{
        haToAzEl_V(pazEl,latitude,phaDec);
        return;
}

canonical_original_code:
void azElToHa_V(double *pazEl, double latitude, double *phaDec)
{
        haToAzEl_V(pazEl,latitude,phaDec);
        return;
}

variable_types:
pazEl
double *

variable_types: latitude double

variable_types:
phaDec
double *


dmToDayNo

decompiled_code:
__int64 __fastcall dmToDayNo(int a1, int a2, unsigned int a3)
{
int v3; // ebx

if ( a2 > 12 )
a2 = 12;
v3 = 1;
if ( a2 > 0 )
v3 = a2;
if ( (unsigned int)isLeapYear(a3) )
v3 += 13;
return (unsigned int)(a1 + dayNoDat_0[v3]);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, unsigned int a3)
{
int v3; // ebx

if ( a2 > 12 )
a2 = 12;
v3 = 1;
if ( a2 > 0 )
v3 = a2;
if ( (unsigned int)isLeapYear(a3) )
v3 += 13;
return (unsigned int)(a1 + dayNoDat_0[v3]);
}

variable_types: mon int

variable_types:
dayNoDat
int [26]

variable_types: index int


fmtDms

original_code:
void fmtDms
        (
         int sgn,
         int deg,
         int min,
         double sec,
         int secFracDig,
         char *cformatted
        )
{
        char c;
        double mval;
        if (secFracDig > 0){
          mval=pow(10.,(double)(-secFracDig))*.5;
        }
        else {
           mval=.5;
        }
        if ((mval+sec)>=60.){
            sec=sec-60. + mval;
            min+=1;
            if (min >=60){
               min-=60;
               deg+=1;
            }
        }
        c=(sgn<0)?'-':' ';
        sprintf(cformatted,"%c%3d:%02d:%0*.*f",c,deg,min,
                ((secFracDig>0)?3+secFracDig:2),secFracDig,sec);
 return;
}

canonical_original_code:
void fmtDms(int sgn, int deg, int min, double sec, int secFracDig, char *cformatted)
{
        char c;
        double mval;
        if (secFracDig > 0){
          mval=pow(10.,(double)(-secFracDig))*.5;
        }
        else {
           mval=.5;
        }
        if ((mval+sec)>=60.){
            sec=sec-60. + mval;
            min+=1;
            if (min >=60){
               min-=60;
               deg+=1;
            }
        }
        c=(sgn<0)?'-':' ';
        sprintf(cformatted,"%c%3d:%02d:%0*.*f",c,deg,min,
                ((secFracDig>0)?3+secFracDig:2),secFracDig,sec);
 return;
}

variable_types: sgn int

variable_types: deg int

variable_types: min int

variable_types: sec double

variable_types: secFracDig int

variable_types:
cformatted
char *

variable_types: c char

variable_types: mval double


decompiled_code:
__int64 __fastcall secMid_hms3(int *a1, int *a2, double *a3, double a4)
{
__int64 result; // rax

*a1 = (int)a4 % 86400 / 3600;
*a2 = (int)a4 % 86400 % 3600 / 60;
result = (unsigned int)((int)a4 % 86400 % 60);
*a3 = a4 - (double)(int)a4 + (double)(int)result;
return result;
}

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

*a1 = (int)a4 % 86400 / 3600;
*a2 = (int)a4 % 86400 % 3600 / 60;
result = (unsigned int)((int)a4 % 86400 % 60);
*a3 = a4 - (double)(int)a4 + (double)(int)result;
return result;
}

original_code:
void secMid_hms3
 (
   double secs,
   int *hh,
   int *mm,
   double *ss
 )
{
 int isecs;
 double frac;
   isecs=secs;
   frac=secs-isecs;
   isecs=isecs%86400;
   *hh=isecs/3600;
   *mm= (isecs -((*hh) * 3600))/60;
   *ss=(isecs%60) + frac;
   return;
}

canonical_original_code:
void secMid_hms3(double secs, int *hh, int *mm, double *ss)
{
 int isecs;
 double frac;
   isecs=secs;
   frac=secs-isecs;
   isecs=isecs%86400;
   *hh=isecs/3600;
   *mm= (isecs -((*hh) * 3600))/60;
   *ss=(isecs%60) + frac;
   return;
}

variable_types: secs double

variable_types:
hh
int *

variable_types:
mm
int *

variable_types:
ss
double *

variable_types: isecs int

variable_types: frac double


fmtSMToHmsD

decompiled_code:
__int64 __fastcall fmtSMToHmsD(unsigned int a1, __int64 a2)
{
unsigned int v3; // [rsp+0h] [rbp-28h] BYREF
unsigned int v4; // [rsp+4h] [rbp-24h] BYREF
double v5[4]; // [rsp+8h] [rbp-20h] BYREF

secMid_hms3(&v3, &v4, v5);
return fmtHmsD(1LL, v3, v4, a1, a2, v5[0]);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
unsigned int v3; // [rsp+0h] [rbp-28h] BYREF
unsigned int v4; // [rsp+4h] [rbp-24h] BYREF
double v5[4]; // [rsp+8h] [rbp-20h] BYREF

secMid_hms3(&v3, &v4, v5);
return fmtHmsD(1LL, v3, v4, a1, a2, v5[0]);
}

original_code:
void fmtSMToHmsD
 (
   double secMidnite,
  int secFracDig,
        char *cformatted
    )
{
 int hour,min;
 double sec;
 secMid_hms3(secMidnite,&hour,&min,&sec);
 fmtHmsD(1,hour,min,sec,secFracDig,cformatted);
    return;
}

canonical_original_code:
void fmtSMToHmsD(double secMidnite, int secFracDig, char *cformatted)
{
 int hour; int min;
 double sec;
 secMid_hms3(secMidnite,&hour,&min,&sec);
 fmtHmsD(1,hour,min,sec,secFracDig,cformatted);
    return;
}

variable_types: secMidnite double

variable_types: hour int


decompiled_code:
__int64 __fastcall rad_hms3(int *a1, int *a2, _DWORD *a3, double *a4, double a5)
{
int v5; // eax
double v8; // xmm0_8
int v9; // eax
__int64 result; // rax
double v11; // [rsp+0h] [rbp-20h]

v5 = 1;
v8 = a5 * 3.819718634205488;
if ( v8 < 0.0 )
{
*(_QWORD *)&v8 ^= LC2;
v5 = -1;
}
*a1 = v5;
v9 = truncDtoI();
*a2 = v9;
v11 = (v8 - (double)v9) * 60.0;
result = truncDtoI();
*a3 = result;
*a4 = (v11 - (double)(int)result) * 60.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int *a2, _DWORD *a3, double *a4, double a5)
{
int v5; // eax
double v8; // xmm0_8
int v9; // eax
__int64 result; // rax
double v11; // [rsp+0h] [rbp-20h]

v5 = 1;
v8 = a5 * 3.819718634205488;
if ( v8 < 0.0 )
{
*(_QWORD *)&v8 ^= LC2;
v5 = -1;
}
*a1 = v5;
v9 = truncDtoI();
*a2 = v9;
v11 = (v8 - (double)v9) * 60.0;
result = truncDtoI();
*a3 = result;
*a4 = (v11 - (double)(int)result) * 60.0;
return result;
}

original_code:
void rad_hms3
 (
  double rad,
         int *sgn,
         int *hh,
         int *mm,
         double *ss
 )
{
        double xh,xm;
        xh=rad*3.81971863420548807255e+00;
        *sgn= xh < 0. ? -1:1;
        xh *= (*sgn);
        *hh = truncDtoI(xh);
        xm = (xh - (*hh))*60.;
        *mm = truncDtoI(xm);
        *ss= (xm - (*mm))*60.;
        return;
}

canonical_original_code:
void rad_hms3(double rad, int *sgn, int *hh, int *mm, double *ss)
{
        double xh; double xm;
        xh=rad*3.81971863420548807255e+00;
        *sgn= xh < 0. ? -1:1;
        xh *= (*sgn);
        *hh = truncDtoI(xh);
        xm = (xh - (*hh))*60.;
        *mm = truncDtoI(xm);
        *ss= (xm - (*mm))*60.;
        return;
}

variable_types: rad double

variable_types:
sgn
int *

variable_types: xh double

variable_types: xm double


setSign

decompiled_code:
__int64 __fastcall setSign(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
if ( (int)result < 0 )
{
*a2 = -1;
*a1 = -*a1;
}
else
{
*a2 = 1;
}
return result;
}

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

result = (unsigned int)*a1;
if ( (int)result < 0 )
{
*a2 = -1;
*a1 = -*a1;
}
else
{
*a2 = 1;
}
return result;
}

original_code:
void setSign
 (
 int* phourDeg,
 int* psign
 )
{
 if (*phourDeg<0){
     *psign=-1;
     *phourDeg= - *phourDeg;
 }
 else{
    *psign=1;
 }
 return;
}

canonical_original_code:
void setSign(int *phourDeg, int *psign)
{
 if (*phourDeg<0){
     *psign=-1;
     *phourDeg= - *phourDeg;
 }
 else{
    *psign=1;
 }
 return;
}

variable_types:
phourDeg
int *

variable_types:
psign
int *


truncDtoI

original_code:
int truncDtoI(double d)
{
 int i;
 i=(d < 0.)?-(floor(-d)):floor(d);
 return(i);
}

variable_types: d double

variable_types: i int


variable_types: mjd int

variable_types:
pm
double *

variable_types:
peqOfEquinox
double *

variable_types: t double

variable_types: obliqRd double

variable_types: delPsiRd double

variable_types: delEpsRd double

variable_types: toRad double

variable_types: omRd double

variable_types: fRd double

variable_types: dRd double

variable_types: lprRd double

variable_types: lRd double


decompiled_code:
__int64 __fastcall rotationZ_M(int a1, __int64 *a2, double a3)
{
double v3; // xmm0_8
__int64 v4; // xmm1_8
double v5; // xmm2_8
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a3, sinx, (double *)&v7);
v3 = sinx[0];
v4 = v7;
*(_QWORD *)&v5 = *(_QWORD *)&sinx[0] ^ LC0;
if ( !a1 )
{
*(_QWORD *)&v3 = *(_QWORD *)&sinx[0] ^ LC0;
v5 = sinx[0];
}
result = LC2;
a2[2] = 0LL;
a2[5] = 0LL;
a2[6] = 0LL;
a2[7] = 0LL;
a2[8] = LC2;
*a2 = v4;
*((double *)a2 + 1) = v3;
*((double *)a2 + 3) = v5;
a2[4] = v4;
return result;
}

original_code:
void rotationZ_M
        (
          double thetaRd,
          int rightHanded,
          double* pm
        )
{
        double costh,sinth;
        costh=cos(thetaRd);
        sinth=sin(thetaRd);
        sinth=(rightHanded)?sinth:-sinth;
        pm[0]=costh;
        pm[1]=sinth;
        pm[2]=0.;
        pm[3]=-sinth;
        pm[4]= costh;
        pm[5]=0.;
        pm[6]=0.;
        pm[7]=0.;
        pm[8]=1.;
        return;
}

canonical_original_code:
void rotationZ_M(double thetaRd, int rightHanded, double *pm)
{
        double costh; double sinth;
        costh=cos(thetaRd);
        sinth=sin(thetaRd);
        sinth=(rightHanded)?sinth:-sinth;
        pm[0]=costh;
        pm[1]=sinth;
        pm[2]=0.;
        pm[3]=-sinth;
        pm[4]= costh;
        pm[5]=0.;
        pm[6]=0.;
        pm[7]=0.;
        pm[8]=1.;
        return;
}

variable_types: thetaRd double

variable_types: rightHanded int

variable_types: costh double

variable_types: sinth double


gregToMjdDno

decompiled_code:
__int64 __fastcall gregToMjdDno(int a1, int a2)
{
int v2; // eax

v2 = a1 + (int)((double)(a2 - 1) * 365.25);
if ( a2 > 1900 )
return (unsigned int)(v2 - 678591);
if ( a2 > 1800 )
return (unsigned int)(v2 - 678590);
if ( a2 > 1700 )
return (unsigned int)(v2 - 678589);
return (unsigned int)(v2 - 678588);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v2; // eax

v2 = a1 + (int)((double)(a2 - 1) * 365.25);
if ( a2 > 1900 )
return (unsigned int)(v2 - 678591);
if ( a2 > 1800 )
return (unsigned int)(v2 - 678590);
if ( a2 > 1700 )
return (unsigned int)(v2 - 678589);
return (unsigned int)(v2 - 678588);
}

original_code:
int gregToMjdDno
        (
        int dayNo,
        int year
        )
{
 int ival;
 ival=( (int)((year-1)*365.25) + dayNo + -678956 + 365);
 if (year <= 1900)ival++;
 if (year <= 1800)ival++;
 if (year <= 1700)ival++;
 return(ival);
}

canonical_original_code:
int gregToMjdDno(int dayNo, int year)
{
 int ival;
 ival=( (int)((year-1)*365.25) + dayNo + -678956 + 365);
 if (year <= 1900)ival++;
 if (year <= 1800)ival++;
 if (year <= 1700)ival++;
 return(ival);
}

variable_types: dayNo int

variable_types: year int

variable_types: ival int


isLeapYear

decompiled_code:
_BOOL8 __fastcall isLeapYear(int a1)
{
_BOOL8 result; // rax
int v2; // edi

result = 0LL;
if ( (a1 & 3) == 0 )
{
result = 1LL;
v2 = -1030792151 * a1 + 85899344;
if ( __ROR4__(v2, 2) <= 0x28F5C28u )
result = __ROR4__(v2, 4) <= 0xA3D70Au;
}
return result;
}

original_code:
int isLeapYear
        (
        int year
        )
{
        if ((year%4)) return(0);
        if ((year%100)) return(1);
        return(!(year%400));
}

canonical_original_code:
int isLeapYear(int year)
{
        if ((year%4)) return(0);
        if ((year%100)) return(1);
        return(!(year%400));
}


original_code:
void precJ2ToDate_M
        (
         int mjd,
         double ut1Frac,
         double* pm
        )
{
        double xiRd,zeRd,thRd;
        double T;
        double cosXi,sinXi,cosZe,sinZe,cosTh,sinTh;;
        T= ((mjdToJulDate(mjd,ut1Frac) - 2451545.0)/(double)36525);
        xiRd = T*(.6406161 + T*( .0000839 + (T*.0000050)))*1.745329251994329577e-2;
        zeRd = T*(.6406161 + T*( .0003041 + (T*.0000051)))*1.745329251994329577e-2;
        thRd = T*(.5567530 - T*( .0001185 + (T*.0000116)))*1.745329251994329577e-2;
        cosXi=cos(xiRd);
        sinXi=sin(xiRd);
        cosZe=cos(zeRd);
        sinZe=sin(zeRd);
        cosTh=cos(thRd);
        sinTh=sin(thRd);
        pm[0]= cosXi*cosTh*cosZe - sinXi*sinZe;
        pm[1]=-sinXi*cosTh*cosZe - cosXi*sinZe;
        pm[2]= -sinTh*cosZe;
        pm[3]= cosXi*cosTh*sinZe + sinXi*cosZe;
        pm[4]=-sinXi*cosTh*sinZe + cosXi*cosZe;
        pm[5]= -sinTh*sinZe;
        pm[6]= cosXi*sinTh;
        pm[7]=-sinXi*sinTh;
        pm[8]= cosTh;
        return;
}

canonical_original_code:
void precJ2ToDate_M(int mjd, double ut1Frac, double *pm)
{
        double xiRd; double zeRd; double thRd;
        double T;
        double cosXi; double sinXi; double cosZe; double sinZe; double cosTh; double sinTh;;
        T= ((mjdToJulDate(mjd,ut1Frac) - 2451545.0)/(double)36525);
        xiRd = T*(.6406161 + T*( .0000839 + (T*.0000050)))*1.745329251994329577e-2;
        zeRd = T*(.6406161 + T*( .0003041 + (T*.0000051)))*1.745329251994329577e-2;
        thRd = T*(.5567530 - T*( .0001185 + (T*.0000116)))*1.745329251994329577e-2;
        cosXi=cos(xiRd);
        sinXi=sin(xiRd);
        cosZe=cos(zeRd);
        sinZe=sin(zeRd);
        cosTh=cos(thRd);
        sinTh=sin(thRd);
        pm[0]= cosXi*cosTh*cosZe - sinXi*sinZe;
        pm[1]=-sinXi*cosTh*cosZe - cosXi*sinZe;
        pm[2]= -sinTh*cosZe;
        pm[3]= cosXi*cosTh*sinZe + sinXi*cosZe;
        pm[4]=-sinXi*cosTh*sinZe + cosXi*cosZe;
        pm[5]= -sinTh*sinZe;
        pm[6]= cosXi*sinTh;
        pm[7]=-sinXi*sinTh;
        pm[8]= cosTh;
        return;
}

variable_types: mjd int

variable_types:
pm
double *

variable_types: xiRd double

variable_types: zeRd double

variable_types: thRd double

variable_types: T double

variable_types: cosXi double

variable_types: sinXi double

variable_types: cosZe double

variable_types: sinZe double

variable_types: cosTh double

variable_types: sinTh double


azzaToRaDecInit

decompiled_code:
__int64 __fastcall azzaToRaDecInit(unsigned int a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // er12
unsigned int v5; // eax
__int64 v7; // [rsp+0h] [rbp-78h] BYREF

if ( (unsigned int)obsPosInp(&unk_8A, a3 + 176) )
return (unsigned int)-1;
precNutInit(a3, 1.0);
if ( (v4 = utcInfoInp(a1, a2, 0LL, a3 + 200)) != 0 )
return (unsigned int)-1;
v5 = gregToMjdDno(a1, a2);
nutation_M(v5, &v7, a3 + 144, 0.0);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // er12
unsigned int v5; // eax
__int64 v7; // [rsp+0h] [rbp-78h] BYREF

if ( (unsigned int)obsPosInp(&unk_8A, a3 + 176) )
return (unsigned int)-1;
precNutInit(a3, 1.0);
if ( (v4 = utcInfoInp(a1, a2, 0LL, a3 + 200)) != 0 )
return (unsigned int)-1;
v5 = gregToMjdDno(a1, a2);
nutation_M(v5, &v7, a3 + 144, 0.0);
return v4;
}

original_code:
int azzaToRaDecInit (
  int dayno,
  int year,
      AZZA_TO_RADEC_INFO *pinfo
 )
{
 int mjd;
 double nutM[9];
 if (obsPosInp(" ",&pinfo->obsPosI) != 0) goto errout;
 precNutInit(1.,&pinfo->precNutI);
 if (utcInfoInp(dayno,year,((void *)0),&pinfo->utcI) != 0) goto errout;
 mjd=gregToMjdDno(dayno,year);
 nutation_M(mjd,0.,nutM,&pinfo->precNutI.eqEquinox);
    return(0);
errout: return((-1));
}

canonical_original_code:
int azzaToRaDecInit(int dayno, int year, struct AZZA_TO_RADEC_INFO *pinfo)
{
 int mjd;
 double nutM[9];
 if (obsPosInp(" ",&pinfo->obsPosI) != 0) goto errout;
 precNutInit(1.,&pinfo->precNutI);
 if (utcInfoInp(dayno,year,((void *)0),&pinfo->utcI) != 0) goto errout;
 mjd=gregToMjdDno(dayno,year);
 nutation_M(mjd,0.,nutM,&pinfo->precNutI.eqEquinox);
    return(0);
errout: return((-1));
}

variable_types: dayno int

variable_types: struct AZZA_TO_RADEC_INFO { struct PRECNUT_INFO { double precN_M[9]; double precNI_M[9]; double eqEquinox; double ut1Frac; double deltaMjd; int mjd; int fill; } precNutI; struct OBS_POS_INFO { double latRd; double wLongRd; int hoursToUtc; int fill; } obsPosI; struct UTC_INFO { int year; int mjdAtOff; double offset; double rate; } utcI; } *

variable_types:
nutM
double [9]

user_defined_types: struct AZZA_TO_RADEC_INFO { struct PRECNUT_INFO precNutI; struct OBS_POS_INFO obsPosI; struct UTC_INFO utcI; }


mjdToJulDate

decompiled_code:
double __fastcall mjdToJulDate(int a1, double a2)
{
return (double)a1 + 2400000.5 + a2;
}

canonical_decompiled_code:
double __fastcall func0(int a1, double a2)
{
return (double)a1 + 2400000.5 + a2;
}

original_code:
double mjdToJulDate
        (
        int mjd,
        double ut1Frac
        )
{
        return(mjd + 2400000.5 + ut1Frac);
}

canonical_original_code:
double mjdToJulDate(int mjd, double ut1Frac)
{
        return(mjd + 2400000.5 + ut1Frac);
}


original_code:
double utcToUt1
        (
        int mjd,
        double utcFrac,
 UTC_INFO* putcI
        )
{
 return(1e-3*1.15740740740740734993e-05 *
       (putcI->offset + ((mjd - putcI->mjdAtOff)+utcFrac)*putcI->rate));
}

canonical_original_code:
double utcToUt1(int mjd, double utcFrac, struct UTC_INFO *putcI)
{
 return(1e-3*1.15740740740740734993e-05 *
       (putcI->offset + ((mjd - putcI->mjdAtOff)+utcFrac)*putcI->rate));
}

variable_types: utcFrac double

variable_types: struct UTC_INFO { int year; int mjdAtOff; double offset; double rate; } *


variable_types:
vr
double *

variable_types: d double


original_code:
double ut1ToLmst
        (
        int mjd,
        double ut1Frac,
        double westLong
        )
{
        double Tu;
        double gmstAt0Ut;
        double dfract;
        double dintp;
        Tu=((mjdToJulDate(mjd,0.) - 2451545.0)/(double)36525);
        gmstAt0Ut=24110.54841 + Tu*(8640184.812866 +
                                Tu*(.093104 -
                                Tu*(6.2e-6)));
        dfract=modf((gmstAt0Ut/86400. + ut1Frac*1.00273790935 -
                     westLong/6.28318530717958647692),&dintp);
        if (dfract < 0.) dfract+=1.;
        return(dfract*6.28318530717958647692);
}

canonical_original_code:
double ut1ToLmst(int mjd, double ut1Frac, double westLong)
{
        double Tu;
        double gmstAt0Ut;
        double dfract;
        double dintp;
        Tu=((mjdToJulDate(mjd,0.) - 2451545.0)/(double)36525);
        gmstAt0Ut=24110.54841 + Tu*(8640184.812866 +
                                Tu*(.093104 -
                                Tu*(6.2e-6)));
        dfract=modf((gmstAt0Ut/86400. + ut1Frac*1.00273790935 -
                     westLong/6.28318530717958647692),&dintp);
        if (dfract < 0.) dfract+=1.;
        return(dfract*6.28318530717958647692);
}

variable_types: mjd int

variable_types: westLong double

variable_types: Tu double

variable_types: dfract double

variable_types: dintp double


original_code:
void MV3D_Mult
        (
        double* m,
        double* v,
        double* vresult
        )
{
        double vtmp[3];
        double *pvtmp,*pv,*pm;
        double tmp;
            pvtmp=vtmp;
            pv=v;
     pm=m;
            tmp=(*pm++) * (*pv++);
            tmp+=(*pm++) * (*pv++);
            *pvtmp++ = (*pm++) * (*pv++) + tmp;
            pv=v;
            tmp=(*pm++) * (*pv++);
            tmp+=(*pm++) * (*pv++);
            *pvtmp = (*pm++) * (*pv++) + tmp;
            pv=v;
            tmp=(*pm++) * (*pv++);
            tmp+=(*pm++) * (*pv++);
            vresult[2]=(*pm) * (*pv) + tmp;
            vresult[1]=vtmp[1];
            *vresult =*vtmp;
        return;
}

canonical_original_code:
void MV3D_Mult(double *m, double *v, double *vresult)
{
        double vtmp[3];
        double *pvtmp; double *pv; double *pm;
        double tmp;
            pvtmp=vtmp;
            pv=v;
     pm=m;
            tmp=(*pm++) * (*pv++);
            tmp+=(*pm++) * (*pv++);
            *pvtmp++ = (*pm++) * (*pv++) + tmp;
            pv=v;
            tmp=(*pm++) * (*pv++);
            tmp+=(*pm++) * (*pv++);
            *pvtmp = (*pm++) * (*pv++) + tmp;
            pv=v;
            tmp=(*pm++) * (*pv++);
            tmp+=(*pm++) * (*pv++);
            vresult[2]=(*pm) * (*pv) + tmp;
            vresult[1]=vtmp[1];
            *vresult =*vtmp;
        return;
}

variable_types:
m
double *

variable_types:
v
double *

variable_types:
vresult
double *

variable_types:
vtmp
double [3]

variable_types:
pvtmp
double *

variable_types:
pv
double *

variable_types:
pm
double *

variable_types: tmp double


decompiled_code:
void __fastcall haToRaDec_V(__int64 a1, __int64 a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm4_8
double v5; // [rsp+0h] [rbp-28h]

v5 = cos(a3);
v3 = sin(COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC0));
v4 = *(double *)a1;
*(double *)a2 = v5 * *(double *)a1 - *(double *)(a1 + 8) * v3;
*(double *)(a2 + 8) = COERCE_DOUBLE(*(_QWORD *)(a1 + 8) ^ LC0) * v5 - v3 * v4;
*(_QWORD *)(a2 + 16) = *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, double a3)
{
double v3; // xmm0_8
double v4; // xmm4_8
double v5; // [rsp+0h] [rbp-28h]

v5 = cos(a3);
v3 = sin(COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC0));
v4 = *(double *)a1;
*(double *)a2 = v5 * *(double *)a1 - *(double *)(a1 + 8) * v3;
*(double *)(a2 + 8) = COERCE_DOUBLE(*(_QWORD *)(a1 + 8) ^ LC0) * v5 - v3 * v4;
*(_QWORD *)(a2 + 16) = *(_QWORD *)(a1 + 16);
}

original_code:
void haToRaDec_V
        (
         double* phaDec,
         double lst,
         double* praDec
        )
{
        double coslst,sinlst;
  double temp;
        coslst=cos(-lst);
        sinlst=sin(-lst);
  temp=phaDec[0];
        praDec[0] = (phaDec[0] * coslst) + (-phaDec[1] * sinlst);
        praDec[1] = (-(temp * sinlst) + (-phaDec[1] * coslst));
        praDec[2] = (phaDec[2]);
        return;
}

canonical_original_code:
void haToRaDec_V(double *phaDec, double lst, double *praDec)
{
        double coslst; double sinlst;
  double temp;
        coslst=cos(-lst);
        sinlst=sin(-lst);
  temp=phaDec[0];
        praDec[0] = (phaDec[0] * coslst) + (-phaDec[1] * sinlst);
        praDec[1] = (-(temp * sinlst) + (-phaDec[1] * coslst));
        praDec[2] = (phaDec[2]);
        return;
}

variable_types:
phaDec
double *

variable_types: lst double

variable_types:
praDec
double *

variable_types: coslst double

variable_types: sinlst double

variable_types: temp double


original_code:
void rotationX_M
        (
          double thetaRd,
          int rightHanded,
          double* pm
        )
{
        double costh,sinth;
        costh=cos(thetaRd);
        sinth=sin(thetaRd);
        sinth=(rightHanded)?sinth:-sinth;
        pm[0]=1.;
        pm[1]=0.;
        pm[2]=0.;
        pm[3]=0.;
        pm[4]=costh;
        pm[5]=sinth;
        pm[6]=0.;
        pm[7]=-sinth;
        pm[8]=costh;
        return;
}

canonical_original_code:
void rotationX_M(double thetaRd, int rightHanded, double *pm)
{
        double costh; double sinth;
        costh=cos(thetaRd);
        sinth=sin(thetaRd);
        sinth=(rightHanded)?sinth:-sinth;
        pm[0]=1.;
        pm[1]=0.;
        pm[2]=0.;
        pm[3]=0.;
        pm[4]=costh;
        pm[5]=sinth;
        pm[6]=0.;
        pm[7]=-sinth;
        pm[8]=costh;
        return;
}

variable_types: thetaRd double

variable_types: rightHanded int

variable_types: costh double

variable_types: sinth double


precNut

decompiled_code:
__int64 __fastcall precNut(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5, double a6)
{
double v10; // xmm0_8
__int64 result; // rax
char v12[80]; // [rsp+8h] [rbp-C8h] BYREF
char v13[120]; // [rsp+58h] [rbp-78h] BYREF

v10 = (double)(int)a1 + a6 - ((double)*(int *)(a3 + 168) + *(double *)(a3 + 152));
if ( v10 < 0.0 )
*(_QWORD *)&v10 ^= LC1;
if ( v10 >= *(double *)(a3 + 160) )
{
*(_DWORD *)(a3 + 168) = a1;
*(double *)(a3 + 152) = a6;
precJ2ToDate_M(a1, v12, a6);
nutation_M(a1, v13, a3 + 144, a6);
MM3D_Mult(v13, v12, a3);
M3D_Transpose(v12);
M3D_Transpose(v13);
result = MM3D_Mult(v12, v13, a3 + 72);
}
if ( a4 && a5 )
{
if ( a2 )
result = MV3D_Mult(a3, a4, a5);
else
result = MV3D_Mult(a3 + 72, a4, a5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, __int64 a3, __int64 a4, __int64 a5, double a6)
{
double v10; // xmm0_8
__int64 result; // rax
char v12[80]; // [rsp+8h] [rbp-C8h] BYREF
char v13[120]; // [rsp+58h] [rbp-78h] BYREF

v10 = (double)(int)a1 + a6 - ((double)*(int *)(a3 + 168) + *(double *)(a3 + 152));
if ( v10 < 0.0 )
*(_QWORD *)&v10 ^= LC1;
if ( v10 >= *(double *)(a3 + 160) )
{
*(_DWORD *)(a3 + 168) = a1;
*(double *)(a3 + 152) = a6;
precJ2ToDate_M(a1, v12, a6);
nutation_M(a1, v13, a3 + 144, a6);
MM3D_Mult(v13, v12, a3);
M3D_Transpose(v12);
M3D_Transpose(v13);
result = MM3D_Mult(v12, v13, a3 + 72);
}
if ( a4 && a5 )
{
if ( a2 )
result = MV3D_Mult(a3, a4, a5);
else
result = MV3D_Mult(a3 + 72, a4, a5);
}
return result;
}

original_code:
void precNut
        (
         int mjd,
         double ut1Frac,
   int jToCur,
   PRECNUT_INFO *pI,
         double *pinpVec,
         double *poutVec
        )
{
     double deltaMjd;
  double precM[9],nutM[9];
  deltaMjd=(mjd + ut1Frac)-(pI->mjd+pI->ut1Frac);
  if (deltaMjd<0.)deltaMjd=-deltaMjd;
  if (deltaMjd >= pI->deltaMjd){
   pI->mjd =mjd;
   pI->ut1Frac =ut1Frac;
         precJ2ToDate_M(mjd,ut1Frac,precM);
         nutation_M(mjd,ut1Frac,nutM,&pI->eqEquinox);
   MM3D_Mult(nutM,precM,pI->precN_M);
         M3D_Transpose(precM,precM);
         M3D_Transpose(nutM,nutM);
   MM3D_Mult(precM,nutM,pI->precNI_M);
  }
  if ((pinpVec != ((void *)0))&&(poutVec != ((void *)0))){
   if (jToCur){
      MV3D_Mult(pI->precN_M,pinpVec,poutVec);
   }
   else {
      MV3D_Mult(pI->precNI_M,pinpVec,poutVec);
   }
  }
        return;
}

canonical_original_code:
void precNut(int mjd, double ut1Frac, int jToCur, struct PRECNUT_INFO *pI, double *pinpVec, double *poutVec)
{
     double deltaMjd;
  double precM[9]; double nutM[9];
  deltaMjd=(mjd + ut1Frac)-(pI->mjd+pI->ut1Frac);
  if (deltaMjd<0.)deltaMjd=-deltaMjd;
  if (deltaMjd >= pI->deltaMjd){
   pI->mjd =mjd;
   pI->ut1Frac =ut1Frac;
         precJ2ToDate_M(mjd,ut1Frac,precM);
         nutation_M(mjd,ut1Frac,nutM,&pI->eqEquinox);
   MM3D_Mult(nutM,precM,pI->precN_M);
         M3D_Transpose(precM,precM);
         M3D_Transpose(nutM,nutM);
   MM3D_Mult(precM,nutM,pI->precNI_M);
  }
  if ((pinpVec != ((void *)0))&&(poutVec != ((void *)0))){
   if (jToCur){
      MV3D_Mult(pI->precN_M,pinpVec,poutVec);
   }
   else {
      MV3D_Mult(pI->precNI_M,pinpVec,poutVec);
   }
  }
        return;
}

variable_types: mjd int

variable_types: jToCur int

variable_types: struct PRECNUT_INFO { double precN_M[9]; double precNI_M[9]; double eqEquinox; double ut1Frac; double deltaMjd; int mjd; int fill; } *

variable_types:
pinpVec
double *

variable_types:
poutVec
double *

variable_types: deltaMjd double

variable_types:
precM
double [9]

variable_types:
nutM
double [9]


decompiled_code:
void __fastcall anglesToVec3(double *a1, double a2, double a3)
{
double v3; // xmm0_8
double v4; // [rsp+8h] [rbp-30h]
double v5; // [rsp+10h] [rbp-28h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

sincos(a2, sinx, &cosx);
v5 = cosx;
v4 = sinx[0];
sincos(a3, sinx, &cosx);
v3 = cosx * v4;
*a1 = v5 * cosx;
a1[1] = v3;
a1[2] = sinx[0];
}

canonical_decompiled_code:
void __fastcall func0(double *a1, double a2, double a3)
{
double v3; // xmm0_8
double v4; // [rsp+8h] [rbp-30h]
double v5; // [rsp+10h] [rbp-28h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

sincos(a2, sinx, &cosx);
v5 = cosx;
v4 = sinx[0];
sincos(a3, sinx, &cosx);
v3 = cosx * v4;
*a1 = v5 * cosx;
a1[1] = v3;
a1[2] = sinx[0];
}

original_code:
void anglesToVec3
 (
   double c1Rad,
   double c2Rad,
   double* pvec3
 )
{
 double cosC2;
 cosC2=cos(c2Rad);
 pvec3[0] = cos(c1Rad)*cosC2;
 pvec3[1]= sin(c1Rad)*cosC2;
 pvec3[2]= sin(c2Rad);
 return;
}

canonical_original_code:
void anglesToVec3(double c1Rad, double c2Rad, double *pvec3)
{
 double cosC2;
 cosC2=cos(c2Rad);
 pvec3[0] = cos(c1Rad)*cosC2;
 pvec3[1]= sin(c1Rad)*cosC2;
 pvec3[2]= sin(c2Rad);
 return;
}


variable_types:
pv
double *

variable_types: L double

variable_types: gRd double

variable_types: n double

variable_types: lambdaRd double

variable_types: C double

variable_types: cosl double


variable_types: sgn int

variable_types: d int

variable_types: m int

variable_types: s double


precNutInit

decompiled_code:
__int64 __fastcall precNutInit(__int64 a1, double a2)
{
__int64 v3; // rdi
__int64 result; // rax

*(_QWORD *)a1 = 0LL;
v3 = a1 + 8;
result = 0LL;
*(_QWORD *)(v3 + 160) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 176) >> 3));
*(double *)(a1 + 160) = a2;
*(_DWORD *)(a1 + 168) = -1000000;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, double a2)
{
__int64 v3; // rdi
__int64 result; // rax

*(_QWORD *)a1 = 0LL;
v3 = a1 + 8;
result = 0LL;
*(_QWORD *)(v3 + 160) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 176) >> 3));
*(double *)(a1 + 160) = a2;
*(_DWORD *)(a1 + 168) = -1000000;
return result;
}

original_code:
void precNutInit
        (
   double deltaMjd,
   PRECNUT_INFO *pI
        )
{
  memset((char*)pI,0,sizeof(PRECNUT_INFO));
  pI->deltaMjd=deltaMjd;
  pI->mjd=-1000000;
  return;
}

canonical_original_code:
void precNutInit(double deltaMjd, struct PRECNUT_INFO *pI)
{
  memset((char *)pI,0,sizeof(PRECNUT_INFO));
  pI->deltaMjd=deltaMjd;
  pI->mjd=-1000000;
  return;
}

variable_types: struct PRECNUT_INFO { double precN_M[9]; double precNI_M[9]; double eqEquinox; double ut1Frac; double deltaMjd; int mjd; int fill; } *


fov

decompiled_code:
double __fastcall fov(double a1, double a2)
{
return (*(double *)&rad2deg + *(double *)&rad2deg) * atan(a2 * 0.5 / a1);
}

canonical_decompiled_code:
double __fastcall func7(double a1, double a2)
{
return (*(double *)&rad2deg + *(double *)&rad2deg) * atan(a2 * 0.5 / a1);
}

original_code:
double fov( double f, double d ) {
  return 2*rad2deg*atan( 0.5*d/f );
}

canonical_original_code:
double fov(double f, double d) {
  return 2*rad2deg*atan( 0.5*d/f );
}

variable_types: f double

variable_types: d double


shiftPt

original_code:
point shiftPt( point* c, point* s ) {
  int modcount = 0;
  double ty = c->y + s->y;
  if( ty < -180.0 ) {
    while( ty < -180.0 ) {
      ty += 180.0; ++modcount;
    }
    if ( modcount % 2 ) ty += 180.0;
  }
  else if( 180.0 < ty ) {
    while( 180.0 < ty ) {
      ty -= 180.0; ++modcount;
    }
    if( modcount % 2 ) ty += -180.0;
  }
  modcount = 0;
  double tp = c->p + s->p;
  if( tp < -90.0 ) {
    while( tp < -90.0 ) {
      tp += 180.0; ++modcount;
    }
    if( modcount % 2 ) tp *= -1.0;
  }
  else if( 90.0 < tp ) {
    while( 90.0 < tp ) {
      tp -= 180.0; ++modcount;
    }
    if( modcount % 2 ) tp *= -1.0;
  }
  point tpt = { ty, tp };
  return tpt;
}

canonical_original_code:
struct point shiftPt(struct point *c, struct point *s) {
  int modcount = 0;
  double ty = c->y + s->y;
  if( ty < -180.0 ) {
    while( ty < -180.0 ) {
      ty += 180.0; ++modcount;
    }
    if ( modcount % 2 ) ty += 180.0;
  }
  else if( 180.0 < ty ) {
    while( 180.0 < ty ) {
      ty -= 180.0; ++modcount;
    }
    if( modcount % 2 ) ty += -180.0;
  }
  modcount = 0;
  double tp = c->p + s->p;
  if( tp < -90.0 ) {
    while( tp < -90.0 ) {
      tp += 180.0; ++modcount;
    }
    if( modcount % 2 ) tp *= -1.0;
  }
  else if( 90.0 < tp ) {
    while( 90.0 < tp ) {
      tp -= 180.0; ++modcount;
    }
    if( modcount % 2 ) tp *= -1.0;
  }
  struct point tpt = { ty, tp };
  return tpt;
}

variable_types:
c
struct point *

variable_types:
s
struct point *

variable_types: modcount int

variable_types: ty double

variable_types: tp double

variable_types:
tpt
struct point { double y; double p; }

return_type: struct point { double y; double p; }


usage

decompiled_code:
int usage()
{
puts("\nTo enter command line arguments and skip dialog:\n");
puts("gigapan <focal length> <sensor width> <sensor height>");
puts(" <start yaw> <start pitch> <how right> <how left>");
puts(" <how up> <how down> <horizontal overlap>");
puts(" <vertical overlap>\n");
printf("There should be 12 arguments total, and this message will be\n ");
return puts("printed again if there is an error in any of them.");
}

canonical_decompiled_code:
int func10()
{
puts("\nTo enter command line arguments and skip dialog:\n");
puts("gigapan <focal length> <sensor width> <sensor height>");
puts(" <start yaw> <start pitch> <how right> <how left>");
puts(" <how up> <how down> <horizontal overlap>");
puts(" <vertical overlap>\n");
printf("There should be 12 arguments total, and this message will be\n ");
return puts("printed again if there is an error in any of them.");
}

original_code:
void usage() {
  puts( "\nTo enter command line arguments and skip dialog:\n" );
  puts( "gigapan <focal length> <sensor width> <sensor height>" );
  puts( "        <start yaw> <start pitch> <how right> <how left>" );
  puts( "        <how up> <how down> <horizontal overlap>" );
  puts( "        <vertical overlap>\n" );
  printf( "There should be 12 arguments total, and this message will be\n " );
  printf( "printed again if there is an error in any of them.\n" );
}


decompiled_code:
__int64 __fastcall send_message(unsigned int a1, __int64 a2)
{
unsigned int v2; // er12

atomic(1LL);
v2 = k_send_message(a1, a2);
atomic(0LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
unsigned int v2; // er12

atomic(1LL);
v2 = k_send_message(a1, a2);
atomic(0LL);
return v2;
}

original_code:
int send_message(int dest_pid, MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_send_message(dest_pid, msg_env);
    atomic(0);
    return ret_value;
}

canonical_original_code:
int send_message(int dest_pid, struct MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_send_message(dest_pid, msg_env);
    atomic(0);
    return ret_value;
}

variable_types: struct MsgEnv { struct MsgEnv *next; unsigned int dest_pid; unsigned int send_pid; int msg_type; char *msg; } *


decompiled_code:
__int64 receive_message()
{
__int64 v0; // r12

atomic(1LL);
v0 = k_receive_message();
atomic(0LL);
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // r12

atomic(1LL);
v0 = k_receive_message();
atomic(0LL);
return v0;
}

original_code:
MsgEnv * receive_message()
{
    atomic(1);
    MsgEnv* ret_value = k_receive_message();
    atomic(0);
    return ret_value;
}

canonical_original_code:
struct MsgEnv *receive_message()
{
    atomic(1);
    struct MsgEnv *ret_value = k_receive_message();
    atomic(0);
    return ret_value;
}

return_type: struct MsgEnv { struct MsgEnv *next; unsigned int dest_pid; unsigned int send_pid; int msg_type; char *msg; } *


decompiled_code:
__int64 request_msg_env()
{
__int64 v0; // r12

atomic(1LL);
v0 = k_request_msg_env();
atomic(0LL);
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r12

atomic(1LL);
v0 = k_request_msg_env();
atomic(0LL);
return v0;
}

original_code:
MsgEnv * request_msg_env()
{
    atomic(1);
    MsgEnv* ret_value = k_request_msg_env();
    atomic(0);
    return ret_value;
}

canonical_original_code:
struct MsgEnv *request_msg_env()
{
    atomic(1);
    struct MsgEnv *ret_value = k_request_msg_env();
    atomic(0);
    return ret_value;
}

user_defined_types: struct MsgEnv { struct MsgEnv *next; unsigned int dest_pid; unsigned int send_pid; int msg_type; char *msg; }


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

atomic(1LL);
v1 = k_release_msg_env(a1);
atomic(0LL);
return v1;
}

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

atomic(1LL);
v1 = k_release_msg_env(a1);
atomic(0LL);
return v1;
}

original_code:
int release_msg_env(MsgEnv * msg_env)
{
    atomic(1);
    int ret_value = k_release_msg_env(msg_env);
    atomic(0);
    return ret_value;
}

canonical_original_code:
int release_msg_env(struct MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_release_msg_env(msg_env);
    atomic(0);
    return ret_value;
}


decompiled_code:
__int64 release_processor()
{
unsigned int v0; // er12

atomic(1LL);
v0 = k_release_processor();
atomic(0LL);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12

atomic(1LL);
v0 = k_release_processor();
atomic(0LL);
return v0;
}

original_code:
int release_processor()
{
    atomic(1);
    int ret_value = k_release_processor();
    atomic(0);
    return ret_value;
}


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

atomic(1LL);
v1 = k_request_process_status(a1);
atomic(0LL);
return v1;
}

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

atomic(1LL);
v1 = k_request_process_status(a1);
atomic(0LL);
return v1;
}

original_code:
int request_process_status(MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_request_process_status(msg_env);
    atomic(0);
    return ret_value;
}

canonical_original_code:
int request_process_status(struct MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_request_process_status(msg_env);
    atomic(0);
    return ret_value;
}


terminate

decompiled_code:
__int64 terminate()
{
unsigned int v0; // er12

atomic(1LL);
v0 = k_terminate();
atomic(0LL);
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er12

atomic(1LL);
v0 = k_terminate();
atomic(0LL);
return v0;
}

original_code:
int terminate()
{
    atomic(1);
    int ret_value = k_terminate();
    atomic(0);
    return ret_value;
}


decompiled_code:
__int64 __fastcall change_priority(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12

atomic(1LL);
v2 = k_change_priority(a1, a2);
atomic(0LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12

atomic(1LL);
v2 = k_change_priority(a1, a2);
atomic(0LL);
return v2;
}

original_code:
int change_priority(int new_priority, int target_process_id)
{
    atomic(1);
    int ret_value = k_change_priority(new_priority, target_process_id);
    atomic(0);
    return ret_value;
}


decompiled_code:
__int64 __fastcall request_delay(unsigned int a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // er12

atomic(1LL);
v4 = k_request_delay(a1, a2, a3);
atomic(0LL);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // er12

atomic(1LL);
v4 = k_request_delay(a1, a2, a3);
atomic(0LL);
return v4;
}

original_code:
int request_delay(int time_delay, int wakeup_code, MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_request_delay(time_delay, wakeup_code, msg_env);
    atomic(0);
    return ret_value;
}

canonical_original_code:
int request_delay(int time_delay, int wakeup_code, struct MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_request_delay(time_delay, wakeup_code, msg_env);
    atomic(0);
    return ret_value;
}


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

atomic(1LL);
v1 = k_send_console_chars(a1);
atomic(0LL);
if ( v1 )
return v1;
kill(rtx_pid, 12);
return 0LL;
}

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

atomic(1LL);
v1 = k_send_console_chars(a1);
atomic(0LL);
if ( v1 )
return v1;
kill(rtx_pid, 12);
return 0LL;
}

original_code:
int send_console_chars(MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_send_console_chars(msg_env);
    atomic(0);
    if (ret_value == 0)
        kill(rtx_pid, 12);
    return ret_value;
}

canonical_original_code:
int send_console_chars(struct MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_send_console_chars(msg_env);
    atomic(0);
    if (ret_value == 0)
        kill(rtx_pid, 12);
    return ret_value;
}


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

atomic(1LL);
v1 = k_get_console_chars(a1);
atomic(0LL);
return v1;
}

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

atomic(1LL);
v1 = k_get_console_chars(a1);
atomic(0LL);
return v1;
}

original_code:
int get_console_chars(MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_get_console_chars(msg_env);
    atomic(0);
    return ret_value;
}

canonical_original_code:
int get_console_chars(struct MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_get_console_chars(msg_env);
    atomic(0);
    return ret_value;
}


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

atomic(1LL);
v1 = k_get_trace_buffers(a1);
atomic(0LL);
return v1;
}

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

atomic(1LL);
v1 = k_get_trace_buffers(a1);
atomic(0LL);
return v1;
}

original_code:
int get_trace_buffers(MsgEnv* msg_env)
{
    atomic(1);
    int ret_value = k_get_trace_buffers(msg_env);
    atomic(0);
    return ret_value;
}

canonical_original_code:
int get_trace_buffers(struct MsgEnv *msg_env)
{
    atomic(1);
    int ret_value = k_get_trace_buffers(msg_env);
    atomic(0);
    return ret_value;
}


decompiled_code:
__int64 clock_get_system_time()
{
__int64 v0; // r12

atomic(1LL);
v0 = k_clock_get_system_time();
atomic(0LL);
return v0;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // r12

atomic(1LL);
v0 = k_clock_get_system_time();
atomic(0LL);
return v0;
}

original_code:
uint64_t clock_get_system_time()
{
    atomic(1);
    uint64_t ret_value = k_clock_get_system_time();
    atomic(0);
    return ret_value;
}

canonical_original_code:
unsigned long clock_get_system_time()
{
    atomic(1);
    unsigned long ret_value = k_clock_get_system_time();
    atomic(0);
    return ret_value;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall timeout_queue_insert(__int64 *a1)
{
__int64 result; // rax
_DWORD *v2; // rcx
int v3; // edx
_QWORD *v4; // rcx

if ( !a1 )
__assert_fail("new_msg_env != NULL", "src/timeout_queue.c", 0xEu, "timeout_queue_insert");
result = k_clock_get_system_time();
v2 = (_DWORD *)a1[3];
v3 = result + *v2;
*v2 = v3;
v4 = (_QWORD *)timeout_queue;
if ( !timeout_queue )
goto LABEL_10;
result = *(_QWORD *)(timeout_queue + 24);
if ( v3 <= *(_DWORD *)result )
{
*a1 = timeout_queue;
LABEL_10:
timeout_queue = (__int64)a1;
return result;
}
result = *(_QWORD *)timeout_queue;
if ( *(_QWORD *)timeout_queue )
{
while ( v3 > **(_DWORD **)(result + 24) )
{
v4 = (_QWORD *)result;
result = *(_QWORD *)result;
}
*v4 = a1;
*a1 = result;
}
else
{
*(_QWORD *)timeout_queue = a1;
*a1 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1)
{
__int64 result; // rax
_DWORD *v2; // rcx
int v3; // edx
_QWORD *v4; // rcx

if ( !a1 )
__assert_fail("new_msg_env != NULL", "src/timeout_queue.c", 0xEu, "timeout_queue_insert");
result = func14();
v2 = (_DWORD *)a1[3];
v3 = result + *v2;
*v2 = v3;
v4 = (_QWORD *)timeout_queue;
if ( !timeout_queue )
goto LABEL_10;
result = *(_QWORD *)(timeout_queue + 24);
if ( v3 <= *(_DWORD *)result )
{
*a1 = timeout_queue;
LABEL_10:
timeout_queue = (__int64)a1;
return result;
}
result = *(_QWORD *)timeout_queue;
if ( *(_QWORD *)timeout_queue )
{
while ( v3 > **(_DWORD **)(result + 24) )
{
v4 = (_QWORD *)result;
result = *(_QWORD *)result;
}
*v4 = a1;
*a1 = result;
}
else
{
*(_QWORD *)timeout_queue = a1;
*a1 = 0LL;
}
return result;
}

original_code:
void timeout_queue_insert (MsgEnv* new_msg_env)
{
    ((void) sizeof ((new_msg_env != ((void *)0)) ? 1 : 0), __extension__ ({ if (new_msg_env != ((void *)0)) ; else __assert_fail ("new_msg_env != NULL", "src/timeout_queue.c", 14, __extension__ __PRETTY_FUNCTION__); }));
    int timeout = k_clock_get_system_time() + *((int *) new_msg_env->msg);
    *((int *) new_msg_env->msg) = timeout;
    if (timeout_queue == ((void *)0))
    {
        timeout_queue = new_msg_env;
        return;
    }
    MsgEnv* node = timeout_queue;
    int timeout_so_far = *((int*)node->msg);
    if (timeout <= *((int *) node->msg))
    {
        new_msg_env->next = node;
        timeout_queue = new_msg_env;
        return;
    }
    MsgEnv* prev_node = node;
    node = node->next;
    if (node)
    {
        timeout_so_far = *((int*)node->msg);
        while(timeout_so_far < timeout && node != ((void *)0))
        {
            prev_node = node;
            node = node->next;
            timeout_so_far = *((int*)node->msg);
        }
    }
    prev_node->next = new_msg_env;
    new_msg_env->next = node;
}

canonical_original_code:
void timeout_queue_insert(struct MsgEnv *new_msg_env)
{
    ((void) sizeof ((new_msg_env != ((void *)0)) ? 1 : 0), __extension__ ({ if (new_msg_env != ((void *)0)) ; else __assert_fail ("new_msg_env != NULL", "src/timeout_queue.c", 14, __extension__ __PRETTY_FUNCTION__); }));
    int timeout = k_clock_get_system_time() + *((int *) new_msg_env->msg);
    *((int *) new_msg_env->msg) = timeout;
    if (timeout_queue == ((void *)0))
    {
        timeout_queue = new_msg_env;
        return;
    }
    struct MsgEnv *node = timeout_queue;
    int timeout_so_far = *((int*)node->msg);
    if (timeout <= *((int *) node->msg))
    {
        new_msg_env->next = node;
        timeout_queue = new_msg_env;
        return;
    }
    struct MsgEnv *prev_node = node;
    node = node->next;
    if (node)
    {
        timeout_so_far = *((int *)node->msg);
        while(timeout_so_far < timeout && node != ((void *)0))
        {
            prev_node = node;
            node = node->next;
            timeout_so_far = *((int *)node->msg);
        }
    }
    prev_node->next = new_msg_env;
    new_msg_env->next = node;
}

variable_types: timeout int


decompiled_code:
_BOOL8 timeout_queue_is_empty()
{
return timeout_queue == 0;
}

canonical_decompiled_code:
_BOOL8 func11()
{
return timeout_queue == 0;
}

original_code:
int timeout_queue_is_empty()
{
    return timeout_queue == ((void *)0);
}


decompiled_code:
__int64 get_timeout_queue()
{
return timeout_queue;
}

canonical_decompiled_code:
__int64 func12()
{
return timeout_queue;
}

original_code:
MsgEnv * get_timeout_queue()
{
 return timeout_queue;
}

canonical_original_code:
struct MsgEnv *get_timeout_queue()
{
 return timeout_queue;
}


decompiled_code:
__int64 check_timeout_queue()
{
unsigned __int64 v0; // rbx
__int64 result; // rax

if ( timeout_queue_is_empty() )
return 0LL;
if ( !timeout_queue )
return 0LL;
v0 = **(int **)(timeout_queue + 24);
if ( v0 > k_clock_get_system_time() )
return 0LL;
result = timeout_queue;
timeout_queue = *(_QWORD *)timeout_queue;
return result;
}

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

if ( func11() )
return 0LL;
if ( !timeout_queue )
return 0LL;
v0 = **(int **)(timeout_queue + 24);
if ( v0 > func14() )
return 0LL;
result = timeout_queue;
timeout_queue = *(_QWORD *)timeout_queue;
return result;
}

original_code:
MsgEnv * check_timeout_queue(MsgEnv* msg_env)
{
    if(!timeout_queue_is_empty())
    {
        while (timeout_queue &&
               *((int *) timeout_queue->msg) <= k_clock_get_system_time())
        {
            msg_env = timeout_queue;
            timeout_queue = timeout_queue->next;
            return msg_env;
        }
    }
 return ((void *)0);
}

canonical_original_code:
struct MsgEnv *check_timeout_queue(struct MsgEnv *msg_env)
{
    if(!timeout_queue_is_empty())
    {
        while (timeout_queue &&
               *((int *) timeout_queue->msg) <= k_clock_get_system_time())
        {
            msg_env = timeout_queue;
            timeout_queue = timeout_queue->next;
            return msg_env;
        }
    }
 return ((void *)0);
}


decompiled_code:
__int64 k_get_trace_buffers()
{
int v0; // eax
int v1; // ecx
__int64 v2; // r9
_DWORD *v3; // rdx
int v4; // edi
int v5; // esi
__int64 v6; // rax
__int64 v7; // rax

find_trace_buf_head(send_trace_buf);
v0 = find_trace_buf_head(recv_trace_buf);
v3 = *(_DWORD **)(v2 + 24);
v4 = v1 + 16;
v5 = v0 - v1;
do
{
v3 += 4;
v6 = 16LL * (v1 % 16);
*(v3 - 4) = *(int *)((char *)&send_trace_buf[1] + v6);
*(v3 - 3) = *(int *)((char *)&send_trace_buf[2] + v6);
*(v3 - 2) = *(int *)((char *)&send_trace_buf[3] + v6);
*(v3 - 1) = *(int *)((char *)&send_trace_buf[4] + v6);
LODWORD(v6) = v5 + v1++;
v7 = 4LL * ((int)v6 % 16);
v3[60] = recv_trace_buf[v7 + 1];
v3[61] = recv_trace_buf[v7 + 2];
v3[62] = recv_trace_buf[v7 + 3];
v3[63] = recv_trace_buf[v7 + 4];
}
while ( v1 != v4 );
return 0LL;
}

original_code:
int k_get_trace_buffers( MsgEnv *msg_env )
{
    int i, send_head, recv_head;
    send_head = _find_trace_buf_head(&_send_trace_buf);
    recv_head = _find_trace_buf_head(&_recv_trace_buf);
    ipc_trace_t *send_dump = (ipc_trace_t *) msg_env->msg;
    ipc_trace_t *recv_dump = send_dump + 16;
    for (i = 0; i < 16; i++)
    {
        ipc_trace_t *trace = &_send_trace_buf.buf[((send_head+i)%16)];
        send_dump->dest_pid = trace->dest_pid;
        send_dump->send_pid = trace->send_pid;
        send_dump->msg_type = trace->msg_type;
        send_dump->time_stamp = trace->time_stamp;
        send_dump++;
        trace = &_recv_trace_buf.buf[((recv_head+i)%16)];
        recv_dump->dest_pid = trace->dest_pid;
        recv_dump->send_pid = trace->send_pid;
        recv_dump->msg_type = trace->msg_type;
        recv_dump->time_stamp = trace->time_stamp;
        recv_dump++;
    }
    return 0;
}

canonical_original_code:
int k_get_trace_buffers(struct MsgEnv *msg_env)
{
    int i; int send_head; int recv_head;
    send_head = _find_trace_buf_head(&_send_trace_buf);
    recv_head = _find_trace_buf_head(&_recv_trace_buf);
    struct ipc_trace *send_dump = (ipc_trace_t *) msg_env->msg;
    struct ipc_trace *recv_dump = send_dump + 16;
    for (i = 0; i < 16; i++)
    {
        struct ipc_trace *trace = &_send_trace_buf.buf[((send_head+i)%16)];
        send_dump->dest_pid = trace->dest_pid;
        send_dump->send_pid = trace->send_pid;
        send_dump->msg_type = trace->msg_type;
        send_dump->time_stamp = trace->time_stamp;
        send_dump++;
        trace = &_recv_trace_buf.buf[((recv_head+i)%16)];
        recv_dump->dest_pid = trace->dest_pid;
        recv_dump->send_pid = trace->send_pid;
        recv_dump->msg_type = trace->msg_type;
        recv_dump->time_stamp = trace->time_stamp;
        recv_dump++;
    }
    return 0;
}

variable_types: i int

variable_types: struct ipc_trace { unsigned int dest_pid; unsigned int send_pid; unsigned int msg_type; unsigned int time_stamp; } *


decompiled_code:
_DWORD *k_receive_message()
{
_DWORD *v0; // r12

while ( 1 )
{
if ( !(unsigned int)msg_env_queue_is_empty(*(_QWORD *)(current_process + 232LL)) )
{
v0 = (_DWORD *)msg_env_queue_dequeue(*(_QWORD *)(current_process + 232LL));
log_msg_event(recv_trace_buf, v0);
return v0;
}
if ( *(_DWORD *)(current_process + 240LL) )
break;
k_process_switch(3LL);
}
return 0LL;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *v0; // r12

while ( 1 )
{
if ( !(unsigned int)msg_env_queue_is_empty(*(_QWORD *)(current_process + 232LL)) )
{
v0 = (_DWORD *)msg_env_queue_dequeue(*(_QWORD *)(current_process + 232LL));
func2(recv_trace_buf, v0);
return v0;
}
if ( *(_DWORD *)(current_process + 240LL) )
break;
k_process_switch(3LL);
}
return 0LL;
}

original_code:
MsgEnv * k_receive_message()
{
    while (msg_env_queue_is_empty(current_process->recv_msgs))
    {
        if (current_process->is_i_process)
        {
            return ((void *)0);
        }
        k_process_switch(P_BLOCKED_ON_RECEIVE);
    }
    MsgEnv *msg_env = msg_env_queue_dequeue(current_process->recv_msgs);
    _log_msg_event(&_recv_trace_buf, msg_env);
    return msg_env;
}

canonical_original_code:
struct MsgEnv *k_receive_message()
{
    while (msg_env_queue_is_empty(current_process->recv_msgs))
    {
        if (current_process->is_i_process)
        {
            return ((void *)0);
        }
        k_process_switch(P_BLOCKED_ON_RECEIVE);
    }
    struct MsgEnv *msg_env = msg_env_queue_dequeue(current_process->recv_msgs);
    _log_msg_event(&_recv_trace_buf, msg_env);
    return msg_env;
}


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

for ( result = 4LL; result != 68; recv_trace_buf[result - 4] = -1 )
{
send_trace_buf[result] = -1;
result += 4LL;
}
return result * 4;
}

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

for ( result = 4LL; result != 68; recv_trace_buf[result - 4] = -1 )
{
send_trace_buf[result] = -1;
result += 4LL;
}
return result * 4;
}

original_code:
void k_ipc_init ()
{
    int i;
    for (i=0; i<16; i++)
    {
        _send_trace_buf.buf[i].time_stamp = ((uint32_t) -1);
        _recv_trace_buf.buf[i].time_stamp = ((uint32_t) -1);
    }
}

canonical_original_code:
void k_ipc_init()
{
    int i;
    for (i=0; i<16; i++)
    {
        _send_trace_buf.buf[i].time_stamp = ((unsigned int) -1);
        _recv_trace_buf.buf[i].time_stamp = ((unsigned int) -1);
    }
}


decompiled_code:
void __noreturn process_A()
{
int v0; // ebx
__int64 v1; // rax
__int64 v2; // rax

v0 = 0;
v1 = receive_message();
release_msg_env(v1);
while ( 1 )
{
v2 = request_msg_env();
*(_DWORD *)(v2 + 16) = -5;
**(_DWORD **)(v2 + 24) = v0++;
send_message(7LL, v2);
release_processor();
}
}

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

v0 = 0;
v1 = receive_message();
release_msg_env(v1);
while ( 1 )
{
v2 = request_msg_env();
*(_DWORD *)(v2 + 16) = -5;
**(_DWORD **)(v2 + 24) = v0++;
send_message(7LL, v2);
release_processor();
}
}

original_code:
void process_A()
{
    MsgEnv * start_msg = receive_message();
    release_msg_env(start_msg);
    int counter = 0;
    while(1)
    {
        MsgEnv * count_msg = request_msg_env();
        count_msg->msg_type = -5;
        *((int *) count_msg->msg) = counter;
        send_message(7, count_msg);
        counter++;
        release_processor();
    }
}

canonical_original_code:
void process_A()
{
    struct MsgEnv *start_msg = receive_message();
    release_msg_env(start_msg);
    int counter = 0;
    while(1)
    {
        struct MsgEnv *count_msg = request_msg_env();
        count_msg->msg_type = -5;
        *((int *) count_msg->msg) = counter;
        send_message(7, count_msg);
        counter++;
        release_processor();
    }
}

variable_types: counter int


decompiled_code:
void __noreturn start_null()
{
while ( 1 )
release_processor();
}

canonical_decompiled_code:
void __noreturn func0()
{
while ( 1 )
release_processor();
}

original_code:
void start_null()
{
    while (1)
    {
        release_processor();
    }
}


decompiled_code:
__int64 k_init()
{
_BYTE v1[296]; // [rsp+0h] [rbp-128h] BYREF

k_storage_init();
qmemcpy(v1, &unk_140, 0x120uLL);
k_process_init(9LL, v1);
fflush(stdout);
sigset(14, (__sighandler_t)&handle_signal);
sigset(2, (__sighandler_t)&handle_signal);
sigset(7, (__sighandler_t)&handle_signal);
sigset(1, (__sighandler_t)&handle_signal);
sigset(4, (__sighandler_t)&handle_signal);
sigset(3, (__sighandler_t)&handle_signal);
sigset(11, (__sighandler_t)&handle_signal);
sigset(15, (__sighandler_t)&handle_signal);
sigset(6, (__sighandler_t)&handle_signal);
ualarm(0x7A120u, 0x186A0u);
k_uart_init();
k_ipc_init();
return k_enter_scheduler();
}

canonical_decompiled_code:
__int64 func0()
{
_BYTE v1[296]; // [rsp+0h] [rbp-128h] BYREF

k_storage_init();
qmemcpy(v1, &unk_140, 0x120uLL);
k_process_init(9LL, v1);
fflush(stdout);
sigset(14, (__sighandler_t)&handle_signal);
sigset(2, (__sighandler_t)&handle_signal);
sigset(7, (__sighandler_t)&handle_signal);
sigset(1, (__sighandler_t)&handle_signal);
sigset(4, (__sighandler_t)&handle_signal);
sigset(3, (__sighandler_t)&handle_signal);
sigset(11, (__sighandler_t)&handle_signal);
sigset(15, (__sighandler_t)&handle_signal);
sigset(6, (__sighandler_t)&handle_signal);
ualarm(0x7A120u, 0x186A0u);
k_uart_init();
k_ipc_init();
return k_enter_scheduler();
}

original_code:
void k_init()
{
    k_storage_init();
    proc_cfg_t init_table[(3 +6)] = {
        { 0, "kb-i", 0, 1, start_kb_i_process },
        { 1, "crt-i", 0, 1, start_crt_i_process },
        { 2, "timeout-i", 0, 1, start_timeout_i_process },
        { 3, "null", 3, 0, start_null },
        { 4, "cci", 2, 0, start_cci },
        { 5, "wallclock", 2, 0, start_wallclock },
        { 6, "a", 0, 0, process_A },
        { 7, "b", 1, 0, process_B },
        { 8, "c", 2, 0, process_C }
    };
    k_process_init((3 +6), init_table);
    fflush(stdout);
    sigset(14, handle_signal);
    sigset(2, handle_signal);
    sigset(7, handle_signal);
    sigset(1, handle_signal);
    sigset(4, handle_signal);
    sigset(3, handle_signal);
    sigset(11, handle_signal);
    sigset(15, handle_signal);
    sigset(6, handle_signal);
    ualarm((500*1000), (100*1000));
    k_uart_init();
    k_ipc_init();
    k_enter_scheduler();
}

canonical_original_code:
void k_init()
{
    k_storage_init();
    struct proc_cfg init_table[-1] = {
        { 0, "kb-i", 0, 1, start_kb_i_process },
        { 1, "crt-i", 0, 1, start_crt_i_process },
        { 2, "timeout-i", 0, 1, start_timeout_i_process },
        { 3, "null", 3, 0, start_null },
        { 4, "cci", 2, 0, start_cci },
        { 5, "wallclock", 2, 0, start_wallclock },
        { 6, "a", 0, 0, process_A },
        { 7, "b", 1, 0, process_B },
        { 8, "c", 2, 0, process_C }
    };
    k_process_init((3 +6), init_table);
    fflush(stdout);
    sigset(14, handle_signal);
    sigset(2, handle_signal);
    sigset(7, handle_signal);
    sigset(1, handle_signal);
    sigset(4, handle_signal);
    sigset(3, handle_signal);
    sigset(11, handle_signal);
    sigset(15, handle_signal);
    sigset(6, handle_signal);
    ualarm((500*1000), (100*1000));
    k_uart_init();
    k_ipc_init();
    k_enter_scheduler();
}

variable_types: struct proc_cfg { unsigned int pid; char *name; unsigned int priority; unsigned int is_i_process; void (*start)(); } [-1]


decompiled_code:
void __noreturn k_terminate()
{
k_uart_cleanup();
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
k_uart_cleanup();
exit(0);
}

original_code:
int k_terminate()
{
    k_uart_cleanup();
    exit(0);
}


decompiled_code:
int k_uart_init()
{
int v0; // eax
unsigned int v1; // ebp
int v2; // eax
unsigned int v3; // er12
void *v4; // rax
void *v5; // rax
char v7[32]; // [rsp+0h] [rbp-58h] BYREF
char s[56]; // [rsp+20h] [rbp-38h] BYREF

sigset(10, (__sighandler_t)&handle_signal);
sigset(12, (__sighandler_t)&handle_signal);
v0 = open("keyboard.dat", 66, 493LL);
if ( v0 < 0
|| (v1 = v0, ftruncate(v0, 1032LL))
|| (v2 = open("crt.dat", 66, 493LL), v3 = v2, v2 < 0)
|| ftruncate(v2, 1025LL)
|| (rtx_pid = getpid(), v4 = mmap(0LL, 0x408uLL, 3, 1, v1, 0LL), v4 == (void *)-1LL) )
{
LABEL_12:
exit(1);
}
kb_buf = v4;
sprintf(v7, "%d", (unsigned int)rtx_pid);
kb_child_pid = fork();
if ( !kb_child_pid )
{
sprintf(s, "%d", v1);
execl("./keyboard", "keyboard", v7, s, 0LL);
goto LABEL_11;
}
v5 = mmap(0LL, 0x401uLL, 3, 1, v3, 0LL);
if ( v5 == (void *)-1LL )
goto LABEL_12;
crt_buf = v5;
crt_child_pid = fork();
if ( !crt_child_pid )
{
sprintf(s, "%d", v3);
execl("./crt", "crt", v7, s, 0LL);
LABEL_11:
kill(rtx_pid, 2);
goto LABEL_12;
}
close(v3);
return close(v1);
}

canonical_decompiled_code:
int func0()
{
int v0; // eax
unsigned int v1; // ebp
int v2; // eax
unsigned int v3; // er12
void *v4; // rax
void *v5; // rax
char v7[32]; // [rsp+0h] [rbp-58h] BYREF
char s[56]; // [rsp+20h] [rbp-38h] BYREF

sigset(10, (__sighandler_t)&handle_signal);
sigset(12, (__sighandler_t)&handle_signal);
v0 = open("keyboard.dat", 66, 493LL);
if ( v0 < 0
|| (v1 = v0, ftruncate(v0, 1032LL))
|| (v2 = open("crt.dat", 66, 493LL), v3 = v2, v2 < 0)
|| ftruncate(v2, 1025LL)
|| (rtx_pid = getpid(), v4 = mmap(0LL, 0x408uLL, 3, 1, v1, 0LL), v4 == (void *)-1LL) )
{
LABEL_12:
exit(1);
}
kb_buf = v4;
sprintf(v7, "%d", (unsigned int)rtx_pid);
kb_child_pid = fork();
if ( !kb_child_pid )
{
sprintf(s, "%d", v1);
execl("./keyboard", "keyboard", v7, s, 0LL);
goto LABEL_11;
}
v5 = mmap(0LL, 0x401uLL, 3, 1, v3, 0LL);
if ( v5 == (void *)-1LL )
goto LABEL_12;
crt_buf = v5;
crt_child_pid = fork();
if ( !crt_child_pid )
{
sprintf(s, "%d", v3);
execl("./crt", "crt", v7, s, 0LL);
LABEL_11:
kill(rtx_pid, 2);
goto LABEL_12;
}
close(v3);
return close(v1);
}

original_code:
void k_uart_init()
{
    sigset(10, handle_signal);
    sigset(12, handle_signal);
    int kb_fid, crt_fid, status;
    kb_fid = open("keyboard.dat", 02 | 0100 , (mode_t) 0755);
    if (kb_fid < 0 )
    {
        exit(1);
    }
    status = ftruncate(kb_fid, sizeof(recv_buf_t));
    if (status != 0)
    {
        exit(1);
    }
    crt_fid = open("crt.dat", 02 | 0100 , (mode_t) 0755);
    if (crt_fid < 0 )
    {
        exit(1);
    }
    status = ftruncate(crt_fid, sizeof(send_buf_t));
    if (status != 0)
    {
        exit(1);
    }
    rtx_pid = getpid();
    void * mmap_ptr = mmap(((void *)0), sizeof(recv_buf_t), 0x1 | 0x2, 0x01, kb_fid, 0);
    if (mmap_ptr == ((void *) -1))
    {
        exit(1);
    }
    kb_buf = (recv_buf_t *) mmap_ptr;
    char arg1[32], arg2[32];
    sprintf(arg1, "%d", rtx_pid);
    kb_child_pid = fork();
    if (kb_child_pid == 0)
    {
        sprintf(arg2, "%d", kb_fid);
        execl("./keyboard", "keyboard", arg1, arg2, ((void *)0));
        kill(rtx_pid, 2);
        exit(1);
    }
    mmap_ptr = mmap(((void *)0), sizeof(send_buf_t), 0x1 | 0x2, 0x01, crt_fid, 0);
    if (mmap_ptr == ((void *) -1))
    {
        exit(1);
    }
    crt_buf = (send_buf_t *)mmap_ptr;
    crt_child_pid = fork();
    if (crt_child_pid == 0)
    {
        sprintf(arg2, "%d", crt_fid);
        execl("./crt", "crt", arg1, arg2, ((void *)0));
        kill(rtx_pid, 2);
        exit(1);
    }
    close(crt_fid);
    close(kb_fid);
}

canonical_original_code:
void k_uart_init()
{
    sigset(10, handle_signal);
    sigset(12, handle_signal);
    int kb_fid; int crt_fid; int status;
    kb_fid = open("keyboard.dat", 02 | 0100 , (unsigned int) 0755);
    if (kb_fid < 0 )
    {
        exit(1);
    }
    status = ftruncate(kb_fid, sizeof(recv_buf_t));
    if (status != 0)
    {
        exit(1);
    }
    crt_fid = open("crt.dat", 02 | 0100 , (unsigned int) 0755);
    if (crt_fid < 0 )
    {
        exit(1);
    }
    status = ftruncate(crt_fid, sizeof(send_buf_t));
    if (status != 0)
    {
        exit(1);
    }
    rtx_pid = getpid();
    void *mmap_ptr = mmap(((void *)0), sizeof(recv_buf_t), 0x1 | 0x2, 0x01, kb_fid, 0);
    if (mmap_ptr == ((void *) -1))
    {
        exit(1);
    }
    kb_buf = (struct recv_buf *) mmap_ptr;
    char arg1[32]; char arg2[32];
    sprintf(arg1, "%d", rtx_pid);
    kb_child_pid = fork();
    if (kb_child_pid == 0)
    {
        sprintf(arg2, "%d", kb_fid);
        execl("./keyboard", "keyboard", arg1, arg2, ((void *)0));
        kill(rtx_pid, 2);
        exit(1);
    }
    mmap_ptr = mmap(((void *)0), sizeof(send_buf_t), 0x1 | 0x2, 0x01, crt_fid, 0);
    if (mmap_ptr == ((void *) -1))
    {
        exit(1);
    }
    crt_buf = (struct send_buf *)mmap_ptr;
    crt_child_pid = fork();
    if (crt_child_pid == 0)
    {
        sprintf(arg2, "%d", crt_fid);
        execl("./crt", "crt", arg1, arg2, ((void *)0));
        kill(rtx_pid, 2);
        exit(1);
    }
    close(crt_fid);
    close(kb_fid);
}

variable_types: status int

user_defined_types: struct recv_buf { char kb_wait_flag; char data[1024]; int length; }

user_defined_types: struct send_buf { char i_process_wait_flag; char data[1024]; }


decompiled_code:
int k_uart_cleanup()
{
kill(kb_child_pid, 2);
kill(crt_child_pid, 2);
munmap(kb_buf, 0x408uLL);
munmap(crt_buf, 0x401uLL);
unlink("keyboard.dat");
return unlink("crt.dat");
}

canonical_decompiled_code:
int func1()
{
kill(kb_child_pid, 2);
kill(crt_child_pid, 2);
munmap(kb_buf, 0x408uLL);
munmap(crt_buf, 0x401uLL);
unlink("keyboard.dat");
return unlink("crt.dat");
}

original_code:
void k_uart_cleanup()
{
    kill(kb_child_pid, 2);
    kill(crt_child_pid, 2);
    int status = munmap(kb_buf, sizeof(*kb_buf));
    if (status == -1)
    {
    }
    status = munmap(crt_buf, sizeof(*crt_buf));
    if (status == -1)
    {
    }
    status = unlink("keyboard.dat");
    if (status == -1)
    {
    }
    status = unlink("crt.dat");
    if (status == -1)
    {
    }
}


decompiled_code:
_QWORD *msg_env_queue_create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func12()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

original_code:
msg_env_queue_t * msg_env_queue_create()
{
    msg_env_queue_t * queue = malloc(sizeof(*queue));
    if (queue)
    {
        queue->head = ((void *)0);
        queue-> tail = ((void *)0);
    }
    return queue;
}

canonical_original_code:
struct msg_env_queue *msg_env_queue_create()
{
    struct msg_env_queue *queue = malloc(sizeof(*queue));
    if (queue)
    {
        queue->head = ((void *)0);
        queue-> tail = ((void *)0);
    }
    return queue;
}

variable_types: struct msg_env_queue { struct MsgEnv { struct MsgEnv *next; unsigned int dest_pid; unsigned int send_pid; int msg_type; char *msg; } *head; struct MsgEnv *tail; } *

user_defined_types: struct msg_env_queue { struct MsgEnv *head; struct MsgEnv *tail; }


decompiled_code:
// attributes: thunk
void msg_env_queue_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func13(void *ptr)
{
free(ptr);
}

original_code:
void msg_env_queue_destroy(msg_env_queue_t * queue)
{
    free(queue);
}

canonical_original_code:
void msg_env_queue_destroy(struct msg_env_queue *queue)
{
    free(queue);
}


decompiled_code:
__int64 __fastcall msg_env_queue_is_empty(_QWORD *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !*a1 )
{
if ( a1[1] )
__assert_fail("queue->tail == NULL", "src/msg_env_queue.c", 0x27u, "msg_env_queue_is_empty");
}
return *a1 == 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !*a1 )
{
if ( a1[1] )
__assert_fail("queue->tail == NULL", "src/msg_env_queue.c", 0x27u, "msg_env_queue_is_empty");
}
return *a1 == 0LL;
}

original_code:
int msg_env_queue_is_empty(msg_env_queue_t* queue)
{
    if (queue == ((void *)0))
    {
        return -1;
    }
    if (queue->head == ((void *)0))
    {
        ((void) sizeof ((queue->tail == ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->tail == ((void *)0)) ; else __assert_fail ("queue->tail == NULL", "src/msg_env_queue.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    }
    return queue->head == ((void *)0);
}

canonical_original_code:
int msg_env_queue_is_empty(struct msg_env_queue *queue)
{
    if (queue == ((void *)0))
    {
        return -1;
    }
    if (queue->head == ((void *)0))
    {
        ((void) sizeof ((queue->tail == ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->tail == ((void *)0)) ; else __assert_fail ("queue->tail == NULL", "src/msg_env_queue.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    }
    return queue->head == ((void *)0);
}


decompiled_code:
__int64 __fastcall msg_env_queue_enqueue(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 )
**(_QWORD **)(a1 + 8) = a2;
else
*(_QWORD *)a1 = a2;
result = 0LL;
*(_QWORD *)(a1 + 8) = a2;
*a2 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 )
**(_QWORD **)(a1 + 8) = a2;
else
*(_QWORD *)a1 = a2;
result = 0LL;
*(_QWORD *)(a1 + 8) = a2;
*a2 = 0LL;
return result;
}

original_code:
int msg_env_queue_enqueue(msg_env_queue_t *queue, MsgEnv* env)
{
 if (queue == ((void *)0) || env == ((void *)0))
 {
  return -1;
 }
    if (queue->head == ((void *)0))
    {
        queue->head = env;
    }
    else
    {
        queue->tail->next = env;
    }
    queue->tail = env;
    queue->tail->next = ((void *)0);
    return 0;
}

canonical_original_code:
int msg_env_queue_enqueue(struct msg_env_queue *queue, struct MsgEnv *env)
{
 if (queue == ((void *)0) || env == ((void *)0))
 {
  return -1;
 }
    if (queue->head == ((void *)0))
    {
        queue->head = env;
    }
    else
    {
        queue->tail->next = env;
    }
    queue->tail = env;
    queue->tail->next = ((void *)0);
    return 0;
}

variable_types:
env
struct MsgEnv *


decompiled_code:
__int64 __fastcall msg_env_queue_size(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

if ( !a1 )
return (unsigned int)-1;
v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

if ( !a1 )
return (unsigned int)-1;
v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

original_code:
int msg_env_queue_size(msg_env_queue_t *queue)
{
    if (queue == ((void *)0))
    {
        return -1;
    }
    MsgEnv * env = queue->head;
    int size = 0;
    while (env != ((void *)0))
    {
        env = env->next;
        size++;
    }
    return size;
}

canonical_original_code:
int msg_env_queue_size(struct msg_env_queue *queue)
{
    if (queue == ((void *)0))
    {
        return -1;
    }
    struct MsgEnv *env = queue->head;
    int size = 0;
    while (env != ((void *)0))
    {
        env = env->next;
        size++;
    }
    return size;
}

variable_types: size int


decompiled_code:
__int64 k_storage_init()
{
__int64 v0; // rbx
__int64 v1; // r12
__int64 v2; // rbp
_QWORD *v3; // rbp
void *v4; // rax
__int64 result; // rax

v0 = 0LL;
env_blocked_pq = proc_pq_create(3LL);
free_env_q = msg_env_queue_create();
v1 = free_env_q;
env_pool = (__int64)malloc(0x400uLL);
v2 = env_pool;
while ( 1 )
{
v3 = (_QWORD *)(v0 + v2);
v0 += 32LL;
v4 = malloc(0x400uLL);
*v3 = 0LL;
v3[3] = v4;
result = msg_env_queue_enqueue(v1, v3);
if ( v0 == 1024 )
break;
v2 = env_pool;
v1 = free_env_q;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
__int64 v1; // r12
__int64 v2; // rbp
_QWORD *v3; // rbp
void *v4; // rax
__int64 result; // rax

v0 = 0LL;
env_blocked_pq = proc_pq_create(3LL);
free_env_q = msg_env_queue_create();
v1 = free_env_q;
env_pool = (__int64)malloc(0x400uLL);
v2 = env_pool;
while ( 1 )
{
v3 = (_QWORD *)(v0 + v2);
v0 += 32LL;
v4 = malloc(0x400uLL);
*v3 = 0LL;
v3[3] = v4;
result = msg_env_queue_enqueue(v1, v3);
if ( v0 == 1024 )
break;
v2 = env_pool;
v1 = free_env_q;
}
return result;
}

original_code:
void k_storage_init()
{
    env_blocked_pq = proc_pq_create(3);
    free_env_q = msg_env_queue_create();
    env_pool = malloc(sizeof(*env_pool) * 32);
    int i;
    for (i = 0; i < 32; i++)
    {
        env_pool[i].msg = malloc(sizeof(*env_pool[i].msg) * 1024);
        env_pool[i].next = ((void *)0);
        msg_env_queue_enqueue(free_env_q, &env_pool[i]);
    }
}


decompiled_code:
__int64 k_request_msg_env()
{
while ( 1 )
{
if ( !(unsigned int)msg_env_queue_is_empty(free_env_q) )
return msg_env_queue_dequeue(free_env_q);
if ( *(_DWORD *)(current_process + 240LL) )
break;
proc_pq_enqueue(env_blocked_pq);
k_process_switch(2LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
while ( 1 )
{
if ( !(unsigned int)msg_env_queue_is_empty(free_env_q) )
return msg_env_queue_dequeue(free_env_q);
if ( *(_DWORD *)(current_process + 240LL) )
break;
proc_pq_enqueue(env_blocked_pq);
k_process_switch(2LL);
}
return 0LL;
}

original_code:
MsgEnv * k_request_msg_env()
{
    while (msg_env_queue_is_empty(free_env_q))
    {
        if (current_process->is_i_process)
        {
            return ((void *)0);
        }
        proc_pq_enqueue(env_blocked_pq, current_process);
        k_process_switch(P_BLOCKED_ON_ENV_REQUEST);
    }
    MsgEnv *env = msg_env_queue_dequeue(free_env_q);
    return env;
}

canonical_original_code:
struct MsgEnv *k_request_msg_env()
{
    while (msg_env_queue_is_empty(free_env_q))
    {
        if (current_process->is_i_process)
        {
            return ((void *)0);
        }
        proc_pq_enqueue(env_blocked_pq, current_process);
        k_process_switch(P_BLOCKED_ON_ENV_REQUEST);
    }
    struct MsgEnv *env = msg_env_queue_dequeue(free_env_q);
    return env;
}


decompiled_code:
_BOOL8 __fastcall k_is_msg_env_valid(unsigned __int64 a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( env_pool <= a1 )
v1 = a1 < env_pool + 1024;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(unsigned __int64 a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( env_pool <= a1 )
v1 = a1 < env_pool + 1024;
return v1;
}

original_code:
int k_is_msg_env_valid(MsgEnv *msg_env)
{
    return msg_env >= env_pool && msg_env < env_pool + 32;
}

canonical_original_code:
int k_is_msg_env_valid(struct MsgEnv *msg_env)
{
    return msg_env >= env_pool && msg_env < env_pool + 32;
}


original_code:
void start_kb_i_process()
{
    int i;
    while (1)
    {
        MsgEnv* message = k_receive_message();
        if (message != ((void *)0))
        {
            for (i = 0; i < kb_buf->length; i++)
            {
                message->msg[i] = kb_buf->data[i];
            }
            message->msg[i] = '\0';
            message->msg_type = -3;
            kb_buf->kb_wait_flag = 0;
            k_send_message(message->send_pid, message);
        }
        kb_buf->length = 0;
        k_i_process_exit();
    }
}

canonical_original_code:
void start_kb_i_process()
{
    int i;
    while (1)
    {
        struct MsgEnv *message = k_receive_message();
        if (message != ((void *)0))
        {
            for (i = 0; i < kb_buf->length; i++)
            {
                message->msg[i] = kb_buf->data[i];
            }
            message->msg[i] = '\0';
            message->msg_type = -3;
            kb_buf->kb_wait_flag = 0;
            k_send_message(message->send_pid, message);
        }
        kb_buf->length = 0;
        k_i_process_exit();
    }
}


decompiled_code:
__int64 __fastcall k_send_console_chars(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 16) = -2;
return k_send_message(1LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 16) = -2;
return k_send_message(1LL, a1);
}

original_code:
int k_send_console_chars(MsgEnv *msg_env)
{
    if (msg_env == ((void *)0))
        return -1;
    msg_env->msg_type = -2;
    return k_send_message(1, msg_env);
}

canonical_original_code:
int k_send_console_chars(struct MsgEnv *msg_env)
{
    if (msg_env == ((void *)0))
        return -1;
    msg_env->msg_type = -2;
    return k_send_message(1, msg_env);
}


decompiled_code:
__int64 __fastcall k_get_console_chars(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 16) = -4;
return k_send_message(0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 16) = -4;
return k_send_message(0LL, a1);
}

original_code:
int k_get_console_chars(MsgEnv *msg_env)
{
    if (msg_env == ((void *)0))
        return -1;
    msg_env->msg_type = -4;
    return k_send_message(0, msg_env);
}

canonical_original_code:
int k_get_console_chars(struct MsgEnv *msg_env)
{
    if (msg_env == ((void *)0))
        return -1;
    msg_env->msg_type = -4;
    return k_send_message(0, msg_env);
}


decompiled_code:
void __noreturn process_B()
{
__int64 v0; // rax

while ( 1 )
{
v0 = receive_message();
send_message(8LL, v0);
}
}

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

while ( 1 )
{
v0 = receive_message();
send_message(8LL, v0);
}
}

original_code:
void process_B()
{
    while(1)
    {
        MsgEnv *received_msg = receive_message();
        send_message(8, received_msg);
    }
}

canonical_original_code:
void process_B()
{
    while(1)
    {
        struct MsgEnv *received_msg = receive_message();
        send_message(8, received_msg);
    }
}


decompiled_code:
int __fastcall k_context_switch(struct __jmp_buf_tag *a1, struct __jmp_buf_tag *a2)
{
int result; // eax

result = setjmp(a1);
if ( !result )
longjmp(a2, 1);
return result;
}

canonical_decompiled_code:
int __fastcall func0(struct __jmp_buf_tag *a1, struct __jmp_buf_tag *a2)
{
int result; // eax

result = setjmp(a1);
if ( !result )
longjmp(a2, 1);
return result;
}

original_code:
void k_context_switch(jmp_buf *old_context, jmp_buf *new_context)
{
    if (_setjmp (*old_context) == 0)
    {
        longjmp(*new_context, 1);
    }
}

canonical_original_code:
void k_context_switch(struct __jmp_buf_tag (*old_context)[1], struct __jmp_buf_tag (*new_context)[1])
{
    if (_setjmp (*old_context) == 0)
    {
        longjmp(*new_context, 1);
    }
}

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*)[1]

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


decompiled_code:
__int64 __fastcall k_request_delay(int a1, int a2, __int64 a3)
{
_DWORD *v3; // rax

v3 = *(_DWORD **)(a3 + 24);
*(_DWORD *)(a3 + 16) = a2;
*v3 = a1;
return k_send_message(2LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, __int64 a3)
{
_DWORD *v3; // rax

v3 = *(_DWORD **)(a3 + 24);
*(_DWORD *)(a3 + 16) = a2;
*v3 = a1;
return k_send_message(2LL, a3);
}

original_code:
int k_request_delay(int time_delay, int wakeup_code, MsgEnv *msg_env)
{
    msg_env->msg_type = wakeup_code;
    int * delay_data = (int *) msg_env->msg;
    *delay_data = time_delay;
    return k_send_message(2, msg_env);
}

canonical_original_code:
int k_request_delay(int time_delay, int wakeup_code, struct MsgEnv *msg_env)
{
    msg_env->msg_type = wakeup_code;
    int *delay_data = (int *) msg_env->msg;
    *delay_data = time_delay;
    return k_send_message(2, msg_env);
}


decompiled_code:
void __noreturn start_timeout_i_process()
{
__int64 v0; // rax
__int64 v1; // rdi
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rsi

while ( 1 )
{
k_clock_incr_system_time();
v0 = k_receive_message();
if ( v0 )
{
v1 = v0;
do
{
timeout_queue_insert(v1);
v1 = k_receive_message();
}
while ( v1 );
}
v2 = 0LL;
v3 = check_timeout_queue(0LL);
v4 = v3;
if ( v3 )
{
v2 = *(unsigned int *)(v3 + 12);
k_send_message(v2, v3);
}
k_i_process_exit(v2, v4);
}
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // rax
__int64 v1; // rdi
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rsi

while ( 1 )
{
k_clock_incr_system_time();
v0 = k_receive_message();
if ( v0 )
{
v1 = v0;
do
{
timeout_queue_insert(v1);
v1 = k_receive_message();
}
while ( v1 );
}
v2 = 0LL;
v3 = check_timeout_queue(0LL);
v4 = v3;
if ( v3 )
{
v2 = *(unsigned int *)(v3 + 12);
k_send_message(v2, v3);
}
k_i_process_exit(v2, v4);
}
}

original_code:
void start_timeout_i_process()
{
    while(1)
    {
        k_clock_incr_system_time();
        MsgEnv* msg_env = k_receive_message();
        while (msg_env != ((void *)0))
        {
            timeout_queue_insert(msg_env);
            msg_env = k_receive_message();
        }
  msg_env = check_timeout_queue(msg_env);
        if (msg_env != ((void *)0))
        {
            k_send_message(msg_env->send_pid, msg_env);
        }
        k_i_process_exit();
    }
}

canonical_original_code:
void start_timeout_i_process()
{
    while(1)
    {
        k_clock_incr_system_time();
        struct MsgEnv *msg_env = k_receive_message();
        while (msg_env != ((void *)0))
        {
            timeout_queue_insert(msg_env);
            msg_env = k_receive_message();
        }
  msg_env = check_timeout_queue(msg_env);
        if (msg_env != ((void *)0))
        {
            k_send_message(msg_env->send_pid, msg_env);
        }
        k_i_process_exit();
    }
}


atomic

decompiled_code:
int __fastcall atomic(int a1)
{
int v1; // eax
int result; // eax
sigset_t v3; // [rsp+0h] [rbp-88h] BYREF

v1 = *(_DWORD *)(current_process + 264LL);
if ( a1 == 1 )
{
result = v1 + 1;
*(_DWORD *)(current_process + 264LL) = result;
if ( result == 1 )
{
sigemptyset(&v3);
sigaddset(&v3, 14);
sigaddset(&v3, 2);
sigaddset(&v3, 10);
sigaddset(&v3, 12);
result = sigprocmask(0, &v3, &oldmask_1);
}
}
else
{
result = v1 - 1;
*(_DWORD *)(current_process + 264LL) = result;
if ( result < 0 )
_assert_fail("current_process->atomic_count >= 0", "src/k_atomic.c", 0x26u, "atomic");
if ( !result )
result = sigprocmask(2, &oldmask_1, 0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int v1; // eax
int result; // eax
sigset_t v3; // [rsp+0h] [rbp-88h] BYREF

v1 = *(_DWORD *)(current_process + 264LL);
if ( a1 == 1 )
{
result = v1 + 1;
*(_DWORD *)(current_process + 264LL) = result;
if ( result == 1 )
{
sigemptyset(&v3);
sigaddset(&v3, 14);
sigaddset(&v3, 2);
sigaddset(&v3, 10);
sigaddset(&v3, 12);
result = sigprocmask(0, &v3, &oldmask_1);
}
}
else
{
result = v1 - 1;
*(_DWORD *)(current_process + 264LL) = result;
if ( result < 0 )
_assert_fail("current_process->atomic_count >= 0", "src/k_atomic.c", 0x26u, "atomic");
if ( !result )
result = sigprocmask(2, &oldmask_1, 0LL);
}
return result;
}

original_code:
void atomic(int on_off)
{
    static sigset_t oldmask;
    sigset_t newmask;
    if (on_off == 1)
    {
        current_process->atomic_count++;
        if (current_process->atomic_count == 1)
        {
            sigemptyset(&newmask);
            sigaddset(&newmask, 14);
            sigaddset(&newmask, 2);
            sigaddset(&newmask, 10);
            sigaddset(&newmask, 12);
            sigprocmask(0, &newmask, &oldmask);
        }
    }
    else
    {
        current_process->atomic_count--;
        ((void) sizeof ((current_process->atomic_count >= 0) ? 1 : 0), __extension__ ({ if (current_process->atomic_count >= 0) ; else __assert_fail ("current_process->atomic_count >= 0", "src/k_atomic.c", 38, __extension__ __PRETTY_FUNCTION__); }));
        if (current_process->atomic_count == 0)
        {
            sigprocmask(2, &oldmask, ((void *)0));
        }
    }
}

canonical_original_code:
void atomic(int on_off)
{
    static struct __sigset_t oldmask;
    struct __sigset_t newmask;
    if (on_off == 1)
    {
        current_process->atomic_count++;
        if (current_process->atomic_count == 1)
        {
            sigemptyset(&newmask);
            sigaddset(&newmask, 14);
            sigaddset(&newmask, 2);
            sigaddset(&newmask, 10);
            sigaddset(&newmask, 12);
            sigprocmask(0, &newmask, &oldmask);
        }
    }
    else
    {
        current_process->atomic_count--;
        ((void) sizeof ((current_process->atomic_count >= 0) ? 1 : 0), __extension__ ({ if (current_process->atomic_count >= 0) ; else __assert_fail ("current_process->atomic_count >= 0", "src/k_atomic.c", 38, __extension__ __PRETTY_FUNCTION__); }));
        if (current_process->atomic_count == 0)
        {
            sigprocmask(2, &oldmask, ((void *)0));
        }
    }
}

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