NetTimeusElapsed

decompiled_code:
__int64 __fastcall NetTimeusElapsed(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
__int64 v4; // rdx
__int64 v5; // rdi
int v6; // eax
unsigned int v7; // er12

v2 = *(_QWORD *)(a1 + 104);
WriteInt16LE(v2, 2LL);
WriteInt8LE(*(_QWORD *)(a1 + 104), (unsigned int)*(char *)(a1 + 88));
WriteInt8LE(*(_QWORD *)(a1 + 104), 3LL);
WriteUInt32LE(*(_QWORD *)(a1 + 104), a2);
(*(void (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 104) + 64LL))(*(_QWORD *)(a1 + 104));
v4 = *(_QWORD *)(a1 + 80);
if ( *(int *)(v4 + 208) > 0 )
{
while ( 1 )
{
v6 = *(_DWORD *)(v4 + 212);
if ( !v6 )
break;
v5 = *(_QWORD *)(a1 + 96);
*(_DWORD *)(v4 + 212) = v6 - 1;
ReadInt32LE(v5);
v4 = *(_QWORD *)(a1 + 80);
}
}
if ( (unsigned __int16)ReadInt16LE(*(_QWORD *)(a1 + 96)) != 2 )
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 1);
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 3 )
goto LABEL_12;
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 3 )
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 3);
v7 = ReadUInt32LE(v2);
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 0x80 )
LABEL_12:
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 2);
return v7;
}

original_code:
uint32 NetTimeusElapsed(NetTime *ob,uint32 start) {
  Stream *out = ob->out;
  int ret_len;
  uint32 ret;
  WriteInt16LE(ob->out,0x0002);
  WriteInt8LE(ob->out,ob->instance);
  WriteInt8LE(ob->out,0x03);
  WriteUInt32LE(ob->out,start);
  ob->out->Flush(ob->out);
  if (ob->conn->mode > 0) {
    while (ob->conn->count) {
      ob->conn->count--;
      ReadInt32LE(ob->in);
    }
  }
  if (ReadInt16LE(ob->in) != 0x0002) longjmp(ob->conn->exception,1);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,2);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,3);
  ret = ReadUInt32LE(out);
  if (ReadUInt8LE(ob->in) != 0x80) longjmp(ob->conn->exception,2);
  return ret;
}

canonical_original_code:
unsigned int NetTimeusElapsed(struct NetTime *ob, unsigned int start) {
  struct Stream *out = ob->out;
  int ret_len;
  unsigned int ret;
  WriteInt16LE(ob->out,0x0002);
  WriteInt8LE(ob->out,ob->instance);
  WriteInt8LE(ob->out,0x03);
  WriteUInt32LE(ob->out,start);
  ob->out->Flush(ob->out);
  if (ob->conn->mode > 0) {
    while (ob->conn->count) {
      ob->conn->count--;
      ReadInt32LE(ob->in);
    }
  }
  if (ReadInt16LE(ob->in) != 0x0002) longjmp(ob->conn->exception,1);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,2);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,3);
  ret = ReadUInt32LE(out);
  if (ReadUInt8LE(ob->in) != 0x80) longjmp(ob->conn->exception,2);
  return ret;
}


NetTimeusFuture

repo: embeddedarm/libtsctl

decompiled_code:
__int64 __fastcall NetTimeusFuture(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v5; // r12
__int64 v6; // rdx
__int64 v7; // rdi
int v8; // eax
unsigned int v9; // er12

v5 = *(_QWORD *)(a1 + 104);
WriteInt16LE(v5, 2LL);
WriteInt8LE(*(_QWORD *)(a1 + 104), (unsigned int)*(char *)(a1 + 88));
WriteInt8LE(*(_QWORD *)(a1 + 104), 4LL);
WriteUInt32LE(*(_QWORD *)(a1 + 104), a2);
WriteUInt32LE(*(_QWORD *)(a1 + 104), a3);
(*(void (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 104) + 64LL))(*(_QWORD *)(a1 + 104));
v6 = *(_QWORD *)(a1 + 80);
if ( *(int *)(v6 + 208) > 0 )
{
while ( 1 )
{
v8 = *(_DWORD *)(v6 + 212);
if ( !v8 )
break;
v7 = *(_QWORD *)(a1 + 96);
*(_DWORD *)(v6 + 212) = v8 - 1;
ReadInt32LE(v7);
v6 = *(_QWORD *)(a1 + 80);
}
}
if ( (unsigned __int16)ReadInt16LE(*(_QWORD *)(a1 + 96)) != 2 )
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 1);
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 4 )
goto LABEL_12;
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 3 )
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 3);
v9 = ReadUInt32LE(v5);
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 0x80 )
LABEL_12:
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 2);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v5; // r12
__int64 v6; // rdx
__int64 v7; // rdi
int v8; // eax
unsigned int v9; // er12

v5 = *(_QWORD *)(a1 + 104);
WriteInt16LE(v5, 2LL);
WriteInt8LE(*(_QWORD *)(a1 + 104), (unsigned int)*(char *)(a1 + 88));
WriteInt8LE(*(_QWORD *)(a1 + 104), 4LL);
WriteUInt32LE(*(_QWORD *)(a1 + 104), a2);
WriteUInt32LE(*(_QWORD *)(a1 + 104), a3);
(*(void (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 104) + 64LL))(*(_QWORD *)(a1 + 104));
v6 = *(_QWORD *)(a1 + 80);
if ( *(int *)(v6 + 208) > 0 )
{
while ( 1 )
{
v8 = *(_DWORD *)(v6 + 212);
if ( !v8 )
break;
v7 = *(_QWORD *)(a1 + 96);
*(_DWORD *)(v6 + 212) = v8 - 1;
ReadInt32LE(v7);
v6 = *(_QWORD *)(a1 + 80);
}
}
if ( (unsigned __int16)ReadInt16LE(*(_QWORD *)(a1 + 96)) != 2 )
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 1);
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 4 )
goto LABEL_12;
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 3 )
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 3);
v9 = ReadUInt32LE(v5);
if ( (unsigned __int8)ReadUInt8LE(*(_QWORD *)(a1 + 96)) != 0x80 )
LABEL_12:
longjmp(*(struct __jmp_buf_tag **)(a1 + 80), 2);
return v9;
}

original_code:
uint32 NetTimeusFuture(NetTime *ob,uint32 start,uint32 microseconds) {
  Stream *out = ob->out;
  int ret_len;
  uint32 ret;
  WriteInt16LE(ob->out,0x0002);
  WriteInt8LE(ob->out,ob->instance);
  WriteInt8LE(ob->out,0x04);
  WriteUInt32LE(ob->out,start);
  WriteUInt32LE(ob->out,microseconds);
  ob->out->Flush(ob->out);
  if (ob->conn->mode > 0) {
    while (ob->conn->count) {
      ob->conn->count--;
      ReadInt32LE(ob->in);
    }
  }
  if (ReadInt16LE(ob->in) != 0x0002) longjmp(ob->conn->exception,1);
  if (ReadUInt8LE(ob->in) != 0x04) longjmp(ob->conn->exception,2);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,3);
  ret = ReadUInt32LE(out);
  if (ReadUInt8LE(ob->in) != 0x80) longjmp(ob->conn->exception,2);
  return ret;
}

canonical_original_code:
unsigned int NetTimeusFuture(struct NetTime *ob, unsigned int start, unsigned int microseconds) {
  struct Stream *out = ob->out;
  int ret_len;
  unsigned int ret;
  WriteInt16LE(ob->out,0x0002);
  WriteInt8LE(ob->out,ob->instance);
  WriteInt8LE(ob->out,0x04);
  WriteUInt32LE(ob->out,start);
  WriteUInt32LE(ob->out,microseconds);
  ob->out->Flush(ob->out);
  if (ob->conn->mode > 0) {
    while (ob->conn->count) {
      ob->conn->count--;
      ReadInt32LE(ob->in);
    }
  }
  if (ReadInt16LE(ob->in) != 0x0002) longjmp(ob->conn->exception,1);
  if (ReadUInt8LE(ob->in) != 0x04) longjmp(ob->conn->exception,2);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,3);
  ret = ReadUInt32LE(out);
  if (ReadUInt8LE(ob->in) != 0x80) longjmp(ob->conn->exception,2);
  return ret;
}

variable_types: struct NetTime { void *(*Init)(void *me, ...); void (*Fini)(void *me); unsigned int (*Wait)(void *me, unsigned int microseconds); void (*Delay)(void *me, unsigned int microseconds); unsigned int (*Tick)(void *me); unsigned int (*usElapsed)(void *me, unsigned int start); unsigned int (*usFuture)(void *me, unsigned int start, unsigned int microseconds); enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 } (*TimeoutQ)(void *me, unsigned int start, unsigned int end); unsigned int (*TPS)(void *me); int InitStatus; struct tsctl { struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } exception[1]; struct Stream { void (*Fini)(struct Stream *); int (*Read)(struct Stream *, char *bytes, int len); int (*Unread)(struct Stream *st, int ch); int (*ReadChar)(struct Stream *st); unsigned int (*InputReady)(struct Stream *st); int (*Write)(struct Stream *, char *bytes, int len); int (*WriteChar)(struct Stream *st, char byte); int (*isEOF)(struct Stream *st); void (*Flush)(struct Stream *st); int outputOffset; } *st; int mode; } *conn; int instance; struct Stream *in; } *

variable_types:
start
unsigned int

variable_types:
microseconds
unsigned int

variable_types:
ret
unsigned int

return_type: unsigned int

user_defined_types: struct NetTime { void *(*Init)(void *me, ...); void (*Fini)(void *me); unsigned int (*Wait)(void *me, unsigned int microseconds); void (*Delay)(void *me, unsigned int microseconds); unsigned int (*Tick)(void *me); unsigned int (*usElapsed)(void *me, unsigned int start); unsigned int (*usFuture)(void *me, unsigned int start, unsigned int microseconds); enum TimeResult (*TimeoutQ)(void *me, unsigned int start, unsigned int end); unsigned int (*TPS)(void *me); int InitStatus; struct tsctl *conn; int instance; struct Stream *in; }

user_defined_types: struct tsctl { struct __jmp_buf_tag exception[1]; struct Stream *st; int mode; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


NetTimeTPS

original_code:
uint32 NetTimeTPS(NetTime *ob) {
  Stream *out = ob->out;
  int ret_len;
  uint32 ret;
  WriteInt16LE(ob->out,0x0002);
  WriteInt8LE(ob->out,ob->instance);
  WriteInt8LE(ob->out,0x06);
  ob->out->Flush(ob->out);
  if (ob->conn->mode > 0) {
    while (ob->conn->count) {
      ob->conn->count--;
      ReadInt32LE(ob->in);
    }
  }
  if (ReadInt16LE(ob->in) != 0x0002) longjmp(ob->conn->exception,1);
  if (ReadUInt8LE(ob->in) != 0x06) longjmp(ob->conn->exception,2);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,3);
  ret = ReadUInt32LE(out);
  if (ReadUInt8LE(ob->in) != 0x80) longjmp(ob->conn->exception,2);
  return ret;
}

canonical_original_code:
unsigned int NetTimeTPS(struct NetTime *ob) {
  struct Stream *out = ob->out;
  int ret_len;
  unsigned int ret;
  WriteInt16LE(ob->out,0x0002);
  WriteInt8LE(ob->out,ob->instance);
  WriteInt8LE(ob->out,0x06);
  ob->out->Flush(ob->out);
  if (ob->conn->mode > 0) {
    while (ob->conn->count) {
      ob->conn->count--;
      ReadInt32LE(ob->in);
    }
  }
  if (ReadInt16LE(ob->in) != 0x0002) longjmp(ob->conn->exception,1);
  if (ReadUInt8LE(ob->in) != 0x06) longjmp(ob->conn->exception,2);
  if (ReadUInt8LE(ob->in) != 0x03) longjmp(ob->conn->exception,3);
  ret = ReadUInt32LE(out);
  if (ReadUInt8LE(ob->in) != 0x80) longjmp(ob->conn->exception,2);
  return ret;
}

variable_types: struct Stream { void (*Fini)(struct Stream *); int (*Read)(struct Stream *, char *bytes, int len); int (*Unread)(struct Stream *st, int ch); int (*ReadChar)(struct Stream *st); unsigned int (*InputReady)(struct Stream *st); int (*Write)(struct Stream *, char *bytes, int len); int (*WriteChar)(struct Stream *st, char byte); int (*isEOF)(struct Stream *st); void (*Flush)(struct Stream *st); int outputOffset; } *

user_defined_types: enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


ArrayFree

decompiled_code:
void __fastcall ArrayFree(__int64 a1)
{
free((void *)(a1 - 12));
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
free((void *)(a1 - 12));
}

original_code:
void ArrayFree(const void *arr) {
  unsigned *ptr = (unsigned *)arr;
  free(ptr-3);
}

canonical_original_code:
void ArrayFree(void *arr) {
  unsigned int *ptr = (unsigned *)arr;
  free(ptr-3);
}

variable_types:
arr
void *

variable_types:
ptr
unsigned int *

return_type: void


ASCIIZ

decompiled_code:
char *__fastcall ASCIIZ(char *src)
{
unsigned int v1; // ebx
char *v2; // rax

v1 = strlen(src);
v2 = (char *)ArrayAlloc(v1, 1u);
return strncpy(v2, src, v1);
}

canonical_decompiled_code:
char *__fastcall func9(char *src)
{
unsigned int v1; // ebx
char *v2; // rax

v1 = strlen(src);
v2 = (char *)ArrayAlloc(v1, 1u);
return strncpy(v2, src, v1);
}

original_code:
char *ASCIIZ(const char *str) {
  unsigned len = strlen(str);
  char *str2 = (char *)ArrayAlloc(len,1);
  strncpy(str2,str,len);
  return str2;
}

canonical_original_code:
char *ASCIIZ(char *str) {
  unsigned int len = strlen(str);
  char *str2 = (char *)ArrayAlloc(len,1);
  strncpy(str2,str,len);
  return str2;
}

variable_types:
str
char *

variable_types:
len
unsigned int

return_type: char *


ArraySizeAuto

decompiled_code:
__int64 __fastcall ArraySizeAuto(__int64 a1, int a2)
{
*(_DWORD *)(a1 - 4) = a2;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
*(_DWORD *)(a1 - 4) = a2;
return a1;
}

original_code:
void *ArraySizeAuto(void *arr,unsigned count) {
  unsigned *ptr = (unsigned *)arr;
  ptr -= 3;
  ptr[2] = count;
  return &ptr[3];
}

canonical_original_code:
void *ArraySizeAuto(void *arr, unsigned int count) {
  unsigned int *ptr = (unsigned *)arr;
  ptr -= 3;
  ptr[2] = count;
  return &ptr[3];
}

variable_types:
count
unsigned int

return_type: void *


ArrayElementSize

decompiled_code:
__int64 __fastcall ArrayElementSize(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

original_code:
unsigned ArrayElementSize(const void *array) {
  return _ArrayElementSize(array);
}

canonical_original_code:
unsigned int ArrayElementSize(void *array) {
  return _ArrayElementSize(array);
}

variable_types:
array
void *


ArrayLength

decompiled_code:
__int64 __fastcall ArrayLength(__int64 a1)
{
return *(unsigned int *)(a1 - 4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned int *)(a1 - 4);
}

original_code:
unsigned ArrayLength(const void *array) {
  return _ArrayLength(array);
}

canonical_original_code:
unsigned int ArrayLength(void *array) {
  return _ArrayLength(array);
}


ArrayFreeFree

decompiled_code:
void __fastcall ArrayFreeFree(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( *(_DWORD *)(a1 - 4) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(a1 + 8 * v2);
if ( v3 )
ArrayFree(v3);
++v2;
}
while ( *(_DWORD *)(a1 - 4) > (unsigned int)v2 );
}
ArrayFree(a1);
}

original_code:
void ArrayFreeFree(const void *arr0) {
  const void * const *arr = (const void * const *)arr0;
  int i;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) ArrayFree(arr[i]);
  }
  ArrayFree(arr);
}

canonical_original_code:
void ArrayFreeFree(void *arr0) {
  void **arr = (const void * const *)arr0;
  int i;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) ArrayFree(arr[i]);
  }
  ArrayFree(arr);
}

variable_types:
arr
void **

variable_types: i int


ArrayFreeFreeFree

decompiled_code:
void __fastcall ArrayFreeFreeFree(__int64 a1)
{
__int64 v2; // rbp
__int64 v3; // rdi
__int64 v4; // rbx

if ( *(_DWORD *)(a1 - 4) )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(a1 + 8 * v2);
if ( v3 )
break;
if ( *(_DWORD *)(a1 - 4) <= (unsigned int)++v2 )
goto LABEL_11;
}
if ( *(_DWORD *)(v3 - 4) )
{
v4 = 0LL;
do
{
if ( *(_QWORD *)(v3 + 8 * v4) )
{
ArrayFree(*(_QWORD *)(v3 + 8 * v4));
v3 = *(_QWORD *)(a1 + 8 * v2);
}
++v4;
}
while ( *(_DWORD *)(v3 - 4) > (unsigned int)v4 );
}
ArrayFree(v3);
++v2;
}
while ( *(_DWORD *)(a1 - 4) > (unsigned int)v2 );
}
LABEL_11:
ArrayFree(a1);
}

original_code:
void ArrayFreeFreeFree(const void *arr0) {
  const void ** const *arr = (const void ** const *)arr0;
  int i,j;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) {
      for (j=0;j<_ArrayLength(arr[i]);j++) {
 if (arr[i][j]) ArrayFree(arr[i][j]);
      }
      ArrayFree(arr[i]);
    }
  }
  ArrayFree(arr);
}

canonical_original_code:
void ArrayFreeFreeFree(void *arr0) {
  void ***arr = (const void ** const *)arr0;
  int i; int j;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) {
      for (j=0;j<_ArrayLength(arr[i]);j++) {
 if (arr[i][j]) ArrayFree(arr[i][j]);
      }
      ArrayFree(arr[i]);
    }
  }
  ArrayFree(arr);
}

variable_types:
arr
void ***

variable_types: j int


ArrayCompareFunction

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

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

original_code:
void *ArrayCompareFunction(const void *array) {
  return ArrayCompareFunction(array);
}

canonical_original_code:
void *ArrayCompareFunction(void *array) {
  return ArrayCompareFunction(array);
}


decompiled_code:
__int64 __fastcall MarvellPXA166DIORawLock(__int64 a1, __int64 a2, char a3)
{
if ( (a3 & 2) != 0 )
++*(_DWORD *)(a1 + 84);
else
++*(_DWORD *)(a1 + 88);
return 1LL;
}

original_code:
int MarvellPXA166DIORawLock(MarvellPXA166DIORaw *ob, unsigned num, int flags) {
  if (flags & SHARED) {
    ob->deferlockR++;
  } else {
    ob->deferlockW++;
  }
  return 1;
}

canonical_original_code:
int MarvellPXA166DIORawLock(struct MarvellPXA166DIORaw *ob, unsigned int num, int flags) {
  if (flags & SHARED) {
    ob->deferlockR++;
  } else {
    ob->deferlockW++;
  }
  return 1;
}

variable_types: struct MarvellPXA166DIORaw { void *(*Init)(struct MarvellPXA166DIORaw *me, void *bus); void (*Fini)(struct MarvellPXA166DIORaw *me); int (*Lock)(struct MarvellPXA166DIORaw *me, unsigned int num, int flags); int (*Unlock)(struct MarvellPXA166DIORaw *me, unsigned int num, int flags); int (*Preempt)(struct MarvellPXA166DIORaw *me); void (*DirSet)(struct MarvellPXA166DIORaw *me, int num, int asOutput); void (*DataSet)(struct MarvellPXA166DIORaw *me, int num, int asHigh); int (*DirGet)(struct MarvellPXA166DIORaw *me, int num); int (*DataGet)(struct MarvellPXA166DIORaw *me, int num); unsigned int (*Count)(struct MarvellPXA166DIORaw *me); int InitStatus; int deferlockR; int deferlockW; struct Bus { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); unsigned char (*Peek8)(void *me, int Address); void (*Poke8)(void *me, int Address, unsigned char Value); unsigned short (*Peek16)(void *me, int Address); void (*Poke16)(void *me, int Address, unsigned short Value); unsigned int (*Peek32)(void *me, int Address); void (*Poke32)(void *me, int Address, unsigned int Value); int (*BitGet8)(void *me, int Address, int BitNumber); void (*BitAssign8)(void *me, int Address, int BitNumber, int Value); void (*BitSet8)(void *me, int Address, int BitNumber); void (*BitClear8)(void *me, int Address, int BitNumber); int (*BitGet16)(void *me, int Address, int BitNumber); void (*BitAssign16)(void *me, int Address, int BitNumber, int Value); void (*BitSet16)(void *me, int Address, int BitNumber); void (*BitClear16)(void *me, int Address, int BitNumber); int (*BitGet32)(void *me, int Address, int BitNumber); void (*BitAssign32)(void *me, int Address, int BitNumber, int Value); void (*BitSet32)(void *me, int Address, int BitNumber); void (*BitClear32)(void *me, int Address, int BitNumber); void (*PeekStream)(void *me, int address, int direction, char *dest); void (*PokeStream)(void *me, int address, int direction, char *data); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); int (*BitToggle8)(void *me, int Address, int BitNumber); int (*BitToggle16)(void *me, int Address, int BitNumber); int (*BitToggle32)(void *me, int Address, int BitNumber); unsigned char (*Assign8X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned short (*Assign16X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned int (*Assign32X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned char (*BitsGet8)(void *me, int Address, int BitMSB, int BitLSB); unsigned short (*BitsGet16)(void *me, int Address, int BitMSB, int BitLSB); unsigned int (*BitsGet32)(void *me, int Address, int BitMSB, int BitLSB); int InitStatus; unsigned int LockBase; int deferlockW; int deferlockR; } *sub; } *

variable_types:
num
unsigned int

variable_types: flags int

return_type: int

user_defined_types: struct MarvellPXA166DIORaw { void *(*Init)(struct MarvellPXA166DIORaw *me, void *bus); void (*Fini)(struct MarvellPXA166DIORaw *me); int (*Lock)(struct MarvellPXA166DIORaw *me, unsigned int num, int flags); int (*Unlock)(struct MarvellPXA166DIORaw *me, unsigned int num, int flags); int (*Preempt)(struct MarvellPXA166DIORaw *me); void (*DirSet)(struct MarvellPXA166DIORaw *me, int num, int asOutput); void (*DataSet)(struct MarvellPXA166DIORaw *me, int num, int asHigh); int (*DirGet)(struct MarvellPXA166DIORaw *me, int num); int (*DataGet)(struct MarvellPXA166DIORaw *me, int num); unsigned int (*Count)(struct MarvellPXA166DIORaw *me); int InitStatus; int deferlockR; int deferlockW; struct Bus *sub; }


decompiled_code:
__int64 __fastcall MarvellPXA166DIORawUnlock(__int64 a1, __int64 a2, char a3)
{
int v3; // eax
__int64 result; // rax
int v5; // eax

if ( (a3 & 2) != 0 )
{
v3 = *(_DWORD *)(a1 + 84);
if ( !v3 )
{
LABEL_3:
(*(void (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 96) + 24LL))(*(_QWORD *)(a1 + 96));
return 1LL;
}
*(_DWORD *)(a1 + 84) = v3 - 1;
result = 1LL;
}
else
{
v5 = *(_DWORD *)(a1 + 88);
if ( !v5 )
goto LABEL_3;
*(_DWORD *)(a1 + 88) = v5 - 1;
result = 1LL;
}
return result;
}

original_code:
int MarvellPXA166DIORawUnlock(MarvellPXA166DIORaw *ob, unsigned num, int flags) {
  if (flags & SHARED) {
    if (ob->deferlockR) {
      ob->deferlockR--;
    } else {
      ob->sub->Unlock(ob->sub,num,flags);
    }
    return 1;
  } else {
    if (ob->deferlockW) {
      ob->deferlockW--;
    } else {
      ob->sub->Unlock(ob->sub,num,flags);
    }
    return 1;
  }
}

canonical_original_code:
int MarvellPXA166DIORawUnlock(struct MarvellPXA166DIORaw *ob, unsigned int num, int flags) {
  if (flags & SHARED) {
    if (ob->deferlockR) {
      ob->deferlockR--;
    } else {
      ob->sub->Unlock(ob->sub,num,flags);
    }
    return 1;
  } else {
    if (ob->deferlockW) {
      ob->deferlockW--;
    } else {
      ob->sub->Unlock(ob->sub,num,flags);
    }
    return 1;
  }
}

user_defined_types: struct Bus { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); unsigned char (*Peek8)(void *me, int Address); void (*Poke8)(void *me, int Address, unsigned char Value); unsigned short (*Peek16)(void *me, int Address); void (*Poke16)(void *me, int Address, unsigned short Value); unsigned int (*Peek32)(void *me, int Address); void (*Poke32)(void *me, int Address, unsigned int Value); int (*BitGet8)(void *me, int Address, int BitNumber); void (*BitAssign8)(void *me, int Address, int BitNumber, int Value); void (*BitSet8)(void *me, int Address, int BitNumber); void (*BitClear8)(void *me, int Address, int BitNumber); int (*BitGet16)(void *me, int Address, int BitNumber); void (*BitAssign16)(void *me, int Address, int BitNumber, int Value); void (*BitSet16)(void *me, int Address, int BitNumber); void (*BitClear16)(void *me, int Address, int BitNumber); int (*BitGet32)(void *me, int Address, int BitNumber); void (*BitAssign32)(void *me, int Address, int BitNumber, int Value); void (*BitSet32)(void *me, int Address, int BitNumber); void (*BitClear32)(void *me, int Address, int BitNumber); void (*PeekStream)(void *me, int address, int direction, char *dest); void (*PokeStream)(void *me, int address, int direction, char *data); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); int (*BitToggle8)(void *me, int Address, int BitNumber); int (*BitToggle16)(void *me, int Address, int BitNumber); int (*BitToggle32)(void *me, int Address, int BitNumber); unsigned char (*Assign8X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned short (*Assign16X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned int (*Assign32X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned char (*BitsGet8)(void *me, int Address, int BitMSB, int BitLSB); unsigned short (*BitsGet16)(void *me, int Address, int BitMSB, int BitLSB); unsigned int (*BitsGet32)(void *me, int Address, int BitMSB, int BitLSB); int InitStatus; unsigned int LockBase; int deferlockW; int deferlockR; }


decompiled_code:
__int64 MarvellPXA166DIORawPreempt()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0xFFFFFFFFLL;
}

original_code:
int MarvellPXA166DIORawPreempt(MarvellPXA166DIORaw *ob) {
  return -1;
}

canonical_original_code:
int MarvellPXA166DIORawPreempt(struct MarvellPXA166DIORaw *ob) {
  return -1;
}


decompiled_code:
__int64 __fastcall MarvellPXA166DIORawInit(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx

result = a1;
if ( *(int *)(a1 + 80) <= 0 )
{
*(_QWORD *)(a1 + 84) = 0LL;
v3 = *(_DWORD *)(a2 + 288);
*(_QWORD *)a1 = MarvellPXA166DIORawInit;
*(_QWORD *)(a1 + 8) = MarvellPXA166DIORawFini;
*(_QWORD *)(a1 + 16) = MarvellPXA166DIORawLock;
*(_QWORD *)(a1 + 24) = MarvellPXA166DIORawUnlock;
*(_QWORD *)(a1 + 32) = MarvellPXA166DIORawPreempt;
*(_QWORD *)(a1 + 40) = MarvellPXA166DIORawDirSet;
*(_QWORD *)(a1 + 48) = MarvellPXA166DIORawDataSet;
*(_QWORD *)(a1 + 56) = MarvellPXA166DIORawDirGet;
*(_QWORD *)(a1 + 64) = MarvellPXA166DIORawDataGet;
*(_QWORD *)(a1 + 72) = MarvellPXA166DIORawCount;
*(_QWORD *)(a1 + 96) = a2;
if ( v3 <= 0 )
*(_DWORD *)(a1 + 80) = -1;
else
*(_DWORD *)(a1 + 80) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx

result = a1;
if ( *(int *)(a1 + 80) <= 0 )
{
*(_QWORD *)(a1 + 84) = 0LL;
v3 = *(_DWORD *)(a2 + 288);
*(_QWORD *)a1 = MarvellPXA166DIORawInit;
*(_QWORD *)(a1 + 8) = MarvellPXA166DIORawFini;
*(_QWORD *)(a1 + 16) = MarvellPXA166DIORawLock;
*(_QWORD *)(a1 + 24) = MarvellPXA166DIORawUnlock;
*(_QWORD *)(a1 + 32) = MarvellPXA166DIORawPreempt;
*(_QWORD *)(a1 + 40) = MarvellPXA166DIORawDirSet;
*(_QWORD *)(a1 + 48) = MarvellPXA166DIORawDataSet;
*(_QWORD *)(a1 + 56) = MarvellPXA166DIORawDirGet;
*(_QWORD *)(a1 + 64) = MarvellPXA166DIORawDataGet;
*(_QWORD *)(a1 + 72) = MarvellPXA166DIORawCount;
*(_QWORD *)(a1 + 96) = a2;
if ( v3 <= 0 )
*(_DWORD *)(a1 + 80) = -1;
else
*(_DWORD *)(a1 + 80) = 1;
}
return result;
}

original_code:
void *MarvellPXA166DIORawInit(MarvellPXA166DIORaw *dio,void *bus1) {
  Bus *bus = bus1;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)MarvellPXA166DIORawInit;
  dio->Fini = (void *)MarvellPXA166DIORawFini;
  dio->Lock = (void *)MarvellPXA166DIORawLock;
  dio->Unlock = (void *)MarvellPXA166DIORawUnlock;
  dio->Preempt = (void *)MarvellPXA166DIORawPreempt;
  dio->DirSet = (void *)MarvellPXA166DIORawDirSet;
  dio->DataSet = (void *)MarvellPXA166DIORawDataSet;
  dio->DirGet = (void *)MarvellPXA166DIORawDirGet;
  dio->DataGet = (void *)MarvellPXA166DIORawDataGet;
  dio->Count = (void *)MarvellPXA166DIORawCount;
  MarvellPXA166DIORawLockInit(dio);
  dio->sub = bus;
  if (dio->sub->InitStatus <= 0) {
    dio->InitStatus = -1;
    return dio;
  }
  dio->InitStatus = 1;
  return dio;
}

canonical_original_code:
void *MarvellPXA166DIORawInit(struct MarvellPXA166DIORaw *dio, void *bus1) {
  struct Bus *bus = bus1;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)MarvellPXA166DIORawInit;
  dio->Fini = (void *)MarvellPXA166DIORawFini;
  dio->Lock = (void *)MarvellPXA166DIORawLock;
  dio->Unlock = (void *)MarvellPXA166DIORawUnlock;
  dio->Preempt = (void *)MarvellPXA166DIORawPreempt;
  dio->DirSet = (void *)MarvellPXA166DIORawDirSet;
  dio->DataSet = (void *)MarvellPXA166DIORawDataSet;
  dio->DirGet = (void *)MarvellPXA166DIORawDirGet;
  dio->DataGet = (void *)MarvellPXA166DIORawDataGet;
  dio->Count = (void *)MarvellPXA166DIORawCount;
  MarvellPXA166DIORawLockInit(dio);
  dio->sub = bus;
  if (dio->sub->InitStatus <= 0) {
    dio->InitStatus = -1;
    return dio;
  }
  dio->InitStatus = 1;
  return dio;
}

variable_types: struct Bus { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); unsigned char (*Peek8)(void *me, int Address); void (*Poke8)(void *me, int Address, unsigned char Value); unsigned short (*Peek16)(void *me, int Address); void (*Poke16)(void *me, int Address, unsigned short Value); unsigned int (*Peek32)(void *me, int Address); void (*Poke32)(void *me, int Address, unsigned int Value); int (*BitGet8)(void *me, int Address, int BitNumber); void (*BitAssign8)(void *me, int Address, int BitNumber, int Value); void (*BitSet8)(void *me, int Address, int BitNumber); void (*BitClear8)(void *me, int Address, int BitNumber); int (*BitGet16)(void *me, int Address, int BitNumber); void (*BitAssign16)(void *me, int Address, int BitNumber, int Value); void (*BitSet16)(void *me, int Address, int BitNumber); void (*BitClear16)(void *me, int Address, int BitNumber); int (*BitGet32)(void *me, int Address, int BitNumber); void (*BitAssign32)(void *me, int Address, int BitNumber, int Value); void (*BitSet32)(void *me, int Address, int BitNumber); void (*BitClear32)(void *me, int Address, int BitNumber); void (*PeekStream)(void *me, int address, int direction, char *dest); void (*PokeStream)(void *me, int address, int direction, char *data); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); int (*BitToggle8)(void *me, int Address, int BitNumber); int (*BitToggle16)(void *me, int Address, int BitNumber); int (*BitToggle32)(void *me, int Address, int BitNumber); unsigned char (*Assign8X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned short (*Assign16X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned int (*Assign32X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned char (*BitsGet8)(void *me, int Address, int BitMSB, int BitLSB); unsigned short (*BitsGet16)(void *me, int Address, int BitMSB, int BitLSB); unsigned int (*BitsGet32)(void *me, int Address, int BitMSB, int BitLSB); int InitStatus; unsigned int LockBase; int deferlockW; int deferlockR; } *


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

(*(void (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 96) + 8LL))(*(_QWORD *)(a1 + 96));
result = *(unsigned int *)(a1 + 80);
if ( (int)result > 0 )
*(_DWORD *)(a1 + 80) = 0;
return result;
}

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

(*(void (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 96) + 8LL))(*(_QWORD *)(a1 + 96));
result = *(unsigned int *)(a1 + 80);
if ( (int)result > 0 )
*(_DWORD *)(a1 + 80) = 0;
return result;
}

original_code:
void MarvellPXA166DIORawFini(MarvellPXA166DIORaw *dio) {
  dio->sub->Fini(dio->sub);
  if (dio->InitStatus > 0) dio->InitStatus = 0;
}

canonical_original_code:
void MarvellPXA166DIORawFini(struct MarvellPXA166DIORaw *dio) {
  dio->sub->Fini(dio->sub);
  if (dio->InitStatus > 0) dio->InitStatus = 0;
}


original_code:
void MarvellPXA166DIORawDirSet(MarvellPXA166DIORaw *dio,int Num,int asOutput) {
  if (( Num<0 ? ~(Num) : (Num)) > 122) return;
  MarvellPXA166DIORawLockReal(dio,0);
  if (( Num<0 ? ~(Num) : (Num)) < 32) {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x0C) : (0x0C)),( Num<0 ? ~(Num) : (Num)),asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 64) {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x10) : (0x10)),( Num<0 ? ~(Num) : (Num))-32,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 96) {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x14) : (0x14)),( Num<0 ? ~(Num) : (Num))-64,asOutput);
  } else {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x10C) : (0x10C)),( Num<0 ? ~(Num) : (Num))-96,asOutput);
  }
}

canonical_original_code:
void MarvellPXA166DIORawDirSet(struct MarvellPXA166DIORaw *dio, int Num, int asOutput) {
  if (( Num<0 ? ~(Num) : (Num)) > 122) return;
  MarvellPXA166DIORawLockReal(dio,0);
  if (( Num<0 ? ~(Num) : (Num)) < 32) {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x0C) : (0x0C)),( Num<0 ? ~(Num) : (Num)),asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 64) {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x10) : (0x10)),( Num<0 ? ~(Num) : (Num))-32,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 96) {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x14) : (0x14)),( Num<0 ? ~(Num) : (Num))-64,asOutput);
  } else {
    dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0x10C) : (0x10C)),( Num<0 ? ~(Num) : (Num))-96,asOutput);
  }
}

variable_types: Num int

variable_types: asOutput int


variable_types: asHigh int


original_code:
int MarvellPXA166DIORawDirGet(MarvellPXA166DIORaw *dio,int Num) {
  if (( Num<0 ? ~(Num) : (Num)) > 122) return 0;
  if (( Num<0 ? ~(Num) : (Num)) == 60 || ( Num<0 ? ~(Num) : (Num)) == 61) return 1;
  MarvellPXA166DIORawLockReal(dio,SHARED);
  if (( Num<0 ? ~(Num) : (Num)) < 32) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x0C) : (0x0C)),( Num<0 ? ~(Num) : (Num)));
  } else if (( Num<0 ? ~(Num) : (Num)) <= 64) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x10) : (0x10)),( Num<0 ? ~(Num) : (Num))-32);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 96) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x14) : (0x14)),( Num<0 ? ~(Num) : (Num))-64);
  } else {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x10C) : (0x10C)),( Num<0 ? ~(Num) : (Num))-96);
  }
}

canonical_original_code:
int MarvellPXA166DIORawDirGet(struct MarvellPXA166DIORaw *dio, int Num) {
  if (( Num<0 ? ~(Num) : (Num)) > 122) return 0;
  if (( Num<0 ? ~(Num) : (Num)) == 60 || ( Num<0 ? ~(Num) : (Num)) == 61) return 1;
  MarvellPXA166DIORawLockReal(dio,SHARED);
  if (( Num<0 ? ~(Num) : (Num)) < 32) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x0C) : (0x0C)),( Num<0 ? ~(Num) : (Num)));
  } else if (( Num<0 ? ~(Num) : (Num)) <= 64) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x10) : (0x10)),( Num<0 ? ~(Num) : (Num))-32);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 96) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x14) : (0x14)),( Num<0 ? ~(Num) : (Num))-64);
  } else {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x10C) : (0x10C)),( Num<0 ? ~(Num) : (Num))-96);
  }
}


original_code:
int MarvellPXA166DIORawDataGet(MarvellPXA166DIORaw *dio,int Num) {
  if (( Num<0 ? ~(Num) : (Num)) > 122) return 0;
  MarvellPXA166DIORawLockReal(dio,SHARED);
  if (( Num<0 ? ~(Num) : (Num)) < 32) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x00) : (0x00)),( Num<0 ? ~(Num) : (Num)));
  } else if (( Num<0 ? ~(Num) : (Num)) <= 64) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x04) : (0x04)),( Num<0 ? ~(Num) : (Num))-32);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 96) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x08) : (0x08)),( Num<0 ? ~(Num) : (Num))-64);
  } else {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x100) : (0x100)),( Num<0 ? ~(Num) : (Num))-96);
  }
}

canonical_original_code:
int MarvellPXA166DIORawDataGet(struct MarvellPXA166DIORaw *dio, int Num) {
  if (( Num<0 ? ~(Num) : (Num)) > 122) return 0;
  MarvellPXA166DIORawLockReal(dio,SHARED);
  if (( Num<0 ? ~(Num) : (Num)) < 32) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x00) : (0x00)),( Num<0 ? ~(Num) : (Num)));
  } else if (( Num<0 ? ~(Num) : (Num)) <= 64) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x04) : (0x04)),( Num<0 ? ~(Num) : (Num))-32);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 96) {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x08) : (0x08)),( Num<0 ? ~(Num) : (Num))-64);
  } else {
    return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(0x100) : (0x100)),( Num<0 ? ~(Num) : (Num))-96);
  }
}


decompiled_code:
__int64 MarvellPXA166DIORawCount()
{
return 128LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 128LL;
}

original_code:
unsigned MarvellPXA166DIORawCount(MarvellPXA166DIORaw *dio) {
  return 128;
}

canonical_original_code:
unsigned int MarvellPXA166DIORawCount(struct MarvellPXA166DIORaw *dio) {
  return 128;
}


original_code:
__attribute__((always_inline))
int MarvellPXA166DIORawLockReal(MarvellPXA166DIORaw *dio,int flags) {
  if (flags & SHARED) {
    while (dio->deferlockR) {
      dio->sub->Lock(dio->sub,0,SHARED);
      dio->deferlockR--;
    }
  } else {
    while (dio->deferlockW) {
      dio->sub->Lock(dio->sub,0,0);
      dio->deferlockW--;
    }
  }
}

canonical_original_code:
int MarvellPXA166DIORawLockReal(struct MarvellPXA166DIORaw *dio, int flags) {
  if (flags & SHARED) {
    while (dio->deferlockR) {
      dio->sub->Lock(dio->sub,0,SHARED);
      dio->deferlockR--;
    }
  } else {
    while (dio->deferlockW) {
      dio->sub->Lock(dio->sub,0,0);
      dio->deferlockW--;
    }
  }
}


accelerate

decompiled_code:
__int64 __fastcall accelerate(_BYTE *a1)
{
while ( *a1 )
{
if ( *a1 == 60 )
return (unsigned int)(char)a1[1];
++a1;
}
return (unsigned int)nonchar_0++;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
while ( *a1 )
{
if ( *a1 == 60 )
return (unsigned int)(char)a1[1];
++a1;
}
return (unsigned int)nonchar_0++;
}

original_code:
static int accelerate(const char *str) {
  static int nonchar = 0x1000;
  while (*str && *str != '<') {
    str++;
  }
  if (*str == '<') {
    return *(str+1);
  } else {
    return nonchar++;
  }
}

canonical_original_code:
static int accelerate(char *str) {
  static int nonchar = 0x1000;
  while (*str && *str != '<') {
    str++;
  }
  if (*str == '<') {
    return *(str+1);
  } else {
    return nonchar++;
  }
}

variable_types: nonchar int


unaccelerate

decompiled_code:
char *__fastcall unaccelerate(const char *a1)
{
const char *v1; // rbx
size_t v2; // rax
char *v3; // r8
char v4; // al
char *v5; // rsi
int v6; // edi
char *v7; // rcx
char *v8; // rdx
char v10; // si

v1 = a1;
v2 = strlen(a1);
v3 = (char *)malloc(v2 + 1);
v4 = *a1;
if ( !*a1 )
return v3;
v5 = v3;
v6 = 0;
while ( 1 )
{
v7 = v5;
v8 = (char *)v1;
if ( v6 || v4 != 60 )
goto LABEL_5;
if ( !v1[1] )
return v3;
v10 = v1[1];
v8 = (char *)(v1 + 2);
v4 = v1[2];
if ( v10 != 62 )
break;
LABEL_11:
if ( !v4 )
return v3;
v6 = 2;
LABEL_5:
*v7 = v4;
v4 = v8[1];
v1 = v8 + 1;
v5 = v7 + 1;
if ( !v4 )
return v3;
}
while ( 1 )
{
*v7++ = v10;
if ( !v4 )
return v3;
++v8;
v10 = v4;
v4 = *v8;
if ( v10 == 62 )
goto LABEL_11;
}
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
const char *v1; // rbx
size_t v2; // rax
char *v3; // r8
char v4; // al
char *v5; // rsi
int v6; // edi
char *v7; // rcx
char *v8; // rdx
char v10; // si

v1 = a1;
v2 = strlen(a1);
v3 = (char *)malloc(v2 + 1);
v4 = *a1;
if ( !*a1 )
return v3;
v5 = v3;
v6 = 0;
while ( 1 )
{
v7 = v5;
v8 = (char *)v1;
if ( v6 || v4 != 60 )
goto LABEL_5;
if ( !v1[1] )
return v3;
v10 = v1[1];
v8 = (char *)(v1 + 2);
v4 = v1[2];
if ( v10 != 62 )
break;
LABEL_11:
if ( !v4 )
return v3;
v6 = 2;
LABEL_5:
*v7 = v4;
v4 = v8[1];
v1 = v8 + 1;
v5 = v7 + 1;
if ( !v4 )
return v3;
}
while ( 1 )
{
*v7++ = v10;
if ( !v4 )
return v3;
++v8;
v10 = v4;
v4 = *v8;
if ( v10 == 62 )
goto LABEL_11;
}
}

original_code:
static char *unaccelerate(const char *str) {
  char *ret,*str2 = malloc(strlen(str)+1);
  int found = 0;
  int i;
  ret = str2;
  while (*str) {
    if (found == 0 && *str == '<') {
      found = 1;
      str++;
    } else if (found == 1 && *str == '>') {
      found = 2;
      str++;
    } else {
      if (found != 1) {
 *(str2++) = *(str++);
      } else {
 *(str2++) = *(str++);
      }
    }
  }
  return ret;
}

canonical_original_code:
static char *unaccelerate(char *str) {
  char *ret; char *str2 = malloc(strlen(str)+1);
  int found = 0;
  int i;
  ret = str2;
  while (*str) {
    if (found == 0 && *str == '<') {
      found = 1;
      str++;
    } else if (found == 1 && *str == '>') {
      found = 2;
      str++;
    } else {
      if (found != 1) {
 *(str2++) = *(str++);
      } else {
 *(str2++) = *(str++);
      }
    }
  }
  return ret;
}

variable_types:
ret
char *

variable_types: found int


OptionHost

decompiled_code:
_BOOL8 __fastcall OptionHost(char *nptr, _DWORD *a2)
{
char *v3; // rbp
__int64 v4; // rsi
__int64 (__fastcall *v5)(char *, __int64); // rax
int v6; // eax
char *v8; // rax
unsigned int v9; // eax

if ( nptr && (v3 = nptr, *nptr) )
{
v8 = strchr(nptr, 58);
if ( v8 )
{
*v8 = 0;
v4 = (unsigned int)strtoul(v8 + 1, 0LL, 0);
v5 = (__int64 (__fastcall *)(char *, __int64))OptionHostSocketCreate;
if ( OptionHostSocketCreate )
goto LABEL_5;
goto LABEL_8;
}
if ( strchr(nptr, 46) || (v9 = atoi(nptr), (v4 = v9) == 0) )
v4 = (unsigned int)OptionHostPortDefault;
else
v3 = "127.0.0.1";
}
else
{
v4 = (unsigned int)OptionHostPortDefault;
v3 = "127.0.0.1";
}
v5 = (__int64 (__fastcall *)(char *, __int64))OptionHostSocketCreate;
if ( OptionHostSocketCreate )
{
LABEL_5:
v6 = v5(v3, v4);
*a2 = v6;
return v6 >= 0;
}
LABEL_8:
*a2 = -1;
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *nptr, _DWORD *a2)
{
char *v3; // rbp
__int64 v4; // rsi
__int64 (__fastcall *v5)(char *, __int64); // rax
int v6; // eax
char *v8; // rax
unsigned int v9; // eax

if ( nptr && (v3 = nptr, *nptr) )
{
v8 = strchr(nptr, 58);
if ( v8 )
{
*v8 = 0;
v4 = (unsigned int)strtoul(v8 + 1, 0LL, 0);
v5 = (__int64 (__fastcall *)(char *, __int64))OptionHostSocketCreate;
if ( OptionHostSocketCreate )
goto LABEL_5;
goto LABEL_8;
}
if ( strchr(nptr, 46) || (v9 = atoi(nptr), (v4 = v9) == 0) )
v4 = (unsigned int)OptionHostPortDefault;
else
v3 = "127.0.0.1";
}
else
{
v4 = (unsigned int)OptionHostPortDefault;
v3 = "127.0.0.1";
}
v5 = (__int64 (__fastcall *)(char *, __int64))OptionHostSocketCreate;
if ( OptionHostSocketCreate )
{
LABEL_5:
v6 = v5(v3, v4);
*a2 = v6;
return v6 >= 0;
}
LABEL_8:
*a2 = -1;
return 0LL;
}

original_code:
int OptionHost(char *arg,void *target0,int opt) {
  int *target = target0;
  char *sport, *host;
  int port;
  if (!arg || arg[0] == 0) {
    host = "127.0.0.1";
    port = OptionHostPortDefault;
  } else {
    sport = strchr(arg,':');
    if (sport) {
      *(sport++) = 0;
      host = arg;
      port = strtoul(sport, ((void *)0), 0);
    } else if (!strchr(arg,'.') && (port = atoi(arg))) {
      host = "127.0.0.1";
    } else {
      host = arg;
      port = OptionHostPortDefault;
    }
  }
  if (OptionHostSocketCreate) {
    *target = OptionHostSocketCreate(host,port);
  } else {
    *target = -1;
  }
  if (*target < 0) {
    return 0;
  }
  return 1;
}

canonical_original_code:
int OptionHost(char *arg, void *target0, int opt) {
  int *target = target0;
  char *sport; char *host;
  int port;
  if (!arg || arg[0] == 0) {
    host = "127.0.0.1";
    port = OptionHostPortDefault;
  } else {
    sport = strchr(arg,':');
    if (sport) {
      *(sport++) = 0;
      host = arg;
      port = strtoul(sport, ((void *)0), 0);
    } else if (!strchr(arg,'.') && (port = atoi(arg))) {
      host = "127.0.0.1";
    } else {
      host = arg;
      port = OptionHostPortDefault;
    }
  }
  if (OptionHostSocketCreate) {
    *target = OptionHostSocketCreate(host,port);
  } else {
    *target = -1;
  }
  if (*target < 0) {
    return 0;
  }
  return 1;
}

variable_types:
arg
char *

variable_types: opt int

variable_types:
target
int *

variable_types:
sport
char *

variable_types:
host
char *

variable_types: port int


OptionString

decompiled_code:
__int64 __fastcall OptionString(char *src, char **a2)
{
size_t v2; // rax
char *v3; // rax

v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
*a2 = v3;
strcpy(v3, src);
return 1LL;
}

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

v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
*a2 = v3;
strcpy(v3, src);
return 1LL;
}

original_code:
int OptionString(char *arg,void *target0,int opt) {
  char **target = target0;
  *target = malloc(strlen(arg)+1);
  strcpy(*target,arg);
  return 1;
}

canonical_original_code:
int OptionString(char *arg, void *target0, int opt) {
  char **target = target0;
  *target = malloc(strlen(arg)+1);
  strcpy(*target,arg);
  return 1;
}

variable_types:
target
char **


OptionBoolean

decompiled_code:
__int64 __fastcall OptionBoolean(__int64 a1, _DWORD *a2)
{
*a2 = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2)
{
*a2 = 1;
return 1LL;
}

original_code:
int OptionBoolean(char *arg,void *target0,int opt) {
  int *target = target0;
  *target = 1;
  return 1;
}

canonical_original_code:
int OptionBoolean(char *arg, void *target0, int opt) {
  int *target = target0;
  *target = 1;
  return 1;
}


decompiled_code:
__int64 __fastcall OptionBoolean0(__int64 a1, _DWORD *a2)
{
*a2 = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2)
{
*a2 = 0;
return 1LL;
}

original_code:
int OptionBoolean0(char *arg,void *target0,int opt) {
  int *target = target0;
  *target = 0;
  return 1;
}

canonical_original_code:
int OptionBoolean0(char *arg, void *target0, int opt) {
  int *target = target0;
  *target = 0;
  return 1;
}


OptionUnsigned

decompiled_code:
__int64 __fastcall OptionUnsigned(const char *a1, _DWORD *a2)
{
if ( a1 )
*a2 = strtoul(a1, 0LL, 0);
else
*a2 = -1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, _DWORD *a2)
{
if ( a1 )
*a2 = strtoul(a1, 0LL, 0);
else
*a2 = -1;
return 1LL;
}

original_code:
int OptionUnsigned(char *arg,void *target0,int opt) {
  unsigned *target = target0;
  if (arg) {
    *target = strtoul(arg,((void *)0),0);
  } else {
    *target = 0xFFFFFFFF;
  }
  return 1;
}

canonical_original_code:
int OptionUnsigned(char *arg, void *target0, int opt) {
  unsigned int *target = target0;
  if (arg) {
    *target = strtoul(arg,((void *)0),0);
  } else {
    *target = 0xFFFFFFFF;
  }
  return 1;
}

variable_types:
target
unsigned int *


OptionSigned

decompiled_code:
__int64 __fastcall OptionSigned(const char *a1, _DWORD *a2)
{
if ( a1 )
*a2 = strtol(a1, 0LL, 0);
else
*a2 = -559038737;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, _DWORD *a2)
{
if ( a1 )
*a2 = strtol(a1, 0LL, 0);
else
*a2 = -559038737;
return 1LL;
}

original_code:
int OptionSigned(char *arg,void *target0,int opt) {
  int *target = target0;
  if (arg) {
    *target = strtol(arg,((void *)0),0);
  } else {
    *target = 0xDEADBEEF;
  }
  return 1;
}

canonical_original_code:
int OptionSigned(char *arg, void *target0, int opt) {
  int *target = target0;
  if (arg) {
    *target = strtol(arg,((void *)0),0);
  } else {
    *target = 0xDEADBEEF;
  }
  return 1;
}


OptionsParse

decompiled_code:
__int64 __fastcall OptionsParse(int a1, char *const *a2, unsigned int *a3)
{
unsigned int *v3; // rax
const char **v4; // r13
int i; // ebx
unsigned int v6; // er12
const char *v7; // rcx
char *v8; // rax
__int64 v9; // rbp
const char *v10; // rsi
char *v11; // rcx
struct option *v12; // r15
struct option *v13; // r14
int v14; // ebp
struct option *v15; // rax
__int64 v16; // r15
const char **v17; // r12
struct option *v18; // rbx
char *v19; // rdi
char *v20; // rax
char *v21; // rdi
int v22; // eax
int v23; // eax
__int64 v24; // rax
__int64 v25; // rdx
__int64 v26; // rbp
char *v27; // rbp
unsigned int v28; // er14
struct option *v29; // rbp
int v30; // er12
unsigned int *v31; // r13
unsigned int v32; // er12
const char **v34; // r12
const char **v35; // rbp
void *v36; // r8
__int64 v37; // rdx
__int64 v38; // [rsp+8h] [rbp-80h]
unsigned int v39; // [rsp+8h] [rbp-80h]
char *shortopts; // [rsp+10h] [rbp-78h]
int v44; // [rsp+2Ch] [rbp-5Ch]
int v45; // [rsp+2Ch] [rbp-5Ch]
int v46; // [rsp+2Ch] [rbp-5Ch]
char *v47; // [rsp+38h] [rbp-50h]
struct option *longopts; // [rsp+40h] [rbp-48h]
struct option *longoptsa; // [rsp+40h] [rbp-48h]
struct option *v50; // [rsp+48h] [rbp-40h]

v3 = a3;
v4 = (const char **)a3;
for ( i = 0; ; ++i )
{
v6 = *v3;
if ( !*v3 && !*((_QWORD *)v3 + 1) && !*((_QWORD *)v3 + 2) )
break;
v3 += 10;
}
v7 = (const char *)*((_QWORD *)v3 + 3);
v8 = (char *)*((_QWORD *)v3 + 4);
v9 = i + 2;
v10 = v7;
v11 = (char *)&unk_26D;
if ( !v10 )
v10 = (const char *)&unk_26D;
if ( v8 )
v11 = v8;
v47 = v11;
v38 = v9;
v12 = (struct option *)malloc(32 * v9);
shortopts = (char *)malloc(3 * i + 2);
*shortopts = 0;
if ( i )
{
v44 = i;
v13 = v12;
longopts = v12;
v14 = 0;
v15 = &v12[i];
v16 = 0LL;
v17 = v4;
v18 = v15;
do
{
v20 = unaccelerate(v17[3]);
v13->flag = 0LL;
v21 = (char *)v17[3];
v13->name = v20;
v13->has_arg = *(_DWORD *)v17;
v22 = accelerate(v21);
v19 = &shortopts[v16];
v13->val = v22;
if ( v22 && v22 <= 254 )
{
*v19 = v22;
v23 = v13->has_arg;
if ( v23 > 0 )
{
shortopts[v14 + 1] = 58;
if ( v23 == 1 )
{
v14 += 2;
}
else
{
shortopts[v14 + 2] = 58;
v14 += 3;
}
}
else
{
++v14;
}
v16 = v14;
v19 = &shortopts[v14];
*v19 = 0;
}
++v13;
v17 += 5;
}
while ( v13 != v18 );
v12 = longopts;
i = v44;
v6 = 0;
v24 = v14 + 1;
v25 = (__int64)&longopts[v38 - 2];
v26 = v38 * 32 - 32;
}
else
{
v19 = shortopts;
v25 = (__int64)v12;
v24 = 1LL;
v26 = 32LL;
}
*v19 = 104;
v27 = (char *)v12 + v26;
*(_QWORD *)v25 = "help";
shortopts[v24] = 0;
*(_DWORD *)(v25 + 8) = 0;
*(_QWORD *)(v25 + 16) = 0LL;
*(_DWORD *)(v25 + 24) = 4095;
v50 = &v12[(unsigned int)(i - 1) + 1];
*(_QWORD *)v27 = 0LL;
*((_DWORD *)v27 + 2) = 0;
*((_QWORD *)v27 + 2) = 0LL;
*((_DWORD *)v27 + 6) = 0;
v45 = 0;
v39 = v6;
LABEL_22:
v28 = getopt_long(a1, a2, shortopts, v12, 0LL);
if ( v28 == -1 )
{
v32 = v39;
free(v12);
free(shortopts);
if ( v45 && !v39 )
v32 = v28;
return v32;
}
v29 = 0LL;
v30 = i;
v31 = a3 + 2;
LABEL_25:
if ( v12[(_QWORD)v29].val != v28 )
goto LABEL_24;
if ( v28 == 4095 )
{
fputs(v10, stderr);
if ( !v30 )
goto LABEL_41;
v46 = v30;
v34 = (const char **)(a3 + 8);
longoptsa = v29;
v35 = &v12->name;
while ( 1 )
{
while ( !*v34 )
{
LABEL_36:
v35 += 4;
v34 += 5;
if ( v50 == (struct option *)v35 )
goto LABEL_40;
}
v37 = *((unsigned int *)v35 + 6);
if ( (int)v37 <= 255 )
{
v36 = &unk_270;
if ( *((int *)v35 + 2) > 0 )
v36 = &unk_26E;
fprintf(stderr, "-%c | --%s%s%s\n", v37, *v35, v36);
goto LABEL_36;
}
fprintf(stderr, "--%s %s\n", *v35, *v34);
v35 += 4;
v34 += 5;
if ( v50 == (struct option *)v35 )
{
LABEL_40:
v30 = v46;
v29 = longoptsa;
LABEL_41:
fputs(v47, stderr);
v45 = 1;
LABEL_24:
v29 = (struct option *)((char *)v29 + 1);
v31 += 10;
if ( v30 < (int)v29 )
{
i = v30;
goto LABEL_22;
}
goto LABEL_25;
}
}
}
++v39;
if ( (*(unsigned int (__fastcall **)(char *, _QWORD, _QWORD))v31)(optarg, *((_QWORD *)v31 + 1), v28) )
goto LABEL_24;
v32 = v39;
free(v12);
free(shortopts);
return v32;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char *const *a2, unsigned int *a3)
{
unsigned int *v3; // rax
const char **v4; // r13
int i; // ebx
unsigned int v6; // er12
const char *v7; // rcx
char *v8; // rax
__int64 v9; // rbp
const char *v10; // rsi
char *v11; // rcx
struct option *v12; // r15
struct option *v13; // r14
int v14; // ebp
struct option *v15; // rax
__int64 v16; // r15
const char **v17; // r12
struct option *v18; // rbx
char *v19; // rdi
char *v20; // rax
char *v21; // rdi
int v22; // eax
int v23; // eax
__int64 v24; // rax
__int64 v25; // rdx
__int64 v26; // rbp
char *v27; // rbp
unsigned int v28; // er14
struct option *v29; // rbp
int v30; // er12
unsigned int *v31; // r13
unsigned int v32; // er12
const char **v34; // r12
const char **v35; // rbp
void *v36; // r8
__int64 v37; // rdx
__int64 v38; // [rsp+8h] [rbp-80h]
unsigned int v39; // [rsp+8h] [rbp-80h]
char *shortopts; // [rsp+10h] [rbp-78h]
int v44; // [rsp+2Ch] [rbp-5Ch]
int v45; // [rsp+2Ch] [rbp-5Ch]
int v46; // [rsp+2Ch] [rbp-5Ch]
char *v47; // [rsp+38h] [rbp-50h]
struct option *longopts; // [rsp+40h] [rbp-48h]
struct option *longoptsa; // [rsp+40h] [rbp-48h]
struct option *v50; // [rsp+48h] [rbp-40h]

v3 = a3;
v4 = (const char **)a3;
for ( i = 0; ; ++i )
{
v6 = *v3;
if ( !*v3 && !*((_QWORD *)v3 + 1) && !*((_QWORD *)v3 + 2) )
break;
v3 += 10;
}
v7 = (const char *)*((_QWORD *)v3 + 3);
v8 = (char *)*((_QWORD *)v3 + 4);
v9 = i + 2;
v10 = v7;
v11 = (char *)&unk_26D;
if ( !v10 )
v10 = (const char *)&unk_26D;
if ( v8 )
v11 = v8;
v47 = v11;
v38 = v9;
v12 = (struct option *)malloc(32 * v9);
shortopts = (char *)malloc(3 * i + 2);
*shortopts = 0;
if ( i )
{
v44 = i;
v13 = v12;
longopts = v12;
v14 = 0;
v15 = &v12[i];
v16 = 0LL;
v17 = v4;
v18 = v15;
do
{
v20 = func1(v17[3]);
v13->flag = 0LL;
v21 = (char *)v17[3];
v13->name = v20;
v13->has_arg = *(_DWORD *)v17;
v22 = func0(v21);
v19 = &shortopts[v16];
v13->val = v22;
if ( v22 && v22 <= 254 )
{
*v19 = v22;
v23 = v13->has_arg;
if ( v23 > 0 )
{
shortopts[v14 + 1] = 58;
if ( v23 == 1 )
{
v14 += 2;
}
else
{
shortopts[v14 + 2] = 58;
v14 += 3;
}
}
else
{
++v14;
}
v16 = v14;
v19 = &shortopts[v14];
*v19 = 0;
}
++v13;
v17 += 5;
}
while ( v13 != v18 );
v12 = longopts;
i = v44;
v6 = 0;
v24 = v14 + 1;
v25 = (__int64)&longopts[v38 - 2];
v26 = v38 * 32 - 32;
}
else
{
v19 = shortopts;
v25 = (__int64)v12;
v24 = 1LL;
v26 = 32LL;
}
*v19 = 104;
v27 = (char *)v12 + v26;
*(_QWORD *)v25 = "help";
shortopts[v24] = 0;
*(_DWORD *)(v25 + 8) = 0;
*(_QWORD *)(v25 + 16) = 0LL;
*(_DWORD *)(v25 + 24) = 4095;
v50 = &v12[(unsigned int)(i - 1) + 1];
*(_QWORD *)v27 = 0LL;
*((_DWORD *)v27 + 2) = 0;
*((_QWORD *)v27 + 2) = 0LL;
*((_DWORD *)v27 + 6) = 0;
v45 = 0;
v39 = v6;
LABEL_22:
v28 = getopt_long(a1, a2, shortopts, v12, 0LL);
if ( v28 == -1 )
{
v32 = v39;
free(v12);
free(shortopts);
if ( v45 && !v39 )
v32 = v28;
return v32;
}
v29 = 0LL;
v30 = i;
v31 = a3 + 2;
LABEL_25:
if ( v12[(_QWORD)v29].val != v28 )
goto LABEL_24;
if ( v28 == 4095 )
{
fputs(v10, stderr);
if ( !v30 )
goto LABEL_41;
v46 = v30;
v34 = (const char **)(a3 + 8);
longoptsa = v29;
v35 = &v12->name;
while ( 1 )
{
while ( !*v34 )
{
LABEL_36:
v35 += 4;
v34 += 5;
if ( v50 == (struct option *)v35 )
goto LABEL_40;
}
v37 = *((unsigned int *)v35 + 6);
if ( (int)v37 <= 255 )
{
v36 = &unk_270;
if ( *((int *)v35 + 2) > 0 )
v36 = &unk_26E;
fprintf(stderr, "-%c | --%s%s%s\n", v37, *v35, v36);
goto LABEL_36;
}
fprintf(stderr, "--%s %s\n", *v35, *v34);
v35 += 4;
v34 += 5;
if ( v50 == (struct option *)v35 )
{
LABEL_40:
v30 = v46;
v29 = longoptsa;
LABEL_41:
fputs(v47, stderr);
v45 = 1;
LABEL_24:
v29 = (struct option *)((char *)v29 + 1);
v31 += 10;
if ( v30 < (int)v29 )
{
i = v30;
goto LABEL_22;
}
goto LABEL_25;
}
}
}
++v39;
if ( (*(unsigned int (__fastcall **)(char *, _QWORD, _QWORD))v31)(optarg, *((_QWORD *)v31 + 1), v28) )
goto LABEL_24;
v32 = v39;
free(v12);
free(shortopts);
return v32;
}

original_code:
int OptionsParse(int argc,char **argv,struct option2 *opts) {
  struct option *long_options;
  char *optstr,*helpstr;
  const char *prolog="",*epilog="";
  int i,n,j,c,total=0,gothelp=0;
  for (n=0;
       opts[n].has_arg||opts[n].f||opts[n].target;
       n++);
  if (opts[n].name) {
    prolog = opts[n].name;
  }
  if (opts[n].help) {
    epilog = opts[n].help;
  }
  long_options = malloc(sizeof(struct option) * (n+2));
  optstr = malloc(2+3*n);
  j=0;
  optstr[j] = 0;
  for (i=0;i<n;i++) {
    long_options[i].name = unaccelerate(opts[i].name);
    long_options[i].has_arg = opts[i].has_arg;
    long_options[i].flag = 0;
    long_options[i].val = accelerate(opts[i].name);
    if (long_options[i].val && long_options[i].val < 0xFF) {
      optstr[j++] = long_options[i].val;
      if (long_options[i].has_arg > 0) {
 optstr[j++] = ':';
      }
      if (long_options[i].has_arg > 1) {
 optstr[j++] = ':';
      }
      optstr[j] = 0;
    }
  }
  long_options[i].name = "help";
  long_options[i].has_arg = 0;
  long_options[i].flag = 0;
  long_options[i].val = 0xFFF;
  long_options[i+1].name = 0;
  long_options[i+1].has_arg = 0;
  long_options[i+1].flag = 0;
  long_options[i+1].val = 0;
  optstr[j++] = 'h';
  optstr[j] = 0;
  while ((c = getopt_long(argc,argv,optstr,long_options,((void *)0))) != -1) {
    for (i=0;i<=n;i++) {
      if (c == long_options[i].val) {
 if (c == 0xFFF) {
   gothelp = 1;
   fprintf(stderr,"%s",prolog);
   for (j=0;j<n;j++) {
     if (opts[j].help) {
       if (long_options[j].val < 0x100) {
  fprintf(stderr,"-%c | --%s%s%s\n",long_options[j].val,
   long_options[j].name,
   (long_options[j].has_arg>0 ? "=" : " "),
   opts[j].help);
       } else {
  fprintf(stderr,"--%s  %s\n",long_options[j].name, opts[j].help);
       }
     }
   }
   fprintf(stderr,"%s",epilog);
 } else if (!++total || !opts[i].f(optarg,opts[i].target,c)) {
   goto OptionsParseDone;
 }
      }
    }
  }
 OptionsParseDone:
  free(long_options);
  free(optstr);
  return (gothelp && total == 0) ? -1 : total;
}

canonical_original_code:
int OptionsParse(int argc, char **argv, struct option2 *opts) {
  struct option *long_options;
  char *optstr; char *helpstr;
  char *prolog = ""; char *epilog = "";
  int i; int n; int j; int c; int total = 0; int gothelp = 0;
  for (n=0;
       opts[n].has_arg||opts[n].f||opts[n].target;
       n++);
  if (opts[n].name) {
    prolog = opts[n].name;
  }
  if (opts[n].help) {
    epilog = opts[n].help;
  }
  long_options = malloc(sizeof(struct option) * (n+2));
  optstr = malloc(2+3*n);
  j=0;
  optstr[j] = 0;
  for (i=0;i<n;i++) {
    long_options[i].name = unaccelerate(opts[i].name);
    long_options[i].has_arg = opts[i].has_arg;
    long_options[i].flag = 0;
    long_options[i].val = accelerate(opts[i].name);
    if (long_options[i].val && long_options[i].val < 0xFF) {
      optstr[j++] = long_options[i].val;
      if (long_options[i].has_arg > 0) {
 optstr[j++] = ':';
      }
      if (long_options[i].has_arg > 1) {
 optstr[j++] = ':';
      }
      optstr[j] = 0;
    }
  }
  long_options[i].name = "help";
  long_options[i].has_arg = 0;
  long_options[i].flag = 0;
  long_options[i].val = 0xFFF;
  long_options[i+1].name = 0;
  long_options[i+1].has_arg = 0;
  long_options[i+1].flag = 0;
  long_options[i+1].val = 0;
  optstr[j++] = 'h';
  optstr[j] = 0;
  while ((c = getopt_long(argc,argv,optstr,long_options,((void *)0))) != -1) {
    for (i=0;i<=n;i++) {
      if (c == long_options[i].val) {
 if (c == 0xFFF) {
   gothelp = 1;
   fprintf(stderr,"%s",prolog);
   for (j=0;j<n;j++) {
     if (opts[j].help) {
       if (long_options[j].val < 0x100) {
  fprintf(stderr,"-%c | --%s%s%s\n",long_options[j].val,
   long_options[j].name,
   (long_options[j].has_arg>0 ? "=" : " "),
   opts[j].help);
       } else {
  fprintf(stderr,"--%s  %s\n",long_options[j].name, opts[j].help);
       }
     }
   }
   fprintf(stderr,"%s",epilog);
 } else if (!++total || !opts[i].f(optarg,opts[i].target,c)) {
   goto OptionsParseDone;
 }
      }
    }
  }
 OptionsParseDone:
  free(long_options);
  free(optstr);
  return (gothelp && total == 0) ? -1 : total;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct option2 { int has_arg; int (*f)(char *arg, void *target, int opt); void *target; char *name; char *help; } *

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

variable_types:
optstr
char *

variable_types:
helpstr
char *

variable_types:
prolog
char *

variable_types:
epilog
char *

variable_types: i int

variable_types: n int

variable_types: j int

variable_types: c int

variable_types: total int

variable_types: gothelp int


TSTimeFini

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

result = *(unsigned int *)(a1 + 72);
if ( (int)result > 0 )
{
result = (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 80) + 8LL))(*(_QWORD *)(a1 + 80));
*(_DWORD *)(a1 + 72) = 0;
}
return result;
}

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

result = *(unsigned int *)(a1 + 72);
if ( (int)result > 0 )
{
result = (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 80) + 8LL))(*(_QWORD *)(a1 + 80));
*(_DWORD *)(a1 + 72) = 0;
}
return result;
}

original_code:
void TSTimeFini(TSTime *me) {
  if (me->InitStatus > 0) {
    me->bus->Fini(me->bus);
    me->InitStatus = 0;
  }
}

canonical_original_code:
void TSTimeFini(struct TSTime *me) {
  if (me->InitStatus > 0) {
    me->bus->Fini(me->bus);
    me->InitStatus = 0;
  }
}

variable_types: struct TSTime { void *(*Init)(struct TSTime *me, void *bus, int adrsMSB, int adrsLSB, int Hz); void (*Fini)(struct TSTime *me); unsigned int (*Wait)(struct TSTime *me, unsigned int microseconds); void (*Delay)(struct TSTime *me, unsigned int microseconds); unsigned int (*Tick)(struct TSTime *me); unsigned int (*usElapsed)(struct TSTime *me, unsigned int start); unsigned int (*usFuture)(struct TSTime *me, unsigned int start, unsigned int microseconds); enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 } (*TimeoutQ)(struct TSTime *me, unsigned int start, unsigned int end); unsigned int (*TPS)(struct TSTime *me); int InitStatus; struct Bus { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); unsigned char (*Peek8)(void *me, int Address); void (*Poke8)(void *me, int Address, unsigned char Value); unsigned short (*Peek16)(void *me, int Address); void (*Poke16)(void *me, int Address, unsigned short Value); unsigned int (*Peek32)(void *me, int Address); void (*Poke32)(void *me, int Address, unsigned int Value); int (*BitGet8)(void *me, int Address, int BitNumber); void (*BitAssign8)(void *me, int Address, int BitNumber, int Value); void (*BitSet8)(void *me, int Address, int BitNumber); void (*BitClear8)(void *me, int Address, int BitNumber); int (*BitGet16)(void *me, int Address, int BitNumber); void (*BitAssign16)(void *me, int Address, int BitNumber, int Value); void (*BitSet16)(void *me, int Address, int BitNumber); void (*BitClear16)(void *me, int Address, int BitNumber); int (*BitGet32)(void *me, int Address, int BitNumber); void (*BitAssign32)(void *me, int Address, int BitNumber, int Value); void (*BitSet32)(void *me, int Address, int BitNumber); void (*BitClear32)(void *me, int Address, int BitNumber); void (*PeekStream)(void *me, int address, int direction, char *dest); void (*PokeStream)(void *me, int address, int direction, char *data); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); int (*BitToggle8)(void *me, int Address, int BitNumber); int (*BitToggle16)(void *me, int Address, int BitNumber); int (*BitToggle32)(void *me, int Address, int BitNumber); unsigned char (*Assign8X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned short (*Assign16X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned int (*Assign32X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned char (*BitsGet8)(void *me, int Address, int BitMSB, int BitLSB); unsigned short (*BitsGet16)(void *me, int Address, int BitMSB, int BitLSB); unsigned int (*BitsGet32)(void *me, int Address, int BitMSB, int BitLSB); int InitStatus; unsigned int LockBase; int deferlockW; int deferlockR; } *bus; int adrsMSB; int adrsLSB; int Hz; } *

user_defined_types: struct TSTime { void *(*Init)(struct TSTime *me, void *bus, int adrsMSB, int adrsLSB, int Hz); void (*Fini)(struct TSTime *me); unsigned int (*Wait)(struct TSTime *me, unsigned int microseconds); void (*Delay)(struct TSTime *me, unsigned int microseconds); unsigned int (*Tick)(struct TSTime *me); unsigned int (*usElapsed)(struct TSTime *me, unsigned int start); unsigned int (*usFuture)(struct TSTime *me, unsigned int start, unsigned int microseconds); enum TimeResult (*TimeoutQ)(struct TSTime *me, unsigned int start, unsigned int end); unsigned int (*TPS)(struct TSTime *me); int InitStatus; struct Bus *bus; int adrsMSB; int adrsLSB; int Hz; }


TSTimeTick

original_code:
unsigned TSTimeTick(TSTime *me) {
  return _TSTimeTick(me);
}

canonical_original_code:
unsigned int TSTimeTick(struct TSTime *me) {
  return _TSTimeTick(me);
}


TSTimeusElapsed

decompiled_code:
__int64 __fastcall TSTimeusElapsed(__int64 a1, int a2)
{
int v3; // er13
unsigned __int16 v4; // r14
int v5; // eax
__int64 result; // rax

v3 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 88));
v4 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 92));
v5 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 88));
if ( (_WORD)v3 == (_WORD)v5 )
result = (v3 << 16) + (unsigned int)v4 - a2;
else
result = (v5 << 16)
+ (unsigned int)(*(unsigned __int16 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 92))
- a2;
return result;
}

original_code:
unsigned TSTimeusElapsed(TSTime *time,unsigned start) {
  unsigned now = _TSTimeTick(time);
  if (now < start) {
    return 1 * ((unsigned)(-start) + now);
  } else {
    return 1 * (now - start);
  }
}

canonical_original_code:
unsigned int TSTimeusElapsed(struct TSTime *time, unsigned int start) {
  unsigned int now = _TSTimeTick(time);
  if (now < start) {
    return 1 * ((unsigned int)(-start) + now);
  } else {
    return 1 * (now - start);
  }
}

variable_types:
start
unsigned int

variable_types:
now
unsigned int


TSTimeusFuture

decompiled_code:
__int64 __fastcall TSTimeusFuture(__int64 a1, int a2, int a3)
{
return (unsigned int)(a2 + a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3)
{
return (unsigned int)(a2 + a3);
}

original_code:
unsigned TSTimeusFuture(TSTime *time,unsigned start,unsigned us) {
  return start + us;
}

canonical_original_code:
unsigned int TSTimeusFuture(struct TSTime *time, unsigned int start, unsigned int us) {
  return start + us;
}

variable_types:
us
unsigned int


TSTimeTimeoutQ

decompiled_code:
__int64 __fastcall TSTimeTimeoutQ(__int64 a1, unsigned int a2, unsigned int a3)
{
int v5; // er15
unsigned __int16 v6; // r14
int v7; // eax
unsigned int v8; // ebp
__int64 result; // rax

v5 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 88));
v6 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 92));
v7 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 88));
if ( (_WORD)v5 == (_WORD)v7 )
v8 = (v5 << 16) + v6;
else
v8 = (*(unsigned __int16 (__fastcall **)(_QWORD, _QWORD))(*(_QWORD *)(a1 + 80) + 56LL))(
*(_QWORD *)(a1 + 80),
*(unsigned int *)(a1 + 92))
+ (v7 << 16);
if ( a3 > a2 )
return (a2 > v8) | (unsigned __int8)(a3 <= v8);
result = 1LL;
if ( a3 != a2 )
result = (a2 > v8) & (unsigned __int8)(a3 <= v8);
return result;
}

original_code:
TimeResult TSTimeTimeoutQ(TSTime *time,unsigned start,unsigned end) {
  unsigned now = _TSTimeTick(time);
  if (end > start) {
    return now >= end || now < start;
  } else if (end == start) {
    return 1;
  } else {
    return !(now >= start || now < end);
  }
}

canonical_original_code:
enum TimeResult TSTimeTimeoutQ(struct TSTime *time, unsigned int start, unsigned int end) {
  unsigned int now = _TSTimeTick(time);
  if (end > start) {
    return now >= end || now < start;
  } else if (end == start) {
    return 1;
  } else {
    return !(now >= start || now < end);
  }
}

variable_types:
end
unsigned int

return_type: enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 }


TSTimeTPS

decompiled_code:
__int64 __fastcall TSTimeTPS(__int64 a1)
{
return *(unsigned int *)(a1 + 96);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned int *)(a1 + 96);
}

original_code:
unsigned TSTimeTPS(TSTime *me) {
  return me->Hz;
}

canonical_original_code:
unsigned int TSTimeTPS(struct TSTime *me) {
  return me->Hz;
}


TSTimeWait

decompiled_code:
__int64 TSTimeWait()
{
return SystemMicroSecondWait();
}

canonical_decompiled_code:
__int64 func7()
{
return SystemMicroSecondWait();
}

original_code:
unsigned TSTimeWait(TSTime *me,unsigned us) {
  return SystemMicroSecondWait(me,us);
}

canonical_original_code:
unsigned int TSTimeWait(struct TSTime *me, unsigned int us) {
  return SystemMicroSecondWait(me,us);
}


TSTimeDelay

decompiled_code:
__int64 TSTimeDelay()
{
return SystemMicroSecondWait();
}

canonical_decompiled_code:
__int64 func8()
{
return SystemMicroSecondWait();
}

original_code:
void TSTimeDelay(TSTime *me,unsigned us) {
  SystemMicroSecondWait(me,us);
}

canonical_original_code:
void TSTimeDelay(struct TSTime *me, unsigned int us) {
  SystemMicroSecondWait(me,us);
}


decompiled_code:
__int64 tsrelay8ArchNextSubArch()
{
return tsrelay8Next;
}

canonical_decompiled_code:
__int64 func0()
{
return tsrelay8Next;
}

canonical_original_code:
struct Arch *tsrelay8ArchNextSubArch() {
  return tsrelay8Next;
}

return_type: struct Arch { struct Arch *(*Init)(); void *(*Function)(int class, int inst); struct Arch *(*NextSubArch)(); void (*NextSubArchSet)(struct Arch *); int (*CANBusId)(int inst); } *


decompiled_code:
void __fastcall tsrelay8NextSubArchSet(__int64 a1)
{
tsrelay8Next = a1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
tsrelay8Next = a1;
}

original_code:
void tsrelay8NextSubArchSet(Arch *arch) {
  tsrelay8Next = arch;
}

canonical_original_code:
void tsrelay8NextSubArchSet(struct Arch *arch) {
  tsrelay8Next = arch;
}

variable_types: struct Arch { struct Arch *(*Init)(); void *(*Function)(int class, int inst); struct Arch *(*NextSubArch)(); void (*NextSubArchSet)(struct Arch *); int (*CANBusId)(int inst); } *


decompiled_code:
__int64 tsrelay8ArchInit()
{
__int64 v0; // r12
__int64 v2; // rbx
__int64 v3; // rbp

v0 = tsrelay8_0;
if ( tsrelay8_0 )
return v0;
v2 = 0LL;
v3 = BusInit(2LL);
(*(void (__fastcall **)(__int64, _QWORD, __int64))(v3 + 16))(v3, 0LL, 2LL);
do
{
if ( (*(unsigned __int8 (__fastcall **)(__int64, _QWORD))(v3 + 40))(v3, (unsigned int)(16 * v2 + 320)) == 0x9B )
r8present[v2] = 1;
++v2;
}
while ( v2 != 4 );
(*(void (__fastcall **)(__int64, _QWORD, __int64))(v3 + 24))(v3, 0LL, 2LL);
if ( !r8present[0] )
return v0;
tsrelay8_0 = (__int64)tsrelay8Arch;
dioctl_config_add2(
&Xtsrelay8_dioctl_config,
(unsigned int)Xtsrelay8_dioctl_config_len,
(unsigned int)Ytsrelay8_dioctl_config_len);
return tsrelay8_0;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r12
__int64 v2; // rbx
__int64 v3; // rbp

v0 = tsrelay8_0;
if ( tsrelay8_0 )
return v0;
v2 = 0LL;
v3 = BusInit(2LL);
(*(void (__fastcall **)(__int64, _QWORD, __int64))(v3 + 16))(v3, 0LL, 2LL);
do
{
if ( (*(unsigned __int8 (__fastcall **)(__int64, _QWORD))(v3 + 40))(v3, (unsigned int)(16 * v2 + 320)) == 0x9B )
r8present[v2] = 1;
++v2;
}
while ( v2 != 4 );
(*(void (__fastcall **)(__int64, _QWORD, __int64))(v3 + 24))(v3, 0LL, 2LL);
if ( !r8present[0] )
return v0;
tsrelay8_0 = (__int64)tsrelay8Arch;
dioctl_config_add2(
&Xtsrelay8_dioctl_config,
(unsigned int)Xtsrelay8_dioctl_config_len,
(unsigned int)Ytsrelay8_dioctl_config_len);
return tsrelay8_0;
}

original_code:
Arch *tsrelay8ArchInit(int model) {
  static Arch *tsrelay8;
  Bus *pc104;
  int i,val;
  if (tsrelay8) return tsrelay8;
  pc104 = BusInit(2);
  pc104->Lock(pc104,0,SHARED);
  for (i=0;i<4;i++) {
    val = pc104->Peek8(pc104,0x140+0x10*i);
    if (val == 0x9B) r8present[i] = 1;
  }
  pc104->Unlock(pc104,0,SHARED);
  if (r8present[0] == 0 && r8present[0] == 0 && r8present[0] == 0 && r8present[0] == 0){
    return 0;
  }
  tsrelay8 = &tsrelay8Arch;
  dioctl_config_add2(Xtsrelay8_dioctl_config,Xtsrelay8_dioctl_config_len,Ytsrelay8_dioctl_config_len);
  return tsrelay8;
}

canonical_original_code:
struct Arch *tsrelay8ArchInit(int model) {
  static struct Arch *tsrelay8;
  struct Bus *pc104;
  int i; int val;
  if (tsrelay8) return tsrelay8;
  pc104 = BusInit(2);
  pc104->Lock(pc104,0,SHARED);
  for (i=0;i<4;i++) {
    val = pc104->Peek8(pc104,0x140+0x10*i);
    if (val == 0x9B) r8present[i] = 1;
  }
  pc104->Unlock(pc104,0,SHARED);
  if (r8present[0] == 0 && r8present[0] == 0 && r8present[0] == 0 && r8present[0] == 0){
    return 0;
  }
  tsrelay8 = &tsrelay8Arch;
  dioctl_config_add2(Xtsrelay8_dioctl_config,Xtsrelay8_dioctl_config_len,Ytsrelay8_dioctl_config_len);
  return tsrelay8;
}

variable_types: model int

variable_types: struct Bus { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); unsigned char (*Peek8)(void *me, int Address); void (*Poke8)(void *me, int Address, unsigned char Value); unsigned short (*Peek16)(void *me, int Address); void (*Poke16)(void *me, int Address, unsigned short Value); unsigned int (*Peek32)(void *me, int Address); void (*Poke32)(void *me, int Address, unsigned int Value); int (*BitGet8)(void *me, int Address, int BitNumber); void (*BitAssign8)(void *me, int Address, int BitNumber, int Value); void (*BitSet8)(void *me, int Address, int BitNumber); void (*BitClear8)(void *me, int Address, int BitNumber); int (*BitGet16)(void *me, int Address, int BitNumber); void (*BitAssign16)(void *me, int Address, int BitNumber, int Value); void (*BitSet16)(void *me, int Address, int BitNumber); void (*BitClear16)(void *me, int Address, int BitNumber); int (*BitGet32)(void *me, int Address, int BitNumber); void (*BitAssign32)(void *me, int Address, int BitNumber, int Value); void (*BitSet32)(void *me, int Address, int BitNumber); void (*BitClear32)(void *me, int Address, int BitNumber); void (*PeekStream)(void *me, int address, int direction, char *dest); void (*PokeStream)(void *me, int address, int direction, char *data); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); int (*BitToggle8)(void *me, int Address, int BitNumber); int (*BitToggle16)(void *me, int Address, int BitNumber); int (*BitToggle32)(void *me, int Address, int BitNumber); unsigned char (*Assign8X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned short (*Assign16X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned int (*Assign32X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned char (*BitsGet8)(void *me, int Address, int BitMSB, int BitLSB); unsigned short (*BitsGet16)(void *me, int Address, int BitMSB, int BitLSB); unsigned int (*BitsGet32)(void *me, int Address, int BitMSB, int BitLSB); int InitStatus; unsigned int LockBase; int deferlockW; int deferlockR; } *

variable_types: val int

user_defined_types: struct Arch { struct Arch *(*Init)(); void *(*Function)(int class, int inst); struct Arch *(*NextSubArch)(); void (*NextSubArchSet)(struct Arch *); int (*CANBusId)(int inst); }


decompiled_code:
__int64 __fastcall tsrelay8__DIORawInit1(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

if ( !r8present[1] )
return tsrelay8__DIORawInit0(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

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

if ( !r8present[1] )
return func6(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

original_code:
DIORaw *tsrelay8__DIORawInit1(DIORaw *dioraw0,int inst) {
  if (!r8present[1]) {
    return tsrelay8__DIORawInit0(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}

canonical_original_code:
struct DIORaw *tsrelay8__DIORawInit1(struct DIORaw *dioraw0, int inst) {
  if (!r8present[1]) {
    return tsrelay8__DIORawInit0(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}

variable_types: inst int

return_type: struct DIORaw { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); void (*DirSet)(void *me, int num, int asOutput); void (*DataSet)(void *me, int num, int asHigh); int (*DirGet)(void *me, int num); int (*DataGet)(void *me, int num); unsigned int (*Count)(void *me); int InitStatus; } *


decompiled_code:
__int64 __fastcall tsrelay8__DIORawInit2(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

if ( !r8present[2] )
return tsrelay8__DIORawInit1(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

if ( !r8present[2] )
return func3(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

original_code:
DIORaw *tsrelay8__DIORawInit2(DIORaw *dioraw0,int inst) {
  if (!r8present[2]) {
    return tsrelay8__DIORawInit1(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}

canonical_original_code:
struct DIORaw *tsrelay8__DIORawInit2(struct DIORaw *dioraw0, int inst) {
  if (!r8present[2]) {
    return tsrelay8__DIORawInit1(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}

user_defined_types: struct DIORaw { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); void (*DirSet)(void *me, int num, int asOutput); void (*DataSet)(void *me, int num, int asHigh); int (*DirGet)(void *me, int num); int (*DataGet)(void *me, int num); unsigned int (*Count)(void *me); int InitStatus; }


decompiled_code:
__int64 __fastcall tsrelay8__DIORawInit3(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

if ( !r8present[3] )
return tsrelay8__DIORawInit2(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

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

if ( !r8present[3] )
return func4(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

original_code:
DIORaw *tsrelay8__DIORawInit3(DIORaw *dioraw0,int inst) {
  if (!r8present[3]) {
    return tsrelay8__DIORawInit2(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}

canonical_original_code:
struct DIORaw *tsrelay8__DIORawInit3(struct DIORaw *dioraw0, int inst) {
  if (!r8present[3]) {
    return tsrelay8__DIORawInit2(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}


decompiled_code:
__int64 __fastcall tsrelay8__DIORawInit0(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

if ( !r8present[0] )
return tsrelay8__DIORawInit3(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

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

if ( !r8present[0] )
return func5(a1, a2);
v2 = BusInit(2LL);
return tsRelay8DIORawInit((char *)&r8dio + 112 * (int)a2, v2, 16 * (a2 + 20));
}

original_code:
DIORaw *tsrelay8__DIORawInit0(DIORaw *dioraw0,int inst) {
  if (!r8present[0]) {
    return tsrelay8__DIORawInit3(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}

canonical_original_code:
struct DIORaw *tsrelay8__DIORawInit0(struct DIORaw *dioraw0, int inst) {
  if (!r8present[0]) {
    return tsrelay8__DIORawInit3(dioraw0,inst);
  }
  return tsRelay8DIORawInit(&r8dio[inst],BusInit(2),0x140 + inst * 0x10);
}


decompiled_code:
__int64 __fastcall tsrelay8__DIOInit0(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rax

v2 = tsrelay8__DIORawInit0(0LL, a2);
if ( a2 > 3 || !r8present[a2] )
return DummyDIOInit((char *)&r8dummyDIO + 128 * (__int64)(int)a2, 8LL);
v3 = v2;
Relay8DIOCapabilities = 0x606060606060606LL;
r8pdio[21 * (int)a2 + 19] = &Relay8DIOCapabilities;
v4 = BusInit(2LL);
return PhysicalDIOInit(&r8pdio[21 * (int)a2], v4, v3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rax

v2 = func6(0LL, a2);
if ( a2 > 3 || !r8present[a2] )
return DummyDIOInit((char *)&r8dummyDIO + 128 * (__int64)(int)a2, 8LL);
v3 = v2;
Relay8DIOCapabilities = 0x606060606060606LL;
r8pdio[21 * (int)a2 + 19] = &Relay8DIOCapabilities;
v4 = BusInit(2LL);
return PhysicalDIOInit(&r8pdio[21 * (int)a2], v4, v3);
}

original_code:
DIO *tsrelay8__DIOInit0(DIO *dio,int inst) {
  int i;
  DIORaw *dioraw = tsrelay8__DIORawInit0(0,inst);
  if (inst >= 0 && inst <= 3 && r8present[inst]) {
    for (i=0;i<8;i++) {
      Relay8DIOCapabilities[i] = DIO_OUTPUT_ONLY;
    }
    r8pdio[inst].Caps = Relay8DIOCapabilities;
    return PhysicalDIOInit(&r8pdio[inst],BusInit(2),dioraw);
  } else {
    return DummyDIOInit(&r8dummyDIO[inst],8);
  }
}

canonical_original_code:
struct DIO *tsrelay8__DIOInit0(struct DIO *dio, int inst) {
  int i;
  struct DIORaw *dioraw = tsrelay8__DIORawInit0(0,inst);
  if (inst >= 0 && inst <= 3 && r8present[inst]) {
    for (i=0;i<8;i++) {
      Relay8DIOCapabilities[i] = DIO_OUTPUT_ONLY;
    }
    r8pdio[inst].Caps = Relay8DIOCapabilities;
    return PhysicalDIOInit(&r8pdio[inst],BusInit(2),dioraw);
  } else {
    return DummyDIOInit(&r8dummyDIO[inst],8);
  }
}

variable_types:
dio
struct DIO *

variable_types: struct DIORaw { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); void (*DirSet)(void *me, int num, int asOutput); void (*DataSet)(void *me, int num, int asHigh); int (*DirGet)(void *me, int num); int (*DataGet)(void *me, int num); unsigned int (*Count)(void *me); int InitStatus; } *

return_type: struct DIO { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); void (*Set)(void *me, int DIONum, enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } State); enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } (*Get)(void *me, int DIONum); void (*SetAsync)(void *me, int DIONum, enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } State); enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } (*GetAsync)(void *me, int DIONum); void (*Wait)(void *me, int *match, int min, int max, int *nh, int *nl); unsigned int (*Count)(void *me); enum DIOCaps { DIO_NOT_PRESENT=0, DIO_CAN_INPUT=1, DIO_CAN_DRIVE_HIGH=2, DIO_HIGH_SIDE=3, DIO_CAN_DRIVE_LOW=4, DIO_LOW_SIDE=5, DIO_OUTPUT_ONLY=6, DIO_NORMAL=7 } (*Capabilities)(void *me, unsigned int num); int (*GetMulti)(void *me, char *state, int offset); int InitStatus; } *

user_defined_types: struct DIO { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); void (*Set)(void *me, int DIONum, enum DIOState State); enum DIOState (*Get)(void *me, int DIONum); void (*SetAsync)(void *me, int DIONum, enum DIOState State); enum DIOState (*GetAsync)(void *me, int DIONum); void (*Wait)(void *me, int *match, int min, int max, int *nh, int *nl); unsigned int (*Count)(void *me); enum DIOCaps (*Capabilities)(void *me, unsigned int num); int (*GetMulti)(void *me, char *state, int offset); int InitStatus; }


decompiled_code:
// attributes: thunk
__int64 __fastcall tsrelay8__DIOInit1(__int64 a1, unsigned int a2)
{
return tsrelay8__DIOInit0(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
return func7(a1, a2);
}

original_code:
DIO *tsrelay8__DIOInit1(DIO *dio,int inst) {
  return tsrelay8__DIOInit0(dio,inst);
}

canonical_original_code:
struct DIO *tsrelay8__DIOInit1(struct DIO *dio, int inst) {
  return tsrelay8__DIOInit0(dio,inst);
}

user_defined_types: enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 }

user_defined_types: enum DIOCaps { DIO_NOT_PRESENT=0, DIO_CAN_INPUT=1, DIO_CAN_DRIVE_HIGH=2, DIO_HIGH_SIDE=3, DIO_CAN_DRIVE_LOW=4, DIO_LOW_SIDE=5, DIO_OUTPUT_ONLY=6, DIO_NORMAL=7 }


decompiled_code:
// attributes: thunk
__int64 __fastcall tsrelay8__DIOInit2(__int64 a1, unsigned int a2)
{
return tsrelay8__DIOInit1(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
return func8(a1, a2);
}

original_code:
DIO *tsrelay8__DIOInit2(DIO *dio,int inst) {
  return tsrelay8__DIOInit0(dio,inst);
}

canonical_original_code:
struct DIO *tsrelay8__DIOInit2(struct DIO *dio, int inst) {
  return tsrelay8__DIOInit0(dio,inst);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall tsrelay8__DIOInit3(__int64 a1, unsigned int a2)
{
return tsrelay8__DIOInit1(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2)
{
return func8(a1, a2);
}

original_code:
DIO *tsrelay8__DIOInit3(DIO *dio,int inst) {
  return tsrelay8__DIOInit0(dio,inst);
}

canonical_original_code:
struct DIO *tsrelay8__DIOInit3(struct DIO *dio, int inst) {
  return tsrelay8__DIOInit0(dio,inst);
}


ArrayFree

decompiled_code:
void __fastcall ArrayFree(__int64 a1)
{
free((void *)(a1 - 12));
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
free((void *)(a1 - 12));
}

original_code:
void ArrayFree(const void *arr) {
  unsigned *ptr = (unsigned *)arr;
  free(ptr-3);
}

canonical_original_code:
void ArrayFree(void *arr) {
  unsigned int *ptr = (unsigned *)arr;
  free(ptr-3);
}

variable_types:
arr
void *

variable_types:
ptr
unsigned int *


ASCIIZ

decompiled_code:
char *__fastcall ASCIIZ(char *src)
{
unsigned int v1; // ebx
char *v2; // rax

v1 = strlen(src);
v2 = (char *)ArrayAlloc(v1, 1u);
return strncpy(v2, src, v1);
}

canonical_decompiled_code:
char *__fastcall func12(char *src)
{
unsigned int v1; // ebx
char *v2; // rax

v1 = strlen(src);
v2 = (char *)ArrayAlloc(v1, 1u);
return strncpy(v2, src, v1);
}

original_code:
char *ASCIIZ(const char *str) {
  unsigned len = strlen(str);
  char *str2 = (char *)ArrayAlloc(len,1);
  strncpy(str2,str,len);
  return str2;
}

canonical_original_code:
char *ASCIIZ(char *str) {
  unsigned int len = strlen(str);
  char *str2 = (char *)ArrayAlloc(len,1);
  strncpy(str2,str,len);
  return str2;
}

variable_types:
str
char *

variable_types:
len
unsigned int


ArraySizeAuto

decompiled_code:
__int64 __fastcall ArraySizeAuto(__int64 a1, int a2)
{
*(_DWORD *)(a1 - 4) = a2;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
*(_DWORD *)(a1 - 4) = a2;
return a1;
}

original_code:
void *ArraySizeAuto(void *arr,unsigned count) {
  unsigned *ptr = (unsigned *)arr;
  ptr -= 3;
  ptr[2] = count;
  return &ptr[3];
}

canonical_original_code:
void *ArraySizeAuto(void *arr, unsigned int count) {
  unsigned int *ptr = (unsigned *)arr;
  ptr -= 3;
  ptr[2] = count;
  return &ptr[3];
}

variable_types:
count
unsigned int


ArrayElementSize

decompiled_code:
__int64 __fastcall ArrayElementSize(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

original_code:
unsigned ArrayElementSize(const void *array) {
  return _ArrayElementSize(array);
}

canonical_original_code:
unsigned int ArrayElementSize(void *array) {
  return _ArrayElementSize(array);
}

variable_types:
array
void *


ArrayLength

decompiled_code:
__int64 __fastcall ArrayLength(__int64 a1)
{
return *(unsigned int *)(a1 - 4);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return *(unsigned int *)(a1 - 4);
}

original_code:
unsigned ArrayLength(const void *array) {
  return _ArrayLength(array);
}

canonical_original_code:
unsigned int ArrayLength(void *array) {
  return _ArrayLength(array);
}


ArrayFreeFree

decompiled_code:
void __fastcall ArrayFreeFree(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( *(_DWORD *)(a1 - 4) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(a1 + 8 * v2);
if ( v3 )
ArrayFree(v3);
++v2;
}
while ( *(_DWORD *)(a1 - 4) > (unsigned int)v2 );
}
ArrayFree(a1);
}

original_code:
void ArrayFreeFree(const void *arr0) {
  const void * const *arr = (const void * const *)arr0;
  int i;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) ArrayFree(arr[i]);
  }
  ArrayFree(arr);
}

canonical_original_code:
void ArrayFreeFree(void *arr0) {
  void **arr = (const void * const *)arr0;
  int i;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) ArrayFree(arr[i]);
  }
  ArrayFree(arr);
}

variable_types:
arr
void **

variable_types: i int


ArrayFreeFreeFree

decompiled_code:
void __fastcall ArrayFreeFreeFree(__int64 a1)
{
__int64 v2; // rbp
__int64 v3; // rdi
__int64 v4; // rbx

if ( *(_DWORD *)(a1 - 4) )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = *(_QWORD *)(a1 + 8 * v2);
if ( v3 )
break;
if ( *(_DWORD *)(a1 - 4) <= (unsigned int)++v2 )
goto LABEL_11;
}
if ( *(_DWORD *)(v3 - 4) )
{
v4 = 0LL;
do
{
if ( *(_QWORD *)(v3 + 8 * v4) )
{
ArrayFree(*(_QWORD *)(v3 + 8 * v4));
v3 = *(_QWORD *)(a1 + 8 * v2);
}
++v4;
}
while ( *(_DWORD *)(v3 - 4) > (unsigned int)v4 );
}
ArrayFree(v3);
++v2;
}
while ( *(_DWORD *)(a1 - 4) > (unsigned int)v2 );
}
LABEL_11:
ArrayFree(a1);
}

original_code:
void ArrayFreeFreeFree(const void *arr0) {
  const void ** const *arr = (const void ** const *)arr0;
  int i,j;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) {
      for (j=0;j<_ArrayLength(arr[i]);j++) {
 if (arr[i][j]) ArrayFree(arr[i][j]);
      }
      ArrayFree(arr[i]);
    }
  }
  ArrayFree(arr);
}

canonical_original_code:
void ArrayFreeFreeFree(void *arr0) {
  void ***arr = (const void ** const *)arr0;
  int i; int j;
  for (i=0;i<_ArrayLength(arr);i++) {
    if (arr[i]) {
      for (j=0;j<_ArrayLength(arr[i]);j++) {
 if (arr[i][j]) ArrayFree(arr[i][j]);
      }
      ArrayFree(arr[i]);
    }
  }
  ArrayFree(arr);
}

variable_types:
arr
void ***

variable_types: j int


ArrayCompareFunction

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

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

original_code:
void *ArrayCompareFunction(const void *array) {
  return ArrayCompareFunction(array);
}

canonical_original_code:
void *ArrayCompareFunction(void *array) {
  return ArrayCompareFunction(array);
}


LinuxTWIFini

decompiled_code:
__int64 __fastcall LinuxTWIFini(__int64 a1)
{
int v2; // edi
__int64 result; // rax

(*(void (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 64) + 8LL))(*(_QWORD *)(a1 + 64));
v2 = *(_DWORD *)(a1 + 88);
if ( v2 )
{
close(v2);
*(_DWORD *)(a1 + 88) = 0;
}
result = *(unsigned int *)(a1 + 56);
if ( (int)result > 0 )
*(_DWORD *)(a1 + 56) = 0;
return result;
}

original_code:
void LinuxTWIFini(LinuxTWI *twi){
  twi->bus->Fini(twi->bus);
  if (twi->f) {
    close(twi->f);
    twi->f = 0;
  }
  if (twi->InitStatus > 0) twi->InitStatus = 0;
}

canonical_original_code:
void LinuxTWIFini(struct LinuxTWI *twi){
  twi->bus->Fini(twi->bus);
  if (twi->f) {
    close(twi->f);
    twi->f = 0;
  }
  if (twi->InitStatus > 0) twi->InitStatus = 0;
}

variable_types: struct LinuxTWI { void *(*Init)(struct LinuxTWI *me, char *devfile); void (*Fini)(struct LinuxTWI *me); int (*Lock)(struct LinuxTWI *me, unsigned int num, int flags); int (*Unlock)(struct LinuxTWI *me, unsigned int num, int flags); int (*Preempt)(struct LinuxTWI *me); enum TWIResult { TWISuccess=1, TWIErrorPortInvalid=-1, TWIErrorModeUnsupported=-2, TWIErrorBaudUnconstrained=-3, TWIErrorHardware=-4, TWIErrorHandle=-5, TWIErrorWriteNAck=-6, TWIErrorDataNAck=-7, TWIErrorReadNack=-8, TWIErrorSDALow=-9, TWIErrorSCLLow=-10, TWIErrorAdrsLen=-11, TWIErrorTimeout=-12, TWIErrorOverrun=-13, TWIErrorArbLost=-14, TWIErrorUnknown=-999, TWIErrorOpInvalid=-15 } (*Write)(struct LinuxTWI *me, int devadr, int adrslen, int adrs, char *bytes); enum TWIResult { TWISuccess=1, TWIErrorPortInvalid=-1, TWIErrorModeUnsupported=-2, TWIErrorBaudUnconstrained=-3, TWIErrorHardware=-4, TWIErrorHandle=-5, TWIErrorWriteNAck=-6, TWIErrorDataNAck=-7, TWIErrorReadNack=-8, TWIErrorSDALow=-9, TWIErrorSCLLow=-10, TWIErrorAdrsLen=-11, TWIErrorTimeout=-12, TWIErrorOverrun=-13, TWIErrorArbLost=-14, TWIErrorUnknown=-999, TWIErrorOpInvalid=-15 } (*Read)(struct LinuxTWI *me, int devadr, int adrslen, int adrs, char *bytes); int InitStatus; struct Bus { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); unsigned char (*Peek8)(void *me, int Address); void (*Poke8)(void *me, int Address, unsigned char Value); unsigned short (*Peek16)(void *me, int Address); void (*Poke16)(void *me, int Address, unsigned short Value); unsigned int (*Peek32)(void *me, int Address); void (*Poke32)(void *me, int Address, unsigned int Value); int (*BitGet8)(void *me, int Address, int BitNumber); void (*BitAssign8)(void *me, int Address, int BitNumber, int Value); void (*BitSet8)(void *me, int Address, int BitNumber); void (*BitClear8)(void *me, int Address, int BitNumber); int (*BitGet16)(void *me, int Address, int BitNumber); void (*BitAssign16)(void *me, int Address, int BitNumber, int Value); void (*BitSet16)(void *me, int Address, int BitNumber); void (*BitClear16)(void *me, int Address, int BitNumber); int (*BitGet32)(void *me, int Address, int BitNumber); void (*BitAssign32)(void *me, int Address, int BitNumber, int Value); void (*BitSet32)(void *me, int Address, int BitNumber); void (*BitClear32)(void *me, int Address, int BitNumber); void (*PeekStream)(void *me, int address, int direction, char *dest); void (*PokeStream)(void *me, int address, int direction, char *data); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); int (*BitToggle8)(void *me, int Address, int BitNumber); int (*BitToggle16)(void *me, int Address, int BitNumber); int (*BitToggle32)(void *me, int Address, int BitNumber); unsigned char (*Assign8X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned short (*Assign16X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned int (*Assign32X)(void *me, int Address, int BitMSB, int BitLSB, int Value); unsigned char (*BitsGet8)(void *me, int Address, int BitMSB, int BitLSB); unsigned short (*BitsGet16)(void *me, int Address, int BitMSB, int BitLSB); unsigned int (*BitsGet32)(void *me, int Address, int BitMSB, int BitLSB); int InitStatus; unsigned int LockBase; int deferlockW; int deferlockR; } *bus; int LockNum; char *devfile; int f; } *

user_defined_types: struct LinuxTWI { void *(*Init)(struct LinuxTWI *me, char *devfile); void (*Fini)(struct LinuxTWI *me); int (*Lock)(struct LinuxTWI *me, unsigned int num, int flags); int (*Unlock)(struct LinuxTWI *me, unsigned int num, int flags); int (*Preempt)(struct LinuxTWI *me); enum TWIResult (*Write)(struct LinuxTWI *me, int devadr, int adrslen, int adrs, char *bytes); enum TWIResult (*Read)(struct LinuxTWI *me, int devadr, int adrslen, int adrs, char *bytes); int InitStatus; struct Bus *bus; int LockNum; char *devfile; int f; }


LinuxTWILock

decompiled_code:
__int64 __fastcall LinuxTWILock(__int64 a1, __int64 a2, char a3)
{
int v3; // er12

if ( (a3 & 2) != 0 )
return (unsigned int)-11;
v3 = ThreadMutexLock(*(unsigned int *)(a1 + 72));
if ( v3 < 0 )
return (unsigned int)v3;
v3 = 1;
if ( *(_DWORD *)(a1 + 88) )
return (unsigned int)v3;
*(_DWORD *)(a1 + 88) = open(*(const char **)(a1 + 80), 2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, char a3)
{
int v3; // er12

if ( (a3 & 2) != 0 )
return (unsigned int)-11;
v3 = ThreadMutexLock(*(unsigned int *)(a1 + 72));
if ( v3 < 0 )
return (unsigned int)v3;
v3 = 1;
if ( *(_DWORD *)(a1 + 88) )
return (unsigned int)v3;
*(_DWORD *)(a1 + 88) = open(*(const char **)(a1 + 80), 2);
return 1LL;
}

original_code:
int LinuxTWILock(LinuxTWI *twi,unsigned num,int flags) {
  int ret,mode;
  if (flags & SHARED) return -11;
  mode = (flags & NONBLOCKING) ?
    LOCK_TRY :
    (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD;
  if ((ret=ThreadMutexLock(twi->LockNum,mode)) < 0) return ret;
  if (!twi->f) {
    twi->f = open(twi->devfile,02);
  }
  return 1;
}

canonical_original_code:
int LinuxTWILock(struct LinuxTWI *twi, unsigned int num, int flags) {
  int ret; int mode;
  if (flags & SHARED) return -11;
  mode = (flags & NONBLOCKING) ?
    LOCK_TRY :
    (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD;
  if ((ret=ThreadMutexLock(twi->LockNum,mode)) < 0) return ret;
  if (!twi->f) {
    twi->f = open(twi->devfile,02);
  }
  return 1;
}

variable_types:
num
unsigned int

variable_types: flags int

variable_types: ret int

variable_types: mode int

user_defined_types: enum TWIResult { TWISuccess=1, TWIErrorPortInvalid=-1, TWIErrorModeUnsupported=-2, TWIErrorBaudUnconstrained=-3, TWIErrorHardware=-4, TWIErrorHandle=-5, TWIErrorWriteNAck=-6, TWIErrorDataNAck=-7, TWIErrorReadNack=-8, TWIErrorSDALow=-9, TWIErrorSCLLow=-10, TWIErrorAdrsLen=-11, TWIErrorTimeout=-12, TWIErrorOverrun=-13, TWIErrorArbLost=-14, TWIErrorUnknown=-999, TWIErrorOpInvalid=-15 }


LinuxTWIUnlock

decompiled_code:
__int64 __fastcall LinuxTWIUnlock(__int64 a1)
{
close(*(_DWORD *)(a1 + 88));
*(_DWORD *)(a1 + 88) = 0;
return ThreadMutexUnlock(*(unsigned int *)(a1 + 72));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
close(*(_DWORD *)(a1 + 88));
*(_DWORD *)(a1 + 88) = 0;
return ThreadMutexUnlock(*(unsigned int *)(a1 + 72));
}

original_code:
int LinuxTWIUnlock(LinuxTWI *twi,unsigned num,int flags) {
  close(twi->f);
  twi->f = 0;
  return ThreadMutexUnlock(twi->LockNum);
}

canonical_original_code:
int LinuxTWIUnlock(struct LinuxTWI *twi, unsigned int num, int flags) {
  close(twi->f);
  twi->f = 0;
  return ThreadMutexUnlock(twi->LockNum);
}


LinuxTWIPreempt

decompiled_code:
__int64 __fastcall LinuxTWIPreempt(__int64 a1)
{
LinuxTWILock(a1, *(unsigned int *)(a1 + 72), 0);
sched_yield();
return LinuxTWILock(a1, *(unsigned int *)(a1 + 72), 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
func2(a1, *(unsigned int *)(a1 + 72), 0);
sched_yield();
return func2(a1, *(unsigned int *)(a1 + 72), 0);
}

original_code:
int LinuxTWIPreempt(LinuxTWI *twi) {
  LinuxTWILock(twi,twi->LockNum,0);
  sched_yield();
  return LinuxTWILock(twi,twi->LockNum,0);
}

canonical_original_code:
int LinuxTWIPreempt(struct LinuxTWI *twi) {
  LinuxTWILock(twi,twi->LockNum,0);
  sched_yield();
  return LinuxTWILock(twi,twi->LockNum,0);
}


ArrayFree

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
free((void *)(a1 - 12));
}


ASCIIZ

canonical_decompiled_code:
char *__fastcall func6(char *src)
{
unsigned int v1; // ebx
char *v2; // rax

v1 = strlen(src);
v2 = (char *)ArrayAlloc(v1, 1u);
return strncpy(v2, src, v1);
}


ArraySizeAuto

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
*(_DWORD *)(a1 - 4) = a2;
return a1;
}


ArrayElementSize

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}


ArrayLength

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned int *)(a1 - 4);
}