getIntParam

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

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

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

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

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

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

variable_types:
paramCnt
int *

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

variable_types:
paramName
char *

variable_types:
readFormat
char *

variable_types: defaultVal int

variable_types: useDefaultVal int

variable_types: iParam int

variable_types: paramInd int

variable_types: sLen int

variable_types: intVal int

variable_types: found int


getFloatParam

repo: RHESSys/RHESSys

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

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

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

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

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

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

variable_types: defaultVal float

variable_types: floatVal float

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

return_type: float


getDoubleParam

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

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

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

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

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

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

variable_types: defaultVal double

variable_types: doubleVal double

return_type: double

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


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

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

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

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

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

variable_types:
s
char *

variable_types: c int

return_type: int


getStrParam

decompiled_code:
void *__fastcall getStrParam(int *a1, void **a2, const char *a3, const char *a4, char *a5, int a6)
{
char *v7; // r15
int v8; // er14
char *v9; // rbx
char *v10; // r12
char *v11; // rax
char *v12; // rbp
int v13; // eax
void *v14; // rbx
int v15; // edx
char *v16; // rbx
int v17; // eax

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

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

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

variable_types:
paramCnt
int *

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

variable_types:
defaultVal
char *

variable_types:
outStr
char *

return_type: char *


getStrWorldfile

decompiled_code:
void *__fastcall getStrWorldfile(int *a1, const char **a2, const char *a3, const char *a4, void *a5, int a6)
{
const char *v9; // rbx
__int64 v10; // r13
const char *v11; // r12
_BYTE *v13; // rbx
int v14; // eax

if ( *a1 <= 0 )
{
LABEL_5:
if ( !a6 )
{
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
else
{
v9 = *a2;
v10 = (__int64)&(*a2)[1072 * (*a1 - 1) + 1072];
while ( 1 )
{
v11 = v9;
if ( !strcmp(v9, a3) )
break;
v9 += 1072;
if ( v9 == (const char *)v10 )
goto LABEL_5;
}
v13 = v9 + 32;
v14 = string_length(v13);
a5 = malloc(v14);
_isoc99_sscanf(v13, a4, a5);
*((_DWORD *)v11 + 266) = 1;
strcpy((char *)v11 + 1056, a4);
}
return a5;
}

canonical_decompiled_code:
void *__fastcall func7(int *a1, const char **a2, const char *a3, const char *a4, void *a5, int a6)
{
const char *v9; // rbx
__int64 v10; // r13
const char *v11; // r12
_BYTE *v13; // rbx
int v14; // eax

if ( *a1 <= 0 )
{
LABEL_5:
if ( !a6 )
{
printf("\nNo parameter value found for %s and 'useDefault' flag set to false\n", a3);
exit(1);
}
}
else
{
v9 = *a2;
v10 = (__int64)&(*a2)[1072 * (*a1 - 1) + 1072];
while ( 1 )
{
v11 = v9;
if ( !strcmp(v9, a3) )
break;
v9 += 1072;
if ( v9 == (const char *)v10 )
goto LABEL_5;
}
v13 = v9 + 32;
v14 = func5(v13);
a5 = malloc(v14);
_isoc99_sscanf(v13, a4, a5);
*((_DWORD *)v11 + 266) = 1;
strcpy((char *)v11 + 1056, a4);
}
return a5;
}

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

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

variable_types:
paramName
char *

variable_types:
readFormat
char *

variable_types: useDefaultVal int


getIntWorldfile

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

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

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

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

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

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

variable_types: defaultVal int

variable_types: iParam int

variable_types: paramInd int

variable_types: sLen int


getFloatWorldfile

decompiled_code:
float __fastcall getFloatWorldfile(int *a1, __int64 *a2, const char *a3, const char *a4, int a5, float a6)
{
__int64 v9; // rbx
__int64 v10; // r13
float v13; // [rsp+1Ch] [rbp-3Ch] BYREF

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

canonical_decompiled_code:
float __fastcall func9(int *a1, __int64 *a2, const char *a3, const char *a4, int a5, float a6)
{
__int64 v9; // rbx
__int64 v10; // r13
float v13; // [rsp+1Ch] [rbp-3Ch] BYREF

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

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

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

variable_types: defaultVal float

variable_types: floatVal float

variable_types: found int


getDoubleWorldfile

decompiled_code:
double __fastcall getDoubleWorldfile(int *a1, __int64 *a2, const char *a3, const char *a4, int a5)
{
__int64 v8; // rbx
__int64 v9; // r13
double result; // xmm0_8
double v11; // [rsp+18h] [rbp-40h] BYREF

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

canonical_decompiled_code:
double __fastcall func10(int *a1, __int64 *a2, const char *a3, const char *a4, int a5)
{
__int64 v8; // rbx
__int64 v9; // r13
double result; // xmm0_8
double v11; // [rsp+18h] [rbp-40h] BYREF

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

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

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

variable_types: defaultVal double

variable_types: doubleVal double

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


decompiled_code:
double __fastcall compute_z_final(double a1, double a2, double a3, double a4, double a5)
{
double v5; // rbp
double v6; // rbx
double v7; // xmm0_8
double result; // xmm0_8
double v9; // xmm0_8
double v10; // xmm1_8

v5 = a1;
v6 = a2;
if ( a2 <= 0.00000001 )
v6 = *(double *)&LC0;
if ( a1 <= 0.00000001 )
v5 = *(double *)&LC0;
if ( a4 <= 0.0 )
{
if ( a5 < 0.0 )
{
result = a4 - a5;
if ( a4 - a5 > 0.0 )
{
*(_QWORD *)&v9 = *(_QWORD *)&result ^ LC2;
if ( v6 < 999.9 )
result = log(v9 / (v5 * v6) + 1.0) * COERCE_DOUBLE(*(_QWORD *)&v6 ^ LC2);
else
result = 0.0 - v9 / v5;
}
}
else
{
result = a4 - a5;
}
}
else
{
v7 = compute_delta_water(v5, v6, a3, a4, 0.0);
if ( v7 > a5 )
{
v10 = a5 / (v5 * v6) + exp(COERCE_DOUBLE(*(_QWORD *)&a4 ^ LC2) / v6);
result = a3;
if ( v10 > 0.0 )
result = log(v10) * COERCE_DOUBLE(*(_QWORD *)&v6 ^ LC2);
}
else
{
result = v7 - a5;
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, double a4, double a5)
{
double v5; // rbp
double v6; // rbx
double v7; // xmm0_8
double result; // xmm0_8
double v9; // xmm0_8
double v10; // xmm1_8

v5 = a1;
v6 = a2;
if ( a2 <= 0.00000001 )
v6 = *(double *)&LC0;
if ( a1 <= 0.00000001 )
v5 = *(double *)&LC0;
if ( a4 <= 0.0 )
{
if ( a5 < 0.0 )
{
result = a4 - a5;
if ( a4 - a5 > 0.0 )
{
*(_QWORD *)&v9 = *(_QWORD *)&result ^ LC2;
if ( v6 < 999.9 )
result = log(v9 / (v5 * v6) + 1.0) * COERCE_DOUBLE(*(_QWORD *)&v6 ^ LC2);
else
result = 0.0 - v9 / v5;
}
}
else
{
result = a4 - a5;
}
}
else
{
v7 = compute_delta_water(v5, v6, a3, a4, 0.0);
if ( v7 > a5 )
{
v10 = a5 / (v5 * v6) + exp(COERCE_DOUBLE(*(_QWORD *)&a4 ^ LC2) / v6);
result = a3;
if ( v10 > 0.0 )
result = log(v10) * COERCE_DOUBLE(*(_QWORD *)&v6 ^ LC2);
}
else
{
result = v7 - a5;
}
}
return result;
}

original_code:
double compute_z_final(
      int verbose_flag,
      double p_0,
      double p,
      double soil_depth,
      double z_initial,
      double delta_water)
{
 double compute_delta_water(
  int,
  double,
  double,
  double,
  double,
  double);
 double arguement;
 double delta_water_surf;
 double z_final;
 p = ((p) > (0.00000001) ? (p) : (0.00000001));
 p_0 = ((p_0) > (0.00000001) ? (p_0) : (0.00000001));
 if ( (z_initial<=0) && (delta_water>=0) ){
  z_final = z_initial - delta_water;
 }
 else if ( (z_initial<=0) && (delta_water<0) ){
  z_final = z_initial - delta_water;
  if ( z_final > 0 ){
   delta_water = -1 * z_final;
   if (p < 999.9) {
     z_final = -1 * p *
      log( 1 + delta_water / ( p * p_0) );
   }
   else
     z_final = (0 - delta_water/p_0);
  }
 }
 else{
  delta_water_surf =
   compute_delta_water(
   verbose_flag,
   p_0,
   p,
   soil_depth,
   z_initial,
   0);
  if ( delta_water < delta_water_surf ){
   arguement = ( exp( -1 * z_initial/p) + delta_water / (p*p_0));
   if ( arguement > 0 ){
    z_final = -1 * p * log(arguement);
   }
   else{
    z_final = soil_depth;
   }
  }
  else{
   z_final = delta_water_surf - delta_water;
  }
 }
 return(z_final);
}

canonical_original_code:
double compute_z_final(int verbose_flag, double p_0, double p, double soil_depth, double z_initial, double delta_water)
{
 double compute_delta_water(int, double, double, double, double, double);
 double arguement;
 double delta_water_surf;
 double z_final;
 p = ((p) > (0.00000001) ? (p) : (0.00000001));
 p_0 = ((p_0) > (0.00000001) ? (p_0) : (0.00000001));
 if ( (z_initial<=0) && (delta_water>=0) ){
  z_final = z_initial - delta_water;
 }
 else if ( (z_initial<=0) && (delta_water<0) ){
  z_final = z_initial - delta_water;
  if ( z_final > 0 ){
   delta_water = -1 * z_final;
   if (p < 999.9) {
     z_final = -1 * p *
      log( 1 + delta_water / ( p * p_0) );
   }
   else
     z_final = (0 - delta_water/p_0);
  }
 }
 else{
  delta_water_surf =
   compute_delta_water(
   verbose_flag,
   p_0,
   p,
   soil_depth,
   z_initial,
   0);
  if ( delta_water < delta_water_surf ){
   arguement = ( exp( -1 * z_initial/p) + delta_water / (p*p_0));
   if ( arguement > 0 ){
    z_final = -1 * p * log(arguement);
   }
   else{
    z_final = soil_depth;
   }
  }
  else{
   z_final = delta_water_surf - delta_water;
  }
 }
 return(z_final);
}

variable_types: p double

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

variable_types: arguement double


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

if ( a5 )
{
v8 = calloc(1uLL, 0x18uLL);
if ( v8 )
{
*v8 = a1;
v8[1] = a2;
*((_QWORD *)v8 + 1) = a3;
*((_QWORD *)v8 + 2) = a4;
*a5 = v8;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate memory for the impervious search context.\n", 1uLL, 0x44uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return impervious context pointer is NULL.\n", 1uLL, 0x32uLL, stderr);
result = 0LL;
}
return result;
}

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

if ( a5 )
{
v8 = calloc(1uLL, 0x18uLL);
if ( v8 )
{
*v8 = a1;
v8[1] = a2;
*((_QWORD *)v8 + 1) = a3;
*((_QWORD *)v8 + 2) = a4;
*a5 = v8;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate memory for the impervious search context.\n", 1uLL, 0x44uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return impervious context pointer is NULL.\n", 1uLL, 0x32uLL, stderr);
result = 0LL;
}
return result;
}

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

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

variable_types: result short

variable_types: struct impervious_context_s { int maxr_; int maxc_; double *roofs_; int *impervious_; } *

return_type: short


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

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

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

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

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

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

variable_types: index int

user_defined_types: struct impervious_context_s { int maxr_; int maxc_; double *roofs_; int *impervious_; }


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

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

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

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


original_code:
double compute_diffuse_radiative_PAR_fluxes( int verbose_flag,
            double *flux_down_ptr,
            double direct_flux,
            double extinction_coef,
            double gap_fraction,
            double lai,
            double theta_noon,
            double reflectance_canopy)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double S;
 flux_reflected = *flux_down_ptr * reflectance_canopy;
 if ( *flux_down_ptr != 0 ){
  S = 0.07 * ( direct_flux / *flux_down_ptr ) *
   ((0) > (1.1- 0.1 * lai * (1- gap_fraction)) ? (0) : (1.1- 0.1 * lai * (1- gap_fraction))) * exp( -1 * cos(theta_noon));
 }
 else{
  S = 0;
 }
 flux_absorbed = ( *flux_down_ptr - flux_reflected)
  * ( 1 - exp(-0.5 * pow(lai*(1-gap_fraction),0.7)) + S);
 flux_transmitted = *flux_down_ptr - flux_reflected - flux_absorbed ;
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f ",
  flux_reflected,flux_absorbed,flux_transmitted);
 return( flux_absorbed );
}

canonical_original_code:
double compute_diffuse_radiative_PAR_fluxes(int verbose_flag, double *flux_down_ptr, double direct_flux, double extinction_coef, double gap_fraction, double lai, double theta_noon, double reflectance_canopy)
{
 double flux_reflected;
 double flux_transmitted;
 double flux_absorbed;
 double S;
 flux_reflected = *flux_down_ptr * reflectance_canopy;
 if ( *flux_down_ptr != 0 ){
  S = 0.07 * ( direct_flux / *flux_down_ptr ) *
   ((0) > (1.1- 0.1 * lai * (1- gap_fraction)) ? (0) : (1.1- 0.1 * lai * (1- gap_fraction))) * exp( -1 * cos(theta_noon));
 }
 else{
  S = 0;
 }
 flux_absorbed = ( *flux_down_ptr - flux_reflected)
  * ( 1 - exp(-0.5 * pow(lai*(1-gap_fraction),0.7)) + S);
 flux_transmitted = *flux_down_ptr - flux_reflected - flux_absorbed ;
 *flux_down_ptr = flux_transmitted;
 if( verbose_flag > 2)
  printf("%8.1f %8.1f %8.1f ",
  flux_reflected,flux_absorbed,flux_transmitted);
 return( flux_absorbed );
}

variable_types: lai double

variable_types: S double


decompiled_code:
double __fastcall compute_N_absorbed(double a1, double a2, double a3, double a4, double a5)
{
double result; // xmm0_8

result = (1.0 - a5) * 2.65 * 1000.0 * ((a2 - a1) * a5 * a3);
if ( result <= 0.0 )
result = 0.0;
return result;
}

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

result = (1.0 - a5) * 2.65 * 1000.0 * ((a2 - a1) * a5 * a3);
if ( result <= 0.0 )
result = 0.0;
return result;
}

original_code:
double compute_N_absorbed(int verbose_flag,
   double z1,
   double z2,
   double N_absorption_rate,
   double p,
   double n_0)
 {
 double nabsorbed;
 double bulk_density;
 bulk_density = 2.65 * (1.0 - n_0) * 1000;
 nabsorbed=n_0*(z2-z1)*N_absorption_rate*bulk_density;
 nabsorbed=((nabsorbed) > (0.0) ? (nabsorbed) : (0.0));
 return(nabsorbed);
}

variable_types: nabsorbed double


decompiled_code:
double __fastcall compute_nonvascular_stratum_conductance(double a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm5_8
double v6; // xmm2_8
double result; // xmm0_8

v5 = a1 - 0.001;
if ( a1 - 0.001 < 0.0 )
v5 = 0.0;
v6 = 0.0;
if ( a2 >= 1.0e-14 )
{
v6 = (v5 + a1) * 0.5 / a2;
if ( v6 < 0.0 )
v6 = 0.0;
}
result = a5 + v6 * a4;
if ( result <= 0.0 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm5_8
double v6; // xmm2_8
double result; // xmm0_8

v5 = a1 - 0.001;
if ( a1 - 0.001 < 0.0 )
v5 = 0.0;
v6 = 0.0;
if ( a2 >= 1.0e-14 )
{
v6 = (v5 + a1) * 0.5 / a2;
if ( v6 < 0.0 )
v6 = 0.0;
}
result = a5 + v6 * a4;
if ( result <= 0.0 )
result = 0.0;
return result;
}

original_code:
double compute_nonvascular_stratum_conductance(
            int verbose_flag,
            double rain_stored,
            double rain_capacity,
            double gl_c,
            double gsurf_slope,
            double gsurf_intercept)
{
 double approx_day_end_storage;
 double adjusted_storage;
 double stratum_conductance;
 approx_day_end_storage = ((0) > (rain_stored - 0.001) ? (0) : (rain_stored - 0.001));
 if (rain_capacity < 0.00000000000001)
  adjusted_storage = 0.0;
 else
  adjusted_storage = ((0) > (((rain_stored + approx_day_end_storage )/2.0) / ( rain_capacity)) ? (0) : (((rain_stored + approx_day_end_storage )/2.0) / ( rain_capacity)));
 stratum_conductance = ((gsurf_slope*adjusted_storage + gsurf_intercept) > (0) ? (gsurf_slope*adjusted_storage + gsurf_intercept) : (0));
 return(stratum_conductance);
}

canonical_original_code:
double compute_nonvascular_stratum_conductance(int verbose_flag, double rain_stored, double rain_capacity, double gl_c, double gsurf_slope, double gsurf_intercept)
{
 double approx_day_end_storage;
 double adjusted_storage;
 double stratum_conductance;
 approx_day_end_storage = ((0) > (rain_stored - 0.001) ? (0) : (rain_stored - 0.001));
 if (rain_capacity < 0.00000000000001)
  adjusted_storage = 0.0;
 else
  adjusted_storage = ((0) > (((rain_stored + approx_day_end_storage )/2.0) / ( rain_capacity)) ? (0) : (((rain_stored + approx_day_end_storage )/2.0) / ( rain_capacity)));
 stratum_conductance = ((gsurf_slope*adjusted_storage + gsurf_intercept) > (0) ? (gsurf_slope*adjusted_storage + gsurf_intercept) : (0));
 return(stratum_conductance);
}


decompiled_code:
double __fastcall grid_dist(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8
double result; // xmm0_8

v4 = (double)((a3 - a4) * (a3 - a4) + (a1 - a2) * (a1 - a2));
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

canonical_decompiled_code:
double __fastcall func0(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8
double result; // xmm0_8

v4 = (double)((a3 - a4) * (a3 - a4) + (a1 - a2) * (a1 - a2));
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

original_code:
static double grid_dist(int _row1, int _row2, int _col1, int _col2) {
 int squaredDist = 0;
 squaredDist = (_row1 - _row2) * (_row1 - _row2)
   + (_col1 - _col2) * (_col1 - _col2);
 return sqrt( (double)squaredDist );
}

variable_types: squaredDist int


decompiled_code:
__int64 __fastcall grid_search(int a1, unsigned int a2, unsigned int a3, signed int a4, signed int a5, unsigned __int16 (__fastcall *a6)(_QWORD, _QWORD, _QWORD, _QWORD, __int64, int *), __int64 (__fastcall *a7)(_QWORD, _QWORD, _QWORD, _QWORD, __int64, unsigned int *, unsigned int *), __int64 a8, unsigned int *a9, unsigned int *a10, __int16 *a11)
{
double v13; // xmm1_8
double v14; // xmm0_8
__int16 v15; // r15
unsigned int v16; // ebp
int v17; // er15
int v18; // er15
double v19; // xmm1_8
double v20; // xmm0_8
int v21; // ebx
double v22; // xmm1_8
double v23; // xmm0_8
__int16 v24; // r15
double v26; // xmm1_8
double v27; // xmm0_8
unsigned __int16 v28; // bp
unsigned int v29; // ebp
int v30; // er15
int v31; // er15
unsigned int v32; // ebx
unsigned int v33; // esi
int v34; // eax
signed int v35; // eax
unsigned __int16 v37; // [rsp+6h] [rbp-72h]
int v38; // [rsp+8h] [rbp-70h]
unsigned int v39; // [rsp+Ch] [rbp-6Ch]
double v40; // [rsp+10h] [rbp-68h]
__int16 v41; // [rsp+1Ch] [rbp-5Ch]
__int16 v42; // [rsp+1Eh] [rbp-5Ah]
int v43; // [rsp+20h] [rbp-58h]
unsigned int v46; // [rsp+34h] [rbp-44h] BYREF
unsigned int v47; // [rsp+38h] [rbp-40h] BYREF
int v48[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( !a6 )
{
fwrite("ERROR: Predicate function pointer is NULL.\n", 1uLL, 0x2BuLL, stderr);
return 0;
}
if ( !a8 )
{
fwrite("ERROR: Predicate context pointer is NULL.\n", 1uLL, 0x2AuLL, stderr);
return 0;
}
if ( !a9 )
{
fwrite("ERROR: Return row pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
return 0;
}
if ( !a10 )
{
fwrite("ERROR: Return column pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
return 0;
}
if ( !a11 )
{
fwrite("ERROR: Return found pointer is NULL.\n", 1uLL, 0x25uLL, stderr);
return 0;
}
v46 = 0;
v47 = 0;
if ( a1 <= 1 )
{
v42 = 0;
v37 = 1;
goto LABEL_46;
}
v43 = 1;
v40 = *(double *)&LC1;
v42 = 0;
v37 = 1;
v41 = 1;
while ( 1 )
{
v32 = a2 - v43;
if ( (int)(a2 - v43) < 0 )
v32 = 0;
v33 = a3 - v43;
if ( (int)(a3 - v43) < 0 )
v33 = 0;
v34 = a2 + v43;
if ( (int)(a2 + v43) > a4 )
v34 = a4;
v38 = v34;
v35 = v43 + a3;
if ( (int)(v43 + a3) > a5 )
v35 = a5;
v39 = v35;
if ( !v37 || v35 < (int)v33 )
break;
v16 = v33;
while ( 1 )
{
v48[0] = 0;
if ( !a6(a2, a3, v32, v16, a8, v48) )
{
v41 = 0;
goto LABEL_26;
}
v17 = v48[0];
if ( v48[0] )
{
v13 = grid_dist(a2, v32, a3, v16);
v14 = (double)v17 * v13;
if ( v40 > v14 )
{
v46 = v32;
v47 = v16;
v40 = (double)v17 * v13;
v42 = 1;
goto LABEL_30;
}
if ( v14 == v40 )
{
if ( v42 )
{
v15 = a7(v46, v47, v32, v16, a8, &v46, &v47);
if ( !v15 )
break;
}
}
}
LABEL_30:
v48[0] = 0;
if ( a6(a2, a3, (unsigned int)v38, v16, a8, v48) )
goto LABEL_31;
v41 = 0;
LABEL_26:
++v16;
if ( !v37 || (int)v39 < (int)v16 )
goto LABEL_35;
}
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
v48[0] = 0;
if ( !a6(a2, a3, (unsigned int)v38, v16, a8, v48) )
goto LABEL_19;
v37 = v15;
v41 = v15;
LABEL_31:
v18 = v48[0];
if ( !v48[0] )
goto LABEL_26;
v19 = grid_dist(a2, v38, a3, v16);
v20 = (double)v18 * v19;
if ( v40 > v20 )
{
v46 = v38;
v47 = v16;
v40 = (double)v18 * v19;
v42 = 1;
goto LABEL_26;
}
if ( v20 != v40 || !v42 || (unsigned __int16)a7(v46, v47, (unsigned int)v38, v16, a8, &v46, &v47) )
goto LABEL_26;
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
LABEL_19:
v37 = 0;
v41 = 0;
LABEL_67:
++v43;
if ( !v41 || a1 <= v43 )
{
v28 = v37;
goto LABEL_55;
}
}
LABEL_35:
if ( v38 <= (int)(v32 + 1) || !v37 )
goto LABEL_67;
v21 = v32 + 2;
while ( 2 )
{
v29 = v21 - 1;
v48[0] = 0;
if ( !a6(a2, a3, (unsigned int)(v21 - 1), v33, a8, v48) )
{
LABEL_58:
if ( v38 <= v21 )
goto LABEL_44;
v41 = 0;
LABEL_60:
++v21;
continue;
}
break;
}
v30 = v48[0];
if ( !v48[0] )
goto LABEL_63;
v22 = grid_dist(a2, v29, a3, v33);
v23 = (double)v30 * v22;
if ( v40 > v23 )
{
v46 = v21 - 1;
v47 = v33;
v40 = (double)v30 * v22;
v42 = 1;
goto LABEL_63;
}
if ( v23 != v40 || !v42 || (v24 = a7(v46, v47, v29, v33, a8, &v46, &v47)) != 0 )
{
LABEL_63:
v48[0] = 0;
if ( a6(a2, a3, v29, v39, a8, v48) )
goto LABEL_64;
goto LABEL_58;
}
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
v48[0] = 0;
v37 = a6(a2, a3, v29, v39, a8, v48);
if ( !v37 )
goto LABEL_44;
v37 = v24;
v41 = v24;
LABEL_64:
v31 = v48[0];
if ( !v48[0] )
{
LABEL_65:
if ( !v37 || v38 <= v21 )
goto LABEL_67;
goto LABEL_60;
}
v26 = grid_dist(a2, v29, a3, v39);
v27 = (double)v31 * v26;
if ( v40 > v27 )
{
v46 = v21 - 1;
v47 = v39;
v40 = (double)v31 * v26;
v42 = 1;
goto LABEL_65;
}
if ( v27 != v40 )
goto LABEL_65;
if ( !v42 )
goto LABEL_65;
v28 = a7(v46, v47, v29, v39, a8, &v46, &v47);
if ( v28 )
goto LABEL_65;
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
LABEL_55:
v37 = v28;
LABEL_44:
if ( v42 )
{
*a9 = v46;
*a10 = v47;
}
LABEL_46:
*a11 = v42;
return v37;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned int a2, unsigned int a3, signed int a4, signed int a5, unsigned __int16 (__fastcall *a6)(_QWORD, _QWORD, _QWORD, _QWORD, __int64, int *), __int64 (__fastcall *a7)(_QWORD, _QWORD, _QWORD, _QWORD, __int64, unsigned int *, unsigned int *), __int64 a8, unsigned int *a9, unsigned int *a10, __int16 *a11)
{
double v13; // xmm1_8
double v14; // xmm0_8
__int16 v15; // r15
unsigned int v16; // ebp
int v17; // er15
int v18; // er15
double v19; // xmm1_8
double v20; // xmm0_8
int v21; // ebx
double v22; // xmm1_8
double v23; // xmm0_8
__int16 v24; // r15
double v26; // xmm1_8
double v27; // xmm0_8
unsigned __int16 v28; // bp
unsigned int v29; // ebp
int v30; // er15
int v31; // er15
unsigned int v32; // ebx
unsigned int v33; // esi
int v34; // eax
signed int v35; // eax
unsigned __int16 v37; // [rsp+6h] [rbp-72h]
int v38; // [rsp+8h] [rbp-70h]
unsigned int v39; // [rsp+Ch] [rbp-6Ch]
double v40; // [rsp+10h] [rbp-68h]
__int16 v41; // [rsp+1Ch] [rbp-5Ch]
__int16 v42; // [rsp+1Eh] [rbp-5Ah]
int v43; // [rsp+20h] [rbp-58h]
unsigned int v46; // [rsp+34h] [rbp-44h] BYREF
unsigned int v47; // [rsp+38h] [rbp-40h] BYREF
int v48[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( !a6 )
{
fwrite("ERROR: Predicate function pointer is NULL.\n", 1uLL, 0x2BuLL, stderr);
return 0;
}
if ( !a8 )
{
fwrite("ERROR: Predicate context pointer is NULL.\n", 1uLL, 0x2AuLL, stderr);
return 0;
}
if ( !a9 )
{
fwrite("ERROR: Return row pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
return 0;
}
if ( !a10 )
{
fwrite("ERROR: Return column pointer is NULL.\n", 1uLL, 0x26uLL, stderr);
return 0;
}
if ( !a11 )
{
fwrite("ERROR: Return found pointer is NULL.\n", 1uLL, 0x25uLL, stderr);
return 0;
}
v46 = 0;
v47 = 0;
if ( a1 <= 1 )
{
v42 = 0;
v37 = 1;
goto LABEL_46;
}
v43 = 1;
v40 = *(double *)&LC1;
v42 = 0;
v37 = 1;
v41 = 1;
while ( 1 )
{
v32 = a2 - v43;
if ( (int)(a2 - v43) < 0 )
v32 = 0;
v33 = a3 - v43;
if ( (int)(a3 - v43) < 0 )
v33 = 0;
v34 = a2 + v43;
if ( (int)(a2 + v43) > a4 )
v34 = a4;
v38 = v34;
v35 = v43 + a3;
if ( (int)(v43 + a3) > a5 )
v35 = a5;
v39 = v35;
if ( !v37 || v35 < (int)v33 )
break;
v16 = v33;
while ( 1 )
{
v48[0] = 0;
if ( !a6(a2, a3, v32, v16, a8, v48) )
{
v41 = 0;
goto LABEL_26;
}
v17 = v48[0];
if ( v48[0] )
{
v13 = func0(a2, v32, a3, v16);
v14 = (double)v17 * v13;
if ( v40 > v14 )
{
v46 = v32;
v47 = v16;
v40 = (double)v17 * v13;
v42 = 1;
goto LABEL_30;
}
if ( v14 == v40 )
{
if ( v42 )
{
v15 = a7(v46, v47, v32, v16, a8, &v46, &v47);
if ( !v15 )
break;
}
}
}
LABEL_30:
v48[0] = 0;
if ( a6(a2, a3, (unsigned int)v38, v16, a8, v48) )
goto LABEL_31;
v41 = 0;
LABEL_26:
++v16;
if ( !v37 || (int)v39 < (int)v16 )
goto LABEL_35;
}
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
v48[0] = 0;
if ( !a6(a2, a3, (unsigned int)v38, v16, a8, v48) )
goto LABEL_19;
v37 = v15;
v41 = v15;
LABEL_31:
v18 = v48[0];
if ( !v48[0] )
goto LABEL_26;
v19 = func0(a2, v38, a3, v16);
v20 = (double)v18 * v19;
if ( v40 > v20 )
{
v46 = v38;
v47 = v16;
v40 = (double)v18 * v19;
v42 = 1;
goto LABEL_26;
}
if ( v20 != v40 || !v42 || (unsigned __int16)a7(v46, v47, (unsigned int)v38, v16, a8, &v46, &v47) )
goto LABEL_26;
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
LABEL_19:
v37 = 0;
v41 = 0;
LABEL_67:
++v43;
if ( !v41 || a1 <= v43 )
{
v28 = v37;
goto LABEL_55;
}
}
LABEL_35:
if ( v38 <= (int)(v32 + 1) || !v37 )
goto LABEL_67;
v21 = v32 + 2;
while ( 2 )
{
v29 = v21 - 1;
v48[0] = 0;
if ( !a6(a2, a3, (unsigned int)(v21 - 1), v33, a8, v48) )
{
LABEL_58:
if ( v38 <= v21 )
goto LABEL_44;
v41 = 0;
LABEL_60:
++v21;
continue;
}
break;
}
v30 = v48[0];
if ( !v48[0] )
goto LABEL_63;
v22 = func0(a2, v29, a3, v33);
v23 = (double)v30 * v22;
if ( v40 > v23 )
{
v46 = v21 - 1;
v47 = v33;
v40 = (double)v30 * v22;
v42 = 1;
goto LABEL_63;
}
if ( v23 != v40 || !v42 || (v24 = a7(v46, v47, v29, v33, a8, &v46, &v47)) != 0 )
{
LABEL_63:
v48[0] = 0;
if ( a6(a2, a3, v29, v39, a8, v48) )
goto LABEL_64;
goto LABEL_58;
}
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
v48[0] = 0;
v37 = a6(a2, a3, v29, v39, a8, v48);
if ( !v37 )
goto LABEL_44;
v37 = v24;
v41 = v24;
LABEL_64:
v31 = v48[0];
if ( !v48[0] )
{
LABEL_65:
if ( !v37 || v38 <= v21 )
goto LABEL_67;
goto LABEL_60;
}
v26 = func0(a2, v29, a3, v39);
v27 = (double)v31 * v26;
if ( v40 > v27 )
{
v46 = v21 - 1;
v47 = v39;
v40 = (double)v31 * v26;
v42 = 1;
goto LABEL_65;
}
if ( v27 != v40 )
goto LABEL_65;
if ( !v42 )
goto LABEL_65;
v28 = a7(v46, v47, v29, v39, a8, &v46, &v47);
if ( v28 )
goto LABEL_65;
fwrite("ERROR: Error determining tiebreaker.\n", 1uLL, 0x25uLL, stderr);
LABEL_55:
v37 = v28;
LABEL_44:
if ( v42 )
{
*a9 = v46;
*a10 = v47;
}
LABEL_46:
*a11 = v42;
return v37;
}

original_code:
bool grid_search(int _max_dist, int _start_row, int _start_col, int _max_row, int _max_col,
  search_predicate_t _predicate, search_predicate_tiebreaker_t _tiebreaker, void* _context, int* _rtn_row,
  int* _rtn_col, bool* _rtn_found) {
 bool keepSearching = true;
 bool result = true;
 if (_predicate == 0) {
  fprintf(stderr, "ERROR: Predicate function pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_context == 0) {
  fprintf(stderr, "ERROR: Predicate context pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_rtn_row == 0) {
  fprintf(stderr, "ERROR: Return row pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_rtn_col == 0) {
  fprintf(stderr, "ERROR: Return column pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_rtn_found == 0) {
  fprintf(stderr, "ERROR: Return found pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else {
  bool found = false;
  int found_row = 0;
  int found_col = 0;
  double min_dist = (double)0x7fffffff;
  for (int offset = 1; keepSearching && offset < _max_dist; ++offset) {
   int min_row = _start_row - offset;
   if (min_row < 0) min_row = 0;
   int min_col = _start_col - offset;
   if (min_col < 0) min_col = 0;
   int max_row = _start_row + offset;
   if (max_row > _max_row) max_row = _max_row;
   int max_col = _start_col + offset;
   if (max_col > _max_col) max_col = _max_col;
   for (int col = min_col; result && col <= max_col; ++col) {
    int vote = 0;
    if (!_predicate(_start_row, _start_col, min_row, col, _context, &vote)) {
     keepSearching = false;
    } else {
     if (vote) {
      double dist = vote * grid_dist(_start_row, min_row,
        _start_col, col);
      if (dist < min_dist) {
       found_row = min_row;
       found_col = col;
       min_dist = dist;
       found = true;
      } else if (dist == min_dist && found) {
       if ( !_tiebreaker(found_row, found_col, min_row, col, _context, &found_row, &found_col) ) {
        fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
        result = false;
        keepSearching = false;
       }
      }
     }
     vote = 0;
     if (!_predicate(_start_row, _start_col, max_row, col, _context, &vote)) {
      keepSearching = false;
     } else {
      if (vote) {
       double dist = vote * grid_dist(_start_row, max_row,
         _start_col, col);
       if (dist < min_dist) {
        found_row = max_row;
        found_col = col;
        min_dist = dist;
        found = true;
       } else if (dist == min_dist && found) {
        if ( !_tiebreaker(found_row, found_col, max_row, col, _context, &found_row, &found_col) ) {
         fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
         result = false;
         keepSearching = false;
        }
       }
      }
     }
    }
   }
   for (int row = min_row + 1; result && row <= max_row - 1; ++row) {
    int vote = 0;
    if (!_predicate(_start_row, _start_col, row, min_col, _context, &vote)) {
     keepSearching = false;
    } else {
     if (vote) {
      double dist = vote * grid_dist(_start_row, row, _start_col,
        min_col);
      if (dist < min_dist) {
       found_row = row;
       found_col = min_col;
       min_dist = dist;
       found = true;
      } else if (dist == min_dist && found) {
       if ( !_tiebreaker(found_row, found_col, row, min_col, _context, &found_row, &found_col) ) {
        fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
        result = false;
        keepSearching = false;
       }
      }
     }
     vote = 0;
     if (!_predicate(_start_row, _start_col, row, max_col, _context, &vote)) {
      keepSearching = false;
     } else {
      if (vote) {
       double dist = vote * grid_dist(_start_row, row, _start_col,
         max_col);
       if (dist < min_dist) {
        found_row = row;
        found_col = max_col;
        min_dist = dist;
        found = true;
       } else if (dist == min_dist && found) {
        if ( !_tiebreaker(found_row, found_col, row, max_col, _context, &found_row, &found_col) ) {
         fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
         result = false;
         keepSearching = false;
        }
       }
      }
     }
    }
   }
  }
  if (found) {
   *_rtn_row = found_row;
   *_rtn_col = found_col;
  }
  *_rtn_found = found;
 }
 return result;
}

canonical_original_code:
short grid_search(int _max_dist, int _start_row, int _start_col, int _max_row, int _max_col, short (*_predicate)(int, int, int, int, void *, int *), short (*_tiebreaker)(int, int, int, int, void *, int *, int *), void *_context, int *_rtn_row, int *_rtn_col, short *_rtn_found) {
 short keepSearching = true;
 short result = true;
 if (_predicate == 0) {
  fprintf(stderr, "ERROR: Predicate function pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_context == 0) {
  fprintf(stderr, "ERROR: Predicate context pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_rtn_row == 0) {
  fprintf(stderr, "ERROR: Return row pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_rtn_col == 0) {
  fprintf(stderr, "ERROR: Return column pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else if (_rtn_found == 0) {
  fprintf(stderr, "ERROR: Return found pointer is NULL.\n");
  result = false;
  keepSearching = false;
 } else {
  short found = false;
  int found_row = 0;
  int found_col = 0;
  double min_dist = (double)0x7fffffff;
  for (int offset = 1; keepSearching && offset < _max_dist; ++offset) {
   int min_row = _start_row - offset;
   if (min_row < 0) min_row = 0;
   int min_col = _start_col - offset;
   if (min_col < 0) min_col = 0;
   int max_row = _start_row + offset;
   if (max_row > _max_row) max_row = _max_row;
   int max_col = _start_col + offset;
   if (max_col > _max_col) max_col = _max_col;
   for (int col = min_col; result && col <= max_col; ++col) {
    int vote = 0;
    if (!_predicate(_start_row, _start_col, min_row, col, _context, &vote)) {
     keepSearching = false;
    } else {
     if (vote) {
      double dist = vote * grid_dist(_start_row, min_row,
        _start_col, col);
      if (dist < min_dist) {
       found_row = min_row;
       found_col = col;
       min_dist = dist;
       found = true;
      } else if (dist == min_dist && found) {
       if ( !_tiebreaker(found_row, found_col, min_row, col, _context, &found_row, &found_col) ) {
        fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
        result = false;
        keepSearching = false;
       }
      }
     }
     vote = 0;
     if (!_predicate(_start_row, _start_col, max_row, col, _context, &vote)) {
      keepSearching = false;
     } else {
      if (vote) {
       double dist = vote * grid_dist(_start_row, max_row,
         _start_col, col);
       if (dist < min_dist) {
        found_row = max_row;
        found_col = col;
        min_dist = dist;
        found = true;
       } else if (dist == min_dist && found) {
        if ( !_tiebreaker(found_row, found_col, max_row, col, _context, &found_row, &found_col) ) {
         fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
         result = false;
         keepSearching = false;
        }
       }
      }
     }
    }
   }
   for (int row = min_row + 1; result && row <= max_row - 1; ++row) {
    int vote = 0;
    if (!_predicate(_start_row, _start_col, row, min_col, _context, &vote)) {
     keepSearching = false;
    } else {
     if (vote) {
      double dist = vote * grid_dist(_start_row, row, _start_col,
        min_col);
      if (dist < min_dist) {
       found_row = row;
       found_col = min_col;
       min_dist = dist;
       found = true;
      } else if (dist == min_dist && found) {
       if ( !_tiebreaker(found_row, found_col, row, min_col, _context, &found_row, &found_col) ) {
        fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
        result = false;
        keepSearching = false;
       }
      }
     }
     vote = 0;
     if (!_predicate(_start_row, _start_col, row, max_col, _context, &vote)) {
      keepSearching = false;
     } else {
      if (vote) {
       double dist = vote * grid_dist(_start_row, row, _start_col,
         max_col);
       if (dist < min_dist) {
        found_row = row;
        found_col = max_col;
        min_dist = dist;
        found = true;
       } else if (dist == min_dist && found) {
        if ( !_tiebreaker(found_row, found_col, row, max_col, _context, &found_row, &found_col) ) {
         fprintf(stderr, "ERROR: Error determining tiebreaker.\n");
         result = false;
         keepSearching = false;
        }
       }
      }
     }
    }
   }
  }
  if (found) {
   *_rtn_row = found_row;
   *_rtn_col = found_col;
  }
  *_rtn_found = found;
 }
 return result;
}

variable_types: short (*)(int, int, int, int, void *, int *)

variable_types: short (*)(int, int, int, int, void *, int *, int *)

variable_types: keepSearching short

variable_types: found short

variable_types: offset int

variable_types: col int

variable_types: vote int

variable_types: dist double

variable_types: row int


decompiled_code:
double __fastcall compute_N_leached(unsigned int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
double v18; // rbx
double v20; // rbx
double v21; // rbx
double v22; // xmm7_8
double v23; // xmm0_8
double v24; // xmm1_8
double v25; // rbp
double v26; // rbx
double v27; // r15
double v28; // rbx
double v29; // rbx
double v30; // rbx
double v31; // r12
double v32; // xmm0_8
double v35; // [rsp+8h] [rbp-50h]
double v36; // [rsp+8h] [rbp-50h]
double v37; // [rsp+18h] [rbp-40h]

v18 = *(double *)&LC0;
if ( a3 <= 0.000000001 )
return v18;
v20 = a4;
if ( a4 < 0.0 )
{
v20 = 0.0;
if ( a5 < 0.0 )
goto LABEL_6;
}
else
{
a5 = fmax(a4, a5);
}
if ( v20 != 0.0 || a5 != 0.0 )
{
v27 = compute_z_final(a1, a8, a9, a12, 0.0, COERCE_DOUBLE(*(_QWORD *)&a5 ^ LC3));
v36 = compute_z_final(a1, a8, a9, a12, 0.0, COERCE_DOUBLE(*(_QWORD *)&v20 ^ LC3));
if ( a10 > 0.0 )
{
v37 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * a11);
v29 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * v36);
v28 = a2 / (1.0 - v37) * (v29 - exp(v27 * COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3)));
}
else
{
v28 = *(double *)&LC0;
if ( v36 <= COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) )
v28 = (v27 - v36) * a2 / (a10 + a11);
}
v30 = fmin(a2, v28);
v31 = compute_delta_water(a1, a8, a9, a12, v27, v36);
v32 = compute_N_absorbed(a1, v36, v27, a13, a9, a8);
if ( v32 > v30 )
{
if ( v31 <= 0.000000001 )
return *(double *)&LC0;
v18 = *(double *)&LC0;
}
else
{
v18 = v30 - v32;
if ( v31 <= 0.000000001 )
{
if ( v18 >= 0.0 )
return 0.0;
goto LABEL_27;
}
}
v24 = a3 * v18 / v31;
goto LABEL_26;
}
LABEL_6:
v35 = fmin(a11, COERCE_DOUBLE(*(_QWORD *)&a9 ^ LC3) * log(1.0 - a3 / (a8 * a9)));
if ( a10 > 0.000000001 )
{
v25 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * a11);
v26 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * 0.0);
v21 = a2 / (1.0 - v25) * (v26 - exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * v35));
}
else
{
v21 = a2 * v35 / a11;
}
v22 = fmin(a2, v21);
v18 = v22;
v23 = compute_N_absorbed(a1, 0.0, v35, a13, a9, a8);
if ( v23 > v22 )
{
v18 = *(double *)&LC0;
goto LABEL_27;
}
v24 = v22 - v23;
if ( v22 - v23 > v22 )
goto LABEL_27;
LABEL_26:
v18 = fmin(v18, v24);
LABEL_27:
if ( v18 <= 0.0 )
v18 = *(double *)&LC0;
return v18;
}

canonical_decompiled_code:
double __fastcall func0(unsigned int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
double v18; // rbx
double v20; // rbx
double v21; // rbx
double v22; // xmm7_8
double v23; // xmm0_8
double v24; // xmm1_8
double v25; // rbp
double v26; // rbx
double v27; // r15
double v28; // rbx
double v29; // rbx
double v30; // rbx
double v31; // r12
double v32; // xmm0_8
double v35; // [rsp+8h] [rbp-50h]
double v36; // [rsp+8h] [rbp-50h]
double v37; // [rsp+18h] [rbp-40h]

v18 = *(double *)&LC0;
if ( a3 <= 0.000000001 )
return v18;
v20 = a4;
if ( a4 < 0.0 )
{
v20 = 0.0;
if ( a5 < 0.0 )
goto LABEL_6;
}
else
{
a5 = fmax(a4, a5);
}
if ( v20 != 0.0 || a5 != 0.0 )
{
v27 = compute_z_final(a1, a8, a9, a12, 0.0, COERCE_DOUBLE(*(_QWORD *)&a5 ^ LC3));
v36 = compute_z_final(a1, a8, a9, a12, 0.0, COERCE_DOUBLE(*(_QWORD *)&v20 ^ LC3));
if ( a10 > 0.0 )
{
v37 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * a11);
v29 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * v36);
v28 = a2 / (1.0 - v37) * (v29 - exp(v27 * COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3)));
}
else
{
v28 = *(double *)&LC0;
if ( v36 <= COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) )
v28 = (v27 - v36) * a2 / (a10 + a11);
}
v30 = fmin(a2, v28);
v31 = compute_delta_water(a1, a8, a9, a12, v27, v36);
v32 = compute_N_absorbed(a1, v36, v27, a13, a9, a8);
if ( v32 > v30 )
{
if ( v31 <= 0.000000001 )
return *(double *)&LC0;
v18 = *(double *)&LC0;
}
else
{
v18 = v30 - v32;
if ( v31 <= 0.000000001 )
{
if ( v18 >= 0.0 )
return 0.0;
goto LABEL_27;
}
}
v24 = a3 * v18 / v31;
goto LABEL_26;
}
LABEL_6:
v35 = fmin(a11, COERCE_DOUBLE(*(_QWORD *)&a9 ^ LC3) * log(1.0 - a3 / (a8 * a9)));
if ( a10 > 0.000000001 )
{
v25 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * a11);
v26 = exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * 0.0);
v21 = a2 / (1.0 - v25) * (v26 - exp(COERCE_DOUBLE(*(_QWORD *)&a10 ^ LC3) * v35));
}
else
{
v21 = a2 * v35 / a11;
}
v22 = fmin(a2, v21);
v18 = v22;
v23 = compute_N_absorbed(a1, 0.0, v35, a13, a9, a8);
if ( v23 > v22 )
{
v18 = *(double *)&LC0;
goto LABEL_27;
}
v24 = v22 - v23;
if ( v22 - v23 > v22 )
goto LABEL_27;
LABEL_26:
v18 = fmin(v18, v24);
LABEL_27:
if ( v18 <= 0.0 )
v18 = *(double *)&LC0;
return v18;
}

original_code:
double compute_N_leached(int verbose_flag,
   double total_nitrate,
   double Qout,
   double s1,
   double s2,
   double m,
   double gamma,
   double n_0,
   double p,
   double N_decay_rate,
   double z2_N,
   double z2_water,
   double N_absorption_rate,
   double *transmissivity)
 {
     double compute_delta_water(
                int,
                double,
                double,
                double,
                double,
                double);
 double compute_z_final(
  int,
  double,
  double,
  double,
  double,
  double);
 double compute_N_absorbed(
  int,
  double,
  double,
  double,
  double,
  double);
 int didx_bot, didx_top;
 double navail, nleached,nabsorbed;
 double theta, sat_deficit;
 double Q, Qtotal;
 double z1, z2;
 double available_water,septic_depth;
 nleached = 0.0;
 Qtotal = 0.0;
 nabsorbed = 0.0;
 navail = 0.0;
 if (Qout > 0.000000001) {
 if (s1 < 0.0) s1 = 0.0;
 if (s2 < s1) s2 = s1;
 if ((s1 == 0.0) && (s2 == 0.0)) {
  z2 = -1.0 * p * log (1 - (Qout) / (p * n_0));
  if (z2 > z2_N)
   z2 = z2_N;
  z1 = 0.0;
  if (N_decay_rate > 0.000000001) {
   navail = total_nitrate
    / (1.0 - exp(-1.0 * N_decay_rate * z2_N) )
    * (exp(-1.0 * N_decay_rate * z1)
    - exp(-1.0 * N_decay_rate * (z2)));
  }
  else {
   navail = total_nitrate * (z2-z1)/z2_N;
  }
  if (navail > total_nitrate) navail=total_nitrate;
  nabsorbed=compute_N_absorbed(verbose_flag,
      z1,
      z2,
      N_absorption_rate,
      p,
      n_0);
  if (nabsorbed > navail) {
   navail=0;
   }
  else
    nleached = navail-nabsorbed;
  if (nleached > navail) nleached=navail;
 }
 else {
 z2 = compute_z_final(
   verbose_flag,
   n_0,
   p,
   z2_water,
   0.0,
   -s2);
 z1 = compute_z_final(
   verbose_flag,
   n_0,
   p,
   z2_water,
   0.0,
   -s1);
 if (N_decay_rate > 0.0) {
  navail = total_nitrate
   / (1.0 - exp(-1.0 * N_decay_rate * z2_N) )
   * (exp(-1.0 * N_decay_rate * z1)
   - exp(-1.0 * N_decay_rate * (z2)));
  }
 else {
   septic_depth = -1.0*N_decay_rate;
   if (z1 > septic_depth)
    navail = 0.0;
   else
    navail = total_nitrate * (z2-z1)/(z2_N - septic_depth);
  }
  if (navail > total_nitrate) navail=total_nitrate;
  available_water = compute_delta_water(
   verbose_flag,
   n_0,p,z2_water,
   z2,
   z1);
  nabsorbed=compute_N_absorbed(verbose_flag,
   z1,
   z2,
   N_absorption_rate,
   p,
   n_0);
  if (nabsorbed > navail) {
    navail=0;
  }
  else navail = navail-nabsorbed;
  if (available_water > 0.000000001) {
   nleached = navail * Qout/available_water;
  }
  else nleached = 0.0;
     }
 }
 if (nleached > navail) nleached=navail;
 nleached = ((nleached) > (0.0) ? (nleached) : (0.0));
 return(nleached);
}

canonical_original_code:
double compute_N_leached(int verbose_flag, double total_nitrate, double Qout, double s1, double s2, double m, double gamma, double n_0, double p, double N_decay_rate, double z2_N, double z2_water, double N_absorption_rate, double *transmissivity)
 {
     double compute_delta_water(int, double, double, double, double, double);
 double compute_z_final(int, double, double, double, double, double);
 double compute_N_absorbed(int, double, double, double, double, double);
 int didx_bot; int didx_top;
 double navail; double nleached; double nabsorbed;
 double theta; double sat_deficit;
 double Q; double Qtotal;
 double z1; double z2;
 double available_water; double septic_depth;
 nleached = 0.0;
 Qtotal = 0.0;
 nabsorbed = 0.0;
 navail = 0.0;
 if (Qout > 0.000000001) {
 if (s1 < 0.0) s1 = 0.0;
 if (s2 < s1) s2 = s1;
 if ((s1 == 0.0) && (s2 == 0.0)) {
  z2 = -1.0 * p * log (1 - (Qout) / (p * n_0));
  if (z2 > z2_N)
   z2 = z2_N;
  z1 = 0.0;
  if (N_decay_rate > 0.000000001) {
   navail = total_nitrate
    / (1.0 - exp(-1.0 * N_decay_rate * z2_N) )
    * (exp(-1.0 * N_decay_rate * z1)
    - exp(-1.0 * N_decay_rate * (z2)));
  }
  else {
   navail = total_nitrate * (z2-z1)/z2_N;
  }
  if (navail > total_nitrate) navail=total_nitrate;
  nabsorbed=compute_N_absorbed(verbose_flag,
      z1,
      z2,
      N_absorption_rate,
      p,
      n_0);
  if (nabsorbed > navail) {
   navail=0;
   }
  else
    nleached = navail-nabsorbed;
  if (nleached > navail) nleached=navail;
 }
 else {
 z2 = compute_z_final(
   verbose_flag,
   n_0,
   p,
   z2_water,
   0.0,
   -s2);
 z1 = compute_z_final(
   verbose_flag,
   n_0,
   p,
   z2_water,
   0.0,
   -s1);
 if (N_decay_rate > 0.0) {
  navail = total_nitrate
   / (1.0 - exp(-1.0 * N_decay_rate * z2_N) )
   * (exp(-1.0 * N_decay_rate * z1)
   - exp(-1.0 * N_decay_rate * (z2)));
  }
 else {
   septic_depth = -1.0*N_decay_rate;
   if (z1 > septic_depth)
    navail = 0.0;
   else
    navail = total_nitrate * (z2-z1)/(z2_N - septic_depth);
  }
  if (navail > total_nitrate) navail=total_nitrate;
  available_water = compute_delta_water(
   verbose_flag,
   n_0,p,z2_water,
   z2,
   z1);
  nabsorbed=compute_N_absorbed(verbose_flag,
   z1,
   z2,
   N_absorption_rate,
   p,
   n_0);
  if (nabsorbed > navail) {
    navail=0;
  }
  else navail = navail-nabsorbed;
  if (available_water > 0.000000001) {
   nleached = navail * Qout/available_water;
  }
  else nleached = 0.0;
     }
 }
 if (nleached > navail) nleached=navail;
 nleached = ((nleached) > (0.0) ? (nleached) : (0.0));
 return(nleached);
}

variable_types: Qout double

variable_types: m double

variable_types: gamma double

variable_types: p double

variable_types:
transmissivity
double *

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

variable_types: navail double

variable_types: nleached double

variable_types: theta double

variable_types: Q double

variable_types: Qtotal double


decompiled_code:
__int64 __fastcall find_patch(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return patchHashTableGet(a1, __PAIR64__(a3, a2), a4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return patchHashTableGet(a1, __PAIR64__(a3, a2), a4);
}

original_code:
int find_patch(PatchTable_t *patchTable, int patchID, int zoneID, int hillID) {
 PatchKey_t k = { patchID, zoneID, hillID };
 return (int)patchHashTableGet(patchTable, k);
}

canonical_original_code:
int find_patch(struct table_s *patchTable, int patchID, int zoneID, int hillID) {
 struct key_s k = { patchID, zoneID, hillID };
 return (int)patchHashTableGet(patchTable, k);
}

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

variable_types: patchID int

variable_types: zoneID int

variable_types: hillID int

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

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


keyIsEmpty

decompiled_code:
_BOOL8 __fastcall keyIsEmpty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return a1 == 0;
}

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

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

variable_types:
key
char *


keysAreEqual

decompiled_code:
_BOOL8 __fastcall keysAreEqual(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

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

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


addToKeyList

decompiled_code:
__int64 __fastcall addToKeyList(__int64 a1)
{
__int64 result; // rax

result = stringListAppend(*(_QWORD *)(a1 + 16));
if ( !*(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

result = stringListAppend(*(_QWORD *)(a1 + 16));
if ( !*(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
static StringList_t *addToKeyList(Dictionary_t *table, char *key) {
 StringList_t *elem = stringListAppend(table->keys, key);
 if (table->keys == ((void *)0)) {
  table->keys = elem;
 }
 return elem;
}

canonical_original_code:
static struct string_list_s *addToKeyList(struct dict_s *table, char *key) {
 struct string_list_s *elem = stringListAppend(table->keys, key);
 if (table->keys == ((void *)0)) {
  table->keys = elem;
 }
 return elem;
}

variable_types: struct dict_s { unsigned long size; unsigned long numEntries; struct string_list_s *keys; struct dict_entry_s { char *key; struct dict_value_s { enum DataType { DATA_TYPE_UNDEFINED=0, DATA_TYPE_BOOL=1, DATA_TYPE_CHAR=2, DATA_TYPE_STRING=3, DATA_TYPE_INT=4, DATA_TYPE_LONG=5, DATA_TYPE_LONG_ARRAY=6, DATA_TYPE_FLOAT=7, DATA_TYPE_DOUBLE=8, DATA_TYPE_DOUBLE_ARRAY=9, DATA_TYPE_FILE_PTR=10, DATA_TYPE_STRUCT=11, DATA_TYPE_STRUCT_PTR=12, DATA_TYPE_STRUCT_PTR_ARRAY=13 } data_type; unsigned long offset; struct dict_s *sub_struct_index; } *value; struct dict_entry_s *next; } *entries; } *

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

user_defined_types: struct dict_s { unsigned long size; unsigned long numEntries; struct string_list_s *keys; struct dict_entry_s *entries; }

user_defined_types: struct dict_entry_s { char *key; struct dict_value_s *value; struct dict_entry_s *next; }

user_defined_types: struct dict_value_s { enum DataType data_type; unsigned long offset; struct dict_s *sub_struct_index; }


freeDictionary

decompiled_code:
void __fastcall freeDictionary(void *ptr)
{
unsigned __int64 v2; // r12
_QWORD *v3; // rbp
_QWORD *v4; // rbx
void *v5; // rdi

if ( ptr )
{
freeStringList(*((_QWORD *)ptr + 2));
if ( *(_QWORD *)ptr )
{
v2 = 0LL;
do
{
v4 = *(_QWORD **)(*((_QWORD *)ptr + 3) + 24 * v2 + 16);
while ( v4 )
{
v3 = v4;
v4 = (_QWORD *)v4[2];
v5 = (void *)v3[1];
if ( v5 )
free(v5);
free(v3);
}
++v2;
}
while ( *(_QWORD *)ptr > v2 );
}
free(*((void **)ptr + 3));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
unsigned __int64 v2; // r12
_QWORD *v3; // rbp
_QWORD *v4; // rbx
void *v5; // rdi

if ( ptr )
{
freeStringList(*((_QWORD *)ptr + 2));
if ( *(_QWORD *)ptr )
{
v2 = 0LL;
do
{
v4 = *(_QWORD **)(*((_QWORD *)ptr + 3) + 24 * v2 + 16);
while ( v4 )
{
v3 = v4;
v4 = (_QWORD *)v4[2];
v5 = (void *)v3[1];
if ( v5 )
free(v5);
free(v3);
}
++v2;
}
while ( *(_QWORD *)ptr > v2 );
}
free(*((void **)ptr + 3));
free(ptr);
}
}

original_code:
void freeDictionary(Dictionary_t *table) {
 if (table == ((void *)0)) return;
 freeStringList(table->keys);
 DictionaryEntry_t *entry;
 DictionaryEntry_t *tmpEntry;
 for (size_t i = 0; i < table->size; i++) {
  entry = table->entries + i;
  tmpEntry = entry->next;
  while (tmpEntry != ((void *)0)) {
   entry = tmpEntry;
   tmpEntry = entry->next;
   if (entry->value) free(entry->value);
   free(entry);
  }
 }
 free(table->entries);
 free(table);
}

canonical_original_code:
void freeDictionary(struct dict_s *table) {
 if (table == ((void *)0)) return;
 freeStringList(table->keys);
 struct dict_entry_s *entry;
 struct dict_entry_s *tmpEntry;
 for (unsigned long i = 0; i < table->size; i++) {
  entry = table->entries + i;
  tmpEntry = entry->next;
  while (tmpEntry != ((void *)0)) {
   entry = tmpEntry;
   tmpEntry = entry->next;
   if (entry->value) free(entry->value);
   free(entry);
  }
 }
 free(table->entries);
 free(table);
}

variable_types: struct dict_s { unsigned long size; unsigned long numEntries; struct string_list_s { char *str; struct string_list_s *next; } *keys; struct dict_entry_s { char *key; struct dict_value_s { enum DataType { DATA_TYPE_UNDEFINED=0, DATA_TYPE_BOOL=1, DATA_TYPE_CHAR=2, DATA_TYPE_STRING=3, DATA_TYPE_INT=4, DATA_TYPE_LONG=5, DATA_TYPE_LONG_ARRAY=6, DATA_TYPE_FLOAT=7, DATA_TYPE_DOUBLE=8, DATA_TYPE_DOUBLE_ARRAY=9, DATA_TYPE_FILE_PTR=10, DATA_TYPE_STRUCT=11, DATA_TYPE_STRUCT_PTR=12, DATA_TYPE_STRUCT_PTR_ARRAY=13 } data_type; unsigned long offset; struct dict_s *sub_struct_index; } *value; struct dict_entry_s *next; } *entries; } *

variable_types: struct dict_entry_s { char *key; struct dict_value_s { enum DataType { DATA_TYPE_UNDEFINED=0, DATA_TYPE_BOOL=1, DATA_TYPE_CHAR=2, DATA_TYPE_STRING=3, DATA_TYPE_INT=4, DATA_TYPE_LONG=5, DATA_TYPE_LONG_ARRAY=6, DATA_TYPE_FLOAT=7, DATA_TYPE_DOUBLE=8, DATA_TYPE_DOUBLE_ARRAY=9, DATA_TYPE_FILE_PTR=10, DATA_TYPE_STRUCT=11, DATA_TYPE_STRUCT_PTR=12, DATA_TYPE_STRUCT_PTR_ARRAY=13 } data_type; unsigned long offset; struct dict_s { unsigned long size; unsigned long numEntries; struct string_list_s { char *str; struct string_list_s *next; } *keys; struct dict_entry_s *entries; } *sub_struct_index; } *value; struct dict_entry_s *next; } *

variable_types:
i
unsigned long

return_type: void


dictionaryValueEquals

decompiled_code:
_BOOL8 __fastcall dictionaryValueEquals(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8, int a9, int a10, __int64 a11)
{
_BOOL8 result; // rax

result = 0LL;
if ( a7 == a10 )
result = a8 == a11;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8, int a9, int a10, __int64 a11)
{
_BOOL8 result; // rax

result = 0LL;
if ( a7 == a10 )
result = a8 == a11;
return result;
}

original_code:
bool dictionaryValueEquals(DictionaryValue_t first, DictionaryValue_t second) {
 if (first.data_type != second.data_type) return false;
 if (first.offset != second.offset) return false;
 return true;
}

canonical_original_code:
short dictionaryValueEquals(struct dict_value_s first, struct dict_value_s second) {
 if (first.data_type != second.data_type) return false;
 if (first.offset != second.offset) return false;
 return true;
}

variable_types: struct dict_value_s { enum DataType { DATA_TYPE_UNDEFINED=0, DATA_TYPE_BOOL=1, DATA_TYPE_CHAR=2, DATA_TYPE_STRING=3, DATA_TYPE_INT=4, DATA_TYPE_LONG=5, DATA_TYPE_LONG_ARRAY=6, DATA_TYPE_FLOAT=7, DATA_TYPE_DOUBLE=8, DATA_TYPE_DOUBLE_ARRAY=9, DATA_TYPE_FILE_PTR=10, DATA_TYPE_STRUCT=11, DATA_TYPE_STRUCT_PTR=12, DATA_TYPE_STRUCT_PTR_ARRAY=13 } data_type; unsigned long offset; struct dict_s { unsigned long size; unsigned long numEntries; struct string_list_s { char *str; struct string_list_s *next; } *keys; struct dict_entry_s { char *key; struct dict_value_s *value; struct dict_entry_s *next; } *entries; } *sub_struct_index; }

variable_types:
second
struct dict_value_s


dictionaryGet

decompiled_code:
unsigned __int64 __fastcall dictionaryGet(unsigned __int64 *a1, char *a2)
{
unsigned __int64 v2; // rbx

if ( !a1 )
_assert_fail("table != NULL", "util/dictionary.c", 0x85u, "dictionaryGet");
v2 = a1[3] + 24 * hash(a2, *a1);
if ( v2 )
{
while ( !*(_QWORD *)v2 || !keysAreEqual(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(unsigned __int64 *a1, char *a2)
{
unsigned __int64 v2; // rbx

if ( !a1 )
_assert_fail("table != NULL", "util/dictionary.c", 0x85u, "dictionaryGet");
v2 = a1[3] + 24 * func0(a2, *a1);
if ( v2 )
{
while ( !*(_QWORD *)v2 || !func2(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
DictionaryValue_t *dictionaryGet(Dictionary_t *table, char *key) {
 ((table != ((void *)0)) ? (void) (0) : __assert_fail ("table != NULL", "util/dictionary.c", 133, __extension__ __PRETTY_FUNCTION__));
 DictionaryTableKey_t hash = _hash(key, table->size);
 DictionaryEntry_t *e = table->entries + hash;
 while (e) {
  if (e->key != ((void *)0) && keysAreEqual(e->key, key)) {
   return e->value;
  }
  e = e->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct dict_value_s *dictionaryGet(struct dict_s *table, char *key) {
 ((table != ((void *)0)) ? (void) (0) : __assert_fail ("table != NULL", "util/dictionary.c", 133, __extension__ __PRETTY_FUNCTION__));
 unsigned long hash = _hash(key, table->size);
 struct dict_entry_s *e = table->entries + hash;
 while (e) {
  if (e->key != ((void *)0) && keysAreEqual(e->key, key)) {
   return e->value;
  }
  e = e->next;
 }
 return ((void *)0);
}

variable_types:
table
struct dict_s *

variable_types:
hash
unsigned long

return_type: struct dict_value_s { enum DataType { DATA_TYPE_UNDEFINED=0, DATA_TYPE_BOOL=1, DATA_TYPE_CHAR=2, DATA_TYPE_STRING=3, DATA_TYPE_INT=4, DATA_TYPE_LONG=5, DATA_TYPE_LONG_ARRAY=6, DATA_TYPE_FLOAT=7, DATA_TYPE_DOUBLE=8, DATA_TYPE_DOUBLE_ARRAY=9, DATA_TYPE_FILE_PTR=10, DATA_TYPE_STRUCT=11, DATA_TYPE_STRUCT_PTR=12, DATA_TYPE_STRUCT_PTR_ARRAY=13 } data_type; unsigned long offset; struct dict_s { unsigned long size; unsigned long numEntries; struct string_list_s { char *str; struct string_list_s *next; } *keys; struct dict_entry_s { char *key; struct dict_value_s *value; struct dict_entry_s *next; } *entries; } *sub_struct_index; } *


printDictionary

decompiled_code:
size_t __fastcall printDictionary(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbp
__int64 v2; // rbx
__int64 i; // rbx

fprintf(stderr, "Dictionary@%p {\n", a1);
if ( *a1 )
{
v1 = 0LL;
do
{
v2 = a1[3] + 24 * v1;
if ( *(_QWORD *)v2 )
{
fprintf(
stderr,
"\t'%s': {data_type: %d, offset: %zu},\n",
*(const char **)v2,
**(unsigned int **)(v2 + 8),
*(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL));
for ( i = *(_QWORD *)(v2 + 16); i; i = *(_QWORD *)(i + 16) )
fprintf(
stderr,
"\t'%s': {data_type: %d, offset: %zu},\n",
*(const char **)i,
**(unsigned int **)(i + 8),
*(_QWORD *)(*(_QWORD *)(i + 8) + 8LL));
}
++v1;
}
while ( *a1 > v1 );
}
return fwrite("}\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func7(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbp
__int64 v2; // rbx
__int64 i; // rbx

fprintf(stderr, "Dictionary@%p {\n", a1);
if ( *a1 )
{
v1 = 0LL;
do
{
v2 = a1[3] + 24 * v1;
if ( *(_QWORD *)v2 )
{
fprintf(
stderr,
"\t'%s': {data_type: %d, offset: %zu},\n",
*(const char **)v2,
**(unsigned int **)(v2 + 8),
*(_QWORD *)(*(_QWORD *)(v2 + 8) + 8LL));
for ( i = *(_QWORD *)(v2 + 16); i; i = *(_QWORD *)(i + 16) )
fprintf(
stderr,
"\t'%s': {data_type: %d, offset: %zu},\n",
*(const char **)i,
**(unsigned int **)(i + 8),
*(_QWORD *)(*(_QWORD *)(i + 8) + 8LL));
}
++v1;
}
while ( *a1 > v1 );
}
return fwrite("}\n", 1uLL, 2uLL, stderr);
}

original_code:
void printDictionary(Dictionary_t *table) {
 DictionaryEntry_t *entry;
 DictionaryEntry_t *tmpEntry;
 fprintf(stderr, "Dictionary@%p {\n", (void *)table);
 for (size_t i = 0; i < table->size; i++) {
  entry = table->entries + i;
  if (entry->key != ((void *)0)) {
   fprintf(stderr, "\t'%s': {data_type: %d, offset: %zu},\n",
     entry->key, entry->value->data_type, entry->value->offset);
   tmpEntry = entry->next;
   while (tmpEntry != ((void *)0)) {
    entry = tmpEntry;
    fprintf(stderr, "\t'%s': {data_type: %d, offset: %zu},\n",
      entry->key, entry->value->data_type, entry->value->offset);
    tmpEntry = entry->next;
   }
  }
 }
 fprintf(stderr, "}\n");
}

canonical_original_code:
void printDictionary(struct dict_s *table) {
 struct dict_entry_s *entry;
 struct dict_entry_s *tmpEntry;
 fprintf(stderr, "Dictionary@%p {\n", (void *)table);
 for (unsigned long i = 0; i < table->size; i++) {
  entry = table->entries + i;
  if (entry->key != ((void *)0)) {
   fprintf(stderr, "\t'%s': {data_type: %d, offset: %zu},\n",
     entry->key, entry->value->data_type, entry->value->offset);
   tmpEntry = entry->next;
   while (tmpEntry != ((void *)0)) {
    entry = tmpEntry;
    fprintf(stderr, "\t'%s': {data_type: %d, offset: %zu},\n",
      entry->key, entry->value->data_type, entry->value->offset);
    tmpEntry = entry->next;
   }
  }
 }
 fprintf(stderr, "}\n");
}

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

user_defined_types: enum DataType { DATA_TYPE_UNDEFINED=0, DATA_TYPE_BOOL=1, DATA_TYPE_CHAR=2, DATA_TYPE_STRING=3, DATA_TYPE_INT=4, DATA_TYPE_LONG=5, DATA_TYPE_LONG_ARRAY=6, DATA_TYPE_FLOAT=7, DATA_TYPE_DOUBLE=8, DATA_TYPE_DOUBLE_ARRAY=9, DATA_TYPE_FILE_PTR=10, DATA_TYPE_STRUCT=11, DATA_TYPE_STRUCT_PTR=12, DATA_TYPE_STRUCT_PTR_ARRAY=13 }


decompiled_code:
__int64 __fastcall row_col_to_index(int a1, int a2, int a3, int a4, _DWORD *a5)
{
__int64 result; // rax

if ( a5 )
{
if ( a1 < 0 || a1 > a3 )
{
result = 0LL;
}
else if ( a2 < 0 || a2 > a4 )
{
result = 0LL;
}
else
{
*a5 = a2 + a4 * a1;
result = 1LL;
}
}
else
{
fwrite("ERROR: Index pointer is NULL.\n", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
return result;
}

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

if ( a5 )
{
if ( a1 < 0 || a1 > a3 )
{
result = 0LL;
}
else if ( a2 < 0 || a2 > a4 )
{
result = 0LL;
}
else
{
*a5 = a2 + a4 * a1;
result = 1LL;
}
}
else
{
fwrite("ERROR: Index pointer is NULL.\n", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool row_col_to_index(
    int _row,
    int _col,
    int _maxr,
    int _maxc,
    int* _rtn_index)
{
    bool result = true;
    if(_rtn_index != 0) {
        if(_row < 0 || _row > _maxr || _col < 0 || _col > _maxc) {
            result = false;
        } else {
            *_rtn_index = _row * _maxc + _col;
        }
    } else {
        fprintf(stderr, "ERROR: Index pointer is NULL.\n");
        result = false;
    }
    return result;
}

canonical_original_code:
short row_col_to_index(int _row, int _col, int _maxr, int _maxc, int *_rtn_index)
{
    short result = true;
    if(_rtn_index != 0) {
        if(_row < 0 || _row > _maxr || _col < 0 || _col > _maxc) {
            result = false;
        } else {
            *_rtn_index = _row * _maxc + _col;
        }
    } else {
        fprintf(stderr, "ERROR: Index pointer is NULL.\n");
        result = false;
    }
    return result;
}

variable_types: result short


decompiled_code:
__int64 __fastcall index_to_row_col(int a1, int a2, int a3, int *a4, int *a5)
{
unsigned int v6; // edi
__int64 result; // rax

if ( a4 && a5 )
{
v6 = 0;
if ( a1 >= 0 && a3 * a2 >= a1 )
{
*a4 = a1 / a3;
*a5 = a1 % a3;
v6 = 1;
}
result = v6;
}
else
{
fwrite("ERROR: Row and/or column pointers are NULL.\n", 1uLL, 0x2CuLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int *a4, int *a5)
{
unsigned int v6; // edi
__int64 result; // rax

if ( a4 && a5 )
{
v6 = 0;
if ( a1 >= 0 && a3 * a2 >= a1 )
{
*a4 = a1 / a3;
*a5 = a1 % a3;
v6 = 1;
}
result = v6;
}
else
{
fwrite("ERROR: Row and/or column pointers are NULL.\n", 1uLL, 0x2CuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool index_to_row_col(
    int _index,
    int _maxr,
    int _maxc,
    int* _rtn_row,
    int* _rtn_col)
{
    bool result = true;
    if(_rtn_row != 0 && _rtn_col != 0) {
        if(_index < 0 || _index > _maxr * _maxc) {
            result = false;
        } else {
            *_rtn_row = _index / _maxc;
            *_rtn_col = _index % _maxc;
        }
    } else {
        fprintf(stderr, "ERROR: Row and/or column pointers are NULL.\n");
        result = false;
    }
    return result;
}

canonical_original_code:
short index_to_row_col(int _index, int _maxr, int _maxc, int *_rtn_row, int *_rtn_col)
{
    short result = true;
    if(_rtn_row != 0 && _rtn_col != 0) {
        if(_index < 0 || _index > _maxr * _maxc) {
            result = false;
        } else {
            *_rtn_row = _index / _maxc;
            *_rtn_col = _index % _maxc;
        }
    } else {
        fprintf(stderr, "ERROR: Row and/or column pointers are NULL.\n");
        result = false;
    }
    return result;
}


decompiled_code:
_BOOL8 __fastcall is_roof(double a1)
{
return a1 >= 0.0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(double a1)
{
return a1 >= 0.0;
}

original_code:
bool is_roof(
    double _roof_value)
{
    return _roof_value >= 0;
}

canonical_original_code:
short is_roof(double _roof_value)
{
    return _roof_value >= 0;
}