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

if ( qword_1130 )
{
result = SDL_RemoveTimer();
qword_1130 = 0LL;
}
if ( timer_data )
{
result = SDL_DestroyCond();
timer_data = 0LL;
}
if ( qword_1128 )
{
result = SDL_DestroyMutex();
qword_1128 = 0LL;
}
return result;
}

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

if ( qword_1130 )
{
result = SDL_RemoveTimer();
qword_1130 = 0LL;
}
if ( timer_data )
{
result = SDL_DestroyCond();
timer_data = 0LL;
}
if ( qword_1128 )
{
result = SDL_DestroyMutex();
qword_1128 = 0LL;
}
return result;
}

original_code:
static void timer_quit(void)
{
  if (timer_data.timer_id != 0) {
    SDL_RemoveTimer(timer_data.timer_id);
    timer_data.timer_id = 0;
  }
  if (timer_data.cond != ((void *)0)) {
    SDL_DestroyCond(timer_data.cond);
    timer_data.cond = 0;
  }
  if (timer_data.mutex != ((void *)0)) {
    SDL_DestroyMutex(timer_data.mutex);
    timer_data.mutex = ((void *)0);
  }
}

canonical_original_code:
static void timer_quit()
{
  if (timer_data.timer_id != 0) {
    SDL_RemoveTimer(timer_data.timer_id);
    timer_data.timer_id = 0;
  }
  if (timer_data.cond != ((void *)0)) {
    SDL_DestroyCond(timer_data.cond);
    timer_data.cond = 0;
  }
  if (timer_data.mutex != ((void *)0)) {
    SDL_DestroyMutex(timer_data.mutex);
    timer_data.mutex = ((void *)0);
  }
}


printStrArray

repo: dreamlayers/acidwarp

decompiled_code:
int __fastcall printStrArray(const char **a1)
{
const char *v1; // rsi
const char **v2; // rbx
int result; // eax

v1 = *a1;
if ( **a1 )
{
v2 = a1;
do
{
++v2;
result = printf("%s", v1);
v1 = *v2;
}
while ( **v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char **a1)
{
const char *v1; // rsi
const char **v2; // rbx
int result; // eax

v1 = *a1;
if ( **a1 )
{
v2 = a1;
do
{
++v2;
result = printf("%s", v1);
v1 = *v2;
}
while ( **v2 );
}
return result;
}

original_code:
void printStrArray(char *strArray[])
{
  char **strPtr;
  for (strPtr = strArray; **strPtr; ++strPtr)
    printf ("%s", *strPtr);
}

variable_types:
strArray
char *[]

variable_types:
strPtr
char **

return_type: void


commandline

decompiled_code:
void __fastcall commandline(int a1, __int64 a2)
{
int v3; // ebx
__int64 v4; // r15
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
__int64 v9; // [rsp+0h] [rbp-50h]
__int64 v10; // [rsp+0h] [rbp-50h]
__int64 v11; // [rsp+8h] [rbp-48h]
__int64 v12; // [rsp+8h] [rbp-48h]
int v13; // [rsp+14h] [rbp-3Ch]

if ( a1 > 1 )
{
v3 = 1;
v13 = a1 - 1;
while ( 1 )
{
v4 = *(_QWORD *)(a2 + 8LL * v3);
if ( *(_BYTE *)v4 != 45 )
break;
if ( *(_BYTE *)(v4 + 1) == 119 && !*(_BYTE *)(v4 + 2) )
{
printStrArray((const char **)The_warper_string);
exit(0);
}
if ( *(_BYTE *)(v4 + 1) == 104 && !*(_BYTE *)(v4 + 2) )
{
printStrArray((const char **)Help_string);
printf(
"\n%s\n",
"Acid Warp Version 4.10 (C)Copyright 1992, 1993 by Noah Spurrier and Mark Bilk\n"
"SDL port by Boris Gjenero based on Linux port by Steven Wills");
exit(0);
}
if ( *(_BYTE *)(v4 + 1) != 110 || *(_BYTE *)(v4 + 2) )
{
if ( *(_BYTE *)(v4 + 1) != 102 || *(_BYTE *)(v4 + 2) )
{
if ( *(_BYTE *)(v4 + 1) != 107 || *(_BYTE *)(v4 + 2) )
{
if ( *(_BYTE *)(v4 + 1) != 111 || *(_BYTE *)(v4 + 2) )
break;
draw_flags &= 0xFFFFFFFD;
}
else
{
disp_flags |= 2u;
}
}
else
{
disp_flags |= 1u;
}
}
else
{
show_logo = 0;
}
LABEL_18:
if ( a1 <= ++v3 )
return;
}
v11 = a2;
v9 = 8LL * v3;
v5 = strcmp("-u", *(const char **)(a2 + v9));
a2 = v11;
if ( v5 )
{
v6 = strcmp("-d", (const char *)v4);
a2 = v11;
if ( v6 )
{
v10 = v11;
v12 = 8LL * v3;
if ( strcmp("-s", (const char *)v4) )
{
fprintf(stderr, "Unknown option \"%s\"\n", (const char *)v4);
exit(-1);
}
a2 = v10;
if ( v13 > v3 )
{
++v3;
v7 = atoi(*(const char **)(v10 + v12 + 8));
a2 = v10;
ROTATION_DELAY = v7;
}
}
else if ( v13 > v3 )
{
++v3;
v8 = atoi(*(const char **)(v11 + v9 + 8));
a2 = v11;
image_time = v8;
}
}
else
{
draw_flags &= 0xFFFFFFFB;
}
goto LABEL_18;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, __int64 a2)
{
int v3; // ebx
__int64 v4; // r15
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
__int64 v9; // [rsp+0h] [rbp-50h]
__int64 v10; // [rsp+0h] [rbp-50h]
__int64 v11; // [rsp+8h] [rbp-48h]
__int64 v12; // [rsp+8h] [rbp-48h]
int v13; // [rsp+14h] [rbp-3Ch]

if ( a1 > 1 )
{
v3 = 1;
v13 = a1 - 1;
while ( 1 )
{
v4 = *(_QWORD *)(a2 + 8LL * v3);
if ( *(_BYTE *)v4 != 45 )
break;
if ( *(_BYTE *)(v4 + 1) == 119 && !*(_BYTE *)(v4 + 2) )
{
func1((const char **)The_warper_string);
exit(0);
}
if ( *(_BYTE *)(v4 + 1) == 104 && !*(_BYTE *)(v4 + 2) )
{
func1((const char **)Help_string);
printf(
"\n%s\n",
"Acid Warp Version 4.10 (C)Copyright 1992, 1993 by Noah Spurrier and Mark Bilk\n"
"SDL port by Boris Gjenero based on Linux port by Steven Wills");
exit(0);
}
if ( *(_BYTE *)(v4 + 1) != 110 || *(_BYTE *)(v4 + 2) )
{
if ( *(_BYTE *)(v4 + 1) != 102 || *(_BYTE *)(v4 + 2) )
{
if ( *(_BYTE *)(v4 + 1) != 107 || *(_BYTE *)(v4 + 2) )
{
if ( *(_BYTE *)(v4 + 1) != 111 || *(_BYTE *)(v4 + 2) )
break;
draw_flags &= 0xFFFFFFFD;
}
else
{
disp_flags |= 2u;
}
}
else
{
disp_flags |= 1u;
}
}
else
{
show_logo = 0;
}
LABEL_18:
if ( a1 <= ++v3 )
return;
}
v11 = a2;
v9 = 8LL * v3;
v5 = strcmp("-u", *(const char **)(a2 + v9));
a2 = v11;
if ( v5 )
{
v6 = strcmp("-d", (const char *)v4);
a2 = v11;
if ( v6 )
{
v10 = v11;
v12 = 8LL * v3;
if ( strcmp("-s", (const char *)v4) )
{
fprintf(stderr, "Unknown option \"%s\"\n", (const char *)v4);
exit(-1);
}
a2 = v10;
if ( v13 > v3 )
{
++v3;
v7 = atoi(*(const char **)(v10 + v12 + 8));
a2 = v10;
ROTATION_DELAY = v7;
}
}
else if ( v13 > v3 )
{
++v3;
v8 = atoi(*(const char **)(v11 + v9 + 8));
a2 = v11;
image_time = v8;
}
}
else
{
draw_flags &= 0xFFFFFFFB;
}
goto LABEL_18;
}
}

original_code:
static void commandline(int argc, char *argv[])
{
  int argNum;
  if (argc >= 2) {
    for (argNum = 1; argNum < argc; ++argNum) {
      if (!strcmp("-w",argv[argNum])) {
        printStrArray(The_warper_string);
        exit (0);
      }
      else
      if (!strcmp("-h",argv[argNum])) {
        printStrArray(Help_string);
        printf("\n%s\n", "Acid Warp Version 4.10 (C)Copyright 1992, 1993 by Noah Spurrier and Mark Bilk\nSDL port by Boris Gjenero based on Linux port by Steven Wills");
        exit (0);
      }
      else
      if(!strcmp("-n",argv[argNum])) {
        show_logo = 0;
      }
      else
      if(!strcmp("-f",argv[argNum])) {
        disp_flags |= 1;
      }
      else
      if(!strcmp("-k",argv[argNum])) {
        disp_flags |= 2;
      }
      else
      if(!strcmp("-o",argv[argNum])) {
        draw_flags &= ~2;
      }
      else
      if(!strcmp("-u",argv[argNum])) {
        draw_flags &= ~4;
      }
      else
      if(!strcmp("-d",argv[argNum])) {
        if((argc-1) > argNum) {
          argNum++;
          image_time = atoi(argv[argNum]);
        }
      }
      else
      if(!strcmp("-s", argv[argNum])) {
        if((argc-1) > argNum) {
          argNum++;
          ROTATION_DELAY = atoi(argv[argNum]);
        }
      }
      else
   {
     fprintf(stderr, "Unknown option \"%s\"\n", argv[argNum]);
     exit(-1);
   }
    }
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: argNum int


mainLoop

decompiled_code:
time_t mainLoop()
{
time_t result; // rax
time_t v1; // rax

disp_processInput();
if ( RESIZE )
{
RESIZE = 0;
if ( !state_2 )
{
if ( !SKIP )
goto LABEL_4;
goto LABEL_21;
}
draw_same();
applyPalette();
}
if ( !SKIP )
{
LABEL_4:
if ( !NP )
goto LABEL_7;
if ( show_logo )
goto LABEL_6;
goto LABEL_22;
}
state_2 = state_2 != 0;
LABEL_21:
show_logo = 0;
if ( NP )
{
LABEL_22:
newPalette();
LABEL_6:
NP = 0;
}
LABEL_7:
result = (unsigned int)state_2;
if ( state_2 != 2 )
{
if ( (unsigned int)state_2 > 2 )
{
if ( state_2 == 3 )
{
if ( GO )
{
result = fadeOut();
if ( (_DWORD)result )
{
show_logo = 0;
state_2 = 1;
}
}
}
return result;
}
if ( !state_2 )
{
draw_init(draw_flags | (unsigned int)(show_logo != 0));
initRolNFade((unsigned int)show_logo);
}
draw_next();
if ( !(SKIP | show_logo) )
newPalette();
SKIP = 0;
v1 = time(0LL);
state_2 = 2;
mtime_0 = v1 + image_time;
}
if ( GO )
{
fadeInAndRotate();
result = time(0LL);
if ( result <= mtime_0 )
return result;
}
else
{
result = time(0LL);
if ( result <= mtime_0 )
return result;
}
if ( !LOCK )
{
result = beginFadeOut((unsigned int)show_logo);
state_2 = 3;
}
return result;
}

canonical_decompiled_code:
time_t func3()
{
time_t result; // rax
time_t v1; // rax

disp_processInput();
if ( RESIZE )
{
RESIZE = 0;
if ( !state_2 )
{
if ( !SKIP )
goto LABEL_4;
goto LABEL_21;
}
draw_same();
applyPalette();
}
if ( !SKIP )
{
LABEL_4:
if ( !NP )
goto LABEL_7;
if ( show_logo )
goto LABEL_6;
goto LABEL_22;
}
state_2 = state_2 != 0;
LABEL_21:
show_logo = 0;
if ( NP )
{
LABEL_22:
newPalette();
LABEL_6:
NP = 0;
}
LABEL_7:
result = (unsigned int)state_2;
if ( state_2 != 2 )
{
if ( (unsigned int)state_2 > 2 )
{
if ( state_2 == 3 )
{
if ( GO )
{
result = fadeOut();
if ( (_DWORD)result )
{
show_logo = 0;
state_2 = 1;
}
}
}
return result;
}
if ( !state_2 )
{
draw_init(draw_flags | (unsigned int)(show_logo != 0));
initRolNFade((unsigned int)show_logo);
}
draw_next();
if ( !(SKIP | show_logo) )
newPalette();
SKIP = 0;
v1 = time(0LL);
state_2 = 2;
mtime_0 = v1 + image_time;
}
if ( GO )
{
fadeInAndRotate();
result = time(0LL);
if ( result <= mtime_0 )
return result;
}
else
{
result = time(0LL);
if ( result <= mtime_0 )
return result;
}
if ( !LOCK )
{
result = beginFadeOut((unsigned int)show_logo);
state_2 = 3;
}
return result;
}

original_code:
static void mainLoop(void)
{
  static time_t ltime, mtime;
  static enum {
    STATE_INITIAL,
    STATE_NEXT,
    STATE_DISPLAY,
    STATE_FADEOUT
  } state = STATE_INITIAL;
  disp_processInput();
  if (RESIZE) {
    RESIZE = FALSE;
    if (state != STATE_INITIAL) {
      draw_same();
      applyPalette();
    }
  }
  if (SKIP) {
    if (state != STATE_INITIAL) state = STATE_NEXT;
    show_logo = 0;
  }
  if(NP) {
    if (!show_logo) newPalette();
    NP = FALSE;
  }
  switch (state) {
  case STATE_INITIAL:
    draw_init(draw_flags | (show_logo ? 1 : 0));
    initRolNFade(show_logo);
  case STATE_NEXT:
    draw_next();
    if (!show_logo && !SKIP) {
      newPalette();
    }
    SKIP = FALSE;
    ltime = time(((void *)0));
    mtime = ltime + image_time;
    state = STATE_DISPLAY;
  case STATE_DISPLAY:
    if(GO) {
      fadeInAndRotate();
    }
    ltime=time(((void *)0));
    if(ltime > mtime && !LOCK) {
      beginFadeOut(show_logo);
      state = STATE_FADEOUT;
    }
    break;
  case STATE_FADEOUT:
    if(GO) {
      if (fadeOut()) {
        show_logo = 0;
        state = STATE_NEXT;
      }
    }
    break;
  }
}

canonical_original_code:
static void mainLoop()
{
  static long ltime; static long mtime;
  static enum { STATE_INITIAL=0, STATE_NEXT=1, STATE_DISPLAY=2, STATE_FADEOUT=3 } state = STATE_INITIAL;
  disp_processInput();
  if (RESIZE) {
    RESIZE = FALSE;
    if (state != STATE_INITIAL) {
      draw_same();
      applyPalette();
    }
  }
  if (SKIP) {
    if (state != STATE_INITIAL) state = STATE_NEXT;
    show_logo = 0;
  }
  if(NP) {
    if (!show_logo) newPalette();
    NP = FALSE;
  }
  switch (state) {
  case STATE_INITIAL:
    draw_init(draw_flags | (show_logo ? 1 : 0));
    initRolNFade(show_logo);
  case STATE_NEXT:
    draw_next();
    if (!show_logo && !SKIP) {
      newPalette();
    }
    SKIP = FALSE;
    ltime = time(((void *)0));
    mtime = ltime + image_time;
    state = STATE_DISPLAY;
  case STATE_DISPLAY:
    if(GO) {
      fadeInAndRotate();
    }
    ltime=time(((void *)0));
    if(ltime > mtime && !LOCK) {
      beginFadeOut(show_logo);
      state = STATE_FADEOUT;
    }
    break;
  case STATE_FADEOUT:
    if(GO) {
      if (fadeOut()) {
        show_logo = 0;
        state = STATE_NEXT;
      }
    }
    break;
  }
}

variable_types: ltime long

variable_types: mtime long


quit

decompiled_code:
void __fastcall __noreturn quit(int status)
{
timer_quit();
draw_quit();
disp_quit();
SDL_Quit();
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int status)
{
func0();
draw_quit();
disp_quit();
SDL_Quit();
exit(status);
}

original_code:
void quit(int retcode)
{
  timer_quit();
  draw_quit();
  disp_quit();
  SDL_Quit();
  exit(retcode);
}

variable_types: retcode int


fatalSDLError

decompiled_code:
void __fastcall __noreturn fatalSDLError(const char *a1)
{
const char *v1; // rax

v1 = (const char *)SDL_GetError();
fprintf(stderr, "SDL error while %s: %s", a1, v1);
quit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
const char *v1; // rax

v1 = (const char *)SDL_GetError();
fprintf(stderr, "SDL error while %s: %s", a1, v1);
func4(-1);
}

original_code:
void fatalSDLError(const char *msg)
{
  fprintf(stderr, "SDL error while %s: %s", msg, SDL_GetError());
  quit(-1);
}

canonical_original_code:
void fatalSDLError(char *msg)
{
  fprintf(stderr, "SDL error while %s: %s", msg, SDL_GetError());
  quit(-1);
}

variable_types:
msg
char *


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

qword_1128 = SDL_CreateMutex();
if ( !qword_1128 )
fatalSDLError("creating timer mutex");
timer_data = SDL_CreateCond();
if ( !timer_data )
fatalSDLError("creating timer condition variable");
result = SDL_AddTimer((unsigned int)(ROTATION_DELAY / 1000), timer_proc, timer_data);
qword_1130 = result;
if ( !result )
fatalSDLError("adding timer");
return result;
}

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

qword_1128 = SDL_CreateMutex();
if ( !qword_1128 )
func5("creating timer mutex");
timer_data = SDL_CreateCond();
if ( !timer_data )
func5("creating timer condition variable");
result = SDL_AddTimer((unsigned int)(ROTATION_DELAY / 1000), timer_proc, timer_data);
qword_1130 = result;
if ( !result )
func5("adding timer");
return result;
}

original_code:
static void timer_init(void)
{
  timer_data.mutex = SDL_CreateMutex();
  if (timer_data.mutex == ((void *)0)) {
    fatalSDLError("creating timer mutex");
  }
  timer_data.cond = SDL_CreateCond();
  if (timer_data.cond == ((void *)0)) {
    fatalSDLError("creating timer condition variable");
  }
  timer_data.timer_id = SDL_AddTimer((ROTATION_DELAY / 1000), timer_proc,
                                     timer_data.cond);
  if (timer_data.timer_id == 0) {
    fatalSDLError("adding timer");
  }
}

canonical_original_code:
static void timer_init()
{
  timer_data.mutex = SDL_CreateMutex();
  if (timer_data.mutex == ((void *)0)) {
    fatalSDLError("creating timer mutex");
  }
  timer_data.cond = SDL_CreateCond();
  if (timer_data.cond == ((void *)0)) {
    fatalSDLError("creating timer condition variable");
  }
  timer_data.timer_id = SDL_AddTimer((ROTATION_DELAY / 1000), timer_proc,
                                     timer_data.cond);
  if (timer_data.timer_id == 0) {
    fatalSDLError("adding timer");
  }
}


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

result = SDL_mutexP(qword_1128);
if ( (_DWORD)result )
fatalSDLError("locking timer mutex");
return result;
}

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

result = SDL_mutexP(qword_1128);
if ( (_DWORD)result )
func5("locking timer mutex");
return result;
}

original_code:
static void timer_lock(void)
{
  if (SDL_mutexP(timer_data.mutex) != 0) {
    fatalSDLError("locking timer mutex");
  }
}

canonical_original_code:
static void timer_lock()
{
  if (SDL_mutexP(timer_data.mutex) != 0) {
    fatalSDLError("locking timer mutex");
  }
}


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

result = SDL_mutexV(qword_1128);
if ( (_DWORD)result )
fatalSDLError("unlocking timer mutex");
return result;
}

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

result = SDL_mutexV(qword_1128);
if ( (_DWORD)result )
func5("unlocking timer mutex");
return result;
}

original_code:
static void timer_unlock(void)
{
  if (SDL_mutexV(timer_data.mutex) != 0) {
    fatalSDLError("unlocking timer mutex");
  }
}

canonical_original_code:
static void timer_unlock()
{
  if (SDL_mutexV(timer_data.mutex) != 0) {
    fatalSDLError("unlocking timer mutex");
  }
}


decompiled_code:
__int64 timer_proc()
{
unsigned int v0; // ebx
__int64 result; // rax

v0 = ROTATION_DELAY / 1000;
timer_lock();
dword_1138 = 1;
SDL_CondSignal(timer_data);
timer_unlock();
result = 1LL;
if ( v0 )
result = v0;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // ebx
__int64 result; // rax

v0 = ROTATION_DELAY / 1000;
func7();
dword_1138 = 1;
SDL_CondSignal(timer_data);
func8();
result = 1LL;
if ( v0 )
result = v0;
return result;
}

original_code:
static Uint32 timer_proc(Uint32 interval, void *param)
{
  unsigned int tmint = (ROTATION_DELAY / 1000);
  timer_lock();
  timer_data.flag = SDL_TRUE;
  SDL_CondSignal(timer_data.cond);
  timer_unlock();
  return tmint ? tmint : 1;
}

canonical_original_code:
static unsigned int timer_proc(unsigned int interval, void *param)
{
  unsigned int tmint = (ROTATION_DELAY / 1000);
  timer_lock();
  timer_data.flag = SDL_TRUE;
  SDL_CondSignal(timer_data.cond);
  timer_unlock();
  return tmint ? tmint : 1;
}

variable_types:
interval
unsigned int

variable_types:
param
void *

variable_types:
tmint
unsigned int

return_type: unsigned int


decompiled_code:
__int64 timer_wait()
{
timer_lock();
while ( !dword_1138 )
{
if ( (unsigned int)SDL_CondWait(timer_data, qword_1128) )
fatalSDLError("waiting on condition");
}
dword_1138 = 0;
return timer_unlock();
}

canonical_decompiled_code:
__int64 func10()
{
func7();
while ( !dword_1138 )
{
if ( (unsigned int)SDL_CondWait(timer_data, qword_1128) )
func5("waiting on condition");
}
dword_1138 = 0;
return func8();
}

original_code:
static void timer_wait(void)
{
  timer_lock();
  while (!timer_data.flag) {
    if (SDL_CondWait(timer_data.cond, timer_data.mutex) != 0) {
      fatalSDLError("waiting on condition");
    }
  }
  timer_data.flag = SDL_FALSE;
  timer_unlock();
}

canonical_original_code:
static void timer_wait()
{
  timer_lock();
  while (!timer_data.flag) {
    if (SDL_CondWait(timer_data.cond, timer_data.mutex) != 0) {
      fatalSDLError("waiting on condition");
    }
  }
  timer_data.flag = SDL_FALSE;
  timer_unlock();
}


makeShuffledList

decompiled_code:
void __fastcall makeShuffledList(char *a1, int a2)
{
int v2; // er13
char *v3; // rax

if ( a2 > 0 )
{
v2 = 0;
memset(a1, 255, 4LL * a2);
do
{
do
v3 = &a1[4 * (rand() / (0x7FFFFFFF / a2 + 1))];
while ( *(_DWORD *)v3 != -1 );
*(_DWORD *)v3 = v2++;
}
while ( a2 != v2 );
}
}

original_code:
void makeShuffledList(int *list, int listSize)
{
  int entryNum, r;
  for (entryNum = 0; entryNum < listSize; ++entryNum)
    list[entryNum] = -1;
  for (entryNum = 0; entryNum < listSize; ++entryNum)
    {
      do
        r = (rand() / (2147483647 / (listSize) + 1));
      while (list[r] != -1);
      list[r] = entryNum;
    }
}

canonical_original_code:
void makeShuffledList(int *list, int listSize)
{
  int entryNum; int r;
  for (entryNum = 0; entryNum < listSize; ++entryNum)
    list[entryNum] = -1;
  for (entryNum = 0; entryNum < listSize; ++entryNum)
    {
      do
        r = (rand() / (2147483647 / (listSize) + 1));
      while (list[r] != -1);
      list[r] = entryNum;
    }
}

variable_types:
list
int *

variable_types: listSize int

variable_types: entryNum int

variable_types: r int


handleinput

decompiled_code:
void __fastcall handleinput(int a1)
{
int v1; // eax

switch ( a1 )
{
case 1:
GO = GO == 0;
break;
case 2:
SKIP = 1;
break;
case 3:
quit(0);
case 4:
NP = 1;
break;
case 5:
LOCK = LOCK == 0;
break;
case 6:
v1 = ROTATION_DELAY - 5000;
if ( ROTATION_DELAY - 5000 < 0 )
v1 = 0;
ROTATION_DELAY = v1;
break;
case 7:
ROTATION_DELAY += 5000;
break;
case 8:
RESIZE = 1;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func12(int a1)
{
int v1; // eax

switch ( a1 )
{
case 1:
GO = GO == 0;
break;
case 2:
SKIP = 1;
break;
case 3:
func4(0);
case 4:
NP = 1;
break;
case 5:
LOCK = LOCK == 0;
break;
case 6:
v1 = ROTATION_DELAY - 5000;
if ( ROTATION_DELAY - 5000 < 0 )
v1 = 0;
ROTATION_DELAY = v1;
break;
case 7:
ROTATION_DELAY += 5000;
break;
case 8:
RESIZE = 1;
break;
default:
return;
}
}

original_code:
void handleinput(enum acidwarp_command cmd)
{
  switch(cmd)
    {
    case CMD_PAUSE:
      if(GO)
 GO = FALSE;
      else
 GO = TRUE;
      break;
    case CMD_SKIP:
      SKIP = TRUE;
      break;
    case CMD_QUIT:
      quit(0);
      break;
    case CMD_NEWPAL:
      NP = TRUE;
      break;
    case CMD_LOCK:
      if(LOCK)
 LOCK = FALSE;
      else
 LOCK = TRUE;
      break;
    case CMD_PAL_FASTER:
      ROTATION_DELAY = ROTATION_DELAY - 5000;
      if (ROTATION_DELAY < 0)
 ROTATION_DELAY = 0;
      break;
    case CMD_PAL_SLOWER:
      ROTATION_DELAY = ROTATION_DELAY + 5000;
      break;
    case CMD_RESIZE:
      RESIZE = TRUE;
      break;
    }
}

variable_types: enum acidwarp_command { CMD_PAUSE=1, CMD_SKIP=2, CMD_QUIT=3, CMD_NEWPAL=4, CMD_LOCK=5, CMD_PAL_FASTER=6, CMD_PAL_SLOWER=7, CMD_RESIZE=8 }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rax

if ( (int)SDL_Init(33LL, argv, envp) >= 0 )
{
v3 = time(0LL);
srand(v3);
commandline(argc, (__int64)argv);
puts("\nPlease wait...\n\n\n*** Press Control-C to exit the program at any time. ***");
printf(
"\n\n%s\n",
"Acid Warp Version 4.10 (C)Copyright 1992, 1993 by Noah Spurrier and Mark Bilk\n"
"SDL port by Boris Gjenero based on Linux port by Steven Wills");
disp_init(320LL, 200LL, (unsigned int)disp_flags);
timer_init();
while ( 1 )
{
mainLoop();
timer_wait();
}
}
v4 = (const char *)SDL_GetError();
fprintf(stderr, "Failed to initialize SDL: %s\n", v4);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rax

if ( (int)SDL_Init(33LL, argv, envp) >= 0 )
{
v3 = time(0LL);
srand(v3);
func2(argc, (__int64)argv);
puts("\nPlease wait...\n\n\n*** Press Control-C to exit the program at any time. ***");
printf(
"\n\n%s\n",
"Acid Warp Version 4.10 (C)Copyright 1992, 1993 by Noah Spurrier and Mark Bilk\n"
"SDL port by Boris Gjenero based on Linux port by Steven Wills");
disp_init(320LL, 200LL, (unsigned int)disp_flags);
func6();
while ( 1 )
{
func3();
func10();
}
}
v4 = (const char *)SDL_GetError();
fprintf(stderr, "Failed to initialize SDL: %s\n", v4);
return -1;
}

original_code:
int main (int argc, char *argv[])
{
  if ( SDL_Init(0x00000020
                | 0x00000001
                ) < 0 ) {
    fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
    return -1;
  }
  (srand((UINT)time( (time_t *)((void *)0) )));
  commandline(argc, argv);
  printf ("\nPlease wait...\n"
   "\n\n*** Press Control-C to exit the program at any time. ***\n");
  printf ("\n\n%s\n", "Acid Warp Version 4.10 (C)Copyright 1992, 1993 by Noah Spurrier and Mark Bilk\nSDL port by Boris Gjenero based on Linux port by Steven Wills");
  disp_init(width, height, disp_flags);
  timer_init();
  while(1) {
    mainLoop();
    timer_wait();
  }
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if ( SDL_Init(0x00000020
                | 0x00000001
                ) < 0 ) {
    fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
    return -1;
  }
  (srand((unsigned int)time( (long *)((void *)0) )));
  commandline(argc, argv);
  printf ("\nPlease wait...\n"
   "\n\n*** Press Control-C to exit the program at any time. ***\n");
  printf ("\n\n%s\n", "Acid Warp Version 4.10 (C)Copyright 1992, 1993 by Noah Spurrier and Mark Bilk\nSDL port by Boris Gjenero based on Linux port by Steven Wills");
  disp_init(width, height, disp_flags);
  timer_init();
  while(1) {
    mainLoop();
    timer_wait();
  }
}

return_type: int


maybeInvertSubPalRollDirection

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

result = (unsigned int)(rand() / 0x800000);
switch ( (_DWORD)result )
{
case 1:
result = GrnRollDirection == 0;
GrnRollDirection = GrnRollDirection == 0;
break;
case 2:
result = BluRollDirection == 0;
BluRollDirection = BluRollDirection == 0;
break;
case 0:
result = RedRollDirection == 0;
RedRollDirection = RedRollDirection == 0;
break;
}
return result;
}

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

result = (unsigned int)(rand() / 0x800000);
switch ( (_DWORD)result )
{
case 1:
result = GrnRollDirection == 0;
GrnRollDirection = GrnRollDirection == 0;
break;
case 2:
result = BluRollDirection == 0;
BluRollDirection = BluRollDirection == 0;
break;
case 0:
result = RedRollDirection == 0;
RedRollDirection = RedRollDirection == 0;
break;
}
return result;
}

original_code:
static void maybeInvertSubPalRollDirection(void)
{
  switch ((rand() / (2147483647 / (256) + 1)))
 {
  case 0 :
   RedRollDirection = !RedRollDirection;
  break;
  case 1 :
   GrnRollDirection = !GrnRollDirection;
  break;
  case 2 :
   BluRollDirection = !BluRollDirection;
  break;
 }
}

canonical_original_code:
static void maybeInvertSubPalRollDirection()
{
  switch ((rand() / (2147483647 / (256) + 1)))
 {
  case 0 :
   RedRollDirection = !RedRollDirection;
  break;
  case 1 :
   GrnRollDirection = !GrnRollDirection;
  break;
  case 2 :
   BluRollDirection = !BluRollDirection;
  break;
 }
}


newPalette

decompiled_code:
__int64 newPalette()
{
int v0; // eax
__int64 result; // rax
int v2; // eax

v0 = rand();
paletteTypeNum = v0 / 238609295;
if ( v0 > 1908874359 )
{
v2 = rand();
result = initPalArray(TargetPalArray, (unsigned int)(v2 / 0x10000000));
}
else
{
result = initPalArray(TargetPalArray, (unsigned int)(v0 / 238609295));
FadeCompleteFlag = 0;
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // eax
__int64 result; // rax
int v2; // eax

v0 = rand();
paletteTypeNum = v0 / 238609295;
if ( v0 > 1908874359 )
{
v2 = rand();
result = initPalArray(TargetPalArray, (unsigned int)(v2 / 0x10000000));
}
else
{
result = initPalArray(TargetPalArray, (unsigned int)(v0 / 238609295));
FadeCompleteFlag = 0;
}
return result;
}

original_code:
void newPalette(void)
{
  paletteTypeNum = (rand() / (2147483647 / (8 + 1) + 1));
  if (paletteTypeNum >= 8) {
    initPalArray(TargetPalArray, (rand() / (2147483647 / (8) + 1)));
  } else {
    initPalArray(TargetPalArray, paletteTypeNum);
    FadeCompleteFlag = FALSE;
  }
}

canonical_original_code:
void newPalette()
{
  paletteTypeNum = (rand() / (2147483647 / (8 + 1) + 1));
  if (paletteTypeNum >= 8) {
    initPalArray(TargetPalArray, (rand() / (2147483647 / (8) + 1)));
  } else {
    initPalArray(TargetPalArray, paletteTypeNum);
    FadeCompleteFlag = FALSE;
  }
}


fadeInAndRotate

decompiled_code:
__int64 fadeInAndRotate()
{
if ( paletteTypeNum == 8 )
return rolNFadMainPalAry2RndTargNLdDAC_constprop_0();
if ( FadeCompleteFlag )
return rollMainPalArrayAndLoadDACRegs_constprop_0();
return rolNFadeMainPalAryToTargNLodDAC_constprop_0();
}

canonical_decompiled_code:
__int64 func13()
{
if ( paletteTypeNum == 8 )
return func5();
if ( FadeCompleteFlag )
return func8();
return func11();
}

original_code:
void fadeInAndRotate(void)
{
  if (paletteTypeNum == 8) {
    rolNFadMainPalAry2RndTargNLdDAC(MainPalArray,TargetPalArray);
  } else if (!FadeCompleteFlag) {
    rolNFadeMainPalAryToTargNLodDAC(MainPalArray,TargetPalArray);
  } else {
    rollMainPalArrayAndLoadDACRegs(MainPalArray);
  }
}

canonical_original_code:
void fadeInAndRotate()
{
  if (paletteTypeNum == 8) {
    rolNFadMainPalAry2RndTargNLdDAC(MainPalArray,TargetPalArray);
  } else if (!FadeCompleteFlag) {
    rolNFadeMainPalAryToTargNLodDAC(MainPalArray,TargetPalArray);
  } else {
    rollMainPalArrayAndLoadDACRegs(MainPalArray);
  }
}


beginFadeOut

decompiled_code:
_BOOL8 __fastcall beginFadeOut(int a1)
{
_BOOL8 result; // rax
int v2; // eax

if ( a1 )
{
FadeCompleteFlag = 0;
result = 1LL;
fade_dir = 1;
}
else
{
v2 = rand();
FadeCompleteFlag = 0;
result = (unsigned int)(v2 + 0x3FFFFFFF) <= 0x7FFFFFFE;
fade_dir = result;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(int a1)
{
_BOOL8 result; // rax
int v2; // eax

if ( a1 )
{
FadeCompleteFlag = 0;
result = 1LL;
fade_dir = 1;
}
else
{
v2 = rand();
FadeCompleteFlag = 0;
result = (unsigned int)(v2 + 0x3FFFFFFF) <= 0x7FFFFFFE;
fade_dir = result;
}
return result;
}

original_code:
void beginFadeOut(int toblack)
{
  if (toblack || (rand() / (2147483647 / (2) + 1)) == 0) {
    fade_dir = 1;
  } else {
    fade_dir = 0;
  }
  FadeCompleteFlag = 0;
}

variable_types: toblack int


fadeOut

decompiled_code:
__int64 fadeOut()
{
if ( fade_dir )
rolNFadeBlkMainPalArrayNLoadDAC_constprop_0();
else
rolNFadeWhtMainPalArrayNLoadDAC_constprop_0();
return (unsigned int)FadeCompleteFlag;
}

canonical_decompiled_code:
__int64 func15()
{
if ( fade_dir )
func10();
else
func9();
return (unsigned int)FadeCompleteFlag;
}

original_code:
int fadeOut(void)
{
  if (fade_dir) {
    rolNFadeBlkMainPalArrayNLoadDAC(MainPalArray);
  } else {
    rolNFadeWhtMainPalArrayNLoadDAC(MainPalArray);
  }
  return FadeCompleteFlag;
}

canonical_original_code:
int fadeOut()
{
  if (fade_dir) {
    rolNFadeBlkMainPalArrayNLoadDAC(MainPalArray);
  } else {
    rolNFadeWhtMainPalArrayNLoadDAC(MainPalArray);
  }
  return FadeCompleteFlag;
}


applyPalette

decompiled_code:
__int64 applyPalette()
{
return disp_setPalette(MainPalArray);
}

canonical_decompiled_code:
__int64 func16()
{
return disp_setPalette(MainPalArray);
}

original_code:
void applyPalette(void)
{
  disp_setPalette(MainPalArray);
}

canonical_original_code:
void applyPalette()
{
  disp_setPalette(MainPalArray);
}


initRolNFade

decompiled_code:
__int64 __fastcall initRolNFade(int a1)
{
if ( a1 )
{
initPalArray(MainPalArray, 4LL);
qmemcpy(TargetPalArray, MainPalArray, 0x300uLL);
}
else
{
memset(MainPalArray, 0, 0x300uLL);
}
return applyPalette();
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
if ( a1 )
{
initPalArray(MainPalArray, 4LL);
qmemcpy(TargetPalArray, MainPalArray, 0x300uLL);
}
else
{
memset(MainPalArray, 0, 0x300uLL);
}
return func16();
}

original_code:
void initRolNFade(int logo)
{
  if (logo) {
    initPalArray(MainPalArray, 4);
    memcpy(TargetPalArray, MainPalArray, sizeof(TargetPalArray));
  } else {
    memset(MainPalArray, 0, sizeof(MainPalArray));
  }
  applyPalette();
}

variable_types: logo int


writeBitmapImageToArray

decompiled_code:
void __fastcall writeBitmapImageToArray(__int64 a1, int a2, int a3, int a4, int a5)
{
if ( !a2 )
bit_map_uncompress_constprop_0(a1, a3, a4, a5);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2, int a3, int a4, int a5)
{
if ( !a2 )
func0(a1, a3, a4, a5);
}

original_code:
void writeBitmapImageToArray (UCHAR *buf_graf, int image_number,
                              int xmax, int ymax, int stride)
{
 switch (image_number)
 {
  case 0:
   bit_map_uncompress (buf_graf, TITLE_DATA,
                                80, 98, xmax, ymax, stride);
  break;
  default:
  break;
 }
}

canonical_original_code:
void writeBitmapImageToArray(unsigned char *buf_graf, int image_number, int xmax, int ymax, int stride)
{
 switch (image_number)
 {
  case 0:
   bit_map_uncompress (buf_graf, TITLE_DATA,
                                80, 98, xmax, ymax, stride);
  break;
  default:
  break;
 }
}

variable_types: xmax int

variable_types: ymax int

variable_types: stride int


canonical_original_code:
void generate_image(int imageFuncNum, unsigned char *buf_graf, int xcenter, int ycenter, int width, int height, int colors, int pitch)
{
long x1; long x2; long x3; long x4; long y1; long y2; long y3; long y4;
  long x; long y; long dx; long dy;
  long dist; long angle;
  long color;
  x1 = (rand() / (2147483647 / (40) + 1))-20; x2 = (rand() / (2147483647 / (40) + 1))-20;
  x3 = (rand() / (2147483647 / (40) + 1))-20; x4 = (rand() / (2147483647 / (40) + 1))-20;
  y1 = (rand() / (2147483647 / (40) + 1))-20; y2 = (rand() / (2147483647 / (40) + 1))-20;
  y3 = (rand() / (2147483647 / (40) + 1))-20; y4 = (rand() / (2147483647 / (40) + 1))-20;
  for (y = 0;
       y < height
       && !abort_draw
       ; ++y)
    {
      for (x = 0; x < width; ++x)
        {
          dx = x - xcenter;
          dy = y - ycenter;
          dist = lut_dist (dx, dy);
          angle = lut_angle (dx, dy);
          switch (imageFuncNum)
            {
            case 0:
              color = angle + lut_sin (dist * 10) / 64 +
                (lut_sin((x * 256 / width * 2)+(256/4))) / 32 +
                (lut_sin((y * 256 / height * 2)+(256/4))) / 32;
              break;
            case 1:
              color = angle + lut_sin (dist * 10) / 16 +
                (lut_sin((x * 256 / width * 2)+(256/4))) / 8 +
                (lut_sin((y * 256 / height * 2)+(256/4))) / 8;
              break;
            case 2:
              color = lut_sin (lut_dist(dx + x1, dy + y1) * 4) / 32 +
                lut_sin (lut_dist(dx + x2, dy + y2) * 8) / 32 +
                lut_sin (lut_dist(dx + x3, dy + y3) * 16) / 32 +
                lut_sin (lut_dist(dx + x4, dy + y4) * 32) / 32;
              break;
            case 3:
              color = angle + lut_sin (lut_dist(dx + 20, dy) * 10) / 32 +
                angle + lut_sin (lut_dist(dx - 20, dy) * 10) / 32;
              break;
            case 4:
              color = lut_sin (dist) / 16;
              break;
            case 5:
              color = (lut_sin((x * 256 / width)+(256/4))) / 8 +
                (lut_sin((y * 256 / height)+(256/4))) / 8 +
                angle + lut_sin(dist) / 32;
              break;
            case 6:
              color = lut_sin (lut_dist(dx, dy - 20) * 4) / 32+
                lut_sin (lut_dist(dx + 20, dy + 20) * 4) / 32+
                lut_sin (lut_dist(dx - 20, dy + 20) * 4) / 32;
              break;
            case 7:
              color = angle +
                lut_sin (lut_dist(dx, dy - 20) * 8) / 32+
                lut_sin (lut_dist(dx + 20, dy + 20) * 8) / 32+
                lut_sin (lut_dist(dx - 20, dy + 20) * 8) / 32;
              break;
            case 8:
              color = lut_sin (lut_dist(dx, dy - 20) * 12) / 32+
                lut_sin (lut_dist(dx + 20, dy + 20) * 12) / 32+
                lut_sin (lut_dist(dx - 20, dy + 20) * 12) / 32;
              break;
            case 9:
              color = dist + lut_sin (5 * angle) / 64;
              break;
            case 10:
              color = (lut_sin((x * 256 / width * 2)+(256/4))) / 4 +
                (lut_sin((y * 256 / height * 2)+(256/4))) / 4;
              break;
            case 11:
              color = (lut_sin((x * 256 / width)+(256/4))) / 8 +
                (lut_sin((y * 256 / height)+(256/4))) / 8;
              break;
            case 12:
              color = dist;
              break;
            case 13:
              color = angle;
              break;
            case 14:
              color = angle + lut_sin(dist * 8)/32;
              break;
            case 15:
              color = lut_sin(dist * 4)/32;
              break;
            case 16:
              color = dist+ lut_sin(dist * 4) / 32;
              break;
            case 17:
              color = lut_sin((lut_sin((2 * x * 256 / width)+(256/4)))) / (20 + dist)
                + lut_sin((lut_sin((2 * y * 256 / height)+(256/4)))) / (20 + dist);
              break;
            case 18:
              color = (lut_sin((7 * x * 256 / width)+(256/4)))/(20 + dist) +
                (lut_sin((7 * y * 256 / height)+(256/4)))/(20 + dist);
              break;
            case 19:
              color = (lut_sin((17 * x * 256/width)+(256/4)))/(20 + dist) +
                (lut_sin((17 * y * 256/height)+(256/4)))/(20 + dist);
              break;
            case 20:
              color = (lut_sin((17 * x * 256 / width)+(256/4))) / 32 +
                (lut_sin((17 * y * 256 / height)+(256/4))) / 32 + dist + angle;
              break;
            case 21:
              color = (lut_sin((7 * x * 256 / width)+(256/4))) / 32 +
                (lut_sin((7 * y * 256 / height)+(256/4))) / 32 + dist;
              break;
            case 22:
              color = (lut_sin((7 * x * 256 / width)+(256/4))) / 32 +
                (lut_sin((7 * y * 256 / height)+(256/4))) / 32 +
                (lut_sin((11 * x * 256 / width)+(256/4))) / 32 +
                (lut_sin((11 * y * 256 / height)+(256/4))) / 32;
              break;
            case 23:
              color = lut_sin (angle * 7) / 32;
              break;
            case 24:
              color = lut_sin (lut_dist(dx + x1, dy + y1) * 2) / 12 +
                lut_sin (lut_dist(dx + x2, dy + y2) * 4) / 12 +
                lut_sin (lut_dist(dx + x3, dy + y3) * 6) / 12 +
                lut_sin (lut_dist(dx + x4, dy + y4) * 8) / 12;
              break;
            case 25:
              color = angle + lut_sin (lut_dist(dx + x1, dy + y1) * 2) / 16 +
                angle + lut_sin (lut_dist(dx + x2, dy + y2) * 4) / 16 +
                lut_sin (lut_dist(dx + x3, dy + y3) * 6) / 8 +
                lut_sin (lut_dist(dx + x4, dy + y4) * 8) / 8;
              break;
            case 26:
              color = angle + lut_sin (lut_dist(dx + x1, dy + y1) * 2) / 12 +
                angle + lut_sin (lut_dist(dx + x2, dy + y2) * 4) / 12 +
                angle + lut_sin (lut_dist(dx + x3, dy + y3) * 6) / 12 +
                angle + lut_sin (lut_dist(dx + x4, dy + y4) * 8) / 12;
              break;
            case 27:
              color = lut_sin (lut_dist(dx + x1, dy + y1) * 2) / 32 +
                lut_sin (lut_dist(dx + x2, dy + y2) * 4) / 32 +
                lut_sin (lut_dist(dx + x3, dy + y3) * 6) / 32 +
                lut_sin (lut_dist(dx + x4, dy + y4) * 8) / 32;
              break;
            case 28:
              if (y == 0 || x == 0)
                color = (rand() / (2147483647 / (16) + 1));
              else
                color = ( *(buf_graf + (pitch * y ) + (x-1))
                         + *(buf_graf + (pitch * (y-1)) + x)) / 2
                  + (rand() / (2147483647 / (16) + 1)) - 8;
              break;
            case 29:
              if (y == 0 || x == 0)
                color = (rand() / (2147483647 / (1024) + 1));
              else
                color = dist/6 + (*(buf_graf + (pitch * y ) + (x-1))
                               + *(buf_graf + (pitch * (y-1)) + x)) / 2
                + (rand() / (2147483647 / (16) + 1)) - 8;
              break;
            case 30:
              color = ((((lut_sin (lut_dist(dx, dy - 20) * 4) / 32) ^ (lut_sin (lut_dist(dx + 20,dy + 20) * 4) / 32))) ^ (lut_sin (lut_dist(dx - 20,dy + 20) * 4) / 32));
              break;
            case 31:
              color = ((((angle) % ((256/4)))) ^ (dist));
              break;
            case 32:
              color = ((dy) ^ (dx));
              break;
            case 33:
              if (y == 0 || x == 0)
                color = (rand() / (2147483647 / (16) + 1));
              else
                color = ( *(buf_graf + (pitch * y ) + (x-1))
                         + *(buf_graf + (pitch * (y-1)) + x ) ) / 2;
              color += (rand() / (2147483647 / (2) + 1)) - 1;
              if (color < 64)
                color += (rand() / (2147483647 / (16) + 1)) - 8;
              break;
            case 34:
              if (y == 0 || x == 0)
                color = (rand() / (2147483647 / (16) + 1));
              else
                color = ( *(buf_graf + (pitch * y ) + (x-1))
                         + *(buf_graf + (pitch * (y-1)) + x ) ) / 2;
              if (color < 100)
                color += (rand() / (2147483647 / (16) + 1)) - 8;
              break;
            case 35:
              color = angle + lut_sin(dist * 8)/32;
              dx = x - xcenter;
              dy = (y - ycenter)*2;
              dist = lut_dist (dx, dy);
          angle = lut_angle (dx, dy);
          color = (color + angle + lut_sin(dist * 8)/32) / 2;
          break;
            case 36:
              color = angle + lut_sin (dist * 10) / 16 +
                (lut_sin((x * 256 / width * 2)+(256/4))) / 8 +
                (lut_sin((y * 256 / height * 2)+(256/4))) / 8;
              dx = x - xcenter;
              dy = (y - ycenter)*2;
              dist = lut_dist (dx, dy);
              angle = lut_angle (dx, dy);
              color = (color + angle + lut_sin(dist * 8)/32) / 2;
              break;
            case 37:
              color = angle + lut_sin (dist * 10) / 16 +
                (lut_sin((x * 256 / width * 2)+(256/4))) / 8 +
                (lut_sin((y * 256 / height * 2)+(256/4))) / 8;
              dx = x - xcenter;
              dy = (y - ycenter)*2;
              dist = lut_dist (dx, dy);
          angle = lut_angle (dx, dy);
          color = (color + angle + lut_sin (dist * 10) / 16 +
                   (lut_sin((x * 256 / width * 2)+(256/4))) / 8 +
                   (lut_sin((y * 256 / height * 2)+(256/4))) / 8) / 2;
          break;
            case 38:
              if (dy%2)
                {
                  dy *= 2;
                  dist = lut_dist (dx, dy);
                  angle = lut_angle (dx, dy);
                }
              color = angle + lut_sin(dist * 8)/32;
              break;
            case 39:
              color = ((((angle) % ((256/4)))) ^ (dist));
              dx = x - xcenter;
              dy = (y - ycenter)*2;
              dist = lut_dist (dx, dy);
              angle = lut_angle (dx, dy);
              color = (color + (((((angle) % ((256/4)))) ^ (dist)))) / 2;
              break;
            case 40:
              color = ((dy) ^ (dx));
              dx = x - xcenter;
              dy = (y - ycenter)*2;
              color = (color + ((dy) ^ (dx))) / 2;
              break;
            default:
              color = (rand() / (2147483647 / (colors - 1) + 1)) + 1;
              break;
            }
          color = (long)color % (colors-1);
          if (color < 0)
            color += (colors - 1);
          ++color;
          *(buf_graf + (pitch * y) + x) = (unsigned char)color;
        }
    }
}

variable_types: imageFuncNum int

variable_types: xcenter int

variable_types: ycenter int

variable_types: width int

variable_types: height int

variable_types: colors int

variable_types: pitch int

variable_types: x long

variable_types: y long

variable_types: dx long

variable_types: dy long

variable_types: dist long

variable_types: angle long

variable_types: color long


repo: embeddedarm/libtsctl

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

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

original_code:
int ts4200PinPreempt(ts4200Pin *ob) {
  return -1;
}

canonical_original_code:
int ts4200PinPreempt(struct ts4200Pin *ob) {
  return -1;
}

variable_types: struct ts4200Pin { void *(*Init)(struct ts4200Pin *me, void *bus, void *busb, void *buspmc, void *busc, void *busa); void (*Fini)(struct ts4200Pin *me); int (*Lock)(struct ts4200Pin *me, unsigned int num, int flags); int (*Unlock)(struct ts4200Pin *me, unsigned int num, int flags); int (*Preempt)(struct ts4200Pin *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 ts4200Pin *me, int PinNumber); enum PinResult { PinSuccess=1, PinErrorModeInvalid=-13 } (*ModeSet)(struct ts4200Pin *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; } *syscon; struct Bus *piob; struct Bus *pmc; struct Bus *pioc; struct Bus *pioa; } *

user_defined_types: struct ts4200Pin { void *(*Init)(struct ts4200Pin *me, void *bus, void *busb, void *buspmc, void *busc, void *busa); void (*Fini)(struct ts4200Pin *me); int (*Lock)(struct ts4200Pin *me, unsigned int num, int flags); int (*Unlock)(struct ts4200Pin *me, unsigned int num, int flags); int (*Preempt)(struct ts4200Pin *me); enum PinMode (*ModeGet)(struct ts4200Pin *me, int PinNumber); enum PinResult (*ModeSet)(struct ts4200Pin *me, int PinNumber, enum PinMode Mode); int InitStatus; unsigned int LockBase; int deferlock; struct Bus *syscon; struct Bus *piob; struct Bus *pmc; struct Bus *pioc; struct Bus *pioa; }


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

result = *(unsigned int *)(a1 + 56);
if ( (int)result > 0 )
*(_DWORD *)(a1 + 56) = 0;
return result;
}

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

result = *(unsigned int *)(a1 + 56);
if ( (int)result > 0 )
*(_DWORD *)(a1 + 56) = 0;
return result;
}

original_code:
void ts4200PinFini(ts4200Pin *pin) {
  if (pin->InitStatus > 0) pin->InitStatus = 0;
}

canonical_original_code:
void ts4200PinFini(struct ts4200Pin *pin) {
  if (pin->InitStatus > 0) pin->InitStatus = 0;
}

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


decompiled_code:
__int64 __fastcall ts4200PinModeGet(_QWORD *a1, int a2)
{
unsigned int v2; // er12
__int64 result; // rax
int v4; // er8

v2 = a2 - 32;
if ( (unsigned int)(a2 - 32) <= 3 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, __int64))(a1[11] + 152LL))(a1[11], 24LL, 13LL)
&& (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[10] + 152LL))(a1[10], 8LL, v2) != 1 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[10] + 152LL))(a1[10], 120LL, v2) != 1 )
return 2LL;
return 0xFFFFFFFFLL;
}
return 0LL;
}
if ( (unsigned int)(a2 - 67) <= 2 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[12] + 152LL))(
a1[12],
8LL,
(unsigned int)(a2 - 64)) != 1 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[12] + 152LL))(
a1[12],
120LL,
(unsigned int)(a2 - 64)) != (a2 == 69) )
return 2LL;
return 0xFFFFFFFFLL;
}
return 0LL;
}
if ( (unsigned int)(a2 - 112) > 0xC )
return 0LL;
v4 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD))(a1[9] + 120LL))(a1[9], 32LL, 0LL);
result = 7LL;
if ( !v4 )
return 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2)
{
unsigned int v2; // er12
__int64 result; // rax
int v4; // er8

v2 = a2 - 32;
if ( (unsigned int)(a2 - 32) <= 3 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, __int64))(a1[11] + 152LL))(a1[11], 24LL, 13LL)
&& (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[10] + 152LL))(a1[10], 8LL, v2) != 1 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[10] + 152LL))(a1[10], 120LL, v2) != 1 )
return 2LL;
return 0xFFFFFFFFLL;
}
return 0LL;
}
if ( (unsigned int)(a2 - 67) <= 2 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[12] + 152LL))(
a1[12],
8LL,
(unsigned int)(a2 - 64)) != 1 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1[12] + 152LL))(
a1[12],
120LL,
(unsigned int)(a2 - 64)) != (a2 == 69) )
return 2LL;
return 0xFFFFFFFFLL;
}
return 0LL;
}
if ( (unsigned int)(a2 - 112) > 0xC )
return 0LL;
v4 = (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD))(a1[9] + 120LL))(a1[9], 32LL, 0LL);
result = 7LL;
if ( !v4 )
return 0LL;
return result;
}

original_code:
PinMode ts4200PinModeGet(ts4200Pin *pin,int npin) {
  int ret;
  if (npin >= 32 && npin <= 35) {
    if (pin->pmc->BitGet32(pin->pmc,0x18,13) == 0) return MODE_DIO;
    if (pin->piob->BitGet32(pin->piob,8,npin-32) == 1) return MODE_DIO;
    if (pin->piob->BitGet32(pin->piob,0x78,npin-32) == 1) return MODE_UNKNOWN;
    return MODE_SPI;
  } else if (npin >= 67 && npin <= 69) {
    if (pin->pioc->BitGet32(pin->pioc,8,npin-64) == 1) return MODE_DIO;
    if (pin->pioc->BitGet32(pin->pioc,0x78,npin-64)
 == ((npin == 67 || npin == 68) ? 0:1)) return MODE_UNKNOWN;
    return MODE_SPI;
  } else if (npin >= 96+16 && npin <= 96+28) {
    return pin->syscon->BitGet16(pin->syscon,0x20,0) ? MODE_BUS:MODE_DIO;
  }
  return MODE_DIO;
}

canonical_original_code:
enum PinMode ts4200PinModeGet(struct ts4200Pin *pin, int npin) {
  int ret;
  if (npin >= 32 && npin <= 35) {
    if (pin->pmc->BitGet32(pin->pmc,0x18,13) == 0) return MODE_DIO;
    if (pin->piob->BitGet32(pin->piob,8,npin-32) == 1) return MODE_DIO;
    if (pin->piob->BitGet32(pin->piob,0x78,npin-32) == 1) return MODE_UNKNOWN;
    return MODE_SPI;
  } else if (npin >= 67 && npin <= 69) {
    if (pin->pioc->BitGet32(pin->pioc,8,npin-64) == 1) return MODE_DIO;
    if (pin->pioc->BitGet32(pin->pioc,0x78,npin-64)
 == ((npin == 67 || npin == 68) ? 0:1)) return MODE_UNKNOWN;
    return MODE_SPI;
  } else if (npin >= 96+16 && npin <= 96+28) {
    return pin->syscon->BitGet16(pin->syscon,0x20,0) ? MODE_BUS:MODE_DIO;
  }
  return MODE_DIO;
}

variable_types: npin int

variable_types: ret 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 ts4200PinModeSet(ts4200Pin *pin,int npin,PinMode mode) {
  if (npin == 30 || npin == 31) {
    if (mode == MODE_DIO) {
      pin->pioa->Poke32(pin->pioa,0,1<<(npin-0));
      return PinSuccess;
    } else if (mode == MODE_UART) {
      pin->pioa->Poke32(pin->pioa,4,1<<(npin-0));
      return PinSuccess;
    } else {
      return PinErrorModeInvalid;
    }
  } else if (npin >= 36 && npin <= 45) {
    if (mode == MODE_DIO) {
      pin->piob->Poke32(pin->piob,0,1<<(npin-32));
      return PinSuccess;
    } else if (mode == MODE_UART) {
      pin->piob->Poke32(pin->piob,4,1<<(npin-32));
      return PinSuccess;
    } else {
      return PinErrorModeInvalid;
    }
  } else if (npin >= 32 && npin <= 35) {
    if (mode == MODE_SPI) {
      pin->pmc->Poke32(pin->pmc,0x10,1<<13);
      pin->piob->Poke32(pin->piob,4,1<<(npin-32));
      pin->piob->Poke32(pin->piob,0x70,1<<(npin-32));
      return PinSuccess;
    } else if (mode == MODE_DIO) {
      pin->piob->Poke32(pin->piob,0,1<<(npin-32));
      return PinSuccess;
    } else return PinErrorModeInvalid;
  } else if (npin >= 67 && npin <= 69) {
    if (mode == MODE_SPI) {
      pin->pioc->Poke32(pin->pioc,4,1<<(npin-64));
      if (npin == 67 || npin == 68 || npin == 69) {
 pin->pioc->Poke32(pin->pioc,0x74,1<<(npin-64));
      } else {
 pin->pioc->Poke32(pin->pioc,0x70,1<<(npin-64));
      }
      return PinSuccess;
    } else if (mode == MODE_DIO) {
      pin->pioc->Poke32(pin->pioc,0,1<<(npin-64));
      return PinSuccess;
    } else return PinErrorModeInvalid;
  } else if (npin >= 96+16 && npin <= 96+28) {
    if (mode == MODE_BUS) {
      pin->syscon->BitSet16(pin->syscon,0x20,0);
    } else if (mode == MODE_DIO) {
      pin->syscon->BitClear16(pin->syscon,0x20,0);
    } else return PinErrorModeInvalid;
  }
  if (mode != MODE_DIO) return PinErrorModeInvalid;
}

canonical_original_code:
enum PinResult ts4200PinModeSet(struct ts4200Pin *pin, int npin, enum PinMode mode) {
  if (npin == 30 || npin == 31) {
    if (mode == MODE_DIO) {
      pin->pioa->Poke32(pin->pioa,0,1<<(npin-0));
      return PinSuccess;
    } else if (mode == MODE_UART) {
      pin->pioa->Poke32(pin->pioa,4,1<<(npin-0));
      return PinSuccess;
    } else {
      return PinErrorModeInvalid;
    }
  } else if (npin >= 36 && npin <= 45) {
    if (mode == MODE_DIO) {
      pin->piob->Poke32(pin->piob,0,1<<(npin-32));
      return PinSuccess;
    } else if (mode == MODE_UART) {
      pin->piob->Poke32(pin->piob,4,1<<(npin-32));
      return PinSuccess;
    } else {
      return PinErrorModeInvalid;
    }
  } else if (npin >= 32 && npin <= 35) {
    if (mode == MODE_SPI) {
      pin->pmc->Poke32(pin->pmc,0x10,1<<13);
      pin->piob->Poke32(pin->piob,4,1<<(npin-32));
      pin->piob->Poke32(pin->piob,0x70,1<<(npin-32));
      return PinSuccess;
    } else if (mode == MODE_DIO) {
      pin->piob->Poke32(pin->piob,0,1<<(npin-32));
      return PinSuccess;
    } else return PinErrorModeInvalid;
  } else if (npin >= 67 && npin <= 69) {
    if (mode == MODE_SPI) {
      pin->pioc->Poke32(pin->pioc,4,1<<(npin-64));
      if (npin == 67 || npin == 68 || npin == 69) {
 pin->pioc->Poke32(pin->pioc,0x74,1<<(npin-64));
      } else {
 pin->pioc->Poke32(pin->pioc,0x70,1<<(npin-64));
      }
      return PinSuccess;
    } else if (mode == MODE_DIO) {
      pin->pioc->Poke32(pin->pioc,0,1<<(npin-64));
      return PinSuccess;
    } else return PinErrorModeInvalid;
  } else if (npin >= 96+16 && npin <= 96+28) {
    if (mode == MODE_BUS) {
      pin->syscon->BitSet16(pin->syscon,0x20,0);
    } else if (mode == MODE_DIO) {
      pin->syscon->BitClear16(pin->syscon,0x20,0);
    } else return PinErrorModeInvalid;
  }
  if (mode != MODE_DIO) return PinErrorModeInvalid;
}

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 ts4200PinLock(__int64 a1, int a2, char a3)
{
unsigned int v3; // er8
unsigned int v4; // er8
__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; // er8
unsigned int v4; // er8
__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 ts4200PinLock(ts4200Pin *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 ts4200PinLock(struct ts4200Pin *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:
num
unsigned int

variable_types: flags int


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

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

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

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

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

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


original_code:
void *ts4200PinInit(ts4200Pin *pin,void *syscon,void *busb,void *buspmc,void *busc,void *busa) {
  if (pin->InitStatus > 0) return pin;
  ;
  unsigned numlocks = DIOCount();
  ;
  pin->LockBase = ThreadLockAllocate(numlocks);
  pin->syscon = syscon;
  pin->pioa = busa;
  pin->piob = busb;
  pin->pioc = busc;
  pin->pmc = buspmc;
  if (pin->syscon->InitStatus < 0
      || pin->piob->InitStatus < 0
      || pin->pmc->InitStatus < 0) {
    pin->Fini(pin);
    pin->InitStatus = -1;
    return pin;
  }
  pin->Init = (void *)ts4200PinInit;
  pin->Fini = (void *)ts4200PinFini;
  pin->Lock = (void *)ts4200PinLock;
  pin->Unlock = (void *)ts4200PinUnlock;
  pin->Preempt = (void *)ts4200PinPreempt;
  pin->ModeGet = (void *)ts4200PinModeGet;
  pin->ModeSet = (void *)ts4200PinModeSet;
  pin->InitStatus = 1;
  return pin;
}

canonical_original_code:
void *ts4200PinInit(struct ts4200Pin *pin, void *syscon, void *busb, void *buspmc, void *busc, void *busa) {
  if (pin->InitStatus > 0) return pin;
  ;
  unsigned int numlocks = DIOCount();
  ;
  pin->LockBase = ThreadLockAllocate(numlocks);
  pin->syscon = syscon;
  pin->pioa = busa;
  pin->piob = busb;
  pin->pioc = busc;
  pin->pmc = buspmc;
  if (pin->syscon->InitStatus < 0
      || pin->piob->InitStatus < 0
      || pin->pmc->InitStatus < 0) {
    pin->Fini(pin);
    pin->InitStatus = -1;
    return pin;
  }
  pin->Init = (void *)ts4200PinInit;
  pin->Fini = (void *)ts4200PinFini;
  pin->Lock = (void *)ts4200PinLock;
  pin->Unlock = (void *)ts4200PinUnlock;
  pin->Preempt = (void *)ts4200PinPreempt;
  pin->ModeGet = (void *)ts4200PinModeGet;
  pin->ModeSet = (void *)ts4200PinModeSet;
  pin->InitStatus = 1;
  return pin;
}

variable_types:
syscon
void *

variable_types:
busb
void *

variable_types:
buspmc
void *

variable_types:
busc
void *

variable_types:
busa
void *

variable_types:
numlocks
unsigned int

return_type: void *


original_code:
static unsigned read_bit(DIOTWI *twi)
{
  unsigned bit;
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  while (twi->dio->GetAsync(twi->dio,twi->TW_CLK) == LOW);
  bit = DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT));
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,LOW);
  return bit;
}

canonical_original_code:
static unsigned int read_bit(struct DIOTWI *twi)
{
  unsigned int bit;
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  while (twi->dio->GetAsync(twi->dio,twi->TW_CLK) == LOW);
  bit = DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT));
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,LOW);
  return bit;
}

variable_types: struct DIOTWI { void *(*Init)(struct DIOTWI *me, void *dio, void *time); void (*Fini)(struct DIOTWI *me); int (*Lock)(struct DIOTWI *me, unsigned int num, int flags); int (*Unlock)(struct DIOTWI *me, unsigned int num, int flags); int (*Preempt)(struct DIOTWI *me); enum TWIResult { TWISuccess=1, TWIErrorPortInvalid=-1, TWIErrorModeUnsupported=-2, TWIErrorBaudUnconstrained=-3, TWIErrorHardware=-4, TWIErrorHandle=-5, TWIErrorWriteNAck=-6, TWIErrorDataNAck=-7, TWIErrorReadNack=-8, TWIErrorSDALow=-9, TWIErrorSCLLow=-10, TWIErrorAdrsLen=-11, TWIErrorTimeout=-12, TWIErrorOverrun=-13, TWIErrorArbLost=-14, TWIErrorUnknown=-999, TWIErrorOpInvalid=-15 } (*Write)(struct DIOTWI *me, int devadr, int adrslen, int adrs, char *bytes); enum TWIResult { TWISuccess=1, TWIErrorPortInvalid=-1, TWIErrorModeUnsupported=-2, TWIErrorBaudUnconstrained=-3, TWIErrorHardware=-4, TWIErrorHandle=-5, TWIErrorWriteNAck=-6, TWIErrorDataNAck=-7, TWIErrorReadNack=-8, TWIErrorSDALow=-9, TWIErrorSCLLow=-10, TWIErrorAdrsLen=-11, TWIErrorTimeout=-12, TWIErrorOverrun=-13, TWIErrorArbLost=-14, TWIErrorUnknown=-999, TWIErrorOpInvalid=-15 } (*Read)(struct DIOTWI *me, int devadr, int adrslen, int adrs, char *bytes); int InitStatus; struct DIO { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); void (*Set)(void *me, int DIONum, enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } State); enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } (*Get)(void *me, int DIONum); void (*SetAsync)(void *me, int DIONum, enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } State); enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } (*GetAsync)(void *me, int DIONum); void (*Wait)(void *me, int *match, int min, int max, int *nh, int *nl); unsigned int (*Count)(void *me); enum DIOCaps { DIO_NOT_PRESENT=0, DIO_CAN_INPUT=1, DIO_CAN_DRIVE_HIGH=2, DIO_HIGH_SIDE=3, DIO_CAN_DRIVE_LOW=4, DIO_LOW_SIDE=5, DIO_OUTPUT_ONLY=6, DIO_NORMAL=7 } (*Capabilities)(void *me, unsigned int num); int (*GetMulti)(void *me, char *state, int offset); int InitStatus; } *dio; struct Time { void *(*Init)(void *me, ...); void (*Fini)(void *me); unsigned int (*Wait)(void *me, unsigned int microseconds); void (*Delay)(void *me, unsigned int microseconds); unsigned int (*Tick)(void *me); unsigned int (*usElapsed)(void *me, unsigned int start); unsigned int (*usFuture)(void *me, unsigned int start, unsigned int microseconds); enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 } (*TimeoutQ)(void *me, unsigned int start, unsigned int end); unsigned int (*TPS)(void *me); int InitStatus; } *t; int TW_CLK; int TW_DAT; int Speed; int delay; int LockNum; unsigned int start; } *

variable_types:
bit
unsigned int

user_defined_types: struct DIOTWI { void *(*Init)(struct DIOTWI *me, void *dio, void *time); void (*Fini)(struct DIOTWI *me); int (*Lock)(struct DIOTWI *me, unsigned int num, int flags); int (*Unlock)(struct DIOTWI *me, unsigned int num, int flags); int (*Preempt)(struct DIOTWI *me); enum TWIResult (*Write)(struct DIOTWI *me, int devadr, int adrslen, int adrs, char *bytes); enum TWIResult (*Read)(struct DIOTWI *me, int devadr, int adrslen, int adrs, char *bytes); int InitStatus; struct DIO *dio; struct Time *t; int TW_CLK; int TW_DAT; int Speed; int delay; int LockNum; unsigned int start; }

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

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


original_code:
static int write_bit(DIOTWI *twi,unsigned bit)
{
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,bit ? INPUT : LOW);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  while (twi->dio->GetAsync(twi->dio,twi->TW_CLK) == LOW);
  if (bit && DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT)) == LOW) {
      return TWIErrorArbLost;
  }
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,LOW);
  return 0;
}

canonical_original_code:
static int write_bit(struct DIOTWI *twi, unsigned int bit)
{
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,bit ? INPUT : LOW);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  while (twi->dio->GetAsync(twi->dio,twi->TW_CLK) == LOW);
  if (bit && DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT)) == LOW) {
      return TWIErrorArbLost;
  }
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,LOW);
  return 0;
}

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

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 }

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


START

original_code:
static int START(DIOTWI *twi)
{
  if (twi->start) {
    twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
    twi->t->Delay(twi->t,twi->delay);
    twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
    while (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_CLK)) == LOW);
  }
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  if (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT)) == LOW) {
    return TWIErrorArbLost;
  }
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,LOW);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,LOW);
  twi->start = 1;
  return TWISuccess;
}

canonical_original_code:
static int START(struct DIOTWI *twi)
{
  if (twi->start) {
    twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
    twi->t->Delay(twi->t,twi->delay);
    twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
    while (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_CLK)) == LOW);
  }
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  if (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT)) == LOW) {
    return TWIErrorArbLost;
  }
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,LOW);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,LOW);
  twi->start = 1;
  return TWISuccess;
}


STOP

original_code:
static int STOP(DIOTWI *twi)
{
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,LOW);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  while (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_CLK)) == LOW);
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  if (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT)) == LOW) {
    return TWIErrorArbLost;
  }
  twi->t->Delay(twi->t,twi->delay);
  twi->start = 0;
  return TWISuccess;
}

canonical_original_code:
static int STOP(struct DIOTWI *twi)
{
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,LOW);
  twi->t->Delay(twi->t,twi->delay);
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  while (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_CLK)) == LOW);
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  if (DIOValue(twi->dio->GetAsync(twi->dio,twi->TW_DAT)) == LOW) {
    return TWIErrorArbLost;
  }
  twi->t->Delay(twi->t,twi->delay);
  twi->start = 0;
  return TWISuccess;
}


tx

decompiled_code:
__int64 __fastcall tx(__int64 a1, unsigned __int8 a2)
{
int v2; // ebp
__int64 result; // rax

v2 = 8;
while ( 1 )
{
result = write_bit(a1, a2 & 0x80);
if ( (int)result < 0 )
break;
a2 *= 2;
if ( !--v2 )
return read_bit(a1) ? 0xFFFFFFFA : 0;
}
return result;
}

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

v2 = 8;
while ( 1 )
{
result = func1(a1, a2 & 0x80);
if ( (int)result < 0 )
break;
a2 *= 2;
if ( !--v2 )
return func0(a1) ? 0xFFFFFFFA : 0;
}
return result;
}

original_code:
static int tx(DIOTWI *twi,unsigned char byte)
{
  unsigned bit;
  unsigned nack;
  int ret;
  for (bit = 0; bit < 8; bit++) {
    ret = write_bit(twi,byte & 0x80);
    if (ret < 0) return ret;
    byte <<= 1;
  }
  nack = read_bit(twi);
  return nack ? TWIErrorWriteNAck : 0;
}

canonical_original_code:
static int tx(struct DIOTWI *twi, unsigned char byte)
{
  unsigned int bit;
  unsigned int nack;
  int ret;
  for (bit = 0; bit < 8; bit++) {
    ret = write_bit(twi,byte & 0x80);
    if (ret < 0) return ret;
    byte <<= 1;
  }
  nack = read_bit(twi);
  return nack ? TWIErrorWriteNAck : 0;
}

variable_types:
byte
unsigned char

variable_types:
nack
unsigned int


rx

decompiled_code:
__int64 __fastcall rx(__int64 a1, int a2)
{
int v2; // ebp
_BOOL4 v3; // ebx
__int64 result; // rax

v2 = 8;
v3 = 0;
do
{
v3 = read_bit(a1) | (2 * v3);
--v2;
}
while ( v2 );
result = write_bit(a1, a2);
if ( (int)result >= 0 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // ebp
_BOOL4 v3; // ebx
__int64 result; // rax

v2 = 8;
v3 = 0;
do
{
v3 = func0(a1) | (2 * v3);
--v2;
}
while ( v2 );
result = func1(a1, a2);
if ( (int)result >= 0 )
result = v3;
return result;
}

original_code:
static int rx (DIOTWI *twi,int nak)
{
  unsigned char byte = 0;
  unsigned bit;
  int ret;
  for (bit = 0; bit < 8; bit++) {
    byte <<= 1;
    byte |= read_bit(twi);
  }
  ret = write_bit(twi,nak);
  if (ret < 0) return ret;
  return byte;
}

canonical_original_code:
static int rx(struct DIOTWI *twi, int nak)
{
  unsigned char byte = 0;
  unsigned int bit;
  int ret;
  for (bit = 0; bit < 8; bit++) {
    byte <<= 1;
    byte |= read_bit(twi);
  }
  ret = write_bit(twi,nak);
  if (ret < 0) return ret;
  return byte;
}

variable_types: nak int


DIOTWIFini

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

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

original_code:
void DIOTWIFini(DIOTWI *twi){
  twi->dio->Fini(twi->dio);
  twi->t->Fini(twi->t);
  if (twi->InitStatus > 0) twi->InitStatus = 0;
}

canonical_original_code:
void DIOTWIFini(struct DIOTWI *twi){
  twi->dio->Fini(twi->dio);
  twi->t->Fini(twi->t);
  if (twi->InitStatus > 0) twi->InitStatus = 0;
}


DIOTWIPreempt

decompiled_code:
void DIOTWIPreempt()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
int DIOTWIPreempt(DIOTWI *twi) {
}

canonical_original_code:
int DIOTWIPreempt(struct DIOTWI *twi) {
}


DIOTWIInit

original_code:
void *DIOTWIInit(DIOTWI *twi,void *dio1,void *t1) {
  DIO *dio = dio1;
  Time *t = t1;
  if (twi->InitStatus > 0) return twi;
  twi->Init = (void *)DIOTWIInit;
  twi->Fini = (void *)DIOTWIFini;
  twi->Lock = (void *)DIOTWILock;
  twi->Unlock = (void *)DIOTWIUnlock;
  twi->Preempt = (void *)DIOTWIPreempt;
  twi->Write = (void *)DIOTWIWrite;
  twi->Read = (void *)DIOTWIRead;
  twi->LockNum = ThreadMutexAllocate(1);
  twi->dio = dio;
  twi->t= t;
  if (twi->Speed == 0) twi->Speed = 100000;
  twi->delay = 1000000/twi->Speed + (1000000%twi->Speed ? 1 : 0);
  if (twi->dio->InitStatus <= 0
      ||twi->t->InitStatus <= 0) {
    twi->Fini(twi);
    twi->InitStatus = -1;
    return twi;
  }
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  usleep(10000);
  twi->InitStatus = 1;
  return twi;
}

canonical_original_code:
void *DIOTWIInit(struct DIOTWI *twi, void *dio1, void *t1) {
  struct DIO *dio = dio1;
  struct Time *t = t1;
  if (twi->InitStatus > 0) return twi;
  twi->Init = (void *)DIOTWIInit;
  twi->Fini = (void *)DIOTWIFini;
  twi->Lock = (void *)DIOTWILock;
  twi->Unlock = (void *)DIOTWIUnlock;
  twi->Preempt = (void *)DIOTWIPreempt;
  twi->Write = (void *)DIOTWIWrite;
  twi->Read = (void *)DIOTWIRead;
  twi->LockNum = ThreadMutexAllocate(1);
  twi->dio = dio;
  twi->t= t;
  if (twi->Speed == 0) twi->Speed = 100000;
  twi->delay = 1000000/twi->Speed + (1000000%twi->Speed ? 1 : 0);
  if (twi->dio->InitStatus <= 0
      ||twi->t->InitStatus <= 0) {
    twi->Fini(twi);
    twi->InitStatus = -1;
    return twi;
  }
  twi->dio->SetAsync(twi->dio,twi->TW_CLK,INPUT);
  twi->dio->SetAsync(twi->dio,twi->TW_DAT,INPUT);
  usleep(10000);
  twi->InitStatus = 1;
  return twi;
}

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

variable_types: struct Time { void *(*Init)(void *me, ...); void (*Fini)(void *me); unsigned int (*Wait)(void *me, unsigned int microseconds); void (*Delay)(void *me, unsigned int microseconds); unsigned int (*Tick)(void *me); unsigned int (*usElapsed)(void *me, unsigned int start); unsigned int (*usFuture)(void *me, unsigned int start, unsigned int microseconds); enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 } (*TimeoutQ)(void *me, unsigned int start, unsigned int end); unsigned int (*TPS)(void *me); int InitStatus; } *


DIOTWILock

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

if ( (a3 & 2) != 0 )
return (unsigned int)-11;
v3 = ThreadMutexLock(*(unsigned int *)(a1 + 96));
if ( v3 < 0 )
return (unsigned int)v3;
v4 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 16LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 80),
0LL);
if ( v4 >= 0 )
{
v4 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 16LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 84),
0LL);
if ( v4 >= 0 )
return 1;
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 24LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 80),
0LL);
}
ThreadMutexUnlock(*(unsigned int *)(a1 + 96));
return (unsigned int)v4;
}

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

if ( (a3 & 2) != 0 )
return (unsigned int)-11;
v3 = ThreadMutexLock(*(unsigned int *)(a1 + 96));
if ( v3 < 0 )
return (unsigned int)v3;
v4 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 16LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 80),
0LL);
if ( v4 >= 0 )
{
v4 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 16LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 84),
0LL);
if ( v4 >= 0 )
return 1;
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 24LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 80),
0LL);
}
ThreadMutexUnlock(*(unsigned int *)(a1 + 96));
return (unsigned int)v4;
}

original_code:
int DIOTWILock(DIOTWI *twi,unsigned num,int flags) {
  int ret,mode;
  if (flags & SHARED) return -11;
  mode = (flags & NONBLOCKING) ?
    LOCK_TRY :
    (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD;
  if ((ret=ThreadMutexLock(twi->LockNum,mode)) < 0) return ret;
  if ((ret=twi->dio->Lock(twi->dio,twi->TW_CLK,0)) < 0) {
    goto DoRelease2;
  }
  if ((ret=twi->dio->Lock(twi->dio,twi->TW_DAT,0)) < 0) {
    goto DoRelease1;
  }
  return 1;
 DoRelease:
   twi->dio->Unlock(twi->dio,twi->TW_DAT,0);
 DoRelease1:
   twi->dio->Unlock(twi->dio,twi->TW_CLK,0);
 DoRelease2:
   ThreadMutexUnlock(twi->LockNum);
   return ret;
}

canonical_original_code:
int DIOTWILock(struct DIOTWI *twi, unsigned int num, int flags) {
  int ret; int mode;
  if (flags & SHARED) return -11;
  mode = (flags & NONBLOCKING) ?
    LOCK_TRY :
    (flags & NOUNLOCK) ? LOCK_FOD : LOCK_SOD;
  if ((ret=ThreadMutexLock(twi->LockNum,mode)) < 0) return ret;
  if ((ret=twi->dio->Lock(twi->dio,twi->TW_CLK,0)) < 0) {
    goto DoRelease2;
  }
  if ((ret=twi->dio->Lock(twi->dio,twi->TW_DAT,0)) < 0) {
    goto DoRelease1;
  }
  return 1;
 DoRelease:
   twi->dio->Unlock(twi->dio,twi->TW_DAT,0);
 DoRelease1:
   twi->dio->Unlock(twi->dio,twi->TW_CLK,0);
 DoRelease2:
   ThreadMutexUnlock(twi->LockNum);
   return ret;
}

variable_types: ret int

variable_types: mode int


DIOTWIUnlock

decompiled_code:
__int64 __fastcall DIOTWIUnlock(__int64 a1)
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 24LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 80),
0LL);
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 24LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 84),
0LL);
return ThreadMutexUnlock(*(unsigned int *)(a1 + 96));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 24LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 80),
0LL);
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 64) + 24LL))(
*(_QWORD *)(a1 + 64),
*(unsigned int *)(a1 + 84),
0LL);
return ThreadMutexUnlock(*(unsigned int *)(a1 + 96));
}

original_code:
int DIOTWIUnlock(DIOTWI *twi,unsigned num,int flags) {
  twi->dio->Unlock(twi->dio,twi->TW_CLK,0);
  twi->dio->Unlock(twi->dio,twi->TW_DAT,0);
  return ThreadMutexUnlock(twi->LockNum);
}

canonical_original_code:
int DIOTWIUnlock(struct DIOTWI *twi, unsigned int num, int flags) {
  twi->dio->Unlock(twi->dio,twi->TW_CLK,0);
  twi->dio->Unlock(twi->dio,twi->TW_DAT,0);
  return ThreadMutexUnlock(twi->LockNum);
}

variable_types:
num
unsigned int


ArrayFree

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

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

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

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

variable_types:
arr
void *

variable_types:
ptr
unsigned int *


ASCIIZ

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

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

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

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

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

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

variable_types:
str
char *

variable_types:
len
unsigned int

return_type: char *


ArraySizeAuto

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

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

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

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

variable_types:
count
unsigned int


ArrayElementSize

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

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

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

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

variable_types:
array
void *


ArrayLength

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

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

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

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


DIOTWIWrite

decompiled_code:
__int64 __fastcall DIOTWIWrite(__int64 a1, char a2, int a3, int a4, __int64 a5)
{
unsigned __int8 *v7; // rbx
int v8; // er15
int v9; // ebp
unsigned __int8 v10; // si
int v12; // [rsp+Ch] [rbp-3Ch]

v7 = (unsigned __int8 *)a5;
v12 = ArrayLength(a5);
v8 = START(a1);
if ( v8 < 0 )
return (unsigned int)v8;
v8 = tx(a1, 2 * a2);
if ( v8 < 0 )
return (unsigned int)v8;
if ( a3 > 0 )
{
do
{
v8 = tx(a1, a4);
if ( v8 < 0 )
return (unsigned int)v8;
a4 >>= 8;
}
while ( --a3 );
}
v9 = v12 + (_DWORD)v7;
while ( v9 - (int)v7 > 0 )
{
v10 = *v7++;
if ( (int)tx(a1, v10) < 0 )
return (unsigned int)v8;
}
return STOP(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char a2, int a3, int a4, __int64 a5)
{
unsigned __int8 *v7; // rbx
int v8; // er15
int v9; // ebp
unsigned __int8 v10; // si
int v12; // [rsp+Ch] [rbp-3Ch]

v7 = (unsigned __int8 *)a5;
v12 = func15(a5);
v8 = func2(a1);
if ( v8 < 0 )
return (unsigned int)v8;
v8 = func4(a1, 2 * a2);
if ( v8 < 0 )
return (unsigned int)v8;
if ( a3 > 0 )
{
do
{
v8 = func4(a1, a4);
if ( v8 < 0 )
return (unsigned int)v8;
a4 >>= 8;
}
while ( --a3 );
}
v9 = v12 + (_DWORD)v7;
while ( v9 - (int)v7 > 0 )
{
v10 = *v7++;
if ( (int)func4(a1, v10) < 0 )
return (unsigned int)v8;
}
return func3(a1);
}

original_code:
TWIResult DIOTWIWrite(DIOTWI *twi,int devadrs,int adrslen,int adrs,const char* bytes){
  int len = ArrayLength(bytes);
  int ret=0;
  if ((ret = START(twi)) < 0) {
      goto WriteDone;
  }
  if ((ret = tx(twi,devadrs << 1)) < 0) {
    goto WriteDone;
  }
  if (adrslen > 0) {
    while (adrslen > 0) {
      if ((ret = tx(twi,adrs&0xFF)) < 0) {
 goto WriteDone;
      }
      adrs >>= 8;
      adrslen--;
    }
  }
  while (len-- > 0) {
    if (tx(twi,*(bytes)++) < 0) {
      goto WriteDone;
    }
  }
  if ((ret = STOP(twi)) < 0) {
    goto WriteDone;
  }
 WriteDone:
  return ret;
}

canonical_original_code:
enum TWIResult DIOTWIWrite(struct DIOTWI *twi, int devadrs, int adrslen, int adrs, char *bytes){
  int len = ArrayLength(bytes);
  int ret = 0;
  if ((ret = START(twi)) < 0) {
      goto WriteDone;
  }
  if ((ret = tx(twi,devadrs << 1)) < 0) {
    goto WriteDone;
  }
  if (adrslen > 0) {
    while (adrslen > 0) {
      if ((ret = tx(twi,adrs&0xFF)) < 0) {
 goto WriteDone;
      }
      adrs >>= 8;
      adrslen--;
    }
  }
  while (len-- > 0) {
    if (tx(twi,*(bytes)++) < 0) {
      goto WriteDone;
    }
  }
  if ((ret = STOP(twi)) < 0) {
    goto WriteDone;
  }
 WriteDone:
  return ret;
}

variable_types: devadrs int

variable_types: adrslen int

variable_types: adrs int

variable_types:
bytes
char *

variable_types: len int

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


DIOTWIRead

decompiled_code:
__int64 __fastcall DIOTWIRead(__int64 a1, char a2, __int64 a3, __int64 a4, __int64 a5)
{
int v6; // edx
int v7; // ecx
int v8; // er15
int v9; // ebx
int v10; // ebp
__int64 result; // rax
__int64 v12; // r14

v8 = ArrayLength(a5);
if ( v6 <= 0 )
{
LABEL_6:
result = START(a1);
if ( (int)result >= 0 )
{
result = tx(a1, 2 * a2 + 1);
if ( (int)result >= 0 )
{
v12 = 0LL;
if ( v8 > 0 )
{
while ( 1 )
{
result = rx(a1, v8 - 1 == v12);
if ( (int)result < 0 )
break;
*(_BYTE *)(a5 + v12++) = result;
if ( v12 == v8 )
goto LABEL_13;
}
}
else
{
LABEL_13:
result = STOP(a1);
}
}
}
}
else
{
v9 = v6;
v10 = v7;
result = START(a1);
if ( (int)result >= 0 )
{
result = tx(a1, 2 * a2);
if ( (int)result >= 0 )
{
while ( 1 )
{
result = tx(a1, v10);
if ( (int)result < 0 )
break;
v10 >>= 8;
if ( !--v9 )
goto LABEL_6;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, char a2, __int64 a3, __int64 a4, __int64 a5)
{
int v6; // edx
int v7; // ecx
int v8; // er15
int v9; // ebx
int v10; // ebp
__int64 result; // rax
__int64 v12; // r14

v8 = func15(a5);
if ( v6 <= 0 )
{
LABEL_6:
result = func2(a1);
if ( (int)result >= 0 )
{
result = func4(a1, 2 * a2 + 1);
if ( (int)result >= 0 )
{
v12 = 0LL;
if ( v8 > 0 )
{
while ( 1 )
{
result = func5(a1, v8 - 1 == v12);
if ( (int)result < 0 )
break;
*(_BYTE *)(a5 + v12++) = result;
if ( v12 == v8 )
goto LABEL_13;
}
}
else
{
LABEL_13:
result = func3(a1);
}
}
}
}
else
{
v9 = v6;
v10 = v7;
result = func2(a1);
if ( (int)result >= 0 )
{
result = func4(a1, 2 * a2);
if ( (int)result >= 0 )
{
while ( 1 )
{
result = func4(a1, v10);
if ( (int)result < 0 )
break;
v10 >>= 8;
if ( !--v9 )
goto LABEL_6;
}
}
}
}
return result;
}

original_code:
TWIResult DIOTWIRead(DIOTWI *twi,int devadrs,int adrslen,int adrs,char* bytes){
  int len = ArrayLength(bytes);
  int i,ret=0;
  if (adrslen > 0) {
    if ((ret = START(twi)) < 0) {
      goto ReadDone;
    }
    if ((ret = tx(twi,devadrs << 1)) < 0) {
      goto ReadDone;
    }
    while (adrslen > 0) {
      if ((ret = tx(twi,adrs&0xFF)) < 0) {
 goto ReadDone;
      }
      adrs >>= 8;
      adrslen--;
    }
  }
  if ((ret = START(twi)) < 0) {
    goto ReadDone;
  }
  if ((ret = tx(twi,(devadrs << 1)+1)) < 0) {
    goto ReadDone;
  }
  for (i=0;i<len;i++) {
    ret = rx(twi,i == len-1);
    if (ret < 0) {
      goto ReadDone;
    }
    bytes[i] = ret;
  }
  if ((ret = STOP(twi)) < 0) {
    goto ReadDone;
  }
 ReadDone:
  return ret;
}

canonical_original_code:
enum TWIResult DIOTWIRead(struct DIOTWI *twi, int devadrs, int adrslen, int adrs, char *bytes){
  int len = ArrayLength(bytes);
  int i; int ret = 0;
  if (adrslen > 0) {
    if ((ret = START(twi)) < 0) {
      goto ReadDone;
    }
    if ((ret = tx(twi,devadrs << 1)) < 0) {
      goto ReadDone;
    }
    while (adrslen > 0) {
      if ((ret = tx(twi,adrs&0xFF)) < 0) {
 goto ReadDone;
      }
      adrs >>= 8;
      adrslen--;
    }
  }
  if ((ret = START(twi)) < 0) {
    goto ReadDone;
  }
  if ((ret = tx(twi,(devadrs << 1)+1)) < 0) {
    goto ReadDone;
  }
  for (i=0;i<len;i++) {
    ret = rx(twi,i == len-1);
    if (ret < 0) {
      goto ReadDone;
    }
    bytes[i] = ret;
  }
  if ((ret = STOP(twi)) < 0) {
    goto ReadDone;
  }
 ReadDone:
  return ret;
}

variable_types: struct DIOTWI { void *(*Init)(struct DIOTWI *me, void *dio, void *time); void (*Fini)(struct DIOTWI *me); int (*Lock)(struct DIOTWI *me, unsigned int num, int flags); int (*Unlock)(struct DIOTWI *me, unsigned int num, int flags); int (*Preempt)(struct DIOTWI *me); enum TWIResult { TWISuccess=1, TWIErrorPortInvalid=-1, TWIErrorModeUnsupported=-2, TWIErrorBaudUnconstrained=-3, TWIErrorHardware=-4, TWIErrorHandle=-5, TWIErrorWriteNAck=-6, TWIErrorDataNAck=-7, TWIErrorReadNack=-8, TWIErrorSDALow=-9, TWIErrorSCLLow=-10, TWIErrorAdrsLen=-11, TWIErrorTimeout=-12, TWIErrorOverrun=-13, TWIErrorArbLost=-14, TWIErrorUnknown=-999, TWIErrorOpInvalid=-15 } (*Write)(struct DIOTWI *me, int devadr, int adrslen, int adrs, char *bytes); enum TWIResult { TWISuccess=1, TWIErrorPortInvalid=-1, TWIErrorModeUnsupported=-2, TWIErrorBaudUnconstrained=-3, TWIErrorHardware=-4, TWIErrorHandle=-5, TWIErrorWriteNAck=-6, TWIErrorDataNAck=-7, TWIErrorReadNack=-8, TWIErrorSDALow=-9, TWIErrorSCLLow=-10, TWIErrorAdrsLen=-11, TWIErrorTimeout=-12, TWIErrorOverrun=-13, TWIErrorArbLost=-14, TWIErrorUnknown=-999, TWIErrorOpInvalid=-15 } (*Read)(struct DIOTWI *me, int devadr, int adrslen, int adrs, char *bytes); int InitStatus; struct DIO { void *(*Init)(void *me, ...); void (*Fini)(void *me); int (*Lock)(void *me, unsigned int num, int flags); int (*Unlock)(void *me, unsigned int num, int flags); int (*Preempt)(void *me); void (*Refresh)(void *me); void (*Commit)(void *me, int ForceAll); void (*Set)(void *me, int DIONum, enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } State); enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } (*Get)(void *me, int DIONum); void (*SetAsync)(void *me, int DIONum, enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } State); enum DIOState { INPUT_LOW=-3, INPUT_HIGH=-2, INPUT=-1, LOW=0, HIGH=1 } (*GetAsync)(void *me, int DIONum); void (*Wait)(void *me, int *match, int min, int max, int *nh, int *nl); unsigned int (*Count)(void *me); enum DIOCaps { DIO_NOT_PRESENT=0, DIO_CAN_INPUT=1, DIO_CAN_DRIVE_HIGH=2, DIO_HIGH_SIDE=3, DIO_CAN_DRIVE_LOW=4, DIO_LOW_SIDE=5, DIO_OUTPUT_ONLY=6, DIO_NORMAL=7 } (*Capabilities)(void *me, unsigned int num); int (*GetMulti)(void *me, char *state, int offset); int InitStatus; } *dio; struct Time { void *(*Init)(void *me, ...); void (*Fini)(void *me); unsigned int (*Wait)(void *me, unsigned int microseconds); void (*Delay)(void *me, unsigned int microseconds); unsigned int (*Tick)(void *me); unsigned int (*usElapsed)(void *me, unsigned int start); unsigned int (*usFuture)(void *me, unsigned int start, unsigned int microseconds); enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 } (*TimeoutQ)(void *me, unsigned int start, unsigned int end); unsigned int (*TPS)(void *me); int InitStatus; } *t; int TW_CLK; int TW_DAT; int Speed; int delay; int LockNum; unsigned int start; } *

variable_types: i 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

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

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

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

variable_types:
arr
void ***

variable_types: j int


ArrayCompareFunction

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

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

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

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


NoneArchNextSubArch

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

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

canonical_original_code:
struct Arch *NoneArchNextSubArch() {
  return 0;
}

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:
__int64 None__SystemInit0()
{
return LocalSystemInit(&Nonesys);
}

canonical_decompiled_code:
__int64 func1()
{
return LocalSystemInit(&Nonesys);
}

original_code:
void *None__SystemInit0(void *s,int inst) {
  return LocalSystemInit(&Nonesys);
}

canonical_original_code:
void *None__SystemInit0(void *s, int inst) {
  return LocalSystemInit(&Nonesys);
}

variable_types:
s
void *

variable_types: inst int


decompiled_code:
__int64 None__TimeInit0()
{
return SystemTimeInit(&NoneTime0);
}

canonical_decompiled_code:
__int64 func2()
{
return SystemTimeInit(&NoneTime0);
}

original_code:
Time *None__TimeInit0(Time *t,int inst) {
  return SystemTimeInit(&NoneTime0);
}

canonical_original_code:
struct Time *None__TimeInit0(struct Time *t, int inst) {
  return SystemTimeInit(&NoneTime0);
}

variable_types:
t
struct Time *

return_type: struct Time { void *(*Init)(void *me, ...); void (*Fini)(void *me); unsigned int (*Wait)(void *me, unsigned int microseconds); void (*Delay)(void *me, unsigned int microseconds); unsigned int (*Tick)(void *me); unsigned int (*usElapsed)(void *me, unsigned int start); unsigned int (*usFuture)(void *me, unsigned int start, unsigned int microseconds); enum TimeResult { TimeoutOccurred=1, TimeoutDidNotOccur=0 } (*TimeoutQ)(void *me, unsigned int start, unsigned int end); unsigned int (*TPS)(void *me); int InitStatus; } *


ArrayFree

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

variable_types:
arr
void *

variable_types:
ptr
unsigned int *


ASCIIZ

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

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

variable_types:
str
char *

variable_types:
len
unsigned int


ArraySizeAuto

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

variable_types:
count
unsigned int


ArrayElementSize

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

variable_types:
array
void *