decompiled_code:
__int64 test002_util()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-30h] BYREF
__int64 v2; // [rsp+16h] [rbp-22h] BYREF
__int16 v3; // [rsp+1Eh] [rbp-1Ah]
int v4; // [rsp+20h] [rbp-18h] BYREF
int v5; // [rsp+24h] [rbp-14h] BYREF
int v6; // [rsp+28h] [rbp-10h] BYREF
int v7[3]; // [rsp+2Ch] [rbp-Ch] BYREF

v4 = 127;
v5 = 129;
v6 = 16643;
v7[0] = 0x200000;
v2 = 0LL;
v3 = 0;
v1 = 0LL;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v4, 10LL, &v2, &v1) )
{
result = 1LL;
if ( MIDILogger )
{
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 ( v1 == 1 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v5, 9LL, (char *)&v2 + 1, &v1) )
{
result = 1LL;
if ( MIDILogger )
{
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 ( BYTE2(v2) == 1 )
{
if ( v1 == 2 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v6, 7LL, (char *)&v2 + 3, &v1) )
{
result = 1LL;
if ( MIDILogger )
{
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(v7, 3LL, (char *)&v2 + 6, &v1) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v7, 4LL, (char *)&v2 + 6, &v1);
if ( (_DWORD)result )
{
if ( MIDILogger )
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 )
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.");
result = 1LL;
}
}
else
{
if ( MIDILogger )
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 )
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 )
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 )
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 )
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 )
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 )
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 )
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
{
result = 1LL;
if ( MIDILogger )
{
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
{
result = 1LL;
if ( MIDILogger )
{
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;
}
}
}
else
{
result = 1LL;
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.");
result = 1LL;
}
}
}
else
{
result = 1LL;
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.");
result = 1LL;
}
}
}
else
{
result = 1LL;
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.");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-30h] BYREF
__int64 v2; // [rsp+16h] [rbp-22h] BYREF
__int16 v3; // [rsp+1Eh] [rbp-1Ah]
int v4; // [rsp+20h] [rbp-18h] BYREF
int v5; // [rsp+24h] [rbp-14h] BYREF
int v6; // [rsp+28h] [rbp-10h] BYREF
int v7[3]; // [rsp+2Ch] [rbp-Ch] BYREF

v4 = 127;
v5 = 129;
v6 = 16643;
v7[0] = 0x200000;
v2 = 0LL;
v3 = 0;
v1 = 0LL;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v4, 10LL, &v2, &v1) )
{
result = 1LL;
if ( MIDILogger )
{
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 ( v1 == 1 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v5, 9LL, (char *)&v2 + 1, &v1) )
{
result = 1LL;
if ( MIDILogger )
{
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 ( BYTE2(v2) == 1 )
{
if ( v1 == 2 )
{
if ( MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(&v6, 7LL, (char *)&v2 + 3, &v1) )
{
result = 1LL;
if ( MIDILogger )
{
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(v7, 3LL, (char *)&v2 + 6, &v1) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v7, 4LL, (char *)&v2 + 6, &v1);
if ( (_DWORD)result )
{
if ( MIDILogger )
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 )
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.");
result = 1LL;
}
}
else
{
if ( MIDILogger )
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 )
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 )
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 )
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 )
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 )
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 )
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 )
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
{
result = 1LL;
if ( MIDILogger )
{
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
{
result = 1LL;
if ( MIDILogger )
{
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;
}
}
}
else
{
result = 1LL;
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.");
result = 1LL;
}
}
}
else
{
result = 1LL;
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.");
result = 1LL;
}
}
}
else
{
result = 1LL;
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.");
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]


repo: jpommerening/midikit

decompiled_code:
__int64 test003_util()
{
char *v0; // rbx
__int64 *v1; // r13
__int64 v2; // r12
__int64 result; // rax
__int64 v4[5]; // [rsp+18h] [rbp-A0h] BYREF
__int64 v5[4]; // [rsp+40h] [rbp-78h] BYREF
int v6[6]; // [rsp+60h] [rbp-58h] BYREF
char v7; // [rsp+78h] [rbp-40h] BYREF

v6[0] = 0;
v6[1] = 123;
v6[2] = 1234;
v6[3] = 123456;
v6[4] = 10108928;
v6[5] = 257949696;
v5[0] = 3405691582LL;
v5[1] = 0LL;
v5[2] = 0LL;
v4[0] = 0LL;
v0 = (char *)v6;
v1 = v5;
v2 = 0LL;
while ( !(MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v0, 20 - v2, (char *)&v4[1] + v2, v4)) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v1, 20 - v2, (char *)&v4[1] + v2, v4);
if ( (_DWORD)result )
{
result = 1LL;
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.");
result = 1LL;
}
return result;
}
if ( *(_DWORD *)v0 != *(_DWORD *)v1 )
{
result = 1LL;
if ( MIDILogger )
{
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.");
result = 1LL;
}
return result;
}
v2 += v4[0];
v0 += 4;
v1 = (__int64 *)((char *)v1 + 4);
if ( v0 == &v7 )
return result;
}
result = 1LL;
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.");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rbx
__int64 *v1; // r13
__int64 v2; // r12
__int64 result; // rax
__int64 v4[5]; // [rsp+18h] [rbp-A0h] BYREF
__int64 v5[4]; // [rsp+40h] [rbp-78h] BYREF
int v6[6]; // [rsp+60h] [rbp-58h] BYREF
char v7; // [rsp+78h] [rbp-40h] BYREF

v6[0] = 0;
v6[1] = 123;
v6[2] = 1234;
v6[3] = 123456;
v6[4] = 10108928;
v6[5] = 257949696;
v5[0] = 3405691582LL;
v5[1] = 0LL;
v5[2] = 0LL;
v4[0] = 0LL;
v0 = (char *)v6;
v1 = v5;
v2 = 0LL;
while ( !(MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v0, 20 - v2, (char *)&v4[1] + v2, v4)) )
{
result = MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v1, 20 - v2, (char *)&v4[1] + v2, v4);
if ( (_DWORD)result )
{
result = 1LL;
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.");
result = 1LL;
}
return result;
}
if ( *(_DWORD *)v0 != *(_DWORD *)v1 )
{
result = 1LL;
if ( MIDILogger )
{
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.");
result = 1LL;
}
return result;
}
v2 += v4[0];
v0 += 4;
v1 = (__int64 *)((char *)v1 + 4);
if ( v0 == &v7 )
return result;
}
result = 1LL;
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.");
result = 1LL;
}
return result;
}

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:
bytes
unsigned long

variable_types:
ptr
unsigned long

variable_types: i int

return_type: int


decompiled_code:
__int64 test004_util()
{
__int64 result; // rax
unsigned __int64 v1; // [rsp+8h] [rbp-20h] BYREF
char v2; // [rsp+11h] [rbp-17h]
__int64 v3; // [rsp+12h] [rbp-16h] BYREF
__int16 v4; // [rsp+1Ah] [rbp-Eh]
int v5[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v3 = 0x584838281LL;
v4 = 0;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v5, 10LL, &v3, &v1) )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( v5[0] > 0xFFFFFFFu )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( v1 == 5 )
{
v5[0] = 0x10000000;
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v5, 4LL, &v3, &v1);
if ( (_DWORD)result )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( v1 > 4 )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( *(&v2 + v1) )
{
result = 1LL;
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.");
result = 1LL;
}
}
}
else
{
result = 1LL;
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.");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned __int64 v1; // [rsp+8h] [rbp-20h] BYREF
char v2; // [rsp+11h] [rbp-17h]
__int64 v3; // [rsp+12h] [rbp-16h] BYREF
__int16 v4; // [rsp+1Ah] [rbp-Eh]
int v5[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v3 = 0x584838281LL;
v4 = 0;
if ( MIDIErrorNumber | (unsigned int)MIDIUtilReadVarLen(v5, 10LL, &v3, &v1) )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( v5[0] > 0xFFFFFFFu )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( v1 == 5 )
{
v5[0] = 0x10000000;
result = MIDIErrorNumber | (unsigned int)MIDIUtilWriteVarLen(v5, 4LL, &v3, &v1);
if ( (_DWORD)result )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( v1 > 4 )
{
result = 1LL;
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.");
result = 1LL;
}
}
else if ( *(&v2 + v1) )
{
result = 1LL;
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.");
result = 1LL;
}
}
}
else
{
result = 1LL;
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.");
result = 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

variable_types:
buffer
unsigned char [10]


MIDIListDestroy

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

if ( ptr )
{
v1 = (__int64 *)*((_QWORD *)ptr + 2);
*((_QWORD *)ptr + 2) = 0LL;
*((_QWORD *)ptr + 3) = 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 + 2) = 0LL;
*((_QWORD *)ptr + 3) = 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; } *

return_type: void

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(
(char *)&loc_E + 2,
"%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(
(char *)&loc_E + 2,
"%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 result; // rax

if ( a1 )
{
if ( a2 )
{
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.");
}
*v2 = a2;
v2[1] = *(_QWORD *)(a1 + 16);
list_item_retain(a1, a2);
*(_QWORD *)(a1 + 16) = v2;
result = 0LL;
if ( !*(_QWORD *)(a1 + 24) )
*(_QWORD *)(a1 + 24) = v2;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 164LL, "[EINVAL] Precondition failed (item != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 163LL, "[EFAULT] Precondition failed (list != NULL)");
result = 14LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
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.");
}
*v2 = a2;
v2[1] = *(_QWORD *)(a1 + 16);
func1(a1, a2);
*(_QWORD *)(a1 + 16) = v2;
result = 0LL;
if ( !*(_QWORD *)(a1 + 24) )
*(_QWORD *)(a1 + 24) = v2;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 164LL, "[EINVAL] Precondition failed (item != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 163LL, "[EFAULT] Precondition failed (list != NULL)");
result = 14LL;
}
}
return result;
}

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)
{
__int64 **v2; // r13
__int64 *v3; // rbx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 **v2; // r13
__int64 *v3; // rbx
__int64 result; // rax

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

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
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
v2 = *(_QWORD **)(a1 + 16);
while ( v2 )
{
if ( *v2 == a2 )
return 0LL;
}
result = 0xFFFFFFFFLL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 228LL, "[EINVAL] Precondition failed (item != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 227LL, "[EFAULT] Precondition failed (list != NULL)");
result = 14LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
v2 = *(_QWORD **)(a1 + 16);
while ( v2 )
{
if ( *v2 == a2 )
return 0LL;
}
result = 0xFFFFFFFFLL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 228LL, "[EINVAL] Precondition failed (item != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 227LL, "[EFAULT] Precondition failed (list != NULL)");
result = 14LL;
}
}
return result;
}

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, __int64 (__fastcall *a4)(_QWORD, __int64))
{
_QWORD *v6; // rbx
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
v6 = *(_QWORD **)(a1 + 16);
while ( v6 )
{
result = a4(*v6, a3);
if ( !(_DWORD)result )
{
*a2 = *v6;
return result;
}
}
result = 0xFFFFFFFFLL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 254LL, "[EINVAL] Precondition failed (item != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 253LL, "[EFAULT] Precondition failed (list != NULL)");
result = 14LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _QWORD *a2, __int64 a3, __int64 (__fastcall *a4)(_QWORD, __int64))
{
_QWORD *v6; // rbx
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
v6 = *(_QWORD **)(a1 + 16);
while ( v6 )
{
result = a4(*v6, a3);
if ( !(_DWORD)result )
{
*a2 = *v6;
return result;
}
}
result = 0xFFFFFFFFLL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 254LL, "[EINVAL] Precondition failed (item != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 253LL, "[EFAULT] Precondition failed (list != NULL)");
result = 14LL;
}
}
return result;
}

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; // ebp
__int64 v6; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, __int64))
{
__int64 *v4; // rbx
unsigned int v5; // ebp
__int64 v6; // rdi

if ( a1 )
{
if ( a3 )
{
v4 = *(__int64 **)(a1 + 16);
if ( v4 )
{
v5 = 0;
do
{
v6 = *v4;
v4 = (__int64 *)v4[1];
if ( v6 )
v5 += a3(v6, a2);
}
while ( v4 );
}
else
{
v5 = 0;
}
}
else
{
MIDIErrorNumber = 22;
v5 = 22;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 283LL, "[EINVAL] Precondition failed (func != NULL)");
}
}
else
{
MIDIErrorNumber = 14;
v5 = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "list.c", 282LL, "[EFAULT] Precondition failed (list != NULL)");
}
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


decompiled_code:
__int64 test001_rtpv6()
{
unsigned int v0; // ebx
__int64 v2; // rdi
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( MIDIErrorNumber | (unsigned int)rtp_addressv6((__m128i *)&server_address, 5104) )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" _rtp_addressv6( &server_address, RTP_SERVER_PORT ) returned an error!\n",
"test",
"driver_rtpv6.c",
54LL,
"Could not fill out server address.");
}
else
{
v0 = MIDIErrorNumber | rtp_socketv6((int *)v4, &server_address);
if ( v0 )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _rtp_socketv6( &s, &server_address ) returned an error!\n",
"test",
"driver_rtpv6.c",
56LL,
"Could not create server socket.");
}
else
{
v2 = RTPSessionCreate(v4[0]);
session = v2;
if ( v2 )
{
RTPSessionGetSSRC(v2, &v3);
printf("SSRC: 0x%lx\n", v3);
}
else
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _session may not be equal to NULL!\n",
"test",
"driver_rtpv6.c",
60LL,
"Could not create RTP session.");
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
__int64 v2; // rdi
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( MIDIErrorNumber | (unsigned int)func0((__m128i *)&server_address, 5104) )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n"
" _rtp_addressv6( &server_address, RTP_SERVER_PORT ) returned an error!\n",
"test",
"driver_rtpv6.c",
54LL,
"Could not fill out server address.");
}
else
{
v0 = MIDIErrorNumber | func1((int *)v4, &server_address);
if ( v0 )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _rtp_socketv6( &s, &server_address ) returned an error!\n",
"test",
"driver_rtpv6.c",
56LL,
"Could not create server socket.");
}
else
{
v2 = RTPSessionCreate(v4[0]);
session = v2;
if ( v2 )
{
RTPSessionGetSSRC(v2, &v3);
printf("SSRC: 0x%lx\n", v3);
}
else
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _session may not be equal to NULL!\n",
"test",
"driver_rtpv6.c",
60LL,
"Could not create RTP session.");
}
}
}
return v0;
}

original_code:
int test001_rtpv6( void ) {
  int s;
  unsigned long ssrc;
  if( ! ((_rtp_addressv6( &server_address, 5104 )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_addressv6( &server_address, RTP_SERVER_PORT )" " returned an error!" "\n", "test", "driver_rtpv6.c", 54, "Could not fill out server address." ); } } while( 0 );; return 1; };
  if( ! ((_rtp_socketv6( &s, &server_address )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_socketv6( &s, &server_address )" " returned an error!" "\n", "test", "driver_rtpv6.c", 56, "Could not create server socket." ); } } while( 0 );; return 1; };
  _session = RTPSessionCreate( s );
  if( ! ((_session) != (((void *)0))) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_session" " may not be equal to " "NULL" "!" "\n", "test", "driver_rtpv6.c", 60, "Could not create RTP session." ); } } while( 0 );; return 1; };
  RTPSessionGetSSRC( _session, &ssrc );
  printf( "SSRC: 0x%lx\n", ssrc );
  return 0;
}

canonical_original_code:
int test001_rtpv6() {
  int s;
  unsigned long ssrc;
  if( ! ((_rtp_addressv6( &server_address, 5104 )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_addressv6( &server_address, RTP_SERVER_PORT )" " returned an error!" "\n", "test", "driver_rtpv6.c", 54, "Could not fill out server address." ); } } while( 0 );; return 1; };
  if( ! ((_rtp_socketv6( &s, &server_address )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_socketv6( &s, &server_address )" " returned an error!" "\n", "test", "driver_rtpv6.c", 56, "Could not create server socket." ); } } while( 0 );; return 1; };
  _session = RTPSessionCreate( s );
  if( ! ((_session) != (((void *)0))) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_session" " may not be equal to " "NULL" "!" "\n", "test", "driver_rtpv6.c", 60, "Could not create RTP session." ); } } while( 0 );; return 1; };
  RTPSessionGetSSRC( _session, &ssrc );
  printf( "SSRC: 0x%lx\n", ssrc );
  return 0;
}

variable_types: s int

variable_types:
ssrc
unsigned long


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

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

original_code:
int test005_rtpv6( void ) {
  return 0;
}

canonical_original_code:
int test005_rtpv6() {
  return 0;
}


decompiled_code:
__int64 test006_rtpv6()
{
if ( session )
RTPSessionRelease();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
if ( session )
RTPSessionRelease();
return 0LL;
}

original_code:
int test006_rtpv6( void ) {
  if( _session != ((void *)0) ) {
    RTPSessionRelease( _session );
  }
  return 0;
}

canonical_original_code:
int test006_rtpv6() {
  if( _session != ((void *)0) ) {
    RTPSessionRelease( _session );
  }
  return 0;
}


decompiled_code:
__int64 test001_rtp()
{
unsigned int v0; // ebx
__int64 v2; // rdi
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( MIDIErrorNumber | (unsigned int)rtp_address((__int64)&server_address, 5104) )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _rtp_address( &server_address, RTP_SERVER_PORT ) returned an error!\n",
"test",
"driver_rtp.c",
43LL,
"Could not fill out server address.");
}
else
{
v0 = MIDIErrorNumber | rtp_socket((int *)v4, &server_address);
if ( v0 )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _rtp_socket( &s, &server_address ) returned an error!\n",
"test",
"driver_rtp.c",
45LL,
"Could not create server socket.");
}
else
{
v2 = RTPSessionCreate(v4[0]);
session = v2;
if ( v2 )
{
RTPSessionGetSSRC(v2, &v3);
printf("SSRC: 0x%lx\n", v3);
}
else
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _session may not be equal to NULL!\n",
"test",
"driver_rtp.c",
49LL,
"Could not create RTP session.");
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
__int64 v2; // rdi
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( MIDIErrorNumber | (unsigned int)func0((__int64)&server_address, 5104) )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _rtp_address( &server_address, RTP_SERVER_PORT ) returned an error!\n",
"test",
"driver_rtp.c",
43LL,
"Could not fill out server address.");
}
else
{
v0 = MIDIErrorNumber | func1((int *)v4, &server_address);
if ( v0 )
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _rtp_socket( &s, &server_address ) returned an error!\n",
"test",
"driver_rtp.c",
45LL,
"Could not create server socket.");
}
else
{
v2 = RTPSessionCreate(v4[0]);
session = v2;
if ( v2 )
{
RTPSessionGetSSRC(v2, &v3);
printf("SSRC: 0x%lx\n", v3);
}
else
{
v0 = 1;
if ( MIDILogger )
MIDILogger(
32LL,
"%s/%s:%i: error: assertion failed: %s\n _session may not be equal to NULL!\n",
"test",
"driver_rtp.c",
49LL,
"Could not create RTP session.");
}
}
}
return v0;
}

original_code:
int test001_rtp( void ) {
  int s;
  unsigned long ssrc;
  if( ! ((_rtp_address( &server_address, 5104 )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_address( &server_address, RTP_SERVER_PORT )" " returned an error!" "\n", "test", "driver_rtp.c", 43, "Could not fill out server address." ); } } while( 0 );; return 1; };
  if( ! ((_rtp_socket( &s, &server_address )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_socket( &s, &server_address )" " returned an error!" "\n", "test", "driver_rtp.c", 45, "Could not create server socket." ); } } while( 0 );; return 1; };
  _session = RTPSessionCreate( s );
  if( ! ((_session) != (((void *)0))) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_session" " may not be equal to " "NULL" "!" "\n", "test", "driver_rtp.c", 49, "Could not create RTP session." ); } } while( 0 );; return 1; };
  RTPSessionGetSSRC( _session, &ssrc );
  printf( "SSRC: 0x%lx\n", ssrc );
  return 0;
}

canonical_original_code:
int test001_rtp() {
  int s;
  unsigned long ssrc;
  if( ! ((_rtp_address( &server_address, 5104 )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_address( &server_address, RTP_SERVER_PORT )" " returned an error!" "\n", "test", "driver_rtp.c", 43, "Could not fill out server address." ); } } while( 0 );; return 1; };
  if( ! ((_rtp_socket( &s, &server_address )) == 0 && MIDIErrorNumber == 0) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_rtp_socket( &s, &server_address )" " returned an error!" "\n", "test", "driver_rtp.c", 45, "Could not create server socket." ); } } while( 0 );; return 1; };
  _session = RTPSessionCreate( s );
  if( ! ((_session) != (((void *)0))) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "_session" " may not be equal to " "NULL" "!" "\n", "test", "driver_rtp.c", 49, "Could not create RTP session." ); } } while( 0 );; return 1; };
  RTPSessionGetSSRC( _session, &ssrc );
  printf( "SSRC: 0x%lx\n", ssrc );
  return 0;
}


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

original_code:
int test005_rtp( void ) {
  return 0;
}

canonical_original_code:
int test005_rtp() {
  return 0;
}


decompiled_code:
__int64 test006_rtp()
{
if ( session )
RTPSessionRelease();
return 0LL;
}

original_code:
int test006_rtp( void ) {
  if( _session != ((void *)0) ) {
    RTPSessionRelease( _session );
  }
  return 0;
}

canonical_original_code:
int test006_rtp() {
  if( _session != ((void *)0) ) {
    RTPSessionRelease( _session );
  }
  return 0;
}


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

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

original_code:
int test002_midi( void ) {
  if( ! (((((0x01 & 0x7f)<<7) | (0x01 & 0x7f))) == ((1<<7)+1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( 0x01, 0x01 )" " has to be equal to " "(1<<7)+1" "!" "\n", "test", "midi.c", 21, "MIDI_LONG_VALUE macro computes incorrect value." ); } } while( 0 );; return 1; };
  if( ! (((((0x40 & 0x7f)<<7) | (0x00 & 0x7f))) == (1<<13)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( 0x40, 0x00 )" " has to be equal to " "1<<13" "!" "\n", "test", "midi.c", 22, "MIDI_LONG_VALUE macro computes incorrect value." ); } } while( 0 );; return 1; };
  if( ! (((((0x7f & 0x7f)<<7) | (0x7f & 0x7f))) == ((1<<14)-1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( 0x7f, 0x7f )" " has to be equal to " "(1<<14)-1" "!" "\n", "test", "midi.c", 23, "MIDI_LONG_VALUE macro computes incorrect value." ); } } while( 0 );; return 1; };
  return 0;
}

canonical_original_code:
int test002_midi() {
  if( ! (((((0x01 & 0x7f)<<7) | (0x01 & 0x7f))) == ((1<<7)+1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( 0x01, 0x01 )" " has to be equal to " "(1<<7)+1" "!" "\n", "test", "midi.c", 21, "MIDI_LONG_VALUE macro computes incorrect value." ); } } while( 0 );; return 1; };
  if( ! (((((0x40 & 0x7f)<<7) | (0x00 & 0x7f))) == (1<<13)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( 0x40, 0x00 )" " has to be equal to " "1<<13" "!" "\n", "test", "midi.c", 22, "MIDI_LONG_VALUE macro computes incorrect value." ); } } while( 0 );; return 1; };
  if( ! (((((0x7f & 0x7f)<<7) | (0x7f & 0x7f))) == ((1<<14)-1)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( 0x7f, 0x7f )" " has to be equal to " "(1<<14)-1" "!" "\n", "test", "midi.c", 23, "MIDI_LONG_VALUE macro computes incorrect value." ); } } while( 0 );; return 1; };
  return 0;
}


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

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

original_code:
int test003_midi( void ) {
  MIDILongValue v = 12345;
  if( ! (((((((v)>>7) & 0x7f & 0x7f)<<7) | ((v) & 0x7f & 0x7f))) == (v)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( MIDI_MSB( v ), MIDI_LSB( v ) )" " has to be equal to " "v" "!" "\n", "test", "midi.c", 32, "MIDI_LONG_VALUE and MIDI_MSB / MIDI_LSB are not orthogonal." ); } } while( 0 );; return 1; };
  return 0;
}

canonical_original_code:
int test003_midi() {
  short v = 12345;
  if( ! (((((((v)>>7) & 0x7f & 0x7f)<<7) | ((v) & 0x7f & 0x7f))) == (v)) ) { do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x20, "%s/%s:%i: " "error: assertion failed: %s\n  " "MIDI_LONG_VALUE( MIDI_MSB( v ), MIDI_LSB( v ) )" " has to be equal to " "v" "!" "\n", "test", "midi.c", 32, "MIDI_LONG_VALUE and MIDI_MSB / MIDI_LSB are not orthogonal." ); } } while( 0 );; return 1; };
  return 0;
}

variable_types: v short


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

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

original_code:
int test001_runloop( void ) {
  return 0;
}

canonical_original_code:
int test001_runloop() {
  return 0;
}


MIDIUtilReadVarLen

decompiled_code:
__int64 __fastcall MIDIUtilReadVarLen(int *a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v7; // rdx
int v8; // eax
char v9; // cl
__int64 result; // rax

if ( a3 && a1 )
{
v7 = 0LL;
v8 = 0;
if ( a2 )
{
while ( 1 )
{
v9 = *(_BYTE *)(a3 + v7);
v8 = v9 & 0x7F | (v8 << 7);
++v7;
if ( v9 >= 0 )
break;
if ( a2 == v7 )
return 1LL;
}
*a1 = v8 & 0xFFFFFFF;
result = 0LL;
if ( a4 )
*a4 = v7;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "util.c", 28LL, "[EINVAL] Precondition failed (size > 0)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"util.c",
27LL,
"[EINVAL] Precondition failed (buffer != NULL && value != NULL)");
result = 22LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 v7; // rdx
int v8; // eax
char v9; // cl
__int64 result; // rax

if ( a3 && a1 )
{
v7 = 0LL;
v8 = 0;
if ( a2 )
{
while ( 1 )
{
v9 = *(_BYTE *)(a3 + v7);
v8 = v9 & 0x7F | (v8 << 7);
++v7;
if ( v9 >= 0 )
break;
if ( a2 == v7 )
return 1LL;
}
*a1 = v8 & 0xFFFFFFF;
result = 0LL;
if ( a4 )
*a4 = v7;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "util.c", 28LL, "[EINVAL] Precondition failed (size > 0)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"util.c",
27LL,
"[EINVAL] Precondition failed (buffer != NULL && value != NULL)");
result = 22LL;
}
}
return result;
}

original_code:
int MIDIUtilReadVarLen( MIDIVarLen * value, size_t size, unsigned char * buffer, size_t * read ) {
  MIDIVarLen v = 0;
  size_t p = 0;
  do { if( !(buffer != ((void *)0) && value != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 27, "[" "EINVAL" "] Precondition failed (" "buffer != NULL && value != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  do { if( !(size > 0) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 28, "[" "EINVAL" "] Precondition failed (" "size > 0" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  do {
    if( p>=size ) return 1;
    v = (v<<7) | (buffer[p] & 0x7f);
  } while( buffer[p++] & 0x80 );
  *value = v & 0x0fffffff;
  if( read != ((void *)0) ) *read = p;
  return 0;
}

canonical_original_code:
int MIDIUtilReadVarLen(unsigned int *value, unsigned long size, unsigned char *buffer, unsigned long *read) {
  unsigned int v = 0;
  unsigned long p = 0;
  do { if( !(buffer != ((void *)0) && value != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 27, "[" "EINVAL" "] Precondition failed (" "buffer != NULL && value != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  do { if( !(size > 0) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 28, "[" "EINVAL" "] Precondition failed (" "size > 0" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  do {
    if( p>=size ) return 1;
    v = (v<<7) | (buffer[p] & 0x7f);
  } while( buffer[p++] & 0x80 );
  *value = v & 0x0fffffff;
  if( read != ((void *)0) ) *read = p;
  return 0;
}

variable_types:
value
unsigned int *

variable_types:
size
unsigned long

variable_types:
buffer
unsigned char *

variable_types:
read
unsigned long *

variable_types:
v
unsigned int

variable_types:
p
unsigned long


MIDIUtilWriteVarLen

decompiled_code:
__int64 __fastcall MIDIUtilWriteVarLen(_DWORD *a1, unsigned __int64 a2, __int64 a3, unsigned __int64 *a4)
{
unsigned int v7; // eax
int *v8; // rcx
unsigned __int64 v9; // rdx
unsigned __int64 v10; // rsi
__int64 result; // rax
unsigned __int64 v12; // rax
unsigned __int64 v13; // rsi
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

v14[0] = 8421504;
if ( a3 && a1 )
{
if ( a2 )
{
v7 = *a1 & 0xFFFFFFF;
v8 = v14;
v9 = 0LL;
do
{
*((_BYTE *)v8 + 3) |= v7 & 0x7F;
v10 = v9++;
v8 = (int *)((char *)v8 - 1);
v7 >>= 7;
}
while ( v7 && v9 <= 3 );
result = 1LL;
if ( a2 >= v9 )
{
v12 = 4 - v9;
if ( 4 - v9 > 3 )
{
v13 = 0LL;
}
else
{
do
{
*(_BYTE *)(a3 + v10 - 3 + v12) = *((_BYTE *)v14 + v12);
++v12;
}
while ( v12 != 4 );
v13 = v10 + 1;
}
result = 0LL;
if ( a4 )
*a4 = v13;
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "util.c", 54LL, "[EINVAL] Precondition failed (size > 0)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"util.c",
53LL,
"[EINVAL] Precondition failed (buffer != NULL && value != NULL)");
result = 22LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, unsigned __int64 a2, __int64 a3, unsigned __int64 *a4)
{
unsigned int v7; // eax
int *v8; // rcx
unsigned __int64 v9; // rdx
unsigned __int64 v10; // rsi
__int64 result; // rax
unsigned __int64 v12; // rax
unsigned __int64 v13; // rsi
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

v14[0] = 8421504;
if ( a3 && a1 )
{
if ( a2 )
{
v7 = *a1 & 0xFFFFFFF;
v8 = v14;
v9 = 0LL;
do
{
*((_BYTE *)v8 + 3) |= v7 & 0x7F;
v10 = v9++;
v8 = (int *)((char *)v8 - 1);
v7 >>= 7;
}
while ( v7 && v9 <= 3 );
result = 1LL;
if ( a2 >= v9 )
{
v12 = 4 - v9;
if ( 4 - v9 > 3 )
{
v13 = 0LL;
}
else
{
do
{
*(_BYTE *)(a3 + v10 - 3 + v12) = *((_BYTE *)v14 + v12);
++v12;
}
while ( v12 != 4 );
v13 = v10 + 1;
}
result = 0LL;
if ( a4 )
*a4 = v13;
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "util.c", 54LL, "[EINVAL] Precondition failed (size > 0)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"util.c",
53LL,
"[EINVAL] Precondition failed (buffer != NULL && value != NULL)");
result = 22LL;
}
}
return result;
}

original_code:
int MIDIUtilWriteVarLen( MIDIVarLen * value, size_t size, unsigned char * buffer, size_t * written ) {
  MIDIVarLen v = 0;
  unsigned char tmp[4] = { 0x80, 0x80, 0x80, 0x00 };
  size_t p = 0, q = 0;
  do { if( !(buffer != ((void *)0) && value != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 53, "[" "EINVAL" "] Precondition failed (" "buffer != NULL && value != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  do { if( !(size > 0) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 54, "[" "EINVAL" "] Precondition failed (" "size > 0" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  v = *value & 0x0fffffff;
  do {
    tmp[3-p] |= v & 0x7f;
    v >>= 7;
    p++;
  } while( v != 0 && p<4 );
  if( p>size ) return 1;
  q = 4-p;
  for( p=0; q+p<4; p++ ) {
    buffer[p] = tmp[q+p];
  }
  if( written != ((void *)0) ) *written = p;
  return 0;
}

canonical_original_code:
int MIDIUtilWriteVarLen(unsigned int *value, unsigned long size, unsigned char *buffer, unsigned long *written) {
  unsigned int v = 0;
  unsigned char tmp[4] = { 0x80, 0x80, 0x80, 0x00 };
  unsigned long p = 0; unsigned long q = 0;
  do { if( !(buffer != ((void *)0) && value != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 53, "[" "EINVAL" "] Precondition failed (" "buffer != NULL && value != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  do { if( !(size > 0) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "util.c", 54, "[" "EINVAL" "] Precondition failed (" "size > 0" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  v = *value & 0x0fffffff;
  do {
    tmp[3-p] |= v & 0x7f;
    v >>= 7;
    p++;
  } while( v != 0 && p<4 );
  if( p>size ) return 1;
  q = 4-p;
  for( p=0; q+p<4; p++ ) {
    buffer[p] = tmp[q+p];
  }
  if( written != ((void *)0) ) *written = p;
  return 0;
}

variable_types:
written
unsigned long *

variable_types:
tmp
unsigned char [4]

variable_types:
q
unsigned long


repo: jpommerening/template

decompiled_code:
void __fastcall template_destroy(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
}

original_code:
void template_destroy( template_t* template ) {
  if( template->data != ((void *)0) ) {
    free( template->data );
  }
}

canonical_original_code:
void template_destroy(struct template_s *template) {
  if( template->data != ((void *)0) ) {
    free( template->data );
  }
}

variable_types:
template
struct template_s { void *data; } *


repo: jpraher/teyjus

decompiled_code:
void *__fastcall UTIL_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
puts("Error : cannot allocate space");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
puts("Error : cannot allocate space");
exit(1);
}
return result;
}

original_code:
void* UTIL_malloc(size_t n)
{
    void* ptr = (void*)malloc(n);
    if (ptr) return ptr;
    printf("Error : cannot allocate space\n");
    exit(1);
}

canonical_original_code:
void *UTIL_malloc(unsigned long n)
{
    void *ptr = (void*)malloc(n);
    if (ptr) return ptr;
    printf("Error : cannot allocate space\n");
    exit(1);
}

variable_types:
n
unsigned long

variable_types:
ptr
void *

return_type: void *


decompiled_code:
void *__fastcall UTIL_mallocStr(__int64 a1)
{
void *result; // rax

result = malloc(a1 + 1);
if ( !result )
{
puts("Error : cannot allocate space");
exit(1);
}
return result;
}

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

result = malloc(a1 + 1);
if ( !result )
{
puts("Error : cannot allocate space");
exit(1);
}
return result;
}

original_code:
char* UTIL_mallocStr(size_t size)
{
    char* ptr = (char*)malloc(sizeof(char)*(size + 1));
    if (ptr) return ptr;
    printf("Error : cannot allocate space\n");
    exit(1);
}

canonical_original_code:
char *UTIL_mallocStr(unsigned long size)
{
    char *ptr = (char*)malloc(sizeof(char)*(size + 1));
    if (ptr) return ptr;
    printf("Error : cannot allocate space\n");
    exit(1);
}

variable_types:
ptr
char *

return_type: char *


decompiled_code:
char *__fastcall UTIL_appendStr(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v2 + v3 + 1);
strcpy(v4, src);
return strcat(v4, a2);
}

canonical_decompiled_code:
char *__fastcall func2(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)func1(v2 + v3 + 1);
strcpy(v4, src);
return strcat(v4, a2);
}

original_code:
char* UTIL_appendStr(char* str1, char* str2)
{
  size_t length = strlen(str1) + strlen(str2);
  char* ptr = UTIL_mallocStr(length + 1);
  strcpy(ptr, str1);
  strcat(ptr, str2);
  return ptr;
}

canonical_original_code:
char *UTIL_appendStr(char *str1, char *str2)
{
  unsigned long length = strlen(str1) + strlen(str2);
  char *ptr = UTIL_mallocStr(length + 1);
  strcpy(ptr, str1);
  strcat(ptr, str2);
  return ptr;
}

variable_types:
length
unsigned long


decompiled_code:
char *__fastcall UTIL_upperCase(const char *a1)
{
char *v1; // rsi
char v2; // al
char *v3; // rdx

v1 = strdup(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)(v2 - 97) <= 0x19u )
*v3 = v2 - 32;
v2 = *++v3;
}
while ( *v3 );
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
char *v1; // rsi
char v2; // al
char *v3; // rdx

v1 = strdup(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)(v2 - 97) <= 0x19u )
*v3 = v2 - 32;
v2 = *++v3;
}
while ( *v3 );
}
return v1;
}

original_code:
char* UTIL_upperCase(char* str)
{
    char *newstr, *tmp;
    newstr = strdup(str);
    tmp = newstr;
    while ((*tmp) != '\0'){
        if ((97 <= (int)*tmp) && ((int)*tmp <= 122))
            *tmp = (char)((int)*tmp - 32);
        tmp++;
    }
    return newstr;
}

canonical_original_code:
char *UTIL_upperCase(char *str)
{
    char *newstr; char *tmp;
    newstr = strdup(str);
    tmp = newstr;
    while ((*tmp) != '\0'){
        if ((97 <= (int)*tmp) && ((int)*tmp <= 122))
            *tmp = (char)((int)*tmp - 32);
        tmp++;
    }
    return newstr;
}

variable_types:
str
char *

variable_types:
newstr
char *

variable_types:
tmp
char *


decompiled_code:
char *__fastcall UTIL_lowerCase(const char *a1)
{
char *v1; // rsi
char v2; // al
char *v3; // rdx

v1 = strdup(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)(v2 - 65) <= 0x19u )
*v3 = v2 + 32;
v2 = *++v3;
}
while ( *v3 );
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1)
{
char *v1; // rsi
char v2; // al
char *v3; // rdx

v1 = strdup(a1);
v2 = *v1;
if ( *v1 )
{
v3 = v1;
do
{
if ( (unsigned __int8)(v2 - 65) <= 0x19u )
*v3 = v2 + 32;
v2 = *++v3;
}
while ( *v3 );
}
return v1;
}

original_code:
char* UTIL_lowerCase(char* str)
{
    char *newstr, *tmp;
    newstr = strdup(str);
    tmp = newstr;
    while ((*tmp) != '\0'){
        if ((65 <= (int)*tmp) && ((int)*tmp) <= 90)
            *tmp = (char)((int)*tmp + 32);
        tmp++;
    }
    return newstr;
}

canonical_original_code:
char *UTIL_lowerCase(char *str)
{
    char *newstr; char *tmp;
    newstr = strdup(str);
    tmp = newstr;
    while ((*tmp) != '\0'){
        if ((65 <= (int)*tmp) && ((int)*tmp) <= 90)
            *tmp = (char)((int)*tmp + 32);
        tmp++;
    }
    return newstr;
}


decompiled_code:
char *__fastcall UTIL_itoa(unsigned int a1)
{
char *v1; // rbx

v1 = (char *)UTIL_mallocStr(33LL);
sprintf(v1, "%d", a1);
return v1;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1)
{
char *v1; // rbx

v1 = (char *)func1(33LL);
sprintf(v1, "%d", a1);
return v1;
}

original_code:
char* UTIL_itoa(int num)
{
    char *str = UTIL_mallocStr(33);
    sprintf(str, "%d", num);
    return str;
}

canonical_original_code:
char *UTIL_itoa(int num)
{
    char *str = UTIL_mallocStr(33);
    sprintf(str, "%d", num);
    return str;
}

variable_types: num int


addStr

decompiled_code:
char *__fastcall addStr(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx
size_t v6; // rax

if ( src )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v2 + v3);
strcpy(v4, src);
strcat(v4, a2);
}
else
{
v6 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v6);
strcpy(v4, a2);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx
size_t v6; // rax

if ( src )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v2 + v3);
strcpy(v4, src);
strcat(v4, a2);
}
else
{
v6 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v6);
strcpy(v4, a2);
}
return v4;
}

original_code:
static char* addStr(char* str, char* addOn)
{
    size_t length = (str ? strlen(str) : 0) + strlen(addOn);
    char* newStr = UTIL_mallocStr(length);
    if (str) {
        strcpy(newStr, str);
        strcat(newStr, addOn);
    } else strcpy(newStr, addOn);
    return newStr;
}

canonical_original_code:
static char *addStr(char *str, char *addOn)
{
    unsigned long length = (str ? strlen(str) : 0) + strlen(addOn);
    char *newStr = UTIL_mallocStr(length);
    if (str) {
        strcpy(newStr, str);
        strcat(newStr, addOn);
    } else strcpy(newStr, addOn);
    return newStr;
}

variable_types:
addOn
char *

variable_types:
newStr
char *


addLine

decompiled_code:
char *__fastcall addLine(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx
size_t v6; // rax

if ( src )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v2 + v3 + 2);
strcpy(v4, src);
strcat(v4, a2);
}
else
{
v6 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v6 + 2);
strcpy(v4, a2);
}
strcat(v4, "\n\n");
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx
size_t v6; // rax

if ( src )
{
v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v2 + v3 + 2);
strcpy(v4, src);
strcat(v4, a2);
}
else
{
v6 = strlen(a2);
v4 = (char *)UTIL_mallocStr(v6 + 2);
strcpy(v4, a2);
}
strcat(v4, "\n\n");
return v4;
}

original_code:
static char* addLine(char* str, char* addOn)
{
    size_t length = (str ? strlen(str) : 0) + strlen(addOn) + 2;
    char* newStr = UTIL_mallocStr(length);
    if (str) {
        strcpy(newStr, str);
        strcat(newStr, addOn);
    } else strcpy(newStr, addOn);
    strcat(newStr, "\n\n");
    return newStr;
}

canonical_original_code:
static char *addLine(char *str, char *addOn)
{
    unsigned long length = (str ? strlen(str) : 0) + strlen(addOn) + 2;
    char *newStr = UTIL_mallocStr(length);
    if (str) {
        strcpy(newStr, str);
        strcat(newStr, addOn);
    } else strcpy(newStr, addOn);
    strcat(newStr, "\n\n");
    return newStr;
}


ocamlGenFixedML

decompiled_code:
void *ocamlGenFixedML()
{
void *result; // rax

result = (void *)OC_mkFixedML();
fixedML = result;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

result = (void *)OC_mkFixedML();
fixedML = result;
return result;
}

original_code:
static void ocamlGenFixedML()
{
    fixedML = OC_mkFixedML();
}


ocamlGenFixedMLI

decompiled_code:
void *ocamlGenFixedMLI()
{
void *result; // rax

result = (void *)OC_mkFixedMLI();
fixedMLI = result;
return result;
}

canonical_decompiled_code:
void *func3()
{
void *result; // rax

result = (void *)OC_mkFixedMLI();
fixedMLI = result;
return result;
}

original_code:
static void ocamlGenFixedMLI()
{
    fixedMLI = OC_mkFixedMLI();
}


ocamlGenNumKinds

decompiled_code:
char *__fastcall ocamlGenNumKinds(char *a1)
{
char *result; // rax

numKindsMLI = strdup("val numberPervasiveKinds : int");
result = addStr("let numberPervasiveKinds = ", a1);
numKindsML = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *a1)
{
char *result; // rax

numKindsMLI = strdup("val numberPervasiveKinds : int");
result = func0("let numberPervasiveKinds = ", a1);
numKindsML = result;
return result;
}

original_code:
void ocamlGenNumKinds(char* number)
{
    numKindsMLI = strdup("val numberPervasiveKinds : int");
    numKindsML = addStr("let numberPervasiveKinds = ", number);
}

canonical_original_code:
void ocamlGenNumKinds(char *number)
{
    numKindsMLI = strdup("val numberPervasiveKinds : int");
    numKindsML = addStr("let numberPervasiveKinds = ", number);
}

variable_types:
number
char *


ocamlGenKind

decompiled_code:
void __fastcall ocamlGenKind(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
void *v6; // rbx
__int64 v7; // rbp
char *v8; // r15
char *v9; // r14
char *v10; // r13
char *v11; // r12
char *v12; // rbp
char *v13; // rbx
char *v14; // rbx
char *v15; // rbx
char *v16; // rbx
char *v17; // rbx

v6 = (void *)OC_mkKVarName(a2);
v7 = OC_mkIsKindFuncName(v6);
v8 = (char *)OC_mkKindVar(v6, a1, a3, a4);
v9 = (char *)OC_mkTabEntry(a1, v6);
v10 = (char *)OC_mkKindVarDec(v6);
v11 = (char *)OC_mkIsKindFuncDec(v7);
v12 = (char *)OC_mkIsKindFuncDef(v7, v6);
free(v6);
v13 = addLine(kindVarList, v8);
free(kindVarList);
free(v8);
kindVarList = v13;
v14 = addStr(buildPervKindBody, v9);
free(buildPervKindBody);
free(v9);
buildPervKindBody = v14;
v15 = addStr(kindVarDecs, v10);
free(kindVarDecs);
free(v10);
kindVarDecs = v15;
v16 = addStr(isKindFuncDecs, v11);
free(isKindFuncDecs);
free(v11);
isKindFuncDecs = v16;
v17 = addLine(isKindFuncDefs, v12);
free(isKindFuncDefs);
free(v12);
isKindFuncDefs = v17;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
void *v6; // rbx
__int64 v7; // rbp
char *v8; // r15
char *v9; // r14
char *v10; // r13
char *v11; // r12
char *v12; // rbp
char *v13; // rbx
char *v14; // rbx
char *v15; // rbx
char *v16; // rbx
char *v17; // rbx

v6 = (void *)OC_mkKVarName(a2);
v7 = OC_mkIsKindFuncName(v6);
v8 = (char *)OC_mkKindVar(v6, a1, a3, a4);
v9 = (char *)OC_mkTabEntry(a1, v6);
v10 = (char *)OC_mkKindVarDec(v6);
v11 = (char *)OC_mkIsKindFuncDec(v7);
v12 = (char *)OC_mkIsKindFuncDef(v7, v6);
free(v6);
v13 = func1(kindVarList, v8);
free(kindVarList);
free(v8);
kindVarList = v13;
v14 = func0(buildPervKindBody, v9);
free(buildPervKindBody);
free(v9);
buildPervKindBody = v14;
v15 = func0(kindVarDecs, v10);
free(kindVarDecs);
free(v10);
kindVarDecs = v15;
v16 = func0(isKindFuncDecs, v11);
free(isKindFuncDecs);
free(v11);
isKindFuncDecs = v16;
v17 = func1(isKindFuncDefs, v12);
free(isKindFuncDefs);
free(v12);
isKindFuncDefs = v17;
}

original_code:
void ocamlGenKind(char* kindName, char* kVarName, char* arity, char* offset)
{
    char* kindVarName = OC_mkKVarName(kVarName);
    char* funcName = OC_mkIsKindFuncName(kindVarName);
    char* kindVar = OC_mkKindVar(kindVarName, kindName, arity, offset);
    char* kindTabEntry = OC_mkTabEntry(kindName, kindVarName);
    char* kindVarDec = OC_mkKindVarDec(kindVarName);
    char* funcDec = OC_mkIsKindFuncDec(funcName);
    char* funcDef = OC_mkIsKindFuncDef(funcName, kindVarName);
    char *myKindVarList, *myBuildPervKindBody, *myKindVarDecs,
        *myisKindFuncDecs, *myisKindFuncDefs;
    free(kindVarName);
    myKindVarList = addLine(kindVarList, kindVar);
    free(kindVarList); free(kindVar);
    kindVarList = myKindVarList;
    myBuildPervKindBody = addStr(buildPervKindBody, kindTabEntry);
    free(buildPervKindBody); free(kindTabEntry);
    buildPervKindBody = myBuildPervKindBody;
    myKindVarDecs = addStr(kindVarDecs, kindVarDec);
    free(kindVarDecs); free(kindVarDec);
    kindVarDecs = myKindVarDecs;
    myisKindFuncDecs = addStr(isKindFuncDecs, funcDec);
    free(isKindFuncDecs); free(funcDec);
    isKindFuncDecs = myisKindFuncDecs;
    myisKindFuncDefs = addLine(isKindFuncDefs, funcDef);
    free(isKindFuncDefs); free(funcDef);
    isKindFuncDefs = myisKindFuncDefs;
}

canonical_original_code:
void ocamlGenKind(char *kindName, char *kVarName, char *arity, char *offset)
{
    char *kindVarName = OC_mkKVarName(kVarName);
    char *funcName = OC_mkIsKindFuncName(kindVarName);
    char *kindVar = OC_mkKindVar(kindVarName, kindName, arity, offset);
    char *kindTabEntry = OC_mkTabEntry(kindName, kindVarName);
    char *kindVarDec = OC_mkKindVarDec(kindVarName);
    char *funcDec = OC_mkIsKindFuncDec(funcName);
    char *funcDef = OC_mkIsKindFuncDef(funcName, kindVarName);
    char *myKindVarList; char *myBuildPervKindBody; char *myKindVarDecs; char *myisKindFuncDecs; char *myisKindFuncDefs;
    free(kindVarName);
    myKindVarList = addLine(kindVarList, kindVar);
    free(kindVarList); free(kindVar);
    kindVarList = myKindVarList;
    myBuildPervKindBody = addStr(buildPervKindBody, kindTabEntry);
    free(buildPervKindBody); free(kindTabEntry);
    buildPervKindBody = myBuildPervKindBody;
    myKindVarDecs = addStr(kindVarDecs, kindVarDec);
    free(kindVarDecs); free(kindVarDec);
    kindVarDecs = myKindVarDecs;
    myisKindFuncDecs = addStr(isKindFuncDecs, funcDec);
    free(isKindFuncDecs); free(funcDec);
    isKindFuncDecs = myisKindFuncDecs;
    myisKindFuncDefs = addLine(isKindFuncDefs, funcDef);
    free(isKindFuncDefs); free(funcDef);
    isKindFuncDefs = myisKindFuncDefs;
}

variable_types:
kindName
char *

variable_types:
kVarName
char *

variable_types:
arity
char *

variable_types:
offset
char *

variable_types:
kindVarName
char *

variable_types:
funcName
char *

variable_types:
kindVar
char *

variable_types:
kindTabEntry
char *

variable_types:
kindVarDec
char *

variable_types:
funcDec
char *

variable_types:
funcDef
char *

variable_types:
myKindVarList
char *

variable_types:
myBuildPervKindBody
char *

variable_types:
myKindVarDecs
char *

variable_types:
myisKindFuncDecs
char *

variable_types:
myisKindFuncDefs
char *