testEnc

decompiled_code:
__int64 __fastcall testEnc(int a1, int a2)
{
__int64 v2; // r9
void *v3; // r8
unsigned __int16 v4; // ax
unsigned __int16 v5; // si
unsigned __int16 v6; // ax

serialPrintV("--- encoding ");
if ( a1 )
{
if ( print_buf )
{
debugPrintfFormat("large payload (%u)", 162LL);
serialPrint(print_buf);
}
pay = (__int64)&largePayload;
paySize = 162;
}
else
{
if ( print_buf )
{
debugPrintfFormat("small payload (%u)", 4LL);
serialPrint(print_buf);
}
pay = (__int64)&smallPayload;
paySize = 4;
}
serialPrintV(" into a ");
if ( a2 )
{
if ( print_buf )
{
debugPrintfFormat("large buffer (%u):\n", 240LL);
serialPrint(print_buf);
}
v3 = &tosBufLarge;
buf = (__int64)&tosBufLarge;
v2 = 240LL;
bufSize = 240;
}
else
{
if ( print_buf )
{
debugPrintfFormat("small buffer (%u):\n", 18LL);
serialPrint(print_buf);
}
v2 = 18LL;
buf = (__int64)&tosBufSmall;
bufSize = 18;
v3 = &tosBufSmall;
}
v4 = 0;
offset = 0;
v5 = paySize;
while ( 1 )
{
v6 = tosSerialMsgEnc(pay + 2LL * (v4 >> 1), v5, 4660LL, 67LL, v3, v2, &written);
processed = v6;
if ( print_buf )
{
debugPrintfFormat(
"offset = %u, bytes processed: %u, written: %u\n",
(unsigned __int16)offset,
v6,
(unsigned __int16)written);
serialPrint(print_buf);
}
if ( written )
debugHexdump(buf);
v5 = paySize - processed;
v4 = processed + offset;
paySize -= processed;
offset += processed;
if ( !processed || !v5 )
break;
v2 = (unsigned __int16)bufSize;
v3 = (void *)buf;
}
serialPrintV("\n");
return msleep(1000LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 v2; // r9
void *v3; // r8
unsigned __int16 v4; // ax
unsigned __int16 v5; // si
unsigned __int16 v6; // ax

func0("--- encoding ");
if ( a1 )
{
if ( print_buf )
{
debugPrintfFormat("large payload (%u)", 162LL);
serialPrint(print_buf);
}
pay = (__int64)&largePayload;
paySize = 162;
}
else
{
if ( print_buf )
{
debugPrintfFormat("small payload (%u)", 4LL);
serialPrint(print_buf);
}
pay = (__int64)&smallPayload;
paySize = 4;
}
func0(" into a ");
if ( a2 )
{
if ( print_buf )
{
debugPrintfFormat("large buffer (%u):\n", 240LL);
serialPrint(print_buf);
}
v3 = &tosBufLarge;
buf = (__int64)&tosBufLarge;
v2 = 240LL;
bufSize = 240;
}
else
{
if ( print_buf )
{
debugPrintfFormat("small buffer (%u):\n", 18LL);
serialPrint(print_buf);
}
v2 = 18LL;
buf = (__int64)&tosBufSmall;
bufSize = 18;
v3 = &tosBufSmall;
}
v4 = 0;
offset = 0;
v5 = paySize;
while ( 1 )
{
v6 = tosSerialMsgEnc(pay + 2LL * (v4 >> 1), v5, 4660LL, 67LL, v3, v2, &written);
processed = v6;
if ( print_buf )
{
debugPrintfFormat(
"offset = %u, bytes processed: %u, written: %u\n",
(unsigned __int16)offset,
v6,
(unsigned __int16)written);
serialPrint(print_buf);
}
if ( written )
debugHexdump(buf);
v5 = paySize - processed;
v4 = processed + offset;
paySize -= processed;
offset += processed;
if ( !processed || !v5 )
break;
v2 = (unsigned __int16)bufSize;
v3 = (void *)buf;
}
func0("\n");
return msleep(1000LL);
}

original_code:
void testEnc(Size_t payload, Size_t buffer) {
    if (1 == 1) { serialPrintV("--- encoding "); } else { if (_print_buf) { debugPrintfFormat("--- encoding "); serialPrint(_print_buf); }; };
    if (payload == SMALL) {
        if (2 == 1) { serialPrintV("small payload (%u)", sizeof(smallPayload)); } else { if (_print_buf) { debugPrintfFormat("small payload (%u)", sizeof(smallPayload)); serialPrint(_print_buf); }; };
        pay = smallPayload;
        paySize = SMALL_PAYLOAD_SIZE * 2;
    } else {
        if (2 == 1) { serialPrintV("large payload (%u)", sizeof(largePayload)); } else { if (_print_buf) { debugPrintfFormat("large payload (%u)", sizeof(largePayload)); serialPrint(_print_buf); }; };
        pay = largePayload;
        paySize = LARGE_PAYLOAD_SIZE * 2;
    }
    if (1 == 1) { serialPrintV(" into a "); } else { if (_print_buf) { debugPrintfFormat(" into a "); serialPrint(_print_buf); }; };
    if (buffer == SMALL) {
        if (2 == 1) { serialPrintV("small buffer (%u):\n", sizeof(tosBufSmall)); } else { if (_print_buf) { debugPrintfFormat("small buffer (%u):\n", sizeof(tosBufSmall)); serialPrint(_print_buf); }; };
        buf = tosBufSmall;
        bufSize = SMALL_TOSBUF_SIZE * 2;
    } else {
        if (2 == 1) { serialPrintV("large buffer (%u):\n", sizeof(tosBufLarge)); } else { if (_print_buf) { debugPrintfFormat("large buffer (%u):\n", sizeof(tosBufLarge)); serialPrint(_print_buf); }; };
        buf = tosBufLarge;
        bufSize = LARGE_TOSBUF_SIZE * 2;
    }
    offset = 0;
    do {
        processed = tosSerialMsgEnc(pay + (offset >> 1), paySize,
                0x1234, 67, buf, bufSize, &written);
        if (4 == 1) { serialPrintV("offset = %u, bytes processed: %u, written: %u\n", offset, processed, written); } else { if (_print_buf) { debugPrintfFormat("offset = %u, bytes processed: %u, written: %u\n", offset, processed, written); serialPrint(_print_buf); }; };
        if (written) debugHexdump((uint8_t *) buf, written);
        paySize -= processed;
        offset += processed;
    } while (paySize && processed);
    if (1 == 1) { serialPrintV("\n"); } else { if (_print_buf) { debugPrintfFormat("\n"); serialPrint(_print_buf); }; };
    msleep(SLEEP_TIME);
}

canonical_original_code:
void testEnc(enum Size_t payload, enum Size_t buffer) {
    if (1 == 1) { serialPrintV("--- encoding "); } else { if (_print_buf) { debugPrintfFormat("--- encoding "); serialPrint(_print_buf); }; };
    if (payload == SMALL) {
        if (2 == 1) { serialPrintV("small payload (%u)", sizeof(smallPayload)); } else { if (_print_buf) { debugPrintfFormat("small payload (%u)", sizeof(smallPayload)); serialPrint(_print_buf); }; };
        pay = smallPayload;
        paySize = SMALL_PAYLOAD_SIZE * 2;
    } else {
        if (2 == 1) { serialPrintV("large payload (%u)", sizeof(largePayload)); } else { if (_print_buf) { debugPrintfFormat("large payload (%u)", sizeof(largePayload)); serialPrint(_print_buf); }; };
        pay = largePayload;
        paySize = LARGE_PAYLOAD_SIZE * 2;
    }
    if (1 == 1) { serialPrintV(" into a "); } else { if (_print_buf) { debugPrintfFormat(" into a "); serialPrint(_print_buf); }; };
    if (buffer == SMALL) {
        if (2 == 1) { serialPrintV("small buffer (%u):\n", sizeof(tosBufSmall)); } else { if (_print_buf) { debugPrintfFormat("small buffer (%u):\n", sizeof(tosBufSmall)); serialPrint(_print_buf); }; };
        buf = tosBufSmall;
        bufSize = SMALL_TOSBUF_SIZE * 2;
    } else {
        if (2 == 1) { serialPrintV("large buffer (%u):\n", sizeof(tosBufLarge)); } else { if (_print_buf) { debugPrintfFormat("large buffer (%u):\n", sizeof(tosBufLarge)); serialPrint(_print_buf); }; };
        buf = tosBufLarge;
        bufSize = LARGE_TOSBUF_SIZE * 2;
    }
    offset = 0;
    do {
        processed = tosSerialMsgEnc(pay + (offset >> 1), paySize,
                0x1234, 67, buf, bufSize, &written);
        if (4 == 1) { serialPrintV("offset = %u, bytes processed: %u, written: %u\n", offset, processed, written); } else { if (_print_buf) { debugPrintfFormat("offset = %u, bytes processed: %u, written: %u\n", offset, processed, written); serialPrint(_print_buf); }; };
        if (written) debugHexdump((unsigned char *) buf, written);
        paySize -= processed;
        offset += processed;
    } while (paySize && processed);
    if (1 == 1) { serialPrintV("\n"); } else { if (_print_buf) { debugPrintfFormat("\n"); serialPrint(_print_buf); }; };
    msleep(SLEEP_TIME);
}

variable_types:
payload
enum Size_t { SMALL=0, LARGE=1 }

variable_types:
buffer
enum Size_t { SMALL=0, LARGE=1 }


adcGetChannelCount

repo: atiselsts/osw

decompiled_code:
__int64 adcGetChannelCount()
{
return 16LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 16LL;
}

original_code:
static inline uint_t adcGetChannelCount(void) {
    return (16);
}

canonical_original_code:
static inline unsigned int adcGetChannelCount() {
    return (16);
}

return_type: unsigned int


doMsleep

decompiled_code:
int __fastcall doMsleep(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int16 a1)
{
return usleep(1000 * a1);
}

original_code:
extern inline void doMsleep(uint16_t milliseconds) {
    usleep(milliseconds * 1000);
}

canonical_original_code:
extern inline void doMsleep(unsigned short milliseconds) {
    usleep(milliseconds * 1000);
}

variable_types:
milliseconds
unsigned short

return_type: void


loopForever

decompiled_code:
// attributes: thunk
void __noreturn loopForever(void)
{
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func0(void)
{
while ( 1 )
;
}

original_code:
static void loopForever(void) {
    for (;;);
}

canonical_original_code:
static void loopForever() {
    for (;;);
}


doMsleep

canonical_decompiled_code:
int __fastcall func1(unsigned __int16 a1)
{
return usleep(1000 * a1);
}


getJiffies

decompiled_code:
__int64 getJiffies()
{
return jiffies;
}

canonical_decompiled_code:
__int64 func0()
{
return jiffies;
}

original_code:
static inline ticks_t getJiffies(void)
{
    Handle_t handle;
    (handle) = 0;
    ticks_t result = jiffies;
    ((void) handle);
    return result;
}

canonical_original_code:
static inline unsigned int getJiffies()
{
    unsigned short handle;
    (handle) = 0;
    unsigned int result = jiffies;
    ((void) handle);
    return result;
}

variable_types:
handle
unsigned short

variable_types:
result
unsigned int


getTimeMs

decompiled_code:
// attributes: thunk
__int64 getTimeMs()
{
return getJiffies();
}

canonical_decompiled_code:
__int64 func1()
{
return func0();
}

original_code:
static inline uint32_t getTimeMs(void) {
    return (uint32_t) getJiffies();
}

canonical_original_code:
static inline unsigned int getTimeMs() {
    return (unsigned int) getJiffies();
}


adcReadFast

decompiled_code:
__int64 adcReadFast()
{
return hplAdcGetVal();
}

canonical_decompiled_code:
__int64 func2()
{
return hplAdcGetVal();
}

original_code:
static inline uint16_t adcReadFast(void)
{
    ;
    while ((0));
    return hplAdcGetVal();
}

canonical_original_code:
static inline unsigned short adcReadFast()
{
    ;
    while ((0));
    return hplAdcGetVal();
}

return_type: unsigned short


doMsleep

canonical_decompiled_code:
int __fastcall func3(unsigned __int16 a1)
{
return usleep(1000 * a1);
}


ledOn

decompiled_code:
__int64 ledOn()
{
return pinSetPc(255LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
return pinSetPc(255LL, 0LL);
}

original_code: static inline void ledOn(void) { led0On(); }

canonical_original_code: static inline void ledOn() { led0On(); }


adcReadFast

canonical_decompiled_code:
__int64 func1()
{
return hplAdcGetVal();
}


ledOff

decompiled_code:
__int64 ledOff()
{
return pinClearPc(255LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
return pinClearPc(255LL, 0LL);
}

original_code: static inline void ledOff(void) { led0Off(); }

canonical_original_code: static inline void ledOff() { led0Off(); }


doMsleep

canonical_decompiled_code:
int __fastcall func4(unsigned __int16 a1)
{
return usleep(1000 * a1);
}


serialPrintV

decompiled_code:
__int64 serialPrintV()
{
return serialPrint();
}

canonical_decompiled_code:
__int64 func0()
{
return serialPrint();
}

original_code:
static inline void serialPrintV(const char* str, ...) {
    serialPrint(str);
}

canonical_original_code:
static inline void serialPrintV(char *str, ...) {
    serialPrint(str);
}

variable_types:
str
char *


repo: atwong/binky

original_code:
void x_strpool_new_blob( Strpool *sp ) {
  struct strpool_blob_r *nsb = malloc(sizeof(struct strpool_blob_r));
  memset(nsb, '\0', sizeof(struct strpool_blob_r));
  sp->nextfree = nsb->blob = malloc(sp->bsize);
  if (sp->head != ((void *)0)) {
    sp->head->prev = nsb;
  }
  nsb->next = sp->head;
  nsb->rem = sp->bsize;
  sp->head = nsb;
  ++sp->bcnt;
}

canonical_original_code:
void x_strpool_new_blob(struct strpool_r *sp) {
  struct strpool_blob_r *nsb = malloc(sizeof(struct strpool_blob_r));
  memset(nsb, '\0', sizeof(struct strpool_blob_r));
  sp->nextfree = nsb->blob = malloc(sp->bsize);
  if (sp->head != ((void *)0)) {
    sp->head->prev = nsb;
  }
  nsb->next = sp->head;
  nsb->rem = sp->bsize;
  sp->head = nsb;
  ++sp->bcnt;
}

variable_types: struct strpool_r { struct strpool_blob_r { struct strpool_blob_r *next; struct strpool_blob_r *prev; char *blob; unsigned long rem; } *head; unsigned long bsize; unsigned int bcnt; char *nextfree; } *

user_defined_types: struct strpool_r { struct strpool_blob_r *head; unsigned long bsize; unsigned int bcnt; char *nextfree; }


decompiled_code:
__int64 __fastcall strpool_init(__int64 *a1, __int64 a2)
{
*a1 = 0LL;
if ( !a2 )
a2 = 5242880LL;
*((_DWORD *)a1 + 4) = 0;
a1[1] = a2;
return x_strpool_new_blob(a1);
}

original_code:
void strpool_init( Strpool *sp, size_t bsize ) {
  sp->bsize = (bsize) ? bsize : ((5*1024*1024)*sizeof(char));
  sp->head = ((void *)0);
  sp->bcnt = 0;
  x_strpool_new_blob(sp);
}

canonical_original_code:
void strpool_init(struct strpool_r *sp, unsigned long bsize) {
  sp->bsize = (bsize) ? bsize : ((5*1024*1024)*sizeof(char));
  sp->head = ((void *)0);
  sp->bcnt = 0;
  x_strpool_new_blob(sp);
}

variable_types:
bsize
unsigned long

user_defined_types: struct strpool_blob_r { struct strpool_blob_r *next; struct strpool_blob_r *prev; char *blob; unsigned long rem; }


decompiled_code:
char *__fastcall strpool_add(__int64 *a1, const char *a2)
{
int v2; // ebp
char *result; // rax

v2 = strlen(a2) + 2;
if ( (unsigned __int64)v2 > *(_QWORD *)(*a1 + 24) )
x_strpool_new_blob(a1);
result = strcpy((char *)(a1[3] + 1), a2);
a1[3] += v2;
*(_QWORD *)(*a1 + 24) -= v2;
return result;
}

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

v2 = strlen(a2) + 2;
if ( (unsigned __int64)v2 > *(_QWORD *)(*a1 + 24) )
func0(a1);
result = strcpy((char *)(a1[3] + 1), a2);
a1[3] += v2;
*(_QWORD *)(*a1 + 24) -= v2;
return result;
}

original_code:
char *strpool_add( Strpool *sp, const char *p ) {
  int slen = strlen(p)+2;
  if ((slen*sizeof(char)) > sp->head->rem) {
    x_strpool_new_blob(sp);
  }
  char *q = sp->nextfree;
  strcpy((q+1), p);
  sp->nextfree += slen;
  sp->head->rem -= slen*sizeof(char);
  return (q+1);
}

canonical_original_code:
char *strpool_add(struct strpool_r *sp, char *p) {
  int slen = strlen(p)+2;
  if ((slen*sizeof(char)) > sp->head->rem) {
    x_strpool_new_blob(sp);
  }
  char *q = sp->nextfree;
  strcpy((q+1), p);
  sp->nextfree += slen;
  sp->head->rem -= slen*sizeof(char);
  return (q+1);
}

variable_types:
p
char *

variable_types: slen int

variable_types:
q
char *

return_type: char *


decompiled_code:
void __fastcall strpool_release(_QWORD *a1)
{
_QWORD *v1; // rbp
_QWORD *v2; // r12
void *v3; // rdi

v1 = (_QWORD *)*a1;
if ( !*a1 )
goto LABEL_8;
do
{
free((void *)v1[2]);
v1 = (_QWORD *)*v1;
}
while ( v1 );
v2 = (_QWORD *)*a1;
if ( *a1 )
{
while ( 1 )
{
v3 = v1;
v1 = v2;
free(v3);
if ( !*v2 )
break;
v2 = (_QWORD *)*v2;
}
free(v2);
}
else
{
LABEL_8:
free(0LL);
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
_QWORD *v1; // rbp
_QWORD *v2; // r12
void *v3; // rdi

v1 = (_QWORD *)*a1;
if ( !*a1 )
goto LABEL_8;
do
{
free((void *)v1[2]);
v1 = (_QWORD *)*v1;
}
while ( v1 );
v2 = (_QWORD *)*a1;
if ( *a1 )
{
while ( 1 )
{
v3 = v1;
v1 = v2;
free(v3);
if ( !*v2 )
break;
v2 = (_QWORD *)*v2;
}
free(v2);
}
else
{
LABEL_8:
free(0LL);
}
}

original_code:
void strpool_release( Strpool *sp ) {
  struct strpool_blob_r *sb, *sbx;
  for (sb=sp->head; sb; sb=sb->next) {
    free(sb->blob);
  }
  for (sbx=0, sb=sp->head; sb; sbx=sb,sb=sb->next)
    free(sbx);
  free(sbx);
}

canonical_original_code:
void strpool_release(struct strpool_r *sp) {
  struct strpool_blob_r *sb; struct strpool_blob_r *sbx;
  for (sb=sp->head; sb; sb=sb->next) {
    free(sb->blob);
  }
  for (sbx=0, sb=sp->head; sb; sbx=sb,sb=sb->next)
    free(sbx);
  free(sbx);
}

variable_types: struct strpool_blob_r { struct strpool_blob_r *next; struct strpool_blob_r *prev; char *blob; unsigned long rem; } *


decompiled_code:
int __fastcall pp_stats(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 i; // rdx
__int64 v4; // rcx

v1 = a1[2];
v2 = 0LL;
for ( i = 0LL; v1; i += v4 )
{
v4 = *(unsigned __int16 *)(v1 + 4);
v1 = *(_QWORD *)(v1 + 8);
v2 = (unsigned int)(v2 + 1);
}
return printf(
"Free list len: %d Cum free size: %lu PagesCount: %d TotalPageSize: %lu Coalesc:%ld\n",
v2,
i,
(unsigned int)(*(_DWORD *)(a1[1] + 16LL) + 1),
(__int64)(*(_DWORD *)(a1[1] + 16LL) + 1) << 16,
a1[6]);
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 i; // rdx
__int64 v4; // rcx

v1 = a1[2];
v2 = 0LL;
for ( i = 0LL; v1; i += v4 )
{
v4 = *(unsigned __int16 *)(v1 + 4);
v1 = *(_QWORD *)(v1 + 8);
v2 = (unsigned int)(v2 + 1);
}
return printf(
"Free list len: %d Cum free size: %lu PagesCount: %d TotalPageSize: %lu Coalesc:%ld\n",
v2,
i,
(unsigned int)(*(_DWORD *)(a1[1] + 16LL) + 1),
(__int64)(*(_DWORD *)(a1[1] + 16LL) + 1) << 16,
a1[6]);
}

original_code:
void pp_stats( pagepool *pp )
{
  struct pagepool_page_r *pg;
  struct ppll *pll;
  size_t cum_free_chunk;
  int nfr;
  for (cum_free_chunk=0,pll=pp->frsiz_head,nfr=0; pll; pll=pll->snext, ++nfr)
    cum_free_chunk += pll->chunk.size;
  printf("Free list len: %d  Cum free size: %lu  PagesCount: %d  TotalPageSize: %lu  Coalesc:%ld\n",
  nfr, cum_free_chunk, (pp->pool_tail->idx+1),
  (size_t)(pp->pool_tail->idx+1)*(1<<16), pp->ncoal);
}

canonical_original_code:
void pp_stats(struct pagepool_r *pp)
{
  struct pagepool_page_r *pg;
  struct ppll *pll;
  unsigned long cum_free_chunk;
  int nfr;
  for (cum_free_chunk=0,pll=pp->frsiz_head,nfr=0; pll; pll=pll->snext, ++nfr)
    cum_free_chunk += pll->chunk.size;
  printf("Free list len: %d  Cum free size: %lu  PagesCount: %d  TotalPageSize: %lu  Coalesc:%ld\n",
  nfr, cum_free_chunk, (pp->pool_tail->idx+1),
  (unsigned long)(pp->pool_tail->idx+1)*(1<<16), pp->ncoal);
}

variable_types: struct pagepool_r { struct pagepool_page_r { struct pagepool_page_r *next; char *page; int idx; } *pool_head; struct pagepool_page_r *pool_tail; struct ppll { struct pagepool_ptr_r { unsigned short pidx; unsigned short poff; unsigned short size; } chunk; struct ppll *snext; struct ppll *lnext; } *frsiz_head; struct ppll *frsiz_tail; struct ppll *frloc_head; struct ppll *frloc_tail; unsigned long ncoal; } *

variable_types: nfr int

user_defined_types: struct pagepool_r { struct pagepool_page_r *pool_head; struct pagepool_page_r *pool_tail; struct ppll *frsiz_head; struct ppll *frsiz_tail; struct ppll *frloc_head; struct ppll *frloc_tail; unsigned long ncoal; }

user_defined_types: struct ppll { struct pagepool_ptr_r chunk; struct ppll *snext; struct ppll *lnext; }


decompiled_code:
void __fastcall pp_validate(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rax
unsigned __int16 v3; // dx
unsigned __int16 v4; // cx
unsigned __int16 *v5; // rcx
unsigned __int16 *v6; // rax
int v7; // edx
int v8; // esi
int v9; // edi

v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
{
v3 = *(_WORD *)(v1 + 4);
do
{
v4 = v3;
v3 = *(_WORD *)(v2 + 4);
if ( v3 < v4 )
_assert_fail("(prev->chunk.size <= pll->chunk.size)", "pagepool.c", 0x28u, "pp_validate");
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
}
v5 = *(unsigned __int16 **)(a1 + 32);
if ( v5 )
{
v6 = (unsigned __int16 *)*((_QWORD *)v5 + 2);
if ( v6 )
{
v7 = *v5;
v8 = v5[1];
do
{
v9 = (v7 << 17) + v8;
v7 = *v6;
v8 = v6[1];
if ( v9 >= v8 + (v7 << 17) )
_assert_fail("(PAGEPOOL_LOC(prev->chunk) < PAGEPOOL_LOC(pll->chunk))", "pagepool.c", 0x2Du, "pp_validate");
v6 = (unsigned __int16 *)*((_QWORD *)v6 + 2);
}
while ( v6 );
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rax
unsigned __int16 v3; // dx
unsigned __int16 v4; // cx
unsigned __int16 *v5; // rcx
unsigned __int16 *v6; // rax
int v7; // edx
int v8; // esi
int v9; // edi

v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 8);
if ( v2 )
{
v3 = *(_WORD *)(v1 + 4);
do
{
v4 = v3;
v3 = *(_WORD *)(v2 + 4);
if ( v3 < v4 )
_assert_fail("(prev->chunk.size <= pll->chunk.size)", "pagepool.c", 0x28u, "pp_validate");
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
}
v5 = *(unsigned __int16 **)(a1 + 32);
if ( v5 )
{
v6 = (unsigned __int16 *)*((_QWORD *)v5 + 2);
if ( v6 )
{
v7 = *v5;
v8 = v5[1];
do
{
v9 = (v7 << 17) + v8;
v7 = *v6;
v8 = v6[1];
if ( v9 >= v8 + (v7 << 17) )
_assert_fail("(PAGEPOOL_LOC(prev->chunk) < PAGEPOOL_LOC(pll->chunk))", "pagepool.c", 0x2Du, "pp_validate");
v6 = (unsigned __int16 *)*((_QWORD *)v6 + 2);
}
while ( v6 );
}
}
}

original_code:
void pp_validate( pagepool *pp )
{
  struct ppll *pll, *prev;
  if (pp->frsiz_head) {
    for (prev=pp->frsiz_head, pll=pp->frsiz_head->snext; pll; prev=pll, pll=pll->snext) {
      ((void) sizeof (((prev->chunk.size <= pll->chunk.size)) ? 1 : 0), __extension__ ({ if ((prev->chunk.size <= pll->chunk.size)) ; else __assert_fail ("(prev->chunk.size <= pll->chunk.size)", "pagepool.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    }
  }
  if (pp->frloc_head) {
    for (prev=pp->frloc_head, pll=pp->frloc_head->lnext; pll; prev=pll, pll=pll->lnext) {
      ((void) sizeof ((((((prev->chunk).pidx*2*(1<<16))+(prev->chunk).poff) < (((pll->chunk).pidx*2*(1<<16))+(pll->chunk).poff))) ? 1 : 0), __extension__ ({ if (((((prev->chunk).pidx*2*(1<<16))+(prev->chunk).poff) < (((pll->chunk).pidx*2*(1<<16))+(pll->chunk).poff))) ; else __assert_fail ("(PAGEPOOL_LOC(prev->chunk) < PAGEPOOL_LOC(pll->chunk))", "pagepool.c", 45, __extension__ __PRETTY_FUNCTION__); }));;
    }
  }
}

canonical_original_code:
void pp_validate(struct pagepool_r *pp)
{
  struct ppll *pll; struct ppll *prev;
  if (pp->frsiz_head) {
    for (prev=pp->frsiz_head, pll=pp->frsiz_head->snext; pll; prev=pll, pll=pll->snext) {
      ((void) sizeof (((prev->chunk.size <= pll->chunk.size)) ? 1 : 0), __extension__ ({ if ((prev->chunk.size <= pll->chunk.size)) ; else __assert_fail ("(prev->chunk.size <= pll->chunk.size)", "pagepool.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    }
  }
  if (pp->frloc_head) {
    for (prev=pp->frloc_head, pll=pp->frloc_head->lnext; pll; prev=pll, pll=pll->lnext) {
      ((void) sizeof ((((((prev->chunk).pidx*2*(1<<16))+(prev->chunk).poff) < (((pll->chunk).pidx*2*(1<<16))+(pll->chunk).poff))) ? 1 : 0), __extension__ ({ if (((((prev->chunk).pidx*2*(1<<16))+(prev->chunk).poff) < (((pll->chunk).pidx*2*(1<<16))+(pll->chunk).poff))) ; else __assert_fail ("(PAGEPOOL_LOC(prev->chunk) < PAGEPOOL_LOC(pll->chunk))", "pagepool.c", 45, __extension__ __PRETTY_FUNCTION__); }));;
    }
  }
}

variable_types: struct ppll { struct pagepool_ptr_r { unsigned short pidx; unsigned short poff; unsigned short size; } chunk; struct ppll *snext; struct ppll *lnext; } *

user_defined_types: struct pagepool_page_r { struct pagepool_page_r *next; char *page; int idx; }


original_code:
void pp_ll_add( pagepool *pp, struct ppll *npll )
{
  struct ppll *pll, *prev;
  for (prev=((void *)0), pll=pp->frsiz_head; pll; prev=pll, pll=pll->snext) {
    if (npll->chunk.size < pll->chunk.size) {
      npll->snext = pll;
      if (prev) {
 prev->snext = npll;
      }
      else {
 pp->frsiz_head = npll;
      }
      break;
    }
  }
  if (pll == ((void *)0)) {
    if (pp->frsiz_tail)
      pp->frsiz_tail->snext = npll;
    pp->frsiz_tail = npll;
    if (!pp->frsiz_head)
      pp->frsiz_head = npll;
  }
  unsigned long loc = (((npll->chunk).pidx*2*(1<<16))+(npll->chunk).poff);
  for (prev=((void *)0), pll=pp->frloc_head; pll; prev=pll, pll=pll->lnext) {
    if (loc <= (((pll->chunk).pidx*2*(1<<16))+(pll->chunk).poff)) {
      ((void) sizeof (((npll != pll)) ? 1 : 0), __extension__ ({ if ((npll != pll)) ; else __assert_fail ("(npll != pll)", "pagepool.c", 139, __extension__ __PRETTY_FUNCTION__); }));
      if (prev) {
 ((void) sizeof (((prev != npll)) ? 1 : 0), __extension__ ({ if ((prev != npll)) ; else __assert_fail ("(prev != npll)", "pagepool.c", 141, __extension__ __PRETTY_FUNCTION__); }));
 if (((((prev->chunk).pidx*2*(1<<16))+(prev->chunk).poff)+prev->chunk.size) == loc) {
   ++pp->ncoal;
   prev->lnext = npll;
   npll->lnext = pll;
 }
 else {
   prev->lnext = npll;
   npll->lnext = pll;
 }
      }
      else {
 ((void) sizeof (((pp->frloc_head == pll)) ? 1 : 0), __extension__ ({ if ((pp->frloc_head == pll)) ; else __assert_fail ("(pp->frloc_head == pll)", "pagepool.c", 155, __extension__ __PRETTY_FUNCTION__); }));
 pp->frloc_head = npll;
 npll->lnext = pll;
      }
      break;
    }
  }
  if (pll == ((void *)0)) {
    ((void) sizeof (((pp->frloc_tail != npll)) ? 1 : 0), __extension__ ({ if ((pp->frloc_tail != npll)) ; else __assert_fail ("(pp->frloc_tail != npll)", "pagepool.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    if (pp->frloc_tail)
      pp->frloc_tail->lnext = npll;
    pp->frloc_tail = npll;
    if (!pp->frloc_head)
      pp->frloc_head = npll;
  }
  return;
}

canonical_original_code:
void pp_ll_add(struct pagepool_r *pp, struct ppll *npll)
{
  struct ppll *pll; struct ppll *prev;
  for (prev=((void *)0), pll=pp->frsiz_head; pll; prev=pll, pll=pll->snext) {
    if (npll->chunk.size < pll->chunk.size) {
      npll->snext = pll;
      if (prev) {
 prev->snext = npll;
      }
      else {
 pp->frsiz_head = npll;
      }
      break;
    }
  }
  if (pll == ((void *)0)) {
    if (pp->frsiz_tail)
      pp->frsiz_tail->snext = npll;
    pp->frsiz_tail = npll;
    if (!pp->frsiz_head)
      pp->frsiz_head = npll;
  }
  unsigned long loc = (((npll->chunk).pidx*2*(1<<16))+(npll->chunk).poff);
  for (prev=((void *)0), pll=pp->frloc_head; pll; prev=pll, pll=pll->lnext) {
    if (loc <= (((pll->chunk).pidx*2*(1<<16))+(pll->chunk).poff)) {
      ((void) sizeof (((npll != pll)) ? 1 : 0), __extension__ ({ if ((npll != pll)) ; else __assert_fail ("(npll != pll)", "pagepool.c", 139, __extension__ __PRETTY_FUNCTION__); }));
      if (prev) {
 ((void) sizeof (((prev != npll)) ? 1 : 0), __extension__ ({ if ((prev != npll)) ; else __assert_fail ("(prev != npll)", "pagepool.c", 141, __extension__ __PRETTY_FUNCTION__); }));
 if (((((prev->chunk).pidx*2*(1<<16))+(prev->chunk).poff)+prev->chunk.size) == loc) {
   ++pp->ncoal;
   prev->lnext = npll;
   npll->lnext = pll;
 }
 else {
   prev->lnext = npll;
   npll->lnext = pll;
 }
      }
      else {
 ((void) sizeof (((pp->frloc_head == pll)) ? 1 : 0), __extension__ ({ if ((pp->frloc_head == pll)) ; else __assert_fail ("(pp->frloc_head == pll)", "pagepool.c", 155, __extension__ __PRETTY_FUNCTION__); }));
 pp->frloc_head = npll;
 npll->lnext = pll;
      }
      break;
    }
  }
  if (pll == ((void *)0)) {
    ((void) sizeof (((pp->frloc_tail != npll)) ? 1 : 0), __extension__ ({ if ((pp->frloc_tail != npll)) ; else __assert_fail ("(pp->frloc_tail != npll)", "pagepool.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    if (pp->frloc_tail)
      pp->frloc_tail->lnext = npll;
    pp->frloc_tail = npll;
    if (!pp->frloc_head)
      pp->frloc_head = npll;
  }
  return;
}

variable_types:
npll
struct ppll *

variable_types:
loc
unsigned long

user_defined_types: struct pagepool_ptr_r { unsigned short pidx; unsigned short poff; unsigned short size; }


original_code:
pgpp pp_alloc( pagepool *pp, size_t size )
{
  pgpp rval;
  struct ppll *pll, *prev, *nppll;
  for (prev=((void *)0), pll=pp->frsiz_head; pll; prev=pll, pll=pll->snext) {
    if (size > pll->chunk.size) continue;
    if ((pll->chunk.size - size) < 16) {
      pp_ll_detach(pp, pll);
      rval = pll->chunk;
      free(pll);
      pp_validate(pp);
      return rval;
    }
    else if (pll->chunk.size >= size) {
      rval = pll->chunk;
      rval.size = size;
      pp_ll_detach(pp, pll);
      pll->chunk.size -= size;
      pll->chunk.poff += size;
      pp_ll_add(pp, pll);
      pp_validate(pp);
      return rval;
    }
  }
  struct pagepool_page_r *pg = malloc(sizeof(struct pagepool_page_r));
  pg->page = malloc(sizeof(char)*(1<<16));
  pg->next = ((void *)0);
  pg->idx = (pp->pool_tail) ? (pp->pool_tail->idx+1) : 0;
  if (pp->pool_tail)
    pp->pool_tail->next = pg;
  if (!pp->pool_head)
    pp->pool_head = pg;
  pp->pool_tail = pg;
  rval.pidx = pg->idx;
  rval.poff = 0;
  rval.size = (size >= 16) ? size : 16;
  nppll = malloc(sizeof(struct ppll));
  nppll->chunk.pidx = pg->idx;
  nppll->chunk.poff = rval.size;
  nppll->chunk.size = (1<<16) - rval.size;
  nppll->snext = ((void *)0);
  nppll->lnext = ((void *)0);
  pp_ll_add(pp, nppll);
  pp_validate(pp);
  return rval;
}

canonical_original_code:
struct pagepool_ptr_r pp_alloc(struct pagepool_r *pp, unsigned long size)
{
  struct pagepool_ptr_r rval;
  struct ppll *pll; struct ppll *prev; struct ppll *nppll;
  for (prev=((void *)0), pll=pp->frsiz_head; pll; prev=pll, pll=pll->snext) {
    if (size > pll->chunk.size) continue;
    if ((pll->chunk.size - size) < 16) {
      pp_ll_detach(pp, pll);
      rval = pll->chunk;
      free(pll);
      pp_validate(pp);
      return rval;
    }
    else if (pll->chunk.size >= size) {
      rval = pll->chunk;
      rval.size = size;
      pp_ll_detach(pp, pll);
      pll->chunk.size -= size;
      pll->chunk.poff += size;
      pp_ll_add(pp, pll);
      pp_validate(pp);
      return rval;
    }
  }
  struct pagepool_page_r *pg = malloc(sizeof(struct pagepool_page_r));
  pg->page = malloc(sizeof(char)*(1<<16));
  pg->next = ((void *)0);
  pg->idx = (pp->pool_tail) ? (pp->pool_tail->idx+1) : 0;
  if (pp->pool_tail)
    pp->pool_tail->next = pg;
  if (!pp->pool_head)
    pp->pool_head = pg;
  pp->pool_tail = pg;
  rval.pidx = pg->idx;
  rval.poff = 0;
  rval.size = (size >= 16) ? size : 16;
  nppll = malloc(sizeof(struct ppll));
  nppll->chunk.pidx = pg->idx;
  nppll->chunk.poff = rval.size;
  nppll->chunk.size = (1<<16) - rval.size;
  nppll->snext = ((void *)0);
  nppll->lnext = ((void *)0);
  pp_ll_add(pp, nppll);
  pp_validate(pp);
  return rval;
}

variable_types: struct pagepool_r { struct pagepool_page_r { struct pagepool_page_r *next; char *page; int idx; } *pool_head; struct pagepool_page_r *pool_tail; struct ppll { struct pagepool_ptr_r chunk; struct ppll *snext; struct ppll *lnext; } *frsiz_head; struct ppll *frsiz_tail; struct ppll *frloc_head; struct ppll *frloc_tail; unsigned long ncoal; } *

variable_types:
size
unsigned long

variable_types: struct pagepool_ptr_r { unsigned short pidx; unsigned short poff; unsigned short size; }


decompiled_code:
unsigned __int64 __fastcall pp_free(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
v2[2] = 0LL;
*(_DWORD *)v2 = a2;
v2[1] = 0LL;
*((_WORD *)v2 + 2) = WORD2(a2);
return pp_ll_add(a1, (unsigned __int16 *)v2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x18uLL);
v2[2] = 0LL;
*(_DWORD *)v2 = a2;
v2[1] = 0LL;
*((_WORD *)v2 + 2) = WORD2(a2);
return func4(a1, (unsigned __int16 *)v2);
}

original_code:
void pp_free( pagepool *pp, pgpp chunk )
{
  struct ppll *pll, *prev, *npll;
  npll = malloc(sizeof(struct ppll));
  npll->chunk = chunk;
  npll->snext = npll->lnext = ((void *)0);
  pp_ll_add(pp, npll);
  return;
}

canonical_original_code:
void pp_free(struct pagepool_r *pp, struct pagepool_ptr_r chunk)
{
  struct ppll *pll; struct ppll *prev; struct ppll *npll;
  npll = malloc(sizeof(struct ppll));
  npll->chunk = chunk;
  npll->snext = npll->lnext = ((void *)0);
  pp_ll_add(pp, npll);
  return;
}

variable_types:
chunk
struct pagepool_ptr_r


decompiled_code:
__int64 __fastcall ilog2(unsigned int a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 > 1 )
{
do
{
a1 >>= 1;
result = (unsigned int)(result + 1);
}
while ( a1 != 1 );
}
return result;
}

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

result = 0LL;
if ( a1 > 1 )
{
do
{
a1 >>= 1;
result = (unsigned int)(result + 1);
}
while ( a1 != 1 );
}
return result;
}

original_code:
unsigned int ilog2( unsigned int x ) {
  int i;
  for (i=0;x>1;++i)
    x = x >> 1;
  return i;
}

canonical_original_code:
unsigned int ilog2(unsigned int x) {
  int i;
  for (i=0;x>1;++i)
    x = x >> 1;
  return i;
}

variable_types:
x
unsigned int

variable_types: i int


original_code:
uint32_t hash32shift(uint32_t key) {
  key = ~key + (key << 15);
  key = key ^ (key >> 12);
  key = key + (key << 2);
  key = key ^ (key >> 4);
  key = key * 2057;
  key = key ^ (key >> 16);
  return key;
}

canonical_original_code:
unsigned int hash32shift(unsigned int key) {
  key = ~key + (key << 15);
  key = key ^ (key >> 12);
  key = key + (key << 2);
  key = key ^ (key >> 4);
  key = key * 2057;
  key = key ^ (key >> 16);
  return key;
}

variable_types:
key
unsigned int


original_code:
uint64_t hash64shift(uint64_t key) {
  key = (~key) + (key << 21);
  key = key ^ (key >> 24);
  key = (key + (key << 3)) + (key << 8);
  key = key ^ (key >> 14);
  key = (key + (key << 2)) + (key << 4);
  key = key ^ (key >> 28);
  key = key + (key << 31);
  return key;
}

canonical_original_code:
unsigned long hash64shift(unsigned long key) {
  key = (~key) + (key << 21);
  key = key ^ (key >> 24);
  key = (key + (key << 3)) + (key << 8);
  key = key ^ (key >> 14);
  key = (key + (key << 2)) + (key << 4);
  key = key ^ (key >> 28);
  key = key + (key << 31);
  return key;
}

variable_types:
key
unsigned long

return_type: unsigned long


original_code:
uint32_t hash6432shift(uint64_t key) {
  key = (~key) + (key << 18);
  key = key ^ (key >> 31);
  key = key * 21;
  key = key ^ (key >> 11);
  key = key + (key << 6);
  key = key ^ (key >> 22);
  return (uint32_t) key;
}

canonical_original_code:
unsigned int hash6432shift(unsigned long key) {
  key = (~key) + (key << 18);
  key = key ^ (key >> 31);
  key = key * 21;
  key = key ^ (key >> 11);
  key = key + (key << 6);
  key = key ^ (key >> 22);
  return (unsigned int) key;
}


original_code:
void vbyte_add( struct vbyte_r *vr, const uint32_t *iv, unsigned int vlen )
{
  unsigned int char7bit = 0x80, d, m;
  int i, j;
  uint32_t u;
  unsigned char *q;
  for (i=0; i<vlen; ++i) {
    u = iv[i];
    do {
      if (vr->len == vr->size) {
 vr->size = (vr->size) ? (2*vr->size) : 16;
 q = malloc(sizeof(unsigned char)*vr->size);
 if (vr->v) {
   memcpy(q, vr->v, sizeof(unsigned char)*vr->len);
   free(vr->v);
 }
 vr->v = q;
      }
      m = u%char7bit;
      vr->v[vr->len] = (m << 1);
      if ((u = u/char7bit)) {
 vr->v[vr->len] |= 0x1;
      }
      ++vr->len;
    } while (u!=0);
  }
}

canonical_original_code:
void vbyte_add(struct vbyte_r *vr, unsigned int *iv, unsigned int vlen)
{
  unsigned int char7bit = 0x80; unsigned int d; unsigned int m;
  int i; int j;
  unsigned int u;
  unsigned char *q;
  for (i=0; i<vlen; ++i) {
    u = iv[i];
    do {
      if (vr->len == vr->size) {
 vr->size = (vr->size) ? (2*vr->size) : 16;
 q = malloc(sizeof(unsigned char)*vr->size);
 if (vr->v) {
   memcpy(q, vr->v, sizeof(unsigned char)*vr->len);
   free(vr->v);
 }
 vr->v = q;
      }
      m = u%char7bit;
      vr->v[vr->len] = (m << 1);
      if ((u = u/char7bit)) {
 vr->v[vr->len] |= 0x1;
      }
      ++vr->len;
    } while (u!=0);
  }
}

variable_types: struct vbyte_r { unsigned int len; unsigned int size; unsigned char *v; } *

variable_types:
iv
unsigned int *

variable_types:
vlen
unsigned int

variable_types:
d
unsigned int

variable_types:
m
unsigned int

variable_types: j int

variable_types:
u
unsigned int

variable_types:
q
unsigned char *


decompiled_code:
__int64 __fastcall vbyte_expand_cb(__int64 a1, __int64 (__fastcall *a2)(__int64, _QWORD, __int64), __int64 a3)
{
unsigned int v3; // er9
__int64 v6; // rdx
int v7; // er13
unsigned int v8; // er8
_BYTE *v9; // rsi
char v10; // cl
__int64 result; // rax

v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
v6 = 0LL;
do
{
v7 = v6;
v8 = 0;
if ( (unsigned int)v6 < v3 )
{
v8 = 0;
v9 = (_BYTE *)(*(_QWORD *)(a1 + 8) + (int)v6);
v10 = 0;
while ( 1 )
{
v7 = v6;
v6 = (unsigned int)(v6 + 1);
result = (unsigned __int8)(*v9 >> 1) << v10;
v8 |= result;
if ( (*v9 & 1) == 0 )
break;
v10 += 7;
++v9;
if ( (unsigned int)v6 >= v3 )
{
v7 = v6;
break;
}
}
}
if ( a2 )
{
result = a2(a3, v8, v6);
v3 = *(_DWORD *)a1;
}
v6 = (unsigned int)(v7 + 1);
}
while ( v3 > (unsigned int)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 (__fastcall *a2)(__int64, _QWORD, __int64), __int64 a3)
{
unsigned int v3; // er9
__int64 v6; // rdx
int v7; // er13
unsigned int v8; // er8
_BYTE *v9; // rsi
char v10; // cl
__int64 result; // rax

v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
{
v6 = 0LL;
do
{
v7 = v6;
v8 = 0;
if ( (unsigned int)v6 < v3 )
{
v8 = 0;
v9 = (_BYTE *)(*(_QWORD *)(a1 + 8) + (int)v6);
v10 = 0;
while ( 1 )
{
v7 = v6;
v6 = (unsigned int)(v6 + 1);
result = (unsigned __int8)(*v9 >> 1) << v10;
v8 |= result;
if ( (*v9 & 1) == 0 )
break;
v10 += 7;
++v9;
if ( (unsigned int)v6 >= v3 )
{
v7 = v6;
break;
}
}
}
if ( a2 )
{
result = a2(a3, v8, v6);
v3 = *(_DWORD *)a1;
}
v6 = (unsigned int)(v7 + 1);
}
while ( v3 > (unsigned int)v6 );
}
return result;
}

original_code:
void vbyte_expand_cb( struct vbyte_r *vr, void (*cb)(void *, uint32_t), void *p )
{
  int i, rshft;
  uint32_t u;
  for (i=0; i<vr->len; ++i) {
    for (u=0, rshft=0; i<vr->len;++i, rshft+=7) {
      u |= ((vr->v[i] >> 1) << rshft);
      if ((vr->v[i] & 0x1) == 0)
 break;
    }
    if (cb)
      cb(p, u);
  }
}

canonical_original_code:
void vbyte_expand_cb(struct vbyte_r *vr, void (*cb)(void *, unsigned int), void *p)
{
  int i; int rshft;
  unsigned int u;
  for (i=0; i<vr->len; ++i) {
    for (u=0, rshft=0; i<vr->len;++i, rshft+=7) {
      u |= ((vr->v[i] >> 1) << rshft);
      if ((vr->v[i] & 0x1) == 0)
 break;
    }
    if (cb)
      cb(p, u);
  }
}

variable_types:
cb
void (*)(void *, unsigned int)

variable_types:
p
void *

variable_types: rshft int

user_defined_types: struct vbyte_r { unsigned int len; unsigned int size; unsigned char *v; }


original_code:
int vbyte_expand( struct vbyte_r *vr, uint32_t desc[], unsigned int dlen)
{
  int i, rshft;
  uint32_t u;
  for (dlen=i=0; i<vr->len; ++i) {
    for (u=0, rshft=0; i<vr->len;++i, rshft+=7) {
      u |= ((vr->v[i] >> 1) << rshft);
      if ((vr->v[i] & 0x1) == 0)
 break;
    }
    desc[dlen++] = u;
  }
  return dlen;
}

canonical_original_code:
int vbyte_expand(struct vbyte_r *vr, unsigned int desc[], unsigned int dlen)
{
  int i; int rshft;
  unsigned int u;
  for (dlen=i=0; i<vr->len; ++i) {
    for (u=0, rshft=0; i<vr->len;++i, rshft+=7) {
      u |= ((vr->v[i] >> 1) << rshft);
      if ((vr->v[i] & 0x1) == 0)
 break;
    }
    desc[dlen++] = u;
  }
  return dlen;
}

variable_types:
desc
unsigned int []

variable_types:
dlen
unsigned int

return_type: int


original_code:
int vbyte_pair_dist( unsigned int dist, int pos, struct vbyte_r *vrl, struct vbyte_r *vrr )
{
  int i, j, i0, j0, rshft;
  uint32_t l, r;
  for (i0=j0=-1, i=j=0; (i<vrl->len)&&(j<vrr->len); i+=(l<=r), j+=(r<=l)) {
    if (i!=i0) {
      for (l=0, rshft=0; (i<vrl->len)&&(vrl->v[i]&0x1); ++i, rshft+=7)
 l |= ((vrl->v[i] >> 1) << rshft);
      l |= ((vrl->v[i] >> 1) << rshft);
      i0 = i;
    }
    if (j!=j0) {
      for (r=0, rshft=0; (j<vrr->len)&&(vrr->v[j]&0x1); ++j, rshft+=7)
 r |= ((vrr->v[j] >> 1) << rshft);
      r |= ((vrr->v[j] >> 1) << rshft);
      j0 = j;
    }
    if (pos) {
      if ((r>l) && ((r-l)<=dist))
 return 1;
    }
    else {
      if (abs((r-l))<=dist)
 return 1;
    }
  }
  return 0;
}

canonical_original_code:
int vbyte_pair_dist(unsigned int dist, int pos, struct vbyte_r *vrl, struct vbyte_r *vrr)
{
  int i; int j; int i0; int j0; int rshft;
  unsigned int l; unsigned int r;
  for (i0=j0=-1, i=j=0; (i<vrl->len)&&(j<vrr->len); i+=(l<=r), j+=(r<=l)) {
    if (i!=i0) {
      for (l=0, rshft=0; (i<vrl->len)&&(vrl->v[i]&0x1); ++i, rshft+=7)
 l |= ((vrl->v[i] >> 1) << rshft);
      l |= ((vrl->v[i] >> 1) << rshft);
      i0 = i;
    }
    if (j!=j0) {
      for (r=0, rshft=0; (j<vrr->len)&&(vrr->v[j]&0x1); ++j, rshft+=7)
 r |= ((vrr->v[j] >> 1) << rshft);
      r |= ((vrr->v[j] >> 1) << rshft);
      j0 = j;
    }
    if (pos) {
      if ((r>l) && ((r-l)<=dist))
 return 1;
    }
    else {
      if (abs((r-l))<=dist)
 return 1;
    }
  }
  return 0;
}

variable_types:
dist
unsigned int

variable_types: pos int

variable_types:
vrr
struct vbyte_r *

variable_types:
l
unsigned int

variable_types:
r
unsigned int


original_code:
int pair_dist( int dist, const int p[], int plen, const int q[], int qlen )
{
  int i, j, l, r;
  for (i=j=0; (i<plen)&&(j<qlen); i+=(int)(l<=r), j+=(int)(r<=l)) {
    l = p[i];
    r = q[j];
    if (abs((l-r)) <= dist)
      return 1;
  }
  return 0;
}

canonical_original_code:
int pair_dist(int dist, int p[], int plen, int q[], int qlen)
{
  int i; int j; int l; int r;
  for (i=j=0; (i<plen)&&(j<qlen); i+=(int)(l<=r), j+=(int)(r<=l)) {
    l = p[i];
    r = q[j];
    if (abs((l-r)) <= dist)
      return 1;
  }
  return 0;
}

variable_types: dist int

variable_types:
p
int []

variable_types: plen int

variable_types:
q
int []

variable_types: qlen int

variable_types: i int

variable_types: l int

variable_types: r int


original_code:
void merge_eq( int *p, int plen, int *q, int qlen, int *z)
{
  int i, j, k;
  for (k=i=j=0; (i<plen)&&(j<qlen); ) {
    if (p[i] < q[j]) {
      ++i;
    }
    else if (q[j] < p[i]) {
      ++j;
    }
    else {
      z[k++] = p[i++];
      ++j;
    }
  }
}

canonical_original_code:
void merge_eq(int *p, int plen, int *q, int qlen, int *z)
{
  int i; int j; int k;
  for (k=i=j=0; (i<plen)&&(j<qlen); ) {
    if (p[i] < q[j]) {
      ++i;
    }
    else if (q[j] < p[i]) {
      ++j;
    }
    else {
      z[k++] = p[i++];
      ++j;
    }
  }
}

variable_types:
p
int *

variable_types:
q
int *

variable_types:
z
int *

variable_types: j int

variable_types: k int


decompiled_code:
__int64 __fastcall htab_init(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 v4; // rcx
const char *v5; // rax
__int64 v6; // rax
__int64 v7; // rdi
void *v8; // rax

v2 = a2;
if ( !a2 )
v2 = 802913LL;
v4 = 53LL;
v5 = "a";
while ( v4 <= v2 )
{
v4 = *(int *)v5;
v5 += 4;
if ( (int)v4 <= 0 )
goto LABEL_7;
}
*(_QWORD *)(a1 + 40) = v4;
fprintf(stderr, "Requested size: %zu Actual size: %zu\n", v2, v4);
LABEL_7:
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
v6 = fnv_32_str("Epsum factorial non deposit quid", 2166136261LL);
v7 = *(_QWORD *)(a1 + 40);
*(_QWORD *)(a1 + 24) = v6;
v8 = calloc(16 * v7, 1uLL);
*(_QWORD *)(a1 + 48) = v8;
return (unsigned int)-(v8 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 v4; // rcx
const char *v5; // rax
__int64 v6; // rax
__int64 v7; // rdi
void *v8; // rax

v2 = a2;
if ( !a2 )
v2 = 802913LL;
v4 = 53LL;
v5 = "a";
while ( v4 <= v2 )
{
v4 = *(int *)v5;
v5 += 4;
if ( (int)v4 <= 0 )
goto LABEL_7;
}
*(_QWORD *)(a1 + 40) = v4;
fprintf(stderr, "Requested size: %zu Actual size: %zu\n", v2, v4);
LABEL_7:
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
v6 = fnv_32_str("Epsum factorial non deposit quid", 2166136261LL);
v7 = *(_QWORD *)(a1 + 40);
*(_QWORD *)(a1 + 24) = v6;
v8 = calloc(16 * v7, 1uLL);
*(_QWORD *)(a1 + 48) = v8;
return (unsigned int)-(v8 == 0LL);
}

original_code:
int htab_init( htab *ht, size_t size ) {
  int i;
  size_t sizreq = (size) ? size : 802913;
  for (i=0; hsize_primes[i] > 0; ++i) {
    if (hsize_primes[i] > sizreq) {
      ht->size = hsize_primes[i];
      fprintf(stderr,"Requested size: %zu  Actual size: %zu\n", sizreq, ht->size);
      break;
    }
  }
  memset(&ht->stats, '\0', sizeof(struct htab_stats));
  ht->hash2_init_basis = fnv_32_str("Epsum factorial non deposit quid", ((Fnv32_t)0x811c9dc5));
  if ((ht->tab = malloc(sizeof(hentry)*ht->size))) {
    memset(ht->tab, '\0', sizeof(hentry)*ht->size);
    return 0;
  }
  return -1;
}

canonical_original_code:
int htab_init(struct htab_r *ht, unsigned long size) {
  int i;
  unsigned long sizreq = (size) ? size : 802913;
  for (i=0; hsize_primes[i] > 0; ++i) {
    if (hsize_primes[i] > sizreq) {
      ht->size = hsize_primes[i];
      fprintf(stderr,"Requested size: %zu  Actual size: %zu\n", sizreq, ht->size);
      break;
    }
  }
  memset(&ht->stats, '\0', sizeof(struct htab_stats));
  ht->hash2_init_basis = fnv_32_str("Epsum factorial non deposit quid", ((unsigned long)0x811c9dc5));
  if ((ht->tab = malloc(sizeof(hentry)*ht->size))) {
    memset(ht->tab, '\0', sizeof(hentry)*ht->size);
    return 0;
  }
  return -1;
}

variable_types: struct htab_r { struct htab_stats { unsigned int resize; unsigned int entrycnt; unsigned int reusecnt; unsigned long probecnt; } stats; unsigned long hash2_init_basis; char *free_slot; unsigned long size; struct hentry_r { void *v; char *key; } *tab; } *

variable_types:
size
unsigned long

variable_types:
sizreq
unsigned long

user_defined_types: struct htab_r { struct htab_stats stats; unsigned long hash2_init_basis; char *free_slot; unsigned long size; struct hentry_r *tab; }


decompiled_code:
void __fastcall htab_free(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)(a1 + 48);
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 48) = 0LL;
}
}

original_code:
void htab_free( htab *ht ) {
  if (ht->tab) {
    free(ht->tab);
    ht->tab = ((void *)0);
  }
}

canonical_original_code:
void htab_free(struct htab_r *ht) {
  if (ht->tab) {
    free(ht->tab);
    ht->tab = ((void *)0);
  }
}

user_defined_types: struct htab_stats { unsigned int resize; unsigned int entrycnt; unsigned int reusecnt; unsigned long probecnt; }


decompiled_code:
__int64 __fastcall htab_find(_QWORD *a1, const char *a2, int *a3)
{
int v4; // eax
__int64 v5; // r8

v4 = htab_find_idx_localalias(a1, a2);
if ( a3 )
*a3 = v4;
v5 = 0LL;
if ( v4 >= 0 )
v5 = *(_QWORD *)(a1[6] + 16LL * v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, const char *a2, int *a3)
{
int v4; // eax
__int64 v5; // r8

v4 = func2(a1, a2);
if ( a3 )
*a3 = v4;
v5 = 0LL;
if ( v4 >= 0 )
v5 = *(_QWORD *)(a1[6] + 16LL * v4);
return v5;
}

original_code:
void *htab_find( htab *ht, char const *key, int *hidx ) {
  int ih = htab_find_idx(ht, key);
  if (hidx)
    *hidx = ih;
  return (ih >= 0) ? ht->tab[ih].v : ((void *)0);
}

canonical_original_code:
void *htab_find(struct htab_r *ht, char *key, int *hidx) {
  int ih = htab_find_idx(ht, key);
  if (hidx)
    *hidx = ih;
  return (ih >= 0) ? ht->tab[ih].v : ((void *)0);
}

variable_types:
key
char *

variable_types:
hidx
int *

variable_types: ih int

return_type: void *


original_code:
int htab_insert( htab *ht, char const *key, void *p ) {
  Fnv32_t h = fnv_32_str((char*)key, ((Fnv32_t)0x811c9dc5));
  Fnv32_t probeinc;
  int ih, jempty = -1, j;
  unsigned int idx = h % ht->size;
  int nprobe = 0;
  probeinc = fnv_32_str((char *)key, ht->hash2_init_basis);
  for (j=0, ih=(h%ht->size); ht->tab[ih].key; ++j, ih=((h+j*probeinc)%ht->size)) {
    ((void) sizeof (((ih >= 0) && (ih<ht->size)) ? 1 : 0), __extension__ ({ if ((ih >= 0) && (ih<ht->size)) ; else __assert_fail ("(ih >= 0) && (ih<ht->size)", "htab.c", 112, __extension__ __PRETTY_FUNCTION__); }));
    if (!strcmp((char*)ht->tab[ih].key, (char*)key)) {
      ht->stats.probecnt += nprobe;
      return ih;
    }
    if ((jempty < 0) && (ht->tab[ih].key == htab_sentinel)) {
      printf("key: %s reuse slot@%d  table fill:[%u/%zu]\n", key, ih, ht->stats.entrycnt, ht->size);
      ht->stats.reusecnt++;
      jempty = ih;
    }
    nprobe++;
  }
  if (jempty < 0) {
    jempty = ih;
  }
  ht->stats.entrycnt++;
  ht->stats.probecnt += nprobe;
  ((void) sizeof (((jempty >= 0) && (jempty < ht->size)) ? 1 : 0), __extension__ ({ if ((jempty >= 0) && (jempty < ht->size)) ; else __assert_fail ("(jempty >= 0) && (jempty < ht->size)", "htab.c", 135, __extension__ __PRETTY_FUNCTION__); }));
  ht->tab[jempty].key = key;
  ht->tab[jempty].v = p;
  return jempty;
}

canonical_original_code:
int htab_insert(struct htab_r *ht, char *key, void *p) {
  unsigned long h = fnv_32_str((char*)key, ((Fnv32_t)0x811c9dc5));
  unsigned long probeinc;
  int ih; int jempty = -1; int j;
  unsigned int idx = h % ht->size;
  int nprobe = 0;
  probeinc = fnv_32_str((char *)key, ht->hash2_init_basis);
  for (j=0, ih=(h%ht->size); ht->tab[ih].key; ++j, ih=((h+j*probeinc)%ht->size)) {
    ((void) sizeof (((ih >= 0) && (ih<ht->size)) ? 1 : 0), __extension__ ({ if ((ih >= 0) && (ih<ht->size)) ; else __assert_fail ("(ih >= 0) && (ih<ht->size)", "htab.c", 112, __extension__ __PRETTY_FUNCTION__); }));
    if (!strcmp((char *)ht->tab[ih].key, (char *)key)) {
      ht->stats.probecnt += nprobe;
      return ih;
    }
    if ((jempty < 0) && (ht->tab[ih].key == htab_sentinel)) {
      printf("key: %s reuse slot@%d  table fill:[%u/%zu]\n", key, ih, ht->stats.entrycnt, ht->size);
      ht->stats.reusecnt++;
      jempty = ih;
    }
    nprobe++;
  }
  if (jempty < 0) {
    jempty = ih;
  }
  ht->stats.entrycnt++;
  ht->stats.probecnt += nprobe;
  ((void) sizeof (((jempty >= 0) && (jempty < ht->size)) ? 1 : 0), __extension__ ({ if ((jempty >= 0) && (jempty < ht->size)) ; else __assert_fail ("(jempty >= 0) && (jempty < ht->size)", "htab.c", 135, __extension__ __PRETTY_FUNCTION__); }));
  ht->tab[jempty].key = key;
  ht->tab[jempty].v = p;
  return jempty;
}

variable_types:
p
void *

variable_types:
h
unsigned long

variable_types:
probeinc
unsigned long

variable_types: jempty int

variable_types:
idx
unsigned int

variable_types: nprobe int


original_code:
int htab_update( htab *ht, char const *key, void *p ) {
  Fnv32_t h = fnv_32_str((char*)key, ((Fnv32_t)0x811c9dc5));
  int probeinc = 1, ih, jempty = -1, j;
  unsigned int idx = h % ht->size;
  int nprobe = 0;
  probeinc = fnv_32_str((char *)key, ht->hash2_init_basis);
  for (j=0, ih=(h%ht->size); ht->tab[ih].key; ++j, ih=((h+j*probeinc)%ht->size)) {
    if (!strcmp((char*)ht->tab[ih].key, (char*)key)) {
      ht->tab[ih].v = p;
      ht->stats.probecnt += nprobe;
      return ih;
    }
    nprobe++;
  }
  return -1;
}

canonical_original_code:
int htab_update(struct htab_r *ht, char *key, void *p) {
  unsigned long h = fnv_32_str((char*)key, ((Fnv32_t)0x811c9dc5));
  int probeinc = 1; int ih; int jempty = -1; int j;
  unsigned int idx = h % ht->size;
  int nprobe = 0;
  probeinc = fnv_32_str((char *)key, ht->hash2_init_basis);
  for (j=0, ih=(h%ht->size); ht->tab[ih].key; ++j, ih=((h+j*probeinc)%ht->size)) {
    if (!strcmp((char *)ht->tab[ih].key, (char *)key)) {
      ht->tab[ih].v = p;
      ht->stats.probecnt += nprobe;
      return ih;
    }
    nprobe++;
  }
  return -1;
}

variable_types: probeinc int


decompiled_code:
__int64 __fastcall htab_update_index(__int64 a1, unsigned int a2, __int64 a3, const char *a4)
{
__int64 v5; // rbx

v5 = *(_QWORD *)(a1 + 48) + 16LL * a2;
if ( a4 && strcmp(*(const char **)(v5 + 8), a4) )
_assert_fail("(strcmp((char*)ht->tab[ih].key, key)==0)", "htab.c", 0xA4u, "htab_update_index");
*(_QWORD *)v5 = a3;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3, const char *a4)
{
__int64 v5; // rbx

v5 = *(_QWORD *)(a1 + 48) + 16LL * a2;
if ( a4 && strcmp(*(const char **)(v5 + 8), a4) )
_assert_fail("(strcmp((char*)ht->tab[ih].key, key)==0)", "htab.c", 0xA4u, "htab_update_index");
*(_QWORD *)v5 = a3;
return a2;
}

original_code:
int htab_update_index( htab *ht, unsigned int ih, void *p, char const *key ) {
  if (key != ((void *)0)) {
    ((void) sizeof (((strcmp((char*)ht->tab[ih].key, key)==0)) ? 1 : 0), __extension__ ({ if ((strcmp((char*)ht->tab[ih].key, key)==0)) ; else __assert_fail ("(strcmp((char*)ht->tab[ih].key, key)==0)", "htab.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  }
  ht->tab[ih].v = p;
  return ih;
}

canonical_original_code:
int htab_update_index(struct htab_r *ht, unsigned int ih, void *p, char *key) {
  if (key != ((void *)0)) {
    ((void) sizeof (((strcmp((char *)ht->tab[ih].key, key)==0)) ? 1 : 0), __extension__ ({ if ((strcmp((char *)ht->tab[ih].key, key)==0)) ; else __assert_fail ("(strcmp((char*)ht->tab[ih].key, key)==0)", "htab.c", 164, __extension__ __PRETTY_FUNCTION__); }));
  }
  ht->tab[ih].v = p;
  return ih;
}

variable_types:
ih
unsigned int


decompiled_code:
void __fastcall htab_iterator(__int64 a1, void (__fastcall *a2)(void *, _QWORD))
{
unsigned __int64 v3; // rbx
_QWORD *v4; // rax
void *v5; // rdi

if ( *(_QWORD *)(a1 + 40) )
{
v3 = 0LL;
do
{
v4 = (_QWORD *)(*(_QWORD *)(a1 + 48) + 16 * v3);
v5 = (void *)v4[1];
if ( v5 )
{
if ( v5 != &htab_sentinel )
a2(v5, *v4);
}
++v3;
}
while ( *(_QWORD *)(a1 + 40) > v3 );
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, void (__fastcall *a2)(void *, _QWORD))
{
unsigned __int64 v3; // rbx
_QWORD *v4; // rax
void *v5; // rdi

if ( *(_QWORD *)(a1 + 40) )
{
v3 = 0LL;
do
{
v4 = (_QWORD *)(*(_QWORD *)(a1 + 48) + 16 * v3);
v5 = (void *)v4[1];
if ( v5 )
{
if ( v5 != &htab_sentinel )
a2(v5, *v4);
}
++v3;
}
while ( *(_QWORD *)(a1 + 40) > v3 );
}
}

original_code:
void htab_iterator( htab *ht, void (*cb)( void *, void * ) )
{
  int ih;
  for (ih=0; ih<ht->size; ++ih) {
    if ((ht->tab[ih].key) && (ht->tab[ih].key != htab_sentinel)) {
      cb((void*)ht->tab[ih].key, (void*)ht->tab[ih].v);
    }
  }
}

canonical_original_code:
void htab_iterator(struct htab_r *ht, void (*cb)(void *, void *))
{
  int ih;
  for (ih=0; ih<ht->size; ++ih) {
    if ((ht->tab[ih].key) && (ht->tab[ih].key != htab_sentinel)) {
      cb((void *)ht->tab[ih].key, (void *)ht->tab[ih].v);
    }
  }
}

variable_types:
cb
void (*)(void *, void *)


decompiled_code:
__int64 __fastcall fnv_32_buf(unsigned __int8 *a1, __int64 a2, __int64 a3)
{
unsigned __int8 *v3; // r8
__int64 result; // rax

v3 = &a1[a2];
result = a3;
if ( a1 < &a1[a2] )
{
do
result = (16777619 * result) ^ *a1++;
while ( v3 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, __int64 a2, __int64 a3)
{
unsigned __int8 *v3; // r8
__int64 result; // rax

v3 = &a1[a2];
result = a3;
if ( a1 < &a1[a2] )
{
do
result = (16777619 * result) ^ *a1++;
while ( v3 != a1 );
}
return result;
}

original_code:
Fnv32_t
fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
{
  unsigned char *bp = (unsigned char *)buf;
  unsigned char *be = bp + len;
  while (bp < be) {
    hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
    hval ^= (Fnv32_t)*bp++;
  }
  return hval;
}

canonical_original_code:
unsigned long fnv_32_buf(void *buf, unsigned long len, unsigned long hval)
{
  unsigned char *bp = (unsigned char *)buf;
  unsigned char *be = bp + len;
  while (bp < be) {
    hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
    hval ^= (Fnv32_t)*bp++;
  }
  return hval;
}

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types:
hval
unsigned long

variable_types:
bp
unsigned char *

variable_types:
be
unsigned char *


decompiled_code:
__int64 __fastcall fnv_32_str(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 v2; // cl
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rax

v2 = *a1;
for ( result = a2; *a1; result = v4 ^ v5 )
{
++a1;
v4 = 16777619 * result;
v5 = v2;
v2 = *a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 v2; // cl
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rax

v2 = *a1;
for ( result = a2; *a1; result = v4 ^ v5 )
{
++a1;
v4 = 16777619 * result;
v5 = v2;
v2 = *a1;
}
return result;
}

original_code:
Fnv32_t
fnv_32_str(char *str, Fnv32_t hval)
{
  unsigned char *s = (unsigned char *)str;
  while (*s) {
    hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
    hval ^= (Fnv32_t)*s++;
  }
  return hval;
}

canonical_original_code:
unsigned long fnv_32_str(char *str, unsigned long hval)
{
  unsigned char *s = (unsigned char *)str;
  while (*s) {
    hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
    hval ^= (Fnv32_t)*s++;
  }
  return hval;
}

variable_types:
str
char *

variable_types:
s
unsigned char *


decompiled_code:
int __fastcall trie_backtrace(_QWORD *a1)
{
_DWORD *v1; // r12
__int64 v2; // rdx
__int64 v3; // rdx
int v4; // eax
char *v5; // rbx
__int64 v6; // rbp
char v7; // di

v1 = a1;
puts(" BTR ---");
v2 = *a1;
if ( *a1 )
{
do
{
printf("%c -- ", *(_BYTE *)(v2 + v1[2] + 2) & 0x7F);
v3 = *(_QWORD *)v1;
v4 = *(unsigned __int8 *)(*(_QWORD *)v1 + 1LL);
if ( (_BYTE)v4 )
{
v5 = (char *)(v3 + 2);
v6 = v3 + (unsigned int)(v4 - 1) + 3;
do
{
v7 = *v5++;
putchar(v7 & 0x7F);
}
while ( v5 != (char *)v6 );
}
v1 -= 4;
putchar(10);
v2 = *(_QWORD *)v1;
}
while ( *(_QWORD *)v1 );
}
return putchar(10);
}

original_code:
void trie_backtrace( trie_btr *pstk )
{
  int i, n;
  char *p;
  printf("  BTR ---\n");
  for (; pstk->p!=((void *)0); --pstk) {
    printf("%c  --  ", (pstk->p[2+pstk->idx] & 0x7f));
    n = (unsigned char)pstk->p[1];
    p = pstk->p+2;
    for (i=0; i<n; ++i) {
      printf("%c", (p[i]&0x7f));
    }
    printf("\n");
  }
  printf("\n");
}

canonical_original_code:
void trie_backtrace(struct trie_backtrace_r *pstk)
{
  int i; int n;
  char *p;
  printf("  BTR ---\n");
  for (; pstk->p!=((void *)0); --pstk) {
    printf("%c  --  ", (pstk->p[2+pstk->idx] & 0x7f));
    n = (unsigned char)pstk->p[1];
    p = pstk->p+2;
    for (i=0; i<n; ++i) {
      printf("%c", (p[i]&0x7f));
    }
    printf("\n");
  }
  printf("\n");
}

variable_types: struct trie_backtrace_r { char *p; int idx; } *

variable_types: i int

variable_types: n int

variable_types:
p
char *


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

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

original_code:
int trie_validate( char *tr )
{
  return 0;
}

canonical_original_code:
int trie_validate(char *tr)
{
  return 0;
}

variable_types:
tr
char *


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

if ( *(_BYTE *)a1 == 0xFE )
result = 3 * (unsigned int)*(unsigned __int8 *)(a1 + 1) + 4;
else
result = (unsigned int)strlen((const char *)a1) + 1;
return result;
}

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

if ( *(_BYTE *)a1 == 0xFE )
result = 3 * (unsigned int)*(unsigned __int8 *)(a1 + 1) + 4;
else
result = (unsigned int)strlen((const char *)a1) + 1;
return result;
}

original_code:
unsigned int trie_fsize( const char *tr )
{
  unsigned int siz;
  if (*tr == '\xfe') {
    unsigned char nelt = *((unsigned char*)(tr+1));
    siz = sizeof(struct trie_elt)*nelt + sizeof(unsigned int);
  }
  else {
    siz = strlen(tr)+1;
  }
  return siz;
}

canonical_original_code:
unsigned int trie_fsize(char *tr)
{
  unsigned int siz;
  if (*tr == '\xfe') {
    unsigned char nelt = *((unsigned char*)(tr+1));
    siz = sizeof(struct trie_elt)*nelt + sizeof(unsigned int);
  }
  else {
    siz = strlen(tr)+1;
  }
  return siz;
}

variable_types:
siz
unsigned int

variable_types:
nelt
unsigned char

user_defined_types: struct trie_elt { char c; unsigned char nelt; struct { unsigned char eow; unsigned char isnode; } flags; }


original_code:
int dmetapool_init( struct dmeta_pool_r *dmp, size_t pagesize, unsigned int mxpagecnt )
{
  dmp->pagesize = (pagesize) ? pagesize : (8*1024);
  dmp->lpagelen = (mxpagecnt) ? mxpagecnt : 256;
  dmp->page_list = malloc(sizeof(struct dmeta_page_r *)*dmp->lpagelen);
  dmp->page_list[0].freep = dmp->page_list[0].base = malloc(sizeof(char)*dmp->pagesize);
  dmp->page_cnt = 1;
  return 0;
}

canonical_original_code:
int dmetapool_init(struct dmeta_pool_r *dmp, unsigned long pagesize, unsigned int mxpagecnt)
{
  dmp->pagesize = (pagesize) ? pagesize : (8*1024);
  dmp->lpagelen = (mxpagecnt) ? mxpagecnt : 256;
  dmp->page_list = malloc(sizeof(struct dmeta_page_r *)*dmp->lpagelen);
  dmp->page_list[0].freep = dmp->page_list[0].base = malloc(sizeof(char)*dmp->pagesize);
  dmp->page_cnt = 1;
  return 0;
}

variable_types: struct dmeta_pool_r { unsigned long pagesize; unsigned int lpagelen; struct dmeta_page_r { char *base; char *freep; } *page_list; unsigned int page_cnt; } *

variable_types:
pagesize
unsigned long

variable_types:
mxpagecnt
unsigned int

user_defined_types: struct dmeta_pool_r { unsigned long pagesize; unsigned int lpagelen; struct dmeta_page_r *page_list; unsigned int page_cnt; }


decompiled_code:
__int64 __fastcall dmetapool_insert_dmeta(__int64 a1, const void *a2, unsigned int a3)
{
size_t v3; // rbp
int v4; // ecx
size_t v5; // r9
_QWORD *v6; // rbx
void *v7; // r8
void *v9; // rax

v3 = a3;
v4 = *(_DWORD *)(a1 + 24);
v5 = *(_QWORD *)a1;
v6 = (_QWORD *)(*(_QWORD *)(a1 + 16) + 16LL * (unsigned int)(v4 - 1));
v7 = (void *)v6[1];
if ( (unsigned __int64)v7 + a3 - *v6 > *(_QWORD *)a1 )
{
*(_DWORD *)(a1 + 24) = v4 + 1;
v9 = malloc(v5);
v6[2] = v9;
v7 = v9;
v6[3] = v9;
v6 += 2;
}
memcpy(v7, a2, v3);
v6[1] += v3;
return 0LL;
}

original_code:
int dmetapool_insert_dmeta( struct dmeta_pool_r *dmp, void *dm, unsigned int dsize )
{
  struct dmeta_page_r *pcur = &(dmp->page_list[dmp->page_cnt-1]);
  if ((pcur->freep - pcur->base) + dsize > dmp->pagesize) {
    ++dmp->page_cnt;
    ++pcur;
    pcur->freep = pcur->base = malloc(sizeof(char)*dmp->pagesize);
  }
  memcpy(pcur->freep, dm, (dsize*sizeof(char)));
  pcur->freep += dsize;
  return 0;
}

canonical_original_code:
int dmetapool_insert_dmeta(struct dmeta_pool_r *dmp, void *dm, unsigned int dsize)
{
  struct dmeta_page_r *pcur = &(dmp->page_list[dmp->page_cnt-1]);
  if ((pcur->freep - pcur->base) + dsize > dmp->pagesize) {
    ++dmp->page_cnt;
    ++pcur;
    pcur->freep = pcur->base = malloc(sizeof(char)*dmp->pagesize);
  }
  memcpy(pcur->freep, dm, (dsize*sizeof(char)));
  pcur->freep += dsize;
  return 0;
}

variable_types:
dm
void *

variable_types:
dsize
unsigned int

variable_types: struct dmeta_page_r { char *base; char *freep; } *


fatal

repo: auchter/dwm-mail-mon

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
static void fatal(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
static void fatal(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

variable_types:
fmt
char *


repo: auditore/XendIP

decompiled_code:
__int64 __fastcall inet6_addr(const char *a1)
{
struct hostent *v1; // rax
__int64 result; // rax

v1 = gethostbyname2(a1, 10);
if ( v1 )
{
if ( v1->h_length == 16 )
{
result = **(_QWORD **)v1->h_addr_list;
}
else
{
fwrite("RIPNG: IPV6 address is the wrong size: defaulting to loopback", 1uLL, 0x3DuLL, stderr);
result = *(_QWORD *)in6addr_loopback.__u6_addr8;
}
}
else
{
fprintf(stderr, "RIPNG: Couldn't get address for %s defaulting to loopback", a1);
result = *(_QWORD *)in6addr_loopback.__u6_addr8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
struct hostent *v1; // rax
__int64 result; // rax

v1 = gethostbyname2(a1, 10);
if ( v1 )
{
if ( v1->h_length == 16 )
{
result = **(_QWORD **)v1->h_addr_list;
}
else
{
fwrite("RIPNG: IPV6 address is the wrong size: defaulting to loopback", 1uLL, 0x3DuLL, stderr);
result = *(_QWORD *)in6addr_loopback.__u6_addr8;
}
}
else
{
fprintf(stderr, "RIPNG: Couldn't get address for %s defaulting to loopback", a1);
result = *(_QWORD *)in6addr_loopback.__u6_addr8;
}
return result;
}

original_code:
static struct in6_addr inet6_addr(char *hostname) {
 struct hostent *host = gethostbyname2(hostname,10);
 struct in6_addr ret;
 if(host==((void *)0)) {
  fprintf(stderr,"RIPNG: Couldn't get address for %s defaulting to loopback",hostname);
  return in6addr_loopback;
 }
 if(host->h_length != sizeof(struct in6_addr)) {
  fprintf(stderr,"RIPNG: IPV6 address is the wrong size: defaulting to loopback");
  return in6addr_loopback;
 }
 memcpy(&ret,host->h_addr_list[0],sizeof(ret));
 return ret;
}

variable_types:
hostname
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


csum

decompiled_code:
__int64 __fastcall csum(unsigned __int16 *a1, int a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rcx
unsigned __int64 v4; // rax
__int64 v5; // rdx

if ( a2 <= 1 )
{
v3 = a1;
v4 = 0LL;
if ( a2 != 1 )
return 0xFFFFFFFFLL;
goto LABEL_5;
}
v2 = a2 - 2;
v3 = &a1[(v2 >> 1) + 1];
v4 = 0LL;
do
{
v5 = *a1++;
v4 += v5;
}
while ( a1 != v3 );
if ( v2 - 2 * (v2 >> 1) == 1 )
LABEL_5:
v4 += *(unsigned __int8 *)v3;
while ( v4 >> 16 )
v4 = (v4 >> 16) + (unsigned __int16)v4;
return (unsigned int)~(_DWORD)v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int16 *a1, int a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rcx
unsigned __int64 v4; // rax
__int64 v5; // rdx

if ( a2 <= 1 )
{
v3 = a1;
v4 = 0LL;
if ( a2 != 1 )
return 0xFFFFFFFFLL;
goto LABEL_5;
}
v2 = a2 - 2;
v3 = &a1[(v2 >> 1) + 1];
v4 = 0LL;
do
{
v5 = *a1++;
v4 += v5;
}
while ( a1 != v3 );
if ( v2 - 2 * (v2 >> 1) == 1 )
LABEL_5:
v4 += *(unsigned __int8 *)v3;
while ( v4 >> 16 )
v4 = (v4 >> 16) + (unsigned __int16)v4;
return (unsigned int)~(_DWORD)v4;
}

original_code:
u_int16_t csum (u_int16_t *packet, int packlen) {
 register unsigned long sum = 0;
 while (packlen > 1) {
  sum+= *(packet++);
  packlen-=2;
 }
 if (packlen > 0)
  sum += *(unsigned char *)packet;
 while (sum >> 16)
  sum = (sum & 0xffff) + (sum >> 16);
 return (u_int16_t) ~sum;
}

canonical_original_code:
unsigned int csum(unsigned int *packet, int packlen) {
 register unsigned long sum = 0;
 while (packlen > 1) {
  sum+= *(packet++);
  packlen-=2;
 }
 if (packlen > 0)
  sum += *(unsigned char *)packet;
 while (sum >> 16)
  sum = (sum & 0xffff) + (sum >> 16);
 return (unsigned int) ~sum;
}

variable_types:
packet
unsigned int *

variable_types: packlen int

variable_types:
sum
unsigned long


decompiled_code:
size_t __fastcall compact_string(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax
__int64 v3; // rcx
int v4; // esi
int i; // edx
int v6; // eax
size_t result; // rax
_BYTE *v8; // rsi
int v9; // ecx
int v10; // er8
int v11; // ecx

if ( *(_BYTE *)a1 != 48 )
return strlen((const char *)a1);
v1 = (unsigned int)*(char *)(a1 + 1);
if ( (*(_BYTE *)(a1 + 1) & 0xDF) != 88 )
{
v8 = (_BYTE *)(a1 + 1);
v9 = 0;
result = 0LL;
if ( !*(_BYTE *)(a1 + 1) )
goto LABEL_22;
while ( 1 )
{
if ( (unsigned __int8)(v1 - 48) > 7u )
{
fprintf(stderr, "Character %c invalid in octal data stream\n", v1);
return 0LL;
}
v11 = v1 + v9 - 48;
if ( (result & 3) == 3 )
{
++v8;
*(_BYTE *)a1 = v11;
v10 = result + 1;
++a1;
v1 = (unsigned int)(char)*v8;
v9 = 0;
if ( !*v8 )
{
LABEL_21:
result = (unsigned int)(((int)result + 4) >> 2);
LABEL_22:
*(_BYTE *)a1 = v9;
return result;
}
}
else
{
v1 = (unsigned int)(char)*++v8;
v9 = 4 * v11;
v10 = result + 1;
if ( !(_BYTE)v1 )
goto LABEL_21;
}
LODWORD(result) = v10;
}
}
v2 = *(unsigned __int8 *)(a1 + 2);
v3 = a1 + 2;
v4 = 0;
if ( !(_BYTE)v2 )
{
result = 0LL;
LABEL_26:
*(_BYTE *)a1 = v4;
return result;
}
for ( i = 0; ; ++i )
{
if ( (unsigned __int8)(v2 - 48) <= 9u )
{
v6 = v2 + v4 - 48;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 65) <= 5u )
{
v6 = v2 + v4 - 55;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 97) > 5u )
break;
v6 = v2 + v4 - 87;
LABEL_6:
v4 = 16 * v6;
if ( (i & 1) != 0 )
{
*(_BYTE *)a1 = v6;
v4 = 0;
++a1;
}
v2 = *(unsigned __int8 *)++v3;
if ( !(_BYTE)v2 )
{
result = (unsigned int)((i + 2) >> 1);
goto LABEL_26;
}
}
fprintf(stderr, "Character %c invalid in hex data stream\n", (unsigned int)(char)v2);
return 0LL;
}

canonical_decompiled_code:
size_t __fastcall func15(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax
__int64 v3; // rcx
int v4; // esi
int i; // edx
int v6; // eax
size_t result; // rax
_BYTE *v8; // rsi
int v9; // ecx
int v10; // er8
int v11; // ecx

if ( *(_BYTE *)a1 != 48 )
return strlen((const char *)a1);
v1 = (unsigned int)*(char *)(a1 + 1);
if ( (*(_BYTE *)(a1 + 1) & 0xDF) != 88 )
{
v8 = (_BYTE *)(a1 + 1);
v9 = 0;
result = 0LL;
if ( !*(_BYTE *)(a1 + 1) )
goto LABEL_22;
while ( 1 )
{
if ( (unsigned __int8)(v1 - 48) > 7u )
{
fprintf(stderr, "Character %c invalid in octal data stream\n", v1);
return 0LL;
}
v11 = v1 + v9 - 48;
if ( (result & 3) == 3 )
{
++v8;
*(_BYTE *)a1 = v11;
v10 = result + 1;
++a1;
v1 = (unsigned int)(char)*v8;
v9 = 0;
if ( !*v8 )
{
LABEL_21:
result = (unsigned int)(((int)result + 4) >> 2);
LABEL_22:
*(_BYTE *)a1 = v9;
return result;
}
}
else
{
v1 = (unsigned int)(char)*++v8;
v9 = 4 * v11;
v10 = result + 1;
if ( !(_BYTE)v1 )
goto LABEL_21;
}
LODWORD(result) = v10;
}
}
v2 = *(unsigned __int8 *)(a1 + 2);
v3 = a1 + 2;
v4 = 0;
if ( !(_BYTE)v2 )
{
result = 0LL;
LABEL_26:
*(_BYTE *)a1 = v4;
return result;
}
for ( i = 0; ; ++i )
{
if ( (unsigned __int8)(v2 - 48) <= 9u )
{
v6 = v2 + v4 - 48;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 65) <= 5u )
{
v6 = v2 + v4 - 55;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 97) > 5u )
break;
v6 = v2 + v4 - 87;
LABEL_6:
v4 = 16 * v6;
if ( (i & 1) != 0 )
{
*(_BYTE *)a1 = v6;
v4 = 0;
++a1;
}
v2 = *(unsigned __int8 *)++v3;
if ( !(_BYTE)v2 )
{
result = (unsigned int)((i + 2) >> 1);
goto LABEL_26;
}
}
fprintf(stderr, "Character %c invalid in hex data stream\n", (unsigned int)(char)v2);
return 0LL;
}

original_code:
int compact_string(char *data_out) {
 char *data_in = data_out;
 int i=0;
 if(*data_in=='0') {
  data_in++;
  if(*data_in=='x' || *data_in=='X') {
   char c='\0';
   data_in++;
   while(*data_in) {
    if(*data_in>='0' && *data_in<='9') {
     c+=*data_in-'0';
    } else if(*data_in>='A' && *data_in<='F') {
     c+=*data_in-'A'+10;
    } else if(*data_in>='a' && *data_in<='f') {
     c+=*data_in-'a'+10;
    } else {
     fprintf(stderr,"Character %c invalid in hex data stream\n",
         *data_in);
     return 0;
    }
    if( i&1) {
     *(data_out++)=c;
     c='\0';
    } else {
     c<<=4;
    }
    data_in++; i++;
   }
   *data_out=c;
   i++; i>>=1;
   return i;
  } else {
   char c='\0';
   while(*data_in) {
    if(*data_in>='0' && *data_in<='7') {
     c+=*data_in-'0';
    } else {
     fprintf(stderr,"Character %c invalid in octal data stream\n",
         *data_in);
     return 0;
    }
    if( (i&3) == 3 ) {
     *(data_out++)=c;
     c='\0';
    } else {
     c<<=2;
    }
    data_in++; i++;
   }
   *data_out=c;
   i+=3; i>>=2;
   return i;
  }
 } else {
  return strlen(data_in);
 }
}

canonical_original_code:
int compact_string(char *data_out) {
 char *data_in = data_out;
 int i = 0;
 if(*data_in=='0') {
  data_in++;
  if(*data_in=='x' || *data_in=='X') {
   char c = '\0';
   data_in++;
   while(*data_in) {
    if(*data_in>='0' && *data_in<='9') {
     c+=*data_in-'0';
    } else if(*data_in>='A' && *data_in<='F') {
     c+=*data_in-'A'+10;
    } else if(*data_in>='a' && *data_in<='f') {
     c+=*data_in-'a'+10;
    } else {
     fprintf(stderr,"Character %c invalid in hex data stream\n",
         *data_in);
     return 0;
    }
    if( i&1) {
     *(data_out++)=c;
     c='\0';
    } else {
     c<<=4;
    }
    data_in++; i++;
   }
   *data_out=c;
   i++; i>>=1;
   return i;
  } else {
   char c = '\0';
   while(*data_in) {
    if(*data_in>='0' && *data_in<='7') {
     c+=*data_in-'0';
    } else {
     fprintf(stderr,"Character %c invalid in octal data stream\n",
         *data_in);
     return 0;
    }
    if( (i&3) == 3 ) {
     *(data_out++)=c;
     c='\0';
    } else {
     c<<=2;
    }
    data_in++; i++;
   }
   *data_out=c;
   i+=3; i>>=2;
   return i;
  }
 } else {
  return strlen(data_in);
 }
}

variable_types: i int

variable_types: c char


initialize

decompiled_code:
_QWORD *initialize()
{
_QWORD *v0; // r12
void *v1; // rax

v0 = malloc(0x10uLL);
v1 = calloc(4uLL, 1uLL);
v0[1] = 4LL;
*v0 = v1;
return v0;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // r12
void *v1; // rax

v0 = malloc(0x10uLL);
v1 = calloc(4uLL, 1uLL);
v0[1] = 4LL;
*v0 = v1;
return v0;
}

original_code:
sendip_data *initialize(void) {
 sendip_data *ret = malloc(sizeof(sendip_data));
 ripng_header *rip = malloc(sizeof(ripng_header));
 memset(rip,0,sizeof(ripng_header));
 ret->alloc_len = sizeof(ripng_header);
 ret->data = (void *)rip;
 ret->modified=0;
 return ret;
}

canonical_original_code:
struct sendip_data *initialize() {
 struct sendip_data *ret = malloc(sizeof(sendip_data));
 struct ripng_header *rip = malloc(sizeof(ripng_header));
 memset(rip,0,sizeof(ripng_header));
 ret->alloc_len = sizeof(ripng_header);
 ret->data = (void *)rip;
 ret->modified=0;
 return ret;
}

variable_types: struct sendip_data { void *data; int alloc_len; unsigned int modified; } *

variable_types: struct ripng_header { unsigned int command; unsigned int version; unsigned int res; } *


original_code:
bool do_opt(char *opt, char *arg, sendip_data *pack) {
 ripng_header *rippack = (ripng_header *)pack->data;
 ripng_entry *ripopt;
 char *p, *q;
 switch(opt[1]) {
 case 'v':
  rippack->version = (u_int8_t)strtoul(arg, (char **)0, 0);
  pack->modified |= 1<<1;
  break;
 case 'c':
  rippack->command = (u_int8_t)strtoul(arg, (char **)0, 0);
  pack->modified |= 1;
  break;
 case 'r':
  rippack->res = htons((u_int16_t)strtoul(arg, (char **)0, 0));
  pack->modified |= 1<<2;
  break;
 case 'e':
  { (pack)->data = realloc((pack)->data,(pack)->alloc_len+sizeof(ripng_entry)); (pack)->alloc_len+=sizeof(ripng_entry); };
  ripopt = ((ripng_entry *)((u_int32_t *)((pack)->data)+((pack)->alloc_len>>2)-(sizeof(ripng_entry)>>2)));
  p=q=arg;
  while(*(q++)!='/') ; *(--q)='\0';
  ripopt->prefix = (p==q)?in6addr_any:inet6_addr(p);
  p=++q; while(*(q++)!='/') ; *(--q)='\0';
  ripopt->tag=htons( (p==q)?0:(u_int16_t)strtoul(p, (char **)0,0));
  p=++q; while(*(q++)!='/') ; *(--q)='\0';
  ripopt->len=(p==q)?(u_int8_t)128:(u_int8_t)strtoul(p, (char **)0,0);
  p=++q; while(*(q++)!='\0') ; *(--q)='\0';
  ripopt->metric=(p==q)?(u_int8_t)16:(u_int8_t)strtoul(p,(char **)0, 0);
  break;
 case 'd':
  if((((pack)->alloc_len-sizeof(ripng_header))/sizeof(ripng_entry)) != 0) {
   fprintf(stderr,"Warning: a real RIPng packet does not have any other entries in a default request.\n");
  }
  rippack->command = (u_int8_t)1;
  rippack->version = (u_int8_t)1;
  rippack->res = (u_int16_t)0;
  pack->modified|=1|1<<1|1<<2;
  { (pack)->data = realloc((pack)->data,(pack)->alloc_len+sizeof(ripng_entry)); (pack)->alloc_len+=sizeof(ripng_entry); };
  ripopt=((ripng_entry *)((u_int32_t *)((pack)->data)+((pack)->alloc_len>>2)-(sizeof(ripng_entry)>>2)));
  ripopt->prefix=in6addr_any;
  ripopt->tag=(u_int16_t)0;
  ripopt->len=(u_int8_t)0;
  ripopt->metric=htons((u_int16_t)16);
  break;
 }
 return (0==0);
}

canonical_original_code:
int do_opt(char *opt, char *arg, struct sendip_data *pack) {
 struct ripng_header *rippack = (ripng_header *)pack->data;
 struct ripng_entry *ripopt;
 char *p; char *q;
 switch(opt[1]) {
 case 'v':
  rippack->version = (unsigned int)strtoul(arg, (char **)0, 0);
  pack->modified |= 1<<1;
  break;
 case 'c':
  rippack->command = (unsigned int)strtoul(arg, (char **)0, 0);
  pack->modified |= 1;
  break;
 case 'r':
  rippack->res = htons((unsigned int)strtoul(arg, (char **)0, 0));
  pack->modified |= 1<<2;
  break;
 case 'e':
  { (pack)->data = realloc((pack)->data,(pack)->alloc_len+sizeof(ripng_entry)); (pack)->alloc_len+=sizeof(ripng_entry); };
  ripopt = ((struct ripng_entry *)((unsigned int *)((pack)->data)+((pack)->alloc_len>>2)-(sizeof(ripng_entry)>>2)));
  p=q=arg;
  while(*(q++)!='/') ; *(--q)='\0';
  ripopt->prefix = (p==q)?in6addr_any:inet6_addr(p);
  p=++q; while(*(q++)!='/') ; *(--q)='\0';
  ripopt->tag=htons( (p==q)?0:(unsigned int)strtoul(p, (char **)0,0));
  p=++q; while(*(q++)!='/') ; *(--q)='\0';
  ripopt->len=(p==q)?(unsigned int)128:(unsigned int)strtoul(p, (char **)0,0);
  p=++q; while(*(q++)!='\0') ; *(--q)='\0';
  ripopt->metric=(p==q)?(unsigned int)16:(unsigned int)strtoul(p,(char **)0, 0);
  break;
 case 'd':
  if((((pack)->alloc_len-sizeof(ripng_header))/sizeof(ripng_entry)) != 0) {
   fprintf(stderr,"Warning: a real RIPng packet does not have any other entries in a default request.\n");
  }
  rippack->command = (unsigned int)1;
  rippack->version = (unsigned int)1;
  rippack->res = (unsigned int)0;
  pack->modified|=1|1<<1|1<<2;
  { (pack)->data = realloc((pack)->data,(pack)->alloc_len+sizeof(ripng_entry)); (pack)->alloc_len+=sizeof(ripng_entry); };
  ripopt=((struct ripng_entry *)((unsigned int *)((pack)->data)+((pack)->alloc_len>>2)-(sizeof(ripng_entry)>>2)));
  ripopt->prefix=in6addr_any;
  ripopt->tag=(unsigned int)0;
  ripopt->len=(unsigned int)0;
  ripopt->metric=htons((unsigned int)16);
  break;
 }
 return (0==0);
}

variable_types:
opt
char *

variable_types:
arg
char *

variable_types: struct ripng_entry { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } prefix; unsigned int tag; unsigned int len; unsigned int metric; } *

variable_types:
p
char *

variable_types:
q
char *

user_defined_types: struct sendip_data { void *data; int alloc_len; unsigned int modified; }

user_defined_types: struct ripng_header { unsigned int command; unsigned int version; unsigned int res; }

user_defined_types: struct ripng_entry { struct in6_addr prefix; unsigned int tag; unsigned int len; unsigned int metric; }


finalize

decompiled_code:
__int64 __fastcall finalize(const char *a1)
{
if ( a1[strlen(a1) - 1] != 117 )
fwrite("Warning: RIPng should be contained in a UDP packet\n", 1uLL, 0x33uLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
if ( a1[strlen(a1) - 1] != 117 )
fwrite("Warning: RIPng should be contained in a UDP packet\n", 1uLL, 0x33uLL, stderr);
return 1LL;
}

original_code:
bool finalize(char *hdrs, sendip_data *headers[], sendip_data *data,
      sendip_data *pack) {
 if(hdrs[strlen(hdrs)-1] != 'u') {
  fprintf(stderr,"Warning: RIPng should be contained in a UDP packet\n");
 }
 return (0==0);
}

canonical_original_code:
int finalize(char *hdrs, struct sendip_data *headers[], struct sendip_data *data, struct sendip_data *pack) {
 if(hdrs[strlen(hdrs)-1] != 'u') {
  fprintf(stderr,"Warning: RIPng should be contained in a UDP packet\n");
 }
 return (0==0);
}

variable_types:
hdrs
char *

variable_types: struct sendip_data { void *data; int alloc_len; unsigned int modified; } *[]

variable_types:
data
struct sendip_data *

variable_types:
pack
struct sendip_data *


decompiled_code:
__int64 num_opts()
{
return 5LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 5LL;
}

original_code:
int num_opts() {
 return sizeof(rip_opts)/sizeof(sendip_option);
}


decompiled_code:
void **get_opts()
{
return &rip_opts;
}

canonical_decompiled_code:
void **func12()
{
return &rip_opts;
}

canonical_original_code:
struct sendip_option *get_opts() {
 return rip_opts;
}

return_type: struct sendip_option { char *optname; int arg; char *description; char *def; } *


decompiled_code:
__int64 get_optchar()
{
return 82LL;
}

canonical_decompiled_code:
__int64 func13()
{
return 82LL;
}

original_code:
char get_optchar() {
 return opt_char;
}

canonical_original_code:
char get_optchar() {
 return opt_char;
}

return_type: char


decompiled_code:
__int64 __fastcall getopt_long(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return getopt_internal(a1, a2, a3, a4, a5, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return getopt_internal(a1, a2, a3, a4, a5, 0LL);
}

original_code:
int getopt_long (int argc, char *const *argv, const char *options,
       const struct option *long_options, int *opt_index)
{
  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}

canonical_original_code:
int getopt_long(int argc, char **argv, char *options, struct option *long_options, int *opt_index)
{
  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
options
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *


decompiled_code:
__int64 __fastcall getopt_long_only(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return getopt_internal(a1, a2, a3, a4, a5, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return getopt_internal(a1, a2, a3, a4, a5, 1LL);
}

original_code:
int
getopt_long_only (int argc, char *const *argv, const char *options,
      const struct option *long_options, int *opt_index)
{
  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}

canonical_original_code:
int getopt_long_only(int argc, char **argv, char *options, struct option *long_options, int *opt_index)
{
  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}

user_defined_types: struct option { char *name; int has_arg; int *flag; int val; }


gnugetopt

decompiled_code:
__int64 __fastcall gnugetopt(int a1, const char **a2, char *a3)
{
return getopt_internal(a1, a2, a3, 0LL, 0LL, 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char **a2, char *a3)
{
return func1(a1, a2, a3, 0LL, 0LL, 0);
}

original_code:
int
gnugetopt (int argc, char *const *argv, const char *optstring)
{
  return _getopt_internal (argc, argv, optstring,
      (const struct option *) 0,
      (int *) 0,
      0);
}

canonical_original_code:
int gnugetopt(int argc, char **argv, char *optstring)
{
  return _getopt_internal (argc, argv, optstring,
      (struct option *) 0,
      (int *) 0,
      0);
}

variable_types:
optstring
char *


csum

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int16 *a1, int a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rcx
unsigned __int64 v4; // rax
__int64 v5; // rdx

if ( a2 <= 1 )
{
v3 = a1;
v4 = 0LL;
if ( a2 != 1 )
return 0xFFFFFFFFLL;
goto LABEL_5;
}
v2 = a2 - 2;
v3 = &a1[(v2 >> 1) + 1];
v4 = 0LL;
do
{
v5 = *a1++;
v4 += v5;
}
while ( a1 != v3 );
if ( v2 - 2 * (v2 >> 1) == 1 )
LABEL_5:
v4 += *(unsigned __int8 *)v3;
while ( v4 >> 16 )
v4 = (v4 >> 16) + (unsigned __int16)v4;
return (unsigned int)~(_DWORD)v4;
}

variable_types:
packet
unsigned int *

variable_types: packlen int

variable_types:
sum
unsigned long


canonical_decompiled_code:
size_t __fastcall func16(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax
__int64 v3; // rcx
int v4; // esi
int i; // edx
int v6; // eax
size_t result; // rax
_BYTE *v8; // rsi
int v9; // ecx
int v10; // er8
int v11; // ecx

if ( *(_BYTE *)a1 != 48 )
return strlen((const char *)a1);
v1 = (unsigned int)*(char *)(a1 + 1);
if ( (*(_BYTE *)(a1 + 1) & 0xDF) != 88 )
{
v8 = (_BYTE *)(a1 + 1);
v9 = 0;
result = 0LL;
if ( !*(_BYTE *)(a1 + 1) )
goto LABEL_22;
while ( 1 )
{
if ( (unsigned __int8)(v1 - 48) > 7u )
{
fprintf(stderr, "Character %c invalid in octal data stream\n", v1);
return 0LL;
}
v11 = v1 + v9 - 48;
if ( (result & 3) == 3 )
{
++v8;
*(_BYTE *)a1 = v11;
v10 = result + 1;
++a1;
v1 = (unsigned int)(char)*v8;
v9 = 0;
if ( !*v8 )
{
LABEL_21:
result = (unsigned int)(((int)result + 4) >> 2);
LABEL_22:
*(_BYTE *)a1 = v9;
return result;
}
}
else
{
v1 = (unsigned int)(char)*++v8;
v9 = 4 * v11;
v10 = result + 1;
if ( !(_BYTE)v1 )
goto LABEL_21;
}
LODWORD(result) = v10;
}
}
v2 = *(unsigned __int8 *)(a1 + 2);
v3 = a1 + 2;
v4 = 0;
if ( !(_BYTE)v2 )
{
result = 0LL;
LABEL_26:
*(_BYTE *)a1 = v4;
return result;
}
for ( i = 0; ; ++i )
{
if ( (unsigned __int8)(v2 - 48) <= 9u )
{
v6 = v2 + v4 - 48;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 65) <= 5u )
{
v6 = v2 + v4 - 55;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 97) > 5u )
break;
v6 = v2 + v4 - 87;
LABEL_6:
v4 = 16 * v6;
if ( (i & 1) != 0 )
{
*(_BYTE *)a1 = v6;
v4 = 0;
++a1;
}
v2 = *(unsigned __int8 *)++v3;
if ( !(_BYTE)v2 )
{
result = (unsigned int)((i + 2) >> 1);
goto LABEL_26;
}
}
fprintf(stderr, "Character %c invalid in hex data stream\n", (unsigned int)(char)v2);
return 0LL;
}

variable_types: i int

variable_types: c char


canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int16 *a1, int a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rcx
unsigned __int64 v4; // rax
__int64 v5; // rdx

if ( a2 <= 1 )
{
v3 = a1;
v4 = 0LL;
if ( a2 != 1 )
return 0xFFFFFFFFLL;
goto LABEL_5;
}
v2 = a2 - 2;
v3 = &a1[(v2 >> 1) + 1];
v4 = 0LL;
do
{
v5 = *a1++;
v4 += v5;
}
while ( a1 != v3 );
if ( v2 - 2 * (v2 >> 1) == 1 )
LABEL_5:
v4 += *(unsigned __int8 *)v3;
while ( v4 >> 16 )
v4 = (v4 >> 16) + (unsigned __int16)v4;
return (unsigned int)~(_DWORD)v4;
}


canonical_decompiled_code:
size_t __fastcall func17(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax
__int64 v3; // rcx
int v4; // esi
int i; // edx
int v6; // eax
size_t result; // rax
_BYTE *v8; // rsi
int v9; // ecx
int v10; // er8
int v11; // ecx

if ( *(_BYTE *)a1 != 48 )
return strlen((const char *)a1);
v1 = (unsigned int)*(char *)(a1 + 1);
if ( (*(_BYTE *)(a1 + 1) & 0xDF) != 88 )
{
v8 = (_BYTE *)(a1 + 1);
v9 = 0;
result = 0LL;
if ( !*(_BYTE *)(a1 + 1) )
goto LABEL_22;
while ( 1 )
{
if ( (unsigned __int8)(v1 - 48) > 7u )
{
fprintf(stderr, "Character %c invalid in octal data stream\n", v1);
return 0LL;
}
v11 = v1 + v9 - 48;
if ( (result & 3) == 3 )
{
++v8;
*(_BYTE *)a1 = v11;
v10 = result + 1;
++a1;
v1 = (unsigned int)(char)*v8;
v9 = 0;
if ( !*v8 )
{
LABEL_21:
result = (unsigned int)(((int)result + 4) >> 2);
LABEL_22:
*(_BYTE *)a1 = v9;
return result;
}
}
else
{
v1 = (unsigned int)(char)*++v8;
v9 = 4 * v11;
v10 = result + 1;
if ( !(_BYTE)v1 )
goto LABEL_21;
}
LODWORD(result) = v10;
}
}
v2 = *(unsigned __int8 *)(a1 + 2);
v3 = a1 + 2;
v4 = 0;
if ( !(_BYTE)v2 )
{
result = 0LL;
LABEL_26:
*(_BYTE *)a1 = v4;
return result;
}
for ( i = 0; ; ++i )
{
if ( (unsigned __int8)(v2 - 48) <= 9u )
{
v6 = v2 + v4 - 48;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 65) <= 5u )
{
v6 = v2 + v4 - 55;
goto LABEL_6;
}
if ( (unsigned __int8)(v2 - 97) > 5u )
break;
v6 = v2 + v4 - 87;
LABEL_6:
v4 = 16 * v6;
if ( (i & 1) != 0 )
{
*(_BYTE *)a1 = v6;
v4 = 0;
++a1;
}
v2 = *(unsigned __int8 *)++v3;
if ( !(_BYTE)v2 )
{
result = (unsigned int)((i + 2) >> 1);
goto LABEL_26;
}
}
fprintf(stderr, "Character %c invalid in hex data stream\n", (unsigned int)(char)v2);
return 0LL;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v5; // eax
const char *v7; // rax
__int64 v8; // rax
struct sockaddr addr; // [rsp+6h] [rbp-22h] BYREF

buf = (char *)malloc(0x20uLL);
if ( argc > 1 && strlen(argv[1]) != 17 )
{
fwrite("Wrong Bluetooth address format\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
s = socket(31, 1, 3);
if ( s < 0 )
{
perror("socket()");
exit(1);
}
*(_QWORD *)&addr.sa_family = 31LL;
*(_WORD *)&addr.sa_data[6] = 1;
if ( (int)str2ba() < 0 )
{
perror("str2ba()");
exit(1);
}
if ( connect(s, &addr, 0xAu) < 0 )
perror("connect()");
puts("sending initial dummies...");
v3 = send(s, "\n\n", 2uLL, 0);
if ( v3 < 0 )
perror("error:send()\n");
else
printf("status: %d\n", (unsigned int)v3);
f = 500;
send(s, "l,9,1\n", 7uLL, 0);
sleep(1u);
send(s, "l,9,0\n", 7uLL, 0);
if ( (unsigned int)SDL_Init() )
{
v7 = (const char *)SDL_GetError();
v4 = 1;
printf("Fehler: %s\n", v7);
}
else
{
atexit(SDL_Quit);
Joystick_Info();
js = SDL_JoystickOpen();
if ( js )
{
puts(aJoystickErfolg);
}
else
{
v8 = SDL_GetError();
printf(aKonnteJoystick, v8);
}
do
{
v4 = eventloop();
SDL_Delay();
}
while ( v4 );
SDL_JoystickClose();
v5 = send(s, "d,0,0\n", 7uLL, 0);
if ( v5 < 0 )
perror("error:send()\n");
else
printf("status code: %d\n", (unsigned int)v5);
sleep(1u);
send(s, "f,0\n", 5uLL, 0);
send(s, "t,0\n", 5uLL, 0);
send(s, "l,9,0\n", 7uLL, 0);
puts("bye");
free(buf);
close(s);
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v5; // eax
const char *v7; // rax
__int64 v8; // rax
struct sockaddr addr; // [rsp+6h] [rbp-22h] BYREF

buf = (char *)malloc(0x20uLL);
if ( argc > 1 && strlen(argv[1]) != 17 )
{
fwrite("Wrong Bluetooth address format\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
s = socket(31, 1, 3);
if ( s < 0 )
{
perror("socket()");
exit(1);
}
*(_QWORD *)&addr.sa_family = 31LL;
*(_WORD *)&addr.sa_data[6] = 1;
if ( (int)str2ba() < 0 )
{
perror("str2ba()");
exit(1);
}
if ( connect(s, &addr, 0xAu) < 0 )
perror("connect()");
puts("sending initial dummies...");
v3 = send(s, "\n\n", 2uLL, 0);
if ( v3 < 0 )
perror("error:send()\n");
else
printf("status: %d\n", (unsigned int)v3);
f = 500;
send(s, "l,9,1\n", 7uLL, 0);
sleep(1u);
send(s, "l,9,0\n", 7uLL, 0);
if ( (unsigned int)SDL_Init() )
{
v7 = (const char *)SDL_GetError();
v4 = 1;
printf("Fehler: %s\n", v7);
}
else
{
func12(SDL_Quit);
func7();
js = SDL_JoystickOpen();
if ( js )
{
puts(aJoystickErfolg);
}
else
{
v8 = SDL_GetError();
printf(aKonnteJoystick, v8);
}
do
{
v4 = func8();
SDL_Delay();
}
while ( v4 );
SDL_JoystickClose();
v5 = send(s, "d,0,0\n", 7uLL, 0);
if ( v5 < 0 )
perror("error:send()\n");
else
printf("status code: %d\n", (unsigned int)v5);
sleep(1u);
send(s, "f,0\n", 5uLL, 0);
send(s, "t,0\n", 5uLL, 0);
send(s, "l,9,0\n", 7uLL, 0);
puts("bye");
free(buf);
close(s);
}
return v4;
}

original_code:
int main(int argc, char **argv) {
 buf=malloc(32);
 const char *bt_destination_address;
 if(argc>1){
  bt_destination_address=argv[1];
 }else{
  bt_destination_address = "10:00:E8:52:BC:49";
 }
 if (strlen(bt_destination_address) != BT_ADDRESS_LENGTH) {
  fprintf(stderr, "Wrong Bluetooth address format\n");
  exit(1);
 }
 s = socket(31, SOCK_STREAM, 3);
 if (s < 0) {
  perror("socket()");
  exit(1);
 }
 struct sockaddr_rc addr = { 0 };
 addr.rc_family = 31;
 addr.rc_channel = 1;
 if (str2ba(bt_destination_address, &addr.rc_bdaddr) < 0) {
  perror("str2ba()");
  exit(1);
 }
 int status;
 status = connect(s, (struct sockaddr *) &addr, sizeof(addr));
 if (status < 0) {
  perror("connect()");
 }
 printf("sending initial dummies...\n");
 status = send(s, "\n\n", sizeof("\n\n")-1, 0);
 if (status < 0) {
   perror("error:send()\n");
  } else {
   printf("status: %d\n",status);
  }
 f=500;
 send(s, "l,9,1\n", sizeof("l,9,1\n"), 0);
 sleep(1);
 send(s, "l,9,0\n", sizeof("l,9,0\n"), 0);
 int done = 1;
   if (SDL_Init (0x00000200 | 0x00000020) != 0) {
     printf ("Fehler: %s\n", SDL_GetError ());
     return 1;
   }
   atexit (SDL_Quit);
   Joystick_Info ();
   js = SDL_JoystickOpen (0);
   if (js == ((void *)0)) {
     printf("Konnte Joystick nicht öffnen:%s\n",SDL_GetError());
   }else{
    printf("Joystick erfolgreich geöffnet\n");
   }
   while( done ) {
    done=eventloop();
    SDL_Delay(10);
   }
   SDL_JoystickClose (js);
   status = send(s, "d,0,0\n", sizeof("d,0,0\n"), 0);
     if (status < 0) {
      perror("error:send()\n");
     } else {
      printf("status code: %d\n",status);
     }
   sleep(1);
   send(s, "f,0\n", sizeof("f,0\n"), 0);
   send(s, "t,0\n", sizeof("t,0\n"), 0);
   send(s, "l,9,0\n", sizeof("l,9,0\n"), 0);
 printf("bye\n");
 free(buf);
 close(s);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 buf=malloc(32);
 char *bt_destination_address;
 if(argc>1){
  bt_destination_address=argv[1];
 }else{
  bt_destination_address = "10:00:E8:52:BC:49";
 }
 if (strlen(bt_destination_address) != BT_ADDRESS_LENGTH) {
  fprintf(stderr, "Wrong Bluetooth address format\n");
  exit(1);
 }
 s = socket(31, SOCK_STREAM, 3);
 if (s < 0) {
  perror("socket()");
  exit(1);
 }
 struct sockaddr_rc addr = { 0 };
 addr.rc_family = 31;
 addr.rc_channel = 1;
 if (str2ba(bt_destination_address, &addr.rc_bdaddr) < 0) {
  perror("str2ba()");
  exit(1);
 }
 int status;
 status = connect(s, (struct sockaddr *) &addr, sizeof(addr));
 if (status < 0) {
  perror("connect()");
 }
 printf("sending initial dummies...\n");
 status = send(s, "\n\n", sizeof("\n\n")-1, 0);
 if (status < 0) {
   perror("error:send()\n");
  } else {
   printf("status: %d\n",status);
  }
 f=500;
 send(s, "l,9,1\n", sizeof("l,9,1\n"), 0);
 sleep(1);
 send(s, "l,9,0\n", sizeof("l,9,0\n"), 0);
 int done = 1;
   if (SDL_Init (0x00000200 | 0x00000020) != 0) {
     printf ("Fehler: %s\n", SDL_GetError ());
     return 1;
   }
   atexit (SDL_Quit);
   Joystick_Info ();
   js = SDL_JoystickOpen (0);
   if (js == ((void *)0)) {
     printf("Konnte Joystick nicht öffnen:%s\n",SDL_GetError());
   }else{
    printf("Joystick erfolgreich geöffnet\n");
   }
   while( done ) {
    done=eventloop();
    SDL_Delay(10);
   }
   SDL_JoystickClose (js);
   status = send(s, "d,0,0\n", sizeof("d,0,0\n"), 0);
     if (status < 0) {
      perror("error:send()\n");
     } else {
      printf("status code: %d\n",status);
     }
   sleep(1);
   send(s, "f,0\n", sizeof("f,0\n"), 0);
   send(s, "t,0\n", sizeof("t,0\n"), 0);
   send(s, "l,9,0\n", sizeof("l,9,0\n"), 0);
 printf("bye\n");
 free(buf);
 close(s);
 return 0;
}

variable_types: struct sockaddr_rc { unsigned short rc_family; struct bdaddr_t { unsigned char b[6]; } rc_bdaddr; unsigned char rc_channel; }

variable_types: status int

variable_types: done int

user_defined_types: struct sockaddr_rc { unsigned short rc_family; struct bdaddr_t rc_bdaddr; unsigned char rc_channel; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
int Joystick_Info()
{
__int64 v0; // rbp
int result; // eax
unsigned int v2; // ebx
const char *v3; // rax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
__int64 v7; // rsi

v0 = (unsigned int)SDL_NumJoysticks();
result = printf("Es wurde(n) %d Joystick(s) auf dem System gefunden\n", v0);
if ( !(_DWORD)v0 )
return puts("Es wurde kein Joystick gefunden");
v2 = 0;
if ( (int)v0 > 0 )
{
do
{
while ( 1 )
{
v7 = v2;
js = SDL_JoystickOpen();
if ( !js )
break;
printf("Joystick %d\n", v2++);
v3 = (const char *)SDL_JoystickName();
printf("\tName: %s\n", v3);
v4 = SDL_JoystickNumAxes();
printf("\tAxen: %i\n", v4);
v5 = SDL_JoystickNumBalls();
printf("\tTrackballs: %i\n", v5);
v6 = SDL_JoystickNumButtons();
printf("\tButtons: %i\n", v6);
result = SDL_JoystickClose();
if ( (_DWORD)v0 == v2 )
return result;
}
++v2;
result = printf(aKannJoystickDN, v7);
}
while ( (_DWORD)v0 != v2 );
}
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbp
int result; // eax
unsigned int v2; // ebx
const char *v3; // rax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
__int64 v7; // rsi

v0 = (unsigned int)SDL_NumJoysticks();
result = printf("Es wurde(n) %d Joystick(s) auf dem System gefunden\n", v0);
if ( !(_DWORD)v0 )
return puts("Es wurde kein Joystick gefunden");
v2 = 0;
if ( (int)v0 > 0 )
{
do
{
while ( 1 )
{
v7 = v2;
js = SDL_JoystickOpen();
if ( !js )
break;
printf("Joystick %d\n", v2++);
v3 = (const char *)SDL_JoystickName();
printf("\tName: %s\n", v3);
v4 = SDL_JoystickNumAxes();
printf("\tAxen: %i\n", v4);
v5 = SDL_JoystickNumBalls();
printf("\tTrackballs: %i\n", v5);
v6 = SDL_JoystickNumButtons();
printf("\tButtons: %i\n", v6);
result = SDL_JoystickClose();
if ( (_DWORD)v0 == v2 )
return result;
}
++v2;
result = printf(aKannJoystickDN, v7);
}
while ( (_DWORD)v0 != v2 );
}
return result;
}

original_code:
static void Joystick_Info (void) {
  int num_js, i;
  num_js = SDL_NumJoysticks();
  printf ("Es wurde(n) %d Joystick(s) auf dem System gefunden\n",
     num_js);
  if (num_js == 0) {
    printf ("Es wurde kein Joystick gefunden\n");
    return;
  }
  for (i = 0; i < num_js; i++) {
    js = SDL_JoystickOpen (i);
    if (js == ((void *)0)) {
      printf ("Kann Joystick %d nicht öffnen\n", i);
    }
    else {
     printf ("Joystick %d\n", i);
     printf ("\tName:       %s\n", SDL_JoystickName(i));
     printf ("\tAxen:       %i\n", SDL_JoystickNumAxes(js));
     printf ("\tTrackballs: %i\n", SDL_JoystickNumBalls(js));
     printf ("\tButtons:   %i\n",SDL_JoystickNumButtons(js));
     SDL_JoystickClose (js);
    }
  }
}

canonical_original_code:
static void Joystick_Info() {
  int num_js; int i;
  num_js = SDL_NumJoysticks();
  printf ("Es wurde(n) %d Joystick(s) auf dem System gefunden\n",
     num_js);
  if (num_js == 0) {
    printf ("Es wurde kein Joystick gefunden\n");
    return;
  }
  for (i = 0; i < num_js; i++) {
    js = SDL_JoystickOpen (i);
    if (js == ((void *)0)) {
      printf ("Kann Joystick %d nicht öffnen\n", i);
    }
    else {
     printf ("Joystick %d\n", i);
     printf ("\tName:       %s\n", SDL_JoystickName(i));
     printf ("\tAxen:       %i\n", SDL_JoystickNumAxes(js));
     printf ("\tTrackballs: %i\n", SDL_JoystickNumBalls(js));
     printf ("\tButtons:   %i\n",SDL_JoystickNumButtons(js));
     SDL_JoystickClose (js);
    }
  }
}