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

result = ts8390_0;
if ( !ts8390_0 )
{
ts8390_0 = (__int64)ts8390Arch;
dioctl_config_add2(
&Xts8390_dioctl_config,
(unsigned int)Xts8390_dioctl_config_len,
(unsigned int)Yts8390_dioctl_config_len);
result = ts8390_0;
}
return result;
}

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

result = ts8390_0;
if ( !ts8390_0 )
{
ts8390_0 = (__int64)ts8390Arch;
dioctl_config_add2(
&Xts8390_dioctl_config,
(unsigned int)Xts8390_dioctl_config_len,
(unsigned int)Yts8390_dioctl_config_len);
result = ts8390_0;
}
return result;
}

original_code:
Arch *ts8390ArchInit() {
  static Arch *ts8390;
  if (ts8390) return ts8390;
  ts8390 = &ts8390Arch;
  dioctl_config_add2(Xts8390_dioctl_config,Xts8390_dioctl_config_len,Yts8390_dioctl_config_len);
  return ts8390;
}

canonical_original_code:
struct Arch *ts8390ArchInit() {
  static struct Arch *ts8390;
  if (ts8390) return ts8390;
  ts8390 = &ts8390Arch;
  dioctl_config_add2(Xts8390_dioctl_config,Xts8390_dioctl_config_len,Yts8390_dioctl_config_len);
  return ts8390;
}

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


ArrayFree

repo: embeddedarm/libtsctl

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

canonical_decompiled_code:
void __fastcall func3(__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 func5(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)
{
__int64 result; // rax

result = a1;
*(_DWORD *)(a1 - 4) = a2;
return result;
}

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

result = a1;
*(_DWORD *)(a1 - 4) = a2;
return result;
}

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 func7(__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 *

return_type: unsigned int


ArrayLength

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

canonical_decompiled_code:
__int64 __fastcall func8(__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
__int64 v5; // rdi

if ( *(_DWORD *)(a1 - 4) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(a1 + 8 * v2);
if ( v3 )
{
if ( *(_DWORD *)(v3 - 4) )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(v3 + 8 * v4);
if ( v5 )
ArrayFree(v5);
v3 = *(_QWORD *)(a1 + 8 * v2);
++v4;
}
while ( *(_DWORD *)(v3 - 4) > (unsigned int)v4 );
}
ArrayFree(v3);
}
++v2;
}
while ( *(_DWORD *)(a1 - 4) > (unsigned int)v2 );
}
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:
__int64 ArrayCompareFunction()
{
return ArrayCompareFunction();
}

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

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

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


PhysicalDIORefresh

original_code:
void PhysicalDIORefresh(PhysicalDIO *dio) {
  dio->bus->Lock(dio->bus,0,0);
  if (dio->gotHUP) {
    dio->bus->Commit(dio->bus,1);
    dio->gotHUP = 0;
  }
  dio->bus->Refresh(dio->bus);
  dio->bus->Unlock(dio->bus,0,0);
}

canonical_original_code:
void PhysicalDIORefresh(struct PhysicalDIO *dio) {
  dio->bus->Lock(dio->bus,0,0);
  if (dio->gotHUP) {
    dio->bus->Commit(dio->bus,1);
    dio->gotHUP = 0;
  }
  dio->bus->Refresh(dio->bus);
  dio->bus->Unlock(dio->bus,0,0);
}

variable_types: struct PhysicalDIO { void *(*Init)(struct PhysicalDIO *me, void *bus, void *dio); void (*Fini)(struct PhysicalDIO *me); int (*Lock)(struct PhysicalDIO *me, unsigned int num, int flags); int (*Unlock)(struct PhysicalDIO *me, unsigned int num, int flags); int (*Preempt)(struct PhysicalDIO *me); void (*Refresh)(struct PhysicalDIO *me); void (*Commit)(struct PhysicalDIO *me, int ForceAll); void (*Set)(struct PhysicalDIO *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)(struct PhysicalDIO *me, int DIONum); void (*SetAsync)(struct PhysicalDIO *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)(struct PhysicalDIO *me, int DIONum); void (*Wait)(struct PhysicalDIO *me, int *match, int min, int max, int *nh, int *nl); unsigned int (*Count)(struct PhysicalDIO *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)(struct PhysicalDIO *me, unsigned int num); int (*GetMulti)(struct PhysicalDIO *me, char *state, int offset); int InitStatus; unsigned int NumLocks; 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; 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; } *dio; int gotHUP; unsigned char *Caps; int *dirCache; } *

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


PhysicalDIOCommit

original_code:
void PhysicalDIOCommit(PhysicalDIO *dio,int forceall) {
  if (dio->gotHUP) {
    forceall = 1;
    dio->gotHUP = 0;
  }
  dio->bus->Lock(dio->bus,0,0);
  dio->bus->Commit(dio->bus,forceall);
  dio->bus->Unlock(dio->bus,0,0);
}

canonical_original_code:
void PhysicalDIOCommit(struct PhysicalDIO *dio, int forceall) {
  if (dio->gotHUP) {
    forceall = 1;
    dio->gotHUP = 0;
  }
  dio->bus->Lock(dio->bus,0,0);
  dio->bus->Commit(dio->bus,forceall);
  dio->bus->Unlock(dio->bus,0,0);
}

variable_types: forceall int

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; }

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; }

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 }


PhysicalDIOSet

decompiled_code:
__int64 __fastcall PhysicalDIOSet(__int64 a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 >= 0 && *(_DWORD *)(a1 + 124) >= (unsigned int)a2 )
{
result = a2;
if ( *(_BYTE *)(*(_QWORD *)(a1 + 152) + a2) )
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 128) + 16LL))(*(_QWORD *)(a1 + 128), 0LL, 0LL);
DIOSet(*(_QWORD *)(a1 + 136), (unsigned int)~a2, a3);
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 128) + 24LL))(
*(_QWORD *)(a1 + 128),
0LL,
0LL);
}
}
return result;
}

original_code:
void PhysicalDIOSet(PhysicalDIO *dio,int DIONum,DIOState State) {
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return;
  dio->bus->Lock(dio->bus,0,0);
  _DIOSet(dio->dio,~DIONum,State);
  dio->bus->Unlock(dio->bus,0,0);
}

canonical_original_code:
void PhysicalDIOSet(struct PhysicalDIO *dio, int DIONum, enum DIOState State) {
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return;
  dio->bus->Lock(dio->bus,0,0);
  _DIOSet(dio->dio,~DIONum,State);
  dio->bus->Unlock(dio->bus,0,0);
}

variable_types: DIONum int

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


PhysicalDIOGet

decompiled_code:
__int64 __fastcall PhysicalDIOGet(__int64 a1, int a2)
{
unsigned int v2; // ebx

if ( a2 < 0 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 124) < (unsigned int)a2 )
return (unsigned int)-1;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 152) + a2) )
return (unsigned int)-1;
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 16LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
v2 = DIOGet(*(_QWORD *)(a1 + 136), ~a2);
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 24LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
return v2;
}

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

if ( a2 < 0 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 124) < (unsigned int)a2 )
return (unsigned int)-1;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 152) + a2) )
return (unsigned int)-1;
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 16LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
v2 = func3(*(_QWORD *)(a1 + 136), ~a2);
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 24LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
return v2;
}

original_code:
DIOState PhysicalDIOGet(PhysicalDIO *dio,int DIONum) {
  DIOState ret;
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return INPUT;
  dio->bus->Lock(dio->bus,0,SHARED);
  ret = _DIOGet(dio->dio,~DIONum);
  dio->bus->Unlock(dio->bus,0,SHARED);
  return ret;
}

canonical_original_code:
enum DIOState PhysicalDIOGet(struct PhysicalDIO *dio, int DIONum) {
  enum DIOState ret;
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return INPUT;
  dio->bus->Lock(dio->bus,0,SHARED);
  ret = _DIOGet(dio->dio,~DIONum);
  dio->bus->Unlock(dio->bus,0,SHARED);
  return ret;
}

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


PhysicalDIOSetAsync

decompiled_code:
__int64 __fastcall PhysicalDIOSetAsync(__int64 a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 >= 0 && *(_DWORD *)(a1 + 124) >= (unsigned int)a2 )
{
result = a2;
if ( *(_BYTE *)(*(_QWORD *)(a1 + 152) + a2) )
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 128) + 16LL))(*(_QWORD *)(a1 + 128), 0LL, 0LL);
DIOSet(*(_QWORD *)(a1 + 136), (unsigned int)a2, a3);
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 128) + 24LL))(
*(_QWORD *)(a1 + 128),
0LL,
0LL);
}
}
return result;
}

original_code:
void PhysicalDIOSetAsync(PhysicalDIO *dio,int DIONum,DIOState State) {
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return;
  dio->bus->Lock(dio->bus,0,0);
  _DIOSet(dio->dio,DIONum,State);
  dio->bus->Unlock(dio->bus,0,0);
}

canonical_original_code:
void PhysicalDIOSetAsync(struct PhysicalDIO *dio, int DIONum, enum DIOState State) {
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return;
  dio->bus->Lock(dio->bus,0,0);
  _DIOSet(dio->dio,DIONum,State);
  dio->bus->Unlock(dio->bus,0,0);
}


PhysicalDIOGetAsync

decompiled_code:
__int64 __fastcall PhysicalDIOGetAsync(__int64 a1, signed int a2)
{
unsigned int v2; // ebp

if ( a2 < 0 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 124) < (unsigned int)a2 )
return (unsigned int)-1;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 152) + a2) )
return (unsigned int)-1;
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 16LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
v2 = DIOGet(*(_QWORD *)(a1 + 136), a2);
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 24LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, signed int a2)
{
unsigned int v2; // ebp

if ( a2 < 0 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 124) < (unsigned int)a2 )
return (unsigned int)-1;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 152) + a2) )
return (unsigned int)-1;
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 16LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
v2 = func3(*(_QWORD *)(a1 + 136), a2);
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 128) + 24LL))(*(_QWORD *)(a1 + 128), 0LL, 2LL);
return v2;
}

original_code:
DIOState PhysicalDIOGetAsync(PhysicalDIO *dio,int DIONum) {
  DIOState ret;
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return INPUT;
  dio->bus->Lock(dio->bus,0,SHARED);
  ret = _DIOGet(dio->dio,DIONum);
  dio->bus->Unlock(dio->bus,0,SHARED);
  return ret;
}

canonical_original_code:
enum DIOState PhysicalDIOGetAsync(struct PhysicalDIO *dio, int DIONum) {
  enum DIOState ret;
  if (DIONum < 0 || DIONum > dio->NumLocks
      || dio->Caps[DIONum] == DIO_NOT_PRESENT) return INPUT;
  dio->bus->Lock(dio->bus,0,SHARED);
  ret = _DIOGet(dio->dio,DIONum);
  dio->bus->Unlock(dio->bus,0,SHARED);
  return ret;
}


PhysicalDIOLock

decompiled_code:
__int64 PhysicalDIOLock()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 1LL;
}

original_code:
int PhysicalDIOLock(PhysicalDIO *dio,unsigned num,int flags) {
  return 1;
}

canonical_original_code:
int PhysicalDIOLock(struct PhysicalDIO *dio, unsigned int num, int flags) {
  return 1;
}

variable_types:
num
unsigned int

variable_types: flags int

return_type: int


PhysicalDIOUnlock

decompiled_code:
__int64 PhysicalDIOUnlock()
{
return 1LL;
}

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

original_code:
int PhysicalDIOUnlock(PhysicalDIO *dio,unsigned num,int flags) {
  return 1;
}

canonical_original_code:
int PhysicalDIOUnlock(struct PhysicalDIO *dio, unsigned int num, int flags) {
  return 1;
}


PhysicalDIOPreempt

decompiled_code:
void PhysicalDIOPreempt()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
int PhysicalDIOPreempt(PhysicalDIO *dio) {
}

canonical_original_code:
int PhysicalDIOPreempt(struct PhysicalDIO *dio) {
}


PhysicalDIOWait

decompiled_code:
void PhysicalDIOWait()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void PhysicalDIOWait(PhysicalDIO *dio,int* match,int min,int max,
      const int* h,const int* l) {
}

canonical_original_code:
void PhysicalDIOWait(struct PhysicalDIO *dio, int *match, int min, int max, int *h, int *l) {
}

variable_types:
match
int *

variable_types: min int

variable_types: max int

variable_types:
h
int *

variable_types:
l
int *


PhysicalDIOCount

decompiled_code:
__int64 __fastcall PhysicalDIOCount(__int64 a1)
{
return (*(__int64 (**)(void))(*(_QWORD *)(a1 + 136) + 72LL))();
}

original_code:
unsigned PhysicalDIOCount(PhysicalDIO *dio) {
  return dio->dio->Count(dio);
}

canonical_original_code:
unsigned int PhysicalDIOCount(struct PhysicalDIO *dio) {
  return dio->dio->Count(dio);
}


PhysicalDIOCapabilities

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

result = 0LL;
if ( *(_DWORD *)(a1 + 124) > a2 )
result = *(unsigned __int8 *)(*(_QWORD *)(a1 + 152) + a2);
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 124) > a2 )
result = *(unsigned __int8 *)(*(_QWORD *)(a1 + 152) + a2);
return result;
}

original_code:
DIOCaps PhysicalDIOCapabilities(PhysicalDIO *dio,unsigned num) {
  if (num < 0 || num >= dio->NumLocks) return DIO_NOT_PRESENT;
  return dio->Caps[num];
}

canonical_original_code:
enum DIOCaps PhysicalDIOCapabilities(struct PhysicalDIO *dio, unsigned int num) {
  if (num < 0 || num >= dio->NumLocks) return DIO_NOT_PRESENT;
  return dio->Caps[num];
}

return_type: 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 }


PhysicalDIOInit

decompiled_code:
__int64 __fastcall PhysicalDIOInit(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ebp

if ( *(int *)(a1 + 120) <= 0 )
{
*(_QWORD *)a1 = PhysicalDIOInit;
*(_QWORD *)(a1 + 8) = PhysicalDIOFini;
*(_QWORD *)(a1 + 16) = PhysicalDIOLock;
*(_QWORD *)(a1 + 24) = PhysicalDIOUnlock;
*(_QWORD *)(a1 + 32) = PhysicalDIOPreempt;
*(_QWORD *)(a1 + 40) = PhysicalDIORefresh;
*(_QWORD *)(a1 + 48) = PhysicalDIOCommit;
*(_QWORD *)(a1 + 56) = PhysicalDIOSet;
*(_QWORD *)(a1 + 64) = PhysicalDIOGet;
*(_QWORD *)(a1 + 72) = PhysicalDIOSetAsync;
*(_QWORD *)(a1 + 80) = PhysicalDIOGetAsync;
*(_QWORD *)(a1 + 88) = PhysicalDIOWait;
*(_QWORD *)(a1 + 96) = PhysicalDIOCount;
*(_QWORD *)(a1 + 104) = PhysicalDIOCapabilities;
*(_QWORD *)(a1 + 112) = PhysicalDIOGetMulti;
*(_QWORD *)(a1 + 128) = a2;
*(_QWORD *)(a1 + 136) = a3;
*(_DWORD *)(a1 + 124) = (*(__int64 (__fastcall **)(__int64))(a3 + 72))(a3);
if ( *(int *)(*(_QWORD *)(a1 + 128) + 288LL) <= 0 || *(int *)(*(_QWORD *)(a1 + 136) + 80LL) <= 0 )
{
(*(void (__fastcall **)(__int64))(a1 + 8))(a1);
*(_DWORD *)(a1 + 120) = -1;
}
else
{
v3 = FPGAReloadRegister(a1 + 144, 7LL);
if ( v3 < 0 )
{
(*(void (__fastcall **)(__int64))(a1 + 8))(a1);
*(_DWORD *)(a1 + 120) = v3;
}
else
{
*(_DWORD *)(a1 + 120) = 1;
}
}
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ebp

if ( *(int *)(a1 + 120) <= 0 )
{
*(_QWORD *)a1 = PhysicalDIOInit;
*(_QWORD *)(a1 + 8) = PhysicalDIOFini;
*(_QWORD *)(a1 + 16) = PhysicalDIOLock;
*(_QWORD *)(a1 + 24) = PhysicalDIOUnlock;
*(_QWORD *)(a1 + 32) = PhysicalDIOPreempt;
*(_QWORD *)(a1 + 40) = PhysicalDIORefresh;
*(_QWORD *)(a1 + 48) = PhysicalDIOCommit;
*(_QWORD *)(a1 + 56) = PhysicalDIOSet;
*(_QWORD *)(a1 + 64) = PhysicalDIOGet;
*(_QWORD *)(a1 + 72) = PhysicalDIOSetAsync;
*(_QWORD *)(a1 + 80) = PhysicalDIOGetAsync;
*(_QWORD *)(a1 + 88) = PhysicalDIOWait;
*(_QWORD *)(a1 + 96) = PhysicalDIOCount;
*(_QWORD *)(a1 + 104) = PhysicalDIOCapabilities;
*(_QWORD *)(a1 + 112) = PhysicalDIOGetMulti;
*(_QWORD *)(a1 + 128) = a2;
*(_QWORD *)(a1 + 136) = a3;
*(_DWORD *)(a1 + 124) = (*(__int64 (__fastcall **)(__int64))(a3 + 72))(a3);
if ( *(int *)(*(_QWORD *)(a1 + 128) + 288LL) <= 0 || *(int *)(*(_QWORD *)(a1 + 136) + 80LL) <= 0 )
{
(*(void (__fastcall **)(__int64))(a1 + 8))(a1);
*(_DWORD *)(a1 + 120) = -1;
}
else
{
v3 = FPGAReloadRegister(a1 + 144, 7LL);
if ( v3 < 0 )
{
(*(void (__fastcall **)(__int64))(a1 + 8))(a1);
*(_DWORD *)(a1 + 120) = v3;
}
else
{
*(_DWORD *)(a1 + 120) = 1;
}
}
}
return a1;
}

original_code:
void *PhysicalDIOInit(PhysicalDIO *dio,void *bus1,void *sub1) {
  Bus *bus = bus1;
  DIORaw *sub = sub1;
  int err;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)PhysicalDIOInit;
  dio->Fini = (void *)PhysicalDIOFini;
  dio->Lock = (void *)PhysicalDIOLock;
  dio->Unlock = (void *)PhysicalDIOUnlock;
  dio->Preempt = (void *)PhysicalDIOPreempt;
  dio->Refresh = (void *)PhysicalDIORefresh;
  dio->Commit = (void *)PhysicalDIOCommit;
  dio->Set = (void *)PhysicalDIOSet;
  dio->Get = (void *)PhysicalDIOGet;
  dio->SetAsync = (void *)PhysicalDIOSetAsync;
  dio->GetAsync = (void *)PhysicalDIOGetAsync;
  dio->Wait = (void *)PhysicalDIOWait;
  dio->Count = (void *)PhysicalDIOCount;
  dio->Capabilities = (void *)PhysicalDIOCapabilities;
  dio->GetMulti = (void *)PhysicalDIOGetMulti;
  dio->bus = bus;
  dio->dio = sub;
  dio->NumLocks = sub->Count(sub);
  if (dio->bus->InitStatus <= 0
      ||dio->dio->InitStatus <= 0) {
    dio->Fini(dio);
    dio->InitStatus = -1;
    return dio;
  }
  if ((err=FPGAReloadRegister(&dio->gotHUP,7)) < 0) {
    dio->Fini(dio);
    dio->InitStatus = err;
    return dio;
  }
  dio->InitStatus = 1;
  return dio;
}

canonical_original_code:
void *PhysicalDIOInit(struct PhysicalDIO *dio, void *bus1, void *sub1) {
  struct Bus *bus = bus1;
  struct DIORaw *sub = sub1;
  int err;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)PhysicalDIOInit;
  dio->Fini = (void *)PhysicalDIOFini;
  dio->Lock = (void *)PhysicalDIOLock;
  dio->Unlock = (void *)PhysicalDIOUnlock;
  dio->Preempt = (void *)PhysicalDIOPreempt;
  dio->Refresh = (void *)PhysicalDIORefresh;
  dio->Commit = (void *)PhysicalDIOCommit;
  dio->Set = (void *)PhysicalDIOSet;
  dio->Get = (void *)PhysicalDIOGet;
  dio->SetAsync = (void *)PhysicalDIOSetAsync;
  dio->GetAsync = (void *)PhysicalDIOGetAsync;
  dio->Wait = (void *)PhysicalDIOWait;
  dio->Count = (void *)PhysicalDIOCount;
  dio->Capabilities = (void *)PhysicalDIOCapabilities;
  dio->GetMulti = (void *)PhysicalDIOGetMulti;
  dio->bus = bus;
  dio->dio = sub;
  dio->NumLocks = sub->Count(sub);
  if (dio->bus->InitStatus <= 0
      ||dio->dio->InitStatus <= 0) {
    dio->Fini(dio);
    dio->InitStatus = -1;
    return dio;
  }
  if ((err=FPGAReloadRegister(&dio->gotHUP,7)) < 0) {
    dio->Fini(dio);
    dio->InitStatus = err;
    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; } *

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; } *

variable_types: err int


PhysicalDIOFini

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

if ( *(int *)(a1 + 120) > 0 )
FPGAReloadUnregister(a1 + 144);
result = (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(a1 + 128) + 8LL))(*(_QWORD *)(a1 + 128));
if ( *(int *)(a1 + 120) > 0 )
*(_DWORD *)(a1 + 120) = 0;
return result;
}

original_code:
void PhysicalDIOFini(PhysicalDIO *dio) {
  if (dio->InitStatus > 0) {
    FPGAReloadUnregister(&dio->gotHUP);
  }
  dio->bus->Fini(dio->bus);
  if (dio->InitStatus > 0) dio->InitStatus = 0;
}

canonical_original_code:
void PhysicalDIOFini(struct PhysicalDIO *dio) {
  if (dio->InitStatus > 0) {
    FPGAReloadUnregister(&dio->gotHUP);
  }
  dio->bus->Fini(dio->bus);
  if (dio->InitStatus > 0) dio->InitStatus = 0;
}


ArrayFree

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

canonical_decompiled_code:
void __fastcall func16(__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 func18(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)
{
__int64 result; // rax

result = a1;
*(_DWORD *)(a1 - 4) = a2;
return result;
}

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

result = a1;
*(_DWORD *)(a1 - 4) = a2;
return result;
}

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 func20(__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 func21(__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);
}


PhysicalDIOGetMulti

original_code:
int PhysicalDIOGetMulti(PhysicalDIO *dio,char* bits,int offset) {
  int i,n=ArrayLength(bits)*8,j,byte,tmp,max,q;
  max = dio->Count(dio) - offset;
  if (n == 0) {
    tmp = 0;
    q = (max-offset > 32) ? 0 : 32-(max-offset);
    n = (max-offset > 32) ? 32 : max-offset;
    for (i=offset;i<n;i++) {
      tmp = (tmp << 1) + DIOValue(dio->Get(dio,i));
    }
    return tmp << q;
  }
  dio->Refresh(dio);
  for (i=offset,j=0,byte=0;i<n;i++) {
    bits[byte] = (bits[byte] << 1) + DIOValue(dio->Get(dio,i));
    if (i == max) {
      bits[byte] <<= (7-j);
      break;
    }
    if (++j == 8) {
      j = 0;
      byte++;
    }
  }
  return n;
}

canonical_original_code:
int PhysicalDIOGetMulti(struct PhysicalDIO *dio, char *bits, int offset) {
  int i; int n = ArrayLength(bits)*8; int j; int byte; int tmp; int max; int q;
  max = dio->Count(dio) - offset;
  if (n == 0) {
    tmp = 0;
    q = (max-offset > 32) ? 0 : 32-(max-offset);
    n = (max-offset > 32) ? 32 : max-offset;
    for (i=offset;i<n;i++) {
      tmp = (tmp << 1) + DIOValue(dio->Get(dio,i));
    }
    return tmp << q;
  }
  dio->Refresh(dio);
  for (i=offset,j=0,byte=0;i<n;i++) {
    bits[byte] = (bits[byte] << 1) + DIOValue(dio->Get(dio,i));
    if (i == max) {
      bits[byte] <<= (7-j);
      break;
    }
    if (++j == 8) {
      j = 0;
      byte++;
    }
  }
  return n;
}

variable_types: struct PhysicalDIO { void *(*Init)(struct PhysicalDIO *me, void *bus, void *dio); void (*Fini)(struct PhysicalDIO *me); int (*Lock)(struct PhysicalDIO *me, unsigned int num, int flags); int (*Unlock)(struct PhysicalDIO *me, unsigned int num, int flags); int (*Preempt)(struct PhysicalDIO *me); void (*Refresh)(struct PhysicalDIO *me); void (*Commit)(struct PhysicalDIO *me, int ForceAll); void (*Set)(struct PhysicalDIO *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)(struct PhysicalDIO *me, int DIONum); void (*SetAsync)(struct PhysicalDIO *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)(struct PhysicalDIO *me, int DIONum); void (*Wait)(struct PhysicalDIO *me, int *match, int min, int max, int *nh, int *nl); unsigned int (*Count)(struct PhysicalDIO *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)(struct PhysicalDIO *me, unsigned int num); int (*GetMulti)(struct PhysicalDIO *me, char *state, int offset); int InitStatus; unsigned int NumLocks; 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; 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; } *dio; int gotHUP; unsigned char *Caps; int *dirCache; } *

variable_types:
bits
char *

variable_types: offset int

variable_types: i int

variable_types: n int

variable_types: j int

variable_types: byte int

variable_types: tmp int

variable_types: q int


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 **


ArrayFreeFreeFree

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

if ( *(_DWORD *)(a1 - 4) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(a1 + 8 * v2);
if ( v3 )
{
if ( *(_DWORD *)(v3 - 4) )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(v3 + 8 * v4);
if ( v5 )
ArrayFree(v5);
v3 = *(_QWORD *)(a1 + 8 * v2);
++v4;
}
while ( *(_DWORD *)(v3 - 4) > (unsigned int)v4 );
}
ArrayFree(v3);
}
++v2;
}
while ( *(_DWORD *)(a1 - 4) > (unsigned int)v2 );
}
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 ***


ArrayCompareFunction

decompiled_code:
__int64 ArrayCompareFunction()
{
return ArrayCompareFunction();
}

canonical_decompiled_code:
__int64 func25()
{
return func25();
}

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

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


ArrayFree

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

variable_types:
arr
void *


ASCIIZ

canonical_decompiled_code:
char *__fastcall func3(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 func4(__int64 a1, int a2)
{
__int64 result; // rax

result = a1;
*(_DWORD *)(a1 - 4) = a2;
return result;
}

variable_types:
ptr
unsigned int *


ArrayElementSize

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


ArrayLength

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


ArrayCompareFunction

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


HashTableEqual

decompiled_code:
_BOOL8 __fastcall HashTableEqual(const void *a1, const void *a2)
{
return memcmp(a1, a2, 0x30uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(const void *a1, const void *a2)
{
return memcmp(a1, a2, 0x30uLL) == 0;
}

original_code:
int HashTableEqual(HashTable *a,HashTable *b) {
  return !memcmp(a,b,sizeof(HashTable));
}

canonical_original_code:
int HashTableEqual(struct HashTable *a, struct HashTable *b) {
  return !memcmp(a,b,sizeof(HashTable));
}

variable_types: struct HashTable { unsigned int tablelength; struct entry { void *k; unsigned int h; struct entry *next; } **table; unsigned int entrycount; unsigned int loadlimit; unsigned int primeindex; unsigned int (*hashfn)(void *k); int (*eqfn)(void *k1, void *k2); } *

variable_types:
b
struct HashTable *

user_defined_types: struct HashTable { unsigned int tablelength; struct entry **table; unsigned int entrycount; unsigned int loadlimit; unsigned int primeindex; unsigned int (*hashfn)(void *k); int (*eqfn)(void *k1, void *k2); }


hash

original_code:
unsigned int
hash(HashTable *h, void *k)
{
    unsigned int i = h->hashfn(k);
    i += ~(i << 9);
    i ^= ((i >> 14) | (i << 18));
    i += (i << 4);
    i ^= ((i >> 10) | (i << 22));
    return i;
}

canonical_original_code:
unsigned int hash(struct HashTable *h, void *k)
{
    unsigned int i = h->hashfn(k);
    i += ~(i << 9);
    i ^= ((i >> 14) | (i << 18));
    i += (i << 4);
    i ^= ((i >> 10) | (i << 22));
    return i;
}

variable_types:
k
void *

variable_types:
i
unsigned int

user_defined_types: struct entry { void *k; unsigned int h; struct entry *next; }


HashTableCount

decompiled_code:
__int64 __fastcall HashTableCount(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
unsigned int
HashTableCount(HashTable *h)
{
    return h->entrycount;
}

canonical_original_code:
unsigned int HashTableCount(struct HashTable *h)
{
    return h->entrycount;
}


HashTableLookup

original_code:
void *
HashTableLookup(HashTable *h, void *k)
{
    struct entry *e;
    unsigned int hashvalue, index;
    hashvalue = hash(h,k);
    index = indexFor(h->tablelength,hashvalue);
    e = h->table[index];
    while (((void *)0) != e)
    {
      if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v;
      e = e->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *HashTableLookup(struct HashTable *h, void *k)
{
    struct entry *e;
    unsigned int hashvalue; unsigned int index;
    hashvalue = hash(h,k);
    index = indexFor(h->tablelength,hashvalue);
    e = h->table[index];
    while (((void *)0) != e)
    {
      if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v;
      e = e->next;
    }
    return ((void *)0);
}

variable_types: struct entry { void *k; unsigned int h; struct entry *next; } *

variable_types:
hashvalue
unsigned int

variable_types:
index
unsigned int


HashTableRemove

original_code:
void *
HashTableRemove(HashTable *h, void *k)
{
    struct entry *e;
    struct entry **pE;
    void *v;
    unsigned int hashvalue, index;
    hashvalue = hash(h,k);
    index = indexFor(h->tablelength,hash(h,k));
    pE = &(h->table[index]);
    e = *pE;
    while (((void *)0) != e)
    {
        if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
        {
            *pE = e->next;
            h->entrycount--;
            v = e->v;
            free(e);
            return v;
        }
        pE = &(e->next);
        e = e->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *HashTableRemove(struct HashTable *h, void *k)
{
    struct entry *e;
    struct entry **pE;
    void *v;
    unsigned int hashvalue; unsigned int index;
    hashvalue = hash(h,k);
    index = indexFor(h->tablelength,hash(h,k));
    pE = &(h->table[index]);
    e = *pE;
    while (((void *)0) != e)
    {
        if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
        {
            *pE = e->next;
            h->entrycount--;
            v = e->v;
            free(e);
            return v;
        }
        pE = &(e->next);
        e = e->next;
    }
    return ((void *)0);
}

variable_types: struct entry { void *k; unsigned int h; struct entry *next; } **

variable_types:
v
void *


HashTableInsert

decompiled_code:
__int64 __fastcall HashTableInsert(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
_DWORD *v5; // rbp
unsigned int v6; // eax
_QWORD *v7; // rax
__int64 result; // rax

HashTableRemove(a1, a2);
v4 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v4;
if ( v4 > *(_DWORD *)(a1 + 20) )
HashTableExpand((unsigned int *)a1);
v5 = malloc(0x20uLL);
if ( v5 )
{
v6 = hash(a1, a2);
v5[4] = v6;
*(_QWORD *)v5 = a2;
*((_QWORD *)v5 + 1) = a3;
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v6 % *(_DWORD *)a1));
*((_QWORD *)v5 + 3) = *v7;
*v7 = v5;
result = 0xFFFFFFFFLL;
}
else
{
--*(_DWORD *)(a1 + 16);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
_DWORD *v5; // rbp
unsigned int v6; // eax
_QWORD *v7; // rax
__int64 result; // rax

func14(a1, a2);
v4 = *(_DWORD *)(a1 + 16) + 1;
*(_DWORD *)(a1 + 16) = v4;
if ( v4 > *(_DWORD *)(a1 + 20) )
func0((unsigned int *)a1);
v5 = malloc(0x20uLL);
if ( v5 )
{
v6 = func11(a1, a2);
v5[4] = v6;
*(_QWORD *)v5 = a2;
*((_QWORD *)v5 + 1) = a3;
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v6 % *(_DWORD *)a1));
*((_QWORD *)v5 + 3) = *v7;
*v7 = v5;
result = 0xFFFFFFFFLL;
}
else
{
--*(_DWORD *)(a1 + 16);
result = 0LL;
}
return result;
}

original_code:
int
HashTableInsert(HashTable *h, void *k, void *v)
{
    unsigned int index;
    struct entry *e;
    HashTableRemove(h,k);
    if (++(h->entrycount) > h->loadlimit)
    {
        HashTableExpand(h);
    }
    e = (struct entry *)malloc(sizeof(struct entry));
    if (((void *)0) == e) { --(h->entrycount); return 0; }
    e->h = hash(h,k);
    index = indexFor(h->tablelength,e->h);
    e->k = k;
    e->v = v;
    e->next = h->table[index];
    h->table[index] = e;
    return -1;
}

canonical_original_code:
int HashTableInsert(struct HashTable *h, void *k, void *v)
{
    unsigned int index;
    struct entry *e;
    HashTableRemove(h,k);
    if (++(h->entrycount) > h->loadlimit)
    {
        HashTableExpand(h);
    }
    e = (struct entry *)malloc(sizeof(struct entry));
    if (((void *)0) == e) { --(h->entrycount); return 0; }
    e->h = hash(h,k);
    index = indexFor(h->tablelength,e->h);
    e->k = k;
    e->v = v;
    e->next = h->table[index];
    h->table[index] = e;
    return -1;
}


HashTableDestroy

decompiled_code:
void __fastcall HashTableDestroy(void *ptr, int a2)
{
__int64 v3; // r13
unsigned int i; // ebp
_QWORD *v5; // rbx
void *v6; // rdi
unsigned int v7; // er14
__int64 v8; // rbx
void **v9; // rbp

v3 = *((_QWORD *)ptr + 1);
if ( a2 )
{
if ( *(_DWORD *)ptr )
{
v7 = 0;
do
{
v8 = *(_QWORD *)(v3 + 8LL * v7);
while ( v8 )
{
v9 = (void **)v8;
v8 = *(_QWORD *)(v8 + 24);
free(*v9);
free(v9[1]);
free(v9);
}
++v7;
}
while ( *(_DWORD *)ptr > v7 );
}
}
else
{
for ( i = 0; *(_DWORD *)ptr > i; ++i )
{
v5 = *(_QWORD **)(v3 + 8LL * i);
while ( v5 )
{
v6 = v5;
v5 = (_QWORD *)v5[3];
free(v6);
}
}
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr, int a2)
{
__int64 v3; // r13
unsigned int i; // ebp
_QWORD *v5; // rbx
void *v6; // rdi
unsigned int v7; // er14
__int64 v8; // rbx
void **v9; // rbp

v3 = *((_QWORD *)ptr + 1);
if ( a2 )
{
if ( *(_DWORD *)ptr )
{
v7 = 0;
do
{
v8 = *(_QWORD *)(v3 + 8LL * v7);
while ( v8 )
{
v9 = (void **)v8;
v8 = *(_QWORD *)(v8 + 24);
free(*v9);
free(v9[1]);
free(v9);
}
++v7;
}
while ( *(_DWORD *)ptr > v7 );
}
}
else
{
for ( i = 0; *(_DWORD *)ptr > i; ++i )
{
v5 = *(_QWORD **)(v3 + 8LL * i);
while ( v5 )
{
v6 = v5;
v5 = (_QWORD *)v5[3];
free(v6);
}
}
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void
HashTableDestroy(HashTable *h, int free_values)
{
    unsigned int i;
    struct entry *e, *f;
    struct entry **table = h->table;
    if (free_values)
    {
        for (i = 0; i < h->tablelength; i++)
        {
            e = table[i];
            while (((void *)0) != e) {
       f = e;
       e = e->next;
       free(f->k);
       free(f->v);
       free(f);
     }
        }
    }
    else
    {
        for (i = 0; i < h->tablelength; i++)
        {
            e = table[i];
            while (((void *)0) != e) {
       f = e;
       e = e->next;
       free(f);
     }
        }
    }
    free(h->table);
    free(h);
}

canonical_original_code:
void HashTableDestroy(struct HashTable *h, int free_values)
{
    unsigned int i;
    struct entry *e; struct entry *f;
    struct entry **table = h->table;
    if (free_values)
    {
        for (i = 0; i < h->tablelength; i++)
        {
            e = table[i];
            while (((void *)0) != e) {
       f = e;
       e = e->next;
       free(f->k);
       free(f->v);
       free(f);
     }
        }
    }
    else
    {
        for (i = 0; i < h->tablelength; i++)
        {
            e = table[i];
            while (((void *)0) != e) {
       f = e;
       e = e->next;
       free(f);
     }
        }
    }
    free(h->table);
    free(h);
}


ASCIIZEqual

decompiled_code:
_BOOL8 __fastcall ASCIIZEqual(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int ASCIIZEqual(char *str1,char *str2) {
  return !strcmp(str1,str2);
}

canonical_original_code:
int ASCIIZEqual(char *str1, char *str2) {
  return !strcmp(str1,str2);
}


ArrayEqualQ

decompiled_code:
_BOOL8 __fastcall ArrayEqualQ(_DWORD *a1, const void *a2)
{
unsigned int v2; // ebp
int v3; // edx
unsigned int v4; // eax

v2 = *(a1 - 1);
v3 = memcmp(a1, a2, *(a1 - 2) * v2);
if ( !v3 )
{
v4 = *((_DWORD *)a2 - 1);
if ( v2 != v4 )
v3 = v4 < v2 ? 1 : -1;
}
return v3 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(_DWORD *a1, const void *a2)
{
unsigned int v2; // ebp
int v3; // edx
unsigned int v4; // eax

v2 = *(a1 - 1);
v3 = memcmp(a1, a2, *(a1 - 2) * v2);
if ( !v3 )
{
v4 = *((_DWORD *)a2 - 1);
if ( v2 != v4 )
v3 = v4 < v2 ? 1 : -1;
}
return v3 == 0;
}

original_code:
int ArrayEqualQ(void *a,void *b) {
  return ArrayCompare(a,b) == 0;
}

canonical_original_code:
int ArrayEqualQ(void *a, void *b) {
  return ArrayCompare(a,b) == 0;
}

variable_types:
a
void *

variable_types:
b
void *


ASCIIZHash

decompiled_code:
__int64 __fastcall ASCIIZHash(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int8 v2; // al
unsigned int v3; // ecx

v1 = a1 + 1;
v2 = *a1;
if ( !*a1 )
return 5381;
v3 = 5381;
do
{
v3 += 32 * v3 + v2;
v2 = *v1++;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int8 v2; // al
unsigned int v3; // ecx

v1 = a1 + 1;
v2 = *a1;
if ( !*a1 )
return 5381;
v3 = 5381;
do
{
v3 += 32 * v3 + v2;
v2 = *v1++;
}
while ( v2 );
return v3;
}

original_code:
unsigned int ASCIIZHash(unsigned char *str) {
  unsigned int hash = 5381;
  int c;
  while ((c = *str++)) {
    hash = ((hash << 5) + hash) + c;
  }
  return hash;
}

variable_types:
str
unsigned char *

variable_types:
hash
unsigned int

variable_types: c int


ArrayHash

decompiled_code:
__int64 __fastcall ArrayHash(__int64 a1)
{
int v1; // ebx
int v2; // ebx
char *v3; // rax
unsigned int v4; // ecx

v1 = ArrayElementSize(a1);
v2 = ArrayLength(a1) * v1;
if ( v2 <= 0 )
return 5381;
v3 = (char *)a1;
v4 = 5381;
do
v4 += *v3++ + 32 * v4;
while ( v3 != (char *)(a1 + (unsigned int)(v2 - 1) + 1) );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
int v1; // ebx
int v2; // ebx
char *v3; // rax
unsigned int v4; // ecx

v1 = func5(a1);
v2 = func6(a1) * v1;
if ( v2 <= 0 )
return 5381;
v3 = (char *)a1;
v4 = 5381;
do
v4 += *v3++ + 32 * v4;
while ( v3 != (char *)(a1 + (unsigned int)(v2 - 1) + 1) );
return v4;
}

original_code:
unsigned int ArrayHash(void *arr1) {
  char *arr = arr1;
  int i,len = ArrayElementSize(arr1) * ArrayLength(arr1);
  unsigned int hash = 5381;
  int c;
  for (i=0;i<len;i++) {
    c = arr[i];
    hash = ((hash << 5) + hash) + c;
  }
  return hash;
}

canonical_original_code:
unsigned int ArrayHash(void *arr1) {
  char *arr = arr1;
  int i; int len = ArrayElementSize(arr1) * ArrayLength(arr1);
  unsigned int hash = 5381;
  int c;
  for (i=0;i<len;i++) {
    c = arr[i];
    hash = ((hash << 5) + hash) + c;
  }
  return hash;
}

variable_types:
arr
char *

variable_types: i int

variable_types: len int


IntegerHash

decompiled_code:
__int64 __fastcall IntegerHash(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
return a1;
}

original_code:
unsigned int IntegerHash(void *i) {
  return (unsigned)i;
}

canonical_original_code:
unsigned int IntegerHash(void *i) {
  return (unsigned int)i;
}

variable_types:
i
void *


IntegerEqualQ

decompiled_code:
_BOOL8 __fastcall IntegerEqualQ(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func22(int a1, int a2)
{
return a1 == a2;
}

original_code:
int IntegerEqualQ(void *a,void *b) {
  return (int)a == (int)b;
}

canonical_original_code:
int IntegerEqualQ(void *a, void *b) {
  return (int)a == (int)b;
}


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

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

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

variable_types: struct FreescaleIMX51DIORaw { void *(*Init)(struct FreescaleIMX51DIORaw *me, void *bus); void (*Fini)(struct FreescaleIMX51DIORaw *me); int (*Lock)(struct FreescaleIMX51DIORaw *me, unsigned int num, int flags); int (*Unlock)(struct FreescaleIMX51DIORaw *me, unsigned int num, int flags); int (*Preempt)(struct FreescaleIMX51DIORaw *me); void (*DirSet)(struct FreescaleIMX51DIORaw *me, int num, int asOutput); void (*DataSet)(struct FreescaleIMX51DIORaw *me, int num, int asHigh); int (*DirGet)(struct FreescaleIMX51DIORaw *me, int num); int (*DataGet)(struct FreescaleIMX51DIORaw *me, int num); unsigned int (*Count)(struct FreescaleIMX51DIORaw *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

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


original_code:
int FreescaleIMX51DIORawUnlock(FreescaleIMX51DIORaw *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 FreescaleIMX51DIORawUnlock(struct FreescaleIMX51DIORaw *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;
  }
}


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

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

original_code:
int FreescaleIMX51DIORawPreempt(FreescaleIMX51DIORaw *ob) {
  return -1;
}

canonical_original_code:
int FreescaleIMX51DIORawPreempt(struct FreescaleIMX51DIORaw *ob) {
  return -1;
}


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

result = a1;
if ( *(int *)(a1 + 80) <= 0 )
{
*(_QWORD *)a1 = FreescaleIMX51DIORawInit;
*(_QWORD *)(a1 + 8) = FreescaleIMX51DIORawFini;
*(_QWORD *)(a1 + 16) = FreescaleIMX51DIORawLock;
*(_QWORD *)(a1 + 24) = FreescaleIMX51DIORawUnlock;
*(_QWORD *)(a1 + 32) = FreescaleIMX51DIORawPreempt;
*(_QWORD *)(a1 + 40) = FreescaleIMX51DIORawDirSet;
*(_QWORD *)(a1 + 48) = FreescaleIMX51DIORawDataSet;
*(_QWORD *)(a1 + 56) = FreescaleIMX51DIORawDirGet;
*(_QWORD *)(a1 + 64) = FreescaleIMX51DIORawDataGet;
*(_QWORD *)(a1 + 72) = FreescaleIMX51DIORawCount;
*(_DWORD *)(a1 + 88) = 0;
*(_DWORD *)(a1 + 84) = 0;
*(_QWORD *)(a1 + 96) = a2;
if ( *(int *)(a2 + 288) <= 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

result = a1;
if ( *(int *)(a1 + 80) <= 0 )
{
*(_QWORD *)a1 = FreescaleIMX51DIORawInit;
*(_QWORD *)(a1 + 8) = FreescaleIMX51DIORawFini;
*(_QWORD *)(a1 + 16) = FreescaleIMX51DIORawLock;
*(_QWORD *)(a1 + 24) = FreescaleIMX51DIORawUnlock;
*(_QWORD *)(a1 + 32) = FreescaleIMX51DIORawPreempt;
*(_QWORD *)(a1 + 40) = FreescaleIMX51DIORawDirSet;
*(_QWORD *)(a1 + 48) = FreescaleIMX51DIORawDataSet;
*(_QWORD *)(a1 + 56) = FreescaleIMX51DIORawDirGet;
*(_QWORD *)(a1 + 64) = FreescaleIMX51DIORawDataGet;
*(_QWORD *)(a1 + 72) = FreescaleIMX51DIORawCount;
*(_DWORD *)(a1 + 88) = 0;
*(_DWORD *)(a1 + 84) = 0;
*(_QWORD *)(a1 + 96) = a2;
if ( *(int *)(a2 + 288) <= 0 )
*(_DWORD *)(a1 + 80) = -1;
else
*(_DWORD *)(a1 + 80) = 1;
}
return result;
}

original_code:
void *FreescaleIMX51DIORawInit(FreescaleIMX51DIORaw *dio,void *bus1) {
  Bus *bus = bus1;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)FreescaleIMX51DIORawInit;
  dio->Fini = (void *)FreescaleIMX51DIORawFini;
  dio->Lock = (void *)FreescaleIMX51DIORawLock;
  dio->Unlock = (void *)FreescaleIMX51DIORawUnlock;
  dio->Preempt = (void *)FreescaleIMX51DIORawPreempt;
  dio->DirSet = (void *)FreescaleIMX51DIORawDirSet;
  dio->DataSet = (void *)FreescaleIMX51DIORawDataSet;
  dio->DirGet = (void *)FreescaleIMX51DIORawDirGet;
  dio->DataGet = (void *)FreescaleIMX51DIORawDataGet;
  dio->Count = (void *)FreescaleIMX51DIORawCount;
  FreescaleIMX51DIORawLockInit(dio);
  dio->sub = bus;
  if (dio->sub->InitStatus <= 0) {
    dio->InitStatus = -1;
    return dio;
  }
  dio->InitStatus = 1;
  return dio;
}

canonical_original_code:
void *FreescaleIMX51DIORawInit(struct FreescaleIMX51DIORaw *dio, void *bus1) {
  struct Bus *bus = bus1;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)FreescaleIMX51DIORawInit;
  dio->Fini = (void *)FreescaleIMX51DIORawFini;
  dio->Lock = (void *)FreescaleIMX51DIORawLock;
  dio->Unlock = (void *)FreescaleIMX51DIORawUnlock;
  dio->Preempt = (void *)FreescaleIMX51DIORawPreempt;
  dio->DirSet = (void *)FreescaleIMX51DIORawDirSet;
  dio->DataSet = (void *)FreescaleIMX51DIORawDataSet;
  dio->DirGet = (void *)FreescaleIMX51DIORawDirGet;
  dio->DataGet = (void *)FreescaleIMX51DIORawDataGet;
  dio->Count = (void *)FreescaleIMX51DIORawCount;
  FreescaleIMX51DIORawLockInit(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 FreescaleIMX51DIORawFini(__int64 a1)
{
__int64 result; // rax

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

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

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


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

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

original_code:
unsigned FreescaleIMX51DIORawCount(FreescaleIMX51DIORaw *dio) {
  return 16;
}

canonical_original_code:
unsigned int FreescaleIMX51DIORawCount(struct FreescaleIMX51DIORaw *dio) {
  return 16;
}


original_code:
void FreescaleIMX51DIORawDirSet(FreescaleIMX51DIORaw *dio,
           int Num,int asOutput) {
  FreescaleIMX51DIORawLockReal(dio,0);
  dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(4) : (4)),( Num<0 ? ~(Num) : (Num)),asOutput);
}

canonical_original_code:
void FreescaleIMX51DIORawDirSet(struct FreescaleIMX51DIORaw *dio, int Num, int asOutput) {
  FreescaleIMX51DIORawLockReal(dio,0);
  dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(4) : (4)),( Num<0 ? ~(Num) : (Num)),asOutput);
}

variable_types: Num int

variable_types: asOutput int


decompiled_code:
__int64 __fastcall FreescaleIMX51DIORawDataSet(__int64 a1, int a2, unsigned int a3)
{
int v4; // eax

if ( *(_DWORD *)(a1 + 88) )
{
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 96) + 16LL))(*(_QWORD *)(a1 + 96), 0LL, 0LL);
v4 = *(_DWORD *)(a1 + 88) - 1;
*(_DWORD *)(a1 + 88) = v4;
}
while ( v4 );
}
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 96) + 160LL))(
*(_QWORD *)(a1 + 96),
(unsigned int)(a2 >> 31),
a2 ^ (unsigned int)(a2 >> 31),
a3);
}

original_code:
void FreescaleIMX51DIORawDataSet(FreescaleIMX51DIORaw *dio,
            int Num,int asHigh) {
  FreescaleIMX51DIORawLockReal(dio,0);
  dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0) : (0)),( Num<0 ? ~(Num) : (Num)),asHigh);
}

canonical_original_code:
void FreescaleIMX51DIORawDataSet(struct FreescaleIMX51DIORaw *dio, int Num, int asHigh) {
  FreescaleIMX51DIORawLockReal(dio,0);
  dio->sub->BitAssign32(dio->sub,( Num<0 ? ~(0) : (0)),( Num<0 ? ~(Num) : (Num)),asHigh);
}

variable_types: asHigh int


original_code:
int FreescaleIMX51DIORawDirGet(FreescaleIMX51DIORaw *dio,int Num) {
  FreescaleIMX51DIORawLockReal(dio,SHARED);
  return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(4) : (4)),( Num<0 ? ~(Num) : (Num)));
}

canonical_original_code:
int FreescaleIMX51DIORawDirGet(struct FreescaleIMX51DIORaw *dio, int Num) {
  FreescaleIMX51DIORawLockReal(dio,SHARED);
  return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(4) : (4)),( Num<0 ? ~(Num) : (Num)));
}


original_code:
int FreescaleIMX51DIORawDataGet(FreescaleIMX51DIORaw *dio,int Num) {
  FreescaleIMX51DIORawLockReal(dio,SHARED);
  return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(8) : (8)),( Num<0 ? ~(Num) : (Num)));
}

canonical_original_code:
int FreescaleIMX51DIORawDataGet(struct FreescaleIMX51DIORaw *dio, int Num) {
  FreescaleIMX51DIORawLockReal(dio,SHARED);
  return dio->sub->BitGet32(dio->sub,( Num<0 ? ~(8) : (8)),( Num<0 ? ~(Num) : (Num)));
}


decompiled_code:
__int64 __fastcall FreescaleIMX51DIORawLockReal(__int64 a1, char a2)
{
__int64 result; // rax

if ( (a2 & 2) != 0 )
{
if ( *(_DWORD *)(a1 + 84) )
{
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 96) + 16LL))(*(_QWORD *)(a1 + 96), 0LL, 2LL);
result = (unsigned int)(*(_DWORD *)(a1 + 84) - 1);
*(_DWORD *)(a1 + 84) = result;
}
while ( (_DWORD)result );
}
}
else if ( *(_DWORD *)(a1 + 88) )
{
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 96) + 16LL))(*(_QWORD *)(a1 + 96), 0LL, 0LL);
result = (unsigned int)(*(_DWORD *)(a1 + 88) - 1);
*(_DWORD *)(a1 + 88) = result;
}
while ( (_DWORD)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char a2)
{
__int64 result; // rax

if ( (a2 & 2) != 0 )
{
if ( *(_DWORD *)(a1 + 84) )
{
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 96) + 16LL))(*(_QWORD *)(a1 + 96), 0LL, 2LL);
result = (unsigned int)(*(_DWORD *)(a1 + 84) - 1);
*(_DWORD *)(a1 + 84) = result;
}
while ( (_DWORD)result );
}
}
else if ( *(_DWORD *)(a1 + 88) )
{
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 96) + 16LL))(*(_QWORD *)(a1 + 96), 0LL, 0LL);
result = (unsigned int)(*(_DWORD *)(a1 + 88) - 1);
*(_DWORD *)(a1 + 88) = result;
}
while ( (_DWORD)result );
}
return result;
}

original_code:
__attribute__((always_inline))
int FreescaleIMX51DIORawLockReal(FreescaleIMX51DIORaw *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 FreescaleIMX51DIORawLockReal(struct FreescaleIMX51DIORaw *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--;
    }
  }
}


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

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

variable_types: struct ts4700DIORaw { void *(*Init)(struct ts4700DIORaw *me, void *bus); void (*Fini)(struct ts4700DIORaw *me); int (*Lock)(struct ts4700DIORaw *me, unsigned int num, int flags); int (*Unlock)(struct ts4700DIORaw *me, unsigned int num, int flags); int (*Preempt)(struct ts4700DIORaw *me); void (*DirSet)(struct ts4700DIORaw *me, int num, int asOutput); void (*DataSet)(struct ts4700DIORaw *me, int num, int asHigh); int (*DirGet)(struct ts4700DIORaw *me, int num); int (*DataGet)(struct ts4700DIORaw *me, int num); unsigned int (*Count)(struct ts4700DIORaw *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; } *

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


original_code:
int ts4700DIORawUnlock(ts4700DIORaw *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 ts4700DIORawUnlock(struct ts4700DIORaw *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;
  }
}


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

original_code:
int ts4700DIORawPreempt(ts4700DIORaw *ob) {
  return -1;
}

canonical_original_code:
int ts4700DIORawPreempt(struct ts4700DIORaw *ob) {
  return -1;
}


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

result = a1;
if ( *(int *)(a1 + 80) <= 0 )
{
*(_QWORD *)a1 = ts4700DIORawInit;
*(_QWORD *)(a1 + 8) = ts4700DIORawFini;
*(_QWORD *)(a1 + 16) = ts4700DIORawLock;
*(_QWORD *)(a1 + 24) = ts4700DIORawUnlock;
*(_QWORD *)(a1 + 32) = ts4700DIORawPreempt;
*(_QWORD *)(a1 + 40) = ts4700DIORawDirSet;
*(_QWORD *)(a1 + 48) = ts4700DIORawDataSet;
*(_QWORD *)(a1 + 56) = ts4700DIORawDirGet;
*(_QWORD *)(a1 + 64) = ts4700DIORawDataGet;
*(_QWORD *)(a1 + 72) = ts4700DIORawCount;
*(_DWORD *)(a1 + 88) = 0;
*(_DWORD *)(a1 + 84) = 0;
*(_QWORD *)(a1 + 96) = a2;
if ( *(int *)(a2 + 288) <= 0 )
*(_DWORD *)(a1 + 80) = -1;
else
*(_DWORD *)(a1 + 80) = 1;
}
return result;
}

original_code:
void *ts4700DIORawInit(ts4700DIORaw *dio,void *bus1) {
  Bus *bus = bus1;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)ts4700DIORawInit;
  dio->Fini = (void *)ts4700DIORawFini;
  dio->Lock = (void *)ts4700DIORawLock;
  dio->Unlock = (void *)ts4700DIORawUnlock;
  dio->Preempt = (void *)ts4700DIORawPreempt;
  dio->DirSet = (void *)ts4700DIORawDirSet;
  dio->DataSet = (void *)ts4700DIORawDataSet;
  dio->DirGet = (void *)ts4700DIORawDirGet;
  dio->DataGet = (void *)ts4700DIORawDataGet;
  dio->Count = (void *)ts4700DIORawCount;
  ts4700DIORawLockInit(dio);
  dio->sub = bus;
  if (dio->sub->InitStatus <= 0) {
    dio->InitStatus = -1;
    return dio;
  }
  dio->InitStatus = 1;
  return dio;
}

canonical_original_code:
void *ts4700DIORawInit(struct ts4700DIORaw *dio, void *bus1) {
  struct Bus *bus = bus1;
  if (dio->InitStatus > 0) return dio;
  dio->Init = (void *)ts4700DIORawInit;
  dio->Fini = (void *)ts4700DIORawFini;
  dio->Lock = (void *)ts4700DIORawLock;
  dio->Unlock = (void *)ts4700DIORawUnlock;
  dio->Preempt = (void *)ts4700DIORawPreempt;
  dio->DirSet = (void *)ts4700DIORawDirSet;
  dio->DataSet = (void *)ts4700DIORawDataSet;
  dio->DirGet = (void *)ts4700DIORawDirGet;
  dio->DataGet = (void *)ts4700DIORawDataGet;
  dio->Count = (void *)ts4700DIORawCount;
  ts4700DIORawLockInit(dio);
  dio->sub = bus;
  if (dio->sub->InitStatus <= 0) {
    dio->InitStatus = -1;
    return dio;
  }
  dio->InitStatus = 1;
  return dio;
}


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

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


decompiled_code:
__int64 ts4700DIORawCount()
{
return 62LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 62LL;
}

original_code:
unsigned ts4700DIORawCount(ts4700DIORaw *dio) {
  return 62;
}

canonical_original_code:
unsigned int ts4700DIORawCount(struct ts4700DIORaw *dio) {
  return 62;
}


original_code:
void ts4700DIORawDirSet(ts4700DIORaw *dio,int Num,int asOutput) {
  if (( Num<0 ? ~(Num) : (Num)) >= 49 && ( Num<0 ? ~(Num) : (Num)) <= 52) printf("DirSet %d %d\n",Num,asOutput);
  if (( Num<0 ? ~(Num) : (Num)) > 59) return;
  ts4700DIORawLockReal(dio,0);
  if (( Num<0 ? ~(Num) : (Num)) <= 14) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x18) : (0x18)),( Num<0 ? ~(Num) : (Num)),asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 20) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1A) : (0x1A)),( Num<0 ? ~(Num) : (Num))-15,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 26) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1A) : (0x1A)),( Num<0 ? ~(Num) : (Num))-22+6,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 42) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1C) : (0x1C)),( Num<0 ? ~(Num) : (Num))-27,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 59) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1E) : (0x1E)),( Num<0 ? ~(Num) : (Num))-48,asOutput);
  }
}

canonical_original_code:
void ts4700DIORawDirSet(struct ts4700DIORaw *dio, int Num, int asOutput) {
  if (( Num<0 ? ~(Num) : (Num)) >= 49 && ( Num<0 ? ~(Num) : (Num)) <= 52) printf("DirSet %d %d\n",Num,asOutput);
  if (( Num<0 ? ~(Num) : (Num)) > 59) return;
  ts4700DIORawLockReal(dio,0);
  if (( Num<0 ? ~(Num) : (Num)) <= 14) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x18) : (0x18)),( Num<0 ? ~(Num) : (Num)),asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 20) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1A) : (0x1A)),( Num<0 ? ~(Num) : (Num))-15,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 26) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1A) : (0x1A)),( Num<0 ? ~(Num) : (Num))-22+6,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 42) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1C) : (0x1C)),( Num<0 ? ~(Num) : (Num))-27,asOutput);
  } else if (( Num<0 ? ~(Num) : (Num)) <= 59) {
    dio->sub->BitAssign16(dio->sub,( Num<0 ? ~(0x1E) : (0x1E)),( Num<0 ? ~(Num) : (Num))-48,asOutput);
  }
}


decompiled_code:
__int64 __fastcall ts4700DIORawLockReal(__int64 a1, char a2)
{
__int64 result; // rax

if ( (a2 & 2) != 0 )
{
if ( *(_DWORD *)(a1 + 84) )
{
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, __int64))(*(_QWORD *)(a1 + 96) + 16LL))(*(_QWORD *)(a1 + 96), 0LL, 2LL);
result = (unsigned int)(*(_DWORD *)(a1 + 84) - 1);
*(_DWORD *)(a1 + 84) = result;
}
while ( (_DWORD)result );
}
}
else if ( *(_DWORD *)(a1 + 88) )
{
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 96) + 16LL))(*(_QWORD *)(a1 + 96), 0LL, 0LL);
result = (unsigned int)(*(_DWORD *)(a1 + 88) - 1);
*(_DWORD *)(a1 + 88) = result;
}
while ( (_DWORD)result );
}
return result;
}

original_code:
__attribute__((always_inline))
int ts4700DIORawLockReal(ts4700DIORaw *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 ts4700DIORawLockReal(struct ts4700DIORaw *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--;
    }
  }
}


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

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

original_code:
int ts4800PinPreempt(ts4800Pin *ob) {
  return -1;
}

canonical_original_code:
int ts4800PinPreempt(struct ts4800Pin *ob) {
  return -1;
}

variable_types: struct ts4800Pin { void *(*Init)(struct ts4800Pin *me, void *syscon, void *dio1bus); void (*Fini)(struct ts4800Pin *me); int (*Lock)(struct ts4800Pin *me, unsigned int num, int flags); int (*Unlock)(struct ts4800Pin *me, unsigned int num, int flags); int (*Preempt)(struct ts4800Pin *me); enum PinMode { MODE_DIO=0, MODE_CAN=1, MODE_SPI=2, MODE_ADC=3, MODE_TWI=4, MODE_UART=5, MODE_TS=6, MODE_BUS=7, MODE_PWM=8, MODE_CLK=9, MODE_UNKNOWN=-1 } (*ModeGet)(struct ts4800Pin *me, int PinNumber); enum PinResult { PinSuccess=1, PinErrorModeInvalid=-13 } (*ModeSet)(struct ts4800Pin *me, int PinNumber, enum PinMode { MODE_DIO=0, MODE_CAN=1, MODE_SPI=2, MODE_ADC=3, MODE_TWI=4, MODE_UART=5, MODE_TS=6, MODE_BUS=7, MODE_PWM=8, MODE_CLK=9, MODE_UNKNOWN=-1 } Mode); int InitStatus; unsigned int LockBase; int deferlock; 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; } *

user_defined_types: struct ts4800Pin { void *(*Init)(struct ts4800Pin *me, void *syscon, void *dio1bus); void (*Fini)(struct ts4800Pin *me); int (*Lock)(struct ts4800Pin *me, unsigned int num, int flags); int (*Unlock)(struct ts4800Pin *me, unsigned int num, int flags); int (*Preempt)(struct ts4800Pin *me); enum PinMode (*ModeGet)(struct ts4800Pin *me, int PinNumber); enum PinResult (*ModeSet)(struct ts4800Pin *me, int PinNumber, enum PinMode Mode); int InitStatus; unsigned int LockBase; int deferlock; struct Bus *bus; }


original_code:
void ts4800PinFini(ts4800Pin *pin) {
  pin->bus->Fini(pin->bus);
  if (pin->InitStatus > 0) pin->InitStatus = 0;
}

canonical_original_code:
void ts4800PinFini(struct ts4800Pin *pin) {
  pin->bus->Fini(pin->bus);
  if (pin->InitStatus > 0) pin->InitStatus = 0;
}

user_defined_types: enum PinMode { MODE_DIO=0, MODE_CAN=1, MODE_SPI=2, MODE_ADC=3, MODE_TWI=4, MODE_UART=5, MODE_TS=6, MODE_BUS=7, MODE_PWM=8, MODE_CLK=9, MODE_UNKNOWN=-1 }

user_defined_types: enum PinResult { PinSuccess=1, PinErrorModeInvalid=-13 }


original_code:
PinMode ts4800PinModeGet(ts4800Pin *pin,int npin) {
  if (npin == 47 || npin == 45) {
    return pin->bus->BitGet16(pin->bus,0x10,0) ? MODE_CAN :
      pin->bus->BitGet16(pin->bus,0x12,0) ? MODE_BUS : MODE_DIO;
  }
  if (npin == 10 || npin == 11) {
    return pin->bus->BitGet16(pin->bus,0x10,1) ? MODE_CAN :
      pin->bus->BitGet16(pin->bus,0x12,0) ? MODE_BUS : MODE_DIO;
  }
  if (npin >= 21 && npin <= 55) {
    return pin->bus->BitGet16(pin->bus,0x12,0) ? MODE_BUS : MODE_DIO;
  }
  if (npin == 3) {
    return pin->bus->BitGet16(pin->bus,2,11) ? MODE_CLK : MODE_DIO;
  }
  if (npin == 42 || npin == 43 || npin == 44 || npin == 45 || npin == 18 || npin == 127 || npin == 128) {
    return pin->bus->BitGet16(pin->bus,0x10,7) ? MODE_SPI : MODE_DIO;
  }
  return MODE_UNKNOWN;
}

canonical_original_code:
enum PinMode ts4800PinModeGet(struct ts4800Pin *pin, int npin) {
  if (npin == 47 || npin == 45) {
    return pin->bus->BitGet16(pin->bus,0x10,0) ? MODE_CAN :
      pin->bus->BitGet16(pin->bus,0x12,0) ? MODE_BUS : MODE_DIO;
  }
  if (npin == 10 || npin == 11) {
    return pin->bus->BitGet16(pin->bus,0x10,1) ? MODE_CAN :
      pin->bus->BitGet16(pin->bus,0x12,0) ? MODE_BUS : MODE_DIO;
  }
  if (npin >= 21 && npin <= 55) {
    return pin->bus->BitGet16(pin->bus,0x12,0) ? MODE_BUS : MODE_DIO;
  }
  if (npin == 3) {
    return pin->bus->BitGet16(pin->bus,2,11) ? MODE_CLK : MODE_DIO;
  }
  if (npin == 42 || npin == 43 || npin == 44 || npin == 45 || npin == 18 || npin == 127 || npin == 128) {
    return pin->bus->BitGet16(pin->bus,0x10,7) ? MODE_SPI : MODE_DIO;
  }
  return MODE_UNKNOWN;
}

variable_types: npin int

return_type: enum PinMode { MODE_DIO=0, MODE_CAN=1, MODE_SPI=2, MODE_ADC=3, MODE_TWI=4, MODE_UART=5, MODE_TS=6, MODE_BUS=7, MODE_PWM=8, MODE_CLK=9, MODE_UNKNOWN=-1 }


original_code:
PinResult ts4800PinModeSet(ts4800Pin *pin,int npin,PinMode mode) {
  if (npin == 42 || npin == 43 || npin == 44 || npin == 45 || npin == 18 || npin == 127 || npin == 128) {
    if (mode != MODE_SPI && mode != MODE_DIO) return MODE_UNKNOWN;
    pin->bus->BitAssign16(pin->bus,0x10,7,(MODE_SPI == mode ? 1 : 0));
  }
  if (npin == 20) {
    if (mode == MODE_DIO) {
      pin->bus->BitClear16(pin->bus,0x10,9);
    }
  }
  if (npin >= 21 && npin <= 55) {
    if (mode == MODE_BUS) {
      pin->bus->BitSet16(pin->bus,0x12,0);
    } else if (mode == MODE_DIO) {
      pin->bus->BitClear16(pin->bus,0x12,0);
    }
  }
  if (npin == 47 || npin == 45) {
    if (mode != MODE_CAN && mode != MODE_DIO) return PinErrorModeInvalid;
    pin->bus->BitAssign16(pin->bus,0x10,0,mode == MODE_CAN);
  } else if (npin == 10 || npin == 11) {
    if (mode != MODE_CAN && mode != MODE_DIO) return PinErrorModeInvalid;
    pin->bus->BitAssign16(pin->bus,0x10,1,mode == MODE_CAN);
  }
  if (npin == 3) {
    pin->bus->Lock(pin->bus,0,0);
    if (mode == MODE_DIO) {
      pin->bus->BitClear16(pin->bus,2,11);
    } else if (mode == MODE_CLK) {
      pin->bus->BitSet16(pin->bus,2,11);
    } else {
      pin->bus->Unlock(pin->bus,0,0);
      return PinErrorModeInvalid;
    }
    pin->bus->Unlock(pin->bus,0,0);
  }
  return PinSuccess;
}

canonical_original_code:
enum PinResult ts4800PinModeSet(struct ts4800Pin *pin, int npin, enum PinMode mode) {
  if (npin == 42 || npin == 43 || npin == 44 || npin == 45 || npin == 18 || npin == 127 || npin == 128) {
    if (mode != MODE_SPI && mode != MODE_DIO) return MODE_UNKNOWN;
    pin->bus->BitAssign16(pin->bus,0x10,7,(MODE_SPI == mode ? 1 : 0));
  }
  if (npin == 20) {
    if (mode == MODE_DIO) {
      pin->bus->BitClear16(pin->bus,0x10,9);
    }
  }
  if (npin >= 21 && npin <= 55) {
    if (mode == MODE_BUS) {
      pin->bus->BitSet16(pin->bus,0x12,0);
    } else if (mode == MODE_DIO) {
      pin->bus->BitClear16(pin->bus,0x12,0);
    }
  }
  if (npin == 47 || npin == 45) {
    if (mode != MODE_CAN && mode != MODE_DIO) return PinErrorModeInvalid;
    pin->bus->BitAssign16(pin->bus,0x10,0,mode == MODE_CAN);
  } else if (npin == 10 || npin == 11) {
    if (mode != MODE_CAN && mode != MODE_DIO) return PinErrorModeInvalid;
    pin->bus->BitAssign16(pin->bus,0x10,1,mode == MODE_CAN);
  }
  if (npin == 3) {
    pin->bus->Lock(pin->bus,0,0);
    if (mode == MODE_DIO) {
      pin->bus->BitClear16(pin->bus,2,11);
    } else if (mode == MODE_CLK) {
      pin->bus->BitSet16(pin->bus,2,11);
    } else {
      pin->bus->Unlock(pin->bus,0,0);
      return PinErrorModeInvalid;
    }
    pin->bus->Unlock(pin->bus,0,0);
  }
  return PinSuccess;
}

variable_types: enum PinMode { MODE_DIO=0, MODE_CAN=1, MODE_SPI=2, MODE_ADC=3, MODE_TWI=4, MODE_UART=5, MODE_TS=6, MODE_BUS=7, MODE_PWM=8, MODE_CLK=9, MODE_UNKNOWN=-1 }

return_type: enum PinResult { PinSuccess=1, PinErrorModeInvalid=-13 }


decompiled_code:
__int64 __fastcall ts4800PinLock(__int64 a1, int a2, char a3)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 result; // rax

v3 = a3 & 2;
if ( (a3 & 2) != 0 )
{
v4 = 0;
if ( (a3 & 1) == 0 )
v4 = ((a3 & 4) == 0) + 1;
result = ThreadLockR((unsigned int)(*(_DWORD *)(a1 + 60) + a2), v4);
}
else
{
if ( (a3 & 1) == 0 )
v3 = ((a3 & 4) == 0) + 1;
result = ThreadLockW((unsigned int)(*(_DWORD *)(a1 + 60) + a2), v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, char a3)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 result; // rax

v3 = a3 & 2;
if ( (a3 & 2) != 0 )
{
v4 = 0;
if ( (a3 & 1) == 0 )
v4 = ((a3 & 4) == 0) + 1;
result = ThreadLockR((unsigned int)(*(_DWORD *)(a1 + 60) + a2), v4);
}
else
{
if ( (a3 & 1) == 0 )
v3 = ((a3 & 4) == 0) + 1;
result = ThreadLockW((unsigned int)(*(_DWORD *)(a1 + 60) + a2), v3);
}
return result;
}

original_code:
int ts4800PinLock(ts4800Pin *ob,unsigned num,int flags) {
  int ret;
  if (flags & SHARED) {
    ret = ThreadLockR(ob->LockBase+num,(flags & NONBLOCKING) ?
        LOCK_TRY :
        (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD);
  } else {
    ret = ThreadLockW(ob->LockBase+num,(flags & NONBLOCKING) ?
        LOCK_TRY :
        (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD);
  }
  return ret;
}

canonical_original_code:
int ts4800PinLock(struct ts4800Pin *ob, unsigned int num, int flags) {
  int ret;
  if (flags & SHARED) {
    ret = ThreadLockR(ob->LockBase+num,(flags & NONBLOCKING) ?
        LOCK_TRY :
        (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD);
  } else {
    ret = ThreadLockW(ob->LockBase+num,(flags & NONBLOCKING) ?
        LOCK_TRY :
        (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD);
  }
  return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall ts4800PinUnlock(__int64 a1, int a2, char a3)
{
__int64 result; // rax

if ( (a3 & 2) != 0 )
result = ThreadUnlockR((unsigned int)(*(_DWORD *)(a1 + 60) + a2));
else
result = ThreadUnlockW((unsigned int)(*(_DWORD *)(a1 + 60) + a2));
return result;
}

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

if ( (a3 & 2) != 0 )
result = ThreadUnlockR((unsigned int)(*(_DWORD *)(a1 + 60) + a2));
else
result = ThreadUnlockW((unsigned int)(*(_DWORD *)(a1 + 60) + a2));
return result;
}

original_code:
int ts4800PinUnlock(ts4800Pin *ob, unsigned num, int flags) {
  if (flags & SHARED) {
    return ThreadUnlockR(ob->LockBase+num);
  } else {
    return ThreadUnlockW(ob->LockBase+num);
  }
}

canonical_original_code:
int ts4800PinUnlock(struct ts4800Pin *ob, unsigned int num, int flags) {
  if (flags & SHARED) {
    return ThreadUnlockR(ob->LockBase+num);
  } else {
    return ThreadUnlockW(ob->LockBase+num);
  }
}


decompiled_code:
__int64 tsdio24ArchNextSubArch()
{
return tsdio24Next;
}

canonical_decompiled_code:
__int64 func0()
{
return tsdio24Next;
}

canonical_original_code:
struct Arch *tsdio24ArchNextSubArch() {
  return tsdio24Next;
}

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 tsdio24NextSubArchSet(__int64 a1)
{
tsdio24Next = a1;
}

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

original_code:
void tsdio24NextSubArchSet(Arch *arch) {
  tsdio24Next = arch;
}

canonical_original_code:
void tsdio24NextSubArchSet(struct Arch *arch) {
  tsdio24Next = 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); } *