main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *i; // r14
int v5; // er15
const char *v6; // rdi
unsigned __int8 v7; // r14
unsigned __int8 v8; // al
unsigned int v9; // er9
__int64 v10; // rax
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
__int64 v14; // rdx
size_t v15; // rbx
size_t v16; // rax
__int64 v17; // rsi
int v18; // eax
int v19; // ebx
unsigned int v20; // er12
FILE *v21; // r13
char v22[1028]; // [rsp+0h] [rbp-4C0h] BYREF
int status; // [rsp+404h] [rbp-BCh]
char *s; // [rsp+408h] [rbp-B8h]
__int64 v25; // [rsp+410h] [rbp-B0h]
__int64 v26; // [rsp+418h] [rbp-A8h]
char v27[8]; // [rsp+420h] [rbp-A0h] BYREF
__int64 v28; // [rsp+428h] [rbp-98h]
int v29; // [rsp+430h] [rbp-90h]
int v30; // [rsp+434h] [rbp-8Ch]
char v31[8]; // [rsp+440h] [rbp-80h] BYREF
__int64 v32; // [rsp+448h] [rbp-78h]
char *v33; // [rsp+450h] [rbp-70h]
int v34; // [rsp+458h] [rbp-68h]
char v35[8]; // [rsp+460h] [rbp-60h] BYREF
__int64 v36; // [rsp+468h] [rbp-58h]
char *v37; // [rsp+470h] [rbp-50h]
int v38; // [rsp+478h] [rbp-48h]
char *v39; // [rsp+480h] [rbp-40h]
int v40; // [rsp+488h] [rbp-38h]

for ( i = 0LL; ; i = (const char *)optarg )
{
v5 = getopt(argc, (char *const *)argv, "h:");
if ( v5 == -1 )
break;
if ( v5 == 63 )
{
v20 = optopt;
v21 = stderr;
if ( optopt == 104 )
{
fprintf(stderr, "Option -%c requires an argument.\n", 104LL);
}
else if ( ((*__ctype_b_loc())[v20] & 0x4000) != 0 )
{
fprintf(v21, "Unknown option `-%c'.\n", v20);
}
else
{
fprintf(v21, "Unknown option character `\\x%x'.\n", v20);
}
LABEL_42:
abort();
}
if ( v5 != 104 )
goto LABEL_42;
}
if ( i )
printf("hash = %s\n", i);
if ( argc - optind <= 1 )
{
printf(
"This takes two(2) or three(3) arguments:\n"
"-h <checksum type to use> (Unnecessary for mode 1 and 3. defaults to md5 for mode 2)\n"
"1: the mode(1 or 2 or 3)[REQUIRED]\n"
"2: the filename[REQUIRED]\n"
"3: user credential(Optional for mode 1)\n"
". The system will now exit\n"
"A possible argument type could be\n"
"-h md5 2 abc.txt password");
exit(-1);
}
LODWORD(v25) = optind;
v6 = argv[optind];
v26 = 8LL * optind;
v7 = atoi(v6);
v8 = v7 - 1;
v9 = v25 + 2;
if ( argc <= (int)v25 + 2 )
{
if ( v8 <= 2u )
{
if ( (unsigned __int8)(v7 - 2) > 1u )
{
s = 0LL;
goto LABEL_14;
}
LABEL_24:
puts("For mode 2 and 3 the third argument(credential) is a required field");
exit(-1);
}
}
else
{
s = *(char **)((char *)argv + v26 + 16);
if ( v8 <= 2u )
{
if ( (unsigned __int8)(v7 - 2) > 1u || s )
{
v9 = v25 + 3;
LABEL_14:
v10 = *(__int64 *)((char *)argv + v26 + 8);
LODWORD(v26) = v9;
v25 = v10;
printf("argc: %d, index: %d\n", (unsigned int)argc, v9);
v13 = (int)v26;
if ( v7 == 3 && argc <= 5 )
{
puts("With mode 3, you need to pass flag and mode to open the file in.");
exit(-1);
}
v14 = 0xFFFFFFFFLL;
if ( v7 == 3 )
{
v5 = atoi(argv[(int)v26]);
v14 = (unsigned int)atoi(argv[(int)v26 + 1]);
}
switch ( v7 )
{
case 2u:
v35[0] = 2;
v37 = v22;
v36 = v25;
v38 = 1024;
v39 = s;
v40 = strlen(s);
status = syscall(349LL, v35);
if ( !status )
{
puts("The integrity of the file updated successfully.");
goto LABEL_21;
}
break;
case 3u:
v27[0] = 3;
v29 = v5;
v28 = v25;
v30 = v14;
v18 = syscall(349LL, v27, v14, v11, v12, v13);
status = v18;
v19 = v18;
if ( v18 > 0 )
{
printf("The file descriptor received is: %d\n", (unsigned int)v18);
close(v19);
goto LABEL_21;
}
break;
case 1u:
v31[0] = 1;
v33 = v22;
v32 = v25;
v34 = 1024;
status = syscall(349LL, v31, v14, v11, v12, v13);
if ( !status )
{
v15 = 0LL;
v16 = strlen(v22);
printf("\nReturned from sys call for mode 1 successfully. sizeof ibuf: %d\n", v16);
while ( strlen(v22) > v15 )
{
v17 = (unsigned __int8)v22[v15++];
printf("%02x", v17);
}
putchar(10);
LABEL_21:
exit(status);
}
break;
default:
goto LABEL_21;
}
perror("Error in calling syscall");
goto LABEL_21;
}
goto LABEL_24;
}
}
printf("The value of flag entered is: %d\nThe accepted values of flag are : 1 or 2 or 3.\nSys will now exit\n", v7);
exit(-1);
}

original_code:
int main(int argc, char *argv[])
{
 int rc, c, index,ii=0;
 int fflag=-1, mode = -1;
    unsigned char flag = 0;
 char *filename = ((void *)0);
 char *pass = ((void *)0);
    char *hash = ((void *)0);
    mode1_args argsm1;
 mode2_args argsm2;
 mode3_args argsm3;
 void *args;
 unsigned int ilen = 1024;
 unsigned char ibuf[ilen];
    while ((c = getopt (argc, argv, "h:")) != -1)
        switch (c)
    {
        case 'h':
            hash = optarg;
            break;
        case '?':
            if (optopt == 'h')
                fprintf (stderr, "Option -%c requires an argument.\n", optopt);
            else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint))
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
        default:
            abort ();
    }
    if(hash)
        printf ("hash = %s\n", hash);
    index = optind;
    if (argc-index < 2){
  printf("This takes two(2) or three(3) arguments:\n"
               "-h <checksum type to use> (Unnecessary for mode 1 and 3. defaults to md5 for mode 2)\n"
               "1: the mode(1 or 2 or 3)[REQUIRED]\n"
               "2: the filename[REQUIRED]\n"
               "3: user credential(Optional for mode 1)\n. The system will now exit\n"
               "A possible argument type could be\n"
               "-h md5 2 abc.txt password");
  exit(-1);
 }
    flag = atoi(argv[index++]);
    filename = argv[index++];
    if(index < argc)
        pass = argv[index++];
 if (flag<1 || flag>3){
  printf("The value of flag entered is: %d\n"
               "The accepted values of flag are : 1 or 2 or 3.\n"
               "Sys will now exit\n", flag);
  exit(-1);
 }
    if((flag == 2 || flag == 3) && pass==((void *)0)){
        printf("For mode 2 and 3 the third argument(credential) is a required field\n");
        exit(-1);
    }
    printf("argc: %d, index: %d\n", argc,index);
    if(flag == 3 && argc < 6){
 printf("With mode 3, you need to pass flag and mode to open the file in.\n");
 exit(-1);
    }
    if(flag == 3){
      fflag = atoi(argv[index++]);
 mode = atoi(argv[index]);
    }
 switch(flag){
        case 1:
   argsm1.flag = 1;
   argsm1.filename = filename;
            argsm1.ibuf = ibuf;
            argsm1.ilen = ilen;
   args = &argsm1;
            rc = syscall(349, args);
            if(!rc){
                printf("\nReturned from sys call for mode 1 successfully. sizeof ibuf: %d\n",strlen((char *)ibuf));
            for(ii=0; ii< strlen((char *)ibuf);ii++)
                printf("%02x",*(ibuf+ii));
            printf("\n");
     }
            else
                perror("Error in calling syscall");
            break;
        case 2:
   argsm2.flag = 2;
   argsm2.filename = filename;
            argsm2.ibuf = ibuf;
            argsm2.ilen = ilen;
            argsm2.credbuf = (unsigned char*)pass;
            argsm2.clen = strlen(pass);
   args = &argsm2;
            rc = syscall(349, args);
            if(!rc)
                printf("The integrity of the file updated successfully.\n");
            else
                perror("Error in calling syscall");
            break;
        case 3:
   argsm3.flag = 3;
   argsm3.filename = filename;
            argsm3.oflag = fflag;
            argsm3.mode = mode;
   args = &argsm3;
            rc = syscall(349, args);
            if(rc > 0){
                printf("The file descriptor received is: %d\n",rc);
                close(rc);
            }
            else
                perror("Error in calling syscall");
            break;
 }
 exit(rc);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int rc; int c; int index; int ii = 0;
 int fflag = -1; int mode = -1;
    unsigned char flag = 0;
 char *filename = ((void *)0);
 char *pass = ((void *)0);
    char *hash = ((void *)0);
    struct mode1_args argsm1;
 struct mode2_args argsm2;
 struct mode3_args argsm3;
 void *args;
 unsigned int ilen = 1024;
 unsigned char ibuf[-1];
    while ((c = getopt (argc, argv, "h:")) != -1)
        switch (c)
    {
        case 'h':
            hash = optarg;
            break;
        case '?':
            if (optopt == 'h')
                fprintf (stderr, "Option -%c requires an argument.\n", optopt);
            else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint))
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
        default:
            abort ();
    }
    if(hash)
        printf ("hash = %s\n", hash);
    index = optind;
    if (argc-index < 2){
  printf("This takes two(2) or three(3) arguments:\n"
               "-h <checksum type to use> (Unnecessary for mode 1 and 3. defaults to md5 for mode 2)\n"
               "1: the mode(1 or 2 or 3)[REQUIRED]\n"
               "2: the filename[REQUIRED]\n"
               "3: user credential(Optional for mode 1)\n. The system will now exit\n"
               "A possible argument type could be\n"
               "-h md5 2 abc.txt password");
  exit(-1);
 }
    flag = atoi(argv[index++]);
    filename = argv[index++];
    if(index < argc)
        pass = argv[index++];
 if (flag<1 || flag>3){
  printf("The value of flag entered is: %d\n"
               "The accepted values of flag are : 1 or 2 or 3.\n"
               "Sys will now exit\n", flag);
  exit(-1);
 }
    if((flag == 2 || flag == 3) && pass==((void *)0)){
        printf("For mode 2 and 3 the third argument(credential) is a required field\n");
        exit(-1);
    }
    printf("argc: %d, index: %d\n", argc,index);
    if(flag == 3 && argc < 6){
 printf("With mode 3, you need to pass flag and mode to open the file in.\n");
 exit(-1);
    }
    if(flag == 3){
      fflag = atoi(argv[index++]);
 mode = atoi(argv[index]);
    }
 switch(flag){
        case 1:
   argsm1.flag = 1;
   argsm1.filename = filename;
            argsm1.ibuf = ibuf;
            argsm1.ilen = ilen;
   args = &argsm1;
            rc = syscall(349, args);
            if(!rc){
                printf("\nReturned from sys call for mode 1 successfully. sizeof ibuf: %d\n",strlen((char *)ibuf));
            for(ii=0; ii< strlen((char *)ibuf);ii++)
                printf("%02x",*(ibuf+ii));
            printf("\n");
     }
            else
                perror("Error in calling syscall");
            break;
        case 2:
   argsm2.flag = 2;
   argsm2.filename = filename;
            argsm2.ibuf = ibuf;
            argsm2.ilen = ilen;
            argsm2.credbuf = (unsigned char *)pass;
            argsm2.clen = strlen(pass);
   args = &argsm2;
            rc = syscall(349, args);
            if(!rc)
                printf("The integrity of the file updated successfully.\n");
            else
                perror("Error in calling syscall");
            break;
        case 3:
   argsm3.flag = 3;
   argsm3.filename = filename;
            argsm3.oflag = fflag;
            argsm3.mode = mode;
   args = &argsm3;
            rc = syscall(349, args);
            if(rc > 0){
                printf("The file descriptor received is: %d\n",rc);
                close(rc);
            }
            else
                perror("Error in calling syscall");
            break;
 }
 exit(rc);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: index int

variable_types: ii int

variable_types: fflag int

variable_types: mode int

variable_types:
flag
unsigned char

variable_types:
filename
char *

variable_types:
pass
char *

variable_types:
hash
char *

variable_types: struct mode1_args { unsigned char flag; char *filename; unsigned char *ibuf; unsigned int ilen; }

variable_types: struct mode2_args { unsigned char flag; char *filename; unsigned char *ibuf; unsigned int ilen; unsigned char *credbuf; unsigned int clen; }

variable_types: struct mode3_args { unsigned char flag; char *filename; int oflag; int mode; }

variable_types:
ilen
unsigned int

variable_types:
ibuf
unsigned char [-1]


decompiled_code:
int __fastcall write_to_file(int fd)
{
ssize_t v1; // rax

v1 = write(fd, "HELLO WORLD", 0xBuLL);
printf("%d bytes written", v1);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func7(int fd)
{
ssize_t v1; // rax

v1 = write(fd, "HELLO WORLD", 0xBuLL);
printf("%d bytes written", v1);
return close(fd);
}

original_code:
void write_to_file(int fd){
    char *buf = "HELLO WORLD";
    int bts = -1;
    bts = write(fd, buf, strlen(buf));
    printf("%d bytes written", bts);
    close(fd);
}

variable_types: fd int

variable_types:
buf
char *

variable_types: bts int

return_type: void


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

if ( a1 == 1 )
{
*a2 = "io_node.tch";
result = 544LL;
}
else if ( a1 == 2 )
{
*a2 = "io_data.tch";
result = 0LL;
}
else
{
*a2 = "meta_data.tch";
result = 1160LL;
}
return result;
}

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

if ( a1 == 1 )
{
*a2 = "io_node.tch";
result = 544LL;
}
else if ( a1 == 2 )
{
*a2 = "io_data.tch";
result = 0LL;
}
else
{
*a2 = "meta_data.tch";
result = 1160LL;
}
return result;
}

original_code:
static inline int get_db(tc_t type,char **db)
{
 switch(type){
  case MD:
   *db = "meta_data.tch";
   return sizeof(Meta_Data);
  case ION:
   *db = "io_node.tch";
   return sizeof(IO_Node);
  case IOD:
   *db = "io_data.tch";
   return 0;
  default:
   fprintf(stderr,"unrecognized tc type!\n");
   break;
 }
 return 0;
}

canonical_original_code:
static inline int get_db(enum tc_t type, char **db)
{
 switch(type){
  case MD:
   *db = "meta_data.tch";
   return sizeof(Meta_Data);
  case ION:
   *db = "io_node.tch";
   return sizeof(IO_Node);
  case IOD:
   *db = "io_data.tch";
   return 0;
  default:
   fprintf(stderr,"unrecognized tc type!\n");
   break;
 }
 return 0;
}

variable_types:
type
enum tc_t { MD=0, ION=1, IOD=2 }

variable_types:
db
char **

return_type: int


decompiled_code:
__int64 __fastcall tc_get(const char *a1, void *a2, int a3)
{
unsigned int v4; // er13
__int64 v5; // rbp
void *v6; // rax
void *v7; // r13
unsigned int v8; // er12
unsigned int v10; // eax
const char *v11; // rax
unsigned int v12; // eax
const char *v13; // rax
int v14; // [rsp+4h] [rbp-34h] BYREF
const char *v15; // [rsp+8h] [rbp-30h] BYREF

v4 = strlen(a1);
v14 = get_db(a3, &v15);
v5 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v5, v15, 5LL) )
{
v6 = (void *)tchdbget(v5, a1, v4, &v14);
v7 = v6;
if ( a2 )
{
v8 = 0;
memcpy(a2, v6, v14);
free(v7);
}
else
{
v8 = 2;
v12 = tchdbecode(v5);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "(key=%s) md_get error:%s\n", a1, v13);
}
}
else
{
v8 = 1;
v10 = tchdbecode(v5);
v11 = (const char *)tchdberrmsg(v10);
fprintf(stderr, "tc_get:open %s error -- %s\n", v15, v11);
}
tchdbdel(v5);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, void *a2, int a3)
{
unsigned int v4; // er13
__int64 v5; // rbp
void *v6; // rax
void *v7; // r13
unsigned int v8; // er12
unsigned int v10; // eax
const char *v11; // rax
unsigned int v12; // eax
const char *v13; // rax
int v14; // [rsp+4h] [rbp-34h] BYREF
const char *v15; // [rsp+8h] [rbp-30h] BYREF

v4 = strlen(a1);
v14 = func0(a3, &v15);
v5 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v5, v15, 5LL) )
{
v6 = (void *)tchdbget(v5, a1, v4, &v14);
v7 = v6;
if ( a2 )
{
v8 = 0;
memcpy(a2, v6, v14);
free(v7);
}
else
{
v8 = 2;
v12 = tchdbecode(v5);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "(key=%s) md_get error:%s\n", a1, v13);
}
}
else
{
v8 = 1;
v10 = tchdbecode(v5);
v11 = (const char *)tchdberrmsg(v10);
fprintf(stderr, "tc_get:open %s error -- %s\n", v15, v11);
}
tchdbdel(v5);
return v8;
}

original_code:
static int tc_get(void * key,void * value,tc_t type)
{
 TCHDB *hdb;
 char * db;
 void * v;
 int ecode;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 int rt = 0;
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOREADER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_get:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 v = tchdbget(hdb,key,ksz,&vsz);
 if(!value){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) md_get error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
  goto ret;
 }
 memcpy(value,v,vsz);
 free(v);
ret:
 tchdbdel(hdb);
 return rt;
}

canonical_original_code:
static int tc_get(void *key, void *value, enum tc_t type)
{
 struct TCHDB *hdb;
 char *db;
 void *v;
 int ecode;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 int rt = 0;
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOREADER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_get:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 v = tchdbget(hdb,key,ksz,&vsz);
 if(!value){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) md_get error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
  goto ret;
 }
 memcpy(value,v,vsz);
 free(v);
ret:
 tchdbdel(hdb);
 return rt;
}

variable_types:
key
void *

variable_types:
value
void *

variable_types: struct TCHDB { void *mmtx; void *rmtxs; void *dmtx; void *wmtx; void *eckey; char *rpath; unsigned char type; unsigned char flags; unsigned long bnum; unsigned char apow; unsigned char fpow; unsigned char opts; char *path; int fd; unsigned int omode; unsigned long rnum; unsigned long fsiz; unsigned long frec; unsigned long dfcur; unsigned long iter; char *map; unsigned long msiz; unsigned long xmsiz; unsigned long xfsiz; unsigned int *ba32; unsigned long *ba64; unsigned int align; unsigned int runit; _Bool zmode; int fbpmax; void *fbpool; int fbpnum; int fbpmis; _Bool async; struct TCXSTR { char *ptr; int size; int asize; } *drpool; struct TCXSTR *drpdef; unsigned long drpoff; struct TCMDB { void **mmtxs; void *imtx; struct TCMAP { struct _TCMAPREC { int ksiz; int vsiz; struct _TCMAPREC *left; struct _TCMAPREC *right; struct _TCMAPREC *prev; struct _TCMAPREC *next; } **buckets; struct _TCMAPREC *first; struct _TCMAPREC *last; struct _TCMAPREC *cur; unsigned int bnum; unsigned long rnum; unsigned long msiz; } **maps; int iter; } *recc; unsigned int rcnum; void *(*enc)(void *ptr, int size, int *sp, void *op); void *encop; void *(*dec)(void *ptr, int size, int *sp, void *op); void *decop; int ecode; _Bool fatal; unsigned long inode; long mtime; unsigned int dfunit; unsigned int dfcnt; _Bool tran; int walfd; unsigned long walend; int dbgfd; long cnt_writerec; long cnt_reuserec; long cnt_moverec; long cnt_readrec; long cnt_searchfbp; long cnt_insertfbp; long cnt_splicefbp; long cnt_dividefbp; long cnt_mergefbp; long cnt_reducefbp; long cnt_appenddrp; long cnt_deferdrp; long cnt_flushdrp; long cnt_adjrecc; long cnt_defrag; long cnt_shiftrec; long cnt_trunc; } *

variable_types:
db
char *

variable_types:
v
void *

variable_types: ecode int

variable_types: ksz int

variable_types: vsz int

variable_types: rt int

user_defined_types: struct TCHDB { void *mmtx; void *rmtxs; void *dmtx; void *wmtx; void *eckey; char *rpath; unsigned char type; unsigned char flags; unsigned long bnum; unsigned char apow; unsigned char fpow; unsigned char opts; char *path; int fd; unsigned int omode; unsigned long rnum; unsigned long fsiz; unsigned long frec; unsigned long dfcur; unsigned long iter; char *map; unsigned long msiz; unsigned long xmsiz; unsigned long xfsiz; unsigned int *ba32; unsigned long *ba64; unsigned int align; unsigned int runit; _Bool zmode; int fbpmax; void *fbpool; int fbpnum; int fbpmis; _Bool async; struct TCXSTR *drpool; struct TCXSTR *drpdef; unsigned long drpoff; struct TCMDB *recc; unsigned int rcnum; void *(*enc)(void *ptr, int size, int *sp, void *op); void *encop; void *(*dec)(void *ptr, int size, int *sp, void *op); void *decop; int ecode; _Bool fatal; unsigned long inode; long mtime; unsigned int dfunit; unsigned int dfcnt; _Bool tran; int walfd; unsigned long walend; int dbgfd; long cnt_writerec; long cnt_reuserec; long cnt_moverec; long cnt_readrec; long cnt_searchfbp; long cnt_insertfbp; long cnt_splicefbp; long cnt_dividefbp; long cnt_mergefbp; long cnt_reducefbp; long cnt_appenddrp; long cnt_deferdrp; long cnt_flushdrp; long cnt_adjrecc; long cnt_defrag; long cnt_shiftrec; long cnt_trunc; }

user_defined_types: struct TCMDB { void **mmtxs; void *imtx; struct TCMAP **maps; int iter; }

user_defined_types: struct TCMAP { struct _TCMAPREC **buckets; struct _TCMAPREC *first; struct _TCMAPREC *last; struct _TCMAPREC *cur; unsigned int bnum; unsigned long rnum; unsigned long msiz; }


decompiled_code:
__int64 __fastcall tc_out(const char *a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rbp
unsigned int v4; // er12
unsigned int v6; // eax
const char *v7; // rax
unsigned int v8; // eax
const char *v9; // rax
const char *v10; // [rsp+8h] [rbp-30h] BYREF

v2 = strlen(a1);
get_db(a2, &v10);
v3 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v3, v10, 2LL) )
{
v4 = 0;
if ( !(unsigned __int8)tchdbout(v3, a1, v2) )
{
v4 = 2;
v8 = tchdbecode(v3);
v9 = (const char *)tchdberrmsg(v8);
fprintf(stderr, "(key=%s) tc_out error:%s\n", a1, v9);
}
}
else
{
v4 = 1;
v6 = tchdbecode(v3);
v7 = (const char *)tchdberrmsg(v6);
fprintf(stderr, "tc_out:open %s error -- %s\n", v10, v7);
}
tchdbdel(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rbp
unsigned int v4; // er12
unsigned int v6; // eax
const char *v7; // rax
unsigned int v8; // eax
const char *v9; // rax
const char *v10; // [rsp+8h] [rbp-30h] BYREF

v2 = strlen(a1);
func0(a2, &v10);
v3 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v3, v10, 2LL) )
{
v4 = 0;
if ( !(unsigned __int8)tchdbout(v3, a1, v2) )
{
v4 = 2;
v8 = tchdbecode(v3);
v9 = (const char *)tchdberrmsg(v8);
fprintf(stderr, "(key=%s) tc_out error:%s\n", a1, v9);
}
}
else
{
v4 = 1;
v6 = tchdbecode(v3);
v7 = (const char *)tchdberrmsg(v6);
fprintf(stderr, "tc_out:open %s error -- %s\n", v10, v7);
}
tchdbdel(v3);
return v4;
}

original_code:
static int tc_out(void * key,tc_t type)
{
    TCHDB *hdb;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 char * db;
 get_db(type,&db);
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER))
 {
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_out:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbout(hdb,key,ksz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_out error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

canonical_original_code:
static int tc_out(void *key, enum tc_t type)
{
    struct TCHDB *hdb;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 char *db;
 get_db(type,&db);
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER))
 {
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_out:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbout(hdb,key,ksz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_out error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

user_defined_types: struct TCXSTR { char *ptr; int size; int asize; }

user_defined_types: struct _TCMAPREC { int ksiz; int vsiz; struct _TCMAPREC *left; struct _TCMAPREC *right; struct _TCMAPREC *prev; struct _TCMAPREC *next; }


decompiled_code:
__int64 __fastcall tc_put(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // er12
unsigned int v7; // eax
__int64 v8; // rbp
__int64 v9; // rdx
unsigned int v10; // er12
unsigned int v12; // eax
const char *v13; // rax
unsigned int v14; // eax
const char *v15; // rax
const char *v16; // [rsp+8h] [rbp-30h] BYREF

v6 = strlen(a1);
v7 = get_db(a4, &v16);
if ( a4 != 2 )
a3 = v7;
v8 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v8, v16, 6LL) )
{
v9 = v6;
v10 = 0;
if ( !(unsigned __int8)tchdbput(v8, a1, v9, a2, a3) )
{
v10 = 2;
v14 = tchdbecode(v8);
v15 = (const char *)tchdberrmsg(v14);
fprintf(stderr, "(key=%s) tc_put error:%s\n", a1, v15);
}
}
else
{
v10 = 1;
v12 = tchdbecode(v8);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "tc_put:open %s error -- %s\n", v16, v13);
}
tchdbdel(v8);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // er12
unsigned int v7; // eax
__int64 v8; // rbp
__int64 v9; // rdx
unsigned int v10; // er12
unsigned int v12; // eax
const char *v13; // rax
unsigned int v14; // eax
const char *v15; // rax
const char *v16; // [rsp+8h] [rbp-30h] BYREF

v6 = strlen(a1);
v7 = func0(a4, &v16);
if ( a4 != 2 )
a3 = v7;
v8 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v8, v16, 6LL) )
{
v9 = v6;
v10 = 0;
if ( !(unsigned __int8)tchdbput(v8, a1, v9, a2, a3) )
{
v10 = 2;
v14 = tchdbecode(v8);
v15 = (const char *)tchdberrmsg(v14);
fprintf(stderr, "(key=%s) tc_put error:%s\n", a1, v15);
}
}
else
{
v10 = 1;
v12 = tchdbecode(v8);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "tc_put:open %s error -- %s\n", v16, v13);
}
tchdbdel(v8);
return v10;
}

original_code:
static int tc_put(void * key,void * value,int len,tc_t type)
{
 TCHDB *hdb;
 char *db;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 if(type == IOD){
  vsz = len;
 }
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_put:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbput(hdb,key,ksz,value,vsz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_put error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

canonical_original_code:
static int tc_put(void *key, void *value, int len, enum tc_t type)
{
 struct TCHDB *hdb;
 char *db;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 if(type == IOD){
  vsz = len;
 }
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_put:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbput(hdb,key,ksz,value,vsz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_put error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

variable_types: len int


decompiled_code:
__int64 __fastcall md_get(const char *a1, void *a2)
{
return tc_get(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, void *a2)
{
return func1(a1, a2, 0);
}

original_code:
int md_get(char *path,Meta_Data * md)
{
 return tc_get((void*)path,(void*)md,MD);
}

canonical_original_code:
int md_get(char *path, struct Meta_Data *md)
{
 return tc_get((void *)path,(void *)md,MD);
}

variable_types:
path
char *

variable_types: struct Meta_Data { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } stat_info; struct Replicas { char rep_ip[16]; } replica[5]; struct IO_Queue { int head; int tail; long access_time[50]; } access_time_queue; char dirty; char io_node_head[260]; char io_node_tail[260]; } *

user_defined_types: struct Meta_Data { struct stat stat_info; struct Replicas replica[5]; struct IO_Queue access_time_queue; char dirty; char io_node_head[260]; char io_node_tail[260]; }

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


decompiled_code:
__int64 __fastcall md_out(const char *a1)
{
return tc_out(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
return func2(a1, 0);
}

original_code:
int md_out(char * path)
{
 return tc_out((void*)path,MD);
}

canonical_original_code:
int md_out(char *path)
{
 return tc_out((void *)path,MD);
}


decompiled_code:
__int64 __fastcall md_put(const char *a1, __int64 a2)
{
return tc_put(a1, a2, 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
return func3(a1, a2, 0, 0);
}

original_code:
int md_put(char * path,Meta_Data * meta_data)
{
 return tc_put((void*)path,(void*)meta_data,0,MD);
}

canonical_original_code:
int md_put(char *path, struct Meta_Data *meta_data)
{
 return tc_put((void *)path,(void *)meta_data,0,MD);
}

user_defined_types: struct IO_Queue { int head; int tail; long access_time[50]; }

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


decompiled_code:
__int64 __fastcall ion_get(const char *a1, void *a2)
{
return tc_get(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, void *a2)
{
return func1(a1, a2, 1);
}

original_code:
int ion_get(char *path_time,IO_Node *ion)
{
 return tc_get((void*)path_time,(void*)ion,ION);
}

canonical_original_code:
int ion_get(char *path_time, struct IO_Node *ion)
{
 return tc_get((void *)path_time,(void *)ion,ION);
}

variable_types: struct IO_Node { long modification_time; unsigned long offset; unsigned int length; char pre[260]; char next[260]; } *


decompiled_code:
__int64 __fastcall ion_out(const char *a1)
{
return tc_out(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
return func2(a1, 1);
}

original_code:
int ion_out(char *path_time)
{
 return tc_out((void*)path_time,ION);
}

canonical_original_code:
int ion_out(char *path_time)
{
 return tc_out((void *)path_time,ION);
}


decompiled_code:
__int64 __fastcall ion_put(const char *a1, __int64 a2)
{
return tc_put(a1, a2, 0, 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
return func3(a1, a2, 0, 1);
}

original_code:
int ion_put(char *path_time,IO_Node *io_node)
{
 return tc_put((void*)path_time,(void*)io_node,0,ION);
}

canonical_original_code:
int ion_put(char *path_time, struct IO_Node *io_node)
{
 return tc_put((void *)path_time,(void *)io_node,0,ION);
}

user_defined_types: struct IO_Node { long modification_time; unsigned long offset; unsigned int length; char pre[260]; char next[260]; }


decompiled_code:
__int64 __fastcall iod_get(const char *a1, void *a2)
{
return tc_get(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, void *a2)
{
return func1(a1, a2, 2);
}

original_code:
int iod_get(char *path_time,void *iod)
{
 return tc_get((void*)path_time,iod,IOD);
}

canonical_original_code:
int iod_get(char *path_time, void *iod)
{
 return tc_get((void *)path_time,iod,IOD);
}

variable_types:
iod
void *


decompiled_code:
__int64 __fastcall iod_out(const char *a1)
{
return tc_out(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
return func2(a1, 2);
}

original_code:
int iod_out(char *path_time)
{
 return tc_out((void*)path_time,IOD);
}

canonical_original_code:
int iod_out(char *path_time)
{
 return tc_out((void *)path_time,IOD);
}


decompiled_code:
__int64 __fastcall iod_put(const char *a1, __int64 a2, unsigned int a3)
{
return tc_put(a1, a2, a3, 2);
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, __int64 a2, unsigned int a3)
{
return func3(a1, a2, a3, 2);
}

original_code:
int iod_put(char *path_time,void *iod,int len)
{
 return tc_put((void*)path_time,iod,len,IOD);
}

canonical_original_code:
int iod_put(char *path_time, void *iod, int len)
{
 return tc_put((void *)path_time,iod,len,IOD);
}


original_code:
static int init_file(char* path)
{
 int rt = 0;
 char data_path[260];
 struct stat my_stat;
 Meta_Data md;
 bzero(&md,sizeof(Meta_Data));
 get_data_path(path,data_path);
 if(stat(data_path,&my_stat) != 0){
  perror("stat");
  rt = 1;
  goto ret;
 }
 memcpy((void*)&(md.stat_info),(void*)&my_stat,sizeof(struct stat));
 md.access_time_queue.head = 0;
 md.access_time_queue.tail = 0;
 md.dirty = 00;
 bzero(md.io_node_head,260);
 bzero(md.io_node_tail,260);
 if(md_put(path,&md) != 0){
  fprintf(stderr,"init file : md_put fail!\n");
  rt = 2;
 }
ret:
 return rt;
}

canonical_original_code:
static int init_file(char *path)
{
 int rt = 0;
 char data_path[260];
 struct stat my_stat;
 struct Meta_Data md;
 bzero(&md,sizeof(Meta_Data));
 get_data_path(path,data_path);
 if(stat(data_path,&my_stat) != 0){
  perror("stat");
  rt = 1;
  goto ret;
 }
 memcpy((void *)&(md.stat_info),(void *)&my_stat,sizeof(struct stat));
 md.access_time_queue.head = 0;
 md.access_time_queue.tail = 0;
 md.dirty = 00;
 bzero(md.io_node_head,260);
 bzero(md.io_node_tail,260);
 if(md_put(path,&md) != 0){
  fprintf(stderr,"init file : md_put fail!\n");
  rt = 2;
 }
ret:
 return rt;
}

variable_types: struct Meta_Data { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } stat_info; struct Replicas { char rep_ip[16]; } replica[5]; struct IO_Queue { int head; int tail; long access_time[50]; } access_time_queue; char dirty; char io_node_head[260]; char io_node_tail[260]; }


decompiled_code:
__int64 __fastcall de_init_file(__int64 a1)
{
unsigned int v1; // er12
size_t v3; // rbx
size_t v4; // rbx
char v5[272]; // [rsp+0h] [rbp-7D8h] BYREF
char v6[280]; // [rsp+110h] [rbp-6C8h] BYREF
char src[264]; // [rsp+228h] [rbp-5B0h] BYREF
char v8[633]; // [rsp+330h] [rbp-4A8h] BYREF
char s[559]; // [rsp+5A9h] [rbp-22Fh] BYREF

v1 = 1;
if ( !(unsigned int)md_get(a1, v8) )
{
v1 = 0;
if ( v8[632] )
{
v3 = strlen(s);
strncpy(v5, s, v3);
if ( v3 )
{
do
{
ion_get(v5, v6);
ion_out(v5);
iod_out(v5);
v4 = strlen(src);
strncpy(v5, src, v4);
}
while ( (_DWORD)v4 );
}
}
md_out(a1);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er12
size_t v3; // rbx
size_t v4; // rbx
char v5[272]; // [rsp+0h] [rbp-7D8h] BYREF
char v6[280]; // [rsp+110h] [rbp-6C8h] BYREF
char src[264]; // [rsp+228h] [rbp-5B0h] BYREF
char v8[633]; // [rsp+330h] [rbp-4A8h] BYREF
char s[559]; // [rsp+5A9h] [rbp-22Fh] BYREF

v1 = 1;
if ( !(unsigned int)md_get(a1, v8) )
{
v1 = 0;
if ( v8[632] )
{
v3 = strlen(s);
strncpy(v5, s, v3);
if ( v3 )
{
do
{
ion_get(v5, v6);
ion_out(v5);
iod_out(v5);
v4 = strlen(src);
strncpy(v5, src, v4);
}
while ( (_DWORD)v4 );
}
}
md_out(a1);
}
return v1;
}

original_code:
static int de_init_file(char *path)
{
 int rt = 0;
 int len;
 char ionp[260];
 Meta_Data md;
 IO_Node ion;
 if(md_get(path,&md) != 0){
  rt = 1;
  goto ret;
 }
 if(md.dirty == 00){
  goto del_md;
 }
 len = strlen(md.io_node_head);
 strncpy(ionp,md.io_node_head,len);
 while(len != 0){
  ion_get(ionp,&ion);
  ion_out(ionp);
  iod_out(ionp);
  len = strlen(ion.next);
  strncpy(ionp,ion.next,len);
 }
del_md:
 md_out(path);
ret:
 return rt;
}

canonical_original_code:
static int de_init_file(char *path)
{
 int rt = 0;
 int len;
 char ionp[260];
 struct Meta_Data md;
 struct IO_Node ion;
 if(md_get(path,&md) != 0){
  rt = 1;
  goto ret;
 }
 if(md.dirty == 00){
  goto del_md;
 }
 len = strlen(md.io_node_head);
 strncpy(ionp,md.io_node_head,len);
 while(len != 0){
  ion_get(ionp,&ion);
  ion_out(ionp);
  iod_out(ionp);
  len = strlen(ion.next);
  strncpy(ionp,ion.next,len);
 }
del_md:
 md_out(path);
ret:
 return rt;
}

variable_types:
ionp
char [260]

variable_types: struct IO_Node { long modification_time; unsigned long offset; unsigned int length; char pre[260]; char next[260]; }


decompiled_code:
__int64 __fastcall que_out(void *buf)
{
int v1; // edx
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
__int64 result; // rax
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v6[0] = 0LL;
v6[0].sa_family = 2;
inet_pton(2, "127.0.0.1", &v6[0].sa_data[2]);
*(_WORD *)v6[0].sa_data = _bswap_16_constprop_0(2LL, 1LL, 0LL);
v2 = socket(2, 1, v1);
if ( v2 == -1 )
{
perror("Socket");
result = 1LL;
}
else
{
v3 = v2;
if ( connect(v2, v6, 0x10u) == -1 )
{
v4 = 2;
perror("Connection");
}
else
{
v4 = 0;
if ( write(v3, buf, 0x228uLL) != 552 )
{
v4 = 3;
perror("write socket");
}
}
close(v3);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *buf)
{
int v1; // edx
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
__int64 result; // rax
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v6[0] = 0LL;
v6[0].sa_family = 2;
inet_pton(2, "127.0.0.1", &v6[0].sa_data[2]);
*(_WORD *)v6[0].sa_data = func2(2LL, 1LL, 0LL);
v2 = socket(2, 1, v1);
if ( v2 == -1 )
{
perror("Socket");
result = 1LL;
}
else
{
v3 = v2;
if ( connect(v2, v6, 0x10u) == -1 )
{
v4 = 2;
perror("Connection");
}
else
{
v4 = 0;
if ( write(v3, buf, 0x228uLL) != 552 )
{
v4 = 3;
perror("write socket");
}
}
close(v3);
result = v4;
}
return result;
}

original_code:
static int que_out(const q_out_req *req)
{
 int rt = 0,cskt,c_len;
 struct sockaddr_in addr;
 bzero(&addr,sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void *)&addr.sin_addr);
 addr.sin_port = htons(9374);
 c_len = sizeof(addr);
 if((cskt = socket(2,SOCK_STREAM,0)) == -1){
  perror("Socket");
  rt = 1;
  goto ret;
 }
 if(connect(cskt,(struct sockaddr*)&addr,c_len) == -1){
  perror("Connection");
  rt = 2;
  goto over;
 }
 if(write(cskt,req,sizeof(q_out_req)) != sizeof(q_out_req)){
  perror("write socket");
  rt = 3;
 }
over:
 close(cskt);
ret:
 return rt;
}

canonical_original_code:
static int que_out(struct q_out_req *req)
{
 int rt = 0; int cskt; int c_len;
 struct sockaddr_in addr;
 bzero(&addr,sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void *)&addr.sin_addr);
 addr.sin_port = htons(9374);
 c_len = sizeof(addr);
 if((cskt = socket(2,SOCK_STREAM,0)) == -1){
  perror("Socket");
  rt = 1;
  goto ret;
 }
 if(connect(cskt,(struct sockaddr *)&addr,c_len) == -1){
  perror("Connection");
  rt = 2;
  goto over;
 }
 if(write(cskt,req,sizeof(q_out_req)) != sizeof(q_out_req)){
  perror("write socket");
  rt = 3;
 }
over:
 close(cskt);
ret:
 return rt;
}

variable_types: struct q_out_req { char path[260]; char ion_key[260]; long m_atime; int io_type; unsigned long offset; unsigned int length; } *

variable_types: cskt int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
void __fastcall rand_generator(__int64 a1, int a2, int a3)
{
__int64 i; // rbx
int v5; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(_DWORD *)(a1 + 4 * i++) = rand() % a3 )
{
v5 = time(0LL);
srand(v5 + i);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, int a3)
{
__int64 i; // rbx
int v5; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(_DWORD *)(a1 + 4 * i++) = rand() % a3 )
{
v5 = time(0LL);
srand(v5 + i);
}
}
}

original_code:
void rand_generator(int a[],int len,int limit)
{
 int i;
 for(i = 0;i < len;i++){
  srand(time(((void *)0)) + i);
  a[i] = rand()%limit;
 }
 return;
}

canonical_original_code:
void rand_generator(int a[], int len, int limit)
{
 int i;
 for(i = 0;i < len;i++){
  srand(time(((void *)0)) + i);
  a[i] = rand()%limit;
 }
 return;
}

variable_types:
a
int []

variable_types: limit int

variable_types: i int


decompiled_code:
__int64 __fastcall get_cache_path(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/cache/");
strcpy((char *)(a2 + 11), src);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/cache/");
strcpy((char *)(a2 + 11), src);
return 1LL;
}

original_code:
int get_cache_path(char* path,char* cache_path)
{
    char *p;
 bzero(cache_path,260);
    p = cache_path + strlen("/mnt/cache/");
    strcpy(cache_path,"/mnt/cache/");
    strcpy(p,path);
    return 1;
}

canonical_original_code:
int get_cache_path(char *path, char *cache_path)
{
    char *p;
 bzero(cache_path,260);
    p = cache_path + strlen("/mnt/cache/");
    strcpy(cache_path,"/mnt/cache/");
    strcpy(p,path);
    return 1;
}

variable_types:
p
char *


original_code:
int get_data_path(char* path,char* data_path)
{
    char *p;
 bzero(data_path,260);
    p = data_path + strlen("/mnt/data_center/");
    strcpy(data_path,"/mnt/data_center/");
    strcpy(p,path);
    return 1;
}

canonical_original_code:
int get_data_path(char *path, char *data_path)
{
    char *p;
 bzero(data_path,260);
    p = data_path + strlen("/mnt/data_center/");
    strcpy(data_path,"/mnt/data_center/");
    strcpy(p,path);
    return 1;
}


decompiled_code:
ssize_t __fastcall get_path_from_fd(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax
char v4[1064]; // [rsp+0h] [rbp-428h] BYREF

memset(v4, 0, 0x400uLL);
v2 = getpid();
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
snprintf(v4, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(v4, (char *)a2, 0x104uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func3(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax
char v4[1064]; // [rsp+0h] [rbp-428h] BYREF

memset(v4, 0, 0x400uLL);
v2 = getpid();
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
snprintf(v4, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(v4, (char *)a2, 0x104uLL);
}

original_code:
int get_path_from_fd(int fd, char* path)
{
    char buf[1024];
 pid_t pid;
    bzero(buf, 1024);
    pid = getpid();
 bzero(path,260);
    snprintf(buf, 1024, "/proc/%i/fd/%i", pid, fd);
    return readlink(buf, path, 260);
}

canonical_original_code:
int get_path_from_fd(int fd, char *path)
{
    char buf[1024];
 int pid;
    bzero(buf, 1024);
    pid = getpid();
 bzero(path,260);
    snprintf(buf, 1024, "/proc/%i/fd/%i", pid, fd);
    return readlink(buf, path, 260);
}

variable_types: fd int

variable_types:
buf
char [1024]

variable_types: pid int


printMove

repo: jpalardy/routine

decompiled_code:
int __fastcall printMove(unsigned int a1, unsigned int a2)
{
return printf("%d -> %d\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1, unsigned int a2)
{
return printf("%d -> %d\n", a1, a2);
}

original_code:
static void printMove(int src, int dst) {
  printf("%d -> %d\n", src, dst);
}

variable_types: src int

variable_types: dst int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax

v3 = 1;
if ( argc > 1 )
{
v4 = atoi(argv[1]);
if ( v4 > 0 )
{
v3 = 0;
hanoi_constprop_0((unsigned int)v4, 1LL, 3LL, 2LL);
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax

v3 = 1;
if ( argc > 1 )
{
v4 = atoi(argv[1]);
if ( v4 > 0 )
{
v3 = 0;
func8((unsigned int)v4, 1LL, 3LL, 2LL);
}
}
return v3;
}

original_code:
int main(int argc, char* argv[]) {
  int rings;
  if (argc < 2) {
    return 1;
  }
  rings = atoi(argv[1]);
  if (rings < 1) {
    return 1;
  }
  hanoi(rings, 1, 3, 2, &printMove);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int rings;
  if (argc < 2) {
    return 1;
  }
  rings = atoi(argv[1]);
  if (rings < 1) {
    return 1;
  }
  hanoi(rings, 1, 3, 2, &printMove);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: rings int


printTask

decompiled_code:
int __fastcall printTask(const char *a1, char a2)
{
int result; // eax

if ( a2 )
result = printf("[ ] %s\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, char a2)
{
int result; // eax

if ( a2 )
result = printf("[ ] %s\n", a1);
return result;
}

original_code:
static void printTask(char* task, _Bool cond) {
  if (!cond) { return; }
  printf("[ ] %s\n", task);
}

canonical_original_code:
static void printTask(char *task, _Bool cond) {
  if (!cond) { return; }
  printf("[ ] %s\n", task);
}

variable_types:
task
char *


printHeader

decompiled_code:
int __fastcall printHeader(struct tm *tp)
{
char s[19]; // [rsp+5h] [rbp-13h] BYREF

puts("-------------------------------------------------");
if ( !strftime(s, 0xBuLL, "%F", tp) )
__assert_fail("strftime(n, 11, \"%F\", tm_day)", "pt.c", 0x14u, "printHeader");
return printf("%s\n\n", s);
}

original_code:
static void printHeader(struct tm* tm_day) {
  char n[11];
  printf("-------------------------------------------------\n");
  ((void) sizeof ((strftime(n, 11, "%F", tm_day)) ? 1 : 0), __extension__ ({ if (strftime(n, 11, "%F", tm_day)) ; else __assert_fail ("strftime(n, 11, \"%F\", tm_day)", "pt.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  printf("%s\n\n", n);
}

canonical_original_code:
static void printHeader(struct tm *tm_day) {
  char n[11];
  printf("-------------------------------------------------\n");
  ((void) sizeof ((strftime(n, 11, "%F", tm_day)) ? 1 : 0), __extension__ ({ if (strftime(n, 11, "%F", tm_day)) ; else __assert_fail ("strftime(n, 11, \"%F\", tm_day)", "pt.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  printf("%s\n\n", n);
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
n
char [11]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct tm *v3; // rbx
unsigned int v4; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v3 = localtime(&timer);
printHeader(v3);
v4 = dateCondFor_isra_0((unsigned int)v3->tm_wday, argv);
generateTasks_constprop_0(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct tm *v3; // rbx
unsigned int v4; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v3 = localtime(&timer);
func8(v3);
v4 = func10((unsigned int)v3->tm_wday, argv);
func9(v4);
return 0;
}

original_code:
int main() {
  time_t now = time(((void *)0));
  struct tm *tm_now = localtime(&now);
  printHeader(tm_now);
  struct dateCond dc = dateCondFor(tm_now);
  generateTasks(dc, &printTask);
  return 0;
}

canonical_original_code:
int main() {
  long now = time(((void *)0));
  struct tm *tm_now = localtime(&now);
  printHeader(tm_now);
  struct dateCond dc = dateCondFor(tm_now);
  generateTasks(dc, &printTask);
  return 0;
}

variable_types: now long

variable_types: struct dateCond { _Bool weekday; _Bool sunday; }

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


flushcache

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

v2 = a2;
v3 = malloc(0x10000000uLL);
if ( !v3 )
{
perror("malloc");
exit(-1);
}
v4 = v3;
if ( a1 > 0 )
{
do
{
v5 = open64(*v2, 0);
if ( v5 == -1 )
{
perror("open");
exit(-1);
}
do
{
while ( 1 )
{
v6 = read(v5, v4, 0x10000000uLL);
if ( v6 != -1 )
break;
if ( *__errno_location() == 5 )
fwrite("I/O error\n", 1uLL, 0xAuLL, stderr);
else
perror("read");
*v4 = v4[1] + v4[2];
}
*v4 = v4[1] + v4[2];
}
while ( v6 );
if ( close(v5) )
{
perror("close");
exit(-1);
}
++v2;
}
while ( &a2[(unsigned int)(a1 - 1) + 1] != v2 );
}
free(v4);
}

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

v2 = a2;
v3 = malloc(0x10000000uLL);
if ( !v3 )
{
perror("malloc");
exit(-1);
}
v4 = v3;
if ( a1 > 0 )
{
do
{
v5 = open64(*v2, 0);
if ( v5 == -1 )
{
perror("open");
exit(-1);
}
do
{
while ( 1 )
{
v6 = read(v5, v4, 0x10000000uLL);
if ( v6 != -1 )
break;
if ( *__errno_location() == 5 )
fwrite("I/O error\n", 1uLL, 0xAuLL, stderr);
else
perror("read");
*v4 = v4[1] + v4[2];
}
*v4 = v4[1] + v4[2];
}
while ( v6 );
if ( close(v5) )
{
perror("close");
exit(-1);
}
++v2;
}
while ( &a2[(unsigned int)(a1 - 1) + 1] != v2 );
}
free(v4);
}

original_code:
void flushcache(int num_files, char **filenames) {
  char *buffer;
  int fildes;
  int i;
  buffer = malloc((1<<28));
  if (buffer == ((void *)0)) { perror("malloc"); exit(-1); };
  for (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<<28));
        if (read_size == -1) {
            if ((*__errno_location ()) == 5)
                fprintf(stderr, "I/O error\n");
            else
                perror("read");
        }
        buffer[0] = buffer[1] + buffer[2];
        if (read_size == 0) break;
      }
      if (close(fildes)) { perror("close"); exit(-1); };
  }
  free(buffer);
}

canonical_original_code:
void flushcache(int num_files, char **filenames) {
  char *buffer;
  int fildes;
  int i;
  buffer = malloc((1<<28));
  if (buffer == ((void *)0)) { perror("malloc"); exit(-1); };
  for (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<<28));
        if (read_size == -1) {
            if ((*__errno_location ()) == 5)
                fprintf(stderr, "I/O error\n");
            else
                perror("read");
        }
        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


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


getticks

decompiled_code:
unsigned __int64 getticks()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func9()
{
return __rdtsc();
}

original_code:
static __inline__ ticks getticks(void)
{
     unsigned a, d;
     asm volatile("rdtsc" : "=a" (a), "=d" (d));
     return ((ticks)a) | (((ticks)d) << 32);
}

canonical_original_code:
static __inline__ unsigned long long getticks()
{
     unsigned int a; unsigned int d;
     asm volatile("rdtsc" : "=a" (a), "=d" (d));
     return ((unsigned long long)a) | (((unsigned long long)d) << 32);
}

variable_types:
a
unsigned int

variable_types:
d
unsigned int

return_type: unsigned long long


elapsed

decompiled_code:
double __fastcall elapsed(__int64 a1, __int64 a2)
{
double v2; // xmm0_8

if ( a1 < 0 )
{
v2 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
if ( a2 >= 0 )
return v2 - (double)(int)a2;
}
else
{
v2 = (double)(int)a1;
if ( a2 >= 0 )
return v2 - (double)(int)a2;
}
return v2
- ((double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1))
+ (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)));
}

canonical_decompiled_code:
double __fastcall func10(__int64 a1, __int64 a2)
{
double v2; // xmm0_8

if ( a1 < 0 )
{
v2 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
if ( a2 >= 0 )
return v2 - (double)(int)a2;
}
else
{
v2 = (double)(int)a1;
if ( a2 >= 0 )
return v2 - (double)(int)a2;
}
return v2
- ((double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1))
+ (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)));
}

original_code: static __inline__ double elapsed(ticks t1, ticks t0) { return (double)t1 - (double)t0; }

canonical_original_code: static __inline__ double elapsed(unsigned long long t1, unsigned long long t0) { return (double)t1 - (double)t0; }

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // r14
size_t v5; // rbx
unsigned __int64 v6; // rbp
void *v7; // rax
size_t v8; // rdx
void *v9; // r15
time_t v10; // rax

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // r14
size_t v5; // rbx
unsigned __int64 v6; // rbp
void *v7; // rax
size_t v8; // rdx
void *v9; // r15
time_t v10; // rax

v3 = fopen64(argv[1], "r");
if ( !v3 )
{
perror("file could not be opened for reading\n");
exit(1);
}
v4 = v3;
v5 = 16LL;
v6 = 0x8000000LL;
do
{
func7((unsigned int)(argc - 2), argv + 2);
v7 = malloc(v5);
v8 = v5;
v9 = v7;
v5 += 16LL;
v6 >>= 4;
func12(v4, v7, v8);
free(v9);
v10 = time(0LL);
srand(v10 % 0x7FFFFFFF);
}
while ( v5 != 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)
{
const char **v2; // rbx
_BYTE *v3; // rax
_BYTE *v4; // rbp
__int64 v5; // r13
int v6; // er12
ssize_t v7; // rax
const char *v8; // rdi

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

canonical_decompiled_code:
void __fastcall func7(int a1, const char **a2)
{
const char **v2; // rbx
_BYTE *v3; // rax
_BYTE *v4; // rbp
__int64 v5; // r13
int v6; // er12
ssize_t v7; // rax
const char *v8; // rdi

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

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: i int


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


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)
{
if ( !*(_BYTE *)a1 )
{
while ( 1 )
;
}
fwrite("busy loop exiting...\n", 1uLL, 0x15uLL, stderr);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(void *a1)
{
if ( !*(_BYTE *)a1 )
{
while ( 1 )
;
}
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 *


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);
}


decompiled_code:
int __fastcall run_rdtsc_trials(FILE *a1, __int64 a2, __int64 a3)
{
int v3; // er13
const char *v4; // r12
__int64 v5; // rbp
unsigned int i; // ebx
unsigned int v7; // er14
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rsi
int result; // eax
__int64 v12; // r15
__int64 v13; // rdx
__int64 v14; // rax

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

canonical_decompiled_code:
int __fastcall func14(FILE *a1, __int64 a2, __int64 a3)
{
int v3; // er13
const char *v4; // r12
__int64 v5; // rbp
unsigned int i; // ebx
unsigned int v7; // er14
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rsi
int result; // eax
__int64 v12; // r15
__int64 v13; // rdx
__int64 v14; // rax

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

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

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

result = *(int *)(a1 + 8000);
*(_DWORD *)(a1 + 8000) = result + 1;
*(_QWORD *)(a1 + 8 * 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


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)
{
float v2; // xmm4_4
__m128i v3; // xmm4

age_particles((__int64 *)a1, a2);
*(float *)v3.m128i_i32 = v2 * *(float *)(a1 + 24);
return emit_particles(a1, v3);
}

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; // er12
void (*v5)(__int64, const char *, ...); // r10
const char *v6; // r9
__int64 v7; // r8

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

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

if ( !a1 )
{
v3 = 14;
v6 = "[EFAULT] Precondition failed (event != NULL)";
v7 = 185LL;
MIDIErrorNumber = 14;
v5 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
goto LABEL_7;
return v3;
}
if ( !a3 )
{
v3 = 22;
v6 = "[EINVAL] Precondition failed (buffer != NULL)";
v7 = 186LL;
MIDIErrorNumber = 22;
v5 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
goto LABEL_7;
return v3;
}
v3 = 1;
if ( *(_QWORD *)(a1 + 16) + 8LL <= a2 )
return v3;
v3 = 12;
MIDIErrorNumber = 12;
v5 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( !MIDILogger )
return v3;
v6 = "[ENOMEM] Precondition failed (size >= required)";
v7 = 188LL;
LABEL_7:
v5(16LL, "%s/%s:%i: %s\n", "midi", "event.c", v7, v6);
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)
{
unsigned int v3; // er12
void (*v5)(__int64, const char *, ...); // r10
const char *v6; // r9
__int64 v7; // r8

if ( !a1 )
{
v3 = 14;
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 205LL, "[EFAULT] Precondition failed (event != NULL)");
return v3;
}
if ( !a3 )
{
v6 = "[EINVAL] Precondition failed (buffer != NULL)";
v7 = 206LL;
MIDIErrorNumber = 22;
v5 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( !MIDILogger )
return 22LL;
goto LABEL_7;
}
v3 = 1;
if ( a2 > 4 )
return v3;
MIDIErrorNumber = 22;
v5 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v6 = "[EINVAL] Precondition failed (size >= required)";
v7 = 208LL;
LABEL_7:
v5(16LL, "%s/%s:%i: %s\n", "midi", "event.c", v7, v6);
}
return 22LL;
}

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

if ( !a1 )
{
v3 = 14;
MIDIErrorNumber = 14;
if ( MIDILogger )
MIDILogger(16LL, "%s/%s:%i: %s\n", "midi", "event.c", 205LL, "[EFAULT] Precondition failed (event != NULL)");
return v3;
}
if ( !a3 )
{
v6 = "[EINVAL] Precondition failed (buffer != NULL)";
v7 = 206LL;
MIDIErrorNumber = 22;
v5 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( !MIDILogger )
return 22LL;
goto LABEL_7;
}
v3 = 1;
if ( a2 > 4 )
return v3;
MIDIErrorNumber = 22;
v5 = (void (*)(__int64, const char *, ...))MIDILogger;
if ( MIDILogger )
{
v6 = "[EINVAL] Precondition failed (size >= required)";
v7 = 208LL;
LABEL_7:
v5(16LL, "%s/%s:%i: %s\n", "midi", "event.c", v7, v6);
}
return 22LL;
}

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
void *v10; // rdi
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.");
v10 = v5;
v5 = 0LL;
free(v10);
}
}
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
void *v10; // rdi
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.");
v10 = v5;
v5 = 0LL;
free(v10);
}
}
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(16LL, "%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(16LL, "%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)
{
unsigned int v2; // er12
const char *v4; // r9
__int64 v5; // r8
void (*v6)(__int64, const char *, ...); // r10

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

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

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

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)
{
unsigned int v2; // er12
const char *v4; // r9
__int64 v5; // r8
void (*v6)(__int64, const char *, ...); // r10

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

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

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

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 func8(_QWORD *a1)
{
*a1 = func7();
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 func9(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 func10(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 = func6(a1);
}
}
else
{
midi_global_clock = func6(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; } *