decompiled_code:
__int64 __fastcall quda_weak_check_amplitudes(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

if ( *(int *)(a1 + 12) <= 0 )
return 0LL;
v1 = 0LL;
v2 = 0;
do
{
if ( quda_complex_abs_square(*(double *)(*(_QWORD *)(a1 + 16) + 16 * v1 + 8)) > 1.0 )
v2 = 1;
++v1;
}
while ( *(_DWORD *)(a1 + 12) > (int)v1 );
return v2;
}

original_code:
int quda_weak_check_amplitudes(quantum_reg* qreg) {
 int i;
 int err = 0;
 for(i=0;i<qreg->num_states;i++) {
  if(quda_complex_abs_square(qreg->states[i].amplitude) > 1.0) {
   err = 1;
  }
 }
 return err;
}

canonical_original_code:
int quda_weak_check_amplitudes(struct quantum_reg *qreg) {
 int i;
 int err = 0;
 for(i=0;i<qreg->num_states;i++) {
  if(quda_complex_abs_square(qreg->states[i].amplitude) > 1.0) {
   err = 1;
  }
 }
 return err;
}

variable_types: err int


repo: jcranmer/libquantum

decompiled_code:
int __fastcall quda_quantum_reg_dump(__int64 a1, const char *a2)
{
int v3; // er14
int result; // eax
__int64 v5; // rbx
__int64 v6; // rdx
__int64 v7; // rsi
__int64 v8; // r15
__int64 v9; // rdx
unsigned __int64 v10; // [rsp+8h] [rbp-40h]

v3 = (1 << *(_DWORD *)a1) - 1;
v10 = ((1 << *(_DWORD *)(a1 + 8)) - 1) << *(_DWORD *)a1;
printf("QREG_DUMP: %d states\n", *(unsigned int *)(a1 + 12));
result = *(_DWORD *)(a1 + 12);
if ( result > 0 )
{
v5 = 0LL;
do
{
v8 = 16 * v5;
if ( a2 )
{
printf("%s: ", a2);
v6 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v5);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v5,
v6,
v6 & v3,
(v6 & v10) >> *(_DWORD *)a1);
printf("%s: ", a2);
}
else
{
v9 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v5);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v5,
v9,
v9 & v3,
(v9 & v10) >> *(_DWORD *)a1);
}
v7 = (unsigned int)v5++;
result = printf(
"qreg->states[%d].amplitude = (%f,%f)\n",
v7,
*(float *)(v8 + *(_QWORD *)(a1 + 16) + 8),
*(float *)(v8 + *(_QWORD *)(a1 + 16) + 12));
}
while ( *(_DWORD *)(a1 + 12) > (int)v5 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, const char *a2)
{
int v3; // er14
int result; // eax
__int64 v5; // rbx
__int64 v6; // rdx
__int64 v7; // rsi
__int64 v8; // r15
__int64 v9; // rdx
unsigned __int64 v10; // [rsp+8h] [rbp-40h]

v3 = (1 << *(_DWORD *)a1) - 1;
v10 = ((1 << *(_DWORD *)(a1 + 8)) - 1) << *(_DWORD *)a1;
printf("QREG_DUMP: %d states\n", *(unsigned int *)(a1 + 12));
result = *(_DWORD *)(a1 + 12);
if ( result > 0 )
{
v5 = 0LL;
do
{
v8 = 16 * v5;
if ( a2 )
{
printf("%s: ", a2);
v6 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v5);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v5,
v6,
v6 & v3,
(v6 & v10) >> *(_DWORD *)a1);
printf("%s: ", a2);
}
else
{
v9 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v5);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v5,
v9,
v9 & v3,
(v9 & v10) >> *(_DWORD *)a1);
}
v7 = (unsigned int)v5++;
result = printf(
"qreg->states[%d].amplitude = (%f,%f)\n",
v7,
*(float *)(v8 + *(_QWORD *)(a1 + 16) + 8),
*(float *)(v8 + *(_QWORD *)(a1 + 16) + 12));
}
while ( *(_DWORD *)(a1 + 12) > (int)v5 );
}
return result;
}

original_code:
void quda_quantum_reg_dump(quantum_reg* qreg, char* tag) {
 int i;
 uint64_t mask = (1 << qreg->qubits)-1;
 uint64_t smask = ((1 << qreg->scratch)-1) << qreg->qubits;
 printf("QREG_DUMP: %d states\n",qreg->num_states);
 for(i=0;i<qreg->num_states;i++) {
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",i,qreg->states[i].state,
    qreg->states[i].state & mask,(qreg->states[i].state & smask) >> qreg->qubits);
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].amplitude = (%f,%f)\n",i,qreg->states[i].amplitude.real,
    qreg->states[i].amplitude.imag);
 }
}

canonical_original_code:
void quda_quantum_reg_dump(struct quantum_reg *qreg, char *tag) {
 int i;
 unsigned long mask = (1 << qreg->qubits)-1;
 unsigned long smask = ((1 << qreg->scratch)-1) << qreg->qubits;
 printf("QREG_DUMP: %d states\n",qreg->num_states);
 for(i=0;i<qreg->num_states;i++) {
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",i,qreg->states[i].state,
    qreg->states[i].state & mask,(qreg->states[i].state & smask) >> qreg->qubits);
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].amplitude = (%f,%f)\n",i,qreg->states[i].amplitude.real,
    qreg->states[i].amplitude.imag);
 }
}

variable_types: struct quantum_reg { int qubits; int size; int scratch; int num_states; struct quantum_state_t { unsigned long state; struct complex_t { float real; float imag; } amplitude; } *states; } *

variable_types:
tag
char *

variable_types: i int

variable_types:
mask
unsigned long

variable_types:
smask
unsigned long

return_type: void

user_defined_types: struct quantum_reg { int qubits; int size; int scratch; int num_states; struct quantum_state_t *states; }

user_defined_types: struct quantum_state_t { unsigned long state; struct complex_t amplitude; }


decompiled_code:
__int64 __fastcall quda_quantum_hadamard_range(int a1, int a2, __int64 a3)
{
unsigned int v4; // ebx

if ( a1 >= a2 )
return 0LL;
v4 = a1;
do
{
if ( (unsigned int)quda_quantum_hadamard_gate(v4, a3) )
return 0xFFFFFFFFLL;
++v4;
}
while ( a2 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, __int64 a3)
{
unsigned int v4; // ebx

if ( a1 >= a2 )
return 0LL;
v4 = a1;
do
{
if ( (unsigned int)quda_quantum_hadamard_gate(v4, a3) )
return 0xFFFFFFFFLL;
++v4;
}
while ( a2 != v4 );
return 0LL;
}

original_code:
int quda_quantum_hadamard_range(int start,int end,quantum_reg* qreg) {
 int i,res;
 for(i=start;i<end;i++) {
  res = quda_quantum_hadamard_gate(i,qreg);
  if(res) {
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int quda_quantum_hadamard_range(int start, int end, struct quantum_reg *qreg) {
 int i; int res;
 for(i=start;i<end;i++) {
  res = quda_quantum_hadamard_gate(i,qreg);
  if(res) {
   return -1;
  }
 }
 return 0;
}

variable_types: start int

variable_types: end int

variable_types: res int

return_type: int

user_defined_types: struct complex_t { float real; float imag; }


decompiled_code:
__int64 __fastcall quda_quantum_hadamard_after(int a1, int *a2)
{
return quda_quantum_hadamard_range(a1, *a2, (__int64)a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int *a2)
{
return func3(a1, *a2, (__int64)a2);
}

original_code:
int quda_quantum_hadamard_after(int start,quantum_reg* qreg) {
 return quda_quantum_hadamard_range(start,qreg->qubits,qreg);
}

canonical_original_code:
int quda_quantum_hadamard_after(int start, struct quantum_reg *qreg) {
 return quda_quantum_hadamard_range(start,qreg->qubits,qreg);
}


decompiled_code:
__int64 __fastcall quda_quantum_hadamard_all(int *a1)
{
return quda_quantum_hadamard_range(0, *a1, (__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1)
{
return func3(0, *a1, (__int64)a1);
}

original_code:
int quda_quantum_hadamard_all(quantum_reg* qreg) {
 return quda_quantum_hadamard_range(0,qreg->qubits,qreg);
}

canonical_original_code:
int quda_quantum_hadamard_all(struct quantum_reg *qreg) {
 return quda_quantum_hadamard_range(0,qreg->qubits,qreg);
}


decompiled_code:
int __fastcall quda_quantum_fourier_transform(int *a1)
{
int v1; // er14
int v2; // er13
int result; // eax
unsigned int v4; // ebp
unsigned int v6; // er15
unsigned int v7; // ebp
int v8; // [rsp+Ch] [rbp-3Ch]

v1 = *a1;
v2 = v1 - 1;
v8 = *a1 - 1;
result = printf("Number of states: %d\n", (unsigned int)a1[3]);
if ( v1 - 1 >= 0 )
{
v4 = v1 - 1;
while ( 1 )
{
quda_quantum_hadamard_gate(v4, a1);
result = printf("Number of states after hadamard %d: %d\n", v4, (unsigned int)a1[3]);
if ( v4-- == 0 )
break;
if ( v1 > v2 )
{
v6 = v1 - v4;
do
{
quda_quantum_controlled_rotate_k_gate(v2 - 2 + v6, v4, a1, v6);
--v6;
}
while ( v6 != 1 );
}
--v2;
}
}
if ( *a1 > 1 )
{
v7 = 0;
do
{
quda_quantum_controlled_not_gate(v7, v8 - v7, a1);
quda_quantum_controlled_not_gate(v8 - v7, v7, a1);
quda_quantum_controlled_not_gate(v7, v8 - v7, a1);
++v7;
result = *a1 / 2;
}
while ( result > (int)v7 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int *a1)
{
int v1; // er14
int v2; // er13
int result; // eax
unsigned int v4; // ebp
unsigned int v6; // er15
unsigned int v7; // ebp
int v8; // [rsp+Ch] [rbp-3Ch]

v1 = *a1;
v2 = v1 - 1;
v8 = *a1 - 1;
result = printf("Number of states: %d\n", (unsigned int)a1[3]);
if ( v1 - 1 >= 0 )
{
v4 = v1 - 1;
while ( 1 )
{
quda_quantum_hadamard_gate(v4, a1);
result = printf("Number of states after hadamard %d: %d\n", v4, (unsigned int)a1[3]);
if ( v4-- == 0 )
break;
if ( v1 > v2 )
{
v6 = v1 - v4;
do
{
quda_quantum_controlled_rotate_k_gate(v2 - 2 + v6, v4, a1, v6);
--v6;
}
while ( v6 != 1 );
}
--v2;
}
}
if ( *a1 > 1 )
{
v7 = 0;
do
{
quda_quantum_controlled_not_gate(v7, v8 - v7, a1);
quda_quantum_controlled_not_gate(v8 - v7, v7, a1);
quda_quantum_controlled_not_gate(v7, v8 - v7, a1);
++v7;
result = *a1 / 2;
}
while ( result > (int)v7 );
}
return result;
}

original_code:
void quda_quantum_fourier_transform(quantum_reg* qreg) {
 int q = qreg->qubits-1;
 int i,j;
  printf("Number of states: %d\n", qreg->num_states);
 for(i=q;i>=0;i--) {
  for(j=q;j>i;j--) {
   quda_quantum_controlled_rotate_k_gate(j,i,qreg,j-i+1);
  }
  quda_quantum_hadamard_gate(i,qreg);
  printf("Number of states after hadamard %d: %d\n", i, qreg->num_states);
 }
 for(i=0;i<qreg->qubits/2;i++) {
  quda_quantum_controlled_not_gate(i,q-i,qreg);
  quda_quantum_controlled_not_gate(q-i,i,qreg);
  quda_quantum_controlled_not_gate(i,q-i,qreg);
 }
}

canonical_original_code:
void quda_quantum_fourier_transform(struct quantum_reg *qreg) {
 int q = qreg->qubits-1;
 int i; int j;
  printf("Number of states: %d\n", qreg->num_states);
 for(i=q;i>=0;i--) {
  for(j=q;j>i;j--) {
   quda_quantum_controlled_rotate_k_gate(j,i,qreg,j-i+1);
  }
  quda_quantum_hadamard_gate(i,qreg);
  printf("Number of states after hadamard %d: %d\n", i, qreg->num_states);
 }
 for(i=0;i<qreg->qubits/2;i++) {
  quda_quantum_controlled_not_gate(i,q-i,qreg);
  quda_quantum_controlled_not_gate(q-i,i,qreg);
  quda_quantum_controlled_not_gate(i,q-i,qreg);
 }
}

variable_types: q int

variable_types: j int


decompiled_code:
unsigned __int64 __fastcall quda_classical_continued_fraction_expansion(__int64 *a1, __int64 *a2)
{
__int64 v3; // r8
float v4; // xmm3_4
float v5; // xmm0_4
float v6; // xmm3_4
unsigned __int64 v7; // rsi
__int64 v8; // rcx
__int64 v9; // r11
__int64 v10; // r10
__int64 v11; // rbx
float v12; // xmm7_4
float v13; // xmm0_4
float v14; // xmm1_4
double v15; // xmm0_8
double v16; // xmm1_8
unsigned __int64 result; // rax
__int64 v18; // rdx
float v19; // xmm1_4
__int64 v20; // rdx
__int64 v21; // rax
__int64 v22; // rdx

v3 = *a2;
if ( *a1 < 0 )
{
v22 = *a1 & 1 | ((unsigned __int64)*a1 >> 1);
v4 = (float)(int)v22 + (float)(int)v22;
if ( v3 >= 0 )
goto LABEL_3;
LABEL_18:
v5 = (float)(int)(*(_DWORD *)a2 & 1 | ((unsigned __int64)v3 >> 1))
+ (float)(int)(*(_DWORD *)a2 & 1 | ((unsigned __int64)v3 >> 1));
goto LABEL_4;
}
v4 = (float)(int)*a1;
if ( v3 < 0 )
goto LABEL_18;
LABEL_3:
v5 = (float)(int)v3;
LABEL_4:
v6 = v4 / v5;
v7 = 2 * v3;
v8 = 1LL;
v9 = 0LL;
v10 = 0LL;
v11 = 1LL;
v12 = v6;
while ( 1 )
{
result = (int)(v12 + 0.000005);
v18 = v9 * (int)result;
v19 = v12 - ((double)(int)result - 0.000005);
v12 = 1.0 / v19;
if ( v18 + v8 > (unsigned __int64)v3 )
return result;
v20 = v8 | v18;
v8 = v9;
v21 = v10 + v11 * result;
v10 = v11;
*a1 = v21;
*a2 = v20;
result = *a1;
if ( *a1 >= 0 )
{
v13 = (float)(int)result;
if ( v20 >= 0 )
goto LABEL_6;
}
else
{
v13 = (float)(int)(*(_DWORD *)a1 & 1 | (result >> 1)) + (float)(int)(*(_DWORD *)a1 & 1 | (result >> 1));
if ( v20 >= 0 )
{
LABEL_6:
v14 = (float)(int)v20;
goto LABEL_7;
}
}
v14 = (float)(v20 & 1 | (unsigned int)((unsigned __int64)v20 >> 1))
+ (float)(v20 & 1 | (unsigned int)((unsigned __int64)v20 >> 1));
LABEL_7:
v15 = COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v13 / v14) - v6) & LC12);
if ( (v3 & 0x4000000000000000LL) != 0 )
v16 = (double)(int)(v7 >> 1) + (double)(int)(v7 >> 1);
else
v16 = (double)(int)v7;
if ( v15 <= 1.0 / v16 )
return result;
v9 = v20;
v11 = *a1;
}
}

original_code:
void quda_classical_continued_fraction_expansion(uint64_t* num, uint64_t* denom) {
 uint64_t orig_denom = *denom;
 float f = *num/(float)orig_denom;
 float g = f;
 uint64_t num1 = 1;
 uint64_t num2 = 0;
 uint64_t denom1 = 0;
 uint64_t denom2 = 1;
 int i;
 do {
  i = (int)(g+0.000005);
  g -= i-0.000005;
  g = 1.0/g;
  if(i * denom1 + denom2 > orig_denom) {
   break;
  }
  *num = i * num1 + num2;
  *denom = i * denom1 | denom2;
  num2 = num1;
  denom2 = denom1;
  num1 = *num;
  denom1 = *denom;
 } while(fabsf((*num/(float)*denom) - f) > 1.0 / (2 * orig_denom));
}

canonical_original_code:
void quda_classical_continued_fraction_expansion(unsigned long *num, unsigned long *denom) {
 unsigned long orig_denom = *denom;
 float f = *num/(float)orig_denom;
 float g = f;
 unsigned long num1 = 1;
 unsigned long num2 = 0;
 unsigned long denom1 = 0;
 unsigned long denom2 = 1;
 int i;
 do {
  i = (int)(g+0.000005);
  g -= i-0.000005;
  g = 1.0/g;
  if(i * denom1 + denom2 > orig_denom) {
   break;
  }
  *num = i * num1 + num2;
  *denom = i * denom1 | denom2;
  num2 = num1;
  denom2 = denom1;
  num1 = *num;
  denom1 = *denom;
 } while(fabsf((*num/(float)*denom) - f) > 1.0 / (2 * orig_denom));
}

variable_types:
num
unsigned long *

variable_types:
denom
unsigned long *

variable_types: f float

variable_types: g float


decompiled_code:
__int64 __fastcall quda_gcd_div(unsigned int a1, int a2)
{
signed int v2; // eax
int v3; // edx
unsigned int v4; // er8

v2 = a1;
v3 = a2;
if ( !a2 )
return a1;
do
{
v4 = v3;
v3 = v2 % v3;
v2 = v4;
}
while ( v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2)
{
signed int v2; // eax
int v3; // edx
unsigned int v4; // er8

v2 = a1;
v3 = a2;
if ( !a2 )
return a1;
do
{
v4 = v3;
v3 = v2 % v3;
v2 = v4;
}
while ( v3 );
return v4;
}

original_code:
int quda_gcd_div(int x, int y) {
 int temp;
 while(y != 0) {
  temp = y;
  y = x % y;
  x = temp;
 }
 return x;
}

variable_types: x int

variable_types: y int

variable_types: temp int


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

result = a1;
if ( !a1 )
return (unsigned int)a2;
for ( ; a2; a2 -= result )
{
for ( ; a2 < (int)result; result = (unsigned int)(result - a2) )
;
}
return result;
}

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

result = a1;
if ( !a1 )
return (unsigned int)a2;
for ( ; a2; a2 -= result )
{
for ( ; a2 < (int)result; result = (unsigned int)(result - a2) )
;
}
return result;
}

original_code:
int quda_gcd_sub(int x, int y) {
 if(x == 0) {
  return y;
 }
 while(y != 0) {
  if(x > y) {
   x -= y;
  } else {
   y -= x;
  }
 }
 return x;
}


decompiled_code:
__int64 __fastcall quda_mod_pow_simple(int a1, __int64 a2, int a3)
{
unsigned __int64 v4; // rsi
__int64 v5; // rcx
unsigned __int64 v6; // rdx

if ( !a2 )
return 1LL;
v4 = a3;
v5 = 0LL;
v6 = 1LL;
do
{
++v5;
v6 = a1 * v6 % v4;
}
while ( a2 != v5 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, int a3)
{
unsigned __int64 v4; // rsi
__int64 v5; // rcx
unsigned __int64 v6; // rdx

if ( !a2 )
return 1LL;
v4 = a3;
v5 = 0LL;
v6 = 1LL;
do
{
++v5;
v6 = a1 * v6 % v4;
}
while ( a2 != v5 );
return v6;
}

original_code:
uint64_t quda_mod_pow_simple(int b, uint64_t e, int n) {
 uint64_t res = 1;
 uint64_t i;
 for(i=0;i<e;i++) {
  res = (res*b) % n;
 }
 return res;
}

canonical_original_code:
unsigned long quda_mod_pow_simple(int b, unsigned long e, int n) {
 unsigned long res = 1;
 unsigned long i;
 for(i=0;i<e;i++) {
  res = (res*b) % n;
 }
 return res;
}

variable_types: b int

variable_types:
e
unsigned long

variable_types: n int

variable_types:
res
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall quda_classical_exp_mod_n(int a1, int a2, int *a3)
{
__int64 result; // rax
__int64 *v4; // r10
int v5; // er12
__int64 v6; // r13
__int64 *v7; // r10
__int64 *v8; // r9
__int64 *v9; // r11

result = (unsigned int)a3[3];
if ( (int)result > 0 )
{
v4 = (__int64 *)*((_QWORD *)a3 + 2);
v5 = *a3;
do
{
v6 = *v4;
result = v6 | (quda_mod_pow_simple(a1, *v4, a2) << v5);
*v7 = result;
v4 = v8;
}
while ( v8 != v9 );
}
return result;
}

original_code:
void quda_classical_exp_mod_n(int x, int n, quantum_reg* qreg) {
 int i;
 for(i=0;i<qreg->num_states;i++) {
  uint64_t value = quda_mod_pow_simple(x,qreg->states[i].state,n);
  value <<= qreg->qubits;
  qreg->states[i].state |= value;
 }
}

canonical_original_code:
void quda_classical_exp_mod_n(int x, int n, struct quantum_reg *qreg) {
 int i;
 for(i=0;i<qreg->num_states;i++) {
  unsigned long value = quda_mod_pow_simple(x,qreg->states[i].state,n);
  value <<= qreg->qubits;
  qreg->states[i].state |= value;
 }
}

variable_types: struct quantum_reg { int qubits; int size; int scratch; int num_states; struct quantum_state_t { unsigned long state; struct complex_t { float real; float imag; } amplitude; } *states; } *

variable_types: i int

variable_types:
value
unsigned long


decompiled_code:
unsigned __int64 __fastcall quda_mod_pow_bin(int a1, unsigned __int64 a2, int a3)
{
unsigned __int64 i; // r8

for ( i = 1LL; a2; a1 = a1 * a1 % a3 )
{
if ( (a2 & 1) != 0 )
i = i * a1 % a3;
a2 >>= 1;
}
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(int a1, unsigned __int64 a2, int a3)
{
unsigned __int64 i; // r8

for ( i = 1LL; a2; a1 = a1 * a1 % a3 )
{
if ( (a2 & 1) != 0 )
i = i * a1 % a3;
a2 >>= 1;
}
return i;
}

original_code:
uint64_t quda_mod_pow_bin(int b, uint64_t e, int n) {
 uint64_t res = 1;
 while(e > 0) {
  if((e & 1) == 1) {
   res = (res*b) % n;
  }
  e >>= 1;
  b = (b*b) % n;
 }
 return res;
}

canonical_original_code:
unsigned long quda_mod_pow_bin(int b, unsigned long e, int n) {
 unsigned long res = 1;
 while(e > 0) {
  if((e & 1) == 1) {
   res = (res*b) % n;
  }
  e >>= 1;
  b = (b*b) % n;
 }
 return res;
}


yyparse

repo: jcsalomon/hoc

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  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 (YYSTYPE)) + (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 == 2)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-10))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 84 < 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 4:
    { code((Inst){.opr = pop}); code((Inst){.opr = (Opr){0}}); return 1; }
    break;
  case 5:
    { code((Inst){.opr = print}); code((Inst){.opr = (Opr){0}}); return 1; }
    break;
  case 6:
    { (yyerrstatus = 0); }
    break;
  case 7:
    { code((Inst){.opr = varpush}); code((Inst){.sym = (yyvsp[-2].sym)}); code((Inst){.opr = assign}); }
    break;
  case 8:
    { code((Inst){.opr = constpush}); code((Inst){.val = (yyvsp[0].val)}); }
    break;
  case 9:
    { code((Inst){.opr = constpush}); code((Inst){.val = lastval}); }
    break;
  case 10:
    { code((Inst){.opr = varpush}); code((Inst){.sym = (yyvsp[0].sym)}); code((Inst){.opr = eval}); }
    break;
  case 12:
    { code((Inst){.opr = add}); }
    break;
  case 13:
    { code((Inst){.opr = sub}); }
    break;
  case 14:
    { code((Inst){.opr = mul}); }
    break;
  case 15:
    { code((Inst){.opr = divd}); }
    break;
  case 16:
    { code((Inst){.opr = mod}); }
    break;
  case 17:
    { code((Inst){.opr = power}); }
    break;
  case 20:
    { code((Inst){.opr = negate}); }
    break;
  case 21:
    { code((Inst){.opr = bltin}); code((Inst){.func = (yyvsp[-3].sym)->func}); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 19;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 84 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          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) == (-10))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 84 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (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 ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  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 (YYSTYPE)) + (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 == 2)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-10))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 84 < 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 4:
    { code((union Inst){.opr = pop}); code((union Inst){.opr = (union Datum (*)()){0}}); return 1; }
    break;
  case 5:
    { code((union Inst){.opr = print}); code((union Inst){.opr = (union Datum (*)()){0}}); return 1; }
    break;
  case 6:
    { (yyerrstatus = 0); }
    break;
  case 7:
    { code((union Inst){.opr = varpush}); code((union Inst){.sym = (yyvsp[-2].sym)}); code((union Inst){.opr = assign}); }
    break;
  case 8:
    { code((union Inst){.opr = constpush}); code((union Inst){.val = (yyvsp[0].val)}); }
    break;
  case 9:
    { code((union Inst){.opr = constpush}); code((union Inst){.val = lastval}); }
    break;
  case 10:
    { code((union Inst){.opr = varpush}); code((union Inst){.sym = (yyvsp[0].sym)}); code((union Inst){.opr = eval}); }
    break;
  case 12:
    { code((union Inst){.opr = add}); }
    break;
  case 13:
    { code((union Inst){.opr = sub}); }
    break;
  case 14:
    { code((union Inst){.opr = mul}); }
    break;
  case 15:
    { code((union Inst){.opr = divd}); }
    break;
  case 16:
    { code((union Inst){.opr = mod}); }
    break;
  case 17:
    { code((union Inst){.opr = power}); }
    break;
  case 20:
    { code((union Inst){.opr = negate}); }
    break;
  case 21:
    { code((union Inst){.opr = bltin}); code((union Inst){.func = (yyvsp[-3].sym)->func}); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 19;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 84 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          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) == (-10))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 84 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (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 ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types: union YYSTYPE { double val; struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; } *sym; union Inst { union Datum { double val; struct Symbol *sym; } (*opr)(); double val; struct Symbol *sym; double (*func)(double); } *inst; } [200]

variable_types: union YYSTYPE { double val; struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; } *sym; union Inst { union Datum { double val; struct Symbol *sym; } (*opr)(); double val; struct Symbol *sym; double (*func)(double); } *inst; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { double val; struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; } *sym; union Inst { union Datum { double val; struct Symbol *sym; } (*opr)(); double val; struct Symbol *sym; double (*func)(double); } *inst; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union YYSTYPE { double val; struct Symbol *sym; union Inst *inst; }

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }

user_defined_types: union Inst { union Datum (*opr)(); double val; struct Symbol *sym; double (*func)(double); }


reset

decompiled_code:
void __noreturn reset()
{
longjmp(begin, 0);
}

canonical_decompiled_code:
void __noreturn func1()
{
longjmp(begin, 0);
}

original_code:
void
reset(void)
{
 longjmp(begin, 0);
}

canonical_original_code:
void reset()
{
 longjmp(begin, 0);
}


main

canonical_name: main

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

v3 = "hoc";
if ( argc > 0 )
v3 = *argv;
argv0 = (__int64)v3;
init(argc, argv, envp);
setjmp(begin);
initcode();
while ( (unsigned int)yyparse() )
{
execute(&prog);
initcode();
}
exit(0);
}

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

v3 = "hoc";
if ( argc > 0 )
v3 = *argv;
argv0 = (__int64)v3;
init(argc, argv, envp);
setjmp(begin);
initcode();
while ( (unsigned int)func0() )
{
execute(&prog);
initcode();
}
exit(0);
}

original_code:
int
main(int argc, char *argv[static argc+1])
{
 argv0 = argc > 0 ? argv[0] : "hoc";
 init();
 _setjmp (begin);
 for (initcode(); yyparse(); initcode())
  execute(prog);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[-1])
{
 argv0 = argc > 0 ? argv[0] : "hoc";
 init();
 _setjmp (begin);
 for (initcode(); yyparse(); initcode())
  execute(prog);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[-1]


warning

decompiled_code:
int __fastcall warning(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s", argv0, a1);
if ( a2 && *a2 )
fprintf(stderr, " %s", a2);
return fprintf(stderr, " near line %zu\n", lineno);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s", argv0, a1);
if ( a2 && *a2 )
fprintf(stderr, " %s", a2);
return fprintf(stderr, " near line %zu\n", lineno);
}

original_code:
void
warning(char const *s, char const *t)
{
 fprintf(stderr, "%s: %s", argv0, s);
 if (t && *t)
  fprintf(stderr, " %s", t);
 fprintf(stderr, " near line %zu\n", lineno);
}

canonical_original_code:
void warning(char *s, char *t)
{
 fprintf(stderr, "%s: %s", argv0, s);
 if (t && *t)
  fprintf(stderr, " %s", t);
 fprintf(stderr, " near line %zu\n", lineno);
}

variable_types:
s
char *

variable_types:
t
char *


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
return warning(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return func0(a1, 0LL);
}

original_code:
void
yyerror(char const *s)
{
 warning(s, ((void *)0));
}

canonical_original_code:
void yyerror(char *s)
{
 warning(s, ((void *)0));
}


execerror

decompiled_code:
__int64 __fastcall execerror(const char *a1, const char *a2)
{
warning(a1, a2);
return reset();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
func0(a1, a2);
return reset();
}

original_code:
void
execerror(char const *s, char const *t)
{
 warning(s, t);
 reset();
}

canonical_original_code:
void execerror(char *s, char *t)
{
 warning(s, t);
 reset();
}


initcode

decompiled_code:
void initcode()
{
stackp = (__int64)&stack;
progp = (__int64)&prog;
}

canonical_decompiled_code:
void func1()
{
stackp = (__int64)&stack;
progp = (__int64)&prog;
}

original_code:
void
initcode(void)
{
 stackp = stack;
 progp = prog;
}

canonical_original_code:
void initcode()
{
 stackp = stack;
 progp = prog;
}


pop

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

if ( stackp <= (unsigned __int64)&stack )
execerror("stack underflow", 0LL);
result = *(_QWORD *)(stackp - 8);
stackp -= 8LL;
return result;
}

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

if ( stackp <= (unsigned __int64)&stack )
execerror("stack underflow", 0LL);
result = *(_QWORD *)(stackp - 8);
stackp -= 8LL;
return result;
}

original_code:
Datum
pop(void)
{
 if (stackp <= stack)
  execerror("stack underflow", ((void *)0));
 return *--stackp;
}

canonical_original_code:
union Datum pop()
{
 if (stackp <= stack)
  execerror("stack underflow", ((void *)0));
 return *--stackp;
}

return_type: union Datum { double val; struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; } *sym; }

user_defined_types: union Datum { double val; struct Symbol *sym; }


constpush

decompiled_code:
__int64 constpush()
{
__int64 v0; // rdi

v0 = *(_QWORD *)pc;
pc += 8LL;
push(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdi

v0 = *(_QWORD *)pc;
pc += 8LL;
func0(v0);
return 0LL;
}

original_code:
Datum
constpush(void)
{
 push((Datum){.val = (*pc++).val});
 return (Datum){0};
}

canonical_original_code:
union Datum constpush()
{
 push((union Datum){.val = (*pc++).val});
 return (union Datum){0};
}

user_defined_types: struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; }


varpush

decompiled_code:
__int64 varpush()
{
__int64 v0; // rdi

v0 = *(_QWORD *)pc;
pc += 8LL;
push(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rdi

v0 = *(_QWORD *)pc;
pc += 8LL;
func0(v0);
return 0LL;
}

original_code:
Datum
varpush(void)
{
 push((Datum){.sym = (*pc++).sym});
 return (Datum){0};
}

canonical_original_code:
union Datum varpush()
{
 push((union Datum){.sym = (*pc++).sym});
 return (union Datum){0};
}


bltin

decompiled_code:
__int64 bltin()
{
double v0; // xmm0_8
double (__fastcall **v1)(double); // rax
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = (double (__fastcall **)(double))pc;
pc += 8LL;
*(double *)&v2 = (*v1)(v0);
push(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
double v0; // xmm0_8
double (__fastcall **v1)(double); // rax
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = (double (__fastcall **)(double))pc;
pc += 8LL;
*(double *)&v2 = (*v1)(v0);
func0(v2);
return 0LL;
}

original_code:
Datum
bltin(void)
{
 Datum d = pop();
 d.val = (*pc++).func(d.val);
 push(d);
 return (Datum){0};
}

canonical_original_code:
union Datum bltin()
{
 union Datum d = pop();
 d.val = (*pc++).func(d.val);
 push(d);
 return (union Datum){0};
}

variable_types: union Datum { double val; struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; } *sym; }


eval

decompiled_code:
__int64 eval()
{
__int64 v0; // rax
__int64 v1; // rbp

v0 = pop();
v1 = v0;
if ( *(_DWORD *)(v0 + 8) == 261 )
{
execerror("undefined variable", *(_QWORD *)v0);
push(*(_QWORD *)(v1 + 16));
}
else
{
push(*(_QWORD *)(v0 + 16));
}
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rax
__int64 v1; // rbp

v0 = func2();
v1 = v0;
if ( *(_DWORD *)(v0 + 8) == 261 )
{
execerror("undefined variable", *(_QWORD *)v0);
func0(*(_QWORD *)(v1 + 16));
}
else
{
func0(*(_QWORD *)(v0 + 16));
}
return 0LL;
}

original_code:
Datum
eval(void)
{
 Datum d = pop();
 if (d.sym->type == 261)
  execerror("undefined variable", d.sym->name);
 d.val = d.sym->val;
 push(d);
 return (Datum){0};
}

canonical_original_code:
union Datum eval()
{
 union Datum d = pop();
 if (d.sym->type == 261)
  execerror("undefined variable", d.sym->name);
 d.val = d.sym->val;
 push(d);
 return (union Datum){0};
}


add

decompiled_code:
__int64 add()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
*(double *)&v1 = v0 + COERCE_DOUBLE(pop());
push(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
*(double *)&v1 = v0 + COERCE_DOUBLE(pop());
func0(v1);
return 0LL;
}

original_code:
Datum
add(void)
{
 Datum d2 = pop();
 Datum d1 = pop();
 d1.val += d2.val;
 push(d1);
 return (Datum){0};
}

canonical_original_code:
union Datum add()
{
 union Datum d2 = pop();
 union Datum d1 = pop();
 d1.val += d2.val;
 push(d1);
 return (union Datum){0};
}


sub

decompiled_code:
__int64 sub()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
push(COERCE__INT64(v1 - v0));
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
func0(COERCE__INT64(v1 - v0));
return 0LL;
}

original_code:
Datum
sub(void)
{
 Datum d2 = pop();
 Datum d1 = pop();
 d1.val -= d2.val;
 push(d1);
 return (Datum){0};
}

canonical_original_code:
union Datum sub()
{
 union Datum d2 = pop();
 union Datum d1 = pop();
 d1.val -= d2.val;
 push(d1);
 return (union Datum){0};
}


mul

decompiled_code:
__int64 mul()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
*(double *)&v1 = v0 * COERCE_DOUBLE(pop());
push(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
*(double *)&v1 = v0 * COERCE_DOUBLE(pop());
func0(v1);
return 0LL;
}

original_code:
Datum
mul(void)
{
 Datum d2 = pop();
 Datum d1 = pop();
 d1.val *= d2.val;
 push(d1);
 return (Datum){0};
}

canonical_original_code:
union Datum mul()
{
 union Datum d2 = pop();
 union Datum d1 = pop();
 d1.val *= d2.val;
 push(d1);
 return (union Datum){0};
}


divd

decompiled_code:
__int64 divd()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
push(COERCE__INT64(v1 / v0));
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
func0(COERCE__INT64(v1 / v0));
return 0LL;
}

original_code:
Datum
divd(void)
{
 Datum d2 = pop();
 Datum d1 = pop();
 d1.val /= d2.val;
 push(d1);
 return (Datum){0};
}

canonical_original_code:
union Datum divd()
{
 union Datum d2 = pop();
 union Datum d1 = pop();
 d1.val /= d2.val;
 push(d1);
 return (union Datum){0};
}


mod

decompiled_code:
__int64 mod()
{
double v0; // rbx
double v1; // rax
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
*(double *)&v2 = fmod(v1, v0);
push(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
double v0; // rbx
double v1; // rax
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
*(double *)&v2 = fmod(v1, v0);
func0(v2);
return 0LL;
}

original_code:
Datum
mod(void)
{
 Datum d2 = pop();
 Datum d1 = pop();
 d1.val = fmod(d1.val, d2.val);
 push(d1);
 return (Datum){0};
}

canonical_original_code:
union Datum mod()
{
 union Datum d2 = pop();
 union Datum d1 = pop();
 d1.val = fmod(d1.val, d2.val);
 push(d1);
 return (union Datum){0};
}


negate

decompiled_code:
__int64 negate()
{
__int64 v0; // rax

v0 = pop();
push(v0 ^ LC3);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rax

v0 = func2();
func0(v0 ^ LC3);
return 0LL;
}

original_code:
Datum
negate(void)
{
 Datum d = pop();
 d.val = -d.val;
 push(d);
 return (Datum){0};
}

canonical_original_code:
union Datum negate()
{
 union Datum d = pop();
 d.val = -d.val;
 push(d);
 return (union Datum){0};
}


power

decompiled_code:
__int64 power()
{
double v0; // rbx
double v1; // rax
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
*(double *)&v2 = pow(v1, v0);
push(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
double v0; // rbx
double v1; // rax
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
*(double *)&v2 = pow(v1, v0);
func0(v2);
return 0LL;
}

original_code:
Datum
power(void)
{
 Datum d2 = pop();
 Datum d1 = pop();
 d1.val = pow(d1.val, d2.val);
 push(d1);
 return (Datum){0};
}

canonical_original_code:
union Datum power()
{
 union Datum d2 = pop();
 union Datum d1 = pop();
 d1.val = pow(d1.val, d2.val);
 push(d1);
 return (union Datum){0};
}


assign

decompiled_code:
__int64 assign()
{
__int64 v0; // rbx
__int64 v1; // rbp

v0 = pop();
v1 = pop();
if ( ((*(_DWORD *)(v0 + 8) - 259) & 0xFFFFFFFD) != 0 )
execerror("assignment to non-variable", *(_QWORD *)v0);
*(_QWORD *)(v0 + 16) = v1;
*(_DWORD *)(v0 + 8) = 259;
push(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rbx
__int64 v1; // rbp

v0 = func2();
v1 = func2();
if ( ((*(_DWORD *)(v0 + 8) - 259) & 0xFFFFFFFD) != 0 )
execerror("assignment to non-variable", *(_QWORD *)v0);
*(_QWORD *)(v0 + 16) = v1;
*(_DWORD *)(v0 + 8) = 259;
func0(v1);
return 0LL;
}

original_code:
Datum
assign(void)
{
 Datum d1 = pop();
 Datum d2 = pop();
 if (d1.sym->type != 259 && d1.sym->type != 261)
  execerror("assignment to non-variable", d1.sym->name);
 d1.sym->val = d2.val;
 d1.sym->type = 259;
 push(d2);
 return (Datum){0};
}

canonical_original_code:
union Datum assign()
{
 union Datum d1 = pop();
 union Datum d2 = pop();
 if (d1.sym->type != 259 && d1.sym->type != 261)
  execerror("assignment to non-variable", d1.sym->name);
 d1.sym->val = d2.val;
 d1.sym->type = 259;
 push(d2);
 return (union Datum){0};
}


print

decompiled_code:
__int64 print()
{
double v0; // r12

v0 = COERCE_DOUBLE(pop());
printf("\t%.8g\n", v0);
return *(_QWORD *)&v0;
}

canonical_decompiled_code:
__int64 func15()
{
double v0; // r12

v0 = COERCE_DOUBLE(pop());
printf("\t%.8g\n", v0);
return *(_QWORD *)&v0;
}

original_code:
Datum
print(void)
{
 Datum d = pop();
 printf("\t%.8g\n", d.val);
 return d;
}

canonical_original_code:
union Datum print()
{
 union Datum d = pop();
 printf("\t%.8g\n", d.val);
 return d;
}


emalloc

decompiled_code:
void *__fastcall emalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
execerror("out of memory", 0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
execerror("out of memory", 0LL);
result = 0LL;
}
return result;
}

original_code:
void *
emalloc(size_t n)
{
 void *p = malloc(n);
 if (p == ((void *)0))
  execerror("out of memory", ((void *)0));
 return p;
}

canonical_original_code:
void *emalloc(unsigned long n)
{
 void *p = malloc(n);
 if (p == ((void *)0))
  execerror("out of memory", ((void *)0));
 return p;
}

variable_types:
n
unsigned long

variable_types:
p
void *

return_type: void *


lookup

decompiled_code:
__int64 __fastcall lookup(char *s2)
{
__int64 i; // r12

for ( i = symlist; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
__int64 i; // r12

for ( i = symlist; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, s2) )
break;
}
return i;
}

original_code:
Symbol *
lookup(char const *s)
{
 for (Symbol *sp = symlist; sp != ((void *)0); sp = sp->next)
  if (strcmp(sp->name, s) == 0)
   return sp;
 return ((void *)0);
}

canonical_original_code:
struct Symbol *lookup(char *s)
{
 for (struct Symbol *sp = symlist; sp != ((void *)0); sp = sp->next)
  if (strcmp(sp->name, s) == 0)
   return sp;
 return ((void *)0);
}

variable_types: struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; } *


install

decompiled_code:
double *__fastcall install(char *src, int a2, double a3)
{
double *v3; // r12
size_t v4; // rax
char *v5; // rax
char *v6; // rax
__int64 v7; // rax
double *result; // rax

v3 = (double *)emalloc(0x20uLL);
v4 = strlen(src);
v5 = (char *)emalloc(v4 + 1);
v6 = strcpy(v5, src);
*((_DWORD *)v3 + 2) = a2;
*(_QWORD *)v3 = v6;
v7 = symlist;
v3[2] = a3;
*((_QWORD *)v3 + 3) = v7;
result = v3;
symlist = (__int64)v3;
return result;
}

canonical_decompiled_code:
double *__fastcall func2(char *src, int a2, double a3)
{
double *v3; // r12
size_t v4; // rax
char *v5; // rax
char *v6; // rax
__int64 v7; // rax
double *result; // rax

v3 = (double *)func0(0x20uLL);
v4 = strlen(src);
v5 = (char *)func0(v4 + 1);
v6 = strcpy(v5, src);
*((_DWORD *)v3 + 2) = a2;
*(_QWORD *)v3 = v6;
v7 = symlist;
v3[2] = a3;
*((_QWORD *)v3 + 3) = v7;
result = v3;
symlist = (__int64)v3;
return result;
}

original_code:
Symbol *
install(char const *s, int t, double d)
{
 Symbol *sp = emalloc(sizeof *sp);
 char *nbuf = emalloc(strlen(s)+1);
 strcpy(nbuf, s);
 *sp = (Symbol) {
  .name = nbuf,
  .type = t,
  .val = d,
  .next = symlist,
 };
 symlist = sp;
 return sp;
}

canonical_original_code:
struct Symbol *install(char *s, int t, double d)
{
 struct Symbol *sp = emalloc(sizeof *sp);
 char *nbuf = emalloc(strlen(s)+1);
 strcpy(nbuf, s);
 *sp = (struct Symbol) {
  .name = nbuf,
  .type = t,
  .val = d,
  .next = symlist,
 };
 symlist = sp;
 return sp;
}

variable_types: t int

variable_types: d double

variable_types:
nbuf
char *

return_type: struct Symbol { char *name; int type; union { double val; double (*func)(double); }; struct Symbol *next; } *


yylex

decompiled_code:
__int64 yylex()
{
int v0; // eax
__int64 v1; // r12
const unsigned __int16 **v2; // rbp
unsigned __int16 v3; // ax
__int64 result; // rax
__int64 v5; // rbx
int v6; // eax
__int64 v7; // rax
unsigned int v8; // er12
char v9; // [rsp+1h] [rbp-89h]
char v10[136]; // [rsp+2h] [rbp-88h] BYREF

do
{
do
v0 = getchar();
while ( v0 == 32 );
LODWORD(v1) = v0;
}
while ( v0 == 9 );
if ( v0 == -1 )
return 0LL;
if ( v0 == 46 || (v2 = _ctype_b_loc(), v3 = (*v2)[(int)v1], (v3 & 0x800) != 0) )
{
ungetc(v1, stdin);
_isoc99_scanf(&unk_181, &yylval);
result = 258LL;
}
else if ( (v3 & 0x400) != 0 )
{
v5 = 0LL;
while ( 1 )
{
++v5;
*(&v9 + v5) = v1;
v6 = getchar();
LODWORD(v1) = v6;
if ( v6 == -1 )
break;
if ( ((*v2)[v6] & 8) == 0 )
goto LABEL_18;
if ( v5 == 100 )
goto LABEL_17;
}
if ( (*(_BYTE *)(*v2 - 1) & 8) == 0 )
goto LABEL_18;
do
LABEL_17:
v1 = getchar();
while ( ((*v2)[v1] & 8) != 0 );
LABEL_18:
ungetc(v1, stdin);
v10[v5] = 0;
v7 = lookup(v10);
if ( !v7 )
v7 = install(v10, 261LL, 0.0);
v8 = *(_DWORD *)(v7 + 8);
yylval = v7;
if ( v8 == 261 )
v8 = 259;
result = v8;
}
else
{
if ( (_DWORD)v1 == 10 )
{
++lineno;
LODWORD(v1) = 59;
}
result = (unsigned int)v1;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 v1; // r12
const unsigned __int16 **v2; // rbp
unsigned __int16 v3; // ax
__int64 result; // rax
__int64 v5; // rbx
int v6; // eax
__int64 v7; // rax
unsigned int v8; // er12
char v9; // [rsp+1h] [rbp-89h]
char v10[136]; // [rsp+2h] [rbp-88h] BYREF

do
{
do
v0 = getchar();
while ( v0 == 32 );
LODWORD(v1) = v0;
}
while ( v0 == 9 );
if ( v0 == -1 )
return 0LL;
if ( v0 == 46 || (v2 = _ctype_b_loc(), v3 = (*v2)[(int)v1], (v3 & 0x800) != 0) )
{
ungetc(v1, stdin);
_isoc99_scanf(&unk_181, &yylval);
result = 258LL;
}
else if ( (v3 & 0x400) != 0 )
{
v5 = 0LL;
while ( 1 )
{
++v5;
*(&v9 + v5) = v1;
v6 = getchar();
LODWORD(v1) = v6;
if ( v6 == -1 )
break;
if ( ((*v2)[v6] & 8) == 0 )
goto LABEL_18;
if ( v5 == 100 )
goto LABEL_17;
}
if ( (*(_BYTE *)(*v2 - 1) & 8) == 0 )
goto LABEL_18;
do
LABEL_17:
v1 = getchar();
while ( ((*v2)[v1] & 8) != 0 );
LABEL_18:
ungetc(v1, stdin);
v10[v5] = 0;
v7 = lookup(v10);
if ( !v7 )
v7 = install(v10, 261LL, 0.0);
v8 = *(_DWORD *)(v7 + 8);
yylval = v7;
if ( v8 == 261 )
v8 = 259;
result = v8;
}
else
{
if ( (_DWORD)v1 == 10 )
{
++lineno;
LODWORD(v1) = 59;
}
result = (unsigned int)v1;
}
return result;
}

original_code:
int
yylex(void)
{
 int c;
 while ((c=getchar()) == ' ' || c == '\t')
  ;
 if (c == (-1))
  return 0;
 if (c == '.' || ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
  ungetc(c, stdin);
  scanf("%lf", &yylval.val);
  return 258;
 }
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)) {
  char sbuf[100+1];
  size_t i = 0;
  do {
   sbuf[i++] = c;
  } while ((c=getchar()) != (-1) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalnum) && i<100);
  while (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalnum))
   c=getchar();
  ungetc(c, stdin);
  sbuf[i] = '\0';
  Symbol *s = lookup(sbuf);
  if (s == ((void *)0))
   s = install(sbuf, 261, 0.0);
  yylval.sym = s;
  return s->type == 261 ? 259 : s->type;
 }
 if (c == '\n') {
  lineno++;
  return ';';
 }
 return c;
}

canonical_original_code:
int yylex()
{
 int c;
 while ((c=getchar()) == ' ' || c == '\t')
  ;
 if (c == (-1))
  return 0;
 if (c == '.' || ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
  ungetc(c, stdin);
  scanf("%lf", &yylval.val);
  return 258;
 }
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)) {
  char sbuf[-1];
  unsigned long i = 0;
  do {
   sbuf[i++] = c;
  } while ((c=getchar()) != (-1) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalnum) && i<100);
  while (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalnum))
   c=getchar();
  ungetc(c, stdin);
  sbuf[i] = '\0';
  struct Symbol *s = lookup(sbuf);
  if (s == ((void *)0))
   s = install(sbuf, 261, 0.0);
  yylval.sym = s;
  return s->type == 261 ? 259 : s->type;
 }
 if (c == '\n') {
  lineno++;
  return ';';
 }
 return c;
}

variable_types: c int

variable_types:
sbuf
char [-1]

variable_types:
i
unsigned long


usage

repo: jcsalterego/gifdump

decompiled_code:
size_t usage()
{
return fwrite("Usage: gifdump <gif>\n", 1uLL, 0x15uLL, _bss_start);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite("Usage: gifdump <gif>\n", 1uLL, 0x15uLL, _bss_start);
}

original_code:
void
usage ()
{
  fprintf(stderr, "Usage: gifdump <gif>\n");
}

canonical_original_code:
void usage()
{
  fprintf(stderr, "Usage: gifdump <gif>\n");
}


decompiled_code:
void *__fastcall gif_init(__int64 a1)
{
void *result; // rax

*(_BYTE *)a1 = 0;
*(_QWORD *)(a1 + 8) = malloc(4uLL);
result = malloc(4uLL);
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1)
{
void *result; // rax

*(_BYTE *)a1 = 0;
*(_QWORD *)(a1 + 8) = malloc(4uLL);
result = malloc(4uLL);
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void
gif_init (gif *self)
{
  self->valid = 0;
  self->signature = (char *)malloc(sizeof(char)*4);
  self->version = (char *)malloc(sizeof(char)*4);
  self->width = 0;
  self->height = 0;
}

canonical_original_code:
void gif_init(struct gif *self)
{
  self->valid = 0;
  self->signature = (char *)malloc(sizeof(char)*4);
  self->version = (char *)malloc(sizeof(char)*4);
  self->width = 0;
  self->height = 0;
}

variable_types: struct gif { _Bool valid; char *signature; char *version; unsigned int width; unsigned int height; unsigned char global_color_table_flag; unsigned char color_resolution; unsigned char sort_flag; unsigned char global_color_table_size; unsigned char background_color_index; unsigned char pixel_aspect_ratio; } *


decompiled_code:
void *gif_new()
{
void *v0; // r12

v0 = malloc(0x28uLL);
gif_init((__int64)v0);
return v0;
}

canonical_decompiled_code:
void *func9()
{
void *v0; // r12

v0 = malloc(0x28uLL);
func8((__int64)v0);
return v0;
}

original_code:
gif *
gif_new ()
{
  gif *self = (gif *)malloc(sizeof(gif));
  gif_init(self);
  return self;
}

canonical_original_code:
struct gif *gif_new()
{
  struct gif *self = (gif *)malloc(sizeof(gif));
  gif_init(self);
  return self;
}

return_type: struct gif { _Bool valid; char *signature; char *version; unsigned int width; unsigned int height; unsigned char global_color_table_flag; unsigned char color_resolution; unsigned char sort_flag; unsigned char global_color_table_size; unsigned char background_color_index; unsigned char pixel_aspect_ratio; } *


decompiled_code:
int __fastcall gif_dump_txt(__int64 a1)
{
const char *v1; // rsi
int result; // eax
__int64 v3; // rsi
const char *v4; // rdx
__int64 v5; // rsi
const char *v6; // rdx

v1 = "no";
if ( *(_BYTE *)a1 )
v1 = "yes";
result = printf("valid:\t%s\n", v1);
if ( *(_BYTE *)a1 )
{
printf("width:\t%d\n", *(unsigned int *)(a1 + 24));
printf("height:\t%d\n", *(unsigned int *)(a1 + 28));
puts("global color table");
v3 = *(unsigned __int8 *)(a1 + 32);
v4 = "no";
if ( (_BYTE)v3 == 1 )
v4 = "yes";
printf("\tpresent:\t%d (%s)\n", v3, v4);
if ( *(_BYTE *)(a1 + 32) )
{
printf(
"\tcolor res:\t%d (%d bits/pixel)\n",
*(unsigned __int8 *)(a1 + 33),
(unsigned int)*(unsigned __int8 *)(a1 + 33) + 1);
v5 = *(unsigned __int8 *)(a1 + 34);
v6 = "desc";
if ( (_BYTE)v5 != 1 )
v6 = "asc";
printf("\tsort flag:\t%d (%s)\n", v5, v6);
printf("\tsize: \t%d (%d)\n", *(unsigned __int8 *)(a1 + 35), (unsigned int)(1 << (*(_BYTE *)(a1 + 35) + 1)));
printf("\tbgcolor index:\t%d\n", *(unsigned __int8 *)(a1 + 36));
}
result = printf("pixel aspect ratio:\t%d\n", *(unsigned __int8 *)(a1 + 37));
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
const char *v1; // rsi
int result; // eax
__int64 v3; // rsi
const char *v4; // rdx
__int64 v5; // rsi
const char *v6; // rdx

v1 = "no";
if ( *(_BYTE *)a1 )
v1 = "yes";
result = printf("valid:\t%s\n", v1);
if ( *(_BYTE *)a1 )
{
printf("width:\t%d\n", *(unsigned int *)(a1 + 24));
printf("height:\t%d\n", *(unsigned int *)(a1 + 28));
puts("global color table");
v3 = *(unsigned __int8 *)(a1 + 32);
v4 = "no";
if ( (_BYTE)v3 == 1 )
v4 = "yes";
printf("\tpresent:\t%d (%s)\n", v3, v4);
if ( *(_BYTE *)(a1 + 32) )
{
printf(
"\tcolor res:\t%d (%d bits/pixel)\n",
*(unsigned __int8 *)(a1 + 33),
(unsigned int)*(unsigned __int8 *)(a1 + 33) + 1);
v5 = *(unsigned __int8 *)(a1 + 34);
v6 = "desc";
if ( (_BYTE)v5 != 1 )
v6 = "asc";
printf("\tsort flag:\t%d (%s)\n", v5, v6);
printf("\tsize: \t%d (%d)\n", *(unsigned __int8 *)(a1 + 35), (unsigned int)(1 << (*(_BYTE *)(a1 + 35) + 1)));
printf("\tbgcolor index:\t%d\n", *(unsigned __int8 *)(a1 + 36));
}
result = printf("pixel aspect ratio:\t%d\n", *(unsigned __int8 *)(a1 + 37));
}
return result;
}

original_code:
void
gif_dump_txt (gif *self)
{
  printf("valid:\t%s\n", self->valid ? "yes" : "no");
  if (self->valid) {
    printf("width:\t%d\n", self->width);
    printf("height:\t%d\n", self->height);
    printf("global color table\n");
    printf("\tpresent:\t%d (%s)\n",
           self->global_color_table_flag,
           self->global_color_table_flag == 1 ? "yes" : "no");
    if (self->global_color_table_flag) {
      printf("\tcolor res:\t%d (%d bits/pixel)\n",
             self->color_resolution, self->color_resolution + 1);
      printf("\tsort flag:\t%d (%s)\n", self->sort_flag,
             self->sort_flag == 1 ? "desc" : "asc");
      printf("\tsize:     \t%d (%d)\n",
             self->global_color_table_size,
             1 << (self->global_color_table_size + 1));
      printf("\tbgcolor index:\t%d\n", self->background_color_index);
    }
    printf("pixel aspect ratio:\t%d\n", self->pixel_aspect_ratio);
  }
}

canonical_original_code:
void gif_dump_txt(struct gif *self)
{
  printf("valid:\t%s\n", self->valid ? "yes" : "no");
  if (self->valid) {
    printf("width:\t%d\n", self->width);
    printf("height:\t%d\n", self->height);
    printf("global color table\n");
    printf("\tpresent:\t%d (%s)\n",
           self->global_color_table_flag,
           self->global_color_table_flag == 1 ? "yes" : "no");
    if (self->global_color_table_flag) {
      printf("\tcolor res:\t%d (%d bits/pixel)\n",
             self->color_resolution, self->color_resolution + 1);
      printf("\tsort flag:\t%d (%s)\n", self->sort_flag,
             self->sort_flag == 1 ? "desc" : "asc");
      printf("\tsize:     \t%d (%d)\n",
             self->global_color_table_size,
             1 << (self->global_color_table_size + 1));
      printf("\tbgcolor index:\t%d\n", self->background_color_index);
    }
    printf("pixel aspect ratio:\t%d\n", self->pixel_aspect_ratio);
  }
}

user_defined_types: struct gif { _Bool valid; char *signature; char *version; unsigned int width; unsigned int height; unsigned char global_color_table_flag; unsigned char color_resolution; unsigned char sort_flag; unsigned char global_color_table_size; unsigned char background_color_index; unsigned char pixel_aspect_ratio; }


decompiled_code:
// attributes: thunk
int __fastcall gif_dump(__int64 a1)
{
return gif_dump_txt(a1);
}

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

original_code:
void
gif_dump (gif *self)
{
  gif_dump_txt(self);
}

canonical_original_code:
void gif_dump(struct gif *self)
{
  gif_dump_txt(self);
}


repo: jcwynholds/mumps

decompiled_code:
__int64 __fastcall Get_GBDs(int a1)
{
int v1; // er12
__int64 result; // rax
int v4; // ebx
time_t v5; // rax
int v6; // er10
__int64 v7; // r8
int v8; // esi
__int64 v9; // rcx
__int64 v10; // r9
__int64 v11; // rdx
__int64 v12; // rdi
__int64 v13; // rdx

v1 = 0;
while ( 1 )
{
while ( (unsigned __int16)SemOp(2LL, (unsigned int)-*(_DWORD *)(systab + 16LL)) )
;
result = *(_QWORD *)(*(_QWORD *)(systab + 8LL * (volnum - 1) + 228) + 8216LL);
if ( !result )
{
v4 = 0;
goto LABEL_8;
}
if ( a1 <= 1 )
return result;
v4 = 1;
while ( 1 )
{
result = *(_QWORD *)(result + 4);
if ( !result )
break;
if ( a1 == ++v4 )
return result;
}
LABEL_8:
v5 = time(0LL);
v6 = hash_start;
v7 = v5;
v8 = (hash_start + 1) & 0x3FF;
v9 = *(_QWORD *)(systab + 8LL * (volnum - 1) + 228);
do
{
v10 = v9 + 8LL * v8;
result = *(_QWORD *)(v10 + 24);
if ( result )
{
v11 = 0LL;
do
{
if ( *(_DWORD *)result )
{
if ( !*(_QWORD *)(result + 20) )
{
v13 = *(_QWORD *)(result + 28);
if ( v7 >= v13 && v13 > 0 && ++v4 >= a1 )
return result;
}
v11 = result;
result = *(_QWORD *)(result + 4);
}
else
{
v12 = *(_QWORD *)(result + 4);
++v4;
if ( v11 )
{
*(_QWORD *)(v11 + 4) = v12;
*(_QWORD *)(result + 4) = *(_QWORD *)(v9 + 8216);
*(_QWORD *)(v9 + 8216) = result;
*(_QWORD *)(result + 20) = 0LL;
*(_QWORD *)(result + 28) = 0LL;
if ( a1 <= v4 )
return result;
result = *(_QWORD *)(v11 + 4);
}
else
{
*(_QWORD *)(v10 + 24) = v12;
*(_QWORD *)(result + 4) = *(_QWORD *)(v9 + 8216);
*(_QWORD *)(v9 + 8216) = result;
*(_QWORD *)(result + 20) = 0LL;
*(_QWORD *)(result + 28) = 0LL;
if ( a1 <= v4 )
return result;
result = *(_QWORD *)(v10 + 24);
}
}
}
while ( result );
}
v8 = ((_WORD)v8 + 1) & 0x3FF;
}
while ( v6 != v8 );
++v1;
SemOp(2LL, (unsigned int)-curr_lock);
sleep(1u);
if ( v1 > 60 )
panic("Get_GBDs: Can't get enough GDBs after 60 seconds");
}
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // er12
__int64 result; // rax
int v4; // ebx
time_t v5; // rax
int v6; // er10
__int64 v7; // r8
int v8; // esi
__int64 v9; // rcx
__int64 v10; // r9
__int64 v11; // rdx
__int64 v12; // rdi
__int64 v13; // rdx

v1 = 0;
while ( 1 )
{
while ( (unsigned __int16)SemOp(2LL, (unsigned int)-*(_DWORD *)(systab + 16LL)) )
;
result = *(_QWORD *)(*(_QWORD *)(systab + 8LL * (volnum - 1) + 228) + 8216LL);
if ( !result )
{
v4 = 0;
goto LABEL_8;
}
if ( a1 <= 1 )
return result;
v4 = 1;
while ( 1 )
{
result = *(_QWORD *)(result + 4);
if ( !result )
break;
if ( a1 == ++v4 )
return result;
}
LABEL_8:
v5 = time(0LL);
v6 = hash_start;
v7 = v5;
v8 = (hash_start + 1) & 0x3FF;
v9 = *(_QWORD *)(systab + 8LL * (volnum - 1) + 228);
do
{
v10 = v9 + 8LL * v8;
result = *(_QWORD *)(v10 + 24);
if ( result )
{
v11 = 0LL;
do
{
if ( *(_DWORD *)result )
{
if ( !*(_QWORD *)(result + 20) )
{
v13 = *(_QWORD *)(result + 28);
if ( v7 >= v13 && v13 > 0 && ++v4 >= a1 )
return result;
}
v11 = result;
result = *(_QWORD *)(result + 4);
}
else
{
v12 = *(_QWORD *)(result + 4);
++v4;
if ( v11 )
{
*(_QWORD *)(v11 + 4) = v12;
*(_QWORD *)(result + 4) = *(_QWORD *)(v9 + 8216);
*(_QWORD *)(v9 + 8216) = result;
*(_QWORD *)(result + 20) = 0LL;
*(_QWORD *)(result + 28) = 0LL;
if ( a1 <= v4 )
return result;
result = *(_QWORD *)(v11 + 4);
}
else
{
*(_QWORD *)(v10 + 24) = v12;
*(_QWORD *)(result + 4) = *(_QWORD *)(v9 + 8216);
*(_QWORD *)(v9 + 8216) = result;
*(_QWORD *)(result + 20) = 0LL;
*(_QWORD *)(result + 28) = 0LL;
if ( a1 <= v4 )
return result;
result = *(_QWORD *)(v10 + 24);
}
}
}
while ( result );
}
v8 = ((_WORD)v8 + 1) & 0x3FF;
}
while ( v6 != v8 );
++v1;
SemOp(2LL, (unsigned int)-curr_lock);
sleep(1u);
if ( v1 > 60 )
panic("Get_GBDs: Can't get enough GDBs after 60 seconds");
}
}

original_code:
void Get_GBDs(int greqd)
{ int i;
  int curr;
  gbd *ptr;
  gbd *last;
  time_t now;
  int pass = 0;
start:
  while (SemOp(2, (-systab->maxjob)));
  ptr = systab->vol[volnum-1]->gbd_hash [1024];
  curr = 0;
  while (ptr != ((void *)0))
  { curr++;
    if (curr >= greqd)
    { return;
    }
    ptr = ptr->next;
  }
  now = time(0) + 1;
  i = (hash_start + 1) & (1024 - 1);
  while (1)
  { ptr = systab->vol[volnum-1]->gbd_hash[i];
    last = ((void *)0);
    while (ptr != ((void *)0))
    { if (ptr->block == 0)
      { if (last == ((void *)0))
        { systab->vol[volnum-1]->gbd_hash[i] = ptr->next;
        }
        else
 { last->next = ptr->next;
 }
 ptr->next = systab->vol[volnum-1]->gbd_hash [1024];
 systab->vol[volnum-1]->gbd_hash [1024] = ptr;
 ptr->dirty = ((void *)0);
 ptr->last_accessed = (time_t) 0;
 curr++;
        if (curr >= greqd)
        { return;
        }
 if (last == ((void *)0))
 { ptr = systab->vol[volnum-1]->gbd_hash[i];
 }
 else
 { ptr = last->next;
 }
 continue;
      }
      if ((ptr->dirty == ((void *)0)) &&
   (ptr->last_accessed < now) &&
   (ptr->last_accessed > 0))
      { curr++;
        if (curr >= greqd)
        { return;
        }
      }
      last = ptr;
      ptr = ptr->next;
    }
    i = (i + 1) & (1024 - 1);
    if (i == hash_start)
    { break;
    }
  }
  SemOp(2, -curr_lock);
  sleep(1);
  pass++;
  if (pass > 60)
  { panic("Get_GBDs: Can't get enough GDBs after 60 seconds");
  }
  goto start;
}

canonical_original_code:
void Get_GBDs(int greqd)
{ int i;
  int curr;
  struct GBD *ptr;
  struct GBD *last;
  long now;
  int pass = 0;
start:
  while (SemOp(2, (-systab->maxjob)));
  ptr = systab->vol[volnum-1]->gbd_hash [1024];
  curr = 0;
  while (ptr != ((void *)0))
  { curr++;
    if (curr >= greqd)
    { return;
    }
    ptr = ptr->next;
  }
  now = time(0) + 1;
  i = (hash_start + 1) & (1024 - 1);
  while (1)
  { ptr = systab->vol[volnum-1]->gbd_hash[i];
    last = ((void *)0);
    while (ptr != ((void *)0))
    { if (ptr->block == 0)
      { if (last == ((void *)0))
        { systab->vol[volnum-1]->gbd_hash[i] = ptr->next;
        }
        else
 { last->next = ptr->next;
 }
 ptr->next = systab->vol[volnum-1]->gbd_hash [1024];
 systab->vol[volnum-1]->gbd_hash [1024] = ptr;
 ptr->dirty = ((void *)0);
 ptr->last_accessed = (long) 0;
 curr++;
        if (curr >= greqd)
        { return;
        }
 if (last == ((void *)0))
 { ptr = systab->vol[volnum-1]->gbd_hash[i];
 }
 else
 { ptr = last->next;
 }
 continue;
      }
      if ((ptr->dirty == ((void *)0)) &&
   (ptr->last_accessed < now) &&
   (ptr->last_accessed > 0))
      { curr++;
        if (curr >= greqd)
        { return;
        }
      }
      last = ptr;
      ptr = ptr->next;
    }
    i = (i + 1) & (1024 - 1);
    if (i == hash_start)
    { break;
    }
  }
  SemOp(2, -curr_lock);
  sleep(1);
  pass++;
  if (pass > 60)
  { panic("Get_GBDs: Can't get enough GDBs after 60 seconds");
  }
  goto start;
}

variable_types: greqd int

variable_types: i int

variable_types: curr int

variable_types: struct GBD { unsigned int block; struct GBD *next; struct DB_BLOCK { unsigned char type; unsigned char flags; unsigned short spare; unsigned int right_ptr; unsigned short last_idx; unsigned short last_free; unsigned long long global; } *mem; struct GBD *dirty; long last_accessed; } *

variable_types: now long

variable_types: pass int

user_defined_types: struct GBD { unsigned int block; struct GBD *next; struct DB_BLOCK *mem; struct GBD *dirty; long last_accessed; }


original_code:
void Get_GBD()
{ int i;
  time_t now;
  time_t exp;
  time_t old;
  int hash = -1;
  gbd *ptr;
  gbd *oldptr = ((void *)0);
  gbd *last;
start:
  if (systab->vol[volnum-1]->gbd_hash [1024])
  { blk[level]
      = systab->vol[volnum-1]->gbd_hash [1024];
    systab->vol[volnum-1]->gbd_hash [1024]
      = blk[level]->next;
    goto exit;
  }
  now = time(0);
  old = now + 1;
  exp = now - gbd_expired;
  i = (hash_start + 1) & (1024 - 1);
  while (1)
  { ptr = systab->vol[volnum-1]->gbd_hash[i];
    last = ((void *)0);
    while (ptr != ((void *)0))
    { if ((ptr->block == 0) ||
   ((ptr->dirty == ((void *)0)) &&
    (ptr->last_accessed < exp) &&
    (ptr->last_accessed > 0)))
      { if (last == ((void *)0))
 { systab->vol[volnum-1]->gbd_hash[i] = ptr->next;
 }
 else
 { last->next = ptr->next;
 }
 hash_start = i;
 blk[level] = ptr;
 goto exit;
      }
      if ((ptr->dirty == ((void *)0)) &&
   (ptr->last_accessed < old) &&
   (ptr->last_accessed > 0))
      { old = ptr->last_accessed;
 oldptr = ptr;
 hash = i;
      }
      last = ptr;
      ptr = ptr->next;
    }
    i = (i + 1) & (1024 - 1);
    if (i == hash_start)
    { break;
    }
  }
  if (oldptr == ((void *)0))
  { if (writing)
    { panic("Get_GBD: Failed to find an available GBD while writing");
    }
    SemOp(2, -curr_lock);
    sleep(1);
    while (SemOp(2, (-systab->maxjob)));
    goto start;
  }
  ptr = systab->vol[volnum-1]->gbd_hash[hash];
  if (ptr == oldptr)
  { systab->vol[volnum-1]->gbd_hash[hash] = ptr->next;
  }
  else
  { while (ptr->next != oldptr)
    { ptr = ptr->next;
    }
    ptr->next = oldptr->next;
  }
  blk[level] = oldptr;
exit:
  blk[level]->block = 0;
  blk[level]->next = ((void *)0);
  blk[level]->dirty = ((void *)0);
  blk[level]->last_accessed = (time_t) 0;
  idx = (u_short *) blk[level]->mem;
  iidx = (int *) blk[level]->mem;
  return;
}

canonical_original_code:
void Get_GBD()
{ int i;
  long now;
  long exp;
  long old;
  int hash = -1;
  struct GBD *ptr;
  struct GBD *oldptr = ((void *)0);
  struct GBD *last;
start:
  if (systab->vol[volnum-1]->gbd_hash [1024])
  { blk[level]
      = systab->vol[volnum-1]->gbd_hash [1024];
    systab->vol[volnum-1]->gbd_hash [1024]
      = blk[level]->next;
    goto exit;
  }
  now = time(0);
  old = now + 1;
  exp = now - gbd_expired;
  i = (hash_start + 1) & (1024 - 1);
  while (1)
  { ptr = systab->vol[volnum-1]->gbd_hash[i];
    last = ((void *)0);
    while (ptr != ((void *)0))
    { if ((ptr->block == 0) ||
   ((ptr->dirty == ((void *)0)) &&
    (ptr->last_accessed < exp) &&
    (ptr->last_accessed > 0)))
      { if (last == ((void *)0))
 { systab->vol[volnum-1]->gbd_hash[i] = ptr->next;
 }
 else
 { last->next = ptr->next;
 }
 hash_start = i;
 blk[level] = ptr;
 goto exit;
      }
      if ((ptr->dirty == ((void *)0)) &&
   (ptr->last_accessed < old) &&
   (ptr->last_accessed > 0))
      { old = ptr->last_accessed;
 oldptr = ptr;
 hash = i;
      }
      last = ptr;
      ptr = ptr->next;
    }
    i = (i + 1) & (1024 - 1);
    if (i == hash_start)
    { break;
    }
  }
  if (oldptr == ((void *)0))
  { if (writing)
    { panic("Get_GBD: Failed to find an available GBD while writing");
    }
    SemOp(2, -curr_lock);
    sleep(1);
    while (SemOp(2, (-systab->maxjob)));
    goto start;
  }
  ptr = systab->vol[volnum-1]->gbd_hash[hash];
  if (ptr == oldptr)
  { systab->vol[volnum-1]->gbd_hash[hash] = ptr->next;
  }
  else
  { while (ptr->next != oldptr)
    { ptr = ptr->next;
    }
    ptr->next = oldptr->next;
  }
  blk[level] = oldptr;
exit:
  blk[level]->block = 0;
  blk[level]->next = ((void *)0);
  blk[level]->dirty = ((void *)0);
  blk[level]->last_accessed = (long) 0;
  idx = (unsigned short *) blk[level]->mem;
  iidx = (int *) blk[level]->mem;
  return;
}

variable_types: exp long

variable_types: old long

variable_types: hash int

user_defined_types: struct DB_BLOCK { unsigned char type; unsigned char flags; unsigned short spare; unsigned int right_ptr; unsigned short last_idx; unsigned short last_free; unsigned long long global; }


original_code:
short Get_block(u_int blknum)
{ int i;
  short s = -1;
  long long file_off;
  gbd *ptr;
  systab->vol[volnum-1]->stats.logrd++;
  ptr = systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)];
  while (ptr != ((void *)0))
  { if (ptr->block == blknum)
    { blk[level] = ptr;
      while (ptr->last_accessed == (time_t) 0)
      { SchedYield();
      }
      goto exit;
    }
    ptr = ptr->next;
  }
  if (!writing)
  { SemOp( 2, -curr_lock);
    s = SemOp( 2, (-systab->maxjob));
    if (s < 0)
    { return s;
    }
    ptr = systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)];
    while (ptr != ((void *)0))
    { if (ptr->block == blknum)
      { blk[level] = ptr;
 SemOp( 2, (systab->maxjob-1));
        while (ptr->last_accessed == (time_t) 0)
        { SchedYield();
        }
        goto exit;
      }
      ptr = ptr->next;
    }
  }
  systab->vol[volnum-1]->stats.phyrd++;
  Get_GBD();
  blk[level]->block = blknum;
  blk[level]->last_accessed = (time_t) 0;
  i = blknum & (1024 - 1);
  blk[level]->next = systab->vol[volnum-1]->gbd_hash[i];
  systab->vol[volnum-1]->gbd_hash[i] = blk[level];
  if (!writing)
  { SemOp( 2, (systab->maxjob-1));
  }
  file_off = (long long) blknum - 1;
  file_off = (file_off * (long long) systab->vol[volnum-1]->vollab->block_size)
           + (long long) systab->vol[volnum-1]->vollab->header_bytes;
  file_off = lseek( partab.vol_fds[volnum - 1],
      file_off, 0);
  if (file_off < 1)
  { panic("Get_block: lseek() failed!");
  }
  i = read(partab.vol_fds[volnum-1], blk[level]->mem,
    systab->vol[volnum-1]->vollab->block_size);
  if (i < 0)
  { panic("Get_block: read() failed!");
  }
exit:
  blk[level]->last_accessed = time(0);
  if ((writing) && (blk[level]->dirty < (gbd *) 5))
  { blk[level]->dirty = (gbd *) 1;
  }
  Index = 10;
  idx = (u_short *) blk[level]->mem;
  iidx = (int *) blk[level]->mem;
  return 0;
}

canonical_original_code:
short Get_block(unsigned int blknum)
{ int i;
  short s = -1;
  long long file_off;
  struct GBD *ptr;
  systab->vol[volnum-1]->stats.logrd++;
  ptr = systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)];
  while (ptr != ((void *)0))
  { if (ptr->block == blknum)
    { blk[level] = ptr;
      while (ptr->last_accessed == (long) 0)
      { SchedYield();
      }
      goto exit;
    }
    ptr = ptr->next;
  }
  if (!writing)
  { SemOp( 2, -curr_lock);
    s = SemOp( 2, (-systab->maxjob));
    if (s < 0)
    { return s;
    }
    ptr = systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)];
    while (ptr != ((void *)0))
    { if (ptr->block == blknum)
      { blk[level] = ptr;
 SemOp( 2, (systab->maxjob-1));
        while (ptr->last_accessed == (long) 0)
        { SchedYield();
        }
        goto exit;
      }
      ptr = ptr->next;
    }
  }
  systab->vol[volnum-1]->stats.phyrd++;
  Get_GBD();
  blk[level]->block = blknum;
  blk[level]->last_accessed = (long) 0;
  i = blknum & (1024 - 1);
  blk[level]->next = systab->vol[volnum-1]->gbd_hash[i];
  systab->vol[volnum-1]->gbd_hash[i] = blk[level];
  if (!writing)
  { SemOp( 2, (systab->maxjob-1));
  }
  file_off = (long long) blknum - 1;
  file_off = (file_off * (long long) systab->vol[volnum-1]->vollab->block_size)
           + (long long) systab->vol[volnum-1]->vollab->header_bytes;
  file_off = lseek( partab.vol_fds[volnum - 1],
      file_off, 0);
  if (file_off < 1)
  { panic("Get_block: lseek() failed!");
  }
  i = read(partab.vol_fds[volnum-1], blk[level]->mem,
    systab->vol[volnum-1]->vollab->block_size);
  if (i < 0)
  { panic("Get_block: read() failed!");
  }
exit:
  blk[level]->last_accessed = time(0);
  if ((writing) && (blk[level]->dirty < (struct GBD *) 5))
  { blk[level]->dirty = (struct GBD *) 1;
  }
  Index = 10;
  idx = (unsigned short *) blk[level]->mem;
  iidx = (int *) blk[level]->mem;
  return 0;
}

variable_types:
blknum
unsigned int

variable_types: s short

return_type: short


original_code:
void Free_GBD(gbd *free)
{ gbd *ptr;
  if (free->block)
  { ptr = systab->vol[volnum-1]->gbd_hash[free->block & (1024 -1)];
    if (ptr == free)
    { systab->vol[volnum-1]->gbd_hash[free->block & (1024 -1)]
        = free->next;
    }
    else
    { while (ptr->next != free)
      { ptr = ptr->next;
      }
      ptr->next = free->next;
    }
  }
  free->next = systab->vol[volnum-1]->gbd_hash[1024];
  systab->vol[volnum-1]->gbd_hash[1024] = free;
  free->block = 0;
  free->dirty = ((void *)0);
  free->last_accessed = (time_t) 0;
  return;
}

canonical_original_code:
void Free_GBD(struct GBD *free)
{ struct GBD *ptr;
  if (free->block)
  { ptr = systab->vol[volnum-1]->gbd_hash[free->block & (1024 -1)];
    if (ptr == free)
    { systab->vol[volnum-1]->gbd_hash[free->block & (1024 -1)]
        = free->next;
    }
    else
    { while (ptr->next != free)
      { ptr = ptr->next;
      }
      ptr->next = free->next;
    }
  }
  free->next = systab->vol[volnum-1]->gbd_hash[1024];
  systab->vol[volnum-1]->gbd_hash[1024] = free;
  free->block = 0;
  free->dirty = ((void *)0);
  free->last_accessed = (long) 0;
  return;
}


original_code:
short New_block()
{ int i;
  u_int blknum;
  u_char *c;
  u_char *end;
  Get_GBD();
  Index = 10;
  c = (u_char *)systab->vol[volnum-1]->first_free;
  end = ((u_char *) systab->vol[volnum-1]->map)
 + (systab->vol[volnum-1]->vollab->max_block / 8);
  while (c <= end)
  { if (*c != 255)
    { blknum = (c - ((u_char *) systab->vol[volnum-1]->map)) * 8;
      for (i = 0; ((1 << i) & *c); i++);
      blknum = blknum + i;
      if (blknum <= systab->vol[volnum-1]->vollab->max_block)
      { *c |= (1 << i);
        systab->vol[volnum-1]->map_dirty_flag++;
        blk[level]->block = blknum;
        blk[level]->next
          = systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)];
 systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)]
  = blk[level];
 bzero(blk[level]->mem, systab->vol[volnum-1]->vollab->block_size);
 blk[level]->dirty = (gbd *) 1;
 blk[level]->last_accessed = time(0);
 systab->vol[volnum-1]->first_free = c;
 return 0;
      }
    }
    c++;
  }
  Free_GBD(blk[level]);
  return -(200 + 11);
}

canonical_original_code:
short New_block()
{ int i;
  unsigned int blknum;
  unsigned char *c;
  unsigned char *end;
  Get_GBD();
  Index = 10;
  c = (unsigned char *)systab->vol[volnum-1]->first_free;
  end = ((unsigned char *) systab->vol[volnum-1]->map)
 + (systab->vol[volnum-1]->vollab->max_block / 8);
  while (c <= end)
  { if (*c != 255)
    { blknum = (c - ((unsigned char *) systab->vol[volnum-1]->map)) * 8;
      for (i = 0; ((1 << i) & *c); i++);
      blknum = blknum + i;
      if (blknum <= systab->vol[volnum-1]->vollab->max_block)
      { *c |= (1 << i);
        systab->vol[volnum-1]->map_dirty_flag++;
        blk[level]->block = blknum;
        blk[level]->next
          = systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)];
 systab->vol[volnum-1]->gbd_hash[blknum & (1024 - 1)]
  = blk[level];
 bzero(blk[level]->mem, systab->vol[volnum-1]->vollab->block_size);
 blk[level]->dirty = (struct GBD *) 1;
 blk[level]->last_accessed = time(0);
 systab->vol[volnum-1]->first_free = c;
 return 0;
      }
    }
    c++;
  }
  Free_GBD(blk[level]);
  return -(200 + 11);
}

variable_types:
c
unsigned char *

variable_types:
end
unsigned char *


decompiled_code:
__int64 __fastcall DB_ViewGet(int a1, int a2)
{
__int64 result; // rax
time_t v3; // r8

if ( a2 <= 0 )
return 0LL;
if ( *(_DWORD *)(**(_QWORD **)(systab + 8LL * (a1 - 1) + 228) + 4LL) < (unsigned int)a2 )
return 0LL;
volnum = a1;
level = 0;
writing = 0;
if ( (SemOp(2LL, 0xFFFFFFFFLL) & 0x8000u) != 0LL )
return 0LL;
if ( (Get_block((unsigned int)a2) & 0x8000u) != 0LL )
{
if ( curr_lock )
SemOp(2LL, (unsigned int)-curr_lock);
return 0LL;
}
v3 = time(0LL);
result = *((_QWORD *)&blk + level);
*(_QWORD *)(result + 28) = v3 + 86400;
if ( curr_lock )
{
SemOp(2LL, (unsigned int)-curr_lock);
result = *((_QWORD *)&blk + level);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax
time_t v3; // r8

if ( a2 <= 0 )
return 0LL;
if ( *(_DWORD *)(**(_QWORD **)(systab + 8LL * (a1 - 1) + 228) + 4LL) < (unsigned int)a2 )
return 0LL;
volnum = a1;
level = 0;
writing = 0;
if ( (SemOp(2LL, 0xFFFFFFFFLL) & 0x8000u) != 0LL )
return 0LL;
if ( (Get_block((unsigned int)a2) & 0x8000u) != 0LL )
{
if ( curr_lock )
SemOp(2LL, (unsigned int)-curr_lock);
return 0LL;
}
v3 = time(0LL);
result = *((_QWORD *)&blk + level);
*(_QWORD *)(result + 28) = v3 + 86400;
if ( curr_lock )
{
SemOp(2LL, (unsigned int)-curr_lock);
result = *((_QWORD *)&blk + level);
}
return result;
}

original_code:
struct GBD *DB_ViewGet(int vol, int block)
{ short s;
  if ((block < 1) || (block > systab->vol[vol-1]->vollab->max_block))
  { return ((void *)0);
  }
  level = 0;
  volnum = vol;
  writing = 0;
  s = SemOp(2, (-1));
  if (s < 0)
  { return ((void *)0);
  }
  s = Get_block(block);
  if (s >= 0)
  { blk[level]->last_accessed = time(0)+86400;
  }
  if (curr_lock)
  { SemOp( 2, -curr_lock);
  }
  return (s < 0) ? ((void *)0) : blk[level];
}

variable_types: vol int

variable_types: block int

return_type: struct GBD { unsigned int block; struct GBD *next; struct DB_BLOCK { unsigned char type; unsigned char flags; unsigned short spare; unsigned int right_ptr; unsigned short last_idx; unsigned short last_free; unsigned long long global; } *mem; struct GBD *dirty; long last_accessed; } *


decompiled_code:
void *__fastcall DB_ViewPut(int a1, unsigned int *a2)
{
void *result; // rax
time_t v3; // rax
__int64 v4; // rdi

volnum = a1;
writing = 0;
result = (void *)SemOp(2LL, (unsigned int)-*(_DWORD *)(systab + 16LL));
if ( (__int16)result >= 0 )
{
v3 = time(0LL);
v4 = *a2;
*(_QWORD *)(a2 + 7) = v3;
if ( **(_BYTE **)(a2 + 3) )
{
result = (void *)Used_block(v4);
}
else
{
Free_block(v4);
result = memset(*(void **)(a2 + 3), 0, *(int *)(**(_QWORD **)(systab + 8LL * (volnum - 1) + 228) + 12LL));
}
level = 0;
if ( !*(_QWORD *)(a2 + 5) )
{
*(_QWORD *)(a2 + 5) = a2;
blk = a2;
result = (void *)Queit();
}
if ( curr_lock )
result = (void *)SemOp(2LL, (unsigned int)-curr_lock);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1, unsigned int *a2)
{
void *result; // rax
time_t v3; // rax
__int64 v4; // rdi

volnum = a1;
writing = 0;
result = (void *)SemOp(2LL, (unsigned int)-*(_DWORD *)(systab + 16LL));
if ( (__int16)result >= 0 )
{
v3 = time(0LL);
v4 = *a2;
*(_QWORD *)(a2 + 7) = v3;
if ( **(_BYTE **)(a2 + 3) )
{
result = (void *)Used_block(v4);
}
else
{
Free_block(v4);
result = memset(*(void **)(a2 + 3), 0, *(int *)(**(_QWORD **)(systab + 8LL * (volnum - 1) + 228) + 12LL));
}
level = 0;
if ( !*(_QWORD *)(a2 + 5) )
{
*(_QWORD *)(a2 + 5) = a2;
blk = a2;
result = (void *)Queit();
}
if ( curr_lock )
result = (void *)SemOp(2LL, (unsigned int)-curr_lock);
}
return result;
}

original_code:
void DB_ViewPut(int vol, struct GBD *ptr)
{ short s;
  volnum = vol;
  writing = 0;
  s = SemOp(2, (-systab->maxjob));
  if (s < 0)
  { return;
  }
  ptr->last_accessed = time(0);
  if (ptr->mem->type)
  { Used_block(ptr->block);
  }
  else
  { Free_block(ptr->block);
    bzero(ptr->mem, systab->vol[(volnum)-1]->vollab->block_size);
  }
  level = 0;
  if (ptr->dirty == ((void *)0))
  { ptr->dirty = ptr;
    blk[level] = ptr;
    Queit();
  }
  if (curr_lock)
  { SemOp(2, -curr_lock);
  }
  return;
}


decompiled_code:
time_t __fastcall DB_ViewRel(__int64 a1, __int64 a2)
{
time_t result; // rax
bool v3; // zf

writing = 0;
result = time(0LL);
v3 = *(_QWORD *)(a2 + 20) == 0LL;
*(_QWORD *)(a2 + 28) = result;
if ( !v3 )
{
result = SemOp(2LL, (unsigned int)-*(_DWORD *)(systab + 16LL));
if ( (result & 0x8000u) == 0LL )
{
Free_GBD(a2);
result = SemOp(2LL, (unsigned int)-curr_lock);
}
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func2(__int64 a1, __int64 a2)
{
time_t result; // rax
bool v3; // zf

writing = 0;
result = time(0LL);
v3 = *(_QWORD *)(a2 + 20) == 0LL;
*(_QWORD *)(a2 + 28) = result;
if ( !v3 )
{
result = SemOp(2LL, (unsigned int)-*(_DWORD *)(systab + 16LL));
if ( (result & 0x8000u) == 0LL )
{
Free_GBD(a2);
result = SemOp(2LL, (unsigned int)-curr_lock);
}
}
return result;
}

original_code:
void DB_ViewRel(int vol, struct GBD *ptr)
{ short s;
  writing = 0;
  ptr->last_accessed = time(0);
  if (ptr->dirty != ((void *)0))
  { s = SemOp(2, (-systab->maxjob));
    if (s < 0)
    { return;
    }
    Free_GBD(ptr);
    SemOp(2, -curr_lock);
  }
  return;
}


decompiled_code:
int __fastcall SQ_File_Open(const char *a1, int a2)
{
__int64 v2; // rsi
int result; // eax
int *v4; // rax

v2 = (unsigned int)(a2 - 1);
if ( (unsigned int)v2 > 2 )
return getError(1LL, 21LL);
result = open(a1, CSWTCH_1[v2], 420LL);
if ( result == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, int a2)
{
__int64 v2; // rsi
int result; // eax
int *v4; // rax

v2 = (unsigned int)(a2 - 1);
if ( (unsigned int)v2 > 2 )
return getError(1LL, 21LL);
result = open(a1, CSWTCH_1[v2], 420LL);
if ( result == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
return result;
}

original_code:
int SQ_File_Open (char *file, int op)
{ int flag;
  int fid;
  switch ( op )
  { case 1:
      flag = 01|01000|0100;
      break;
    case 2:
      flag = 00;
      break;
    case 3:
      flag = 01|02000|0100;
      break;
    default:
      return ( getError ( 1, 21 ) );
  }
  fid = open ( file, flag, 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3) );
  if ( fid == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( fid );
}

canonical_original_code:
int SQ_File_Open(char *file, int op)
{ int flag;
  int fid;
  switch ( op )
  { case 1:
      flag = 01|01000|0100;
      break;
    case 2:
      flag = 00;
      break;
    case 3:
      flag = 01|02000|0100;
      break;
    default:
      return ( getError ( 1, 21 ) );
  }
  fid = open ( file, flag, 0400|0200|(0400 >> 3)|((0400 >> 3) >> 3) );
  if ( fid == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( fid );
}

variable_types:
file
char *

variable_types: op int

variable_types: flag int

variable_types: fid int


decompiled_code:
ssize_t __fastcall SQ_File_Write(int a1, const void *a2, int a3)
{
ssize_t result; // rax
int *v4; // rax

result = write(a1, a2, a3);
if ( (_DWORD)result == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int a1, const void *a2, int a3)
{
ssize_t result; // rax
int *v4; // rax

result = write(a1, a2, a3);
if ( (_DWORD)result == -1 )
{
v4 = _errno_location();
result = getError(0LL, (unsigned int)*v4);
}
return result;
}

original_code:
int SQ_File_Write (int fid, u_char *writebuf, int nbytes)
{ int ret;
  ret = write ( fid, writebuf, nbytes );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

canonical_original_code:
int SQ_File_Write(int fid, unsigned char *writebuf, int nbytes)
{ int ret;
  ret = write ( fid, writebuf, nbytes );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  return ( ret );
}

variable_types:
writebuf
unsigned char *

variable_types: nbytes int

variable_types: ret int


decompiled_code:
ssize_t __fastcall SQ_File_Read(int a1, void *a2)
{
ssize_t result; // rax
int *v3; // rax

result = read(a1, a2, 1uLL);
if ( (_DWORD)result == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int a1, void *a2)
{
ssize_t result; // rax
int *v3; // rax

result = read(a1, a2, 1uLL);
if ( (_DWORD)result == -1 )
{
v3 = _errno_location();
result = getError(0LL, (unsigned int)*v3);
}
return result;
}

original_code:
int SQ_File_Read (int fid, u_char *readbuf)
{ int ret;
  ret = read ( fid, readbuf, 1 );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  else return ( ret );
}

canonical_original_code:
int SQ_File_Read(int fid, unsigned char *readbuf)
{ int ret;
  ret = read ( fid, readbuf, 1 );
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  else return ( ret );
}

variable_types:
readbuf
unsigned char *


getError

decompiled_code:
__int64 __fastcall getError(int a1, int a2)
{
__int64 result; // rax

if ( !a1 )
return (unsigned int)(-400 - a2);
result = (unsigned int)(-200 - a2);
if ( a1 != 1 )
result = 4294967076LL;
return result;
}

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

if ( !a1 )
return (unsigned int)(-400 - a2);
result = (unsigned int)(-200 - a2);
if ( a1 != 1 )
result = 4294967076LL;
return result;
}

original_code:
int getError (int type, int errnum)
{ int err;
  switch ( type )
  { case 0:
      err = errnum + 200 + 200;
      break;
    case 1:
      err = errnum + 200;
      break;
    default:
      err = 20 + 200;
      break;
  }
  return ( -err );
}

canonical_original_code:
int getError(int type, int errnum)
{ int err;
  switch ( type )
  { case 0:
      err = errnum + 200 + 200;
      break;
    case 1:
      err = errnum + 200;
      break;
    default:
      err = 20 + 200;
      break;
  }
  return ( -err );
}

variable_types: type int

variable_types: errnum int

variable_types: err int


setSignalBitMask

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

if ( a1 == 3 )
return DoInfo();
result = partab;
*(_DWORD *)(partab + 28LL) = 1;
*(_DWORD *)(result + 24) |= 1 << a1;
return result;
}

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

if ( a1 == 3 )
return DoInfo();
result = partab;
*(_DWORD *)(partab + 28LL) = 1;
*(_DWORD *)(result + 24) |= 1 << a1;
return result;
}

original_code:
void setSignalBitMask (int sig)
{ int mask;
  if ( sig == 3 )
    DoInfo();
  else
  { partab.jobtab->attention = 1;
    mask = 1 << sig;
    partab.jobtab->trap |= mask;
  }
}

canonical_original_code:
void setSignalBitMask(int sig)
{ int mask;
  if ( sig == 3 )
    DoInfo();
  else
  { partab.jobtab->attention = 1;
    mask = 1 << sig;
    partab.jobtab->trap |= mask;
  }
}

variable_types: sig int

variable_types: mask int


seqioSelect

decompiled_code:
__int64 __fastcall seqioSelect(int a1, int a2, int a3)
{
int v3; // er9
struct timeval *v4; // r8
int v5; // eax
unsigned int v6; // er8
int *v8; // rax
__int64 v9[2]; // [rsp+0h] [rbp-98h] BYREF
fd_set writefds; // [rsp+10h] [rbp-88h] BYREF

v3 = a1 + 1;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
if ( a3 )
{
v4 = 0LL;
if ( a2 )
{
LABEL_3:
v5 = select(v3, 0LL, &writefds, 0LL, v4);
if ( v5 == -1 )
goto LABEL_8;
goto LABEL_4;
}
}
else
{
v9[0] = 0LL;
v4 = (struct timeval *)v9;
v9[1] = 0LL;
if ( a2 )
goto LABEL_3;
}
v5 = select(v3, &writefds, 0LL, 0LL, v4);
if ( v5 == -1 )
goto LABEL_8;
LABEL_4:
v6 = 0;
if ( v5 )
return v6;
if ( raise(14) != -1 )
return (unsigned int)-1;
LABEL_8:
v8 = _errno_location();
return getError(0, *v8);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3)
{
int v3; // er9
struct timeval *v4; // r8
int v5; // eax
unsigned int v6; // er8
int *v8; // rax
__int64 v9[2]; // [rsp+0h] [rbp-98h] BYREF
fd_set writefds; // [rsp+10h] [rbp-88h] BYREF

v3 = a1 + 1;
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
if ( a3 )
{
v4 = 0LL;
if ( a2 )
{
LABEL_3:
v5 = select(v3, 0LL, &writefds, 0LL, v4);
if ( v5 == -1 )
goto LABEL_8;
goto LABEL_4;
}
}
else
{
v9[0] = 0LL;
v4 = (struct timeval *)v9;
v9[1] = 0LL;
if ( a2 )
goto LABEL_3;
}
v5 = select(v3, &writefds, 0LL, 0LL, v4);
if ( v5 == -1 )
goto LABEL_8;
LABEL_4:
v6 = 0;
if ( v5 )
return v6;
if ( raise(14) != -1 )
return (unsigned int)-1;
LABEL_8:
v8 = _errno_location();
return func0(0, *v8);
}

original_code:
int seqioSelect (int sid, int type, int tout)
{ int nfds;
  fd_set fds;
  int ret;
  struct timeval timeout;
  nfds = sid + 1;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((sid) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sid) % (8 * (int) sizeof (__fd_mask)))))));
  if ( tout == 0 )
  { timeout.tv_sec = 0;
    timeout.tv_usec = 0;
    if ( type == 0 ) ret = select ( nfds, &fds, ((void *)0), ((void *)0), &timeout );
    else ret = select ( nfds, ((void *)0), &fds, ((void *)0), &timeout );
  }
  else
  { if ( type == 0 ) ret = select ( nfds, &fds, ((void *)0), ((void *)0), ((void *)0) );
    else ret = select ( nfds, ((void *)0), &fds, ((void *)0), ((void *)0) );
  }
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  else if ( ret == 0 )
  { ret = raise ( 14 );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    return ( -1 );
  }
  else return ( 0 );
}

canonical_original_code:
int seqioSelect(int sid, int type, int tout)
{ int nfds;
  struct fd_set fds;
  int ret;
  struct timeval timeout;
  nfds = sid + 1;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((sid) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sid) % (8 * (int) sizeof (__fd_mask)))))));
  if ( tout == 0 )
  { timeout.tv_sec = 0;
    timeout.tv_usec = 0;
    if ( type == 0 ) ret = select ( nfds, &fds, ((void *)0), ((void *)0), &timeout );
    else ret = select ( nfds, ((void *)0), &fds, ((void *)0), &timeout );
  }
  else
  { if ( type == 0 ) ret = select ( nfds, &fds, ((void *)0), ((void *)0), ((void *)0) );
    else ret = select ( nfds, ((void *)0), &fds, ((void *)0), ((void *)0) );
  }
  if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
  else if ( ret == 0 )
  { ret = raise ( 14 );
    if ( ret == -1 ) return ( getError ( 0, (*__errno_location ()) ) );
    return ( -1 );
  }
  else return ( 0 );
}

variable_types: sid int

variable_types: tout int

variable_types: nfds int

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

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


mcopy

decompiled_code:
__int64 __fastcall mcopy(void *src, void *dest, int a3)
{
unsigned __int64 v4; // rax

if ( *(_QWORD *)((char *)&partab + 20) <= (unsigned __int64)dest )
{
v4 = *(_QWORD *)((char *)&partab + 28);
if ( v4 > (unsigned __int64)dest && v4 < (unsigned __int64)dest + a3 )
return 4294967088LL;
}
if ( a3 > 0x7FFF )
return 4294967221LL;
*((_BYTE *)memmove(dest, src, a3) + a3) = 0;
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src, void *dest, int a3)
{
unsigned __int64 v4; // rax

if ( *(_QWORD *)((char *)&partab + 20) <= (unsigned __int64)dest )
{
v4 = *(_QWORD *)((char *)&partab + 28);
if ( v4 > (unsigned __int64)dest && v4 < (unsigned __int64)dest + a3 )
return 4294967088LL;
}
if ( a3 > 0x7FFF )
return 4294967221LL;
*((_BYTE *)memmove(dest, src, a3) + a3) = 0;
return (unsigned int)a3;
}

original_code:
short mcopy(u_char *src, u_char *dst, int bytes)
{ if ( (dst >= partab.sstk_start) &&
       (dst < partab.sstk_last) &&
       (&dst[bytes] > partab.sstk_last) )
         return -(200 +8);
  if (bytes > 32767)
  { return -75;
  }
  bcopy(src, dst, bytes);
  dst[bytes] = '\0';
  return bytes;
}

canonical_original_code:
short mcopy(unsigned char *src, unsigned char *dst, int bytes)
{ if ( (dst >= partab.sstk_start) &&
       (dst < partab.sstk_last) &&
       (&dst[bytes] > partab.sstk_last) )
         return -(200 +8);
  if (bytes > 32767)
  { return -75;
  }
  bcopy(src, dst, bytes);
  dst[bytes] = '\0';
  return bytes;
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types: bytes int