decompiled_code:
double __fastcall compute_diffuse_radiative_fluxes(int a1, double *a2, double *a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double v11; // r13
double v12; // xmm0_8
double result; // xmm0_8
double v14; // xmm2_8
double v15; // xmm0_8
double v16; // [rsp+10h] [rbp-48h]
double v17; // [rsp+10h] [rbp-48h]
double v18; // [rsp+18h] [rbp-40h]

*a3 = a9 * *a2;
v11 = *(double *)&LC0;
if ( *a2 != 0.0 )
{
v18 = a4 / *a2 * 0.07000000000000001;
v17 = 1.1 - a7 * 0.1 * (1.0 - a6);
if ( v17 < 0.0 )
v17 = 0.0;
v15 = cos(a8);
v11 = v18 * v17 * exp(COERCE_DOUBLE(*(_QWORD *)&v15 ^ LC5));
}
v16 = *a2 - *a3;
v12 = pow((1.0 - a6) * a7, 0.7);
result = (1.0 - exp(COERCE_DOUBLE(*(_QWORD *)&v12 ^ LC5)) + v11) * v16;
v14 = *a2 - *a3 - result;
*a2 = v14;
if ( a1 > 2 )
{
printf(" %8.1f %8.1f %8.1f %10.8f ", *a3, result, v14, v11);
}
else if ( a1 == -5 )
{
printf(
"\n DIFRADFLUX: extcoef=%lf thetanoon=%lf S=%lf fluxrefl=%lf fluxabs=%lf fluxtrans=%lf",
a5,
a8,
v11,
*a3,
result,
v14);
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(int a1, double *a2, double *a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double v11; // r13
double v12; // xmm0_8
double result; // xmm0_8
double v14; // xmm2_8
double v15; // xmm0_8
double v16; // [rsp+10h] [rbp-48h]
double v17; // [rsp+10h] [rbp-48h]
double v18; // [rsp+18h] [rbp-40h]

*a3 = a9 * *a2;
v11 = *(double *)&LC0;
if ( *a2 != 0.0 )
{
v18 = a4 / *a2 * 0.07000000000000001;
v17 = 1.1 - a7 * 0.1 * (1.0 - a6);
if ( v17 < 0.0 )
v17 = 0.0;
v15 = cos(a8);
v11 = v18 * v17 * exp(COERCE_DOUBLE(*(_QWORD *)&v15 ^ LC5));
}
v16 = *a2 - *a3;
v12 = pow((1.0 - a6) * a7, 0.7);
result = (1.0 - exp(COERCE_DOUBLE(*(_QWORD *)&v12 ^ LC5)) + v11) * v16;
v14 = *a2 - *a3 - result;
*a2 = v14;
if ( a1 > 2 )
{
printf(" %8.1f %8.1f %8.1f %10.8f ", *a3, result, v14, v11);
}
else if ( a1 == -5 )
{
printf(
"\n DIFRADFLUX: extcoef=%lf thetanoon=%lf S=%lf fluxrefl=%lf fluxabs=%lf fluxtrans=%lf",
a5,
a8,
v11,
*a3,
result,
v14);
}
return result;
}

original_code:
double compute_diffuse_radiative_fluxes( int verbose_flag,
           double *flux_down_ptr,
           double *flux_up_ptr,
           double direct_flux,
           double extinction_coef,
           double gap_fraction,
           double pai,
           double theta_noon,
           double reflectance_canopy)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double S;
 *flux_up_ptr = *flux_down_ptr * reflectance_canopy;
 if ( *flux_down_ptr != 0 ){
  S = 0.07 * ( direct_flux / *flux_down_ptr ) *
   ((0) > (1.1-0.1*pai*(1-gap_fraction)) ? (0) : (1.1-0.1*pai*(1-gap_fraction)))*exp( -1 * cos(theta_noon));
 }
 else{
  S = 0;
 }
 flux_absorbed = ( *flux_down_ptr - *flux_up_ptr)
  * ( 1 - exp(-1*pow(pai*(1-gap_fraction),0.7))+S);
 flux_transmitted = *flux_down_ptr - *flux_up_ptr - flux_absorbed ;
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf(" %8.1f %8.1f %8.1f %10.8f ",
  *flux_up_ptr,flux_absorbed,flux_transmitted, S);
 if ( verbose_flag == -5 ){
  printf("\n          DIFRADFLUX: extcoef=%lf thetanoon=%lf S=%lf fluxrefl=%lf fluxabs=%lf fluxtrans=%lf",
      extinction_coef, theta_noon, S, *flux_up_ptr, flux_absorbed, flux_transmitted);
 }
 return( flux_absorbed );
}

canonical_original_code:
double compute_diffuse_radiative_fluxes(int verbose_flag, double *flux_down_ptr, double *flux_up_ptr, double direct_flux, double extinction_coef, double gap_fraction, double pai, double theta_noon, double reflectance_canopy)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double S;
 *flux_up_ptr = *flux_down_ptr * reflectance_canopy;
 if ( *flux_down_ptr != 0 ){
  S = 0.07 * ( direct_flux / *flux_down_ptr ) *
   ((0) > (1.1-0.1*pai*(1-gap_fraction)) ? (0) : (1.1-0.1*pai*(1-gap_fraction)))*exp( -1 * cos(theta_noon));
 }
 else{
  S = 0;
 }
 flux_absorbed = ( *flux_down_ptr - *flux_up_ptr)
  * ( 1 - exp(-1*pow(pai*(1-gap_fraction),0.7))+S);
 flux_transmitted = *flux_down_ptr - *flux_up_ptr - flux_absorbed ;
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf(" %8.1f %8.1f %8.1f %10.8f ",
  *flux_up_ptr,flux_absorbed,flux_transmitted, S);
 if ( verbose_flag == -5 ){
  printf("\n          DIFRADFLUX: extcoef=%lf thetanoon=%lf S=%lf fluxrefl=%lf fluxabs=%lf fluxtrans=%lf",
      extinction_coef, theta_noon, S, *flux_up_ptr, flux_absorbed, flux_transmitted);
 }
 return( flux_absorbed );
}

variable_types: pai double

variable_types: S double


repo: RHESSys/RHESSys

decompiled_code:
double __fastcall compute_vapor_pressure_deficit(double a1, double a2)
{
double result; // xmm0_8

result = a1 - a2;
if ( result <= 0.0 )
result = 0.0;
return result;
}

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

result = a1 - a2;
if ( result <= 0.0 )
result = 0.0;
return result;
}

original_code:
double compute_vapor_pressure_deficit(double saturation_vapor_pressure,
  double dewpoint_vapor_pressure) {
 return ((saturation_vapor_pressure - dewpoint_vapor_pressure) > (0.0) ? (saturation_vapor_pressure - dewpoint_vapor_pressure) : (0.0));
}

return_type: double


decompiled_code:
void __fastcall destroy_stratum_defaults(__int64 a1, __int64 a2, void *a3)
{
free(a3);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, void *a3)
{
free(a3);
}

original_code:
void destroy_stratum_defaults(int num_default_files,
         int grow_flag,
         struct stratum_default *default_object_list )
{
 free( default_object_list );
 return;
}

canonical_original_code:
void destroy_stratum_defaults(int num_default_files, int grow_flag, struct stratum_default *default_object_list)
{
 free( default_object_list );
 return;
}

variable_types: struct stratum_default { int ID; int lai_end_day; int lai_start_day; int lai_seasonal_flag; double albedo; double APAR_coef; double gsurf_slope; double gsurf_intercept; double K_absorptance; double K_reflectance; double K_transmittance; double lai_stomatal_fraction; double min_heat_capacity; double max_heat_capacity; double PAR_absorptance; double PAR_reflectance; double PAR_transmittance; double specific_rain_capacity; double specific_snow_capacity; double wind_attenuation_coeff; double ustar_overu; struct epconst_struct { double max_lai; double max_storage_percent; double min_percent_leafg; double proj_sla; double shade_sla_mult; double proj_swa; double lai_ratio; double int_coef; double ext_coef; double netpabs; double netpabs_age_mult; double netpabs_shade; double netpabs_sunlit; double flnr_age_mult; double flnr; double flnr_shade; double flnr_sunlit; double ppfd_coef; double topt; double tmax; double tcoef; double psi_open; double psi_close; double psi_threshold; double psi_slp; double psi_intercpt; double vpd_open; double vpd_close; double gl_smax; double gl_smax_sunlit; double gl_smax_shade; double gl_c; double gl_bl; double gs_tmin; double gs_tmax; double gs_trange; double gs_vpd_min; double gs_vpd_max; double gs_vpd_range; double gs_dayl_min; double gs_dayl_max; double gs_dayl_range; double gs_psi_min; double gs_psi_max; double gs_psi_range; double gs_ravg_days; double gsi_thresh; double cpool_mort_fract; int gs_npp_on; double gs_npp_slp; double gs_npp_intercpt; double coef_CO2; int day_leafon; int day_leafoff; int ndays_expand; int ndays_litfall; int phenology_flag; int allocation_flag; int veg_type; int phenology_type; int nfix; int psi_curve; int edible; int Tacclim; int zero_turnover_sprouts; int alternative_ra_surface; double gr_perc; double leaf_turnover; double livewood_turnover; double deadleaf_turnover; double froot_turnover; double kfrag_base; double storage_transfer_prop; double branch_turnover; double min_daily_mortality; double max_daily_mortality; double daily_mortality_threshold; double daily_fire_turnover; double froot_cn; double leaf_cn; double livewood_cn; double leaflitr_cn; double leaflitr_flab; double leaflitr_fucel; double leaflitr_fscel; double leaflitr_flig; double litter_gsurf_intercept; double litter_gsurf_slope; double litter_moist_coef; double litter_density; double frootlitr_flab; double frootlitr_fucel; double frootlitr_fscel; double frootlitr_flig; double deadwood_fucel; double deadwood_fscel; double deadwood_flig; double deadwood_cn; double alloc_frootc_crootc; double alloc_frootc_leafc; double alloc_crootc_stemc; double alloc_stemc_leafc; double alloc_livewoodc_woodc; double height_to_stem_coef; double height_to_stem_exp; double phloemcsa_per_alllai; double alloc_cpool_fhold; double alloc_npool_fhold; double alloc_maxlgf; double alloc_prop_day_growth; int dynamic_alloc_prop_day_growth; double min_leaf_carbon; double resprout_leaf_carbon; double root_growth_direction; double root_distrib_parm; double max_stem_density; double resprout_stem_density; double max_root_depth; double crown_ratio; int max_years_resprout; double waring_pa; double waring_pb; double dickenson_pa; double Tacclim_days; double Tacclim_slp; double Tacclim_intercpt; double gxylem_min_gs; double gxylem_csat; double gxylem_bsat; double gxylem_max; double LWP_gxylem_min; double gxylem_recovery_rate; } epc; struct mrconst_struct { double q10; double per_N; double sapw_max; } mrc; double understory_mort; double consumption; double overstory_mort_k1; double overstory_mort_k2; } *

return_type: void

user_defined_types: struct stratum_default { int ID; int lai_end_day; int lai_start_day; int lai_seasonal_flag; double albedo; double APAR_coef; double gsurf_slope; double gsurf_intercept; double K_absorptance; double K_reflectance; double K_transmittance; double lai_stomatal_fraction; double min_heat_capacity; double max_heat_capacity; double PAR_absorptance; double PAR_reflectance; double PAR_transmittance; double specific_rain_capacity; double specific_snow_capacity; double wind_attenuation_coeff; double ustar_overu; struct epconst_struct epc; struct mrconst_struct mrc; double understory_mort; double consumption; double overstory_mort_k1; double overstory_mort_k2; }


original_code:
void update_litter_soil_mortality(
       struct cdayflux_patch_struct *cdf_patch,
       struct ndayflux_patch_struct *ndf_patch,
       struct soil_c_object *cs_soil,
       struct soil_n_object *ns_soil,
       struct litter_c_object *cs_litr,
       struct litter_n_object *ns_litr,
       struct fire_litter_soil_loss_struct fire_loss)
{
 double m_litr1c_to_atmos;
 double m_litr2c_to_atmos;
 double m_litr3c_to_atmos;
 double m_litr4c_to_atmos;
 double m_soil1c_to_atmos;
 double m_soil2c_to_atmos;
 double m_soil3c_to_atmos;
 double m_soil4c_to_atmos;
 double m_litr1n_to_atmos;
 double m_litr2n_to_atmos;
 double m_litr3n_to_atmos;
 double m_litr4n_to_atmos;
 double m_soil1n_to_atmos;
 double m_soil2n_to_atmos;
 double m_soil3n_to_atmos;
 double m_soil4n_to_atmos;
 m_litr1c_to_atmos = fire_loss.loss_litr1c * cs_litr->litr1c;
 m_litr2c_to_atmos = fire_loss.loss_litr2c * cs_litr->litr2c;
 m_litr3c_to_atmos = fire_loss.loss_litr3c * cs_litr->litr3c;
 m_litr4c_to_atmos = fire_loss.loss_litr4c * cs_litr->litr4c;
 m_soil1c_to_atmos = fire_loss.loss_soil1c * cs_soil->soil1c;
 m_soil2c_to_atmos = fire_loss.loss_soil2c * cs_soil->soil2c;
 m_soil3c_to_atmos = fire_loss.loss_soil3c * cs_soil->soil3c;
 m_soil4c_to_atmos = fire_loss.loss_soil4c * cs_soil->soil4c;
 m_litr1n_to_atmos = fire_loss.loss_litr1n * ns_litr->litr1n;
 m_litr2n_to_atmos = fire_loss.loss_litr2n * ns_litr->litr2n;
 m_litr3n_to_atmos = fire_loss.loss_litr3n * ns_litr->litr3n;
 m_litr4n_to_atmos = fire_loss.loss_litr4n * ns_litr->litr4n;
 m_soil1n_to_atmos = fire_loss.loss_soil1n * ns_soil->soil1n;
 m_soil2n_to_atmos = fire_loss.loss_soil2n * ns_soil->soil2n;
 m_soil3n_to_atmos = fire_loss.loss_soil3n * ns_soil->soil3n;
 m_soil4n_to_atmos = fire_loss.loss_soil4n * ns_soil->soil4n;
 cs_litr->litr1c -= m_litr1c_to_atmos;
 cs_litr->litr2c -= m_litr2c_to_atmos;
 cs_litr->litr3c -= m_litr3c_to_atmos;
 cs_litr->litr4c -= m_litr4c_to_atmos;
 cs_soil->soil1c -= m_soil1c_to_atmos;
 cs_soil->soil2c -= m_soil2c_to_atmos;
 cs_soil->soil3c -= m_soil3c_to_atmos;
 cs_soil->soil4c -= m_soil4c_to_atmos;
 ns_litr->litr1n -= m_litr1n_to_atmos;
 ns_litr->litr2n -= m_litr2n_to_atmos;
 ns_litr->litr3n -= m_litr3n_to_atmos;
 ns_litr->litr4n -= m_litr4n_to_atmos;
 ns_soil->soil1n -= m_soil1n_to_atmos;
 ns_soil->soil2n -= m_soil2n_to_atmos;
 ns_soil->soil3n -= m_soil3n_to_atmos;
 ns_soil->soil4n -= m_soil4n_to_atmos;
 return;
}

canonical_original_code:
void update_litter_soil_mortality(struct cdayflux_patch_struct *cdf_patch, struct ndayflux_patch_struct *ndf_patch, struct soil_c_object *cs_soil, struct soil_n_object *ns_soil, struct litter_c_object *cs_litr, struct litter_n_object *ns_litr, struct fire_litter_soil_loss_struct fire_loss)
{
 double m_litr1c_to_atmos;
 double m_litr2c_to_atmos;
 double m_litr3c_to_atmos;
 double m_litr4c_to_atmos;
 double m_soil1c_to_atmos;
 double m_soil2c_to_atmos;
 double m_soil3c_to_atmos;
 double m_soil4c_to_atmos;
 double m_litr1n_to_atmos;
 double m_litr2n_to_atmos;
 double m_litr3n_to_atmos;
 double m_litr4n_to_atmos;
 double m_soil1n_to_atmos;
 double m_soil2n_to_atmos;
 double m_soil3n_to_atmos;
 double m_soil4n_to_atmos;
 m_litr1c_to_atmos = fire_loss.loss_litr1c * cs_litr->litr1c;
 m_litr2c_to_atmos = fire_loss.loss_litr2c * cs_litr->litr2c;
 m_litr3c_to_atmos = fire_loss.loss_litr3c * cs_litr->litr3c;
 m_litr4c_to_atmos = fire_loss.loss_litr4c * cs_litr->litr4c;
 m_soil1c_to_atmos = fire_loss.loss_soil1c * cs_soil->soil1c;
 m_soil2c_to_atmos = fire_loss.loss_soil2c * cs_soil->soil2c;
 m_soil3c_to_atmos = fire_loss.loss_soil3c * cs_soil->soil3c;
 m_soil4c_to_atmos = fire_loss.loss_soil4c * cs_soil->soil4c;
 m_litr1n_to_atmos = fire_loss.loss_litr1n * ns_litr->litr1n;
 m_litr2n_to_atmos = fire_loss.loss_litr2n * ns_litr->litr2n;
 m_litr3n_to_atmos = fire_loss.loss_litr3n * ns_litr->litr3n;
 m_litr4n_to_atmos = fire_loss.loss_litr4n * ns_litr->litr4n;
 m_soil1n_to_atmos = fire_loss.loss_soil1n * ns_soil->soil1n;
 m_soil2n_to_atmos = fire_loss.loss_soil2n * ns_soil->soil2n;
 m_soil3n_to_atmos = fire_loss.loss_soil3n * ns_soil->soil3n;
 m_soil4n_to_atmos = fire_loss.loss_soil4n * ns_soil->soil4n;
 cs_litr->litr1c -= m_litr1c_to_atmos;
 cs_litr->litr2c -= m_litr2c_to_atmos;
 cs_litr->litr3c -= m_litr3c_to_atmos;
 cs_litr->litr4c -= m_litr4c_to_atmos;
 cs_soil->soil1c -= m_soil1c_to_atmos;
 cs_soil->soil2c -= m_soil2c_to_atmos;
 cs_soil->soil3c -= m_soil3c_to_atmos;
 cs_soil->soil4c -= m_soil4c_to_atmos;
 ns_litr->litr1n -= m_litr1n_to_atmos;
 ns_litr->litr2n -= m_litr2n_to_atmos;
 ns_litr->litr3n -= m_litr3n_to_atmos;
 ns_litr->litr4n -= m_litr4n_to_atmos;
 ns_soil->soil1n -= m_soil1n_to_atmos;
 ns_soil->soil2n -= m_soil2n_to_atmos;
 ns_soil->soil3n -= m_soil3n_to_atmos;
 ns_soil->soil4n -= m_soil4n_to_atmos;
 return;
}

variable_types: struct cdayflux_patch_struct { double do_litr1c_loss; double do_litr2c_loss; double do_litr3c_loss; double do_litr4c_loss; double do_soil1c_loss; double do_soil2c_loss; double do_soil3c_loss; double do_soil4c_loss; double total_DOC_loss; double DOC_to_gw; double plitr1c_loss; double plitr2c_loss; double plitr3c_loss; double plitr4c_loss; double psoil1c_loss; double psoil2c_loss; double psoil3c_loss; double psoil4c_loss; double kl4; double decomp_w_scalar; double decomp_t_scalar; double leafc_to_litr1c; double leafc_to_litr2c; double leafc_to_litr3c; double leafc_to_litr4c; double frootc_to_litr1c; double frootc_to_litr2c; double frootc_to_litr3c; double frootc_to_litr4c; double litr1c_to_soil1c; double litr2c_to_soil2c; double litr3c_to_litr2c; double litr4c_to_soil3c; double soil1c_to_soil2c; double soil2c_to_soil3c; double soil3c_to_soil4c; double cwdc_to_litr2c; double cwdc_to_litr3c; double cwdc_to_litr4c; double litr1c_hr; double litr2c_hr; double litr3c_hr; double litr4c_hr; double soil1c_hr; double soil2c_hr; double soil3c_hr; double soil4c_hr; double m_leafc_to_litr1c; double m_leafc_to_litr2c; double m_leafc_to_litr3c; double m_leafc_to_litr4c; double m_frootc_to_litr1c; double m_frootc_to_litr2c; double m_frootc_to_litr3c; double m_frootc_to_litr4c; double m_leafc_store_to_litr1c; double m_frootc_store_to_litr1c; double m_livestemc_store_to_litr1c; double m_deadstemc_store_to_litr1c; double m_livecrootc_store_to_litr1c; double m_deadcrootc_store_to_litr1c; double m_leafc_transfer_to_litr1c; double m_frootc_transfer_to_litr1c; double m_livestemc_transfer_to_litr1c; double m_deadstemc_transfer_to_litr1c; double m_livecrootc_transfer_to_litr1c; double m_deadcrootc_transfer_to_litr1c; double m_gresp_store_to_litr1c; double m_gresp_transfer_to_litr1c; double m_litr1c_to_atmos; double m_litr2c_to_atmos; double m_litr3c_to_atmos; double m_litr4c_to_atmos; double m_soil1c_to_atmos; double m_soil2c_to_atmos; double m_soil3c_to_atmos; double m_soil4c_to_atmos; } *

variable_types: struct ndayflux_patch_struct { double do_litr1n_loss; double do_litr2n_loss; double do_litr3n_loss; double do_litr4n_loss; double do_soil1n_loss; double do_soil2n_loss; double do_soil3n_loss; double do_soil4n_loss; double total_DON_loss; double DON_to_gw; double mineralized; double potential_immob; double net_mineralized; double pmnf_l1s1; double pmnf_l2s2; double pmnf_l3l2; double pmnf_l4s3; double pmnf_s1s2; double pmnf_s2s3; double pmnf_s3s4; double pmnf_s4; double leafn_to_litr1n; double leafn_to_litr2n; double leafn_to_litr3n; double leafn_to_litr4n; double frootn_to_litr1n; double frootn_to_litr2n; double frootn_to_litr3n; double frootn_to_litr4n; double litr1n_to_soil1n; double litr2n_to_soil2n; double litr4n_to_soil3n; double litr3n_to_litr2n; double soil1n_to_soil2n; double soil2n_to_soil3n; double soil3n_to_soil4n; double cwdn_to_litr2n; double cwdn_to_litr3n; double cwdn_to_litr4n; double plant_potential_ndemand; double plant_avail_uptake; double sminn_to_soil1n_l1; double sminn_to_soil2n_l2; double sminn_to_soil2n_l3; double sminn_to_soil3n_l4; double sminn_to_soil2n_s1; double sminn_to_soil3n_s2; double sminn_to_soil4n_s3; double sminn_to_npool; double soil4n_to_sminn; double sminn_to_nitrate; double m_leafn_to_litr1n; double m_leafn_to_litr2n; double m_leafn_to_litr3n; double m_leafn_to_litr4n; double m_frootn_to_litr1n; double m_frootn_to_litr2n; double m_frootn_to_litr3n; double m_frootn_to_litr4n; double m_livestemn_to_litr1n; double m_livecrootn_to_litr1n; double m_leafn_store_to_litr1n; double m_frootn_store_to_litr1n; double m_livestemn_store_to_litr1n; double m_deadstemn_store_to_litr1n; double m_livecrootn_store_to_litr1n; double m_deadcrootn_store_to_litr1n; double m_leafn_transfer_to_litr1n; double m_frootn_transfer_to_litr1n; double m_livestemn_transfer_to_litr1n; double m_deadstemn_transfer_to_litr1n; double m_livecrootn_transfer_to_litr1n; double m_deadcrootn_transfer_to_litr1n; double m_retransn_to_litr1n; double sminn_to_nvol; double denitrif; double ndep_to_sminn; double nfix_to_sminn; double N_to_gw; double m_litr1n_to_atmos; double m_litr2n_to_atmos; double m_litr3n_to_atmos; double m_litr4n_to_atmos; double m_soil1n_to_atmos; double m_soil2n_to_atmos; double m_soil3n_to_atmos; double m_soil4n_to_atmos; } *

variable_types: struct soil_c_object { double frootc; double DOC; double DOC_Qin; double DOC_Qout; double DOC_Qin_total; double DOC_Qout_total; double totalc; double soil_cpool; double soil1c; double soil2c; double soil3c; double soil4c; double soil1c_hr_snk; double soil2c_hr_snk; double soil3c_hr_snk; double soil4c_hr_snk; } *

variable_types: struct soil_n_object { double nlimit; double fract_potential_immob; double fract_potential_uptake; double totaln; double soil_npool; double DON; double DON_Qin; double DON_Qout; double DON_Qin_total; double DON_Qout_total; double soil1n; double soil2n; double soil3n; double soil4n; double sminn; double nitrate; double NO3_Qin_total; double NO3_Qout_total; double NO3_Qin; double NO3_Qout; double NH4_Qin; double NH4_Qout; double NH4_Qin_total; double NH4_Qout_total; double leach; double nfix_src; double ndep_src; double nleached_snk; double nvolatilized_snk; } *

variable_types: struct litter_c_object { double totalc; double litr1c; double litr2c; double litr3c; double litr4c; double litr1c_hr_snk; double litr2c_hr_snk; double litr4c_hr_snk; double fire_snk; double t_scalar; double w_scalar; } *

variable_types: struct litter_n_object { double totaln; double litr1n; double litr2n; double litr3n; double litr4n; double fire_snk; } *

variable_types: struct fire_litter_soil_loss_struct { double loss_litr1c; double loss_litr2c; double loss_litr3c; double loss_litr4c; double loss_soil1c; double loss_soil2c; double loss_soil3c; double loss_soil4c; double loss_litr1n; double loss_litr2n; double loss_litr3n; double loss_litr4n; double loss_soil1n; double loss_soil2n; double loss_soil3n; double loss_soil4n; }


original_code:
double compute_direct_radiative_PAR_fluxes( int verbose_flag,
      double *flux_down_ptr,
      double extinction_coef,
      double gap_fraction,
      double proj_pai,
      double proj_lai,
      double all_lai,
      double theta_noon,
      double reflectance_canopy,
      double reflectance_bkgd)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double unreflected_fraction;
 double noon_extinction;
 double noon_transmission;
 flux_reflected = *flux_down_ptr * reflectance_canopy;
 unreflected_fraction = ( 1- reflectance_canopy);
 noon_extinction = extinction_coef*(1-gap_fraction)*proj_pai/cos(theta_noon);
 if (( noon_extinction == 0 ) || (all_lai < 0.000000001)) {
  noon_transmission = 1;
  flux_absorbed = 0;
 }
 else if ( noon_extinction < -0.3 ){
  noon_transmission = exp(noon_extinction);
  flux_absorbed = *flux_down_ptr * (unreflected_fraction-noon_transmission);
 }
 else{
  noon_extinction = ( noon_extinction *1.1 );
  noon_transmission = exp(noon_extinction);
    flux_absorbed = *flux_down_ptr * (unreflected_fraction-noon_transmission);
 }
 if ( flux_absorbed < 0 ) flux_absorbed = 0;
  flux_transmitted = *flux_down_ptr - flux_reflected - flux_absorbed;
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f ",
  flux_reflected,flux_absorbed,flux_transmitted);
 return( flux_absorbed );
}

canonical_original_code:
double compute_direct_radiative_PAR_fluxes(int verbose_flag, double *flux_down_ptr, double extinction_coef, double gap_fraction, double proj_pai, double proj_lai, double all_lai, double theta_noon, double reflectance_canopy, double reflectance_bkgd)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double unreflected_fraction;
 double noon_extinction;
 double noon_transmission;
 flux_reflected = *flux_down_ptr * reflectance_canopy;
 unreflected_fraction = ( 1- reflectance_canopy);
 noon_extinction = extinction_coef*(1-gap_fraction)*proj_pai/cos(theta_noon);
 if (( noon_extinction == 0 ) || (all_lai < 0.000000001)) {
  noon_transmission = 1;
  flux_absorbed = 0;
 }
 else if ( noon_extinction < -0.3 ){
  noon_transmission = exp(noon_extinction);
  flux_absorbed = *flux_down_ptr * (unreflected_fraction-noon_transmission);
 }
 else{
  noon_extinction = ( noon_extinction *1.1 );
  noon_transmission = exp(noon_extinction);
    flux_absorbed = *flux_down_ptr * (unreflected_fraction-noon_transmission);
 }
 if ( flux_absorbed < 0 ) flux_absorbed = 0;
  flux_transmitted = *flux_down_ptr - flux_reflected - flux_absorbed;
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f ",
  flux_reflected,flux_absorbed,flux_transmitted);
 return( flux_absorbed );
}


decompiled_code:
__int64 __fastcall update_rooting_depth(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7)
{
double v8; // rbx

if ( a7 <= 0.000000001 )
*(double *)(a1 + 32) = pow(a2 + a2, a3) * 3.0 / a4;
else
*(double *)(a1 + 32) = pow((a2 + a2) / a7, a3) * 3.0 / a4;
v8 = fmin(fmin(*(double *)(a1 + 32), a5), a6 - 0.0001);
if ( v8 <= 0.0 )
v8 = *(double *)&LC0;
*(double *)(a1 + 32) = v8;
return 0LL;
}

original_code:
int update_rooting_depth( struct rooting_zone_object *rootzone,
         double rootc,
         double root_growth_direction,
         double root_distrib_parm,
         double max_root_depth,
         double soil_depth,
         double stem_density)
{
 int ok=1;
 double biomass_carbon_ratio;
 biomass_carbon_ratio = 2.0;
 if (stem_density > 0.000000001) {
 rootzone->depth = 3.0 * pow((biomass_carbon_ratio*rootc/stem_density), root_growth_direction)
    / root_distrib_parm;
 }
 else {
 rootzone->depth = 3.0 * pow((biomass_carbon_ratio*rootc), root_growth_direction)
    / root_distrib_parm;
 }
 rootzone->depth = ((rootzone->depth) < (max_root_depth) ? (rootzone->depth) : (max_root_depth));
 rootzone->depth = ((rootzone->depth) < (soil_depth-0.0001) ? (rootzone->depth) : (soil_depth-0.0001));
 rootzone->depth = ((rootzone->depth) > (0.0) ? (rootzone->depth) : (0.0));
 return (!ok);
}

canonical_original_code:
int update_rooting_depth(struct rooting_zone_object *rootzone, double rootc, double root_growth_direction, double root_distrib_parm, double max_root_depth, double soil_depth, double stem_density)
{
 int ok = 1;
 double biomass_carbon_ratio;
 biomass_carbon_ratio = 2.0;
 if (stem_density > 0.000000001) {
 rootzone->depth = 3.0 * pow((biomass_carbon_ratio*rootc/stem_density), root_growth_direction)
    / root_distrib_parm;
 }
 else {
 rootzone->depth = 3.0 * pow((biomass_carbon_ratio*rootc), root_growth_direction)
    / root_distrib_parm;
 }
 rootzone->depth = ((rootzone->depth) < (max_root_depth) ? (rootzone->depth) : (max_root_depth));
 rootzone->depth = ((rootzone->depth) < (soil_depth-0.0001) ? (rootzone->depth) : (soil_depth-0.0001));
 rootzone->depth = ((rootzone->depth) > (0.0) ? (rootzone->depth) : (0.0));
 return (!ok);
}

variable_types: struct rooting_zone_object { double field_capacity; double potential_sat; double sat; double unsat; double depth; double preday_depth; double S; double T; } *

variable_types: rootc double

variable_types: ok int

return_type: int


decompiled_code:
double __fastcall leaf_conductance_APAR_curve(double a1, double a2)
{
double result; // xmm0_8

if ( a2 <= 0.000000001 )
result = *(double *)&LC0;
else
result = a1 * a2 / (a1 * a2 + 1.0);
return result;
}

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

if ( a2 <= 0.000000001 )
result = *(double *)&LC0;
else
result = a1 * a2 / (a1 * a2 + 1.0);
return result;
}

original_code:
double leaf_conductance_APAR_curve( double APAR,
         double APAR_coef)
{
 double m_APAR;
 if (APAR_coef > 0.000000001)
  m_APAR = ( APAR * APAR_coef ) / ( 1.0 + APAR * APAR_coef );
 else
  m_APAR = 1.0;
 return(m_APAR);
}

canonical_original_code:
double leaf_conductance_APAR_curve(double APAR, double APAR_coef)
{
 double m_APAR;
 if (APAR_coef > 0.000000001)
  m_APAR = ( APAR * APAR_coef ) / ( 1.0 + APAR * APAR_coef );
 else
  m_APAR = 1.0;
 return(m_APAR);
}

variable_types: APAR double


decompiled_code:
__int64 __fastcall stream_make_context(int a1, int a2, __int64 a3, _QWORD *a4)
{
_DWORD *v6; // rax
__int64 result; // rax

if ( a4 )
{
v6 = calloc(1uLL, 0x10uLL);
if ( v6 )
{
*v6 = a1;
v6[1] = a2;
*((_QWORD *)v6 + 1) = a3;
*a4 = v6;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate memory for the stream search context.\n", 1uLL, 0x40uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return stream context pointer is NULL.\n", 1uLL, 0x2EuLL, stderr);
result = 0LL;
}
return result;
}

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

if ( a4 )
{
v6 = calloc(1uLL, 0x10uLL);
if ( v6 )
{
*v6 = a1;
v6[1] = a2;
*((_QWORD *)v6 + 1) = a3;
*a4 = v6;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate memory for the stream search context.\n", 1uLL, 0x40uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return stream context pointer is NULL.\n", 1uLL, 0x2EuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool stream_make_context(
  int _maxr,
  int _maxc,
  const int* _stream,
  void** _rtn_ctx)
{
 bool result = true;
 if(_rtn_ctx == 0) {
  fprintf(stderr, "ERROR: Return stream context pointer is NULL.\n");
  result = false;
 } else {
  stream_context_t* context = (stream_context_t*)calloc(1, sizeof(stream_context_t));
  if(context == 0) {
   fprintf(stderr, "ERROR: Failed to allocate memory for the stream search context.\n");
   result = false;
  } else {
   context->maxr_ = _maxr;
   context->maxc_ = _maxc;
   context->stream_ = _stream;
   *_rtn_ctx = (void*)context;
  }
 }
 return result;
}

canonical_original_code:
short stream_make_context(int _maxr, int _maxc, int *_stream, void **_rtn_ctx)
{
 short result = true;
 if(_rtn_ctx == 0) {
  fprintf(stderr, "ERROR: Return stream context pointer is NULL.\n");
  result = false;
 } else {
  struct stream_context_s *context = (stream_context_t*)calloc(1, sizeof(stream_context_t));
  if(context == 0) {
   fprintf(stderr, "ERROR: Failed to allocate memory for the stream search context.\n");
   result = false;
  } else {
   context->maxr_ = _maxr;
   context->maxc_ = _maxc;
   context->stream_ = _stream;
   *_rtn_ctx = (void *)context;
  }
 }
 return result;
}

variable_types: result short

variable_types: struct stream_context_s { int maxr_; int maxc_; int *stream_; } *

return_type: short


decompiled_code:
__int64 __fastcall stream_search_predicate(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int *a5, _DWORD *a6)
{
__int64 result; // rax
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a5 )
{
result = row_col_to_index(a3, a4, *a5, a5[1], v9);
if ( (_WORD)result )
{
*a6 = *(_DWORD *)(*((_QWORD *)a5 + 1) + 4LL * v9[0]) == 1;
result = 1LL;
}
}
else
{
fwrite("ERROR: Search context pointer is NULL.\n", 1uLL, 0x27uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int *a5, _DWORD *a6)
{
__int64 result; // rax
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a5 )
{
result = row_col_to_index(a3, a4, *a5, a5[1], v9);
if ( (_WORD)result )
{
*a6 = *(_DWORD *)(*((_QWORD *)a5 + 1) + 4LL * v9[0]) == 1;
result = 1LL;
}
}
else
{
fwrite("ERROR: Search context pointer is NULL.\n", 1uLL, 0x27uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool stream_search_predicate(
  int _subjectRow,
  int _subjectCol,
  int _row,
  int _col,
  void* _context,
  int* _rtn_vote)
{
 bool result = true;
 if(_context == 0) {
  fprintf(stderr, "ERROR: Search context pointer is NULL.\n");
  result = false;
 } else {
  stream_context_t* context = (stream_context_t*)_context;
  int index;
  if(!row_col_to_index(_row, _col, context->maxr_, context->maxc_, &index)) {
   result = false;
  } else {
   if(context->stream_[index] == 1) {
    *_rtn_vote = 1;
   } else {
    *_rtn_vote = 0;
   }
  }
 }
 return result;
}

canonical_original_code:
short stream_search_predicate(int _subjectRow, int _subjectCol, int _row, int _col, void *_context, int *_rtn_vote)
{
 short result = true;
 if(_context == 0) {
  fprintf(stderr, "ERROR: Search context pointer is NULL.\n");
  result = false;
 } else {
  struct stream_context_s *context = (stream_context_t*)_context;
  int index;
  if(!row_col_to_index(_row, _col, context->maxr_, context->maxc_, &index)) {
   result = false;
  } else {
   if(context->stream_[index] == 1) {
    *_rtn_vote = 1;
   } else {
    *_rtn_vote = 0;
   }
  }
 }
 return result;
}

variable_types: index int

user_defined_types: struct stream_context_s { int maxr_; int maxc_; int *stream_; }


decompiled_code:
__int64 __fastcall stream_search_tiebreaker(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, _DWORD *a6, _DWORD *a7)
{
*a6 = a1;
*a7 = a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, _DWORD *a6, _DWORD *a7)
{
*a6 = a1;
*a7 = a2;
return 1LL;
}

original_code:
bool stream_search_tiebreaker(
 int _rowA,
 int _colA,
 int _rowB,
 int _colB,
 void* _context,
 int* _winnerRow,
 int* _winnerCol) {
 *_winnerRow = _rowA;
 *_winnerCol = _colA;
 return true;
}

canonical_original_code:
short stream_search_tiebreaker(int _rowA, int _colA, int _rowB, int _colB, void *_context, int *_winnerRow, int *_winnerCol) {
 *_winnerRow = _rowA;
 *_winnerCol = _colA;
 return true;
}


decompiled_code:
__int64 __fastcall parse_dyn_flag(void *ptr)
{
bool v2; // zf
unsigned int v3; // ebx

v2 = memcmp(ptr, "STATIC", 6uLL) == 0;
v3 = !v2;
if ( !v2 )
{
v2 = memcmp(ptr, "static", 6uLL) == 0;
v3 = !v2;
if ( !v2 )
{
if ( !memcmp(ptr, "DYNAMIC", 7uLL) )
{
v3 = 2;
}
else if ( !memcmp(ptr, "dynamic", 7uLL) )
{
v3 = 2;
}
else
{
v2 = memcmp(ptr, "CONSTANT", 8uLL) == 0;
v3 = !v2;
if ( !v2 )
{
v2 = memcmp(ptr, "constant", 8uLL) == 0;
v3 = !v2;
if ( !v2 )
{
if ( !strcmp((const char *)ptr, "DROUGHT") )
{
v3 = 1;
}
else
{
if ( strcmp((const char *)ptr, "drought") )
{
fwrite("\n FATAL ERROR - parse_dyn_flag", 1uLL, 0x1EuLL, stderr);
fprintf(stderr, "\n Flag must be stati or dynamic and is %s", (const char *)ptr);
exit(1);
}
v3 = 1;
}
}
}
}
}
}
free(ptr);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
bool v2; // zf
unsigned int v3; // ebx

v2 = memcmp(ptr, "STATIC", 6uLL) == 0;
v3 = !v2;
if ( !v2 )
{
v2 = memcmp(ptr, "static", 6uLL) == 0;
v3 = !v2;
if ( !v2 )
{
if ( !memcmp(ptr, "DYNAMIC", 7uLL) )
{
v3 = 2;
}
else if ( !memcmp(ptr, "dynamic", 7uLL) )
{
v3 = 2;
}
else
{
v2 = memcmp(ptr, "CONSTANT", 8uLL) == 0;
v3 = !v2;
if ( !v2 )
{
v2 = memcmp(ptr, "constant", 8uLL) == 0;
v3 = !v2;
if ( !v2 )
{
if ( !strcmp((const char *)ptr, "DROUGHT") )
{
v3 = 1;
}
else
{
if ( strcmp((const char *)ptr, "drought") )
{
fwrite("\n FATAL ERROR - parse_dyn_flag", 1uLL, 0x1EuLL, stderr);
fprintf(stderr, "\n Flag must be stati or dynamic and is %s", (const char *)ptr);
exit(1);
}
v3 = 1;
}
}
}
}
}
}
free(ptr);
return v3;
}

original_code:
int parse_dyn_flag( char *input_string)
{
 int dyn_flag;
 if ((strncmp(input_string,"STATIC",6) == 0) ||
  (strncmp(input_string, "static",6) == 0) )
  dyn_flag = 0;
 else if ((strncmp(input_string,"DYNAMIC",7) == 0) ||
  (strncmp(input_string, "dynamic",7) == 0) )
  dyn_flag = 2;
 else if ((strncmp(input_string,"CONSTANT",8) == 0) ||
  (strncmp(input_string, "constant",8) == 0) )
  dyn_flag = 0;
 else if ((strncmp(input_string,"DROUGHT",9) == 0) ||
  (strncmp(input_string, "drought",9) == 0) )
  dyn_flag = 1;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_dyn_flag");
  fprintf(stderr,"\n Flag must be stati or dynamic and is %s" , input_string);
  exit(1);
 }
 free(input_string);
 return(dyn_flag);
}

canonical_original_code:
int parse_dyn_flag(char *input_string)
{
 int dyn_flag;
 if ((strncmp(input_string,"STATIC",6) == 0) ||
  (strncmp(input_string, "static",6) == 0) )
  dyn_flag = 0;
 else if ((strncmp(input_string,"DYNAMIC",7) == 0) ||
  (strncmp(input_string, "dynamic",7) == 0) )
  dyn_flag = 2;
 else if ((strncmp(input_string,"CONSTANT",8) == 0) ||
  (strncmp(input_string, "constant",8) == 0) )
  dyn_flag = 0;
 else if ((strncmp(input_string,"DROUGHT",9) == 0) ||
  (strncmp(input_string, "drought",9) == 0) )
  dyn_flag = 1;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_dyn_flag");
  fprintf(stderr,"\n Flag must be stati or dynamic and is %s" , input_string);
  exit(1);
 }
 free(input_string);
 return(dyn_flag);
}


decompiled_code:
void __fastcall destroy_fire_defaults(__int64 a1, __int64 a2, void *a3)
{
free(a3);
}

original_code:
void destroy_fire_defaults(int num_default_files,
       int grow_flag,
       struct fire_default *default_object_list )
{
 free( default_object_list );
 return;
}

canonical_original_code:
void destroy_fire_defaults(int num_default_files, int grow_flag, struct fire_default *default_object_list)
{
 free( default_object_list );
 return;
}

variable_types: struct fire_default { int ID; double ndays_average; double load_k1; double moisture_k1; double load_k2; double moisture_k2; double winddir_k1; double winddir_k2; double windmax; double slope_k1; double slope_k2; double ignition_tmin; double ignition_col; double ignition_row; int fire_write; int fire_verbose; int n_rows; int n_cols; int fire_in_buffer; int spread_calc_type; double mean_log_wind; double sd_log_wind; double mean1_rvm; double mean2_rvm; double kappa1_rvm; double kappa2_rvm; double p_rvm; double ign_def_mod; double veg_k1; double veg_k2; double mean_ign; long ran_seed; double moisture_ign_k1; double moisture_ign_k2; double load_ign_k1; double load_ign_k2; int calc_fire_effects; int include_wui; int fire_size_name; double wind_shift; } *


original_code:
int update_dissolved_organic_losses(
      struct date current_date,
      double DON_production_rate,
      struct soil_c_object *cs_soil,
      struct soil_n_object *ns_soil,
      struct litter_c_object *cs_litr,
      struct litter_n_object *ns_litr,
      struct cdayflux_patch_struct *cdf,
      struct ndayflux_patch_struct *ndf)
{
 double cn_l1,cn_l2,cn_l3,cn_l4,cn_s1,cn_s2,cn_s3,cn_s4;
 int ok;
 ok=1;
 if (ns_litr->litr1n > 0.000000001) cn_l1 = cs_litr->litr1c/ns_litr->litr1n;
  else cn_l1 = 50;
 if (ns_litr->litr2n > 0.000000001) cn_l2 = cs_litr->litr2c/ns_litr->litr2n;
  else cn_l2 = 250.0;
 if (ns_litr->litr3n > 0.000000001) cn_l3 = cs_litr->litr3c/ns_litr->litr3n;
  else cn_l3 = 500.0;
 if (ns_litr->litr4n > 0.000000001) cn_l4 = cs_litr->litr4c/ns_litr->litr4n;
  else cn_l4 = 500.0;
 cn_s1 = 12.0;
 cn_s2 = 12.0;
 cn_s3 = 10.0;
 cn_s4 = 8.0;
 if (-1.0*ndf->pmnf_l1s1 > 0.000000001) {
  ndf->do_litr1n_loss = DON_production_rate * -1.0*ndf->pmnf_l1s1;
  cdf->do_litr1c_loss = ndf->do_litr1n_loss * cn_l1;
  }
 if (-1.0*ndf->pmnf_l2s2 > 0.000000001) {
  ndf->do_litr2n_loss = DON_production_rate * -1.0*ndf->pmnf_l2s2;
  cdf->do_litr2c_loss = ndf->do_litr2n_loss * cn_l2;
  }
 if (-1.0*ndf->pmnf_l4s3 > 0.000000001) {
  ndf->do_litr3n_loss = DON_production_rate * -1.0*ndf->pmnf_l3l2;
  cdf->do_litr3c_loss = ndf->do_litr3n_loss * cn_l3;
  }
 if (-1.0*ndf->pmnf_l4s3 > 0.000000001) {
  ndf->do_litr4n_loss = DON_production_rate * -1.0*ndf->pmnf_l4s3;
  cdf->do_litr4c_loss = ndf->do_litr4n_loss * cn_l4;
  }
 if (-1.0*ndf->pmnf_s1s2 > 0.000000001) {
  ndf->do_soil1n_loss = DON_production_rate * -1.0*ndf->pmnf_s1s2;
  cdf->do_soil1c_loss = ndf->do_soil1n_loss * cn_s1;
  }
 if (-1.0*ndf->pmnf_s2s3 > 0.000000001) {
  ndf->do_soil2n_loss = DON_production_rate * -1.0*ndf->pmnf_s2s3;
  cdf->do_soil2c_loss = ndf->do_soil2n_loss * cn_s2;
  }
 if (-1.0*ndf->pmnf_s3s4 > 0.000000001) {
  ndf->do_soil3n_loss = DON_production_rate * -1.0*ndf->pmnf_s3s4;
  cdf->do_soil3c_loss = ndf->do_soil3n_loss * cn_s3;
  }
 if (-1.0*ndf->soil4n_to_sminn > 0.000000001) {
  ndf->do_soil4n_loss = DON_production_rate * -1.0*ndf->soil4n_to_sminn;
  cdf->do_soil4c_loss = ndf->do_soil4n_loss * cn_s4;
  }
 cs_litr->litr1c -= cdf->do_litr1c_loss;
 cs_litr->litr3c -= cdf->do_litr3c_loss;
 cs_litr->litr2c -= cdf->do_litr2c_loss;
 cs_litr->litr4c -= cdf->do_litr4c_loss;
 cs_soil->soil1c -= cdf->do_soil1c_loss;
 cs_soil->soil2c -= cdf->do_soil2c_loss;
 cs_soil->soil3c -= cdf->do_soil3c_loss;
 cs_soil->soil4c -= cdf->do_soil4c_loss;
 ns_litr->litr1n -= ndf->do_litr1n_loss;
 ns_litr->litr2n -= ndf->do_litr2n_loss;
 ns_litr->litr3n -= ndf->do_litr3n_loss;
 ns_litr->litr4n -= ndf->do_litr4n_loss;
 ns_soil->soil1n -= ndf->do_soil1n_loss;
 ns_soil->soil2n -= ndf->do_soil2n_loss;
 ns_soil->soil3n -= ndf->do_soil3n_loss;
 ns_soil->soil4n -= ndf->do_soil4n_loss;
 cs_soil->DOC += (cdf->do_soil1c_loss + cdf->do_soil2c_loss + cdf->do_soil3c_loss + cdf->do_soil4c_loss);
 ns_soil->DON += ( ndf->do_soil1n_loss + ndf->do_soil3n_loss + ndf->do_soil2n_loss + ndf->do_soil4n_loss);
 return (!ok);
}

canonical_original_code:
int update_dissolved_organic_losses(struct date current_date, double DON_production_rate, struct soil_c_object *cs_soil, struct soil_n_object *ns_soil, struct litter_c_object *cs_litr, struct litter_n_object *ns_litr, struct cdayflux_patch_struct *cdf, struct ndayflux_patch_struct *ndf)
{
 double cn_l1; double cn_l2; double cn_l3; double cn_l4; double cn_s1; double cn_s2; double cn_s3; double cn_s4;
 int ok;
 ok=1;
 if (ns_litr->litr1n > 0.000000001) cn_l1 = cs_litr->litr1c/ns_litr->litr1n;
  else cn_l1 = 50;
 if (ns_litr->litr2n > 0.000000001) cn_l2 = cs_litr->litr2c/ns_litr->litr2n;
  else cn_l2 = 250.0;
 if (ns_litr->litr3n > 0.000000001) cn_l3 = cs_litr->litr3c/ns_litr->litr3n;
  else cn_l3 = 500.0;
 if (ns_litr->litr4n > 0.000000001) cn_l4 = cs_litr->litr4c/ns_litr->litr4n;
  else cn_l4 = 500.0;
 cn_s1 = 12.0;
 cn_s2 = 12.0;
 cn_s3 = 10.0;
 cn_s4 = 8.0;
 if (-1.0*ndf->pmnf_l1s1 > 0.000000001) {
  ndf->do_litr1n_loss = DON_production_rate * -1.0*ndf->pmnf_l1s1;
  cdf->do_litr1c_loss = ndf->do_litr1n_loss * cn_l1;
  }
 if (-1.0*ndf->pmnf_l2s2 > 0.000000001) {
  ndf->do_litr2n_loss = DON_production_rate * -1.0*ndf->pmnf_l2s2;
  cdf->do_litr2c_loss = ndf->do_litr2n_loss * cn_l2;
  }
 if (-1.0*ndf->pmnf_l4s3 > 0.000000001) {
  ndf->do_litr3n_loss = DON_production_rate * -1.0*ndf->pmnf_l3l2;
  cdf->do_litr3c_loss = ndf->do_litr3n_loss * cn_l3;
  }
 if (-1.0*ndf->pmnf_l4s3 > 0.000000001) {
  ndf->do_litr4n_loss = DON_production_rate * -1.0*ndf->pmnf_l4s3;
  cdf->do_litr4c_loss = ndf->do_litr4n_loss * cn_l4;
  }
 if (-1.0*ndf->pmnf_s1s2 > 0.000000001) {
  ndf->do_soil1n_loss = DON_production_rate * -1.0*ndf->pmnf_s1s2;
  cdf->do_soil1c_loss = ndf->do_soil1n_loss * cn_s1;
  }
 if (-1.0*ndf->pmnf_s2s3 > 0.000000001) {
  ndf->do_soil2n_loss = DON_production_rate * -1.0*ndf->pmnf_s2s3;
  cdf->do_soil2c_loss = ndf->do_soil2n_loss * cn_s2;
  }
 if (-1.0*ndf->pmnf_s3s4 > 0.000000001) {
  ndf->do_soil3n_loss = DON_production_rate * -1.0*ndf->pmnf_s3s4;
  cdf->do_soil3c_loss = ndf->do_soil3n_loss * cn_s3;
  }
 if (-1.0*ndf->soil4n_to_sminn > 0.000000001) {
  ndf->do_soil4n_loss = DON_production_rate * -1.0*ndf->soil4n_to_sminn;
  cdf->do_soil4c_loss = ndf->do_soil4n_loss * cn_s4;
  }
 cs_litr->litr1c -= cdf->do_litr1c_loss;
 cs_litr->litr3c -= cdf->do_litr3c_loss;
 cs_litr->litr2c -= cdf->do_litr2c_loss;
 cs_litr->litr4c -= cdf->do_litr4c_loss;
 cs_soil->soil1c -= cdf->do_soil1c_loss;
 cs_soil->soil2c -= cdf->do_soil2c_loss;
 cs_soil->soil3c -= cdf->do_soil3c_loss;
 cs_soil->soil4c -= cdf->do_soil4c_loss;
 ns_litr->litr1n -= ndf->do_litr1n_loss;
 ns_litr->litr2n -= ndf->do_litr2n_loss;
 ns_litr->litr3n -= ndf->do_litr3n_loss;
 ns_litr->litr4n -= ndf->do_litr4n_loss;
 ns_soil->soil1n -= ndf->do_soil1n_loss;
 ns_soil->soil2n -= ndf->do_soil2n_loss;
 ns_soil->soil3n -= ndf->do_soil3n_loss;
 ns_soil->soil4n -= ndf->do_soil4n_loss;
 cs_soil->DOC += (cdf->do_soil1c_loss + cdf->do_soil2c_loss + cdf->do_soil3c_loss + cdf->do_soil4c_loss);
 ns_soil->DON += ( ndf->do_soil1n_loss + ndf->do_soil3n_loss + ndf->do_soil2n_loss + ndf->do_soil4n_loss);
 return (!ok);
}

variable_types: struct date { long year; long month; long day; long hour; }

user_defined_types: struct soil_c_object { double frootc; double DOC; double DOC_Qin; double DOC_Qout; double DOC_Qin_total; double DOC_Qout_total; double totalc; double soil_cpool; double soil1c; double soil2c; double soil3c; double soil4c; double soil1c_hr_snk; double soil2c_hr_snk; double soil3c_hr_snk; double soil4c_hr_snk; }

user_defined_types: struct soil_n_object { double nlimit; double fract_potential_immob; double fract_potential_uptake; double totaln; double soil_npool; double DON; double DON_Qin; double DON_Qout; double DON_Qin_total; double DON_Qout_total; double soil1n; double soil2n; double soil3n; double soil4n; double sminn; double nitrate; double NO3_Qin_total; double NO3_Qout_total; double NO3_Qin; double NO3_Qout; double NH4_Qin; double NH4_Qout; double NH4_Qin_total; double NH4_Qout_total; double leach; double nfix_src; double ndep_src; double nleached_snk; double nvolatilized_snk; }

user_defined_types: struct litter_c_object { double totalc; double litr1c; double litr2c; double litr3c; double litr4c; double litr1c_hr_snk; double litr2c_hr_snk; double litr4c_hr_snk; double fire_snk; double t_scalar; double w_scalar; }

user_defined_types: struct litter_n_object { double totaln; double litr1n; double litr2n; double litr3n; double litr4n; double fire_snk; }

user_defined_types: struct cdayflux_patch_struct { double do_litr1c_loss; double do_litr2c_loss; double do_litr3c_loss; double do_litr4c_loss; double do_soil1c_loss; double do_soil2c_loss; double do_soil3c_loss; double do_soil4c_loss; double total_DOC_loss; double DOC_to_gw; double plitr1c_loss; double plitr2c_loss; double plitr3c_loss; double plitr4c_loss; double psoil1c_loss; double psoil2c_loss; double psoil3c_loss; double psoil4c_loss; double kl4; double decomp_w_scalar; double decomp_t_scalar; double leafc_to_litr1c; double leafc_to_litr2c; double leafc_to_litr3c; double leafc_to_litr4c; double frootc_to_litr1c; double frootc_to_litr2c; double frootc_to_litr3c; double frootc_to_litr4c; double litr1c_to_soil1c; double litr2c_to_soil2c; double litr3c_to_litr2c; double litr4c_to_soil3c; double soil1c_to_soil2c; double soil2c_to_soil3c; double soil3c_to_soil4c; double cwdc_to_litr2c; double cwdc_to_litr3c; double cwdc_to_litr4c; double litr1c_hr; double litr2c_hr; double litr3c_hr; double litr4c_hr; double soil1c_hr; double soil2c_hr; double soil3c_hr; double soil4c_hr; double m_leafc_to_litr1c; double m_leafc_to_litr2c; double m_leafc_to_litr3c; double m_leafc_to_litr4c; double m_frootc_to_litr1c; double m_frootc_to_litr2c; double m_frootc_to_litr3c; double m_frootc_to_litr4c; double m_leafc_store_to_litr1c; double m_frootc_store_to_litr1c; double m_livestemc_store_to_litr1c; double m_deadstemc_store_to_litr1c; double m_livecrootc_store_to_litr1c; double m_deadcrootc_store_to_litr1c; double m_leafc_transfer_to_litr1c; double m_frootc_transfer_to_litr1c; double m_livestemc_transfer_to_litr1c; double m_deadstemc_transfer_to_litr1c; double m_livecrootc_transfer_to_litr1c; double m_deadcrootc_transfer_to_litr1c; double m_gresp_store_to_litr1c; double m_gresp_transfer_to_litr1c; double m_litr1c_to_atmos; double m_litr2c_to_atmos; double m_litr3c_to_atmos; double m_litr4c_to_atmos; double m_soil1c_to_atmos; double m_soil2c_to_atmos; double m_soil3c_to_atmos; double m_soil4c_to_atmos; }

user_defined_types: struct ndayflux_patch_struct { double do_litr1n_loss; double do_litr2n_loss; double do_litr3n_loss; double do_litr4n_loss; double do_soil1n_loss; double do_soil2n_loss; double do_soil3n_loss; double do_soil4n_loss; double total_DON_loss; double DON_to_gw; double mineralized; double potential_immob; double net_mineralized; double pmnf_l1s1; double pmnf_l2s2; double pmnf_l3l2; double pmnf_l4s3; double pmnf_s1s2; double pmnf_s2s3; double pmnf_s3s4; double pmnf_s4; double leafn_to_litr1n; double leafn_to_litr2n; double leafn_to_litr3n; double leafn_to_litr4n; double frootn_to_litr1n; double frootn_to_litr2n; double frootn_to_litr3n; double frootn_to_litr4n; double litr1n_to_soil1n; double litr2n_to_soil2n; double litr4n_to_soil3n; double litr3n_to_litr2n; double soil1n_to_soil2n; double soil2n_to_soil3n; double soil3n_to_soil4n; double cwdn_to_litr2n; double cwdn_to_litr3n; double cwdn_to_litr4n; double plant_potential_ndemand; double plant_avail_uptake; double sminn_to_soil1n_l1; double sminn_to_soil2n_l2; double sminn_to_soil2n_l3; double sminn_to_soil3n_l4; double sminn_to_soil2n_s1; double sminn_to_soil3n_s2; double sminn_to_soil4n_s3; double sminn_to_npool; double soil4n_to_sminn; double sminn_to_nitrate; double m_leafn_to_litr1n; double m_leafn_to_litr2n; double m_leafn_to_litr3n; double m_leafn_to_litr4n; double m_frootn_to_litr1n; double m_frootn_to_litr2n; double m_frootn_to_litr3n; double m_frootn_to_litr4n; double m_livestemn_to_litr1n; double m_livecrootn_to_litr1n; double m_leafn_store_to_litr1n; double m_frootn_store_to_litr1n; double m_livestemn_store_to_litr1n; double m_deadstemn_store_to_litr1n; double m_livecrootn_store_to_litr1n; double m_deadcrootn_store_to_litr1n; double m_leafn_transfer_to_litr1n; double m_frootn_transfer_to_litr1n; double m_livestemn_transfer_to_litr1n; double m_deadstemn_transfer_to_litr1n; double m_livecrootn_transfer_to_litr1n; double m_deadcrootn_transfer_to_litr1n; double m_retransn_to_litr1n; double sminn_to_nvol; double denitrif; double ndep_to_sminn; double nfix_to_sminn; double N_to_gw; double m_litr1n_to_atmos; double m_litr2n_to_atmos; double m_litr3n_to_atmos; double m_litr4n_to_atmos; double m_soil1n_to_atmos; double m_soil2n_to_atmos; double m_soil3n_to_atmos; double m_soil4n_to_atmos; }


decompiled_code:
char *__fastcall get_iso_date(_QWORD *a1)
{
char *v1; // rbp
__int64 v2; // rax

v1 = (char *)malloc(0x11uLL);
v2 = a1[3];
if ( v2 > 24 )
v2 = 24LL;
snprintf(v1, 0x11uLL, "%ld-%02ld-%02ldT%02ld:%02d", *a1, a1[1], a1[2], v2, 0LL);
return v1;
}

original_code:
char *get_iso_date(struct date const * const d) {
 char *iso_date = malloc(17);
 long hour = d->hour;
 if (hour > 24) hour = 24;
 snprintf(iso_date, 17, "%ld-%02ld-%02ldT%02ld:%02d",
   d->year, d->month, d->day, hour, 0);
 return iso_date;
}

canonical_original_code:
char *get_iso_date(struct date *d) {
 char *iso_date = malloc(17);
 long hour = d->hour;
 if (hour > 24) hour = 24;
 snprintf(iso_date, 17, "%ld-%02ld-%02ldT%02ld:%02d",
   d->year, d->month, d->day, hour, 0);
 return iso_date;
}

variable_types: struct date { long year; long month; long day; long hour; } *

variable_types: hour long

return_type: char *


decompiled_code:
void __fastcall destroy_basin_defaults(int a1, int a2, void **a3)
{
void **v4; // rbx
__int64 v5; // r12

if ( a2 && a1 > 0 )
{
v4 = a3 + 2;
v5 = (__int64)&a3[3 * (unsigned int)(a1 - 1) + 5];
do
{
free(*v4);
v4 += 3;
}
while ( v4 != (void **)v5 );
}
free(a3);
}

original_code:
void destroy_basin_defaults(int num_default_files,
       int grow_flag,
       struct basin_default *default_object_list )
{
 int i;
 if ( grow_flag ){
  for ( i=0 ; i<num_default_files; i++ )
   free( default_object_list[i].grow_defaults );
 }
 free( default_object_list );
 return;
}

canonical_original_code:
void destroy_basin_defaults(int num_default_files, int grow_flag, struct basin_default *default_object_list)
{
 int i;
 if ( grow_flag ){
  for ( i=0 ; i<num_default_files; i++ )
   free( default_object_list[i].grow_defaults );
 }
 free( default_object_list );
 return;
}

variable_types: struct basin_default { int ID; int n_routing_timesteps; int wyday_start; struct basin_grow_default { int temp; } *grow_defaults; } *

variable_types: i int

user_defined_types: struct basin_default { int ID; int n_routing_timesteps; int wyday_start; struct basin_grow_default *grow_defaults; }


original_code:
int compute_potential_decomp(double tsoil, double maxpsi,
        double minpsi,
        double theta,
        double std,
        double fixed_t_mult,
        double fixed_w_mult,
        double nitrif_parm_smax,
        struct soil_c_object *cs_soil,
        struct soil_n_object *ns_soil,
        struct litter_c_object *cs_litr,
        struct litter_n_object *ns_litr,
        struct cdayflux_patch_struct *cdf,
        struct ndayflux_patch_struct *ndf)
{
 int ok;
 double rate_scalar, t_scalar, w_scalar;
 double a,b,c,d;
 double tk, thetai;
 double rfl1s1, rfl2s2,rfl4s3,rfs1s2,rfs2s3,rfs3s4;
 double kl1_base,kl2_base,kl4_base,ks1_base,ks2_base,ks3_base,ks4_base;
 double kl1,kl2,kl4,ks1,ks2,ks3,ks4;
 double cn_l1,cn_l2,cn_l4,cn_s1,cn_s2,cn_s3,cn_s4;
 double plitr1c_loss, plitr3c_loss, plitr2c_loss, plitr4c_loss;
 double psoil1c_loss, psoil2c_loss, psoil3c_loss, psoil4c_loss;
 double pmnf_l1s1,pmnf_l2s2,pmnf_l3l2, pmnf_l4s3,pmnf_s1s2,pmnf_s2s3,pmnf_s3s4,pmnf_s4;
 double potential_immob,mineralized;
 double weight1, weight2, theta1, theta2;
 int nlimit, i;
 double NORMAL[10]= {0,0,0.253,0.524,0.842,1.283,-0.253,-0.524,-0.842,-1.283};
 ok = 0;
 if (tsoil < -10.0){
  t_scalar = 0.0;
 }
 else{
  tk = tsoil + 273.15;
  t_scalar = exp(308.56*((1.0/71.02)-(1.0/(tk-227.13))));
 }
 if (fixed_t_mult > -999)
  t_scalar = fixed_t_mult;
 a = nitrif_parm_smax;
 b=2.5; c=0.0012; d=2.84;
 w_scalar = 0.0;
 if (std > 0.000000001) {
  for (i=0; i<10; i++) {
   thetai = theta + NORMAL[i]*std;
   thetai = ((1.0) < (thetai) ? (1.0) : (thetai));
   thetai = ((0.1) > (thetai) ? (0.1) : (thetai));
   w_scalar += (pow( ((thetai -b) / (a-b)), d*(b-a)/(a-c))
     * pow( ((thetai-c)/ (a-c)), d)) * 1.0/10;
   }
 }
 else {
  if ((theta <= 0.000000001) || (theta > 1.0))
   theta = 1.0;
  if (theta > c) {
   w_scalar = pow( ((theta -b) / (a-b)), d*(b-a)/(a-c))
   * pow( ((theta-c)/ (a-c)), d);
    }
  else
   w_scalar = 0.000001;
 }
 if (w_scalar > 0.000000001)
  w_scalar = sqrt(w_scalar);
 else
  w_scalar = 0.000000001;
 if (fixed_w_mult > -999)
  w_scalar = fixed_w_mult;
 rate_scalar = w_scalar * t_scalar;
 cs_litr->t_scalar = t_scalar;
 cs_litr->w_scalar = w_scalar;
 if ((cs_litr->litr1c > 0.000000001) && (ns_litr->litr1n > 0.000000001 )) cn_l1 = cs_litr->litr1c/ns_litr->litr1n;
  else cn_l1 = 50;
 if ((cs_litr->litr2c > 0.000000001) && (ns_litr->litr2n > 0.000000001)) cn_l2 = cs_litr->litr2c/ns_litr->litr2n;
  else cn_l2 = 250.0;
 if ((cs_litr->litr4c > 0.000000001) && (ns_litr->litr4n > 0.000000001)) cn_l4 = cs_litr->litr4c/ns_litr->litr4n;
  else cn_l4 = 500.0;
 cn_s1 = 12.0;
 cn_s2 = 12.0;
 cn_s3 = 10.0;
 cn_s4 = 8.0;
 rfl1s1 = 0.39;
 rfl2s2 = 0.55;
 rfl4s3 = 0.29;
 rfs1s2 = 0.28;
 rfs2s3 = 0.46;
 rfs3s4 = 0.55;
 kl1_base = 0.7;
 kl2_base = 0.07;
 kl4_base = 0.014;
 ks1_base = 0.07;
 ks2_base = 0.014;
 ks3_base = 0.0014;
 ks4_base = 0.0001;
 kl1 = kl1_base * rate_scalar;
 kl2 = kl2_base * rate_scalar;
 kl4 = kl4_base * rate_scalar;
 ks1 = ks1_base * rate_scalar;
 ks2 = ks2_base * rate_scalar;
 ks3 = ks3_base * rate_scalar;
 ks4 = ks4_base * rate_scalar;
 plitr1c_loss = plitr2c_loss = plitr3c_loss = plitr4c_loss = 0.0;
 psoil1c_loss = psoil2c_loss = psoil3c_loss = psoil4c_loss = 0.0;
 pmnf_l1s1 = pmnf_l2s2 = pmnf_l3l2 = pmnf_l4s3 = 0.0;
 pmnf_s1s2 = pmnf_s2s3 = pmnf_s3s4 = pmnf_s4 = 0.0;
 if ((cs_litr->litr1c > 0.000000001) && (ns_litr->litr1n > 0.000000001)) {
  plitr1c_loss = kl1 * cs_litr->litr1c;
  pmnf_l1s1 = (plitr1c_loss * (1.0 - rfl1s1 - (cn_s1/cn_l1)))/cn_s1;
 }
 if ((ns_litr->litr2n > 0.000000001) && (cs_litr->litr2c > 0.000000001)) {
  plitr2c_loss = kl2 * cs_litr->litr2c;
  pmnf_l2s2 = (plitr2c_loss * (1.0 - rfl2s2 - (cn_s2/cn_l2)))/cn_s2;
 }
 if ((ns_litr->litr3n > 0.000000001) && (cs_litr->litr3c > 0.000000001)) {
  plitr3c_loss = kl4 * cs_litr->litr3c;
  pmnf_l3l2 = (plitr3c_loss * (1.0 - rfl4s3 - (cn_l2/cn_l2)))/cn_l2;
 }
 if ((ns_litr->litr4n > 0.000000001) && (cs_litr->litr4c > 0.000000001)) {
  plitr4c_loss = kl4 * cs_litr->litr4c;
  pmnf_l4s3 = (plitr4c_loss * (1.0 - rfl4s3 - (cn_s3/cn_l4)))/cn_s3;
 }
 if ((ns_soil->soil1n > 0.000000001) && (cs_soil->soil1c > 0.000000001)) {
  psoil1c_loss = ks1 * cs_soil->soil1c;
  pmnf_s1s2 = (psoil1c_loss * (1.0 - rfs1s2 - (cn_s2/cn_s1)))/cn_s2;
 }
 if ((ns_soil->soil2n > 0.000000001) && (cs_soil->soil2c > 0.000000001)) {
  psoil2c_loss = ks2 * cs_soil->soil2c;
  pmnf_s2s3 = (psoil2c_loss * (1.0 - rfs2s3 - (cn_s3/cn_s2)))/cn_s3;
 }
 if ((ns_soil->soil3n > 0.000000001) && (cs_soil->soil3c > 0.000000001)) {
  psoil3c_loss = ks3 * cs_soil->soil3c;
  pmnf_s3s4 = (psoil3c_loss * (1.0 - rfs3s4 - (cn_s4/cn_s3)))/cn_s4;
 }
 if ((ns_soil->soil4n > 0.000000001) && (cs_soil->soil4c > 0.000000001)) {
  psoil4c_loss = ks4 * cs_soil->soil4c;
  pmnf_s4 = -psoil4c_loss/cn_s4;
 }
 nlimit = 0;
 potential_immob = 0.0;
 mineralized = 0.0;
 if (pmnf_l1s1 > 0.0) potential_immob += pmnf_l1s1;
 else mineralized += -pmnf_l1s1;
 if (pmnf_l2s2 > 0.0) potential_immob += pmnf_l2s2;
 else mineralized += -pmnf_l2s2;
 if (pmnf_l3l2 > 0.0) potential_immob += pmnf_l3l2;
 else mineralized += -pmnf_l3l2;
 if (pmnf_l4s3 > 0.0) potential_immob += pmnf_l4s3;
 else mineralized += -pmnf_l4s3;
 if (pmnf_s1s2 > 0.0) potential_immob += pmnf_s1s2;
 else mineralized += -pmnf_s1s2;
 if (pmnf_s2s3 > 0.0) potential_immob += pmnf_s2s3;
 else mineralized += -pmnf_s2s3;
 if (pmnf_s3s4 > 0.0) potential_immob += pmnf_s3s4;
 else mineralized += -pmnf_s3s4;
 mineralized += -pmnf_s4;
 ndf->mineralized = mineralized;
 ndf->potential_immob = potential_immob;
 cdf->plitr1c_loss = plitr1c_loss;
 ndf->pmnf_l1s1 = pmnf_l1s1;
 cdf->plitr2c_loss = plitr2c_loss;
 ndf->pmnf_l2s2 = pmnf_l2s2;
 cdf->plitr3c_loss = plitr3c_loss;
 ndf->pmnf_l3l2 = pmnf_l3l2;
 cdf->plitr4c_loss = plitr4c_loss;
 ndf->pmnf_l4s3 = pmnf_l4s3;
 cdf->psoil1c_loss = psoil1c_loss;
 ndf->pmnf_s1s2 = pmnf_s1s2;
 cdf->psoil2c_loss = psoil2c_loss;
 ndf->pmnf_s2s3 = pmnf_s2s3;
 cdf->psoil3c_loss = psoil3c_loss;
 ndf->pmnf_s3s4 = pmnf_s3s4;
 cdf->psoil4c_loss = psoil4c_loss;
 ndf->pmnf_s4 = pmnf_s4;
 cdf->kl4 = kl4;
 cdf->decomp_w_scalar = w_scalar;
 cdf->decomp_t_scalar = t_scalar;
 return(ok);
}

canonical_original_code:
int compute_potential_decomp(double tsoil, double maxpsi, double minpsi, double theta, double std, double fixed_t_mult, double fixed_w_mult, double nitrif_parm_smax, struct soil_c_object *cs_soil, struct soil_n_object *ns_soil, struct litter_c_object *cs_litr, struct litter_n_object *ns_litr, struct cdayflux_patch_struct *cdf, struct ndayflux_patch_struct *ndf)
{
 int ok;
 double rate_scalar; double t_scalar; double w_scalar;
 double a; double b; double c; double d;
 double tk; double thetai;
 double rfl1s1; double rfl2s2; double rfl4s3; double rfs1s2; double rfs2s3; double rfs3s4;
 double kl1_base; double kl2_base; double kl4_base; double ks1_base; double ks2_base; double ks3_base; double ks4_base;
 double kl1; double kl2; double kl4; double ks1; double ks2; double ks3; double ks4;
 double cn_l1; double cn_l2; double cn_l4; double cn_s1; double cn_s2; double cn_s3; double cn_s4;
 double plitr1c_loss; double plitr3c_loss; double plitr2c_loss; double plitr4c_loss;
 double psoil1c_loss; double psoil2c_loss; double psoil3c_loss; double psoil4c_loss;
 double pmnf_l1s1; double pmnf_l2s2; double pmnf_l3l2; double pmnf_l4s3; double pmnf_s1s2; double pmnf_s2s3; double pmnf_s3s4; double pmnf_s4;
 double potential_immob; double mineralized;
 double weight1; double weight2; double theta1; double theta2;
 int nlimit; int i;
 double NORMAL[10] = {0,0,0.253,0.524,0.842,1.283,-0.253,-0.524,-0.842,-1.283};
 ok = 0;
 if (tsoil < -10.0){
  t_scalar = 0.0;
 }
 else{
  tk = tsoil + 273.15;
  t_scalar = exp(308.56*((1.0/71.02)-(1.0/(tk-227.13))));
 }
 if (fixed_t_mult > -999)
  t_scalar = fixed_t_mult;
 a = nitrif_parm_smax;
 b=2.5; c=0.0012; d=2.84;
 w_scalar = 0.0;
 if (std > 0.000000001) {
  for (i=0; i<10; i++) {
   thetai = theta + NORMAL[i]*std;
   thetai = ((1.0) < (thetai) ? (1.0) : (thetai));
   thetai = ((0.1) > (thetai) ? (0.1) : (thetai));
   w_scalar += (pow( ((thetai -b) / (a-b)), d*(b-a)/(a-c))
     * pow( ((thetai-c)/ (a-c)), d)) * 1.0/10;
   }
 }
 else {
  if ((theta <= 0.000000001) || (theta > 1.0))
   theta = 1.0;
  if (theta > c) {
   w_scalar = pow( ((theta -b) / (a-b)), d*(b-a)/(a-c))
   * pow( ((theta-c)/ (a-c)), d);
    }
  else
   w_scalar = 0.000001;
 }
 if (w_scalar > 0.000000001)
  w_scalar = sqrt(w_scalar);
 else
  w_scalar = 0.000000001;
 if (fixed_w_mult > -999)
  w_scalar = fixed_w_mult;
 rate_scalar = w_scalar * t_scalar;
 cs_litr->t_scalar = t_scalar;
 cs_litr->w_scalar = w_scalar;
 if ((cs_litr->litr1c > 0.000000001) && (ns_litr->litr1n > 0.000000001 )) cn_l1 = cs_litr->litr1c/ns_litr->litr1n;
  else cn_l1 = 50;
 if ((cs_litr->litr2c > 0.000000001) && (ns_litr->litr2n > 0.000000001)) cn_l2 = cs_litr->litr2c/ns_litr->litr2n;
  else cn_l2 = 250.0;
 if ((cs_litr->litr4c > 0.000000001) && (ns_litr->litr4n > 0.000000001)) cn_l4 = cs_litr->litr4c/ns_litr->litr4n;
  else cn_l4 = 500.0;
 cn_s1 = 12.0;
 cn_s2 = 12.0;
 cn_s3 = 10.0;
 cn_s4 = 8.0;
 rfl1s1 = 0.39;
 rfl2s2 = 0.55;
 rfl4s3 = 0.29;
 rfs1s2 = 0.28;
 rfs2s3 = 0.46;
 rfs3s4 = 0.55;
 kl1_base = 0.7;
 kl2_base = 0.07;
 kl4_base = 0.014;
 ks1_base = 0.07;
 ks2_base = 0.014;
 ks3_base = 0.0014;
 ks4_base = 0.0001;
 kl1 = kl1_base * rate_scalar;
 kl2 = kl2_base * rate_scalar;
 kl4 = kl4_base * rate_scalar;
 ks1 = ks1_base * rate_scalar;
 ks2 = ks2_base * rate_scalar;
 ks3 = ks3_base * rate_scalar;
 ks4 = ks4_base * rate_scalar;
 plitr1c_loss = plitr2c_loss = plitr3c_loss = plitr4c_loss = 0.0;
 psoil1c_loss = psoil2c_loss = psoil3c_loss = psoil4c_loss = 0.0;
 pmnf_l1s1 = pmnf_l2s2 = pmnf_l3l2 = pmnf_l4s3 = 0.0;
 pmnf_s1s2 = pmnf_s2s3 = pmnf_s3s4 = pmnf_s4 = 0.0;
 if ((cs_litr->litr1c > 0.000000001) && (ns_litr->litr1n > 0.000000001)) {
  plitr1c_loss = kl1 * cs_litr->litr1c;
  pmnf_l1s1 = (plitr1c_loss * (1.0 - rfl1s1 - (cn_s1/cn_l1)))/cn_s1;
 }
 if ((ns_litr->litr2n > 0.000000001) && (cs_litr->litr2c > 0.000000001)) {
  plitr2c_loss = kl2 * cs_litr->litr2c;
  pmnf_l2s2 = (plitr2c_loss * (1.0 - rfl2s2 - (cn_s2/cn_l2)))/cn_s2;
 }
 if ((ns_litr->litr3n > 0.000000001) && (cs_litr->litr3c > 0.000000001)) {
  plitr3c_loss = kl4 * cs_litr->litr3c;
  pmnf_l3l2 = (plitr3c_loss * (1.0 - rfl4s3 - (cn_l2/cn_l2)))/cn_l2;
 }
 if ((ns_litr->litr4n > 0.000000001) && (cs_litr->litr4c > 0.000000001)) {
  plitr4c_loss = kl4 * cs_litr->litr4c;
  pmnf_l4s3 = (plitr4c_loss * (1.0 - rfl4s3 - (cn_s3/cn_l4)))/cn_s3;
 }
 if ((ns_soil->soil1n > 0.000000001) && (cs_soil->soil1c > 0.000000001)) {
  psoil1c_loss = ks1 * cs_soil->soil1c;
  pmnf_s1s2 = (psoil1c_loss * (1.0 - rfs1s2 - (cn_s2/cn_s1)))/cn_s2;
 }
 if ((ns_soil->soil2n > 0.000000001) && (cs_soil->soil2c > 0.000000001)) {
  psoil2c_loss = ks2 * cs_soil->soil2c;
  pmnf_s2s3 = (psoil2c_loss * (1.0 - rfs2s3 - (cn_s3/cn_s2)))/cn_s3;
 }
 if ((ns_soil->soil3n > 0.000000001) && (cs_soil->soil3c > 0.000000001)) {
  psoil3c_loss = ks3 * cs_soil->soil3c;
  pmnf_s3s4 = (psoil3c_loss * (1.0 - rfs3s4 - (cn_s4/cn_s3)))/cn_s4;
 }
 if ((ns_soil->soil4n > 0.000000001) && (cs_soil->soil4c > 0.000000001)) {
  psoil4c_loss = ks4 * cs_soil->soil4c;
  pmnf_s4 = -psoil4c_loss/cn_s4;
 }
 nlimit = 0;
 potential_immob = 0.0;
 mineralized = 0.0;
 if (pmnf_l1s1 > 0.0) potential_immob += pmnf_l1s1;
 else mineralized += -pmnf_l1s1;
 if (pmnf_l2s2 > 0.0) potential_immob += pmnf_l2s2;
 else mineralized += -pmnf_l2s2;
 if (pmnf_l3l2 > 0.0) potential_immob += pmnf_l3l2;
 else mineralized += -pmnf_l3l2;
 if (pmnf_l4s3 > 0.0) potential_immob += pmnf_l4s3;
 else mineralized += -pmnf_l4s3;
 if (pmnf_s1s2 > 0.0) potential_immob += pmnf_s1s2;
 else mineralized += -pmnf_s1s2;
 if (pmnf_s2s3 > 0.0) potential_immob += pmnf_s2s3;
 else mineralized += -pmnf_s2s3;
 if (pmnf_s3s4 > 0.0) potential_immob += pmnf_s3s4;
 else mineralized += -pmnf_s3s4;
 mineralized += -pmnf_s4;
 ndf->mineralized = mineralized;
 ndf->potential_immob = potential_immob;
 cdf->plitr1c_loss = plitr1c_loss;
 ndf->pmnf_l1s1 = pmnf_l1s1;
 cdf->plitr2c_loss = plitr2c_loss;
 ndf->pmnf_l2s2 = pmnf_l2s2;
 cdf->plitr3c_loss = plitr3c_loss;
 ndf->pmnf_l3l2 = pmnf_l3l2;
 cdf->plitr4c_loss = plitr4c_loss;
 ndf->pmnf_l4s3 = pmnf_l4s3;
 cdf->psoil1c_loss = psoil1c_loss;
 ndf->pmnf_s1s2 = pmnf_s1s2;
 cdf->psoil2c_loss = psoil2c_loss;
 ndf->pmnf_s2s3 = pmnf_s2s3;
 cdf->psoil3c_loss = psoil3c_loss;
 ndf->pmnf_s3s4 = pmnf_s3s4;
 cdf->psoil4c_loss = psoil4c_loss;
 ndf->pmnf_s4 = pmnf_s4;
 cdf->kl4 = kl4;
 cdf->decomp_w_scalar = w_scalar;
 cdf->decomp_t_scalar = t_scalar;
 return(ok);
}

variable_types: tsoil double

variable_types: maxpsi double

variable_types: minpsi double

variable_types: theta double

variable_types: std double

variable_types: struct soil_c_object { double frootc; double DOC; double DOC_Qin; double DOC_Qout; double DOC_Qin_total; double DOC_Qout_total; double totalc; double soil_cpool; double soil1c; double soil2c; double soil3c; double soil4c; double soil1c_hr_snk; double soil2c_hr_snk; double soil3c_hr_snk; double soil4c_hr_snk; } *

variable_types: struct soil_n_object { double nlimit; double fract_potential_immob; double fract_potential_uptake; double totaln; double soil_npool; double DON; double DON_Qin; double DON_Qout; double DON_Qin_total; double DON_Qout_total; double soil1n; double soil2n; double soil3n; double soil4n; double sminn; double nitrate; double NO3_Qin_total; double NO3_Qout_total; double NO3_Qin; double NO3_Qout; double NH4_Qin; double NH4_Qout; double NH4_Qin_total; double NH4_Qout_total; double leach; double nfix_src; double ndep_src; double nleached_snk; double nvolatilized_snk; } *

variable_types: struct cdayflux_patch_struct { double do_litr1c_loss; double do_litr2c_loss; double do_litr3c_loss; double do_litr4c_loss; double do_soil1c_loss; double do_soil2c_loss; double do_soil3c_loss; double do_soil4c_loss; double total_DOC_loss; double DOC_to_gw; double plitr1c_loss; double plitr2c_loss; double plitr3c_loss; double plitr4c_loss; double psoil1c_loss; double psoil2c_loss; double psoil3c_loss; double psoil4c_loss; double kl4; double decomp_w_scalar; double decomp_t_scalar; double leafc_to_litr1c; double leafc_to_litr2c; double leafc_to_litr3c; double leafc_to_litr4c; double frootc_to_litr1c; double frootc_to_litr2c; double frootc_to_litr3c; double frootc_to_litr4c; double litr1c_to_soil1c; double litr2c_to_soil2c; double litr3c_to_litr2c; double litr4c_to_soil3c; double soil1c_to_soil2c; double soil2c_to_soil3c; double soil3c_to_soil4c; double cwdc_to_litr2c; double cwdc_to_litr3c; double cwdc_to_litr4c; double litr1c_hr; double litr2c_hr; double litr3c_hr; double litr4c_hr; double soil1c_hr; double soil2c_hr; double soil3c_hr; double soil4c_hr; double m_leafc_to_litr1c; double m_leafc_to_litr2c; double m_leafc_to_litr3c; double m_leafc_to_litr4c; double m_frootc_to_litr1c; double m_frootc_to_litr2c; double m_frootc_to_litr3c; double m_frootc_to_litr4c; double m_leafc_store_to_litr1c; double m_frootc_store_to_litr1c; double m_livestemc_store_to_litr1c; double m_deadstemc_store_to_litr1c; double m_livecrootc_store_to_litr1c; double m_deadcrootc_store_to_litr1c; double m_leafc_transfer_to_litr1c; double m_frootc_transfer_to_litr1c; double m_livestemc_transfer_to_litr1c; double m_deadstemc_transfer_to_litr1c; double m_livecrootc_transfer_to_litr1c; double m_deadcrootc_transfer_to_litr1c; double m_gresp_store_to_litr1c; double m_gresp_transfer_to_litr1c; double m_litr1c_to_atmos; double m_litr2c_to_atmos; double m_litr3c_to_atmos; double m_litr4c_to_atmos; double m_soil1c_to_atmos; double m_soil2c_to_atmos; double m_soil3c_to_atmos; double m_soil4c_to_atmos; } *

variable_types: struct ndayflux_patch_struct { double do_litr1n_loss; double do_litr2n_loss; double do_litr3n_loss; double do_litr4n_loss; double do_soil1n_loss; double do_soil2n_loss; double do_soil3n_loss; double do_soil4n_loss; double total_DON_loss; double DON_to_gw; double mineralized; double potential_immob; double net_mineralized; double pmnf_l1s1; double pmnf_l2s2; double pmnf_l3l2; double pmnf_l4s3; double pmnf_s1s2; double pmnf_s2s3; double pmnf_s3s4; double pmnf_s4; double leafn_to_litr1n; double leafn_to_litr2n; double leafn_to_litr3n; double leafn_to_litr4n; double frootn_to_litr1n; double frootn_to_litr2n; double frootn_to_litr3n; double frootn_to_litr4n; double litr1n_to_soil1n; double litr2n_to_soil2n; double litr4n_to_soil3n; double litr3n_to_litr2n; double soil1n_to_soil2n; double soil2n_to_soil3n; double soil3n_to_soil4n; double cwdn_to_litr2n; double cwdn_to_litr3n; double cwdn_to_litr4n; double plant_potential_ndemand; double plant_avail_uptake; double sminn_to_soil1n_l1; double sminn_to_soil2n_l2; double sminn_to_soil2n_l3; double sminn_to_soil3n_l4; double sminn_to_soil2n_s1; double sminn_to_soil3n_s2; double sminn_to_soil4n_s3; double sminn_to_npool; double soil4n_to_sminn; double sminn_to_nitrate; double m_leafn_to_litr1n; double m_leafn_to_litr2n; double m_leafn_to_litr3n; double m_leafn_to_litr4n; double m_frootn_to_litr1n; double m_frootn_to_litr2n; double m_frootn_to_litr3n; double m_frootn_to_litr4n; double m_livestemn_to_litr1n; double m_livecrootn_to_litr1n; double m_leafn_store_to_litr1n; double m_frootn_store_to_litr1n; double m_livestemn_store_to_litr1n; double m_deadstemn_store_to_litr1n; double m_livecrootn_store_to_litr1n; double m_deadcrootn_store_to_litr1n; double m_leafn_transfer_to_litr1n; double m_frootn_transfer_to_litr1n; double m_livestemn_transfer_to_litr1n; double m_deadstemn_transfer_to_litr1n; double m_livecrootn_transfer_to_litr1n; double m_deadcrootn_transfer_to_litr1n; double m_retransn_to_litr1n; double sminn_to_nvol; double denitrif; double ndep_to_sminn; double nfix_to_sminn; double N_to_gw; double m_litr1n_to_atmos; double m_litr2n_to_atmos; double m_litr3n_to_atmos; double m_litr4n_to_atmos; double m_soil1n_to_atmos; double m_soil2n_to_atmos; double m_soil3n_to_atmos; double m_soil4n_to_atmos; } *

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: d double

variable_types: tk double

variable_types: thetai double

variable_types: mineralized double

variable_types: nlimit int

variable_types:
NORMAL
double [10]


decompiled_code:
__int64 __fastcall find_stream(__int64 a1, int a2, _DWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbp
int v7; // er12

v4 = a1 + 160LL * a2;
result = *(unsigned int *)(v4 + 20);
if ( (_DWORD)result == 1 )
{
*a3 = a2;
}
else if ( *(int *)(v4 + 96) <= 0 )
{
result = 0LL;
}
else
{
v6 = *(_QWORD *)(v4 + 128);
v7 = 1;
while ( 1 )
{
result = 0LL;
if ( *(_DWORD *)(v6 + 16) != 1 )
result = find_stream(a1, *(unsigned int *)(v6 + 12), a3);
if ( *(_DWORD *)(v4 + 96) < ++v7 || (_DWORD)result )
break;
v6 = *(_QWORD *)(v6 + 48);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, _DWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbp
int v7; // er12

v4 = a1 + 160LL * a2;
result = *(unsigned int *)(v4 + 20);
if ( (_DWORD)result == 1 )
{
*a3 = a2;
}
else if ( *(int *)(v4 + 96) <= 0 )
{
result = 0LL;
}
else
{
v6 = *(_QWORD *)(v4 + 128);
v7 = 1;
while ( 1 )
{
result = 0LL;
if ( *(_DWORD *)(v6 + 16) != 1 )
result = func0(a1, *(unsigned int *)(v6 + 12), a3);
if ( *(_DWORD *)(v4 + 96) < ++v7 || (_DWORD)result )
break;
v6 = *(_QWORD *)(v6 + 48);
}
}
return result;
}

original_code:
int find_stream(struct flow_struct *flow_table, int curr, int *str_inx) {
 struct adj_struct *aptr;
 int i, inx, fnd;
 fnd = 0;
 aptr = flow_table[curr].adj_list;
 if (flow_table[curr].land != 1) {
  i = 1;
  while ((i <= flow_table[curr].num_adjacent) && (fnd == 0)) {
   inx = aptr->inx;
   if (aptr->landtype != 1)
    fnd = (int) find_stream(flow_table, inx, str_inx);
   aptr = aptr->next;
   i += 1;
  }
 }
 else {
  fnd = 1;
  *str_inx = curr;
 }
 return (fnd);
}

canonical_original_code:
int find_stream(struct flow_struct *flow_table, int curr, int *str_inx) {
 struct adj_struct *aptr;
 int i; int inx; int fnd;
 fnd = 0;
 aptr = flow_table[curr].adj_list;
 if (flow_table[curr].land != 1) {
  i = 1;
  while ((i <= flow_table[curr].num_adjacent) && (fnd == 0)) {
   inx = aptr->inx;
   if (aptr->landtype != 1)
    fnd = (int) find_stream(flow_table, inx, str_inx);
   aptr = aptr->next;
   i += 1;
  }
 }
 else {
  fnd = 1;
  *str_inx = curr;
 }
 return (fnd);
}

variable_types: struct flow_struct { int patchID; int hillID; int zoneID; int ID_order; int area; int land; int sewer; float x; float y; float z; float flna; float acc_area; float total_str_gamma; float total_gamma; float gamma_neigh; float total_perimeter; float road_dist; float slope; float internal_slope; float max_slope; double path_length; int num_str; int inflow_cnt; int num_adjacent; int num_dsa; int stream_inx; float stream_gamma; struct ID_struct { int patch; int hill; int zone; } stream_ID; struct adj_struct { int patchID; int hillID; int zoneID; int inx; int landtype; int sewertype; double perimeter; float slope; float gamma; float z; struct adj_struct *next; } *adj_list; struct adj_struct *adj_ptr; struct adj_struct *adj_str_ptr; struct adj_struct *adj_str_list; } *

variable_types: curr int

variable_types: i int

variable_types: inx int

variable_types: fnd int

user_defined_types: struct flow_struct { int patchID; int hillID; int zoneID; int ID_order; int area; int land; int sewer; float x; float y; float z; float flna; float acc_area; float total_str_gamma; float total_gamma; float gamma_neigh; float total_perimeter; float road_dist; float slope; float internal_slope; float max_slope; double path_length; int num_str; int inflow_cnt; int num_adjacent; int num_dsa; int stream_inx; float stream_gamma; struct ID_struct stream_ID; struct adj_struct *adj_list; struct adj_struct *adj_ptr; struct adj_struct *adj_str_ptr; struct adj_struct *adj_str_list; }


decompiled_code:
double __fastcall compute_radiative_fluxes(int a1, double *a2, double *a3, double a4, double a5, double a6)
{
double v7; // xmm0_8
double v8; // xmm3_8
double v10; // xmm0_8
double v11; // xmm3_8
double v12; // [rsp+8h] [rbp-40h]

if ( a1 > 2 )
{
printf("%8.1f %8.1f %8.1f %8.1f ", *a2, a4, a5, a6);
*a3 = a5 * *a2;
v10 = exp(COERCE_DOUBLE(*(_QWORD *)&a4 ^ LC1));
v12 = a6 * *a2 * (1.0 - v10);
v11 = *a2 - *a3 - v12;
*a2 = v11;
printf("%8.1f %8.1f %8.1f %8.1f ", v10, *a3, v12, v11);
}
else
{
*a3 = a5 * *a2;
v7 = exp(COERCE_DOUBLE(*(_QWORD *)&a4 ^ LC1));
v12 = a6 * *a2 * (1.0 - v7);
v8 = *a2 - *a3 - v12;
*a2 = v8;
if ( a1 == -5 )
printf("\nRADFLUX: trans=%lf fluxrefl=%1f fluxabs=%lf fluxtrans=%lf ", v7, *a3, v12, v8);
}
return v12;
}

original_code:
double compute_radiative_fluxes(int verbose_flag,
         double *flux_down_ptr,
         double *flux_up_ptr,
         double total_extinction,
         double reflectance,
         double absorptance)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double opaque_transmittance;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f %8.1f ", *flux_down_ptr, total_extinction,
  reflectance, absorptance);
 *flux_up_ptr = *flux_down_ptr * reflectance ;
 opaque_transmittance = exp(-1.0 * total_extinction);
 flux_absorbed = *flux_down_ptr * absorptance * (1.0 - opaque_transmittance );
 flux_transmitted = *flux_down_ptr - *flux_up_ptr - flux_absorbed ;
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f %8.1f ", opaque_transmittance, *flux_up_ptr,
  flux_absorbed,flux_transmitted);
 if ( verbose_flag == -5 ){
  printf("\nRADFLUX: trans=%lf fluxrefl=%1f fluxabs=%lf fluxtrans=%lf ", opaque_transmittance, *flux_up_ptr,
     flux_absorbed,flux_transmitted);
 }
 return( flux_absorbed );
}

variable_types: reflectance double

variable_types: absorptance double


original_code:
int update_denitrif(
     struct soil_c_object *cs_soil,
     struct soil_n_object *ns_soil,
     struct cdayflux_patch_struct *cdf,
     struct ndayflux_patch_struct *ndf,
     struct soil_class soil_type,
     double theta,
     double std)
{
 int ok,i;
 double denitrify;
 double a, b, c, d;
 double water_scalar, thetai, water_scalari;
 double fnitrate, fCO2;
 double hr, nitrate_ratio;
 double NORMAL[10]= {0,0,0.253,0.524,0.842,1.283,-0.253,-0.524,-0.842,-1.283};
 ok = 1;
 if ((theta <= 0.000000001) || (theta > 1.0)) theta = 1.0;
 if ((ns_soil->nitrate > 0.000000001)) {
  if (soil_type.sand > 0.5) {
   a = 1.56; b=12.0; c=16.0; d=2.01;
  }
  else if (soil_type.clay > 0.5) {
   a = 60.0; b=18.0; c=22.0; d=1.06;
  }
  else {
   a=4.82; b=14.0; c=16.0; d=1.39;
  }
  water_scalar = 0.0;
  if (std > 0) {
   for (i =1; i< 10; i++) {
    thetai = theta + std*NORMAL[i];
    thetai = ((1.0) < (thetai) ? (1.0) : (thetai));
    thetai = ((0.0) > (thetai) ? (0.0) : (thetai));
    if (thetai > 0.000000001)
    water_scalari = ((1.0) < (a / pow(b, (c / pow(b, (d*thetai) )) )) ? (1.0) : (a / pow(b, (c / pow(b, (d*thetai) )) )));
    water_scalar += 1.0/10 * water_scalari;
    }
   }
  else
    water_scalar = ((1.0) < (a / pow(b, (c / pow(b, (d*theta) )) )) ? (1.0) : (a / pow(b, (c / pow(b, (d*theta) )) )));
  nitrate_ratio = (ns_soil->nitrate)
   / (cs_soil->totalc + ns_soil->totaln) * 1e6;
  fnitrate = atan(3.14159265359*0.002*(nitrate_ratio - 180)) * 0.004 / 3.14159265359 + 0.0011;
  hr = (cdf->soil1c_hr + cdf->soil2c_hr + cdf->soil3c_hr + cdf->soil4c_hr);
  if (hr > 0.000000001)
   fCO2 = 0.0024 / (1+ 200.0/exp(0.35*hr*10000.0)) - 0.00001;
  else
   fCO2 = 0.0;
  denitrify = ((fCO2) < (fnitrate) ? (fCO2) : (fnitrate)) * water_scalar;
 }
 else
  denitrify = 0.0;
 denitrify = ((denitrify) < (ns_soil->nitrate) ? (denitrify) : (ns_soil->nitrate));
 denitrify = ((0.0) > (denitrify) ? (0.0) : (denitrify));
 ns_soil->nvolatilized_snk += denitrify;
 ndf->sminn_to_nvol = denitrify;
 ns_soil->nitrate -= denitrify;
 ndf->denitrif = denitrify;
 ok = 0;
 return(ok);
}

canonical_original_code:
int update_denitrif(struct soil_c_object *cs_soil, struct soil_n_object *ns_soil, struct cdayflux_patch_struct *cdf, struct ndayflux_patch_struct *ndf, struct soil_class soil_type, double theta, double std)
{
 int ok; int i;
 double denitrify;
 double a; double b; double c; double d;
 double water_scalar; double thetai; double water_scalari;
 double fnitrate; double fCO2;
 double hr; double nitrate_ratio;
 double NORMAL[10] = {0,0,0.253,0.524,0.842,1.283,-0.253,-0.524,-0.842,-1.283};
 ok = 1;
 if ((theta <= 0.000000001) || (theta > 1.0)) theta = 1.0;
 if ((ns_soil->nitrate > 0.000000001)) {
  if (soil_type.sand > 0.5) {
   a = 1.56; b=12.0; c=16.0; d=2.01;
  }
  else if (soil_type.clay > 0.5) {
   a = 60.0; b=18.0; c=22.0; d=1.06;
  }
  else {
   a=4.82; b=14.0; c=16.0; d=1.39;
  }
  water_scalar = 0.0;
  if (std > 0) {
   for (i =1; i< 10; i++) {
    thetai = theta + std*NORMAL[i];
    thetai = ((1.0) < (thetai) ? (1.0) : (thetai));
    thetai = ((0.0) > (thetai) ? (0.0) : (thetai));
    if (thetai > 0.000000001)
    water_scalari = ((1.0) < (a / pow(b, (c / pow(b, (d*thetai) )) )) ? (1.0) : (a / pow(b, (c / pow(b, (d*thetai) )) )));
    water_scalar += 1.0/10 * water_scalari;
    }
   }
  else
    water_scalar = ((1.0) < (a / pow(b, (c / pow(b, (d*theta) )) )) ? (1.0) : (a / pow(b, (c / pow(b, (d*theta) )) )));
  nitrate_ratio = (ns_soil->nitrate)
   / (cs_soil->totalc + ns_soil->totaln) * 1e6;
  fnitrate = atan(3.14159265359*0.002*(nitrate_ratio - 180)) * 0.004 / 3.14159265359 + 0.0011;
  hr = (cdf->soil1c_hr + cdf->soil2c_hr + cdf->soil3c_hr + cdf->soil4c_hr);
  if (hr > 0.000000001)
   fCO2 = 0.0024 / (1+ 200.0/exp(0.35*hr*10000.0)) - 0.00001;
  else
   fCO2 = 0.0;
  denitrify = ((fCO2) < (fnitrate) ? (fCO2) : (fnitrate)) * water_scalar;
 }
 else
  denitrify = 0.0;
 denitrify = ((denitrify) < (ns_soil->nitrate) ? (denitrify) : (ns_soil->nitrate));
 denitrify = ((0.0) > (denitrify) ? (0.0) : (denitrify));
 ns_soil->nvolatilized_snk += denitrify;
 ndf->sminn_to_nvol = denitrify;
 ns_soil->nitrate -= denitrify;
 ndf->denitrif = denitrify;
 ok = 0;
 return(ok);
}

variable_types: struct soil_c_object { double frootc; double DOC; double DOC_Qin; double DOC_Qout; double DOC_Qin_total; double DOC_Qout_total; double totalc; double soil_cpool; double soil1c; double soil2c; double soil3c; double soil4c; double soil1c_hr_snk; double soil2c_hr_snk; double soil3c_hr_snk; double soil4c_hr_snk; } *

variable_types: struct soil_n_object { double nlimit; double fract_potential_immob; double fract_potential_uptake; double totaln; double soil_npool; double DON; double DON_Qin; double DON_Qout; double DON_Qin_total; double DON_Qout_total; double soil1n; double soil2n; double soil3n; double soil4n; double sminn; double nitrate; double NO3_Qin_total; double NO3_Qout_total; double NO3_Qin; double NO3_Qout; double NH4_Qin; double NH4_Qout; double NH4_Qin_total; double NH4_Qout_total; double leach; double nfix_src; double ndep_src; double nleached_snk; double nvolatilized_snk; } *

variable_types: struct cdayflux_patch_struct { double do_litr1c_loss; double do_litr2c_loss; double do_litr3c_loss; double do_litr4c_loss; double do_soil1c_loss; double do_soil2c_loss; double do_soil3c_loss; double do_soil4c_loss; double total_DOC_loss; double DOC_to_gw; double plitr1c_loss; double plitr2c_loss; double plitr3c_loss; double plitr4c_loss; double psoil1c_loss; double psoil2c_loss; double psoil3c_loss; double psoil4c_loss; double kl4; double decomp_w_scalar; double decomp_t_scalar; double leafc_to_litr1c; double leafc_to_litr2c; double leafc_to_litr3c; double leafc_to_litr4c; double frootc_to_litr1c; double frootc_to_litr2c; double frootc_to_litr3c; double frootc_to_litr4c; double litr1c_to_soil1c; double litr2c_to_soil2c; double litr3c_to_litr2c; double litr4c_to_soil3c; double soil1c_to_soil2c; double soil2c_to_soil3c; double soil3c_to_soil4c; double cwdc_to_litr2c; double cwdc_to_litr3c; double cwdc_to_litr4c; double litr1c_hr; double litr2c_hr; double litr3c_hr; double litr4c_hr; double soil1c_hr; double soil2c_hr; double soil3c_hr; double soil4c_hr; double m_leafc_to_litr1c; double m_leafc_to_litr2c; double m_leafc_to_litr3c; double m_leafc_to_litr4c; double m_frootc_to_litr1c; double m_frootc_to_litr2c; double m_frootc_to_litr3c; double m_frootc_to_litr4c; double m_leafc_store_to_litr1c; double m_frootc_store_to_litr1c; double m_livestemc_store_to_litr1c; double m_deadstemc_store_to_litr1c; double m_livecrootc_store_to_litr1c; double m_deadcrootc_store_to_litr1c; double m_leafc_transfer_to_litr1c; double m_frootc_transfer_to_litr1c; double m_livestemc_transfer_to_litr1c; double m_deadstemc_transfer_to_litr1c; double m_livecrootc_transfer_to_litr1c; double m_deadcrootc_transfer_to_litr1c; double m_gresp_store_to_litr1c; double m_gresp_transfer_to_litr1c; double m_litr1c_to_atmos; double m_litr2c_to_atmos; double m_litr3c_to_atmos; double m_litr4c_to_atmos; double m_soil1c_to_atmos; double m_soil2c_to_atmos; double m_soil3c_to_atmos; double m_soil4c_to_atmos; } *

variable_types: struct ndayflux_patch_struct { double do_litr1n_loss; double do_litr2n_loss; double do_litr3n_loss; double do_litr4n_loss; double do_soil1n_loss; double do_soil2n_loss; double do_soil3n_loss; double do_soil4n_loss; double total_DON_loss; double DON_to_gw; double mineralized; double potential_immob; double net_mineralized; double pmnf_l1s1; double pmnf_l2s2; double pmnf_l3l2; double pmnf_l4s3; double pmnf_s1s2; double pmnf_s2s3; double pmnf_s3s4; double pmnf_s4; double leafn_to_litr1n; double leafn_to_litr2n; double leafn_to_litr3n; double leafn_to_litr4n; double frootn_to_litr1n; double frootn_to_litr2n; double frootn_to_litr3n; double frootn_to_litr4n; double litr1n_to_soil1n; double litr2n_to_soil2n; double litr4n_to_soil3n; double litr3n_to_litr2n; double soil1n_to_soil2n; double soil2n_to_soil3n; double soil3n_to_soil4n; double cwdn_to_litr2n; double cwdn_to_litr3n; double cwdn_to_litr4n; double plant_potential_ndemand; double plant_avail_uptake; double sminn_to_soil1n_l1; double sminn_to_soil2n_l2; double sminn_to_soil2n_l3; double sminn_to_soil3n_l4; double sminn_to_soil2n_s1; double sminn_to_soil3n_s2; double sminn_to_soil4n_s3; double sminn_to_npool; double soil4n_to_sminn; double sminn_to_nitrate; double m_leafn_to_litr1n; double m_leafn_to_litr2n; double m_leafn_to_litr3n; double m_leafn_to_litr4n; double m_frootn_to_litr1n; double m_frootn_to_litr2n; double m_frootn_to_litr3n; double m_frootn_to_litr4n; double m_livestemn_to_litr1n; double m_livecrootn_to_litr1n; double m_leafn_store_to_litr1n; double m_frootn_store_to_litr1n; double m_livestemn_store_to_litr1n; double m_deadstemn_store_to_litr1n; double m_livecrootn_store_to_litr1n; double m_deadcrootn_store_to_litr1n; double m_leafn_transfer_to_litr1n; double m_frootn_transfer_to_litr1n; double m_livestemn_transfer_to_litr1n; double m_deadstemn_transfer_to_litr1n; double m_livecrootn_transfer_to_litr1n; double m_deadcrootn_transfer_to_litr1n; double m_retransn_to_litr1n; double sminn_to_nvol; double denitrif; double ndep_to_sminn; double nfix_to_sminn; double N_to_gw; double m_litr1n_to_atmos; double m_litr2n_to_atmos; double m_litr3n_to_atmos; double m_litr4n_to_atmos; double m_soil1n_to_atmos; double m_soil2n_to_atmos; double m_soil3n_to_atmos; double m_soil4n_to_atmos; } *

variable_types: struct soil_class { double sand; double silt; double clay; }

variable_types: theta double

variable_types: std double

variable_types: ok int

variable_types: denitrify double

variable_types: fnitrate double

variable_types: hr double


decompiled_code:
double __fastcall compute_delta_water(double a1, double a2, double a3, double a4, double a5)
{
double v7; // rbx
double v8; // xmm1_8
double v9; // xmm0_8
double v10; // xmm4_8
double v12; // rbp
double v13; // [rsp+8h] [rbp-30h]

v7 = a4;
v8 = a4;
if ( a4 >= 0.0 )
v8 = 0.0;
v9 = a5;
if ( a5 >= 0.0 )
v9 = 0.0;
v13 = v8 - v9;
if ( a5 <= 0.0 )
a5 = 0.0;
v10 = fmin(a5, a3);
if ( a4 <= 0.0 )
v7 = *(double *)&LC0;
if ( a2 == 0.0 || a2 >= 999.0 )
return (v7 - v10) * a1 + v13;
v12 = exp(COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC2) / a2);
return a2 * a1 * (v12 - exp(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC2) / a2)) + v13;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, double a4, double a5)
{
double v7; // rbx
double v8; // xmm1_8
double v9; // xmm0_8
double v10; // xmm4_8
double v12; // rbp
double v13; // [rsp+8h] [rbp-30h]

v7 = a4;
v8 = a4;
if ( a4 >= 0.0 )
v8 = 0.0;
v9 = a5;
if ( a5 >= 0.0 )
v9 = 0.0;
v13 = v8 - v9;
if ( a5 <= 0.0 )
a5 = 0.0;
v10 = fmin(a5, a3);
if ( a4 <= 0.0 )
v7 = *(double *)&LC0;
if ( a2 == 0.0 || a2 >= 999.0 )
return (v7 - v10) * a1 + v13;
v12 = exp(COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC2) / a2);
return a2 * a1 * (v12 - exp(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC2) / a2)) + v13;
}

original_code:
double compute_delta_water(
       int verbose_flag,
       double n_0,
       double p,
       double soil_depth,
       double z_initial,
       double z_final)
{
 double delta_water;
 delta_water = ((z_initial) < (0) ? (z_initial) : (0)) - ((z_final) < (0) ? (z_final) : (0));
 z_final = ((((z_final) > (0) ? (z_final) : (0))) < (soil_depth) ? (((z_final) > (0) ? (z_final) : (0))) : (soil_depth));
 z_initial = ((z_initial) > (0) ? (z_initial) : (0));
 if ( ( p != 0 ) && (p < 999.0) ){
  delta_water += n_0 * p *
   (exp(-z_final/p) - exp(-z_initial/p));
 }
 else{
  delta_water += n_0 * (z_initial - z_final );
 }
 return(delta_water);
}

canonical_original_code:
double compute_delta_water(int verbose_flag, double n_0, double p, double soil_depth, double z_initial, double z_final)
{
 double delta_water;
 delta_water = ((z_initial) < (0) ? (z_initial) : (0)) - ((z_final) < (0) ? (z_final) : (0));
 z_final = ((((z_final) > (0) ? (z_final) : (0))) < (soil_depth) ? (((z_final) > (0) ? (z_final) : (0))) : (soil_depth));
 z_initial = ((z_initial) > (0) ? (z_initial) : (0));
 if ( ( p != 0 ) && (p < 999.0) ){
  delta_water += n_0 * p *
   (exp(-z_final/p) - exp(-z_initial/p));
 }
 else{
  delta_water += n_0 * (z_initial - z_final );
 }
 return(delta_water);
}

variable_types: p double


variable_types: cn double

variable_types:
u
double *

variable_types:
ga
double *

variable_types: ra double


decompiled_code:
void __fastcall destroy_zone_defaults(int a1, int a2, void **a3)
{
void **v4; // rbx
__int64 v5; // r12

if ( a2 && a1 > 0 )
{
v4 = a3 + 35;
v5 = (__int64)&a3[40 * (unsigned int)(a1 - 1) + 75];
do
{
free(*v4);
v4 += 40;
}
while ( v4 != (void **)v5 );
}
free(a3);
}

original_code:
void destroy_zone_defaults(int num_default_files,
         int grow_flag,
         struct zone_default *default_object_list )
{
 int i;
 if ( grow_flag ){
  for ( i=0 ; i<num_default_files; i++ )
   free( default_object_list[i].grow_defaults );
 }
 free( default_object_list );
 return;
}

canonical_original_code:
void destroy_zone_defaults(int num_default_files, int grow_flag, struct zone_default *default_object_list)
{
 int i;
 if ( grow_flag ){
  for ( i=0 ; i<num_default_files; i++ )
   free( default_object_list[i].grow_defaults );
 }
 free( default_object_list );
 return;
}

variable_types: struct zone_default { int ID; double atm_trans_lapse_rate; double dewpoint_lapse_rate; double lapse_rate; double wet_lapse_rate; double lapse_rate_precip_default; double lapse_rate_tmin; double lapse_rate_tmax; double lapse_rate_tavg; double max_effective_lai; double pptmin; double sea_level_clear_sky_trans; double temcf; double trans_coeff1; double trans_coeff2; double trans_coeff1_sum; double trans_coeff2_sum; int trans_startmonth_sum; double trans_coeff1_win; double trans_coeff2_win; int trans_startmonth_win; double wind; double wind_direction; double max_snow_temp; double min_rain_temp; double ndep_NO3; double atm_CO2; double psen[7]; double ravg_days; struct zone_grow_default { int temp; } *grow_defaults; double search_x; double search_y; double res_patch; int grid_interpolation; } *

variable_types: i int

user_defined_types: struct zone_default { int ID; double atm_trans_lapse_rate; double dewpoint_lapse_rate; double lapse_rate; double wet_lapse_rate; double lapse_rate_precip_default; double lapse_rate_tmin; double lapse_rate_tmax; double lapse_rate_tavg; double max_effective_lai; double pptmin; double sea_level_clear_sky_trans; double temcf; double trans_coeff1; double trans_coeff2; double trans_coeff1_sum; double trans_coeff2_sum; int trans_startmonth_sum; double trans_coeff1_win; double trans_coeff2_win; int trans_startmonth_win; double wind; double wind_direction; double max_snow_temp; double min_rain_temp; double ndep_NO3; double atm_CO2; double psen[7]; double ravg_days; struct zone_grow_default *grow_defaults; double search_x; double search_y; double res_patch; int grid_interpolation; }


decompiled_code:
__int64 __fastcall find_sewer(__int64 a1, int a2, _DWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbp
int v7; // er12

v4 = a1 + 160LL * a2;
result = *(unsigned int *)(v4 + 20);
if ( (_DWORD)result == 1 )
{
*a3 = a2;
}
else if ( *(int *)(v4 + 96) <= 0 )
{
result = 0LL;
}
else
{
v6 = *(_QWORD *)(v4 + 128);
v7 = 1;
while ( 1 )
{
result = 0LL;
if ( *(_DWORD *)(v6 + 20) != 1 )
result = find_sewer(a1, *(unsigned int *)(v6 + 12), a3);
if ( *(_DWORD *)(v4 + 96) < ++v7 || (_DWORD)result )
break;
v6 = *(_QWORD *)(v6 + 48);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, _DWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbp
int v7; // er12

v4 = a1 + 160LL * a2;
result = *(unsigned int *)(v4 + 20);
if ( (_DWORD)result == 1 )
{
*a3 = a2;
}
else if ( *(int *)(v4 + 96) <= 0 )
{
result = 0LL;
}
else
{
v6 = *(_QWORD *)(v4 + 128);
v7 = 1;
while ( 1 )
{
result = 0LL;
if ( *(_DWORD *)(v6 + 20) != 1 )
result = func0(a1, *(unsigned int *)(v6 + 12), a3);
if ( *(_DWORD *)(v4 + 96) < ++v7 || (_DWORD)result )
break;
v6 = *(_QWORD *)(v6 + 48);
}
}
return result;
}

original_code:
int find_sewer(struct flow_struct *flow_table, int curr, int *str_inx) {
 struct adj_struct *aptr;
 int i, inx, fnd;
 fnd = 0;
 aptr = flow_table[curr].adj_list;
 if (flow_table[curr].land != 1) {
  i = 1;
  while ((i <= flow_table[curr].num_adjacent) && (fnd == 0)) {
   inx = aptr->inx;
   if (aptr->sewertype != 1)
    fnd = (int) find_sewer(flow_table, inx, str_inx);
   aptr = aptr->next;
   i += 1;
  }
 }
 else {
  fnd = 1;
  *str_inx = curr;
 }
 return (fnd);
}

canonical_original_code:
int find_sewer(struct flow_struct *flow_table, int curr, int *str_inx) {
 struct adj_struct *aptr;
 int i; int inx; int fnd;
 fnd = 0;
 aptr = flow_table[curr].adj_list;
 if (flow_table[curr].land != 1) {
  i = 1;
  while ((i <= flow_table[curr].num_adjacent) && (fnd == 0)) {
   inx = aptr->inx;
   if (aptr->sewertype != 1)
    fnd = (int) find_sewer(flow_table, inx, str_inx);
   aptr = aptr->next;
   i += 1;
  }
 }
 else {
  fnd = 1;
  *str_inx = curr;
 }
 return (fnd);
}

variable_types: struct flow_struct { int patchID; int hillID; int zoneID; int ID_order; int area; int land; int sewer; float x; float y; float z; float flna; float acc_area; float total_str_gamma; float total_gamma; float gamma_neigh; float total_perimeter; float road_dist; float slope; float internal_slope; float max_slope; double path_length; int num_str; int inflow_cnt; int num_adjacent; int num_dsa; int stream_inx; float stream_gamma; struct ID_struct { int patch; int hill; int zone; } stream_ID; struct adj_struct { int patchID; int hillID; int zoneID; int inx; int landtype; int sewertype; double perimeter; float slope; float gamma; float z; struct adj_struct *next; } *adj_list; struct adj_struct *adj_ptr; struct adj_struct *adj_str_ptr; struct adj_struct *adj_str_list; } *

variable_types: curr int

variable_types: inx int

variable_types: fnd int


keysAreEqual

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

result = 0LL;
if ( (_DWORD)a3 == (_DWORD)a1 && a2 == a4 )
result = HIDWORD(a1) == HIDWORD(a3);
return result;
}

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

result = 0LL;
if ( (_DWORD)a3 == (_DWORD)a1 && a2 == a4 )
result = HIDWORD(a1) == HIDWORD(a3);
return result;
}

original_code:
static bool keysAreEqual(char *key1, char *key2) {
 return strcmp(key1, key2) == 0;
}

canonical_original_code:
static short keysAreEqual(char *key1, char *key2) {
 return strcmp(key1, key2) == 0;
}


keyIsEmpty

decompiled_code:
_BOOL8 __fastcall keyIsEmpty(__int64 a1, int a2)
{
return (HIDWORD(a1) & (unsigned int)a1 & a2) == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, int a2)
{
return (HIDWORD(a1) & (unsigned int)a1 & a2) == -1;
}

original_code:
static bool keyIsEmpty(char *key) {
 return key == ((void *)0);
}

canonical_original_code:
static short keyIsEmpty(char *key) {
 return key == ((void *)0);
}

variable_types:
key
char *


freePatchHashTable

decompiled_code:
void __fastcall freePatchHashTable(void *ptr)
{
unsigned __int64 i; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( !ptr )
_assert_fail("table != NULL", "src/patch_hash_table.c", 0x45u, "freePatchHashTable");
for ( i = 0LL; *(_QWORD *)ptr > i; ++i )
{
v3 = *(_QWORD **)(*((_QWORD *)ptr + 2) + 24 * i + 16);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
}
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
unsigned __int64 i; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( !ptr )
_assert_fail("table != NULL", "src/patch_hash_table.c", 0x45u, "freePatchHashTable");
for ( i = 0LL; *(_QWORD *)ptr > i; ++i )
{
v3 = *(_QWORD **)(*((_QWORD *)ptr + 2) + 24 * i + 16);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
}
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void freePatchHashTable(PatchTable_t *table) {
 ((table != ((void *)0)) ? (void) (0) : __assert_fail ("table != NULL", "src/patch_hash_table.c", 69, __extension__ __PRETTY_FUNCTION__));
 PatchTableEntry_t *entry;
 PatchTableEntry_t *tmpEntry;
 size_t size = sizeof(PatchTableEntry_t);
 for (size_t i = 0; i < table->tableSize; i++) {
  entry = table->entries + i;
  tmpEntry = entry->next;
  while (tmpEntry != ((void *)0) ) {
   entry = tmpEntry;
   tmpEntry = entry->next;
   free(entry);
  }
 }
 free(table->entries);
 free(table);
}

canonical_original_code:
void freePatchHashTable(struct table_s *table) {
 ((table != ((void *)0)) ? (void) (0) : __assert_fail ("table != NULL", "src/patch_hash_table.c", 69, __extension__ __PRETTY_FUNCTION__));
 struct table_entry_s *entry;
 struct table_entry_s *tmpEntry;
 unsigned long size = sizeof(PatchTableEntry_t);
 for (unsigned long i = 0; i < table->tableSize; i++) {
  entry = table->entries + i;
  tmpEntry = entry->next;
  while (tmpEntry != ((void *)0) ) {
   entry = tmpEntry;
   tmpEntry = entry->next;
   free(entry);
  }
 }
 free(table->entries);
 free(table);
}

variable_types: struct table_s { unsigned long tableSize; unsigned long numEntries; struct table_entry_s { struct key_s { int patchID; int zoneID; int hillID; } originKey; int value; struct table_entry_s *next; } *entries; } *

variable_types:
size
unsigned long

variable_types:
i
unsigned long

user_defined_types: struct table_s { unsigned long tableSize; unsigned long numEntries; struct table_entry_s *entries; }

user_defined_types: struct table_entry_s { struct key_s originKey; int value; struct table_entry_s *next; }


patchHashTableGet

decompiled_code:
__int64 __fastcall patchHashTableGet(unsigned __int64 *a1, __int64 a2, int a3)
{
unsigned __int64 v3; // rbx

if ( !a1 )
_assert_fail("table != NULL", "src/patch_hash_table.c", 0x88u, "patchHashTableGet");
v3 = a1[2] + 24 * hash(a2, a3, *a1);
if ( !v3 )
return 0xFFFFFFFFLL;
while ( !keysAreEqual(*(_QWORD *)v3, *(_DWORD *)(v3 + 8), a2, a3) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v3 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1, __int64 a2, int a3)
{
unsigned __int64 v3; // rbx

if ( !a1 )
_assert_fail("table != NULL", "src/patch_hash_table.c", 0x88u, "patchHashTableGet");
v3 = a1[2] + 24 * func0(a2, a3, *a1);
if ( !v3 )
return 0xFFFFFFFFLL;
while ( !func1(*(_QWORD *)v3, *(_DWORD *)(v3 + 8), a2, a3) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v3 + 12);
}

original_code:
PatchTableValue_t patchHashTableGet(PatchTable_t *table, PatchKey_t key) {
 ((table != ((void *)0)) ? (void) (0) : __assert_fail ("table != NULL", "src/patch_hash_table.c", 136, __extension__ __PRETTY_FUNCTION__));
 PatchTableKey_t hash = _hash(key, table->tableSize);
 PatchTableEntry_t *entry = table->entries + hash;
 while (entry) {
  if (_keysAreEqual(entry->originKey, key)) {
   return entry->value;
  }
  entry = entry->next;
 }
 return -1;
}

canonical_original_code:
int patchHashTableGet(struct table_s *table, struct key_s key) {
 ((table != ((void *)0)) ? (void) (0) : __assert_fail ("table != NULL", "src/patch_hash_table.c", 136, __extension__ __PRETTY_FUNCTION__));
 unsigned long hash = _hash(key, table->tableSize);
 struct table_entry_s *entry = table->entries + hash;
 while (entry) {
  if (_keysAreEqual(entry->originKey, key)) {
   return entry->value;
  }
  entry = entry->next;
 }
 return -1;
}

variable_types:
key
struct key_s

variable_types:
hash
unsigned long

variable_types: struct table_entry_s { struct key_s { int patchID; int zoneID; int hillID; } originKey; int value; struct table_entry_s *next; } *