decompiled_code:
void __fastcall thread_pool_run(void *a1)
{
_QWORD *v1; // rbx

while ( *((_DWORD *)a1 + 23) )
{
v1 = (_QWORD *)task_queue_take((__int64)a1);
((void (__fastcall *)(_QWORD))*v1)(v1[1]);
task_queue_delete(v1);
}
}

canonical_decompiled_code:
void __fastcall func14(void *a1)
{
_QWORD *v1; // rbx

while ( *((_DWORD *)a1 + 23) )
{
v1 = (_QWORD *)func11((__int64)a1);
((void (__fastcall *)(_QWORD))*v1)(v1[1]);
func12(v1);
}
}

original_code:
void* thread_pool_run(void *arg)
{
 thread_pool_t *pool = (thread_pool_t*)arg;
 while(pool->flag)
 {
  task_queue_node_t *node = task_queue_take(pool);
  node->callback(node->arg);
  task_queue_delete(node);
 }
}

canonical_original_code:
void *thread_pool_run(void *arg)
{
 struct thread_pool_t *pool = (thread_pool_t*)arg;
 while(pool->flag)
 {
  struct task_queue_node_t *node = task_queue_take(pool);
  node->callback(node->arg);
  task_queue_delete(node);
 }
}


repo: QMonkey/Thread-Pool

decompiled_code:
int __fastcall thread_pool_start(void *arg)
{
unsigned int v1; // ebp
int result; // eax

if ( !*((_DWORD *)arg + 23) )
{
*((_DWORD *)arg + 23) = 1;
if ( *((_DWORD *)arg + 22) )
{
v1 = 0;
do
result = pthread_create(
(pthread_t *)(*((_QWORD *)arg + 9) + 8LL * v1++),
0LL,
(void *(*)(void *))thread_pool_run,
arg);
while ( *((_DWORD *)arg + 22) > v1 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(void *arg)
{
unsigned int v1; // ebp
int result; // eax

if ( !*((_DWORD *)arg + 23) )
{
*((_DWORD *)arg + 23) = 1;
if ( *((_DWORD *)arg + 22) )
{
v1 = 0;
do
result = pthread_create(
(pthread_t *)(*((_QWORD *)arg + 9) + 8LL * v1++),
0LL,
(void *(*)(void *))thread_pool_run,
arg);
while ( *((_DWORD *)arg + 22) > v1 );
}
}
return result;
}

original_code:
void thread_pool_start(thread_pool_t *pool)
{
 if(!pool->flag)
 {
  pool->flag = 1;
  uint32_t i;
  for(i = 0; i < pool->size; ++i)
  {
   pthread_create(pool->tids + i,((void *)0),thread_pool_run,pool);
  }
 }
}

canonical_original_code:
void thread_pool_start(struct thread_pool_t *pool)
{
 if(!pool->flag)
 {
  pool->flag = 1;
  unsigned int i;
  for(i = 0; i < pool->size; ++i)
  {
   pthread_create(pool->tids + i,((void *)0),thread_pool_run,pool);
  }
 }
}

variable_types: struct thread_pool_t { union sem_t { char __size[32]; long __align; } semaphore; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned long *tids; struct task_queue_node_t { void *(*callback)(void *); void *arg; struct task_queue_node_t *next; } *head; unsigned int size; int flag; } *

variable_types:
i
unsigned int

return_type: void

user_defined_types: struct thread_pool_t { union sem_t semaphore; union pthread_mutex_t mutex; unsigned long *tids; struct task_queue_node_t *head; unsigned int size; int flag; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall thread_pool_execute(sem_t *a1, __int64 a2, __int64 a3)
{
return task_queue_put(a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func17(sem_t *a1, __int64 a2, __int64 a3)
{
return func9(a1, a2, a3);
}

original_code:
void thread_pool_execute(thread_pool_t *pool,void* (*callback)(void*),void *arg)
{
 task_queue_put(pool,callback,arg);
}

canonical_original_code:
void thread_pool_execute(struct thread_pool_t *pool, void *(*callback)(void *), void *arg)
{
 task_queue_put(pool,callback,arg);
}

variable_types:
callback
void *(*)(void *)

variable_types:
arg
void *

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct task_queue_node_t { void *(*callback)(void *); void *arg; struct task_queue_node_t *next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall thread_pool_join(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx
int result; // eax

v1 = *(_QWORD *)(a1 + 72);
if ( *(_DWORD *)(a1 + 88) )
{
v2 = 0LL;
do
result = pthread_join(*(_QWORD *)(v1 + 8 * v2++), 0LL);
while ( *(_DWORD *)(a1 + 88) > (unsigned int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx
int result; // eax

v1 = *(_QWORD *)(a1 + 72);
if ( *(_DWORD *)(a1 + 88) )
{
v2 = 0LL;
do
result = pthread_join(*(_QWORD *)(v1 + 8 * v2++), 0LL);
while ( *(_DWORD *)(a1 + 88) > (unsigned int)v2 );
}
return result;
}

original_code:
void thread_pool_join(thread_pool_t *pool)
{
 int i;
 pthread_t *tids = pool->tids;
 for(i = 0; i < pool->size; ++i)
 {
  pthread_join(tids[i],((void *)0));
 }
}

canonical_original_code:
void thread_pool_join(struct thread_pool_t *pool)
{
 int i;
 unsigned long *tids = pool->tids;
 for(i = 0; i < pool->size; ++i)
 {
  pthread_join(tids[i],((void *)0));
 }
}

variable_types: i int

variable_types:
tids
unsigned long *


decompiled_code:
void __fastcall thread_pool_stop(__int64 a1)
{
*(_DWORD *)(a1 + 92) = 0;
}

original_code:
void thread_pool_stop(thread_pool_t *pool)
{
 pool->flag = 0;
}

canonical_original_code:
void thread_pool_stop(struct thread_pool_t *pool)
{
 pool->flag = 0;
}


decompiled_code:
void __fastcall thread_pool_destroy(void *ptr)
{
thread_pool_stop((__int64)ptr);
sem_destroy((sem_t *)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
task_queue_destroy((void **)ptr + 10);
free(*((void **)ptr + 9));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func20(void *ptr)
{
func19((__int64)ptr);
sem_destroy((sem_t *)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
func13((void **)ptr + 10);
free(*((void **)ptr + 9));
free(ptr);
}

original_code:
void thread_pool_destroy(thread_pool_t *pool)
{
 thread_pool_stop(pool);
 sem_destroy(&pool->semaphore);
 pthread_mutex_destroy(&pool->mutex);
 task_queue_destroy(&pool->head);
 free(pool->tids);
 free(pool);
}

canonical_original_code:
void thread_pool_destroy(struct thread_pool_t *pool)
{
 thread_pool_stop(pool);
 sem_destroy(&pool->semaphore);
 pthread_mutex_destroy(&pool->mutex);
 task_queue_destroy(&pool->head);
 free(pool->tids);
 free(pool);
}


repo: QuLogic/travis-test

decompiled_code:
__int64 compile_stdin()
{
char *v0; // rax
char *v1; // r12
size_t v2; // rbp
char *v3; // rax
char *v4; // rbx
int v5; // eax
char v7[536]; // [rsp+0h] [rbp-218h] BYREF

++_gcov0_compile_stdin;
v0 = (char *)malloc(0x200uLL);
if ( !v0 )
{
++qword_968;
perror("Allocation failed");
++qword_970;
exit(1);
}
v1 = v0;
*v0 = 0;
v2 = 1LL;
while ( fgets(v7, 512, stdin) )
{
v2 += strlen(v7);
v3 = (char *)realloc(v1, v2);
v4 = v3;
if ( !v3 )
{
++qword_978;
perror("Reallocation failed");
++qword_988;
free(v1);
exit(2);
}
++qword_980;
strcat(v3, v7);
v1 = v4;
}
++qword_990;
v5 = ferror(stdin);
++qword_998;
if ( v5 )
{
++qword_9A0;
free(v1);
perror("Error reading standard input");
++qword_9A8;
exit(2);
}
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rax
char *v1; // r12
size_t v2; // rbp
char *v3; // rax
char *v4; // rbx
int v5; // eax
char v7[536]; // [rsp+0h] [rbp-218h] BYREF

++_gcov0_compile_stdin;
v0 = (char *)malloc(0x200uLL);
if ( !v0 )
{
++qword_968;
perror("Allocation failed");
++qword_970;
exit(1);
}
v1 = v0;
*v0 = 0;
v2 = 1LL;
while ( fgets(v7, 512, stdin) )
{
v2 += strlen(v7);
v3 = (char *)realloc(v1, v2);
v4 = v3;
if ( !v3 )
{
++qword_978;
perror("Reallocation failed");
++qword_988;
free(v1);
exit(2);
}
++qword_980;
strcat(v3, v7);
v1 = v4;
}
++qword_990;
v5 = ferror(stdin);
++qword_998;
if ( v5 )
{
++qword_9A0;
free(v1);
perror("Error reading standard input");
++qword_9A8;
exit(2);
}
free(v1);
return 0LL;
}

original_code:
int compile_stdin(char* outfile) {
    int ret;
    char buffer[512];
    size_t size = 1;
    char *source_string = malloc(sizeof(char) * 512);
    if(source_string == ((void *)0)) {
        perror("Allocation failed");
        exit(1);
    }
    source_string[0] = '\0';
    while(fgets(buffer, 512, stdin)) {
        char *old = source_string;
        size += strlen(buffer);
        source_string = realloc(source_string, size);
        if(source_string == ((void *)0)) {
            perror("Reallocation failed");
            free(old);
            exit(2);
        }
        strcat(source_string, buffer);
    }
    if(ferror(stdin)) {
        free(source_string);
        perror("Error reading standard input");
        exit(2);
    }
    free(source_string);
    return ret;
}

canonical_original_code:
int compile_stdin(char *outfile) {
    int ret;
    char buffer[512];
    unsigned long size = 1;
    char *source_string = malloc(sizeof(char) * 512);
    if(source_string == ((void *)0)) {
        perror("Allocation failed");
        exit(1);
    }
    source_string[0] = '\0';
    while(fgets(buffer, 512, stdin)) {
        char *old = source_string;
        size += strlen(buffer);
        source_string = realloc(source_string, size);
        if(source_string == ((void *)0)) {
            perror("Reallocation failed");
            free(old);
            exit(2);
        }
        strcat(source_string, buffer);
    }
    if(ferror(stdin)) {
        free(source_string);
        perror("Error reading standard input");
        exit(2);
    }
    free(source_string);
    return ret;
}

variable_types:
outfile
char *

variable_types: ret int

variable_types:
buffer
char [512]

variable_types:
size
unsigned long

variable_types:
old
char *

return_type: int


decompiled_code:
__int64 compile_file()
{
++_gcov0_compile_file;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
++_gcov0_compile_file;
return 0LL;
}

original_code:
int compile_file(char* input_path, char* outfile) {
    int ret;
    return ret;
}

canonical_original_code:
int compile_file(char *input_path, char *outfile) {
    int ret;
    return ret;
}


decompiled_code:
int __fastcall print_usage(const char *a1)
{
int result; // eax

++_gcov0_print_usage;
printf("Usage: %s [OPTION]... [FILE]\n\n", a1);
++qword_9C8;
puts("Options:");
++qword_9D0;
puts(" -o OUTFILE Write output to specified file.");
++qword_9D8;
printf(" -t NAME Output style. Can be:");
++qword_9E0;
printf(" %s", *(&style_option_strings + 2));
++qword_9F0;
putchar(44);
++qword_9F8;
printf(" %s", style_option_strings);
++qword_9E8;
puts(".");
++qword_9F8;
++qword_A00;
puts(" -l Emit comments showing original line numbers.");
++qword_A08;
puts(" -g Emit source map.");
++qword_A10;
puts(" -I PATH Set Sass import path.");
++qword_A18;
puts(" -h Display this help message.");
++qword_A20;
result = putchar(10);
++qword_A28;
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
int result; // eax

++_gcov0_print_usage;
printf("Usage: %s [OPTION]... [FILE]\n\n", a1);
++qword_9C8;
puts("Options:");
++qword_9D0;
puts(" -o OUTFILE Write output to specified file.");
++qword_9D8;
printf(" -t NAME Output style. Can be:");
++qword_9E0;
printf(" %s", *(&style_option_strings + 2));
++qword_9F0;
putchar(44);
++qword_9F8;
printf(" %s", style_option_strings);
++qword_9E8;
puts(".");
++qword_9F8;
++qword_A00;
puts(" -l Emit comments showing original line numbers.");
++qword_A08;
puts(" -g Emit source map.");
++qword_A10;
puts(" -I PATH Set Sass import path.");
++qword_A18;
puts(" -h Display this help message.");
++qword_A20;
result = putchar(10);
++qword_A28;
return result;
}

original_code:
void print_usage(char* argv0) {
    int i;
    printf("Usage: %s [OPTION]... [FILE]\n\n", argv0);
    printf("Options:\n");
    printf("   -o OUTFILE     Write output to specified file.\n");
    printf("   -t NAME        Output style. Can be:");
    for(i = sizeof(style_option_strings) / sizeof(style_option_strings[0]) - 1; i >= 0; i--) {
        printf(" %s", style_option_strings[i].style_string);
        printf(i == 0 ? ".\n" : ",");
    }
    printf("   -l             Emit comments showing original line numbers.\n");
    printf("   -g             Emit source map.\n");
    printf("   -I PATH        Set Sass import path.\n");
    printf("   -h             Display this help message.\n");
    printf("\n");
}

canonical_original_code:
void print_usage(char *argv0) {
    int i;
    printf("Usage: %s [OPTION]... [FILE]\n\n", argv0);
    printf("Options:\n");
    printf("   -o OUTFILE     Write output to specified file.\n");
    printf("   -t NAME        Output style. Can be:");
    for(i = sizeof(style_option_strings) / sizeof(style_option_strings[0]) - 1; i >= 0; i--) {
        printf(" %s", style_option_strings[i].style_string);
        printf(i == 0 ? ".\n" : ",");
    }
    printf("   -l             Emit comments showing original line numbers.\n");
    printf("   -g             Emit source map.\n");
    printf("   -I PATH        Set Sass import path.\n");
    printf("   -h             Display this help message.\n");
    printf("\n");
}


decompiled_code:
void __fastcall __noreturn invalid_usage(const char *a1)
{
++_gcov0_invalid_usage;
fprintf(stderr, "See '%s -h'\n", a1);
++qword_A38;
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
++_gcov0_invalid_usage;
fprintf(stderr, "See '%s -h'\n", a1);
++qword_A38;
exit(1);
}

original_code:
void invalid_usage(char* argv0) {
    fprintf(stderr, "See '%s -h'\n", argv0);
    exit(1);
}

canonical_original_code:
void invalid_usage(char *argv0) {
    fprintf(stderr, "See '%s -h'\n", argv0);
    exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // r13
__int64 v5; // r12
int result; // eax

++_gcov0_main;
while ( 2 )
{
v3 = getopt(argc, (char *const *)argv, "ho:lgt:I:");
if ( v3 != -1 )
{
switch ( v3 )
{
case '?':
++qword_A50;
invalid_usage(*argv);
case 'I':
case 'g':
case 'l':
case 'o':
goto LABEL_8;
case 'h':
++qword_A58;
print_usage(*argv);
++qword_AA0;
return 0;
case 't':
v4 = optarg;
if ( strcmp(optarg, style_option_strings) )
{
v5 = qword_A68++;
if ( strcmp(v4, *(&style_option_strings + 2)) )
{
qword_A68 = v5 + 2;
++qword_A70;
++qword_A78;
fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", v4);
++qword_A80;
fprintf(stderr, " %s", style_option_strings);
++qword_A88;
fprintf(stderr, " %s", *(&style_option_strings + 2));
++qword_A88;
++qword_A90;
fputc(10, stderr);
++qword_A98;
invalid_usage(*argv);
}
}
++qword_A60;
LABEL_8:
++qword_AB0;
continue;
default:
++qword_A48;
fwrite("Unknown error while processing arguments\n", 1uLL, 0x29uLL, stderr);
++qword_AA8;
return 2;
}
}
break;
}
++qword_AB8;
result = 0;
if ( argc - 1 > optind )
{
++qword_AC0;
fwrite("Error: Too many arguments.\n", 1uLL, 0x1BuLL, stderr);
++qword_AC8;
invalid_usage(*argv);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // r13
__int64 v5; // r12
int result; // eax

++_gcov0_main;
while ( 2 )
{
v3 = getopt(argc, (char *const *)argv, "ho:lgt:I:");
if ( v3 != -1 )
{
switch ( v3 )
{
case '?':
++qword_A50;
func4(*argv);
case 'I':
case 'g':
case 'l':
case 'o':
goto LABEL_8;
case 'h':
++qword_A58;
func3(*argv);
++qword_AA0;
return 0;
case 't':
v4 = optarg;
if ( strcmp(optarg, style_option_strings) )
{
v5 = qword_A68++;
if ( strcmp(v4, *(&style_option_strings + 2)) )
{
qword_A68 = v5 + 2;
++qword_A70;
++qword_A78;
fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", v4);
++qword_A80;
fprintf(stderr, " %s", style_option_strings);
++qword_A88;
fprintf(stderr, " %s", *(&style_option_strings + 2));
++qword_A88;
++qword_A90;
fputc(10, stderr);
++qword_A98;
func4(*argv);
}
}
++qword_A60;
LABEL_8:
++qword_AB0;
continue;
default:
++qword_A48;
fwrite("Unknown error while processing arguments\n", 1uLL, 0x29uLL, stderr);
++qword_AA8;
return 2;
}
}
break;
}
++qword_AB8;
result = 0;
if ( argc - 1 > optind )
{
++qword_AC0;
fwrite("Error: Too many arguments.\n", 1uLL, 0x1BuLL, stderr);
++qword_AC8;
func4(*argv);
}
return result;
}

original_code:
int main(int argc, char** argv) {
    char *outfile = 0;
    int c, i;
    while ((c = getopt(argc, argv, "ho:lgt:I:")) != -1) {
        switch (c) {
        case 'o':
            outfile = optarg;
            break;
        case 'I':
            break;
        case 't':
            for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                if(strcmp(optarg, style_option_strings[i].style_string) == 0) {
                    break;
                }
            }
            if(i == sizeof(style_option_strings) / sizeof(style_option_strings[0])) {
                fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", optarg);
                for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                    fprintf(stderr, " %s", style_option_strings[i].style_string);
                }
                fprintf(stderr, "\n");
                invalid_usage(argv[0]);
            }
            break;
        case 'l':
            break;
        case 'g':
            break;
        case 'h':
            print_usage(argv[0]);
            return 0;
        case '?':
            invalid_usage(argv[0]);
        default:
            fprintf(stderr, "Unknown error while processing arguments\n");
            return 2;
        }
    }
    if(optind < argc - 1) {
        fprintf(stderr, "Error: Too many arguments.\n");
        invalid_usage(argv[0]);
    }
    if(optind < argc && strcmp(argv[optind], "-") != 0) {
    } else {
    }
}

canonical_original_code:
int main(int argc, char **argv) {
    char *outfile = 0;
    int c; int i;
    while ((c = getopt(argc, argv, "ho:lgt:I:")) != -1) {
        switch (c) {
        case 'o':
            outfile = optarg;
            break;
        case 'I':
            break;
        case 't':
            for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                if(strcmp(optarg, style_option_strings[i].style_string) == 0) {
                    break;
                }
            }
            if(i == sizeof(style_option_strings) / sizeof(style_option_strings[0])) {
                fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", optarg);
                for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                    fprintf(stderr, " %s", style_option_strings[i].style_string);
                }
                fprintf(stderr, "\n");
                invalid_usage(argv[0]);
            }
            break;
        case 'l':
            break;
        case 'g':
            break;
        case 'h':
            print_usage(argv[0]);
            return 0;
        case '?':
            invalid_usage(argv[0]);
        default:
            fprintf(stderr, "Unknown error while processing arguments\n");
            return 2;
        }
    }
    if(optind < argc - 1) {
        fprintf(stderr, "Error: Too many arguments.\n");
        invalid_usage(argv[0]);
    }
    if(optind < argc && strcmp(argv[optind], "-") != 0) {
    } else {
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int


repo: Quadra-H/QH-GPU

decompiled_code:
void __fastcall list_add_tail(_QWORD *a1, __int64 *a2)
{
_list_add(a1, *a2, a2);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, __int64 *a2)
{
func1(a1, *a2, a2);
}

original_code:
static inline void list_add_tail(struct list_head *new_item, struct list_head *head)
{
    __list_add(new_item, head->prev, head);
}

variable_types: struct list_head { struct list_head *prev; } *

variable_types:
head
struct list_head *


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_list_del(*(_QWORD *)a1, *(_QWORD **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
    __list_del(entry->prev, entry->next);
    entry->next = ((void *)0);
    entry->prev = ((void *)0);
}

user_defined_types: struct list_head { struct list_head *prev; }


decompiled_code:
__int64 qc_finit()
{
int v0; // ebx

if ( munmap(mmap_address, 0x400000uLL) == -1 )
puts("[qhgpu connector] error : unmap fail.");
v0 = devfd;
ioctl(devfd, 0x6705uLL);
close(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx

if ( munmap(mmap_address, 0x400000uLL) == -1 )
puts("[qhgpu connector] error : unmap fail.");
v0 = devfd;
ioctl(devfd, 0x6705uLL);
close(v0);
return 0LL;
}


decompiled_code:
__int64 __fastcall qc_send_response(void *buf)
{
int v1; // eax

v1 = write(devfd, buf, 8uLL);
safe_syscall(v1, "connector.c", 0x360u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *buf)
{
int v1; // eax

v1 = write(devfd, buf, 8uLL);
func9(v1, "connector.c", 0x360u);
return 0LL;
}

original_code:
int qc_send_response(struct qhgpu_ku_response *resp) {
 _safe_syscall(write(devfd, resp, sizeof(struct qhgpu_ku_response)), "connector.c", 864);
 return 0;
}

variable_types: struct qhgpu_ku_response { int id; int errcode; } *


decompiled_code:
__int64 qc_main_loop()
{
if ( !qc_loop_continue )
return 0LL;
do
{
_qc_process_request((__int64 (__fastcall *)(__int64))qc_service_done, (__int64)&post_exec_reqs, 0);
_qc_process_request(qc_post_exec, (__int64)&running_reqs, 1);
_qc_process_request((__int64 (__fastcall *)(__int64))qc_launch_exec, (__int64)&init_reqs, 0);
}
while ( (unsigned int)qc_get_next_service_request() != -123 && qc_loop_continue );
return 0LL;
}

canonical_decompiled_code:
__int64 func20()
{
if ( !qc_loop_continue )
return 0LL;
do
{
func19((__int64 (__fastcall *)(__int64))qc_service_done, (__int64)&post_exec_reqs, 0);
func19(qc_post_exec, (__int64)&running_reqs, 1);
func19((__int64 (__fastcall *)(__int64))qc_launch_exec, (__int64)&init_reqs, 0);
}
while ( (unsigned int)func16() != -123 && qc_loop_continue );
return 0LL;
}

original_code:
int qc_main_loop() {
 while (qc_loop_continue) {
  __qc_process_request(qc_service_done, &post_exec_reqs, 0);
  __qc_process_request(qc_post_exec, &running_reqs, 1);
  __qc_process_request(qc_launch_exec, &init_reqs, 0);
  if (qc_get_next_service_request() == -123) {
   break;
  }
 }
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

qhgpu_dev_path = "/dev/qhgpu";
service_lib_dir = (__int64)"./";
qc_init(argc, argv, envp);
v3 = (unsigned int)qc_load_all_services(service_lib_dir, context, devices);
printf("service_cnt: %d \n", v3);
if ( !(_DWORD)v3 )
LODWORD(v3) = 1;
if ( ioctl(devfd, 0x80106702uLL, (int)v3) < 0 )
{
perror("device write fail!");
abort();
}
init_mmap(v3);
qc_main_loop();
qc_finit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

qhgpu_dev_path = "/dev/qhgpu";
service_lib_dir = (__int64)"./";
func10(argc, argv, envp);
v3 = (unsigned int)qc_load_all_services(service_lib_dir, context, devices);
printf("service_cnt: %d \n", v3);
if ( !(_DWORD)v3 )
LODWORD(v3) = 1;
if ( ioctl(devfd, 0x80106702uLL, (int)v3) < 0 )
{
perror("device write fail!");
abort();
}
func8(v3);
func20();
func11();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int c;
 qhgpu_dev_path = "/dev/qhgpu";
 service_lib_dir = "./";
 qc_init();
 int service_cnt = qc_load_all_services(service_lib_dir, context, devices);
 printf("service_cnt: %d \n",service_cnt);
 if(service_cnt == 0) service_cnt = 1;
 int r = ioctl(devfd, (((2U) << (((0 +8)+8)+14)) | ((('g')) << (0 +8)) | (((2)) << 0) | ((((sizeof(struct qhgpu_gpu_mem_info[1])))) << ((0 +8)+8))),(unsigned long)service_cnt);
 if (r < 0) {
  perror("device write fail!");
  abort();
 }
 init_mmap(service_cnt);
 qc_main_loop();
 qc_finit();
 return 0;
}

variable_types:
argv
char *[]

variable_types: r int


canonical_original_code:
static inline void list_del(struct list_head *entry)
{
    __list_del(entry->prev, entry->next);
    entry->next = ((void *)0);
    entry->prev = ((void *)0);
}


decompiled_code:
__int64 __fastcall qc_unregister_service(char *a1)
{
char *v1; // rax

v1 = lookup_qhgpu_sitem(a1);
return _unregister_service(v1);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
char *v1; // rax

v1 = func5(a1);
return func7(v1);
}

original_code:
int qc_unregister_service(const char *name)
{
 return __unregister_service(lookup_qhgpu_sitem(name));
}

canonical_original_code:
int qc_unregister_service(char *name)
{
 return __unregister_service(lookup_qhgpu_sitem(name));
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall qc_load_all_services(const char *a1)
{
size_t v1; // rbx
unsigned int v2; // ebp
glob_t v4; // [rsp+0h] [rbp-168h] BYREF
char s[280]; // [rsp+50h] [rbp-118h] BYREF

v4.gl_pathc = 0LL;
v4.gl_pathv = 0LL;
v4.gl_offs = 0LL;
*(_QWORD *)&v4.gl_flags = 0LL;
v4.gl_closedir = 0LL;
v4.gl_readdir = 0LL;
v4.gl_opendir = 0LL;
v4.gl_lstat = 0LL;
v4.gl_stat = 0LL;
snprintf(s, 0x100uLL, "%s/%s*", a1, "libsrv_");
glob(s, 0, 0LL, &v4);
if ( v4.gl_pathc )
{
v1 = 0LL;
do
{
qc_load_service(v4.gl_pathv[v1]);
v2 = ++v1;
}
while ( v4.gl_pathc > v1 );
}
else
{
v2 = 0;
}
globfree(&v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
size_t v1; // rbx
unsigned int v2; // ebp
glob_t v4; // [rsp+0h] [rbp-168h] BYREF
char s[280]; // [rsp+50h] [rbp-118h] BYREF

v4.gl_pathc = 0LL;
v4.gl_pathv = 0LL;
v4.gl_offs = 0LL;
*(_QWORD *)&v4.gl_flags = 0LL;
v4.gl_closedir = 0LL;
v4.gl_readdir = 0LL;
v4.gl_opendir = 0LL;
v4.gl_lstat = 0LL;
v4.gl_stat = 0LL;
snprintf(s, 0x100uLL, "%s/%s*", a1, "libsrv_");
glob(s, 0, 0LL, &v4);
if ( v4.gl_pathc )
{
v1 = 0LL;
do
{
func11(v4.gl_pathv[v1]);
v2 = ++v1;
}
while ( v4.gl_pathc > v1 );
}
else
{
v2 = 0;
}
globfree(&v4);
return v2;
}

original_code:
int qc_load_all_services(const char *dir)
{
 char path[256];
 int i;
 char *libpath;
 int e=0;
 glob_t glb = {0,((void *)0),0};
 snprintf(path, 256, "%s/%s*", dir, "libsrv_");
 glob(path, 0, ((void *)0), &glb);
 for (i=0; i<glb.gl_pathc; i++)
 {
  libpath = glb.gl_pathv[i];
  e += qc_load_service(libpath);
 }
 globfree(&glb);
 return i;
}

canonical_original_code:
int qc_load_all_services(char *dir)
{
 char path[256];
 int i;
 char *libpath;
 int e = 0;
 struct glob_t glb = {0,((void *)0),0};
 snprintf(path, 256, "%s/%s*", dir, "libsrv_");
 glob(path, 0, ((void *)0), &glb);
 for (i=0; i<glb.gl_pathc; i++)
 {
  libpath = glb.gl_pathv[i];
  e += qc_load_service(libpath);
 }
 globfree(&glb);
 return i;
}

variable_types:
dir
char *

variable_types:
path
char [256]

variable_types:
libpath
char *

variable_types: e int

variable_types: struct glob_t { unsigned long gl_pathc; char **gl_pathv; unsigned long gl_offs; int gl_flags; void (*gl_closedir)(void *); void *(*gl_readdir)(void *); void *(*gl_opendir)(char *); int (*gl_lstat)(char *, void *); int (*gl_stat)(char *, void *); }


decompiled_code:
__int64 __fastcall qc_unload_service(char *a1)
{
char *v1; // rax

v1 = lookup_qhgpu_sitem(a1);
return _unload_service(v1);
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
char *v1; // rax

v1 = func5(a1);
return func9(v1);
}

original_code:
int qc_unload_service(const char *name)
{
    return __unload_service(lookup_qhgpu_sitem(name));
}

canonical_original_code:
int qc_unload_service(char *name)
{
    return __unload_service(lookup_qhgpu_sitem(name));
}


decompiled_code:
int qhgpu_log(int a1, const char *a2, const char *a3, __int64 a4, const char *a5, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 == 2 )
{
printf("[%s] %s() %d DEBUG: ", a2, a3, a4);
goto LABEL_9;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
printf("[%s] %s() %d INFO: ", a2, a3, a4);
goto LABEL_9;
}
LABEL_11:
printf("[%s] %s() %d: ", a2, a3, a4);
goto LABEL_9;
}
if ( !a1 )
{
printf("[%s] %s() %d ERROR: ", a2, a3, a4);
goto LABEL_9;
}
if ( a1 != 1 )
goto LABEL_11;
printf("[%s] %s() %d ALERT: ", a2, a3, a4);
LABEL_9:
va_start(arg, a5);
return vprintf(a5, arg);
}

canonical_decompiled_code:
int func0(int a1, const char *a2, const char *a3, __int64 a4, const char *a5, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 == 2 )
{
printf("[%s] %s() %d DEBUG: ", a2, a3, a4);
goto LABEL_9;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
printf("[%s] %s() %d INFO: ", a2, a3, a4);
goto LABEL_9;
}
LABEL_11:
printf("[%s] %s() %d: ", a2, a3, a4);
goto LABEL_9;
}
if ( !a1 )
{
printf("[%s] %s() %d ERROR: ", a2, a3, a4);
goto LABEL_9;
}
if ( a1 != 1 )
goto LABEL_11;
printf("[%s] %s() %d ALERT: ", a2, a3, a4);
LABEL_9:
va_start(arg, a5);
return vprintf(a5, arg);
}

original_code:
void qhgpu_log(int level, const char* module, const char *func, int line_num, const char *fmt, ...) {
 va_list args;
 switch(level) {
 case 0:
  printf("[%s] %s() %d ERROR: ", module, func, line_num);
  break;
 case 1:
  printf("[%s] %s() %d ALERT: ", module, func, line_num);
  break;
 case 2:
  printf("[%s] %s() %d DEBUG: ", module, func, line_num);
  break;
 case 3:
  printf("[%s] %s() %d INFO: ", module, func, line_num);
  break;
 case 4:
 default:
  printf("[%s] %s() %d: ", module, func, line_num);
  break;
 }
 __builtin_va_start(args,fmt);
 vprintf(fmt, args);
 __builtin_va_end(args);
}

canonical_original_code:
void qhgpu_log(int level, char *module, char *func, int line_num, char *fmt, ...) {
 __builtin_va_list args;
 switch(level) {
 case 0:
  printf("[%s] %s() %d ERROR: ", module, func, line_num);
  break;
 case 1:
  printf("[%s] %s() %d ALERT: ", module, func, line_num);
  break;
 case 2:
  printf("[%s] %s() %d DEBUG: ", module, func, line_num);
  break;
 case 3:
  printf("[%s] %s() %d INFO: ", module, func, line_num);
  break;
 case 4:
 default:
  printf("[%s] %s() %d: ", module, func, line_num);
  break;
 }
 __builtin_va_start(args,fmt);
 vprintf(fmt, args);
 __builtin_va_end(args);
}

variable_types: level int

variable_types:
module
char *

variable_types:
func
char *

variable_types:
fmt
char *


decompiled_code:
int __fastcall print_ip(unsigned int a1)
{
return printf("%3d.%3d.%3d.%3d", HIBYTE(a1), BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
return printf("%3d.%3d.%3d.%3d", HIBYTE(a1), BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
}

original_code:
void print_ip(int ip) {
 unsigned char bytes[4];
 bytes[0] = ip & 0xFF;
 bytes[1] = (ip >> 8) & 0xFF;
 bytes[2] = (ip >> 16) & 0xFF;
 bytes[3] = (ip >> 24) & 0xFF;
 printf("%3d.%3d.%3d.%3d", bytes[3], bytes[2], bytes[1], bytes[0]);
}

variable_types: ip int

variable_types:
bytes
unsigned char [4]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

if ( argc <= 1 )
{
fwrite("Option error\nNF Queue Num default setting 0.\n", 1uLL, 0x2DuLL, _bss_start);
v3 = 0LL;
}
else
{
v3 = (unsigned int)atoi(argv[1]);
}
return netlink_init(v3);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

if ( argc <= 1 )
{
fwrite("Option error\nNF Queue Num default setting 0.\n", 1uLL, 0x2DuLL, _bss_start);
v3 = 0LL;
}
else
{
v3 = (unsigned int)atoi(argv[1]);
}
return func12(v3);
}

original_code:
int main(int argc, char **argv) {
 int q_num = 0;
 if (argc < 2) {
  fprintf(stderr, "Option error\nNF Queue Num default setting 0.\n");
  q_num = 0;
 } else
  q_num = atoi(argv[1]);
 return netlink_init(q_num);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall finit_service(__int64 a1, __int64 (__fastcall *a2)(__int64 *))
{
puts("[libsrv_default] Info: mmap_ioctl_test finit");
return a2(&mmap_ioctl_srv);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 (__fastcall *a2)(__int64 *))
{
puts("[libsrv_default] Info: mmap_ioctl_test finit");
return a2(&mmap_ioctl_srv);
}

original_code:
int finit_service(void *lh, int (*unreg_srv)(const char*))
{
 printf("[libsrv_default] Info: mmap_ioctl_test finit\n");
 return unreg_srv(mmap_ioctl_srv.name);
}

canonical_original_code:
int finit_service(void *lh, int (*unreg_srv)(char *))
{
 printf("[libsrv_default] Info: mmap_ioctl_test finit\n");
 return unreg_srv(mmap_ioctl_srv.name);
}

variable_types:
lh
void *


decompiled_code:
__int64 __fastcall finit_service(__int64 a1, __int64 (__fastcall *a2)(char *))
{
puts("[libsrv_default] Info: finit default service");
return a2(default_srv);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 (__fastcall *a2)(char *))
{
puts("[libsrv_default] Info: finit default service");
return a2(default_srv);
}


repo: Queeniebee/Practice

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
gtk_init();
gtk_window_new();
g_type_check_instance_cast();
g_signal_connect_data();
gtk_label_new();
gtk_container_get_type();
g_type_check_instance_cast();
gtk_container_add();
gtk_widget_show_all();
gtk_main();
return 0;
}

original_code:
int main(void)
{
  printf("Hello World\n");
  return 0;
}

canonical_original_code:
int main()
{
  printf("Hello World\n");
  return 0;
}


repo: QuentinBarrand/ENSIIE-IALP-solitaire

decompiled_code:
int create_color()
{
start_color();
init_pair(1, 7, 0);
init_pair(2, 1, 0);
return init_pair(3, 2, 0);
}

canonical_decompiled_code:
int func0()
{
start_color();
init_pair(1, 7, 0);
init_pair(2, 1, 0);
return init_pair(3, 2, 0);
}

original_code:
static void create_color()
{
    start_color();
    init_pair(1, 7, 0);
    init_pair(2, 1, 0);
    init_pair(3, 2, 0);
}


decompiled_code:
int __fastcall Sgui_Help(int a1, int a2)
{
int v2; // ebx
int result; // eax

v2 = 3 * a1 + 16;
if ( a2 == 1 )
{
mvprintw(4, v2, "Aide :");
mvprintw(6, v2, aLnnlnnCoordonn);
mvprintw(7, v2, "\tL : lettre");
mvprintw(8, v2, "\tnn : chiffres");
mvprintw(9, v2, aPRevenirAuCoup);
mvprintw(10, v2, "i : Indication");
mvprintw(12, v2, "? : Cacher cette aide");
result = mvprintw(13, v2, "q : Quitter");
}
else
{
if ( wmove(stdscr, 4, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 6, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 7, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 8, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 9, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 10, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
result = wmove(stdscr, 11, v2);
if ( result != -1 )
result = whline(stdscr, 0x20uLL, COLS - 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2)
{
int v2; // ebx
int result; // eax

v2 = 3 * a1 + 16;
if ( a2 == 1 )
{
mvprintw(4, v2, "Aide :");
mvprintw(6, v2, aLnnlnnCoordonn);
mvprintw(7, v2, "\tL : lettre");
mvprintw(8, v2, "\tnn : chiffres");
mvprintw(9, v2, aPRevenirAuCoup);
mvprintw(10, v2, "i : Indication");
mvprintw(12, v2, "? : Cacher cette aide");
result = mvprintw(13, v2, "q : Quitter");
}
else
{
if ( wmove(stdscr, 4, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 6, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 7, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 8, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 9, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 10, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
result = wmove(stdscr, 11, v2);
if ( result != -1 )
result = whline(stdscr, 0x20uLL, COLS - 1);
}
return result;
}

original_code:
extern void Sgui_Help(int table_width, int print)
{
    int x_offset = 6 + table_width * 3 + 10;
    int y_offset = 4;
    if(print == 1)
    {
        mvprintw(y_offset, x_offset, "Aide :");
        mvprintw(y_offset + 2, x_offset, "LnnLnn : coordonnées");
        mvprintw(y_offset + 3, x_offset, "\tL : lettre");
        mvprintw(y_offset + 4, x_offset, "\tnn : chiffres");
        mvprintw(y_offset + 5, x_offset, "p : Revenir au coup "
            "précédent");
        mvprintw(y_offset + 6, x_offset, "i : Indication");
        mvprintw(y_offset + 8, x_offset, "? : Cacher cette "
            "aide");
        mvprintw(y_offset + 9, x_offset, "q : Quitter");
    }
    else
    {
        (wmove((stdscr),((y_offset)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 2)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 3)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 4)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 5)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 6)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 7)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
    }
}

variable_types: print int


decompiled_code:
size_t __fastcall Sgui_ReadCoup(char *s)
{
echo();
mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
wgetnstr(stdscr, s, -1);
noecho();
return strlen(s);
}

canonical_decompiled_code:
size_t __fastcall func3(char *s)
{
echo();
mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
wgetnstr(stdscr, s, -1);
noecho();
return strlen(s);
}

original_code:
extern int Sgui_ReadCoup(char* userinput)
{
    echo();
    mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
    wgetnstr(stdscr, (userinput), -1);
    noecho();
    return strlen(userinput);
}

canonical_original_code:
extern int Sgui_ReadCoup(char *userinput)
{
    echo();
    mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
    wgetnstr(stdscr, (userinput), -1);
    noecho();
    return strlen(userinput);
}

variable_types:
userinput
char *


decompiled_code:
int __fastcall Sgui_RuntimeMessage(char *a1, int a2)
{
if ( a2 == 1 )
{
wattr_on(stdscr, 0x300uLL, 0LL);
}
else if ( a2 == 2 )
{
wattr_on(stdscr, 0x200uLL, 0LL);
}
mvprintw(LINES - 1, 0, a1);
wrefresh(stdscr);
create_color();
wattr_on(stdscr, 0x100uLL, 0LL);
sleep(3u);
if ( wmove(stdscr, LINES - 1, 0) != -1 )
whline(stdscr, 0x20uLL, COLS);
if ( wmove(stdscr, LINES - 2, 36) != -1 )
whline(stdscr, 0x20uLL, COLS - 36);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, int a2)
{
if ( a2 == 1 )
{
wattr_on(stdscr, 0x300uLL, 0LL);
}
else if ( a2 == 2 )
{
wattr_on(stdscr, 0x200uLL, 0LL);
}
mvprintw(LINES - 1, 0, a1);
wrefresh(stdscr);
func0();
wattr_on(stdscr, 0x100uLL, 0LL);
sleep(3u);
if ( wmove(stdscr, LINES - 1, 0) != -1 )
whline(stdscr, 0x20uLL, COLS);
if ( wmove(stdscr, LINES - 2, 36) != -1 )
whline(stdscr, 0x20uLL, COLS - 36);
return wrefresh(stdscr);
}

variable_types:
message
char *

variable_types: enum message_type { INFO=0, SUCCESS=1, ERROR=2 }


decompiled_code:
int __fastcall Sgui_StartupError(char *s)
{
int v1; // ebx
size_t v2; // rax

v1 = LINES / 2 + 6;
create_color();
wattr_on(stdscr, 0x200uLL, 0LL);
v2 = strlen(s);
mvprintw(v1, COLS / 2 - (v2 >> 1), s);
return wattr_on(stdscr, 0x100uLL, 0LL);
}

canonical_decompiled_code:
int __fastcall func6(char *s)
{
int v1; // ebx
size_t v2; // rax

v1 = LINES / 2 + 6;
func0();
wattr_on(stdscr, 0x200uLL, 0LL);
v2 = strlen(s);
mvprintw(v1, COLS / 2 - (v2 >> 1), s);
return wattr_on(stdscr, 0x100uLL, 0LL);
}

original_code:
extern void Sgui_StartupError(char* message)
{
    int x_offset = (LINES / 2) + 6;
    create_color();
    wattr_on(stdscr, (attr_t)(((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    mvprintw(x_offset, (COLS / 2) - (strlen(message) / 2), message);
    wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
}

canonical_original_code:
extern void Sgui_StartupError(char *message)
{
    int x_offset = (LINES / 2) + 6;
    create_color();
    wattr_on(stdscr, (attr_t)(((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    mvprintw(x_offset, (COLS / 2) - (strlen(message) / 2), message);
    wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
}


decompiled_code:
int Sgui_Terminer()
{
wclear(stdscr);
mvprintw(LINES / 2, COLS / 2 - 17, aMerciDAvoirJou);
wrefresh(stdscr);
sleep(3u);
return endwin();
}

canonical_decompiled_code:
int func7()
{
wclear(stdscr);
mvprintw(LINES / 2, COLS / 2 - 17, aMerciDAvoirJou);
wrefresh(stdscr);
sleep(3u);
return endwin();
}

original_code:
extern void Sgui_Terminer()
{
    wclear(stdscr);
    mvprintw(LINES / 2, COLS / 2 - 17, "Merci d'avoir joué, à bientôt !");
    wrefresh(stdscr);
    sleep(3);
    endwin();
}


decompiled_code:
void __fastcall Stack_Free(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Stack_Free(Stack* stack)
{
    free(stack->container);
    free(stack);
}

canonical_original_code:
void Stack_Free(struct Stack *stack)
{
    free(stack->container);
    free(stack);
}

variable_types: struct Stack { int count; int max; void **container; } *


decompiled_code:
__int64 __fastcall Stack_Size(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return *a1;
}

original_code:
int Stack_Size(Stack* stack)
{
    return stack->count;
}

canonical_original_code:
int Stack_Size(struct Stack *stack)
{
    return stack->count;
}

user_defined_types: struct Stack { int count; int max; void **container; }


decompiled_code:
__int64 __fastcall Stack_Max(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int Stack_Max(Stack* stack)
{
    return stack->max;
}

canonical_original_code:
int Stack_Max(struct Stack *stack)
{
    return stack->max;
}


decompiled_code:
_BOOL8 __fastcall Stack_IsEmpty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int Stack_IsEmpty(Stack* stack)
{
    if(stack->count == 0)
        return 1;
    return 0;
}

canonical_original_code:
int Stack_IsEmpty(struct Stack *stack)
{
    if(stack->count == 0)
        return 1;
    return 0;
}


decompiled_code:
void *__fastcall Stack_ResizeContainer(__int64 a1)
{
int v1; // er12
void *v2; // rax
void *result; // rax

v1 = *(_DWORD *)(a1 + 4);
v2 = malloc(16LL * v1);
result = memmove(v2, *(const void **)(a1 + 8), 8LL * v1);
*(_DWORD *)(a1 + 4) = 2 * v1;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
int v1; // er12
void *v2; // rax
void *result; // rax

v1 = *(_DWORD *)(a1 + 4);
v2 = malloc(16LL * v1);
result = memmove(v2, *(const void **)(a1 + 8), 8LL * v1);
*(_DWORD *)(a1 + 4) = 2 * v1;
return result;
}

original_code:
void** Stack_ResizeContainer(Stack* stack)
{
    void** tmpContainer = malloc(sizeof(void**) * stack->max * 2);
    bcopy(stack->container, tmpContainer, sizeof(void**)*stack->max);
    stack->max *= 2;
    return tmpContainer;
}

canonical_original_code:
void **Stack_ResizeContainer(struct Stack *stack)
{
    void **tmpContainer = malloc(sizeof(void**) * stack->max * 2);
    bcopy(stack->container, tmpContainer, sizeof(void **)*stack->max);
    stack->max *= 2;
    return tmpContainer;
}

variable_types:
tmpContainer
void **

return_type: void **


decompiled_code:
__int64 __fastcall Stack_Search(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // edx

LODWORD(v2) = *(_DWORD *)a2 - 1;
if ( (int)v2 < 0 )
return (unsigned int)-1;
v2 = (int)v2;
while ( 1 )
{
v3 = v2;
if ( *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v2) == a1 )
break;
if ( (int)--v2 < 0 )
return (unsigned int)-1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // edx

LODWORD(v2) = *(_DWORD *)a2 - 1;
if ( (int)v2 < 0 )
return (unsigned int)-1;
v2 = (int)v2;
while ( 1 )
{
v3 = v2;
if ( *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v2) == a1 )
break;
if ( (int)--v2 < 0 )
return (unsigned int)-1;
}
return v3;
}

original_code:
int Stack_Search(void* value, Stack* stack)
{
    int i;
    for(i = stack->count - 1; i >= 0; i--)
    {
        if(stack->container[i] == value)
            return i;
    }
    return -1;
}

canonical_original_code:
int Stack_Search(void *value, struct Stack *stack)
{
    int i;
    for(i = stack->count - 1; i >= 0; i--)
    {
        if(stack->container[i] == value)
            return i;
    }
    return -1;
}

variable_types:
value
void *

variable_types: i int


original_code:
void* Stack_Peek(Stack* stack)
{
    if (stack->count > 0)
        return stack->container[stack->count - 1];
    return ((void *)0);
}

canonical_original_code:
void *Stack_Peek(struct Stack *stack)
{
    if (stack->count > 0)
        return stack->container[stack->count - 1];
    return ((void *)0);
}

return_type: void *


decompiled_code:
__int64 __fastcall Stack_Push(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(_DWORD *)a2 == *(_DWORD *)(a2 + 4) )
*(_QWORD *)(a2 + 8) = Stack_ResizeContainer(a2);
result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(result + 8LL * (int)(*(_DWORD *)a2)++) = a1;
return result;
}

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

if ( *(_DWORD *)a2 == *(_DWORD *)(a2 + 4) )
*(_QWORD *)(a2 + 8) = func4(a2);
result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(result + 8LL * (int)(*(_DWORD *)a2)++) = a1;
return result;
}

original_code:
void Stack_Push(void* item, Stack* stack)
{
    if (stack->count == stack->max)
        stack->container = Stack_ResizeContainer(stack);
    stack->container[stack->count] = item;
    stack->count++;
}

canonical_original_code:
void Stack_Push(void *item, struct Stack *stack)
{
    if (stack->count == stack->max)
        stack->container = Stack_ResizeContainer(stack);
    stack->container[stack->count] = item;
    stack->count++;
}

variable_types:
item
void *


original_code:
void* Stack_Pop(Stack* stack)
{
    if (stack->count > 0)
    {
        stack->count--;
        return stack->container[stack->count];
    }
    return ((void *)0);
}

canonical_original_code:
void *Stack_Pop(struct Stack *stack)
{
    if (stack->count > 0)
    {
        stack->count--;
        return stack->container[stack->count];
    }
    return ((void *)0);
}


getOrdByNumber

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

if ( (unsigned __int8)(a1 - 49) > 8u )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a1 - 49);
return result;
}

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

if ( (unsigned __int8)(a1 - 49) > 8u )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a1 - 49);
return result;
}

original_code:
static int getOrdByNumber(char c)
{
    const int FUNC_NOT_A_NUMBER = -1;
    return (c >= '1' && c <= '9') ? c - '0' - 1 : FUNC_NOT_A_NUMBER;
}

canonical_original_code:
static int getOrdByNumber(char c)
{
    int FUNC_NOT_A_NUMBER = -1;
    return (c >= '1' && c <= '9') ? c - '0' - 1 : FUNC_NOT_A_NUMBER;
}

variable_types: c char


getOrdByTwoNumbers

decompiled_code:
__int64 __fastcall getOrdByTwoNumbers(char a1, char a2)
{
int v2; // ebp
int v3; // eax
__int64 result; // rax

v2 = getOrdByNumber(a1) + 1;
v3 = getOrdByNumber(a2) + 1;
if ( v2 && v3 )
result = (unsigned int)(v3 + 10 * v2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, char a2)
{
int v2; // ebp
int v3; // eax
__int64 result; // rax

v2 = func0(a1) + 1;
v3 = func0(a2) + 1;
if ( v2 && v3 )
result = (unsigned int)(v3 + 10 * v2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int getOrdByTwoNumbers(char c1, char c2)
{
    const int FUNC_NOT_A_NUMBER = -1;
    int p1 = getOrdByNumber(c1) + 1;
    int p2 = getOrdByNumber(c2) + 1;
    if(p1 == 0 || p2 == 0) return FUNC_NOT_A_NUMBER;
    return 10 * p1 + p2;
}

canonical_original_code:
static int getOrdByTwoNumbers(char c1, char c2)
{
    int FUNC_NOT_A_NUMBER = -1;
    int p1 = getOrdByNumber(c1) + 1;
    int p2 = getOrdByNumber(c2) + 1;
    if(p1 == 0 || p2 == 0) return FUNC_NOT_A_NUMBER;
    return 10 * p1 + p2;
}


getAbsByLetter

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

if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return (unsigned int)(a1 - 65);
result = (unsigned int)(a1 - 97);
if ( (unsigned __int8)(a1 - 97) >= 0x1Au )
result = 0xFFFFFFFFLL;
return result;
}

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

if ( (unsigned __int8)(a1 - 65) <= 0x19u )
return (unsigned int)(a1 - 65);
result = (unsigned int)(a1 - 97);
if ( (unsigned __int8)(a1 - 97) >= 0x1Au )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int getAbsByLetter(char c)
{
    const int FUNC_NOT_A_LETTER = -1;
    if(c >= 'A' && c <= 'Z') return c - 'A';
    if(c >= 'a' && c <= 'z') return c - 'a';
    return FUNC_NOT_A_LETTER;
}

canonical_original_code:
static int getAbsByLetter(char c)
{
    int FUNC_NOT_A_LETTER = -1;
    if(c >= 'A' && c <= 'Z') return c - 'A';
    if(c >= 'a' && c <= 'z') return c - 'a';
    return FUNC_NOT_A_LETTER;
}


decompiled_code:
__int64 __fastcall coordutils_ToIntCoord(char *s, _DWORD *a2, int a3, int a4)
{
_DWORD *v4; // r13
char v5; // r12
int i; // ebx
int v7; // eax
__int64 result; // rax
char v9; // r15
int v10; // eax
int v11; // eax

v4 = a2;
v5 = 1;
for ( i = 0; i < (int)strlen(s); ++i )
{
if ( (v5 & 1) != 0 )
{
v7 = getAbsByLetter(s[i]);
if ( v7 == -1 )
return 1LL;
*v4 = v7;
}
else
{
v9 = s[i];
v10 = getOrdByTwoNumbers(v9, s[i + 1]);
if ( v10 == -1 )
{
v11 = getOrdByNumber(v9);
if ( v11 == -1 )
return 1LL;
*v4 = v11;
}
else
{
*v4 = v10;
++i;
}
}
++v5;
++v4;
}
result = 2LL;
if ( *a2 < a3 && a2[1] < a4 && a2[2] < a3 )
result = 2 * (unsigned int)(a2[3] >= a4);
return result;
}

original_code:
extern int coordutils_ToIntCoord(char* userinput, int* coord, int width,
    int length)
{
    const int FUNC_SUCCESS = 0;
    const int FUNC_INCORRECT_CHAR = 1;
    const int FUNC_OUT_OF_BOUNDS = 2;
    int i, j = 0, current;
    for(i = 0; i < (int)strlen(userinput); i++)
    {
        if(j % 2 == 0)
        {
            if((current = getAbsByLetter(userinput[i])) != -1)
            {
                coord[j] = current;
                j++;
                continue;
            }
        }
        else
        {
            if((current =
                getOrdByTwoNumbers(userinput[i], userinput[i + 1])) != -1)
            {
                coord[j] = current;
                i++;
                j++;
                continue;
            }
            if((current = getOrdByNumber(userinput[i])) != -1)
            {
                coord[j] = current;
                j++;
                continue;
            }
        }
        return FUNC_INCORRECT_CHAR;
    }
    if(coord[0] + 1 > width ||
        coord[1] + 1 > length ||
        coord[2] + 1 > width ||
        coord[3] + 1 > length)
        return FUNC_OUT_OF_BOUNDS;
    return FUNC_SUCCESS;
}

canonical_original_code:
extern int coordutils_ToIntCoord(char *userinput, int *coord, int width, int length)
{
    int FUNC_SUCCESS = 0;
    int FUNC_INCORRECT_CHAR = 1;
    int FUNC_OUT_OF_BOUNDS = 2;
    int i; int j = 0; int current;
    for(i = 0; i < (int)strlen(userinput); i++)
    {
        if(j % 2 == 0)
        {
            if((current = getAbsByLetter(userinput[i])) != -1)
            {
                coord[j] = current;
                j++;
                continue;
            }
        }
        else
        {
            if((current =
                getOrdByTwoNumbers(userinput[i], userinput[i + 1])) != -1)
            {
                coord[j] = current;
                i++;
                j++;
                continue;
            }
            if((current = getOrdByNumber(userinput[i])) != -1)
            {
                coord[j] = current;
                j++;
                continue;
            }
        }
        return FUNC_INCORRECT_CHAR;
    }
    if(coord[0] + 1 > width ||
        coord[1] + 1 > length ||
        coord[2] + 1 > width ||
        coord[3] + 1 > length)
        return FUNC_OUT_OF_BOUNDS;
    return FUNC_SUCCESS;
}

variable_types:
coord
int *

variable_types: width int

variable_types: length int

variable_types: j int

variable_types: current int


repo: RHESSys/RHESSys

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

if ( !memcmp(ptr, "TREE", 4uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "tree", 4uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "GRASS", 5uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "grass", 5uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "C4GRASS", 7uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "c4grass", 7uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "C3GRASS", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "c3grass", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "NON_VEG", 5uLL) )
{
v2 = 20;
}
else
{
if ( memcmp(ptr, "non_veg", 5uLL) )
{
fwrite("\n FATAL ERROR - parse_veg_type", 1uLL, 0x1EuLL, stderr);
fprintf(stderr, "\n %s Unknown veg type in stratum default file", (const char *)ptr);
fwrite("\n must be either TREE or GRASS\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
v2 = 20;
}
free(ptr);
return v2;
}

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

if ( !memcmp(ptr, "TREE", 4uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "tree", 4uLL) )
{
v2 = 1;
}
else if ( !memcmp(ptr, "GRASS", 5uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "grass", 5uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "C4GRASS", 7uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "c4grass", 7uLL) )
{
v2 = 3;
}
else if ( !memcmp(ptr, "C3GRASS", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "c3grass", 7uLL) )
{
v2 = 2;
}
else if ( !memcmp(ptr, "NON_VEG", 5uLL) )
{
v2 = 20;
}
else
{
if ( memcmp(ptr, "non_veg", 5uLL) )
{
fwrite("\n FATAL ERROR - parse_veg_type", 1uLL, 0x1EuLL, stderr);
fprintf(stderr, "\n %s Unknown veg type in stratum default file", (const char *)ptr);
fwrite("\n must be either TREE or GRASS\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
v2 = 20;
}
free(ptr);
return v2;
}

original_code:
int parse_veg_type( char *input_string)
{
 int veg_type;
 if ((strncmp(input_string,"TREE",4) == 0) ||
  (strncmp(input_string, "tree",4) == 0) )
  veg_type = 1;
 else if ((strncmp(input_string,"GRASS",5) == 0) ||
  (strncmp(input_string, "grass",5) == 0) )
  veg_type = 2;
 else if ((strncmp(input_string,"C4GRASS",7) == 0) ||
  (strncmp(input_string, "c4grass",7) == 0) )
  veg_type = 3;
 else if ((strncmp(input_string,"C3GRASS",7) == 0) ||
  (strncmp(input_string, "c3grass",7) == 0) )
  veg_type = 2;
 else if ((strncmp(input_string,"NON_VEG",5) == 0) ||
  (strncmp(input_string, "non_veg",5) == 0) )
  veg_type = 20;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_veg_type");
  fprintf(stderr,"\n %s Unknown veg type in stratum default file", input_string);
  fprintf(stderr,"\n must be either TREE or GRASS\n");
  exit(1);
 }
 free(input_string);
 return(veg_type);
}

canonical_original_code:
int parse_veg_type(char *input_string)
{
 int veg_type;
 if ((strncmp(input_string,"TREE",4) == 0) ||
  (strncmp(input_string, "tree",4) == 0) )
  veg_type = 1;
 else if ((strncmp(input_string,"GRASS",5) == 0) ||
  (strncmp(input_string, "grass",5) == 0) )
  veg_type = 2;
 else if ((strncmp(input_string,"C4GRASS",7) == 0) ||
  (strncmp(input_string, "c4grass",7) == 0) )
  veg_type = 3;
 else if ((strncmp(input_string,"C3GRASS",7) == 0) ||
  (strncmp(input_string, "c3grass",7) == 0) )
  veg_type = 2;
 else if ((strncmp(input_string,"NON_VEG",5) == 0) ||
  (strncmp(input_string, "non_veg",5) == 0) )
  veg_type = 20;
 else {
  fprintf(stderr,"\n FATAL ERROR - parse_veg_type");
  fprintf(stderr,"\n %s Unknown veg type in stratum default file", input_string);
  fprintf(stderr,"\n must be either TREE or GRASS\n");
  exit(1);
 }
 free(input_string);
 return(veg_type);
}


original_code:
int compute_farq_psn( struct psnin_struct *in,
      struct psnout_struct* out, int verbose)
{
 int ok=1;
 double t;
 double tk;
 double g;
 double O2;
 double Ca;
 double gamma;
 double Kc;
 double Ko;
 double act;
 double Rd;
 double Vmax;
 double Jmax;
 double J;
 double Av;
 double Aj;
 double A;
 double aa,bb,cc,det;
 double netpabs;
 int c3;
 static double fnr = 7.16;
 static double Kc25 = 404.0;
 static double q10Kc = 2.1;
 static double Ko25 = 248.0;
 static double q10Ko = 1.2;
 static double act25 = 3.6;
 static double q10act = 2.4;
 static double pabs = 0.85;
 Rd = in->Rd;
 t = in->t;
 tk = t + 273.15;
 g = in->g * 1e3 / (8.3143 * tk);
 Ca = in->co2 * in->pa / 1e6;
 c3 = 0;
 in->c3 = 1;
 netpabs = in->netpabs;
 if (in->c3)
        {
  c3 = 1;
        }
        else
        {
                Ca *= 10.0;
        }
 O2 = 0.21 * in->pa;
 Ko = Ko25 * pow(q10Ko, (t-25.0)/10.0);
 Ko = Ko * 100.0;
 if (t > 15.0){
  Kc = Kc25 * pow(q10Kc, (t-25.0)/10.0);
  act = act25 * pow(q10act, (t-25.0)/10.0);
 }
 else{
  Kc = Kc25 * pow(1.8*q10Kc, (t-15.0)/10.0) / q10Kc;
  act = act25 * pow(1.8*q10act, (t-15.0)/10.0) / q10act;
 }
 Kc = Kc * 0.10;
 act = act * 1e6 / 60.0;
 gamma = 0.5 * 0.21 * Kc * O2 / Ko;
 Vmax = in->lnc * in->flnr * fnr * act;
 Jmax = 2.1 * Vmax;
        aa = 0.7;
        bb = -Jmax - (in->irad*netpabs);
        cc = Jmax * in->irad*netpabs;
        J = (-bb - sqrt(bb*bb - 4.0*aa*cc))/(2.0*aa);
 aa = -1.0/g;
 bb = Ca + (Vmax - Rd)/g + Kc*(1.0 + O2/Ko);
 cc = Vmax*(gamma - Ca) + Rd*(Ca + Kc*(1.0 + O2/Ko));
 if ((det = bb*bb - 4.0*aa*cc) < 0.0){
  printf("negative root error in psn routine\n");
  return (1);
 }
 Av = (-bb + sqrt(det)) / (2.0*aa);
 aa = -4.5/g;
 bb = 4.5*Ca + 10.5*gamma + J/g - 4.5*Rd/g;
 cc = J*(gamma - Ca) + Rd*(4.5*Ca + 10.5*gamma);
 if ((det = bb*bb - 4.0*aa*cc) < 0.0){
  printf("negative root error in psn routine\n");
  return(1);
 }
 Aj = (-bb + sqrt(det)) / (2.0*aa);
 if (Av < Aj)
  A = Av;
 else
  A = Aj;
 out->A = A;
  out->g = g;
  out->Ca = Ca;
  out->Ci = Ca - A/g;
  out->dC13 = out->Ci/out->Ca*(28-4.4)+4.4;
  out->gamma = gamma;
  out->O2 = O2;
  out->Kc = Kc;
  out->Ko = Ko;
  out->act = act;
  out->Vmax = Vmax;
  out->Jmax = Jmax;
  out->J = J;
  out->Av = Av;
  out->Aj = Aj;
 return (!ok);
}

canonical_original_code:
int compute_farq_psn(struct psnin_struct *in, struct psnout_struct *out, int verbose)
{
 int ok = 1;
 double t;
 double tk;
 double g;
 double O2;
 double Ca;
 double gamma;
 double Kc;
 double Ko;
 double act;
 double Rd;
 double Vmax;
 double Jmax;
 double J;
 double Av;
 double Aj;
 double A;
 double aa; double bb; double cc; double det;
 double netpabs;
 int c3;
 static double fnr = 7.16;
 static double Kc25 = 404.0;
 static double q10Kc = 2.1;
 static double Ko25 = 248.0;
 static double q10Ko = 1.2;
 static double act25 = 3.6;
 static double q10act = 2.4;
 static double pabs = 0.85;
 Rd = in->Rd;
 t = in->t;
 tk = t + 273.15;
 g = in->g * 1e3 / (8.3143 * tk);
 Ca = in->co2 * in->pa / 1e6;
 c3 = 0;
 in->c3 = 1;
 netpabs = in->netpabs;
 if (in->c3)
        {
  c3 = 1;
        }
        else
        {
                Ca *= 10.0;
        }
 O2 = 0.21 * in->pa;
 Ko = Ko25 * pow(q10Ko, (t-25.0)/10.0);
 Ko = Ko * 100.0;
 if (t > 15.0){
  Kc = Kc25 * pow(q10Kc, (t-25.0)/10.0);
  act = act25 * pow(q10act, (t-25.0)/10.0);
 }
 else{
  Kc = Kc25 * pow(1.8*q10Kc, (t-15.0)/10.0) / q10Kc;
  act = act25 * pow(1.8*q10act, (t-15.0)/10.0) / q10act;
 }
 Kc = Kc * 0.10;
 act = act * 1e6 / 60.0;
 gamma = 0.5 * 0.21 * Kc * O2 / Ko;
 Vmax = in->lnc * in->flnr * fnr * act;
 Jmax = 2.1 * Vmax;
        aa = 0.7;
        bb = -Jmax - (in->irad*netpabs);
        cc = Jmax * in->irad*netpabs;
        J = (-bb - sqrt(bb*bb - 4.0*aa*cc))/(2.0*aa);
 aa = -1.0/g;
 bb = Ca + (Vmax - Rd)/g + Kc*(1.0 + O2/Ko);
 cc = Vmax*(gamma - Ca) + Rd*(Ca + Kc*(1.0 + O2/Ko));
 if ((det = bb*bb - 4.0*aa*cc) < 0.0){
  printf("negative root error in psn routine\n");
  return (1);
 }
 Av = (-bb + sqrt(det)) / (2.0*aa);
 aa = -4.5/g;
 bb = 4.5*Ca + 10.5*gamma + J/g - 4.5*Rd/g;
 cc = J*(gamma - Ca) + Rd*(4.5*Ca + 10.5*gamma);
 if ((det = bb*bb - 4.0*aa*cc) < 0.0){
  printf("negative root error in psn routine\n");
  return(1);
 }
 Aj = (-bb + sqrt(det)) / (2.0*aa);
 if (Av < Aj)
  A = Av;
 else
  A = Aj;
 out->A = A;
  out->g = g;
  out->Ca = Ca;
  out->Ci = Ca - A/g;
  out->dC13 = out->Ci/out->Ca*(28-4.4)+4.4;
  out->gamma = gamma;
  out->O2 = O2;
  out->Kc = Kc;
  out->Ko = Ko;
  out->act = act;
  out->Vmax = Vmax;
  out->Jmax = Jmax;
  out->J = J;
  out->Av = Av;
  out->Aj = Aj;
 return (!ok);
}

variable_types: struct psnin_struct { int c3; double pa; double co2; double t; double irad; double g; double Rd; double lnc; double flnr; double netpabs; } *

variable_types: struct psnout_struct { double g; double O2; double Ca; double Ci; double gamma; double Kc; double Ko; double act; double Vmax; double Jmax; double J; double Av; double Aj; double A; double dC13; } *

variable_types: verbose int

variable_types: ok int

variable_types: t double

variable_types: tk double

variable_types: g double

variable_types: Ca double

variable_types: gamma double

variable_types: Kc double

variable_types: Ko double

variable_types: act double

variable_types: Rd double

variable_types: Vmax double

variable_types: Jmax double

variable_types: J double

variable_types: Av double

variable_types: Aj double

variable_types: A double

variable_types: aa double

variable_types: bb double

variable_types: cc double

variable_types: det double

variable_types: netpabs double

variable_types: fnr double

variable_types: pabs double


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

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

original_code:
void destroy_hillslope_defaults(int num_default_files,
        int grow_flag,
        struct hillslope_default *default_object_list )
{
 int i;
 free( default_object_list );
 return;
}

canonical_original_code:
void destroy_hillslope_defaults(int num_default_files, int grow_flag, struct hillslope_default *default_object_list)
{
 int i;
 free( default_object_list );
 return;
}

variable_types: struct hillslope_default { int ID; int n_routing_timesteps; double gw_loss_coeff; double gw_loss_fast_coeff; double gw_loss_fast_threshold; } *

variable_types: i int


freePointerSet

decompiled_code:
__int64 __fastcall freePointerSet(_QWORD *a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1[1];
free(a1);
result = freePointerSet(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1[1];
free(a1);
result = func0(v1);
}
return result;
}

original_code:
void freePointerSet(PointerSet *set) {
 if (set == ((void *)0)) return;
 PointerSet *next = set->next;
 free(set);
 freePointerSet(next);
}

canonical_original_code:
void freePointerSet(struct pointer_set_s *set) {
 if (set == ((void *)0)) return;
 struct pointer_set_s *next = set->next;
 free(set);
 freePointerSet(next);
}

variable_types: struct pointer_set_s { void *ptr; struct pointer_set_s *next; } *


printPointerSet

decompiled_code:
size_t __fastcall printPointerSet(const void **a1)
{
const void **v1; // rbx

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

canonical_decompiled_code:
size_t __fastcall func1(const void **a1)
{
const void **v1; // rbx

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

original_code:
void printPointerSet(PointerSet *set) {
 fprintf(stderr, "PointerSet@%p {\n", (void *)set);
 PointerSet *s = set;
 while (s != ((void *)0)) {
  fprintf(stderr, "%p,\n", s->ptr);
  s = s->next;
 }
 fprintf(stderr, "}\n");
}

canonical_original_code:
void printPointerSet(struct pointer_set_s *set) {
 fprintf(stderr, "PointerSet@%p {\n", (void *)set);
 struct pointer_set_s *s = set;
 while (s != ((void *)0)) {
  fprintf(stderr, "%p,\n", s->ptr);
  s = s->next;
 }
 fprintf(stderr, "}\n");
}

user_defined_types: struct pointer_set_s { void *ptr; struct pointer_set_s *next; }


original_code:
double adjust_pit(struct flow_struct *flow_table, int curr, int edge_inx,
  double edge_elev, double cell, int slp_flag)
{
 int j;
 double total_perimeter;
 float xrun, yrun;
 float rise;
 struct adj_struct *aptr;
 if (flow_table[curr].num_adjacent > 0) {
  aptr = flow_table[curr].adj_list;
  total_perimeter = aptr->perimeter;
  for (j = 1; j < flow_table[curr].num_adjacent; j++) {
   aptr = aptr->next;
   total_perimeter += aptr->perimeter;
  }
 } else
  total_perimeter = 0.0;
 if (flow_table[curr].num_adjacent == 0) {
  if ((flow_table[curr].adj_list = (struct adj_struct *) malloc(
    sizeof(struct adj_struct))) == ((void *)0) ) {
   printf("\n Not enough memory");
   exit(1);
  }
  aptr = flow_table[curr].adj_list;
 }
 else {
  if ((aptr->next = (struct adj_struct *) malloc(
    sizeof(struct adj_struct))) == ((void *)0) ) {
   printf("\n Not enough memory");
   exit(1);
  }
  aptr = aptr->next;
 }
 aptr->patchID = flow_table[edge_inx].patchID;
 aptr->zoneID = flow_table[edge_inx].zoneID;
 aptr->hillID = flow_table[edge_inx].hillID;
 aptr->perimeter = total_perimeter;
 aptr->z = (float) edge_elev;
 aptr->inx = edge_inx;
 xrun = (flow_table[curr].x - flow_table[edge_inx].x);
 xrun = xrun * xrun;
 yrun = (flow_table[curr].y - flow_table[edge_inx].y);
 yrun = yrun * yrun;
 rise = flow_table[curr].z - flow_table[edge_inx].z;
 if ((yrun + xrun) <= 0.000000001)
  aptr->slope = rise;
 else
  aptr->slope = (float) (rise / (sqrt(xrun + yrun) * (cell)));
 aptr->gamma = 1.0;
 flow_table[curr].gamma_neigh = (float) (aptr->perimeter * aptr->slope);
 if (0 == slp_flag) {
  flow_table[curr].total_gamma = (float) (flow_table[curr].area
    * aptr->slope * cell * cell);
 }
 if (1 == slp_flag) {
  flow_table[curr].total_gamma = (float) (flow_table[curr].area
    * flow_table[curr].internal_slope * cell * cell);
 }
 if (2 == slp_flag) {
  flow_table[curr].total_gamma = (float) (flow_table[curr].area
    * flow_table[curr].max_slope * cell * cell);
 }
 flow_table[curr].z = (float) (edge_elev + 0.001);
 flow_table[curr].num_adjacent += 1;
 return (1);
}

canonical_original_code:
double adjust_pit(struct flow_struct *flow_table, int curr, int edge_inx, double edge_elev, double cell, int slp_flag)
{
 int j;
 double total_perimeter;
 float xrun; float yrun;
 float rise;
 struct adj_struct *aptr;
 if (flow_table[curr].num_adjacent > 0) {
  aptr = flow_table[curr].adj_list;
  total_perimeter = aptr->perimeter;
  for (j = 1; j < flow_table[curr].num_adjacent; j++) {
   aptr = aptr->next;
   total_perimeter += aptr->perimeter;
  }
 } else
  total_perimeter = 0.0;
 if (flow_table[curr].num_adjacent == 0) {
  if ((flow_table[curr].adj_list = (struct adj_struct *) malloc(
    sizeof(struct adj_struct))) == ((void *)0) ) {
   printf("\n Not enough memory");
   exit(1);
  }
  aptr = flow_table[curr].adj_list;
 }
 else {
  if ((aptr->next = (struct adj_struct *) malloc(
    sizeof(struct adj_struct))) == ((void *)0) ) {
   printf("\n Not enough memory");
   exit(1);
  }
  aptr = aptr->next;
 }
 aptr->patchID = flow_table[edge_inx].patchID;
 aptr->zoneID = flow_table[edge_inx].zoneID;
 aptr->hillID = flow_table[edge_inx].hillID;
 aptr->perimeter = total_perimeter;
 aptr->z = (float) edge_elev;
 aptr->inx = edge_inx;
 xrun = (flow_table[curr].x - flow_table[edge_inx].x);
 xrun = xrun * xrun;
 yrun = (flow_table[curr].y - flow_table[edge_inx].y);
 yrun = yrun * yrun;
 rise = flow_table[curr].z - flow_table[edge_inx].z;
 if ((yrun + xrun) <= 0.000000001)
  aptr->slope = rise;
 else
  aptr->slope = (float) (rise / (sqrt(xrun + yrun) * (cell)));
 aptr->gamma = 1.0;
 flow_table[curr].gamma_neigh = (float) (aptr->perimeter * aptr->slope);
 if (0 == slp_flag) {
  flow_table[curr].total_gamma = (float) (flow_table[curr].area
    * aptr->slope * cell * cell);
 }
 if (1 == slp_flag) {
  flow_table[curr].total_gamma = (float) (flow_table[curr].area
    * flow_table[curr].internal_slope * cell * cell);
 }
 if (2 == slp_flag) {
  flow_table[curr].total_gamma = (float) (flow_table[curr].area
    * flow_table[curr].max_slope * cell * cell);
 }
 flow_table[curr].z = (float) (edge_elev + 0.001);
 flow_table[curr].num_adjacent += 1;
 return (1);
}

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

variable_types: curr int

variable_types: cell double

variable_types: j int

variable_types: xrun float

variable_types: yrun float

variable_types: rise float

return_type: double

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


decompiled_code:
_QWORD *new_struct_index()
{
_QWORD *result; // rax

result = malloc(0xE8uLL);
if ( !result )
_assert_fail("i", "util/index_struct_fields.c", 0xDu, "new_struct_index");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
result[8] = 0LL;
result[9] = 0LL;
result[10] = 0LL;
result[11] = 0LL;
result[12] = 0LL;
result[13] = 0LL;
result[14] = 0LL;
result[15] = 0LL;
result[16] = 0LL;
result[17] = 0LL;
result[18] = 0LL;
result[19] = 0LL;
result[20] = 0LL;
result[21] = 0LL;
result[22] = 0LL;
result[23] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0xE8uLL);
if ( !result )
_assert_fail("i", "util/index_struct_fields.c", 0xDu, "new_struct_index");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
result[8] = 0LL;
result[9] = 0LL;
result[10] = 0LL;
result[11] = 0LL;
result[12] = 0LL;
result[13] = 0LL;
result[14] = 0LL;
result[15] = 0LL;
result[16] = 0LL;
result[17] = 0LL;
result[18] = 0LL;
result[19] = 0LL;
result[20] = 0LL;
result[21] = 0LL;
result[22] = 0LL;
result[23] = 0LL;
return result;
}

original_code:
StructIndex_t *new_struct_index() {
 StructIndex_t *i = (StructIndex_t *) malloc(sizeof(StructIndex_t));
 ((i) ? (void) (0) : __assert_fail ("i", "util/index_struct_fields.c", 13, __extension__ __PRETTY_FUNCTION__));
 i->patch_object = ((void *)0);
 i->accumulate_patch_object = ((void *)0);
 i->patch_hourly_object = ((void *)0);
 i->patch_fire_water_object = ((void *)0);
 i->rooting_zone_object = ((void *)0);
 i->snowpack_object = ((void *)0);
 i->soil_c_object = ((void *)0);
 i->soil_n_object = ((void *)0);
 i->litter_object = ((void *)0);
 i->litter_c_object = ((void *)0);
 i->litter_n_object = ((void *)0);
 i->cdayflux_patch_struct = ((void *)0);
 i->ndayflux_patch_struct = ((void *)0);
 i->canopy_strata_object = ((void *)0);
 i->accumulate_strata_object = ((void *)0);
 i->cdayflux_struct = ((void *)0);
 i->cstate_struct = ((void *)0);
 i->target_object = ((void *)0);
 i->epvar_struct = ((void *)0);
 i->nstate_struct = ((void *)0);
 i->ndayflux_struct = ((void *)0);
 i->phenology_struct = ((void *)0);
 i->fire_effects_object = ((void *)0);
 i->mult_conduct_struct = ((void *)0);
 i->hillslope_object == ((void *)0);
 i->gw_object == ((void *)0);
 i->zone_object == ((void *)0);
 i->accumulate_zone_object == ((void *)0);
 i->metvar_struct == ((void *)0);
 return i;
}

canonical_original_code:
struct struct_index_s *new_struct_index() {
 struct struct_index_s *i = (StructIndex_t *) malloc(sizeof(StructIndex_t));
 ((i) ? (void) (0) : __assert_fail ("i", "util/index_struct_fields.c", 13, __extension__ __PRETTY_FUNCTION__));
 i->patch_object = ((void *)0);
 i->accumulate_patch_object = ((void *)0);
 i->patch_hourly_object = ((void *)0);
 i->patch_fire_water_object = ((void *)0);
 i->rooting_zone_object = ((void *)0);
 i->snowpack_object = ((void *)0);
 i->soil_c_object = ((void *)0);
 i->soil_n_object = ((void *)0);
 i->litter_object = ((void *)0);
 i->litter_c_object = ((void *)0);
 i->litter_n_object = ((void *)0);
 i->cdayflux_patch_struct = ((void *)0);
 i->ndayflux_patch_struct = ((void *)0);
 i->canopy_strata_object = ((void *)0);
 i->accumulate_strata_object = ((void *)0);
 i->cdayflux_struct = ((void *)0);
 i->cstate_struct = ((void *)0);
 i->target_object = ((void *)0);
 i->epvar_struct = ((void *)0);
 i->nstate_struct = ((void *)0);
 i->ndayflux_struct = ((void *)0);
 i->phenology_struct = ((void *)0);
 i->fire_effects_object = ((void *)0);
 i->mult_conduct_struct = ((void *)0);
 i->hillslope_object == ((void *)0);
 i->gw_object == ((void *)0);
 i->zone_object == ((void *)0);
 i->accumulate_zone_object == ((void *)0);
 i->metvar_struct == ((void *)0);
 return i;
}

variable_types: struct struct_index_s { 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; } *patch_object; struct dict_s *accumulate_patch_object; struct dict_s *patch_hourly_object; struct dict_s *patch_fire_water_object; struct dict_s *rooting_zone_object; struct dict_s *snowpack_object; struct dict_s *soil_c_object; struct dict_s *soil_n_object; struct dict_s *litter_object; struct dict_s *litter_c_object; struct dict_s *litter_n_object; struct dict_s *cdayflux_patch_struct; struct dict_s *ndayflux_patch_struct; struct dict_s *canopy_strata_object; struct dict_s *accumulate_strata_object; struct dict_s *cdayflux_struct; struct dict_s *cstate_struct; struct dict_s *target_object; struct dict_s *epvar_struct; struct dict_s *nstate_struct; struct dict_s *ndayflux_struct; struct dict_s *phenology_struct; struct dict_s *fire_effects_object; struct dict_s *mult_conduct_struct; struct dict_s *hillslope_object; struct dict_s *gw_object; struct dict_s *zone_object; struct dict_s *accumulate_zone_object; struct dict_s *metvar_struct; } *

user_defined_types: struct struct_index_s { struct dict_s *patch_object; struct dict_s *accumulate_patch_object; struct dict_s *patch_hourly_object; struct dict_s *patch_fire_water_object; struct dict_s *rooting_zone_object; struct dict_s *snowpack_object; struct dict_s *soil_c_object; struct dict_s *soil_n_object; struct dict_s *litter_object; struct dict_s *litter_c_object; struct dict_s *litter_n_object; struct dict_s *cdayflux_patch_struct; struct dict_s *ndayflux_patch_struct; struct dict_s *canopy_strata_object; struct dict_s *accumulate_strata_object; struct dict_s *cdayflux_struct; struct dict_s *cstate_struct; struct dict_s *target_object; struct dict_s *epvar_struct; struct dict_s *nstate_struct; struct dict_s *ndayflux_struct; struct dict_s *phenology_struct; struct dict_s *fire_effects_object; struct dict_s *mult_conduct_struct; struct dict_s *hillslope_object; struct dict_s *gw_object; struct dict_s *zone_object; struct dict_s *accumulate_zone_object; struct dict_s *metvar_struct; }

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


decompiled_code:
void __fastcall free_struct_index(void *ptr)
{
if ( ptr )
{
if ( *(_QWORD *)ptr )
freeDictionary();
if ( *((_QWORD *)ptr + 1) )
freeDictionary();
if ( *((_QWORD *)ptr + 2) )
freeDictionary();
if ( *((_QWORD *)ptr + 3) )
freeDictionary();
if ( *((_QWORD *)ptr + 4) )
freeDictionary();
if ( *((_QWORD *)ptr + 5) )
freeDictionary();
if ( *((_QWORD *)ptr + 6) )
freeDictionary();
if ( *((_QWORD *)ptr + 7) )
freeDictionary();
if ( *((_QWORD *)ptr + 8) )
freeDictionary();
if ( *((_QWORD *)ptr + 9) )
freeDictionary();
if ( *((_QWORD *)ptr + 10) )
freeDictionary();
if ( *((_QWORD *)ptr + 11) )
freeDictionary();
if ( *((_QWORD *)ptr + 12) )
freeDictionary();
if ( *((_QWORD *)ptr + 13) )
freeDictionary();
if ( *((_QWORD *)ptr + 14) )
freeDictionary();
if ( *((_QWORD *)ptr + 15) )
freeDictionary();
if ( *((_QWORD *)ptr + 16) )
freeDictionary();
if ( *((_QWORD *)ptr + 17) )
freeDictionary();
if ( *((_QWORD *)ptr + 18) )
freeDictionary();
if ( *((_QWORD *)ptr + 19) )
freeDictionary();
if ( *((_QWORD *)ptr + 20) )
freeDictionary();
if ( *((_QWORD *)ptr + 21) )
freeDictionary();
if ( *((_QWORD *)ptr + 22) )
freeDictionary();
if ( *((_QWORD *)ptr + 23) )
freeDictionary();
if ( *((_QWORD *)ptr + 24) )
freeDictionary();
if ( *((_QWORD *)ptr + 25) )
freeDictionary();
if ( *((_QWORD *)ptr + 26) )
freeDictionary();
if ( *((_QWORD *)ptr + 27) )
freeDictionary();
if ( *((_QWORD *)ptr + 28) )
freeDictionary();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
if ( *(_QWORD *)ptr )
freeDictionary();
if ( *((_QWORD *)ptr + 1) )
freeDictionary();
if ( *((_QWORD *)ptr + 2) )
freeDictionary();
if ( *((_QWORD *)ptr + 3) )
freeDictionary();
if ( *((_QWORD *)ptr + 4) )
freeDictionary();
if ( *((_QWORD *)ptr + 5) )
freeDictionary();
if ( *((_QWORD *)ptr + 6) )
freeDictionary();
if ( *((_QWORD *)ptr + 7) )
freeDictionary();
if ( *((_QWORD *)ptr + 8) )
freeDictionary();
if ( *((_QWORD *)ptr + 9) )
freeDictionary();
if ( *((_QWORD *)ptr + 10) )
freeDictionary();
if ( *((_QWORD *)ptr + 11) )
freeDictionary();
if ( *((_QWORD *)ptr + 12) )
freeDictionary();
if ( *((_QWORD *)ptr + 13) )
freeDictionary();
if ( *((_QWORD *)ptr + 14) )
freeDictionary();
if ( *((_QWORD *)ptr + 15) )
freeDictionary();
if ( *((_QWORD *)ptr + 16) )
freeDictionary();
if ( *((_QWORD *)ptr + 17) )
freeDictionary();
if ( *((_QWORD *)ptr + 18) )
freeDictionary();
if ( *((_QWORD *)ptr + 19) )
freeDictionary();
if ( *((_QWORD *)ptr + 20) )
freeDictionary();
if ( *((_QWORD *)ptr + 21) )
freeDictionary();
if ( *((_QWORD *)ptr + 22) )
freeDictionary();
if ( *((_QWORD *)ptr + 23) )
freeDictionary();
if ( *((_QWORD *)ptr + 24) )
freeDictionary();
if ( *((_QWORD *)ptr + 25) )
freeDictionary();
if ( *((_QWORD *)ptr + 26) )
freeDictionary();
if ( *((_QWORD *)ptr + 27) )
freeDictionary();
if ( *((_QWORD *)ptr + 28) )
freeDictionary();
free(ptr);
}
}

original_code:
void free_struct_index(StructIndex_t *i) {
 if (i == ((void *)0)) return;
 if (i->patch_object) {
  freeDictionary(i->patch_object);
 }
 if (i->accumulate_patch_object) {
  freeDictionary(i->accumulate_patch_object);
 }
 if (i->patch_hourly_object) {
  freeDictionary(i->patch_hourly_object);
 }
 if (i->patch_fire_water_object) {
  freeDictionary(i->patch_fire_water_object);
 }
 if (i->rooting_zone_object) {
  freeDictionary(i->rooting_zone_object);
 }
 if (i->snowpack_object) {
  freeDictionary(i->snowpack_object);
 }
 if (i->soil_c_object) {
  freeDictionary(i->soil_c_object);
 }
 if (i->soil_n_object) {
  freeDictionary(i->soil_n_object);
 }
 if (i->litter_object) {
  freeDictionary(i->litter_object);
 }
 if (i->litter_c_object) {
  freeDictionary(i->litter_c_object);
 }
 if (i->litter_n_object) {
  freeDictionary(i->litter_n_object);
 }
 if (i->cdayflux_patch_struct) {
  freeDictionary(i->cdayflux_patch_struct);
 }
 if (i->ndayflux_patch_struct) {
  freeDictionary(i->ndayflux_patch_struct);
 }
 if (i->canopy_strata_object) {
  freeDictionary(i->canopy_strata_object);
 }
 if (i->accumulate_strata_object) {
  freeDictionary(i->accumulate_strata_object);
 }
 if (i->cdayflux_struct) {
  freeDictionary(i->cdayflux_struct);
 }
 if (i->cstate_struct) {
  freeDictionary(i->cstate_struct);
 }
 if (i->target_object) {
  freeDictionary(i->target_object);
 }
 if (i->epvar_struct) {
  freeDictionary(i->epvar_struct);
 }
 if (i->nstate_struct) {
  freeDictionary(i->nstate_struct);
 }
 if (i->ndayflux_struct) {
  freeDictionary(i->ndayflux_struct);
 }
 if (i->phenology_struct) {
  freeDictionary(i->phenology_struct);
 }
 if (i->fire_effects_object) {
  freeDictionary(i->fire_effects_object);
 }
 if (i->mult_conduct_struct) {
  freeDictionary(i->mult_conduct_struct);
 }
 if (i->hillslope_object) {
  freeDictionary(i->hillslope_object);
 }
 if (i->gw_object) {
  freeDictionary(i->gw_object);
 }
 if (i->zone_object) {
  freeDictionary(i->zone_object);
 }
 if (i->accumulate_zone_object) {
  freeDictionary(i->accumulate_zone_object);
 }
 if (i->metvar_struct) {
  freeDictionary(i->metvar_struct);
 }
 free(i);
}

canonical_original_code:
void free_struct_index(struct struct_index_s *i) {
 if (i == ((void *)0)) return;
 if (i->patch_object) {
  freeDictionary(i->patch_object);
 }
 if (i->accumulate_patch_object) {
  freeDictionary(i->accumulate_patch_object);
 }
 if (i->patch_hourly_object) {
  freeDictionary(i->patch_hourly_object);
 }
 if (i->patch_fire_water_object) {
  freeDictionary(i->patch_fire_water_object);
 }
 if (i->rooting_zone_object) {
  freeDictionary(i->rooting_zone_object);
 }
 if (i->snowpack_object) {
  freeDictionary(i->snowpack_object);
 }
 if (i->soil_c_object) {
  freeDictionary(i->soil_c_object);
 }
 if (i->soil_n_object) {
  freeDictionary(i->soil_n_object);
 }
 if (i->litter_object) {
  freeDictionary(i->litter_object);
 }
 if (i->litter_c_object) {
  freeDictionary(i->litter_c_object);
 }
 if (i->litter_n_object) {
  freeDictionary(i->litter_n_object);
 }
 if (i->cdayflux_patch_struct) {
  freeDictionary(i->cdayflux_patch_struct);
 }
 if (i->ndayflux_patch_struct) {
  freeDictionary(i->ndayflux_patch_struct);
 }
 if (i->canopy_strata_object) {
  freeDictionary(i->canopy_strata_object);
 }
 if (i->accumulate_strata_object) {
  freeDictionary(i->accumulate_strata_object);
 }
 if (i->cdayflux_struct) {
  freeDictionary(i->cdayflux_struct);
 }
 if (i->cstate_struct) {
  freeDictionary(i->cstate_struct);
 }
 if (i->target_object) {
  freeDictionary(i->target_object);
 }
 if (i->epvar_struct) {
  freeDictionary(i->epvar_struct);
 }
 if (i->nstate_struct) {
  freeDictionary(i->nstate_struct);
 }
 if (i->ndayflux_struct) {
  freeDictionary(i->ndayflux_struct);
 }
 if (i->phenology_struct) {
  freeDictionary(i->phenology_struct);
 }
 if (i->fire_effects_object) {
  freeDictionary(i->fire_effects_object);
 }
 if (i->mult_conduct_struct) {
  freeDictionary(i->mult_conduct_struct);
 }
 if (i->hillslope_object) {
  freeDictionary(i->hillslope_object);
 }
 if (i->gw_object) {
  freeDictionary(i->gw_object);
 }
 if (i->zone_object) {
  freeDictionary(i->zone_object);
 }
 if (i->accumulate_zone_object) {
  freeDictionary(i->accumulate_zone_object);
 }
 if (i->metvar_struct) {
  freeDictionary(i->metvar_struct);
 }
 free(i);
}

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:
double __fastcall leaf_conductance_tavg_curve(double a1, double a2, double a3, double a4)
{
double v4; // xmm4_8
double result; // xmm0_8
double v6; // r14
double v7; // xmm0_8
double v8; // rbx

v4 = a1;
result = 0.0;
if ( v4 < 0.0 )
return 0.0;
if ( v4 <= a3 )
{
v6 = (a3 - v4) / (a3 - a2);
pow(v6, (a3 - a2) / (a2 + 10.0));
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a2) & LC3) > 0.1 )
{
v7 = log(v6);
v8 = exp(v7 * (a3 - a2) * a4);
result = exp(a4 * (a1 - a2)) * v8;
}
else
{
result = *(double *)&LC0;
}
if ( a1 < 5.0 )
result = result * a1 / 5.0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3, double a4)
{
double v4; // xmm4_8
double result; // xmm0_8
double v6; // r14
double v7; // xmm0_8
double v8; // rbx

v4 = a1;
result = 0.0;
if ( v4 < 0.0 )
return 0.0;
if ( v4 <= a3 )
{
v6 = (a3 - v4) / (a3 - a2);
pow(v6, (a3 - a2) / (a2 + 10.0));
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a2) & LC3) > 0.1 )
{
v7 = log(v6);
v8 = exp(v7 * (a3 - a2) * a4);
result = exp(a4 * (a1 - a2)) * v8;
}
else
{
result = *(double *)&LC0;
}
if ( a1 < 5.0 )
result = result * a1 / 5.0;
}
return result;
}

original_code:
double leaf_conductance_tavg_curve( double Tair_mean_day,
         double topt,
         double tmax,
         double tcoef)
{
 double dt;
 double m_tavg;
 double temp;
 double pp;
 if ( Tair_mean_day < 0.0 || Tair_mean_day > tmax ){
  m_tavg = 0.0;
 }
 else{
  pp = pow(((tmax-Tair_mean_day)/(tmax - topt)),((tmax - topt)/(topt +10)));
  m_tavg = (Tair_mean_day +10 ) / (topt + 10 ) * pp;
  dt = tmax - topt;
  if (fabs(Tair_mean_day-topt) > 0.1) {
  temp = exp(log((tmax-Tair_mean_day)/dt) * dt * tcoef);
  m_tavg = temp * exp(tcoef * (Tair_mean_day - topt));
  }
  else
  { m_tavg = 1.0; }
  if ( Tair_mean_day < 5.0 ){
   m_tavg = m_tavg * Tair_mean_day / 5.0;
  }
 }
 return(m_tavg);
}

canonical_original_code:
double leaf_conductance_tavg_curve(double Tair_mean_day, double topt, double tmax, double tcoef)
{
 double dt;
 double m_tavg;
 double temp;
 double pp;
 if ( Tair_mean_day < 0.0 || Tair_mean_day > tmax ){
  m_tavg = 0.0;
 }
 else{
  pp = pow(((tmax-Tair_mean_day)/(tmax - topt)),((tmax - topt)/(topt +10)));
  m_tavg = (Tair_mean_day +10 ) / (topt + 10 ) * pp;
  dt = tmax - topt;
  if (fabs(Tair_mean_day-topt) > 0.1) {
  temp = exp(log((tmax-Tair_mean_day)/dt) * dt * tcoef);
  m_tavg = temp * exp(tcoef * (Tair_mean_day - topt));
  }
  else
  { m_tavg = 1.0; }
  if ( Tair_mean_day < 5.0 ){
   m_tavg = m_tavg * Tair_mean_day / 5.0;
  }
 }
 return(m_tavg);
}

variable_types: topt double

variable_types: tmax double

variable_types: tcoef double

variable_types: dt double

variable_types: temp double

variable_types: pp double


decompiled_code:
double __fastcall compute_return_flow(double a1, double a2, __int64 a3, __int64 a4)
{
double v4; // xmm0_8
double v5; // xmm2_8
double v6; // xmm1_8

v4 = COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC1) - a1;
if ( v4 < 0.0 )
v4 = 0.0;
v5 = *(double *)(a4 + 24);
v6 = *(double *)(a4 + 56) - v5;
if ( v6 <= 0.0 )
v6 = 0.0;
*(double *)(a4 + 24) = v5 + v6;
return v4 - v6;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, __int64 a3, __int64 a4)
{
double v4; // xmm0_8
double v5; // xmm2_8
double v6; // xmm1_8

v4 = COERCE_DOUBLE(*(_QWORD *)&a2 ^ LC1) - a1;
if ( v4 < 0.0 )
v4 = 0.0;
v5 = *(double *)(a4 + 24);
v6 = *(double *)(a4 + 56) - v5;
if ( v6 <= 0.0 )
v6 = 0.0;
*(double *)(a4 + 24) = v5 + v6;
return v4 - v6;
}

original_code:
double compute_return_flow(
       int verbose_flag,
       double detention_store_size,
       double sat_deficit,
       struct litter_object *litter )
{
 double return_flow;
 double excess, add_to_litter;
 excess = ((0) > (-1 * sat_deficit - detention_store_size) ? (0) : (-1 * sat_deficit - detention_store_size));
 return_flow = ((0) > (excess) ? (0) : (excess));
 add_to_litter = (((litter[0].rain_capacity - litter[0].rain_stored)) > (0.0) ? ((litter[0].rain_capacity - litter[0].rain_stored)) : (0.0));
 return_flow -= add_to_litter;
 litter[0].rain_stored += add_to_litter;
 return(return_flow);
}

canonical_original_code:
double compute_return_flow(int verbose_flag, double detention_store_size, double sat_deficit, struct litter_object *litter)
{
 double return_flow;
 double excess; double add_to_litter;
 excess = ((0) > (-1 * sat_deficit - detention_store_size) ? (0) : (-1 * sat_deficit - detention_store_size));
 return_flow = ((0) > (excess) ? (0) : (excess));
 add_to_litter = (((litter[0].rain_capacity - litter[0].rain_stored)) > (0.0) ? ((litter[0].rain_capacity - litter[0].rain_stored)) : (0.0));
 return_flow -= add_to_litter;
 litter[0].rain_stored += add_to_litter;
 return(return_flow);
}

variable_types: struct litter_object { double cover_fraction; double depth; double density; double rain_stored; double NO3_stored; double gsurf; double proj_pai; double rain_capacity; double gl_c; double gsurf_slope; double gsurf_intercept; double moist_coef; double T; } *

variable_types: excess double


decompiled_code:
__int64 __fastcall create_flow_adjacency(__int64 a1, int a2, float **a3, double a4)
{
__int64 result; // rax
float *v6; // rax
float *v7; // rbx
float v8; // xmm0_4

if ( a1 )
{
if ( a3 )
{
if ( a2 < 0 )
{
fwrite("ERROR: Flow table index less than zero.\n", 1uLL, 0x28uLL, stderr);
result = 0LL;
}
else if ( a4 >= 0.0 && a4 <= 1.0 )
{
v6 = (float *)calloc(1uLL, 0x38uLL);
if ( v6 )
{
v7 = (float *)(160LL * a2 + a1);
*v6 = *v7;
v6[1] = v7[1];
v6[2] = v7[2];
v6[4] = v7[5];
v6[5] = v7[6];
v6[8] = v7[17];
v6[10] = v7[9];
*((_DWORD *)v6 + 3) = a2;
v8 = a4;
v6[9] = v8;
*((_QWORD *)v6 + 6) = 0LL;
*((_QWORD *)v6 + 3) = 0LL;
*a3 = v6;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate flow table adjacency struct.\n", 1uLL, 0x37uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Proportion is out of bounds.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return adjacency pointer is NULL.\n", 1uLL, 0x29uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, float **a3, double a4)
{
__int64 result; // rax
float *v6; // rax
float *v7; // rbx
float v8; // xmm0_4

if ( a1 )
{
if ( a3 )
{
if ( a2 < 0 )
{
fwrite("ERROR: Flow table index less than zero.\n", 1uLL, 0x28uLL, stderr);
result = 0LL;
}
else if ( a4 >= 0.0 && a4 <= 1.0 )
{
v6 = (float *)calloc(1uLL, 0x38uLL);
if ( v6 )
{
v7 = (float *)(160LL * a2 + a1);
*v6 = *v7;
v6[1] = v7[1];
v6[2] = v7[2];
v6[4] = v7[5];
v6[5] = v7[6];
v6[8] = v7[17];
v6[10] = v7[9];
*((_DWORD *)v6 + 3) = a2;
v8 = a4;
v6[9] = v8;
*((_QWORD *)v6 + 6) = 0LL;
*((_QWORD *)v6 + 3) = 0LL;
*a3 = v6;
result = 1LL;
}
else
{
fwrite("ERROR: Failed to allocate flow table adjacency struct.\n", 1uLL, 0x37uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Proportion is out of bounds.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Return adjacency pointer is NULL.\n", 1uLL, 0x29uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool create_flow_adjacency(
    struct flow_struct* _flow_table,
    int _index,
    double _proportion,
    struct adj_struct** _rtn_adjacency)
{
    bool result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_rtn_adjacency == 0) {
        fprintf(stderr, "ERROR: Return adjacency pointer is NULL.\n");
        result = false;
    } else if(_index < 0) {
        fprintf(stderr, "ERROR: Flow table index less than zero.\n");
        result = false;
    } else if(_proportion < 0 || _proportion > 1) {
        fprintf(stderr, "ERROR: Proportion is out of bounds.\n");
        result = false;
    } else {
        struct adj_struct* adjacency = (struct adj_struct*)calloc(1, sizeof(struct adj_struct));
        if(adjacency == 0) {
            fprintf(stderr, "ERROR: Failed to allocate flow table adjacency struct.\n");
            result = false;
        } else {
            adjacency->patchID = _flow_table[_index].patchID;
            adjacency->hillID = _flow_table[_index].hillID;
            adjacency->zoneID = _flow_table[_index].zoneID;
            adjacency->landtype = _flow_table[_index].land;
            adjacency->sewertype = _flow_table[_index].sewer;
            adjacency->slope = _flow_table[_index].slope;
            adjacency->z = _flow_table[_index].z;
            adjacency->inx = _index;
            adjacency->gamma = (float)_proportion;
            adjacency->next = 0;
            adjacency->perimeter = 0;
            *_rtn_adjacency = adjacency;
        }
    }
    return result;
}

canonical_original_code:
short create_flow_adjacency(struct flow_struct *_flow_table, int _index, double _proportion, struct adj_struct **_rtn_adjacency)
{
    short result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_rtn_adjacency == 0) {
        fprintf(stderr, "ERROR: Return adjacency pointer is NULL.\n");
        result = false;
    } else if(_index < 0) {
        fprintf(stderr, "ERROR: Flow table index less than zero.\n");
        result = false;
    } else if(_proportion < 0 || _proportion > 1) {
        fprintf(stderr, "ERROR: Proportion is out of bounds.\n");
        result = false;
    } else {
        struct adj_struct *adjacency = (struct adj_struct*)calloc(1, sizeof(struct adj_struct));
        if(adjacency == 0) {
            fprintf(stderr, "ERROR: Failed to allocate flow table adjacency struct.\n");
            result = false;
        } else {
            adjacency->patchID = _flow_table[_index].patchID;
            adjacency->hillID = _flow_table[_index].hillID;
            adjacency->zoneID = _flow_table[_index].zoneID;
            adjacency->landtype = _flow_table[_index].land;
            adjacency->sewertype = _flow_table[_index].sewer;
            adjacency->slope = _flow_table[_index].slope;
            adjacency->z = _flow_table[_index].z;
            adjacency->inx = _index;
            adjacency->gamma = (float)_proportion;
            adjacency->next = 0;
            adjacency->perimeter = 0;
            *_rtn_adjacency = adjacency;
        }
    }
    return result;
}

variable_types: result short

variable_types: struct adj_struct { int patchID; int hillID; int zoneID; int inx; int landtype; int sewertype; double perimeter; float slope; float gamma; float z; struct adj_struct *next; } *

return_type: short

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


decompiled_code:
__int64 __fastcall add_adjacency_to_contributor(__int64 a1, int a2, __int64 a3)
{
__int64 v3; // rdi
__int64 v4; // rax
__int64 result; // rax

if ( a1 )
{
if ( a3 )
{
if ( a2 < 0 )
{
fwrite("ERROR: Contributor index is less than 0.\n", 1uLL, 0x29uLL, stderr);
result = 0LL;
}
else
{
v3 = 160LL * a2 + a1;
v4 = *(_QWORD *)(v3 + 128);
*(_QWORD *)(v3 + 128) = a3;
*(_QWORD *)(a3 + 48) = v4;
*(_QWORD *)(v3 + 136) = *(_QWORD *)(v3 + 128);
++*(_DWORD *)(v3 + 96);
result = 1LL;
}
}
else
{
fwrite("ERROR: Adjacency pointer is NULL.\n", 1uLL, 0x22uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3)
{
__int64 v3; // rdi
__int64 v4; // rax
__int64 result; // rax

if ( a1 )
{
if ( a3 )
{
if ( a2 < 0 )
{
fwrite("ERROR: Contributor index is less than 0.\n", 1uLL, 0x29uLL, stderr);
result = 0LL;
}
else
{
v3 = 160LL * a2 + a1;
v4 = *(_QWORD *)(v3 + 128);
*(_QWORD *)(v3 + 128) = a3;
*(_QWORD *)(a3 + 48) = v4;
*(_QWORD *)(v3 + 136) = *(_QWORD *)(v3 + 128);
++*(_DWORD *)(v3 + 96);
result = 1LL;
}
}
else
{
fwrite("ERROR: Adjacency pointer is NULL.\n", 1uLL, 0x22uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR: Flow table pointer is NULL.\n", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bool add_adjacency_to_contributor(
    struct flow_struct* _flow_table,
    int _index,
    struct adj_struct* _adjacency)
{
    bool result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_adjacency == 0) {
        fprintf(stderr, "ERROR: Adjacency pointer is NULL.\n");
        result = false;
    } else if(_index < 0) {
        fprintf(stderr, "ERROR: Contributor index is less than 0.\n");
        result = false;
    } else {
        struct adj_struct* adjacency_list = _flow_table[_index].adj_list;
        _flow_table[_index].adj_list = _adjacency;
        _adjacency->next = adjacency_list;
        _flow_table[_index].adj_ptr = _flow_table[_index].adj_list;
        ++_flow_table[_index].num_adjacent;
    }
    return result;
}

canonical_original_code:
short add_adjacency_to_contributor(struct flow_struct *_flow_table, int _index, struct adj_struct *_adjacency)
{
    short result = true;
    if(_flow_table == 0) {
        fprintf(stderr, "ERROR: Flow table pointer is NULL.\n");
        result = false;
    } else if(_adjacency == 0) {
        fprintf(stderr, "ERROR: Adjacency pointer is NULL.\n");
        result = false;
    } else if(_index < 0) {
        fprintf(stderr, "ERROR: Contributor index is less than 0.\n");
        result = false;
    } else {
        struct adj_struct *adjacency_list = _flow_table[_index].adj_list;
        _flow_table[_index].adj_list = _adjacency;
        _adjacency->next = adjacency_list;
        _flow_table[_index].adj_ptr = _flow_table[_index].adj_list;
        ++_flow_table[_index].num_adjacent;
    }
    return result;
}

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