decompiled_code:
__int64 __fastcall RVC_decoder__texture_U__IAP__DOLLAR__d10577(__int64 a1, __int64 a2)
{
return (unsigned int)pinPeek_int32_t_constprop_0(*(_QWORD *)(a2 + 40) + 232LL) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int64 a2)
{
return (unsigned int)func14(*(_QWORD *)(a2 + 40) + 232LL) >> 31;
}

original_code:
bool_t RVC_decoder__texture_U__IAP__DOLLAR__d10577(art_action_context_t *context, ActorInstance_RVC_decoder__texture_U__IAP *thisActor) {
  int32_t s;
  {
    bool_t ret;
    s = pinPeek_int32_t(&(thisActor->base.inputPort[2].localInputPort), 0);
    ret = (s < 0);
    return ret;
  }
}

canonical_original_code:
int RVC_decoder__texture_U__IAP__DOLLAR__d10577(void *context, struct ActorInstance_RVC_decoder__texture_U__IAP *thisActor) {
  int s;
  {
    int ret;
    s = pinPeek_int32_t(&(thisActor->base.inputPort[2].localInputPort), 0);
    ret = (s < 0);
    return ret;
  }
}

user_defined_types: struct dllist_head_t { struct dllist_link_tag head_element; union pthread_mutex_t mutex; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }


repo: Caltoopia/caltoopia-calvin

decompiled_code:
_BOOL8 __fastcall RVC_decoder__texture_U__IAP__DOLLAR__d10606(__int64 a1, __int64 a2)
{
return *(_DWORD *)(a2 + 108) == 64;
}

original_code:
bool_t RVC_decoder__texture_U__IAP__DOLLAR__d10606(art_action_context_t *context, ActorInstance_RVC_decoder__texture_U__IAP *thisActor) {
  {
    bool_t ret;
    ret = (thisActor->count == 64);
    return ret;
  }
}

canonical_original_code:
int RVC_decoder__texture_U__IAP__DOLLAR__d10606(void *context, struct ActorInstance_RVC_decoder__texture_U__IAP *thisActor) {
  {
    int ret;
    ret = (thisActor->count == 64);
    return ret;
  }
}

variable_types:
context
void *

variable_types: struct ActorInstance_RVC_decoder__texture_U__IAP { struct AbstractActorInstance { struct dllist_link_tag { struct dllist_link_tag *suc; } listEntry; struct ActorClass { unsigned int majorVersion; unsigned int minorVersion; char *name; int sizeActorInstance; int numInputPorts; struct PortDescription { int dummy; char *name; int tokenSize; struct tokenFn { char *(*serialize)(void *, char *); char *(*deserialize)(void **, char *); long (*size)(void *); int (*free)(void *, int); } *functions; } *inputPortDescriptions; int numOutputPorts; struct PortDescription *outputPortDescriptions; int numActions; struct ActionDescription { char *name; int *consumption; int *production; } *actionDescriptions; int *(*action_scheduler)(struct AbstractActorInstance *); void (*constructor)(struct AbstractActorInstance *); void (*destructor)(struct AbstractActorInstance *); void (*set_param)(struct AbstractActorInstance *, char *, char *); } *actorClass; char *instanceName; int numInputPorts; struct InputPort { struct dllist_link_tag asConsumer; struct OutputPort { struct LocalOutputPort { void *bufferStart; void *bufferEnd; void *writePtr; unsigned int spaceLeft; } localOutputPort; unsigned int capacity; unsigned int tokensProduced; unsigned int fullAt; struct tokenFn functions; struct dllist_head_t { struct dllist_link_tag head_element; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } consumers; } *producer; struct LocalInputPort { void *bufferStart; void *bufferEnd; void *readPtr; unsigned int available; } localInputPort; unsigned int tokensConsumed; unsigned int drainedAt; unsigned int capacity; struct tokenFn functions; } *inputPort; int numOutputPorts; struct OutputPort *outputPort; int *(*action_scheduler)(struct AbstractActorInstance *); } base; int _fsmState; int ptr; int pred_ptr; int acpred_flag; int top; int *buf; int s_prev_quant; int count; int s_quant; } *

variable_types: ret int

return_type: int

user_defined_types: struct ActorInstance_RVC_decoder__texture_U__IAP { struct AbstractActorInstance base; int _fsmState; int ptr; int pred_ptr; int acpred_flag; int top; int *buf; int s_prev_quant; int count; int s_quant; }

user_defined_types: struct AbstractActorInstance { struct dllist_link_tag listEntry; struct ActorClass *actorClass; char *instanceName; int numInputPorts; struct InputPort *inputPort; int numOutputPorts; struct OutputPort *outputPort; int *(*action_scheduler)(struct AbstractActorInstance *); }

user_defined_types: struct ActorClass { unsigned int majorVersion; unsigned int minorVersion; char *name; int sizeActorInstance; int numInputPorts; struct PortDescription *inputPortDescriptions; int numOutputPorts; struct PortDescription *outputPortDescriptions; int numActions; struct ActionDescription *actionDescriptions; int *(*action_scheduler)(struct AbstractActorInstance *); void (*constructor)(struct AbstractActorInstance *); void (*destructor)(struct AbstractActorInstance *); void (*set_param)(struct AbstractActorInstance *, char *, char *); }

user_defined_types: struct InputPort { struct dllist_link_tag asConsumer; struct OutputPort *producer; struct LocalInputPort localInputPort; unsigned int tokensConsumed; unsigned int drainedAt; unsigned int capacity; struct tokenFn functions; }

user_defined_types: struct PortDescription { int dummy; char *name; int tokenSize; struct tokenFn *functions; }

user_defined_types: struct OutputPort { struct LocalOutputPort localOutputPort; unsigned int capacity; unsigned int tokensProduced; unsigned int fullAt; struct tokenFn functions; struct dllist_head_t consumers; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
void *__fastcall RVC_decoder__texture_U__IAP_action_scheduler(__int64 a1)
{
int v1; // eax
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx

v1 = *(_DWORD *)(a1 + 72);
do
{
if ( !v1 )
goto LABEL_9;
}
while ( v1 != 1 );
LABEL_4:
while ( !(unsigned int)RVC_decoder__texture_U__IAP__DOLLAR__d10606(0LL, a1) )
{
if ( !(unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL))
|| !(unsigned int)pinAvailOut_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) )
{
return &exitcode_block_Any;
}
action4__copy(a1);
*(_DWORD *)(a1 + 72) = 1;
}
action3__advance(a1);
*(_DWORD *)(a1 + 72) = 0;
LABEL_9:
while ( (unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL)) )
{
if ( !(unsigned int)RVC_decoder__texture_U__IAP__DOLLAR__d10566(0LL, a1) )
{
if ( !(unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL)) )
return &exitcode_block_Any;
if ( (unsigned int)RVC_decoder__texture_U__IAP__DOLLAR__d10577(0LL, a1) )
{
action1__skip(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_4;
}
if ( (unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL))
&& (unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(v3 + 152))
&& (unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(v4 + 360))
&& (unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(v5 + 464)) )
{
action2__start(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_4;
}
return &exitcode_block_Any;
}
action0__newvop(a1);
*(_DWORD *)(a1 + 72) = 0;
}
return &exitcode_block_Any;
}

canonical_decompiled_code:
void *__fastcall func23(__int64 a1)
{
int v1; // eax
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx

v1 = *(_DWORD *)(a1 + 72);
do
{
if ( !v1 )
goto LABEL_9;
}
while ( v1 != 1 );
LABEL_4:
while ( !(unsigned int)func22(0LL, a1) )
{
if ( !(unsigned int)func19(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL))
|| !(unsigned int)func18(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) )
{
return &exitcode_block_Any;
}
action4__copy(a1);
*(_DWORD *)(a1 + 72) = 1;
}
func7(a1);
*(_DWORD *)(a1 + 72) = 0;
LABEL_9:
while ( (unsigned int)func19(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL)) )
{
if ( !(unsigned int)func20(0LL, a1) )
{
if ( !(unsigned int)func19(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL)) )
return &exitcode_block_Any;
if ( (unsigned int)func21(0LL, a1) )
{
func11(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_4;
}
if ( (unsigned int)func19(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL))
&& (unsigned int)func19(*(_DWORD *)(v3 + 152))
&& (unsigned int)func19(*(_DWORD *)(v4 + 360))
&& (unsigned int)func19(*(_DWORD *)(v5 + 464)) )
{
func12(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_4;
}
return &exitcode_block_Any;
}
func10(a1);
*(_DWORD *)(a1 + 72) = 0;
}
return &exitcode_block_Any;
}

original_code:
static const int *RVC_decoder__texture_U__IAP_action_scheduler(AbstractActorInstance *pBase) {
  const int *result = exit_code_yield;
  ActorInstance_RVC_decoder__texture_U__IAP *thisActor=(ActorInstance_RVC_decoder__texture_U__IAP*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1)) {
          if (RVC_decoder__texture_U__IAP__DOLLAR__d10566(context, thisActor)) {
            action0__newvop(thisActor);
            thisActor->_fsmState = 0;
            continue;
          }
        }
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1)) {
          if (RVC_decoder__texture_U__IAP__DOLLAR__d10577(context, thisActor)) {
            action1__skip(thisActor);
            thisActor->_fsmState = 1;
            continue;
          }
        }
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[1].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[3].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[4].localInputPort)) >= 1)) {
          action2__start(thisActor);
          thisActor->_fsmState = 1;
          continue;
        }
        result = exitcode_block_Any;
        goto out;
        break;
      case 1:
        if (RVC_decoder__texture_U__IAP__DOLLAR__d10606(context, thisActor)) {
          action3__advance(thisActor);
          thisActor->_fsmState = 0;
          continue;
        }
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 1)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1)) {
            action4__copy(thisActor);
            thisActor->_fsmState = 1;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}

canonical_original_code:
static int *RVC_decoder__texture_U__IAP_action_scheduler(struct AbstractActorInstance *pBase) {
  int *result = exit_code_yield;
  struct ActorInstance_RVC_decoder__texture_U__IAP *thisActor = (ActorInstance_RVC_decoder__texture_U__IAP*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1)) {
          if (RVC_decoder__texture_U__IAP__DOLLAR__d10566(context, thisActor)) {
            action0__newvop(thisActor);
            thisActor->_fsmState = 0;
            continue;
          }
        }
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1)) {
          if (RVC_decoder__texture_U__IAP__DOLLAR__d10577(context, thisActor)) {
            action1__skip(thisActor);
            thisActor->_fsmState = 1;
            continue;
          }
        }
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[1].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[3].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[4].localInputPort)) >= 1)) {
          action2__start(thisActor);
          thisActor->_fsmState = 1;
          continue;
        }
        result = exitcode_block_Any;
        goto out;
        break;
      case 1:
        if (RVC_decoder__texture_U__IAP__DOLLAR__d10606(context, thisActor)) {
          action3__advance(thisActor);
          thisActor->_fsmState = 0;
          continue;
        }
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 1)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1)) {
            action4__copy(thisActor);
            thisActor->_fsmState = 1;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}

variable_types: struct AbstractActorInstance { struct dllist_link_tag { struct dllist_link_tag *suc; } listEntry; struct ActorClass { unsigned int majorVersion; unsigned int minorVersion; char *name; int sizeActorInstance; int numInputPorts; struct PortDescription { int dummy; char *name; int tokenSize; struct tokenFn { char *(*serialize)(void *, char *); char *(*deserialize)(void **, char *); long (*size)(void *); int (*free)(void *, int); } *functions; } *inputPortDescriptions; int numOutputPorts; struct PortDescription *outputPortDescriptions; int numActions; struct ActionDescription { char *name; int *consumption; int *production; } *actionDescriptions; int *(*action_scheduler)(struct AbstractActorInstance *); void (*constructor)(struct AbstractActorInstance *); void (*destructor)(struct AbstractActorInstance *); void (*set_param)(struct AbstractActorInstance *, char *, char *); } *actorClass; char *instanceName; int numInputPorts; struct InputPort { struct dllist_link_tag asConsumer; struct OutputPort { struct LocalOutputPort { void *bufferStart; void *bufferEnd; void *writePtr; unsigned int spaceLeft; } localOutputPort; unsigned int capacity; unsigned int tokensProduced; unsigned int fullAt; struct tokenFn functions; struct dllist_head_t { struct dllist_link_tag head_element; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } consumers; } *producer; struct LocalInputPort { void *bufferStart; void *bufferEnd; void *readPtr; unsigned int available; } localInputPort; unsigned int tokensConsumed; unsigned int drainedAt; unsigned int capacity; struct tokenFn functions; } *inputPort; int numOutputPorts; struct OutputPort *outputPort; int *(*action_scheduler)(struct AbstractActorInstance *); } *

variable_types:
result
int *

return_type: int *


decompiled_code:
void __fastcall ActorInstance_RVC_decoder__parser__splitter_Qp_constructor(__int64 a1)
{
*(_DWORD *)(a1 + 72) = 0;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
*(_DWORD *)(a1 + 72) = 0;
}

original_code:
static void ActorInstance_RVC_decoder__parser__splitter_Qp_constructor(AbstractActorInstance *pBase) {
  ActorInstance_RVC_decoder__parser__splitter_Qp *thisActor=(ActorInstance_RVC_decoder__parser__splitter_Qp*) pBase;
  thisActor->_fsmState = 0;
  {
  }
}

canonical_original_code:
static void ActorInstance_RVC_decoder__parser__splitter_Qp_constructor(struct AbstractActorInstance *pBase) {
  struct ActorInstance_RVC_decoder__parser__splitter_Qp *thisActor = (ActorInstance_RVC_decoder__parser__splitter_Qp*) pBase;
  thisActor->_fsmState = 0;
  {
  }
}

variable_types: struct ActorInstance_RVC_decoder__parser__splitter_Qp { struct AbstractActorInstance { struct dllist_link_tag { struct dllist_link_tag *suc; } listEntry; struct ActorClass { unsigned int majorVersion; unsigned int minorVersion; char *name; int sizeActorInstance; int numInputPorts; struct PortDescription { int dummy; char *name; int tokenSize; struct tokenFn { char *(*serialize)(void *, char *); char *(*deserialize)(void **, char *); long (*size)(void *); int (*free)(void *, int); } *functions; } *inputPortDescriptions; int numOutputPorts; struct PortDescription *outputPortDescriptions; int numActions; struct ActionDescription { char *name; int *consumption; int *production; } *actionDescriptions; int *(*action_scheduler)(struct AbstractActorInstance *); void (*constructor)(struct AbstractActorInstance *); void (*destructor)(struct AbstractActorInstance *); void (*set_param)(struct AbstractActorInstance *, char *, char *); } *actorClass; char *instanceName; int numInputPorts; struct InputPort { struct dllist_link_tag asConsumer; struct OutputPort { struct LocalOutputPort { void *bufferStart; void *bufferEnd; void *writePtr; unsigned int spaceLeft; } localOutputPort; unsigned int capacity; unsigned int tokensProduced; unsigned int fullAt; struct tokenFn functions; struct dllist_head_t { struct dllist_link_tag head_element; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } consumers; } *producer; struct LocalInputPort { void *bufferStart; void *bufferEnd; void *readPtr; unsigned int available; } localInputPort; unsigned int tokensConsumed; unsigned int drainedAt; unsigned int capacity; struct tokenFn functions; } *inputPort; int numOutputPorts; struct OutputPort *outputPort; int *(*action_scheduler)(struct AbstractActorInstance *); } base; int _fsmState; } *

return_type: void

user_defined_types: struct ActorInstance_RVC_decoder__parser__splitter_Qp { struct AbstractActorInstance base; int _fsmState; }


decompiled_code:
void __fastcall action0__quant__split(__int64 a1)
{
void *v1; // rbp

v1 = malloc(0x18uLL);
pinReadRepeat_int32_t_constprop_0((char **)(*(_QWORD *)(a1 + 40) + 24LL), (char *)v1);
pinWrite_int32_t(*(_QWORD *)(a1 + 56), *(_DWORD *)v1);
pinWrite_int32_t(*(_QWORD *)(a1 + 56), *((_DWORD *)v1 + 1));
pinWrite_int32_t(*(_QWORD *)(a1 + 56), *((_DWORD *)v1 + 2));
pinWrite_int32_t(*(_QWORD *)(a1 + 56), *((_DWORD *)v1 + 3));
pinWrite_int32_t(*(_QWORD *)(a1 + 56) + 136LL, *((_DWORD *)v1 + 4));
pinWrite_int32_t(*(_QWORD *)(a1 + 56) + 272LL, *((_DWORD *)v1 + 5));
free(v1);
}

original_code:
static void action0__quant__split(ActorInstance_RVC_decoder__parser__splitter_Qp *thisActor) {
  int32_t* list;
  ;
  list = malloc((sizeof(int32_t) * 6));
  pinReadRepeat_int32_t(&(thisActor->base.inputPort[0].localInputPort), list, 6);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[0]);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[1]);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[2]);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[3]);
  pinWrite_int32_t(&(thisActor->base.outputPort[1].localOutputPort), list[4]);
  pinWrite_int32_t(&(thisActor->base.outputPort[2].localOutputPort), list[5]);
  free((void*) list);
  ;
}

canonical_original_code:
static void action0__quant__split(struct ActorInstance_RVC_decoder__parser__splitter_Qp *thisActor) {
  int *list;
  ;
  list = malloc((sizeof(int) * 6));
  pinReadRepeat_int32_t(&(thisActor->base.inputPort[0].localInputPort), list, 6);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[0]);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[1]);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[2]);
  pinWrite_int32_t(&(thisActor->base.outputPort[0].localOutputPort), list[3]);
  pinWrite_int32_t(&(thisActor->base.outputPort[1].localOutputPort), list[4]);
  pinWrite_int32_t(&(thisActor->base.outputPort[2].localOutputPort), list[5]);
  free((void *) list);
  ;
}

variable_types:
list
int *

user_defined_types: struct dllist_link_tag { struct dllist_link_tag *suc; }

user_defined_types: struct LocalInputPort { void *bufferStart; void *bufferEnd; void *readPtr; unsigned int available; }

user_defined_types: struct ActionDescription { char *name; int *consumption; int *production; }

user_defined_types: struct LocalOutputPort { void *bufferStart; void *bufferEnd; void *writePtr; unsigned int spaceLeft; }

user_defined_types: struct tokenFn { char *(*serialize)(void *, char *); char *(*deserialize)(void **, char *); long (*size)(void *); int (*free)(void *, int); }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
void *__fastcall RVC_decoder__parser__splitter_Qp_action_scheduler(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rdx

while ( *(_DWORD *)(a1 + 72) )
;
while ( (unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL)) > 5
&& (unsigned int)pinAvailOut_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) > 3
&& (unsigned int)pinAvailOut_int32_t_isra_0(*(_DWORD *)(v1 + 160))
&& (unsigned int)pinAvailOut_int32_t_isra_0(*(_DWORD *)(v2 + 296)) )
{
action0__quant__split(a1);
*(_DWORD *)(a1 + 72) = 0;
}
return &exitcode_block_Any;
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rdx

while ( *(_DWORD *)(a1 + 72) )
;
while ( (unsigned int)func10(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL)) > 5
&& (unsigned int)func9(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) > 3
&& (unsigned int)func9(*(_DWORD *)(v1 + 160))
&& (unsigned int)func9(*(_DWORD *)(v2 + 296)) )
{
func8(a1);
*(_DWORD *)(a1 + 72) = 0;
}
return &exitcode_block_Any;
}

original_code:
static const int *RVC_decoder__parser__splitter_Qp_action_scheduler(AbstractActorInstance *pBase) {
  const int *result = exit_code_yield;
  ActorInstance_RVC_decoder__parser__splitter_Qp *thisActor=(ActorInstance_RVC_decoder__parser__splitter_Qp*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 6)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1*4) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[1].localOutputPort)) >= 1) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[2].localOutputPort)) >= 1)) {
            action0__quant__split(thisActor);
            thisActor->_fsmState = 0;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}

canonical_original_code:
static int *RVC_decoder__parser__splitter_Qp_action_scheduler(struct AbstractActorInstance *pBase) {
  int *result = exit_code_yield;
  struct ActorInstance_RVC_decoder__parser__splitter_Qp *thisActor = (ActorInstance_RVC_decoder__parser__splitter_Qp*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 6)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1*4) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[1].localOutputPort)) >= 1) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[2].localOutputPort)) >= 1)) {
            action0__quant__split(thisActor);
            thisActor->_fsmState = 0;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}


rshift

decompiled_code:
__int64 __fastcall rshift(int a1, char a2)
{
return (unsigned int)(a1 >> a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, char a2)
{
return (unsigned int)(a1 >> a2);
}

original_code: static inline int32_t rshift(int32_t x, int32_t n) { return x >> n; }

canonical_original_code: static inline int rshift(int x, int n) { return x >> n; }

variable_types: x int

variable_types: n int


decompiled_code:
void __fastcall ActorInstance_RVC_decoder__texture_U__idct2d__column_constructor(__int64 a1)
{
*(_DWORD *)(a1 + 72) = 0;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
*(_DWORD *)(a1 + 72) = 0;
}

original_code:
static void ActorInstance_RVC_decoder__texture_U__idct2d__column_constructor(AbstractActorInstance *pBase) {
  ActorInstance_RVC_decoder__texture_U__idct2d__column *thisActor=(ActorInstance_RVC_decoder__texture_U__idct2d__column*) pBase;
  thisActor->_fsmState = 0;
  {
  }
}

canonical_original_code:
static void ActorInstance_RVC_decoder__texture_U__idct2d__column_constructor(struct AbstractActorInstance *pBase) {
  struct ActorInstance_RVC_decoder__texture_U__idct2d__column *thisActor = (ActorInstance_RVC_decoder__texture_U__idct2d__column*) pBase;
  thisActor->_fsmState = 0;
  {
  }
}

variable_types: struct ActorInstance_RVC_decoder__texture_U__idct2d__column { struct AbstractActorInstance { struct dllist_link_tag { struct dllist_link_tag *suc; } listEntry; struct ActorClass { unsigned int majorVersion; unsigned int minorVersion; char *name; int sizeActorInstance; int numInputPorts; struct PortDescription { int dummy; char *name; int tokenSize; struct tokenFn { char *(*serialize)(void *, char *); char *(*deserialize)(void **, char *); long (*size)(void *); int (*free)(void *, int); } *functions; } *inputPortDescriptions; int numOutputPorts; struct PortDescription *outputPortDescriptions; int numActions; struct ActionDescription { char *name; int *consumption; int *production; } *actionDescriptions; int *(*action_scheduler)(struct AbstractActorInstance *); void (*constructor)(struct AbstractActorInstance *); void (*destructor)(struct AbstractActorInstance *); void (*set_param)(struct AbstractActorInstance *, char *, char *); } *actorClass; char *instanceName; int numInputPorts; struct InputPort { struct dllist_link_tag asConsumer; struct OutputPort { struct LocalOutputPort { void *bufferStart; void *bufferEnd; void *writePtr; unsigned int spaceLeft; } localOutputPort; unsigned int capacity; unsigned int tokensProduced; unsigned int fullAt; struct tokenFn functions; struct dllist_head_t { struct dllist_link_tag head_element; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } consumers; } *producer; struct LocalInputPort { void *bufferStart; void *bufferEnd; void *readPtr; unsigned int available; } localInputPort; unsigned int tokensConsumed; unsigned int drainedAt; unsigned int capacity; struct tokenFn functions; } *inputPort; int numOutputPorts; struct OutputPort *outputPort; int *(*action_scheduler)(struct AbstractActorInstance *); } base; int _fsmState; } *

user_defined_types: struct ActorInstance_RVC_decoder__texture_U__idct2d__column { struct AbstractActorInstance base; int _fsmState; }


decompiled_code:
void *__fastcall RVC_decoder__texture_U__idct2d__column_action_scheduler(__int64 a1)
{
unsigned int v1; // eax

v1 = pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL));
do
{
while ( v1 > 7 )
{
if ( (unsigned int)pinAvailOut_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) <= 7 )
return &exitcode_block_Any;
action0(a1);
v1 = pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL));
}
}
while ( *(_DWORD *)(a1 + 72) );
return &exitcode_block_Any;
}

canonical_decompiled_code:
void *__fastcall func19(__int64 a1)
{
unsigned int v1; // eax

v1 = func18(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL));
do
{
while ( v1 > 7 )
{
if ( (unsigned int)func17(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) <= 7 )
return &exitcode_block_Any;
func16(a1);
v1 = func18(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 48LL));
}
}
while ( *(_DWORD *)(a1 + 72) );
return &exitcode_block_Any;
}

original_code:
static const int *RVC_decoder__texture_U__idct2d__column_action_scheduler(AbstractActorInstance *pBase) {
  const int *result = exit_code_yield;
  ActorInstance_RVC_decoder__texture_U__idct2d__column *thisActor=(ActorInstance_RVC_decoder__texture_U__idct2d__column*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 8)) {
      if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 8)) {
        action0(thisActor);
        continue;
      } else {
        result = exitcode_block_Any;
        goto out;
      }
    }
    switch(thisActor->_fsmState) {
      case 0:
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}

canonical_original_code:
static int *RVC_decoder__texture_U__idct2d__column_action_scheduler(struct AbstractActorInstance *pBase) {
  int *result = exit_code_yield;
  struct ActorInstance_RVC_decoder__texture_U__idct2d__column *thisActor = (ActorInstance_RVC_decoder__texture_U__idct2d__column*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 8)) {
      if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 8)) {
        action0(thisActor);
        continue;
      } else {
        result = exitcode_block_Any;
        goto out;
      }
    }
    switch(thisActor->_fsmState) {
      case 0:
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}

user_defined_types: struct dllist_head_t { struct dllist_link_tag head_element; union pthread_mutex_t mutex; }


decompiled_code:
void __fastcall ActorInstance_RVC_decoder__texture_V__IQ_constructor(__int64 a1)
{
*(_DWORD *)(a1 + 72) = 0;
}

original_code:
static void ActorInstance_RVC_decoder__texture_V__IQ_constructor(AbstractActorInstance *pBase) {
  ActorInstance_RVC_decoder__texture_V__IQ *thisActor=(ActorInstance_RVC_decoder__texture_V__IQ*) pBase;
  thisActor->_fsmState = 0;
  {
  }
}

canonical_original_code:
static void ActorInstance_RVC_decoder__texture_V__IQ_constructor(struct AbstractActorInstance *pBase) {
  struct ActorInstance_RVC_decoder__texture_V__IQ *thisActor = (ActorInstance_RVC_decoder__texture_V__IQ*) pBase;
  thisActor->_fsmState = 0;
  {
  }
}

variable_types: struct ActorInstance_RVC_decoder__texture_V__IQ { struct AbstractActorInstance { struct dllist_link_tag { struct dllist_link_tag *suc; } listEntry; struct ActorClass { unsigned int majorVersion; unsigned int minorVersion; char *name; int sizeActorInstance; int numInputPorts; struct PortDescription { int dummy; char *name; int tokenSize; struct tokenFn { char *(*serialize)(void *, char *); char *(*deserialize)(void **, char *); long (*size)(void *); int (*free)(void *, int); } *functions; } *inputPortDescriptions; int numOutputPorts; struct PortDescription *outputPortDescriptions; int numActions; struct ActionDescription { char *name; int *consumption; int *production; } *actionDescriptions; int *(*action_scheduler)(struct AbstractActorInstance *); void (*constructor)(struct AbstractActorInstance *); void (*destructor)(struct AbstractActorInstance *); void (*set_param)(struct AbstractActorInstance *, char *, char *); } *actorClass; char *instanceName; int numInputPorts; struct InputPort { struct dllist_link_tag asConsumer; struct OutputPort { struct LocalOutputPort { void *bufferStart; void *bufferEnd; void *writePtr; unsigned int spaceLeft; } localOutputPort; unsigned int capacity; unsigned int tokensProduced; unsigned int fullAt; struct tokenFn functions; struct dllist_head_t { struct dllist_link_tag head_element; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } consumers; } *producer; struct LocalInputPort { void *bufferStart; void *bufferEnd; void *readPtr; unsigned int available; } localInputPort; unsigned int tokensConsumed; unsigned int drainedAt; unsigned int capacity; struct tokenFn functions; } *inputPort; int numOutputPorts; struct OutputPort *outputPort; int *(*action_scheduler)(struct AbstractActorInstance *); } base; int _fsmState; int round; int count; int quant; } *

user_defined_types: struct ActorInstance_RVC_decoder__texture_V__IQ { struct AbstractActorInstance base; int _fsmState; int round; int count; int quant; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }


decompiled_code:
__int64 __fastcall pinRead_int32_t(__int64 a1)
{
int v1; // eax
unsigned int *v2; // rcx
unsigned int v3; // er8
_DWORD *v4; // rdx

v1 = *(_DWORD *)(a1 + 24);
v2 = *(unsigned int **)(a1 + 16);
if ( !v1 )
__assert_fail("p->available > 0", "../../actors-fifo.h", 0x6Bu, "pinRead_int32_t");
v3 = *v2;
v4 = v2 + 1;
if ( *(_QWORD *)(a1 + 8) <= (unsigned __int64)(v2 + 1) )
v4 = *(_DWORD **)a1;
*(_QWORD *)(a1 + 16) = v4;
*(_DWORD *)(a1 + 24) = v1 - 1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // eax
unsigned int *v2; // rcx
unsigned int v3; // er8
_DWORD *v4; // rdx

v1 = *(_DWORD *)(a1 + 24);
v2 = *(unsigned int **)(a1 + 16);
if ( !v1 )
__assert_fail("p->available > 0", "../../actors-fifo.h", 0x6Bu, "pinRead_int32_t");
v3 = *v2;
v4 = v2 + 1;
if ( *(_QWORD *)(a1 + 8) <= (unsigned __int64)(v2 + 1) )
v4 = *(_DWORD **)a1;
*(_QWORD *)(a1 + 16) = v4;
*(_DWORD *)(a1 + 24) = v1 - 1;
return v3;
}

original_code:
static inline int32_t pinRead_int32_t(LocalInputPort *p)
{
  const int32_t *readPtr=(const int32_t *) p->readPtr;
  int32_t result;
  ((void) sizeof ((p->available > 0) ? 1 : 0), __extension__ ({ if (p->available > 0) ; else __assert_fail ("p->available > 0", "../../actors-fifo.h", 107, __extension__ __PRETTY_FUNCTION__); }));
  result = (int32_t) *readPtr++;
  if (readPtr >= (const int32_t*) p->bufferEnd)
    readPtr = (const int32_t*)p->bufferStart;
  p->readPtr=readPtr;
  p->available--;
  return result;
}

canonical_original_code:
static inline int pinRead_int32_t(struct LocalInputPort *p)
{
  int *readPtr = (const int32_t *) p->readPtr;
  int result;
  ((void) sizeof ((p->available > 0) ? 1 : 0), __extension__ ({ if (p->available > 0) ; else __assert_fail ("p->available > 0", "../../actors-fifo.h", 107, __extension__ __PRETTY_FUNCTION__); }));
  result = (int) *readPtr++;
  if (readPtr >= (int *) p->bufferEnd)
    readPtr = (int *)p->bufferStart;
  p->readPtr=readPtr;
  p->available--;
  return result;
}

variable_types: struct LocalInputPort { void *bufferStart; void *bufferEnd; void *readPtr; unsigned int available; } *

variable_types:
readPtr
int *

variable_types: result int


decompiled_code:
void *__fastcall RVC_decoder__texture_V__IQ_action_scheduler(__int64 a1)
{
int v1; // eax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 72);
do
{
if ( !v1 )
goto LABEL_8;
}
while ( v1 != 1 );
while ( (unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 152LL)) > 0x3E
&& (unsigned int)pinAvailOut_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) > 0x3E )
{
action1__ac(a1);
*(_DWORD *)(a1 + 72) = 0;
LABEL_8:
if ( !(unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL))
|| !(unsigned int)pinAvailIn_int32_t_isra_0(*(_DWORD *)(v3 + 48))
|| !(unsigned int)pinAvailOut_int32_t_isra_0(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) )
{
break;
}
action0__get_qp(a1);
*(_DWORD *)(a1 + 72) = 1;
}
return &exitcode_block_Any;
}

canonical_decompiled_code:
void *__fastcall func18(__int64 a1)
{
int v1; // eax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 72);
do
{
if ( !v1 )
goto LABEL_8;
}
while ( v1 != 1 );
while ( (unsigned int)func17(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 152LL)) > 0x3E
&& (unsigned int)func16(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) > 0x3E )
{
func13(a1);
*(_DWORD *)(a1 + 72) = 0;
LABEL_8:
if ( !(unsigned int)func17(*(_DWORD *)(*(_QWORD *)(a1 + 40) + 256LL))
|| !(unsigned int)func17(*(_DWORD *)(v3 + 48))
|| !(unsigned int)func16(*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL)) )
{
break;
}
action0__get_qp(a1);
*(_DWORD *)(a1 + 72) = 1;
}
return &exitcode_block_Any;
}

original_code:
static const int *RVC_decoder__texture_V__IQ_action_scheduler(AbstractActorInstance *pBase) {
  const int *result = exit_code_yield;
  ActorInstance_RVC_decoder__texture_V__IQ *thisActor=(ActorInstance_RVC_decoder__texture_V__IQ*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 1)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1)) {
            action0__get_qp(thisActor);
            thisActor->_fsmState = 1;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
      case 1:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[1].localInputPort)) >= 63)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 63)) {
            action1__ac(thisActor);
            thisActor->_fsmState = 0;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}

canonical_original_code:
static int *RVC_decoder__texture_V__IQ_action_scheduler(struct AbstractActorInstance *pBase) {
  int *result = exit_code_yield;
  struct ActorInstance_RVC_decoder__texture_V__IQ *thisActor = (ActorInstance_RVC_decoder__texture_V__IQ*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[2].localInputPort)) >= 1) && (pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 1)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1)) {
            action0__get_qp(thisActor);
            thisActor->_fsmState = 1;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
      case 1:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[1].localInputPort)) >= 63)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 63)) {
            action1__ac(thisActor);
            thisActor->_fsmState = 0;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}

user_defined_types: struct AbstractActorInstance { struct dllist_link_tag listEntry; struct ActorClass *actorClass; char *instanceName; int numInputPorts; struct InputPort *inputPort; int numOutputPorts; struct OutputPort *outputPort; int *(*action_scheduler)(struct AbstractActorInstance *); }


repo: Caltoopia/caltoopia-linux-runtime

decompiled_code:
int printout_config()
{
_DWORD *v0; // rbx
int v1; // ebp
__int64 v2; // rsi
const char *v3; // rdx
int result; // eax
_QWORD *v5; // rbx
int v6; // ebp
const char *v7; // rdx
const char *v8; // rsi
__int64 v9; // r9
const char *v10; // r8

printf("Schedule type: %s\n", schedule);
printf("Number of partition: %d\n", numPartitions);
puts("partition InstanceName");
if ( numInstances > 0 )
{
v0 = instanceAfinity;
v1 = 0;
do
{
v2 = (unsigned int)v0[2];
v3 = *(const char **)v0;
++v1;
v0 += 4;
printf("%d %s\n", v2, v3);
}
while ( numInstances > v1 );
}
puts("src src_port dst dst_port size");
result = numConnects;
if ( numConnects > 0 )
{
v5 = connects;
v6 = 0;
do
{
v7 = (const char *)v5[3];
v8 = (const char *)v5[2];
v9 = *((unsigned int *)v5 + 8);
v10 = (const char *)v5[1];
++v6;
v5 += 5;
result = printf("%s %s %s %s %d\n", v8, v7, (const char *)*(v5 - 5), v10, v9);
}
while ( numConnects > v6 );
}
return result;
}

canonical_decompiled_code:
int func3()
{
_DWORD *v0; // rbx
int v1; // ebp
__int64 v2; // rsi
const char *v3; // rdx
int result; // eax
_QWORD *v5; // rbx
int v6; // ebp
const char *v7; // rdx
const char *v8; // rsi
__int64 v9; // r9
const char *v10; // r8

printf("Schedule type: %s\n", schedule);
printf("Number of partition: %d\n", numPartitions);
puts("partition InstanceName");
if ( numInstances > 0 )
{
v0 = instanceAfinity;
v1 = 0;
do
{
v2 = (unsigned int)v0[2];
v3 = *(const char **)v0;
++v1;
v0 += 4;
printf("%d %s\n", v2, v3);
}
while ( numInstances > v1 );
}
puts("src src_port dst dst_port size");
result = numConnects;
if ( numConnects > 0 )
{
v5 = connects;
v6 = 0;
do
{
v7 = (const char *)v5[3];
v8 = (const char *)v5[2];
v9 = *((unsigned int *)v5 + 8);
v10 = (const char *)v5[1];
++v6;
v5 += 5;
result = printf("%s %s %s %s %d\n", v8, v7, (const char *)*(v5 - 5), v10, v9);
}
while ( numConnects > v6 );
}
return result;
}

original_code:
void printout_config()
{
  int i,j;
  printf("Schedule type:       %s\n",schedule.type);
  printf("Number of partition: %d\n",numPartitions);
  printf("partition InstanceName\n");
  for(i=0; i<_numInstances; i++)
    printf("%d  %s\n",instanceAfinity[i].affinity,
                      instanceAfinity[i].name);
  printf("src src_port dst dst_port size\n");
  for(i=0; i<_numConnects; i++)
    printf("%s %s %s %s %d\n",connects[i].src,
                              connects[i].src_port,
                              connects[i].dst,
                              connects[i].dst_port,
                              connects[i].size);
}

canonical_original_code:
void printout_config()
{
  int i; int j;
  printf("Schedule type:       %s\n",schedule.type);
  printf("Number of partition: %d\n",numPartitions);
  printf("partition InstanceName\n");
  for(i=0; i<_numInstances; i++)
    printf("%d  %s\n",instanceAfinity[i].affinity,
                      instanceAfinity[i].name);
  printf("src src_port dst dst_port size\n");
  for(i=0; i<_numConnects; i++)
    printf("%s %s %s %s %d\n",connects[i].src,
                              connects[i].src_port,
                              connects[i].dst,
                              connects[i].dst_port,
                              connects[i].size);
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall pinWrite_double(int *a1, double a2)
{
int v2; // eax
bool v3; // sf
__int64 result; // rax

v2 = *a1;
*(double *)(*((_QWORD *)a1 + 1) + 8LL * *a1) = a2;
v3 = v2 + 1 < 0;
result = (unsigned int)(v2 + 1);
*a1 = result;
if ( !v3 )
{
result = (unsigned int)-a1[4];
*a1 = result;
}
--a1[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, double a2)
{
int v2; // eax
bool v3; // sf
__int64 result; // rax

v2 = *a1;
*(double *)(*((_QWORD *)a1 + 1) + 8LL * *a1) = a2;
v3 = v2 + 1 < 0;
result = (unsigned int)(v2 + 1);
*a1 = result;
if ( !v3 )
{
result = (unsigned int)-a1[4];
*a1 = result;
}
--a1[1];
return result;
}

original_code:
static inline void pinWrite_double(LocalOutputPort *p, double token)
{
  ((void) (0));
  ((double*)p->buffer)[p->pos] = token;
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
}

canonical_original_code:
static inline void pinWrite_double(struct LocalOutputPort *p, double token)
{
  ((void) (0));
  ((double *)p->buffer)[p->pos] = token;
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
}

variable_types: struct LocalOutputPort { int pos; int available; void *buffer; unsigned int capacity; } *

variable_types: token double


decompiled_code:
__int64 __fastcall pinRead_double(_DWORD *a1)
{
bool v1; // sf
__int64 result; // rax

v1 = *a1 + 1 < 0;
result = (unsigned int)(*a1 + 1);
*a1 = result;
if ( !v1 )
{
result = (unsigned int)-a1[4];
*a1 = result;
}
--a1[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
bool v1; // sf
__int64 result; // rax

v1 = *a1 + 1 < 0;
result = (unsigned int)(*a1 + 1);
*a1 = result;
if ( !v1 )
{
result = (unsigned int)-a1[4];
*a1 = result;
}
--a1[1];
return result;
}

original_code:
static inline double pinRead_double(LocalInputPort *p)
{
  double result;
  ((void) (0));
  result = ((double*)p->buffer)[p->pos];
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
  return result;
}

canonical_original_code:
static inline double pinRead_double(struct LocalInputPort *p)
{
  double result;
  ((void) (0));
  result = ((double *)p->buffer)[p->pos];
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
  return result;
}

variable_types: struct LocalInputPort { int pos; int available; void *buffer; unsigned int capacity; } *

variable_types: result double

return_type: double


original_code:
static inline int32_t pinRead_int32_t(LocalInputPort *p)
{
  int32_t result;
  ((void) (0));
  result = ((int32_t*)p->buffer)[p->pos];
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
  return result;
}

canonical_original_code:
static inline int pinRead_int32_t(struct LocalInputPort *p)
{
  int result;
  ((void) (0));
  result = ((int *)p->buffer)[p->pos];
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
  return result;
}

user_defined_types: struct LocalInputPort { int pos; int available; void *buffer; unsigned int capacity; }


clearRect

decompiled_code:
__int64 __fastcall clearRect(unsigned int a1, int a2, int a3, int a4, __int64 a5)
{
unsigned int v6; // er14
unsigned int i; // ebx
__int64 v10; // rdi
__int64 result; // rax

if ( a2 < a4 )
{
v6 = a2;
do
{
for ( i = a1;
a3 > (int)i;
result = (*(__int64 (__fastcall **)(__int64, _QWORD, void *, __int64))(a5 + 48))(
v10,
v6,
&blackMacroBlock_0,
a5) )
{
v10 = i;
i += 16;
}
v6 += 16;
}
while ( a4 > (int)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, int a3, int a4, __int64 a5)
{
unsigned int v6; // er14
unsigned int i; // ebx
__int64 v10; // rdi
__int64 result; // rax

if ( a2 < a4 )
{
v6 = a2;
do
{
for ( i = a1;
a3 > (int)i;
result = (*(__int64 (__fastcall **)(__int64, _QWORD, void *, __int64))(a5 + 48))(
v10,
v6,
&blackMacroBlock_0,
a5) )
{
v10 = i;
i += 16;
}
v6 += 16;
}
while ( a4 > (int)v6 );
}
return result;
}

original_code:
static void clearRect(int x0, int y0,
                      int x1, int y1,
                      FrameBuffer *frameBuffer) {
  static yuv_sample_t blackMacroBlock[(6*64)];
  int x,y;
  for (y=y0; y<y1; y+=16)
    for (x=x0; x<x1; x+=16)
      frameBuffer->display_yuv(x,y,blackMacroBlock,frameBuffer);
}

canonical_original_code:
static void clearRect(int x0, int y0, int x1, int y1, struct FrameBuffer *frameBuffer) {
  static int blackMacroBlock[-1];
  int x; int y;
  for (y=y0; y<y1; y+=16)
    for (x=x0; x<x1; x+=16)
      frameBuffer->display_yuv(x,y,blackMacroBlock,frameBuffer);
}

variable_types: struct FrameBuffer { void *framePtr; int bytesPerPixel; int pixelsPerLine; int Roffset; int Rwidth; int Goffset; int Gwidth; int Boffset; int Bwidth; void *displaySpecific; void (*display_yuv)(int x, int y, int macroBlock[-1], struct FrameBuffer *format); void (*frame_done)(struct FrameBuffer *format); void (*free_display)(struct FrameBuffer *format); } *

variable_types:
blackMacroBlock
int [-1]

variable_types: y int


decompiled_code:
__int64 __fastcall pinWrite_int32_t(int *a1, int a2)
{
__int64 result; // rax

result = *((_QWORD *)a1 + 1);
*(_DWORD *)(result + 4LL * *a1) = a2;
if ( ++*a1 >= 0 )
{
result = (unsigned int)-a1[4];
*a1 = result;
}
--a1[1];
return result;
}

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

result = *((_QWORD *)a1 + 1);
*(_DWORD *)(result + 4LL * *a1) = a2;
if ( ++*a1 >= 0 )
{
result = (unsigned int)-a1[4];
*a1 = result;
}
--a1[1];
return result;
}

original_code:
static inline void pinWrite_int32_t(LocalOutputPort *p, int32_t token)
{
  ((void) (0));
  ((int32_t*)p->buffer)[p->pos] = token;
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
}

canonical_original_code:
static inline void pinWrite_int32_t(struct LocalOutputPort *p, int token)
{
  ((void) (0));
  ((int *)p->buffer)[p->pos] = token;
  p->pos++;
  if (p->pos >= 0) { p->pos = -(p->capacity); }
  p->available--;
}

variable_types: token int

user_defined_types: struct LocalOutputPort { int pos; int available; void *buffer; unsigned int capacity; }


repo: CaptJeffThomas/AiBerlinPuzzle

decompiled_code:
__int64 __fastcall closed_contains(__int64 a1)
{
_QWORD *v1; // rdx
__int64 v2; // rax
unsigned int v3; // er8
__int64 result; // rax

v1 = closed_head;
if ( closed_head )
{
while ( size_of_array > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
if ( *((_WORD *)v1 + v2 + 4) != *(_WORD *)(a1 + 2 * v2 + 16) )
++v3;
++v2;
}
while ( size_of_array != v2 );
if ( !v3 )
goto LABEL_10;
v1 = (_QWORD *)*v1;
if ( !v1 )
goto LABEL_9;
}
result = 0LL;
}
else
{
LABEL_9:
v3 = 1;
LABEL_10:
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_QWORD *v1; // rdx
__int64 v2; // rax
unsigned int v3; // er8
__int64 result; // rax

v1 = closed_head;
if ( closed_head )
{
while ( size_of_array > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
if ( *((_WORD *)v1 + v2 + 4) != *(_WORD *)(a1 + 2 * v2 + 16) )
++v3;
++v2;
}
while ( size_of_array != v2 );
if ( !v3 )
goto LABEL_10;
v1 = (_QWORD *)*v1;
if ( !v1 )
goto LABEL_9;
}
result = 0LL;
}
else
{
LABEL_9:
v3 = 1;
LABEL_10:
result = v3;
}
return result;
}

original_code:
int closed_contains(node * ptr){
  closed_node * temp = closed_head;
  int same_state;
  while (temp != ((void *)0)){
    same_state=0;
    for (int i=0; i<size_of_array; i++){
      if (temp->state[i]!=ptr->state[i]) same_state++;
    }
    if (same_state==0) return 0;
    temp = temp->next;
  }
  return 1;
}

canonical_original_code:
int closed_contains(struct a_node *ptr){
  struct closed_node *temp = closed_head;
  int same_state;
  while (temp != ((void *)0)){
    same_state=0;
    for (int i = 0; i<size_of_array; i++){
      if (temp->state[i]!=ptr->state[i]) same_state++;
    }
    if (same_state==0) return 0;
    temp = temp->next;
  }
  return 1;
}

variable_types: struct a_node { short f_val; short g_val; struct a_node *next; short state[]; } *

variable_types: struct closed_node { struct closed_node *next; short state[]; } *


decompiled_code:
__int64 __fastcall add_closed(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rax
__int64 v3; // rdx
void **v4; // rbp
int v5; // er12
__int64 v6; // rcx
_QWORD *v7; // rsi
int v8; // ebp
int v9; // er12
__int64 v10; // rcx

result = closed_contains(a1);
if ( (_DWORD)result )
{
v2 = closed_head;
v3 = size_of_array;
if ( !closed_head )
{
v8 = size_of_array + 4;
v9 = curr_mem;
closed_head = malloc(2 * (size_of_array + 4LL));
curr_mem = v9 + 2 * v8;
check_mem_usage();
v3 = size_of_array;
v2 = closed_head;
v10 = 0LL;
if ( size_of_array > 0 )
{
do
{
*((_WORD *)v2 + v10 + 4) = *(_WORD *)(a1 + 2 * v10 + 16);
++v10;
}
while ( v3 != v10 );
}
}
do
{
v4 = (void **)v2;
v2 = (_QWORD *)*v2;
}
while ( v2 );
v5 = v3 + 4;
*v4 = malloc(2 * (v3 + 4));
curr_mem += 2 * v5;
result = check_mem_usage();
v6 = size_of_array;
v7 = *v4;
if ( size_of_array > 0 )
{
result = 0LL;
do
{
*((_WORD *)v7 + result + 4) = *(_WORD *)(a1 + 2 * result + 16);
++result;
}
while ( v6 != result );
}
*v7 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rax
__int64 v3; // rdx
void **v4; // rbp
int v5; // er12
__int64 v6; // rcx
_QWORD *v7; // rsi
int v8; // ebp
int v9; // er12
__int64 v10; // rcx

result = func0(a1);
if ( (_DWORD)result )
{
v2 = closed_head;
v3 = size_of_array;
if ( !closed_head )
{
v8 = size_of_array + 4;
v9 = curr_mem;
closed_head = malloc(2 * (size_of_array + 4LL));
curr_mem = v9 + 2 * v8;
check_mem_usage();
v3 = size_of_array;
v2 = closed_head;
v10 = 0LL;
if ( size_of_array > 0 )
{
do
{
*((_WORD *)v2 + v10 + 4) = *(_WORD *)(a1 + 2 * v10 + 16);
++v10;
}
while ( v3 != v10 );
}
}
do
{
v4 = (void **)v2;
v2 = (_QWORD *)*v2;
}
while ( v2 );
v5 = v3 + 4;
*v4 = malloc(2 * (v3 + 4));
curr_mem += 2 * v5;
result = check_mem_usage();
v6 = size_of_array;
v7 = *v4;
if ( size_of_array > 0 )
{
result = 0LL;
do
{
*((_WORD *)v7 + result + 4) = *(_WORD *)(a1 + 2 * result + 16);
++result;
}
while ( v6 != result );
}
*v7 = 0LL;
}
return result;
}

original_code:
void add_closed(node * ptr){
  if (closed_contains(ptr)==0) return;
  if (closed_head == ((void *)0)){
    closed_head = malloc(sizeof(closed_node) + (size_of_array * sizeof(short int)));
    curr_mem += (sizeof(closed_node) + (size_of_array * sizeof(short int)));
    check_mem_usage();
    for (int i=0; i<size_of_array; i++){
      closed_head->state[i] = ptr->state[i];
    }
  }
  closed_node * temp = closed_head;
  while(temp->next!=((void *)0)){
    temp = temp->next;
  }
  temp->next = malloc(sizeof(closed_node) + (size_of_array * sizeof(short int)));
  curr_mem += (sizeof(closed_node) + (size_of_array * sizeof(short int)));
  check_mem_usage();
  for (int i=0; i<size_of_array; i++){
    temp->next->state[i] = ptr->state[i];
  }
  temp->next->next=((void *)0);
  return;
}

canonical_original_code:
void add_closed(struct a_node *ptr){
  if (closed_contains(ptr)==0) return;
  if (closed_head == ((void *)0)){
    closed_head = malloc(sizeof(closed_node) + (size_of_array * sizeof(short)));
    curr_mem += (sizeof(closed_node) + (size_of_array * sizeof(short)));
    check_mem_usage();
    for (int i = 0; i<size_of_array; i++){
      closed_head->state[i] = ptr->state[i];
    }
  }
  struct closed_node *temp = closed_head;
  while(temp->next!=((void *)0)){
    temp = temp->next;
  }
  temp->next = malloc(sizeof(closed_node) + (size_of_array * sizeof(short)));
  curr_mem += (sizeof(closed_node) + (size_of_array * sizeof(short)));
  check_mem_usage();
  for (int i = 0; i<size_of_array; i++){
    temp->next->state[i] = ptr->state[i];
  }
  temp->next->next=((void *)0);
  return;
}

user_defined_types: struct a_node { short f_val; short g_val; struct a_node *next; short state[]; }

user_defined_types: struct closed_node { struct closed_node *next; short state[]; }


decompiled_code:
void clear_closed()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = closed_head;
if ( closed_head )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
curr_mem -= 2 * size_of_array + 8;
free(v1);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func2()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = closed_head;
if ( closed_head )
{
do
{
v1 = v0;
v0 = (_QWORD *)*v0;
curr_mem -= 2 * size_of_array + 8;
free(v1);
}
while ( v0 );
}
}

original_code:
void clear_closed()
{
  closed_node *del = closed_head;
  closed_node *temp = ((void *)0);
  while(del != ((void *)0)){
    temp = del->next;
    curr_mem -= (sizeof(closed_node) + (size_of_array * sizeof(short int)));
    free(del);
    del = temp;
  }
  del = ((void *)0);
  temp = ((void *)0);
}

canonical_original_code:
void clear_closed()
{
  struct closed_node *del = closed_head;
  struct closed_node *temp = ((void *)0);
  while(del != ((void *)0)){
    temp = del->next;
    curr_mem -= (sizeof(closed_node) + (size_of_array * sizeof(short)));
    free(del);
    del = temp;
  }
  del = ((void *)0);
  temp = ((void *)0);
}


decompiled_code:
__int64 __fastcall push_to_fringe(void *src, __int16 a2)
{
__int64 v2; // rbx
_WORD *v3; // rax
_WORD *v4; // rbp
__int64 v5; // rbx
__int64 result; // rax
_WORD *v7; // rdi
void *v8; // rax

v2 = size_of_array + 8LL;
v3 = malloc(2 * v2);
if ( !v3 )
{
puts("ERROR: malloc failed ");
exit(1);
}
v4 = v3;
curr_mem += 2 * v2;
check_mem_usage();
v5 = size_of_array;
memset(v4, 0, 2LL * size_of_array + 16);
if ( (int)v5 > 0 )
memcpy(v4 + 8, src, 2 * v5);
if ( (unsigned int)closed_contains(v4) == 1 )
{
add_closed(v4);
v7 = v4 + 8;
if ( size_of_fringe )
{
v8 = fringe_head;
fringe_head = v4;
v4[1] = a2 + 1;
*((_QWORD *)v4 + 1) = v8;
result = heuristic(v7);
*v4 = result + a2 + 1;
}
else
{
*((_QWORD *)v4 + 1) = 0LL;
v4[1] = 0;
fringe_head = v4;
result = heuristic(v7);
*v4 = result;
}
++size_of_fringe;
}
else
{
free(v4);
result = (unsigned int)(2 * size_of_array + 16);
curr_mem -= result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src, __int16 a2)
{
__int64 v2; // rbx
_WORD *v3; // rax
_WORD *v4; // rbp
__int64 v5; // rbx
__int64 result; // rax
_WORD *v7; // rdi
void *v8; // rax

v2 = size_of_array + 8LL;
v3 = malloc(2 * v2);
if ( !v3 )
{
puts("ERROR: malloc failed ");
exit(1);
}
v4 = v3;
curr_mem += 2 * v2;
check_mem_usage();
v5 = size_of_array;
memset(v4, 0, 2LL * size_of_array + 16);
if ( (int)v5 > 0 )
memcpy(v4 + 8, src, 2 * v5);
if ( (unsigned int)closed_contains(v4) == 1 )
{
add_closed(v4);
v7 = v4 + 8;
if ( size_of_fringe )
{
v8 = fringe_head;
fringe_head = v4;
v4[1] = a2 + 1;
*((_QWORD *)v4 + 1) = v8;
result = heuristic(v7);
*v4 = result + a2 + 1;
}
else
{
*((_QWORD *)v4 + 1) = 0LL;
v4[1] = 0;
fringe_head = v4;
result = heuristic(v7);
*v4 = result;
}
++size_of_fringe;
}
else
{
free(v4);
result = (unsigned int)(2 * size_of_array + 16);
curr_mem -= result;
}
return result;
}

original_code:
void push_to_fringe(short int newState[],short int path_cost)
{
  node *new = ((void *)0);
  new = malloc(sizeof(node) + (size_of_array * sizeof(short int)));
  if(new == ((void *)0)){
    printf("ERROR: malloc failed \n");
    exit(1);
  }
  curr_mem += (sizeof(node) + (size_of_array * sizeof(short int)));
  check_mem_usage();
  memset(new,0,(sizeof(node) + (size_of_array * sizeof(short int))));
  for(int x = 0; x < size_of_array; x++){
      new->state[x] = newState[x];
  }
  int check = closed_contains(new);
  if(check == 1){
    add_closed(new);
    if(size_of_fringe == 0){
      new->next = ((void *)0);
      fringe_head = new;
      new->g_val = 0;
      new->f_val = new->g_val + heuristic(new->state);
    }
    else{
      new->next = fringe_head;
      fringe_head = new;
      new->g_val = path_cost + 1;
      new->f_val = new->g_val + heuristic(new->state);
    }
    size_of_fringe++;
  }
  else{
    free(new);
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short int)));
  }
}

canonical_original_code:
void push_to_fringe(short newState[], short path_cost)
{
  struct a_node *new = ((void *)0);
  new = malloc(sizeof(node) + (size_of_array * sizeof(short)));
  if(new == ((void *)0)){
    printf("ERROR: malloc failed \n");
    exit(1);
  }
  curr_mem += (sizeof(node) + (size_of_array * sizeof(short)));
  check_mem_usage();
  memset(new,0,(sizeof(node) + (size_of_array * sizeof(short))));
  for(int x = 0; x < size_of_array; x++){
      new->state[x] = newState[x];
  }
  int check = closed_contains(new);
  if(check == 1){
    add_closed(new);
    if(size_of_fringe == 0){
      new->next = ((void *)0);
      fringe_head = new;
      new->g_val = 0;
      new->f_val = new->g_val + heuristic(new->state);
    }
    else{
      new->next = fringe_head;
      fringe_head = new;
      new->g_val = path_cost + 1;
      new->f_val = new->g_val + heuristic(new->state);
    }
    size_of_fringe++;
  }
  else{
    free(new);
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short)));
  }
}

variable_types:
newState
short []

variable_types: x int

variable_types: check int


decompiled_code:
void __fastcall pop_from_fringe(__int64 a1)
{
void *v2; // rbp
void *v3; // rdi

v2 = fringe_head;
if ( size_of_fringe == 1 )
{
copy_node(fringe_head, a1);
curr_mem -= 2 * size_of_array + 16;
free(v2);
--size_of_fringe;
fringe_head = 0LL;
}
else
{
if ( size_of_fringe <= 1 )
{
puts("ERROR: fringe is empty can't dequeue");
exit(1);
}
v3 = fringe_head;
fringe_head = (void *)*((_QWORD *)fringe_head + 1);
copy_node(v3, a1);
curr_mem -= 2 * size_of_array + 16;
free(v2);
--size_of_fringe;
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
void *v2; // rbp
void *v3; // rdi

v2 = fringe_head;
if ( size_of_fringe == 1 )
{
copy_node(fringe_head, a1);
curr_mem -= 2 * size_of_array + 16;
free(v2);
--size_of_fringe;
fringe_head = 0LL;
}
else
{
if ( size_of_fringe <= 1 )
{
puts("ERROR: fringe is empty can't dequeue");
exit(1);
}
v3 = fringe_head;
fringe_head = (void *)*((_QWORD *)fringe_head + 1);
copy_node(v3, a1);
curr_mem -= 2 * size_of_array + 16;
free(v2);
--size_of_fringe;
}
}

original_code:
void pop_from_fringe(node *current)
{
  node *temp = fringe_head;
  if(size_of_fringe == 1){
    copy_node(temp,current);
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short int)));
    free(temp);
    temp = ((void *)0);
    fringe_head = ((void *)0);
  }
  else if(size_of_fringe > 1){
    fringe_head = temp->next;
    copy_node(temp,current);
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short int)));
    free(temp);
    temp = ((void *)0);
  }
  else{
    printf("ERROR: fringe is empty can't dequeue\n");
    exit(1);
  }
  size_of_fringe--;
}

canonical_original_code:
void pop_from_fringe(struct a_node *current)
{
  struct a_node *temp = fringe_head;
  if(size_of_fringe == 1){
    copy_node(temp,current);
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short)));
    free(temp);
    temp = ((void *)0);
    fringe_head = ((void *)0);
  }
  else if(size_of_fringe > 1){
    fringe_head = temp->next;
    copy_node(temp,current);
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short)));
    free(temp);
    temp = ((void *)0);
  }
  else{
    printf("ERROR: fringe is empty can't dequeue\n");
    exit(1);
  }
  size_of_fringe--;
}


decompiled_code:
void clear_fringe()
{
void *v0; // rbx
void *v1; // rdi

v0 = fringe_head;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 1);
curr_mem -= 2 * size_of_array + 16;
free(v1);
}
}

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

v0 = fringe_head;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 1);
curr_mem -= 2 * size_of_array + 16;
free(v1);
}
}

original_code:
void clear_fringe()
{
  node *del = fringe_head;
  node *temp = ((void *)0);
  while(del != ((void *)0)){
    temp = del->next;
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short int)));
    free(del);
    del = temp;
  }
  del = ((void *)0);
  temp = ((void *)0);
}

canonical_original_code:
void clear_fringe()
{
  struct a_node *del = fringe_head;
  struct a_node *temp = ((void *)0);
  while(del != ((void *)0)){
    temp = del->next;
    curr_mem -= (sizeof(node) + (size_of_array * sizeof(short)));
    free(del);
    del = temp;
  }
  del = ((void *)0);
  temp = ((void *)0);
}


repo: CaptainHayashi/playslave

decompiled_code:
__int64 __fastcall PaUtil_GetRingBufferReadAvailable(_QWORD *a1)
{
return a1[3] & (a1[1] - a1[2]);
}

original_code:
ring_buffer_size_t PaUtil_GetRingBufferReadAvailable( const PaUtilRingBuffer *rbuf )
{
    return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
}

canonical_original_code:
long PaUtil_GetRingBufferReadAvailable(struct PaUtilRingBuffer *rbuf)
{
    return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
}

variable_types: struct PaUtilRingBuffer { long bufferSize; long writeIndex; long readIndex; long bigMask; long smallMask; long elementSizeBytes; char *buffer; } *

return_type: long


decompiled_code:
__int64 __fastcall PaUtil_GetRingBufferWriteAvailable(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rcx

v1 = PaUtil_GetRingBufferReadAvailable(a1);
return v2 - v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rcx

v1 = func0(a1);
return v2 - v1;
}

original_code:
ring_buffer_size_t PaUtil_GetRingBufferWriteAvailable( const PaUtilRingBuffer *rbuf )
{
    return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
}

canonical_original_code:
long PaUtil_GetRingBufferWriteAvailable(struct PaUtilRingBuffer *rbuf)
{
    return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
}

user_defined_types: struct PaUtilRingBuffer { long bufferSize; long writeIndex; long readIndex; long bigMask; long smallMask; long elementSizeBytes; char *buffer; }


decompiled_code:
void __fastcall PaUtil_FlushRingBuffer(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
{
    rbuf->writeIndex = rbuf->readIndex = 0;
}

canonical_original_code:
void PaUtil_FlushRingBuffer(struct PaUtilRingBuffer *rbuf)
{
    rbuf->writeIndex = rbuf->readIndex = 0;
}


decompiled_code:
__int64 __fastcall PaUtil_InitializeRingBuffer(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r8
__int64 v5; // rdx
__int64 v6; // rax

if ( (a3 & (a3 - 1)) != 0 )
return -1LL;
*a1 = a3;
a1[6] = a4;
PaUtil_FlushRingBuffer((__int64)a1);
a1[3] = v5;
a1[4] = v6;
a1[5] = a2;
return v4;
}

original_code:
ring_buffer_size_t PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementSizeBytes, ring_buffer_size_t elementCount, void *dataPtr )
{
    if( ((elementCount-1) & elementCount) != 0) return -1;
    rbuf->bufferSize = elementCount;
    rbuf->buffer = (char *)dataPtr;
    PaUtil_FlushRingBuffer( rbuf );
    rbuf->bigMask = (elementCount*2)-1;
    rbuf->smallMask = (elementCount)-1;
    rbuf->elementSizeBytes = elementSizeBytes;
    return 0;
}

canonical_original_code:
long PaUtil_InitializeRingBuffer(struct PaUtilRingBuffer *rbuf, long elementSizeBytes, long elementCount, void *dataPtr)
{
    if( ((elementCount-1) & elementCount) != 0) return -1;
    rbuf->bufferSize = elementCount;
    rbuf->buffer = (char *)dataPtr;
    PaUtil_FlushRingBuffer( rbuf );
    rbuf->bigMask = (elementCount*2)-1;
    rbuf->smallMask = (elementCount)-1;
    rbuf->elementSizeBytes = elementSizeBytes;
    return 0;
}

variable_types: elementSizeBytes long

variable_types: elementCount long

variable_types:
dataPtr
void *


original_code:
ring_buffer_size_t PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount,
                                       void **dataPtr1, ring_buffer_size_t *sizePtr1,
                                       void **dataPtr2, ring_buffer_size_t *sizePtr2 )
{
    ring_buffer_size_t index;
    ring_buffer_size_t available = PaUtil_GetRingBufferWriteAvailable( rbuf );
    if( elementCount > available ) elementCount = available;
    index = rbuf->writeIndex & rbuf->smallMask;
    if( (index + elementCount) > rbuf->bufferSize )
    {
        ring_buffer_size_t firstHalf = rbuf->bufferSize - index;
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = firstHalf;
        *dataPtr2 = &rbuf->buffer[0];
        *sizePtr2 = elementCount - firstHalf;
    }
    else
    {
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = elementCount;
        *dataPtr2 = ((void *)0);
        *sizePtr2 = 0;
    }
    if( available )
        __sync_synchronize();
    return elementCount;
}

canonical_original_code:
long PaUtil_GetRingBufferWriteRegions(struct PaUtilRingBuffer *rbuf, long elementCount, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
    long index;
    long available = PaUtil_GetRingBufferWriteAvailable( rbuf );
    if( elementCount > available ) elementCount = available;
    index = rbuf->writeIndex & rbuf->smallMask;
    if( (index + elementCount) > rbuf->bufferSize )
    {
        long firstHalf = rbuf->bufferSize - index;
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = firstHalf;
        *dataPtr2 = &rbuf->buffer[0];
        *sizePtr2 = elementCount - firstHalf;
    }
    else
    {
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = elementCount;
        *dataPtr2 = ((void *)0);
        *sizePtr2 = 0;
    }
    if( available )
        __sync_synchronize();
    return elementCount;
}

variable_types: index long

variable_types: available long

variable_types: firstHalf long


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

_mm_mfence();
result = *(_QWORD *)(a1 + 24) & (a2 + *(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

_mm_mfence();
result = *(_QWORD *)(a1 + 24) & (a2 + *(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount )
{
    __sync_synchronize();
    return rbuf->writeIndex = (rbuf->writeIndex + elementCount) & rbuf->bigMask;
}

canonical_original_code:
long PaUtil_AdvanceRingBufferWriteIndex(struct PaUtilRingBuffer *rbuf, long elementCount)
{
    __sync_synchronize();
    return rbuf->writeIndex = (rbuf->writeIndex + elementCount) & rbuf->bigMask;
}


original_code:
ring_buffer_size_t PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount,
                                void **dataPtr1, ring_buffer_size_t *sizePtr1,
                                void **dataPtr2, ring_buffer_size_t *sizePtr2 )
{
    ring_buffer_size_t index;
    ring_buffer_size_t available = PaUtil_GetRingBufferReadAvailable( rbuf );
    if( elementCount > available ) elementCount = available;
    index = rbuf->readIndex & rbuf->smallMask;
    if( (index + elementCount) > rbuf->bufferSize )
    {
        ring_buffer_size_t firstHalf = rbuf->bufferSize - index;
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = firstHalf;
        *dataPtr2 = &rbuf->buffer[0];
        *sizePtr2 = elementCount - firstHalf;
    }
    else
    {
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = elementCount;
        *dataPtr2 = ((void *)0);
        *sizePtr2 = 0;
    }
    if( available )
        __sync_synchronize();
    return elementCount;
}

canonical_original_code:
long PaUtil_GetRingBufferReadRegions(struct PaUtilRingBuffer *rbuf, long elementCount, void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
    long index;
    long available = PaUtil_GetRingBufferReadAvailable( rbuf );
    if( elementCount > available ) elementCount = available;
    index = rbuf->readIndex & rbuf->smallMask;
    if( (index + elementCount) > rbuf->bufferSize )
    {
        long firstHalf = rbuf->bufferSize - index;
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = firstHalf;
        *dataPtr2 = &rbuf->buffer[0];
        *sizePtr2 = elementCount - firstHalf;
    }
    else
    {
        *dataPtr1 = &rbuf->buffer[index*rbuf->elementSizeBytes];
        *sizePtr1 = elementCount;
        *dataPtr2 = ((void *)0);
        *sizePtr2 = 0;
    }
    if( available )
        __sync_synchronize();
    return elementCount;
}


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

_mm_mfence();
result = *(_QWORD *)(a1 + 24) & (a2 + *(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

_mm_mfence();
result = *(_QWORD *)(a1 + 24) & (a2 + *(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, ring_buffer_size_t elementCount )
{
    __sync_synchronize();
    return rbuf->readIndex = (rbuf->readIndex + elementCount) & rbuf->bigMask;
}

canonical_original_code:
long PaUtil_AdvanceRingBufferReadIndex(struct PaUtilRingBuffer *rbuf, long elementCount)
{
    __sync_synchronize();
    return rbuf->readIndex = (rbuf->readIndex + elementCount) & rbuf->bigMask;
}


decompiled_code:
__int64 __fastcall PaUtil_WriteRingBuffer(__int64 *a1, char *a2, __int64 a3)
{
__int64 v3; // rax
size_t v4; // rdx
__int64 v5; // r12
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+8h] [rbp-30h]
void *dest; // [rsp+10h] [rbp-28h] BYREF
void *v10; // [rsp+18h] [rbp-20h] BYREF

v3 = PaUtil_GetRingBufferWriteRegions(a1, a3, (__int64)&dest, &v7, &v10);
v4 = v7 * a1[5];
v5 = v3;
if ( v8 <= 0 )
{
memcpy(dest, a2, v4);
}
else
{
memcpy(dest, a2, v4);
memcpy(v10, &a2[v7 * a1[5]], a1[5] * v8);
}
PaUtil_AdvanceRingBufferWriteIndex((__int64)a1, v5);
return v5;
}

original_code:
ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount )
{
    ring_buffer_size_t size1, size2, numWritten;
    void *data1, *data2;
    numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );
    if( size2 > 0 )
    {
        memcpy( data1, data, size1*rbuf->elementSizeBytes );
        data = ((char *)data) + size1*rbuf->elementSizeBytes;
        memcpy( data2, data, size2*rbuf->elementSizeBytes );
    }
    else
    {
        memcpy( data1, data, size1*rbuf->elementSizeBytes );
    }
    PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
    return numWritten;
}

canonical_original_code:
long PaUtil_WriteRingBuffer(struct PaUtilRingBuffer *rbuf, void *data, long elementCount)
{
    long size1; long size2; long numWritten;
    void *data1; void *data2;
    numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );
    if( size2 > 0 )
    {
        memcpy( data1, data, size1*rbuf->elementSizeBytes );
        data = ((char *)data) + size1*rbuf->elementSizeBytes;
        memcpy( data2, data, size2*rbuf->elementSizeBytes );
    }
    else
    {
        memcpy( data1, data, size1*rbuf->elementSizeBytes );
    }
    PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
    return numWritten;
}

variable_types:
data
void *

variable_types: numWritten long


decompiled_code:
__int64 __fastcall PaUtil_ReadRingBuffer(_QWORD *a1, char *a2, __int64 a3)
{
__int64 v3; // r12
__int64 v5; // [rsp+0h] [rbp-48h]
__int64 v6; // [rsp+8h] [rbp-40h]
void *src; // [rsp+10h] [rbp-38h]
void *v8; // [rsp+18h] [rbp-30h]

v3 = PaUtil_GetRingBufferReadRegions(a1, a3);
memcpy(a2, src, v5 * a1[5]);
if ( v6 > 0 )
memcpy(&a2[a1[5] * v5], v8, v6 * a1[5]);
PaUtil_AdvanceRingBufferReadIndex((__int64)a1, v3);
return v3;
}

original_code:
ring_buffer_size_t PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, ring_buffer_size_t elementCount )
{
    ring_buffer_size_t size1, size2, numRead;
    void *data1, *data2;
    numRead = PaUtil_GetRingBufferReadRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );
    if( size2 > 0 )
    {
        memcpy( data, data1, size1*rbuf->elementSizeBytes );
        data = ((char *)data) + size1*rbuf->elementSizeBytes;
        memcpy( data, data2, size2*rbuf->elementSizeBytes );
    }
    else
    {
        memcpy( data, data1, size1*rbuf->elementSizeBytes );
    }
    PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead );
    return numRead;
}

canonical_original_code:
long PaUtil_ReadRingBuffer(struct PaUtilRingBuffer *rbuf, void *data, long elementCount)
{
    long size1; long size2; long numRead;
    void *data1; void *data2;
    numRead = PaUtil_GetRingBufferReadRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );
    if( size2 > 0 )
    {
        memcpy( data, data1, size1*rbuf->elementSizeBytes );
        data = ((char *)data) + size1*rbuf->elementSizeBytes;
        memcpy( data, data2, size2*rbuf->elementSizeBytes );
    }
    else
    {
        memcpy( data, data1, size1*rbuf->elementSizeBytes );
    }
    PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead );
    return numRead;
}

variable_types: numRead long


dequeue

repo: Cassidy/mks

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

if ( (_UNKNOWN *)qword_2E8 != &kbd )
{
result = qword_2E0;
if ( qword_2E8 == qword_2E0 )
{
qword_2E8 = (__int64)&kbd;
qword_2E0 = (__int64)&kbd;
}
else
{
result = ++qword_2E0;
}
}
return result;
}

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

if ( (_UNKNOWN *)qword_2E8 != &kbd )
{
result = qword_2E0;
if ( qword_2E8 == qword_2E0 )
{
qword_2E8 = (__int64)&kbd;
qword_2E0 = (__int64)&kbd;
}
else
{
result = ++qword_2E0;
}
}
return result;
}

original_code:
static void dequeue(void) {
  if (kbd.tail == kbd.buf)
    return;
  if (kbd.head == kbd.tail && kbd.head != kbd.buf) {
    kbd.head = kbd.tail = kbd.buf;
    return;
  }
  kbd.head++;
}

canonical_original_code:
static void dequeue() {
  if (kbd.tail == kbd.buf)
    return;
  if (kbd.head == kbd.tail && kbd.head != kbd.buf) {
    kbd.head = kbd.tail = kbd.buf;
    return;
  }
  kbd.head++;
}


headqueue

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

if ( qword_2E8 == qword_2E0 )
result = 0LL;
else
result = *(unsigned __int8 *)qword_2E0;
return result;
}

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

if ( qword_2E8 == qword_2E0 )
result = 0LL;
else
result = *(unsigned __int8 *)qword_2E0;
return result;
}

original_code:
static unsigned char headqueue(void) {
  if (kbd.tail == kbd.head)
    return 0;
  return *kbd.head;
}

canonical_original_code:
static unsigned char headqueue() {
  if (kbd.tail == kbd.head)
    return 0;
  return *kbd.head;
}

return_type: unsigned char


decompiled_code:
void keyboard_init()
{
qword_2E8 = (__int64)&kbd;
qword_2E0 = (__int64)&kbd;
}

canonical_decompiled_code:
void func2()
{
qword_2E8 = (__int64)&kbd;
qword_2E0 = (__int64)&kbd;
}

original_code:
void keyboard_init(void) {
  kbd.head = kbd.tail = kbd.buf;
}

canonical_original_code:
void keyboard_init() {
  kbd.head = kbd.tail = kbd.buf;
}


decompiled_code:
__int64 do_intr_keyboard()
{
char v0; // al
int v1; // edi
char v2; // al
__int64 result; // rax
int v4; // edi

v0 = __inbyte(0x60u);
v1 = (unsigned __int8)v0;
if ( v0 < 0 )
{
v4 = v0 & 0x7F;
if ( v4 == 42 || v4 == 54 )
dequeue();
}
else if ( v0 == 42 || v0 == 54 )
{
enqueue_isra_0(v0);
}
else
{
v2 = headqueue();
printchar((unsigned __int8)keymap[3 * v1 + (v2 == 42 || v2 == 54)]);
}
result = 32LL;
__outbyte(0x20u, 0x20u);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
char v0; // al
int v1; // edi
char v2; // al
__int64 result; // rax
int v4; // edi

v0 = __inbyte(0x60u);
v1 = (unsigned __int8)v0;
if ( v0 < 0 )
{
v4 = v0 & 0x7F;
if ( v4 == 42 || v4 == 54 )
func0();
}
else if ( v0 == 42 || v0 == 54 )
{
enqueue_isra_0(v0);
}
else
{
v2 = func1();
printchar((unsigned __int8)keymap[3 * v1 + (v2 == 42 || v2 == 54)]);
}
result = 32LL;
__outbyte(0x20u, 0x20u);
return result;
}

original_code:
void do_intr_keyboard(void) {
  unsigned char keycode;
  unsigned char keymapcol = 0;
  unsigned char scan_code = ({ unsigned char _v; __asm__ volatile("inb %%dx, %%al":"=a"(_v):"d"(0x60)); _v; });
  if ((scan_code & 0x80) == 0) {
    if ((scan_code != 0x2A) && (scan_code != 0x36)) {
      if ((keycode = headqueue()) == 0x2A || keycode == 0x36)
        keymapcol = 1;
      printchar(keymap[scan_code*3 +keymapcol]);
    } else if ((scan_code == 0x2A) || (scan_code == 0x36)) {
      enqueue(scan_code);
    } else
                      ;
  } else if ((scan_code & 0x80) == 0x80) {
    if (((scan_code & 0x7F) == 0x2A) || ((scan_code & 0x7F) == 0x36))
      dequeue();
  } else
                    ;
  __asm__("outb %%al, %%dx\n" "\tjmp 1f\n" "1:\tjmp 1f\n" "1:"::"a"(0x20), "d"(0x20));
}

canonical_original_code:
void do_intr_keyboard() {
  unsigned char keycode;
  unsigned char keymapcol = 0;
  unsigned char scan_code = ({ unsigned char _v; __asm__ volatile("inb %%dx, %%al":"=a"(_v):"d"(0x60)); _v; });
  if ((scan_code & 0x80) == 0) {
    if ((scan_code != 0x2A) && (scan_code != 0x36)) {
      if ((keycode = headqueue()) == 0x2A || keycode == 0x36)
        keymapcol = 1;
      printchar(keymap[scan_code*3 +keymapcol]);
    } else if ((scan_code == 0x2A) || (scan_code == 0x36)) {
      enqueue(scan_code);
    } else
                      ;
  } else if ((scan_code & 0x80) == 0x80) {
    if (((scan_code & 0x7F) == 0x2A) || ((scan_code & 0x7F) == 0x36))
      dequeue();
  } else
                    ;
  __asm__("outb %%al, %%dx\n" "\tjmp 1f\n" "1:\tjmp 1f\n" "1:"::"a"(0x20), "d"(0x20));
}

variable_types:
keycode
unsigned char

variable_types:
keymapcol
unsigned char


decompiled_code:
__int64 update_cursor()
{
__int16 v0; // cx
__int64 result; // rax

v0 = 2 * (x + 80 * y - 0x4000);
__outbyte(0x3D4u, 0xEu);
__outbyte(0x3D5u, HIBYTE(v0));
__outbyte(0x3D4u, 0xFu);
result = (unsigned __int8)v0;
__outbyte(0x3D5u, v0);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int16 v0; // cx
__int64 result; // rax

v0 = 2 * (x + 80 * y - 0x4000);
__outbyte(0x3D4u, 0xEu);
__outbyte(0x3D5u, HIBYTE(v0));
__outbyte(0x3D4u, 0xFu);
result = (unsigned __int8)v0;
__outbyte(0x3D5u, v0);
return result;
}


println

original_code:
void println(void)
{
  char * ph = 0xb8000 + video_num_columns * 2 * y + x * 2;
  char * pe;
  x = 0;
  y++;
  if(y < 25)
    pe = 0xb8000 + video_num_columns * 2 * (y + 1);
  else {
    char * ph1 = 0xb8000;
    char * pe1 = 0xb8000 + video_num_columns * 2;
    while(ph1 < pe1) {
   *ph1++ = 32;
   *ph1++ = attr;
 }
    pe = 0xb8000 + video_num_columns * 2 * y;
    y = 0;
  }
  while(ph < pe) {
    *ph++ = 32;
    *ph++ = attr;
  }
}

canonical_original_code:
void println()
{
  char *ph = 0xb8000 + video_num_columns * 2 * y + x * 2;
  char *pe;
  x = 0;
  y++;
  if(y < 25)
    pe = 0xb8000 + video_num_columns * 2 * (y + 1);
  else {
    char *ph1 = 0xb8000;
    char *pe1 = 0xb8000 + video_num_columns * 2;
    while(ph1 < pe1) {
   *ph1++ = 32;
   *ph1++ = attr;
 }
    pe = 0xb8000 + video_num_columns * 2 * y;
    y = 0;
  }
  while(ph < pe) {
    *ph++ = 32;
    *ph++ = attr;
  }
}

variable_types:
ph
char *

variable_types:
pe
char *


printchar

decompiled_code:
unsigned __int64 __fastcall printchar(char a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
_BYTE *v3; // rcx

result = y;
v2 = x + 1;
v3 = (_BYTE *)(2 * (x + 80 * y + 376832));
*v3 = a1;
v3[1] = 7;
if ( v2 > 0x4F )
{
x = 0LL;
y = ++result;
}
else
{
x = v2;
}
if ( result > 0x18 )
{
y = 1LL;
x = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
_BYTE *v3; // rcx

result = y;
v2 = x + 1;
v3 = (_BYTE *)(2 * (x + 80 * y + 376832));
*v3 = a1;
v3[1] = 7;
if ( v2 > 0x4F )
{
x = 0LL;
y = ++result;
}
else
{
x = v2;
}
if ( result > 0x18 )
{
y = 1LL;
x = 0LL;
}
return result;
}

original_code:
void printchar(unsigned char c) {
  pos = 0xb8000 + (video_num_columns * y + x) * 2;
  (*(char *)pos) = c;
  (*(char *)(pos + 1)) = attr;
  ++x;
  if (x >= 80) {
    x = 0;
    ++y;
  }
  if (y >= 25) {
    y = 1;
    x = 0;
  }
}

variable_types:
c
unsigned char


printk

decompiled_code:
__int64 printk()
{
unsigned int v0; // er8

prints();
println();
return v0;
}

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

func6();
func1();
return v0;
}

original_code:
int printk(const char *fmt)
{
  int a;
  a = prints(fmt);
  println();
  return a;
}

canonical_original_code:
int printk(char *fmt)
{
  int a;
  a = prints(fmt);
  println();
  return a;
}

variable_types:
fmt
char *

variable_types: a int


decompiled_code:
__int64 con_init()
{
__int64 v0; // rax
_WORD *v1; // rdx

v0 = 753664LL;
x = 0LL;
y = 0LL;
do
{
v1 = (_WORD *)v0;
v0 += 2LL;
*v1 = 1824;
}
while ( v1 != (_WORD *)757662 );
printk(" MKS -- Micro Kernel for Study ");
return update_cursor();
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
_WORD *v1; // rdx

v0 = 753664LL;
x = 0LL;
y = 0LL;
do
{
v1 = (_WORD *)v0;
v0 += 2LL;
*v1 = 1824;
}
while ( v1 != (_WORD *)757662 );
func3(" MKS -- Micro Kernel for Study ");
return func0();
}

original_code:
void con_init()
{
  x = 0;
  y = 0;
  char * ph = 0xb8000;
  char * pe = 0xb8000 + 4000;
  while(ph < pe) {
    *ph++ = 32;
    *ph++ = attr;
  }
  printk("                  MKS -- Micro Kernel for Study                   ");
  update_cursor();
}

canonical_original_code:
void con_init()
{
  x = 0;
  y = 0;
  char *ph = 0xb8000;
  char *pe = 0xb8000 + 4000;
  while(ph < pe) {
    *ph++ = 32;
    *ph++ = attr;
  }
  printk("                  MKS -- Micro Kernel for Study                   ");
  update_cursor();
}


decompiled_code:
__int64 __fastcall write_char(char a1)
{
unsigned __int64 v1; // rsi
unsigned __int64 v2; // rcx
__int64 result; // rax

v1 = y;
result = 2 * (x + 80 * y + 376832);
v2 = ++x;
*(_BYTE *)result = a1;
*(_BYTE *)(result + 1) = 7;
if ( v2 > 0x4F )
{
v1 += v2 / 0x50;
result = 80 * (v2 / 0x50);
y = v1;
x = v2 % 0x50;
}
if ( v1 > 0x18 )
{
con_init();
result = 25 * (y / 0x19uLL);
y %= 0x19uLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
unsigned __int64 v1; // rsi
unsigned __int64 v2; // rcx
__int64 result; // rax

v1 = y;
result = 2 * (x + 80 * y + 376832);
v2 = ++x;
*(_BYTE *)result = a1;
*(_BYTE *)(result + 1) = 7;
if ( v2 > 0x4F )
{
v1 += v2 / 0x50;
result = 80 * (v2 / 0x50);
y = v1;
x = v2 % 0x50;
}
if ( v1 > 0x18 )
{
func4();
result = 25 * (y / 0x19uLL);
y %= 0x19uLL;
}
return result;
}

original_code:
static inline void write_char(char ch)
{
  pos = 0xb8000 + video_num_columns * 2 * y + x * 2;
  *((char *)pos) = ch;
  *((char *)(pos+1)) = attr;
  x++;
  if(x >= 80) {
      y += x / 80;
      x = x % 80;
  }
  if(y >= 25) {
    con_init();
    y = y % 25;
  }
}

variable_types: ch char


prints

decompiled_code:
__int64 __fastcall prints(char *a1)
{
unsigned int v1; // er12
char *v2; // rbx
char i; // di

v1 = 0;
v2 = a1;
for ( i = *a1; i; ++v1 )
{
write_char(i);
i = *++v2;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
unsigned int v1; // er12
char *v2; // rbx
char i; // di

v1 = 0;
v2 = a1;
for ( i = *a1; i; ++v1 )
{
func5(i);
i = *++v2;
}
return v1;
}

original_code:
int prints(const char *fmt)
{
  int i;
  char * ps = fmt;
  for(i=0; *ps!='\0'; i++) {
    write_char(*ps);
    ps++;
  }
  return i;
}

canonical_original_code:
int prints(char *fmt)
{
  int i;
  char *ps = fmt;
  for(i=0; *ps!='\0'; i++) {
    write_char(*ps);
    ps++;
  }
  return i;
}

variable_types: i int

variable_types:
ps
char *


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

if ( a1 )
{
print_charina(a1 / 0xA);
result = write_char((unsigned __int8)(a1 % 0xA) + 48);
}
return result;
}

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

if ( a1 )
{
func7(a1 / 0xA);
result = func5((unsigned __int8)(a1 % 0xA) + 48);
}
return result;
}

original_code:
static inline void print_charina(unsigned long a)
{
  unsigned long b, c;
  if(a == 0)
    return;
  b = a / 10;
  c = b * 10;
  c = a - c;
  print_charina(b);
  c = c + 48;
  write_char((char)c);
}

canonical_original_code:
static inline void print_charina(unsigned long a)
{
  unsigned long b; unsigned long c;
  if(a == 0)
    return;
  b = a / 10;
  c = b * 10;
  c = a - c;
  print_charina(b);
  c = c + 48;
  write_char((char)c);
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
c
unsigned long


printa

decompiled_code:
__int64 __fastcall printa(unsigned __int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebx
__int64 result; // rax

LODWORD(v1) = a1;
if ( a1 >> 31 == 1 )
{
v1 = -(__int64)a1;
write_char(45);
}
v2 = v1 & 0x7FFFFFFF;
if ( v2 )
result = print_charina(v2);
else
result = write_char(48);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebx
__int64 result; // rax

LODWORD(v1) = a1;
if ( a1 >> 31 == 1 )
{
v1 = -(__int64)a1;
func5(45);
}
v2 = v1 & 0x7FFFFFFF;
if ( v2 )
result = func7(v2);
else
result = func5(48);
return result;
}

original_code:
void printa(const long a)
{
  unsigned long b = (unsigned long)a;
  unsigned long c = b >> 31;
  if(c == 1)
    {
      write_char('-');
      b = ~(b-1);
    }
  c = b & 0x7FFFFFFF;
  if(c == 0)
      write_char(48);
  else
    print_charina(c);
}

canonical_original_code:
void printa(long a)
{
  unsigned long b = (unsigned long)a;
  unsigned long c = b >> 31;
  if(c == 1)
    {
      write_char('-');
      b = ~(b-1);
    }
  c = b & 0x7FFFFFFF;
  if(c == 0)
      write_char(48);
  else
    print_charina(c);
}

variable_types: a long


printbin

decompiled_code:
__int64 __fastcall printbin(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = 32;
do
{
while ( (int)a1 < 0 )
{
a1 *= 2LL;
result = write_char(49);
if ( !--v1 )
return result;
}
a1 *= 2LL;
result = write_char(48);
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = 32;
do
{
while ( (int)a1 < 0 )
{
a1 *= 2LL;
result = func5(49);
if ( !--v1 )
return result;
}
a1 *= 2LL;
result = func5(48);
--v1;
}
while ( v1 );
return result;
}

original_code:
void printbin(const unsigned long el)
{
  int i;
  unsigned long ef = el;
  for(i=32; i>0; i--) {
    if(ef & 0x80000000)
      write_char(49);
    else
      write_char(48);
    ef = ef << 1;
  }
}

canonical_original_code:
void printbin(unsigned long el)
{
  int i;
  unsigned long ef = el;
  for(i=32; i>0; i--) {
    if(ef & 0x80000000)
      write_char(49);
    else
      write_char(48);
    ef = ef << 1;
  }
}

variable_types:
el
unsigned long

variable_types:
ef
unsigned long


printhex

decompiled_code:
__int64 __fastcall printhex(unsigned __int8 a1)
{
char v1; // bp
char v2; // dl
unsigned __int8 v3; // al
char v4; // di

v1 = __ROL1__(a1, 4);
write_char(48);
write_char(120);
v2 = (a1 >> 4) + 48;
if ( (unsigned __int8)(a1 >> 4) > 9u )
v2 = (a1 >> 4) + 55;
write_char(v2);
v3 = __ROL1__(v1, 4) & 0xF;
v4 = v3 + 55;
if ( v3 <= 9u )
v4 = v3 + 48;
return write_char(v4);
}

original_code:
void printhex(unsigned char c) {
  int i;
  unsigned char tmp;
  write_char(48);
  write_char(120);
  for (i = 0; i < 2; ++i) {
    c = (c << 4) | (c >> 4);
    tmp = c & 0x0F;
    if (tmp > 9)
      tmp = tmp - 10 + 'A';
    else if (0 <= tmp && tmp <= 9)
      tmp = tmp + '0';
    else
      printk("error");
    write_char(tmp);
  }
}

variable_types:
tmp
unsigned char


decompiled_code:
__int64 *msg_init()
{
__int64 *result; // rax

small_send_tail = 0LL;
result = &msg_hardware;
small_send_head = 0LL;
small_receive_tail = 0LL;
small_receive_head = 0LL;
big_send_tail = 0LL;
big_send_head = 0LL;
big_receive_tail = 0LL;
big_receive_head = 0LL;
do
{
*result = 0LL;
result += 4;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
*(result - 1) = 0LL;
}
while ( result != &msg_hardware + 4096 );
return result;
}

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

small_send_tail = 0LL;
result = &msg_hardware;
small_send_head = 0LL;
small_receive_tail = 0LL;
small_receive_head = 0LL;
big_send_tail = 0LL;
big_send_head = 0LL;
big_receive_tail = 0LL;
big_receive_head = 0LL;
do
{
*result = 0LL;
result += 4;
*(result - 3) = 0LL;
*(result - 2) = 0LL;
*(result - 1) = 0LL;
}
while ( result != &msg_hardware + 4096 );
return result;
}

original_code:
void msg_init(void)
{
  long i;
  small_send_head = small_send_tail = ((void *) 0);
  small_receive_head = small_receive_tail = ((void *) 0);
  big_send_head = big_send_tail = ((void *) 0);
  big_receive_head = big_receive_tail = ((void *) 0);
  for(i=0; i<1024; i++) {
    msg_hardware[i].src = 0;
    msg_hardware[i].dest = 0;
    msg_hardware[i].msg = 0;
    msg_hardware[i].next = ((void *) 0);
  }
}

canonical_original_code:
void msg_init()
{
  long i;
  small_send_head = small_send_tail = ((void *) 0);
  small_receive_head = small_receive_tail = ((void *) 0);
  big_send_head = big_send_tail = ((void *) 0);
  big_receive_head = big_receive_tail = ((void *) 0);
  for(i=0; i<1024; i++) {
    msg_hardware[i].src = 0;
    msg_hardware[i].dest = 0;
    msg_hardware[i].msg = 0;
    msg_hardware[i].next = ((void *) 0);
  }
}

variable_types: i long


original_code:
long small_send(long src, long * dest, long * msg)
{
  struct msg_struct * msg_p = small_receive_head;
  struct msg_struct * msg_t = ((void *) 0);
  if((src<0 && src!=-2) || src>=64)
    return -1;
  if(*dest < 0 || *dest >= 64)
    return -1;
  while(msg_p)
    {
      if(*dest==msg_p->dest &&
  (src==*((long *)(msg_p->src)) || *((long *)(msg_p->src))==-1))
 break;
      msg_t = msg_p;
      msg_p = msg_p->next;
    }
  if(msg_p)
    {
      *((long *)(msg_p->msg)) = *msg;
      if(*((long *)(msg_p->src)) == -1)
 *((long *)(msg_p->src)) = src;
      if(!msg_t)
        small_receive_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        small_receive_tail = msg_t;
      proc[msg_p->dest]->state = 0;
      schedule();
      return 1;
    }
  msg_p = small_send_head;
  while(msg_p)
    {
      if(*dest==msg_p->src && src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_send_head;
  while(msg_p)
    {
      if(*dest==msg_p->src && src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_receive_head;
  while(msg_p)
    {
      if(*dest==msg_p->dest && src==*((long *)(msg_p->src)))
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = ((void *) 0);
  if(src == -2)
    {
      int i;
      for(i=0; i<1024; i++)
        if(msg_hardware[i].src != -2)
          {
            msg_p = &msg_hardware[i];
            break;
          }
      if(!msg_p)
        return -1;
    }
  else
    {
      struct msg_struct new_msg;
      msg_p = &new_msg;
    }
  msg_p->src = src;
  msg_p->dest = *dest;
  msg_p->msg = *msg;
  msg_p->next = ((void *) 0);
  if(!small_send_head)
    small_send_head = small_send_tail = msg_p;
  else
    {
      small_send_tail->next = msg_p;
      small_send_tail = msg_p;
    }
  if(src != -2)
    proc[src]->state = 1;
  schedule();
  return 1;
}

canonical_original_code:
long small_send(long src, long *dest, long *msg)
{
  struct msg_struct *msg_p = small_receive_head;
  struct msg_struct *msg_t = ((void *) 0);
  if((src<0 && src!=-2) || src>=64)
    return -1;
  if(*dest < 0 || *dest >= 64)
    return -1;
  while(msg_p)
    {
      if(*dest==msg_p->dest &&
  (src==*((long *)(msg_p->src)) || *((long *)(msg_p->src))==-1))
 break;
      msg_t = msg_p;
      msg_p = msg_p->next;
    }
  if(msg_p)
    {
      *((long *)(msg_p->msg)) = *msg;
      if(*((long *)(msg_p->src)) == -1)
 *((long *)(msg_p->src)) = src;
      if(!msg_t)
        small_receive_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        small_receive_tail = msg_t;
      proc[msg_p->dest]->state = 0;
      schedule();
      return 1;
    }
  msg_p = small_send_head;
  while(msg_p)
    {
      if(*dest==msg_p->src && src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_send_head;
  while(msg_p)
    {
      if(*dest==msg_p->src && src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_receive_head;
  while(msg_p)
    {
      if(*dest==msg_p->dest && src==*((long *)(msg_p->src)))
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = ((void *) 0);
  if(src == -2)
    {
      int i;
      for(i=0; i<1024; i++)
        if(msg_hardware[i].src != -2)
          {
            msg_p = &msg_hardware[i];
            break;
          }
      if(!msg_p)
        return -1;
    }
  else
    {
      struct msg_struct new_msg;
      msg_p = &new_msg;
    }
  msg_p->src = src;
  msg_p->dest = *dest;
  msg_p->msg = *msg;
  msg_p->next = ((void *) 0);
  if(!small_send_head)
    small_send_head = small_send_tail = msg_p;
  else
    {
      small_send_tail->next = msg_p;
      small_send_tail = msg_p;
    }
  if(src != -2)
    proc[src]->state = 1;
  schedule();
  return 1;
}

variable_types: src long

variable_types:
dest
long *

variable_types:
msg
long *

variable_types: struct msg_struct { long src; long dest; long msg; struct msg_struct *next; } *