original_code:
double compute_snow_sublimation(
       int verbose_flag,
       double T_air,
       double T_snow,
       double vp_air,
       double snowpack_water_equivalent,
       double gasnow,
          double z_obs,
       double net_radiation,
       double pa,
          double *radsubl)
{
   double Qe;
   double Uz;
   double z_rough=0.005;
   double De;
   double hf;
   double hv, hs;
   double T_air_K;
   double T_snow_K;
   double vp_sat_ice;
   double ra, delta, psych, sublim, sublim_rad, sublim_turb;
   double ro;
   double stabil_func;
   double von_Karman=0.4;
   double sublim_floor_wind;
 T_air_K = T_air + 273.16;
 T_snow_K = T_snow + 273.16;
 hf = 334;
 hv = 2470;
 stabil_func = 1.0;
 gasnow = gasnow / 1.0;
 ro = 1.292 - ( 0.00428 * T_air );
 hs = (677.0 - 0.07*T_air) * 4.1868;
 vp_sat_ice = 610.78 * exp ((21.875 * (T_air_K - 273.16)/(T_air_K - 7.66)));
 De = gasnow;
 ra = 1/gasnow;
 Qe = -ro * hs * De * stabil_func * (0.622 * (vp_air - vp_sat_ice)/pa);
 delta = 2508.3/pow((T_air+237.3),2) * exp(17.3*T_air/(T_air+237.3)) * 1000.0;
 psych = 1.006 * pa / (0.622 * hs);
 sublim_rad = (delta * net_radiation) / (1000 * hs * (delta + psych));
 sublim_turb = (86400 * psych * 0.622 * hs * ro * (vp_sat_ice - vp_air) / (pa * ra)) / (1000 * hs * (delta + psych));
 sublim = ((sublim_rad + sublim_turb) > (0.0) ? (sublim_rad + sublim_turb) : (0.0));
 sublim = ((sublim) < (snowpack_water_equivalent) ? (sublim) : (snowpack_water_equivalent));
 if (sublim_rad > 0)
  *radsubl = sublim_rad / (sublim_rad + sublim_turb);
 else
  *radsubl = 0.0;
 if (verbose_flag == -5) {
  printf("\n                                             SUBLIM: De=%lf ro=%lf vp_air=%lf vp_ice=%lf pa=%lf Qe_pot=%lf subl_pot=%lf",
      De,ro,vp_air,vp_sat_ice,pa,Qe,Qe*86400/(hf+hv)/1000.0);
  printf("\n                                             SUBLIM2: netrad=%lf delta=%lf psych=%lf sublim_rad=%lf sublim_turb=%lf sublim=%lf swe=%lf",
      net_radiation/86.4, delta, psych, sublim_rad, sublim_turb, sublim, snowpack_water_equivalent);
 }
    return( sublim );
}

canonical_original_code:
double compute_snow_sublimation(int verbose_flag, double T_air, double T_snow, double vp_air, double snowpack_water_equivalent, double gasnow, double z_obs, double net_radiation, double pa, double *radsubl)
{
   double Qe;
   double Uz;
   double z_rough = 0.005;
   double De;
   double hf;
   double hv; double hs;
   double T_air_K;
   double T_snow_K;
   double vp_sat_ice;
   double ra; double delta; double psych; double sublim; double sublim_rad; double sublim_turb;
   double ro;
   double stabil_func;
   double von_Karman = 0.4;
   double sublim_floor_wind;
 T_air_K = T_air + 273.16;
 T_snow_K = T_snow + 273.16;
 hf = 334;
 hv = 2470;
 stabil_func = 1.0;
 gasnow = gasnow / 1.0;
 ro = 1.292 - ( 0.00428 * T_air );
 hs = (677.0 - 0.07*T_air) * 4.1868;
 vp_sat_ice = 610.78 * exp ((21.875 * (T_air_K - 273.16)/(T_air_K - 7.66)));
 De = gasnow;
 ra = 1/gasnow;
 Qe = -ro * hs * De * stabil_func * (0.622 * (vp_air - vp_sat_ice)/pa);
 delta = 2508.3/pow((T_air+237.3),2) * exp(17.3*T_air/(T_air+237.3)) * 1000.0;
 psych = 1.006 * pa / (0.622 * hs);
 sublim_rad = (delta * net_radiation) / (1000 * hs * (delta + psych));
 sublim_turb = (86400 * psych * 0.622 * hs * ro * (vp_sat_ice - vp_air) / (pa * ra)) / (1000 * hs * (delta + psych));
 sublim = ((sublim_rad + sublim_turb) > (0.0) ? (sublim_rad + sublim_turb) : (0.0));
 sublim = ((sublim) < (snowpack_water_equivalent) ? (sublim) : (snowpack_water_equivalent));
 if (sublim_rad > 0)
  *radsubl = sublim_rad / (sublim_rad + sublim_turb);
 else
  *radsubl = 0.0;
 if (verbose_flag == -5) {
  printf("\n                                             SUBLIM: De=%lf ro=%lf vp_air=%lf vp_ice=%lf pa=%lf Qe_pot=%lf subl_pot=%lf",
      De,ro,vp_air,vp_sat_ice,pa,Qe,Qe*86400/(hf+hv)/1000.0);
  printf("\n                                             SUBLIM2: netrad=%lf delta=%lf psych=%lf sublim_rad=%lf sublim_turb=%lf sublim=%lf swe=%lf",
      net_radiation/86.4, delta, psych, sublim_rad, sublim_turb, sublim, snowpack_water_equivalent);
 }
    return( sublim );
}

variable_types: gasnow double

variable_types: pa double

variable_types:
radsubl
double *

variable_types: Qe double

variable_types: Uz double

variable_types: De double

variable_types: hf double

variable_types: hv double

variable_types: hs double

variable_types: ra double

variable_types: delta double

variable_types: psych double

variable_types: sublim double

variable_types: ro double


repo: RHESSys/RHESSys

decompiled_code:
unsigned __int64 __fastcall sort_flow_table(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // er15
signed int v5; // er12
signed int *v6; // rbx
int v7; // er14
int v8; // ebp
signed int v9; // ecx
signed int v10; // eax
__int64 v11; // rdx
__int64 v12; // rcx
unsigned __int64 v14; // [rsp+28h] [rbp-50h]

v3 = 0;
v5 = 0;
v6 = (signed int *)(a1 + 160);
mergesort(a1 + 160, a2, 160LL, comparatorDesc);
v7 = 0;
if ( (int)a2 > 0 )
{
v8 = 1;
do
{
v9 = *v6;
v10 = v6[2];
v6[3] = v8;
v11 = (unsigned int)v6[1];
v14 = __PAIR64__(v10, v9);
if ( v5 < v9 )
v5 = v9;
if ( v7 < v10 )
v7 = v10;
v12 = (unsigned int)v8;
if ( v3 < (int)v11 )
v3 = v6[1];
++v8;
v6 += 40;
patchHashTableInsert(a3, v14, v11, v12);
}
while ( (int)a2 >= v8 );
}
return __PAIR64__(v3, v5);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // er15
signed int v5; // er12
signed int *v6; // rbx
int v7; // er14
int v8; // ebp
signed int v9; // ecx
signed int v10; // eax
__int64 v11; // rdx
__int64 v12; // rcx
unsigned __int64 v14; // [rsp+28h] [rbp-50h]

v3 = 0;
v5 = 0;
v6 = (signed int *)(a1 + 160);
mergesort(a1 + 160, a2, 160LL, comparatorDesc);
v7 = 0;
if ( (int)a2 > 0 )
{
v8 = 1;
do
{
v9 = *v6;
v10 = v6[2];
v6[3] = v8;
v11 = (unsigned int)v6[1];
v14 = __PAIR64__(v10, v9);
if ( v5 < v9 )
v5 = v9;
if ( v7 < v10 )
v7 = v10;
v12 = (unsigned int)v8;
if ( v3 < (int)v11 )
v3 = v6[1];
++v8;
v6 += 40;
patchHashTableInsert(a3, v14, v11, v12);
}
while ( (int)a2 >= v8 );
}
return __PAIR64__(v3, v5);
}

original_code:
struct ID_struct sort_flow_table(struct flow_struct *flow_table, int num_patches,
  PatchTable_t *patchTable) {
 struct ID_struct max_ID;
 mergesort(flow_table+1, num_patches, sizeof(struct flow_struct), _comparatorDesc);
 max_ID.patch = 0;
 max_ID.zone = 0;
 max_ID.hill = 0;
 PatchKey_t k;
 for (int i = 1; i <= num_patches; i++) {
  if (flow_table[i].patchID > max_ID.patch)
   max_ID.patch = flow_table[i].patchID;
  if (flow_table[i].zoneID > max_ID.zone)
   max_ID.zone = flow_table[i].zoneID;
  if (flow_table[i].hillID > max_ID.hill)
   max_ID.hill = flow_table[i].hillID;
  flow_table[i].ID_order = i;
  k.patchID = flow_table[i].patchID;
  k.zoneID = flow_table[i].zoneID;
  k.hillID = flow_table[i].hillID;
  patchHashTableInsert(patchTable, k, i);
 }
 return (max_ID);
}

canonical_original_code:
struct ID_struct sort_flow_table(struct flow_struct *flow_table, int num_patches, struct table_s *patchTable) {
 struct ID_struct max_ID;
 mergesort(flow_table+1, num_patches, sizeof(struct flow_struct), _comparatorDesc);
 max_ID.patch = 0;
 max_ID.zone = 0;
 max_ID.hill = 0;
 struct key_s k;
 for (int i = 1; i <= num_patches; i++) {
  if (flow_table[i].patchID > max_ID.patch)
   max_ID.patch = flow_table[i].patchID;
  if (flow_table[i].zoneID > max_ID.zone)
   max_ID.zone = flow_table[i].zoneID;
  if (flow_table[i].hillID > max_ID.hill)
   max_ID.hill = flow_table[i].hillID;
  flow_table[i].ID_order = i;
  k.patchID = flow_table[i].patchID;
  k.zoneID = flow_table[i].zoneID;
  k.hillID = flow_table[i].hillID;
  patchHashTableInsert(patchTable, k, i);
 }
 return (max_ID);
}

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 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: 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: struct ID_struct { int patch; int hill; int zone; }

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

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


original_code:
double compute_field_capacity(
          int verbose_flag,
          int curve,
          double psi_air_entry,
          double pore_size_index,
          double p3,
          double p4,
          double p_0,
          double p,
          double z_water_table,
          double z,
          double z_surface)
{
 double compute_delta_water(
  int,
  double,
  double,
  double,
  double,
  double);
 double depth;
 double field_capacity;
 double max_field_capacity;
 double porosity;
 double psi;
 double theta;
 double theta_actual;
 field_capacity = 0;
 p = ((p) > (0.00000001) ? (p) : (0.00000001));
 p_0 = ((p_0) > (0.00000001) ? (p_0) : (0.00000001));
 if (z < 0.000000001) z = 0.0;
 if (z_surface < 0.000000001) z_surface = 0.0;
 if ( p < 999.0 ) {
  if ( z > 0 ){
   for ( depth = z ; depth >z_surface ; depth = depth - 0.001){
    psi = (z-depth);
    if ( psi > psi_air_entry ){
     switch(curve) {
     case 1:
      theta = pow((psi_air_entry /psi),pore_size_index);
      break;
     case 2:
      theta = pow(1+pow(psi/psi_air_entry,p3),-pore_size_index);
      break;
     case 3:
      theta = exp((log(psi)-p3)/p4);
      break;
     }
    }
    else{
     theta = 1;
    }
    porosity = p_0 * exp( -1 * depth / p);
    theta_actual = theta * porosity ;
    field_capacity += theta_actual * 0.001;
   }
  }
 }
 else{
  field_capacity = p_0 * ( pow((psi_air_entry / 3.4),pore_size_index) ) * (z - z_surface);
 }
 max_field_capacity = compute_delta_water(
  verbose_flag,
  p_0,
  p,
  z_water_table,
  z,
  z_surface);
 field_capacity = ((field_capacity) < (max_field_capacity) ? (field_capacity) : (max_field_capacity));
 field_capacity = ((field_capacity) > (0.0) ? (field_capacity) : (0.0));
 return(field_capacity);
}

canonical_original_code:
double compute_field_capacity(int verbose_flag, int curve, double psi_air_entry, double pore_size_index, double p3, double p4, double p_0, double p, double z_water_table, double z, double z_surface)
{
 double compute_delta_water(int, double, double, double, double, double);
 double depth;
 double field_capacity;
 double max_field_capacity;
 double porosity;
 double psi;
 double theta;
 double theta_actual;
 field_capacity = 0;
 p = ((p) > (0.00000001) ? (p) : (0.00000001));
 p_0 = ((p_0) > (0.00000001) ? (p_0) : (0.00000001));
 if (z < 0.000000001) z = 0.0;
 if (z_surface < 0.000000001) z_surface = 0.0;
 if ( p < 999.0 ) {
  if ( z > 0 ){
   for ( depth = z ; depth >z_surface ; depth = depth - 0.001){
    psi = (z-depth);
    if ( psi > psi_air_entry ){
     switch(curve) {
     case 1:
      theta = pow((psi_air_entry /psi),pore_size_index);
      break;
     case 2:
      theta = pow(1+pow(psi/psi_air_entry,p3),-pore_size_index);
      break;
     case 3:
      theta = exp((log(psi)-p3)/p4);
      break;
     }
    }
    else{
     theta = 1;
    }
    porosity = p_0 * exp( -1 * depth / p);
    theta_actual = theta * porosity ;
    field_capacity += theta_actual * 0.001;
   }
  }
 }
 else{
  field_capacity = p_0 * ( pow((psi_air_entry / 3.4),pore_size_index) ) * (z - z_surface);
 }
 max_field_capacity = compute_delta_water(
  verbose_flag,
  p_0,
  p,
  z_water_table,
  z,
  z_surface);
 field_capacity = ((field_capacity) < (max_field_capacity) ? (field_capacity) : (max_field_capacity));
 field_capacity = ((field_capacity) > (0.0) ? (field_capacity) : (0.0));
 return(field_capacity);
}

variable_types: curve int

variable_types: p double

variable_types: z double

variable_types: double (int, double, double, double, double, double)

variable_types: depth double

variable_types: porosity double

variable_types: psi double

variable_types: theta double

return_type: double


newStringList

decompiled_code:
char **__fastcall newStringList(char *src)
{
char **v1; // rax
char **v2; // r12
size_t v3; // r13
char *v4; // rax

v1 = (char **)malloc(0x10uLL);
if ( !v1 )
_assert_fail("l", "util/string_list.c", 0x10u, "newStringList");
v1[1] = 0LL;
v2 = v1;
v3 = strlen(src) + 1;
v4 = (char *)malloc(v3);
*v2 = v4;
strncpy(v4, src, v3);
return v2;
}

canonical_decompiled_code:
char **__fastcall func0(char *src)
{
char **v1; // rax
char **v2; // r12
size_t v3; // r13
char *v4; // rax

v1 = (char **)malloc(0x10uLL);
if ( !v1 )
_assert_fail("l", "util/string_list.c", 0x10u, "newStringList");
v1[1] = 0LL;
v2 = v1;
v3 = strlen(src) + 1;
v4 = (char *)malloc(v3);
*v2 = v4;
strncpy(v4, src, v3);
return v2;
}

original_code:
StringList_t *newStringList(char *str) {
 StringList_t *l = (StringList_t *) malloc(sizeof(StringList_t));
 ((l) ? (void) (0) : __assert_fail ("l", "util/string_list.c", 16, __extension__ __PRETTY_FUNCTION__));
 l->next = ((void *)0);
 size_t strSize = strlen(str) + 1;
 l->str = (char *) malloc(strSize);
 strncpy(l->str, str, strSize);
 return l;
}

canonical_original_code:
struct string_list_s *newStringList(char *str) {
 struct string_list_s *l = (StringList_t *) malloc(sizeof(StringList_t));
 ((l) ? (void) (0) : __assert_fail ("l", "util/string_list.c", 16, __extension__ __PRETTY_FUNCTION__));
 l->next = ((void *)0);
 unsigned long strSize = strlen(str) + 1;
 l->str = (char *) malloc(strSize);
 strncpy(l->str, str, strSize);
 return l;
}

variable_types:
str
char *

variable_types: struct string_list_s { char *str; struct string_list_s *next; } *

variable_types:
strSize
unsigned long


freeStringList

decompiled_code:
void __fastcall freeStringList(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[1];
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void freeStringList(StringList_t *list) {
 if (list == ((void *)0)) return;
 StringList_t *next = list->next;
 free(list->str);
 free(list);
 freeStringList(next);
}

canonical_original_code:
void freeStringList(struct string_list_s *list) {
 if (list == ((void *)0)) return;
 struct string_list_s *next = list->next;
 free(list->str);
 free(list);
 freeStringList(next);
}

return_type: void

user_defined_types: struct string_list_s { char *str; struct string_list_s *next; }


stringListAppend

decompiled_code:
char **__fastcall stringListAppend(__int64 a1, char *a2)
{
__int64 v2; // rbx
char **result; // rax

if ( !a1 )
return newStringList(a2);
do
{
v2 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
result = newStringList(a2);
*(_QWORD *)(v2 + 8) = result;
return result;
}

canonical_decompiled_code:
char **__fastcall func2(__int64 a1, char *a2)
{
__int64 v2; // rbx
char **result; // rax

if ( !a1 )
return func0(a2);
do
{
v2 = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
result = func0(a2);
*(_QWORD *)(v2 + 8) = result;
return result;
}

original_code:
StringList_t *stringListAppend(StringList_t *list, char *str) {
 if (list == ((void *)0)) {
  return newStringList(str);
 } else {
  StringList_t *l = list;
  while (l->next != ((void *)0)) {
   l = l->next;
  }
  l->next = newStringList(str);
  return l->next;
 }
}

canonical_original_code:
struct string_list_s *stringListAppend(struct string_list_s *list, char *str) {
 if (list == ((void *)0)) {
  return newStringList(str);
 } else {
  struct string_list_s *l = list;
  while (l->next != ((void *)0)) {
   l = l->next;
  }
  l->next = newStringList(str);
  return l->next;
 }
}

variable_types:
list
struct string_list_s *

return_type: struct string_list_s { char *str; struct string_list_s *next; } *


printStringList

decompiled_code:
size_t __fastcall printStringList(const char **a1)
{
const char **v1; // rbx

v1 = a1;
fprintf(stderr, "StringList@%p [\n", a1);
if ( a1 )
{
do
{
fprintf(stderr, "%s,\n", *v1);
v1 = (const char **)v1[1];
}
while ( v1 );
}
return fwrite("]\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func3(const char **a1)
{
const char **v1; // rbx

v1 = a1;
fprintf(stderr, "StringList@%p [\n", a1);
if ( a1 )
{
do
{
fprintf(stderr, "%s,\n", *v1);
v1 = (const char **)v1[1];
}
while ( v1 );
}
return fwrite("]\n", 1uLL, 2uLL, stderr);
}

original_code:
void printStringList(StringList_t *list) {
 fprintf(stderr, "StringList@%p [\n", (void *)list);
 StringList_t *l = list;
 while (l != ((void *)0)) {
  fprintf(stderr, "%s,\n", l->str);
  l = l->next;
 }
 fprintf(stderr, "]\n");
}

canonical_original_code:
void printStringList(struct string_list_s *list) {
 fprintf(stderr, "StringList@%p [\n", (void *)list);
 struct string_list_s *l = list;
 while (l != ((void *)0)) {
  fprintf(stderr, "%s,\n", l->str);
  l = l->next;
 }
 fprintf(stderr, "]\n");
}


original_code:
void find_max_flna(struct flow_struct *flow_table, int curr, int *str_inx)
{
 struct adj_struct *aptr;
 int i, inx;
 double max_flna;
 aptr = flow_table[curr].adj_list;
 max_flna = flow_table[aptr->inx].flna;
 i = 1;
 while ((i <= flow_table[curr].num_adjacent)) {
  inx = aptr->inx;
  if ((flow_table[inx].flna >= max_flna) && (aptr->gamma != 0.0)) {
   *str_inx = inx;
   max_flna = flow_table[inx].flna;
  }
  aptr = aptr->next;
  i += 1;
 }
 return;
}

canonical_original_code:
void find_max_flna(struct flow_struct *flow_table, int curr, int *str_inx)
{
 struct adj_struct *aptr;
 int i; int inx;
 double max_flna;
 aptr = flow_table[curr].adj_list;
 max_flna = flow_table[aptr->inx].flna;
 i = 1;
 while ((i <= flow_table[curr].num_adjacent)) {
  inx = aptr->inx;
  if ((flow_table[inx].flna >= max_flna) && (aptr->gamma != 0.0)) {
   *str_inx = inx;
   max_flna = flow_table[inx].flna;
  }
  aptr = aptr->next;
  i += 1;
 }
 return;
}

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


yearday

original_code:
long yearday(struct date calender_date)
{
 long day;
 long cummulative_day_by_month[12]
  = {0,31,59,90,120,151,181,212,243,273,304,334};
 day = cummulative_day_by_month[calender_date.month-1]
  + calender_date.day;
 return(day);
}

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

variable_types: day long

return_type: long


decompiled_code:
__int64 __fastcall pervious_make_context(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, _QWORD *a9)
{
_QWORD *v13; // rax
__int64 result; // rax

if ( a9 )
{
v13 = calloc(1uLL, 0x38uLL);
if ( v13 )
{
v13[4] = a6;
*(_DWORD *)v13 = a1;
v13[5] = a7;
*((_DWORD *)v13 + 1) = a2;
v13[1] = a3;
v13[2] = a4;
v13[3] = a5;
*((_DWORD *)v13 + 12) = a8;
*a9 = v13;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate memory for the impervious search context.\n", 1uLL, 0x44uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return impervious context pointer is NULL.\n", 1uLL, 0x32uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, _QWORD *a9)
{
_QWORD *v13; // rax
__int64 result; // rax

if ( a9 )
{
v13 = calloc(1uLL, 0x38uLL);
if ( v13 )
{
v13[4] = a6;
*(_DWORD *)v13 = a1;
v13[5] = a7;
*((_DWORD *)v13 + 1) = a2;
v13[1] = a3;
v13[2] = a4;
v13[3] = a5;
*((_DWORD *)v13 + 12) = a8;
*a9 = v13;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate memory for the impervious search context.\n", 1uLL, 0x44uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return impervious context pointer is NULL.\n", 1uLL, 0x32uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool pervious_make_context(
    int _maxr,
    int _maxc,
    const double* _roofs,
    const int* _impervious,
    const int* _priorityCells,
    const double* _elevation,
    const int* _patch,
    int _priorityWeight,
    void** _rtn_ctx)
{
    bool result = true;
    if(_rtn_ctx == 0) {
 fprintf(stderr, "ERROR: Return impervious context pointer is NULL.\n");
 result = false;
    } else {
 pervious_context_t* context = (pervious_context_t*)calloc(1, sizeof(pervious_context_t));
 if(context == 0) {
     fprintf(stderr, "ERROR: Failed to allocate memory for the impervious search context.\n");
     result = false;
 } else {
     context->maxr_ = _maxr;
     context->maxc_ = _maxc;
     context->roofs_ = _roofs;
     context->impervious_ = _impervious;
     context->priorityCells_ = _priorityCells;
     context->elevation_ = _elevation;
     context->patch_ = _patch;
     context->priorityWeight_ = _priorityWeight;
     *_rtn_ctx = (void*)context;
 }
    }
    return result;
}

canonical_original_code:
short pervious_make_context(int _maxr, int _maxc, double *_roofs, int *_impervious, int *_priorityCells, double *_elevation, int *_patch, int _priorityWeight, void **_rtn_ctx)
{
    short result = true;
    if(_rtn_ctx == 0) {
 fprintf(stderr, "ERROR: Return impervious context pointer is NULL.\n");
 result = false;
    } else {
 struct pervious_context_s *context = (pervious_context_t*)calloc(1, sizeof(pervious_context_t));
 if(context == 0) {
     fprintf(stderr, "ERROR: Failed to allocate memory for the impervious search context.\n");
     result = false;
 } else {
     context->maxr_ = _maxr;
     context->maxc_ = _maxc;
     context->roofs_ = _roofs;
     context->impervious_ = _impervious;
     context->priorityCells_ = _priorityCells;
     context->elevation_ = _elevation;
     context->patch_ = _patch;
     context->priorityWeight_ = _priorityWeight;
     *_rtn_ctx = (void *)context;
 }
    }
    return result;
}

variable_types: result short

variable_types: struct pervious_context_s { int maxr_; int maxc_; double *roofs_; int *impervious_; int *priorityCells_; double *elevation_; int *patch_; int priorityWeight_; } *

return_type: short


decompiled_code:
__int64 __fastcall pervious_search_predicate(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int *a5, _DWORD *a6)
{
__int64 result; // rax
__int64 v11; // rax
int v12; // [rsp+8h] [rbp-30h] BYREF
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a5 )
{
if ( (unsigned __int16)row_col_to_index(a1, a2, *a5, a5[1], &v12)
&& (unsigned __int16)row_col_to_index(a3, a4, *a5, a5[1], v13) )
{
if ( *(_DWORD *)(*((_QWORD *)a5 + 2) + 4LL * v13[0])
|| (unsigned __int16)is_roof(*(double *)(*((_QWORD *)a5 + 1) + 8LL * v13[0])) )
{
*a6 = 0;
result = 1LL;
}
else
{
v11 = *((_QWORD *)a5 + 3);
if ( v11
&& *(_DWORD *)(v11 + 4LL * v13[0]) == 1
&& *(double *)(*((_QWORD *)a5 + 4) + 8LL * v12) > *(double *)(*((_QWORD *)a5 + 4) + 8LL * v13[0]) )
{
*a6 = 1;
result = 1LL;
}
else
{
*a6 = a5[12];
result = 1LL;
}
}
}
else
{
result = 0LL;
}
}
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
__int64 v11; // rax
int v12; // [rsp+8h] [rbp-30h] BYREF
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a5 )
{
if ( (unsigned __int16)row_col_to_index(a1, a2, *a5, a5[1], &v12)
&& (unsigned __int16)row_col_to_index(a3, a4, *a5, a5[1], v13) )
{
if ( *(_DWORD *)(*((_QWORD *)a5 + 2) + 4LL * v13[0])
|| (unsigned __int16)is_roof(*(double *)(*((_QWORD *)a5 + 1) + 8LL * v13[0])) )
{
*a6 = 0;
result = 1LL;
}
else
{
v11 = *((_QWORD *)a5 + 3);
if ( v11
&& *(_DWORD *)(v11 + 4LL * v13[0]) == 1
&& *(double *)(*((_QWORD *)a5 + 4) + 8LL * v12) > *(double *)(*((_QWORD *)a5 + 4) + 8LL * v13[0]) )
{
*a6 = 1;
result = 1LL;
}
else
{
*a6 = a5[12];
result = 1LL;
}
}
}
else
{
result = 0LL;
}
}
else
{
fwrite("ERROR: Search context pointer is NULL.\n", 1uLL, 0x27uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool pervious_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 {
     pervious_context_t* context = (pervious_context_t*)_context;
     int subjectIndex;
     int index;
     if (!row_col_to_index(_subjectRow, _subjectCol, context->maxr_, context->maxc_, &subjectIndex) ||
       !row_col_to_index(_row, _col, context->maxr_, context->maxc_, &index)) {
      result = false;
     } else {
      if (context->impervious_[index] == 0 && !is_roof(context->roofs_[index])) {
       if (context->priorityCells_ != ((void *)0) &&
         context->priorityCells_[index] == 1 && context->elevation_[index] < context->elevation_[subjectIndex]) {
        *_rtn_vote = 1;
       } else {
        *_rtn_vote = context->priorityWeight_;
       }
      } else {
       *_rtn_vote = 0;
      }
     }
    }
    return result;
}

canonical_original_code:
short pervious_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 pervious_context_s *context = (pervious_context_t*)_context;
     int subjectIndex;
     int index;
     if (!row_col_to_index(_subjectRow, _subjectCol, context->maxr_, context->maxc_, &subjectIndex) ||
       !row_col_to_index(_row, _col, context->maxr_, context->maxc_, &index)) {
      result = false;
     } else {
      if (context->impervious_[index] == 0 && !is_roof(context->roofs_[index])) {
       if (context->priorityCells_ != ((void *)0) &&
         context->priorityCells_[index] == 1 && context->elevation_[index] < context->elevation_[subjectIndex]) {
        *_rtn_vote = 1;
       } else {
        *_rtn_vote = context->priorityWeight_;
       }
      } else {
       *_rtn_vote = 0;
      }
     }
    }
    return result;
}

variable_types: subjectIndex int

variable_types: index int

user_defined_types: struct pervious_context_s { int maxr_; int maxc_; double *roofs_; int *impervious_; int *priorityCells_; double *elevation_; int *patch_; int priorityWeight_; }


decompiled_code:
__int64 __fastcall pervious_search_tiebreaker(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int *a5, unsigned int *a6, unsigned int *a7)
{
__int64 result; // rax
__int64 v12; // rdx
int v13; // [rsp+8h] [rbp-40h] BYREF
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( a5 )
{
if ( (unsigned __int16)row_col_to_index(a1, a2, *a5, a5[1], &v13)
&& (unsigned __int16)row_col_to_index(a3, a4, *a5, a5[1], v14) )
{
v12 = *((_QWORD *)a5 + 3);
*a6 = a1;
*a7 = a2;
result = 1LL;
if ( v12 && *(_DWORD *)(v12 + 4LL * v13) != 1 && *(_DWORD *)(v12 + 4LL * v14[0]) == 1 )
{
*a6 = a3;
*a7 = a4;
}
}
else
{
result = 0LL;
}
}
else
{
fwrite("ERROR: Search context pointer is NULL.\n", 1uLL, 0x27uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int *a5, unsigned int *a6, unsigned int *a7)
{
__int64 result; // rax
__int64 v12; // rdx
int v13; // [rsp+8h] [rbp-40h] BYREF
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( a5 )
{
if ( (unsigned __int16)row_col_to_index(a1, a2, *a5, a5[1], &v13)
&& (unsigned __int16)row_col_to_index(a3, a4, *a5, a5[1], v14) )
{
v12 = *((_QWORD *)a5 + 3);
*a6 = a1;
*a7 = a2;
result = 1LL;
if ( v12 && *(_DWORD *)(v12 + 4LL * v13) != 1 && *(_DWORD *)(v12 + 4LL * v14[0]) == 1 )
{
*a6 = a3;
*a7 = a4;
}
}
else
{
result = 0LL;
}
}
else
{
fwrite("ERROR: Search context pointer is NULL.\n", 1uLL, 0x27uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool pervious_search_tiebreaker(
 int _rowA,
 int _colA,
 int _rowB,
 int _colB,
 void* _context,
 int* _winnerRow,
 int* _winnerCol) {
 bool result = true;
 if (_context == 0) {
  fprintf(stderr, "ERROR: Search context pointer is NULL.\n");
  result = false;
 } else {
  pervious_context_t* context = (pervious_context_t*)_context;
  int aIndex;
  int bIndex;
  if (!row_col_to_index(_rowA, _colA, context->maxr_, context->maxc_, &aIndex) ||
    !row_col_to_index(_rowB, _colB, context->maxr_, context->maxc_, &bIndex)) {
   result = false;
  } else {
   result = true;
   *_winnerRow = _rowA;
   *_winnerCol = _colA;
   if (context->priorityCells_ != ((void *)0)) {
    if ( context->priorityCells_[aIndex] != 1 &&
      context->priorityCells_[bIndex] == 1 ) {
      *_winnerRow = _rowB;
      *_winnerCol = _colB;
    }
   }
  }
 }
 return result;
}

canonical_original_code:
short pervious_search_tiebreaker(int _rowA, int _colA, int _rowB, int _colB, void *_context, int *_winnerRow, int *_winnerCol) {
 short result = true;
 if (_context == 0) {
  fprintf(stderr, "ERROR: Search context pointer is NULL.\n");
  result = false;
 } else {
  struct pervious_context_s *context = (pervious_context_t*)_context;
  int aIndex;
  int bIndex;
  if (!row_col_to_index(_rowA, _colA, context->maxr_, context->maxc_, &aIndex) ||
    !row_col_to_index(_rowB, _colB, context->maxr_, context->maxc_, &bIndex)) {
   result = false;
  } else {
   result = true;
   *_winnerRow = _rowA;
   *_winnerCol = _colA;
   if (context->priorityCells_ != ((void *)0)) {
    if ( context->priorityCells_[aIndex] != 1 &&
      context->priorityCells_[bIndex] == 1 ) {
      *_winnerRow = _rowB;
      *_winnerCol = _colB;
    }
   }
  }
 }
 return result;
}

variable_types: aIndex int

variable_types: bIndex int


original_code:
void update_litter_interception_capacity( double litter_moist_coef,
           double litter_density,
           struct litter_c_object *litr_cs,
           struct litter_object *litter)
{
 double total_litter_C;
 total_litter_C = litr_cs->litr1c + litr_cs->litr2c
  + litr_cs->litr3c + litr_cs->litr4c;
 litter->rain_capacity = total_litter_C * litter_moist_coef * litter->cover_fraction;
 if (litter->rain_capacity < 0.000000001) litter->rain_capacity = 0;
 if (total_litter_C > 0.000000001){
  litter->proj_pai = 1.0*litter->cover_fraction;
  litter->depth = total_litter_C / litter_density;
 }
 else{
  litter->proj_pai = 0.0;
  litter->depth = 0.0;
 }
 return;
}

canonical_original_code:
void update_litter_interception_capacity(double litter_moist_coef, double litter_density, struct litter_c_object *litr_cs, struct litter_object *litter)
{
 double total_litter_C;
 total_litter_C = litr_cs->litr1c + litr_cs->litr2c
  + litr_cs->litr3c + litr_cs->litr4c;
 litter->rain_capacity = total_litter_C * litter_moist_coef * litter->cover_fraction;
 if (litter->rain_capacity < 0.000000001) litter->rain_capacity = 0;
 if (total_litter_C > 0.000000001){
  litter->proj_pai = 1.0*litter->cover_fraction;
  litter->depth = total_litter_C / litter_density;
 }
 else{
  litter->proj_pai = 0.0;
  litter->depth = 0.0;
 }
 return;
}

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_object { double cover_fraction; double depth; double density; double rain_stored; double NO3_stored; double gsurf; double proj_pai; double rain_capacity; double gl_c; double gsurf_slope; double gsurf_intercept; double moist_coef; double T; } *


decompiled_code:
__int64 __fastcall update_N_stratum_daily(double *a1, double *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31, int a32, int a33, int a34, int a35, int a36, int a37, int a38, int a39, int a40, int a41, int a42, int a43, int a44, int a45, int a46, int a47, int a48, int a49, int a50, int a51, int a52, int a53, int a54, int a55, int a56, int a57, int a58, int a59, int a60, int a61, int a62)
{
double v62; // xmm0_8
double v63; // xmm1_8
double v64; // xmm5_8
double v65; // xmm8_8
double v66; // xmm3_8
double v67; // xmm4_8
double v68; // xmm7_8
double v69; // xmm6_8
double v70; // xmm2_8
double v71; // xmm9_8
double v72; // xmm9_8
double v73; // xmm9_8
double v74; // xmm13_8
double v75; // xmm12_8
double v76; // xmm11_8
double v77; // xmm10_8
double v78; // xmm2_8
double v79; // xmm1_8
double v80; // xmm5_8
double v81; // xmm3_8
double v82; // xmm0_8
double v83; // xmm4_8
double v84; // xmm0_8
__int64 result; // rax
double v86; // xmm11_8
double v87; // xmm15_8
double v88; // xmm9_8
double v89; // xmm13_8
double v90; // xmm12_8
double v91; // xmm14_8
double v92; // xmm13_8
double v93; // xmm9_8
double v94; // xmm10_8
double v95; // xmm11_8
double v96; // xmm9_8
double v97; // xmm10_8
double v98; // xmm9_8
double v99; // xmm0_8
double v100; // [rsp+0h] [rbp-48h]
double v101; // [rsp+8h] [rbp-40h]
double v102; // [rsp+10h] [rbp-38h]
double v103; // [rsp+18h] [rbp-30h]
double v104; // [rsp+20h] [rbp-28h]
double v105; // [rsp+28h] [rbp-20h]
double v106; // [rsp+30h] [rbp-18h]
double v107; // [rsp+38h] [rbp-10h]
double v108; // [rsp+40h] [rbp-8h]

v62 = a1[3];
v63 = a1[4];
v64 = a1[18];
v65 = a1[12];
v66 = a1[10];
v67 = a1[23];
v68 = a1[17];
v69 = a1[24];
v70 = a1[11];
v71 = v62 + v63 + v64 + v65 + v67 + v68 + v66;
if ( a62 == 1 )
v72 = v71
+ a1[6]
+ a1[13]
+ a1[19]
+ a1[7]
+ a1[14]
+ a1[20]
+ a1[8]
+ a1[15]
+ a1[21]
+ a1[9]
+ a1[16]
+ a1[22]
+ v69
+ v70;
else
v72 = v71 + v69 + v70;
a1[1] = v72;
v73 = a2[12];
v74 = a2[13];
v75 = a2[14];
v76 = a2[15];
v77 = a2[16];
v78 = v70 - v73;
v79 = v63 + v74;
v80 = v64 + v75;
v81 = v66 + v76;
v82 = v62 + v73 + *a2 - v74;
v83 = v67 + v77;
a1[11] = v78;
a1[4] = v79;
a1[18] = v80;
a1[10] = v81;
a1[23] = v83;
v84 = v82 - v75 - v76 - v77;
a1[3] = v84;
if ( a62 == 1 )
{
v86 = a1[7];
result = 0LL;
v87 = a2[17];
v88 = a1[8];
v89 = a1[19];
v90 = a2[22];
v103 = a2[20];
v100 = a1[6] + v87;
a1[6] = v100;
v91 = a2[18];
v101 = v89 + v91;
a1[19] = v89 + v91;
v92 = a2[19];
v102 = v86 + v92;
a1[7] = v86 + v92;
v93 = v88 + a2[21];
v105 = a2[21];
v94 = a1[9];
v104 = a1[20] + v103;
a1[20] = v104;
v95 = a2[23];
v106 = v93;
a1[8] = v93;
v96 = a1[21] + v90;
v108 = v94 + v95;
a1[9] = v94 + v95;
v97 = a2[24];
v107 = v96;
a1[21] = v96;
v98 = a1[22] + v97;
a1[22] = v98;
v99 = v84 - v87 - v91 - v92 - v103 - v105 - v90 - v95 - v97;
a1[3] = v99;
a1[2] = v69
+ v98
+ v99
+ v79
+ v80
+ v65
+ v83
+ v68
+ v81
+ v100
+ a1[13]
+ v101
+ v102
+ a1[14]
+ v104
+ v106
+ a1[15]
+ v107
+ v108
+ a1[16]
+ v78;
}
else
{
result = 0LL;
a1[2] = v69 + v81 + v68 + v83 + v65 + v80 + v84 + v79 + v78;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, double *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31, int a32, int a33, int a34, int a35, int a36, int a37, int a38, int a39, int a40, int a41, int a42, int a43, int a44, int a45, int a46, int a47, int a48, int a49, int a50, int a51, int a52, int a53, int a54, int a55, int a56, int a57, int a58, int a59, int a60, int a61, int a62)
{
double v62; // xmm0_8
double v63; // xmm1_8
double v64; // xmm5_8
double v65; // xmm8_8
double v66; // xmm3_8
double v67; // xmm4_8
double v68; // xmm7_8
double v69; // xmm6_8
double v70; // xmm2_8
double v71; // xmm9_8
double v72; // xmm9_8
double v73; // xmm9_8
double v74; // xmm13_8
double v75; // xmm12_8
double v76; // xmm11_8
double v77; // xmm10_8
double v78; // xmm2_8
double v79; // xmm1_8
double v80; // xmm5_8
double v81; // xmm3_8
double v82; // xmm0_8
double v83; // xmm4_8
double v84; // xmm0_8
__int64 result; // rax
double v86; // xmm11_8
double v87; // xmm15_8
double v88; // xmm9_8
double v89; // xmm13_8
double v90; // xmm12_8
double v91; // xmm14_8
double v92; // xmm13_8
double v93; // xmm9_8
double v94; // xmm10_8
double v95; // xmm11_8
double v96; // xmm9_8
double v97; // xmm10_8
double v98; // xmm9_8
double v99; // xmm0_8
double v100; // [rsp+0h] [rbp-48h]
double v101; // [rsp+8h] [rbp-40h]
double v102; // [rsp+10h] [rbp-38h]
double v103; // [rsp+18h] [rbp-30h]
double v104; // [rsp+20h] [rbp-28h]
double v105; // [rsp+28h] [rbp-20h]
double v106; // [rsp+30h] [rbp-18h]
double v107; // [rsp+38h] [rbp-10h]
double v108; // [rsp+40h] [rbp-8h]

v62 = a1[3];
v63 = a1[4];
v64 = a1[18];
v65 = a1[12];
v66 = a1[10];
v67 = a1[23];
v68 = a1[17];
v69 = a1[24];
v70 = a1[11];
v71 = v62 + v63 + v64 + v65 + v67 + v68 + v66;
if ( a62 == 1 )
v72 = v71
+ a1[6]
+ a1[13]
+ a1[19]
+ a1[7]
+ a1[14]
+ a1[20]
+ a1[8]
+ a1[15]
+ a1[21]
+ a1[9]
+ a1[16]
+ a1[22]
+ v69
+ v70;
else
v72 = v71 + v69 + v70;
a1[1] = v72;
v73 = a2[12];
v74 = a2[13];
v75 = a2[14];
v76 = a2[15];
v77 = a2[16];
v78 = v70 - v73;
v79 = v63 + v74;
v80 = v64 + v75;
v81 = v66 + v76;
v82 = v62 + v73 + *a2 - v74;
v83 = v67 + v77;
a1[11] = v78;
a1[4] = v79;
a1[18] = v80;
a1[10] = v81;
a1[23] = v83;
v84 = v82 - v75 - v76 - v77;
a1[3] = v84;
if ( a62 == 1 )
{
v86 = a1[7];
result = 0LL;
v87 = a2[17];
v88 = a1[8];
v89 = a1[19];
v90 = a2[22];
v103 = a2[20];
v100 = a1[6] + v87;
a1[6] = v100;
v91 = a2[18];
v101 = v89 + v91;
a1[19] = v89 + v91;
v92 = a2[19];
v102 = v86 + v92;
a1[7] = v86 + v92;
v93 = v88 + a2[21];
v105 = a2[21];
v94 = a1[9];
v104 = a1[20] + v103;
a1[20] = v104;
v95 = a2[23];
v106 = v93;
a1[8] = v93;
v96 = a1[21] + v90;
v108 = v94 + v95;
a1[9] = v94 + v95;
v97 = a2[24];
v107 = v96;
a1[21] = v96;
v98 = a1[22] + v97;
a1[22] = v98;
v99 = v84 - v87 - v91 - v92 - v103 - v105 - v90 - v95 - v97;
a1[3] = v99;
a1[2] = v69
+ v98
+ v99
+ v79
+ v80
+ v65
+ v83
+ v68
+ v81
+ v100
+ a1[13]
+ v101
+ v102
+ a1[14]
+ v104
+ v106
+ a1[15]
+ v107
+ v108
+ a1[16]
+ v78;
}
else
{
result = 0LL;
a1[2] = v69 + v81 + v68 + v83 + v65 + v80 + v84 + v79 + v78;
}
return result;
}

original_code:
int update_N_stratum_daily( struct epconst_struct epc,
         struct nstate_struct *ns, struct ndayflux_struct *ndf,
         struct soil_n_object *ns_soil)
{
 int ok=1;
 if (epc.veg_type == 1){
  ns->preday_totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->live_stemn + ns->livestemn_transfer + ns->livestemn_store +
  ns->dead_stemn + ns->deadstemn_transfer + ns->deadstemn_store +
  ns->live_crootn + ns->livecrootn_transfer + ns->livecrootn_store +
  ns->dead_crootn + ns->deadcrootn_transfer + ns->deadcrootn_store + ns->cwdn + ns->retransn);
 }
 else {
  ns->preday_totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->cwdn + ns->retransn);
 }
 ns->npool += ndf->retransn_to_npool;
 ns->retransn -= ndf->retransn_to_npool;
 ns->npool += ndf->sminn_to_npool;
 ns->leafn += ndf->npool_to_leafn;
 ns->npool -= ndf->npool_to_leafn;
 ns->leafn_store += ndf->npool_to_leafn_store;
 ns->npool -= ndf->npool_to_leafn_store;
 ns->frootn += ndf->npool_to_frootn;
 ns->npool -= ndf->npool_to_frootn;
 ns->frootn_store += ndf->npool_to_frootn_store;
 ns->npool -= ndf->npool_to_frootn_store;
 if (epc.veg_type == 1){
  ns->live_stemn += ndf->npool_to_livestemn;
  ns->npool -= ndf->npool_to_livestemn;
  ns->livestemn_store += ndf->npool_to_livestemn_store;
  ns->npool -= ndf->npool_to_livestemn_store;
  ns->dead_stemn += ndf->npool_to_deadstemn;
  ns->npool -= ndf->npool_to_deadstemn;
  ns->deadstemn_store += ndf->npool_to_deadstemn_store;
  ns->npool -= ndf->npool_to_deadstemn_store;
  ns->live_crootn += ndf->npool_to_livecrootn;
  ns->npool -= ndf->npool_to_livecrootn;
  ns->livecrootn_store += ndf->npool_to_livecrootn_store;
  ns->npool -= ndf->npool_to_livecrootn_store;
  ns->dead_crootn += ndf->npool_to_deadcrootn;
  ns->npool -= ndf->npool_to_deadcrootn;
  ns->deadcrootn_store += ndf->npool_to_deadcrootn_store;
  ns->npool -= ndf->npool_to_deadcrootn_store;
 }
 if (epc.veg_type == 1){
  ns->totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->live_stemn + ns->livestemn_transfer + ns->livestemn_store +
  ns->dead_stemn + ns->deadstemn_transfer + ns->deadstemn_store +
  ns->live_crootn + ns->livecrootn_transfer + ns->livecrootn_store +
  ns->dead_crootn + ns->deadcrootn_transfer + ns->deadcrootn_store + ns->cwdn + ns->retransn);
 }
 else {
  ns->totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->cwdn + ns->retransn);
 }
 return (!ok);
}

canonical_original_code:
int update_N_stratum_daily(struct epconst_struct epc, struct nstate_struct *ns, struct ndayflux_struct *ndf, struct soil_n_object *ns_soil)
{
 int ok = 1;
 if (epc.veg_type == 1){
  ns->preday_totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->live_stemn + ns->livestemn_transfer + ns->livestemn_store +
  ns->dead_stemn + ns->deadstemn_transfer + ns->deadstemn_store +
  ns->live_crootn + ns->livecrootn_transfer + ns->livecrootn_store +
  ns->dead_crootn + ns->deadcrootn_transfer + ns->deadcrootn_store + ns->cwdn + ns->retransn);
 }
 else {
  ns->preday_totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->cwdn + ns->retransn);
 }
 ns->npool += ndf->retransn_to_npool;
 ns->retransn -= ndf->retransn_to_npool;
 ns->npool += ndf->sminn_to_npool;
 ns->leafn += ndf->npool_to_leafn;
 ns->npool -= ndf->npool_to_leafn;
 ns->leafn_store += ndf->npool_to_leafn_store;
 ns->npool -= ndf->npool_to_leafn_store;
 ns->frootn += ndf->npool_to_frootn;
 ns->npool -= ndf->npool_to_frootn;
 ns->frootn_store += ndf->npool_to_frootn_store;
 ns->npool -= ndf->npool_to_frootn_store;
 if (epc.veg_type == 1){
  ns->live_stemn += ndf->npool_to_livestemn;
  ns->npool -= ndf->npool_to_livestemn;
  ns->livestemn_store += ndf->npool_to_livestemn_store;
  ns->npool -= ndf->npool_to_livestemn_store;
  ns->dead_stemn += ndf->npool_to_deadstemn;
  ns->npool -= ndf->npool_to_deadstemn;
  ns->deadstemn_store += ndf->npool_to_deadstemn_store;
  ns->npool -= ndf->npool_to_deadstemn_store;
  ns->live_crootn += ndf->npool_to_livecrootn;
  ns->npool -= ndf->npool_to_livecrootn;
  ns->livecrootn_store += ndf->npool_to_livecrootn_store;
  ns->npool -= ndf->npool_to_livecrootn_store;
  ns->dead_crootn += ndf->npool_to_deadcrootn;
  ns->npool -= ndf->npool_to_deadcrootn;
  ns->deadcrootn_store += ndf->npool_to_deadcrootn_store;
  ns->npool -= ndf->npool_to_deadcrootn_store;
 }
 if (epc.veg_type == 1){
  ns->totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->live_stemn + ns->livestemn_transfer + ns->livestemn_store +
  ns->dead_stemn + ns->deadstemn_transfer + ns->deadstemn_store +
  ns->live_crootn + ns->livecrootn_transfer + ns->livecrootn_store +
  ns->dead_crootn + ns->deadcrootn_transfer + ns->deadcrootn_store + ns->cwdn + ns->retransn);
 }
 else {
  ns->totaln = (ns->npool+ns->leafn+ns->leafn_store+ns->leafn_transfer+ns->frootn_store+ns->frootn_transfer+ns->frootn +
  ns->cwdn + ns->retransn);
 }
 return (!ok);
}

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

variable_types: struct nstate_struct { double nlimit; double preday_totaln; double totaln; double npool; double leafn; double dead_leafn; double live_stemn; double dead_stemn; double live_crootn; double dead_crootn; double frootn; double retransn; double leafn_transfer; double livestemn_transfer; double deadstemn_transfer; double livecrootn_transfer; double deadcrootn_transfer; double frootn_transfer; double leafn_store; double livestemn_store; double deadstemn_store; double livecrootn_store; double deadcrootn_store; double frootn_store; double cwdn; double fire_snk; } *

variable_types: struct ndayflux_struct { double sminn_to_npool; double leafn_to_deadleafn; double leafn_store_to_leafn; double frootn_store_to_frootn; double leafn_transfer_to_leafn; double frootn_transfer_to_frootn; double livestemn_transfer_to_livestemn; double deadstemn_transfer_to_deadstemn; double livecrootn_transfer_to_livecrootn; double deadcrootn_transfer_to_deadcrootn; double potential_N_uptake; double actual_N_uptake; double retransn_to_npool; double npool_to_leafn; double npool_to_leafn_store; double npool_to_frootn; double npool_to_frootn_store; double npool_to_livestemn; double npool_to_livestemn_store; double npool_to_deadstemn; double npool_to_deadstemn_store; double npool_to_livecrootn; double npool_to_livecrootn_store; double npool_to_deadcrootn; double npool_to_deadcrootn_store; double leafn_store_to_leafn_transfer; double frootn_store_to_frootn_transfer; double livestemn_store_to_livestemn_transfer; double deadstemn_store_to_deadstemn_transfer; double livecrootn_store_to_livecrootn_transfer; double deadcrootn_store_to_deadcrootn_transfer; double carbohydrate_transfer; double livestemn_to_deadstemn; double livestemn_to_retransn; double livecrootn_to_deadcrootn; double livecrootn_to_retransn; } *

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: ok int

return_type: int


decompiled_code:
_BOOL8 __fastcall parse_phenology_type(void *ptr)
{
_BOOL4 v2; // er12
bool v4; // zf

if ( !memcmp(ptr, "DECIDUOUS", 5uLL) || !memcmp(ptr, "deciduous", 5uLL) )
{
v2 = 1;
}
else
{
v4 = memcmp(ptr, "EVERGREEN", 9uLL) == 0;
v2 = !v4;
if ( !v4 )
{
v4 = memcmp(ptr, "evergreen", 9uLL) == 0;
v2 = !v4;
if ( !v4 )
{
fwrite("\n FATAL ERROR - parse_phenology_type", 1uLL, 0x24uLL, stderr);
fprintf(stderr, "\n Unknown phenology type %s in stratum default file", (const char *)ptr);
fwrite("\n Must be either DECID or EVERGREEN", 1uLL, 0x23uLL, stderr);
exit(1);
}
}
}
free(ptr);
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(void *ptr)
{
_BOOL4 v2; // er12
bool v4; // zf

if ( !memcmp(ptr, "DECIDUOUS", 5uLL) || !memcmp(ptr, "deciduous", 5uLL) )
{
v2 = 1;
}
else
{
v4 = memcmp(ptr, "EVERGREEN", 9uLL) == 0;
v2 = !v4;
if ( !v4 )
{
v4 = memcmp(ptr, "evergreen", 9uLL) == 0;
v2 = !v4;
if ( !v4 )
{
fwrite("\n FATAL ERROR - parse_phenology_type", 1uLL, 0x24uLL, stderr);
fprintf(stderr, "\n Unknown phenology type %s in stratum default file", (const char *)ptr);
fwrite("\n Must be either DECID or EVERGREEN", 1uLL, 0x23uLL, stderr);
exit(1);
}
}
}
free(ptr);
return v2;
}

original_code:
int parse_phenology_type( char *input_string)
{
 int veg_type;
 if ((strncmp(input_string,"DECIDUOUS",5) == 0) ||
   (strncmp(input_string,"deciduous",5) == 0) )
  veg_type = 1;
 else if ((strncmp(input_string,"EVERGREEN",9) == 0) ||
   (strncmp(input_string,"evergreen",9) == 0) )
  veg_type = 0;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_phenology_type");
  fprintf(stderr,"\n Unknown phenology type %s in stratum default file", input_string);
  fprintf(stderr,"\n Must be either DECID or EVERGREEN");
  exit(1);
  }
 free(input_string);
 return(veg_type);
}

canonical_original_code:
int parse_phenology_type(char *input_string)
{
 int veg_type;
 if ((strncmp(input_string,"DECIDUOUS",5) == 0) ||
   (strncmp(input_string,"deciduous",5) == 0) )
  veg_type = 1;
 else if ((strncmp(input_string,"EVERGREEN",9) == 0) ||
   (strncmp(input_string,"evergreen",9) == 0) )
  veg_type = 0;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_phenology_type");
  fprintf(stderr,"\n Unknown phenology type %s in stratum default file", input_string);
  fprintf(stderr,"\n Must be either DECID or EVERGREEN");
  exit(1);
  }
 free(input_string);
 return(veg_type);
}


decompiled_code:
// attributes: thunk
__int64 compute_lwp_predawn()
{
return compute_soil_water_potential();
}

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

original_code:
double compute_lwp_predawn(
       int verbose_flag,
       int curve,
       double Tsoil,
       double LWP_min_spring,
       double LWP_stom_closure,
       double psi_air_entry,
       double pore_size_index,
       double p3,
       double p4,
       double p_0,
       double p,
       double S)
{
 double compute_soil_water_potential(
  int,
  int,
  double,
  double,
  double,
  double,
  double,
  double,
  double,
  double,
  double,
  double);
 double LWP_predawn;
 LWP_predawn = compute_soil_water_potential(verbose_flag,
  curve,
  Tsoil,
  LWP_min_spring,
  LWP_stom_closure,
  psi_air_entry,
  pore_size_index,
  p3,
  p4,
  p_0,
  p,
  S);
 return(LWP_predawn);
}

canonical_original_code:
double compute_lwp_predawn(int verbose_flag, int curve, double Tsoil, double LWP_min_spring, double LWP_stom_closure, double psi_air_entry, double pore_size_index, double p3, double p4, double p_0, double p, double S)
{
 double compute_soil_water_potential(int, int, double, double, double, double, double, double, double, double, double, double);
 double LWP_predawn;
 LWP_predawn = compute_soil_water_potential(verbose_flag,
  curve,
  Tsoil,
  LWP_min_spring,
  LWP_stom_closure,
  psi_air_entry,
  pore_size_index,
  p3,
  p4,
  p_0,
  p,
  S);
 return(LWP_predawn);
}

variable_types: curve int

variable_types: Tsoil double

variable_types: p double

variable_types: S double

variable_types: double (int, int, double, double, double, double, double, double, double, double, double, double)


decompiled_code:
void __fastcall destroy_surface_energy_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_surface_energy_defaults(int num_default_files,
       int grow_flag,
       struct surface_energy_default *default_object_list )
{
 free( default_object_list );
 return;
}

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

variable_types: struct surface_energy_default { int ID; int N_thermal_nodes; int exp_dist; double damping_depth; double iteration_threshold; } *


decompiled_code:
__int64 __fastcall normalize_receivers(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
float v4; // xmm1_4
__int64 result; // rax

if ( a1 )
{
v2 = *(_QWORD *)(a1 + 160LL * a2 + 128);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 160LL * a2 + 128);
v4 = 0.0;
do
{
v4 = v4 + *(float *)(v3 + 36);
v3 = *(_QWORD *)(v3 + 48);
}
while ( v3 );
do
{
*(float *)(v2 + 36) = *(float *)(v2 + 36) / v4;
v2 = *(_QWORD *)(v2 + 48);
}
while ( v2 );
}
result = 1LL;
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
float v4; // xmm1_4
__int64 result; // rax

if ( a1 )
{
v2 = *(_QWORD *)(a1 + 160LL * a2 + 128);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 160LL * a2 + 128);
v4 = 0.0;
do
{
v4 = v4 + *(float *)(v3 + 36);
v3 = *(_QWORD *)(v3 + 48);
}
while ( v3 );
do
{
*(float *)(v2 + 36) = *(float *)(v2 + 36) / v4;
v2 = *(_QWORD *)(v2 + 48);
}
while ( v2 );
}
result = 1LL;
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
static bool normalize_receivers(
    struct flow_struct* _flow_table,
    int _patch)
{
    bool result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    }
    else if(_patch < 0) {
        fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", _patch);
        result = false;
    } else {
        float total_gamma = 0.0;
        for(struct adj_struct* adjacency = _flow_table[_patch].adj_list; result && adjacency; adjacency = adjacency->next) {
            total_gamma += adjacency->gamma;
        }
        for(struct adj_struct* adjacency = _flow_table[_patch].adj_list; result && adjacency; adjacency = adjacency->next) {
            float new_gamma = adjacency->gamma / total_gamma;
            adjacency->gamma = new_gamma;
        }
    }
    return result;
}

canonical_original_code:
static short normalize_receivers(struct flow_struct *_flow_table, int _patch)
{
    short result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    }
    else if(_patch < 0) {
        fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", _patch);
        result = false;
    } else {
        float total_gamma = 0.0;
        for(struct adj_struct *adjacency = _flow_table[_patch].adj_list; result && adjacency; adjacency = adjacency->next) {
            total_gamma += adjacency->gamma;
        }
        for(struct adj_struct *adjacency = _flow_table[_patch].adj_list; result && adjacency; adjacency = adjacency->next) {
            float new_gamma = adjacency->gamma / total_gamma;
            adjacency->gamma = new_gamma;
        }
    }
    return result;
}

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: result short


decompiled_code:
__int64 __fastcall consolidate_duplicate_receivers(__int64 a1, int a2)
{
__int64 v2; // r13
__int64 v3; // rbp
_QWORD *v4; // rdi
_QWORD *v5; // r12
_QWORD *v6; // rbx

if ( a1 )
{
v2 = a1 + 160LL * a2;
v3 = *(_QWORD *)(v2 + 128);
if ( !v3 )
return 1LL;
while ( 1 )
{
v4 = *(_QWORD **)(v3 + 48);
if ( !v4 )
return 1LL;
v5 = (_QWORD *)v3;
while ( 1 )
{
v6 = (_QWORD *)v4[6];
if ( *(_QWORD *)v3 == *v4 && *(_DWORD *)(v3 + 8) == *((_DWORD *)v4 + 2) )
break;
if ( !v6 )
goto LABEL_10;
LABEL_6:
v5 = v4;
v4 = v6;
}
*(float *)(v3 + 36) = *(float *)(v3 + 36) + *((float *)v4 + 9);
v5[6] = v6;
v6 = (_QWORD *)v4[6];
free(v4);
--*(_DWORD *)(v2 + 96);
v4 = v5;
if ( v6 )
goto LABEL_6;
LABEL_10:
v3 = *(_QWORD *)(v3 + 48);
if ( !v3 )
return 1LL;
}
}
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
return 0LL;
}

original_code:
static bool consolidate_duplicate_receivers(
    struct flow_struct* _flow_table,
    int _patch)
{
    bool result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    }
    else if(_patch < 0) {
        fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", _patch);
        result = false;
    } else {
        struct adj_struct* adjacency = 0;
        for(adjacency = _flow_table[_patch].adj_list; result && adjacency != 0 && adjacency->next != 0; adjacency = adjacency->next) {
            struct adj_struct* other_adj = 0;
            struct adj_struct* prev_adj = adjacency;
            for(other_adj = adjacency->next; result && other_adj != 0;) {
                if(adjacency->patchID == other_adj->patchID &&
                   adjacency->hillID == other_adj->hillID &&
                   adjacency->zoneID == other_adj->zoneID) {
                    adjacency->gamma += other_adj->gamma;
                    prev_adj->next = other_adj->next;
                    struct adj_struct* tmp_adj = other_adj;
                    other_adj = other_adj->next;
                    free(tmp_adj);
                    --_flow_table[_patch].num_adjacent;
                } else {
                    prev_adj = other_adj;
                    other_adj = other_adj->next;
                }
            }
        }
    }
    return result;
}

canonical_original_code:
static short consolidate_duplicate_receivers(struct flow_struct *_flow_table, int _patch)
{
    short result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    }
    else if(_patch < 0) {
        fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", _patch);
        result = false;
    } else {
        struct adj_struct *adjacency = 0;
        for(adjacency = _flow_table[_patch].adj_list; result && adjacency != 0 && adjacency->next != 0; adjacency = adjacency->next) {
            struct adj_struct *other_adj = 0;
            struct adj_struct *prev_adj = adjacency;
            for(other_adj = adjacency->next; result && other_adj != 0;) {
                if(adjacency->patchID == other_adj->patchID &&
                   adjacency->hillID == other_adj->hillID &&
                   adjacency->zoneID == other_adj->zoneID) {
                    adjacency->gamma += other_adj->gamma;
                    prev_adj->next = other_adj->next;
                    struct adj_struct *tmp_adj = other_adj;
                    other_adj = other_adj->next;
                    free(tmp_adj);
                    --_flow_table[_patch].num_adjacent;
                } else {
                    prev_adj = other_adj;
                    other_adj = other_adj->next;
                }
            }
        }
    }
    return result;
}

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

user_defined_types: struct ID_struct { int patch; int hill; int zone; }


decompiled_code:
__int64 __fastcall normalize_roof_patches(__int64 a1, int a2)
{
_DWORD *v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

if ( a1 )
{
v2 = (_DWORD *)(a1 + 20);
v3 = 0;
if ( a2 >= 0 )
{
do
{
if ( *v2 == 4 )
{
if ( !(unsigned __int16)consolidate_duplicate_receivers(a1, v3) )
{
fprintf(stderr, "ERROR: Failed to consolidate the duplicate receivers for patch, %d.\n", v3);
return 0LL;
}
if ( !(unsigned __int16)normalize_receivers(a1, v3) )
{
fprintf(stderr, "ERROR: Failed to normalize the receivers for patch, %d.\n", v3);
return 0LL;
}
}
++v3;
v2 += 40;
}
while ( a2 >= (int)v3 );
result = 1LL;
}
else
{
fprintf(stderr, "ERROR: Number of patches, %d, is less than zero.\n", (unsigned int)a2);
result = 0LL;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
_DWORD *v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

if ( a1 )
{
v2 = (_DWORD *)(a1 + 20);
v3 = 0;
if ( a2 >= 0 )
{
do
{
if ( *v2 == 4 )
{
if ( !(unsigned __int16)func1(a1, v3) )
{
fprintf(stderr, "ERROR: Failed to consolidate the duplicate receivers for patch, %d.\n", v3);
return 0LL;
}
if ( !(unsigned __int16)func0(a1, v3) )
{
fprintf(stderr, "ERROR: Failed to normalize the receivers for patch, %d.\n", v3);
return 0LL;
}
}
++v3;
v2 += 40;
}
while ( a2 >= (int)v3 );
result = 1LL;
}
else
{
fprintf(stderr, "ERROR: Number of patches, %d, is less than zero.\n", (unsigned int)a2);
result = 0LL;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool normalize_roof_patches(
    struct flow_struct* _flow_table,
    int _num_patches)
{
    bool result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_num_patches < 0) {
        fprintf(stderr, "ERROR: Number of patches, %d, is less than zero.\n", _num_patches);
        result = false;
    } else {
        for(int index = 0; result && index <= _num_patches; ++index) {
            if(_flow_table[index].land == LANDTYPE_ROOF) {
                if(!consolidate_duplicate_receivers(_flow_table, index)) {
                    fprintf(stderr, "ERROR: Failed to consolidate the duplicate receivers for patch, %d.\n", index);
                    result = false;
                }
                else if(!normalize_receivers(_flow_table, index)) {
                    fprintf(stderr, "ERROR: Failed to normalize the receivers for patch, %d.\n", index);
                    result = false;
                }
            }
        }
    }
    return result;
}

canonical_original_code:
short normalize_roof_patches(struct flow_struct *_flow_table, int _num_patches)
{
    short result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_num_patches < 0) {
        fprintf(stderr, "ERROR: Number of patches, %d, is less than zero.\n", _num_patches);
        result = false;
    } else {
        for(int index = 0; result && index <= _num_patches; ++index) {
            if(_flow_table[index].land == LANDTYPE_ROOF) {
                if(!consolidate_duplicate_receivers(_flow_table, index)) {
                    fprintf(stderr, "ERROR: Failed to consolidate the duplicate receivers for patch, %d.\n", index);
                    result = false;
                }
                else if(!normalize_receivers(_flow_table, index)) {
                    fprintf(stderr, "ERROR: Failed to normalize the receivers for patch, %d.\n", index);
                    result = false;
                }
            }
        }
    }
    return result;
}

variable_types: index int

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


strip

decompiled_code:
__int64 __fastcall strip(char *s)
{
size_t v1; // rax
__int64 result; // rax

if ( !s )
return 0LL;
v1 = strlen(s);
if ( v1 > 2 )
result = (int)strndup(s + 1, v1 - 2);
else
result = (int)strdup(s);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
size_t v1; // rax
__int64 result; // rax

if ( !s )
return 0LL;
v1 = strlen(s);
if ( v1 > 2 )
result = (int)strndup(s + 1, v1 - 2);
else
result = (int)strdup(s);
return result;
}

original_code:
char *strip(const char * const str) {
    char *stripped = ((void *)0);
    if (str != ((void *)0)) {
        size_t len = strlen(str);
        if (len < 3) {
            stripped = strdup(str);
        } else {
            stripped = strndup(str + 1, len - 2);
        }
    }
    return stripped;
}

canonical_original_code:
char *strip(char *str) {
    char *stripped = ((void *)0);
    if (str != ((void *)0)) {
        unsigned long len = strlen(str);
        if (len < 3) {
            stripped = strdup(str);
        } else {
            stripped = strndup(str + 1, len - 2);
        }
    }
    return stripped;
}

variable_types:
str
char *

variable_types:
stripped
char *

variable_types:
len
unsigned long

return_type: char *


getIntParam

decompiled_code:
__int64 __fastcall getIntParam(int *a1, void **a2, const char *a3, const char *a4, unsigned int a5, int a6)
{
int v8; // er12
char *v9; // r15
char *v10; // rbp
__int64 result; // rax
char *v12; // rax
int v13; // edx
char *v14; // rbx
unsigned int v17; // [rsp+2Ch] [rbp-3Ch] BYREF

v8 = *a1;
v9 = (char *)*a2;
if ( *a1 <= 0 )
{
if ( !a6 )
goto LABEL_12;
if ( v8 )
{
LABEL_7:
v12 = (char *)realloc(v9, 1072LL * (v8 + 1));
*a2 = v12;
}
else
{
v12 = (char *)malloc(0x430uLL);
*a2 = v12;
}
v13 = (*a1)++;
v14 = &v12[1072 * v13];
strcpy(v14, a3);
sprintf(v14 + 32, "%d", a5);
*((_QWORD *)v14 + 133) = 0x100000001LL;
strcpy(v14 + 1056, a4);
result = a5;
}
else
{
v10 = (char *)*a2;
while ( strcmp(v10, a3) )
{
v10 += 1072;
if ( &v9[1072 * (v8 - 1) + 1072] == v10 )
{
if ( a6 )
goto LABEL_7;
LABEL_12:
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
_isoc99_sscanf(v10 + 32, a4, &v17);
*((_DWORD *)v10 + 266) = 1;
strcpy(v10 + 1056, a4);
result = v17;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, void **a2, const char *a3, const char *a4, unsigned int a5, int a6)
{
int v8; // er12
char *v9; // r15
char *v10; // rbp
__int64 result; // rax
char *v12; // rax
int v13; // edx
char *v14; // rbx
unsigned int v17; // [rsp+2Ch] [rbp-3Ch] BYREF

v8 = *a1;
v9 = (char *)*a2;
if ( *a1 <= 0 )
{
if ( !a6 )
goto LABEL_12;
if ( v8 )
{
LABEL_7:
v12 = (char *)realloc(v9, 1072LL * (v8 + 1));
*a2 = v12;
}
else
{
v12 = (char *)malloc(0x430uLL);
*a2 = v12;
}
v13 = (*a1)++;
v14 = &v12[1072 * v13];
strcpy(v14, a3);
sprintf(v14 + 32, "%d", a5);
*((_QWORD *)v14 + 133) = 0x100000001LL;
strcpy(v14 + 1056, a4);
result = a5;
}
else
{
v10 = (char *)*a2;
while ( strcmp(v10, a3) )
{
v10 += 1072;
if ( &v9[1072 * (v8 - 1) + 1072] == v10 )
{
if ( a6 )
goto LABEL_7;
LABEL_12:
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
_isoc99_sscanf(v10 + 32, a4, &v17);
*((_DWORD *)v10 + 266) = 1;
strcpy(v10 + 1056, a4);
result = v17;
}
return result;
}

original_code:
int getIntParam(int *paramCnt, param **paramPtr , char *paramName, char *readFormat, int defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    int intVal;
    int found = 0;
    param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &intVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return intVal;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        sprintf(params[paramInd].strVal, "%d", defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

canonical_original_code:
int getIntParam(int *paramCnt, struct param **paramPtr, char *paramName, char *readFormat, int defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    int intVal;
    int found = 0;
    struct param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &intVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return intVal;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (struct param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (struct param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        sprintf(params[paramInd].strVal, "%d", defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

variable_types:
paramCnt
int *

variable_types: struct param { char name[32]; char strVal[1024]; char format[8]; int accessed; int defaultValUsed; } **

variable_types:
paramName
char *

variable_types:
readFormat
char *

variable_types: defaultVal int

variable_types: useDefaultVal int

variable_types: iParam int

variable_types: paramInd int

variable_types: sLen int

variable_types: intVal int

variable_types: found int


getFloatParam

decompiled_code:
float __fastcall getFloatParam(int *a1, void **a2, const char *a3, const char *a4, int a5, float result)
{
int v8; // er14
char *v9; // r15
char *v10; // rbp
char *v11; // rax
int v12; // edx
char *v13; // rbx
float v15; // [rsp+2Ch] [rbp-3Ch] BYREF

v8 = *a1;
v9 = (char *)*a2;
if ( *a1 <= 0 )
{
if ( !a5 )
{
LABEL_7:
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
return result;
}
if ( !v8 )
{
v11 = (char *)malloc(0x430uLL);
*a2 = v11;
goto LABEL_9;
}
}
else
{
v10 = (char *)*a2;
do
{
if ( !strcmp(v10, a3) )
{
_isoc99_sscanf(v10 + 32, a4, &v15);
*((_DWORD *)v10 + 266) = 1;
strcpy(v10 + 1056, a4);
return v15;
}
v10 += 1072;
}
while ( &v9[1072 * (v8 - 1) + 1072] != v10 );
if ( !a5 )
goto LABEL_7;
}
v11 = (char *)realloc(v9, 1072LL * (v8 + 1));
*a2 = v11;
LABEL_9:
v12 = (*a1)++;
v13 = &v11[1072 * v12];
strcpy(v13, a3);
sprintf(v13 + 32, "%f", result);
*((_QWORD *)v13 + 133) = 0x100000001LL;
strcpy(v13 + 1056, a4);
return result;
}

canonical_decompiled_code:
float __fastcall func2(int *a1, void **a2, const char *a3, const char *a4, int a5, float result)
{
int v8; // er14
char *v9; // r15
char *v10; // rbp
char *v11; // rax
int v12; // edx
char *v13; // rbx
float v15; // [rsp+2Ch] [rbp-3Ch] BYREF

v8 = *a1;
v9 = (char *)*a2;
if ( *a1 <= 0 )
{
if ( !a5 )
{
LABEL_7:
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
return result;
}
if ( !v8 )
{
v11 = (char *)malloc(0x430uLL);
*a2 = v11;
goto LABEL_9;
}
}
else
{
v10 = (char *)*a2;
do
{
if ( !strcmp(v10, a3) )
{
_isoc99_sscanf(v10 + 32, a4, &v15);
*((_DWORD *)v10 + 266) = 1;
strcpy(v10 + 1056, a4);
return v15;
}
v10 += 1072;
}
while ( &v9[1072 * (v8 - 1) + 1072] != v10 );
if ( !a5 )
goto LABEL_7;
}
v11 = (char *)realloc(v9, 1072LL * (v8 + 1));
*a2 = v11;
LABEL_9:
v12 = (*a1)++;
v13 = &v11[1072 * v12];
strcpy(v13, a3);
sprintf(v13 + 32, "%f", result);
*((_QWORD *)v13 + 133) = 0x100000001LL;
strcpy(v13 + 1056, a4);
return result;
}

original_code:
float getFloatParam(int *paramCnt, param **paramPtr , char *paramName, char *readFormat, float defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    float floatVal;
    int found = 0;
    param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &floatVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return floatVal;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        sprintf(params[paramInd].strVal, "%f", defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
    }
}

canonical_original_code:
float getFloatParam(int *paramCnt, struct param **paramPtr, char *paramName, char *readFormat, float defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    float floatVal;
    int found = 0;
    struct param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &floatVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return floatVal;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (struct param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (struct param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        sprintf(params[paramInd].strVal, "%f", defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
    }
}

variable_types: defaultVal float

variable_types: floatVal float

variable_types: struct param { char name[32]; char strVal[1024]; char format[8]; int accessed; int defaultValUsed; } *

return_type: float


getDoubleParam

decompiled_code:
double __fastcall getDoubleParam(int *a1, void **a2, const char *a3, const char *a4, int a5, double result)
{
int v8; // er12
char *v9; // r15
char *v10; // rbp
char *v11; // rax
int v12; // edx
char *v13; // rbx
double v15; // [rsp+28h] [rbp-40h] BYREF

v8 = *a1;
v9 = (char *)*a2;
if ( *a1 <= 0 )
{
if ( !a5 )
goto LABEL_12;
if ( v8 )
{
LABEL_7:
v11 = (char *)realloc(v9, 1072LL * (v8 + 1));
*a2 = v11;
}
else
{
v11 = (char *)malloc(0x430uLL);
*a2 = v11;
}
v12 = (*a1)++;
v13 = &v11[1072 * v12];
strcpy(v13, a3);
sprintf(v13 + 32, "%f", result);
*((_QWORD *)v13 + 133) = 0x100000001LL;
strcpy(v13 + 1056, a4);
}
else
{
v10 = (char *)*a2;
while ( strcmp(v10, a3) )
{
v10 += 1072;
if ( &v9[1072 * (v8 - 1) + 1072] == v10 )
{
if ( a5 )
goto LABEL_7;
LABEL_12:
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
_isoc99_sscanf(v10 + 32, a4, &v15);
*((_DWORD *)v10 + 266) = 1;
strcpy(v10 + 1056, a4);
result = v15;
}
return result;
}

canonical_decompiled_code:
double __fastcall func3(int *a1, void **a2, const char *a3, const char *a4, int a5, double result)
{
int v8; // er12
char *v9; // r15
char *v10; // rbp
char *v11; // rax
int v12; // edx
char *v13; // rbx
double v15; // [rsp+28h] [rbp-40h] BYREF

v8 = *a1;
v9 = (char *)*a2;
if ( *a1 <= 0 )
{
if ( !a5 )
goto LABEL_12;
if ( v8 )
{
LABEL_7:
v11 = (char *)realloc(v9, 1072LL * (v8 + 1));
*a2 = v11;
}
else
{
v11 = (char *)malloc(0x430uLL);
*a2 = v11;
}
v12 = (*a1)++;
v13 = &v11[1072 * v12];
strcpy(v13, a3);
sprintf(v13 + 32, "%f", result);
*((_QWORD *)v13 + 133) = 0x100000001LL;
strcpy(v13 + 1056, a4);
}
else
{
v10 = (char *)*a2;
while ( strcmp(v10, a3) )
{
v10 += 1072;
if ( &v9[1072 * (v8 - 1) + 1072] == v10 )
{
if ( a5 )
goto LABEL_7;
LABEL_12:
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
_isoc99_sscanf(v10 + 32, a4, &v15);
*((_DWORD *)v10 + 266) = 1;
strcpy(v10 + 1056, a4);
result = v15;
}
return result;
}

original_code:
double getDoubleParam(int *paramCnt, param **paramPtr, char *paramName, char *readFormat, double defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    double doubleVal;
    int found = 0;
    param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &doubleVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return doubleVal;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        sprintf(params[paramInd].strVal, "%f", defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

canonical_original_code:
double getDoubleParam(int *paramCnt, struct param **paramPtr, char *paramName, char *readFormat, double defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    double doubleVal;
    int found = 0;
    struct param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &doubleVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return doubleVal;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (struct param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (struct param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        sprintf(params[paramInd].strVal, "%f", defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

variable_types: defaultVal double

variable_types: doubleVal double

user_defined_types: struct param { char name[32]; char strVal[1024]; char format[8]; int accessed; int defaultValUsed; }


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

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

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

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int string_length(char *s)
{
   int c = 0;
   while(*(s+c))
      c++;
   return c;
}

variable_types:
s
char *

variable_types: c int


getStrParam

decompiled_code:
void *__fastcall getStrParam(int *a1, void **a2, const char *a3, const char *a4, char *a5, int a6)
{
int v9; // er13
char *v10; // r15
__int64 v11; // rbx
int v12; // eax
void *v13; // r13
char *v15; // rax
int v16; // edx
char *v17; // rbx
int v18; // eax
void *ptr; // [rsp+18h] [rbp-40h]

v9 = *a1;
ptr = *a2;
if ( *a1 <= 0 )
{
if ( !a6 )
goto LABEL_13;
if ( v9 )
{
LABEL_8:
v15 = (char *)realloc(ptr, 1072LL * (v9 + 1));
*a2 = v15;
}
else
{
v15 = (char *)malloc(0x430uLL);
*a2 = v15;
}
v16 = (*a1)++;
v17 = &v15[1072 * v16];
strcpy(v17, a3);
strcpy(v17 + 32, a5);
*((_QWORD *)v17 + 133) = 0x100000001LL;
strcpy(v17 + 1056, a4);
v18 = string_length(a5);
v13 = malloc(v18);
_isoc99_sscanf(a5, a4, v13);
}
else
{
v10 = (char *)*a2;
v11 = (__int64)*a2 + 1072 * (unsigned int)(v9 - 1) + 1072;
while ( strcmp(v10, a3) )
{
v10 += 1072;
if ( (char *)v11 == v10 )
{
if ( a6 )
goto LABEL_8;
LABEL_13:
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
v12 = string_length(v10 + 32);
v13 = malloc(v12);
_isoc99_sscanf(v10 + 32, a4, v13);
*((_DWORD *)v10 + 266) = 1;
strcpy(v10 + 1056, a4);
}
return v13;
}

original_code:
char * getStrParam(int *paramCnt, param **paramPtr, char *paramName, char *readFormat, char *defaultVal, int useDefaultVal) {
    int iParam;
    int sLen;
    char *outStr;
    int found = 0;
    int paramInd;
    param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sLen = string_length(params[iParam].strVal);
            outStr = (char *)malloc(sizeof(char) * sLen);
            sscanf(params[iParam].strVal, readFormat, outStr);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return outStr;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        strcpy(params[paramInd].strVal, defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        sLen = string_length(defaultVal);
        outStr = (char *)malloc(sizeof(char) * sLen);
 sscanf(defaultVal,readFormat,outStr);
 return outStr;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

canonical_original_code:
char *getStrParam(int *paramCnt, struct param **paramPtr, char *paramName, char *readFormat, char *defaultVal, int useDefaultVal) {
    int iParam;
    int sLen;
    char *outStr;
    int found = 0;
    int paramInd;
    struct param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sLen = string_length(params[iParam].strVal);
            outStr = (char *)malloc(sizeof(char) * sLen);
            sscanf(params[iParam].strVal, readFormat, outStr);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return outStr;
    } else if (useDefaultVal) {
        if (*paramCnt == 0) {
            params = (struct param *) malloc(sizeof(param));
            *paramPtr = params;
        } else {
            params = (struct param *) realloc(params, (sizeof(param) * (*paramCnt + 1)));
            *paramPtr = params;
        }
        (*paramCnt)++;
        paramInd = *paramCnt - 1;
        strcpy(params[paramInd].name, paramName);
        strcpy(params[paramInd].strVal, defaultVal);
        params[paramInd].accessed = 1;
        params[paramInd].defaultValUsed = 1;
        strcpy(params[paramInd].format, readFormat);
        sLen = string_length(defaultVal);
        outStr = (char *)malloc(sizeof(char) * sLen);
 sscanf(defaultVal,readFormat,outStr);
 return outStr;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

variable_types:
paramCnt
int *

variable_types: struct param { char name[32]; char strVal[1024]; char format[8]; int accessed; int defaultValUsed; } **

variable_types:
defaultVal
char *

variable_types:
outStr
char *


getStrWorldfile

decompiled_code:
void *__fastcall getStrWorldfile(int *a1, __int64 *a2, const char *a3, const char *a4, void *a5, int a6)
{
__int64 v9; // rbx
__int64 v11; // rbp
int v12; // eax

v9 = *a2;
if ( *a1 <= 0 )
{
LABEL_6:
if ( !a6 )
{
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
else
{
v11 = v9 + 1072LL * (unsigned int)(*a1 - 1) + 1072;
while ( strcmp((const char *)v9, a3) )
{
v9 += 1072LL;
if ( v9 == v11 )
goto LABEL_6;
}
v12 = string_length((_BYTE *)(v9 + 32));
a5 = malloc(v12);
_isoc99_sscanf(v9 + 32, a4, a5);
*(_DWORD *)(v9 + 1064) = 1;
strcpy((char *)(v9 + 1056), a4);
}
return a5;
}

canonical_decompiled_code:
void *__fastcall func7(int *a1, __int64 *a2, const char *a3, const char *a4, void *a5, int a6)
{
__int64 v9; // rbx
__int64 v11; // rbp
int v12; // eax

v9 = *a2;
if ( *a1 <= 0 )
{
LABEL_6:
if ( !a6 )
{
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
else
{
v11 = v9 + 1072LL * (unsigned int)(*a1 - 1) + 1072;
while ( strcmp((const char *)v9, a3) )
{
v9 += 1072LL;
if ( v9 == v11 )
goto LABEL_6;
}
v12 = func5((_BYTE *)(v9 + 32));
a5 = malloc(v12);
_isoc99_sscanf(v9 + 32, a4, a5);
*(_DWORD *)(v9 + 1064) = 1;
strcpy((char *)(v9 + 1056), a4);
}
return a5;
}

original_code:
char * getStrWorldfile(int *paramCnt, param **paramPtr, char *paramName, char *readFormat, char *defaultVal, int useDefaultVal) {
    int iParam;
    int sLen;
    char *outStr;
    int found = 0;
    int paramInd;
    param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sLen = string_length(params[iParam].strVal);
            outStr = (char *)malloc(sizeof(char) * sLen);
            sscanf(params[iParam].strVal, readFormat, outStr);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return outStr;
    } else if (useDefaultVal) {
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

canonical_original_code:
char *getStrWorldfile(int *paramCnt, struct param **paramPtr, char *paramName, char *readFormat, char *defaultVal, int useDefaultVal) {
    int iParam;
    int sLen;
    char *outStr;
    int found = 0;
    int paramInd;
    struct param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sLen = string_length(params[iParam].strVal);
            outStr = (char *)malloc(sizeof(char) * sLen);
            sscanf(params[iParam].strVal, readFormat, outStr);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return outStr;
    } else if (useDefaultVal) {
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

variable_types:
paramName
char *

variable_types:
readFormat
char *

variable_types: useDefaultVal int


getIntWorldfile

decompiled_code:
int __fastcall getIntWorldfile(int *a1, __int64 *a2, const char *a3, const char *a4, int a5, int a6)
{
__int64 v9; // rbx
__int64 v11; // r14
int result; // eax
int v13; // [rsp+Ch] [rbp-3Ch] BYREF

v9 = *a2;
if ( *a1 <= 0 )
{
LABEL_7:
result = a5;
if ( !a6 )
result = printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
}
else
{
v11 = v9 + 1072LL * (unsigned int)(*a1 - 1) + 1072;
while ( strcmp((const char *)v9, a3) )
{
v9 += 1072LL;
if ( v9 == v11 )
goto LABEL_7;
}
_isoc99_sscanf(v9 + 32, a4, &v13);
*(_DWORD *)(v9 + 1064) = 1;
strcpy((char *)(v9 + 1056), a4);
result = v13;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int *a1, __int64 *a2, const char *a3, const char *a4, int a5, int a6)
{
__int64 v9; // rbx
__int64 v11; // r14
int result; // eax
int v13; // [rsp+Ch] [rbp-3Ch] BYREF

v9 = *a2;
if ( *a1 <= 0 )
{
LABEL_7:
result = a5;
if ( !a6 )
result = printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
}
else
{
v11 = v9 + 1072LL * (unsigned int)(*a1 - 1) + 1072;
while ( strcmp((const char *)v9, a3) )
{
v9 += 1072LL;
if ( v9 == v11 )
goto LABEL_7;
}
_isoc99_sscanf(v9 + 32, a4, &v13);
*(_DWORD *)(v9 + 1064) = 1;
strcpy((char *)(v9 + 1056), a4);
result = v13;
}
return result;
}

original_code:
int getIntWorldfile(int *paramCnt, param **paramPtr , char *paramName, char *readFormat, int defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    int intVal;
    int found = 0;
    param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &intVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return intVal;
    } else if (useDefaultVal) {
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
    }
}

canonical_original_code:
int getIntWorldfile(int *paramCnt, struct param **paramPtr, char *paramName, char *readFormat, int defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    int intVal;
    int found = 0;
    struct param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &intVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return intVal;
    } else if (useDefaultVal) {
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
    }
}

variable_types: defaultVal int

variable_types: iParam int

variable_types: paramInd int

variable_types: sLen int


getFloatWorldfile

decompiled_code:
int __fastcall getFloatWorldfile(int *a1, __int64 *a2, const char *a3, const char *a4, int a5)
{
int result; // eax
__int64 v8; // rbx
__int64 v10; // r13
int v11; // [rsp+0h] [rbp-3Ch] BYREF

result = *a1;
v8 = *a2;
if ( *a1 <= 0 )
{
LABEL_6:
if ( !a5 )
{
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
else
{
v10 = v8 + 1072LL * (unsigned int)(result - 1) + 1072;
while ( 1 )
{
result = strcmp((const char *)v8, a3);
if ( !result )
break;
v8 += 1072LL;
if ( v8 == v10 )
goto LABEL_6;
}
_isoc99_sscanf(v8 + 32, a4, &v11);
*(_DWORD *)(v8 + 1064) = 1;
result = (unsigned int)strcpy((char *)(v8 + 1056), a4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int *a1, __int64 *a2, const char *a3, const char *a4, int a5)
{
int result; // eax
__int64 v8; // rbx
__int64 v10; // r13
int v11; // [rsp+0h] [rbp-3Ch] BYREF

result = *a1;
v8 = *a2;
if ( *a1 <= 0 )
{
LABEL_6:
if ( !a5 )
{
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
else
{
v10 = v8 + 1072LL * (unsigned int)(result - 1) + 1072;
while ( 1 )
{
result = strcmp((const char *)v8, a3);
if ( !result )
break;
v8 += 1072LL;
if ( v8 == v10 )
goto LABEL_6;
}
_isoc99_sscanf(v8 + 32, a4, &v11);
*(_DWORD *)(v8 + 1064) = 1;
result = (unsigned int)strcpy((char *)(v8 + 1056), a4);
}
return result;
}

original_code:
float getFloatWorldfile(int *paramCnt, param **paramPtr , char *paramName, char *readFormat, float defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    float floatVal;
    int found = 0;
    param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &floatVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return floatVal;
    } else if (useDefaultVal) {
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

canonical_original_code:
float getFloatWorldfile(int *paramCnt, struct param **paramPtr, char *paramName, char *readFormat, float defaultVal, int useDefaultVal) {
    int iParam;
    int paramInd;
    int sLen;
    float floatVal;
    int found = 0;
    struct param *params;
    params = *paramPtr;
    for (iParam = 0; iParam < *paramCnt; iParam++) {
        if (strcmp(params[iParam].name, paramName) == 0) {
            found = 1;
            sscanf(params[iParam].strVal, readFormat, &floatVal);
            params[iParam].accessed = 1;
            strcpy(params[iParam].format, readFormat);
            break;
        }
    }
    if (found) {
        return floatVal;
    } else if (useDefaultVal) {
        return defaultVal;
    } else {
        printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", paramName);
 exit(1);
    }
}

variable_types: defaultVal float

variable_types: floatVal float

variable_types: found int