main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v3; // rbx
unsigned __int64 v4; // r12
void *v5; // rbp
time_t v6; // rax
FILE *stream; // [rsp+8h] [rbp-40h]

stream = fopen64(argv[1], "r");
if ( !stream )
{
perror("file could not be opened for reading\n");
exit(1);
}
v3 = 16LL;
v4 = 0x8000000LL;
do
{
flushcache(argc - 2, argv + 2);
v5 = malloc(v3);
run_experiment(stream, v5, v3);
free(v5);
v6 = time(0LL);
srand(v6 % 0x7FFFFFFF);
v3 += 16LL;
v4 >>= 4;
}
while ( v3 != 131088 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v3; // rbx
unsigned __int64 v4; // r12
void *v5; // rbp
time_t v6; // rax
FILE *stream; // [rsp+8h] [rbp-40h]

stream = fopen64(argv[1], "r");
if ( !stream )
{
perror("file could not be opened for reading\n");
exit(1);
}
v3 = 16LL;
v4 = 0x8000000LL;
do
{
func7(argc - 2, argv + 2);
v5 = malloc(v3);
func12(stream, v5, v3);
free(v5);
v6 = time(0LL);
srand(v6 % 0x7FFFFFFF);
v3 += 16LL;
v4 >>= 4;
}
while ( v3 != 131088 );
return 0;
}

original_code:
int main(int argc, char **argv){
 unsigned long max_offset;
 unsigned long buffer_size=1;
 int fd = open("10GigFile",00|O_LARGEFILE);
 if(fd == -1)
 {
  perror("file could not be opened for reading\n");
  exit(1);
 }
 char* buffer;
 srand(time(((void *)0))%0x7fffffff);
 max_offset = (10240*1024/buffer_size)-1;
 buffer = (char*) malloc(buffer_size*1024);
 run_experiment(fd,buffer,buffer_size*1024,max_offset);
 free(buffer);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 unsigned long max_offset;
 unsigned long buffer_size = 1;
 int fd = open("10GigFile",00|O_LARGEFILE);
 if(fd == -1)
 {
  perror("file could not be opened for reading\n");
  exit(1);
 }
 char *buffer;
 srand(time(((void *)0))%0x7fffffff);
 max_offset = (10240*1024/buffer_size)-1;
 buffer = (char *) malloc(buffer_size*1024);
 run_experiment(fd,buffer,buffer_size*1024,max_offset);
 free(buffer);
    return 0;
}

variable_types:
argv
char **

variable_types: fd int


decompiled_code:
void __fastcall setup_system(int a1, const char **a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rbx
const char **v4; // r12
ssize_t v5; // rax
int v6; // ebp

v2 = malloc(0x100000uLL);
if ( !v2 )
{
perror("malloc");
exit(-1);
}
v3 = v2;
if ( a1 > 0 )
{
v4 = a2;
do
{
v6 = open64(*v4, 0);
if ( v6 == -1 )
{
perror("open");
exit(-1);
}
do
{
while ( 1 )
{
v5 = read(v6, v3, 0x100000uLL);
if ( v5 != -1 )
break;
if ( *__errno_location() != 5 )
{
perror("read");
exit(-1);
}
perror("read");
*v3 = v3[1] + v3[2];
}
*v3 = v3[1] + v3[2];
}
while ( v5 );
if ( close(v6) )
{
perror("close");
exit(-1);
}
++v4;
}
while ( v4 != &a2[(unsigned int)(a1 - 1) + 1] );
}
free(v3);
}

canonical_decompiled_code:
void __fastcall func7(int a1, const char **a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rbx
const char **v4; // r12
ssize_t v5; // rax
int v6; // ebp

v2 = malloc(0x100000uLL);
if ( !v2 )
{
perror("malloc");
exit(-1);
}
v3 = v2;
if ( a1 > 0 )
{
v4 = a2;
do
{
v6 = open64(*v4, 0);
if ( v6 == -1 )
{
perror("open");
exit(-1);
}
do
{
while ( 1 )
{
v5 = read(v6, v3, 0x100000uLL);
if ( v5 != -1 )
break;
if ( *__errno_location() != 5 )
{
perror("read");
exit(-1);
}
perror("read");
*v3 = v3[1] + v3[2];
}
*v3 = v3[1] + v3[2];
}
while ( v5 );
if ( close(v6) )
{
perror("close");
exit(-1);
}
++v4;
}
while ( v4 != &a2[(unsigned int)(a1 - 1) + 1] );
}
free(v3);
}

original_code:
void setup_system(int num_files, char **filenames) {
  char *buffer;
  int fildes;
  buffer = malloc((1<<20));
  if (buffer == ((void *)0)) { perror("malloc"); exit(-1); };
  for (int i = 0; i < num_files; i++) {
      if ((fildes = open(filenames[i], 00)) == -1) { perror("open"); exit(-1); };
      while (1) {
        ssize_t read_size = read(fildes, buffer, (1<<20));
        if (read_size == -1) {
            if ((*__errno_location ()) == 5)
                perror("read");
            else
                if (1) { perror("read"); exit(-1); };
        }
        buffer[0] = buffer[1] + buffer[2];
        if (read_size == 0) break;
      }
      if (close(fildes)) { perror("close"); exit(-1); };
  }
  free(buffer);
}

canonical_original_code:
void setup_system(int num_files, char **filenames) {
  char *buffer;
  int fildes;
  buffer = malloc((1<<20));
  if (buffer == ((void *)0)) { perror("malloc"); exit(-1); };
  for (int i = 0; i < num_files; i++) {
      if ((fildes = open(filenames[i], 00)) == -1) { perror("open"); exit(-1); };
      while (1) {
        long read_size = read(fildes, buffer, (1<<20));
        if (read_size == -1) {
            if ((*__errno_location ()) == 5)
                perror("read");
            else
                if (1) { perror("read"); exit(-1); };
        }
        buffer[0] = buffer[1] + buffer[2];
        if (read_size == 0) break;
      }
      if (close(fildes)) { perror("close"); exit(-1); };
  }
  free(buffer);
}

variable_types:
filenames
char **

variable_types:
buffer
char *

variable_types: fildes int

variable_types: i int

return_type: void


decompiled_code:
__int64 get_clock_frequency()
{
return 3400LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 3400LL;
}

original_code:
long get_clock_frequency(void) {
    return 3400l;
}

canonical_original_code:
long get_clock_frequency() {
    return 3400l;
}

return_type: long


rdtsc

decompiled_code:
__int64 __fastcall rdtsc(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // eax

__asm { rdtscp }
return (a3 << 32) | v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // eax

__asm { rdtscp }
return (a3 << 32) | v3;
}

original_code:
static __inline__ unsigned long long rdtsc(void)
{
 unsigned hi, lo;
 __asm__ __volatile__ (
      "rdtscp\n\t"
      : "=a"(lo), "=d"(hi));
 return ( (unsigned long long)lo) | ( ((unsigned long long)hi)<<32 );
}

canonical_original_code:
static __inline__ unsigned long long rdtsc()
{
 unsigned int hi; unsigned int lo;
 __asm__ __volatile__ (
      "rdtscp\n\t"
      : "=a"(lo), "=d"(hi));
 return ( (unsigned long long)lo) | ( ((unsigned long long)hi)<<32 );
}

variable_types:
hi
unsigned int

variable_types:
lo
unsigned int

return_type: unsigned long long


decompiled_code:
__int64 invariant_tsc()
{
_RAX = 2147483655LL;
__asm { cpuid }
return BYTE1(_RDX) & 1;
}

original_code:
static __inline__ _Bool invariant_tsc(void)
{
  unsigned ret;
  __asm__ __volatile__ (
      "movl $0x80000007, %%eax\n\t"
      "cpuid\n\t"
      "movl %%edx, %0\n\t"
      : "=d"(ret)
      :
      : "%eax"
      );
  return ret & 1 << 8;
}

canonical_original_code:
static __inline__ _Bool invariant_tsc()
{
  unsigned int ret;
  __asm__ __volatile__ (
      "movl $0x80000007, %%eax\n\t"
      "cpuid\n\t"
      "movl %%edx, %0\n\t"
      : "=d"(ret)
      :
      : "%eax"
      );
  return ret & 1 << 8;
}

variable_types:
ret
unsigned int


decompiled_code:
void __fastcall __noreturn busy_loop(void *a1)
{
while ( !*(_BYTE *)a1 )
;
fwrite("busy loop exiting...\n", 1uLL, 0x15uLL, stderr);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(void *a1)
{
while ( !*(_BYTE *)a1 )
;
fwrite("busy loop exiting...\n", 1uLL, 0x15uLL, stderr);
pthread_exit(0LL);
}

original_code:
void *busy_loop(void *_args) {
    struct busy_loop_arg *args = (struct busy_loop_arg *) _args;
    while (!args->done);
    fprintf(stderr, "busy loop exiting...\n");
    pthread_exit(0);
}

variable_types: struct busy_loop_arg { _Bool done; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } exiting_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } exiting; } *

return_type: void *

user_defined_types: struct busy_loop_arg { _Bool done; union pthread_mutex_t exiting_mutex; union pthread_cond_t exiting; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

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


original_code:
int subtract_timespec(struct timespec *ts1, struct timespec *ts2, struct timespec *result) {
    result->tv_sec = ts1->tv_sec - ts2->tv_sec;
    if (ts1->tv_nsec < ts2->tv_nsec) {
        result->tv_nsec = (1000000000) - (ts2->tv_nsec - ts1->tv_nsec);
        result->tv_sec -= 1;
    } else {
        result->tv_nsec = ts1->tv_nsec - ts2->tv_nsec;
    }
    return 0;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types:
result
struct timespec *

return_type: int


decompiled_code:
int __fastcall print_time(_QWORD *a1)
{
return printf("%lu s,%lu ns", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func13(_QWORD *a1)
{
return printf("%lu s,%lu ns", *a1, a1[1]);
}

original_code:
void print_time(struct timespec *tp) {
    printf("%lu s,%lu ns", tp->tv_sec, tp->tv_nsec);
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int __fastcall run_rdtsc_trials(FILE *a1, __int64 a2, __int64 a3)
{
const char *v3; // r14
__int64 v4; // r13
unsigned int v5; // er12
int v6; // er15
double v7; // xmm0_8
double v8; // xmm1_8
int result; // eax
unsigned int i; // ebp
__int64 v11; // rbx
__int64 v12; // rdx
__int64 v13; // rax

v3 = (const char *)a1;
v4 = a2;
v5 = 0;
v6 = a2 & 1;
do
{
for ( i = 0; i != 10; ++i )
{
v11 = rdtsc((__int64)a1, a2, a3);
sleep(v5);
v13 = rdtsc(v5, a2, v12) - v11;
if ( v13 < 0 )
v7 = (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1))
+ (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1));
else
v7 = (double)(int)v13;
if ( v4 < 0 )
v8 = (double)(int)(v6 | ((unsigned __int64)v4 >> 1)) + (double)(int)(v6 | ((unsigned __int64)v4 >> 1));
else
v8 = (double)(int)v4;
printf("%d,%d,%s,%f", i, v5, "rdtsc", v7 / v8);
a2 = (__int64)v3;
printf(",%s\n", v3);
a1 = stdout;
result = fflush(stdout);
}
v5 += 5;
}
while ( v5 != 65 );
return result;
}

canonical_decompiled_code:
int __fastcall func14(FILE *a1, __int64 a2, __int64 a3)
{
const char *v3; // r14
__int64 v4; // r13
unsigned int v5; // er12
int v6; // er15
double v7; // xmm0_8
double v8; // xmm1_8
int result; // eax
unsigned int i; // ebp
__int64 v11; // rbx
__int64 v12; // rdx
__int64 v13; // rax

v3 = (const char *)a1;
v4 = a2;
v5 = 0;
v6 = a2 & 1;
do
{
for ( i = 0; i != 10; ++i )
{
v11 = func9((__int64)a1, a2, a3);
sleep(v5);
v13 = func9(v5, a2, v12) - v11;
if ( v13 < 0 )
v7 = (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1))
+ (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1));
else
v7 = (double)(int)v13;
if ( v4 < 0 )
v8 = (double)(int)(v6 | ((unsigned __int64)v4 >> 1)) + (double)(int)(v6 | ((unsigned __int64)v4 >> 1));
else
v8 = (double)(int)v4;
printf("%d,%d,%s,%f", i, v5, "rdtsc", v7 / v8);
a2 = (__int64)v3;
printf(",%s\n", v3);
a1 = stdout;
result = fflush(stdout);
}
v5 += 5;
}
while ( v5 != 65 );
return result;
}

original_code:
void run_rdtsc_trials(char *extra, unsigned long cpu_freq) {
    unsigned long long start, end;
    double diff, time;
    for (int sleep_time = 0; sleep_time <= 60; sleep_time += 5) {
        for (int trial = 0; trial < 10; trial++) {
            start = rdtsc();
            sleep(sleep_time);
            end = rdtsc();
            diff = (double) (end - start);
            time = diff / cpu_freq;
            printf("%d,%d,%s,%f", trial, sleep_time, "rdtsc", time);
            printf(",%s\n", extra);
            fflush(stdout);
        }
    }
}

canonical_original_code:
void run_rdtsc_trials(char *extra, unsigned long cpu_freq) {
    unsigned long long start; unsigned long long end;
    double diff; double time;
    for (int sleep_time = 0; sleep_time <= 60; sleep_time += 5) {
        for (int trial = 0; trial < 10; trial++) {
            start = rdtsc();
            sleep(sleep_time);
            end = rdtsc();
            diff = (double) (end - start);
            time = diff / cpu_freq;
            printf("%d,%d,%s,%f", trial, sleep_time, "rdtsc", time);
            printf(",%s\n", extra);
            fflush(stdout);
        }
    }
}

variable_types:
extra
char *

variable_types:
start
unsigned long long

variable_types:
end
unsigned long long

variable_types: diff double

variable_types: time double

variable_types: trial int


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

__asm { rdtscp }
return (a3 << 32) | v3;
}


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return fprintf(stderr, "Usage: %s <big file for testing> <setup file 1> [<setup file 2> ...]\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "Usage: %s <big file for testing> <setup file 1> [<setup file 2> ...]\n", a1);
}

original_code:
void print_usage(char *cmd) {
    fprintf(stderr, "Usage: %s <big file for testing> <setup file 1> [<setup file 2> ...]\n", cmd);
}

variable_types:
cmd
char *


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

original_code:
void init_offset_tracker(struct offset_tracker *tracker) {
    tracker->len_offsets = 0;
}

variable_types: struct offset_tracker { unsigned long long offsets[1000]; int len_offsets; } *


original_code:
_Bool already_used(struct offset_tracker *tracker, unsigned long long offset, int read_size) {
    for (int i = 0; i < tracker->len_offsets; i++) {
        if (abs(tracker->offsets[i] - offset) <= (read_size > (128 * 1024) ? read_size : (128 * 1024)))
            return 1;
    }
    return 0;
}

variable_types:
offset
unsigned long long

user_defined_types: struct offset_tracker { unsigned long long offsets[1000]; int len_offsets; }


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

LODWORD(result) = *(_DWORD *)(a1 + 8000);
*(_DWORD *)(a1 + 8000) = result + 1;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result) = a2;
return result;
}

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

LODWORD(result) = *(_DWORD *)(a1 + 8000);
*(_DWORD *)(a1 + 8000) = result + 1;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result) = a2;
return result;
}

original_code:
void register_offset(struct offset_tracker *tracker, unsigned long offset) {
    tracker->offsets[tracker->len_offsets++] = offset;
}

variable_types:
offset
unsigned long


decompiled_code:
unsigned __int64 __fastcall random_offset(__int64 a1, __int64 a2, _DWORD *a3, int a4)
{
__int64 v6; // rbx
int v7; // er14
double v8; // xmm1_8
unsigned __int64 v9; // r15
double v10; // xmm0_8
double v11; // xmm0_8

v6 = a1 - 1 - a4;
v7 = ((_BYTE)a1 - 1 - (_BYTE)a4) & 1;
do
{
v10 = drand48();
if ( v6 < 0 )
v8 = (double)(int)(v7 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v7 | ((unsigned __int64)v6 >> 1));
else
v8 = (double)(int)v6;
v11 = v10 * v8;
if ( v11 >= 9.223372036854776e18 )
v9 = (unsigned int)(int)(v11 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v9 = (unsigned int)(int)v11;
}
while ( (unsigned __int8)already_used(a3, v9, a4) );
register_offset((__int64)a3, v9);
return v9;
}

original_code:
unsigned long long random_offset(size_t file_size, int buf_size, struct offset_tracker *tracker, int read_size) {
    unsigned long long offset;
    while(already_used(tracker, (offset = drand48() * ((unsigned long long) file_size - read_size - 1)), read_size));
    register_offset(tracker, offset);
    return offset;
}

canonical_original_code:
unsigned long long random_offset(unsigned long file_size, int buf_size, struct offset_tracker *tracker, int read_size) {
    unsigned long long offset;
    while(already_used(tracker, (offset = drand48() * ((unsigned long long) file_size - read_size - 1)), read_size));
    register_offset(tracker, offset);
    return offset;
}


repo: jpochyla/pare

decompiled_code:
float __fastcall random_float(float a1, float a2)
{
return (float)((float)rand() / (float)(2147483600.0 / (float)(a2 - a1))) + a1;
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return (float)((float)rand() / (float)(2147483600.0 / (float)(a2 - a1))) + a1;
}

original_code:
static float
random_float(float min, float max) {
  return min + (float)rand() / ((float)2147483647 / (max - min));
}

variable_types: min float

variable_types: max float

return_type: float


original_code:
void
age_particles(par_sys_t *sys, float dt) {
  for (int i = 0; i < sys->par_count; i++) {
    par_t *par = &sys->par[i];
    par->age += dt;
    if (par->age > par->lft) {
      --i;
      --sys->par_count;
      *par = sys->par[sys->par_count];
    } else {
      par->vel += sys->env_acc * dt;
      par->vel += par->acc * dt;
      par->pos += par->vel * dt;
    }
  }
}

canonical_original_code:
void age_particles(struct par_sys_t *sys, float dt) {
  for (int i = 0; i < sys->par_count; i++) {
    struct par_t *par = &sys->par[i];
    par->age += dt;
    if (par->age > par->lft) {
      --i;
      --sys->par_count;
      *par = sys->par[sys->par_count];
    } else {
      par->vel += sys->env_acc * dt;
      par->vel += par->acc * dt;
      par->pos += par->vel * dt;
    }
  }
}

variable_types: struct par_sys_t { struct par_t { float pos; float vel; float acc; float age; float lft; } *par; int par_count; int par_size; float env_acc; float emit_pos; float emit_rate; float emit_residue; float min_emit_lft; float min_emit_angle; float min_emit_accmag; float min_emit_velmag; } *

variable_types: dt float

variable_types: i int

user_defined_types: struct par_sys_t { struct par_t *par; int par_count; int par_size; float env_acc; float emit_pos; float emit_rate; float emit_residue; float min_emit_lft; float min_emit_angle; float min_emit_accmag; float min_emit_velmag; }


original_code:
void
emit_particles(par_sys_t *sys, float n) {
  int np = n + sys->emit_residue;
  for (int i = sys->par_count; i < sys->par_count + np; i++) {
    const float velmag = random_float(sys->min_emit_velmag, sys->max_emit_velmag);
    const float accmag = random_float(sys->min_emit_accmag, sys->max_emit_accmag);
    const float angle = random_float(sys->min_emit_angle, sys->max_emit_angle);
    const float lft = random_float(sys->min_emit_lft, sys->max_emit_lft);
    const vec_t dir = {cosf(angle), sinf(angle)};
    par_t *par = &sys->par[i];
    par->pos = sys->emit_pos;
    par->vel = dir * velmag;
    par->acc = dir * accmag;
    par->lft = lft;
    par->age = 0.0f;
  }
  sys->emit_residue = n - np;
  sys->par_count += np;
}

canonical_original_code:
void emit_particles(struct par_sys_t *sys, float n) {
  int np = n + sys->emit_residue;
  for (int i = sys->par_count; i < sys->par_count + np; i++) {
    float velmag = random_float(sys->min_emit_velmag, sys->max_emit_velmag);
    float accmag = random_float(sys->min_emit_accmag, sys->max_emit_accmag);
    float angle = random_float(sys->min_emit_angle, sys->max_emit_angle);
    float lft = random_float(sys->min_emit_lft, sys->max_emit_lft);
    float dir = {cosf(angle), sinf(angle)};
    struct par_t *par = &sys->par[i];
    par->pos = sys->emit_pos;
    par->vel = dir * velmag;
    par->acc = dir * accmag;
    par->lft = lft;
    par->age = 0.0f;
  }
  sys->emit_residue = n - np;
  sys->par_count += np;
}

variable_types: n float

variable_types: np int

variable_types: velmag float

variable_types: accmag float

variable_types: angle float

variable_types: lft float

variable_types: dir float

variable_types: struct par_t { float pos; float vel; float acc; float age; float lft; } *


decompiled_code:
__int64 __fastcall update_particles(__int64 a1, float a2)
{
age_particles(a1, a2);
return emit_particles(a1, a2 * *(float *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, float a2)
{
func1(a1, a2);
return func2(a1, a2 * *(float *)(a1 + 24));
}

original_code:
void
update_particles(par_sys_t *sys, float dt) {
  age_particles(sys, dt);
  emit_particles(sys, dt * sys->emit_rate);
}

canonical_original_code:
void update_particles(struct par_sys_t *sys, float dt) {
  age_particles(sys, dt);
  emit_particles(sys, dt * sys->emit_rate);
}

user_defined_types: struct par_t { float pos; float vel; float acc; float age; float lft; }


MIDIEventEncode

repo: jpommerening/midikit

decompiled_code:
__int64 __fastcall MIDIEventEncode(__int64 a1, unsigned __int64 a2, __int64 a3)
{
unsigned int v3; // edx

if ( a1 )
{
if ( a3 )
{
v3 = 1;
if ( *(_QWORD *)(a1 + 16) + 8LL > a2 )
{
MIDIErrorNumber = 12;
v3 = 12;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"event.c",
188LL,
"[ENOMEM] Precondition failed (size >= required)");
v3 = 12;
}
}
}
else
{
MIDIErrorNumber = 22;
v3 = 22;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 186LL, "[EINVAL] Precondition failed (buffer != NULL)");
v3 = 22;
}
}
}
else
{
MIDIErrorNumber = 14;
v3 = 14;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 185LL, "[EFAULT] Precondition failed (event != NULL)");
v3 = 14;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2, __int64 a3)
{
unsigned int v3; // edx

if ( a1 )
{
if ( a3 )
{
v3 = 1;
if ( *(_QWORD *)(a1 + 16) + 8LL > a2 )
{
MIDIErrorNumber = 12;
v3 = 12;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"event.c",
188LL,
"[ENOMEM] Precondition failed (size >= required)");
v3 = 12;
}
}
}
else
{
MIDIErrorNumber = 22;
v3 = 22;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 186LL, "[EINVAL] Precondition failed (buffer != NULL)");
v3 = 22;
}
}
}
else
{
MIDIErrorNumber = 14;
v3 = 14;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 185LL, "[EFAULT] Precondition failed (event != NULL)");
v3 = 14;
}
}
return v3;
}

original_code:
int MIDIEventEncode( struct MIDIEvent * event, size_t size, void * buffer, size_t * written ) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 185, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(buffer != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 186, "[" "EINVAL" "] Precondition failed (" "buffer != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  size_t required = 8 + event->length;
  do { if( !(size >= required) ) { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 188, "[" "ENOMEM" "] Precondition failed (" "size >= required" ")" ); } } while( 0 );; return 12;; } } while( 0 );
  return 1;
}

canonical_original_code:
int MIDIEventEncode(struct MIDIEvent *event, unsigned long size, void *buffer, unsigned long *written) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 185, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(buffer != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 186, "[" "EINVAL" "] Precondition failed (" "buffer != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  unsigned long required = 8 + event->length;
  do { if( !(size >= required) ) { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 188, "[" "ENOMEM" "] Precondition failed (" "size >= required" ")" ); } } while( 0 );; return 12;; } } while( 0 );
  return 1;
}

variable_types: struct MIDIEvent { int refs; unsigned long id; unsigned long length; char *message; void *info; } *

variable_types:
size
unsigned long

variable_types:
buffer
void *

variable_types:
written
unsigned long *

variable_types:
required
unsigned long


MIDIEventDecode

decompiled_code:
__int64 __fastcall MIDIEventDecode(__int64 a1, unsigned __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 )
{
if ( a3 )
{
result = 1LL;
if ( a2 <= 4 )
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"event.c",
208LL,
"[EINVAL] Precondition failed (size >= required)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 206LL, "[EINVAL] Precondition failed (buffer != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 205LL, "[EFAULT] Precondition failed (event != NULL)");
result = 14LL;
}
}
return result;
}

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

if ( a1 )
{
if ( a3 )
{
result = 1LL;
if ( a2 <= 4 )
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(
16LL,
"%s/%s:%i: %s\n",
"midi",
"event.c",
208LL,
"[EINVAL] Precondition failed (size >= required)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 206LL, "[EINVAL] Precondition failed (buffer != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 205LL, "[EFAULT] Precondition failed (event != NULL)");
result = 14LL;
}
}
return result;
}

original_code:
int MIDIEventDecode( struct MIDIEvent * event, size_t size, void * buffer, size_t * read ) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 205, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(buffer != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 206, "[" "EINVAL" "] Precondition failed (" "buffer != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  size_t required = 5;
  do { if( !(size >= required) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 208, "[" "EINVAL" "] Precondition failed (" "size >= required" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  return 1;
}

canonical_original_code:
int MIDIEventDecode(struct MIDIEvent *event, unsigned long size, void *buffer, unsigned long *read) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 205, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(buffer != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 206, "[" "EINVAL" "] Precondition failed (" "buffer != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  unsigned long required = 5;
  do { if( !(size >= required) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 208, "[" "EINVAL" "] Precondition failed (" "size >= required" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  return 1;
}

variable_types:
read
unsigned long *

user_defined_types: struct MIDIEvent { int refs; unsigned long id; unsigned long length; char *message; void *info; }


MIDIEventCreate

decompiled_code:
_QWORD *MIDIEventCreate(__int64 a1, __int64 a2, const char *a3, ...)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
char *v6; // rbp
int v7; // eax
__int64 v8; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

v4 = malloc(0x28uLL);
v5 = v4;
if ( v4 )
{
*(_DWORD *)v4 = 1;
v4[1] = a1;
v4[4] = a2;
if ( a3 )
{
v6 = (char *)malloc(0x40uLL);
va_start(arg, a3);
if ( v6 )
{
v7 = vsnprintf(v6, 0x3FuLL, a3, arg);
v8 = v7;
if ( (unsigned __int64)v7 > 0x40 )
v6 = (char *)realloc(v6, v7);
else
v8 = 64LL;
v5[3] = v6;
v5[2] = v8;
}
else
{
MIDIErrorNumber = 12;
if ( MIDILogger )
MIDILogger(
16LL,
"%s/%s:%i: [ENOMEM] %s\n",
"midi",
"event.c",
68LL,
"Could not allocate space for static buffer.");
free(v5);
v5 = 0LL;
}
}
else
{
v4[3] = 0LL;
v4[2] = 0LL;
}
}
else
{
MIDIErrorNumber = 12;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 55LL, "[ENOMEM] Precondition failed (event != NULL)");
}
return v5;
}

canonical_decompiled_code:
_QWORD *func2(__int64 a1, __int64 a2, const char *a3, ...)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
char *v6; // rbp
int v7; // eax
__int64 v8; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

v4 = malloc(0x28uLL);
v5 = v4;
if ( v4 )
{
*(_DWORD *)v4 = 1;
v4[1] = a1;
v4[4] = a2;
if ( a3 )
{
v6 = (char *)malloc(0x40uLL);
va_start(arg, a3);
if ( v6 )
{
v7 = vsnprintf(v6, 0x3FuLL, a3, arg);
v8 = v7;
if ( (unsigned __int64)v7 > 0x40 )
v6 = (char *)realloc(v6, v7);
else
v8 = 64LL;
v5[3] = v6;
v5[2] = v8;
}
else
{
MIDIErrorNumber = 12;
if ( MIDILogger )
MIDILogger(
16LL,
"%s/%s:%i: [ENOMEM] %s\n",
"midi",
"event.c",
68LL,
"Could not allocate space for static buffer.");
free(v5);
v5 = 0LL;
}
}
else
{
v4[3] = 0LL;
v4[2] = 0LL;
}
}
else
{
MIDIErrorNumber = 12;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 55LL, "[ENOMEM] Precondition failed (event != NULL)");
}
return v5;
}

original_code:
struct MIDIEvent * MIDIEventCreate( size_t id, void * info, char * message, ... ) {
  void * buffer;
  size_t length, required;
  va_list vargs;
  struct MIDIEvent * event = malloc( sizeof( struct MIDIEvent ) );
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 55, "[" "ENOMEM" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return ((void *)0);; } } while( 0 );
  event->refs = 1;
  event->id = id;
  event->info = info;
  if( message != ((void *)0) ) {
    length = 64;
    buffer = malloc( length );
    __builtin_va_start(vargs,message);
    do {
      if( buffer == ((void *)0) ) {
        do { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "[" "ENOMEM" "] %s\n", "midi", "event.c", 68, "Could not allocate space for static buffer." ); } } while( 0 );; } while( 0 );
        free (event);
        return ((void *)0);
      }
      required = vsnprintf( buffer, length-1, message, vargs );
      if( required > length ) {
        buffer = realloc( buffer, required );
        length = required;
      }
    } while( required > length );
    __builtin_va_end(vargs);
    event->message = buffer;
    event->length = length;
  } else {
    event->message = ((void *)0);
    event->length = 0;
  }
  return event;
}

canonical_original_code:
struct MIDIEvent *MIDIEventCreate(unsigned long id, void *info, char *message, ...) {
  void *buffer;
  unsigned long length; unsigned long required;
  __builtin_va_list vargs;
  struct MIDIEvent *event = malloc( sizeof( struct MIDIEvent ) );
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 55, "[" "ENOMEM" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return ((void *)0);; } } while( 0 );
  event->refs = 1;
  event->id = id;
  event->info = info;
  if( message != ((void *)0) ) {
    length = 64;
    buffer = malloc( length );
    __builtin_va_start(vargs,message);
    do {
      if( buffer == ((void *)0) ) {
        do { MIDIErrorNumber = 12; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "[" "ENOMEM" "] %s\n", "midi", "event.c", 68, "Could not allocate space for static buffer." ); } } while( 0 );; } while( 0 );
        free (event);
        return ((void *)0);
      }
      required = vsnprintf( buffer, length-1, message, vargs );
      if( required > length ) {
        buffer = realloc( buffer, required );
        length = required;
      }
    } while( required > length );
    __builtin_va_end(vargs);
    event->message = buffer;
    event->length = length;
  } else {
    event->message = ((void *)0);
    event->length = 0;
  }
  return event;
}

variable_types:
id
unsigned long

variable_types:
info
void *

variable_types:
message
char *

variable_types:
length
unsigned long

return_type: struct MIDIEvent { int refs; unsigned long id; unsigned long length; char *message; void *info; } *


MIDIEventDestroy

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 97LL, "[EFAULT] Precondition failed (event != NULL)");
}
}

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 97LL, "[EFAULT] Precondition failed (event != NULL)");
}
}

original_code:
void MIDIEventDestroy( struct MIDIEvent * event ) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 97, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  if( event->message != ((void *)0) ) {
    free( event->message );
  }
  free( event );
}

canonical_original_code:
void MIDIEventDestroy(struct MIDIEvent *event) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 97, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return (void)0;; } } while( 0 );
  if( event->message != ((void *)0) ) {
    free( event->message );
  }
  free( event );
}


MIDIEventRelease

decompiled_code:
void __fastcall MIDIEventRelease(_DWORD *a1)
{
if ( a1 )
{
if ( (*a1)-- == 1 )
MIDIEventDestroy(a1);
}
else
{
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(&loc_10, "%s/%s:%i: %s\n", "midi", "event.c", 123LL, "[EFAULT] Precondition failed (event != NULL)");
}
}

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

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

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


MIDIEventGetId

decompiled_code:
__int64 __fastcall MIDIEventGetId(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 8);
result = 0LL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 146LL, "[EINVAL] Precondition failed (id != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 145LL, "[EFAULT] Precondition failed (event != NULL)");
result = 14LL;
}
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 8);
result = 0LL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 146LL, "[EINVAL] Precondition failed (id != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 145LL, "[EFAULT] Precondition failed (event != NULL)");
result = 14LL;
}
}
return result;
}

original_code:
int MIDIEventGetId( struct MIDIEvent * event, size_t * id ) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 145, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(id != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 146, "[" "EINVAL" "] Precondition failed (" "id != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  *id = event->id;
  return 0;
}

canonical_original_code:
int MIDIEventGetId(struct MIDIEvent *event, unsigned long *id) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 145, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(id != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 146, "[" "EINVAL" "] Precondition failed (" "id != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  *id = event->id;
  return 0;
}

variable_types:
id
unsigned long *


MIDIEventGetInfo

decompiled_code:
__int64 __fastcall MIDIEventGetInfo(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 32);
result = 0LL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 160LL, "[EINVAL] Precondition failed (info != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 159LL, "[EFAULT] Precondition failed (event != NULL)");
result = 14LL;
}
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
*a2 = *(_QWORD *)(a1 + 32);
result = 0LL;
}
else
{
MIDIErrorNumber = 22;
result = 22LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 160LL, "[EINVAL] Precondition failed (info != NULL)");
result = 22LL;
}
}
}
else
{
MIDIErrorNumber = 14;
result = 14LL;
if ( MIDILogger )
{
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 159LL, "[EFAULT] Precondition failed (event != NULL)");
result = 14LL;
}
}
return result;
}

original_code:
int MIDIEventGetInfo( struct MIDIEvent * event, void ** info ) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 159, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(info != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 160, "[" "EINVAL" "] Precondition failed (" "info != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  *info = event->info;
  return 0;
}

canonical_original_code:
int MIDIEventGetInfo(struct MIDIEvent *event, void **info) {
  do { if( !(event != ((void *)0)) ) { MIDIErrorNumber = 14; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 159, "[" "EFAULT" "] Precondition failed (" "event != NULL" ")" ); } } while( 0 );; return 14;; } } while( 0 );
  do { if( !(info != ((void *)0)) ) { MIDIErrorNumber = 22; do { if( MIDILogger != ((void *)0) ) { (*MIDILogger)( 0x10, "%s/%s:%i: " "%s\n", "midi", "event.c", 160, "[" "EINVAL" "] Precondition failed (" "info != NULL" ")" ); } } while( 0 );; return 22;; } } while( 0 );
  *info = event->info;
  return 0;
}

variable_types:
info
void **


MIDIClockGetGlobalClock

decompiled_code:
__int64 __fastcall MIDIClockGetGlobalClock(_QWORD *a1)
{
*a1 = get_global_clock();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
*a1 = func4();
return 0LL;
}

original_code:
int MIDIClockGetGlobalClock( struct MIDIClock ** clock ) {
  *clock = _get_global_clock();
  return 0;
}

canonical_original_code:
int MIDIClockGetGlobalClock(struct MIDIClock **clock) {
  *clock = _get_global_clock();
  return 0;
}

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


MIDIClockDestroy

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

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

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

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

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


MIDIClockProvide

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

if ( midi_global_clock )
{
if ( *(_DWORD *)(midi_global_clock + 16) == a1 )
{
MIDIClockRetain((_DWORD *)midi_global_clock);
result = midi_global_clock;
}
else
{
result = MIDIClockCreate(a1);
}
}
else
{
midi_global_clock = MIDIClockCreate(a1);
MIDIClockRetain((_DWORD *)midi_global_clock);
result = midi_global_clock;
}
return result;
}

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

if ( midi_global_clock )
{
if ( *(_DWORD *)(midi_global_clock + 16) == a1 )
{
MIDIClockRetain((_DWORD *)midi_global_clock);
result = midi_global_clock;
}
else
{
result = func3(a1);
}
}
else
{
midi_global_clock = func3(a1);
MIDIClockRetain((_DWORD *)midi_global_clock);
result = midi_global_clock;
}
return result;
}

original_code:
struct MIDIClock * MIDIClockProvide( MIDISamplingRate rate ) {
  if( _midi_global_clock == ((void *)0) ) {
    _midi_global_clock = MIDIClockCreate( rate );
    MIDIClockRetain( _midi_global_clock );
    return _midi_global_clock;
  } else if( _midi_global_clock->rate == rate ) {
    MIDIClockRetain( _midi_global_clock );
    return _midi_global_clock;
  } else {
    return MIDIClockCreate( rate );
  }
}

canonical_original_code:
struct MIDIClock *MIDIClockProvide(unsigned int rate) {
  if( _midi_global_clock == ((void *)0) ) {
    _midi_global_clock = MIDIClockCreate( rate );
    MIDIClockRetain( _midi_global_clock );
    return _midi_global_clock;
  } else if( _midi_global_clock->rate == rate ) {
    MIDIClockRetain( _midi_global_clock );
    return _midi_global_clock;
  } else {
    return MIDIClockCreate( rate );
  }
}

variable_types:
rate
unsigned int

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


MIDIClockRelease

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

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

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

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

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


MIDIClockSetGlobalClock

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

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

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

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


MIDIClockSetNow

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

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

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

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

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

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

variable_types:
now
long long


MIDIClockGetNow

decompiled_code:
__int64 __fastcall MIDIClockGetNow(__int64 a1, _QWORD *a2)
{
__int64 v2; // rbx
__int64 result; // rax

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

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

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

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

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

variable_types:
now
long long *


MIDIClockSetSamplingRate

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

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

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

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

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

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


MIDIClockGetSamplingRate

decompiled_code:
__int64 __fastcall MIDIClockGetSamplingRate(__int64 a1, _DWORD *a2)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, _DWORD *a2)
{
__int64 result; // rax

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

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

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

variable_types:
rate
unsigned int *


MIDIClockTimestampToSeconds

decompiled_code:
__int64 __fastcall MIDIClockTimestampToSeconds(__int64 a1, __int64 a2, double *a3)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, double *a3)
{
__int64 result; // rax

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

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

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

variable_types:
timestamp
long long

variable_types:
seconds
double *


MIDIClockTimestampFromSeconds

decompiled_code:
__int64 __fastcall MIDIClockTimestampFromSeconds(__int64 a1, _QWORD *a2, double a3)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _QWORD *a2, double a3)
{
__int64 result; // rax

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

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

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

variable_types:
timestamp
long long *

variable_types: seconds double


MIDIClockConvertTimestamp

decompiled_code:
__int64 __fastcall MIDIClockConvertTimestamp(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rbx
_QWORD *v4; // rbp
__int64 result; // rax
unsigned __int64 v7; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rbx
_QWORD *v4; // rbp
__int64 result; // rax
unsigned __int64 v7; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

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

variable_types:
source
struct MIDIClock *

variable_types:
tmp
long long

variable_types:
numer
unsigned long long

variable_types:
denom
unsigned long long


MIDITimerDestroy

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

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

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

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

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

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


MIDITimerRelease

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

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

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

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


decompiled_code:
__int64 test001_util()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-30h] BYREF
__int64 v2; // [rsp+10h] [rbp-28h] BYREF
__int64 v3; // [rsp+18h] [rbp-20h] BYREF
__int64 v4; // [rsp+26h] [rbp-12h] BYREF
__int16 v5; // [rsp+2Eh] [rbp-Ah]

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

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-30h] BYREF
__int64 v2; // [rsp+10h] [rbp-28h] BYREF
__int64 v3; // [rsp+18h] [rbp-20h] BYREF
__int64 v4; // [rsp+26h] [rbp-12h] BYREF
__int16 v5; // [rsp+2Eh] [rbp-Ah]

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

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

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

variable_types:
buffer
unsigned char [10]

variable_types:
out
unsigned int [4]

variable_types:
test
unsigned int [4]

variable_types:
bytes
unsigned long

variable_types:
ptr
unsigned long