repo: gburd/cauchy

original_code:
void Init_field(UNSIGNED *pCOLBIT, UNSIGNED *BIT, UNSIGNED *ExptoFE,
                UNSIGNED *FEtoExp)
{
int i ;
static UNSIGNED CARRYMASK ;
static UNSIGNED POLYMASK[16] =
         {0x0, 0x3, 0x7, 0xB, 0x13, 0x25, 0x43, 0x83,
          0x11D, 0x211, 0x409, 0x805, 0x1053, 0x201B, 0x402B, 0x8003} ;
BIT[0] = 0x1 ;
for (i=1; i < 10 ; i++) BIT[i] = BIT[i-1] << 1 ;
*pCOLBIT = BIT[10 -1] ;
CARRYMASK = *pCOLBIT << 1 ;
ExptoFE[0] = 0x1 ;
for (i=1; i < SMultField + 10 - 1 ; i++)
  {
  ExptoFE[i] = ExptoFE[i-1] << 1 ;
  if (ExptoFE[i]&CARRYMASK) ExptoFE[i] ^= POLYMASK[10] ;
  } ;
FEtoExp[0] = -1 ;
for (i=0; i < SMultField ; i++) FEtoExp[ExptoFE[i]] = i ;
}

canonical_original_code:
void Init_field(unsigned int *pCOLBIT, unsigned int *BIT, unsigned int *ExptoFE, unsigned int *FEtoExp)
{
int i;
static unsigned int CARRYMASK;
static unsigned int POLYMASK[16] = {0x0, 0x3, 0x7, 0xB, 0x13, 0x25, 0x43, 0x83,
          0x11D, 0x211, 0x409, 0x805, 0x1053, 0x201B, 0x402B, 0x8003};
BIT[0] = 0x1 ;
for (i=1; i < 10 ; i++) BIT[i] = BIT[i-1] << 1 ;
*pCOLBIT = BIT[10 -1] ;
CARRYMASK = *pCOLBIT << 1 ;
ExptoFE[0] = 0x1 ;
for (i=1; i < SMultField + 10 - 1 ; i++)
  {
  ExptoFE[i] = ExptoFE[i-1] << 1 ;
  if (ExptoFE[i]&CARRYMASK) ExptoFE[i] ^= POLYMASK[10] ;
  } ;
FEtoExp[0] = -1 ;
for (i=0; i < SMultField ; i++) FEtoExp[ExptoFE[i]] = i ;
}

variable_types:
pCOLBIT
unsigned int *

variable_types:
BIT
unsigned int *

variable_types:
ExptoFE
unsigned int *

variable_types:
FEtoExp
unsigned int *

variable_types:
CARRYMASK
unsigned int

variable_types:
POLYMASK
unsigned int [16]


decompiled_code:
__int64 __fastcall Lose_Packets(__int64 a1, __int64 a2, int *a3)
{
__int64 v5; // rcx
int v6; // eax
__int64 v7; // rdi
__int64 v8; // rsi
__int64 i; // rax
struct timezone tz; // [rsp+8h] [rbp-30h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&tv, &tz);
srand48(tv.tv_usec);
*a3 = 0;
v5 = a1 + 100400;
v6 = 0;
v7 = a1 + 301200;
do
{
v8 = a2 + 1004LL * v6;
for ( i = 0LL; i != 1004; i += 4LL )
*(_DWORD *)(v8 + i) = *(_DWORD *)(v5 + i);
v5 += 1004LL;
v6 = *a3 + 1;
*a3 = v6;
}
while ( v7 != v5 );
return LODWORD(tv.tv_usec);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int *a3)
{
__int64 v5; // rcx
int v6; // eax
__int64 v7; // rdi
__int64 v8; // rsi
__int64 i; // rax
struct timezone tz; // [rsp+8h] [rbp-30h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&tv, &tz);
srand48(tv.tv_usec);
*a3 = 0;
v5 = a1 + 100400;
v6 = 0;
v7 = a1 + 301200;
do
{
v8 = a2 + 1004LL * v6;
for ( i = 0LL; i != 1004; i += 4LL )
*(_DWORD *)(v8 + i) = *(_DWORD *)(v5 + i);
v5 += 1004LL;
v6 = *a3 + 1;
*a3 = v6;
}
while ( v7 != v5 );
return LODWORD(tv.tv_usec);
}

original_code:
int Lose_Packets(UNSIGNED *packets, UNSIGNED *rec_packets, int *pNrec)
{
int i,j,k,m;
int ranval ;
struct timeval tp ;
struct timezone tzp;
gettimeofday(&tp, &tzp);
srand48(tp.tv_usec);
*pNrec = 0 ;
k = 0 ;
m = 0 ;
for (i=(Npackets-200)/2 ; i < (Npackets+200)/2; i++)
  {
   k = Plentot * i ;
   m = Plentot * (*pNrec) ;
   for (j=0; j < Plentot; j++) rec_packets[m+j] = packets[k+j] ;
   (*pNrec)++ ;
  } ;
return tp.tv_usec ;
}

canonical_original_code:
int Lose_Packets(unsigned int *packets, unsigned int *rec_packets, int *pNrec)
{
int i; int j; int k; int m;
int ranval;
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp, &tzp);
srand48(tp.tv_usec);
*pNrec = 0 ;
k = 0 ;
m = 0 ;
for (i=(Npackets-200)/2 ; i < (Npackets+200)/2; i++)
  {
   k = Plentot * i ;
   m = Plentot * (*pNrec) ;
   for (j=0; j < Plentot; j++) rec_packets[m+j] = packets[k+j] ;
   (*pNrec)++ ;
  } ;
return tp.tv_usec ;
}

variable_types:
packets
unsigned int *

variable_types:
pNrec
int *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: m int

variable_types: ranval int

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

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

return_type: int


Decode

decompiled_code:
__int64 __fastcall Decode(int a1, _DWORD *a2, __int64 a3, __int64 a4, int *a5, unsigned int *a6, void *s)
{
char *v10; // r14
int *v11; // rdi
__int64 v12; // rsi
signed int v13; // er9
int v14; // eax
int v15; // er10
int *v16; // rcx
char *v17; // r8
__int64 i; // rax
int v19; // er12
__int64 v20; // rax
int v21; // edx
__int64 v22; // rcx
__int64 v23; // rax
__int64 v24; // r8
int v25; // edx
__int64 v26; // rax
unsigned int v27; // ecx
int v28; // ecx
char *v29; // rsi
char *v30; // rcx
_DWORD *v31; // r8
char *v32; // rax
_DWORD *v33; // r14
__int64 j; // rbp
int v35; // er10
int v36; // edx
int *v37; // r11
char *v38; // rcx
int v39; // er9
_DWORD *v40; // rsi
int v41; // edi
char *v42; // rax
_DWORD *v43; // rdx
_DWORD *v44; // r9
__int64 k; // rdx
int v46; // esi
unsigned int v47; // ebp
__int64 v48; // rax
int v49; // ecx
int v50; // ecx
__int64 l; // r13
int v52; // er12
__int64 m; // rbx
int v54; // eax
int v55; // er10
char *v56; // rcx
_DWORD *v57; // r9
_DWORD *v58; // rsi
int v59; // edi
char *v60; // rax
char *v61; // rdx
__int64 result; // rax
_DWORD *v63; // [rsp+0h] [rbp-D8h]
_DWORD *v64; // [rsp+0h] [rbp-D8h]
_DWORD *v65; // [rsp+0h] [rbp-D8h]
_DWORD *v66; // [rsp+8h] [rbp-D0h]
__int64 v67; // [rsp+10h] [rbp-C8h]
__int64 v68; // [rsp+18h] [rbp-C0h]
int v69; // [rsp+18h] [rbp-C0h]
_DWORD *v70; // [rsp+20h] [rbp-B8h]
_DWORD *v73; // [rsp+38h] [rbp-A0h]
_DWORD *v74; // [rsp+40h] [rbp-98h]
_DWORD *v75; // [rsp+48h] [rbp-90h]
_DWORD *v76; // [rsp+50h] [rbp-88h]
unsigned int v78; // [rsp+60h] [rbp-78h]
char *v79; // [rsp+70h] [rbp-68h]
char *v80; // [rsp+78h] [rbp-60h]
struct timeval tv; // [rsp+80h] [rbp-58h] BYREF
struct timeval v82; // [rsp+90h] [rbp-48h] BYREF

v63 = calloc(0xC8uLL, 4uLL);
if ( !v63 )
{
puts("\ndecode: Rec_index malloc failed");
exit(434);
}
v70 = calloc(0xC8uLL, 4uLL);
if ( !v70 )
{
puts("\ndecode: Col_Ind malloc failed");
exit(434);
}
v66 = calloc(0xC8uLL, 4uLL);
if ( !v66 )
{
puts("\ndecode: Row_Ind malloc failed");
exit(434);
}
v73 = calloc(0xC8uLL, 4uLL);
if ( !v73 )
{
puts("\ndecode: C malloc failed");
exit(434);
}
v74 = calloc(0xC8uLL, 4uLL);
if ( !v74 )
{
puts("\ndecode: D malloc failed");
exit(434);
}
v75 = calloc(0xC8uLL, 4uLL);
if ( !v75 )
{
puts("\ndecode: E malloc failed");
exit(434);
}
v76 = calloc(0xC8uLL, 4uLL);
if ( !v76 )
{
puts("\ndecode: F malloc failed");
exit(434);
}
v10 = (char *)calloc(0xC350uLL, 4uLL);
if ( !v10 )
{
puts("\ndecode: M malloc failed");
exit(434);
}
if ( (int)*a6 <= 199 )
{
printf("*** Need %d packets to recover message", 200LL);
printf(" but only %d packets received *** \n", *a6);
result = 1LL;
}
else
{
memset(s, 0, 0x30D40uLL);
gettimeofday(&tv, 0LL);
if ( (int)*a6 <= 0 )
{
v19 = 200;
v12 = 0LL;
}
else
{
v11 = a5;
v12 = 0LL;
v13 = 0;
do
{
v14 = *v11;
if ( *v11 <= 199 )
{
v15 = 0;
v63[v14] = 1;
v16 = v11;
v17 = (char *)s + 1000 * v14;
do
{
for ( i = 0LL; i != 25; ++i )
*(_DWORD *)&v17[i * 4] = v16[i + 1];
v15 += 25;
v16 += 25;
v17 += 100;
}
while ( v15 != 250 );
v12 = (unsigned int)(v12 + 1);
}
++v13;
v11 += 251;
}
while ( (int)*a6 > v13 );
v19 = 200 - v12;
}
printf("Nfirstrec= %d, Nextra= %d \n", v12, (unsigned int)v19);
v20 = 0LL;
v21 = 0;
do
{
if ( !v63[v20] )
{
v22 = v21++;
v70[v22] = v20;
}
++v20;
}
while ( v20 != 200 );
v23 = (int)*a6;
if ( (int)v23 > 0 )
{
v24 = 251 * v23;
v25 = 0;
v26 = 0LL;
do
{
v27 = a5[v26];
if ( v27 > 0xC7 )
{
v66[v25] = v27 - 200;
v28 = 250 * v25++;
v29 = (char *)&a5[(unsigned int)(v26 + 1)];
v30 = &v10[4 * v28];
*(_QWORD *)v30 = *(_QWORD *)v29;
*((_QWORD *)v30 + 124) = *((_QWORD *)v29 + 124);
qmemcpy(
(void *)((unsigned __int64)(v30 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v29 - &v30[-((unsigned __int64)(v30 + 8) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((unsigned int)v30 - (((_DWORD)v30 + 8) & 0xFFFFFFF8) + 1000) >> 3));
if ( v25 >= v19 )
break;
}
v26 += 251LL;
}
while ( v24 != v26 );
}
if ( v19 > 0 )
{
v80 = v10;
v31 = a2 + 10;
v67 = v19;
v32 = v10 + 100;
v33 = v63;
v68 = 0LL;
v79 = v32;
do
{
for ( j = 0LL; j != 200; ++j )
{
while ( v33[j] != 1 )
{
if ( ++j == 200 )
goto LABEL_43;
}
v35 = 250 * v68;
v36 = (4198405
* (unsigned __int64)(unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ (unsigned int)j ^ v66[v68])))) >> 32;
v37 = (int *)(a3
+ 4LL
* (1023
- *(_DWORD *)(a4 + 4LL * (a1 ^ (unsigned int)j ^ v66[v68]))
- 1023
* ((v36
+ ((unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ (unsigned int)j ^ v66[v68])) - v36) >> 1)) >> 9)));
v38 = &v79[1000 * v68];
do
{
v39 = *v37;
v40 = a2;
v41 = 250 * j;
do
{
while ( (*v40 & v39) == 0 )
{
++v40;
v41 += 25;
if ( v31 == v40 )
goto LABEL_41;
}
v64 = v40;
v42 = v38 - 100;
v43 = (char *)s + 4 * v41;
do
{
*(_DWORD *)v42 ^= *v43;
v42 += 4;
++v43;
}
while ( v38 != v42 );
v41 += 25;
++v40;
}
while ( v31 != v64 + 1 );
LABEL_41:
v35 += 25;
++v37;
v38 += 100;
}
while ( 250 * ((_DWORD)v68 + 1) != v35 );
}
LABEL_43:
++v68;
}
while ( v19 != v68 );
v44 = v73;
for ( k = 0LL; k != v19; ++k )
{
v46 = v75[k];
v47 = v66[k];
v48 = 0LL;
do
{
if ( (_DWORD)k != (_DWORD)v48 )
{
v49 = *(_DWORD *)(a4 + 4LL * (v70[k] ^ v70[v48]));
*v44 += *(_DWORD *)(a4 + 4LL * (int)(v47 ^ v66[v48]));
v74[v48] += v49;
}
v50 = *(_DWORD *)(a4 + 4LL * (a1 ^ v47 ^ v70[v48]));
v76[v48++] += v50;
v46 += v50;
}
while ( v19 != v48 );
v75[k] = v46;
++v44;
}
for ( l = 0LL; l != v67; ++l )
{
v69 = v76[l] - v74[l];
v52 = 250 * v70[l];
v78 = v70[l];
for ( m = 0LL; m != v67; ++m )
{
v54 = v75[m] + v69 - v73[m] - *(_DWORD *)(a4 + 4LL * (a1 ^ v66[m] ^ v78));
if ( v54 < 0 )
v54 = 1023 - (*(_DWORD *)(a4 + 4LL * (a1 ^ v66[m] ^ v78)) - (v75[m] + v69 - v73[m])) % 0x3FFu;
v55 = v52;
v56 = (char *)s + 4 * v52 + 100;
v57 = (_DWORD *)(a3 + 4LL * (v54 % 0x3FFu));
do
{
v58 = a2;
v59 = 250 * m;
do
{
while ( (*v58 & *v57) == 0 )
{
++v58;
v59 += 25;
if ( v31 == v58 )
goto LABEL_61;
}
v65 = v58;
v60 = v56 - 100;
v61 = &v80[4 * v59];
do
{
*(_DWORD *)v60 ^= *(_DWORD *)v61;
v60 += 4;
v61 += 4;
}
while ( v56 != v60 );
v59 += 25;
++v58;
}
while ( v31 != v65 + 1 );
LABEL_61:
v55 += 25;
++v57;
v56 += 100;
}
while ( v55 != v52 + 250 );
}
}
}
gettimeofday(&v82, 0LL);
printf("\n------------------------------------------------");
printf(
"\n decode: number of seconds is %f",
(float)(LODWORD(v82.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (float)(LODWORD(v82.tv_sec) - LODWORD(tv.tv_sec)));
puts("\n------------------------------------------------\n");
fflush(stdout);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, _DWORD *a2, __int64 a3, __int64 a4, int *a5, unsigned int *a6, void *s)
{
char *v10; // r14
int *v11; // rdi
__int64 v12; // rsi
signed int v13; // er9
int v14; // eax
int v15; // er10
int *v16; // rcx
char *v17; // r8
__int64 i; // rax
int v19; // er12
__int64 v20; // rax
int v21; // edx
__int64 v22; // rcx
__int64 v23; // rax
__int64 v24; // r8
int v25; // edx
__int64 v26; // rax
unsigned int v27; // ecx
int v28; // ecx
char *v29; // rsi
char *v30; // rcx
_DWORD *v31; // r8
char *v32; // rax
_DWORD *v33; // r14
__int64 j; // rbp
int v35; // er10
int v36; // edx
int *v37; // r11
char *v38; // rcx
int v39; // er9
_DWORD *v40; // rsi
int v41; // edi
char *v42; // rax
_DWORD *v43; // rdx
_DWORD *v44; // r9
__int64 k; // rdx
int v46; // esi
unsigned int v47; // ebp
__int64 v48; // rax
int v49; // ecx
int v50; // ecx
__int64 l; // r13
int v52; // er12
__int64 m; // rbx
int v54; // eax
int v55; // er10
char *v56; // rcx
_DWORD *v57; // r9
_DWORD *v58; // rsi
int v59; // edi
char *v60; // rax
char *v61; // rdx
__int64 result; // rax
_DWORD *v63; // [rsp+0h] [rbp-D8h]
_DWORD *v64; // [rsp+0h] [rbp-D8h]
_DWORD *v65; // [rsp+0h] [rbp-D8h]
_DWORD *v66; // [rsp+8h] [rbp-D0h]
__int64 v67; // [rsp+10h] [rbp-C8h]
__int64 v68; // [rsp+18h] [rbp-C0h]
int v69; // [rsp+18h] [rbp-C0h]
_DWORD *v70; // [rsp+20h] [rbp-B8h]
_DWORD *v73; // [rsp+38h] [rbp-A0h]
_DWORD *v74; // [rsp+40h] [rbp-98h]
_DWORD *v75; // [rsp+48h] [rbp-90h]
_DWORD *v76; // [rsp+50h] [rbp-88h]
unsigned int v78; // [rsp+60h] [rbp-78h]
char *v79; // [rsp+70h] [rbp-68h]
char *v80; // [rsp+78h] [rbp-60h]
struct timeval tv; // [rsp+80h] [rbp-58h] BYREF
struct timeval v82; // [rsp+90h] [rbp-48h] BYREF

v63 = calloc(0xC8uLL, 4uLL);
if ( !v63 )
{
puts("\ndecode: Rec_index malloc failed");
exit(434);
}
v70 = calloc(0xC8uLL, 4uLL);
if ( !v70 )
{
puts("\ndecode: Col_Ind malloc failed");
exit(434);
}
v66 = calloc(0xC8uLL, 4uLL);
if ( !v66 )
{
puts("\ndecode: Row_Ind malloc failed");
exit(434);
}
v73 = calloc(0xC8uLL, 4uLL);
if ( !v73 )
{
puts("\ndecode: C malloc failed");
exit(434);
}
v74 = calloc(0xC8uLL, 4uLL);
if ( !v74 )
{
puts("\ndecode: D malloc failed");
exit(434);
}
v75 = calloc(0xC8uLL, 4uLL);
if ( !v75 )
{
puts("\ndecode: E malloc failed");
exit(434);
}
v76 = calloc(0xC8uLL, 4uLL);
if ( !v76 )
{
puts("\ndecode: F malloc failed");
exit(434);
}
v10 = (char *)calloc(0xC350uLL, 4uLL);
if ( !v10 )
{
puts("\ndecode: M malloc failed");
exit(434);
}
if ( (int)*a6 <= 199 )
{
printf("*** Need %d packets to recover message", 200LL);
printf(" but only %d packets received *** \n", *a6);
result = 1LL;
}
else
{
memset(s, 0, 0x30D40uLL);
gettimeofday(&tv, 0LL);
if ( (int)*a6 <= 0 )
{
v19 = 200;
v12 = 0LL;
}
else
{
v11 = a5;
v12 = 0LL;
v13 = 0;
do
{
v14 = *v11;
if ( *v11 <= 199 )
{
v15 = 0;
v63[v14] = 1;
v16 = v11;
v17 = (char *)s + 1000 * v14;
do
{
for ( i = 0LL; i != 25; ++i )
*(_DWORD *)&v17[i * 4] = v16[i + 1];
v15 += 25;
v16 += 25;
v17 += 100;
}
while ( v15 != 250 );
v12 = (unsigned int)(v12 + 1);
}
++v13;
v11 += 251;
}
while ( (int)*a6 > v13 );
v19 = 200 - v12;
}
printf("Nfirstrec= %d, Nextra= %d \n", v12, (unsigned int)v19);
v20 = 0LL;
v21 = 0;
do
{
if ( !v63[v20] )
{
v22 = v21++;
v70[v22] = v20;
}
++v20;
}
while ( v20 != 200 );
v23 = (int)*a6;
if ( (int)v23 > 0 )
{
v24 = 251 * v23;
v25 = 0;
v26 = 0LL;
do
{
v27 = a5[v26];
if ( v27 > 0xC7 )
{
v66[v25] = v27 - 200;
v28 = 250 * v25++;
v29 = (char *)&a5[(unsigned int)(v26 + 1)];
v30 = &v10[4 * v28];
*(_QWORD *)v30 = *(_QWORD *)v29;
*((_QWORD *)v30 + 124) = *((_QWORD *)v29 + 124);
qmemcpy(
(void *)((unsigned __int64)(v30 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v29 - &v30[-((unsigned __int64)(v30 + 8) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((unsigned int)v30 - (((_DWORD)v30 + 8) & 0xFFFFFFF8) + 1000) >> 3));
if ( v25 >= v19 )
break;
}
v26 += 251LL;
}
while ( v24 != v26 );
}
if ( v19 > 0 )
{
v80 = v10;
v31 = a2 + 10;
v67 = v19;
v32 = v10 + 100;
v33 = v63;
v68 = 0LL;
v79 = v32;
do
{
for ( j = 0LL; j != 200; ++j )
{
while ( v33[j] != 1 )
{
if ( ++j == 200 )
goto LABEL_43;
}
v35 = 250 * v68;
v36 = (4198405
* (unsigned __int64)(unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ (unsigned int)j ^ v66[v68])))) >> 32;
v37 = (int *)(a3
+ 4LL
* (1023
- *(_DWORD *)(a4 + 4LL * (a1 ^ (unsigned int)j ^ v66[v68]))
- 1023
* ((v36
+ ((unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ (unsigned int)j ^ v66[v68])) - v36) >> 1)) >> 9)));
v38 = &v79[1000 * v68];
do
{
v39 = *v37;
v40 = a2;
v41 = 250 * j;
do
{
while ( (*v40 & v39) == 0 )
{
++v40;
v41 += 25;
if ( v31 == v40 )
goto LABEL_41;
}
v64 = v40;
v42 = v38 - 100;
v43 = (char *)s + 4 * v41;
do
{
*(_DWORD *)v42 ^= *v43;
v42 += 4;
++v43;
}
while ( v38 != v42 );
v41 += 25;
++v40;
}
while ( v31 != v64 + 1 );
LABEL_41:
v35 += 25;
++v37;
v38 += 100;
}
while ( 250 * ((_DWORD)v68 + 1) != v35 );
}
LABEL_43:
++v68;
}
while ( v19 != v68 );
v44 = v73;
for ( k = 0LL; k != v19; ++k )
{
v46 = v75[k];
v47 = v66[k];
v48 = 0LL;
do
{
if ( (_DWORD)k != (_DWORD)v48 )
{
v49 = *(_DWORD *)(a4 + 4LL * (v70[k] ^ v70[v48]));
*v44 += *(_DWORD *)(a4 + 4LL * (int)(v47 ^ v66[v48]));
v74[v48] += v49;
}
v50 = *(_DWORD *)(a4 + 4LL * (a1 ^ v47 ^ v70[v48]));
v76[v48++] += v50;
v46 += v50;
}
while ( v19 != v48 );
v75[k] = v46;
++v44;
}
for ( l = 0LL; l != v67; ++l )
{
v69 = v76[l] - v74[l];
v52 = 250 * v70[l];
v78 = v70[l];
for ( m = 0LL; m != v67; ++m )
{
v54 = v75[m] + v69 - v73[m] - *(_DWORD *)(a4 + 4LL * (a1 ^ v66[m] ^ v78));
if ( v54 < 0 )
v54 = 1023 - (*(_DWORD *)(a4 + 4LL * (a1 ^ v66[m] ^ v78)) - (v75[m] + v69 - v73[m])) % 0x3FFu;
v55 = v52;
v56 = (char *)s + 4 * v52 + 100;
v57 = (_DWORD *)(a3 + 4LL * (v54 % 0x3FFu));
do
{
v58 = a2;
v59 = 250 * m;
do
{
while ( (*v58 & *v57) == 0 )
{
++v58;
v59 += 25;
if ( v31 == v58 )
goto LABEL_61;
}
v65 = v58;
v60 = v56 - 100;
v61 = &v80[4 * v59];
do
{
*(_DWORD *)v60 ^= *(_DWORD *)v61;
v60 += 4;
v61 += 4;
}
while ( v56 != v60 );
v59 += 25;
++v58;
}
while ( v31 != v65 + 1 );
LABEL_61:
v55 += 25;
++v57;
v56 += 100;
}
while ( v55 != v52 + 250 );
}
}
}
gettimeofday(&v82, 0LL);
printf("\n------------------------------------------------");
printf(
"\n decode: number of seconds is %f",
(float)(LODWORD(v82.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (float)(LODWORD(v82.tv_sec) - LODWORD(tv.tv_sec)));
puts("\n------------------------------------------------\n");
fflush(stdout);
result = 0LL;
}
return result;
}

original_code:
int Decode(UNSIGNED COLBIT, UNSIGNED *BIT, UNSIGNED *ExptoFE,
           UNSIGNED *FEtoExp, UNSIGNED *rec_packets, int *pNrec,
           UNSIGNED *rec_message)
{
int i,j,k,l,m, index, seg_ind ;
int col_ind, row_ind, col_eqn, row_eqn ;
int Nfirstrec, Nextra ;
int *Rec_index ;
int *Col_Ind, *Row_Ind, ExpFE ;
UNSIGNED *M ;
UNSIGNED *C, *D, *E, *F ;
struct timeval start_time, end_time;
Rec_index = (int *) calloc(200, sizeof(int));
if (!(Rec_index)) {printf("\ndecode: Rec_index malloc failed\n"); exit(434); }
Col_Ind = (int *) calloc(200, sizeof(int));
if (!(Col_Ind)) {printf("\ndecode: Col_Ind malloc failed\n"); exit(434); }
Row_Ind = (int *) calloc(200, sizeof(int));
if (!(Row_Ind)) {printf("\ndecode: Row_Ind malloc failed\n"); exit(434); }
C = (UNSIGNED *) calloc(200, sizeof(UNSIGNED));
if (!(C)) {printf("\ndecode: C malloc failed\n"); exit(434); }
D = (UNSIGNED *) calloc(200, sizeof(UNSIGNED));
if (!(D)) {printf("\ndecode: D malloc failed\n"); exit(434); }
E = (UNSIGNED *) calloc(200, sizeof(UNSIGNED));
if (!(E)) {printf("\ndecode: E malloc failed\n"); exit(434); }
F = (UNSIGNED *) calloc(200, sizeof(UNSIGNED));
if (!(F)) {printf("\ndecode: F malloc failed\n"); exit(434); }
M = (UNSIGNED *) calloc(25*200*10, sizeof(UNSIGNED));
if (!(M)) {printf("\ndecode: M malloc failed\n"); exit(434); }
if (*pNrec < 200)
  {
  printf("*** Need %d packets to recover message",200) ;
  printf(" but only %d packets received *** \n",*pNrec) ;
  return 1 ;
  } ;
for (i=0; i < Mlen ; i++) rec_message[i] = 0 ;
gettimeofday(&start_time,0) ;
Nfirstrec = 0 ;
for (i=0; i < 200; i++) Rec_index[i] = 0 ;
m = 0 ;
for (i=0; i < *pNrec ; i++)
  {
  index = rec_packets[m] ;
  if (index < 200)
    {
    j = index * Plen ;
    Rec_index[index] = 1 ;
    for (row_eqn=0; row_eqn < 10 ; row_eqn++)
      {
      k = row_eqn * 25 ;
      l = j + k ;
      for (seg_ind=0; seg_ind < 25 ; seg_ind++)
        rec_message[seg_ind+l] = rec_packets[m+1+seg_ind+k] ;
       } ;
    Nfirstrec++ ;
    } ;
  m += Plentot ;
  } ;
Nextra = 200 - Nfirstrec ;
printf("Nfirstrec= %d, Nextra= %d \n",Nfirstrec,Nextra) ;
col_ind = 0 ;
for (i=0; i < 200 ; i++)
  {
  if (Rec_index[i] == 0)
    Col_Ind[col_ind++] = i ;
  } ;
row_ind = 0 ;
m = 0 ;
for (i=0; i < *pNrec ; i++)
  {
  if (rec_packets[m] >= 200)
    {
     k = 25*row_ind*10 ;
     Row_Ind[row_ind] = rec_packets[m] - 200 ;
     for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
      {
       j = row_eqn*25 ;
       for (seg_ind=0 ; seg_ind < 25 ; seg_ind++)
         {
          M[k] = rec_packets[m+1+seg_ind+j] ;
          k++ ;
         } ;
      } ;
     row_ind ++ ;
     if (row_ind >= Nextra) break ;
    } ;
  m += Plentot ;
  } ;
for (row_ind = 0 ; row_ind < Nextra ; row_ind++)
  {
  for (col_ind=0 ; col_ind < 200 ; col_ind++)
    {
    if (Rec_index[col_ind] == 1)
      {
      ExpFE = (SMultField - FEtoExp[Row_Ind[row_ind]^col_ind^COLBIT]) % SMultField ;
      for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
        {
        j = 25*(row_eqn + row_ind*10) ;
        for (col_eqn=0 ; col_eqn < 10 ; col_eqn++)
          {
          k = 25*(col_eqn + col_ind*10) ;
          if (ExptoFE[ExpFE+row_eqn] & BIT[col_eqn])
            {
            for (seg_ind=0 ; seg_ind < 25 ; seg_ind++)
              {
              M[j+seg_ind] ^= rec_message[k+seg_ind] ;
              } ;
            } ;
          } ;
        } ;
      } ;
    } ;
  } ;
for (row_ind = 0 ; row_ind < Nextra ; row_ind++)
  {
  for (col_ind = 0 ; col_ind < Nextra ; col_ind++)
    {
    if (col_ind != row_ind)
      {
      C[row_ind] += FEtoExp[Row_Ind[row_ind]^Row_Ind[col_ind]] ;
      D[col_ind] += FEtoExp[Col_Ind[row_ind]^Col_Ind[col_ind]] ;
      } ;
    E[row_ind] += FEtoExp[Row_Ind[row_ind]^Col_Ind[col_ind]^COLBIT] ;
    F[col_ind] += FEtoExp[Row_Ind[row_ind]^Col_Ind[col_ind]^COLBIT] ;
    } ;
  } ;
for (row_ind = 0 ; row_ind < Nextra ; row_ind++)
  {
  for (col_ind = 0 ; col_ind < Nextra ; col_ind++)
    {
    ExpFE = E[col_ind] + F[row_ind] - C[col_ind] - D[row_ind]
      - FEtoExp[Row_Ind[col_ind]^Col_Ind[row_ind]^COLBIT] ;
    if (ExpFE < 0) ExpFE = SMultField-((-ExpFE) % SMultField) ;
    ExpFE = ExpFE % SMultField ;
    j = Col_Ind[row_ind] * 10 * 25 ;
    for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
      {
      k = row_eqn*25 + j ;
      for (col_eqn=0 ; col_eqn < 10 ; col_eqn++)
        {
        l = 25 *(col_eqn + col_ind*10) ;
        if (ExptoFE[ExpFE+row_eqn] & BIT[col_eqn])
          {
          for (seg_ind=0 ; seg_ind < 25 ; seg_ind++)
            {
             rec_message[seg_ind+k] ^= M[l] ;
             l++ ;
            } ;
          } ;
        } ;
      } ;
    } ;
  } ;
gettimeofday(&end_time,0) ;
printf ("\n------------------------------------------------") ;
printf ("\n decode: number of seconds is %f",
     (float)(end_time.tv_sec-start_time.tv_sec)+
      (float)(end_time.tv_usec-start_time.tv_usec)/1000000.0) ;
printf ("\n------------------------------------------------\n\n") ;
fflush(stdout) ;
return 0 ;
}

canonical_original_code:
int Decode(unsigned int COLBIT, unsigned int *BIT, unsigned int *ExptoFE, unsigned int *FEtoExp, unsigned int *rec_packets, int *pNrec, unsigned int *rec_message)
{
int i; int j; int k; int l; int m; int index; int seg_ind;
int col_ind; int row_ind; int col_eqn; int row_eqn;
int Nfirstrec; int Nextra;
int *Rec_index;
int *Col_Ind; int *Row_Ind; int ExpFE;
unsigned int *M;
unsigned int *C; unsigned int *D; unsigned int *E; unsigned int *F;
struct timeval start_time; struct timeval end_time;
Rec_index = (int *) calloc(200, sizeof(int));
if (!(Rec_index)) {printf("\ndecode: Rec_index malloc failed\n"); exit(434); }
Col_Ind = (int *) calloc(200, sizeof(int));
if (!(Col_Ind)) {printf("\ndecode: Col_Ind malloc failed\n"); exit(434); }
Row_Ind = (int *) calloc(200, sizeof(int));
if (!(Row_Ind)) {printf("\ndecode: Row_Ind malloc failed\n"); exit(434); }
C = (unsigned int *) calloc(200, sizeof(UNSIGNED));
if (!(C)) {printf("\ndecode: C malloc failed\n"); exit(434); }
D = (unsigned int *) calloc(200, sizeof(UNSIGNED));
if (!(D)) {printf("\ndecode: D malloc failed\n"); exit(434); }
E = (unsigned int *) calloc(200, sizeof(UNSIGNED));
if (!(E)) {printf("\ndecode: E malloc failed\n"); exit(434); }
F = (unsigned int *) calloc(200, sizeof(UNSIGNED));
if (!(F)) {printf("\ndecode: F malloc failed\n"); exit(434); }
M = (unsigned int *) calloc(25*200*10, sizeof(UNSIGNED));
if (!(M)) {printf("\ndecode: M malloc failed\n"); exit(434); }
if (*pNrec < 200)
  {
  printf("*** Need %d packets to recover message",200) ;
  printf(" but only %d packets received *** \n",*pNrec) ;
  return 1 ;
  } ;
for (i=0; i < Mlen ; i++) rec_message[i] = 0 ;
gettimeofday(&start_time,0) ;
Nfirstrec = 0 ;
for (i=0; i < 200; i++) Rec_index[i] = 0 ;
m = 0 ;
for (i=0; i < *pNrec ; i++)
  {
  index = rec_packets[m] ;
  if (index < 200)
    {
    j = index * Plen ;
    Rec_index[index] = 1 ;
    for (row_eqn=0; row_eqn < 10 ; row_eqn++)
      {
      k = row_eqn * 25 ;
      l = j + k ;
      for (seg_ind=0; seg_ind < 25 ; seg_ind++)
        rec_message[seg_ind+l] = rec_packets[m+1+seg_ind+k] ;
       } ;
    Nfirstrec++ ;
    } ;
  m += Plentot ;
  } ;
Nextra = 200 - Nfirstrec ;
printf("Nfirstrec= %d, Nextra= %d \n",Nfirstrec,Nextra) ;
col_ind = 0 ;
for (i=0; i < 200 ; i++)
  {
  if (Rec_index[i] == 0)
    Col_Ind[col_ind++] = i ;
  } ;
row_ind = 0 ;
m = 0 ;
for (i=0; i < *pNrec ; i++)
  {
  if (rec_packets[m] >= 200)
    {
     k = 25*row_ind*10 ;
     Row_Ind[row_ind] = rec_packets[m] - 200 ;
     for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
      {
       j = row_eqn*25 ;
       for (seg_ind=0 ; seg_ind < 25 ; seg_ind++)
         {
          M[k] = rec_packets[m+1+seg_ind+j] ;
          k++ ;
         } ;
      } ;
     row_ind ++ ;
     if (row_ind >= Nextra) break ;
    } ;
  m += Plentot ;
  } ;
for (row_ind = 0 ; row_ind < Nextra ; row_ind++)
  {
  for (col_ind=0 ; col_ind < 200 ; col_ind++)
    {
    if (Rec_index[col_ind] == 1)
      {
      ExpFE = (SMultField - FEtoExp[Row_Ind[row_ind]^col_ind^COLBIT]) % SMultField ;
      for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
        {
        j = 25*(row_eqn + row_ind*10) ;
        for (col_eqn=0 ; col_eqn < 10 ; col_eqn++)
          {
          k = 25*(col_eqn + col_ind*10) ;
          if (ExptoFE[ExpFE+row_eqn] & BIT[col_eqn])
            {
            for (seg_ind=0 ; seg_ind < 25 ; seg_ind++)
              {
              M[j+seg_ind] ^= rec_message[k+seg_ind] ;
              } ;
            } ;
          } ;
        } ;
      } ;
    } ;
  } ;
for (row_ind = 0 ; row_ind < Nextra ; row_ind++)
  {
  for (col_ind = 0 ; col_ind < Nextra ; col_ind++)
    {
    if (col_ind != row_ind)
      {
      C[row_ind] += FEtoExp[Row_Ind[row_ind]^Row_Ind[col_ind]] ;
      D[col_ind] += FEtoExp[Col_Ind[row_ind]^Col_Ind[col_ind]] ;
      } ;
    E[row_ind] += FEtoExp[Row_Ind[row_ind]^Col_Ind[col_ind]^COLBIT] ;
    F[col_ind] += FEtoExp[Row_Ind[row_ind]^Col_Ind[col_ind]^COLBIT] ;
    } ;
  } ;
for (row_ind = 0 ; row_ind < Nextra ; row_ind++)
  {
  for (col_ind = 0 ; col_ind < Nextra ; col_ind++)
    {
    ExpFE = E[col_ind] + F[row_ind] - C[col_ind] - D[row_ind]
      - FEtoExp[Row_Ind[col_ind]^Col_Ind[row_ind]^COLBIT] ;
    if (ExpFE < 0) ExpFE = SMultField-((-ExpFE) % SMultField) ;
    ExpFE = ExpFE % SMultField ;
    j = Col_Ind[row_ind] * 10 * 25 ;
    for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
      {
      k = row_eqn*25 + j ;
      for (col_eqn=0 ; col_eqn < 10 ; col_eqn++)
        {
        l = 25 *(col_eqn + col_ind*10) ;
        if (ExptoFE[ExpFE+row_eqn] & BIT[col_eqn])
          {
          for (seg_ind=0 ; seg_ind < 25 ; seg_ind++)
            {
             rec_message[seg_ind+k] ^= M[l] ;
             l++ ;
            } ;
          } ;
        } ;
      } ;
    } ;
  } ;
gettimeofday(&end_time,0) ;
printf ("\n------------------------------------------------") ;
printf ("\n decode: number of seconds is %f",
     (float)(end_time.tv_sec-start_time.tv_sec)+
      (float)(end_time.tv_usec-start_time.tv_usec)/1000000.0) ;
printf ("\n------------------------------------------------\n\n") ;
fflush(stdout) ;
return 0 ;
}

variable_types:
COLBIT
unsigned int

variable_types: l int

variable_types: index int

variable_types: Nfirstrec int

variable_types: Nextra int

variable_types: ExpFE int

variable_types:
M
unsigned int *

variable_types:
C
unsigned int *

variable_types:
D
unsigned int *

variable_types:
E
unsigned int *

variable_types:
F
unsigned int *

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


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

for ( result = 0LL; result != 50000; ++result )
*(_DWORD *)(a1 + 4 * result) = result;
return result;
}

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

for ( result = 0LL; result != 50000; ++result )
*(_DWORD *)(a1 + 4 * result) = result;
return result;
}

original_code:
void Get_msg(UNSIGNED *message)
{
int i;
for (i=0; i < Mlen; i++) message[i] = i ;
}

canonical_original_code:
void Get_msg(unsigned int *message)
{
int i;
for (i=0; i < Mlen; i++) message[i] = i ;
}

variable_types:
message
unsigned int *

variable_types: i int

return_type: void


Encode

original_code:
void Encode(UNSIGNED COLBIT, UNSIGNED *BIT, UNSIGNED *ExptoFE,
            UNSIGNED *FEtoExp, UNSIGNED *packets, UNSIGNED *message)
{
int i,j,k,l,m, ind_seg,col_eqn,row_eqn,ind_eqn ;
int row, col, ExpFE ;
struct timeval start_time, end_time ;
for (i=0; i < Npackets ; i++) packets[i*Plentot] = i;
gettimeofday(&start_time,0) ;
k = 0 ;
j = 0 ;
for (i=0; i < 200 ; i++)
  {
  k ++ ;
  for (ind_eqn=0; ind_eqn < 10 ; ind_eqn++)
    {
    for (ind_seg =0; ind_seg < 25 ; ind_seg ++)
     {
      packets[k] = message[j] ;
      j++ ;
      k++ ;
     } ;
    } ;
  } ;
for (row=0; row < 200 ; row++)
  {
  j = (row+200)*Plentot ;
  for (i =1 ; i < Plentot ; i ++) packets[j+i] = 0 ;
  for (col=0 ; col < 200 ; col++)
    {
    m = col*10 * 25 ;
    ExpFE = (SMultField - FEtoExp[row^col^COLBIT]) % SMultField ;
    for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
      {
      k = row_eqn * 25 ;
      for (col_eqn=0 ; col_eqn < 10 ; col_eqn++)
        {
        if (ExptoFE[ExpFE+row_eqn] & BIT[col_eqn])
          {
          l = col_eqn * 25 + m ;
          for (ind_seg=0 ; ind_seg < 25 ; ind_seg++)
            {
            packets[j+1+ind_seg+k] ^= message[ind_seg+l] ;
            } ;
          } ;
        } ;
      } ;
    } ;
  } ;
gettimeofday(&end_time,0) ;
printf ("\n------------------------------------------------") ;
printf ("\n encode: number of seconds is %f",
     (float)(end_time.tv_sec-start_time.tv_sec)+
      (float)(end_time.tv_usec-start_time.tv_usec)/1000000.0) ;
printf ("\n------------------------------------------------\n\n") ;
fflush(stdout) ;
}

canonical_original_code:
void Encode(unsigned int COLBIT, unsigned int *BIT, unsigned int *ExptoFE, unsigned int *FEtoExp, unsigned int *packets, unsigned int *message)
{
int i; int j; int k; int l; int m; int ind_seg; int col_eqn; int row_eqn; int ind_eqn;
int row; int col; int ExpFE;
struct timeval start_time; struct timeval end_time;
for (i=0; i < Npackets ; i++) packets[i*Plentot] = i;
gettimeofday(&start_time,0) ;
k = 0 ;
j = 0 ;
for (i=0; i < 200 ; i++)
  {
  k ++ ;
  for (ind_eqn=0; ind_eqn < 10 ; ind_eqn++)
    {
    for (ind_seg =0; ind_seg < 25 ; ind_seg ++)
     {
      packets[k] = message[j] ;
      j++ ;
      k++ ;
     } ;
    } ;
  } ;
for (row=0; row < 200 ; row++)
  {
  j = (row+200)*Plentot ;
  for (i =1 ; i < Plentot ; i ++) packets[j+i] = 0 ;
  for (col=0 ; col < 200 ; col++)
    {
    m = col*10 * 25 ;
    ExpFE = (SMultField - FEtoExp[row^col^COLBIT]) % SMultField ;
    for (row_eqn=0 ; row_eqn < 10 ; row_eqn++)
      {
      k = row_eqn * 25 ;
      for (col_eqn=0 ; col_eqn < 10 ; col_eqn++)
        {
        if (ExptoFE[ExpFE+row_eqn] & BIT[col_eqn])
          {
          l = col_eqn * 25 + m ;
          for (ind_seg=0 ; ind_seg < 25 ; ind_seg++)
            {
            packets[j+1+ind_seg+k] ^= message[ind_seg+l] ;
            } ;
          } ;
        } ;
      } ;
    } ;
  } ;
gettimeofday(&end_time,0) ;
printf ("\n------------------------------------------------") ;
printf ("\n encode: number of seconds is %f",
     (float)(end_time.tv_sec-start_time.tv_sec)+
      (float)(end_time.tv_usec-start_time.tv_usec)/1000000.0) ;
printf ("\n------------------------------------------------\n\n") ;
fflush(stdout) ;
}

variable_types:
BIT
unsigned int *

variable_types:
ExptoFE
unsigned int *

variable_types:
FEtoExp
unsigned int *

variable_types:
packets
unsigned int *

variable_types: j int

variable_types: k int

variable_types: m int

variable_types: row int

variable_types: col int


decompiled_code:
int __fastcall Compare_msg(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rsi
__int64 v5; // rdx
int result; // eax

for ( i = 0LL; i != 50000; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = *(unsigned int *)(a2 + 4 * i);
if ( (_DWORD)v4 != (_DWORD)v5 )
result = printf("*** Error: mismatch between %x and %x in word %d\n", v4, v5, (unsigned int)i);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
__int64 i; // rbx
__int64 v4; // rsi
__int64 v5; // rdx
int result; // eax

for ( i = 0LL; i != 50000; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = *(unsigned int *)(a2 + 4 * i);
if ( (_DWORD)v4 != (_DWORD)v5 )
result = printf("*** Error: mismatch between %x and %x in word %d\n", v4, v5, (unsigned int)i);
}
return result;
}

original_code:
void Compare_msg(UNSIGNED *message, UNSIGNED *rec_message)
{
int i,j,k,l,m,n;
for (i=0; i < Mlen; i++)
 {
 if (message[i] != rec_message[i])
  {
  printf("*** Error: mismatch between %x and %x in word %d\n",
    message[i], rec_message[i], i) ;
  } ;
 } ;
}

canonical_original_code:
void Compare_msg(unsigned int *message, unsigned int *rec_message)
{
int i; int j; int k; int l; int m; int n;
for (i=0; i < Mlen; i++)
 {
 if (message[i] != rec_message[i])
  {
  printf("*** Error: mismatch between %x and %x in word %d\n",
    message[i], rec_message[i], i) ;
  } ;
 } ;
}

variable_types: l int

variable_types: n int


repo: gc-labs/ddplus

decompiled_code:
int __fastcall dd_dev_open_ro(const char *a1, int a2)
{
int result; // eax

if ( a2 )
result = open(a1, 49152);
else
result = open(a1, 0x8000);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, int a2)
{
int result; // eax

if ( a2 )
result = open(a1, 49152);
else
result = open(a1, 0x8000);
return result;
}

original_code:
int dd_dev_open_ro(char *device_name, int o_direct)
{
 if ( o_direct )
  return open(device_name, 00000000|00040000|00100000);
 return open(device_name, 00000000|00100000);
}


decompiled_code:
int __fastcall dd_dev_open_rw(const char *a1, int a2)
{
int result; // eax

if ( a2 )
result = open(a1, 49154);
else
result = open(a1, 32770);
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, int a2)
{
int result; // eax

if ( a2 )
result = open(a1, 49154);
else
result = open(a1, 32770);
return result;
}

original_code:
int dd_dev_open_rw(char *device_name, int o_direct)
{
 if ( o_direct )
  return open(device_name, 00000002|00040000|00100000);
 return open(device_name, 00000002|00100000);
}


original_code:
off64_t dd_device_size(int fd)
{
 off64_t size_bytes;
 size_bytes = lseek64(fd, 0, 2);
 if ( size_bytes == -1 )
  return -1;
 if ( lseek64(fd, 0, 0) == -1 )
  return -1;
 return size_bytes;
}

canonical_original_code:
long dd_device_size(int fd)
{
 long size_bytes;
 size_bytes = lseek64(fd, 0, 2);
 if ( size_bytes == -1 )
  return -1;
 if ( lseek64(fd, 0, 0) == -1 )
  return -1;
 return size_bytes;
}

variable_types: fd int

return_type: long


decompiled_code:
_BOOL8 __fastcall dd_file_exists(const char *a1)
{
return access(a1, 0) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
return access(a1, 0) == 0;
}

original_code:
int dd_file_exists(char *filename)
{
 return !access(filename, 0);
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall dd_file_size(const char *a1)
{
int v1; // eax
__int64 result; // rax

v1 = open(a1, 0x8000);
if ( v1 == -1 )
result = -1LL;
else
result = dd_device_size(v1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
int v1; // eax
__int64 result; // rax

v1 = open(a1, 0x8000);
if ( v1 == -1 )
result = -1LL;
else
result = func2(v1);
return result;
}

original_code:
off64_t dd_file_size(char *filename)
{
 int fd;
 if ((fd = open(filename, 00000000|00100000)) == -1 )
  return fd;
 return dd_device_size(fd);
}

canonical_original_code:
long dd_file_size(char *filename)
{
 int fd;
 if ((fd = open(filename, 00000000|00100000)) == -1 )
  return fd;
 return dd_device_size(fd);
}


decompiled_code:
__int64 __fastcall set_dd_flag(char a1)
{
return 1 << a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
return 1 << a1;
}

original_code:
u_int64_t set_dd_flag(u_int64_t flag)
{
 return (1 << flag);
}

canonical_original_code:
unsigned int set_dd_flag(unsigned int flag)
{
 return (1 << flag);
}

variable_types:
flag
unsigned int

return_type: unsigned int


decompiled_code:
void dd_loglevel_inc()
{
++log_level;
}

canonical_decompiled_code:
void func0()
{
++log_level;
}

original_code:
void dd_loglevel_inc()
{
 log_level++;
}

canonical_original_code:
void dd_loglevel_inc()
{
 log_level++;
}


decompiled_code:
int __fastcall dd_log_init(const char *a1)
{
main_thread = pthread_self();
return snprintf(log_name, 0x80uLL, "%s", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
main_thread = pthread_self();
return snprintf(log_name, 0x80uLL, "%s", a1);
}

original_code:
void dd_log_init(char *progam_name)
{
 main_thread = pthread_self();
 snprintf(log_name, 128, "%s", progam_name);
}


decompiled_code:
void dd_log(int a1, const char *a2, ...)
{
pthread_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
if ( log_level > a1 || a1 == 10 )
{
v2 = pthread_self();
if ( main_thread == v2 )
printf("%s> ", log_name);
else
printf("%s[%x]> ", log_name, (unsigned int)v2);
vfprintf(stdout, a2, arg);
putchar(10);
if ( a1 == 10 )
perror("err> perror");
}
}

canonical_decompiled_code:
void func2(int a1, const char *a2, ...)
{
pthread_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
if ( log_level > a1 || a1 == 10 )
{
v2 = pthread_self();
if ( main_thread == v2 )
printf("%s> ", log_name);
else
printf("%s[%x]> ", log_name, (unsigned int)v2);
vfprintf(stdout, a2, arg);
putchar(10);
if ( a1 == 10 )
perror("err> perror");
}
}

original_code:
void dd_log(int log_type, char *format_string, ...)
{
 va_list var_args;
 __builtin_va_start(var_args,format_string);
 if ( log_type < log_level || log_type == 10 )
 {
  pthread_t pthread = pthread_self();
  if ( pthread != main_thread )
  {
   printf("%s[%x]> ", log_name, (unsigned int)pthread);
  }
  else
  {
   printf("%s> ", log_name);
  }
  vfprintf(stdout, format_string, var_args);
  printf("\n");
 }
 if ( log_type == 10 )
 {
  perror("err> perror");
 }
 __builtin_va_end(var_args);
}

canonical_original_code:
void dd_log(int log_type, char *format_string, ...)
{
 __builtin_va_list var_args;
 __builtin_va_start(var_args,format_string);
 if ( log_type < log_level || log_type == 10 )
 {
  unsigned long pthread = pthread_self();
  if ( pthread != main_thread )
  {
   printf("%s[%x]> ", log_name, (unsigned int)pthread);
  }
  else
  {
   printf("%s> ", log_name);
  }
  vfprintf(stdout, format_string, var_args);
  printf("\n");
 }
 if ( log_type == 10 )
 {
  perror("err> perror");
 }
 __builtin_va_end(var_args);
}

variable_types:
pthread
unsigned long


original_code:
void ddmap_dump(struct ddmap_data *map_data)
{
 int cols = 8;
 int i;
 u_int32_t *ptr = map_data->map;
 char *line;
 line = malloc(132);
 if (!line)
  return;
 *line = '\0';
 for (i=0; i<map_data->map_size; i++)
 {
  if (i % cols == 0 && *line)
  {
   printf("%08llx: %s\n", (long long unsigned)i * sizeof(u_int32_t) - (cols * sizeof(u_int32_t)), line);
   *line = '\0';
  }
  snprintf(line+strlen(line), 10, "%08x ",*ptr);
  ptr++;
 }
 printf("%08llx: %s\n", (long long unsigned)i * sizeof(u_int32_t), line);
 free(line);
}

canonical_original_code:
void ddmap_dump(struct ddmap_data *map_data)
{
 int cols = 8;
 int i;
 unsigned int *ptr = map_data->map;
 char *line;
 line = malloc(132);
 if (!line)
  return;
 *line = '\0';
 for (i=0; i<map_data->map_size; i++)
 {
  if (i % cols == 0 && *line)
  {
   printf("%08llx: %s\n", (unsigned long long)i * sizeof(u_int32_t) - (cols * sizeof(u_int32_t)), line);
   *line = '\0';
  }
  snprintf(line+strlen(line), 10, "%08x ",*ptr);
  ptr++;
 }
 printf("%08llx: %s\n", (unsigned long long)i * sizeof(u_int32_t), line);
 free(line);
}

variable_types: struct ddmap_data { char map_device[1024]; unsigned int name_sum; unsigned int map_size; unsigned int map_size_bytes; unsigned int *map; } *

variable_types: cols int

variable_types:
ptr
unsigned int *

variable_types:
line
char *


decompiled_code:
__int64 __fastcall ddmap_read(__int64 a1, int a2)
{
int v2; // eax
int v3; // er13
unsigned int *v4; // rax
unsigned int *v5; // rbp
unsigned int v6; // eax
unsigned int v7; // er14
size_t v8; // r14
void *v9; // rax
ssize_t v10; // rax
__int64 v11; // rdx
__int64 v12; // rdx

v2 = dd_dev_open_ro(a1, 0LL);
if ( v2 == -1 )
{
dd_log(10LL, "unable to open map: %s", (const char *)a1);
v7 = -1;
}
else
{
v3 = v2;
dd_log(0LL, "opened map: %s", (const char *)a1);
dd_log(0LL, "header size: %d", 20LL);
v4 = (unsigned int *)malloc(0x14uLL);
v5 = v4;
if ( v4 )
{
v6 = read(v3, v4, 0x14uLL);
v7 = v6;
if ( v6 == -1 )
{
dd_log(10LL, "unable to read header from map");
}
else if ( v6 == 20 )
{
v8 = 4LL * v5[4];
*(_QWORD *)(a1 + 1024) = *(_QWORD *)(v5 + 3);
*(_QWORD *)(a1 + 1032) = v8;
if ( a2 )
{
printf("ddmap.device: %s\n", (const char *)a1);
printf("ddmap.info: %s\n", (const char *)v5);
printf("ddmap.version: %d\n", *((unsigned __int8 *)v5 + 8));
printf("ddmap.suspended: %d\n", *((unsigned __int8 *)v5 + 9));
printf("ddmap.name_sum: 0x%08x\n", v5[3]);
printf("ddmap.map_size: %u (u32)\n", v5[4]);
printf("ddmap.map_size_bytes: %llu\n", *(_QWORD *)(a1 + 1032));
v8 = *(_QWORD *)(a1 + 1032);
}
v9 = malloc(v8);
*(_QWORD *)(a1 + 1040) = v9;
if ( v9 )
{
v10 = read(v3, v9, v8);
v7 = v10;
if ( (_DWORD)v10 == -1 )
{
dd_log(10LL, "unable to read map", v11, v10);
}
else
{
v12 = *(_QWORD *)(a1 + 1032);
v7 = 0;
if ( (int)v10 != v12 )
{
v7 = -1;
dd_log(10LL, "unable to read %d map bytes, got %d bytes (map data is broken!)", v12, v10);
}
}
}
else
{
v7 = -1;
dd_log(10LL, "unable to allocate memory for map");
}
}
else
{
v7 = -1;
dd_log(10LL, "unable to read %d header bytes, got %d bytes", 20LL, v6);
}
free(v5);
}
else
{
v7 = -1;
dd_log(10LL, "unable to allocate memory for ddmap_header");
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // eax
int v3; // er13
unsigned int *v4; // rax
unsigned int *v5; // rbp
unsigned int v6; // eax
unsigned int v7; // er14
size_t v8; // r14
void *v9; // rax
ssize_t v10; // rax
__int64 v11; // rdx
__int64 v12; // rdx

v2 = dd_dev_open_ro(a1, 0LL);
if ( v2 == -1 )
{
dd_log(10LL, "unable to open map: %s", (const char *)a1);
v7 = -1;
}
else
{
v3 = v2;
dd_log(0LL, "opened map: %s", (const char *)a1);
dd_log(0LL, "header size: %d", 20LL);
v4 = (unsigned int *)malloc(0x14uLL);
v5 = v4;
if ( v4 )
{
v6 = read(v3, v4, 0x14uLL);
v7 = v6;
if ( v6 == -1 )
{
dd_log(10LL, "unable to read header from map");
}
else if ( v6 == 20 )
{
v8 = 4LL * v5[4];
*(_QWORD *)(a1 + 1024) = *(_QWORD *)(v5 + 3);
*(_QWORD *)(a1 + 1032) = v8;
if ( a2 )
{
printf("ddmap.device: %s\n", (const char *)a1);
printf("ddmap.info: %s\n", (const char *)v5);
printf("ddmap.version: %d\n", *((unsigned __int8 *)v5 + 8));
printf("ddmap.suspended: %d\n", *((unsigned __int8 *)v5 + 9));
printf("ddmap.name_sum: 0x%08x\n", v5[3]);
printf("ddmap.map_size: %u (u32)\n", v5[4]);
printf("ddmap.map_size_bytes: %llu\n", *(_QWORD *)(a1 + 1032));
v8 = *(_QWORD *)(a1 + 1032);
}
v9 = malloc(v8);
*(_QWORD *)(a1 + 1040) = v9;
if ( v9 )
{
v10 = read(v3, v9, v8);
v7 = v10;
if ( (_DWORD)v10 == -1 )
{
dd_log(10LL, "unable to read map", v11, v10);
}
else
{
v12 = *(_QWORD *)(a1 + 1032);
v7 = 0;
if ( (int)v10 != v12 )
{
v7 = -1;
dd_log(10LL, "unable to read %d map bytes, got %d bytes (map data is broken!)", v12, v10);
}
}
}
else
{
v7 = -1;
dd_log(10LL, "unable to allocate memory for map");
}
}
else
{
v7 = -1;
dd_log(10LL, "unable to read %d header bytes, got %d bytes", 20LL, v6);
}
free(v5);
}
else
{
v7 = -1;
dd_log(10LL, "unable to allocate memory for ddmap_header");
}
}
return v7;
}

original_code:
int ddmap_read(struct ddmap_data *map_data, int dump_header)
{
 int ret = 0;
 int fd;
 struct ddmap_header *hdr = ((void *)0);
 int header_bytes = sizeof(struct ddmap_header);
 int read_bytes;
 if ((fd = dd_dev_open_ro(map_data->map_device, 0)) == -1 )
 {
  dd_log(10, "unable to open map: %s",map_data->map_device);
  return -1;
 }
 dd_log(0, "opened map: %s",map_data->map_device);
 dd_log(0, "header size: %d", header_bytes);
 if ( (hdr = malloc(header_bytes)) == ((void *)0) )
 {
  dd_log(10,"unable to allocate memory for ddmap_header");
  return -1;
 }
 if ( (read_bytes = read(fd, hdr, header_bytes)) == -1 )
 {
  dd_log(10, "unable to read header from map");
  ret = -1;
  goto err;
 }
 if ( read_bytes != header_bytes )
 {
  dd_log(10, "unable to read %d header bytes, got %d bytes",
   header_bytes, read_bytes);
  ret = -1;
  goto err;
 }
 map_data->name_sum = hdr->name_sum;
 map_data->map_size = hdr->map_size;
 map_data->map_size_bytes = hdr->map_size * sizeof(u_int32_t);
 if ( dump_header )
 {
  printf("ddmap.device: %s\n", map_data->map_device);
  printf("ddmap.info: %s\n", hdr->info);
  printf("ddmap.version: %d\n", hdr->version);
  printf("ddmap.suspended: %d\n", hdr->suspended);
  printf("ddmap.name_sum: 0x%08x\n", hdr->name_sum);
  printf("ddmap.map_size: %u (u32)\n", hdr->map_size);
  printf("ddmap.map_size_bytes: %llu\n", (long long unsigned)map_data->map_size_bytes);
 }
 if ( (map_data->map = malloc(map_data->map_size_bytes)) == ((void *)0) )
 {
  dd_log(10, "unable to allocate memory for map");
  ret = -1;
  goto err;
 }
 if ( (read_bytes = read(fd, map_data->map, map_data->map_size_bytes)) == -1 )
 {
  dd_log(10, "unable to read map");
  ret = -1;
  goto err;
 }
 if ( read_bytes != map_data->map_size_bytes )
 {
  dd_log(10, "unable to read %d map bytes, got %d bytes (map data is broken!)",
   map_data->map_size_bytes, read_bytes);
  ret = -1;
  goto err;
 }
err:
 if (hdr)
  free(hdr);
 return ret;
}

canonical_original_code:
int ddmap_read(struct ddmap_data *map_data, int dump_header)
{
 int ret = 0;
 int fd;
 struct ddmap_header *hdr = ((void *)0);
 int header_bytes = sizeof(struct ddmap_header);
 int read_bytes;
 if ((fd = dd_dev_open_ro(map_data->map_device, 0)) == -1 )
 {
  dd_log(10, "unable to open map: %s",map_data->map_device);
  return -1;
 }
 dd_log(0, "opened map: %s",map_data->map_device);
 dd_log(0, "header size: %d", header_bytes);
 if ( (hdr = malloc(header_bytes)) == ((void *)0) )
 {
  dd_log(10,"unable to allocate memory for ddmap_header");
  return -1;
 }
 if ( (read_bytes = read(fd, hdr, header_bytes)) == -1 )
 {
  dd_log(10, "unable to read header from map");
  ret = -1;
  goto err;
 }
 if ( read_bytes != header_bytes )
 {
  dd_log(10, "unable to read %d header bytes, got %d bytes",
   header_bytes, read_bytes);
  ret = -1;
  goto err;
 }
 map_data->name_sum = hdr->name_sum;
 map_data->map_size = hdr->map_size;
 map_data->map_size_bytes = hdr->map_size * sizeof(u_int32_t);
 if ( dump_header )
 {
  printf("ddmap.device: %s\n", map_data->map_device);
  printf("ddmap.info: %s\n", hdr->info);
  printf("ddmap.version: %d\n", hdr->version);
  printf("ddmap.suspended: %d\n", hdr->suspended);
  printf("ddmap.name_sum: 0x%08x\n", hdr->name_sum);
  printf("ddmap.map_size: %u (u32)\n", hdr->map_size);
  printf("ddmap.map_size_bytes: %llu\n", (unsigned long long)map_data->map_size_bytes);
 }
 if ( (map_data->map = malloc(map_data->map_size_bytes)) == ((void *)0) )
 {
  dd_log(10, "unable to allocate memory for map");
  ret = -1;
  goto err;
 }
 if ( (read_bytes = read(fd, map_data->map, map_data->map_size_bytes)) == -1 )
 {
  dd_log(10, "unable to read map");
  ret = -1;
  goto err;
 }
 if ( read_bytes != map_data->map_size_bytes )
 {
  dd_log(10, "unable to read %d map bytes, got %d bytes (map data is broken!)",
   map_data->map_size_bytes, read_bytes);
  ret = -1;
  goto err;
 }
err:
 if (hdr)
  free(hdr);
 return ret;
}

variable_types: ret int

variable_types: struct ddmap_header { char info[8]; unsigned int version; unsigned int suspended; unsigned int unused1; unsigned int unused2; unsigned int name_sum; unsigned int map_size; } *

user_defined_types: struct ddmap_data { char map_device[1024]; unsigned int name_sum; unsigned int map_size; unsigned int map_size_bytes; unsigned int *map; }


original_code:
u_int32_t MurmurHash2 ( const void * key, u_int32_t len, u_int32_t seed )
{
 const u_int32_t m = 0x5bd1e995;
 const u_int32_t r = 24;
 u_int32_t h = seed ^ len;
 const unsigned char * data = (const unsigned char *)key;
 while(len >= 4)
 {
  u_int32_t k = *(u_int32_t *)data;
  k *= m;
  k ^= k >> r;
  k *= m;
  h *= m;
  h ^= k;
  data += 4;
  len -= 4;
 }
 switch(len)
 {
 case 3: h ^= data[2] << 16;
 case 2: h ^= data[1] << 8;
 case 1: h ^= data[0];
         h *= m;
 };
 h ^= h >> 13;
 h *= m;
 h ^= h >> 15;
 return h;
}

canonical_original_code:
unsigned int MurmurHash2(void *key, unsigned int len, unsigned int seed)
{
 unsigned int m = 0x5bd1e995;
 unsigned int r = 24;
 unsigned int h = seed ^ len;
 unsigned char *data = (const unsigned char *)key;
 while(len >= 4)
 {
  unsigned int k = *(u_int32_t *)data;
  k *= m;
  k ^= k >> r;
  k *= m;
  h *= m;
  h ^= k;
  data += 4;
  len -= 4;
 }
 switch(len)
 {
 case 3: h ^= data[2] << 16;
 case 2: h ^= data[1] << 8;
 case 1: h ^= data[0];
         h *= m;
 };
 h ^= h >> 13;
 h *= m;
 h ^= h >> 15;
 return h;
}

variable_types:
key
void *

variable_types:
len
unsigned int

variable_types:
seed
unsigned int

variable_types:
m
unsigned int

variable_types:
r
unsigned int

variable_types:
h
unsigned int

variable_types:
data
unsigned char *

variable_types:
k
unsigned int


decompiled_code:
__int64 __fastcall read_long(int a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = 0LL;
v1 = read(a1, &buf, 8uLL);
if ( v1 == -1 )
{
dd_log(10LL, "read_long: Failed to read %d bytes", 8LL);
exit(1);
}
v2 = v1;
dd_log(1LL, "read_long: read %d bytes", 8LL);
if ( v2 == 8 )
{
dd_log(1LL, "read_long: Returned %llu", buf);
result = buf;
}
else
{
dd_log(10LL, "read_long: Failed to read %llu bytes, actual read was %llu", 8LL, v2);
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = 0LL;
v1 = read(a1, &buf, 8uLL);
if ( v1 == -1 )
{
dd_log(10LL, "read_long: Failed to read %d bytes", 8LL);
exit(1);
}
v2 = v1;
dd_log(1LL, "read_long: read %d bytes", 8LL);
if ( v2 == 8 )
{
dd_log(1LL, "read_long: Returned %llu", buf);
result = buf;
}
else
{
dd_log(10LL, "read_long: Failed to read %llu bytes, actual read was %llu", 8LL, v2);
result = -1LL;
}
return result;
}

original_code:
u_int64_t read_long(int fd)
{
 u_int64_t buff = 0;
 int read_size = sizeof(u_int64_t);
 int buffer_read_bytes = 0;
 if ((buffer_read_bytes = read(fd, (void *)&buff, read_size))==-1)
        {
  dd_log(10, "read_long: Failed to read %d bytes", read_size);
  exit(1);
        }
 dd_log(1, "read_long: read %d bytes", read_size);
 if (buffer_read_bytes != read_size)
 {
  dd_log(10, "read_long: Failed to read %llu bytes, actual read was %llu", read_size, buffer_read_bytes);
  return -1;
 }
 dd_log(1,"read_long: Returned %llu", buff);
 return buff;
}

canonical_original_code:
unsigned int read_long(int fd)
{
 unsigned int buff = 0;
 int read_size = sizeof(u_int64_t);
 int buffer_read_bytes = 0;
 if ((buffer_read_bytes = read(fd, (void *)&buff, read_size))==-1)
        {
  dd_log(10, "read_long: Failed to read %d bytes", read_size);
  exit(1);
        }
 dd_log(1, "read_long: read %d bytes", read_size);
 if (buffer_read_bytes != read_size)
 {
  dd_log(10, "read_long: Failed to read %llu bytes, actual read was %llu", read_size, buffer_read_bytes);
  return -1;
 }
 dd_log(1,"read_long: Returned %llu", buff);
 return buff;
}

variable_types: fd int

variable_types:
buff
unsigned int


ddprofile

decompiled_code:
__int64 __fastcall ddprofile(int a1)
{
int v1; // eax
const char *v2; // rdx
size_t v3; // rax
void *v4; // rax
__int64 v5; // r13
__int64 v6; // rbp
__int64 v7; // r12
__int64 i; // rbx
__int64 v9; // r8
__int64 v10; // r9
float v11; // xmm0_4
float v12; // xmm0_4
__int64 result; // rax

*(_DWORD *)parms = a1;
v1 = dd_dev_open_rw((unsigned int)((_DWORD)parms + 2136), 0LL);
v2 = (const char *)(unsigned int)((_DWORD)parms + 2136);
*(_DWORD *)&parms[3176] = v1;
if ( v1 == -1 )
{
dd_log(10LL, "unable to open file: %s", v2);
exit(1);
}
dd_log(1LL, "opened file: %s", v2);
v3 = dd_device_size(*(unsigned int *)&parms[3176]);
*(_QWORD *)&parms[3168] = v3;
if ( v3 == -1LL )
{
dd_log(10LL, "unable to determine checksum file %s size", (const char *)(unsigned int)((_DWORD)parms + 2136));
result = 0xFFFFFFFFLL;
}
else
{
v4 = mmap64(0LL, v3, 3, 1, *(_DWORD *)&parms[3176], 0LL);
*(_QWORD *)&parms[3184] = v4;
if ( v4 == (void *)-1LL )
{
dd_log(10LL, "unable to mmap from the checksum file");
result = 0xFFFFFFFFLL;
}
else
{
v5 = 0LL;
dd_log(1LL, "checksum array ptr: %p", v4);
v6 = *(_QWORD *)&parms[3184];
v7 = *(_QWORD *)&parms[3168] >> 3;
if ( v7 )
{
for ( i = 0LL; i != v7; fprintf(stdout, "block %llu/%llu %08x %08x\n", i, v7, v9, v10) )
{
v9 = *(unsigned int *)(v6 + 8 * i);
v10 = *(unsigned int *)(v6 + 8 * i + 4);
if ( (_DWORD)v9 == 1756617503 )
v5 += (_DWORD)v10 == -1420504442;
++i;
}
if ( v5 < 0 )
v11 = (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1))
+ (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1));
else
v11 = (float)(int)v5;
v12 = v11 * 100.0;
}
else
{
v12 = 0.0;
}
fprintf(stdout, "blank %llu/%llu %.2f%%\n", v5, v7, (float)(v12 / (float)(int)v7));
munmap(*(void **)&parms[3184], *(_QWORD *)&parms[3168]);
close(*(_DWORD *)&parms[3176]);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
const char *v2; // rdx
size_t v3; // rax
void *v4; // rax
__int64 v5; // r13
__int64 v6; // rbp
__int64 v7; // r12
__int64 i; // rbx
__int64 v9; // r8
__int64 v10; // r9
float v11; // xmm0_4
float v12; // xmm0_4
__int64 result; // rax

*(_DWORD *)parms = a1;
v1 = dd_dev_open_rw((unsigned int)((_DWORD)parms + 2136), 0LL);
v2 = (const char *)(unsigned int)((_DWORD)parms + 2136);
*(_DWORD *)&parms[3176] = v1;
if ( v1 == -1 )
{
dd_log(10LL, "unable to open file: %s", v2);
exit(1);
}
dd_log(1LL, "opened file: %s", v2);
v3 = dd_device_size(*(unsigned int *)&parms[3176]);
*(_QWORD *)&parms[3168] = v3;
if ( v3 == -1LL )
{
dd_log(10LL, "unable to determine checksum file %s size", (const char *)(unsigned int)((_DWORD)parms + 2136));
result = 0xFFFFFFFFLL;
}
else
{
v4 = mmap64(0LL, v3, 3, 1, *(_DWORD *)&parms[3176], 0LL);
*(_QWORD *)&parms[3184] = v4;
if ( v4 == (void *)-1LL )
{
dd_log(10LL, "unable to mmap from the checksum file");
result = 0xFFFFFFFFLL;
}
else
{
v5 = 0LL;
dd_log(1LL, "checksum array ptr: %p", v4);
v6 = *(_QWORD *)&parms[3184];
v7 = *(_QWORD *)&parms[3168] >> 3;
if ( v7 )
{
for ( i = 0LL; i != v7; fprintf(stdout, "block %llu/%llu %08x %08x\n", i, v7, v9, v10) )
{
v9 = *(unsigned int *)(v6 + 8 * i);
v10 = *(unsigned int *)(v6 + 8 * i + 4);
if ( (_DWORD)v9 == 1756617503 )
v5 += (_DWORD)v10 == -1420504442;
++i;
}
if ( v5 < 0 )
v11 = (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1))
+ (float)(v5 & 1 | (unsigned int)((unsigned __int64)v5 >> 1));
else
v11 = (float)(int)v5;
v12 = v11 * 100.0;
}
else
{
v12 = 0.0;
}
fprintf(stdout, "blank %llu/%llu %.2f%%\n", v5, v7, (float)(v12 / (float)(int)v7));
munmap(*(void **)&parms[3184], *(_QWORD *)&parms[3168]);
close(*(_DWORD *)&parms[3176]);
result = 0LL;
}
}
return result;
}

original_code:
int ddprofile(int runmode)
{
 parms.runmode = runmode;
 if ((parms.mmap_fd = dd_dev_open_rw(parms.checksum_file, 0)) == -1 )
        {
                dd_log(10, "unable to open file: %s", parms.checksum_file);
                exit (1);
        }
        dd_log(1, "opened file: %s", parms.checksum_file);
 if ((parms.mmap_size = dd_device_size(parms.mmap_fd)) == -1 )
 {
  dd_log(10, "unable to determine checksum file %s size",parms.checksum_file);
  return -1;
 }
 parms.checksum_array = (void *)mmap64(
  0, parms.mmap_size, 0x1 | 0x2, 0x01, parms.mmap_fd, 0);
 if ( parms.checksum_array == ((void *) -1) )
 {
  dd_log(10, "unable to mmap from the checksum file");
  return -1;
 }
 dd_log(1,"checksum array ptr: %p", parms.checksum_array);
 u_int64_t i;
 u_int64_t checksum_blank = 0;
 u_int64_t check_count = parms.mmap_size / sizeof(checksum_struct);
 checksum_struct *checksum_ptr = parms.checksum_array;
 for (i=0; i < check_count; i++)
 {
  if (checksum_ptr->checksum1_murmur == 0x68b3db1f && checksum_ptr->checksum2_crc32 == 0xab54d286) {
   checksum_blank++;
  }
  fprintf (stdout, "block %llu/%llu %08x %08x\n", (long long unsigned int)i+1, (long long unsigned int)check_count, checksum_ptr->checksum1_murmur, checksum_ptr->checksum2_crc32);
  checksum_ptr++;
 }
 fprintf (stdout, "blank %llu/%llu %.2f%%\n", (long long unsigned int)checksum_blank, (long long unsigned int)check_count, 100*(float)checksum_blank/check_count);
        munmap((void*)parms.checksum_array, parms.mmap_size);
        close(parms.mmap_fd);
        return 0;
}

canonical_original_code:
int ddprofile(int runmode)
{
 parms.runmode = runmode;
 if ((parms.mmap_fd = dd_dev_open_rw(parms.checksum_file, 0)) == -1 )
        {
                dd_log(10, "unable to open file: %s", parms.checksum_file);
                exit (1);
        }
        dd_log(1, "opened file: %s", parms.checksum_file);
 if ((parms.mmap_size = dd_device_size(parms.mmap_fd)) == -1 )
 {
  dd_log(10, "unable to determine checksum file %s size",parms.checksum_file);
  return -1;
 }
 parms.checksum_array = (void *)mmap64(
  0, parms.mmap_size, 0x1 | 0x2, 0x01, parms.mmap_fd, 0);
 if ( parms.checksum_array == ((void *) -1) )
 {
  dd_log(10, "unable to mmap from the checksum file");
  return -1;
 }
 dd_log(1,"checksum array ptr: %p", parms.checksum_array);
 unsigned int i;
 unsigned int checksum_blank = 0;
 unsigned int check_count = parms.mmap_size / sizeof(checksum_struct);
 struct checksum_struct *checksum_ptr = parms.checksum_array;
 for (i=0; i < check_count; i++)
 {
  if (checksum_ptr->checksum1_murmur == 0x68b3db1f && checksum_ptr->checksum2_crc32 == 0xab54d286) {
   checksum_blank++;
  }
  fprintf (stdout, "block %llu/%llu %08x %08x\n", (unsigned long long)i+1, (unsigned long long)check_count, checksum_ptr->checksum1_murmur, checksum_ptr->checksum2_crc32);
  checksum_ptr++;
 }
 fprintf (stdout, "blank %llu/%llu %.2f%%\n", (unsigned long long)checksum_blank, (unsigned long long)check_count, 100*(float)checksum_blank/check_count);
        munmap((void *)parms.checksum_array, parms.mmap_size);
        close(parms.mmap_fd);
        return 0;
}

variable_types: runmode int

variable_types:
i
unsigned int

variable_types: struct checksum_struct { unsigned int checksum1_murmur; unsigned int checksum2_crc32; } *


repo: gcali/minesweeper

decompiled_code:
__int64 __fastcall choose_dimension_bombs(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 result; // rax
const char *v6; // rdx
unsigned int v7; // [rsp+4h] [rbp-54h] BYREF
unsigned int v8; // [rsp+8h] [rbp-50h] BYREF
unsigned int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char *s[9]; // [rsp+10h] [rbp-48h] BYREF

for ( i = 0LL; ; ++i )
{
s[i] = (char *)malloc(0x32uLL);
grid_get_data_from_id(&v7, &v8, &v9, (unsigned int)i);
if ( i )
break;
v6 = "Small";
LABEL_10:
sprintf(s[i], "%s\t (%02dx%02d)", v6, v7, v8);
LABEL_11:
;
}
if ( (_DWORD)i == 1 )
{
v6 = "Medium";
goto LABEL_10;
}
sprintf(s[i], "%s\t (%02dx%02d)", "Large", v7, v8);
if ( i != 2 )
goto LABEL_11;
result = interface_screen_choices(&v9, s, 3LL, "Choose the size");
if ( (_DWORD)result != 1 )
{
free(s[0]);
free(s[1]);
free(s[2]);
result = v9;
if ( v9 != -1 )
result = (unsigned int)grid_get_data_from_id(a1, a2, a3, v9) == 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 result; // rax
const char *v6; // rdx
unsigned int v7; // [rsp+4h] [rbp-54h] BYREF
unsigned int v8; // [rsp+8h] [rbp-50h] BYREF
unsigned int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char *s[9]; // [rsp+10h] [rbp-48h] BYREF

for ( i = 0LL; ; ++i )
{
s[i] = (char *)malloc(0x32uLL);
grid_get_data_from_id(&v7, &v8, &v9, (unsigned int)i);
if ( i )
break;
v6 = "Small";
LABEL_10:
sprintf(s[i], "%s\t (%02dx%02d)", v6, v7, v8);
LABEL_11:
;
}
if ( (_DWORD)i == 1 )
{
v6 = "Medium";
goto LABEL_10;
}
sprintf(s[i], "%s\t (%02dx%02d)", "Large", v7, v8);
if ( i != 2 )
goto LABEL_11;
result = interface_screen_choices(&v9, s, 3LL, "Choose the size");
if ( (_DWORD)result != 1 )
{
free(s[0]);
free(s[1]);
free(s[2]);
result = v9;
if ( v9 != -1 )
result = (unsigned int)grid_get_data_from_id(a1, a2, a3, v9) == 1;
}
return result;
}

original_code:
int choose_dimension_bombs(int *row_dim, int *col_dim, int *bombs)
{
  int result;
  int retval;
  char *choices[3];
  int lines = sizeof(choices) / sizeof(*choices);
  int i;
  for (i = 0; i < 3; i++)
  {
    int tmp_row, tmp_col, tmp_bombs;
    char *tmp_name;
    choices[i] = malloc(sizeof(char) * 50);
    retval = grid_get_data_from_id(&tmp_row, &tmp_col, &tmp_bombs, i);
    if (i == 0)
      tmp_name = "Small";
    else if (i == 1)
      tmp_name = "Medium";
    else if (i == 2)
      tmp_name = "Large";
    sprintf(choices[i], "%s\t (%02dx%02d)", tmp_name, tmp_row, tmp_col);
  }
  retval = interface_screen_choices(&result, choices, lines, "Choose the size");
  if (((retval) == (!(0)))) return (!(0));
  for (i = 0; i < 3; i++)
    free(choices[i]);
  if (result == -1)
    return -1;
  retval = grid_get_data_from_id(row_dim, col_dim, bombs, result);
  if (((retval) == (!(0)))) return (!(0));
  return (0);
}

canonical_original_code:
int choose_dimension_bombs(int *row_dim, int *col_dim, int *bombs)
{
  int result;
  int retval;
  char *choices[3];
  int lines = sizeof(choices) / sizeof(*choices);
  int i;
  for (i = 0; i < 3; i++)
  {
    int tmp_row; int tmp_col; int tmp_bombs;
    char *tmp_name;
    choices[i] = malloc(sizeof(char) * 50);
    retval = grid_get_data_from_id(&tmp_row, &tmp_col, &tmp_bombs, i);
    if (i == 0)
      tmp_name = "Small";
    else if (i == 1)
      tmp_name = "Medium";
    else if (i == 2)
      tmp_name = "Large";
    sprintf(choices[i], "%s\t (%02dx%02d)", tmp_name, tmp_row, tmp_col);
  }
  retval = interface_screen_choices(&result, choices, lines, "Choose the size");
  if (((retval) == (!(0)))) return (!(0));
  for (i = 0; i < 3; i++)
    free(choices[i]);
  if (result == -1)
    return -1;
  retval = grid_get_data_from_id(row_dim, col_dim, bombs, result);
  if (((retval) == (!(0)))) return (!(0));
  return (0);
}

variable_types:
bombs
int *

variable_types: result int

variable_types: retval int

variable_types:
choices
char *[3]

variable_types: lines int

variable_types: i int


decompiled_code:
__int64 __fastcall new_game(_DWORD *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
int v6; // ebx
unsigned int v7; // er12
unsigned int v9; // [rsp+8h] [rbp-1B0h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-1ACh] BYREF
unsigned int v11; // [rsp+10h] [rbp-1A8h] BYREF
unsigned int v12; // [rsp+14h] [rbp-1A4h] BYREF
unsigned int v13; // [rsp+18h] [rbp-1A0h] BYREF
int v14; // [rsp+1Ch] [rbp-19Ch] BYREF
__int64 v15; // [rsp+20h] [rbp-198h] BYREF
__int64 v16; // [rsp+28h] [rbp-190h] BYREF
__int64 v17; // [rsp+30h] [rbp-188h] BYREF
__int64 v18; // [rsp+38h] [rbp-180h] BYREF
int v19[94]; // [rsp+40h] [rbp-178h] BYREF

v6 = 0;
v13 = 10;
highscore_get_id(&v12);
grid_create(&v15, a2, a3);
v9 = (int)a2 / 2;
v10 = (int)a3 / 2;
timer_reset_time();
while ( 1 )
{
v7 = interface_grid_next_move(&v9, &v10, &v11, v15, a2, a3);
if ( v7 == -1 )
{
grid_destroy(&v15, a2, a3);
return v7;
}
if ( !v6 )
grid_populate_random(v15, v9, v10, a2, a3, a4);
grid_elaborate_move(v15, v9, v10, a2, a3, v11);
grid_status(v19, v15, a2, a3);
if ( v19[0] == 1 )
{
*a1 = 1;
goto LABEL_11;
}
if ( v19[0] == 2 )
break;
v6 = 1;
}
*a1 = 2;
LABEL_11:
timer_get_elapsed_time(&v17, &v18);
interface_reset_screen();
interface_result_screen(v15, a2, a3, (unsigned int)*a1, v17, v18);
if ( *a1 == 2 )
{
v13 = 10;
highscore_is_score_top(&v14, v12, v17, v18, 10LL);
if ( v14 )
{
highscore_get_highscores(v19, &v13, v12);
interface_new_score_screen(&v16, v19, v13);
highscore_destroy(v19, v13);
highscore_add_score(v12, v17, v18, v16);
}
v13 = 10;
highscore_get_highscores(v19, &v13, v12);
interface_print_scores(v19, v13);
highscore_destroy(v19, v13);
}
v7 = 0;
grid_destroy(&v15, a2, a3);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
int v6; // ebx
unsigned int v7; // er12
unsigned int v9; // [rsp+8h] [rbp-1B0h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-1ACh] BYREF
unsigned int v11; // [rsp+10h] [rbp-1A8h] BYREF
unsigned int v12; // [rsp+14h] [rbp-1A4h] BYREF
unsigned int v13; // [rsp+18h] [rbp-1A0h] BYREF
int v14; // [rsp+1Ch] [rbp-19Ch] BYREF
__int64 v15; // [rsp+20h] [rbp-198h] BYREF
__int64 v16; // [rsp+28h] [rbp-190h] BYREF
__int64 v17; // [rsp+30h] [rbp-188h] BYREF
__int64 v18; // [rsp+38h] [rbp-180h] BYREF
int v19[94]; // [rsp+40h] [rbp-178h] BYREF

v6 = 0;
v13 = 10;
highscore_get_id(&v12);
grid_create(&v15, a2, a3);
v9 = (int)a2 / 2;
v10 = (int)a3 / 2;
timer_reset_time();
while ( 1 )
{
v7 = interface_grid_next_move(&v9, &v10, &v11, v15, a2, a3);
if ( v7 == -1 )
{
grid_destroy(&v15, a2, a3);
return v7;
}
if ( !v6 )
grid_populate_random(v15, v9, v10, a2, a3, a4);
grid_elaborate_move(v15, v9, v10, a2, a3, v11);
grid_status(v19, v15, a2, a3);
if ( v19[0] == 1 )
{
*a1 = 1;
goto LABEL_11;
}
if ( v19[0] == 2 )
break;
v6 = 1;
}
*a1 = 2;
LABEL_11:
timer_get_elapsed_time(&v17, &v18);
interface_reset_screen();
interface_result_screen(v15, a2, a3, (unsigned int)*a1, v17, v18);
if ( *a1 == 2 )
{
v13 = 10;
highscore_is_score_top(&v14, v12, v17, v18, 10LL);
if ( v14 )
{
highscore_get_highscores(v19, &v13, v12);
interface_new_score_screen(&v16, v19, v13);
highscore_destroy(v19, v13);
highscore_add_score(v12, v17, v18, v16);
}
v13 = 10;
highscore_get_highscores(v19, &v13, v12);
interface_print_scores(v19, v13);
highscore_destroy(v19, v13);
}
v7 = 0;
grid_destroy(&v15, a2, a3);
return v7;
}

original_code:
int new_game(int *result, int row_dim, int col_dim, int bombs)
{
  int curr_row, curr_col;
  Grid grid;
  int choice;
  int game_ended = 0;
  int grid_initialized = 0;
  Time time;
  int score_id;
  Score scores[10];
  unsigned int scores_dim = 10;
  highscore_get_id(&score_id, row_dim, col_dim);
  grid_create(&grid, row_dim, col_dim);
  curr_row = row_dim / 2;
  curr_col = col_dim / 2;
  timer_reset_time();
  do
  {
    int status;
    int retval;
    retval = interface_grid_next_move(&curr_row, &curr_col, &choice, grid, row_dim, col_dim);
    if (retval == -1)
    {
      grid_destroy(&grid, row_dim, col_dim);
      return -1;
    }
    else
    {
      if (!grid_initialized)
      {
        grid_populate_random(grid, curr_row, curr_col, row_dim, col_dim, bombs);
        grid_initialized = 1;
      }
      grid_elaborate_move(grid, curr_row, curr_col, row_dim, col_dim, choice);
    }
    grid_status(&status, grid, row_dim, col_dim);
    if (status == 1)
    {
      *result = 1;
      game_ended = 1;
    }
    else if (status == 2)
    {
      *result = 2;
      game_ended = 1;
    }
  } while (!game_ended);
  timer_get_elapsed_time(&(time.sec), &(time.msec));
  interface_reset_screen();
  interface_result_screen(grid, row_dim, col_dim, *result, time);
  if (*result == 2)
  {
    char *name;
    int is_top;
    scores_dim = 10;
    highscore_is_score_top(&is_top, score_id, time, scores_dim);
    if (is_top)
    {
      highscore_get_highscores(scores, &scores_dim, score_id);
      interface_new_score_screen(&name, scores, scores_dim);
      highscore_destroy(scores, scores_dim);
      highscore_add_score(score_id, time, name);
    }
    scores_dim = 10;
    highscore_get_highscores(scores, &scores_dim, score_id);
    interface_print_scores(scores, scores_dim);
    highscore_destroy(scores, scores_dim);
  }
  grid_destroy(&grid, row_dim, col_dim);
  return (0);
}

canonical_original_code:
int new_game(int *result, int row_dim, int col_dim, int bombs)
{
  int curr_row; int curr_col;
  int **grid;
  int choice;
  int game_ended = 0;
  int grid_initialized = 0;
  struct TimeStruct time;
  int score_id;
  struct ScoreStruct scores[10];
  unsigned int scores_dim = 10;
  highscore_get_id(&score_id, row_dim, col_dim);
  grid_create(&grid, row_dim, col_dim);
  curr_row = row_dim / 2;
  curr_col = col_dim / 2;
  timer_reset_time();
  do
  {
    int status;
    int retval;
    retval = interface_grid_next_move(&curr_row, &curr_col, &choice, grid, row_dim, col_dim);
    if (retval == -1)
    {
      grid_destroy(&grid, row_dim, col_dim);
      return -1;
    }
    else
    {
      if (!grid_initialized)
      {
        grid_populate_random(grid, curr_row, curr_col, row_dim, col_dim, bombs);
        grid_initialized = 1;
      }
      grid_elaborate_move(grid, curr_row, curr_col, row_dim, col_dim, choice);
    }
    grid_status(&status, grid, row_dim, col_dim);
    if (status == 1)
    {
      *result = 1;
      game_ended = 1;
    }
    else if (status == 2)
    {
      *result = 2;
      game_ended = 1;
    }
  } while (!game_ended);
  timer_get_elapsed_time(&(time.sec), &(time.msec));
  interface_reset_screen();
  interface_result_screen(grid, row_dim, col_dim, *result, time);
  if (*result == 2)
  {
    char *name;
    int is_top;
    scores_dim = 10;
    highscore_is_score_top(&is_top, score_id, time, scores_dim);
    if (is_top)
    {
      highscore_get_highscores(scores, &scores_dim, score_id);
      interface_new_score_screen(&name, scores, scores_dim);
      highscore_destroy(scores, scores_dim);
      highscore_add_score(score_id, time, name);
    }
    scores_dim = 10;
    highscore_get_highscores(scores, &scores_dim, score_id);
    interface_print_scores(scores, scores_dim);
    highscore_destroy(scores, scores_dim);
  }
  grid_destroy(&grid, row_dim, col_dim);
  return (0);
}

variable_types:
result
int *

variable_types: bombs int

variable_types:
grid
int **

variable_types: choice int

variable_types: struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } [10]

variable_types: status int

variable_types:
name
char *

user_defined_types: struct ScoreStruct { int id; struct TimeStruct time; char *name; }


decompiled_code:
__int64 __fastcall print_highscores(unsigned int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-14Ch] BYREF
char v3[328]; // [rsp+10h] [rbp-148h] BYREF

v2 = 10;
highscore_get_highscores(v3, &v2, a1);
interface_print_scores(v3, v2);
highscore_destroy(v3, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-14Ch] BYREF
char v3[328]; // [rsp+10h] [rbp-148h] BYREF

v2 = 10;
highscore_get_highscores(v3, &v2, a1);
interface_print_scores(v3, v2);
highscore_destroy(v3, v2);
return 0LL;
}

original_code:
int print_highscores(int score_id)
{
  Score scores[10];
  unsigned int scores_dim = 10;
  highscore_get_highscores(scores, &scores_dim, score_id);
  interface_print_scores(scores, scores_dim);
  highscore_destroy(scores, scores_dim);
  return (0);
}

canonical_original_code:
int print_highscores(int score_id)
{
  struct ScoreStruct scores[10];
  unsigned int scores_dim = 10;
  highscore_get_highscores(scores, &scores_dim, score_id);
  interface_print_scores(scores, scores_dim);
  highscore_destroy(scores, scores_dim);
  return (0);
}

user_defined_types: struct TimeStruct { long sec; long msec; }


decompiled_code:
__int64 menu_highscores()
{
unsigned int v1; // [rsp+Ch] [rbp-3Ch] BYREF
int v2; // [rsp+10h] [rbp-38h] BYREF
int v3; // [rsp+14h] [rbp-34h] BYREF
char v4[4]; // [rsp+18h] [rbp-30h] BYREF
unsigned int v5; // [rsp+1Ch] [rbp-2Ch] BYREF
__int64 v6[5]; // [rsp+20h] [rbp-28h] BYREF

v6[0] = (__int64)"Small";
v6[1] = (__int64)"Medium";
v6[2] = (__int64)"Large";
if ( (unsigned int)interface_screen_choices(&v1, v6, 3LL, "Choose the size") == 1
|| (unsigned int)grid_get_data_from_id(&v2, &v3, v4, v1) == 1 )
{
return 1LL;
}
highscore_get_id(&v5);
print_highscores(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v1; // [rsp+Ch] [rbp-3Ch] BYREF
int v2; // [rsp+10h] [rbp-38h] BYREF
int v3; // [rsp+14h] [rbp-34h] BYREF
char v4[4]; // [rsp+18h] [rbp-30h] BYREF
unsigned int v5; // [rsp+1Ch] [rbp-2Ch] BYREF
__int64 v6[5]; // [rsp+20h] [rbp-28h] BYREF

v6[0] = (__int64)"Small";
v6[1] = (__int64)"Medium";
v6[2] = (__int64)"Large";
if ( (unsigned int)interface_screen_choices(&v1, v6, 3LL, "Choose the size") == 1
|| (unsigned int)grid_get_data_from_id(&v2, &v3, v4, v1) == 1 )
{
return 1LL;
}
highscore_get_id(&v5);
func2(v5);
return 0LL;
}

original_code:
int menu_highscores(void)
{
  char *(choices[]) = {"Small", "Medium", "Large"};
  int number_of_choices = sizeof(choices) / sizeof(*choices);
  char *title = "Choose the size";
  int retval;
  int result;
  int row_dim, col_dim, bombs;
  int score_id;
  retval = interface_screen_choices(&result, choices, number_of_choices, title);
  if (((retval) == (!(0)))) return (!(0));
  retval = grid_get_data_from_id(&row_dim, &col_dim, &bombs, result);
  if (((retval) == (!(0)))) return (!(0));
  highscore_get_id(&score_id, row_dim, col_dim);
  print_highscores(score_id);
  return (0);
}

canonical_original_code:
int menu_highscores()
{
  char *choices[] = {"Small", "Medium", "Large"};
  int number_of_choices = sizeof(choices) / sizeof(*choices);
  char *title = "Choose the size";
  int retval;
  int result;
  int row_dim; int col_dim; int bombs;
  int score_id;
  retval = interface_screen_choices(&result, choices, number_of_choices, title);
  if (((retval) == (!(0)))) return (!(0));
  retval = grid_get_data_from_id(&row_dim, &col_dim, &bombs, result);
  if (((retval) == (!(0)))) return (!(0));
  highscore_get_id(&score_id, row_dim, col_dim);
  print_highscores(score_id);
  return (0);
}

variable_types:
choices
char *[]

variable_types:
title
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // [rsp+4h] [rbp-34h] BYREF
unsigned int v5; // [rsp+8h] [rbp-30h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v7[5]; // [rsp+10h] [rbp-28h] BYREF

highscore_init(argc, argv, envp);
result = interface_init();
if ( result != 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
interface_reset_screen();
v7[0] = (__int64)"New Game";
v7[1] = (__int64)"Help";
v7[2] = (__int64)"Highscores";
v7[3] = (__int64)"Exit";
interface_screen_choices(&v4, v7, 4LL, "MineSweeper");
if ( v4 )
break;
if ( (unsigned int)choose_dimension_bombs((__int64)&v5, (__int64)&v6, (__int64)v7) != -1 )
new_game(&v4, v5, v6, v7[0]);
}
if ( v4 != 1 )
break;
interface_print_help(
"Use the arrow keys or 'h', 'j', 'k', 'l' to move,\n"
"'f' to flag the selected cell, Enter or 'rr' to uncover\n"
"the selected cell and 'q' or 'x' to go back to the previous\n"
"screen or quit the program.\n"
"\n"
"Important: if the selected board size is too large\n"
"for the screen, the interface will probably not work\n"
"correctly. The only solution is to close and reopen\n"
"the program.\n");
}
if ( v4 != 2 )
break;
menu_highscores();
}
interface_close_down();
highscore_save();
highscore_close_down();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // [rsp+4h] [rbp-34h] BYREF
unsigned int v5; // [rsp+8h] [rbp-30h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v7[5]; // [rsp+10h] [rbp-28h] BYREF

highscore_init(argc, argv, envp);
result = interface_init();
if ( result != 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
interface_reset_screen();
v7[0] = (__int64)"New Game";
v7[1] = (__int64)"Help";
v7[2] = (__int64)"Highscores";
v7[3] = (__int64)"Exit";
interface_screen_choices(&v4, v7, 4LL, "MineSweeper");
if ( v4 )
break;
if ( (unsigned int)func0((__int64)&v5, (__int64)&v6, (__int64)v7) != -1 )
func1(&v4, v5, v6, v7[0]);
}
if ( v4 != 1 )
break;
interface_print_help(
"Use the arrow keys or 'h', 'j', 'k', 'l' to move,\n"
"'f' to flag the selected cell, Enter or 'rr' to uncover\n"
"the selected cell and 'q' or 'x' to go back to the previous\n"
"screen or quit the program.\n"
"\n"
"Important: if the selected board size is too large\n"
"for the screen, the interface will probably not work\n"
"correctly. The only solution is to close and reopen\n"
"the program.\n");
}
if ( v4 != 2 )
break;
func3();
}
interface_close_down();
highscore_save();
highscore_close_down();
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
  int retval;
  int result;
  highscore_init();
  retval = interface_init();
  if (((retval) == (!(0)))) return (!(0));
  while (1)
  {
    interface_reset_screen();
    {
      char *(choices[]) = {"New Game", "Help", "Highscores", "Exit"};
      int number_of_choices = sizeof(choices) / sizeof(*choices);
      char *title = "MineSweeper";
      retval = interface_screen_choices(&result, choices, number_of_choices, title);
    }
    if (result == 0)
    {
      int row_dim, col_dim;
      int bombs;
      retval = choose_dimension_bombs(&row_dim, &col_dim, &bombs);
      if (retval != -1)
      {
        retval = new_game(&result, row_dim, col_dim, bombs);
      }
    }
    else if (result == 1)
    {
      interface_print_help(help_screen_string);
    }
    else if (result == 2)
      menu_highscores();
    else
      break;
  }
  interface_close_down();
  highscore_save();
  highscore_close_down();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int retval;
  int result;
  highscore_init();
  retval = interface_init();
  if (((retval) == (!(0)))) return (!(0));
  while (1)
  {
    interface_reset_screen();
    {
      char *choices[] = {"New Game", "Help", "Highscores", "Exit"};
      int number_of_choices = sizeof(choices) / sizeof(*choices);
      char *title = "MineSweeper";
      retval = interface_screen_choices(&result, choices, number_of_choices, title);
    }
    if (result == 0)
    {
      int row_dim; int col_dim;
      int bombs;
      retval = choose_dimension_bombs(&row_dim, &col_dim, &bombs);
      if (retval != -1)
      {
        retval = new_game(&result, row_dim, col_dim, bombs);
      }
    }
    else if (result == 1)
    {
      interface_print_help(help_screen_string);
    }
    else if (result == 2)
      menu_highscores();
    else
      break;
  }
  interface_close_down();
  highscore_save();
  highscore_close_down();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
_BOOL8 __fastcall is_attr_on(int a1, int a2)
{
_BOOL8 result; // rax

if ( a2 )
result = (a2 & a1) == a2;
else
result = a1 == 0;
return result;
}

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

if ( a2 )
result = (a2 & a1) == a2;
else
result = a1 == 0;
return result;
}

original_code:
int is_attr_on(int var, int attr)
{
  if (attr == 0)
  {
    return var == attr;
  }
  return (((var) & (attr)) == (attr));
}

variable_types: var int

variable_types: attr int


decompiled_code:
__int64 __fastcall toggle_attr(unsigned int a1, int a2)
{
return a2 ^ a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
return a2 ^ a1;
}

original_code:
int toggle_attr(int var, int attr)
{
  return var ^ attr;
}


decompiled_code:
__int64 __fastcall turn_attr_off(int a1, int a2)
{
return a1 & (unsigned int)~a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return a1 & (unsigned int)~a2;
}

original_code:
int turn_attr_off(int var, int attr)
{
  return var & (~attr);
}


decompiled_code:
__int64 __fastcall turn_attr_on(unsigned int a1, int a2)
{
return a2 | a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2)
{
return a2 | a1;
}

original_code:
int turn_attr_on(int var, int attr)
{
  return var | attr;
}


original_code:
int string_append(char **string, int *dim, char c) {
  if (*string == ((void *)0)) {
    *string = malloc(sizeof(char) * 50);
    *dim = 50;
    (*string)[0] = c;
    (*string)[1] = '\0';
    return 1;
  }
  if (strlen(*string) + 2 > *dim) {
   char *temp_string;
   temp_string = realloc(*string, (*dim) + 50);
   *string = temp_string;
   *dim = *dim + 50;
  }
  {
    int i;
    for (i = 0; (*string)[i] != '\0'; i++)
      ;
    (*string)[i] = c;
    (*string)[i+1] = '\0';
  }
  return 1;
}

variable_types:
string
char **

variable_types:
dim
int *

variable_types: c char


decompiled_code:
__int64 __fastcall string_to_num(int *a1, char *a2)
{
char v2; // al
__int64 v3; // rdx
int v4; // er8
int v5; // eax
int v6; // ecx
int v7; // er8
__int64 result; // rax

*a1 = 0;
v2 = *a2;
if ( *a2 )
{
v3 = 0LL;
v4 = 1;
while ( 1 )
{
while ( v2 == 45 && !(_DWORD)v3 )
{
++v3;
v4 = -v4;
v2 = a2[v3];
if ( !v2 )
{
LABEL_8:
v7 = *a1 * v4;
goto LABEL_9;
}
}
if ( (unsigned __int8)(v2 - 48) > 9u )
break;
v5 = 10 * *a1;
*a1 = v5;
v6 = a2[v3++];
*a1 = v5 + v6 - 48;
v2 = a2[v3];
if ( !v2 )
goto LABEL_8;
}
result = 1LL;
}
else
{
v7 = 0;
LABEL_9:
*a1 = v7;
result = 0LL;
}
return result;
}

original_code:
int string_to_num(int *num, const char *string) {
 int i;
 int fact;
 *num = 0;
  fact = 1;
 for (i = 0; string[i] != '\0'; i++) {
  if (i == 0 && string[i] == '-')
   fact *= -1;
  else if (!((string[i]) >= '0' && (string[i]) <= '9')) {
   return 1;
  }
  else {
   *num *= 10;
   *num += string[i] - '0';
  }
 }
  *num *= fact;
 return 0;
}

canonical_original_code:
int string_to_num(int *num, char *string) {
 int i;
 int fact;
 *num = 0;
  fact = 1;
 for (i = 0; string[i] != '\0'; i++) {
  if (i == 0 && string[i] == '-')
   fact *= -1;
  else if (!((string[i]) >= '0' && (string[i]) <= '9')) {
   return 1;
  }
  else {
   *num *= 10;
   *num += string[i] - '0';
  }
 }
  *num *= fact;
 return 0;
}

variable_types:
num
int *

variable_types:
string
char *

variable_types: i int

variable_types: fact int


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

result = 0LL;
if ( a2 >= 0 )
{
for ( result = 1LL; a2; --a2 )
result = (unsigned int)(a1 * result);
}
return result;
}

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

result = 0LL;
if ( a2 >= 0 )
{
for ( result = 1LL; a2; --a2 )
result = (unsigned int)(a1 * result);
}
return result;
}

original_code:
int pow_int(int base, int exp) {
  int res;
  res = 1;
  if (exp < 0)
    return 0;
  while (exp >= 1) {
    res *= base;
    exp--;
  }
  return res;
}

variable_types: base int

variable_types: exp int

variable_types: res int


decompiled_code:
__int64 __fastcall last_digit(unsigned int a1)
{
unsigned int i; // er8

for ( i = a1; i + 9 > 0x12; i = (int)i / 10 )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
unsigned int i; // er8

for ( i = a1; i + 9 > 0x12; i = (int)i / 10 )
;
return i;
}

original_code:
int last_digit(int num) {
  while (num / 10 != 0)
    num /= 10;
  return num;
}

variable_types: num int


decompiled_code:
__int64 __fastcall number_of_digits(int a1)
{
unsigned int i; // er8

for ( i = 0; a1; a1 /= 10 )
++i;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
unsigned int i; // er8

for ( i = 0; a1; a1 /= 10 )
++i;
return i;
}

original_code:
int number_of_digits(int num) {
  int digits;
  for (digits = 0; num != 0; digits++) {
    num /= 10;
  }
  return digits;
}

variable_types: digits int


decompiled_code:
__int64 __fastcall string_length(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int string_length(char *string) {
  int i;
  for (i = 0; string[i] != '\0'; i++)
    ;
  return i;
}


digit

decompiled_code:
__int64 __fastcall digit(int a1)
{
int v1; // eax
int v2; // ecx

pow_int(10, a1);
v1 = pow_int(10, 2);
return (unsigned int)(v2 % v1);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
int v1; // eax
int v2; // ecx

func8(10, a1);
v1 = func8(10, 2);
return (unsigned int)(v2 % v1);
}

original_code:
int digit(int digit_number, int num) {
  num /= pow_int(10, digit_number);
  num %= pow_int(10, 2);
  return num;
}


chomp

decompiled_code:
__int64 __fastcall chomp(const char *a1)
{
a1[strlen(a1) - 1] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1)
{
a1[strlen(a1) - 1] = 0;
return 0LL;
}

original_code:
int chomp (char *string) {
  string[strlen(string) - 1] = '\0';
  return 0;
}

canonical_original_code:
int chomp(char *string) {
  string[strlen(string) - 1] = '\0';
  return 0;
}


decompiled_code:
__int64 __fastcall is_string_a_number(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0LL;
while ( (unsigned __int8)(v1 - 48) <= 9u || !(_DWORD)v2 && v1 == 45 )
{
v1 = a1[++v2];
if ( !v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0LL;
while ( (unsigned __int8)(v1 - 48) <= 9u || !(_DWORD)v2 && v1 == 45 )
{
v1 = a1[++v2];
if ( !v1 )
return 1LL;
}
return 0LL;
}

original_code:
int is_string_a_number(char *string) {
  int i;
  for (i = 0; string[i] != '\0'; i++) {
    if (!((string[i]) >= '0' && (string[i]) <= '9'))
      if (i != 0 || string[i] != '-')
        return 0;
  }
  return 1;
}


decompiled_code:
__int64 __fastcall highscore_std_cmp(__int64 a1, int a2, __int64 a3, int a4)
{
__int64 result; // rax

if ( a1 < a3 )
return 0xFFFFFFFFLL;
result = 1LL;
if ( a1 <= a3 )
result = (unsigned int)(a2 - a4);
return result;
}

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

if ( a1 < a3 )
return 0xFFFFFFFFLL;
result = 1LL;
if ( a1 <= a3 )
result = (unsigned int)(a2 - a4);
return result;
}

original_code:
static int highscore_std_cmp(Time a, Time b)
{
  if (a.sec < b.sec)
    return -1;
  else if (a.sec > b.sec)
    return 1;
  else
    return a.msec - b.msec;
}

canonical_original_code:
static int highscore_std_cmp(struct TimeStruct a, struct TimeStruct b)
{
  if (a.sec < b.sec)
    return -1;
  else if (a.sec > b.sec)
    return 1;
  else
    return a.msec - b.msec;
}

variable_types: struct TimeStruct { long sec; long msec; }

variable_types:
b
struct TimeStruct


decompiled_code:
__int64 highscore_close_down()
{
while ( score_list )
highscore_remove_first_isra_0();
if ( scores_file )
{
free(scores_file);
scores_file = 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
while ( score_list )
func2();
if ( scores_file )
{
free(scores_file);
scores_file = 0LL;
}
return 0LL;
}

original_code:
int highscore_close_down()
{
  while (score_list != ((void *)0))
    highscore_remove_first();
  if (scores_file != ((void *)0))
  {
    free(scores_file);
    scores_file = ((void *)0);
  }
  return (0);
}


decompiled_code:
__int64 __fastcall highscore_destroy(__int64 a1, int a2)
{
void **v2; // rbx

if ( !a2 )
return 0LL;
v2 = (void **)(a1 + 24);
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
v2 += 4;
}
while ( v2 != (void **)(a1 + 32LL * (unsigned int)(a2 - 1) + 56) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
void **v2; // rbx

if ( !a2 )
return 0LL;
v2 = (void **)(a1 + 24);
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
v2 += 4;
}
while ( v2 != (void **)(a1 + 32LL * (unsigned int)(a2 - 1) + 56) );
return 0LL;
}

original_code:
int highscore_destroy(Score array[], unsigned int nmemb)
{
  int i;
  for (i = 0; i < nmemb; i++)
    if (array[i].name != ((void *)0))
    {
      free(array[i].name);
      array[i].name = ((void *)0);
    }
  return (0);
}

canonical_original_code:
int highscore_destroy(struct ScoreStruct array[], unsigned int nmemb)
{
  int i;
  for (i = 0; i < nmemb; i++)
    if (array[i].name != ((void *)0))
    {
      free(array[i].name);
      array[i].name = ((void *)0);
    }
  return (0);
}

variable_types: struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } []

variable_types:
nmemb
unsigned int


decompiled_code:
__int64 __fastcall highscore_get_highscores(__int64 a1, unsigned int *a2, int a3)
{
char *v3; // rbx
unsigned int v6; // ebp
__int64 v7; // r12
__m128i v8; // xmm0
const char *v9; // rdi
__int64 v10; // r12
size_t v11; // rax
char *v12; // rax

v3 = (char *)score_list;
if ( *a2 && score_list )
{
v6 = 0;
while ( 1 )
{
if ( *(_DWORD *)v3 == a3 )
{
v7 = v6;
v8 = _mm_loadu_si128((const __m128i *)(v3 + 8));
v9 = (const char *)*((_QWORD *)v3 + 3);
++v6;
v10 = a1 + 32 * v7;
*(_DWORD *)v10 = a3;
*(__m128i *)(v10 + 8) = v8;
v11 = strlen(v9);
v12 = (char *)malloc(v11 + 1);
*(_QWORD *)(v10 + 24) = v12;
strcpy(v12, *((const char **)v3 + 3));
v3 = (char *)*((_QWORD *)v3 + 4);
if ( *a2 <= v6 )
goto LABEL_8;
}
else
{
v3 = (char *)*((_QWORD *)v3 + 4);
if ( *a2 <= v6 )
goto LABEL_8;
}
if ( !v3 )
goto LABEL_8;
}
}
v6 = 0;
LABEL_8:
*a2 = v6;
return 0LL;
}

original_code:
int highscore_get_highscores(Score *array, unsigned int *nmemb, int id)
{
  unsigned int i;
  List work_list;
  i = 0;
  work_list = score_list;
  while (i < *nmemb && work_list != ((void *)0))
  {
    if (work_list->score.id == id)
    {
      array[i].time = work_list->score.time;
      array[i].id = work_list->score.id;
      array[i].name = malloc(sizeof(char) * (strlen(work_list->score.name) + 1));
      strcpy(array[i].name, work_list->score.name);
      i++;
    }
    work_list = work_list->next;
  }
  if (i < *nmemb);
    *nmemb = i;
  return (0);
}

canonical_original_code:
int highscore_get_highscores(struct ScoreStruct *array, unsigned int *nmemb, int id)
{
  unsigned int i;
  struct NodeStruct *work_list;
  i = 0;
  work_list = score_list;
  while (i < *nmemb && work_list != ((void *)0))
  {
    if (work_list->score.id == id)
    {
      array[i].time = work_list->score.time;
      array[i].id = work_list->score.id;
      array[i].name = malloc(sizeof(char) * (strlen(work_list->score.name) + 1));
      strcpy(array[i].name, work_list->score.name);
      i++;
    }
    work_list = work_list->next;
  }
  if (i < *nmemb);
    *nmemb = i;
  return (0);
}

variable_types: struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } *

variable_types:
nmemb
unsigned int *

variable_types: id int

variable_types:
i
unsigned int

variable_types: struct NodeStruct { struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } score; struct NodeStruct *next; } *

user_defined_types: struct NodeStruct { struct ScoreStruct score; struct NodeStruct *next; }


decompiled_code:
__int64 __fastcall highscore_add_score_struct(int a1, int a2, int a3, int a4, int a5, int a6, int a7, __int128 a8, char *s)
{
_QWORD *v9; // r8
void **v10; // rbx
char *v11; // r12
__int64 v12; // r8
char *v13; // rax
__m128i v14; // xmm0
_QWORD *v15; // r13
size_t v16; // r14
void *v17; // rax
__int64 result; // rax

v9 = score_list;
v10 = &score_list;
v11 = s;
if ( score_list )
{
do
{
if ( *(_DWORD *)v9 > a7 )
break;
if ( (int)highscore_std_cmp(v9[1], v9[2], a8, SDWORD2(a8)) > 0 )
break;
v10 = (void **)(v12 + 32);
v9 = *(_QWORD **)(v12 + 32);
}
while ( v9 );
}
v13 = (char *)malloc(0x28uLL);
v14 = _mm_loadu_si128((const __m128i *)&a8);
*(_DWORD *)v13 = a7;
v15 = v13;
*(__m128i *)(v13 + 8) = v14;
v16 = strlen(v11) + 1;
v17 = malloc(v16);
v15[3] = v17;
memcpy(v17, v11, v16);
v15[4] = *v10;
result = 0LL;
*v10 = v15;
return result;
}

original_code:
int highscore_add_score_struct(Score score)
{
  List *work_list;
  List aux_list;
  work_list = &score_list;
  while (*work_list != ((void *)0) &&
         (*work_list)->score.id <= score.id &&
         highscore_std_cmp((*work_list)->score.time, score.time) <= 0)
    work_list = &((*work_list)->next);
  aux_list = malloc(sizeof(*aux_list));
  aux_list->score.id = score.id;
  aux_list->score.time = score.time;
  aux_list->score.name = malloc(sizeof(char) * (strlen(score.name) + 1));
  strcpy(aux_list->score.name, score.name);
  aux_list->next = *work_list;
  *work_list = aux_list;
  return (0);
}

canonical_original_code:
int highscore_add_score_struct(struct ScoreStruct score)
{
  struct NodeStruct **work_list;
  struct NodeStruct *aux_list;
  work_list = &score_list;
  while (*work_list != ((void *)0) &&
         (*work_list)->score.id <= score.id &&
         highscore_std_cmp((*work_list)->score.time, score.time) <= 0)
    work_list = &((*work_list)->next);
  aux_list = malloc(sizeof(*aux_list));
  aux_list->score.id = score.id;
  aux_list->score.time = score.time;
  aux_list->score.name = malloc(sizeof(char) * (strlen(score.name) + 1));
  strcpy(aux_list->score.name, score.name);
  aux_list->next = *work_list;
  *work_list = aux_list;
  return (0);
}

variable_types: struct NodeStruct { struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } score; struct NodeStruct *next; } **


decompiled_code:
__int64 __fastcall highscore_add_score(int a1, __int64 a2, __int64 a3, char *a4, int a5, int a6)
{
__int128 v7; // [rsp-18h] [rbp-40h]

*((_QWORD *)&v7 + 1) = a3;
*(_QWORD *)&v7 = a2;
return highscore_add_score_struct(a1, a2, a3, (int)a4, a5, a6, a1, v7, a4);
}

original_code:
int highscore_add_score(int id, Time time, char *name)
{
  Score score;
  score.id = id;
  score.time = time;
  score.name = name;
  return highscore_add_score_struct(score);
}

canonical_original_code:
int highscore_add_score(int id, struct TimeStruct time, char *name)
{
  struct ScoreStruct score;
  score.id = id;
  score.time = time;
  score.name = name;
  return highscore_add_score_struct(score);
}

variable_types:
name
char *

variable_types: struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; }


decompiled_code:
__int64 highscore_init()
{
const char *v0; // rdi

v0 = scores_file;
if ( !scores_file )
{
highscore_init_scores_file_string_isra_0();
v0 = scores_file;
}
highscore_stream = fopen(v0, "r");
if ( highscore_stream )
highscore_import_file_isra_0(highscore_stream);
else
highscore_stream = fopen(scores_file, "w");
fclose(highscore_stream);
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
const char *v0; // rdi

v0 = scores_file;
if ( !scores_file )
{
func1();
v0 = scores_file;
}
highscore_stream = fopen(v0, "r");
if ( highscore_stream )
func9(highscore_stream);
else
highscore_stream = fopen(scores_file, "w");
fclose(highscore_stream);
return 0LL;
}

original_code:
int highscore_init()
{
  if (scores_file == ((void *)0))
    highscore_init_scores_file_string();
  highscore_stream = fopen(scores_file, "r");
  if (highscore_stream == ((void *)0))
    highscore_stream = fopen(scores_file, "w");
  else
    highscore_import_file(highscore_stream);
  fclose(highscore_stream);
  return 0;
}


decompiled_code:
__int64 __fastcall highscore_is_score_top(_DWORD *a1, int a2, __int64 a3, int a4, int a5)
{
_QWORD *v5; // r9
int v9; // ebx
__int64 v10; // r9
int v11; // er10

v5 = score_list;
v9 = 0;
if ( score_list )
{
do
{
if ( *(_DWORD *)v5 > a2 )
break;
if ( (int)highscore_std_cmp(v5[1], v5[2], a3, a4) > 0 )
break;
v5 = *(_QWORD **)(v10 + 32);
v9 += v11 == a2;
}
while ( v5 );
}
*a1 = a5 > v9;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, int a2, __int64 a3, int a4, int a5)
{
_QWORD *v5; // r9
int v9; // ebx
__int64 v10; // r9
int v11; // er10

v5 = score_list;
v9 = 0;
if ( score_list )
{
do
{
if ( *(_DWORD *)v5 > a2 )
break;
if ( (int)func0(v5[1], v5[2], a3, a4) > 0 )
break;
v5 = *(_QWORD **)(v10 + 32);
v9 += v11 == a2;
}
while ( v5 );
}
*a1 = a5 > v9;
return 0LL;
}

original_code:
int highscore_is_score_top(int *result, int id, Time time, int top)
{
  int i;
  List aux_list;
  aux_list = score_list;
  i = 0;
  while (aux_list != ((void *)0) &&
         aux_list->score.id <= id &&
         highscore_std_cmp(aux_list->score.time, time) <= 0)
  {
    if (aux_list->score.id == id)
      i++;
    aux_list = aux_list->next;
  }
  *result = i < top;
  return (0);
}

canonical_original_code:
int highscore_is_score_top(int *result, int id, struct TimeStruct time, int top)
{
  int i;
  struct NodeStruct *aux_list;
  aux_list = score_list;
  i = 0;
  while (aux_list != ((void *)0) &&
         aux_list->score.id <= id &&
         highscore_std_cmp(aux_list->score.time, time) <= 0)
  {
    if (aux_list->score.id == id)
      i++;
    aux_list = aux_list->next;
  }
  *result = i < top;
  return (0);
}

variable_types:
result
int *

variable_types: top int

variable_types: i int


decompiled_code:
__int64 highscore_print_debug()
{
_QWORD *v0; // rbx
int v1; // ebp

v0 = score_list;
if ( score_list )
{
v1 = 0;
do
{
printf("%02d) %ld.%ld | %s\n", (unsigned int)++v1, v0[1], v0[2], (const char *)v0[3]);
v0 = (_QWORD *)v0[4];
}
while ( v0 );
}
puts("---");
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
_QWORD *v0; // rbx
int v1; // ebp

v0 = score_list;
if ( score_list )
{
v1 = 0;
do
{
printf("%02d) %ld.%ld | %s\n", (unsigned int)++v1, v0[1], v0[2], (const char *)v0[3]);
v0 = (_QWORD *)v0[4];
}
while ( v0 );
}
puts("---");
return 0LL;
}

original_code:
int highscore_print_debug()
{
  List work_list;
  int i;
  work_list = score_list;
  i = 0;
  while (work_list != ((void *)0))
  {
    printf("%02d) %ld.%ld | %s\n", ++i,
                                 work_list->score.time.sec,
                                 work_list->score.time.msec,
                                 work_list->score.name);
    work_list = work_list->next;
  }
  printf("---\n");
  return (0);
}

canonical_original_code:
int highscore_print_debug()
{
  struct NodeStruct *work_list;
  int i;
  work_list = score_list;
  i = 0;
  while (work_list != ((void *)0))
  {
    printf("%02d) %ld.%ld | %s\n", ++i,
                                 work_list->score.time.sec,
                                 work_list->score.time.msec,
                                 work_list->score.name);
    work_list = work_list->next;
  }
  printf("---\n");
  return (0);
}


decompiled_code:
__int64 __fastcall highscore_get_id(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax

result = 0LL;
*a1 = a3 + 100 * a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, int a2, int a3)
{
__int64 result; // rax

result = 0LL;
*a1 = a3 + 100 * a2;
return result;
}

original_code:
int highscore_get_id(int *id, int row_dim, int col_dim)
{
  *id = row_dim * 100 + col_dim;
  return (0);
}

variable_types:
id
int *


decompiled_code:
__int64 timer_reset_time()
{
gettimeofday(&set_time, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
gettimeofday(&set_time, 0LL);
return 0LL;
}

original_code:
int timer_reset_time(void)
{
  gettimeofday(&set_time, ((void *)0));
  return (0);
}

canonical_original_code:
int timer_reset_time()
{
  gettimeofday(&set_time, ((void *)0));
  return (0);
}