inverterPalavras

decompiled_code:
__int64 __fastcall inverterPalavras(__int64 a1)
{
char *v1; // rbp
unsigned int v2; // er13
char *v4; // rbx
int v5; // esi
int v6; // edx
int v7; // ecx
int v8; // er8
int v9; // er9
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9
int v14[8]; // [rsp+0h] [rbp-68h] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF

v1 = *(char **)a1;
if ( !(unsigned __int8)initString((__int64)&ptr) || !(unsigned __int8)initPilha(v14, *(unsigned int *)(a1 + 16)) )
return 0;
while ( v1 )
{
v5 = *v1;
if ( *v1 == 32 )
{
if ( !(unsigned __int8)inverterLetras((__int64)&ptr) )
return 0;
v5 = 32;
inserirChar((__int64)&ptr, 32);
inserirStringEmPilha((__int64)v14, 32, v6, v7, v8, v9, ptr);
if ( !(unsigned __int8)initString((__int64)&ptr) )
return 0;
}
else
{
inserirChar((__int64)&ptr, v5);
}
v4 = (char *)*((_QWORD *)v1 + 1);
free(v1);
if ( !v4 )
{
if ( !(unsigned __int8)inverterLetras((__int64)&ptr) )
return 0;
inserirStringEmPilha((__int64)v14, v5, v10, v11, v12, v13, ptr);
break;
}
v1 = v4;
}
v2 = initString(a1);
if ( !(_BYTE)v2 )
return 0;
inserirPilhaEmString((__int64)v14, a1);
freePilha(v14);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
char *v1; // rbp
unsigned int v2; // er13
char *v4; // rbx
int v5; // esi
int v6; // edx
int v7; // ecx
int v8; // er8
int v9; // er9
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9
int v14[8]; // [rsp+0h] [rbp-68h] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF

v1 = *(char **)a1;
if ( !(unsigned __int8)func0((__int64)&ptr) || !(unsigned __int8)initPilha(v14, *(unsigned int *)(a1 + 16)) )
return 0;
while ( v1 )
{
v5 = *v1;
if ( *v1 == 32 )
{
if ( !(unsigned __int8)func11((__int64)&ptr) )
return 0;
v5 = 32;
func3((__int64)&ptr, 32);
func9((__int64)v14, 32, v6, v7, v8, v9, ptr);
if ( !(unsigned __int8)func0((__int64)&ptr) )
return 0;
}
else
{
func3((__int64)&ptr, v5);
}
v4 = (char *)*((_QWORD *)v1 + 1);
free(v1);
if ( !v4 )
{
if ( !(unsigned __int8)func11((__int64)&ptr) )
return 0;
func9((__int64)v14, v5, v10, v11, v12, v13, ptr);
break;
}
v1 = v4;
}
v2 = func0(a1);
if ( !(_BYTE)v2 )
return 0;
func10((__int64)v14, a1);
freePilha(v14);
return v2;
}

original_code:
_Bool inverterPalavras(string * str){
    pilha pil;
    caracter * pos, * aux;
    string strAux;
    pos = str->inicio;
    if(!initString(&strAux))
        return 0;
    if(!initPilha(&pil, str->len))
        return 0;
    while(pos != ((void *)0)){
        if(pos->value != ' '){
            inserirChar(&strAux, pos->value);
        }else{
            if(!inverterLetras(&strAux))
                return 0;
            inserirChar(&strAux, ' ');
            inserirStringEmPilha(strAux, &pil);
            if(!initString(&strAux))
                return 0;
        }
        aux = pos;
        pos = pos->prox;
        free(aux);
        if(pos == ((void *)0)){
            if(!inverterLetras(&strAux))
                return 0;
            inserirStringEmPilha(strAux, &pil);
        }
    }
    if(!initString(str))
        return 0;
    inserirPilhaEmString(&pil, str);
    freePilha(&pil);
    return 1;
}

canonical_original_code:
_Bool inverterPalavras(struct tString *str){
    struct tPilha pil;
    struct tCaracter *pos; struct tCaracter *aux;
    struct tString strAux;
    pos = str->inicio;
    if(!initString(&strAux))
        return 0;
    if(!initPilha(&pil, str->len))
        return 0;
    while(pos != ((void *)0)){
        if(pos->value != ' '){
            inserirChar(&strAux, pos->value);
        }else{
            if(!inverterLetras(&strAux))
                return 0;
            inserirChar(&strAux, ' ');
            inserirStringEmPilha(strAux, &pil);
            if(!initString(&strAux))
                return 0;
        }
        aux = pos;
        pos = pos->prox;
        free(aux);
        if(pos == ((void *)0)){
            if(!inverterLetras(&strAux))
                return 0;
            inserirStringEmPilha(strAux, &pil);
        }
    }
    if(!initString(str))
        return 0;
    inserirPilhaEmString(&pil, str);
    freePilha(&pil);
    return 1;
}


inverterLetrasPalavras

decompiled_code:
__int64 __fastcall inverterLetrasPalavras(__int64 a1)
{
char *v1; // rbp
char *v3; // rbx
int v4; // edx
int v5; // ecx
int v6; // er8
int v7; // er9
int v8; // esi
int v9; // edx
int v10; // ecx
int v11; // er8
int v12; // er9
unsigned int v13; // er13
int v14[8]; // [rsp+0h] [rbp-68h] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF

v1 = *(char **)a1;
if ( !(unsigned __int8)initString((__int64)&ptr) || !(unsigned __int8)initPilha(v14, *(unsigned int *)(a1 + 16)) )
return 0LL;
while ( v1 )
{
v8 = *v1;
if ( *v1 == 32 )
{
v8 = 32;
inserirChar((__int64)&ptr, 32);
inserirStringEmPilha((__int64)v14, 32, v9, v10, v11, v12, ptr);
if ( !(unsigned __int8)initString((__int64)&ptr) )
return 0LL;
}
else
{
inserirChar((__int64)&ptr, v8);
}
v3 = (char *)*((_QWORD *)v1 + 1);
free(v1);
if ( !v3 )
{
inserirStringEmPilha((__int64)v14, v8, v4, v5, v6, v7, ptr);
break;
}
v1 = v3;
}
v13 = initString(a1);
if ( !(_BYTE)v13 )
return 0LL;
inserirPilhaEmString((__int64)v14, a1);
freePilha(v14);
inverterPalavras(a1);
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
char *v1; // rbp
char *v3; // rbx
int v4; // edx
int v5; // ecx
int v6; // er8
int v7; // er9
int v8; // esi
int v9; // edx
int v10; // ecx
int v11; // er8
int v12; // er9
unsigned int v13; // er13
int v14[8]; // [rsp+0h] [rbp-68h] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF

v1 = *(char **)a1;
if ( !(unsigned __int8)func0((__int64)&ptr) || !(unsigned __int8)initPilha(v14, *(unsigned int *)(a1 + 16)) )
return 0LL;
while ( v1 )
{
v8 = *v1;
if ( *v1 == 32 )
{
v8 = 32;
func3((__int64)&ptr, 32);
func9((__int64)v14, 32, v9, v10, v11, v12, ptr);
if ( !(unsigned __int8)func0((__int64)&ptr) )
return 0LL;
}
else
{
func3((__int64)&ptr, v8);
}
v3 = (char *)*((_QWORD *)v1 + 1);
free(v1);
if ( !v3 )
{
func9((__int64)v14, v8, v4, v5, v6, v7, ptr);
break;
}
v1 = v3;
}
v13 = func0(a1);
if ( !(_BYTE)v13 )
return 0LL;
func10((__int64)v14, a1);
freePilha(v14);
func12(a1);
return v13;
}

original_code:
_Bool inverterLetrasPalavras(string * str){
    pilha pil;
    caracter * pos, * aux;
    string strAux;
    pos = str->inicio;
    if(!initString(&strAux))
        return 0;
    if(!initPilha(&pil, str->len))
        return 0;
    while(pos != ((void *)0)){
        if(pos->value != ' '){
            inserirChar(&strAux, pos->value);
        }else{
            inserirChar(&strAux, ' ');
            inserirStringEmPilha(strAux, &pil);
            if(!initString(&strAux))
                return 0;
        }
        aux = pos;
        pos = pos->prox;
        free(aux);
        if(pos == ((void *)0))
            inserirStringEmPilha(strAux, &pil);
    }
    if(!initString(str))
        return 0;
    inserirPilhaEmString(&pil, str);
    freePilha(&pil);
    inverterPalavras(str);
    return 1;
}

canonical_original_code:
_Bool inverterLetrasPalavras(struct tString *str){
    struct tPilha pil;
    struct tCaracter *pos; struct tCaracter *aux;
    struct tString strAux;
    pos = str->inicio;
    if(!initString(&strAux))
        return 0;
    if(!initPilha(&pil, str->len))
        return 0;
    while(pos != ((void *)0)){
        if(pos->value != ' '){
            inserirChar(&strAux, pos->value);
        }else{
            inserirChar(&strAux, ' ');
            inserirStringEmPilha(strAux, &pil);
            if(!initString(&strAux))
                return 0;
        }
        aux = pos;
        pos = pos->prox;
        free(aux);
        if(pos == ((void *)0))
            inserirStringEmPilha(strAux, &pil);
    }
    if(!initString(str))
        return 0;
    inserirPilhaEmString(&pil, str);
    freePilha(&pil);
    inverterPalavras(str);
    return 1;
}

variable_types: struct tString { struct tCaracter { char value; struct tCaracter *prox; struct tCaracter *ante; } *inicio; struct tCaracter *ultimo; int len; } *

variable_types: struct tPilha { int topo; char *p; int tm; }

user_defined_types: struct tString { struct tCaracter *inicio; struct tCaracter *ultimo; int len; }


printStringFrente

decompiled_code:
int __fastcall printStringFrente(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char *a7)
{
char *i; // rbx
int result; // eax

for ( i = a7; i; i = (char *)*((_QWORD *)i + 1) )
result = putchar(*i);
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char *a7)
{
char *i; // rbx
int result; // eax

for ( i = a7; i; i = (char *)*((_QWORD *)i + 1) )
result = putchar(*i);
return result;
}

original_code:
void printStringFrente(string str){
    caracter * pos;
    pos = str.inicio;
    while(pos != ((void *)0)){
        printf("%c", pos->value);
        pos = pos->prox;
    }
}

canonical_original_code:
void printStringFrente(struct tString str){
    struct tCaracter *pos;
    pos = str.inicio;
    while(pos != ((void *)0)){
        printf("%c", pos->value);
        pos = pos->prox;
    }
}

variable_types: struct tString { struct tCaracter { char value; struct tCaracter *prox; struct tCaracter *ante; } *inicio; struct tCaracter *ultimo; int len; }

return_type: void


printStringTras

decompiled_code:
int __fastcall printStringTras(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, char *a8)
{
char *i; // rbx
int result; // eax

for ( i = a8; i; i = (char *)*((_QWORD *)i + 2) )
result = putchar(*i);
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, char *a8)
{
char *i; // rbx
int result; // eax

for ( i = a8; i; i = (char *)*((_QWORD *)i + 2) )
result = putchar(*i);
return result;
}

original_code:
void printStringTras(string str){
    caracter * pos;
    pos = str.ultimo;
    while(pos != ((void *)0)){
        printf("%c", pos->value);
        pos = pos->ante;
    }
}

canonical_original_code:
void printStringTras(struct tString str){
    struct tCaracter *pos;
    pos = str.ultimo;
    while(pos != ((void *)0)){
        printf("%c", pos->value);
        pos = pos->ante;
    }
}

variable_types: struct tCaracter { char value; struct tCaracter *prox; struct tCaracter *ante; } *


repo: peete-q/lua-stream

decompiled_code:
void __fastcall buffer_delete(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void buffer_delete(buffer_t *self)
{
 free((*self));
 (*self) = ((void *)0);
}

canonical_original_code:
void buffer_delete(struct buffer_ **self)
{
 free((*self));
 (*self) = ((void *)0);
}

variable_types: struct buffer_ { unsigned long pos; unsigned long size; char ptr[]; } **


decompiled_code:
void *__fastcall buffer_read(__int64 a1, __int64 a2, void *a3, size_t a4)
{
size_t v6; // rdx
const void *v7; // rsi

v6 = *(_QWORD *)(*(_QWORD *)a1 + 8LL) - a2;
v7 = (const void *)(*(_QWORD *)a1 + a2 + 16);
if ( v6 > a4 )
v6 = a4;
return memcpy(a3, v7, v6);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, __int64 a2, void *a3, size_t a4)
{
size_t v6; // rdx
const void *v7; // rsi

v6 = *(_QWORD *)(*(_QWORD *)a1 + 8LL) - a2;
v7 = (const void *)(*(_QWORD *)a1 + a2 + 16);
if ( v6 > a4 )
v6 = a4;
return memcpy(a3, v7, v6);
}

original_code:
void buffer_read(buffer_t *self, size_t pos, void* data, size_t size)
{
 size_t read = (((*self)->size - pos) < (size) ? (*self)->size - pos : size);
 memcpy(data, (*self)->ptr + pos, read);
}

canonical_original_code:
void buffer_read(struct buffer_ **self, unsigned long pos, void *data, unsigned long size)
{
 unsigned long read = (((*self)->size - pos) < (size) ? (*self)->size - pos : size);
 memcpy(data, (*self)->ptr + pos, read);
}

variable_types:
pos
unsigned long

variable_types:
data
void *

variable_types:
size
unsigned long

variable_types:
read
unsigned long

user_defined_types: struct buffer_ { unsigned long pos; unsigned long size; char ptr[]; }


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

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

original_code:
size_t buffer_tell(buffer_t *self)
{
 return (*self)->pos;
}

canonical_original_code:
unsigned long buffer_tell(struct buffer_ **self)
{
 return (*self)->pos;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall buffer_size(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)a1 + 8LL);
}

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

original_code:
size_t buffer_size(buffer_t *self)
{
 return (*self)->size;
}

canonical_original_code:
unsigned long buffer_size(struct buffer_ **self)
{
 return (*self)->size;
}


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

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

original_code:
char *buffer_ptr(buffer_t *self)
{
 return (*self)->ptr;
}

canonical_original_code:
char *buffer_ptr(struct buffer_ **self)
{
 return (*self)->ptr;
}

return_type: char *


decompiled_code:
__int64 __fastcall buffer_at(unsigned __int64 **a1, unsigned __int64 a2)
{
if ( **a1 <= a2 )
_assert_fail("pos < _self->pos", "buffer.c", 0x71u, "buffer_at");
return (__int64)*a1 + a2 + 16;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 **a1, unsigned __int64 a2)
{
if ( **a1 <= a2 )
_assert_fail("pos < _self->pos", "buffer.c", 0x71u, "buffer_at");
return (__int64)*a1 + a2 + 16;
}

original_code:
char *buffer_at(buffer_t *self, size_t pos)
{
 ((void) sizeof ((pos < (*self)->pos) ? 1 : 0), __extension__ ({ if (pos < (*self)->pos) ; else __assert_fail ("pos < _self->pos", "buffer.c", 113, __extension__ __PRETTY_FUNCTION__); }));
 return (*self)->ptr + pos;
}

canonical_original_code:
char *buffer_at(struct buffer_ **self, unsigned long pos)
{
 ((void) sizeof ((pos < (*self)->pos) ? 1 : 0), __extension__ ({ if (pos < (*self)->pos) ; else __assert_fail ("pos < _self->pos", "buffer.c", 113, __extension__ __PRETTY_FUNCTION__); }));
 return (*self)->ptr + pos;
}


setBank

repo: peffis/xmerlin

decompiled_code:
void __fastcall setBank(int a1)
{
currentBank = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
currentBank = a1;
}

original_code:
void
setBank( BANK b )
{
    currentBank = b;
}

canonical_original_code:
void setBank(enum BANK b)
{
    currentBank = b;
}

variable_types: enum BANK { NATURAL=0, NUMERAL=1, EXTENDED=2 }


getBank

decompiled_code:
__int64 getBank()
{
return (unsigned int)currentBank;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)currentBank;
}

original_code:
BANK
getBank()
{
    return currentBank;
}

canonical_original_code:
enum BANK getBank()
{
    return currentBank;
}

return_type: enum BANK { NATURAL=0, NUMERAL=1, EXTENDED=2 }


initModels

decompiled_code:
__int64 initModels()
{
__int64 v0; // rbx
void *v1; // rax

v0 = 0LL;
while ( 1 )
{
v1 = calloc(0x640uLL, 1uLL);
models[v0] = (__int64)v1;
if ( !v1 )
break;
npatterns[v0++] = 0;
if ( v0 == 3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
void *v1; // rax

v0 = 0LL;
while ( 1 )
{
v1 = calloc(0x640uLL, 1uLL);
models[v0] = (__int64)v1;
if ( !v1 )
break;
npatterns[v0++] = 0;
if ( v0 == 3 )
return 0LL;
}
return 1LL;
}

original_code:
int
initModels()
{
    int i, j;
    for ( i = 0; i < 3; i++ )
    {
 models[i] = (Pattern **) malloc( 200 * sizeof(Pattern *));
 if ( models[i] == ((void *)0) )
 {
     for ( j = 0; j < i; j++)
  free( models[i] );
     return 1;
 }
 for ( j = 0; j < 200; j++ )
     models[i][j] = ((void *)0);
 npatterns[i] = 0;
    }
    return 0;
}

canonical_original_code:
int initModels()
{
    int i; int j;
    for ( i = 0; i < 3; i++ )
    {
 models[i] = (struct pattern **) malloc( 200 * sizeof(struct pattern *));
 if ( models[i] == ((void *)0) )
 {
     for ( j = 0; j < i; j++)
  free( models[i] );
     return 1;
 }
 for ( j = 0; j < 200; j++ )
     models[i][j] = ((void *)0);
 npatterns[i] = 0;
    }
    return 0;
}

variable_types: i int

variable_types: j int

return_type: int

user_defined_types: struct pattern { struct point *pv; int *s; int nPoints; unsigned char ascii; int size; }

user_defined_types: struct point { int x; int y; char isLast; }


freeModels

decompiled_code:
void freeModels()
{
__int64 *v0; // rbp
char *v1; // r8
__int64 i; // rbx

v0 = models;
do
{
v1 = (char *)*v0;
for ( i = 0LL; i != 1600; i += 8LL )
{
if ( *(_QWORD *)&v1[i] )
{
deletePattern();
v1 = (char *)*v0;
}
}
if ( v1 )
free(v1);
*v0++ = 0LL;
}
while ( v0 != &preprocessor );
}

canonical_decompiled_code:
void func3()
{
__int64 *v0; // rbp
char *v1; // r8
__int64 i; // rbx

v0 = models;
do
{
v1 = (char *)*v0;
for ( i = 0LL; i != 1600; i += 8LL )
{
if ( *(_QWORD *)&v1[i] )
{
deletePattern();
v1 = (char *)*v0;
}
}
if ( v1 )
free(v1);
*v0++ = 0LL;
}
while ( v0 != &preprocessor );
}

original_code:
void
freeModels()
{
    int i, j;
    for ( i = 0; i < 3; i++ )
    {
 for ( j = 0; j < 200; j++ )
     if ( models[i][j] != ((void *)0) )
  deletePattern( models[i][j] );
 if ( models[i] != ((void *)0) )
     free( models[i] );
 models[i] = ((void *)0);
    }
}

canonical_original_code:
void freeModels()
{
    int i; int j;
    for ( i = 0; i < 3; i++ )
    {
 for ( j = 0; j < 200; j++ )
     if ( models[i][j] != ((void *)0) )
  deletePattern( models[i][j] );
 if ( models[i] != ((void *)0) )
     free( models[i] );
 models[i] = ((void *)0);
    }
}


maxWidth

original_code:
int
maxWidth( Pattern *p )
{
    int minx, maxx, miny, maxy, i;
    Point p1 = p->pv[0];
    minx = maxx = p1.x;
    miny = maxy = p1.y;
    for ( i = 1; i < p->nPoints; i++ )
    {
 Point p2 = p->pv[i];
 if (p2.x > maxx)
     maxx = p2.x;
 if (p2.y > maxy)
     maxy = p2.y;
 if (p2.x < minx)
     minx = p2.x;
 if (p2.y < miny)
     miny = p2.y;
    }
    return ((maxx - minx) > (maxy - miny) ? (maxx - minx) : (maxy - miny));
}

canonical_original_code:
int maxWidth(struct pattern *p)
{
    int minx; int maxx; int miny; int maxy; int i;
    struct point p1 = p->pv[0];
    minx = maxx = p1.x;
    miny = maxy = p1.y;
    for ( i = 1; i < p->nPoints; i++ )
    {
 struct point p2 = p->pv[i];
 if (p2.x > maxx)
     maxx = p2.x;
 if (p2.y > maxy)
     maxy = p2.y;
 if (p2.x < minx)
     minx = p2.x;
 if (p2.y < miny)
     miny = p2.y;
    }
    return ((maxx - minx) > (maxy - miny) ? (maxx - minx) : (maxy - miny));
}

variable_types: struct pattern { struct point { int x; int y; char isLast; } *pv; int *s; int nPoints; unsigned char ascii; int size; } *

variable_types: minx int

variable_types: maxx int

variable_types: miny int

variable_types: maxy int


min

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
int
min( int x, int y )
{
    if ( x <= y )
 return x;
    return y;
}

canonical_original_code:
int min(int x, int y)
{
    if ( x <= y )
 return x;
    return y;
}

variable_types: x int

variable_types: y int


slopeDistance

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

v2 = abs32(a1 - a2);
result = (unsigned int)(6283 - v2);
if ( (int)result > v2 )
result = (unsigned int)v2;
return result;
}

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

v2 = abs32(a1 - a2);
result = (unsigned int)(6283 - v2);
if ( (int)result > v2 )
result = (unsigned int)v2;
return result;
}

variable_types: delta int


pointDistance

decompiled_code:
__int64 __fastcall pointDistance(int a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = slopeDistance(
*(_DWORD *)(*(_QWORD *)(unknown + 8) + 4LL * a1),
*(_DWORD *)(*(_QWORD *)(currentModel + 8) + 4LL * a2));
return (unsigned int)(v3 + v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = func6(
*(_DWORD *)(*(_QWORD *)(unknown + 8) + 4LL * a1),
*(_DWORD *)(*(_QWORD *)(currentModel + 8) + 4LL * a2));
return (unsigned int)(v3 + v2);
}

original_code:
int
pointDistance( int i, int j )
{
    Point p1 = unknown->pv[i];
    Point p2 = currentModel->pv[j];
    return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)
 + slopeDistance( unknown->s[i], currentModel->s[j] );
}

canonical_original_code:
int pointDistance(int i, int j)
{
    struct point p1 = unknown->pv[i];
    struct point p2 = currentModel->pv[j];
    return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)
 + slopeDistance( unknown->s[i], currentModel->s[j] );
}

variable_types: struct point { int x; int y; char isLast; }


freeLookup

decompiled_code:
void freeLookup()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi

v0 = lookup;
if ( lookup_n > 0 )
{
v1 = (void **)lookup;
v2 = (void **)((char *)lookup + 8 * (unsigned int)(lookup_n - 1) + 8);
do
{
v3 = *v1++;
free(v3);
}
while ( v1 != v2 );
}
free(v0);
}

canonical_decompiled_code:
void func8()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi

v0 = lookup;
if ( lookup_n > 0 )
{
v1 = (void **)lookup;
v2 = (void **)((char *)lookup + 8 * (unsigned int)(lookup_n - 1) + 8);
do
{
v3 = *v1++;
free(v3);
}
while ( v1 != v2 );
}
free(v0);
}

original_code:
void
freeLookup()
{
    int i;
    for ( i = 0; i < lookup_n; i++ )
 free( lookup[i] );
    free( lookup );
}


newLookup

decompiled_code:
__int64 __fastcall newLookup(int a1, int a2)
{
void *v2; // rax
_QWORD *v3; // rbx
_QWORD *v4; // r15
_DWORD *v5; // rax
_DWORD *v6; // rdx
int v7; // eax
int *v8; // r11
int v9; // er12
int i; // er10
__int64 v11; // r10
__int64 result; // rax
int j; // er10
int v14; // ebp
__int64 v15; // r10

if ( lookup )
freeLookup();
lookup_n = a1;
v2 = malloc(8LL * a1);
lookup = v2;
v3 = v2;
if ( a1 > 0 )
{
v4 = v2;
do
{
v5 = malloc(4LL * a2);
*v4 = v5;
v6 = &v5[a2 - 1 + 1];
if ( a2 > 0 )
{
do
*v5++ = -1;
while ( v6 != v5 );
}
++v4;
}
while ( v4 != &v3[a1] );
}
v7 = pointDistance(0, 0);
*v8 = v7;
v9 = v7;
if ( a2 > 1 )
{
for ( i = 1; ; i = v11 + 1 )
{
v9 += pointDistance(0, i);
v8[v11] = v9;
if ( a2 - 1 == v11 )
break;
}
}
result = (unsigned int)a1;
if ( a1 > 1 )
{
for ( j = 1; ; j = v15 + 1 )
{
v14 = *v8;
result = pointDistance(j, 0);
v8 = (int *)v3[v15];
*v8 = result + v14;
if ( v15 == a1 - 1 )
break;
}
}
return result;
}

original_code:
void
newLookup( int n, int m )
{
    int i, j;
    if ( lookup != ((void *)0) )
     freeLookup();
    lookup = (int **) malloc( (lookup_n = n) * sizeof(int *));
    for ( i = 0; i < lookup_n; i++ )
    {
 lookup[i] = (int *) malloc( m * sizeof(int) );
 for ( j = 0; j < m; j++ )
     lookup[i][j] = -1;
    }
    lookup[0][0] = pointDistance(0, 0);
    for ( j = 1; j < m; j++ )
 lookup[0][j] = lookup[0][j-1] + pointDistance(0, j);
    for ( i = 1; i < n; i++ )
 lookup[i][0] = lookup[i-1][0] + pointDistance(i, 0);
}

canonical_original_code:
void newLookup(int n, int m)
{
    int i; int j;
    if ( lookup != ((void *)0) )
     freeLookup();
    lookup = (int **) malloc( (lookup_n = n) * sizeof(int *));
    for ( i = 0; i < lookup_n; i++ )
    {
 lookup[i] = (int *) malloc( m * sizeof(int) );
 for ( j = 0; j < m; j++ )
     lookup[i][j] = -1;
    }
    lookup[0][0] = pointDistance(0, 0);
    for ( j = 1; j < m; j++ )
 lookup[0][j] = lookup[0][j-1] + pointDistance(0, j);
    for ( i = 1; i < n; i++ )
 lookup[i][0] = lookup[i-1][0] + pointDistance(i, 0);
}

variable_types: n int

variable_types: m int


D

decompiled_code:
__int64 __fastcall D(int a1, int a2)
{
_QWORD *v2; // r13
__int64 result; // rax
unsigned int v4; // er14
int v5; // ebx
unsigned int v6; // er15
unsigned int v7; // eax
unsigned int v8; // er15
unsigned int v9; // eax
int v10; // ebx
unsigned int v11; // ebp
unsigned int v12; // eax

v2 = (char *)lookup + 8 * a1;
result = *(unsigned int *)(*v2 + 4LL * a2);
if ( (_DWORD)result == -1 )
{
v4 = a1 - 1;
if ( a2 == 1 )
{
v10 = pointDistance(a1, 1);
v11 = D(v4, 0LL);
v12 = D(v4, 1LL);
result = v10 + (unsigned int)min(v12, v11);
*(_DWORD *)(*v2 + 4LL * a2) = result;
}
else
{
v5 = pointDistance(a1, a2);
v6 = D(v4, (unsigned int)(a2 - 2));
v7 = D(v4, (unsigned int)(a2 - 1));
v8 = min(v7, v6);
v9 = D(v4, (unsigned int)a2);
result = v5 + (unsigned int)min(v9, v8);
*(_DWORD *)(*v2 + 4LL * a2) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
_QWORD *v2; // r13
__int64 result; // rax
unsigned int v4; // er14
int v5; // ebx
unsigned int v6; // er15
unsigned int v7; // eax
unsigned int v8; // er15
unsigned int v9; // eax
int v10; // ebx
unsigned int v11; // ebp
unsigned int v12; // eax

v2 = (char *)lookup + 8 * a1;
result = *(unsigned int *)(*v2 + 4LL * a2);
if ( (_DWORD)result == -1 )
{
v4 = a1 - 1;
if ( a2 == 1 )
{
v10 = func7(a1, 1);
v11 = func10(v4, 0LL);
v12 = func10(v4, 1LL);
result = v10 + (unsigned int)func5(v12, v11);
*(_DWORD *)(*v2 + 4LL * a2) = result;
}
else
{
v5 = func7(a1, a2);
v6 = func10(v4, (unsigned int)(a2 - 2));
v7 = func10(v4, (unsigned int)(a2 - 1));
v8 = func5(v7, v6);
v9 = func10(v4, (unsigned int)a2);
result = v5 + (unsigned int)func5(v9, v8);
*(_DWORD *)(*v2 + 4LL * a2) = result;
}
}
return result;
}

original_code:
int
D( int i, int j )
{
    if ( lookup[i][j] != -1 )
 return lookup[i][j];
    if ( j == 1 )
 return lookup[i][j] = pointDistance(i, 1)
     + min(D(i-1, 1), D(i-1, 0));
    else
 return lookup[i][j] = pointDistance(i,j)
     + min(D(i-1, j), min(D(i-1, j-1), D(i-1, j-2)));
}

canonical_original_code:
int D(int i, int j)
{
    if ( lookup[i][j] != -1 )
 return lookup[i][j];
    if ( j == 1 )
 return lookup[i][j] = pointDistance(i, 1)
     + min(D(i-1, 1), D(i-1, 0));
    else
 return lookup[i][j] = pointDistance(i,j)
     + min(D(i-1, j), min(D(i-1, j-1), D(i-1, j-2)));
}


distance

decompiled_code:
__int64 __fastcall distance(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int v3; // edi
int v4; // esi

v1 = unknown;
v2 = *(_QWORD *)(samples + 8LL * a1);
v3 = *(_DWORD *)(unknown + 16);
v4 = *(_DWORD *)(v2 + 16);
currentModel = v2;
newLookup(v3, v4);
return (unsigned int)((int)D(*(_DWORD *)(v1 + 16) - 1, *(_DWORD *)(v2 + 16) - 1) / *(_DWORD *)(v2 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int v3; // edi
int v4; // esi

v1 = unknown;
v2 = *(_QWORD *)(samples + 8LL * a1);
v3 = *(_DWORD *)(unknown + 16);
v4 = *(_DWORD *)(v2 + 16);
currentModel = v2;
func9(v3, v4);
return (unsigned int)((int)func10(*(_DWORD *)(v1 + 16) - 1, *(_DWORD *)(v2 + 16) - 1) / *(_DWORD *)(v2 + 16));
}

original_code:
int
distance( int sampleIndex )
{
    currentModel = samples[ sampleIndex ];
    newLookup( unknown->nPoints, currentModel->nPoints );
    return D( unknown->nPoints - 1, currentModel->nPoints - 1 )
 / currentModel->nPoints;
}

canonical_original_code:
int distance(int sampleIndex)
{
    currentModel = samples[ sampleIndex ];
    newLookup( unknown->nPoints, currentModel->nPoints );
    return D( unknown->nPoints - 1, currentModel->nPoints - 1 )
 / currentModel->nPoints;
}

variable_types: sampleIndex int


recognize

decompiled_code:
__int64 __fastcall recognize(int **a1)
{
unsigned int v1; // er13
__int64 v2; // r11
__int64 v3; // r15
__int64 v4; // r14
int v5; // eax
__int64 v6; // r12
int v7; // ebp
__int64 i; // rbx
int v9; // eax

v1 = 46;
if ( (int)maxWidth(a1) > 5 )
{
v3 = apply(preprocessor, v2);
calcSlopes(v3);
v4 = models[(unsigned int)getBank(0LL)];
samples = v4;
v5 = getBank(0LL);
unknown = v3;
v6 = npatterns[v5];
v1 = *(unsigned __int8 *)(*(_QWORD *)v4 + 20LL);
v7 = distance(0);
if ( (int)v6 > 1 )
{
for ( i = 1LL; i != v6; ++i )
{
v9 = distance(i);
if ( v7 > v9 )
{
v7 = v9;
v1 = *(unsigned __int8 *)(*(_QWORD *)(v4 + 8 * i) + 20LL);
}
}
}
deletePattern(v3);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(int **a1)
{
unsigned int v1; // er13
__int64 v2; // r11
__int64 v3; // r15
__int64 v4; // r14
int v5; // eax
__int64 v6; // r12
int v7; // ebp
__int64 i; // rbx
int v9; // eax

v1 = 46;
if ( (int)func4(a1) > 5 )
{
v3 = apply(preprocessor, v2);
calcSlopes(v3);
v4 = models[(unsigned int)func1(0LL)];
samples = v4;
v5 = func1(0LL);
unknown = v3;
v6 = npatterns[v5];
v1 = *(unsigned __int8 *)(*(_QWORD *)v4 + 20LL);
v7 = func11(0);
if ( (int)v6 > 1 )
{
for ( i = 1LL; i != v6; ++i )
{
v9 = func11(i);
if ( v7 > v9 )
{
v7 = v9;
v1 = *(unsigned __int8 *)(*(_QWORD *)(v4 + 8 * i) + 20LL);
}
}
}
deletePattern(v3);
}
return v1;
}

original_code:
unsigned char
recognize( Pattern *p )
{
    unsigned char ascii;
    int mind, tmpd, i, nsamples;
    Pattern *np;
    if ( maxWidth( p ) < 6 )
 return '.';
    np = apply( preprocessor, p );
    calcSlopes( np );
    samples = models[ getBank() ];
    nsamples = npatterns[ getBank() ];
    unknown = np;
    ascii = samples[0]->ascii;
    mind = distance( 0 );
    for ( i = 1; i < nsamples; i++ )
    {
 tmpd = distance( i );
 if ( tmpd < mind )
 {
     mind = tmpd;
     ascii = samples[i]->ascii;
 }
    }
    deletePattern( np );
    return ascii;
}

canonical_original_code:
unsigned char recognize(struct pattern *p)
{
    unsigned char ascii;
    int mind; int tmpd; int i; int nsamples;
    struct pattern *np;
    if ( maxWidth( p ) < 6 )
 return '.';
    np = apply( preprocessor, p );
    calcSlopes( np );
    samples = models[ getBank() ];
    nsamples = npatterns[ getBank() ];
    unknown = np;
    ascii = samples[0]->ascii;
    mind = distance( 0 );
    for ( i = 1; i < nsamples; i++ )
    {
 tmpd = distance( i );
 if ( tmpd < mind )
 {
     mind = tmpd;
     ascii = samples[i]->ascii;
 }
    }
    deletePattern( np );
    return ascii;
}

variable_types:
ascii
unsigned char

variable_types: mind int

variable_types: tmpd int

variable_types: nsamples int

return_type: unsigned char


initWizard

decompiled_code:
void initWizard()
{
preprocessor = newPreprocessor(&off_A20, 3LL);
loadPatterns();
printf("Found %d patterns in %s bank\n", (unsigned int)npatterns[0], "NATURAL");
printf("Found %d patterns in %s bank\n", (unsigned int)dword_A74, "NUMERAL");
printf("Found %d patterns in %s bank\n", (unsigned int)dword_A78, "EXTENDED");
setBank(0);
}

canonical_decompiled_code:
void func15()
{
preprocessor = newPreprocessor(&off_A20, 3LL);
func14();
printf("Found %d patterns in %s bank\n", (unsigned int)npatterns[0], "NATURAL");
printf("Found %d patterns in %s bank\n", (unsigned int)dword_A74, "NUMERAL");
printf("Found %d patterns in %s bank\n", (unsigned int)dword_A78, "EXTENDED");
func0(0);
}

original_code:
void
initWizard()
{
    int i;
    preprocessor = newPreprocessor( fs, 3 );
    loadPatterns();
    for ( i = 0; i < 3; i++ )
 printf("Found %d patterns in %s bank\n",
        npatterns[i],
        (i == 0 ? "NATURAL" : (i == 1 ? "NUMERAL" : "EXTENDED")));
    setBank( NATURAL );
}

variable_types: i int


sizeNormFilter

original_code:
Pattern *
sizeNormFilter( Pattern *p )
{
    int i, xmin, xmax, ymin, ymax;
    float xm, ym, dx, dy, delta, centerx, centery;
    Point tmp, po;
    Pattern *np;
    if ( p == ((void *)0) )
 return ((void *)0);
    np = newPattern( p->size, p->ascii );
    if ( np == ((void *)0) )
 return ((void *)0);
    tmp = p->pv[ 0 ];
    xmin = xmax = tmp.x;
    ymin = ymax = tmp.y;
    for ( i = 1; i < p->nPoints; i++ )
    {
 tmp = p->pv[ i ];
 if ( tmp.x < xmin )
     xmin = tmp.x;
 if ( tmp.y < ymin )
     ymin = tmp.y;
 if ( tmp.x > xmax )
     xmax = tmp.x;
 if ( tmp.y > ymax )
     ymax = tmp.y;
    }
    xm = ( xmax + xmin ) / 2.0;
    ym = ( ymax + ymin ) / 2.0;
    dx = ( xmax - xmin ) / 2.0;
    dy = ( ymax - ymin ) / 2.0;
    delta = ( (dx) > (dy) ? (dx) : (dy));
    centerx = (100 - 1) / 2.0;
    centery = (100 - 1) / 2.0;
    for ( i = 0; i < p->nPoints; i++ )
    {
 tmp = p->pv[ i ];
 po.x = (int) ( centerx + centerx * (( tmp.x - xm ) / delta ));
 po.y = (int) ( centery + centery * (( tmp.y - ym ) / delta ));
 addPoint( np, po );
    }
    return np;
}

canonical_original_code:
struct pattern *sizeNormFilter(struct pattern *p)
{
    int i; int xmin; int xmax; int ymin; int ymax;
    float xm; float ym; float dx; float dy; float delta; float centerx; float centery;
    struct point tmp; struct point po;
    struct pattern *np;
    if ( p == ((void *)0) )
 return ((void *)0);
    np = newPattern( p->size, p->ascii );
    if ( np == ((void *)0) )
 return ((void *)0);
    tmp = p->pv[ 0 ];
    xmin = xmax = tmp.x;
    ymin = ymax = tmp.y;
    for ( i = 1; i < p->nPoints; i++ )
    {
 tmp = p->pv[ i ];
 if ( tmp.x < xmin )
     xmin = tmp.x;
 if ( tmp.y < ymin )
     ymin = tmp.y;
 if ( tmp.x > xmax )
     xmax = tmp.x;
 if ( tmp.y > ymax )
     ymax = tmp.y;
    }
    xm = ( xmax + xmin ) / 2.0;
    ym = ( ymax + ymin ) / 2.0;
    dx = ( xmax - xmin ) / 2.0;
    dy = ( ymax - ymin ) / 2.0;
    delta = ( (dx) > (dy) ? (dx) : (dy));
    centerx = (100 - 1) / 2.0;
    centery = (100 - 1) / 2.0;
    for ( i = 0; i < p->nPoints; i++ )
    {
 tmp = p->pv[ i ];
 po.x = (int) ( centerx + centerx * (( tmp.x - xm ) / delta ));
 po.y = (int) ( centery + centery * (( tmp.y - ym ) / delta ));
 addPoint( np, po );
    }
    return np;
}

variable_types:
p
struct pattern *

variable_types: xmin int

variable_types: xmax int

variable_types: ymin int

variable_types: ymax int

variable_types: xm float

variable_types: ym float

variable_types: dx float

variable_types: dy float

variable_types: delta float

variable_types: centerx float

variable_types: centery float

variable_types: struct pattern { struct point { int x; int y; char isLast; } *pv; int *s; int nPoints; unsigned char ascii; int size; } *


distanceSq

decompiled_code:
__int64 __fastcall distanceSq(__int64 a1, __int64 a2, __int64 a3)
{
return (unsigned int)((a1 - a3) * (a1 - a3) + (HIDWORD(a1) - HIDWORD(a3)) * (HIDWORD(a1) - HIDWORD(a3)));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return (unsigned int)((a1 - a3) * (a1 - a3) + (HIDWORD(a1) - HIDWORD(a3)) * (HIDWORD(a1) - HIDWORD(a3)));
}

original_code:
int
distanceSq( Point p0, Point p1 )
{
    return (( p0.x - p1.x ) * ( p0.x - p1.x ))
 + (( p0.y - p1.y ) * ( p0.y - p1.y ));
}

canonical_original_code:
int distanceSq(struct point p0, struct point p1)
{
    return (( p0.x - p1.x ) * ( p0.x - p1.x ))
 + (( p0.y - p1.y ) * ( p0.y - p1.y ));
}

variable_types: struct point { int x; int y; char isLast; }


pointDistanceNormFilter

decompiled_code:
__int64 __fastcall pointDistanceNormFilter(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // rbx
int v3; // er12
unsigned int v4; // er8
__int64 v5; // r9
__int64 v7; // [rsp+8h] [rbp-40h]

if ( !a1 )
return 0LL;
v1 = newPattern(*(unsigned int *)(a1 + 24), *(unsigned __int8 *)(a1 + 20));
if ( !v1 )
return 0LL;
v7 = **(_QWORD **)a1;
addPoint(v1, v7, *(unsigned int *)(*(_QWORD *)a1 + 8LL));
if ( *(int *)(a1 + 16) > 1 )
{
v2 = 12LL;
v3 = 1;
do
{
while ( (int)distanceSq(*(_QWORD *)(*(_QWORD *)a1 + v2), *(unsigned int *)(*(_QWORD *)a1 + v2 + 8), v7) <= 35 )
{
++v3;
v2 += 12LL;
if ( *(_DWORD *)(a1 + 16) <= v3 )
return v1;
}
v7 = v5;
++v3;
v2 += 12LL;
addPoint(v1, v5, v4);
}
while ( *(_DWORD *)(a1 + 16) > v3 );
}
return v1;
}

original_code:
Pattern *
pointDistanceNormFilter( Pattern *p )
{
    Pattern *np;
    Point last, tmp;
    int i;
    if ( p == ((void *)0) )
 return ((void *)0);
    np = newPattern( p->size, p->ascii );
    if ( np == ((void *)0) )
 return ((void *)0);
    last = p->pv[ 0 ];
    addPoint( np, last );
    for ( i = 1; i < p->nPoints; i++ )
    {
 tmp = p->pv[ i ];
 if ( distanceSq( tmp, last ) >= 36 )
 {
     last = tmp;
     addPoint( np, last );
 }
    }
    return np;
}

canonical_original_code:
struct pattern *pointDistanceNormFilter(struct pattern *p)
{
    struct pattern *np;
    struct point last; struct point tmp;
    int i;
    if ( p == ((void *)0) )
 return ((void *)0);
    np = newPattern( p->size, p->ascii );
    if ( np == ((void *)0) )
 return ((void *)0);
    last = p->pv[ 0 ];
    addPoint( np, last );
    for ( i = 1; i < p->nPoints; i++ )
    {
 tmp = p->pv[ i ];
 if ( distanceSq( tmp, last ) >= 36 )
 {
     last = tmp;
     addPoint( np, last );
 }
    }
    return np;
}

return_type: struct pattern { struct point { int x; int y; char isLast; } *pv; int *s; int nPoints; unsigned char ascii; int size; } *


smoothFilter

original_code:
Pattern *
smoothFilter( Pattern *p )
{
    Pattern *np;
    Point p1, p2, p3, tmp;
    int i;
    if ( p == ((void *)0) )
 return ((void *)0);
    np = newPattern( p->size, p->ascii );
    if ( np == ((void *)0) )
 return ((void *)0);
    addPoint( np, p->pv[ 0 ] );
    for ( i = 1; i < p->nPoints - 1; i++ )
    {
 p1 = p->pv[ i - 1 ];
 p2 = p->pv[ i ];
 p3 = p->pv[ i + 1 ];
 tmp.x = ( p1.x + p2.x + p3.x ) / 3;
 tmp.y = ( p1.y + p2.y + p3.y ) / 3;
 addPoint( np, tmp );
    }
    addPoint( np, p->pv[ p->nPoints - 1 ] );
    return np;
}

canonical_original_code:
struct pattern *smoothFilter(struct pattern *p)
{
    struct pattern *np;
    struct point p1; struct point p2; struct point p3; struct point tmp;
    int i;
    if ( p == ((void *)0) )
 return ((void *)0);
    np = newPattern( p->size, p->ascii );
    if ( np == ((void *)0) )
 return ((void *)0);
    addPoint( np, p->pv[ 0 ] );
    for ( i = 1; i < p->nPoints - 1; i++ )
    {
 p1 = p->pv[ i - 1 ];
 p2 = p->pv[ i ];
 p3 = p->pv[ i + 1 ];
 tmp.x = ( p1.x + p2.x + p3.x ) / 3;
 tmp.y = ( p1.y + p2.y + p3.y ) / 3;
 addPoint( np, tmp );
    }
    addPoint( np, p->pv[ p->nPoints - 1 ] );
    return np;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
initGraphics(argc, argv, envp);
initWizard();
current = newPattern(100LL, 97LL);
setBank(0LL);
setMode(0LL);
eventLoop();
return 0;
}

original_code:
int
main(int argc, char **argv)
{
    initGraphics( argc, argv );
    initWizard();
    current = newPattern( 100, 'a' );
    setBank( NATURAL );
    setMode( SINGLE_STROKE );
    eventLoop();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


assignDefault

decompiled_code:
void assignDefault()
{
window_y = 0;
window_x = 0;
window_width = 200;
window_height = 100;
}

canonical_decompiled_code:
void func0()
{
window_y = 0;
window_x = 0;
window_width = 200;
window_height = 100;
}

original_code:
void
assignDefault()
{
    window_x = window_y = 0;
    window_width = 200;
    window_height = 100;
}


parseArgs

decompiled_code:
_BOOL8 __fastcall parseArgs(int a1, __int64 a2)
{
bool v2; // zf
_BOOL4 v3; // er12
char v5; // [rsp+Eh] [rbp-Ah] BYREF
char v6; // [rsp+Fh] [rbp-9h] BYREF

if ( a1 != 3 )
return 1;
v2 = strcmp("-geometry", *(const char **)(a2 + 8)) == 0;
v3 = !v2;
if ( !v2
|| (unsigned int)_isoc99_sscanf(
*(_QWORD *)(a2 + 16),
"%dx%d%c%d%c%d\n",
&window_width,
&window_height,
&v5,
&window_x,
&v6,
&window_y) != 6 )
{
return 1;
}
if ( v5 == 45 )
window_x = myDisplay->screens[(__int64)myScreen].width - window_width - window_x;
if ( v6 == 45 )
window_y = myDisplay->screens[(__int64)myScreen].height - window_height - window_y;
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1, __int64 a2)
{
bool v2; // zf
_BOOL4 v3; // er12
char v5; // [rsp+Eh] [rbp-Ah] BYREF
char v6; // [rsp+Fh] [rbp-9h] BYREF

if ( a1 != 3 )
return 1;
v2 = strcmp("-geometry", *(const char **)(a2 + 8)) == 0;
v3 = !v2;
if ( !v2
|| (unsigned int)_isoc99_sscanf(
*(_QWORD *)(a2 + 16),
"%dx%d%c%d%c%d\n",
&window_width,
&window_height,
&v5,
&window_x,
&v6,
&window_y) != 6 )
{
return 1;
}
if ( v5 == 45 )
window_x = myDisplay->screens[(__int64)myScreen].width - window_width - window_x;
if ( v6 == 45 )
window_y = myDisplay->screens[(__int64)myScreen].height - window_height - window_y;
return v3;
}

original_code:
int
parseArgs( int argc, char *argv[])
{
    char xsign, ysign;
    if ( argc != 3 || strcmp( "-geometry", argv[1] ) )
 return 1;
    if ( sscanf( argv[2], "%dx%d%c%d%c%d\n", &window_width,
   &window_height,
   &xsign, &window_x, &ysign, &window_y ) != 6 )
     return 1;
    if ( xsign == '-' )
    {
 int screen_width = (((&((_XPrivDisplay)(myDisplay))->screens[myScreen]))->width);
 window_x = screen_width - window_width - window_x;
    }
    if ( ysign == '-' )
    {
 int screen_height = (((&((_XPrivDisplay)(myDisplay))->screens[myScreen]))->height);
 window_y = screen_height - window_height - window_y;
    }
    return 0;
}

canonical_original_code:
int parseArgs(int argc, char *argv[])
{
    char xsign; char ysign;
    if ( argc != 3 || strcmp( "-geometry", argv[1] ) )
 return 1;
    if ( sscanf( argv[2], "%dx%d%c%d%c%d\n", &window_width,
   &window_height,
   &xsign, &window_x, &ysign, &window_y ) != 6 )
     return 1;
    if ( xsign == '-' )
    {
 int screen_width = (((&((_XPrivDisplay)(myDisplay))->screens[myScreen]))->width);
 window_x = screen_width - window_width - window_x;
    }
    if ( ysign == '-' )
    {
 int screen_height = (((&((_XPrivDisplay)(myDisplay))->screens[myScreen]))->height);
 window_y = screen_height - window_height - window_y;
    }
    return 0;
}

variable_types:
argv
char *[]

variable_types: xsign char

variable_types: ysign char


drawText

decompiled_code:
int drawText()
{
unsigned __int64 v0; // rax

XDrawString(myDisplay, myWindow, myGC, 3, 16, "abc", 3);
XDrawString(myDisplay, myWindow, myGC, (int)window_width / 2 - 12, 16, "ABC", 3);
XDrawString(myDisplay, myWindow, myGC, window_width - 28, 16, "123", 3);
v0 = getColor(myDisplay, 60, 120, 200);
XSetForeground(myDisplay, myGC, v0);
XDrawString(myDisplay, myWindow, myGC, 2, 15, "abc", 3);
XDrawString(myDisplay, myWindow, myGC, (int)window_width / 2 - 13, 15, "ABC", 3);
XDrawString(myDisplay, myWindow, myGC, window_width - 29, 15, "123", 3);
return XSetForeground(myDisplay, myGC, myDisplay->screens[(__int64)myScreen].black_pixel);
}

canonical_decompiled_code:
int func3()
{
unsigned __int64 v0; // rax

XDrawString(myDisplay, myWindow, myGC, 3, 16, "abc", 3);
XDrawString(myDisplay, myWindow, myGC, (int)window_width / 2 - 12, 16, "ABC", 3);
XDrawString(myDisplay, myWindow, myGC, window_width - 28, 16, "123", 3);
v0 = func2(myDisplay, 60, 120, 200);
XSetForeground(myDisplay, myGC, v0);
XDrawString(myDisplay, myWindow, myGC, 2, 15, "abc", 3);
XDrawString(myDisplay, myWindow, myGC, (int)window_width / 2 - 13, 15, "ABC", 3);
XDrawString(myDisplay, myWindow, myGC, window_width - 29, 15, "123", 3);
return XSetForeground(myDisplay, myGC, myDisplay->screens[(__int64)myScreen].black_pixel);
}

original_code:
void
drawText()
{
    XDrawString( myDisplay, myWindow, myGC, 2+1, 15+1,
   "abc", strlen("abc"));
    XDrawString( myDisplay, myWindow, myGC, window_width/2 - 13 + 1, 15 + 1,
   "ABC", strlen("ABC"));
    XDrawString( myDisplay, myWindow, myGC, window_width - 3*9 - 2 + 1, 15 + 1,
   "123", strlen("123"));
    XSetForeground (myDisplay, myGC, getColor( myDisplay, 60, 120, 200 ) );
    XDrawString( myDisplay, myWindow, myGC, 2, 15,
   "abc", strlen("abc"));
    XDrawString( myDisplay, myWindow, myGC, window_width/2 - 13, 15,
   "ABC", strlen("ABC"));
    XDrawString( myDisplay, myWindow, myGC, window_width - 3*9 - 2, 15,
   "123", strlen("123"));
    XSetForeground (myDisplay, myGC, ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->black_pixel) );
}


paintPattern

decompiled_code:
void paintPattern()
{
__int64 v0; // rcx
__int64 v1; // rax
int v2; // ebp
__int64 v3; // rbx
__int64 v4; // rsi

v0 = current;
if ( current && *(int *)(current + 16LL) > 1 )
{
v1 = 0LL;
v2 = 0;
do
{
while ( 1 )
{
++v2;
v3 = v1 + 12;
v4 = *(_QWORD *)v0 + v1;
if ( !*(_BYTE *)(v4 + 8) )
break;
v1 += 12LL;
if ( *(_DWORD *)(v0 + 16) - 1 <= v2 )
return;
}
XDrawLine(
myDisplay,
myWindow,
myGC,
*(_DWORD *)v4,
*(_DWORD *)(v4 + 4),
*(_DWORD *)(v3 + *(_QWORD *)v0),
*(_DWORD *)(v3 + *(_QWORD *)v0 + 4));
v0 = current;
v1 = v3;
}
while ( *(_DWORD *)(current + 16LL) - 1 > v2 );
}
}

canonical_decompiled_code:
void func4()
{
__int64 v0; // rcx
__int64 v1; // rax
int v2; // ebp
__int64 v3; // rbx
__int64 v4; // rsi

v0 = current;
if ( current && *(int *)(current + 16LL) > 1 )
{
v1 = 0LL;
v2 = 0;
do
{
while ( 1 )
{
++v2;
v3 = v1 + 12;
v4 = *(_QWORD *)v0 + v1;
if ( !*(_BYTE *)(v4 + 8) )
break;
v1 += 12LL;
if ( *(_DWORD *)(v0 + 16) - 1 <= v2 )
return;
}
XDrawLine(
myDisplay,
myWindow,
myGC,
*(_DWORD *)v4,
*(_DWORD *)(v4 + 4),
*(_DWORD *)(v3 + *(_QWORD *)v0),
*(_DWORD *)(v3 + *(_QWORD *)v0 + 4));
v0 = current;
v1 = v3;
}
while ( *(_DWORD *)(current + 16LL) - 1 > v2 );
}
}

original_code:
void
paintPattern()
{
    int i;
    if ( current != ((void *)0) && current->nPoints > 1 )
    {
 for ( i = 0; i < current->nPoints - 1; i++ )
     if ( !current->pv[i].isLast )
  XDrawLine( myDisplay, myWindow, myGC,
      current->pv[i].x, current->pv[i].y,
      current->pv[i+1].x, current->pv[i+1].y );
    }
}

variable_types: i int


paint

decompiled_code:
int paint()
{
int result; // eax
int v1; // [rsp-10h] [rbp-18h]

XClearWindow(myDisplay, myWindow);
XSetLineAttributes(myDisplay, myGC, 1u, 1, 0, 0);
XDrawLine(myDisplay, myWindow, myGC, (int)window_width / 2, 20, (int)window_width / 2, window_height);
XSetLineAttributes(myDisplay, myGC, 1u, 0, 0, 0);
paintPattern();
result = v1;
if ( myFont )
result = drawText();
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax
int v1; // [rsp-10h] [rbp-18h]

XClearWindow(myDisplay, myWindow);
XSetLineAttributes(myDisplay, myGC, 1u, 1, 0, 0);
XDrawLine(myDisplay, myWindow, myGC, (int)window_width / 2, 20, (int)window_width / 2, window_height);
XSetLineAttributes(myDisplay, myGC, 1u, 0, 0, 0);
func4();
result = v1;
if ( myFont )
result = func3();
return result;
}

original_code:
void
paint( void )
{
    XClearWindow( myDisplay, myWindow );
    XSetLineAttributes( myDisplay, myGC, 1, 1,
   0, 0 );
    XDrawLine( myDisplay, myWindow, myGC, window_width / 2,
        20, window_width / 2, window_height );
    XSetLineAttributes( myDisplay, myGC, 1, 0,
   0, 0 );
    paintPattern();
    if ( myFont != ((void *)0) )
 drawText();
}

canonical_original_code:
void paint()
{
    XClearWindow( myDisplay, myWindow );
    XSetLineAttributes( myDisplay, myGC, 1, 1,
   0, 0 );
    XDrawLine( myDisplay, myWindow, myGC, window_width / 2,
        20, window_width / 2, window_height );
    XSetLineAttributes( myDisplay, myGC, 1, 0,
   0, 0 );
    paintPattern();
    if ( myFont != ((void *)0) )
 drawText();
}


initGraphics

decompiled_code:
int __fastcall initGraphics(int a1, __int64 a2)
{
Display *v2; // rax
int v3; // ebx
XFontStruct *v4; // rax
XSetWindowAttributes v6; // [rsp+0h] [rbp-108h] BYREF
XGCValues v7; // [rsp+70h] [rbp-98h] BYREF

v2 = XOpenDisplay(&byte_74F);
myDisplay = v2;
if ( !v2 )
LABEL_9:
exit(0);
myScreen = v2->default_screen;
v3 = v2->screens[(__int64)myScreen].root_depth;
if ( parseArgs(a1, a2) )
assignDefault();
v6.border_pixel = myDisplay->screens[(__int64)myScreen].black_pixel;
v6.override_redirect = 0;
v6.background_pixel = getColor(myDisplay, 252, 234, 212);
myWindow = XCreateWindow(
myDisplay,
myDisplay->screens[(__int64)myScreen].root,
window_x,
window_y,
window_width,
window_height,
1u,
v3,
1u,
0LL,
0x20AuLL,
&v6);
myGC = XCreateGC(myDisplay, myWindow, 0LL, &v7);
if ( !myGC )
{
XDestroyWindow(myDisplay, myScreen);
goto LABEL_9;
}
v4 = XLoadQueryFont(myDisplay, "9x15");
myFont = (__int64)v4;
if ( v4 )
{
XSetFont(myDisplay, myGC, v4->fid);
}
else
{
fwrite("Cannot get font:9x15.\n", 1uLL, 0x16uLL, stderr);
myFont = 0LL;
}
XSetForeground(myDisplay, myGC, myDisplay->screens[(__int64)myScreen].black_pixel);
XMapWindow(myDisplay, myWindow);
XLowerWindow(myDisplay, myWindow);
paint();
return XFlush(myDisplay);
}

canonical_decompiled_code:
int __fastcall func6(int a1, __int64 a2)
{
Display *v2; // rax
int v3; // ebx
XFontStruct *v4; // rax
XSetWindowAttributes v6; // [rsp+0h] [rbp-108h] BYREF
XGCValues v7; // [rsp+70h] [rbp-98h] BYREF

v2 = XOpenDisplay(&byte_74F);
myDisplay = v2;
if ( !v2 )
LABEL_9:
exit(0);
myScreen = v2->default_screen;
v3 = v2->screens[(__int64)myScreen].root_depth;
if ( func1(a1, a2) )
func0();
v6.border_pixel = myDisplay->screens[(__int64)myScreen].black_pixel;
v6.override_redirect = 0;
v6.background_pixel = func2(myDisplay, 252, 234, 212);
myWindow = XCreateWindow(
myDisplay,
myDisplay->screens[(__int64)myScreen].root,
window_x,
window_y,
window_width,
window_height,
1u,
v3,
1u,
0LL,
0x20AuLL,
&v6);
myGC = XCreateGC(myDisplay, myWindow, 0LL, &v7);
if ( !myGC )
{
XDestroyWindow(myDisplay, myScreen);
goto LABEL_9;
}
v4 = XLoadQueryFont(myDisplay, "9x15");
myFont = (__int64)v4;
if ( v4 )
{
XSetFont(myDisplay, myGC, v4->fid);
}
else
{
fwrite("Cannot get font:9x15.\n", 1uLL, 0x16uLL, stderr);
myFont = 0LL;
}
XSetForeground(myDisplay, myGC, myDisplay->screens[(__int64)myScreen].black_pixel);
XMapWindow(myDisplay, myWindow);
XLowerWindow(myDisplay, myWindow);
func5();
return XFlush(myDisplay);
}

original_code:
void
initGraphics( int argc, char *argv[] )
{
    XSetWindowAttributes myWindowAttributes;
    int myDepth;
    XGCValues myGCValues;
    unsigned long myWindowMask;
    myDisplay = XOpenDisplay( "" );
    if (myDisplay == ((void *)0))
    {
 exit (0);
    }
    myScreen = (((_XPrivDisplay)(myDisplay))->default_screen);
    myDepth = ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->root_depth);
    if ( parseArgs( argc, argv ) )
 assignDefault();
    myWindowAttributes.border_pixel =
 ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->black_pixel);
    myWindowAttributes.background_pixel =
 getColor( myDisplay, 252, 234, 212 );
    myWindowAttributes.override_redirect = 0;
    myWindowMask = (1L<<1) | (1L<<3) | (1L<<9);
    myWindow = XCreateWindow (myDisplay,
         ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->root),
         window_x,
         window_y,
         window_width, window_height,
         1, myDepth, 1,
         0L, myWindowMask,
         &myWindowAttributes);
    myGC = XCreateGC (myDisplay, myWindow, (unsigned long) 0, &myGCValues);
    if (myGC == 0)
    {
 XDestroyWindow(myDisplay, myScreen);
 exit (0);
    }
    myFont = XLoadQueryFont (myDisplay, "9x15");
    if (myFont == (XFontStruct *)((void *)0))
    {
        fprintf(stderr,"Cannot get font:9x15.\n");
        myFont = ((void *)0);
    }
    else
 XSetFont (myDisplay, myGC, myFont->fid);
    XSetForeground (myDisplay, myGC, ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->black_pixel) );
    XMapWindow (myDisplay, myWindow);
    XLowerWindow( myDisplay, myWindow );
    paint();
    XFlush( myDisplay );
}

canonical_original_code:
void initGraphics(int argc, char *argv[])
{
    struct XSetWindowAttributes myWindowAttributes;
    int myDepth;
    struct XGCValues myGCValues;
    unsigned long myWindowMask;
    myDisplay = XOpenDisplay( "" );
    if (myDisplay == ((void *)0))
    {
 exit (0);
    }
    myScreen = (((_XPrivDisplay)(myDisplay))->default_screen);
    myDepth = ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->root_depth);
    if ( parseArgs( argc, argv ) )
 assignDefault();
    myWindowAttributes.border_pixel =
 ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->black_pixel);
    myWindowAttributes.background_pixel =
 getColor( myDisplay, 252, 234, 212 );
    myWindowAttributes.override_redirect = 0;
    myWindowMask = (1L<<1) | (1L<<3) | (1L<<9);
    myWindow = XCreateWindow (myDisplay,
         ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->root),
         window_x,
         window_y,
         window_width, window_height,
         1, myDepth, 1,
         0L, myWindowMask,
         &myWindowAttributes);
    myGC = XCreateGC (myDisplay, myWindow, (unsigned long) 0, &myGCValues);
    if (myGC == 0)
    {
 XDestroyWindow(myDisplay, myScreen);
 exit (0);
    }
    myFont = XLoadQueryFont (myDisplay, "9x15");
    if (myFont == (struct XFontStruct *)((void *)0))
    {
        fprintf(stderr,"Cannot get font:9x15.\n");
        myFont = ((void *)0);
    }
    else
 XSetFont (myDisplay, myGC, myFont->fid);
    XSetForeground (myDisplay, myGC, ((&((_XPrivDisplay)(myDisplay))->screens[myScreen])->black_pixel) );
    XMapWindow (myDisplay, myWindow);
    XLowerWindow( myDisplay, myWindow );
    paint();
    XFlush( myDisplay );
}

variable_types: struct XSetWindowAttributes { unsigned long background_pixmap; unsigned long background_pixel; unsigned long border_pixmap; unsigned long border_pixel; int bit_gravity; int win_gravity; int backing_store; unsigned long backing_planes; unsigned long backing_pixel; int save_under; long event_mask; long do_not_propagate_mask; int override_redirect; unsigned long colormap; unsigned long cursor; }

variable_types: myDepth int

variable_types: struct XGCValues { int function; unsigned long plane_mask; unsigned long foreground; unsigned long background; int line_width; int line_style; int cap_style; int join_style; int fill_style; int fill_rule; int arc_mode; unsigned long tile; unsigned long stipple; int ts_x_origin; int ts_y_origin; unsigned long font; int subwindow_mode; int graphics_exposures; int clip_x_origin; int clip_y_origin; unsigned long clip_mask; int dash_offset; char dashes; }

variable_types:
myWindowMask
unsigned long

user_defined_types: struct XFontStruct { struct _XExtData *ext_data; unsigned long fid; unsigned int direction; unsigned int min_char_or_byte2; unsigned int max_char_or_byte2; unsigned int min_byte1; unsigned int max_byte1; int all_chars_exist; unsigned int default_char; int n_properties; struct XFontProp *properties; struct XCharStruct min_bounds; struct XCharStruct max_bounds; struct XCharStruct *per_char; int ascent; int descent; }

user_defined_types: struct XCharStruct { short lbearing; short rbearing; short width; short ascent; short descent; unsigned short attributes; }

user_defined_types: struct _XExtData { int number; struct _XExtData *next; int (*free_private)(struct _XExtData *extension); char *private_data; }

user_defined_types: struct XFontProp { unsigned long name; unsigned long card32; }


asciiToKeycode

decompiled_code:
__int64 __fastcall asciiToKeycode(unsigned __int8 a1, _DWORD *a2)
{
*a2 = asciiToKeycode[2 * a1 + 1];
return (unsigned int)asciiToKeycode[2 * a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, _DWORD *a2)
{
*a2 = asciiToKeycode[2 * a1 + 1];
return (unsigned int)asciiToKeycode[2 * a1];
}

original_code:
unsigned int
asciiToKeycode( unsigned char c, unsigned int *state )
{
    *state = _asciiToKeycode[c].state;
    return _asciiToKeycode[c].keycode;
}

canonical_original_code:
unsigned int asciiToKeycode(unsigned char c, unsigned int *state)
{
    *state = _asciiToKeycode[c].state;
    return _asciiToKeycode[c].keycode;
}

variable_types:
c
unsigned char

variable_types:
state
unsigned int *

return_type: unsigned int


deletePattern

decompiled_code:
void __fastcall deletePattern(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(*(void **)ptr);
free(ptr);
}

original_code:
void
deletePattern( Pattern *p )
{
    if ( p->s != ((void *)0))
 free( p->s );
    free( p->pv );
    free( p );
}

canonical_original_code:
void deletePattern(struct pattern *p)
{
    if ( p->s != ((void *)0))
 free( p->s );
    free( p->pv );
    free( p );
}


growVector

decompiled_code:
void *__fastcall growVector(void *src, int a2, int a3)
{
void *v3; // rax
void *v4; // r8

v3 = malloc(12LL * a3);
v4 = v3;
if ( v3 )
v4 = memcpy(v3, src, 12LL * a2);
return v4;
}

canonical_decompiled_code:
void *__fastcall func1(void *src, int a2, int a3)
{
void *v3; // rax
void *v4; // r8

v3 = malloc(12LL * a3);
v4 = v3;
if ( v3 )
v4 = memcpy(v3, src, 12LL * a2);
return v4;
}

original_code:
Point *
growVector( Point *old, int oldSize, int newSize )
{
    Point *np = (Point *) malloc( newSize * sizeof( Point ) );
    if (np == ((void *)0))
 return ((void *)0);
    memcpy( np, old, oldSize * sizeof( Point ) );
    return np;
}

canonical_original_code:
struct point *growVector(struct point *old, int oldSize, int newSize)
{
    struct point *np = (Point *) malloc( newSize * sizeof( Point ) );
    if (np == ((void *)0))
 return ((void *)0);
    memcpy( np, old, oldSize * sizeof( Point ) );
    return np;
}

variable_types:
old
struct point *

variable_types: oldSize int

variable_types: newSize int

variable_types: struct point { int x; int y; char isLast; } *


addPoint

original_code:
void
addPoint( Pattern *p, Point po )
{
    po.isLast = 0;
    p->pv[ p->nPoints++ ] = po;
    if ( p->nPoints == p->size )
    {
 Point *old = p->pv;
 int newSize = p->size * 2;
 p->pv = growVector( p->pv, p->size, newSize );
 if ( p->pv != ((void *)0))
 {
     p->size = newSize;
     free( old );
 }
 else
 {
     p->pv = old;
     p->nPoints--;
 }
    }
}

canonical_original_code:
void addPoint(struct pattern *p, struct point po)
{
    po.isLast = 0;
    p->pv[ p->nPoints++ ] = po;
    if ( p->nPoints == p->size )
    {
 struct point *old = p->pv;
 int newSize = p->size * 2;
 p->pv = growVector( p->pv, p->size, newSize );
 if ( p->pv != ((void *)0))
 {
     p->size = newSize;
     free( old );
 }
 else
 {
     p->pv = old;
     p->nPoints--;
 }
    }
}

variable_types: struct pattern { struct point { int x; int y; char isLast; } *pv; int *s; int nPoints; unsigned char ascii; int size; } *

variable_types:
po
struct point


pointSlope

decompiled_code:
__int64 __fastcall pointSlope(unsigned __int64 a1, __int64 a2, unsigned __int64 a3)
{
int v4; // edi
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rbp
double v7; // xmm1_8
float v8; // xmm1_4
float v9; // xmm0_4

v4 = a1 - a3;
v5 = HIDWORD(a1);
v6 = HIDWORD(a3);
v7 = (double)(v4 * v4 + (HIDWORD(a1) - HIDWORD(a3)) * (HIDWORD(a1) - HIDWORD(a3)));
if ( v7 < 0.0 )
sqrt(v7);
else
v7 = sqrt(v7);
v8 = v7;
v9 = acos((float)((float)v4 / v8));
if ( v8 == 0.0 )
fwrite("Hyp is zero!!!!!!!!!!!!!!!!!!!!!!!!!!\n", 1uLL, 0x26uLL, stderr);
if ( (int)v5 < (int)v6 )
v9 = 6.283185307179586 - v9;
return (unsigned int)(int)(v9 * 1000.0);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1, __int64 a2, unsigned __int64 a3)
{
int v4; // edi
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rbp
double v7; // xmm1_8
float v8; // xmm1_4
float v9; // xmm0_4

v4 = a1 - a3;
v5 = HIDWORD(a1);
v6 = HIDWORD(a3);
v7 = (double)(v4 * v4 + (HIDWORD(a1) - HIDWORD(a3)) * (HIDWORD(a1) - HIDWORD(a3)));
if ( v7 < 0.0 )
sqrt(v7);
else
v7 = sqrt(v7);
v8 = v7;
v9 = acos((float)((float)v4 / v8));
if ( v8 == 0.0 )
fwrite("Hyp is zero!!!!!!!!!!!!!!!!!!!!!!!!!!\n", 1uLL, 0x26uLL, stderr);
if ( (int)v5 < (int)v6 )
v9 = 6.283185307179586 - v9;
return (unsigned int)(int)(v9 * 1000.0);
}

canonical_original_code:
int pointSlope(struct point p1, struct point p0)
{
    float hyp = (float) sqrt( (( p1.x - p0.x ) * ( p1.x - p0.x ))
         + (( p1.y - p0.y ) * ( p1.y - p0.y )) );
    float alpha = (float) acos( ( p1.x - p0.x ) / hyp );
    if (hyp == 0)
 fprintf(stderr, "Hyp is zero!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
    if ( p1.y < p0.y )
 alpha = 2 * 3.14159265358979323846 - alpha;
    return (int) ( 1000.0 * alpha );
}

variable_types: struct point { int x; int y; char isLast; }

variable_types: hyp float

variable_types: alpha float


deletePreprocessor

decompiled_code:
// attributes: thunk
void deletePreprocessor(void *ptr)
{
free(ptr);
}

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

original_code:
void
deletePreprocessor( Preprocessor *p )
{
    free( p );
}

canonical_original_code:
void deletePreprocessor(struct preprocessor *p)
{
    free( p );
}

variable_types: struct preprocessor { struct pattern { struct point { int x; int y; char isLast; } *pv; int *s; int nPoints; unsigned char ascii; int size; } *(**fs)(struct pattern *); int nFilters; } *

user_defined_types: struct preprocessor { struct pattern *(**fs)(struct pattern *); int nFilters; }


applyFilter

decompiled_code:
__int64 __fastcall applyFilter(__int64 (__fastcall *a1)(__int64), __int64 a2)
{
return a1(a2);
}

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

original_code:
Pattern *
applyFilter( filter f, Pattern *p)
{
    return f( p );
}

canonical_original_code:
struct pattern *applyFilter(struct pattern *(*f)(struct pattern *), struct pattern *p)
{
    return f( p );
}

variable_types:
f
struct pattern *(*)(struct pattern *)

variable_types:
p
struct pattern *


apply

original_code:
Pattern *
apply( Preprocessor *p, Pattern *pat )
{
    Pattern *np, *old;
    int i;
    if ( p->nFilters == 0 )
 return pat;
    np = applyFilter( p->fs[ 0 ], pat );
    for ( i = 1; i < p->nFilters; i++)
    {
 old = np;
 np = applyFilter( p->fs[ i ], np );
 deletePattern( old );
    }
    return np;
}

canonical_original_code:
struct pattern *apply(struct preprocessor *p, struct pattern *pat)
{
    struct pattern *np; struct pattern *old;
    int i;
    if ( p->nFilters == 0 )
 return pat;
    np = applyFilter( p->fs[ 0 ], pat );
    for ( i = 1; i < p->nFilters; i++)
    {
 old = np;
 np = applyFilter( p->fs[ i ], np );
 deletePattern( old );
    }
    return np;
}

variable_types: struct preprocessor { struct pattern *(**fs)(struct pattern *); int nFilters; } *

variable_types:
pat
struct pattern *

variable_types: i int


intCaptureHandler

repo: pegerto/snooper

decompiled_code:
void intCaptureHandler()
{
pcap_breakloop(handle);
}

canonical_decompiled_code:
void func0()
{
pcap_breakloop(handle);
}

original_code:
void
intCaptureHandler(int dummy)
{
 pcap_breakloop(handle) ;
}

variable_types: dummy int


decompiled_code:
__int64 __fastcall packet_handler(__int64 a1, __int64 a2, __int64 a3)
{
printf("pk %d \n", *(unsigned int *)(a2 + 20));
return cb_pkg_push(cb_pkg, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
printf("pk %d \n", *(unsigned int *)(a2 + 20));
return cb_pkg_push(cb_pkg, a2, a3);
}

original_code:
void
packet_handler(u_char *user, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
 printf("pk %d \n", header->len);
 cb_pkg_push(cb_pkg, header, pkt_data);
}

canonical_original_code:
void packet_handler(unsigned char *user, struct pcap_pkthdr *header, unsigned char *pkt_data)
{
 printf("pk %d \n", header->len);
 cb_pkg_push(cb_pkg, header, pkt_data);
}

variable_types:
user
unsigned char *

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // r12
__int64 v5; // rbp
unsigned int *v6; // rbx
int result; // eax
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

cb_pkg = cb_pkg_init("g device: %s\n", (const char *)argv);
v3 = (const char *)pcap_lookupdev(v8);
if ( v3 )
{
v4 = v3;
printf("Using device: %s\n", v3);
handle = pcap_open_live(v4, 0x2000LL, 1LL, 1000LL, v8);
v5 = handle;
if ( handle )
{
signal(2, (__sighandler_t)intCaptureHandler);
pcap_loop(v5, 0LL, packet_handler, 0LL);
pcap_close(handle);
v6 = (unsigned int *)malloc(0x18uLL);
puts("List the buffer");
while ( 1 )
{
result = cb_pkg_pull(cb_pkg, v6, 0LL);
if ( !result )
break;
printf("b pk %d\n", v6[5]);
}
}
else
{
fprintf(stderr, "Couldn't open the device %s, are you Su\n", v4);
result = 2;
}
}
else
{
fprintf(stderr, "Couldn't find default device: %s\n", v8);
result = 2;
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 char *dev;
 char errbuf[256];
 cb_pkg = cb_pkg_init(100);
 dev = pcap_lookupdev(errbuf);
 if (dev == ((void *)0))
 {
  fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
  return(2);
 }
 else
 {
  printf("Using device: %s\n", dev);
 }
 handle = pcap_open_live(dev, 8192, 1, 1000, errbuf);
 if (handle == ((void *)0))
 {
   fprintf(stderr, "Couldn't open the device %s, are you Su\n", dev);
   return(2);
 }
 signal(2, intCaptureHandler);
 pcap_loop(handle,0, packet_handler, ((void *)0));
 pcap_close(handle);
 struct pcap_pkthdr *h;
 h = malloc(sizeof(struct pcap_pkthdr));
 printf("List the buffer\n");
 while(cb_pkg_pull(cb_pkg, h, ((void *)0)))
 {
  printf("b pk %d\n", h->len);
 }
 return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
dev
char *

variable_types:
errbuf
char [256]

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
const void *__fastcall cb_pkg_push(__int64 a1, const __m128i *a2)
{
unsigned __int64 v2; // r12
__m128i *v3; // rax
const void *result; // rax
unsigned __int64 v5; // r14
char *v6; // rax
char *v7; // r13
void *v8; // r15

if ( !a1 )
{
fwrite("Error: Package buffer is not started\n", 1uLL, 0x25uLL, stderr);
exit(2);
}
v2 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 24) == v2 )
{
v5 = v2 + (v2 >> 1);
v6 = (char *)malloc(24 * v5);
v7 = v6;
if ( !v6 )
{
fwrite("Error: There is not more memory to enlarge pkg buffer\n", 1uLL, 0x36uLL, stderr);
exit(2);
}
v8 = *(void **)a1;
memcpy(v6, *(const void **)a1, 24 * v2);
*(_QWORD *)(a1 + 32) = &v7[*(_QWORD *)(a1 + 32) - (_QWORD)v8];
*(_QWORD *)(a1 + 40) = &v7[*(_QWORD *)(a1 + 40) - (_QWORD)v8];
free(v8);
*(_QWORD *)a1 = v7;
*(_QWORD *)(a1 + 16) = v5;
printf("New header buffer capacity %d\n", v2 + (v2 >> 1));
}
v3 = *(__m128i **)(a1 + 32);
*v3 = _mm_loadu_si128(a2);
v3[1].m128i_i64[0] = a2[1].m128i_i64[0];
result = (const void *)(*(_QWORD *)(a1 + 32) + 24LL);
if ( result == (const void *)(*(_QWORD *)a1 + 24LL * *(_QWORD *)(a1 + 16)) )
result = *(const void **)a1;
++*(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 32) = result;
return result;
}

canonical_decompiled_code:
const void *__fastcall func0(__int64 a1, const __m128i *a2)
{
unsigned __int64 v2; // r12
__m128i *v3; // rax
const void *result; // rax
unsigned __int64 v5; // r14
char *v6; // rax
char *v7; // r13
void *v8; // r15

if ( !a1 )
{
fwrite("Error: Package buffer is not started\n", 1uLL, 0x25uLL, stderr);
exit(2);
}
v2 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 24) == v2 )
{
v5 = v2 + (v2 >> 1);
v6 = (char *)malloc(24 * v5);
v7 = v6;
if ( !v6 )
{
fwrite("Error: There is not more memory to enlarge pkg buffer\n", 1uLL, 0x36uLL, stderr);
exit(2);
}
v8 = *(void **)a1;
memcpy(v6, *(const void **)a1, 24 * v2);
*(_QWORD *)(a1 + 32) = &v7[*(_QWORD *)(a1 + 32) - (_QWORD)v8];
*(_QWORD *)(a1 + 40) = &v7[*(_QWORD *)(a1 + 40) - (_QWORD)v8];
free(v8);
*(_QWORD *)a1 = v7;
*(_QWORD *)(a1 + 16) = v5;
printf("New header buffer capacity %d\n", v2 + (v2 >> 1));
}
v3 = *(__m128i **)(a1 + 32);
*v3 = _mm_loadu_si128(a2);
v3[1].m128i_i64[0] = a2[1].m128i_i64[0];
result = (const void *)(*(_QWORD *)(a1 + 32) + 24LL);
if ( result == (const void *)(*(_QWORD *)a1 + 24LL * *(_QWORD *)(a1 + 16)) )
result = *(const void **)a1;
++*(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 32) = result;
return result;
}

original_code:
void
cb_pkg_push(cb_pkg_buffer *cb_pkg, const struct pcap_pkthdr *header,
   const u_char *pkt_data)
{
 size_t sz = sizeof(struct pcap_pkthdr);
 size_t new_capacity;
 void *new_header_buffer;
 if (cb_pkg == ((void *)0))
 {
  fprintf(stderr, "Error: Package buffer is not started\n" );
  exit(2);
 }
 if (cb_pkg->count == cb_pkg->capacity)
 {
  new_capacity = cb_pkg->capacity + ( cb_pkg-> capacity / 2);
  new_header_buffer = malloc (new_capacity * sz);
  if (new_header_buffer == ((void *)0))
  {
   fprintf(stderr, "Error: There is not more memory to enlarge pkg buffer\n" );
   exit(2);
  }
  memcpy(new_header_buffer, cb_pkg->header_buffer , cb_pkg->capacity * sz);
  cb_pkg->h_head = new_header_buffer + (cb_pkg->h_head - cb_pkg->header_buffer);
  cb_pkg->h_tail = new_header_buffer + (cb_pkg->h_tail - cb_pkg->header_buffer);
  free(cb_pkg->header_buffer);
  cb_pkg->header_buffer = new_header_buffer;
  cb_pkg->capacity = new_capacity;
  printf("New header buffer capacity %d\n", new_capacity);
 }
 memcpy(cb_pkg->h_head, header,sz);
 cb_pkg->h_head = cb_pkg->h_head + sz;
 if (cb_pkg->h_head == (cb_pkg->header_buffer + (sz * cb_pkg->capacity)))
  cb_pkg->h_head = cb_pkg->header_buffer;
 cb_pkg->count++;
}

canonical_original_code:
void cb_pkg_push(struct cb_pkg_buffer *cb_pkg, struct pcap_pkthdr *header, unsigned char *pkt_data)
{
 unsigned long sz = sizeof(struct pcap_pkthdr);
 unsigned long new_capacity;
 void *new_header_buffer;
 if (cb_pkg == ((void *)0))
 {
  fprintf(stderr, "Error: Package buffer is not started\n" );
  exit(2);
 }
 if (cb_pkg->count == cb_pkg->capacity)
 {
  new_capacity = cb_pkg->capacity + ( cb_pkg-> capacity / 2);
  new_header_buffer = malloc (new_capacity * sz);
  if (new_header_buffer == ((void *)0))
  {
   fprintf(stderr, "Error: There is not more memory to enlarge pkg buffer\n" );
   exit(2);
  }
  memcpy(new_header_buffer, cb_pkg->header_buffer , cb_pkg->capacity * sz);
  cb_pkg->h_head = new_header_buffer + (cb_pkg->h_head - cb_pkg->header_buffer);
  cb_pkg->h_tail = new_header_buffer + (cb_pkg->h_tail - cb_pkg->header_buffer);
  free(cb_pkg->header_buffer);
  cb_pkg->header_buffer = new_header_buffer;
  cb_pkg->capacity = new_capacity;
  printf("New header buffer capacity %d\n", new_capacity);
 }
 memcpy(cb_pkg->h_head, header,sz);
 cb_pkg->h_head = cb_pkg->h_head + sz;
 if (cb_pkg->h_head == (cb_pkg->header_buffer + (sz * cb_pkg->capacity)))
  cb_pkg->h_head = cb_pkg->header_buffer;
 cb_pkg->count++;
}

variable_types: struct cb_pkg_buffer { void *header_buffer; void *package_buffer; unsigned long capacity; unsigned long count; void *h_head; void *h_tail; void *p_head; void *p_tail; } *

variable_types:
sz
unsigned long


original_code:
int
cb_pkg_pull(cb_pkg_buffer *cb_pkg, struct pcap_pkthdr *header,
   u_char *pkt_data)
{
 size_t sz = sizeof(struct pcap_pkthdr);
 if (cb_pkg == ((void *)0))
 {
  fprintf(stderr, "Error: Package buffer is not started\n" );
  exit(2);
 }
 if (cb_pkg->count == 0 )
  return 0;
 memcpy(header, cb_pkg->h_tail , sz);
 cb_pkg->h_tail = cb_pkg->h_tail + sz;
 if (cb_pkg->h_tail == (cb_pkg->capacity * sz + cb_pkg->header_buffer))
  cb_pkg->h_tail = cb_pkg->header_buffer;
 cb_pkg->count--;
 return 1;
}

canonical_original_code:
int cb_pkg_pull(struct cb_pkg_buffer *cb_pkg, struct pcap_pkthdr *header, unsigned char *pkt_data)
{
 unsigned long sz = sizeof(struct pcap_pkthdr);
 if (cb_pkg == ((void *)0))
 {
  fprintf(stderr, "Error: Package buffer is not started\n" );
  exit(2);
 }
 if (cb_pkg->count == 0 )
  return 0;
 memcpy(header, cb_pkg->h_tail , sz);
 cb_pkg->h_tail = cb_pkg->h_tail + sz;
 if (cb_pkg->h_tail == (cb_pkg->capacity * sz + cb_pkg->header_buffer))
  cb_pkg->h_tail = cb_pkg->header_buffer;
 cb_pkg->count--;
 return 1;
}

user_defined_types: struct cb_pkg_buffer { void *header_buffer; void *package_buffer; unsigned long capacity; unsigned long count; void *h_head; void *h_tail; void *p_head; void *p_tail; }


repo: pekkanikander/MacCEC

decompiled_code:
__int64 __fastcall p8_decode(__int64 a1, unsigned __int64 *a2, __int64 a3, signed __int64 a4)
{
unsigned __int64 v5; // r11
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rbx
_BYTE *v9; // rax
unsigned __int64 v10; // r8
char *v11; // rbp
_QWORD *v12; // r12
unsigned __int64 v13; // rdx
char *v14; // rdx
unsigned __int8 v15; // r13
char v16; // al
char *v17; // rdi
char v18; // al
__int64 v19; // rax
_BYTE *v20; // rdx
unsigned __int64 v21; // rax
unsigned __int64 v22; // rax

v5 = a1 + 20;
v6 = *(_QWORD *)(a1 + 8);
if ( v6 < a1 + 20 || (v7 = a1 + 128, v6 > a1 + 128) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x1Eu,
"p8_decode");
v9 = *(_BYTE **)a1;
if ( v7 < *(_QWORD *)a1 || v5 > (unsigned __int64)v9 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x1Eu,
"p8_decode");
if ( v6 < (unsigned __int64)v9 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 0x1Eu, "p8_decode");
v10 = a2[1];
v11 = (char *)a2 + 20;
if ( v10 < (unsigned __int64)a2 + 20 || (v12 = a2 + 16, v10 > (unsigned __int64)(a2 + 16)) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x1Fu,
"p8_decode");
v13 = *a2;
if ( (unsigned __int64)v11 > *a2 || (unsigned __int64)v12 < v13 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x1Fu,
"p8_decode");
if ( v10 < v13 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 0x1Fu, "p8_decode");
v14 = (char *)(v6 - (_QWORD)v9);
if ( (unsigned int)(v6 - (_DWORD)v9) <= 2 )
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
if ( *v9 != 0xFF )
return p8_frame_error(1LL, a1, v14, a4, v10, a1);
v15 = v9[1];
v14 = v9 + 2;
v16 = v9[2];
if ( v16 != -2 )
{
if ( v6 > (unsigned __int64)v14 )
{
a4 = v10 + 1;
while ( v16 != -1 )
{
v17 = v14 + 1;
if ( v16 == -3 )
{
if ( v6 < (unsigned __int64)v17 )
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
v18 = v14[1];
v14 += 2;
v10 = a4;
*(_BYTE *)(a4 - 1) = v18 - 3;
v16 = *v14;
if ( *v14 == -2 )
goto LABEL_22;
}
else
{
++v14;
*(_BYTE *)(a4 - 1) = v16;
v10 = a4;
v16 = *v17;
if ( *v17 == -2 )
goto LABEL_22;
}
++a4;
if ( v6 <= (unsigned __int64)v14 )
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
}
}
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
}
LABEL_22:
if ( (v15 & 0x3Fu) >= P8_CODE_TYPE_COUNT )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
a4 = (signed __int64)&p8_code_types + 5 * (v15 & 0x3F);
if ( (*(_BYTE *)a4 & 2) == 0 )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
v19 = v10 - a2[1];
if ( v19 < *(unsigned __int8 *)(a4 + 3) )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
a4 = *(unsigned __int8 *)(a4 + 4);
if ( v19 > a4 )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
v20 = v14 + 1;
*(_QWORD *)a1 = v20;
a2[1] = v10;
v21 = *(_QWORD *)(a1 + 8);
if ( v5 > v21 || v7 < v21 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x47u,
"p8_decode");
if ( v5 > (unsigned __int64)v20 || v7 < (unsigned __int64)v20 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x47u,
"p8_decode");
if ( v21 < (unsigned __int64)v20 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 0x47u, "p8_decode");
if ( (unsigned __int64)v11 > v10 || (unsigned __int64)v12 < v10 )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x48u,
"p8_decode");
v22 = *a2;
if ( (unsigned __int64)v11 > *a2 || (unsigned __int64)v12 < v22 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x48u,
"p8_decode");
if ( v22 > v10 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 0x48u, "p8_decode");
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 *a2, __int64 a3, signed __int64 a4)
{
unsigned __int64 v5; // r11
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rbx
_BYTE *v9; // rax
unsigned __int64 v10; // r8
char *v11; // rbp
_QWORD *v12; // r12
unsigned __int64 v13; // rdx
char *v14; // rdx
unsigned __int8 v15; // r13
char v16; // al
char *v17; // rdi
char v18; // al
__int64 v19; // rax
_BYTE *v20; // rdx
unsigned __int64 v21; // rax
unsigned __int64 v22; // rax

v5 = a1 + 20;
v6 = *(_QWORD *)(a1 + 8);
if ( v6 < a1 + 20 || (v7 = a1 + 128, v6 > a1 + 128) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x1Eu,
"p8_decode");
v9 = *(_BYTE **)a1;
if ( v7 < *(_QWORD *)a1 || v5 > (unsigned __int64)v9 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x1Eu,
"p8_decode");
if ( v6 < (unsigned __int64)v9 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 0x1Eu, "p8_decode");
v10 = a2[1];
v11 = (char *)a2 + 20;
if ( v10 < (unsigned __int64)a2 + 20 || (v12 = a2 + 16, v10 > (unsigned __int64)(a2 + 16)) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x1Fu,
"p8_decode");
v13 = *a2;
if ( (unsigned __int64)v11 > *a2 || (unsigned __int64)v12 < v13 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x1Fu,
"p8_decode");
if ( v10 < v13 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 0x1Fu, "p8_decode");
v14 = (char *)(v6 - (_QWORD)v9);
if ( (unsigned int)(v6 - (_DWORD)v9) <= 2 )
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
if ( *v9 != 0xFF )
return p8_frame_error(1LL, a1, v14, a4, v10, a1);
v15 = v9[1];
v14 = v9 + 2;
v16 = v9[2];
if ( v16 != -2 )
{
if ( v6 > (unsigned __int64)v14 )
{
a4 = v10 + 1;
while ( v16 != -1 )
{
v17 = v14 + 1;
if ( v16 == -3 )
{
if ( v6 < (unsigned __int64)v17 )
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
v18 = v14[1];
v14 += 2;
v10 = a4;
*(_BYTE *)(a4 - 1) = v18 - 3;
v16 = *v14;
if ( *v14 == -2 )
goto LABEL_22;
}
else
{
++v14;
*(_BYTE *)(a4 - 1) = v16;
v10 = a4;
v16 = *v17;
if ( *v17 == -2 )
goto LABEL_22;
}
++a4;
if ( v6 <= (unsigned __int64)v14 )
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
}
}
return p8_frame_error(0LL, a1, v14, a4, v10, a1);
}
LABEL_22:
if ( (v15 & 0x3Fu) >= P8_CODE_TYPE_COUNT )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
a4 = (signed __int64)&p8_code_types + 5 * (v15 & 0x3F);
if ( (*(_BYTE *)a4 & 2) == 0 )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
v19 = v10 - a2[1];
if ( v19 < *(unsigned __int8 *)(a4 + 3) )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
a4 = *(unsigned __int8 *)(a4 + 4);
if ( v19 > a4 )
return p8_frame_error(3LL, a1, v14, a4, v10, a1);
v20 = v14 + 1;
*(_QWORD *)a1 = v20;
a2[1] = v10;
v21 = *(_QWORD *)(a1 + 8);
if ( v5 > v21 || v7 < v21 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x47u,
"p8_decode");
if ( v5 > (unsigned __int64)v20 || v7 < (unsigned __int64)v20 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_decode.c",
0x47u,
"p8_decode");
if ( v21 < (unsigned __int64)v20 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 0x47u, "p8_decode");
if ( (unsigned __int64)v11 > v10 || (unsigned __int64)v12 < v10 )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x48u,
"p8_decode");
v22 = *a2;
if ( (unsigned __int64)v11 > *a2 || (unsigned __int64)v12 < v22 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_decode.c",
0x48u,
"p8_decode");
if ( v22 > v10 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 0x48u, "p8_decode");
return v15;
}

original_code:
int
p8_decode(p8s_frame_t *iframe, p8_frame_t *oframe) {
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 31, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 31, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    proto_char_t *end = iframe->f_end;
    proto_char_t *p = iframe->f_sta;
    proto_len_t len = end - p;
    proto_char_t *q = oframe->f_end;
    if (len < 3)
        return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
    if (*p++ != P8_FRAME_BEGIN)
        return p8_frame_error(P8_ERROR_FRAME_BEGIN_MISSING, iframe);
    const proto_char_t code = *p++;
    const proto_char_t p8_code = code & 0x3F;
    while (*p != P8_FRAME_END && p < end) {
        if (*p == P8_FRAME_BEGIN)
            return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
        if (*p == P8_FRAME_ESC) {
            if (++p > end)
                return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
            *q++ = *p++ - (P8_FRAME_BEGIN - P8_FRAME_ESC + 1);
        } else
            *q++ = *p++;
    }
    if (*p++ != P8_FRAME_END)
        return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
    if ( (p8_code >= P8_CODE_TYPE_COUNT)
        || (p8_code_types[p8_code].ct_type & 0x02) == 0
        || (q - oframe->f_end < p8_code_types[p8_code].ct_a2h_min_plen)
        || (q - oframe->f_end > p8_code_types[p8_code].ct_a2h_max_plen)) {
        return p8_frame_error(P8_ERROR_FRAME_MALFORMED, iframe);
    }
    iframe->f_sta = p;
    oframe->f_end = q;
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 71, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 71, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 72, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 72, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    return code;
}

canonical_original_code:
int p8_decode(struct proto_frame *iframe, struct proto_frame *oframe) {
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 31, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 31, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    unsigned char *end = iframe->f_end;
    unsigned char *p = iframe->f_sta;
    unsigned int len = end - p;
    unsigned char *q = oframe->f_end;
    if (len < 3)
        return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
    if (*p++ != P8_FRAME_BEGIN)
        return p8_frame_error(P8_ERROR_FRAME_BEGIN_MISSING, iframe);
    unsigned char code = *p++;
    unsigned char p8_code = code & 0x3F;
    while (*p != P8_FRAME_END && p < end) {
        if (*p == P8_FRAME_BEGIN)
            return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
        if (*p == P8_FRAME_ESC) {
            if (++p > end)
                return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
            *q++ = *p++ - (P8_FRAME_BEGIN - P8_FRAME_ESC + 1);
        } else
            *q++ = *p++;
    }
    if (*p++ != P8_FRAME_END)
        return p8_frame_error(P8_ERROR_FRAME_INCOMPLETE, iframe);
    if ( (p8_code >= P8_CODE_TYPE_COUNT)
        || (p8_code_types[p8_code].ct_type & 0x02) == 0
        || (q - oframe->f_end < p8_code_types[p8_code].ct_a2h_min_plen)
        || (q - oframe->f_end > p8_code_types[p8_code].ct_a2h_max_plen)) {
        return p8_frame_error(P8_ERROR_FRAME_MALFORMED, iframe);
    }
    iframe->f_sta = p;
    oframe->f_end = q;
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 71, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_decode.c", 71, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_decode.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 72, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_decode.c", 72, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_decode.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    return code;
}

variable_types: struct proto_frame { unsigned char *f_sta; unsigned char *f_end; int f_status; unsigned char f_buf[-1]; } *

variable_types:
oframe
struct proto_frame *

variable_types:
end
unsigned char *

variable_types:
p
unsigned char *

variable_types:
len
unsigned int

variable_types:
q
unsigned char *

variable_types:
code
unsigned char


decompiled_code:
unsigned __int8 *__fastcall encode_char(unsigned __int8 *a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al

v2 = a2;
if ( a2 > 0xFCu )
{
*a1 = -3;
v2 = a2 - 3;
++a1;
}
*a1 = v2;
return a1 + 1;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func0(unsigned __int8 *a1, unsigned __int8 a2)
{
unsigned __int8 v2; // al

v2 = a2;
if ( a2 > 0xFCu )
{
*a1 = -3;
v2 = a2 - 3;
++a1;
}
*a1 = v2;
return a1 + 1;
}

original_code:
static proto_char_t *
encode_char(proto_char_t *p, proto_char_t c) {
    if (c >= P8_FRAME_ESC) {
        *p++ = P8_FRAME_ESC;
        c -= (P8_FRAME_BEGIN - P8_FRAME_ESC + 1);
    }
    *p++ = c;
    return p;
}

canonical_original_code:
static unsigned char *encode_char(unsigned char *p, unsigned char c) {
    if (c >= P8_FRAME_ESC) {
        *p++ = P8_FRAME_ESC;
        c -= (P8_FRAME_BEGIN - P8_FRAME_ESC + 1);
    }
    *p++ = c;
    return p;
}

variable_types:
c
unsigned char

return_type: unsigned char *