decompiled_code:
__int64 prev_bitrate()
{
signed int v0; // er8
unsigned int *v1; // rax

v0 = *(_DWORD *)(proxy_stat + 72LL);
v1 = (unsigned int *)(proxy_stat + 68LL);
while ( (int)*v1 >= v0 )
{
if ( --v1 == (unsigned int *)(proxy_stat + 52LL) )
return (unsigned int)v0;
}
return *v1;
}

canonical_decompiled_code:
__int64 func1()
{
signed int v0; // er8
unsigned int *v1; // rax

v0 = *(_DWORD *)(proxy_stat + 72LL);
v1 = (unsigned int *)(proxy_stat + 68LL);
while ( (int)*v1 >= v0 )
{
if ( --v1 == (unsigned int *)(proxy_stat + 52LL) )
return (unsigned int)v0;
}
return *v1;
}

original_code:
int prev_bitrate()
{
 int cur_bitrate = proxy_stat->bitrate;
 int prev_bitrate = proxy_stat->bitrate;
 for(int i=3; i>=0; i--){
  if(proxy_stat->bitrates[i]<cur_bitrate){
   prev_bitrate = proxy_stat->bitrates[i];
   break;
  }
 }
 return prev_bitrate;
}

canonical_original_code:
int prev_bitrate()
{
 int cur_bitrate = proxy_stat->bitrate;
 int prev_bitrate = proxy_stat->bitrate;
 for(int i = 3; i>=0; i--){
  if(proxy_stat->bitrates[i]<cur_bitrate){
   prev_bitrate = proxy_stat->bitrates[i];
   break;
  }
 }
 return prev_bitrate;
}


original_code:
void update_bitrate(long long t1, long long t2, int size, int bit, char* chunkname, char *client_ip)
{
 if(t2-t1 < 10){
  return;
 }
 float alpha = proxy_stat->alpha;
 float t = (float)(((float)size)/((float)(t2-t1))) * 8000;
 proxy_stat->t = alpha*t + (1.0-alpha)*proxy_stat->t;
 int next = next_bitrate();
 int prev = prev_bitrate();
 if(proxy_stat->t > 1.5*next*1000){
  proxy_stat->bitrate = next;
 }
 if(proxy_stat->t < 1.5*proxy_stat->bitrate*1000){
  proxy_stat->bitrate = prev;
 }
 if(verbal)
  fprintf(stdout,"---------------------throughput = %lf -------------------\n",t/1000);
 fprintf(stdout,"%.2f    %.2f   %d\n",t/1000,proxy_stat->t/1000,bit);
 logWrite((float)(t2-t1)/1000, t/1000, proxy_stat->t/1000, bit, client_ip, chunkname);
}

canonical_original_code:
void update_bitrate(long long t1, long long t2, int size, int bit, char *chunkname, char *client_ip)
{
 if(t2-t1 < 10){
  return;
 }
 float alpha = proxy_stat->alpha;
 float t = (float)(((float)size)/((float)(t2-t1))) * 8000;
 proxy_stat->t = alpha*t + (1.0-alpha)*proxy_stat->t;
 int next = next_bitrate();
 int prev = prev_bitrate();
 if(proxy_stat->t > 1.5*next*1000){
  proxy_stat->bitrate = next;
 }
 if(proxy_stat->t < 1.5*proxy_stat->bitrate*1000){
  proxy_stat->bitrate = prev;
 }
 if(verbal)
  fprintf(stdout,"---------------------throughput = %lf -------------------\n",t/1000);
 fprintf(stdout,"%.2f    %.2f   %d\n",t/1000,proxy_stat->t/1000,bit);
 logWrite((float)(t2-t1)/1000, t/1000, proxy_stat->t/1000, bit, client_ip, chunkname);
}

variable_types: size int

variable_types: bit int

variable_types:
chunkname
char *

variable_types: alpha float

variable_types: t float

variable_types: next int

variable_types: prev int

return_type: void


decompiled_code:
__int64 __fastcall construct_request_packet(__int64 a1, __int64 a2, _DWORD *a3)
{
*(_QWORD *)a2 = 0x100010000LL;
*(_DWORD *)(a2 + 8) = 0;
sprintf(
(char *)(a2 + 12),
"%c%s%c%s%c%s%c%s%c%c%c%c%c",
5LL,
"video",
2LL,
"cs",
3LL,
"cmu",
3LL,
"edu",
0LL,
0LL,
1LL,
0LL,
1LL);
*a3 = 34;
return 0LL;
}

original_code:
int construct_request_packet(const char *node, char *buf, int *len)
{
 int header_len = sizeof(header_t);
 header_t header = {0};
 header.qr = 1;
 header.qdcount = 1;
 memcpy(buf, &header, header_len);
 int question_len = 22;
 sprintf(buf+header_len,"%c%s%c%s%c%s%c%s%c%c%c%c%c",5,"video",2,"cs",3,"cmu",3,"edu",0,0,1,0,1);
 *len = header_len+question_len;
 return 0;
}

canonical_original_code:
int construct_request_packet(char *node, char *buf, int *len)
{
 int header_len = sizeof(header_t);
 struct header header = {0};
 header.qr = 1;
 header.qdcount = 1;
 memcpy(buf, &header, header_len);
 int question_len = 22;
 sprintf(buf+header_len,"%c%s%c%s%c%s%c%s%c%c%c%c%c",5,"video",2,"cs",3,"cmu",3,"edu",0,0,1,0,1);
 *len = header_len+question_len;
 return 0;
}

variable_types:
node
char *

variable_types:
buf
char *

variable_types:
len
int *

variable_types: struct header { unsigned int id; unsigned int qr; unsigned int opcode; unsigned int aa; unsigned int tc; unsigned int rd; unsigned int ra; unsigned int z; unsigned int rcode; unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; }

return_type: int


decompiled_code:
__int64 __fastcall parse_dns_response(__int64 a1, char *a2)
{
printf("response = %s\n", (const char *)a1);
printf("response = %s\n", (const char *)(a1 + 34));
sprintf(
a2,
"%hu.%hu.%hu.%hu",
(unsigned __int8)BYTE4(*(_QWORD *)(a1 + 42)),
(unsigned __int8)((unsigned __int16)WORD2(*(_QWORD *)(a1 + 42)) >> 8),
(unsigned __int8)BYTE6(*(_QWORD *)(a1 + 42)),
HIBYTE(*(_QWORD *)(a1 + 42)));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char *a2)
{
printf("response = %s\n", (const char *)a1);
printf("response = %s\n", (const char *)(a1 + 34));
sprintf(
a2,
"%hu.%hu.%hu.%hu",
(unsigned __int8)BYTE4(*(_QWORD *)(a1 + 42)),
(unsigned __int8)((unsigned __int16)WORD2(*(_QWORD *)(a1 + 42)) >> 8),
(unsigned __int8)BYTE6(*(_QWORD *)(a1 + 42)),
HIBYTE(*(_QWORD *)(a1 + 42)));
return 0LL;
}

original_code:
int parse_dns_response(char *buf, char *ip)
{
 printf("response = %s\n", buf);
 char *answer_buf = buf+sizeof(header_t)+22;
 printf("response = %s\n", answer_buf);
 answer_t answer = {0};
 memcpy(&answer, answer_buf, sizeof(answer_t));
 sprintf(ip,"%hu.%hu.%hu.%hu",answer.ip1,answer.ip2,answer.ip3,answer.ip4);
 return 0;
}

canonical_original_code:
int parse_dns_response(char *buf, char *ip)
{
 printf("response = %s\n", buf);
 char *answer_buf = buf+sizeof(header_t)+22;
 printf("response = %s\n", answer_buf);
 struct answer answer = {0};
 memcpy(&answer, answer_buf, sizeof(answer_t));
 sprintf(ip,"%hu.%hu.%hu.%hu",answer.ip1,answer.ip2,answer.ip3,answer.ip4);
 return 0;
}

variable_types:
ip
char *

variable_types: struct answer { unsigned int name; unsigned int type; unsigned int _class; unsigned int ttl; unsigned int ttl2; unsigned int rdlength; unsigned int ip1; unsigned int ip2; unsigned int ip3; unsigned int ip4; }


checkbuf

decompiled_code:
size_t __fastcall checkbuf(unsigned __int8 *a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
size_t result; // rax

if ( verbal > 2 )
{
v2 = 0LL;
fprintf(stdout, "\n***********len:%d - %p**************\n", (unsigned int)a2, a1);
if ( a2 <= 0 )
return fwrite("\n*************************\n\n", 1uLL, 0x1CuLL, stdout);
while ( 1 )
{
if ( (v2 & 1) != 0 )
{
if ( (v2 & 0xF) == 0 )
goto LABEL_8;
}
else
{
fputc(32, stdout);
if ( (v2 & 0xF) == 0 )
{
LABEL_8:
fputc(10, stdout);
goto LABEL_5;
}
}
LABEL_5:
v3 = a1[v2++];
fprintf(stdout, "%2x", v3);
if ( a2 == v2 )
return fwrite("\n*************************\n\n", 1uLL, 0x1CuLL, stdout);
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(unsigned __int8 *a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
size_t result; // rax

if ( verbal > 2 )
{
v2 = 0LL;
fprintf(stdout, "\n***********len:%d - %p**************\n", (unsigned int)a2, a1);
if ( a2 <= 0 )
return fwrite("\n*************************\n\n", 1uLL, 0x1CuLL, stdout);
while ( 1 )
{
if ( (v2 & 1) != 0 )
{
if ( (v2 & 0xF) == 0 )
goto LABEL_8;
}
else
{
fputc(32, stdout);
if ( (v2 & 0xF) == 0 )
{
LABEL_8:
fputc(10, stdout);
goto LABEL_5;
}
}
LABEL_5:
v3 = a1[v2++];
fprintf(stdout, "%2x", v3);
if ( a2 == v2 )
return fwrite("\n*************************\n\n", 1uLL, 0x1CuLL, stdout);
}
}
return result;
}

original_code:
void checkbuf(char *buf,int len){
 if(verbal<=2) return;
 fprintf(stdout, "\n***********len:%d - %p**************\n",len,buf);
 for (int i=0;i<len;i++){
  if(i%2 == 0)
   fprintf(stdout, " ");
  if(i%16 == 0)
   fprintf(stdout, "\n");
  fprintf(stdout, "%2x",*(uint8_t *)(buf+i));
 }
 fprintf(stdout, "\n*************************\n\n");
}

canonical_original_code:
void checkbuf(char *buf, int len){
 if(verbal<=2) return;
 fprintf(stdout, "\n***********len:%d - %p**************\n",len,buf);
 for (int i = 0;i<len;i++){
  if(i%2 == 0)
   fprintf(stdout, " ");
  if(i%16 == 0)
   fprintf(stdout, "\n");
  fprintf(stdout, "%2x",*(unsigned char *)(buf+i));
 }
 fprintf(stdout, "\n*************************\n\n");
}

variable_types: len int

variable_types: i int


parseRequestData

original_code:
int parseRequestData(char *data,char *buf){
 if(verbal>1)
  fprintf(stdout, "-----------in parseRequestData----------\n");
 int len=0;
 char *ptr = data;
 int curr;
 while((curr=(int)*ptr)!=0){
  ptr++;
  strncpy(buf+len,ptr,curr);
  len+=curr;
  ptr+=curr;
  strncpy(buf+len,".",1);
  len++;
 }
 *(buf+len-1)=0;
 return 0;
}

canonical_original_code:
int parseRequestData(char *data, char *buf){
 if(verbal>1)
  fprintf(stdout, "-----------in parseRequestData----------\n");
 int len = 0;
 char *ptr = data;
 int curr;
 while((curr=(int)*ptr)!=0){
  ptr++;
  strncpy(buf+len,ptr,curr);
  len+=curr;
  ptr+=curr;
  strncpy(buf+len,".",1);
  len++;
 }
 *(buf+len-1)=0;
 return 0;
}

variable_types:
data
char *

variable_types:
ptr
char *

variable_types: curr int


getIP

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

if ( verbal > 1 )
fwrite("-----in getIP-----\n", 1uLL, 0x13uLL, stdout);
if ( *DNS_stat )
result = getIP_Robin(*(_QWORD *)(DNS_stat + 56LL));
else
result = getIP_LSAs(*(_QWORD *)(DNS_stat + 64LL), a1, *(_QWORD *)(DNS_stat + 56LL));
return result;
}

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

if ( verbal > 1 )
fwrite("-----in getIP-----\n", 1uLL, 0x13uLL, stdout);
if ( *DNS_stat )
result = getIP_Robin(*(_QWORD *)(DNS_stat + 56LL));
else
result = getIP_LSAs(*(_QWORD *)(DNS_stat + 64LL), a1, *(_QWORD *)(DNS_stat + 56LL));
return result;
}

canonical_original_code:
struct ip_t *getIP(char *clientIP){
 if(verbal>1)
  fprintf(stdout, "-----in getIP-----\n");
 if(DNS_stat->robinFlag){
  return getIP_Robin(DNS_stat->robin_list);
 }else{
  return getIP_LSAs(DNS_stat->lsaGraph, clientIP, DNS_stat->robin_list);
 }
 if(verbal>1)
   fprintf(stdout, "-----in getIP fail-----\n");
 return ((void *)0);
}

variable_types:
clientIP
char *

return_type: struct ip_t { char ip_str[20]; unsigned char ip[4]; } *


buildResponseData

decompiled_code:
__int64 __fastcall buildResponseData(void *src, size_t n, void *dest, __int64 a4)
{
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rax
__int64 result; // rax

if ( verbal > 1 )
fwrite("-----------in buildResponseData----------\n", 1uLL, 0x2AuLL, stdout);
memcpy(dest, src, n);
v6 = getIP(a4);
v7 = v6;
if ( v6 )
{
logWrite(a4, "video.cs.cmu.edu", v6);
v8 = *(unsigned int *)(v7 + 20);
*(_QWORD *)((char *)dest + n) = 0x10001000CC0LL;
*(_QWORD *)((char *)dest + n + 8) = (v8 << 32) | 0x4000000;
result = (unsigned int)(n + 16);
}
else
{
logWrite(a4, "video.cs.cmu.edu", &unk_591);
result = (unsigned int)n;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, size_t n, void *dest, __int64 a4)
{
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // rax
__int64 result; // rax

if ( verbal > 1 )
fwrite("-----------in buildResponseData----------\n", 1uLL, 0x2AuLL, stdout);
memcpy(dest, src, n);
v6 = func2(a4);
v7 = v6;
if ( v6 )
{
logWrite(a4, "video.cs.cmu.edu", v6);
v8 = *(unsigned int *)(v7 + 20);
*(_QWORD *)((char *)dest + n) = 0x10001000CC0LL;
*(_QWORD *)((char *)dest + n + 8) = (v8 << 32) | 0x4000000;
result = (unsigned int)(n + 16);
}
else
{
logWrite(a4, "video.cs.cmu.edu", &unk_591);
result = (unsigned int)n;
}
return result;
}

original_code:
int buildResponseData(char *request,size_t len, char* ret,char *clientIP){
 if(verbal>1)
  fprintf(stdout, "-----------in buildResponseData----------\n");
 memcpy(ret,request,len);
 ip_t *ip=getIP(clientIP);
 if(ip==((void *)0)){
  logWrite(clientIP,"video.cs.cmu.edu","");
   return len;
 }
 logWrite(clientIP,"video.cs.cmu.edu",ip->ip_str);
 answer_t answer;
 answer.name=0x0cc0;
   answer.type=0x100;
   answer._class=0x100;
 answer.ttl=0;
 answer.ttl2=0;
   answer.rdlength=0x400;
   answer.ip1=ip->ip[0];
   answer.ip2=ip->ip[1];
   answer.ip3=ip->ip[2];
   answer.ip4=ip->ip[3];
    memcpy(ret+len,&answer,sizeof(answer_t));
 return len+16;
}

canonical_original_code:
int buildResponseData(char *request, unsigned long len, char *ret, char *clientIP){
 if(verbal>1)
  fprintf(stdout, "-----------in buildResponseData----------\n");
 memcpy(ret,request,len);
 struct ip_t *ip = getIP(clientIP);
 if(ip==((void *)0)){
  logWrite(clientIP,"video.cs.cmu.edu","");
   return len;
 }
 logWrite(clientIP,"video.cs.cmu.edu",ip->ip_str);
 struct answer answer;
 answer.name=0x0cc0;
   answer.type=0x100;
   answer._class=0x100;
 answer.ttl=0;
 answer.ttl2=0;
   answer.rdlength=0x400;
   answer.ip1=ip->ip[0];
   answer.ip2=ip->ip[1];
   answer.ip3=ip->ip[2];
   answer.ip4=ip->ip[3];
    memcpy(ret+len,&answer,sizeof(answer_t));
 return len+16;
}

variable_types:
request
char *

variable_types:
len
unsigned long

variable_types:
ret
char *

variable_types: struct ip_t { char ip_str[20]; unsigned char ip[4]; } *

user_defined_types: struct answer { unsigned int name; unsigned int type; unsigned int _class; unsigned int ttl; unsigned int ttl2; unsigned int rdlength; unsigned int ip1; unsigned int ip2; unsigned int ip3; unsigned int ip4; }


parse

decompiled_code:
__int64 __fastcall parse(unsigned __int8 *a1, __int64 a2, _QWORD *a3)
{
void *v4; // r12
char *v5; // r15
unsigned __int16 v6; // ax
__int64 v7; // rbp
__int64 v8; // rbx
__int64 v9; // r12
unsigned __int16 v11; // [rsp+Eh] [rbp-83Ah]
__int128 v12; // [rsp+10h] [rbp-838h] BYREF
char v13[1008]; // [rsp+20h] [rbp-828h] BYREF
__int128 dest; // [rsp+410h] [rbp-438h] BYREF
char v15[1008]; // [rsp+420h] [rbp-428h] BYREF

if ( verbal > 1 )
fwrite("--------------in parse-------------\n", 1uLL, 0x24uLL, stdout);
v4 = a1 + 12;
checkbuf(a1, a2);
v5 = inet_ntoa((struct in_addr)HIDWORD(*a3));
memset(v13, 0, sizeof(v13));
v12 = 0LL;
memset(v15, 0, sizeof(v15));
v6 = *(_WORD *)a1;
dest = 0LL;
v11 = v6;
parseRequestData((char *)a1 + 12, (__int64)&v12);
fprintf(stdout, "name: %s\n", (const char *)&v12);
if ( !strcmp((const char *)&v12, "video.cs.cmu.edu") )
{
v7 = a2 - 12;
v8 = (unsigned int)buildResponseData(v4, a2 - 12, &dest, (__int64)v5);
v9 = construct_response_packet(v11, 0LL, v8, &dest, a3, 0.0);
checkbuf(*(unsigned __int8 **)(v9 + 24), v8 + 12);
LABEL_5:
fprintf(
stdout,
"%d.%d.%d.%d\n",
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 24),
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 25),
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 26),
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 27));
enqueue(*(_QWORD *)(DNS_stat + 40LL), v9);
goto LABEL_6;
}
logWrite(v5, &v12, "0.0.0.0");
v9 = construct_response_packet(v11, 3LL, (unsigned int)(a2 - 12), v4, a3, 0.0);
if ( v9 )
{
v7 = a2 - 12;
goto LABEL_5;
}
LABEL_6:
if ( verbal > 1 )
fwrite("--------------in parse - done-------------\n", 1uLL, 0x2BuLL, stdout);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, __int64 a2, _QWORD *a3)
{
void *v4; // r12
char *v5; // r15
unsigned __int16 v6; // ax
__int64 v7; // rbp
__int64 v8; // rbx
__int64 v9; // r12
unsigned __int16 v11; // [rsp+Eh] [rbp-83Ah]
__int128 v12; // [rsp+10h] [rbp-838h] BYREF
char v13[1008]; // [rsp+20h] [rbp-828h] BYREF
__int128 dest; // [rsp+410h] [rbp-438h] BYREF
char v15[1008]; // [rsp+420h] [rbp-428h] BYREF

if ( verbal > 1 )
fwrite("--------------in parse-------------\n", 1uLL, 0x24uLL, stdout);
v4 = a1 + 12;
func0(a1, a2);
v5 = inet_ntoa((struct in_addr)HIDWORD(*a3));
memset(v13, 0, sizeof(v13));
v12 = 0LL;
memset(v15, 0, sizeof(v15));
v6 = *(_WORD *)a1;
dest = 0LL;
v11 = v6;
func1((char *)a1 + 12, (__int64)&v12);
fprintf(stdout, "name: %s\n", (const char *)&v12);
if ( !strcmp((const char *)&v12, "video.cs.cmu.edu") )
{
v7 = a2 - 12;
v8 = (unsigned int)func3(v4, a2 - 12, &dest, (__int64)v5);
v9 = construct_response_packet(v11, 0LL, v8, &dest, a3, 0.0);
func0(*(unsigned __int8 **)(v9 + 24), v8 + 12);
LABEL_5:
fprintf(
stdout,
"%d.%d.%d.%d\n",
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 24),
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 25),
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 26),
(unsigned int)*(char *)(*(_QWORD *)(v9 + 24) + v7 + 27));
enqueue(*(_QWORD *)(DNS_stat + 40LL), v9);
goto LABEL_6;
}
logWrite(v5, &v12, "0.0.0.0");
v9 = construct_response_packet(v11, 3LL, (unsigned int)(a2 - 12), v4, a3, 0.0);
if ( v9 )
{
v7 = a2 - 12;
goto LABEL_5;
}
LABEL_6:
if ( verbal > 1 )
fwrite("--------------in parse - done-------------\n", 1uLL, 0x2BuLL, stdout);
return 0LL;
}

original_code:
int parse(char *buf,size_t len,SA *addr){
 if(verbal>1)
  fprintf(stdout, "--------------in parse-------------\n");
 checkbuf(buf,len);
 struct sockaddr_in tmpaddr = *((struct sockaddr_in*)addr);
  char* clientIP = inet_ntoa(tmpaddr.sin_addr);
 char name[1024] = {0};
 char data[1024] = {0};
 packet_t *packet = (packet_t *) buf;
 unsigned short requestID = packet->header.id;
 send_packet_t *sendPacket;
 parseRequestData(packet->data,name);
 fprintf(stdout,"name: %s\n",name);
 if(!strcmp(name,"video.cs.cmu.edu")){
  int datalen=buildResponseData(packet->data,len-12,data,clientIP);
     sendPacket=construct_response_packet(requestID,0,datalen,data,addr);
     checkbuf((char *)(sendPacket->data),datalen+12);
 }else{
  logWrite(clientIP,name,"0.0.0.0");
  sendPacket=construct_response_packet(requestID,3,len-12,packet->data,addr);
 }
 if(sendPacket!=((void *)0)){
  char *tmp = sendPacket->data->data;
  tmp+=len-12;
  fprintf(stdout,"%d.%d.%d.%d\n",(int)(*(tmp+12)),(int)(*(tmp+13)),(int)(*(tmp+14)),(int)(*(tmp+15)));
  enqueue(DNS_stat->send_packets,sendPacket);
 }
 if(verbal>1)
 fprintf(stdout, "--------------in parse - done-------------\n");
 return 0;
}

canonical_original_code:
int parse(char *buf, unsigned long len, struct sockaddr *addr){
 if(verbal>1)
  fprintf(stdout, "--------------in parse-------------\n");
 checkbuf(buf,len);
 struct sockaddr_in tmpaddr = *((struct sockaddr_in*)addr);
  char *clientIP = inet_ntoa(tmpaddr.sin_addr);
 char name[1024] = {0};
 char data[1024] = {0};
 struct packet_t *packet = (packet_t *) buf;
 unsigned short requestID = packet->header.id;
 struct send_packet_t *sendPacket;
 parseRequestData(packet->data,name);
 fprintf(stdout,"name: %s\n",name);
 if(!strcmp(name,"video.cs.cmu.edu")){
  int datalen = buildResponseData(packet->data,len-12,data,clientIP);
     sendPacket=construct_response_packet(requestID,0,datalen,data,addr);
     checkbuf((char *)(sendPacket->data),datalen+12);
 }else{
  logWrite(clientIP,name,"0.0.0.0");
  sendPacket=construct_response_packet(requestID,3,len-12,packet->data,addr);
 }
 if(sendPacket!=((void *)0)){
  char *tmp = sendPacket->data->data;
  tmp+=len-12;
  fprintf(stdout,"%d.%d.%d.%d\n",(int)(*(tmp+12)),(int)(*(tmp+13)),(int)(*(tmp+14)),(int)(*(tmp+15)));
  enqueue(DNS_stat->send_packets,sendPacket);
 }
 if(verbal>1)
 fprintf(stdout, "--------------in parse - done-------------\n");
 return 0;
}

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

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

variable_types:
name
char [1024]

variable_types:
data
char [1024]

variable_types:
requestID
unsigned short

variable_types: struct send_packet_t { int size; int sent; struct sockaddr { unsigned short sa_family; char sa_data[14]; } address; struct packet_t { struct header { unsigned int id; unsigned int qr; unsigned int opcode; unsigned int aa; unsigned int tc; unsigned int rd; unsigned int ra; unsigned int z; unsigned int rcode; unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; } header; char data[1024]; } *data; } *

variable_types: datalen int

variable_types:
tmp
char *

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 packet_t { struct header header; char data[1024]; }

user_defined_types: struct send_packet_t { int size; int sent; struct sockaddr address; struct packet_t *data; }


closeLogFile

decompiled_code:
void closeLogFile()
{
if ( logFile )
{
if ( fclose(logFile) )
{
fwrite("Error:in closing log file\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
}
}

canonical_decompiled_code:
void func0()
{
if ( logFile )
{
if ( fclose(logFile) )
{
fwrite("Error:in closing log file\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
}
}

original_code:
void closeLogFile() {
 if(logFile!=((void *)0))
  if(fclose(logFile)!=0){
   fprintf(stderr, "Error:in closing log file\n");
   exit(0);
  }
}


closeDNSServer

decompiled_code:
void __noreturn closeDNSServer()
{
closeLogFile();
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
closeLogFile();
exit(0);
}

original_code:
void closeDNSServer(){
 closeLogFile();
    exit(0);
}


decompiled_code:
__int64 __fastcall doIt_Read(int fd)
{
int v1; // eax
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-41Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-418h] BYREF
char buf[1032]; // [rsp+20h] [rbp-408h] BYREF

if ( verbal > 1 )
puts("dns doit read");
addr_len = 16;
v1 = recvfrom(fd, buf, 0x2000uLL, 0, &addr, &addr_len);
if ( v1 < 0 )
{
fwrite("error while recieving data\n", 1uLL, 0x1BuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
parse(buf, v1, &addr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
int v1; // eax
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-41Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-418h] BYREF
char buf[1032]; // [rsp+20h] [rbp-408h] BYREF

if ( verbal > 1 )
puts("dns doit read");
addr_len = 16;
v1 = recvfrom(fd, buf, 0x2000uLL, 0, &addr, &addr_len);
if ( v1 < 0 )
{
fwrite("error while recieving data\n", 1uLL, 0x1BuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
parse(buf, v1, &addr);
result = 0LL;
}
return result;
}

original_code:
int doIt_Read(int fd){
 if(verbal > 1) printf("dns doit read\n");
 socklen_t addrlen=sizeof(struct sockaddr_in);
 struct sockaddr_in clientaddr;
 char buf[1024];
 int recvret;
 if((recvret=recvfrom(fd, buf, 8192, 0, (SA *) &clientaddr, &addrlen))<0){
  fprintf(stderr, "error while recieving data\n" );
  return -1;
 }
 parse(buf,recvret,(SA *)&clientaddr);
 return 0;
}

canonical_original_code:
int doIt_Read(int fd){
 if(verbal > 1) printf("dns doit read\n");
 unsigned int addrlen = sizeof(struct sockaddr_in);
 struct sockaddr_in clientaddr;
 char buf[1024];
 int recvret;
 if((recvret=recvfrom(fd, buf, 8192, 0, (struct sockaddr *) &clientaddr, &addrlen))<0){
  fprintf(stderr, "error while recieving data\n" );
  return -1;
 }
 parse(buf,recvret,(struct sockaddr *)&clientaddr);
 return 0;
}

variable_types: fd int

variable_types:
addrlen
unsigned int

variable_types:
buf
char [1024]

variable_types: recvret int

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


decompiled_code:
__int64 __fastcall doIt_Send(int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // eax
__int64 result; // rax
__int64 v5; // rbx

v1 = DNS_stat;
v2 = *(_QWORD *)(DNS_stat + 48);
if ( v2 )
{
v3 = *(_DWORD *)(v2 + 4)
+ sendto(
a1,
(const void *)(*(_QWORD *)(v2 + 24) + *(int *)(v2 + 4)),
*(_DWORD *)v2 - *(_DWORD *)(v2 + 4),
0,
(const struct sockaddr *)(v2 + 8),
0x10u);
*(_DWORD *)(v2 + 4) = v3;
if ( v3 == *(_DWORD *)v2 )
{
free_send_packet(v2);
v5 = DNS_stat;
*(_QWORD *)(v5 + 48) = dequeue(*(_QWORD *)(DNS_stat + 40));
}
result = 0LL;
}
else
{
*(_QWORD *)(v1 + 48) = dequeue(*(_QWORD *)(DNS_stat + 40));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // eax
__int64 result; // rax
__int64 v5; // rbx

v1 = DNS_stat;
v2 = *(_QWORD *)(DNS_stat + 48);
if ( v2 )
{
v3 = *(_DWORD *)(v2 + 4)
+ sendto(
a1,
(const void *)(*(_QWORD *)(v2 + 24) + *(int *)(v2 + 4)),
*(_DWORD *)v2 - *(_DWORD *)(v2 + 4),
0,
(const struct sockaddr *)(v2 + 8),
0x10u);
*(_DWORD *)(v2 + 4) = v3;
if ( v3 == *(_DWORD *)v2 )
{
free_send_packet(v2);
v5 = DNS_stat;
*(_QWORD *)(v5 + 48) = dequeue(*(_QWORD *)(DNS_stat + 40));
}
result = 0LL;
}
else
{
*(_QWORD *)(v1 + 48) = dequeue(*(_QWORD *)(DNS_stat + 40));
result = 0LL;
}
return result;
}

original_code:
int doIt_Send(int fd){
 send_packet_t *send = DNS_stat->sending;
 if(send != ((void *)0)){
  int sendret = sendto(fd,((char *)send->data)+(send->sent),(send->size)-(send->sent),0,&(send->address),sizeof(send->address));
  send->sent += sendret;
  if(send->sent == send->size){
   free_send_packet(send);
   DNS_stat->sending= (send_packet_t *)dequeue(DNS_stat->send_packets);
  }
 }else{
  DNS_stat->sending = (send_packet_t *)dequeue(DNS_stat->send_packets);
 }
 return 0;
}

canonical_original_code:
int doIt_Send(int fd){
 struct send_packet_t *send = DNS_stat->sending;
 if(send != ((void *)0)){
  int sendret = sendto(fd,((char *)send->data)+(send->sent),(send->size)-(send->sent),0,&(send->address),sizeof(send->address));
  send->sent += sendret;
  if(send->sent == send->size){
   free_send_packet(send);
   DNS_stat->sending= (struct send_packet_t *)dequeue(DNS_stat->send_packets);
  }
 }else{
  DNS_stat->sending = (struct send_packet_t *)dequeue(DNS_stat->send_packets);
 }
 return 0;
}

variable_types: sendret int

user_defined_types: struct header { unsigned int id; unsigned int qr; unsigned int opcode; unsigned int aa; unsigned int tc; unsigned int rd; unsigned int ra; unsigned int z; unsigned int rcode; unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; }


decompiled_code:
__int64 __fastcall open_listenfd(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
int v6; // edi
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v8[2]; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v2 = socket(2, 2, 0);
if ( v2 < 0 )
{
v3 = -1;
fwrite("error in open socket\n", 1uLL, 0x15uLL, stderr);
}
else
{
v3 = v2;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 )
{
v3 = -1;
fwrite("error in set socket\n", 1uLL, 0x14uLL, stderr);
}
else
{
v8[0] = 0LL;
v8[0].sa_family = 2;
inet_aton(cp, (struct in_addr *)&v8[0].sa_data[2]);
*(_WORD *)v8[0].sa_data = _bswap_16(a2);
if ( bind(v3, v8, v4) < 0 )
{
fwrite("error in bind socket\n", 1uLL, 0x15uLL, stderr);
v6 = v3;
v3 = -1;
close(v6);
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
int v6; // edi
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v8[2]; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v2 = socket(2, 2, 0);
if ( v2 < 0 )
{
v3 = -1;
fwrite("error in open socket\n", 1uLL, 0x15uLL, stderr);
}
else
{
v3 = v2;
if ( setsockopt(v2, 1, 2, &optval, 4u) < 0 )
{
v3 = -1;
fwrite("error in set socket\n", 1uLL, 0x14uLL, stderr);
}
else
{
v8[0] = 0LL;
v8[0].sa_family = 2;
inet_aton(cp, (struct in_addr *)&v8[0].sa_data[2]);
*(_WORD *)v8[0].sa_data = func0(a2);
if ( bind(v3, v8, v4) < 0 )
{
fwrite("error in bind socket\n", 1uLL, 0x15uLL, stderr);
v6 = v3;
v3 = -1;
close(v6);
}
}
}
return v3;
}

original_code:
int open_listenfd(char* ip, int port)
{
    int listenfd, optval=1;
    struct sockaddr_in serveraddr;
    if ((listenfd = socket(2, SOCK_DGRAM, IPPROTO_IP)) < 0){
     fprintf(stderr, "error in open socket\n");
     return -1;
 }
    if (setsockopt(listenfd, 1, 2,
           (const void *)&optval , sizeof(int)) < 0){
     fprintf(stderr, "error in set socket\n");
     return -1;
 }
    bzero((char *) &serveraddr, sizeof(serveraddr));
    serveraddr.sin_family = 2;
    inet_aton(ip,(struct in_addr *)&serveraddr.sin_addr.s_addr);
    serveraddr.sin_port = htons((unsigned short)port);
    if (bind(listenfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0){
     fprintf(stderr, "error in bind socket\n");
     close(listenfd);
     return -1;
    }
    return listenfd;
}

canonical_original_code:
int open_listenfd(char *ip, int port)
{
    int listenfd; int optval = 1;
    struct sockaddr_in serveraddr;
    if ((listenfd = socket(2, SOCK_DGRAM, IPPROTO_IP)) < 0){
     fprintf(stderr, "error in open socket\n");
     return -1;
 }
    if (setsockopt(listenfd, 1, 2,
           (void *)&optval , sizeof(int)) < 0){
     fprintf(stderr, "error in set socket\n");
     return -1;
 }
    bzero((char *) &serveraddr, sizeof(serveraddr));
    serveraddr.sin_family = 2;
    inet_aton(ip,(struct in_addr *)&serveraddr.sin_addr.s_addr);
    serveraddr.sin_port = htons((unsigned short)port);
    if (bind(listenfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0){
     fprintf(stderr, "error in bind socket\n");
     close(listenfd);
     return -1;
    }
    return listenfd;
}

variable_types:
ip
char *

variable_types: port int

variable_types: listenfd int

variable_types: optval int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rdi
int v5; // eax
int v6; // er14
__int64 v7; // rbp
__int64 v8; // r15
int v9; // ebx
__fd_mask v10; // rax
bool v11; // cc
int fd; // [rsp+Ch] [rbp-13Ch]
fd_set readfds; // [rsp+10h] [rbp-138h] BYREF
fd_set writefds; // [rsp+90h] [rbp-B8h] BYREF

if ( verbal )
fwrite("--------------DNS start-----------------\n", 1uLL, 0x29uLL, stdout);
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
signal(2, (__sighandler_t)closeDNSServer);
v3 = initDNSServer(argc, argv);
v4 = v3[2];
DNS_stat = (__int64)v3;
createLogFile(v4);
v5 = open_listenfd(*(char **)(DNS_stat + 8), *(_DWORD *)(DNS_stat + 4));
fd = v5;
if ( v5 >= 0 )
{
v6 = v5 + 1;
v7 = 1LL << v5;
v8 = v5 >> 6;
while ( 1 )
{
LABEL_8:
v10 = writefds.fds_bits[v8];
do
{
readfds.fds_bits[v8] |= v7;
v11 = verbal <= 2;
writefds.fds_bits[v8] = v7 | v10;
if ( !v11 )
fwrite("selecting......\n", 1uLL, 0x10uLL, stdout);
v9 = select(v6, &readfds, &writefds, 0LL, 0LL);
if ( v9 < 0 )
{
fwrite("select error\n", 1uLL, 0xDuLL, stderr);
exit(0);
}
if ( verbal > 2 )
{
fwrite("select done\n", 1uLL, 0xCuLL, stdout);
if ( !v9 )
goto LABEL_8;
}
else if ( !v9 )
{
goto LABEL_8;
}
if ( (readfds.fds_bits[v8] & v7) != 0 )
doIt_Read(fd);
v10 = writefds.fds_bits[v8];
}
while ( (v10 & v7) == 0 );
doIt_Send(fd);
}
}
fwrite("error in open_listenfd\n", 1uLL, 0x17uLL, stderr);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rdi
int v5; // eax
int v6; // er14
__int64 v7; // rbp
__int64 v8; // r15
int v9; // ebx
__fd_mask v10; // rax
bool v11; // cc
int fd; // [rsp+Ch] [rbp-13Ch]
fd_set readfds; // [rsp+10h] [rbp-138h] BYREF
fd_set writefds; // [rsp+90h] [rbp-B8h] BYREF

if ( verbal )
fwrite("--------------DNS start-----------------\n", 1uLL, 0x29uLL, stdout);
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
signal(2, (__sighandler_t)closeDNSServer);
v3 = initDNSServer(argc, argv);
v4 = v3[2];
DNS_stat = (__int64)v3;
createLogFile(v4);
v5 = func4(*(char **)(DNS_stat + 8), *(_DWORD *)(DNS_stat + 4));
fd = v5;
if ( v5 >= 0 )
{
v6 = v5 + 1;
v7 = 1LL << v5;
v8 = v5 >> 6;
while ( 1 )
{
LABEL_8:
v10 = writefds.fds_bits[v8];
do
{
readfds.fds_bits[v8] |= v7;
v11 = verbal <= 2;
writefds.fds_bits[v8] = v7 | v10;
if ( !v11 )
fwrite("selecting......\n", 1uLL, 0x10uLL, stdout);
v9 = select(v6, &readfds, &writefds, 0LL, 0LL);
if ( v9 < 0 )
{
fwrite("select error\n", 1uLL, 0xDuLL, stderr);
exit(0);
}
if ( verbal > 2 )
{
fwrite("select done\n", 1uLL, 0xCuLL, stdout);
if ( !v9 )
goto LABEL_8;
}
else if ( !v9 )
{
goto LABEL_8;
}
if ( (readfds.fds_bits[v8] & v7) != 0 )
func2(fd);
v10 = writefds.fds_bits[v8];
}
while ( (v10 & v7) == 0 );
func3(fd);
}
}
fwrite("error in open_listenfd\n", 1uLL, 0x17uLL, stderr);
return -1;
}

original_code:
int main(int argc, char **argv){
 if(verbal)
  fprintf(stdout,"--------------DNS start-----------------\n");
 int listenfd;
 fd_set read_set,write_set;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_set)->__fds_bits)[0]) : "memory"); } while (0);
 signal(2,closeDNSServer);
 DNS_stat=initDNSServer(argc,argv);
 createLogFile(DNS_stat->logFile);
 if((listenfd=open_listenfd(DNS_stat->ip,DNS_stat->port))<0){
  fprintf(stderr, "error in open_listenfd\n");
  return -1;
 }
 while(1){
  int nready=0;
  ((void) (((&read_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&write_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
  if(verbal>2) fprintf(stdout, "selecting......\n");
  if((nready=select(listenfd+1,&read_set,&write_set,((void *)0),((void *)0)))<0){
   fprintf(stderr, "select error\n");
   exit(0);
  }
  if(verbal>2) fprintf(stdout, "select done\n");
  if(nready>0){
   if(((((&read_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
    doIt_Read(listenfd);
   }
   if(((((&write_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
    doIt_Send(listenfd);
   }
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 if(verbal)
  fprintf(stdout,"--------------DNS start-----------------\n");
 int listenfd;
 struct fd_set read_set; struct fd_set write_set;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_set)->__fds_bits)[0]) : "memory"); } while (0);
 signal(2,closeDNSServer);
 DNS_stat=initDNSServer(argc,argv);
 createLogFile(DNS_stat->logFile);
 if((listenfd=open_listenfd(DNS_stat->ip,DNS_stat->port))<0){
  fprintf(stderr, "error in open_listenfd\n");
  return -1;
 }
 while(1){
  int nready = 0;
  ((void) (((&read_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&write_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
  if(verbal>2) fprintf(stdout, "selecting......\n");
  if((nready=select(listenfd+1,&read_set,&write_set,((void *)0),((void *)0)))<0){
   fprintf(stderr, "select error\n");
   exit(0);
  }
  if(verbal>2) fprintf(stdout, "select done\n");
  if(nready>0){
   if(((((&read_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
    doIt_Read(listenfd);
   }
   if(((((&write_set)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
    doIt_Send(listenfd);
   }
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: nready int


decompiled_code:
char *__fastcall construct_neighbors(char *a1)
{
char *v1; // rbp
char *v2; // r13
char *i; // r12
char *v4; // rbx
char *v5; // rbp

v1 = strtok(a1, ",");
v2 = (char *)calloc(1uLL, 0x418uLL);
strcpy(v2 + 4, v1);
for ( i = v2; ; i = v4 )
{
v5 = strtok(0LL, ",");
if ( !v5 )
break;
v4 = (char *)calloc(1uLL, 0x418uLL);
strcpy(v4 + 4, v5);
*((_QWORD *)i + 130) = v4;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
char *v1; // rbp
char *v2; // r13
char *i; // r12
char *v4; // rbx
char *v5; // rbp

v1 = strtok(a1, ",");
v2 = (char *)calloc(1uLL, 0x418uLL);
strcpy(v2 + 4, v1);
for ( i = v2; ; i = v4 )
{
v5 = strtok(0LL, ",");
if ( !v5 )
break;
v4 = (char *)calloc(1uLL, 0x418uLL);
strcpy(v4 + 4, v5);
*((_QWORD *)i + 130) = v4;
}
return v2;
}

original_code:
gnode_t *construct_neighbors(char *neighbors)
{
 char *search = ",";
 char *token;
 token = strtok(neighbors, search);
 gnode_t *nb = calloc(1,sizeof(gnode_t));
 strcpy(nb->name, token);
 gnode_t *tmp = nb;
 while((token = strtok(((void *)0), search)) != ((void *)0)){
  gnode_t *next = calloc(1,sizeof(gnode_t));
  strcpy(next->name, token);
  tmp->next = next;
  tmp = next;
 }
 return nb;
}

canonical_original_code:
struct gnode *construct_neighbors(char *neighbors)
{
 char *search = ",";
 char *token;
 token = strtok(neighbors, search);
 struct gnode *nb = calloc(1,sizeof(gnode_t));
 strcpy(nb->name, token);
 struct gnode *tmp = nb;
 while((token = strtok(((void *)0), search)) != ((void *)0)){
  struct gnode *next = calloc(1,sizeof(gnode_t));
  strcpy(next->name, token);
  tmp->next = next;
  tmp = next;
 }
 return nb;
}

variable_types:
neighbors
char *

variable_types:
search
char *

variable_types:
token
char *

variable_types: struct gnode { int seqNum; char name[1024]; struct gnode *neighbors; struct gnode *next; } *


decompiled_code:
char *__fastcall update_graph(char *a1, const char *a2, int a3, char *a4)
{
char *v6; // rbx
char *v7; // r15
char *v8; // rax
char *v9; // rax

if ( a1 )
{
v6 = a1;
while ( strcmp(v6 + 4, a2) )
{
v6 = (char *)*((_QWORD *)v6 + 130);
if ( !v6 )
goto LABEL_7;
}
v7 = a1;
if ( *(_DWORD *)v6 < a3 )
{
*(_DWORD *)v6 = a3;
free_neighbors(*((void **)v6 + 129));
*((_QWORD *)v6 + 129) = construct_neighbors(a4);
}
}
else
{
LABEL_7:
v8 = (char *)calloc(1uLL, 0x418uLL);
*(_DWORD *)v8 = a3;
v7 = v8;
strcpy(v8 + 4, a2);
v9 = construct_neighbors(a4);
*((_QWORD *)v7 + 130) = a1;
*((_QWORD *)v7 + 129) = v9;
}
return v7;
}

original_code:
gnode_t *update_graph(gnode_t *graph, char *name, int seqNum, char *neighbors)
{
 gnode_t *tmp = graph;
 while(tmp != ((void *)0)){
  if(strcmp(tmp->name, name) == 0){
   if(tmp->seqNum >= seqNum){
    return graph;
   }
   else{
    tmp->seqNum = seqNum;
    free_neighbors(tmp->neighbors);
    tmp->neighbors = construct_neighbors(neighbors);
    return graph;
   }
  }
  tmp = tmp->next;
 }
 gnode_t *new_node = calloc(1,sizeof(gnode_t));
 new_node->seqNum = seqNum;
 strcpy(new_node->name, name);
 new_node->neighbors = construct_neighbors(neighbors);
 new_node->next = graph;
 return new_node;
}

canonical_original_code:
struct gnode *update_graph(struct gnode *graph, char *name, int seqNum, char *neighbors)
{
 struct gnode *tmp = graph;
 while(tmp != ((void *)0)){
  if(strcmp(tmp->name, name) == 0){
   if(tmp->seqNum >= seqNum){
    return graph;
   }
   else{
    tmp->seqNum = seqNum;
    free_neighbors(tmp->neighbors);
    tmp->neighbors = construct_neighbors(neighbors);
    return graph;
   }
  }
  tmp = tmp->next;
 }
 struct gnode *new_node = calloc(1,sizeof(gnode_t));
 new_node->seqNum = seqNum;
 strcpy(new_node->name, name);
 new_node->neighbors = construct_neighbors(neighbors);
 new_node->next = graph;
 return new_node;
}

variable_types:
graph
struct gnode *

variable_types:
name
char *

variable_types: seqNum int

return_type: struct gnode { int seqNum; char name[1024]; struct gnode *neighbors; struct gnode *next; } *


decompiled_code:
__int64 __fastcall getIP_Robin(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 24);
if ( result == *(_QWORD *)(a1 + 16) )
v2 = *(_QWORD *)(a1 + 8);
else
v2 = *(_QWORD *)(result + 24);
*(_QWORD *)(a1 + 24) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 24);
if ( result == *(_QWORD *)(a1 + 16) )
v2 = *(_QWORD *)(a1 + 8);
else
v2 = *(_QWORD *)(result + 24);
*(_QWORD *)(a1 + 24) = v2;
return result;
}

original_code:
ip_t *getIP_Robin(robin_list_t* list){
 if (list->size==0) return ((void *)0);
 ip_t *ret = &list->ptr->ip;
 if(list->ptr == list->tail)
  list->ptr = list->head;
 else list->ptr = list->ptr->next;
 return ret;
}

canonical_original_code:
struct ip_t *getIP_Robin(struct robin_list_t *list){
 if (list->size==0) return ((void *)0);
 struct ip_t *ret = &list->ptr->ip;
 if(list->ptr == list->tail)
  list->ptr = list->head;
 else list->ptr = list->ptr->next;
 return ret;
}

variable_types: struct robin_list_t { int size; struct robin_node_s { struct ip_t ip; struct robin_node_s *next; } *head; struct robin_node_s *tail; struct robin_node_s *ptr; } *

variable_types: struct ip_t { char ip_str[20]; unsigned char ip[4]; } *

user_defined_types: struct robin_list_t { int size; struct robin_node_s *head; struct robin_node_s *tail; struct robin_node_s *ptr; }


decompiled_code:
__int64 __fastcall gpg_err_code(unsigned __int16 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
return a1;
}

original_code:
static __inline__ gpg_err_code_t
gpg_err_code (gpg_error_t err)
{
  return (gpg_err_code_t) (err & (GPG_ERR_CODE_DIM - 1));
}

canonical_original_code:
static __inline__ enum gpg_err_code_t gpg_err_code(unsigned int err)
{
  return (gpg_err_code_t) (err & (GPG_ERR_CODE_DIM - 1));
}

variable_types:
err
unsigned int

return_type: enum gpg_err_code_t { GPG_ERR_NO_ERROR=0, GPG_ERR_GENERAL=1, GPG_ERR_UNKNOWN_PACKET=2, GPG_ERR_UNKNOWN_VERSION=3, GPG_ERR_PUBKEY_ALGO=4, GPG_ERR_DIGEST_ALGO=5, GPG_ERR_BAD_PUBKEY=6, GPG_ERR_BAD_SECKEY=7, GPG_ERR_BAD_SIGNATURE=8, GPG_ERR_NO_PUBKEY=9, GPG_ERR_CHECKSUM=10, GPG_ERR_BAD_PASSPHRASE=11, GPG_ERR_CIPHER_ALGO=12, GPG_ERR_KEYRING_OPEN=13, GPG_ERR_INV_PACKET=14, GPG_ERR_INV_ARMOR=15, GPG_ERR_NO_USER_ID=16, GPG_ERR_NO_SECKEY=17, GPG_ERR_WRONG_SECKEY=18, GPG_ERR_BAD_KEY=19, GPG_ERR_COMPR_ALGO=20, GPG_ERR_NO_PRIME=21, GPG_ERR_NO_ENCODING_METHOD=22, GPG_ERR_NO_ENCRYPTION_SCHEME=23, GPG_ERR_NO_SIGNATURE_SCHEME=24, GPG_ERR_INV_ATTR=25, GPG_ERR_NO_VALUE=26, GPG_ERR_NOT_FOUND=27, GPG_ERR_VALUE_NOT_FOUND=28, GPG_ERR_SYNTAX=29, GPG_ERR_BAD_MPI=30, GPG_ERR_INV_PASSPHRASE=31, GPG_ERR_SIG_CLASS=32, GPG_ERR_RESOURCE_LIMIT=33, GPG_ERR_INV_KEYRING=34, GPG_ERR_TRUSTDB=35, GPG_ERR_BAD_CERT=36, GPG_ERR_INV_USER_ID=37, GPG_ERR_UNEXPECTED=38, GPG_ERR_TIME_CONFLICT=39, GPG_ERR_KEYSERVER=40, GPG_ERR_WRONG_PUBKEY_ALGO=41, GPG_ERR_TRIBUTE_TO_D_A=42, GPG_ERR_WEAK_KEY=43, GPG_ERR_INV_KEYLEN=44, GPG_ERR_INV_ARG=45, GPG_ERR_BAD_URI=46, GPG_ERR_INV_URI=47, GPG_ERR_NETWORK=48, GPG_ERR_UNKNOWN_HOST=49, GPG_ERR_SELFTEST_FAILED=50, GPG_ERR_NOT_ENCRYPTED=51, GPG_ERR_NOT_PROCESSED=52, GPG_ERR_UNUSABLE_PUBKEY=53, GPG_ERR_UNUSABLE_SECKEY=54, GPG_ERR_INV_VALUE=55, GPG_ERR_BAD_CERT_CHAIN=56, GPG_ERR_MISSING_CERT=57, GPG_ERR_NO_DATA=58, GPG_ERR_BUG=59, GPG_ERR_NOT_SUPPORTED=60, GPG_ERR_INV_OP=61, GPG_ERR_TIMEOUT=62, GPG_ERR_INTERNAL=63, GPG_ERR_EOF_GCRYPT=64, GPG_ERR_INV_OBJ=65, GPG_ERR_TOO_SHORT=66, GPG_ERR_TOO_LARGE=67, GPG_ERR_NO_OBJ=68, GPG_ERR_NOT_IMPLEMENTED=69, GPG_ERR_CONFLICT=70, GPG_ERR_INV_CIPHER_MODE=71, GPG_ERR_INV_FLAG=72, GPG_ERR_INV_HANDLE=73, GPG_ERR_TRUNCATED=74, GPG_ERR_INCOMPLETE_LINE=75, GPG_ERR_INV_RESPONSE=76, GPG_ERR_NO_AGENT=77, GPG_ERR_AGENT=78, GPG_ERR_INV_DATA=79, GPG_ERR_ASSUAN_SERVER_FAULT=80, GPG_ERR_ASSUAN=81, GPG_ERR_INV_SESSION_KEY=82, GPG_ERR_INV_SEXP=83, GPG_ERR_UNSUPPORTED_ALGORITHM=84, GPG_ERR_NO_PIN_ENTRY=85, GPG_ERR_PIN_ENTRY=86, GPG_ERR_BAD_PIN=87, GPG_ERR_INV_NAME=88, GPG_ERR_BAD_DATA=89, GPG_ERR_INV_PARAMETER=90, GPG_ERR_WRONG_CARD=91, GPG_ERR_NO_DIRMNGR=92, GPG_ERR_DIRMNGR=93, GPG_ERR_CERT_REVOKED=94, GPG_ERR_NO_CRL_KNOWN=95, GPG_ERR_CRL_TOO_OLD=96, GPG_ERR_LINE_TOO_LONG=97, GPG_ERR_NOT_TRUSTED=98, GPG_ERR_CANCELED=99, GPG_ERR_BAD_CA_CERT=100, GPG_ERR_CERT_EXPIRED=101, GPG_ERR_CERT_TOO_YOUNG=102, GPG_ERR_UNSUPPORTED_CERT=103, GPG_ERR_UNKNOWN_SEXP=104, GPG_ERR_UNSUPPORTED_PROTECTION=105, GPG_ERR_CORRUPTED_PROTECTION=106, GPG_ERR_AMBIGUOUS_NAME=107, GPG_ERR_CARD=108, GPG_ERR_CARD_RESET=109, GPG_ERR_CARD_REMOVED=110, GPG_ERR_INV_CARD=111, GPG_ERR_CARD_NOT_PRESENT=112, GPG_ERR_NO_PKCS15_APP=113, GPG_ERR_NOT_CONFIRMED=114, GPG_ERR_CONFIGURATION=115, GPG_ERR_NO_POLICY_MATCH=116, GPG_ERR_INV_INDEX=117, GPG_ERR_INV_ID=118, GPG_ERR_NO_SCDAEMON=119, GPG_ERR_SCDAEMON=120, GPG_ERR_UNSUPPORTED_PROTOCOL=121, GPG_ERR_BAD_PIN_METHOD=122, GPG_ERR_CARD_NOT_INITIALIZED=123, GPG_ERR_UNSUPPORTED_OPERATION=124, GPG_ERR_WRONG_KEY_USAGE=125, GPG_ERR_NOTHING_FOUND=126, GPG_ERR_WRONG_BLOB_TYPE=127, GPG_ERR_MISSING_VALUE=128, GPG_ERR_HARDWARE=129, GPG_ERR_PIN_BLOCKED=130, GPG_ERR_USE_CONDITIONS=131, GPG_ERR_PIN_NOT_SYNCED=132, GPG_ERR_INV_CRL=133, GPG_ERR_BAD_BER=134, GPG_ERR_INV_BER=135, GPG_ERR_ELEMENT_NOT_FOUND=136, GPG_ERR_IDENTIFIER_NOT_FOUND=137, GPG_ERR_INV_TAG=138, GPG_ERR_INV_LENGTH=139, GPG_ERR_INV_KEYINFO=140, GPG_ERR_UNEXPECTED_TAG=141, GPG_ERR_NOT_DER_ENCODED=142, GPG_ERR_NO_CMS_OBJ=143, GPG_ERR_INV_CMS_OBJ=144, GPG_ERR_UNKNOWN_CMS_OBJ=145, GPG_ERR_UNSUPPORTED_CMS_OBJ=146, GPG_ERR_UNSUPPORTED_ENCODING=147, GPG_ERR_UNSUPPORTED_CMS_VERSION=148, GPG_ERR_UNKNOWN_ALGORITHM=149, GPG_ERR_INV_ENGINE=150, GPG_ERR_PUBKEY_NOT_TRUSTED=151, GPG_ERR_DECRYPT_FAILED=152, GPG_ERR_KEY_EXPIRED=153, GPG_ERR_SIG_EXPIRED=154, GPG_ERR_ENCODING_PROBLEM=155, GPG_ERR_INV_STATE=156, GPG_ERR_DUP_VALUE=157, GPG_ERR_MISSING_ACTION=158, GPG_ERR_MODULE_NOT_FOUND=159, GPG_ERR_INV_OID_STRING=160, GPG_ERR_INV_TIME=161, GPG_ERR_INV_CRL_OBJ=162, GPG_ERR_UNSUPPORTED_CRL_VERSION=163, GPG_ERR_INV_CERT_OBJ=164, GPG_ERR_UNKNOWN_NAME=165, GPG_ERR_LOCALE_PROBLEM=166, GPG_ERR_NOT_LOCKED=167, GPG_ERR_PROTOCOL_VIOLATION=168, GPG_ERR_INV_MAC=169, GPG_ERR_INV_REQUEST=170, GPG_ERR_UNKNOWN_EXTN=171, GPG_ERR_UNKNOWN_CRIT_EXTN=172, GPG_ERR_LOCKED=173, GPG_ERR_UNKNOWN_OPTION=174, GPG_ERR_UNKNOWN_COMMAND=175, GPG_ERR_NOT_OPERATIONAL=176, GPG_ERR_NO_PASSPHRASE=177, GPG_ERR_NO_PIN=178, GPG_ERR_NOT_ENABLED=179, GPG_ERR_NO_ENGINE=180, GPG_ERR_MISSING_KEY=181, GPG_ERR_TOO_MANY=182, GPG_ERR_LIMIT_REACHED=183, GPG_ERR_NOT_INITIALIZED=184, GPG_ERR_MISSING_ISSUER_CERT=185, GPG_ERR_NO_KEYSERVER=186, GPG_ERR_INV_CURVE=187, GPG_ERR_UNKNOWN_CURVE=188, GPG_ERR_DUP_KEY=189, GPG_ERR_AMBIGUOUS=190, GPG_ERR_NO_CRYPT_CTX=191, GPG_ERR_WRONG_CRYPT_CTX=192, GPG_ERR_BAD_CRYPT_CTX=193, GPG_ERR_CRYPT_CTX_CONFLICT=194, GPG_ERR_BROKEN_PUBKEY=195, GPG_ERR_BROKEN_SECKEY=196, GPG_ERR_MAC_ALGO=197, GPG_ERR_FULLY_CANCELED=198, GPG_ERR_UNFINISHED=199, GPG_ERR_BUFFER_TOO_SHORT=200, GPG_ERR_SEXP_INV_LEN_SPEC=201, GPG_ERR_SEXP_STRING_TOO_LONG=202, GPG_ERR_SEXP_UNMATCHED_PAREN=203, GPG_ERR_SEXP_NOT_CANONICAL=204, GPG_ERR_SEXP_BAD_CHARACTER=205, GPG_ERR_SEXP_BAD_QUOTATION=206, GPG_ERR_SEXP_ZERO_PREFIX=207, GPG_ERR_SEXP_NESTED_DH=208, GPG_ERR_SEXP_UNMATCHED_DH=209, GPG_ERR_SEXP_UNEXPECTED_PUNC=210, GPG_ERR_SEXP_BAD_HEX_CHAR=211, GPG_ERR_SEXP_ODD_HEX_NUMBERS=212, GPG_ERR_SEXP_BAD_OCT_CHAR=213, GPG_ERR_SUBKEYS_EXP_OR_REV=217, GPG_ERR_DB_CORRUPTED=218, GPG_ERR_SERVER_FAILED=219, GPG_ERR_NO_NAME=220, GPG_ERR_NO_KEY=221, GPG_ERR_LEGACY_KEY=222, GPG_ERR_REQUEST_TOO_SHORT=223, GPG_ERR_REQUEST_TOO_LONG=224, GPG_ERR_OBJ_TERM_STATE=225, GPG_ERR_NO_CERT_CHAIN=226, GPG_ERR_CERT_TOO_LARGE=227, GPG_ERR_INV_RECORD=228, GPG_ERR_BAD_MAC=229, GPG_ERR_UNEXPECTED_MSG=230, GPG_ERR_COMPR_FAILED=231, GPG_ERR_WOULD_WRAP=232, GPG_ERR_FATAL_ALERT=233, GPG_ERR_NO_CIPHER=234, GPG_ERR_MISSING_CLIENT_CERT=235, GPG_ERR_CLOSE_NOTIFY=236, GPG_ERR_TICKET_EXPIRED=237, GPG_ERR_BAD_TICKET=238, GPG_ERR_UNKNOWN_IDENTITY=239, GPG_ERR_BAD_HS_CERT=240, GPG_ERR_BAD_HS_CERT_REQ=241, GPG_ERR_BAD_HS_CERT_VER=242, GPG_ERR_BAD_HS_CHANGE_CIPHER=243, GPG_ERR_BAD_HS_CLIENT_HELLO=244, GPG_ERR_BAD_HS_SERVER_HELLO=245, GPG_ERR_BAD_HS_SERVER_HELLO_DONE=246, GPG_ERR_BAD_HS_FINISHED=247, GPG_ERR_BAD_HS_SERVER_KEX=248, GPG_ERR_BAD_HS_CLIENT_KEX=249, GPG_ERR_BOGUS_STRING=250, GPG_ERR_FORBIDDEN=251, GPG_ERR_KEY_DISABLED=252, GPG_ERR_KEY_ON_CARD=253, GPG_ERR_INV_LOCK_OBJ=254, GPG_ERR_TRUE=255, GPG_ERR_FALSE=256, GPG_ERR_ASS_GENERAL=257, GPG_ERR_ASS_ACCEPT_FAILED=258, GPG_ERR_ASS_CONNECT_FAILED=259, GPG_ERR_ASS_INV_RESPONSE=260, GPG_ERR_ASS_INV_VALUE=261, GPG_ERR_ASS_INCOMPLETE_LINE=262, GPG_ERR_ASS_LINE_TOO_LONG=263, GPG_ERR_ASS_NESTED_COMMANDS=264, GPG_ERR_ASS_NO_DATA_CB=265, GPG_ERR_ASS_NO_INQUIRE_CB=266, GPG_ERR_ASS_NOT_A_SERVER=267, GPG_ERR_ASS_NOT_A_CLIENT=268, GPG_ERR_ASS_SERVER_START=269, GPG_ERR_ASS_READ_ERROR=270, GPG_ERR_ASS_WRITE_ERROR=271, GPG_ERR_ASS_TOO_MUCH_DATA=273, GPG_ERR_ASS_UNEXPECTED_CMD=274, GPG_ERR_ASS_UNKNOWN_CMD=275, GPG_ERR_ASS_SYNTAX=276, GPG_ERR_ASS_CANCELED=277, GPG_ERR_ASS_NO_INPUT=278, GPG_ERR_ASS_NO_OUTPUT=279, GPG_ERR_ASS_PARAMETER=280, GPG_ERR_ASS_UNKNOWN_INQUIRE=281, GPG_ERR_ENGINE_TOO_OLD=300, GPG_ERR_WINDOW_TOO_SMALL=301, GPG_ERR_WINDOW_TOO_LARGE=302, GPG_ERR_MISSING_ENVVAR=303, GPG_ERR_USER_ID_EXISTS=304, GPG_ERR_NAME_EXISTS=305, GPG_ERR_DUP_NAME=306, GPG_ERR_TOO_YOUNG=307, GPG_ERR_TOO_OLD=308, GPG_ERR_UNKNOWN_FLAG=309, GPG_ERR_INV_ORDER=310, GPG_ERR_ALREADY_FETCHED=311, GPG_ERR_TRY_LATER=312, GPG_ERR_WRONG_NAME=313, GPG_ERR_SYSTEM_BUG=666, GPG_ERR_DNS_UNKNOWN=711, GPG_ERR_DNS_SECTION=712, GPG_ERR_DNS_ADDRESS=713, GPG_ERR_DNS_NO_QUERY=714, GPG_ERR_DNS_NO_ANSWER=715, GPG_ERR_DNS_CLOSED=716, GPG_ERR_DNS_VERIFY=717, GPG_ERR_DNS_TIMEOUT=718, GPG_ERR_LDAP_GENERAL=721, GPG_ERR_LDAP_ATTR_GENERAL=722, GPG_ERR_LDAP_NAME_GENERAL=723, GPG_ERR_LDAP_SECURITY_GENERAL=724, GPG_ERR_LDAP_SERVICE_GENERAL=725, GPG_ERR_LDAP_UPDATE_GENERAL=726, GPG_ERR_LDAP_E_GENERAL=727, GPG_ERR_LDAP_X_GENERAL=728, GPG_ERR_LDAP_OTHER_GENERAL=729, GPG_ERR_LDAP_X_CONNECTING=750, GPG_ERR_LDAP_REFERRAL_LIMIT=751, GPG_ERR_LDAP_CLIENT_LOOP=752, GPG_ERR_LDAP_NO_RESULTS=754, GPG_ERR_LDAP_CONTROL_NOT_FOUND=755, GPG_ERR_LDAP_NOT_SUPPORTED=756, GPG_ERR_LDAP_CONNECT=757, GPG_ERR_LDAP_NO_MEMORY=758, GPG_ERR_LDAP_PARAM=759, GPG_ERR_LDAP_USER_CANCELLED=760, GPG_ERR_LDAP_FILTER=761, GPG_ERR_LDAP_AUTH_UNKNOWN=762, GPG_ERR_LDAP_TIMEOUT=763, GPG_ERR_LDAP_DECODING=764, GPG_ERR_LDAP_ENCODING=765, GPG_ERR_LDAP_LOCAL=766, GPG_ERR_LDAP_SERVER_DOWN=767, GPG_ERR_LDAP_SUCCESS=768, GPG_ERR_LDAP_OPERATIONS=769, GPG_ERR_LDAP_PROTOCOL=770, GPG_ERR_LDAP_TIMELIMIT=771, GPG_ERR_LDAP_SIZELIMIT=772, GPG_ERR_LDAP_COMPARE_FALSE=773, GPG_ERR_LDAP_COMPARE_TRUE=774, GPG_ERR_LDAP_UNSUPPORTED_AUTH=775, GPG_ERR_LDAP_STRONG_AUTH_RQRD=776, GPG_ERR_LDAP_PARTIAL_RESULTS=777, GPG_ERR_LDAP_REFERRAL=778, GPG_ERR_LDAP_ADMINLIMIT=779, GPG_ERR_LDAP_UNAVAIL_CRIT_EXTN=780, GPG_ERR_LDAP_CONFIDENT_RQRD=781, GPG_ERR_LDAP_SASL_BIND_INPROG=782, GPG_ERR_LDAP_NO_SUCH_ATTRIBUTE=784, GPG_ERR_LDAP_UNDEFINED_TYPE=785, GPG_ERR_LDAP_BAD_MATCHING=786, GPG_ERR_LDAP_CONST_VIOLATION=787, GPG_ERR_LDAP_TYPE_VALUE_EXISTS=788, GPG_ERR_LDAP_INV_SYNTAX=789, GPG_ERR_LDAP_NO_SUCH_OBJ=800, GPG_ERR_LDAP_ALIAS_PROBLEM=801, GPG_ERR_LDAP_INV_DN_SYNTAX=802, GPG_ERR_LDAP_IS_LEAF=803, GPG_ERR_LDAP_ALIAS_DEREF=804, GPG_ERR_LDAP_X_PROXY_AUTH_FAIL=815, GPG_ERR_LDAP_BAD_AUTH=816, GPG_ERR_LDAP_INV_CREDENTIALS=817, GPG_ERR_LDAP_INSUFFICIENT_ACC=818, GPG_ERR_LDAP_BUSY=819, GPG_ERR_LDAP_UNAVAILABLE=820, GPG_ERR_LDAP_UNWILL_TO_PERFORM=821, GPG_ERR_LDAP_LOOP_DETECT=822, GPG_ERR_LDAP_NAMING_VIOLATION=832, GPG_ERR_LDAP_OBJ_CLS_VIOLATION=833, GPG_ERR_LDAP_NOT_ALLOW_NONLEAF=834, GPG_ERR_LDAP_NOT_ALLOW_ON_RDN=835, GPG_ERR_LDAP_ALREADY_EXISTS=836, GPG_ERR_LDAP_NO_OBJ_CLASS_MODS=837, GPG_ERR_LDAP_RESULTS_TOO_LARGE=838, GPG_ERR_LDAP_AFFECTS_MULT_DSAS=839, GPG_ERR_LDAP_VLV=844, GPG_ERR_LDAP_OTHER=848, GPG_ERR_LDAP_CUP_RESOURCE_LIMIT=881, GPG_ERR_LDAP_CUP_SEC_VIOLATION=882, GPG_ERR_LDAP_CUP_INV_DATA=883, GPG_ERR_LDAP_CUP_UNSUP_SCHEME=884, GPG_ERR_LDAP_CUP_RELOAD=885, GPG_ERR_LDAP_CANCELLED=886, GPG_ERR_LDAP_NO_SUCH_OPERATION=887, GPG_ERR_LDAP_TOO_LATE=888, GPG_ERR_LDAP_CANNOT_CANCEL=889, GPG_ERR_LDAP_ASSERTION_FAILED=890, GPG_ERR_LDAP_PROX_AUTH_DENIED=891, GPG_ERR_USER_1=1024, GPG_ERR_USER_2=1025, GPG_ERR_USER_3=1026, GPG_ERR_USER_4=1027, GPG_ERR_USER_5=1028, GPG_ERR_USER_6=1029, GPG_ERR_USER_7=1030, GPG_ERR_USER_8=1031, GPG_ERR_USER_9=1032, GPG_ERR_USER_10=1033, GPG_ERR_USER_11=1034, GPG_ERR_USER_12=1035, GPG_ERR_USER_13=1036, GPG_ERR_USER_14=1037, GPG_ERR_USER_15=1038, GPG_ERR_USER_16=1039, GPG_ERR_MISSING_ERRNO=16381, GPG_ERR_UNKNOWN_ERRNO=16382, GPG_ERR_EOF=16383, GPG_ERR_E2BIG=expr, GPG_ERR_EACCES=expr, GPG_ERR_EADDRINUSE=expr, GPG_ERR_EADDRNOTAVAIL=expr, GPG_ERR_EADV=expr, GPG_ERR_EAFNOSUPPORT=expr, GPG_ERR_EAGAIN=expr, GPG_ERR_EALREADY=expr, GPG_ERR_EAUTH=expr, GPG_ERR_EBACKGROUND=expr, GPG_ERR_EBADE=expr, GPG_ERR_EBADF=expr, GPG_ERR_EBADFD=expr, GPG_ERR_EBADMSG=expr, GPG_ERR_EBADR=expr, GPG_ERR_EBADRPC=expr, GPG_ERR_EBADRQC=expr, GPG_ERR_EBADSLT=expr, GPG_ERR_EBFONT=expr, GPG_ERR_EBUSY=expr, GPG_ERR_ECANCELED=expr, GPG_ERR_ECHILD=expr, GPG_ERR_ECHRNG=expr, GPG_ERR_ECOMM=expr, GPG_ERR_ECONNABORTED=expr, GPG_ERR_ECONNREFUSED=expr, GPG_ERR_ECONNRESET=expr, GPG_ERR_ED=expr, GPG_ERR_EDEADLK=expr, GPG_ERR_EDEADLOCK=expr, GPG_ERR_EDESTADDRREQ=expr, GPG_ERR_EDIED=expr, GPG_ERR_EDOM=expr, GPG_ERR_EDOTDOT=expr, GPG_ERR_EDQUOT=expr, GPG_ERR_EEXIST=expr, GPG_ERR_EFAULT=expr, GPG_ERR_EFBIG=expr, GPG_ERR_EFTYPE=expr, GPG_ERR_EGRATUITOUS=expr, GPG_ERR_EGREGIOUS=expr, GPG_ERR_EHOSTDOWN=expr, GPG_ERR_EHOSTUNREACH=expr, GPG_ERR_EIDRM=expr, GPG_ERR_EIEIO=expr, GPG_ERR_EILSEQ=expr, GPG_ERR_EINPROGRESS=expr, GPG_ERR_EINTR=expr, GPG_ERR_EINVAL=expr, GPG_ERR_EIO=expr, GPG_ERR_EISCONN=expr, GPG_ERR_EISDIR=expr, GPG_ERR_EISNAM=expr, GPG_ERR_EL2HLT=expr, GPG_ERR_EL2NSYNC=expr, GPG_ERR_EL3HLT=expr, GPG_ERR_EL3RST=expr, GPG_ERR_ELIBACC=expr, GPG_ERR_ELIBBAD=expr, GPG_ERR_ELIBEXEC=expr, GPG_ERR_ELIBMAX=expr, GPG_ERR_ELIBSCN=expr, GPG_ERR_ELNRNG=expr, GPG_ERR_ELOOP=expr, GPG_ERR_EMEDIUMTYPE=expr, GPG_ERR_EMFILE=expr, GPG_ERR_EMLINK=expr, GPG_ERR_EMSGSIZE=expr, GPG_ERR_EMULTIHOP=expr, GPG_ERR_ENAMETOOLONG=expr, GPG_ERR_ENAVAIL=expr, GPG_ERR_ENEEDAUTH=expr, GPG_ERR_ENETDOWN=expr, GPG_ERR_ENETRESET=expr, GPG_ERR_ENETUNREACH=expr, GPG_ERR_ENFILE=expr, GPG_ERR_ENOANO=expr, GPG_ERR_ENOBUFS=expr, GPG_ERR_ENOCSI=expr, GPG_ERR_ENODATA=expr, GPG_ERR_ENODEV=expr, GPG_ERR_ENOENT=expr, GPG_ERR_ENOEXEC=expr, GPG_ERR_ENOLCK=expr, GPG_ERR_ENOLINK=expr, GPG_ERR_ENOMEDIUM=expr, GPG_ERR_ENOMEM=expr, GPG_ERR_ENOMSG=expr, GPG_ERR_ENONET=expr, GPG_ERR_ENOPKG=expr, GPG_ERR_ENOPROTOOPT=expr, GPG_ERR_ENOSPC=expr, GPG_ERR_ENOSR=expr, GPG_ERR_ENOSTR=expr, GPG_ERR_ENOSYS=expr, GPG_ERR_ENOTBLK=expr, GPG_ERR_ENOTCONN=expr, GPG_ERR_ENOTDIR=expr, GPG_ERR_ENOTEMPTY=expr, GPG_ERR_ENOTNAM=expr, GPG_ERR_ENOTSOCK=expr, GPG_ERR_ENOTSUP=expr, GPG_ERR_ENOTTY=expr, GPG_ERR_ENOTUNIQ=expr, GPG_ERR_ENXIO=expr, GPG_ERR_EOPNOTSUPP=expr, GPG_ERR_EOVERFLOW=expr, GPG_ERR_EPERM=expr, GPG_ERR_EPFNOSUPPORT=expr, GPG_ERR_EPIPE=expr, GPG_ERR_EPROCLIM=expr, GPG_ERR_EPROCUNAVAIL=expr, GPG_ERR_EPROGMISMATCH=expr, GPG_ERR_EPROGUNAVAIL=expr, GPG_ERR_EPROTO=expr, GPG_ERR_EPROTONOSUPPORT=expr, GPG_ERR_EPROTOTYPE=expr, GPG_ERR_ERANGE=expr, GPG_ERR_EREMCHG=expr, GPG_ERR_EREMOTE=expr, GPG_ERR_EREMOTEIO=expr, GPG_ERR_ERESTART=expr, GPG_ERR_EROFS=expr, GPG_ERR_ERPCMISMATCH=expr, GPG_ERR_ESHUTDOWN=expr, GPG_ERR_ESOCKTNOSUPPORT=expr, GPG_ERR_ESPIPE=expr, GPG_ERR_ESRCH=expr, GPG_ERR_ESRMNT=expr, GPG_ERR_ESTALE=expr, GPG_ERR_ESTRPIPE=expr, GPG_ERR_ETIME=expr, GPG_ERR_ETIMEDOUT=expr, GPG_ERR_ETOOMANYREFS=expr, GPG_ERR_ETXTBSY=expr, GPG_ERR_EUCLEAN=expr, GPG_ERR_EUNATCH=expr, GPG_ERR_EUSERS=expr, GPG_ERR_EWOULDBLOCK=expr, GPG_ERR_EXDEV=expr, GPG_ERR_EXFULL=expr, GPG_ERR_CODE_DIM=65536 }


decompiled_code:
// attributes: thunk
__int64 __fastcall gcry_err_code(unsigned __int16 a1)
{
return gpg_err_code(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
return func0(a1);
}

original_code:
static __inline__ gcry_err_code_t
gcry_err_code (gcry_error_t err)
{
  return gpg_err_code (err);
}

canonical_original_code:
static __inline__ enum gpg_err_code_t gcry_err_code(unsigned int err)
{
  return gpg_err_code (err);
}

user_defined_types: enum gpg_err_code_t { GPG_ERR_NO_ERROR=0, GPG_ERR_GENERAL=1, GPG_ERR_UNKNOWN_PACKET=2, GPG_ERR_UNKNOWN_VERSION=3, GPG_ERR_PUBKEY_ALGO=4, GPG_ERR_DIGEST_ALGO=5, GPG_ERR_BAD_PUBKEY=6, GPG_ERR_BAD_SECKEY=7, GPG_ERR_BAD_SIGNATURE=8, GPG_ERR_NO_PUBKEY=9, GPG_ERR_CHECKSUM=10, GPG_ERR_BAD_PASSPHRASE=11, GPG_ERR_CIPHER_ALGO=12, GPG_ERR_KEYRING_OPEN=13, GPG_ERR_INV_PACKET=14, GPG_ERR_INV_ARMOR=15, GPG_ERR_NO_USER_ID=16, GPG_ERR_NO_SECKEY=17, GPG_ERR_WRONG_SECKEY=18, GPG_ERR_BAD_KEY=19, GPG_ERR_COMPR_ALGO=20, GPG_ERR_NO_PRIME=21, GPG_ERR_NO_ENCODING_METHOD=22, GPG_ERR_NO_ENCRYPTION_SCHEME=23, GPG_ERR_NO_SIGNATURE_SCHEME=24, GPG_ERR_INV_ATTR=25, GPG_ERR_NO_VALUE=26, GPG_ERR_NOT_FOUND=27, GPG_ERR_VALUE_NOT_FOUND=28, GPG_ERR_SYNTAX=29, GPG_ERR_BAD_MPI=30, GPG_ERR_INV_PASSPHRASE=31, GPG_ERR_SIG_CLASS=32, GPG_ERR_RESOURCE_LIMIT=33, GPG_ERR_INV_KEYRING=34, GPG_ERR_TRUSTDB=35, GPG_ERR_BAD_CERT=36, GPG_ERR_INV_USER_ID=37, GPG_ERR_UNEXPECTED=38, GPG_ERR_TIME_CONFLICT=39, GPG_ERR_KEYSERVER=40, GPG_ERR_WRONG_PUBKEY_ALGO=41, GPG_ERR_TRIBUTE_TO_D_A=42, GPG_ERR_WEAK_KEY=43, GPG_ERR_INV_KEYLEN=44, GPG_ERR_INV_ARG=45, GPG_ERR_BAD_URI=46, GPG_ERR_INV_URI=47, GPG_ERR_NETWORK=48, GPG_ERR_UNKNOWN_HOST=49, GPG_ERR_SELFTEST_FAILED=50, GPG_ERR_NOT_ENCRYPTED=51, GPG_ERR_NOT_PROCESSED=52, GPG_ERR_UNUSABLE_PUBKEY=53, GPG_ERR_UNUSABLE_SECKEY=54, GPG_ERR_INV_VALUE=55, GPG_ERR_BAD_CERT_CHAIN=56, GPG_ERR_MISSING_CERT=57, GPG_ERR_NO_DATA=58, GPG_ERR_BUG=59, GPG_ERR_NOT_SUPPORTED=60, GPG_ERR_INV_OP=61, GPG_ERR_TIMEOUT=62, GPG_ERR_INTERNAL=63, GPG_ERR_EOF_GCRYPT=64, GPG_ERR_INV_OBJ=65, GPG_ERR_TOO_SHORT=66, GPG_ERR_TOO_LARGE=67, GPG_ERR_NO_OBJ=68, GPG_ERR_NOT_IMPLEMENTED=69, GPG_ERR_CONFLICT=70, GPG_ERR_INV_CIPHER_MODE=71, GPG_ERR_INV_FLAG=72, GPG_ERR_INV_HANDLE=73, GPG_ERR_TRUNCATED=74, GPG_ERR_INCOMPLETE_LINE=75, GPG_ERR_INV_RESPONSE=76, GPG_ERR_NO_AGENT=77, GPG_ERR_AGENT=78, GPG_ERR_INV_DATA=79, GPG_ERR_ASSUAN_SERVER_FAULT=80, GPG_ERR_ASSUAN=81, GPG_ERR_INV_SESSION_KEY=82, GPG_ERR_INV_SEXP=83, GPG_ERR_UNSUPPORTED_ALGORITHM=84, GPG_ERR_NO_PIN_ENTRY=85, GPG_ERR_PIN_ENTRY=86, GPG_ERR_BAD_PIN=87, GPG_ERR_INV_NAME=88, GPG_ERR_BAD_DATA=89, GPG_ERR_INV_PARAMETER=90, GPG_ERR_WRONG_CARD=91, GPG_ERR_NO_DIRMNGR=92, GPG_ERR_DIRMNGR=93, GPG_ERR_CERT_REVOKED=94, GPG_ERR_NO_CRL_KNOWN=95, GPG_ERR_CRL_TOO_OLD=96, GPG_ERR_LINE_TOO_LONG=97, GPG_ERR_NOT_TRUSTED=98, GPG_ERR_CANCELED=99, GPG_ERR_BAD_CA_CERT=100, GPG_ERR_CERT_EXPIRED=101, GPG_ERR_CERT_TOO_YOUNG=102, GPG_ERR_UNSUPPORTED_CERT=103, GPG_ERR_UNKNOWN_SEXP=104, GPG_ERR_UNSUPPORTED_PROTECTION=105, GPG_ERR_CORRUPTED_PROTECTION=106, GPG_ERR_AMBIGUOUS_NAME=107, GPG_ERR_CARD=108, GPG_ERR_CARD_RESET=109, GPG_ERR_CARD_REMOVED=110, GPG_ERR_INV_CARD=111, GPG_ERR_CARD_NOT_PRESENT=112, GPG_ERR_NO_PKCS15_APP=113, GPG_ERR_NOT_CONFIRMED=114, GPG_ERR_CONFIGURATION=115, GPG_ERR_NO_POLICY_MATCH=116, GPG_ERR_INV_INDEX=117, GPG_ERR_INV_ID=118, GPG_ERR_NO_SCDAEMON=119, GPG_ERR_SCDAEMON=120, GPG_ERR_UNSUPPORTED_PROTOCOL=121, GPG_ERR_BAD_PIN_METHOD=122, GPG_ERR_CARD_NOT_INITIALIZED=123, GPG_ERR_UNSUPPORTED_OPERATION=124, GPG_ERR_WRONG_KEY_USAGE=125, GPG_ERR_NOTHING_FOUND=126, GPG_ERR_WRONG_BLOB_TYPE=127, GPG_ERR_MISSING_VALUE=128, GPG_ERR_HARDWARE=129, GPG_ERR_PIN_BLOCKED=130, GPG_ERR_USE_CONDITIONS=131, GPG_ERR_PIN_NOT_SYNCED=132, GPG_ERR_INV_CRL=133, GPG_ERR_BAD_BER=134, GPG_ERR_INV_BER=135, GPG_ERR_ELEMENT_NOT_FOUND=136, GPG_ERR_IDENTIFIER_NOT_FOUND=137, GPG_ERR_INV_TAG=138, GPG_ERR_INV_LENGTH=139, GPG_ERR_INV_KEYINFO=140, GPG_ERR_UNEXPECTED_TAG=141, GPG_ERR_NOT_DER_ENCODED=142, GPG_ERR_NO_CMS_OBJ=143, GPG_ERR_INV_CMS_OBJ=144, GPG_ERR_UNKNOWN_CMS_OBJ=145, GPG_ERR_UNSUPPORTED_CMS_OBJ=146, GPG_ERR_UNSUPPORTED_ENCODING=147, GPG_ERR_UNSUPPORTED_CMS_VERSION=148, GPG_ERR_UNKNOWN_ALGORITHM=149, GPG_ERR_INV_ENGINE=150, GPG_ERR_PUBKEY_NOT_TRUSTED=151, GPG_ERR_DECRYPT_FAILED=152, GPG_ERR_KEY_EXPIRED=153, GPG_ERR_SIG_EXPIRED=154, GPG_ERR_ENCODING_PROBLEM=155, GPG_ERR_INV_STATE=156, GPG_ERR_DUP_VALUE=157, GPG_ERR_MISSING_ACTION=158, GPG_ERR_MODULE_NOT_FOUND=159, GPG_ERR_INV_OID_STRING=160, GPG_ERR_INV_TIME=161, GPG_ERR_INV_CRL_OBJ=162, GPG_ERR_UNSUPPORTED_CRL_VERSION=163, GPG_ERR_INV_CERT_OBJ=164, GPG_ERR_UNKNOWN_NAME=165, GPG_ERR_LOCALE_PROBLEM=166, GPG_ERR_NOT_LOCKED=167, GPG_ERR_PROTOCOL_VIOLATION=168, GPG_ERR_INV_MAC=169, GPG_ERR_INV_REQUEST=170, GPG_ERR_UNKNOWN_EXTN=171, GPG_ERR_UNKNOWN_CRIT_EXTN=172, GPG_ERR_LOCKED=173, GPG_ERR_UNKNOWN_OPTION=174, GPG_ERR_UNKNOWN_COMMAND=175, GPG_ERR_NOT_OPERATIONAL=176, GPG_ERR_NO_PASSPHRASE=177, GPG_ERR_NO_PIN=178, GPG_ERR_NOT_ENABLED=179, GPG_ERR_NO_ENGINE=180, GPG_ERR_MISSING_KEY=181, GPG_ERR_TOO_MANY=182, GPG_ERR_LIMIT_REACHED=183, GPG_ERR_NOT_INITIALIZED=184, GPG_ERR_MISSING_ISSUER_CERT=185, GPG_ERR_NO_KEYSERVER=186, GPG_ERR_INV_CURVE=187, GPG_ERR_UNKNOWN_CURVE=188, GPG_ERR_DUP_KEY=189, GPG_ERR_AMBIGUOUS=190, GPG_ERR_NO_CRYPT_CTX=191, GPG_ERR_WRONG_CRYPT_CTX=192, GPG_ERR_BAD_CRYPT_CTX=193, GPG_ERR_CRYPT_CTX_CONFLICT=194, GPG_ERR_BROKEN_PUBKEY=195, GPG_ERR_BROKEN_SECKEY=196, GPG_ERR_MAC_ALGO=197, GPG_ERR_FULLY_CANCELED=198, GPG_ERR_UNFINISHED=199, GPG_ERR_BUFFER_TOO_SHORT=200, GPG_ERR_SEXP_INV_LEN_SPEC=201, GPG_ERR_SEXP_STRING_TOO_LONG=202, GPG_ERR_SEXP_UNMATCHED_PAREN=203, GPG_ERR_SEXP_NOT_CANONICAL=204, GPG_ERR_SEXP_BAD_CHARACTER=205, GPG_ERR_SEXP_BAD_QUOTATION=206, GPG_ERR_SEXP_ZERO_PREFIX=207, GPG_ERR_SEXP_NESTED_DH=208, GPG_ERR_SEXP_UNMATCHED_DH=209, GPG_ERR_SEXP_UNEXPECTED_PUNC=210, GPG_ERR_SEXP_BAD_HEX_CHAR=211, GPG_ERR_SEXP_ODD_HEX_NUMBERS=212, GPG_ERR_SEXP_BAD_OCT_CHAR=213, GPG_ERR_SUBKEYS_EXP_OR_REV=217, GPG_ERR_DB_CORRUPTED=218, GPG_ERR_SERVER_FAILED=219, GPG_ERR_NO_NAME=220, GPG_ERR_NO_KEY=221, GPG_ERR_LEGACY_KEY=222, GPG_ERR_REQUEST_TOO_SHORT=223, GPG_ERR_REQUEST_TOO_LONG=224, GPG_ERR_OBJ_TERM_STATE=225, GPG_ERR_NO_CERT_CHAIN=226, GPG_ERR_CERT_TOO_LARGE=227, GPG_ERR_INV_RECORD=228, GPG_ERR_BAD_MAC=229, GPG_ERR_UNEXPECTED_MSG=230, GPG_ERR_COMPR_FAILED=231, GPG_ERR_WOULD_WRAP=232, GPG_ERR_FATAL_ALERT=233, GPG_ERR_NO_CIPHER=234, GPG_ERR_MISSING_CLIENT_CERT=235, GPG_ERR_CLOSE_NOTIFY=236, GPG_ERR_TICKET_EXPIRED=237, GPG_ERR_BAD_TICKET=238, GPG_ERR_UNKNOWN_IDENTITY=239, GPG_ERR_BAD_HS_CERT=240, GPG_ERR_BAD_HS_CERT_REQ=241, GPG_ERR_BAD_HS_CERT_VER=242, GPG_ERR_BAD_HS_CHANGE_CIPHER=243, GPG_ERR_BAD_HS_CLIENT_HELLO=244, GPG_ERR_BAD_HS_SERVER_HELLO=245, GPG_ERR_BAD_HS_SERVER_HELLO_DONE=246, GPG_ERR_BAD_HS_FINISHED=247, GPG_ERR_BAD_HS_SERVER_KEX=248, GPG_ERR_BAD_HS_CLIENT_KEX=249, GPG_ERR_BOGUS_STRING=250, GPG_ERR_FORBIDDEN=251, GPG_ERR_KEY_DISABLED=252, GPG_ERR_KEY_ON_CARD=253, GPG_ERR_INV_LOCK_OBJ=254, GPG_ERR_TRUE=255, GPG_ERR_FALSE=256, GPG_ERR_ASS_GENERAL=257, GPG_ERR_ASS_ACCEPT_FAILED=258, GPG_ERR_ASS_CONNECT_FAILED=259, GPG_ERR_ASS_INV_RESPONSE=260, GPG_ERR_ASS_INV_VALUE=261, GPG_ERR_ASS_INCOMPLETE_LINE=262, GPG_ERR_ASS_LINE_TOO_LONG=263, GPG_ERR_ASS_NESTED_COMMANDS=264, GPG_ERR_ASS_NO_DATA_CB=265, GPG_ERR_ASS_NO_INQUIRE_CB=266, GPG_ERR_ASS_NOT_A_SERVER=267, GPG_ERR_ASS_NOT_A_CLIENT=268, GPG_ERR_ASS_SERVER_START=269, GPG_ERR_ASS_READ_ERROR=270, GPG_ERR_ASS_WRITE_ERROR=271, GPG_ERR_ASS_TOO_MUCH_DATA=273, GPG_ERR_ASS_UNEXPECTED_CMD=274, GPG_ERR_ASS_UNKNOWN_CMD=275, GPG_ERR_ASS_SYNTAX=276, GPG_ERR_ASS_CANCELED=277, GPG_ERR_ASS_NO_INPUT=278, GPG_ERR_ASS_NO_OUTPUT=279, GPG_ERR_ASS_PARAMETER=280, GPG_ERR_ASS_UNKNOWN_INQUIRE=281, GPG_ERR_ENGINE_TOO_OLD=300, GPG_ERR_WINDOW_TOO_SMALL=301, GPG_ERR_WINDOW_TOO_LARGE=302, GPG_ERR_MISSING_ENVVAR=303, GPG_ERR_USER_ID_EXISTS=304, GPG_ERR_NAME_EXISTS=305, GPG_ERR_DUP_NAME=306, GPG_ERR_TOO_YOUNG=307, GPG_ERR_TOO_OLD=308, GPG_ERR_UNKNOWN_FLAG=309, GPG_ERR_INV_ORDER=310, GPG_ERR_ALREADY_FETCHED=311, GPG_ERR_TRY_LATER=312, GPG_ERR_WRONG_NAME=313, GPG_ERR_SYSTEM_BUG=666, GPG_ERR_DNS_UNKNOWN=711, GPG_ERR_DNS_SECTION=712, GPG_ERR_DNS_ADDRESS=713, GPG_ERR_DNS_NO_QUERY=714, GPG_ERR_DNS_NO_ANSWER=715, GPG_ERR_DNS_CLOSED=716, GPG_ERR_DNS_VERIFY=717, GPG_ERR_DNS_TIMEOUT=718, GPG_ERR_LDAP_GENERAL=721, GPG_ERR_LDAP_ATTR_GENERAL=722, GPG_ERR_LDAP_NAME_GENERAL=723, GPG_ERR_LDAP_SECURITY_GENERAL=724, GPG_ERR_LDAP_SERVICE_GENERAL=725, GPG_ERR_LDAP_UPDATE_GENERAL=726, GPG_ERR_LDAP_E_GENERAL=727, GPG_ERR_LDAP_X_GENERAL=728, GPG_ERR_LDAP_OTHER_GENERAL=729, GPG_ERR_LDAP_X_CONNECTING=750, GPG_ERR_LDAP_REFERRAL_LIMIT=751, GPG_ERR_LDAP_CLIENT_LOOP=752, GPG_ERR_LDAP_NO_RESULTS=754, GPG_ERR_LDAP_CONTROL_NOT_FOUND=755, GPG_ERR_LDAP_NOT_SUPPORTED=756, GPG_ERR_LDAP_CONNECT=757, GPG_ERR_LDAP_NO_MEMORY=758, GPG_ERR_LDAP_PARAM=759, GPG_ERR_LDAP_USER_CANCELLED=760, GPG_ERR_LDAP_FILTER=761, GPG_ERR_LDAP_AUTH_UNKNOWN=762, GPG_ERR_LDAP_TIMEOUT=763, GPG_ERR_LDAP_DECODING=764, GPG_ERR_LDAP_ENCODING=765, GPG_ERR_LDAP_LOCAL=766, GPG_ERR_LDAP_SERVER_DOWN=767, GPG_ERR_LDAP_SUCCESS=768, GPG_ERR_LDAP_OPERATIONS=769, GPG_ERR_LDAP_PROTOCOL=770, GPG_ERR_LDAP_TIMELIMIT=771, GPG_ERR_LDAP_SIZELIMIT=772, GPG_ERR_LDAP_COMPARE_FALSE=773, GPG_ERR_LDAP_COMPARE_TRUE=774, GPG_ERR_LDAP_UNSUPPORTED_AUTH=775, GPG_ERR_LDAP_STRONG_AUTH_RQRD=776, GPG_ERR_LDAP_PARTIAL_RESULTS=777, GPG_ERR_LDAP_REFERRAL=778, GPG_ERR_LDAP_ADMINLIMIT=779, GPG_ERR_LDAP_UNAVAIL_CRIT_EXTN=780, GPG_ERR_LDAP_CONFIDENT_RQRD=781, GPG_ERR_LDAP_SASL_BIND_INPROG=782, GPG_ERR_LDAP_NO_SUCH_ATTRIBUTE=784, GPG_ERR_LDAP_UNDEFINED_TYPE=785, GPG_ERR_LDAP_BAD_MATCHING=786, GPG_ERR_LDAP_CONST_VIOLATION=787, GPG_ERR_LDAP_TYPE_VALUE_EXISTS=788, GPG_ERR_LDAP_INV_SYNTAX=789, GPG_ERR_LDAP_NO_SUCH_OBJ=800, GPG_ERR_LDAP_ALIAS_PROBLEM=801, GPG_ERR_LDAP_INV_DN_SYNTAX=802, GPG_ERR_LDAP_IS_LEAF=803, GPG_ERR_LDAP_ALIAS_DEREF=804, GPG_ERR_LDAP_X_PROXY_AUTH_FAIL=815, GPG_ERR_LDAP_BAD_AUTH=816, GPG_ERR_LDAP_INV_CREDENTIALS=817, GPG_ERR_LDAP_INSUFFICIENT_ACC=818, GPG_ERR_LDAP_BUSY=819, GPG_ERR_LDAP_UNAVAILABLE=820, GPG_ERR_LDAP_UNWILL_TO_PERFORM=821, GPG_ERR_LDAP_LOOP_DETECT=822, GPG_ERR_LDAP_NAMING_VIOLATION=832, GPG_ERR_LDAP_OBJ_CLS_VIOLATION=833, GPG_ERR_LDAP_NOT_ALLOW_NONLEAF=834, GPG_ERR_LDAP_NOT_ALLOW_ON_RDN=835, GPG_ERR_LDAP_ALREADY_EXISTS=836, GPG_ERR_LDAP_NO_OBJ_CLASS_MODS=837, GPG_ERR_LDAP_RESULTS_TOO_LARGE=838, GPG_ERR_LDAP_AFFECTS_MULT_DSAS=839, GPG_ERR_LDAP_VLV=844, GPG_ERR_LDAP_OTHER=848, GPG_ERR_LDAP_CUP_RESOURCE_LIMIT=881, GPG_ERR_LDAP_CUP_SEC_VIOLATION=882, GPG_ERR_LDAP_CUP_INV_DATA=883, GPG_ERR_LDAP_CUP_UNSUP_SCHEME=884, GPG_ERR_LDAP_CUP_RELOAD=885, GPG_ERR_LDAP_CANCELLED=886, GPG_ERR_LDAP_NO_SUCH_OPERATION=887, GPG_ERR_LDAP_TOO_LATE=888, GPG_ERR_LDAP_CANNOT_CANCEL=889, GPG_ERR_LDAP_ASSERTION_FAILED=890, GPG_ERR_LDAP_PROX_AUTH_DENIED=891, GPG_ERR_USER_1=1024, GPG_ERR_USER_2=1025, GPG_ERR_USER_3=1026, GPG_ERR_USER_4=1027, GPG_ERR_USER_5=1028, GPG_ERR_USER_6=1029, GPG_ERR_USER_7=1030, GPG_ERR_USER_8=1031, GPG_ERR_USER_9=1032, GPG_ERR_USER_10=1033, GPG_ERR_USER_11=1034, GPG_ERR_USER_12=1035, GPG_ERR_USER_13=1036, GPG_ERR_USER_14=1037, GPG_ERR_USER_15=1038, GPG_ERR_USER_16=1039, GPG_ERR_MISSING_ERRNO=16381, GPG_ERR_UNKNOWN_ERRNO=16382, GPG_ERR_EOF=16383, GPG_ERR_E2BIG=expr, GPG_ERR_EACCES=expr, GPG_ERR_EADDRINUSE=expr, GPG_ERR_EADDRNOTAVAIL=expr, GPG_ERR_EADV=expr, GPG_ERR_EAFNOSUPPORT=expr, GPG_ERR_EAGAIN=expr, GPG_ERR_EALREADY=expr, GPG_ERR_EAUTH=expr, GPG_ERR_EBACKGROUND=expr, GPG_ERR_EBADE=expr, GPG_ERR_EBADF=expr, GPG_ERR_EBADFD=expr, GPG_ERR_EBADMSG=expr, GPG_ERR_EBADR=expr, GPG_ERR_EBADRPC=expr, GPG_ERR_EBADRQC=expr, GPG_ERR_EBADSLT=expr, GPG_ERR_EBFONT=expr, GPG_ERR_EBUSY=expr, GPG_ERR_ECANCELED=expr, GPG_ERR_ECHILD=expr, GPG_ERR_ECHRNG=expr, GPG_ERR_ECOMM=expr, GPG_ERR_ECONNABORTED=expr, GPG_ERR_ECONNREFUSED=expr, GPG_ERR_ECONNRESET=expr, GPG_ERR_ED=expr, GPG_ERR_EDEADLK=expr, GPG_ERR_EDEADLOCK=expr, GPG_ERR_EDESTADDRREQ=expr, GPG_ERR_EDIED=expr, GPG_ERR_EDOM=expr, GPG_ERR_EDOTDOT=expr, GPG_ERR_EDQUOT=expr, GPG_ERR_EEXIST=expr, GPG_ERR_EFAULT=expr, GPG_ERR_EFBIG=expr, GPG_ERR_EFTYPE=expr, GPG_ERR_EGRATUITOUS=expr, GPG_ERR_EGREGIOUS=expr, GPG_ERR_EHOSTDOWN=expr, GPG_ERR_EHOSTUNREACH=expr, GPG_ERR_EIDRM=expr, GPG_ERR_EIEIO=expr, GPG_ERR_EILSEQ=expr, GPG_ERR_EINPROGRESS=expr, GPG_ERR_EINTR=expr, GPG_ERR_EINVAL=expr, GPG_ERR_EIO=expr, GPG_ERR_EISCONN=expr, GPG_ERR_EISDIR=expr, GPG_ERR_EISNAM=expr, GPG_ERR_EL2HLT=expr, GPG_ERR_EL2NSYNC=expr, GPG_ERR_EL3HLT=expr, GPG_ERR_EL3RST=expr, GPG_ERR_ELIBACC=expr, GPG_ERR_ELIBBAD=expr, GPG_ERR_ELIBEXEC=expr, GPG_ERR_ELIBMAX=expr, GPG_ERR_ELIBSCN=expr, GPG_ERR_ELNRNG=expr, GPG_ERR_ELOOP=expr, GPG_ERR_EMEDIUMTYPE=expr, GPG_ERR_EMFILE=expr, GPG_ERR_EMLINK=expr, GPG_ERR_EMSGSIZE=expr, GPG_ERR_EMULTIHOP=expr, GPG_ERR_ENAMETOOLONG=expr, GPG_ERR_ENAVAIL=expr, GPG_ERR_ENEEDAUTH=expr, GPG_ERR_ENETDOWN=expr, GPG_ERR_ENETRESET=expr, GPG_ERR_ENETUNREACH=expr, GPG_ERR_ENFILE=expr, GPG_ERR_ENOANO=expr, GPG_ERR_ENOBUFS=expr, GPG_ERR_ENOCSI=expr, GPG_ERR_ENODATA=expr, GPG_ERR_ENODEV=expr, GPG_ERR_ENOENT=expr, GPG_ERR_ENOEXEC=expr, GPG_ERR_ENOLCK=expr, GPG_ERR_ENOLINK=expr, GPG_ERR_ENOMEDIUM=expr, GPG_ERR_ENOMEM=expr, GPG_ERR_ENOMSG=expr, GPG_ERR_ENONET=expr, GPG_ERR_ENOPKG=expr, GPG_ERR_ENOPROTOOPT=expr, GPG_ERR_ENOSPC=expr, GPG_ERR_ENOSR=expr, GPG_ERR_ENOSTR=expr, GPG_ERR_ENOSYS=expr, GPG_ERR_ENOTBLK=expr, GPG_ERR_ENOTCONN=expr, GPG_ERR_ENOTDIR=expr, GPG_ERR_ENOTEMPTY=expr, GPG_ERR_ENOTNAM=expr, GPG_ERR_ENOTSOCK=expr, GPG_ERR_ENOTSUP=expr, GPG_ERR_ENOTTY=expr, GPG_ERR_ENOTUNIQ=expr, GPG_ERR_ENXIO=expr, GPG_ERR_EOPNOTSUPP=expr, GPG_ERR_EOVERFLOW=expr, GPG_ERR_EPERM=expr, GPG_ERR_EPFNOSUPPORT=expr, GPG_ERR_EPIPE=expr, GPG_ERR_EPROCLIM=expr, GPG_ERR_EPROCUNAVAIL=expr, GPG_ERR_EPROGMISMATCH=expr, GPG_ERR_EPROGUNAVAIL=expr, GPG_ERR_EPROTO=expr, GPG_ERR_EPROTONOSUPPORT=expr, GPG_ERR_EPROTOTYPE=expr, GPG_ERR_ERANGE=expr, GPG_ERR_EREMCHG=expr, GPG_ERR_EREMOTE=expr, GPG_ERR_EREMOTEIO=expr, GPG_ERR_ERESTART=expr, GPG_ERR_EROFS=expr, GPG_ERR_ERPCMISMATCH=expr, GPG_ERR_ESHUTDOWN=expr, GPG_ERR_ESOCKTNOSUPPORT=expr, GPG_ERR_ESPIPE=expr, GPG_ERR_ESRCH=expr, GPG_ERR_ESRMNT=expr, GPG_ERR_ESTALE=expr, GPG_ERR_ESTRPIPE=expr, GPG_ERR_ETIME=expr, GPG_ERR_ETIMEDOUT=expr, GPG_ERR_ETOOMANYREFS=expr, GPG_ERR_ETXTBSY=expr, GPG_ERR_EUCLEAN=expr, GPG_ERR_EUNATCH=expr, GPG_ERR_EUSERS=expr, GPG_ERR_EWOULDBLOCK=expr, GPG_ERR_EXDEV=expr, GPG_ERR_EXFULL=expr, GPG_ERR_CODE_DIM=65536 }


decompiled_code:
int __fastcall print_hex(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = a1;
do
{
v4 = *v3++;
result = printf("%02X", v4);
}
while ( v2 != v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 )
{
v2 = &a1[a2];
v3 = a1;
do
{
v4 = *v3++;
result = printf("%02X", v4);
}
while ( v2 != v3 );
}
return result;
}

original_code:
void print_hex(const char *str, const size_t str_len)
{
    int i;
    for(i = 0; i < str_len; i++)
    {
        printf("%02X", (unsigned char)str[i]);
    }
}

canonical_original_code:
void print_hex(char *str, unsigned long str_len)
{
    int i;
    for(i = 0; i < str_len; i++)
    {
        printf("%02X", (unsigned char)str[i]);
    }
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
void *__fastcall get_filename(void *src)
{
char *v1; // rax
const char *v2; // rbp
size_t v3; // r12
char *v4; // rax
void *result; // rax
size_t v6; // r12
void *v7; // rax

v1 = strrchr((const char *)src, 47);
if ( v1 )
{
v2 = v1 + 1;
v3 = strlen(v1 + 1) + 1;
v4 = (char *)calloc(1uLL, v3);
result = strncpy(v4, v2, v3);
}
else
{
v6 = strlen((const char *)src) + 1;
v7 = calloc(1uLL, v6);
result = memcpy(v7, src, v6);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(void *src)
{
char *v1; // rax
const char *v2; // rbp
size_t v3; // r12
char *v4; // rax
void *result; // rax
size_t v6; // r12
void *v7; // rax

v1 = strrchr((const char *)src, 47);
if ( v1 )
{
v2 = v1 + 1;
v3 = strlen(v1 + 1) + 1;
v4 = (char *)calloc(1uLL, v3);
result = strncpy(v4, v2, v3);
}
else
{
v6 = strlen((const char *)src) + 1;
v7 = calloc(1uLL, v6);
result = memcpy(v7, src, v6);
}
return result;
}

original_code:
char* get_filename(const char *filepath)
{
    size_t len;
    char *last_loc, *filename;
    if((last_loc = strrchr(filepath, '/')) == ((void *)0))
    {
        filename = (char*)calloc(1, strlen(filepath) + 1);
        strcpy(filename, filepath);
        return filename;
    }
    last_loc++;
    len = strlen(last_loc);
    filename = (char*)calloc(1, len + 1);
    strncpy(filename, last_loc, len + 1);
    return filename;
}

canonical_original_code:
char *get_filename(char *filepath)
{
    unsigned long len;
    char *last_loc; char *filename;
    if((last_loc = strrchr(filepath, '/')) == ((void *)0))
    {
        filename = (char *)calloc(1, strlen(filepath) + 1);
        strcpy(filename, filepath);
        return filename;
    }
    last_loc++;
    len = strlen(last_loc);
    filename = (char *)calloc(1, len + 1);
    strncpy(filename, last_loc, len + 1);
    return filename;
}

variable_types:
filepath
char *

variable_types:
len
unsigned long

variable_types:
filename
char *

return_type: char *


decompiled_code:
const char *__fastcall get_str_cipher_mode(unsigned int a1)
{
const char *result; // rax

result = "unknown";
if ( a1 <= 7 )
result = CSWTCH_7[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func6(unsigned int a1)
{
const char *result; // rax

result = "unknown";
if ( a1 <= 7 )
result = CSWTCH_7[a1];
return result;
}

original_code:
char* get_str_cipher_mode(int mode)
{
    switch(mode)
    {
        case GCRY_CIPHER_MODE_NONE:
            return "NONE";
        case GCRY_CIPHER_MODE_ECB:
            return "ECB";
        case GCRY_CIPHER_MODE_CFB:
            return "CFB";
        case GCRY_CIPHER_MODE_CBC:
            return "CBC";
        case GCRY_CIPHER_MODE_STREAM:
            return "Stream";
        case GCRY_CIPHER_MODE_OFB:
            return "OFB";
        case GCRY_CIPHER_MODE_CTR:
            return "Counter";
        case GCRY_CIPHER_MODE_AESWRAP:
            return "AES wrap";
        default:
            return "unknown";
    }
}

canonical_original_code:
char *get_str_cipher_mode(int mode)
{
    switch(mode)
    {
        case GCRY_CIPHER_MODE_NONE:
            return "NONE";
        case GCRY_CIPHER_MODE_ECB:
            return "ECB";
        case GCRY_CIPHER_MODE_CFB:
            return "CFB";
        case GCRY_CIPHER_MODE_CBC:
            return "CBC";
        case GCRY_CIPHER_MODE_STREAM:
            return "Stream";
        case GCRY_CIPHER_MODE_OFB:
            return "OFB";
        case GCRY_CIPHER_MODE_CTR:
            return "Counter";
        case GCRY_CIPHER_MODE_AESWRAP:
            return "AES wrap";
        default:
            return "unknown";
    }
}

variable_types: mode int


decompiled_code:
int __fastcall print_gcry_error(const char *a1, _DWORD *a2)
{
unsigned int v2; // eax
const char *v3; // rcx
const char *v4; // r8

gcry_strsource((unsigned int)*a2);
gcry_strerror((unsigned int)*a2);
v2 = gcry_err_code(*a2);
return printf("%s: [%d] %s - %s\n", a1, v2, v3, v4);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, _DWORD *a2)
{
unsigned int v2; // eax
const char *v3; // rcx
const char *v4; // r8

gcry_strsource((unsigned int)*a2);
gcry_strerror((unsigned int)*a2);
v2 = func1(*a2);
return printf("%s: [%d] %s - %s\n", a1, v2, v3, v4);
}

original_code:
void print_gcry_error(const char* message, const gcry_error_t* error)
{
    printf("%s: [%d] %s - %s\n",
            message,
            gcry_err_code(*error),
            gcry_strerror(*error),
            gcry_strsource(*error));
}

canonical_original_code:
void print_gcry_error(char *message, unsigned int *error)
{
    printf("%s: [%d] %s - %s\n",
            message,
            gcry_err_code(*error),
            gcry_strerror(*error),
            gcry_strsource(*error));
}

variable_types:
message
char *

variable_types:
error
unsigned int *


decompiled_code:
__int64 __fastcall hw_init(_QWORD *a1)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v1 = (int)a1;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 352) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * ((v1 - (v2 & 0xFFFFFFF8) + 368) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v1 = (int)a1;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 352) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * ((v1 - (v2 & 0xFFFFFFF8) + 368) >> 3));
return result;
}

original_code:
void hw_init(struct mtev_hw_state *hw)
{
 memset(hw, 0, sizeof(struct mtev_hw_state));
}

variable_types: struct mtev_hw_state { struct mtev_touch_point { int touch_major; int width_major; int orientation; int position_x; int pressure; int tracking_id; } contact[10]; int num_contacts; int num_read; } *

user_defined_types: struct mtev_hw_state { struct mtev_touch_point contact[10]; int num_contacts; int num_read; }


repo: motevin/Shell

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
setvbuf(_bss_start, 0LL, 2, 0LL);
signal(2, interrupt_handler);
while ( 1 )
{
prompt();
fflush(_bss_start);
getargs();
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
setvbuf(_bss_start, 0LL, 2, 0LL);
signal(2, interrupt_handler);
while ( 1 )
{
func8();
fflush(_bss_start);
func15();
}
}

original_code:
int main(int argc, char *argv[]) {
      (argc) = (argc);
      (argv) = (argv);
      setvbuf(stdout, ((void *)0), 2, 0);
      signal(2, interrupt_handler);
      while (1) {
        prompt();
        fflush(stdout);
        getargs();
  }
  return 0;
  }

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void interrupt_handler()
{
puts("<Control-C>");
}

canonical_decompiled_code:
void func7()
{
puts("<Control-C>");
}

original_code:
void interrupt_handler(int signum) {
      printf("<Control-C>\n");
      signum = 0;
      if (signum == 0) {
        return;
      }
    }

variable_types: signum int


prompt

decompiled_code:
int prompt()
{
char *v0; // r13
__int64 v1; // rbp
char *v2; // r12
__uid_t v3; // eax
struct passwd *v4; // rax

v0 = getcwd(0LL, 0LL);
v1 = sysconf(180);
v2 = (char *)calloc(v1, 1uLL);
gethostname(v2, v1);
sysconf(71);
v3 = getuid();
v4 = getpwuid(v3);
return printf("%s@%s:%s> ", v4->pw_name, v2, v0);
}

canonical_decompiled_code:
int func8()
{
char *v0; // r13
__int64 v1; // rbp
char *v2; // r12
__uid_t v3; // eax
struct passwd *v4; // rax

v0 = getcwd(0LL, 0LL);
v1 = sysconf(180);
v2 = (char *)calloc(v1, 1uLL);
gethostname(v2, v1);
sysconf(71);
v3 = getuid();
v4 = getpwuid(v3);
return printf("%s@%s:%s> ", v4->pw_name, v2, v0);
}

original_code:
void prompt()
  {
    char *pwd = getcwd(((void *)0), 0);
    char *host;
  size_t host_max = sysconf(_SC_HOST_NAME_MAX);
  host = calloc(host_max, sizeof(char));
  gethostname(host, host_max);
  char *user;
  size_t user_max = sysconf(_SC_LOGIN_NAME_MAX);
  user = calloc(user_max, sizeof(char));
  struct passwd *pw = getpwuid(getuid());
  user = pw->pw_name;
  printf("%s@%s:%s> ", user, host, pwd);
  }

canonical_original_code:
void prompt()
  {
    char *pwd = getcwd(((void *)0), 0);
    char *host;
  unsigned long host_max = sysconf(_SC_HOST_NAME_MAX);
  host = calloc(host_max, sizeof(char));
  gethostname(host, host_max);
  char *user;
  unsigned long user_max = sysconf(_SC_LOGIN_NAME_MAX);
  user = calloc(user_max, sizeof(char));
  struct passwd *pw = getpwuid(getuid());
  user = pw->pw_name;
  printf("%s@%s:%s> ", user, host, pwd);
  }

variable_types:
pwd
char *

variable_types:
host
char *

variable_types:
user
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
void __noreturn do_exit()
{
puts("So long and thanks for all the fish!");
exit(0);
}

canonical_decompiled_code:
void __noreturn func9()
{
puts("So long and thanks for all the fish!");
exit(0);
}

original_code:
void do_exit() {
    printf("So long and thanks for all the fish!\n");
    exit(0);
  }


deleteArgs

decompiled_code:
void __fastcall deleteArgs(void **a1)
{
void **v1; // rbx
void *i; // rdi

v1 = a1;
for ( i = *a1; i; ++v1 )
{
free(i);
i = v1[1];
}
}

canonical_decompiled_code:
void __fastcall func11(void **a1)
{
void **v1; // rbx
void *i; // rdi

v1 = a1;
for ( i = *a1; i; ++v1 )
{
free(i);
i = v1[1];
}
}

original_code:
void deleteArgs(char** args) {
    char* arg = *(args);
    while (arg != 0) {
      free(arg);
      arg = *(++args);
    }
  }

canonical_original_code:
void deleteArgs(char **args) {
    char *arg = *(args);
    while (arg != 0) {
      free(arg);
      arg = *(++args);
    }
  }

variable_types:
args
char **

variable_types:
arg
char *


memoryError

decompiled_code:
void __noreturn memoryError()
{
printf("HERE BE DRAGONS");
do_exit();
}

canonical_decompiled_code:
void __noreturn func12()
{
printf("HERE BE DRAGONS");
func9();
}

original_code:
void memoryError() {
    printf("HERE BE DRAGONS");
    do_exit();
  }


addWord

original_code:
fd addWord(char* word, char*** arguments, int* argCount, int* argSteps, char* error, fd redirect, char** file) {
    if (redirect != -1) {
      if (strncmp(word, "<", 1) == 0 || strncmp(word, ">", 1) == 0 || strncmp(word, "2>", 2) == 0) {
        *error |= 1;
      }
      file[redirect] = word;
      return -1;
    }
    else if (strncmp(word, "<", 1) == 0) {
      if (file[0][0]) {
        *error |= 1;
        return -1;
      } else {
        *error |= 32;
        return 0;
      }
    } else if (strncmp(word, ">", 1) == 0) {
      if (file[1][0]) {
        *error |= 1;
        return -1;
      } else {
        *error |= 16;
        return 1;
      }
    } else if (strncmp(word, "2>", 2) == 0) {
      if (file[2][0]) {
        *error |= 1;
        return -1;
      } else {
        *error |= 64;
        return 2;
      }
    } else {
      if (file[2][0] || file[1][0] || file[0][0]) {
        *error |= 1;
        return -1;
      }
      if (*argCount == (*argSteps * 5)) {
        (*argSteps)++;
        char** newArguments = (char**)calloc(*argSteps * 5, sizeof(char*));
        if (!newArguments) {
          memoryError();
        }
        memcpy(newArguments, *arguments, sizeof(char**) * ((*argSteps) - 1) * 5);
        free(*arguments);
        *arguments = newArguments;
      }
      (*arguments)[*argCount] = word;
      (*argCount)++;
      return -1;
    }
}

canonical_original_code:
int addWord(char *word, char ***arguments, int *argCount, int *argSteps, char *error, int redirect, char **file) {
    if (redirect != -1) {
      if (strncmp(word, "<", 1) == 0 || strncmp(word, ">", 1) == 0 || strncmp(word, "2>", 2) == 0) {
        *error |= 1;
      }
      file[redirect] = word;
      return -1;
    }
    else if (strncmp(word, "<", 1) == 0) {
      if (file[0][0]) {
        *error |= 1;
        return -1;
      } else {
        *error |= 32;
        return 0;
      }
    } else if (strncmp(word, ">", 1) == 0) {
      if (file[1][0]) {
        *error |= 1;
        return -1;
      } else {
        *error |= 16;
        return 1;
      }
    } else if (strncmp(word, "2>", 2) == 0) {
      if (file[2][0]) {
        *error |= 1;
        return -1;
      } else {
        *error |= 64;
        return 2;
      }
    } else {
      if (file[2][0] || file[1][0] || file[0][0]) {
        *error |= 1;
        return -1;
      }
      if (*argCount == (*argSteps * 5)) {
        (*argSteps)++;
        char **newArguments = (char**)calloc(*argSteps * 5, sizeof(char*));
        if (!newArguments) {
          memoryError();
        }
        memcpy(newArguments, *arguments, sizeof(char **) * ((*argSteps) - 1) * 5);
        free(*arguments);
        *arguments = newArguments;
      }
      (*arguments)[*argCount] = word;
      (*argCount)++;
      return -1;
    }
}

variable_types:
word
char *

variable_types:
arguments
char ***

variable_types:
argCount
int *

variable_types:
argSteps
int *

variable_types:
error
char *

variable_types: redirect int

variable_types:
file
char **

variable_types:
newArguments
char **


readArgs

original_code:
char** readArgs(char* error, char** file) {
    char** arguments = (char**)calloc(5, sizeof(char*));
    if (!arguments) {
      memoryError();
    }
    int argCount = 0;
    int argSteps = 1;
    char c = getchar();
    while (c == ' ' || c == '\t') {
      c = getchar();
    }
    char* cmdWord = (char*)calloc(10 + 1, sizeof(char));
    if (!cmdWord) {
      memoryError();
    }
    int wordChunks = 1;
    int wordLength = 0;
    fd redirect = -1;
    while (c != '\n' && c != (-1)) {
      if (c == '\t' || c == ' ') {
        while (c == '\t' || c == ' ') {
          c = getchar();
        }
        cmdWord[wordLength] = 0;
        redirect = addWord(cmdWord, &arguments, &argCount, &argSteps, error, redirect, file);
        wordChunks = 1;
        wordLength = 0;
        cmdWord = (char*)calloc(10 + 1, sizeof(char));
        if (!cmdWord) {
          memoryError();
        }
        continue;
      }
      if (c == '\\') {
        c = getchar();
        switch(c) {
          case '\\':
          case ' ':
          case '&':
              break;
          case 't':
              c = '\t';
              break;
          case 'n':
              c = '\n';
              continue;
          default:
              *error |= 2;
        }
        cmdWord[wordLength] = c;
        wordLength++;
        c = getchar();
        continue;
      }
      if (c == '&' && ~(*error&4)) {
        if (*error&4)
          *error|=1;
        background_handler(error,&c);
        if (*error&4)
          break;
      }
      if (wordLength == 10 * wordChunks) {
        wordChunks++;
        char* newWord = (char*)calloc(10 * wordChunks + 1, sizeof(char));
        if (!newWord) {
          memoryError();
        }
        memcpy(newWord, cmdWord, sizeof(char) * 10 * (wordChunks - 1));
        free(cmdWord);
        cmdWord = newWord;
      }
      cmdWord[wordLength] = c;
      wordLength++;
      c = getchar();
    }
    if (wordLength) {
      cmdWord[wordLength] = 0;
      redirect = addWord(cmdWord, &arguments, &argCount, &argSteps, error, redirect, file);
    }
    if (c == (-1)) {
      (*error) |= 8;
    }
    return arguments;
  }

canonical_original_code:
char **readArgs(char *error, char **file) {
    char **arguments = (char**)calloc(5, sizeof(char*));
    if (!arguments) {
      memoryError();
    }
    int argCount = 0;
    int argSteps = 1;
    char c = getchar();
    while (c == ' ' || c == '\t') {
      c = getchar();
    }
    char *cmdWord = (char*)calloc(10 + 1, sizeof(char));
    if (!cmdWord) {
      memoryError();
    }
    int wordChunks = 1;
    int wordLength = 0;
    int redirect = -1;
    while (c != '\n' && c != (-1)) {
      if (c == '\t' || c == ' ') {
        while (c == '\t' || c == ' ') {
          c = getchar();
        }
        cmdWord[wordLength] = 0;
        redirect = addWord(cmdWord, &arguments, &argCount, &argSteps, error, redirect, file);
        wordChunks = 1;
        wordLength = 0;
        cmdWord = (char *)calloc(10 + 1, sizeof(char));
        if (!cmdWord) {
          memoryError();
        }
        continue;
      }
      if (c == '\\') {
        c = getchar();
        switch(c) {
          case '\\':
          case ' ':
          case '&':
              break;
          case 't':
              c = '\t';
              break;
          case 'n':
              c = '\n';
              continue;
          default:
              *error |= 2;
        }
        cmdWord[wordLength] = c;
        wordLength++;
        c = getchar();
        continue;
      }
      if (c == '&' && ~(*error&4)) {
        if (*error&4)
          *error|=1;
        background_handler(error,&c);
        if (*error&4)
          break;
      }
      if (wordLength == 10 * wordChunks) {
        wordChunks++;
        char *newWord = (char*)calloc(10 * wordChunks + 1, sizeof(char));
        if (!newWord) {
          memoryError();
        }
        memcpy(newWord, cmdWord, sizeof(char) * 10 * (wordChunks - 1));
        free(cmdWord);
        cmdWord = newWord;
      }
      cmdWord[wordLength] = c;
      wordLength++;
      c = getchar();
    }
    if (wordLength) {
      cmdWord[wordLength] = 0;
      redirect = addWord(cmdWord, &arguments, &argCount, &argSteps, error, redirect, file);
    }
    if (c == (-1)) {
      (*error) |= 8;
    }
    return arguments;
  }

variable_types:
arguments
char **

variable_types: argCount int

variable_types: argSteps int

variable_types: c char

variable_types:
cmdWord
char *

variable_types: wordChunks int

variable_types: wordLength int

variable_types:
newWord
char *

return_type: char **


getargs

decompiled_code:
void getargs()
{
_QWORD *v0; // rax
_QWORD *v1; // rbp
_QWORD *v2; // rbx
_QWORD *v3; // r12
void *v4; // rax
char **v5; // r12
char v6; // al
char v7; // bl
int v8; // er13
int v9; // er14
int v10; // er15
int v11; // eax
int v12; // eax
int v13; // er15
int v14; // er14
int v15; // eax
int fd; // [rsp+Ch] [rbp-4Ch]
char v17[57]; // [rsp+1Fh] [rbp-39h] BYREF

v0 = calloc(3uLL, 8uLL);
if ( !v0 )
LABEL_48:
memoryError();
v1 = v0;
v2 = v0;
v3 = v0 + 3;
do
{
v4 = calloc(0x65uLL, 1uLL);
*v2 = v4;
if ( !v4 )
goto LABEL_48;
++v2;
}
while ( v3 != v2 );
v17[0] = 0;
v5 = (char **)readArgs(v17, (_BYTE **)v1);
v6 = v17[0];
v7 = v17[0] & 8;
if ( (v17[0] & 3) == 1 )
goto LABEL_27;
if ( (v17[0] & 3) == 2 )
{
puts("Error: Unrecognized escape sequence.");
if ( v7 )
goto LABEL_45;
return;
}
if ( *v5 && !v5[1] && !memcmp(*v5, "exit", 4uLL) )
goto LABEL_45;
v8 = 0;
if ( (v17[0] & 0x10) != 0 )
{
v14 = open((const char *)v1[1], 578, 384LL);
if ( v14 == -1 )
goto LABEL_27;
v8 = dup(1);
close(1);
dup(v14);
close(v14);
v6 = v17[0];
}
v9 = 0;
if ( (v6 & 0x40) == 0 )
goto LABEL_11;
v13 = open((const char *)v1[2], 578, 384LL);
if ( v13 == -1 )
{
LABEL_27:
puts("Error: Invalid syntax.");
if ( v7 )
goto LABEL_45;
return;
}
v9 = dup(2);
close(2);
dup(v13);
close(v13);
v6 = v17[0];
LABEL_11:
if ( (v6 & 0x20) != 0 )
{
v12 = open((const char *)*v1, 0);
if ( v12 == -1 )
{
puts("Error: Unable to open redirection file.");
if ( v7 )
goto LABEL_45;
return;
}
fd = v12;
v10 = dup(0);
close(0);
dup(fd);
close(fd);
}
else
{
v10 = 0;
}
v11 = fork();
if ( v11 < 0 )
{
printf("Error: process creation failed");
goto LABEL_45;
}
if ( !v11 )
{
if ( execvp(*v5, v5) && **v5 )
{
printf("Error: ");
v15 = *__errno_location();
if ( v15 == 2 )
{
puts("Command not found.");
}
else if ( v15 == 13 || v15 == 1 )
{
puts("Permission denied.");
}
else
{
puts("Unkown error.");
}
}
exit(0);
}
if ( (v17[0] & 4) == 0 )
waitpid(v11, 0LL, 0);
if ( v7 )
LABEL_45:
do_exit();
if ( v10 )
{
close(0);
dup(v10);
close(v10);
}
if ( v8 )
{
close(1);
dup(v8);
close(v8);
}
if ( v9 )
{
close(2);
dup(v9);
close(v9);
}
free((void *)*v1);
free((void *)v1[1]);
free((void *)v1[2]);
free(v1);
deleteArgs((void **)v5);
free(v5);
}

canonical_decompiled_code:
void func15()
{
_QWORD *v0; // rax
_QWORD *v1; // rbp
_QWORD *v2; // rbx
_QWORD *v3; // r12
void *v4; // rax
char **v5; // r12
char v6; // al
char v7; // bl
int v8; // er13
int v9; // er14
int v10; // er15
int v11; // eax
int v12; // eax
int v13; // er15
int v14; // er14
int v15; // eax
int fd; // [rsp+Ch] [rbp-4Ch]
char v17[57]; // [rsp+1Fh] [rbp-39h] BYREF

v0 = calloc(3uLL, 8uLL);
if ( !v0 )
LABEL_48:
func12();
v1 = v0;
v2 = v0;
v3 = v0 + 3;
do
{
v4 = calloc(0x65uLL, 1uLL);
*v2 = v4;
if ( !v4 )
goto LABEL_48;
++v2;
}
while ( v3 != v2 );
v17[0] = 0;
v5 = (char **)func14(v17, (_BYTE **)v1);
v6 = v17[0];
v7 = v17[0] & 8;
if ( (v17[0] & 3) == 1 )
goto LABEL_27;
if ( (v17[0] & 3) == 2 )
{
puts("Error: Unrecognized escape sequence.");
if ( v7 )
goto LABEL_45;
return;
}
if ( *v5 && !v5[1] && !memcmp(*v5, "exit", 4uLL) )
goto LABEL_45;
v8 = 0;
if ( (v17[0] & 0x10) != 0 )
{
v14 = open((const char *)v1[1], 578, 384LL);
if ( v14 == -1 )
goto LABEL_27;
v8 = dup(1);
close(1);
dup(v14);
close(v14);
v6 = v17[0];
}
v9 = 0;
if ( (v6 & 0x40) == 0 )
goto LABEL_11;
v13 = open((const char *)v1[2], 578, 384LL);
if ( v13 == -1 )
{
LABEL_27:
puts("Error: Invalid syntax.");
if ( v7 )
goto LABEL_45;
return;
}
v9 = dup(2);
close(2);
dup(v13);
close(v13);
v6 = v17[0];
LABEL_11:
if ( (v6 & 0x20) != 0 )
{
v12 = open((const char *)*v1, 0);
if ( v12 == -1 )
{
puts("Error: Unable to open redirection file.");
if ( v7 )
goto LABEL_45;
return;
}
fd = v12;
v10 = dup(0);
close(0);
dup(fd);
close(fd);
}
else
{
v10 = 0;
}
v11 = fork();
if ( v11 < 0 )
{
printf("Error: process creation failed");
goto LABEL_45;
}
if ( !v11 )
{
if ( execvp(*v5, v5) && **v5 )
{
printf("Error: ");
v15 = *__errno_location();
if ( v15 == 2 )
{
puts("Command not found.");
}
else if ( v15 == 13 || v15 == 1 )
{
puts("Permission denied.");
}
else
{
puts("Unkown error.");
}
}
exit(0);
}
if ( (v17[0] & 4) == 0 )
waitpid(v11, 0LL, 0);
if ( v7 )
LABEL_45:
func9();
if ( v10 )
{
close(0);
dup(v10);
close(v10);
}
if ( v8 )
{
close(1);
dup(v8);
close(v8);
}
if ( v9 )
{
close(2);
dup(v9);
close(v9);
}
free((void *)*v1);
free((void *)v1[1]);
free((void *)v1[2]);
free(v1);
func11((void **)v5);
free(v5);
}

original_code:
void getargs() {
char **file = calloc(3, sizeof(char*));
   if (!file) {
   memoryError();
   }
for (int i = 0; i < 3; i++)
{
file[i] = calloc(100 + 1, sizeof(char));
if (!file[i]) {
memoryError();
}
}
char parseStatus = 0;
char** args = readArgs(&parseStatus, file);
bool quit = 8 & parseStatus;
switch(parseStatus & (1 | 2)){
case 1:
printf("Error: Invalid syntax.\n");
if (quit)
do_exit();
return;
case 2:
printf("Error: Unrecognized escape sequence.\n");
if (quit)
do_exit();
return;
}
if (args[0]) {
if (args[1] == ((void *)0) && strncmp(args[0], "exit", strlen("exit")) == 0) {
do_exit();
}
}
int restore_stdout = 0;
int restore_stdin = 0;
int restore_stderr = 0;
  int f = -1;
if (parseStatus & 16)
{
f = open(file[1],02|0100|01000,0400|0200);
if (f == -1)
{
printf("Error: Invalid syntax.\n");
if (quit) {
do_exit();
}
return;
}
         restore_stdout = dup(1);
         close(1);
dup(f);
close(f);
}
if (parseStatus & 64)
{
f = open(file[2],02|0100|01000,0400|0200);
if (f == -1)
{
printf("Error: Invalid syntax.\n");
if (quit) {
do_exit();
}
return;
}
         restore_stderr = dup(2);
         close(2);
dup(f);
close(f);
}
if (parseStatus & 32)
{
f = open(file[0],00);
if (f == -1)
{
printf("Error: Unable to open redirection file.\n");
if (quit) {
do_exit();
}
return;
}
         restore_stdin = dup(0);
         close(0);
dup(f);
close(f);
}
  pid_t parent = fork();
  if (parent < 0) {
    printf("Error: process creation failed");
    do_exit();
  }
  else if (!parent) {
    if (execvp(args[0], args)) {
     if((*args)[0]) {
          printf("Error: ");
          switch((*__errno_location ())) {
            case 1: printf("Permission denied.\n"); break;
            case 2: printf("Command not found.\n"); break;
case 13: printf("Permission denied.\n"); break;
            default: printf("Unkown error.\n"); break;
     }
      }
    }
    exit(0);
  } else {
if (!(parseStatus & 4)) {
     waitpid(parent, ((void *)0), 0);
}
     if (quit) {
       do_exit();
    }
  }
  if(restore_stdin)
  {
   close(0);
   dup(restore_stdin);
   close(restore_stdin);
  }
  if(restore_stdout)
  {
   close(1);
   dup(restore_stdout);
   close(restore_stdout);
  }
  if(restore_stderr)
  {
   close(2);
   dup(restore_stderr);
   close(restore_stderr);
  }
  for (int i = 0; i < 3; i++) {
    free(file[i]);
  }
  free(file);
  deleteArgs(args);
  free(args);
}

canonical_original_code:
void getargs() {
char **file = calloc(3, sizeof(char*));
   if (!file) {
   memoryError();
   }
for (int i = 0; i < 3; i++)
{
file[i] = calloc(100 + 1, sizeof(char));
if (!file[i]) {
memoryError();
}
}
char parseStatus = 0;
char **args = readArgs(&parseStatus, file);
char quit = 8 & parseStatus;
switch(parseStatus & (1 | 2)){
case 1:
printf("Error: Invalid syntax.\n");
if (quit)
do_exit();
return;
case 2:
printf("Error: Unrecognized escape sequence.\n");
if (quit)
do_exit();
return;
}
if (args[0]) {
if (args[1] == ((void *)0) && strncmp(args[0], "exit", strlen("exit")) == 0) {
do_exit();
}
}
int restore_stdout = 0;
int restore_stdin = 0;
int restore_stderr = 0;
  int f = -1;
if (parseStatus & 16)
{
f = open(file[1],02|0100|01000,0400|0200);
if (f == -1)
{
printf("Error: Invalid syntax.\n");
if (quit) {
do_exit();
}
return;
}
         restore_stdout = dup(1);
         close(1);
dup(f);
close(f);
}
if (parseStatus & 64)
{
f = open(file[2],02|0100|01000,0400|0200);
if (f == -1)
{
printf("Error: Invalid syntax.\n");
if (quit) {
do_exit();
}
return;
}
         restore_stderr = dup(2);
         close(2);
dup(f);
close(f);
}
if (parseStatus & 32)
{
f = open(file[0],00);
if (f == -1)
{
printf("Error: Unable to open redirection file.\n");
if (quit) {
do_exit();
}
return;
}
         restore_stdin = dup(0);
         close(0);
dup(f);
close(f);
}
  int parent = fork();
  if (parent < 0) {
    printf("Error: process creation failed");
    do_exit();
  }
  else if (!parent) {
    if (execvp(args[0], args)) {
     if((*args)[0]) {
          printf("Error: ");
          switch((*__errno_location ())) {
            case 1: printf("Permission denied.\n"); break;
            case 2: printf("Command not found.\n"); break;
case 13: printf("Permission denied.\n"); break;
            default: printf("Unkown error.\n"); break;
     }
      }
    }
    exit(0);
  } else {
if (!(parseStatus & 4)) {
     waitpid(parent, ((void *)0), 0);
}
     if (quit) {
       do_exit();
    }
  }
  if(restore_stdin)
  {
   close(0);
   dup(restore_stdin);
   close(restore_stdin);
  }
  if(restore_stdout)
  {
   close(1);
   dup(restore_stdout);
   close(restore_stdout);
  }
  if(restore_stderr)
  {
   close(2);
   dup(restore_stderr);
   close(restore_stderr);
  }
  for (int i = 0; i < 3; i++) {
    free(file[i]);
  }
  free(file);
  deleteArgs(args);
  free(args);
}

variable_types: i int

variable_types: parseStatus char

variable_types:
args
char **

variable_types: quit char

variable_types: f int

variable_types: parent int


main

repo: moyeah/mbt

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
g_type_init(argc, argv, envp);
test_mbt_mb();
test_mbt_mb_data_item();
test_mbt_mb_mbt_mb_data_item();
test_mbt_mb_device();
test_mbt_mb_mbt_mb_device();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
g_type_init(argc, argv, envp);
func2();
func4();
func5();
func7();
func8();
return 0;
}

original_code:
int
main (int argc,
      char *argv[])
{
  g_type_init ();
  test_mbt_mb ();
  test_mbt_mb_data_item ();
  test_mbt_mb_mbt_mb_data_item ();
  test_mbt_mb_device ();
  test_mbt_mb_mbt_mb_device ();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  g_type_init ();
  test_mbt_mb ();
  test_mbt_mb_data_item ();
  test_mbt_mb_mbt_mb_data_item ();
  test_mbt_mb_device ();
  test_mbt_mb_mbt_mb_device ();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]