main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
char *v4; // r15
_BOOL4 v5; // er12
unsigned int v6; // ebp
__int64 v7; // rbx
int v8; // er13
size_t v9; // rbp
void **v10; // rax
void **v11; // rbx
void **v12; // r13
_DWORD *v13; // rdi
_QWORD *v14; // rdx
_DWORD *v15; // r8
__int64 v16; // rsi
_QWORD *v17; // rdx
int v18; // esi
int v19; // er13
int v20; // ebx
__int64 v21; // rax
int v22; // er12
char v23; // r14
__int64 v24; // rax
int v25; // eax
char *v26; // rbx
char *v27; // rbx
int v28; // er12
__int64 i; // rax
_DWORD *v30; // rdx
__int64 v31; // rcx
__int64 v32; // rax
int v33; // ebx
int v34; // eax
_QWORD *v35; // rdx
__int64 v36; // rax
_QWORD *v37; // rdx
__int64 v38; // rax
char *v39; // rbx
int v40; // ebp
__int64 v41; // rax
__int64 v42; // rdx
__int64 v43; // rax
int v44; // ebx
int v45; // eax
_QWORD *v46; // rdx
__int64 v47; // rax
char *v48; // rbx
int v49; // ebp
char *v50; // rbx
int v51; // ebp
__int64 v52; // rbx
__int64 v53; // rbx
__int64 v54; // rbx
bool v56; // zf
int v57; // [rsp+Ch] [rbp-46Ch]
void *v58; // [rsp+10h] [rbp-468h]
int v59; // [rsp+18h] [rbp-460h]
int v60; // [rsp+1Ch] [rbp-45Ch]
__int64 v61; // [rsp+28h] [rbp-450h]
char s[256]; // [rsp+30h] [rbp-448h] BYREF
char haystack[256]; // [rsp+130h] [rbp-348h] BYREF
char nptr[256]; // [rsp+230h] [rbp-248h] BYREF
char dest[256]; // [rsp+330h] [rbp-148h] BYREF
int v66; // [rsp+430h] [rbp-48h] BYREF
unsigned int v67; // [rsp+434h] [rbp-44h] BYREF
unsigned int v68; // [rsp+438h] [rbp-40h] BYREF
int v69[15]; // [rsp+43Ch] [rbp-3Ch] BYREF

v69[0] = 0;
v68 = 0;
v67 = 0;
v66 = 0;
v57 = 0;
v60 = 0;
v5 = 0;
do
{
LABEL_119:
_isoc99_scanf("%s", haystack, envp);
if ( !strcmp(haystack, "@") )
exit(0);
if ( !strcmp(haystack, "*Vertices") )
{
_isoc99_scanf("%d", v69);
v57 = -2;
if ( !v5 )
{
v6 = v69[0];
v7 = v69[0];
v4 = (char *)malloc(264LL * v69[0]);
v58 = malloc(8 * v7);
init_nome(v4, v6);
v8 = v69[0];
v9 = 8LL * v69[0];
v10 = (void **)malloc(v9);
v3 = (__int64)v10;
if ( v8 <= 0 )
{
v57 = 1;
}
else
{
v11 = v10;
v12 = &v10[v8];
do
*v11++ = malloc(v9);
while ( v11 != v12 );
v57 = 1;
}
}
}
LABEL_121:
while ( !strcmp(haystack, "*Edges") )
{
if ( v5 )
{
if ( v60 == 1 )
{
if ( !strcmp(haystack, "*Arcs") )
goto LABEL_130;
v57 = -2;
goto LABEL_126;
}
v57 = 2;
break;
}
if ( !strcmp(haystack, "*Arcs") )
{
LABEL_136:
v56 = strcmp(haystack, "*Queries") == 0;
v5 = !v56;
if ( v56 )
{
LABEL_12:
if ( v60 )
goto LABEL_96;
v57 = -3;
LABEL_118:
sleep(2u);
printf("\x1B[H\x1B[2J");
}
else
{
sleep(2u);
printf("\x1B[H\x1B[2J");
v57 = -1;
v5 = 0;
}
goto LABEL_119;
}
v57 = -1;
LABEL_126:
if ( !strcmp(haystack, "*Queries") )
goto LABEL_12;
switch ( v57 )
{
case -4:
case -3:
case -2:
case -1:
goto LABEL_132;
case 1:
if ( v69[0] <= 0 )
{
puts("Erro.Numero minimo de 1 vertice nao atingido.");
v5 = 0;
}
else
{
v19 = -1;
v61 = v3;
while ( 1 )
{
v27 = s;
v28 = -1;
do
{
++v28;
_isoc99_scanf("%c", v27++);
}
while ( *(v27 - 1) != 10 );
s[v28] = 0;
v23 = s[0];
if ( s[0] == 42 )
{
++v19;
}
else
{
v20 = strlen(s);
if ( v23 == 32 )
{
v22 = 0;
}
else
{
v21 = 1LL;
do
{
haystack[v21 + 255] = v23;
v22 = v21++;
v23 = *((_BYTE *)&v61 + v21 + 7);
}
while ( v23 != 32 );
}
nptr[v22] = 0;
v59 = atoi(nptr);
LODWORD(v24) = v22 + 2;
if ( v20 <= v22 + 2 )
{
v25 = 0;
}
else
{
v24 = (int)v24;
do
{
nptr[v24 - v22 - 2] = s[v24];
++v24;
}
while ( v20 > (int)v24 );
v25 = v20 - 2 - v22;
}
nptr[v25 - 1] = 0;
strcpy(dest, nptr);
if ( v69[0] <= v59 )
{
puts("Indice superior ao maior indice na matriz de adjacencia.");
}
else
{
v26 = &v4[264 * v59];
strcpy(v26, dest);
*((_DWORD *)v26 + 64) = 1;
*((_DWORD *)v26 + 65) = 0;
++v19;
}
}
if ( v69[0] <= v19 )
break;
if ( !strcmp(s, "*Edges") )
{
v3 = v61;
goto LABEL_44;
}
if ( !strcmp(s, "*Arcs") )
{
v3 = v61;
LABEL_42:
strcpy(haystack, "*Arcs");
v5 = v57;
goto LABEL_121;
}
}
v3 = v61;
if ( !strcmp(s, "*Edges") )
{
LABEL_44:
strcpy(haystack, "*Edges");
v5 = v57;
goto LABEL_121;
}
if ( !strcmp(s, "*Arcs") )
goto LABEL_42;
v5 = v57;
}
goto LABEL_118;
case 2:
if ( v69[0] > 0 )
{
v17 = (_QWORD *)v3;
v18 = 0;
do
{
for ( i = 0LL; v69[0] > (int)i; ++i )
{
*(_DWORD *)(*v17 + 8 * i + 4) = 0;
*(_DWORD *)(*v17 + 8 * i) = 0;
}
++v18;
++v17;
}
while ( v69[0] > v18 );
if ( v69[0] > 0 )
{
v30 = v4 + 256;
v31 = 8LL * (unsigned int)(v69[0] - 1) + 8;
v32 = 0LL;
do
{
if ( *v30 == 1 )
*(_DWORD *)(*(_QWORD *)(v3 + v32) + v32 + 4) = 1;
v30 += 66;
v32 += 8LL;
}
while ( v32 != v31 );
}
}
while ( 2 )
{
v39 = s;
v40 = -1;
do
{
++v40;
_isoc99_scanf("%c", v39++);
}
while ( *(v39 - 1) != 10 );
s[v40] = 0;
if ( s[0] == 42 )
{
if ( !strcmp(s, "*Queries") )
goto LABEL_64;
puts("Instrucao nao suportada dentro da instrucao *Edges.");
}
else
{
separa_string(s, &v68, &v67, &v66);
v33 = validar(v68, (unsigned int)v69[0], *(unsigned int *)&v4[264 * v68 + 256]);
v34 = validar(v67, (unsigned int)v69[0], *(unsigned int *)&v4[264 * v67 + 256]);
if ( v33 == 1 && v34 == 1 )
{
v35 = (_QWORD *)(v3 + 8LL * (int)v68);
v36 = (int)v67;
*(_DWORD *)(*v35 + 8LL * (int)v67 + 4) = 1;
*(_DWORD *)(*v35 + 8 * v36) = v66;
v37 = (_QWORD *)(v3 + 8LL * (int)v67);
v38 = (int)v68;
*(_DWORD *)(*v37 + 8LL * (int)v68 + 4) = 1;
*(_DWORD *)(*v37 + 8 * v38) = v66;
}
}
if ( !strcmp(s, "*Queries") )
goto LABEL_64;
continue;
}
case 3:
if ( v69[0] > 0 )
{
v13 = v4 + 256;
v14 = (_QWORD *)v3;
v15 = v4 + 256;
v16 = 0LL;
do
{
if ( *v15 == 1 )
*(_DWORD *)(*v14 + 8 * v16 + 4) = 1;
if ( v69[0] > 0 )
{
v41 = 0LL;
do
{
*(_DWORD *)(*v14 + 8 * v41 + 4) = 0;
*(_DWORD *)(*v14 + 8 * v41++) = 0;
}
while ( v69[0] > (int)v41 );
}
++v16;
v15 += 66;
++v14;
}
while ( v69[0] > (int)v16 );
if ( v69[0] > 0 )
{
v42 = 8LL * (unsigned int)(v69[0] - 1) + 8;
v43 = 0LL;
do
{
if ( *v13 == 1 )
*(_DWORD *)(*(_QWORD *)(v3 + v43) + v43 + 4) = 1;
v13 += 66;
v43 += 8LL;
}
while ( v43 != v42 );
}
}
while ( 2 )
{
v48 = s;
v49 = -1;
do
{
++v49;
_isoc99_scanf("%c", v48++);
}
while ( *(v48 - 1) != 10 );
s[v49] = 0;
if ( s[0] != 42 )
{
separa_string(s, &v68, &v67, &v66);
v44 = validar(v68, (unsigned int)v69[0], *(unsigned int *)&v4[264 * v68 + 256]);
v45 = validar(v67, (unsigned int)v69[0], *(unsigned int *)&v4[264 * v67 + 256]);
if ( v44 == 1 && v45 == 1 )
{
v46 = (_QWORD *)(v3 + 8LL * (int)v68);
v47 = (int)v67;
*(_DWORD *)(*v46 + 8LL * (int)v67 + 4) = 1;
*(_DWORD *)(*v46 + 8 * v47) = v66;
}
LABEL_81:
if ( !strcmp(s, "*Queries") )
goto LABEL_64;
continue;
}
break;
}
if ( strcmp(s, "*Queries") )
{
puts("Instrucao nao suportada dentro da instrucao *Arcs.");
goto LABEL_81;
}
LABEL_64:
strcpy(haystack, "*Queries");
v60 = 1;
break;
case 4:
goto LABEL_96;
default:
puts("Instrucao nao implementada.");
v57 = 5;
goto LABEL_118;
}
}
if ( strcmp(haystack, "*Arcs") )
goto LABEL_126;
if ( !v5 )
goto LABEL_136;
if ( v60 != 1 )
{
v57 = 3;
goto LABEL_126;
}
LABEL_130:
if ( !strcmp(haystack, "*Queries") )
{
LABEL_96:
while ( 1 )
{
v50 = haystack;
v51 = -1;
do
{
++v51;
_isoc99_scanf("%c", v50++);
}
while ( *(v50 - 1) != 10 );
haystack[v51] = 0;
if ( !strcmp(haystack, "@") )
break;
if ( strstr(haystack, "get") )
{
v52 = (unsigned int)separa_id(haystack);
if ( (unsigned int)get_ID(v52, dest, v4, (unsigned int)v69[0]) == 1 )
printf("\"{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"sucesso\"}}\n", (unsigned int)v52, dest);
else
printf("{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"falha\"}}\n", (unsigned int)v52, dest);
}
if ( strstr(haystack, "delete") )
{
v53 = (unsigned int)separa_id(haystack);
if ( (unsigned int)delete_ID(v53, (unsigned int)v69[0], v3, v4) == 1 )
printf("{\"delete\":{\"ID\":%d,\"resposta\":\"sucesso\"}}\n", (unsigned int)v53);
else
printf("{\"delete\":{\"ID\":%d,\"resposta\":\"falha\"}}\n", (unsigned int)v53);
}
if ( strstr(haystack, "vizinhos") )
{
v54 = (unsigned int)separa_id(haystack);
if ( (unsigned int)vizinhos_ID(v54, (unsigned int)v69[0], v3, s) == 1 )
printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"sucesso\", \"vizinhos\":[%s]}}\n", (unsigned int)v54, s);
else
printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"falha\", \"vizinhos\":[]}}\n", (unsigned int)v54);
}
if ( strstr(haystack, "conexao") )
{
separa_id_id(haystack, &v68, &v67);
if ( (unsigned int)conexao(v68, v67, (unsigned int)v69[0], v3) == 1 )
printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"sucesso\", \"conexao\":\"sim\"}}\n", v68, v67);
else
printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"falha\", \"conexao\":\"\"}}\n", v68, v67);
}
if ( strstr(haystack, "ordemtopologica") )
{
s[0] = 0;
v58 = (void *)adjacencia(v58, v3, (unsigned int)v69[0]);
if ( (unsigned int)ordem_t(v3, v58, v4, s, (unsigned int)v69[0]) == 1 )
printf("{\"ordemtop\":%s}\n", s);
else
puts("{\"ordemtop\":falha}");
}
if ( strstr(haystack, "arvoreminima") )
{
s[0] = 0;
if ( (unsigned int)arvoreminima(v3, v4, s, (unsigned int)v69[0], 0LL) == 1 )
printf("{\"arvoreminima\":{\"arestas\":[%s],\"custo\":%d}}\n", s, 0LL);
else
puts("{\"arvoreminima\":falha}");
}
}
exit(0);
}
v57 = -2;
LABEL_132:
sleep(2u);
printf("\x1B[H\x1B[2J");
}
while ( v57 );
return 0;
}

original_code:
int main()
{
   int vertices=0,vertices_ok=0,arestas_ok=0;
   int code=0,valido_1=0,valido_2=0,resposta=0;
   int id=-1;
   int i=0,j=0,k=0;
   int indice=0,tamanho=0;
   int v1=0,v2=0,peso=0;
   int custo=0;
   char nome[255];
   char aux[255];
   char entrada[255];
   char string[255];
   NOME_VERTICES *nodos;
   MATRIZ **grafo;
   LISTA_ADJACENCIA *lista;
   do{
 scanf("%s",entrada);
 if(strcmp(entrada,"@")==0){
   exit(0);
    }
    if(strcmp(entrada,"*Vertices")==0){
    scanf("%d",&vertices);
    if(vertices_ok!=1){
   nodos=malloc(vertices*sizeof(NOME_VERTICES));
   lista=malloc(vertices*sizeof(LISTA_ADJACENCIA));
         init_nome(nodos,vertices);
         grafo=malloc(vertices*sizeof(MATRIZ));
         for(i=0;i<vertices;i++){
              grafo[i]=malloc(vertices*sizeof(MATRIZ));
   }
  code=1;
    }
    else{
       code=-2;
    }
 }
menu:
    if(strcmp(entrada,"*Edges")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=2;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
     }
    if(strcmp(entrada,"*Arcs")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=3;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
 }
 if(strcmp(entrada,"*Queries")==0){
   if(arestas_ok!=0){
     code=4;
   }
   else{
     code=-3;
   }
 }
    switch(code){
      case -4:
           break;
      case -3:
           break;
      case -2:
           if(arestas_ok!=1){
           }
           else{
     }
           break;
      case -1:
           break;
      case 1:
           if(vertices>0){
     i=-1;
     do{
       i++;
       j=-1;
       do{
         j++;
         scanf("%c",&string[j]);
       }while(string[j]!='\n');
       string[j]='\0';
       tamanho=strlen(string);
       if(string[0]!='*'){
         j=0;
         while(string[j]!=' '){
         aux[j]=string[j];
         j++;
      }
      aux[j]='\0';
      indice=atoi(aux);
      k=0;
      j+=2;
      while(j<tamanho){
         aux[k]=string[j];
         j++;
         k++;
      }
      aux[k-1]='\0';
      strcpy(nome,aux);
                  if(indice<(vertices)){
                    strcpy(nodos[indice].nome,nome);
                    nodos[indice].ini=1;
                    nodos[indice].del=0;
                  }
         else{
        printf("Indice superior ao maior indice na matriz de adjacencia.\n");
     i--;
      }
    }
    }while((i<(vertices))&&((strcmp(string,"*Edges")!=0)&&(strcmp(string,"*Arcs")!=0)));
       vertices_ok=1;
    if(strcmp(string,"*Edges")==0){
    strcpy(entrada,"*Edges");
       goto menu;
       }
    else{
               if(strcmp(string,"*Arcs")==0){
         strcpy(entrada,"*Arcs");
         goto menu;
         }
    }
     }
     else{
       printf("Erro.Numero minimo de 1 vertice nao atingido.\n");
       vertices_ok=0;
     }
           break;
      case 2:
   for(j=0;j<vertices;j++){
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
     do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                   grafo[v2][v1].conexo=1;
                   grafo[v2][v1].peso=peso;
                }
              }
              else{
       if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Edges.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
           strcpy(entrada,"*Queries");
           goto menu;
           break;
     case 3:
   for(j=0;j<vertices;j++){
     if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
   do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                }
              }
              else{
    if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Arcs.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
     strcpy(entrada,"*Queries");
     goto menu;
           break;
     case 4:
           do{
             j=-1;
             do{
      j++;
       scanf("%c",&entrada[j]);
    }while(entrada[j]!='\n');
    entrada[j]='\0';
             if(strcmp(entrada,"@")==0){
         exit(0);
             }
             if(strstr(entrada,"get")){
    resposta=0;
          id=separa_id(entrada);
          resposta=get_ID(id,nome,nodos,vertices);
          if(resposta==1){
       printf("\"{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"sucesso\"}}\n",id,nome);
    }
    else{
       printf("{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"falha\"}}\n",id,nome);
    }
       }
       if(strstr(entrada,"delete")){
    resposta=0;
          id=separa_id(entrada);
          resposta=delete_ID(id,vertices,grafo,nodos);
       if(resposta==1){
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"sucesso\"}}\n",id);
    }
    else{
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"falha\"}}\n",id);
    }
    }
       if(strstr(entrada,"vizinhos")){
                resposta=0;
          id=separa_id(entrada);
          resposta=vizinhos_ID(id,vertices,grafo,string);
          if(resposta==1){
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"sucesso\", \"vizinhos\":[%s]}}\n",id,string);
    }
    else{
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"falha\", \"vizinhos\":[]}}\n",id);
    }
       }
             if(strstr(entrada,"conexao")){
       resposta=0;
          separa_id_id(entrada,&v1,&v2);
          resposta=conexao(v1,v2,vertices,grafo);
       if(resposta==1){
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"sucesso\", \"conexao\":\"sim\"}}\n",v1,v2);
    }
    else{
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"falha\", \"conexao\":\"\"}}\n",v1,v2);
    }
    }
             if(strstr(entrada,"ordemtopologica")){
    resposta=0;
    string[0]='\0';
       lista=adjacencia(lista,grafo,vertices);
       resposta=ordem_t(grafo,lista,nodos,string,vertices);
        if(resposta==1){
       printf("{\"ordemtop\":%s}\n",string);
     }
     else{
       printf("{\"ordemtop\":falha}\n");
     }
    }
             if(strstr(entrada,"arvoreminima")){
       resposta=0;
    custo=0;
    string[0]='\0';
       resposta=arvoreminima(grafo,nodos,string,vertices,custo);
        if(resposta==1){
       printf("{\"arvoreminima\":{\"arestas\":[%s],\"custo\":%d}}\n",string,custo);
     }
     else{
       printf("{\"arvoreminima\":falha}\n");
     }
    }
           }while(1);
           break;
     default:
           printf("Instrucao nao implementada.\n");
           code=5;
           break;
    }
   sleep(2);
   printf("\33[H\33[2J");
   }while(code!=0);
 return 0;
}

canonical_original_code:
int main()
{
   int vertices = 0; int vertices_ok = 0; int arestas_ok = 0;
   int code = 0; int valido_1 = 0; int valido_2 = 0; int resposta = 0;
   int id = -1;
   int i = 0; int j = 0; int k = 0;
   int indice = 0; int tamanho = 0;
   int v1 = 0; int v2 = 0; int peso = 0;
   int custo = 0;
   char nome[255];
   char aux[255];
   char entrada[255];
   char string[255];
   struct nome_vertices *nodos;
   struct matriz **grafo;
   struct lista_adjacencia *lista;
   do{
 scanf("%s",entrada);
 if(strcmp(entrada,"@")==0){
   exit(0);
    }
    if(strcmp(entrada,"*Vertices")==0){
    scanf("%d",&vertices);
    if(vertices_ok!=1){
   nodos=malloc(vertices*sizeof(NOME_VERTICES));
   lista=malloc(vertices*sizeof(LISTA_ADJACENCIA));
         init_nome(nodos,vertices);
         grafo=malloc(vertices*sizeof(MATRIZ));
         for(i=0;i<vertices;i++){
              grafo[i]=malloc(vertices*sizeof(MATRIZ));
   }
  code=1;
    }
    else{
       code=-2;
    }
 }
menu:
    if(strcmp(entrada,"*Edges")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=2;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
     }
    if(strcmp(entrada,"*Arcs")==0){
    if(vertices_ok!=0){
      if(arestas_ok!=1){
        code=3;
      }
      else{
     code=-2;
   }
    }
    else{
      code=-1;
    }
 }
 if(strcmp(entrada,"*Queries")==0){
   if(arestas_ok!=0){
     code=4;
   }
   else{
     code=-3;
   }
 }
    switch(code){
      case -4:
           break;
      case -3:
           break;
      case -2:
           if(arestas_ok!=1){
           }
           else{
     }
           break;
      case -1:
           break;
      case 1:
           if(vertices>0){
     i=-1;
     do{
       i++;
       j=-1;
       do{
         j++;
         scanf("%c",&string[j]);
       }while(string[j]!='\n');
       string[j]='\0';
       tamanho=strlen(string);
       if(string[0]!='*'){
         j=0;
         while(string[j]!=' '){
         aux[j]=string[j];
         j++;
      }
      aux[j]='\0';
      indice=atoi(aux);
      k=0;
      j+=2;
      while(j<tamanho){
         aux[k]=string[j];
         j++;
         k++;
      }
      aux[k-1]='\0';
      strcpy(nome,aux);
                  if(indice<(vertices)){
                    strcpy(nodos[indice].nome,nome);
                    nodos[indice].ini=1;
                    nodos[indice].del=0;
                  }
         else{
        printf("Indice superior ao maior indice na matriz de adjacencia.\n");
     i--;
      }
    }
    }while((i<(vertices))&&((strcmp(string,"*Edges")!=0)&&(strcmp(string,"*Arcs")!=0)));
       vertices_ok=1;
    if(strcmp(string,"*Edges")==0){
    strcpy(entrada,"*Edges");
       goto menu;
       }
    else{
               if(strcmp(string,"*Arcs")==0){
         strcpy(entrada,"*Arcs");
         goto menu;
         }
    }
     }
     else{
       printf("Erro.Numero minimo de 1 vertice nao atingido.\n");
       vertices_ok=0;
     }
           break;
      case 2:
   for(j=0;j<vertices;j++){
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
     do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                   grafo[v2][v1].conexo=1;
                   grafo[v2][v1].peso=peso;
                }
              }
              else{
       if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Edges.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
           strcpy(entrada,"*Queries");
           goto menu;
           break;
     case 3:
   for(j=0;j<vertices;j++){
     if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
     for(i=0;i<vertices;i++){
                 grafo[j][i].conexo=0;
                 grafo[j][i].peso=pow(2,-15);
               }
            }
            for(j=0;j<vertices;j++){
              if(nodos[j].ini==1){
       grafo[j][j].conexo=1;
     }
   }
   do{
    j=-1;
    do{
      j++;
      scanf("%c",&string[j]);
    }while(string[j]!='\n');
    string[j]='\0';
    tamanho=strlen(string);
    if(string[0]!='*'){
                valido_1=0;
                valido_2=0;
                separa_string(string,&v1,&v2,&peso);
                valido_1=validar(v1,vertices,nodos[v1].ini);
                valido_2=validar(v2,vertices,nodos[v2].ini);
    if((valido_1==1)&&(valido_2==1)){
       grafo[v1][v2].conexo=1;
                   grafo[v1][v2].peso=peso;
                }
              }
              else{
    if(strcmp(string,"*Queries")!=0){
       printf("Instrucao nao suportada dentro da instrucao *Arcs.\n");
    }
     }
           }while(strcmp(string,"*Queries")!=0);
     arestas_ok=1;
     strcpy(entrada,"*Queries");
     goto menu;
           break;
     case 4:
           do{
             j=-1;
             do{
      j++;
       scanf("%c",&entrada[j]);
    }while(entrada[j]!='\n');
    entrada[j]='\0';
             if(strcmp(entrada,"@")==0){
         exit(0);
             }
             if(strstr(entrada,"get")){
    resposta=0;
          id=separa_id(entrada);
          resposta=get_ID(id,nome,nodos,vertices);
          if(resposta==1){
       printf("\"{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"sucesso\"}}\n",id,nome);
    }
    else{
       printf("{\"vertice\":{\"ID\":%d, \"dado\":\"%s\", \"resposta\":\"falha\"}}\n",id,nome);
    }
       }
       if(strstr(entrada,"delete")){
    resposta=0;
          id=separa_id(entrada);
          resposta=delete_ID(id,vertices,grafo,nodos);
       if(resposta==1){
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"sucesso\"}}\n",id);
    }
    else{
       printf("{\"delete\":{\"ID\":%d,\"resposta\":\"falha\"}}\n",id);
    }
    }
       if(strstr(entrada,"vizinhos")){
                resposta=0;
          id=separa_id(entrada);
          resposta=vizinhos_ID(id,vertices,grafo,string);
          if(resposta==1){
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"sucesso\", \"vizinhos\":[%s]}}\n",id,string);
    }
    else{
       printf("{\"vizinhos\":{\"ID\":%d, \"resposta\":\"falha\", \"vizinhos\":[]}}\n",id);
    }
       }
             if(strstr(entrada,"conexao")){
       resposta=0;
          separa_id_id(entrada,&v1,&v2);
          resposta=conexao(v1,v2,vertices,grafo);
       if(resposta==1){
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"sucesso\", \"conexao\":\"sim\"}}\n",v1,v2);
    }
    else{
       printf("{\"conexao\":{\"ID1\":%d, \"ID2\":%d, \"resposta\":\"falha\", \"conexao\":\"\"}}\n",v1,v2);
    }
    }
             if(strstr(entrada,"ordemtopologica")){
    resposta=0;
    string[0]='\0';
       lista=adjacencia(lista,grafo,vertices);
       resposta=ordem_t(grafo,lista,nodos,string,vertices);
        if(resposta==1){
       printf("{\"ordemtop\":%s}\n",string);
     }
     else{
       printf("{\"ordemtop\":falha}\n");
     }
    }
             if(strstr(entrada,"arvoreminima")){
       resposta=0;
    custo=0;
    string[0]='\0';
       resposta=arvoreminima(grafo,nodos,string,vertices,custo);
        if(resposta==1){
       printf("{\"arvoreminima\":{\"arestas\":[%s],\"custo\":%d}}\n",string,custo);
     }
     else{
       printf("{\"arvoreminima\":falha}\n");
     }
    }
           }while(1);
           break;
     default:
           printf("Instrucao nao implementada.\n");
           code=5;
           break;
    }
   sleep(2);
   printf("\33[H\33[2J");
   }while(code!=0);
 return 0;
}

variable_types: vertices int

variable_types: code int

variable_types: resposta int

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: indice int

variable_types: peso int

variable_types:
nome
char [255]

variable_types:
aux
char [255]

variable_types:
entrada
char [255]

variable_types:
string
char [255]


itemweight

repo: RoguelikeRestorationProject/urogue

decompiled_code:
__int64 __fastcall itemweight(__int64 a1)
{
__int64 result; // rax
char v2; // dl
__int64 v3; // rdx

result = *(unsigned int *)(a1 + 96);
v2 = *(_BYTE *)(a1 + 64);
if ( v2 == 41 )
{
if ( *(_DWORD *)(a1 + 80) + *(_DWORD *)(a1 + 84) > 0 )
result = (unsigned int)((int)result / 2);
}
else if ( v2 == 93 )
{
result = (unsigned int)((10 - (armors[8 * *(int *)(a1 + 76) + 5] - *(_DWORD *)(a1 + 88))) / 10 * result);
}
v3 = *(_QWORD *)(a1 + 48);
if ( (v3 & 1) != 0 )
{
result = (unsigned int)((int)result / 2 + result);
}
else if ( (v3 & 0x20) != 0 )
{
result = (unsigned int)((int)result / -5 + result);
}
if ( (int)result < 0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
char v2; // dl
__int64 v3; // rdx

result = *(unsigned int *)(a1 + 96);
v2 = *(_BYTE *)(a1 + 64);
if ( v2 == 41 )
{
if ( *(_DWORD *)(a1 + 80) + *(_DWORD *)(a1 + 84) > 0 )
result = (unsigned int)((int)result / 2);
}
else if ( v2 == 93 )
{
result = (unsigned int)((10 - (armors[8 * *(int *)(a1 + 76) + 5] - *(_DWORD *)(a1 + 88))) / 10 * result);
}
v3 = *(_QWORD *)(a1 + 48);
if ( (v3 & 1) != 0 )
{
result = (unsigned int)((int)result / 2 + result);
}
else if ( (v3 & 0x20) != 0 )
{
result = (unsigned int)((int)result / -5 + result);
}
if ( (int)result < 0 )
result = 0LL;
return result;
}

original_code:
int
itemweight(struct object *wh)
{
    int weight = wh->o_weight;
    int ac;
    switch (wh->o_type)
    {
        case ']':
            ac = armors[wh->o_which].a_class - wh->o_ac;
            weight *= (10 - ac) / 10;
            break;
        case ')':
            if ((wh->o_hplus + wh->o_dplus) > 0)
                weight /= 2;
    }
    if (wh->o_flags & 0x00000001UL)
        weight += weight / 2;
    else if (wh->o_flags & 0x00000020UL)
        weight -= weight / 5;
    if (weight < 0)
        weight = 0;
    return (weight);
}

variable_types: struct object { struct coord { int x; int y; } o_pos; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *

variable_types: weight int

variable_types: ac int

return_type: int

user_defined_types: struct object { struct coord o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; }

user_defined_types: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing *th; void *l_data; } data; }

user_defined_types: struct thing { long chasee_index; struct linked_list *t_pack; struct stats t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; }


packweight

decompiled_code:
__int64 packweight()
{
_QWORD *v0; // rbx
int v1; // er12
__int64 v2; // rbp
__int64 result; // rax

v0 = (_QWORD *)player[2];
if ( v0 )
{
v1 = 0;
do
{
v2 = v0[2];
v1 += *(_DWORD *)(v2 + 72) * itemweight(v2);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
else
{
v1 = 0;
}
result = 0LL;
if ( v1 >= 0 )
result = (unsigned int)v1;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rbx
int v1; // er12
__int64 v2; // rbp
__int64 result; // rax

v0 = (_QWORD *)player[2];
if ( v0 )
{
v1 = 0;
do
{
v2 = v0[2];
v1 += *(_DWORD *)(v2 + 72) * func0(v2);
v0 = (_QWORD *)*v0;
}
while ( v0 );
}
else
{
v1 = 0;
}
result = 0LL;
if ( v1 >= 0 )
result = (unsigned int)v1;
return result;
}

original_code:
int
packweight(void)
{
    struct linked_list *pc;
    int weight = 0;
    for (pc = player.t_pack; pc != ((void *)0); pc = ((pc)?(pc->l_next):((void *)0)))
    {
        struct object *obj = ((*pc).data.obj);
        weight += itemweight(obj) * obj->o_count;
    }
    if (weight < 0)
        weight = 0;
    return (weight);
}

canonical_original_code:
int packweight()
{
    struct linked_list *pc;
    int weight = 0;
    for (pc = player.t_pack; pc != ((void *)0); pc = ((pc)?(pc->l_next):((void *)0)))
    {
        struct object *obj = ((*pc).data.obj);
        weight += itemweight(obj) * obj->o_count;
    }
    if (weight < 0)
        weight = 0;
    return (weight);
}

variable_types: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *


playenc

decompiled_code:
__int64 playenc()
{
unsigned int v0; // ebx

v0 = 50 * (LODWORD(player[9]) - 10);
if ( (unsigned int)is_wearing(19LL) )
v0 += 300 * ring_value(19LL);
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx

v0 = 50 * (LODWORD(player[9]) - 10);
if ( (unsigned int)is_wearing(19LL) )
v0 += 300 * ring_value(19LL);
return v0;
}

original_code:
int
playenc(void)
{
    int ret_val = (player.t_stats.s_str - 10) * 50;
    if (is_wearing(19))
        ret_val += ring_value(19) * 300;
    return (ret_val);
}

canonical_original_code:
int playenc()
{
    int ret_val = (player.t_stats.s_str - 10) * 50;
    if (is_wearing(19))
        ret_val += ring_value(19) * 300;
    return (ret_val);
}


totalenc

decompiled_code:
__int64 totalenc()
{
__int64 result; // rax

result = (unsigned int)playenc() + 1400;
if ( hungry_state == 2 )
return (unsigned int)(result - (int)result / 4);
if ( hungry_state == 3 )
result = (unsigned int)((int)result / 2);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

result = (unsigned int)func2() + 1400;
if ( hungry_state == 2 )
return (unsigned int)(result - (int)result / 4);
if ( hungry_state == 3 )
result = (unsigned int)((int)result / 2);
return result;
}

original_code:
int
totalenc(void)
{
    int wtotal = 1400 + playenc();
    switch (hungry_state)
    {
        case 0:
        case 1:
            break;
        case 2:
            wtotal -= wtotal / 4;
            break;
        case 3:
            wtotal /= 2;
            break;
    }
    return (wtotal);
}

canonical_original_code:
int totalenc()
{
    int wtotal = 1400 + playenc();
    switch (hungry_state)
    {
        case 0:
        case 1:
            break;
        case 2:
            wtotal -= wtotal / 4;
            break;
        case 3:
            wtotal /= 2;
            break;
    }
    return (wtotal);
}

variable_types: wtotal int


updpack

decompiled_code:
__int64 __fastcall updpack(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rdx
__int64 result; // rax

v2 = packweight();
HIDWORD(player[6]) = totalenc();
if ( (unsigned int)is_carrying(0LL) )
HIDWORD(player[6]) += 1000;
foodlev = 0;
v3 = (unsigned int)((5 * v2) >> 31);
LODWORD(v3) = 5 * v2 % SHIDWORD(player[6]);
switch ( 5 * v2 / SHIDWORD(player[6]) )
{
case 0:
goto LABEL_13;
case 1:
goto LABEL_11;
case 2:
goto LABEL_9;
case 3:
goto LABEL_7;
case 4:
goto LABEL_5;
case 5:
foodlev = 1;
LABEL_5:
if ( (int)rnd(100LL, a2, v3) <= 79 )
++foodlev;
LABEL_7:
if ( (int)rnd(100LL, a2, v3) <= 59 )
++foodlev;
LABEL_9:
if ( (int)rnd(100LL, a2, v3) <= 39 )
++foodlev;
LABEL_11:
if ( (int)rnd(100LL, a2, v3) <= 19 )
++foodlev;
LABEL_13:
++foodlev;
break;
default:
break;
}
LODWORD(player[6]) = v2;
result = is_carrying(0LL);
if ( (_DWORD)result )
--foodlev;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rdx
__int64 result; // rax

v2 = func1();
HIDWORD(player[6]) = func3();
if ( (unsigned int)is_carrying(0LL) )
HIDWORD(player[6]) += 1000;
foodlev = 0;
v3 = (unsigned int)((5 * v2) >> 31);
LODWORD(v3) = 5 * v2 % SHIDWORD(player[6]);
switch ( 5 * v2 / SHIDWORD(player[6]) )
{
case 0:
goto LABEL_13;
case 1:
goto LABEL_11;
case 2:
goto LABEL_9;
case 3:
goto LABEL_7;
case 4:
goto LABEL_5;
case 5:
foodlev = 1;
LABEL_5:
if ( (int)rnd(100LL, a2, v3) <= 79 )
++foodlev;
LABEL_7:
if ( (int)rnd(100LL, a2, v3) <= 59 )
++foodlev;
LABEL_9:
if ( (int)rnd(100LL, a2, v3) <= 39 )
++foodlev;
LABEL_11:
if ( (int)rnd(100LL, a2, v3) <= 19 )
++foodlev;
LABEL_13:
++foodlev;
break;
default:
break;
}
LODWORD(player[6]) = v2;
result = is_carrying(0LL);
if ( (_DWORD)result )
--foodlev;
return result;
}

original_code:
void
updpack(void)
{
    int curcarry = packweight();
    player.t_stats.s_carry = totalenc();
    if (is_carrying(0))
        player.t_stats.s_carry += 1000;
    foodlev = 0;
    switch ((curcarry * 5) / player.t_stats.s_carry)
    {
        case 5:
            foodlev++;
        case 4:
            if (rnd(100) < 80)
                foodlev++;
        case 3:
            if (rnd(100) < 60)
                foodlev++;
        case 2:
            if (rnd(100) < 40)
                foodlev++;
        case 1:
            if (rnd(100) < 20)
                foodlev++;
        case 0:
            foodlev++;
    }
    player.t_stats.s_pack = curcarry;
    if (is_carrying(0))
        foodlev--;
}

canonical_original_code:
void updpack()
{
    int curcarry = packweight();
    player.t_stats.s_carry = totalenc();
    if (is_carrying(0))
        player.t_stats.s_carry += 1000;
    foodlev = 0;
    switch ((curcarry * 5) / player.t_stats.s_carry)
    {
        case 5:
            foodlev++;
        case 4:
            if (rnd(100) < 80)
                foodlev++;
        case 3:
            if (rnd(100) < 60)
                foodlev++;
        case 2:
            if (rnd(100) < 40)
                foodlev++;
        case 1:
            if (rnd(100) < 20)
                foodlev++;
        case 0:
            foodlev++;
    }
    player.t_stats.s_pack = curcarry;
    if (is_carrying(0))
        foodlev--;
}

variable_types: curcarry int

return_type: void


hitweight

decompiled_code:
__int64 hitweight()
{
return (unsigned int)(3 - foodlev);
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)(3 - foodlev);
}

original_code:
int
hitweight(void)
{
    return(3 - foodlev);
}

canonical_original_code:
int hitweight()
{
    return(3 - foodlev);
}


fatal

decompiled_code:
void __fastcall __noreturn fatal(const char *a1)
{
wclear(stdscr);
wmove(stdscr, LINES - 2, 0);
printw("%s", a1);
wrefresh(stdscr);
endwin();
putchar(10);
exit(100);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
wclear(stdscr);
wmove(stdscr, LINES - 2, 0);
printw("%s", a1);
wrefresh(stdscr);
endwin();
putchar(10);
exit(100);
}

original_code:
void
fatal(char *s)
{
    wclear(stdscr);
    wmove(stdscr,(LINES - 2),(0));
    printw("%s", s);
    wrefresh(stdscr);
    endwin();
    printf("\n");
    exit(100);
}

variable_types:
s
char *


ucrnd

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

result = a1;
if ( (_BYTE)a1 )
result = (ur_random() & 0x7FFFFFFF) % (unsigned __int8)a1;
return result;
}

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

result = a1;
if ( (_BYTE)a1 )
result = (ur_random() & 0x7FFFFFFF) % (unsigned __int8)a1;
return result;
}

original_code:
unsigned char
ucrnd(unsigned char range)
{
    return (unsigned char)(range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types:
range
unsigned char

return_type: unsigned char


srnd

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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
return result;
}

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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
return result;
}

original_code:
short
srnd(short range)
{
    return (short)(range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types: range short

return_type: short


rnd

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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
return result;
}

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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
return result;
}

original_code:
int
rnd(int range)
{
    return (range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types: range int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // rbx
const char **v5; // rdx
int v6; // edi
int v7; // esi
char v8; // cl
char *v9; // rax
char *v10; // r13
char *v11; // rsi
int v12; // er12
int v13; // edi
int v14; // eax
char *v15; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v3 = argc;
v4 = argv;
if ( argc <= 1 )
{
v7 = 1;
}
else
{
v5 = argv + 1;
v6 = 0;
v7 = 1;
do
{
if ( **v5 != 45 )
break;
v8 = (*v5)[1];
switch ( v8 )
{
case 's':
prscore = 1;
break;
case 'v':
prversion = 1;
break;
case 'r':
v6 = 1;
break;
default:
fprintf(stderr, "%s: Unknown option '%c'.\n", *v4, (unsigned int)v8);
exit(1);
}
++v7;
++v5;
}
while ( v3 != v7 );
if ( v6 )
{
LABEL_13:
strcpy(&score_file, "urogue.scr");
fd_score = (__int64)fopen(&score_file, "r+");
if ( !fd_score )
fd_score = (__int64)fopen(&score_file, "a+");
v9 = getenv("OPTIONS");
v10 = v9;
if ( v9 )
parse_opts(v9);
v11 = getenv("USER");
if ( v11 )
{
strcpy(&whoami, v11);
}
else
{
*(_QWORD *)&whoami = 0x756F6D796E6F6E61LL;
*((_WORD *)&whoami + 4) = 115;
}
v12 = time(&timer);
if ( wizard && getenv("SEED") )
{
v15 = getenv("SEED");
v13 = atoi(v15);
}
else
{
v13 = v12;
}
dnum = v13;
ur_srandom();
if ( !v10 || !fruit )
{
v14 = rnd(20);
strcpy(&fruit, funfruit_0[v14]);
}
fd_data[5] = md_strdup(&fruit);
if ( !prscore )
{
if ( !prversion )
{
if ( wizard )
printf("Hello %s, welcome to dungeon #%d", &whoami, dnum);
else
printf("Hello %s, just a moment while I dig the dungeon...", &whoami);
mem_debug(2LL);
mem_tracking(1LL);
fflush(stdout);
init_things();
init_fd();
init_colors();
init_stones();
init_materials();
initscr();
wrefresh(stdscr);
init_names();
cbreak();
cbreak();
noecho();
nonl();
food_left = (int)(float)((float)((float)(COLS * LINES) / 2000.0) * (float)food_left);
cw = newwin(LINES, COLS, 0, 0);
mw = newwin(LINES, COLS, 0, 0);
hw = newwin(LINES, COLS, 0, 0);
if ( v3 == 2 && *v4[1] && !(unsigned int)restore() )
exit(1);
waswizard = wizard;
init_player();
resurrect = *((_DWORD *)&player + 22);
init_exp();
init_flags();
wclear(hw);
wrefresh(hw);
new_level(1LL, 0LL);
start_daemon(1LL, &player, 2LL);
light_fuse(1LL, 0LL, 140LL, 2LL);
start_daemon(3LL, 0LL, 2LL);
start_daemon(4LL, 0LL, 2LL);
char_type = *((_DWORD *)&player + 90);
*((_QWORD *)&player + 25) = *((_QWORD *)&player + 24);
oldrp = roomin();
after = 1;
signal(2, (__sighandler_t)&quit_handler);
while ( playing )
{
do_daemons(1LL);
do_fuses(1LL);
command();
if ( after )
do_after_effects();
}
fatal((const char *)&unk_658);
}
printf("UltraRogue Version %s.\n", release);
exit(0);
}
waswizard = 1;
score(0LL, 0LL, 0xFFFFFFFFLL, 0LL);
exit(0);
}
}
v3 -= v7 - 1;
v4 = &v4[v7 - 1];
goto LABEL_13;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // rbx
const char **v5; // rdx
int v6; // edi
int v7; // esi
char v8; // cl
char *v9; // rax
char *v10; // r13
char *v11; // rsi
int v12; // er12
int v13; // edi
int v14; // eax
char *v15; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v3 = argc;
v4 = argv;
if ( argc <= 1 )
{
v7 = 1;
}
else
{
v5 = argv + 1;
v6 = 0;
v7 = 1;
do
{
if ( **v5 != 45 )
break;
v8 = (*v5)[1];
switch ( v8 )
{
case 's':
prscore = 1;
break;
case 'v':
prversion = 1;
break;
case 'r':
v6 = 1;
break;
default:
fprintf(stderr, "%s: Unknown option '%c'.\n", *v4, (unsigned int)v8);
exit(1);
}
++v7;
++v5;
}
while ( v3 != v7 );
if ( v6 )
{
LABEL_13:
strcpy(&score_file, "urogue.scr");
fd_score = (__int64)fopen(&score_file, "r+");
if ( !fd_score )
fd_score = (__int64)fopen(&score_file, "a+");
v9 = getenv("OPTIONS");
v10 = v9;
if ( v9 )
parse_opts(v9);
v11 = getenv("USER");
if ( v11 )
{
strcpy(&whoami, v11);
}
else
{
*(_QWORD *)&whoami = 0x756F6D796E6F6E61LL;
*((_WORD *)&whoami + 4) = 115;
}
v12 = time(&timer);
if ( wizard && getenv("SEED") )
{
v15 = getenv("SEED");
v13 = atoi(v15);
}
else
{
v13 = v12;
}
dnum = v13;
ur_srandom();
if ( !v10 || !fruit )
{
v14 = func3(20);
strcpy(&fruit, funfruit_0[v14]);
}
fd_data[5] = md_strdup(&fruit);
if ( !prscore )
{
if ( !prversion )
{
if ( wizard )
printf("Hello %s, welcome to dungeon #%d", &whoami, dnum);
else
printf("Hello %s, just a moment while I dig the dungeon...", &whoami);
mem_debug(2LL);
mem_tracking(1LL);
fflush(stdout);
init_things();
init_fd();
init_colors();
init_stones();
init_materials();
initscr();
wrefresh(stdscr);
init_names();
cbreak();
cbreak();
noecho();
nonl();
food_left = (int)(float)((float)((float)(COLS * LINES) / 2000.0) * (float)food_left);
cw = newwin(LINES, COLS, 0, 0);
mw = newwin(LINES, COLS, 0, 0);
hw = newwin(LINES, COLS, 0, 0);
if ( v3 == 2 && *v4[1] && !(unsigned int)restore() )
exit(1);
waswizard = wizard;
init_player();
resurrect = *((_DWORD *)&player + 22);
init_exp();
init_flags();
wclear(hw);
wrefresh(hw);
new_level(1LL, 0LL);
start_daemon(1LL, &player, 2LL);
light_fuse(1LL, 0LL, 140LL, 2LL);
start_daemon(3LL, 0LL, 2LL);
start_daemon(4LL, 0LL, 2LL);
char_type = *((_DWORD *)&player + 90);
*((_QWORD *)&player + 25) = *((_QWORD *)&player + 24);
oldrp = roomin();
after = 1;
signal(2, (__sighandler_t)&quit_handler);
while ( playing )
{
do_daemons(1LL);
do_fuses(1LL);
command();
if ( after )
do_after_effects();
}
func0((const char *)&unk_658);
}
printf("UltraRogue Version %s.\n", release);
exit(0);
}
waswizard = 1;
score(0LL, 0LL, 0xFFFFFFFFLL, 0LL);
exit(0);
}
}
v3 -= v7 - 1;
v4 = &v4[v7 - 1];
goto LABEL_13;
}

original_code:
int
main(int argc, char *argv[])
{
    int x;
    char *env;
    time_t lowtime;
    time_t now;
    int rflag = 0;
    char *nm;
 float scale;
    for (x = 1; x < argc; x++)
    {
        if (argv[x][0] != '-')
            break;
        switch (argv[x][1])
        {
            case 's':
                prscore = 1;
                break;
            case 'v':
                prversion = 1;
                break;
            case 'r':
                rflag = 1;
                break;
            default:
                fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
                exit(1);
        }
    }
    if (!rflag)
    {
        argc -= (x - 1);
        argv += (x - 1);
    }
    strcpy(score_file, "urogue.scr");
    fd_score = fopen(score_file, "r+");
    if (fd_score == ((void *)0))
        fd_score = fopen(score_file, "a+");
    if ((env = getenv("OPTIONS")) != ((void *)0))
        parse_opts(env);
    nm = getenv("USER");
    if (nm != ((void *)0))
        strcpy(whoami,nm);
    else
        strcpy(whoami,"anonymous");
 lowtime = time(&now);
 dnum = (wizard && getenv("SEED") != ((void *)0) ? atoi( getenv("SEED")) : (int)lowtime);
 ur_srandom(dnum);
    if (env == ((void *)0) || fruit[0] == '\0')
    {
        static const char *funfruit[] =
        {
            "candleberry", "caprifig", "dewberry", "elderberry",
            "gooseberry", "guanabana", "hagberry", "ilama", "imbu",
            "jaboticaba", "jujube", "litchi", "mombin", "pitanga",
            "prickly pear", "rambutan", "sapodilla", "soursop",
            "sweetsop", "whortleberry"
        };
        strcpy(fruit, funfruit[rnd(sizeof(funfruit) / sizeof(funfruit[0]))]);
    }
    fd_data[1].mi_name = md_strdup(fruit);
    if (prscore)
    {
        waswizard = 1;
        score(0L, 0, -1, 0);
        exit(0);
    }
    if (prversion)
    {
        printf("UltraRogue Version %s.\n", release);
        exit(0);
    }
    if (wizard)
        printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
    else
        printf("Hello %s, just a moment while I dig the dungeon...", whoami);
    mem_debug(2);
 mem_tracking(1);
    fflush(stdout);
    init_things();
    init_fd();
    init_colors();
    init_stones();
    init_materials();
    initscr();
    wrefresh(stdscr);
    init_names();
    cbreak();
    cbreak();
    noecho();
    nonl();
    scale = (float) (LINES * COLS) / (80.0F * 25.0F);
    food_left = (int) (food_left * scale);
    cw = newwin(LINES, COLS, 0, 0);
    mw = newwin(LINES, COLS, 0, 0);
    hw = newwin(LINES, COLS, 0, 0);
    if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1]))
        exit(1);
    waswizard = wizard;
    init_player();
    resurrect = player.t_stats.s_const;
    init_exp();
    init_flags();
    wclear(hw);
    wrefresh(hw);
    new_level(POSTLEV,0);
    start_daemon(1, &player, 2);
    light_fuse(1, 0, 140, 2);
    start_daemon(3, 0, 2);
    start_daemon(4, 0, 2);
    char_type = player.t_ctype;
    player.t_oldpos = player.t_pos;
    oldrp = roomin(player.t_pos);
    after = 1;
    signal(2, quit_handler);
    while(playing)
    {
        do_daemons(1);
        do_fuses(1);
        command();
        if (after)
            do_after_effects();
    }
    fatal("");
    return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int x;
    char *env;
    long lowtime;
    long now;
    int rflag = 0;
    char *nm;
 float scale;
    for (x = 1; x < argc; x++)
    {
        if (argv[x][0] != '-')
            break;
        switch (argv[x][1])
        {
            case 's':
                prscore = 1;
                break;
            case 'v':
                prversion = 1;
                break;
            case 'r':
                rflag = 1;
                break;
            default:
                fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
                exit(1);
        }
    }
    if (!rflag)
    {
        argc -= (x - 1);
        argv += (x - 1);
    }
    strcpy(score_file, "urogue.scr");
    fd_score = fopen(score_file, "r+");
    if (fd_score == ((void *)0))
        fd_score = fopen(score_file, "a+");
    if ((env = getenv("OPTIONS")) != ((void *)0))
        parse_opts(env);
    nm = getenv("USER");
    if (nm != ((void *)0))
        strcpy(whoami,nm);
    else
        strcpy(whoami,"anonymous");
 lowtime = time(&now);
 dnum = (wizard && getenv("SEED") != ((void *)0) ? atoi( getenv("SEED")) : (int)lowtime);
 ur_srandom(dnum);
    if (env == ((void *)0) || fruit[0] == '\0')
    {
        static char *funfruit[] = {
            "candleberry", "caprifig", "dewberry", "elderberry",
            "gooseberry", "guanabana", "hagberry", "ilama", "imbu",
            "jaboticaba", "jujube", "litchi", "mombin", "pitanga",
            "prickly pear", "rambutan", "sapodilla", "soursop",
            "sweetsop", "whortleberry"
        };
        strcpy(fruit, funfruit[rnd(sizeof(funfruit) / sizeof(funfruit[0]))]);
    }
    fd_data[1].mi_name = md_strdup(fruit);
    if (prscore)
    {
        waswizard = 1;
        score(0L, 0, -1, 0);
        exit(0);
    }
    if (prversion)
    {
        printf("UltraRogue Version %s.\n", release);
        exit(0);
    }
    if (wizard)
        printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
    else
        printf("Hello %s, just a moment while I dig the dungeon...", whoami);
    mem_debug(2);
 mem_tracking(1);
    fflush(stdout);
    init_things();
    init_fd();
    init_colors();
    init_stones();
    init_materials();
    initscr();
    wrefresh(stdscr);
    init_names();
    cbreak();
    cbreak();
    noecho();
    nonl();
    scale = (float) (LINES * COLS) / (80.0F * 25.0F);
    food_left = (int) (food_left * scale);
    cw = newwin(LINES, COLS, 0, 0);
    mw = newwin(LINES, COLS, 0, 0);
    hw = newwin(LINES, COLS, 0, 0);
    if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1]))
        exit(1);
    waswizard = wizard;
    init_player();
    resurrect = player.t_stats.s_const;
    init_exp();
    init_flags();
    wclear(hw);
    wrefresh(hw);
    new_level(POSTLEV,0);
    start_daemon(1, &player, 2);
    light_fuse(1, 0, 140, 2);
    start_daemon(3, 0, 2);
    start_daemon(4, 0, 2);
    char_type = player.t_ctype;
    player.t_oldpos = player.t_pos;
    oldrp = roomin(player.t_pos);
    after = 1;
    signal(2, quit_handler);
    while(playing)
    {
        do_daemons(1);
        do_fuses(1);
        command();
        if (after)
            do_after_effects();
    }
    fatal("");
    return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x int

variable_types:
env
char *

variable_types: lowtime long

variable_types: now long

variable_types: rflag int

variable_types:
nm
char *

variable_types: scale float

variable_types:
funfruit
char *[]


ulrnd

decompiled_code:
unsigned __int64 __fastcall ulrnd(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx

v1 = a1;
if ( a1 )
v1 = (ur_random() & 0x7FFFFFFFuLL) % a1;
return v1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx

v1 = a1;
if ( a1 )
v1 = (ur_random() & 0x7FFFFFFFuLL) % a1;
return v1;
}

original_code:
unsigned long
ulrnd(unsigned long range)
{
    return(range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types:
range
unsigned long

return_type: unsigned long


roll

decompiled_code:
__int64 __fastcall roll(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // ebp

v2 = a1;
if ( !a1 )
return 0;
v3 = 0;
do
{
v3 += rnd(a2) + 1;
--v2;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // ebp

v2 = a1;
if ( !a1 )
return 0;
v3 = 0;
do
{
v3 += func3(a2) + 1;
--v2;
}
while ( v2 );
return v3;
}

original_code:
int
roll(int number, int sides)
{
    int dtotal = 0;
    while (number--)
        dtotal += rnd(sides) + 1;
    return(dtotal);
}

variable_types: number int

variable_types: sides int

variable_types: dtotal int


original_code:
void
swap_top(struct linked_list *top, struct linked_list *node)
{
    struct object *obt, *obn;
    obt = ((*top).data.obj);
    obn = ((*node).data.obj);
    _detach(&(obt->next_obj), node);
    _attach(&lvl_obj, node);
    _detach(&lvl_obj, top);
    obn->next_obj = obt->next_obj;
    if (obn->next_obj)
        obn->next_obj->l_prev = ((void *)0);
    _attach(&(obn->next_obj), top);
}

canonical_original_code:
void swap_top(struct linked_list *top, struct linked_list *node)
{
    struct object *obt; struct object *obn;
    obt = ((*top).data.obj);
    obn = ((*node).data.obj);
    _detach(&(obt->next_obj), node);
    _attach(&lvl_obj, node);
    _detach(&lvl_obj, top);
    obn->next_obj = obt->next_obj;
    if (obn->next_obj)
        obn->next_obj->l_prev = ((void *)0);
    _attach(&(obn->next_obj), top);
}

variable_types: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *

variable_types:
node
struct linked_list *

variable_types: struct object { struct coord { int x; int y; } o_pos; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *


decompiled_code:
__int64 __fastcall pack_report(__int64 a1, int a2, __int64 a3)
{
const char *v3; // rbp
int v4; // eax
int v6; // ecx
__int64 v7; // rax

if ( a2 )
{
if ( !terse )
addmsg(a3);
v3 = (const char *)inv_name(a1, terse == 0);
v4 = get_ident(a1);
msg("(%c%c) %s.", (unsigned int)*(char *)(a1 + 64), (unsigned int)*((char *)&print_letters + v4), v3);
}
if ( *(_BYTE *)(a1 + 64) == 44 )
{
v6 = *(_DWORD *)(a1 + 76);
has_artifact |= 1 << v6;
picked_artifact |= 1 << v6;
v7 = *(_QWORD *)(a1 + 56);
if ( (v7 & 1) == 0 )
{
*(_QWORD *)(a1 + 56) = v7 | 1;
player[4] += arts[10 * v6 + 7] / 10;
check_level();
}
}
return updpack();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3)
{
const char *v3; // rbp
int v4; // eax
int v6; // ecx
__int64 v7; // rax

if ( a2 )
{
if ( !terse )
addmsg(a3);
v3 = (const char *)inv_name(a1, terse == 0);
v4 = get_ident(a1);
msg("(%c%c) %s.", (unsigned int)*(char *)(a1 + 64), (unsigned int)*((char *)&print_letters + v4), v3);
}
if ( *(_BYTE *)(a1 + 64) == 44 )
{
v6 = *(_DWORD *)(a1 + 76);
has_artifact |= 1 << v6;
picked_artifact |= 1 << v6;
v7 = *(_QWORD *)(a1 + 56);
if ( (v7 & 1) == 0 )
{
*(_QWORD *)(a1 + 56) = v7 | 1;
player[4] += arts[10 * v6 + 7] / 10;
check_level();
}
}
return updpack();
}

original_code:
void
pack_report(object *obj, int print_message, char *message)
{
    if (print_message)
    {
        if (!terse)
            addmsg(message);
        msg("(%c%c) %s.", obj->o_type, print_letters[get_ident(obj)],
            inv_name(obj, !terse));
    }
    if (obj->o_type == ',')
    {
        has_artifact |= (1 << obj->o_which);
        picked_artifact |= (1 << obj->o_which);
        if (!(obj->ar_flags & 01))
        {
            obj->ar_flags |= 01;
            player.t_stats.s_exp += arts[obj->o_which].ar_worth / 10;
            check_level();
        }
    }
    updpack();
    return;
}

canonical_original_code:
void pack_report(struct object *obj, int print_message, char *message)
{
    if (print_message)
    {
        if (!terse)
            addmsg(message);
        msg("(%c%c) %s.", obj->o_type, print_letters[get_ident(obj)],
            inv_name(obj, !terse));
    }
    if (obj->o_type == ',')
    {
        has_artifact |= (1 << obj->o_which);
        picked_artifact |= (1 << obj->o_which);
        if (!(obj->ar_flags & 01))
        {
            obj->ar_flags |= 01;
            player.t_stats.s_exp += arts[obj->o_which].ar_worth / 10;
            check_level();
        }
    }
    updpack();
    return;
}

variable_types:
message
char *

user_defined_types: struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; }


decompiled_code:
__int64 __fastcall add_pack(__int64 a1, int a2)
{
__int64 v2; // rbp
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // r14
__int64 v7; // rdi
_QWORD *v8; // rax
__int64 v10; // rdx
const char *v11; // rdx
const char *v12; // rsi
char v13; // si
int v14; // er14
const char *v15; // rax
const char *v16; // rdx
const char *v17; // rsi

v2 = a1;
v4 = 0;
if ( !a1 )
{
v7 = find_obj(HIDWORD(player[24]), LODWORD(player[24]));
if ( !v7 )
{
msg("Nothing to pick up.");
return v4;
}
v2 = get_stack(v7);
if ( !v2 )
return 0;
v4 = 1;
}
v5 = *(_QWORD *)(v2 + 16);
if ( *(_BYTE *)(v5 + 64) == 42 )
{
if ( a2 )
{
if ( !terse )
addmsg("You found ");
msg("%d gold pieces.", *(unsigned int *)(v5 + 72));
}
v8 = (_QWORD *)mlist;
if ( mlist )
{
do
{
v10 = v8[2];
if ( *(_QWORD *)(v10 + 184) == v5 )
{
*(_DWORD *)(v10 + 168) = 1;
*(_QWORD *)(v10 + 176) = player;
*(_QWORD *)(v10 + 184) = 0LL;
}
v8 = (_QWORD *)*v8;
}
while ( v8 );
}
if ( LODWORD(player[45]) == 7 )
{
player[4] += *(_DWORD *)(v5 + 72) >> 2;
check_level();
}
purse += *(unsigned int *)(v5 + 72);
if ( v4 )
rem_obj(v2, 1LL);
else
v4 = 1;
}
else if ( (signed int)(LODWORD(player[6]) + itemweight(*(_QWORD *)(v2 + 16))) > SHIDWORD(player[6]) )
{
msg("Too much for you to carry.");
v4 = a2;
if ( a2 )
{
v11 = (const char *)inv_name(v5, 1LL);
v12 = "Moved";
if ( !terse )
v12 = "You moved";
msg("%s onto %s", v12, v11);
v4 = 0;
}
}
else
{
v6 = apply_to_bag(player[2], (unsigned int)*(char *)(v5 + 64), &bff_group, 0LL, v5);
if ( v6 )
{
*(_DWORD *)(v6 + 72) += *(_DWORD *)(v5 + 72);
if ( v4 )
rem_obj(v2, 0LL);
pack_report(v6, a2, (__int64)"You now have ");
v4 = 1;
}
else
{
v13 = *(_BYTE *)(v5 + 64);
if ( v13 == 63 && *(_DWORD *)(v5 + 76) == 7 && (*(_BYTE *)(v5 + 48) & 1) != 0 )
{
msg("The scroll turns to dust as you pick it up.");
rem_obj(v2, 1LL);
v4 = 1;
}
else
{
v14 = count_bag(player[2], (unsigned int)v13, 0LL);
if ( v14 == (unsigned int)max_print() )
{
v15 = (const char *)name_type((unsigned int)*(char *)(v5 + 64));
msg("You have no room for more %s.", v15);
v4 = a2;
if ( a2 )
{
v16 = (const char *)inv_name(*(_QWORD *)(v2 + 16), 1LL);
v17 = "Moved";
if ( !terse )
v17 = "You moved";
msg("%s onto %s.", v17, v16);
v4 = 0;
}
}
else
{
if ( v4 )
rem_obj(v2, 0LL);
push_bag((unsigned int)((_DWORD)player + 16), v5);
pack_report(v5, a2, (__int64)"You now have ");
ur_free(v2);
v4 = 1;
}
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rbp
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // r14
__int64 v7; // rdi
_QWORD *v8; // rax
__int64 v10; // rdx
const char *v11; // rdx
const char *v12; // rsi
char v13; // si
int v14; // er14
const char *v15; // rax
const char *v16; // rdx
const char *v17; // rsi

v2 = a1;
v4 = 0;
if ( !a1 )
{
v7 = find_obj(HIDWORD(player[24]), LODWORD(player[24]));
if ( !v7 )
{
msg("Nothing to pick up.");
return v4;
}
v2 = get_stack(v7);
if ( !v2 )
return 0;
v4 = 1;
}
v5 = *(_QWORD *)(v2 + 16);
if ( *(_BYTE *)(v5 + 64) == 42 )
{
if ( a2 )
{
if ( !terse )
addmsg("You found ");
msg("%d gold pieces.", *(unsigned int *)(v5 + 72));
}
v8 = (_QWORD *)mlist;
if ( mlist )
{
do
{
v10 = v8[2];
if ( *(_QWORD *)(v10 + 184) == v5 )
{
*(_DWORD *)(v10 + 168) = 1;
*(_QWORD *)(v10 + 176) = player;
*(_QWORD *)(v10 + 184) = 0LL;
}
v8 = (_QWORD *)*v8;
}
while ( v8 );
}
if ( LODWORD(player[45]) == 7 )
{
player[4] += *(_DWORD *)(v5 + 72) >> 2;
check_level();
}
purse += *(unsigned int *)(v5 + 72);
if ( v4 )
rem_obj(v2, 1LL);
else
v4 = 1;
}
else if ( (signed int)(LODWORD(player[6]) + itemweight(*(_QWORD *)(v2 + 16))) > SHIDWORD(player[6]) )
{
msg("Too much for you to carry.");
v4 = a2;
if ( a2 )
{
v11 = (const char *)inv_name(v5, 1LL);
v12 = "Moved";
if ( !terse )
v12 = "You moved";
msg("%s onto %s", v12, v11);
v4 = 0;
}
}
else
{
v6 = apply_to_bag(player[2], (unsigned int)*(char *)(v5 + 64), &bff_group, 0LL, v5);
if ( v6 )
{
*(_DWORD *)(v6 + 72) += *(_DWORD *)(v5 + 72);
if ( v4 )
rem_obj(v2, 0LL);
func1(v6, a2, (__int64)"You now have ");
v4 = 1;
}
else
{
v13 = *(_BYTE *)(v5 + 64);
if ( v13 == 63 && *(_DWORD *)(v5 + 76) == 7 && (*(_BYTE *)(v5 + 48) & 1) != 0 )
{
msg("The scroll turns to dust as you pick it up.");
rem_obj(v2, 1LL);
v4 = 1;
}
else
{
v14 = count_bag(player[2], (unsigned int)v13, 0LL);
if ( v14 == (unsigned int)max_print() )
{
v15 = (const char *)name_type((unsigned int)*(char *)(v5 + 64));
msg("You have no room for more %s.", v15);
v4 = a2;
if ( a2 )
{
v16 = (const char *)inv_name(*(_QWORD *)(v2 + 16), 1LL);
v17 = "Moved";
if ( !terse )
v17 = "You moved";
msg("%s onto %s.", v17, v16);
v4 = 0;
}
}
else
{
if ( v4 )
rem_obj(v2, 0LL);
push_bag((unsigned int)((_DWORD)player + 16), v5);
func1(v5, a2, (__int64)"You now have ");
ur_free(v2);
v4 = 1;
}
}
}
}
return v4;
}

original_code:
int
add_pack(struct linked_list *item, int print_message)
{
    struct object *obj, *op;
    int from_floor;
    if (item == ((void *)0))
    {
        from_floor = 1;
        if ((item = find_obj(player.t_pos.y, player.t_pos.x)) == ((void *)0))
        {
            msg("Nothing to pick up.");
            return(0);
        }
    }
    else
        from_floor = 0;
    if (from_floor)
    {
        item = get_stack(item);
        if (!item)
            return(0);
    }
    obj = ((*item).data.obj);
    if (obj->o_type == '*')
    {
        struct linked_list *mitem;
        struct thing *tp;
        if (print_message)
        {
            if (!terse)
                addmsg("You found ");
            msg("%d gold pieces.", obj->o_count);
        }
        for (mitem = mlist; mitem != ((void *)0); mitem = ((mitem)?(mitem->l_next):((void *)0)))
        {
            tp = ((*mitem).data.th);
            if (tp->t_horde==obj)
            {
                tp->t_ischasing = 1;
                tp->t_chasee = &player;
                tp->t_horde = ((void *)0);
            }
        }
        if (player.t_ctype == 7)
        {
            player.t_stats.s_exp += obj->o_count / 4;
            check_level();
        }
        purse += obj->o_count;
        if (from_floor)
            rem_obj(item, 1);
        return (1);
    }
    if (itemweight(obj) + player.t_stats.s_pack > player.t_stats.s_carry)
    {
        msg("Too much for you to carry.");
        if (print_message)
        {
            msg("%s onto %s", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if ((op = apply_to_bag(player.t_pack, obj->o_type, bff_group, ((void *)0), obj)) != ((void *)0))
    {
        op->o_count += obj->o_count;
        if (from_floor)
            rem_obj(item, 0);
        pack_report(op, print_message, "You now have ");
        return(1);
    }
    if (obj->o_type == '?' && obj->o_which == 7)
        if (obj->o_flags & 0x00000001UL)
        {
            msg("The scroll turns to dust as you pick it up.");
            rem_obj(item, 1);
            return(1);
        }
    if (count_bag(player.t_pack, obj->o_type, ((void *)0)) == max_print())
    {
        msg("You have no room for more %s.", name_type(obj->o_type));
        if (print_message)
        {
            obj = ((*item).data.obj);
            msg("%s onto %s.", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if (from_floor)
        rem_obj(item, 0);
    push_bag(&player.t_pack, obj);
    pack_report(obj, print_message, "You now have ");
    ur_free(item);
    return(1);
}

canonical_original_code:
int add_pack(struct linked_list *item, int print_message)
{
    struct object *obj; struct object *op;
    int from_floor;
    if (item == ((void *)0))
    {
        from_floor = 1;
        if ((item = find_obj(player.t_pos.y, player.t_pos.x)) == ((void *)0))
        {
            msg("Nothing to pick up.");
            return(0);
        }
    }
    else
        from_floor = 0;
    if (from_floor)
    {
        item = get_stack(item);
        if (!item)
            return(0);
    }
    obj = ((*item).data.obj);
    if (obj->o_type == '*')
    {
        struct linked_list *mitem;
        struct thing *tp;
        if (print_message)
        {
            if (!terse)
                addmsg("You found ");
            msg("%d gold pieces.", obj->o_count);
        }
        for (mitem = mlist; mitem != ((void *)0); mitem = ((mitem)?(mitem->l_next):((void *)0)))
        {
            tp = ((*mitem).data.th);
            if (tp->t_horde==obj)
            {
                tp->t_ischasing = 1;
                tp->t_chasee = &player;
                tp->t_horde = ((void *)0);
            }
        }
        if (player.t_ctype == 7)
        {
            player.t_stats.s_exp += obj->o_count / 4;
            check_level();
        }
        purse += obj->o_count;
        if (from_floor)
            rem_obj(item, 1);
        return (1);
    }
    if (itemweight(obj) + player.t_stats.s_pack > player.t_stats.s_carry)
    {
        msg("Too much for you to carry.");
        if (print_message)
        {
            msg("%s onto %s", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if ((op = apply_to_bag(player.t_pack, obj->o_type, bff_group, ((void *)0), obj)) != ((void *)0))
    {
        op->o_count += obj->o_count;
        if (from_floor)
            rem_obj(item, 0);
        pack_report(op, print_message, "You now have ");
        return(1);
    }
    if (obj->o_type == '?' && obj->o_which == 7)
        if (obj->o_flags & 0x00000001UL)
        {
            msg("The scroll turns to dust as you pick it up.");
            rem_obj(item, 1);
            return(1);
        }
    if (count_bag(player.t_pack, obj->o_type, ((void *)0)) == max_print())
    {
        msg("You have no room for more %s.", name_type(obj->o_type));
        if (print_message)
        {
            obj = ((*item).data.obj);
            msg("%s onto %s.", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if (from_floor)
        rem_obj(item, 0);
    push_bag(&player.t_pack, obj);
    pack_report(obj, print_message, "You now have ");
    ur_free(item);
    return(1);
}

variable_types: struct thing { long chasee_index; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing *th; void *l_data; } data; } *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *


decompiled_code:
void __fastcall get_all(__int64 a1)
{
__int64 v2; // rbp

while ( a1 )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
rem_obj(a1, 0LL);
if ( !(unsigned int)add_pack(a1, 0) )
break;
a1 = v2;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v2; // rbp

while ( a1 )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
rem_obj(a1, 0LL);
if ( !(unsigned int)func2(a1, 0) )
break;
a1 = v2;
}
}

original_code:
void
get_all(struct linked_list *top)
{
    struct linked_list *node;
    struct object *obt;
    while (top)
    {
        obt = ((*top).data.obj);
        node = obt->next_obj;
        rem_obj(top, 0);
        if (!add_pack(top, 0))
            return;
        top = node;
    }
}


inventory

decompiled_code:
__int64 __fastcall inventory(__int64 a1, unsigned int a2)
{
const char *v2; // rax
__int64 result; // rax
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a2;
if ( a2 || (msg("What kind of item <%s> to inventory (* for all)?", type_list), v4[0] = (char)readchar(), v4[0] != 27) )
{
if ( v4[0] == 42 )
v4[0] = 0;
mpos = 0;
if ( (unsigned int)count_bag(a1, v4[0], 0LL) )
{
apply_to_bag(a1, v4[0], 0LL, &baf_print_item, v4);
end_line();
result = msg((const char *)&unk_D6C);
}
else
{
v2 = (const char *)name_type(v4[0]);
result = msg("You don't have any %s.", v2);
}
}
else
{
after = 0;
result = msg((const char *)&unk_D6C);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
const char *v2; // rax
__int64 result; // rax
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a2;
if ( a2 || (msg("What kind of item <%s> to inventory (* for all)?", type_list), v4[0] = (char)readchar(), v4[0] != 27) )
{
if ( v4[0] == 42 )
v4[0] = 0;
mpos = 0;
if ( (unsigned int)count_bag(a1, v4[0], 0LL) )
{
apply_to_bag(a1, v4[0], 0LL, &baf_print_item, v4);
end_line();
result = msg((const char *)&unk_D6C);
}
else
{
v2 = (const char *)name_type(v4[0]);
result = msg("You don't have any %s.", v2);
}
}
else
{
after = 0;
result = msg((const char *)&unk_D6C);
}
return result;
}

original_code:
void
inventory(struct linked_list *container, int type)
{
    int cnt;
    if (type == 0)
    {
        msg("What kind of item <%s> to inventory (* for all)?", type_list);
        type = readchar();
        if (type == 27)
        {
            after = 0;
            msg("");
            return;
        }
    }
    if (type == '*')
        type = 0;
    mpos = 0;
    if ((cnt = count_bag(container, type, ((void *)0))) == 0)
        msg("You don't have any %s.", name_type(type));
    else
    {
        apply_to_bag(container, type, ((void *)0), baf_print_item, &type);
        end_line();
        msg("");
    }
    return;
}

variable_types: type int

variable_types: cnt int


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

switch ( a1 )
{
case '!':
case ')':
case '*':
case ',':
case '/':
case ':':
case '=':
case '?':
case ']':
result = add_pack(0LL, 1);
break;
default:
if ( wizard )
{
if ( wiz_verbose )
result = msg("Where did you pick that up???");
}
break;
}
return result;
}

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

switch ( a1 )
{
case '!':
case ')':
case '*':
case ',':
case '/':
case ':':
case '=':
case '?':
case ']':
result = func2(0LL, 1);
break;
default:
if ( wizard )
{
if ( wiz_verbose )
result = msg("Where did you pick that up???");
}
break;
}
return result;
}

original_code:
void
pick_up(char ch)
{
    switch(ch)
    {
        default:
            if (wizard && wiz_verbose) msg("Where did you pick that up???");
            break;
        case '*':
        case ']':
        case '!':
        case ':':
        case ')':
        case '?':
        case ',':
        case '=':
        case '/':
            add_pack(((void *)0), 1);
            break;
    }
}

variable_types: ch char


decompiled_code:
__int64 __fastcall get_object(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 v5; // rbx
char v6; // bl
const char *v7; // rax
char v9; // bl
unsigned int v10; // er14
unsigned int v11; // eax
unsigned int v12[4]; // [rsp+Ch] [rbp-3Ch] BYREF
char v13[41]; // [rsp+1Fh] [rbp-29h] BYREF

v12[0] = a3;
if ( a1 )
{
v5 = apply_to_bag(a1, v12[0], a4, 0LL, 0LL);
if ( v5 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
if ( v12[0] )
goto LABEL_18;
msg("What kind of item <%s> do you want to %s (* for list)?", type_list, a2);
v6 = readchar();
if ( v6 == 27 )
{
after = 0;
msg((const char *)&unk_D6C);
return 0LL;
}
msg((const char *)&unk_D6C);
if ( v6 != 42 )
break;
add_line("! Potion");
add_line("? Scroll");
add_line("= Ring");
add_line("/ Stick");
add_line("] Armor");
add_line(") Weapon");
add_line(": Food");
end_line();
}
if ( (unsigned int)is_member(type_list, (unsigned int)v6) )
break;
beep();
}
if ( (unsigned int)count_bag(a1, (unsigned int)v6, 0LL) )
break;
v7 = (const char *)name_type((unsigned int)v6);
msg("You don't have any %s.", v7);
}
v12[0] = v6;
do
{
while ( 1 )
{
LABEL_18:
msg("What item do you want to %s (* for list)?", a2);
v9 = readchar();
msg((const char *)&unk_D6C);
if ( v9 == 27 )
{
after = 0;
msg((const char *)&unk_D6C);
return 0LL;
}
if ( v9 != 42 )
break;
mpos = 0;
apply_to_bag(a1, v12[0], a4, &baf_print_item, v12);
end_line();
}
v10 = v12[0];
v13[0] = v9;
v11 = unprint_id(v13);
v5 = scan_bag(a1, v10, v11);
}
while ( !v5 );
mpos = 0;
msg((const char *)&unk_D6C);
}
else
{
msg("You seem to have nothing to %s.", a2);
after = 0;
}
}
else
{
msg("There isn't anything in there.");
after = 0;
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 v5; // rbx
char v6; // bl
const char *v7; // rax
char v9; // bl
unsigned int v10; // er14
unsigned int v11; // eax
unsigned int v12[4]; // [rsp+Ch] [rbp-3Ch] BYREF
char v13[41]; // [rsp+1Fh] [rbp-29h] BYREF

v12[0] = a3;
if ( a1 )
{
v5 = apply_to_bag(a1, v12[0], a4, 0LL, 0LL);
if ( v5 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
if ( v12[0] )
goto LABEL_18;
msg("What kind of item <%s> do you want to %s (* for list)?", type_list, a2);
v6 = readchar();
if ( v6 == 27 )
{
after = 0;
msg((const char *)&unk_D6C);
return 0LL;
}
msg((const char *)&unk_D6C);
if ( v6 != 42 )
break;
add_line("! Potion");
add_line("? Scroll");
add_line("= Ring");
add_line("/ Stick");
add_line("] Armor");
add_line(") Weapon");
add_line(": Food");
end_line();
}
if ( (unsigned int)is_member(type_list, (unsigned int)v6) )
break;
beep();
}
if ( (unsigned int)count_bag(a1, (unsigned int)v6, 0LL) )
break;
v7 = (const char *)name_type((unsigned int)v6);
msg("You don't have any %s.", v7);
}
v12[0] = v6;
do
{
while ( 1 )
{
LABEL_18:
msg("What item do you want to %s (* for list)?", a2);
v9 = readchar();
msg((const char *)&unk_D6C);
if ( v9 == 27 )
{
after = 0;
msg((const char *)&unk_D6C);
return 0LL;
}
if ( v9 != 42 )
break;
mpos = 0;
apply_to_bag(a1, v12[0], a4, &baf_print_item, v12);
end_line();
}
v10 = v12[0];
v13[0] = v9;
v11 = unprint_id(v13);
v5 = scan_bag(a1, v10, v11);
}
while ( !v5 );
mpos = 0;
msg((const char *)&unk_D6C);
}
else
{
msg("You seem to have nothing to %s.", a2);
after = 0;
}
}
else
{
msg("There isn't anything in there.");
after = 0;
v5 = 0LL;
}
return v5;
}

original_code:
struct object *
get_object(struct linked_list *container, char *purpose, int type, int (*bff_p)(struct object *obj, bag_arg *junk))
{
    struct object *obj_p = ((void *)0);
    char sel_id;
    int sel_type;
    char response;
    if (container == ((void *)0))
    {
        msg("There isn't anything in there.");
        after = 0;
        return(((void *)0));
    }
    if (apply_to_bag(container, type, bff_p, ((void *)0), ((void *)0)) == ((void *)0))
    {
        msg("You seem to have nothing to %s.", purpose);
        after = 0;
        return(((void *)0));
    }
    while (obj_p == ((void *)0))
    {
        if (type == 0)
        {
            msg("What kind of item <%s> do you want to %s (* for list)?", type_list, purpose);
            response = readchar();
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            msg("");
            if (response == '*')
            {
                add_line("! Potion");
                add_line("? Scroll");
                add_line("= Ring");
                add_line("/ Stick");
                add_line("] Armor");
                add_line(") Weapon");
                add_line(": Food");
                end_line();
                continue;
            }
            if (!is_member(type_list, response)) { beep();
               continue; }
            if (count_bag(container, response, ((void *)0)) == 0)
            {
                msg("You don't have any %s.", name_type(response));
                continue;
            }
            type = response;
        }
        while(obj_p == ((void *)0))
        {
            msg("What item do you want to %s (* for list)?", purpose);
            response = readchar();
            msg("");
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            if (response == '*')
            {
                mpos = 0;
                apply_to_bag(container, type, bff_p, baf_print_item, &type);
                end_line();
                continue;
            }
            sel_type = type;
            sel_id = response;
            obj_p = scan_bag(container, sel_type,unprint_id(&sel_id));
        }
    }
    mpos = 0;
    msg("");
    return(obj_p);
}

canonical_original_code:
struct object *get_object(struct linked_list *container, char *purpose, int type, int (*bff_p)(struct object *obj, union bag_arg *junk))
{
    struct object *obj_p = ((void *)0);
    char sel_id;
    int sel_type;
    char response;
    if (container == ((void *)0))
    {
        msg("There isn't anything in there.");
        after = 0;
        return(((void *)0));
    }
    if (apply_to_bag(container, type, bff_p, ((void *)0), ((void *)0)) == ((void *)0))
    {
        msg("You seem to have nothing to %s.", purpose);
        after = 0;
        return(((void *)0));
    }
    while (obj_p == ((void *)0))
    {
        if (type == 0)
        {
            msg("What kind of item <%s> do you want to %s (* for list)?", type_list, purpose);
            response = readchar();
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            msg("");
            if (response == '*')
            {
                add_line("! Potion");
                add_line("? Scroll");
                add_line("= Ring");
                add_line("/ Stick");
                add_line("] Armor");
                add_line(") Weapon");
                add_line(": Food");
                end_line();
                continue;
            }
            if (!is_member(type_list, response)) { beep();
               continue; }
            if (count_bag(container, response, ((void *)0)) == 0)
            {
                msg("You don't have any %s.", name_type(response));
                continue;
            }
            type = response;
        }
        while(obj_p == ((void *)0))
        {
            msg("What item do you want to %s (* for list)?", purpose);
            response = readchar();
            msg("");
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            if (response == '*')
            {
                mpos = 0;
                apply_to_bag(container, type, bff_p, baf_print_item, &type);
                end_line();
                continue;
            }
            sel_type = type;
            sel_id = response;
            obj_p = scan_bag(container, sel_type,unprint_id(&sel_id));
        }
    }
    mpos = 0;
    msg("");
    return(obj_p);
}

variable_types:
container
struct linked_list *

variable_types:
purpose
char *

variable_types: int (*)(struct object *obj, union bag_arg { void *varg; int *iarg; struct object *obj; } *junk)

variable_types: response char

return_type: struct object { struct coord { int x; int y; } o_pos; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *


decompiled_code:
__int64 __fastcall get_item(const char *a1, unsigned int a2)
{
__int64 result; // rax

result = get_object(player[2], a1, a2, 0LL);
if ( result )
result = make_item(result);
return result;
}

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

result = func6(player[2], a1, a2, 0LL);
if ( result )
result = make_item(result);
return result;
}

original_code:
struct linked_list *
get_item(char *purpose, int type)
{
    struct object *obj_p;
    if ((obj_p = get_object(player.t_pack, purpose, type, ((void *)0))) == ((void *)0))
        return(((void *)0));
    return(make_item(obj_p));
}

canonical_original_code:
struct linked_list *get_item(char *purpose, int type)
{
    struct object *obj_p;
    if ((obj_p = get_object(player.t_pack, purpose, type, ((void *)0))) == ((void *)0))
        return(((void *)0));
    return(make_item(obj_p));
}

return_type: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *


decompiled_code:
void __fastcall cur_null(__int64 a1)
{
if ( cur_weapon == a1 )
{
cur_weapon = 0LL;
}
else if ( cur_armor == a1 )
{
cur_armor = 0LL;
}
else if ( cur_ring[0] == a1 )
{
cur_ring[0] = 0LL;
}
else if ( cur_ring[1] == a1 )
{
cur_ring[1] = 0LL;
}
else if ( cur_ring[2] == a1 )
{
cur_ring[2] = 0LL;
}
else if ( cur_ring[3] == a1 )
{
cur_ring[3] = 0LL;
}
else if ( cur_ring[4] == a1 )
{
cur_ring[4] = 0LL;
}
else if ( cur_ring[5] == a1 )
{
cur_ring[5] = 0LL;
}
else if ( cur_ring[6] == a1 )
{
cur_ring[6] = 0LL;
}
else if ( cur_ring[7] == a1 )
{
cur_ring[7] = 0LL;
}
else if ( cur_ring[8] == a1 )
{
cur_ring[8] = 0LL;
}
else if ( cur_ring[9] == a1 )
{
cur_ring[9] = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
if ( cur_weapon == a1 )
{
cur_weapon = 0LL;
}
else if ( cur_armor == a1 )
{
cur_armor = 0LL;
}
else if ( cur_ring[0] == a1 )
{
cur_ring[0] = 0LL;
}
else if ( cur_ring[1] == a1 )
{
cur_ring[1] = 0LL;
}
else if ( cur_ring[2] == a1 )
{
cur_ring[2] = 0LL;
}
else if ( cur_ring[3] == a1 )
{
cur_ring[3] = 0LL;
}
else if ( cur_ring[4] == a1 )
{
cur_ring[4] = 0LL;
}
else if ( cur_ring[5] == a1 )
{
cur_ring[5] = 0LL;
}
else if ( cur_ring[6] == a1 )
{
cur_ring[6] = 0LL;
}
else if ( cur_ring[7] == a1 )
{
cur_ring[7] = 0LL;
}
else if ( cur_ring[8] == a1 )
{
cur_ring[8] = 0LL;
}
else if ( cur_ring[9] == a1 )
{
cur_ring[9] = 0LL;
}
}

original_code:
void
cur_null(struct object *op)
{
    if (op == cur_weapon)
        cur_weapon = ((void *)0);
    else if (op == cur_armor)
        cur_armor = ((void *)0);
    else if (op == cur_ring[0])
        cur_ring[0] = ((void *)0);
    else if (op == cur_ring[1])
        cur_ring[1] = ((void *)0);
    else if (op == cur_ring[2])
        cur_ring[2] = ((void *)0);
    else if (op == cur_ring[3])
        cur_ring[3] = ((void *)0);
    else if (op == cur_ring[4])
        cur_ring[4] = ((void *)0);
    else if (op == cur_ring[5])
        cur_ring[5] = ((void *)0);
    else if (op == cur_ring[6])
        cur_ring[6] = ((void *)0);
    else if (op == cur_ring[7])
        cur_ring[7] = ((void *)0);
    else if (op == cur_ring[8])
        cur_ring[8] = ((void *)0);
    else if (op == cur_ring[9])
        cur_ring[9] = ((void *)0);
}


decompiled_code:
__int64 __fastcall rem_pack(__int64 a1)
{
cur_null(a1);
pop_bag((unsigned int)((_DWORD)player + 16), a1);
return updpack();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
func8(a1);
pop_bag((unsigned int)((_DWORD)player + 16), a1);
return updpack();
}

original_code:
void
rem_pack(struct object *obj_p)
{
    cur_null(obj_p);
    pop_bag(&player.t_pack, obj_p);
    updpack();
    return;
}


decompiled_code:
__int64 __fastcall del_pack(__int64 a1)
{
rem_pack(*(_QWORD *)(a1 + 16));
return discard(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
func9(*(_QWORD *)(a1 + 16));
return discard(a1);
}

original_code:
void
del_pack(struct linked_list *what)
{
    rem_pack(((*what).data.obj));
    discard(what);
}


decompiled_code:
__int64 __fastcall discard_pack(__int64 a1)
{
rem_pack(a1);
return throw_away(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
func9(a1);
return throw_away(a1);
}

original_code:
void
discard_pack(struct object *obj_p)
{
    rem_pack(obj_p);
    throw_away(obj_p);
}


idenpack

decompiled_code:
__int64 idenpack()
{
return apply_to_bag(player[2], 0LL, 0LL, &baf_identify, 0LL);
}

canonical_decompiled_code:
__int64 func12()
{
return apply_to_bag(player[2], 0LL, 0LL, &baf_identify, 0LL);
}

original_code:
void
idenpack(void)
{
    apply_to_bag(player.t_pack, 0, ((void *)0), baf_identify, ((void *)0));
}

canonical_original_code:
void idenpack()
{
    apply_to_bag(player.t_pack, 0, ((void *)0), baf_identify, ((void *)0));
}


decompiled_code:
__int64 show_floor()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rsi
__int64 v3; // rdi
const char *v4; // rax

result = find_obj(player[49], player[48]);
if ( result )
{
v1 = result;
v2 = "Moved";
if ( !terse )
v2 = "You moved";
addmsg("%s onto ", v2);
v3 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v3 + 8) )
{
result = msg("a stack of things.");
}
else if ( *(_BYTE *)(v3 + 64) == 42 )
{
result = msg("%d gold pieces.", *(unsigned int *)(v3 + 72));
}
else
{
v4 = (const char *)inv_name(v3, 1LL);
addmsg(v4);
addmsg(".");
result = endmsg();
}
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rsi
__int64 v3; // rdi
const char *v4; // rax

result = find_obj(player[49], player[48]);
if ( result )
{
v1 = result;
v2 = "Moved";
if ( !terse )
v2 = "You moved";
addmsg("%s onto ", v2);
v3 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v3 + 8) )
{
result = msg("a stack of things.");
}
else if ( *(_BYTE *)(v3 + 64) == 42 )
{
result = msg("%d gold pieces.", *(unsigned int *)(v3 + 72));
}
else
{
v4 = (const char *)inv_name(v3, 1LL);
addmsg(v4);
addmsg(".");
result = endmsg();
}
}
return result;
}

original_code:
void
show_floor(void)
{
    struct linked_list *item;
    struct object *obj;
    item = find_obj(player.t_pos.y, player.t_pos.x);
    if (item != ((void *)0))
    {
        addmsg("%s onto ", terse ? "Moved" : "You moved");
        obj = ((*item).data.obj);
        if (obj->next_obj != ((void *)0))
      msg("a stack of things.");
  else if (obj->o_type == '*')
            msg("%d gold pieces.", obj->o_count);
        else
        {
            addmsg(inv_name(obj, 1));
            addmsg(".");
            endmsg();
        }
    }
}

canonical_original_code:
void show_floor()
{
    struct linked_list *item;
    struct object *obj;
    item = find_obj(player.t_pos.y, player.t_pos.x);
    if (item != ((void *)0))
    {
        addmsg("%s onto ", terse ? "Moved" : "You moved");
        obj = ((*item).data.obj);
        if (obj->next_obj != ((void *)0))
      msg("a stack of things.");
  else if (obj->o_type == '*')
            msg("%d gold pieces.", obj->o_count);
        else
        {
            addmsg(inv_name(obj, 1));
            addmsg(".");
            endmsg();
        }
    }
}