WriteFontName

decompiled_code:
__int64 __fastcall WriteFontName(const char **a1)
{
__int64 v1; // rbx
const char *v2; // r12
char v3; // dl
char *v4; // rax
char v5; // cl
char *v6; // rdx
int v7; // ecx
__int64 result; // rax
char v9[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = 0LL;
v2 = *a1 + 1;
*a1 = v2;
v3 = *v2;
v4 = (char *)v2;
if ( *v2 == 42 )
return fprintRTF(&unk_17D);
do
{
if ( !v3 || (int)v1 > 99 )
{
diagnostics(0LL, "No terminating '*' in font name\nFound in cfg file command <%s>", v2);
v4 = (char *)*a1;
}
v5 = *v4;
v6 = v4++;
*a1 = v4;
v9[v1] = v5;
v3 = v6[1];
v7 = ++v1;
}
while ( v3 != 42 );
v9[v7] = 0;
if ( (int)RtfFontNumber(v9) < 0 )
result = diagnostics(0LL, "Unknown font <%s>\nFound in cfg file command <%s>", v9, v2);
else
result = fprintRTF(&unk_17F);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
__int64 v1; // rbx
const char *v2; // r12
char v3; // dl
char *v4; // rax
char v5; // cl
char *v6; // rdx
int v7; // ecx
__int64 result; // rax
char v9[136]; // [rsp+0h] [rbp-88h] BYREF

v1 = 0LL;
v2 = *a1 + 1;
*a1 = v2;
v3 = *v2;
v4 = (char *)v2;
if ( *v2 == 42 )
return fprintRTF(&unk_17D);
do
{
if ( !v3 || (int)v1 > 99 )
{
diagnostics(0LL, "No terminating '*' in font name\nFound in cfg file command <%s>", v2);
v4 = (char *)*a1;
}
v5 = *v4;
v6 = v4++;
*a1 = v4;
v9[v1] = v5;
v3 = v6[1];
v7 = ++v1;
}
while ( v3 != 42 );
v9[v7] = 0;
if ( (int)RtfFontNumber(v9) < 0 )
result = diagnostics(0LL, "Unknown font <%s>\nFound in cfg file command <%s>", v9, v2);
else
result = fprintRTF(&unk_17F);
return result;
}

original_code:
void WriteFontName(const char **buffpoint)
{
 char fontname[100 + 1];
 int i;
 int fnumber;
 const char *buff;
 (*buffpoint)++;
 buff = *buffpoint;
 if (**buffpoint == '*') {
  fprintRTF("*");
  return;
 }
 i = 0;
 while (**buffpoint != '*') {
  if ((i >= 100) || (**buffpoint == '\0'))
   diagnostics(0, "No terminating '*' in font name\nFound in cfg file command <%s>",buff);
  fontname[i] = **buffpoint;
  i++;
  (*buffpoint)++;
 }
 fontname[i] = '\0';
 fnumber = RtfFontNumber(fontname);
 if (fnumber< 0)
  diagnostics(0,"Unknown font <%s>\nFound in cfg file command <%s>",fontname,buff);
 else
  fprintRTF("%u", (unsigned int) fnumber);
}

canonical_original_code:
void WriteFontName(char **buffpoint)
{
 char fontname[-1];
 int i;
 int fnumber;
 char *buff;
 (*buffpoint)++;
 buff = *buffpoint;
 if (**buffpoint == '*') {
  fprintRTF("*");
  return;
 }
 i = 0;
 while (**buffpoint != '*') {
  if ((i >= 100) || (**buffpoint == '\0'))
   diagnostics(0, "No terminating '*' in font name\nFound in cfg file command <%s>",buff);
  fontname[i] = **buffpoint;
  i++;
  (*buffpoint)++;
 }
 fontname[i] = '\0';
 fnumber = RtfFontNumber(fontname);
 if (fnumber< 0)
  diagnostics(0,"Unknown font <%s>\nFound in cfg file command <%s>",fontname,buff);
 else
  fprintRTF("%u", (unsigned int) fnumber);
}

variable_types:
buffpoint
char **

variable_types:
fontname
char [-1]

variable_types: fnumber int

variable_types:
buff
char *


TryDirectConvert

decompiled_code:
__int64 __fastcall TryDirectConvert(__int64 a1)
{
char *v1; // rbp
const char *v2; // rcx
__int64 result; // rax
__int64 i; // rsi
const char *v5; // [rsp+8h] [rbp-10h] BYREF

v1 = (char *)strdup_together(&unk_182, a1);
v2 = (const char *)SearchRtfCmd(v1, 0LL);
result = 0LL;
if ( v2 )
{
v5 = v2;
diagnostics(4LL, "Directly converting %s to %s", v1, v2);
for ( i = (unsigned int)*v5; *v5; i = (unsigned int)*v5 )
{
if ( (_BYTE)i == 42 )
WriteFontName(&v5);
else
fprintRTF("%c", i);
++v5;
}
free(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v1; // rbp
const char *v2; // rcx
__int64 result; // rax
__int64 i; // rsi
const char *v5; // [rsp+8h] [rbp-10h] BYREF

v1 = (char *)strdup_together(&unk_182, a1);
v2 = (const char *)SearchRtfCmd(v1, 0LL);
result = 0LL;
if ( v2 )
{
v5 = v2;
diagnostics(4LL, "Directly converting %s to %s", v1, v2);
for ( i = (unsigned int)*v5; *v5; i = (unsigned int)*v5 )
{
if ( (_BYTE)i == 42 )
func0(&v5);
else
fprintRTF("%c", i);
++v5;
}
free(v1);
result = 1LL;
}
return result;
}

original_code:
bool
TryDirectConvert(char *command)
{
 const char *buffpoint;
 const char *RtfCommand;
 char *TexCommand;
 TexCommand = strdup_together("\\",command);
 RtfCommand = SearchRtfCmd(TexCommand, 0);
 if (RtfCommand == ((void *)0))
  return 0;
 buffpoint = RtfCommand;
 diagnostics(4, "Directly converting %s to %s", TexCommand, RtfCommand);
 while (buffpoint[0] != '\0') {
  if (buffpoint[0] == '*')
   WriteFontName(&buffpoint);
  else
   fprintRTF("%c", *buffpoint);
  ++buffpoint;
 }
 free(TexCommand);
 return 1;
}

canonical_original_code:
int TryDirectConvert(char *command)
{
 char *buffpoint;
 char *RtfCommand;
 char *TexCommand;
 TexCommand = strdup_together("\\",command);
 RtfCommand = SearchRtfCmd(TexCommand, 0);
 if (RtfCommand == ((void *)0))
  return 0;
 buffpoint = RtfCommand;
 diagnostics(4, "Directly converting %s to %s", TexCommand, RtfCommand);
 while (buffpoint[0] != '\0') {
  if (buffpoint[0] == '*')
   WriteFontName(&buffpoint);
  else
   fprintRTF("%c", *buffpoint);
  ++buffpoint;
 }
 free(TexCommand);
 return 1;
}

variable_types:
command
char *

variable_types:
buffpoint
char *

variable_types:
RtfCommand
char *

variable_types:
TexCommand
char *

return_type: int


main

canonical_name: main

repo: raas/mbw

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
unsigned __int64 v4; // rbp
int v5; // eax
unsigned __int64 v6; // rax
const char *v7; // rdi
unsigned __int64 v8; // rax
double v9; // xmm0_8
unsigned __int64 v10; // r13
void *v11; // r15
void *v12; // r14
unsigned __int64 v13; // rbx
int result; // eax
int v15; // ebp
__int64 v16; // rsi
int v17; // [rsp+4h] [rbp-74h]
double v18; // [rsp+8h] [rbp-70h]
__int64 v19; // [rsp+10h] [rbp-68h]
double v20; // [rsp+18h] [rbp-60h]
double v21; // [rsp+20h] [rbp-58h]
int v22; // [rsp+2Ch] [rbp-4Ch]
__int64 v23; // [rsp+34h] [rbp-44h]
int v24; // [rsp+3Ch] [rbp-3Ch]

v3 = 0;
v4 = 0x40000LL;
v23 = 0LL;
v24 = 0;
v22 = 1;
v17 = 10;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "haqn:t:b:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v22 = 0;
break;
case 'b':
v4 = strtoull(optarg, 0LL, 10);
if ( !v4 )
{
puts("Error: what block size do you mean?");
exit(1);
}
return result;
case 'h':
usage();
exit(1);
case 'n':
v17 = strtoul(optarg, 0LL, 10);
break;
case 'q':
v3 = 1;
break;
case 't':
v6 = strtoul(optarg, 0LL, 10);
if ( v6 > 2 )
{
printf("Error: test number must be between 0 and %d\n", 2LL);
exit(1);
}
*((_DWORD *)&v23 + v6) = 1;
break;
default:
continue;
}
}
if ( !(v24 + (_DWORD)v23 + HIDWORD(v23)) )
{
v24 = 1;
v23 = 0x100000001LL;
if ( v17 )
goto LABEL_14;
LABEL_28:
puts("Error: nr_loops can be zero if only one test selected!");
exit(1);
}
if ( !v17 && v24 + (_DWORD)v23 + HIDWORD(v23) != 1 )
goto LABEL_28;
LABEL_14:
if ( _bss_start >= argc )
{
puts("Error: no array size given!");
exit(1);
}
v7 = argv[_bss_start++];
v8 = strtoul(v7, 0LL, 10);
if ( (v8 & 0x8000000000000000LL) != 0LL )
v21 = (double)(int)(v8 & 1 | (v8 >> 1)) + (double)(int)(v8 & 1 | (v8 >> 1));
else
v21 = (double)(int)v8;
if ( v21 <= 0.0 )
{
puts("Error: array size wrong!");
exit(1);
}
v9 = v21 * 131072.0;
if ( v21 * 131072.0 >= 9.223372036854776e18 )
v10 = (unsigned int)(int)(v9 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v10 = (unsigned int)(int)v9;
if ( 8 * v10 < v4 )
{
printf("Error: array size larger than block size (%llu bytes)!\n", v4);
exit(1);
}
if ( v3 )
{
v11 = (void *)make_array(v10);
v12 = (void *)make_array(v10);
}
else
{
printf("Long uses %d bytes. ", 8LL);
printf("Allocating 2*%lld elements = %lld bytes of memory.\n", v10, 16 * v10);
if ( v24 )
printf("Using %lld bytes as blocks for memcpy block copy test.\n", v4);
v11 = (void *)make_array(v10);
v12 = (void *)make_array(v10);
printf("Getting down to business... Doing %d runs per test.\n", (unsigned int)v17);
}
v19 = 0LL;
v13 = v4;
do
{
if ( *((_DWORD *)&v23 + v19) )
{
if ( v17 < 0 )
{
v18 = 0.0;
}
else
{
v18 = 0.0;
v15 = 0;
do
{
do
{
v16 = (unsigned int)v15;
v20 = worker(v10, v11, v12, (unsigned int)v19, v13);
++v15;
v18 = v18 + v20;
printf("%d\t", v16);
printout((unsigned int)v19, v20, v21);
}
while ( v17 > v15 );
}
while ( !v17 );
}
if ( v22 )
{
printf("AVG\t");
printout((unsigned int)v19, v18 / (double)v17, v21);
}
}
++v19;
}
while ( v19 != 3 );
free(v11);
free(v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
unsigned __int64 v4; // rbp
int v5; // eax
unsigned __int64 v6; // rax
const char *v7; // rdi
unsigned __int64 v8; // rax
double v9; // xmm0_8
unsigned __int64 v10; // r13
void *v11; // r15
void *v12; // r14
unsigned __int64 v13; // rbx
int result; // eax
int v15; // ebp
__int64 v16; // rsi
int v17; // [rsp+4h] [rbp-74h]
double v18; // [rsp+8h] [rbp-70h]
__int64 v19; // [rsp+10h] [rbp-68h]
double v20; // [rsp+18h] [rbp-60h]
double v21; // [rsp+20h] [rbp-58h]
int v22; // [rsp+2Ch] [rbp-4Ch]
__int64 v23; // [rsp+34h] [rbp-44h]
int v24; // [rsp+3Ch] [rbp-3Ch]

v3 = 0;
v4 = 0x40000LL;
v23 = 0LL;
v24 = 0;
v22 = 1;
v17 = 10;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "haqn:t:b:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v22 = 0;
break;
case 'b':
v4 = strtoull(optarg, 0LL, 10);
if ( !v4 )
{
puts("Error: what block size do you mean?");
exit(1);
}
return result;
case 'h':
func7();
exit(1);
case 'n':
v17 = strtoul(optarg, 0LL, 10);
break;
case 'q':
v3 = 1;
break;
case 't':
v6 = strtoul(optarg, 0LL, 10);
if ( v6 > 2 )
{
printf("Error: test number must be between 0 and %d\n", 2LL);
exit(1);
}
*((_DWORD *)&v23 + v6) = 1;
break;
default:
continue;
}
}
if ( !(v24 + (_DWORD)v23 + HIDWORD(v23)) )
{
v24 = 1;
v23 = 0x100000001LL;
if ( v17 )
goto LABEL_14;
LABEL_28:
puts("Error: nr_loops can be zero if only one test selected!");
exit(1);
}
if ( !v17 && v24 + (_DWORD)v23 + HIDWORD(v23) != 1 )
goto LABEL_28;
LABEL_14:
if ( _bss_start >= argc )
{
puts("Error: no array size given!");
exit(1);
}
v7 = argv[_bss_start++];
v8 = strtoul(v7, 0LL, 10);
if ( (v8 & 0x8000000000000000LL) != 0LL )
v21 = (double)(int)(v8 & 1 | (v8 >> 1)) + (double)(int)(v8 & 1 | (v8 >> 1));
else
v21 = (double)(int)v8;
if ( v21 <= 0.0 )
{
puts("Error: array size wrong!");
exit(1);
}
v9 = v21 * 131072.0;
if ( v21 * 131072.0 >= 9.223372036854776e18 )
v10 = (unsigned int)(int)(v9 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v10 = (unsigned int)(int)v9;
if ( 8 * v10 < v4 )
{
printf("Error: array size larger than block size (%llu bytes)!\n", v4);
exit(1);
}
if ( v3 )
{
v11 = (void *)make_array(v10);
v12 = (void *)make_array(v10);
}
else
{
printf("Long uses %d bytes. ", 8LL);
printf("Allocating 2*%lld elements = %lld bytes of memory.\n", v10, 16 * v10);
if ( v24 )
printf("Using %lld bytes as blocks for memcpy block copy test.\n", v4);
v11 = (void *)make_array(v10);
v12 = (void *)make_array(v10);
printf("Getting down to business... Doing %d runs per test.\n", (unsigned int)v17);
}
v19 = 0LL;
v13 = v4;
do
{
if ( *((_DWORD *)&v23 + v19) )
{
if ( v17 < 0 )
{
v18 = 0.0;
}
else
{
v18 = 0.0;
v15 = 0;
do
{
do
{
v16 = (unsigned int)v15;
v20 = func8(v10, v11, v12, (unsigned int)v19, v13);
++v15;
v18 = v18 + v20;
printf("%d\t", v16);
func9((unsigned int)v19, v20, v21);
}
while ( v17 > v15 );
}
while ( !v17 );
}
if ( v22 )
{
printf("AVG\t");
func9((unsigned int)v19, v18 / (double)v17, v21);
}
}
++v19;
}
while ( v19 != 3 );
free(v11);
free(v12);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    unsigned int long_size=0;
    double te, te_sum;
    unsigned long long asize=0;
    int i;
    long *a, *b;
    int o;
    unsigned long testno;
    int nr_loops=10;
    unsigned long long block_size=262144;
    int showavg=1;
    int tests[3];
    double mt=0;
    int quiet=0;
    tests[0]=0;
    tests[1]=0;
    tests[2]=0;
    while((o=getopt(argc, argv, "haqn:t:b:")) != (-1)) {
        switch(o) {
            case 'h':
                usage();
                exit(1);
                break;
            case 'a':
                showavg=0;
                break;
            case 'n':
                nr_loops=strtoul(optarg, (char **)((void *)0), 10);
                break;
            case 't':
                testno=strtoul(optarg, (char **)((void *)0), 10);
                if(testno>3 -1) {
                    printf("Error: test number must be between 0 and %d\n", 3 -1);
                    exit(1);
                }
                tests[testno]=1;
                break;
            case 'b':
                block_size=strtoull(optarg, (char **)((void *)0), 10);
                if(0>=block_size) {
                    printf("Error: what block size do you mean?\n");
                    exit(1);
                }
                break;
            case 'q':
                quiet=1;
                break;
            default:
                break;
        }
    }
    if( (tests[0]+tests[1]+tests[2]) == 0) {
        tests[0]=1;
        tests[1]=1;
        tests[2]=1;
    }
    if( nr_loops==0 && ((tests[0]+tests[1]+tests[2]) != 1) ) {
        printf("Error: nr_loops can be zero if only one test selected!\n");
        exit(1);
    }
    if(optind<argc) {
        mt=strtoul(argv[optind++], (char **)((void *)0), 10);
    } else {
        printf("Error: no array size given!\n");
        exit(1);
    }
    if(0>=mt) {
        printf("Error: array size wrong!\n");
        exit(1);
    }
    long_size=sizeof(long);
    asize=1024*1024/long_size*mt;
    if(asize*long_size < block_size) {
        printf("Error: array size larger than block size (%llu bytes)!\n", block_size);
        exit(1);
    }
    if(!quiet) {
        printf("Long uses %d bytes. ", long_size);
        printf("Allocating 2*%lld elements = %lld bytes of memory.\n", asize, 2*asize*long_size);
        if(tests[2]) {
            printf("Using %lld bytes as blocks for memcpy block copy test.\n", block_size);
        }
    }
    a=make_array(asize);
    b=make_array(asize);
    if(!quiet) {
        printf("Getting down to business... Doing %d runs per test.\n", nr_loops);
    }
    for(testno=0; testno<3; testno++) {
        te_sum=0;
        if(tests[testno]) {
            for (i=0; nr_loops==0 || i<nr_loops; i++) {
                te=worker(asize, a, b, testno, block_size);
                te_sum+=te;
                printf("%d\t", i);
                printout(te, mt, testno);
            }
            if(showavg) {
                printf("AVG\t");
                printout(te_sum/nr_loops, mt, testno);
            }
        }
    }
    free(a);
    free(b);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned int long_size = 0;
    double te; double te_sum;
    unsigned long long asize = 0;
    int i;
    long *a; long *b;
    int o;
    unsigned long testno;
    int nr_loops = 10;
    unsigned long long block_size = 262144;
    int showavg = 1;
    int tests[3];
    double mt = 0;
    int quiet = 0;
    tests[0]=0;
    tests[1]=0;
    tests[2]=0;
    while((o=getopt(argc, argv, "haqn:t:b:")) != (-1)) {
        switch(o) {
            case 'h':
                usage();
                exit(1);
                break;
            case 'a':
                showavg=0;
                break;
            case 'n':
                nr_loops=strtoul(optarg, (char **)((void *)0), 10);
                break;
            case 't':
                testno=strtoul(optarg, (char **)((void *)0), 10);
                if(testno>3 -1) {
                    printf("Error: test number must be between 0 and %d\n", 3 -1);
                    exit(1);
                }
                tests[testno]=1;
                break;
            case 'b':
                block_size=strtoull(optarg, (char **)((void *)0), 10);
                if(0>=block_size) {
                    printf("Error: what block size do you mean?\n");
                    exit(1);
                }
                break;
            case 'q':
                quiet=1;
                break;
            default:
                break;
        }
    }
    if( (tests[0]+tests[1]+tests[2]) == 0) {
        tests[0]=1;
        tests[1]=1;
        tests[2]=1;
    }
    if( nr_loops==0 && ((tests[0]+tests[1]+tests[2]) != 1) ) {
        printf("Error: nr_loops can be zero if only one test selected!\n");
        exit(1);
    }
    if(optind<argc) {
        mt=strtoul(argv[optind++], (char **)((void *)0), 10);
    } else {
        printf("Error: no array size given!\n");
        exit(1);
    }
    if(0>=mt) {
        printf("Error: array size wrong!\n");
        exit(1);
    }
    long_size=sizeof(long);
    asize=1024*1024/long_size*mt;
    if(asize*long_size < block_size) {
        printf("Error: array size larger than block size (%llu bytes)!\n", block_size);
        exit(1);
    }
    if(!quiet) {
        printf("Long uses %d bytes. ", long_size);
        printf("Allocating 2*%lld elements = %lld bytes of memory.\n", asize, 2*asize*long_size);
        if(tests[2]) {
            printf("Using %lld bytes as blocks for memcpy block copy test.\n", block_size);
        }
    }
    a=make_array(asize);
    b=make_array(asize);
    if(!quiet) {
        printf("Getting down to business... Doing %d runs per test.\n", nr_loops);
    }
    for(testno=0; testno<3; testno++) {
        te_sum=0;
        if(tests[testno]) {
            for (i=0; nr_loops==0 || i<nr_loops; i++) {
                te=worker(asize, a, b, testno, block_size);
                te_sum+=te;
                printf("%d\t", i);
                printout(te, mt, testno);
            }
            if(showavg) {
                printf("AVG\t");
                printout(te_sum/nr_loops, mt, testno);
            }
        }
    }
    free(a);
    free(b);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: te double

variable_types:
asize
unsigned long long

variable_types: i int

variable_types:
a
long *

variable_types:
b
long *

variable_types: o int

variable_types:
testno
unsigned long

variable_types: showavg int

variable_types:
tests
int [3]

variable_types: mt double

variable_types: quiet int


usage

decompiled_code:
int usage()
{
printf("mbw memory benchmark v%s, https://github.com/raas/mbw\n", "1.5");
puts("Usage: mbw [options] array_size_in_MiB");
puts("Options:");
puts("\t-n: number of runs per test (0 to run forever)");
puts("\t-a: Don't display average");
printf("\t-t%d: memcpy test\n", 0LL);
printf("\t-t%d: dumb (b[i]=a[i] style) test\n", 1LL);
printf("\t-t%d: memcpy test with fixed block size\n", 2LL);
printf("\t-b <size>: block size in bytes for -t2 (default: %d)\n", 0x40000LL);
puts("\t-q: quiet (print statistics only)");
puts("(will then use two arrays, watch out for swapping)");
puts("'Bandwidth' is amount of data copied over the time this operation took.");
return puts("\nThe default is to run all tests available.");
}

canonical_decompiled_code:
int func7()
{
printf("mbw memory benchmark v%s, https://github.com/raas/mbw\n", "1.5");
puts("Usage: mbw [options] array_size_in_MiB");
puts("Options:");
puts("\t-n: number of runs per test (0 to run forever)");
puts("\t-a: Don't display average");
printf("\t-t%d: memcpy test\n", 0LL);
printf("\t-t%d: dumb (b[i]=a[i] style) test\n", 1LL);
printf("\t-t%d: memcpy test with fixed block size\n", 2LL);
printf("\t-b <size>: block size in bytes for -t2 (default: %d)\n", 0x40000LL);
puts("\t-q: quiet (print statistics only)");
puts("(will then use two arrays, watch out for swapping)");
puts("'Bandwidth' is amount of data copied over the time this operation took.");
return puts("\nThe default is to run all tests available.");
}

original_code:
void usage()
{
    printf("mbw memory benchmark v%s, https://github.com/raas/mbw\n", "1.5");
    printf("Usage: mbw [options] array_size_in_MiB\n");
    printf("Options:\n");
    printf("	-n: number of runs per test (0 to run forever)\n");
    printf("	-a: Don't display average\n");
    printf("	-t%d: memcpy test\n", 0);
    printf("	-t%d: dumb (b[i]=a[i] style) test\n", 1);
    printf("	-t%d: memcpy test with fixed block size\n", 2);
    printf("	-b <size>: block size in bytes for -t2 (default: %d)\n", 262144);
    printf("	-q: quiet (print statistics only)\n");
    printf("(will then use two arrays, watch out for swapping)\n");
    printf("'Bandwidth' is amount of data copied over the time this operation took.\n");
    printf("\nThe default is to run all tests available.\n");
}

return_type: void


worker

decompiled_code:
double __fastcall worker(__int64 a1, char *a2, char *a3, int a4, size_t a5)
{
char *v5; // r13
size_t v6; // r12
__int64 i; // rax
struct timeval v11; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v5 = a2;
v6 = 8 * a1;
switch ( a4 )
{
case 0:
gettimeofday(&v11, 0LL);
LABEL_6:
memcpy(a3, v5, v6);
LABEL_7:
gettimeofday(&tv, 0LL);
return (double)(LODWORD(tv.tv_usec) + 1000000 * (LODWORD(tv.tv_sec) - LODWORD(v11.tv_sec)) - LODWORD(v11.tv_usec))
/ 1000000.0;
case 2:
gettimeofday(&v11, 0LL);
for ( ; a5 <= v6; v5 += a5 )
{
v6 -= a5;
memcpy(a3, v5, a5);
a3 += a5;
}
if ( !v6 )
goto LABEL_7;
goto LABEL_6;
case 1:
gettimeofday(&v11, 0LL);
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
*(_QWORD *)&a3[8 * i] = *(_QWORD *)&a2[8 * i];
}
goto LABEL_7;
}
return (double)(LODWORD(tv.tv_usec) + 1000000 * (LODWORD(tv.tv_sec) - LODWORD(v11.tv_sec)) - LODWORD(v11.tv_usec))
/ 1000000.0;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1, char *a2, char *a3, int a4, size_t a5)
{
char *v5; // r13
size_t v6; // r12
__int64 i; // rax
struct timeval v11; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF

v5 = a2;
v6 = 8 * a1;
switch ( a4 )
{
case 0:
gettimeofday(&v11, 0LL);
LABEL_6:
memcpy(a3, v5, v6);
LABEL_7:
gettimeofday(&tv, 0LL);
return (double)(LODWORD(tv.tv_usec) + 1000000 * (LODWORD(tv.tv_sec) - LODWORD(v11.tv_sec)) - LODWORD(v11.tv_usec))
/ 1000000.0;
case 2:
gettimeofday(&v11, 0LL);
for ( ; a5 <= v6; v5 += a5 )
{
v6 -= a5;
memcpy(a3, v5, a5);
a3 += a5;
}
if ( !v6 )
goto LABEL_7;
goto LABEL_6;
case 1:
gettimeofday(&v11, 0LL);
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
*(_QWORD *)&a3[8 * i] = *(_QWORD *)&a2[8 * i];
}
goto LABEL_7;
}
return (double)(LODWORD(tv.tv_usec) + 1000000 * (LODWORD(tv.tv_sec) - LODWORD(v11.tv_sec)) - LODWORD(v11.tv_usec))
/ 1000000.0;
}

original_code:
double worker(unsigned long long asize, long *a, long *b, int type, unsigned long long block_size)
{
    unsigned long long t;
    struct timeval starttime, endtime;
    double te;
    unsigned int long_size=sizeof(long);
    unsigned long long array_bytes=asize*long_size;
    if(type==0) {
        gettimeofday(&starttime, ((void *)0));
        memcpy(b, a, array_bytes);
        gettimeofday(&endtime, ((void *)0));
    } else if(type==2) {
        char* src = (char*)a;
        char* dst = (char*)b;
        gettimeofday(&starttime, ((void *)0));
        for (t=array_bytes; t >= block_size; t-=block_size, src+=block_size){
            dst=(char *) memcpy(dst, src, block_size) + block_size;
        }
        if(t) {
            dst=(char *) memcpy(dst, src, t) + t;
        }
        gettimeofday(&endtime, ((void *)0));
    } else if(type==1) {
        gettimeofday(&starttime, ((void *)0));
        for(t=0; t<asize; t++) {
            b[t]=a[t];
        }
        gettimeofday(&endtime, ((void *)0));
    }
    te=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
    return te;
}

canonical_original_code:
double worker(unsigned long long asize, long *a, long *b, int type, unsigned long long block_size)
{
    unsigned long long t;
    struct timeval starttime; struct timeval endtime;
    double te;
    unsigned int long_size = sizeof(long);
    unsigned long long array_bytes = asize*long_size;
    if(type==0) {
        gettimeofday(&starttime, ((void *)0));
        memcpy(b, a, array_bytes);
        gettimeofday(&endtime, ((void *)0));
    } else if(type==2) {
        char *src = (char*)a;
        char *dst = (char*)b;
        gettimeofday(&starttime, ((void *)0));
        for (t=array_bytes; t >= block_size; t-=block_size, src+=block_size){
            dst=(char *) memcpy(dst, src, block_size) + block_size;
        }
        if(t) {
            dst=(char *) memcpy(dst, src, t) + t;
        }
        gettimeofday(&endtime, ((void *)0));
    } else if(type==1) {
        gettimeofday(&starttime, ((void *)0));
        for(t=0; t<asize; t++) {
            b[t]=a[t];
        }
        gettimeofday(&endtime, ((void *)0));
    }
    te=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;
    return te;
}

variable_types: type int

variable_types:
t
unsigned long long

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

variable_types:
src
char *

variable_types:
dst
char *

return_type: double


printout

decompiled_code:
int __fastcall printout(int a1, double a2, double a3)
{
double v3; // xmm2_8

v3 = a2;
switch ( a1 )
{
case 1:
printf("Method: DUMB\t");
v3 = a2;
break;
case 2:
printf("Method: MCBLOCK\t");
v3 = a2;
break;
case 0:
printf("Method: MEMCPY\t");
v3 = a2;
break;
}
printf("Elapsed: %.5f\t", v3);
printf("MiB: %.5f\t", a3);
return printf("Copy: %.3f MiB/s\n", a3 / v3);
}

canonical_decompiled_code:
int __fastcall func9(int a1, double a2, double a3)
{
double v3; // xmm2_8

v3 = a2;
switch ( a1 )
{
case 1:
printf("Method: DUMB\t");
v3 = a2;
break;
case 2:
printf("Method: MCBLOCK\t");
v3 = a2;
break;
case 0:
printf("Method: MEMCPY\t");
v3 = a2;
break;
}
printf("Elapsed: %.5f\t", v3);
printf("MiB: %.5f\t", a3);
return printf("Copy: %.3f MiB/s\n", a3 / v3);
}

original_code:
void printout(double te, double mt, int type)
{
    switch(type) {
        case 0:
            printf("Method: MEMCPY\t");
            break;
        case 1:
            printf("Method: DUMB\t");
            break;
        case 2:
            printf("Method: MCBLOCK\t");
            break;
    }
    printf("Elapsed: %.5f\t", te);
    printf("MiB: %.5f\t", mt);
    printf("Copy: %.3f MiB/s\n", mt/te);
    return;
}


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

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

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

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

original_code:
int mount_list_size(MountList *mount_list) {
    int size = -1;
    for (size = 0; mount_list -> mounts[size] != ((void *)0); size++);
    return size;
}

canonical_original_code:
int mount_list_size(struct MountList *mount_list) {
    int size = -1;
    for (size = 0; mount_list -> mounts[size] != ((void *)0); size++);
    return size;
}

variable_types: struct MountList { struct Mount { char *directory_path; char *device; } *mounts[100]; } *

variable_types: size int

user_defined_types: struct MountList { struct Mount *mounts[100]; }


decompiled_code:
void *mount_list_new()
{
return calloc(0x320uLL, 1uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(0x320uLL, 1uLL);
}

original_code:
MountList *mount_list_new()
{
    MountList *mount_list = (MountList *)malloc(sizeof(MountList));
    int index = -1;
    for (index = 0; index < 100; index++) {
        mount_list -> mounts[index] = ((void *)0);
    }
    return mount_list;
}

canonical_original_code:
struct MountList *mount_list_new()
{
    struct MountList *mount_list = (MountList *)malloc(sizeof(MountList));
    int index = -1;
    for (index = 0; index < 100; index++) {
        mount_list -> mounts[index] = ((void *)0);
    }
    return mount_list;
}

variable_types: index int

return_type: struct MountList { struct Mount { char *directory_path; char *device; } *mounts[100]; } *


decompiled_code:
__int64 __fastcall mount_list_add(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = (int)mount_list_size(a1);
a1[(int)result] = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = (int)func0(a1);
a1[(int)result] = a2;
return result;
}

original_code:
void mount_list_add(MountList *mount_list, Mount *mount) {
    int index = mount_list_size(mount_list);
    mount_list -> mounts[index] = mount;
}

canonical_original_code:
void mount_list_add(struct MountList *mount_list, struct Mount *mount) {
    int index = mount_list_size(mount_list);
    mount_list -> mounts[index] = mount;
}

variable_types:
mount
struct Mount *

user_defined_types: struct Mount { char *directory_path; char *device; }


decompiled_code:
__int64 __fastcall mount_list_get(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

original_code:
Mount *mount_list_get(MountList *mount_list, int index) {
    Mount *mount = mount_list -> mounts[index];
    return mount;
}

canonical_original_code:
struct Mount *mount_list_get(struct MountList *mount_list, int index) {
    struct Mount *mount = mount_list -> mounts[index];
    return mount;
}

variable_types: struct MountList { struct Mount *mounts[100]; } *

variable_types: struct Mount { char *directory_path; char *device; } *


decompiled_code:
__int64 __fastcall mount_list_contains(_QWORD *a1, __int64 a2)
{
int v2; // eax
int v3; // er12
int v4; // ebx
__int64 v5; // rax

v2 = mount_list_size(a1);
if ( v2 <= 0 )
return 0LL;
v3 = v2;
v4 = 0;
while ( 1 )
{
v5 = mount_list_get((__int64)a1, v4);
if ( (unsigned int)mount_are_equal(a2, v5) )
break;
if ( v3 == ++v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
int v2; // eax
int v3; // er12
int v4; // ebx
__int64 v5; // rax

v2 = func0(a1);
if ( v2 <= 0 )
return 0LL;
v3 = v2;
v4 = 0;
while ( 1 )
{
v5 = func3((__int64)a1, v4);
if ( (unsigned int)mount_are_equal(a2, v5) )
break;
if ( v3 == ++v4 )
return 0LL;
}
return 1LL;
}

original_code:
int mount_list_contains(MountList *mount_list, Mount *mount)
{
    int contains = 0;
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        Mount *current_mount = mount_list_get(mount_list, index);
        if (mount_are_equal(mount, current_mount)) {
            contains = 1;
            break;
        }
    }
    return contains;
}

canonical_original_code:
int mount_list_contains(struct MountList *mount_list, struct Mount *mount)
{
    int contains = 0;
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        struct Mount *current_mount = mount_list_get(mount_list, index);
        if (mount_are_equal(mount, current_mount)) {
            contains = 1;
            break;
        }
    }
    return contains;
}

variable_types: contains int


decompiled_code:
__int64 __fastcall mount_list_print(_QWORD *a1)
{
__int64 result; // rax
int v2; // ebp
int i; // ebx
int v4; // esi
__int64 v5; // rax

result = mount_list_size(a1);
if ( (int)result > 0 )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
v4 = i;
v5 = mount_list_get((__int64)a1, v4);
result = mount_print(v5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 result; // rax
int v2; // ebp
int i; // ebx
int v4; // esi
__int64 v5; // rax

result = func0(a1);
if ( (int)result > 0 )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
v4 = i;
v5 = func3((__int64)a1, v4);
result = mount_print(v5);
}
}
return result;
}

original_code:
void mount_list_print(MountList *mount_list) {
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        Mount *mount = mount_list_get(mount_list, index);
        mount_print(mount);
    }
}

canonical_original_code:
void mount_list_print(struct MountList *mount_list) {
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        struct Mount *mount = mount_list_get(mount_list, index);
        mount_print(mount);
    }
}


decompiled_code:
__int64 __fastcall mount_list_diff(_QWORD *a1, _QWORD *a2)
{
int v2; // er15
int v3; // er14
int i; // er13
__int64 v5; // rbp
int j; // er15
__int64 v7; // rbp
__int64 v9; // [rsp+8h] [rbp-40h]

if ( !a1 || !a2 )
return 0LL;
v2 = mount_list_size(a1);
v9 = 0LL;
v3 = mount_list_size(a2);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
while ( 1 )
{
v5 = mount_list_get((__int64)a1, i);
if ( !(unsigned int)mount_list_contains(a2, v5) )
break;
if ( v2 == ++i )
goto LABEL_8;
}
v9 = mount_diff_new(v5, 1LL);
}
}
LABEL_8:
if ( v3 > 0 )
{
for ( j = 0; j != v3; ++j )
{
while ( 1 )
{
v7 = mount_list_get((__int64)a2, j);
if ( !(unsigned int)mount_list_contains(a1, v7) )
break;
if ( v3 == ++j )
return v9;
}
v9 = mount_diff_new(v7, 0LL);
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, _QWORD *a2)
{
int v2; // er15
int v3; // er14
int i; // er13
__int64 v5; // rbp
int j; // er15
__int64 v7; // rbp
__int64 v9; // [rsp+8h] [rbp-40h]

if ( !a1 || !a2 )
return 0LL;
v2 = func0(a1);
v9 = 0LL;
v3 = func0(a2);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
while ( 1 )
{
v5 = func3((__int64)a1, i);
if ( !(unsigned int)func4(a2, v5) )
break;
if ( v2 == ++i )
goto LABEL_8;
}
v9 = mount_diff_new(v5, 1LL);
}
}
LABEL_8:
if ( v3 > 0 )
{
for ( j = 0; j != v3; ++j )
{
while ( 1 )
{
v7 = func3((__int64)a2, j);
if ( !(unsigned int)func4(a1, v7) )
break;
if ( v3 == ++j )
return v9;
}
v9 = mount_diff_new(v7, 0LL);
}
}
return v9;
}

original_code:
MountDiff *mount_list_diff(MountList *old_mount_list, MountList *new_mount_list) {
    if (old_mount_list == ((void *)0) || new_mount_list == ((void *)0)) return ((void *)0);
    int old_size = mount_list_size(old_mount_list);
    int new_size = mount_list_size(new_mount_list);
    int index = -1;
    MountDiff *mount_diff = ((void *)0);
    for (index = 0; index < old_size; index++) {
        Mount *old_mount = mount_list_get(old_mount_list, index);
        if (!mount_list_contains(new_mount_list, old_mount)) {
            mount_diff = mount_diff_new(old_mount, 1);
        }
    }
    for (index = 0; index < new_size; index++) {
        Mount *new_mount = mount_list_get(new_mount_list, index);
        if (!mount_list_contains(old_mount_list, new_mount)) {
            mount_diff = mount_diff_new(new_mount, 0);
        }
    }
    return mount_diff;
}

canonical_original_code:
struct MountDiff *mount_list_diff(struct MountList *old_mount_list, struct MountList *new_mount_list) {
    if (old_mount_list == ((void *)0) || new_mount_list == ((void *)0)) return ((void *)0);
    int old_size = mount_list_size(old_mount_list);
    int new_size = mount_list_size(new_mount_list);
    int index = -1;
    struct MountDiff *mount_diff = ((void *)0);
    for (index = 0; index < old_size; index++) {
        struct Mount *old_mount = mount_list_get(old_mount_list, index);
        if (!mount_list_contains(new_mount_list, old_mount)) {
            mount_diff = mount_diff_new(old_mount, 1);
        }
    }
    for (index = 0; index < new_size; index++) {
        struct Mount *new_mount = mount_list_get(new_mount_list, index);
        if (!mount_list_contains(old_mount_list, new_mount)) {
            mount_diff = mount_diff_new(new_mount, 0);
        }
    }
    return mount_diff;
}

variable_types: struct MountDiff { int type; struct Mount { char *directory_path; char *device; } *mount; } *

user_defined_types: struct MountDiff { int type; struct Mount *mount; }


decompiled_code:
int __fastcall mount_print(const char **a1)
{
return printf("The device [%s] is mounted to [%s]. \n", a1[1], *a1);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
return printf("The device [%s] is mounted to [%s]. \n", a1[1], *a1);
}

original_code:
void mount_print(Mount *mount)
{
    printf("The device [%s] is mounted to [%s]. \n", mount -> device, mount -> directory_path);
}

canonical_original_code:
void mount_print(struct Mount *mount)
{
    printf("The device [%s] is mounted to [%s]. \n", mount -> device, mount -> directory_path);
}


decompiled_code:
_BOOL8 __fastcall mount_are_equal(const char **a1, const char **a2)
{
return strcmp(*a1, *a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char **a1, const char **a2)
{
return strcmp(*a1, *a2) == 0;
}

original_code:
int mount_are_equal(Mount *one_mount, Mount *other_mount) {
    if (strcmp(one_mount -> directory_path, other_mount -> directory_path) == 0) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int mount_are_equal(struct Mount *one_mount, struct Mount *other_mount) {
    if (strcmp(one_mount -> directory_path, other_mount -> directory_path) == 0) {
        return 1;
    } else {
        return 0;
    }
}


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

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

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

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

original_code:
int text_length(char *text)
{
    int length = 0;
    while (text[length] != '\0') length++;
    return length;
}

variable_types:
text
char *

variable_types: length int


decompiled_code:
char *__fastcall text_color(_BYTE *a1, _BYTE *a2)
{
int v2; // eax
int v3; // edx
char *v4; // r12

text_length(a1);
text_length(a2);
v2 = text_length("\x1B[0m");
v4 = (char *)malloc(v3 + v2);
sprintf(v4, "%s%s%s", a2, a1, "\x1B[0m");
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(_BYTE *a1, _BYTE *a2)
{
int v2; // eax
int v3; // edx
char *v4; // r12

func0(a1);
func0(a2);
v2 = func0("\x1B[0m");
v4 = (char *)malloc(v3 + v2);
sprintf(v4, "%s%s%s", a2, a1, "\x1B[0m");
return v4;
}

original_code:
char *text_color(char *text, char *color)
{
    char *colored_text = (char *)malloc(sizeof(char) * (text_length(text) + 1 + text_length(color) + text_length("\033[0m")));
    sprintf(colored_text, "%s%s%s", color, text, "\033[0m");
    return colored_text;
}

variable_types:
color
char *

return_type: char *


decompiled_code:
char *__fastcall text_red(_BYTE *a1)
{
return text_color(a1, "\x1B[0;31m");
}

canonical_decompiled_code:
char *__fastcall func2(_BYTE *a1)
{
return func1(a1, "\x1B[0;31m");
}

original_code:
char *text_red(char *text) {
    return text_color(text, "\033[0;31m");
}


decompiled_code:
char *__fastcall text_copy(char *src)
{
int v1; // eax
char *v2; // rax

v1 = text_length(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
int v1; // eax
char *v2; // rax

v1 = func0(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *text_copy(char *text) {
    int size = text_length(text);
    char *copied_text = (char *)malloc(sizeof(char) * (size + 1));
    strcpy(copied_text, text);
    return copied_text;
}


decompiled_code:
// attributes: thunk
void mount_poll_handler_user_data_destroy(void *ptr)
{
_mount_poll_free(ptr);
}

canonical_decompiled_code:
void func8(void *ptr)
{
func3(ptr);
}

original_code:
void mount_poll_handler_user_data_destroy(MountPollHandlerUserData* user_data)
{
    __mount_poll_handler_user_data_free(user_data);
}

canonical_original_code:
void mount_poll_handler_user_data_destroy(struct MountPollHandlerUserData *user_data)
{
    __mount_poll_handler_user_data_free(user_data);
}

variable_types: struct MountPollHandlerUserData { char *mounts_file_path; struct MountList { struct Mount { char *directory_path; char *device; } *mounts[100]; } *last_mount_list; void (*handler)(struct MountDiff { int type; struct Mount *mount; } *); } *

user_defined_types: struct MountPollHandlerUserData { char *mounts_file_path; struct MountList *last_mount_list; void (*handler)(struct MountDiff *); }


decompiled_code:
// attributes: thunk
void __fastcall poll_destroy(void *ptr)
{
_poll_free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
func1(ptr);
}

original_code:
void poll_destroy(Poll *poll)
{
    __poll_free(poll);
}

canonical_original_code:
void poll_destroy(struct Poll *poll)
{
    __poll_free(poll);
}

variable_types: struct Poll { char *directory_path; struct pollfd { int fd; short events; short revents; } *pollfd; } *

user_defined_types: struct Poll { char *directory_path; struct pollfd *pollfd; }


decompiled_code:
// attributes: thunk
void __fastcall poll_event_destroy(void *ptr)
{
poll_destroy(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
func2(ptr);
}

original_code:
void poll_event_destroy(PollEvent *poll_event)
{
    __poll_event_free(poll_event);
}

canonical_original_code:
void poll_event_destroy(struct PollEvent *poll_event)
{
    __poll_event_free(poll_event);
}

variable_types: struct PollEvent { struct Poll { char *directory_path; struct pollfd { int fd; short events; short revents; } *pollfd; } *poll; } *


decompiled_code:
int __fastcall handle_mount_diff(int *a1)
{
int v2; // edx
const char *v3; // rdi
__int64 v4; // rbp
const char *v5; // r12
const char *v6; // rax

v2 = *a1;
v3 = "ADDED";
if ( v2 )
{
v3 = "REMOVED";
if ( v2 != 1 )
v3 = 0LL;
}
v4 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL);
v5 = (const char *)text_red(v3);
v6 = (const char *)text_red(v4);
return printf("%s has been %s\n", v6, v5);
}

canonical_decompiled_code:
int __fastcall func0(int *a1)
{
int v2; // edx
const char *v3; // rdi
__int64 v4; // rbp
const char *v5; // r12
const char *v6; // rax

v2 = *a1;
v3 = "ADDED";
if ( v2 )
{
v3 = "REMOVED";
if ( v2 != 1 )
v3 = 0LL;
}
v4 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL);
v5 = (const char *)text_red(v3);
v6 = (const char *)text_red(v4);
return printf("%s has been %s\n", v6, v5);
}

original_code:
void handle_mount_diff(MountDiff *mount_diff)
{
    char *label = ((void *)0);
    label = ((void *)0);
    switch(mount_diff -> type)
    {
        case 0:
            label = "ADDED";
            break;
        case 1:
            label = "REMOVED";
            break;
    }
    char *device = mount_diff -> mount -> device;
    printf("%s has been %s\n", text_red(device), text_red(label));
}

canonical_original_code:
void handle_mount_diff(struct MountDiff *mount_diff)
{
    char *label = ((void *)0);
    label = ((void *)0);
    switch(mount_diff -> type)
    {
        case 0:
            label = "ADDED";
            break;
        case 1:
            label = "REMOVED";
            break;
    }
    char *device = mount_diff -> mount -> device;
    printf("%s has been %s\n", text_red(device), text_red(label));
}

variable_types:
label
char *

variable_types:
device
char *


main

repo: raedwulf/buddyalloc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // r13
__int64 v6; // rbp
__int64 v7; // r12

memset(&btree, 0, 0x100uLL);
bdebugtree(1LL, 1024LL);
v3 = balloc2(102400LL);
bdebugtree(1LL, 1024LL);
v4 = balloc2(245760LL);
bdebugtree(1LL, 1024LL);
v5 = balloc2(0x10000LL);
bdebugtree(1LL, 1024LL);
v6 = balloc2(0x40000LL);
bdebugtree(1LL, 1024LL);
bfree(v4);
bdebugtree(1LL, 1024LL);
bfree(v3);
bdebugtree(1LL, 1024LL);
v7 = balloc2(76800LL);
bdebugtree(1LL, 1024LL);
bfree(v5);
bdebugtree(1LL, 1024LL);
bfree(v7);
bdebugtree(1LL, 1024LL);
bfree(v6);
bdebugtree(1LL, 1024LL);
return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
a
void *

variable_types:
b
void *

variable_types:
c
void *

variable_types:
d
void *

variable_types:
e
void *


balloc

variable_types:
size
unsigned int

variable_types:
x
unsigned int

variable_types:
bs
unsigned int

variable_types:
blk
unsigned int

variable_types:
i
unsigned int

variable_types:
b
unsigned int

variable_types:
a
unsigned int

variable_types:
l
unsigned int

variable_types:
r
unsigned int

return_type: void *


btrav

decompiled_code:
__int64 __fastcall btrav(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // er8
unsigned int v5; // er12
int v6; // edx
__int64 result; // rax
int v8; // edx
int v9; // edx

while ( 1 )
{
v4 = 2 * a2;
v5 = 2 * a2 + 1;
if ( a3 <= 0x3FF )
return 0xFFFFFFFFLL;
v6 = btree[a2 >> 3];
if ( !_bittest(&v6, a2 & 7) )
break;
v8 = btree[v4 >> 3];
if ( !_bittest(&v8, v4 & 7) )
{
v9 = btree[v5 >> 3];
if ( !_bittest(&v9, v5 & 7) )
return 0xFFFFFFFFLL;
}
LABEL_4:
a3 >>= 1;
result = btrav(a1, v4, a3);
if ( (_DWORD)result != -1 )
return result;
a2 = 2 * a2 + 1;
}
if ( a3 != a1 )
goto LABEL_4;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // er8
unsigned int v5; // er12
int v6; // edx
__int64 result; // rax
int v8; // edx
int v9; // edx

while ( 1 )
{
v4 = 2 * a2;
v5 = 2 * a2 + 1;
if ( a3 <= 0x3FF )
return 0xFFFFFFFFLL;
v6 = btree[a2 >> 3];
if ( !_bittest(&v6, a2 & 7) )
break;
v8 = btree[v4 >> 3];
if ( !_bittest(&v8, v4 & 7) )
{
v9 = btree[v5 >> 3];
if ( !_bittest(&v9, v5 & 7) )
return 0xFFFFFFFFLL;
}
LABEL_4:
a3 >>= 1;
result = func8(a1, v4, a3);
if ( (_DWORD)result != -1 )
return result;
a2 = 2 * a2 + 1;
}
if ( a3 != a1 )
goto LABEL_4;
return a2;
}

original_code:
uint32_t btrav(uint32_t size, uint32_t n, uint32_t s)
{
 uint32_t a;
 uint32_t l = n << 1, r = (n << 1) + 1;
 if (s < (1 << 10)) return 0xffffffff;
 if (!(btree[(n) >> 3] & (1 << ((n) & 7))) && size == s)
  return n;
 else if ((btree[(n) >> 3] & (1 << ((n) & 7))) && !((btree[(l) >> 3] & (1 << ((l) & 7))) || (btree[(r) >> 3] & (1 << ((r) & 7)))))
  return 0xffffffff;
 else {
  if ((a = btrav(size, l, s >> 1)) != 0xffffffff)
   return a;
  if ((a = btrav(size, r, s >> 1)) != 0xffffffff)
   return a;
  return 0xffffffff;
 }
}

canonical_original_code:
unsigned int btrav(unsigned int size, unsigned int n, unsigned int s)
{
 unsigned int a;
 unsigned int l = n << 1; unsigned int r = (n << 1) + 1;
 if (s < (1 << 10)) return 0xffffffff;
 if (!(btree[(n) >> 3] & (1 << ((n) & 7))) && size == s)
  return n;
 else if ((btree[(n) >> 3] & (1 << ((n) & 7))) && !((btree[(l) >> 3] & (1 << ((l) & 7))) || (btree[(r) >> 3] & (1 << ((r) & 7)))))
  return 0xffffffff;
 else {
  if ((a = btrav(size, l, s >> 1)) != 0xffffffff)
   return a;
  if ((a = btrav(size, r, s >> 1)) != 0xffffffff)
   return a;
  return 0xffffffff;
 }
}

variable_types:
n
unsigned int

variable_types:
s
unsigned int

return_type: unsigned int


canonical_original_code:
void *balloc2(unsigned int size)
{
 if (!size) return ((void *)0);
 if (size < (1 << 10)) size = (1 << 10);
 unsigned int x = 20 - (32 - __builtin_clz(size-1));
 unsigned int blk = (1 << 20) >> x; unsigned int n;
 if ((n = btrav((1 << 20) >> x, 1, (1 << 20))) != 0xffffffff) {
  for (unsigned int b = n; b; b >>= 1) btree[(b) >> 3] |= (1 << ((b) & 7));
  unsigned int y = 31 - __builtin_clz(n);
  return bmem + ((1 << 20) >> y) * (n - (1 << y));
 }
 return ((void *)0);
}

variable_types:
y
unsigned int


bfree

decompiled_code:
unsigned int __fastcall bfree(_BYTE *a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
unsigned int v3; // ecx
int v4; // edi
unsigned int result; // eax
__int64 v6; // rdx
int v7; // ecx
int v8; // esi
unsigned int v9; // er8
int v10; // er10
int v11; // esi

if ( a1 < bmem || a1 > (_BYTE *)&end )
return fprintf(stderr, "%s: %p out of range\n", "bfree", a1);
if ( ((a1 - bmem) & 0x3FF) != 0 )
return fprintf(stderr, "%s: %p not on minimum blocksize boundary\n", "bfree", a1);
v1 = ((unsigned int)(a1 - bmem) >> 10) + 1024;
v2 = v1 >> 3;
v3 = ((unsigned int)(a1 - bmem) >> 10) & 7;
v4 = btree[v2];
if ( !_bittest(&v4, v3) )
{
result = v1 >> 1;
while ( 1 )
{
v6 = result >> 3;
v7 = result & 7;
v8 = btree[v6];
if ( _bittest(&v8, v7) )
{
v9 = 2 * result + 1;
v10 = btree[(2 * result) >> 3];
if ( _bittest(&v10, (2 * result) & 7) )
return result;
v11 = btree[v9 >> 3];
if ( _bittest(&v11, v9 & 7) )
return result;
btree[v6] &= ~(1 << v7);
}
result >>= 1;
if ( !result )
return result;
}
}
result = v4 & ~(1 << v3);
btree[v2] = v4 & ~(1 << v3);
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func10(_BYTE *a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
unsigned int v3; // ecx
int v4; // edi
unsigned int result; // eax
__int64 v6; // rdx
int v7; // ecx
int v8; // esi
unsigned int v9; // er8
int v10; // er10
int v11; // esi

if ( a1 < bmem || a1 > (_BYTE *)&end )
return fprintf(stderr, "%s: %p out of range\n", "bfree", a1);
if ( ((a1 - bmem) & 0x3FF) != 0 )
return fprintf(stderr, "%s: %p not on minimum blocksize boundary\n", "bfree", a1);
v1 = ((unsigned int)(a1 - bmem) >> 10) + 1024;
v2 = v1 >> 3;
v3 = ((unsigned int)(a1 - bmem) >> 10) & 7;
v4 = btree[v2];
if ( !_bittest(&v4, v3) )
{
result = v1 >> 1;
while ( 1 )
{
v6 = result >> 3;
v7 = result & 7;
v8 = btree[v6];
if ( _bittest(&v8, v7) )
{
v9 = 2 * result + 1;
v10 = btree[(2 * result) >> 3];
if ( _bittest(&v10, (2 * result) & 7) )
return result;
v11 = btree[v9 >> 3];
if ( _bittest(&v11, v9 & 7) )
return result;
btree[v6] &= ~(1 << v7);
}
result >>= 1;
if ( !result )
return result;
}
}
result = v4 & ~(1 << v3);
btree[v2] = v4 & ~(1 << v3);
return result;
}

canonical_original_code:
void bfree(void *mem)
{
 if (mem < (void *)bmem || mem > (void *)bmem + (1 << 20)) {
  fprintf(stderr, "%s: %p out of range\n", __func__, mem);
  return;
 }
 unsigned int y = (uint32_t)(mem - (void *)bmem);
 if (y & ((1 << 10) - 1)) {
  fprintf(stderr, "%s: %p not on minimum blocksize boundary\n",
    __func__, mem);
  return;
 }
 unsigned int b = (1 << (20 - 10)) + (y >> 10);
 if ((btree[(b) >> 3] & (1 << ((b) & 7))))
  btree[(b) >> 3] &= ~(1 << ((b) & 7));
 else
  for (unsigned int a = b >> 1; a; a >>= 1) {
   if ((btree[(a) >> 3] & (1 << ((a) & 7)))) {
    unsigned int l = a << 1; unsigned int r = (a << 1) + 1;
    if ((btree[(l) >> 3] & (1 << ((l) & 7))) || (btree[(r) >> 3] & (1 << ((r) & 7)))) break;
    btree[(a) >> 3] &= ~(1 << ((a) & 7));
   }
  }
}

variable_types:
mem
void *


utime

decompiled_code:
__time_t utime()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return 1000000 * v1.tv_sec + v1.tv_nsec / 1000;
}

canonical_decompiled_code:
__time_t func0()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return 1000000 * v1.tv_sec + v1.tv_nsec / 1000;
}

original_code:
static inline uint64_t utime() {
    struct timespec ts;
    clock_gettime(1, &ts);
    return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
}

canonical_original_code:
static inline unsigned long utime() {
    struct timespec ts;
    clock_gettime(1, &ts);
    return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er13
__int64 v6; // r12
int v7; // eax
size_t v8; // r15
__int64 v9; // rbp
__int64 v10; // r15
_BYTE *v11; // rbp
__int64 v12; // r14
char *v13; // r14
int v14; // er15
__int64 v15; // rax
char v16; // dl
unsigned int v17; // er9
__int64 i; // r15
__int64 j; // r15
__int64 v20; // r15
int v21; // ecx
int v22; // eax
int v23; // ecx
__int64 k; // rbp
int v25; // er12
int v26; // er12
__time_t v27; // [rsp+0h] [rbp-58h]
__time_t v28; // [rsp+8h] [rbp-50h]
int longind[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

check_flag = 0;
help_flag = 0;
read_offset = 0;
write_offset = 0;
iterations = 100;
size = 10000;
algtype = 0;
while ( 1 )
{
longind[0] = 0;
v3 = getopt_long(argc, (char *const *)argv, "o:s:i:t:hc", &long_options_0, longind);
if ( v3 == -1 )
break;
if ( v3 )
{
switch ( v3 )
{
case 'c':
check_flag = 1;
continue;
case 'h':
help_flag = 1;
continue;
case 'i':
_isoc99_sscanf(optarg, "%d", &iterations);
continue;
case 'r':
_isoc99_sscanf(optarg, "%d", &read_offset);
continue;
case 's':
_isoc99_sscanf(optarg, "%d", &size);
continue;
case 't':
_isoc99_sscanf(optarg, "%d", &algtype);
continue;
case 'w':
_isoc99_sscanf(optarg, "%d", &write_offset);
continue;
default:
return 1;
}
}
}
v4 = help_flag;
if ( help_flag )
{
v4 = 0;
printf(
"Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
" -s set the size of the data to copy\n"
" -o set the offset to copy from (default=0)\n"
" -i set the iterations to run (default=100)\n"
" -t algorithm type (0=c,1=rep movsb,2=sse2)\n"
" -h this help\n",
*argv);
return v4;
}
v6 = read_offset;
if ( (unsigned int)read_offset > 0x10 )
{
v4 = 1;
fprintf(stderr, "%s: option --read_offset must be between 0 and 15\n", *argv);
return v4;
}
v7 = write_offset;
if ( (unsigned int)write_offset > 0x10 )
{
v4 = 1;
fprintf(stderr, "%s: option --write_offset must be between 0 and 15\n", *argv);
return v4;
}
if ( read_offset >= write_offset )
v7 = read_offset;
if ( size < v7 )
{
v4 = 1;
fprintf(stderr, "%s: option --size must be greater than 0 and offset\n", *argv);
return v4;
}
if ( (unsigned int)algtype > 2 )
{
fprintf(stderr, "%s: option --type must be between 0 and 2\n", *argv);
return 1;
}
v8 = size + 32;
v9 = (__int64)calloc(v8, 1uLL);
dst_data = (__int64)malloc(v8);
v10 = dst_data;
if ( (v9 & 0xF) != 0 )
v9 = v9 - (v9 & 0xF) + 16;
v11 = (_BYTE *)(v6 + v9);
while ( size + read_offset > (int)v6 )
v11[v6++] = rand() % 255 + 1;
v12 = v10;
if ( (v10 & 0xF) != 0 )
v12 = v10 - (v10 & 0xF) + 16;
v13 = (char *)(write_offset + v12);
memset((void *)v10, 0, size + 32);
v14 = algtype;
switch ( algtype )
{
case 1:
v26 = 0;
v27 = utime();
while ( iterations > v26 )
{
++v26;
memcpy_movsb(v13, v11, size);
}
goto LABEL_64;
case 2:
v25 = 0;
v27 = utime();
while ( iterations > v25 )
{
++v25;
memcpy_sse2(v13, v11, size);
}
goto LABEL_64;
case 0:
v27 = utime();
while ( iterations > v14 )
{
++v14;
memcpy(v13, v11, size);
}
LABEL_64:
v28 = utime();
break;
}
if ( check_flag )
{
v15 = 0LL;
while ( 1 )
{
v17 = v15;
if ( size <= (int)v15 )
break;
v16 = v11[v15++];
if ( v16 != v13[v15 - 1] )
{
fprintf(stderr, "%s: bad copy %d\n", *argv, v17);
break;
}
}
for ( i = 0LL; read_offset > (int)i; ++i )
{
if ( v11[i] )
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)i);
}
for ( j = 0LL; write_offset > (int)j; ++j )
{
if ( v13[j] )
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)j);
}
v20 = size;
v21 = read_offset;
v22 = size;
while ( v22 + v21 > (int)v20 )
{
if ( v11[v20] )
{
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)v20);
v21 = read_offset;
v22 = size;
}
++v20;
}
v23 = write_offset;
for ( k = v22; v22 + v23 > (int)k; ++k )
{
if ( v13[k] )
{
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)k);
v23 = write_offset;
v22 = size;
}
}
}
printf("%llu\n", v28 - v27);
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er13
__int64 v6; // r12
int v7; // eax
size_t v8; // r15
__int64 v9; // rbp
__int64 v10; // r15
_BYTE *v11; // rbp
__int64 v12; // r14
char *v13; // r14
int v14; // er15
__int64 v15; // rax
char v16; // dl
unsigned int v17; // er9
__int64 i; // r15
__int64 j; // r15
__int64 v20; // r15
int v21; // ecx
int v22; // eax
int v23; // ecx
__int64 k; // rbp
int v25; // er12
int v26; // er12
__time_t v27; // [rsp+0h] [rbp-58h]
__time_t v28; // [rsp+8h] [rbp-50h]
int longind[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

check_flag = 0;
help_flag = 0;
read_offset = 0;
write_offset = 0;
iterations = 100;
size = 10000;
algtype = 0;
while ( 1 )
{
longind[0] = 0;
v3 = getopt_long(argc, (char *const *)argv, "o:s:i:t:hc", &long_options_0, longind);
if ( v3 == -1 )
break;
if ( v3 )
{
switch ( v3 )
{
case 'c':
check_flag = 1;
continue;
case 'h':
help_flag = 1;
continue;
case 'i':
_isoc99_sscanf(optarg, "%d", &iterations);
continue;
case 'r':
_isoc99_sscanf(optarg, "%d", &read_offset);
continue;
case 's':
_isoc99_sscanf(optarg, "%d", &size);
continue;
case 't':
_isoc99_sscanf(optarg, "%d", &algtype);
continue;
case 'w':
_isoc99_sscanf(optarg, "%d", &write_offset);
continue;
default:
return 1;
}
}
}
v4 = help_flag;
if ( help_flag )
{
v4 = 0;
printf(
"Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
" -s set the size of the data to copy\n"
" -o set the offset to copy from (default=0)\n"
" -i set the iterations to run (default=100)\n"
" -t algorithm type (0=c,1=rep movsb,2=sse2)\n"
" -h this help\n",
*argv);
return v4;
}
v6 = read_offset;
if ( (unsigned int)read_offset > 0x10 )
{
v4 = 1;
fprintf(stderr, "%s: option --read_offset must be between 0 and 15\n", *argv);
return v4;
}
v7 = write_offset;
if ( (unsigned int)write_offset > 0x10 )
{
v4 = 1;
fprintf(stderr, "%s: option --write_offset must be between 0 and 15\n", *argv);
return v4;
}
if ( read_offset >= write_offset )
v7 = read_offset;
if ( size < v7 )
{
v4 = 1;
fprintf(stderr, "%s: option --size must be greater than 0 and offset\n", *argv);
return v4;
}
if ( (unsigned int)algtype > 2 )
{
fprintf(stderr, "%s: option --type must be between 0 and 2\n", *argv);
return 1;
}
v8 = size + 32;
v9 = (__int64)calloc(v8, 1uLL);
dst_data = (__int64)malloc(v8);
v10 = dst_data;
if ( (v9 & 0xF) != 0 )
v9 = v9 - (v9 & 0xF) + 16;
v11 = (_BYTE *)(v6 + v9);
while ( size + read_offset > (int)v6 )
v11[v6++] = rand() % 255 + 1;
v12 = v10;
if ( (v10 & 0xF) != 0 )
v12 = v10 - (v10 & 0xF) + 16;
v13 = (char *)(write_offset + v12);
memset((void *)v10, 0, size + 32);
v14 = algtype;
switch ( algtype )
{
case 1:
v26 = 0;
v27 = func0();
while ( iterations > v26 )
{
++v26;
memcpy_movsb(v13, v11, size);
}
goto LABEL_64;
case 2:
v25 = 0;
v27 = func0();
while ( iterations > v25 )
{
++v25;
memcpy_sse2(v13, v11, size);
}
goto LABEL_64;
case 0:
v27 = func0();
while ( iterations > v14 )
{
++v14;
memcpy(v13, v11, size);
}
LABEL_64:
v28 = func0();
break;
}
if ( check_flag )
{
v15 = 0LL;
while ( 1 )
{
v17 = v15;
if ( size <= (int)v15 )
break;
v16 = v11[v15++];
if ( v16 != v13[v15 - 1] )
{
fprintf(stderr, "%s: bad copy %d\n", *argv, v17);
break;
}
}
for ( i = 0LL; read_offset > (int)i; ++i )
{
if ( v11[i] )
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)i);
}
for ( j = 0LL; write_offset > (int)j; ++j )
{
if ( v13[j] )
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)j);
}
v20 = size;
v21 = read_offset;
v22 = size;
while ( v22 + v21 > (int)v20 )
{
if ( v11[v20] )
{
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)v20);
v21 = read_offset;
v22 = size;
}
++v20;
}
v23 = write_offset;
for ( k = v22; v22 + v23 > (int)k; ++k )
{
if ( v13[k] )
{
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)k);
v23 = write_offset;
v22 = size;
}
}
}
printf("%llu\n", v28 - v27);
return v4;
}

original_code:
int main(int argc, char **argv) {
 int c;
 check_flag = 0;
 help_flag = 0;
 read_offset = 0;
 write_offset = 0;
 iterations = 100;
 size = 10000;
 algtype = 0;
 while (1) {
  static struct option long_options[] = {
   {"check", 0, &check_flag, 1},
   {"read_offset", 1, 0, 'r'},
   {"write_offset", 1, 0, 'w'},
   {"size", 1, 0, 's'},
   {"iterations", 1, 0, 'i'},
   {"type", 1, 0, 't'},
   {"help", 0, &help_flag, 'h'},
   {0, 0, 0, 0}
  };
  int option_index = 0;
  c = getopt_long(argc, argv, "o:s:i:t:hc", long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   if (long_options[option_index].flag != 0)
    break;
   break;
  case 's':
   sscanf(optarg, "%d", &size);
   break;
  case 'r':
   sscanf(optarg, "%d", &read_offset);
   break;
  case 'w':
   sscanf(optarg, "%d", &write_offset);
   break;
  case 'i':
   sscanf(optarg, "%d", &iterations);
   break;
  case 't':
   sscanf(optarg, "%d", &algtype);
   break;
  case 'h':
   help_flag = 1;
   break;
  case 'c':
   check_flag = 1;
   break;
  default:
   return 1;
  }
 }
 if (help_flag) {
  printf("Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
         "    -s    set the size of the data to copy\n"
         "    -o    set the offset to copy from (default=0)\n"
         "    -i    set the iterations to run (default=100)\n"
         "    -t    algorithm type (0=c,1=rep movsb,2=sse2)\n"
         "    -h    this help\n", argv[0]);
  return 0;
 }
 if (read_offset < 0 || read_offset > 16) {
  fprintf(stderr,
          "%s: option --read_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (write_offset < 0 || write_offset > 16) {
  fprintf(stderr,
          "%s: option --write_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (size < 0 || size < read_offset || size < write_offset) {
  fprintf(stderr,
          "%s: option --size must be greater than 0 and offset\n",
          argv[0]);
  return 1;
 }
 if (algtype < 0 || algtype > 2) {
  fprintf(stderr,
          "%s: option --type must be between 0 and 2\n",
          argv[0]);
  return 1;
 }
 src_data = malloc(size + 16 * 2);
 dst_data = malloc(size + 16 * 2);
 uint8_t *src = ((((uintptr_t)src_data) % 16) ? (src_data + 16 - (((uintptr_t)src_data) % 16)) : src_data) + read_offset;
 memset(src_data, 0, size + 16 * 2);
 for (int i = read_offset; i < size + read_offset; i++)
  src[i] = rand() % 255 + 1;
 uint8_t *dst = ((((uintptr_t)dst_data) % 16) ? (dst_data + 16 - (((uintptr_t)dst_data) % 16)) : dst_data) + write_offset;
 memset(dst_data, 0, size + 16 * 2);
 uint64_t start, end;
 switch (algtype) {
 case 0:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy(dst, src, size);
  end = utime();
  break;
 case 1:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_movsb(dst, src, size);
  end = utime();
  break;
 case 2:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_sse2(dst, src, size);
  end = utime();
  break;
 }
 if (check_flag) {
  for (int i = 0; i < size; i++) {
   if (src[i] != dst[i]) {
    fprintf(stderr, "%s: bad copy %d\n",
     argv[0], i);
    break;
   }
  }
  for (int i = 0; i < read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0],
     i);
   }
  }
  for (int i = 0; i < write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
 }
 printf("%llu\n", end - start);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int c;
 check_flag = 0;
 help_flag = 0;
 read_offset = 0;
 write_offset = 0;
 iterations = 100;
 size = 10000;
 algtype = 0;
 while (1) {
  static struct option long_options[] = {
   {"check", 0, &check_flag, 1},
   {"read_offset", 1, 0, 'r'},
   {"write_offset", 1, 0, 'w'},
   {"size", 1, 0, 's'},
   {"iterations", 1, 0, 'i'},
   {"type", 1, 0, 't'},
   {"help", 0, &help_flag, 'h'},
   {0, 0, 0, 0}
  };
  int option_index = 0;
  c = getopt_long(argc, argv, "o:s:i:t:hc", long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   if (long_options[option_index].flag != 0)
    break;
   break;
  case 's':
   sscanf(optarg, "%d", &size);
   break;
  case 'r':
   sscanf(optarg, "%d", &read_offset);
   break;
  case 'w':
   sscanf(optarg, "%d", &write_offset);
   break;
  case 'i':
   sscanf(optarg, "%d", &iterations);
   break;
  case 't':
   sscanf(optarg, "%d", &algtype);
   break;
  case 'h':
   help_flag = 1;
   break;
  case 'c':
   check_flag = 1;
   break;
  default:
   return 1;
  }
 }
 if (help_flag) {
  printf("Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
         "    -s    set the size of the data to copy\n"
         "    -o    set the offset to copy from (default=0)\n"
         "    -i    set the iterations to run (default=100)\n"
         "    -t    algorithm type (0=c,1=rep movsb,2=sse2)\n"
         "    -h    this help\n", argv[0]);
  return 0;
 }
 if (read_offset < 0 || read_offset > 16) {
  fprintf(stderr,
          "%s: option --read_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (write_offset < 0 || write_offset > 16) {
  fprintf(stderr,
          "%s: option --write_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (size < 0 || size < read_offset || size < write_offset) {
  fprintf(stderr,
          "%s: option --size must be greater than 0 and offset\n",
          argv[0]);
  return 1;
 }
 if (algtype < 0 || algtype > 2) {
  fprintf(stderr,
          "%s: option --type must be between 0 and 2\n",
          argv[0]);
  return 1;
 }
 src_data = malloc(size + 16 * 2);
 dst_data = malloc(size + 16 * 2);
 unsigned char *src = ((((uintptr_t)src_data) % 16) ? (src_data + 16 - (((uintptr_t)src_data) % 16)) : src_data) + read_offset;
 memset(src_data, 0, size + 16 * 2);
 for (int i = read_offset; i < size + read_offset; i++)
  src[i] = rand() % 255 + 1;
 unsigned char *dst = ((((uintptr_t)dst_data) % 16) ? (dst_data + 16 - (((uintptr_t)dst_data) % 16)) : dst_data) + write_offset;
 memset(dst_data, 0, size + 16 * 2);
 unsigned long start; unsigned long end;
 switch (algtype) {
 case 0:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy(dst, src, size);
  end = utime();
  break;
 case 1:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_movsb(dst, src, size);
  end = utime();
  break;
 case 2:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_sse2(dst, src, size);
  end = utime();
  break;
 }
 if (check_flag) {
  for (int i = 0; i < size; i++) {
   if (src[i] != dst[i]) {
    fprintf(stderr, "%s: bad copy %d\n",
     argv[0], i);
    break;
   }
  }
  for (int i = 0; i < read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0],
     i);
   }
  }
  for (int i = 0; i < write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
 }
 printf("%llu\n", end - start);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
src
unsigned char *

variable_types: i int

variable_types:
dst
unsigned char *

variable_types:
start
unsigned long

variable_types:
end
unsigned long


repo: raeffu/ginf-c-pointers

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts(
"struct NODE nodes[5] = {\n"
" { 5, nodes + 3, NULL },\n"
" { 15, nodes + 4, nodes + 3 },\n"
" { 22, NULL, nodes + 4 },\n"
" { 12, nodes + 1, nodes },\n"
" { 18, nodes + 2, nodes + 1 }\n"
"};");
printf("sizeof(int) \t\t%zu\n", 4uLL);
printf("sizeof(struct NODE *) \t%zu\n", 8uLL);
printf("sizeof(nodes[0].a) \t%zu\n", 4uLL);
printf("sizeof(nodes[0].b) \t%zu\n", 8uLL);
printf("sizeof(nodes[0].c) \t%zu\n", 8uLL);
printf("sizeof(nodes[0]) \t%zu\n", 0x18uLL);
printf("sizeof(nodes) \t\t%zu\n", 0x78uLL);
printf("nodes[3].a\t\t%i\n", (unsigned int)dword_4040C8);
printf("nodes[3].a\t\t%i\n", (unsigned int)dword_4040C8);
printf("nodes\t\t\t%p\n", &nodes);
printf("nodes[3].a\t\t%i\n", (unsigned int)dword_4040C8);
printf("nodes[3].c\t\t%p\n", off_4040D8);
printf("nodes[3].c->a\t\t%i\n", (unsigned int)*off_4040D8);
printf("*nodes\t\t\t{ %i, %p, %p }\n", (unsigned int)nodes, off_404088, (const void *)qword_404090);
puts("*nodes.a\t\tillegal");
printf("(*nodes).a\t\t%i\n", (unsigned int)nodes);
printf("nodes->a\t\t%i\n", (unsigned int)nodes);
printf("nodes[3].b->b\t\t%p\n", *((const void **)off_4040D0 + 1));
printf(
"*nodes[3].b->b\t\t{ %i, %p, %p }\n",
**((unsigned int **)off_4040D0 + 1),
*(const void **)(*((_QWORD *)off_4040D0 + 1) + 8LL),
*(const void **)(*((_QWORD *)off_4040D0 + 1) + 16LL));
printf("&nodes\t\t\t%p \n", &nodes);
printf("&nodes[3].a\t\t%p \n", &dword_4040C8);
printf("&nodes[3].b\t\t%p \n", &off_4040D0);
printf("&nodes[3].c\t\t%p \n", &off_4040D8);
printf("&nodes[3].c->a\t\t%p \n", off_4040D8);
printf("np\t\t\t%p \n", np);
printf("np->a\t\t\t%i \n", *(unsigned int *)np);
printf("np->c->c->a\t\t%i \n", **(unsigned int **)(*((_QWORD *)np + 2) + 16LL));
printf("*npp\t\t\t%p \n", *npp);
printf("**npp\t\t\t{ %i, %p, %p }\n", *(unsigned int *)*npp, *((const void **)*npp + 1), *((const void **)*npp + 2));
printf("**npp\t\t\t{ %i, %p, %p }\n", *(unsigned int *)*npp, *((const void **)*npp + 1), *((const void **)*npp + 2));
puts("*npp->a\t\t\tillegal");
printf("(*npp)->a\t\t%i\n", *(unsigned int *)*npp);
printf("&np\t\t\tunknown: %p\n", &np);
printf("&np->a\t\t\t%p\n", np);
printf("&np->c->c->a\t\t%p\n", *(const void **)(*((_QWORD *)np + 2) + 16LL));
return 1;
}

original_code:
int main(){
  printf("struct NODE nodes[5] = {\n { 5, nodes + 3, NULL },\n { 15, nodes + 4, nodes + 3 },\n { 22, NULL, nodes + 4 },\n { 12, nodes + 1, nodes },\n { 18, nodes + 2, nodes + 1 }\n};\n");
  printf("sizeof(int) \t\t%zu\n", sizeof(int));
  printf("sizeof(struct NODE *) \t%zu\n", sizeof(struct NODE *));
  printf("sizeof(nodes[0].a) \t%zu\n", sizeof(nodes[0].a));
  printf("sizeof(nodes[0].b) \t%zu\n", sizeof(nodes[0].b));
  printf("sizeof(nodes[0].c) \t%zu\n", sizeof(nodes[0].c));
    printf("sizeof(nodes[0]) \t%zu\n", sizeof(nodes[0]));
  printf("sizeof(nodes) \t\t%zu\n", sizeof(nodes));
  printf("nodes[3].a\t\t%i\n", nodes[3].a);
  printf("nodes[3].a\t\t%i\n", nodes[3].a);
  printf("nodes\t\t\t%p\n", nodes);
  printf("nodes[3].a\t\t%i\n", nodes[3].a);
  printf("nodes[3].c\t\t%p\n", nodes[3].c);
  printf("nodes[3].c->a\t\t%i\n", nodes[3].c->a);
  printf("*nodes\t\t\t{ %i, %p, %p }\n", (*nodes).a, (*nodes).b, (*nodes).c);
  printf("*nodes.a\t\tillegal\n");
  printf("(*nodes).a\t\t%i\n", (*nodes).a);
  printf("nodes->a\t\t%i\n", nodes->a);
  printf("nodes[3].b->b\t\t%p\n", nodes[3].b->b);
  printf("*nodes[3].b->b\t\t{ %i, %p, %p }\n", (*nodes[3].b->b).a, (*nodes[3].b->b).b, (*nodes[3].b->b).c );
  printf("&nodes\t\t\t%p \n", &nodes);
  printf("&nodes[3].a\t\t%p \n", &nodes[3].a);
    printf("&nodes[3].b\t\t%p \n", &nodes[3].b);
  printf("&nodes[3].c\t\t%p \n", &nodes[3].c);
  printf("&nodes[3].c->a\t\t%p \n", &nodes[3].c->a);
  printf("np\t\t\t%p \n", np);
  printf("np->a\t\t\t%i \n", np->a);
  printf("np->c->c->a\t\t%i \n", np->c->c->a);
  printf("*npp\t\t\t%p \n", *npp);
  printf("**npp\t\t\t{ %i, %p, %p }\n", (**npp).a, (**npp).b, (**npp).c );
  printf("**npp\t\t\t{ %i, %p, %p }\n", (**npp).a, (**npp).b, (**npp).c );
  printf("*npp->a\t\t\tillegal\n" );
  printf("(*npp)->a\t\t%i\n",(*npp)->a );
  printf("&np\t\t\tunknown: %p\n",&np);
  printf("&np->a\t\t\t%p\n",&np->a);
  printf("&np->c->c->a\t\t%p\n",&np->c->c->a);
  return 1;
}

user_defined_types: struct NODE { int a; struct NODE *b; struct NODE *c; }


decompiled_code:
void __fastcall usb_bulk_send(__int64 a1, int a2)
{
int v3; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( a2 > 0 )
{
v3 = a2;
do
{
v4 = libusb_bulk_transfer(usb, 1LL, a1, (unsigned int)v3, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_send error %d\n", v4);
exit(2);
}
v3 -= v5[0];
a1 += v5[0];
}
while ( v3 > 0 );
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
int v3; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( a2 > 0 )
{
v3 = a2;
do
{
v4 = libusb_bulk_transfer(usb, 1LL, a1, (unsigned int)v3, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_send error %d\n", v4);
exit(2);
}
v3 -= v5[0];
a1 += v5[0];
}
while ( v3 > 0 );
}
}

original_code:
static void usb_bulk_send(const void *data, int length)
{
    int rc, sent;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_OUT,
                (void*)data, length, &sent, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_send error %d\n", rc);
            exit(2);
        }
        length -= sent;
        data += sent;
    }
}

canonical_original_code:
static void usb_bulk_send(void *data, int length)
{
    int rc; int sent;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_OUT,
                (void *)data, length, &sent, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_send error %d\n", rc);
            exit(2);
        }
        length -= sent;
        data += sent;
    }
}

variable_types:
data
void *

variable_types: length int

variable_types: rc int

variable_types: sent int


decompiled_code:
void __fastcall aw_send_usb_request(__int64 a1, unsigned int a2)
{
unsigned int v2; // er8
__int128 v3; // [rsp+0h] [rbp-28h] BYREF
__int128 v4; // [rsp+10h] [rbp-18h]

DWORD1(v3) = 0;
v4 = 0LL;
LODWORD(v3) = 1129666369;
*(_DWORD *)((char *)&v4 + 2) = _uint32_identity(a2);
DWORD2(v3) = *(_DWORD *)((char *)&v4 + 2);
LOWORD(v4) = _uint16_identity(v2);
HIDWORD(v3) = _uint32_identity(0xC000000u);
usb_bulk_send((__int64)&v3, 32);
}

original_code:
static void aw_send_usb_request(int type, int length)
{
    struct aw_usb_request req;
    memset(&req, 0, sizeof(req));
    strcpy(req.signature, "AWUC");
    req.length = req.length2 = __uint32_identity (length);
    req.request = __uint16_identity (type);
    req.unknown1 = __uint32_identity (0x0c000000);
    usb_bulk_send(&req, sizeof(req));
}

variable_types: type int

variable_types: struct aw_usb_request { char signature[8]; unsigned int length; unsigned int unknown1; unsigned short request; unsigned int length2; char pad[10]; }


decompiled_code:
void __fastcall usb_bulk_recv(__int64 a1, int a2)
{
int v3; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( a2 > 0 )
{
v3 = a2;
do
{
v4 = libusb_bulk_transfer(usb, 130LL, a1, (unsigned int)v3, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_recv error %d\n", v4);
exit(2);
}
v3 -= v5[0];
a1 += v5[0];
}
while ( v3 > 0 );
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
int v3; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( a2 > 0 )
{
v3 = a2;
do
{
v4 = libusb_bulk_transfer(usb, 130LL, a1, (unsigned int)v3, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_recv error %d\n", v4);
exit(2);
}
v3 -= v5[0];
a1 += v5[0];
}
while ( v3 > 0 );
}
}

original_code:
static void usb_bulk_recv(void *data, int length)
{
    int rc, recv;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_IN,
                data, length, &recv, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_recv error %d\n", rc);
            exit(2);
        }
        length -= recv;
        data += recv;
    }
}

canonical_original_code:
static void usb_bulk_recv(void *data, int length)
{
    int rc; int recv;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_IN,
                data, length, &recv, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_recv error %d\n", rc);
            exit(2);
        }
        length -= recv;
        data += recv;
    }
}

variable_types: recv int


decompiled_code:
void aw_read_usb_response()
{
int v0; // [rsp+3h] [rbp-15h] BYREF
char v1; // [rsp+7h] [rbp-11h]

usb_bulk_recv((__int64)&v0, 13);
if ( v0 != 1398101825 || v1 )
puts("warn: bad response from device");
}

canonical_decompiled_code:
void func5()
{
int v0; // [rsp+3h] [rbp-15h] BYREF
char v1; // [rsp+7h] [rbp-11h]

func4((__int64)&v0, 13);
if ( v0 != 1398101825 || v1 )
puts("warn: bad response from device");
}

original_code:
static void aw_read_usb_response(void)
{
    char buf[13];
    usb_bulk_recv(&buf, sizeof(buf));
    if( strcmp(buf, "AWUS") ) {
        printf("warn: bad response from device\n");
    }
}

canonical_original_code:
static void aw_read_usb_response()
{
    char buf[13];
    usb_bulk_recv(&buf, sizeof(buf));
    if( strcmp(buf, "AWUS") ) {
        printf("warn: bad response from device\n");
    }
}

variable_types:
buf
char [13]


decompiled_code:
void __fastcall aw_usb_write(__int64 a1, unsigned int a2)
{
aw_send_usb_request(18LL, a2);
usb_bulk_send(a1, a2);
aw_read_usb_response();
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, unsigned int a2)
{
func3(18LL, a2);
func2(a1, a2);
func5();
}

original_code:
static void aw_usb_write(const void *data, size_t len)
{
    aw_send_usb_request(0x12, len);
    usb_bulk_send(data, len);
    aw_read_usb_response();
}

canonical_original_code:
static void aw_usb_write(void *data, unsigned long len)
{
    aw_send_usb_request(0x12, len);
    usb_bulk_send(data, len);
    aw_read_usb_response();
}

variable_types:
len
unsigned long


decompiled_code:
void __fastcall aw_send_fel_request(unsigned int a1, unsigned int a2)
{
unsigned int v2; // edx
int v3[6]; // [rsp+0h] [rbp-18h] BYREF

v3[3] = 0;
v3[0] = _uint32_identity(a1);
v3[1] = _uint32_identity(a2);
v3[2] = _uint32_identity(v2);
aw_usb_write((__int64)v3, 0x10u);
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1, unsigned int a2)
{
unsigned int v2; // edx
int v3[6]; // [rsp+0h] [rbp-18h] BYREF

v3[3] = 0;
v3[0] = func1(a1);
v3[1] = func1(a2);
v3[2] = func1(v2);
func6((__int64)v3, 0x10u);
}

original_code:
static void aw_send_fel_request(int type, uint32_t addr,
        uint32_t length)
{
    struct aw_fel_request req;
    memset(&req, 0, sizeof(req));
    req.request = __uint32_identity (type);
    req.address = __uint32_identity (addr);
    req.length = __uint32_identity (length);
    req.flags = 0;
    aw_usb_write(&req, sizeof(req));
}

canonical_original_code:
static void aw_send_fel_request(int type, unsigned int addr, unsigned int length)
{
    struct aw_fel_request req;
    memset(&req, 0, sizeof(req));
    req.request = __uint32_identity (type);
    req.address = __uint32_identity (addr);
    req.length = __uint32_identity (length);
    req.flags = 0;
    aw_usb_write(&req, sizeof(req));
}

variable_types:
addr
unsigned int

variable_types:
length
unsigned int

variable_types: struct aw_fel_request { unsigned int request; unsigned int address; unsigned int length; unsigned int flags; }


decompiled_code:
void aw_read_fel_status()
{
char v0[16]; // [rsp+8h] [rbp-10h] BYREF

aw_usb_read_constprop_0((__int64)v0);
}

canonical_decompiled_code:
void func9()
{
char v0[16]; // [rsp+8h] [rbp-10h] BYREF

func8((__int64)v0);
}

original_code:
static void aw_read_fel_status(void)
{
    char buf[8];
    aw_usb_read(&buf, sizeof(buf));
}

canonical_original_code:
static void aw_read_fel_status()
{
    char buf[8];
    aw_usb_read(&buf, sizeof(buf));
}

variable_types:
buf
char [8]


decompiled_code:
__int64 __fastcall send_bootfile(const char *a1, unsigned int a2)
{
int v4; // eax
char *v5; // rax
unsigned int v6; // er12
int v7; // edi
signed int v8; // eax
signed int v9; // ebx
int v10; // edi
char *v12; // rax
char v13[1008]; // [rsp+0h] [rbp-80418h] BYREF
char buf[524328]; // [rsp+3F0h] [rbp-80028h] BYREF

v4 = readlink("/proc/self/exe", buf, 0x80000uLL);
if ( v4 > 0 )
{
buf[v4] = 0;
v5 = dirname(buf);
sprintf(v13, "%s/arm/%s", v5, a1);
v6 = open(v13, 0);
if ( v6 != -1 )
goto LABEL_7;
v7 = *_errno_location();
if ( v7 != 2 )
{
v12 = strerror(v7);
fprintf(stderr, "unable to open FEL bootfile %s: %s\n", v13, v12);
return v6;
}
}
sprintf(v13, "/usr/share/allwindisk/%s", a1);
v6 = open(v13, 0);
if ( v6 == -1 )
{
fprintf(stderr, "unable to open FEL bootfile %s\n", v13);
return v6;
}
LABEL_7:
while ( 1 )
{
v8 = read(v6, buf, 0x80000uLL);
v9 = v8;
if ( v8 <= 0 )
break;
send_write_request_constprop_0(a2, (unsigned int)v8, (__int64)buf, v8);
a2 += v9;
}
v10 = v6;
v6 = 0;
close(v10);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, unsigned int a2)
{
int v4; // eax
char *v5; // rax
unsigned int v6; // er12
int v7; // edi
signed int v8; // eax
signed int v9; // ebx
int v10; // edi
char *v12; // rax
char v13[1008]; // [rsp+0h] [rbp-80418h] BYREF
char buf[524328]; // [rsp+3F0h] [rbp-80028h] BYREF

v4 = readlink("/proc/self/exe", buf, 0x80000uLL);
if ( v4 > 0 )
{
buf[v4] = 0;
v5 = dirname(buf);
sprintf(v13, "%s/arm/%s", v5, a1);
v6 = open(v13, 0);
if ( v6 != -1 )
goto LABEL_7;
v7 = *_errno_location();
if ( v7 != 2 )
{
v12 = strerror(v7);
fprintf(stderr, "unable to open FEL bootfile %s: %s\n", v13, v12);
return v6;
}
}
sprintf(v13, "/usr/share/allwindisk/%s", a1);
v6 = open(v13, 0);
if ( v6 == -1 )
{
fprintf(stderr, "unable to open FEL bootfile %s\n", v13);
return v6;
}
LABEL_7:
while ( 1 )
{
v8 = read(v6, buf, 0x80000uLL);
v9 = v8;
if ( v8 <= 0 )
break;
func11(a2, (unsigned int)v8, (__int64)buf, v8);
a2 += v9;
}
v10 = v6;
v6 = 0;
close(v10);
return v6;
}

original_code:
static int send_bootfile(const char *fname, unsigned load_addr)
{
    int fd = -1, rd;
    char buf[0x80000];
    char filepath[1000];
    if( (rd = readlink("/proc/self/exe", buf, sizeof(buf))) > 0 )
    {
        buf[rd] = '\0';
        char *dname = dirname(buf);
        sprintf(filepath, "%s/arm/%s", dname, fname);
        fd = open(filepath, 00);
        if( fd == -1 && (*__errno_location ()) != 2 ) {
            fprintf(stderr, "unable to open FEL bootfile %s: %s\n",
                    filepath, strerror((*__errno_location ())));
            return -1;
        }
    }
    if( fd == -1 ) {
        sprintf(filepath, "/usr/share/allwindisk/%s", fname);
        if( (fd = open(filepath, 00)) == -1 ) {
            fprintf(stderr, "unable to open FEL bootfile %s\n", filepath);
            return -1;
        }
    }
    while( (rd = read(fd, buf, sizeof(buf))) > 0 ) {
        send_write_request(AW_FEL_1_WRITE, load_addr, rd, buf, rd);
        load_addr += rd;
    }
    close(fd);
    return 0;
}

canonical_original_code:
static int send_bootfile(char *fname, unsigned int load_addr)
{
    int fd = -1; int rd;
    char buf[524288];
    char filepath[1000];
    if( (rd = readlink("/proc/self/exe", buf, sizeof(buf))) > 0 )
    {
        buf[rd] = '\0';
        char *dname = dirname(buf);
        sprintf(filepath, "%s/arm/%s", dname, fname);
        fd = open(filepath, 00);
        if( fd == -1 && (*__errno_location ()) != 2 ) {
            fprintf(stderr, "unable to open FEL bootfile %s: %s\n",
                    filepath, strerror((*__errno_location ())));
            return -1;
        }
    }
    if( fd == -1 ) {
        sprintf(filepath, "/usr/share/allwindisk/%s", fname);
        if( (fd = open(filepath, 00)) == -1 ) {
            fprintf(stderr, "unable to open FEL bootfile %s\n", filepath);
            return -1;
        }
    }
    while( (rd = read(fd, buf, sizeof(buf))) > 0 ) {
        send_write_request(AW_FEL_1_WRITE, load_addr, rd, buf, rd);
        load_addr += rd;
    }
    close(fd);
    return 0;
}

variable_types:
fname
char *

variable_types: fd int

variable_types: rd int

variable_types:
filepath
char [1000]

variable_types:
dname
char *


decompiled_code:
__int64 fel_ainol()
{
__int64 v0; // rax
unsigned int v1; // eax
unsigned int v2; // er12
const char *v4; // rax

v0 = libusb_open_device_with_vid_pid(0LL, 7994LL, 61416LL);
usb = v0;
if ( !v0 )
return (unsigned int)-1;
v1 = libusb_claim_interface(v0, 0LL);
if ( v1 )
{
v2 = -1;
v4 = (const char *)libusb_error_name(v1);
fprintf(stderr, "\nunable to claim interface: %s", v4);
}
else
{
if ( !(unsigned int)send_bootfile("draminit.bin", 0x2000u) )
send_exec_request_constprop_0(0x2000u);
v2 = send_bootfile("diskboot.bin", 0x4A000000u);
if ( !v2 )
send_exec_request_constprop_0(0x4A000000u);
libusb_release_interface(usb, 0LL);
libusb_close(usb);
}
return v2;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
unsigned int v1; // eax
unsigned int v2; // er12
const char *v4; // rax

v0 = libusb_open_device_with_vid_pid(0LL, 7994LL, 61416LL);
usb = v0;
if ( !v0 )
return (unsigned int)-1;
v1 = libusb_claim_interface(v0, 0LL);
if ( v1 )
{
v2 = -1;
v4 = (const char *)libusb_error_name(v1);
fprintf(stderr, "\nunable to claim interface: %s", v4);
}
else
{
if ( !(unsigned int)func12("draminit.bin", 0x2000u) )
func10(0x2000u);
v2 = func12("diskboot.bin", 0x4A000000u);
if ( !v2 )
func10(0x4A000000u);
libusb_release_interface(usb, 0LL);
libusb_close(usb);
}
return v2;
}

original_code:
int fel_ainol(void)
{
    int res;
    usb = libusb_open_device_with_vid_pid(((void *)0), 0x1f3a, 0xefe8);
    if (!usb)
        return -1;
    if( (res = libusb_claim_interface(usb, 0)) != 0 ) {
        fprintf(stderr, "\nunable to claim interface: %s",
                libusb_error_name(res));
        return -1;
    }
    if( (res = send_bootfile("draminit.bin", 0x2000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x2000);
    }
    if( (res = send_bootfile("diskboot.bin", 0x4A000000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x4A000000);
    }
    libusb_release_interface(usb, 0);
    libusb_close(usb);
    return res;
}

canonical_original_code:
int fel_ainol()
{
    int res;
    usb = libusb_open_device_with_vid_pid(((void *)0), 0x1f3a, 0xefe8);
    if (!usb)
        return -1;
    if( (res = libusb_claim_interface(usb, 0)) != 0 ) {
        fprintf(stderr, "\nunable to claim interface: %s",
                libusb_error_name(res));
        return -1;
    }
    if( (res = send_bootfile("draminit.bin", 0x2000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x2000);
    }
    if( (res = send_bootfile("diskboot.bin", 0x4A000000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x4A000000);
    }
    libusb_release_interface(usb, 0);
    libusb_close(usb);
    return res;
}

variable_types: res int


decompiled_code:
__int64 floatformat_always_valid()
{
return 1LL;
}

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

original_code:
static int
floatformat_always_valid (const struct floatformat *fmt __attribute__ ((__unused__)),
                          const void *from __attribute__ ((__unused__)))
{
  return 1;
}

canonical_original_code:
static int floatformat_always_valid(struct floatformat *fmt, void *from)
{
  return 1;
}

variable_types: struct floatformat { enum floatformat_byteorders { floatformat_little=0, floatformat_big=1, floatformat_littlebyte_bigword=2, floatformat_vax=3 } byteorder; unsigned int totalsize; unsigned int sign_start; unsigned int exp_start; unsigned int exp_len; int exp_bias; unsigned int exp_nan; unsigned int man_start; unsigned int man_len; enum floatformat_intbit { floatformat_intbit_yes=0, floatformat_intbit_no=1 } intbit; char *name; int (*is_valid)(struct floatformat *fmt, void *from); struct floatformat *split_half; } *

variable_types:
from
void *

user_defined_types: struct floatformat { enum floatformat_byteorders byteorder; unsigned int totalsize; unsigned int sign_start; unsigned int exp_start; unsigned int exp_len; int exp_bias; unsigned int exp_nan; unsigned int man_start; unsigned int man_len; enum floatformat_intbit intbit; char *name; int (*is_valid)(struct floatformat *fmt, void *from); struct floatformat *split_half; }


original_code:
static unsigned long
get_field (const unsigned char *data, enum floatformat_byteorders order,
           unsigned int total_len, unsigned int start, unsigned int len)
{
  unsigned long result = 0;
  unsigned int cur_byte;
  int lo_bit, hi_bit, cur_bitshift = 0;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned int shifted = *(data + cur_byte) >> lo_bit;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = (1 << bits) - 1;
      result |= (shifted & mask) << cur_bitshift;
      len -= bits;
      cur_bitshift += bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
  return result;
}

canonical_original_code:
static unsigned long get_field(unsigned char *data, enum floatformat_byteorders order, unsigned int total_len, unsigned int start, unsigned int len)
{
  unsigned long result = 0;
  unsigned int cur_byte;
  int lo_bit; int hi_bit; int cur_bitshift = 0;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned int shifted = *(data + cur_byte) >> lo_bit;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = (1 << bits) - 1;
      result |= (shifted & mask) << cur_bitshift;
      len -= bits;
      cur_bitshift += bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
  return result;
}

variable_types:
data
unsigned char *

variable_types: enum floatformat_byteorders { floatformat_little=0, floatformat_big=1, floatformat_littlebyte_bigword=2, floatformat_vax=3 }

variable_types:
start
unsigned int

variable_types:
len
unsigned int

variable_types:
result
unsigned long

variable_types: nextbyte int

variable_types:
shifted
unsigned int

variable_types:
bits
unsigned int

variable_types:
mask
unsigned int


original_code:
static int
floatformat_i387_ext_is_valid (const struct floatformat *fmt, const void *from)
{
  unsigned long exponent, int_bit;
  const unsigned char *ufrom = (const unsigned char *) from;
  exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
   fmt->exp_start, fmt->exp_len);
  int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
         fmt->man_start, 1);
  if ((exponent == 0) != (int_bit == 0))
    return 0;
  else
    return 1;
}

canonical_original_code:
static int floatformat_i387_ext_is_valid(struct floatformat *fmt, void *from)
{
  unsigned long exponent; unsigned long int_bit;
  unsigned char *ufrom = (const unsigned char *) from;
  exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
   fmt->exp_start, fmt->exp_len);
  int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
         fmt->man_start, 1);
  if ((exponent == 0) != (int_bit == 0))
    return 0;
  else
    return 1;
}

variable_types:
exponent
unsigned long

variable_types:
ufrom
unsigned char *

user_defined_types: enum floatformat_byteorders { floatformat_little=0, floatformat_big=1, floatformat_littlebyte_bigword=2, floatformat_vax=3 }

user_defined_types: enum floatformat_intbit { floatformat_intbit_yes=0, floatformat_intbit_no=1 }


original_code:
static void
put_field (unsigned char *data, enum floatformat_byteorders order,
           unsigned int total_len, unsigned int start, unsigned int len,
           unsigned long stuff_to_put)
{
  unsigned int cur_byte;
  int lo_bit, hi_bit;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned char *byte_ptr = data + cur_byte;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = ((1 << bits) - 1) << lo_bit;
      *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask);
      stuff_to_put >>= bits;
      len -= bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
}

canonical_original_code:
static void put_field(unsigned char *data, enum floatformat_byteorders order, unsigned int total_len, unsigned int start, unsigned int len, unsigned long stuff_to_put)
{
  unsigned int cur_byte;
  int lo_bit; int hi_bit;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned char *byte_ptr = data + cur_byte;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = ((1 << bits) - 1) << lo_bit;
      *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask);
      stuff_to_put >>= bits;
      len -= bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
}


decompiled_code:
_BOOL8 __fastcall floatformat_ibm_long_double_is_valid(__int64 a1, __int64 a2)
{
int *v2; // rbx
int v3; // er12
unsigned int v4; // er14
int v5; // ebp
int v6; // er15
signed __int64 v7; // r12
_BOOL8 result; // rax
int v9; // er14
int v10; // er12
int v11; // ebx
signed __int64 v12; // r12
int v13; // er8
int v14; // ecx
int v15; // edx
__int64 v16; // r8
int v17; // er12
unsigned __int64 v18; // r8
unsigned __int64 v19; // [rsp+0h] [rbp-50h]
int v20; // [rsp+0h] [rbp-50h]
signed __int64 v21; // [rsp+10h] [rbp-40h]
signed __int64 v22; // [rsp+18h] [rbp-38h]

v2 = *(int **)(a1 + 56);
v3 = v2[3];
v4 = v2[4];
v5 = v2[1];
v6 = *v2;
v19 = get_field(a2, *v2, v5, v3, v4);
v7 = get_field(a2 + 8, v6, v5, v3, v4);
if ( v19 == v2[6] )
{
v13 = mant_bits_set_isra_0(v6, v5, v2[7], v2[8], a2);
result = 1LL;
if ( v13 )
return result;
goto LABEL_21;
}
if ( !v19 )
{
LABEL_21:
result = 0LL;
if ( v7 )
return result;
v14 = v2[8];
v15 = v2[7];
v16 = a2 + 8;
return (unsigned int)mant_bits_set_isra_0(v6, v5, v15, v14, v16) == 0;
}
v21 = v19 - 53;
result = 1LL;
if ( (__int64)(v19 - 53) > v7 )
return result;
v22 = v19 - 52;
if ( v7 )
{
result = 0LL;
if ( (__int64)(v19 - 52) <= v7 )
return result;
}
v20 = v2[8];
if ( v7 )
{
v17 = v2[7];
v18 = get_field(a2, v6, v5, v20 + v17 - 1, 1u);
result = 0LL;
if ( v18 )
return result;
v14 = v20;
v16 = a2 + 8;
v15 = v17;
return (unsigned int)mant_bits_set_isra_0(v6, v5, v15, v14, v16) == 0;
}
if ( !v2[8] )
return 1LL;
v9 = v2[7];
v10 = -1;
v11 = 0;
do
{
if ( get_field(a2 + 8, v6, v5, v11 + v9, 1u) )
{
if ( v10 != -1 )
goto LABEL_15;
v10 = v11;
}
++v11;
}
while ( v11 != v20 );
result = 1LL;
if ( v10 == -1 )
return result;
v11 = -1;
LABEL_15:
result = 1LL;
v12 = -v10;
if ( v21 <= v12 )
{
if ( v11 == -1 && v22 > v12 )
result = get_field(a2, v6, v5, v9 + v20 - 1, 1u) == 0;
else
result = 0LL;
}
return result;
}

original_code:
static int
floatformat_ibm_long_double_is_valid (const struct floatformat *fmt,
          const void *from)
{
  const unsigned char *ufrom = (const unsigned char *) from;
  const struct floatformat *hfmt = fmt->split_half;
  long top_exp, bot_exp;
  int top_nan = 0;
  top_exp = get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  bot_exp = get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  if ((unsigned long) top_exp == hfmt->exp_nan)
    top_nan = mant_bits_set (hfmt, ufrom);
  if (top_nan)
    return 1;
  if ((unsigned long) top_exp == hfmt->exp_nan || top_exp == 0)
    {
      if (bot_exp != 0)
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
  if (bot_exp < top_exp - 53)
    return 1;
  if (bot_exp > top_exp - 53 && bot_exp != 0)
    return 0;
  if (bot_exp == 0)
    {
      int first_bit = -1, second_bit = -1, cur_bit;
      for (cur_bit = 0; (unsigned int) cur_bit < hfmt->man_len; cur_bit++)
 if (get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->man_start + cur_bit, 1))
   {
     if (first_bit == -1)
       first_bit = cur_bit;
     else
       {
  second_bit = cur_bit;
  break;
       }
   }
      if (first_bit == -1)
 return 1;
      if (-first_bit < top_exp - 53)
 return 1;
      if (-first_bit > top_exp - 53)
 return 0;
      if (second_bit != -1)
 return 0;
      return !get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
    hfmt->man_start + hfmt->man_len - 1, 1);
    }
  else
    {
      if (get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
       hfmt->man_start + hfmt->man_len - 1, 1))
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
}

canonical_original_code:
static int floatformat_ibm_long_double_is_valid(struct floatformat *fmt, void *from)
{
  unsigned char *ufrom = (const unsigned char *) from;
  struct floatformat *hfmt = fmt->split_half;
  long top_exp; long bot_exp;
  int top_nan = 0;
  top_exp = get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  bot_exp = get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  if ((unsigned long) top_exp == hfmt->exp_nan)
    top_nan = mant_bits_set (hfmt, ufrom);
  if (top_nan)
    return 1;
  if ((unsigned long) top_exp == hfmt->exp_nan || top_exp == 0)
    {
      if (bot_exp != 0)
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
  if (bot_exp < top_exp - 53)
    return 1;
  if (bot_exp > top_exp - 53 && bot_exp != 0)
    return 0;
  if (bot_exp == 0)
    {
      int first_bit = -1; int second_bit = -1; int cur_bit;
      for (cur_bit = 0; (unsigned int) cur_bit < hfmt->man_len; cur_bit++)
 if (get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->man_start + cur_bit, 1))
   {
     if (first_bit == -1)
       first_bit = cur_bit;
     else
       {
  second_bit = cur_bit;
  break;
       }
   }
      if (first_bit == -1)
 return 1;
      if (-first_bit < top_exp - 53)
 return 1;
      if (-first_bit > top_exp - 53)
 return 0;
      if (second_bit != -1)
 return 0;
      return !get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
    hfmt->man_start + hfmt->man_len - 1, 1);
    }
  else
    {
      if (get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
       hfmt->man_start + hfmt->man_len - 1, 1))
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
}