original_code:
int request_analysis(int client_fd,char* buffer,char func[],char arguments[][100]){
 int n=0;
 int i=0;
 int j=0;
 int sock_stat = 0;
 char request[10];
 char tm[20];
 sock_stat = recv(client_fd,buffer,4096,0);
 if(sock_stat<0){
  printf("request_analysis recv package error! \n");
  return -1;
 }
 else if(sock_stat==0){
  return 0;
 }
 while(buffer[n]!=';'){
  request[n] = buffer[n];
  n++;
 }
 request[n+1] = '\0';
 if(strncmp(request,"request",7)==0){
  n++;
  i=0;
  while(buffer[n]!=';'){
   func[i] = buffer[n];
   n++;
   i++;
  }
  func[i] = '\0';
  n++;
  i=0;
  j=0;
  while(buffer[n]!='|'){
   if(buffer[n]==';'){
    arguments[j][i] = '\0';
    i=0;
    j++;
    n++;
   }
   else{
    arguments[j][i] = buffer[n];
    n++;
    i++;
   }
  }
  arguments[j][i] = '\0';
 }
 return sock_stat;
}

canonical_original_code:
int request_analysis(int client_fd, char *buffer, char func[], char arguments[][100]){
 int n = 0;
 int i = 0;
 int j = 0;
 int sock_stat = 0;
 char request[10];
 char tm[20];
 sock_stat = recv(client_fd,buffer,4096,0);
 if(sock_stat<0){
  printf("request_analysis recv package error! \n");
  return -1;
 }
 else if(sock_stat==0){
  return 0;
 }
 while(buffer[n]!=';'){
  request[n] = buffer[n];
  n++;
 }
 request[n+1] = '\0';
 if(strncmp(request,"request",7)==0){
  n++;
  i=0;
  while(buffer[n]!=';'){
   func[i] = buffer[n];
   n++;
   i++;
  }
  func[i] = '\0';
  n++;
  i=0;
  j=0;
  while(buffer[n]!='|'){
   if(buffer[n]==';'){
    arguments[j][i] = '\0';
    i=0;
    j++;
    n++;
   }
   else{
    arguments[j][i] = buffer[n];
    n++;
    i++;
   }
  }
  arguments[j][i] = '\0';
 }
 return sock_stat;
}

variable_types:
buffer
char *

variable_types:
func
char []

variable_types:
arguments
char [][100]

variable_types: n int

variable_types: i int

variable_types: j int

variable_types:
request
char [10]

variable_types:
tm
char [20]


decompiled_code:
__int64 __fastcall init_data_connection(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
struct sockaddr in[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&in[0].sa_family = a1;
*(_QWORD *)&in[0].sa_data[6] = a2;
v2 = socket(2, 1, 0);
*(_WORD *)in[0].sa_data = _bswap_16_constprop_0(2LL, 1LL);
v3 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
printf("%s require data connection at port: %d\n", (const char *)v3, *(unsigned __int16 *)in[0].sa_data);
sleep(1u);
if ( connect(v2, in, 0x10u) == -1 )
{
v2 = -1;
puts("can not connect to the client ");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
struct sockaddr in[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&in[0].sa_family = a1;
*(_QWORD *)&in[0].sa_data[6] = a2;
v2 = socket(2, 1, 0);
*(_WORD *)in[0].sa_data = func0(2LL, 1LL);
v3 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
printf("%s require data connection at port: %d\n", (const char *)v3, *(unsigned __int16 *)in[0].sa_data);
sleep(1u);
if ( connect(v2, in, 0x10u) == -1 )
{
v2 = -1;
puts("can not connect to the client ");
}
return v2;
}

original_code:
int init_data_connection(struct sockaddr_in client_addr)
{
 int client_recv_fd;
 client_recv_fd = socket(2,SOCK_STREAM,0);
 client_addr.sin_port=htons(30667);
 printf("%s require data connection at port: %d\n",inet_ntoa(client_addr.sin_addr.s_addr),client_addr.sin_port);
 sleep(1);
 if(connect(client_recv_fd,(struct sockaddr *) &client_addr,sizeof(client_addr))==-1){
  printf("can not connect to the client \n");
  return -1;
 }
 return client_recv_fd;
}

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

return_type: int

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

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


SendFileNames

decompiled_code:
__int64 __fastcall SendFileNames(int fd, void *buf, __int64 a3)
{
unsigned int v3; // er12
size_t v5; // rax
_QWORD *i; // rbx
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
size_t v11; // rax
size_t v12; // rax
char v13[248]; // [rsp+0h] [rbp-F8h] BYREF

v3 = 0;
v5 = strlen((const char *)buf);
memset(buf, 0, v5);
for ( i = *(_QWORD **)(a3 + 16); i; i = (_QWORD *)i[2] )
{
while ( 1 )
{
sprintf(
v13,
"%d<%s<%d/",
(*(_DWORD *)(i[1] + 24LL) & 0xF000) == 0x4000,
(const char *)(*i + 19LL),
*(_QWORD *)(i[1] + 48LL));
v7 = strlen((const char *)buf);
v8 = stpcpy((char *)buf + v7, v13) - (_BYTE *)buf;
if ( v8 > 0xBFF )
break;
i = (_QWORD *)i[2];
if ( !i )
goto LABEL_7;
}
v3 += send(fd, buf, v8, 0);
if ( v3 == -1 )
goto LABEL_11;
v9 = strlen((const char *)buf);
memset(buf, 0, v9);
}
LABEL_7:
if ( *(_BYTE *)buf )
{
v11 = strlen((const char *)buf);
v3 += send(fd, buf, v11, 0);
if ( v3 != -1 )
{
v12 = strlen((const char *)buf);
memset(buf, 0, v12);
return v3;
}
LABEL_11:
v3 = -1;
puts("send error ");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, void *buf, __int64 a3)
{
unsigned int v3; // er12
size_t v5; // rax
_QWORD *i; // rbx
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
size_t v11; // rax
size_t v12; // rax
char v13[248]; // [rsp+0h] [rbp-F8h] BYREF

v3 = 0;
v5 = strlen((const char *)buf);
memset(buf, 0, v5);
for ( i = *(_QWORD **)(a3 + 16); i; i = (_QWORD *)i[2] )
{
while ( 1 )
{
sprintf(
v13,
"%d<%s<%d/",
(*(_DWORD *)(i[1] + 24LL) & 0xF000) == 0x4000,
(const char *)(*i + 19LL),
*(_QWORD *)(i[1] + 48LL));
v7 = strlen((const char *)buf);
v8 = stpcpy((char *)buf + v7, v13) - (_BYTE *)buf;
if ( v8 > 0xBFF )
break;
i = (_QWORD *)i[2];
if ( !i )
goto LABEL_7;
}
v3 += send(fd, buf, v8, 0);
if ( v3 == -1 )
goto LABEL_11;
v9 = strlen((const char *)buf);
memset(buf, 0, v9);
}
LABEL_7:
if ( *(_BYTE *)buf )
{
v11 = strlen((const char *)buf);
v3 += send(fd, buf, v11, 0);
if ( v3 != -1 )
{
v12 = strlen((const char *)buf);
memset(buf, 0, v12);
return v3;
}
LABEL_11:
v3 = -1;
puts("send error ");
}
return v3;
}

original_code:
int SendFileNames(int client_data_channel_fd,char * buffer,struct file_list * pfile)
{
 int bytes_send = 0;
 char tem_str[200];
 memset(buffer,'\0',strlen(buffer));
 while(pfile->next_file != ((void *)0)){
  pfile = pfile->next_file;
  sprintf(tem_str,"%d<%s<%d/",((((pfile->file_stat->st_mode)) & 0170000) == (0040000)),pfile->file->d_name,pfile->file_stat->st_size);
  strcat(buffer,tem_str);
  if(strlen(buffer) >= 3072){
   if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
   {
    printf("send error \n");
    return -1;
      }
   memset(buffer,'\0',strlen(buffer));
  }
 }
 if(strlen(buffer)>0){
  if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
  {
   printf("send error \n");
   return -1;
     }
  memset(buffer,'\0',strlen(buffer));
 }
 return bytes_send;
}

canonical_original_code:
int SendFileNames(int client_data_channel_fd, char *buffer, struct file_list *pfile)
{
 int bytes_send = 0;
 char tem_str[200];
 memset(buffer,'\0',strlen(buffer));
 while(pfile->next_file != ((void *)0)){
  pfile = pfile->next_file;
  sprintf(tem_str,"%d<%s<%d/",((((pfile->file_stat->st_mode)) & 0170000) == (0040000)),pfile->file->d_name,pfile->file_stat->st_size);
  strcat(buffer,tem_str);
  if(strlen(buffer) >= 3072){
   if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
   {
    printf("send error \n");
    return -1;
      }
   memset(buffer,'\0',strlen(buffer));
  }
 }
 if(strlen(buffer)>0){
  if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
  {
   printf("send error \n");
   return -1;
     }
  memset(buffer,'\0',strlen(buffer));
 }
 return bytes_send;
}

variable_types: struct file_list { struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *file; 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]; } *file_stat; struct file_list *next_file; } *

user_defined_types: struct file_list { struct dirent *file; struct stat *file_stat; struct file_list *next_file; }

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


GetDirContent

decompiled_code:
__int64 __fastcall GetDirContent(int fd, void *buf, const char *a3, __int64 a4, __int64 a5)
{
_QWORD *v7; // rax
void *v8; // r12
int v9; // er14
unsigned int v10; // eax
unsigned int v11; // er13
char v13[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v13, "%s%s", root_directory, a3);
v7 = get_file_list(v13);
if ( !v7 )
{
strcpy((char *)buf, "error;1001|");
if ( send(fd, buf, 0x1000uLL, 0) != -1 )
return (unsigned int)-1;
LABEL_10:
puts("send error");
exit(1);
}
v8 = v7;
strcpy((char *)buf + 16, "t|");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC13);
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
goto LABEL_10;
v9 = init_data_connection(a4, a5);
v10 = SendFileNames(v9, buf, (__int64)v8);
v11 = v10;
if ( v10 == -1 )
{
puts("SendFileNames send package failed!");
}
else
{
v11 = 1;
printf("%d bytes sended \n", v10);
close(v9);
}
free_file_list(v8);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, const char *a3, __int64 a4, __int64 a5)
{
_QWORD *v7; // rax
void *v8; // r12
int v9; // er14
unsigned int v10; // eax
unsigned int v11; // er13
char v13[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v13, "%s%s", root_directory, a3);
v7 = get_file_list(v13);
if ( !v7 )
{
strcpy((char *)buf, "error;1001|");
if ( send(fd, buf, 0x1000uLL, 0) != -1 )
return (unsigned int)-1;
LABEL_10:
puts("send error");
exit(1);
}
v8 = v7;
strcpy((char *)buf + 16, "t|");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC13);
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
goto LABEL_10;
v9 = func2(a4, a5);
v10 = func4(v9, buf, (__int64)v8);
v11 = v10;
if ( v10 == -1 )
{
puts("SendFileNames send package failed!");
}
else
{
v11 = 1;
printf("%d bytes sended \n", v10);
close(v9);
}
func3(v8);
return v11;
}

original_code:
int GetDirContent(int client_fd,char* buffer,char* directory,struct sockaddr_in client_addr)
{
 int bytes_send = 0;
 char abs_dir[100];
 int client_data_channel_fd;
 struct file_list * files_head = ((void *)0);
 sprintf(abs_dir,"%s%s",root_directory,directory);
 files_head = get_file_list(abs_dir);
 if(files_head != ((void *)0)){
  sprintf(buffer,"ack;rcvdircontent|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
   printf("send error\n");
   exit(1);
  }
 }
 else{
  sprintf(buffer,"error;1001|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
     printf("send error\n");
     exit(1);
  }
  return -1;
 }
 client_data_channel_fd = init_data_connection(client_addr);
 if((bytes_send = SendFileNames(client_data_channel_fd,buffer,files_head)) == -1){
  printf("SendFileNames send package failed!\n");
  free_file_list(files_head);
  return -1;
 }
 printf("%d bytes sended \n",bytes_send);
 close(client_data_channel_fd);
  free_file_list(files_head);
 return 1;
}

canonical_original_code:
int GetDirContent(int client_fd, char *buffer, char *directory, struct sockaddr_in client_addr)
{
 int bytes_send = 0;
 char abs_dir[100];
 int client_data_channel_fd;
 struct file_list *files_head = ((void *)0);
 sprintf(abs_dir,"%s%s",root_directory,directory);
 files_head = get_file_list(abs_dir);
 if(files_head != ((void *)0)){
  sprintf(buffer,"ack;rcvdircontent|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
   printf("send error\n");
   exit(1);
  }
 }
 else{
  sprintf(buffer,"error;1001|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
     printf("send error\n");
     exit(1);
  }
  return -1;
 }
 client_data_channel_fd = init_data_connection(client_addr);
 if((bytes_send = SendFileNames(client_data_channel_fd,buffer,files_head)) == -1){
  printf("SendFileNames send package failed!\n");
  free_file_list(files_head);
  return -1;
 }
 printf("%d bytes sended \n",bytes_send);
 close(client_data_channel_fd);
  free_file_list(files_head);
 return 1;
}

variable_types:
directory
char *

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }

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


ChangeDirectory

decompiled_code:
__int64 __fastcall ChangeDirectory(int fd, void *buf, const char *a3, const char *a4)
{
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v5, "%s%s%s", root_directory, a3, a4);
if ( opendir(v5) )
{
strcpy((char *)buf + 16, "nged|");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC15);
if ( send(fd, buf, 0x1000uLL, 0) != -1 )
return 1LL;
LABEL_6:
puts("send error");
exit(1);
}
strcpy((char *)buf, "error;1002|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
goto LABEL_6;
closedir(0LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, void *buf, const char *a3, const char *a4)
{
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v5, "%s%s%s", root_directory, a3, a4);
if ( opendir(v5) )
{
strcpy((char *)buf + 16, "nged|");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC15);
if ( send(fd, buf, 0x1000uLL, 0) != -1 )
return 1LL;
LABEL_6:
puts("send error");
exit(1);
}
strcpy((char *)buf, "error;1002|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
goto LABEL_6;
closedir(0LL);
return 0xFFFFFFFFLL;
}

original_code:
int ChangeDirectory(int server_fd,char new_dir[])
{
 char response_type[20];
 char response_argu[20];
 memset(buffer,1048576,'\0');
 sprintf(buffer,"request;changedirectory;%s;%s|",current_directory,new_dir);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
  return -1;
 }
 memset(buffer,1048576,'\0');
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
  printf("the directory don't exist\n");
  return -1;
 }
 strcat(current_directory,new_dir);
 current_directory[strlen(current_directory)] = '/';
 current_directory[strlen(current_directory)+1] = '\0';
 printf("directory changed\n");
 return 1;
}

canonical_original_code:
int ChangeDirectory(int server_fd, char new_dir[])
{
 char response_type[20];
 char response_argu[20];
 memset(buffer,1048576,'\0');
 sprintf(buffer,"request;changedirectory;%s;%s|",current_directory,new_dir);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
  return -1;
 }
 memset(buffer,1048576,'\0');
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
  printf("the directory don't exist\n");
  return -1;
 }
 strcat(current_directory,new_dir);
 current_directory[strlen(current_directory)] = '/';
 current_directory[strlen(current_directory)+1] = '\0';
 printf("directory changed\n");
 return 1;
}


session

original_code:
void session(struct sockaddr_sockfd* client_addr_fd)
{
 int n = 1;
 char func[20];
 int client_fd = 0 ;
 char arguments[5][100];
 char buffer[4096];
 client_fd = client_addr_fd->socket_fd;
 struct sockaddr_in client_addr;
 memcpy(&client_addr,&(client_addr_fd->socket_addr),sizeof(client_addr_fd->socket_addr));
 printf("get connection with:%s at port: %d\n",inet_ntoa(client_addr.sin_addr.s_addr),client_addr.sin_port);
 while(request_analysis(client_fd,buffer,func,arguments)>0){
  printf("%s execute command:%s\targu[0]:%s\targu[1]:%s\taru[2]:%s \n",inet_ntoa(client_addr.sin_addr.s_addr),func,arguments[0],arguments[1],arguments[2]);
  if(strcmp(func,"downloadfile")==0){
   DownloadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"uploadfile")==0){
   UploadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"querydircontent")==0){
   GetDirContent(client_fd,buffer,arguments[0],client_addr);
  }
  else if(strcmp(func,"rename")==0){
  }
  else if(strcmp(func,"deletefile")==0){
  }
  else if(strcmp(func,"changedirectory")==0){
   ChangeDirectory(client_fd,buffer,arguments[0],arguments[1]);
  }
 }
 printf("%s disconnected \n",inet_ntoa(client_addr.sin_addr.s_addr));
 close(client_fd);
 return;
}

canonical_original_code:
void session(struct sockaddr_sockfd *client_addr_fd)
{
 int n = 1;
 char func[20];
 int client_fd = 0;
 char arguments[5][100];
 char buffer[4096];
 client_fd = client_addr_fd->socket_fd;
 struct sockaddr_in client_addr;
 memcpy(&client_addr,&(client_addr_fd->socket_addr),sizeof(client_addr_fd->socket_addr));
 printf("get connection with:%s at port: %d\n",inet_ntoa(client_addr.sin_addr.s_addr),client_addr.sin_port);
 while(request_analysis(client_fd,buffer,func,arguments)>0){
  printf("%s execute command:%s\targu[0]:%s\targu[1]:%s\taru[2]:%s \n",inet_ntoa(client_addr.sin_addr.s_addr),func,arguments[0],arguments[1],arguments[2]);
  if(strcmp(func,"downloadfile")==0){
   DownloadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"uploadfile")==0){
   UploadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"querydircontent")==0){
   GetDirContent(client_fd,buffer,arguments[0],client_addr);
  }
  else if(strcmp(func,"rename")==0){
  }
  else if(strcmp(func,"deletefile")==0){
  }
  else if(strcmp(func,"changedirectory")==0){
   ChangeDirectory(client_fd,buffer,arguments[0],arguments[1]);
  }
 }
 printf("%s disconnected \n",inet_ntoa(client_addr.sin_addr.s_addr));
 close(client_fd);
 return;
}

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

variable_types:
func
char [20]

variable_types:
arguments
char [5][100]

variable_types:
buffer
char [4096]

return_type: void

user_defined_types: struct sockaddr_sockfd { int socket_fd; struct sockaddr_in socket_addr; }


decompiled_code:
void test_glob()
{
glob_t v0; // [rsp+0h] [rbp-58h] BYREF

*(_OWORD *)&v0.gl_pathc = 0LL;
*(_OWORD *)&v0.gl_offs = 0LL;
*(_OWORD *)&v0.gl_closedir = 0LL;
*(_OWORD *)&v0.gl_opendir = 0LL;
v0.gl_stat = 0LL;
glob("/dev/sd*", 0, 0LL, &v0);
globfree(&v0);
}

canonical_decompiled_code:
void func7()
{
glob_t v0; // [rsp+0h] [rbp-58h] BYREF

*(_OWORD *)&v0.gl_pathc = 0LL;
*(_OWORD *)&v0.gl_offs = 0LL;
*(_OWORD *)&v0.gl_closedir = 0LL;
*(_OWORD *)&v0.gl_opendir = 0LL;
v0.gl_stat = 0LL;
glob("/dev/sd*", 0, 0LL, &v0);
globfree(&v0);
}

original_code:
void test_glob(void)
{
 glob_t globbuf = {
  .gl_pathc = 0,
  .gl_pathv = ((void *)0),
  .gl_offs = 0};
 glob("/dev/sd*", 0, ((void *)0), &globbuf);
 globfree(&globbuf);
}

canonical_original_code:
void test_glob()
{
 struct glob_t globbuf = {
  .gl_pathc = 0,
  .gl_pathv = ((void *)0),
  .gl_offs = 0};
 glob("/dev/sd*", 0, ((void *)0), &globbuf);
 globfree(&globbuf);
}

variable_types: struct glob_t { unsigned long gl_pathc; char **gl_pathv; unsigned long gl_offs; int gl_flags; void (*gl_closedir)(void *); void *(*gl_readdir)(void *); void *(*gl_opendir)(char *); int (*gl_lstat)(char *, void *); int (*gl_stat)(char *, void *); }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // r12
char *v5; // rbp

v3 = strdup("hello0");
v4 = strdup("hello1");
v5 = strdup("hello2");
puts(v3);
puts(v4);
puts(v5);
test_glob(v5, argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // r12
char *v5; // rbp

v3 = strdup("hello0");
v4 = strdup("hello1");
v5 = strdup("hello2");
puts(v3);
puts(v4);
puts(v5);
func7(v5, argv);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int i;
 struct test_s ttt = {0};
 ttt.list = calloc(10, sizeof(char **));
 ttt.count = 3;
 ttt.list[0] = strdup("hello0");
 ttt.list[1] = strdup("hello1");
 ttt.list[2] = strdup("hello2");
 for (i=0; i<ttt.count; i++) {
  printf("%s\n", ttt.list[i]);
 }
 test_glob();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct test_s { char **list; int count; }


memalign

decompiled_code:
__int64 __fastcall memalign(__int64 a1, __int64 a2)
{
return (-a2 & a1) + a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
return (-a2 & a1) + a2;
}

original_code:
static void *memalign(void *p, unsigned long align_size)
{
 return (void *)(((unsigned long)p & ~(align_size-1)) + align_size);
}

variable_types:
p
void *

return_type: void *


routine

decompiled_code:
void *__fastcall routine(void *a1)
{
unsigned int *v1; // rbp
int v2; // er13
unsigned int v3; // ebx
void *v4; // rax
void *v5; // r12
size_t v6; // rdx
int v7; // ebx
int *v8; // rbx
char *v9; // rax
int *v11; // rbx
char *v12; // rax

v1 = *(unsigned int **)a1;
v2 = *((_DWORD *)a1 + 2);
v3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
v4 = malloc(2 * v3);
if ( v4 )
{
v5 = (void *)memalign((__int64)v4, v3);
memset(v5, 97, v6);
lseek(v2, v1[3], 0);
if ( (int)v1[2] > 0 )
{
v7 = 0;
while ( (int)write(v2, v5, v1[1]) >= 0 )
{
if ( (int)v1[2] <= ++v7 )
goto LABEL_7;
}
v8 = __errno_location();
v9 = strerror(*v8);
printf("Can not write to file.(%d)%s\n", (unsigned int)*v8, v9);
}
}
else
{
v11 = __errno_location();
v12 = strerror(*v11);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v11, v12);
}
LABEL_7:
puts("thread exit.");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
unsigned int *v1; // rbp
int v2; // er13
unsigned int v3; // ebx
void *v4; // rax
void *v5; // r12
size_t v6; // rdx
int v7; // ebx
int *v8; // rbx
char *v9; // rax
int *v11; // rbx
char *v12; // rax

v1 = *(unsigned int **)a1;
v2 = *((_DWORD *)a1 + 2);
v3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
v4 = malloc(2 * v3);
if ( v4 )
{
v5 = (void *)func7((__int64)v4, v3);
memset(v5, 97, v6);
lseek(v2, v1[3], 0);
if ( (int)v1[2] > 0 )
{
v7 = 0;
while ( (int)write(v2, v5, v1[1]) >= 0 )
{
if ( (int)v1[2] <= ++v7 )
goto LABEL_7;
}
v8 = __errno_location();
v9 = strerror(*v8);
printf("Can not write to file.(%d)%s\n", (unsigned int)*v8, v9);
}
}
else
{
v11 = __errno_location();
v12 = strerror(*v11);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v11, v12);
}
LABEL_7:
puts("thread exit.");
return 0LL;
}

original_code:
void *routine(void *arg)
{
 struct thread_info *th_info = (struct thread_info *)arg;
 struct options *opts = th_info->opts;
 int fd = th_info->fd;
 char *buf = ((void *)0);
 int i, ret;
 off_t cur_size = 0;
 buf = malloc(opts->block_size*2);
 if (buf == ((void *)0) || th_info == ((void *)0)) {
  printf("Can not alloc mem.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 buf = (char *)memalign((void *)buf, opts->block_size);
 memset(buf, 'a', opts->block_size);
 lseek(fd, opts->file_pos, 0);
 for (i=0; i<opts->block_count; i++){
  ret = write(fd, buf, opts->block_size);
  if (ret < 0) {
   printf("Can not write to file.(%d)%s\n",
    (*__errno_location ()), strerror((*__errno_location ())));
   goto out;
  }
  cur_size+=ret;
 }
out:
 printf("thread exit.\n");
 return ((void *)0);
}

canonical_original_code:
void *routine(void *arg)
{
 struct thread_info *th_info = (struct thread_info *)arg;
 struct options *opts = th_info->opts;
 int fd = th_info->fd;
 char *buf = ((void *)0);
 int i; int ret;
 long cur_size = 0;
 buf = malloc(opts->block_size*2);
 if (buf == ((void *)0) || th_info == ((void *)0)) {
  printf("Can not alloc mem.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 buf = (char *)memalign((void *)buf, opts->block_size);
 memset(buf, 'a', opts->block_size);
 lseek(fd, opts->file_pos, 0);
 for (i=0; i<opts->block_count; i++){
  ret = write(fd, buf, opts->block_size);
  if (ret < 0) {
   printf("Can not write to file.(%d)%s\n",
    (*__errno_location ()), strerror((*__errno_location ())));
   goto out;
  }
  cur_size+=ret;
 }
out:
 printf("thread exit.\n");
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct thread_info { struct options { int mode; unsigned int block_size; int block_count; unsigned int file_pos; char *filepath; } *opts; int fd; } *

variable_types: fd int

variable_types:
buf
char *

variable_types: ret int

user_defined_types: struct thread_info { struct options *opts; int fd; }


controler

decompiled_code:
__int64 controler()
{
int *v1; // rbx
char *v2; // rax

if ( calloc(1uLL, 0x200uLL) )
return 0LL;
v1 = __errno_location();
v2 = strerror(*v1);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func9()
{
int *v1; // rbx
char *v2; // rax

if ( calloc(1uLL, 0x200uLL) )
return 0LL;
v1 = __errno_location();
v2 = strerror(*v1);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

original_code:
int controler(int fd)
{
 char *buf = ((void *)0);
 int ret;
 int i;
 buf = calloc(1, 512);
 if (buf == ((void *)0)) {
  printf("Can not alloc mem.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 memset(buf, 'b', 512);
 for (i=0; i<0; i++) {
  printf("input to continue:");
  getchar();
  ret = write(fd, buf, 512);
  if (ret < 0) {
   printf("Can not write to file.(%d)%s\n",
    (*__errno_location ()), strerror((*__errno_location ())));
   goto failed;
  }
  printf("write finished.\n");
 }
 return 0;
failed:
 return -1;
}

variable_types: i int


getfd

decompiled_code:
int __fastcall getfd(__int64 a1)
{
return open(*(const char **)(a1 + 16), 16450, 420LL);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
return open(*(const char **)(a1 + 16), 16450, 420LL);
}

original_code:
int getfd(struct options *opts)
{
 return open(opts->filepath, (02|0100|040000), 0644);
}

variable_types: struct options { int mode; unsigned int block_size; int block_count; unsigned int file_pos; char *filepath; } *


original_code:
int parse_args(int argc, char *argv[], struct options *opts)
{
 int i;
 memset(opts, '\0', sizeof(*opts));
 opts->block_size = 4096;
 opts->block_count = 1024;
 opts->file_pos = 512;
 for (i=1; i<argc; i++) {
  if (strcmp(argv[i], "-d") == 0) {
   opts->mode |= 040000;
  } else if (strcmp(argv[i], "-a") == 0) {
   opts->mode |= 02000;
  } else if (strcmp(argv[i], "-b") == 0) {
   if (i == argc-1) {
    printf("missing args for -b\n");
    goto failed;
   }
   i++;
   opts->block_size = atol(argv[i]);
  } else if(strcmp(argv[i], "-c") == 0) {
   if (i == argc-1) {
    printf("missing args for -c\n");
    goto failed;
   }
   i++;
   opts->block_count = atol(argv[i]);
  } else {
   if (!opts->filepath)
    opts->filepath = strdup(argv[i]);
  }
 }
 if (!opts->filepath) {
  printf("provide a file path\n");
  goto failed;
 }
 return 0;
failed:
 return 1;
}

user_defined_types: struct options { int mode; unsigned int block_size; int block_count; unsigned int file_pos; char *filepath; }


decompiled_code:
__off_t __fastcall file_size(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (int)fstat(a1, &v2) < 0 )
result = -1LL;
else
result = v2.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func7(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (int)func15(a1, &v2) < 0 )
result = -1LL;
else
result = v2.st_size;
return result;
}

original_code:
off_t file_size(int fd)
{
 struct stat stbuff;
 if (fstat(fd, &stbuff) < 0)
  return -1;
 return stbuff.st_size;
}

canonical_original_code:
long file_size(int fd)
{
 struct stat stbuff;
 if (fstat(fd, &stbuff) < 0)
  return -1;
 return stbuff.st_size;
}

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

return_type: long


decompiled_code:
__int64 __fastcall file_check(int fd, __off_t a2, __off_t a3, __int64 a4, __int64 a5)
{
__int64 result; // rax

if ( a3 > a2 && (unsigned int)_file_check_gap(fd, a2, a3 - a2) )
result = 1LL;
else
result = _file_check_data(fd, a3, a4 - a3, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, __off_t a2, __off_t a3, __int64 a4, __int64 a5)
{
__int64 result; // rax

if ( a3 > a2 && (unsigned int)func8(fd, a2, a3 - a2) )
result = 1LL;
else
result = func9(fd, a3, a4 - a3, a5);
return result;
}

original_code:
int file_check(int fd, off_t pos1, off_t pos2, off_t pos3, char *data)
{
 int ret = 1;
 if (pos2 > pos1)
  if (__file_check_gap(fd, pos1, pos2-pos1))
   goto out;
 ret = __file_check_data(fd, pos2, pos3-pos2, data);
out:
 return ret;
}

canonical_original_code:
int file_check(int fd, long pos1, long pos2, long pos3, char *data)
{
 int ret = 1;
 if (pos2 > pos1)
  if (__file_check_gap(fd, pos1, pos2-pos1))
   goto out;
 ret = __file_check_data(fd, pos2, pos3-pos2, data);
out:
 return ret;
}

variable_types:
data
char *


decompiled_code:
__int64 __fastcall grow_file(int fd, int a2)
{
__off_t v2; // rbx
__off_t v3; // rax
__off_t v4; // r12
__int64 v5; // r15
__off_t v6; // r14
ssize_t v7; // rax
size_t v8; // rbx
unsigned int v9; // er12
__off_t v11; // rax
__int64 v12; // r15
__off_t v13; // rax
signed int v14; // er13
__off_t v15; // rax
__off_t v16; // rbx
__off_t v17; // [rsp+0h] [rbp-48h]

v2 = file_size(fd);
v3 = lseek(fd, 0LL, 2);
if ( v3 < 0 || (v4 = v3, v2 != v3) )
{
v9 = 1;
puts("file end & file size mismatch or operation failed");
return v9;
}
v5 = qword_4040C8;
if ( qword_4040C8 )
{
v11 = lseek(fd, qword_4040C8 + v2, 0);
v6 = v11;
if ( v11 < 0 || v5 != v11 - v4 )
{
v9 = 1;
puts("lseek do not reach require size or operation failed");
return v9;
}
}
else
{
v6 = v3;
}
v7 = write(fd, buf, size);
if ( v7 >= 0 && (v8 = size, size == v7) )
{
v12 = lseek(fd, 0LL, 1);
v13 = file_size(fd);
if ( v12 >= 0 && v12 == v13 && v12 - v6 == v8 )
{
v17 = v13;
v9 = file_check(fd, v4, v6, v12, (__int64)buf);
if ( v9 )
{
v9 = 1;
}
else
{
v14 = a2 + 1;
if ( !((a2 + 1) % dword_4040F8) )
{
v15 = lseek(fd, 0LL, 1);
v16 = v15;
if ( v15 >= 0 && v12 == v15 )
{
printf("truncate file to %jd trunk_pos=%jd\n", v15 - qword_4040F0, v15);
printf(
"refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
v14 / dword_4040F8 * (size * dword_4040F8 - qword_4040F0),
(unsigned int)v14,
v12,
v17,
v12 - v6);
if ( (size * dword_4040F8 - qword_4040F0) * (v14 / dword_4040F8) == v16 - qword_4040F0 )
{
if ( ftruncate(fd, v16 - qword_4040F0) < 0 )
{
v9 = 1;
puts("can not truncate file");
}
}
else
{
v9 = 1;
puts("wrong truncate position");
}
}
else
{
v9 = 1;
puts("trunk_pos does't match");
}
}
}
}
else
{
v9 = 1;
puts("write data len mismatch or operation failed");
}
}
else
{
v9 = 1;
puts("write len does't not match or operation failed");
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, int a2)
{
__off_t v2; // rbx
__off_t v3; // rax
__off_t v4; // r12
__int64 v5; // r15
__off_t v6; // r14
ssize_t v7; // rax
size_t v8; // rbx
unsigned int v9; // er12
__off_t v11; // rax
__int64 v12; // r15
__off_t v13; // rax
signed int v14; // er13
__off_t v15; // rax
__off_t v16; // rbx
__off_t v17; // [rsp+0h] [rbp-48h]

v2 = func7(fd);
v3 = lseek(fd, 0LL, 2);
if ( v3 < 0 || (v4 = v3, v2 != v3) )
{
v9 = 1;
puts("file end & file size mismatch or operation failed");
return v9;
}
v5 = qword_4040C8;
if ( qword_4040C8 )
{
v11 = lseek(fd, qword_4040C8 + v2, 0);
v6 = v11;
if ( v11 < 0 || v5 != v11 - v4 )
{
v9 = 1;
puts("lseek do not reach require size or operation failed");
return v9;
}
}
else
{
v6 = v3;
}
v7 = write(fd, buf, size);
if ( v7 >= 0 && (v8 = size, size == v7) )
{
v12 = lseek(fd, 0LL, 1);
v13 = func7(fd);
if ( v12 >= 0 && v12 == v13 && v12 - v6 == v8 )
{
v17 = v13;
v9 = func10(fd, v4, v6, v12, (__int64)buf);
if ( v9 )
{
v9 = 1;
}
else
{
v14 = a2 + 1;
if ( !((a2 + 1) % dword_4040F8) )
{
v15 = lseek(fd, 0LL, 1);
v16 = v15;
if ( v15 >= 0 && v12 == v15 )
{
printf("truncate file to %jd trunk_pos=%jd\n", v15 - qword_4040F0, v15);
printf(
"refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
v14 / dword_4040F8 * (size * dword_4040F8 - qword_4040F0),
(unsigned int)v14,
v12,
v17,
v12 - v6);
if ( (size * dword_4040F8 - qword_4040F0) * (v14 / dword_4040F8) == v16 - qword_4040F0 )
{
if ( ftruncate(fd, v16 - qword_4040F0) < 0 )
{
v9 = 1;
puts("can not truncate file");
}
}
else
{
v9 = 1;
puts("wrong truncate position");
}
}
else
{
v9 = 1;
puts("trunk_pos does't match");
}
}
}
}
else
{
v9 = 1;
puts("write data len mismatch or operation failed");
}
}
else
{
v9 = 1;
puts("write len does't not match or operation failed");
}
return v9;
}

original_code:
int grow_file(int fd, int iter)
{
 off_t fsize;
 ssize_t write_len;
 off_t pos1, pos2, pos3;
 off_t trunk_pos;
 fsize = file_size(fd);
 pos1 = pos2 = lseek(fd, 0, 2);
 if (pos1 < 0 || fsize != pos1) {
  printf("file end & file size mismatch or operation failed\n");
  goto failed;
 }
 if (opt.gap_size) {
  pos2 = lseek(fd, fsize + opt.gap_size, 0);
  if (pos2 < 0 || (pos2 - pos1) != opt.gap_size) {
   printf("lseek do not reach require size or operation failed\n");
   goto failed;
  }
 }
 write_len = write(fd, opt.data, opt.data_size);
 if (write_len < 0 || write_len != opt.data_size) {
  printf("write len does't not match or operation failed\n");
  goto failed;
 }
 pos3 = lseek(fd, 0, 1);
 fsize = file_size(fd);
 if (pos3 < 0 || fsize != pos3 || (pos3 - pos2) != opt.data_size) {
  printf("write data len mismatch or operation failed\n");
  goto failed;
 }
 if (file_check(fd, pos1, pos2, pos3, opt.data))
  goto failed;
 if (((iter+1)%opt.trunc_iter) == 0) {
  trunk_pos = lseek(fd, 0, 1);
  if (trunk_pos < 0 || trunk_pos != pos3) {
   printf("trunk_pos does't match\n");
   goto failed;
  }
  printf("truncate file to  %jd trunk_pos=%jd\n", trunk_pos-opt.trunc_size, trunk_pos);
  printf("refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
    ((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size),
    iter+1,
    pos3,
    fsize,
    write_len);
  if (((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size)
    != trunk_pos-opt.trunc_size) {
   printf("wrong truncate position\n");
   goto failed;
  }
  if (ftruncate(fd, trunk_pos - opt.trunc_size) < 0) {
   printf("can not truncate file\n");
   goto failed;
  }
 }
 return 0;
failed:
 return 1;
}

canonical_original_code:
int grow_file(int fd, int iter)
{
 long fsize;
 long write_len;
 long pos1; long pos2; long pos3;
 long trunk_pos;
 fsize = file_size(fd);
 pos1 = pos2 = lseek(fd, 0, 2);
 if (pos1 < 0 || fsize != pos1) {
  printf("file end & file size mismatch or operation failed\n");
  goto failed;
 }
 if (opt.gap_size) {
  pos2 = lseek(fd, fsize + opt.gap_size, 0);
  if (pos2 < 0 || (pos2 - pos1) != opt.gap_size) {
   printf("lseek do not reach require size or operation failed\n");
   goto failed;
  }
 }
 write_len = write(fd, opt.data, opt.data_size);
 if (write_len < 0 || write_len != opt.data_size) {
  printf("write len does't not match or operation failed\n");
  goto failed;
 }
 pos3 = lseek(fd, 0, 1);
 fsize = file_size(fd);
 if (pos3 < 0 || fsize != pos3 || (pos3 - pos2) != opt.data_size) {
  printf("write data len mismatch or operation failed\n");
  goto failed;
 }
 if (file_check(fd, pos1, pos2, pos3, opt.data))
  goto failed;
 if (((iter+1)%opt.trunc_iter) == 0) {
  trunk_pos = lseek(fd, 0, 1);
  if (trunk_pos < 0 || trunk_pos != pos3) {
   printf("trunk_pos does't match\n");
   goto failed;
  }
  printf("truncate file to  %jd trunk_pos=%jd\n", trunk_pos-opt.trunc_size, trunk_pos);
  printf("refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
    ((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size),
    iter+1,
    pos3,
    fsize,
    write_len);
  if (((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size)
    != trunk_pos-opt.trunc_size) {
   printf("wrong truncate position\n");
   goto failed;
  }
  if (ftruncate(fd, trunk_pos - opt.trunc_size) < 0) {
   printf("can not truncate file\n");
   goto failed;
  }
 }
 return 0;
failed:
 return 1;
}

variable_types: iter int

variable_types: fsize long


original_code:
int get_opt(int argc, char *argv[])
{
 int i;
 for (i=1; i< argc; i++) {
  if (strcmp(argv[i], "-s") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.get_size_way = atoi(argv[i]);
  } else if (strcmp(argv[i], "-g") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.gap_size = atoi(argv[i]);
  } else if (strcmp(argv[i], "-d") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.data_size = atoi(argv[i]);
  } else if (strcmp(argv[i], "-i") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.iter = atoi(argv[i]);
  } else {
   opt.file_path = strdup(argv[i]);
  }
 }
 return 0;
failed:
 printf("options parse failed!\n");
 return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebx
int v5; // eax
int v6; // ebp
int *v7; // rbx
char *v8; // rax

if ( !(unsigned int)get_opt(argc, argv, envp) && file )
{
v3 = 0;
buf = (void *)prepare_data(size);
if ( buf )
{
v4 = 0;
if ( dword_4040D8 <= 0 )
return v3;
while ( 1 )
{
v5 = open(file, 66, 511LL);
v6 = v5;
if ( v5 < 0 )
break;
if ( (unsigned int)grow_file(v5) )
goto LABEL_10;
++v4;
close(v6);
if ( dword_4040D8 <= v4 )
return v3;
}
puts("can not open file");
}
else
{
puts("memory alloc failed!");
}
}
LABEL_10:
v3 = 1;
v7 = __errno_location();
v8 = strerror(*v7);
printf("Got error(%d):%s\n", (unsigned int)*v7, v8);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebx
int v5; // eax
int v6; // ebp
int *v7; // rbx
char *v8; // rax

if ( !(unsigned int)func12(argc, argv, envp) && file )
{
v3 = 0;
buf = (void *)prepare_data(size);
if ( buf )
{
v4 = 0;
if ( dword_4040D8 <= 0 )
return v3;
while ( 1 )
{
v5 = open(file, 66, 511LL);
v6 = v5;
if ( v5 < 0 )
break;
if ( (unsigned int)func11(v5) )
goto LABEL_10;
++v4;
close(v6);
if ( dword_4040D8 <= v4 )
return v3;
}
puts("can not open file");
}
else
{
puts("memory alloc failed!");
}
}
LABEL_10:
v3 = 1;
v7 = __errno_location();
v8 = strerror(*v7);
printf("Got error(%d):%s\n", (unsigned int)*v7, v8);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 int fd, i;
 if (get_opt(argc, argv) || !opt.file_path)
  goto failed;
 opt.data = prepare_data(opt.data_size);
 if (!opt.data) {
  printf("memory alloc failed!\n");
  goto failed;
 }
 for (i=0; i<opt.iter; i++) {
  fd = open(opt.file_path, 02|0100, 0777);
  if (fd < 0) {
   printf("can not open file\n");
   goto failed;
  }
  if (grow_file(fd, i))
   goto failed;
  close(fd);
 }
 return 0;
failed:
 printf("Got error(%d):%s\n", (*__errno_location ()), strerror((*__errno_location ())));
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd; int i;
 if (get_opt(argc, argv) || !opt.file_path)
  goto failed;
 opt.data = prepare_data(opt.data_size);
 if (!opt.data) {
  printf("memory alloc failed!\n");
  goto failed;
 }
 for (i=0; i<opt.iter; i++) {
  fd = open(opt.file_path, 02|0100, 0777);
  if (fd < 0) {
   printf("can not open file\n");
   goto failed;
  }
  if (grow_file(fd, i))
   goto failed;
  close(fd);
 }
 return 0;
failed:
 printf("Got error(%d):%s\n", (*__errno_location ()), strerror((*__errno_location ())));
 return 1;
}


debuger

decompiled_code:
int __fastcall debuger(unsigned int a1)
{
return printf("test write for %d times\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("test write for %d times\n", a1);
}

original_code:
void debuger(int counter)
{
 printf("test write for %d times\n", counter);
}

variable_types: counter int


decompiled_code:
int __fastcall sys_open(const char *a1, int a2)
{
return open(a1, a2 | 0x800);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, int a2)
{
return open(a1, a2 | 0x800);
}

original_code:
int
sys_open(const char *file_path, int flags, mode_t mode)
{
 int ret;
 flags |= 04000;
 ret = open(file_path, flags, mode);
 return ret;
}

canonical_original_code:
int sys_open(char *file_path, int flags, unsigned int mode)
{
 int ret;
 flags |= 04000;
 ret = open(file_path, flags, mode);
 return ret;
}

variable_types: flags int

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall sys_write(int a1, const void *a2, size_t a3)
{
__int64 result; // rax

LODWORD(result) = write(a1, a2, a3);
if ( (_DWORD)result != 11 )
return (int)result;
puts("debug_ding:non block mode continue to write");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, const void *a2, size_t a3)
{
__int64 result; // rax

LODWORD(result) = write(a1, a2, a3);
if ( (_DWORD)result != 11 )
return (int)result;
puts("debug_ding:non block mode continue to write");
return 0LL;
}

original_code:
ssize_t
sys_write(int fd, const void *buf, size_t count)
{
 ssize_t ret;
 ret = write(fd, buf, count);
 if (ret == 11) {
  ret = 0;
  printf("debug_ding:non block mode continue to write\n");
 }
 return ret;
}

canonical_original_code:
long sys_write(int fd, void *buf, unsigned long count)
{
 long ret;
 ret = write(fd, buf, count);
 if (ret == 11) {
  ret = 0;
  printf("debug_ding:non block mode continue to write\n");
 }
 return ret;
}

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: ret long


decompiled_code:
int __fastcall sys_close(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int __fastcall func10(int fd)
{
return close(fd);
}

original_code:
int
sys_close(int fd)
{
 return close(fd);
}


decompiled_code:
__int64 __fastcall test_thread(void *a1)
{
unsigned int v1; // ebx
int v2; // eax
int v3; // ebp
int *v4; // rbx
char *v5; // rax
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = 0;
sprintf(v7, "%s%d", (const char *)file_prefix, *(unsigned int *)a1);
printf("file_path:%s\n", v7);
do
{
v2 = sys_open(v7, 1090);
v3 = v2;
if ( v2 < 0 )
{
printf("can not open file");
goto LABEL_10;
}
if ( (int)sys_write(v2, (const void *)buf, 0x100000uLL) < 0
|| (int)sys_write(v3, (const void *)buf, 0x100000uLL) < 0 )
{
printf("write error");
LABEL_10:
v4 = __errno_location();
v5 = strerror(*v4);
printf(" errno:%d(%s)\n", (unsigned int)*v4, v5);
return -1LL;
}
if ( sys_close(v3) )
{
printf("can not close file");
goto LABEL_10;
}
++v1;
if ( __ROR4__(-286331153 * v1, 1) <= 0x8888888u )
debuger(v1);
}
while ( v1 != 40960 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(void *a1)
{
unsigned int v1; // ebx
int v2; // eax
int v3; // ebp
int *v4; // rbx
char *v5; // rax
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = 0;
sprintf(v7, "%s%d", (const char *)file_prefix, *(unsigned int *)a1);
printf("file_path:%s\n", v7);
do
{
v2 = func8(v7, 1090);
v3 = v2;
if ( v2 < 0 )
{
printf("can not open file");
goto LABEL_10;
}
if ( (int)func9(v2, (const void *)buf, 0x100000uLL) < 0
|| (int)func9(v3, (const void *)buf, 0x100000uLL) < 0 )
{
printf("write error");
LABEL_10:
v4 = __errno_location();
v5 = strerror(*v4);
printf(" errno:%d(%s)\n", (unsigned int)*v4, v5);
return -1LL;
}
if ( func10(v3) )
{
printf("can not close file");
goto LABEL_10;
}
++v1;
if ( __ROR4__(-286331153 * v1, 1) <= 0x8888888u )
func7(v1);
}
while ( v1 != 40960 );
return 0LL;
}

original_code:
void *
test_thread (void *arg)
{
 int fd;
 int ret;
 int i;
 int loop_counter = 0;
 int *thread_num = (int *)arg;
 char file_path[100];
 sprintf(file_path, "%s%d", file_prefix, *thread_num);
 printf("file_path:%s\n", file_path);
 i = 40960;
 while (i-->0) {
  fd = sys_open(file_path, 02|0100|02000, 0400|0200);
  do {if (fd < 0) { do { printf("can not open file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_close (fd);
  do {if (ret != 0) { do { printf("can not close file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  loop_counter++;
  if ((loop_counter%30)==0) {
   debuger(loop_counter);
  }
 }
 return 0;
}

canonical_original_code:
void *test_thread(void *arg)
{
 int fd;
 int ret;
 int i;
 int loop_counter = 0;
 int *thread_num = (int *)arg;
 char file_path[100];
 sprintf(file_path, "%s%d", file_prefix, *thread_num);
 printf("file_path:%s\n", file_path);
 i = 40960;
 while (i-->0) {
  fd = sys_open(file_path, 02|0100|02000, 0400|0200);
  do {if (fd < 0) { do { printf("can not open file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_close (fd);
  do {if (ret != 0) { do { printf("can not close file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  loop_counter++;
  if ((loop_counter%30)==0) {
   debuger(loop_counter);
  }
 }
 return 0;
}

variable_types:
arg
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int arg; // [rsp+4h] [rbp-14h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( argc <= 1 )
{
file_prefix = (__int64)"/cluster2/test1/test_file";
printf("use default file location:%s\n", "/cluster2/test1/test_file");
}
else
{
file_prefix = (__int64)argv[1];
printf("use user specified file location:%s\n", (const char *)file_prefix);
}
arg = 0;
buf = (__int64)malloc(0x100000uLL);
pthread_create(newthread, 0LL, test_thread, &arg);
printf("waiting for thread %d\n", 0LL);
pthread_join(newthread[0], 0LL);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 int i;
 int args[1];
 void * ptr;
 pthread_t th_id[1];
 if (argc > 1) {
  file_prefix = argv[1];
  printf("use user specified file location:%s\n", file_prefix);
 }
 else {
  file_prefix = "/cluster2/test1/test_file";
  printf("use default file location:%s\n", file_prefix);
 }
 buf = malloc(1048576);
 if(buf < 0){
  printf("can not alloc memory");
  return -1;
 }
 memset(buf, 1048576, '\0');
 for (i=0; i<1; i++){
  args[i] = i;
  pthread_create (&th_id[i], ((void *)0), test_thread, (void *)&args[i]);
 }
 for (i=0; i<1; i++) {
  printf ("waiting for thread %d\n", i);
  pthread_join (th_id[i], ((void *)0));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i;
 int args[1];
 void *ptr;
 unsigned long th_id[1];
 if (argc > 1) {
  file_prefix = argv[1];
  printf("use user specified file location:%s\n", file_prefix);
 }
 else {
  file_prefix = "/cluster2/test1/test_file";
  printf("use default file location:%s\n", file_prefix);
 }
 buf = malloc(1048576);
 if(buf < 0){
  printf("can not alloc memory");
  return -1;
 }
 memset(buf, 1048576, '\0');
 for (i=0; i<1; i++){
  args[i] = i;
  pthread_create (&th_id[i], ((void *)0), test_thread, (void *)&args[i]);
 }
 for (i=0; i<1; i++) {
  printf ("waiting for thread %d\n", i);
  pthread_join (th_id[i], ((void *)0));
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
args
int [1]

variable_types:
ptr
void *


decompiled_code:
void __fastcall __noreturn my_thread(void *a1)
{
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
BUG();
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
BUG();
}

original_code:
void *my_thread(void *args)
{
 int i = 0;
 char *p = ((void *)0);
 while (i++ < 5) {
  sleep(1);
 }
 i = (int)p[0];
 printf("i=%d\n", i);
 return ((void *)0);
}

variable_types:
args
void *

variable_types: i int

variable_types:
p
char *


decompiled_code:
void __fastcall my_sig_handler(unsigned int a1)
{
__int64 v1; // rax

puts("enter signal handler");
if ( a1 == signal_name_map )
{
v1 = 0LL;
}
else if ( a1 == dword_404070 )
{
v1 = 1LL;
}
else
{
if ( a1 != dword_404080 )
{
printf("no match signal for %d\n", a1);
return;
}
v1 = 2LL;
}
printf("recieve signal %s\n", (&off_404068)[2 * v1]);
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1)
{
__int64 v1; // rax

puts("enter signal handler");
if ( a1 == signal_name_map )
{
v1 = 0LL;
}
else if ( a1 == dword_404070 )
{
v1 = 1LL;
}
else
{
if ( a1 != dword_404080 )
{
printf("no match signal for %d\n", a1);
return;
}
v1 = 2LL;
}
printf("recieve signal %s\n", (&off_404068)[2 * v1]);
}

original_code:
void my_sig_handler (int signum)
{
 int i;
 printf("enter signal handler\n");
 for (i=0; i<3; i++) {
  if (signum == signal_name_map[i].signal_num) {
   printf ("recieve signal %s\n", signal_name_map[i].signal_name);
   return;
  }
 }
 printf("no match signal for %d\n", signum);
}

canonical_original_code:
void my_sig_handler(int signum)
{
 int i;
 printf("enter signal handler\n");
 for (i=0; i<3; i++) {
  if (signum == signal_name_map[i].signal_num) {
   printf ("recieve signal %s\n", signal_name_map[i].signal_name);
   return;
  }
 }
 printf("no match signal for %d\n", signum);
}

variable_types: signum int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, my_thread, 0LL);
signal(9, my_sig_handler);
signal(15, my_sig_handler);
signal(11, my_sig_handler);
while ( 1 )
{
sleep(1u);
puts("sleeping ");
}
}

original_code:
int main ()
{
 pthread_t tid;
 pthread_create(&tid, ((void *)0), my_thread, ((void *)0));
 signal(9, my_sig_handler);
 signal(15, my_sig_handler);
 signal(11, my_sig_handler);
 while (1) {
  sleep(1);
  printf ("sleeping \n");
 }
 return 0;
}

canonical_original_code:
int main()
{
 unsigned long tid;
 pthread_create(&tid, ((void *)0), my_thread, ((void *)0));
 signal(9, my_sig_handler);
 signal(15, my_sig_handler);
 signal(11, my_sig_handler);
 while (1) {
  sleep(1);
  printf ("sleeping \n");
 }
 return 0;
}

variable_types:
tid
unsigned long


decompiled_code:
int __fastcall follow_link(char *src)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rbp
size_t v4; // rax
int v5; // eax
ssize_t v6; // rax
size_t v7; // rax
int result; // eax
int *v9; // r13
char *v10; // rax
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v1 = (char *)calloc(1uLL, 0x1000uLL);
v2 = (char *)calloc(1uLL, 0x1000uLL);
v3 = v2;
if ( *src != 47 )
{
if ( !getcwd(v2, 0xFFFuLL) )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("BW_VMDIO:Get cwd error. %d(%s)\n", (unsigned int)*v9, v10);
}
*(_WORD *)&v3[strlen(v3)] = 47;
}
v4 = strlen(v3);
strncat(v3, src, 4095 - v4);
LABEL_3:
if ( (unsigned int)lstat(v3, &v11) )
return printf("BW_VMDIO:stat %s failed.\n", v3);
while ( 1 )
{
v5 = v11.st_mode & 0xF000;
if ( v5 != 40960 )
break;
v6 = readlink(v3, v1, 0xFFFuLL);
if ( v6 < 0 )
return printf("BW_VMDIO:read link %s failed\n", v3);
v1[v6] = 0;
if ( *v1 == 47 )
{
strcpy(v3, v1);
goto LABEL_3;
}
dirname(v3);
v7 = strlen(v3);
*(_WORD *)&v3[v7] = 47;
strncat(v3, v1, 4094 - v7);
if ( (unsigned int)lstat(v3, &v11) )
return printf("BW_VMDIO:stat %s failed.\n", v3);
}
if ( v5 == 24576 )
result = printf("BW_VMDIO: final path = %s\n", v3);
else
result = printf("BW_VMDIO:%s unkown file mode %o\n", v3, v11.st_mode);
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *src)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rbp
size_t v4; // rax
int v5; // eax
ssize_t v6; // rax
size_t v7; // rax
int result; // eax
int *v9; // r13
char *v10; // rax
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v1 = (char *)calloc(1uLL, 0x1000uLL);
v2 = (char *)calloc(1uLL, 0x1000uLL);
v3 = v2;
if ( *src != 47 )
{
if ( !getcwd(v2, 0xFFFuLL) )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("BW_VMDIO:Get cwd error. %d(%s)\n", (unsigned int)*v9, v10);
}
*(_WORD *)&v3[strlen(v3)] = 47;
}
v4 = strlen(v3);
strncat(v3, src, 4095 - v4);
LABEL_3:
if ( (unsigned int)func10(v3, &v11) )
return printf("BW_VMDIO:stat %s failed.\n", v3);
while ( 1 )
{
v5 = v11.st_mode & 0xF000;
if ( v5 != 40960 )
break;
v6 = readlink(v3, v1, 0xFFFuLL);
if ( v6 < 0 )
return printf("BW_VMDIO:read link %s failed\n", v3);
v1[v6] = 0;
if ( *v1 == 47 )
{
strcpy(v3, v1);
goto LABEL_3;
}
dirname(v3);
v7 = strlen(v3);
*(_WORD *)&v3[v7] = 47;
strncat(v3, v1, 4094 - v7);
if ( (unsigned int)func10(v3, &v11) )
return printf("BW_VMDIO:stat %s failed.\n", v3);
}
if ( v5 == 24576 )
result = printf("BW_VMDIO: final path = %s\n", v3);
else
result = printf("BW_VMDIO:%s unkown file mode %o\n", v3, v11.st_mode);
return result;
}

original_code:
void follow_link(const char *src_path)
{
 struct stat st;
 int ret;
 ssize_t sym_len;
 char *dev_path = ((void *)0);
 char *sym_path = ((void *)0);
 sym_path = calloc(1, 4096);
 dev_path = calloc(1, 4096);
 if (src_path[0] != '/') {
  if (getcwd(dev_path, 4096 -1) == ((void *)0)) {
   printf("BW_VMDIO:Get cwd error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  }
  strcat(dev_path, "/");
 }
 strncat(dev_path, src_path, 4096 -strlen(dev_path)-1);
 while (1) {
  ret = lstat(dev_path, &st);
  if (ret) {
   printf("BW_VMDIO:stat %s failed.\n", dev_path);
   goto failed;
  }
  if (((((st.st_mode)) & 0170000) == (0120000))) {
   sym_len = readlink(dev_path, sym_path, 4096 -1);
   if (sym_len < 0) {
    printf("BW_VMDIO:read link %s failed\n", dev_path);
    goto failed;
   }
   sym_path[sym_len] = '\0';
   if (sym_path[0] == '/') {
    strcpy(dev_path, sym_path);
   } else {
    dirname(dev_path);
    strcat(dev_path, "/");
    strncat(dev_path, sym_path, 4096 -strlen(dev_path)-1);
   }
   continue;
  } else if (((((st.st_mode)) & 0170000) == (0060000))) {
   break;
  } else {
   printf("BW_VMDIO:%s unkown file mode %o\n", dev_path, st.st_mode);
   goto failed;
  }
 }
 printf("BW_VMDIO: final path = %s\n", dev_path);
 return ;
failed:
 return ;
}

canonical_original_code:
void follow_link(char *src_path)
{
 struct stat st;
 int ret;
 long sym_len;
 char *dev_path = ((void *)0);
 char *sym_path = ((void *)0);
 sym_path = calloc(1, 4096);
 dev_path = calloc(1, 4096);
 if (src_path[0] != '/') {
  if (getcwd(dev_path, 4096 -1) == ((void *)0)) {
   printf("BW_VMDIO:Get cwd error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  }
  strcat(dev_path, "/");
 }
 strncat(dev_path, src_path, 4096 -strlen(dev_path)-1);
 while (1) {
  ret = lstat(dev_path, &st);
  if (ret) {
   printf("BW_VMDIO:stat %s failed.\n", dev_path);
   goto failed;
  }
  if (((((st.st_mode)) & 0170000) == (0120000))) {
   sym_len = readlink(dev_path, sym_path, 4096 -1);
   if (sym_len < 0) {
    printf("BW_VMDIO:read link %s failed\n", dev_path);
    goto failed;
   }
   sym_path[sym_len] = '\0';
   if (sym_path[0] == '/') {
    strcpy(dev_path, sym_path);
   } else {
    dirname(dev_path);
    strcat(dev_path, "/");
    strncat(dev_path, sym_path, 4096 -strlen(dev_path)-1);
   }
   continue;
  } else if (((((st.st_mode)) & 0170000) == (0060000))) {
   break;
  } else {
   printf("BW_VMDIO:%s unkown file mode %o\n", dev_path, st.st_mode);
   goto failed;
  }
 }
 printf("BW_VMDIO: final path = %s\n", dev_path);
 return ;
failed:
 return ;
}

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

variable_types: ret int


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

if ( argc <= 1 )
{
puts("Provide a path.");
}
else
{
v3 = strdup(argv[1]);
follow_link(v3);
}
return 0;
}

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

if ( argc <= 1 )
{
puts("Provide a path.");
}
else
{
v3 = strdup(argv[1]);
func7(v3);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *file_path;
 if (argc < 2) {
  printf("Provide a path.\n");
  goto out;
 }
 file_path = strdup(argv[1]);
 follow_link(file_path);
out:
 return 0;
}


decompiled_code:
__int64 __fastcall gen_dir(const char *a1)
{
unsigned int v1; // er12
int *v2; // rax
unsigned int *v3; // rbx
char *v4; // rax

v1 = mkdir(a1, 0x1EDu);
if ( !v1 )
return v1;
v2 = __errno_location();
v3 = (unsigned int *)v2;
if ( *v2 != 17 )
{
v4 = strerror(*v2);
printf("ret=%d,errno=%d(%s)\n", v1, *v3, v4);
return v1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned int v1; // er12
int *v2; // rax
unsigned int *v3; // rbx
char *v4; // rax

v1 = mkdir(a1, 0x1EDu);
if ( !v1 )
return v1;
v2 = __errno_location();
v3 = (unsigned int *)v2;
if ( *v2 != 17 )
{
v4 = strerror(*v2);
printf("ret=%d,errno=%d(%s)\n", v1, *v3, v4);
return v1;
}
return 0LL;
}

original_code:
int gen_dir(char *path)
{
 int ret = 0;
 ret = mkdir(path, 0755);
 if (ret && (*__errno_location ())==17) {
  ret = 0;
 } else if (ret) {
  printf("ret=%d,errno=%d(%s)\n", ret, (*__errno_location ()), strerror((*__errno_location ())));
 }
 return ret;
}

variable_types:
path
char *


decompiled_code:
__int64 __fastcall gen_parent(const char *a1)
{
char *v1; // rax
char *v2; // rax

v1 = strdup(a1);
v2 = dirname(v1);
return gen_dir(v2);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
char *v1; // rax
char *v2; // rax

v1 = strdup(a1);
v2 = dirname(v1);
return func7(v2);
}

original_code:
int gen_parent(char *path)
{
 char *dirpath;
 dirpath = dirname(strdup(path));
 return gen_dir(dirpath);
}

variable_types:
dirpath
char *


decompiled_code:
__int64 __fastcall lock_pidfile(int fd, int a2)
{
int i; // ebx
unsigned int v3; // er12

for ( i = a2; ; --i )
{
v3 = flock(fd, a2 == 0 ? 2 : 6);
if ( !v3 || *__errno_location() != 11 || !i )
break;
sleep(1u);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, int a2)
{
int i; // ebx
unsigned int v3; // er12

for ( i = a2; ; --i )
{
v3 = flock(fd, a2 == 0 ? 2 : 6);
if ( !v3 || *__errno_location() != 11 || !i )
break;
sleep(1u);
}
return v3;
}

original_code:
int lock_pidfile(int fd, uint32_t timeo)
{
 int ret = -1;
 int lock_mode = 2;
 if (timeo != 0)
  lock_mode |= 4;
 while (ret) {
  ret = flock(fd, lock_mode);
  if (ret == 0)
   break;
  if ((*__errno_location ()) != 11)
   break;
  if (timeo == 0)
   break;
  sleep(1);
  timeo--;
 }
 return ret;
}

canonical_original_code:
int lock_pidfile(int fd, unsigned int timeo)
{
 int ret = -1;
 int lock_mode = 2;
 if (timeo != 0)
  lock_mode |= 4;
 while (ret) {
  ret = flock(fd, lock_mode);
  if (ret == 0)
   break;
  if ((*__errno_location ()) != 11)
   break;
  if (timeo == 0)
   break;
  sleep(1);
  timeo--;
 }
 return ret;
}

variable_types: fd int

variable_types:
timeo
unsigned int


decompiled_code:
__int64 __fastcall unlock_pidfile(int a1)
{
unsigned int v1; // er12
int *v3; // rbx
char *v4; // rax

v1 = flock(a1, 8);
if ( v1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("unlock error.%d(%s)\n", (unsigned int)*v3, v4);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
unsigned int v1; // er12
int *v3; // rbx
char *v4; // rax

v1 = flock(a1, 8);
if ( v1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("unlock error.%d(%s)\n", (unsigned int)*v3, v4);
}
return v1;
}

original_code:
int unlock_pidfile(int fd)
{
 int ret = 0;
 ret = flock(fd, 8);
 if (ret) {
  printf("unlock error.%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
out:
 return ret;
}


decompiled_code:
__int64 __fastcall get_right(char *file)
{
int v1; // eax
unsigned int v2; // er12
int *v4; // r12
char *v5; // rax
__int64 v6; // rsi

if ( (unsigned int)gen_parent(file) )
{
v2 = -1;
puts("gen_parent error");
}
else
{
v1 = open(file, 66, 420LL);
v2 = v1;
if ( v1 < 0 )
{
v4 = __errno_location();
v5 = strerror(*v4);
v6 = (unsigned int)*v4;
v2 = -1;
printf("open error, %d(%s)\n", v6, v5);
}
else if ( (unsigned int)lock_pidfile(v1, 10) )
{
v2 = -1;
puts("lock_pidfile error");
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *file)
{
int v1; // eax
unsigned int v2; // er12
int *v4; // r12
char *v5; // rax
__int64 v6; // rsi

if ( (unsigned int)func8(file) )
{
v2 = -1;
puts("gen_parent error");
}
else
{
v1 = open(file, 66, 420LL);
v2 = v1;
if ( v1 < 0 )
{
v4 = __errno_location();
v5 = strerror(*v4);
v6 = (unsigned int)*v4;
v2 = -1;
printf("open error, %d(%s)\n", v6, v5);
}
else if ( (unsigned int)func9(v1, 10) )
{
v2 = -1;
puts("lock_pidfile error");
}
}
return v2;
}

original_code:
int get_right(char *pid_path)
{
 int ret, fd;
 ret = gen_parent(pid_path);
 if (ret) {
  printf("gen_parent error\n");
  goto fail;
 }
 fd = open(pid_path, 02|0100, 0644);
 if (fd < 0) {
  printf("open error, %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  ret = (*__errno_location ());
  goto fail;
 }
 ret = lock_pidfile(fd, 10);
 if (ret) {
  printf("lock_pidfile error\n");
  goto fail;
 }
 return fd;
fail:
 return -1;
}

canonical_original_code:
int get_right(char *pid_path)
{
 int ret; int fd;
 ret = gen_parent(pid_path);
 if (ret) {
  printf("gen_parent error\n");
  goto fail;
 }
 fd = open(pid_path, 02|0100, 0644);
 if (fd < 0) {
  printf("open error, %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  ret = (*__errno_location ());
  goto fail;
 }
 ret = lock_pidfile(fd, 10);
 if (ret) {
  printf("lock_pidfile error\n");
  goto fail;
 }
 return fd;
fail:
 return -1;
}


decompiled_code:
// attributes: thunk
__int64 __fastcall put_right(int a1)
{
return unlock_pidfile(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return func10(a1);
}

original_code:
int put_right(int fd)
{
 return unlock_pidfile(fd);
}


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

v3 = get_right("/var/log/test.pid");
if ( v3 < 0 )
puts("get right fail");
sleep(0xAu);
put_right((unsigned int)v3, argv);
return 0;
}

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

v3 = func11("/var/log/test.pid");
if ( v3 < 0 )
puts("get right fail");
sleep(0xAu);
func12((unsigned int)v3, argv);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int fd;
 fd = get_right("/var/log/test.pid");
 if (fd < 0)
  printf("get right fail\n");
 sleep(10);
 put_right(fd);
 return 0;
}


decompiled_code:
void __fastcall sig_handler(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
printf("recieve msg:%d, at:%d\n", a1, tv.tv_sec);
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
printf("recieve msg:%d, at:%d\n", a1, tv.tv_sec);
}

original_code:
void sig_handler(int signum)
{
 struct timeval tv;
 struct timezone tz;
 gettimeofday(&tv, &tz);
 printf("recieve msg:%d, at:%d\n", signum, tv.tv_sec);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


decompiled_code:
__int64 tm1_handler()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm1:interval=%u.%u\n", v1.tv_sec - tm1_last.tv_sec, v1.tv_usec - tm1_last.tv_usec);
result = 0LL;
tm1_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm1:interval=%u.%u\n", v1.tv_sec - tm1_last.tv_sec, v1.tv_usec - tm1_last.tv_usec);
result = 0LL;
tm1_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return result;
}

original_code:
int32_t tm1_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm1:interval=%u.%u\n",
   tm_now.tv_sec-tm1_last.tv_sec, tm_now.tv_usec-tm1_last.tv_usec);
 tm1_last = tm_now;
 return 0;
}

canonical_original_code:
int tm1_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm1:interval=%u.%u\n",
   tm_now.tv_sec-tm1_last.tv_sec, tm_now.tv_usec-tm1_last.tv_usec);
 tm1_last = tm_now;
 return 0;
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 tm2_handler()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm2:interval=%u.%u\n", v1.tv_sec - tm2_last.tv_sec, v1.tv_usec - tm2_last.tv_usec);
result = 0LL;
tm2_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm2:interval=%u.%u\n", v1.tv_sec - tm2_last.tv_sec, v1.tv_usec - tm2_last.tv_usec);
result = 0LL;
tm2_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return result;
}

original_code:
int32_t tm2_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm2:interval=%u.%u\n",
   tm_now.tv_sec-tm2_last.tv_sec, tm_now.tv_usec-tm2_last.tv_usec);
 tm2_last = tm_now;
 return 0;
}

canonical_original_code:
int tm2_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm2:interval=%u.%u\n",
   tm_now.tv_sec-tm2_last.tv_sec, tm_now.tv_usec-tm2_last.tv_usec);
 tm2_last = tm_now;
 return 0;
}


decompiled_code:
__int64 tm3_handler()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm3:interval=%u.%u\n", v1.tv_sec - tm3_last.tv_sec, v1.tv_usec - tm3_last.tv_usec);
result = 0LL;
tm3_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
printf("tm3:interval=%u.%u\n", v1.tv_sec - tm3_last.tv_sec, v1.tv_usec - tm3_last.tv_usec);
result = 0LL;
tm3_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return result;
}

original_code:
int32_t tm3_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm3:interval=%u.%u\n",
   tm_now.tv_sec-tm3_last.tv_sec, tm_now.tv_usec-tm3_last.tv_usec);
 tm3_last = tm_now;
 return 0;
}

canonical_original_code:
int tm3_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm3:interval=%u.%u\n",
   tm_now.tv_sec-tm3_last.tv_sec, tm_now.tv_usec-tm3_last.tv_usec);
 tm3_last = tm_now;
 return 0;
}


decompiled_code:
int __fastcall timer_thread(unsigned int *a1)
{
printf("thread run, val=%d\n", *a1);
sleep(5u);
return puts("thread finished");
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
printf("thread run, val=%d\n", *a1);
sleep(5u);
return puts("thread finished");
}

original_code:
void timer_thread(sigval_t val)
{
 struct timer_struct *ts = val.sival_ptr;
 printf("thread run, val=%d\n", ts->priv);
 sleep(5);
 printf("thread finished\n");
}

canonical_original_code:
void timer_thread(union sigval val)
{
 struct timer_struct *ts = val.sival_ptr;
 printf("thread run, val=%d\n", ts->priv);
 sleep(5);
 printf("thread finished\n");
}

variable_types: union sigval { int sival_int; void *sival_ptr; }

variable_types: struct timer_struct { int priv; void *timer_id; struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; } tick; } *

user_defined_types: struct timer_struct { int priv; void *timer_id; struct itimerspec tick; }

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }


decompiled_code:
int test_timer_create()
{
void *v0; // rdi
int v1; // ebx
void *v2; // rdi
int *v3; // rbx
char *v4; // rax
struct itimerspec v6; // [rsp+0h] [rbp-68h] BYREF
struct sigevent evp; // [rsp+20h] [rbp-48h] BYREF

signal(14, (__sighandler_t)sig_handler);
*(_QWORD *)&evp.sigev_signo = 0x20000000ELL;
evp.sigev_value.sival_ptr = &g_ts;
evp._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_thread;
evp._sigev_un._sigev_thread._attribute = 0LL;
if ( !timer_create(0, &evp, (timer_t *)(unsigned int)((_DWORD)&g_ts + 8)) )
{
v0 = *(&g_ts + 1);
*(&g_ts + 4) = 0LL;
v1 = 0;
*(&g_ts + 5) = 0LL;
*(&g_ts + 2) = 0LL;
*(&g_ts + 3) = 0LL;
timer_settime(v0, 0, (const struct itimerspec *)(unsigned int)((_DWORD)&g_ts + 16), 0LL);
while ( 1 )
{
timer_gettime(*(&g_ts + 1), &v6);
printf(
"still it_value=%d.%d it_interval=%d.%d seconds.\n",
v6.it_value.tv_sec,
v6.it_value.tv_nsec,
v6.it_interval.tv_sec,
v6.it_interval.tv_nsec);
if ( v6.it_value.tv_sec <= 1 && v1 <= 9 )
{
v2 = *(&g_ts + 1);
v6.it_value.tv_sec = 4LL;
++v1;
timer_settime(v2, 0, &v6, 0LL);
}
sleep(1u);
}
}
v3 = _errno_location();
v4 = strerror(*v3);
return printf("timer_create error:%d(%s)\n", (unsigned int)*v3, v4);
}

canonical_decompiled_code:
int func5()
{
void *v0; // rdi
int v1; // ebx
void *v2; // rdi
int *v3; // rbx
char *v4; // rax
struct itimerspec v6; // [rsp+0h] [rbp-68h] BYREF
struct sigevent evp; // [rsp+20h] [rbp-48h] BYREF

signal(14, (__sighandler_t)sig_handler);
*(_QWORD *)&evp.sigev_signo = 0x20000000ELL;
evp.sigev_value.sival_ptr = &g_ts;
evp._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_thread;
evp._sigev_un._sigev_thread._attribute = 0LL;
if ( !timer_create(0, &evp, (timer_t *)(unsigned int)((_DWORD)&g_ts + 8)) )
{
v0 = *(&g_ts + 1);
*(&g_ts + 4) = 0LL;
v1 = 0;
*(&g_ts + 5) = 0LL;
*(&g_ts + 2) = 0LL;
*(&g_ts + 3) = 0LL;
timer_settime(v0, 0, (const struct itimerspec *)(unsigned int)((_DWORD)&g_ts + 16), 0LL);
while ( 1 )
{
timer_gettime(*(&g_ts + 1), &v6);
printf(
"still it_value=%d.%d it_interval=%d.%d seconds.\n",
v6.it_value.tv_sec,
v6.it_value.tv_nsec,
v6.it_interval.tv_sec,
v6.it_interval.tv_nsec);
if ( v6.it_value.tv_sec <= 1 && v1 <= 9 )
{
v2 = *(&g_ts + 1);
v6.it_value.tv_sec = 4LL;
++v1;
timer_settime(v2, 0, &v6, 0LL);
}
sleep(1u);
}
}
v3 = _errno_location();
v4 = strerror(*v3);
return printf("timer_create error:%d(%s)\n", (unsigned int)*v3, v4);
}

original_code:
void test_timer_create(void)
{
 struct sigevent sige;
 struct itimerspec tspec;
 long ret;
 int count = 0;
 signal(14, sig_handler);
 sige.sigev_value.sival_ptr = &g_ts;
 sige.sigev_signo = 14;
 sige.sigev_notify = SIGEV_THREAD;
 sige._sigev_un._sigev_thread._function = timer_thread;
 sige._sigev_un._sigev_thread._attribute = ((void *)0);
 ret = timer_create(0, &sige, &g_ts.timer_id);
 if (ret) {
  printf("timer_create error:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  return ;
 }
 g_ts.tick.it_value.tv_sec = 0;
 g_ts.tick.it_value.tv_nsec = 0;
 g_ts.tick.it_interval.tv_sec = 0;
 g_ts.tick.it_interval.tv_nsec = 0;
 timer_settime(g_ts.timer_id, 0, &g_ts.tick, ((void *)0));
 while(1) {
  timer_gettime(g_ts.timer_id, &tspec);
  printf("still it_value=%d.%d it_interval=%d.%d seconds.\n",
    tspec.it_value.tv_sec,
    tspec.it_value.tv_nsec,
    tspec.it_interval.tv_sec,
    tspec.it_interval.tv_nsec);
  if (tspec.it_value.tv_sec < 2 && count < 10) {
   tspec.it_value.tv_sec = 4;
   timer_settime(g_ts.timer_id, 0, &tspec, ((void *)0));
   count ++;
  }
  sleep(1);
 }
}

canonical_original_code:
void test_timer_create()
{
 struct sigevent sige;
 struct itimerspec tspec;
 long ret;
 int count = 0;
 signal(14, sig_handler);
 sige.sigev_value.sival_ptr = &g_ts;
 sige.sigev_signo = 14;
 sige.sigev_notify = SIGEV_THREAD;
 sige._sigev_un._sigev_thread._function = timer_thread;
 sige._sigev_un._sigev_thread._attribute = ((void *)0);
 ret = timer_create(0, &sige, &g_ts.timer_id);
 if (ret) {
  printf("timer_create error:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  return ;
 }
 g_ts.tick.it_value.tv_sec = 0;
 g_ts.tick.it_value.tv_nsec = 0;
 g_ts.tick.it_interval.tv_sec = 0;
 g_ts.tick.it_interval.tv_nsec = 0;
 timer_settime(g_ts.timer_id, 0, &g_ts.tick, ((void *)0));
 while(1) {
  timer_gettime(g_ts.timer_id, &tspec);
  printf("still it_value=%d.%d it_interval=%d.%d seconds.\n",
    tspec.it_value.tv_sec,
    tspec.it_value.tv_nsec,
    tspec.it_interval.tv_sec,
    tspec.it_interval.tv_nsec);
  if (tspec.it_value.tv_sec < 2 && count < 10) {
   tspec.it_value.tv_sec = 4;
   timer_settime(g_ts.timer_id, 0, &tspec, ((void *)0));
   count ++;
  }
  sleep(1);
 }
}

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

variable_types: struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; }

variable_types: ret long

variable_types: count int

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


decompiled_code:
int test_setitimer()
{
struct itimerval v1; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

v1.it_value.tv_sec = 3LL;
v1.it_value.tv_usec = 0LL;
v1.it_interval.tv_sec = 3LL;
v1.it_interval.tv_usec = 0LL;
newa.it_value.tv_sec = 3LL;
newa.it_value.tv_usec = 0LL;
newa.it_interval.tv_sec = 5LL;
newa.it_interval.tv_usec = 0LL;
signal(14, (__sighandler_t)sig_handler);
if ( !setitimer(ITIMER_REAL, &v1, 0LL) && !setitimer(ITIMER_REAL, &newa, 0LL) )
{
while ( 1 )
pause();
}
return puts("set timer failed");
}

canonical_decompiled_code:
int func6()
{
struct itimerval v1; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

v1.it_value.tv_sec = 3LL;
v1.it_value.tv_usec = 0LL;
v1.it_interval.tv_sec = 3LL;
v1.it_interval.tv_usec = 0LL;
newa.it_value.tv_sec = 3LL;
newa.it_value.tv_usec = 0LL;
newa.it_interval.tv_sec = 5LL;
newa.it_interval.tv_usec = 0LL;
signal(14, (__sighandler_t)sig_handler);
if ( !setitimer(ITIMER_REAL, &v1, 0LL) && !setitimer(ITIMER_REAL, &newa, 0LL) )
{
while ( 1 )
pause();
}
return puts("set timer failed");
}

original_code:
void test_setitimer(void)
{
 int ret;
 struct itimerval tick1;
 struct itimerval tick2;
 tick1.it_value.tv_sec = 3;
 tick1.it_value.tv_usec = 0;
 tick1.it_interval.tv_sec = 3;
 tick1.it_interval.tv_usec = 0;
 tick2.it_value.tv_sec = 3;
 tick2.it_value.tv_usec = 0;
 tick2.it_interval.tv_sec = 5;
 tick2.it_interval.tv_usec = 0;
 signal(14, sig_handler);
 ret = setitimer(ITIMER_REAL, &tick1, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 ret = setitimer(ITIMER_REAL, &tick2, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 while(1) {
  pause();
 }
}

canonical_original_code:
void test_setitimer()
{
 int ret;
 struct itimerval tick1;
 struct itimerval tick2;
 tick1.it_value.tv_sec = 3;
 tick1.it_value.tv_usec = 0;
 tick1.it_interval.tv_sec = 3;
 tick1.it_interval.tv_usec = 0;
 tick2.it_value.tv_sec = 3;
 tick2.it_value.tv_usec = 0;
 tick2.it_interval.tv_sec = 5;
 tick2.it_interval.tv_usec = 0;
 signal(14, sig_handler);
 ret = setitimer(ITIMER_REAL, &tick1, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 ret = setitimer(ITIMER_REAL, &tick2, ((void *)0));
 if (ret) {
  printf("set timer failed\n");
  return;
 }
 while(1) {
  pause();
 }
}

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // r13
__int64 v6; // r12
__int64 v7; // r14
int v8; // ebx
int v9; // er15
int v10; // er8
int v11; // eax
int v12; // ebx
int v13; // ebx
int v14; // er12

v3 = bw_timer_create_queue(argc, argv, envp);
if ( v3 )
{
v4 = v3;
v5 = bw_timer_create_timer(5LL, 0LL, 1LL, 0LL, tm1_handler, "hello");
v6 = bw_timer_create_timer(4LL, 0LL, 2LL, 0LL, tm2_handler, "hello");
v7 = bw_timer_create_timer(6LL, 0LL, 3LL, 0LL, tm3_handler, "hello");
if ( v6 == 0 || v5 == 0 || !v7 )
{
puts("Create timer 2 failed.");
}
else
{
gettimeofday(&tm1_last, 0LL);
v8 = bw_timer_queue_timer(v4, v5);
gettimeofday(&tm2_last, 0LL);
v9 = bw_timer_queue_timer(v4, v6);
gettimeofday(&tm3_last, 0LL);
v10 = bw_timer_queue_timer(v4, v7);
v11 = v8;
v12 = 10;
if ( v10 | v9 | v11 )
{
puts("Queue timer failed.");
}
else
{
do
{
sleep(1u);
--v12;
}
while ( v12 );
v13 = bw_timer_unqueue_timer(v4, v5);
v14 = bw_timer_unqueue_timer(v4, v6);
if ( !((unsigned int)bw_timer_unqueue_timer(v4, v7) | v14 | v13) )
{
while ( 1 )
sleep(1u);
}
puts("Unqueue timer failed.");
}
}
}
else
{
puts("Create timer queue failed.");
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct timeval tm1_begin = {.tv_sec=5, .tv_usec=0,},
         tm1_tick = {.tv_sec=1, .tv_usec=0,},
         tm2_begin = {.tv_sec=4, .tv_usec=0,},
         tm2_tick = {.tv_sec=2, .tv_usec=0,},
         tm3_begin = {.tv_sec=6, .tv_usec=0,},
         tm3_tick = {.tv_sec=3, .tv_usec=0,};
 char *args = "hello";
 int ret1, ret2, ret3, i;
 bw_timer_queue_t *queue;
 bw_timer_timer_t *tm1, *tm2, *tm3;
 queue = bw_timer_create_queue();
 if (!queue) {
  printf("Create timer queue failed.\n");
  goto out;
 }
 tm1 = bw_timer_create_timer(tm1_begin, tm1_tick, tm1_handler, args);
 tm2 = bw_timer_create_timer(tm2_begin, tm2_tick, tm2_handler, args);
 tm3 = bw_timer_create_timer(tm3_begin, tm3_tick, tm3_handler, args);
 if (!tm1 || !tm2 || !tm3) {
  printf("Create timer 2 failed.\n");
  goto out;
 }
 gettimeofday(&tm1_last, ((void *)0));
 ret1 = bw_timer_queue_timer(queue, tm1);
 gettimeofday(&tm2_last, ((void *)0));
 ret2 = bw_timer_queue_timer(queue, tm2);
 gettimeofday(&tm3_last, ((void *)0));
 ret3 = bw_timer_queue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Queue timer failed.\n");
  goto out;
 }
 for (i=0; i<10; i++)
  sleep(1);
 ret1 = bw_timer_unqueue_timer(queue, tm1);
 ret2 = bw_timer_unqueue_timer(queue, tm2);
 ret3 = bw_timer_unqueue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Unqueue timer failed.\n");
  goto out;
 }
 while (1)
  sleep(1);
out:
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct timeval tm1_begin = {.tv_sec=5, .tv_usec=0,}; struct timeval tm1_tick = {.tv_sec=1, .tv_usec=0,}; struct timeval tm2_begin = {.tv_sec=4, .tv_usec=0,}; struct timeval tm2_tick = {.tv_sec=2, .tv_usec=0,}; struct timeval tm3_begin = {.tv_sec=6, .tv_usec=0,}; struct timeval tm3_tick = {.tv_sec=3, .tv_usec=0,};
 char *args = "hello";
 int ret1; int ret2; int ret3; int i;
 struct _bw_timer_queue *queue;
 struct _bw_timer_timer *tm1; struct _bw_timer_timer *tm2; struct _bw_timer_timer *tm3;
 queue = bw_timer_create_queue();
 if (!queue) {
  printf("Create timer queue failed.\n");
  goto out;
 }
 tm1 = bw_timer_create_timer(tm1_begin, tm1_tick, tm1_handler, args);
 tm2 = bw_timer_create_timer(tm2_begin, tm2_tick, tm2_handler, args);
 tm3 = bw_timer_create_timer(tm3_begin, tm3_tick, tm3_handler, args);
 if (!tm1 || !tm2 || !tm3) {
  printf("Create timer 2 failed.\n");
  goto out;
 }
 gettimeofday(&tm1_last, ((void *)0));
 ret1 = bw_timer_queue_timer(queue, tm1);
 gettimeofday(&tm2_last, ((void *)0));
 ret2 = bw_timer_queue_timer(queue, tm2);
 gettimeofday(&tm3_last, ((void *)0));
 ret3 = bw_timer_queue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Queue timer failed.\n");
  goto out;
 }
 for (i=0; i<10; i++)
  sleep(1);
 ret1 = bw_timer_unqueue_timer(queue, tm1);
 ret2 = bw_timer_unqueue_timer(queue, tm2);
 ret3 = bw_timer_unqueue_timer(queue, tm3);
 if (ret1 || ret2 || ret3) {
  printf("Unqueue timer failed.\n");
  goto out;
 }
 while (1)
  sleep(1);
out:
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
args
char *

variable_types: i int

variable_types: struct _bw_timer_queue { struct bw_list_head { struct bw_list_head *next; } tmq_list; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } tmq_sige; void *tmq_id; struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; } tmq_timeo; int tmq_count; } *

variable_types: struct _bw_timer_timer { struct bw_list_head { struct bw_list_head *next; } tm_node; int (*tm_handler)(void *); void *tm_args; struct timeval { long tv_sec; long tv_usec; } tm_begin; struct timeval tm_tick; struct timeval tm_timeo; } *

user_defined_types: struct _bw_timer_queue { struct bw_list_head tmq_list; struct sigevent tmq_sige; void *tmq_id; struct itimerspec tmq_timeo; int tmq_count; }

user_defined_types: struct _bw_timer_timer { struct bw_list_head tm_node; int (*tm_handler)(void *); void *tm_args; struct timeval tm_begin; struct timeval tm_tick; struct timeval tm_timeo; }


decompiled_code:
// attributes: thunk
int alloc_keep(int fd, off_t offset, off_t len)
{
return posix_fallocate(fd, offset, len);
}

canonical_decompiled_code:
int func7(int fd, off_t offset, off_t len)
{
return posix_fallocate(fd, offset, len);
}

original_code:
int alloc_keep(int fd, loff_t off, loff_t len)
{
 return posix_fallocate(fd, off, len);
}

canonical_original_code:
int alloc_keep(int fd, long off, long len)
{
 return posix_fallocate(fd, off, len);
}

variable_types: fd int

variable_types: off long

variable_types: len long


decompiled_code:
// attributes: thunk
int __fastcall alloc_unkeep(int fd, off_t offset, off_t len)
{
return alloc_keep(fd, offset, len);
}

canonical_decompiled_code:
int __fastcall func8(int fd, off_t offset, off_t len)
{
return func7(fd, offset, len);
}

original_code:
int alloc_unkeep(int fd, loff_t off, loff_t len)
{
 return posix_fallocate(fd, off, len);
}

canonical_original_code:
int alloc_unkeep(int fd, long off, long len)
{
 return posix_fallocate(fd, off, len);
}


test

decompiled_code:
int __fastcall test(__int64 a1)
{
int v2; // edi
unsigned int v3; // ebp
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax

if ( !calloc(1uLL, *(_QWORD *)(a1 + 24)) )
{
puts("Can not alloc mem.");
return puts("test failed.");
}
v2 = open(*(const char **)a1, 66, 420LL);
if ( v2 >= 0 )
{
v3 = alloc_keep(v2, *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( !v3 )
return puts("test succeed.");
v5 = __errno_location();
v6 = strerror(*v5);
printf("Can not fallocate file.ret = %d (%d)%s\n", v3, (unsigned int)*v5, v6);
return puts("test failed.");
}
v7 = __errno_location();
v8 = strerror(*v7);
printf("Can not open file.(%d)%s\n", (unsigned int)*v7, v8);
return puts("test failed.");
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int v2; // edi
unsigned int v3; // ebp
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax

if ( !calloc(1uLL, *(_QWORD *)(a1 + 24)) )
{
puts("Can not alloc mem.");
return puts("test failed.");
}
v2 = open(*(const char **)a1, 66, 420LL);
if ( v2 >= 0 )
{
v3 = func7(v2, *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
if ( !v3 )
return puts("test succeed.");
v5 = __errno_location();
v6 = strerror(*v5);
printf("Can not fallocate file.ret = %d (%d)%s\n", v3, (unsigned int)*v5, v6);
return puts("test failed.");
}
v7 = __errno_location();
v8 = strerror(*v7);
printf("Can not open file.(%d)%s\n", (unsigned int)*v7, v8);
return puts("test failed.");
}

original_code:
void test(const struct options *opts)
{
 int fd = 0, ret = 0;
 loff_t off_now = 0;
 char *buf = ((void *)0);
 ssize_t write_bytes = 0;
 buf = calloc(1, opts->len);
 if (!buf) {
  printf("Can not alloc mem.\n");
  goto failed;
 }
 fd = open(opts->file_path, (02|0100), 0644);
 if (fd < 0) {
  printf("Can not open file.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 if (opts->keep)
  ret = alloc_keep(fd, opts->off, opts->len);
 else
  ret = alloc_unkeep(fd, opts->off, opts->len);
 if (ret) {
  printf("Can not fallocate file.ret = %d (%d)%s\n", ret, (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 printf("test succeed.\n");
 return ;
failed:
 printf("test failed.\n");
 return ;
}

canonical_original_code:
void test(struct options *opts)
{
 int fd = 0; int ret = 0;
 long off_now = 0;
 char *buf = ((void *)0);
 long write_bytes = 0;
 buf = calloc(1, opts->len);
 if (!buf) {
  printf("Can not alloc mem.\n");
  goto failed;
 }
 fd = open(opts->file_path, (02|0100), 0644);
 if (fd < 0) {
  printf("Can not open file.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 if (opts->keep)
  ret = alloc_keep(fd, opts->off, opts->len);
 else
  ret = alloc_unkeep(fd, opts->off, opts->len);
 if (ret) {
  printf("Can not fallocate file.ret = %d (%d)%s\n", ret, (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 printf("test succeed.\n");
 return ;
failed:
 printf("test failed.\n");
 return ;
}

variable_types: struct options { char *file_path; int keep; long off; long len; } *

variable_types: ret int

variable_types:
buf
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int128 v5; // [rsp+0h] [rbp-28h] BYREF
__int128 v6; // [rsp+10h] [rbp-18h]

v5 = 0LL;
v6 = 0LL;
if ( (unsigned int)parse_args(argc, argv, &v5) )
return -1;
v3 = 0;
puts("test info:");
printf("\tfile_path=%s\n", (const char *)v5);
printf("\tkeep=%d\n", DWORD2(v5));
printf("\toffset=%lld\n", (_QWORD)v6);
printf("\tlength=%lld\n", *((_QWORD *)&v6 + 1));
test(&v5);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int128 v5; // [rsp+0h] [rbp-28h] BYREF
__int128 v6; // [rsp+10h] [rbp-18h]

v5 = 0LL;
v6 = 0LL;
if ( (unsigned int)func10(argc, argv, &v5) )
return -1;
v3 = 0;
puts("test info:");
printf("\tfile_path=%s\n", (const char *)v5);
printf("\tkeep=%d\n", DWORD2(v5));
printf("\toffset=%lld\n", (_QWORD)v6);
printf("\tlength=%lld\n", *((_QWORD *)&v6 + 1));
func9(&v5);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 struct options opts = {0};
 if (parse_args(argc, argv, &opts))
  return -1;
 printf("test info:\n");
 printf("\tfile_path=%s\n", opts.file_path);
 printf("\tkeep=%d\n", opts.keep);
 printf("\toffset=%lld\n", opts.off);
 printf("\tlength=%lld\n", opts.len);
 test(&opts);
 return 0;
}

variable_types: struct options { char *file_path; int keep; long off; long len; }


decompiled_code:
__int64 __fastcall parse_args(int a1, __int64 a2, __int64 a3)
{
int v5; // er13
int v6; // ebx
__int64 v7; // rdi
__int64 v8; // rdx
__int64 result; // rax

*(_DWORD *)(a3 + 8) = 1;
*(_QWORD *)(a3 + 16) = 1024LL;
*(_QWORD *)(a3 + 24) = 4096LL;
if ( a1 > 1 )
{
v5 = a1 - 1;
v6 = 1;
while ( 1 )
{
v7 = *(_QWORD *)(a2 + 8LL * v6);
v8 = 8LL * v6;
if ( *(_BYTE *)v7 != 45 )
break;
if ( *(_BYTE *)(v7 + 1) == 111 && !*(_BYTE *)(v7 + 2) )
{
if ( v5 == v6 )
{
puts("missing args for -o");
return 1LL;
}
++v6;
*(_QWORD *)(a3 + 16) = atoll(*(const char **)(a2 + v8 + 8));
goto LABEL_5;
}
if ( *(_BYTE *)(v7 + 1) == 108 && !*(_BYTE *)(v7 + 2) )
{
if ( v5 == v6 )
{
LABEL_25:
puts("missing args for -l");
return 1LL;
}
++v6;
*(_QWORD *)(a3 + 24) = atoll(*(const char **)(a2 + v8 + 8));
goto LABEL_5;
}
if ( *(_BYTE *)(v7 + 1) != 109 || *(_BYTE *)(v7 + 2) )
break;
if ( v5 == v6 )
goto LABEL_25;
++v6;
if ( !strcmp(*(const char **)(a2 + v8 + 8), "keep_size") )
{
++v6;
*(_DWORD *)(a3 + 8) = 1;
if ( a1 <= v6 )
goto LABEL_14;
}
else
{
if ( strcmp(*(const char **)(a2 + v8 + 8), "unkeep_size") )
{
printf("Unkown args %s for -m\n", *(const char **)(a2 + v8 + 8));
return 1LL;
}
*(_DWORD *)(a3 + 8) = 0;
LABEL_5:
if ( a1 <= ++v6 )
goto LABEL_14;
}
}
if ( *(_QWORD *)a3 )
{
printf("invalid option %s.\n", *(const char **)(a2 + 8LL * v6));
return 1LL;
}
*(_QWORD *)a3 = strdup((const char *)v7);
goto LABEL_5;
}
LABEL_14:
result = 0LL;
if ( !*(_QWORD *)a3 )
{
puts("provide a file path");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, __int64 a3)
{
int v5; // er13
int v6; // ebx
__int64 v7; // rdi
__int64 v8; // rdx
__int64 result; // rax

*(_DWORD *)(a3 + 8) = 1;
*(_QWORD *)(a3 + 16) = 1024LL;
*(_QWORD *)(a3 + 24) = 4096LL;
if ( a1 > 1 )
{
v5 = a1 - 1;
v6 = 1;
while ( 1 )
{
v7 = *(_QWORD *)(a2 + 8LL * v6);
v8 = 8LL * v6;
if ( *(_BYTE *)v7 != 45 )
break;
if ( *(_BYTE *)(v7 + 1) == 111 && !*(_BYTE *)(v7 + 2) )
{
if ( v5 == v6 )
{
puts("missing args for -o");
return 1LL;
}
++v6;
*(_QWORD *)(a3 + 16) = atoll(*(const char **)(a2 + v8 + 8));
goto LABEL_5;
}
if ( *(_BYTE *)(v7 + 1) == 108 && !*(_BYTE *)(v7 + 2) )
{
if ( v5 == v6 )
{
LABEL_25:
puts("missing args for -l");
return 1LL;
}
++v6;
*(_QWORD *)(a3 + 24) = atoll(*(const char **)(a2 + v8 + 8));
goto LABEL_5;
}
if ( *(_BYTE *)(v7 + 1) != 109 || *(_BYTE *)(v7 + 2) )
break;
if ( v5 == v6 )
goto LABEL_25;
++v6;
if ( !strcmp(*(const char **)(a2 + v8 + 8), "keep_size") )
{
++v6;
*(_DWORD *)(a3 + 8) = 1;
if ( a1 <= v6 )
goto LABEL_14;
}
else
{
if ( strcmp(*(const char **)(a2 + v8 + 8), "unkeep_size") )
{
printf("Unkown args %s for -m\n", *(const char **)(a2 + v8 + 8));
return 1LL;
}
*(_DWORD *)(a3 + 8) = 0;
LABEL_5:
if ( a1 <= ++v6 )
goto LABEL_14;
}
}
if ( *(_QWORD *)a3 )
{
printf("invalid option %s.\n", *(const char **)(a2 + 8LL * v6));
return 1LL;
}
*(_QWORD *)a3 = strdup((const char *)v7);
goto LABEL_5;
}
LABEL_14:
result = 0LL;
if ( !*(_QWORD *)a3 )
{
puts("provide a file path");
result = 1LL;
}
return result;
}

original_code:
int parse_args(int argc, char *argv[], struct options *opts)
{
 int i;
 opts->keep = 1;
 opts->off = 1024;
 opts->len = 4096;
 for (i=1; i<argc; i++) {
  if (strcmp(argv[i], "-o") == 0) {
   if (i == argc-1) {
    printf("missing args for -o\n");
    goto failed;
   }
   opts->off = atoll(argv[++i]);
  } else if (strcmp(argv[i], "-l") == 0) {
   if (i == argc-1) {
    printf("missing args for -l\n");
    goto failed;
   }
   opts->len = atoll(argv[++i]);
  } else if (strcmp(argv[i], "-m") == 0) {
   if (i == argc-1) {
    printf("missing args for -l\n");
    goto failed;
   }
   i++;
   if (strcmp(argv[i], "keep_size") == 0) {
    opts->keep = 1;
   } else if (strcmp(argv[i], "unkeep_size") == 0) {
    opts->keep = 0;
   } else {
    printf("Unkown args %s for -m\n", argv[i]);
    goto failed;
   }
  } else {
   if (!opts->file_path) {
    opts->file_path = strdup(argv[i]);
   } else {
    printf("invalid option %s.\n", argv[i]);
    goto failed;
   }
  }
 }
 if (!opts->file_path) {
  printf("provide a file path\n");
  goto failed;
 }
 return 0;
failed:
 return 1;
}

user_defined_types: struct options { char *file_path; int keep; long off; long len; }


decompiled_code:
int test_string_array()
{
printf("%s\t", "sd");
printf("%s\t", "ssd");
printf("%s\t", "hd");
putchar(10);
printf("%s\t", "md");
printf("%s\t", "dm");
putchar(10);
return printf("%llu\n", -1LL);
}

canonical_decompiled_code:
int func7()
{
printf("%s\t", "sd");
printf("%s\t", "ssd");
printf("%s\t", "hd");
putchar(10);
printf("%s\t", "md");
printf("%s\t", "dm");
putchar(10);
return printf("%llu\n", -1LL);
}

original_code:
void test_string_array(void)
{
 int i, j;
 for (i=0; i<2; i++) {
  for (j=0; j<3; j++) {
   if (bwlc_scan_keyword[i][j] != ((void *)0))
    printf("%s\t", bwlc_scan_keyword[i][j]);
  }
  printf("\n");
 }
 printf("%llu\n", (uint64_t)-1);
 return ;
}

canonical_original_code:
void test_string_array()
{
 int i; int j;
 for (i=0; i<2; i++) {
  for (j=0; j<3; j++) {
   if (bwlc_scan_keyword[i][j] != ((void *)0))
    printf("%s\t", bwlc_scan_keyword[i][j]);
  }
  printf("\n");
 }
 printf("%llu\n", (unsigned long)-1);
 return ;
}

variable_types: j int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("block:%s\n", "block/sda");
printf("first '/:'%s\n", "/sda");
printf("last '/':%s\n", "/sda");
printf("find device:%s\n", "sda");
test_string_array();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("block:%s\n", "block/sda");
printf("first '/:'%s\n", "/sda");
printf("last '/':%s\n", "/sda");
printf("find device:%s\n", "sda");
func7();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *source = "/sys/devices/pci0000:00/0000:00:07.1/host0/target0:0:0/0:0:0:0/block/sda";
 char *block = ((void *)0);
 char *first = ((void *)0);
 char *last = ((void *)0);
 block = strstr(source, "block");
 if (!block)
  goto out;
 printf("block:%s\n", block);
 first = index(block, '/');
 if (!first)
  goto out;
 printf("first '/:'%s\n", first);
 last = rindex(block, '/');
 if (!last)
  goto out;
 printf("last '/':%s\n", last);
 if (first != last)
  goto out;
 printf("find device:%s\n", last+1);
 test_string_array();
out:
 return 0;
}

variable_types:
source
char *

variable_types:
block
char *

variable_types:
first
char *

variable_types:
last
char *


decompiled_code:
__int64 __fastcall bwlc_handle_dev_msg(const char **a1)
{
printf("recieve msg:type=%d,devpath=%s\n", *(unsigned int *)a1, a1[1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char **a1)
{
printf("recieve msg:type=%d,devpath=%s\n", *(unsigned int *)a1, a1[1]);
return 0LL;
}

original_code:
int32_t bwlc_handle_dev_msg(bwlc_devent_msg_t *devent)
{
 printf("recieve msg:type=%d,devpath=%s\n", devent->event_type, devent->dev_path);
 return 0;
}

canonical_original_code:
int bwlc_handle_dev_msg(struct _bwlc_devent_msg *devent)
{
 printf("recieve msg:type=%d,devpath=%s\n", devent->event_type, devent->dev_path);
 return 0;
}

variable_types: struct _bwlc_devent_msg { enum _bwlc_devent_type { BWLC_DEV_ARRIVE=1, BWLC_DEV_REMOVE=2 } event_type; char *dev_path; } *

user_defined_types: struct _bwlc_devent_msg { enum _bwlc_devent_type event_type; char *dev_path; }