decompiled_code:
void __fastcall hashtbl_destroy(void *ptr)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx
void *v4; // rdi

if ( *(_QWORD *)ptr )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v2);
while ( v3 )
{
free(*(void **)v3);
v4 = (void *)v3;
v3 = *(_QWORD *)(v3 + 16);
free(v4);
}
++v2;
}
while ( *(_QWORD *)ptr > v2 );
}
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx
void *v4; // rdi

if ( *(_QWORD *)ptr )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v2);
while ( v3 )
{
free(*(void **)v3);
v4 = (void *)v3;
v3 = *(_QWORD *)(v3 + 16);
free(v4);
}
++v2;
}
while ( *(_QWORD *)ptr > v2 );
}
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void hashtbl_destroy(HASHTBL *hashtbl)
{
    HSIZE n;
    ENTRY *node, *oldnode;
    for (n = 0; n < hashtbl->size; ++n) {
        node = hashtbl->nodes[n];
        while (node) {
            free(node->key);
            oldnode = node;
            node = node->next;
            free(oldnode);
        }
    }
    free(hashtbl->nodes);
    free(hashtbl);
}

canonical_original_code:
void hashtbl_destroy(struct hashtbl *hashtbl)
{
    unsigned long n;
    struct hashnode *node; struct hashnode *oldnode;
    for (n = 0; n < hashtbl->size; ++n) {
        node = hashtbl->nodes[n];
        while (node) {
            free(node->key);
            oldnode = node;
            node = node->next;
            free(oldnode);
        }
    }
    free(hashtbl->nodes);
    free(hashtbl);
}

variable_types: struct hashtbl { unsigned long size; unsigned long count; struct hashnode { char *key; void *data; struct hashnode *next; } **nodes; unsigned long (*hashfunc)(char *); } *

variable_types:
n
unsigned long

user_defined_types: struct hashtbl { unsigned long size; unsigned long count; struct hashnode **nodes; unsigned long (*hashfunc)(char *); }


repo: qzchenwl/hashtable

original_code:
int hashtbl_remove(HASHTBL *hashtbl, const char *key)
{
    ENTRY *node, *prevnode = ((void *)0);
    HSIZE hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            free(node->key);
            if (prevnode)
                prevnode->next = node->next;
            else
                hashtbl->nodes[hash] = node->next;
            free(node);
            hashtbl->count--;
            return 0;
        }
        prevnode = node;
        node = node->next;
    }
    return -1;
}

canonical_original_code:
int hashtbl_remove(struct hashtbl *hashtbl, char *key)
{
    struct hashnode *node; struct hashnode *prevnode = ((void *)0);
    unsigned long hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            free(node->key);
            if (prevnode)
                prevnode->next = node->next;
            else
                hashtbl->nodes[hash] = node->next;
            free(node);
            hashtbl->count--;
            return 0;
        }
        prevnode = node;
        node = node->next;
    }
    return -1;
}

variable_types:
key
char *

variable_types: struct hashnode { char *key; void *data; struct hashnode *next; } *

variable_types:
hash
unsigned long

return_type: int


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

v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16)
+ 8 * ((unsigned __int64)(*(__int64 (__fastcall **)(const char *))(a1 + 24))(a2) % *(_QWORD *)a1));
if ( v2 )
{
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
void *hashtbl_get(HASHTBL *hashtbl, const char *key)
{
    ENTRY *node;
    HSIZE hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            return node->data;
        }
        node = node->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *hashtbl_get(struct hashtbl *hashtbl, char *key)
{
    struct hashnode *node;
    unsigned long hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            return node->data;
        }
        node = node->next;
    }
    return ((void *)0);
}

return_type: void *

user_defined_types: struct hashnode { char *key; void *data; struct hashnode *next; }


original_code:
int hashtbl_resize(HASHTBL *hashtbl, HSIZE size)
{
    HASHTBL newtbl;
    HSIZE n;
    ENTRY *node,*next;
    newtbl.size = size;
    newtbl.count = 0;
    newtbl.hashfunc = hashtbl->hashfunc;
    if (!(newtbl.nodes = calloc(size, sizeof(ENTRY*))))
        return -1;
    for (n = 0; n < hashtbl->size; ++n) {
        for (node = hashtbl->nodes[n]; node; node = next) {
            next = node->next;
            hashtbl_insert(&newtbl, node->key, node->data);
            hashtbl_remove(hashtbl, node->key);
        }
    }
    free(hashtbl->nodes);
    hashtbl->size = newtbl.size;
    hashtbl->count = newtbl.count;
    hashtbl->nodes = newtbl.nodes;
    return 0;
}

canonical_original_code:
int hashtbl_resize(struct hashtbl *hashtbl, unsigned long size)
{
    struct hashtbl newtbl;
    unsigned long n;
    struct hashnode *node; struct hashnode *next;
    newtbl.size = size;
    newtbl.count = 0;
    newtbl.hashfunc = hashtbl->hashfunc;
    if (!(newtbl.nodes = calloc(size, sizeof(struct hashnode *))))
        return -1;
    for (n = 0; n < hashtbl->size; ++n) {
        for (node = hashtbl->nodes[n]; node; node = next) {
            next = node->next;
            hashtbl_insert(&newtbl, node->key, node->data);
            hashtbl_remove(hashtbl, node->key);
        }
    }
    free(hashtbl->nodes);
    hashtbl->size = newtbl.size;
    hashtbl->count = newtbl.count;
    hashtbl->nodes = newtbl.nodes;
    return 0;
}

variable_types:
size
unsigned long

variable_types: struct hashtbl { unsigned long size; unsigned long count; struct hashnode { char *key; void *data; struct hashnode *next; } **nodes; unsigned long (*hashfunc)(char *); }


original_code:
int hashtbl_insert(HASHTBL *hashtbl, const char *key, void *data)
{
    ENTRY *node;
    HSIZE hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            node->data = data;
            return 0;
        }
        node = node->next;
    }
    if (hashtbl->count >= hashtbl->size * 0.75) {
        hashtbl_resize(hashtbl, hashtbl->size * 2 + 1);
    }
    if (!(node = malloc(sizeof(ENTRY))))
        return -1;
    if (!(node->key = strdup(key))) {
        free(node);
        return -1;
    }
    node->data = data;
    node->next = hashtbl->nodes[hash];
    hashtbl->nodes[hash] = node;
    hashtbl->count++;
    return 0;
}

canonical_original_code:
int hashtbl_insert(struct hashtbl *hashtbl, char *key, void *data)
{
    struct hashnode *node;
    unsigned long hash = hashtbl->hashfunc(key) % hashtbl->size;
    node = hashtbl->nodes[hash];
    while (node) {
        if (!strcmp(node->key, key)) {
            node->data = data;
            return 0;
        }
        node = node->next;
    }
    if (hashtbl->count >= hashtbl->size * 0.75) {
        hashtbl_resize(hashtbl, hashtbl->size * 2 + 1);
    }
    if (!(node = malloc(sizeof(ENTRY))))
        return -1;
    if (!(node->key = strdup(key))) {
        free(node);
        return -1;
    }
    node->data = data;
    node->next = hashtbl->nodes[hash];
    hashtbl->nodes[hash] = node;
    hashtbl->count++;
    return 0;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall hash_func(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
do
{
++a1;
v2 += v1;
v1 = *a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
do
{
++a1;
v2 += v1;
v1 = *a1;
}
while ( *a1 );
return v2;
}

original_code:
HSIZE hash_func(const char *key) {
    HSIZE hash = 0;
    while (*key)
        hash += (*key++);
    return hash;
}

canonical_original_code:
unsigned long hash_func(char *key) {
    unsigned long hash = 0;
    while (*key)
        hash += (*key++);
    return hash;
}

return_type: unsigned long


help

decompiled_code:
int __fastcall help(__int64 a1, const char **a2)
{
return printf("%s <table size> <element count>\n", *a2);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, const char **a2)
{
return printf("%s <table size> <element count>\n", *a2);
}

original_code:
void help(int argc, char *argv[])
{
    printf("%s <table size> <element count>\n", argv[0]);
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: void


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned __int64 v4; // r13
_QWORD *v5; // r14
unsigned __int64 *v6; // r12
unsigned __int64 v7; // rbx
unsigned int v8; // ebp
const char *v9; // rsi
int v10; // eax
_BYTE *v11; // rax
unsigned __int64 v12; // r13
unsigned int v13; // ebp
__int64 v14; // rbx
size_t n[6]; // [rsp+4h] [rbp-34h] BYREF

*(size_t *)((char *)n + 4) = 0LL;
LODWORD(n[0]) = 0;
if ( argc )
{
if ( argc != 3 )
{
help(*(__int64 *)&argc, argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = malloc(0x18uLL);
v6 = hashtbl_create(v3, 0LL);
printf("tbl = %p\n", v6);
if ( v4 <= 1 )
{
v8 = 0;
goto LABEL_14;
}
}
else
{
v5 = malloc(0x18uLL);
v6 = hashtbl_create(0x3F5uLL, 0LL);
printf("tbl = %p\n", v6);
v4 = 1000LL;
}
v7 = 1LL;
v8 = 0;
do
{
v10 = getline((char **)((char *)n + 4), n, stdin);
if ( v10 == -1 )
{
fwrite("getline() failed\n", 1uLL, 0x11uLL, stderr);
}
else
{
if ( v10 > 0 )
{
v11 = (_BYTE *)(*(size_t *)((char *)n + 4) + v10 - 1);
if ( *v11 == 10 )
*v11 = 0;
}
v9 = *(const char **)((char *)n + 4);
*v5 = *(size_t *)((char *)n + 4);
hashtbl_insert((__int64)v6, v9, v7);
++v8;
}
++v7;
}
while ( v4 > v7 );
LABEL_14:
printf("insert %d elements\n", v8);
printf("ele cnt = %d\n", v6[1]);
hashtbl_remove((__int64)v6, "www.domain3912.com");
hashtbl_remove((__int64)v6, "www.domain92492.com");
hashtbl_remove((__int64)v6, "www.domain77224.com");
hashtbl_remove((__int64)v6, "www.domain68464.com");
hashtbl_remove((__int64)v6, "www.domain12497.com");
hashtbl_remove((__int64)v6, "www.domain43997.com");
printf("ele cnt = %d\n", v6[1]);
if ( *v6 )
{
v12 = 0LL;
v13 = 0;
do
{
v14 = *(_QWORD *)(v6[2] + 8 * v12);
if ( v14 )
{
--v13;
do
{
fprintf(stderr, "%s:%d\n", *(const char **)v14, *(unsigned int *)(v14 + 8));
++v13;
v14 = *(_QWORD *)(v14 + 16);
}
while ( v14 );
}
++v12;
}
while ( *v6 > v12 );
}
else
{
v13 = 0;
}
printf("tbl %d collisions\n", v13);
hashtbl_dump(v6);
if ( *(size_t *)((char *)n + 4) )
free(*(void **)((char *)n + 4));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned __int64 v4; // r13
_QWORD *v5; // r14
unsigned __int64 *v6; // r12
unsigned __int64 v7; // rbx
unsigned int v8; // ebp
const char *v9; // rsi
int v10; // eax
_BYTE *v11; // rax
unsigned __int64 v12; // r13
unsigned int v13; // ebp
__int64 v14; // rbx
size_t n[6]; // [rsp+4h] [rbp-34h] BYREF

*(size_t *)((char *)n + 4) = 0LL;
LODWORD(n[0]) = 0;
if ( argc )
{
if ( argc != 3 )
{
func15(*(__int64 *)&argc, argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = malloc(0x18uLL);
v6 = hashtbl_create(v3, 0LL);
printf("tbl = %p\n", v6);
if ( v4 <= 1 )
{
v8 = 0;
goto LABEL_14;
}
}
else
{
v5 = malloc(0x18uLL);
v6 = hashtbl_create(0x3F5uLL, 0LL);
printf("tbl = %p\n", v6);
v4 = 1000LL;
}
v7 = 1LL;
v8 = 0;
do
{
v10 = getline((char **)((char *)n + 4), n, stdin);
if ( v10 == -1 )
{
fwrite("getline() failed\n", 1uLL, 0x11uLL, stderr);
}
else
{
if ( v10 > 0 )
{
v11 = (_BYTE *)(*(size_t *)((char *)n + 4) + v10 - 1);
if ( *v11 == 10 )
*v11 = 0;
}
v9 = *(const char **)((char *)n + 4);
*v5 = *(size_t *)((char *)n + 4);
func12((__int64)v6, v9, v7);
++v8;
}
++v7;
}
while ( v4 > v7 );
LABEL_14:
printf("insert %d elements\n", v8);
printf("ele cnt = %d\n", v6[1]);
func9((__int64)v6, "www.domain3912.com");
func9((__int64)v6, "www.domain92492.com");
func9((__int64)v6, "www.domain77224.com");
func9((__int64)v6, "www.domain68464.com");
func9((__int64)v6, "www.domain12497.com");
func9((__int64)v6, "www.domain43997.com");
printf("ele cnt = %d\n", v6[1]);
if ( *v6 )
{
v12 = 0LL;
v13 = 0;
do
{
v14 = *(_QWORD *)(v6[2] + 8 * v12);
if ( v14 )
{
--v13;
do
{
fprintf(stderr, "%s:%d\n", *(const char **)v14, *(unsigned int *)(v14 + 8));
++v13;
v14 = *(_QWORD *)(v14 + 16);
}
while ( v14 );
}
++v12;
}
while ( *v6 > v12 );
}
else
{
v13 = 0;
}
printf("tbl %d collisions\n", v13);
func13(v6);
if ( *(size_t *)((char *)n + 4) )
free(*(void **)((char *)n + 4));
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
    HASHTBL *tbl;
    ENTRY *entry;
    HSIZE tblsiz, elecnt;
    char *line = ((void *)0);
    int ret, i, cnt, len = 0;
    if (argc == 0) {
        tblsiz = 1013;
        elecnt = 1000;
    }
    else if (argc != 3) {
        help(argc, argv);
        exit(1);
    }
    else {
        tblsiz = atoi(argv[1]);
        elecnt = atoi(argv[2]);
    }
    entry = malloc(sizeof(ENTRY));
    tbl = hashtbl_create(tblsiz, ((void *)0));
    printf("tbl = %p\n", tbl);
    for (i = 1, cnt = 0; i < elecnt; ++i) {
        if ( (ret = getline(&line, &len, stdin)) == -1) {
            fprintf(stderr, "getline() failed\n");
            continue;
        }
        if ( ret > 0 && line[ret-1] == '\n')
            line[ret-1] = '\0';
        entry->key = line;
        hashtbl_insert(tbl, entry->key, (void*)i);
        ++cnt;
    }
    printf("insert %d elements\n", cnt);
    printf("ele cnt = %d\n", tbl->count);
    hashtbl_remove(tbl, "www.domain3912.com");
    hashtbl_remove(tbl, "www.domain92492.com");
    hashtbl_remove(tbl, "www.domain77224.com");
    hashtbl_remove(tbl, "www.domain68464.com");
    hashtbl_remove(tbl, "www.domain12497.com");
    hashtbl_remove(tbl, "www.domain43997.com");
    printf("ele cnt = %d\n", tbl->count);
    for (i = 0, cnt = 0; i < tbl->size; ++i) {
        entry = tbl->nodes[i];
        if (entry)
            --cnt;
        while (entry) {
            fprintf(stderr, "%s:%d\n", entry->key, (int)entry->data);
            ++cnt;
            entry = entry->next;
        }
    }
    printf("tbl %d collisions\n", cnt);
    hashtbl_dump(tbl, stdout);
    if (line)
        free(line);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct hashtbl *tbl;
    struct hashnode *entry;
    unsigned long tblsiz; unsigned long elecnt;
    char *line = ((void *)0);
    int ret; int i; int cnt; int len = 0;
    if (argc == 0) {
        tblsiz = 1013;
        elecnt = 1000;
    }
    else if (argc != 3) {
        help(argc, argv);
        exit(1);
    }
    else {
        tblsiz = atoi(argv[1]);
        elecnt = atoi(argv[2]);
    }
    entry = malloc(sizeof(ENTRY));
    tbl = hashtbl_create(tblsiz, ((void *)0));
    printf("tbl = %p\n", tbl);
    for (i = 1, cnt = 0; i < elecnt; ++i) {
        if ( (ret = getline(&line, &len, stdin)) == -1) {
            fprintf(stderr, "getline() failed\n");
            continue;
        }
        if ( ret > 0 && line[ret-1] == '\n')
            line[ret-1] = '\0';
        entry->key = line;
        hashtbl_insert(tbl, entry->key, (void *)i);
        ++cnt;
    }
    printf("insert %d elements\n", cnt);
    printf("ele cnt = %d\n", tbl->count);
    hashtbl_remove(tbl, "www.domain3912.com");
    hashtbl_remove(tbl, "www.domain92492.com");
    hashtbl_remove(tbl, "www.domain77224.com");
    hashtbl_remove(tbl, "www.domain68464.com");
    hashtbl_remove(tbl, "www.domain12497.com");
    hashtbl_remove(tbl, "www.domain43997.com");
    printf("ele cnt = %d\n", tbl->count);
    for (i = 0, cnt = 0; i < tbl->size; ++i) {
        entry = tbl->nodes[i];
        if (entry)
            --cnt;
        while (entry) {
            fprintf(stderr, "%s:%d\n", entry->key, (int)entry->data);
            ++cnt;
            entry = entry->next;
        }
    }
    printf("tbl %d collisions\n", cnt);
    hashtbl_dump(tbl, stdout);
    if (line)
        free(line);
    return 0;
}

variable_types:
tblsiz
unsigned long

variable_types:
elecnt
unsigned long

variable_types:
line
char *

variable_types: ret int

variable_types: i int

variable_types: cnt int

variable_types: len int


decompiled_code:
int thread_setup()
{
lock_cs = (pthread_mutex_t *)CRYPTO_malloc(40LL, "fuzz.c", 293LL);
lock_count = CRYPTO_malloc(8LL, "fuzz.c", 294LL);
*(_QWORD *)lock_count = 0LL;
return pthread_mutex_init(lock_cs, 0LL);
}

canonical_decompiled_code:
int func2()
{
lock_cs = (pthread_mutex_t *)CRYPTO_malloc(40LL, "fuzz.c", 293LL);
lock_count = CRYPTO_malloc(8LL, "fuzz.c", 294LL);
*(_QWORD *)lock_count = 0LL;
return pthread_mutex_init(lock_cs, 0LL);
}

original_code:
void thread_setup(void)
{
 int i;
 lock_cs=CRYPTO_malloc((1) * sizeof(pthread_mutex_t), "fuzz.c", 293);
 lock_count=CRYPTO_malloc((1) * sizeof(long), "fuzz.c", 294);
 for (i=0; i<(1); i++)
 {
  lock_count[i]=0;
  pthread_mutex_init(&(lock_cs[i]),((void *)0));
 }
 ;
 ;
}

canonical_original_code:
void thread_setup()
{
 int i;
 lock_cs=CRYPTO_malloc((1) * sizeof(pthread_mutex_t), "fuzz.c", 293);
 lock_count=CRYPTO_malloc((1) * sizeof(long), "fuzz.c", 294);
 for (i=0; i<(1); i++)
 {
  lock_count[i]=0;
  pthread_mutex_init(&(lock_cs[i]),((void *)0));
 }
 ;
 ;
}


decompiled_code:
pthread_t pthreads_thread_id()
{
return pthread_self();
}

canonical_decompiled_code:
pthread_t func3()
{
return pthread_self();
}

original_code:
unsigned long pthreads_thread_id(void)
{
 unsigned long ret;
 ret=(unsigned long)pthread_self();
 return(ret);
}

canonical_original_code:
unsigned long pthreads_thread_id()
{
 unsigned long ret;
 ret=(unsigned long)pthread_self();
 return(ret);
}

variable_types:
ret
unsigned long


decompiled_code:
int __fastcall pthreads_locking_callback(char a1, int a2)
{
int result; // eax

if ( (a1 & 1) == 0 )
return pthread_mutex_unlock(&lock_cs[a2]);
pthread_mutex_lock(&lock_cs[a2]);
result = lock_count;
++*(_QWORD *)(lock_count + 8LL * a2);
return result;
}

canonical_decompiled_code:
int __fastcall func4(char a1, int a2)
{
int result; // eax

if ( (a1 & 1) == 0 )
return pthread_mutex_unlock(&lock_cs[a2]);
pthread_mutex_lock(&lock_cs[a2]);
result = lock_count;
++*(_QWORD *)(lock_count + 8LL * a2);
return result;
}

original_code:
void pthreads_locking_callback(int mode, int type, char *file, int line)
{
 if (mode & 1)
 {
  pthread_mutex_lock(&(lock_cs[type]));
  lock_count[type]++;
 }
 else
  pthread_mutex_unlock(&(lock_cs[type]));
}

variable_types: mode int

variable_types: type int

variable_types:
file
char *

variable_types: line int


decompiled_code:
__int64 pthread_cleanup()
{
pthread_mutex_t *v0; // rbx

v0 = lock_cs;
pthread_mutex_destroy(lock_cs);
CRYPTO_free(v0, "fuzz.c", 331LL);
return CRYPTO_free(lock_count, "fuzz.c", 332LL);
}

canonical_decompiled_code:
__int64 func5()
{
pthread_mutex_t *v0; // rbx

v0 = lock_cs;
pthread_mutex_destroy(lock_cs);
CRYPTO_free(v0, "fuzz.c", 331LL);
return CRYPTO_free(lock_count, "fuzz.c", 332LL);
}

original_code:
void pthread_cleanup(void)
{
 int i;
 ;
 for (i=0; i<(1); i++)
  pthread_mutex_destroy(&(lock_cs[i]));
 CRYPTO_free(lock_cs, "fuzz.c", 331);
 CRYPTO_free(lock_count, "fuzz.c", 332);
}

canonical_original_code:
void pthread_cleanup()
{
 int i;
 ;
 for (i=0; i<(1); i++)
  pthread_mutex_destroy(&(lock_cs[i]));
 CRYPTO_free(lock_cs, "fuzz.c", 331);
 CRYPTO_free(lock_count, "fuzz.c", 332);
}


initssl

decompiled_code:
__int64 initssl()
{
CRYPTO_malloc_init();
OPENSSL_init_ssl(0LL, 0LL);
return OPENSSL_init_ssl(2097154LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
CRYPTO_malloc_init();
OPENSSL_init_ssl(0LL, 0LL);
return OPENSSL_init_ssl(2097154LL, 0LL);
}

original_code:
void initssl()
{
 CRYPTO_malloc_init();
 OPENSSL_init_ssl(0, ((void *)0));
 OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
}


original_code:
unsigned int base64decode(char *buffer)
{
 uint8_t car, i;
 char valcar[4];
 unsigned int pos_src, pos_dst;
 pos_src = 0;
 pos_dst = 0;
 while (buffer[pos_src] > ' ' && buffer[pos_src] != '=')
 {
  for (i = 0; i < 4 && buffer[pos_src] != '='; i++)
  {
   car = buffer[pos_src++];
   if ('A' <= car && car <= 'Z')
    valcar[i] = car - 'A';
   else if ('a' <= car && car <= 'z')
    valcar[i] = car + 26 - 'a';
   else if ('0' <= car && car <= '9')
    valcar[i] = car + 52 - '0';
   else if (car == '+')
    valcar[i] = 62;
   else if (car == '/')
    valcar[i] = 63;
  }
  buffer[pos_dst++] = (valcar[0] << 2) | (valcar[1] >> 4);
  if (i > 2)
  {
   buffer[pos_dst++] = (valcar[1] << 4) | (valcar[2] >> 2);
   if (i > 3)
    buffer[pos_dst++] = (valcar[2] << 6) | (valcar[3]);
  }
 }
 buffer[pos_dst] = '\0';
 return (pos_dst);
}

canonical_original_code:
unsigned int base64decode(char *buffer)
{
 unsigned char car; unsigned char i;
 char valcar[4];
 unsigned int pos_src; unsigned int pos_dst;
 pos_src = 0;
 pos_dst = 0;
 while (buffer[pos_src] > ' ' && buffer[pos_src] != '=')
 {
  for (i = 0; i < 4 && buffer[pos_src] != '='; i++)
  {
   car = buffer[pos_src++];
   if ('A' <= car && car <= 'Z')
    valcar[i] = car - 'A';
   else if ('a' <= car && car <= 'z')
    valcar[i] = car + 26 - 'a';
   else if ('0' <= car && car <= '9')
    valcar[i] = car + 52 - '0';
   else if (car == '+')
    valcar[i] = 62;
   else if (car == '/')
    valcar[i] = 63;
  }
  buffer[pos_dst++] = (valcar[0] << 2) | (valcar[1] >> 4);
  if (i > 2)
  {
   buffer[pos_dst++] = (valcar[1] << 4) | (valcar[2] >> 2);
   if (i > 3)
    buffer[pos_dst++] = (valcar[2] << 6) | (valcar[3]);
  }
 }
 buffer[pos_dst] = '\0';
 return (pos_dst);
}

variable_types:
buffer
char *

variable_types:
car
unsigned char

variable_types:
i
unsigned char

variable_types:
valcar
char [4]

return_type: unsigned int


urlencode

original_code:
void urlencode( char *src, char **dst, unsigned int size, int type )
{
 unsigned int i,j=0;
 unsigned char c;
 char newchar[4];
 char newdst[2048];
 if(type > 2)
  return;
 for(i=0; i< size && j<(2048 -1); i++)
 {
  c=src[i];
  if( (c < 48 ) || (c> 57 && c< 65) || (c > 90 && c < 97) || (c > 122 && c < 128))
  {
   if(type==2 && c==32)
   {
    newdst[j++]='+';
   }
   else
   {
    sprintf(newchar,"\%%%2x",c);
    newdst[j]=newchar[0];
    newdst[j+1]=newchar[1];
    newdst[j+2]=newchar[2];
    j=j+3;
   }
  }
  else
  {
   newdst[j]=c;
   j++;
  }
 }
 if(j<(2048 -1))
  newdst[j]='\0';
 else
  newdst[j-1]='\0';
 *dst=realloc(*dst, strlen(newdst)+1);
if(*dst==((void *)0))
{
 printf("\n Realloc failed \n");
 exit(0);
}
 strcpy(*dst,newdst);
}

canonical_original_code:
void urlencode(char *src, char **dst, unsigned int size, int type)
{
 unsigned int i; unsigned int j = 0;
 unsigned char c;
 char newchar[4];
 char newdst[2048];
 if(type > 2)
  return;
 for(i=0; i< size && j<(2048 -1); i++)
 {
  c=src[i];
  if( (c < 48 ) || (c> 57 && c< 65) || (c > 90 && c < 97) || (c > 122 && c < 128))
  {
   if(type==2 && c==32)
   {
    newdst[j++]='+';
   }
   else
   {
    sprintf(newchar,"\%%%2x",c);
    newdst[j]=newchar[0];
    newdst[j+1]=newchar[1];
    newdst[j+2]=newchar[2];
    j=j+3;
   }
  }
  else
  {
   newdst[j]=c;
   j++;
  }
 }
 if(j<(2048 -1))
  newdst[j]='\0';
 else
  newdst[j-1]='\0';
 *dst=realloc(*dst, strlen(newdst)+1);
if(*dst==((void *)0))
{
 printf("\n Realloc failed \n");
 exit(0);
}
 strcpy(*dst,newdst);
}

variable_types:
src
char *

variable_types:
dst
char **

variable_types:
size
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
c
unsigned char

variable_types:
newchar
char [4]

variable_types:
newdst
char [2048]


delnewline

decompiled_code:
char *__fastcall delnewline(char *s)
{
char *result; // rax

result = strchr(s, 13);
if ( result )
{
*result = 0;
LABEL_3:
*result = 0;
return result;
}
result = strchr(s, 10);
if ( result )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
char *result; // rax

result = strchr(s, 13);
if ( result )
{
*result = 0;
LABEL_3:
*result = 0;
return result;
}
result = strchr(s, 10);
if ( result )
goto LABEL_3;
return result;
}

original_code:
void delnewline(char *string)
{
   char *p = strchr(string, '\r');
   if (p)
        *p = 0;
 else
  p = strchr(string, '\n');
 if(p)
  *p = 0;
}

variable_types:
string
char *

variable_types:
p
char *


decompiled_code:
__time_t __fastcall path_mtime(char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = (unsigned int)stat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = v3.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func6(char *a1)
{
bool v1; // zf
__time_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = (unsigned int)func10(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = v3.st_mtim.tv_sec;
return result;
}

original_code:
time_t path_mtime(const char *path)
{
     struct stat s;
     time_t mtime = 0;
     int ret;
     ret = stat(path, &s);
     if(ret == 0) {
        mtime = s.st_mtim.tv_sec;
     }
     return mtime;
}

canonical_original_code:
long path_mtime(char *path)
{
     struct stat s;
     long mtime = 0;
     int ret;
     ret = stat(path, &s);
     if(ret == 0) {
        mtime = s.st_mtim.tv_sec;
     }
     return mtime;
}

variable_types:
path
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: mtime long

variable_types: ret int

return_type: long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall cmp_mtime(const void *a1, const void *a2)
{
__int64 v2; // rbx
__int64 v3; // rax
unsigned int v4; // edx

v2 = path_mtime(*(_QWORD *)a1);
v3 = path_mtime(*(_QWORD *)a2);
v4 = -1;
if ( v2 >= v3 )
v4 = v2 > v3;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
__int64 v2; // rbx
__int64 v3; // rax
unsigned int v4; // edx

v2 = func6(*(_QWORD *)a1);
v3 = func6(*(_QWORD *)a2);
v4 = -1;
if ( v2 >= v3 )
v4 = v2 > v3;
return v4;
}

original_code:
static int cmp_mtime(const void *p1, const void *p2)
{
       int ret = 0;
       time_t m1 = path_mtime(* (char * const *) p1);
       time_t m2 = path_mtime(* (char * const *) p2);
       if( m1 > m2)
           ret = 1;
       if( m1 < m2)
           ret = -1;
       return ret;
}

canonical_original_code:
static int cmp_mtime(void *p1, void *p2)
{
       int ret = 0;
       long m1 = path_mtime(* (char * const *) p1);
       long m2 = path_mtime(* (char * const *) p2);
       if( m1 > m2)
           ret = 1;
       if( m1 < m2)
           ret = -1;
       return ret;
}


getenv

decompiled_code:
__int64 __fastcall getenv(const char *a1)
{
bool v2; // cf
bool v3; // zf
__int64 v4; // rcx
const char *v5; // rdi
const char *v6; // rsi
__int64 result; // rax

o_dl_0 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "getenv");
v4 = 14LL;
v5 = "SSH_AUTH_SOCK";
v6 = a1;
do
{
if ( !v4 )
break;
v2 = *v6 < (unsigned int)*v5;
v3 = *v6++ == *v5++;
--v4;
}
while ( v3 );
if ( (!v2 && !v3) != v2 || (result = latest_ssh_auth_sock(v5, v6)) == 0 )
result = o_dl_0(a1, v6);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
bool v2; // cf
bool v3; // zf
__int64 v4; // rcx
const char *v5; // rdi
const char *v6; // rsi
__int64 result; // rax

o_dl_0 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "getenv");
v4 = 14LL;
v5 = "SSH_AUTH_SOCK";
v6 = a1;
do
{
if ( !v4 )
break;
v2 = *v6 < (unsigned int)*v5;
v3 = *v6++ == *v5++;
--v4;
}
while ( v3 );
if ( (!v2 && !v3) != v2 || (result = func8(v5, v6)) == 0 )
result = o_dl_0(a1, v6);
return result;
}

original_code:
char *getenv(const char *name)
{
   static char* (*o_dl)(const char *name) = 0;
   char *new_sock;
   o_dl = (char*(*)(const char *name)) dlsym(((void *) -1l),"getenv");
   if(strcmp(name, "SSH_AUTH_SOCK") == 0) {
       new_sock = latest_ssh_auth_sock();
       if(new_sock != ((void *)0)) {
           return new_sock;
       }
   }
   return (*o_dl)(name);
}

canonical_original_code:
char *getenv(char *name)
{
   static char *(*o_dl)(char *name) = 0;
   char *new_sock;
   o_dl = (char *(*)(char *name)) dlsym(((void *) -1l),"getenv");
   if(strcmp(name, "SSH_AUTH_SOCK") == 0) {
       new_sock = latest_ssh_auth_sock();
       if(new_sock != ((void *)0)) {
           return new_sock;
       }
   }
   return (*o_dl)(name);
}

variable_types:
name
char *

return_type: char *


odd

decompiled_code:
__int64 __fastcall odd(char a1)
{
return a1 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return a1 & 1;
}

original_code:
int
odd(int n)
{
 return (n&1);
}

canonical_original_code:
int odd(int n)
{
 return (n&1);
}

variable_types: n int


even

decompiled_code:
_BOOL8 __fastcall even(char a1)
{
return (a1 & 1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
return (a1 & 1) == 0;
}

original_code:
int
even(int n)
{
 return (!(n&1));
}

canonical_original_code:
int even(int n)
{
 return (!(n&1));
}


decompiled_code:
__int64 __fastcall strstr_count(char *haystack, char *needle)
{
size_t v2; // r12
char *v3; // rax
unsigned int v4; // ebx
size_t v5; // r12

if ( !needle || !haystack )
return 0;
v2 = strlen(needle);
v3 = strstr(haystack, needle);
if ( !v3 )
return 0;
v4 = 0;
v5 = v2 - 1;
do
{
++v4;
v3 = strstr(&v3[v5], needle);
}
while ( v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *haystack, char *needle)
{
size_t v2; // r12
char *v3; // rax
unsigned int v4; // ebx
size_t v5; // r12

if ( !needle || !haystack )
return 0;
v2 = strlen(needle);
v3 = strstr(haystack, needle);
if ( !v3 )
return 0;
v4 = 0;
v5 = v2 - 1;
do
{
++v4;
v3 = strstr(&v3[v5], needle);
}
while ( v3 );
return v4;
}

original_code:
int
strstr_count(char *s, char *t)
{
 int n=0;
 size_t len;
 char *p;
 if (t==((void *)0) || s==((void *)0)) return n;
 len = strlen(t);
 p = strstr(s,t);
 while (p) {
  n++;
  p = strstr(p+len-1,t);
 }
 return n;
}

canonical_original_code:
int strstr_count(char *s, char *t)
{
 int n = 0;
 unsigned long len;
 char *p;
 if (t==((void *)0) || s==((void *)0)) return n;
 len = strlen(t);
 p = strstr(s,t);
 while (p) {
  n++;
  p = strstr(p+len-1,t);
 }
 return n;
}

variable_types:
s
char *

variable_types:
t
char *

variable_types:
len
unsigned long


decompiled_code:
char *__fastcall my_strndup(char *src, size_t n)
{
char *v2; // rax
char *v3; // rbx

v2 = (char *)calloc(n + 1, 1uLL);
v3 = v2;
if ( v2 )
strncpy(v2, src, n);
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(char *src, size_t n)
{
char *v2; // rax
char *v3; // rbx

v2 = (char *)calloc(n + 1, 1uLL);
v3 = v2;
if ( v2 )
strncpy(v2, src, n);
return v3;
}

original_code:
char *
my_strndup(char *src, size_t n)
{
 char *dst;
 dst = (char *) calloc(n+1,sizeof(char));
 if (dst==((void *)0)) return ((void *)0);
 strncpy(dst,src,n);
 return dst;
}

canonical_original_code:
char *my_strndup(char *src, unsigned long n)
{
 char *dst;
 dst = (char *) calloc(n+1,sizeof(char));
 if (dst==((void *)0)) return ((void *)0);
 strncpy(dst,src,n);
 return dst;
}

variable_types:
src
char *

variable_types:
n
unsigned long

variable_types:
dst
char *


decompiled_code:
char *__fastcall strdup_together(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx

if ( src )
{
if ( a2 )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
if ( !v4 )
diagnostics(0LL, "Could not allocate memory for both strings.");
strcpy(v4, src);
strcat(v4, a2);
}
else
{
v4 = (char *)my_strdup(src);
}
}
else
{
v4 = a2;
if ( a2 )
v4 = (char *)my_strdup(a2);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func4(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx

if ( src )
{
if ( a2 )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
if ( !v4 )
diagnostics(0LL, "Could not allocate memory for both strings.");
strcpy(v4, src);
strcat(v4, a2);
}
else
{
v4 = (char *)my_strdup(src);
}
}
else
{
v4 = a2;
if ( a2 )
v4 = (char *)my_strdup(a2);
}
return v4;
}

original_code:
char *
strdup_together(char *s, char *t)
{
 char * both;
 if (s==((void *)0)) {
  if (t==((void *)0)) return ((void *)0);
  return my_strdup(t);
 }
 if (t==((void *)0))
  return my_strdup(s);
 both = malloc(strlen(s) + strlen(t) + 1);
 if (both == ((void *)0))
  diagnostics(0, "Could not allocate memory for both strings.");
 strcpy(both, s);
 strcat(both, t);
 return both;
}

canonical_original_code:
char *strdup_together(char *s, char *t)
{
 char *both;
 if (s==((void *)0)) {
  if (t==((void *)0)) return ((void *)0);
  return my_strdup(t);
 }
 if (t==((void *)0))
  return my_strdup(s);
 both = malloc(strlen(s) + strlen(t) + 1);
 if (both == ((void *)0))
  diagnostics(0, "Could not allocate memory for both strings.");
 strcpy(both, s);
 strcat(both, t);
 return both;
}

variable_types:
both
char *


original_code:
char *
strdup_noblanks(char *s)
{
char *p, *dup;
 if (s==((void *)0)) return ((void *)0);
 while (*s == ' ' || *s == '\n') s++;
 dup = malloc(strlen(s) + 1);
 p = dup;
 while (*s) {
  *p = *s;
  if (*p != ' ' && *p != '\n') p++;
  s++;
 }
 *p = '\0';
 return dup;
}

canonical_original_code:
char *strdup_noblanks(char *s)
{
char *p; char *dup;
 if (s==((void *)0)) return ((void *)0);
 while (*s == ' ' || *s == '\n') s++;
 dup = malloc(strlen(s) + 1);
 p = dup;
 while (*s) {
  *p = *s;
  if (*p != ' ' && *p != '\n') p++;
  s++;
 }
 *p = '\0';
 return dup;
}

variable_types:
dup
char *


decompiled_code:
char *__fastcall strdup_nobadchars(char *a1)
{
char *v1; // rsi
char v2; // al
char *v3; // rcx

v1 = strdup_noblanks(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)((v2 & 0xDF) - 65) > 0x19u && (unsigned __int8)(v2 - 48) > 9u )
*v3 = 95;
v2 = *++v3;
}
while ( *v3 );
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func7(char *a1)
{
char *v1; // rsi
char v2; // al
char *v3; // rcx

v1 = func6(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)((v2 & 0xDF) - 65) > 0x19u && (unsigned __int8)(v2 - 48) > 9u )
*v3 = 95;
v2 = *++v3;
}
while ( *v3 );
}
return v1;
}

original_code:
char *
strdup_nobadchars(char * text)
{
 char *dup, *s;
 dup = strdup_noblanks(text);
 s = dup;
 while (*s) {
  if (!('a' <= *s && *s <= 'z') &&
      !('A' <= *s && *s <= 'Z') &&
      !('0' <= *s && *s <= '9'))
   *s = '_';
  s++;
 }
 return dup;
}

canonical_original_code:
char *strdup_nobadchars(char *text)
{
 char *dup; char *s;
 dup = strdup_noblanks(text);
 s = dup;
 while (*s) {
  if (!('a' <= *s && *s <= 'z') &&
      !('A' <= *s && *s <= 'Z') &&
      !('0' <= *s && *s <= '9'))
   *s = '_';
  s++;
 }
 return dup;
}

variable_types:
text
char *


decompiled_code:
char *__fastcall strdup_noendblanks(char *src)
{
char v1; // al
char *v2; // rbx
char *v3; // rsi
char *result; // rax

if ( !src )
return 0LL;
v1 = *src;
if ( !*src )
goto LABEL_9;
if ( v1 == 32 || (v2 = src, v1 == 10) )
{
v2 = src;
do
{
do
++v2;
while ( *v2 == 32 );
}
while ( *v2 == 10 );
}
v3 = &src[strlen(src) - 1];
if ( v3 < v2 )
goto LABEL_9;
while ( *v3 == 32 || *v3 == 10 )
{
if ( --v3 < v2 )
goto LABEL_9;
}
if ( v3 >= v2 )
result = my_strndup(v2, v3 - v2 + 1);
else
LABEL_9:
result = (char *)my_strdup(&unk_4D4);
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
char v1; // al
char *v2; // rbx
char *v3; // rsi
char *result; // rax

if ( !src )
return 0LL;
v1 = *src;
if ( !*src )
goto LABEL_9;
if ( v1 == 32 || (v2 = src, v1 == 10) )
{
v2 = src;
do
{
do
++v2;
while ( *v2 == 32 );
}
while ( *v2 == 10 );
}
v3 = &src[strlen(src) - 1];
if ( v3 < v2 )
goto LABEL_9;
while ( *v3 == 32 || *v3 == 10 )
{
if ( --v3 < v2 )
goto LABEL_9;
}
if ( v3 >= v2 )
result = func3(v2, v3 - v2 + 1);
else
LABEL_9:
result = (char *)my_strdup(&unk_4D4);
return result;
}

original_code:
char *
strdup_noendblanks(char * s)
{
char *p, *t;
 if (s==((void *)0)) return ((void *)0);
 if (*s=='\0') return my_strdup("");
 t=s;
 while (*t == ' ' || *t == '\n') t++;
 p = s + strlen(s) -1;
 while (p >= t && (*p == ' ' || *p == '\n')) p--;
 if (t>p) return my_strdup("");
 return my_strndup(t,(size_t) (p-t+1));
}

canonical_original_code:
char *strdup_noendblanks(char *s)
{
char *p; char *t;
 if (s==((void *)0)) return ((void *)0);
 if (*s=='\0') return my_strdup("");
 t=s;
 while (*t == ' ' || *t == '\n') t++;
 p = s + strlen(s) -1;
 while (p >= t && (*p == ' ' || *p == '\n')) p--;
 if (t>p) return my_strdup("");
 return my_strndup(t,(unsigned long) (p-t+1));
}


ExtractLabelTag

decompiled_code:
char *__fastcall ExtractLabelTag(char *haystack)
{
char *v1; // rbx
char *v2; // rbp
const char *v3; // rdx

v1 = strstr(haystack, "\\label{");
if ( v1 || (v1 = strstr(haystack, "\\label ")) != 0LL )
{
PushSource(0LL, v1 + 6);
v2 = (char *)getBraceParam();
PopSource();
v1 = strdup_nobadchars(v2);
free(v2);
v3 = "missing";
if ( v1 )
v3 = v1;
diagnostics(4LL, "LabelTag = <%s>", v3);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func9(char *haystack)
{
char *v1; // rbx
char *v2; // rbp
const char *v3; // rdx

v1 = strstr(haystack, "\\label{");
if ( v1 || (v1 = strstr(haystack, "\\label ")) != 0LL )
{
PushSource(0LL, v1 + 6);
v2 = (char *)getBraceParam();
PopSource();
v1 = func7(v2);
free(v2);
v3 = "missing";
if ( v1 )
v3 = v1;
diagnostics(4LL, "LabelTag = <%s>", v3);
}
return v1;
}

original_code:
char *
ExtractLabelTag(char *text)
{
 char *s, *label_with_spaces, *label;
 s = strstr(text,"\\label{");
 if (!s) s = strstr(text,"\\label ");
 if (!s) return ((void *)0);
 s += strlen("\\label");
 PushSource(((void *)0),s);
 label_with_spaces = getBraceParam();
 PopSource();
 label = strdup_nobadchars(label_with_spaces);
 free(label_with_spaces);
 diagnostics(4, "LabelTag = <%s>", (label) ? label : "missing");
 return label;
}

canonical_original_code:
char *ExtractLabelTag(char *text)
{
 char *s; char *label_with_spaces; char *label;
 s = strstr(text,"\\label{");
 if (!s) s = strstr(text,"\\label ");
 if (!s) return ((void *)0);
 s += strlen("\\label");
 PushSource(((void *)0),s);
 label_with_spaces = getBraceParam();
 PopSource();
 label = strdup_nobadchars(label_with_spaces);
 free(label_with_spaces);
 diagnostics(4, "LabelTag = <%s>", (label) ? label : "missing");
 return label;
}

variable_types:
label
char *


ExtractAndRemoveTag

decompiled_code:
char *__fastcall ExtractAndRemoveTag(char *needle, char *haystack)
{
char *v2; // rbx
char *v3; // rbp
char *v4; // r13
char *v5; // rbp
char *v6; // rbp

diagnostics(5LL, "target tag = <%s>", needle);
diagnostics(5LL, "original text = <%s>", haystack);
v3 = haystack;
do
{
if ( !v3 )
break;
v2 = strstr(v3, needle);
if ( !v2 )
return 0LL;
v3 = &v2[strlen(needle)];
if ( *v3 == 32 )
break;
}
while ( *v3 != 123 );
PushSource(0LL, v3);
v4 = (char *)getBraceParam();
PopSource();
if ( v4 )
{
v5 = strstr(v3, v4);
v6 = &v5[strlen(v4) + 1];
free(v4);
v4 = my_strndup(v2, v6 - v2);
do
*v2++ = *v6++;
while ( *v6 );
*v2 = 0;
diagnostics(5LL, "final contents = <%s>", v4);
diagnostics(5LL, "final text = <%s>", haystack);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func10(char *needle, char *haystack)
{
char *v2; // rbx
char *v3; // rbp
char *v4; // r13
char *v5; // rbp
char *v6; // rbp

diagnostics(5LL, "target tag = <%s>", needle);
diagnostics(5LL, "original text = <%s>", haystack);
v3 = haystack;
do
{
if ( !v3 )
break;
v2 = strstr(v3, needle);
if ( !v2 )
return 0LL;
v3 = &v2[strlen(needle)];
if ( *v3 == 32 )
break;
}
while ( *v3 != 123 );
PushSource(0LL, v3);
v4 = (char *)getBraceParam();
PopSource();
if ( v4 )
{
v5 = strstr(v3, v4);
v6 = &v5[strlen(v4) + 1];
free(v4);
v4 = func3(v2, v6 - v2);
do
*v2++ = *v6++;
while ( *v6 );
*v2 = 0;
diagnostics(5LL, "final contents = <%s>", v4);
diagnostics(5LL, "final text = <%s>", haystack);
}
return v4;
}

original_code:
char *
ExtractAndRemoveTag(char *tag, char *text)
{
 char *s, *contents, *start, *end;
 s = text;
 diagnostics(5, "target tag = <%s>", tag);
 diagnostics(5, "original text = <%s>", text);
 while (s) {
  start = strstr(s,tag);
  if (!start) return ((void *)0);
  s = start+strlen(tag);
  if (*s == ' ' || *s == '{') break;
 }
 PushSource(((void *)0),s);
 contents = getBraceParam();
 PopSource();
    if (!contents) return ((void *)0);
    end = strstr(s,contents)+strlen(contents)+1;
 free(contents);
 contents = my_strndup(start,(size_t) (end-start));
    do *start++=*end++; while (*end);
 *start='\0';
 diagnostics(5, "final contents = <%s>", contents);
 diagnostics(5, "final text = <%s>", text);
 return contents;
}

canonical_original_code:
char *ExtractAndRemoveTag(char *tag, char *text)
{
 char *s; char *contents; char *start; char *end;
 s = text;
 diagnostics(5, "target tag = <%s>", tag);
 diagnostics(5, "original text = <%s>", text);
 while (s) {
  start = strstr(s,tag);
  if (!start) return ((void *)0);
  s = start+strlen(tag);
  if (*s == ' ' || *s == '{') break;
 }
 PushSource(((void *)0),s);
 contents = getBraceParam();
 PopSource();
    if (!contents) return ((void *)0);
    end = strstr(s,contents)+strlen(contents)+1;
 free(contents);
 contents = my_strndup(start,(unsigned long) (end-start));
    do *start++=*end++; while (*end);
 *start='\0';
 diagnostics(5, "final contents = <%s>", contents);
 diagnostics(5, "final text = <%s>", text);
 return contents;
}

variable_types:
tag
char *

variable_types:
contents
char *

variable_types:
start
char *

variable_types:
end
char *


existsCounter

decompiled_code:
__int64 __fastcall existsCounter(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // ebp

v1 = iCounterCount;
if ( iCounterCount <= 0 )
{
v3 = 0;
}
else
{
v2 = 0LL;
do
{
v3 = v2;
if ( strstr((const char *)Counters[2 * v2], needle) )
break;
v3 = ++v2;
}
while ( v2 != v1 );
}
if ( v1 == v3 )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // ebp

v1 = iCounterCount;
if ( iCounterCount <= 0 )
{
v3 = 0;
}
else
{
v2 = 0LL;
do
{
v3 = v2;
if ( strstr((const char *)Counters[2 * v2], needle) )
break;
v3 = ++v2;
}
while ( v2 != v1 );
}
if ( v1 == v3 )
v3 = -1;
return v3;
}

original_code:
static int
existsCounter(char * s)
{
 int i=0;
 while(i < iCounterCount && strstr(Counters[i].name,s)==((void *)0))
  i++;
 if (i==iCounterCount)
  return -1;
 else
  return i;
}

canonical_original_code:
static int existsCounter(char *s)
{
 int i = 0;
 while(i < iCounterCount && strstr(Counters[i].name,s)==((void *)0))
  i++;
 if (i==iCounterCount)
  return -1;
 else
  return i;
}

variable_types: i int


newCounter

decompiled_code:
int __fastcall newCounter(const char *a1, int a2)
{
__int64 v2; // rbx

if ( iCounterCount == 50 )
return fprintf(stderr, "Too many counters, ignoring %s", a1);
v2 = 2LL * iCounterCount;
LODWORD(Counters[v2 + 1]) = a2;
Counters[v2] = my_strdup();
if ( !Counters[2 * iCounterCount] )
{
fprintf(stderr, "\nCannot allocate name for counter \\%s\n", a1);
exit(1);
}
return ++iCounterCount;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, int a2)
{
__int64 v2; // rbx

if ( iCounterCount == 50 )
return fprintf(stderr, "Too many counters, ignoring %s", a1);
v2 = 2LL * iCounterCount;
LODWORD(Counters[v2 + 1]) = a2;
Counters[v2] = my_strdup();
if ( !Counters[2 * iCounterCount] )
{
fprintf(stderr, "\nCannot allocate name for counter \\%s\n", a1);
exit(1);
}
return ++iCounterCount;
}

original_code:
static void
newCounter(char *s, int n)
{
 if (iCounterCount==50){
  fprintf(stderr,"Too many counters, ignoring %s", s);
  return;
 }
 Counters[iCounterCount].number=n;
 Counters[iCounterCount].name=my_strdup(s);
 if (Counters[iCounterCount].name==((void *)0)) {
  fprintf(stderr, "\nCannot allocate name for counter \\%s\n", s);
  exit(1);
 }
 iCounterCount++;
}


incrementCounter

decompiled_code:
int __fastcall incrementCounter(char *a1)
{
int v1; // eax
unsigned __int64 v2; // rax

v1 = existsCounter(a1);
if ( v1 < 0 )
{
LODWORD(v2) = newCounter(a1, 1);
}
else
{
v2 = 16LL * v1;
++LODWORD(Counters[v2 / 8 + 1]);
}
return v2;
}

canonical_decompiled_code:
int __fastcall func2(char *a1)
{
int v1; // eax
unsigned __int64 v2; // rax

v1 = func0(a1);
if ( v1 < 0 )
{
LODWORD(v2) = func1(a1, 1);
}
else
{
v2 = 16LL * v1;
++LODWORD(Counters[v2 / 8 + 1]);
}
return v2;
}

original_code:
void
incrementCounter(char * s)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, 1);
 else
  Counters[i].number++;
}

canonical_original_code:
void incrementCounter(char *s)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, 1);
 else
  Counters[i].number++;
}


setCounter

decompiled_code:
int __fastcall setCounter(char *a1, int a2)
{
int v2; // eax
unsigned __int64 v3; // rax

v2 = existsCounter(a1);
if ( v2 < 0 )
{
LODWORD(v3) = newCounter(a1, a2);
}
else
{
v3 = 16LL * v2;
LODWORD(Counters[v3 / 8 + 1]) = a2;
}
return v3;
}

canonical_decompiled_code:
int __fastcall func3(char *a1, int a2)
{
int v2; // eax
unsigned __int64 v3; // rax

v2 = func0(a1);
if ( v2 < 0 )
{
LODWORD(v3) = func1(a1, a2);
}
else
{
v3 = 16LL * v2;
LODWORD(Counters[v3 / 8 + 1]) = a2;
}
return v3;
}

original_code:
void
setCounter(char * s, int n)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, n);
 else
  Counters[i].number = n;
}

canonical_original_code:
void setCounter(char *s, int n)
{
 int i;
 i = existsCounter(s);
 if (i<0)
  newCounter(s, n);
 else
  Counters[i].number = n;
}


getCounter

decompiled_code:
__int64 __fastcall getCounter(char *a1)
{
int v1; // eax

v1 = existsCounter(a1);
if ( v1 >= 0 )
return LODWORD(Counters[2 * v1 + 1]);
fprintf(stderr, "No counter of type <%s>", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
int v1; // eax

v1 = func0(a1);
if ( v1 >= 0 )
return LODWORD(Counters[2 * v1 + 1]);
fprintf(stderr, "No counter of type <%s>", a1);
return 0LL;
}

original_code:
int
getCounter(char * s)
{
 int i;
 i = existsCounter(s);
 if (i<0) {
  fprintf(stderr, "No counter of type <%s>", s);
  return 0;
 }
 return Counters[i].number;
}

canonical_original_code:
int getCounter(char *s)
{
 int i;
 i = existsCounter(s);
 if (i<0) {
  fprintf(stderr, "No counter of type <%s>", s);
  return 0;
 }
 return Counters[i].number;
}


CallCommandFunc

decompiled_code:
int __fastcall CallCommandFunc(char *s2)
{
int v2; // eax
__int64 v3; // r15
const char **v4; // rbp
const char *v5; // rdi
unsigned int v6; // er12
__int64 v7; // rbx
int result; // eax
char *v9; // rbx
const char *v10; // rdx

diagnostics(5LL, "CallCommandFunc <%s>, iEnvCount = %d", s2, (unsigned int)iEnvCount);
v2 = existsDefinition(s2);
if ( v2 >= 0 )
{
v9 = (char *)expandDefinition((unsigned int)v2);
diagnostics(3LL, "CallCommandFunc <%s> expanded to <%s>", s2, v9);
ConvertString(v9);
free(v9);
result = 1;
}
else
{
LODWORD(v3) = iEnvCount - 1;
if ( iEnvCount - 1 < 0 )
{
result = 0;
}
else
{
v3 = (int)v3;
while ( 1 )
{
v4 = (const char **)Environments[v3];
v5 = *v4;
v6 = 0;
v7 = 0LL;
if ( **v4 )
break;
LABEL_7:
if ( (int)--v3 < 0 )
return 0;
}
while ( 1 )
{
result = strcmp(v5, s2);
if ( !result )
break;
++v6;
v7 += 3LL;
v5 = v4[v7];
if ( !*v5 )
goto LABEL_7;
}
v10 = v4[v7 + 1];
if ( v10 )
{
if ( v10 == (const char *)&CmdIgnoreParameter )
diagnostics(1LL, "Command \\%s ignored", s2);
diagnostics(
5LL,
"CallCommandFunc Found %s iEnvCount=%d number=%d",
*(const char **)(Environments[(int)v3] + v7 * 8),
(unsigned int)v3,
v6);
(*(void (__fastcall **)(_QWORD))(Environments[(int)v3] + v7 * 8 + 8))(*(unsigned int *)(Environments[(int)v3]
+ v7 * 8
+ 16));
result = 1;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s2)
{
int v2; // eax
__int64 v3; // r15
const char **v4; // rbp
const char *v5; // rdi
unsigned int v6; // er12
__int64 v7; // rbx
int result; // eax
char *v9; // rbx
const char *v10; // rdx

diagnostics(5LL, "CallCommandFunc <%s>, iEnvCount = %d", s2, (unsigned int)iEnvCount);
v2 = existsDefinition(s2);
if ( v2 >= 0 )
{
v9 = (char *)expandDefinition((unsigned int)v2);
diagnostics(3LL, "CallCommandFunc <%s> expanded to <%s>", s2, v9);
ConvertString(v9);
free(v9);
result = 1;
}
else
{
LODWORD(v3) = iEnvCount - 1;
if ( iEnvCount - 1 < 0 )
{
result = 0;
}
else
{
v3 = (int)v3;
while ( 1 )
{
v4 = (const char **)Environments[v3];
v5 = *v4;
v6 = 0;
v7 = 0LL;
if ( **v4 )
break;
LABEL_7:
if ( (int)--v3 < 0 )
return 0;
}
while ( 1 )
{
result = strcmp(v5, s2);
if ( !result )
break;
++v6;
v7 += 3LL;
v5 = v4[v7];
if ( !*v5 )
goto LABEL_7;
}
v10 = v4[v7 + 1];
if ( v10 )
{
if ( v10 == (const char *)&CmdIgnoreParameter )
diagnostics(1LL, "Command \\%s ignored", s2);
diagnostics(
5LL,
"CallCommandFunc Found %s iEnvCount=%d number=%d",
*(const char **)(Environments[(int)v3] + v7 * 8),
(unsigned int)v3,
v6);
(*(void (__fastcall **)(_QWORD))(Environments[(int)v3] + v7 * 8 + 8))(*(unsigned int *)(Environments[(int)v3]
+ v7 * 8
+ 16));
result = 1;
}
}
}
return result;
}

original_code:
bool
CallCommandFunc(char *cCommand)
{
 int i, j;
 char * macro_string;
 diagnostics(5,"CallCommandFunc <%s>, iEnvCount = %d",cCommand,iEnvCount);
 i=existsDefinition(cCommand);
 if (i>-1) {
  macro_string=expandDefinition(i);
     diagnostics(3,"CallCommandFunc <%s> expanded to <%s>", cCommand, macro_string);
  ConvertString(macro_string);
  free(macro_string);
  return 1;
 }
 for (j = iEnvCount - 1; j >= 0; j--) {
  i = 0;
  while (strcmp(Environments[j][i].cpCommand, "") != 0) {
   if (strcmp(Environments[j][i].cpCommand, cCommand) == 0) {
    if (Environments[j][i].func == ((void *)0))
     return 0;
    if (*Environments[j][i].func == CmdIgnoreParameter) {
     diagnostics(1, "Command \\%s ignored", cCommand);
    }
   diagnostics(5,"CallCommandFunc Found %s iEnvCount=%d number=%d",Environments[j][i].cpCommand, j, i);
    (*Environments[j][i].func) ((Environments[j][i].param));
    return 1;
   }
   ++i;
  }
 }
 return 0;
}

canonical_original_code:
int CallCommandFunc(char *cCommand)
{
 int i; int j;
 char *macro_string;
 diagnostics(5,"CallCommandFunc <%s>, iEnvCount = %d",cCommand,iEnvCount);
 i=existsDefinition(cCommand);
 if (i>-1) {
  macro_string=expandDefinition(i);
     diagnostics(3,"CallCommandFunc <%s> expanded to <%s>", cCommand, macro_string);
  ConvertString(macro_string);
  free(macro_string);
  return 1;
 }
 for (j = iEnvCount - 1; j >= 0; j--) {
  i = 0;
  while (strcmp(Environments[j][i].cpCommand, "") != 0) {
   if (strcmp(Environments[j][i].cpCommand, cCommand) == 0) {
    if (Environments[j][i].func == ((void *)0))
     return 0;
    if (*Environments[j][i].func == CmdIgnoreParameter) {
     diagnostics(1, "Command \\%s ignored", cCommand);
    }
   diagnostics(5,"CallCommandFunc Found %s iEnvCount=%d number=%d",Environments[j][i].cpCommand, j, i);
    (*Environments[j][i].func) ((Environments[j][i].param));
    return 1;
   }
   ++i;
  }
 }
 return 0;
}

variable_types:
cCommand
char *

variable_types: j int


CallParamFunc

decompiled_code:
int __fastcall CallParamFunc(char *s2, unsigned int a2)
{
const char **v3; // rbx
int v4; // ebp
const char *v5; // rdi
int result; // eax
__int64 (__fastcall *v7)(_QWORD); // rax
char v8[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = (const char **)&off_50B8;
v4 = 0;
v5 = "center";
while ( 1 )
{
result = strcmp(v5, s2);
if ( !result )
break;
++v4;
v5 = *v3;
v3 += 3;
if ( !*v5 )
{
if ( a2 == 0x4000 )
{
snprintf(v8, 0x64uLL, "\\%s%s%s", "end{", s2, "}");
Ignore_Environment(s2);
result = diagnostics(1LL, "Environment <%s> ignored. Not defined in commands.c", s2);
}
return result;
}
}
v7 = (__int64 (__fastcall *)(_QWORD))*(&funcs_208 + 3 * v4);
if ( !v7 )
_assert_fail("params[i].func != NULL", "commands.c", 0x31Bu, "CallParamFunc");
return v7(dword_50B0[6 * v4] | a2);
}

canonical_decompiled_code:
int __fastcall func1(char *s2, unsigned int a2)
{
const char **v3; // rbx
int v4; // ebp
const char *v5; // rdi
int result; // eax
__int64 (__fastcall *v7)(_QWORD); // rax
char v8[152]; // [rsp+0h] [rbp-98h] BYREF

v3 = (const char **)&off_50B8;
v4 = 0;
v5 = "center";
while ( 1 )
{
result = strcmp(v5, s2);
if ( !result )
break;
++v4;
v5 = *v3;
v3 += 3;
if ( !*v5 )
{
if ( a2 == 0x4000 )
{
snprintf(v8, 0x64uLL, "\\%s%s%s", "end{", s2, "}");
Ignore_Environment(s2);
result = diagnostics(1LL, "Environment <%s> ignored. Not defined in commands.c", s2);
}
return result;
}
}
v7 = (__int64 (__fastcall *)(_QWORD))*(&funcs_208 + 3 * v4);
if ( !v7 )
_assert_fail("params[i].func != NULL", "commands.c", 0x31Bu, "CallParamFunc");
return v7(dword_50B0[6 * v4] | a2);
}

original_code:
void
CallParamFunc(char *cCommand, int AddParam)
{
 int i = 0;
 char unknown_environment[100];
 while (strcmp(params[i].cpCommand, "") != 0) {
  if (strcmp(params[i].cpCommand, cCommand) == 0) {
   ((void) sizeof ((params[i].func != ((void *)0)) ? 1 : 0), __extension__ ({ if (params[i].func != ((void *)0)) ; else __assert_fail ("params[i].func != NULL", "commands.c", 795, __extension__ __PRETTY_FUNCTION__); }));
   (*params[i].func) ((params[i].param) | AddParam);
   return;
  }
  ++i;
 }
 if (AddParam == 0x4000) {
  snprintf(unknown_environment, 100, "\\%s%s%s", "end{", cCommand, "}");
  Ignore_Environment(cCommand);
  diagnostics(1, "Environment <%s> ignored.  Not defined in commands.c", cCommand);
 }
}

variable_types: AddParam int


CurrentEnvironmentCount

decompiled_code:
__int64 CurrentEnvironmentCount()
{
return (unsigned int)iEnvCount;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)iEnvCount;
}

original_code:
int
CurrentEnvironmentCount(void)
{
 return iEnvCount;
}

canonical_original_code:
int CurrentEnvironmentCount()
{
 return iEnvCount;
}


PushEnvironment

decompiled_code:
__int64 __fastcall PushEnvironment(int a1)
{
int v1; // ebp
int v2; // eax
__int64 v3; // rdx
const char *v4; // rdx

v1 = iEnvCount;
g_par_indent_array[v1] = getLength("parindent");
v2 = iEnvCount;
v3 = iEnvCount;
g_left_indent_array[iEnvCount] = g_left_margin_indent;
g_right_indent_array[v3] = g_right_margin_indent;
switch ( a1 )
{
case 1:
Environments[v2] = (__int64)&PreambleCommands;
v4 = "preamble";
break;
case 2:
Environments[v2] = (__int64)&commands;
v4 = "document";
break;
case 3:
Environments[v2] = (__int64)&ItemizeCommands;
v4 = "itemize";
break;
case 4:
Environments[v2] = (__int64)&EnumerateCommands;
v4 = "enumerate";
break;
case 5:
Environments[v2] = (__int64)&DescriptionCommands;
v4 = "description";
break;
case 8:
Environments[v2] = (__int64)&LetterCommands;
v4 = "letter";
break;
case 9:
Environments[v2] = (__int64)&commands;
v4 = "*latex2rtf ignored*";
break;
case 10:
Environments[v2] = (__int64)&hyperlatex;
v4 = "hyperlatex";
break;
case 11:
Environments[v2] = (__int64)&FigureCommands;
v4 = "figure";
break;
case 12:
Environments[v2] = (__int64)&GermanModeCommands;
v4 = "german";
break;
case 13:
Environments[v2] = (__int64)&FrenchModeCommands;
v4 = "french";
break;
case 14:
Environments[v2] = (__int64)&RussianModeCommands;
v4 = "french";
break;
case 15:
Environments[v2] = (__int64)&commands;
v4 = "Generic Environment";
break;
case 16:
Environments[v2] = (__int64)&CzechModeCommands;
v4 = "french";
break;
case 17:
Environments[v2] = (__int64)&apaciteCommands;
v4 = "apacite";
break;
case 18:
Environments[v2] = (__int64)&natbibCommands;
v4 = "natbib";
break;
default:
diagnostics(0LL, "assertion failed at function PushEnvironment");
v4 = (const char *)&unk_4001;
break;
}
return diagnostics(3LL, "Entered %s environment, iEnvCount now = %d", v4, (unsigned int)++iEnvCount);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ebp
int v2; // eax
__int64 v3; // rdx
const char *v4; // rdx

v1 = iEnvCount;
g_par_indent_array[v1] = getLength("parindent");
v2 = iEnvCount;
v3 = iEnvCount;
g_left_indent_array[iEnvCount] = g_left_margin_indent;
g_right_indent_array[v3] = g_right_margin_indent;
switch ( a1 )
{
case 1:
Environments[v2] = (__int64)&PreambleCommands;
v4 = "preamble";
break;
case 2:
Environments[v2] = (__int64)&commands;
v4 = "document";
break;
case 3:
Environments[v2] = (__int64)&ItemizeCommands;
v4 = "itemize";
break;
case 4:
Environments[v2] = (__int64)&EnumerateCommands;
v4 = "enumerate";
break;
case 5:
Environments[v2] = (__int64)&DescriptionCommands;
v4 = "description";
break;
case 8:
Environments[v2] = (__int64)&LetterCommands;
v4 = "letter";
break;
case 9:
Environments[v2] = (__int64)&commands;
v4 = "*latex2rtf ignored*";
break;
case 10:
Environments[v2] = (__int64)&hyperlatex;
v4 = "hyperlatex";
break;
case 11:
Environments[v2] = (__int64)&FigureCommands;
v4 = "figure";
break;
case 12:
Environments[v2] = (__int64)&GermanModeCommands;
v4 = "german";
break;
case 13:
Environments[v2] = (__int64)&FrenchModeCommands;
v4 = "french";
break;
case 14:
Environments[v2] = (__int64)&RussianModeCommands;
v4 = "french";
break;
case 15:
Environments[v2] = (__int64)&commands;
v4 = "Generic Environment";
break;
case 16:
Environments[v2] = (__int64)&CzechModeCommands;
v4 = "french";
break;
case 17:
Environments[v2] = (__int64)&apaciteCommands;
v4 = "apacite";
break;
case 18:
Environments[v2] = (__int64)&natbibCommands;
v4 = "natbib";
break;
default:
diagnostics(0LL, "assertion failed at function PushEnvironment");
v4 = (const char *)&unk_4001;
break;
}
return diagnostics(3LL, "Entered %s environment, iEnvCount now = %d", v4, (unsigned int)++iEnvCount);
}

original_code:
void
PushEnvironment(int code)
{
 char *diag = "";
 g_par_indent_array[iEnvCount] = getLength("parindent");
 g_left_indent_array[iEnvCount] = g_left_margin_indent;
 g_right_indent_array[iEnvCount] = g_right_margin_indent;
 switch (code) {
 case 1:
  Environments[iEnvCount] = PreambleCommands;
  diag = "preamble";
  break;
 case 2:
  Environments[iEnvCount] = commands;
  diag = "document";
  break;
 case 3:
  Environments[iEnvCount] = ItemizeCommands;
  diag = "itemize";
  break;
 case 4:
  Environments[iEnvCount] = EnumerateCommands;
  diag = "enumerate";
  break;
 case 8:
  Environments[iEnvCount] = LetterCommands;
  diag = "letter";
  break;
 case 5:
  Environments[iEnvCount] = DescriptionCommands;
  diag = "description";
  break;
 case 12:
  Environments[iEnvCount] = GermanModeCommands;
  diag = "german";
  break;
 case 13:
  Environments[iEnvCount] = FrenchModeCommands;
  diag = "french";
  break;
 case 14:
  Environments[iEnvCount] = RussianModeCommands;
  diag = "french";
   break;
 case 16:
  Environments[iEnvCount] = CzechModeCommands;
  diag = "french";
  break;
 case 11:
  Environments[iEnvCount] = FigureCommands;
  diag = "figure";
  break;
 case 9:
  Environments[iEnvCount] = commands;
  diag = "*latex2rtf ignored*";
  break;
 case 10:
  Environments[iEnvCount] = hyperlatex;
  diag = "hyperlatex";
  break;
 case 17:
  Environments[iEnvCount] = apaciteCommands;
  diag = "apacite";
  break;
 case 18:
  Environments[iEnvCount] = natbibCommands;
  diag = "natbib";
  break;
 case 15:
  Environments[iEnvCount] = commands;
  diag = "Generic Environment";
  break;
 default:
  diagnostics(0,"assertion failed at function PushEnvironment");
 }
 iEnvCount++;
 diagnostics(3, "Entered %s environment, iEnvCount now = %d", diag, iEnvCount);
}

variable_types: code int

variable_types:
diag
char *


PopEnvironment

decompiled_code:
__int64 PopEnvironment()
{
__int64 v0; // rax

v0 = --iEnvCount;
Environments[iEnvCount] = 0LL;
setLength("parindent", (unsigned int)g_par_indent_array[v0]);
g_left_margin_indent = g_left_indent_array[iEnvCount];
g_right_margin_indent = g_right_indent_array[iEnvCount];
return diagnostics(3LL, "Exited environment, iEnvCount now = %d", (unsigned int)iEnvCount);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax

v0 = --iEnvCount;
Environments[iEnvCount] = 0LL;
setLength("parindent", (unsigned int)g_par_indent_array[v0]);
g_left_margin_indent = g_left_indent_array[iEnvCount];
g_right_margin_indent = g_right_indent_array[iEnvCount];
return diagnostics(3LL, "Exited environment, iEnvCount now = %d", (unsigned int)iEnvCount);
}

original_code:
void
PopEnvironment()
{
 --iEnvCount;
 Environments[iEnvCount] = ((void *)0);
 setLength("parindent",g_par_indent_array[iEnvCount]);
 g_left_margin_indent=g_left_indent_array[iEnvCount];
 g_right_margin_indent=g_right_indent_array[iEnvCount];
 diagnostics(3, "Exited environment, iEnvCount now = %d", iEnvCount);
 return;
}


ClearEnvironment

decompiled_code:
void ClearEnvironment()
{
Environments[0] = 0LL;
iEnvCount = 0;
}

canonical_decompiled_code:
void func5()
{
Environments[0] = 0LL;
iEnvCount = 0;
}

original_code:
void
ClearEnvironment()
{
 Environments[0] = ((void *)0);
 iEnvCount = 0;
 return;
}


existsLength

decompiled_code:
__int64 __fastcall existsLength(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // ebp

v1 = iLengthCount;
if ( iLengthCount <= 0 )
{
v3 = 0;
}
else
{
v2 = 0LL;
do
{
v3 = v2;
if ( strstr((const char *)Lengths[2 * v2], needle) )
break;
v3 = ++v2;
}
while ( v2 != v1 );
}
if ( v1 == v3 )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *needle)
{
int v1; // er14
__int64 v2; // rbx
unsigned int v3; // ebp

v1 = iLengthCount;
if ( iLengthCount <= 0 )
{
v3 = 0;
}
else
{
v2 = 0LL;
do
{
v3 = v2;
if ( strstr((const char *)Lengths[2 * v2], needle) )
break;
v3 = ++v2;
}
while ( v2 != v1 );
}
if ( v1 == v3 )
v3 = -1;
return v3;
}

original_code:
static int
existsLength(char * s)
{
 int i=0;
 while(i < iLengthCount && strstr(Lengths[i].name,s)==((void *)0))
  i++;
 if (i==iLengthCount)
  return -1;
 else
  return i;
}

canonical_original_code:
static int existsLength(char *s)
{
 int i = 0;
 while(i < iLengthCount && strstr(Lengths[i].name,s)==((void *)0))
  i++;
 if (i==iLengthCount)
  return -1;
 else
  return i;
}

variable_types:
s
char *


newLength

decompiled_code:
__int64 __fastcall newLength(const char *a1, int a2)
{
__int64 v2; // rbx

if ( iLengthCount == 50 )
return diagnostics(1LL, "Too many lengths, ignoring %s", a1);
v2 = 2LL * iLengthCount;
LODWORD(Lengths[v2 + 1]) = a2;
Lengths[v2] = my_strdup();
if ( !Lengths[2 * iLengthCount] )
{
fprintf(stderr, "\nCannot allocate name for length \\%s\n", a1);
exit(1);
}
return (unsigned int)++iLengthCount;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, int a2)
{
__int64 v2; // rbx

if ( iLengthCount == 50 )
return diagnostics(1LL, "Too many lengths, ignoring %s", a1);
v2 = 2LL * iLengthCount;
LODWORD(Lengths[v2 + 1]) = a2;
Lengths[v2] = my_strdup();
if ( !Lengths[2 * iLengthCount] )
{
fprintf(stderr, "\nCannot allocate name for length \\%s\n", a1);
exit(1);
}
return (unsigned int)++iLengthCount;
}

original_code:
static void
newLength(char *s, int d)
{
 if (iLengthCount==50){
  diagnostics(1,"Too many lengths, ignoring %s", s);
  return;
 }
 Lengths[iLengthCount].distance=d;
 Lengths[iLengthCount].name=my_strdup(s);
 if (Lengths[iLengthCount].name==((void *)0)) {
  fprintf(stderr, "\nCannot allocate name for length \\%s\n", s);
  exit(1);
 }
 iLengthCount++;
}

variable_types: d int


setLength

decompiled_code:
__int64 __fastcall setLength(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax

v2 = existsLength(a1);
if ( v2 < 0 )
return newLength(a1, a2);
result = 2LL * v2;
LODWORD(Lengths[result + 1]) = a2;
return result * 8;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax

v2 = func0(a1);
if ( v2 < 0 )
return func1(a1, a2);
result = 2LL * v2;
LODWORD(Lengths[result + 1]) = a2;
return result * 8;
}

original_code:
void
setLength(char * s, int d)
{
 int i;
 i = existsLength(s);
 if (i<0)
  newLength(s, d);
 else
  Lengths[i].distance = d;
}

canonical_original_code:
void setLength(char *s, int d)
{
 int i;
 i = existsLength(s);
 if (i<0)
  newLength(s, d);
 else
  Lengths[i].distance = d;
}


getLength

decompiled_code:
__int64 __fastcall getLength(char *a1)
{
int v1; // eax

v1 = existsLength(a1);
if ( v1 >= 0 )
return LODWORD(Lengths[2 * v1 + 1]);
diagnostics(1LL, "No length of type %s", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
int v1; // eax

v1 = func0(a1);
if ( v1 >= 0 )
return LODWORD(Lengths[2 * v1 + 1]);
diagnostics(1LL, "No length of type %s", a1);
return 0LL;
}

original_code:
int
getLength(char * s)
{
 int i;
 i = existsLength(s);
 if (i<0) {
  diagnostics(1, "No length of type %s", s);
  return 0;
 }
 return Lengths[i].distance;
}

canonical_original_code:
int getLength(char *s)
{
 int i;
 i = existsLength(s);
 if (i<0) {
  diagnostics(1, "No length of type %s", s);
  return 0;
 }
 return Lengths[i].distance;
}


CmdSetTexLength

decompiled_code:
__int64 __fastcall CmdSetTexLength(int a1)
{
char v1; // al
__int64 v2; // rbp
__int64 result; // rax

v1 = getNonSpace();
if ( v1 == 61 )
skipSpaces();
else
ungetTexChar((unsigned int)v1);
v2 = (unsigned int)getDimension();
result = diagnostics(4LL, "CmdSetTexLength size = %d", v2);
switch ( a1 )
{
case 1:
result = setLength("hoffset", v2);
break;
case 2:
result = setLength("voffset", v2);
break;
case 3:
result = setLength("parindent", v2);
break;
case 4:
result = setLength("parskip", v2);
break;
case 5:
result = setLength("baselineskip", v2);
break;
case 6:
result = setLength("topmargin", v2);
break;
case 7:
result = setLength("textheight", v2);
break;
case 8:
result = setLength("headheight", v2);
break;
case 9:
result = setLength("headsep", v2);
break;
case 10:
result = setLength("textwidth", v2);
break;
case 11:
result = setLength("oddsidemargin", v2);
break;
case 12:
result = setLength("evensidemargin", v2);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
char v1; // al
__int64 v2; // rbp
__int64 result; // rax

v1 = getNonSpace();
if ( v1 == 61 )
skipSpaces();
else
ungetTexChar((unsigned int)v1);
v2 = (unsigned int)getDimension();
result = diagnostics(4LL, "CmdSetTexLength size = %d", v2);
switch ( a1 )
{
case 1:
result = func2("hoffset", v2);
break;
case 2:
result = func2("voffset", v2);
break;
case 3:
result = func2("parindent", v2);
break;
case 4:
result = func2("parskip", v2);
break;
case 5:
result = func2("baselineskip", v2);
break;
case 6:
result = func2("topmargin", v2);
break;
case 7:
result = func2("textheight", v2);
break;
case 8:
result = func2("headheight", v2);
break;
case 9:
result = func2("headsep", v2);
break;
case 10:
result = func2("textwidth", v2);
break;
case 11:
result = func2("oddsidemargin", v2);
break;
case 12:
result = func2("evensidemargin", v2);
break;
default:
return result;
}
return result;
}

original_code:
void
CmdSetTexLength(int code)
{
 int d;
 char c;
 c = getNonSpace();
 if (c == '=')
  skipSpaces();
 else
  ungetTexChar(c);
 d = getDimension();
 diagnostics(4, "CmdSetTexLength size = %d",d);
  switch (code){
  case 1:
   setLength("hoffset",d);
   break;
  case 2:
   setLength("voffset",d);
   break;
  case 3:
   setLength("parindent",d);
   break;
  case 4:
   setLength("parskip",d);
   break;
  case 5:
   setLength("baselineskip",d);
   break;
  case 6:
   setLength("topmargin",d);
   break;
  case 7:
   setLength("textheight",d);
   break;
  case 8:
   setLength("headheight",d);
   break;
  case 9:
   setLength("headsep",d);
   break;
  case 10:
   setLength("textwidth",d);
   break;
  case 11:
   setLength("oddsidemargin",d);
   break;
  case 12:
   setLength("evensidemargin",d);
   break;
 }
}

variable_types: c char


decompiled_code:
int __fastcall cfg_compare(const void *a1, const void *a2)
{
return strcmp(**(const char ***)a1, **(const char ***)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(**(const char ***)a1, **(const char ***)a2);
}

original_code:
static int cfg_compare(ConfigEntryT ** el1, ConfigEntryT ** el2)
{
 return strcmp((*el1)->TexCommand, (*el2)->TexCommand);
}

canonical_original_code:
static int cfg_compare(struct ConfigEntryT **el1, struct ConfigEntryT **el2)
{
 return strcmp((*el1)->TexCommand, (*el2)->TexCommand);
}

variable_types: struct ConfigEntryT { char *TexCommand; char *RtfCommand; } **


decompiled_code:
void *__fastcall search_rtf(__int64 a1, unsigned int a2)
{
const void *v2; // rax
__int64 *key; // [rsp+8h] [rbp-20h] BYREF
__int64 v5[3]; // [rsp+10h] [rbp-18h] BYREF

v5[0] = a1;
v5[1] = (__int64)&unk_98D;
key = v5;
if ( a2 > 4 )
_assert_fail("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 0x12Bu, "search_rtf");
v2 = (const void *)qword_8C8[4 * (int)a2];
if ( !v2 )
_assert_fail("configinfo[WhichCfg].config_info != NULL", "cfg.c", 0x12Cu, "search_rtf");
return bsearch(&key, v2, qword_8D0[4 * (int)a2], 8uLL, cfg_compare);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, unsigned int a2)
{
const void *v2; // rax
__int64 *key; // [rsp+8h] [rbp-20h] BYREF
__int64 v5[3]; // [rsp+10h] [rbp-18h] BYREF

v5[0] = a1;
v5[1] = (__int64)&unk_98D;
key = v5;
if ( a2 > 4 )
_assert_fail("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 0x12Bu, "search_rtf");
v2 = (const void *)qword_8C8[4 * (int)a2];
if ( !v2 )
_assert_fail("configinfo[WhichCfg].config_info != NULL", "cfg.c", 0x12Cu, "search_rtf");
return bsearch(&key, v2, qword_8D0[4 * (int)a2], 8uLL, cfg_compare);
}

original_code:
static ConfigEntryT **
search_rtf(const char *theTexCommand, int WhichCfg)
{
 ConfigEntryT compare_item;
 ConfigEntryT *compare_ptr;
 compare_item.TexCommand = theTexCommand;
 compare_item.RtfCommand = "";
 compare_ptr = &compare_item;
 ((void) sizeof ((WhichCfg >= 0 && (size_t) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ? 1 : 0), __extension__ ({ if (WhichCfg >= 0 && (size_t) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ; else __assert_fail ("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 299, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((configinfo[WhichCfg].config_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (configinfo[WhichCfg].config_info != ((void *)0)) ; else __assert_fail ("configinfo[WhichCfg].config_info != NULL", "cfg.c", 300, __extension__ __PRETTY_FUNCTION__); }));
 return (ConfigEntryT **) bsearch
  (&compare_ptr
   ,configinfo[WhichCfg].config_info
   ,configinfo[WhichCfg].config_info_size
   ,sizeof(compare_ptr)
   ,(fptr) cfg_compare
  );
}

canonical_original_code:
static struct ConfigEntryT **search_rtf(char *theTexCommand, int WhichCfg)
{
 struct ConfigEntryT compare_item;
 struct ConfigEntryT *compare_ptr;
 compare_item.TexCommand = theTexCommand;
 compare_item.RtfCommand = "";
 compare_ptr = &compare_item;
 ((void) sizeof ((WhichCfg >= 0 && (unsigned long) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ? 1 : 0), __extension__ ({ if (WhichCfg >= 0 && (unsigned long) WhichCfg < (sizeof(configinfo) / sizeof(ConfigInfoT))) ; else __assert_fail ("WhichCfg >= 0 && (size_t) WhichCfg < CONFIG_SIZE", "cfg.c", 299, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((configinfo[WhichCfg].config_info != ((void *)0)) ? 1 : 0), __extension__ ({ if (configinfo[WhichCfg].config_info != ((void *)0)) ; else __assert_fail ("configinfo[WhichCfg].config_info != NULL", "cfg.c", 300, __extension__ __PRETTY_FUNCTION__); }));
 return (struct ConfigEntryT **) bsearch
  (&compare_ptr
   ,configinfo[WhichCfg].config_info
   ,configinfo[WhichCfg].config_info_size
   ,sizeof(compare_ptr)
   ,(int (*)(void *, void *)) cfg_compare
  );
}

variable_types:
theTexCommand
char *

variable_types: WhichCfg int

return_type: struct ConfigEntryT { char *TexCommand; char *RtfCommand; } **


SearchRtfIndex

decompiled_code:
__int64 __fastcall SearchRtfIndex(__int64 a1, unsigned int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = search_rtf(a1, a2);
if ( v2 )
result = ((__int64)v2 - qword_8C8[4 * (int)a2]) >> 3;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
void *v2; // rax
__int64 result; // rax

v2 = func1(a1, a2);
if ( v2 )
result = ((__int64)v2 - qword_8C8[4 * (int)a2]) >> 3;
else
result = 0LL;
return result;
}

original_code:
int
SearchRtfIndex(const char *theTexCommand, int WhichCfg)
{
 ConfigEntryT **help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0)) {
  return 0;
 }
 return help - configinfo[WhichCfg].config_info;
}

canonical_original_code:
int SearchRtfIndex(char *theTexCommand, int WhichCfg)
{
 struct ConfigEntryT **help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0)) {
  return 0;
 }
 return help - configinfo[WhichCfg].config_info;
}

user_defined_types: struct ConfigEntryT { char *TexCommand; char *RtfCommand; }


SearchRtfCmd

decompiled_code:
void *__fastcall SearchRtfCmd(__int64 a1, unsigned int a2)
{
void *result; // rax

result = search_rtf(a1, a2);
if ( result )
result = *(void **)(*(_QWORD *)result + 8LL);
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, unsigned int a2)
{
void *result; // rax

result = func1(a1, a2);
if ( result )
result = *(void **)(*(_QWORD *)result + 8LL);
return result;
}

original_code:
char *
SearchRtfCmd(const char *theTexCommand, int WhichCfg)
{
 ConfigEntryT **help;
 help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0))
  return ((void *)0);
 else
  return (char *)(*help)->RtfCommand;
}

canonical_original_code:
char *SearchRtfCmd(char *theTexCommand, int WhichCfg)
{
 struct ConfigEntryT **help;
 help = search_rtf(theTexCommand, WhichCfg);
 if (help == ((void *)0))
  return ((void *)0);
 else
  return (char *)(*help)->RtfCommand;
}


CfgStartIterate

decompiled_code:
__int64 CfgStartIterate()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 0LL;
}

original_code:
ConfigEntryT **
CfgStartIterate(int WhichCfg)
{
 return ((void *)0);
}

canonical_original_code:
struct ConfigEntryT **CfgStartIterate(int WhichCfg)
{
 return ((void *)0);
}


CfgNext

decompiled_code:
__int64 __fastcall CfgNext(int a1, __int64 a2)
{
unsigned __int64 v2; // rsi

if ( !a2 )
return qword_8C8[4 * a1];
v2 = a2 + 8;
if ( v2 > qword_8C8[4 * a1] + 8 * qword_8D0[4 * a1] - 8 )
v2 = 0LL;
return v2;
}

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

if ( !a2 )
return qword_8C8[4 * a1];
v2 = a2 + 8;
if ( v2 > qword_8C8[4 * a1] + 8 * qword_8D0[4 * a1] - 8 )
v2 = 0LL;
return v2;
}

original_code:
ConfigEntryT **
CfgNext(int WhichCfg, ConfigEntryT ** last)
{
 if (last == ((void *)0)) {
  return (ConfigEntryT **) configinfo[WhichCfg].config_info;
 }
 last++;
 if (last
     > (ConfigEntryT **) configinfo[WhichCfg].config_info
     + configinfo[WhichCfg].config_info_size
     - 1
  ) {
  return ((void *)0);
 }
 return last;
}

canonical_original_code:
struct ConfigEntryT **CfgNext(int WhichCfg, struct ConfigEntryT **last)
{
 if (last == ((void *)0)) {
  return (struct ConfigEntryT **) configinfo[WhichCfg].config_info;
 }
 last++;
 if (last
     > (struct ConfigEntryT **) configinfo[WhichCfg].config_info
     + configinfo[WhichCfg].config_info_size
     - 1
  ) {
  return ((void *)0);
 }
 return last;
}

variable_types:
last
struct ConfigEntryT **


ConvertBabelName

decompiled_code:
void *__fastcall ConvertBabelName(__int64 a1)
{
void *result; // rax

result = SearchRtfCmd(a1, 4u);
if ( result )
result = (void *)ConvertString(result);
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1)
{
void *result; // rax

result = func3(a1, 4u);
if ( result )
result = (void *)ConvertString(result);
return result;
}

original_code:
void
ConvertBabelName(char *name)
{
 char *s = SearchRtfCmd(name, 4);
 if (s != ((void *)0))
  ConvertString(s);
}

variable_types:
name
char *


IgnoreVar

decompiled_code:
__int64 IgnoreVar()
{
__int64 result; // rax

do
result = getTexChar();
while ( (result & 0xDF) != 0 && (_BYTE)result != 10 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

do
result = getTexChar();
while ( (result & 0xDF) != 0 && (_BYTE)result != 10 );
return result;
}

original_code:
void
IgnoreVar(void)
{
 char c;
 while ((c = getTexChar()) && c != '\n' && c != ' '){}
}

canonical_original_code:
void IgnoreVar()
{
 char c;
 while ((c = getTexChar()) && c != '\n' && c != ' '){}
}


IgnoreCmd

decompiled_code:
__int64 IgnoreCmd()
{
char v0; // al
char v1; // bl

do
v0 = getTexChar();
while ( v0 != 92 && v0 );
do
v1 = getTexChar();
while ( v1 && ((*_ctype_b_loc())[v1] & 0x400) == 0 );
return ungetTexChar((unsigned int)v1);
}

canonical_decompiled_code:
__int64 func1()
{
char v0; // al
char v1; // bl

do
v0 = getTexChar();
while ( v0 != 92 && v0 );
do
v1 = getTexChar();
while ( v1 && ((*_ctype_b_loc())[v1] & 0x400) == 0 );
return ungetTexChar((unsigned int)v1);
}

original_code:
void
IgnoreCmd(void)
{
 char c;
 while ((c = getTexChar()) && c != '\\'){}
 while ((c = getTexChar()) && !((*__ctype_b_loc ())[(int) (((int)c))] & (unsigned short int) _ISalpha)){}
 ungetTexChar(c);
}

canonical_original_code:
void IgnoreCmd()
{
 char c;
 while ((c = getTexChar()) && c != '\\'){}
 while ((c = getTexChar()) && !((*__ctype_b_loc ())[(int) (((int)c))] & (unsigned short) _ISalpha)){}
 ungetTexChar(c);
}


decompiled_code:
__int64 __fastcall Ignore_Environment(const char *a1)
{
unsigned int v1; // ebp
void *v2; // rbx
char v4[136]; // [rsp+0h] [rbp-88h] BYREF

diagnostics(4LL, "Entering IgnoreEnvironment <%s>", a1);
snprintf(v4, 0x64uLL, "\\%s%s%s", "end{", a1, "}");
v1 = TexFontNumber("Typewriter");
CmdEndParagraph(0LL);
CmdStartParagraph(1LL);
fprintRTF("\\qc [Sorry. Ignored ");
fprintRTF("{\\plain\\f%d\\\\begin\\{%s\\} ... \\\\end\\{%s\\}}]", v1, a1, a1);
CmdEndParagraph(0LL);
CmdIndent(2LL);
v2 = (void *)getTexUntil(v4, 0LL);
ConvertString(v4);
free(v2);
return diagnostics(4LL, "Exiting IgnoreEnvironment");
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // ebp
void *v2; // rbx
char v4[136]; // [rsp+0h] [rbp-88h] BYREF

diagnostics(4LL, "Entering IgnoreEnvironment <%s>", a1);
snprintf(v4, 0x64uLL, "\\%s%s%s", "end{", a1, "}");
v1 = TexFontNumber("Typewriter");
CmdEndParagraph(0LL);
CmdStartParagraph(1LL);
fprintRTF("\\qc [Sorry. Ignored ");
fprintRTF("{\\plain\\f%d\\\\begin\\{%s\\} ... \\\\end\\{%s\\}}]", v1, a1, a1);
CmdEndParagraph(0LL);
CmdIndent(2LL);
v2 = (void *)getTexUntil(v4, 0LL);
ConvertString(v4);
free(v2);
return diagnostics(4LL, "Exiting IgnoreEnvironment");
}

original_code:
void
Ignore_Environment(char *cCommand)
{
 char unknown_environment[100];
 char *buffer;
 int font;
 diagnostics(4, "Entering IgnoreEnvironment <%s>", cCommand);
 snprintf(unknown_environment, 100, "\\%s%s%s", "end{", cCommand, "}");
 font = TexFontNumber("Typewriter");
 CmdEndParagraph(0);
 CmdStartParagraph(1);
 fprintRTF("\\qc [Sorry. Ignored ");
 fprintRTF("{\\plain\\f%d\\\\begin\\{%s\\} ... \\\\end\\{%s\\}}]", font, cCommand, cCommand);
 CmdEndParagraph(0);
 CmdIndent(2);
 buffer = getTexUntil(unknown_environment,0);
 ConvertString(unknown_environment);
 free(buffer);
 diagnostics(4, "Exiting IgnoreEnvironment");
}

variable_types:
buffer
char *

variable_types: font int


TryVariableIgnore

decompiled_code:
_BOOL8 __fastcall TryVariableIgnore(char *src)
{
const char *v2; // rax
_BOOL4 v3; // edx
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
__int64 v7; // rcx
const char *v8; // rsi
char v9; // dl
bool v10; // cf
bool v11; // zf
__int64 v12; // rcx
char v13; // dl
bool v14; // cf
bool v15; // zf
__int64 v16; // rcx
char v17; // dl
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
const char *v22; // rsi
bool v23; // cl
bool v24; // cf
bool v25; // zf
const char *v26; // rdi
__int64 v27; // rcx
const char *v28; // rsi
char v29; // dl
bool v30; // cf
bool v31; // zf
const char *v32; // rdi
__int64 v33; // rcx
const char *v34; // rsi
bool v35; // dl
bool v36; // cf
bool v37; // zf
const char *v38; // rdi
__int64 v39; // rcx
const char *v40; // rsi
size_t v42; // rax
char *v43; // rbp
char v44[152]; // [rsp+0h] [rbp-98h] BYREF

if ( strlen(src) > 0x63 )
{
diagnostics(1LL, "Command <%s> is too long", src);
v3 = 0;
}
else
{
v44[0] = 92;
v44[1] = 0;
strcat(v44, src);
v2 = (const char *)SearchRtfCmd(v44, 2LL);
v3 = 0;
v4 = 0;
v5 = v2 == 0LL;
if ( v2 )
{
v6 = "NUMBER";
v7 = 7LL;
v8 = v2;
do
{
if ( !v7 )
break;
v4 = *v8 < (unsigned int)*v6;
v5 = *v8++ == *v6++;
--v7;
}
while ( v5 );
v9 = (!v4 && !v5) - v4;
v10 = 0;
v11 = v9 == 0;
if ( !v9 )
goto LABEL_36;
v6 = "MEASURE";
v12 = 8LL;
v8 = v2;
do
{
if ( !v12 )
break;
v10 = *v8 < (unsigned int)*v6;
v11 = *v8++ == *v6++;
--v12;
}
while ( v11 );
v13 = (!v10 && !v11) - v10;
v14 = 0;
v15 = v13 == 0;
if ( !v13 )
goto LABEL_36;
v6 = "OTHER";
v16 = 6LL;
v8 = v2;
do
{
if ( !v16 )
break;
v14 = *v8 < (unsigned int)*v6;
v15 = *v8++ == *v6++;
--v16;
}
while ( v15 );
v17 = (!v14 && !v15) - v14;
v18 = 0;
v19 = v17 == 0;
if ( v17 )
{
v20 = "COMMAND";
v21 = 8LL;
v22 = v2;
do
{
if ( !v21 )
break;
v18 = *v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
if ( (!v18 && !v19) == v18 )
{
IgnoreCmd(v20, v22);
v3 = 1;
}
else
{
v23 = strcmp(v2, "SINGLE") != 0;
v3 = 1;
v24 = 0;
v25 = !v23;
if ( v23 )
{
v26 = "PARAMETER";
v27 = 10LL;
v28 = v2;
do
{
if ( !v27 )
break;
v24 = *v28 < (unsigned int)*v26;
v25 = *v28++ == *v26++;
--v27;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( v29 )
{
v32 = "TWOPARAMETER";
v33 = 13LL;
v34 = v2;
do
{
if ( !v33 )
break;
v30 = *v34 < (unsigned int)*v32;
v31 = *v34++ == *v32++;
--v33;
}
while ( v31 );
if ( (!v30 && !v31) == v30 )
{
CmdIgnoreParameter(2LL, v34);
v3 = 1;
}
else
{
v35 = strcmp(v2, "ENVIRONMENT") != 0;
v36 = 0;
v37 = !v35;
if ( v35 )
{
v38 = "ENVCMD";
v39 = 7LL;
v40 = v2;
do
{
if ( !v39 )
break;
v36 = *v40 < (unsigned int)*v38;
v37 = *v40++ == *v38++;
--v39;
}
while ( v37 );
if ( (!v36 && !v37) == v36 )
{
PushEnvironment(9LL, v40);
v3 = 1;
}
else
{
v3 = strcmp(v2, "PACKAGE") == 0;
}
}
else
{
v42 = strlen(src);
v43 = (char *)malloc(v42 + 5);
if ( !v43 )
diagnostics(0LL, "malloc error -> out of memory!\n");
strcpy(v43, "end{");
strcat(v43, src);
*(_WORD *)&v43[strlen(v43)] = 125;
Ignore_Environment(v43);
free(v43);
v3 = 1;
}
}
}
else
{
CmdIgnoreParameter(1LL, v28);
v3 = 1;
}
}
}
}
else
{
LABEL_36:
IgnoreVar(v6, v8);
v3 = 1;
}
}
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *src)
{
const char *v2; // rax
_BOOL4 v3; // edx
bool v4; // cf
bool v5; // zf
const char *v6; // rdi
__int64 v7; // rcx
const char *v8; // rsi
char v9; // dl
bool v10; // cf
bool v11; // zf
__int64 v12; // rcx
char v13; // dl
bool v14; // cf
bool v15; // zf
__int64 v16; // rcx
char v17; // dl
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
const char *v22; // rsi
bool v23; // cl
bool v24; // cf
bool v25; // zf
const char *v26; // rdi
__int64 v27; // rcx
const char *v28; // rsi
char v29; // dl
bool v30; // cf
bool v31; // zf
const char *v32; // rdi
__int64 v33; // rcx
const char *v34; // rsi
bool v35; // dl
bool v36; // cf
bool v37; // zf
const char *v38; // rdi
__int64 v39; // rcx
const char *v40; // rsi
size_t v42; // rax
char *v43; // rbp
char v44[152]; // [rsp+0h] [rbp-98h] BYREF

if ( strlen(src) > 0x63 )
{
diagnostics(1LL, "Command <%s> is too long", src);
v3 = 0;
}
else
{
v44[0] = 92;
v44[1] = 0;
strcat(v44, src);
v2 = (const char *)SearchRtfCmd(v44, 2LL);
v3 = 0;
v4 = 0;
v5 = v2 == 0LL;
if ( v2 )
{
v6 = "NUMBER";
v7 = 7LL;
v8 = v2;
do
{
if ( !v7 )
break;
v4 = *v8 < (unsigned int)*v6;
v5 = *v8++ == *v6++;
--v7;
}
while ( v5 );
v9 = (!v4 && !v5) - v4;
v10 = 0;
v11 = v9 == 0;
if ( !v9 )
goto LABEL_36;
v6 = "MEASURE";
v12 = 8LL;
v8 = v2;
do
{
if ( !v12 )
break;
v10 = *v8 < (unsigned int)*v6;
v11 = *v8++ == *v6++;
--v12;
}
while ( v11 );
v13 = (!v10 && !v11) - v10;
v14 = 0;
v15 = v13 == 0;
if ( !v13 )
goto LABEL_36;
v6 = "OTHER";
v16 = 6LL;
v8 = v2;
do
{
if ( !v16 )
break;
v14 = *v8 < (unsigned int)*v6;
v15 = *v8++ == *v6++;
--v16;
}
while ( v15 );
v17 = (!v14 && !v15) - v14;
v18 = 0;
v19 = v17 == 0;
if ( v17 )
{
v20 = "COMMAND";
v21 = 8LL;
v22 = v2;
do
{
if ( !v21 )
break;
v18 = *v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
if ( (!v18 && !v19) == v18 )
{
func1(v20, v22);
v3 = 1;
}
else
{
v23 = strcmp(v2, "SINGLE") != 0;
v3 = 1;
v24 = 0;
v25 = !v23;
if ( v23 )
{
v26 = "PARAMETER";
v27 = 10LL;
v28 = v2;
do
{
if ( !v27 )
break;
v24 = *v28 < (unsigned int)*v26;
v25 = *v28++ == *v26++;
--v27;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( v29 )
{
v32 = "TWOPARAMETER";
v33 = 13LL;
v34 = v2;
do
{
if ( !v33 )
break;
v30 = *v34 < (unsigned int)*v32;
v31 = *v34++ == *v32++;
--v33;
}
while ( v31 );
if ( (!v30 && !v31) == v30 )
{
CmdIgnoreParameter(2LL, v34);
v3 = 1;
}
else
{
v35 = strcmp(v2, "ENVIRONMENT") != 0;
v36 = 0;
v37 = !v35;
if ( v35 )
{
v38 = "ENVCMD";
v39 = 7LL;
v40 = v2;
do
{
if ( !v39 )
break;
v36 = *v40 < (unsigned int)*v38;
v37 = *v40++ == *v38++;
--v39;
}
while ( v37 );
if ( (!v36 && !v37) == v36 )
{
PushEnvironment(9LL, v40);
v3 = 1;
}
else
{
v3 = strcmp(v2, "PACKAGE") == 0;
}
}
else
{
v42 = strlen(src);
v43 = (char *)malloc(v42 + 5);
if ( !v43 )
diagnostics(0LL, "malloc error -> out of memory!\n");
strcpy(v43, "end{");
strcat(v43, src);
*(_WORD *)&v43[strlen(v43)] = 125;
func2(v43);
free(v43);
v3 = 1;
}
}
}
else
{
CmdIgnoreParameter(1LL, v28);
v3 = 1;
}
}
}
}
else
{
LABEL_36:
func0(v6, v8);
v3 = 1;
}
}
}
return v3;
}

original_code:
bool
TryVariableIgnore(char *command)
{
 const char *RtfCommand;
 char TexCommand[128];
 bool result = 1;
 if (strlen(command) >= 100) {
  diagnostics(1, "Command <%s> is too long", command);
  return 0;
 }
 TexCommand[0] = '\\';
 TexCommand[1] = '\0';
 strcat(TexCommand, command);
 RtfCommand = SearchRtfCmd(TexCommand, 2);
 if (RtfCommand == ((void *)0))
  result = 0;
 else if (strcmp(RtfCommand, "NUMBER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "MEASURE") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "OTHER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "COMMAND") == 0)
  IgnoreCmd();
 else if (strcmp(RtfCommand, "SINGLE") == 0)
  {}
 else if (strcmp(RtfCommand, "PARAMETER") == 0)
  CmdIgnoreParameter(01);
    else if (strcmp(RtfCommand, "TWOPARAMETER") == 0)
         CmdIgnoreParameter(02);
 else if (strcmp(RtfCommand, "ENVIRONMENT") == 0) {
  char *str;
  str = malloc(strlen(command) + 5);
  if (str == ((void *)0))
   diagnostics(0, "malloc error -> out of memory!\n");
  strcpy(str, "end{");
  strcat(str, command);
  strcat(str, "}");
  Ignore_Environment(str);
  free(str);
 } else if (strcmp(RtfCommand, "ENVCMD") == 0)
  PushEnvironment(9);
 else if (strcmp(RtfCommand, "PACKAGE") == 0)
  {}
 else
  result = 0;
 return (result);
}

canonical_original_code:
int TryVariableIgnore(char *command)
{
 char *RtfCommand;
 char TexCommand[128];
 int result = 1;
 if (strlen(command) >= 100) {
  diagnostics(1, "Command <%s> is too long", command);
  return 0;
 }
 TexCommand[0] = '\\';
 TexCommand[1] = '\0';
 strcat(TexCommand, command);
 RtfCommand = SearchRtfCmd(TexCommand, 2);
 if (RtfCommand == ((void *)0))
  result = 0;
 else if (strcmp(RtfCommand, "NUMBER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "MEASURE") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "OTHER") == 0)
  IgnoreVar();
 else if (strcmp(RtfCommand, "COMMAND") == 0)
  IgnoreCmd();
 else if (strcmp(RtfCommand, "SINGLE") == 0)
  {}
 else if (strcmp(RtfCommand, "PARAMETER") == 0)
  CmdIgnoreParameter(01);
    else if (strcmp(RtfCommand, "TWOPARAMETER") == 0)
         CmdIgnoreParameter(02);
 else if (strcmp(RtfCommand, "ENVIRONMENT") == 0) {
  char *str;
  str = malloc(strlen(command) + 5);
  if (str == ((void *)0))
   diagnostics(0, "malloc error -> out of memory!\n");
  strcpy(str, "end{");
  strcat(str, command);
  strcat(str, "}");
  Ignore_Environment(str);
  free(str);
 } else if (strcmp(RtfCommand, "ENVCMD") == 0)
  PushEnvironment(9);
 else if (strcmp(RtfCommand, "PACKAGE") == 0)
  {}
 else
  result = 0;
 return (result);
}

variable_types:
command
char *

variable_types:
RtfCommand
char *

variable_types:
TexCommand
char [128]

variable_types: result int

variable_types:
str
char *


myprintStack

decompiled_code:
int myprintStack()
{
int result; // eax
__int64 v1; // rbx

result = fprintf(stderr, "\nStack Status top=%d\n", (unsigned int)top);
if ( top > 0 )
{
v1 = 0LL;
do
{
fprintf(
stderr,
" #%d lev=%d bracket=%d\n",
(unsigned int)(v1 + 1),
(unsigned int)dword_364[2 * v1],
(unsigned int)dword_368[2 * v1]);
result = 2 * ++v1;
}
while ( top > 2 * (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
__int64 v1; // rbx

result = fprintf(stderr, "\nStack Status top=%d\n", (unsigned int)top);
if ( top > 0 )
{
v1 = 0LL;
do
{
fprintf(
stderr,
" #%d lev=%d bracket=%d\n",
(unsigned int)(v1 + 1),
(unsigned int)dword_364[2 * v1],
(unsigned int)dword_368[2 * v1]);
result = 2 * ++v1;
}
while ( top > 2 * (int)v1 );
}
return result;
}

original_code:
void
myprintStack(void)
{
int i, lev, brack;
 fprintf(stderr, "\nStack Status top=%d\n",top);
 i=0;
 while (2*i<top) {
  lev = stack[2*i+1];
  brack = stack[2*i+2];
  i++;
  fprintf(stderr, " #%d lev=%d bracket=%d\n", i, lev, brack);
 }
}

canonical_original_code:
void myprintStack()
{
int i; int lev; int brack;
 fprintf(stderr, "\nStack Status top=%d\n",top);
 i=0;
 while (2*i<top) {
  lev = stack[2*i+1];
  brack = stack[2*i+2];
  i++;
  fprintf(stderr, " #%d lev=%d bracket=%d\n", i, lev, brack);
 }
}

variable_types: i int

variable_types: lev int

variable_types: brack int


BasicPush

decompiled_code:
__int64 __fastcall BasicPush(int a1, int a2)
{
int v2; // eax

v2 = top;
stack[top + 1] = a1;
v2 += 2;
top = v2;
stack[v2] = a2;
if ( v2 > 999 )
diagnostics(0LL, "Nesting too deep. latex2rtf bug, if file TeXs properly");
return (unsigned int)top;
}

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

v2 = top;
stack[top + 1] = a1;
v2 += 2;
top = v2;
stack[v2] = a2;
if ( v2 > 999 )
diagnostics(0LL, "Nesting too deep. latex2rtf bug, if file TeXs properly");
return (unsigned int)top;
}

original_code:
int
BasicPush(int lev, int brack)
{
 ++top;
 stack[top] = lev;
 ++top;
 stack[top] = brack;
 if (top >= 1000)
  diagnostics(0, "Nesting too deep.  latex2rtf bug, if file TeXs properly");
 return top;
}


BasicPop

decompiled_code:
__int64 __fastcall BasicPop(_DWORD *a1, _DWORD *a2)
{
int v2; // eax

v2 = top;
*a2 = stack[top];
*a1 = stack[v2 - 1];
top = v2 - 2;
if ( v2 - 2 < 0 )
diagnostics(0LL, "Nesting problem. latex2rtf bug, if file TeXs properly");
return (unsigned int)top;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
int v2; // eax

v2 = top;
*a2 = stack[top];
*a1 = stack[v2 - 1];
top = v2 - 2;
if ( v2 - 2 < 0 )
diagnostics(0LL, "Nesting problem. latex2rtf bug, if file TeXs properly");
return (unsigned int)top;
}

original_code:
int
BasicPop(int *lev, int *brack)
{
 *brack = stack[top];
 --top;
 *lev = stack[top];
 --top;
 if (top < 0)
  diagnostics(0, "Nesting problem.  latex2rtf bug, if file TeXs properly");
 return top;
}

variable_types:
lev
int *

variable_types:
brack
int *


PopLevels

decompiled_code:
__int64 PopLevels()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

BasicPop(v1, &BraceLevel);
return v1[0];
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

func2(v1, &BraceLevel);
return v1[0];
}

original_code:
int
PopLevels(void)
{
 int level;
 (void) BasicPop(&level, &BraceLevel);
 return level;
}

canonical_original_code:
int PopLevels()
{
 int level;
 (void) BasicPop(&level, &BraceLevel);
 return level;
}

variable_types: level int


getStackRecursionLevel

decompiled_code:
__int64 getStackRecursionLevel()
{
unsigned int v0; // ebx
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = RecursionLevel;
BasicPop(v3, &v2);
while ( (int)BasicPop(v3, &v2) >= 0 && v2 >= BraceLevel )
v0 = v3[0];
BasicPush(v3[0], v2);
BasicPush(v0, BraceLevel);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = RecursionLevel;
func2(v3, &v2);
while ( (int)func2(v3, &v2) >= 0 && v2 >= BraceLevel )
v0 = v3[0];
func1(v3[0], v2);
func1(v0, BraceLevel);
return v0;
}

original_code:
int
getStackRecursionLevel(void)
{
int PopLevel, PopBrack, PPopLevel, PPopBrack, size;
  PPopLevel = RecursionLevel;
  PPopBrack = BraceLevel;
  size = BasicPop(&PopLevel, &PopBrack);
  while ((size = BasicPop(&PopLevel, &PopBrack)) >= 0) {
   if (PopBrack < BraceLevel) {
    break;
   }
   PPopLevel = PopLevel;
   PPopBrack = PopBrack;
  }
  (void) BasicPush(PopLevel, PopBrack);
  (void) BasicPush(PPopLevel, BraceLevel);
  return PPopLevel;
}

canonical_original_code:
int getStackRecursionLevel()
{
int PopLevel; int PopBrack; int PPopLevel; int PPopBrack; int size;
  PPopLevel = RecursionLevel;
  PPopBrack = BraceLevel;
  size = BasicPop(&PopLevel, &PopBrack);
  while ((size = BasicPop(&PopLevel, &PopBrack)) >= 0) {
   if (PopBrack < BraceLevel) {
    break;
   }
   PPopLevel = PopLevel;
   PPopBrack = PopBrack;
  }
  (void) BasicPush(PopLevel, PopBrack);
  (void) BasicPush(PPopLevel, BraceLevel);
  return PPopLevel;
}

variable_types: PopLevel int

variable_types: PopBrack int

variable_types: PPopLevel int

variable_types: PPopBrack int

variable_types: size int


CleanStack

decompiled_code:
__int64 CleanStack()
{
__int64 result; // rax
int i; // edi
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = diagnostics(5LL, "Cleaning Stack");
if ( top > 3 )
{
BasicPop(&v3, &v2);
BasicPop(v5, &v4);
for ( i = v5[0]; v3 == v5[0]; i = v5[0] )
{
if ( v2 != v4 )
break;
if ( top <= 0 )
break;
BasicPop(v5, &v4);
}
BasicPush(i, v4);
if ( v3 != v5[0] || (result = v4, v2 != v4) )
result = BasicPush(v3, v2);
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
int i; // edi
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = diagnostics(5LL, "Cleaning Stack");
if ( top > 3 )
{
func2(&v3, &v2);
func2(v5, &v4);
for ( i = v5[0]; v3 == v5[0]; i = v5[0] )
{
if ( v2 != v4 )
break;
if ( top <= 0 )
break;
func2(v5, &v4);
}
func1(i, v4);
if ( v3 != v5[0] || (result = v4, v2 != v4) )
result = func1(v3, v2);
}
return result;
}

original_code:
void
CleanStack(void)
{
int PopLevel, PopBrack, PPopLevel, PPopBrack;
 diagnostics(5, "Cleaning Stack");
 if (top<4) return;
 BasicPop(&PPopLevel, &PPopBrack);
 BasicPop(&PopLevel, &PopBrack);
 while (PPopLevel == PopLevel && PPopBrack == PopBrack && top>0)
  BasicPop(&PopLevel, &PopBrack);
 BasicPush(PopLevel, PopBrack);
 if (PPopLevel != PopLevel || PPopBrack != PopBrack)
  BasicPush(PPopLevel, PPopBrack);
}

canonical_original_code:
void CleanStack()
{
int PopLevel; int PopBrack; int PPopLevel; int PPopBrack;
 diagnostics(5, "Cleaning Stack");
 if (top<4) return;
 BasicPop(&PPopLevel, &PPopBrack);
 BasicPop(&PopLevel, &PopBrack);
 while (PPopLevel == PopLevel && PPopBrack == PopBrack && top>0)
  BasicPop(&PopLevel, &PopBrack);
 BasicPush(PopLevel, PopBrack);
 if (PPopLevel != PopLevel || PPopBrack != PopBrack)
  BasicPush(PPopLevel, PPopBrack);
}


PushLevels

decompiled_code:
__int64 PushLevels()
{
diagnostics(5LL, "PushLevels");
CleanStack();
return BasicPush(RecursionLevel, BraceLevel);
}

canonical_decompiled_code:
__int64 func6()
{
diagnostics(5LL, "PushLevels");
func5();
return func1(RecursionLevel, BraceLevel);
}

original_code:
void
PushLevels(void)
{
 diagnostics(5, "PushLevels");
 CleanStack();
 (void) BasicPush(RecursionLevel, BraceLevel);
}

canonical_original_code:
void PushLevels()
{
 diagnostics(5, "PushLevels");
 CleanStack();
 (void) BasicPush(RecursionLevel, BraceLevel);
}


InitializeStack

decompiled_code:
__int64 InitializeStack()
{
__int64 result; // rax

BraceLevel = 0;
RecursionLevel = 1;
result = PushLevels();
BraceLevel = 1;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

BraceLevel = 0;
RecursionLevel = 1;
result = func6();
BraceLevel = 1;
return result;
}

original_code:
void
InitializeStack(void)
{
 BraceLevel=0;
 RecursionLevel = 1;
 PushLevels();
 BraceLevel=1;
}

canonical_original_code:
void InitializeStack()
{
 BraceLevel=0;
 RecursionLevel = 1;
 PushLevels();
 BraceLevel=1;
}


PushBrace

decompiled_code:
__int64 PushBrace()
{
__int64 result; // rax

result = BasicPush(RecursionLevel, BraceLevel);
++BraceLevel;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax

result = func1(RecursionLevel, BraceLevel);
++BraceLevel;
return result;
}

original_code:
void
PushBrace(void)
{
 BasicPush(RecursionLevel,BraceLevel);
 ++BraceLevel;
}

canonical_original_code:
void PushBrace()
{
 BasicPush(RecursionLevel,BraceLevel);
 ++BraceLevel;
}


PopBrace

decompiled_code:
__int64 PopBrace()
{
int v0; // ebx
int i; // esi
int v3; // [rsp+8h] [rbp-10h] BYREF
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

diagnostics(6LL, "Popping Brace Level");
--BraceLevel;
v0 = RecursionLevel;
BasicPop(v4, &v3);
for ( i = v3; v3 >= BraceLevel; i = v3 )
{
if ( v0 > v4[0] )
v0 = v4[0];
BasicPop(v4, &v3);
}
BasicPush(v4[0], i);
BasicPush(v0, BraceLevel);
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // ebx
int i; // esi
int v3; // [rsp+8h] [rbp-10h] BYREF
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

diagnostics(6LL, "Popping Brace Level");
--BraceLevel;
v0 = RecursionLevel;
func2(v4, &v3);
for ( i = v3; v3 >= BraceLevel; i = v3 )
{
if ( v0 > v4[0] )
v0 = v4[0];
func2(v4, &v3);
}
func1(v4[0], i);
func1(v0, BraceLevel);
return (unsigned int)v0;
}

original_code:
int
PopBrace(void)
{
int PopLevel, PopBrack, PPopLevel;
 diagnostics(6,"Popping Brace Level");
 BraceLevel--;
 PPopLevel = RecursionLevel;
 BasicPop(&PopLevel, &PopBrack);
 while (PopBrack >= BraceLevel) {
  if (PopLevel < PPopLevel) PPopLevel = PopLevel;
  BasicPop(&PopLevel, &PopBrack);
 }
 BasicPush(PopLevel, PopBrack);
 BasicPush(PPopLevel, BraceLevel);
 return PPopLevel;
}

canonical_original_code:
int PopBrace()
{
int PopLevel; int PopBrack; int PPopLevel;
 diagnostics(6,"Popping Brace Level");
 BraceLevel--;
 PPopLevel = RecursionLevel;
 BasicPop(&PopLevel, &PopBrack);
 while (PopBrack >= BraceLevel) {
  if (PopLevel < PPopLevel) PPopLevel = PopLevel;
  BasicPop(&PopLevel, &PopBrack);
 }
 BasicPush(PopLevel, PopBrack);
 BasicPush(PPopLevel, BraceLevel);
 return PPopLevel;
}