MIDIClockRelease

decompiled_code:
void __fastcall MIDIClockRelease(_DWORD *a1)
{
if ( a1 )
{
if ( (*a1)-- == 1 )
MIDIClockDestroy(a1);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 366LL, "[EFAULT] Precondition failed (clock != NULL)");
}
}

canonical_decompiled_code:
void __fastcall func11(_DWORD *a1)
{
if ( a1 )
{
if ( (*a1)-- == 1 )
func9(a1);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 366LL, "[EFAULT] Precondition failed (clock != NULL)");
}
}

original_code:
void MIDIClockRelease( struct MIDIClock * clock ) {
  do { if( !(clock != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 366, "[" "EFAULT" "] Precondition failed (" "clock != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  if( ! --clock->refs ) {
    MIDIClockDestroy( clock );
  }
}

canonical_original_code:
void MIDIClockRelease(struct MIDIClock *clock) {
  do { if( !(clock != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 366, "[" "EFAULT" "] Precondition failed (" "clock != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  if( ! --clock->refs ) {
    MIDIClockDestroy( clock );
  }
}

user_defined_types: struct MIDIClock { int refs; long long offset; unsigned int rate; unsigned long long numer; unsigned long long denom; }


MIDIClockSetGlobalClock

repo: jpommerening/midikit

decompiled_code:
__int64 __fastcall MIDIClockSetGlobalClock(_DWORD *a1)
{
if ( (_DWORD *)midi_global_clock != a1 )
{
if ( midi_global_clock )
MIDIClockRelease((_DWORD *)midi_global_clock);
midi_global_clock = (__int64)a1;
MIDIClockRetain(a1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1)
{
if ( (_DWORD *)midi_global_clock != a1 )
{
if ( midi_global_clock )
func11((_DWORD *)midi_global_clock);
midi_global_clock = (__int64)a1;
MIDIClockRetain(a1);
}
return 0LL;
}

original_code:
int MIDIClockSetGlobalClock( struct MIDIClock * clock ) {
  if( clock == _midi_global_clock ) return 0;
  if( _midi_global_clock != ((void *)0) ) MIDIClockRelease( _midi_global_clock );
  _midi_global_clock = clock;
  MIDIClockRetain( clock );
  return 0;
}

canonical_original_code:
int MIDIClockSetGlobalClock(struct MIDIClock *clock) {
  if( clock == _midi_global_clock ) return 0;
  if( _midi_global_clock != ((void *)0) ) MIDIClockRelease( _midi_global_clock );
  _midi_global_clock = clock;
  MIDIClockRetain( clock );
  return 0;
}

variable_types: struct MIDIClock { int refs; long long offset; unsigned int rate; unsigned long long numer; unsigned long long denom; } *

return_type: int


MIDIClockSetNow

decompiled_code:
__int64 __fastcall MIDIClockSetNow(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rsi

v2 = a1;
if ( !a1 )
v2 = get_global_clock();
if ( *(_DWORD *)v2 == 1 )
{
v4 = a2 - get_real_time(v2);
result = 0LL;
*(_QWORD *)(v2 + 8) = v4;
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 391LL, "[EFAULT] Precondition failed (clock->refs == 1)");
result = 14LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rsi

v2 = a1;
if ( !a1 )
v2 = func7();
if ( *(_DWORD *)v2 == 1 )
{
v4 = a2 - func4(v2);
result = 0LL;
*(_QWORD *)(v2 + 8) = v4;
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 391LL, "[EFAULT] Precondition failed (clock->refs == 1)");
result = 14LL;
}
return result;
}

original_code:
int MIDIClockSetNow( struct MIDIClock * clock, MIDITimestamp now ) {
  if( clock == ((void *)0) ) clock = _get_global_clock();
  do { if( !(clock->refs == 1) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 391, "[" "EFAULT" "] Precondition failed (" "clock->refs == 1" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  clock->offset = now - _get_real_time( clock );
  return 0;
}

canonical_original_code:
int MIDIClockSetNow(struct MIDIClock *clock, long long now) {
  if( clock == ((void *)0) ) clock = _get_global_clock();
  do { if( !(clock->refs == 1) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 391, "[" "EFAULT" "] Precondition failed (" "clock->refs == 1" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  clock->offset = now - _get_real_time( clock );
  return 0;
}

variable_types:
now
long long


MIDIClockGetNow

decompiled_code:
__int64 __fastcall MIDIClockGetNow(__int64 a1, _QWORD *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12

if ( a2 )
{
v2 = a1;
if ( !a1 )
v2 = get_global_clock();
v3 = 0;
*a2 = *(_QWORD *)(v2 + 8) + get_real_time(v2);
}
else
{
v3 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 405LL, "[EINVAL] Precondition failed (now != NULL)");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, _QWORD *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12

if ( a2 )
{
v2 = a1;
if ( !a1 )
v2 = func7();
v3 = 0;
*a2 = *(_QWORD *)(v2 + 8) + func4(v2);
}
else
{
v3 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 405LL, "[EINVAL] Precondition failed (now != NULL)");
}
return v3;
}

original_code:
int MIDIClockGetNow( struct MIDIClock * clock, MIDITimestamp * now ) {
  do { if( !(now != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 405, "[" "EINVAL" "] Precondition failed (" "now != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *now = _get_real_time( clock ) + clock->offset;
  return 0;
}

canonical_original_code:
int MIDIClockGetNow(struct MIDIClock *clock, long long *now) {
  do { if( !(now != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 405, "[" "EINVAL" "] Precondition failed (" "now != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *now = _get_real_time( clock ) + clock->offset;
  return 0;
}

variable_types:
now
long long *


MIDIClockSetSamplingRate

decompiled_code:
__int64 __fastcall MIDIClockSetSamplingRate(__int64 a1, unsigned int a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rax
unsigned int v4; // er12

if ( !a1 )
a1 = get_global_clock();
if ( *(_DWORD *)a1 == 1 )
{
v2 = *(unsigned int *)(a1 + 16);
v3 = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 16) = a2;
v4 = 0;
*(_QWORD *)(a1 + 24) = a2 * (v3 / v2);
return v4;
}
v4 = 14;
MIDIErrorNumber = 14;
if ( !MIDILogger )
return v4;
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 422LL, "[EFAULT] Precondition failed (clock->refs == 1)");
return 14LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned int a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rax
unsigned int v4; // er12

if ( !a1 )
a1 = func7();
if ( *(_DWORD *)a1 == 1 )
{
v2 = *(unsigned int *)(a1 + 16);
v3 = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 16) = a2;
v4 = 0;
*(_QWORD *)(a1 + 24) = a2 * (v3 / v2);
return v4;
}
v4 = 14;
MIDIErrorNumber = 14;
if ( !MIDILogger )
return v4;
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 422LL, "[EFAULT] Precondition failed (clock->refs == 1)");
return 14LL;
}

original_code:
int MIDIClockSetSamplingRate( struct MIDIClock * clock, MIDISamplingRate rate ) {
  if( clock == ((void *)0) ) clock = _get_global_clock();
  do { if( !(clock->refs == 1) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 422, "[" "EFAULT" "] Precondition failed (" "clock->refs == 1" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  clock->numer = ( clock->numer / clock->rate ) * rate;
  clock->rate = rate;
  return 0;
}

canonical_original_code:
int MIDIClockSetSamplingRate(struct MIDIClock *clock, unsigned int rate) {
  if( clock == ((void *)0) ) clock = _get_global_clock();
  do { if( !(clock->refs == 1) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 422, "[" "EFAULT" "] Precondition failed (" "clock->refs == 1" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  clock->numer = ( clock->numer / clock->rate ) * rate;
  clock->rate = rate;
  return 0;
}

variable_types:
rate
unsigned int


MIDIClockGetSamplingRate

decompiled_code:
__int64 __fastcall MIDIClockGetSamplingRate(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er12

if ( a2 )
{
if ( !a1 )
a1 = get_global_clock();
v2 = 0;
*a2 = *(_DWORD *)(a1 + 16);
}
else
{
v2 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 437LL, "[EINVAL] Precondition failed (rate != NULL)");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er12

if ( a2 )
{
if ( !a1 )
a1 = func7();
v2 = 0;
*a2 = *(_DWORD *)(a1 + 16);
}
else
{
v2 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 437LL, "[EINVAL] Precondition failed (rate != NULL)");
}
return v2;
}

original_code:
int MIDIClockGetSamplingRate( struct MIDIClock * clock, MIDISamplingRate * rate ) {
  do { if( !(rate != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 437, "[" "EINVAL" "] Precondition failed (" "rate != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *rate = clock->rate;
  return 0;
}

canonical_original_code:
int MIDIClockGetSamplingRate(struct MIDIClock *clock, unsigned int *rate) {
  do { if( !(rate != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 437, "[" "EINVAL" "] Precondition failed (" "rate != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *rate = clock->rate;
  return 0;
}

variable_types:
rate
unsigned int *


MIDIClockTimestampToSeconds

decompiled_code:
__int64 __fastcall MIDIClockTimestampToSeconds(__int64 a1, __int64 a2, double *a3)
{
unsigned int v4; // er12

if ( a3 )
{
if ( !a1 )
a1 = get_global_clock();
v4 = 0;
*a3 = (double)(int)(a2 / *(unsigned int *)(a1 + 16));
}
else
{
v4 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 453LL, "[EINVAL] Precondition failed (seconds != NULL)");
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, double *a3)
{
unsigned int v4; // er12

if ( a3 )
{
if ( !a1 )
a1 = func7();
v4 = 0;
*a3 = (double)(int)(a2 / *(unsigned int *)(a1 + 16));
}
else
{
v4 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 453LL, "[EINVAL] Precondition failed (seconds != NULL)");
}
return v4;
}

original_code:
int MIDIClockTimestampToSeconds( struct MIDIClock * clock, MIDITimestamp timestamp, double * seconds ) {
  do { if( !(seconds != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 453, "[" "EINVAL" "] Precondition failed (" "seconds != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *seconds = timestamp / clock->rate;
  return 0;
}

canonical_original_code:
int MIDIClockTimestampToSeconds(struct MIDIClock *clock, long long timestamp, double *seconds) {
  do { if( !(seconds != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 453, "[" "EINVAL" "] Precondition failed (" "seconds != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *seconds = timestamp / clock->rate;
  return 0;
}

variable_types:
timestamp
long long

variable_types:
seconds
double *


MIDIClockTimestampFromSeconds

decompiled_code:
__int64 __fastcall MIDIClockTimestampFromSeconds(__int64 a1, _QWORD *a2, double a3)
{
unsigned int v3; // er12

if ( a2 )
{
if ( !a1 )
a1 = get_global_clock();
v3 = 0;
*a2 = (unsigned int)(int)(a3 * (double)*(int *)(a1 + 16));
}
else
{
v3 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 468LL, "[EINVAL] Precondition failed (timestamp != NULL)");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, _QWORD *a2, double a3)
{
unsigned int v3; // er12

if ( a2 )
{
if ( !a1 )
a1 = func7();
v3 = 0;
*a2 = (unsigned int)(int)(a3 * (double)*(int *)(a1 + 16));
}
else
{
v3 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 468LL, "[EINVAL] Precondition failed (timestamp != NULL)");
}
return v3;
}

original_code:
int MIDIClockTimestampFromSeconds( struct MIDIClock * clock, MIDITimestamp * timestamp, double seconds ) {
  do { if( !(timestamp != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 468, "[" "EINVAL" "] Precondition failed (" "timestamp != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *timestamp = seconds * clock->rate;
  return 0;
}

canonical_original_code:
int MIDIClockTimestampFromSeconds(struct MIDIClock *clock, long long *timestamp, double seconds) {
  do { if( !(timestamp != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 468, "[" "EINVAL" "] Precondition failed (" "timestamp != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  *timestamp = seconds * clock->rate;
  return 0;
}

variable_types:
timestamp
long long *

variable_types: seconds double


MIDIClockConvertTimestamp

decompiled_code:
__int64 __fastcall MIDIClockConvertTimestamp(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rbx
_QWORD *v4; // rbp
unsigned int v6; // er12
unsigned __int64 v8; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a3 )
{
v3 = a1;
v4 = a2;
if ( a1 )
{
if ( a2 )
goto LABEL_4;
}
else
{
v3 = (_QWORD *)get_global_clock();
if ( a2 )
goto LABEL_4;
}
v4 = (_QWORD *)get_global_clock();
LABEL_4:
v6 = 0;
if ( v3 != v4 )
{
v8 = v4[4] * v3[3];
v9[0] = v4[3] * v3[4];
normalize_frac(&v8, v9);
*a3 = v3[1] + v8 * (*a3 - v4[1]) / v9[0];
}
return v6;
}
v6 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 488LL, "[EINVAL] Precondition failed (timestamp != NULL)");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rbx
_QWORD *v4; // rbp
unsigned int v6; // er12
unsigned __int64 v8; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a3 )
{
v3 = a1;
v4 = a2;
if ( a1 )
{
if ( a2 )
goto LABEL_4;
}
else
{
v3 = (_QWORD *)func7();
if ( a2 )
goto LABEL_4;
}
v4 = (_QWORD *)func7();
LABEL_4:
v6 = 0;
if ( v3 != v4 )
{
v8 = v4[4] * v3[3];
v9[0] = v4[3] * v3[4];
func0(&v8, v9);
*a3 = v3[1] + v8 * (*a3 - v4[1]) / v9[0];
}
return v6;
}
v6 = 22;
MIDIErrorNumber = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "clock.c", 488LL, "[EINVAL] Precondition failed (timestamp != NULL)");
return v6;
}

original_code:
int MIDIClockConvertTimestamp( struct MIDIClock * clock, struct MIDIClock * source, MIDITimestamp * timestamp ) {
  long long tmp;
  unsigned long long numer, denom;
  do { if( !(timestamp != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 488, "[" "EINVAL" "] Precondition failed (" "timestamp != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  if( source == ((void *)0) ) source = _get_global_clock();
  if( clock == source ) return 0;
  numer = clock->numer * source->denom;
  denom = clock->denom * source->numer;
  _normalize_frac( &numer, &denom );
  tmp = ( *timestamp - source->offset );
  tmp = ( tmp * numer ) / denom;
  *timestamp = ( tmp + clock->offset );
  return 0;
}

canonical_original_code:
int MIDIClockConvertTimestamp(struct MIDIClock *clock, struct MIDIClock *source, long long *timestamp) {
  long long tmp;
  unsigned long long numer; unsigned long long denom;
  do { if( !(timestamp != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "clock.c", 488, "[" "EINVAL" "] Precondition failed (" "timestamp != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  if( clock == ((void *)0) ) clock = _get_global_clock();
  if( source == ((void *)0) ) source = _get_global_clock();
  if( clock == source ) return 0;
  numer = clock->numer * source->denom;
  denom = clock->denom * source->numer;
  _normalize_frac( &numer, &denom );
  tmp = ( *timestamp - source->offset );
  tmp = ( tmp * numer ) / denom;
  *timestamp = ( tmp + clock->offset );
  return 0;
}

variable_types:
source
struct MIDIClock *

variable_types:
tmp
long long

variable_types:
numer
unsigned long long

variable_types:
denom
unsigned long long


MIDITimerDestroy

decompiled_code:
// attributes: thunk
void MIDITimerDestroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void MIDITimerDestroy( struct MIDITimer * timer ) {
  free( timer );
}

canonical_original_code:
void MIDITimerDestroy(struct MIDITimer *timer) {
  free( timer );
}

variable_types: struct MIDITimer { int refs; struct MIDITimerDelegate {  } *delegate; short song_position; short beats_per_minute; long long last_timestamp; long long clocks[4]; } *

return_type: void

user_defined_types: struct MIDITimer { int refs; struct MIDITimerDelegate *delegate; short song_position; short beats_per_minute; long long last_timestamp; long long clocks[4]; }


MIDITimerRelease

decompiled_code:
void __fastcall MIDITimerRelease(_DWORD *a1)
{
if ( (*a1)-- == 1 )
MIDITimerDestroy(a1);
}

canonical_decompiled_code:
void __fastcall func2(_DWORD *a1)
{
if ( (*a1)-- == 1 )
func0(a1);
}

original_code:
void MIDITimerRelease( struct MIDITimer * timer ) {
  if( ! --timer->refs ) {
    MIDITimerDestroy( timer );
  }
}

canonical_original_code:
void MIDITimerRelease(struct MIDITimer *timer) {
  if( ! --timer->refs ) {
    MIDITimerDestroy( timer );
  }
}


decompiled_code:
__int64 test001_util()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-50h] BYREF
__int64 v2; // [rsp+Eh] [rbp-42h] BYREF
__int16 v3; // [rsp+16h] [rbp-3Ah]
__int128 v4[3]; // [rsp+18h] [rbp-38h] BYREF

v2 = 0x808003828101817FLL;
v3 = 128;
v1 = 0LL;
v4[0] = 0LL;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v4, 10LL, &v2, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[0], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
20LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else
{
if ( LODWORD(v4[0]) != 127 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[0] has to be equal to test[0]!\n",
"test",
"util.c",
21LL,
"Read wrong number.");
return 1LL;
}
return 1LL;
}
if ( v1 != 1 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 1!\n",
"test",
"util.c",
22LL,
"Read wrong number of bytes.");
return 1LL;
}
return 1LL;
}
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 4, 9LL, (char *)&v2 + 1, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[1], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
24LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else
{
if ( DWORD1(v4[0]) != 129 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[1] has to be equal to test[1]!\n",
"test",
"util.c",
25LL,
"Read wrong number.");
return 1LL;
}
return 1LL;
}
if ( v1 == 2 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 8, 7LL, (char *)&v2 + 3, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[2], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
28LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else if ( DWORD2(v4[0]) == 16643 )
{
if ( v1 == 3 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 12, 3LL, (char *)&v2 + 6, &v1) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 12, 4LL, (char *)&v2 + 6, &v1);
if ( (_DWORD)result )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[3], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
33LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else if ( HIDWORD(v4[0]) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[3] has to be equal to test[3]!\n",
"test",
"util.c",
34LL,
"Read wrong number.");
result = 1LL;
}
else if ( v1 != 4 )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 4!\n",
"test",
"util.c",
35LL,
"Read wrong number of bytes.");
return 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[3], 9-ptr, buffer+ptr, &bytes ) returned no error!\n",
"test",
"util.c",
32LL,
"Read number that reached out of the buffer.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 3!\n",
"test",
"util.c",
30LL,
"Read wrong number of bytes.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[2] has to be equal to test[2]!\n",
"test",
"util.c",
29LL,
"Read wrong number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 2!\n",
"test",
"util.c",
26LL,
"Read wrong number of bytes.");
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-50h] BYREF
__int64 v2; // [rsp+Eh] [rbp-42h] BYREF
__int16 v3; // [rsp+16h] [rbp-3Ah]
__int128 v4[3]; // [rsp+18h] [rbp-38h] BYREF

v2 = 0x808003828101817FLL;
v3 = 128;
v1 = 0LL;
v4[0] = 0LL;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v4, 10LL, &v2, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[0], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
20LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else
{
if ( LODWORD(v4[0]) != 127 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[0] has to be equal to test[0]!\n",
"test",
"util.c",
21LL,
"Read wrong number.");
return 1LL;
}
return 1LL;
}
if ( v1 != 1 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 1!\n",
"test",
"util.c",
22LL,
"Read wrong number of bytes.");
return 1LL;
}
return 1LL;
}
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 4, 9LL, (char *)&v2 + 1, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[1], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
24LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else
{
if ( DWORD1(v4[0]) != 129 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[1] has to be equal to test[1]!\n",
"test",
"util.c",
25LL,
"Read wrong number.");
return 1LL;
}
return 1LL;
}
if ( v1 == 2 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 8, 7LL, (char *)&v2 + 3, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[2], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
28LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else if ( DWORD2(v4[0]) == 16643 )
{
if ( v1 == 3 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 12, 3LL, (char *)&v2 + 6, &v1) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen((char *)v4 + 12, 4LL, (char *)&v2 + 6, &v1);
if ( (_DWORD)result )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[3], 10-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
33LL,
"Could not read var length number from buffer.");
result = 1LL;
}
else if ( HIDWORD(v4[0]) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[3] has to be equal to test[3]!\n",
"test",
"util.c",
34LL,
"Read wrong number.");
result = 1LL;
}
else if ( v1 != 4 )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 4!\n",
"test",
"util.c",
35LL,
"Read wrong number of bytes.");
return 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[3], 9-ptr, buffer+ptr, &bytes ) returned no error!\n",
"test",
"util.c",
32LL,
"Read number that reached out of the buffer.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 3!\n",
"test",
"util.c",
30LL,
"Read wrong number of bytes.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[2] has to be equal to test[2]!\n",
"test",
"util.c",
29LL,
"Read wrong number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 2!\n",
"test",
"util.c",
26LL,
"Read wrong number of bytes.");
result = 1LL;
}
}
}
return result;
}

original_code:
int test001_util( void ) {
  unsigned char buffer[10] = {
    0x7f,
    0x81, 0x01,
    0x81, 0x82, 0x03,
    0x80, 0x80, 0x80, 0x00
  };
  MIDIVarLen out[4] = { 0 };
  MIDIVarLen test[4] = { 0x7f, 0x81, 0x4103, 0x00 };
  size_t bytes = 0;
  size_t ptr = 0;
  if( ! ((MIDIUtilReadVarLen( &out[0], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[0], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 20, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[0]) == (test[0])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[0]" " has to be equal to " "test[0]" "!" "\n", "test", "util.c", 21, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "1" "!" "\n", "test", "util.c", 22, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilReadVarLen( &out[1], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[1], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 24, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[1]) == (test[1])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[1]" " has to be equal to " "test[1]" "!" "\n", "test", "util.c", 25, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (2)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "2" "!" "\n", "test", "util.c", 26, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilReadVarLen( &out[2], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[2], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 28, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[2]) == (test[2])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[2]" " has to be equal to " "test[2]" "!" "\n", "test", "util.c", 29, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (3)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "3" "!" "\n", "test", "util.c", 30, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilReadVarLen( &out[3], 9-ptr, buffer+ptr, &bytes )) != 0 || MIDIErrorNumber != 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[3], 9-ptr, buffer+ptr, &bytes )" " returned no error!" "\n", "test", "util.c", 32, "Read number that reached out of the buffer." ); } } while( 0 );; return 1; };
  if( ! ((MIDIUtilReadVarLen( &out[3], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[3], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 33, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[3]) == (test[3])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[3]" " has to be equal to " "test[3]" "!" "\n", "test", "util.c", 34, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (4)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "4" "!" "\n", "test", "util.c", 35, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  return 0;
}

canonical_original_code:
int test001_util() {
  unsigned char buffer[10] = {
    0x7f,
    0x81, 0x01,
    0x81, 0x82, 0x03,
    0x80, 0x80, 0x80, 0x00
  };
  unsigned int out[4] = { 0 };
  unsigned int test[4] = { 0x7f, 0x81, 0x4103, 0x00 };
  unsigned long bytes = 0;
  unsigned long ptr = 0;
  if( ! ((MIDIUtilReadVarLen( &out[0], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[0], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 20, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[0]) == (test[0])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[0]" " has to be equal to " "test[0]" "!" "\n", "test", "util.c", 21, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "1" "!" "\n", "test", "util.c", 22, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilReadVarLen( &out[1], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[1], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 24, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[1]) == (test[1])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[1]" " has to be equal to " "test[1]" "!" "\n", "test", "util.c", 25, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (2)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "2" "!" "\n", "test", "util.c", 26, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilReadVarLen( &out[2], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[2], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 28, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[2]) == (test[2])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[2]" " has to be equal to " "test[2]" "!" "\n", "test", "util.c", 29, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (3)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "3" "!" "\n", "test", "util.c", 30, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilReadVarLen( &out[3], 9-ptr, buffer+ptr, &bytes )) != 0 || MIDIErrorNumber != 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[3], 9-ptr, buffer+ptr, &bytes )" " returned no error!" "\n", "test", "util.c", 32, "Read number that reached out of the buffer." ); } } while( 0 );; return 1; };
  if( ! ((MIDIUtilReadVarLen( &out[3], 10-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[3], 10-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 33, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[3]) == (test[3])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[3]" " has to be equal to " "test[3]" "!" "\n", "test", "util.c", 34, "Read wrong number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (4)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "4" "!" "\n", "test", "util.c", 35, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  return 0;
}

variable_types:
buffer
unsigned char [10]

variable_types:
out
unsigned int [4]

variable_types:
test
unsigned int [4]

variable_types:
bytes
unsigned long

variable_types:
ptr
unsigned long


decompiled_code:
__int64 test002_util()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-50h] BYREF
__int64 v2; // [rsp+16h] [rbp-42h] BYREF
__int16 v3; // [rsp+1Eh] [rbp-3Ah]
__int64 v4; // [rsp+20h] [rbp-38h] BYREF
__int64 v5[6]; // [rsp+28h] [rbp-30h] BYREF

v4 = 0x810000007FLL;
v5[0] = 0x20000000004103LL;
v2 = 0LL;
v3 = 0;
v1 = 0LL;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v4, 10LL, &v2, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[0], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
55LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else
{
if ( (_BYTE)v2 != 127 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[0] has to be equal to test[0]!\n",
"test",
"util.c",
56LL,
"Wrote wrong byte (0) of number.");
return 1LL;
}
return 1LL;
}
if ( v1 != 1 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 1!\n",
"test",
"util.c",
57LL,
"Wrote wrong number of bytes.");
return 1LL;
}
return 1LL;
}
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen((char *)&v4 + 4, 9LL, (char *)&v2 + 1, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[1], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
59LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else
{
if ( BYTE1(v2) != 0x81 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[1] has to be equal to test[1]!\n",
"test",
"util.c",
60LL,
"Wrote wrong byte (0) of number.");
return 1LL;
}
return 1LL;
}
if ( BYTE2(v2) == 1 )
{
if ( v1 == 2 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v5, 7LL, (char *)&v2 + 3, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[2], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
64LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else if ( BYTE3(v2) == 0x81 )
{
if ( BYTE4(v2) == 0x82 )
{
if ( BYTE5(v2) == 3 )
{
if ( v1 == 3 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen((char *)v5 + 4, 3LL, (char *)&v2 + 6, &v1) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(
(char *)v5 + 4,
4LL,
(char *)&v2 + 6,
&v1);
if ( (_DWORD)result )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[3], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
71LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else if ( BYTE6(v2) == 0x81 )
{
if ( HIBYTE(v2) == 0x80 )
{
if ( (_BYTE)v3 == 0x80 )
{
if ( HIBYTE(v3) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[9] has to be equal to test[9]!\n",
"test",
"util.c",
75LL,
"Wrote wrong byte (3) of number.");
result = 1LL;
}
else if ( v1 != 4 )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 4!\n",
"test",
"util.c",
76LL,
"Wrote wrong number of bytes.");
return 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[8] has to be equal to test[8]!\n",
"test",
"util.c",
74LL,
"Wrote wrong byte (2) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[7] has to be equal to test[7]!\n",
"test",
"util.c",
73LL,
"Wrote wrong byte (1) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[6] has to be equal to test[6]!\n",
"test",
"util.c",
72LL,
"Wrote wrong byte (0) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[3], 9-ptr, out+ptr, &bytes ) returned no error!\n",
"test",
"util.c",
70LL,
"Wrote number that reached out of the buffer.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 3!\n",
"test",
"util.c",
68LL,
"Wrote wrong number of bytes.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[5] has to be equal to test[5]!\n",
"test",
"util.c",
67LL,
"Wrote wrong byte (2) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[4] has to be equal to test[4]!\n",
"test",
"util.c",
66LL,
"Wrote wrong byte (1) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[3] has to be equal to test[3]!\n",
"test",
"util.c",
65LL,
"Wrote wrong byte (0) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 2!\n",
"test",
"util.c",
62LL,
"Wrote wrong number of bytes.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[2] has to be equal to test[2]!\n",
"test",
"util.c",
61LL,
"Wrote wrong byte (1) of number.");
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-50h] BYREF
__int64 v2; // [rsp+16h] [rbp-42h] BYREF
__int16 v3; // [rsp+1Eh] [rbp-3Ah]
__int64 v4; // [rsp+20h] [rbp-38h] BYREF
__int64 v5[6]; // [rsp+28h] [rbp-30h] BYREF

v4 = 0x810000007FLL;
v5[0] = 0x20000000004103LL;
v2 = 0LL;
v3 = 0;
v1 = 0LL;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v4, 10LL, &v2, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[0], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
55LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else
{
if ( (_BYTE)v2 != 127 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[0] has to be equal to test[0]!\n",
"test",
"util.c",
56LL,
"Wrote wrong byte (0) of number.");
return 1LL;
}
return 1LL;
}
if ( v1 != 1 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 1!\n",
"test",
"util.c",
57LL,
"Wrote wrong number of bytes.");
return 1LL;
}
return 1LL;
}
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen((char *)&v4 + 4, 9LL, (char *)&v2 + 1, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[1], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
59LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else
{
if ( BYTE1(v2) != 0x81 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[1] has to be equal to test[1]!\n",
"test",
"util.c",
60LL,
"Wrote wrong byte (0) of number.");
return 1LL;
}
return 1LL;
}
if ( BYTE2(v2) == 1 )
{
if ( v1 == 2 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v5, 7LL, (char *)&v2 + 3, &v1) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[2], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
64LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else if ( BYTE3(v2) == 0x81 )
{
if ( BYTE4(v2) == 0x82 )
{
if ( BYTE5(v2) == 3 )
{
if ( v1 == 3 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen((char *)v5 + 4, 3LL, (char *)&v2 + 6, &v1) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(
(char *)v5 + 4,
4LL,
(char *)&v2 + 6,
&v1);
if ( (_DWORD)result )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[3], 10-ptr, out+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
71LL,
"Could not write var length number to buffer.");
result = 1LL;
}
else if ( BYTE6(v2) == 0x81 )
{
if ( HIBYTE(v2) == 0x80 )
{
if ( (_BYTE)v3 == 0x80 )
{
if ( HIBYTE(v3) )
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[9] has to be equal to test[9]!\n",
"test",
"util.c",
75LL,
"Wrote wrong byte (3) of number.");
result = 1LL;
}
else if ( v1 != 4 )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 4!\n",
"test",
"util.c",
76LL,
"Wrote wrong number of bytes.");
return 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[8] has to be equal to test[8]!\n",
"test",
"util.c",
74LL,
"Wrote wrong byte (2) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[7] has to be equal to test[7]!\n",
"test",
"util.c",
73LL,
"Wrote wrong byte (1) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[6] has to be equal to test[6]!\n",
"test",
"util.c",
72LL,
"Wrote wrong byte (0) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &buffer[3], 9-ptr, out+ptr, &bytes ) returned no error!\n",
"test",
"util.c",
70LL,
"Wrote number that reached out of the buffer.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 3!\n",
"test",
"util.c",
68LL,
"Wrote wrong number of bytes.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[5] has to be equal to test[5]!\n",
"test",
"util.c",
67LL,
"Wrote wrong byte (2) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[4] has to be equal to test[4]!\n",
"test",
"util.c",
66LL,
"Wrote wrong byte (1) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[3] has to be equal to test[3]!\n",
"test",
"util.c",
65LL,
"Wrote wrong byte (0) of number.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 2!\n",
"test",
"util.c",
62LL,
"Wrote wrong number of bytes.");
result = 1LL;
}
}
else
{
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n out[2] has to be equal to test[2]!\n",
"test",
"util.c",
61LL,
"Wrote wrong byte (1) of number.");
result = 1LL;
}
}
}
return result;
}

original_code:
int test002_util( void ) {
  MIDIVarLen buffer[4] = { 0x7f, 0x81, 0x4103, 1<<21 };
  unsigned char out[10] = { 0 };
  unsigned char test[10] = {
    0x7f,
    0x81, 0x01,
    0x81, 0x82, 0x03,
    0x81, 0x80, 0x80, 0x00
  };
  size_t bytes = 0;
  size_t ptr = 0;
  if( ! ((MIDIUtilWriteVarLen( &buffer[0], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[0], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 55, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[0]) == (test[0])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[0]" " has to be equal to " "test[0]" "!" "\n", "test", "util.c", 56, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "1" "!" "\n", "test", "util.c", 57, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilWriteVarLen( &buffer[1], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[1], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 59, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[1]) == (test[1])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[1]" " has to be equal to " "test[1]" "!" "\n", "test", "util.c", 60, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[2]) == (test[2])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[2]" " has to be equal to " "test[2]" "!" "\n", "test", "util.c", 61, "Wrote wrong byte (1) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (2)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "2" "!" "\n", "test", "util.c", 62, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilWriteVarLen( &buffer[2], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[2], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 64, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[3]) == (test[3])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[3]" " has to be equal to " "test[3]" "!" "\n", "test", "util.c", 65, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[4]) == (test[4])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[4]" " has to be equal to " "test[4]" "!" "\n", "test", "util.c", 66, "Wrote wrong byte (1) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[5]) == (test[5])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[5]" " has to be equal to " "test[5]" "!" "\n", "test", "util.c", 67, "Wrote wrong byte (2) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (3)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "3" "!" "\n", "test", "util.c", 68, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilWriteVarLen( &buffer[3], 9-ptr, out+ptr, &bytes )) != 0 || MIDIErrorNumber != 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[3], 9-ptr, out+ptr, &bytes )" " returned no error!" "\n", "test", "util.c", 70, "Wrote number that reached out of the buffer." ); } } while( 0 );; return 1; };
  if( ! ((MIDIUtilWriteVarLen( &buffer[3], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[3], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 71, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[6]) == (test[6])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[6]" " has to be equal to " "test[6]" "!" "\n", "test", "util.c", 72, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[7]) == (test[7])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[7]" " has to be equal to " "test[7]" "!" "\n", "test", "util.c", 73, "Wrote wrong byte (1) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[8]) == (test[8])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[8]" " has to be equal to " "test[8]" "!" "\n", "test", "util.c", 74, "Wrote wrong byte (2) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[9]) == (test[9])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[9]" " has to be equal to " "test[9]" "!" "\n", "test", "util.c", 75, "Wrote wrong byte (3) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (4)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "4" "!" "\n", "test", "util.c", 76, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  return 0;
}

canonical_original_code:
int test002_util() {
  unsigned int buffer[4] = { 0x7f, 0x81, 0x4103, 1<<21 };
  unsigned char out[10] = { 0 };
  unsigned char test[10] = {
    0x7f,
    0x81, 0x01,
    0x81, 0x82, 0x03,
    0x81, 0x80, 0x80, 0x00
  };
  unsigned long bytes = 0;
  unsigned long ptr = 0;
  if( ! ((MIDIUtilWriteVarLen( &buffer[0], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[0], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 55, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[0]) == (test[0])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[0]" " has to be equal to " "test[0]" "!" "\n", "test", "util.c", 56, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "1" "!" "\n", "test", "util.c", 57, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilWriteVarLen( &buffer[1], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[1], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 59, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[1]) == (test[1])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[1]" " has to be equal to " "test[1]" "!" "\n", "test", "util.c", 60, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[2]) == (test[2])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[2]" " has to be equal to " "test[2]" "!" "\n", "test", "util.c", 61, "Wrote wrong byte (1) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (2)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "2" "!" "\n", "test", "util.c", 62, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilWriteVarLen( &buffer[2], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[2], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 64, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[3]) == (test[3])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[3]" " has to be equal to " "test[3]" "!" "\n", "test", "util.c", 65, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[4]) == (test[4])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[4]" " has to be equal to " "test[4]" "!" "\n", "test", "util.c", 66, "Wrote wrong byte (1) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[5]) == (test[5])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[5]" " has to be equal to " "test[5]" "!" "\n", "test", "util.c", 67, "Wrote wrong byte (2) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (3)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "3" "!" "\n", "test", "util.c", 68, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  if( ! ((MIDIUtilWriteVarLen( &buffer[3], 9-ptr, out+ptr, &bytes )) != 0 || MIDIErrorNumber != 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[3], 9-ptr, out+ptr, &bytes )" " returned no error!" "\n", "test", "util.c", 70, "Wrote number that reached out of the buffer." ); } } while( 0 );; return 1; };
  if( ! ((MIDIUtilWriteVarLen( &buffer[3], 10-ptr, out+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &buffer[3], 10-ptr, out+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 71, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
  if( ! ((out[6]) == (test[6])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[6]" " has to be equal to " "test[6]" "!" "\n", "test", "util.c", 72, "Wrote wrong byte (0) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[7]) == (test[7])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[7]" " has to be equal to " "test[7]" "!" "\n", "test", "util.c", 73, "Wrote wrong byte (1) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[8]) == (test[8])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[8]" " has to be equal to " "test[8]" "!" "\n", "test", "util.c", 74, "Wrote wrong byte (2) of number." ); } } while( 0 );; return 1; };
  if( ! ((out[9]) == (test[9])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "out[9]" " has to be equal to " "test[9]" "!" "\n", "test", "util.c", 75, "Wrote wrong byte (3) of number." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (4)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "4" "!" "\n", "test", "util.c", 76, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  ptr+=bytes;
  return 0;
}

variable_types:
buffer
unsigned int [4]

variable_types:
out
unsigned char [10]

variable_types:
test
unsigned char [10]


decompiled_code:
__int64 test003_util()
{
__int64 v0; // r15
char *v1; // rbx
__int128 *v2; // r13
__int64 result; // rax
__int64 v4[5]; // [rsp+20h] [rbp-A0h] BYREF
__int64 v5[3]; // [rsp+48h] [rbp-78h] BYREF
char v6; // [rsp+60h] [rbp-60h] BYREF
__int128 v7; // [rsp+68h] [rbp-58h] BYREF
__int64 v8; // [rsp+78h] [rbp-48h]

v0 = 0LL;
v5[0] = 0x7B00000000LL;
v1 = (char *)v5;
v2 = &v7;
v5[1] = 0x1E240000004D2LL;
v5[2] = 0xF600000009A4000LL;
v7 = 0LL;
v8 = 0LL;
LODWORD(v7) = -889275714;
v4[0] = 0LL;
while ( 1 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v1, 20 - v0, (char *)&v4[1] + v0, v4) )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &in[i], 20-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
92LL,
"Could not write var length number to buffer.");
return 1LL;
}
return 1LL;
}
result = MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v2, 20 - v0, (char *)&v4[1] + v0, v4);
if ( (_DWORD)result )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[i], 20-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
93LL,
"Could not read var length number from buffer.");
return 1LL;
}
if ( *(_DWORD *)v1 != *(_DWORD *)v2 )
break;
v0 += v4[0];
v1 += 4;
v2 = (__int128 *)((char *)v2 + 4);
if ( v1 == &v6 )
return result;
}
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n in[i] has to be equal to out[i]!\n",
"test",
"util.c",
94LL,
"Variable length number did not survive turnaround unharmed.");
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r15
char *v1; // rbx
__int128 *v2; // r13
__int64 result; // rax
__int64 v4[5]; // [rsp+20h] [rbp-A0h] BYREF
__int64 v5[3]; // [rsp+48h] [rbp-78h] BYREF
char v6; // [rsp+60h] [rbp-60h] BYREF
__int128 v7; // [rsp+68h] [rbp-58h] BYREF
__int64 v8; // [rsp+78h] [rbp-48h]

v0 = 0LL;
v5[0] = 0x7B00000000LL;
v1 = (char *)v5;
v2 = &v7;
v5[1] = 0x1E240000004D2LL;
v5[2] = 0xF600000009A4000LL;
v7 = 0LL;
v8 = 0LL;
LODWORD(v7) = -889275714;
v4[0] = 0LL;
while ( 1 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v1, 20 - v0, (char *)&v4[1] + v0, v4) )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilWriteVarLen( &in[i], 20-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
92LL,
"Could not write var length number to buffer.");
return 1LL;
}
return 1LL;
}
result = MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v2, 20 - v0, (char *)&v4[1] + v0, v4);
if ( (_DWORD)result )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" MIDIUtilReadVarLen( &out[i], 20-ptr, buffer+ptr, &bytes ) returned an error!\n",
"test",
"util.c",
93LL,
"Could not read var length number from buffer.");
return 1LL;
}
if ( *(_DWORD *)v1 != *(_DWORD *)v2 )
break;
v0 += v4[0];
v1 += 4;
v2 = (__int128 *)((char *)v2 + 4);
if ( v1 == &v6 )
return result;
}
if ( !MIDILogger )
return 1LL;
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n in[i] has to be equal to out[i]!\n",
"test",
"util.c",
94LL,
"Variable length number did not survive turnaround unharmed.");
return 1LL;
}

original_code:
int test003_util( void ) {
  MIDIVarLen in[6] = { 0, 123, 1234, 123456, 1234<<13, 123<<21 };
  MIDIVarLen out[6] = { 0xcafebabe, 0 };
  unsigned char buffer[20];
  size_t bytes = 0;
  size_t ptr = 0;
  int i;
  for( i=0; i<6; i++ ) {
    if( ! ((MIDIUtilWriteVarLen( &in[i], 20-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &in[i], 20-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 92, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
    if( ! ((MIDIUtilReadVarLen( &out[i], 20-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[i], 20-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 93, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
    if( ! ((in[i]) == (out[i])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "in[i]" " has to be equal to " "out[i]" "!" "\n", "test", "util.c", 94, "Variable length number did not survive turnaround unharmed." ); } } while( 0 );; return 1; };
    ptr+=bytes;
  }
  return 0;
}

canonical_original_code:
int test003_util() {
  unsigned int in[6] = { 0, 123, 1234, 123456, 1234<<13, 123<<21 };
  unsigned int out[6] = { 0xcafebabe, 0 };
  unsigned char buffer[20];
  unsigned long bytes = 0;
  unsigned long ptr = 0;
  int i;
  for( i=0; i<6; i++ ) {
    if( ! ((MIDIUtilWriteVarLen( &in[i], 20-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &in[i], 20-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 92, "Could not write var length number to buffer." ); } } while( 0 );; return 1; };
    if( ! ((MIDIUtilReadVarLen( &out[i], 20-ptr, buffer+ptr, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &out[i], 20-ptr, buffer+ptr, &bytes )" " returned an error!" "\n", "test", "util.c", 93, "Could not read var length number from buffer." ); } } while( 0 );; return 1; };
    if( ! ((in[i]) == (out[i])) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "in[i]" " has to be equal to " "out[i]" "!" "\n", "test", "util.c", 94, "Variable length number did not survive turnaround unharmed." ); } } while( 0 );; return 1; };
    ptr+=bytes;
  }
  return 0;
}

variable_types:
in
unsigned int [6]

variable_types:
out
unsigned int [6]

variable_types:
buffer
unsigned char [20]

variable_types: i int


decompiled_code:
__int64 test004_util()
{
__int64 result; // rax
unsigned int v1; // [rsp+4h] [rbp-44h] BYREF
unsigned __int64 v2; // [rsp+8h] [rbp-40h] BYREF
char v3; // [rsp+15h] [rbp-33h]
__int64 v4; // [rsp+16h] [rbp-32h] BYREF
__int16 v5; // [rsp+1Eh] [rbp-2Ah]

v4 = 0x584838281LL;
v5 = 0;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(&v1, 10LL, &v4, &v2) )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n MIDIUtilReadVarLen( &n, 10, buffer, &bytes ) returned an error!\n",
"test",
"util.c",
110LL,
"Could not read broken stream.");
return 1LL;
}
return 1LL;
}
if ( v1 > 0xFFFFFFF )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n n has to be less or equal 0x0fffffff!\n",
"test",
"util.c",
111LL,
"Over-long number was not truncated.");
return 1LL;
}
return 1LL;
}
if ( v2 != 5 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 5!\n",
"test",
"util.c",
112LL,
"Read wrong number of bytes.");
return 1LL;
}
return 1LL;
}
v1 = 0x10000000;
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v1, 4LL, &v4, &v2);
if ( (_DWORD)result )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n MIDIUtilWriteVarLen( &n, 4, buffer, &bytes ) returned an error!\n",
"test",
"util.c",
114LL,
"Invalid number could not be written.");
return 1LL;
}
return 1LL;
}
if ( v2 > 4 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be less or equal 4!\n",
"test",
"util.c",
115LL,
"Wrote wrong number of bytes.");
return 1LL;
}
return 1LL;
}
if ( *(&v3 + v2) )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n buffer[bytes-1] has to be equal to 0x00!\n",
"test",
"util.c",
116LL,
"Wrote wrong last byte of number.");
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned int v1; // [rsp+4h] [rbp-44h] BYREF
unsigned __int64 v2; // [rsp+8h] [rbp-40h] BYREF
char v3; // [rsp+15h] [rbp-33h]
__int64 v4; // [rsp+16h] [rbp-32h] BYREF
__int16 v5; // [rsp+1Eh] [rbp-2Ah]

v4 = 0x584838281LL;
v5 = 0;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(&v1, 10LL, &v4, &v2) )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n MIDIUtilReadVarLen( &n, 10, buffer, &bytes ) returned an error!\n",
"test",
"util.c",
110LL,
"Could not read broken stream.");
return 1LL;
}
return 1LL;
}
if ( v1 > 0xFFFFFFF )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n n has to be less or equal 0x0fffffff!\n",
"test",
"util.c",
111LL,
"Over-long number was not truncated.");
return 1LL;
}
return 1LL;
}
if ( v2 != 5 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be equal to 5!\n",
"test",
"util.c",
112LL,
"Read wrong number of bytes.");
return 1LL;
}
return 1LL;
}
v1 = 0x10000000;
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v1, 4LL, &v4, &v2);
if ( (_DWORD)result )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n MIDIUtilWriteVarLen( &n, 4, buffer, &bytes ) returned an error!\n",
"test",
"util.c",
114LL,
"Invalid number could not be written.");
return 1LL;
}
return 1LL;
}
if ( v2 > 4 )
{
if ( MIDILogger )
{
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n bytes has to be less or equal 4!\n",
"test",
"util.c",
115LL,
"Wrote wrong number of bytes.");
return 1LL;
}
return 1LL;
}
if ( *(&v3 + v2) )
{
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n buffer[bytes-1] has to be equal to 0x00!\n",
"test",
"util.c",
116LL,
"Wrote wrong last byte of number.");
return 1LL;
}
return result;
}

original_code:
int test004_util( void ) {
  MIDIVarLen n;
  unsigned char buffer[10] = { 0x81, 0x82, 0x83, 0x84, 0x05 };
  size_t bytes;
  if( ! ((MIDIUtilReadVarLen( &n, 10, buffer, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &n, 10, buffer, &bytes )" " returned an error!" "\n", "test", "util.c", 110, "Could not read broken stream." ); } } while( 0 );; return 1; };
  if( ! ((n) <= (0x0fffffff)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "n" " has to be less or equal " "0x0fffffff" "!" "\n", "test", "util.c", 111, "Over-long number was not truncated." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (5)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "5" "!" "\n", "test", "util.c", 112, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  n = 0x80<<21;
  if( ! ((MIDIUtilWriteVarLen( &n, 4, buffer, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &n, 4, buffer, &bytes )" " returned an error!" "\n", "test", "util.c", 114, "Invalid number could not be written." ); } } while( 0 );; return 1; };
  if( ! ((bytes) <= (4)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be less or equal " "4" "!" "\n", "test", "util.c", 115, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  if( ! ((buffer[bytes-1]) == (0x00)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "buffer[bytes-1]" " has to be equal to " "0x00" "!" "\n", "test", "util.c", 116, "Wrote wrong last byte of number." ); } } while( 0 );; return 1; };
  return 0;
}

canonical_original_code:
int test004_util() {
  unsigned int n;
  unsigned char buffer[10] = { 0x81, 0x82, 0x83, 0x84, 0x05 };
  unsigned long bytes;
  if( ! ((MIDIUtilReadVarLen( &n, 10, buffer, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilReadVarLen( &n, 10, buffer, &bytes )" " returned an error!" "\n", "test", "util.c", 110, "Could not read broken stream." ); } } while( 0 );; return 1; };
  if( ! ((n) <= (0x0fffffff)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "n" " has to be less or equal " "0x0fffffff" "!" "\n", "test", "util.c", 111, "Over-long number was not truncated." ); } } while( 0 );; return 1; };
  if( ! ((bytes) == (5)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be equal to " "5" "!" "\n", "test", "util.c", 112, "Read wrong number of bytes." ); } } while( 0 );; return 1; };
  n = 0x80<<21;
  if( ! ((MIDIUtilWriteVarLen( &n, 4, buffer, &bytes )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDIUtilWriteVarLen( &n, 4, buffer, &bytes )" " returned an error!" "\n", "test", "util.c", 114, "Invalid number could not be written." ); } } while( 0 );; return 1; };
  if( ! ((bytes) <= (4)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "bytes" " has to be less or equal " "4" "!" "\n", "test", "util.c", 115, "Wrote wrong number of bytes." ); } } while( 0 );; return 1; };
  if( ! ((buffer[bytes-1]) == (0x00)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "buffer[bytes-1]" " has to be equal to " "0x00" "!" "\n", "test", "util.c", 116, "Wrote wrong last byte of number." ); } } while( 0 );; return 1; };
  return 0;
}

variable_types:
n
unsigned int


MIDIListDestroy

decompiled_code:
void __fastcall MIDIListDestroy(void *ptr)
{
__int64 *v1; // rbx
__int64 *v2; // rbp

if ( ptr )
{
v1 = (__int64 *)*((_QWORD *)ptr + 2);
*((_QWORD *)ptr + 3) = 0LL;
*((_QWORD *)ptr + 2) = 0LL;
while ( v1 )
{
v2 = v1;
v1 = (__int64 *)v1[1];
list_item_release((__int64)ptr, *v2);
free(v2);
}
free(ptr);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 106LL, "[EFAULT] Precondition failed (list != NULL)");
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 *v1; // rbx
__int64 *v2; // rbp

if ( ptr )
{
v1 = (__int64 *)*((_QWORD *)ptr + 2);
*((_QWORD *)ptr + 3) = 0LL;
*((_QWORD *)ptr + 2) = 0LL;
while ( v1 )
{
v2 = v1;
v1 = (__int64 *)v1[1];
func0((__int64)ptr, *v2);
free(v2);
}
free(ptr);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 106LL, "[EFAULT] Precondition failed (list != NULL)");
}
}

original_code:
void MIDIListDestroy( struct MIDIList * list ) {
  struct MIDIIterator * entry;
  struct MIDIIterator * next;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 106, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  entry = list->first;
  list->first = ((void *)0);
  list->last = ((void *)0);
  while( entry != ((void *)0) ) {
    next = entry->next;
    _list_item_release( list, entry->object );
    free( entry );
    entry = next;
  }
  free( list );
}

canonical_original_code:
void MIDIListDestroy(struct MIDIList *list) {
  struct MIDIIterator *entry;
  struct MIDIIterator *next;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 106, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  entry = list->first;
  list->first = ((void *)0);
  list->last = ((void *)0);
  while( entry != ((void *)0) ) {
    next = entry->next;
    _list_item_release( list, entry->object );
    free( entry );
    entry = next;
  }
  free( list );
}

variable_types: struct MIDIList { int refs; struct MIDITypeSpec { unsigned long type_id; char *type_name; unsigned long size; void (*retain)(void *object); void (*release)(void *object); int (*encode)(void *object, unsigned long size, void *buffer, unsigned long *bytes); int (*decode)(void *object, unsigned long size, void *buffer, unsigned long *bytes); } *type; struct MIDIIterator { void *object; struct MIDIIterator *next; } *first; struct MIDIIterator *last; } *

user_defined_types: struct MIDIList { int refs; struct MIDITypeSpec *type; struct MIDIIterator *first; struct MIDIIterator *last; }


MIDIListRelease

decompiled_code:
void __fastcall MIDIListRelease(_DWORD *a1)
{
if ( a1 )
{
if ( (*a1)-- == 1 )
MIDIListDestroy(a1);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 138LL, "[EFAULT] Precondition failed (list != NULL)");
}
}

canonical_decompiled_code:
void __fastcall func3(_DWORD *a1)
{
if ( a1 )
{
if ( (*a1)-- == 1 )
func2(a1);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 138LL, "[EFAULT] Precondition failed (list != NULL)");
}
}

original_code:
void MIDIListRelease( struct MIDIList * list ) {
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 138, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  if( ! --list->refs ) {
    MIDIListDestroy( list );
  }
}

canonical_original_code:
void MIDIListRelease(struct MIDIList *list) {
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 138, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  if( ! --list->refs ) {
    MIDIListDestroy( list );
  }
}

user_defined_types: struct MIDITypeSpec { unsigned long type_id; char *type_name; unsigned long size; void (*retain)(void *object); void (*release)(void *object); int (*encode)(void *object, unsigned long size, void *buffer, unsigned long *bytes); int (*decode)(void *object, unsigned long size, void *buffer, unsigned long *bytes); }

user_defined_types: struct MIDIIterator { void *object; struct MIDIIterator *next; }


MIDIListAdd

decompiled_code:
__int64 __fastcall MIDIListAdd(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // rax
unsigned int v4; // er13
bool v5; // zf
void (*v7)(__int64, const char *, ...); // r10
const char *v8; // r9
__int64 v9; // r8

if ( !a1 )
{
v4 = 14;
v8 = "[EFAULT] Precondition failed (list != NULL)";
v9 = 163LL;
MIDIErrorNumber = 14;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
goto LABEL_9;
return v4;
}
if ( !a2 )
{
v4 = 22;
MIDIErrorNumber = 22;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v8 = "[EINVAL] Precondition failed (item != NULL)";
v9 = 164LL;
LABEL_9:
v7(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v9, v8);
return v4;
}
return v4;
}
v2 = malloc(0x10uLL);
if ( !v2 )
{
MIDIErrorNumber = 12;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: [ENOMEM] %s\n", "midi", "list.c", 168LL, "Failed to allocate space for iterator.");
}
v3 = *(_QWORD *)(a1 + 16);
*v2 = a2;
v4 = 0;
v2[1] = v3;
list_item_retain(a1, a2);
v5 = *(_QWORD *)(a1 + 24) == 0LL;
*(_QWORD *)(a1 + 16) = v2;
if ( !v5 )
return v4;
*(_QWORD *)(a1 + 24) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // rax
unsigned int v4; // er13
bool v5; // zf
void (*v7)(__int64, const char *, ...); // r10
const char *v8; // r9
__int64 v9; // r8

if ( !a1 )
{
v4 = 14;
v8 = "[EFAULT] Precondition failed (list != NULL)";
v9 = 163LL;
MIDIErrorNumber = 14;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
goto LABEL_9;
return v4;
}
if ( !a2 )
{
v4 = 22;
MIDIErrorNumber = 22;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v8 = "[EINVAL] Precondition failed (item != NULL)";
v9 = 164LL;
LABEL_9:
v7(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v9, v8);
return v4;
}
return v4;
}
v2 = malloc(0x10uLL);
if ( !v2 )
{
MIDIErrorNumber = 12;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: [ENOMEM] %s\n", "midi", "list.c", 168LL, "Failed to allocate space for iterator.");
}
v3 = *(_QWORD *)(a1 + 16);
*v2 = a2;
v4 = 0;
v2[1] = v3;
func1(a1, a2);
v5 = *(_QWORD *)(a1 + 24) == 0LL;
*(_QWORD *)(a1 + 16) = v2;
if ( !v5 )
return v4;
*(_QWORD *)(a1 + 24) = v2;
return 0LL;
}

original_code:
int MIDIListAdd( struct MIDIList * list, void * item ) {
  struct MIDIIterator * entry;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 163, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 164, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = malloc( sizeof( struct MIDIIterator ) );
  if( entry == ((void *)0) ) {
    do { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "[" "ENOMEM" "] %s\n", "midi", "list.c", 168, "Failed to allocate space for iterator." ); } } while( 0 );; } while( 0 );
  }
  entry->object = item;
  entry->next = list->first;
  _list_item_retain( list, entry->object );
  list->first = entry;
  if( list->last == ((void *)0) ) {
    list->last = entry;
  }
  return 0;
}

canonical_original_code:
int MIDIListAdd(struct MIDIList *list, void *item) {
  struct MIDIIterator *entry;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 163, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 164, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = malloc( sizeof( struct MIDIIterator ) );
  if( entry == ((void *)0) ) {
    do { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "[" "ENOMEM" "] %s\n", "midi", "list.c", 168, "Failed to allocate space for iterator." ); } } while( 0 );; } while( 0 );
  }
  entry->object = item;
  entry->next = list->first;
  _list_item_retain( list, entry->object );
  list->first = entry;
  if( list->last == ((void *)0) ) {
    list->last = entry;
  }
  return 0;
}

variable_types:
item
void *

variable_types: struct MIDIIterator { void *object; struct MIDIIterator *next; } *


MIDIListRemove

decompiled_code:
__int64 __fastcall MIDIListRemove(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbp
_QWORD *v3; // r13
unsigned int v4; // er12
const char *v6; // r9
__int64 v7; // r8
void (*v8)(__int64, const char *, ...); // r10

if ( a1 )
{
if ( a2 )
{
v2 = *(_QWORD **)(a1 + 16);
v3 = (_QWORD *)(a1 + 16);
while ( v2 )
{
while ( *v2 != a2 )
{
v3 = v2 + 1;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0;
}
if ( *(_QWORD **)(a1 + 24) == v2 )
*(_QWORD *)(a1 + 24) = *v3;
list_item_release(a1, a2);
*v3 = v2[1];
free(v2);
v2 = (_QWORD *)*v3;
}
return 0;
}
v4 = 22;
MIDIErrorNumber = 22;
v8 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v6 = "[EINVAL] Precondition failed (item != NULL)";
v7 = 194LL;
goto LABEL_13;
}
return v4;
}
v4 = 14;
v6 = "[EFAULT] Precondition failed (list != NULL)";
v7 = 193LL;
MIDIErrorNumber = 14;
v8 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( !MIDILogger )
return v4;
LABEL_13:
v8(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v7, v6);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbp
_QWORD *v3; // r13
unsigned int v4; // er12
const char *v6; // r9
__int64 v7; // r8
void (*v8)(__int64, const char *, ...); // r10

if ( a1 )
{
if ( a2 )
{
v2 = *(_QWORD **)(a1 + 16);
v3 = (_QWORD *)(a1 + 16);
while ( v2 )
{
while ( *v2 != a2 )
{
v3 = v2 + 1;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0;
}
if ( *(_QWORD **)(a1 + 24) == v2 )
*(_QWORD *)(a1 + 24) = *v3;
func0(a1, a2);
*v3 = v2[1];
free(v2);
v2 = (_QWORD *)*v3;
}
return 0;
}
v4 = 22;
MIDIErrorNumber = 22;
v8 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v6 = "[EINVAL] Precondition failed (item != NULL)";
v7 = 194LL;
goto LABEL_13;
}
return v4;
}
v4 = 14;
v6 = "[EFAULT] Precondition failed (list != NULL)";
v7 = 193LL;
MIDIErrorNumber = 14;
v8 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( !MIDILogger )
return v4;
LABEL_13:
v8(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v7, v6);
return v4;
}

original_code:
int MIDIListRemove( struct MIDIList * list, void * item ) {
  struct MIDIIterator * entry;
  struct MIDIIterator ** eptr;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 193, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 194, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  eptr = &(list->first);
  entry = list->first;
  while( entry != ((void *)0) ) {
    if( entry->object == item ) {
      if( entry == list->last ) {
        list->last = *eptr;
      }
      _list_item_release( list, entry->object );
      *eptr = entry->next;
      free( entry );
      entry = *eptr;
    } else {
      eptr = &(entry->next);
      entry = entry->next;
    }
  }
  return 0;
}

canonical_original_code:
int MIDIListRemove(struct MIDIList *list, void *item) {
  struct MIDIIterator *entry;
  struct MIDIIterator **eptr;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 193, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 194, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  eptr = &(list->first);
  entry = list->first;
  while( entry != ((void *)0) ) {
    if( entry->object == item ) {
      if( entry == list->last ) {
        list->last = *eptr;
      }
      _list_item_release( list, entry->object );
      *eptr = entry->next;
      free( entry );
      entry = *eptr;
    } else {
      eptr = &(entry->next);
      entry = entry->next;
    }
  }
  return 0;
}

variable_types: struct MIDIIterator { void *object; struct MIDIIterator *next; } **


MIDIListContains

decompiled_code:
__int64 __fastcall MIDIListContains(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
unsigned int v3; // er12
const char *v5; // r9
__int64 v6; // r8
void (*v7)(__int64, const char *, ...); // r10

if ( !a1 )
{
v3 = 14;
v5 = "[EFAULT] Precondition failed (list != NULL)";
v6 = 227LL;
MIDIErrorNumber = 14;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
LABEL_10:
v7(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v6, v5);
return v3;
}
return v3;
}
if ( !a2 )
{
v3 = 22;
MIDIErrorNumber = 22;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v5 = "[EINVAL] Precondition failed (item != NULL)";
v6 = 228LL;
goto LABEL_10;
}
return v3;
}
v2 = *(_QWORD **)(a1 + 16);
do
{
if ( !v2 )
return (unsigned int)-1;
}
while ( *v2 != a2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
unsigned int v3; // er12
const char *v5; // r9
__int64 v6; // r8
void (*v7)(__int64, const char *, ...); // r10

if ( !a1 )
{
v3 = 14;
v5 = "[EFAULT] Precondition failed (list != NULL)";
v6 = 227LL;
MIDIErrorNumber = 14;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
LABEL_10:
v7(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v6, v5);
return v3;
}
return v3;
}
if ( !a2 )
{
v3 = 22;
MIDIErrorNumber = 22;
v7 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v5 = "[EINVAL] Precondition failed (item != NULL)";
v6 = 228LL;
goto LABEL_10;
}
return v3;
}
v2 = *(_QWORD **)(a1 + 16);
do
{
if ( !v2 )
return (unsigned int)-1;
}
while ( *v2 != a2 );
return 0LL;
}

original_code:
int MIDIListContains( struct MIDIList * list, void * item ) {
  struct MIDIIterator * entry;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 227, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 228, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = list->first;
  while( entry != ((void *)0) ) {
    if( entry->object == item ) {
      return 0;
    }
  }
  return -1;
}

canonical_original_code:
int MIDIListContains(struct MIDIList *list, void *item) {
  struct MIDIIterator *entry;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 227, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 228, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = list->first;
  while( entry != ((void *)0) ) {
    if( entry->object == item ) {
      return 0;
    }
  }
  return -1;
}


MIDIListFind

decompiled_code:
__int64 __fastcall MIDIListFind(__int64 a1, _QWORD *a2, __int64 a3, unsigned int (__fastcall *a4)(_QWORD, __int64))
{
_QWORD *v4; // rbx
unsigned int v7; // er12
const char *v9; // r9
__int64 v10; // r8
void (*v11)(__int64, const char *, ...); // r10

if ( !a1 )
{
v7 = 14;
v9 = "[EFAULT] Precondition failed (list != NULL)";
v10 = 253LL;
MIDIErrorNumber = 14;
v11 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
LABEL_10:
v11(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v10, v9);
return v7;
}
return v7;
}
if ( !a2 )
{
v7 = 22;
MIDIErrorNumber = 22;
v11 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v9 = "[EINVAL] Precondition failed (item != NULL)";
v10 = 254LL;
goto LABEL_10;
}
return v7;
}
v4 = *(_QWORD **)(a1 + 16);
do
{
if ( !v4 )
return (unsigned int)-1;
}
while ( a4(*v4, a3) );
*a2 = *v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _QWORD *a2, __int64 a3, unsigned int (__fastcall *a4)(_QWORD, __int64))
{
_QWORD *v4; // rbx
unsigned int v7; // er12
const char *v9; // r9
__int64 v10; // r8
void (*v11)(__int64, const char *, ...); // r10

if ( !a1 )
{
v7 = 14;
v9 = "[EFAULT] Precondition failed (list != NULL)";
v10 = 253LL;
MIDIErrorNumber = 14;
v11 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
LABEL_10:
v11(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v10, v9);
return v7;
}
return v7;
}
if ( !a2 )
{
v7 = 22;
MIDIErrorNumber = 22;
v11 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v9 = "[EINVAL] Precondition failed (item != NULL)";
v10 = 254LL;
goto LABEL_10;
}
return v7;
}
v4 = *(_QWORD **)(a1 + 16);
do
{
if ( !v4 )
return (unsigned int)-1;
}
while ( a4(*v4, a3) );
*a2 = *v4;
return 0LL;
}

original_code:
int MIDIListFind( struct MIDIList * list, void ** item, void * info, int (*func)( void *, void *) ) {
  struct MIDIIterator * entry;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 253, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 254, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = list->first;
  while( entry != ((void *)0) ) {
    if( (*func)( entry->object, info ) == 0 ) {
      *item = entry->object;
      return 0;
    }
  }
  return -1;
}

canonical_original_code:
int MIDIListFind(struct MIDIList *list, void **item, void *info, int (*func)(void *, void *)) {
  struct MIDIIterator *entry;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 253, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(item != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 254, "[" "EINVAL" "] Precondition failed (" "item != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = list->first;
  while( entry != ((void *)0) ) {
    if( (*func)( entry->object, info ) == 0 ) {
      *item = entry->object;
      return 0;
    }
  }
  return -1;
}

variable_types:
item
void **

variable_types:
info
void *

variable_types:
func
int (*)(void *, void *)


MIDIListApply

decompiled_code:
__int64 __fastcall MIDIListApply(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, __int64))
{
__int64 *v4; // rbx
unsigned int v5; // er12
__int64 v6; // rdi
const char *v8; // r9
__int64 v9; // r8
void (*v10)(__int64, const char *, ...); // r10

if ( a1 )
{
if ( a3 )
{
v4 = *(__int64 **)(a1 + 16);
if ( !v4 )
return 0;
v5 = 0;
do
{
v6 = *v4;
v4 = (__int64 *)v4[1];
if ( v6 )
v5 += a3(v6, a2);
}
while ( v4 );
return v5;
}
v5 = 22;
MIDIErrorNumber = 22;
v10 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v8 = "[EINVAL] Precondition failed (func != NULL)";
v9 = 283LL;
goto LABEL_10;
}
return v5;
}
v5 = 14;
v8 = "[EFAULT] Precondition failed (list != NULL)";
v9 = 282LL;
MIDIErrorNumber = 14;
v10 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( !MIDILogger )
return v5;
LABEL_10:
v10(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v9, v8);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, __int64))
{
__int64 *v4; // rbx
unsigned int v5; // er12
__int64 v6; // rdi
const char *v8; // r9
__int64 v9; // r8
void (*v10)(__int64, const char *, ...); // r10

if ( a1 )
{
if ( a3 )
{
v4 = *(__int64 **)(a1 + 16);
if ( !v4 )
return 0;
v5 = 0;
do
{
v6 = *v4;
v4 = (__int64 *)v4[1];
if ( v6 )
v5 += a3(v6, a2);
}
while ( v4 );
return v5;
}
v5 = 22;
MIDIErrorNumber = 22;
v10 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v8 = "[EINVAL] Precondition failed (func != NULL)";
v9 = 283LL;
goto LABEL_10;
}
return v5;
}
v5 = 14;
v8 = "[EFAULT] Precondition failed (list != NULL)";
v9 = 282LL;
MIDIErrorNumber = 14;
v10 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( !MIDILogger )
return v5;
LABEL_10:
v10(16LL, "%s/%s:%i: %s\n", "midi", "list.c", v9, v8);
return v5;
}

original_code:
int MIDIListApply( struct MIDIList * list, void * info, int (*func)( void *, void * ) ) {
  struct MIDIIterator * entry;
  void * item;
  int result = 0;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 282, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(func != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 283, "[" "EINVAL" "] Precondition failed (" "func != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = list->first;
  while( entry != ((void *)0) ) {
    item = entry->object;
    entry = entry->next;
    if( item != ((void *)0) ) {
      result += (*func)( item, info );
    }
  }
  return result;
}

canonical_original_code:
int MIDIListApply(struct MIDIList *list, void *info, int (*func)(void *, void *)) {
  struct MIDIIterator *entry;
  void *item;
  int result = 0;
  do { if( !(list != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 282, "[" "EFAULT" "] Precondition failed (" "list != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(func != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "list.c", 283, "[" "EINVAL" "] Precondition failed (" "func != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  entry = list->first;
  while( entry != ((void *)0) ) {
    item = entry->object;
    entry = entry->next;
    if( item != ((void *)0) ) {
      result += (*func)( item, info );
    }
  }
  return result;
}

variable_types: result int