tokenmsg

decompiled_code:
const char **__fastcall tokenmsg(char *src)
{
char *v1; // rbp
const char **v2; // r12
char *v3; // r14
int v4; // ebx
char *v5; // rsi
char *v6; // rsi
char *v7; // rsi
char *v9; // rsi
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = (char *)malloc(0x100uLL);
v2 = (const char **)malloc(0x30uLL);
v3 = (char *)malloc(0x100uLL);
*v2 = v3;
v2[1] = (const char *)malloc(0x100uLL);
v2[2] = (const char *)malloc(0x100uLL);
v2[3] = (const char *)malloc(0x100uLL);
v2[4] = (const char *)malloc(0x100uLL);
v4 = interpret(src);
*((_DWORD *)v2 + 11) = v4;
strcpy(v3, src);
strcpy(v1, src);
if ( v4 == 3 || (v1 = strtok_r(v1, "&+-", save_ptr), *((_DWORD *)v2 + 11) != 4) )
{
v5 = strtok_r(v1, "`\n", save_ptr);
if ( !v5 )
{
puts("Error tokenizing ack!");
exit(1);
}
v1 = 0LL;
strcpy((char *)v2[1], v5);
*((_DWORD *)v2 + 10) = atoi(v2[1]);
}
v6 = strtok_r(v1, "`\n", save_ptr);
if ( !v6 )
{
puts("Error tokenizing src!");
exit(1);
}
strcpy((char *)v2[2], v6);
v7 = strtok_r(0LL, "`\n", save_ptr);
if ( !v7 )
{
puts("Error tokenizing dest!");
exit(1);
}
strcpy((char *)v2[3], v7);
if ( (unsigned int)(*((_DWORD *)v2 + 11) - 3) > 1 )
return v2;
v9 = strtok_r(0LL, "`\n", save_ptr);
if ( !v9 )
{
printf("[%s]\nError tokenizing payload!\n", *v2);
exit(1);
}
strcpy((char *)v2[4], v9);
return v2;
}

canonical_decompiled_code:
const char **__fastcall func7(char *src)
{
char *v1; // rbp
const char **v2; // r12
char *v3; // r14
int v4; // ebx
char *v5; // rsi
char *v6; // rsi
char *v7; // rsi
char *v9; // rsi
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = (char *)malloc(0x100uLL);
v2 = (const char **)malloc(0x30uLL);
v3 = (char *)malloc(0x100uLL);
*v2 = v3;
v2[1] = (const char *)malloc(0x100uLL);
v2[2] = (const char *)malloc(0x100uLL);
v2[3] = (const char *)malloc(0x100uLL);
v2[4] = (const char *)malloc(0x100uLL);
v4 = func3(src);
*((_DWORD *)v2 + 11) = v4;
strcpy(v3, src);
strcpy(v1, src);
if ( v4 == 3 || (v1 = strtok_r(v1, "&+-", save_ptr), *((_DWORD *)v2 + 11) != 4) )
{
v5 = strtok_r(v1, "`\n", save_ptr);
if ( !v5 )
{
puts("Error tokenizing ack!");
exit(1);
}
v1 = 0LL;
strcpy((char *)v2[1], v5);
*((_DWORD *)v2 + 10) = atoi(v2[1]);
}
v6 = strtok_r(v1, "`\n", save_ptr);
if ( !v6 )
{
puts("Error tokenizing src!");
exit(1);
}
strcpy((char *)v2[2], v6);
v7 = strtok_r(0LL, "`\n", save_ptr);
if ( !v7 )
{
puts("Error tokenizing dest!");
exit(1);
}
strcpy((char *)v2[3], v7);
if ( (unsigned int)(*((_DWORD *)v2 + 11) - 3) > 1 )
return v2;
v9 = strtok_r(0LL, "`\n", save_ptr);
if ( !v9 )
{
printf("[%s]\nError tokenizing payload!\n", *v2);
exit(1);
}
strcpy((char *)v2[4], v9);
return v2;
}

original_code:
struct msgtok *tokenmsg(char *msg)
{
    char *tok, *saveptr;
    char *temp = malloc(256);
    struct msgtok *msgtok = malloc(sizeof(struct msgtok));
    msgtok->orig = malloc(256);
    msgtok->ack = malloc(256);
    msgtok->src = malloc(256);
    msgtok->dest = malloc(256);
    msgtok->pay = malloc(256);
    msgtok->type = interpret(msg);
    strcpy(msgtok->orig, msg);
    strcpy(temp, msg);
    if (msgtok->type != enumrealmsg) {
        tok = strtok_r(temp, "&+-", &saveptr);
        temp = tok;
    }
    if(msgtok->type != enumdvrmsg)
    {
 tok = strtok_r(temp, "`\n", &saveptr);
 if(tok == ((void *)0))
 {
  printf("Error tokenizing ack!\n");
  exit(1);
 }
 strcpy(msgtok->ack, tok);
 msgtok->acknum = atoi(msgtok->ack);
 temp = ((void *)0);
    }
    tok = strtok_r(temp, "`\n", &saveptr);
    if(tok == ((void *)0))
    {
        printf("Error tokenizing src!\n");
        exit(1);
    }
    strcpy(msgtok->src, tok);
    tok = strtok_r(((void *)0), "`\n", &saveptr);
    if(tok == ((void *)0))
    {
        printf("Error tokenizing dest!\n");
        exit(1);
    }
    strcpy(msgtok->dest, tok);
    if (msgtok->type == enumrealmsg || msgtok->type == enumdvrmsg)
    {
 tok = strtok_r(((void *)0), "`\n", &saveptr);
 if(tok == ((void *)0))
 {
     printf("[%s]\nError tokenizing payload!\n", msgtok->orig);
     exit(1);
 }
 else
     strcpy(msgtok->pay, tok);
    }
    return msgtok;
}

canonical_original_code:
struct msgtok *tokenmsg(char *msg)
{
    char *tok; char *saveptr;
    char *temp = malloc(256);
    struct msgtok *msgtok = malloc(sizeof(struct msgtok));
    msgtok->orig = malloc(256);
    msgtok->ack = malloc(256);
    msgtok->src = malloc(256);
    msgtok->dest = malloc(256);
    msgtok->pay = malloc(256);
    msgtok->type = interpret(msg);
    strcpy(msgtok->orig, msg);
    strcpy(temp, msg);
    if (msgtok->type != enumrealmsg) {
        tok = strtok_r(temp, "&+-", &saveptr);
        temp = tok;
    }
    if(msgtok->type != enumdvrmsg)
    {
 tok = strtok_r(temp, "`\n", &saveptr);
 if(tok == ((void *)0))
 {
  printf("Error tokenizing ack!\n");
  exit(1);
 }
 strcpy(msgtok->ack, tok);
 msgtok->acknum = atoi(msgtok->ack);
 temp = ((void *)0);
    }
    tok = strtok_r(temp, "`\n", &saveptr);
    if(tok == ((void *)0))
    {
        printf("Error tokenizing src!\n");
        exit(1);
    }
    strcpy(msgtok->src, tok);
    tok = strtok_r(((void *)0), "`\n", &saveptr);
    if(tok == ((void *)0))
    {
        printf("Error tokenizing dest!\n");
        exit(1);
    }
    strcpy(msgtok->dest, tok);
    if (msgtok->type == enumrealmsg || msgtok->type == enumdvrmsg)
    {
 tok = strtok_r(((void *)0), "`\n", &saveptr);
 if(tok == ((void *)0))
 {
     printf("[%s]\nError tokenizing payload!\n", msgtok->orig);
     exit(1);
 }
 else
     strcpy(msgtok->pay, tok);
    }
    return msgtok;
}

variable_types:
tok
char *

variable_types:
saveptr
char *

variable_types:
temp
char *

return_type: struct msgtok { char *orig; char *ack; int acknum; int type; } *


iamdest

repo: jknightdoeswork/nettop

decompiled_code:
_BOOL8 __fastcall iamdest(char *s2, __int64 a2)
{
return strcmp(*(const char **)(a2 + 24), s2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(char *s2, __int64 a2)
{
return strcmp(*(const char **)(a2 + 24), s2) == 0;
}

original_code:
int iamdest(char *name, struct msgtok *tok)
{
    if(strcmp(tok->dest, name) == 0)
        return 1;
    else
        return 0;
}

variable_types:
name
char *

variable_types: struct msgtok { char *orig; char *ack; int acknum; int type; } *

return_type: int


sendbackack

decompiled_code:
int __fastcall sendbackack(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
int result; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "+%d`%s`%s`", *(unsigned int *)(a1 + 40), *(const char **)(a1 + 24), *(const char **)(a1 + 16));
v1 = *(_QWORD *)(a1 + 16);
v2 = getnodefromname(*(_QWORD *)(a1 + 24));
v3 = getwindowlist(v2, v1);
if ( v3 )
result = enqueue(*(_QWORD *)(v3 + 16), v5);
else
result = fprintf(
stderr,
"sendbackack could not find window list %s-%s\n",
*(const char **)(a1 + 24),
*(const char **)(a1 + 16));
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
int result; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "+%d`%s`%s`", *(unsigned int *)(a1 + 40), *(const char **)(a1 + 24), *(const char **)(a1 + 16));
v1 = *(_QWORD *)(a1 + 16);
v2 = getnodefromname(*(_QWORD *)(a1 + 24));
v3 = getwindowlist(v2, v1);
if ( v3 )
result = enqueue(*(_QWORD *)(v3 + 16), v5);
else
result = fprintf(
stderr,
"sendbackack could not find window list %s-%s\n",
*(const char **)(a1 + 24),
*(const char **)(a1 + 16));
return result;
}

original_code:
void sendbackack(struct msgtok *tok)
{
    char ackmsg[256];
    sprintf(ackmsg, "+%d`%s`%s`", tok->acknum, tok->dest, tok->src);
    struct windowlist* wl = getwindowlist(getnodefromname(tok->dest), tok->src);
    if(wl == ((void *)0)) {
        fprintf(stderr, "sendbackack could not find window list %s-%s\n", tok->dest, tok->src);
     return;
    }
    enqueue(wl->ackq, ackmsg);
    return;
}

canonical_original_code:
void sendbackack(struct msgtok *tok)
{
    char ackmsg[256];
    sprintf(ackmsg, "+%d`%s`%s`", tok->acknum, tok->dest, tok->src);
    struct windowlist *wl = getwindowlist(getnodefromname(tok->dest), tok->src);
    if(wl == ((void *)0)) {
        fprintf(stderr, "sendbackack could not find window list %s-%s\n", tok->dest, tok->src);
     return;
    }
    enqueue(wl->ackq, ackmsg);
    return;
}

variable_types:
ackmsg
char [256]

variable_types: struct windowlist { struct window { struct packet { char *msg; long enqT; int acknum; int received; int sent; struct packet *next; } *head; struct packet *tail; int sz; int max; int first; int last; int cur; } *sendq; struct window *ackq; char *name; struct windowlist *next; } *

return_type: void

user_defined_types: struct msgtok { char *orig; char *ack; int acknum; int type; }

user_defined_types: struct windowlist { struct window *sendq; struct window *ackq; char *name; struct windowlist *next; }

user_defined_types: struct window { struct packet *head; struct packet *tail; int sz; int max; int first; int last; int cur; }


sendbacknack

decompiled_code:
int __fastcall sendbacknack(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
int result; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v6, "-%d`%s`%s`", a2, *(const char **)(a1 + 24), *(const char **)(a1 + 16));
v2 = *(_QWORD *)(a1 + 16);
v3 = getnodefromname(*(_QWORD *)(a1 + 24));
v4 = getwindowlist(v3, v2);
if ( v4 )
result = enqueue(*(_QWORD *)(v4 + 16), v6);
else
result = fprintf(
stderr,
"sendbacknack could not find window list %s-%s\n",
*(const char **)(a1 + 24),
*(const char **)(a1 + 16));
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
int result; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v6, "-%d`%s`%s`", a2, *(const char **)(a1 + 24), *(const char **)(a1 + 16));
v2 = *(_QWORD *)(a1 + 16);
v3 = getnodefromname(*(_QWORD *)(a1 + 24));
v4 = getwindowlist(v3, v2);
if ( v4 )
result = enqueue(*(_QWORD *)(v4 + 16), v6);
else
result = fprintf(
stderr,
"sendbacknack could not find window list %s-%s\n",
*(const char **)(a1 + 24),
*(const char **)(a1 + 16));
return result;
}

original_code:
void sendbacknack(struct msgtok *tok, int out)
{
    char nackmsg[256];
    sprintf(nackmsg, "-%d`%s`%s`", out, tok->dest, tok->src);
    struct windowlist* wl = getwindowlist(getnodefromname(tok->dest), tok->src);
    if(wl == ((void *)0)) {
        fprintf(stderr, "sendbacknack could not find window list %s-%s\n", tok->dest, tok->src);
     return;
    }
    enqueue(wl->ackq, nackmsg);
    return;
}

canonical_original_code:
void sendbacknack(struct msgtok *tok, int out)
{
    char nackmsg[256];
    sprintf(nackmsg, "-%d`%s`%s`", out, tok->dest, tok->src);
    struct windowlist *wl = getwindowlist(getnodefromname(tok->dest), tok->src);
    if(wl == ((void *)0)) {
        fprintf(stderr, "sendbacknack could not find window list %s-%s\n", tok->dest, tok->src);
     return;
    }
    enqueue(wl->ackq, nackmsg);
    return;
}

variable_types: out int

variable_types:
nackmsg
char [256]

user_defined_types: struct packet { char *msg; long enqT; int acknum; int received; int sent; struct packet *next; }


sendnacks

decompiled_code:
int __fastcall sendnacks(__int64 *a1, __int64 a2)
{
__int64 v3; // r12
signed int v4; // ebx
int result; // eax
unsigned int v6; // esi

v3 = *a1;
v4 = *((_DWORD *)a1 + 6);
if ( *a1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = v4++;
if ( *(_DWORD *)(v3 + 16) != v6 )
break;
v3 = *(_QWORD *)(v3 + 32);
v4 = v6 + 1;
if ( !v3 )
return result;
}
result = sendbacknack(a2, v6);
if ( *(_DWORD *)(a2 + 40) <= v4 )
{
v3 = *(_QWORD *)(v3 + 32);
++v4;
if ( !v3 )
break;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 *a1, __int64 a2)
{
__int64 v3; // r12
signed int v4; // ebx
int result; // eax
unsigned int v6; // esi

v3 = *a1;
v4 = *((_DWORD *)a1 + 6);
if ( *a1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = v4++;
if ( *(_DWORD *)(v3 + 16) != v6 )
break;
v3 = *(_QWORD *)(v3 + 32);
v4 = v6 + 1;
if ( !v3 )
return result;
}
result = func11(a2, v6);
if ( *(_DWORD *)(a2 + 40) <= v4 )
{
v3 = *(_QWORD *)(v3 + 32);
++v4;
if ( !v3 )
break;
}
}
}
return result;
}

original_code:
void sendnacks(struct window *q, struct msgtok *tok)
{
    struct packet *el = q->head;
    int outack = q->first;
    while(el != ((void *)0))
    {
        while(el->acknum != outack)
        {
            sendbacknack(tok, outack);
            outack++;
            if(outack >= tok->acknum)
                break;
        }
        outack++;
        el = el->next;
    }
    return;
}

variable_types: struct window { struct packet { char *msg; long enqT; int acknum; int received; int sent; struct packet *next; } *head; struct packet *tail; int sz; int max; int first; int last; int cur; } *

variable_types: outack int


receivemsg

decompiled_code:
__int64 __fastcall receivemsg(char *s2)
{
int v1; // eax
int v2; // eax
unsigned int v3; // ebx
const char **v4; // rbp
int v5; // eax
__int64 v7; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-19Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-198h] BYREF
char buf[280]; // [rsp+90h] [rbp-118h] BYREF

v1 = getsockfromname();
v2 = recvfrom(v1, buf, 0xFFuLL, 0, &addr, &addr_len);
v3 = v2;
if ( v2 > 0 )
{
buf[v2] = 0;
v4 = tokenmsg(buf);
v5 = *((_DWORD *)v4 + 11);
switch ( v5 )
{
case 4:
v7 = getnodefromname(s2);
handledvrmessage(v7, v4);
break;
case 2:
handleack(s2, (__int64)v4);
break;
case 1:
handlenack(s2, (__int64)v4);
break;
default:
handlemsg(s2, v4);
break;
}
freetok(v4);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *s2)
{
int v1; // eax
int v2; // eax
unsigned int v3; // ebx
const char **v4; // rbp
int v5; // eax
__int64 v7; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-19Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-198h] BYREF
char buf[280]; // [rsp+90h] [rbp-118h] BYREF

v1 = getsockfromname();
v2 = recvfrom(v1, buf, 0xFFuLL, 0, &addr, &addr_len);
v3 = v2;
if ( v2 > 0 )
{
buf[v2] = 0;
v4 = func7(buf);
v5 = *((_DWORD *)v4 + 11);
switch ( v5 )
{
case 4:
v7 = getnodefromname(s2);
handledvrmessage(v7, v4);
break;
case 2:
func13(s2, (__int64)v4);
break;
case 1:
func14(s2, (__int64)v4);
break;
default:
func15(s2, v4);
break;
}
func6(v4);
}
return v3;
}

original_code:
int receivemsg(char *name)
{
    char recvbuf[256];
    struct sockaddr_storage their;
    socklen_t addr_size;
    int sock = getsockfromname(name);
    int bytes = recvfrom(sock, recvbuf, 256 -1, 0,
                         (struct sockaddr*)&their, &addr_size);
    if(bytes <= 0)
        return bytes;
    recvbuf[bytes] = '\0';
    struct msgtok *tok = tokenmsg(recvbuf);
    if(tok->type == enumdvrmsg)
         handledvrmessage(getnodefromname(name), tok);
    else if(tok->type == enumpureack)
        handleack(name, tok);
    else if(tok->type == enumnack)
        handlenack(name, tok);
    else
        handlemsg(name, tok);
    freetok(tok);
    return bytes;
}

canonical_original_code:
int receivemsg(char *name)
{
    char recvbuf[256];
    struct sockaddr_storage their;
    unsigned int addr_size;
    int sock = getsockfromname(name);
    int bytes = recvfrom(sock, recvbuf, 256 -1, 0,
                         (struct sockaddr*)&their, &addr_size);
    if(bytes <= 0)
        return bytes;
    recvbuf[bytes] = '\0';
    struct msgtok *tok = tokenmsg(recvbuf);
    if(tok->type == enumdvrmsg)
         handledvrmessage(getnodefromname(name), tok);
    else if(tok->type == enumpureack)
        handleack(name, tok);
    else if(tok->type == enumnack)
        handlenack(name, tok);
    else
        handlemsg(name, tok);
    freetok(tok);
    return bytes;
}

variable_types:
recvbuf
char [256]

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types: sock int

variable_types: bytes int


decompiled_code:
void __fastcall set_interval(int a1)
{
dvr_interval = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
dvr_interval = a1;
}

original_code:
void set_interval(int seconds)
{
    dvr_interval = seconds;
}

variable_types: seconds int


decompiled_code:
void __fastcall set_dvr_reset_interval(int a1)
{
dvr_reset_interval = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
dvr_reset_interval = a1;
}

original_code:
void set_dvr_reset_interval(int seconds)
{
    dvr_reset_interval = seconds;
}


decompiled_code:
_BOOL8 __fastcall is_neighbour(const char **a1)
{
return strcmp(a1[1], *a1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char **a1)
{
return strcmp(a1[1], *a1) == 0;
}

original_code:
int is_neighbour(struct routing_table_entry* rte)
{
    return (strcmp(rte->through, rte->name) == 0);
}

canonical_original_code:
int is_neighbour(struct routing_table_entry *rte)
{
    return (strcmp(rte->through, rte->name) == 0);
}

variable_types: struct routing_table_entry { char *name; char *through; float weight; int drop; int delay; struct routing_table_entry *next; } *


createlogdir

decompiled_code:
int createlogdir()
{
struct tm *v0; // rax
int result; // eax
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

*(_OWORD *)folderpath = 0LL;
*(_OWORD *)&folderpath[16] = 0LL;
*(_OWORD *)&folderpath[32] = 0LL;
*(_OWORD *)&folderpath[48] = 0LL;
time(&timer);
mkdir("logs", 0x1C0u);
v0 = localtime(&timer);
strftime(folderpath, 0x40uLL, "logs/%d-%m-%Y-%T", v0);
result = mkdir(folderpath, 0x1C0u);
if ( result )
{
v2 = strerror(result);
result = fprintf(stderr, "error creating directory: %s", v2);
}
return result;
}

canonical_decompiled_code:
int func0()
{
struct tm *v0; // rax
int result; // eax
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

*(_OWORD *)folderpath = 0LL;
*(_OWORD *)&folderpath[16] = 0LL;
*(_OWORD *)&folderpath[32] = 0LL;
*(_OWORD *)&folderpath[48] = 0LL;
time(&timer);
mkdir("logs", 0x1C0u);
v0 = localtime(&timer);
strftime(folderpath, 0x40uLL, "logs/%d-%m-%Y-%T", v0);
result = mkdir(folderpath, 0x1C0u);
if ( result )
{
v2 = strerror(result);
result = fprintf(stderr, "error creating directory: %s", v2);
}
return result;
}

original_code:
void createlogdir()
{
    int error;
    bzero(folderpath, 64);
    time_t curtime;
    time(&curtime);
    mkdir("logs", 0400 | 0100 | 0200);
    strftime(folderpath, 64, "logs/%d-%m-%Y-%T", localtime(&curtime));
    if ((error = mkdir(folderpath, 0400 | 0100 | 0200)) != 0)
    {
        fprintf(stderr, "error creating directory: %s", strerror(error));
    }
}

canonical_original_code:
void createlogdir()
{
    int error;
    bzero(folderpath, 64);
    long curtime;
    time(&curtime);
    mkdir("logs", 0400 | 0100 | 0200);
    strftime(folderpath, 64, "logs/%d-%m-%Y-%T", localtime(&curtime));
    if ((error = mkdir(folderpath, 0400 | 0100 | 0200)) != 0)
    {
        fprintf(stderr, "error creating directory: %s", strerror(error));
    }
}

variable_types: error int

variable_types: curtime long


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

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

original_code:
unsigned int chars_to_int(unsigned char *bytes)
{
 unsigned int *chars = (unsigned int *) bytes;
 return (*chars << 0x18) |
 (*chars << 0x08 & 0x00FF0000) |
 (*chars >> 0x08 & 0x0000FF00) |
 (*chars >> 0x18);
}

variable_types:
bytes
unsigned char *

variable_types:
chars
unsigned int *

return_type: unsigned int


original_code:
unsigned char *recalculate_crc(datachunk *chunk)
{
 int datasize = sizeof(char)*(4 + chunk->sizenum);
 int x;
 unsigned char *data = (unsigned char *)malloc(datasize);
 unsigned char *old_crc;
 for (x = 0; x < 4; x++)
  data[x] = chunk->type[x];
 for (x = 0; x < datasize - 4; x++)
  data[x+4] = chunk->body[x];
 old_crc = chunk->crc;
 chunk->crc = (unsigned char *)int_to_chars(chksum_crc32(data, datasize));
 free(old_crc);
 free(data);
 return chunk->crc;
}

canonical_original_code:
unsigned char *recalculate_crc(struct datachunk *chunk)
{
 int datasize = sizeof(char)*(4 + chunk->sizenum);
 int x;
 unsigned char *data = (unsigned char *)malloc(datasize);
 unsigned char *old_crc;
 for (x = 0; x < 4; x++)
  data[x] = chunk->type[x];
 for (x = 0; x < datasize - 4; x++)
  data[x+4] = chunk->body[x];
 old_crc = chunk->crc;
 chunk->crc = (unsigned char *)int_to_chars(chksum_crc32(data, datasize));
 free(old_crc);
 free(data);
 return chunk->crc;
}

variable_types: struct datachunk { unsigned char *size; unsigned char *type; unsigned char *body; unsigned char *crc; unsigned int sizenum; unsigned int typenum; } *

variable_types: datasize int

variable_types: x int

variable_types:
data
unsigned char *

return_type: unsigned char *


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

if ( fin )
result = fclose(fin);
if ( fout )
result = fclose(fout);
if ( ftext )
result = fclose(ftext);
fin = 0LL;
fout = 0LL;
ftext = 0LL;
return result;
}

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

if ( fin )
result = fclose(fin);
if ( fout )
result = fclose(fout);
if ( ftext )
result = fclose(ftext);
fin = 0LL;
fout = 0LL;
ftext = 0LL;
return result;
}

original_code:
void close_files()
{
 if(fin) fclose(fin);
 if(fout) fclose(fout);
 if(ftext) fclose(ftext);
 fin = ((void *)0);
 fout = ((void *)0);
 ftext = ((void *)0);
}


decompiled_code:
int __fastcall open_files(char *filename, char *a2, char *a3)
{
char *v4; // rax
FILE *v5; // rax
char *v6; // rdi
char *v7; // rdi

v4 = strstr(filename, ".png");
if ( v4 && strlen(v4) <= 4 )
{
v5 = fopen(filename, "r");
fin = v5;
if ( !v5 )
{
puts("ERROR\tInput file could not be opened!");
LODWORD(v5) = close_files();
}
}
else
{
puts("ERROR\tInput image file type must be .png!");
LODWORD(v5) = close_files();
}
if ( a2 )
{
v6 = strstr(a2, ".png");
if ( v6 && strlen(v6) <= 4 )
{
v5 = fopen(a2, "w");
fout = v5;
if ( !v5 )
{
puts("ERROR\tOutput file could not be opened!");
LODWORD(v5) = close_files();
}
}
else
{
puts("ERROR\tOutput image file type must be .png!");
LODWORD(v5) = close_files();
}
}
if ( a3 )
{
v7 = strstr(a3, ".txt");
if ( !v7 || strlen(v7) > 4 )
puts("WARNING\tText file may not be plaintext! Proceeding anyway...");
v5 = fopen(a3, "r");
ftext = v5;
if ( !v5 )
{
puts("ERROR\tText file could not be opened!");
LODWORD(v5) = close_files();
}
}
return (int)v5;
}

canonical_decompiled_code:
int __fastcall func3(char *filename, char *a2, char *a3)
{
char *v4; // rax
FILE *v5; // rax
char *v6; // rdi
char *v7; // rdi

v4 = strstr(filename, ".png");
if ( v4 && strlen(v4) <= 4 )
{
v5 = fopen(filename, "r");
fin = v5;
if ( !v5 )
{
puts("ERROR\tInput file could not be opened!");
LODWORD(v5) = func2();
}
}
else
{
puts("ERROR\tInput image file type must be .png!");
LODWORD(v5) = func2();
}
if ( a2 )
{
v6 = strstr(a2, ".png");
if ( v6 && strlen(v6) <= 4 )
{
v5 = fopen(a2, "w");
fout = v5;
if ( !v5 )
{
puts("ERROR\tOutput file could not be opened!");
LODWORD(v5) = func2();
}
}
else
{
puts("ERROR\tOutput image file type must be .png!");
LODWORD(v5) = func2();
}
}
if ( a3 )
{
v7 = strstr(a3, ".txt");
if ( !v7 || strlen(v7) > 4 )
puts("WARNING\tText file may not be plaintext! Proceeding anyway...");
v5 = fopen(a3, "r");
ftext = v5;
if ( !v5 )
{
puts("ERROR\tText file could not be opened!");
LODWORD(v5) = func2();
}
}
return (int)v5;
}

original_code:
void open_files(char *inname, char *outname, char* textname)
{
 int len = strlen(inname);
 char *intype;
 char *outtype;
 char *texttype;
 intype = strstr(inname, ".png");
 if (intype)
 {
  if (strlen(intype) > 4)
  {
   printf("ERROR\tInput image file type must be .png!\n");
   close_files();
  }
  else if((fin = fopen(inname, "r")) == ((void *)0))
  {
   printf("ERROR\tInput file could not be opened!\n");
   close_files();
  }
 }
 else
 {
  printf("ERROR\tInput image file type must be .png!\n");
  close_files();
 }
 if (outname)
 {
  outtype = strstr(outname, ".png");
  if (outtype)
  {
   if (strlen(outtype) > 4)
   {
    printf("ERROR\tOutput image file type must be .png!\n");
    close_files();
   }
   else if((fout = fopen(outname, "w")) == ((void *)0))
   {
    printf("ERROR\tOutput file could not be opened!\n");
    close_files();
   }
  }
  else
  {
   printf("ERROR\tOutput image file type must be .png!\n");
   close_files();
  }
 }
 if (textname)
 {
  texttype = strstr(textname, ".txt");
  if (texttype)
  {
   if (strlen(texttype) > 4)
    printf("WARNING\tText file may not be plaintext! Proceeding anyway...\n");
  }
  else
   printf("WARNING\tText file may not be plaintext! Proceeding anyway...\n");
  if((ftext = fopen(textname, "r")) == ((void *)0))
  {
   printf("ERROR\tText file could not be opened!\n");
   close_files();
  }
 }
}

canonical_original_code:
void open_files(char *inname, char *outname, char *textname)
{
 int len = strlen(inname);
 char *intype;
 char *outtype;
 char *texttype;
 intype = strstr(inname, ".png");
 if (intype)
 {
  if (strlen(intype) > 4)
  {
   printf("ERROR\tInput image file type must be .png!\n");
   close_files();
  }
  else if((fin = fopen(inname, "r")) == ((void *)0))
  {
   printf("ERROR\tInput file could not be opened!\n");
   close_files();
  }
 }
 else
 {
  printf("ERROR\tInput image file type must be .png!\n");
  close_files();
 }
 if (outname)
 {
  outtype = strstr(outname, ".png");
  if (outtype)
  {
   if (strlen(outtype) > 4)
   {
    printf("ERROR\tOutput image file type must be .png!\n");
    close_files();
   }
   else if((fout = fopen(outname, "w")) == ((void *)0))
   {
    printf("ERROR\tOutput file could not be opened!\n");
    close_files();
   }
  }
  else
  {
   printf("ERROR\tOutput image file type must be .png!\n");
   close_files();
  }
 }
 if (textname)
 {
  texttype = strstr(textname, ".txt");
  if (texttype)
  {
   if (strlen(texttype) > 4)
    printf("WARNING\tText file may not be plaintext! Proceeding anyway...\n");
  }
  else
   printf("WARNING\tText file may not be plaintext! Proceeding anyway...\n");
  if((ftext = fopen(textname, "r")) == ((void *)0))
  {
   printf("ERROR\tText file could not be opened!\n");
   close_files();
  }
 }
}

variable_types:
inname
char *

variable_types:
outname
char *

variable_types:
textname
char *

variable_types: len int

variable_types:
intype
char *

variable_types:
outtype
char *

variable_types:
texttype
char *


decompiled_code:
size_t __fastcall write_out(const void *a1, unsigned int a2)
{
return fwrite(a1, 1uLL, a2, fout);
}

canonical_decompiled_code:
size_t __fastcall func4(const void *a1, unsigned int a2)
{
return fwrite(a1, 1uLL, a2, fout);
}

original_code:
void write_out(unsigned char *data, unsigned int size)
{
 fwrite(data, sizeof(char), size, fout);
}

variable_types:
size
unsigned int


decompiled_code:
void *get_header()
{
void *v0; // r12

v0 = malloc(8uLL);
fread(v0, 1uLL, 8uLL, fin);
return v0;
}

canonical_decompiled_code:
void *func5()
{
void *v0; // r12

v0 = malloc(8uLL);
fread(v0, 1uLL, 8uLL, fin);
return v0;
}

original_code:
unsigned char *get_header()
{
 unsigned char *header;
 header = malloc(sizeof(char)*8);
 fread(header, sizeof(char), 8, fin);
 return header;
}

variable_types:
header
unsigned char *


decompiled_code:
__int64 process_chunk()
{
void *v0; // rbp
void *v1; // r13
void *v2; // rbx
size_t v3; // r12
void *v4; // r14
_QWORD *v5; // rax
__int64 v6; // r12

v0 = malloc(4uLL);
v1 = malloc(4uLL);
v2 = malloc(4uLL);
fread(v0, 1uLL, 4uLL, fin);
fread(v1, 1uLL, 4uLL, fin);
v3 = (unsigned int)chars_to_int((unsigned int *)v0);
v4 = malloc(v3);
fread(v4, 1uLL, v3, fin);
fread(v2, 1uLL, 4uLL, fin);
v5 = malloc(0x28uLL);
*v5 = v0;
v6 = (__int64)v5;
v5[1] = v1;
v5[2] = v4;
v5[3] = v2;
*((_DWORD *)v5 + 8) = chars_to_int((unsigned int *)v0);
*(_DWORD *)(v6 + 36) = chars_to_int((unsigned int *)v1);
*(_QWORD *)(v6 + 24) = recalculate_crc(v6);
recalculate_crc(v6);
if ( *(_DWORD *)(v6 + 36) == 1229472850 )
{
scanlen = chars_to_int((unsigned int *)v4);
step = 3 * scanlen + 1;
}
return v6;
}

canonical_decompiled_code:
__int64 func6()
{
void *v0; // rbp
void *v1; // r13
void *v2; // rbx
size_t v3; // r12
void *v4; // r14
_QWORD *v5; // rax
__int64 v6; // r12

v0 = malloc(4uLL);
v1 = malloc(4uLL);
v2 = malloc(4uLL);
fread(v0, 1uLL, 4uLL, fin);
fread(v1, 1uLL, 4uLL, fin);
v3 = (unsigned int)func0((unsigned int *)v0);
v4 = malloc(v3);
fread(v4, 1uLL, v3, fin);
fread(v2, 1uLL, 4uLL, fin);
v5 = malloc(0x28uLL);
*v5 = v0;
v6 = (__int64)v5;
v5[1] = v1;
v5[2] = v4;
v5[3] = v2;
*((_DWORD *)v5 + 8) = func0((unsigned int *)v0);
*(_DWORD *)(v6 + 36) = func0((unsigned int *)v1);
*(_QWORD *)(v6 + 24) = func1(v6);
func1(v6);
if ( *(_DWORD *)(v6 + 36) == 1229472850 )
{
scanlen = func0((unsigned int *)v4);
step = 3 * scanlen + 1;
}
return v6;
}

original_code:
datachunk *process_chunk()
{
 datachunk *chunk;
 unsigned char *size, *type, *body, *crc;
 unsigned int bodysize;
 size = malloc(sizeof(char)*4);
 type = malloc(sizeof(char)*4);
 body = malloc(sizeof(char)*4);
 crc = malloc(sizeof(char)*4);
 fread(size, sizeof(char), 4, fin);
 fread(type, sizeof(char), 4, fin);
 bodysize = chars_to_int(size);
 body = malloc(sizeof(char)*bodysize);
 fread(body, sizeof(char), bodysize, fin);
 fread(crc, sizeof(char), 4, fin);
 chunk = malloc(sizeof(char)*sizeof(datachunk));
 chunk->size = size;
 chunk->type = type;
 chunk->body = body;
 chunk->crc = crc;
 chunk->sizenum = chars_to_int(size);
 chunk->typenum = chars_to_int(type);
 chunk->crc = recalculate_crc(chunk);
 if(chars_to_int(crc) != chars_to_int(recalculate_crc(chunk)))
 {
 }
 if (chunk->typenum == 0x49484452)
 {
  scanlen = chars_to_int(body);
  step = (scanlen*3)+1;
 }
 return chunk;
}

canonical_original_code:
struct datachunk *process_chunk()
{
 struct datachunk *chunk;
 unsigned char *size; unsigned char *type; unsigned char *body; unsigned char *crc;
 unsigned int bodysize;
 size = malloc(sizeof(char)*4);
 type = malloc(sizeof(char)*4);
 body = malloc(sizeof(char)*4);
 crc = malloc(sizeof(char)*4);
 fread(size, sizeof(char), 4, fin);
 fread(type, sizeof(char), 4, fin);
 bodysize = chars_to_int(size);
 body = malloc(sizeof(char)*bodysize);
 fread(body, sizeof(char), bodysize, fin);
 fread(crc, sizeof(char), 4, fin);
 chunk = malloc(sizeof(char)*sizeof(datachunk));
 chunk->size = size;
 chunk->type = type;
 chunk->body = body;
 chunk->crc = crc;
 chunk->sizenum = chars_to_int(size);
 chunk->typenum = chars_to_int(type);
 chunk->crc = recalculate_crc(chunk);
 if(chars_to_int(crc) != chars_to_int(recalculate_crc(chunk)))
 {
 }
 if (chunk->typenum == 0x49484452)
 {
  scanlen = chars_to_int(body);
  step = (scanlen*3)+1;
 }
 return chunk;
}

variable_types:
size
unsigned char *

variable_types:
type
unsigned char *

variable_types:
body
unsigned char *

variable_types:
crc
unsigned char *

variable_types:
bodysize
unsigned int

return_type: struct datachunk { unsigned char *size; unsigned char *type; unsigned char *body; unsigned char *crc; unsigned int sizenum; unsigned int typenum; } *


collate

original_code:
datachunk *collate()
{
 datachunk *chunk = malloc(sizeof(char)*sizeof(datachunk));
 datachunk *collated = malloc(sizeof(char)*sizeof(datachunk));
 unsigned char *size, *type, *body, *crc;
 unsigned int fullsize = 0, currtype = 0, deposit = 0;
 unsigned int x;
 size = (unsigned char *)malloc(sizeof(char)*4);
 type = (unsigned char *)malloc(sizeof(char)*4);
 body = (unsigned char *)malloc(sizeof(char)*4);
 crc = (unsigned char *)malloc(sizeof(char)*4);
 get_header();
 chunk = process_chunk();
 currtype = chunk->typenum;
 while (currtype != 0x49444154)
 {
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 while (currtype == 0x49444154)
 {
  fullsize += chunk->sizenum;
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 body = malloc(sizeof(char)*fullsize);
 size = int_to_chars(fullsize);
 type = int_to_chars(0x49444154);
 rewind(fin);
 get_header();
 chunk = process_chunk();
 currtype = chunk->typenum;
 while (currtype != 0x49444154)
 {
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 while (currtype == 0x49444154)
 {
  for (x = 0; x < chunk->sizenum; x++)
   body[deposit+x] = chunk->body[x];
  deposit += chunk->sizenum;
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 blksize = 0x00000000;
 blksize = (body[4] << 8) + body[3];
 collated->size = size;
 collated->type = type;
 collated->body = body;
 collated->crc = crc;
 collated->crc = recalculate_crc(collated);
 collated->sizenum = chars_to_int(size);
 collated->typenum = chars_to_int(type);
 rewind(fin);
 return collated;
}

canonical_original_code:
struct datachunk *collate()
{
 struct datachunk *chunk = malloc(sizeof(char)*sizeof(datachunk));
 struct datachunk *collated = malloc(sizeof(char)*sizeof(datachunk));
 unsigned char *size; unsigned char *type; unsigned char *body; unsigned char *crc;
 unsigned int fullsize = 0; unsigned int currtype = 0; unsigned int deposit = 0;
 unsigned int x;
 size = (unsigned char *)malloc(sizeof(char)*4);
 type = (unsigned char *)malloc(sizeof(char)*4);
 body = (unsigned char *)malloc(sizeof(char)*4);
 crc = (unsigned char *)malloc(sizeof(char)*4);
 get_header();
 chunk = process_chunk();
 currtype = chunk->typenum;
 while (currtype != 0x49444154)
 {
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 while (currtype == 0x49444154)
 {
  fullsize += chunk->sizenum;
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 body = malloc(sizeof(char)*fullsize);
 size = int_to_chars(fullsize);
 type = int_to_chars(0x49444154);
 rewind(fin);
 get_header();
 chunk = process_chunk();
 currtype = chunk->typenum;
 while (currtype != 0x49444154)
 {
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 while (currtype == 0x49444154)
 {
  for (x = 0; x < chunk->sizenum; x++)
   body[deposit+x] = chunk->body[x];
  deposit += chunk->sizenum;
  chunk = process_chunk();
  currtype = chunk->typenum;
 }
 blksize = 0x00000000;
 blksize = (body[4] << 8) + body[3];
 collated->size = size;
 collated->type = type;
 collated->body = body;
 collated->crc = crc;
 collated->crc = recalculate_crc(collated);
 collated->sizenum = chars_to_int(size);
 collated->typenum = chars_to_int(type);
 rewind(fin);
 return collated;
}

variable_types: struct datachunk { unsigned char *size; unsigned char *type; unsigned char *body; unsigned char *crc; unsigned int sizenum; unsigned int typenum; } *

variable_types:
fullsize
unsigned int

variable_types:
currtype
unsigned int

variable_types:
deposit
unsigned int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall write_body(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // er12
const void *v4; // rax

write_out(*(const void **)a1, 4u);
write_out(*(const void **)(a1 + 8), 4u);
if ( *(_DWORD *)(a1 + 36) == 1229209940 )
{
v3 = write_code(a1, a2);
write_out(*(const void **)(a1 + 16), *(_DWORD *)(a1 + 32));
v4 = (const void *)recalculate_crc(a1);
*(_QWORD *)(a1 + 24) = v4;
write_out(v4, 4u);
result = v3;
}
else
{
write_out(*(const void **)(a1 + 16), *(_DWORD *)(a1 + 32));
write_out(*(const void **)(a1 + 24), 4u);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // er12
const void *v4; // rax

func4(*(const void **)a1, 4u);
func4(*(const void **)(a1 + 8), 4u);
if ( *(_DWORD *)(a1 + 36) == 1229209940 )
{
v3 = write_code(a1, a2);
func4(*(const void **)(a1 + 16), *(_DWORD *)(a1 + 32));
v4 = (const void *)func1(a1);
*(_QWORD *)(a1 + 24) = v4;
func4(v4, 4u);
result = v3;
}
else
{
func4(*(const void **)(a1 + 16), *(_DWORD *)(a1 + 32));
func4(*(const void **)(a1 + 24), 4u);
result = 0LL;
}
return result;
}

original_code:
int write_body(datachunk *chunk, char *msg)
{
 int success;
 write_out(chunk->size, 4);
 write_out(chunk->type, 4);
 if(chunk->typenum != 0x49444154)
 {
  write_out(chunk->body, chunk->sizenum);
  write_out(chunk->crc, 4);
  return 0;
 }
 success = write_code(chunk, msg);
 write_out(chunk->body, chunk->sizenum);
 chunk->crc = recalculate_crc(chunk);
 write_out(chunk->crc, 4);
 return success;
}

canonical_original_code:
int write_body(struct datachunk *chunk, char *msg)
{
 int success;
 write_out(chunk->size, 4);
 write_out(chunk->type, 4);
 if(chunk->typenum != 0x49444154)
 {
  write_out(chunk->body, chunk->sizenum);
  write_out(chunk->crc, 4);
  return 0;
 }
 success = write_code(chunk, msg);
 write_out(chunk->body, chunk->sizenum);
 chunk->crc = recalculate_crc(chunk);
 write_out(chunk->crc, 4);
 return success;
}

variable_types:
msg
char *

variable_types: success int

user_defined_types: struct datachunk { unsigned char *size; unsigned char *type; unsigned char *body; unsigned char *crc; unsigned int sizenum; unsigned int typenum; }


decompiled_code:
__int64 encode_msg()
{
unsigned int v0; // ebx
__int64 v1; // rdi
unsigned int v2; // ebx
const char *v3; // r12
char v4; // r8
__int64 v5; // rax
char *v6; // rbx
int v7; // eax
__int64 result; // rax

v0 = 0;
while ( !feof(ftext) )
{
++v0;
fgetc(ftext);
}
v1 = v0;
v2 = 0;
v3 = (const char *)malloc(v1 + 1);
rewind(ftext);
while ( !feof(ftext) )
{
v4 = fgetc(ftext);
v5 = v2++;
v3[v5] = v4;
}
rewind(ftext);
v6 = (char *)&v3[v2 - 1];
*v6 = 0;
printf("%s\n\n", v3);
v7 = encrypt_flag;
*v6 = -1;
if ( v7 )
result = encrypt_text(v3);
else
result = (__int64)v3;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // ebx
__int64 v1; // rdi
unsigned int v2; // ebx
const char *v3; // r12
char v4; // r8
__int64 v5; // rax
char *v6; // rbx
int v7; // eax
__int64 result; // rax

v0 = 0;
while ( !feof(ftext) )
{
++v0;
fgetc(ftext);
}
v1 = v0;
v2 = 0;
v3 = (const char *)malloc(v1 + 1);
rewind(ftext);
while ( !feof(ftext) )
{
v4 = fgetc(ftext);
v5 = v2++;
v3[v5] = v4;
}
rewind(ftext);
v6 = (char *)&v3[v2 - 1];
*v6 = 0;
printf("%s\n\n", v3);
v7 = encrypt_flag;
*v6 = -1;
if ( v7 )
result = encrypt_text(v3);
else
result = (__int64)v3;
return result;
}

original_code:
char *encode_msg()
{
 unsigned int len = 0;
 char *msg;
 while (!feof(ftext))
 {
  fgetc(ftext);
  len++;
 }
 msg = malloc(len*sizeof(char) + 1);
 rewind(ftext);
 len = 0;
 while (!feof(ftext))
  msg[len++] = fgetc(ftext);
 rewind(ftext);
 msg[len-1] = '\0';
 printf("%s\n\n", msg);
 msg[len-1] = (-1);
 if (!encrypt_flag)
  return msg;
 return encrypt_text(msg);
}

variable_types:
len
unsigned int

return_type: char *


decompiled_code:
__int64 __fastcall decode_msg(_BYTE *a1)
{
__int64 v1; // rdx
_BYTE *v2; // rax

LODWORD(v1) = encrypt_flag;
if ( encrypt_flag )
return decrypt_text();
v2 = a1;
if ( *a1 != 0xFF )
{
do
{
v1 = (unsigned int)(v1 + 1);
v2 = &a1[v1];
}
while ( a1[v1] != 0xFF );
}
*v2 = 0;
return (__int64)a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1)
{
__int64 v1; // rdx
_BYTE *v2; // rax

LODWORD(v1) = encrypt_flag;
if ( encrypt_flag )
return decrypt_text();
v2 = a1;
if ( *a1 != 0xFF )
{
do
{
v1 = (unsigned int)(v1 + 1);
v2 = &a1[v1];
}
while ( a1[v1] != 0xFF );
}
*v2 = 0;
return (__int64)a1;
}

original_code:
char *decode_msg(char *msg)
{
 unsigned int i = 0;
 if (encrypt_flag)
  return decrypt_text(msg);
 while (msg[i] != (-1))
  i++;
 msg[i] = '\0';
 return msg;
}

variable_types:
i
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // bl
__int64 v4; // rbx
char **v5; // r13
_QWORD *v6; // rax
_BYTE *v7; // rax
const char *v8; // rbp
__int64 v10; // r13
_QWORD *v11; // r12
unsigned int **v12; // rbp
int v13; // ebx
char v14[104]; // [rsp+0h] [rbp-68h] BYREF

encrypt_flag = 1;
chksum_crc32gentab(argc, argv, envp);
if ( argc > 1 && !strcmp(argv[1], "-h") )
{
puts("\n***Atra-Hasis Steganography Tool***\n");
puts("Program default is to encrypt text:");
puts("to ENCODE with ENCRYPTION:\t ./AtraHasis [input image] [output image] [input text]");
puts("to DECODE with DECRYPTION:\t ./AtraHasis [input image]\n");
puts("User may choose to use plaintext instead with the [-u] flag.");
puts("to ENCODE with PLAINTEXT:\t ./AtraHasis -u [input image] [output image] [input text]");
puts("to DECODE with PLAINTEXT:\t ./AtraHasis -u [input image]\n");
return 0;
}
if ( (unsigned int)(argc - 2) > 3 || ((argc - 3) & 0xFFFFFFFD) == 0 && strcmp(argv[1], "-u") )
{
puts("\nINCORRECT ARGUMENT FORMAT");
puts("use [-h] for help.\n");
return 0;
}
if ( ((argc - 2) & 0xFFFFFFFD) != 0 )
{
encrypt_flag = 0;
v3 = 1;
}
else
{
v3 = 0;
printf("Enter password for this image: ");
fgets(v14, 63, stdin);
keygen(v14);
}
v4 = (char)(v3 + 1);
v5 = (char **)&argv[v4];
if ( argc > 3 )
{
putchar(10);
open_files(*v5, (char *)argv[v4 + 1], (char *)argv[v4 + 2]);
if ( fin && fout && ftext )
{
puts("ENCODING THIS MESSAGE...\n");
v10 = encode_msg();
v11 = collate();
v12 = (unsigned int **)get_header();
write_out(v12, 8u);
while ( 1 )
{
free(v12);
v12 = (unsigned int **)process_chunk();
if ( (unsigned int)chars_to_int(v12[1]) == 1229209940 )
break;
write_body((__int64)v12, 0LL);
}
v13 = write_body((__int64)v11, v10);
free(v11);
while ( (unsigned int)chars_to_int(v12[1]) == 1229209940 )
v12 = (unsigned int **)process_chunk();
while ( 1 )
{
write_body((__int64)v12, 0LL);
free(v12);
if ( (unsigned int)chars_to_int(v12[1]) == 1229278788 )
break;
v12 = (unsigned int **)process_chunk();
}
if ( v13 )
puts("MESSAGE ENCODED SUCCESSFULLY\n");
else
puts("MESSAGE ENCODING FAILED. Image was too small.\n");
goto LABEL_11;
}
LABEL_30:
puts("MESSAGE ENCODING FAILED. Argument files not valid.\n");
return 0;
}
putchar(10);
open_files(*v5, 0LL, 0LL);
if ( !fin )
goto LABEL_30;
puts("DECODING MESSAGE...");
v6 = collate();
v7 = (_BYTE *)read_code(v6);
v8 = (const char *)decode_msg(v7);
puts("\nSTART DECODED MESSAGE:");
printf("\n%s\n", v8);
puts("\n:END DECODED MESSAGE\n");
LABEL_11:
close_files();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // bl
__int64 v4; // rbx
char **v5; // r13
_QWORD *v6; // rax
_BYTE *v7; // rax
const char *v8; // rbp
__int64 v10; // r13
_QWORD *v11; // r12
unsigned int **v12; // rbp
int v13; // ebx
char v14[104]; // [rsp+0h] [rbp-68h] BYREF

encrypt_flag = 1;
chksum_crc32gentab(argc, argv, envp);
if ( argc > 1 && !strcmp(argv[1], "-h") )
{
puts("\n***Atra-Hasis Steganography Tool***\n");
puts("Program default is to encrypt text:");
puts("to ENCODE with ENCRYPTION:\t ./AtraHasis [input image] [output image] [input text]");
puts("to DECODE with DECRYPTION:\t ./AtraHasis [input image]\n");
puts("User may choose to use plaintext instead with the [-u] flag.");
puts("to ENCODE with PLAINTEXT:\t ./AtraHasis -u [input image] [output image] [input text]");
puts("to DECODE with PLAINTEXT:\t ./AtraHasis -u [input image]\n");
return 0;
}
if ( (unsigned int)(argc - 2) > 3 || ((argc - 3) & 0xFFFFFFFD) == 0 && strcmp(argv[1], "-u") )
{
puts("\nINCORRECT ARGUMENT FORMAT");
puts("use [-h] for help.\n");
return 0;
}
if ( ((argc - 2) & 0xFFFFFFFD) != 0 )
{
encrypt_flag = 0;
v3 = 1;
}
else
{
v3 = 0;
printf("Enter password for this image: ");
fgets(v14, 63, stdin);
keygen(v14);
}
v4 = (char)(v3 + 1);
v5 = (char **)&argv[v4];
if ( argc > 3 )
{
putchar(10);
func3(*v5, (char *)argv[v4 + 1], (char *)argv[v4 + 2]);
if ( fin && fout && ftext )
{
puts("ENCODING THIS MESSAGE...\n");
v10 = func9();
v11 = func7();
v12 = (unsigned int **)func5();
func4(v12, 8u);
while ( 1 )
{
free(v12);
v12 = (unsigned int **)func6();
if ( (unsigned int)func0(v12[1]) == 1229209940 )
break;
func8((__int64)v12, 0LL);
}
v13 = func8((__int64)v11, v10);
free(v11);
while ( (unsigned int)func0(v12[1]) == 1229209940 )
v12 = (unsigned int **)func6();
while ( 1 )
{
func8((__int64)v12, 0LL);
free(v12);
if ( (unsigned int)func0(v12[1]) == 1229278788 )
break;
v12 = (unsigned int **)func6();
}
if ( v13 )
puts("MESSAGE ENCODED SUCCESSFULLY\n");
else
puts("MESSAGE ENCODING FAILED. Image was too small.\n");
goto LABEL_11;
}
LABEL_30:
puts("MESSAGE ENCODING FAILED. Argument files not valid.\n");
return 0;
}
putchar(10);
func3(*v5, 0LL, 0LL);
if ( !fin )
goto LABEL_30;
puts("DECODING MESSAGE...");
v6 = func7();
v7 = (_BYTE *)read_code(v6);
v8 = (const char *)func10(v7);
puts("\nSTART DECODED MESSAGE:");
printf("\n%s\n", v8);
puts("\n:END DECODED MESSAGE\n");
LABEL_11:
func2();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 unsigned char *header;
 char *msg, password[63];
 datachunk *chunk, *IDATchunk;
 char arg_offset = 0;
 int success = 0;
 encrypt_flag = 1;
 chksum_crc32gentab();
 if (argc >= 2 && !strcmp(argv[1],"-h"))
 {
  printf("\n***Atra-Hasis Steganography Tool***\n\n");
  printf("Program default is to encrypt text:\n");
  printf("to ENCODE with ENCRYPTION:\t ./AtraHasis [input image] [output image] [input text]\n");
  printf("to DECODE with DECRYPTION:\t ./AtraHasis [input image]\n\n");
  printf("User may choose to use plaintext instead with the [-u] flag.\n");
  printf("to ENCODE with PLAINTEXT:\t ./AtraHasis -u [input image] [output image] [input text]\n");
  printf("to DECODE with PLAINTEXT:\t ./AtraHasis -u [input image]\n\n");
  return 0;
 }
 else if(argc > 5 || argc < 2 || ((argc == 3 || argc == 5) && strcmp(argv[1],"-u")))
 {
  printf("\nINCORRECT ARGUMENT FORMAT\n");
  printf("use [-h] for help.\n\n");
  return 0;
 }
 if (argc == 2 || argc == 4)
 {
  printf("Enter password for this image: ");
  fgets(password, sizeof(password), stdin);
  keygen(password);
 }
 else
 {
  encrypt_flag = 0;
  arg_offset = 1;
 }
 if(argc <= 3)
 {
  printf("\n");
  open_files(argv[arg_offset+1], ((void *)0), ((void *)0));
  if (!fin)
  {
   printf("MESSAGE ENCODING FAILED. Argument files not valid.\n\n");
   return 0;
  }
  printf("DECODING MESSAGE...\n");
  IDATchunk = collate();
  msg = read_code(IDATchunk);
  msg = decode_msg(msg);
  printf("\nSTART DECODED MESSAGE:\n");
  printf("\n%s\n", msg);
  printf("\n:END DECODED MESSAGE\n\n");
 }
 else
 {
  printf("\n");
  open_files(argv[arg_offset+1], argv[arg_offset+2], argv[arg_offset+3]);
  if (!fin || !fout || !ftext)
  {
   printf("MESSAGE ENCODING FAILED. Argument files not valid.\n\n");
   return 0;
  }
  printf("ENCODING THIS MESSAGE...\n\n");
  msg = encode_msg();
  IDATchunk = collate();
  header = get_header();
  write_out(header, 8);
  free(header);
  chunk = process_chunk();
  while (chars_to_int(chunk->type) != 0x49444154)
  {
   write_body(chunk, ((void *)0));
   free(chunk);
   chunk = process_chunk();
  }
  success = write_body(IDATchunk, msg);
  free(IDATchunk);
  while (chars_to_int(chunk->type) == 0x49444154)
  {
   chunk = process_chunk();
  }
  write_body(chunk, ((void *)0));
  free(chunk);
  while (chars_to_int(chunk->type) != 0x49454e44)
  {
   chunk = process_chunk();
   write_body(chunk, ((void *)0));
   free(chunk);
  }
  if (success)
   printf("MESSAGE ENCODED SUCCESSFULLY\n\n");
  else
   printf("MESSAGE ENCODING FAILED. Image was too small.\n\n");
 }
 close_files();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned char *header;
 char *msg; char password[63];
 struct datachunk *chunk; struct datachunk *IDATchunk;
 char arg_offset = 0;
 int success = 0;
 encrypt_flag = 1;
 chksum_crc32gentab();
 if (argc >= 2 && !strcmp(argv[1],"-h"))
 {
  printf("\n***Atra-Hasis Steganography Tool***\n\n");
  printf("Program default is to encrypt text:\n");
  printf("to ENCODE with ENCRYPTION:\t ./AtraHasis [input image] [output image] [input text]\n");
  printf("to DECODE with DECRYPTION:\t ./AtraHasis [input image]\n\n");
  printf("User may choose to use plaintext instead with the [-u] flag.\n");
  printf("to ENCODE with PLAINTEXT:\t ./AtraHasis -u [input image] [output image] [input text]\n");
  printf("to DECODE with PLAINTEXT:\t ./AtraHasis -u [input image]\n\n");
  return 0;
 }
 else if(argc > 5 || argc < 2 || ((argc == 3 || argc == 5) && strcmp(argv[1],"-u")))
 {
  printf("\nINCORRECT ARGUMENT FORMAT\n");
  printf("use [-h] for help.\n\n");
  return 0;
 }
 if (argc == 2 || argc == 4)
 {
  printf("Enter password for this image: ");
  fgets(password, sizeof(password), stdin);
  keygen(password);
 }
 else
 {
  encrypt_flag = 0;
  arg_offset = 1;
 }
 if(argc <= 3)
 {
  printf("\n");
  open_files(argv[arg_offset+1], ((void *)0), ((void *)0));
  if (!fin)
  {
   printf("MESSAGE ENCODING FAILED. Argument files not valid.\n\n");
   return 0;
  }
  printf("DECODING MESSAGE...\n");
  IDATchunk = collate();
  msg = read_code(IDATchunk);
  msg = decode_msg(msg);
  printf("\nSTART DECODED MESSAGE:\n");
  printf("\n%s\n", msg);
  printf("\n:END DECODED MESSAGE\n\n");
 }
 else
 {
  printf("\n");
  open_files(argv[arg_offset+1], argv[arg_offset+2], argv[arg_offset+3]);
  if (!fin || !fout || !ftext)
  {
   printf("MESSAGE ENCODING FAILED. Argument files not valid.\n\n");
   return 0;
  }
  printf("ENCODING THIS MESSAGE...\n\n");
  msg = encode_msg();
  IDATchunk = collate();
  header = get_header();
  write_out(header, 8);
  free(header);
  chunk = process_chunk();
  while (chars_to_int(chunk->type) != 0x49444154)
  {
   write_body(chunk, ((void *)0));
   free(chunk);
   chunk = process_chunk();
  }
  success = write_body(IDATchunk, msg);
  free(IDATchunk);
  while (chars_to_int(chunk->type) == 0x49444154)
  {
   chunk = process_chunk();
  }
  write_body(chunk, ((void *)0));
  free(chunk);
  while (chars_to_int(chunk->type) != 0x49454e44)
  {
   chunk = process_chunk();
   write_body(chunk, ((void *)0));
   free(chunk);
  }
  if (success)
   printf("MESSAGE ENCODED SUCCESSFULLY\n\n");
  else
   printf("MESSAGE ENCODING FAILED. Image was too small.\n\n");
 }
 close_files();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
password
char [63]


decompiled_code:
__int64 __fastcall chksum_crc32(_BYTE *a1, int a2)
{
_BYTE *v2; // rsi
unsigned __int64 v3; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = 0xFFFFFFFFLL;
do
v3 = (v3 >> 8) ^ (unsigned int)crc_tab[(unsigned __int8)(*a1++ ^ v3)];
while ( a1 != v2 );
return (unsigned int)~(_DWORD)v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, int a2)
{
_BYTE *v2; // rsi
unsigned __int64 v3; // rax

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = 0xFFFFFFFFLL;
do
v3 = (v3 >> 8) ^ (unsigned int)crc_tab[(unsigned __int8)(*a1++ ^ v3)];
while ( a1 != v2 );
return (unsigned int)~(_DWORD)v3;
}

original_code:
u_int32_t chksum_crc32 (unsigned char *block, unsigned int length)
{
 register unsigned long crc;
 unsigned long i;
 crc = 0xFFFFFFFF;
 for (i = 0; i < length; i++)
 {
  crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
 }
 return (crc ^ 0xFFFFFFFF);
}

canonical_original_code:
unsigned int chksum_crc32(unsigned char *block, unsigned int length)
{
 register unsigned long crc;
 unsigned long i;
 crc = 0xFFFFFFFF;
 for (i = 0; i < length; i++)
 {
  crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
 }
 return (crc ^ 0xFFFFFFFF);
}

variable_types:
block
unsigned char *

variable_types:
length
unsigned int

variable_types:
crc
unsigned long

variable_types:
i
unsigned long


decompiled_code:
unsigned __int64 chksum_crc32gentab()
{
unsigned __int64 i; // r8
unsigned __int64 result; // rax
int v2; // edx
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rsi

for ( i = 0LL; i != 256; ++i )
{
result = i;
v2 = 8;
do
{
v3 = result & 1;
v4 = result >> 1;
result = (result >> 1) ^ 0xEDB88320;
if ( !v3 )
result = v4;
--v2;
}
while ( v2 );
crc_tab[i] = result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func1()
{
unsigned __int64 i; // r8
unsigned __int64 result; // rax
int v2; // edx
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rsi

for ( i = 0LL; i != 256; ++i )
{
result = i;
v2 = 8;
do
{
v3 = result & 1;
v4 = result >> 1;
result = (result >> 1) ^ 0xEDB88320;
if ( !v3 )
result = v4;
--v2;
}
while ( v2 );
crc_tab[i] = result;
}
return result;
}

original_code:
void chksum_crc32gentab ()
{
 unsigned long crc, poly;
 int i, j;
 poly = 0xEDB88320L;
 for (i = 0; i < 256; i++)
 {
  crc = i;
  for (j = 8; j > 0; j--)
  {
   if (crc & 1)
   {
    crc = (crc >> 1) ^ poly;
   }
   else
   {
    crc >>= 1;
   }
  }
  crc_tab[i] = crc;
 }
}

canonical_original_code:
void chksum_crc32gentab()
{
 unsigned long crc; unsigned long poly;
 int i; int j;
 poly = 0xEDB88320L;
 for (i = 0; i < 256; i++)
 {
  crc = i;
  for (j = 8; j > 0; j--)
  {
   if (crc & 1)
   {
    crc = (crc >> 1) ^ poly;
   }
   else
   {
    crc >>= 1;
   }
  }
  crc_tab[i] = crc;
 }
}

variable_types:
poly
unsigned long

variable_types: i int

variable_types: j int


paeth

decompiled_code:
__int64 __fastcall paeth(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // esi
int v5; // ecx
unsigned int v6; // edx
int v7; // eax
unsigned int v8; // edx
unsigned int v9; // eax
unsigned int v10; // ecx
unsigned int v11; // er9

v4 = a3;
v5 = a2 - a3;
v6 = a1 + a2 - a3;
v7 = v6 - v4;
v8 = abs32(v6 - a2);
v9 = abs32(v7);
v10 = abs32(v5);
v11 = v9;
if ( v8 <= v9 )
v11 = v8;
if ( v10 > v11 )
{
if ( v8 <= v9 )
v4 = a2;
a1 = v4;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // esi
int v5; // ecx
unsigned int v6; // edx
int v7; // eax
unsigned int v8; // edx
unsigned int v9; // eax
unsigned int v10; // ecx
unsigned int v11; // er9

v4 = a3;
v5 = a2 - a3;
v6 = a1 + a2 - a3;
v7 = v6 - v4;
v8 = abs32(v6 - a2);
v9 = abs32(v7);
v10 = abs32(v5);
v11 = v9;
if ( v8 <= v9 )
v11 = v8;
if ( v10 > v11 )
{
if ( v8 <= v9 )
v4 = a2;
a1 = v4;
}
return a1;
}

original_code:
unsigned int paeth(unsigned int a, unsigned int b, unsigned int c)
{
 unsigned int p, pa, pb, pc;
 p = a + b - c;
 pa = abs(p-a);
 pb = abs(p-b);
 pc = abs(p-c);
 if ((pa <= pb) && (pa <= pc)) return a;
 else if (pb <= pc) return b;
 else return c;
}

canonical_original_code:
unsigned int paeth(unsigned int a, unsigned int b, unsigned int c)
{
 unsigned int p; unsigned int pa; unsigned int pb; unsigned int pc;
 p = a + b - c;
 pa = abs(p-a);
 pb = abs(p-b);
 pc = abs(p-c);
 if ((pa <= pb) && (pa <= pc)) return a;
 else if (pb <= pc) return b;
 else return c;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
p
unsigned int

variable_types:
pa
unsigned int

variable_types:
pb
unsigned int

variable_types:
pc
unsigned int


filter

decompiled_code:
void filter()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void filter(unsigned char *prev, unsigned char *curr, int type)
{
 switch (type)
 {
  case 0:
   break;
  case 1:
   break;
  case 2:
   break;
  case 3:
   break;
  case 4:
   break;
  default:
   break;
 }
}

variable_types:
prev
unsigned char *

variable_types:
curr
unsigned char *

variable_types: type int


decompiled_code:
void __fastcall unfilter1(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
__int64 v3; // rcx

if ( (unsigned int)step > 4 )
{
v1 = 4;
do
{
v2 = v1;
v3 = v1 - 3;
++v1;
*(_BYTE *)(a1 + v2) += *(_BYTE *)(a1 + v3);
}
while ( (unsigned int)step > v1 );
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
__int64 v3; // rcx

if ( (unsigned int)step > 4 )
{
v1 = 4;
do
{
v2 = v1;
v3 = v1 - 3;
++v1;
*(_BYTE *)(a1 + v2) += *(_BYTE *)(a1 + v3);
}
while ( (unsigned int)step > v1 );
}
}

original_code:
void unfilter1(unsigned char *curr)
{
 unsigned int pos;
 for (pos = 4; pos < step; pos++)
  curr[pos] += curr[pos-3];
}

variable_types:
pos
unsigned int


decompiled_code:
void __fastcall unfilter2(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx

if ( (unsigned int)step > 1 )
{
v2 = 1;
do
{
v3 = v2++;
*(_BYTE *)(a2 + v3) += *(_BYTE *)(a1 + v3);
}
while ( (unsigned int)step > v2 );
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx

if ( (unsigned int)step > 1 )
{
v2 = 1;
do
{
v3 = v2++;
*(_BYTE *)(a2 + v3) += *(_BYTE *)(a1 + v3);
}
while ( (unsigned int)step > v2 );
}
}

original_code:
void unfilter2(unsigned char *prev, unsigned char *curr)
{
 unsigned int pos;
 for (pos = 1; pos < step; pos++)
  curr[pos] += prev[pos];
}


decompiled_code:
char __fastcall unfilter3(_BYTE *a1, _BYTE *a2)
{
int v2; // eax
unsigned int v3; // edx
__int64 v4; // rcx
__int64 v5; // rax

a2[1] += a1[1] >> 1;
a2[2] += a1[2] >> 1;
LOBYTE(v2) = a1[3] >> 1;
a2[3] += v2;
if ( (unsigned int)step > 4 )
{
v3 = 4;
do
{
v4 = v3;
v5 = v3 - 3;
++v3;
v2 = ((unsigned __int8)a1[v4] + (unsigned __int8)a2[v5]) >> 1;
a2[v4] += v2;
}
while ( (unsigned int)step > v3 );
}
return v2;
}

canonical_decompiled_code:
char __fastcall func6(_BYTE *a1, _BYTE *a2)
{
int v2; // eax
unsigned int v3; // edx
__int64 v4; // rcx
__int64 v5; // rax

a2[1] += a1[1] >> 1;
a2[2] += a1[2] >> 1;
LOBYTE(v2) = a1[3] >> 1;
a2[3] += v2;
if ( (unsigned int)step > 4 )
{
v3 = 4;
do
{
v4 = v3;
v5 = v3 - 3;
++v3;
v2 = ((unsigned __int8)a1[v4] + (unsigned __int8)a2[v5]) >> 1;
a2[v4] += v2;
}
while ( (unsigned int)step > v3 );
}
return v2;
}

original_code:
void unfilter3(unsigned char *prev, unsigned char *curr)
{
 unsigned int pos;
 curr[1] += prev[1]/2;
 curr[2] += prev[2]/2;
 curr[3] += prev[3]/2;
 for (pos = 4; pos < step; pos++)
  curr[pos] += (curr[pos-3]+prev[pos])/2;
}


decompiled_code:
__int64 __fastcall unfilter4(unsigned __int8 *a1)
{
char v1; // al
__int64 v2; // r11
char v3; // al
__int64 v4; // r11
__int64 result; // rax
__int64 v6; // r11
unsigned int v7; // er10
__int64 v8; // rbx

v1 = paeth(0, a1[1], 0);
*(_BYTE *)(v2 + 1) += v1;
v3 = paeth(0, a1[2], 0);
*(_BYTE *)(v4 + 2) += v3;
result = paeth(0, a1[3], 0);
*(_BYTE *)(v6 + 3) += result;
if ( (unsigned int)step > 4 )
{
v7 = 4;
do
{
v8 = v7;
result = paeth(*(unsigned __int8 *)(v6 + v7 - 3), a1[v7], a1[v7 - 3]);
*(_BYTE *)(v6 + v8) += result;
}
while ( (unsigned int)step > v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
char v1; // al
__int64 v2; // r11
char v3; // al
__int64 v4; // r11
__int64 result; // rax
__int64 v6; // r11
unsigned int v7; // er10
__int64 v8; // rbx

v1 = func2(0, a1[1], 0);
*(_BYTE *)(v2 + 1) += v1;
v3 = func2(0, a1[2], 0);
*(_BYTE *)(v4 + 2) += v3;
result = func2(0, a1[3], 0);
*(_BYTE *)(v6 + 3) += result;
if ( (unsigned int)step > 4 )
{
v7 = 4;
do
{
v8 = v7;
result = func2(*(unsigned __int8 *)(v6 + v7 - 3), a1[v7], a1[v7 - 3]);
*(_BYTE *)(v6 + v8) += result;
}
while ( (unsigned int)step > v7 );
}
return result;
}

original_code:
void unfilter4(unsigned char *prev, unsigned char *curr)
{
 unsigned int pos;
 curr[1] += paeth(0, prev[1], 0);
 curr[2] += paeth(0, prev[2], 0);
 curr[3] += paeth(0, prev[3], 0);
 for (pos = 4; pos < step; pos++)
  curr[pos] += paeth(curr[pos-3], prev[pos], prev[pos-3]);
}


unfilter

decompiled_code:
void __fastcall unfilter(unsigned __int8 *a1, _BYTE *a2, int a3)
{
*a2 = 0;
if ( a3 == 3 )
{
unfilter3(a1, a2);
}
else if ( a3 > 3 )
{
if ( a3 == 4 )
unfilter4(a1);
}
else if ( a3 == 1 )
{
unfilter1((__int64)a2);
}
else if ( a3 == 2 )
{
unfilter2((__int64)a1, (__int64)a2);
}
}

original_code:
void unfilter(unsigned char *prev, unsigned char *curr, int type)
{
 curr[0] = 0;
 switch (type)
 {
  case 0:
   break;
  case 1:
   unfilter1(curr);
   break;
  case 2:
   unfilter2(prev, curr);
   break;
  case 3:
   unfilter3(prev, curr);
   break;
  case 4:
   unfilter4(prev, curr);
   break;
  default:
   break;
 }
}


original_code:
int write_code(datachunk *chunk, char *msg)
{
 unsigned int size = chunk->sizenum;
 unsigned int count = 7;
 unsigned int x = 0;
 unsigned int msgloc = 0;
 unsigned int linepos, oldblksize;
 unsigned char prevline[sizeof(char)*step];
 unsigned char currline[sizeof(char)*step];
 unsigned char charmask = 0x01;
 unsigned char matchmask = 0xFE;
 char ch, shift, endflag;
 ch = msg[msgloc];
 endflag = ch == (-1);
 shift = 0;
 for (count = 7; count < size; count += step)
 {
  oldblksize = blksize;
  x = 0;
  for(linepos = 0; linepos < step; linepos++)
  {
   if ((linepos + count) == blksize+7)
   {
    blksize = 0x00000000;
    blksize = (chunk->body[linepos+count+2] << 8) + chunk->body[linepos+count+1];
    blksize += oldblksize + 5;
    count += 5;
    x++;
   }
   if (count+linepos < size)
    currline[linepos] = chunk->body[linepos + count];
  }
  unfilter(prevline, currline, currline[0]);
  blksize = oldblksize;
  count -= 5*x;
  for(linepos = 0; linepos < step; linepos++)
  {
   if ((linepos + count) == blksize+7)
   {
    blksize = 0x00000000;
    blksize = (chunk->body[count+linepos+2] << 8) + chunk->body[count+linepos+1];
    blksize += oldblksize + 5;
    count += 5;
   }
   if (count+linepos < size)
   {
    chunk->body[count+linepos] = currline[linepos];
    if (linepos)
    {
      chunk->body[count+linepos] &= matchmask;
     chunk->body[count+linepos] |= ((ch >> shift) & charmask);
     if (shift == 7)
     {
      if (!endflag)
      {
       ch = msg[++msgloc];
       endflag = ch == (-1);
      }
      shift = 0;
     }
     else
      shift++;
    }
   }
   prevline[linepos] = currline[linepos];
  }
 }
 return endflag;
}

canonical_original_code:
int write_code(struct datachunk *chunk, char *msg)
{
 unsigned int size = chunk->sizenum;
 unsigned int count = 7;
 unsigned int x = 0;
 unsigned int msgloc = 0;
 unsigned int linepos; unsigned int oldblksize;
 unsigned char prevline[-1];
 unsigned char currline[-1];
 unsigned char charmask = 0x01;
 unsigned char matchmask = 0xFE;
 char ch; char shift; char endflag;
 ch = msg[msgloc];
 endflag = ch == (-1);
 shift = 0;
 for (count = 7; count < size; count += step)
 {
  oldblksize = blksize;
  x = 0;
  for(linepos = 0; linepos < step; linepos++)
  {
   if ((linepos + count) == blksize+7)
   {
    blksize = 0x00000000;
    blksize = (chunk->body[linepos+count+2] << 8) + chunk->body[linepos+count+1];
    blksize += oldblksize + 5;
    count += 5;
    x++;
   }
   if (count+linepos < size)
    currline[linepos] = chunk->body[linepos + count];
  }
  unfilter(prevline, currline, currline[0]);
  blksize = oldblksize;
  count -= 5*x;
  for(linepos = 0; linepos < step; linepos++)
  {
   if ((linepos + count) == blksize+7)
   {
    blksize = 0x00000000;
    blksize = (chunk->body[count+linepos+2] << 8) + chunk->body[count+linepos+1];
    blksize += oldblksize + 5;
    count += 5;
   }
   if (count+linepos < size)
   {
    chunk->body[count+linepos] = currline[linepos];
    if (linepos)
    {
      chunk->body[count+linepos] &= matchmask;
     chunk->body[count+linepos] |= ((ch >> shift) & charmask);
     if (shift == 7)
     {
      if (!endflag)
      {
       ch = msg[++msgloc];
       endflag = ch == (-1);
      }
      shift = 0;
     }
     else
      shift++;
    }
   }
   prevline[linepos] = currline[linepos];
  }
 }
 return endflag;
}

variable_types: struct datachunk { unsigned char *size; unsigned char *type; unsigned char *body; unsigned char *crc; unsigned int sizenum; unsigned int typenum; } *

variable_types:
msg
char *

variable_types:
size
unsigned int

variable_types:
count
unsigned int

variable_types:
x
unsigned int

variable_types:
msgloc
unsigned int

variable_types:
linepos
unsigned int

variable_types:
oldblksize
unsigned int

variable_types:
prevline
unsigned char [-1]

variable_types:
currline
unsigned char [-1]

variable_types:
charmask
unsigned char

variable_types:
matchmask
unsigned char

variable_types: ch char

variable_types: shift char

variable_types: endflag char


repo: jkodumal/banshee

decompiled_code:
void term_reset_stats()
{
term_stats = 0LL;
*((_DWORD *)&term_stats + 2) = 0;
}

canonical_decompiled_code:
void func0()
{
term_stats = 0LL;
*((_DWORD *)&term_stats + 2) = 0;
}

original_code:
static void term_reset_stats(void)
{
  term_stats.fresh = 0;
  term_stats.fresh_small = 0;
  term_stats.fresh_large = 0;
}

canonical_original_code:
static void term_reset_stats()
{
  term_stats.fresh = 0;
  term_stats.fresh_small = 0;
  term_stats.fresh_large = 0;
}


decompiled_code:
__int64 __fastcall term_fresh(__int64 a1)
{
LODWORD(term_stats) = term_stats + 1;
return tv_fresh(term_sort_region, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
LODWORD(term_stats) = term_stats + 1;
return tv_fresh(term_sort_region, a1);
}

original_code:
gen_e term_fresh(const char *name)
{
  term_stats.fresh++;
  return (gen_e)tv_fresh(term_sort_region,name);
}

canonical_original_code:
struct gen_e_ *term_fresh(char *name)
{
  term_stats.fresh++;
  return (struct gen_e_ *)tv_fresh(term_sort_region,name);
}

variable_types:
name
char *

return_type: struct gen_e_ { enum sort_kind { flowrow_sort=0, setif_sort=1, setst_sort=2, term_sort=3 } sort; } *


decompiled_code:
__int64 __fastcall term_fresh_large(__int64 a1)
{
++*((_DWORD *)&term_stats + 2);
return tv_fresh_large(term_sort_region, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
++*((_DWORD *)&term_stats + 2);
return tv_fresh_large(term_sort_region, a1);
}

original_code:
gen_e term_fresh_large(const char *name)
{
  term_stats.fresh_large++;
  return (gen_e)tv_fresh_large(term_sort_region,name);
}

canonical_original_code:
struct gen_e_ *term_fresh_large(char *name)
{
  term_stats.fresh_large++;
  return (struct gen_e_ *)tv_fresh_large(term_sort_region,name);
}

user_defined_types: enum sort_kind { flowrow_sort=0, setif_sort=1, setst_sort=2, term_sort=3 }


decompiled_code:
__int64 __fastcall term_fresh_small(__int64 a1)
{
++HIDWORD(term_stats);
return tv_fresh_small(term_sort_region, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
++HIDWORD(term_stats);
return tv_fresh_small(term_sort_region, a1);
}

original_code:
gen_e term_fresh_small(const char *name)
{
  term_stats.fresh_small++;
  return (gen_e)tv_fresh_small(term_sort_region,name);
}

canonical_original_code:
struct gen_e_ *term_fresh_small(char *name)
{
  term_stats.fresh_small++;
  return (struct gen_e_ *)tv_fresh_small(term_sort_region,name);
}


decompiled_code:
void *term_zero()
{
return &zero;
}

canonical_decompiled_code:
void *func5()
{
return &zero;
}

original_code:
gen_e term_zero(void)
{
  return (gen_e)&zero;
}

canonical_original_code:
struct gen_e_ *term_zero()
{
  return (gen_e)&zero;
}


decompiled_code:
void *term_one()
{
return &one;
}

canonical_decompiled_code:
void *func6()
{
return &one;
}

original_code:
gen_e term_one(void)
{
  return (gen_e)&one;
}

canonical_original_code:
struct gen_e_ *term_one()
{
  return (gen_e)&one;
}


decompiled_code:
void *term_wild()
{
return &wild;
}

canonical_decompiled_code:
void *func7()
{
return &wild;
}

original_code:
gen_e term_wild(void)
{
  return (gen_e)&wild;
}

canonical_original_code:
struct gen_e_ *term_wild()
{
  return (gen_e)&wild;
}


decompiled_code:
__int64 __fastcall term_constant(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // r12
int v5; // eax
int v6[8]; // [rsp+8h] [rbp-20h] BYREF

v6[0] = 4;
v1 = _rc_rstrdup(banshee_nonptr_region, a1);
v6[1] = stamp_string(v1);
result = term_hash_find(term_sort_hash, v6, 2LL);
if ( !result )
{
v3 = _rc_ralloc_small0(term_constant_region, 24LL);
*(_DWORD *)(v3 + 4) = 4;
v4 = v3;
v5 = stamp_fresh();
*(_QWORD *)(v4 + 16) = v1;
*(_DWORD *)(v4 + 8) = v5;
term_hash_insert(term_sort_hash, v4, v6, 2LL);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // r12
int v5; // eax
int v6[8]; // [rsp+8h] [rbp-20h] BYREF

v6[0] = 4;
v1 = _rc_rstrdup(banshee_nonptr_region, a1);
v6[1] = stamp_string(v1);
result = term_hash_find(term_sort_hash, v6, 2LL);
if ( !result )
{
v3 = _rc_ralloc_small0(term_constant_region, 24LL);
*(_DWORD *)(v3 + 4) = 4;
v4 = v3;
v5 = stamp_fresh();
*(_QWORD *)(v4 + 16) = v1;
*(_DWORD *)(v4 + 8) = v5;
term_hash_insert(term_sort_hash, v4, v6, 2LL);
result = v4;
}
return result;
}

original_code:
gen_e term_constant(const char *str)
{
  stamp st[2];
  gen_e result;
  char *name = (((void)0), __rc_rstrdup)(banshee_nonptr_region,str);
  ((void) (0));
  st[0] = 4;
  st[1] = stamp_string(name);
  if ( (result = term_hash_find(term_sort_hash,st,2)) == ((void *)0))
    {
      term_constant_ c = (sizeof(struct term_constant_) < (1 << (13 - 3)) ? (((void)0), __rc_ralloc_small0)((term_constant_region), sizeof(struct term_constant_)) : (((void)0), __rc_typed_ralloc)((term_constant_region), sizeof(struct term_constant_), 0));
      c->type = 4;
      c->st = stamp_fresh();
      c->name = name;
      result = (gen_e) c;
      term_hash_insert(term_sort_hash,result,st,2);
      return result;
    }
  else
    {
      return result;
    }
}

canonical_original_code:
struct gen_e_ *term_constant(char *str)
{
  int st[2];
  struct gen_e_ *result;
  char *name = (((void)0), __rc_rstrdup)(banshee_nonptr_region,str);
  ((void) (0));
  st[0] = 4;
  st[1] = stamp_string(name);
  if ( (result = term_hash_find(term_sort_hash,st,2)) == ((void *)0))
    {
      struct term_constant_ *c = (sizeof(struct term_constant_) < (1 << (13 - 3)) ? (((void)0), __rc_ralloc_small0)((term_constant_region), sizeof(struct term_constant_)) : (((void)0), __rc_typed_ralloc)((term_constant_region), sizeof(struct term_constant_), 0));
      c->type = 4;
      c->st = stamp_fresh();
      c->name = name;
      result = (struct gen_e_ *) c;
      term_hash_insert(term_sort_hash,result,st,2);
      return result;
    }
  else
    {
      return result;
    }
}

variable_types:
str
char *

variable_types:
st
int [2]

variable_types: struct gen_e_ { enum sort_kind { flowrow_sort=0, setif_sort=1, setst_sort=2, term_sort=3 } sort; } *

variable_types: struct term_constant_ { enum sort_kind { flowrow_sort=0, setif_sort=1, setst_sort=2, term_sort=3 } sort; int type; int st; char *name; } *

user_defined_types: struct term_constant_ { enum sort_kind sort; int type; int st; char *name; }


decompiled_code:
bool __fastcall term_is_initial_var(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == -1;
}

canonical_decompiled_code:
bool __fastcall func9(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == -1;
}

original_code:
bool term_is_initial_var(gen_e e)
{
  return ((gen_term)e)->type == -1;
}

canonical_original_code:
unsigned char term_is_initial_var(struct gen_e_ *e)
{
  return ((struct gen_term *)e)->type == -1;
}

return_type: unsigned char

user_defined_types: struct gen_term { enum sort_kind sort; int type; int st; }


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

if ( *(_DWORD *)(a1 + 4) == -1 )
result = *(unsigned int *)(term_get_ecr(a1) + 8);
else
result = *(unsigned int *)(a1 + 8);
return result;
}

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

if ( *(_DWORD *)(a1 + 4) == -1 )
result = *(unsigned int *)(func10(a1) + 8);
else
result = *(unsigned int *)(a1 + 8);
return result;
}

original_code:
stamp term_get_stamp(gen_e e)
{
  if ( ((gen_term)e)->type == -1 )
    return ((gen_term)term_get_ecr(e))->st;
  else
    return ((gen_term)e)->st;
}

canonical_original_code:
int term_get_stamp(struct gen_e_ *e)
{
  if ( ((struct gen_term *)e)->type == -1 )
    return ((struct gen_term *)term_get_ecr(e))->st;
  else
    return ((struct gen_term *)e)->st;
}


decompiled_code:
bool __fastcall term_is_zero(__int64 a1)
{
return *(_DWORD *)(term_get_ecr(a1) + 4) == 0;
}

canonical_decompiled_code:
bool __fastcall func13(__int64 a1)
{
return *(_DWORD *)(func10(a1) + 4) == 0;
}

original_code:
bool term_is_zero(gen_e e)
{
  return ( ((gen_term)term_get_ecr(e))->type == 0);
}

canonical_original_code:
unsigned char term_is_zero(struct gen_e_ *e)
{
  return ( ((struct gen_term *)term_get_ecr(e))->type == 0);
}


decompiled_code:
bool __fastcall term_is_wild(__int64 a1)
{
return *(_DWORD *)(term_get_ecr(a1) + 4) == 6;
}

canonical_decompiled_code:
bool __fastcall func14(__int64 a1)
{
return *(_DWORD *)(func10(a1) + 4) == 6;
}

original_code:
bool term_is_wild(gen_e e)
{
  return ( ((gen_term)term_get_ecr(e))->type == 6);
}

canonical_original_code:
unsigned char term_is_wild(struct gen_e_ *e)
{
  return ( ((struct gen_term *)term_get_ecr(e))->type == 6);
}


decompiled_code:
bool __fastcall term_is_one(__int64 a1)
{
return *(_DWORD *)(term_get_ecr(a1) + 4) == 1;
}

canonical_decompiled_code:
bool __fastcall func15(__int64 a1)
{
return *(_DWORD *)(func10(a1) + 4) == 1;
}

original_code:
bool term_is_one(gen_e e)
{
  return ( ((gen_term)term_get_ecr(e))->type == 1);
}

canonical_original_code:
unsigned char term_is_one(struct gen_e_ *e)
{
  return ( ((struct gen_term *)term_get_ecr(e))->type == 1);
}


decompiled_code:
bool __fastcall term_is_var(__int64 a1)
{
return *(_DWORD *)(term_get_ecr(a1) + 4) == -1;
}

canonical_decompiled_code:
bool __fastcall func16(__int64 a1)
{
return *(_DWORD *)(func10(a1) + 4) == -1;
}

original_code:
bool term_is_var(gen_e e)
{
  return ( ((gen_term)term_get_ecr(e))->type == -1);
}

canonical_original_code:
unsigned char term_is_var(struct gen_e_ *e)
{
  return ( ((struct gen_term *)term_get_ecr(e))->type == -1);
}


decompiled_code:
bool __fastcall term_is_bottom(__int64 a1)
{
bool v1; // r8
bool result; // al

v1 = term_is_zero(a1);
result = 1;
if ( !v1 )
result = term_is_var(a1);
return result;
}

canonical_decompiled_code:
bool __fastcall func17(__int64 a1)
{
bool v1; // r8
bool result; // al

v1 = func13(a1);
result = 1;
if ( !v1 )
result = func16(a1);
return result;
}

original_code:
static bool term_is_bottom(gen_e e)
{
  return (term_is_zero(e) || term_is_var(e));
}

canonical_original_code:
static unsigned char term_is_bottom(struct gen_e_ *e)
{
  return (term_is_zero(e) || term_is_var(e));
}


decompiled_code:
bool __fastcall term_is_constant(__int64 a1)
{
return *(_DWORD *)(term_get_ecr(a1) + 4) == 4;
}

canonical_decompiled_code:
bool __fastcall func18(__int64 a1)
{
return *(_DWORD *)(func10(a1) + 4) == 4;
}

original_code:
bool term_is_constant(gen_e e)
{
  return ( ((gen_term)term_get_ecr(e))->type == 4);
}

canonical_original_code:
unsigned char term_is_constant(struct gen_e_ *e)
{
  return ( ((struct gen_term *)term_get_ecr(e))->type == 4);
}


decompiled_code:
__int64 __fastcall term_get_constant_name(__int64 a1)
{
__int64 v1; // rbx
bool v2; // r8
__int64 result; // rax

v1 = term_get_ecr(a1);
v2 = term_is_constant(v1);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(v1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
__int64 v1; // rbx
bool v2; // r8
__int64 result; // rax

v1 = func10(a1);
v2 = func18(v1);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(v1 + 16);
return result;
}

original_code:
char *term_get_constant_name(gen_e e)
{
  gen_e ecr = term_get_ecr(e);
  if(! term_is_constant(ecr))
    return ((void *)0);
  else
    return ((term_constant_)ecr)->name;
}

canonical_original_code:
char *term_get_constant_name(struct gen_e_ *e)
{
  struct gen_e_ *ecr = term_get_ecr(e);
  if(! term_is_constant(ecr))
    return ((void *)0);
  else
    return ((struct term_constant_ *)ecr)->name;
}


decompiled_code:
// attributes: thunk
bool __fastcall term_eq(__int64 a1, __int64 a2)
{
return eq(a1, a2);
}

canonical_decompiled_code:
bool __fastcall func20(__int64 a1, __int64 a2)
{
return func12(a1, a2);
}

original_code:
bool term_eq(gen_e e1, gen_e e2)
{
  return eq(e1,e2);
}

canonical_original_code:
unsigned char term_eq(struct gen_e_ *e1, struct gen_e_ *e2)
{
  return eq(e1,e2);
}


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

term_rollback_info_region = newregion();
term_constant_region = newregion();
term_var_region = newregion();
term_sort_region = newregion();
result = make_term_hash(0LL);
term_sort_hash = result;
return result;
}

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

term_rollback_info_region = newregion();
term_constant_region = newregion();
term_var_region = newregion();
term_sort_region = newregion();
result = make_term_hash(0LL);
term_sort_hash = result;
return result;
}

original_code:
void term_init(void)
{
  term_rollback_info_region = newregion();
  term_constant_region = newregion();
  term_var_region = newregion();
  term_sort_region = newregion();
  term_sort_hash = make_term_hash(((void *)0));
}

canonical_original_code:
void term_init()
{
  term_rollback_info_region = newregion();
  term_constant_region = newregion();
  term_var_region = newregion();
  term_sort_region = newregion();
  term_sort_hash = make_term_hash(((void *)0));
}


decompiled_code:
__int64 term_reset()
{
term_hash_delete(term_sort_hash);
deleteregion(term_sort_region);
deleteregion(term_var_region);
deleteregion(term_constant_region);
deleteregion(term_rollback_info_region);
term_reset_stats();
return term_init();
}

canonical_decompiled_code:
__int64 func28()
{
term_hash_delete(term_sort_hash);
deleteregion(term_sort_region);
deleteregion(term_var_region);
deleteregion(term_constant_region);
deleteregion(term_rollback_info_region);
func0();
return func27();
}

original_code:
void term_reset(void)
{
  term_hash_delete(term_sort_hash);
  deleteregion(term_sort_region);
  deleteregion(term_var_region);
  deleteregion(term_constant_region);
  deleteregion(term_rollback_info_region);
  term_reset_stats();
  term_init();
}

canonical_original_code:
void term_reset()
{
  term_hash_delete(term_sort_hash);
  deleteregion(term_sort_region);
  deleteregion(term_var_region);
  deleteregion(term_constant_region);
  deleteregion(term_rollback_info_region);
  term_reset_stats();
  term_init();
}


decompiled_code:
__int64 term_set_fields()
{
return deserialize_set_obj(&term_current_rollback_info);
}

canonical_decompiled_code:
__int64 func37()
{
return deserialize_set_obj(&term_current_rollback_info);
}

original_code:
void term_set_fields(void)
{
  deserialize_set_obj((void **)&term_current_rollback_info);
}

canonical_original_code:
void term_set_fields()
{
  deserialize_set_obj((void **)&term_current_rollback_info);
}


eq

decompiled_code:
bool __fastcall eq(__int64 a1, __int64 a2)
{
int v2; // ebx

v2 = term_get_stamp(a1);
return v2 == (unsigned int)term_get_stamp(a2);
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // ebx

v2 = func11(a1);
return v2 == (unsigned int)func11(a2);
}

original_code:
static bool eq(gen_e e1, gen_e e2)
{
  return term_get_stamp(e1) == term_get_stamp(e2);
}

canonical_original_code:
static unsigned char eq(struct gen_e_ *e1, struct gen_e_ *e2)
{
  return term_get_stamp(e1) == term_get_stamp(e2);
}


decompiled_code:
__int64 __fastcall check2(int a1)
{
if ( a1 <= 0x1FFFFFFF )
return (unsigned int)a1;
_fail("stamp.c", 64LL, "check2", "Unable to create a stamp with regular index\n");
return check1();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( a1 <= 0x1FFFFFFF )
return (unsigned int)a1;
_fail("stamp.c", 64LL, "check2", "Unable to create a stamp with regular index\n");
return func1();
}

original_code:
static inline stamp check2(int i)
{
  if (i > bounds2)
    __fail("stamp.c", 64, __FUNCTION__, "Unable to create a stamp with regular index\n");
  return i;
}

canonical_original_code:
static inline int check2(int i)
{
  if (i > bounds2)
    __fail("stamp.c", 64, __FUNCTION__, "Unable to create a stamp with regular index\n");
  return i;
}

variable_types: i int


decompiled_code:
__int64 __fastcall check1(unsigned int a1)
{
if ( a1 != 0x80000000 )
return a1;
_fail("stamp.c", 57LL, "check1", "Unable to create stamp with small index\n");
return check3();
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
if ( a1 != 0x80000000 )
return a1;
_fail("stamp.c", 57LL, "check1", "Unable to create stamp with small index\n");
return func2();
}

original_code:
static inline stamp check1(int i)
{
  if (i <= bounds1)
    __fail("stamp.c", 57, __FUNCTION__, "Unable to create stamp with small index\n");
  return i;
}

canonical_original_code:
static inline int check1(int i)
{
  if (i <= bounds1)
    __fail("stamp.c", 57, __FUNCTION__, "Unable to create stamp with small index\n");
  return i;
}


decompiled_code:
__int64 __fastcall check3(unsigned int a1)
{
if ( a1 != 0x7FFFFFFF )
return a1;
_fail("stamp.c", 71LL, "check3", "Unable to create a stamp with large index\n");
return new_stamp_list();
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
if ( a1 != 0x7FFFFFFF )
return a1;
_fail("stamp.c", 71LL, "check3", "Unable to create a stamp with large index\n");
return func3();
}

original_code:
static inline stamp check3(int i)
{
  if (i >= bounds3)
    __fail("stamp.c", 71, __FUNCTION__, "Unable to create a stamp with large index\n");
  return i;
}

canonical_original_code:
static inline int check3(int i)
{
  if (i >= bounds3)
    __fail("stamp.c", 71, __FUNCTION__, "Unable to create a stamp with large index\n");
  return i;
}


decompiled_code:
__int64 stamp_fresh()
{
return check2(++count2);
}

canonical_decompiled_code:
__int64 func31()
{
return func0(++count2);
}

original_code:
stamp stamp_fresh(void)
{
  return (check2(++count2));
}

canonical_original_code:
int stamp_fresh()
{
  return (check2(++count2));
}


decompiled_code:
__int64 stamp_fresh_small()
{
return check1(--count1);
}

canonical_decompiled_code:
__int64 func32()
{
return func1(--count1);
}

original_code:
stamp stamp_fresh_small(void)
{
  return (check1(--count1));
}

canonical_original_code:
int stamp_fresh_small()
{
  return (check1(--count1));
}


decompiled_code:
__int64 stamp_fresh_large()
{
return check3(++count3);
}

canonical_decompiled_code:
__int64 func33()
{
return func2(++count3);
}

original_code:
stamp stamp_fresh_large(void)
{
  return (check3(++count3));
}

canonical_original_code:
int stamp_fresh_large()
{
  return (check3(++count3));
}


decompiled_code:
__int64 __fastcall stamp_string(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !(unsigned __int8)hash_table_lookup(str_hash, a1, v2) )
{
v2[0] = stamp_fresh();
hash_table_insert(str_hash, a1, (int)v2[0]);
}
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func34(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !(unsigned __int8)hash_table_lookup(str_hash, a1, v2) )
{
v2[0] = func31();
hash_table_insert(str_hash, a1, (int)v2[0]);
}
return v2[0];
}

original_code:
stamp stamp_string(const char *str)
{
  int st;
  ((void) (0));
  if (! hash_table_lookup(str_hash,(hash_key)str, (hash_data *) &st))
    {
      st = stamp_fresh();
      (void)hash_table_insert(str_hash,(hash_key)str,(hash_data) st);
    }
  return st;
}

canonical_original_code:
int stamp_string(char *str)
{
  int st;
  ((void) (0));
  if (! hash_table_lookup(str_hash,(void *)str, (void **) &st))
    {
      st = stamp_fresh();
      (void)hash_table_insert(str_hash,(void *)str,(void *) st);
    }
  return st;
}

variable_types: st int


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

count1 = 0;
count2 = 2000;
count3 = 0x1FFFFFFF;
result = make_persistent_string_hash_table(32LL, 0LL);
str_hash = result;
return result;
}

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

count1 = 0;
count2 = 2000;
count3 = 0x1FFFFFFF;
result = make_persistent_string_hash_table(32LL, 0LL);
str_hash = result;
return result;
}

original_code:
void stamp_init(void)
{
  count1 = 0;
  count2 = 2000;
  count3 = 536870911;
  str_hash = make_persistent_string_hash_table(32,
            0);
}

canonical_original_code:
void stamp_init()
{
  count1 = 0;
  count2 = 2000;
  count3 = 536870911;
  str_hash = make_persistent_string_hash_table(32,
            0);
}


decompiled_code:
// attributes: thunk
__int64 stamp_reset()
{
return stamp_init();
}

canonical_decompiled_code:
__int64 func36()
{
return func35();
}

original_code:
void stamp_reset(void)
{
  stamp_init();
}

canonical_original_code:
void stamp_reset()
{
  stamp_init();
}


decompiled_code:
__int64 stamp_set_fields()
{
return deserialize_set_obj(&str_hash);
}

canonical_decompiled_code:
__int64 func40()
{
return deserialize_set_obj(&str_hash);
}

original_code:
void stamp_set_fields(void)
{
  deserialize_set_obj((void **)&str_hash);
}

canonical_original_code:
void stamp_set_fields()
{
  deserialize_set_obj((void **)&str_hash);
}


original_code:
unsigned long stamp_hash(hash_key key)
{
  unsigned long keyval = (unsigned long)key;
  keyval += (keyval << 12);
  keyval ^= (keyval >> 22);
  keyval += (keyval << 4);
  keyval ^= (keyval >> 9);
  keyval += (keyval << 10);
  keyval ^= (keyval >> 2);
  keyval += (keyval << 7);
  keyval ^= (keyval >> 12);
  return keyval;
}

canonical_original_code:
unsigned long stamp_hash(void *key)
{
  unsigned long keyval = (unsigned long)key;
  keyval += (keyval << 12);
  keyval ^= (keyval >> 22);
  keyval += (keyval << 4);
  keyval ^= (keyval >> 9);
  keyval += (keyval << 10);
  keyval ^= (keyval >> 2);
  keyval += (keyval << 7);
  keyval ^= (keyval >> 12);
  return keyval;
}

variable_types:
key
void *

variable_types:
keyval
unsigned long

return_type: unsigned long


decompiled_code:
bool __fastcall stamp_eq(__int64 a1, __int64 a2)
{
return a2 == a1;
}

canonical_decompiled_code:
bool __fastcall func44(__int64 a1, __int64 a2)
{
return a2 == a1;
}

original_code:
bool stamp_eq(hash_key s1, hash_key s2)
{
  return s1 == s2;
}

canonical_original_code:
unsigned char stamp_eq(void *s1, void *s2)
{
  return s1 == s2;
}


decompiled_code:
void sd_del_list()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void sd_del_list(sd_list l)
{
}

canonical_original_code:
void sd_del_list(struct sd_list *l)
{
}

variable_types: struct sd_list { struct sd_list_pos { struct sd_list_pos *next; struct sd_list_pos *previous; } *first; struct sd_list_pos *null; struct sd_list_pos *last; } *

user_defined_types: struct sd_list { struct sd_list_pos *first; struct sd_list_pos *null; struct sd_list_pos *last; }


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

a2[1] = (__int64)a1;
result = *a1;
*a2 = *a1;
*(_QWORD *)(result + 8) = a2;
*a1 = (__int64)a2;
return result;
}

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

a2[1] = (__int64)a1;
result = *a1;
*a2 = *a1;
*(_QWORD *)(result + 8) = a2;
*a1 = (__int64)a2;
return result;
}

original_code:
void sd_insert_after(sd_list_pos where, sd_list_pos data)
{
  data->previous = where;
  data->next = where->next;
  where->next->previous = data;
  where->next = data;
}

canonical_original_code:
void sd_insert_after(struct sd_list_pos *where, struct sd_list_pos *data)
{
  data->previous = where;
  data->next = where->next;
  where->next->previous = data;
  where->next = data;
}

variable_types: struct sd_list_pos { struct sd_list_pos *next; struct sd_list_pos *previous; } *

variable_types:
data
struct sd_list_pos *


decompiled_code:
// attributes: thunk
__int64 __fastcall sd_add_first(__int64 *a1, __int64 *a2)
{
return sd_insert_after(a1, a2);
}

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

original_code:
void sd_add_first(sd_list l, sd_list_pos data)
{
  sd_insert_after((sd_list_pos)l, data);
}

canonical_original_code:
void sd_add_first(struct sd_list *l, struct sd_list_pos *data)
{
  sd_insert_after((struct sd_list_pos *)l, data);
}

user_defined_types: struct sd_list_pos { struct sd_list_pos *next; struct sd_list_pos *previous; }


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

result = *a1;
*(_QWORD *)a1[1] = *a1;
*(_QWORD *)(result + 8) = a1[1];
return result;
}

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

result = *a1;
*(_QWORD *)a1[1] = *a1;
*(_QWORD *)(result + 8) = a1[1];
return result;
}

original_code:
void sd_remove(sd_list_pos what)
{
  what->previous->next = what->next;
  what->next->previous = what->previous;
}

canonical_original_code:
void sd_remove(struct sd_list_pos *what)
{
  what->previous->next = what->next;
  what->next->previous = what->previous;
}


decompiled_code:
__int64 __fastcall sd_first(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
sd_list_pos sd_first(sd_list l)
{
  return l->first;
}

canonical_original_code:
struct sd_list_pos *sd_first(struct sd_list *l)
{
  return l->first;
}

variable_types: struct sd_list { struct sd_list_pos *first; struct sd_list_pos *null; struct sd_list_pos *last; } *

return_type: struct sd_list_pos { struct sd_list_pos *next; struct sd_list_pos *previous; } *


decompiled_code:
__int64 __fastcall sd_last(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
sd_list_pos sd_last(sd_list l)
{
  return l->last;
}

canonical_original_code:
struct sd_list_pos *sd_last(struct sd_list *l)
{
  return l->last;
}


decompiled_code:
__int64 __fastcall sd_length(__int64 a1)
{
_QWORD **v1; // rax
__int64 v2; // r8
_QWORD *i; // rax

v1 = (_QWORD **)sd_first(a1);
v2 = 0LL;
for ( i = *v1; i; ++v2 )
i = (_QWORD *)*i;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_QWORD **v1; // rax
__int64 v2; // r8
_QWORD *i; // rax

v1 = (_QWORD **)func4(a1);
v2 = 0LL;
for ( i = *v1; i; ++v2 )
i = (_QWORD *)*i;
return v2;
}

original_code:
unsigned long sd_length(sd_list l)
{
  sd_list_pos scan;
  unsigned long len = 0;
  for (scan = sd_first((l)); !(!(scan)->next); scan = ((scan)->next)) len++;
  return len;
}

canonical_original_code:
unsigned long sd_length(struct sd_list *l)
{
  struct sd_list_pos *scan;
  unsigned long len = 0;
  for (scan = sd_first((l)); !(!(scan)->next); scan = ((scan)->next)) len++;
  return len;
}

variable_types:
len
unsigned long


hash

decompiled_code:
__int64 __fastcall hash(int a1, __int64 a2, int a3)
{
__int64 v5; // r9
__int64 v6; // rsi
int v7; // ecx
unsigned int v8; // er11
unsigned int v9; // eax
unsigned int v10; // edx

if ( a3 <= 0 )
return 0LL;
v5 = (unsigned int)(a3 + 1);
v6 = 1LL;
v7 = 83;
v8 = 0;
while ( 1 )
{
v9 = abs32(*(_DWORD *)(a2 + 4 * v6 - 4));
v10 = v6++;
v8 = a1 & (v8 + v7 * v9);
if ( v5 == v6 )
break;
v7 = primes[v10 % 0xF];
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3)
{
__int64 v5; // r9
__int64 v6; // rsi
int v7; // ecx
unsigned int v8; // er11
unsigned int v9; // eax
unsigned int v10; // edx

if ( a3 <= 0 )
return 0LL;
v5 = (unsigned int)(a3 + 1);
v6 = 1LL;
v7 = 83;
v8 = 0;
while ( 1 )
{
v9 = abs32(*(_DWORD *)(a2 + 4 * v6 - 4));
v10 = v6++;
v8 = a1 & (v8 + v7 * v9);
if ( v5 == v6 )
break;
v7 = primes[v10 % 0xF];
}
return v8;
}

original_code:
static int hash(int ub, stamp stamps[], int len)
{
  int i, n;
  n = 0;
  for (i = 0; i < len; i++)
    {
      n = (n + (primes[i % 15] * abs(stamps[i]))) & ub;
    }
  return n;
}

canonical_original_code:
static int hash(int ub, int stamps[], int len)
{
  int i; int n;
  n = 0;
  for (i = 0; i < len; i++)
    {
      n = (n + (primes[i % 15] * abs(stamps[i]))) & ub;
    }
  return n;
}

variable_types: ub int

variable_types:
stamps
int []

variable_types: len int

variable_types: n int


rehash

original_code:
static void rehash(hash_set hs)
{
  int *old_table;
  int old_capacity, i;
  old_table = hs->table;
  old_capacity = hs->capacity;
  hs->capacity *= 2;
  hs->ub = ((1<<++hs->size)-1);
  hs->table = (int *)calloc(hs->capacity, sizeof(int));
  ((void) (0));
  for (i = 0; i < old_capacity; i++)
    {
      reinsert(hs->table, hs->ub, old_table[i]);
    }
  free(old_table);
}

canonical_original_code:
static void rehash(struct hash_set *hs)
{
  int *old_table;
  int old_capacity; int i;
  old_table = hs->table;
  old_capacity = hs->capacity;
  hs->capacity *= 2;
  hs->ub = ((1<<++hs->size)-1);
  hs->table = (int *)calloc(hs->capacity, sizeof(int));
  ((void) (0));
  for (i = 0; i < old_capacity; i++)
    {
      reinsert(hs->table, hs->ub, old_table[i]);
    }
  free(old_table);
}

variable_types: struct hash_set { int *table; unsigned int ub; unsigned int capacity; unsigned int inserts; unsigned int size; } *


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

result = (unsigned int)(*(_DWORD *)(a1 + 28) + 1);
*(_DWORD *)(a1 + 28) = result;
if ( *(_DWORD *)(a1 + 24) == (_DWORD)result )
result = rehash(a1);
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a1 + 28) + 1);
*(_DWORD *)(a1 + 28) = result;
if ( *(_DWORD *)(a1 + 24) == (_DWORD)result )
result = func1(a1);
return result;
}

original_code:
static void post_insert(hash_set hs)
{
  int capacity = hs->capacity;
  int inserts = ++hs->inserts;
  float percent_capacity = capacity * .85;
  if ( (float) inserts >= percent_capacity)
    {
      rehash(hs);
    }
}

canonical_original_code:
static void post_insert(struct hash_set *hs)
{
  int capacity = hs->capacity;
  int inserts = ++hs->inserts;
  float percent_capacity = capacity * .85;
  if ( (float) inserts >= percent_capacity)
    {
      rehash(hs);
    }
}

variable_types: capacity int

variable_types: inserts int

user_defined_types: struct hash_set { int *table; unsigned int ub; unsigned int capacity; unsigned int inserts; unsigned int size; }


walk

decompiled_code:
const void ***__fastcall walk(const void ***a1, const void *a2, int a3)
{
const void ***v3; // r12
size_t v5; // r14
const void **v6; // rbx

if ( !a1 )
return 0LL;
v3 = a1;
v5 = 4LL * a3;
while ( 1 )
{
v6 = *v3;
if ( *(_DWORD *)*v3 == a3 && !memcmp(a2, v6[1], v5) )
break;
v3 = (const void ***)v3[1];
if ( !v3 )
return v3;
}
return (const void ***)v6[2];
}

canonical_decompiled_code:
const void ***__fastcall func3(const void ***a1, const void *a2, int a3)
{
const void ***v3; // r12
size_t v5; // r14
const void **v6; // rbx

if ( !a1 )
return 0LL;
v3 = a1;
v5 = 4LL * a3;
while ( 1 )
{
v6 = *v3;
if ( *(_DWORD *)*v3 == a3 && !memcmp(a2, v6[1], v5) )
break;
v3 = (const void ***)v3[1];
if ( !v3 )
return v3;
}
return (const void ***)v6[2];
}

original_code:
static gen_e walk(term_bucket b, stamp stamps[], int len)
{
  term_bucket cur;
  for(cur = b; cur; cur = cur->next)
    {
      if (len == cur->entry->length
   && (memcmp(stamps, cur->entry->stamps, sizeof(int)*len) == 0) )
 return cur->entry->e;
    }
  return ((void *)0);
}

canonical_original_code:
static struct gen_e_ *walk(struct term_bucket *b, int stamps[], int len)
{
  struct term_bucket *cur;
  for(cur = b; cur; cur = cur->next)
    {
      if (len == cur->entry->length
   && (memcmp(stamps, cur->entry->stamps, sizeof(int)*len) == 0) )
 return cur->entry->e;
    }
  return ((void *)0);
}

variable_types: struct term_bucket { struct hash_entry { int length; int *stamps; struct gen_e_ *e; } *entry; struct term_bucket *next; } *

variable_types: struct term_bucket { struct hash_entry { int length; int *stamps; struct gen_e_ { enum sort_kind { flowrow_sort=0, setif_sort=1, setst_sort=2, term_sort=3 } sort; } *e; } *entry; struct term_bucket *next; } *

user_defined_types: struct term_bucket { struct hash_entry *entry; struct term_bucket *next; }


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

term_bucketptr_region = newregion();
term_bucket_region = newregion();
term_hash_region = newregion();
result = newregion();
hash_entry_region = result;
return result;
}

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

term_bucketptr_region = newregion();
term_bucket_region = newregion();
term_hash_region = newregion();
result = newregion();
hash_entry_region = result;
return result;
}

original_code:
void term_hash_init()
{
  term_bucketptr_region = newregion();
  term_bucket_region = newregion();
  term_hash_region = newregion();
  hash_entry_region = newregion();
}


decompiled_code:
__int64 term_hash_reset()
{
deleteregion(term_bucketptr_region);
deleteregion(term_bucket_region);
deleteregion(term_hash_region);
deleteregion(hash_entry_region);
return term_hash_init();
}

canonical_decompiled_code:
__int64 func10()
{
deleteregion(term_bucketptr_region);
deleteregion(term_bucket_region);
deleteregion(term_hash_region);
deleteregion(hash_entry_region);
return func9();
}

original_code:
void term_hash_reset()
{
  deleteregion(term_bucketptr_region);
  deleteregion(term_bucket_region);
  deleteregion(term_hash_region);
  deleteregion(hash_entry_region);
  term_hash_init();
}


bclearb

decompiled_code:
int *__fastcall bclearb(int *a1)
{
memset(a1 + 2, 0, 8LL * *a1);
return a1;
}

canonical_decompiled_code:
int *__fastcall func1(int *a1)
{
memset(a1 + 2, 0, 8LL * *a1);
return a1;
}

original_code:
bitset bclearb(bitset b)
{
  memset(b->bitset, 0, b->bsize * sizeof(b->bitset[0]));
  return b;
}

canonical_original_code:
struct { int bsize; long bitset[]; } *bclearb(struct { int bsize; long bitset[]; } *b)
{
  memset(b->bitset, 0, b->bsize * sizeof(b->bitset[0]));
  return b;
}

variable_types:
b
struct { int bsize; long bitset[]; } *

return_type: struct { int bsize; long bitset[]; } *


bunionb

original_code:
bitset bunionb(bitset b1, bitset b2)
{
  int i, bsize = b1->bsize;
  ((void) sizeof ((b1->size == b2->size) ? 1 : 0), __extension__ ({ if (b1->size == b2->size) ; else __assert_fail ("b1->size == b2->size", "bitset.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  for (i = 0; i < bsize; i++) b1->bitset[i] |= b2->bitset[i];
  return b1;
}

canonical_original_code:
struct { int bsize; long bitset[]; } *bunionb(struct { int bsize; long bitset[]; } *b1, struct { int bsize; long bitset[]; } *b2)
{
  int i; int bsize = b1->bsize;
  ((void) sizeof ((b1->size == b2->size) ? 1 : 0), __extension__ ({ if (b1->size == b2->size) ; else __assert_fail ("b1->size == b2->size", "bitset.c", 85, __extension__ __PRETTY_FUNCTION__); }));
  for (i = 0; i < bsize; i++) b1->bitset[i] |= b2->bitset[i];
  return b1;
}

variable_types: i int

variable_types: bsize int


bintersectionb

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

v2 = *a1;
if ( a1[1] != *(_DWORD *)(a2 + 4) )
_assert_fail("b1->size == b2->size", "bitset.c", 0x6Au, "bintersectionb");
v3 = 1LL;
if ( v2 > 0 )
{
do
{
*(_QWORD *)&a1[2 * v3] &= *(_QWORD *)(a2 + 8 * v3);
++v3;
}
while ( v3 != v2 + 1 );
}
return a1;
}

original_code:
bitset bintersectionb(bitset b1, bitset b2)
{
  int i, bsize = b1->bsize;
  ((void) sizeof ((b1->size == b2->size) ? 1 : 0), __extension__ ({ if (b1->size == b2->size) ; else __assert_fail ("b1->size == b2->size", "bitset.c", 106, __extension__ __PRETTY_FUNCTION__); }));
  for (i = 0; i < bsize; i++) b1->bitset[i] &= b2->bitset[i];
  return b1;
}

canonical_original_code:
struct { int bsize; long bitset[]; } *bintersectionb(struct { int bsize; long bitset[]; } *b1, struct { int bsize; long bitset[]; } *b2)
{
  int i; int bsize = b1->bsize;
  ((void) sizeof ((b1->size == b2->size) ? 1 : 0), __extension__ ({ if (b1->size == b2->size) ; else __assert_fail ("b1->size == b2->size", "bitset.c", 106, __extension__ __PRETTY_FUNCTION__); }));
  for (i = 0; i < bsize; i++) b1->bitset[i] &= b2->bitset[i];
  return b1;
}