acao

decompiled_code:
__int64 __fastcall acao(char a1, int *a2)
{
int v2; // ebx
unsigned int v3; // ebp
char v4; // al
char v5; // r12
__int64 v6; // rdx
__int64 result; // rax
unsigned int v8; // ebp
char v9; // r12
__int64 v10; // rdx
__int64 v11; // r13
int v12; // er14
char v13; // al
unsigned int v14; // er12
__int64 v15; // rbx
unsigned int v16; // eax
int v17; // er12
unsigned int v18; // ebp
unsigned int v19; // eax
__int64 v20; // rdx
__int64 v21; // r13
int v22; // er12
unsigned int v23; // ebx
unsigned int v24; // er15
unsigned int v25; // eax
__int64 v26; // rdx
__int64 v27; // r13
int v28; // ebp
unsigned int v29; // ebx
unsigned int v30; // er15
unsigned int v31; // eax
__int64 v32; // rdx
__int64 v33; // r13
int v34; // ebp
unsigned int v35; // ebx
unsigned int v36; // er15
unsigned int v37; // eax
__int64 v38; // rdx
__int64 v39; // r13
int v40; // ebp
unsigned int v41; // ebx
unsigned int v42; // er15
unsigned int v43; // eax
__int64 v44; // rdx
int v45; // ebp
__int64 v46; // r14
char v47; // r12
unsigned int v48; // er15
int v49; // ebx
unsigned int v50; // eax
char v51; // cl
__int64 v52; // rdx
unsigned int v53; // eax

v2 = *a2;
switch ( a1 )
{
case 1:
v3 = conversaoHexa(ram[2 * v2 - 1]);
v4 = getEndreco(ram[2 * v2], ram[2 * v2 + 1]);
v5 = leituraMem(v4);
printf("Registrador [%X] = 0x%X\n", v3, (unsigned int)variavel[v3]);
printf("Registrador [%X] <= 0x[%c%c]\n", v3, (unsigned int)ram[2 * v2], (unsigned int)ram[2 * v2 + 1]);
v6 = (unsigned int)v5;
variavel[v3] = v6;
printf("Registrador [%X] = 0x%X\n", v3, v6);
result = 1LL;
break;
case 2:
v8 = conversaoHexa(ram[2 * v2 - 1]);
v9 = getEndreco(ram[2 * v2], ram[2 * v2 + 1]);
printf("Registrador [%X] = 0x%X\n", v8, (unsigned int)variavel[v8]);
printf("Registrador [%X] <= 0x%c%c\n", v8, (unsigned int)ram[2 * v2], (unsigned int)ram[2 * v2 + 1]);
v10 = (unsigned int)v9;
variavel[v8] = v10;
printf("Registrador [%X] = 0x%X\n", v8, v10);
result = 1LL;
break;
case 3:
v11 = v2 - 1;
v12 = variavel[(int)conversaoHexa(ram[2 * v11 + 1])];
v13 = getEndreco(ram[2 * v2], ram[2 * v2 + 1]);
v14 = v13;
v15 = v13;
printf(aMem, (unsigned int)v13, (unsigned int)ram[2 * v13], (unsigned int)ram[2 * v13 + 1]);
v16 = conversaoHexa(ram[2 * v11 + 1]);
printf(aMem_0, v14, v16);
conversaoHToChar((char)v12, v14);
printf(aMem, v14, (unsigned int)ram[2 * v15], (unsigned int)ram[2 * v15 + 1]);
result = 1LL;
break;
case 4:
if ( (unsigned int)conversaoHexa(ram[2 * v2 - 1]) )
{
puts(aInstru);
exit(1);
}
v17 = variavel[(int)conversaoHexa(ram[2 * v2])];
v18 = conversaoHexa(ram[2 * v2 + 1]);
printf("Registrador [%X] = 0x%X\n", v18, (unsigned int)variavel[v18]);
v19 = conversaoHexa(ram[2 * v2]);
printf("Registrador [%X] <= R[%X]\n", v18, v19);
v20 = (unsigned int)(char)v17;
variavel[v18] = v20;
printf("Registrador [%X] = 0x%X\n", v18, v20);
result = 1LL;
break;
case 5:
v21 = v2;
v22 = conversaoHexa(ram[2 * v2]);
LOBYTE(v22) = LOBYTE(variavel[v22]) + variavel[(int)conversaoHexa(ram[2 * v2 + 1])];
v23 = conversaoHexa(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v23, (unsigned int)variavel[v23]);
v24 = conversaoHexa(ram[2 * v21 + 1]);
v25 = conversaoHexa(ram[2 * v21]);
printf("Registrador [%X] <= R[%X] + R[%X]\n", v23, v25, v24);
v26 = (unsigned int)(char)v22;
variavel[v23] = v26;
printf("Registrador [%X] = 0x%X\n", v23, v26);
result = 1LL;
break;
case 6:
puts(aInstru_0);
result = 1LL;
break;
case 7:
v27 = v2;
v28 = variavel[(int)conversaoHexa(ram[2 * v2])];
LOBYTE(v28) = LOBYTE(variavel[(int)conversaoHexa(ram[2 * v2 + 1])]) | v28;
v29 = conversaoHexa(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v29, (unsigned int)variavel[v29]);
v30 = conversaoHexa(ram[2 * v27 + 1]);
v31 = conversaoHexa(ram[2 * v27]);
printf("Registrador [%X] <= R[%X] v R[%X]\n", v29, v31, v30);
v32 = (unsigned int)(char)v28;
variavel[v29] = v32;
printf("Registrador [%X] = 0x%X\n", v29, v32);
result = 1LL;
break;
case 8:
v33 = v2;
v34 = variavel[(int)conversaoHexa(ram[2 * v2])];
LOBYTE(v34) = LOBYTE(variavel[(int)conversaoHexa(ram[2 * v2 + 1])]) & v34;
v35 = conversaoHexa(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v35, (unsigned int)variavel[v35]);
v36 = conversaoHexa(ram[2 * v33 + 1]);
v37 = conversaoHexa(ram[2 * v33]);
printf("Registrador [%X] <= R[%X] ^ R[%X]\n", v35, v37, v36);
v38 = (unsigned int)(char)v34;
variavel[v35] = v38;
printf("Registrador [%X] = 0x%X\n", v35, v38);
result = 1LL;
break;
case 9:
v39 = v2;
v40 = variavel[(int)conversaoHexa(ram[2 * v2])];
LOBYTE(v40) = LOBYTE(variavel[(int)conversaoHexa(ram[2 * v2 + 1])]) ^ v40;
v41 = conversaoHexa(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v41, (unsigned int)variavel[v41]);
v42 = conversaoHexa(ram[2 * v39 + 1]);
v43 = conversaoHexa(ram[2 * v39]);
printf("Registrador [%X] <= R[%X] xor R[%X]\n", v41, v43, v42);
v44 = (unsigned int)(char)v40;
variavel[v41] = v44;
printf("Registrador [%X] = 0x%X\n", v41, v44);
result = 1LL;
break;
case 10:
v45 = conversaoHexa(ram[2 * v2]);
if ( v45 )
{
puts(aInstru);
exit(1);
}
v46 = v2;
v47 = conversaoHexa(ram[2 * v2 + 1]);
v48 = conversaoHexa(ram[2 * v2 - 1]);
v49 = variavel[v48];
printf("Registrador [%X] = 0x%X\n", v48, (unsigned int)(char)v49);
v50 = conversaoHexa(ram[2 * v46 + 1]);
printf("Registrador [%X] <= R[%X] >> %d\n", v48, v48, v50);
if ( v47 > 0 )
{
do
{
v51 = v49 & 1;
LOBYTE(v49) = (char)v49 >> 1;
if ( v51 )
LOBYTE(v49) = v49 | 0x80;
++v45;
}
while ( v45 != v47 );
}
v52 = (unsigned int)(char)v49;
variavel[v48] = v52;
printf("Registrador [%X] = 0x%X\n", v48, v52);
result = 1LL;
break;
case 11:
v53 = conversaoHexa(ram[2 * v2 - 1]);
if ( variavel[v53] == variavel[0] )
{
printf(
"Registrador [%X] == Registrador [0], go to 0x%c%c",
v53,
(unsigned int)ram[2 * v2],
(unsigned int)ram[2 * v2 + 1]);
*a2 = (char)getEndreco(ram[2 * v2], ram[2 * v2 + 1]) - 1;
}
else
{
printf("Registrador [%X] =/= Registrador [0], go to 0x%X", v53, (unsigned int)(v2 + 1));
}
result = 1LL;
break;
case 12:
if ( (unsigned int)conversaoHexa(ram[2 * v2 - 1])
|| (unsigned int)conversaoHexa(ram[2 * v2])
|| (unsigned int)conversaoHexa(ram[2 * v2 + 1]) )
{
puts(aInstru);
exit(1);
}
puts("Halt.");
*a2 = 256;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1, int *a2)
{
int v2; // ebx
unsigned int v3; // ebp
char v4; // al
char v5; // r12
__int64 v6; // rdx
__int64 result; // rax
unsigned int v8; // ebp
char v9; // r12
__int64 v10; // rdx
__int64 v11; // r13
int v12; // er14
char v13; // al
unsigned int v14; // er12
__int64 v15; // rbx
unsigned int v16; // eax
int v17; // er12
unsigned int v18; // ebp
unsigned int v19; // eax
__int64 v20; // rdx
__int64 v21; // r13
int v22; // er12
unsigned int v23; // ebx
unsigned int v24; // er15
unsigned int v25; // eax
__int64 v26; // rdx
__int64 v27; // r13
int v28; // ebp
unsigned int v29; // ebx
unsigned int v30; // er15
unsigned int v31; // eax
__int64 v32; // rdx
__int64 v33; // r13
int v34; // ebp
unsigned int v35; // ebx
unsigned int v36; // er15
unsigned int v37; // eax
__int64 v38; // rdx
__int64 v39; // r13
int v40; // ebp
unsigned int v41; // ebx
unsigned int v42; // er15
unsigned int v43; // eax
__int64 v44; // rdx
int v45; // ebp
__int64 v46; // r14
char v47; // r12
unsigned int v48; // er15
int v49; // ebx
unsigned int v50; // eax
char v51; // cl
__int64 v52; // rdx
unsigned int v53; // eax

v2 = *a2;
switch ( a1 )
{
case 1:
v3 = func2(ram[2 * v2 - 1]);
v4 = func4(ram[2 * v2], ram[2 * v2 + 1]);
v5 = func5(v4);
printf("Registrador [%X] = 0x%X\n", v3, (unsigned int)variavel[v3]);
printf("Registrador [%X] <= 0x[%c%c]\n", v3, (unsigned int)ram[2 * v2], (unsigned int)ram[2 * v2 + 1]);
v6 = (unsigned int)v5;
variavel[v3] = v6;
printf("Registrador [%X] = 0x%X\n", v3, v6);
result = 1LL;
break;
case 2:
v8 = func2(ram[2 * v2 - 1]);
v9 = func4(ram[2 * v2], ram[2 * v2 + 1]);
printf("Registrador [%X] = 0x%X\n", v8, (unsigned int)variavel[v8]);
printf("Registrador [%X] <= 0x%c%c\n", v8, (unsigned int)ram[2 * v2], (unsigned int)ram[2 * v2 + 1]);
v10 = (unsigned int)v9;
variavel[v8] = v10;
printf("Registrador [%X] = 0x%X\n", v8, v10);
result = 1LL;
break;
case 3:
v11 = v2 - 1;
v12 = variavel[(int)func2(ram[2 * v11 + 1])];
v13 = func4(ram[2 * v2], ram[2 * v2 + 1]);
v14 = v13;
v15 = v13;
printf(aMem, (unsigned int)v13, (unsigned int)ram[2 * v13], (unsigned int)ram[2 * v13 + 1]);
v16 = func2(ram[2 * v11 + 1]);
printf(aMem_0, v14, v16);
func7((char)v12, v14);
printf(aMem, v14, (unsigned int)ram[2 * v15], (unsigned int)ram[2 * v15 + 1]);
result = 1LL;
break;
case 4:
if ( (unsigned int)func2(ram[2 * v2 - 1]) )
{
puts(aInstru);
exit(1);
}
v17 = variavel[(int)func2(ram[2 * v2])];
v18 = func2(ram[2 * v2 + 1]);
printf("Registrador [%X] = 0x%X\n", v18, (unsigned int)variavel[v18]);
v19 = func2(ram[2 * v2]);
printf("Registrador [%X] <= R[%X]\n", v18, v19);
v20 = (unsigned int)(char)v17;
variavel[v18] = v20;
printf("Registrador [%X] = 0x%X\n", v18, v20);
result = 1LL;
break;
case 5:
v21 = v2;
v22 = func2(ram[2 * v2]);
LOBYTE(v22) = LOBYTE(variavel[v22]) + variavel[(int)func2(ram[2 * v2 + 1])];
v23 = func2(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v23, (unsigned int)variavel[v23]);
v24 = func2(ram[2 * v21 + 1]);
v25 = func2(ram[2 * v21]);
printf("Registrador [%X] <= R[%X] + R[%X]\n", v23, v25, v24);
v26 = (unsigned int)(char)v22;
variavel[v23] = v26;
printf("Registrador [%X] = 0x%X\n", v23, v26);
result = 1LL;
break;
case 6:
puts(aInstru_0);
result = 1LL;
break;
case 7:
v27 = v2;
v28 = variavel[(int)func2(ram[2 * v2])];
LOBYTE(v28) = LOBYTE(variavel[(int)conversaoHexa(ram[2 * v2 + 1])]) | v28;
v29 = func2(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v29, (unsigned int)variavel[v29]);
v30 = func2(ram[2 * v27 + 1]);
v31 = func2(ram[2 * v27]);
printf("Registrador [%X] <= R[%X] v R[%X]\n", v29, v31, v30);
v32 = (unsigned int)(char)v28;
variavel[v29] = v32;
printf("Registrador [%X] = 0x%X\n", v29, v32);
result = 1LL;
break;
case 8:
v33 = v2;
v34 = variavel[(int)func2(ram[2 * v2])];
LOBYTE(v34) = LOBYTE(variavel[(int)conversaoHexa(ram[2 * v2 + 1])]) & v34;
v35 = func2(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v35, (unsigned int)variavel[v35]);
v36 = func2(ram[2 * v33 + 1]);
v37 = func2(ram[2 * v33]);
printf("Registrador [%X] <= R[%X] ^ R[%X]\n", v35, v37, v36);
v38 = (unsigned int)(char)v34;
variavel[v35] = v38;
printf("Registrador [%X] = 0x%X\n", v35, v38);
result = 1LL;
break;
case 9:
v39 = v2;
v40 = variavel[(int)func2(ram[2 * v2])];
LOBYTE(v40) = LOBYTE(variavel[(int)conversaoHexa(ram[2 * v2 + 1])]) ^ v40;
v41 = func2(ram[2 * v2 - 1]);
printf("Registrador [%X] = 0x%X\n", v41, (unsigned int)variavel[v41]);
v42 = func2(ram[2 * v39 + 1]);
v43 = func2(ram[2 * v39]);
printf("Registrador [%X] <= R[%X] xor R[%X]\n", v41, v43, v42);
v44 = (unsigned int)(char)v40;
variavel[v41] = v44;
printf("Registrador [%X] = 0x%X\n", v41, v44);
result = 1LL;
break;
case 10:
v45 = func2(ram[2 * v2]);
if ( v45 )
{
puts(aInstru);
exit(1);
}
v46 = v2;
v47 = func2(ram[2 * v2 + 1]);
v48 = func2(ram[2 * v2 - 1]);
v49 = variavel[v48];
printf("Registrador [%X] = 0x%X\n", v48, (unsigned int)(char)v49);
v50 = func2(ram[2 * v46 + 1]);
printf("Registrador [%X] <= R[%X] >> %d\n", v48, v48, v50);
if ( v47 > 0 )
{
do
{
v51 = v49 & 1;
LOBYTE(v49) = (char)v49 >> 1;
if ( v51 )
LOBYTE(v49) = v49 | 0x80;
++v45;
}
while ( v45 != v47 );
}
v52 = (unsigned int)(char)v49;
variavel[v48] = v52;
printf("Registrador [%X] = 0x%X\n", v48, v52);
result = 1LL;
break;
case 11:
v53 = func2(ram[2 * v2 - 1]);
if ( variavel[v53] == variavel[0] )
{
printf(
"Registrador [%X] == Registrador [0], go to 0x%c%c",
v53,
(unsigned int)ram[2 * v2],
(unsigned int)ram[2 * v2 + 1]);
*a2 = (char)func4(ram[2 * v2], ram[2 * v2 + 1]) - 1;
}
else
{
printf("Registrador [%X] =/= Registrador [0], go to 0x%X", v53, (unsigned int)(v2 + 1));
}
result = 1LL;
break;
case 12:
if ( (unsigned int)func2(ram[2 * v2 - 1])
|| (unsigned int)func2(ram[2 * v2])
|| (unsigned int)func2(ram[2 * v2 + 1]) )
{
puts(aInstru);
exit(1);
}
puts("Halt.");
*a2 = 256;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int acao(char opcode, int *position){
 int i, indice,pos;
 char x, y, c, aux;
 pos = *position;
 switch(opcode){
  case 1: indice = conversaoHexa(ram[pos-1].valor[1]);
   x = leituraMem(getEndreco(ram[pos].valor[0], ram[pos].valor[1]));
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= 0x[%c%c]\n", indice, ram[pos].valor[0], ram[pos].valor[1]);
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 2: indice = conversaoHexa(ram[pos-1].valor[1]);
   x = getEndreco(ram[pos].valor[0], ram[pos].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= 0x%c%c\n", indice, ram[pos].valor[0], ram[pos].valor[1]);
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 3: indice = conversaoHexa(ram[pos-1].valor[1]);
   x = variavel.valor[indice];
   indice = getEndreco(ram[pos].valor[0], ram[pos].valor[1]);
   printf("Memória [%X] = 0x%c%c\n", indice, ram[indice].valor[0], ram[indice].valor[1]);
   printf("Memória [%X] <= R[%X]\n", indice, conversaoHexa(ram[pos-1].valor[1]));
   conversaoHToChar(x, indice);
   printf("Memória [%X] = 0x%c%c\n", indice, ram[indice].valor[0], ram[indice].valor[1]);
   break;
  case 4: if (!conversaoHexa(ram[pos-1].valor[1])){
    indice = conversaoHexa(ram[pos].valor[0]);
    x = variavel.valor[indice];
    indice = conversaoHexa(ram[pos].valor[1]);
    printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
    printf("Registrador [%X] <= R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]));
    variavel.valor[indice] = x;
    printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   } else {
    printf("Instrução não encontrada.\n\n");
    exit(1);
   }
   break;
  case 5: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   y = variavel.valor[indice];
   x = x + y;
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] + R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 6: printf("Instrução com ponto flutuante. Não abordada.\n");
   break;
  case 7: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   x = x | variavel.valor[indice];
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] v R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 8: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   x = x & variavel.valor[indice];
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] ^ R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 9: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   x = x ^ variavel.valor[indice];
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] xor R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 10: if (!conversaoHexa(ram[pos].valor[0])){
    y = conversaoHexa(ram[pos].valor[1]);
    i = 0;
    indice = conversaoHexa(ram[pos-1].valor[1]);
    c = variavel.valor[indice];
    printf("Registrador [%X] = 0x%X\n", indice, c);
    printf("Registrador [%X] <= R[%X] >> %d\n", indice, indice, conversaoHexa(ram[pos].valor[1]));
    while (i < y){
     aux = c & 1;
     c = c >> 1;
     if (aux == 1){
      c = c | 128;
     }
     i++;
    }
    variavel.valor[indice] = c;
    printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   } else {
    printf("Instrução não encontrada.\n\n");
    exit(1);
   }
   break;
  case 11: indice = conversaoHexa(ram[pos-1].valor[1]);
   if (variavel.valor[indice] == variavel.valor[0]){
    printf("Registrador [%X] == Registrador [0], go to 0x%c%c", indice, ram[pos].valor[0], ram[pos].valor[1]);
    x = getEndreco(ram[pos].valor[0], ram[pos].valor[1]);
    *position = x - 1;
   } else {
    printf("Registrador [%X] =/= Registrador [0], go to 0x%X", indice, pos+1);
   }
   break;
  case 12: if (!conversaoHexa(ram[pos-1].valor[1]) && !conversaoHexa(ram[pos].valor[0]) && !conversaoHexa(ram[pos].valor[1])){
    printf("Halt.\n");
    *position = 256;
   } else {
    printf("Instrução não encontrada.\n\n");
    exit(1);
   }
   break;
  default: return 0;
 }
 return 1;
}

canonical_original_code:
int acao(char opcode, int *position){
 int i; int indice; int pos;
 char x; char y; char c; char aux;
 pos = *position;
 switch(opcode){
  case 1: indice = conversaoHexa(ram[pos-1].valor[1]);
   x = leituraMem(getEndreco(ram[pos].valor[0], ram[pos].valor[1]));
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= 0x[%c%c]\n", indice, ram[pos].valor[0], ram[pos].valor[1]);
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 2: indice = conversaoHexa(ram[pos-1].valor[1]);
   x = getEndreco(ram[pos].valor[0], ram[pos].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= 0x%c%c\n", indice, ram[pos].valor[0], ram[pos].valor[1]);
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 3: indice = conversaoHexa(ram[pos-1].valor[1]);
   x = variavel.valor[indice];
   indice = getEndreco(ram[pos].valor[0], ram[pos].valor[1]);
   printf("Memória [%X] = 0x%c%c\n", indice, ram[indice].valor[0], ram[indice].valor[1]);
   printf("Memória [%X] <= R[%X]\n", indice, conversaoHexa(ram[pos-1].valor[1]));
   conversaoHToChar(x, indice);
   printf("Memória [%X] = 0x%c%c\n", indice, ram[indice].valor[0], ram[indice].valor[1]);
   break;
  case 4: if (!conversaoHexa(ram[pos-1].valor[1])){
    indice = conversaoHexa(ram[pos].valor[0]);
    x = variavel.valor[indice];
    indice = conversaoHexa(ram[pos].valor[1]);
    printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
    printf("Registrador [%X] <= R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]));
    variavel.valor[indice] = x;
    printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   } else {
    printf("Instrução não encontrada.\n\n");
    exit(1);
   }
   break;
  case 5: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   y = variavel.valor[indice];
   x = x + y;
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] + R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 6: printf("Instrução com ponto flutuante. Não abordada.\n");
   break;
  case 7: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   x = x | variavel.valor[indice];
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] v R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 8: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   x = x & variavel.valor[indice];
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] ^ R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 9: indice = conversaoHexa(ram[pos].valor[0]);
   x = variavel.valor[indice];
   indice = conversaoHexa(ram[pos].valor[1]);
   x = x ^ variavel.valor[indice];
   indice = conversaoHexa(ram[pos-1].valor[1]);
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   printf("Registrador [%X] <= R[%X] xor R[%X]\n", indice, conversaoHexa(ram[pos].valor[0]), conversaoHexa(ram[pos].valor[1]));
   variavel.valor[indice] = x;
   printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   break;
  case 10: if (!conversaoHexa(ram[pos].valor[0])){
    y = conversaoHexa(ram[pos].valor[1]);
    i = 0;
    indice = conversaoHexa(ram[pos-1].valor[1]);
    c = variavel.valor[indice];
    printf("Registrador [%X] = 0x%X\n", indice, c);
    printf("Registrador [%X] <= R[%X] >> %d\n", indice, indice, conversaoHexa(ram[pos].valor[1]));
    while (i < y){
     aux = c & 1;
     c = c >> 1;
     if (aux == 1){
      c = c | 128;
     }
     i++;
    }
    variavel.valor[indice] = c;
    printf("Registrador [%X] = 0x%X\n", indice, variavel.valor[indice]);
   } else {
    printf("Instrução não encontrada.\n\n");
    exit(1);
   }
   break;
  case 11: indice = conversaoHexa(ram[pos-1].valor[1]);
   if (variavel.valor[indice] == variavel.valor[0]){
    printf("Registrador [%X] == Registrador [0], go to 0x%c%c", indice, ram[pos].valor[0], ram[pos].valor[1]);
    x = getEndreco(ram[pos].valor[0], ram[pos].valor[1]);
    *position = x - 1;
   } else {
    printf("Registrador [%X] =/= Registrador [0], go to 0x%X", indice, pos+1);
   }
   break;
  case 12: if (!conversaoHexa(ram[pos-1].valor[1]) && !conversaoHexa(ram[pos].valor[0]) && !conversaoHexa(ram[pos].valor[1])){
    printf("Halt.\n");
    *position = 256;
   } else {
    printf("Instrução não encontrada.\n\n");
    exit(1);
   }
   break;
  default: return 0;
 }
 return 1;
}

variable_types: opcode char

variable_types:
position
int *

variable_types: indice int

variable_types: x char

variable_types: y char


execucao

repo: marlonsd/PCI-VirtualMachine

decompiled_code:
__int64 execucao()
{
char v0; // r13
int v1; // er14
unsigned int v3; // eax
char v4; // bl
unsigned int v5; // ebx
int v6; // eax
char v7; // [rsp+Bh] [rbp-2Dh] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = ram[0];
if ( !ram[0] )
return 1;
v1 = 0;
do
{
v8[0] = v1 + 1;
v3 = conversaoHexa(v0);
v4 = v3;
printf(
"-- %X%c%c%c\n",
v3,
(unsigned int)ram[2 * v1 + 1],
(unsigned int)ram[2 * v1 + 2],
(unsigned int)ram[2 * v1 + 3]);
v5 = acao(v4, v8);
if ( !v5 )
{
printf(aInstru_1);
return v5;
}
v6 = v8[0] + 1;
v8[0] = v6;
if ( v6 <= 255 )
v0 = ram[2 * v6];
_isoc99_scanf(&unk_104E, &v7);
putchar(10);
v1 = v8[0];
}
while ( v8[0] <= 255 && v0 );
return 1;
}

canonical_decompiled_code:
__int64 func9()
{
char v0; // r13
int v1; // er14
unsigned int v3; // eax
char v4; // bl
unsigned int v5; // ebx
int v6; // eax
char v7; // [rsp+Bh] [rbp-2Dh] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = ram[0];
if ( !ram[0] )
return 1;
v1 = 0;
do
{
v8[0] = v1 + 1;
v3 = func2(v0);
v4 = v3;
printf(
"-- %X%c%c%c\n",
v3,
(unsigned int)ram[2 * v1 + 1],
(unsigned int)ram[2 * v1 + 2],
(unsigned int)ram[2 * v1 + 3]);
v5 = func8(v4, v8);
if ( !v5 )
{
printf(aInstru_1);
return v5;
}
v6 = v8[0] + 1;
v8[0] = v6;
if ( v6 <= 255 )
v0 = ram[2 * v6];
_isoc99_scanf(&unk_104E, &v7);
putchar(10);
v1 = v8[0];
}
while ( v8[0] <= 255 && v0 );
return 1;
}

original_code:
int execucao(){
 int i, operacao;
 char aux, c;
 i = 0;
 aux = ram[i].valor[0];
 while ((i < 256) && (aux != '\0')){
  i++;
  operacao = conversaoHexa(aux);
  printf("-- %X%c%c%c\n", operacao, ram[i-1].valor[1], ram[i].valor[0], ram[i].valor[1]);
  if (!acao(operacao, &i)){
   printf("Instrução não existe.");
   return 0;
  }
  i++;
  if (i < 256){
   aux = ram[i].valor[0];
  }
  scanf("%c", &c);
  printf("\n");
 }
 return 1;
}

canonical_original_code:
int execucao(){
 int i; int operacao;
 char aux; char c;
 i = 0;
 aux = ram[i].valor[0];
 while ((i < 256) && (aux != '\0')){
  i++;
  operacao = conversaoHexa(aux);
  printf("-- %X%c%c%c\n", operacao, ram[i-1].valor[1], ram[i].valor[0], ram[i].valor[1]);
  if (!acao(operacao, &i)){
   printf("Instrução não existe.");
   return 0;
  }
  i++;
  if (i < 256){
   aux = ram[i].valor[0];
  }
  scanf("%c", &c);
  printf("\n");
 }
 return 1;
}

variable_types: i int

variable_types: operacao int

variable_types: aux char

variable_types: c char

return_type: int


printRegistradores

decompiled_code:
int printRegistradores()
{
__int64 i; // rbx

puts("\n-- Registradores:");
for ( i = 0LL; i != 16; ++i )
printf("\tRegistrador[%X] = 0x%X\n", (unsigned int)i, (unsigned int)variavel[i]);
return putchar(10);
}

canonical_decompiled_code:
int func10()
{
__int64 i; // rbx

puts("\n-- Registradores:");
for ( i = 0LL; i != 16; ++i )
printf("\tRegistrador[%X] = 0x%X\n", (unsigned int)i, (unsigned int)variavel[i]);
return putchar(10);
}

original_code:
void printRegistradores(){
 int i;
 i = 0;
 printf("\n-- Registradores:\n");
 while (i < 16) {
  printf("\tRegistrador[%X] = 0x%X\n", i, variavel.valor[i]);
  i++;
 }
 printf("\n");
}

return_type: void


main

canonical_name: main

repo: marmolak/badass

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

dlerror();
v3 = dlopen("libbadass.so", 1);
if ( v3 )
{
dlclose(v3);
puts("Doing stuff...");
sleep(6u);
result = 0;
}
else
{
v5 = dlerror();
printf("Unable to open libbadass.so. Error: %s\n", v5);
result = 1;
}
return result;
}

original_code:
int main (int argc, char **argv)
{
    (void) argc; (void) (argv);
    dlerror ();
    void *handle = dlopen ("libbadass.so", 0x00001);
    if ( handle == ((void *)0) ) {
        printf ("Unable to open " "libbadass.so" ". Error: %s\n", dlerror());
        return 1;
    }
    dlclose (handle);
    printf ("Doing stuff...\n");
    sleep (timeout);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    (void) argc; (void) (argv);
    dlerror ();
    void *handle = dlopen ("libbadass.so", 0x00001);
    if ( handle == ((void *)0) ) {
        printf ("Unable to open " "libbadass.so" ". Error: %s\n", dlerror());
        return 1;
    }
    dlclose (handle);
    printf ("Doing stuff...\n");
    sleep (timeout);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
handle
void *


decompiled_code:
void *__fastcall just_run(void *a1)
{
sleep(5u);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1)
{
sleep(5u);
return 0LL;
}

original_code:
static void *just_run (void *data)
{
    (void) data;
    sleep (timeout);
    x = 100;
    return ((void *)0);
}

canonical_original_code:
static void *just_run(void *data)
{
    (void) data;
    sleep (timeout);
    x = 100;
    return ((void *)0);
}

variable_types:
data
void *

return_type: void *


initialize

decompiled_code:
int initialize()
{
return pthread_create(&th, 0LL, just_run, 0LL);
}

canonical_decompiled_code:
int func7()
{
return pthread_create(&th, 0LL, just_run, 0LL);
}

original_code:
void initialize (void)
{
    pthread_create (&th, ((void *)0), &just_run, ((void *)0));
}

canonical_original_code:
void initialize()
{
    pthread_create (&th, ((void *)0), &just_run, ((void *)0));
}


yyerror

repo: marrony/bison-flex

decompiled_code:
int __fastcall yyerror(__int64 a1, __int64 a2, const char *a3)
{
return printf("\n*** Error: %s\n", a3);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, const char *a3)
{
return printf("\n*** Error: %s\n", a3);
}

original_code:
void yyerror(yyscan_t scanner, int* value, const char* errmsg) {
    printf("\n*** Error: %s\n", errmsg);
}

canonical_original_code:
void yyerror(void *scanner, int *value, char *errmsg) {
    printf("\n*** Error: %s\n", errmsg);
}

variable_types:
scanner
void *

variable_types:
value
int *

variable_types:
errmsg
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+4h] [rbp-14h] BYREF
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v4 = 0;
yylex_init(&v5, argv, envp);
if ( !(unsigned int)yyparse(v5, &v4) )
printf("result: %d\n", v4);
yylex_destroy(v5);
return 0;
}

original_code:
int main(int argc, char** argv) {
    yyscan_t scanner;
    int value = 0;
    yylex_init(&scanner);
    if(!yyparse(scanner, &value))
        printf("result: %d\n", value);
    yylex_destroy(scanner);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    void *scanner;
    int value = 0;
    yylex_init(&scanner);
    if(!yyparse(scanner, &value))
        printf("result: %d\n", value);
    yylex_destroy(scanner);
    return 0;
}

variable_types: value int


decompiled_code:
__int64 __fastcall yysyntax_error(unsigned __int64 *a1, const char **a2, __int16 *a3, int a4)
{
char *v6; // r12
_BYTE *v7; // rax
__int64 v8; // r13
__int64 v9; // rbx
int v10; // er12
int v11; // ebp
char *v12; // rsi
_BYTE *v13; // rax
bool v14; // cf
_BYTE *v15; // rax
const char *v16; // rbx
size_t v17; // rax
unsigned int v18; // edx
unsigned __int64 v19; // rax
char *v20; // r12
char v21; // al
int v22; // edx
int v23; // er13
_BYTE *v25; // [rsp+8h] [rbp-80h]
_BYTE *v26; // [rsp+10h] [rbp-78h]
__int64 v28[13]; // [rsp+20h] [rbp-68h]

v6 = yytname[a4];
v7 = yytnamerr(0LL, v6);
v26 = v7;
if ( a4 == -2 )
{
v11 = 0;
v16 = "syntax error";
}
else
{
LOBYTE(v8) = yypact[*a3];
v28[0] = (__int64)v6;
if ( (_BYTE)v8 == 0xFB )
{
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
LODWORD(v9) = -(char)v8;
if ( (v8 & 0x80u) == 0LL )
LODWORD(v9) = 0;
v10 = 15 - (char)v8;
if ( v10 > 10 )
v10 = 10;
if ( (int)v9 >= v10 )
{
LABEL_41:
v25 = v26;
LABEL_42:
v26 = v25;
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
v9 = (int)v9;
v25 = v7;
v11 = 1;
v8 = (char)v8;
do
{
if ( (unsigned __int8)yycheck[v8 + v9] == (_DWORD)v9 && (_DWORD)v9 != 1 )
{
if ( v11 == 5 )
goto LABEL_41;
v12 = yytname[v9];
v28[v11] = (__int64)v12;
v13 = yytnamerr(0LL, v12);
v14 = __CFADD__(v25, v13);
v15 = &v13[(_QWORD)v25];
if ( v14 )
return 2;
++v11;
v25 = v15;
}
++v9;
}
while ( v10 > (int)v9 );
switch ( v11 )
{
case 1:
goto LABEL_42;
case 2:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s";
break;
case 3:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s";
break;
case 4:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s";
break;
case 5:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s or %s";
break;
default:
v26 = v25;
v16 = "syntax error";
break;
}
}
}
}
v17 = strlen(v16);
v18 = 2;
v14 = __CFADD__(v26, v17);
v19 = (unsigned __int64)&v26[v17];
if ( !v14 )
{
if ( *a1 < v19 )
{
if ( 2 * v19 < v19 )
*a1 = -1LL;
else
*a1 = 2 * v19;
v18 = 1;
}
else
{
v20 = (char *)*a2;
v21 = *v16;
**a2 = *v16;
if ( v21 )
{
v22 = 0;
do
{
if ( v21 == 37 && v16[1] == 115 && v11 > v22 )
{
v23 = v22 + 1;
v20 = &v20[(_QWORD)yytnamerr(v20, (char *)v28[v22])];
v16 += 2;
v22 = v23;
}
else
{
++v20;
++v16;
}
v21 = *v16;
*v20 = *v16;
}
while ( v21 );
v18 = 0;
}
else
{
v18 = 0;
}
}
}
return v18;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, const char **a2, __int16 *a3, int a4)
{
char *v6; // r12
_BYTE *v7; // rax
__int64 v8; // r13
__int64 v9; // rbx
int v10; // er12
int v11; // ebp
char *v12; // rsi
_BYTE *v13; // rax
bool v14; // cf
_BYTE *v15; // rax
const char *v16; // rbx
size_t v17; // rax
unsigned int v18; // edx
unsigned __int64 v19; // rax
char *v20; // r12
char v21; // al
int v22; // edx
int v23; // er13
_BYTE *v25; // [rsp+8h] [rbp-80h]
_BYTE *v26; // [rsp+10h] [rbp-78h]
__int64 v28[13]; // [rsp+20h] [rbp-68h]

v6 = yytname[a4];
v7 = yytnamerr(0LL, v6);
v26 = v7;
if ( a4 == -2 )
{
v11 = 0;
v16 = "syntax error";
}
else
{
LOBYTE(v8) = yypact[*a3];
v28[0] = (__int64)v6;
if ( (_BYTE)v8 == 0xFB )
{
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
LODWORD(v9) = -(char)v8;
if ( (v8 & 0x80u) == 0LL )
LODWORD(v9) = 0;
v10 = 15 - (char)v8;
if ( v10 > 10 )
v10 = 10;
if ( (int)v9 >= v10 )
{
LABEL_41:
v25 = v26;
LABEL_42:
v26 = v25;
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
v9 = (int)v9;
v25 = v7;
v11 = 1;
v8 = (char)v8;
do
{
if ( (unsigned __int8)yycheck[v8 + v9] == (_DWORD)v9 && (_DWORD)v9 != 1 )
{
if ( v11 == 5 )
goto LABEL_41;
v12 = yytname[v9];
v28[v11] = (__int64)v12;
v13 = yytnamerr(0LL, v12);
v14 = __CFADD__(v25, v13);
v15 = &v13[(_QWORD)v25];
if ( v14 )
return 2;
++v11;
v25 = v15;
}
++v9;
}
while ( v10 > (int)v9 );
switch ( v11 )
{
case 1:
goto LABEL_42;
case 2:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s";
break;
case 3:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s";
break;
case 4:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s";
break;
case 5:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s or %s";
break;
default:
v26 = v25;
v16 = "syntax error";
break;
}
}
}
}
v17 = strlen(v16);
v18 = 2;
v14 = __CFADD__(v26, v17);
v19 = (unsigned __int64)&v26[v17];
if ( !v14 )
{
if ( *a1 < v19 )
{
if ( 2 * v19 < v19 )
*a1 = -1LL;
else
*a1 = 2 * v19;
v18 = 1;
}
else
{
v20 = (char *)*a2;
v21 = *v16;
**a2 = *v16;
if ( v21 )
{
v22 = 0;
do
{
if ( v21 == 37 && v16[1] == 115 && v11 > v22 )
{
v23 = v22 + 1;
v20 = &v20[(_QWORD)yytnamerr(v20, (char *)v28[v22])];
v16 += 2;
v22 = v23;
}
else
{
++v20;
++v16;
}
v21 = *v16;
*v20 = *v16;
}
while ( v21 );
v18 = 0;
}
else
{
v18 = 0;
}
}
}
return v18;
}

original_code:
static int
yysyntax_error (long unsigned int *yymsg_alloc, char **yymsg,
                yytype_int16 *yyssp, int yytoken)
{
  long unsigned int yysize0 = yytnamerr (((void*)0), yytname[yytoken]);
  long unsigned int yysize = yysize0;
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  const char *yyformat = ((void*)0);
  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  int yycount = 0;
  if (yytoken != (-2))
    {
      int yyn = yypact[*yyssp];
      yyarg[yycount++] = yytname[yytoken];
      if (!(!!((yyn) == (-5))))
        {
          int yyxbegin = yyn < 0 ? -yyn : 0;
          int yychecklim = 14 - yyn + 1;
          int yyxend = yychecklim < 10 ? yychecklim : 10;
          int yyx;
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != 1
                && !0)
              {
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
                  {
                    yycount = 1;
                    yysize = yysize0;
                    break;
                  }
                yyarg[yycount++] = yytname[yyx];
                {
                  long unsigned int yysize1 = yysize + yytnamerr (((void*)0), yytname[yyx]);
                  if (yysize <= yysize1 && yysize1 <= ((long unsigned int) -1))
                    yysize = yysize1;
                  else
                    return 2;
                }
              }
        }
    }
  switch (yycount)
    {
    default:
      case 0: yyformat = "syntax error"; break;
      case 1: yyformat = "syntax error, unexpected %s"; break;
      case 2: yyformat = "syntax error, unexpected %s, expecting %s"; break;
      case 3: yyformat = "syntax error, unexpected %s, expecting %s or %s"; break;
      case 4: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s"; break;
      case 5: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s or %s"; break;
    }
  {
    long unsigned int yysize1 = yysize + strlen (yyformat);
    if (yysize <= yysize1 && yysize1 <= ((long unsigned int) -1))
      yysize = yysize1;
    else
      return 2;
  }
  if (*yymsg_alloc < yysize)
    {
      *yymsg_alloc = 2 * yysize;
      if (! (yysize <= *yymsg_alloc
             && *yymsg_alloc <= ((long unsigned int) -1)))
        *yymsg_alloc = ((long unsigned int) -1);
      return 1;
    }
  {
    char *yyp = *yymsg;
    int yyi = 0;
    while ((*yyp = *yyformat) != '\0')
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
        {
          yyp += yytnamerr (yyp, yyarg[yyi++]);
          yyformat += 2;
        }
      else
        {
          yyp++;
          yyformat++;
        }
  }
  return 0;
}

canonical_original_code:
static int yysyntax_error(unsigned long *yymsg_alloc, char **yymsg, short *yyssp, int yytoken)
{
  unsigned long yysize0 = yytnamerr (((void*)0), yytname[yytoken]);
  unsigned long yysize = yysize0;
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  char *yyformat = ((void*)0);
  char *yyarg[-1];
  int yycount = 0;
  if (yytoken != (-2))
    {
      int yyn = yypact[*yyssp];
      yyarg[yycount++] = yytname[yytoken];
      if (!(!!((yyn) == (-5))))
        {
          int yyxbegin = yyn < 0 ? -yyn : 0;
          int yychecklim = 14 - yyn + 1;
          int yyxend = yychecklim < 10 ? yychecklim : 10;
          int yyx;
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != 1
                && !0)
              {
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
                  {
                    yycount = 1;
                    yysize = yysize0;
                    break;
                  }
                yyarg[yycount++] = yytname[yyx];
                {
                  unsigned long yysize1 = yysize + yytnamerr (((void*)0), yytname[yyx]);
                  if (yysize <= yysize1 && yysize1 <= ((unsigned long) -1))
                    yysize = yysize1;
                  else
                    return 2;
                }
              }
        }
    }
  switch (yycount)
    {
    default:
      case 0: yyformat = "syntax error"; break;
      case 1: yyformat = "syntax error, unexpected %s"; break;
      case 2: yyformat = "syntax error, unexpected %s, expecting %s"; break;
      case 3: yyformat = "syntax error, unexpected %s, expecting %s or %s"; break;
      case 4: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s"; break;
      case 5: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s or %s"; break;
    }
  {
    unsigned long yysize1 = yysize + strlen (yyformat);
    if (yysize <= yysize1 && yysize1 <= ((unsigned long) -1))
      yysize = yysize1;
    else
      return 2;
  }
  if (*yymsg_alloc < yysize)
    {
      *yymsg_alloc = 2 * yysize;
      if (! (yysize <= *yymsg_alloc
             && *yymsg_alloc <= ((unsigned long) -1)))
        *yymsg_alloc = ((unsigned long) -1);
      return 1;
    }
  {
    char *yyp = *yymsg;
    int yyi = 0;
    while ((*yyp = *yyformat) != '\0')
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
        {
          yyp += yytnamerr (yyp, yyarg[yyi++]);
          yyformat += 2;
        }
      else
        {
          yyp++;
          yyformat++;
        }
  }
  return 0;
}

variable_types:
yymsg
char **

variable_types:
yyssp
short *

variable_types: yytoken int

variable_types:
yysize
unsigned long

variable_types:
yyformat
char *

variable_types:
yyarg
char *[-1]

variable_types: yycount int

variable_types: yyn int

variable_types: yyxbegin int

variable_types: yychecklim int

variable_types: yyxend int

variable_types: yyx int

variable_types:
yyp
char *

variable_types: yyi int


yyparse

original_code:
int
yyparse (yyscan_t* scanner, int *value)
{
int yychar;

int yylval ;
    int yynerrs;
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    int yyvsa[200];
    int *yyvs;
    int *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  int yyval;
  char yymsgbuf[128];
  char *yymsg = yymsgbuf;
  long unsigned int yymsg_alloc = sizeof yymsgbuf;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (int)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 8)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-5))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex (&yylval, scanner);
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 258 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 14 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 2:
    { *value = yyvsp[0]; }
    break;
  case 3:
    { yyval = yyvsp[-2] + yyvsp[0]; }
    break;
  case 4:
    { yyval = yyvsp[-2] - yyvsp[0]; }
    break;
  case 5:
    { yyval = yyvsp[0]; }
    break;
  case 6:
    { yyval = yyvsp[-2] * yyvsp[0]; }
    break;
  case 7:
    { yyval = yyvsp[-2] / yyvsp[0]; }
    break;
  case 8:
    { yyval = yyvsp[0]; }
    break;
  case 9:
    { yyval = yyvsp[0]; }
    break;
  case 10:
    { yyval = yyvsp[-1]; }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 10;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 14 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 258 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      {
        char const *yymsgp = "syntax error";
        int yysyntax_error_status;
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
        if (yysyntax_error_status == 0)
          yymsgp = yymsg;
        else if (yysyntax_error_status == 1)
          {
            if (yymsg != yymsgbuf)
              free (yymsg);
            yymsg = (char *) malloc (yymsg_alloc);
            if (!yymsg)
              {
                yymsg = yymsgbuf;
                yymsg_alloc = sizeof yymsgbuf;
                yysyntax_error_status = 2;
              }
            else
              {
                yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
                yymsgp = yymsg;
              }
          }
        yyerror (scanner, value, yymsgp);
        if (yysyntax_error_status == 2)
          goto yyexhaustedlab;
      }
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval, scanner, value);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-5))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 14 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp, scanner, value);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror (scanner, value, "memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 258 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval, scanner, value);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp, scanner, value);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  if (yymsg != yymsgbuf)
    free (yymsg);
  return yyresult;
}

canonical_original_code:
int yyparse(void **scanner, int *value)
{
int yychar;

int yylval;
    int yynerrs;
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    int yyvsa[200];
    int *yyvs;
    int *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  int yyval;
  char yymsgbuf[128];
  char *yymsg = yymsgbuf;
  unsigned long yymsg_alloc = sizeof yymsgbuf;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (int)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 8)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-5))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex (&yylval, scanner);
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 258 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 14 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 2:
    { *value = yyvsp[0]; }
    break;
  case 3:
    { yyval = yyvsp[-2] + yyvsp[0]; }
    break;
  case 4:
    { yyval = yyvsp[-2] - yyvsp[0]; }
    break;
  case 5:
    { yyval = yyvsp[0]; }
    break;
  case 6:
    { yyval = yyvsp[-2] * yyvsp[0]; }
    break;
  case 7:
    { yyval = yyvsp[-2] / yyvsp[0]; }
    break;
  case 8:
    { yyval = yyvsp[0]; }
    break;
  case 9:
    { yyval = yyvsp[0]; }
    break;
  case 10:
    { yyval = yyvsp[-1]; }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 10;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 14 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 258 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      {
        char *yymsgp = "syntax error";
        int yysyntax_error_status;
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
        if (yysyntax_error_status == 0)
          yymsgp = yymsg;
        else if (yysyntax_error_status == 1)
          {
            if (yymsg != yymsgbuf)
              free (yymsg);
            yymsg = (char *) malloc (yymsg_alloc);
            if (!yymsg)
              {
                yymsg = yymsgbuf;
                yymsg_alloc = sizeof yymsgbuf;
                yysyntax_error_status = 2;
              }
            else
              {
                yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
                yymsgp = yymsg;
              }
          }
        yyerror (scanner, value, yymsgp);
        if (yysyntax_error_status == 2)
          goto yyexhaustedlab;
      }
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval, scanner, value);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-5))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 14 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp, scanner, value);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror (scanner, value, "memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 258 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval, scanner, value);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp, scanner, value);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  if (yymsg != yymsgbuf)
    free (yymsg);
  return yyresult;
}

variable_types:
scanner
void **

variable_types:
value
int *

variable_types: yychar int

variable_types: yylval int

variable_types: yynerrs int

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyvsa
int [200]

variable_types:
yyvs
int *

variable_types:
yyvsp
int *

variable_types:
yystacksize
unsigned long

variable_types: yyresult int

variable_types: yyval int

variable_types:
yymsgbuf
char [128]

variable_types:
yymsg
char *

variable_types: yylen int

variable_types: union yyalloc { short yyss_alloc; int yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types:
yymsgp
char *


Bwrite

original_code:
long
Bwrite(Biobuf *bp, void *ap, long count)
{
 long c;
 unsigned char *p;
 int i, n, oc;
 p = ap;
 c = count;
 oc = bp->ocount;
 while(c > 0) {
  n = -oc;
  if(n > c)
   n = c;
  if(n == 0) {
   if(bp->state != Bwactive)
    return Beof;
   i = p9write(bp->fid, bp->bbuf, bp->bsize);
   if(i != bp->bsize) {
    bp->state = Binactive;
    return Beof;
   }
   bp->offset += i;
   oc = -bp->bsize;
   continue;
  }
  memmove(bp->ebuf+oc, p, n);
  oc += n;
  c -= n;
  p += n;
 }
 bp->ocount = oc;
 return count-c;
}

canonical_original_code:
long Bwrite(struct Biobuf *bp, void *ap, long count)
{
 long c;
 unsigned char *p;
 int i; int n; int oc;
 p = ap;
 c = count;
 oc = bp->ocount;
 while(c > 0) {
  n = -oc;
  if(n > c)
   n = c;
  if(n == 0) {
   if(bp->state != Bwactive)
    return Beof;
   i = p9write(bp->fid, bp->bbuf, bp->bsize);
   if(i != bp->bsize) {
    bp->state = Binactive;
    return Beof;
   }
   bp->offset += i;
   oc = -bp->bsize;
   continue;
  }
  memmove(bp->ebuf+oc, p, n);
  oc += n;
  c -= n;
  p += n;
 }
 bp->ocount = oc;
 return count-c;
}

variable_types: struct Biobuf { int icount; int ocount; int rdline; int runesize; int state; int fid; int flag; long long offset; int bsize; unsigned char *bbuf; unsigned char *ebuf; unsigned char *gbuf; unsigned char b[-1]; } *

variable_types:
ap
void *

variable_types: count long

variable_types: c long

variable_types:
p
unsigned char *

variable_types: i int

variable_types: n int

variable_types: oc int

return_type: long


delarray

decompiled_code:
__int64 __fastcall delarray(__int64 a1, int a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = v2;
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = v2;
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = result;
return result;
}

original_code:
static void
delarray(_Altarray *a, int i)
{
 --a->n;
 a->a[i] = a->a[a->n];
}

canonical_original_code:
static void delarray(struct _Altarray *a, int i)
{
 --a->n;
 a->a[i] = a->a[a->n];
}

variable_types: struct _Altarray { struct Alt { struct Channel { unsigned int bufsize; unsigned int elemsize; unsigned char *buf; unsigned int nbuf; unsigned int off; struct _Altarray asend; struct _Altarray arecv; char *name; } *c; void *v; unsigned int op; struct _Thread { struct _Thread *next; struct _Thread *prev; struct _Thread *allnext; struct _Thread *allprev; struct Context { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; } context; void (*startfn)(void *); void *startarg; unsigned int id; unsigned char *stk; unsigned int stksize; int exiting; struct Proc { struct Proc *next; struct Proc *prev; char msg[128]; int osprocid; struct Lock { int held; } lock; int nswitch; struct _Thread *thread; struct _Thread *pinthread; struct _Threadlist { struct _Thread *head; struct _Thread *tail; } runqueue; struct _Threadlist idlequeue; struct _Threadlist allthreads; unsigned int nthread; unsigned int sysproc; struct _Procrendez { struct Lock *l; int asleep; int pid; } runrend; struct Context schedcontext; void *udata; struct Jmp { long b[-1]; } sigjmp; int mainproc; } *proc; char name[256]; char state[256]; void *udata; struct Alt *chanalt; } *thread; } **a; unsigned int n; unsigned int m; } *

user_defined_types: struct _Altarray { struct Alt **a; unsigned int n; unsigned int m; }

user_defined_types: struct Alt { struct Channel *c; void *v; unsigned int op; struct _Thread *thread; }

user_defined_types: struct _Thread { struct _Thread *next; struct _Thread *prev; struct _Thread *allnext; struct _Thread *allprev; struct Context context; void (*startfn)(void *); void *startarg; unsigned int id; unsigned char *stk; unsigned int stksize; int exiting; struct Proc *proc; char name[256]; char state[256]; void *udata; struct Alt *chanalt; }

user_defined_types: struct Context { struct ucontext_t uc; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct Proc { struct Proc *next; struct Proc *prev; char msg[128]; int osprocid; struct Lock lock; int nswitch; struct _Thread *thread; struct _Thread *pinthread; struct _Threadlist runqueue; struct _Threadlist idlequeue; struct _Threadlist allthreads; unsigned int nthread; unsigned int sysproc; struct _Procrendez runrend; struct Context schedcontext; void *udata; struct Jmp sigjmp; int mainproc; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


chanarray

decompiled_code:
__int64 __fastcall chanarray(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdi

result = a1 + 24;
if ( a2 != 1 )
{
v3 = a1 + 40;
result = 0LL;
if ( a2 == 2 )
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdi

result = a1 + 24;
if ( a2 != 1 )
{
v3 = a1 + 40;
result = 0LL;
if ( a2 == 2 )
result = v3;
}
return result;
}

original_code:
static _Altarray*
chanarray(Channel *c, uint op)
{
 switch(op){
 default:
  return ((void*)0);
 case CHANSND:
  return &c->asend;
 case CHANRCV:
  return &c->arecv;
 }
}

canonical_original_code:
static struct _Altarray *chanarray(struct Channel *c, unsigned int op)
{
 switch(op){
 default:
  return ((void *)0);
 case CHANSND:
  return &c->asend;
 case CHANRCV:
  return &c->arecv;
 }
}

variable_types:
c
struct Channel *

variable_types:
op
unsigned int

return_type: struct _Altarray { struct Alt { struct Channel { unsigned int bufsize; unsigned int elemsize; unsigned char *buf; unsigned int nbuf; unsigned int off; struct _Altarray asend; struct _Altarray arecv; char *name; } *c; void *v; unsigned int op; struct _Thread { struct _Thread *next; struct _Thread *prev; struct _Thread *allnext; struct _Thread *allprev; struct Context { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; } context; void (*startfn)(void *); void *startarg; unsigned int id; unsigned char *stk; unsigned int stksize; int exiting; struct Proc { struct Proc *next; struct Proc *prev; char msg[128]; int osprocid; struct Lock { int held; } lock; int nswitch; struct _Thread *thread; struct _Thread *pinthread; struct _Threadlist { struct _Thread *head; struct _Thread *tail; } runqueue; struct _Threadlist idlequeue; struct _Threadlist allthreads; unsigned int nthread; unsigned int sysproc; struct _Procrendez { struct Lock *l; int asleep; int pid; } runrend; struct Context schedcontext; void *udata; struct Jmp { long b[-1]; } sigjmp; int mainproc; } *proc; char name[256]; char state[256]; void *udata; struct Alt *chanalt; } *thread; } **a; unsigned int n; unsigned int m; } *


altdequeue

decompiled_code:
__int64 __fastcall altdequeue(__int64 a1)
{
unsigned int v2; // ebp
__int64 v3; // rax
__int64 v4; // rdi
int v5; // edx
__int64 v6; // rcx
__int64 v7; // rax

v2 = *(_DWORD *)(a1 + 16);
v3 = chanarray(*(_QWORD *)a1, v2);
if ( !v3 )
{
fprint(2LL, "bad use of altdequeue op=%d\n", v2);
abort();
}
v4 = v3;
v5 = *(_DWORD *)(v3 + 8);
if ( !v5 )
{
LABEL_6:
fprint(2LL, "cannot find self in altdq\n");
abort();
}
v6 = *(_QWORD *)v3;
v7 = 0LL;
while ( *(_QWORD *)(v6 + 8 * v7) != a1 )
{
if ( ++v7 == v5 )
goto LABEL_6;
}
return delarray(v4, v7);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v2; // ebp
__int64 v3; // rax
__int64 v4; // rdi
int v5; // edx
__int64 v6; // rcx
__int64 v7; // rax

v2 = *(_DWORD *)(a1 + 16);
v3 = func1(*(_QWORD *)a1, v2);
if ( !v3 )
{
fprint(2LL, "bad use of altdequeue op=%d\n", v2);
abort();
}
v4 = v3;
v5 = *(_DWORD *)(v3 + 8);
if ( !v5 )
{
LABEL_6:
fprint(2LL, "cannot find self in altdq\n");
abort();
}
v6 = *(_QWORD *)v3;
v7 = 0LL;
while ( *(_QWORD *)(v6 + 8 * v7) != a1 )
{
if ( ++v7 == v5 )
goto LABEL_6;
}
return func0(v4, v7);
}

original_code:
static void
altdequeue(Alt *a)
{
 int i;
 _Altarray *ar;
 ar = chanarray(a->c, a->op);
 if(ar == ((void*)0)){
  fprint(2, "bad use of altdequeue op=%d\n", a->op);
  abort();
 }
 for(i=0; i<ar->n; i++)
  if(ar->a[i] == a){
   delarray(ar, i);
   return;
  }
 fprint(2, "cannot find self in altdq\n");
 abort();
}

canonical_original_code:
static void altdequeue(struct Alt *a)
{
 int i;
 struct _Altarray *ar;
 ar = chanarray(a->c, a->op);
 if(ar == ((void *)0)){
  fprint(2, "bad use of altdequeue op=%d\n", a->op);
  abort();
 }
 for(i=0; i<ar->n; i++)
  if(ar->a[i] == a){
   delarray(ar, i);
   return;
  }
 fprint(2, "cannot find self in altdq\n");
 abort();
}

variable_types: struct Alt { struct Channel { unsigned int bufsize; unsigned int elemsize; unsigned char *buf; unsigned int nbuf; unsigned int off; struct _Altarray { struct Alt **a; unsigned int n; unsigned int m; } asend; struct _Altarray arecv; char *name; } *c; void *v; unsigned int op; struct _Thread { struct _Thread *next; struct _Thread *prev; struct _Thread *allnext; struct _Thread *allprev; struct Context { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; } context; void (*startfn)(void *); void *startarg; unsigned int id; unsigned char *stk; unsigned int stksize; int exiting; struct Proc { struct Proc *next; struct Proc *prev; char msg[128]; int osprocid; struct Lock { int held; } lock; int nswitch; struct _Thread *thread; struct _Thread *pinthread; struct _Threadlist { struct _Thread *head; struct _Thread *tail; } runqueue; struct _Threadlist idlequeue; struct _Threadlist allthreads; unsigned int nthread; unsigned int sysproc; struct _Procrendez { struct Lock *l; int asleep; int pid; } runrend; struct Context schedcontext; void *udata; struct Jmp { long b[-1]; } sigjmp; int mainproc; } *proc; char name[256]; char state[256]; void *udata; struct Alt *chanalt; } *thread; } *

user_defined_types: struct Channel { unsigned int bufsize; unsigned int elemsize; unsigned char *buf; unsigned int nbuf; unsigned int off; struct _Altarray asend; struct _Altarray arecv; char *name; }


altalldequeue

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

v1 = a1;
for ( result = *(unsigned int *)(a1 + 16); (result & 0xFFFFFFFB) != 0; result = *(unsigned int *)(v1 + 16) )
{
if ( (_DWORD)result != 3 )
altdequeue(v1);
v1 += 32LL;
}
return result;
}

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

v1 = a1;
for ( result = *(unsigned int *)(a1 + 16); (result & 0xFFFFFFFB) != 0; result = *(unsigned int *)(v1 + 16) )
{
if ( (_DWORD)result != 3 )
func3(v1);
v1 += 32LL;
}
return result;
}

original_code:
static void
altalldequeue(Alt *a)
{
 int i;
 for(i=0; a[i].op!=CHANEND && a[i].op!=CHANNOBLK; i++)
  if(a[i].op != CHANNOP)
   altdequeue(&a[i]);
}

canonical_original_code:
static void altalldequeue(struct Alt *a)
{
 int i;
 for(i=0; a[i].op!=CHANEND && a[i].op!=CHANNOBLK; i++)
  if(a[i].op != CHANNOP)
   altdequeue(&a[i]);
}

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct _Threadlist { struct _Thread *head; struct _Thread *tail; }

user_defined_types: struct _Procrendez { struct Lock *l; int asleep; int pid; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


amove

decompiled_code:
void *__fastcall amove(void *a1, const void *a2, unsigned int a3)
{
void *result; // rax

if ( a1 )
{
if ( a2 )
result = memmove(a1, a2, a3);
else
result = memset(a1, 0, a3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(void *a1, const void *a2, unsigned int a3)
{
void *result; // rax

if ( a1 )
{
if ( a2 )
result = memmove(a1, a2, a3);
else
result = memset(a1, 0, a3);
}
return result;
}

original_code:
static void
amove(void *dst, void *src, uint n)
{
 if(dst){
  if(src == ((void*)0))
   memset(dst, 0, n);
  else
   memmove(dst, src, n);
 }
}

canonical_original_code:
static void amove(void *dst, void *src, unsigned int n)
{
 if(dst){
  if(src == ((void *)0))
   memset(dst, 0, n);
  else
   memmove(dst, src, n);
 }
}

variable_types:
dst
void *

variable_types:
src
void *

variable_types:
n
unsigned int


altcopy

original_code:
static void
altcopy(Alt *s, Alt *r)
{
 Alt *t;
 Channel *c;
 uchar *cp;
 if(s == ((void*)0) && r == ((void*)0))
  return;
 ((void) sizeof ((s != ((void*)0)) ? 1 : 0), __extension__ ({ if (s != ((void*)0)) ; else __assert_fail ("s != nil", "channel.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 c = s->c;
 if(s->op == CHANRCV){
  t = s;
  s = r;
  r = t;
 }
 ((void) sizeof ((s==((void*)0) || s->op == CHANSND) ? 1 : 0), __extension__ ({ if (s==((void*)0) || s->op == CHANSND) ; else __assert_fail ("s==nil || s->op == CHANSND", "channel.c", 196, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((r==((void*)0) || r->op == CHANRCV) ? 1 : 0), __extension__ ({ if (r==((void*)0) || r->op == CHANRCV) ; else __assert_fail ("r==nil || r->op == CHANRCV", "channel.c", 197, __extension__ __PRETTY_FUNCTION__); }));
 if(s && r && c->nbuf == 0){
  amove(r->v, s->v, c->elemsize);
  return;
 }
 if(r){
  cp = c->buf + c->off*c->elemsize;
  amove(r->v, cp, c->elemsize);
  --c->nbuf;
  if(++c->off == c->bufsize)
   c->off = 0;
 }
 if(s){
  cp = c->buf + (c->off+c->nbuf)%c->bufsize*c->elemsize;
  amove(cp, s->v, c->elemsize);
  ++c->nbuf;
 }
}

canonical_original_code:
static void altcopy(struct Alt *s, struct Alt *r)
{
 struct Alt *t;
 struct Channel *c;
 unsigned char *cp;
 if(s == ((void *)0) && r == ((void *)0))
  return;
 ((void) sizeof ((s != ((void *)0)) ? 1 : 0), __extension__ ({ if (s != ((void *)0)) ; else __assert_fail ("s != nil", "channel.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 c = s->c;
 if(s->op == CHANRCV){
  t = s;
  s = r;
  r = t;
 }
 ((void) sizeof ((s==((void *)0) || s->op == CHANSND) ? 1 : 0), __extension__ ({ if (s==((void *)0) || s->op == CHANSND) ; else __assert_fail ("s==nil || s->op == CHANSND", "channel.c", 196, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((r==((void *)0) || r->op == CHANRCV) ? 1 : 0), __extension__ ({ if (r==((void *)0) || r->op == CHANRCV) ; else __assert_fail ("r==nil || r->op == CHANRCV", "channel.c", 197, __extension__ __PRETTY_FUNCTION__); }));
 if(s && r && c->nbuf == 0){
  amove(r->v, s->v, c->elemsize);
  return;
 }
 if(r){
  cp = c->buf + c->off*c->elemsize;
  amove(r->v, cp, c->elemsize);
  --c->nbuf;
  if(++c->off == c->bufsize)
   c->off = 0;
 }
 if(s){
  cp = c->buf + (c->off+c->nbuf)%c->bufsize*c->elemsize;
  amove(cp, s->v, c->elemsize);
  ++c->nbuf;
 }
}

variable_types:
r
struct Alt *

variable_types: struct Channel { unsigned int bufsize; unsigned int elemsize; unsigned char *buf; unsigned int nbuf; unsigned int off; struct _Altarray { struct Alt { struct Channel *c; void *v; unsigned int op; struct _Thread { struct _Thread *next; struct _Thread *prev; struct _Thread *allnext; struct _Thread *allprev; struct Context { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; } context; void (*startfn)(void *); void *startarg; unsigned int id; unsigned char *stk; unsigned int stksize; int exiting; struct Proc { struct Proc *next; struct Proc *prev; char msg[128]; int osprocid; struct Lock { int held; } lock; int nswitch; struct _Thread *thread; struct _Thread *pinthread; struct _Threadlist { struct _Thread *head; struct _Thread *tail; } runqueue; struct _Threadlist idlequeue; struct _Threadlist allthreads; unsigned int nthread; unsigned int sysproc; struct _Procrendez { struct Lock *l; int asleep; int pid; } runrend; struct Context schedcontext; void *udata; struct Jmp { long b[-1]; } sigjmp; int mainproc; } *proc; char name[256]; char state[256]; void *udata; struct Alt *chanalt; } *thread; } **a; unsigned int n; unsigned int m; } asend; struct _Altarray arecv; char *name; } *

variable_types:
cp
unsigned char *


altexec

original_code:
static void
altexec(Alt *a)
{
 int i;
 _Altarray *ar;
 Alt *other;
 Channel *c;
 c = a->c;
 ar = chanarray(c, (CHANSND+CHANRCV-(a->op)));
 if(ar && ar->n){
  i = p9rand()%ar->n;
  other = ar->a[i];
  altcopy(a, other);
  altalldequeue(other->thread->chanalt);
  other->thread->chanalt = other;
  _threadready(other->thread);
 }else
  altcopy(a, ((void*)0));
}

canonical_original_code:
static void altexec(struct Alt *a)
{
 int i;
 struct _Altarray *ar;
 struct Alt *other;
 struct Channel *c;
 c = a->c;
 ar = chanarray(c, (CHANSND+CHANRCV-(a->op)));
 if(ar && ar->n){
  i = p9rand()%ar->n;
  other = ar->a[i];
  altcopy(a, other);
  altalldequeue(other->thread->chanalt);
  other->thread->chanalt = other;
  _threadready(other->thread);
 }else
  altcopy(a, ((void *)0));
}


addarray

decompiled_code:
__int64 __fastcall addarray(__int64 *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax
unsigned int v5; // eax

v2 = *((_DWORD *)a1 + 3);
if ( *((_DWORD *)a1 + 2) == v2 )
{
v5 = v2 + 16;
*((_DWORD *)a1 + 3) = v5;
*a1 = p9realloc(*a1, 8LL * v5);
}
v3 = *a1;
LODWORD(result) = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 2) = result + 1;
result = (unsigned int)result;
*(_QWORD *)(v3 + 8LL * (unsigned int)result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax
unsigned int v5; // eax

v2 = *((_DWORD *)a1 + 3);
if ( *((_DWORD *)a1 + 2) == v2 )
{
v5 = v2 + 16;
*((_DWORD *)a1 + 3) = v5;
*a1 = p9realloc(*a1, 8LL * v5);
}
v3 = *a1;
LODWORD(result) = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 2) = result + 1;
result = (unsigned int)result;
*(_QWORD *)(v3 + 8LL * (unsigned int)result) = a2;
return result;
}

original_code:
static void
addarray(_Altarray *a, Alt *chanalt)
{
 if(a->n == a->m){
  a->m += 16;
  a->a = p9realloc(a->a, a->m*sizeof a->a[0]);
 }
 a->a[a->n++] = chanalt;
}

canonical_original_code:
static void addarray(struct _Altarray *a, struct Alt *chanalt)
{
 if(a->n == a->m){
  a->m += 16;
  a->a = p9realloc(a->a, a->m*sizeof a->a[0]);
 }
 a->a[a->n++] = chanalt;
}

variable_types:
chanalt
struct Alt *


altqueue

decompiled_code:
void __fastcall altqueue(__int64 a1)
{
__int64 v2; // rdi
__int64 *v3; // rax

v2 = *(_QWORD *)a1;
if ( v2 )
{
v3 = (__int64 *)chanarray(v2, *(_DWORD *)(a1 + 16));
addarray(v3, a1);
}
}

original_code:
static void
altqueue(Alt *a)
{
 _Altarray *ar;
 if(a->c == ((void*)0))
  return;
 ar = chanarray(a->c, a->op);
 addarray(ar, a);
}

canonical_original_code:
static void altqueue(struct Alt *a)
{
 struct _Altarray *ar;
 if(a->c == ((void *)0))
  return;
 ar = chanarray(a->c, a->op);
 addarray(ar, a);
}


chansetname

decompiled_code:
__int64 chansetname(__int64 a1, __int64 a2, ...)
{
__int64 v2; // rbp
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a2);
v2 = vsmprint(a2, va);
result = p9free(*(_QWORD *)(a1 + 56));
*(_QWORD *)(a1 + 56) = v2;
return result;
}

canonical_decompiled_code:
__int64 func11(__int64 a1, __int64 a2, ...)
{
__int64 v2; // rbp
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a2);
v2 = vsmprint(a2, va);
result = p9free(*(_QWORD *)(a1 + 56));
*(_QWORD *)(a1 + 56) = v2;
return result;
}

original_code:
void
chansetname(Channel *c, char *fmt, ...)
{
 char *name;
 va_list arg;
 __builtin_va_start(arg,fmt);
 name = vsmprint(fmt, arg);
 __builtin_va_end(arg);
 p9free(c->name);
 c->name = name;
}

canonical_original_code:
void chansetname(struct Channel *c, char *fmt, ...)
{
 char *name;
 __builtin_va_list arg;
 __builtin_va_start(arg,fmt);
 name = vsmprint(fmt, arg);
 __builtin_va_end(arg);
 p9free(c->name);
 c->name = name;
}

variable_types:
fmt
char *

variable_types:
name
char *


chanfree

decompiled_code:
__int64 __fastcall chanfree(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
p9free(a1[7]);
p9free(a1[5]);
p9free(a1[3]);
result = p9free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
p9free(a1[7]);
p9free(a1[5]);
p9free(a1[3]);
result = p9free(a1);
}
return result;
}

original_code:
void
chanfree(Channel *c)
{
 if(c == ((void*)0))
  return;
 p9free(c->name);
 p9free(c->arecv.a);
 p9free(c->asend.a);
 p9free(c);
}

canonical_original_code:
void chanfree(struct Channel *c)
{
 if(c == ((void *)0))
  return;
 p9free(c->name);
 p9free(c->arecv.a);
 p9free(c->asend.a);
 p9free(c);
}


chanalt

original_code:
int
chanalt(Alt *a)
{
 int i, j, ncan, n, canblock;
 Channel *c;
 _Thread *t;
 needstack(512);
 for(i=0; a[i].op != CHANEND && a[i].op != CHANNOBLK; i++)
  ;
 n = i;
 canblock = a[i].op == CHANEND;
 t = _threadproc()->thread;
 for(i=0; i<n; i++)
  a[i].thread = t;
 t->chanalt = a;
 qlock(&chanlock);
if(0) print("alt ");
 ncan = 0;
 for(i=0; i<n; i++){
  c = a[i].c;
if(0) print(" %c:", "esrnb"[a[i].op]);
if(0) if(c->name) print("%s", c->name); else print("%p", c);
  if(altcanexec(&a[i])){
if(0) print("*");
   ncan++;
  }
 }
 if(ncan){
  j = p9rand()%ncan;
  for(i=0; i<n; i++){
   if(altcanexec(&a[i])){
    if(j-- == 0){
if(0){
c = a[i].c;
print(" => %c:", "esrnb"[a[i].op]);
if(c->name) print("%s", c->name); else print("%p", c);
print("\n");
}
     altexec(&a[i]);
     qunlock(&chanlock);
     return i;
    }
   }
  }
 }
if(0)print("\n");
 if(!canblock){
  qunlock(&chanlock);
  return -1;
 }
 for(i=0; i<n; i++){
  if(a[i].op != CHANNOP)
   altqueue(&a[i]);
 }
 qunlock(&chanlock);
 _threadswitch();
 if(t->chanalt < a || t->chanalt >= a+n)
  sysfatal("channel bad alt");
 return t->chanalt - a;
}

canonical_original_code:
int chanalt(struct Alt *a)
{
 int i; int j; int ncan; int n; int canblock;
 struct Channel *c;
 struct _Thread *t;
 needstack(512);
 for(i=0; a[i].op != CHANEND && a[i].op != CHANNOBLK; i++)
  ;
 n = i;
 canblock = a[i].op == CHANEND;
 t = _threadproc()->thread;
 for(i=0; i<n; i++)
  a[i].thread = t;
 t->chanalt = a;
 qlock(&chanlock);
if(0) print("alt ");
 ncan = 0;
 for(i=0; i<n; i++){
  c = a[i].c;
if(0) print(" %c:", "esrnb"[a[i].op]);
if(0) if(c->name) print("%s", c->name); else print("%p", c);
  if(altcanexec(&a[i])){
if(0) print("*");
   ncan++;
  }
 }
 if(ncan){
  j = p9rand()%ncan;
  for(i=0; i<n; i++){
   if(altcanexec(&a[i])){
    if(j-- == 0){
if(0){
c = a[i].c;
print(" => %c:", "esrnb"[a[i].op]);
if(c->name) print("%s", c->name); else print("%p", c);
print("\n");
}
     altexec(&a[i]);
     qunlock(&chanlock);
     return i;
    }
   }
  }
 }
if(0)print("\n");
 if(!canblock){
  qunlock(&chanlock);
  return -1;
 }
 for(i=0; i<n; i++){
  if(a[i].op != CHANNOP)
   altqueue(&a[i]);
 }
 qunlock(&chanlock);
 _threadswitch();
 if(t->chanalt < a || t->chanalt >= a+n)
  sysfatal("channel bad alt");
 return t->chanalt - a;
}

variable_types: j int

variable_types: ncan int

variable_types: canblock int

variable_types: struct _Thread { struct _Thread *next; struct _Thread *prev; struct _Thread *allnext; struct _Thread *allprev; struct Context { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; } context; void (*startfn)(void *); void *startarg; unsigned int id; unsigned char *stk; unsigned int stksize; int exiting; struct Proc { struct Proc *next; struct Proc *prev; char msg[128]; int osprocid; struct Lock { int held; } lock; int nswitch; struct _Thread *thread; struct _Thread *pinthread; struct _Threadlist { struct _Thread *head; struct _Thread *tail; } runqueue; struct _Threadlist idlequeue; struct _Threadlist allthreads; unsigned int nthread; unsigned int sysproc; struct _Procrendez { struct Lock *l; int asleep; int pid; } runrend; struct Context schedcontext; void *udata; struct Jmp { long b[-1]; } sigjmp; int mainproc; } *proc; char name[256]; char state[256]; void *udata; struct Alt { struct Channel { unsigned int bufsize; unsigned int elemsize; unsigned char *buf; unsigned int nbuf; unsigned int off; struct _Altarray { struct Alt **a; unsigned int n; unsigned int m; } asend; struct _Altarray arecv; char *name; } *c; void *v; unsigned int op; struct _Thread *thread; } *chanalt; } *


chansend

decompiled_code:
__int64 __fastcall chansend(__int64 a1, __int64 a2)
{
return chanop(a1, 1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return func14(a1, 1, a2, 1);
}

original_code:
int
chansend(Channel *c, void *v)
{
 return _chanop(c, CHANSND, v, 1);
}

canonical_original_code:
int chansend(struct Channel *c, void *v)
{
 return _chanop(c, CHANSND, v, 1);
}

variable_types:
v
void *


channbsend

decompiled_code:
__int64 __fastcall channbsend(__int64 a1, __int64 a2)
{
return chanop(a1, 1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
return func14(a1, 1, a2, 0);
}

original_code:
int
channbsend(Channel *c, void *v)
{
 return _chanop(c, CHANSND, v, 0);
}

canonical_original_code:
int channbsend(struct Channel *c, void *v)
{
 return _chanop(c, CHANSND, v, 0);
}


chanrecv

decompiled_code:
__int64 __fastcall chanrecv(__int64 a1, __int64 a2)
{
return chanop(a1, 2, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
return func14(a1, 2, a2, 1);
}

original_code:
int
chanrecv(Channel *c, void *v)
{
 return _chanop(c, CHANRCV, v, 1);
}

canonical_original_code:
int chanrecv(struct Channel *c, void *v)
{
 return _chanop(c, CHANRCV, v, 1);
}


channbrecv

decompiled_code:
__int64 __fastcall channbrecv(__int64 a1, __int64 a2)
{
return chanop(a1, 2, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2)
{
return func14(a1, 2, a2, 0);
}

original_code:
int
channbrecv(Channel *c, void *v)
{
 return _chanop(c, CHANRCV, v, 0);
}

canonical_original_code:
int channbrecv(struct Channel *c, void *v)
{
 return _chanop(c, CHANRCV, v, 0);
}


chansendp

decompiled_code:
__int64 __fastcall chansendp(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return chanop(a1, 1, (__int64)&v3, 1);
}

original_code:
int
chansendp(Channel *c, void *v)
{
 return _chanop(c, CHANSND, (void*)&v, 1);
}

canonical_original_code:
int chansendp(struct Channel *c, void *v)
{
 return _chanop(c, CHANSND, (void *)&v, 1);
}


chanrecvp

decompiled_code:
__int64 __fastcall chanrecvp(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)chanop(a1, 2, (__int64)&v3, 1) <= 0;
result = 0LL;
if ( !v1 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)func14(a1, 2, (__int64)&v3, 1) <= 0;
result = 0LL;
if ( !v1 )
result = v3;
return result;
}

original_code:
void*
chanrecvp(Channel *c)
{
 void *v;
 if(_chanop(c, CHANRCV, (void*)&v, 1) > 0)
  return v;
 return ((void*)0);
}

canonical_original_code:
void *chanrecvp(struct Channel *c)
{
 void *v;
 if(_chanop(c, CHANRCV, (void *)&v, 1) > 0)
  return v;
 return ((void *)0);
}


channbsendp

decompiled_code:
__int64 __fastcall channbsendp(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return chanop(a1, 1, (__int64)&v3, 0);
}

original_code:
int
channbsendp(Channel *c, void *v)
{
 return _chanop(c, CHANSND, (void*)&v, 0);
}

canonical_original_code:
int channbsendp(struct Channel *c, void *v)
{
 return _chanop(c, CHANSND, (void *)&v, 0);
}


channbrecvp

decompiled_code:
__int64 __fastcall channbrecvp(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)chanop(a1, 2, (__int64)&v3, 0) <= 0;
result = 0LL;
if ( !v1 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)func14(a1, 2, (__int64)&v3, 0) <= 0;
result = 0LL;
if ( !v1 )
result = v3;
return result;
}

original_code:
void*
channbrecvp(Channel *c)
{
 void *v;
 if(_chanop(c, CHANRCV, (void*)&v, 0) > 0)
  return v;
 return ((void*)0);
}

canonical_original_code:
void *channbrecvp(struct Channel *c)
{
 void *v;
 if(_chanop(c, CHANRCV, (void *)&v, 0) > 0)
  return v;
 return ((void *)0);
}


chansendul

decompiled_code:
__int64 __fastcall chansendul(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return chanop(a1, 1, (__int64)&v3, 1);
}

original_code:
int
chansendul(Channel *c, ulong val)
{
 return _chanop(c, CHANSND, &val, 1);
}

canonical_original_code:
int chansendul(struct Channel *c, unsigned long val)
{
 return _chanop(c, CHANSND, &val, 1);
}

variable_types:
val
unsigned long


chanrecvul

decompiled_code:
__int64 __fastcall chanrecvul(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)chanop(a1, 2, (__int64)&v3, 1) <= 0;
result = -1LL;
if ( !v1 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)func14(a1, 2, (__int64)&v3, 1) <= 0;
result = -1LL;
if ( !v1 )
result = v3;
return result;
}

original_code:
ulong
chanrecvul(Channel *c)
{
 ulong val;
 if(_chanop(c, CHANRCV, &val, 1) > 0)
  return val;
 return -1;
}

canonical_original_code:
unsigned long chanrecvul(struct Channel *c)
{
 unsigned long val;
 if(_chanop(c, CHANRCV, &val, 1) > 0)
  return val;
 return -1;
}

return_type: unsigned long


channbsendul

decompiled_code:
__int64 __fastcall channbsendul(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return chanop(a1, 1, (__int64)&v3, 0);
}

original_code:
int
channbsendul(Channel *c, ulong val)
{
 return _chanop(c, CHANSND, &val, 0);
}

canonical_original_code:
int channbsendul(struct Channel *c, unsigned long val)
{
 return _chanop(c, CHANSND, &val, 0);
}


channbrecvul

decompiled_code:
__int64 __fastcall channbrecvul(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)chanop(a1, 2, (__int64)&v3, 0) <= 0;
result = -1LL;
if ( !v1 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1)
{
bool v1; // cc
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v1 = (int)func14(a1, 2, (__int64)&v3, 0) <= 0;
result = -1LL;
if ( !v1 )
result = v3;
return result;
}

original_code:
ulong
channbrecvul(Channel *c)
{
 ulong val;
 if(_chanop(c, CHANRCV, &val, 0) > 0)
  return val;
 return -1;
}

canonical_original_code:
unsigned long channbrecvul(struct Channel *c)
{
 unsigned long val;
 if(_chanop(c, CHANRCV, &val, 0) > 0)
  return val;
 return -1;
}


readn

decompiled_code:
ssize_t __fastcall readn(int fd, __int64 a2, __int64 a3)
{
ssize_t v4; // rbx
ssize_t v5; // rax

if ( a3 <= 0 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( v5 <= 0 )
break;
v4 += v5;
if ( a3 <= v4 )
return v4;
}
if ( !v4 )
v4 = v5;
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int fd, __int64 a2, __int64 a3)
{
ssize_t v4; // rbx
ssize_t v5; // rax

if ( a3 <= 0 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( v5 <= 0 )
break;
v4 += v5;
if ( a3 <= v4 )
return v4;
}
if ( !v4 )
v4 = v5;
return v4;
}

original_code:
long
readn(int f, void *av, long n)
{
 char *a;
 long m, t;
 a = av;
 t = 0;
 while(t < n){
  m = read(f, a+t, n-t);
  if(m <= 0){
   if(t == 0)
    return m;
   break;
  }
  t += m;
 }
 return t;
}

canonical_original_code:
long readn(int f, void *av, long n)
{
 char *a;
 long m; long t;
 a = av;
 t = 0;
 while(t < n){
  m = read(f, a+t, n-t);
  if(m <= 0){
   if(t == 0)
    return m;
   break;
  }
  t += m;
 }
 return t;
}

variable_types: f int

variable_types:
av
void *

variable_types: n long

variable_types:
a
char *

variable_types: m long

variable_types: t long


bsearch

decompiled_code:
unsigned int *__fastcall bsearch(unsigned int a1, unsigned int *a2, int a3, int a4)
{
unsigned int *v5; // rcx
unsigned int *result; // rax

while ( a3 > 1 )
{
v5 = &a2[a4 * (a3 / 2)];
if ( *v5 <= a1 )
{
a3 -= a3 / 2;
a2 = v5;
}
else
{
a3 /= 2;
}
}
result = 0LL;
if ( a3 && *a2 <= a1 )
result = a2;
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int a1, unsigned int *a2, int a3, int a4)
{
unsigned int *v5; // rcx
unsigned int *result; // rax

while ( a3 > 1 )
{
v5 = &a2[a4 * (a3 / 2)];
if ( *v5 <= a1 )
{
a3 -= a3 / 2;
a2 = v5;
}
else
{
a3 /= 2;
}
}
result = 0LL;
if ( a3 && *a2 <= a1 )
result = a2;
return result;
}

original_code:
static Rune*
bsearch(Rune c, Rune *t, int n, int ne)
{
 Rune *p;
 int m;
 while(n > 1) {
  m = n/2;
  p = t + m*ne;
  if(c >= p[0]) {
   t = p;
   n = n-m;
  } else
   n = m;
 }
 if(n && c >= t[0])
  return t;
 return 0;
}

canonical_original_code:
static unsigned int *bsearch(unsigned int c, unsigned int *t, int n, int ne)
{
 unsigned int *p;
 int m;
 while(n > 1) {
  m = n/2;
  p = t + m*ne;
  if(c >= p[0]) {
   t = p;
   n = n-m;
  } else
   n = m;
 }
 if(n && c >= t[0])
  return t;
 return 0;
}

variable_types:
c
unsigned int

variable_types:
t
unsigned int *

variable_types: n int

variable_types: ne int

variable_types:
p
unsigned int *

variable_types: m int

return_type: unsigned int *


istitlerune

decompiled_code:
_BOOL8 __fastcall istitlerune(unsigned int a1)
{
_BOOL8 result; // rax

result = isupperrune(a1);
if ( result )
result = islowerrune(a1);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(unsigned int a1)
{
_BOOL8 result; // rax

result = func5(a1);
if ( result )
result = func4(a1);
return result;
}

original_code:
int
istitlerune(Rune c)
{
 return isupperrune(c) && islowerrune(c);
}

canonical_original_code:
int istitlerune(unsigned int c)
{
 return isupperrune(c) && islowerrune(c);
}