repo: bambreeze/sandbox

decompiled_code:
void __fastcall __noreturn workerer_thread(void *a1)
{
pthread_mutex_t *v1; // r12
int i; // eax
__int64 v3; // rcx
unsigned int *v4; // rbp
int v5; // eax
char *v6; // rax
char *v7; // rax
__int64 v8; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 200);
time(&timer);
while ( 1 )
{
pthread_mutex_lock(v1);
for ( i = *((_DWORD *)a1 + 2); i; i = *((_DWORD *)a1 + 2) )
{
v3 = *((int *)a1 + 1);
v4 = (unsigned int *)*((_QWORD *)a1 + v3 + 2);
*((_DWORD *)a1 + 2) = i - 1;
v5 = v3 + 1;
if ( (_DWORD)v3 == 15 )
v5 = 0;
*((_QWORD *)a1 + v3 + 2) = 0LL;
*((_DWORD *)a1 + 1) = v5;
puts("\nprocessing...");
printf(" req->is_v4: %d\n", *v4);
printf(" req->is_add: %d\n", v4[1]);
printf(" req->interface: 0x%08x\n", v4[2]);
puts("processing done\n");
time(&timer);
v6 = ctime(&timer);
printf("before cond wait - %s", v6);
*((_DWORD *)a1 + 36) = 1;
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 152), v1);
*((_DWORD *)a1 + 36) = 0;
time(&timer);
v7 = ctime(&timer);
printf("after cond wait - %s", v7);
printf("\n <== free req ... interface: 0x%08x\n\n", v4[2]);
free(v4);
pthread_mutex_unlock(v1);
pthread_mutex_lock(v1);
}
pthread_mutex_unlock(v1);
v8 = syscall(186LL);
printf("[pid %d] no req...\n", v8);
sleep(1u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
pthread_mutex_t *v1; // r12
int i; // eax
__int64 v3; // rcx
unsigned int *v4; // rbp
int v5; // eax
char *v6; // rax
char *v7; // rax
__int64 v8; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 200);
time(&timer);
while ( 1 )
{
pthread_mutex_lock(v1);
for ( i = *((_DWORD *)a1 + 2); i; i = *((_DWORD *)a1 + 2) )
{
v3 = *((int *)a1 + 1);
v4 = (unsigned int *)*((_QWORD *)a1 + v3 + 2);
*((_DWORD *)a1 + 2) = i - 1;
v5 = v3 + 1;
if ( (_DWORD)v3 == 15 )
v5 = 0;
*((_QWORD *)a1 + v3 + 2) = 0LL;
*((_DWORD *)a1 + 1) = v5;
puts("\nprocessing...");
printf(" req->is_v4: %d\n", *v4);
printf(" req->is_add: %d\n", v4[1]);
printf(" req->interface: 0x%08x\n", v4[2]);
puts("processing done\n");
time(&timer);
v6 = ctime(&timer);
printf("before cond wait - %s", v6);
*((_DWORD *)a1 + 36) = 1;
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 152), v1);
*((_DWORD *)a1 + 36) = 0;
time(&timer);
v7 = ctime(&timer);
printf("after cond wait - %s", v7);
printf("\n <== free req ... interface: 0x%08x\n\n", v4[2]);
free(v4);
pthread_mutex_unlock(v1);
pthread_mutex_lock(v1);
}
pthread_mutex_unlock(v1);
v8 = syscall(186LL);
printf("[pid %d] no req...\n", v8);
sleep(1u);
}
}

original_code:
void *workerer_thread(void *arg)
{
    req_queue *queue = ((void *)0);
    req_entry *req = ((void *)0);
    time_t t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        if (queue->counter) {
            req = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 16) {
                queue->out = 0;
            }
            printf("\nprocessing...\n");
            printf("  req->is_v4: %d\n", req->is_v4);
            printf("  req->is_add: %d\n", req->is_add);
            printf("  req->interface: 0x%08x\n", req->interface);
            printf("processing done\n\n");
            time(&t);
            printf("before cond wait - %s", ctime(&t));
            queue->waiting = 1;
            pthread_cond_wait(&queue->cond, &queue->mutex);
            queue->waiting = 0;
            time(&t);
            printf("after cond wait - %s", ctime(&t));
            printf("\n  <== free req ... interface: 0x%08x\n\n", req->interface);
            free(req);
            req = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no req...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

canonical_original_code:
void *workerer_thread(void *arg)
{
    struct _req_queue *queue = ((void *)0);
    struct _req_entry *req = ((void *)0);
    long t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        if (queue->counter) {
            req = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 16) {
                queue->out = 0;
            }
            printf("\nprocessing...\n");
            printf("  req->is_v4: %d\n", req->is_v4);
            printf("  req->is_add: %d\n", req->is_add);
            printf("  req->interface: 0x%08x\n", req->interface);
            printf("processing done\n\n");
            time(&t);
            printf("before cond wait - %s", ctime(&t));
            queue->waiting = 1;
            pthread_cond_wait(&queue->cond, &queue->mutex);
            queue->waiting = 0;
            time(&t);
            printf("after cond wait - %s", ctime(&t));
            printf("\n  <== free req ... interface: 0x%08x\n\n", req->interface);
            free(req);
            req = ((void *)0);
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no req...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

variable_types:
arg
void *

variable_types: struct _req_queue { int in; int out; int counter; struct _req_entry { int is_v4; int is_add; int interface; } *entry[16]; int waiting; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; 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; } *

variable_types: t long

return_type: void *

user_defined_types: struct _req_queue { int in; int out; int counter; struct _req_entry *entry[16]; int waiting; union pthread_cond_t cond; union pthread_mutex_t mutex; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

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:
void __fastcall __noreturn notifier_thread(void *a1)
{
pthread_mutex_t *v1; // rbx
unsigned int v2; // eax
int v3; // eax
char *v4; // rax
char *v5; // rax
__int64 v6; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 200);
v2 = time(&timer);
srand(v2);
while ( 1 )
{
v3 = rand();
sleep(v3 % 2);
pthread_mutex_lock(v1);
if ( *((_DWORD *)a1 + 36) )
{
time(&timer);
v4 = ctime(&timer);
printf("before cond signal - %s", v4);
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 152));
time(&timer);
v5 = ctime(&timer);
printf("after cond signal - %s", v5);
pthread_mutex_unlock(v1);
}
else
{
pthread_mutex_unlock(v1);
v6 = syscall(186LL);
printf("[pid %d] no pending...\n", v6);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
pthread_mutex_t *v1; // rbx
unsigned int v2; // eax
int v3; // eax
char *v4; // rax
char *v5; // rax
__int64 v6; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 200);
v2 = time(&timer);
srand(v2);
while ( 1 )
{
v3 = rand();
sleep(v3 % 2);
pthread_mutex_lock(v1);
if ( *((_DWORD *)a1 + 36) )
{
time(&timer);
v4 = ctime(&timer);
printf("before cond signal - %s", v4);
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 152));
time(&timer);
v5 = ctime(&timer);
printf("after cond signal - %s", v5);
pthread_mutex_unlock(v1);
}
else
{
pthread_mutex_unlock(v1);
v6 = syscall(186LL);
printf("[pid %d] no pending...\n", v6);
}
}
}

original_code:
void *notifier_thread(void * arg)
{
    req_queue *queue = ((void *)0);
    time_t t;
    srand((unsigned) time(&t));
    queue = arg;
    while (1) {
        sleep((rand() % 2));
        pthread_mutex_lock(&queue->mutex);
        if (queue->waiting) {
            time(&t);
            printf("before cond signal - %s", ctime(&t));
            pthread_cond_signal(&queue->cond);
            time(&t);
            printf("after cond signal - %s", ctime(&t));
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no pending...\n", (int) syscall(186));
        }
    }
}

canonical_original_code:
void *notifier_thread(void *arg)
{
    struct _req_queue *queue = ((void *)0);
    long t;
    srand((unsigned int) time(&t));
    queue = arg;
    while (1) {
        sleep((rand() % 2));
        pthread_mutex_lock(&queue->mutex);
        if (queue->waiting) {
            time(&t);
            printf("before cond signal - %s", ctime(&t));
            pthread_cond_signal(&queue->cond);
            time(&t);
            printf("after cond signal - %s", ctime(&t));
            pthread_mutex_unlock(&queue->mutex);
        } else {
            pthread_mutex_unlock(&queue->mutex);
            printf("[pid %d] no pending...\n", (int) syscall(186));
        }
    }
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct _req_entry { int is_v4; int is_add; int interface; }

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


decompiled_code:
__int64 __fastcall add_req(pthread_mutex_t *a1, int a2, int a3, int a4)
{
_DWORD *v7; // rax
_DWORD *v8; // rbp
__int64 v9; // rax
pthread_mutex_t *v10; // rdi
int v11; // edx
int v12; // eax
__int64 result; // rax

if ( a1->__owner == 16 )
{
puts("\n!!! req-queue is full, will discard req !!!");
result = 1LL;
}
else
{
v7 = malloc(0xCuLL);
v8 = v7;
if ( !v7 )
{
puts("malloc req failed");
exit(1);
}
*v7 = a2;
v7[1] = a3;
v7[2] = a4;
pthread_mutex_lock(a1 + 5);
v9 = a1->__lock;
v10 = a1 + 5;
v11 = a1->__lock;
*(_QWORD *)&a1->__size[8 * v9 + 16] = v8;
v12 = v9 + 1;
++a1->__owner;
if ( v11 == 15 )
v12 = 0;
a1->__lock = v12;
pthread_mutex_unlock(v10);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_mutex_t *a1, int a2, int a3, int a4)
{
_DWORD *v7; // rax
_DWORD *v8; // rbp
__int64 v9; // rax
pthread_mutex_t *v10; // rdi
int v11; // edx
int v12; // eax
__int64 result; // rax

if ( a1->__owner == 16 )
{
puts("\n!!! req-queue is full, will discard req !!!");
result = 1LL;
}
else
{
v7 = malloc(0xCuLL);
v8 = v7;
if ( !v7 )
{
puts("malloc req failed");
exit(1);
}
*v7 = a2;
v7[1] = a3;
v7[2] = a4;
pthread_mutex_lock(a1 + 5);
v9 = a1->__lock;
v10 = a1 + 5;
v11 = a1->__lock;
*(_QWORD *)&a1->__size[8 * v9 + 16] = v8;
v12 = v9 + 1;
++a1->__owner;
if ( v11 == 15 )
v12 = 0;
a1->__lock = v12;
pthread_mutex_unlock(v10);
result = 0LL;
}
return result;
}

original_code:
int add_req(req_queue *queue, int is_v4, int is_add, int interface)
{
    req_entry *req = ((void *)0);
    if (queue->counter == 16) {
        printf("\n!!! req-queue is full, will discard req !!!\n");
        return 1;
    }
    req = malloc(sizeof(req_entry));
    if (!req) {
        printf("malloc req failed\n");
        exit(1);
    }
    req->is_v4 = is_v4;
    req->is_add = is_add;
    req->interface = interface;
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = req;
    queue->counter++;
    queue->in++;
    if (queue->in == 16) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

canonical_original_code:
int add_req(struct _req_queue *queue, int is_v4, int is_add, int interface)
{
    struct _req_entry *req = ((void *)0);
    if (queue->counter == 16) {
        printf("\n!!! req-queue is full, will discard req !!!\n");
        return 1;
    }
    req = malloc(sizeof(req_entry));
    if (!req) {
        printf("malloc req failed\n");
        exit(1);
    }
    req->is_v4 = is_v4;
    req->is_add = is_add;
    req->interface = interface;
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = req;
    queue->counter++;
    queue->in++;
    if (queue->in == 16) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

variable_types: interface int

variable_types: struct _req_entry { int is_v4; int is_add; int interface; } *

return_type: int


decompiled_code:
void handler2()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv4, del, interface: 0x%08x\n", v1);
add_req((pthread_mutex_t *)global_req_queue, 1, 0, v0);
}

canonical_decompiled_code:
void func11()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv4, del, interface: 0x%08x\n", v1);
func9((pthread_mutex_t *)global_req_queue, 1, 0, v0);
}

original_code:
void handler2(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv4, del, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 1, 0, interface);
}

variable_types: signo int

return_type: void


decompiled_code:
void handler3()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv6, add, interface: 0x%08x\n", v1);
add_req((pthread_mutex_t *)global_req_queue, 0, 1, v0);
}

canonical_decompiled_code:
void func12()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv6, add, interface: 0x%08x\n", v1);
func9((pthread_mutex_t *)global_req_queue, 0, 1, v0);
}

original_code:
void handler3(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv6, add, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 0, 1, interface);
}


decompiled_code:
void handler4()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv6, del, interface: 0x%08x\n", v1);
add_req((pthread_mutex_t *)global_req_queue, 0, 0, v0);
}

canonical_decompiled_code:
void func13()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv6, del, interface: 0x%08x\n", v1);
func9((pthread_mutex_t *)global_req_queue, 0, 0, v0);
}

original_code:
void handler4(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv6, del, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 0, 0, interface);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(3, handler1) == (__sighandler_t)-1LL
|| signal(4, handler2) == (__sighandler_t)-1LL
|| signal(5, handler3) == (__sighandler_t)-1LL
|| signal(6, handler4) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
global_req_queue = malloc(0xF0uLL);
if ( !global_req_queue )
{
puts("malloc queue failed");
exit(1);
}
init_queue(global_req_queue);
if ( pthread_create(&th, 0LL, workerer_thread, global_req_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
if ( pthread_create(newthread, 0LL, notifier_thread, global_req_queue) )
{
puts("Creating notifier thread failed.");
exit(1);
}
v3 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v3);
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
v4 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(3, handler1) == (__sighandler_t)-1LL
|| signal(4, handler2) == (__sighandler_t)-1LL
|| signal(5, handler3) == (__sighandler_t)-1LL
|| signal(6, handler4) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
global_req_queue = malloc(0xF0uLL);
if ( !global_req_queue )
{
puts("malloc queue failed");
exit(1);
}
func14(global_req_queue);
if ( pthread_create(&th, 0LL, workerer_thread, global_req_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
if ( pthread_create(newthread, 0LL, notifier_thread, global_req_queue) )
{
puts("Creating notifier thread failed.");
exit(1);
}
v3 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v3);
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
v4 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v4);
return 0;
}

original_code:
int main()
{
    int rc = 0;
    if (signal(3, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(4, handler2) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(5, handler3) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(6, handler4) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_req_queue = malloc(sizeof(req_queue));
    if (!global_req_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_req_queue);
    pthread_t worker;
    if (pthread_create(&worker, ((void *)0), workerer_thread, global_req_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    pthread_t notifier;
    if (pthread_create(&notifier, ((void *)0), notifier_thread, global_req_queue) != 0) {
        printf("Creating notifier thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    pthread_join(notifier, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}

canonical_original_code:
int main()
{
    int rc = 0;
    if (signal(3, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(4, handler2) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(5, handler3) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    if (signal(6, handler4) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_req_queue = malloc(sizeof(req_queue));
    if (!global_req_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_req_queue);
    unsigned long worker;
    if (pthread_create(&worker, ((void *)0), workerer_thread, global_req_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    unsigned long notifier;
    if (pthread_create(&notifier, ((void *)0), notifier_thread, global_req_queue) != 0) {
        printf("Creating notifier thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    pthread_join(notifier, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}

variable_types: rc int

variable_types:
worker
unsigned long

variable_types:
notifier
unsigned long


decompiled_code:
void handler1()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv4, add, interface: 0x%08x\n", v1);
add_req((pthread_mutex_t *)global_req_queue, 1, 1, v0);
}

canonical_decompiled_code:
void func10()
{
int v0; // er12
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> ipv4, add, interface: 0x%08x\n", v1);
func9((pthread_mutex_t *)global_req_queue, 1, 1, v0);
}

original_code:
void handler1(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> ipv4, add, interface: 0x%08x\n", interface);
    add_req(global_req_queue, 1, 1, interface);
}


decompiled_code:
int __fastcall init_queue(__int64 a1)
{
pthread_cond_t *v2; // rbp
__int64 v3; // rdi

v2 = (pthread_cond_t *)(a1 + 152);
v3 = a1 + 24;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 112) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 144) >> 3));
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 144) = 0;
pthread_mutex_init((pthread_mutex_t *)(a1 + 200), 0LL);
return pthread_cond_init(v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
pthread_cond_t *v2; // rbp
__int64 v3; // rdi

v2 = (pthread_cond_t *)(a1 + 152);
v3 = a1 + 24;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 112) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 144) >> 3));
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 144) = 0;
pthread_mutex_init((pthread_mutex_t *)(a1 + 200), 0LL);
return pthread_cond_init(v2, 0LL);
}

original_code:
void init_queue(req_queue *queue)
{
    int i = 0;
    for (i = 0; i < 16; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    queue->waiting = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
    pthread_cond_init(&queue->cond, ((void *)0));
}

canonical_original_code:
void init_queue(struct _req_queue *queue)
{
    int i = 0;
    for (i = 0; i < 16; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    queue->waiting = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
    pthread_cond_init(&queue->cond, ((void *)0));
}

variable_types: i int


decompiled_code:
void __fastcall __noreturn worker_thread(void *a1)
{
pthread_mutex_t *v1; // r12
int v2; // ebp
__int64 v3; // rdx
unsigned int *v4; // rbp
int v5; // eax
unsigned int v6; // eax
__int64 v7; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 2064);
time(&timer);
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock(v1);
v2 = *((_DWORD *)a1 + 2);
pthread_mutex_unlock(v1);
if ( v2 )
break;
v7 = syscall(186LL);
printf("[pid %d] no pending command...\n", v7);
sleep(1u);
}
pthread_mutex_lock(v1);
v3 = *((int *)a1 + 1);
v4 = (unsigned int *)*((_QWORD *)a1 + v3 + 2);
--*((_DWORD *)a1 + 2);
*((_QWORD *)a1 + v3 + 2) = 0LL;
v5 = v3 + 1;
if ( (_DWORD)v3 == 255 )
v5 = 0;
*((_DWORD *)a1 + 1) = v5;
pthread_mutex_unlock(v1);
puts("\nexecute commands...");
printf(" cmd->interface: 0x%08x\n", *v4);
printf(" cmd->cmd: %s\n", (const char *)v4 + 4);
v6 = system((const char *)v4 + 4);
printf("done, return %d\n\n", v6);
printf("\n <== free cmd ... interface: 0x%08x\n\n", *v4);
free(v4);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
pthread_mutex_t *v1; // r12
int v2; // ebp
__int64 v3; // rdx
unsigned int *v4; // rbp
int v5; // eax
unsigned int v6; // eax
__int64 v7; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 2064);
time(&timer);
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock(v1);
v2 = *((_DWORD *)a1 + 2);
pthread_mutex_unlock(v1);
if ( v2 )
break;
v7 = syscall(186LL);
printf("[pid %d] no pending command...\n", v7);
sleep(1u);
}
pthread_mutex_lock(v1);
v3 = *((int *)a1 + 1);
v4 = (unsigned int *)*((_QWORD *)a1 + v3 + 2);
--*((_DWORD *)a1 + 2);
*((_QWORD *)a1 + v3 + 2) = 0LL;
v5 = v3 + 1;
if ( (_DWORD)v3 == 255 )
v5 = 0;
*((_DWORD *)a1 + 1) = v5;
pthread_mutex_unlock(v1);
puts("\nexecute commands...");
printf(" cmd->interface: 0x%08x\n", *v4);
printf(" cmd->cmd: %s\n", (const char *)v4 + 4);
v6 = system((const char *)v4 + 4);
printf("done, return %d\n\n", v6);
printf("\n <== free cmd ... interface: 0x%08x\n\n", *v4);
free(v4);
}
}

original_code:
void *worker_thread(void *arg)
{
    cmd_queue *queue = ((void *)0);
    cmd_entry *cmd = ((void *)0);
    int pending_cmd = 0;
    int status = 0;
    time_t t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        pending_cmd = queue->counter;
        pthread_mutex_unlock(&queue->mutex);
        if (pending_cmd) {
            pthread_mutex_lock(&queue->mutex);
            cmd = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 256) {
                queue->out = 0;
            }
            pthread_mutex_unlock(&queue->mutex);
            printf("\nexecute commands...\n");
            printf("  cmd->interface: 0x%08x\n", cmd->interface);
            printf("  cmd->cmd: %s\n", cmd->cmd);
            status = system(cmd->cmd);
            printf("done, return %d\n\n", status);
            printf("\n  <== free cmd ... interface: 0x%08x\n\n", cmd->interface);
            free(cmd);
            cmd = ((void *)0);
        } else {
            printf("[pid %d] no pending command...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

canonical_original_code:
void *worker_thread(void *arg)
{
    struct _cmd_queue *queue = ((void *)0);
    struct _cmd_entry *cmd = ((void *)0);
    int pending_cmd = 0;
    int status = 0;
    long t;
    time(&t);
    queue = arg;
    while (1) {
        pthread_mutex_lock(&queue->mutex);
        pending_cmd = queue->counter;
        pthread_mutex_unlock(&queue->mutex);
        if (pending_cmd) {
            pthread_mutex_lock(&queue->mutex);
            cmd = queue->entry[queue->out];
            queue->counter--;
            queue->entry[queue->out] = ((void *)0);
            queue->out++;
            if (queue->out == 256) {
                queue->out = 0;
            }
            pthread_mutex_unlock(&queue->mutex);
            printf("\nexecute commands...\n");
            printf("  cmd->interface: 0x%08x\n", cmd->interface);
            printf("  cmd->cmd: %s\n", cmd->cmd);
            status = system(cmd->cmd);
            printf("done, return %d\n\n", status);
            printf("\n  <== free cmd ... interface: 0x%08x\n\n", cmd->interface);
            free(cmd);
            cmd = ((void *)0);
        } else {
            printf("[pid %d] no pending command...\n", (int) syscall(186));
            sleep(1);
        }
    }
}

variable_types: struct _cmd_queue { int in; int out; unsigned int counter; struct _cmd_entry { int interface; char cmd[256]; char fname[256]; } *entry[256]; 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; } *

variable_types: status int

user_defined_types: struct _cmd_queue { int in; int out; unsigned int counter; struct _cmd_entry *entry[256]; union pthread_mutex_t mutex; }


decompiled_code:
__int64 __fastcall add_cmd(unsigned int *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // r12
const __m128i *v4; // rax
__m128i v5; // xmm0
__int32 v6; // ecx
__int8 v7; // al
__int64 v8; // rax
int v9; // edx
unsigned int v10; // eax
__int64 result; // rax
char v12[296]; // [rsp+0h] [rbp-128h] BYREF

if ( a1[2] == 256 )
{
puts("\n!!! cmd-queue is full, will discard cmd !!!");
result = 1LL;
}
else
{
v2 = malloc(0x204uLL);
v3 = v2;
if ( !v2 )
{
puts("malloc cmd failed");
exit(1);
}
*v2 = a2;
v4 = (const __m128i *)"../util/sleep2to5sr1";
if ( (unsigned int)(-858993459 * a2 + 429496729) >= 0x33333333 )
v4 = (const __m128i *)"../util/sleep2to5sr0";
v5 = _mm_loadu_si128(v4);
v6 = v4[1].m128i_i32[0];
v7 = v4[1].m128i_i8[4];
*(__m128i *)(v3 + 1) = v5;
v3[5] = v6;
*((_BYTE *)v3 + 24) = v7;
system("date > cmd_file");
snprintf((char *)v3 + 260, 0x100uLL, "cmd_file.%d", *a1);
snprintf(v12, 0x100uLL, "cp cmd_file %s", (const char *)v3 + 260);
system(v12);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 516));
v8 = (int)*a1;
v9 = *a1;
*(_QWORD *)&a1[2 * v8 + 4] = v3;
v10 = v8 + 1;
++a1[2];
if ( v9 == 255 )
v10 = 0;
*a1 = v10;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 516));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // r12
const __m128i *v4; // rax
__m128i v5; // xmm0
__int32 v6; // ecx
__int8 v7; // al
__int64 v8; // rax
int v9; // edx
unsigned int v10; // eax
__int64 result; // rax
char v12[296]; // [rsp+0h] [rbp-128h] BYREF

if ( a1[2] == 256 )
{
puts("\n!!! cmd-queue is full, will discard cmd !!!");
result = 1LL;
}
else
{
v2 = malloc(0x204uLL);
v3 = v2;
if ( !v2 )
{
puts("malloc cmd failed");
exit(1);
}
*v2 = a2;
v4 = (const __m128i *)"../util/sleep2to5sr1";
if ( (unsigned int)(-858993459 * a2 + 429496729) >= 0x33333333 )
v4 = (const __m128i *)"../util/sleep2to5sr0";
v5 = _mm_loadu_si128(v4);
v6 = v4[1].m128i_i32[0];
v7 = v4[1].m128i_i8[4];
*(__m128i *)(v3 + 1) = v5;
v3[5] = v6;
*((_BYTE *)v3 + 24) = v7;
system("date > cmd_file");
snprintf((char *)v3 + 260, 0x100uLL, "cmd_file.%d", *a1);
snprintf(v12, 0x100uLL, "cp cmd_file %s", (const char *)v3 + 260);
system(v12);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 516));
v8 = (int)*a1;
v9 = *a1;
*(_QWORD *)&a1[2 * v8 + 4] = v3;
v10 = v8 + 1;
++a1[2];
if ( v9 == 255 )
v10 = 0;
*a1 = v10;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 516));
result = 0LL;
}
return result;
}

original_code:
int add_cmd(cmd_queue *queue, int interface)
{
    cmd_entry *cmd = ((void *)0);
    char str[256];
    char *fbin = ((void *)0);
    char *fcfg = "cmd_file";
    if (queue->counter == 256) {
        printf("\n!!! cmd-queue is full, will discard cmd !!!\n");
        return 1;
    }
    cmd = malloc(sizeof(cmd_entry));
    if (!cmd) {
        printf("malloc cmd failed\n");
        exit(1);
    }
    cmd->interface = interface;
    if (interface % 5 == 0) {
        fbin = "../util/sleep2to5sr1";
    } else {
        fbin = "../util/sleep2to5sr0";
    }
    memcpy(cmd->cmd, fbin, strlen(fbin) + 1);
    system("date > cmd_file");
    snprintf(cmd->fname, sizeof(cmd->fname), "cmd_file.%d", queue->in);
    snprintf(str, sizeof(str), "cp cmd_file %s", cmd->fname);
    system(str);
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = cmd;
    queue->counter++;
    queue->in++;
    if (queue->in == 256) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

canonical_original_code:
int add_cmd(struct _cmd_queue *queue, int interface)
{
    struct _cmd_entry *cmd = ((void *)0);
    char str[256];
    char *fbin = ((void *)0);
    char *fcfg = "cmd_file";
    if (queue->counter == 256) {
        printf("\n!!! cmd-queue is full, will discard cmd !!!\n");
        return 1;
    }
    cmd = malloc(sizeof(cmd_entry));
    if (!cmd) {
        printf("malloc cmd failed\n");
        exit(1);
    }
    cmd->interface = interface;
    if (interface % 5 == 0) {
        fbin = "../util/sleep2to5sr1";
    } else {
        fbin = "../util/sleep2to5sr0";
    }
    memcpy(cmd->cmd, fbin, strlen(fbin) + 1);
    system("date > cmd_file");
    snprintf(cmd->fname, sizeof(cmd->fname), "cmd_file.%d", queue->in);
    snprintf(str, sizeof(str), "cp cmd_file %s", cmd->fname);
    system(str);
    pthread_mutex_lock(&queue->mutex);
    queue->entry[queue->in] = cmd;
    queue->counter++;
    queue->in++;
    if (queue->in == 256) {
        queue->in = 0;
    }
    pthread_mutex_unlock(&queue->mutex);
    return 0;
}

variable_types: struct _cmd_entry { int interface; char cmd[256]; char fname[256]; } *

variable_types:
str
char [256]

variable_types:
fbin
char *

variable_types:
fcfg
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(1, handler1) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
global_cmd_queue = malloc(0x838uLL);
if ( !global_cmd_queue )
{
puts("malloc queue failed");
exit(1);
}
init_queue(global_cmd_queue);
if ( pthread_create(newthread, 0LL, worker_thread, global_cmd_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
v3 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v3);
pthread_join(newthread[0], 0LL);
v4 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( signal(1, handler1) == (__sighandler_t)-1LL )
{
puts("Signal error.");
exit(1);
}
global_cmd_queue = malloc(0x838uLL);
if ( !global_cmd_queue )
{
puts("malloc queue failed");
exit(1);
}
func10(global_cmd_queue);
if ( pthread_create(newthread, 0LL, worker_thread, global_cmd_queue) )
{
puts("Creating worker thread failed.");
exit(1);
}
v3 = syscall(186LL);
printf("[pid %d] main(), waiting for thread join...\n", v3);
pthread_join(newthread[0], 0LL);
v4 = syscall(186LL);
printf("[pid %d] main(), thread join done\n", v4);
return 0;
}

original_code:
int main()
{
    int rc = 0;
    if (signal(1, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_cmd_queue = malloc(sizeof(cmd_queue));
    if (!global_cmd_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_cmd_queue);
    pthread_t worker;
    if (pthread_create(&worker, ((void *)0), worker_thread, global_cmd_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}

canonical_original_code:
int main()
{
    int rc = 0;
    if (signal(1, handler1) == ((__sighandler_t) -1)) {
        printf("Signal error.\n");
        exit(1);
    }
    global_cmd_queue = malloc(sizeof(cmd_queue));
    if (!global_cmd_queue) {
        printf("malloc queue failed\n");
        exit(1);
    }
    init_queue(global_cmd_queue);
    unsigned long worker;
    if (pthread_create(&worker, ((void *)0), worker_thread, global_cmd_queue) != 0) {
        printf("Creating worker thread failed.\n");
        exit(1);
    }
    printf("[pid %d] main(), waiting for thread join...\n", (int) syscall(186));
    pthread_join(worker, ((void *)0));
    printf("[pid %d] main(), thread join done\n", (int) syscall(186));
    return 0;
}


decompiled_code:
void handler1()
{
int v0; // ebp
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> add command, interface: 0x%08x\n", v1);
add_cmd((unsigned int *)global_cmd_queue, v0);
}

canonical_decompiled_code:
void func9()
{
int v0; // ebp
__int64 v1; // rsi

v0 = global_interface;
v1 = (unsigned int)global_interface++;
printf("\n ==> add command, interface: 0x%08x\n", v1);
func8((unsigned int *)global_cmd_queue, v0);
}

original_code:
void handler1(int signo)
{
    int interface = 0;
    interface = global_interface;
    global_interface++;
    printf("\n  ==> add command, interface: 0x%08x\n", interface);
    add_cmd(global_cmd_queue, interface);
}


decompiled_code:
int __fastcall init_queue(__int64 a1)
{
pthread_mutex_t *v2; // r8
__int64 v3; // rdi

*(_QWORD *)(a1 + 16) = 0LL;
v2 = (pthread_mutex_t *)(a1 + 2064);
v3 = a1 + 24;
*(_QWORD *)(v3 + 2032) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 2064) >> 3));
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
return pthread_mutex_init(v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
pthread_mutex_t *v2; // r8
__int64 v3; // rdi

*(_QWORD *)(a1 + 16) = 0LL;
v2 = (pthread_mutex_t *)(a1 + 2064);
v3 = a1 + 24;
*(_QWORD *)(v3 + 2032) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 2064) >> 3));
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
return pthread_mutex_init(v2, 0LL);
}

original_code:
void init_queue(cmd_queue *queue)
{
    int i = 0;
    for (i = 0; i < 256; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
}

canonical_original_code:
void init_queue(struct _cmd_queue *queue)
{
    int i = 0;
    for (i = 0; i < 256; i++) {
        queue->entry[i] = ((void *)0);
    }
    queue->in = 0;
    queue->out = 0;
    queue->counter = 0;
    pthread_mutex_init(&queue->mutex, ((void *)0));
}

user_defined_types: struct _cmd_entry { int interface; char cmd[256]; char fname[256]; }


togglePower

decompiled_code:
int togglePower()
{
int result; // eax

if ( powerState )
{
result = mvprintw(4, 25, "p: standard power");
powerState = 0;
}
else
{
result = mvprintw(4, 25, "p: low power ");
powerState = 1;
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax

if ( powerState )
{
result = mvprintw(4, 25, "p: standard power");
powerState = 0;
}
else
{
result = mvprintw(4, 25, "p: low power ");
powerState = 1;
}
return result;
}

original_code:
void togglePower()
{
   if (powerState == 0) {
      mvprintw(4, 25, "p: low power     ");
      powerState = 1;
   } else {
      mvprintw(4, 25, "p: standard power");
      powerState = 0;
   }
}


nextAccelRange

decompiled_code:
int nextAccelRange()
{
int result; // eax

switch ( accelSensitivity )
{
case 0x2000:
accelSensitivity = 4096;
result = mvprintw(2, 49, " 8g");
break;
case 0x4000:
accelSensitivity = 0x2000;
result = mvprintw(2, 49, " 4g");
break;
case 0x1000:
accelSensitivity = 2048;
result = mvprintw(2, 49, "16g");
break;
default:
accelSensitivity = 0x4000;
result = mvprintw(2, 49, " 2g");
break;
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax

switch ( accelSensitivity )
{
case 0x2000:
accelSensitivity = 4096;
result = mvprintw(2, 49, " 8g");
break;
case 0x4000:
accelSensitivity = 0x2000;
result = mvprintw(2, 49, " 4g");
break;
case 0x1000:
accelSensitivity = 2048;
result = mvprintw(2, 49, "16g");
break;
default:
accelSensitivity = 0x4000;
result = mvprintw(2, 49, " 2g");
break;
}
return result;
}

original_code:
void nextAccelRange()
{
   switch(accelSensitivity) {
      case 16384:
         accelSensitivity = 8192;
         mvprintw(2, 49, " 4g");
         break;
      case 8192:
         accelSensitivity = 4096;
         mvprintw(2, 49, " 8g");
         break;
      case 4096:
         accelSensitivity = 2048;
         mvprintw(2, 49, "16g");
         break;
      case 2048:
      default:
         accelSensitivity = 16384;
         mvprintw(2, 49, " 2g");
         break;
   }
}


nextGyroRange

decompiled_code:
int nextGyroRange()
{
int v0; // eax
int result; // eax

v0 = (int)*(double *)&gyroSensitivity;
if ( (int)*(double *)&gyroSensitivity == 65 )
{
gyroSensitivity = 0x4040666666666666LL;
result = mvprintw(3, 49, "1000°/s");
}
else if ( v0 == 131 )
{
gyroSensitivity = 0x4050600000000000LL;
result = mvprintw(3, 49, " 500°/s");
}
else if ( v0 == 32 )
{
gyroSensitivity = 0x4030666666666666LL;
result = mvprintw(3, 49, "2000°/s");
}
else
{
gyroSensitivity = 0x4060600000000000LL;
result = mvprintw(3, 49, " 250°/s");
}
return result;
}

canonical_decompiled_code:
int func9()
{
int v0; // eax
int result; // eax

v0 = (int)*(double *)&gyroSensitivity;
if ( (int)*(double *)&gyroSensitivity == 65 )
{
gyroSensitivity = 0x4040666666666666LL;
result = mvprintw(3, 49, "1000°/s");
}
else if ( v0 == 131 )
{
gyroSensitivity = 0x4050600000000000LL;
result = mvprintw(3, 49, " 500°/s");
}
else if ( v0 == 32 )
{
gyroSensitivity = 0x4030666666666666LL;
result = mvprintw(3, 49, "2000°/s");
}
else
{
gyroSensitivity = 0x4060600000000000LL;
result = mvprintw(3, 49, " 250°/s");
}
return result;
}

original_code:
void nextGyroRange()
{
   switch((int)gyroSensitivity) {
      case 131:
         gyroSensitivity = 65.5;
         mvprintw(3, 49, " 500°/s");
         break;
      case 65:
         gyroSensitivity = 32.8;
         mvprintw(3, 49, "1000°/s");
         break;
      case 32:
         gyroSensitivity = 16.4;
         mvprintw(3, 49, "2000°/s");
         break;
      case 16:
      default:
         gyroSensitivity = 131;
         mvprintw(3, 49, " 250°/s");
         break;
   }
}


outputData

decompiled_code:
int __fastcall outputData(__int64 a1, unsigned int a2, double a3)
{
__int64 v4; // rdi

v4 = 0LL;
while ( *(_DWORD *)(a1 + 4 * v4) != a2 )
{
if ( ++v4 == 10 )
return a1;
}
if ( a2 - 120 > 2 )
LODWORD(a1) = mvprintw(v4, 0, "%c: %8.2f °/s", a2, a3 / *(double *)&gyroSensitivity);
else
LODWORD(a1) = mvprintw(v4, 0, "%c: %7.3f g", a2, a3 / (double)accelSensitivity);
return a1;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, unsigned int a2, double a3)
{
__int64 v4; // rdi

v4 = 0LL;
while ( *(_DWORD *)(a1 + 4 * v4) != a2 )
{
if ( ++v4 == 10 )
return a1;
}
if ( a2 - 120 > 2 )
LODWORD(a1) = mvprintw(v4, 0, "%c: %8.2f °/s", a2, a3 / *(double *)&gyroSensitivity);
else
LODWORD(a1) = mvprintw(v4, 0, "%c: %7.3f g", a2, a3 / (double)accelSensitivity);
return a1;
}

original_code:
void outputData(int* position, int in, double data)
{
   int i;
   for (i = 0; i < 10; i++) {
      if (position[i] == in) {
         break;
      }
   }
   if (i == 10) {
      return;
   }
   if (in == 'x' || in == 'y' || in == 'z') {
      mvprintw(i, 0, "%c: %7.3f g", in, data/accelSensitivity);
   } else {
      mvprintw(i, 0, "%c: %8.2f °/s", in, data/gyroSensitivity);
   }
}

canonical_original_code:
void outputData(int *position, int in, double data)
{
   int i;
   for (i = 0; i < 10; i++) {
      if (position[i] == in) {
         break;
      }
   }
   if (i == 10) {
      return;
   }
   if (in == 'x' || in == 'y' || in == 'z') {
      mvprintw(i, 0, "%c: %7.3f g", in, data/accelSensitivity);
   } else {
      mvprintw(i, 0, "%c: %8.2f °/s", in, data/gyroSensitivity);
   }
}

variable_types:
position
int *

variable_types: in int

variable_types: data double


charIsWhitespace

decompiled_code:
bool __fastcall charIsWhitespace(unsigned __int8 a1)
{
bool result; // al

if ( a1 > 0x20u )
result = 0;
else
result = ((1LL << a1) & 0x100002600LL) != 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(unsigned __int8 a1)
{
bool result; // al

if ( a1 > 0x20u )
result = 0;
else
result = ((1LL << a1) & 0x100002600LL) != 0;
return result;
}

original_code:
static _Bool charIsWhitespace(char c)
{
 switch(c)
 {
  case ' ':
  case '\t':
  case '\n':
  case '\r':
   return 1;
  default:
   return 0;
 }
}

variable_types: c char


printPosition

decompiled_code:
int __fastcall printPosition(__int64 a1, int a2, int a3)
{
_BYTE *v4; // rdx
__int64 v5; // r8
unsigned int v6; // er10
_BYTE *v7; // rax
__int64 v8; // rcx
const char *v9; // rdx
int result; // eax

if ( a2 <= 0 )
{
v5 = 1LL;
v6 = 1;
}
else
{
v4 = *(_BYTE **)(a1 + 8);
LODWORD(v5) = 1;
v6 = 1;
v7 = v4 + 1;
v8 = (__int64)&v4[a2 - 1 + 1];
while ( 1 )
{
v5 = (unsigned int)(v5 + 1);
if ( *v4 == 10 )
{
++v6;
v5 = 1LL;
}
v4 = v7;
if ( v7 == (_BYTE *)v8 )
break;
++v7;
}
}
v9 = *(const char **)(a1 + 16);
if ( a3 )
result = fprintf(stderr, "%s:%i:%i-%i: ", v9, v6, v5, (unsigned int)(v5 + a3));
else
result = fprintf(stderr, "%s:%i:%i: ", v9, v6, v5);
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2, int a3)
{
_BYTE *v4; // rdx
__int64 v5; // r8
unsigned int v6; // er10
_BYTE *v7; // rax
__int64 v8; // rcx
const char *v9; // rdx
int result; // eax

if ( a2 <= 0 )
{
v5 = 1LL;
v6 = 1;
}
else
{
v4 = *(_BYTE **)(a1 + 8);
LODWORD(v5) = 1;
v6 = 1;
v7 = v4 + 1;
v8 = (__int64)&v4[a2 - 1 + 1];
while ( 1 )
{
v5 = (unsigned int)(v5 + 1);
if ( *v4 == 10 )
{
++v6;
v5 = 1LL;
}
v4 = v7;
if ( v7 == (_BYTE *)v8 )
break;
++v7;
}
}
v9 = *(const char **)(a1 + 16);
if ( a3 )
result = fprintf(stderr, "%s:%i:%i-%i: ", v9, v6, v5, (unsigned int)(v5 + a3));
else
result = fprintf(stderr, "%s:%i:%i: ", v9, v6, v5);
return result;
}

original_code:
static void printPosition(const Stream* s, int offset, int length)
{
 int line=1;
 int column=1;
 for(int i=0;i<offset;i++)
 {
  if(s->data[i]=='\n')
  {
   line++;
   column=0;
  }
  column++;
 }
 if(length==0)
     fprintf(stderr, "%s:%i:%i: ", s->filename,line,column);
 else
     fprintf(stderr, "%s:%i:%i-%i: ", s->filename,line,column,column+length);
}

canonical_original_code:
static void printPosition(struct Stream *s, int offset, int length)
{
 int line = 1;
 int column = 1;
 for(int i = 0;i<offset;i++)
 {
  if(s->data[i]=='\n')
  {
   line++;
   column=0;
  }
  column++;
 }
 if(length==0)
     fprintf(stderr, "%s:%i:%i: ", s->filename,line,column);
 else
     fprintf(stderr, "%s:%i:%i-%i: ", s->filename,line,column,column+length);
}

variable_types: struct Stream { int length; int offset; char *data; char *filename; void (*errorHandler)(); } *

variable_types: offset int

variable_types: length int

variable_types: line int

variable_types: column int


closeStream

decompiled_code:
void __fastcall closeStream(void *ptr)
{
if ( ptr )
{
munmap(*((void **)ptr + 1), *(int *)ptr);
free(*((void **)ptr + 2));
free(ptr);
}
else
{
panic("stream.c", 55LL, "failed assertion: %s", "s!=NULL");
isEof();
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
munmap(*((void **)ptr + 1), *(int *)ptr);
free(*((void **)ptr + 2));
free(ptr);
}
else
{
panic("stream.c", 55LL, "failed assertion: %s", "s!=NULL");
func4();
}
}

original_code:
void closeStream(Stream* s)
{
 {if(!(s!=((void *)0))){panic("stream.c",55,"failed assertion: %s","s!=NULL");}};
 munmap(s->data,s->length);
 free(s->filename);
 free(s);
}

canonical_original_code:
void closeStream(struct Stream *s)
{
 {if(!(s!=((void *)0))){panic("stream.c",55,"failed assertion: %s","s!=NULL");}};
 munmap(s->data,s->length);
 free(s->filename);
 free(s);
}

user_defined_types: struct Stream { int length; int offset; char *data; char *filename; void (*errorHandler)(); }


isEof

decompiled_code:
bool __fastcall isEof(_DWORD *a1)
{
return a1[1] >= *a1;
}

canonical_decompiled_code:
bool __fastcall func4(_DWORD *a1)
{
return a1[1] >= *a1;
}

original_code:
_Bool isEof(const Stream* s)
{
 return s->offset>=s->length;
}

canonical_original_code:
_Bool isEof(struct Stream *s)
{
 return s->offset>=s->length;
}


peekStream

decompiled_code:
__int64 __fastcall peekStream(__int64 a1, int a2)
{
int v2; // esi
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 4) + a2;
if ( v2 >= *(_DWORD *)a1 || v2 < 0 )
result = 0LL;
else
result = *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // esi
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 4) + a2;
if ( v2 >= *(_DWORD *)a1 || v2 < 0 )
result = 0LL;
else
result = *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + v2);
return result;
}

original_code:
char peekStream(const Stream* s, int offset)
{
 if(s->offset+offset>=s->length || s->offset+offset<0)
  return '\0';
 else
  return s->data[s->offset+offset];
}

canonical_original_code:
char peekStream(struct Stream *s, int offset)
{
 if(s->offset+offset>=s->length || s->offset+offset<0)
  return '\0';
 else
  return s->data[s->offset+offset];
}

return_type: char


getStream

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

if ( *(_DWORD *)a1 <= a2 || a2 < 0 )
result = 0LL;
else
result = *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + a2);
return result;
}

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

if ( *(_DWORD *)a1 <= a2 || a2 < 0 )
result = 0LL;
else
result = *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + a2);
return result;
}

original_code:
char getStream(const Stream* s, int position)
{
 if(position>=s->length || position<0)
  return '\0';
 else
  return s->data[position];
}

canonical_original_code:
char getStream(struct Stream *s, int position)
{
 if(position>=s->length || position<0)
  return '\0';
 else
  return s->data[position];
}

variable_types: position int


printContext

decompiled_code:
void __fastcall printContext(int *a1, int a2, int a3)
{
int i; // ebx
char v6; // al
unsigned __int8 v7; // di
bool v8; // al
int j; // er14
char v10; // al
int v11; // er15
bool v12; // al
char v13; // al

if ( *a1 > a2 )
{
for ( i = a2; ; --i )
{
v6 = getStream((__int64)a1, i);
if ( !v6 || v6 == 10 )
break;
}
while ( 1 )
{
v7 = getStream((__int64)a1, i);
v8 = charIsWhitespace(v7);
if ( v7 )
{
if ( !v8 )
break;
}
++i;
}
for ( j = i; ; ++j )
{
v10 = getStream((__int64)a1, j);
if ( v10 == 10 || !v10 )
break;
}
v11 = i;
fputc(9, stderr);
if ( i < j )
{
do
{
v13 = getStream((__int64)a1, v11);
if ( v13 == 9 )
fputc(32, stderr);
else
fputc(v13, stderr);
++v11;
}
while ( j != v11 );
}
fputc(10, stderr);
fputc(9, stderr);
v12 = i < a3;
if ( j > a3 )
j = a3;
if ( i < j )
{
do
{
if ( a2 <= i && v12 )
fputc(94, stderr);
else
fputc(32, stderr);
v12 = a3 > ++i;
}
while ( i != j );
}
fputc(10, stderr);
}
}

canonical_decompiled_code:
void __fastcall func7(int *a1, int a2, int a3)
{
int i; // ebx
char v6; // al
unsigned __int8 v7; // di
bool v8; // al
int j; // er14
char v10; // al
int v11; // er15
bool v12; // al
char v13; // al

if ( *a1 > a2 )
{
for ( i = a2; ; --i )
{
v6 = func6((__int64)a1, i);
if ( !v6 || v6 == 10 )
break;
}
while ( 1 )
{
v7 = func6((__int64)a1, i);
v8 = func0(v7);
if ( v7 )
{
if ( !v8 )
break;
}
++i;
}
for ( j = i; ; ++j )
{
v10 = func6((__int64)a1, j);
if ( v10 == 10 || !v10 )
break;
}
v11 = i;
fputc(9, stderr);
if ( i < j )
{
do
{
v13 = func6((__int64)a1, v11);
if ( v13 == 9 )
fputc(32, stderr);
else
fputc(v13, stderr);
++v11;
}
while ( j != v11 );
}
fputc(10, stderr);
fputc(9, stderr);
v12 = i < a3;
if ( j > a3 )
j = a3;
if ( i < j )
{
do
{
if ( a2 <= i && v12 )
fputc(94, stderr);
else
fputc(32, stderr);
v12 = a3 > ++i;
}
while ( i != j );
}
fputc(10, stderr);
}
}

original_code:
static void printContext(const Stream* s, int start, int end)
{
 if(start<s->length)
 {
  int quote_start=start;
  while((getStream(s,quote_start))!='\n' && getStream(s,quote_start)!='\0')
   quote_start--;
  while(charIsWhitespace(getStream(s,quote_start)) || getStream(s,quote_start)=='\0')
   quote_start++;
  int quote_end=quote_start;
  while((getStream(s,quote_end))!='\n' && getStream(s,quote_end)!='\0')
   quote_end++;
  fprintf(stderr, "\t");
  for(int i=quote_start;i<quote_end;i++)
  {
   if(getStream(s,i)=='\t')
    fprintf(stderr," ");
   else
    fprintf(stderr,"%c",getStream(s,i));
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "\t");
  for(int i=quote_start;i<quote_end && i<end;i++)
  {
   if(i>=start && i<end)
    fprintf(stderr, "^");
   else
    fprintf(stderr, " ");
  }
  fprintf(stderr, "\n");
 }
}

canonical_original_code:
static void printContext(struct Stream *s, int start, int end)
{
 if(start<s->length)
 {
  int quote_start = start;
  while((getStream(s,quote_start))!='\n' && getStream(s,quote_start)!='\0')
   quote_start--;
  while(charIsWhitespace(getStream(s,quote_start)) || getStream(s,quote_start)=='\0')
   quote_start++;
  int quote_end = quote_start;
  while((getStream(s,quote_end))!='\n' && getStream(s,quote_end)!='\0')
   quote_end++;
  fprintf(stderr, "\t");
  for(int i = quote_start;i<quote_end;i++)
  {
   if(getStream(s,i)=='\t')
    fprintf(stderr," ");
   else
    fprintf(stderr,"%c",getStream(s,i));
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "\t");
  for(int i = quote_start;i<quote_end && i<end;i++)
  {
   if(i>=start && i<end)
    fprintf(stderr, "^");
   else
    fprintf(stderr, " ");
  }
  fprintf(stderr, "\n");
 }
}

variable_types: start int

variable_types: end int

variable_types: i int


seekStream

decompiled_code:
void __fastcall seekStream(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) += a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) += a2;
}

original_code:
void seekStream(Stream* s, int offset)
{
 s->offset+=offset;
}

canonical_original_code:
void seekStream(struct Stream *s, int offset)
{
 s->offset+=offset;
}


makeString

decompiled_code:
void __fastcall makeString(__int64 a1, int a2, int a3, __int64 a4)
{
if ( a4 )
{
*(_DWORD *)a4 = a2;
*(_DWORD *)(a4 + 4) = a3;
*(_QWORD *)(a4 + 8) = a1;
}
}

original_code:
void makeString(Stream* s, int start, int end, String* out)
{
 if(out==((void *)0))
  return;
 *out=(String){
  .offset=start,
  .length=end,
  .stream=s,
 };
}

canonical_original_code:
void makeString(struct Stream *s, int start, int end, struct String *out)
{
 if(out==((void *)0))
  return;
 *out=(struct String){
  .offset=start,
  .length=end,
  .stream=s,
 };
}

variable_types: struct String { int offset; int length; struct Stream *stream; } *


compareString

decompiled_code:
__int64 __fastcall compareString(int *a1, int *a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rax

v2 = a1[1];
result = 0LL;
if ( (_DWORD)v2 == a2[1] )
{
if ( (int)v2 <= 0 )
{
LABEL_8:
result = 1LL;
}
else
{
v4 = 0LL;
while ( *(_BYTE *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL) + *a1 + v4) == *(_BYTE *)(*(_QWORD *)(*((_QWORD *)a2 + 1) + 8LL)
+ *a2
+ v4) )
{
if ( v2 == ++v4 )
goto LABEL_8;
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, int *a2)
{
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // rax

v2 = a1[1];
result = 0LL;
if ( (_DWORD)v2 == a2[1] )
{
if ( (int)v2 <= 0 )
{
LABEL_8:
result = 1LL;
}
else
{
v4 = 0LL;
while ( *(_BYTE *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL) + *a1 + v4) == *(_BYTE *)(*(_QWORD *)(*((_QWORD *)a2 + 1) + 8LL)
+ *a2
+ v4) )
{
if ( v2 == ++v4 )
goto LABEL_8;
}
result = 0LL;
}
}
return result;
}

original_code:
_Bool compareString(const String* a, const String* b)
{
 if(a->length!=b->length)
  return 0;
 for(int i=0;i<a->length;i++)
  if(a->stream->data[a->offset+i]!=b->stream->data[b->offset+i])
   return 0;
 return 1;
}

canonical_original_code:
_Bool compareString(struct String *a, struct String *b)
{
 if(a->length!=b->length)
  return 0;
 for(int i = 0;i<a->length;i++)
  if(a->stream->data[a->offset+i]!=b->stream->data[b->offset+i])
   return 0;
 return 1;
}

variable_types: struct String { int offset; int length; struct Stream { int length; int offset; char *data; char *filename; void (*errorHandler)(); } *stream; } *

variable_types:
b
struct String *

user_defined_types: struct String { int offset; int length; struct Stream *stream; }


warnStream

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

va_start(arg, a2);
printPosition(a1, *(_DWORD *)(a1 + 4), 0);
fwrite("warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, a2, arg);
return fputc(10, stderr);
}

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

va_start(arg, a2);
func2(a1, *(_DWORD *)(a1 + 4), 0);
fwrite("warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, a2, arg);
return fputc(10, stderr);
}

original_code:
void warnStream(const Stream* s, const char* format, ...)
{
    printPosition(s,s->offset,0);
 fprintf(stderr, "warning: ");
 va_list args;
 __builtin_va_start(args,format);
 vfprintf(stderr,format,args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
}

canonical_original_code:
void warnStream(struct Stream *s, char *format, ...)
{
    printPosition(s,s->offset,0);
 fprintf(stderr, "warning: ");
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vfprintf(stderr,format,args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
}

variable_types:
format
char *


vpanicString

decompiled_code:
__int64 __fastcall vpanicString(__int64 a1, const char *a2, void *a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v8; // rdi
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9

if ( a1 )
{
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
{
printPosition(v8, *(_DWORD *)a1, *(_DWORD *)(a1 + 4));
fwrite("error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a2, a3);
fputc(10, stderr);
printContext(*(int **)(a1 + 8), *(_DWORD *)a1, *(_DWORD *)a1 + *(_DWORD *)(a1 + 4));
(*(void (**)(void))(*(_QWORD *)(a1 + 8) + 24LL))();
}
panic("stream.c", 207LL, "failed assertion: %s", "s->stream!=NULL");
}
panic("stream.c", 206LL, "failed assertion: %s", "s!=NULL");
return panicString((unsigned int)"stream.c", 206, v10, v11, v12, v13, a7);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2, void *a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v8; // rdi
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9

if ( a1 )
{
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
{
func2(v8, *(_DWORD *)a1, *(_DWORD *)(a1 + 4));
fwrite("error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a2, a3);
fputc(10, stderr);
func7(*(int **)(a1 + 8), *(_DWORD *)a1, *(_DWORD *)a1 + *(_DWORD *)(a1 + 4));
(*(void (**)(void))(*(_QWORD *)(a1 + 8) + 24LL))();
}
panic("stream.c", 207LL, "failed assertion: %s", "s->stream!=NULL");
}
panic("stream.c", 206LL, "failed assertion: %s", "s!=NULL");
return func13((unsigned int)"stream.c", 206, v10, v11, v12, v13, a7);
}

original_code:
void vpanicString(const String* s, const char* format, va_list args)
{
 {if(!(s!=((void *)0))){panic("stream.c",206,"failed assertion: %s","s!=NULL");}};
 {if(!(s->stream!=((void *)0))){panic("stream.c",207,"failed assertion: %s","s->stream!=NULL");}};
 printPosition(s->stream,s->offset,s->length);
    fprintf(stderr, "error: ");
 vfprintf(stderr,format,args);
 fprintf(stderr, "\n");
 printContext(s->stream,s->offset,s->offset+s->length);
 s->stream->errorHandler();
 {if(!(0)){panic("stream.c",220,"failed assertion: %s","false");}};
}

canonical_original_code:
void vpanicString(struct String *s, char *format, __builtin_va_list args)
{
 {if(!(s!=((void *)0))){panic("stream.c",206,"failed assertion: %s","s!=NULL");}};
 {if(!(s->stream!=((void *)0))){panic("stream.c",207,"failed assertion: %s","s->stream!=NULL");}};
 printPosition(s->stream,s->offset,s->length);
    fprintf(stderr, "error: ");
 vfprintf(stderr,format,args);
 fprintf(stderr, "\n");
 printContext(s->stream,s->offset,s->offset+s->length);
 s->stream->errorHandler();
 {if(!(0)){panic("stream.c",220,"failed assertion: %s","false");}};
}


panicString

decompiled_code:
__int64 panicString(__int64 a1, const char *a2, ...)
{
char v3; // [rsp+0h] [rbp-D8h]
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF
__int64 v5; // [rsp+30h] [rbp-A8h]
__int64 v6; // [rsp+38h] [rbp-A0h]
__int64 v7; // [rsp+40h] [rbp-98h]
__int64 v8; // [rsp+48h] [rbp-90h]

va_start(va, a2);
v5 = va_arg(va, _QWORD);
v6 = va_arg(va, _QWORD);
v7 = va_arg(va, _QWORD);
v8 = va_arg(va, _QWORD);
va_end(va);
va_start(va, a2);
vpanicString(a1, a2, va, v6, v7, v8, v3);
return panicStream();
}

canonical_decompiled_code:
__int64 func13(__int64 a1, const char *a2, ...)
{
char v3; // [rsp+0h] [rbp-D8h]
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF
__int64 v5; // [rsp+30h] [rbp-A8h]
__int64 v6; // [rsp+38h] [rbp-A0h]
__int64 v7; // [rsp+40h] [rbp-98h]
__int64 v8; // [rsp+48h] [rbp-90h]

va_start(va, a2);
v5 = va_arg(va, _QWORD);
v6 = va_arg(va, _QWORD);
v7 = va_arg(va, _QWORD);
v8 = va_arg(va, _QWORD);
va_end(va);
va_start(va, a2);
func12(a1, a2, va, v6, v7, v8, v3);
return func14();
}

original_code:
void panicString(const String* s, const char* format, ...)
{
 va_list args;
 __builtin_va_start(args,format);
 vpanicString(s,format,args);
 __builtin_va_end(args);
}

canonical_original_code:
void panicString(struct String *s, char *format, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vpanicString(s,format,args);
 __builtin_va_end(args);
}


panicStream

decompiled_code:
__int64 panicStream(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
printPosition(a1, *(_DWORD *)(a1 + 4), 0);
fwrite("error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a2, arg);
fputc(10, stderr);
printContext((int *)a1, *(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 4) + 1);
(*(void (**)(void))(a1 + 24))();
return strdupString();
}

canonical_decompiled_code:
__int64 func14(__int64 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
func2(a1, *(_DWORD *)(a1 + 4), 0);
fwrite("error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a2, arg);
fputc(10, stderr);
func7((int *)a1, *(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 4) + 1);
(*(void (**)(void))(a1 + 24))();
return func15();
}

original_code:
_Bool panicStream(const Stream* s, const char* format, ...)
{
    printPosition(s,s->offset,0);
    fprintf(stderr, "error: ");
 va_list args;
 __builtin_va_start(args,format);
 vfprintf(stderr,format,args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
 printContext(s,s->offset,s->offset+1);
 s->errorHandler();
 {if(!(0)){panic("stream.c",249,"failed assertion: %s","false");}};
}

canonical_original_code:
_Bool panicStream(struct Stream *s, char *format, ...)
{
    printPosition(s,s->offset,0);
    fprintf(stderr, "error: ");
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vfprintf(stderr,format,args);
 __builtin_va_end(args);
 fprintf(stderr, "\n");
 printContext(s,s->offset,s->offset+1);
 s->errorHandler();
 {if(!(0)){panic("stream.c",249,"failed assertion: %s","false");}};
}


strdupString

decompiled_code:
__int64 __fastcall strdupString(int *a1)
{
return (int)strndup((const char *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL) + *a1), (unsigned int)a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func15(int *a1)
{
return (int)strndup((const char *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL) + *a1), (unsigned int)a1[1]);
}

original_code:
char* strdupString(const String* s)
{
 return strndup(s->stream->data+s->offset,s->length);
}

canonical_original_code:
char *strdupString(struct String *s)
{
 return strndup(s->stream->data+s->offset,s->length);
}

return_type: char *


copyString

original_code:
char* copyString(const String* s, char* buf, int len)
{
 int min(int a, int b)
 {
  return a>b?b:a;
 }
 for(int i=0;i<len&&i<s->length;i++)
  buf[i]=s->stream->data[s->offset+i];
 buf[min(len-1,s->length)]='\0';
 return buf;
}

canonical_original_code:
char *copyString(struct String *s, char *buf, int len)
{
 int min(int a, int b)
 {
  return a>b?b:a;
 }
 for(int i = 0;i<len&&i<s->length;i++)
  buf[i]=s->stream->data[s->offset+i];
 buf[min(len-1,s->length)]='\0';
 return buf;
}

variable_types:
buf
char *

variable_types: len int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
const char *v5; // r11
__int64 v6; // rdx
const char *v7; // r8

if ( argc <= 1 )
{
LABEL_14:
panic("lang.c", 95LL, "no filename specified");
LABEL_15:
panic("lang.c", 79LL, "failed assertion: %s", "i+1<argc");
LABEL_16:
panic("lang.c", 85LL, "unknown option: %s", v7);
JUMPOUT(0x26ALL);
}
v3 = 0x10000;
v4 = 1;
v5 = "out.bc";
while ( 1 )
{
v6 = v4;
v7 = argv[v6];
if ( !*v7 )
goto LABEL_4;
if ( *v7 != 45 )
return run(v3, (__int64)v5, argc - v4, &argv[v6]);
if ( !strcmp(argv[v4], "--dump-pt") )
{
LOBYTE(v3) = 1;
}
else if ( !strcmp(argv[v4], "--dump-llvm") )
{
BYTE1(v3) = 1;
}
else
{
if ( strcmp(argv[v4], "--output") )
goto LABEL_16;
++v4;
v3 &= 0xFF00FFFF;
if ( v4 >= argc )
goto LABEL_15;
v5 = argv[v6 + 1];
}
LABEL_4:
if ( argc <= ++v4 )
goto LABEL_14;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
const char *v5; // r11
__int64 v6; // rdx
const char *v7; // r8

if ( argc <= 1 )
{
LABEL_14:
panic("lang.c", 95LL, "no filename specified");
LABEL_15:
panic("lang.c", 79LL, "failed assertion: %s", "i+1<argc");
LABEL_16:
panic("lang.c", 85LL, "unknown option: %s", v7);
JUMPOUT(0x26ALL);
}
v3 = 0x10000;
v4 = 1;
v5 = "out.bc";
while ( 1 )
{
v6 = v4;
v7 = argv[v6];
if ( !*v7 )
goto LABEL_4;
if ( *v7 != 45 )
return func0(v3, (__int64)v5, argc - v4, &argv[v6]);
if ( !strcmp(argv[v4], "--dump-pt") )
{
LOBYTE(v3) = 1;
}
else if ( !strcmp(argv[v4], "--dump-llvm") )
{
BYTE1(v3) = 1;
}
else
{
if ( strcmp(argv[v4], "--output") )
goto LABEL_16;
++v4;
v3 &= 0xFF00FFFF;
if ( v4 >= argc )
goto LABEL_15;
v5 = argv[v6 + 1];
}
LABEL_4:
if ( argc <= ++v4 )
goto LABEL_14;
}
}

original_code:
int main(int argc, const char* argv[])
{
 Config config={
  .output="out.bc",
  .run=1
 };
 for(int i=1;i<argc;i++)
 {
  if(strlen(argv[i])>0)
  {
   if(argv[i][0]=='-')
   {
    if(strcmp(argv[i],"--dump-pt")==0)
    {
     config.dumpPT=1;
    }
    else if(strcmp(argv[i],"--dump-llvm")==0)
    {
     config.dumpLLVM=1;
    }
    else if(strcmp(argv[i],"--output")==0)
    {
     config.run=0;
     {if(!(i+1<argc)){panic("lang.c",79,"failed assertion: %s","i+1<argc");}};
     config.output=argv[i+1];
     i++;
    }
    else
    {
     panic("lang.c",85,"unknown option: %s",argv[i]);
    }
   }
   else
   {
    return run(config,argc-i,&argv[i]);
   }
  }
 }
 panic("lang.c",95,"no filename specified");
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct Config config = {
  .output="out.bc",
  .run=1
 };
 for(int i = 1;i<argc;i++)
 {
  if(strlen(argv[i])>0)
  {
   if(argv[i][0]=='-')
   {
    if(strcmp(argv[i],"--dump-pt")==0)
    {
     config.dumpPT=1;
    }
    else if(strcmp(argv[i],"--dump-llvm")==0)
    {
     config.dumpLLVM=1;
    }
    else if(strcmp(argv[i],"--output")==0)
    {
     config.run=0;
     {if(!(i+1<argc)){panic("lang.c",79,"failed assertion: %s","i+1<argc");}};
     config.output=argv[i+1];
     i++;
    }
    else
    {
     panic("lang.c",85,"unknown option: %s",argv[i]);
    }
   }
   else
   {
    return run(config,argc-i,&argv[i]);
   }
  }
 }
 panic("lang.c",95,"no filename specified");
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct Config { _Bool dumpPT; _Bool dumpLLVM; _Bool run; char *output; }


parseOperator

decompiled_code:
__int64 __fastcall parseOperator(__int64 a1, _DWORD *a2, char a3)
{
int v4; // ebp
__int64 v5; // rbx
__int64 result; // rax

v4 = 0;
v5 = (unsigned int)((_DWORD)&operators + 8);
do
{
if ( (*(_DWORD *)v5 == 1) == a3 )
{
result = readString(a1, *(_QWORD *)(v5 + 16));
if ( (_BYTE)result )
{
*a2 = v4;
return result;
}
}
++v4;
v5 += 56LL;
}
while ( v4 != 24 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, char a3)
{
int v4; // ebp
__int64 v5; // rbx
__int64 result; // rax

v4 = 0;
v5 = (unsigned int)((_DWORD)&operators + 8);
do
{
if ( (*(_DWORD *)v5 == 1) == a3 )
{
result = readString(a1, *(_QWORD *)(v5 + 16));
if ( (_BYTE)result )
{
*a2 = v4;
return result;
}
}
++v4;
v5 += 56LL;
}
while ( v4 != 24 );
return 0LL;
}

original_code:
_Bool parseOperator(Stream* s, OperatorId* out, _Bool prefix)
{
 for(OperatorId op=0;op<OPERATOR_LAST;op++)
 {
  if((operators[op].type==PREFIX) == prefix)
   if(readString(s,operators[op].chars))
   {
    *out=op;
    return 1;
   }
 }
 return 0;
}

canonical_original_code:
_Bool parseOperator(struct Stream *s, enum OperatorId *out, _Bool prefix)
{
 for(enum OperatorId op = 0;op<OPERATOR_LAST;op++)
 {
  if((operators[op].type==PREFIX) == prefix)
   if(readString(s,operators[op].chars))
   {
    *out=op;
    return 1;
   }
 }
 return 0;
}

variable_types: struct Stream { int length; int offset; char *data; char *filename; void (*errorHandler)(); } *

variable_types: enum OperatorId { OPERATOR_ELEMENT=0, OPERATOR_INDEX=1, OPERATOR_CALL=2, OPERATOR_POSTFIX_INCREMENT=3, OPERATOR_POSTFIX_DECREMENT=4, OPERATOR_DEREF=5, OPERATOR_ADDRESS=6, OPERATOR_PREFIX_INCREMENT=7, OPERATOR_PREFIX_DECREMENT=8, OPERATOR_PREFIX_PLUS=9, OPERATOR_PREFIX_MINUS=10, OPERATOR_MUL=11, OPERATOR_DIV=12, OPERATOR_IDIV=13, OPERATOR_MOD=14, OPERATOR_PLUS=15, OPERATOR_MINUS=16, OPERATOR_LT=17, OPERATOR_GT=18, OPERATOR_LE=19, OPERATOR_GE=20, OPERATOR_EQ=21, OPERATOR_NE=22, OPERATOR_ASSIGMENT=23, OPERATOR_LAST=24 } *


parseIdentifier

decompiled_code:
__int64 __fastcall parseIdentifier(__int64 a1, __int64 a2)
{
unsigned int v2; // er12

v2 = readIdentifier(a1, a2 + 8);
if ( (_BYTE)v2 )
{
*(_DWORD *)a2 = 1;
*(_QWORD *)(a2 + 24) = strdupString(a2 + 8);
}
return v2;
}

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

v2 = readIdentifier(a1, a2 + 8);
if ( (_BYTE)v2 )
{
*(_DWORD *)a2 = 1;
*(_QWORD *)(a2 + 24) = strdupString(a2 + 8);
}
return v2;
}

original_code:
_Bool parseIdentifier(Stream* s, Node* out)
{
 if(readIdentifier(s,&out->source))
 {
  out->type=IDENTIFIER;
  out->value=strdupString(&out->source);
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
_Bool parseIdentifier(struct Stream *s, struct Node *out)
{
 if(readIdentifier(s,&out->source))
 {
  out->type=IDENTIFIER;
  out->value=strdupString(&out->source);
  return 1;
 }
 else
 {
  return 0;
 }
}

variable_types: struct Node { int type; struct String { int offset; int length; struct Stream *stream; } source; char *value; enum OperatorId { OPERATOR_ELEMENT=0, OPERATOR_INDEX=1, OPERATOR_CALL=2, OPERATOR_POSTFIX_INCREMENT=3, OPERATOR_POSTFIX_DECREMENT=4, OPERATOR_DEREF=5, OPERATOR_ADDRESS=6, OPERATOR_PREFIX_INCREMENT=7, OPERATOR_PREFIX_DECREMENT=8, OPERATOR_PREFIX_PLUS=9, OPERATOR_PREFIX_MINUS=10, OPERATOR_MUL=11, OPERATOR_DIV=12, OPERATOR_IDIV=13, OPERATOR_MOD=14, OPERATOR_PLUS=15, OPERATOR_MINUS=16, OPERATOR_LT=17, OPERATOR_GT=18, OPERATOR_LE=19, OPERATOR_GE=20, OPERATOR_EQ=21, OPERATOR_NE=22, OPERATOR_ASSIGMENT=23, OPERATOR_LAST=24 } operator; struct Node *child; struct Node *next; } *

user_defined_types: struct Node { int type; struct String source; char *value; enum OperatorId operator; struct Node *child; struct Node *next; }


parseExpresion

decompiled_code:
__int64 __fastcall parseExpresion(__int64 a1, __int64 a2)
{
return parseOperatorExpresion(a1, a2, parseSimpleExpresion, parseOperator);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return parseOperatorExpresion(a1, a2, parseSimpleExpresion, parseOperator);
}

original_code:
_Bool parseExpresion(Stream*s, Node* out)
{
 return parseOperatorExpresion(s, out, parseSimpleExpresion,parseOperator);
}

canonical_original_code:
_Bool parseExpresion(struct Stream *s, struct Node *out)
{
 return parseOperatorExpresion(s, out, parseSimpleExpresion,parseOperator);
}

user_defined_types: enum OperatorId { OPERATOR_ELEMENT=0, OPERATOR_INDEX=1, OPERATOR_CALL=2, OPERATOR_POSTFIX_INCREMENT=3, OPERATOR_POSTFIX_DECREMENT=4, OPERATOR_DEREF=5, OPERATOR_ADDRESS=6, OPERATOR_PREFIX_INCREMENT=7, OPERATOR_PREFIX_DECREMENT=8, OPERATOR_PREFIX_PLUS=9, OPERATOR_PREFIX_MINUS=10, OPERATOR_MUL=11, OPERATOR_DIV=12, OPERATOR_IDIV=13, OPERATOR_MOD=14, OPERATOR_PLUS=15, OPERATOR_MINUS=16, OPERATOR_LT=17, OPERATOR_GT=18, OPERATOR_LE=19, OPERATOR_GE=20, OPERATOR_EQ=21, OPERATOR_NE=22, OPERATOR_ASSIGMENT=23, OPERATOR_LAST=24 }


parseSimpleExpresion

decompiled_code:
__int64 __fastcall parseSimpleExpresion(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v5; // er12

v2 = readString(a1, "null");
if ( (_BYTE)v2 )
{
*(_DWORD *)a2 = 7;
return v2;
}
v5 = readString(a1, "true");
if ( (_BYTE)v5 )
{
*(_DWORD *)a2 = 8;
return v5;
}
v3 = readString(a1, "false");
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 9;
return v3;
}
if ( (unsigned __int8)parseIdentifier(a1, a2) )
return 1;
v3 = readNumber(a1, a2 + 8);
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 3;
*(_QWORD *)(a2 + 24) = strdupString(a2 + 8);
return v3;
}
if ( !(unsigned __int8)readString(a1, "(") )
{
v3 = readString(a1, asc_B84);
if ( !(_BYTE)v3 )
{
v3 = readStringConstant(a1, a2 + 8);
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 5;
*(_QWORD *)(a2 + 24) = unquoteString(a2 + 8);
}
else
{
v3 = readCharConstant(a1, a2 + 8);
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 4;
*(_QWORD *)(a2 + 24) = unquoteString(a2 + 8);
}
}
return v3;
}
*(_DWORD *)a2 = 6;
while ( !(unsigned __int8)readString(a1, &asc_B84[1]) )
{
if ( !(unsigned __int8)childParse(a1, a2, parseExpresion) || !(unsigned __int8)readString(a1, &asc_B84[2]) )
{
expect(a1, &asc_B84[1]);
return v3;
}
}
return 1;
}
v3 = parseExpresion(a1, a2);
if ( (_BYTE)v3 )
{
expect(a1, ")");
return v3;
}
panicStream(a1, "expected expresion");
return parseStructBody();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v5; // er12

v2 = readString(a1, "null");
if ( (_BYTE)v2 )
{
*(_DWORD *)a2 = 7;
return v2;
}
v5 = readString(a1, "true");
if ( (_BYTE)v5 )
{
*(_DWORD *)a2 = 8;
return v5;
}
v3 = readString(a1, "false");
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 9;
return v3;
}
if ( (unsigned __int8)func1(a1, a2) )
return 1;
v3 = readNumber(a1, a2 + 8);
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 3;
*(_QWORD *)(a2 + 24) = strdupString(a2 + 8);
return v3;
}
if ( !(unsigned __int8)readString(a1, "(") )
{
v3 = readString(a1, asc_B84);
if ( !(_BYTE)v3 )
{
v3 = readStringConstant(a1, a2 + 8);
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 5;
*(_QWORD *)(a2 + 24) = unquoteString(a2 + 8);
}
else
{
v3 = readCharConstant(a1, a2 + 8);
if ( (_BYTE)v3 )
{
*(_DWORD *)a2 = 4;
*(_QWORD *)(a2 + 24) = unquoteString(a2 + 8);
}
}
return v3;
}
*(_DWORD *)a2 = 6;
while ( !(unsigned __int8)readString(a1, &asc_B84[1]) )
{
if ( !(unsigned __int8)childParse(a1, a2, parseExpresion) || !(unsigned __int8)readString(a1, &asc_B84[2]) )
{
expect(a1, &asc_B84[1]);
return v3;
}
}
return 1;
}
v3 = func2(a1, a2);
if ( (_BYTE)v3 )
{
expect(a1, ")");
return v3;
}
panicStream(a1, "expected expresion");
return func4();
}

original_code:
_Bool parseSimpleExpresion(Stream* s, Node* out)
{
 if(readString(s,"null"))
 {
  out->type=NULL_CONSTANT;
 }
 else if(readString(s,"true"))
 {
  out->type=TRUE_CONSTANT;
 }
 else if(readString(s,"false"))
 {
  out->type=FALSE_CONSTANT;
 }
 else if(parseIdentifier(s,out))
 {
 }
 else if(readNumber(s,&out->source))
 {
  out->type=NUMERIC_CONSTANT;
  out->value=strdupString(&out->source);
 }
 else if(readString(s,"("))
 {
  parseExpresion(s,out) ?0: panicStream(s,"expected expresion");
  expect(s,")");
 }
 else if(readString(s,"{"))
 {
  out->type=STRUCT_CONSTANT;
  while(readString(s,"}")==0)
  {
   if(childParse(s,out,parseExpresion)==0)
   {
    expect(s,"}");
    break;
   }
   if(readString(s,",")==0)
   {
    expect(s,"}");
    break;
   }
  }
 }
 else if(readStringConstant(s,&out->source))
 {
  out->type=STRING_CONSTANT;
  out->value=unquoteString(&out->source);
 }
 else if(readCharConstant(s,&out->source))
 {
  out->type=CHAR_CONSTANT;
  out->value=unquoteString(&out->source);
 }
 else
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
_Bool parseSimpleExpresion(struct Stream *s, struct Node *out)
{
 if(readString(s,"null"))
 {
  out->type=NULL_CONSTANT;
 }
 else if(readString(s,"true"))
 {
  out->type=TRUE_CONSTANT;
 }
 else if(readString(s,"false"))
 {
  out->type=FALSE_CONSTANT;
 }
 else if(parseIdentifier(s,out))
 {
 }
 else if(readNumber(s,&out->source))
 {
  out->type=NUMERIC_CONSTANT;
  out->value=strdupString(&out->source);
 }
 else if(readString(s,"("))
 {
  parseExpresion(s,out) ?0: panicStream(s,"expected expresion");
  expect(s,")");
 }
 else if(readString(s,"{"))
 {
  out->type=STRUCT_CONSTANT;
  while(readString(s,"}")==0)
  {
   if(childParse(s,out,parseExpresion)==0)
   {
    expect(s,"}");
    break;
   }
   if(readString(s,",")==0)
   {
    expect(s,"}");
    break;
   }
  }
 }
 else if(readStringConstant(s,&out->source))
 {
  out->type=STRING_CONSTANT;
  out->value=unquoteString(&out->source);
 }
 else if(readCharConstant(s,&out->source))
 {
  out->type=CHAR_CONSTANT;
  out->value=unquoteString(&out->source);
 }
 else
 {
  return 0;
 }
 return 1;
}


parseStructBody

decompiled_code:
__int64 __fastcall parseStructBody(__int64 a1, _DWORD *a2)
{
*a2 = 16;
expect(a1, asc_B84);
parseTerminated(a1, a2, parseVariableDeclaration, &asc_B84[3]);
expect(a1, &asc_B84[1]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2)
{
*a2 = 16;
expect(a1, asc_B84);
parseTerminated(a1, a2, parseVariableDeclaration, &asc_B84[3]);
expect(a1, &asc_B84[1]);
return 1LL;
}

original_code:
static _Bool parseStructBody(Stream* s, Node* out) {
 out->type=STRUCT_TYPE;
 expect(s,"{");
 parseTerminated(s,out,parseVariableDeclaration,";");
 expect(s,"}");
 return 1;
}

canonical_original_code:
static _Bool parseStructBody(struct Stream *s, struct Node *out) {
 out->type=STRUCT_TYPE;
 expect(s,"{");
 parseTerminated(s,out,parseVariableDeclaration,";");
 expect(s,"}");
 return 1;
}


parseBlock

decompiled_code:
__int64 __fastcall parseBlock(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er13
unsigned int v3; // er12

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
v3 = readString(a1, asc_B84);
if ( (_BYTE)v3 )
{
*a2 = 26;
parseTerminated(a1, a2, parseStatement, &asc_B84[3]);
expect(a1, &asc_B84[1]);
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er13
unsigned int v3; // er12

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
v3 = readString(a1, asc_B84);
if ( (_BYTE)v3 )
{
*a2 = 26;
parseTerminated(a1, a2, parseStatement, &asc_B84[3]);
expect(a1, &asc_B84[1]);
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
}
return v3;
}

original_code:
_Bool parseBlock(Stream* s, Node* out)
{
 readWhitespace(s);
 int start=s->offset;
 if(!readString(s,"{"))
  return 0;
 out->type=BLOCK;
 parseTerminated(s,out,parseStatement,";");
 expect(s,"}");
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}

canonical_original_code:
_Bool parseBlock(struct Stream *s, struct Node *out)
{
 readWhitespace(s);
 int start = s->offset;
 if(!readString(s,"{"))
  return 0;
 out->type=BLOCK;
 parseTerminated(s,out,parseStatement,";");
 expect(s,"}");
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}


parseVariableDeclaration

decompiled_code:
__int64 __fastcall parseVariableDeclaration(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er13
__int64 result; // rax
unsigned __int8 v4; // al
unsigned __int8 v5; // [rsp+Fh] [rbp-19h]

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
result = childParse(a1, a2, parseIdentifier);
if ( (_BYTE)result )
{
*a2 = 12;
expect(a1, &asc_B84[4]);
v4 = childParse(a1, a2, parseType);
if ( v4 )
{
v5 = v4;
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
result = v5;
}
else
{
panicStream(a1, "expected type name");
result = parseFunctionType();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er13
__int64 result; // rax
unsigned __int8 v4; // al
unsigned __int8 v5; // [rsp+Fh] [rbp-19h]

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
result = childParse(a1, a2, parseIdentifier);
if ( (_BYTE)result )
{
*a2 = 12;
expect(a1, &asc_B84[4]);
v4 = childParse(a1, a2, parseType);
if ( v4 )
{
v5 = v4;
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
result = v5;
}
else
{
panicStream(a1, "expected type name");
result = func7();
}
}
return result;
}

original_code:
_Bool parseVariableDeclaration(Stream* s, Node* out)
{
 readWhitespace(s);
 int start=s->offset;
 if(!childParse(s,out,parseIdentifier))
  return 0;
 out->type = VARIABLE_DECLARATION;
 expect(s,":");
 childParse(s,out,parseType) ?0: panicStream(s,"expected type name");
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}

canonical_original_code:
_Bool parseVariableDeclaration(struct Stream *s, struct Node *out)
{
 readWhitespace(s);
 int start = s->offset;
 if(!childParse(s,out,parseIdentifier))
  return 0;
 out->type = VARIABLE_DECLARATION;
 expect(s,":");
 childParse(s,out,parseType) ?0: panicStream(s,"expected type name");
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}


parseFunctionType

decompiled_code:
__int64 __fastcall parseFunctionType(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
int v4; // edx
_OWORD v5[3]; // [rsp+0h] [rbp-58h] BYREF
__int64 v6; // [rsp+30h] [rbp-28h]

expect(a1, "(");
while ( (unsigned __int8)childParse(a1, a2, parseVariableDeclaration) )
{
if ( !(unsigned __int8)readString(a1, &asc_B84[2]) )
goto LABEL_6;
}
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "...") )
{
v4 = *(_DWORD *)(a1 + 4);
v5[0] = 0LL;
v6 = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
makeString(a1, v2, v4 - v2, (char *)v5 + 8);
addChild(a2);
}
LABEL_6:
expect(a1, ")");
expect(a1, &asc_B84[4]);
childParse(a1, a2, parseType);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
int v4; // edx
_OWORD v5[3]; // [rsp+0h] [rbp-58h] BYREF
__int64 v6; // [rsp+30h] [rbp-28h]

expect(a1, "(");
while ( (unsigned __int8)childParse(a1, a2, parseVariableDeclaration) )
{
if ( !(unsigned __int8)readString(a1, &asc_B84[2]) )
goto LABEL_6;
}
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "...") )
{
v4 = *(_DWORD *)(a1 + 4);
v5[0] = 0LL;
v6 = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
makeString(a1, v2, v4 - v2, (char *)v5 + 8);
addChild(a2);
}
LABEL_6:
expect(a1, ")");
expect(a1, &asc_B84[4]);
childParse(a1, a2, parseType);
return 1LL;
}

original_code:
_Bool parseFunctionType(Stream* s, Node* out)
{
 expect(s,"(");
 while(1)
 {
  if(!childParse(s,out,parseVariableDeclaration))
  {
   int start=s->offset;
   if(readString(s,"..."))
   {
    Node ellipsis={.type=ELLIPSIS};
    makeString(s, start, s->offset-start, &ellipsis.source);
    addChild(out,ellipsis);
   }
   break;
  }
  if(!readString(s,","))
   break;
 }
 expect(s,")");
 expect(s,":");
 childParse(s,out,parseType);
 return 1;
}

canonical_original_code:
_Bool parseFunctionType(struct Stream *s, struct Node *out)
{
 expect(s,"(");
 while(1)
 {
  if(!childParse(s,out,parseVariableDeclaration))
  {
   int start = s->offset;
   if(readString(s,"..."))
   {
    struct Node ellipsis = {.type=ELLIPSIS};
    makeString(s, start, s->offset-start, &ellipsis.source);
    addChild(out,ellipsis);
   }
   break;
  }
  if(!readString(s,","))
   break;
 }
 expect(s,")");
 expect(s,":");
 childParse(s,out,parseType);
 return 1;
}

variable_types: struct Node { int type; struct String { int offset; int length; struct Stream { int length; int offset; char *data; char *filename; void (*errorHandler)(); } *stream; } source; char *value; enum OperatorId { OPERATOR_ELEMENT=0, OPERATOR_INDEX=1, OPERATOR_CALL=2, OPERATOR_POSTFIX_INCREMENT=3, OPERATOR_POSTFIX_DECREMENT=4, OPERATOR_DEREF=5, OPERATOR_ADDRESS=6, OPERATOR_PREFIX_INCREMENT=7, OPERATOR_PREFIX_DECREMENT=8, OPERATOR_PREFIX_PLUS=9, OPERATOR_PREFIX_MINUS=10, OPERATOR_MUL=11, OPERATOR_DIV=12, OPERATOR_IDIV=13, OPERATOR_MOD=14, OPERATOR_PLUS=15, OPERATOR_MINUS=16, OPERATOR_LT=17, OPERATOR_GT=18, OPERATOR_LE=19, OPERATOR_GE=20, OPERATOR_EQ=21, OPERATOR_NE=22, OPERATOR_ASSIGMENT=23, OPERATOR_LAST=24 } operator; struct Node *child; struct Node *next; }


parseType

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

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "struct") )
{
parseStructBody(a1, a2);
LABEL_3:
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
return 1LL;
}
if ( (unsigned __int8)readString(a1, "function") )
{
*a2 = 17;
parseFunctionType(a1, (__int64)a2);
goto LABEL_3;
}
if ( (unsigned __int8)readString(a1, "*") )
{
*a2 = 14;
childParse(a1, a2, parseType);
goto LABEL_3;
}
if ( (unsigned __int8)readString(a1, "[") )
{
*a2 = 15;
childParse(a1, a2, parseExpresion);
expect(a1, "]");
childParse(a1, a2, parseType);
goto LABEL_3;
}
result = parseIdentifier(a1, (__int64)a2);
if ( (_BYTE)result )
goto LABEL_3;
return result;
}

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

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "struct") )
{
func4(a1, a2);
LABEL_3:
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
return 1LL;
}
if ( (unsigned __int8)readString(a1, "function") )
{
*a2 = 17;
func7(a1, (__int64)a2);
goto LABEL_3;
}
if ( (unsigned __int8)readString(a1, "*") )
{
*a2 = 14;
childParse(a1, a2, parseType);
goto LABEL_3;
}
if ( (unsigned __int8)readString(a1, "[") )
{
*a2 = 15;
childParse(a1, a2, parseExpresion);
expect(a1, "]");
childParse(a1, a2, parseType);
goto LABEL_3;
}
result = func1(a1, (__int64)a2);
if ( (_BYTE)result )
goto LABEL_3;
return result;
}

original_code:
_Bool parseType(Stream* s, Node* out)
{
 readWhitespace(s);
 int start=s->offset;
 if(readString(s,"struct"))
 {
  parseStructBody(s,out);
 }
 else if(readString(s,"function"))
 {
  out->type=FUNCTION_TYPE;
  parseFunctionType(s,out);
 }
 else if(readString(s,"*"))
 {
  out->type=POINTER_TYPE;
  childParse(s,out,parseType);
 }
 else if(readString(s,"["))
 {
  out->type=ARRAY_TYPE;
  childParse(s,out,parseExpresion);
  expect(s,"]");
  childParse(s,out,parseType);
 }
 else if(parseIdentifier(s,out))
 {
 }
 else
 {
  return 0;
 }
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}

canonical_original_code:
_Bool parseType(struct Stream *s, struct Node *out)
{
 readWhitespace(s);
 int start = s->offset;
 if(readString(s,"struct"))
 {
  parseStructBody(s,out);
 }
 else if(readString(s,"function"))
 {
  out->type=FUNCTION_TYPE;
  parseFunctionType(s,out);
 }
 else if(readString(s,"*"))
 {
  out->type=POINTER_TYPE;
  childParse(s,out,parseType);
 }
 else if(readString(s,"["))
 {
  out->type=ARRAY_TYPE;
  childParse(s,out,parseExpresion);
  expect(s,"]");
  childParse(s,out,parseType);
 }
 else if(parseIdentifier(s,out))
 {
 }
 else
 {
  return 0;
 }
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}


parseDeclaration

decompiled_code:
__int64 __fastcall parseDeclaration(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int128 v4[3]; // [rsp+0h] [rbp-58h] BYREF
__int64 v5; // [rsp+30h] [rbp-28h]

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "struct") )
{
*a2 = 11;
childParse(a1, a2, parseIdentifier);
childParse(a1, a2, parseStructBody);
LABEL_3:
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
return 1LL;
}
if ( (unsigned __int8)readString(a1, "var") )
{
*a2 = 12;
parseVariableDeclaration(a1, a2);
if ( (unsigned __int8)readString(a1, "=") )
childParse(a1, a2, parseExpresion);
goto LABEL_3;
}
result = readString(a1, "function");
if ( (_BYTE)result )
{
*a2 = 13;
childParse(a1, a2, parseIdentifier);
v4[0] = 0LL;
v5 = 0LL;
LODWORD(v4[0]) = 17;
v4[1] = 0LL;
v4[2] = 0LL;
parseFunctionType(a1, (__int64)v4);
addChild(a2);
childParse(a1, a2, parseBlock);
goto LABEL_3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int128 v4[3]; // [rsp+0h] [rbp-58h] BYREF
__int64 v5; // [rsp+30h] [rbp-28h]

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "struct") )
{
*a2 = 11;
childParse(a1, a2, parseIdentifier);
childParse(a1, a2, parseStructBody);
LABEL_3:
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
return 1LL;
}
if ( (unsigned __int8)readString(a1, "var") )
{
*a2 = 12;
func6(a1, a2);
if ( (unsigned __int8)readString(a1, "=") )
childParse(a1, a2, parseExpresion);
goto LABEL_3;
}
result = readString(a1, "function");
if ( (_BYTE)result )
{
*a2 = 13;
childParse(a1, a2, parseIdentifier);
v4[0] = 0LL;
v5 = 0LL;
LODWORD(v4[0]) = 17;
v4[1] = 0LL;
v4[2] = 0LL;
func7(a1, (__int64)v4);
addChild(a2);
childParse(a1, a2, parseBlock);
goto LABEL_3;
}
return result;
}

original_code:
_Bool parseDeclaration(Stream* s, Node* out)
{
 readWhitespace(s);
 int start=s->offset;
 if(readString(s,"struct"))
 {
  out->type = STRUCT_DECLARATION;
  childParse(s,out,parseIdentifier);
  childParse(s,out,parseStructBody);
 }
 else if(readString(s,"var"))
 {
  out->type = VARIABLE_DECLARATION;
  parseVariableDeclaration(s,out);
  if(readString(s,"="))
  {
   childParse(s,out,parseExpresion);
  }
 }
 else if(readString(s,"function"))
 {
  out->type = FUNCTION_DECLARATION;
  childParse(s,out,parseIdentifier);
  Node type={.type=FUNCTION_TYPE};
  parseFunctionType(s,&type);
  addChild(out,type);
  childParse(s,out,parseBlock);
 }
 else
 {
  return 0;
 }
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}

canonical_original_code:
_Bool parseDeclaration(struct Stream *s, struct Node *out)
{
 readWhitespace(s);
 int start = s->offset;
 if(readString(s,"struct"))
 {
  out->type = STRUCT_DECLARATION;
  childParse(s,out,parseIdentifier);
  childParse(s,out,parseStructBody);
 }
 else if(readString(s,"var"))
 {
  out->type = VARIABLE_DECLARATION;
  parseVariableDeclaration(s,out);
  if(readString(s,"="))
  {
   childParse(s,out,parseExpresion);
  }
 }
 else if(readString(s,"function"))
 {
  out->type = FUNCTION_DECLARATION;
  childParse(s,out,parseIdentifier);
  struct Node type = {.type=FUNCTION_TYPE};
  parseFunctionType(s,&type);
  addChild(out,type);
  childParse(s,out,parseBlock);
 }
 else
 {
  return 0;
 }
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}


parseStatement

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

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "if") )
{
*a2 = 19;
expect(a1, "(");
if ( !(unsigned __int8)childParse(a1, a2, parseExpresion) )
goto LABEL_15;
expect(a1, ")");
if ( !(unsigned __int8)childParse(a1, a2, parseStatement) )
{
LABEL_10:
panicStream(a1, "expected statement");
goto LABEL_11;
}
if ( !(unsigned __int8)readString(a1, "else") )
{
LABEL_5:
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
return 1LL;
}
LABEL_9:
if ( (unsigned __int8)childParse(a1, a2, parseStatement) )
goto LABEL_5;
goto LABEL_10;
}
if ( (unsigned __int8)readString(a1, "while") )
{
*a2 = 20;
expect(a1, "(");
if ( !(unsigned __int8)childParse(a1, a2, parseExpresion) )
goto LABEL_15;
LABEL_8:
expect(a1, ")");
goto LABEL_9;
}
LABEL_11:
if ( (unsigned __int8)readString(a1, "break") )
goto LABEL_12;
if ( (unsigned __int8)readString(a1, "continue") )
{
LABEL_14:
*a2 = 25;
goto LABEL_5;
}
while ( (unsigned __int8)readString(a1, "for") )
{
*a2 = 21;
expect(a1, "(");
if ( !(unsigned __int8)childParse(a1, a2, parseStatement) )
goto LABEL_10;
expect(a1, &asc_B84[3]);
if ( (unsigned __int8)childParse(a1, a2, parseExpresion) )
{
expect(a1, &asc_B84[3]);
if ( (unsigned __int8)childParse(a1, a2, parseStatement) )
goto LABEL_8;
goto LABEL_10;
}
LABEL_15:
panicStream(a1, "expected expresion");
}
if ( (unsigned __int8)readString(a1, "return") )
{
*a2 = 22;
childParse(a1, a2, parseExpresion);
goto LABEL_5;
}
if ( (unsigned __int8)readString(a1, "assert") )
{
*a2 = 23;
childParse(a1, a2, parseExpresion);
goto LABEL_5;
}
if ( (unsigned __int8)readString(a1, "break") )
{
LABEL_12:
*a2 = 24;
goto LABEL_5;
}
if ( (unsigned __int8)readString(a1, "continue") )
goto LABEL_14;
if ( (unsigned __int8)parseBlock(a1, a2) )
goto LABEL_5;
if ( (unsigned __int8)parseDeclaration(a1, a2) )
goto LABEL_5;
result = parseExpresion(a1, (__int64)a2);
if ( (_BYTE)result )
goto LABEL_5;
return result;
}

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

readWhitespace();
v2 = *(_DWORD *)(a1 + 4);
if ( (unsigned __int8)readString(a1, "if") )
{
*a2 = 19;
expect(a1, "(");
if ( !(unsigned __int8)childParse(a1, a2, parseExpresion) )
goto LABEL_15;
expect(a1, ")");
if ( !(unsigned __int8)childParse(a1, a2, parseStatement) )
{
LABEL_10:
panicStream(a1, "expected statement");
goto LABEL_11;
}
if ( !(unsigned __int8)readString(a1, "else") )
{
LABEL_5:
makeString(a1, v2, *(_DWORD *)(a1 + 4) - v2, a2 + 2);
return 1LL;
}
LABEL_9:
if ( (unsigned __int8)childParse(a1, a2, parseStatement) )
goto LABEL_5;
goto LABEL_10;
}
if ( (unsigned __int8)readString(a1, "while") )
{
*a2 = 20;
expect(a1, "(");
if ( !(unsigned __int8)childParse(a1, a2, parseExpresion) )
goto LABEL_15;
LABEL_8:
expect(a1, ")");
goto LABEL_9;
}
LABEL_11:
if ( (unsigned __int8)readString(a1, "break") )
goto LABEL_12;
if ( (unsigned __int8)readString(a1, "continue") )
{
LABEL_14:
*a2 = 25;
goto LABEL_5;
}
while ( (unsigned __int8)readString(a1, "for") )
{
*a2 = 21;
expect(a1, "(");
if ( !(unsigned __int8)childParse(a1, a2, parseStatement) )
goto LABEL_10;
expect(a1, &asc_B84[3]);
if ( (unsigned __int8)childParse(a1, a2, parseExpresion) )
{
expect(a1, &asc_B84[3]);
if ( (unsigned __int8)childParse(a1, a2, parseStatement) )
goto LABEL_8;
goto LABEL_10;
}
LABEL_15:
panicStream(a1, "expected expresion");
}
if ( (unsigned __int8)readString(a1, "return") )
{
*a2 = 22;
childParse(a1, a2, parseExpresion);
goto LABEL_5;
}
if ( (unsigned __int8)readString(a1, "assert") )
{
*a2 = 23;
childParse(a1, a2, parseExpresion);
goto LABEL_5;
}
if ( (unsigned __int8)readString(a1, "break") )
{
LABEL_12:
*a2 = 24;
goto LABEL_5;
}
if ( (unsigned __int8)readString(a1, "continue") )
goto LABEL_14;
if ( (unsigned __int8)func5(a1, a2) )
goto LABEL_5;
if ( (unsigned __int8)func9(a1, a2) )
goto LABEL_5;
result = func2(a1, (__int64)a2);
if ( (_BYTE)result )
goto LABEL_5;
return result;
}

original_code:
_Bool parseStatement(Stream* s, Node* out)
{
 readWhitespace(s);
 int start=s->offset;
 if(readString(s,"if"))
 {
  out->type=IF_STATEMENT;
  expect(s,"(");
  childParse(s,out,parseExpresion) ?0: panicStream(s,"expected expresion");
  expect(s,")");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  if(readString(s,"else"))
  {
   childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  }
 }
 else if(readString(s,"while"))
 {
  out->type=WHILE_STATEMENT;
  expect(s,"(");
  childParse(s,out,parseExpresion) ?0: panicStream(s,"expected expresion");
  expect(s,")");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
 }
 else if(readString(s,"break"))
 {
  out->type=BREAK_STATEMENT;
 }
 else if(readString(s,"continue"))
 {
  out->type=CONTINUE_STATEMENT;
 }
 else if(readString(s,"for"))
 {
  out->type=FOR_STATEMENT;
  expect(s,"(");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  expect(s,";");
  childParse(s,out,parseExpresion) ?0: panicStream(s,"expected expresion");
  expect(s,";");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  expect(s,")");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
 }
 else if(readString(s,"return"))
 {
  out->type=RETURN_STATEMENT;
  childParse(s,out,parseExpresion);
 }
 else if(readString(s,"assert"))
 {
  out->type=ASSERT_STATEMENT;
  childParse(s,out,parseExpresion);
 }
 else if(readString(s,"break"))
 {
  out->type=BREAK_STATEMENT;
 }
 else if(readString(s,"continue"))
 {
  out->type=CONTINUE_STATEMENT;
 }
 else if(parseBlock(s,out))
 {
 }
 else if(parseDeclaration(s, out))
 {
 }
 else if(parseExpresion(s,out))
 {
 }
 else
 {
  return 0;
 }
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}

canonical_original_code:
_Bool parseStatement(struct Stream *s, struct Node *out)
{
 readWhitespace(s);
 int start = s->offset;
 if(readString(s,"if"))
 {
  out->type=IF_STATEMENT;
  expect(s,"(");
  childParse(s,out,parseExpresion) ?0: panicStream(s,"expected expresion");
  expect(s,")");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  if(readString(s,"else"))
  {
   childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  }
 }
 else if(readString(s,"while"))
 {
  out->type=WHILE_STATEMENT;
  expect(s,"(");
  childParse(s,out,parseExpresion) ?0: panicStream(s,"expected expresion");
  expect(s,")");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
 }
 else if(readString(s,"break"))
 {
  out->type=BREAK_STATEMENT;
 }
 else if(readString(s,"continue"))
 {
  out->type=CONTINUE_STATEMENT;
 }
 else if(readString(s,"for"))
 {
  out->type=FOR_STATEMENT;
  expect(s,"(");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  expect(s,";");
  childParse(s,out,parseExpresion) ?0: panicStream(s,"expected expresion");
  expect(s,";");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
  expect(s,")");
  childParse(s,out,parseStatement) ?0: panicStream(s,"expected statement");
 }
 else if(readString(s,"return"))
 {
  out->type=RETURN_STATEMENT;
  childParse(s,out,parseExpresion);
 }
 else if(readString(s,"assert"))
 {
  out->type=ASSERT_STATEMENT;
  childParse(s,out,parseExpresion);
 }
 else if(readString(s,"break"))
 {
  out->type=BREAK_STATEMENT;
 }
 else if(readString(s,"continue"))
 {
  out->type=CONTINUE_STATEMENT;
 }
 else if(parseBlock(s,out))
 {
 }
 else if(parseDeclaration(s, out))
 {
 }
 else if(parseExpresion(s,out))
 {
 }
 else
 {
  return 0;
 }
 makeString(s, start, s->offset-start, &out->source);
 return 1;
}