decompiled_code:
__int64 __fastcall add_flow_to_table(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, double a7, __int64 a8, int a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, __int64 a14)
{
unsigned int v16; // er15
int v18; // ebp
int v19; // ecx
__int64 v20; // rsi
float *v23; // [rsp+10h] [rbp-48h] BYREF
int v24; // [rsp+18h] [rbp-40h] BYREF
int v25[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v25[0] = 0;
v24 = 0;
if ( a8 )
{
if ( a11 )
{
if ( a7 >= 0.0 && a7 <= 1.0 )
{
v16 = row_col_to_index(a1, a2, a5, a6, v25);
if ( (_WORD)v16 )
{
v16 = row_col_to_index(a3, a4, a5, a6, &v24);
if ( (_WORD)v16 )
{
v18 = find_patch(
a10,
*(unsigned int *)(a11 + 4LL * v25[0]),
*(unsigned int *)(a13 + 4LL * v25[0]),
*(unsigned int *)(a12 + 4LL * v25[0]));
if ( v18 == -1 )
{
fprintf(
stderr,
"add_flow_to_table:125: Unable to find patch: patchID: %d, zoneID: %d, hillID: %d\n",
*(unsigned int *)(a11 + 4LL * v25[0]),
*(unsigned int *)(a13 + 4LL * v25[0]),
*(unsigned int *)(a12 + 4LL * v25[0]));
exit(1);
}
v19 = find_patch(
a10,
*(unsigned int *)(a11 + 4LL * v24),
*(unsigned int *)(a13 + 4LL * v24),
*(unsigned int *)(a12 + 4LL * v24));
v20 = *(unsigned int *)(a11 + 4LL * v24);
if ( (int)v20 > 0 && *(int *)(a13 + 4LL * v24) > 0 && *(int *)(a12 + 4LL * v24) > 0 )
{
v23 = 0LL;
v16 = create_flow_adjacency(a8, v19, &v23, a7);
if ( (_WORD)v16 )
{
v16 = add_adjacency_to_contributor(a8, v18, (__int64)v23);
if ( (_WORD)v16 )
v16 = 1;
else
fwrite("ERROR: Failed to add receiver adjacency to the contributor.\n", 1uLL, 0x3CuLL, stderr);
}
else
{
fwrite("ERROR: Failed to create receiver adjacency.\n", 1uLL, 0x2CuLL, stderr);
}
if ( a14 && a7 > 0.0 )
++*(_DWORD *)(a14 + 4LL * v24);
}
else
{
printf("Receiver patch %d is outside of basin\n", v20);
v16 = 1;
}
}
else
{
fprintf(stderr, "ERROR: Failed to map receiver row: %d and column %d to an index.\n", a3, a4);
}
}
else
{
fprintf(
stderr,
"ERROR: Failed to map contributor row: %d and column %d to an index.\n",
(unsigned int)a1,
(unsigned int)a2);
}
}
else
{
fwrite("ERROR: The roof proportion is out of range.\n", 1uLL, 0x2CuLL, stderr);
v16 = 0;
}
}
else
{
fwrite("ERROR: Patch pointer is NULL.\n", 1uLL, 0x1EuLL, stderr);
v16 = 0;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
v16 = 0;
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, double a7, __int64 a8, int a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, __int64 a14)
{
unsigned int v16; // er15
int v18; // ebp
int v19; // ecx
__int64 v20; // rsi
float *v23; // [rsp+10h] [rbp-48h] BYREF
int v24; // [rsp+18h] [rbp-40h] BYREF
int v25[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v25[0] = 0;
v24 = 0;
if ( a8 )
{
if ( a11 )
{
if ( a7 >= 0.0 && a7 <= 1.0 )
{
v16 = row_col_to_index(a1, a2, a5, a6, v25);
if ( (_WORD)v16 )
{
v16 = row_col_to_index(a3, a4, a5, a6, &v24);
if ( (_WORD)v16 )
{
v18 = find_patch(
a10,
*(unsigned int *)(a11 + 4LL * v25[0]),
*(unsigned int *)(a13 + 4LL * v25[0]),
*(unsigned int *)(a12 + 4LL * v25[0]));
if ( v18 == -1 )
{
fprintf(
stderr,
"add_flow_to_table:125: Unable to find patch: patchID: %d, zoneID: %d, hillID: %d\n",
*(unsigned int *)(a11 + 4LL * v25[0]),
*(unsigned int *)(a13 + 4LL * v25[0]),
*(unsigned int *)(a12 + 4LL * v25[0]));
exit(1);
}
v19 = find_patch(
a10,
*(unsigned int *)(a11 + 4LL * v24),
*(unsigned int *)(a13 + 4LL * v24),
*(unsigned int *)(a12 + 4LL * v24));
v20 = *(unsigned int *)(a11 + 4LL * v24);
if ( (int)v20 > 0 && *(int *)(a13 + 4LL * v24) > 0 && *(int *)(a12 + 4LL * v24) > 0 )
{
v23 = 0LL;
v16 = func0(a8, v19, &v23, a7);
if ( (_WORD)v16 )
{
v16 = func1(a8, v18, (__int64)v23);
if ( (_WORD)v16 )
v16 = 1;
else
fwrite("ERROR: Failed to add receiver adjacency to the contributor.\n", 1uLL, 0x3CuLL, stderr);
}
else
{
fwrite("ERROR: Failed to create receiver adjacency.\n", 1uLL, 0x2CuLL, stderr);
}
if ( a14 && a7 > 0.0 )
++*(_DWORD *)(a14 + 4LL * v24);
}
else
{
printf("Receiver patch %d is outside of basin\n", v20);
v16 = 1;
}
}
else
{
fprintf(stderr, "ERROR: Failed to map receiver row: %d and column %d to an index.\n", a3, a4);
}
}
else
{
fprintf(
stderr,
"ERROR: Failed to map contributor row: %d and column %d to an index.\n",
(unsigned int)a1,
(unsigned int)a2);
}
}
else
{
fwrite("ERROR: The roof proportion is out of range.\n", 1uLL, 0x2CuLL, stderr);
v16 = 0;
}
}
else
{
fwrite("ERROR: Patch pointer is NULL.\n", 1uLL, 0x1EuLL, stderr);
v16 = 0;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
v16 = 0;
}
return v16;
}

original_code:
bool add_flow_to_table(
    int _contributor_row,
    int _contributor_col,
    int _receiver_row,
    int _receiver_col,
    int _maxr,
    int _maxc,
    struct flow_struct* _flow_table,
    int _num_patches,
    PatchTable_t *_patchTable,
    const int* _patch,
    const int* _hill,
    const int* _zone,
    double _proportion,
    int* const _receiver_out)
{
    bool result = true;
    int contributor_index = 0;
    int receiver_index = 0;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_patch == 0) {
        fprintf(stderr, "ERROR: Patch pointer is NULL.\n");
        result = false;
    } else if(_proportion < 0 || _proportion > 1) {
        fprintf(stderr, "ERROR: The roof proportion is out of range.\n");
        result = false;
    } else if(!row_col_to_index(_contributor_row, _contributor_col, _maxr, _maxc, &contributor_index)) {
        fprintf(stderr, "ERROR: Failed to map contributor row: %d and column %d to an index.\n", _contributor_row, _contributor_col);
        result = false;
    } else if(!row_col_to_index(_receiver_row, _receiver_col, _maxr, _maxc, &receiver_index)) {
        fprintf(stderr, "ERROR: Failed to map receiver row: %d and column %d to an index.\n", _receiver_row, _receiver_col);
        result = false;
    }
    else {
     int contributor_patch = find_patch(_patchTable, _patch[contributor_index], _zone[contributor_index], _hill[contributor_index]);
     if ( contributor_patch == -1 ) {
      fprintf(stderr, "add_flow_to_table:125: Unable to find patch: patchID: %d, zoneID: %d, hillID: %d\n",
       _patch[contributor_index], _zone[contributor_index], _hill[contributor_index]);
      exit(1);
     }
     int receiver_patch = find_patch(_patchTable, _patch[receiver_index], _zone[receiver_index], _hill[receiver_index]);
     if ( (_patch[receiver_index] > 0) && (_zone[receiver_index] > 0) && (_hill[receiver_index] > 0)) {
   struct adj_struct* adjacency = 0;
   if(!create_flow_adjacency(_flow_table, receiver_patch, _proportion, &adjacency)) {
    fprintf(stderr, "ERROR: Failed to create receiver adjacency.\n");
    result = false;
   }
   else if(!add_adjacency_to_contributor(_flow_table, contributor_patch, adjacency)) {
    fprintf(stderr, "ERROR: Failed to add receiver adjacency to the contributor.\n");
    result = false;
   }
   if ( _receiver_out && _proportion > 0 ) {
    _receiver_out[receiver_index] += 1;
   }
     } else {
      printf("Receiver patch %d is outside of basin\n", _patch[receiver_index]);
     }
    }
    return result;
}

canonical_original_code:
short add_flow_to_table(int _contributor_row, int _contributor_col, int _receiver_row, int _receiver_col, int _maxr, int _maxc, struct flow_struct *_flow_table, int _num_patches, struct table_s *_patchTable, int *_patch, int *_hill, int *_zone, double _proportion, int *_receiver_out)
{
    short result = true;
    int contributor_index = 0;
    int receiver_index = 0;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_patch == 0) {
        fprintf(stderr, "ERROR: Patch pointer is NULL.\n");
        result = false;
    } else if(_proportion < 0 || _proportion > 1) {
        fprintf(stderr, "ERROR: The roof proportion is out of range.\n");
        result = false;
    } else if(!row_col_to_index(_contributor_row, _contributor_col, _maxr, _maxc, &contributor_index)) {
        fprintf(stderr, "ERROR: Failed to map contributor row: %d and column %d to an index.\n", _contributor_row, _contributor_col);
        result = false;
    } else if(!row_col_to_index(_receiver_row, _receiver_col, _maxr, _maxc, &receiver_index)) {
        fprintf(stderr, "ERROR: Failed to map receiver row: %d and column %d to an index.\n", _receiver_row, _receiver_col);
        result = false;
    }
    else {
     int contributor_patch = find_patch(_patchTable, _patch[contributor_index], _zone[contributor_index], _hill[contributor_index]);
     if ( contributor_patch == -1 ) {
      fprintf(stderr, "add_flow_to_table:125: Unable to find patch: patchID: %d, zoneID: %d, hillID: %d\n",
       _patch[contributor_index], _zone[contributor_index], _hill[contributor_index]);
      exit(1);
     }
     int receiver_patch = find_patch(_patchTable, _patch[receiver_index], _zone[receiver_index], _hill[receiver_index]);
     if ( (_patch[receiver_index] > 0) && (_zone[receiver_index] > 0) && (_hill[receiver_index] > 0)) {
   struct adj_struct *adjacency = 0;
   if(!create_flow_adjacency(_flow_table, receiver_patch, _proportion, &adjacency)) {
    fprintf(stderr, "ERROR: Failed to create receiver adjacency.\n");
    result = false;
   }
   else if(!add_adjacency_to_contributor(_flow_table, contributor_patch, adjacency)) {
    fprintf(stderr, "ERROR: Failed to add receiver adjacency to the contributor.\n");
    result = false;
   }
   if ( _receiver_out && _proportion > 0 ) {
    _receiver_out[receiver_index] += 1;
   }
     } else {
      printf("Receiver patch %d is outside of basin\n", _patch[receiver_index]);
     }
    }
    return result;
}

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

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

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

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


repo: RHESSys/RHESSys

decompiled_code:
__int64 __fastcall parse_albedo_flag(void *ptr)
{
unsigned int v2; // ebp

if ( !memcmp(ptr, &unk_D8, 3uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, &unk_DC, 3uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "bats", 4uLL) )
{
v2 = 2;
}
else
{
if ( memcmp(ptr, "BATS", 4uLL) )
{
fwrite("\n FATAL ERROR - parse_albedo_flag", 1uLL, 0x21uLL, stderr);
fprintf(stderr, "\n Flag must be age or bats and is %s", (const char *)ptr);
exit(1);
}
v2 = 2;
}
free(ptr);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
unsigned int v2; // ebp

if ( !memcmp(ptr, &unk_D8, 3uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, &unk_DC, 3uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "bats", 4uLL) )
{
v2 = 2;
}
else
{
if ( memcmp(ptr, "BATS", 4uLL) )
{
fwrite("\n FATAL ERROR - parse_albedo_flag", 1uLL, 0x21uLL, stderr);
fprintf(stderr, "\n Flag must be age or bats and is %s", (const char *)ptr);
exit(1);
}
v2 = 2;
}
free(ptr);
return v2;
}

original_code:
int parse_albedo_flag( char *input_string)
{
 int albedo_flag;
 if ((strncmp(input_string,"age",3) == 0) ||
  (strncmp(input_string, "AGE",3) == 0) )
  albedo_flag = 1;
 else if ((strncmp(input_string,"bats",4) == 0) ||
  (strncmp(input_string, "BATS",4) == 0) )
  albedo_flag = 2;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_albedo_flag");
  fprintf(stderr,"\n Flag must be age or bats and is %s" , input_string);
  exit(1);
 }
 free(input_string);
 return(albedo_flag);
}

canonical_original_code:
int parse_albedo_flag(char *input_string)
{
 int albedo_flag;
 if ((strncmp(input_string,"age",3) == 0) ||
  (strncmp(input_string, "AGE",3) == 0) )
  albedo_flag = 1;
 else if ((strncmp(input_string,"bats",4) == 0) ||
  (strncmp(input_string, "BATS",4) == 0) )
  albedo_flag = 2;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_albedo_flag");
  fprintf(stderr,"\n Flag must be age or bats and is %s" , input_string);
  exit(1);
 }
 free(input_string);
 return(albedo_flag);
}

return_type: int


original_code:
struct tec_entry *construct_tec_entry(
           struct date cal_date,
           char *tec_command)
{
 void *alloc( size_t, char *, char *);
 struct tec_entry *event;
 event = (struct tec_entry *) alloc( 1 *
  sizeof(struct tec_entry),"entry","construct_tec_entry");
 event[0].cal_date.year = cal_date.year;
 event[0].cal_date.month = cal_date.month;
 event[0].cal_date.day = cal_date.day;
 event[0].cal_date.hour = cal_date.hour;
 strcpy(event[0].command, tec_command);
 return(event);
}

canonical_original_code:
struct tec_entry *construct_tec_entry(struct date cal_date, char *tec_command)
{
 void *alloc(unsigned long, char *, char *);
 struct tec_entry *event;
 event = (struct tec_entry *) alloc( 1 *
  sizeof(struct tec_entry),"entry","construct_tec_entry");
 event[0].cal_date.year = cal_date.year;
 event[0].cal_date.month = cal_date.month;
 event[0].cal_date.day = cal_date.day;
 event[0].cal_date.hour = cal_date.hour;
 strcpy(event[0].command, tec_command);
 return(event);
}

variable_types:
alloc
void *(unsigned long, char *, char *)

variable_types: struct tec_entry { struct date { long year; long month; long day; long hour; } cal_date; char command[256]; } *

user_defined_types: struct tec_entry { struct date cal_date; char command[256]; }


variable_types: elevation double

variable_types: Pair double

return_type: double


variable_types: cn double

variable_types:
u
double *

variable_types: z double

variable_types:
ga
double *

variable_types: ra double


alloc

decompiled_code:
void *__fastcall alloc(size_t n, const char *a2, const char *a3)
{
void *v4; // rax
void *v5; // rbp

if ( !n )
return 0LL;
v4 = malloc(n);
v5 = v4;
if ( !v4 )
{
fprintf(stderr, "FATAL ERROR: in malloc, unable to allocate %s for %s\n", a2, a3);
exit(1);
}
memset(v4, 0, n);
return v5;
}

canonical_decompiled_code:
void *__fastcall func0(size_t n, const char *a2, const char *a3)
{
void *v4; // rax
void *v5; // rbp

if ( !n )
return 0LL;
v4 = malloc(n);
v5 = v4;
if ( !v4 )
{
fprintf(stderr, "FATAL ERROR: in malloc, unable to allocate %s for %s\n", a2, a3);
exit(1);
}
memset(v4, 0, n);
return v5;
}

original_code:
void *alloc(size_t size, char *array_name, char *calling_function)
{
 void *array;
 if ( size == 0 ){
  return( ((void *)0) );
 }
 else{
  array = malloc(size);
  if ( array == ((void *)0) ){
   fprintf(stderr,
    "FATAL ERROR: in malloc, unable to allocate %s for %s\n",
    array_name, calling_function );
   exit(1);
  }
  else{
   memset(array, 0, size);
   return(array);
  }
 }
}

canonical_original_code:
void *alloc(unsigned long size, char *array_name, char *calling_function)
{
 void *array;
 if ( size == 0 ){
  return( ((void *)0) );
 }
 else{
  array = malloc(size);
  if ( array == ((void *)0) ){
   fprintf(stderr,
    "FATAL ERROR: in malloc, unable to allocate %s for %s\n",
    array_name, calling_function );
   exit(1);
  }
  else{
   memset(array, 0, size);
   return(array);
  }
 }
}

variable_types:
size
unsigned long

variable_types:
array
void *

return_type: void *


decompiled_code:
_BOOL8 __fastcall is_approximately(double a1, double a2, double a3)
{
_BOOL8 result; // rax

if ( a2 + a3 <= a1 )
result = 0LL;
else
result = a1 > a2 - a3;
return result;
}

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

if ( a2 + a3 <= a1 )
result = 0LL;
else
result = a1 > a2 - a3;
return result;
}

original_code:
int is_approximately(const double value,const double target,const double tolerance)
{ return ((value) < ((target) +(tolerance))) && ((value) > ((target) - (tolerance)));}

canonical_original_code:
int is_approximately(double value, double target, double tolerance)
{ return ((value) < ((target) +(tolerance))) && ((value) > ((target) - (tolerance)));}

variable_types: value double

variable_types: target double

variable_types: tolerance double


decompiled_code:
__int64 __fastcall in_list(int a1, __int64 a2, int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
unsigned int v5; // edx

if ( a3 <= 0 )
return 0;
v3 = (unsigned int)(a3 + 1);
v4 = 1LL;
v5 = 0;
do
{
if ( *(_DWORD *)(a2 + 4 * v4) == a1 )
v5 = v4;
++v4;
}
while ( v4 != v3 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3)
{
__int64 v3; // rcx
__int64 v4; // rax
unsigned int v5; // edx

if ( a3 <= 0 )
return 0;
v3 = (unsigned int)(a3 + 1);
v4 = 1LL;
v5 = 0;
do
{
if ( *(_DWORD *)(a2 + 4 * v4) == a1 )
v5 = v4;
++v4;
}
while ( v4 != v3 );
return v5;
}

original_code:
int in_list(int inx, int *list, int num_pit) {
 int i, fnd;
 fnd = 0;
 for (i = 1; i <= num_pit; i++) {
  if (inx == list[i])
   fnd = i;
 }
 return (fnd);
}

canonical_original_code:
int in_list(int inx, int *list, int num_pit) {
 int i; int fnd;
 fnd = 0;
 for (i = 1; i <= num_pit; i++) {
  if (inx == list[i])
   fnd = i;
 }
 return (fnd);
}

variable_types: inx int

variable_types:
list
int *

variable_types: i int

variable_types: fnd int


decompiled_code:
__int64 __fastcall construct_roof_geometry(_QWORD *a1)
{
_DWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = calloc(1uLL, 0x20uLL);
if ( v1 )
{
*v1 = 0x7FFFFFFF;
v1[1] = 0x7FFFFFFF;
*a1 = v1;
result = 1LL;
}
else
{
fwrite("ERROR: Failed allocating memory for a roof geometry.\n", 1uLL, 0x35uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_DWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = calloc(1uLL, 0x20uLL);
if ( v1 )
{
*v1 = 0x7FFFFFFF;
v1[1] = 0x7FFFFFFF;
*a1 = v1;
result = 1LL;
}
else
{
fwrite("ERROR: Failed allocating memory for a roof geometry.\n", 1uLL, 0x35uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool construct_roof_geometry(roof_geometry_t** _rtn_geometry) {
 bool result = true;
 if (_rtn_geometry != 0) {
  roof_geometry_t* geometry = (roof_geometry_t*) calloc(1,
    sizeof(roof_geometry_t));
  if (geometry == 0) {
   fprintf(stderr,
     "ERROR: Failed allocating memory for a roof geometry.\n");
   result = false;
  } else {
   geometry->min_row_ = 0x7fffffff;
   geometry->min_col_ = 0x7fffffff;
   *_rtn_geometry = geometry;
  }
 } else {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 }
 return result;
}

canonical_original_code:
short construct_roof_geometry(struct roof_geometry_s **_rtn_geometry) {
 short result = true;
 if (_rtn_geometry != 0) {
  struct roof_geometry_s *geometry = (roof_geometry_t*) calloc(1,
    sizeof(roof_geometry_t));
  if (geometry == 0) {
   fprintf(stderr,
     "ERROR: Failed allocating memory for a roof geometry.\n");
   result = false;
  } else {
   geometry->min_row_ = 0x7fffffff;
   geometry->min_col_ = 0x7fffffff;
   *_rtn_geometry = geometry;
  }
 } else {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 }
 return result;
}

variable_types: struct roof_geometry_s { int min_row_; int min_col_; int max_row_; int max_col_; int num_squares_; struct roof_square_s { int row_; int col_; struct roof_square_s *next_; } *squares_; } **

variable_types: result short

return_type: short

user_defined_types: struct roof_geometry_s { int min_row_; int min_col_; int max_row_; int max_col_; int num_squares_; struct roof_square_s *squares_; }


decompiled_code:
__int64 __fastcall destroy_roof_geometry(_QWORD **a1)
{
_QWORD *v2; // r12
_QWORD *v3; // rbx
void *v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
v3 = (_QWORD *)v2[3];
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
free(v2);
*a1 = 0LL;
result = 1LL;
}
else
{
fwrite("ERROR: Attempting to destroy NULL roof geometry.\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD **a1)
{
_QWORD *v2; // r12
_QWORD *v3; // rbx
void *v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
v3 = (_QWORD *)v2[3];
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
free(v2);
*a1 = 0LL;
result = 1LL;
}
else
{
fwrite("ERROR: Attempting to destroy NULL roof geometry.\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool destroy_roof_geometry(roof_geometry_t** _rtn_geometry) {
 bool result = true;
 if (_rtn_geometry != 0) {
  roof_geometry_t* geometry = *_rtn_geometry;
  if (geometry == 0) {
   fprintf(stderr,
     "ERROR: Attempting to destroy NULL roof geometry.\n");
   result = false;
  } else {
   roof_square_t* square = geometry->squares_;
   while (result && square != 0) {
    roof_square_t* current_square = square;
    square = square->next_;
    free(current_square);
   }
   if (result) {
    free(geometry);
    *_rtn_geometry = 0;
   }
  }
 } else {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 }
 return result;
}

canonical_original_code:
short destroy_roof_geometry(struct roof_geometry_s **_rtn_geometry) {
 short result = true;
 if (_rtn_geometry != 0) {
  struct roof_geometry_s *geometry = *_rtn_geometry;
  if (geometry == 0) {
   fprintf(stderr,
     "ERROR: Attempting to destroy NULL roof geometry.\n");
   result = false;
  } else {
   struct roof_square_s *square = geometry->squares_;
   while (result && square != 0) {
    struct roof_square_s *current_square = square;
    square = square->next_;
    free(current_square);
   }
   if (result) {
    free(geometry);
    *_rtn_geometry = 0;
   }
  }
 } else {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 }
 return result;
}

variable_types: struct roof_geometry_s { int min_row_; int min_col_; int max_row_; int max_col_; int num_squares_; struct roof_square_s { int row_; int col_; struct roof_square_s *next_; } *squares_; } *


decompiled_code:
__int64 __fastcall add_roof_square(__int64 a1, int a2, int a3)
{
unsigned int v3; // ebp
__int64 v4; // rax
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) < a2 )
*(_DWORD *)(a1 + 8) = a2;
if ( *(_DWORD *)a1 > a2 )
*(_DWORD *)a1 = a2;
if ( *(_DWORD *)(a1 + 12) < a3 )
*(_DWORD *)(a1 + 12) = a3;
if ( *(_DWORD *)(a1 + 4) > a3 )
*(_DWORD *)(a1 + 4) = a3;
v6[0] = 0LL;
v3 = construct_roof_square(a2, a3, v6);
if ( (_WORD)v3 )
{
v4 = v6[0];
*(_QWORD *)(v6[0] + 8) = *(_QWORD *)(a1 + 24);
++*(_DWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = v4;
v3 = 1;
}
else
{
fwrite("ERROR: Failed to construct a new roof square.\n", 1uLL, 0x2EuLL, stderr);
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
unsigned int v3; // ebp
__int64 v4; // rax
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) < a2 )
*(_DWORD *)(a1 + 8) = a2;
if ( *(_DWORD *)a1 > a2 )
*(_DWORD *)a1 = a2;
if ( *(_DWORD *)(a1 + 12) < a3 )
*(_DWORD *)(a1 + 12) = a3;
if ( *(_DWORD *)(a1 + 4) > a3 )
*(_DWORD *)(a1 + 4) = a3;
v6[0] = 0LL;
v3 = func0(a2, a3, v6);
if ( (_WORD)v3 )
{
v4 = v6[0];
*(_QWORD *)(v6[0] + 8) = *(_QWORD *)(a1 + 24);
++*(_DWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) = v4;
v3 = 1;
}
else
{
fwrite("ERROR: Failed to construct a new roof square.\n", 1uLL, 0x2EuLL, stderr);
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
v3 = 0;
}
return v3;
}

original_code:
bool add_roof_square(roof_geometry_t* _roof_geometry, int _row, int _col) {
 bool result = true;
 if (_roof_geometry != 0) {
  if (_row > _roof_geometry->max_row_) {
   _roof_geometry->max_row_ = _row;
  }
  if (_row < _roof_geometry->min_row_) {
   _roof_geometry->min_row_ = _row;
  }
  if (_col > _roof_geometry->max_col_) {
   _roof_geometry->max_col_ = _col;
  }
  if (_col < _roof_geometry->min_col_) {
   _roof_geometry->min_col_ = _col;
  }
  roof_square_t* square = 0;
  if (!construct_roof_square(_row, _col, &square)) {
   fprintf(stderr, "ERROR: Failed to construct a new roof square.\n");
   result = false;
  } else {
   square->next_ = _roof_geometry->squares_;
   ++(_roof_geometry->num_squares_);
   _roof_geometry->squares_ = square;
  }
 } else {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 }
 return result;
}

canonical_original_code:
short add_roof_square(struct roof_geometry_s *_roof_geometry, int _row, int _col) {
 short result = true;
 if (_roof_geometry != 0) {
  if (_row > _roof_geometry->max_row_) {
   _roof_geometry->max_row_ = _row;
  }
  if (_row < _roof_geometry->min_row_) {
   _roof_geometry->min_row_ = _row;
  }
  if (_col > _roof_geometry->max_col_) {
   _roof_geometry->max_col_ = _col;
  }
  if (_col < _roof_geometry->min_col_) {
   _roof_geometry->min_col_ = _col;
  }
  struct roof_square_s *square = 0;
  if (!construct_roof_square(_row, _col, &square)) {
   fprintf(stderr, "ERROR: Failed to construct a new roof square.\n");
   result = false;
  } else {
   square->next_ = _roof_geometry->squares_;
   ++(_roof_geometry->num_squares_);
   _roof_geometry->squares_ = square;
  }
 } else {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 }
 return result;
}

variable_types: struct roof_square_s { int row_; int col_; struct roof_square_s *next_; } *


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

if ( a1 )
{
if ( a2 )
{
*a2 = *a1;
result = 1LL;
}
else
{
fwrite("ERROR: Return row pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof square pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
*a2 = *a1;
result = 1LL;
}
else
{
fwrite("ERROR: Return row pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof square pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool roof_square_row(roof_square_t* _square, int* _rtn_row) {
 bool result = true;
 if (_square == 0) {
  fprintf(stderr, "ERROR: Roof square pointer is NULL.\n");
  result = false;
 } else if (_rtn_row == 0) {
  fprintf(stderr, "ERROR: Return row pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_row = _square->row_;
 }
 return result;
}

canonical_original_code:
short roof_square_row(struct roof_square_s *_square, int *_rtn_row) {
 short result = true;
 if (_square == 0) {
  fprintf(stderr, "ERROR: Roof square pointer is NULL.\n");
  result = false;
 } else if (_rtn_row == 0) {
  fprintf(stderr, "ERROR: Return row pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_row = _square->row_;
 }
 return result;
}

user_defined_types: struct roof_square_s { int row_; int col_; struct roof_square_s *next_; }


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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_DWORD *)(a1 + 4);
result = 1LL;
}
else
{
fwrite("ERROR: Return col pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof square pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_DWORD *)(a1 + 4);
result = 1LL;
}
else
{
fwrite("ERROR: Return col pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof square pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool roof_square_col(roof_square_t* _square, int* _rtn_col) {
 bool result = true;
 if (_square == 0) {
  fprintf(stderr, "ERROR: Roof square pointer is NULL.\n");
  result = false;
 } else if (_rtn_col == 0) {
  fprintf(stderr, "ERROR: Return col pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_col = _square->col_;
 }
 return result;
}

canonical_original_code:
short roof_square_col(struct roof_square_s *_square, int *_rtn_col) {
 short result = true;
 if (_square == 0) {
  fprintf(stderr, "ERROR: Roof square pointer is NULL.\n");
  result = false;
 } else if (_rtn_col == 0) {
  fprintf(stderr, "ERROR: Return col pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_col = _square->col_;
 }
 return result;
}


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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 8);
result = 1LL;
}
else
{
fwrite("ERROR: Return next pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof square pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 8);
result = 1LL;
}
else
{
fwrite("ERROR: Return next pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof square pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool roof_square_next(roof_square_t* _square, roof_square_t** _rtn_next) {
 bool result = true;
 if (_square == 0) {
  fprintf(stderr, "ERROR: Roof square pointer is NULL.\n");
  result = false;
 } else if (_rtn_next == 0) {
  fprintf(stderr, "ERROR: Return next pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_next = _square->next_;
 }
 return result;
}

canonical_original_code:
short roof_square_next(struct roof_square_s *_square, struct roof_square_s **_rtn_next) {
 short result = true;
 if (_square == 0) {
  fprintf(stderr, "ERROR: Roof square pointer is NULL.\n");
  result = false;
 } else if (_rtn_next == 0) {
  fprintf(stderr, "ERROR: Return next pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_next = _square->next_;
 }
 return result;
}


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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 24);
result = 1LL;
}
else
{
fwrite("ERROR: Return next pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 24);
result = 1LL;
}
else
{
fwrite("ERROR: Return next pointer is NULL.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Roof geometry pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool roof_geometry_squares(roof_geometry_t* _geometry,
  roof_square_t** _rtn_squares) {
 bool result = true;
 if (_geometry == 0) {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 } else if (_rtn_squares == 0) {
  fprintf(stderr, "ERROR: Return next pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_squares = _geometry->squares_;
 }
 return result;
}

canonical_original_code:
short roof_geometry_squares(struct roof_geometry_s *_geometry, struct roof_square_s **_rtn_squares) {
 short result = true;
 if (_geometry == 0) {
  fprintf(stderr, "ERROR: Roof geometry pointer is NULL.\n");
  result = false;
 } else if (_rtn_squares == 0) {
  fprintf(stderr, "ERROR: Return next pointer is NULL.\n");
  result = false;
 } else {
  *_rtn_squares = _geometry->squares_;
 }
 return result;
}


canonical_original_code:
double compute_ra_understory(int verbose_flag, double cn, double *u, double h_o, double h_u, double *ga)
{
 double d_o; double d_u;
 double zo_o; double zo_u;
 double ra;
 double ra_u;
 ra = 1/(*ga);
 d_o = 0.7 * h_o;
 d_u = 0.7 * h_u;
 zo_o = 0.1 * h_o;
 zo_u = 0.1 * h_u;
 if ( h_o < d_o ){
  fprintf(stderr,
   "FATAL ERROR: screen height < zero plane stratum\n");
  exit(1);
 }
 ra_u = ra + log ( (h_o-d_o)/zo_o ) * h_o * exp(-1*cn)
  * ( exp(-1*cn*(d_u+zo_u)/h_o) - exp(-1*cn*(d_o+zo_o)/h_o))
  / ( *u * 0.41 * 0.41 * cn * (h_o - d_o));
 *u = (((*u * exp(cn*(((h_u) > (0.1*h_o) ? (h_u) : (0.1*h_o))/h_o - 1)))) > (0.0) ? ((*u * exp(cn*(((h_u) > (0.1*h_o) ? (h_u) : (0.1*h_o))/h_o - 1)))) : (0.0));
 if ( h_u <= 0.1*h_o )
  ra_u += pow(log( (0.1*h_o)/ ((zo_u) > (0.01) ? (zo_u) : (0.01))),2.0) / (*u * 0.41*0.41);
 *ga = 1/ra_u;
 return(ra);
}

variable_types: cn double

variable_types:
u
double *


variable_types:
idum
long *

variable_types: j int

variable_types: k long

variable_types: iy long

variable_types:
iv
long [32]

variable_types: temp float

return_type: float


gasdev

original_code:
float gasdev ()
{
 static int iset=0;
 static float gset;
 float fac,rsq,v1,v2;
  if (iset == 0) {
  do {
   v1=2.0*rand()/(2147483647 +1.0)-1.0;
   v2=2.0*rand()/(2147483647 +1.0)-1.0;
   rsq=v1*v1+v2*v2;
   } while (rsq >= 1.0 || rsq == 0.0);
   fac=sqrt(-2.0*log(rsq)/rsq);
   gset=v1*fac;
   iset=1;
   return v2*fac;
  } else {
   iset=0;
   return gset;
  }
 }

canonical_original_code:
float gasdev()
{
 static int iset = 0;
 static float gset;
 float fac; float rsq; float v1; float v2;
  if (iset == 0) {
  do {
   v1=2.0*rand()/(2147483647 +1.0)-1.0;
   v2=2.0*rand()/(2147483647 +1.0)-1.0;
   rsq=v1*v1+v2*v2;
   } while (rsq >= 1.0 || rsq == 0.0);
   fac=sqrt(-2.0*log(rsq)/rsq);
   gset=v1*fac;
   iset=1;
   return v2*fac;
  } else {
   iset=0;
   return gset;
  }
 }

variable_types: iset int

variable_types: gset float

variable_types: fac float

variable_types: rsq float


normdist

decompiled_code:
double __fastcall normdist(double a1, double a2)
{
return gasdev() * a2 + a1;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
return func1() * a2 + a1;
}

original_code:
double normdist(double mean, double std)
{
 double result;
 float gasdev();
 result = gasdev()*std+mean;
 return(result);
}

variable_types: mean double

variable_types: std double

variable_types: result double

variable_types:
gasdev
float ()


unifdist

decompiled_code:
double __fastcall unifdist(double a1, double a2)
{
int v2; // eax
double result; // xmm0_8
double v5; // [rsp+8h] [rbp-10h]

v5 = a1;
v2 = rand();
result = 0.0;
if ( a2 - a1 > 0.0 )
result = (double)v2 * 4.656612873077393e-10 * (a2 - v5) + a1;
return result;
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2)
{
int v2; // eax
double result; // xmm0_8
double v5; // [rsp+8h] [rbp-10h]

v5 = a1;
v2 = rand();
result = 0.0;
if ( a2 - a1 > 0.0 )
result = (double)v2 * 4.656612873077393e-10 * (a2 - v5) + a1;
return result;
}

original_code:
double unifdist(double min, double max)
{
 double result, range;
    int random_integer = rand();
  range = max-min;
 if (range > 0)
  result = random_integer/(2147483647 +1.0)*range+min;
 else
  result = 0;
 return(result);
}

canonical_original_code:
double unifdist(double min, double max)
{
 double result; double range;
    int random_integer = rand();
  range = max-min;
 if (range > 0)
  result = random_integer/(2147483647 +1.0)*range+min;
 else
  result = 0;
 return(result);
}

variable_types: min double

variable_types: max double

variable_types: range double


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


decompiled_code:
unsigned __int64 __fastcall sort_flow_table(__int64 a1, __int64 a2, __int64 a3)
{
signed int *v3; // rbx
int v4; // er12
int v5; // er13
signed int v6; // er14
int v7; // ebp
unsigned int v8; // ecx
signed int v9; // eax
__int64 v10; // rdx

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

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
signed int *v3; // rbx
int v4; // er12
int v5; // er13
signed int v6; // er14
int v7; // ebp
unsigned int v8; // ecx
signed int v9; // eax
__int64 v10; // rdx

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

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


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


newStringList

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

v1 = (char **)malloc(0x10uLL);
if ( !v1 )
_assert_fail("l", "util/string_list.c", 0x10u, "newStringList");
v2 = v1;
v1[1] = 0LL;
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; // rbx
size_t v3; // r12
char *v4; // rax

v1 = (char **)malloc(0x10uLL);
if ( !v1 )
_assert_fail("l", "util/string_list.c", 0x10u, "newStringList");
v2 = v1;
v1[1] = 0LL;
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:
__int64 __fastcall freeStringList(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
free(*(void **)a1);
free((void *)a1);
result = freeStringList(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
free(*(void **)a1);
free((void *)a1);
result = func1(v1);
}
return result;
}

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)
{
_DWORD *v13; // rax
__int64 result; // rax

if ( a9 )
{
v13 = calloc(1uLL, 0x38uLL);
if ( v13 )
{
*v13 = a1;
v13[1] = a2;
*((_QWORD *)v13 + 1) = a3;
*((_QWORD *)v13 + 2) = a4;
*((_QWORD *)v13 + 3) = a5;
*((_QWORD *)v13 + 4) = a6;
*((_QWORD *)v13 + 5) = a7;
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)
{
_DWORD *v13; // rax
__int64 result; // rax

if ( a9 )
{
v13 = calloc(1uLL, 0x38uLL);
if ( v13 )
{
*v13 = a1;
v13[1] = a2;
*((_QWORD *)v13 + 1) = a3;
*((_QWORD *)v13 + 2) = a4;
*((_QWORD *)v13 + 3) = a5;
*((_QWORD *)v13 + 4) = a6;
*((_QWORD *)v13 + 5) = a7;
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_; } *


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 )
{
result = row_col_to_index(a1, a2, *a5, a5[1], &v12);
if ( (_WORD)result )
{
result = row_col_to_index(a3, a4, *a5, a5[1], v13);
if ( (_WORD)result )
{
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
{
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 )
{
result = row_col_to_index(a1, a2, *a5, a5[1], &v12);
if ( (_WORD)result )
{
result = row_col_to_index(a3, a4, *a5, a5[1], v13);
if ( (_WORD)result )
{
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
{
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 )
{
result = row_col_to_index(a1, a2, *a5, a5[1], &v13);
if ( (_WORD)result )
{
result = row_col_to_index(a3, a4, *a5, a5[1], v14);
if ( (_WORD)result )
{
*a6 = a1;
*a7 = a2;
v12 = *((_QWORD *)a5 + 3);
result = 1LL;
if ( v12 )
{
if ( *(_DWORD *)(v12 + 4LL * v13) != 1 && *(_DWORD *)(v12 + 4LL * v14[0]) == 1 )
{
*a6 = a3;
*a7 = a4;
result = 1LL;
}
}
}
}
}
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 )
{
result = row_col_to_index(a1, a2, *a5, a5[1], &v13);
if ( (_WORD)result )
{
result = row_col_to_index(a3, a4, *a5, a5[1], v14);
if ( (_WORD)result )
{
*a6 = a1;
*a7 = a2;
v12 = *((_QWORD *)a5 + 3);
result = 1LL;
if ( v12 )
{
if ( *(_DWORD *)(v12 + 4LL * v13) != 1 && *(_DWORD *)(v12 + 4LL * v14[0]) == 1 )
{
*a6 = a3;
*a7 = a4;
result = 1LL;
}
}
}
}
}
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; } *


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


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

if ( !memcmp(ptr, "DECIDUOUS", 5uLL) )
{
v3 = 1;
}
else if ( !memcmp(ptr, "deciduous", 5uLL) )
{
v3 = 1;
}
else
{
v2 = memcmp(ptr, "EVERGREEN", 9uLL) == 0;
v3 = !v2;
if ( !v2 )
{
v2 = memcmp(ptr, "evergreen", 9uLL) == 0;
v3 = !v2;
if ( !v2 )
{
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 v3;
}

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

if ( !memcmp(ptr, "DECIDUOUS", 5uLL) )
{
v3 = 1;
}
else if ( !memcmp(ptr, "deciduous", 5uLL) )
{
v3 = 1;
}
else
{
v2 = memcmp(ptr, "EVERGREEN", 9uLL) == 0;
v3 = !v2;
if ( !v2 )
{
v2 = memcmp(ptr, "evergreen", 9uLL) == 0;
v3 = !v2;
if ( !v2 )
{
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 v3;
}

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:
__int64 __fastcall compute_lwp_predawn(__int64 a1, __int64 a2)
{
return compute_soil_water_potential(a1, a2);
}

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

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 )
{
if ( a2 < 0 )
{
fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", (unsigned int)a2);
result = 0LL;
}
else
{
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
{
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 )
{
if ( a2 < 0 )
{
fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", (unsigned int)a2);
result = 0LL;
}
else
{
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
{
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; // r12
__int64 v3; // rbx
__int64 result; // rax
float *v5; // rbp
float *v6; // rdi
float *v7; // r13

if ( a1 )
{
if ( a2 < 0 )
{
fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", (unsigned int)a2);
result = 0LL;
}
else
{
v2 = a1 + 160LL * a2;
v3 = *(_QWORD *)(v2 + 128);
result = 1LL;
if ( v3 )
{
do
{
v6 = *(float **)(v3 + 48);
if ( !v6 )
return 1LL;
v5 = (float *)v3;
do
{
if ( *(_QWORD *)v3 == *(_QWORD *)v6 && *(_DWORD *)(v3 + 8) == *((_DWORD *)v6 + 2) )
{
*(float *)(v3 + 36) = *(float *)(v3 + 36) + v6[9];
v7 = (float *)*((_QWORD *)v6 + 6);
*((_QWORD *)v5 + 6) = v7;
free(v6);
--*(_DWORD *)(v2 + 96);
v6 = v7;
}
else
{
v5 = v6;
v6 = (float *)*((_QWORD *)v6 + 6);
}
}
while ( v6 );
v3 = *(_QWORD *)(v3 + 48);
}
while ( v3 );
result = 1LL;
}
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 v2; // r12
__int64 v3; // rbx
__int64 result; // rax
float *v5; // rbp
float *v6; // rdi
float *v7; // r13

if ( a1 )
{
if ( a2 < 0 )
{
fprintf(stderr, "ERROR: Patch index, %d, is less than zero.\n", (unsigned int)a2);
result = 0LL;
}
else
{
v2 = a1 + 160LL * a2;
v3 = *(_QWORD *)(v2 + 128);
result = 1LL;
if ( v3 )
{
do
{
v6 = *(float **)(v3 + 48);
if ( !v6 )
return 1LL;
v5 = (float *)v3;
do
{
if ( *(_QWORD *)v3 == *(_QWORD *)v6 && *(_DWORD *)(v3 + 8) == *((_DWORD *)v6 + 2) )
{
*(float *)(v3 + 36) = *(float *)(v3 + 36) + v6[9];
v7 = (float *)*((_QWORD *)v6 + 6);
*((_QWORD *)v5 + 6) = v7;
free(v6);
--*(_DWORD *)(v2 + 96);
v6 = v7;
}
else
{
v5 = v6;
v6 = (float *)*((_QWORD *)v6 + 6);
}
}
while ( v6 );
v3 = *(_QWORD *)(v3 + 48);
}
while ( v3 );
result = 1LL;
}
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

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; // rbp
unsigned int v3; // ebx
__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; // rbp
unsigned int v3; // ebx
__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


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 *