runSimpleHighPassFilter

original_code:
void
runSimpleHighPassFilter(LADSPA_Handle Instance,
         unsigned long SampleCount) {
  LADSPA_Data * pfInput;
  LADSPA_Data * pfOutput;
  LADSPA_Data fAmountOfCurrent;
  LADSPA_Data fAmountOfLast;
  LADSPA_Data fComp;
  LADSPA_Data fLastOutput;
  SimpleFilter * psFilter;
  unsigned long lSampleIndex;
  psFilter = (SimpleFilter *)Instance;
  pfInput = psFilter->m_pfInput;
  pfOutput = psFilter->m_pfOutput;
  if (*psFilter->m_pfCutoff !=
      psFilter->m_fLastCutoff) {
    psFilter->m_fLastCutoff = *psFilter->m_pfCutoff;
    if (psFilter->m_fLastCutoff <= 0) {
      psFilter->m_fAmountOfCurrent = 1;
      psFilter->m_fAmountOfLast = 0;
    }
    else if (psFilter->m_fLastCutoff > psFilter->m_fSampleRate * 0.5) {
      psFilter->m_fAmountOfCurrent = psFilter->m_fAmountOfLast = 0;
    }
    else {
      psFilter->m_fAmountOfLast = 0;
      fComp = 2 - cos(psFilter->m_fTwoPiOverSampleRate
        * psFilter->m_fLastCutoff);
      psFilter->m_fAmountOfLast = fComp - (LADSPA_Data)sqrt(fComp * fComp - 1);
      psFilter->m_fAmountOfCurrent = 1 - psFilter->m_fAmountOfLast;
    }
  }
  fAmountOfCurrent = psFilter->m_fAmountOfCurrent;
  fAmountOfLast = psFilter->m_fAmountOfLast;
  fLastOutput = psFilter->m_fLastOutput;
  for (lSampleIndex = 0;
       lSampleIndex < SampleCount;
       lSampleIndex++) {
    fLastOutput
      = (fAmountOfCurrent * *pfInput
  + fAmountOfLast * fLastOutput);
    *(pfOutput++) = *(pfInput++) - fLastOutput;
  }
  psFilter->m_fLastOutput = fLastOutput;
}

canonical_original_code:
void runSimpleHighPassFilter(void *Instance, unsigned long SampleCount) {
  float *pfInput;
  float *pfOutput;
  float fAmountOfCurrent;
  float fAmountOfLast;
  float fComp;
  float fLastOutput;
  struct SimpleFilter *psFilter;
  unsigned long lSampleIndex;
  psFilter = (struct SimpleFilter *)Instance;
  pfInput = psFilter->m_pfInput;
  pfOutput = psFilter->m_pfOutput;
  if (*psFilter->m_pfCutoff !=
      psFilter->m_fLastCutoff) {
    psFilter->m_fLastCutoff = *psFilter->m_pfCutoff;
    if (psFilter->m_fLastCutoff <= 0) {
      psFilter->m_fAmountOfCurrent = 1;
      psFilter->m_fAmountOfLast = 0;
    }
    else if (psFilter->m_fLastCutoff > psFilter->m_fSampleRate * 0.5) {
      psFilter->m_fAmountOfCurrent = psFilter->m_fAmountOfLast = 0;
    }
    else {
      psFilter->m_fAmountOfLast = 0;
      fComp = 2 - cos(psFilter->m_fTwoPiOverSampleRate
        * psFilter->m_fLastCutoff);
      psFilter->m_fAmountOfLast = fComp - (float)sqrt(fComp * fComp - 1);
      psFilter->m_fAmountOfCurrent = 1 - psFilter->m_fAmountOfLast;
    }
  }
  fAmountOfCurrent = psFilter->m_fAmountOfCurrent;
  fAmountOfLast = psFilter->m_fAmountOfLast;
  fLastOutput = psFilter->m_fLastOutput;
  for (lSampleIndex = 0;
       lSampleIndex < SampleCount;
       lSampleIndex++) {
    fLastOutput
      = (fAmountOfCurrent * *pfInput
  + fAmountOfLast * fLastOutput);
    *(pfOutput++) = *(pfInput++) - fLastOutput;
  }
  psFilter->m_fLastOutput = fLastOutput;
}


cleanupSimpleFilter

repo: war-immo/ladspa

decompiled_code:
void __fastcall cleanupSimpleFilter(void *a1)
{
free(a1);
}

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

original_code:
void
cleanupSimpleFilter(LADSPA_Handle Instance) {
  free(Instance);
}

canonical_original_code:
void cleanupSimpleFilter(void *Instance) {
  free(Instance);
}

variable_types:
Instance
void *

return_type: void


deleteDescriptor

decompiled_code:
void __fastcall deleteDescriptor(void *ptr)
{
unsigned __int64 v1; // rbx

if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 7));
if ( *((_QWORD *)ptr + 6) )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 8) + 8 * v1++));
while ( *((_QWORD *)ptr + 6) > v1 );
}
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
unsigned __int64 v1; // rbx

if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 7));
if ( *((_QWORD *)ptr + 6) )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 8) + 8 * v1++));
while ( *((_QWORD *)ptr + 6) > v1 );
}
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}
}

original_code:
void
deleteDescriptor(LADSPA_Descriptor * psDescriptor) {
  unsigned long lIndex;
  if (psDescriptor) {
    free((char *)psDescriptor->Label);
    free((char *)psDescriptor->Name);
    free((char *)psDescriptor->Maker);
    free((char *)psDescriptor->Copyright);
    free((LADSPA_PortDescriptor *)psDescriptor->PortDescriptors);
    for (lIndex = 0; lIndex < psDescriptor->PortCount; lIndex++)
      free((char *)(psDescriptor->PortNames[lIndex]));
    free((char **)psDescriptor->PortNames);
    free((LADSPA_PortRangeHint *)psDescriptor->PortRangeHints);
    free(psDescriptor);
  }
}

canonical_original_code:
void deleteDescriptor(struct _LADSPA_Descriptor *psDescriptor) {
  unsigned long lIndex;
  if (psDescriptor) {
    free((char *)psDescriptor->Label);
    free((char *)psDescriptor->Name);
    free((char *)psDescriptor->Maker);
    free((char *)psDescriptor->Copyright);
    free((int *)psDescriptor->PortDescriptors);
    for (lIndex = 0; lIndex < psDescriptor->PortCount; lIndex++)
      free((char *)(psDescriptor->PortNames[lIndex]));
    free((char **)psDescriptor->PortNames);
    free((struct _LADSPA_PortRangeHint *)psDescriptor->PortRangeHints);
    free(psDescriptor);
  }
}

variable_types: struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; } *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); } *

variable_types:
lIndex
unsigned long

user_defined_types: struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); }


runSimpleDelayLine

original_code:
void
runSimpleDelayLine(LADSPA_Handle Instance,
     unsigned long SampleCount) {
  LADSPA_Data * pfBuffer;
  LADSPA_Data * pfInput;
  LADSPA_Data * pfOutput;
  LADSPA_Data fDry;
  LADSPA_Data fInputSample;
  LADSPA_Data fWet;
  SimpleDelayLine * psSimpleDelayLine;
  unsigned long lBufferReadOffset;
  unsigned long lBufferSizeMinusOne;
  unsigned long lBufferWriteOffset;
  unsigned long lDelay;
  unsigned long lSampleIndex;
  psSimpleDelayLine = (SimpleDelayLine *)Instance;
  lBufferSizeMinusOne = psSimpleDelayLine->m_lBufferSize - 1;
  lDelay = (unsigned long)
    ((((*(psSimpleDelayLine->m_pfDelay)) < 0) ? 0 : (((*(psSimpleDelayLine->m_pfDelay)) > 5) ? 5 : (*(psSimpleDelayLine->m_pfDelay))))
     * psSimpleDelayLine->m_fSampleRate);
  pfInput = psSimpleDelayLine->m_pfInput;
  pfOutput = psSimpleDelayLine->m_pfOutput;
  pfBuffer = psSimpleDelayLine->m_pfBuffer;
  lBufferWriteOffset = psSimpleDelayLine->m_lWritePointer;
  lBufferReadOffset
    = lBufferWriteOffset + psSimpleDelayLine->m_lBufferSize - lDelay;
  fWet = (((*(psSimpleDelayLine->m_pfDryWet)) < 0) ? 0 : (((*(psSimpleDelayLine->m_pfDryWet)) > 1) ? 1 : (*(psSimpleDelayLine->m_pfDryWet))));
  fDry = 1 - fWet;
  for (lSampleIndex = 0;
       lSampleIndex < SampleCount;
       lSampleIndex++) {
    fInputSample = *(pfInput++);
    *(pfOutput++) = (fDry * fInputSample
       + fWet * pfBuffer[((lSampleIndex + lBufferReadOffset)
     & lBufferSizeMinusOne)]);
    pfBuffer[((lSampleIndex + lBufferWriteOffset)
       & lBufferSizeMinusOne)] = fInputSample;
  }
  psSimpleDelayLine->m_lWritePointer
    = ((psSimpleDelayLine->m_lWritePointer + SampleCount)
       & lBufferSizeMinusOne);
}

canonical_original_code:
void runSimpleDelayLine(void *Instance, unsigned long SampleCount) {
  float *pfBuffer;
  float *pfInput;
  float *pfOutput;
  float fDry;
  float fInputSample;
  float fWet;
  struct SimpleDelayLine *psSimpleDelayLine;
  unsigned long lBufferReadOffset;
  unsigned long lBufferSizeMinusOne;
  unsigned long lBufferWriteOffset;
  unsigned long lDelay;
  unsigned long lSampleIndex;
  psSimpleDelayLine = (struct SimpleDelayLine *)Instance;
  lBufferSizeMinusOne = psSimpleDelayLine->m_lBufferSize - 1;
  lDelay = (unsigned long)
    ((((*(psSimpleDelayLine->m_pfDelay)) < 0) ? 0 : (((*(psSimpleDelayLine->m_pfDelay)) > 5) ? 5 : (*(psSimpleDelayLine->m_pfDelay))))
     * psSimpleDelayLine->m_fSampleRate);
  pfInput = psSimpleDelayLine->m_pfInput;
  pfOutput = psSimpleDelayLine->m_pfOutput;
  pfBuffer = psSimpleDelayLine->m_pfBuffer;
  lBufferWriteOffset = psSimpleDelayLine->m_lWritePointer;
  lBufferReadOffset
    = lBufferWriteOffset + psSimpleDelayLine->m_lBufferSize - lDelay;
  fWet = (((*(psSimpleDelayLine->m_pfDryWet)) < 0) ? 0 : (((*(psSimpleDelayLine->m_pfDryWet)) > 1) ? 1 : (*(psSimpleDelayLine->m_pfDryWet))));
  fDry = 1 - fWet;
  for (lSampleIndex = 0;
       lSampleIndex < SampleCount;
       lSampleIndex++) {
    fInputSample = *(pfInput++);
    *(pfOutput++) = (fDry * fInputSample
       + fWet * pfBuffer[((lSampleIndex + lBufferReadOffset)
     & lBufferSizeMinusOne)]);
    pfBuffer[((lSampleIndex + lBufferWriteOffset)
       & lBufferSizeMinusOne)] = fInputSample;
  }
  psSimpleDelayLine->m_lWritePointer
    = ((psSimpleDelayLine->m_lWritePointer + SampleCount)
       & lBufferSizeMinusOne);
}

variable_types:
SampleCount
unsigned long

variable_types:
pfBuffer
float *

variable_types:
pfInput
float *

variable_types:
pfOutput
float *

variable_types: fDry float

variable_types: fInputSample float

variable_types: fWet float

variable_types: struct SimpleDelayLine { float m_fSampleRate; float *m_pfBuffer; unsigned long m_lBufferSize; unsigned long m_lWritePointer; float *m_pfDelay; float *m_pfDryWet; float *m_pfInput; float *m_pfOutput; } *

variable_types:
lBufferReadOffset
unsigned long

variable_types:
lBufferSizeMinusOne
unsigned long

variable_types:
lBufferWriteOffset
unsigned long

variable_types:
lDelay
unsigned long

variable_types:
lSampleIndex
unsigned long


instantiateSimpleDelayLine

decompiled_code:
float *__fastcall instantiateSimpleDelayLine(__int64 a1, __int64 a2)
{
float *v2; // rbx
float v3; // xmm0_4
float v4; // xmm0_4
unsigned __int64 v5; // rax
size_t i; // rdi
void *v7; // rbp

v2 = (float *)malloc(0x40uLL);
if ( v2 )
{
if ( a2 < 0 )
v3 = (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1))
+ (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1));
else
v3 = (float)(int)a2;
*v2 = v3;
v4 = v3 * 5.0;
if ( v4 >= 9.223372e18 )
v5 = (unsigned int)(int)(float)(v4 - 9.223372e18) ^ 0x8000000000000000LL;
else
v5 = (unsigned int)(int)v4;
*((_QWORD *)v2 + 2) = 1LL;
if ( v5 <= 1 )
{
i = 1LL;
}
else
{
for ( i = 1LL; i < v5; i *= 2LL )
;
*((_QWORD *)v2 + 2) = i;
}
v7 = calloc(i, 4uLL);
*((_QWORD *)v2 + 1) = v7;
if ( v7 )
{
*((_QWORD *)v2 + 3) = 0LL;
}
else
{
free(v2);
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
float *__fastcall func2(__int64 a1, __int64 a2)
{
float *v2; // rbx
float v3; // xmm0_4
float v4; // xmm0_4
unsigned __int64 v5; // rax
size_t i; // rdi
void *v7; // rbp

v2 = (float *)malloc(0x40uLL);
if ( v2 )
{
if ( a2 < 0 )
v3 = (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1))
+ (float)(a2 & 1 | (unsigned int)((unsigned __int64)a2 >> 1));
else
v3 = (float)(int)a2;
*v2 = v3;
v4 = v3 * 5.0;
if ( v4 >= 9.223372e18 )
v5 = (unsigned int)(int)(float)(v4 - 9.223372e18) ^ 0x8000000000000000LL;
else
v5 = (unsigned int)(int)v4;
*((_QWORD *)v2 + 2) = 1LL;
if ( v5 <= 1 )
{
i = 1LL;
}
else
{
for ( i = 1LL; i < v5; i *= 2LL )
;
*((_QWORD *)v2 + 2) = i;
}
v7 = calloc(i, 4uLL);
*((_QWORD *)v2 + 1) = v7;
if ( v7 )
{
*((_QWORD *)v2 + 3) = 0LL;
}
else
{
free(v2);
v2 = 0LL;
}
}
return v2;
}

original_code:
LADSPA_Handle
instantiateSimpleDelayLine(const LADSPA_Descriptor * Descriptor,
      unsigned long SampleRate) {
  unsigned long lMinimumBufferSize;
  SimpleDelayLine * psDelayLine;
  psDelayLine
    = (SimpleDelayLine *)malloc(sizeof(SimpleDelayLine));
  if (psDelayLine == ((void *)0))
    return ((void *)0);
  psDelayLine->m_fSampleRate = (LADSPA_Data)SampleRate;
  lMinimumBufferSize = (unsigned long)((LADSPA_Data)SampleRate * 5);
  psDelayLine->m_lBufferSize = 1;
  while (psDelayLine->m_lBufferSize < lMinimumBufferSize)
    psDelayLine->m_lBufferSize <<= 1;
  psDelayLine->m_pfBuffer
    = (LADSPA_Data *)calloc(psDelayLine->m_lBufferSize, sizeof(LADSPA_Data));
  if (psDelayLine->m_pfBuffer == ((void *)0)) {
    free(psDelayLine);
    return ((void *)0);
  }
  psDelayLine->m_lWritePointer = 0;
  return psDelayLine;
}

canonical_original_code:
void *instantiateSimpleDelayLine(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate) {
  unsigned long lMinimumBufferSize;
  struct SimpleDelayLine *psDelayLine;
  psDelayLine
    = (struct SimpleDelayLine *)malloc(sizeof(SimpleDelayLine));
  if (psDelayLine == ((void *)0))
    return ((void *)0);
  psDelayLine->m_fSampleRate = (float)SampleRate;
  lMinimumBufferSize = (unsigned long)((float)SampleRate * 5);
  psDelayLine->m_lBufferSize = 1;
  while (psDelayLine->m_lBufferSize < lMinimumBufferSize)
    psDelayLine->m_lBufferSize <<= 1;
  psDelayLine->m_pfBuffer
    = (float *)calloc(psDelayLine->m_lBufferSize, sizeof(LADSPA_Data));
  if (psDelayLine->m_pfBuffer == ((void *)0)) {
    free(psDelayLine);
    return ((void *)0);
  }
  psDelayLine->m_lWritePointer = 0;
  return psDelayLine;
}

variable_types:
SampleRate
unsigned long

variable_types:
lMinimumBufferSize
unsigned long

return_type: void *

user_defined_types: struct SimpleDelayLine { float m_fSampleRate; float *m_pfBuffer; unsigned long m_lBufferSize; unsigned long m_lWritePointer; float *m_pfDelay; float *m_pfDryWet; float *m_pfInput; float *m_pfOutput; }

user_defined_types: struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; }


cleanupSimpleDelayLine

decompiled_code:
void __fastcall cleanupSimpleDelayLine(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void
cleanupSimpleDelayLine(LADSPA_Handle Instance) {
  SimpleDelayLine * psSimpleDelayLine;
  psSimpleDelayLine = (SimpleDelayLine *)Instance;
  free(psSimpleDelayLine->m_pfBuffer);
  free(psSimpleDelayLine);
}

canonical_original_code:
void cleanupSimpleDelayLine(void *Instance) {
  struct SimpleDelayLine *psSimpleDelayLine;
  psSimpleDelayLine = (struct SimpleDelayLine *)Instance;
  free(psSimpleDelayLine->m_pfBuffer);
  free(psSimpleDelayLine);
}

variable_types:
Instance
void *


activateSimpleDelayLine

decompiled_code:
void *__fastcall activateSimpleDelayLine(__int64 a1)
{
return memset(*(void **)(a1 + 8), 0, 4LL * *(_QWORD *)(a1 + 16));
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
return memset(*(void **)(a1 + 8), 0, 4LL * *(_QWORD *)(a1 + 16));
}

original_code:
void
activateSimpleDelayLine(LADSPA_Handle Instance) {
  SimpleDelayLine * psSimpleDelayLine;
  psSimpleDelayLine = (SimpleDelayLine *)Instance;
  memset(psSimpleDelayLine->m_pfBuffer,
  0,
  sizeof(LADSPA_Data) * psSimpleDelayLine->m_lBufferSize);
}

canonical_original_code:
void activateSimpleDelayLine(void *Instance) {
  struct SimpleDelayLine *psSimpleDelayLine;
  psSimpleDelayLine = (struct SimpleDelayLine *)Instance;
  memset(psSimpleDelayLine->m_pfBuffer,
  0,
  sizeof(LADSPA_Data) * psSimpleDelayLine->m_lBufferSize);
}


setNoiseSourceRunAddingGain

decompiled_code:
void __fastcall setNoiseSourceRunAddingGain(__int64 a1, float a2)
{
*(float *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, float a2)
{
*(float *)(a1 + 16) = a2;
}

original_code:
void
setNoiseSourceRunAddingGain(LADSPA_Handle Instance,
       LADSPA_Data Gain) {
  ((NoiseSource *)Instance)->m_fRunAddingGain = Gain;
}

canonical_original_code:
void setNoiseSourceRunAddingGain(void *Instance, float Gain) {
  ((struct NoiseSource *)Instance)->m_fRunAddingGain = Gain;
}

variable_types: Gain float

user_defined_types: struct NoiseSource { float *m_pfAmplitudeValue; float *m_pfOutputBuffer; float m_fRunAddingGain; }


instantiateNoiseSource

decompiled_code:
void *instantiateNoiseSource()
{
return malloc(0x18uLL);
}

canonical_decompiled_code:
void *func2()
{
return malloc(0x18uLL);
}

original_code:
LADSPA_Handle
instantiateNoiseSource(const LADSPA_Descriptor * Descriptor,
         unsigned long SampleRate) {
  return malloc(sizeof(NoiseSource));
}

canonical_original_code:
void *instantiateNoiseSource(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate) {
  return malloc(sizeof(NoiseSource));
}

variable_types: struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; } *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); } *


runNoiseSource

decompiled_code:
float *__fastcall runNoiseSource(float **a1, __int64 a2)
{
float *result; // rax
float *v3; // r12
__int64 i; // rbx
float v5; // [rsp+Ch] [rbp-1Ch]

result = *a1;
v5 = 9.3132257e-10 * **a1;
v3 = a1[1];
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
result = (float *)(unsigned int)(rand() - 0x3FFFFFFF);
v3[i] = (float)(int)result * v5;
}
}
return result;
}

canonical_decompiled_code:
float *__fastcall func3(float **a1, __int64 a2)
{
float *result; // rax
float *v3; // r12
__int64 i; // rbx
float v5; // [rsp+Ch] [rbp-1Ch]

result = *a1;
v5 = 9.3132257e-10 * **a1;
v3 = a1[1];
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
result = (float *)(unsigned int)(rand() - 0x3FFFFFFF);
v3[i] = (float)(int)result * v5;
}
}
return result;
}

original_code:
void
runNoiseSource(LADSPA_Handle Instance,
        unsigned long SampleCount) {
  NoiseSource * psNoiseSource;
  LADSPA_Data * pfOutput;
  LADSPA_Data fAmplitude;
  unsigned long lSampleIndex;
  psNoiseSource = (NoiseSource *)Instance;
  fAmplitude
    = *(psNoiseSource->m_pfAmplitudeValue) * (LADSPA_Data)(2.0 / 2147483647);
  pfOutput = psNoiseSource->m_pfOutputBuffer;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = (rand() - (2147483647 / 2)) * fAmplitude;
}

canonical_original_code:
void runNoiseSource(void *Instance, unsigned long SampleCount) {
  struct NoiseSource *psNoiseSource;
  float *pfOutput;
  float fAmplitude;
  unsigned long lSampleIndex;
  psNoiseSource = (struct NoiseSource *)Instance;
  fAmplitude
    = *(psNoiseSource->m_pfAmplitudeValue) * (LADSPA_Data)(2.0 / 2147483647);
  pfOutput = psNoiseSource->m_pfOutputBuffer;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) = (rand() - (2147483647 / 2)) * fAmplitude;
}

variable_types:
SampleCount
unsigned long

variable_types: struct NoiseSource { float *m_pfAmplitudeValue; float *m_pfOutputBuffer; float m_fRunAddingGain; } *

variable_types: fAmplitude float


runAddingNoiseSource

decompiled_code:
float *__fastcall runAddingNoiseSource(__int64 a1, __int64 a2)
{
float *result; // rax
__int64 v3; // rbp
__int64 i; // rbx
float v5; // [rsp+Ch] [rbp-1Ch]

result = *(float **)a1;
v5 = (float)(**(float **)a1 * *(float *)(a1 + 16)) * 9.3132257e-10;
v3 = *(_QWORD *)(a1 + 8);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
result = (float *)(unsigned int)(rand() - 0x3FFFFFFF);
*(float *)(v3 + 4 * i) = (float)((float)(int)result * v5) + *(float *)(v3 + 4 * i);
}
}
return result;
}

canonical_decompiled_code:
float *__fastcall func4(__int64 a1, __int64 a2)
{
float *result; // rax
__int64 v3; // rbp
__int64 i; // rbx
float v5; // [rsp+Ch] [rbp-1Ch]

result = *(float **)a1;
v5 = (float)(**(float **)a1 * *(float *)(a1 + 16)) * 9.3132257e-10;
v3 = *(_QWORD *)(a1 + 8);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
result = (float *)(unsigned int)(rand() - 0x3FFFFFFF);
*(float *)(v3 + 4 * i) = (float)((float)(int)result * v5) + *(float *)(v3 + 4 * i);
}
}
return result;
}

original_code:
void
runAddingNoiseSource(LADSPA_Handle Instance,
       unsigned long SampleCount) {
  NoiseSource * psNoiseSource;
  LADSPA_Data * pfOutput;
  LADSPA_Data fAmplitude;
  unsigned long lSampleIndex;
  psNoiseSource = (NoiseSource *)Instance;
  fAmplitude
    = (*(psNoiseSource->m_pfAmplitudeValue)
       * psNoiseSource->m_fRunAddingGain
       * (LADSPA_Data)(2.0 / 2147483647));
  pfOutput = psNoiseSource->m_pfOutputBuffer;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) += (rand() - (2147483647 / 2)) * fAmplitude;
}

canonical_original_code:
void runAddingNoiseSource(void *Instance, unsigned long SampleCount) {
  struct NoiseSource *psNoiseSource;
  float *pfOutput;
  float fAmplitude;
  unsigned long lSampleIndex;
  psNoiseSource = (struct NoiseSource *)Instance;
  fAmplitude
    = (*(psNoiseSource->m_pfAmplitudeValue)
       * psNoiseSource->m_fRunAddingGain
       * (LADSPA_Data)(2.0 / 2147483647));
  pfOutput = psNoiseSource->m_pfOutputBuffer;
  for (lSampleIndex = 0; lSampleIndex < SampleCount; lSampleIndex++)
    *(pfOutput++) += (rand() - (2147483647 / 2)) * fAmplitude;
}

variable_types:
pfOutput
float *


cleanupNoiseSource

decompiled_code:
void __fastcall cleanupNoiseSource(void *a1)
{
free(a1);
}

original_code:
void
cleanupNoiseSource(LADSPA_Handle Instance) {
  free(Instance);
}

canonical_original_code:
void cleanupNoiseSource(void *Instance) {
  free(Instance);
}


analysePlugin

decompiled_code:
__int64 __fastcall analysePlugin(const char *a1, const char *a2, int a3)
{
unsigned __int64 v3; // r15
size_t v4; // r14
__int64 i; // rbp
char *v6; // rcx
__int64 result; // rax
double v8; // xmm0_8
double v9; // xmm0_8
__int64 v10; // rax
__int64 v11; // rbx
size_t v12; // rax
unsigned __int64 v13; // rax
size_t v14; // r14
unsigned __int64 v15; // r15
__int64 j; // rax
double v17; // xmm0_8
unsigned __int64 k; // rbp
unsigned __int64 *v19; // rbx
size_t v20; // rbp
unsigned __int64 v21; // rax
__int64 v22; // r12
float v23; // xmm0_4
float v24; // xmm0_4
float v25; // xmm0_4
double v26; // xmm1_8
float v27; // xmm0_4
double v28; // xmm1_8
int v29; // eax
int v30; // eax
__int64 v31; // r13
int v32; // ebp
int v33; // eax
__int64 v34; // [rsp+0h] [rbp-68h]
__int64 (__fastcall *v35)(__int64); // [rsp+8h] [rbp-60h]
void *v37; // [rsp+20h] [rbp-48h]
double v38; // [rsp+28h] [rbp-40h]
double v39; // [rsp+28h] [rbp-40h]

v37 = (void *)loadLADSPAPluginLibrary();
dlerror();
v35 = (__int64 (__fastcall *)(__int64))dlsym(v37, "ladspa_descriptor");
if ( v35 )
{
if ( a3 )
{
v15 = 0LL;
v14 = 0LL;
}
else
{
v3 = 0LL;
v4 = 0LL;
for ( i = 0LL; ; ++i )
{
v10 = v35(i);
v11 = v10;
if ( !v10 )
break;
if ( !a2 || !strcmp(a2, *(const char **)(v10 + 8)) )
{
v12 = strlen(*(const char **)(v11 + 8));
if ( v4 < v12 )
v4 = v12;
v13 = *(_QWORD *)v11;
if ( *(__int64 *)v11 < 0 )
v8 = (double)(int)(*(_DWORD *)v11 & 1 | (v13 >> 1)) + (double)(int)(*(_DWORD *)v11 & 1 | (v13 >> 1));
else
v8 = (double)(int)v13;
v9 = log10(v8);
if ( v3 < (unsigned __int64)(unsigned int)(int)v9 + 1 )
v3 = (unsigned int)(int)v9 + 1LL;
}
}
v14 = v4 + 2;
v15 = v3 + 2;
}
v34 = 0LL;
for ( j = v35(0LL); ; j = v35(v34) )
{
v19 = (unsigned __int64 *)j;
if ( !j )
break;
if ( a2 && strcmp(a2, *(const char **)(j + 8)) )
goto LABEL_24;
if ( !a3 )
{
printf("%s", (const char *)v19[1]);
v20 = strlen((const char *)v19[1]);
if ( v14 > v20 )
{
do
{
putchar(32);
++v20;
}
while ( v14 != v20 );
}
printf("%lu", *v19);
v21 = *v19;
if ( (*v19 & 0x8000000000000000LL) != 0LL )
v17 = (double)(int)(*(_DWORD *)v19 & 1 | (v21 >> 1)) + (double)(int)(*(_DWORD *)v19 & 1 | (v21 >> 1));
else
v17 = (double)(int)v21;
for ( k = (unsigned int)(int)log10(v17) + 1LL; v15 > k; ++k )
putchar(32);
puts((const char *)v19[3]);
goto LABEL_24;
}
putchar(10);
printf("Plugin Name: \"%s\"\n", (const char *)v19[3]);
printf("Plugin Label: \"%s\"\n", (const char *)v19[1]);
printf("Plugin Unique ID: %lu\n", *v19);
printf("Maker: \"%s\"\n", (const char *)v19[4]);
printf("Copyright: \"%s\"\n", (const char *)v19[5]);
printf("Must Run Real-Time: ");
if ( (v19[2] & 1) != 0 )
puts("Yes");
else
puts("No");
printf("Has activate() Function: ");
if ( v19[13] )
puts("Yes");
else
puts("No");
printf("Has deactivate() Function: ");
if ( v19[17] )
puts("Yes");
else
puts("No");
printf("Has run_adding() Function: ");
if ( v19[15] )
puts("Yes");
else
puts("No");
if ( !v19[11] )
puts("ERROR: PLUGIN HAS NO INSTANTIATE FUNCTION.");
if ( !v19[12] )
puts("ERROR: PLUGIN HAS NO CONNECT_PORT FUNCTION.");
if ( !v19[14] )
puts("ERROR: PLUGIN HAS NO RUN FUNCTION.");
if ( !v19[15]
|| !v19[16] && (puts("ERROR: PLUGIN HAS RUN_ADDING FUNCTION BUT NOT SET_RUN_ADDING_GAIN."), !v19[15]) )
{
if ( v19[16] )
puts("ERROR: PLUGIN HAS SET_RUN_ADDING_GAIN FUNCTION BUT NOT RUN_ADDING.");
}
if ( !v19[18] )
puts("ERROR: PLUGIN HAS NO CLEANUP FUNCTION.");
printf("Environment: ");
if ( (v19[2] & 4) != 0 )
puts("Normal or Hard Real-Time");
else
puts("Normal");
if ( (v19[2] & 2) != 0 )
puts("This plugin cannot use in-place processing. It will not work with all hosts.");
printf("Ports:");
if ( v19[6] || (puts("\tERROR: PLUGIN HAS NO PORTS."), v19[6]) )
{
v22 = 0LL;
while ( 1 )
{
printf("\t\"%s\" ", *(const char **)(v19[8] + 8 * v22));
v29 = *(_DWORD *)(v19[7] + 4 * v22);
if ( (v29 & 3) == 3 )
{
printf("ERROR: INPUT AND OUTPUT");
}
else if ( (v29 & 1) != 0 )
{
printf("input");
}
else if ( (v29 & 2) != 0 )
{
printf("output");
}
else
{
printf("ERROR: NEITHER INPUT NOR OUTPUT");
}
v30 = *(_DWORD *)(v19[7] + 4 * v22);
if ( (v30 & 0xC) == 12 )
{
printf(", ERROR: CONTROL AND AUDIO");
}
else if ( (v30 & 4) != 0 )
{
printf(", control");
}
else if ( (v30 & 8) != 0 )
{
printf(", audio");
}
else
{
printf(", ERROR: NEITHER CONTROL NOR AUDIO");
}
v31 = 12 * v22;
v32 = *(_DWORD *)(v19[9] + 12 * v22);
if ( (v32 & 3) != 0 )
{
printf(", ");
if ( (v32 & 1) != 0 )
{
v23 = *(float *)(v19[9] + v31 + 4);
if ( (v32 & 8) != 0 && v23 != 0.0 )
printf("%g*srate", v23);
else
printf("%g", v23);
}
else
{
printf("...");
}
printf(" to ");
if ( (v32 & 2) != 0 )
{
v24 = *(float *)(v19[9] + v31 + 8);
if ( (v32 & 8) != 0 && v24 != 0.0 )
printf("%g*srate", v24);
else
printf("%g", v24);
}
else
{
printf("...");
}
}
if ( (v32 & 4) != 0 )
{
if ( (v32 | 0x240) == 580 )
printf(", toggled");
else
printf(", ERROR: TOGGLED INCOMPATIBLE WITH OTHER HINT");
}
v33 = v32 & 0x3C0;
if ( v33 == 320 )
break;
if ( (v32 & 0x3C0u) > 0x140 )
{
if ( v33 == 640 )
{
printf(", default 100");
}
else if ( (v32 & 0x3C0u) <= 0x280 )
{
if ( v33 == 512 )
{
printf(", default 0");
}
else
{
if ( v33 != 576 )
goto LABEL_151;
printf(", default 1");
}
}
else
{
if ( v33 != 704 )
goto LABEL_151;
printf(", default 440");
}
}
else
{
if ( v33 == 128 )
{
if ( (v32 & 0x10) != 0 )
{
v38 = log(*(float *)(v19[9] + v31 + 4));
v26 = log(*(float *)(v19[9] + v31 + 8));
v25 = exp(v38 * 0.75 + v26 * 0.25);
}
else
{
v25 = *(float *)(v19[9] + v31 + 8) * 0.25 + *(float *)(v19[9] + v31 + 4) * 0.75;
}
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
goto LABEL_120;
}
if ( (v32 & 0x3C0u) > 0x80 )
{
if ( v33 == 192 )
{
if ( (v32 & 0x10) != 0 )
{
v27 = *(float *)(v19[9] + v31 + 4) * *(float *)(v19[9] + v31 + 8);
if ( v27 < 0.0 )
v25 = sqrtf(v27);
else
v25 = fsqrt(v27);
}
else
{
v25 = (float)(*(float *)(v19[9] + v31 + 4) + *(float *)(v19[9] + v31 + 8)) * 0.5;
}
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
}
else
{
if ( v33 != 256 )
{
LABEL_151:
printf(", UNKNOWN DEFAULT CODE");
goto LABEL_122;
}
if ( (v32 & 0x10) != 0 )
{
v39 = log(*(float *)(v19[9] + v31 + 4));
v28 = log(*(float *)(v19[9] + v31 + 8));
v25 = exp(v39 * 0.25 + v28 * 0.75);
}
else
{
v25 = *(float *)(v19[9] + v31 + 8) * 0.75 + *(float *)(v19[9] + v31 + 4) * 0.25;
}
if ( (v32 & 8) == 0 || v25 == 0.0 )
{
LABEL_149:
printf(", default %g", v25);
goto LABEL_122;
}
}
goto LABEL_120;
}
if ( (v32 & 0x3C0) != 0 )
{
if ( v33 != 64 )
goto LABEL_151;
v25 = *(float *)(v19[9] + v31 + 4);
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
goto LABEL_120;
}
}
LABEL_122:
if ( (v32 & 0x10) != 0 )
printf(", logarithmic");
if ( (v32 & 0x20) != 0 )
printf(", integer");
putchar(10);
if ( v19[6] <= ++v22 )
goto LABEL_24;
}
v25 = *(float *)(v19[9] + v31 + 8);
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
LABEL_120:
printf(", default %g*srate", v25);
goto LABEL_122;
}
LABEL_24:
++v34;
}
if ( a3 )
putchar(10);
unloadLADSPAPluginLibrary(v37);
result = 0LL;
}
else
{
v6 = dlerror();
result = 1LL;
if ( v6 )
{
fprintf(
stderr,
"Unable to find ladspa_descriptor() function in plugin file \"%s\": %s.\n"
"Are you sure this is a LADSPA plugin file?\n",
a1,
v6);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2, int a3)
{
unsigned __int64 v3; // r15
size_t v4; // r14
__int64 i; // rbp
char *v6; // rcx
__int64 result; // rax
double v8; // xmm0_8
double v9; // xmm0_8
__int64 v10; // rax
__int64 v11; // rbx
size_t v12; // rax
unsigned __int64 v13; // rax
size_t v14; // r14
unsigned __int64 v15; // r15
__int64 j; // rax
double v17; // xmm0_8
unsigned __int64 k; // rbp
unsigned __int64 *v19; // rbx
size_t v20; // rbp
unsigned __int64 v21; // rax
__int64 v22; // r12
float v23; // xmm0_4
float v24; // xmm0_4
float v25; // xmm0_4
double v26; // xmm1_8
float v27; // xmm0_4
double v28; // xmm1_8
int v29; // eax
int v30; // eax
__int64 v31; // r13
int v32; // ebp
int v33; // eax
__int64 v34; // [rsp+0h] [rbp-68h]
__int64 (__fastcall *v35)(__int64); // [rsp+8h] [rbp-60h]
void *v37; // [rsp+20h] [rbp-48h]
double v38; // [rsp+28h] [rbp-40h]
double v39; // [rsp+28h] [rbp-40h]

v37 = (void *)loadLADSPAPluginLibrary();
dlerror();
v35 = (__int64 (__fastcall *)(__int64))dlsym(v37, "ladspa_descriptor");
if ( v35 )
{
if ( a3 )
{
v15 = 0LL;
v14 = 0LL;
}
else
{
v3 = 0LL;
v4 = 0LL;
for ( i = 0LL; ; ++i )
{
v10 = v35(i);
v11 = v10;
if ( !v10 )
break;
if ( !a2 || !strcmp(a2, *(const char **)(v10 + 8)) )
{
v12 = strlen(*(const char **)(v11 + 8));
if ( v4 < v12 )
v4 = v12;
v13 = *(_QWORD *)v11;
if ( *(__int64 *)v11 < 0 )
v8 = (double)(int)(*(_DWORD *)v11 & 1 | (v13 >> 1)) + (double)(int)(*(_DWORD *)v11 & 1 | (v13 >> 1));
else
v8 = (double)(int)v13;
v9 = log10(v8);
if ( v3 < (unsigned __int64)(unsigned int)(int)v9 + 1 )
v3 = (unsigned int)(int)v9 + 1LL;
}
}
v14 = v4 + 2;
v15 = v3 + 2;
}
v34 = 0LL;
for ( j = v35(0LL); ; j = v35(v34) )
{
v19 = (unsigned __int64 *)j;
if ( !j )
break;
if ( a2 && strcmp(a2, *(const char **)(j + 8)) )
goto LABEL_24;
if ( !a3 )
{
printf("%s", (const char *)v19[1]);
v20 = strlen((const char *)v19[1]);
if ( v14 > v20 )
{
do
{
putchar(32);
++v20;
}
while ( v14 != v20 );
}
printf("%lu", *v19);
v21 = *v19;
if ( (*v19 & 0x8000000000000000LL) != 0LL )
v17 = (double)(int)(*(_DWORD *)v19 & 1 | (v21 >> 1)) + (double)(int)(*(_DWORD *)v19 & 1 | (v21 >> 1));
else
v17 = (double)(int)v21;
for ( k = (unsigned int)(int)log10(v17) + 1LL; v15 > k; ++k )
putchar(32);
puts((const char *)v19[3]);
goto LABEL_24;
}
putchar(10);
printf("Plugin Name: \"%s\"\n", (const char *)v19[3]);
printf("Plugin Label: \"%s\"\n", (const char *)v19[1]);
printf("Plugin Unique ID: %lu\n", *v19);
printf("Maker: \"%s\"\n", (const char *)v19[4]);
printf("Copyright: \"%s\"\n", (const char *)v19[5]);
printf("Must Run Real-Time: ");
if ( (v19[2] & 1) != 0 )
puts("Yes");
else
puts("No");
printf("Has activate() Function: ");
if ( v19[13] )
puts("Yes");
else
puts("No");
printf("Has deactivate() Function: ");
if ( v19[17] )
puts("Yes");
else
puts("No");
printf("Has run_adding() Function: ");
if ( v19[15] )
puts("Yes");
else
puts("No");
if ( !v19[11] )
puts("ERROR: PLUGIN HAS NO INSTANTIATE FUNCTION.");
if ( !v19[12] )
puts("ERROR: PLUGIN HAS NO CONNECT_PORT FUNCTION.");
if ( !v19[14] )
puts("ERROR: PLUGIN HAS NO RUN FUNCTION.");
if ( !v19[15]
|| !v19[16] && (puts("ERROR: PLUGIN HAS RUN_ADDING FUNCTION BUT NOT SET_RUN_ADDING_GAIN."), !v19[15]) )
{
if ( v19[16] )
puts("ERROR: PLUGIN HAS SET_RUN_ADDING_GAIN FUNCTION BUT NOT RUN_ADDING.");
}
if ( !v19[18] )
puts("ERROR: PLUGIN HAS NO CLEANUP FUNCTION.");
printf("Environment: ");
if ( (v19[2] & 4) != 0 )
puts("Normal or Hard Real-Time");
else
puts("Normal");
if ( (v19[2] & 2) != 0 )
puts("This plugin cannot use in-place processing. It will not work with all hosts.");
printf("Ports:");
if ( v19[6] || (puts("\tERROR: PLUGIN HAS NO PORTS."), v19[6]) )
{
v22 = 0LL;
while ( 1 )
{
printf("\t\"%s\" ", *(const char **)(v19[8] + 8 * v22));
v29 = *(_DWORD *)(v19[7] + 4 * v22);
if ( (v29 & 3) == 3 )
{
printf("ERROR: INPUT AND OUTPUT");
}
else if ( (v29 & 1) != 0 )
{
printf("input");
}
else if ( (v29 & 2) != 0 )
{
printf("output");
}
else
{
printf("ERROR: NEITHER INPUT NOR OUTPUT");
}
v30 = *(_DWORD *)(v19[7] + 4 * v22);
if ( (v30 & 0xC) == 12 )
{
printf(", ERROR: CONTROL AND AUDIO");
}
else if ( (v30 & 4) != 0 )
{
printf(", control");
}
else if ( (v30 & 8) != 0 )
{
printf(", audio");
}
else
{
printf(", ERROR: NEITHER CONTROL NOR AUDIO");
}
v31 = 12 * v22;
v32 = *(_DWORD *)(v19[9] + 12 * v22);
if ( (v32 & 3) != 0 )
{
printf(", ");
if ( (v32 & 1) != 0 )
{
v23 = *(float *)(v19[9] + v31 + 4);
if ( (v32 & 8) != 0 && v23 != 0.0 )
printf("%g*srate", v23);
else
printf("%g", v23);
}
else
{
printf("...");
}
printf(" to ");
if ( (v32 & 2) != 0 )
{
v24 = *(float *)(v19[9] + v31 + 8);
if ( (v32 & 8) != 0 && v24 != 0.0 )
printf("%g*srate", v24);
else
printf("%g", v24);
}
else
{
printf("...");
}
}
if ( (v32 & 4) != 0 )
{
if ( (v32 | 0x240) == 580 )
printf(", toggled");
else
printf(", ERROR: TOGGLED INCOMPATIBLE WITH OTHER HINT");
}
v33 = v32 & 0x3C0;
if ( v33 == 320 )
break;
if ( (v32 & 0x3C0u) > 0x140 )
{
if ( v33 == 640 )
{
printf(", default 100");
}
else if ( (v32 & 0x3C0u) <= 0x280 )
{
if ( v33 == 512 )
{
printf(", default 0");
}
else
{
if ( v33 != 576 )
goto LABEL_151;
printf(", default 1");
}
}
else
{
if ( v33 != 704 )
goto LABEL_151;
printf(", default 440");
}
}
else
{
if ( v33 == 128 )
{
if ( (v32 & 0x10) != 0 )
{
v38 = log(*(float *)(v19[9] + v31 + 4));
v26 = log(*(float *)(v19[9] + v31 + 8));
v25 = exp(v38 * 0.75 + v26 * 0.25);
}
else
{
v25 = *(float *)(v19[9] + v31 + 8) * 0.25 + *(float *)(v19[9] + v31 + 4) * 0.75;
}
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
goto LABEL_120;
}
if ( (v32 & 0x3C0u) > 0x80 )
{
if ( v33 == 192 )
{
if ( (v32 & 0x10) != 0 )
{
v27 = *(float *)(v19[9] + v31 + 4) * *(float *)(v19[9] + v31 + 8);
if ( v27 < 0.0 )
v25 = sqrtf(v27);
else
v25 = fsqrt(v27);
}
else
{
v25 = (float)(*(float *)(v19[9] + v31 + 4) + *(float *)(v19[9] + v31 + 8)) * 0.5;
}
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
}
else
{
if ( v33 != 256 )
{
LABEL_151:
printf(", UNKNOWN DEFAULT CODE");
goto LABEL_122;
}
if ( (v32 & 0x10) != 0 )
{
v39 = log(*(float *)(v19[9] + v31 + 4));
v28 = log(*(float *)(v19[9] + v31 + 8));
v25 = exp(v39 * 0.25 + v28 * 0.75);
}
else
{
v25 = *(float *)(v19[9] + v31 + 8) * 0.75 + *(float *)(v19[9] + v31 + 4) * 0.25;
}
if ( (v32 & 8) == 0 || v25 == 0.0 )
{
LABEL_149:
printf(", default %g", v25);
goto LABEL_122;
}
}
goto LABEL_120;
}
if ( (v32 & 0x3C0) != 0 )
{
if ( v33 != 64 )
goto LABEL_151;
v25 = *(float *)(v19[9] + v31 + 4);
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
goto LABEL_120;
}
}
LABEL_122:
if ( (v32 & 0x10) != 0 )
printf(", logarithmic");
if ( (v32 & 0x20) != 0 )
printf(", integer");
putchar(10);
if ( v19[6] <= ++v22 )
goto LABEL_24;
}
v25 = *(float *)(v19[9] + v31 + 8);
if ( (v32 & 8) == 0 || v25 == 0.0 )
goto LABEL_149;
LABEL_120:
printf(", default %g*srate", v25);
goto LABEL_122;
}
LABEL_24:
++v34;
}
if ( a3 )
putchar(10);
unloadLADSPAPluginLibrary(v37);
result = 0LL;
}
else
{
v6 = dlerror();
result = 1LL;
if ( v6 )
{
fprintf(
stderr,
"Unable to find ladspa_descriptor() function in plugin file \"%s\": %s.\n"
"Are you sure this is a LADSPA plugin file?\n",
a1,
v6);
result = 1LL;
}
}
return result;
}

original_code:
static int
analysePlugin(const char * pcPluginFilename,
       const char * pcPluginLabel,
       const int bVerbose) {
  LADSPA_Descriptor_Function pfDescriptorFunction;
  const LADSPA_Descriptor * psDescriptor;
  unsigned long lPluginIndex;
  unsigned long lPortIndex;
  unsigned long lSpaceIndex;
  unsigned long lSpacePadding1;
  unsigned long lSpacePadding2;
  unsigned long lLength;
  void * pvPluginHandle;
  LADSPA_PortRangeHintDescriptor iHintDescriptor;
  LADSPA_Data fBound;
  LADSPA_Data fDefault;
  pvPluginHandle = loadLADSPAPluginLibrary(pcPluginFilename);
  dlerror();
  pfDescriptorFunction
    = (LADSPA_Descriptor_Function)dlsym(pvPluginHandle, "ladspa_descriptor");
  if (!pfDescriptorFunction) {
    const char * pcError = dlerror();
    if (pcError)
      fprintf(stderr,
       "Unable to find ladspa_descriptor() function in plugin file "
       "\"%s\": %s.\n"
       "Are you sure this is a LADSPA plugin file?\n",
       pcPluginFilename,
       pcError);
    return 1;
  }
  lSpacePadding1 = 0;
  lSpacePadding2 = 0;
  if (!bVerbose) {
    for (lPluginIndex = 0;; lPluginIndex++) {
      psDescriptor = pfDescriptorFunction(lPluginIndex);
      if (!psDescriptor)
 break;
      if (pcPluginLabel != ((void *)0))
 if (strcmp(pcPluginLabel, psDescriptor->Label) != 0)
   continue;
      lLength = strlen(psDescriptor->Label);
      if (lSpacePadding1 < lLength)
 lSpacePadding1 = lLength;
      lLength = (long)(log10(psDescriptor->UniqueID)) + 1;
      if (lSpacePadding2 < lLength)
 lSpacePadding2 = lLength;
    }
    lSpacePadding1 += 2;
    lSpacePadding2 += 2;
  }
  for (lPluginIndex = 0;; lPluginIndex++) {
    psDescriptor = pfDescriptorFunction(lPluginIndex);
    if (!psDescriptor)
      break;
    if (pcPluginLabel != ((void *)0))
      if (strcmp(pcPluginLabel, psDescriptor->Label) != 0)
 continue;
    if (!bVerbose) {
      printf("%s", psDescriptor->Label);
      for (lSpaceIndex = strlen(psDescriptor->Label);
    lSpaceIndex < lSpacePadding1;
    lSpaceIndex++)
 putchar(' ');
      printf("%lu", psDescriptor->UniqueID);
      for (lSpaceIndex = (long)(log10(psDescriptor->UniqueID)) + 1;
    lSpaceIndex < lSpacePadding2;
    lSpaceIndex++)
 putchar(' ');
      puts(psDescriptor->Name);
    }
    else {
      putchar('\n');
      printf("Plugin Name: \"%s\"\n", psDescriptor->Name);
      printf("Plugin Label: \"%s\"\n", psDescriptor->Label);
      printf("Plugin Unique ID: %lu\n", psDescriptor->UniqueID);
      printf("Maker: \"%s\"\n", psDescriptor->Maker);
      printf("Copyright: \"%s\"\n", psDescriptor->Copyright);
      printf("Must Run Real-Time: ");
      if (((psDescriptor->Properties) & 0x1))
 printf("Yes\n");
      else
 printf("No\n");
      printf("Has activate() Function: ");
      if (psDescriptor->activate != ((void *)0))
 printf("Yes\n");
      else
 printf("No\n");
      printf("Has deactivate() Function: ");
      if (psDescriptor->deactivate != ((void *)0))
 printf("Yes\n");
      else
 printf("No\n");
      printf("Has run_adding() Function: ");
      if (psDescriptor->run_adding != ((void *)0))
 printf("Yes\n");
      else
 printf("No\n");
      if (psDescriptor->instantiate == ((void *)0))
 printf("ERROR: PLUGIN HAS NO INSTANTIATE FUNCTION.\n");
      if (psDescriptor->connect_port == ((void *)0))
 printf("ERROR: PLUGIN HAS NO CONNECT_PORT FUNCTION.\n");
      if (psDescriptor->run == ((void *)0))
 printf("ERROR: PLUGIN HAS NO RUN FUNCTION.\n");
      if (psDescriptor->run_adding != ((void *)0)
   && psDescriptor->set_run_adding_gain == ((void *)0))
 printf("ERROR: PLUGIN HAS RUN_ADDING FUNCTION BUT "
        "NOT SET_RUN_ADDING_GAIN.\n");
      if (psDescriptor->run_adding == ((void *)0)
   && psDescriptor->set_run_adding_gain != ((void *)0))
 printf("ERROR: PLUGIN HAS SET_RUN_ADDING_GAIN FUNCTION BUT "
        "NOT RUN_ADDING.\n");
      if (psDescriptor->cleanup == ((void *)0))
 printf("ERROR: PLUGIN HAS NO CLEANUP FUNCTION.\n");
      printf("Environment: ");
      if (((psDescriptor->Properties) & 0x4))
 printf("Normal or Hard Real-Time\n");
      else
 printf("Normal\n");
      if (((psDescriptor->Properties) & 0x2))
 printf("This plugin cannot use in-place processing. "
        "It will not work with all hosts.\n");
      printf("Ports:");
      if (psDescriptor->PortCount == 0)
 printf("\tERROR: PLUGIN HAS NO PORTS.\n");
      for (lPortIndex = 0;
    lPortIndex < psDescriptor->PortCount;
    lPortIndex++) {
 printf("\t\"%s\" ", psDescriptor->PortNames[lPortIndex]);
 if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x1)
     && ((psDescriptor->PortDescriptors[lPortIndex]) & 0x2))
   printf("ERROR: INPUT AND OUTPUT");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x1))
   printf("input");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x2))
   printf("output");
 else
   printf("ERROR: NEITHER INPUT NOR OUTPUT");
 if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x4)
     && ((psDescriptor->PortDescriptors[lPortIndex]) & 0x8))
   printf(", ERROR: CONTROL AND AUDIO");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x4))
   printf(", control");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x8))
   printf(", audio");
 else
   printf(", ERROR: NEITHER CONTROL NOR AUDIO");
 iHintDescriptor
   = psDescriptor->PortRangeHints[lPortIndex].HintDescriptor;
 if (((iHintDescriptor) & 0x1)
     || ((iHintDescriptor) & 0x2)) {
   printf(", ");
   if (((iHintDescriptor) & 0x1)) {
     fBound = psDescriptor->PortRangeHints[lPortIndex].LowerBound;
     if (((iHintDescriptor) & 0x8) && fBound != 0)
       printf("%g*srate", fBound);
     else
       printf("%g", fBound);
   }
   else
     printf("...");
   printf(" to ");
   if (((iHintDescriptor) & 0x2)) {
     fBound = psDescriptor->PortRangeHints[lPortIndex].UpperBound;
     if (((iHintDescriptor) & 0x8) && fBound != 0)
       printf("%g*srate", fBound);
     else
       printf("%g", fBound);
   }
   else
     printf("...");
 }
 if (((iHintDescriptor) & 0x4)) {
   if ((iHintDescriptor
        | 0x200
        | 0x240)
        != (0x4
     | 0x200
     | 0x240))
     printf(", ERROR: TOGGLED INCOMPATIBLE WITH OTHER HINT");
   else
     printf(", toggled");
 }
 switch (iHintDescriptor & 0x3C0) {
 case 0x0:
   break;
 case 0x40:
   fDefault = psDescriptor->PortRangeHints[lPortIndex].LowerBound;
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x80:
   if (((iHintDescriptor) & 0x10)) {
     fDefault
       = exp(log(psDescriptor->PortRangeHints[lPortIndex].LowerBound)
      * 0.75
      + log(psDescriptor->PortRangeHints[lPortIndex].UpperBound)
      * 0.25);
   }
   else {
     fDefault
       = (psDescriptor->PortRangeHints[lPortIndex].LowerBound
   * 0.75
   + psDescriptor->PortRangeHints[lPortIndex].UpperBound
   * 0.25);
   }
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0xC0:
   if (((iHintDescriptor) & 0x10)) {
     fDefault
       = sqrt(psDescriptor->PortRangeHints[lPortIndex].LowerBound
       * psDescriptor->PortRangeHints[lPortIndex].UpperBound);
   }
   else {
     fDefault
       = 0.5 * (psDescriptor->PortRangeHints[lPortIndex].LowerBound
         + psDescriptor->PortRangeHints[lPortIndex].UpperBound);
   }
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x100:
   if (((iHintDescriptor) & 0x10)) {
     fDefault
       = exp(log(psDescriptor->PortRangeHints[lPortIndex].LowerBound)
      * 0.25
      + log(psDescriptor->PortRangeHints[lPortIndex].UpperBound)
      * 0.75);
   }
   else {
     fDefault
       = (psDescriptor->PortRangeHints[lPortIndex].LowerBound
   * 0.25
   + psDescriptor->PortRangeHints[lPortIndex].UpperBound
   * 0.75);
   }
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x140:
   fDefault = psDescriptor->PortRangeHints[lPortIndex].UpperBound;
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x200:
   printf(", default 0");
   break;
 case 0x240:
   printf(", default 1");
   break;
 case 0x280:
   printf(", default 100");
   break;
 case 0x2C0:
   printf(", default 440");
   break;
 default:
   printf(", UNKNOWN DEFAULT CODE");
   break;
 }
 if (((iHintDescriptor) & 0x10))
   printf(", logarithmic");
 if (((iHintDescriptor) & 0x20))
   printf(", integer");
 putchar('\n');
      }
    }
  }
  if (bVerbose)
    putchar('\n');
  unloadLADSPAPluginLibrary(pvPluginHandle);
  return(0);
}

canonical_original_code:
static int analysePlugin(char *pcPluginFilename, char *pcPluginLabel, int bVerbose) {
  struct _LADSPA_Descriptor *(*pfDescriptorFunction)(unsigned long Index);
  struct _LADSPA_Descriptor *psDescriptor;
  unsigned long lPluginIndex;
  unsigned long lPortIndex;
  unsigned long lSpaceIndex;
  unsigned long lSpacePadding1;
  unsigned long lSpacePadding2;
  unsigned long lLength;
  void *pvPluginHandle;
  int iHintDescriptor;
  float fBound;
  float fDefault;
  pvPluginHandle = loadLADSPAPluginLibrary(pcPluginFilename);
  dlerror();
  pfDescriptorFunction
    = (struct _LADSPA_Descriptor *(*)(unsigned long Index))dlsym(pvPluginHandle, "ladspa_descriptor");
  if (!pfDescriptorFunction) {
    char *pcError = dlerror();
    if (pcError)
      fprintf(stderr,
       "Unable to find ladspa_descriptor() function in plugin file "
       "\"%s\": %s.\n"
       "Are you sure this is a LADSPA plugin file?\n",
       pcPluginFilename,
       pcError);
    return 1;
  }
  lSpacePadding1 = 0;
  lSpacePadding2 = 0;
  if (!bVerbose) {
    for (lPluginIndex = 0;; lPluginIndex++) {
      psDescriptor = pfDescriptorFunction(lPluginIndex);
      if (!psDescriptor)
 break;
      if (pcPluginLabel != ((void *)0))
 if (strcmp(pcPluginLabel, psDescriptor->Label) != 0)
   continue;
      lLength = strlen(psDescriptor->Label);
      if (lSpacePadding1 < lLength)
 lSpacePadding1 = lLength;
      lLength = (long)(log10(psDescriptor->UniqueID)) + 1;
      if (lSpacePadding2 < lLength)
 lSpacePadding2 = lLength;
    }
    lSpacePadding1 += 2;
    lSpacePadding2 += 2;
  }
  for (lPluginIndex = 0;; lPluginIndex++) {
    psDescriptor = pfDescriptorFunction(lPluginIndex);
    if (!psDescriptor)
      break;
    if (pcPluginLabel != ((void *)0))
      if (strcmp(pcPluginLabel, psDescriptor->Label) != 0)
 continue;
    if (!bVerbose) {
      printf("%s", psDescriptor->Label);
      for (lSpaceIndex = strlen(psDescriptor->Label);
    lSpaceIndex < lSpacePadding1;
    lSpaceIndex++)
 putchar(' ');
      printf("%lu", psDescriptor->UniqueID);
      for (lSpaceIndex = (long)(log10(psDescriptor->UniqueID)) + 1;
    lSpaceIndex < lSpacePadding2;
    lSpaceIndex++)
 putchar(' ');
      puts(psDescriptor->Name);
    }
    else {
      putchar('\n');
      printf("Plugin Name: \"%s\"\n", psDescriptor->Name);
      printf("Plugin Label: \"%s\"\n", psDescriptor->Label);
      printf("Plugin Unique ID: %lu\n", psDescriptor->UniqueID);
      printf("Maker: \"%s\"\n", psDescriptor->Maker);
      printf("Copyright: \"%s\"\n", psDescriptor->Copyright);
      printf("Must Run Real-Time: ");
      if (((psDescriptor->Properties) & 0x1))
 printf("Yes\n");
      else
 printf("No\n");
      printf("Has activate() Function: ");
      if (psDescriptor->activate != ((void *)0))
 printf("Yes\n");
      else
 printf("No\n");
      printf("Has deactivate() Function: ");
      if (psDescriptor->deactivate != ((void *)0))
 printf("Yes\n");
      else
 printf("No\n");
      printf("Has run_adding() Function: ");
      if (psDescriptor->run_adding != ((void *)0))
 printf("Yes\n");
      else
 printf("No\n");
      if (psDescriptor->instantiate == ((void *)0))
 printf("ERROR: PLUGIN HAS NO INSTANTIATE FUNCTION.\n");
      if (psDescriptor->connect_port == ((void *)0))
 printf("ERROR: PLUGIN HAS NO CONNECT_PORT FUNCTION.\n");
      if (psDescriptor->run == ((void *)0))
 printf("ERROR: PLUGIN HAS NO RUN FUNCTION.\n");
      if (psDescriptor->run_adding != ((void *)0)
   && psDescriptor->set_run_adding_gain == ((void *)0))
 printf("ERROR: PLUGIN HAS RUN_ADDING FUNCTION BUT "
        "NOT SET_RUN_ADDING_GAIN.\n");
      if (psDescriptor->run_adding == ((void *)0)
   && psDescriptor->set_run_adding_gain != ((void *)0))
 printf("ERROR: PLUGIN HAS SET_RUN_ADDING_GAIN FUNCTION BUT "
        "NOT RUN_ADDING.\n");
      if (psDescriptor->cleanup == ((void *)0))
 printf("ERROR: PLUGIN HAS NO CLEANUP FUNCTION.\n");
      printf("Environment: ");
      if (((psDescriptor->Properties) & 0x4))
 printf("Normal or Hard Real-Time\n");
      else
 printf("Normal\n");
      if (((psDescriptor->Properties) & 0x2))
 printf("This plugin cannot use in-place processing. "
        "It will not work with all hosts.\n");
      printf("Ports:");
      if (psDescriptor->PortCount == 0)
 printf("\tERROR: PLUGIN HAS NO PORTS.\n");
      for (lPortIndex = 0;
    lPortIndex < psDescriptor->PortCount;
    lPortIndex++) {
 printf("\t\"%s\" ", psDescriptor->PortNames[lPortIndex]);
 if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x1)
     && ((psDescriptor->PortDescriptors[lPortIndex]) & 0x2))
   printf("ERROR: INPUT AND OUTPUT");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x1))
   printf("input");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x2))
   printf("output");
 else
   printf("ERROR: NEITHER INPUT NOR OUTPUT");
 if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x4)
     && ((psDescriptor->PortDescriptors[lPortIndex]) & 0x8))
   printf(", ERROR: CONTROL AND AUDIO");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x4))
   printf(", control");
 else if (((psDescriptor->PortDescriptors[lPortIndex]) & 0x8))
   printf(", audio");
 else
   printf(", ERROR: NEITHER CONTROL NOR AUDIO");
 iHintDescriptor
   = psDescriptor->PortRangeHints[lPortIndex].HintDescriptor;
 if (((iHintDescriptor) & 0x1)
     || ((iHintDescriptor) & 0x2)) {
   printf(", ");
   if (((iHintDescriptor) & 0x1)) {
     fBound = psDescriptor->PortRangeHints[lPortIndex].LowerBound;
     if (((iHintDescriptor) & 0x8) && fBound != 0)
       printf("%g*srate", fBound);
     else
       printf("%g", fBound);
   }
   else
     printf("...");
   printf(" to ");
   if (((iHintDescriptor) & 0x2)) {
     fBound = psDescriptor->PortRangeHints[lPortIndex].UpperBound;
     if (((iHintDescriptor) & 0x8) && fBound != 0)
       printf("%g*srate", fBound);
     else
       printf("%g", fBound);
   }
   else
     printf("...");
 }
 if (((iHintDescriptor) & 0x4)) {
   if ((iHintDescriptor
        | 0x200
        | 0x240)
        != (0x4
     | 0x200
     | 0x240))
     printf(", ERROR: TOGGLED INCOMPATIBLE WITH OTHER HINT");
   else
     printf(", toggled");
 }
 switch (iHintDescriptor & 0x3C0) {
 case 0x0:
   break;
 case 0x40:
   fDefault = psDescriptor->PortRangeHints[lPortIndex].LowerBound;
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x80:
   if (((iHintDescriptor) & 0x10)) {
     fDefault
       = exp(log(psDescriptor->PortRangeHints[lPortIndex].LowerBound)
      * 0.75
      + log(psDescriptor->PortRangeHints[lPortIndex].UpperBound)
      * 0.25);
   }
   else {
     fDefault
       = (psDescriptor->PortRangeHints[lPortIndex].LowerBound
   * 0.75
   + psDescriptor->PortRangeHints[lPortIndex].UpperBound
   * 0.25);
   }
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0xC0:
   if (((iHintDescriptor) & 0x10)) {
     fDefault
       = sqrt(psDescriptor->PortRangeHints[lPortIndex].LowerBound
       * psDescriptor->PortRangeHints[lPortIndex].UpperBound);
   }
   else {
     fDefault
       = 0.5 * (psDescriptor->PortRangeHints[lPortIndex].LowerBound
         + psDescriptor->PortRangeHints[lPortIndex].UpperBound);
   }
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x100:
   if (((iHintDescriptor) & 0x10)) {
     fDefault
       = exp(log(psDescriptor->PortRangeHints[lPortIndex].LowerBound)
      * 0.25
      + log(psDescriptor->PortRangeHints[lPortIndex].UpperBound)
      * 0.75);
   }
   else {
     fDefault
       = (psDescriptor->PortRangeHints[lPortIndex].LowerBound
   * 0.25
   + psDescriptor->PortRangeHints[lPortIndex].UpperBound
   * 0.75);
   }
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x140:
   fDefault = psDescriptor->PortRangeHints[lPortIndex].UpperBound;
   if (((iHintDescriptor) & 0x8) && fDefault != 0)
     printf(", default %g*srate", fDefault);
   else
     printf(", default %g", fDefault);
   break;
 case 0x200:
   printf(", default 0");
   break;
 case 0x240:
   printf(", default 1");
   break;
 case 0x280:
   printf(", default 100");
   break;
 case 0x2C0:
   printf(", default 440");
   break;
 default:
   printf(", UNKNOWN DEFAULT CODE");
   break;
 }
 if (((iHintDescriptor) & 0x10))
   printf(", logarithmic");
 if (((iHintDescriptor) & 0x20))
   printf(", integer");
 putchar('\n');
      }
    }
  }
  if (bVerbose)
    putchar('\n');
  unloadLADSPAPluginLibrary(pvPluginHandle);
  return(0);
}

variable_types:
pcPluginFilename
char *

variable_types:
pcPluginLabel
char *

variable_types: bVerbose int

variable_types: struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; } *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); } *(*)(unsigned long Index)

variable_types:
lPluginIndex
unsigned long

variable_types:
lPortIndex
unsigned long

variable_types:
lSpaceIndex
unsigned long

variable_types:
lLength
unsigned long

variable_types:
pvPluginHandle
void *

variable_types: iHintDescriptor int

variable_types: fBound float

variable_types: fDefault float

variable_types:
pcError
char *

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
const char *v5; // rsi
int v6; // edx

if ( argc == 3 )
{
v4 = argv[1];
if ( strcmp(v4, "-l") )
{
v5 = argv[2];
goto LABEL_12;
}
v4 = argv[2];
v5 = 0LL;
}
else
{
if ( argc != 4 )
{
if ( argc == 2 )
{
v4 = argv[1];
if ( strcmp(v4, "-h") )
{
v5 = 0LL;
LABEL_12:
v6 = 1;
return analysePlugin(v4, v5, v6);
}
}
LABEL_4:
fwrite(
"Usage:\tanalyseplugin [flags] <LADSPA plugin file name> [<plugin label>].\n"
"Flags:-l Produce a summary list rather than a verbose report.\n"
"Note that the LADSPA_PATH environment variable is used to help find plugins.\n",
1uLL,
0xD5uLL,
stderr);
return 1;
}
if ( strcmp(argv[1], "-l") )
goto LABEL_4;
v4 = argv[2];
v5 = argv[3];
}
v6 = 0;
if ( !v4 )
goto LABEL_4;
return analysePlugin(v4, v5, v6);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
const char *v5; // rsi
int v6; // edx

if ( argc == 3 )
{
v4 = argv[1];
if ( strcmp(v4, "-l") )
{
v5 = argv[2];
goto LABEL_12;
}
v4 = argv[2];
v5 = 0LL;
}
else
{
if ( argc != 4 )
{
if ( argc == 2 )
{
v4 = argv[1];
if ( strcmp(v4, "-h") )
{
v5 = 0LL;
LABEL_12:
v6 = 1;
return func0(v4, v5, v6);
}
}
LABEL_4:
fwrite(
"Usage:\tanalyseplugin [flags] <LADSPA plugin file name> [<plugin label>].\n"
"Flags:-l Produce a summary list rather than a verbose report.\n"
"Note that the LADSPA_PATH environment variable is used to help find plugins.\n",
1uLL,
0xD5uLL,
stderr);
return 1;
}
if ( strcmp(argv[1], "-l") )
goto LABEL_4;
v4 = argv[2];
v5 = argv[3];
}
v6 = 0;
if ( !v4 )
goto LABEL_4;
return func0(v4, v5, v6);
}

original_code:
int
main(const int iArgc, const char ** ppcArgv) {
  const char * pcPluginName = ((void *)0);
  const char * pcPluginLabel = ((void *)0);
  int bVerbose = 1;
  switch (iArgc) {
  case 2:
    if (strcmp(ppcArgv[1], "-h") != 0) {
      pcPluginName = ppcArgv[1];
      pcPluginLabel = ((void *)0);
    }
    break;
  case 3:
    if (strcmp(ppcArgv[1], "-l") == 0) {
      pcPluginName = ppcArgv[2];
      pcPluginLabel = ((void *)0);
      bVerbose = 0;
    }
    else {
      pcPluginName = ppcArgv[1];
      pcPluginLabel = ppcArgv[2];
    }
    break;
  case 4:
    if (strcmp(ppcArgv[1], "-l") == 0) {
      pcPluginName = ppcArgv[2];
      pcPluginLabel = ppcArgv[3];
      bVerbose = 0;
    }
    break;
  }
  if (!pcPluginName) {
    fprintf(stderr,
     "Usage:\tanalyseplugin [flags] <LADSPA plugin file name> "
     "[<plugin label>].\n"
     "Flags:"
     "-l  Produce a summary list rather than a verbose report.\n"
            "Note that the LADSPA_PATH environment variable is used "
            "to help find plugins.\n");
    return(1);
  }
  return analysePlugin(pcPluginName, pcPluginLabel, bVerbose);
}

canonical_original_code:
int main(int iArgc, char **ppcArgv) {
  char *pcPluginName = ((void *)0);
  char *pcPluginLabel = ((void *)0);
  int bVerbose = 1;
  switch (iArgc) {
  case 2:
    if (strcmp(ppcArgv[1], "-h") != 0) {
      pcPluginName = ppcArgv[1];
      pcPluginLabel = ((void *)0);
    }
    break;
  case 3:
    if (strcmp(ppcArgv[1], "-l") == 0) {
      pcPluginName = ppcArgv[2];
      pcPluginLabel = ((void *)0);
      bVerbose = 0;
    }
    else {
      pcPluginName = ppcArgv[1];
      pcPluginLabel = ppcArgv[2];
    }
    break;
  case 4:
    if (strcmp(ppcArgv[1], "-l") == 0) {
      pcPluginName = ppcArgv[2];
      pcPluginLabel = ppcArgv[3];
      bVerbose = 0;
    }
    break;
  }
  if (!pcPluginName) {
    fprintf(stderr,
     "Usage:\tanalyseplugin [flags] <LADSPA plugin file name> "
     "[<plugin label>].\n"
     "Flags:"
     "-l  Produce a summary list rather than a verbose report.\n"
            "Note that the LADSPA_PATH environment variable is used "
            "to help find plugins.\n");
    return(1);
  }
  return analysePlugin(pcPluginName, pcPluginLabel, bVerbose);
}

variable_types: iArgc int

variable_types:
ppcArgv
char **

variable_types:
pcPluginName
char *


loadLADSPAPluginLibrary

decompiled_code:
void *__fastcall loadLADSPAPluginLibrary(const char *a1)
{
void *result; // rax
char *v2; // rax

result = dlopenLADSPA(a1, 2u);
if ( !result )
{
v2 = dlerror();
fprintf(stderr, "Failed to load plugin \"%s\": %s\n", a1, v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(const char *a1)
{
void *result; // rax
char *v2; // rax

result = func0(a1, 2u);
if ( !result )
{
v2 = dlerror();
fprintf(stderr, "Failed to load plugin \"%s\": %s\n", a1, v2);
exit(1);
}
return result;
}

original_code:
void *
loadLADSPAPluginLibrary(const char * pcPluginFilename) {
  void * pvPluginHandle;
  pvPluginHandle = dlopenLADSPA(pcPluginFilename, 0x00002);
  if (!pvPluginHandle) {
    fprintf(stderr,
     "Failed to load plugin \"%s\": %s\n",
     pcPluginFilename,
     dlerror());
    exit(1);
  }
  return pvPluginHandle;
}

canonical_original_code:
void *loadLADSPAPluginLibrary(char *pcPluginFilename) {
  void *pvPluginHandle;
  pvPluginHandle = dlopenLADSPA(pcPluginFilename, 0x00002);
  if (!pvPluginHandle) {
    fprintf(stderr,
     "Failed to load plugin \"%s\": %s\n",
     pcPluginFilename,
     dlerror());
    exit(1);
  }
  return pvPluginHandle;
}


unloadLADSPAPluginLibrary

decompiled_code:
int __fastcall unloadLADSPAPluginLibrary(void *a1)
{
return dlclose(a1);
}

canonical_decompiled_code:
int __fastcall func2(void *a1)
{
return dlclose(a1);
}

original_code:
void
unloadLADSPAPluginLibrary(void * pvLADSPAPluginLibrary) {
  dlclose(pvLADSPAPluginLibrary);
}

canonical_original_code:
void unloadLADSPAPluginLibrary(void *pvLADSPAPluginLibrary) {
  dlclose(pvLADSPAPluginLibrary);
}

variable_types:
pvLADSPAPluginLibrary
void *


findLADSPAPluginDescriptor

decompiled_code:
__int64 __fastcall findLADSPAPluginDescriptor(void *handle, const char *a2, const char *a3)
{
__int64 (__fastcall *v4)(__int64); // r12
__int64 i; // rbp
char *v6; // rax
__int64 v7; // rax
__int64 v8; // rbx

dlerror();
v4 = (__int64 (__fastcall *)(__int64))dlsym(handle, "ladspa_descriptor");
if ( !v4 )
{
v6 = dlerror();
if ( v6 )
{
fprintf(
stderr,
"Unable to find ladspa_descriptor() function in plugin library file \"%s\": %s.\n"
"Are you sure this is a LADSPA plugin file?\n",
a2,
v6);
exit(1);
}
}
for ( i = 0LL; ; ++i )
{
v7 = v4(i);
v8 = v7;
if ( !v7 )
{
fprintf(stderr, "Unable to find label \"%s\" in plugin library file \"%s\".\n", a3, a2);
exit(1);
}
if ( !strcmp(*(const char **)(v7 + 8), a3) )
break;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *handle, const char *a2, const char *a3)
{
__int64 (__fastcall *v4)(__int64); // r12
__int64 i; // rbp
char *v6; // rax
__int64 v7; // rax
__int64 v8; // rbx

dlerror();
v4 = (__int64 (__fastcall *)(__int64))dlsym(handle, "ladspa_descriptor");
if ( !v4 )
{
v6 = dlerror();
if ( v6 )
{
fprintf(
stderr,
"Unable to find ladspa_descriptor() function in plugin library file \"%s\": %s.\n"
"Are you sure this is a LADSPA plugin file?\n",
a2,
v6);
exit(1);
}
}
for ( i = 0LL; ; ++i )
{
v7 = v4(i);
v8 = v7;
if ( !v7 )
{
fprintf(stderr, "Unable to find label \"%s\" in plugin library file \"%s\".\n", a3, a2);
exit(1);
}
if ( !strcmp(*(const char **)(v7 + 8), a3) )
break;
}
return v8;
}

original_code:
const LADSPA_Descriptor *
findLADSPAPluginDescriptor(void * pvLADSPAPluginLibrary,
      const char * pcPluginLibraryFilename,
      const char * pcPluginLabel) {
  const LADSPA_Descriptor * psDescriptor;
  LADSPA_Descriptor_Function pfDescriptorFunction;
  unsigned long lPluginIndex;
  dlerror();
  pfDescriptorFunction
    = (LADSPA_Descriptor_Function)dlsym(pvLADSPAPluginLibrary,
     "ladspa_descriptor");
  if (!pfDescriptorFunction) {
    const char * pcError = dlerror();
    if (pcError) {
      fprintf(stderr,
       "Unable to find ladspa_descriptor() function in plugin "
       "library file \"%s\": %s.\n"
       "Are you sure this is a LADSPA plugin file?\n",
       pcPluginLibraryFilename,
       pcError);
      exit(1);
    }
  }
  for (lPluginIndex = 0;; lPluginIndex++) {
    psDescriptor = pfDescriptorFunction(lPluginIndex);
    if (psDescriptor == ((void *)0)) {
      fprintf(stderr,
       "Unable to find label \"%s\" in plugin library file \"%s\".\n",
       pcPluginLabel,
       pcPluginLibraryFilename);
      exit(1);
    }
    if (strcmp(psDescriptor->Label, pcPluginLabel) == 0)
      return psDescriptor;
  }
}

canonical_original_code:
struct _LADSPA_Descriptor *findLADSPAPluginDescriptor(void *pvLADSPAPluginLibrary, char *pcPluginLibraryFilename, char *pcPluginLabel) {
  struct _LADSPA_Descriptor *psDescriptor;
  struct _LADSPA_Descriptor *(*pfDescriptorFunction)(unsigned long Index);
  unsigned long lPluginIndex;
  dlerror();
  pfDescriptorFunction
    = (struct _LADSPA_Descriptor *(*)(unsigned long Index))dlsym(pvLADSPAPluginLibrary,
     "ladspa_descriptor");
  if (!pfDescriptorFunction) {
    char *pcError = dlerror();
    if (pcError) {
      fprintf(stderr,
       "Unable to find ladspa_descriptor() function in plugin "
       "library file \"%s\": %s.\n"
       "Are you sure this is a LADSPA plugin file?\n",
       pcPluginLibraryFilename,
       pcError);
      exit(1);
    }
  }
  for (lPluginIndex = 0;; lPluginIndex++) {
    psDescriptor = pfDescriptorFunction(lPluginIndex);
    if (psDescriptor == ((void *)0)) {
      fprintf(stderr,
       "Unable to find label \"%s\" in plugin library file \"%s\".\n",
       pcPluginLabel,
       pcPluginLibraryFilename);
      exit(1);
    }
    if (strcmp(psDescriptor->Label, pcPluginLabel) == 0)
      return psDescriptor;
  }
}

variable_types:
pcPluginLibraryFilename
char *

variable_types: struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; } *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); } *


listPlugins

decompiled_code:
__int64 listPlugins()
{
LADSPAPluginSearch(&describePluginLibrary);
return 0LL;
}

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

original_code:
static int
listPlugins() {
  LADSPAPluginSearch(describePluginLibrary);
  return(0);
}


describePluginLibrary

decompiled_code:
int __fastcall describePluginLibrary(const char *a1, void *a2, __int64 (__fastcall *a3)(__int64))
{
__int64 i; // rbx
__int64 v5; // rax

printf("%s:\n", a1);
for ( i = 0LL; ; ++i )
{
v5 = a3(i);
if ( !v5 )
break;
printf("\t%s (%lu/%s)\n", *(const char **)(v5 + 24), *(_QWORD *)v5, *(const char **)(v5 + 8));
}
return dlclose(a2);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, void *a2, __int64 (__fastcall *a3)(__int64))
{
__int64 i; // rbx
__int64 v5; // rax

printf("%s:\n", a1);
for ( i = 0LL; ; ++i )
{
v5 = a3(i);
if ( !v5 )
break;
printf("\t%s (%lu/%s)\n", *(const char **)(v5 + 24), *(_QWORD *)v5, *(const char **)(v5 + 8));
}
return dlclose(a2);
}

original_code:
static void
describePluginLibrary(const char * pcFullFilename,
        void * pvPluginHandle,
        LADSPA_Descriptor_Function fDescriptorFunction) {
  const LADSPA_Descriptor * psDescriptor;
  long lIndex;
  printf("%s:\n", pcFullFilename);
  for (lIndex = 0;
       (psDescriptor = fDescriptorFunction(lIndex)) != ((void *)0);
       lIndex++)
    printf("\t%s (%lu/%s)\n",
    psDescriptor->Name,
    psDescriptor->UniqueID,
    psDescriptor->Label);
  dlclose(pvPluginHandle);
}

canonical_original_code:
static void describePluginLibrary(char *pcFullFilename, void *pvPluginHandle, struct _LADSPA_Descriptor *(*fDescriptorFunction)(unsigned long Index)) {
  struct _LADSPA_Descriptor *psDescriptor;
  long lIndex;
  printf("%s:\n", pcFullFilename);
  for (lIndex = 0;
       (psDescriptor = fDescriptorFunction(lIndex)) != ((void *)0);
       lIndex++)
    printf("\t%s (%lu/%s)\n",
    psDescriptor->Name,
    psDescriptor->UniqueID,
    psDescriptor->Label);
  dlclose(pvPluginHandle);
}

variable_types:
pcFullFilename
char *

variable_types: lIndex long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return listPlugins(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func0(argc, argv, envp);
}

original_code:
int
main(const int iArgc, const char ** ppcArgv) {
  return listPlugins();
}

canonical_original_code:
int main(int iArgc, char **ppcArgv) {
  return listPlugins();
}


LADSPAPluginSearch

decompiled_code:
void __fastcall LADSPAPluginSearch(void (__fastcall *a1)(char *, void *, void *))
{
char *v1; // rax
const char *v2; // r12
const char *v3; // rbp
char *v4; // rax
char *v5; // r14
const char *v6; // rbx
const char *v7; // rdx

v1 = getenv("LADSPA_PATH");
if ( v1 )
{
v2 = v1;
if ( *v1 )
{
do
{
if ( *v2 == 58 || (v6 = v2, !*v2) )
{
v3 = v2 + 1;
v5 = (char *)malloc(1uLL);
v6 = v2;
}
else
{
do
v7 = v6++;
while ( *v6 != 58 && *v6 );
v3 = v7 + 2;
v4 = (char *)malloc(v7 + 2 - v2);
v5 = v4;
if ( v6 > v2 )
strncpy(v4, v2, v6 - v2);
}
v5[v6 - v2] = 0;
LADSPADirectoryPluginSearch(v5, a1);
free(v5);
if ( *v6 != 58 )
v3 = v6;
v2 = v3;
}
while ( *v3 );
}
}
else
{
fwrite("Warning: You do not have a LADSPA_PATH environment variable set.\n", 1uLL, 0x41uLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func1(void (__fastcall *a1)(char *, void *, void *))
{
char *v1; // rax
const char *v2; // r12
const char *v3; // rbp
char *v4; // rax
char *v5; // r14
const char *v6; // rbx
const char *v7; // rdx

v1 = getenv("LADSPA_PATH");
if ( v1 )
{
v2 = v1;
if ( *v1 )
{
do
{
if ( *v2 == 58 || (v6 = v2, !*v2) )
{
v3 = v2 + 1;
v5 = (char *)malloc(1uLL);
v6 = v2;
}
else
{
do
v7 = v6++;
while ( *v6 != 58 && *v6 );
v3 = v7 + 2;
v4 = (char *)malloc(v7 + 2 - v2);
v5 = v4;
if ( v6 > v2 )
strncpy(v4, v2, v6 - v2);
}
v5[v6 - v2] = 0;
func0(v5, a1);
free(v5);
if ( *v6 != 58 )
v3 = v6;
v2 = v3;
}
while ( *v3 );
}
}
else
{
fwrite("Warning: You do not have a LADSPA_PATH environment variable set.\n", 1uLL, 0x41uLL, stderr);
}
}

original_code:
void
LADSPAPluginSearch(LADSPAPluginSearchCallbackFunction fCallbackFunction) {
  char * pcBuffer;
  const char * pcEnd;
  const char * pcLADSPAPath;
  const char * pcStart;
  pcLADSPAPath = getenv("LADSPA_PATH");
  if (!pcLADSPAPath) {
    fprintf(stderr,
     "Warning: You do not have a LADSPA_PATH "
     "environment variable set.\n");
    return;
  }
  pcStart = pcLADSPAPath;
  while (*pcStart != '\0') {
    pcEnd = pcStart;
    while (*pcEnd != ':' && *pcEnd != '\0')
      pcEnd++;
    pcBuffer = malloc(1 + pcEnd - pcStart);
    if (pcEnd > pcStart)
      strncpy(pcBuffer, pcStart, pcEnd - pcStart);
    pcBuffer[pcEnd - pcStart] = '\0';
    LADSPADirectoryPluginSearch(pcBuffer, fCallbackFunction);
    free(pcBuffer);
    pcStart = pcEnd;
    if (*pcStart == ':')
      pcStart++;
  }
}

canonical_original_code:
void LADSPAPluginSearch(void fCallbackFunction(char *pcFullFilename, void *pvPluginHandle, struct _LADSPA_Descriptor *(*fDescriptorFunction)(unsigned long Index))) {
  char *pcBuffer;
  char *pcEnd;
  char *pcLADSPAPath;
  char *pcStart;
  pcLADSPAPath = getenv("LADSPA_PATH");
  if (!pcLADSPAPath) {
    fprintf(stderr,
     "Warning: You do not have a LADSPA_PATH "
     "environment variable set.\n");
    return;
  }
  pcStart = pcLADSPAPath;
  while (*pcStart != '\0') {
    pcEnd = pcStart;
    while (*pcEnd != ':' && *pcEnd != '\0')
      pcEnd++;
    pcBuffer = malloc(1 + pcEnd - pcStart);
    if (pcEnd > pcStart)
      strncpy(pcBuffer, pcStart, pcEnd - pcStart);
    pcBuffer[pcEnd - pcStart] = '\0';
    LADSPADirectoryPluginSearch(pcBuffer, fCallbackFunction);
    free(pcBuffer);
    pcStart = pcEnd;
    if (*pcStart == ':')
      pcStart++;
  }
}

variable_types: void (char *pcFullFilename, void *pvPluginHandle, struct _LADSPA_Descriptor { unsigned long UniqueID; char *Label; int Properties; char *Name; char *Maker; char *Copyright; unsigned long PortCount; int *PortDescriptors; char **PortNames; struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; } *PortRangeHints; void *ImplementationData; void *(*instantiate)(struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate); void (*connect_port)(void *Instance, unsigned long Port, float *DataLocation); void (*activate)(void *Instance); void (*run)(void *Instance, unsigned long SampleCount); void (*run_adding)(void *Instance, unsigned long SampleCount); void (*set_run_adding_gain)(void *Instance, float Gain); void (*deactivate)(void *Instance); void (*cleanup)(void *Instance); } *(*fDescriptorFunction)(unsigned long Index))

variable_types:
pcBuffer
char *

variable_types:
pcEnd
char *

variable_types:
pcLADSPAPath
char *

variable_types:
pcStart
char *


getLADSPADefault

original_code:
int
getLADSPADefault(const LADSPA_PortRangeHint * psPortRangeHint,
   const unsigned long lSampleRate,
   LADSPA_Data * pfResult) {
  int iHintDescriptor;
  iHintDescriptor = psPortRangeHint->HintDescriptor & 0x3C0;
  switch (iHintDescriptor & 0x3C0) {
  case 0x0:
    return -1;
  case 0x40:
    *pfResult = psPortRangeHint->LowerBound;
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x80:
    if (((iHintDescriptor) & 0x10)) {
      *pfResult = exp(log(psPortRangeHint->LowerBound) * 0.75
        + log(psPortRangeHint->UpperBound) * 0.25);
    }
    else {
      *pfResult = (psPortRangeHint->LowerBound * 0.75
     + psPortRangeHint->UpperBound * 0.25);
    }
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0xC0:
    if (((iHintDescriptor) & 0x10)) {
      *pfResult = sqrt(psPortRangeHint->LowerBound
         * psPortRangeHint->UpperBound);
    }
    else {
      *pfResult = 0.5 * (psPortRangeHint->LowerBound
    + psPortRangeHint->UpperBound);
    }
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x100:
    if (((iHintDescriptor) & 0x10)) {
      *pfResult = exp(log(psPortRangeHint->LowerBound) * 0.25
        + log(psPortRangeHint->UpperBound) * 0.75);
    }
    else {
      *pfResult = (psPortRangeHint->LowerBound * 0.25
     + psPortRangeHint->UpperBound * 0.75);
    }
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x140:
    *pfResult = psPortRangeHint->UpperBound;
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x200:
    *pfResult = 0;
    return 0;
  case 0x240:
    *pfResult = 1;
    return 0;
  case 0x280:
    *pfResult = 100;
    return 0;
  case 0x2C0:
    *pfResult = 440;
    return 0;
  }
  return -1;
}

canonical_original_code:
int getLADSPADefault(struct _LADSPA_PortRangeHint *psPortRangeHint, unsigned long lSampleRate, float *pfResult) {
  int iHintDescriptor;
  iHintDescriptor = psPortRangeHint->HintDescriptor & 0x3C0;
  switch (iHintDescriptor & 0x3C0) {
  case 0x0:
    return -1;
  case 0x40:
    *pfResult = psPortRangeHint->LowerBound;
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x80:
    if (((iHintDescriptor) & 0x10)) {
      *pfResult = exp(log(psPortRangeHint->LowerBound) * 0.75
        + log(psPortRangeHint->UpperBound) * 0.25);
    }
    else {
      *pfResult = (psPortRangeHint->LowerBound * 0.75
     + psPortRangeHint->UpperBound * 0.25);
    }
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0xC0:
    if (((iHintDescriptor) & 0x10)) {
      *pfResult = sqrt(psPortRangeHint->LowerBound
         * psPortRangeHint->UpperBound);
    }
    else {
      *pfResult = 0.5 * (psPortRangeHint->LowerBound
    + psPortRangeHint->UpperBound);
    }
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x100:
    if (((iHintDescriptor) & 0x10)) {
      *pfResult = exp(log(psPortRangeHint->LowerBound) * 0.25
        + log(psPortRangeHint->UpperBound) * 0.75);
    }
    else {
      *pfResult = (psPortRangeHint->LowerBound * 0.25
     + psPortRangeHint->UpperBound * 0.75);
    }
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x140:
    *pfResult = psPortRangeHint->UpperBound;
    if (((psPortRangeHint->HintDescriptor) & 0x8))
      *pfResult *= lSampleRate;
    return 0;
  case 0x200:
    *pfResult = 0;
    return 0;
  case 0x240:
    *pfResult = 1;
    return 0;
  case 0x280:
    *pfResult = 100;
    return 0;
  case 0x2C0:
    *pfResult = 440;
    return 0;
  }
  return -1;
}

variable_types: struct _LADSPA_PortRangeHint { int HintDescriptor; float LowerBound; float UpperBound; } *

variable_types:
lSampleRate
unsigned long

variable_types:
pfResult
float *

variable_types: iHintDescriptor int


repo: warfish/ftrace

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

for ( result = g_task_list; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = g_task_list; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
static struct ftrace_task* find_task(int pid)
{
 struct ftrace_task* task = g_task_list;
 while(task) {
  if(task->pid == pid) {
   return task;
  }
  task = task->next;
 }
 return ((void *)0);
}

canonical_original_code:
static struct ftrace_task *find_task(int pid)
{
 struct ftrace_task *task = g_task_list;
 while(task) {
  if(task->pid == pid) {
   return task;
  }
  task = task->next;
 }
 return ((void *)0);
}

variable_types: pid int

variable_types: struct ftrace_task { int pid; int status; int in_syscall; struct ftrace_task *next; } *


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

if ( a1 > 18 )
{
result = "rename";
if ( a1 != 82 )
{
result = "unknown syscall";
if ( a1 == 85 )
result = "creat";
}
}
else
{
result = "unknown syscall";
if ( a1 >= 0 )
{
switch ( a1 )
{
case 0:
result = "read";
break;
case 1:
result = "write";
break;
case 2:
result = "open";
break;
case 3:
result = "close";
break;
case 17:
result = "pread";
break;
case 18:
result = "pwrite";
break;
default:
result = "unknown syscall";
break;
}
}
}
return result;
}

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

if ( a1 > 18 )
{
result = "rename";
if ( a1 != 82 )
{
result = "unknown syscall";
if ( a1 == 85 )
result = "creat";
}
}
else
{
result = "unknown syscall";
if ( a1 >= 0 )
{
switch ( a1 )
{
case 0:
result = "read";
break;
case 1:
result = "write";
break;
case 2:
result = "open";
break;
case 3:
result = "close";
break;
case 17:
result = "pread";
break;
case 18:
result = "pwrite";
break;
default:
result = "unknown syscall";
break;
}
}
}
return result;
}

original_code:
static const char* syscall_name(int syscall)
{
 switch(syscall) {
 case 2: return "open";
 case 3: return "close";
 case 85: return "creat";
 case 82: return "rename";
 case 0: return "read";
 case 17: return "pread";
 case 1: return "write";
 case 18: return "pwrite";
 default: return "unknown syscall";
 };
}

canonical_original_code:
static char *syscall_name(int syscall)
{
 switch(syscall) {
 case 2: return "open";
 case 3: return "close";
 case 85: return "creat";
 case 82: return "rename";
 case 0: return "read";
 case 17: return "pread";
 case 1: return "write";
 case 18: return "pwrite";
 default: return "unknown syscall";
 };
}

variable_types: syscall int

return_type: char *


usage

decompiled_code:
int usage()
{
return puts(
"ftrace - Trace process file i/o:\n"
"usage: ftrace command [args...]\n"
" command [args...]\t- run command with optional arguments.");
}

canonical_decompiled_code:
int func2()
{
return puts(
"ftrace - Trace process file i/o:\n"
"usage: ftrace command [args...]\n"
" command [args...]\t- run command with optional arguments.");
}

original_code:
static void usage()
{
 printf( "ftrace - Trace process file i/o:\n"
  "usage: ftrace command [args...]\n"
  " command [args...]	- run command with optional arguments.\n"
 );
}


decompiled_code:
__int64 __fastcall setup_ptrace_options(unsigned int a1)
{
return ptrace(PTRACE_SETOPTIONS, a1, 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return ptrace(PTRACE_SETOPTIONS, a1, 10LL);
}

original_code:
static void setup_ptrace_options(int pid)
{
 ptrace(PTRACE_SETOPTIONS, pid, PTRACE_O_TRACEFORK | PTRACE_O_TRACECLONE);
}


decompiled_code:
__int64 __fastcall add_task(int a1)
{
_QWORD *v1; // rax

v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0LL;
v1[1] = 0LL;
*(_DWORD *)v1 = a1;
v1[2] = g_task_list;
g_task_list = (__int64)v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
_QWORD *v1; // rax

v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0LL;
v1[1] = 0LL;
*(_DWORD *)v1 = a1;
v1[2] = g_task_list;
g_task_list = (__int64)v1;
return 0LL;
}

original_code:
static int add_task(int pid)
{
 struct ftrace_task* task = malloc(sizeof(struct ftrace_task));
 if(!task) {
  return -1;
 }
 memset(task, 0, sizeof(*task));
 task->pid = pid;
 task->next = g_task_list;
 g_task_list = task;
 return 0;
}

canonical_original_code:
static int add_task(int pid)
{
 struct ftrace_task *task = malloc(sizeof(struct ftrace_task));
 if(!task) {
  return -1;
 }
 memset(task, 0, sizeof(*task));
 task->pid = pid;
 task->next = g_task_list;
 g_task_list = task;
 return 0;
}

user_defined_types: struct ftrace_task { int pid; int status; int in_syscall; struct ftrace_task *next; }


decompiled_code:
void __fastcall remove_task(_QWORD *a1)
{
__int64 v1; // rax

v1 = g_task_list;
if ( (_QWORD *)g_task_list == a1 )
{
g_task_list = a1[2];
}
else
{
while ( 1 )
{
if ( !v1 )
_assert_fail("(prev && (prev->next == task))", "ftrace.c", 0x52u, "remove_task");
if ( *(_QWORD **)(v1 + 16) == a1 )
break;
v1 = *(_QWORD *)(v1 + 16);
}
*(_QWORD *)(v1 + 16) = a1[2];
}
free(a1);
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax

v1 = g_task_list;
if ( (_QWORD *)g_task_list == a1 )
{
g_task_list = a1[2];
}
else
{
while ( 1 )
{
if ( !v1 )
_assert_fail("(prev && (prev->next == task))", "ftrace.c", 0x52u, "remove_task");
if ( *(_QWORD **)(v1 + 16) == a1 )
break;
v1 = *(_QWORD *)(v1 + 16);
}
*(_QWORD *)(v1 + 16) = a1[2];
}
free(a1);
}

original_code:
static void remove_task(struct ftrace_task* task)
{
 if(task == g_task_list) {
  g_task_list = task->next;
 } else {
  struct ftrace_task* prev = g_task_list;
  while(prev && (prev->next != task)) {
   prev = prev->next;
  }
  ((void) sizeof (((prev && (prev->next == task))) ? 1 : 0), __extension__ ({ if ((prev && (prev->next == task))) ; else __assert_fail ("(prev && (prev->next == task))", "ftrace.c", 82, __extension__ __PRETTY_FUNCTION__); }));
  prev->next = task->next;
 }
 free(task);
}

canonical_original_code:
static void remove_task(struct ftrace_task *task)
{
 if(task == g_task_list) {
  g_task_list = task->next;
 } else {
  struct ftrace_task *prev = g_task_list;
  while(prev && (prev->next != task)) {
   prev = prev->next;
  }
  ((void) sizeof (((prev && (prev->next == task))) ? 1 : 0), __extension__ ({ if ((prev && (prev->next == task))) ; else __assert_fail ("(prev && (prev->next == task))", "ftrace.c", 82, __extension__ __PRETTY_FUNCTION__); }));
  prev->next = task->next;
 }
 free(task);
}


decompiled_code:
int __fastcall trace_task(unsigned int *a1)
{
int v1; // eax
unsigned int v2; // ebp
const char *v3; // rax
int result; // eax
const char *v5; // rax
int v6; // eax
__int64 v7[2]; // [rsp+0h] [rbp-1018h] BYREF
char v8[4080]; // [rsp+10h] [rbp-1008h] BYREF

v1 = task_syscall_num();
v2 = v1;
if ( a1[2] )
{
v3 = syscall_name(v1);
result = fprintf(stderr, "task %d is returning from syscall \"%s\" (%d)\n", *a1, v3, v2);
a1[2] = 0;
}
else
{
v5 = syscall_name(v1);
result = fprintf(stderr, "task %d is entering syscall \"%s\" (%d)\n", *a1, v5, v2);
if ( v2 == 2 )
{
v7[0] = 0LL;
v7[1] = 0LL;
memset(v8, 0, sizeof(v8));
v6 = task_syscall_p1(a1);
task_peekstr(a1, v6, v7, 4096LL);
result = fprintf(stderr, "task %d opens file \"%s\"\n", *a1, (const char *)v7);
}
a1[2] = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
int v1; // eax
unsigned int v2; // ebp
const char *v3; // rax
int result; // eax
const char *v5; // rax
int v6; // eax
__int64 v7[2]; // [rsp+0h] [rbp-1018h] BYREF
char v8[4080]; // [rsp+10h] [rbp-1008h] BYREF

v1 = task_syscall_num();
v2 = v1;
if ( a1[2] )
{
v3 = func1(v1);
result = fprintf(stderr, "task %d is returning from syscall \"%s\" (%d)\n", *a1, v3, v2);
a1[2] = 0;
}
else
{
v5 = func1(v1);
result = fprintf(stderr, "task %d is entering syscall \"%s\" (%d)\n", *a1, v5, v2);
if ( v2 == 2 )
{
v7[0] = 0LL;
v7[1] = 0LL;
memset(v8, 0, sizeof(v8));
v6 = task_syscall_p1(a1);
task_peekstr(a1, v6, v7, 4096LL);
result = fprintf(stderr, "task %d opens file \"%s\"\n", *a1, (const char *)v7);
}
a1[2] = 1;
}
return result;
}

original_code:
static void trace_task(struct ftrace_task* task)
{
 int sysnum = task_syscall_num(task);
 if(task->in_syscall) {
  fprintf(stderr, "task %d is returning from syscall \"%s\" (%d)\n", task->pid, syscall_name(sysnum), sysnum);
  task->in_syscall = 0;
 } else {
  fprintf(stderr, "task %d is entering syscall \"%s\" (%d)\n", task->pid, syscall_name(sysnum), sysnum);
  if(sysnum == 2) {
   char name[4096] = {0};
   long int nameaddr = task_syscall_p1(task);
   unsigned namelen = task_peekstr(task, nameaddr, name, 4096);
   fprintf(stderr, "task %d opens file \"%s\"\n", task->pid, name);
  }
  task->in_syscall = 1;
 }
}

canonical_original_code:
static void trace_task(struct ftrace_task *task)
{
 int sysnum = task_syscall_num(task);
 if(task->in_syscall) {
  fprintf(stderr, "task %d is returning from syscall \"%s\" (%d)\n", task->pid, syscall_name(sysnum), sysnum);
  task->in_syscall = 0;
 } else {
  fprintf(stderr, "task %d is entering syscall \"%s\" (%d)\n", task->pid, syscall_name(sysnum), sysnum);
  if(sysnum == 2) {
   char name[4096] = {0};
   long nameaddr = task_syscall_p1(task);
   unsigned int namelen = task_peekstr(task, nameaddr, name, 4096);
   fprintf(stderr, "task %d opens file \"%s\"\n", task->pid, name);
  }
  task->in_syscall = 1;
 }
}

variable_types: sysnum int

variable_types:
name
char [4096]

variable_types: nameaddr long

variable_types:
namelen
unsigned int


start

decompiled_code:
__int64 start()
{
int v0; // eax
unsigned int v1; // ebx
unsigned int *v2; // rbp
unsigned int v4; // [rsp+8h] [rbp-20h] BYREF
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
v0 = waitpid(-1, &stat_loc, 0);
v1 = v0;
if ( v0 == -1 )
break;
v2 = (unsigned int *)find_task(v0);
if ( !v2 )
_assert_fail("(task != ((void *)0))", "ftrace.c", 0xB7u, "start");
if ( (stat_loc & 0x7F) != 0 && (__OFSUB__((stat_loc & 0x7F) + 1, 1) || (stat_loc & 0x7F) == 0) )
{
if ( (_BYTE)stat_loc == 127 )
{
if ( BYTE1(stat_loc) == 5 || BYTE1(stat_loc) == 19 )
{
if ( stat_loc >> 16 )
{
if ( (unsigned int)((stat_loc >> 16) - 1) <= 2 )
{
ptrace(PTRACE_GETEVENTMSG, *v2, 0LL, &v4);
add_task(v4);
fprintf(stderr, "task %d cloned, new pid is %d\n", *v2, v4);
}
}
else
{
trace_task(v2);
}
}
}
else
{
fprintf(stderr, "Unknown task %d status\n", v1);
}
}
else
{
fprintf(stderr, "task %d terminated\n", v1);
remove_task(v2);
}
ptrace(PTRACE_SYSCALL, v1, 0LL, 0LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
unsigned int v1; // ebx
unsigned int *v2; // rbp
unsigned int v4; // [rsp+8h] [rbp-20h] BYREF
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

while ( 1 )
{
v0 = waitpid(-1, &stat_loc, 0);
v1 = v0;
if ( v0 == -1 )
break;
v2 = (unsigned int *)func0(v0);
if ( !v2 )
_assert_fail("(task != ((void *)0))", "ftrace.c", 0xB7u, "start");
if ( (stat_loc & 0x7F) != 0 && (__OFSUB__((stat_loc & 0x7F) + 1, 1) || (stat_loc & 0x7F) == 0) )
{
if ( (_BYTE)stat_loc == 127 )
{
if ( BYTE1(stat_loc) == 5 || BYTE1(stat_loc) == 19 )
{
if ( stat_loc >> 16 )
{
if ( (unsigned int)((stat_loc >> 16) - 1) <= 2 )
{
ptrace(PTRACE_GETEVENTMSG, *v2, 0LL, &v4);
func4(v4);
fprintf(stderr, "task %d cloned, new pid is %d\n", *v2, v4);
}
}
else
{
func6(v2);
}
}
}
else
{
fprintf(stderr, "Unknown task %d status\n", v1);
}
}
else
{
fprintf(stderr, "task %d terminated\n", v1);
func5(v2);
}
ptrace(PTRACE_SYSCALL, v1, 0LL, 0LL);
}
return 0LL;
}

original_code:
static ftrace_result_t start(void)
{
 int status;
 int pid;
 int signo;
 while((pid = waitpid(-1, &status, 0)) != -1) {
  signo = 0;
  struct ftrace_task* task = find_task(pid);
  ((void) sizeof (((task != ((void *)0))) ? 1 : 0), __extension__ ({ if ((task != ((void *)0))) ; else __assert_fail ("(task != ((void *)0))", "ftrace.c", 183, __extension__ __PRETTY_FUNCTION__); }));
  if((((status) & 0x7f) == 0) || (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)) {
   fprintf(stderr, "task %d terminated\n", pid);
   remove_task(task);
  } else if((((status) & 0xff) == 0x7f)) {
   signo = (((status) & 0xff00) >> 8);
   if((signo == 5) || (signo == 19)) {
    switch(( (status) >> 16 )) {
    case PTRACE_EVENT_FORK:
    case PTRACE_EVENT_VFORK:
    case PTRACE_EVENT_CLONE: {
     int new_pid;
     ptrace(PTRACE_GETEVENTMSG, task->pid, ((void *)0), &new_pid);
     add_task(new_pid);
     fprintf(stderr, "task %d cloned, new pid is %d\n", task->pid, new_pid);
     break;
    }
    case 0: {
     trace_task(task);
    }
    default: break;
    };
   }
  } else {
   fprintf(stderr, "Unknown task %d status\n", pid);
  }
  ptrace(PTRACE_SYSCALL, pid, ((void *)0), ((void *)0));
 }
 return FTRACE_SUCCESS;
}

canonical_original_code:
static enum ftrace_result_t start()
{
 int status;
 int pid;
 int signo;
 while((pid = waitpid(-1, &status, 0)) != -1) {
  signo = 0;
  struct ftrace_task *task = find_task(pid);
  ((void) sizeof (((task != ((void *)0))) ? 1 : 0), __extension__ ({ if ((task != ((void *)0))) ; else __assert_fail ("(task != ((void *)0))", "ftrace.c", 183, __extension__ __PRETTY_FUNCTION__); }));
  if((((status) & 0x7f) == 0) || (((char) (((status) & 0x7f) + 1) >> 1) > 0)) {
   fprintf(stderr, "task %d terminated\n", pid);
   remove_task(task);
  } else if((((status) & 0xff) == 0x7f)) {
   signo = (((status) & 0xff00) >> 8);
   if((signo == 5) || (signo == 19)) {
    switch(( (status) >> 16 )) {
    case PTRACE_EVENT_FORK:
    case PTRACE_EVENT_VFORK:
    case PTRACE_EVENT_CLONE: {
     int new_pid;
     ptrace(PTRACE_GETEVENTMSG, task->pid, ((void *)0), &new_pid);
     add_task(new_pid);
     fprintf(stderr, "task %d cloned, new pid is %d\n", task->pid, new_pid);
     break;
    }
    case 0: {
     trace_task(task);
    }
    default: break;
    };
   }
  } else {
   fprintf(stderr, "Unknown task %d status\n", pid);
  }
  ptrace(PTRACE_SYSCALL, pid, ((void *)0), ((void *)0));
 }
 return FTRACE_SUCCESS;
}

variable_types: status int

variable_types: signo int

return_type: enum ftrace_result_t { FTRACE_SUCCESS=0, FTRACE_NO_MEMORY=1, FTRACE_INVALID_PROCESS=2 }


decompiled_code:
__int64 __fastcall ftrace_create(const char *a1, char *const *a2)
{
int v2; // eax
unsigned int v3; // ebx
__int64 result; // rax
int v5; // edx
struct _IO_FILE *v6; // rdi
__int64 v7; // rdx
int stat_loc[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v2 = vfork();
if ( v2 < 0 )
{
fwrite("Error: vfork failed\n", 1uLL, 0x14uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
if ( v2 )
{
stat_loc[0] = 0;
waitpid(v2, stat_loc, 2);
if ( (stat_loc[0] & 0x7F) != 0 )
{
v5 = add_task(v3);
result = 1LL;
if ( !v5 )
{
setup_ptrace_options(v3);
ptrace(PTRACE_SYSCALL, v3, 0LL, 0LL);
v6 = stderr;
fprintf(stderr, "Starting trace for pid %d\n", v3);
result = start(v6, "Starting trace for pid %d\n", v7);
}
}
else
{
fwrite("Error: child process failed to execute\n", 1uLL, 0x27uLL, stderr);
result = 2LL;
}
}
else
{
if ( ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL) >= 0 )
{
execvp(a1, a2);
fwrite("Error: exec failed\n", 1uLL, 0x13uLL, stderr);
exit(0);
}
fwrite("Error: ptrace failed\n", 1uLL, 0x15uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, char *const *a2)
{
int v2; // eax
unsigned int v3; // ebx
__int64 result; // rax
int v5; // edx
struct _IO_FILE *v6; // rdi
__int64 v7; // rdx
int stat_loc[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v2 = vfork();
if ( v2 < 0 )
{
fwrite("Error: vfork failed\n", 1uLL, 0x14uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
if ( v2 )
{
stat_loc[0] = 0;
waitpid(v2, stat_loc, 2);
if ( (stat_loc[0] & 0x7F) != 0 )
{
v5 = func4(v3);
result = 1LL;
if ( !v5 )
{
func3(v3);
ptrace(PTRACE_SYSCALL, v3, 0LL, 0LL);
v6 = stderr;
fprintf(stderr, "Starting trace for pid %d\n", v3);
result = func7(v6, "Starting trace for pid %d\n", v7);
}
}
else
{
fwrite("Error: child process failed to execute\n", 1uLL, 0x27uLL, stderr);
result = 2LL;
}
}
else
{
if ( ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL) >= 0 )
{
execvp(a1, a2);
fwrite("Error: exec failed\n", 1uLL, 0x13uLL, stderr);
exit(0);
}
fwrite("Error: ptrace failed\n", 1uLL, 0x15uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static ftrace_result_t ftrace_create(const char* name, char** argv)
{
 int pid = vfork();
 if(pid < 0) {
  fprintf(stderr, "Error: vfork failed\n");
  return -1;
 }
 if(pid == 0) {
  long rc = ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
  if(rc < 0) {
   fprintf(stderr, "Error: ptrace failed\n");
   return -1;
  }
  execvp(name, argv);
  fprintf(stderr, "Error: exec failed\n");
  exit(0);
 }
 int status = 0;
 waitpid(pid, &status, 2);
 if((((status) & 0x7f) == 0)) {
  fprintf(stderr, "Error: child process failed to execute\n");
  return FTRACE_INVALID_PROCESS;
 }
 if(0 != add_task(pid)) {
  return FTRACE_NO_MEMORY;
 }
 setup_ptrace_options(pid);
 ptrace(PTRACE_SYSCALL, pid, ((void *)0), ((void *)0));
 fprintf(stderr, "Starting trace for pid %d\n", pid);
 return start();
}

canonical_original_code:
static enum ftrace_result_t ftrace_create(char *name, char **argv)
{
 int pid = vfork();
 if(pid < 0) {
  fprintf(stderr, "Error: vfork failed\n");
  return -1;
 }
 if(pid == 0) {
  long rc = ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
  if(rc < 0) {
   fprintf(stderr, "Error: ptrace failed\n");
   return -1;
  }
  execvp(name, argv);
  fprintf(stderr, "Error: exec failed\n");
  exit(0);
 }
 int status = 0;
 waitpid(pid, &status, 2);
 if((((status) & 0x7f) == 0)) {
  fprintf(stderr, "Error: child process failed to execute\n");
  return FTRACE_INVALID_PROCESS;
 }
 if(0 != add_task(pid)) {
  return FTRACE_NO_MEMORY;
 }
 setup_ptrace_options(pid);
 ptrace(PTRACE_SYSCALL, pid, ((void *)0), ((void *)0));
 fprintf(stderr, "Starting trace for pid %d\n", pid);
 return start();
}

variable_types:
name
char *

variable_types:
argv
char **

variable_types: rc long

user_defined_types: enum ftrace_result_t { FTRACE_SUCCESS=0, FTRACE_NO_MEMORY=1, FTRACE_INVALID_PROCESS=2 }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
return ftrace_create(argv[1], (char *const *)argv + 1);
usage();
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
return func8(argv[1], (char *const *)argv + 1);
func2();
return 1;
}

original_code:
int main(int argc, char** argv)
{
 if(argc < 2) {
  usage();
  return 1;
 }
 const char* cmd = argv[1];
 char** args = &argv[1];
 return ftrace_create(cmd, args);
}

canonical_original_code:
int main(int argc, char **argv)
{
 if(argc < 2) {
  usage();
  return 1;
 }
 char *cmd = argv[1];
 char **args = &argv[1];
 return ftrace_create(cmd, args);
}

variable_types: argc int

variable_types:
cmd
char *

variable_types:
args
char **