printPatchHashTable

decompiled_code:
int __fastcall printPatchHashTable(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbp
const void **v2; // rbx
int result; // eax
unsigned int *i; // rbx

if ( *a1 )
{
v1 = 0LL;
do
{
v2 = (const void **)(a1[2] + 24 * v1);
result = fprintf(
stderr,
"Entry %d: originKey: %d, %d, %d; value: %d; next: %p\n",
v1,
*(unsigned int *)v2,
*((unsigned int *)v2 + 2),
*((unsigned int *)v2 + 1),
*((unsigned int *)v2 + 3),
v2[2]);
for ( i = (unsigned int *)v2[2]; i; i = (unsigned int *)*((_QWORD *)i + 2) )
result = fprintf(
stderr,
"\tEntry %d: originKey: %d, %d, %d; value: %d; next: %p\n",
v1,
*i,
i[2],
i[1],
i[3],
*((const void **)i + 2));
++v1;
}
while ( *a1 > v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbp
const void **v2; // rbx
int result; // eax
unsigned int *i; // rbx

if ( *a1 )
{
v1 = 0LL;
do
{
v2 = (const void **)(a1[2] + 24 * v1);
result = fprintf(
stderr,
"Entry %d: originKey: %d, %d, %d; value: %d; next: %p\n",
v1,
*(unsigned int *)v2,
*((unsigned int *)v2 + 2),
*((unsigned int *)v2 + 1),
*((unsigned int *)v2 + 3),
v2[2]);
for ( i = (unsigned int *)v2[2]; i; i = (unsigned int *)*((_QWORD *)i + 2) )
result = fprintf(
stderr,
"\tEntry %d: originKey: %d, %d, %d; value: %d; next: %p\n",
v1,
*i,
i[2],
i[1],
i[3],
*((const void **)i + 2));
++v1;
}
while ( *a1 > v1 );
}
return result;
}

original_code:
void printPatchHashTable(PatchTable_t *table) {
 PatchTableEntry_t *entry;
 PatchTableEntry_t *tmpEntry;
 size_t size = sizeof(PatchTableEntry_t);
 for (size_t i = 0; i < table->tableSize; i++) {
  entry = table->entries + i;
  fprintf(stderr, "Entry %d: originKey: %d, %d, %d; value: %d; next: %p\n", i,
    entry->originKey.patchID, entry->originKey.hillID,
    entry->originKey.zoneID, entry->value, entry->next);
  tmpEntry = entry->next;
  while (tmpEntry != ((void *)0) ) {
   entry = tmpEntry;
   fprintf(stderr, "\tEntry %d: originKey: %d, %d, %d; value: %d; next: %p\n", i,
     entry->originKey.patchID, entry->originKey.hillID,
     entry->originKey.zoneID, entry->value, entry->next);
   tmpEntry = entry->next;
  }
 }
}

canonical_original_code:
void printPatchHashTable(struct table_s *table) {
 struct table_entry_s *entry;
 struct table_entry_s *tmpEntry;
 unsigned long size = sizeof(PatchTableEntry_t);
 for (unsigned long i = 0; i < table->tableSize; i++) {
  entry = table->entries + i;
  fprintf(stderr, "Entry %d: originKey: %d, %d, %d; value: %d; next: %p\n", i,
    entry->originKey.patchID, entry->originKey.hillID,
    entry->originKey.zoneID, entry->value, entry->next);
  tmpEntry = entry->next;
  while (tmpEntry != ((void *)0) ) {
   entry = tmpEntry;
   fprintf(stderr, "\tEntry %d: originKey: %d, %d, %d; value: %d; next: %p\n", i,
     entry->originKey.patchID, entry->originKey.hillID,
     entry->originKey.zoneID, entry->value, entry->next);
   tmpEntry = entry->next;
  }
 }
}

user_defined_types: struct key_s { int patchID; int zoneID; int hillID; }


repo: RHESSys/RHESSys

decompiled_code:
__int64 __fastcall verify_num_adjacent_for_patch(__int64 a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__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 = 160LL * a2 + a1;
v3 = *(_QWORD *)(v2 + 128);
if ( v3 )
{
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)(v4 + 1);
v3 = *(_QWORD *)(v3 + 48);
}
while ( v3 );
}
else
{
v4 = 0LL;
}
v5 = *(unsigned int *)(v2 + 96);
result = 1LL;
if ( (_DWORD)v5 != (_DWORD)v4 )
{
fprintf(
stderr,
"ERROR: The number of adjacencies in the list, %d, does not match the patches num_adjacent field, %d.\n",
v4,
v5);
result = 0LL;
}
}
}
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; // rdi
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__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 = 160LL * a2 + a1;
v3 = *(_QWORD *)(v2 + 128);
if ( v3 )
{
LODWORD(v4) = 0;
do
{
v4 = (unsigned int)(v4 + 1);
v3 = *(_QWORD *)(v3 + 48);
}
while ( v3 );
}
else
{
v4 = 0LL;
}
v5 = *(unsigned int *)(v2 + 96);
result = 1LL;
if ( (_DWORD)v5 != (_DWORD)v4 )
{
fprintf(
stderr,
"ERROR: The number of adjacencies in the list, %d, does not match the patches num_adjacent field, %d.\n",
v4,
v5);
result = 0LL;
}
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool verify_num_adjacent_for_patch(
    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 {
        int num_adjacent = 0;
        for(struct adj_struct* adjacency = _flow_table[_patch].adj_list; result && adjacency; adjacency = adjacency->next) {
            ++num_adjacent;
        }
        if(num_adjacent != _flow_table[_patch].num_adjacent) {
            fprintf(stderr, "ERROR: The number of adjacencies in the list, %d, does not match the patches num_adjacent field, %d.\n",
                    num_adjacent, _flow_table[_patch].num_adjacent);
            result = false;
        }
    }
    return result;
}

canonical_original_code:
short verify_num_adjacent_for_patch(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 {
        int num_adjacent = 0;
        for(struct adj_struct *adjacency = _flow_table[_patch].adj_list; result && adjacency; adjacency = adjacency->next) {
            ++num_adjacent;
        }
        if(num_adjacent != _flow_table[_patch].num_adjacent) {
            fprintf(stderr, "ERROR: The number of adjacencies in the list, %d, does not match the patches num_adjacent field, %d.\n",
                    num_adjacent, _flow_table[_patch].num_adjacent);
            result = false;
        }
    }
    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

return_type: short

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


decompiled_code:
__int64 __fastcall verify_num_adjacent(__int64 a1, int a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx

if ( a1 )
{
if ( a2 < 0 )
{
fprintf(stderr, "ERROR: Number of patches, %d, is less than zero.\n", (unsigned int)a2);
v3 = 0;
}
else
{
v2 = 0;
v3 = 1;
if ( a2 > 0 )
{
do
{
v3 = verify_num_adjacent_for_patch(a1, v2);
if ( !(_WORD)v3 )
{
fprintf(stderr, "ERROR: Patch, %d, has adjacency and num_adjacent mismatch.\n", v2);
return v3;
}
++v2;
}
while ( a2 != v2 );
v3 = 1;
}
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx

if ( a1 )
{
if ( a2 < 0 )
{
fprintf(stderr, "ERROR: Number of patches, %d, is less than zero.\n", (unsigned int)a2);
v3 = 0;
}
else
{
v2 = 0;
v3 = 1;
if ( a2 > 0 )
{
do
{
v3 = func0(a1, v2);
if ( !(_WORD)v3 )
{
fprintf(stderr, "ERROR: Patch, %d, has adjacency and num_adjacent mismatch.\n", v2);
return v3;
}
++v2;
}
while ( a2 != v2 );
v3 = 1;
}
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
v3 = 0;
}
return v3;
}

original_code:
bool verify_num_adjacent(
    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(!verify_num_adjacent_for_patch(_flow_table, index)) {
                fprintf(stderr, "ERROR: Patch, %d, has adjacency and num_adjacent mismatch.\n", index);
                result = false;
            }
        }
    }
    return result;
}

canonical_original_code:
short verify_num_adjacent(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(!verify_num_adjacent_for_patch(_flow_table, index)) {
                fprintf(stderr, "ERROR: Patch, %d, has adjacency and num_adjacent mismatch.\n", index);
                result = false;
            }
        }
    }
    return result;
}

variable_types: index int

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

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


original_code:
void zero_flow_table(struct flow_struct *flow_table, int maxr, int maxc) {
 int r, c;
 int inx;
 for (r = 0; r < maxr; r++) {
  for (c = 0; c < maxc; c++) {
   inx = r * maxc + c;
   flow_table[inx].patchID = -99999;
   flow_table[inx].zoneID = -99999;
   flow_table[inx].hillID = -99999;
   flow_table[inx].ID_order = -99999;
   flow_table[inx].area = 0;
   flow_table[inx].x = 0.0;
   flow_table[inx].y = 0.0;
   flow_table[inx].z = 0.0;
   flow_table[inx].land = 0;
   flow_table[inx].flna = 0.0;
   flow_table[inx].total_gamma = 0.0;
   flow_table[inx].acc_area = 0.0;
   flow_table[inx].path_length = 0.0;
   flow_table[inx].num_adjacent = 0;
  }
 }
 return;
}

canonical_original_code:
void zero_flow_table(struct flow_struct *flow_table, int maxr, int maxc) {
 int r; int c;
 int inx;
 for (r = 0; r < maxr; r++) {
  for (c = 0; c < maxc; c++) {
   inx = r * maxc + c;
   flow_table[inx].patchID = -99999;
   flow_table[inx].zoneID = -99999;
   flow_table[inx].hillID = -99999;
   flow_table[inx].ID_order = -99999;
   flow_table[inx].area = 0;
   flow_table[inx].x = 0.0;
   flow_table[inx].y = 0.0;
   flow_table[inx].z = 0.0;
   flow_table[inx].land = 0;
   flow_table[inx].flna = 0.0;
   flow_table[inx].total_gamma = 0.0;
   flow_table[inx].acc_area = 0.0;
   flow_table[inx].path_length = 0.0;
   flow_table[inx].num_adjacent = 0;
  }
 }
 return;
}

variable_types: maxr int

variable_types: maxc int

variable_types: r int

variable_types: c int

variable_types: inx int

return_type: void


original_code:
int zero_stratum_daily_flux(
       struct cdayflux_struct *cdf,
       struct ndayflux_struct *ndf)
{
 int ok=1;
 cdf->psn_to_cpool = 0.0;
 cdf->leafc_transfer_to_leafc = 0.0;
 cdf->frootc_transfer_to_frootc = 0.0;
 cdf->livestemc_transfer_to_livestemc = 0.0;
 cdf->deadstemc_transfer_to_deadstemc = 0.0;
 cdf->livecrootc_transfer_to_livecrootc = 0.0;
 cdf->deadcrootc_transfer_to_deadcrootc = 0.0;
 cdf->livestemc_to_deadstemc = 0.0;
 cdf->livecrootc_to_deadcrootc = 0.0;
 cdf->added_carbon = 0.0;
 cdf->cpool_to_leafc = 0.0;
 cdf->cpool_to_leafc_store = 0.0;
 cdf->cpool_to_frootc = 0.0;
 cdf->cpool_to_frootc_store = 0.0;
 cdf->cpool_to_livestemc = 0.0;
 cdf->cpool_to_livestemc_store = 0.0;
 cdf->cpool_to_deadstemc = 0.0;
 cdf->cpool_to_deadstemc_store = 0.0;
 cdf->cpool_to_livecrootc = 0.0;
 cdf->cpool_to_livecrootc_store = 0.0;
 cdf->cpool_to_deadcrootc = 0.0;
 cdf->cpool_to_deadcrootc_store = 0.0;
 cdf->cpool_to_gresp_store = 0.0;
 cdf->leafc_store_to_leafc_transfer = 0.0;
 cdf->frootc_store_to_frootc_transfer = 0.0;
 cdf->livestemc_store_to_livestemc_transfer = 0.0;
 cdf->deadstemc_store_to_deadstemc_transfer = 0.0;
 cdf->livecrootc_store_to_livecrootc_transfer = 0.0;
 cdf->deadcrootc_store_to_deadcrootc_transfer = 0.0;
 cdf->gresp_store_to_gresp_transfer = 0.0;
 cdf->storage_transfer_prop = 0.0;
 cdf->carbohydrate_transfer = 0.0;
 cdf->leaf_day_mr = 0.0;
 cdf->leaf_night_mr = 0.0;
 cdf->froot_mr = 0.0;
 cdf->livestem_mr = 0.0;
 cdf->livecroot_mr = 0.0;
  cdf->total_mr = 0.0;
 cdf->transfer_leaf_gr = 0.0;
 cdf->cpool_froot_gr = 0.0;
 cdf->transfer_froot_gr = 0.0;
 cdf->cpool_livestem_gr = 0.0;
 cdf->transfer_livestem_gr = 0.0;
 cdf->cpool_deadstem_gr = 0.0;
 cdf->transfer_deadstem_gr = 0.0;
 cdf->cpool_livecroot_gr = 0.0;
 cdf->transfer_livecroot_gr = 0.0;
 cdf->cpool_deadcroot_gr = 0.0;
 cdf->transfer_deadcroot_gr = 0.0;
 ndf->leafn_transfer_to_leafn = 0.0;
 ndf->frootn_transfer_to_frootn = 0.0;
 ndf->livestemn_transfer_to_livestemn = 0.0;
 ndf->deadstemn_transfer_to_deadstemn = 0.0;
 ndf->livecrootn_transfer_to_livecrootn = 0.0;
 ndf->deadcrootn_transfer_to_deadcrootn = 0.0;
 ndf->livestemn_to_deadstemn = 0.0;
 ndf->livestemn_to_retransn = 0.0;
 ndf->livecrootn_to_deadcrootn = 0.0;
 ndf->livecrootn_to_retransn = 0.0;
 ndf->potential_N_uptake = 0.0;
 ndf->sminn_to_npool = 0.0;
 ndf->retransn_to_npool = 0.0;
 ndf->npool_to_leafn = 0.0;
 ndf->npool_to_leafn_store = 0.0;
 ndf->npool_to_frootn = 0.0;
 ndf->npool_to_frootn_store = 0.0;
 ndf->npool_to_livestemn = 0.0;
 ndf->npool_to_livestemn_store = 0.0;
 ndf->npool_to_deadstemn = 0.0;
 ndf->npool_to_deadstemn_store = 0.0;
 ndf->npool_to_livecrootn = 0.0;
 ndf->npool_to_livecrootn_store = 0.0;
 ndf->npool_to_deadcrootn = 0.0;
 ndf->npool_to_deadcrootn_store = 0.0;
 ndf->leafn_store_to_leafn_transfer = 0.0;
 ndf->frootn_store_to_frootn_transfer = 0.0;
 ndf->livestemn_store_to_livestemn_transfer = 0.0;
 ndf->deadstemn_store_to_deadstemn_transfer = 0.0;
 ndf->livecrootn_store_to_livecrootn_transfer = 0.0;
 ndf->deadcrootn_store_to_deadcrootn_transfer = 0.0;
 ndf->carbohydrate_transfer = 0.0;
 return (!ok);
}

canonical_original_code:
int zero_stratum_daily_flux(struct cdayflux_struct *cdf, struct ndayflux_struct *ndf)
{
 int ok = 1;
 cdf->psn_to_cpool = 0.0;
 cdf->leafc_transfer_to_leafc = 0.0;
 cdf->frootc_transfer_to_frootc = 0.0;
 cdf->livestemc_transfer_to_livestemc = 0.0;
 cdf->deadstemc_transfer_to_deadstemc = 0.0;
 cdf->livecrootc_transfer_to_livecrootc = 0.0;
 cdf->deadcrootc_transfer_to_deadcrootc = 0.0;
 cdf->livestemc_to_deadstemc = 0.0;
 cdf->livecrootc_to_deadcrootc = 0.0;
 cdf->added_carbon = 0.0;
 cdf->cpool_to_leafc = 0.0;
 cdf->cpool_to_leafc_store = 0.0;
 cdf->cpool_to_frootc = 0.0;
 cdf->cpool_to_frootc_store = 0.0;
 cdf->cpool_to_livestemc = 0.0;
 cdf->cpool_to_livestemc_store = 0.0;
 cdf->cpool_to_deadstemc = 0.0;
 cdf->cpool_to_deadstemc_store = 0.0;
 cdf->cpool_to_livecrootc = 0.0;
 cdf->cpool_to_livecrootc_store = 0.0;
 cdf->cpool_to_deadcrootc = 0.0;
 cdf->cpool_to_deadcrootc_store = 0.0;
 cdf->cpool_to_gresp_store = 0.0;
 cdf->leafc_store_to_leafc_transfer = 0.0;
 cdf->frootc_store_to_frootc_transfer = 0.0;
 cdf->livestemc_store_to_livestemc_transfer = 0.0;
 cdf->deadstemc_store_to_deadstemc_transfer = 0.0;
 cdf->livecrootc_store_to_livecrootc_transfer = 0.0;
 cdf->deadcrootc_store_to_deadcrootc_transfer = 0.0;
 cdf->gresp_store_to_gresp_transfer = 0.0;
 cdf->storage_transfer_prop = 0.0;
 cdf->carbohydrate_transfer = 0.0;
 cdf->leaf_day_mr = 0.0;
 cdf->leaf_night_mr = 0.0;
 cdf->froot_mr = 0.0;
 cdf->livestem_mr = 0.0;
 cdf->livecroot_mr = 0.0;
  cdf->total_mr = 0.0;
 cdf->transfer_leaf_gr = 0.0;
 cdf->cpool_froot_gr = 0.0;
 cdf->transfer_froot_gr = 0.0;
 cdf->cpool_livestem_gr = 0.0;
 cdf->transfer_livestem_gr = 0.0;
 cdf->cpool_deadstem_gr = 0.0;
 cdf->transfer_deadstem_gr = 0.0;
 cdf->cpool_livecroot_gr = 0.0;
 cdf->transfer_livecroot_gr = 0.0;
 cdf->cpool_deadcroot_gr = 0.0;
 cdf->transfer_deadcroot_gr = 0.0;
 ndf->leafn_transfer_to_leafn = 0.0;
 ndf->frootn_transfer_to_frootn = 0.0;
 ndf->livestemn_transfer_to_livestemn = 0.0;
 ndf->deadstemn_transfer_to_deadstemn = 0.0;
 ndf->livecrootn_transfer_to_livecrootn = 0.0;
 ndf->deadcrootn_transfer_to_deadcrootn = 0.0;
 ndf->livestemn_to_deadstemn = 0.0;
 ndf->livestemn_to_retransn = 0.0;
 ndf->livecrootn_to_deadcrootn = 0.0;
 ndf->livecrootn_to_retransn = 0.0;
 ndf->potential_N_uptake = 0.0;
 ndf->sminn_to_npool = 0.0;
 ndf->retransn_to_npool = 0.0;
 ndf->npool_to_leafn = 0.0;
 ndf->npool_to_leafn_store = 0.0;
 ndf->npool_to_frootn = 0.0;
 ndf->npool_to_frootn_store = 0.0;
 ndf->npool_to_livestemn = 0.0;
 ndf->npool_to_livestemn_store = 0.0;
 ndf->npool_to_deadstemn = 0.0;
 ndf->npool_to_deadstemn_store = 0.0;
 ndf->npool_to_livecrootn = 0.0;
 ndf->npool_to_livecrootn_store = 0.0;
 ndf->npool_to_deadcrootn = 0.0;
 ndf->npool_to_deadcrootn_store = 0.0;
 ndf->leafn_store_to_leafn_transfer = 0.0;
 ndf->frootn_store_to_frootn_transfer = 0.0;
 ndf->livestemn_store_to_livestemn_transfer = 0.0;
 ndf->deadstemn_store_to_deadstemn_transfer = 0.0;
 ndf->livecrootn_store_to_livecrootn_transfer = 0.0;
 ndf->deadcrootn_store_to_deadcrootn_transfer = 0.0;
 ndf->carbohydrate_transfer = 0.0;
 return (!ok);
}

variable_types: struct cdayflux_struct { double fcroot; double fleaf; double froot; double fwood; double added_carbon; double assim_sunlit; double assim_shade; double psn_to_cpool; double potential_psn_to_cpool; double DOC_to_gw; double trans_sunlit; double trans_shade; double leafc_to_deadleafc; double leafc_store_to_leafc; double frootc_store_to_frootc; double leafc_transfer_to_leafc; double frootc_transfer_to_frootc; double livestemc_transfer_to_livestemc; double deadstemc_transfer_to_deadstemc; double livecrootc_transfer_to_livecrootc; double deadcrootc_transfer_to_deadcrootc; double cpool_to_leafc; double cpool_to_leafc_store; double cpool_to_frootc; double cpool_to_frootc_store; double cpool_to_livestemc; double cpool_to_livestemc_store; double cpool_to_deadstemc; double cpool_to_deadstemc_store; double cpool_to_livecrootc; double cpool_to_livecrootc_store; double cpool_to_deadcrootc; double cpool_to_deadcrootc_store; double cpool_to_gresp_store; double actual_C_growth; double leafc_store_to_leafc_transfer; double frootc_store_to_frootc_transfer; double livestemc_store_to_livestemc_transfer; double deadstemc_store_to_deadstemc_transfer; double livecrootc_store_to_livecrootc_transfer; double deadcrootc_store_to_deadcrootc_transfer; double gresp_store_to_gresp_transfer; double carbohydrate_transfer; double storage_transfer_prop; double livestemc_to_deadstemc; double livecrootc_to_deadcrootc; double leaf_day_mr; double leaf_night_mr; double froot_mr; double livestem_mr; double livecroot_mr; double total_mr; double cpool_leaf_gr; double transfer_leaf_gr; double cpool_froot_gr; double transfer_froot_gr; double cpool_livestem_gr; double transfer_livestem_gr; double cpool_deadstem_gr; double transfer_deadstem_gr; double cpool_livecroot_gr; double transfer_livecroot_gr; double cpool_deadcroot_gr; double transfer_deadcroot_gr; double transfer_gr; double total_gr; } *

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

return_type: int


decompiled_code:
__int64 __fastcall key_compare(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
double v3; // xmm1_8
__int64 result; // rax

v2 = *(double *)(a1 + 16);
v3 = *(double *)(a2 + 16);
result = 0xFFFFFFFFLL;
if ( v2 <= v3 )
result = v3 > v2;
return result;
}

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

v2 = *(double *)(a1 + 16);
v3 = *(double *)(a2 + 16);
result = 0xFFFFFFFFLL;
if ( v2 <= v3 )
result = v3 > v2;
return result;
}

original_code:
int key_compare( void * e1, void *e2 )
{
 double v1,v2;
  v1 = ((struct layer_object *)e1)->height;
  v2 = ((struct layer_object *)e2)->height;
 return (v1>v2) ? -1 : (v1<v2) ? 1: 0;
}

canonical_original_code:
int key_compare(void *e1, void *e2)
{
 double v1; double v2;
  v1 = ((struct layer_object *)e1)->height;
  v2 = ((struct layer_object *)e2)->height;
 return (v1>v2) ? -1 : (v1<v2) ? 1: 0;
}

user_defined_types: struct layer_object { int count; long *strata; double height; double base; double null_cover; }


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

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

variable_types: struct soil_default { int ID; int theta_psi_curve; int recompute_gamma_flag; double albedo; double interval_size; double cap_rise_max; double Ksat_0; double Ksat_0_v; double m; double m_v; double m_z; double mz_v; double nitrif_parm_smax; double porosity_0; double porosity_decay; double p3; double p4; double pore_size_index; double psi_air_entry; double psi_max; double sat_to_gw_coeff; double soil_depth; double effective_soil_depth; double soil_water_cap; double deltaz; double min_heat_capacity; double detention_store_size; double max_heat_capacity; double maximum_snow_energy_deficit; double snow_water_capacity; double snow_light_ext_coef; double snow_melt_Tcoef; double fixed_t_mult; double fixed_w_mult; double fs_spill; double fs_percolation; double fs_threshold; int snow_albedo_flag; double bats_b; double bats_r3; double active_zone_z; double DOM_decay_rate; double DON_adsorption_rate; double DOC_adsorption_rate; double N_decay_rate; double NO3_adsorption_rate; double NH4_adsorption_rate; double denitrif_proportion; double DON_production_rate; double gl_c; double gsurf_slope; double gsurf_intercept; double theta_mean_std_p1; double theta_mean_std_p2; double overstory_height_thresh; double understory_height_thresh; struct soil_class { double sand; double silt; double clay; } soil_type; } *

user_defined_types: struct soil_default { int ID; int theta_psi_curve; int recompute_gamma_flag; double albedo; double interval_size; double cap_rise_max; double Ksat_0; double Ksat_0_v; double m; double m_v; double m_z; double mz_v; double nitrif_parm_smax; double porosity_0; double porosity_decay; double p3; double p4; double pore_size_index; double psi_air_entry; double psi_max; double sat_to_gw_coeff; double soil_depth; double effective_soil_depth; double soil_water_cap; double deltaz; double min_heat_capacity; double detention_store_size; double max_heat_capacity; double maximum_snow_energy_deficit; double snow_water_capacity; double snow_light_ext_coef; double snow_melt_Tcoef; double fixed_t_mult; double fixed_w_mult; double fs_spill; double fs_percolation; double fs_threshold; int snow_albedo_flag; double bats_b; double bats_r3; double active_zone_z; double DOM_decay_rate; double DON_adsorption_rate; double DOC_adsorption_rate; double N_decay_rate; double NO3_adsorption_rate; double NH4_adsorption_rate; double denitrif_proportion; double DON_production_rate; double gl_c; double gsurf_slope; double gsurf_intercept; double theta_mean_std_p1; double theta_mean_std_p2; double overstory_height_thresh; double understory_height_thresh; struct soil_class soil_type; }


decompiled_code:
double __fastcall compute_toc_wind(double a1, double a2, double a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
double v8; // r15
double v10; // [rsp+0h] [rbp-28h]
double v11; // [rsp+8h] [rbp-20h]

if ( a3 <= 0.0 )
{
v11 = *(double *)&LC0;
v10 = 0.0;
}
else
{
v10 = a3 * 0.7;
v11 = a3 * 0.1;
}
if ( v10 > a2 )
{
fprintf(stderr, "FATAL ERROR: screen height %d < zero plane of patch highest stratum %d \n", a6, a7);
exit(1);
}
v8 = log((a3 - v10) / v11);
return a1 * v8 / log((a2 - v10) / v11);
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
double v8; // r15
double v10; // [rsp+0h] [rbp-28h]
double v11; // [rsp+8h] [rbp-20h]

if ( a3 <= 0.0 )
{
v11 = *(double *)&LC0;
v10 = 0.0;
}
else
{
v10 = a3 * 0.7;
v11 = a3 * 0.1;
}
if ( v10 > a2 )
{
fprintf(stderr, "FATAL ERROR: screen height %d < zero plane of patch highest stratum %d \n", a6, a7);
exit(1);
}
v8 = log((a3 - v10) / v11);
return a1 * v8 / log((a2 - v10) / v11);
}

original_code:
double compute_toc_wind(
       int verbose_flag,
       double u_h,
       double h,
       double z)
{
 double u_z;
 double d_o;
 double z_o;
 if (z > 0.0) {
  d_o = 0.7 * z;
  z_o = 0.1 * z;
 }
 else {
  d_o = 0.0;
  z_o = 0.01;
 }
 if ( h < d_o ){
  fprintf(stderr,
   "FATAL ERROR: screen height %d < zero plane of patch highest stratum %d \n", h, d_o);
  exit(1);
 }
 u_z = u_h * log((z-d_o)/z_o) / log((h-d_o)/z_o);
 return(u_z);
}

canonical_original_code:
double compute_toc_wind(int verbose_flag, double u_h, double h, double z)
{
 double u_z;
 double d_o;
 double z_o;
 if (z > 0.0) {
  d_o = 0.7 * z;
  z_o = 0.1 * z;
 }
 else {
  d_o = 0.0;
  z_o = 0.01;
 }
 if ( h < d_o ){
  fprintf(stderr,
   "FATAL ERROR: screen height %d < zero plane of patch highest stratum %d \n", h, d_o);
  exit(1);
 }
 u_z = u_h * log((z-d_o)/z_o) / log((h-d_o)/z_o);
 return(u_z);
}

variable_types: h double

variable_types: z double

return_type: double


decompiled_code:
double __fastcall compute_potential_exfiltration(int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double v10; // r12
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v18; // [rsp+8h] [rbp-50h]
double v20; // [rsp+18h] [rbp-40h]
double v21; // [rsp+28h] [rbp-30h]

v20 = a4;
v18 = a8 * a9 * (1.0 - exp(COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC2) / a8)) / a3;
if ( a5 > 0.000000001 )
v20 = a5 * a4 * (1.0 - exp(COERCE_DOUBLE(*(_QWORD *)&a3 ^ LC2) / a5)) / a3;
if ( a2 < 1.0 )
{
if ( a2 < 0.0 )
a2 = *(double *)&LC0;
}
else
{
a2 = *(double *)&LC1;
}
v10 = pow(a2, 1.0 / (a7 + a7) + 2.0);
v11 = v18 * 8.0 * v20 * a6 / ((a7 * 3.0 + 1.0) * 3.0 * (a7 * 4.0 + 1.0));
if ( v11 < 0.0 )
v12 = sqrt(v11);
else
v12 = sqrt(v11);
v21 = v12 * v10;
v13 = log(2.5 / a6);
v14 = exp(COERCE_DOUBLE(*(_QWORD *)&v13 ^ LC2) * a7) * v18;
if ( a1 == -5 )
printf(
"\n COMPUTE POTENTIAL EXFIL: wilpt=%lf potexfil=%lf S=%lf porosity=%lf Ksatavg=%lf psi_ae=%lf b=%lf",
v14,
v21,
a2,
v18,
v20,
a6,
a7);
v15 = (a2 - v14) * v18;
if ( v15 <= 0.0 )
v15 = 0.0;
return fmin(v15, v21);
}

original_code:
double compute_potential_exfiltration(
            int verbose_flag,
            double S,
            double sat_deficit_z,
            double Ksat_0,
            double m_z,
            double psi_air_entry,
            double pore_size_index,
            double p,
            double p_0)
{
 double porosity_average;
 double Ksat_average, wilting_point;
 double potential_exfiltration;
 porosity_average = p * p_0 * (1-exp(-1*sat_deficit_z/p)) / sat_deficit_z;
 if (m_z > 0.000000001)
  Ksat_average = m_z* Ksat_0 *(1-exp(-1*sat_deficit_z/m_z)) / sat_deficit_z;
 else
  Ksat_average = Ksat_0;
 S = ((0) > (((S) < (1) ? (S) : (1))) ? (0) : (((S) < (1) ? (S) : (1))));
 potential_exfiltration =
  pow(S,(1/(2*pore_size_index))+2) * sqrt( (8 * porosity_average
  * Ksat_average * psi_air_entry ) / (3 * (1 + 3 * pore_size_index)
  * (1 + 4 * pore_size_index) ) );
 wilting_point = exp(-1.0*log(2.5/psi_air_entry)
   * pore_size_index) * porosity_average;
 if ( verbose_flag == -5 ){
  printf("\n          COMPUTE POTENTIAL EXFIL: wilpt=%lf potexfil=%lf S=%lf porosity=%lf Ksatavg=%lf psi_ae=%lf b=%lf",
      wilting_point,
      potential_exfiltration,
      S,
      porosity_average,
      Ksat_average,
      psi_air_entry,
      pore_size_index);
 }
 potential_exfiltration = (((((S-wilting_point)*porosity_average) > (0.0) ? ((S-wilting_point)*porosity_average) : (0.0))) < (potential_exfiltration) ? ((((S-wilting_point)*porosity_average) > (0.0) ? ((S-wilting_point)*porosity_average) : (0.0))) : (potential_exfiltration));
 return(potential_exfiltration);
}

canonical_original_code:
double compute_potential_exfiltration(int verbose_flag, double S, double sat_deficit_z, double Ksat_0, double m_z, double psi_air_entry, double pore_size_index, double p, double p_0)
{
 double porosity_average;
 double Ksat_average; double wilting_point;
 double potential_exfiltration;
 porosity_average = p * p_0 * (1-exp(-1*sat_deficit_z/p)) / sat_deficit_z;
 if (m_z > 0.000000001)
  Ksat_average = m_z* Ksat_0 *(1-exp(-1*sat_deficit_z/m_z)) / sat_deficit_z;
 else
  Ksat_average = Ksat_0;
 S = ((0) > (((S) < (1) ? (S) : (1))) ? (0) : (((S) < (1) ? (S) : (1))));
 potential_exfiltration =
  pow(S,(1/(2*pore_size_index))+2) * sqrt( (8 * porosity_average
  * Ksat_average * psi_air_entry ) / (3 * (1 + 3 * pore_size_index)
  * (1 + 4 * pore_size_index) ) );
 wilting_point = exp(-1.0*log(2.5/psi_air_entry)
   * pore_size_index) * porosity_average;
 if ( verbose_flag == -5 ){
  printf("\n          COMPUTE POTENTIAL EXFIL: wilpt=%lf potexfil=%lf S=%lf porosity=%lf Ksatavg=%lf psi_ae=%lf b=%lf",
      wilting_point,
      potential_exfiltration,
      S,
      porosity_average,
      Ksat_average,
      psi_air_entry,
      pore_size_index);
 }
 potential_exfiltration = (((((S-wilting_point)*porosity_average) > (0.0) ? ((S-wilting_point)*porosity_average) : (0.0))) < (potential_exfiltration) ? ((((S-wilting_point)*porosity_average) > (0.0) ? ((S-wilting_point)*porosity_average) : (0.0))) : (potential_exfiltration));
 return(potential_exfiltration);
}

variable_types: S double

variable_types: p double


decompiled_code:
_BOOL8 __fastcall valid_option(char *s1)
{
_BOOL4 v1; // edx

v1 = 1;
if ( strcmp(s1, "bgc")
&& strcmp(s1, "-v")
&& strcmp(s1, "-e")
&& strcmp(s1, "-b")
&& strcmp(s1, "-h")
&& strcmp(s1, "-p")
&& strcmp(s1, "-g")
&& strcmp(s1, "-c")
&& strcmp(s1, "-f")
&& strcmp(s1, "-o")
&& strcmp(s1, "-w")
&& strcmp(s1, "-r")
&& strcmp(s1, "-t")
&& strcmp(s1, "-s")
&& strcmp(s1, "-z")
&& strcmp(s1, "-sv")
&& strcmp(s1, "-st") )
{
if ( !strcmp(s1, "-th") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-ed") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-tmp") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-gw") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-tchange") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-pre") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-rddn") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-stdev") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-dor") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-csv") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-vgsen") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-noredist") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-vmort") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-svalt") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-precip") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-gwtoriparian") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-surfaceenergy") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-firespread") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-snowdistb") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-whdr") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-netcdf") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-climrepeat") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-template") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-fs") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-vegspinup") )
{
v1 = 1;
}
else
{
v1 = strcmp(s1, "-msr") == 0;
}
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *s1)
{
_BOOL4 v1; // edx

v1 = 1;
if ( strcmp(s1, "bgc")
&& strcmp(s1, "-v")
&& strcmp(s1, "-e")
&& strcmp(s1, "-b")
&& strcmp(s1, "-h")
&& strcmp(s1, "-p")
&& strcmp(s1, "-g")
&& strcmp(s1, "-c")
&& strcmp(s1, "-f")
&& strcmp(s1, "-o")
&& strcmp(s1, "-w")
&& strcmp(s1, "-r")
&& strcmp(s1, "-t")
&& strcmp(s1, "-s")
&& strcmp(s1, "-z")
&& strcmp(s1, "-sv")
&& strcmp(s1, "-st") )
{
if ( !strcmp(s1, "-th") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-ed") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-tmp") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-gw") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-tchange") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-pre") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-rddn") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-stdev") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-dor") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-csv") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-vgsen") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-noredist") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-vmort") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-svalt") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-precip") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-gwtoriparian") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-surfaceenergy") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-firespread") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-snowdistb") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-whdr") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-netcdf") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-climrepeat") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-template") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-fs") )
{
v1 = 1;
}
else if ( !strcmp(s1, "-vegspinup") )
{
v1 = 1;
}
else
{
v1 = strcmp(s1, "-msr") == 0;
}
}
return v1;
}

original_code:
int valid_option( char *command_line){
 int i;
 i = 1;
 if (( strcmp(command_line,"bgc") == 0) ||
  (strcmp(command_line,"-v") == 0) ||
  (strcmp(command_line,"-e") == 0) ||
  (strcmp(command_line,"-b") == 0) ||
  (strcmp(command_line,"-h") == 0) ||
  (strcmp(command_line,"-p") == 0) ||
  (strcmp(command_line,"-g") == 0) ||
  (strcmp(command_line,"-c") == 0) ||
  (strcmp(command_line,"-f") == 0) ||
  (strcmp(command_line,"-o") == 0) ||
  (strcmp(command_line,"-w") == 0) ||
  (strcmp(command_line,"-r") == 0) ||
  (strcmp(command_line,"-t") == 0) ||
  (strcmp(command_line,"-s") == 0) ||
  (strcmp(command_line,"-z") == 0) ||
  (strcmp(command_line,"-sv") == 0) ||
  (strcmp(command_line,"-st") == 0) ||
  (strcmp(command_line,"-th") == 0) ||
  (strcmp(command_line,"-ed") == 0) ||
  (strcmp(command_line,"-tmp") == 0) ||
  (strcmp(command_line,"-gw") == 0) ||
  (strcmp(command_line,"-tchange") == 0) ||
  (strcmp(command_line,"-pre") == 0) ||
  (strcmp(command_line,"-rddn") == 0) ||
  (strcmp(command_line,"-stdev") == 0) ||
  (strcmp(command_line,"-dor") == 0) ||
  (strcmp(command_line,"-csv") == 0) ||
  (strcmp(command_line,"-vgsen") == 0) ||
  (strcmp(command_line,"-noredist") == 0) ||
  (strcmp(command_line,"-vmort") == 0) ||
  (strcmp(command_line,"-svalt") == 0) ||
  (strcmp(command_line,"-precip") == 0) ||
  (strcmp(command_line,"-gwtoriparian") == 0) ||
  (strcmp(command_line,"-surfaceenergy") == 0) ||
  (strcmp(command_line,"-firespread") == 0) ||
  (strcmp(command_line,"-snowdistb") == 0) ||
  (strcmp(command_line,"-whdr") == 0) ||
  (strcmp(command_line,"-netcdf") == 0) ||
  (strcmp(command_line,"-climrepeat") == 0) ||
  (strcmp(command_line,"-template") == 0) ||
  (strcmp(command_line,"-fs") == 0) ||
  (strcmp(command_line,"-vegspinup") == 0) ||
  (strcmp(command_line,"-template") == 0) ||
  (strcmp(command_line,"-msr") == 0))
  i = 0;
 if ( i == 0 ){
  return(1);
 }
 else{
  return(0);
 }
}

canonical_original_code:
int valid_option(char *command_line){
 int i;
 i = 1;
 if (( strcmp(command_line,"bgc") == 0) ||
  (strcmp(command_line,"-v") == 0) ||
  (strcmp(command_line,"-e") == 0) ||
  (strcmp(command_line,"-b") == 0) ||
  (strcmp(command_line,"-h") == 0) ||
  (strcmp(command_line,"-p") == 0) ||
  (strcmp(command_line,"-g") == 0) ||
  (strcmp(command_line,"-c") == 0) ||
  (strcmp(command_line,"-f") == 0) ||
  (strcmp(command_line,"-o") == 0) ||
  (strcmp(command_line,"-w") == 0) ||
  (strcmp(command_line,"-r") == 0) ||
  (strcmp(command_line,"-t") == 0) ||
  (strcmp(command_line,"-s") == 0) ||
  (strcmp(command_line,"-z") == 0) ||
  (strcmp(command_line,"-sv") == 0) ||
  (strcmp(command_line,"-st") == 0) ||
  (strcmp(command_line,"-th") == 0) ||
  (strcmp(command_line,"-ed") == 0) ||
  (strcmp(command_line,"-tmp") == 0) ||
  (strcmp(command_line,"-gw") == 0) ||
  (strcmp(command_line,"-tchange") == 0) ||
  (strcmp(command_line,"-pre") == 0) ||
  (strcmp(command_line,"-rddn") == 0) ||
  (strcmp(command_line,"-stdev") == 0) ||
  (strcmp(command_line,"-dor") == 0) ||
  (strcmp(command_line,"-csv") == 0) ||
  (strcmp(command_line,"-vgsen") == 0) ||
  (strcmp(command_line,"-noredist") == 0) ||
  (strcmp(command_line,"-vmort") == 0) ||
  (strcmp(command_line,"-svalt") == 0) ||
  (strcmp(command_line,"-precip") == 0) ||
  (strcmp(command_line,"-gwtoriparian") == 0) ||
  (strcmp(command_line,"-surfaceenergy") == 0) ||
  (strcmp(command_line,"-firespread") == 0) ||
  (strcmp(command_line,"-snowdistb") == 0) ||
  (strcmp(command_line,"-whdr") == 0) ||
  (strcmp(command_line,"-netcdf") == 0) ||
  (strcmp(command_line,"-climrepeat") == 0) ||
  (strcmp(command_line,"-template") == 0) ||
  (strcmp(command_line,"-fs") == 0) ||
  (strcmp(command_line,"-vegspinup") == 0) ||
  (strcmp(command_line,"-template") == 0) ||
  (strcmp(command_line,"-msr") == 0))
  i = 0;
 if ( i == 0 ){
  return(1);
 }
 else{
  return(0);
 }
}

variable_types: i int


original_code:
double compute_stability_correction(
          int verbose_flag,
          double zsurf,
          double Tsurf,
          double usurf,
          double zair,
          double Tair,
          double uair)
{
 double ri;
 double correction;
 double Z0, ri_cr, ri_lim;
 Z0 = 0.01;
 ri_cr = 0.2;
 correction = 1.0;
 if (Tsurf != Tair) {
  ri = 9.8 * (Tair - Tsurf) * (zair - zsurf) / (((Tair + 273.15) + (Tsurf + 273.15)) / 2.0 * uair * uair);
  ri_lim = (Tair + 273.15) / (((Tair + 273.15) + (Tsurf + 273.15)) / 2.0 * (log((zair - zsurf) / Z0) + 5));
  if (ri > ri_lim)
   ri = ri_lim;
  if (ri > 0.0)
   correction = (1 - ri / ri_cr) * (1 - ri / ri_cr);
  else {
   if (ri < -0.5)
    ri = -0.5;
   correction = sqrt(1 - 16 * ri);
   }
 }
 return(correction);
}

canonical_original_code:
double compute_stability_correction(int verbose_flag, double zsurf, double Tsurf, double usurf, double zair, double Tair, double uair)
{
 double ri;
 double correction;
 double Z0; double ri_cr; double ri_lim;
 Z0 = 0.01;
 ri_cr = 0.2;
 correction = 1.0;
 if (Tsurf != Tair) {
  ri = 9.8 * (Tair - Tsurf) * (zair - zsurf) / (((Tair + 273.15) + (Tsurf + 273.15)) / 2.0 * uair * uair);
  ri_lim = (Tair + 273.15) / (((Tair + 273.15) + (Tsurf + 273.15)) / 2.0 * (log((zair - zsurf) / Z0) + 5));
  if (ri > ri_lim)
   ri = ri_lim;
  if (ri > 0.0)
   correction = (1 - ri / ri_cr) * (1 - ri / ri_cr);
  else {
   if (ri < -0.5)
    ri = -0.5;
   correction = sqrt(1 - 16 * ri);
   }
 }
 return(correction);
}

variable_types: zsurf double

variable_types: Tsurf double

variable_types: usurf double

variable_types: zair double

variable_types: Tair double

variable_types: uair double

variable_types: ri double

variable_types: correction double


original_code:
double compute_soil_water_potential(
       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 LWP_predawn;
 p = ((p) > (0.00000001) ? (p) : (0.00000001));
 p_0 = ((p_0) > (0.00000001) ? (p_0) : (0.00000001));
 if (S > 1.0) {
  LWP_predawn = LWP_min_spring;
 }
 else{
  switch(curve) {
  case 1:
   LWP_predawn = ((-1.0 * 0.01 * ( psi_air_entry * pow ( S , -1/pore_size_index) )) < (LWP_min_spring) ? (-1.0 * 0.01 * ( psi_air_entry * pow ( S , -1/pore_size_index) )) : (LWP_min_spring));
   break;
  case 2:
   if (S > 0.000000001)
    LWP_predawn = ((-1.0 * 0.01 * psi_air_entry * pow( pow(1/S,1/(1-1/pore_size_index)) -1 , 1/pore_size_index )) < (LWP_min_spring) ? (-1.0 * 0.01 * psi_air_entry * pow( pow(1/S,1/(1-1/pore_size_index)) -1 , 1/pore_size_index )) : (LWP_min_spring));
   else LWP_predawn = LWP_stom_closure;
   break;
  case 3:
   if (S > 0.000000001)
    LWP_predawn = -1.0*exp(p3+p4*log(S));
   else LWP_predawn = LWP_stom_closure;
   break;
  }
 }
 if ( Tsoil < 0.0000000001 )
  LWP_predawn = LWP_predawn * 2.0;
 LWP_predawn = ((LWP_predawn) > (LWP_stom_closure) ? (LWP_predawn) : (LWP_stom_closure));
 return(LWP_predawn);
}

canonical_original_code:
double compute_soil_water_potential(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 LWP_predawn;
 p = ((p) > (0.00000001) ? (p) : (0.00000001));
 p_0 = ((p_0) > (0.00000001) ? (p_0) : (0.00000001));
 if (S > 1.0) {
  LWP_predawn = LWP_min_spring;
 }
 else{
  switch(curve) {
  case 1:
   LWP_predawn = ((-1.0 * 0.01 * ( psi_air_entry * pow ( S , -1/pore_size_index) )) < (LWP_min_spring) ? (-1.0 * 0.01 * ( psi_air_entry * pow ( S , -1/pore_size_index) )) : (LWP_min_spring));
   break;
  case 2:
   if (S > 0.000000001)
    LWP_predawn = ((-1.0 * 0.01 * psi_air_entry * pow( pow(1/S,1/(1-1/pore_size_index)) -1 , 1/pore_size_index )) < (LWP_min_spring) ? (-1.0 * 0.01 * psi_air_entry * pow( pow(1/S,1/(1-1/pore_size_index)) -1 , 1/pore_size_index )) : (LWP_min_spring));
   else LWP_predawn = LWP_stom_closure;
   break;
  case 3:
   if (S > 0.000000001)
    LWP_predawn = -1.0*exp(p3+p4*log(S));
   else LWP_predawn = LWP_stom_closure;
   break;
  }
 }
 if ( Tsoil < 0.0000000001 )
  LWP_predawn = LWP_predawn * 2.0;
 LWP_predawn = ((LWP_predawn) > (LWP_stom_closure) ? (LWP_predawn) : (LWP_stom_closure));
 return(LWP_predawn);
}

variable_types: curve int

variable_types: Tsoil double


original_code:
int resolve_sminn_competition(
         struct soil_n_object *ns_soil,
         double surface_NO3,
         double surface_NH4,
         double rooting_depth,
         double active_zone_z,
         double N_decay_rate,
         struct ndayflux_patch_struct *ndf)
{
 double sum_ndemand, sum_avail;
 double actual_immob, actual_uptake, perc_inroot;
 sum_ndemand = ndf->plant_potential_ndemand + ndf->potential_immob;
 sum_avail = ((ns_soil->sminn + ns_soil->nitrate + ndf->mineralized) > (0.0) ? (ns_soil->sminn + ns_soil->nitrate + ndf->mineralized) : (0.0));
 perc_inroot = (1.0-exp(-N_decay_rate * rooting_depth)) /
   (1.0 - exp(-N_decay_rate * active_zone_z));
 perc_inroot = ((perc_inroot) < (1.0) ? (perc_inroot) : (1.0));
 if (rooting_depth > 0.000000001)
  perc_inroot = ((0.1) > (perc_inroot) ? (0.1) : (perc_inroot));
 sum_avail = perc_inroot * sum_avail;
 if (sum_ndemand <= sum_avail){
  actual_immob = ndf->potential_immob;
  ns_soil->nlimit = 0;
  ns_soil->fract_potential_immob = 1.0;
  ns_soil->fract_potential_uptake = 1.0;
  ndf->plant_avail_uptake = ndf->plant_potential_ndemand;
 }
 else{
  ns_soil->nlimit = 1;
  actual_immob = (sum_avail) * (ndf->potential_immob/sum_ndemand);
  actual_uptake = sum_avail - actual_immob;
  if (ndf->potential_immob == 0)
   ns_soil->fract_potential_immob = 0.0;
  else
   ns_soil->fract_potential_immob = actual_immob/ndf->potential_immob;
  if (ndf->plant_potential_ndemand == 0) {
   ns_soil->fract_potential_uptake = 0.0;
   ndf->plant_avail_uptake = actual_uptake;
  }
  else {
   ns_soil->fract_potential_uptake = actual_uptake
    / ndf->plant_potential_ndemand;
   ndf->plant_avail_uptake = actual_uptake;
  }
 }
 return(0);
}

canonical_original_code:
int resolve_sminn_competition(struct soil_n_object *ns_soil, double surface_NO3, double surface_NH4, double rooting_depth, double active_zone_z, double N_decay_rate, struct ndayflux_patch_struct *ndf)
{
 double sum_ndemand; double sum_avail;
 double actual_immob; double actual_uptake; double perc_inroot;
 sum_ndemand = ndf->plant_potential_ndemand + ndf->potential_immob;
 sum_avail = ((ns_soil->sminn + ns_soil->nitrate + ndf->mineralized) > (0.0) ? (ns_soil->sminn + ns_soil->nitrate + ndf->mineralized) : (0.0));
 perc_inroot = (1.0-exp(-N_decay_rate * rooting_depth)) /
   (1.0 - exp(-N_decay_rate * active_zone_z));
 perc_inroot = ((perc_inroot) < (1.0) ? (perc_inroot) : (1.0));
 if (rooting_depth > 0.000000001)
  perc_inroot = ((0.1) > (perc_inroot) ? (0.1) : (perc_inroot));
 sum_avail = perc_inroot * sum_avail;
 if (sum_ndemand <= sum_avail){
  actual_immob = ndf->potential_immob;
  ns_soil->nlimit = 0;
  ns_soil->fract_potential_immob = 1.0;
  ns_soil->fract_potential_uptake = 1.0;
  ndf->plant_avail_uptake = ndf->plant_potential_ndemand;
 }
 else{
  ns_soil->nlimit = 1;
  actual_immob = (sum_avail) * (ndf->potential_immob/sum_ndemand);
  actual_uptake = sum_avail - actual_immob;
  if (ndf->potential_immob == 0)
   ns_soil->fract_potential_immob = 0.0;
  else
   ns_soil->fract_potential_immob = actual_immob/ndf->potential_immob;
  if (ndf->plant_potential_ndemand == 0) {
   ns_soil->fract_potential_uptake = 0.0;
   ndf->plant_avail_uptake = actual_uptake;
  }
  else {
   ns_soil->fract_potential_uptake = actual_uptake
    / ndf->plant_potential_ndemand;
   ndf->plant_avail_uptake = actual_uptake;
  }
 }
 return(0);
}

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

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


original_code:
double nonlinear_kimetic_wave(double alfa,double Qin,double initial_flow,double lateral_input,double previous_lateral_input,double dx,double dt)
{
 int mlm;
 int k;
 int ilm;
 double beta,Qout;
 double epsi0;
 double qk;
 double qk1;
 double up;
 double down;
 double c;
 double epsi;
 double f1;
 double fk;
 double alam;
 double f;
        beta=0.6;
 epsi0=0.001;
 mlm=5;
 k = 0;
  if(Qin <= 4.5e-308 && initial_flow <= 4.5e-308)
   qk=0.5*(lateral_input+previous_lateral_input)*dx;
  else
  {up=(dt/dx)*Qin+alfa*beta*initial_flow*pow((0.5*(Qin+initial_flow)),(beta-1))+dt*0.5*(lateral_input+previous_lateral_input);
   down=(dt/dx)+alfa*beta*pow((0.5*(Qin+initial_flow)),(beta-1));
   qk=up/down;
  }
  if(qk<0){
   Qout=0;
          return(Qout);}
  c=(dt/dx)*Qin+alfa*pow(initial_flow,beta)+dt*0.5*(lateral_input+previous_lateral_input);
         epsi=0.00001*c;
  do{
   fk=(dt/dx)*qk+alfa*pow(qk,beta)-c;
  f1=(dt/dx)+alfa*beta*pow(qk,(beta-1));
  qk1=qk-fk/f1;
  k=k+1;
  if(qk1<=0)
   qk1=qk*0.00000001;
  for(ilm=1;ilm<=mlm;ilm++){
   alam=1.0/pow(2.0,(ilm-1));
   Qout=alam*qk1+(1-alam)*qk;
   f=(dt/dx)*Qout+alfa*pow(Qout,beta)-c;
   if(abs(f)<=epsi || abs(f)<=epsi0)
                    goto _jumpout;
   if(abs(f)<abs(fk))
    break;
  }
  qk=Qout;
  if(k>25)
   break;}while(abs(f)>epsi);
         _jumpout:
         return(Qout);
}

canonical_original_code:
double nonlinear_kimetic_wave(double alfa, double Qin, double initial_flow, double lateral_input, double previous_lateral_input, double dx, double dt)
{
 int mlm;
 int k;
 int ilm;
 double beta; double Qout;
 double epsi0;
 double qk;
 double qk1;
 double up;
 double down;
 double c;
 double epsi;
 double f1;
 double fk;
 double alam;
 double f;
        beta=0.6;
 epsi0=0.001;
 mlm=5;
 k = 0;
  if(Qin <= 4.5e-308 && initial_flow <= 4.5e-308)
   qk=0.5*(lateral_input+previous_lateral_input)*dx;
  else
  {up=(dt/dx)*Qin+alfa*beta*initial_flow*pow((0.5*(Qin+initial_flow)),(beta-1))+dt*0.5*(lateral_input+previous_lateral_input);
   down=(dt/dx)+alfa*beta*pow((0.5*(Qin+initial_flow)),(beta-1));
   qk=up/down;
  }
  if(qk<0){
   Qout=0;
          return(Qout);}
  c=(dt/dx)*Qin+alfa*pow(initial_flow,beta)+dt*0.5*(lateral_input+previous_lateral_input);
         epsi=0.00001*c;
  do{
   fk=(dt/dx)*qk+alfa*pow(qk,beta)-c;
  f1=(dt/dx)+alfa*beta*pow(qk,(beta-1));
  qk1=qk-fk/f1;
  k=k+1;
  if(qk1<=0)
   qk1=qk*0.00000001;
  for(ilm=1;ilm<=mlm;ilm++){
   alam=1.0/pow(2.0,(ilm-1));
   Qout=alam*qk1+(1-alam)*qk;
   f=(dt/dx)*Qout+alfa*pow(Qout,beta)-c;
   if(abs(f)<=epsi || abs(f)<=epsi0)
                    goto _jumpout;
   if(abs(f)<abs(fk))
    break;
  }
  qk=Qout;
  if(k>25)
   break;}while(abs(f)>epsi);
         _jumpout:
         return(Qout);
}

variable_types: alfa double

variable_types: Qin double

variable_types: dx double

variable_types: dt double

variable_types: mlm int

variable_types: k int

variable_types: ilm int

variable_types: beta double

variable_types: Qout double

variable_types: qk double

variable_types: up double

variable_types: down double

variable_types: c double

variable_types: epsi double

variable_types: fk double

variable_types: alam double

variable_types: f double


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

canonical_original_code:
void find_min_flna(struct flow_struct *flow_table, int curr, int *str_inx)
{
 struct adj_struct *aptr;
 int i; int inx;
 double min_flna;
 aptr = flow_table[curr].adj_list;
 min_flna = flow_table[aptr->inx].flna;
 i = 1;
 while ((i <= flow_table[curr].num_adjacent)) {
  inx = aptr->inx;
  if ((flow_table[inx].flna <= min_flna) && (aptr->gamma != 0.0)) {
   *str_inx = inx;
   min_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: i int

variable_types: inx int


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

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

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

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

variable_types: ok int


original_code:
int compute_growth_resp(int alloc, struct epconst_struct epc,
      struct cdayflux_struct* cdf)
{
 int ok=1;
 double g1;
 g1 = epc.gr_perc;
 cdf->cpool_leaf_gr = cdf->cpool_to_leafc * g1;
 cdf->cpool_froot_gr = cdf->cpool_to_frootc * g1;
 cdf->transfer_leaf_gr = cdf->leafc_transfer_to_leafc * g1;
 cdf->transfer_froot_gr = cdf->frootc_transfer_to_frootc * g1;
 cdf->total_gr = cdf->cpool_leaf_gr + cdf->cpool_froot_gr +
  cdf->transfer_leaf_gr + cdf->transfer_froot_gr;
 if (epc.veg_type == 1){
  cdf->cpool_livestem_gr = cdf->cpool_to_livestemc * g1;
  cdf->cpool_deadstem_gr = cdf->cpool_to_deadstemc * g1;
  cdf->cpool_livecroot_gr = cdf->cpool_to_livecrootc * g1;
  cdf->cpool_deadcroot_gr = cdf->cpool_to_deadcrootc * g1;
  cdf->transfer_livestem_gr = cdf->livestemc_transfer_to_livestemc * g1;
  cdf->transfer_deadstem_gr = cdf->deadstemc_transfer_to_deadstemc * g1;
  cdf->transfer_livecroot_gr = cdf->livecrootc_transfer_to_livecrootc * g1;
  cdf->transfer_deadcroot_gr = cdf->deadcrootc_transfer_to_deadcrootc * g1;
  cdf->total_gr += cdf->cpool_livestem_gr + cdf->cpool_deadstem_gr
   + cdf->cpool_livecroot_gr + cdf->cpool_deadcroot_gr
   + cdf->transfer_livecroot_gr + cdf->transfer_deadcroot_gr
   + cdf->transfer_livestem_gr + cdf->transfer_deadstem_gr ;
 }
 return (!ok);
}

canonical_original_code:
int compute_growth_resp(int alloc, struct epconst_struct epc, struct cdayflux_struct *cdf)
{
 int ok = 1;
 double g1;
 g1 = epc.gr_perc;
 cdf->cpool_leaf_gr = cdf->cpool_to_leafc * g1;
 cdf->cpool_froot_gr = cdf->cpool_to_frootc * g1;
 cdf->transfer_leaf_gr = cdf->leafc_transfer_to_leafc * g1;
 cdf->transfer_froot_gr = cdf->frootc_transfer_to_frootc * g1;
 cdf->total_gr = cdf->cpool_leaf_gr + cdf->cpool_froot_gr +
  cdf->transfer_leaf_gr + cdf->transfer_froot_gr;
 if (epc.veg_type == 1){
  cdf->cpool_livestem_gr = cdf->cpool_to_livestemc * g1;
  cdf->cpool_deadstem_gr = cdf->cpool_to_deadstemc * g1;
  cdf->cpool_livecroot_gr = cdf->cpool_to_livecrootc * g1;
  cdf->cpool_deadcroot_gr = cdf->cpool_to_deadcrootc * g1;
  cdf->transfer_livestem_gr = cdf->livestemc_transfer_to_livestemc * g1;
  cdf->transfer_deadstem_gr = cdf->deadstemc_transfer_to_deadstemc * g1;
  cdf->transfer_livecroot_gr = cdf->livecrootc_transfer_to_livecrootc * g1;
  cdf->transfer_deadcroot_gr = cdf->deadcrootc_transfer_to_deadcrootc * g1;
  cdf->total_gr += cdf->cpool_livestem_gr + cdf->cpool_deadstem_gr
   + cdf->cpool_livecroot_gr + cdf->cpool_deadcroot_gr
   + cdf->transfer_livecroot_gr + cdf->transfer_deadcroot_gr
   + cdf->transfer_livestem_gr + cdf->transfer_deadstem_gr ;
 }
 return (!ok);
}

variable_types: alloc int

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 cdayflux_struct { double fcroot; double fleaf; double froot; double fwood; double added_carbon; double assim_sunlit; double assim_shade; double psn_to_cpool; double potential_psn_to_cpool; double DOC_to_gw; double trans_sunlit; double trans_shade; double leafc_to_deadleafc; double leafc_store_to_leafc; double frootc_store_to_frootc; double leafc_transfer_to_leafc; double frootc_transfer_to_frootc; double livestemc_transfer_to_livestemc; double deadstemc_transfer_to_deadstemc; double livecrootc_transfer_to_livecrootc; double deadcrootc_transfer_to_deadcrootc; double cpool_to_leafc; double cpool_to_leafc_store; double cpool_to_frootc; double cpool_to_frootc_store; double cpool_to_livestemc; double cpool_to_livestemc_store; double cpool_to_deadstemc; double cpool_to_deadstemc_store; double cpool_to_livecrootc; double cpool_to_livecrootc_store; double cpool_to_deadcrootc; double cpool_to_deadcrootc_store; double cpool_to_gresp_store; double actual_C_growth; double leafc_store_to_leafc_transfer; double frootc_store_to_frootc_transfer; double livestemc_store_to_livestemc_transfer; double deadstemc_store_to_deadstemc_transfer; double livecrootc_store_to_livecrootc_transfer; double deadcrootc_store_to_deadcrootc_transfer; double gresp_store_to_gresp_transfer; double carbohydrate_transfer; double storage_transfer_prop; double livestemc_to_deadstemc; double livecrootc_to_deadcrootc; double leaf_day_mr; double leaf_night_mr; double froot_mr; double livestem_mr; double livecroot_mr; double total_mr; double cpool_leaf_gr; double transfer_leaf_gr; double cpool_froot_gr; double transfer_froot_gr; double cpool_livestem_gr; double transfer_livestem_gr; double cpool_deadstem_gr; double transfer_deadstem_gr; double cpool_livecroot_gr; double transfer_livecroot_gr; double cpool_deadcroot_gr; double transfer_deadcroot_gr; double transfer_gr; double total_gr; } *


returnWithError

decompiled_code:
__int64 __fastcall returnWithError(char *a1, size_t a2, char *a3)
{
strncpy(a1, a3, a2);
free(a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, size_t a2, char *a3)
{
strncpy(a1, a3, a2);
free(a3);
return 0LL;
}

original_code:
static bool returnWithError(char * const error, size_t error_len, char *error_mesg) {
 strncpy(error, error_mesg, error_len);
 free(error_mesg);
 return false;
}

canonical_original_code:
static short returnWithError(char *error, unsigned long error_len, char *error_mesg) {
 strncpy(error, error_mesg, error_len);
 free(error_mesg);
 return false;
}

variable_types:
error
char *


original_code:
double compute_surface_heat_flux(
          int verbose_flag,
          double snow_stored,
          double rain_stored,
          double rain_capacity,
          double tsurface_initial,
          double tsurface_final,
          double tdeep,
          double deltaz,
          double min_heat_cap,
          double max_heat_cap)
{
 double surface_heat_flux;
 double temp1;
 double temp2;
 tsurface_initial += 273;
 tsurface_final += 273;
 tdeep += 273;
 surface_heat_flux = 0;
 if ( snow_stored == 0 ){
  if (tsurface_initial!=tdeep){
   temp1 = (1 - tdeep/tsurface_initial) / log(tdeep/tsurface_initial )
    * tsurface_initial;
  }
  else{
   temp1 = tdeep;
  }
  if (tsurface_final!=tdeep){
   temp2 = (1 - tdeep/tsurface_final) / log(tdeep/tsurface_final )
    * tsurface_final;
  }
  else{
   temp2 = tdeep;
  }
  if ( rain_capacity > 0 ){
   surface_heat_flux = ((min_heat_cap + (max_heat_cap - min_heat_cap) * (rain_stored / rain_capacity)) > (0) ? (min_heat_cap + (max_heat_cap - min_heat_cap) * (rain_stored / rain_capacity)) : (0)) / deltaz * ( temp1 - temp2 );
  }
  else{
   surface_heat_flux = min_heat_cap * deltaz * (temp1-temp2);
  }
 }
 return(surface_heat_flux/1000);
}

canonical_original_code:
double compute_surface_heat_flux(int verbose_flag, double snow_stored, double rain_stored, double rain_capacity, double tsurface_initial, double tsurface_final, double tdeep, double deltaz, double min_heat_cap, double max_heat_cap)
{
 double surface_heat_flux;
 double temp1;
 double temp2;
 tsurface_initial += 273;
 tsurface_final += 273;
 tdeep += 273;
 surface_heat_flux = 0;
 if ( snow_stored == 0 ){
  if (tsurface_initial!=tdeep){
   temp1 = (1 - tdeep/tsurface_initial) / log(tdeep/tsurface_initial )
    * tsurface_initial;
  }
  else{
   temp1 = tdeep;
  }
  if (tsurface_final!=tdeep){
   temp2 = (1 - tdeep/tsurface_final) / log(tdeep/tsurface_final )
    * tsurface_final;
  }
  else{
   temp2 = tdeep;
  }
  if ( rain_capacity > 0 ){
   surface_heat_flux = ((min_heat_cap + (max_heat_cap - min_heat_cap) * (rain_stored / rain_capacity)) > (0) ? (min_heat_cap + (max_heat_cap - min_heat_cap) * (rain_stored / rain_capacity)) : (0)) / deltaz * ( temp1 - temp2 );
  }
  else{
   surface_heat_flux = min_heat_cap * deltaz * (temp1-temp2);
  }
 }
 return(surface_heat_flux/1000);
}

variable_types: tdeep double

variable_types: deltaz double


original_code:
int update_nitrif(
      struct soil_c_object *cs_soil,
      struct soil_n_object *ns_soil,
      struct cdayflux_patch_struct *cdf,
      struct ndayflux_patch_struct *ndf,
      struct soil_class soil_type,
      double PH,
      double theta,
      double soilT,
      double porosity,
      double organic_soil_depth,
      double nitrif_prop,
      double std)
{
 int ok,i;
 double nitrify;
 double a, b, c, d;
 double nh4_conc, bulk_density, kg_soil;
 double N_scalar, water_scalar, T_scalar, pH_scalar;
 double thetai;
 double max_nit_rate;
 ok = 1;
 max_nit_rate = 0.0;
 if ((theta <= 0.000000001) || (theta > 1.0))
  theta = 1.0;
 if ((ns_soil->sminn > 0.000000001)) {
  bulk_density = 2.65 * (1.0 - porosity) * 1000;
  kg_soil = bulk_density * organic_soil_depth;
  max_nit_rate = kg_soil * 120 * 0.000001;
  nh4_conc = ns_soil->sminn / kg_soil * 1000000.0;
  N_scalar = 1.0 - exp(-0.0105 * nh4_conc);
  if (soil_type.sand > 0.5) {
   a = 0.55; b=1.7; c=-0.007; d=3.22;
  }
  else {
   a=0.6; b=1.27; c=0.0012; d=2.84;
  }
  water_scalar = 0.0;
  if (std > 0.000000001) {
   for (i=0; i<10; i++) {
    thetai = theta + NORMAL[i]*std;
    thetai = ((1.0) < (thetai) ? (1.0) : (thetai));
    thetai = ((0.0) > (thetai) ? (0.0) : (thetai));
    water_scalar += 1.0/10 * (
       pow( ((thetai -b) / (a-b)), d*(b-a)/(a-c))
      * pow( ((thetai-c)/ (a-c)), d) );
    }
   }
  else {
   if (theta > c)
    water_scalar = pow( ((theta -b) / (a-b)), d*(b-a)/(a-c))
    * pow( ((theta-c)/ (a-c)), d);
   else
    water_scalar = 0.000001;
   }
  T_scalar = -0.06 + 0.13 * exp(0.07 * soilT);
  if (T_scalar < 0.000000001) T_scalar = 0.0;
                pH_scalar = 0.56 + (atan(3.14159265359*0.45*(-5+PH))/3.14159265359);
  nitrify = water_scalar * T_scalar * N_scalar * pH_scalar * 120 * ns_soil->sminn * 1000.0;
 }
 else
  nitrify = 0.0;
 nitrify = ((nitrify/1000) < (ns_soil->sminn) ? (nitrify/1000) : (ns_soil->sminn));
 nitrify = ((nitrify) > (0.0) ? (nitrify) : (0.0));
 nitrify = ((nitrify) < (max_nit_rate) ? (nitrify) : (max_nit_rate));
 ndf->sminn_to_nitrate = nitrify;
 ns_soil->sminn -= (nitrify);
 ns_soil->nitrate += (nitrify);
 ok = 0;
 return(ok);
}

canonical_original_code:
int update_nitrif(struct soil_c_object *cs_soil, struct soil_n_object *ns_soil, struct cdayflux_patch_struct *cdf, struct ndayflux_patch_struct *ndf, struct soil_class soil_type, double PH, double theta, double soilT, double porosity, double organic_soil_depth, double nitrif_prop, double std)
{
 int ok; int i;
 double nitrify;
 double a; double b; double c; double d;
 double nh4_conc; double bulk_density; double kg_soil;
 double N_scalar; double water_scalar; double T_scalar; double pH_scalar;
 double thetai;
 double max_nit_rate;
 ok = 1;
 max_nit_rate = 0.0;
 if ((theta <= 0.000000001) || (theta > 1.0))
  theta = 1.0;
 if ((ns_soil->sminn > 0.000000001)) {
  bulk_density = 2.65 * (1.0 - porosity) * 1000;
  kg_soil = bulk_density * organic_soil_depth;
  max_nit_rate = kg_soil * 120 * 0.000001;
  nh4_conc = ns_soil->sminn / kg_soil * 1000000.0;
  N_scalar = 1.0 - exp(-0.0105 * nh4_conc);
  if (soil_type.sand > 0.5) {
   a = 0.55; b=1.7; c=-0.007; d=3.22;
  }
  else {
   a=0.6; b=1.27; c=0.0012; d=2.84;
  }
  water_scalar = 0.0;
  if (std > 0.000000001) {
   for (i=0; i<10; i++) {
    thetai = theta + NORMAL[i]*std;
    thetai = ((1.0) < (thetai) ? (1.0) : (thetai));
    thetai = ((0.0) > (thetai) ? (0.0) : (thetai));
    water_scalar += 1.0/10 * (
       pow( ((thetai -b) / (a-b)), d*(b-a)/(a-c))
      * pow( ((thetai-c)/ (a-c)), d) );
    }
   }
  else {
   if (theta > c)
    water_scalar = pow( ((theta -b) / (a-b)), d*(b-a)/(a-c))
    * pow( ((theta-c)/ (a-c)), d);
   else
    water_scalar = 0.000001;
   }
  T_scalar = -0.06 + 0.13 * exp(0.07 * soilT);
  if (T_scalar < 0.000000001) T_scalar = 0.0;
                pH_scalar = 0.56 + (atan(3.14159265359*0.45*(-5+PH))/3.14159265359);
  nitrify = water_scalar * T_scalar * N_scalar * pH_scalar * 120 * ns_soil->sminn * 1000.0;
 }
 else
  nitrify = 0.0;
 nitrify = ((nitrify/1000) < (ns_soil->sminn) ? (nitrify/1000) : (ns_soil->sminn));
 nitrify = ((nitrify) > (0.0) ? (nitrify) : (0.0));
 nitrify = ((nitrify) < (max_nit_rate) ? (nitrify) : (max_nit_rate));
 ndf->sminn_to_nitrate = nitrify;
 ns_soil->sminn -= (nitrify);
 ns_soil->nitrate += (nitrify);
 ok = 0;
 return(ok);
}

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

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

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

variable_types: PH double

variable_types: theta double

variable_types: soilT double

variable_types: porosity double

variable_types: std double

variable_types: nitrify double

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: d double

variable_types: thetai double

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

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


decompiled_code:
double __fastcall compute_direct_radiative_fluxes(int a1, double *a2, double *a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double v11; // r13
double v12; // r14
double v13; // xmm0_8
double v14; // xmm3_8
double v15; // xmm5_8
double v16; // r13
double v17; // xmm2_8
double v19; // [rsp+0h] [rbp-78h]
double cosx; // [rsp+30h] [rbp-48h] BYREF
double sinx[8]; // [rsp+38h] [rbp-40h] BYREF

sincos(a7, sinx, &cosx);
v11 = cosx;
v12 = sinx[0];
*a3 = a8 * *a2;
v19 = 1.0 - a8;
v13 = (1.0 - a5) * a4 * a6 / v11;
if ( a1 == -5 )
printf("\n DIRRADFLUX: noonext=%lf extcoef=%lf thetanoon=%lf", v13, a4, a7);
if ( v13 >= -0.3 )
v14 = (1.0 - exp(v13 * 1.1)) * v19;
else
v14 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64((1.0 - a9) * ((a7 - 1.570795) * v12 + v11)) ^ LC4)
/ ((1.570795 - a7)
* (1.0 - v12))
* exp(v13)
+ v19;
v15 = *a2 * v14;
v16 = v15;
v17 = (v19 - v14) * *a2;
*a2 = v17;
if ( a1 > 2 )
{
printf("%8.1f %8.1f %8.1f ", *a3, v15, v17);
}
else if ( a1 == -5 )
{
printf("\n fluxrefl=%lf fluxabs=%lf fluxtrans=%lf dayabs=%lf canrefl=%lf", *a3, v15, v17, v14, a8);
}
return v16;
}

canonical_decompiled_code:
double __fastcall func0(int a1, double *a2, double *a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
double v11; // r13
double v12; // r14
double v13; // xmm0_8
double v14; // xmm3_8
double v15; // xmm5_8
double v16; // r13
double v17; // xmm2_8
double v19; // [rsp+0h] [rbp-78h]
double cosx; // [rsp+30h] [rbp-48h] BYREF
double sinx[8]; // [rsp+38h] [rbp-40h] BYREF

sincos(a7, sinx, &cosx);
v11 = cosx;
v12 = sinx[0];
*a3 = a8 * *a2;
v19 = 1.0 - a8;
v13 = (1.0 - a5) * a4 * a6 / v11;
if ( a1 == -5 )
printf("\n DIRRADFLUX: noonext=%lf extcoef=%lf thetanoon=%lf", v13, a4, a7);
if ( v13 >= -0.3 )
v14 = (1.0 - exp(v13 * 1.1)) * v19;
else
v14 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64((1.0 - a9) * ((a7 - 1.570795) * v12 + v11)) ^ LC4)
/ ((1.570795 - a7)
* (1.0 - v12))
* exp(v13)
+ v19;
v15 = *a2 * v14;
v16 = v15;
v17 = (v19 - v14) * *a2;
*a2 = v17;
if ( a1 > 2 )
{
printf("%8.1f %8.1f %8.1f ", *a3, v15, v17);
}
else if ( a1 == -5 )
{
printf("\n fluxrefl=%lf fluxabs=%lf fluxtrans=%lf dayabs=%lf canrefl=%lf", *a3, v15, v17, v14, a8);
}
return v16;
}

original_code:
double compute_direct_radiative_fluxes( int verbose_flag,
          double *flux_down_ptr,
          double *flux_up_ptr,
          double extinction_coef,
          double gap_fraction,
          double proj_pai,
          double theta_noon,
          double reflectance_canopy,
          double reflectance_bkgd)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double unreflected_fraction;
 double day_correction;
 double noon_extinction;
 double noon_transmission;
 double day_absorption;
 *flux_up_ptr = *flux_down_ptr * reflectance_canopy;
 unreflected_fraction = ( 1- reflectance_canopy);
 noon_extinction = extinction_coef*(1-gap_fraction) * proj_pai/cos(theta_noon);
 if ( verbose_flag == -5 ){
  printf("\n          DIRRADFLUX: noonext=%lf extcoef=%lf thetanoon=%lf",noon_extinction, extinction_coef, theta_noon);
 }
 if ( noon_extinction < -0.3 ){
  noon_transmission = exp(noon_extinction);
  day_correction = -1 * (( 1 - reflectance_bkgd )
   * ((theta_noon - 3.14159/2)*sin(theta_noon)
   + cos(theta_noon))) / ((3.14159/2-theta_noon)*(1-sin(theta_noon)));
  day_correction = -1 * (( 1 - reflectance_bkgd )
   * ((theta_noon - 3.14159/2)*sin(theta_noon)
   + cos(theta_noon))) / ((3.14159/2-theta_noon)*(1-sin(theta_noon)));
  day_absorption = unreflected_fraction + day_correction
   * noon_transmission;
 }
 else{
  noon_extinction = ( noon_extinction *1.1 );
  day_absorption = unreflected_fraction * ( 1.0 - exp(noon_extinction) );
 }
 flux_absorbed = *flux_down_ptr * day_absorption;
 flux_transmitted = *flux_down_ptr * (1 - reflectance_canopy - day_absorption );
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f ", *flux_up_ptr,flux_absorbed,
  flux_transmitted);
 if ( verbose_flag == -5 ){
  printf("\n               fluxrefl=%lf fluxabs=%lf fluxtrans=%lf dayabs=%lf canrefl=%lf", *flux_up_ptr,flux_absorbed,
     flux_transmitted, day_absorption, reflectance_canopy);
 }
 return( flux_absorbed );
}

canonical_original_code:
double compute_direct_radiative_fluxes(int verbose_flag, double *flux_down_ptr, double *flux_up_ptr, double extinction_coef, double gap_fraction, double proj_pai, double theta_noon, double reflectance_canopy, double reflectance_bkgd)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double unreflected_fraction;
 double day_correction;
 double noon_extinction;
 double noon_transmission;
 double day_absorption;
 *flux_up_ptr = *flux_down_ptr * reflectance_canopy;
 unreflected_fraction = ( 1- reflectance_canopy);
 noon_extinction = extinction_coef*(1-gap_fraction) * proj_pai/cos(theta_noon);
 if ( verbose_flag == -5 ){
  printf("\n          DIRRADFLUX: noonext=%lf extcoef=%lf thetanoon=%lf",noon_extinction, extinction_coef, theta_noon);
 }
 if ( noon_extinction < -0.3 ){
  noon_transmission = exp(noon_extinction);
  day_correction = -1 * (( 1 - reflectance_bkgd )
   * ((theta_noon - 3.14159/2)*sin(theta_noon)
   + cos(theta_noon))) / ((3.14159/2-theta_noon)*(1-sin(theta_noon)));
  day_correction = -1 * (( 1 - reflectance_bkgd )
   * ((theta_noon - 3.14159/2)*sin(theta_noon)
   + cos(theta_noon))) / ((3.14159/2-theta_noon)*(1-sin(theta_noon)));
  day_absorption = unreflected_fraction + day_correction
   * noon_transmission;
 }
 else{
  noon_extinction = ( noon_extinction *1.1 );
  day_absorption = unreflected_fraction * ( 1.0 - exp(noon_extinction) );
 }
 flux_absorbed = *flux_down_ptr * day_absorption;
 flux_transmitted = *flux_down_ptr * (1 - reflectance_canopy - day_absorption );
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f ", *flux_up_ptr,flux_absorbed,
  flux_transmitted);
 if ( verbose_flag == -5 ){
  printf("\n               fluxrefl=%lf fluxabs=%lf fluxtrans=%lf dayabs=%lf canrefl=%lf", *flux_up_ptr,flux_absorbed,
     flux_transmitted, day_absorption, reflectance_canopy);
 }
 return( flux_absorbed );
}


decompiled_code:
double __fastcall Ksat_z_curve(double a1, double a2, double a3)
{
double v3; // rbx

v3 = a3;
if ( a1 > 0.000000001 )
v3 = a3 * exp(COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC1) / a1);
return v3;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3)
{
double v3; // rbx

v3 = a3;
if ( a1 > 0.000000001 )
v3 = a3 * exp(COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC1) / a1);
return v3;
}

original_code:
double Ksat_z_curve(
      int verbose_flag,
      double m,
      double z,
      double Ksat_0 )
{
 double Ksat_z;
 if ( m > 0.000000001 ){
  Ksat_z = Ksat_0 * exp( -1 * z / m );
 }
 else{
  Ksat_z = Ksat_0;
 }
 return(Ksat_z);
}

canonical_original_code:
double Ksat_z_curve(int verbose_flag, double m, double z, double Ksat_0)
{
 double Ksat_z;
 if ( m > 0.000000001 ){
  Ksat_z = Ksat_0 * exp( -1 * z / m );
 }
 else{
  Ksat_z = Ksat_0;
 }
 return(Ksat_z);
}

variable_types: m double

variable_types: z double


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

if ( !memcmp(ptr, "STATIC", 6uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "static", 6uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "DYNAMIC", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "dynamic", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "CONSTANT", 8uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "constant", 8uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "WARING", 6uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "waring", 6uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "DICKENSON", 9uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "dickenson", 9uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "COMBINED", 8uLL) )
{
v2 = 4;
}
else
{
if ( memcmp(ptr, "combined", 8uLL) )
{
fwrite("\n FATAL ERROR - parse_alloc_flag", 1uLL, 0x20uLL, stderr);
fprintf(stderr, "\n Flag must be static or dynamic and is %s", (const char *)ptr);
exit(1);
}
v2 = 4;
}
free(ptr);
return v2;
}

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

if ( !memcmp(ptr, "STATIC", 6uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "static", 6uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "DYNAMIC", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "dynamic", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "CONSTANT", 8uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "constant", 8uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "WARING", 6uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "waring", 6uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "DICKENSON", 9uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "dickenson", 9uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "COMBINED", 8uLL) )
{
v2 = 4;
}
else
{
if ( memcmp(ptr, "combined", 8uLL) )
{
fwrite("\n FATAL ERROR - parse_alloc_flag", 1uLL, 0x20uLL, stderr);
fprintf(stderr, "\n Flag must be static or dynamic and is %s", (const char *)ptr);
exit(1);
}
v2 = 4;
}
free(ptr);
return v2;
}

original_code:
int parse_alloc_flag( char *input_string)
{
 int alloc_flag;
 if ((strncmp(input_string,"STATIC",6) == 0) ||
  (strncmp(input_string, "static",6) == 0) )
  alloc_flag = 1;
 else if ((strncmp(input_string,"DYNAMIC",7) == 0) ||
  (strncmp(input_string, "dynamic",7) == 0) )
  alloc_flag = 2;
 else if ((strncmp(input_string,"CONSTANT",8) == 0) ||
  (strncmp(input_string, "constant",8) == 0) )
  alloc_flag = 1;
 else if ((strncmp(input_string,"WARING",6) == 0) ||
  (strncmp(input_string, "waring",6) == 0) )
  alloc_flag = 2;
 else if ((strncmp(input_string,"DICKENSON",9) == 0) ||
  (strncmp(input_string, "dickenson",9) == 0) )
  alloc_flag = 3;
 else if ((strncmp(input_string,"COMBINED",8) == 0) ||
  (strncmp(input_string, "combined",8) == 0) )
  alloc_flag = 4;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_alloc_flag");
  fprintf(stderr,"\n Flag must be static or dynamic and is %s" , input_string);
  exit(1);
 }
 free(input_string);
 return(alloc_flag);
}

canonical_original_code:
int parse_alloc_flag(char *input_string)
{
 int alloc_flag;
 if ((strncmp(input_string,"STATIC",6) == 0) ||
  (strncmp(input_string, "static",6) == 0) )
  alloc_flag = 1;
 else if ((strncmp(input_string,"DYNAMIC",7) == 0) ||
  (strncmp(input_string, "dynamic",7) == 0) )
  alloc_flag = 2;
 else if ((strncmp(input_string,"CONSTANT",8) == 0) ||
  (strncmp(input_string, "constant",8) == 0) )
  alloc_flag = 1;
 else if ((strncmp(input_string,"WARING",6) == 0) ||
  (strncmp(input_string, "waring",6) == 0) )
  alloc_flag = 2;
 else if ((strncmp(input_string,"DICKENSON",9) == 0) ||
  (strncmp(input_string, "dickenson",9) == 0) )
  alloc_flag = 3;
 else if ((strncmp(input_string,"COMBINED",8) == 0) ||
  (strncmp(input_string, "combined",8) == 0) )
  alloc_flag = 4;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_alloc_flag");
  fprintf(stderr,"\n Flag must be static or dynamic and is %s" , input_string);
  exit(1);
 }
 free(input_string);
 return(alloc_flag);
}


original_code:
double compute_varbased_returnflow( double std,
         double unsat_storage,
     double sat_deficit ,
     struct litter_object *litter)
{
 double add_to_litter, return_flow,sd;
 double normal[9], perc[9];
 int i;
 normal[0] = 0;
 normal[1] = 0.253;
 normal[2] = 0.524;
 normal[3] = 0.842;
 normal[4] = 1.283;
 normal[5] = -0.253;
 normal[6] = -0.524;
 normal[7] = -0.842;
 normal[8] = -1.283;
 perc[0] = 0.2;
 for (i=1; i<8; i++)
  perc[i] = 0.1;
 return_flow = 0.0;
 if (std > 0.000000001) {
 for (i=0; i <9; i++) {
     sd = (sat_deficit - unsat_storage)
   + std*normal[i];
  if (sd < -1.0*0.000000001)
   return_flow += -1 * sd * perc[i];
 }
 }
 else return_flow = ((-1*(sat_deficit-unsat_storage)) > (0.0) ? (-1*(sat_deficit-unsat_storage)) : (0.0));
 add_to_litter = (((litter[0].rain_capacity - litter[0].rain_stored)) > (0.0) ? ((litter[0].rain_capacity - litter[0].rain_stored)) : (0.0));
 add_to_litter = ((add_to_litter) < (return_flow) ? (add_to_litter) : (return_flow));
 add_to_litter = 0.0;
 return_flow -= add_to_litter;
 litter[0].rain_stored += add_to_litter;
 return(return_flow);
}

canonical_original_code:
double compute_varbased_returnflow(double std, double unsat_storage, double sat_deficit, struct litter_object *litter)
{
 double add_to_litter; double return_flow; double sd;
 double normal[9]; double perc[9];
 int i;
 normal[0] = 0;
 normal[1] = 0.253;
 normal[2] = 0.524;
 normal[3] = 0.842;
 normal[4] = 1.283;
 normal[5] = -0.253;
 normal[6] = -0.524;
 normal[7] = -0.842;
 normal[8] = -1.283;
 perc[0] = 0.2;
 for (i=1; i<8; i++)
  perc[i] = 0.1;
 return_flow = 0.0;
 if (std > 0.000000001) {
 for (i=0; i <9; i++) {
     sd = (sat_deficit - unsat_storage)
   + std*normal[i];
  if (sd < -1.0*0.000000001)
   return_flow += -1 * sd * perc[i];
 }
 }
 else return_flow = ((-1*(sat_deficit-unsat_storage)) > (0.0) ? (-1*(sat_deficit-unsat_storage)) : (0.0));
 add_to_litter = (((litter[0].rain_capacity - litter[0].rain_stored)) > (0.0) ? ((litter[0].rain_capacity - litter[0].rain_stored)) : (0.0));
 add_to_litter = ((add_to_litter) < (return_flow) ? (add_to_litter) : (return_flow));
 add_to_litter = 0.0;
 return_flow -= add_to_litter;
 litter[0].rain_stored += add_to_litter;
 return(return_flow);
}

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

variable_types: sd double

variable_types:
normal
double [9]

variable_types:
perc
double [9]

variable_types: i int


original_code:
double penman_monteith(
      int verbose_flag,
      double Tair,
      double Pair,
      double vpd,
      double Rnet,
      double rs,
      double ra,
      int output_flag)
{
 double dt;
 double rho;
 double lhvap;
 double s;
 double t1;
 double t2;
 double pvs1;
 double pvs2;
 double e;
 double tk;
 double rr;
 double rhr;
 double gamma;
 tk = Tair + 273.15;
 rho = 1.292 - ( 0.00428 * Tair );
 lhvap = 2.5023e6 - 2430.54 * Tair;
 dt = 0.2;
 t1 = Tair + dt;
 t2 = Tair - dt;
 pvs1 = 610.7 * exp(17.38 * t1 / ( 239.0 + t1));
 pvs2 = 610.7 * exp(17.38 * t2 / ( 239.0 + t2));
 s = ( pvs1 - pvs2 ) / ( t1 - t2 );
 gamma = 1010.0 * Pair / ( lhvap );
 e = ((s*Rnet) + (rho*1010.0*vpd/ra)) / (gamma*(1.0 + rs/ra) +s);
 if ( verbose_flag > 2)
  printf("%8.4f %8.4f %8.4f %8.4f %8.1f %8.1f ",s , ra, rs,
  Rnet,gamma,vpd);
 if ( verbose_flag > 2)
  printf("%8.2f %8.4f ",Rnet, vpd);
 if ( verbose_flag == -5) {
  printf("\n          PENMAN: s=%8.4f ra=%8.4f rs=%8.4f Rnet=%8.4f gamma=%8.4f vpd=%8.4f rho=%8.4f CP=%8.4f Tair=%lf Pair=%lf LE=%8.4f e=%8.4f",
      s , ra, rs,
      Rnet,gamma,vpd,
      rho,1010.0,
      Tair,Pair,
      e,
      e / ( lhvap * 1000 ) * 1000.0);
 }
 if ( output_flag == 0 ){
  return ( e / lhvap );
 }
 else if ( output_flag == 1 ){
  return(e);
 }
 else if ( output_flag == 2 ){
  if ( verbose_flag > 2)
   printf("%8.4f",e );
  return( e / ( lhvap * 1000 ));
 }
 else{
  fprintf(stderr,"FATAL ERROR: in penman_monteith - invalid output flag");
  exit(1);
 }
}

canonical_original_code:
double penman_monteith(int verbose_flag, double Tair, double Pair, double vpd, double Rnet, double rs, double ra, int output_flag)
{
 double dt;
 double rho;
 double lhvap;
 double s;
 double t1;
 double t2;
 double pvs1;
 double pvs2;
 double e;
 double tk;
 double rr;
 double rhr;
 double gamma;
 tk = Tair + 273.15;
 rho = 1.292 - ( 0.00428 * Tair );
 lhvap = 2.5023e6 - 2430.54 * Tair;
 dt = 0.2;
 t1 = Tair + dt;
 t2 = Tair - dt;
 pvs1 = 610.7 * exp(17.38 * t1 / ( 239.0 + t1));
 pvs2 = 610.7 * exp(17.38 * t2 / ( 239.0 + t2));
 s = ( pvs1 - pvs2 ) / ( t1 - t2 );
 gamma = 1010.0 * Pair / ( lhvap );
 e = ((s*Rnet) + (rho*1010.0*vpd/ra)) / (gamma*(1.0 + rs/ra) +s);
 if ( verbose_flag > 2)
  printf("%8.4f %8.4f %8.4f %8.4f %8.1f %8.1f ",s , ra, rs,
  Rnet,gamma,vpd);
 if ( verbose_flag > 2)
  printf("%8.2f %8.4f ",Rnet, vpd);
 if ( verbose_flag == -5) {
  printf("\n          PENMAN: s=%8.4f ra=%8.4f rs=%8.4f Rnet=%8.4f gamma=%8.4f vpd=%8.4f rho=%8.4f CP=%8.4f Tair=%lf Pair=%lf LE=%8.4f e=%8.4f",
      s , ra, rs,
      Rnet,gamma,vpd,
      rho,1010.0,
      Tair,Pair,
      e,
      e / ( lhvap * 1000 ) * 1000.0);
 }
 if ( output_flag == 0 ){
  return ( e / lhvap );
 }
 else if ( output_flag == 1 ){
  return(e);
 }
 else if ( output_flag == 2 ){
  if ( verbose_flag > 2)
   printf("%8.4f",e );
  return( e / ( lhvap * 1000 ));
 }
 else{
  fprintf(stderr,"FATAL ERROR: in penman_monteith - invalid output flag");
  exit(1);
 }
}

variable_types: Tair double

variable_types: Pair double

variable_types: vpd double

variable_types: Rnet double

variable_types: rs double

variable_types: ra double

variable_types: dt double

variable_types: rho double

variable_types: lhvap double

variable_types: s double

variable_types: e double

variable_types: tk double

variable_types: rr double

variable_types: rhr double

variable_types: gamma double


original_code:
double compute_infiltration(int verbose_flag,
        double z,
        double S,
        double Ksat_vertical,
        double Ksat_0,
        double m_z,
        double p_0,
        double p,
        double precip,
        double duration,
        double psi_air_entry)
{
 double porosity;
 double Ksat;
 double Sp;
 double psi_f;
 double theta;
 double intensity, tp,t;
 double infiltration;
 if ((S < 1.0) && (Ksat_0 > 0.000000001)) {
 if (m_z > 0.000000001)
  Ksat = m_z * Ksat_0 * (1-exp(-z/m_z))/z;
 else
  Ksat = Ksat_0;
 if (p < 999.9)
  porosity = p*p_0*(1-exp(-z/p))/z;
 else
  porosity = p_0;
 theta = S*porosity;
 psi_f = 0.76 * psi_air_entry;
 Sp = pow(2 * Ksat * (psi_f),0.5);
 intensity = precip/duration;
 if (intensity > Ksat)
  tp = Ksat * psi_f * (porosity-theta) / (intensity * (intensity-Ksat));
 else
  tp = duration;
 t = duration - tp;
 if (duration <= tp)
  infiltration = precip;
 else
  infiltration = Sp * pow(t, 0.5) +Ksat*1.5/3.0 * t + tp * intensity;
 }
 else
  infiltration = 0.0;
 if (infiltration > precip)
  infiltration = precip;
 if (infiltration < 0.000000001)
  infiltration = 0.0;
 infiltration = infiltration * Ksat_vertical;
 return(infiltration);
}

canonical_original_code:
double compute_infiltration(int verbose_flag, double z, double S, double Ksat_vertical, double Ksat_0, double m_z, double p_0, double p, double precip, double duration, double psi_air_entry)
{
 double porosity;
 double Ksat;
 double Sp;
 double psi_f;
 double theta;
 double intensity; double tp; double t;
 double infiltration;
 if ((S < 1.0) && (Ksat_0 > 0.000000001)) {
 if (m_z > 0.000000001)
  Ksat = m_z * Ksat_0 * (1-exp(-z/m_z))/z;
 else
  Ksat = Ksat_0;
 if (p < 999.9)
  porosity = p*p_0*(1-exp(-z/p))/z;
 else
  porosity = p_0;
 theta = S*porosity;
 psi_f = 0.76 * psi_air_entry;
 Sp = pow(2 * Ksat * (psi_f),0.5);
 intensity = precip/duration;
 if (intensity > Ksat)
  tp = Ksat * psi_f * (porosity-theta) / (intensity * (intensity-Ksat));
 else
  tp = duration;
 t = duration - tp;
 if (duration <= tp)
  infiltration = precip;
 else
  infiltration = Sp * pow(t, 0.5) +Ksat*1.5/3.0 * t + tp * intensity;
 }
 else
  infiltration = 0.0;
 if (infiltration > precip)
  infiltration = precip;
 if (infiltration < 0.000000001)
  infiltration = 0.0;
 infiltration = infiltration * Ksat_vertical;
 return(infiltration);
}

variable_types: z double

variable_types: S double

variable_types: p double

variable_types: precip double

variable_types: duration double

variable_types: porosity double

variable_types: Ksat double

variable_types: Sp double

variable_types: theta double

variable_types: intensity double

variable_types: tp double

variable_types: t double

variable_types: infiltration double


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

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

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

variable_types: struct landuse_default { int ID; int msr_sat_transfer_flag; int shading_flag; double fertilizer_NO3; double fertilizer_NH4; double irrigation; double PH; double septic_NO3_load; double septic_water_load; double detention_store_size; double lai_cut; double percent_impervious; double grazing_Closs; double sh_l; double sh_g; } *


julday

original_code:
long julday( struct date calendar_date )
{
 long jul;
 int ja, jy, jm;
 if (calendar_date.year == 0) {
  return(0);
 }
 if (calendar_date.year < 0) ++(calendar_date.year);
 if (calendar_date.month > 2) {
  jy = calendar_date.year;
  jm = calendar_date.month+1;
 }
 else {
  jy = calendar_date.year - 1;
  jm = calendar_date.month + 13;
 }
 jul= (long)(floor(365.25 * jy) + floor(30.6001 * jm)
  + calendar_date.day + 1720995);
 if (calendar_date.day + 31L * (calendar_date.month + 12L *calendar_date.year)
  >= (15+31L*(10+12L*1582))) {
  ja = (int)(0.01 * jy);
  jul += (2 - ja + (int)(0.25 * ja));
 }
 return jul;
}

canonical_original_code:
long julday(struct date calendar_date)
{
 long jul;
 int ja; int jy; int jm;
 if (calendar_date.year == 0) {
  return(0);
 }
 if (calendar_date.year < 0) ++(calendar_date.year);
 if (calendar_date.month > 2) {
  jy = calendar_date.year;
  jm = calendar_date.month+1;
 }
 else {
  jy = calendar_date.year - 1;
  jm = calendar_date.month + 13;
 }
 jul= (long)(floor(365.25 * jy) + floor(30.6001 * jm)
  + calendar_date.day + 1720995);
 if (calendar_date.day + 31L * (calendar_date.month + 12L *calendar_date.year)
  >= (15+31L*(10+12L*1582))) {
  ja = (int)(0.01 * jy);
  jul += (2 - ja + (int)(0.25 * ja));
 }
 return jul;
}

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

variable_types: jul long

variable_types: ja int

variable_types: jy int

variable_types: jm int

return_type: long