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

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

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

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

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


repo: Caltoopia/caltoopia-calvin

decompiled_code:
_BOOL8 __fastcall RVC_decoder__texture_V__IAP__DOLLAR__d10566(__int64 a1, __int64 a2)
{
return (unsigned int)pinPeek_int32_t(*(_QWORD *)(a2 + 40) + 232LL, 0) == -2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func20(__int64 a1, __int64 a2)
{
return (unsigned int)func19(*(_QWORD *)(a2 + 40) + 232LL, 0) == -2;
}

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

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

variable_types:
context
void *

variable_types: struct ActorInstance_RVC_decoder__texture_V__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: s int

variable_types: ret int

return_type: int

user_defined_types: struct ActorInstance_RVC_decoder__texture_V__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 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; }

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:
__int64 __fastcall RVC_decoder__texture_V__IAP__DOLLAR__d10577(__int64 a1, __int64 a2)
{
return (unsigned int)pinPeek_int32_t(*(_QWORD *)(a2 + 40) + 232LL, 0) >> 31;
}

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

original_code:
bool_t RVC_decoder__texture_V__IAP__DOLLAR__d10577(art_action_context_t *context, ActorInstance_RVC_decoder__texture_V__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_V__IAP__DOLLAR__d10577(void *context, struct ActorInstance_RVC_decoder__texture_V__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_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:
_BOOL8 __fastcall RVC_decoder__texture_V__IAP__DOLLAR__d10606(__int64 a1, __int64 a2)
{
return *(_DWORD *)(a2 + 108) == 64;
}

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

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


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

LABEL_1:
while ( 2 )
{
while ( 2 )
{
v1 = *(_DWORD *)(a1 + 72);
do
{
if ( !v1 )
{
if ( !(unsigned int)pinAvailIn_int32_t(*(_QWORD *)(a1 + 40) + 232LL) )
return &exitcode_block_Any;
if ( (unsigned int)RVC_decoder__texture_V__IAP__DOLLAR__d10566(0LL, a1) )
{
action0__newvop(a1);
*(_DWORD *)(a1 + 72) = 0;
goto LABEL_1;
}
if ( !(unsigned int)pinAvailIn_int32_t(*(_QWORD *)(a1 + 40) + 232LL) )
return &exitcode_block_Any;
if ( (unsigned int)RVC_decoder__texture_V__IAP__DOLLAR__d10577(0LL, a1) )
{
action1__skip(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_1;
}
v3 = *(_QWORD *)(a1 + 40);
if ( (unsigned int)pinAvailIn_int32_t(v3 + 232)
&& (unsigned int)pinAvailIn_int32_t(v3 + 128)
&& (unsigned int)pinAvailIn_int32_t(v3 + 336)
&& (unsigned int)pinAvailIn_int32_t(v3 + 440) )
{
action2__start(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_1;
}
return &exitcode_block_Any;
}
}
while ( v1 != 1 );
if ( (unsigned int)RVC_decoder__texture_V__IAP__DOLLAR__d10606(0LL, a1) )
{
action3__advance(a1);
*(_DWORD *)(a1 + 72) = 0;
continue;
}
break;
}
if ( (unsigned int)pinAvailIn_int32_t(*(_QWORD *)(a1 + 40) + 24LL)
&& (unsigned int)pinAvailOut_int32_t(*(_QWORD *)(a1 + 56)) )
{
action4__copy(a1);
*(_DWORD *)(a1 + 72) = 1;
continue;
}
return &exitcode_block_Any;
}
}

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

LABEL_1:
while ( 2 )
{
while ( 2 )
{
v1 = *(_DWORD *)(a1 + 72);
do
{
if ( !v1 )
{
if ( !(unsigned int)func10(*(_QWORD *)(a1 + 40) + 232LL) )
return &exitcode_block_Any;
if ( (unsigned int)func20(0LL, a1) )
{
func16(a1);
*(_DWORD *)(a1 + 72) = 0;
goto LABEL_1;
}
if ( !(unsigned int)func10(*(_QWORD *)(a1 + 40) + 232LL) )
return &exitcode_block_Any;
if ( (unsigned int)func21(0LL, a1) )
{
func17(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_1;
}
v3 = *(_QWORD *)(a1 + 40);
if ( (unsigned int)func10(v3 + 232)
&& (unsigned int)func10(v3 + 128)
&& (unsigned int)func10(v3 + 336)
&& (unsigned int)func10(v3 + 440) )
{
func18(a1);
*(_DWORD *)(a1 + 72) = 1;
goto LABEL_1;
}
return &exitcode_block_Any;
}
}
while ( v1 != 1 );
if ( (unsigned int)func22(0LL, a1) )
{
func13(a1);
*(_DWORD *)(a1 + 72) = 0;
continue;
}
break;
}
if ( (unsigned int)func10(*(_QWORD *)(a1 + 40) + 24LL)
&& (unsigned int)func11(*(_QWORD *)(a1 + 56)) )
{
action4__copy(a1);
*(_DWORD *)(a1 + 72) = 1;
continue;
}
return &exitcode_block_Any;
}
}

original_code:
static const int *RVC_decoder__texture_V__IAP_action_scheduler(AbstractActorInstance *pBase) {
  const int *result = exit_code_yield;
  ActorInstance_RVC_decoder__texture_V__IAP *thisActor=(ActorInstance_RVC_decoder__texture_V__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_V__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_V__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_V__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_V__IAP_action_scheduler(struct AbstractActorInstance *pBase) {
  int *result = exit_code_yield;
  struct ActorInstance_RVC_decoder__texture_V__IAP *thisActor = (ActorInstance_RVC_decoder__texture_V__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_V__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_V__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_V__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_BTYPE_constructor(__int64 a1)
{
*(_DWORD *)(a1 + 72) = 0;
}

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

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

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

variable_types: struct ActorInstance_RVC_decoder__parser__splitter_BTYPE { 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_BTYPE { struct AbstractActorInstance base; int _fsmState; }


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

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


decompiled_code:
void *__fastcall pinReadRepeat_int32_t(char **a1, char *a2, unsigned int a3)
{
char *v4; // rsi
char *v5; // rbp
unsigned __int64 v6; // r13
unsigned int v7; // eax
void *result; // rax

v4 = a1[2];
v5 = &v4[4 * a3];
v6 = (unsigned __int64)a1[1];
v7 = *((_DWORD *)a1 + 6);
if ( v7 < a3 )
__assert_fail("p->available >= n", "../../actors-fifo.h", 0x7Eu, "pinReadRepeat_int32_t");
*((_DWORD *)a1 + 6) = v7 - a3;
if ( (unsigned __int64)v5 >= v6 )
{
memcpy(a2, v4, (int)v6 - (int)v4);
a2 += (int)v6 - (int)v4;
v4 = *a1;
v5 = &v5[(_QWORD)*a1 - v6];
}
result = memcpy(a2, v4, v5 - v4);
a1[2] = v5;
return result;
}

canonical_decompiled_code:
void *__fastcall func12(char **a1, char *a2, unsigned int a3)
{
char *v4; // rsi
char *v5; // rbp
unsigned __int64 v6; // r13
unsigned int v7; // eax
void *result; // rax

v4 = a1[2];
v5 = &v4[4 * a3];
v6 = (unsigned __int64)a1[1];
v7 = *((_DWORD *)a1 + 6);
if ( v7 < a3 )
__assert_fail("p->available >= n", "../../actors-fifo.h", 0x7Eu, "pinReadRepeat_int32_t");
*((_DWORD *)a1 + 6) = v7 - a3;
if ( (unsigned __int64)v5 >= v6 )
{
memcpy(a2, v4, (int)v6 - (int)v4);
a2 += (int)v6 - (int)v4;
v4 = *a1;
v5 = &v5[(_QWORD)*a1 - v6];
}
result = memcpy(a2, v4, v5 - v4);
a1[2] = v5;
return result;
}

original_code:
static inline void pinReadRepeat_int32_t(LocalInputPort *p,
                                            int32_t *buf,
                                            int n)
{
  const char *startPtr=(char*) p->readPtr;
  const char *endPtr=(char*) ((int32_t*) startPtr + n);
  const char *bufferEnd=(char*) p->bufferEnd;
  ((void) sizeof ((p->available >= n) ? 1 : 0), __extension__ ({ if (p->available >= n) ; else __assert_fail ("p->available >= n", "../../actors-fifo.h", 126, __extension__ __PRETTY_FUNCTION__); }));
  p->available -= n;
  if (endPtr >= bufferEnd) {
    int numBytes=bufferEnd-startPtr;
    memcpy(buf, startPtr, numBytes);
    buf=(int32_t*) ((char*) buf + numBytes);
    startPtr=p->bufferStart;
    endPtr=startPtr+(endPtr-bufferEnd);
  }
  memcpy(buf, startPtr, endPtr-startPtr);
  p->readPtr=endPtr;
}

canonical_original_code:
static inline void pinReadRepeat_int32_t(struct LocalInputPort *p, int *buf, int n)
{
  char *startPtr = (char*) p->readPtr;
  char *endPtr = (char*) ((int32_t*) startPtr + n);
  char *bufferEnd = (char*) p->bufferEnd;
  ((void) sizeof ((p->available >= n) ? 1 : 0), __extension__ ({ if (p->available >= n) ; else __assert_fail ("p->available >= n", "../../actors-fifo.h", 126, __extension__ __PRETTY_FUNCTION__); }));
  p->available -= n;
  if (endPtr >= bufferEnd) {
    int numBytes = bufferEnd-startPtr;
    memcpy(buf, startPtr, numBytes);
    buf=(int *) ((char *) buf + numBytes);
    startPtr=p->bufferStart;
    endPtr=startPtr+(endPtr-bufferEnd);
  }
  memcpy(buf, startPtr, endPtr-startPtr);
  p->readPtr=endPtr;
}

variable_types:
buf
int *

variable_types: n int

variable_types:
startPtr
char *

variable_types:
endPtr
char *

variable_types:
bufferEnd
char *

variable_types: numBytes int


original_code:
static void action2__cmd__split(ActorInstance_RVC_decoder__parser__splitter_BTYPE *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 action2__cmd__split(struct ActorInstance_RVC_decoder__parser__splitter_BTYPE *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 *


decompiled_code:
_BOOL8 __fastcall RVC_decoder__parser__splitter_BTYPE__DOLLAR__d637(__int64 a1, __int64 a2)
{
unsigned int v2; // eax

v2 = pinPeek_int32_t(*(_QWORD *)(a2 + 40) + 24LL, 0);
return (unsigned int)bitand(v2, 2048) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(__int64 a1, __int64 a2)
{
unsigned int v2; // eax

v2 = func11(*(_QWORD *)(a2 + 40) + 24LL, 0);
return (unsigned int)func6(v2, 2048) != 0;
}

original_code:
bool_t RVC_decoder__parser__splitter_BTYPE__DOLLAR__d637(art_action_context_t *context, ActorInstance_RVC_decoder__parser__splitter_BTYPE *thisActor) {
  int32_t cmd;
  {
    bool_t ret;
    cmd = pinPeek_int32_t(&(thisActor->base.inputPort[0].localInputPort), 0);
    ret = (bitand(cmd, NEWVOP) != 0);
    return ret;
  }
}

canonical_original_code:
int RVC_decoder__parser__splitter_BTYPE__DOLLAR__d637(void *context, struct ActorInstance_RVC_decoder__parser__splitter_BTYPE *thisActor) {
  int cmd;
  {
    int ret;
    cmd = pinPeek_int32_t(&(thisActor->base.inputPort[0].localInputPort), 0);
    ret = (bitand(cmd, NEWVOP) != 0);
    return ret;
  }
}

variable_types: cmd int


decompiled_code:
void *__fastcall RVC_decoder__parser__splitter_BTYPE_action_scheduler(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
__int64 v4; // rbp
__int64 v5; // rbp

LABEL_1:
while ( 2 )
{
v1 = *(_DWORD *)(a1 + 72);
while ( v1 )
{
if ( v1 == 1 )
{
if ( (unsigned int)pinAvailIn_int32_t(*(_QWORD *)(a1 + 40) + 24LL) > 1 )
{
v2 = *(_QWORD *)(a1 + 56);
if ( (unsigned int)pinAvailOut_int32_t(v2) > 1
&& (unsigned int)pinAvailOut_int32_t(v2 + 136) > 1
&& (unsigned int)pinAvailOut_int32_t(v2 + 272) > 1 )
{
action1__skip(a1);
*(_DWORD *)(a1 + 72) = 0;
goto LABEL_1;
}
}
return &exitcode_block_Any;
}
}
if ( !(unsigned int)pinAvailIn_int32_t(*(_QWORD *)(a1 + 40) + 24LL) )
return &exitcode_block_Any;
if ( (unsigned int)RVC_decoder__parser__splitter_BTYPE__DOLLAR__d637(0LL, a1) )
{
v4 = *(_QWORD *)(a1 + 56);
if ( (unsigned int)pinAvailOut_int32_t(v4)
&& (unsigned int)pinAvailOut_int32_t(v4 + 136)
&& (unsigned int)pinAvailOut_int32_t(v4 + 272) )
{
action0__cmd__newVop(a1);
*(_DWORD *)(a1 + 72) = 1;
continue;
}
}
else if ( (unsigned int)pinAvailIn_int32_t(*(_QWORD *)(a1 + 40) + 24LL) > 5 )
{
v5 = *(_QWORD *)(a1 + 56);
if ( (unsigned int)pinAvailOut_int32_t(v5) > 3
&& (unsigned int)pinAvailOut_int32_t(v5 + 136)
&& (unsigned int)pinAvailOut_int32_t(v5 + 272) )
{
action2__cmd__split(a1);
*(_DWORD *)(a1 + 72) = 0;
continue;
}
}
return &exitcode_block_Any;
}
}

canonical_decompiled_code:
void *__fastcall func16(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
__int64 v4; // rbp
__int64 v5; // rbp

LABEL_1:
while ( 2 )
{
v1 = *(_DWORD *)(a1 + 72);
while ( v1 )
{
if ( v1 == 1 )
{
if ( (unsigned int)func7(*(_QWORD *)(a1 + 40) + 24LL) > 1 )
{
v2 = *(_QWORD *)(a1 + 56);
if ( (unsigned int)func8(v2) > 1
&& (unsigned int)func8(v2 + 136) > 1
&& (unsigned int)func8(v2 + 272) > 1 )
{
func14(a1);
*(_DWORD *)(a1 + 72) = 0;
goto LABEL_1;
}
}
return &exitcode_block_Any;
}
}
if ( !(unsigned int)func7(*(_QWORD *)(a1 + 40) + 24LL) )
return &exitcode_block_Any;
if ( (unsigned int)func15(0LL, a1) )
{
v4 = *(_QWORD *)(a1 + 56);
if ( (unsigned int)func8(v4)
&& (unsigned int)func8(v4 + 136)
&& (unsigned int)func8(v4 + 272) )
{
action0__cmd__newVop(a1);
*(_DWORD *)(a1 + 72) = 1;
continue;
}
}
else if ( (unsigned int)func7(*(_QWORD *)(a1 + 40) + 24LL) > 5 )
{
v5 = *(_QWORD *)(a1 + 56);
if ( (unsigned int)func8(v5) > 3
&& (unsigned int)func8(v5 + 136)
&& (unsigned int)func8(v5 + 272) )
{
func13(a1);
*(_DWORD *)(a1 + 72) = 0;
continue;
}
}
return &exitcode_block_Any;
}
}

original_code:
static const int *RVC_decoder__parser__splitter_BTYPE_action_scheduler(AbstractActorInstance *pBase) {
  const int *result = exit_code_yield;
  ActorInstance_RVC_decoder__parser__splitter_BTYPE *thisActor=(ActorInstance_RVC_decoder__parser__splitter_BTYPE*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 1)) {
          if (RVC_decoder__parser__splitter_BTYPE__DOLLAR__d637(context, thisActor)) {
            if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[1].localOutputPort)) >= 1) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[2].localOutputPort)) >= 1)) {
              action0__cmd__newVop(thisActor);
              thisActor->_fsmState = 1;
              continue;
            } else {
              result = exitcode_block_Any;
              goto out;
            }
          }
        }
        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)) {
            action2__cmd__split(thisActor);
            thisActor->_fsmState = 0;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
      case 1:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 2)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1*2) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[1].localOutputPort)) >= 1*2) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[2].localOutputPort)) >= 1*2)) {
            action1__skip(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_BTYPE_action_scheduler(struct AbstractActorInstance *pBase) {
  int *result = exit_code_yield;
  struct ActorInstance_RVC_decoder__parser__splitter_BTYPE *thisActor = (ActorInstance_RVC_decoder__parser__splitter_BTYPE*) pBase;
  void *context = ((void *)0); context = context;
  while(1) {
    switch(thisActor->_fsmState) {
      case 0:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 1)) {
          if (RVC_decoder__parser__splitter_BTYPE__DOLLAR__d637(context, thisActor)) {
            if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[1].localOutputPort)) >= 1) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[2].localOutputPort)) >= 1)) {
              action0__cmd__newVop(thisActor);
              thisActor->_fsmState = 1;
              continue;
            } else {
              result = exitcode_block_Any;
              goto out;
            }
          }
        }
        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)) {
            action2__cmd__split(thisActor);
            thisActor->_fsmState = 0;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
      case 1:
        if ((pinAvailIn_int32_t(&(thisActor->base.inputPort[0].localInputPort)) >= 2)) {
          if ((pinAvailOut_int32_t(&(thisActor->base.outputPort[0].localOutputPort)) >= 1*2) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[1].localOutputPort)) >= 1*2) && (pinAvailOut_int32_t(&(thisActor->base.outputPort[2].localOutputPort)) >= 1*2)) {
            action1__skip(thisActor);
            thisActor->_fsmState = 0;
            continue;
          } else {
            result = exitcode_block_Any;
            goto out;
          }
        }
        result = exitcode_block_Any;
        goto out;
        break;
    }
  }
  out:

  return result;
}


COORD

decompiled_code:
__int64 __fastcall COORD(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
static inline struct coord COORD(int x, int y) {
 return (struct coord){ .x = x, .y = y };
}

variable_types: x int

variable_types: y int

return_type: struct coord { union { int x; }; union { int y; }; }


max

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code:
static int max(int a, int b) {
 return a > b ? a : b;
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall thumb_size_for_frame(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx

v1 = max(a1, HIDWORD(a1));
v2 = 128;
if ( v1 > 128 )
{
v2 = 256;
if ( v1 >= 257 )
v2 = 512;
}
return v2;
}

original_code:
static int thumb_size_for_frame(struct coord frame_dim) {
 int longer = max(frame_dim.width, frame_dim.height);
 if (longer <= 128) {
  return 128;
 } else if (longer <= 256) {
  return 256;
 } else {
  return 512;
 }
}

variable_types: struct coord { union { int x; }; union { int y; }; }

variable_types: longer int


decompiled_code:
__int64 __fastcall next_to_update(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbp
__int64 v3; // r12
__int64 v4; // rdx
__int64 v5; // r13
__int64 v6; // r15
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rbx

v2 = a1;
if ( !a1 )
return 0LL;
v3 = view_visible_rect(view);
v5 = v4;
v6 = *a1;
if ( *a1 )
{
v7 = 0LL;
while ( 1 )
{
v8 = layout_frame_rect_by_number(a2, (unsigned int)v7);
if ( (unsigned int)rect_intersect(v8, v9, v3, v5) )
{
v6 = a1[v7];
if ( !*(_DWORD *)(v6 + 28)
&& (!*(_QWORD *)(v6 + 8)
|| *(_DWORD *)(v6 + 24) != (unsigned int)thumb_size_for_frame(**(_QWORD **)(view + 16LL))) )
{
break;
}
}
if ( !a1[++v7] )
{
v6 = *a1;
if ( *a1 )
{
v10 = view;
do
{
if ( !*(_DWORD *)(v6 + 28)
&& (!*(_QWORD *)(v6 + 8)
|| *(_DWORD *)(v6 + 24) != (unsigned int)thumb_size_for_frame(**(_QWORD **)(v10 + 16))) )
{
break;
}
v6 = *++v2;
}
while ( *v2 );
}
return v6;
}
}
}
return v6;
}

original_code:
static struct thumbnail *next_to_update(struct thumbnail **list, struct layout *layout) {
 if (list == ((void *)0)) {
  return ((void *)0);
 }
 struct rect onscreen = view_visible_rect(view);
 struct thumbnail **p = list;
 int frame_num = 0;
 while (*p != ((void *)0)) {
  struct rect frame_rect = layout_frame_rect_by_number(layout, frame_num);
  if (
   rect_intersect(frame_rect, onscreen) &&
   !(*p)->failed &&
   (
    (*p)->imlib == ((void *)0) ||
    (*p)->size != thumb_size_for_frame(view->frame->thumb_dim)
   )
  ) {
   return (*p);
  }
  p++;
  frame_num++;
 }
 p = list;
 frame_num = 0;
 while (*p != ((void *)0)) {
  if (
   !(*p)->failed &&
   (
    (*p)->imlib == ((void *)0) ||
    (*p)->size != thumb_size_for_frame(view->frame->thumb_dim)
   )
  ) {
   return (*p);
  }
  p++;
  frame_num++;
 }
 return ((void *)0);
}

variable_types:
list
struct thumbnail **

variable_types: struct layout { struct coord window; int frame_count; int total_height; int _frames_per_row; double _frame_spacing; } *

variable_types: struct rect { struct coord { union { int x; }; union { int y; }; } tl; struct coord dim; }

variable_types: struct thumbnail { char *filename; void *imlib; struct coord { union { int x; }; union { int y; }; } thumb_dim; int size; int failed; } **

user_defined_types: struct rect { struct coord tl; struct coord dim; }

user_defined_types: struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; }


decompiled_code:
const char **__fastcall find_thumbnail_by_name(char *s1)
{
const char ***v1; // rbp
const char **i; // rbx

v1 = (const char ***)thumbnails;
for ( i = *(const char ***)thumbnails; *v1; i = *v1 )
{
if ( !strcmp(s1, *i) )
break;
++v1;
}
return i;
}

canonical_decompiled_code:
const char **__fastcall func4(char *s1)
{
const char ***v1; // rbp
const char **i; // rbx

v1 = (const char ***)thumbnails;
for ( i = *(const char ***)thumbnails; *v1; i = *v1 )
{
if ( !strcmp(s1, *i) )
break;
++v1;
}
return i;
}

original_code:
struct thumbnail *find_thumbnail_by_name(char *filename) {
 struct thumbnail **p = thumbnails;
 while (*p != ((void *)0)) {
  if (!strcmp(filename, (*p)->filename)) {
   return *p;
  }
  p++;
 }
 return ((void *)0);
}

variable_types:
filename
char *

return_type: struct thumbnail { char *filename; void *imlib; struct coord { union { int x; }; union { int y; }; } thumb_dim; int size; int failed; } *


decompiled_code:
__int64 try_update_thumbnails()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
unsigned int v4; // er12
unsigned int v5; // eax

v0 = next_to_update((_QWORD *)thumbnails, *(_QWORD *)(view + 8LL));
result = 0LL;
if ( v0 )
{
v2 = (unsigned int)thumb_size_for_frame(**(_QWORD **)(view + 16LL));
v3 = thumbnail_from_storage(*(_QWORD *)v0, v2);
*(_QWORD *)(v0 + 8) = v3;
if ( v3 )
{
imlib_context_set_image(v3);
v4 = imlib_image_get_height();
v5 = imlib_image_get_width();
*(_QWORD *)(v0 + 16) = COORD(v5, v4);
*(_DWORD *)(v0 + 24) = v2;
result = 1LL;
}
else
{
*(_DWORD *)(v0 + 28) = 1;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
unsigned int v4; // er12
unsigned int v5; // eax

v0 = func3((_QWORD *)thumbnails, *(_QWORD *)(view + 8LL));
result = 0LL;
if ( v0 )
{
v2 = (unsigned int)func2(**(_QWORD **)(view + 16LL));
v3 = thumbnail_from_storage(*(_QWORD *)v0, v2);
*(_QWORD *)(v0 + 8) = v3;
if ( v3 )
{
imlib_context_set_image(v3);
v4 = imlib_image_get_height();
v5 = imlib_image_get_width();
*(_QWORD *)(v0 + 16) = func0(v5, v4);
*(_DWORD *)(v0 + 24) = v2;
result = 1LL;
}
else
{
*(_DWORD *)(v0 + 28) = 1;
result = 1LL;
}
}
return result;
}

original_code:
int try_update_thumbnails() {
 struct thumbnail *t = next_to_update(thumbnails, view->layout);
 if (t == ((void *)0)) {
  return 0;
 }
 int size = thumb_size_for_frame(view->frame->thumb_dim);
 t->imlib = thumbnail_from_storage(t->filename, size);
 if (t->imlib != ((void *)0)) {
  imlib_context_set_image(t->imlib);
  t->thumb_dim = COORD(
   imlib_image_get_width(),
   imlib_image_get_height()
  );
  t->size = size;
 } else {
  t->failed = 1;
 }
 return 1;
}

variable_types: struct thumbnail { char *filename; void *imlib; struct coord { union { int x; }; union { int y; }; } thumb_dim; int size; int failed; } *

variable_types: size int


RECT

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

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

original_code:
static inline struct rect RECT(struct coord tl, struct coord dim) {
 return (struct rect){ .tl = tl, .dim = dim };
}

variable_types:
tl
struct coord

variable_types:
dim
struct coord

return_type: struct rect { struct coord { union { int x; }; union { int y; }; } tl; struct coord dim; }


decompiled_code:
_DWORD *layout_new()
{
_DWORD *v0; // rbx

v0 = malloc(0x30uLL);
v0[6] = 0;
*(_QWORD *)v0 = COORD(0, 0LL);
*((_QWORD *)v0 + 1) = COORD(0, 0LL);
*((_QWORD *)v0 + 2) = COORD(0, 0LL);
return v0;
}

original_code:
struct layout *layout_new() {
 struct layout *l = malloc(sizeof(struct layout));
 l->frame_count = 0;
 l->window = COORD(0, 0);
 l->spacing = COORD(0, 0);
 l->frame = COORD(0, 0);
 return l;
}

variable_types: struct layout { struct coord { union { int x; }; union { int y; }; } window; int frame_count; int total_height; int _frames_per_row; double _frame_spacing; } *

user_defined_types: struct layout { struct coord window; int frame_count; int total_height; int _frames_per_row; double _frame_spacing; }


original_code:
struct rect layout_frame_rect_by_number(struct layout *l, int frame) {
 if (frame >= l->frame_count) {
  return RECT(COORD(0, 0), COORD(0, 0));
 }
 struct rect r;
 int col = frame % l->_frames_per_row;
 int row = frame / l->_frames_per_row;
 r.tl.x = (col + 1) * l->_frame_spacing
        + col * l->frame.width;
 r.tl.y = (row + 1) * l->spacing.vertical
        + row * l->frame.height;
 r.dim = l->frame;
 return r;
}

variable_types: frame int

variable_types: col int

variable_types: row int

user_defined_types: struct coord { union { int x; }; union { int y; }; }


decompiled_code:
__int64 __fastcall layout_frame_number_by_coord(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__int64 v3; // rax
__int64 v4; // rdx

if ( *(int *)(a1 + 24) <= 0 )
return (unsigned int)-1;
v2 = 0;
while ( 1 )
{
v3 = layout_frame_rect_by_number(a1, v2);
if ( (unsigned int)rect_contains(v3, v4, a2) )
break;
if ( *(_DWORD *)(a1 + 24) <= (signed int)++v2 )
return (unsigned int)-1;
}
return v2;
}

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

if ( *(int *)(a1 + 24) <= 0 )
return (unsigned int)-1;
v2 = 0;
while ( 1 )
{
v3 = func3(a1, v2);
if ( (unsigned int)rect_contains(v3, v4, a2) )
break;
if ( *(_DWORD *)(a1 + 24) <= (signed int)++v2 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int layout_frame_number_by_coord(struct layout *l, struct coord probe) {
 for (int f = 0; f < l->frame_count; f++) {
  struct rect ff = layout_frame_rect_by_number(l, f);
  if (rect_contains(ff, probe)) {
   return f;
  }
 }
 return -1;
}

variable_types:
probe
struct coord

variable_types: f int


original_code:
void layout_recompute(struct layout *l) {
 int fpr = (l->window.width - l->spacing.horizontal)
         / (l->frame.width + l->spacing.horizontal);
 if (fpr < 1) {
  fpr = 1;
 }
 l->_frame_spacing = (l->window.width - l->frame.width * fpr)
                   / (double)(fpr + 1);
 l->_frames_per_row = fpr;
 int rows = ceil(l->frame_count / (double)fpr);
 l->total_height = rows * l->frame.height
                 + (rows + 1) * l->spacing.vertical;
}

variable_types: fpr int

variable_types: rows int


COORD

canonical_original_code:
static inline struct coord COORD(int x, int y) {
 return (struct coord){ .x = x, .y = y };
}

variable_types: x int

variable_types: y int


decompiled_code:
void __fastcall input_set_drag_handlers(__int64 (__fastcall *a1)(_QWORD, _QWORD), __int64 (__fastcall *a2)(_QWORD), __int64 a3)
{
ev_drag_start = a1;
ev_drag_stop = a2;
ev_drag_update = a3;
}

canonical_decompiled_code:
void __fastcall func4(__int64 (__fastcall *a1)(_QWORD, _QWORD), __int64 (__fastcall *a2)(_QWORD), __int64 a3)
{
ev_drag_start = a1;
ev_drag_stop = a2;
ev_drag_update = a3;
}

original_code:
void input_set_drag_handlers(
 void (*drag_start )(int, struct coord),
 void (*drag_stop )(int),
 void (*drag_update)(int, struct coord, struct coord)
) {
 ev_drag_start = drag_start;
 ev_drag_stop = drag_stop;
 ev_drag_update = drag_update;
}

canonical_original_code:
void input_set_drag_handlers(void (*drag_start)(int, struct coord), void (*drag_stop)(int), void (*drag_update)(int, struct coord, struct coord)) {
 ev_drag_start = drag_start;
 ev_drag_stop = drag_stop;
 ev_drag_update = drag_update;
}

variable_types: void (*)(int, struct coord { union { int x; }; union { int y; }; })

variable_types: void (*)(int, struct coord, struct coord)


decompiled_code:
void __fastcall input_set_click_handler(__int64 a1)
{
ev_click = a1;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
ev_click = a1;
}

original_code:
void input_set_click_handler(void (*click)(int, struct coord)) {
 ev_click = click;
}


decompiled_code:
void __fastcall input_set_hover_handler(__int64 a1)
{
ev_hover = a1;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
ev_hover = a1;
}

original_code:
void input_set_hover_handler(void (*hover)(struct coord)) {
 ev_hover = hover;
}

variable_types: void (*)(struct coord { union { int x; }; union { int y; }; })


decompiled_code:
void input_set_drag_limits()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void input_set_drag_limits(int xneg, int xpos, int yneg, int ypos) {
 drag_limit_xneg = xneg;
 drag_limit_xpos = xpos;
 drag_limit_yneg = yneg;
 drag_limit_ypos = ypos;
}

variable_types: xneg int

variable_types: xpos int

variable_types: yneg int

variable_types: ypos int


decompiled_code:
__int64 __fastcall coord_scale_to_fit(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx

v2 = a2;
v3 = (unsigned int)(int)((double)(int)a2 * (double)SHIDWORD(a1) / (double)(int)a1);
if ( (int)v3 > SHIDWORD(a2) )
{
v2 = (int)((double)SHIDWORD(a2) * (double)(int)a1 / (double)SHIDWORD(a1));
v3 = HIDWORD(a2);
}
return (v3 << 32) | v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx

v2 = a2;
v3 = (unsigned int)(int)((double)(int)a2 * (double)SHIDWORD(a1) / (double)(int)a1);
if ( (int)v3 > SHIDWORD(a2) )
{
v2 = (int)((double)SHIDWORD(a2) * (double)(int)a1 / (double)SHIDWORD(a1));
v3 = HIDWORD(a2);
}
return (v3 << 32) | v2;
}

original_code:
struct coord coord_scale_to_fit(struct coord obj, struct coord fit) {
 struct coord new;
 new.x = fit.x;
 new.y = fit.x * (double)obj.y / obj.x;
 if (new.y > fit.y) {
  new.x = fit.y * (double)obj.x / obj.y;
  new.y = fit.y;
 }
 return new;
}

variable_types:
obj
struct coord

variable_types:
fit
struct coord

variable_types: struct coord { union { int x; }; union { int y; }; }


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

if ( (int)a1 >= (int)a2 || SHIDWORD(a1) >= SHIDWORD(a2) )
result = coord_scale_to_fit(a1, a2);
else
result = (a1 >> 32 << 32) | (unsigned int)a1;
return result;
}

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

if ( (int)a1 >= (int)a2 || SHIDWORD(a1) >= SHIDWORD(a2) )
result = func0(a1, a2);
else
result = (a1 >> 32 << 32) | (unsigned int)a1;
return result;
}

original_code:
struct coord coord_downscale_to_fit(struct coord obj, struct coord fit) {
 if (obj.x < fit.x && obj.y < fit.y) {
  return obj;
 } else {
  return coord_scale_to_fit(obj, fit);
 }
}


decompiled_code:
_BOOL8 __fastcall rect_intersect(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax
__int64 v5; // rdi
__int64 v6; // rdx

result = 0LL;
if ( (int)a1 + (int)a2 >= (int)a3 && (int)a3 + (int)a4 >= (int)a1 )
{
v5 = a1 >> 32;
v6 = a3 >> 32;
if ( (int)v5 + HIDWORD(a2) >= (int)v6 )
result = HIDWORD(a4) + (int)v6 >= (int)v5;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax
__int64 v5; // rdi
__int64 v6; // rdx

result = 0LL;
if ( (int)a1 + (int)a2 >= (int)a3 && (int)a3 + (int)a4 >= (int)a1 )
{
v5 = a1 >> 32;
v6 = a3 >> 32;
if ( (int)v5 + HIDWORD(a2) >= (int)v6 )
result = HIDWORD(a4) + (int)v6 >= (int)v5;
}
return result;
}

original_code:
int rect_intersect(struct rect r1, struct rect r2) {
 return !(
  r2.tl.x > r1.tl.x + r1.dim.width ||
  r2.tl.x + r2.dim.width < r1.tl.x ||
  r2.tl.y > r1.tl.y + r1.dim.height ||
  r2.tl.y + r2.dim.height < r1.tl.y
 );
}

variable_types: struct rect { struct coord { union { int x; }; union { int y; }; } tl; struct coord dim; }


decompiled_code:
_BOOL8 __fastcall rect_contains(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( (int)a3 >= (int)a1 )
{
if ( (int)a2 + (int)a1 >= (int)a3 && SHIDWORD(a1) <= SHIDWORD(a3) )
result = HIDWORD(a1) + HIDWORD(a2) >= SHIDWORD(a3);
else
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( (int)a3 >= (int)a1 )
{
if ( (int)a2 + (int)a1 >= (int)a3 && SHIDWORD(a1) <= SHIDWORD(a3) )
result = HIDWORD(a1) + HIDWORD(a2) >= SHIDWORD(a3);
else
result = 0LL;
}
return result;
}

original_code:
int rect_contains(struct rect r, struct coord c) {
 return (
  r.tl.x <= c.x && r.tl.x + r.dim.width >= c.x &&
  r.tl.y <= c.y && r.tl.y + r.dim.height >= c.y
 );
}

variable_types:
c
struct coord


decompiled_code:
const char *__fastcall imlib_load_error_string(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "No such file or directory";
break;
case 2:
result = "Is a directory";
break;
case 3:
result = "Permission denied";
break;
case 4:
case 14:
result = "No Imlib2 loader for that file format";
break;
case 5:
result = "Filename too long";
break;
case 6:
result = "No such file or directory (along path)";
break;
case 7:
result = "Not a directory";
break;
case 8:
result = "Bad address";
break;
case 9:
result = "Too many levels of symbolic links";
break;
case 10:
result = "Out of memory";
break;
case 11:
result = "Too many open files";
break;
case 12:
result = "Permission denied (to write to directory)";
break;
case 13:
result = "No space left on device";
break;
default:
result = "Unknown error";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "No such file or directory";
break;
case 2:
result = "Is a directory";
break;
case 3:
result = "Permission denied";
break;
case 4:
case 14:
result = "No Imlib2 loader for that file format";
break;
case 5:
result = "Filename too long";
break;
case 6:
result = "No such file or directory (along path)";
break;
case 7:
result = "Not a directory";
break;
case 8:
result = "Bad address";
break;
case 9:
result = "Too many levels of symbolic links";
break;
case 10:
result = "Out of memory";
break;
case 11:
result = "Too many open files";
break;
case 12:
result = "Permission denied (to write to directory)";
break;
case 13:
result = "No space left on device";
break;
default:
result = "Unknown error";
break;
}
return result;
}

original_code:
const char *imlib_load_error_string(Imlib_Load_Error e) {
 switch (e) {
 case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST : return "No such file or directory";
 case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY : return "Is a directory";
 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ : return "Permission denied";
 case IMLIB_LOAD_ERROR_UNKNOWN :
 case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT : return "No Imlib2 loader for that file format";
 case IMLIB_LOAD_ERROR_PATH_TOO_LONG : return "Filename too long";
 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT : return "No such file or directory (along path)";
 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY : return "Not a directory";
 case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE : return "Bad address";
 case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS : return "Too many levels of symbolic links";
 case IMLIB_LOAD_ERROR_OUT_OF_MEMORY : return "Out of memory";
 case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS : return "Too many open files";
 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE : return "Permission denied (to write to directory)";
 case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE : return "No space left on device";
 default : return "Unknown error";
 }
}

canonical_original_code:
char *imlib_load_error_string(enum _imlib_load_error e) {
 switch (e) {
 case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST : return "No such file or directory";
 case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY : return "Is a directory";
 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ : return "Permission denied";
 case IMLIB_LOAD_ERROR_UNKNOWN :
 case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT : return "No Imlib2 loader for that file format";
 case IMLIB_LOAD_ERROR_PATH_TOO_LONG : return "Filename too long";
 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT : return "No such file or directory (along path)";
 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY : return "Not a directory";
 case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE : return "Bad address";
 case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS : return "Too many levels of symbolic links";
 case IMLIB_LOAD_ERROR_OUT_OF_MEMORY : return "Out of memory";
 case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS : return "Too many open files";
 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE : return "Permission denied (to write to directory)";
 case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE : return "No space left on device";
 default : return "Unknown error";
 }
}

variable_types: enum _imlib_load_error { IMLIB_LOAD_ERROR_NONE=0, IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST=1, IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY=2, IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ=3, IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT=4, IMLIB_LOAD_ERROR_PATH_TOO_LONG=5, IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT=6, IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY=7, IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE=8, IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS=9, IMLIB_LOAD_ERROR_OUT_OF_MEMORY=10, IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS=11, IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE=12, IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE=13, IMLIB_LOAD_ERROR_UNKNOWN=14 }

return_type: char *


decompiled_code:
int __fastcall ctl_handle_fd(int fd)
{
char v2; // [rsp+Fh] [rbp-129h] BYREF
char v3[267]; // [rsp+10h] [rbp-128h] BYREF
int buf; // [rsp+11Bh] [rbp-1Dh] BYREF
char v5; // [rsp+11Fh] [rbp-19h]

buf = 0;
v5 = 0;
read(fd, &buf, 4uLL);
if ( strcmp((const char *)&buf, "OPEN") )
return fprintf(stderr, "unknown command on ctl pipe: %s\n", (const char *)&buf);
read(fd, &v2, 1uLL);
read(fd, v3, v2);
v3[v2] = 0;
fprintf(stderr, "loading image file: %s\n", v3);
load_image(v3);
return render_image();
}

canonical_decompiled_code:
int __fastcall func0(int fd)
{
char v2; // [rsp+Fh] [rbp-129h] BYREF
char v3[267]; // [rsp+10h] [rbp-128h] BYREF
int buf; // [rsp+11Bh] [rbp-1Dh] BYREF
char v5; // [rsp+11Fh] [rbp-19h]

buf = 0;
v5 = 0;
read(fd, &buf, 4uLL);
if ( strcmp((const char *)&buf, "OPEN") )
return fprintf(stderr, "unknown command on ctl pipe: %s\n", (const char *)&buf);
read(fd, &v2, 1uLL);
read(fd, v3, v2);
v3[v2] = 0;
fprintf(stderr, "loading image file: %s\n", v3);
load_image(v3);
return render_image();
}

original_code:
void ctl_handle_fd(int fd) {
 char command[5];
 memset(command, '\0', 5);
 read(fd, command, 4);
 if (!strcmp(command, "OPEN")) {
  char count;
  read(fd, &count, 1);
  char filename[256];
  read(fd, filename, count);
  filename[count] = '\0';
  fprintf(stderr, "loading image file: %s\n", filename);
  load_image(filename);
  render_image();
 } else {
  fprintf(stderr, "unknown command on ctl pipe: %s\n", command);
 }
}

variable_types: fd int

variable_types:
command
char [5]

variable_types: count char

variable_types:
filename
char [256]


RECT

canonical_original_code:
static inline struct rect RECT(struct coord tl, struct coord dim) {
 return (struct rect){ .tl = tl, .dim = dim };
}

variable_types:
tl
struct coord

variable_types:
dim
struct coord


fileread

repo: pentix/frontdown

decompiled_code:
size_t __fastcall fileread(void *a1, int a2, int a3, FILE *a4)
{
return fread(a1, a2, a3, a4);
}

canonical_decompiled_code:
size_t __fastcall func3(void *a1, int a2, int a3, FILE *a4)
{
return fread(a1, a2, a3, a4);
}

original_code:
int fileread(void *ptr, int size, int n, void *stream){
 return (curl_off_t)fread(ptr, size, n, stream);
}

canonical_original_code:
int fileread(void *ptr, int size, int n, void *stream){
 return (long)fread(ptr, size, n, stream);
}

variable_types:
ptr
void *

variable_types: size int

variable_types: n int

variable_types:
stream
void *


decompiled_code:
int __fastcall create_dest_dir(__int64 a1, __int64 a2)
{
int result; // eax
__int64 v3[2]; // [rsp+0h] [rbp-8018h] BYREF
char s[32752]; // [rsp+10h] [rbp-8008h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(s, 0, sizeof(s));
result = 0;
if ( *(_DWORD *)(a1 + 32) == 1 )
{
strcpy((char *)v3, (const char *)(*(_QWORD *)(a1 + 8) + 7LL));
strcat((char *)v3, (const char *)(a2 + 1));
result = mkdir((const char *)v3, 0x1FDu);
if ( result )
{
if ( *_errno_location() != 17
|| (result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int64 *))(a1 + 56))(1LL, 0LL, v3)) != 0 )
{
(*(void (__fastcall **)(__int64, __int64, __int64 *))(a1 + 56))(1LL, 1LL, v3);
result = -1;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
int result; // eax
__int64 v3[2]; // [rsp+0h] [rbp-8018h] BYREF
char s[32752]; // [rsp+10h] [rbp-8008h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(s, 0, sizeof(s));
result = 0;
if ( *(_DWORD *)(a1 + 32) == 1 )
{
strcpy((char *)v3, (const char *)(*(_QWORD *)(a1 + 8) + 7LL));
strcat((char *)v3, (const char *)(a2 + 1));
result = mkdir((const char *)v3, 0x1FDu);
if ( result )
{
if ( *_errno_location() != 17
|| (result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int64 *))(a1 + 56))(1LL, 0LL, v3)) != 0 )
{
(*(void (__fastcall **)(__int64, __int64, __int64 *))(a1 + 56))(1LL, 1LL, v3);
result = -1;
}
}
}
return result;
}

original_code:
int create_dest_dir(struct frontdown_config *config, char *relpath){
 char fullpath[16384*2]={0};
 switch(config->con_type){
  case _FILE_:
   strcpy(fullpath, &config->destination[7]);
   strcat(fullpath, &relpath[1]);
   if((mkdir(fullpath , (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)))!=0){
    if(((*__errno_location ())==17)&&(config->error(_MKDIR_ERROR_, 0, fullpath)==0)){
     return 0;
    } else {
     config->error(_MKDIR_ERROR_, 1, fullpath);
     return -1;
    }
   }
  break;
  case _UNKNOWN_:
  default:
  break;
 }
 return 0;
}

canonical_original_code:
int create_dest_dir(struct frontdown_config *config, char *relpath){
 char fullpath[-1] = {0};
 switch(config->con_type){
  case _FILE_:
   strcpy(fullpath, &config->destination[7]);
   strcat(fullpath, &relpath[1]);
   if((mkdir(fullpath , (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)))!=0){
    if(((*__errno_location ())==17)&&(config->error(_MKDIR_ERROR_, 0, fullpath)==0)){
     return 0;
    } else {
     config->error(_MKDIR_ERROR_, 1, fullpath);
     return -1;
    }
   }
  break;
  case _UNKNOWN_:
  default:
  break;
 }
 return 0;
}

variable_types: struct frontdown_config { char *source; char *destination; char *destinationUname; char *destinationPwd; enum frontdown_connection_type { _DICT_=0, _FILE_=1, _FTP_=2, _HTTP_=3, _IMAP_=4, _LDAP_=5, _POP3_=6, _RTMP_=7, _RTSP_=8, _SCP_=9, _SFTP_=10, _SMTP_=11, _TELNET_=12, _TFTP_=13, _UNKNOWN_=14 } con_type; struct frontdown_exclude_list { char exclude_path[16384]; struct frontdown_exclude_list *next; } *excludes; int (*info)(char *); int (*error)(enum frontdown_error_code { _INDEX_DB_ERROR_=0, _MKDIR_ERROR_=1, _DST_CONNECTION_ERROR_=2, _PUT_FILE_ERROR_=3 }, char, char *); char last_backup; char verbose; long long now; } *

variable_types:
relpath
char *

variable_types:
fullpath
char [-1]

user_defined_types: struct frontdown_config { char *source; char *destination; char *destinationUname; char *destinationPwd; enum frontdown_connection_type con_type; struct frontdown_exclude_list *excludes; int (*info)(char *); int (*error)(enum frontdown_error_code, char, char *); char last_backup; char verbose; long long now; }


decompiled_code:
__int64 close_destination()
{
curl_easy_cleanup(dst_connection);
curl_global_cleanup();
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
curl_easy_cleanup(dst_connection);
curl_global_cleanup();
return 0LL;
}

original_code:
int close_destination(){
 curl_easy_cleanup(dst_connection.curl);
 curl_global_cleanup();
 return 0;
}


info

decompiled_code:
int __fastcall info(const char *a1)
{
int result; // eax

if ( *((_BYTE *)&config + 65) )
result = printf("INFO: %s\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

if ( *((_BYTE *)&config + 65) )
result = printf("INFO: %s\n", a1);
return result;
}

original_code:
void info(char *text){
 if(config.verbose){
  printf("INFO: %s\n",text);
 }
}

variable_types:
text
char *


error

decompiled_code:
__int64 __fastcall error(__int64 a1, char a2, const char *a3)
{
printf("ERROR: %s\n", a3);
if ( a2 )
return 0xFFFFFFFFLL;
puts("Ignore nonfatal error");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, const char *a3)
{
printf("ERROR: %s\n", a3);
if ( a2 )
return 0xFFFFFFFFLL;
puts("Ignore nonfatal error");
return 0LL;
}

original_code:
int error(enum frontdown_error_code error_code, char fatal, char *text){
 printf("ERROR: %s\n",text);
 if(!fatal){
  printf("Ignore nonfatal error\n");
  return 0;
 }
 return -1;
}

variable_types: enum frontdown_error_code { _INDEX_DB_ERROR_=0, _MKDIR_ERROR_=1, _DST_CONNECTION_ERROR_=2, _PUT_FILE_ERROR_=3 }

variable_types: fatal char


usage

decompiled_code:
int usage()
{
puts("Usage: frontdown [OPTIONS] \n");
puts("\t-h --help Print this help");
puts("\t-v --verbose Verbose Output\n");
puts("\t-c --conf Configuration file");
puts("\t-e --exclude File/Folder to exclude as POSIX Extended Regular Expressions");
puts("\t-i --incremental Only backup what has changed since last time\n");
puts("\t-s --source Backup source");
puts("\t-d --destination Backup destination");
puts("\t-l --login Destination requires login\n");
puts("There are no bugs - just random features.");
puts("Mail them to: <nosupport@nowhere.nix>\n");
return puts("(C) Copyright 2012-2013 by Patrick Eigensatz & Florian Wernli\n");
}

canonical_decompiled_code:
int func3()
{
puts("Usage: frontdown [OPTIONS] \n");
puts("\t-h --help Print this help");
puts("\t-v --verbose Verbose Output\n");
puts("\t-c --conf Configuration file");
puts("\t-e --exclude File/Folder to exclude as POSIX Extended Regular Expressions");
puts("\t-i --incremental Only backup what has changed since last time\n");
puts("\t-s --source Backup source");
puts("\t-d --destination Backup destination");
puts("\t-l --login Destination requires login\n");
puts("There are no bugs - just random features.");
puts("Mail them to: <nosupport@nowhere.nix>\n");
return puts("(C) Copyright 2012-2013 by Patrick Eigensatz & Florian Wernli\n");
}

original_code:
void usage(void){
 printf("Usage: frontdown [OPTIONS] \n\n");
 printf("\t-h --help          Print this help\n");
 printf("\t-v --verbose       Verbose Output\n\n");
 printf("\t-c --conf          Configuration file\n");
 printf("\t-e --exclude       File/Folder to exclude as POSIX Extended Regular Expressions\n");
 printf("\t-i --incremental   Only backup what has changed since last time\n\n");
 printf("\t-s --source        Backup source\n");
 printf("\t-d --destination   Backup destination\n");
 printf("\t-l --login         Destination requires login\n\n");
 printf("There are no bugs - just random features.\n");
 printf("Mail them to: <nosupport@nowhere.nix>\n\n");
 printf("(C) Copyright 2012-2013 by Patrick Eigensatz & Florian Wernli\n\n");
}

canonical_original_code:
void usage(){
 printf("Usage: frontdown [OPTIONS] \n\n");
 printf("\t-h --help          Print this help\n");
 printf("\t-v --verbose       Verbose Output\n\n");
 printf("\t-c --conf          Configuration file\n");
 printf("\t-e --exclude       File/Folder to exclude as POSIX Extended Regular Expressions\n");
 printf("\t-i --incremental   Only backup what has changed since last time\n\n");
 printf("\t-s --source        Backup source\n");
 printf("\t-d --destination   Backup destination\n");
 printf("\t-l --login         Destination requires login\n\n");
 printf("There are no bugs - just random features.\n");
 printf("Mail them to: <nosupport@nowhere.nix>\n\n");
 printf("(C) Copyright 2012-2013 by Patrick Eigensatz & Florian Wernli\n\n");
}


help

decompiled_code:
int help()
{
version();
return usage();
}

canonical_decompiled_code:
int func4()
{
func2();
return func3();
}

original_code:
void help(){
 version();
 usage();
}

canonical_original_code:
void help(){
 version();
 usage();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
_BYTE *v4; // r12
_BYTE *v5; // rax
char *v6; // rbx
const char *v7; // rsi
const char *v8; // rsi
const char *v9; // rsi
char *v11; // rbx
size_t v12; // rax
char *v13; // rbp
char *v14; // rbx
size_t v15; // rax
char *v16; // rbp
__int64 v17[2051]; // [rsp+0h] [rbp-4018h] BYREF

v3 = calloc(1uLL, 0x4008uLL);
*(&config + 5) = (__int64)v3;
if ( !v3 )
{
fwrite("Make sure you have enough memory and run it again", 1uLL, 0x31uLL, stderr);
exit(1);
}
*(&config + 9) = time(0LL);
latest_exclude = *(&config + 5);
v4 = malloc(0x4000uLL);
config = (__int64)v4;
v5 = malloc(0x4000uLL);
*(&config + 1) = (__int64)v5;
*(&config + 2) = 0LL;
*(&config + 3) = 0LL;
*(&config + 6) = (__int64)info;
*(&config + 7) = (__int64)error;
*v4 = 0;
*v5 = 0;
*((_BYTE *)&config + 64) = 0;
*((_BYTE *)&config + 65) = 0;
if ( (int)parse_options((unsigned int)argc, argv) < 0 )
{
fprintf(stderr, "\nRun '%s --help' for help\n", *argv);
exit(64);
}
v6 = (char *)*(&config + 1);
if ( v6 == strstr(v6, "file://") )
{
*((_DWORD *)&config + 8) = 1;
}
else if ( v6 == strstr(v6, "ftp://") )
{
*((_DWORD *)&config + 8) = 2;
}
else if ( v6 == strstr(v6, "sftp://") )
{
*((_DWORD *)&config + 8) = 10;
}
else if ( v6 == strstr(v6, "ftps://") )
{
*((_DWORD *)&config + 8) = 2;
}
else
{
*((_DWORD *)&config + 8) = 1;
v17[0] = 0x2F2F3A656C6966LL;
strncat((char *)v17, v6, 0x3FF8uLL);
strcpy(v6, (const char *)v17);
}
puts("================================ CONFIG ================================");
v7 = "None";
if ( conf )
v7 = &conf;
printf("Configuration File: %s\n", v7);
printf("Source: %s\n", (const char *)config);
printf("Destination: %s\n", (const char *)*(&config + 1));
v8 = "yes";
if ( !*((_BYTE *)&config + 64) )
v8 = "no";
printf("Backuped before: %s\n", v8);
v9 = "yes";
if ( !*((_BYTE *)&config + 65) )
v9 = "no";
printf("Verbose output: %s\n", v9);
puts("========================================================================\n");
if ( destinationLogin )
{
v11 = getpass("User: ");
*(&config + 2) = (__int64)v11;
v12 = strlen(v11);
v13 = (char *)malloc(v12);
strcpy(v13, v11);
*(&config + 2) = (__int64)v13;
v14 = getpass("Password: ");
*(&config + 3) = (__int64)v14;
v15 = strlen(v14);
v16 = (char *)malloc(v15);
strcpy(v16, v14);
*(&config + 3) = (__int64)v16;
puts("\n");
}
frontdown(&config);
return 0;
}

original_code:
int main(int argc, char **argv){
 if((config.excludes = calloc(1, sizeof(struct frontdown_exclude_list)))==((void *)0)){
  fprintf(stderr,"Make sure you have enough memory and run it again");
  exit(1);
 }
 config.now=(long long)time(((void *)0));
 latest_exclude = config.excludes;
 config.source=malloc(16384);
 config.destination=malloc(16384);
 config.destinationUname=((void *)0);
 config.destinationPwd=((void *)0);
 config.info=&info;
 config.error=&error;
 config.source[0]=0;
 config.destination[0]=0;
 config.last_backup=0;
 config.verbose=0;
 if(parse_options(argc, argv)<0){
  fprintf(stderr,"\nRun '%s --help' for help\n", argv[0]);
  exit(64);
 }
 char urlbuffer[16384];
 if(strstr(config.destination, "file://") == config.destination) config.con_type=_FILE_;
 else if(strstr(config.destination, "ftp://") == config.destination) config.con_type=_FTP_;
 else if(strstr(config.destination, "sftp://") == config.destination) config.con_type=_SFTP_;
 else if(strstr(config.destination, "ftps://") == config.destination) config.con_type=_FTP_;
 else {
  config.con_type=_FILE_;
  strcpy(urlbuffer, "file://");
  strncat(urlbuffer, config.destination, 16384 -8);
  strcpy(config.destination, urlbuffer);
 }
 printf("================================ CONFIG ================================\n");
 printf("Configuration File:     %s\n", strlen(conf)==0?"None":conf);
 printf("Source:                 %s\n", config.source);
 printf("Destination:            %s\n", config.destination);
 printf("Backuped before:        %s\n", config.last_backup!=0?"yes":"no");
 printf("Verbose output:         %s\n", config.verbose!=0?"yes":"no");
 printf("========================================================================\n\n");
 char *buf;
 if(destinationLogin){
  config.destinationUname=getpass("User: ");
  buf=malloc(strlen(config.destinationUname));
  strcpy(buf, config.destinationUname);
  config.destinationUname=buf;
  config.destinationPwd=getpass("Password: ");
  buf=malloc(strlen(config.destinationPwd));
  strcpy(buf, config.destinationPwd);
  config.destinationPwd=buf;
  printf("\n\n");
 }
 frontdown(&config);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
urlbuffer
char [16384]

variable_types:
buf
char *

user_defined_types: struct frontdown_exclude_list { char exclude_path[16384]; struct frontdown_exclude_list *next; }


decompiled_code:
void search_destroy()
{
__int64 v0; // rbx

if ( _PARSER_SEARCH )
{
if ( _PARSER_KEYS_READ )
{
v0 = 0LL;
do
free(*((void **)_PARSER_SEARCH + v0++));
while ( _PARSER_KEYS_READ > (unsigned int)v0 );
}
free(_PARSER_SEARCH);
_PARSER_KEYS_READ = 0;
}
else
{
_PARSER_KEYS_READ = 0;
}
}

canonical_decompiled_code:
void func4()
{
__int64 v0; // rbx

if ( _PARSER_SEARCH )
{
if ( _PARSER_KEYS_READ )
{
v0 = 0LL;
do
free(*((void **)_PARSER_SEARCH + v0++));
while ( _PARSER_KEYS_READ > (unsigned int)v0 );
}
free(_PARSER_SEARCH);
_PARSER_KEYS_READ = 0;
}
else
{
_PARSER_KEYS_READ = 0;
}
}

original_code:
void search_destroy(void){
 int i;
 if(__PARSER_SEARCH != ((void *)0)){
  for(i=0; i<__PARSER_KEYS_READ; i++){
   free(__PARSER_SEARCH[i]);
  }
  free(__PARSER_SEARCH);
 }
 __PARSER_KEYS_READ = 0;
}

canonical_original_code:
void search_destroy(){
 int i;
 if(__PARSER_SEARCH != ((void *)0)){
  for(i=0; i<__PARSER_KEYS_READ; i++){
   free(__PARSER_SEARCH[i]);
  }
  free(__PARSER_SEARCH);
 }
 __PARSER_KEYS_READ = 0;
}

variable_types: i int


decompiled_code:
const char *__fastcall search_for_key(char *s2, char a2)
{
const char *v2; // r12
const char ***v3; // rbx
const char ***v4; // r13
const char **v5; // r12
const char ***v6; // rbx
const char ***v7; // r13
const char **v8; // r12

v2 = (const char *)_PARSER_SEARCH;
if ( _PARSER_SEARCH )
{
if ( a2 )
{
if ( _PARSER_KEYS_READ )
{
v3 = (const char ***)_PARSER_SEARCH;
v4 = (const char ***)((char *)_PARSER_SEARCH + 8 * (unsigned int)(_PARSER_KEYS_READ - 1) + 8);
while ( 1 )
{
v5 = *v3;
if ( !strcmp(**v3, s2) )
break;
if ( ++v3 == v4 )
return 0LL;
}
v2 = v5[1];
}
else
{
v2 = 0LL;
}
}
else if ( _PARSER_KEYS_READ )
{
v6 = (const char ***)_PARSER_SEARCH;
v7 = (const char ***)((char *)_PARSER_SEARCH + 8 * (unsigned int)(_PARSER_KEYS_READ - 1) + 8);
while ( 1 )
{
v8 = *v6;
if ( !strcasecmp(**v6, s2) )
break;
if ( ++v6 == v7 )
return 0LL;
}
v2 = v8[1];
}
else
{
v2 = 0LL;
}
}
else
{
perror("Error: Search was not initialized!\n");
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func5(char *s2, char a2)
{
const char *v2; // r12
const char ***v3; // rbx
const char ***v4; // r13
const char **v5; // r12
const char ***v6; // rbx
const char ***v7; // r13
const char **v8; // r12

v2 = (const char *)_PARSER_SEARCH;
if ( _PARSER_SEARCH )
{
if ( a2 )
{
if ( _PARSER_KEYS_READ )
{
v3 = (const char ***)_PARSER_SEARCH;
v4 = (const char ***)((char *)_PARSER_SEARCH + 8 * (unsigned int)(_PARSER_KEYS_READ - 1) + 8);
while ( 1 )
{
v5 = *v3;
if ( !strcmp(**v3, s2) )
break;
if ( ++v3 == v4 )
return 0LL;
}
v2 = v5[1];
}
else
{
v2 = 0LL;
}
}
else if ( _PARSER_KEYS_READ )
{
v6 = (const char ***)_PARSER_SEARCH;
v7 = (const char ***)((char *)_PARSER_SEARCH + 8 * (unsigned int)(_PARSER_KEYS_READ - 1) + 8);
while ( 1 )
{
v8 = *v6;
if ( !strcasecmp(**v6, s2) )
break;
if ( ++v6 == v7 )
return 0LL;
}
v2 = v8[1];
}
else
{
v2 = 0LL;
}
}
else
{
perror("Error: Search was not initialized!\n");
}
return v2;
}

original_code:
char *search_for_key(char *key, char case_sensitive){
 if(__PARSER_SEARCH == ((void *)0)){
  perror("Error: Search was not initialized!\n");
  return ((void *)0);
 }
 unsigned int i=0;
 if(case_sensitive == 0){
  for(i=0; i<__PARSER_KEYS_READ; i++){
   if(strcasecmp(__PARSER_SEARCH[i]->key, key) == 0)
    return __PARSER_SEARCH[i]->value;
  }
 } else {
  for(i=0; i<__PARSER_KEYS_READ; i++){
   if(strcmp(__PARSER_SEARCH[i]->key, key) == 0)
    return __PARSER_SEARCH[i]->value;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *search_for_key(char *key, char case_sensitive){
 if(__PARSER_SEARCH == ((void *)0)){
  perror("Error: Search was not initialized!\n");
  return ((void *)0);
 }
 unsigned int i = 0;
 if(case_sensitive == 0){
  for(i=0; i<__PARSER_KEYS_READ; i++){
   if(strcasecmp(__PARSER_SEARCH[i]->key, key) == 0)
    return __PARSER_SEARCH[i]->value;
  }
 } else {
  for(i=0; i<__PARSER_KEYS_READ; i++){
   if(strcmp(__PARSER_SEARCH[i]->key, key) == 0)
    return __PARSER_SEARCH[i]->value;
  }
 }
 return ((void *)0);
}

variable_types:
key
char *

variable_types:
i
unsigned int


decompiled_code:
void __fastcall key_value_destroy(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void key_value_destroy(struct key_value *keyval){
 if(keyval != ((void *)0)){
  if(keyval->key != ((void *)0))
   free(keyval->key);
  if(keyval->value != ((void *)0))
   free(keyval->value);
  free(keyval);
 }
}

variable_types: struct key_value { char *key; char *value; } *


upload

original_code:
int upload(struct frontdown_config *config, const char *source, char *relpath, char *name, struct stat filestat){
 char srcpathstring[16384*2]={0};
 char dstpathstring[16384*2]={0};
 char ret;
 int len=-1;
 strcpy(&srcpathstring[len+1], name);
 strcpy(dstpathstring, config->destination);
 len=strlen(config->destination);
 dstpathstring[len]='/';
 strcpy(&dstpathstring[len+1], relpath);
 len+=1+strlen(relpath);
 dstpathstring[len]='/';
 strcpy(&dstpathstring[len+1], name);
 config->info(dstpathstring);
 if((ret=put_file(config, srcpathstring, name, dstpathstring, filestat.st_size))==0){
  FilesUpdated++;
  return 0;
 } else if(ret==-1){
  FilesFailed++;
  return -1;
 } else {
  return -2;
 }
}

canonical_original_code:
int upload(struct frontdown_config *config, char *source, char *relpath, char *name, struct stat filestat){
 char srcpathstring[-1] = {0};
 char dstpathstring[-1] = {0};
 char ret;
 int len = -1;
 strcpy(&srcpathstring[len+1], name);
 strcpy(dstpathstring, config->destination);
 len=strlen(config->destination);
 dstpathstring[len]='/';
 strcpy(&dstpathstring[len+1], relpath);
 len+=1+strlen(relpath);
 dstpathstring[len]='/';
 strcpy(&dstpathstring[len+1], name);
 config->info(dstpathstring);
 if((ret=put_file(config, srcpathstring, name, dstpathstring, filestat.st_size))==0){
  FilesUpdated++;
  return 0;
 } else if(ret==-1){
  FilesFailed++;
  return -1;
 } else {
  return -2;
 }
}

variable_types:
source
char *

variable_types:
name
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
srcpathstring
char [-1]

variable_types:
dstpathstring
char [-1]

variable_types: ret char

variable_types: len int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: enum frontdown_connection_type { _DICT_=0, _FILE_=1, _FTP_=2, _HTTP_=3, _IMAP_=4, _LDAP_=5, _POP3_=6, _RTMP_=7, _RTSP_=8, _SCP_=9, _SFTP_=10, _SMTP_=11, _TELNET_=12, _TFTP_=13, _UNKNOWN_=14 }

user_defined_types: enum frontdown_error_code { _INDEX_DB_ERROR_=0, _MKDIR_ERROR_=1, _DST_CONNECTION_ERROR_=2, _PUT_FILE_ERROR_=3 }


decompiled_code:
__int64 __fastcall fd_scandir(__int64 a1, __int64 a2)
{
char *v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rbp
_QWORD *v5; // r12
__int64 v6; // rax
_QWORD *v7; // r15
int v8; // er15
_BYTE *v9; // r12
size_t v10; // rax
_BYTE *v11; // rax
char v12; // al
char path[32768]; // [rsp+10h] [rbp-18438h] BYREF
char dest[32768]; // [rsp+8010h] [rbp-10438h] BYREF
__int64 v16[128]; // [rsp+10010h] [rbp-8438h]
__int64 v17[2]; // [rsp+10410h] [rbp-8038h] BYREF
char s[32752]; // [rsp+10420h] [rbp-8028h] BYREF

v17[0] = 0LL;
v17[1] = 0LL;
memset(s, 0, sizeof(s));
strcpy(dest, *(const char **)a1);
v2 = get_current_dir_name();
strcpy(path, v2);
if ( chdir(*(const char **)a1) < 0 )
{
LABEL_19:
perror("chdir");
return 0xFFFFFFFFLL;
}
v3 = calloc(1uLL, 0x218uLL);
*(_WORD *)v3 = 46;
LOBYTE(v17[0]) = 46;
v16[0] = (__int64)v17 + 1;
create_dest_dir(a1, v17);
LODWORD(v4) = 0;
while ( 1 )
{
(*(void (__fastcall **)(__int64 *))(a1 + 48))(v17);
v12 = anakin_filewalker(a1, (__int64)v3, (char *)v3[64], (__int64)dest, (char *)v17, a2, *(_QWORD *)(a1 + 40));
if ( v12 )
break;
v5 = (_QWORD *)v3[66];
v6 = v3[65];
if ( !v6 )
goto LABEL_21;
v4 = (int)v4;
while ( 1 )
{
*(_QWORD *)(v6 + 512) = v5;
if ( v5 )
break;
v7 = (_QWORD *)v3[65];
free(v3);
if ( !v7[65] )
goto LABEL_21;
if ( chdir("..") < 0 )
goto LABEL_19;
**(_BYTE **)&dest[8 * v4 + 32760] = 0;
v5 = (_QWORD *)v7[66];
v6 = v7[65];
--v4;
if ( !v6 )
goto LABEL_21;
v3 = v7;
}
free(v3);
if ( chdir("..") < 0 )
goto LABEL_19;
v8 = v4 - 1;
*(_BYTE *)v16[(int)v4 - 1] = 0;
v3 = v5;
LABEL_14:
if ( chdir((const char *)v3) < 0 )
{
perror("chdir");
puts((const char *)v3);
return 0xFFFFFFFFLL;
}
LODWORD(v4) = v8 + 1;
v9 = (_BYTE *)v16[v8];
*v9 = 47;
v10 = strlen((const char *)v3);
memcpy(v9 + 1, v3, v10);
v11 = &v9[strlen((const char *)v3) + 1];
v16[v8 + 1] = (__int64)v11;
*v11 = 0;
create_dest_dir(a1, v17);
if ( !v3[65] )
{
LABEL_21:
printf("Total %d files\n \t\rUpdated %d files\n \t\rFailed on %d files\n", FilesFound, FilesUpdated, FilesFailed);
chdir(path);
return 0LL;
}
}
if ( v12 == 1 )
{
v3 = (_QWORD *)v3[64];
v8 = v4;
goto LABEL_14;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
char *v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rbp
_QWORD *v5; // r12
__int64 v6; // rax
_QWORD *v7; // r15
int v8; // er15
_BYTE *v9; // r12
size_t v10; // rax
_BYTE *v11; // rax
char v12; // al
char path[32768]; // [rsp+10h] [rbp-18438h] BYREF
char dest[32768]; // [rsp+8010h] [rbp-10438h] BYREF
__int64 v16[128]; // [rsp+10010h] [rbp-8438h]
__int64 v17[2]; // [rsp+10410h] [rbp-8038h] BYREF
char s[32752]; // [rsp+10420h] [rbp-8028h] BYREF

v17[0] = 0LL;
v17[1] = 0LL;
memset(s, 0, sizeof(s));
strcpy(dest, *(const char **)a1);
v2 = get_current_dir_name();
strcpy(path, v2);
if ( chdir(*(const char **)a1) < 0 )
{
LABEL_19:
perror("chdir");
return 0xFFFFFFFFLL;
}
v3 = calloc(1uLL, 0x218uLL);
*(_WORD *)v3 = 46;
LOBYTE(v17[0]) = 46;
v16[0] = (__int64)v17 + 1;
create_dest_dir(a1, v17);
LODWORD(v4) = 0;
while ( 1 )
{
(*(void (__fastcall **)(__int64 *))(a1 + 48))(v17);
v12 = func2(a1, (__int64)v3, (char *)v3[64], (__int64)dest, (char *)v17, a2, *(_QWORD *)(a1 + 40));
if ( v12 )
break;
v5 = (_QWORD *)v3[66];
v6 = v3[65];
if ( !v6 )
goto LABEL_21;
v4 = (int)v4;
while ( 1 )
{
*(_QWORD *)(v6 + 512) = v5;
if ( v5 )
break;
v7 = (_QWORD *)v3[65];
free(v3);
if ( !v7[65] )
goto LABEL_21;
if ( chdir("..") < 0 )
goto LABEL_19;
**(_BYTE **)&dest[8 * v4 + 32760] = 0;
v5 = (_QWORD *)v7[66];
v6 = v7[65];
--v4;
if ( !v6 )
goto LABEL_21;
v3 = v7;
}
free(v3);
if ( chdir("..") < 0 )
goto LABEL_19;
v8 = v4 - 1;
*(_BYTE *)v16[(int)v4 - 1] = 0;
v3 = v5;
LABEL_14:
if ( chdir((const char *)v3) < 0 )
{
perror("chdir");
puts((const char *)v3);
return 0xFFFFFFFFLL;
}
LODWORD(v4) = v8 + 1;
v9 = (_BYTE *)v16[v8];
*v9 = 47;
v10 = strlen((const char *)v3);
memcpy(v9 + 1, v3, v10);
v11 = &v9[strlen((const char *)v3) + 1];
v16[v8 + 1] = (__int64)v11;
*v11 = 0;
create_dest_dir(a1, v17);
if ( !v3[65] )
{
LABEL_21:
printf("Total %d files\n \t\rUpdated %d files\n \t\rFailed on %d files\n", FilesFound, FilesUpdated, FilesFailed);
chdir(path);
return 0LL;
}
}
if ( v12 == 1 )
{
v3 = (_QWORD *)v3[64];
v8 = v4;
goto LABEL_14;
}
return 0xFFFFFFFFLL;
}

original_code:
int fd_scandir(struct frontdown_config *config, long long timestamp){
 char pathstring[16384*2]={0};
 char *dirpointer[128];
 int dirptrc=0;
 char ret;
 struct dirnode *node, *root, *freewilli;
 char sourcepath[16384*2];
 strcpy(sourcepath, config->source);
 char orig_dir[16384*2];
 strcpy(orig_dir, get_current_dir_name());
 if(chdir(config->source)<0){
  perror("chdir");
  return -1;
 }
 root=calloc(1,sizeof(struct dirnode));
 strcpy(root->path, ".");
 pathstring[0]='.';
 dirpointer[dirptrc]=&pathstring[1];
 create_dest_dir(config, pathstring);
 node=root;
 do{
  config->info(pathstring);
  if((ret=anakin_filewalker(config, node, node->sub, sourcepath, pathstring, timestamp, config->excludes))==0){
   next_dir:
    freewilli=node;
    node=node->next;
    if(freewilli->top==((void *)0)) break;
    freewilli->top->sub=node;
    if(node==((void *)0)){
     node=freewilli->top;
     free(freewilli);
     if(node->top==((void *)0))break;
     if(chdir("..")<0){
      perror("chdir");
      return -1;
     }
     dirptrc--;
     *dirpointer[dirptrc]='\0';
   goto next_dir;
    }
   free(freewilli);
   if(chdir("..")<0){
    perror("chdir");
    return -1;
   }
   dirptrc--;
   *dirpointer[dirptrc]='\0';
  } else if(ret==1) {
   node=node->sub;
  } else {
   return -1;
  }
  if(chdir(node->path)<0){
   perror("chdir");
   puts(node->path);
   return -1;
  }
  dirptrc++;
  *dirpointer[dirptrc-1]='/';
  memcpy(dirpointer[dirptrc-1]+1, node->path, strlen(node->path));
  dirpointer[dirptrc]=dirpointer[dirptrc-1]+1+strlen(node->path);
  *dirpointer[dirptrc]='\0';
 create_dest_dir(config, pathstring);
 }while(node->top!=((void *)0));
 printf("Total %d files\n 	\rUpdated %d files\n 	\rFailed on %d files\n", FilesFound, FilesUpdated, FilesFailed);
 chdir(orig_dir);
 return 0;
}

canonical_original_code:
int fd_scandir(struct frontdown_config *config, long long timestamp){
 char pathstring[-1] = {0};
 char *dirpointer[128];
 int dirptrc = 0;
 char ret;
 struct dirnode *node; struct dirnode *root; struct dirnode *freewilli;
 char sourcepath[-1];
 strcpy(sourcepath, config->source);
 char orig_dir[-1];
 strcpy(orig_dir, get_current_dir_name());
 if(chdir(config->source)<0){
  perror("chdir");
  return -1;
 }
 root=calloc(1,sizeof(struct dirnode));
 strcpy(root->path, ".");
 pathstring[0]='.';
 dirpointer[dirptrc]=&pathstring[1];
 create_dest_dir(config, pathstring);
 node=root;
 do{
  config->info(pathstring);
  if((ret=anakin_filewalker(config, node, node->sub, sourcepath, pathstring, timestamp, config->excludes))==0){
   next_dir:
    freewilli=node;
    node=node->next;
    if(freewilli->top==((void *)0)) break;
    freewilli->top->sub=node;
    if(node==((void *)0)){
     node=freewilli->top;
     free(freewilli);
     if(node->top==((void *)0))break;
     if(chdir("..")<0){
      perror("chdir");
      return -1;
     }
     dirptrc--;
     *dirpointer[dirptrc]='\0';
   goto next_dir;
    }
   free(freewilli);
   if(chdir("..")<0){
    perror("chdir");
    return -1;
   }
   dirptrc--;
   *dirpointer[dirptrc]='\0';
  } else if(ret==1) {
   node=node->sub;
  } else {
   return -1;
  }
  if(chdir(node->path)<0){
   perror("chdir");
   puts(node->path);
   return -1;
  }
  dirptrc++;
  *dirpointer[dirptrc-1]='/';
  memcpy(dirpointer[dirptrc-1]+1, node->path, strlen(node->path));
  dirpointer[dirptrc]=dirpointer[dirptrc-1]+1+strlen(node->path);
  *dirpointer[dirptrc]='\0';
 create_dest_dir(config, pathstring);
 }while(node->top!=((void *)0));
 printf("Total %d files\n 	\rUpdated %d files\n 	\rFailed on %d files\n", FilesFound, FilesUpdated, FilesFailed);
 chdir(orig_dir);
 return 0;
}

variable_types: struct frontdown_config { char *source; char *destination; char *destinationUname; char *destinationPwd; enum frontdown_connection_type { _DICT_=0, _FILE_=1, _FTP_=2, _HTTP_=3, _IMAP_=4, _LDAP_=5, _POP3_=6, _RTMP_=7, _RTSP_=8, _SCP_=9, _SFTP_=10, _SMTP_=11, _TELNET_=12, _TFTP_=13, _UNKNOWN_=14 } con_type; struct frontdown_exclude_list { char exclude_path[16384]; struct frontdown_exclude_list *next; } *excludes; int (*info)(char *); int (*error)(enum frontdown_error_code { _INDEX_DB_ERROR_=0, _MKDIR_ERROR_=1, _DST_CONNECTION_ERROR_=2, _PUT_FILE_ERROR_=3 }, char, char *); char last_backup; char verbose; long long now; } *

variable_types:
timestamp
long long

variable_types:
pathstring
char [-1]

variable_types:
dirpointer
char *[128]

variable_types: dirptrc int

variable_types: struct dirnode { char path[512]; struct dirnode *sub; struct dirnode *top; struct dirnode *next; } *

variable_types:
sourcepath
char [-1]


decompiled_code:
__int64 parse_config()
{
const char *v0; // rax
const char *v1; // rbx
size_t v2; // rax
const char *v3; // rax
const char *v4; // rbx
size_t v5; // rax
const char *v6; // rdi
__int64 result; // rax

search_init(&conf);
v0 = (const char *)search_for_key("source", 0LL);
if ( v0
&& (v1 = v0,
v2 = strlen(v0),
memcpy(config, v1, v2 + 1),
v3 = (const char *)search_for_key("destination", 0LL),
(v4 = v3) != 0LL) )
{
v5 = strlen(v3);
memcpy(*(&config + 1), v4, v5 + 1);
v6 = (const char *)search_for_key("lastbackup", 0LL);
if ( v6 )
*((_BYTE *)&config + 64) = atoi(v6);
search_destroy(v6);
result = 1LL;
}
else
{
((void (*)(void))search_destroy)();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rax
const char *v1; // rbx
size_t v2; // rax
const char *v3; // rax
const char *v4; // rbx
size_t v5; // rax
const char *v6; // rdi
__int64 result; // rax

search_init(&conf);
v0 = (const char *)search_for_key("source", 0LL);
if ( v0
&& (v1 = v0,
v2 = strlen(v0),
memcpy(config, v1, v2 + 1),
v3 = (const char *)search_for_key("destination", 0LL),
(v4 = v3) != 0LL) )
{
v5 = strlen(v3);
memcpy(*(&config + 1), v4, v5 + 1);
v6 = (const char *)search_for_key("lastbackup", 0LL);
if ( v6 )
*((_BYTE *)&config + 64) = atoi(v6);
search_destroy(v6);
result = 1LL;
}
else
{
((void (*)(void))search_destroy)();
result = 0LL;
}
return result;
}

original_code:
int parse_config(void){
 search_init(conf);
 char *test_ptr;
 test_ptr = search_for_key("source", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.source, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("destination", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.destination, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("lastbackup", 0);
 if(test_ptr != ((void *)0)){
  config.last_backup = atoi(test_ptr);
 }
 search_destroy();
 return 1;
}

canonical_original_code:
int parse_config(){
 search_init(conf);
 char *test_ptr;
 test_ptr = search_for_key("source", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.source, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("destination", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.destination, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("lastbackup", 0);
 if(test_ptr != ((void *)0)){
  config.last_backup = atoi(test_ptr);
 }
 search_destroy();
 return 1;
}


decompiled_code:
__int64 __fastcall parse_options(int argc, char **argv)
{
char v2; // r15
char v3; // r14
char v4; // r13
int v5; // eax
unsigned int v6; // ebx
char *v7; // rbx
char *v8; // rax
int longind; // [rsp+Ch] [rbp-17Ch] BYREF
struct option longopts[11]; // [rsp+10h] [rbp-178h] BYREF

qmemcpy(longopts, &off_44C0, 0x140uLL);
longind = 0;
*((_BYTE *)&config + 64) = 0;
destinationLogin = 0;
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt_long(argc, argv, "s:d:t:hc:e:liuv", longopts, &longind);
v6 = v5;
if ( v5 == -1 )
break;
switch ( v5 )
{
case 's':
if ( v4 )
{
fwrite("Cannot use more than 1 source directory at the moment\n", 1uLL, 0x36uLL, stderr);
return (unsigned int)-1;
}
strncpy(config, optarg, 0x3FFFuLL);
v4 = 1;
break;
case 'd':
if ( v3 )
{
fwrite("Cannot use more than 1 destination directory at the moment\n", 1uLL, 0x3BuLL, stderr);
return (unsigned int)-1;
}
strncpy(*(&config + 1), optarg, 0x3FFFuLL);
v3 = 1;
break;
case 'l':
destinationLogin = 1;
break;
case 'h':
help();
exit(0);
case 'c':
if ( v2 )
{
fwrite("Only 1 configuration file is allowed\n", 1uLL, 0x25uLL, stderr);
return (unsigned int)-1;
}
strncpy(conf, optarg, 0x3FFFuLL);
if ( !(unsigned int)parse_config() )
{
fwrite("Error parsing configuration file\n", 1uLL, 0x21uLL, stderr);
return (unsigned int)-1;
}
v2 = 1;
break;
case 'e':
strncpy(latest_exclude, optarg, 0x3FFFuLL);
v7 = latest_exclude;
v8 = (char *)calloc(1uLL, 0x4008uLL);
*((_QWORD *)v7 + 2048) = v8;
latest_exclude = v8;
break;
case 'i':
*((_BYTE *)&config + 64) = 1;
break;
case 'v':
*((_BYTE *)&config + 65) = 1;
break;
default:
return (unsigned int)-1;
}
}
if ( v2 || v4 && v3 )
{
if ( optind < argc )
fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
else
v6 = 0;
}
else
{
fwrite("Need configuration file or source and destination\n", 1uLL, 0x32uLL, stderr);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv)
{
char v2; // r15
char v3; // r14
char v4; // r13
int v5; // eax
unsigned int v6; // ebx
char *v7; // rbx
char *v8; // rax
int longind; // [rsp+Ch] [rbp-17Ch] BYREF
struct option longopts[11]; // [rsp+10h] [rbp-178h] BYREF

qmemcpy(longopts, &off_44C0, 0x140uLL);
longind = 0;
*((_BYTE *)&config + 64) = 0;
destinationLogin = 0;
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt_long(argc, argv, "s:d:t:hc:e:liuv", longopts, &longind);
v6 = v5;
if ( v5 == -1 )
break;
switch ( v5 )
{
case 's':
if ( v4 )
{
fwrite("Cannot use more than 1 source directory at the moment\n", 1uLL, 0x36uLL, stderr);
return (unsigned int)-1;
}
strncpy(config, optarg, 0x3FFFuLL);
v4 = 1;
break;
case 'd':
if ( v3 )
{
fwrite("Cannot use more than 1 destination directory at the moment\n", 1uLL, 0x3BuLL, stderr);
return (unsigned int)-1;
}
strncpy(*(&config + 1), optarg, 0x3FFFuLL);
v3 = 1;
break;
case 'l':
destinationLogin = 1;
break;
case 'h':
help();
exit(0);
case 'c':
if ( v2 )
{
fwrite("Only 1 configuration file is allowed\n", 1uLL, 0x25uLL, stderr);
return (unsigned int)-1;
}
strncpy(conf, optarg, 0x3FFFuLL);
if ( !(unsigned int)parse_config() )
{
fwrite("Error parsing configuration file\n", 1uLL, 0x21uLL, stderr);
return (unsigned int)-1;
}
v2 = 1;
break;
case 'e':
strncpy(latest_exclude, optarg, 0x3FFFuLL);
v7 = latest_exclude;
v8 = (char *)calloc(1uLL, 0x4008uLL);
*((_QWORD *)v7 + 2048) = v8;
latest_exclude = v8;
break;
case 'i':
*((_BYTE *)&config + 64) = 1;
break;
case 'v':
*((_BYTE *)&config + 65) = 1;
break;
default:
return (unsigned int)-1;
}
}
if ( v2 || v4 && v3 )
{
if ( optind < argc )
fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
else
v6 = 0;
}
else
{
fwrite("Need configuration file or source and destination\n", 1uLL, 0x32uLL, stderr);
}
return v6;
}

original_code:
int parse_options(int argc, char **argv){
 struct option command_options[] = {
  {"source", 1, 0, 's'},
  {"destination", 1, 0, 'd'},
  {"help", 0, 0, 'h'},
  {"conf", 1, 0, 'c'},
  {"exclude", 1, 0, 'e'},
  {"login", 0, 0, 'l'},
  {"gui", 0, 0, 'u'},
  {"incremental", 0, 0, 'i'},
  {"verbose", 0, 0, 'v'},
  {0, 0, 0, 0}
 };
 int opt, option_index=0;
 config.last_backup = 0;
 destinationLogin = 0;
 char s=0, d=0, c=0;
 while(1){
  opt = getopt_long(argc, argv, "s:d:t:hc:e:liuv", command_options, &option_index);
  if(opt == -1)
   break;
  if(opt == 's'){
   if(s){
    fprintf(stderr, "Cannot use more than 1 source directory at the moment\n");
    return(-1);
   }
   strncpy(config.source, optarg, 16383);
   s=1;
  } else if(opt == 'd'){
   if(d){
    fprintf(stderr, "Cannot use more than 1 destination directory at the moment\n");
    return(-1);
   }
   strncpy(config.destination, optarg, 16383);
   d=1;
  } else if(opt == 'l'){
   destinationLogin = 1;
  } else if(opt == 'h'){
   help();
   exit(0);
  } else if(opt == 'c'){
   if(c){
    fprintf(stderr, "Only 1 configuration file is allowed\n");
    return(-1);
   }
   strncpy(conf, optarg, 16383);
   if(!parse_config()){
    fprintf(stderr, "Error parsing configuration file\n");
    return(-1);
   }
   c=1;
  } else if(opt == 'e'){
   strncpy(latest_exclude->exclude_path, optarg, 16383);
   latest_exclude->next = calloc(1, sizeof(struct frontdown_exclude_list));
   latest_exclude = latest_exclude->next;
  } else if(opt == 'i'){
   config.last_backup=1;
  } else if(opt == 'v'){
   config.verbose=1;
  } else{
   return(-1);
  }
 }
 if(!(c || (s && d))){
  fprintf(stderr, "Need configuration file or source and destination\n");
  return(-1);
 }
 if(optind < argc){
  fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
  return(-1);
 }
 return(0);
}

canonical_original_code:
int parse_options(int argc, char **argv){
 struct option command_options[] = {
  {"source", 1, 0, 's'},
  {"destination", 1, 0, 'd'},
  {"help", 0, 0, 'h'},
  {"conf", 1, 0, 'c'},
  {"exclude", 1, 0, 'e'},
  {"login", 0, 0, 'l'},
  {"gui", 0, 0, 'u'},
  {"incremental", 0, 0, 'i'},
  {"verbose", 0, 0, 'v'},
  {0, 0, 0, 0}
 };
 int opt; int option_index = 0;
 config.last_backup = 0;
 destinationLogin = 0;
 char s = 0; char d = 0; char c = 0;
 while(1){
  opt = getopt_long(argc, argv, "s:d:t:hc:e:liuv", command_options, &option_index);
  if(opt == -1)
   break;
  if(opt == 's'){
   if(s){
    fprintf(stderr, "Cannot use more than 1 source directory at the moment\n");
    return(-1);
   }
   strncpy(config.source, optarg, 16383);
   s=1;
  } else if(opt == 'd'){
   if(d){
    fprintf(stderr, "Cannot use more than 1 destination directory at the moment\n");
    return(-1);
   }
   strncpy(config.destination, optarg, 16383);
   d=1;
  } else if(opt == 'l'){
   destinationLogin = 1;
  } else if(opt == 'h'){
   help();
   exit(0);
  } else if(opt == 'c'){
   if(c){
    fprintf(stderr, "Only 1 configuration file is allowed\n");
    return(-1);
   }
   strncpy(conf, optarg, 16383);
   if(!parse_config()){
    fprintf(stderr, "Error parsing configuration file\n");
    return(-1);
   }
   c=1;
  } else if(opt == 'e'){
   strncpy(latest_exclude->exclude_path, optarg, 16383);
   latest_exclude->next = calloc(1, sizeof(struct frontdown_exclude_list));
   latest_exclude = latest_exclude->next;
  } else if(opt == 'i'){
   config.last_backup=1;
  } else if(opt == 'v'){
   config.verbose=1;
  } else{
   return(-1);
  }
 }
 if(!(c || (s && d))){
  fprintf(stderr, "Need configuration file or source and destination\n");
  return(-1);
 }
 if(optind < argc){
  fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
  return(-1);
 }
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

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

variable_types: opt int

variable_types: s char

variable_types: d char

variable_types: c char