decompiled_code:
void find_TXToutputSoilReg_inUse()
{
unsigned __int64 v0; // rdi
__int64 v1; // rcx
unsigned __int16 v2; // si
__int64 v3; // rdx

*(_QWORD *)SW_OutFiles = 0LL;
v0 = (unsigned int)((_DWORD)&SW_Output + 16);
v1 = 0LL;
v2 = used_OUTNPERIODS;
*(_QWORD *)&SW_OutFiles[2] = 0LL;
*(_QWORD *)&SW_OutFiles[4] = 0LL;
*(_QWORD *)&SW_OutFiles[6] = 0LL;
do
{
v3 = 0LL;
if ( v2 )
{
while ( 1 )
{
if ( *(_WORD *)((char *)&timeSteps + 2 * v3 + v1) == 999 )
goto LABEL_5;
if ( *(_DWORD *)v0 )
{
SW_OutFiles[*(unsigned __int16 *)((char *)&timeSteps + 2 * v3 + v1)] = 1;
LABEL_5:
if ( v2 <= (unsigned __int16)++v3 )
break;
}
else
{
SW_OutFiles[*(unsigned __int16 *)((char *)&timeSteps + 2 * v3++ + v1) + 4] = 1;
if ( v2 <= (unsigned __int16)v3 )
break;
}
}
}
v0 += 48LL;
v1 += 8LL;
}
while ( (_DWORD)&SW_Output + 1552 != v0 );
}

canonical_decompiled_code:
void func6()
{
unsigned __int64 v0; // rdi
__int64 v1; // rcx
unsigned __int16 v2; // si
__int64 v3; // rdx

*(_QWORD *)SW_OutFiles = 0LL;
v0 = (unsigned int)((_DWORD)&SW_Output + 16);
v1 = 0LL;
v2 = used_OUTNPERIODS;
*(_QWORD *)&SW_OutFiles[2] = 0LL;
*(_QWORD *)&SW_OutFiles[4] = 0LL;
*(_QWORD *)&SW_OutFiles[6] = 0LL;
do
{
v3 = 0LL;
if ( v2 )
{
while ( 1 )
{
if ( *(_WORD *)((char *)&timeSteps + 2 * v3 + v1) == 999 )
goto LABEL_5;
if ( *(_DWORD *)v0 )
{
SW_OutFiles[*(unsigned __int16 *)((char *)&timeSteps + 2 * v3 + v1)] = 1;
LABEL_5:
if ( v2 <= (unsigned __int16)++v3 )
break;
}
else
{
SW_OutFiles[*(unsigned __int16 *)((char *)&timeSteps + 2 * v3++ + v1) + 4] = 1;
if ( v2 <= (unsigned __int16)v3 )
break;
}
}
}
v0 += 48LL;
v1 += 8LL;
}
while ( (_DWORD)&SW_Output + 1552 != v0 );
}

original_code:
void find_TXToutputSoilReg_inUse(void)
{
 IntUS i;
 OutKey k;
 for((i)=0; (i)<=3; (i)++)
 {
  SW_OutFiles.make_soil[i] = swFALSE;
  SW_OutFiles.make_regular[i] = swFALSE;
 }
 for((k)=eSW_NoKey+1; (k)<eSW_LastKey; (k)++)
 {
  for (i = 0; i < used_OUTNPERIODS; i++)
  {
   if (timeSteps[k][i] != 999)
   {
    if (SW_Output[k].has_sl)
    {
     SW_OutFiles.make_soil[timeSteps[k][i]] = swTRUE;
    } else
    {
     SW_OutFiles.make_regular[timeSteps[k][i]] = swTRUE;
    }
   }
  }
 }
}

canonical_original_code:
void find_TXToutputSoilReg_inUse()
{
 unsigned short i;
 enum OutKey k;
 for((i)=0; (i)<=3; (i)++)
 {
  SW_OutFiles.make_soil[i] = swFALSE;
  SW_OutFiles.make_regular[i] = swFALSE;
 }
 for((k)=eSW_NoKey+1; (k)<eSW_LastKey; (k)++)
 {
  for (i = 0; i < used_OUTNPERIODS; i++)
  {
   if (timeSteps[k][i] != 999)
   {
    if (SW_Output[k].has_sl)
    {
     SW_OutFiles.make_soil[timeSteps[k][i]] = swTRUE;
    } else
    {
     SW_OutFiles.make_regular[timeSteps[k][i]] = swTRUE;
    }
   }
  }
 }
}

variable_types:
i
unsigned short

variable_types: enum OutKey { eSW_NoKey=-1, eSW_AllWthr=0, eSW_Temp=1, eSW_Precip=2, eSW_SoilInf=3, eSW_Runoff=4, eSW_AllH2O=5, eSW_VWCBulk=6, eSW_VWCMatric=7, eSW_SWCBulk=8, eSW_SWABulk=9, eSW_SWAMatric=10, eSW_SWA=11, eSW_SWPMatric=12, eSW_SurfaceWater=13, eSW_Transp=14, eSW_EvapSoil=15, eSW_EvapSurface=16, eSW_Interception=17, eSW_LyrDrain=18, eSW_HydRed=19, eSW_ET=20, eSW_AET=21, eSW_PET=22, eSW_WetDays=23, eSW_SnowPack=24, eSW_DeepSWC=25, eSW_SoilTemp=26, eSW_Frozen=27, eSW_AllVeg=28, eSW_Estab=29, eSW_CO2Effects=30, eSW_Biomass=31, eSW_LastKey=32 }


repo: Burke-Lauenroth-Lab/SOILWAT

decompiled_code:
__int64 SW_OUT_close_files()
{
__int64 v0; // rbp
__int64 i; // rbx
__int64 result; // rax
int v3; // er12

v0 = (unsigned int)((_DWORD)SW_OutFiles + 12064);
for ( i = 0LL; i != 4; ++i )
{
if ( *(_DWORD *)((char *)&use_OutPeriod + i * 4) )
{
result = (unsigned int)SW_OutFiles[i + 4];
v3 = SW_OutFiles[i];
if ( (_DWORD)result )
result = CloseFile(v0 - 12032);
if ( v3 )
result = CloseFile(v0);
}
v0 += 8LL;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbp
__int64 i; // rbx
__int64 result; // rax
int v3; // er12

v0 = (unsigned int)((_DWORD)SW_OutFiles + 12064);
for ( i = 0LL; i != 4; ++i )
{
if ( *(_DWORD *)((char *)&use_OutPeriod + i * 4) )
{
result = (unsigned int)SW_OutFiles[i + 4];
v3 = SW_OutFiles[i];
if ( (_DWORD)result )
result = CloseFile(v0 - 12032);
if ( v3 )
result = CloseFile(v0);
}
v0 += 8LL;
}
return result;
}

original_code:
void SW_OUT_close_files(void) {
 Bool close_regular, close_layers, close_aggs;
 OutPeriod p;
 for((p)=0; (p)<=3; (p)++) {
  close_regular = SW_OutFiles.make_regular[p];
  close_layers = SW_OutFiles.make_soil[p];
  close_aggs = swFALSE;
  if (use_OutPeriod[p]) {
   if (close_regular) {
    CloseFile(&SW_OutFiles.fp_reg[p]);
   }
   if (close_layers) {
    CloseFile(&SW_OutFiles.fp_soil[p]);
   }
   if (close_aggs) {
   }
  }
 }
}

canonical_original_code:
void SW_OUT_close_files() {
 enum Bool close_regular; enum Bool close_layers; enum Bool close_aggs;
 unsigned short p;
 for((p)=0; (p)<=3; (p)++) {
  close_regular = SW_OutFiles.make_regular[p];
  close_layers = SW_OutFiles.make_soil[p];
  close_aggs = swFALSE;
  if (use_OutPeriod[p]) {
   if (close_regular) {
    CloseFile(&SW_OutFiles.fp_reg[p]);
   }
   if (close_layers) {
    CloseFile(&SW_OutFiles.fp_soil[p]);
   }
   if (close_aggs) {
   }
  }
 }
}

variable_types:
p
unsigned short

return_type: void


decompiled_code:
void Time_init_model()
{
days_in_month = (__int128)_mm_load_si128((const __m128i *)&monthdays);
xmmword_310 = (__int128)_mm_load_si128((const __m128i *)&xmmword_350);
xmmword_320 = (__int128)_mm_load_si128((const __m128i *)&xmmword_360);
}

canonical_decompiled_code:
void func0()
{
days_in_month = (__int128)_mm_load_si128((const __m128i *)&monthdays);
xmmword_310 = (__int128)_mm_load_si128((const __m128i *)&xmmword_350);
xmmword_320 = (__int128)_mm_load_si128((const __m128i *)&xmmword_360);
}

original_code:
void Time_init_model(void) {
 memcpy(days_in_month, monthdays, sizeof(TimeInt) * 12);
}

canonical_original_code:
void Time_init_model() {
 memcpy(days_in_month, monthdays, sizeof(TimeInt) * 12);
}


decompiled_code:
__int64 __fastcall Time_days_in_month(unsigned int a1)
{
return *((unsigned int *)&days_in_month + a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return *((unsigned int *)&days_in_month + a1);
}

original_code:
TimeInt Time_days_in_month(TimeInt month) {
 return days_in_month[month];
}

canonical_original_code:
unsigned int Time_days_in_month(unsigned int month) {
 return days_in_month[month];
}

variable_types:
month
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall doy2month(unsigned int a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( cum_monthdays[v1] >= a1 )
break;
if ( ++v1 == 11 )
return 11;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( cum_monthdays[v1] >= a1 )
break;
if ( ++v1 == 11 )
return 11;
}
return v2;
}

original_code:
TimeInt doy2month(const TimeInt doy) {
 TimeInt mon;
 for (mon = 0; mon < 11 && doy > cum_monthdays[mon]; mon++)
  ;
 return mon;
}

canonical_original_code:
unsigned int doy2month(unsigned int doy) {
 unsigned int mon;
 for (mon = 0; mon < 11 && doy > cum_monthdays[mon]; mon++)
  ;
 return mon;
}

variable_types:
doy
unsigned int

variable_types:
mon
unsigned int


decompiled_code:
__int64 __fastcall doy2mday(unsigned int a1)
{
unsigned int v1; // er9
int v2; // eax
int v3; // er9

v1 = a1;
if ( (unsigned int)days_in_month < a1 )
{
v2 = doy2month(a1);
v1 = v3 - cum_monthdays[v2 - 1];
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
unsigned int v1; // er9
int v2; // eax
int v3; // er9

v1 = a1;
if ( (unsigned int)days_in_month < a1 )
{
v2 = func2(a1);
v1 = v3 - cum_monthdays[v2 - 1];
}
return v1;
}

original_code:
TimeInt doy2mday(const TimeInt doy) {
  return (doy <= days_in_month[0]) ? doy : doy - cum_monthdays[doy2month(doy) - 1];
}

canonical_original_code:
unsigned int doy2mday(unsigned int doy) {
  return (doy <= days_in_month[0]) ? doy : doy - cum_monthdays[doy2month(doy) - 1];
}


decompiled_code:
__int64 __fastcall doy2week(int a1)
{
return (a1 - 1) / 7u;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return (a1 - 1) / 7u;
}

original_code:
TimeInt doy2week(TimeInt doy) {
 return ((TimeInt) (((doy) - 1) / 7));
}

canonical_original_code:
unsigned int doy2week(unsigned int doy) {
 return ((TimeInt) (((doy) - 1) / 7));
}


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

result = a1;
if ( a1 <= 0x64 )
{
result = a1 + 2000;
if ( a1 > 0x31 )
result = a1 + 1900;
}
return result;
}

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

result = a1;
if ( a1 <= 0x64 )
{
result = a1 + 2000;
if ( a1 > 0x31 )
result = a1 + 1900;
}
return result;
}

original_code:
TimeInt yearto4digit(TimeInt yr) {
 return (TimeInt) ((yr > 100) ? yr : (yr < 50) ? 2000 + yr : 1900 + yr);
}

canonical_original_code:
unsigned int yearto4digit(unsigned int yr) {
 return (TimeInt) ((yr > 100) ? yr : (yr < 50) ? 2000 + yr : 1900 + yr);
}

variable_types:
yr
unsigned int


isleapyear

decompiled_code:
__int64 __fastcall isleapyear(unsigned int a1)
{
unsigned int v1; // er8
__int64 result; // rax

v1 = 0;
if ( (a1 & 3) == 0 && (v1 = 1, a1 == 100 * (a1 / 0x64)) )
result = __ROR4__(a1 / 0x64, 2) <= 0xA3D70Au;
else
result = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
unsigned int v1; // er8
__int64 result; // rax

v1 = 0;
if ( (a1 & 3) == 0 && (v1 = 1, a1 == 100 * (a1 / 0x64)) )
result = __ROR4__(a1 / 0x64, 2) <= 0xA3D70Au;
else
result = v1;
return result;
}

original_code:
Bool isleapyear(const TimeInt year) {
 TimeInt t = (year / 100) * 100;
 return (Bool) (((year % 4) == 0) && (((t) != year) || ((year % 400) == 0)));
}

canonical_original_code:
enum Bool isleapyear(unsigned int year) {
 unsigned int t = (year / 100) * 100;
 return (Bool) (((year % 4) == 0) && (((t) != year) || ((year % 400) == 0)));
}

variable_types:
year
unsigned int

variable_types:
t
unsigned int

return_type: enum Bool { swFALSE=expr, swTRUE=expr }


decompiled_code:
__int64 __fastcall Time_new_year(unsigned int a1)
{
int v1; // eax
int v2; // ecx
int v3; // edx
__int64 result; // rax

v1 = isleapyear(a1);
v2 = days_in_month;
v3 = 28 - ((v1 == 0) - 1);
cum_monthdays[0] = days_in_month;
result = 0LL;
DWORD1(days_in_month) = v3;
while ( 1 )
{
cum_monthdays[++result] = v2 + v3;
if ( result == 11 )
break;
v3 = *(_DWORD *)((char *)&days_in_month + result * 4 + 4);
v2 = cum_monthdays[result];
}
return result * 4;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
int v1; // eax
int v2; // ecx
int v3; // edx
__int64 result; // rax

v1 = func6(a1);
v2 = days_in_month;
v3 = 28 - ((v1 == 0) - 1);
cum_monthdays[0] = days_in_month;
result = 0LL;
DWORD1(days_in_month) = v3;
while ( 1 )
{
cum_monthdays[++result] = v2 + v3;
if ( result == 11 )
break;
v3 = *(_DWORD *)((char *)&days_in_month + result * 4 + 4);
v2 = cum_monthdays[result];
}
return result * 4;
}

original_code:
void Time_new_year(TimeInt year) {
 TimeInt m;
 days_in_month[1] = isleapyear(year) ? 29 : 28;
 cum_monthdays[0] = days_in_month[0];
 for (m = 1; m < 12; m++)
 {
  cum_monthdays[m] = days_in_month[m] + cum_monthdays[m - 1];
 }
}

canonical_original_code:
void Time_new_year(unsigned int year) {
 unsigned int m;
 days_in_month[1] = isleapyear(year) ? 29 : 28;
 cum_monthdays[0] = days_in_month[0];
 for (m = 1; m < 12; m++)
 {
  cum_monthdays[m] = days_in_month[m] + cum_monthdays[m - 1];
 }
}

variable_types:
m
unsigned int


decompiled_code:
__int64 __fastcall Time_get_lastdoy_y(unsigned int a1)
{
return 365 - ((unsigned int)((unsigned int)isleapyear(a1) == 0) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return 365 - ((unsigned int)((unsigned int)func6(a1) == 0) - 1);
}

original_code:
TimeInt Time_get_lastdoy_y(TimeInt year) {
 return isleapyear(year) ? 366 : 365;
}

canonical_original_code:
unsigned int Time_get_lastdoy_y(unsigned int year) {
 return isleapyear(year) ? 366 : 365;
}


decompiled_code:
__int64 __fastcall interpolate_monthlyValues(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
unsigned int v4; // ecx
double *v5; // rsi
double *v6; // r8
int v7; // eax
__int64 v8; // xmm0_8
double v9; // xmm1_8
__int64 result; // rax
unsigned int v11; // edi
unsigned int v12; // eax
int v13; // edx
int v14; // ecx
double *v15; // r10
int v16; // er11
double v17; // xmm2_8
__int64 v18; // rax
__int64 v19; // r8

if ( a2 )
{
v3 = 0;
a2 = 1;
}
else
{
v3 = 1;
}
v4 = a2 + v3;
v5 = (double *)(a3 + 8LL * a2);
while ( 1 )
{
v11 = v4;
doy2mday(v4);
v12 = doy2month(v11);
v17 = v15[v12];
if ( v13 != 15 )
break;
*v5 = v17;
result = (unsigned int)(v14 + 1);
++v5;
if ( v14 == v16 )
return result;
LABEL_9:
v4 = result;
}
if ( (unsigned int)v13 <= 0xE )
{
if ( v12 )
{
v18 = v12 - 1;
v19 = (unsigned int)v18;
}
else
{
v19 = 11LL;
v18 = 11LL;
}
v7 = *((_DWORD *)&days_in_month + v18);
v6 = &v15[v19];
v8 = LC1;
}
else
{
v6 = v15;
if ( v12 != 11 )
v6 = &v15[v12 + 1];
v7 = *((_DWORD *)&days_in_month + v12);
v8 = LC0;
}
++v5;
v9 = (double)v7;
result = (unsigned int)(v14 + 1);
*(v5 - 1) = ((double)v13 - 15.0) * ((*v6 - v17) * *(double *)&v8) / v9 + v17;
if ( v14 != v16 )
goto LABEL_9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
unsigned int v4; // ecx
double *v5; // rsi
double *v6; // r8
int v7; // eax
__int64 v8; // xmm0_8
double v9; // xmm1_8
__int64 result; // rax
unsigned int v11; // edi
unsigned int v12; // eax
int v13; // edx
int v14; // ecx
double *v15; // r10
int v16; // er11
double v17; // xmm2_8
__int64 v18; // rax
__int64 v19; // r8

if ( a2 )
{
v3 = 0;
a2 = 1;
}
else
{
v3 = 1;
}
v4 = a2 + v3;
v5 = (double *)(a3 + 8LL * a2);
while ( 1 )
{
v11 = v4;
func3(v4);
v12 = func2(v11);
v17 = v15[v12];
if ( v13 != 15 )
break;
*v5 = v17;
result = (unsigned int)(v14 + 1);
++v5;
if ( v14 == v16 )
return result;
LABEL_9:
v4 = result;
}
if ( (unsigned int)v13 <= 0xE )
{
if ( v12 )
{
v18 = v12 - 1;
v19 = (unsigned int)v18;
}
else
{
v19 = 11LL;
v18 = 11LL;
}
v7 = *((_DWORD *)&days_in_month + v18);
v6 = &v15[v19];
v8 = LC1;
}
else
{
v6 = v15;
if ( v12 != 11 )
v6 = &v15[v12 + 1];
v7 = *((_DWORD *)&days_in_month + v12);
v8 = LC0;
}
++v5;
v9 = (double)v7;
result = (unsigned int)(v14 + 1);
*(v5 - 1) = ((double)v13 - 15.0) * ((*v6 - v17) * *(double *)&v8) / v9 + v17;
if ( v14 != v16 )
goto LABEL_9;
return result;
}

original_code:
void interpolate_monthlyValues(double monthlyValues[], Bool interpAsBase1,
                               double dailyValues[]) {
 unsigned int doy, mday, month, month2 = 12, nmdays;
    unsigned int startdoy = 1, endDay = 366, doyOffset = 0;
 double sign = 1.;
    if(!interpAsBase1) {
        startdoy = 0;
        endDay = 366 - 1;
        doyOffset = 1;
    }
 for (doy = startdoy; doy <= endDay; doy++) {
  mday = doy2mday(doy + doyOffset);
  month = doy2month(doy + doyOffset);
  if (mday == 15) {
   dailyValues[doy] = monthlyValues[month];
  } else {
   if (mday >= 15) {
    month2 = (month == 11) ? 0 : month + 1;
    sign = 1;
    nmdays = days_in_month[month];
   } else {
    month2 = (month == 0) ? 11 : month - 1;
    sign = -1;
    nmdays = days_in_month[month2];
   }
   dailyValues[doy] = monthlyValues[month]
     + sign * (monthlyValues[month2] - monthlyValues[month])
     * (mday - 15.) / nmdays;
  }
 }
}

canonical_original_code:
void interpolate_monthlyValues(double monthlyValues[], enum Bool interpAsBase1, double dailyValues[]) {
 unsigned int doy; unsigned int mday; unsigned int month; unsigned int month2 = 12; unsigned int nmdays;
    unsigned int startdoy = 1; unsigned int endDay = 366; unsigned int doyOffset = 0;
 double sign = 1.;
    if(!interpAsBase1) {
        startdoy = 0;
        endDay = 366 - 1;
        doyOffset = 1;
    }
 for (doy = startdoy; doy <= endDay; doy++) {
  mday = doy2mday(doy + doyOffset);
  month = doy2month(doy + doyOffset);
  if (mday == 15) {
   dailyValues[doy] = monthlyValues[month];
  } else {
   if (mday >= 15) {
    month2 = (month == 11) ? 0 : month + 1;
    sign = 1;
    nmdays = days_in_month[month];
   } else {
    month2 = (month == 0) ? 11 : month - 1;
    sign = -1;
    nmdays = days_in_month[month2];
   }
   dailyValues[doy] = monthlyValues[month]
     + sign * (monthlyValues[month2] - monthlyValues[month])
     * (mday - 15.) / nmdays;
  }
 }
}

variable_types:
monthlyValues
double []

variable_types:
dailyValues
double []

variable_types:
mday
unsigned int

variable_types:
nmdays
unsigned int

variable_types:
startdoy
unsigned int

variable_types:
endDay
unsigned int

variable_types:
doyOffset
unsigned int

variable_types: sign double


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

result = Time_init_model();
*(_QWORD *)(&SW_Model + 13) = 1LL;
*(_QWORD *)(&SW_Model + 15) = 0LL;
return result;
}

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

result = Time_init_model();
*(_QWORD *)(&SW_Model + 13) = 1LL;
*(_QWORD *)(&SW_Model + 15) = 0LL;
return result;
}

original_code:
void SW_MDL_construct(void) {
 OutPeriod pd;
 Time_init_model();
 for((pd)=0; (pd)<=3; (pd)++)
 {
  SW_Model.newperiod[pd] = swFALSE;
 }
 SW_Model.newperiod[0] = swTRUE;
}

canonical_original_code:
void SW_MDL_construct() {
 unsigned short pd;
 Time_init_model();
 for((pd)=0; (pd)<=3; (pd)++)
 {
  SW_Model.newperiod[pd] = swFALSE;
 }
 SW_Model.newperiod[0] = swTRUE;
}

variable_types:
pd
unsigned short


decompiled_code:
void SW_MDL_deconstruct()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void SW_MDL_deconstruct(void)
{}

canonical_original_code:
void SW_MDL_deconstruct()
{}


decompiled_code:
__int64 __fastcall SW_MDL_new_year(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
int v3; // eax
bool v4; // zf
__int64 result; // rax

v2 = SW_Model[10];
prevmonth = 0xFFFF;
prevweek = 0xFFFF;
Time_new_year(v2);
SW_Model[11] = SW_Model[10] + SW_Model[12];
v3 = 1;
if ( SW_Model[0] == v2 )
v3 = SW_Model[2];
v4 = SW_Model[1] == v2;
SW_Model[5] = v3;
result = (unsigned int)SW_Model[3];
if ( !v4 )
result = Time_get_lastdoy_y(v2, a2);
SW_Model[6] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
int v3; // eax
bool v4; // zf
__int64 result; // rax

v2 = SW_Model[10];
prevmonth = 0xFFFF;
prevweek = 0xFFFF;
Time_new_year(v2);
SW_Model[11] = SW_Model[10] + SW_Model[12];
v3 = 1;
if ( SW_Model[0] == v2 )
v3 = SW_Model[2];
v4 = SW_Model[1] == v2;
SW_Model[5] = v3;
result = (unsigned int)SW_Model[3];
if ( !v4 )
result = Time_get_lastdoy_y(v2, a2);
SW_Model[6] = result;
return result;
}

original_code:
void SW_MDL_new_year(void) {
 SW_MODEL *m = &SW_Model;
 TimeInt year = SW_Model.year;
 _prevweek = _prevmonth = _prevyear = _notime;
 Time_new_year(year);
 SW_Model.simyear = SW_Model.year + SW_Model.addtl_yr;
 m->firstdoy = (year == m->startyr) ? m->startstart : 1;
 m->lastdoy = (year == m->endyr) ? m->endend : Time_get_lastdoy_y(year);
}

canonical_original_code:
void SW_MDL_new_year() {
 struct SW_MODEL *m = &SW_Model;
 unsigned int year = SW_Model.year;
 _prevweek = _prevmonth = _prevyear = _notime;
 Time_new_year(year);
 SW_Model.simyear = SW_Model.year + SW_Model.addtl_yr;
 m->firstdoy = (year == m->startyr) ? m->startstart : 1;
 m->lastdoy = (year == m->endyr) ? m->endend : Time_get_lastdoy_y(year);
}

variable_types: struct SW_MODEL { unsigned int startyr; int addtl_yr; enum Bool { swFALSE=expr, swTRUE=expr } newperiod[4]; enum Bool { swFALSE=expr, swTRUE=expr } isnorth; } *

user_defined_types: struct SW_MODEL { unsigned int startyr; int addtl_yr; enum Bool newperiod[4]; enum Bool isnorth; }


decompiled_code:
__int64 SW_MDL_new_day()
{
int v0; // eax
__int64 v1; // rdi
__int64 result; // rax
bool v3; // cc
int v4; // ecx
int v5; // edx

v0 = doy2month((unsigned int)SW_Model[7]);
v1 = (unsigned int)SW_Model[7];
SW_Model[9] = v0;
result = doy2week(v1);
v3 = SW_Model[7] <= (unsigned int)SW_Model[6];
SW_Model[8] = result;
if ( v3 )
{
v4 = prevmonth;
if ( SW_Model[9] == prevmonth )
{
SW_Model[15] = 0;
v5 = prevweek;
if ( (_DWORD)result != prevweek )
goto LABEL_4;
}
else
{
prevmonth = SW_Model[9];
v5 = prevweek;
SW_Model[15] = v4 != 0xFFFF;
if ( (_DWORD)result != v5 )
{
LABEL_4:
prevweek = result;
SW_Model[14] = v5 != 0xFFFF;
return result;
}
}
SW_Model[14] = 0;
}
else
{
result = 0x100000001LL;
*(_QWORD *)&SW_Model[13] = 0x100000001LL;
*(_QWORD *)&SW_Model[15] = 0x100000001LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
__int64 v1; // rdi
__int64 result; // rax
bool v3; // cc
int v4; // ecx
int v5; // edx

v0 = doy2month((unsigned int)SW_Model[7]);
v1 = (unsigned int)SW_Model[7];
SW_Model[9] = v0;
result = doy2week(v1);
v3 = SW_Model[7] <= (unsigned int)SW_Model[6];
SW_Model[8] = result;
if ( v3 )
{
v4 = prevmonth;
if ( SW_Model[9] == prevmonth )
{
SW_Model[15] = 0;
v5 = prevweek;
if ( (_DWORD)result != prevweek )
goto LABEL_4;
}
else
{
prevmonth = SW_Model[9];
v5 = prevweek;
SW_Model[15] = v4 != 0xFFFF;
if ( (_DWORD)result != v5 )
{
LABEL_4:
prevweek = result;
SW_Model[14] = v5 != 0xFFFF;
return result;
}
}
SW_Model[14] = 0;
}
else
{
result = 0x100000001LL;
*(_QWORD *)&SW_Model[13] = 0x100000001LL;
*(_QWORD *)&SW_Model[15] = 0x100000001LL;
}
return result;
}

original_code:
void SW_MDL_new_day(void) {
 OutPeriod pd;
 SW_Model.month = doy2month(SW_Model.doy);
 SW_Model.week = doy2week(SW_Model.doy);
 if (SW_Model.doy > SW_Model.lastdoy) {
  for((pd)=0; (pd)<=3; (pd)++)
  {
  SW_Model.newperiod[pd] = swTRUE;
  }
  return;
 }
 if (SW_Model.month != _prevmonth) {
  SW_Model.newperiod[2] = (_prevmonth != _notime) ? swTRUE : swFALSE;
  _prevmonth = SW_Model.month;
 } else
  SW_Model.newperiod[2] = swFALSE;
 if (SW_Model.week != _prevweek) {
  SW_Model.newperiod[1] = (_prevweek != _notime) ? swTRUE : swFALSE;
  _prevweek = SW_Model.week;
 } else
  SW_Model.newperiod[1] = swFALSE;
}

canonical_original_code:
void SW_MDL_new_day() {
 unsigned short pd;
 SW_Model.month = doy2month(SW_Model.doy);
 SW_Model.week = doy2week(SW_Model.doy);
 if (SW_Model.doy > SW_Model.lastdoy) {
  for((pd)=0; (pd)<=3; (pd)++)
  {
  SW_Model.newperiod[pd] = swTRUE;
  }
  return;
 }
 if (SW_Model.month != _prevmonth) {
  SW_Model.newperiod[2] = (_prevmonth != _notime) ? swTRUE : swFALSE;
  _prevmonth = SW_Model.month;
 } else
  SW_Model.newperiod[2] = swFALSE;
 if (SW_Model.week != _prevweek) {
  SW_Model.newperiod[1] = (_prevweek != _notime) ? swTRUE : swFALSE;
  _prevweek = SW_Model.week;
 } else
  SW_Model.newperiod[1] = swFALSE;
}


RandSeed

decompiled_code:
__int64 __fastcall RandSeed(__int64 a1, __int64 a2, __int64 a3)
{
time_t v4; // r12
time_t v5; // rax

if ( a1 )
return pcg32_srandom_r(a3, a1, a2);
v4 = time(0LL) + a2;
v5 = time(0LL);
return pcg32_srandom_r(a3, v5, v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
time_t v4; // r12
time_t v5; // rax

if ( a1 )
return pcg32_srandom_r(a3, a1, a2);
v4 = time(0LL) + a2;
v5 = time(0LL);
return pcg32_srandom_r(a3, v5, v4);
}

original_code:
void RandSeed(
  unsigned long initstate,
  unsigned long initseq,
  pcg32_random_t* pcg_rng
) {
  if (initstate == 0u) {
    pcg32_srandom_r(pcg_rng, time(((void *)0)), initseq + time(((void *)0)));
  } else {
    pcg32_srandom_r(pcg_rng, initstate, initseq);
  }
}

canonical_original_code:
void RandSeed(unsigned long initstate, unsigned long initseq, struct pcg_state_setseq_64 *pcg_rng) {
  if (initstate == 0u) {
    pcg32_srandom_r(pcg_rng, time(((void *)0)), initseq + time(((void *)0)));
  } else {
    pcg32_srandom_r(pcg_rng, initstate, initseq);
  }
}

variable_types:
initstate
unsigned long

variable_types:
initseq
unsigned long

variable_types: struct pcg_state_setseq_64 { unsigned long state; unsigned long inc; } *


RandUni

decompiled_code:
void RandUni()
{
int v0; // eax

v0 = pcg32_random_r();
ldexp((double)v0, -32);
}

canonical_decompiled_code:
void func1()
{
int v0; // eax

v0 = pcg32_random_r();
ldexp((double)v0, -32);
}

original_code:
double RandUni(pcg32_random_t* pcg_rng) {
  double res;
    res = ldexp(pcg32_random_r(pcg_rng), -32);
  return res;
}

canonical_original_code:
double RandUni(struct pcg_state_setseq_64 *pcg_rng) {
  double res;
    res = ldexp(pcg32_random_r(pcg_rng), -32);
  return res;
}

variable_types: res double

return_type: double

user_defined_types: struct pcg_state_setseq_64 { unsigned long state; unsigned long inc; }


RandUniIntRange

decompiled_code:
__int64 __fastcall RandUniIntRange(__int64 a1, __int64 a2, __int64 a3)
{
bool v3; // cc
__int64 v4; // rbx
__int64 v5; // rsi

v3 = a1 <= a2;
if ( a1 == a2 )
return (unsigned int)a1;
v4 = a2;
v5 = a1 + 1;
if ( v3 )
{
v5 = v4 + 1;
v4 = a1;
}
return (unsigned int)v4 + (unsigned int)pcg32_boundedrand_r(a3, v5 - v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
bool v3; // cc
__int64 v4; // rbx
__int64 v5; // rsi

v3 = a1 <= a2;
if ( a1 == a2 )
return (unsigned int)a1;
v4 = a2;
v5 = a1 + 1;
if ( v3 )
{
v5 = v4 + 1;
v4 = a1;
}
return (unsigned int)v4 + (unsigned int)pcg32_boundedrand_r(a3, v5 - v4);
}

original_code:
int RandUniIntRange(const long first, const long last, pcg32_random_t* pcg_rng) {
  long f, l, res;
  if (first == last)
    return first;
  if (first > last) {
    l = first + 1;
    f = last;
  } else {
    f = first;
    l = last + 1;
  }
    long r = l - f;
    res = pcg32_boundedrand_r(pcg_rng, r) + f;
  return res;
}

canonical_original_code:
int RandUniIntRange(long first, long last, struct pcg_state_setseq_64 *pcg_rng) {
  long f; long l; long res;
  if (first == last)
    return first;
  if (first > last) {
    l = first + 1;
    f = last;
  } else {
    f = first;
    l = last + 1;
  }
    long r = l - f;
    res = pcg32_boundedrand_r(pcg_rng, r) + f;
  return res;
}

variable_types: first long

variable_types: last long

variable_types: f long

variable_types: l long

variable_types: res long

variable_types: r long

return_type: int


RandUniFloatRange

decompiled_code:
float __fastcall RandUniFloatRange(double a1, double a2)
{
float v2; // xmm0_4
double v3; // xmm2_8

if ( *(float *)&a2 != *(float *)&a1 )
{
if ( *(float *)&a1 <= *(float *)&a2 )
{
v3 = a2;
LODWORD(a2) = LODWORD(a1);
a1 = v3;
}
RandUni();
v2 = a1 * (float)(*(float *)&a1 - *(float *)&a2);
*(float *)&a1 = v2 + *(float *)&a2;
}
return *(float *)&a1;
}

canonical_decompiled_code:
float __fastcall func3(double a1, double a2)
{
float v2; // xmm0_4
double v3; // xmm2_8

if ( *(float *)&a2 != *(float *)&a1 )
{
if ( *(float *)&a1 <= *(float *)&a2 )
{
v3 = a2;
LODWORD(a2) = LODWORD(a1);
a1 = v3;
}
func1();
v2 = a1 * (float)(*(float *)&a1 - *(float *)&a2);
*(float *)&a1 = v2 + *(float *)&a2;
}
return *(float *)&a1;
}

original_code:
float RandUniFloatRange(const float min, const float max, pcg32_random_t* pcg_rng) {
 float f, l, r;
 if (max == min)
  return min;
 if (min > max) {
  l = min;
  f = max;
 } else {
  f = min;
  l = max;
 }
 r = l - f;
 return (float) (RandUni(pcg_rng) * r) + f;
}

canonical_original_code:
float RandUniFloatRange(float min, float max, struct pcg_state_setseq_64 *pcg_rng) {
 float f; float l; float r;
 if (max == min)
  return min;
 if (min > max) {
  l = min;
  f = max;
 } else {
  f = min;
  l = max;
 }
 r = l - f;
 return (float) (RandUni(pcg_rng) * r) + f;
}

variable_types: min float

variable_types: max float

variable_types: f float

variable_types: l float

variable_types: r float

return_type: float


RandUniList

original_code:
void RandUniList(long count, long first, long last, RandListType list[], pcg32_random_t* pcg_rng) {
 long i, j, c, range, *klist;
 range = last - first + 1;
 if (count > range || range <= 0) {
    sw_error(-1, "Error in RandUniList: count > range || range <= 0\n");
 }
 if (count == range) {
  for (i = 0; i < count; i++)
   list[i] = first + i;
  return;
 }
 if (count <= 2) {
  list[0] = (long) RandUniIntRange(first, last, pcg_rng);
  if (count == 2) {
   while ((list[1] = RandUniIntRange(first, last, pcg_rng)) == list[0]);
  }
  return;
 }
 klist = (long *) Mem_Malloc(sizeof(long) * range, "RandUniList");
 for (i = 0, j = first; j <= last; klist[i++] = j++)
  ;
 for (i = 0; i < range; i++) {
  while ((j = RandUniIntRange(0, range - 1, pcg_rng)) == i)
   ;
  c = klist[i];
  klist[i] = klist[j];
  klist[j] = c;
 }
 for (i = 0; i < count; i++) {
  list[i] = klist[i];
 }
 Mem_Free(klist);
}

canonical_original_code:
void RandUniList(long count, long first, long last, long list[], struct pcg_state_setseq_64 *pcg_rng) {
 long i; long j; long c; long range; long *klist;
 range = last - first + 1;
 if (count > range || range <= 0) {
    sw_error(-1, "Error in RandUniList: count > range || range <= 0\n");
 }
 if (count == range) {
  for (i = 0; i < count; i++)
   list[i] = first + i;
  return;
 }
 if (count <= 2) {
  list[0] = (long) RandUniIntRange(first, last, pcg_rng);
  if (count == 2) {
   while ((list[1] = RandUniIntRange(first, last, pcg_rng)) == list[0]);
  }
  return;
 }
 klist = (long *) Mem_Malloc(sizeof(long) * range, "RandUniList");
 for (i = 0, j = first; j <= last; klist[i++] = j++)
  ;
 for (i = 0; i < range; i++) {
  while ((j = RandUniIntRange(0, range - 1, pcg_rng)) == i)
   ;
  c = klist[i];
  klist[i] = klist[j];
  klist[j] = c;
 }
 for (i = 0; i < count; i++) {
  list[i] = klist[i];
 }
 Mem_Free(klist);
}

variable_types: count long

variable_types:
list
long []

variable_types: i long

variable_types: j long

variable_types: c long

variable_types: range long

variable_types:
klist
long *


RandNorm

decompiled_code:
double __fastcall RandNorm(double a1, double a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm0_8
double v6; // [rsp+8h] [rbp-20h]
double v7; // [rsp+10h] [rbp-18h]

v7 = a1;
do
{
do
{
RandUni();
RandUni();
a1 = a1 + a1 - 1.0;
v2 = a1 * a1 + a1 * a1;
}
while ( v2 >= 1.0 );
}
while ( v2 == 0.0 );
v6 = a1 * a2;
v3 = log(v2) * -2.0 / v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
return v4 * v6 + v7;
}

canonical_decompiled_code:
double __fastcall func5(double a1, double a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm0_8
double v6; // [rsp+8h] [rbp-20h]
double v7; // [rsp+10h] [rbp-18h]

v7 = a1;
do
{
do
{
func1();
func1();
a1 = a1 + a1 - 1.0;
v2 = a1 * a1 + a1 * a1;
}
while ( v2 >= 1.0 );
}
while ( v2 == 0.0 );
v6 = a1 * a2;
v3 = log(v2) * -2.0 / v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
return v4 * v6 + v7;
}

original_code:
double RandNorm(double mean, double stddev, pcg32_random_t* pcg_rng) {
 double res;
  double v1, v2, r;
  do {
   v1 = 2.0 * RandUni(pcg_rng) - 1.0;
   v2 = 2.0 * RandUni(pcg_rng) - 1.0;
   r = v1 * v1 + v2 * v2;
  } while (r >= 1.0 || r == 0.);
  res = mean + stddev * v2 * ((sizeof(-2.0 * log(r) / r)==sizeof(float)) ? sqrtf(-2.0 * log(r) / r) : sqrt(-2.0 * log(r) / r));
 return res;
}

canonical_original_code:
double RandNorm(double mean, double stddev, struct pcg_state_setseq_64 *pcg_rng) {
 double res;
  double v1; double v2; double r;
  do {
   v1 = 2.0 * RandUni(pcg_rng) - 1.0;
   v2 = 2.0 * RandUni(pcg_rng) - 1.0;
   r = v1 * v1 + v2 * v2;
  } while (r >= 1.0 || r == 0.);
  res = mean + stddev * v2 * ((sizeof(-2.0 * log(r) / r)==sizeof(float)) ? sqrtf(-2.0 * log(r) / r) : sqrt(-2.0 * log(r) / r));
 return res;
}

variable_types: mean double

variable_types: stddev double

variable_types: struct pcg_state_setseq_64 { unsigned long state; unsigned long inc; } *

variable_types: res double

variable_types: r double


decompiled_code:
__int64 SW_SKY_new_year()
{
unsigned int v0; // ebx
int v1; // ebp
__int64 result; // rax

v0 = SW_Model[10];
if ( SW_Model[0] == v0 || (v1 = isleapyear(v0), result = isleapyear(v0 - 1), v1 != (_DWORD)result) )
result = interpolate_monthlyValues(
(unsigned int)((_DWORD)&SW_Sky + 288),
1LL,
(unsigned int)((_DWORD)&SW_Sky + 480));
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx
int v1; // ebp
__int64 result; // rax

v0 = SW_Model[10];
if ( SW_Model[0] == v0 || (v1 = isleapyear(v0), result = isleapyear(v0 - 1), v1 != (_DWORD)result) )
result = interpolate_monthlyValues(
(unsigned int)((_DWORD)&SW_Sky + 288),
1LL,
(unsigned int)((_DWORD)&SW_Sky + 480));
return result;
}

original_code:
void SW_SKY_new_year(void) {
 TimeInt year = SW_Model.year;
 SW_SKY *v = &SW_Sky;
    Bool interpAsBase1 = swTRUE;
  if (year == SW_Model.startyr || isleapyear(year) != isleapyear(year - 1)) {
    interpolate_monthlyValues(v->snow_density, interpAsBase1, v->snow_density_daily);
  }
}

canonical_original_code:
void SW_SKY_new_year() {
 unsigned int year = SW_Model.year;
 struct SW_SKY *v = &SW_Sky;
    enum Bool interpAsBase1 = swTRUE;
  if (year == SW_Model.startyr || isleapyear(year) != isleapyear(year - 1)) {
    interpolate_monthlyValues(v->snow_density, interpAsBase1, v->snow_density_daily);
  }
}

variable_types:
year
unsigned int

variable_types: struct SW_SKY { double cloudcov[12]; double snow_density_daily[-1]; } *


decompiled_code:
__int64 SW_CTL_setup_model()
{
SW_F_construct();
SW_MDL_construct();
SW_WTH_construct();
SW_SIT_construct();
SW_VES_construct();
SW_VPD_construct();
SW_OUT_construct();
SW_SWC_construct();
return SW_CBN_construct();
}

canonical_decompiled_code:
__int64 func3()
{
SW_F_construct();
SW_MDL_construct();
SW_WTH_construct();
SW_SIT_construct();
SW_VES_construct();
SW_VPD_construct();
SW_OUT_construct();
SW_SWC_construct();
return SW_CBN_construct();
}

original_code:
void SW_CTL_setup_model(const char *firstfile) {
 SW_F_construct(firstfile);
 SW_MDL_construct();
 SW_WTH_construct();
 SW_SIT_construct();
 SW_VES_construct();
 SW_VPD_construct();
 SW_OUT_construct();
 SW_SWC_construct();
 SW_CBN_construct();
}

canonical_original_code:
void SW_CTL_setup_model(char *firstfile) {
 SW_F_construct(firstfile);
 SW_MDL_construct();
 SW_WTH_construct();
 SW_SIT_construct();
 SW_VES_construct();
 SW_VPD_construct();
 SW_OUT_construct();
 SW_SWC_construct();
 SW_CBN_construct();
}

variable_types:
firstfile
char *


decompiled_code:
__int64 __fastcall SW_CTL_clear_model(unsigned int a1)
{
SW_F_deconstruct();
SW_MDL_deconstruct();
SW_WTH_deconstruct();
SW_SIT_deconstruct();
SW_VES_deconstruct();
SW_VPD_deconstruct();
SW_OUT_deconstruct(a1);
SW_SWC_deconstruct();
return SW_CBN_deconstruct();
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
SW_F_deconstruct();
SW_MDL_deconstruct();
SW_WTH_deconstruct();
SW_SIT_deconstruct();
SW_VES_deconstruct();
SW_VPD_deconstruct();
SW_OUT_deconstruct(a1);
SW_SWC_deconstruct();
return SW_CBN_deconstruct();
}

original_code:
void SW_CTL_clear_model(Bool full_reset) {
 SW_F_deconstruct();
 SW_MDL_deconstruct();
 SW_WTH_deconstruct();
 SW_SIT_deconstruct();
 SW_VES_deconstruct();
 SW_VPD_deconstruct();
 SW_OUT_deconstruct(full_reset);
 SW_SWC_deconstruct();
 SW_CBN_deconstruct();
}

canonical_original_code:
void SW_CTL_clear_model(enum Bool full_reset) {
 SW_F_deconstruct();
 SW_MDL_deconstruct();
 SW_WTH_deconstruct();
 SW_SIT_deconstruct();
 SW_VES_deconstruct();
 SW_VPD_deconstruct();
 SW_OUT_deconstruct(full_reset);
 SW_SWC_deconstruct();
 SW_CBN_deconstruct();
}


decompiled_code:
__int64 SW_CTL_init_run()
{
SW_WTH_init_run();
SW_PET_init_run();
SW_SIT_init_run();
SW_VES_init_run();
SW_VPD_init_run();
SW_FLW_init_run();
SW_ST_init_run();
SW_SWC_init_run();
return SW_CBN_init_run();
}

canonical_decompiled_code:
__int64 func5()
{
SW_WTH_init_run();
SW_PET_init_run();
SW_SIT_init_run();
SW_VES_init_run();
SW_VPD_init_run();
SW_FLW_init_run();
SW_ST_init_run();
SW_SWC_init_run();
return SW_CBN_init_run();
}

original_code:
void SW_CTL_init_run(void) {
 SW_WTH_init_run();
 SW_PET_init_run();
 SW_SIT_init_run();
 SW_VES_init_run();
 SW_VPD_init_run();
 SW_FLW_init_run();
 SW_ST_init_run();
 SW_SWC_init_run();
 SW_CBN_init_run();
}

canonical_original_code:
void SW_CTL_init_run() {
 SW_WTH_init_run();
 SW_PET_init_run();
 SW_SIT_init_run();
 SW_VES_init_run();
 SW_VPD_init_run();
 SW_FLW_init_run();
 SW_ST_init_run();
 SW_SWC_init_run();
 SW_CBN_init_run();
}


decompiled_code:
__int64 SW_CTL_run_current_year()
{
unsigned int v0; // eax
bool v1; // cc
unsigned int v2; // eax

begin_year();
v0 = SW_Model[5];
v1 = v0 <= SW_Model[6];
for ( SW_Model[7] = v0; v1; SW_Model[7] = v2 )
{
begin_day();
SW_SWC_water_flow();
if ( SW_VegProd[69932] )
{
calculate_repartitioned_soilwater();
if ( SW_VegEstab )
{
LABEL_7:
SW_VES_checkestab();
goto LABEL_4;
}
}
else if ( SW_VegEstab )
{
goto LABEL_7;
}
LABEL_4:
end_day();
v2 = SW_Model[7] + 1;
v1 = v2 <= SW_Model[6];
}
return SW_OUT_flush();
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
bool v1; // cc
unsigned int v2; // eax

func0();
v0 = SW_Model[5];
v1 = v0 <= SW_Model[6];
for ( SW_Model[7] = v0; v1; SW_Model[7] = v2 )
{
func1();
SW_SWC_water_flow();
if ( SW_VegProd[69932] )
{
calculate_repartitioned_soilwater();
if ( SW_VegEstab )
{
LABEL_7:
SW_VES_checkestab();
goto LABEL_4;
}
}
else if ( SW_VegEstab )
{
goto LABEL_7;
}
LABEL_4:
func2();
v2 = SW_Model[7] + 1;
v1 = v2 <= SW_Model[6];
}
return SW_OUT_flush();
}

original_code:
void SW_CTL_run_current_year(void) {
  TimeInt *doy = &SW_Model.doy;
  _begin_year();
  for (*doy = SW_Model.firstdoy; *doy <= SW_Model.lastdoy; (*doy)++) {
    _begin_day();
    SW_SWC_water_flow();
    if (SW_VegProd.use_SWA) {
      calculate_repartitioned_soilwater();
    }
    if (SW_VegEstab.use) {
      SW_VES_checkestab();
    }
    _end_day();
  }
  SW_OUT_flush();
}

canonical_original_code:
void SW_CTL_run_current_year() {
  unsigned int *doy = &SW_Model.doy;
  _begin_year();
  for (*doy = SW_Model.firstdoy; *doy <= SW_Model.lastdoy; (*doy)++) {
    _begin_day();
    SW_SWC_water_flow();
    if (SW_VegProd.use_SWA) {
      calculate_repartitioned_soilwater();
    }
    if (SW_VegEstab.use) {
      SW_VES_checkestab();
    }
    _end_day();
  }
  SW_OUT_flush();
}

variable_types:
doy
unsigned int *


decompiled_code:
__int64 SW_CTL_main()
{
__int64 result; // rax
bool v1; // cc

result = SW_Model[0];
v1 = SW_Model[0] <= SW_Model[1];
for ( SW_Model[10] = SW_Model[0]; v1; SW_Model[10] = result )
{
SW_CTL_run_current_year();
result = (unsigned int)(SW_Model[10] + 1);
v1 = (unsigned int)result <= SW_Model[1];
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
bool v1; // cc

result = SW_Model[0];
v1 = SW_Model[0] <= SW_Model[1];
for ( SW_Model[10] = SW_Model[0]; v1; SW_Model[10] = result )
{
func6();
result = (unsigned int)(SW_Model[10] + 1);
v1 = (unsigned int)result <= SW_Model[1];
}
return result;
}

original_code:
void SW_CTL_main(void) {
  TimeInt *cur_yr = &SW_Model.year;
  for (*cur_yr = SW_Model.startyr; *cur_yr <= SW_Model.endyr; (*cur_yr)++) {
    SW_CTL_run_current_year();
  }
}

canonical_original_code:
void SW_CTL_main() {
  unsigned int *cur_yr = &SW_Model.year;
  for (*cur_yr = SW_Model.startyr; *cur_yr <= SW_Model.endyr; (*cur_yr)++) {
    SW_CTL_run_current_year();
  }
}


decompiled_code:
__int64 SW_CTL_read_inputs_from_disk()
{
SW_F_read(0LL);
SW_MDL_read();
SW_WTH_setup();
SW_SKY_read();
if ( SW_Weather[2] == 2 )
SW_MKV_setup();
SW_WTH_read();
SW_VPD_read();
SW_SIT_read();
SW_LYR_read();
SW_SWRC_read();
SW_VES_read();
SW_OUT_read();
SW_CBN_read();
return SW_SWC_read();
}

canonical_decompiled_code:
__int64 func8()
{
SW_F_read(0LL);
SW_MDL_read();
SW_WTH_setup();
SW_SKY_read();
if ( SW_Weather[2] == 2 )
SW_MKV_setup();
SW_WTH_read();
SW_VPD_read();
SW_SIT_read();
SW_LYR_read();
SW_SWRC_read();
SW_VES_read();
SW_OUT_read();
SW_CBN_read();
return SW_SWC_read();
}

original_code:
void SW_CTL_read_inputs_from_disk(void) {
  SW_F_read(((void *)0));
  SW_MDL_read();
  SW_WTH_setup();
  SW_SKY_read();
  if (SW_Weather.generateWeatherMethod == 2) {
    SW_MKV_setup();
  }
  SW_WTH_read();
  SW_VPD_read();
  SW_SIT_read();
  SW_LYR_read();
  SW_SWRC_read();
  SW_VES_read();
  SW_OUT_read();
  SW_CBN_read();
  SW_SWC_read();
}

canonical_original_code:
void SW_CTL_read_inputs_from_disk() {
  SW_F_read(((void *)0));
  SW_MDL_read();
  SW_WTH_setup();
  SW_SKY_read();
  if (SW_Weather.generateWeatherMethod == 2) {
    SW_MKV_setup();
  }
  SW_WTH_read();
  SW_VPD_read();
  SW_SIT_read();
  SW_LYR_read();
  SW_SWRC_read();
  SW_VES_read();
  SW_OUT_read();
  SW_CBN_read();
  SW_SWC_read();
}


init

decompiled_code:
int __fastcall init(char *src)
{
char *v1; // rax
char *v2; // rbp
char *v3; // r12
__int128 v5; // [rsp+0h] [rbp-218h] BYREF
char v6[496]; // [rsp+10h] [rbp-208h] BYREF

LODWORD(v1) = 0;
v2 = src;
v3 = InFiles;
v5 = 0LL;
memset(v6, 0, sizeof(v6));
if ( InFiles )
{
if ( src )
{
LODWORD(v1) = strcmp(src, InFiles);
if ( (_DWORD)v1 )
{
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, src);
if ( (_BYTE)v5 )
{
Mem_Free(v3);
LABEL_8:
v1 = (char *)Str_Dup(&v5);
InFiles = v1;
return (int)v1;
}
}
}
}
else
{
if ( !src )
v2 = "files.in";
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, v2);
if ( (_BYTE)v5 )
goto LABEL_8;
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func0(char *src)
{
char *v1; // rax
char *v2; // rbp
char *v3; // r12
__int128 v5; // [rsp+0h] [rbp-218h] BYREF
char v6[496]; // [rsp+10h] [rbp-208h] BYREF

LODWORD(v1) = 0;
v2 = src;
v3 = InFiles;
v5 = 0LL;
memset(v6, 0, sizeof(v6));
if ( InFiles )
{
if ( src )
{
LODWORD(v1) = strcmp(src, InFiles);
if ( (_DWORD)v1 )
{
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, src);
if ( (_BYTE)v5 )
{
Mem_Free(v3);
LABEL_8:
v1 = (char *)Str_Dup(&v5);
InFiles = v1;
return (int)v1;
}
}
}
}
else
{
if ( !src )
v2 = "files.in";
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, v2);
if ( (_BYTE)v5 )
goto LABEL_8;
}
return (int)v1;
}

original_code:
static void init(const char *s) {
 char fname[512] = { '\0' };
 if (((void *)0) == InFiles[eFirst])
  strcpy(fname, (s ? s : "files.in"));
 else if (s && strcmp(s, InFiles[eFirst]))
  strcpy(fname, s);
 if (*fname) {
  if (!(((void *)0) == (InFiles[eFirst])))
   Mem_Free(InFiles[eFirst]);
  InFiles[eFirst] = Str_Dup(fname);
 }
}

canonical_original_code:
static void init(char *s) {
 char fname[512] = { '\0' };
 if (((void *)0) == InFiles[eFirst])
  strcpy(fname, (s ? s : "files.in"));
 else if (s && strcmp(s, InFiles[eFirst]))
  strcpy(fname, s);
 if (*fname) {
  if (!(((void *)0) == (InFiles[eFirst])))
   Mem_Free(InFiles[eFirst]);
  InFiles[eFirst] = Str_Dup(fname);
 }
}

variable_types:
s
char *

variable_types:
fname
char [512]


decompiled_code:
int __fastcall SW_CSV_F_INIT(char *src)
{
__int64 v1; // rax
int result; // eax
__int64 v3; // rax
const char *v4; // rax
const char *v5; // rax

v1 = ((__int64 (*)(void))DirName)();
if ( (unsigned int)DirExists(v1) )
{
strcpy(&inbuf, src);
result = RemoveFiles(&inbuf);
if ( !result )
{
LogError(logfp, 2LL, "Can't remove old csv output file: %s\n", src);
result = printf("Can't remove old csv output file: %s\n", src);
}
}
else
{
v3 = DirName(src);
result = MkDir(v3);
if ( !result )
{
v4 = (const char *)DirName(src);
LogError(logfp, 12LL, "Can't make output path for csv file: %s\n", v4);
v5 = (const char *)DirName(src);
result = printf("Can't make output path for csv file: %s\n", v5);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *src)
{
__int64 v1; // rax
int result; // eax
__int64 v3; // rax
const char *v4; // rax
const char *v5; // rax

v1 = ((__int64 (*)(void))DirName)();
if ( (unsigned int)DirExists(v1) )
{
strcpy(&inbuf, src);
result = RemoveFiles(&inbuf);
if ( !result )
{
LogError(logfp, 2LL, "Can't remove old csv output file: %s\n", src);
result = printf("Can't remove old csv output file: %s\n", src);
}
}
else
{
v3 = DirName(src);
result = MkDir(v3);
if ( !result )
{
v4 = (const char *)DirName(src);
LogError(logfp, 12LL, "Can't make output path for csv file: %s\n", v4);
v5 = (const char *)DirName(src);
result = printf("Can't make output path for csv file: %s\n", v5);
}
}
return result;
}

original_code:
void SW_CSV_F_INIT(const char *s)
{
 if (DirExists(DirName(s)))
 {
  strcpy(inbuf, s);
  if (!RemoveFiles(inbuf))
  {
   LogError(logfp, 0x02, "Can't remove old csv output file: %s\n", s);
   printf("Can't remove old csv output file: %s\n", s);
  }
 }
 else if (!MkDir(DirName(s)))
 {
  LogError(logfp, 0x0c, "Can't make output path for csv file: %s\n", DirName(s));
  printf("Can't make output path for csv file: %s\n", DirName(s));
 }
}

canonical_original_code:
void SW_CSV_F_INIT(char *s)
{
 if (DirExists(DirName(s)))
 {
  strcpy(inbuf, s);
  if (!RemoveFiles(inbuf))
  {
   LogError(logfp, 0x02, "Can't remove old csv output file: %s\n", s);
   printf("Can't remove old csv output file: %s\n", s);
  }
 }
 else if (!MkDir(DirName(s)))
 {
  LogError(logfp, 0x0c, "Can't make output path for csv file: %s\n", DirName(s));
  printf("Can't make output path for csv file: %s\n", DirName(s));
 }
}


decompiled_code:
char *__fastcall SW_F_name(int a1)
{
return (&InFiles)[a1];
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
return (&InFiles)[a1];
}

original_code:
char *SW_F_name(SW_FileIndex i) {
 return InFiles[i];
}

canonical_original_code:
char *SW_F_name(enum SW_FileIndex i) {
 return InFiles[i];
}

variable_types: enum SW_FileIndex { eNoFile=-1, eFirst=0, eModel=1, eLog=2, eSite=3, eLayers=4, eSWRCp=5, eWeather=6, eMarkovProb=7, eMarkovCov=8, eSky=9, eVegProd=10, eVegEstab=11, eCarbon=12, eSoilwat=13, eOutput=14, eOutputDaily=15, eOutputWeekly=16, eOutputMonthly=17, eOutputYearly=18, eOutputDaily_soil=19, eOutputWeekly_soil=20, eOutputMonthly_soil=21, eOutputYearly_soil=22, eEndFile=23 }

return_type: char *


decompiled_code:
const char *__fastcall SW_F_construct(char *a1)
{
char *v1; // rbx
const char *result; // rax
char i; // dl

v1 = a1;
init(a1);
result = (const char *)DirName(a1);
if ( result )
{
strcpy(&ProjDir, result);
result = &a1[strlen(&ProjDir)];
for ( i = *result; *result; i = *result )
{
++result;
*v1++ = i;
}
*v1 = 0;
}
else
{
ProjDir = 0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(char *a1)
{
char *v1; // rbx
const char *result; // rax
char i; // dl

v1 = a1;
func0(a1);
result = (const char *)DirName(a1);
if ( result )
{
strcpy(&ProjDir, result);
result = &a1[strlen(&ProjDir)];
for ( i = *result; *result; i = *result )
{
++result;
*v1++ = i;
}
*v1 = 0;
}
else
{
ProjDir = 0;
}
return result;
}

original_code:
void SW_F_construct(const char *firstfile) {
 char *c, *p;
 init(firstfile);
 if ((c = DirName(firstfile))) {
  strcpy(_ProjDir, c);
  c = (char *) firstfile;
  p = c + strlen(_ProjDir);
  while (*p)
   *(c++) = *(p++);
  *c = '\0';
 } else
  _ProjDir[0] = '\0';
}

canonical_original_code:
void SW_F_construct(char *firstfile) {
 char *c; char *p;
 init(firstfile);
 if ((c = DirName(firstfile))) {
  strcpy(_ProjDir, c);
  c = (char *) firstfile;
  p = c + strlen(_ProjDir);
  while (*p)
   *(c++) = *(p++);
  *c = '\0';
 } else
  _ProjDir[0] = '\0';
}

variable_types:
c
char *

variable_types:
p
char *


decompiled_code:
__int64 SW_F_deconstruct()
{
char **v0; // rbx
__int64 result; // rax

v0 = &InFiles;
do
{
if ( *v0 )
{
result = Mem_Free(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != &InFiles + 23 );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
char **v0; // rbx
__int64 result; // rax

v0 = &InFiles;
do
{
if ( *v0 )
{
result = Mem_Free(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != &InFiles + 23 );
return result;
}

original_code:
void SW_F_deconstruct(void) {
 IntUS i;
 for (i = 0; i < 23; i++)
 {
  if (!(((void *)0) == (InFiles[i]))) {
   Mem_Free(InFiles[i]);
   InFiles[i] = ((void *)0);
  }
 }
}

canonical_original_code:
void SW_F_deconstruct() {
 unsigned short i;
 for (i = 0; i < 23; i++)
 {
  if (!(((void *)0) == (InFiles[i]))) {
   Mem_Free(InFiles[i]);
   InFiles[i] = ((void *)0);
  }
 }
}

variable_types:
i
unsigned short


decompiled_code:
char *__fastcall SW_WeatherPrefix(char *a1)
{
return strcpy(a1, weather_prefix);
}

canonical_decompiled_code:
char *__fastcall func6(char *a1)
{
return strcpy(a1, weather_prefix);
}

original_code:
void SW_WeatherPrefix(char prefix[]) {
 strcpy(prefix, weather_prefix);
}

variable_types:
prefix
char []


decompiled_code:
char *__fastcall SW_OutputPrefix(char *a1)
{
char *result; // rax

if ( *(_WORD *)output_prefix != 47 )
return strcpy(a1, output_prefix);
*a1 = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *a1)
{
char *result; // rax

if ( *(_WORD *)output_prefix != 47 )
return strcpy(a1, output_prefix);
*a1 = 0;
return result;
}

original_code:
void SW_OutputPrefix(char prefix[]) {
 if (strcmp(output_prefix, "/") == 0)
  prefix[0] = '\0';
 else
  strcpy(prefix, output_prefix);
}


decompiled_code:
int sw_print_usage()
{
return puts(
"Ecosystem water simulation model SOILWAT2\n"
"More details at https://github.com/Burke-Lauenroth-Lab/SOILWAT2\n"
"Usage: ./SOILWAT2 [-d startdir] [-f files.in] [-e] [-q] [-v] [-h]\n"
" -d : operate (chdir) in startdir (default=.)\n"
" -f : name of main input file (default=files.in)\n"
" a preceeding path applies to all input files\n"
" -e : echo initial values from site and estab to logfile\n"
" -q : quiet mode, don't print message to check logfile\n"
" -v : print version information\n"
" -h : print this help information");
}

canonical_decompiled_code:
int func0()
{
return puts(
"Ecosystem water simulation model SOILWAT2\n"
"More details at https://github.com/Burke-Lauenroth-Lab/SOILWAT2\n"
"Usage: ./SOILWAT2 [-d startdir] [-f files.in] [-e] [-q] [-v] [-h]\n"
" -d : operate (chdir) in startdir (default=.)\n"
" -f : name of main input file (default=files.in)\n"
" a preceeding path applies to all input files\n"
" -e : echo initial values from site and estab to logfile\n"
" -q : quiet mode, don't print message to check logfile\n"
" -v : print version information\n"
" -h : print this help information");
}

original_code:
static void sw_print_usage(void) {
 printf(
  "Ecosystem water simulation model SOILWAT2\n"
  "More details at https://github.com/Burke-Lauenroth-Lab/SOILWAT2\n"
  "Usage: ./SOILWAT2 [-d startdir] [-f files.in] [-e] [-q] [-v] [-h]\n"
  "  -d : operate (chdir) in startdir (default=.)\n"
  "  -f : name of main input file (default=files.in)\n"
  "       a preceeding path applies to all input files\n"
  "  -e : echo initial values from site and estab to logfile\n"
  "  -q : quiet mode, don't print message to check logfile\n"
  "  -v : print version information\n"
  "  -h : print this help information\n"
 );
}

canonical_original_code:
static void sw_print_usage() {
 printf(
  "Ecosystem water simulation model SOILWAT2\n"
  "More details at https://github.com/Burke-Lauenroth-Lab/SOILWAT2\n"
  "Usage: ./SOILWAT2 [-d startdir] [-f files.in] [-e] [-q] [-v] [-h]\n"
  "  -d : operate (chdir) in startdir (default=.)\n"
  "  -f : name of main input file (default=files.in)\n"
  "       a preceeding path applies to all input files\n"
  "  -e : echo initial values from site and estab to logfile\n"
  "  -q : quiet mode, don't print message to check logfile\n"
  "  -v : print version information\n"
  "  -h : print this help information\n"
 );
}


decompiled_code:
__int64 __fastcall sw_init_args(int a1, __int64 a2)
{
int v2; // er12
__int64 result; // rax
const char *v4; // r13
__int64 v5; // rbp
const char **v6; // r14
const char *v7; // r15
const char *v8; // rsi
int v10; // [rsp+1Ch] [rbp-48Ch]
__int64 v11[10]; // [rsp+20h] [rbp-488h]
char dest[1080]; // [rsp+70h] [rbp-438h] BYREF

v2 = 1;
firstfile[8] = 0;
v11[0] = 0x100000001LL;
result = 0x6E692E73656C6966LL;
v11[5] = (__int64)"-f";
v11[6] = (__int64)"-e";
v11[7] = (__int64)"-q";
v11[8] = (__int64)"-v";
v11[9] = (__int64)"-h";
v11[1] = 0LL;
v11[2] = 0LL;
*(_QWORD *)firstfile = 0x6E692E73656C6966LL;
EchoInits = 0;
QuietMode = 0;
v10 = 6;
do
{
if ( a1 <= v2 )
break;
v4 = "-d";
v5 = 0LL;
v6 = (const char **)(8LL * v2 + a2);
v7 = *v6;
while ( strncmp(v4, v7, 2uLL) )
{
if ( ++v5 == 6 )
{
sw_print_usage();
result = sw_error(0xFFFFFFFFLL, "\nInvalid option %s\n", *v6);
goto LABEL_14;
}
v4 = (const char *)v11[v5 + 4];
}
dest[0] = 0;
result = *((unsigned int *)v11 + (int)v5);
if ( (_DWORD)result )
{
if ( v7[2] )
{
result = (__int64)strcpy(dest, v7 + 2);
}
else
{
v8 = *(const char **)(a2 + 8LL * v2 + 8);
if ( *v8 == 45 )
{
if ( (int)result > 0 )
{
sw_print_usage();
result = sw_error(0xFFFFFFFFLL, "\nIncomplete option %s\n", v4);
}
}
else
{
++v2;
result = (__int64)strcpy(dest, v8);
}
}
}
switch ( (int)v5 )
{
case 1:
result = (__int64)strcpy(firstfile, dest);
break;
case 2:
EchoInits = 1;
break;
case 3:
QuietMode = 1;
break;
case 4:
sw_print_version();
result = sw_error(0xFFFFFFFFLL, (const char *)&unk_1A61);
break;
case 5:
sw_print_usage();
result = sw_error(0xFFFFFFFFLL, (const char *)&unk_1A61);
break;
default:
result = ChDir(dest);
if ( !(_DWORD)result )
result = LogError(logfp, 12LL, "Invalid project directory (%s)", dest);
break;
}
++v2;
LABEL_14:
--v10;
}
while ( v10 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
int v2; // er12
__int64 result; // rax
const char *v4; // r13
__int64 v5; // rbp
const char **v6; // r14
const char *v7; // r15
const char *v8; // rsi
int v10; // [rsp+1Ch] [rbp-48Ch]
__int64 v11[10]; // [rsp+20h] [rbp-488h]
char dest[1080]; // [rsp+70h] [rbp-438h] BYREF

v2 = 1;
firstfile[8] = 0;
v11[0] = 0x100000001LL;
result = 0x6E692E73656C6966LL;
v11[5] = (__int64)"-f";
v11[6] = (__int64)"-e";
v11[7] = (__int64)"-q";
v11[8] = (__int64)"-v";
v11[9] = (__int64)"-h";
v11[1] = 0LL;
v11[2] = 0LL;
*(_QWORD *)firstfile = 0x6E692E73656C6966LL;
EchoInits = 0;
QuietMode = 0;
v10 = 6;
do
{
if ( a1 <= v2 )
break;
v4 = "-d";
v5 = 0LL;
v6 = (const char **)(8LL * v2 + a2);
v7 = *v6;
while ( strncmp(v4, v7, 2uLL) )
{
if ( ++v5 == 6 )
{
func0();
result = sw_error(0xFFFFFFFFLL, "\nInvalid option %s\n", *v6);
goto LABEL_14;
}
v4 = (const char *)v11[v5 + 4];
}
dest[0] = 0;
result = *((unsigned int *)v11 + (int)v5);
if ( (_DWORD)result )
{
if ( v7[2] )
{
result = (__int64)strcpy(dest, v7 + 2);
}
else
{
v8 = *(const char **)(a2 + 8LL * v2 + 8);
if ( *v8 == 45 )
{
if ( (int)result > 0 )
{
func0();
result = sw_error(0xFFFFFFFFLL, "\nIncomplete option %s\n", v4);
}
}
else
{
++v2;
result = (__int64)strcpy(dest, v8);
}
}
}
switch ( (int)v5 )
{
case 1:
result = (__int64)strcpy(firstfile, dest);
break;
case 2:
EchoInits = 1;
break;
case 3:
QuietMode = 1;
break;
case 4:
func1();
result = sw_error(0xFFFFFFFFLL, (const char *)&unk_1A61);
break;
case 5:
func0();
result = sw_error(0xFFFFFFFFLL, (const char *)&unk_1A61);
break;
default:
result = ChDir(dest);
if ( !(_DWORD)result )
result = LogError(logfp, 12LL, "Invalid project directory (%s)", dest);
break;
}
++v2;
LABEL_14:
--v10;
}
while ( v10 );
return result;
}

original_code:
void sw_init_args(int argc, char **argv) {
 char str[1024];
 char const *opts[] = { "-d", "-f", "-e", "-q", "-v", "-h" };
 int valopts[] = { 1, 1, 0, 0, 0, 0 };
 int i,
 a,
 op,
 nopts = sizeof(opts) / sizeof(char *);
 strcpy(_firstfile, "files.in");
 QuietMode = EchoInits = swFALSE;
 a = 1;
 for (i = 1; i <= nopts; i++) {
  if (a >= argc)
   break;
  for (op = 0; op < nopts; op++) {
   if (strncmp(opts[op], argv[a], 2) == 0)
    break;
  }
  if (op >= nopts) {
      sw_print_usage();
      sw_error(-1, "\nInvalid option %s\n", argv[a]);
  } else {
   *str = '\0';
   if (valopts[op]) {
    if ('\0' != argv[a][2]) {
     strcpy(str, (argv[a] + 2));
    } else if ('-' != *argv[a + 1]) {
     strcpy(str, argv[++a]);
    } else if (0 < valopts[op]) {
     sw_print_usage();
     sw_error(-1, "\nIncomplete option %s\n", opts[op]);
    }
   }
   switch (op) {
    case 0:
     if (!ChDir(str)) {
      LogError(logfp, 0x0c, "Invalid project directory (%s)", str);
     }
     break;
    case 1:
     strcpy(_firstfile, str);
     break;
    case 2:
     EchoInits = swTRUE;
     break;
    case 3:
     QuietMode = swTRUE;
     break;
    case 4:
     sw_print_version();
     sw_error(-1, "");
     break;
    case 5:
     sw_print_usage();
     sw_error(-1, "");
     break;
    default:
     LogError(
      logfp,
      0x0c,
      "Programmer: bad option in main:sw_init_args:switch"
     );
   }
   a++;
  }
 }
}

canonical_original_code:
void sw_init_args(int argc, char **argv) {
 char str[1024];
 char *opts[] = { "-d", "-f", "-e", "-q", "-v", "-h" };
 int valopts[] = { 1, 1, 0, 0, 0, 0 };
 int i; int a; int op; int nopts = sizeof(opts) / sizeof(char *);
 strcpy(_firstfile, "files.in");
 QuietMode = EchoInits = swFALSE;
 a = 1;
 for (i = 1; i <= nopts; i++) {
  if (a >= argc)
   break;
  for (op = 0; op < nopts; op++) {
   if (strncmp(opts[op], argv[a], 2) == 0)
    break;
  }
  if (op >= nopts) {
      sw_print_usage();
      sw_error(-1, "\nInvalid option %s\n", argv[a]);
  } else {
   *str = '\0';
   if (valopts[op]) {
    if ('\0' != argv[a][2]) {
     strcpy(str, (argv[a] + 2));
    } else if ('-' != *argv[a + 1]) {
     strcpy(str, argv[++a]);
    } else if (0 < valopts[op]) {
     sw_print_usage();
     sw_error(-1, "\nIncomplete option %s\n", opts[op]);
    }
   }
   switch (op) {
    case 0:
     if (!ChDir(str)) {
      LogError(logfp, 0x0c, "Invalid project directory (%s)", str);
     }
     break;
    case 1:
     strcpy(_firstfile, str);
     break;
    case 2:
     EchoInits = swTRUE;
     break;
    case 3:
     QuietMode = swTRUE;
     break;
    case 4:
     sw_print_version();
     sw_error(-1, "");
     break;
    case 5:
     sw_print_usage();
     sw_error(-1, "");
     break;
    default:
     LogError(
      logfp,
      0x0c,
      "Programmer: bad option in main:sw_init_args:switch"
     );
   }
   a++;
  }
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
str
char [1024]

variable_types:
opts
char *[]

variable_types:
valopts
int []

variable_types: i int

variable_types: a int

variable_types: op int

variable_types: nopts int


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

result = logfp;
if ( (struct _IO_FILE *)logfp != stdout && (struct _IO_FILE *)logfp != stderr )
{
result = CloseFile(&logfp);
if ( logged )
{
result = (unsigned int)QuietMode;
if ( !QuietMode )
result = sw_error(0LL, "\nCheck logfile for error or status messages.\n");
}
}
return result;
}

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

result = logfp;
if ( (struct _IO_FILE *)logfp != stdout && (struct _IO_FILE *)logfp != stderr )
{
result = CloseFile(&logfp);
if ( logged )
{
result = (unsigned int)QuietMode;
if ( !QuietMode )
result = sw_error(0LL, "\nCheck logfile for error or status messages.\n");
}
}
return result;
}

original_code:
void sw_check_log(void) {
 if (logfp != stdout && logfp != stderr) {
  CloseFile(&logfp);
  if (logged && !QuietMode) {
   sw_error(0, "\nCheck logfile for error or status messages.\n");
  }
 }
}

canonical_original_code:
void sw_check_log() {
 if (logfp != stdout && logfp != stderr) {
  CloseFile(&logfp);
  if (logged && !QuietMode) {
   sw_error(0, "\nCheck logfile for error or status messages.\n");
  }
 }
}


decompiled_code:
void *SW_CBN_construct()
{
return memset(SW_Carbon, 0, 0x4E68uLL);
}

canonical_decompiled_code:
void *func0()
{
return memset(SW_Carbon, 0, 0x4E68uLL);
}

original_code:
void SW_CBN_construct(void)
{
  memset(&SW_Carbon, 0, sizeof(SW_Carbon));
}

canonical_original_code:
void SW_CBN_construct()
{
  memset(&SW_Carbon, 0, sizeof(SW_Carbon));
}


decompiled_code:
void SW_CBN_deconstruct()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void SW_CBN_deconstruct(void)
{
}

canonical_original_code:
void SW_CBN_deconstruct()
{
}


decompiled_code:
void SW_CBN_init_run()
{
int v0; // ebp
unsigned int v1; // er13
unsigned int v2; // ebp
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm0_8
double *v7; // rbx
double *v8; // rbx
double v9; // [rsp+0h] [rbp-38h]
double v10; // [rsp+0h] [rbp-38h]
double v11; // [rsp+0h] [rbp-38h]

if ( *(_QWORD *)SW_Carbon )
{
v0 = SW_Model[12];
v1 = v0 + SW_Model[1];
v2 = SW_Model[0] + v0;
if ( v1 >= v2 )
{
while ( 1 )
{
v5 = *(double *)&SW_Carbon[8 * v2 + 72];
*(_QWORD *)&v6 = *(_QWORD *)&SW_Carbon[8 * v2 + 72] & LC9;
if ( v6 > 0.0 )
{
v3 = v6 * 2.220446049250313e-16;
if ( v3 < 2.220446049250313e-15 )
v4 = *(double *)&LC13;
else
v4 = 0.0 - v3;
if ( v4 <= v5 )
goto LABEL_7;
LABEL_12:
v9 = *(double *)&SW_Carbon[8 * v2 + 72];
snprintf(&errstr, 0x1000uLL, "(SW_Carbon) No CO2 ppm data was provided for year %d\n", v2);
LogError(logfp, 12LL, &errstr);
v5 = v9;
if ( *(_DWORD *)&SW_Carbon[4] )
goto LABEL_13;
LABEL_8:
if ( !*(_DWORD *)SW_Carbon )
goto LABEL_9;
LABEL_16:
v8 = (double *)&SW_VegProd;
do
{
v11 = v8[3739];
v8[v2 + 6241] = pow(v5, v8[3740]) * v11;
v8 += 8741;
}
while ( v8 != (double *)((char *)&SW_VegProd + 279712) );
if ( v1 < ++v2 )
return;
}
else
{
if ( v5 < -2.220446049250313e-15 )
goto LABEL_12;
LABEL_7:
if ( !*(_DWORD *)&SW_Carbon[4] )
goto LABEL_8;
LABEL_13:
v7 = (double *)&SW_VegProd;
do
{
v10 = v7[3737];
v7[v2 + 3741] = pow(v5, v7[3738]) * v10;
v7 += 8741;
}
while ( v7 != (double *)((char *)&SW_VegProd + 279712) );
if ( *(_DWORD *)SW_Carbon )
goto LABEL_16;
LABEL_9:
if ( v1 < ++v2 )
return;
}
}
}
}
}

canonical_decompiled_code:
void func3()
{
int v0; // ebp
unsigned int v1; // er13
unsigned int v2; // ebp
double v3; // xmm0_8
double v4; // xmm1_8
double v5; // xmm2_8
double v6; // xmm0_8
double *v7; // rbx
double *v8; // rbx
double v9; // [rsp+0h] [rbp-38h]
double v10; // [rsp+0h] [rbp-38h]
double v11; // [rsp+0h] [rbp-38h]

if ( *(_QWORD *)SW_Carbon )
{
v0 = SW_Model[12];
v1 = v0 + SW_Model[1];
v2 = SW_Model[0] + v0;
if ( v1 >= v2 )
{
while ( 1 )
{
v5 = *(double *)&SW_Carbon[8 * v2 + 72];
*(_QWORD *)&v6 = *(_QWORD *)&SW_Carbon[8 * v2 + 72] & LC9;
if ( v6 > 0.0 )
{
v3 = v6 * 2.220446049250313e-16;
if ( v3 < 2.220446049250313e-15 )
v4 = *(double *)&LC13;
else
v4 = 0.0 - v3;
if ( v4 <= v5 )
goto LABEL_7;
LABEL_12:
v9 = *(double *)&SW_Carbon[8 * v2 + 72];
snprintf(&errstr, 0x1000uLL, "(SW_Carbon) No CO2 ppm data was provided for year %d\n", v2);
LogError(logfp, 12LL, &errstr);
v5 = v9;
if ( *(_DWORD *)&SW_Carbon[4] )
goto LABEL_13;
LABEL_8:
if ( !*(_DWORD *)SW_Carbon )
goto LABEL_9;
LABEL_16:
v8 = (double *)&SW_VegProd;
do
{
v11 = v8[3739];
v8[v2 + 6241] = pow(v5, v8[3740]) * v11;
v8 += 8741;
}
while ( v8 != (double *)((char *)&SW_VegProd + 279712) );
if ( v1 < ++v2 )
return;
}
else
{
if ( v5 < -2.220446049250313e-15 )
goto LABEL_12;
LABEL_7:
if ( !*(_DWORD *)&SW_Carbon[4] )
goto LABEL_8;
LABEL_13:
v7 = (double *)&SW_VegProd;
do
{
v10 = v7[3737];
v7[v2 + 3741] = pow(v5, v7[3738]) * v10;
v7 += 8741;
}
while ( v7 != (double *)((char *)&SW_VegProd + 279712) );
if ( *(_DWORD *)SW_Carbon )
goto LABEL_16;
LABEL_9:
if ( v1 < ++v2 )
return;
}
}
}
}
}

variable_types: k int

variable_types:
year
unsigned int

variable_types:
simendyr
unsigned int

variable_types: ppm double

variable_types: struct SW_CARBON { int use_wue_mult; char scenario[64]; double ppm[2500]; } *

variable_types: struct SW_VEGPROD { struct VegType { struct CoverType { double fCover; } cov; struct tanfunc_t { float xinflec; } cnpy; double canopy_height_constant; struct tanfunc_t tr_shade_effects; double shade_scale; double litter[12]; double litter_daily[-1]; enum Bool { swFALSE=expr, swTRUE=expr } flagHydraulicRedistribution; double maxCondroot; double SWPcrit; double veg_kSmax; double EsTpartitioning_param; double co2_bio_coeff1; double co2_multipliers[2][2500]; } veg[4]; struct CoverType bare_cov; enum Bool { swFALSE=expr, swTRUE=expr } use_SWA; double critSoilWater[4]; int rank_SWPcrits[4]; struct SW_VEGPROD_OUTPUTS { struct VegTypeOut { double biomass_inveg; } veg[4]; double biomass_total; } *p_accu[4]; } *

user_defined_types: struct SW_VEGPROD { struct VegType veg[4]; struct CoverType bare_cov; enum Bool use_SWA; double critSoilWater[4]; int rank_SWPcrits[4]; struct SW_VEGPROD_OUTPUTS *p_accu[4]; }

user_defined_types: struct VegType { struct CoverType cov; struct tanfunc_t cnpy; double canopy_height_constant; struct tanfunc_t tr_shade_effects; double shade_scale; double litter[12]; double litter_daily[-1]; enum Bool flagHydraulicRedistribution; double maxCondroot; double SWPcrit; double veg_kSmax; double EsTpartitioning_param; double co2_bio_coeff1; double co2_multipliers[2][2500]; }

user_defined_types: struct SW_VEGPROD_OUTPUTS { struct VegTypeOut veg[4]; double biomass_total; }


repo: ByteInternet/byte-rpc-crontab

decompiled_code:
int set_cron_uid()
{
int result; // eax

result = seteuid(0);
if ( result < 0 )
{
perror("seteuid");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

result = seteuid(0);
if ( result < 0 )
{
perror("seteuid");
exit(1);
}
return result;
}

original_code:
void
set_cron_uid()
{
 if (seteuid(0) < 0) {
  perror("seteuid");
  exit(1);
 }
}


decompiled_code:
int set_cron_cwd()
{
int *v0; // rax
int *v1; // rbx
__mode_t v2; // ebp
int *v3; // rbx
__mode_t v4; // ebp
struct group *v5; // rax
const char *v6; // rdx
int *v7; // rax
char *v8; // rax
char *v9; // rax
char *v10; // rax
char *v11; // rax
char *v12; // rax
struct stat v14; // [rsp+0h] [rbp-A8h] BYREF

if ( stat("/var/spool/cron", &v14) < 0 )
{
v1 = _errno_location();
if ( *v1 == 2 )
{
perror("/var/spool/cron");
if ( getuid() )
goto LABEL_19;
v2 = umask(0);
if ( mkdir("/var/spool/cron", 0x1EDu) )
{
v12 = strerror(*v1);
fprintf(stderr, "%s: mkdir: %s\n", "/var/spool/cron", v12);
goto LABEL_19;
}
fprintf(stderr, "%s: created\n", "/var/spool/cron");
stat("/var/spool/cron", &v14);
umask(v2);
}
}
if ( (v14.st_mode & 0x4000) == 0 )
{
v6 = "/var/spool/cron";
LABEL_18:
fprintf(stderr, "'%s' is not a directory, bailing out.\n", v6);
goto LABEL_19;
}
if ( chdir("/var/spool/cron") < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: chdir: %s\n", "/var/spool/cron", v8);
goto LABEL_19;
}
LODWORD(v0) = stat("crontabs", &v14);
if ( (int)v0 < 0 )
{
v0 = _errno_location();
v3 = v0;
if ( *v0 == 2 )
{
perror("crontabs");
if ( getuid() )
goto LABEL_19;
v4 = umask(0);
if ( mkdir("crontabs", 0x3D8u) )
{
v11 = strerror(*v3);
fprintf(stderr, "%s: mkdir: %s\n", "crontabs", v11);
}
else
{
fprintf(stderr, "%s: created\n", "crontabs");
umask(v4);
v5 = getgrnam("crontab");
if ( v5 )
{
if ( !chown("crontabs", 0xFFFFFFFF, v5->gr_gid) )
{
fprintf(stderr, "%s: chowned\n", "crontabs");
LODWORD(v0) = stat("crontabs", &v14);
goto LABEL_5;
}
v9 = strerror(*v3);
fprintf(stderr, "%s: chown: %s\n", "crontabs", v9);
}
else
{
v10 = strerror(*v3);
fprintf(stderr, "%s: getgrnam: %s\n", "crontabs", v10);
}
}
LABEL_19:
exit(1);
}
}
LABEL_5:
if ( (v14.st_mode & 0x4000) == 0 )
{
v6 = "crontabs";
goto LABEL_18;
}
return (int)v0;
}

canonical_decompiled_code:
int func5()
{
int *v0; // rax
int *v1; // rbx
__mode_t v2; // ebp
int *v3; // rbx
__mode_t v4; // ebp
struct group *v5; // rax
const char *v6; // rdx
int *v7; // rax
char *v8; // rax
char *v9; // rax
char *v10; // rax
char *v11; // rax
char *v12; // rax
struct stat v14; // [rsp+0h] [rbp-A8h] BYREF

if ( stat("/var/spool/cron", &v14) < 0 )
{
v1 = _errno_location();
if ( *v1 == 2 )
{
perror("/var/spool/cron");
if ( getuid() )
goto LABEL_19;
v2 = umask(0);
if ( mkdir("/var/spool/cron", 0x1EDu) )
{
v12 = strerror(*v1);
fprintf(stderr, "%s: mkdir: %s\n", "/var/spool/cron", v12);
goto LABEL_19;
}
fprintf(stderr, "%s: created\n", "/var/spool/cron");
stat("/var/spool/cron", &v14);
umask(v2);
}
}
if ( (v14.st_mode & 0x4000) == 0 )
{
v6 = "/var/spool/cron";
LABEL_18:
fprintf(stderr, "'%s' is not a directory, bailing out.\n", v6);
goto LABEL_19;
}
if ( chdir("/var/spool/cron") < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: chdir: %s\n", "/var/spool/cron", v8);
goto LABEL_19;
}
LODWORD(v0) = stat("crontabs", &v14);
if ( (int)v0 < 0 )
{
v0 = _errno_location();
v3 = v0;
if ( *v0 == 2 )
{
perror("crontabs");
if ( getuid() )
goto LABEL_19;
v4 = umask(0);
if ( mkdir("crontabs", 0x3D8u) )
{
v11 = strerror(*v3);
fprintf(stderr, "%s: mkdir: %s\n", "crontabs", v11);
}
else
{
fprintf(stderr, "%s: created\n", "crontabs");
umask(v4);
v5 = getgrnam("crontab");
if ( v5 )
{
if ( !chown("crontabs", 0xFFFFFFFF, v5->gr_gid) )
{
fprintf(stderr, "%s: chowned\n", "crontabs");
LODWORD(v0) = stat("crontabs", &v14);
goto LABEL_5;
}
v9 = strerror(*v3);
fprintf(stderr, "%s: chown: %s\n", "crontabs", v9);
}
else
{
v10 = strerror(*v3);
fprintf(stderr, "%s: getgrnam: %s\n", "crontabs", v10);
}
}
LABEL_19:
exit(1);
}
}
LABEL_5:
if ( (v14.st_mode & 0x4000) == 0 )
{
v6 = "crontabs";
goto LABEL_18;
}
return (int)v0;
}

original_code:
void
set_cron_cwd()
{
 struct stat sb;
 mode_t um;
 struct group *gr;
 if (stat("/var/spool/cron", &sb) < 0 && (*__errno_location ()) == 2) {
  perror("/var/spool/cron");
  if (getuid() != 0 )
   exit(1);
  um = umask(000);
  if (0 == mkdir("/var/spool/cron", 0755)) {
   fprintf(stderr, "%s: created\n", "/var/spool/cron");
   stat("/var/spool/cron", &sb);
  } else {
   fprintf(stderr, "%s: mkdir: %s\n", "/var/spool/cron",
    strerror((*__errno_location ())));
   exit(1);
  }
  (void) umask(um);
 }
 if (!(sb.st_mode & 0040000)) {
  fprintf(stderr, "'%s' is not a directory, bailing out.\n",
   "/var/spool/cron");
  exit(1);
 }
 if (chdir("/var/spool/cron") < 0) {
  fprintf(stderr, "%s: chdir: %s\n", "/var/spool/cron", strerror((*__errno_location ())));
  exit(1);
 }
 if (stat("crontabs", &sb) < 0 && (*__errno_location ()) == 2) {
  perror("crontabs");
  if (getuid() != 0 )
   exit(1);
  um = umask(000);
  if (0 == mkdir("crontabs", 01730)) {
   fprintf(stderr, "%s: created\n", "crontabs");
  } else {
   fprintf(stderr, "%s: mkdir: %s\n", "crontabs",
    strerror((*__errno_location ())));
   exit(1);
  }
  (void) umask(um);
  if (!(gr = getgrnam("crontab"))) {
   fprintf(stderr, "%s: getgrnam: %s\n", "crontabs",
    strerror((*__errno_location ())));
   exit(1);
  }
  if (0 == chown("crontabs", -1, gr->gr_gid)) {
   fprintf(stderr, "%s: chowned\n", "crontabs");
    stat("crontabs", &sb);
  } else {
   fprintf(stderr, "%s: chown: %s\n", "crontabs",
   strerror((*__errno_location ())));
   exit(1);
  }
 }
 if (!(sb.st_mode & 0040000)) {
  fprintf(stderr, "'%s' is not a directory, bailing out.\n",
   "crontabs");
  exit(1);
 }
}

canonical_original_code:
void set_cron_cwd()
{
 struct stat sb;
 unsigned int um;
 struct group *gr;
 if (stat("/var/spool/cron", &sb) < 0 && (*__errno_location ()) == 2) {
  perror("/var/spool/cron");
  if (getuid() != 0 )
   exit(1);
  um = umask(000);
  if (0 == mkdir("/var/spool/cron", 0755)) {
   fprintf(stderr, "%s: created\n", "/var/spool/cron");
   stat("/var/spool/cron", &sb);
  } else {
   fprintf(stderr, "%s: mkdir: %s\n", "/var/spool/cron",
    strerror((*__errno_location ())));
   exit(1);
  }
  (void) umask(um);
 }
 if (!(sb.st_mode & 0040000)) {
  fprintf(stderr, "'%s' is not a directory, bailing out.\n",
   "/var/spool/cron");
  exit(1);
 }
 if (chdir("/var/spool/cron") < 0) {
  fprintf(stderr, "%s: chdir: %s\n", "/var/spool/cron", strerror((*__errno_location ())));
  exit(1);
 }
 if (stat("crontabs", &sb) < 0 && (*__errno_location ()) == 2) {
  perror("crontabs");
  if (getuid() != 0 )
   exit(1);
  um = umask(000);
  if (0 == mkdir("crontabs", 01730)) {
   fprintf(stderr, "%s: created\n", "crontabs");
  } else {
   fprintf(stderr, "%s: mkdir: %s\n", "crontabs",
    strerror((*__errno_location ())));
   exit(1);
  }
  (void) umask(um);
  if (!(gr = getgrnam("crontab"))) {
   fprintf(stderr, "%s: getgrnam: %s\n", "crontabs",
    strerror((*__errno_location ())));
   exit(1);
  }
  if (0 == chown("crontabs", -1, gr->gr_gid)) {
   fprintf(stderr, "%s: chowned\n", "crontabs");
    stat("crontabs", &sb);
  } else {
   fprintf(stderr, "%s: chown: %s\n", "crontabs",
   strerror((*__errno_location ())));
   exit(1);
  }
 }
 if (!(sb.st_mode & 0040000)) {
  fprintf(stderr, "'%s' is not a directory, bailing out.\n",
   "crontabs");
  exit(1);
 }
}

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

variable_types:
um
unsigned int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

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


decompiled_code:
// attributes: thunk
void log_close(void)
{
closelog();
}

canonical_decompiled_code:
void func13(void)
{
closelog();
}

original_code:
void
log_close() {
 closelog();
}

canonical_original_code:
void log_close() {
 closelog();
}


decompiled_code:
__int64 swap_uids()
{
__gid_t v0; // eax
__uid_t v1; // eax

save_euid = geteuid();
save_egid = getegid();
v0 = getgid();
if ( setegid(v0) )
return 0xFFFFFFFFLL;
v1 = getuid();
return (unsigned int)-(seteuid(v1) != 0);
}

canonical_decompiled_code:
__int64 func17()
{
__gid_t v0; // eax
__uid_t v1; // eax

save_euid = geteuid();
save_egid = getegid();
v0 = getgid();
if ( setegid(v0) )
return 0xFFFFFFFFLL;
v1 = getuid();
return (unsigned int)-(seteuid(v1) != 0);
}

original_code:
int swap_uids()
{
 save_euid = geteuid(); save_egid = getegid();
 return (setegid(getgid()) || seteuid(getuid())) ? -1 : 0;
}


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

if ( setegid(save_egid) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(seteuid(save_euid) != 0);
return result;
}

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

if ( setegid(save_egid) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(seteuid(save_euid) != 0);
return result;
}

original_code:
int swap_uids_back()
{
 return (setegid(save_egid) || seteuid(save_euid)) ? -1 : 0;
}


decompiled_code:
__int64 __fastcall get_gmtoff(time_t *timer, struct tm *a2)
{
struct tm *v2; // rbx
struct tm *v3; // rax
int v4; // er15
int v5; // edx
int v6; // er13
int v7; // er12
int v8; // er14
__int64 result; // rax
struct tm *v10; // rax
int v11; // [rsp+Ch] [rbp-3Ch]

v2 = a2;
v3 = gmtime(timer);
v4 = v3->tm_sec;
v5 = v3->tm_min;
v6 = v3->tm_hour;
v7 = v3->tm_year;
v8 = v3->tm_yday;
if ( !a2 )
{
v11 = v3->tm_min;
v10 = localtime(timer);
v5 = v11;
v2 = v10;
}
result = 3600 * (v2->tm_hour - v6) + v2->tm_sec - v4 + 60 * (v2->tm_min - v5);
if ( v2->tm_year < v7 )
goto LABEL_7;
if ( v2->tm_year > v7 )
{
LABEL_5:
result += 86400LL;
return result;
}
if ( v2->tm_yday >= v8 )
{
if ( v2->tm_yday > v8 )
goto LABEL_5;
}
else
{
LABEL_7:
result -= 86400LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(time_t *timer, struct tm *a2)
{
struct tm *v2; // rbx
struct tm *v3; // rax
int v4; // er15
int v5; // edx
int v6; // er13
int v7; // er12
int v8; // er14
__int64 result; // rax
struct tm *v10; // rax
int v11; // [rsp+Ch] [rbp-3Ch]

v2 = a2;
v3 = gmtime(timer);
v4 = v3->tm_sec;
v5 = v3->tm_min;
v6 = v3->tm_hour;
v7 = v3->tm_year;
v8 = v3->tm_yday;
if ( !a2 )
{
v11 = v3->tm_min;
v10 = localtime(timer);
v5 = v11;
v2 = v10;
}
result = 3600 * (v2->tm_hour - v6) + v2->tm_sec - v4 + 60 * (v2->tm_min - v5);
if ( v2->tm_year < v7 )
goto LABEL_7;
if ( v2->tm_year > v7 )
{
LABEL_5:
result += 86400LL;
return result;
}
if ( v2->tm_yday >= v8 )
{
if ( v2->tm_yday > v8 )
goto LABEL_5;
}
else
{
LABEL_7:
result -= 86400LL;
}
return result;
}

original_code:
long get_gmtoff(time_t *clock, struct tm *local)
{
 struct tm gmt;
 long offset;
 gmt = *gmtime(clock);
 if (local == ((void *)0))
  local = localtime(clock);
 offset = (local->tm_sec - gmt.tm_sec) +
     ((local->tm_min - gmt.tm_min) * 60) +
     ((local->tm_hour - gmt.tm_hour) * 3600);
 if (local->tm_year < gmt.tm_year)
  offset -= 24 * 3600;
 else if (local->tm_year > gmt.tm_year)
  offset += 24 * 3600;
 else if (local->tm_yday < gmt.tm_yday)
  offset -= 24 * 3600;
 else if (local->tm_yday > gmt.tm_yday)
  offset += 24 * 3600;
 return (offset);
}

canonical_original_code:
long get_gmtoff(long *clock, struct tm *local)
{
 struct tm gmt;
 long offset;
 gmt = *gmtime(clock);
 if (local == ((void *)0))
  local = localtime(clock);
 offset = (local->tm_sec - gmt.tm_sec) +
     ((local->tm_min - gmt.tm_min) * 60) +
     ((local->tm_hour - gmt.tm_hour) * 3600);
 if (local->tm_year < gmt.tm_year)
  offset -= 24 * 3600;
 else if (local->tm_year > gmt.tm_year)
  offset += 24 * 3600;
 else if (local->tm_yday < gmt.tm_yday)
  offset -= 24 * 3600;
 else if (local->tm_yday > gmt.tm_yday)
  offset += 24 * 3600;
 return (offset);
}

variable_types:
clock
long *

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

variable_types: offset long

return_type: long


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "usage: %s\n", (const char *)ProgramName);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
fprintf(stderr, "usage: %s\n", (const char *)ProgramName);
exit(1);
}

original_code:
static void
usage() {
 fprintf(stderr, "usage: %s\n", ProgramName);
 exit(1);
}


decompiled_code:
unsigned __int64 __fastcall set_time(int a1)
{
const __m128i *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__m128i v4; // xmm2
time_t v5; // rcx
unsigned __int64 result; // rax
__int128 v7[3]; // [rsp+0h] [rbp-48h] BYREF
__int64 v8; // [rsp+30h] [rbp-18h]

StartTime = time(0LL);
v1 = (const __m128i *)localtime(&StartTime);
v7[0] = (__int128)_mm_loadu_si128(v1);
v7[1] = (__int128)_mm_loadu_si128(v1 + 1);
v4 = _mm_loadu_si128(v1 + 2);
v7[2] = (__int128)v4;
v8 = v1[3].m128i_i64[0];
if ( a1 || (v3 = GMToff, v4.m128i_i32[0] != isdst_0) )
{
isdst_0 = v4.m128i_i32[0];
GMToff = get_gmtoff(&StartTime, v7, v2, v3);
v3 = GMToff;
}
v5 = StartTime + v3;
result = 0x8888888888888889LL * v5;
clockTime = (int)v5 / 60;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(int a1)
{
const __m128i *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__m128i v4; // xmm2
time_t v5; // rcx
unsigned __int64 result; // rax
__int128 v7[3]; // [rsp+0h] [rbp-48h] BYREF
__int64 v8; // [rsp+30h] [rbp-18h]

StartTime = time(0LL);
v1 = (const __m128i *)localtime(&StartTime);
v7[0] = (__int128)_mm_loadu_si128(v1);
v7[1] = (__int128)_mm_loadu_si128(v1 + 1);
v4 = _mm_loadu_si128(v1 + 2);
v7[2] = (__int128)v4;
v8 = v1[3].m128i_i64[0];
if ( a1 || (v3 = GMToff, v4.m128i_i32[0] != isdst_0) )
{
isdst_0 = v4.m128i_i32[0];
GMToff = get_gmtoff(&StartTime, v7, v2, v3);
v3 = GMToff;
}
v5 = StartTime + v3;
result = 0x8888888888888889LL * v5;
clockTime = (int)v5 / 60;
return result;
}

original_code:
static void
set_time(int initialize)
{
    struct tm tm;
    static int isdst;
    StartTime = time(((void *)0));
    tm = *localtime(&StartTime);
    if (initialize || tm.tm_isdst != isdst) {
       isdst = tm.tm_isdst;
       GMToff = get_gmtoff(&StartTime, &tm);
       ;
    }
    clockTime = (StartTime + GMToff) / (time_t)60;
}

canonical_original_code:
static void set_time(int initialize)
{
    struct tm tm;
    static int isdst;
    StartTime = time(((void *)0));
    tm = *localtime(&StartTime);
    if (initialize || tm.tm_isdst != isdst) {
       isdst = tm.tm_isdst;
       GMToff = get_gmtoff(&StartTime, &tm);
       ;
    }
    clockTime = (StartTime + GMToff) / (long)60;
}

variable_types: initialize int

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

variable_types: isdst int


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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

original_code:
char **
env_init()
{
 register char **p = (char **) malloc(sizeof(char **));
 if (p)
  p[0] = ((void *)0);
 return (p);
}

canonical_original_code:
char **env_init()
{
 register char **p = (char **) malloc(sizeof(char **));
 if (p)
  p[0] = ((void *)0);
 return (p);
}

variable_types:
p
char **

return_type: char **


decompiled_code:
__int64 job_runqueue()
{
unsigned int v0; // er12
_QWORD *v1; // rbx
void *v2; // rdi
__int64 result; // rax

v0 = 0;
v1 = jhead;
if ( jhead )
{
do
{
++v0;
do_command(v1[1], v1[2]);
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
jtail = 0LL;
result = v0;
jhead = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12
_QWORD *v1; // rbx
void *v2; // rdi
__int64 result; // rax

v0 = 0;
v1 = jhead;
if ( jhead )
{
do
{
++v0;
do_command(v1[1], v1[2]);
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
jtail = 0LL;
result = v0;
jhead = 0LL;
return result;
}

original_code:
int
job_runqueue()
{
 register job *j, *jn;
 register int run = 0;
 for (j=jhead; j; j=jn) {
  do_command(j->e, j->u);
  jn = j->next;
  free(j);
  run++;
 }
 jhead = jtail = ((void *)0);
 return run;
}

canonical_original_code:
int job_runqueue()
{
 register struct _job *j; register struct _job *jn;
 register int run = 0;
 for (j=jhead; j; j=jn) {
  do_command(j->e, j->u);
  jn = j->next;
  free(j);
  run++;
 }
 jhead = jtail = ((void *)0);
 return run;
}

variable_types: struct _job { struct _job *next; struct _entry { struct _entry *next; unsigned int uid; unsigned int gid; char **envp; char *cmd; unsigned char minute[-1]; unsigned char hour[-1]; unsigned char dom[-1]; unsigned char month[-1]; unsigned char dow[-1]; int flags; } *e; struct _user { struct _user *next; char *name; long mtime; struct _entry *crontab; } *u; } *

variable_types: run int

user_defined_types: struct _job { struct _job *next; struct _entry *e; struct _user *u; }


decompiled_code:
__int64 __fastcall build_env(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
static char ** build_env(char **cronenv)
{
        char **jobenv = cronenv;
    return jobenv;
}

canonical_original_code:
static char **build_env(char **cronenv)
{
        char **jobenv = cronenv;
    return jobenv;
}

variable_types:
cronenv
char **

variable_types:
jobenv
char **


repo: ByzantineFailure/BSON-JSON-Utils

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

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

canonical_original_code:
struct bson_Document *bson_parseJSON(char *JSON, int JSON_length)
{
 return 0;
}

variable_types:
JSON
char *

return_type: struct bson_Document { int length; struct bson_dll { struct bson_dll_node { void *data; struct bson_dll_node *next; struct bson_dll_node *previous; } *head; } *elements; } *

user_defined_types: struct bson_Document { int length; struct bson_dll *elements; }

user_defined_types: struct bson_dll { struct bson_dll_node *head; }


decompiled_code:
__int64 __fastcall json_isValidNumberCharacter(char a1, int a2, int a3, int a4)
{
__int64 result; // rax

if ( a1 <= 10 )
return 4 * (unsigned int)(a1 >= 9) - 1;
switch ( a1 )
{
case ' ':
case ',':
result = 3LL;
break;
case '+':
case '-':
result = a2 == 0 ? -1 : 1;
break;
case '.':
result = a4 == 0 ? 4 : -1;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
result = 1LL;
break;
case 'E':
case 'e':
result = (a3 | a2) == 0 ? 2 : -1;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, int a2, int a3, int a4)
{
__int64 result; // rax

if ( a1 <= 10 )
return 4 * (unsigned int)(a1 >= 9) - 1;
switch ( a1 )
{
case ' ':
case ',':
result = 3LL;
break;
case '+':
case '-':
result = a2 == 0 ? -1 : 1;
break;
case '.':
result = a4 == 0 ? 4 : -1;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
result = 1LL;
break;
case 'E':
case 'e':
result = (a3 | a2) == 0 ? 2 : -1;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int json_isValidNumberCharacter(char check, int firstChar, int hasExponent, int hasPeriod)
{
 switch(check)
 {
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
   return 1;
  case 'e':
  case 'E':
   if(!firstChar && !hasExponent)
    return 2;
   else
    return -1;
  case '-':
  case '+':
   if(firstChar)
    return 1;
   else
    return -1;
  case '.':
   if(hasPeriod)
    return -1;
   else
    return 4;
  case ' ':
  case '\n':
  case '\t':
  case ',':
   return 3;
  default:
   return -1;
 }
}

variable_types: check char

variable_types: firstChar int

variable_types: hasExponent int

variable_types: hasPeriod int


decompiled_code:
__int64 __fastcall json_checkValidNumber(const char *a1)
{
int v1; // ebp
int v2; // eax
__int64 v3; // r8
int v4; // ecx
int v5; // er10
int v6; // er9
unsigned int v7; // edx
unsigned int v8; // er11

v1 = 0;
v2 = strlen(a1);
v3 = 0LL;
v4 = 0;
v5 = 1;
v6 = v2;
LABEL_2:
while ( v6 > (int)v3 )
{
v7 = json_isValidNumberCharacter(a1[v3], v5, v1, v4);
switch ( v7 )
{
case 0xFFFFFFFF:
return v7;
case 1u:
v5 = 0;
goto LABEL_7;
case 2u:
v1 = 1;
v5 = 1;
goto LABEL_7;
case 3u:
return v8;
case 4u:
v4 = 1;
LABEL_7:
++v3;
break;
default:
goto LABEL_2;
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
int v1; // ebp
int v2; // eax
__int64 v3; // r8
int v4; // ecx
int v5; // er10
int v6; // er9
unsigned int v7; // edx
unsigned int v8; // er11

v1 = 0;
v2 = strlen(a1);
v3 = 0LL;
v4 = 0;
v5 = 1;
v6 = v2;
LABEL_2:
while ( v6 > (int)v3 )
{
v7 = func1(a1[v3], v5, v1, v4);
switch ( v7 )
{
case 0xFFFFFFFF:
return v7;
case 1u:
v5 = 0;
goto LABEL_7;
case 2u:
v1 = 1;
v5 = 1;
goto LABEL_7;
case 3u:
return v8;
case 4u:
v4 = 1;
LABEL_7:
++v3;
break;
default:
goto LABEL_2;
}
}
return (unsigned int)-1;
}

original_code:
int json_checkValidNumber(char *JSON)
{
 int i, objlen, firstChar, hasExponent, hasPeriod;
 char currentChar;
 i = 0;
 hasExponent = 0;
 firstChar = 1;
 hasPeriod = 0;
 objlen = strlen(JSON);
 while(i < objlen)
 {
  currentChar = *(JSON + i);
  switch(json_isValidNumberCharacter(currentChar, firstChar, hasExponent, hasPeriod))
  {
   case 2:
    hasExponent = 1;
    firstChar = 1;
    i++;
    break;
   case 1:
    firstChar = 0;
    i++;
    break;
   case 3:
    return i;
    break;
   case 4:
    hasPeriod = 1;
    i++;
    break;
   case -1:
    return -1;
    break;
  }
 }
 return -1;
}

canonical_original_code:
int json_checkValidNumber(char *JSON)
{
 int i; int objlen; int firstChar; int hasExponent; int hasPeriod;
 char currentChar;
 i = 0;
 hasExponent = 0;
 firstChar = 1;
 hasPeriod = 0;
 objlen = strlen(JSON);
 while(i < objlen)
 {
  currentChar = *(JSON + i);
  switch(json_isValidNumberCharacter(currentChar, firstChar, hasExponent, hasPeriod))
  {
   case 2:
    hasExponent = 1;
    firstChar = 1;
    i++;
    break;
   case 1:
    firstChar = 0;
    i++;
    break;
   case 3:
    return i;
    break;
   case 4:
    hasPeriod = 1;
    i++;
    break;
   case -1:
    return -1;
    break;
  }
 }
 return -1;
}

variable_types: i int

variable_types: objlen int

variable_types: currentChar char


decompiled_code:
__int64 __fastcall json_checkNextFourCharsForHex(__int64 a1)
{
_BYTE *v1; // rax
_BYTE *v2; // rdi

v1 = (_BYTE *)(a1 + 1);
v2 = (_BYTE *)(a1 + 5);
do
{
if ( (unsigned __int8)(*v1 - 48) > 0x36u || ((1LL << (*v1 - 48)) & 0x7E0000007E03FFLL) == 0 )
return 0xFFFFFFFFLL;
++v1;
}
while ( v1 != v2 );
return 1LL;
}

original_code:
int json_checkNextFourCharsForHex(char *JSON)
{
 int i;
 for(i = 1; i < 5; i++)
 {
  switch(*(JSON + i))
  {
   case '0':
   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
   case '8':
   case '9':
   case 'a':
   case 'A':
   case 'b':
   case 'B':
   case 'c':
   case 'C':
   case 'd':
   case 'D':
   case 'e':
   case 'E':
   case 'f':
   case 'F':
    break;
   default:
    return -1;
  }
 }
 return 1;
}


decompiled_code:
__int64 __fastcall json_checkValidString(const char *a1)
{
int v2; // eax
int v3; // er10
int v4; // er9
char v5; // dl
__int64 result; // rax
char *v7; // rdi
char v8; // al
int v9; // er9

v2 = strlen(a1);
if ( *a1 != 34 || v2 <= 1 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = 1;
while ( 1 )
{
v5 = a1[v4];
result = (unsigned int)(v4 + 1);
if ( v5 == 34 )
return result;
if ( v5 == 92 )
{
v7 = (char *)&a1[(int)result];
v8 = *v7;
if ( *v7 > 117 )
return 0xFFFFFFFFLL;
if ( v8 <= 91 )
{
if ( v8 != 34 && v8 != 47 )
return 0xFFFFFFFFLL;
LABEL_16:
v4 += 2;
}
else
{
switch ( v8 )
{
case '\\':
case 'b':
case 'f':
case 'n':
case 'r':
case 't':
goto LABEL_16;
case 'u':
result = json_checkNextFourCharsForHex((__int64)v7);
if ( (_DWORD)result == -1 )
return result;
v4 = v9 + 6;
break;
default:
return 0xFFFFFFFFLL;
}
}
}
else
{
++v4;
}
if ( v4 >= v3 )
return 0xFFFFFFFFLL;
}
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
int v2; // eax
int v3; // er10
int v4; // er9
char v5; // dl
__int64 result; // rax
char *v7; // rdi
char v8; // al
int v9; // er9

v2 = strlen(a1);
if ( *a1 != 34 || v2 <= 1 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = 1;
while ( 1 )
{
v5 = a1[v4];
result = (unsigned int)(v4 + 1);
if ( v5 == 34 )
return result;
if ( v5 == 92 )
{
v7 = (char *)&a1[(int)result];
v8 = *v7;
if ( *v7 > 117 )
return 0xFFFFFFFFLL;
if ( v8 <= 91 )
{
if ( v8 != 34 && v8 != 47 )
return 0xFFFFFFFFLL;
LABEL_16:
v4 += 2;
}
else
{
switch ( v8 )
{
case '\\':
case 'b':
case 'f':
case 'n':
case 'r':
case 't':
goto LABEL_16;
case 'u':
result = func3((__int64)v7);
if ( (_DWORD)result == -1 )
return result;
v4 = v9 + 6;
break;
default:
return 0xFFFFFFFFLL;
}
}
}
else
{
++v4;
}
if ( v4 >= v3 )
return 0xFFFFFFFFLL;
}
}

original_code:
int json_checkValidString(char *JSON)
{
 int i, hexResult, objlen;
 char currentChar;
 i = 1;
 objlen = strlen(JSON);
 if(*(JSON) != '\"')
  return -1;
 while(i < objlen)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case '\\':
    i++;
    currentChar = *(JSON + i);
    switch(currentChar)
    {
     case '\\':
     case '\"':
     case '/':
     case 'b':
     case 'f':
     case 'n':
     case 'r':
     case 't':
      i++;
      break;
     case 'u':
      hexResult = json_checkNextFourCharsForHex(JSON + i);
      if(hexResult == -1)
       return -1;
      i += 4;
      i++;
      break;
     default:
      return -1;
    }
    break;
   case '\"':
    i++;
    return i;
   default:
    i++;
  }
 }
 return -1;
}

canonical_original_code:
int json_checkValidString(char *JSON)
{
 int i; int hexResult; int objlen;
 char currentChar;
 i = 1;
 objlen = strlen(JSON);
 if(*(JSON) != '\"')
  return -1;
 while(i < objlen)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case '\\':
    i++;
    currentChar = *(JSON + i);
    switch(currentChar)
    {
     case '\\':
     case '\"':
     case '/':
     case 'b':
     case 'f':
     case 'n':
     case 'r':
     case 't':
      i++;
      break;
     case 'u':
      hexResult = json_checkNextFourCharsForHex(JSON + i);
      if(hexResult == -1)
       return -1;
      i += 4;
      i++;
      break;
     default:
      return -1;
    }
    break;
   case '\"':
    i++;
    return i;
   default:
    i++;
  }
 }
 return -1;
}

variable_types: hexResult int


decompiled_code:
__int64 __fastcall json_checkValidValue(const char *a1)
{
int v2; // eax
int v3; // ecx
int v4; // ebx
__int64 v5; // rdx
const char *v6; // rdi
char v7; // al
__int64 result; // rax
const char *v9; // rcx

v2 = strlen(a1);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = 0;
while ( 2 )
{
v5 = v4;
v6 = &a1[v4];
v7 = *v6;
if ( *v6 > 57 )
{
switch ( v7 )
{
case '[':
result = json_checkValidArray();
goto LABEL_9;
case 'f':
if ( a1[v4 + 1] == 97 && a1[v4 + 2] == 108 && a1[v4 + 3] == 115 && a1[v4 + 4] == 101 )
{
result = 5LL;
}
else
{
v9 = a1;
v5 = -1LL;
v4 = -1;
LABEL_16:
result = 0xFFFFFFFFLL;
if ( *v9 == 117 && a1[v5 + 2] == 108 && a1[v5 + 3] == 108 )
{
++v4;
LABEL_20:
result = (unsigned int)(v4 + 4);
}
}
break;
case 'n':
v9 = &a1[v4 + 1];
goto LABEL_16;
case 't':
result = 0xFFFFFFFFLL;
if ( a1[v4 + 1] != 114 || a1[v4 + 2] != 117 || a1[v4 + 3] != 101 )
return result;
goto LABEL_20;
case '{':
result = json_checkValidJSON();
goto LABEL_9;
default:
return 0xFFFFFFFFLL;
}
return result;
}
if ( v7 <= 8 )
return 0xFFFFFFFFLL;
switch ( v7 )
{
case 9:
case 10:
case 32:
if ( ++v4 >= v3 )
return 0xFFFFFFFFLL;
continue;
case 34:
result = json_checkValidString(v6);
break;
case 45:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
result = json_checkValidNumber(v6);
break;
default:
return 0xFFFFFFFFLL;
}
break;
}
LABEL_9:
if ( (_DWORD)result != -1 )
result = (unsigned int)(v4 + result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
int v2; // eax
int v3; // ecx
int v4; // ebx
__int64 v5; // rdx
const char *v6; // rdi
char v7; // al
__int64 result; // rax
const char *v9; // rcx

v2 = strlen(a1);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = 0;
while ( 2 )
{
v5 = v4;
v6 = &a1[v4];
v7 = *v6;
if ( *v6 > 57 )
{
switch ( v7 )
{
case '[':
result = func8();
goto LABEL_9;
case 'f':
if ( a1[v4 + 1] == 97 && a1[v4 + 2] == 108 && a1[v4 + 3] == 115 && a1[v4 + 4] == 101 )
{
result = 5LL;
}
else
{
v9 = a1;
v5 = -1LL;
v4 = -1;
LABEL_16:
result = 0xFFFFFFFFLL;
if ( *v9 == 117 && a1[v5 + 2] == 108 && a1[v5 + 3] == 108 )
{
++v4;
LABEL_20:
result = (unsigned int)(v4 + 4);
}
}
break;
case 'n':
v9 = &a1[v4 + 1];
goto LABEL_16;
case 't':
result = 0xFFFFFFFFLL;
if ( a1[v4 + 1] != 114 || a1[v4 + 2] != 117 || a1[v4 + 3] != 101 )
return result;
goto LABEL_20;
case '{':
result = func7();
goto LABEL_9;
default:
return 0xFFFFFFFFLL;
}
return result;
}
if ( v7 <= 8 )
return 0xFFFFFFFFLL;
switch ( v7 )
{
case 9:
case 10:
case 32:
if ( ++v4 >= v3 )
return 0xFFFFFFFFLL;
continue;
case 34:
result = func4(v6);
break;
case 45:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
result = func2(v6);
break;
default:
return 0xFFFFFFFFLL;
}
break;
}
LABEL_9:
if ( (_DWORD)result != -1 )
result = (unsigned int)(v4 + result);
return result;
}

original_code:
int json_checkValidValue(char *JSON)
{
 char currentChar;
 int i, breakLoop, objLen, length;
 i = 0;
 breakLoop = 0;
 length = -1;
 objLen = strlen(JSON);
 while(i < objLen && i != -1 && breakLoop == 0)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case '\"':
    breakLoop = 1;
    length = json_checkValidString(JSON + i);
    break;
   case '0':
   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
   case '8':
   case '9':
   case '-':
    breakLoop = 1;
    length = json_checkValidNumber(JSON + i);
    break;
   case '[':
    breakLoop = 1;
    length = json_checkValidArray(JSON + i);
    break;
   case '{':
    breakLoop = 1;
    length = json_checkValidJSON(JSON + i);
    break;
   case 't':
    breakLoop = 1;
    if(*(JSON + i + 1) != 'r' || *(JSON + i + 2) != 'u'
     || *(JSON + i +3) != 'e')
     i = -1;
    else
     length = 4;
    break;
   case 'f':
    breakLoop = 1;
    if(*(JSON + i + 1) != 'a' || *(JSON + i + 2) != 'l'
     || *(JSON + i + 3) != 's' || *(JSON + i + 4) != 'e')
     i = -1;
    else
     length = 5;
   case 'n':
    breakLoop = 1;
    if(*(JSON + i + 1) != 'u' || *(JSON + i + 2) != 'l'
     || *(JSON + i + 3) != 'l')
     i = -1;
    else
     length = 4;
   case ' ':
   case '\n':
   case '\t':
    i++;
    break;
   default:
    breakLoop = 1;
    break;
  }
 }
 if(length != -1)
  return i + length;
 else
  return -1;
}

canonical_original_code:
int json_checkValidValue(char *JSON)
{
 char currentChar;
 int i; int breakLoop; int objLen; int length;
 i = 0;
 breakLoop = 0;
 length = -1;
 objLen = strlen(JSON);
 while(i < objLen && i != -1 && breakLoop == 0)
 {
  currentChar = *(JSON + i);
  switch(currentChar)
  {
   case '\"':
    breakLoop = 1;
    length = json_checkValidString(JSON + i);
    break;
   case '0':
   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
   case '8':
   case '9':
   case '-':
    breakLoop = 1;
    length = json_checkValidNumber(JSON + i);
    break;
   case '[':
    breakLoop = 1;
    length = json_checkValidArray(JSON + i);
    break;
   case '{':
    breakLoop = 1;
    length = json_checkValidJSON(JSON + i);
    break;
   case 't':
    breakLoop = 1;
    if(*(JSON + i + 1) != 'r' || *(JSON + i + 2) != 'u'
     || *(JSON + i +3) != 'e')
     i = -1;
    else
     length = 4;
    break;
   case 'f':
    breakLoop = 1;
    if(*(JSON + i + 1) != 'a' || *(JSON + i + 2) != 'l'
     || *(JSON + i + 3) != 's' || *(JSON + i + 4) != 'e')
     i = -1;
    else
     length = 5;
   case 'n':
    breakLoop = 1;
    if(*(JSON + i + 1) != 'u' || *(JSON + i + 2) != 'l'
     || *(JSON + i + 3) != 'l')
     i = -1;
    else
     length = 4;
   case ' ':
   case '\n':
   case '\t':
    i++;
    break;
   default:
    breakLoop = 1;
    break;
  }
 }
 if(length != -1)
  return i + length;
 else
  return -1;
}

variable_types: breakLoop int

variable_types: objLen int

variable_types: length int