decompiled_code:
__int64 __fastcall pack_szb_image(int fd, void *buf, const char **a3, const char *a4)
{
const void **v4; // r15
const char **v5; // r14
int v6; // ebx
const char *v7; // rax
const char *v8; // rdx
int v9; // eax
const char *v10; // rdx
const char *v11; // rdx
int v12; // er9
const char *v13; // rax
int v14; // ebx
const char *v16; // rdx
int v17; // eax
const char *v18; // r9
const char *v19; // rdx
int v20; // eax
const char *v21; // r9
const char *v22; // rdx
int v23; // eax
const char *v24; // r9
const char *v25; // rdx
int v26; // eax
const char *v27; // r9
const char *v28; // rdx
int v29; // eax
const char *v30; // r9
const char *v31; // rdx
int v32; // eax
const char *v33; // r9
const char *v34; // [rsp+0h] [rbp-48h]
const char *v35; // [rsp+0h] [rbp-48h]
const char *v36; // [rsp+0h] [rbp-48h]
const char *v37; // [rsp+0h] [rbp-48h]
const char *v38; // [rsp+0h] [rbp-48h]
const char *v39; // [rsp+0h] [rbp-48h]
const char *v40; // [rsp+0h] [rbp-48h]
const char *v41; // [rsp+0h] [rbp-48h]

v4 = (const void **)a3;
if ( a3[1] )
{
v5 = a3;
v6 = 0x2000;
do
{
while ( 1 )
{
v7 = *v5;
if ( *((_QWORD *)*v5 + 8) != 0x64616F6C746F6F62LL || *((_WORD *)*v5 + 36) != 29285 )
break;
puts("start pack uboot.bin......");
v8 = *v5;
*((_DWORD *)v8 + 26) = v6;
v34 = v8;
v9 = get_file_size(v8);
v10 = v34;
v35 = *v5;
*((_DWORD *)v10 + 27) = v9;
v11 = "uboot.bin";
LABEL_16:
*((_DWORD *)v35 + 24) = get_crc_checksum(fd, v5, v11);
v12 = get_system_time();
v13 = *v5;
v5 = (const char **)v5[1];
*((_DWORD *)v13 + 25) = v12;
v6 += (*((_DWORD *)v13 + 27) & 0xFFFFFFF0) + 80;
if ( !v5[1] )
goto LABEL_17;
}
if ( *((_DWORD *)v7 + 16) == 1953460066 )
{
puts("start pack boot.img......");
v19 = *v5;
*((_DWORD *)v19 + 26) = v6;
v37 = v19;
v20 = get_file_size(v19);
v21 = *v5;
*((_DWORD *)v37 + 27) = v20;
v11 = "boot.img";
v35 = v21;
goto LABEL_16;
}
if ( *((_QWORD *)v7 + 8) == 0x797265766F636572LL )
{
puts("start pack recovery.img......");
v22 = *v5;
*((_DWORD *)v22 + 26) = v6;
v38 = v22;
v23 = get_file_size(v22);
v24 = *v5;
*((_DWORD *)v38 + 27) = v23;
v11 = "recovery.img";
v35 = v24;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1953724787 && *((_WORD *)*v5 + 34) == 28005 )
{
puts("start pack system.img");
v16 = *v5;
*((_DWORD *)v16 + 26) = v6;
v36 = v16;
v17 = get_file_size(v16);
v18 = *v5;
*((_DWORD *)v36 + 27) = v17;
v11 = "system.img";
v35 = v18;
goto LABEL_16;
}
if ( *((_QWORD *)v7 + 8) == 0x6174616472657375LL )
{
puts("start pack userdata.img");
v31 = *v5;
*((_DWORD *)v31 + 26) = v6;
v41 = v31;
v32 = get_file_size(v31);
v33 = *v5;
*((_DWORD *)v41 + 27) = v32;
v11 = "userdata.img";
v35 = v33;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1835626595 && *((_WORD *)*v5 + 34) == 26465 && (*v5)[70] == 101 )
{
puts("start pack cpimage.img ......");
v25 = *v5;
*((_DWORD *)v25 + 26) = v6;
v39 = v25;
v26 = get_file_size(v25);
v27 = *v5;
*((_DWORD *)v39 + 27) = v26;
v11 = "cpimage.img";
v35 = v27;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1818587760 && *((_WORD *)*v5 + 34) == 24943 && (*v5)[70] == 100 )
{
puts("start pack preload.img......");
v28 = *v5;
*((_DWORD *)v28 + 26) = v6;
v40 = v28;
v29 = get_file_size(v28);
v30 = *v5;
*((_DWORD *)v40 + 27) = v29;
v11 = "preload.img";
v35 = v30;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1751343459 && (*v5)[68] == 101 )
{
puts("start pack cache.img...... ");
v5 = (const char **)v5[1];
}
else if ( !memcmp(*v5 + 64, "fat", 5uLL) )
{
puts("start pack fat.img...... ");
v5 = (const char **)v5[1];
}
}
while ( v5[1] );
}
LABEL_17:
*((_DWORD *)buf + 20) = get_system_time();
*((_DWORD *)buf + 3) = get_file_size(a4);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
LABEL_36:
puts("pack header is Error!");
exit(1);
}
v14 = 0;
if ( *((_DWORD *)buf + 21) )
{
while ( write(fd, *v4, 0x100uLL) >= 0 )
{
v4 = (const void **)v4[1];
if ( *((_DWORD *)buf + 21) <= (unsigned int)++v14 )
goto LABEL_21;
}
goto LABEL_36;
}
LABEL_21:
*((_DWORD *)buf + 2) = header_crc_checksum(fd, 12LL, 2045);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
puts("pack header crc is Error!");
exit(1);
}
close(fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, const char **a3, const char *a4)
{
const void **v4; // r15
const char **v5; // r14
int v6; // ebx
const char *v7; // rax
const char *v8; // rdx
int v9; // eax
const char *v10; // rdx
const char *v11; // rdx
int v12; // er9
const char *v13; // rax
int v14; // ebx
const char *v16; // rdx
int v17; // eax
const char *v18; // r9
const char *v19; // rdx
int v20; // eax
const char *v21; // r9
const char *v22; // rdx
int v23; // eax
const char *v24; // r9
const char *v25; // rdx
int v26; // eax
const char *v27; // r9
const char *v28; // rdx
int v29; // eax
const char *v30; // r9
const char *v31; // rdx
int v32; // eax
const char *v33; // r9
const char *v34; // [rsp+0h] [rbp-48h]
const char *v35; // [rsp+0h] [rbp-48h]
const char *v36; // [rsp+0h] [rbp-48h]
const char *v37; // [rsp+0h] [rbp-48h]
const char *v38; // [rsp+0h] [rbp-48h]
const char *v39; // [rsp+0h] [rbp-48h]
const char *v40; // [rsp+0h] [rbp-48h]
const char *v41; // [rsp+0h] [rbp-48h]

v4 = (const void **)a3;
if ( a3[1] )
{
v5 = a3;
v6 = 0x2000;
do
{
while ( 1 )
{
v7 = *v5;
if ( *((_QWORD *)*v5 + 8) != 0x64616F6C746F6F62LL || *((_WORD *)*v5 + 36) != 29285 )
break;
puts("start pack uboot.bin......");
v8 = *v5;
*((_DWORD *)v8 + 26) = v6;
v34 = v8;
v9 = func1(v8);
v10 = v34;
v35 = *v5;
*((_DWORD *)v10 + 27) = v9;
v11 = "uboot.bin";
LABEL_16:
*((_DWORD *)v35 + 24) = func3(fd, v5, v11);
v12 = func2();
v13 = *v5;
v5 = (const char **)v5[1];
*((_DWORD *)v13 + 25) = v12;
v6 += (*((_DWORD *)v13 + 27) & 0xFFFFFFF0) + 80;
if ( !v5[1] )
goto LABEL_17;
}
if ( *((_DWORD *)v7 + 16) == 1953460066 )
{
puts("start pack boot.img......");
v19 = *v5;
*((_DWORD *)v19 + 26) = v6;
v37 = v19;
v20 = func1(v19);
v21 = *v5;
*((_DWORD *)v37 + 27) = v20;
v11 = "boot.img";
v35 = v21;
goto LABEL_16;
}
if ( *((_QWORD *)v7 + 8) == 0x797265766F636572LL )
{
puts("start pack recovery.img......");
v22 = *v5;
*((_DWORD *)v22 + 26) = v6;
v38 = v22;
v23 = func1(v22);
v24 = *v5;
*((_DWORD *)v38 + 27) = v23;
v11 = "recovery.img";
v35 = v24;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1953724787 && *((_WORD *)*v5 + 34) == 28005 )
{
puts("start pack system.img");
v16 = *v5;
*((_DWORD *)v16 + 26) = v6;
v36 = v16;
v17 = func1(v16);
v18 = *v5;
*((_DWORD *)v36 + 27) = v17;
v11 = "system.img";
v35 = v18;
goto LABEL_16;
}
if ( *((_QWORD *)v7 + 8) == 0x6174616472657375LL )
{
puts("start pack userdata.img");
v31 = *v5;
*((_DWORD *)v31 + 26) = v6;
v41 = v31;
v32 = func1(v31);
v33 = *v5;
*((_DWORD *)v41 + 27) = v32;
v11 = "userdata.img";
v35 = v33;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1835626595 && *((_WORD *)*v5 + 34) == 26465 && (*v5)[70] == 101 )
{
puts("start pack cpimage.img ......");
v25 = *v5;
*((_DWORD *)v25 + 26) = v6;
v39 = v25;
v26 = func1(v25);
v27 = *v5;
*((_DWORD *)v39 + 27) = v26;
v11 = "cpimage.img";
v35 = v27;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1818587760 && *((_WORD *)*v5 + 34) == 24943 && (*v5)[70] == 100 )
{
puts("start pack preload.img......");
v28 = *v5;
*((_DWORD *)v28 + 26) = v6;
v40 = v28;
v29 = func1(v28);
v30 = *v5;
*((_DWORD *)v40 + 27) = v29;
v11 = "preload.img";
v35 = v30;
goto LABEL_16;
}
if ( *((_DWORD *)v7 + 16) == 1751343459 && (*v5)[68] == 101 )
{
puts("start pack cache.img...... ");
v5 = (const char **)v5[1];
}
else if ( !memcmp(*v5 + 64, "fat", 5uLL) )
{
puts("start pack fat.img...... ");
v5 = (const char **)v5[1];
}
}
while ( v5[1] );
}
LABEL_17:
*((_DWORD *)buf + 20) = func2();
*((_DWORD *)buf + 3) = func1(a4);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
LABEL_36:
puts("pack header is Error!");
exit(1);
}
v14 = 0;
if ( *((_DWORD *)buf + 21) )
{
while ( write(fd, *v4, 0x100uLL) >= 0 )
{
v4 = (const void **)v4[1];
if ( *((_DWORD *)buf + 21) <= (unsigned int)++v14 )
goto LABEL_21;
}
goto LABEL_36;
}
LABEL_21:
*((_DWORD *)buf + 2) = func4(fd, 12LL, 2045);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
puts("pack header crc is Error!");
exit(1);
}
close(fd);
return 0LL;
}

original_code:
int pack_szb_image(int new_szb_file, szb_header_t *szb_header,image_node *header,char *packname)
{
 unsigned int i,set;
 image_node *prefix=header;
 unsigned int start_offset=8192;
 for(i=0;prefix->next!=((void *)0);i++)
 {
  if (memcmp(prefix->data->partname,"bootloader",10)==0)
  {
   printf("start pack uboot.bin......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"uboot.bin");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"boot",4)==0)
  {
   printf("start pack boot.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"boot.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"recovery",8)==0)
  {
   printf("start pack recovery.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"recovery.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"system",6)==0)
  {
   printf("start pack system.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"system.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start pack userdata.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"userdata.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cpimage",7)==0)
  {
   printf("start pack cpimage.img ......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"cpimage.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"preload",7)==0)
  {
   printf("start pack preload.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"preload.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start  pack userdata.img......\n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cache",5)==0)
  {
   printf("start pack  cache.img...... \n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"fat",5)==0)
  {
   printf("start pack  fat.img...... \n");
   prefix=prefix->next;
   continue;
  }
 }
 szb_header->timestamp=get_system_time();;
 szb_header->filesize=get_file_size(packname);
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header  is Error!\n");
  exit(1);
 };
 prefix=header;
 for (i = 0; i < szb_header->imagecount; i++)
 {
  if(write(new_szb_file,(char *)prefix->data,256)<0)
  {
   printf("pack  header  is Error!\n");
   exit(1);
  };
  prefix=prefix->next;
 }
 szb_header->checksum = header_crc_checksum(new_szb_file,12,(256*32-12)/sizeof(unsigned int));
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header crc   is Error!\n");
  exit(1);
 };
 close(new_szb_file);
 return 0;
}

canonical_original_code:
int pack_szb_image(int new_szb_file, struct szb_header_t *szb_header, struct image_node *header, char *packname)
{
 unsigned int i; unsigned int set;
 struct image_node *prefix = header;
 unsigned int start_offset = 8192;
 for(i=0;prefix->next!=((void *)0);i++)
 {
  if (memcmp(prefix->data->partname,"bootloader",10)==0)
  {
   printf("start pack uboot.bin......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"uboot.bin");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"boot",4)==0)
  {
   printf("start pack boot.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"boot.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"recovery",8)==0)
  {
   printf("start pack recovery.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"recovery.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"system",6)==0)
  {
   printf("start pack system.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"system.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start pack userdata.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"userdata.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cpimage",7)==0)
  {
   printf("start pack cpimage.img ......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"cpimage.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"preload",7)==0)
  {
   printf("start pack preload.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"preload.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start  pack userdata.img......\n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cache",5)==0)
  {
   printf("start pack  cache.img...... \n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"fat",5)==0)
  {
   printf("start pack  fat.img...... \n");
   prefix=prefix->next;
   continue;
  }
 }
 szb_header->timestamp=get_system_time();;
 szb_header->filesize=get_file_size(packname);
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header  is Error!\n");
  exit(1);
 };
 prefix=header;
 for (i = 0; i < szb_header->imagecount; i++)
 {
  if(write(new_szb_file,(char *)prefix->data,256)<0)
  {
   printf("pack  header  is Error!\n");
   exit(1);
  };
  prefix=prefix->next;
 }
 szb_header->checksum = header_crc_checksum(new_szb_file,12,(256*32-12)/sizeof(unsigned int));
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header crc   is Error!\n");
  exit(1);
 };
 close(new_szb_file);
 return 0;
}

variable_types: struct szb_header_t { unsigned char magic[8]; unsigned int checksum; unsigned int filesize; unsigned char author[32]; unsigned char version[32]; unsigned int timestamp; unsigned int imagecount; unsigned char tools[32]; unsigned char reserve[-1]; } *

variable_types:
packname
char *


original_code:
int pack_main(image_node *header,szb_header_t *szb_header,header_temp_t *header_temp,char new_pack_header,char *packname,char *author_name)
{
 int i;
 int new_szb_file;
 szb_header=(szb_header_t *)malloc(sizeof(szb_header_t));
 strncpy(szb_header->magic,"LmSzBfMt",8);
 strncpy(szb_header->author,author_name,32);
 strncpy(szb_header->version,"[www.lephone.cc]",16);
 strcat(szb_header->version,packname);
 strncpy(szb_header->tools,"木马男孩leszb 1.0",32);
 szb_header->imagecount=0;
 header=(image_node *)malloc(sizeof(image_node));
 header->data=(szb_images_t *)malloc(sizeof(szb_images_t));
 header->next=((void *)0);
 image_node *prefix=header,*suffix=header;
 for (i = 0; header_temp[i].flag==1; i++)
 {
  strncpy(prefix->data->partname,header_temp[i].partname,32);
  strncpy(prefix->data->filename,header_temp[i].filename,64);
  prefix->data->writeflag=header_temp[i].writeflag;
  prefix->data->eraseflag=header_temp[i].eraseflag;
  prefix=(image_node *)malloc(sizeof(image_node));
  prefix->data=(szb_images_t *)malloc(sizeof(szb_images_t));
  suffix->next=prefix;
  prefix->next=((void *)0);
  suffix=prefix;
 }
 szb_header->imagecount=i;
 if((new_szb_file = open(packname,02|0100|01000,0777))<0)
 {
  printf("%s file creat faill!\n",packname);
  exit(1);
 }
 pack_szb_image(new_szb_file,szb_header,header,packname);
 return 0;
}

canonical_original_code:
int pack_main(struct image_node *header, struct szb_header_t *szb_header, struct header_temp_t *header_temp, char new_pack_header, char *packname, char *author_name)
{
 int i;
 int new_szb_file;
 szb_header=(struct szb_header_t *)malloc(sizeof(szb_header_t));
 strncpy(szb_header->magic,"LmSzBfMt",8);
 strncpy(szb_header->author,author_name,32);
 strncpy(szb_header->version,"[www.lephone.cc]",16);
 strcat(szb_header->version,packname);
 strncpy(szb_header->tools,"木马男孩leszb 1.0",32);
 szb_header->imagecount=0;
 header=(struct image_node *)malloc(sizeof(image_node));
 header->data=(struct szb_images_t *)malloc(sizeof(szb_images_t));
 header->next=((void *)0);
 struct image_node *prefix = header; struct image_node *suffix = header;
 for (i = 0; header_temp[i].flag==1; i++)
 {
  strncpy(prefix->data->partname,header_temp[i].partname,32);
  strncpy(prefix->data->filename,header_temp[i].filename,64);
  prefix->data->writeflag=header_temp[i].writeflag;
  prefix->data->eraseflag=header_temp[i].eraseflag;
  prefix=(struct image_node *)malloc(sizeof(image_node));
  prefix->data=(struct szb_images_t *)malloc(sizeof(szb_images_t));
  suffix->next=prefix;
  prefix->next=((void *)0);
  suffix=prefix;
 }
 szb_header->imagecount=i;
 if((new_szb_file = open(packname,02|0100|01000,0777))<0)
 {
  printf("%s file creat faill!\n",packname);
  exit(1);
 }
 pack_szb_image(new_szb_file,szb_header,header,packname);
 return 0;
}

variable_types: struct image_node { struct szb_images_t { unsigned char filename[64]; unsigned char partname[32]; unsigned int checksum; unsigned int timestamp; unsigned int imageoffset; unsigned int imagesize; unsigned int eraseflag; unsigned int writeflag; unsigned char reserve[-1]; } *data; struct image_node *next; } *

variable_types: struct header_temp_t { unsigned int flag; unsigned char filename[64]; unsigned char partname[32]; unsigned int eraseflag; unsigned int writeflag; } *

variable_types: i int

return_type: int

user_defined_types: struct image_node { struct szb_images_t *data; struct image_node *next; }

user_defined_types: struct szb_header_t { unsigned char magic[8]; unsigned int checksum; unsigned int filesize; unsigned char author[32]; unsigned char version[32]; unsigned int timestamp; unsigned int imagecount; unsigned char tools[32]; unsigned char reserve[-1]; }


original_code:
void display_head(char *packname,szb_header_t *szb_header)
{
 printf("Pack information :!\n");
 printf("..............................................\n");
 printf("CRC校验码  :%x\n",szb_header->checksum);
 printf("szb包大小  :%dB\n",szb_header->filesize);
 printf("szb作者    :%s\n",szb_header->author);
 printf("szb包版本  :%s\n",szb_header->version);
 printf("封包时间   :%x\n",szb_header->timestamp);
 printf("img包数量  :%d\n",szb_header->imagecount);
 printf("打包工具   :%s\n",szb_header->tools);
 printf("..............................................\n");
}

canonical_original_code:
void display_head(char *packname, struct szb_header_t *szb_header)
{
 printf("Pack information :!\n");
 printf("..............................................\n");
 printf("CRC校验码  :%x\n",szb_header->checksum);
 printf("szb包大小  :%dB\n",szb_header->filesize);
 printf("szb作者    :%s\n",szb_header->author);
 printf("szb包版本  :%s\n",szb_header->version);
 printf("封包时间   :%x\n",szb_header->timestamp);
 printf("img包数量  :%d\n",szb_header->imagecount);
 printf("打包工具   :%s\n",szb_header->tools);
 printf("..............................................\n");
}

return_type: void


decompiled_code:
__int64 __fastcall get_szb_info(const char *a1)
{
int v1; // eax
int v2; // ebp
__int64 result; // rax
unsigned int v4[70]; // [rsp+0h] [rbp-118h] BYREF

v1 = open(a1, 2, 511LL);
v2 = v1;
if ( v1 < 0 )
{
printf("open szbPack is faill!%d\n", (unsigned int)v1);
result = 1LL;
}
else if ( read(v1, v4, 0x100uLL) < 0 )
{
puts("read head fail! exit ");
result = 1LL;
}
else
{
display_head((__int64)a1, v4);
show_szb_info(v2, (__int64)v4);
close(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
int v1; // eax
int v2; // ebp
__int64 result; // rax
unsigned int v4[70]; // [rsp+0h] [rbp-118h] BYREF

v1 = open(a1, 2, 511LL);
v2 = v1;
if ( v1 < 0 )
{
printf("open szbPack is faill!%d\n", (unsigned int)v1);
result = 1LL;
}
else if ( read(v1, v4, 0x100uLL) < 0 )
{
puts("read head fail! exit ");
result = 1LL;
}
else
{
func8((__int64)a1, v4);
func7(v2, (__int64)v4);
close(v2);
result = 0LL;
}
return result;
}

original_code:
int get_szb_info(char *packname,image_node *header,szb_header_t *szb_header)
{
 char head_buff[256];
 int szb_path;
 int i;
 if((szb_path=open(packname,02,0777))<0)
 {
  printf("open szbPack is faill!%d\n",szb_path);
  return 1;
 }
 if(read(szb_path,head_buff,256)<0)
 {
  printf("read head fail! exit \n");
  return 1;
 }
 szb_header=(szb_header_t *)head_buff;
 display_head(packname,szb_header);
 header=show_szb_info(szb_path,szb_header);
 close(szb_path);
 return 0;
}

canonical_original_code:
int get_szb_info(char *packname, struct image_node *header, struct szb_header_t *szb_header)
{
 char head_buff[256];
 int szb_path;
 int i;
 if((szb_path=open(packname,02,0777))<0)
 {
  printf("open szbPack is faill!%d\n",szb_path);
  return 1;
 }
 if(read(szb_path,head_buff,256)<0)
 {
  printf("read head fail! exit \n");
  return 1;
 }
 szb_header=(struct szb_header_t *)head_buff;
 display_head(packname,szb_header);
 header=show_szb_info(szb_path,szb_header);
 close(szb_path);
 return 0;
}

user_defined_types: struct szb_images_t { unsigned char filename[64]; unsigned char partname[32]; unsigned int checksum; unsigned int timestamp; unsigned int imageoffset; unsigned int imagesize; unsigned int eraseflag; unsigned int writeflag; unsigned char reserve[-1]; }


sort

repo: yuanyiyixi/C-program

decompiled_code:
__int64 __fastcall sort(__int64 a1, __int64 a2)
{
bool v3; // cf
bool v4; // zf
const char *v5; // rax
const char *v6; // rdi
__int64 v7; // rcx
const char *v8; // rsi
char v9; // dl
bool v10; // cf
bool v11; // zf
const char *v12; // rsi
const char *v13; // rdi
__int64 v14; // rcx

puts("sort cmd");
v5 = *(const char **)(a2 + 8);
v6 = "name";
v7 = 5LL;
v8 = v5;
do
{
if ( !v7 )
break;
v3 = *v8 < (unsigned int)*v6;
v4 = *v8++ == *v6++;
--v7;
}
while ( v4 );
v9 = (!v3 && !v4) - v3;
v10 = 0;
v11 = v9 == 0;
if ( !v9 )
{
sort_by_name(v6, v8);
v5 = *(const char **)(a2 + 8);
}
v12 = v5;
v13 = "age";
v14 = 4LL;
do
{
if ( !v14 )
break;
v10 = *v12 < (unsigned int)*v13;
v11 = *v12++ == *v13++;
--v14;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
sort_by_age(v13, v12);
return 0LL;
}

variable_types:
a
int []

variable_types: len int

variable_types:
bit
char [-1]

variable_types: pos int

variable_types: j int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
unsigned int v4; // [rsp+Ch] [rbp-CCh] BYREF
char *s1[8]; // [rsp+10h] [rbp-C8h] BYREF
char s[136]; // [rsp+50h] [rbp-88h] BYREF

puts(::s);
while ( 1 )
{
v4 = 0;
v3 = cmds;
puts(&byte_402030);
fgets(s, 128, _bss_start);
parse(s, &v4, s1);
do
{
if ( !strcmp(s1[0], v3) )
(*((void (__fastcall **)(_QWORD, char **))v3 + 2))(v4, s1);
v3 += 24;
}
while ( v3 != (char *)&_bss_start );
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
unsigned int v4; // [rsp+Ch] [rbp-CCh] BYREF
char *s1[8]; // [rsp+10h] [rbp-C8h] BYREF
char s[136]; // [rsp+50h] [rbp-88h] BYREF

puts(::s);
while ( 1 )
{
v4 = 0;
v3 = cmds;
puts(&byte_402030);
fgets(s, 128, _bss_start);
func22(s, &v4, s1);
do
{
if ( !strcmp(s1[0], v3) )
(*((void (__fastcall **)(_QWORD, char **))v3 + 2))(v4, s1);
v3 += 24;
}
while ( v3 != (char *)&_bss_start );
}
}

original_code:
int main(void)
{
 int a[100];
 init_array(a, 100);
 sort(a, 100);
 show(a, 100);
 return 0;
}

canonical_original_code:
int main()
{
 int a[100];
 init_array(a, 100);
 sort(a, 100);
 show(a, 100);
 return 0;
}


repo: yubai/PPNFS

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
ppnfs_client_config_init(argc, argv, envp);
ppnfs_client_net_start();
ppnfs_client_metadata_init();
ppnfs_client_grpir_init();
fuse_main_real((unsigned int)argc, argv, &ppnfs_oper, 360LL, 0LL);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
    ppnfs_client_config_init();
    ppnfs_client_net_start();
    ppnfs_client_metadata_init();
    ppnfs_client_grpir_init();
    void* user_data = ((void *)0);
    fuse_main_real(argc, argv, &ppnfs_oper, sizeof(*(&ppnfs_oper)), user_data);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    ppnfs_client_config_init();
    ppnfs_client_net_start();
    ppnfs_client_metadata_init();
    ppnfs_client_grpir_init();
    void *user_data = ((void *)0);
    fuse_main_real(argc, argv, &ppnfs_oper, sizeof(*(&ppnfs_oper)), user_data);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 ppnfs_init()
{
fprintf(stderr, "INF|ppnfs_fuse.c:%d:%s|Filesystem now serving requests...\n", 161LL, "ppnfs_init");
fflush(stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
fprintf(stderr, "INF|ppnfs_fuse.c:%d:%s|Filesystem now serving requests...\n", 161LL, "ppnfs_init");
fflush(stderr);
return 0LL;
}

original_code:
static void*
ppnfs_init(struct fuse_conn_info *conn)
{
    do { fprintf(stderr, "INF" "|" "ppnfs_fuse.c" ":%d:%s|" "Filesystem now serving requests...\n", 161, __FUNCTION__ ); fflush(stderr); } while(0);
    return ((void *)0);
}

canonical_original_code:
static void *ppnfs_init(struct fuse_conn_info *conn)
{
    do { fprintf(stderr, "INF" "|" "ppnfs_fuse.c" ":%d:%s|" "Filesystem now serving requests...\n", 161, __FUNCTION__ ); fflush(stderr); } while(0);
    return ((void *)0);
}

variable_types: struct fuse_conn_info { unsigned int proto_major; unsigned int proto_minor; unsigned int async_read; unsigned int max_write; unsigned int max_readahead; unsigned int capable; unsigned int want; unsigned int max_background; unsigned int congestion_threshold; unsigned int reserved[23]; } *

return_type: void *


decompiled_code:
__int64 __fastcall ppnfs_readdir(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, const char *, int *))
{
unsigned int v4; // er12
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // rbx
unsigned int v9; // eax
int v10[48]; // [rsp+0h] [rbp-C0h] BYREF

memset(v10, 0, 0x90uLL);
v10[6] = 0x4000;
v4 = a3(a2, ".", v10);
if ( !v4 )
{
v4 = ((__int64 (__fastcall *)(__int64, const char *, int *, _QWORD))a3)(a2, "..", v10, 0LL);
if ( !v4 )
{
v6 = ppnfs_metadata_find(a1);
v7 = v6;
if ( v6 )
{
v8 = ppnfs_metadata_get_child(v6);
if ( v8 )
{
while ( 1 )
{
v9 = ((__int64 (__fastcall *)(__int64, __int64, __int64, _QWORD))a3)(a2, v8 + 8, v8 + 336, 0LL);
if ( v9 )
break;
v8 = ppnfs_metadata_get(*(_QWORD *)(v8 + 288));
if ( !v8 )
goto LABEL_10;
}
v4 = v9;
}
LABEL_10:
ppnfs_metadata_release(v7);
}
else
{
v4 = -2;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, const char *, int *))
{
unsigned int v4; // er12
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // rbx
unsigned int v9; // eax
int v10[48]; // [rsp+0h] [rbp-C0h] BYREF

memset(v10, 0, 0x90uLL);
v10[6] = 0x4000;
v4 = a3(a2, ".", v10);
if ( !v4 )
{
v4 = ((__int64 (__fastcall *)(__int64, const char *, int *, _QWORD))a3)(a2, "..", v10, 0LL);
if ( !v4 )
{
v6 = ppnfs_metadata_find(a1);
v7 = v6;
if ( v6 )
{
v8 = ppnfs_metadata_get_child(v6);
if ( v8 )
{
while ( 1 )
{
v9 = ((__int64 (__fastcall *)(__int64, __int64, __int64, _QWORD))a3)(a2, v8 + 8, v8 + 336, 0LL);
if ( v9 )
break;
v8 = ppnfs_metadata_get(*(_QWORD *)(v8 + 288));
if ( !v8 )
goto LABEL_10;
}
v4 = v9;
}
LABEL_10:
ppnfs_metadata_release(v7);
}
else
{
v4 = -2;
}
}
}
return v4;
}

original_code:
static int
ppnfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
     off_t offset, struct fuse_file_info *info)
{
    int res = 0;
    struct ppnfs_metadata_t* mfather, *mchild;
    struct stat st;
    (void) offset;
    (void) info;
    memset(&st, 0, sizeof(struct stat));
    st.st_mode = 0040000;
    res = filler(buf, ".", &st, 0);
    if (res) return res;
    res = filler(buf, "..", &st, 0);
    if (res) return res;
    mfather = ppnfs_metadata_find(path);
    if (!mfather) return -2;
    for (mchild = ppnfs_metadata_get_child(mfather); mchild; mchild
   = ppnfs_metadata_get(mchild->next)) {
        res = filler(buf, mchild->d_name, &(mchild->st), 0);
        if (res) break;
    }
    ppnfs_metadata_release(mfather);
    return res;
}

canonical_original_code:
static int ppnfs_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *info)
{
    int res = 0;
    struct ppnfs_metadata_t *mfather; struct ppnfs_metadata_t *mchild;
    struct stat st;
    (void) offset;
    (void) info;
    memset(&st, 0, sizeof(struct stat));
    st.st_mode = 0040000;
    res = filler(buf, ".", &st, 0);
    if (res) return res;
    res = filler(buf, "..", &st, 0);
    if (res) return res;
    mfather = ppnfs_metadata_find(path);
    if (!mfather) return -2;
    for (mchild = ppnfs_metadata_get_child(mfather); mchild; mchild
   = ppnfs_metadata_get(mchild->next)) {
        res = filler(buf, mchild->d_name, &(mchild->st), 0);
        if (res) break;
    }
    ppnfs_metadata_release(mfather);
    return res;
}

variable_types:
path
char *

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, 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]; } *stbuf, long off)

variable_types: offset long

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *

variable_types: res int

variable_types: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; 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]; } st; unsigned int prime; unsigned int c; char pi[]; } *

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

user_defined_types: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; struct stat st; unsigned int prime; unsigned int c; char pi[]; }


decompiled_code:
__int64 __fastcall ppnfs_open(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = ppnfs_metadata_find(a1);
if ( !v1 )
return 4294967294LL;
if ( (*(_DWORD *)(v1 + 360) & 0xF000) == 0x8000 )
{
ppnfs_metadata_release(v1);
result = 0LL;
}
else
{
ppnfs_metadata_release(v1);
result = 4294967275LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = ppnfs_metadata_find(a1);
if ( !v1 )
return 4294967294LL;
if ( (*(_DWORD *)(v1 + 360) & 0xF000) == 0x8000 )
{
ppnfs_metadata_release(v1);
result = 0LL;
}
else
{
ppnfs_metadata_release(v1);
result = 4294967275LL;
}
return result;
}

original_code:
static int
ppnfs_open(const char *path, struct fuse_file_info* info)
{
    struct ppnfs_metadata_t* mdata = ppnfs_metadata_find(path);
    if (mdata == ((void *)0)) {
        return -2;
    }
    if (!((((mdata->st.st_mode)) & 0170000) == (0100000))) {
        ppnfs_metadata_release(mdata);
        return -21;
    }
    ppnfs_metadata_release(mdata);
    return 0;
}

canonical_original_code:
static int ppnfs_open(char *path, struct fuse_file_info *info)
{
    struct ppnfs_metadata_t *mdata = ppnfs_metadata_find(path);
    if (mdata == ((void *)0)) {
        return -2;
    }
    if (!((((mdata->st.st_mode)) & 0170000) == (0100000))) {
        ppnfs_metadata_release(mdata);
        return -21;
    }
    ppnfs_metadata_release(mdata);
    return 0;
}

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }

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


decompiled_code:
__int64 __fastcall ppnfs_read(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
int v7; // er15
unsigned int v8; // er15
__int64 v10; // rdx
__int64 v11; // rcx
unsigned int v12; // er14
void *v13; // r13
unsigned int i; // er15
__int64 v15; // r14
void *v16; // rax
__int64 v17; // rsi
__int64 v18; // [rsp+8h] [rbp-D8h]
unsigned int v20; // [rsp+10h] [rbp-D0h]
unsigned int v21; // [rsp+1Ch] [rbp-C4h]
char v22[16]; // [rsp+20h] [rbp-C0h] BYREF
char v23[16]; // [rsp+30h] [rbp-B0h] BYREF
char v24[16]; // [rsp+40h] [rbp-A0h] BYREF
char v25[16]; // [rsp+50h] [rbp-90h] BYREF
char v26[16]; // [rsp+60h] [rbp-80h] BYREF
char v27[16]; // [rsp+70h] [rbp-70h] BYREF
char v28[16]; // [rsp+80h] [rbp-60h] BYREF
char v29[80]; // [rsp+90h] [rbp-50h] BYREF

v6 = ppnfs_metadata_find(a1);
clock();
v7 = NR_BITPERBLK;
_gmpz_init(v22);
init_rand(v29, v22, (unsigned int)((v7 >> 3) + 1));
ppnfs_genmodulus(v6, (unsigned int)v7, v29, v24, v25, v26);
if ( *(_QWORD *)(v6 + 384) <= a4 || (v8 = ppnfs_client_send_gm(v24, v26)) != 0 )
{
v8 = 0;
LABEL_4:
clock();
goto LABEL_5;
}
v10 = *(_QWORD *)(v6 + 384) - a4;
if ( (unsigned __int64)(a4 + a3) <= *(_QWORD *)(v6 + 384) )
v10 = a3;
v11 = (unsigned int)NR_BITPERBLK >> 4;
v20 = v10;
v12 = a4 / v11;
v18 = a4 / v11;
v21 = (v10 + a4 - 1) / (unsigned __int64)v11 + 1;
if ( (unsigned int)ppnfs_client_send_blknr(v21 - v12, a4 / v11, (v10 + a4 - 1) % (unsigned __int64)v11) != -1 )
{
v13 = malloc(((unsigned int)NR_BITPERBLK >> 3) + 1);
for ( i = v18; i < v21; a2 += (unsigned int)NR_BITPERBLK >> 4 )
{
++i;
_gmpz_init(v23);
_gmpz_powm(v23, v24, v25, v26);
v15 = ppnfs_client_retrieve_block(v12);
v16 = malloc((unsigned int)NR_BITPERBLK);
_gmp_sprintf(v16, "%Zx\n", v15);
_gmpz_init(v27);
_gmpz_init(v28);
v17 = v15;
v12 = i;
_gmpz_powm(v27, v17, v25, v26);
discrete_log(v28, v23, v27, v26, *(unsigned int *)(v6 + 480), *(unsigned int *)(v6 + 484));
memset(v13, 0, ((unsigned int)NR_BITPERBLK >> 3) + 1);
_gmp_sprintf(v13, "%Zx", v28);
groupStr(a2, v13);
}
v8 = v20;
goto LABEL_4;
}
LABEL_5:
ppnfs_metadata_release(v6);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
int v7; // er15
unsigned int v8; // er15
__int64 v10; // rdx
__int64 v11; // rcx
unsigned int v12; // er14
void *v13; // r13
unsigned int i; // er15
__int64 v15; // r14
void *v16; // rax
__int64 v17; // rsi
__int64 v18; // [rsp+8h] [rbp-D8h]
unsigned int v20; // [rsp+10h] [rbp-D0h]
unsigned int v21; // [rsp+1Ch] [rbp-C4h]
char v22[16]; // [rsp+20h] [rbp-C0h] BYREF
char v23[16]; // [rsp+30h] [rbp-B0h] BYREF
char v24[16]; // [rsp+40h] [rbp-A0h] BYREF
char v25[16]; // [rsp+50h] [rbp-90h] BYREF
char v26[16]; // [rsp+60h] [rbp-80h] BYREF
char v27[16]; // [rsp+70h] [rbp-70h] BYREF
char v28[16]; // [rsp+80h] [rbp-60h] BYREF
char v29[80]; // [rsp+90h] [rbp-50h] BYREF

v6 = ppnfs_metadata_find(a1);
clock();
v7 = NR_BITPERBLK;
_gmpz_init(v22);
init_rand(v29, v22, (unsigned int)((v7 >> 3) + 1));
ppnfs_genmodulus(v6, (unsigned int)v7, v29, v24, v25, v26);
if ( *(_QWORD *)(v6 + 384) <= a4 || (v8 = ppnfs_client_send_gm(v24, v26)) != 0 )
{
v8 = 0;
LABEL_4:
clock();
goto LABEL_5;
}
v10 = *(_QWORD *)(v6 + 384) - a4;
if ( (unsigned __int64)(a4 + a3) <= *(_QWORD *)(v6 + 384) )
v10 = a3;
v11 = (unsigned int)NR_BITPERBLK >> 4;
v20 = v10;
v12 = a4 / v11;
v18 = a4 / v11;
v21 = (v10 + a4 - 1) / (unsigned __int64)v11 + 1;
if ( (unsigned int)ppnfs_client_send_blknr(v21 - v12, a4 / v11, (v10 + a4 - 1) % (unsigned __int64)v11) != -1 )
{
v13 = malloc(((unsigned int)NR_BITPERBLK >> 3) + 1);
for ( i = v18; i < v21; a2 += (unsigned int)NR_BITPERBLK >> 4 )
{
++i;
_gmpz_init(v23);
_gmpz_powm(v23, v24, v25, v26);
v15 = ppnfs_client_retrieve_block(v12);
v16 = malloc((unsigned int)NR_BITPERBLK);
_gmp_sprintf(v16, "%Zx\n", v15);
_gmpz_init(v27);
_gmpz_init(v28);
v17 = v15;
v12 = i;
_gmpz_powm(v27, v17, v25, v26);
discrete_log(v28, v23, v27, v26, *(unsigned int *)(v6 + 480), *(unsigned int *)(v6 + 484));
memset(v13, 0, ((unsigned int)NR_BITPERBLK >> 3) + 1);
_gmp_sprintf(v13, "%Zx", v28);
groupStr(a2, v13);
}
v8 = v20;
goto LABEL_4;
}
LABEL_5:
ppnfs_metadata_release(v6);
return v8;
}

original_code:
static int
ppnfs_read(const char *path, char *buf, size_t size, off_t offset,
     struct fuse_file_info* info)
{
    struct ppnfs_metadata_t* mdata = ppnfs_metadata_find(path);
    clock_t start, end;
    start = clock();
    char timebuf[128];
    int modulusbits = NR_BITPERBLK;
    gmp_randstate_t rand;
    mpz_t seed;
    __gmpz_init(seed);
    init_rand(rand, seed, (modulusbits >> 3) + 1);
    mpz_t h, g, q, M;
    ppnfs_genmodulus(mdata, modulusbits, rand, &g, &q, &M);
    if (offset < mdata->st.st_size && ppnfs_client_send_gm(&g, &M) == 0) {
        char* pbuf = buf;
        if (offset + size > mdata->st.st_size) {
            size = mdata->st.st_size - offset;
        }
        mpz_t he;
        mpz_t data;
        unsigned int mask = NR_BITPERBLK >> 4;
        unsigned int blk_begin = offset / mask;
        unsigned int blk_end = (offset + size - 1) / mask + 1;
        if (ppnfs_client_send_blknr(blk_end - blk_begin) == -1){
            size = 0;
            ppnfs_metadata_release(mdata);
            return size;
        }
        char *buffer = malloc((NR_BITPERBLK >> 3) + 1);
        int i;
        for (i = blk_begin; i < blk_end; ++i) {
            __gmpz_init(h);
            __gmpz_powm(h, g, q, M);
            mpz_t* ge = ppnfs_client_retrieve_block(i);
            char* gestr = (char*)malloc(sizeof(char) * NR_BITPERBLK);
            __gmp_sprintf(gestr, "%Zx\n", ge);
            __gmpz_init(he);
            __gmpz_init(data);
            __gmpz_powm(he, *ge, q, M);
            discrete_log(data, h, he, M, mdata->prime, mdata->c);
            memset(buffer, 0, (NR_BITPERBLK >> 3) + 1);
            __gmp_sprintf(buffer, "%Zx", data);
            groupStr(pbuf, buffer);
            pbuf += (NR_BITPERBLK >> 4);
        }
    } else {
        size = 0;
    }
    end = clock();
    ppnfs_metadata_release(mdata);
 return size;
}

canonical_original_code:
static int ppnfs_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *info)
{
    struct ppnfs_metadata_t *mdata = ppnfs_metadata_find(path);
    long start; long end;
    start = clock();
    char timebuf[128];
    int modulusbits = NR_BITPERBLK;
    struct __gmp_randstate_struct rand[1];
    struct __mpz_struct seed[1];
    __gmpz_init(seed);
    init_rand(rand, seed, (modulusbits >> 3) + 1);
    struct __mpz_struct h[1]; struct __mpz_struct g[1]; struct __mpz_struct q[1]; struct __mpz_struct M[1];
    ppnfs_genmodulus(mdata, modulusbits, rand, &g, &q, &M);
    if (offset < mdata->st.st_size && ppnfs_client_send_gm(&g, &M) == 0) {
        char *pbuf = buf;
        if (offset + size > mdata->st.st_size) {
            size = mdata->st.st_size - offset;
        }
        struct __mpz_struct he[1];
        struct __mpz_struct data[1];
        unsigned int mask = NR_BITPERBLK >> 4;
        unsigned int blk_begin = offset / mask;
        unsigned int blk_end = (offset + size - 1) / mask + 1;
        if (ppnfs_client_send_blknr(blk_end - blk_begin) == -1){
            size = 0;
            ppnfs_metadata_release(mdata);
            return size;
        }
        char *buffer = malloc((NR_BITPERBLK >> 3) + 1);
        int i;
        for (i = blk_begin; i < blk_end; ++i) {
            __gmpz_init(h);
            __gmpz_powm(h, g, q, M);
            struct __mpz_struct (*ge)[1] = ppnfs_client_retrieve_block(i);
            char *gestr = (char*)malloc(sizeof(char) * NR_BITPERBLK);
            __gmp_sprintf(gestr, "%Zx\n", ge);
            __gmpz_init(he);
            __gmpz_init(data);
            __gmpz_powm(he, *ge, q, M);
            discrete_log(data, h, he, M, mdata->prime, mdata->c);
            memset(buffer, 0, (NR_BITPERBLK >> 3) + 1);
            __gmp_sprintf(buffer, "%Zx", data);
            groupStr(pbuf, buffer);
            pbuf += (NR_BITPERBLK >> 4);
        }
    } else {
        size = 0;
    }
    end = clock();
    ppnfs_metadata_release(mdata);
 return size;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: start long

variable_types: end long

variable_types:
timebuf
char [128]

variable_types: modulusbits int

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
pbuf
char *

variable_types:
mask
unsigned int

variable_types:
buffer
char *

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]

variable_types:
gestr
char *

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


decompiled_code:
__int64 ppnfs_getattr()
{
return ppnfs_metadata_getattr();
}

canonical_decompiled_code:
__int64 func4()
{
return ppnfs_metadata_getattr();
}

original_code:
static int
ppnfs_getattr(const char *path, struct stat *stbuf)
{
    return ppnfs_metadata_getattr(path, stbuf);
}

canonical_original_code:
static int ppnfs_getattr(char *path, struct stat *stbuf)
{
    return ppnfs_metadata_getattr(path, stbuf);
}

variable_types:
path
char *

variable_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 { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *


decompiled_code:
int ppnfs_client_net_close()
{
return close(hsock);
}

canonical_decompiled_code:
int func3()
{
return close(hsock);
}

original_code:
void
ppnfs_client_net_close()
{
    close(hsock);
}


mheadcmd

decompiled_code:
_DWORD *mheadcmd()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 1;
return result;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 1;
return result;
}

original_code:
struct ppnfs_net_cmd*
mheadcmd()
{
    struct ppnfs_net_mhead_cmd* cmd;
    cmd = (struct ppnfs_net_mhead_cmd*) malloc (sizeof(struct ppnfs_net_mhead_cmd));
    cmd->type = PPNFS_REQUEST_MHEAD;
    return (struct ppnfs_net_cmd*)cmd;
}

canonical_original_code:
struct ppnfs_net_cmd *mheadcmd()
{
    struct ppnfs_net_mhead_cmd *cmd;
    cmd = (struct ppnfs_net_mhead_cmd *) malloc (sizeof(struct ppnfs_net_mhead_cmd));
    cmd->type = PPNFS_REQUEST_MHEAD;
    return (struct ppnfs_net_cmd *)cmd;
}

variable_types: struct ppnfs_net_mhead_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

return_type: struct ppnfs_net_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

user_defined_types: struct ppnfs_net_mhead_cmd { enum _ppnfs_net_type type; }

user_defined_types: struct ppnfs_net_cmd { enum _ppnfs_net_type type; }


mdatacmd

decompiled_code:
_DWORD *mdatacmd()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 2;
return result;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 2;
return result;
}

original_code:
struct ppnfs_net_cmd*
mdatacmd()
{
    struct ppnfs_net_mdata_cmd* cmd;
    cmd = (struct ppnfs_net_mdata_cmd*) malloc (sizeof(struct ppnfs_net_mdata_cmd));
    cmd->type = PPNFS_REQUEST_MDATA;
    return (struct ppnfs_net_cmd*)cmd;
}

canonical_original_code:
struct ppnfs_net_cmd *mdatacmd()
{
    struct ppnfs_net_mdata_cmd *cmd;
    cmd = (struct ppnfs_net_mdata_cmd *) malloc (sizeof(struct ppnfs_net_mdata_cmd));
    cmd->type = PPNFS_REQUEST_MDATA;
    return (struct ppnfs_net_cmd *)cmd;
}

variable_types: struct ppnfs_net_mdata_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

user_defined_types: struct ppnfs_net_mdata_cmd { enum _ppnfs_net_type type; }


decompiled_code:
int ppnfs_client_net_start()
{
int result; // eax
_DWORD *v1; // r12
void *v2; // r12
_DWORD *v3; // r13
size_t v4; // rbx
char *v5; // r13
__int64 v6; // rbx
int *v7; // rax
int *v8; // rax
int v9; // er14
int *v10; // rax
int *v11; // rax
int *v12; // rbx
char *v13; // rax

result = ppnfs_client_net_init_constprop_0();
if ( result == -1 )
return result;
v1 = mheadcmd();
if ( (unsigned int)ppnfs_client_net_send_constprop_0(v1) == -1 )
{
v10 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
151LL,
"ppnfs_client_net_start",
(unsigned int)*v10);
return fflush(stderr);
}
free(v1);
v2 = malloc(0x58uLL);
bytecount = recv(hsock, v2, 0x58uLL, 0);
if ( bytecount == -1 )
{
v8 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata head %d\n",
161LL,
"ppnfs_client_net_start",
(unsigned int)*v8);
return fflush(stderr);
}
LODWORD(NR_BITPERBLK) = *((_DWORD *)v2 + 16);
v3 = mdatacmd();
if ( (unsigned int)ppnfs_client_net_send_constprop_0(v3) == -1 )
{
v11 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
178LL,
"ppnfs_client_net_start",
(unsigned int)*v11);
return fflush(stderr);
}
free(v3);
ppnfs_metadata_struct_size = (((unsigned int)NR_BITPERBLK >> 3) + 496) & 0x3FFFFFF8;
v4 = *((_QWORD *)v2 + 9) * ppnfs_metadata_struct_size;
v5 = (char *)malloc(v4);
if ( v4 )
{
v6 = 0LL;
while ( recv(hsock, &v5[v6], 1uLL, 0) != -1 )
{
if ( ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9) <= (unsigned __int64)++v6 )
goto LABEL_13;
}
v7 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata %d\n",
211LL,
"ppnfs_client_net_start",
(unsigned int)*v7);
return fflush(stderr);
}
LABEL_13:
v9 = open64(ppnfs_metafile, 578, 438LL);
if ( v9 == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Could not open '%s' : err=%d:%s\n",
237LL,
"ppnfs_client_net_start",
ppnfs_metafile,
(unsigned int)*v12,
v13);
fflush(stderr);
}
pwrite64(v9, v5, ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9), 0LL);
free(v2);
free(v5);
return close(v9);
}

canonical_decompiled_code:
int func6()
{
int result; // eax
_DWORD *v1; // r12
void *v2; // r12
_DWORD *v3; // r13
size_t v4; // rbx
char *v5; // r13
__int64 v6; // rbx
int *v7; // rax
int *v8; // rax
int v9; // er14
int *v10; // rax
int *v11; // rax
int *v12; // rbx
char *v13; // rax

result = func2();
if ( result == -1 )
return result;
v1 = func4();
if ( (unsigned int)func0(v1) == -1 )
{
v10 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
151LL,
"ppnfs_client_net_start",
(unsigned int)*v10);
return fflush(stderr);
}
free(v1);
v2 = malloc(0x58uLL);
bytecount = recv(hsock, v2, 0x58uLL, 0);
if ( bytecount == -1 )
{
v8 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata head %d\n",
161LL,
"ppnfs_client_net_start",
(unsigned int)*v8);
return fflush(stderr);
}
LODWORD(NR_BITPERBLK) = *((_DWORD *)v2 + 16);
v3 = func5();
if ( (unsigned int)func0(v3) == -1 )
{
v11 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error sending data %d\n",
178LL,
"ppnfs_client_net_start",
(unsigned int)*v11);
return fflush(stderr);
}
free(v3);
ppnfs_metadata_struct_size = (((unsigned int)NR_BITPERBLK >> 3) + 496) & 0x3FFFFFF8;
v4 = *((_QWORD *)v2 + 9) * ppnfs_metadata_struct_size;
v5 = (char *)malloc(v4);
if ( v4 )
{
v6 = 0LL;
while ( recv(hsock, &v5[v6], 1uLL, 0) != -1 )
{
if ( ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9) <= (unsigned __int64)++v6 )
goto LABEL_13;
}
v7 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving metadata %d\n",
211LL,
"ppnfs_client_net_start",
(unsigned int)*v7);
return fflush(stderr);
}
LABEL_13:
v9 = open64(ppnfs_metafile, 578, 438LL);
if ( v9 == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Could not open '%s' : err=%d:%s\n",
237LL,
"ppnfs_client_net_start",
ppnfs_metafile,
(unsigned int)*v12,
v13);
fflush(stderr);
}
pwrite64(v9, v5, ppnfs_metadata_struct_size * *((_QWORD *)v2 + 9), 0LL);
free(v2);
free(v5);
return close(v9);
}

original_code:
void ppnfs_client_net_start()
{
    int host_port = 11010;
    char* host_name = "127.0.0.1";
    if (ppnfs_client_net_init(&hsock, host_name, host_port) == -1) {
        goto FINISH;
    }
    struct ppnfs_net_cmd* cmd = mheadcmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 151, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    struct ppnfs_metadata_head_t* head =
 malloc ( sizeof(struct ppnfs_metadata_head_t) );
    if((bytecount = recv(hsock, head,
                         sizeof(struct ppnfs_metadata_head_t), 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata head %d\n", 161, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    NR_BITPERBLK = head->bit_per_blk;
    cmd = mdatacmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 178, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    ppnfs_metadata_struct_size =
 sizeof(struct ppnfs_metadata_t) + sizeof(char) * ((NR_BITPERBLK>>3) + 1);
    ppnfs_metadata_struct_size = (ppnfs_metadata_struct_size + 7) & (~0x07);
    struct ppnfs_metadata_t* ppnfs_metadata =
 malloc ( ppnfs_metadata_struct_size * head->alloced_nb );
    int i;
    for (i = 0; i < ppnfs_metadata_struct_size * head->alloced_nb; ++i) {
        if (recv(hsock, (char*)ppnfs_metadata + i, 1, 0) == -1) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata %d\n", 211, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
            goto FINISH;
        }
    }
    int ppnfs_metadata_fd;
    ppnfs_metadata_fd =
 open(ppnfs_metafile, 0100 | 01000 | 02,
   (0400 | 0200 | (0400 >> 3) | (0200 >> 3) |((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)));
    if ( ppnfs_metadata_fd == -1 ) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 237, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
    }
    pwrite(ppnfs_metadata_fd, ppnfs_metadata,
     ppnfs_metadata_struct_size * head->alloced_nb, 0);
    free (head);
    free (ppnfs_metadata);
    close(ppnfs_metadata_fd);
FINISH:
    ;
}

canonical_original_code:
void ppnfs_client_net_start()
{
    int host_port = 11010;
    char *host_name = "127.0.0.1";
    if (ppnfs_client_net_init(&hsock, host_name, host_port) == -1) {
        goto FINISH;
    }
    struct ppnfs_net_cmd *cmd = mheadcmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 151, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    struct ppnfs_metadata_head_t *head = malloc ( sizeof(struct ppnfs_metadata_head_t) );
    if((bytecount = recv(hsock, head,
                         sizeof(struct ppnfs_metadata_head_t), 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata head %d\n", 161, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    NR_BITPERBLK = head->bit_per_blk;
    cmd = mdatacmd();
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 178, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        goto FINISH;
    }
    free (cmd);
    ppnfs_metadata_struct_size =
 sizeof(struct ppnfs_metadata_t) + sizeof(char) * ((NR_BITPERBLK>>3) + 1);
    ppnfs_metadata_struct_size = (ppnfs_metadata_struct_size + 7) & (~0x07);
    struct ppnfs_metadata_t *ppnfs_metadata = malloc ( ppnfs_metadata_struct_size * head->alloced_nb );
    int i;
    for (i = 0; i < ppnfs_metadata_struct_size * head->alloced_nb; ++i) {
        if (recv(hsock, (char *)ppnfs_metadata + i, 1, 0) == -1) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving metadata %d\n", 211, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
            goto FINISH;
        }
    }
    int ppnfs_metadata_fd;
    ppnfs_metadata_fd =
 open(ppnfs_metafile, 0100 | 01000 | 02,
   (0400 | 0200 | (0400 >> 3) | (0200 >> 3) |((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)));
    if ( ppnfs_metadata_fd == -1 ) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 237, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
    }
    pwrite(ppnfs_metadata_fd, ppnfs_metadata,
     ppnfs_metadata_struct_size * head->alloced_nb, 0);
    free (head);
    free (ppnfs_metadata);
    close(ppnfs_metadata_fd);
FINISH:
    ;
}

variable_types: struct ppnfs_net_cmd { enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 } type; } *

variable_types: struct ppnfs_metadata_head_t { char magic[64]; unsigned int bit_per_blk; unsigned long long alloced_nb; unsigned long long first_free; } *

variable_types: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; 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]; } st; unsigned int prime; unsigned int c; char pi[]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall ppnfs_client_send_gm(__int64 a1, __int64 a2)
{
_DWORD *v2; // r13
unsigned int v3; // er12
int *v5; // rax

v2 = blockcmd(a1, a2);
v3 = ppnfs_client_net_send_constprop_0(v2);
if ( v3 == -1 )
{
v5 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending gm %d\n", 260LL, "ppnfs_client_send_gm", (unsigned int)*v5);
fflush(stderr);
}
else
{
v3 = 0;
free(v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
_DWORD *v2; // r13
unsigned int v3; // er12
int *v5; // rax

v2 = blockcmd(a1, a2);
v3 = func0(v2);
if ( v3 == -1 )
{
v5 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending gm %d\n", 260LL, "ppnfs_client_send_gm", (unsigned int)*v5);
fflush(stderr);
}
else
{
v3 = 0;
free(v2);
}
return v3;
}

original_code:
int
ppnfs_client_send_gm(mpz_t* g, mpz_t* M)
{
    int i;
    struct ppnfs_net_cmd* cmd = blockcmd(g, M);
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending gm %d\n", 260, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        return -1;
    }
    free (cmd);
    return 0;
}

canonical_original_code:
int ppnfs_client_send_gm(struct __mpz_struct (*g)[1], struct __mpz_struct (*M)[1])
{
    int i;
    struct ppnfs_net_cmd *cmd = blockcmd(g, M);
    if (ppnfs_client_net_send(&hsock, cmd) == -1) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending gm %d\n", 260, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        return -1;
    }
    free (cmd);
    return 0;
}

variable_types:
M
struct __mpz_struct (*)[1]

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: enum _ppnfs_net_type { PPNFS_REQUEST_MHEAD=1, PPNFS_REQUEST_MDATA=2, PPNFS_REQUEST_BLOCK=3 }


decompiled_code:
__int64 __fastcall ppnfs_client_send_blknr(int a1)
{
int *v2; // rax
int buf; // [rsp+Ch] [rbp-4h] BYREF

buf = a1;
bytecount = send(hsock, &buf, 4uLL, 0);
if ( bytecount != -1 )
return 0LL;
v2 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending data %d\n", 272LL, "ppnfs_client_send_blknr", (unsigned int)*v2);
fflush(stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int *v2; // rax
int buf; // [rsp+Ch] [rbp-4h] BYREF

buf = a1;
bytecount = send(hsock, &buf, 4uLL, 0);
if ( bytecount != -1 )
return 0LL;
v2 = _errno_location();
fprintf(stderr, "ERR|ppnfs_net.c:%d:%s|Error sending data %d\n", 272LL, "ppnfs_client_send_blknr", (unsigned int)*v2);
fflush(stderr);
return 0xFFFFFFFFLL;
}

original_code:
int
ppnfs_client_send_blknr(int nr)
{
    if( (bytecount=send(hsock, &nr, sizeof(int), 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error sending data %d\n", 272, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
        return -1;
    }
    return 0;
}

variable_types: nr int


decompiled_code:
void *ppnfs_client_retrieve_block()
{
size_t v0; // r14
void *v1; // r13
void *v2; // r12
int *v4; // rax

v0 = (unsigned int)NR_BITPERBLK;
v1 = malloc((unsigned int)NR_BITPERBLK);
v2 = malloc(0x10uLL);
bytecount = recv(hsock, v1, v0, 0);
if ( bytecount == -1 )
{
v4 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving ge %d\n",
285LL,
"ppnfs_client_retrieve_block",
(unsigned int)*v4);
fflush(stderr);
}
_gmpz_init(v2);
_gmp_sscanf(v1, "%Zx\n", v2);
return v2;
}

canonical_decompiled_code:
void *func9()
{
size_t v0; // r14
void *v1; // r13
void *v2; // r12
int *v4; // rax

v0 = (unsigned int)NR_BITPERBLK;
v1 = malloc((unsigned int)NR_BITPERBLK);
v2 = malloc(0x10uLL);
bytecount = recv(hsock, v1, v0, 0);
if ( bytecount == -1 )
{
v4 = _errno_location();
fprintf(
stderr,
"ERR|ppnfs_net.c:%d:%s|Error receiving ge %d\n",
285LL,
"ppnfs_client_retrieve_block",
(unsigned int)*v4);
fflush(stderr);
}
_gmpz_init(v2);
_gmp_sscanf(v1, "%Zx\n", v2);
return v2;
}

original_code:
mpz_t*
ppnfs_client_retrieve_block(unsigned int idx)
{
    char* gestr = malloc(sizeof(char) * NR_BITPERBLK);
    mpz_t* ge = (mpz_t*)malloc(sizeof(mpz_t));
    if((bytecount = recv(hsock, gestr, NR_BITPERBLK, 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving ge %d\n", 285, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
    }
    __gmpz_init(*ge);
    __gmp_sscanf(gestr, "%Zx\n", ge);
    return ge;
}

canonical_original_code:
struct __mpz_struct (*ppnfs_client_retrieve_block(unsigned int idx))[1]
{
    char *gestr = malloc(sizeof(char) * NR_BITPERBLK);
    struct __mpz_struct (*ge)[1] = (mpz_t*)malloc(sizeof(mpz_t));
    if((bytecount = recv(hsock, gestr, NR_BITPERBLK, 0))== -1){
        do { fprintf(stderr, "ERR" "|" "ppnfs_net.c" ":%d:%s|" "Error receiving ge %d\n", 285, __FUNCTION__,(*__errno_location ()) ); fflush(stderr); } while(0);
    }
    __gmpz_init(*ge);
    __gmp_sscanf(gestr, "%Zx\n", ge);
    return ge;
}

variable_types:
idx
unsigned int

return_type: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } (*)[1]


decompiled_code:
void ppnfs_client_config_init()
{
ppnfs_metafile = "/home/bai/workspace/thesis/ppnfs/client/PPNFS_METAFILE";
}

canonical_decompiled_code:
void func0()
{
ppnfs_metafile = "/home/bai/workspace/thesis/ppnfs/client/PPNFS_METAFILE";
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
char *__fastcall ppnfs_metadata_get(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( a1 == -1 )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Attempt to fetch an EMPTY child !\n", 89LL, "ppnfs_metadata_get");
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
BUG();
}
if ( a1 * ppnfs_metadata_struct_size >= ppnfs_metadata_size )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Out of bounds : id=%llu\n", 92LL, "ppnfs_metadata_get", a1);
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
BUG();
}
return (char *)ppnfs_metadata + a1 * ppnfs_metadata_struct_size;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( a1 == -1 )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Attempt to fetch an EMPTY child !\n", 89LL, "ppnfs_metadata_get");
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
BUG();
}
if ( a1 * ppnfs_metadata_struct_size >= ppnfs_metadata_size )
{
fprintf(stderr, "BUG|ppnfs_metadata.c:%d:%s|Out of bounds : id=%llu\n", 92LL, "ppnfs_metadata_get", a1);
fflush(stderr);
*(_BYTE *)ppnfs_metadata_close = 0;
BUG();
}
return (char *)ppnfs_metadata + a1 * ppnfs_metadata_struct_size;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_get(ppnfs_metadata_id id)
{
    if (!id)
        return ((void *)0);
    if (id == ppnfs_metadata_id_EMPTY) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Attempt to fetch an EMPTY child !\n", 89, __FUNCTION__ ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
    if (id * ppnfs_metadata_struct_size >= ppnfs_metadata_size) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Out of bounds : id=%llu\n", 92, __FUNCTION__, id ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
    return (struct ppnfs_metadata_t*)((char*)ppnfs_metadata + id * ppnfs_metadata_struct_size);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_get(unsigned long long id)
{
    if (!id)
        return ((void *)0);
    if (id == ppnfs_metadata_id_EMPTY) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Attempt to fetch an EMPTY child !\n", 89, __FUNCTION__ ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
    if (id * ppnfs_metadata_struct_size >= ppnfs_metadata_size) {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Out of bounds : id=%llu\n", 92, __FUNCTION__, id ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
    return (struct ppnfs_metadata_t *)((char *)ppnfs_metadata + id * ppnfs_metadata_struct_size);
}

variable_types:
id
unsigned long long

return_type: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; 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]; } st; unsigned int prime; unsigned int c; char pi[]; } *


decompiled_code:
bool __fastcall ppnfs_metadata_equals(char *a1, __int64 a2, int a3)
{
int v5; // ebx
size_t v6; // r8
size_t v7; // rax
__int64 v8; // rsi
__int64 v9; // rdi

v5 = a3;
if ( a3 <= 1 )
return *((_QWORD *)a1 + 34) == 0LL;
while ( 1 )
{
v6 = v5 - 1;
v7 = v6;
while ( *(_BYTE *)(a2 + v7) != 47 )
{
if ( !(_DWORD)--v7 )
{
v5 = 0;
v8 = 1LL;
goto LABEL_6;
}
}
LODWORD(v6) = v5 - v7 - 1;
v8 = (int)v7 + 1;
v5 = v7;
v6 = (int)v6;
LABEL_6:
if ( strncmp(a1 + 8, (const char *)(a2 + v8), v6) )
return 0;
v9 = *((_QWORD *)a1 + 34);
if ( !v9 )
return 0;
a1 = ppnfs_metadata_get(v9);
if ( v5 <= 1 )
return *((_QWORD *)a1 + 34) == 0LL;
}
}

original_code:
static _Bool
ppnfs_metadata_equals(struct ppnfs_metadata_t* mdata, const char* path, int path_size)
{
    int path_start;
    while (1) {
        ;
        if (path_size <= 1)
            return mdata->father == 0;
        path_start = path_size ? path_size - 1 : 0;
        while (path_start && path[path_start] != '/')
            path_start--;
        ;
        if (strncmp(mdata->d_name, &(path[path_start + 1]),
                    path_size - path_start - 1)) {
            ;
            return 0;
        }
        if (!mdata->father)
            return 0;
        mdata = ppnfs_metadata_get(mdata->father);
        path_size = path_start;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Shall not be here.\n", 136, __FUNCTION__ ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    return -1;
}

canonical_original_code:
static _Bool ppnfs_metadata_equals(struct ppnfs_metadata_t *mdata, char *path, int path_size)
{
    int path_start;
    while (1) {
        ;
        if (path_size <= 1)
            return mdata->father == 0;
        path_start = path_size ? path_size - 1 : 0;
        while (path_start && path[path_start] != '/')
            path_start--;
        ;
        if (strncmp(mdata->d_name, &(path[path_start + 1]),
                    path_size - path_start - 1)) {
            ;
            return 0;
        }
        if (!mdata->father)
            return 0;
        mdata = ppnfs_metadata_get(mdata->father);
        path_size = path_start;
    }
    do { do { fprintf(stderr, "BUG" "|" "ppnfs_metadata.c" ":%d:%s|" "Shall not be here.\n", 136, __FUNCTION__ ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    return -1;
}


decompiled_code:
char *ppnfs_metadata_get_root()
{
return ppnfs_metadata_get(1LL);
}

canonical_decompiled_code:
char *func2()
{
return func0(1LL);
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_get_root()
{
    return ppnfs_metadata_get(ppnfs_metadata_id_root);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_get_root()
{
    return ppnfs_metadata_get(ppnfs_metadata_id_root);
}


decompiled_code:
char *ppnfs_client_metadata_init()
{
int v0; // er8
__off_t v1; // rsi
int *v3; // rbx
char *v4; // rax
struct stat64 v5; // [rsp+0h] [rbp-A0h] BYREF

if ( !stat64(ppnfs_metafile, &v5) && v5.st_size )
{
ppnfs_metadata_fd = open64(ppnfs_metafile, 2);
v0 = ppnfs_metadata_fd;
if ( ppnfs_metadata_fd == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open '%s' : err=%d:%s\n",
34LL,
"ppnfs_client_metadata_init",
ppnfs_metafile,
(unsigned int)*v3,
v4);
fflush(stderr);
v0 = ppnfs_metadata_fd;
}
v1 = v5.st_size;
ppnfs_metadata_size = v5.st_size;
}
else
{
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open metafile '%s'\n",
40LL,
"ppnfs_client_metadata_init",
ppnfs_metafile);
fflush(stderr);
v0 = ppnfs_metadata_fd;
v1 = ppnfs_metadata_size;
}
ppnfs_metadata = mmap64(0LL, v1, 3, 1, v0, 0LL);
if ( (char *)ppnfs_metadata - 1 > (char *)0xFFFFFFFFFFFFFFFDLL )
{
fprintf(stderr, "ERR|ppnfs_metadata.c:%d:%s|Could not open metadata !\n", 51LL, "ppnfs_client_metadata_init");
fflush(stderr);
exit(-1);
}
return ppnfs_metadata_get_root();
}

canonical_decompiled_code:
char *func3()
{
int v0; // er8
__off_t v1; // rsi
int *v3; // rbx
char *v4; // rax
struct stat64 v5; // [rsp+0h] [rbp-A0h] BYREF

if ( !stat64(ppnfs_metafile, &v5) && v5.st_size )
{
ppnfs_metadata_fd = open64(ppnfs_metafile, 2);
v0 = ppnfs_metadata_fd;
if ( ppnfs_metadata_fd == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open '%s' : err=%d:%s\n",
34LL,
"ppnfs_client_metadata_init",
ppnfs_metafile,
(unsigned int)*v3,
v4);
fflush(stderr);
v0 = ppnfs_metadata_fd;
}
v1 = v5.st_size;
ppnfs_metadata_size = v5.st_size;
}
else
{
fprintf(
stderr,
"ERR|ppnfs_metadata.c:%d:%s|Could not open metafile '%s'\n",
40LL,
"ppnfs_client_metadata_init",
ppnfs_metafile);
fflush(stderr);
v0 = ppnfs_metadata_fd;
v1 = ppnfs_metadata_size;
}
ppnfs_metadata = mmap64(0LL, v1, 3, 1, v0, 0LL);
if ( (char *)ppnfs_metadata - 1 > (char *)0xFFFFFFFFFFFFFFFDLL )
{
fprintf(stderr, "ERR|ppnfs_metadata.c:%d:%s|Could not open metadata !\n", 51LL, "ppnfs_client_metadata_init");
fflush(stderr);
exit(-1);
}
return func2();
}

original_code:
void
ppnfs_client_metadata_init()
{
    struct stat st;
    if (stat(ppnfs_metafile, &st) == 0 && st.st_size) {
        ppnfs_metadata_fd = open(ppnfs_metafile, 02);
        if ( ppnfs_metadata_fd == -1 ) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 34, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
        }
        ppnfs_metadata_size = st.st_size;
        ;
    }
    else {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metafile '%s'\n", 40, __FUNCTION__, ppnfs_metafile ); fflush(stderr); } while(0);
    }
    ;
    ppnfs_metadata = (struct ppnfs_metadata_t*)mmap(((void *)0),
                                                    ppnfs_metadata_size,
                                                    0x1 | 0x2, 0x01,
                                                    ppnfs_metadata_fd, 0);
    if (ppnfs_metadata == ((void *)0) || ppnfs_metadata == ((void *) -1)) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metadata !\n", 51, __FUNCTION__ ); fflush(stderr); } while(0);
        exit(-1);
    }
    struct ppnfs_metadata_t* current = ppnfs_metadata_get_root();
    ;
    ;
}

canonical_original_code:
void ppnfs_client_metadata_init()
{
    struct stat st;
    if (stat(ppnfs_metafile, &st) == 0 && st.st_size) {
        ppnfs_metadata_fd = open(ppnfs_metafile, 02);
        if ( ppnfs_metadata_fd == -1 ) {
            do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open '%s' : err=%d:%s\n", 34, __FUNCTION__, ppnfs_metafile, (*__errno_location ()), strerror((*__errno_location ())) ); fflush(stderr); } while(0);
        }
        ppnfs_metadata_size = st.st_size;
        ;
    }
    else {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metafile '%s'\n", 40, __FUNCTION__, ppnfs_metafile ); fflush(stderr); } while(0);
    }
    ;
    ppnfs_metadata = (struct ppnfs_metadata_t *)mmap(((void *)0),
                                                    ppnfs_metadata_size,
                                                    0x1 | 0x2, 0x01,
                                                    ppnfs_metadata_fd, 0);
    if (ppnfs_metadata == ((void *)0) || ppnfs_metadata == ((void *) -1)) {
        do { fprintf(stderr, "ERR" "|" "ppnfs_metadata.c" ":%d:%s|" "Could not open metadata !\n", 51, __FUNCTION__ ); fflush(stderr); } while(0);
        exit(-1);
    }
    struct ppnfs_metadata_t *current = ppnfs_metadata_get_root();
    ;
    ;
}

variable_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 { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
char *__fastcall ppnfs_metadata_find_hash(__int64 a1, unsigned __int64 a2, int a3)
{
char *i; // r12

LABEL_2:
for ( i = ppnfs_metadata_get_root(); i; i = ppnfs_metadata_get(*((_QWORD *)i + 38)) )
{
while ( *(_QWORD *)i <= a2 )
{
if ( *(_QWORD *)i < a2 )
{
i = ppnfs_metadata_get(*((_QWORD *)i + 39));
goto LABEL_2;
}
if ( ppnfs_metadata_equals(i, a1, a3) )
return i;
i = ppnfs_metadata_get(*((_QWORD *)i + 40));
if ( !i )
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, unsigned __int64 a2, int a3)
{
char *i; // r12

LABEL_2:
for ( i = func2(); i; i = func0(*((_QWORD *)i + 38)) )
{
while ( *(_QWORD *)i <= a2 )
{
if ( *(_QWORD *)i < a2 )
{
i = func0(*((_QWORD *)i + 39));
goto LABEL_2;
}
if ( func1(i, a1, a3) )
return i;
i = func0(*((_QWORD *)i + 40));
if ( !i )
return 0LL;
}
}
return 0LL;
}

original_code:
static struct ppnfs_metadata_t*
ppnfs_metadata_find_hash(const char* path, hash_t hash, int path_size)
{
    struct ppnfs_metadata_t* current = ppnfs_metadata_get_root();
    ;
    while (current) {
        ;
        if (hash < current->hash) {
            current = ppnfs_metadata_get(current->left);
            continue;
        }
        if (current->hash < hash) {
            current = ppnfs_metadata_get(current->right);
            continue;
        }
        if (ppnfs_metadata_equals(current, path, path_size)) {
            return current;
        }
        ;
        current = ppnfs_metadata_get(current->collision_next);
    }
    return ((void *)0);
}

canonical_original_code:
static struct ppnfs_metadata_t *ppnfs_metadata_find_hash(char *path, unsigned long long hash, int path_size)
{
    struct ppnfs_metadata_t *current = ppnfs_metadata_get_root();
    ;
    while (current) {
        ;
        if (hash < current->hash) {
            current = ppnfs_metadata_get(current->left);
            continue;
        }
        if (current->hash < hash) {
            current = ppnfs_metadata_get(current->right);
            continue;
        }
        if (ppnfs_metadata_equals(current, path, path_size)) {
            return current;
        }
        ;
        current = ppnfs_metadata_get(current->collision_next);
    }
    return ((void *)0);
}

variable_types:
hash
unsigned long long


decompiled_code:
char *__fastcall ppnfs_metadata_get_child(__int64 a1)
{
__int64 v1; // rdi

v1 = *(_QWORD *)(a1 + 280);
if ( v1 == -1 )
return 0LL;
if ( !v1 )
v1 = 0LL;
return ppnfs_metadata_get(v1);
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
__int64 v1; // rdi

v1 = *(_QWORD *)(a1 + 280);
if ( v1 == -1 )
return 0LL;
if ( !v1 )
v1 = 0LL;
return func0(v1);
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_get_child(struct ppnfs_metadata_t* father)
{
    ppnfs_metadata_id fatherid = father->id;
    struct ppnfs_metadata_t* newmeta = ((void *)0);
    if (father->child == ppnfs_metadata_id_EMPTY) {
        ;
        return ((void *)0);
    } else if (father->child) {
        ;
        return ppnfs_metadata_get(father->child);
    }
    return ppnfs_metadata_get(father->child);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_get_child(struct ppnfs_metadata_t *father)
{
    unsigned long long fatherid = father->id;
    struct ppnfs_metadata_t *newmeta = ((void *)0);
    if (father->child == ppnfs_metadata_id_EMPTY) {
        ;
        return ((void *)0);
    } else if (father->child) {
        ;
        return ppnfs_metadata_get(father->child);
    }
    return ppnfs_metadata_get(father->child);
}

variable_types:
father
struct ppnfs_metadata_t *

variable_types:
fatherid
unsigned long long


decompiled_code:
char *__fastcall ppnfs_metadata_walk_down(char *a1, __int64 a2, int a3)
{
const char *v4; // rbx
__int64 v5; // rax
char v6; // dl
unsigned int v7; // er14
size_t v8; // r13
__int64 v9; // r12
char *v10; // rax
__int64 v11; // rdi
__int64 v12; // r12
int v14; // [rsp+Ch] [rbp-44h]
const char *v15; // [rsp+18h] [rbp-38h]

while ( 1 )
{
v4 = (const char *)(a2 + a3 + 1);
v14 = a3 + 1;
if ( *v4 == 47 || !*v4 )
{
v15 = (const char *)(a2 + a3 + 1);
v7 = 0;
v8 = 0LL;
}
else
{
v5 = 1LL;
do
{
v6 = v4[v5];
v7 = v5;
v8 = v5;
v15 = &v4[v5++];
}
while ( v6 && v6 != 47 );
}
v9 = *((_QWORD *)a1 + 33);
a1 = ppnfs_metadata_get_child((__int64)a1);
if ( !a1 )
return 0LL;
v10 = ppnfs_metadata_get(v9);
v11 = *((_QWORD *)v10 + 34) ? continueHash(*(_QWORD *)v10, "/") : *(_QWORD *)v10;
v12 = continueHashPartial(v11, v4, v7);
while ( *(_QWORD *)a1 != v12 || strncmp(a1 + 8, v4, v8) )
{
a1 = ppnfs_metadata_get(*((_QWORD *)a1 + 36));
if ( !a1 )
return 0LL;
}
if ( !*v15 )
break;
a3 = v14 + v7 + 1;
}
return a1;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_walk_down(struct ppnfs_metadata_t* father,
                         const char* path, int path_size)
{
    const char* rpath = ((void *)0);
    hash_t father_hash, hash;
    int rpath_size;
    ppnfs_metadata_id father_id;
walk_down_start:
    path_size++;
    rpath = &(path[path_size]);
    rpath_size = 0;
    while (rpath[rpath_size] != '\0' && rpath[rpath_size] != '/')
        rpath_size++;
    father_hash = father->hash;
    father_id = father->id;
    hash = 0;
    ;
    struct ppnfs_metadata_t* child = ppnfs_metadata_get_child(father);
    father = ((void *)0);
    if (!child)
        return ((void *)0);
    ;
    father = ppnfs_metadata_get(father_id);
    father_hash = father->father ? continueHash(father->hash, "/") : father->hash;
    hash = continueHashPartial(father_hash, rpath, rpath_size);
    for (; child; child = ppnfs_metadata_get(child->next)) {
        ;
        if (child->hash == hash && strncmp(child->d_name, rpath, rpath_size) == 0) {
            ;
            if (rpath[rpath_size]) {
                ;
                father = child;
                path_size += rpath_size + 1;
                goto walk_down_start;
            }
            return child;
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_walk_down(struct ppnfs_metadata_t *father, char *path, int path_size)
{
    char *rpath = ((void *)0);
    unsigned long long father_hash; unsigned long long hash;
    int rpath_size;
    unsigned long long father_id;
walk_down_start:
    path_size++;
    rpath = &(path[path_size]);
    rpath_size = 0;
    while (rpath[rpath_size] != '\0' && rpath[rpath_size] != '/')
        rpath_size++;
    father_hash = father->hash;
    father_id = father->id;
    hash = 0;
    ;
    struct ppnfs_metadata_t *child = ppnfs_metadata_get_child(father);
    father = ((void *)0);
    if (!child)
        return ((void *)0);
    ;
    father = ppnfs_metadata_get(father_id);
    father_hash = father->father ? continueHash(father->hash, "/") : father->hash;
    hash = continueHashPartial(father_hash, rpath, rpath_size);
    for (; child; child = ppnfs_metadata_get(child->next)) {
        ;
        if (child->hash == hash && strncmp(child->d_name, rpath, rpath_size) == 0) {
            ;
            if (rpath[rpath_size]) {
                ;
                father = child;
                path_size += rpath_size + 1;
                goto walk_down_start;
            }
            return child;
        }
    }
    return ((void *)0);
}

variable_types:
rpath
char *


decompiled_code:
char *__fastcall ppnfs_metadata_find_locked(const char *a1)
{
int v1; // er13
int v2; // er12
unsigned __int64 v3; // rax
char *result; // rax
__int64 v5; // r15
int v6; // ebx
int v7; // er13
const char *i; // r15
char *v9; // rax
unsigned __int64 v10; // rax

v1 = strlen(a1);
v2 = v1;
v3 = doHash(a1);
result = ppnfs_metadata_find_hash((__int64)a1, v3, v1);
if ( !result )
{
if ( v1 )
{
v5 = v1;
v6 = v1;
v7 = v1 - 1;
for ( i = &a1[v5]; ; --i )
{
v2 = v6;
if ( *i == 47 )
{
if ( v6 <= 1 )
break;
v10 = doHashPartial(a1, (unsigned int)v6);
v9 = ppnfs_metadata_find_hash((__int64)a1, v10, v6);
if ( v9 )
goto LABEL_8;
}
else if ( !v7 )
{
v2 = 0;
break;
}
--v7;
--v6;
}
}
v9 = ppnfs_metadata_get_root();
LABEL_8:
result = ppnfs_metadata_walk_down(v9, (__int64)a1, v2);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
int v1; // er13
int v2; // er12
unsigned __int64 v3; // rax
char *result; // rax
__int64 v5; // r15
int v6; // ebx
int v7; // er13
const char *i; // r15
char *v9; // rax
unsigned __int64 v10; // rax

v1 = strlen(a1);
v2 = v1;
v3 = doHash(a1);
result = func4((__int64)a1, v3, v1);
if ( !result )
{
if ( v1 )
{
v5 = v1;
v6 = v1;
v7 = v1 - 1;
for ( i = &a1[v5]; ; --i )
{
v2 = v6;
if ( *i == 47 )
{
if ( v6 <= 1 )
break;
v10 = doHashPartial(a1, (unsigned int)v6);
v9 = func4((__int64)a1, v10, v6);
if ( v9 )
goto LABEL_8;
}
else if ( !v7 )
{
v2 = 0;
break;
}
--v7;
--v6;
}
}
v9 = func2();
LABEL_8:
result = func6(v9, (__int64)a1, v2);
}
return result;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_find_locked(const char* path)
{
    struct ppnfs_metadata_t* metadata;
    int path_size = strlen(path);
    hash_t hash = doHash(path);
    ;
    metadata = ppnfs_metadata_find_hash(path, hash, path_size);
    if (metadata) {
        ;
        return metadata;
    }
    ;
    while (1) {
        while (path_size && path[path_size] != '/') {
            path_size--;
        }
        if (path_size <= 1) {
            metadata = ppnfs_metadata_get_root();
            break;
        }
        hash = doHashPartial(path, path_size);
        metadata = ppnfs_metadata_find_hash(path, hash, path_size);
        if (metadata)
            break;
        path_size--;
    }
    ;
    return ppnfs_metadata_walk_down(metadata, path, path_size);
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_find_locked(char *path)
{
    struct ppnfs_metadata_t *metadata;
    int path_size = strlen(path);
    unsigned long long hash = doHash(path);
    ;
    metadata = ppnfs_metadata_find_hash(path, hash, path_size);
    if (metadata) {
        ;
        return metadata;
    }
    ;
    while (1) {
        while (path_size && path[path_size] != '/') {
            path_size--;
        }
        if (path_size <= 1) {
            metadata = ppnfs_metadata_get_root();
            break;
        }
        hash = doHashPartial(path, path_size);
        metadata = ppnfs_metadata_find_hash(path, hash, path_size);
        if (metadata)
            break;
        path_size--;
    }
    ;
    return ppnfs_metadata_walk_down(metadata, path, path_size);
}

variable_types:
path
char *


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

ppnfs_mutex_lock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
result = ppnfs_metadata_find_locked(a1);
if ( !result )
{
ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
result = 0LL;
}
return result;
}

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

ppnfs_mutex_lock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
result = func7(a1);
if ( !result )
{
ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_find");
result = 0LL;
}
return result;
}

original_code:
struct ppnfs_metadata_t*
ppnfs_metadata_find(const char* path)
{
    struct ppnfs_metadata_t* metadata;
    ppnfs_mutex_lock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    metadata = ppnfs_metadata_find_locked(path);
    if (!metadata)
        ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    return metadata;
}

canonical_original_code:
struct ppnfs_metadata_t *ppnfs_metadata_find(char *path)
{
    struct ppnfs_metadata_t *metadata;
    ppnfs_mutex_lock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    metadata = ppnfs_metadata_find_locked(path);
    if (!metadata)
        ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
    return metadata;
}


decompiled_code:
__int64 ppnfs_metadata_release()
{
return ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_release");
}

canonical_decompiled_code:
__int64 func9()
{
return ppnfs_mutex_unlock(&ppnfs_metadata_mutex, "metadata", "ppnfs_metadata_release");
}

original_code:
void
ppnfs_metadata_release(struct ppnfs_metadata_t* mdata)
{
    (void) mdata;
    ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
}

canonical_original_code:
void ppnfs_metadata_release(struct ppnfs_metadata_t *mdata)
{
    (void) mdata;
    ppnfs_mutex_unlock ( &ppnfs_metadata_mutex, "metadata", __FUNCTION__ );;
}


original_code:
int
ppnfs_metadata_getattr(const char* path, struct stat* stbuf)
{
    struct ppnfs_metadata_t* mdata = ppnfs_metadata_find(path);
    if (!mdata) {
        ;
        return -2;
    }
    ;
    memcpy(stbuf, &(mdata->st), sizeof(struct stat));
    ppnfs_metadata_release(mdata);
    if (((((stbuf->st_mode)) & 0170000) == (0040000)) && stbuf->st_size == 0) {
        stbuf->st_size = 1 << 12;
    }
    return 0;
}

canonical_original_code:
int ppnfs_metadata_getattr(char *path, struct stat *stbuf)
{
    struct ppnfs_metadata_t *mdata = ppnfs_metadata_find(path);
    if (!mdata) {
        ;
        return -2;
    }
    ;
    memcpy(stbuf, &(mdata->st), sizeof(struct stat));
    ppnfs_metadata_release(mdata);
    if (((((stbuf->st_mode)) & 0170000) == (0040000)) && stbuf->st_size == 0) {
        stbuf->st_size = 1 << 12;
    }
    return 0;
}

variable_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 { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *


original_code:
static hash_t
sdbm_hash( hash_t h, const char* str, int sz )
{
    int cur = 0;
    const char* c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

canonical_original_code:
static unsigned long long sdbm_hash(unsigned long long h, char *str, int sz)
{
    int cur = 0;
    char *c;
    unsigned char d;
    for ( c = str ; *c ; c++ ) {
        d = (unsigned char)(*c);
        h = d + (h<<6) + (h<<16) - h;
        cur++;
        if ( cur == sz ) break;
    }
    return h;
}

variable_types:
h
unsigned long long

variable_types:
str
char *

variable_types: sz int

variable_types: cur int

variable_types:
c
char *

variable_types:
d
unsigned char

return_type: unsigned long long


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

result = a1 - 48;
if ( (unsigned __int8)(a1 - 48) > 9u )
{
result = a1 - 87;
if ( (unsigned __int8)(a1 - 97) >= 6u )
result = a1;
}
return result;
}

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

result = a1 - 48;
if ( (unsigned __int8)(a1 - 48) > 9u )
{
result = a1 - 87;
if ( (unsigned __int8)(a1 - 97) >= 6u )
result = a1;
}
return result;
}

original_code:
static char
ppnfs_client_convert(char ch)
{
    if (ch >= '0' && ch <= '9') {
        ch -= '0';
    } else if (ch >= 'a' && ch <= 'f') {
        ch += 0x0a;
        ch -= 'a';
    }
    return ch;
}

variable_types: ch char

return_type: char


continueHashPartial

decompiled_code:
__int64 __fastcall continueHashPartial(__int64 a1, unsigned __int8 *a2, int a3)
{
return sdbm_hash(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 *a2, int a3)
{
return func0(a1, a2, a3);
}

original_code:
hash_t continueHashPartial ( hash_t h, const char* str, int sz )
{
    return sdbm_hash( h, str, sz );
}

canonical_original_code:
unsigned long long continueHashPartial(unsigned long long h, char *str, int sz)
{
    return sdbm_hash( h, str, sz );
}


continueHash

decompiled_code:
__int64 __fastcall continueHash(__int64 a1, unsigned __int8 *a2)
{
return continueHashPartial(a1, a2, -1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 *a2)
{
return func2(a1, a2, -1);
}

original_code:
hash_t continueHash ( hash_t h, const char* str )
{
    return continueHashPartial ( h, str, ~((int)0) );
}

canonical_original_code:
unsigned long long continueHash(unsigned long long h, char *str)
{
    return continueHashPartial ( h, str, ~((int)0) );
}


doHashPartial

decompiled_code:
__int64 __fastcall doHashPartial(unsigned __int8 *a1, int a2)
{
return continueHashPartial(581LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, int a2)
{
return func2(581LL, a1, a2);
}

original_code:
hash_t doHashPartial ( const char* str, int sz )
{
    hash_t h = 0x245;
    return continueHashPartial ( h, str, sz );
}

canonical_original_code:
unsigned long long doHashPartial(char *str, int sz)
{
    unsigned long long h = 0x245;
    return continueHashPartial ( h, str, sz );
}


doHash

decompiled_code:
__int64 __fastcall doHash(unsigned __int8 *a1)
{
return doHashPartial(a1, -1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
return func4(a1, -1);
}

original_code:
hash_t doHash ( const char* str )
{
    return doHashPartial ( str, ~((int)0) );
}

canonical_original_code:
unsigned long long doHash(char *str)
{
    return doHashPartial ( str, ~((int)0) );
}


groupStr

decompiled_code:
size_t __fastcall groupStr(__int64 a1, char *a2)
{
char *v3; // r12
size_t result; // rax
unsigned __int64 v5; // rax
unsigned int v6; // edi
char v7; // al
unsigned int v8; // edi
char v9; // bl

v3 = a2;
result = strlen(a2);
if ( (result & 1) == 0 )
goto LABEL_6;
v5 = (unsigned __int64)&a2[result - 1];
if ( (unsigned __int64)a2 <= v5 )
memmove(a2 + 1, a2, v5 - (_QWORD)a2 + 1);
*a2 = 48;
v6 = 48;
do
{
v7 = ppnfs_client_convert(v6);
v8 = v3[1];
++a1;
v3 += 2;
v9 = v7;
result = ppnfs_client_convert(v8);
*(_BYTE *)(a1 - 1) = result + 16 * v9;
LABEL_6:
v6 = *v3;
}
while ( *v3 );
return result;
}

canonical_decompiled_code:
size_t __fastcall func6(__int64 a1, char *a2)
{
char *v3; // r12
size_t result; // rax
unsigned __int64 v5; // rax
unsigned int v6; // edi
char v7; // al
unsigned int v8; // edi
char v9; // bl

v3 = a2;
result = strlen(a2);
if ( (result & 1) == 0 )
goto LABEL_6;
v5 = (unsigned __int64)&a2[result - 1];
if ( (unsigned __int64)a2 <= v5 )
memmove(a2 + 1, a2, v5 - (_QWORD)a2 + 1);
*a2 = 48;
v6 = 48;
do
{
v7 = func1(v6);
v8 = v3[1];
++a1;
v3 += 2;
v9 = v7;
result = func1(v8);
*(_BYTE *)(a1 - 1) = result + 16 * v9;
LABEL_6:
v6 = *v3;
}
while ( *v3 );
return result;
}

original_code:
void groupStr(char *dest, char *src)
{
    char high, low;
    char *p;
    char *q;
    size_t len = strlen(src);
    int i;
    if ((len % 2) != 0) {
        p = src + len -1;
        q = src + len;
        while (p >= src) {
            *q-- = *p--;
        }
        *src = '0';
    }
    p = dest;
    q = src;
    while (*q) {
        high = ppnfs_client_convert(*q++);
        low = ppnfs_client_convert(*q++);
        *p++ = (high << 4) + low;
    }
}

canonical_original_code:
void groupStr(char *dest, char *src)
{
    char high; char low;
    char *p;
    char *q;
    unsigned long len = strlen(src);
    int i;
    if ((len % 2) != 0) {
        p = src + len -1;
        q = src + len;
        while (p >= src) {
            *q-- = *p--;
        }
        *src = '0';
    }
    p = dest;
    q = src;
    while (*q) {
        high = ppnfs_client_convert(*q++);
        low = ppnfs_client_convert(*q++);
        *p++ = (high << 4) + low;
    }
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: high char

variable_types: low char

variable_types:
p
char *

variable_types:
q
char *

variable_types:
len
unsigned long

variable_types: i int


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
bool __fastcall ppnfs_mutex_init(pthread_mutex_t *a1)
{
bool result; // al
char *v2; // rax
pthread_mutexattr_t attr; // [rsp+18h] [rbp-8h] BYREF
int errnum; // [rsp+1Ch] [rbp-4h]

pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, 2);
errnum = pthread_mutex_init(a1, &attr);
result = errnum != 0;
if ( errnum )
{
v2 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not init mutex : err=%d:%s\n",
25LL,
"ppnfs_mutex_init",
(unsigned int)errnum,
v2);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(pthread_mutex_t *a1)
{
bool result; // al
char *v2; // rax
pthread_mutexattr_t attr; // [rsp+18h] [rbp-8h] BYREF
int errnum; // [rsp+1Ch] [rbp-4h]

pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, 2);
errnum = pthread_mutex_init(a1, &attr);
result = errnum != 0;
if ( errnum )
{
v2 = strerror(errnum);
fprintf(
stdout,
"BUG|ppnfs_mutex.cc:%d:%s|Could not init mutex : err=%d:%s\n",
25LL,
"ppnfs_mutex_init",
(unsigned int)errnum,
v2);
fflush(stdout);
result = 0;
*(_BYTE *)ppnfs_mutex_init = 0;
}
return result;
}

original_code:
void
ppnfs_mutex_init(struct ppnfs_mutex_t* mutex)
{
    int res;
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
    if ((res = pthread_mutex_init(&(mutex->mutex), &attr)) != 0)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not init mutex : err=%d:%s\n", 24, __FUNCTION__, res, strerror(res) ); fflush(stderr); } while(0); ((char*)((void *)0))[0] = 0; } while(0);
    }
}

canonical_original_code:
void ppnfs_mutex_init(struct ppnfs_mutex_t *mutex)
{
    int res;
    union pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
    if ((res = pthread_mutex_init(&(mutex->mutex), &attr)) != 0)
    {
        do { do { fprintf(stderr, "BUG" "|" "ppnfs_mutex.c" ":%d:%s|" "Could not init mutex : err=%d:%s\n", 24, __FUNCTION__, res, strerror(res) ); fflush(stderr); } while(0); ((char *)((void *)0))[0] = 0; } while(0);
    }
}

variable_types: struct ppnfs_mutex_t { 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; } mutex; unsigned long owner; char *context; } *

variable_types: res int

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct ppnfs_mutex_t { union pthread_mutex_t mutex; unsigned long owner; char *context; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; 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; }