insert

decompiled_code:
void insert()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rax
_DWORD *v3; // rbp
_DWORD *v4; // rbp
_DWORD *v5; // rbp
_DWORD *v6; // rdx
void *v7; // rdi
_QWORD *v8; // rax
int v9; // ecx
void *v10; // rdi
_DWORD **v11; // rdx

v0 = malloc(0x10uLL);
if ( !v0 )
return;
v1 = v0;
v0[1] = 0LL;
v2 = malloc(0x18uLL);
*v1 = v2;
if ( !v2 )
{
free(v1);
return;
}
fflush(stdin);
printf("Student's ID: ");
v3 = (_DWORD *)*v1;
*v3 = getInt();
fflush(stdin);
printf("Student's name: ");
v4 = (_DWORD *)*v1;
*((_QWORD *)v4 + 1) = getString();
fflush(stdin);
printf("Student's house: ");
v5 = (_DWORD *)*v1;
*((_QWORD *)v5 + 2) = getString();
v6 = (_DWORD *)*v1;
v7 = *(void **)(*v1 + 8LL);
if ( !v7 )
goto LABEL_12;
if ( !*((_QWORD *)v6 + 2) )
{
free(v7);
LABEL_12:
v10 = *(void **)(*v1 + 16LL);
if ( v10 )
free(v10);
free((void *)*v1);
free(v1);
return;
}
v8 = first;
if ( first )
{
v9 = *v6;
if ( *v6 >= **(_DWORD **)first )
{
while ( 1 )
{
if ( v9 == *(_DWORD *)*v8 )
{
free(v7);
free(*(void **)(*v1 + 16LL));
free((void *)*v1);
free(v1);
goto LABEL_8;
}
v11 = (_DWORD **)v8[1];
if ( !v11 )
break;
if ( v9 < **v11 )
{
v1[1] = v11;
v8[1] = v1;
goto LABEL_8;
}
v8 = (_QWORD *)v8[1];
}
v8[1] = v1;
}
else
{
v1[1] = first;
first = v1;
}
}
else
{
first = v1;
}
LABEL_8:
traverse();
}

canonical_decompiled_code:
void func10()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rax
_DWORD *v3; // rbp
_DWORD *v4; // rbp
_DWORD *v5; // rbp
_DWORD *v6; // rdx
void *v7; // rdi
_QWORD *v8; // rax
int v9; // ecx
void *v10; // rdi
_DWORD **v11; // rdx

v0 = malloc(0x10uLL);
if ( !v0 )
return;
v1 = v0;
v0[1] = 0LL;
v2 = malloc(0x18uLL);
*v1 = v2;
if ( !v2 )
{
free(v1);
return;
}
fflush(stdin);
printf("Student's ID: ");
v3 = (_DWORD *)*v1;
*v3 = func12();
fflush(stdin);
printf("Student's name: ");
v4 = (_DWORD *)*v1;
*((_QWORD *)v4 + 1) = func11();
fflush(stdin);
printf("Student's house: ");
v5 = (_DWORD *)*v1;
*((_QWORD *)v5 + 2) = func11();
v6 = (_DWORD *)*v1;
v7 = *(void **)(*v1 + 8LL);
if ( !v7 )
goto LABEL_12;
if ( !*((_QWORD *)v6 + 2) )
{
free(v7);
LABEL_12:
v10 = *(void **)(*v1 + 16LL);
if ( v10 )
free(v10);
free((void *)*v1);
free(v1);
return;
}
v8 = first;
if ( first )
{
v9 = *v6;
if ( *v6 >= **(_DWORD **)first )
{
while ( 1 )
{
if ( v9 == *(_DWORD *)*v8 )
{
free(v7);
free(*(void **)(*v1 + 16LL));
free((void *)*v1);
free(v1);
goto LABEL_8;
}
v11 = (_DWORD **)v8[1];
if ( !v11 )
break;
if ( v9 < **v11 )
{
v1[1] = v11;
v8[1] = v1;
goto LABEL_8;
}
v8 = (_QWORD *)v8[1];
}
v8[1] = v1;
}
else
{
v1[1] = first;
first = v1;
}
}
else
{
first = v1;
}
LABEL_8:
func8();
}

original_code:
void insert(void)
{
    node *newptr = malloc(sizeof(node));
    if (newptr == ((void *)0))
        return;
    newptr->next = ((void *)0);
    newptr->student = malloc(sizeof(student));
    if (newptr->student == ((void *)0))
    {
        free(newptr);
        return;
    }
    fflush(stdin);
    printf("Student's ID: ");
    newptr->student->id = getInt();
    fflush(stdin);
    printf("Student's name: ");
    newptr->student->name = getString();
    fflush(stdin);
    printf("Student's house: ");
    newptr->student->house = getString();
    if (newptr->student->name == ((void *)0) || newptr->student->house== ((void *)0))
    {
        if (newptr->student->name != ((void *)0))
            free(newptr->student->name);
        if (newptr->student->house != ((void *)0))
            free(newptr->student->house);
        free(newptr->student);
        free(newptr);
        return;
    }
    if (first == ((void *)0))
        first = newptr;
    else if (newptr->student->id < first->student->id)
    {
        newptr->next = first;
        first = newptr;
    }
    else
    {
        node *predptr = first;
        while (1)
        {
            if (predptr->student->id == newptr->student->id)
            {
                free(newptr->student->name);
                free(newptr->student->house);
                free(newptr->student);
                free(newptr);
                break;
            }
            else if (predptr->next == ((void *)0))
            {
                predptr->next = newptr;
                break;
            }
            else if (predptr->next->student->id > newptr->student->id)
            {
                newptr->next = predptr->next;
                predptr->next = newptr;
                break;
            }
            predptr = predptr->next;
        }
    }
    traverse();
}

canonical_original_code:
void insert()
{
    struct node *newptr = malloc(sizeof(node));
    if (newptr == ((void *)0))
        return;
    newptr->next = ((void *)0);
    newptr->student = malloc(sizeof(student));
    if (newptr->student == ((void *)0))
    {
        free(newptr);
        return;
    }
    fflush(stdin);
    printf("Student's ID: ");
    newptr->student->id = getInt();
    fflush(stdin);
    printf("Student's name: ");
    newptr->student->name = getString();
    fflush(stdin);
    printf("Student's house: ");
    newptr->student->house = getString();
    if (newptr->student->name == ((void *)0) || newptr->student->house== ((void *)0))
    {
        if (newptr->student->name != ((void *)0))
            free(newptr->student->name);
        if (newptr->student->house != ((void *)0))
            free(newptr->student->house);
        free(newptr->student);
        free(newptr);
        return;
    }
    if (first == ((void *)0))
        first = newptr;
    else if (newptr->student->id < first->student->id)
    {
        newptr->next = first;
        first = newptr;
    }
    else
    {
        struct node *predptr = first;
        while (1)
        {
            if (predptr->student->id == newptr->student->id)
            {
                free(newptr->student->name);
                free(newptr->student->house);
                free(newptr->student);
                free(newptr);
                break;
            }
            else if (predptr->next == ((void *)0))
            {
                predptr->next = newptr;
                break;
            }
            else if (predptr->next->student->id > newptr->student->id)
            {
                newptr->next = predptr->next;
                predptr->next = newptr;
                break;
            }
            predptr = predptr->next;
        }
    }
    traverse();
}


main

canonical_name: main

repo: gazeddyw/apple-and-blackberry-crumble

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
void *v4; // rdi
int v6; // ebx

while ( 2 )
{
puts("\nMENU\n\n1 - Delete\n2 - Find\n3 - Insert\n4 - Traverse\n0 - Quit\n");
printf("Command: ");
v6 = getInt("Command: ", argv);
switch ( v6 )
{
case 0:
puts("\n\nBYE!\n");
break;
case 1:
delete();
continue;
case 2:
find();
continue;
case 3:
insert();
continue;
case 4:
traverse();
continue;
default:
puts("\nInvalid choice...");
if ( v6 )
continue;
break;
}
break;
}
v3 = first;
while ( v3 )
{
v4 = v3;
v3 = (void *)*((_QWORD *)v3 + 1);
free(v4);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
void *v4; // rdi
int v6; // ebx

while ( 2 )
{
puts("\nMENU\n\n1 - Delete\n2 - Find\n3 - Insert\n4 - Traverse\n0 - Quit\n");
printf("Command: ");
v6 = func12("Command: ", argv);
switch ( v6 )
{
case 0:
puts("\n\nBYE!\n");
break;
case 1:
func9();
continue;
case 2:
func7();
continue;
case 3:
func10();
continue;
case 4:
func8();
continue;
default:
puts("\nInvalid choice...");
if ( v6 )
continue;
break;
}
break;
}
v3 = first;
while ( v3 )
{
v4 = v3;
v3 = (void *)*((_QWORD *)v3 + 1);
free(v4);
}
return 0;
}

original_code:
int main(void)
{
    int c;
    do
    {
        printf("\nMENU\n\n"
               "1 - Delete\n"
               "2 - Find\n"
               "3 - Insert\n"
               "4 - Traverse\n"
               "0 - Quit\n\n");
        printf("Command: ");
        c = getInt();
        switch (c)
        {
            case 0: printf("\n\nBYE!\n\n"); break;
            case 1: delete(); break;
            case 2: find(); break;
            case 3: insert(); break;
            case 4: traverse(); break;
            default: printf("\nInvalid choice...\n");
        }
    }
    while (c != 0);
    node *ptr = first;
    while (ptr != ((void *)0))
    {
        node *predptr = ptr;
        ptr = ptr->next;
        free(predptr);
    }
    return 0;
}

canonical_original_code:
int main()
{
    int c;
    do
    {
        printf("\nMENU\n\n"
               "1 - Delete\n"
               "2 - Find\n"
               "3 - Insert\n"
               "4 - Traverse\n"
               "0 - Quit\n\n");
        printf("Command: ");
        c = getInt();
        switch (c)
        {
            case 0: printf("\n\nBYE!\n\n"); break;
            case 1: delete(); break;
            case 2: find(); break;
            case 3: insert(); break;
            case 4: traverse(); break;
            default: printf("\nInvalid choice...\n");
        }
    }
    while (c != 0);
    struct node *ptr = first;
    while (ptr != ((void *)0))
    {
        struct node *predptr = ptr;
        ptr = ptr->next;
        free(predptr);
    }
    return 0;
}

variable_types: c int

variable_types: struct node { struct student { int id; char *name; char *house; } *student; struct node *next; } *

return_type: int

user_defined_types: struct node { struct student *student; struct node *next; }


getString

decompiled_code:
char *getString()
{
unsigned int v0; // ebp
int v1; // er12
char *i; // r13
char *v3; // r14
char *v4; // rax
int v5; // eax
char v6; // bl

v0 = 0;
v1 = 0;
for ( i = 0LL; ; i[v0++] = v6 )
{
v5 = fgetc(stdin);
v6 = v5;
if ( v5 == -1 || v5 == 10 )
break;
if ( v0 + 1 > v1 )
{
if ( v1 )
{
if ( v1 < 0 )
{
free(i);
return 0LL;
}
v1 *= 2;
}
else
{
v1 = 32;
}
v4 = (char *)realloc(i, (unsigned int)v1);
v3 = v4;
if ( !v4 )
{
free(i);
return v3;
}
i = v4;
}
}
if ( v0 || (v3 = 0LL, v5 != -1) )
{
v3 = (char *)malloc(v0 + 1);
strncpy(v3, i, v0);
free(i);
v3[v0] = 0;
}
return v3;
}

canonical_decompiled_code:
char *func11()
{
unsigned int v0; // ebp
int v1; // er12
char *i; // r13
char *v3; // r14
char *v4; // rax
int v5; // eax
char v6; // bl

v0 = 0;
v1 = 0;
for ( i = 0LL; ; i[v0++] = v6 )
{
v5 = fgetc(stdin);
v6 = v5;
if ( v5 == -1 || v5 == 10 )
break;
if ( v0 + 1 > v1 )
{
if ( v1 )
{
if ( v1 < 0 )
{
free(i);
return 0LL;
}
v1 *= 2;
}
else
{
v1 = 32;
}
v4 = (char *)realloc(i, (unsigned int)v1);
v3 = v4;
if ( !v4 )
{
free(i);
return v3;
}
i = v4;
}
}
if ( v0 || (v3 = 0LL, v5 != -1) )
{
v3 = (char *)malloc(v0 + 1);
strncpy(v3, i, v0);
free(i);
v3[v0] = 0;
}
return v3;
}

original_code:
char* getString(void)
{
    char *buffer = ((void *)0);
    unsigned int capacity = 0;
    unsigned int n = 0;
    int c;
    while ((c = fgetc(stdin)) != '\n' && c != (-1))
    {
        if (n + 1 > capacity)
        {
            if (capacity == 0)
                capacity = 32;
            else if (capacity <= ((0x7fffffff * 2U + 1U) / 2))
                capacity *= 2;
            else
            {
                free(buffer);
                return ((void *)0);
            }
            char *temp = realloc(buffer, capacity * sizeof(char));
            if (temp == ((void *)0))
            {
                free(buffer);
                return ((void *)0);
            }
            buffer = temp;
        }
        buffer[n++] = c;
    }
    if (n == 0 && c == (-1))
        return ((void *)0);
    char *minimal = malloc((n + 1) * sizeof(char));
    strncpy(minimal, buffer, n);
    free(buffer);
    minimal[n] = '\0';
    return minimal;
}

canonical_original_code:
char *getString()
{
    char *buffer = ((void *)0);
    unsigned int capacity = 0;
    unsigned int n = 0;
    int c;
    while ((c = fgetc(stdin)) != '\n' && c != (-1))
    {
        if (n + 1 > capacity)
        {
            if (capacity == 0)
                capacity = 32;
            else if (capacity <= ((0x7fffffff * 2U + 1U) / 2))
                capacity *= 2;
            else
            {
                free(buffer);
                return ((void *)0);
            }
            char *temp = realloc(buffer, capacity * sizeof(char));
            if (temp == ((void *)0))
            {
                free(buffer);
                return ((void *)0);
            }
            buffer = temp;
        }
        buffer[n++] = c;
    }
    if (n == 0 && c == (-1))
        return ((void *)0);
    char *minimal = malloc((n + 1) * sizeof(char));
    strncpy(minimal, buffer, n);
    free(buffer);
    minimal[n] = '\0';
    return minimal;
}

variable_types:
buffer
char *

variable_types:
capacity
unsigned int

variable_types:
n
unsigned int

variable_types:
temp
char *

variable_types:
minimal
char *

return_type: char *


getInt

decompiled_code:
__int64 getInt()
{
char *v0; // rax
char *v1; // rbx
unsigned int v3; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
v0 = getString();
if ( !v0 )
break;
v1 = v0;
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
free(v1);
return v3;
}
free(v1);
printf("Retry: ");
}
return 0x7FFFFFFFLL;
}

canonical_decompiled_code:
__int64 func12()
{
char *v0; // rax
char *v1; // rbx
unsigned int v3; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
v0 = func11();
if ( !v0 )
break;
v1 = v0;
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
free(v1);
return v3;
}
free(v1);
printf("Retry: ");
}
return 0x7FFFFFFFLL;
}

original_code:
int getInt(void)
{
    while (1)
    {
        char *line = getString();
        if (line == ((void *)0))
            return 0x7fffffff;
        int n;
        char c;
        if (sscanf(line, " %d %c", &n, &c) == 1)
        {
            free(line);
            return n;
        }
        else
        {
            free(line);
            printf("Retry: ");
        }
    }
}

canonical_original_code:
int getInt()
{
    while (1)
    {
        char *line = getString();
        if (line == ((void *)0))
            return 0x7fffffff;
        int n;
        char c;
        if (sscanf(line, " %d %c", &n, &c) == 1)
        {
            free(line);
            return n;
        }
        else
        {
            free(line);
            printf("Retry: ");
        }
    }
}

variable_types:
line
char *

variable_types: n int

variable_types: c char


repo: gbildson/nprizeadditions

decompiled_code:
__int64 score_argv()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code: int score_argv(char **argv) {return 0;}

canonical_original_code: int score_argv(char **argv) {return 0;}

variable_types:
argv
char **


removeUV

decompiled_code:
__int64 removeUV()
{
int v0; // er10
int *v1; // rdi
float *v2; // r8
__int64 result; // rax
double v4; // xmm2_8
__int64 v5; // rdx
unsigned __int64 v6; // rsi
float v7; // xmm0_4
int v8; // ecx

v0 = aopt;
v1 = (int *)&useridx;
v2 = (float *)&wbU;
do
{
v8 = *v1;
if ( v0 )
result = (unsigned int)(v1[3] + v1[1] + v1[2]);
else
result = (unsigned int)(v1[1] + v1[2]);
if ( (int)result > 0 )
{
v4 = *v2 + 3.603304;
v5 = 4LL * v8;
v6 = 4 * (v8 + (unsigned __int64)(unsigned int)(result - 1) + 1);
do
{
result = ((*(_DWORD *)((char *)&userent + v5) >> 15) & 7u) + 1;
v7 = (double)(int)result - (wbV[*(_DWORD *)((_BYTE *)&userent + v5) & 0x7FFF] + v4);
*(float *)((char *)&err + v5) = v7;
v5 += 4LL;
}
while ( v5 != v6 );
}
v1 += 4;
++v2;
}
while ( v1 != (int *)(unsigned int)((_DWORD)&useridx + 7683024) );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er10
int *v1; // rdi
float *v2; // r8
__int64 result; // rax
double v4; // xmm2_8
__int64 v5; // rdx
unsigned __int64 v6; // rsi
float v7; // xmm0_4
int v8; // ecx

v0 = aopt;
v1 = (int *)&useridx;
v2 = (float *)&wbU;
do
{
v8 = *v1;
if ( v0 )
result = (unsigned int)(v1[3] + v1[1] + v1[2]);
else
result = (unsigned int)(v1[1] + v1[2]);
if ( (int)result > 0 )
{
v4 = *v2 + 3.603304;
v5 = 4LL * v8;
v6 = 4 * (v8 + (unsigned __int64)(unsigned int)(result - 1) + 1);
do
{
result = ((*(_DWORD *)((char *)&userent + v5) >> 15) & 7u) + 1;
v7 = (double)(int)result - (wbV[*(_DWORD *)((_BYTE *)&userent + v5) & 0x7FFF] + v4);
*(float *)((char *)&err + v5) = v7;
v5 += 4LL;
}
while ( v5 != v6 );
}
v1 += 4;
++v2;
}
while ( v1 != (int *)(unsigned int)((_DWORD)&useridx + 7683024) );
return result;
}

original_code:
void removeUV() {
 int u,f;
 for(u=0;u<(480189);u++) {
  int base0=useridx[u][0];
  int d012=(aopt?(useridx[u][1]+useridx[u][2]+useridx[u][3]):(useridx[u][1]+useridx[u][2]));
  int i;
  int dall=(aopt?(useridx[u][1]+useridx[u][2]+useridx[u][3]):(useridx[u][1]+useridx[u][2]));
  int j,j2;
  for(i=0; i<d012;i++) {
   int m=userent[base0+i]&(0x7fff);
   int r=(userent[base0+i]>>(15))&7;
   r++;
   err[base0+i] = r - ((3.603304) + wbU[u] + wbV[m]);
  }
 }
}

canonical_original_code:
void removeUV() {
 int u; int f;
 for(u=0;u<(480189);u++) {
  int base0 = useridx[u][0];
  int d012 = (aopt?(useridx[u][1]+useridx[u][2]+useridx[u][3]):(useridx[u][1]+useridx[u][2]));
  int i;
  int dall = (aopt?(useridx[u][1]+useridx[u][2]+useridx[u][3]):(useridx[u][1]+useridx[u][2]));
  int j; int j2;
  for(i=0; i<d012;i++) {
   int m = userent[base0+i]&(0x7fff);
   int r = (userent[base0+i]>>(15))&7;
   r++;
   err[base0+i] = r - ((3.603304) + wbU[u] + wbV[m]);
  }
 }
}

variable_types: u int

variable_types: f int

variable_types: i int

variable_types: dall int

variable_types: j int

variable_types: m int

variable_types: r int

return_type: void


decompiled_code:
__int64 weight_time_setup()
{
char *v0; // rdx
__int64 result; // rax

v0 = 0LL;
do
{
result = (unsigned int)((*(_DWORD *)((char *)&userent + (_QWORD)v0) >> 18) + 2922);
*(float *)((char *)wgt + (_QWORD)v0) = (float)(int)result;
v0 += 4;
}
while ( v0 != (char *)&unk_18A0C998 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rdx
__int64 result; // rax

v0 = 0LL;
do
{
result = (unsigned int)((*(_DWORD *)((char *)&userent + (_QWORD)v0) >> 18) + 2922);
*(float *)((char *)wgt + (_QWORD)v0) = (float)(int)result;
v0 += 4;
}
while ( v0 != (char *)&unk_18A0C998 );
return result;
}


decompiled_code:
int *weight_norm()
{
unsigned int *v0; // rcx
int v1; // ebx
__int64 v2; // rsi
float *v3; // rax
int *v4; // rdx
int *result; // rax
float v6; // xmm0_4
double v7; // [rsp+8h] [rbp-10h]

v0 = (unsigned int *)&useridx;
v1 = 0;
v7 = 0.0;
do
{
v4 = (int *)*v0;
if ( aopt )
v2 = v0[1] + v0[2];
else
v2 = v0[1];
if ( (int)v2 > 0 )
{
v3 = (float *)&wgt[(int)v4];
v4 = &wgt[(unsigned int)(v2 - 1) + 1 + (__int64)(int)v4];
do
v7 = *v3++ + v7;
while ( v3 != (float *)v4 );
}
v1 += v2;
v0 += 4;
}
while ( v0 != (unsigned int *)(unsigned int)((_DWORD)&useridx + 7683024) );
lg("sum=%f\n", v2, v4, v7);
result = wgt;
do
{
v6 = *(float *)result * ((double)v1 / v7);
*(float *)result++ = v6;
}
while ( result != (int *)((char *)&unk_18A0C998 + (_QWORD)wgt) );
return result;
}

canonical_decompiled_code:
int *func1()
{
unsigned int *v0; // rcx
int v1; // ebx
__int64 v2; // rsi
float *v3; // rax
int *v4; // rdx
int *result; // rax
float v6; // xmm0_4
double v7; // [rsp+8h] [rbp-10h]

v0 = (unsigned int *)&useridx;
v1 = 0;
v7 = 0.0;
do
{
v4 = (int *)*v0;
if ( aopt )
v2 = v0[1] + v0[2];
else
v2 = v0[1];
if ( (int)v2 > 0 )
{
v3 = (float *)&wgt[(int)v4];
v4 = &wgt[(unsigned int)(v2 - 1) + 1 + (__int64)(int)v4];
do
v7 = *v3++ + v7;
while ( v3 != (float *)v4 );
}
v1 += v2;
v0 += 4;
}
while ( v0 != (unsigned int *)(unsigned int)((_DWORD)&useridx + 7683024) );
lg("sum=%f\n", v2, v4, v7);
result = wgt;
do
{
v6 = *(float *)result * ((double)v1 / v7);
*(float *)result++ = v6;
}
while ( result != (int *)((char *)&unk_18A0C998 + (_QWORD)wgt) );
return result;
}

original_code:
void weight_norm()
{
 double sum=0.;
    int total=0;
    int u,i;
 for(u=0;u<(480189);u++) {
  int base=useridx[u][0];
  int d=(aopt?(useridx[u][1]+useridx[u][2]):(useridx[u][1]));
  int j;
  for(j=0;j<d;j++) {
   sum+=wgt[base+j];
  }
        total+=d;
 }
 lg("sum=%f\n",sum);
    sum=total/sum;
    for(i=0;i<(103297638);i++) wgt[i]*=sum;
}

canonical_original_code:
void weight_norm()
{
 double sum = 0.;
    int total = 0;
    int u; int i;
 for(u=0;u<(480189);u++) {
  int base = useridx[u][0];
  int d = (aopt?(useridx[u][1]+useridx[u][2]):(useridx[u][1]));
  int j;
  for(j=0;j<d;j++) {
   sum+=wgt[base+j];
  }
        total+=d;
 }
 lg("sum=%f\n",sum);
    sum=total/sum;
    for(i=0;i<(103297638);i++) wgt[i]*=sum;
}

variable_types: sum double

variable_types: total int

variable_types: base int

variable_types: d int


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, _DWORD *a3)
{
__int64 v5; // rcx
__int64 v6; // rdi
__int64 v7; // 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 = a1 + 301200;
do
{
v7 = a2 + 1004LL * *a3;
for ( i = 0LL; i != 1004; i += 4LL )
*(_DWORD *)(v7 + i) = *(_DWORD *)(v5 + i);
++*a3;
v5 += 1004LL;
}
while ( v5 != v6 );
return LODWORD(tv.tv_usec);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _DWORD *a3)
{
__int64 v5; // rcx
__int64 v6; // rdi
__int64 v7; // 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 = a1 + 301200;
do
{
v7 = a2 + 1004LL * *a3;
for ( i = 0LL; i != 1004; i += 4LL )
*(_DWORD *)(v7 + i) = *(_DWORD *)(v5 + i);
++*a3;
v5 += 1004LL;
}
while ( v5 != v6 );
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: k 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; }


Decode

decompiled_code:
__int64 __fastcall Decode(int a1, _DWORD *a2, __int64 a3, __int64 a4, int *a5, unsigned int *a6, _DWORD *a7)
{
char *v10; // r14
_DWORD *v11; // rax
_DWORD *v12; // rax
int *v13; // rdi
signed int v14; // er8
__int64 result; // rax
int v16; // eax
_DWORD *v17; // rsi
int *v18; // rcx
int i; // er9
__int64 j; // rax
int v21; // ebp
__int64 v22; // rax
int v23; // edx
int v24; // er8
int v25; // er9
int v26; // edi
char *v27; // rsi
int *v28; // rcx
int k; // er10
__int64 l; // rax
_DWORD *v31; // rsi
int v32; // edi
_DWORD *v33; // rax
_DWORD *v34; // rdx
int *v35; // r11
int v36; // er10
__int64 v37; // rcx
int v38; // er8
__int64 m; // rbp
int v40; // ecx
int v41; // ecx
int v42; // edi
__int64 v43; // rax
__int64 v44; // rdx
unsigned int *v45; // r9
_DWORD *v46; // rsi
unsigned int v47; // er11
__int64 v48; // r13
_DWORD *v49; // rsi
int v50; // edi
_DWORD *v51; // rax
char *v52; // rdx
_DWORD *v53; // r8
int v54; // er10
__int64 v55; // rcx
__int64 v56; // rbx
int v57; // eax
_DWORD *v58; // [rsp+8h] [rbp-E0h]
unsigned int v59; // [rsp+10h] [rbp-D8h]
__int64 v60; // [rsp+10h] [rbp-D8h]
_DWORD *v61; // [rsp+18h] [rbp-D0h]
_DWORD *v62; // [rsp+20h] [rbp-C8h]
int v63; // [rsp+28h] [rbp-C0h]
unsigned int v64; // [rsp+28h] [rbp-C0h]
_DWORD *v67; // [rsp+38h] [rbp-B0h]
_DWORD *v68; // [rsp+40h] [rbp-A8h]
_DWORD *v69; // [rsp+48h] [rbp-A0h]
_DWORD *v70; // [rsp+50h] [rbp-98h]
_DWORD *v71; // [rsp+58h] [rbp-90h]
int v73; // [rsp+68h] [rbp-80h]
int v74; // [rsp+78h] [rbp-70h]
struct timeval v75; // [rsp+90h] [rbp-58h] BYREF
struct timeval tv; // [rsp+A0h] [rbp-48h] BYREF

v58 = calloc(0xC8uLL, 4uLL);
if ( !v58 )
{
puts("\ndecode: Rec_index malloc failed");
exit(434);
}
v62 = calloc(0xC8uLL, 4uLL);
if ( !v62 )
{
puts("\ndecode: Col_Ind malloc failed");
exit(434);
}
v61 = calloc(0xC8uLL, 4uLL);
if ( !v61 )
{
puts("\ndecode: Row_Ind malloc failed");
exit(434);
}
v67 = calloc(0xC8uLL, 4uLL);
if ( !v67 )
{
puts("\ndecode: C malloc failed");
exit(434);
}
v68 = calloc(0xC8uLL, 4uLL);
if ( !v68 )
{
puts("\ndecode: D malloc failed");
exit(434);
}
v69 = calloc(0xC8uLL, 4uLL);
if ( !v69 )
{
puts("\ndecode: E malloc failed");
exit(434);
}
v70 = calloc(0xC8uLL, 4uLL);
if ( !v70 )
{
puts("\ndecode: F malloc failed");
exit(434);
}
v10 = (char *)calloc(0xC350uLL, 4uLL);
if ( !v10 )
{
puts("\ndecode: M malloc failed");
exit(434);
}
v11 = a7;
if ( (int)*a6 <= 199 )
{
printf("*** Need %d packets to recover message", 200LL);
printf(" but only %d packets received *** \n", *a6);
result = 1LL;
}
else
{
do
*v11++ = 0;
while ( v11 != a7 + 50000 );
gettimeofday(&tv, 0LL);
v12 = v58;
do
*v12++ = 0;
while ( v12 != v58 + 200 );
if ( (int)*a6 <= 0 )
{
v59 = 0;
}
else
{
v13 = a5;
v59 = 0;
v14 = 0;
do
{
v16 = *v13;
if ( *v13 <= 199 )
{
v58[v16] = 1;
v17 = &a7[250 * v16];
v18 = v13;
for ( i = 0; i != 250; i += 25 )
{
for ( j = 0LL; j != 25; ++j )
v17[j] = v18[j + 1];
v18 += 25;
v17 += 25;
}
++v59;
}
++v14;
v13 += 251;
}
while ( (int)*a6 > v14 );
}
v21 = 200 - v59;
printf("Nfirstrec= %d, Nextra= %d \n", v59, 200 - v59);
v22 = 0LL;
v23 = 0;
do
{
if ( !v58[v22] )
v62[v23++] = v22;
++v22;
}
while ( v22 != 200 );
if ( (int)*a6 > 0 )
{
v24 = 251 * *a6 + 1;
v25 = 1;
v26 = 0;
do
{
if ( (unsigned int)*a5 > 0xC7 )
{
v61[v26] = *a5 - 200;
v27 = &v10[1000 * v26];
v28 = a5;
for ( k = 0; k != 250; k += 25 )
{
for ( l = 0LL; l != 25; ++l )
*(_DWORD *)&v27[l * 4] = v28[l + 1];
v28 += 25;
v27 += 100;
}
if ( v21 <= ++v26 )
break;
}
a5 += 251;
v25 += 251;
}
while ( v25 != v24 );
}
if ( v21 > 0 )
{
v74 = 10 * v21;
v71 = v61;
v63 = 0;
do
{
for ( m = 0LL; m != 200; ++m )
{
if ( v58[m] == 1 )
{
v40 = (4198405
* (unsigned __int64)(unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ *v71 ^ (unsigned int)m)))) >> 32;
v35 = (int *)(a3
+ 4LL
* (int)(1023
- *(_DWORD *)(a4 + 4LL * (a1 ^ *v71 ^ (unsigned int)m))
- 1023
* ((v40
+ ((unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ *v71 ^ (unsigned int)m)) - v40) >> 1)) >> 9)));
v37 = (__int64)&v10[100 * v63 + 100];
v36 = 25 * v63;
do
{
v38 = *v35;
v31 = a2;
v32 = 250 * m;
do
{
if ( (*v31 & v38) != 0 )
{
v33 = (_DWORD *)(v37 - 100);
v34 = &a7[v32];
do
*v33++ ^= *v34++;
while ( v33 != (_DWORD *)v37 );
}
++v31;
v32 += 25;
}
while ( v31 != a2 + 10 );
++v35;
v36 += 25;
v37 += 100LL;
}
while ( v36 != 25 * v63 + 250 );
}
}
v63 += 10;
++v71;
}
while ( v63 != v74 );
v46 = v67;
v60 = 200 - v59;
v44 = 0LL;
v45 = v61;
do
{
v42 = v69[v44];
v47 = *v45;
v43 = 0LL;
do
{
if ( (_DWORD)v43 != (_DWORD)v44 )
{
*v46 += *(_DWORD *)(a4 + 4LL * (int)(v61[v43] ^ v47));
v68[v43] += *(_DWORD *)(a4 + 4LL * (v62[v43] ^ v62[v44]));
}
v41 = *(_DWORD *)(a4 + 4LL * (a1 ^ v62[v43] ^ v47));
v42 += v41;
v70[v43++] += v41;
}
while ( v43 != v60 );
v69[v44++] = v42;
++v45;
++v46;
}
while ( v44 != v60 );
v48 = 0LL;
do
{
v73 = v70[v48] - v68[v48];
v64 = v62[v48];
v56 = 0LL;
do
{
v57 = v69[v56] + v73 - v67[v56] - *(_DWORD *)(a4 + 4LL * (a1 ^ v61[v56] ^ v64));
if ( v57 < 0 )
v57 = 1023 - (*(_DWORD *)(a4 + 4LL * (a1 ^ v61[v56] ^ v64)) - (v69[v56] + v73 - v67[v56])) % 1023;
v53 = (_DWORD *)(a3 + 4LL * (v57 % 1023));
v54 = 250 * v64;
v55 = (__int64)&a7[250 * v64 + 25];
do
{
v49 = a2;
v50 = 250 * v56;
do
{
if ( (*v49 & *v53) != 0 )
{
v51 = (_DWORD *)(v55 - 100);
v52 = &v10[4 * v50];
do
{
*v51++ ^= *(_DWORD *)v52;
v52 += 4;
}
while ( (_DWORD *)v55 != v51 );
}
++v49;
v50 += 25;
}
while ( a2 + 10 != v49 );
++v53;
v54 += 25;
v55 += 100LL;
}
while ( 250 * v64 + 250 != v54 );
++v56;
}
while ( v56 != v60 );
++v48;
}
while ( v48 != v60 );
}
gettimeofday(&v75, 0LL);
printf("\n------------------------------------------------");
printf(
"\n decode: number of seconds is %f",
(float)(LODWORD(v75.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (float)(LODWORD(v75.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, _DWORD *a7)
{
char *v10; // r14
_DWORD *v11; // rax
_DWORD *v12; // rax
int *v13; // rdi
signed int v14; // er8
__int64 result; // rax
int v16; // eax
_DWORD *v17; // rsi
int *v18; // rcx
int i; // er9
__int64 j; // rax
int v21; // ebp
__int64 v22; // rax
int v23; // edx
int v24; // er8
int v25; // er9
int v26; // edi
char *v27; // rsi
int *v28; // rcx
int k; // er10
__int64 l; // rax
_DWORD *v31; // rsi
int v32; // edi
_DWORD *v33; // rax
_DWORD *v34; // rdx
int *v35; // r11
int v36; // er10
__int64 v37; // rcx
int v38; // er8
__int64 m; // rbp
int v40; // ecx
int v41; // ecx
int v42; // edi
__int64 v43; // rax
__int64 v44; // rdx
unsigned int *v45; // r9
_DWORD *v46; // rsi
unsigned int v47; // er11
__int64 v48; // r13
_DWORD *v49; // rsi
int v50; // edi
_DWORD *v51; // rax
char *v52; // rdx
_DWORD *v53; // r8
int v54; // er10
__int64 v55; // rcx
__int64 v56; // rbx
int v57; // eax
_DWORD *v58; // [rsp+8h] [rbp-E0h]
unsigned int v59; // [rsp+10h] [rbp-D8h]
__int64 v60; // [rsp+10h] [rbp-D8h]
_DWORD *v61; // [rsp+18h] [rbp-D0h]
_DWORD *v62; // [rsp+20h] [rbp-C8h]
int v63; // [rsp+28h] [rbp-C0h]
unsigned int v64; // [rsp+28h] [rbp-C0h]
_DWORD *v67; // [rsp+38h] [rbp-B0h]
_DWORD *v68; // [rsp+40h] [rbp-A8h]
_DWORD *v69; // [rsp+48h] [rbp-A0h]
_DWORD *v70; // [rsp+50h] [rbp-98h]
_DWORD *v71; // [rsp+58h] [rbp-90h]
int v73; // [rsp+68h] [rbp-80h]
int v74; // [rsp+78h] [rbp-70h]
struct timeval v75; // [rsp+90h] [rbp-58h] BYREF
struct timeval tv; // [rsp+A0h] [rbp-48h] BYREF

v58 = calloc(0xC8uLL, 4uLL);
if ( !v58 )
{
puts("\ndecode: Rec_index malloc failed");
exit(434);
}
v62 = calloc(0xC8uLL, 4uLL);
if ( !v62 )
{
puts("\ndecode: Col_Ind malloc failed");
exit(434);
}
v61 = calloc(0xC8uLL, 4uLL);
if ( !v61 )
{
puts("\ndecode: Row_Ind malloc failed");
exit(434);
}
v67 = calloc(0xC8uLL, 4uLL);
if ( !v67 )
{
puts("\ndecode: C malloc failed");
exit(434);
}
v68 = calloc(0xC8uLL, 4uLL);
if ( !v68 )
{
puts("\ndecode: D malloc failed");
exit(434);
}
v69 = calloc(0xC8uLL, 4uLL);
if ( !v69 )
{
puts("\ndecode: E malloc failed");
exit(434);
}
v70 = calloc(0xC8uLL, 4uLL);
if ( !v70 )
{
puts("\ndecode: F malloc failed");
exit(434);
}
v10 = (char *)calloc(0xC350uLL, 4uLL);
if ( !v10 )
{
puts("\ndecode: M malloc failed");
exit(434);
}
v11 = a7;
if ( (int)*a6 <= 199 )
{
printf("*** Need %d packets to recover message", 200LL);
printf(" but only %d packets received *** \n", *a6);
result = 1LL;
}
else
{
do
*v11++ = 0;
while ( v11 != a7 + 50000 );
gettimeofday(&tv, 0LL);
v12 = v58;
do
*v12++ = 0;
while ( v12 != v58 + 200 );
if ( (int)*a6 <= 0 )
{
v59 = 0;
}
else
{
v13 = a5;
v59 = 0;
v14 = 0;
do
{
v16 = *v13;
if ( *v13 <= 199 )
{
v58[v16] = 1;
v17 = &a7[250 * v16];
v18 = v13;
for ( i = 0; i != 250; i += 25 )
{
for ( j = 0LL; j != 25; ++j )
v17[j] = v18[j + 1];
v18 += 25;
v17 += 25;
}
++v59;
}
++v14;
v13 += 251;
}
while ( (int)*a6 > v14 );
}
v21 = 200 - v59;
printf("Nfirstrec= %d, Nextra= %d \n", v59, 200 - v59);
v22 = 0LL;
v23 = 0;
do
{
if ( !v58[v22] )
v62[v23++] = v22;
++v22;
}
while ( v22 != 200 );
if ( (int)*a6 > 0 )
{
v24 = 251 * *a6 + 1;
v25 = 1;
v26 = 0;
do
{
if ( (unsigned int)*a5 > 0xC7 )
{
v61[v26] = *a5 - 200;
v27 = &v10[1000 * v26];
v28 = a5;
for ( k = 0; k != 250; k += 25 )
{
for ( l = 0LL; l != 25; ++l )
*(_DWORD *)&v27[l * 4] = v28[l + 1];
v28 += 25;
v27 += 100;
}
if ( v21 <= ++v26 )
break;
}
a5 += 251;
v25 += 251;
}
while ( v25 != v24 );
}
if ( v21 > 0 )
{
v74 = 10 * v21;
v71 = v61;
v63 = 0;
do
{
for ( m = 0LL; m != 200; ++m )
{
if ( v58[m] == 1 )
{
v40 = (4198405
* (unsigned __int64)(unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ *v71 ^ (unsigned int)m)))) >> 32;
v35 = (int *)(a3
+ 4LL
* (int)(1023
- *(_DWORD *)(a4 + 4LL * (a1 ^ *v71 ^ (unsigned int)m))
- 1023
* ((v40
+ ((unsigned int)(1023 - *(_DWORD *)(a4 + 4LL * (a1 ^ *v71 ^ (unsigned int)m)) - v40) >> 1)) >> 9)));
v37 = (__int64)&v10[100 * v63 + 100];
v36 = 25 * v63;
do
{
v38 = *v35;
v31 = a2;
v32 = 250 * m;
do
{
if ( (*v31 & v38) != 0 )
{
v33 = (_DWORD *)(v37 - 100);
v34 = &a7[v32];
do
*v33++ ^= *v34++;
while ( v33 != (_DWORD *)v37 );
}
++v31;
v32 += 25;
}
while ( v31 != a2 + 10 );
++v35;
v36 += 25;
v37 += 100LL;
}
while ( v36 != 25 * v63 + 250 );
}
}
v63 += 10;
++v71;
}
while ( v63 != v74 );
v46 = v67;
v60 = 200 - v59;
v44 = 0LL;
v45 = v61;
do
{
v42 = v69[v44];
v47 = *v45;
v43 = 0LL;
do
{
if ( (_DWORD)v43 != (_DWORD)v44 )
{
*v46 += *(_DWORD *)(a4 + 4LL * (int)(v61[v43] ^ v47));
v68[v43] += *(_DWORD *)(a4 + 4LL * (v62[v43] ^ v62[v44]));
}
v41 = *(_DWORD *)(a4 + 4LL * (a1 ^ v62[v43] ^ v47));
v42 += v41;
v70[v43++] += v41;
}
while ( v43 != v60 );
v69[v44++] = v42;
++v45;
++v46;
}
while ( v44 != v60 );
v48 = 0LL;
do
{
v73 = v70[v48] - v68[v48];
v64 = v62[v48];
v56 = 0LL;
do
{
v57 = v69[v56] + v73 - v67[v56] - *(_DWORD *)(a4 + 4LL * (a1 ^ v61[v56] ^ v64));
if ( v57 < 0 )
v57 = 1023 - (*(_DWORD *)(a4 + 4LL * (a1 ^ v61[v56] ^ v64)) - (v69[v56] + v73 - v67[v56])) % 1023;
v53 = (_DWORD *)(a3 + 4LL * (v57 % 1023));
v54 = 250 * v64;
v55 = (__int64)&a7[250 * v64 + 25];
do
{
v49 = a2;
v50 = 250 * v56;
do
{
if ( (*v49 & *v53) != 0 )
{
v51 = (_DWORD *)(v55 - 100);
v52 = &v10[4 * v50];
do
{
*v51++ ^= *(_DWORD *)v52;
v52 += 4;
}
while ( (_DWORD *)v55 != v51 );
}
++v49;
v50 += 25;
}
while ( a2 + 10 != v49 );
++v53;
v54 += 25;
v55 += 100LL;
}
while ( 250 * v64 + 250 != v54 );
++v56;
}
while ( v56 != v60 );
++v48;
}
while ( v48 != v60 );
}
gettimeofday(&v75, 0LL);
printf("\n------------------------------------------------");
printf(
"\n decode: number of seconds is %f",
(float)(LODWORD(v75.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (float)(LODWORD(v75.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: i int

variable_types: j int

variable_types: l int

variable_types: m 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 *


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: k int

variable_types: row int

variable_types: col int

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


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: i int

variable_types: j int

variable_types: l int

variable_types: m 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);
}


decompiled_code:
__off64_t __fastcall dd_device_size(int fd)
{
__off64_t v1; // rbx

v1 = lseek64(fd, 0LL, 2);
if ( v1 != -1 && lseek64(fd, 0LL, 0) == -1 )
v1 = -1LL;
return v1;
}

canonical_decompiled_code:
__off64_t __fastcall func2(int fd)
{
__off64_t v1; // rbx

v1 = lseek64(fd, 0LL, 2);
if ( v1 != -1 && lseek64(fd, 0LL, 0) == -1 )
v1 = -1LL;
return v1;
}

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:
__off64_t __fastcall dd_file_size(const char *a1)
{
int v1; // edi
__off64_t result; // rax

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

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

v1 = open(a1, 0x8000);
result = -1LL;
if ( v1 != -1 )
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; // er12
char *v3; // rax
char *v4; // rbp
unsigned int v5; // eax
unsigned int v6; // er14
unsigned int v7; // eax
size_t v8; // r13
void *v9; // rsi
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);
v6 = -1;
}
else
{
dd_log(0LL, "opened map: %s", (const char *)a1);
dd_log(0LL, "header size: %d", 20LL);
v3 = (char *)malloc(0x14uLL);
v4 = v3;
if ( v3 )
{
v5 = read(v2, v3, 0x14uLL);
v6 = v5;
if ( v5 == -1 )
{
dd_log(10LL, "unable to read header from map");
}
else if ( v5 == 20 )
{
*(_DWORD *)(a1 + 1024) = *((_DWORD *)v4 + 3);
v7 = *((_DWORD *)v4 + 4);
*(_DWORD *)(a1 + 1028) = v7;
*(_QWORD *)(a1 + 1032) = 4LL * v7;
if ( a2 )
{
printf("ddmap.device: %s\n", (const char *)a1);
printf("ddmap.info: %s\n", v4);
printf("ddmap.version: %d\n", (unsigned __int8)v4[8]);
printf("ddmap.suspended: %d\n", (unsigned __int8)v4[9]);
printf("ddmap.name_sum: 0x%08x\n", *((unsigned int *)v4 + 3));
printf("ddmap.map_size: %u (u32)\n", *((unsigned int *)v4 + 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(v2, v9, v8);
v6 = v10;
if ( (_DWORD)v10 == -1 )
{
dd_log(10LL, "unable to read map", v11, v10);
}
else
{
v12 = *(_QWORD *)(a1 + 1032);
v6 = 0;
if ( (int)v10 != v12 )
{
dd_log(10LL, "unable to read %d map bytes, got %d bytes (map data is broken!)", v12, v10);
v6 = -1;
}
}
}
else
{
dd_log(10LL, "unable to allocate memory for map");
v6 = -1;
}
}
else
{
dd_log(10LL, "unable to read %d header bytes, got %d bytes", 20LL, v5);
v6 = -1;
}
free(v4);
}
else
{
dd_log(10LL, "unable to allocate memory for ddmap_header");
v6 = -1;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // er12
char *v3; // rax
char *v4; // rbp
unsigned int v5; // eax
unsigned int v6; // er14
unsigned int v7; // eax
size_t v8; // r13
void *v9; // rsi
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);
v6 = -1;
}
else
{
dd_log(0LL, "opened map: %s", (const char *)a1);
dd_log(0LL, "header size: %d", 20LL);
v3 = (char *)malloc(0x14uLL);
v4 = v3;
if ( v3 )
{
v5 = read(v2, v3, 0x14uLL);
v6 = v5;
if ( v5 == -1 )
{
dd_log(10LL, "unable to read header from map");
}
else if ( v5 == 20 )
{
*(_DWORD *)(a1 + 1024) = *((_DWORD *)v4 + 3);
v7 = *((_DWORD *)v4 + 4);
*(_DWORD *)(a1 + 1028) = v7;
*(_QWORD *)(a1 + 1032) = 4LL * v7;
if ( a2 )
{
printf("ddmap.device: %s\n", (const char *)a1);
printf("ddmap.info: %s\n", v4);
printf("ddmap.version: %d\n", (unsigned __int8)v4[8]);
printf("ddmap.suspended: %d\n", (unsigned __int8)v4[9]);
printf("ddmap.name_sum: 0x%08x\n", *((unsigned int *)v4 + 3));
printf("ddmap.map_size: %u (u32)\n", *((unsigned int *)v4 + 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(v2, v9, v8);
v6 = v10;
if ( (_DWORD)v10 == -1 )
{
dd_log(10LL, "unable to read map", v11, v10);
}
else
{
v12 = *(_QWORD *)(a1 + 1032);
v6 = 0;
if ( (int)v10 != v12 )
{
dd_log(10LL, "unable to read %d map bytes, got %d bytes (map data is broken!)", v12, v10);
v6 = -1;
}
}
}
else
{
dd_log(10LL, "unable to allocate memory for map");
v6 = -1;
}
}
else
{
dd_log(10LL, "unable to read %d header bytes, got %d bytes", 20LL, v5);
v6 = -1;
}
free(v4);
}
else
{
dd_log(10LL, "unable to allocate memory for ddmap_header");
v6 = -1;
}
}
return v6;
}

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
size_t v2; // rsi
void *v3; // rdx
unsigned __int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // r13
unsigned __int64 v7; // rbx
__int64 result; // rax
__int64 v9; // r9
__int64 v10; // r8
float v11; // xmm0_4

*(_DWORD *)parms = a1;
v1 = dd_dev_open_rw((unsigned int)((_DWORD)parms + 2136), 0LL);
*(_DWORD *)&parms[3176] = v1;
if ( v1 == -1 )
{
dd_log(10LL, "unable to open file: %s", (const char *)(unsigned int)((_DWORD)parms + 2136));
exit(1);
}
dd_log(1LL, "opened file: %s", (const char *)(unsigned int)((_DWORD)parms + 2136));
v2 = dd_device_size(*(unsigned int *)&parms[3176]);
*(_QWORD *)&parms[3168] = v2;
if ( v2 == -1LL )
{
dd_log(10LL, "unable to determine checksum file %s size", (const char *)(unsigned int)((_DWORD)parms + 2136));
result = 0xFFFFFFFFLL;
}
else
{
v3 = mmap64(0LL, v2, 3, 1, *(_DWORD *)&parms[3176], 0LL);
*(_QWORD *)&parms[3184] = v3;
if ( v3 == (void *)-1LL )
{
dd_log(10LL, "unable to mmap from the checksum file");
result = 0xFFFFFFFFLL;
}
else
{
dd_log(1LL, "checksum array ptr: %p", v3);
v4 = *(_QWORD *)&parms[3168] >> 3;
v5 = *(_QWORD *)&parms[3184];
if ( *(_QWORD *)&parms[3168] <= 7uLL )
{
v6 = 0LL;
}
else
{
v6 = 0LL;
v7 = 0LL;
do
{
v10 = *(unsigned int *)(v5 + 8 * v7);
if ( *(_QWORD *)(v5 + 8 * v7) == 0xAB54D28668B3DB1FLL )
++v6;
v9 = *(unsigned int *)(v5 + 8 * v7++ + 4);
fprintf(stdout, "block %llu/%llu %08x %08x\n", v7, v4, v10, v9);
}
while ( v7 < v4 );
}
if ( v6 < 0 )
v11 = (float)(v6 & 1 | (unsigned int)((unsigned __int64)v6 >> 1))
+ (float)(v6 & 1 | (unsigned int)((unsigned __int64)v6 >> 1));
else
v11 = (float)(int)v6;
fprintf(stdout, "blank %llu/%llu %.2f%%\n", v6, v4, (float)((float)(v11 * 100.0) / (float)(int)v4));
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
size_t v2; // rsi
void *v3; // rdx
unsigned __int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // r13
unsigned __int64 v7; // rbx
__int64 result; // rax
__int64 v9; // r9
__int64 v10; // r8
float v11; // xmm0_4

*(_DWORD *)parms = a1;
v1 = dd_dev_open_rw((unsigned int)((_DWORD)parms + 2136), 0LL);
*(_DWORD *)&parms[3176] = v1;
if ( v1 == -1 )
{
dd_log(10LL, "unable to open file: %s", (const char *)(unsigned int)((_DWORD)parms + 2136));
exit(1);
}
dd_log(1LL, "opened file: %s", (const char *)(unsigned int)((_DWORD)parms + 2136));
v2 = dd_device_size(*(unsigned int *)&parms[3176]);
*(_QWORD *)&parms[3168] = v2;
if ( v2 == -1LL )
{
dd_log(10LL, "unable to determine checksum file %s size", (const char *)(unsigned int)((_DWORD)parms + 2136));
result = 0xFFFFFFFFLL;
}
else
{
v3 = mmap64(0LL, v2, 3, 1, *(_DWORD *)&parms[3176], 0LL);
*(_QWORD *)&parms[3184] = v3;
if ( v3 == (void *)-1LL )
{
dd_log(10LL, "unable to mmap from the checksum file");
result = 0xFFFFFFFFLL;
}
else
{
dd_log(1LL, "checksum array ptr: %p", v3);
v4 = *(_QWORD *)&parms[3168] >> 3;
v5 = *(_QWORD *)&parms[3184];
if ( *(_QWORD *)&parms[3168] <= 7uLL )
{
v6 = 0LL;
}
else
{
v6 = 0LL;
v7 = 0LL;
do
{
v10 = *(unsigned int *)(v5 + 8 * v7);
if ( *(_QWORD *)(v5 + 8 * v7) == 0xAB54D28668B3DB1FLL )
++v6;
v9 = *(unsigned int *)(v5 + 8 * v7++ + 4);
fprintf(stdout, "block %llu/%llu %08x %08x\n", v7, v4, v10, v9);
}
while ( v7 < v4 );
}
if ( v6 < 0 )
v11 = (float)(v6 & 1 | (unsigned int)((unsigned __int64)v6 >> 1))
+ (float)(v6 & 1 | (unsigned int)((unsigned __int64)v6 >> 1));
else
v11 = (float)(int)v6;
fprintf(stdout, "blank %llu/%llu %.2f%%\n", v6, v4, (float)((float)(v11 * 100.0) / (float)(int)v4));
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)
{
const char *v3; // r12
int v5; // ebp
__int64 i; // rbx
__int64 result; // rax
unsigned int v8; // [rsp+14h] [rbp-64h] BYREF
unsigned int v9; // [rsp+18h] [rbp-60h] BYREF
char v10[4]; // [rsp+1Ch] [rbp-5Ch] BYREF
char *s[2]; // [rsp+20h] [rbp-58h] BYREF
void *v12; // [rsp+30h] [rbp-48h]
unsigned int v13[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
const char *v3; // r12
int v5; // ebp
__int64 i; // rbx
__int64 result; // rax
unsigned int v8; // [rsp+14h] [rbp-64h] BYREF
unsigned int v9; // [rsp+18h] [rbp-60h] BYREF
char v10[4]; // [rsp+1Ch] [rbp-5Ch] BYREF
char *s[2]; // [rsp+20h] [rbp-58h] BYREF
void *v12; // [rsp+30h] [rbp-48h]
unsigned int v13[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v5 = 1;
for ( i = 0LL; ; ++i )
{
s[i] = (char *)malloc(0x32uLL);
grid_get_data_from_id(&v8, &v9, v10, (unsigned int)i);
if ( !(_DWORD)i )
{
v3 = "Small";
LABEL_3:
sprintf(s[i], "%s\t (%02dx%02d)", v3, v8, v9);
goto LABEL_4;
}
if ( (_DWORD)i == 1 )
{
v3 = "Medium";
goto LABEL_3;
}
if ( (_DWORD)i == 2 )
break;
sprintf(s[i], "%s\t (%02dx%02d)", v3, v8, v9);
if ( v5 > 2 )
goto LABEL_9;
LABEL_4:
++v5;
}
sprintf((char *)v12, "%s\t (%02dx%02d)", "Large", v8, v9);
LABEL_9:
result = interface_screen_choices(v13, s, 3LL, "Choose the size");
if ( (_DWORD)result != 1 )
{
free(s[0]);
free(s[1]);
free(v12);
result = v13[0];
if ( v13[0] != -1 )
result = (unsigned int)grid_get_data_from_id(a1, a2, a3, v13[0]) == 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 i; // er13
unsigned int v7; // ebx
int v9; // [rsp+Ch] [rbp-1CCh] BYREF
__int64 v10; // [rsp+10h] [rbp-1C8h] BYREF
unsigned int v11; // [rsp+1Ch] [rbp-1BCh] BYREF
char v12[332]; // [rsp+20h] [rbp-1B8h] BYREF
unsigned int v13; // [rsp+16Ch] [rbp-6Ch] BYREF
__int64 v14; // [rsp+170h] [rbp-68h] BYREF
__int64 v15; // [rsp+178h] [rbp-60h] BYREF
unsigned int v16; // [rsp+18Ch] [rbp-4Ch] BYREF
__int64 v17; // [rsp+190h] [rbp-48h] BYREF
unsigned int v18; // [rsp+198h] [rbp-40h] BYREF
unsigned int v19[15]; // [rsp+19Ch] [rbp-3Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
int i; // er13
unsigned int v7; // ebx
int v9; // [rsp+Ch] [rbp-1CCh] BYREF
__int64 v10; // [rsp+10h] [rbp-1C8h] BYREF
unsigned int v11; // [rsp+1Ch] [rbp-1BCh] BYREF
char v12[332]; // [rsp+20h] [rbp-1B8h] BYREF
unsigned int v13; // [rsp+16Ch] [rbp-6Ch] BYREF
__int64 v14; // [rsp+170h] [rbp-68h] BYREF
__int64 v15; // [rsp+178h] [rbp-60h] BYREF
unsigned int v16; // [rsp+18Ch] [rbp-4Ch] BYREF
__int64 v17; // [rsp+190h] [rbp-48h] BYREF
unsigned int v18; // [rsp+198h] [rbp-40h] BYREF
unsigned int v19[15]; // [rsp+19Ch] [rbp-3Ch] BYREF

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

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()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-3Ch] BYREF
char v2[4]; // [rsp+10h] [rbp-38h] BYREF
int v3; // [rsp+14h] [rbp-34h] BYREF
int v4; // [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";
result = interface_screen_choices(&v5, v6, 3LL, "Choose the size");
if ( (_DWORD)result != 1 )
{
result = grid_get_data_from_id(&v4, &v3, v2, v5);
if ( (_DWORD)result != 1 )
{
highscore_get_id(&v1);
print_highscores(v1);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-3Ch] BYREF
char v2[4]; // [rsp+10h] [rbp-38h] BYREF
int v3; // [rsp+14h] [rbp-34h] BYREF
int v4; // [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";
result = interface_screen_choices(&v5, v6, 3LL, "Choose the size");
if ( (_DWORD)result != 1 )
{
result = grid_get_data_from_id(&v4, &v3, v2, v5);
if ( (_DWORD)result != 1 )
{
highscore_get_id(&v1);
func2(v1);
result = 0LL;
}
}
return result;
}

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

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

highscore_init(argc, argv, envp);
result = interface_init();
if ( result != 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
interface_reset_screen();
v6[0] = (__int64)"New Game";
v6[1] = (__int64)"Help";
v6[2] = (__int64)"Highscores";
v6[3] = (__int64)"Exit";
interface_screen_choices(v7, v6, 4LL, "MineSweeper");
if ( v7[0] )
break;
if ( (unsigned int)choose_dimension_bombs((__int64)&v4, (__int64)&v5, (__int64)v6) != -1 )
new_game(v7, v4, v5, v6[0]);
}
if ( v7[0] != 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 ( v7[0] != 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
unsigned int v4; // [rsp+8h] [rbp-40h] BYREF
unsigned int v5; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v6[5]; // [rsp+10h] [rbp-38h] BYREF
int v7[3]; // [rsp+3Ch] [rbp-Ch] BYREF

highscore_init(argc, argv, envp);
result = interface_init();
if ( result != 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
interface_reset_screen();
v6[0] = (__int64)"New Game";
v6[1] = (__int64)"Help";
v6[2] = (__int64)"Highscores";
v6[3] = (__int64)"Exit";
interface_screen_choices(v7, v6, 4LL, "MineSweeper");
if ( v7[0] )
break;
if ( (unsigned int)func0((__int64)&v4, (__int64)&v5, (__int64)v6) != -1 )
func1(v7, v4, v5, v6[0]);
}
if ( v7[0] != 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 ( v7[0] != 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);
}