main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
signed __int64 v5; // rax
_QWORD *v6; // r12
_QWORD *v7; // r13
__int64 v8; // r12
int v9; // er14
char v10; // al
_QWORD *v11; // r14
_QWORD *v12; // r14
void **v13; // r12
char *v15; // rsi
int *v16; // rax
int v17; // [rsp+Ch] [rbp-13Ch]
char buf[312]; // [rsp+10h] [rbp-138h] BYREF

if ( !getcwd(buf, 0x100uLL) )
{
v16 = _errno_location();
fail("Could not get current directory!", &unk_2A7, (unsigned int)*v16);
}
v17 = 90;
v3 = 10;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "s:t:r:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 's':
v5 = stpcpy(buf, optarg) - buf;
if ( v5 == 2 && buf[1] == 58 )
{
sprintf(buf, "%s/", buf);
}
else if ( *((_BYTE *)&v17 + v5 + 3) == 47 )
{
*((_BYTE *)&v17 + v5 + 3) = 0;
}
break;
case 't':
v17 = atoi(optarg);
break;
case 'r':
v3 = atoi(optarg);
break;
default:
usage(*argv);
}
}
printf("Source: %s\n", buf);
printf("Range: %i KB, Triggervalue: %i\n", (unsigned int)v3, (unsigned int)v17);
printf("Press enter to continue or CTRL-C to stop.");
fflush(stdout);
while ( getc(stdin) != 10 )
;
v6 = (_QWORD *)recurse(buf, 0LL);
puts("Done scanning");
fflush(stdout);
if ( !v6 )
fail("No music found at ", buf, 0LL);
do
{
v7 = v6;
v6 = (_QWORD *)*v6;
}
while ( v6 );
v8 = v7[197];
if ( v8 )
{
while ( 1 )
{
if ( (int)abs32(v7[98] - *(_DWORD *)(v8 + 784)) < v3 )
{
v9 = fncmp(v7 + 34, v8 + 272);
if ( v17 <= v9 )
{
printf("(1) %s/%s\n", (const char *)v7 + 16, (const char *)v7 + 272);
printf("(2) %s/%s\n", (const char *)(v8 + 16), (const char *)(v8 + 272));
printf("(%i/%i) Delete (1/2) or keep? ", (unsigned int)v9, abs32(v7[98] - *(_DWORD *)(v8 + 784)));
fflush(stdout);
LABEL_27:
while ( 1 )
{
v10 = getchar();
if ( v10 == 10 )
break;
while ( v10 != 49 )
{
if ( v10 != 50 )
goto LABEL_27;
v11 = *(_QWORD **)v8;
if ( remtitle(v8) )
{
fail("Could not delete file!", v8 + 272, 0xFFFFFFFFLL);
if ( v11 != v7 )
goto LABEL_32;
}
else if ( v11 != v7 )
{
goto LABEL_32;
}
v11 = (_QWORD *)v11[197];
LABEL_32:
if ( !v11 )
v11 = v7;
v8 = (__int64)v11;
v10 = getchar();
if ( v10 == 10 )
goto LABEL_23;
}
v12 = (_QWORD *)*v7;
if ( *v7 )
{
if ( remtitle((__int64)v7) )
{
v15 = (char *)(v7 + 34);
v7 = v12;
fail("Could not delete file!", v15, 0xFFFFFFFFLL);
}
else
{
v7 = v12;
}
}
else
{
fail("Sorry, can't delete first title in list...", &unk_2A7, 0xFFFFFFFFLL);
}
}
}
}
LABEL_23:
v8 = *(_QWORD *)(v8 + 1576);
if ( !v8 )
{
v13 = (void **)v7[197];
if ( v13 )
{
v7 = (_QWORD *)v7[197];
free(*v13);
*v13 = 0LL;
}
activity("Checking");
v8 = v7[197];
if ( !v8 )
break;
}
}
}
free(v7);
puts("Done.");
fflush(stdout);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
signed __int64 v5; // rax
_QWORD *v6; // r12
_QWORD *v7; // r13
__int64 v8; // r12
int v9; // er14
char v10; // al
_QWORD *v11; // r14
_QWORD *v12; // r14
void **v13; // r12
char *v15; // rsi
int *v16; // rax
int v17; // [rsp+Ch] [rbp-13Ch]
char buf[312]; // [rsp+10h] [rbp-138h] BYREF

if ( !getcwd(buf, 0x100uLL) )
{
v16 = _errno_location();
fail("Could not get current directory!", &unk_2A7, (unsigned int)*v16);
}
v17 = 90;
v3 = 10;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "s:t:r:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 's':
v5 = stpcpy(buf, optarg) - buf;
if ( v5 == 2 && buf[1] == 58 )
{
sprintf(buf, "%s/", buf);
}
else if ( *((_BYTE *)&v17 + v5 + 3) == 47 )
{
*((_BYTE *)&v17 + v5 + 3) = 0;
}
break;
case 't':
v17 = atoi(optarg);
break;
case 'r':
v3 = atoi(optarg);
break;
default:
func0(*argv);
}
}
printf("Source: %s\n", buf);
printf("Range: %i KB, Triggervalue: %i\n", (unsigned int)v3, (unsigned int)v17);
printf("Press enter to continue or CTRL-C to stop.");
fflush(stdout);
while ( getc(stdin) != 10 )
;
v6 = (_QWORD *)recurse(buf, 0LL);
puts("Done scanning");
fflush(stdout);
if ( !v6 )
fail("No music found at ", buf, 0LL);
do
{
v7 = v6;
v6 = (_QWORD *)*v6;
}
while ( v6 );
v8 = v7[197];
if ( v8 )
{
while ( 1 )
{
if ( (int)abs32(v7[98] - *(_DWORD *)(v8 + 784)) < v3 )
{
v9 = fncmp(v7 + 34, v8 + 272);
if ( v17 <= v9 )
{
printf("(1) %s/%s\n", (const char *)v7 + 16, (const char *)v7 + 272);
printf("(2) %s/%s\n", (const char *)(v8 + 16), (const char *)(v8 + 272));
printf("(%i/%i) Delete (1/2) or keep? ", (unsigned int)v9, abs32(v7[98] - *(_DWORD *)(v8 + 784)));
fflush(stdout);
LABEL_27:
while ( 1 )
{
v10 = getchar();
if ( v10 == 10 )
break;
while ( v10 != 49 )
{
if ( v10 != 50 )
goto LABEL_27;
v11 = *(_QWORD **)v8;
if ( func1(v8) )
{
fail("Could not delete file!", v8 + 272, 0xFFFFFFFFLL);
if ( v11 != v7 )
goto LABEL_32;
}
else if ( v11 != v7 )
{
goto LABEL_32;
}
v11 = (_QWORD *)v11[197];
LABEL_32:
if ( !v11 )
v11 = v7;
v8 = (__int64)v11;
v10 = getchar();
if ( v10 == 10 )
goto LABEL_23;
}
v12 = (_QWORD *)*v7;
if ( *v7 )
{
if ( func1((__int64)v7) )
{
v15 = (char *)(v7 + 34);
v7 = v12;
fail("Could not delete file!", v15, 0xFFFFFFFFLL);
}
else
{
v7 = v12;
}
}
else
{
fail("Sorry, can't delete first title in list...", &unk_2A7, 0xFFFFFFFFLL);
}
}
}
}
LABEL_23:
v8 = *(_QWORD *)(v8 + 1576);
if ( !v8 )
{
v13 = (void **)v7[197];
if ( v13 )
{
v7 = (_QWORD *)v7[197];
free(*v13);
*v13 = 0LL;
}
activity("Checking");
v8 = v7[197];
if ( !v8 )
break;
}
}
}
free(v7);
puts("Done.");
fflush(stdout);
return 0;
}

original_code:
int main( int argc, char **argv ){
 int result=0;
 int trigger=90;
 int range=10;
 char curdir[256];
 char c;
 struct entry_t *runner, *buff;
 struct entry_t *root=((void *)0);
 if( ((void *)0) == getcwd( curdir, 256 ) )
  fail( "Could not get current directory!", "", (*__errno_location ()));
 while( ( c = getopt( argc, argv, "s:t:r:" ) ) != -1 ) {
  switch( c ) {
  case 's':
   strcpy( curdir, optarg );
   if( ( strlen(curdir) == 2 ) && ( curdir[1] == ':' ) )
    sprintf( curdir, "%s/", curdir );
   else if ( curdir[ strlen( curdir ) -1 ] == '/' )
    curdir[ strlen( curdir ) -1 ] = 0;
   break;
  case 't':
   trigger = atoi( optarg );
   break;
  case 'r':
   range = atoi( optarg );
   break;
  default:
   usage( argv[0] );
   break;
  }
 }
 printf( "Source: %s\n", curdir );
 printf( "Range: %i KB, Triggervalue: %i\n", range, trigger );
 printf( "Press enter to continue or CTRL-C to stop." );
 fflush( stdout );
 while(getc(stdin)!=10);
 root=recurse( curdir, root );
 printf("Done scanning\n");
 fflush( stdout );
 if( ((void *)0) == root ) fail( "No music found at ", curdir, 0 );
 while(((void *)0) != root->prev) root=root->prev;
 while( ((void *)0) != root->next ){
  runner=root->next;
  while( ((void *)0) != runner ){
   if( abs( root->size - runner->size ) < range ){
    result=fncmp( root->name, runner->name );
    if( result >= trigger ){
     printf( "(1) %s/%s\n", root->path, root->name );
     printf( "(2) %s/%s\n", runner->path, runner->name );
     printf( "(%i/%i) Delete (1/2) or keep? ", result, abs( root->size - runner->size ) ); fflush(stdout);
     c=getchar();
     while(c!=10){
      switch(c){
      case '1':
       if( root->prev == ((void *)0) ) fail( "Sorry, can't delete first title in list...", "", -1 );
       else{
        buff=root->prev;
        if(remtitle( root )) fail( "Could not delete file!", root->name, -1 );
        root=buff;
       }
       break;
      case '2':
       buff=runner->prev;
       if(remtitle( runner )) fail( "Could not delete file!", runner->name, -1 );
       runner=buff;
       if( runner == root ) runner=runner->next;
       if( runner == ((void *)0) ) runner=root;
       break;
      }
      c=getchar();
     }
    }
   }
   runner=runner->next;
  }
  if( root->next != ((void *)0) ){
   root=root->next;
   free( root->prev );
   root->prev=((void *)0);
  }
  activity("Checking");
 }
 free( root );
 printf("Done.\n");
 fflush( stdout );
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 int result = 0;
 int trigger = 90;
 int range = 10;
 char curdir[256];
 char c;
 struct entry_t *runner; struct entry_t *buff;
 struct entry_t *root = ((void *)0);
 if( ((void *)0) == getcwd( curdir, 256 ) )
  fail( "Could not get current directory!", "", (*__errno_location ()));
 while( ( c = getopt( argc, argv, "s:t:r:" ) ) != -1 ) {
  switch( c ) {
  case 's':
   strcpy( curdir, optarg );
   if( ( strlen(curdir) == 2 ) && ( curdir[1] == ':' ) )
    sprintf( curdir, "%s/", curdir );
   else if ( curdir[ strlen( curdir ) -1 ] == '/' )
    curdir[ strlen( curdir ) -1 ] = 0;
   break;
  case 't':
   trigger = atoi( optarg );
   break;
  case 'r':
   range = atoi( optarg );
   break;
  default:
   usage( argv[0] );
   break;
  }
 }
 printf( "Source: %s\n", curdir );
 printf( "Range: %i KB, Triggervalue: %i\n", range, trigger );
 printf( "Press enter to continue or CTRL-C to stop." );
 fflush( stdout );
 while(getc(stdin)!=10);
 root=recurse( curdir, root );
 printf("Done scanning\n");
 fflush( stdout );
 if( ((void *)0) == root ) fail( "No music found at ", curdir, 0 );
 while(((void *)0) != root->prev) root=root->prev;
 while( ((void *)0) != root->next ){
  runner=root->next;
  while( ((void *)0) != runner ){
   if( abs( root->size - runner->size ) < range ){
    result=fncmp( root->name, runner->name );
    if( result >= trigger ){
     printf( "(1) %s/%s\n", root->path, root->name );
     printf( "(2) %s/%s\n", runner->path, runner->name );
     printf( "(%i/%i) Delete (1/2) or keep? ", result, abs( root->size - runner->size ) ); fflush(stdout);
     c=getchar();
     while(c!=10){
      switch(c){
      case '1':
       if( root->prev == ((void *)0) ) fail( "Sorry, can't delete first title in list...", "", -1 );
       else{
        buff=root->prev;
        if(remtitle( root )) fail( "Could not delete file!", root->name, -1 );
        root=buff;
       }
       break;
      case '2':
       buff=runner->prev;
       if(remtitle( runner )) fail( "Could not delete file!", runner->name, -1 );
       runner=buff;
       if( runner == root ) runner=runner->next;
       if( runner == ((void *)0) ) runner=root;
       break;
      }
      c=getchar();
     }
    }
   }
   runner=runner->next;
  }
  if( root->next != ((void *)0) ){
   root=root->next;
   free( root->prev );
   root->prev=((void *)0);
  }
  activity("Checking");
 }
 free( root );
 printf("Done.\n");
 fflush( stdout );
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: result int

variable_types: trigger int

variable_types: range int

variable_types: struct entry_t { struct entry_t *prev; unsigned long key; char path[256]; char name[256]; char display[256]; unsigned long size; char artist[256]; int rating; char title[256]; char album[256]; int length; unsigned long played; struct entry_t *next; } *


repo: fpgaminer/strong-arm

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

result = test_finite_field();
if ( !result )
{
result = test_ecdsa();
if ( !result )
{
result = test_keychain();
if ( !result )
{
result = test_ripemd160();
if ( !result )
{
result = test_sha256();
if ( !result )
{
result = test_base58();
if ( !result )
{
result = test_random();
if ( !result )
{
result = test_hmac();
if ( !result )
{
result = test_pbkdf2();
if ( !result )
{
result = test_drbg();
if ( !result )
{
result = test_aes();
if ( !result )
result = test_threefish();
}
}
}
}
}
}
}
}
}
}
return result;
}

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

result = test_finite_field();
if ( !result )
{
result = test_ecdsa();
if ( !result )
{
result = test_keychain();
if ( !result )
{
result = test_ripemd160();
if ( !result )
{
result = test_sha256();
if ( !result )
{
result = test_base58();
if ( !result )
{
result = test_random();
if ( !result )
{
result = test_hmac();
if ( !result )
{
result = test_pbkdf2();
if ( !result )
{
result = test_drbg();
if ( !result )
{
result = test_aes();
if ( !result )
result = test_threefish();
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
static char *all_tests ()
{
 char *msg;
 if ((msg = test_finite_field ())) return msg;
 if ((msg = test_ecdsa ())) return msg;
 if ((msg = test_keychain ())) return msg;
 if ((msg = test_ripemd160 ())) return msg;
 if ((msg = test_sha256 ())) return msg;
 if ((msg = test_base58 ())) return msg;
 if ((msg = test_random ())) return msg;
 if ((msg = test_hmac ())) return msg;
 if ((msg = test_pbkdf2())) return msg;
 if ((msg = test_drbg ())) return msg;
 if ((msg = test_aes ())) return msg;
 if ((msg = test_threefish ())) return msg;
 return 0;
}

canonical_original_code:
static char *all_tests()
{
 char *msg;
 if ((msg = test_finite_field ())) return msg;
 if ((msg = test_ecdsa ())) return msg;
 if ((msg = test_keychain ())) return msg;
 if ((msg = test_ripemd160 ())) return msg;
 if ((msg = test_sha256 ())) return msg;
 if ((msg = test_base58 ())) return msg;
 if ((msg = test_random ())) return msg;
 if ((msg = test_hmac ())) return msg;
 if ((msg = test_pbkdf2())) return msg;
 if ((msg = test_drbg ())) return msg;
 if ((msg = test_aes ())) return msg;
 if ((msg = test_threefish ())) return msg;
 return 0;
}

variable_types:
msg
char *

return_type: char *


canonical_name: main

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

strongarm_init(argc, argv, envp);
v3 = (const char *)all_tests();
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

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

strongarm_init(argc, argv, envp);
v3 = (const char *)func0();
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

original_code:
int main (void)
{
 strongarm_init ();
 char *result = all_tests ();
 if (result != 0)
  printf ("%s\n", result);
 else
  printf ("ALL TESTS PASSED\n");
 printf ("Tests run: %d\n", tests_run);
 return result != 0;
}

canonical_original_code:
int main()
{
 strongarm_init ();
 char *result = all_tests ();
 if (result != 0)
  printf ("%s\n", result);
 else
  printf ("ALL TESTS PASSED\n");
 printf ("Tests run: %d\n", tests_run);
 return result != 0;
}

variable_types:
result
char *

return_type: int


decompiled_code:
__int64 __fastcall ec_double(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 result; // rax
_BYTE v4[32]; // [rsp+0h] [rbp-C8h] BYREF
char v5[32]; // [rsp+20h] [rbp-A8h] BYREF
char v6[32]; // [rsp+40h] [rbp-88h] BYREF
char v7[32]; // [rsp+60h] [rbp-68h] BYREF
char v8[72]; // [rsp+80h] [rbp-48h] BYREF

v2 = a2 + 32;
if ( (unsigned __int8)ff_is_zero(a2) && (unsigned __int8)ff_is_zero(a2 + 32) )
{
ff_zero(a1);
result = ff_zero(a1 + 32);
}
else
{
ff_mul(v5, a2, a2, &ec_p);
ff_add(v6, v5, v5, &ec_p);
ff_add(v5, v6, v5, &ec_p);
ff_add(v6, v2, v2, &ec_p);
ff_inv(v6, v6, &ec_p);
ff_mul(v4, v5, v6, &ec_p);
ff_mul(v5, v4, v4, &ec_p);
ff_sub(v7, v5, a2, &ec_p);
ff_sub(v7, v7, a2, &ec_p);
ff_sub(v5, a2, v7, &ec_p);
ff_mul(v8, v4, v5, &ec_p);
ff_sub(v8, v8, v2, &ec_p);
ff_copy(a1, v7);
result = ff_copy(a1 + 32, v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 result; // rax
_BYTE v4[32]; // [rsp+0h] [rbp-C8h] BYREF
char v5[32]; // [rsp+20h] [rbp-A8h] BYREF
char v6[32]; // [rsp+40h] [rbp-88h] BYREF
char v7[32]; // [rsp+60h] [rbp-68h] BYREF
char v8[72]; // [rsp+80h] [rbp-48h] BYREF

v2 = a2 + 32;
if ( (unsigned __int8)ff_is_zero(a2) && (unsigned __int8)ff_is_zero(a2 + 32) )
{
ff_zero(a1);
result = ff_zero(a1 + 32);
}
else
{
ff_mul(v5, a2, a2, &ec_p);
ff_add(v6, v5, v5, &ec_p);
ff_add(v5, v6, v5, &ec_p);
ff_add(v6, v2, v2, &ec_p);
ff_inv(v6, v6, &ec_p);
ff_mul(v4, v5, v6, &ec_p);
ff_mul(v5, v4, v4, &ec_p);
ff_sub(v7, v5, a2, &ec_p);
ff_sub(v7, v7, a2, &ec_p);
ff_sub(v5, a2, v7, &ec_p);
ff_mul(v8, v4, v5, &ec_p);
ff_sub(v8, v8, v2, &ec_p);
ff_copy(a1, v7);
result = ff_copy(a1 + 32, v8);
}
return result;
}

original_code:
void ec_double (EC_POINT *const out, EC_POINT const *const P)
{
 FF_NUM slope, tmp, tmp1;
 FF_NUM x3, y3;
 if ((ff_is_zero (&(P->x))) && (ff_is_zero (&(P->y))))
 {
  ff_zero (&(out->x));
  ff_zero (&(out->y));
  return;
 }
 ff_mul (&tmp, &(P->x), &(P->x), &ec_p);
 ff_add (&tmp1, &tmp, &tmp, &ec_p);
 ff_add (&tmp, &tmp1, &tmp, &ec_p);
 ff_add (&tmp1, &(P->y), &(P->y), &ec_p);
 ff_inv (&tmp1, &tmp1, &ec_p);
 ff_mul (&slope, &tmp, &tmp1, &ec_p);
 ff_mul (&tmp, &slope, &slope, &ec_p);
 ff_sub (&x3, &tmp, &(P->x), &ec_p);
 ff_sub (&x3, &x3, &(P->x), &ec_p);
 ff_sub (&tmp, &(P->x), &x3, &ec_p);
 ff_mul (&y3, &slope, &tmp, &ec_p);
 ff_sub (&y3, &y3, &(P->y), &ec_p);
 ff_copy (&(out->x), &x3);
 ff_copy (&(out->y), &y3);
}

canonical_original_code:
void ec_double(struct EC_POINT *out, struct EC_POINT *P)
{
 struct FF_NUM slope; struct FF_NUM tmp; struct FF_NUM tmp1;
 struct FF_NUM x3; struct FF_NUM y3;
 if ((ff_is_zero (&(P->x))) && (ff_is_zero (&(P->y))))
 {
  ff_zero (&(out->x));
  ff_zero (&(out->y));
  return;
 }
 ff_mul (&tmp, &(P->x), &(P->x), &ec_p);
 ff_add (&tmp1, &tmp, &tmp, &ec_p);
 ff_add (&tmp, &tmp1, &tmp, &ec_p);
 ff_add (&tmp1, &(P->y), &(P->y), &ec_p);
 ff_inv (&tmp1, &tmp1, &ec_p);
 ff_mul (&slope, &tmp, &tmp1, &ec_p);
 ff_mul (&tmp, &slope, &slope, &ec_p);
 ff_sub (&x3, &tmp, &(P->x), &ec_p);
 ff_sub (&x3, &x3, &(P->x), &ec_p);
 ff_sub (&tmp, &(P->x), &x3, &ec_p);
 ff_mul (&y3, &slope, &tmp, &ec_p);
 ff_sub (&y3, &y3, &(P->y), &ec_p);
 ff_copy (&(out->x), &x3);
 ff_copy (&(out->y), &y3);
}

variable_types: struct EC_POINT { struct FF_NUM { unsigned int z[8]; } x; } *

variable_types:
P
struct EC_POINT *

variable_types:
slope
struct FF_NUM { unsigned int z[8]; }

variable_types:
tmp
struct FF_NUM { unsigned int z[8]; }

return_type: void

user_defined_types:
struct FF_NUM { unsigned int z[8]; }
struct EC_POINT { struct FF_NUM x; }


decompiled_code:
__int64 __fastcall ec_add(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r15
__int64 v5; // r13
__int64 result; // rax
_BYTE v7[32]; // [rsp+0h] [rbp-C8h] BYREF
char v8[32]; // [rsp+20h] [rbp-A8h] BYREF
char v9[32]; // [rsp+40h] [rbp-88h] BYREF
char v10[32]; // [rsp+60h] [rbp-68h] BYREF
char v11[72]; // [rsp+80h] [rbp-48h] BYREF

v4 = a3 + 32;
v5 = a2 + 32;
if ( (unsigned __int8)ff_is_zero(a2) && (unsigned __int8)ff_is_zero(a2 + 32) )
{
ff_copy(a1, a3);
result = ff_copy(a1 + 32, v4);
}
else if ( (unsigned __int8)ff_is_zero(a3) && (unsigned __int8)ff_is_zero(v4) )
{
ff_copy(a1, a2);
result = ff_copy(a1 + 32, v5);
}
else if ( (unsigned int)ff_compare(a2, a3) )
{
ff_sub(v8, v4, v5, &ec_p);
ff_sub(v9, a3, a2, &ec_p);
ff_inv(v9, v9, &ec_p);
ff_mul(v7, v8, v9, &ec_p);
ff_mul(v8, v7, v7, &ec_p);
ff_sub(v10, v8, a2, &ec_p);
ff_sub(v10, v10, a3, &ec_p);
ff_sub(v8, a2, v10, &ec_p);
ff_mul(v8, v7, v8, &ec_p);
ff_sub(v11, v8, v5, &ec_p);
ff_copy(a1, v10);
result = ff_copy(a1 + 32, v11);
}
else
{
ff_add(v8, v5, v4, &ec_p);
if ( (unsigned __int8)ff_is_zero(v8) )
{
ff_zero(a1);
result = ff_zero(a1 + 32);
}
else
{
result = ec_double(a1, a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r15
__int64 v5; // r13
__int64 result; // rax
_BYTE v7[32]; // [rsp+0h] [rbp-C8h] BYREF
char v8[32]; // [rsp+20h] [rbp-A8h] BYREF
char v9[32]; // [rsp+40h] [rbp-88h] BYREF
char v10[32]; // [rsp+60h] [rbp-68h] BYREF
char v11[72]; // [rsp+80h] [rbp-48h] BYREF

v4 = a3 + 32;
v5 = a2 + 32;
if ( (unsigned __int8)ff_is_zero(a2) && (unsigned __int8)ff_is_zero(a2 + 32) )
{
ff_copy(a1, a3);
result = ff_copy(a1 + 32, v4);
}
else if ( (unsigned __int8)ff_is_zero(a3) && (unsigned __int8)ff_is_zero(v4) )
{
ff_copy(a1, a2);
result = ff_copy(a1 + 32, v5);
}
else if ( (unsigned int)ff_compare(a2, a3) )
{
ff_sub(v8, v4, v5, &ec_p);
ff_sub(v9, a3, a2, &ec_p);
ff_inv(v9, v9, &ec_p);
ff_mul(v7, v8, v9, &ec_p);
ff_mul(v8, v7, v7, &ec_p);
ff_sub(v10, v8, a2, &ec_p);
ff_sub(v10, v10, a3, &ec_p);
ff_sub(v8, a2, v10, &ec_p);
ff_mul(v8, v7, v8, &ec_p);
ff_sub(v11, v8, v5, &ec_p);
ff_copy(a1, v10);
result = ff_copy(a1 + 32, v11);
}
else
{
ff_add(v8, v5, v4, &ec_p);
if ( (unsigned __int8)ff_is_zero(v8) )
{
ff_zero(a1);
result = ff_zero(a1 + 32);
}
else
{
result = func0(a1, a1);
}
}
return result;
}

original_code:
void ec_add (EC_POINT *const out, EC_POINT const *const A, EC_POINT const *const B)
{
 FF_NUM slope, tmp, tmp1;
 FF_NUM x3, y3;
 if ((ff_is_zero (&(A->x))) && (ff_is_zero (&(A->y))))
 {
  ff_copy (&(out->x), &(B->x));
  ff_copy (&(out->y), &(B->y));
  return;
 }
 if ((ff_is_zero (&(B->x))) && (ff_is_zero (&(B->y))))
 {
  ff_copy (&(out->x), &(A->x));
  ff_copy (&(out->y), &(A->y));
  return;
 }
 if (ff_compare (&(A->x), &(B->x)) == 0)
 {
  ff_add (&tmp, &(A->y), &(B->y), &ec_p);
  if (ff_is_zero (&tmp))
  {
   ff_zero (&(out->x));
   ff_zero (&(out->y));
   return;
  }
  else
  {
   ec_double (out, out);
   return;
  }
 }
 ff_sub (&tmp, &(B->y), &(A->y), &ec_p);
 ff_sub (&tmp1, &(B->x), &(A->x), &ec_p);
 ff_inv (&tmp1, &tmp1, &ec_p);
 ff_mul (&slope, &tmp, &tmp1, &ec_p);
 ff_mul (&tmp, &slope, &slope, &ec_p);
 ff_sub (&x3, &tmp, &(A->x), &ec_p);
 ff_sub (&x3, &x3, &(B->x), &ec_p);
 ff_sub (&tmp, &(A->x), &x3, &ec_p);
 ff_mul (&tmp, &slope, &tmp, &ec_p);
 ff_sub (&y3, &tmp, &(A->y), &ec_p);
 ff_copy (&(out->x), &x3);
 ff_copy (&(out->y), &y3);
}

canonical_original_code:
void ec_add(struct EC_POINT *out, struct EC_POINT *A, struct EC_POINT *B)
{
 struct FF_NUM slope; struct FF_NUM tmp; struct FF_NUM tmp1;
 struct FF_NUM x3; struct FF_NUM y3;
 if ((ff_is_zero (&(A->x))) && (ff_is_zero (&(A->y))))
 {
  ff_copy (&(out->x), &(B->x));
  ff_copy (&(out->y), &(B->y));
  return;
 }
 if ((ff_is_zero (&(B->x))) && (ff_is_zero (&(B->y))))
 {
  ff_copy (&(out->x), &(A->x));
  ff_copy (&(out->y), &(A->y));
  return;
 }
 if (ff_compare (&(A->x), &(B->x)) == 0)
 {
  ff_add (&tmp, &(A->y), &(B->y), &ec_p);
  if (ff_is_zero (&tmp))
  {
   ff_zero (&(out->x));
   ff_zero (&(out->y));
   return;
  }
  else
  {
   ec_double (out, out);
   return;
  }
 }
 ff_sub (&tmp, &(B->y), &(A->y), &ec_p);
 ff_sub (&tmp1, &(B->x), &(A->x), &ec_p);
 ff_inv (&tmp1, &tmp1, &ec_p);
 ff_mul (&slope, &tmp, &tmp1, &ec_p);
 ff_mul (&tmp, &slope, &slope, &ec_p);
 ff_sub (&x3, &tmp, &(A->x), &ec_p);
 ff_sub (&x3, &x3, &(B->x), &ec_p);
 ff_sub (&tmp, &(A->x), &x3, &ec_p);
 ff_mul (&tmp, &slope, &tmp, &ec_p);
 ff_sub (&y3, &tmp, &(A->y), &ec_p);
 ff_copy (&(out->x), &x3);
 ff_copy (&(out->y), &y3);
}

variable_types:
A
struct EC_POINT *

variable_types:
B
struct EC_POINT *


decompiled_code:
__int64 __fastcall ec_mul(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx
int v5; // eax
_BYTE v7[32]; // [rsp+0h] [rbp-68h] BYREF
char v8[72]; // [rsp+20h] [rbp-48h] BYREF

v4 = 255;
ff_zero(v7);
ff_zero(v8);
while ( 1 )
{
ec_double((__int64)v7, (__int64)v7);
v5 = *(_DWORD *)(a2 + 4LL * (v4 >> 5));
if ( _bittest(&v5, v4) )
break;
if ( !v4 )
goto LABEL_6;
LABEL_3:
--v4;
}
ec_add((__int64)v7, (__int64)v7, a3);
if ( v4 )
goto LABEL_3;
LABEL_6:
ff_copy(a1, v7);
return ff_copy(a1 + 32, v8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx
int v5; // eax
_BYTE v7[32]; // [rsp+0h] [rbp-68h] BYREF
char v8[72]; // [rsp+20h] [rbp-48h] BYREF

v4 = 255;
ff_zero(v7);
ff_zero(v8);
while ( 1 )
{
func0((__int64)v7, (__int64)v7);
v5 = *(_DWORD *)(a2 + 4LL * (v4 >> 5));
if ( _bittest(&v5, v4) )
break;
if ( !v4 )
goto LABEL_6;
LABEL_3:
--v4;
}
func1((__int64)v7, (__int64)v7, a3);
if ( v4 )
goto LABEL_3;
LABEL_6:
ff_copy(a1, v7);
return ff_copy(a1 + 32, v8);
}

original_code:
void ec_mul (EC_POINT *const out, FF_NUM const *const k, EC_POINT const *const P)
{
 EC_POINT Q;
 ff_zero (&(Q.x));
 ff_zero (&(Q.y));
 for (uint32_t i = 255; 1; --i)
 {
  ec_double (&Q, &Q);
  if ((k->z[i>>5] >> (i&31)) & 1)
   ec_add (&Q, &Q, P);
  if (i == 0)
   break;
 }
 ff_copy (&(out->x), &(Q.x));
 ff_copy (&(out->y), &(Q.y));
}

canonical_original_code:
void ec_mul(struct EC_POINT *out, struct FF_NUM *k, struct EC_POINT *P)
{
 struct EC_POINT Q;
 ff_zero (&(Q.x));
 ff_zero (&(Q.y));
 for (unsigned int i = 255; 1; --i)
 {
  ec_double (&Q, &Q);
  if ((k->z[i>>5] >> (i&31)) & 1)
   ec_add (&Q, &Q, P);
  if (i == 0)
   break;
 }
 ff_copy (&(out->x), &(Q.x));
 ff_copy (&(out->y), &(Q.y));
}

variable_types:
k
struct FF_NUM *

variable_types: struct EC_POINT { struct FF_NUM { unsigned int z[8]; } x; }

variable_types:
i
unsigned int

user_defined_types:
struct EC_POINT { struct FF_NUM x; }
struct FF_NUM { unsigned int z[8]; }


decompiled_code:
__int64 __fastcall ec_create_key(__int64 a1, __int64 a2)
{
ff_rand(a1, &ec_n);
return ec_mul(a2, a1, (__int64)&ec_G);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
ff_rand(a1, &ec_n);
return func2(a2, a1, (__int64)&ec_G);
}

original_code:
void ec_create_key (FF_NUM *const ret_privkey, EC_POINT *const ret_pubkey)
{
 ff_rand (ret_privkey, &ec_n);
 ec_mul (ret_pubkey, ret_privkey, &ec_G);
}

canonical_original_code:
void ec_create_key(struct FF_NUM *ret_privkey, struct EC_POINT *ret_pubkey)
{
 ff_rand (ret_privkey, &ec_n);
 ec_mul (ret_pubkey, ret_privkey, &ec_G);
}


decompiled_code:
__int64 __fastcall ec_sign(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v7[32]; // [rsp+0h] [rbp-C8h] BYREF
char v8[32]; // [rsp+20h] [rbp-A8h] BYREF
char v9[32]; // [rsp+40h] [rbp-88h] BYREF
char v10[104]; // [rsp+60h] [rbp-68h] BYREF

if ( (unsigned __int8)ff_is_zero(a4) || (int)ff_compare(a4, &ec_n) >= 0 )
return 0LL;
do
{
do
{
ff_rand(v7, &ec_n);
ec_mul((__int64)v10, (__int64)v7, (__int64)&ec_G);
ff_zero(v8);
ff_add(v8, v8, v10, &ec_n);
}
while ( (unsigned __int8)ff_is_zero(v8) );
ff_inv(v7, v7, &ec_n);
ff_mul(v9, v8, a4, &ec_n);
ff_add(v9, a3, v9, &ec_n);
ff_mul(v9, v7, v9, &ec_n);
}
while ( (unsigned __int8)ff_is_zero(v9) );
ff_copy(a1, v8);
ff_copy(a2, v9);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v7[32]; // [rsp+0h] [rbp-C8h] BYREF
char v8[32]; // [rsp+20h] [rbp-A8h] BYREF
char v9[32]; // [rsp+40h] [rbp-88h] BYREF
char v10[104]; // [rsp+60h] [rbp-68h] BYREF

if ( (unsigned __int8)ff_is_zero(a4) || (int)ff_compare(a4, &ec_n) >= 0 )
return 0LL;
do
{
do
{
ff_rand(v7, &ec_n);
func2((__int64)v10, (__int64)v7, (__int64)&ec_G);
ff_zero(v8);
ff_add(v8, v8, v10, &ec_n);
}
while ( (unsigned __int8)ff_is_zero(v8) );
ff_inv(v7, v7, &ec_n);
ff_mul(v9, v8, a4, &ec_n);
ff_add(v9, a3, v9, &ec_n);
ff_mul(v9, v7, v9, &ec_n);
}
while ( (unsigned __int8)ff_is_zero(v9) );
ff_copy(a1, v8);
ff_copy(a2, v9);
return 1LL;
}

original_code:
_Bool ec_sign (FF_NUM *const out_r, FF_NUM *const out_s, FF_NUM const *const z, FF_NUM const *const d)
{
 FF_NUM k, r, s;
 EC_POINT kG;
 if ((ff_is_zero (d)) || (ff_compare (d, &ec_n) >= 0))
  return 0;
 while (1)
 {
  ff_rand (&k, &ec_n);
  ec_mul (&kG, &k, &ec_G);
  ff_zero (&r);
  ff_add (&r, &r, &(kG.x), &ec_n);
  if (ff_is_zero (&r))
   continue;
  ff_inv (&k, &k, &ec_n);
  ff_mul (&s, &r, d, &ec_n);
  ff_add (&s, z, &s, &ec_n);
  ff_mul (&s, &k, &s, &ec_n);
  if (ff_is_zero (&s))
   continue;
  break;
 }
 ff_copy (out_r, &r);
 ff_copy (out_s, &s);
 return 1;
}

canonical_original_code:
_Bool ec_sign(struct FF_NUM *out_r, struct FF_NUM *out_s, struct FF_NUM *z, struct FF_NUM *d)
{
 struct FF_NUM k; struct FF_NUM r; struct FF_NUM s;
 struct EC_POINT kG;
 if ((ff_is_zero (d)) || (ff_compare (d, &ec_n) >= 0))
  return 0;
 while (1)
 {
  ff_rand (&k, &ec_n);
  ec_mul (&kG, &k, &ec_G);
  ff_zero (&r);
  ff_add (&r, &r, &(kG.x), &ec_n);
  if (ff_is_zero (&r))
   continue;
  ff_inv (&k, &k, &ec_n);
  ff_mul (&s, &r, d, &ec_n);
  ff_add (&s, z, &s, &ec_n);
  ff_mul (&s, &k, &s, &ec_n);
  if (ff_is_zero (&s))
   continue;
  break;
 }
 ff_copy (out_r, &r);
 ff_copy (out_s, &s);
 return 1;
}

variable_types:
z
struct FF_NUM *

variable_types:
d
struct FF_NUM *

variable_types:
k
struct FF_NUM { unsigned int z[8]; }

variable_types:
r
struct FF_NUM { unsigned int z[8]; }

variable_types:
s
struct FF_NUM { unsigned int z[8]; }


decompiled_code:
bool __fastcall ec_on_curve(__int64 a1)
{
_BYTE v2[32]; // [rsp+0h] [rbp-58h] BYREF
char v3[56]; // [rsp+20h] [rbp-38h] BYREF

if ( (int)ff_compare(a1, &ec_p) >= 0 || (int)ff_compare(a1 + 32, &ec_p) >= 0 )
return 0;
ff_mul(v2, a1, a1, &ec_p);
ff_mul(v2, v2, a1, &ec_p);
ff_add(v2, v2, &ec_b, &ec_p);
ff_mul(v3, a1 + 32, a1 + 32, &ec_p);
return (unsigned int)ff_compare(v3, v2) == 0;
}

canonical_decompiled_code:
bool __fastcall func5(__int64 a1)
{
_BYTE v2[32]; // [rsp+0h] [rbp-58h] BYREF
char v3[56]; // [rsp+20h] [rbp-38h] BYREF

if ( (int)ff_compare(a1, &ec_p) >= 0 || (int)ff_compare(a1 + 32, &ec_p) >= 0 )
return 0;
ff_mul(v2, a1, a1, &ec_p);
ff_mul(v2, v2, a1, &ec_p);
ff_add(v2, v2, &ec_b, &ec_p);
ff_mul(v3, a1 + 32, a1 + 32, &ec_p);
return (unsigned int)ff_compare(v3, v2) == 0;
}

original_code:
_Bool ec_on_curve (EC_POINT const *const P)
{
 FF_NUM tmp, y2;
 if (ff_compare (&(P->x), &ec_p) >= 0)
  return 0;
 if (ff_compare (&(P->y), &ec_p) >= 0)
  return 0;
 ff_mul (&tmp, &(P->x), &(P->x), &ec_p);
 ff_mul (&tmp, &tmp, &(P->x), &ec_p);
 ff_add (&tmp, &tmp, &ec_b, &ec_p);
 ff_mul (&y2, &(P->y), &(P->y), &ec_p);
 if (ff_compare (&y2, &tmp) != 0)
  return 0;
 return 1;
}

canonical_original_code:
_Bool ec_on_curve(struct EC_POINT *P)
{
 struct FF_NUM tmp; struct FF_NUM y2;
 if (ff_compare (&(P->x), &ec_p) >= 0)
  return 0;
 if (ff_compare (&(P->y), &ec_p) >= 0)
  return 0;
 ff_mul (&tmp, &(P->x), &(P->x), &ec_p);
 ff_mul (&tmp, &tmp, &(P->x), &ec_p);
 ff_add (&tmp, &tmp, &ec_b, &ec_p);
 ff_mul (&y2, &(P->y), &(P->y), &ec_p);
 if (ff_compare (&y2, &tmp) != 0)
  return 0;
 return 1;
}


decompiled_code:
bool __fastcall ec_verify(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v7[32]; // [rsp+0h] [rbp-128h] BYREF
char v8[32]; // [rsp+20h] [rbp-108h] BYREF
char v9[32]; // [rsp+40h] [rbp-E8h] BYREF
char v10[32]; // [rsp+60h] [rbp-C8h] BYREF
char v11[32]; // [rsp+80h] [rbp-A8h] BYREF
char v12[32]; // [rsp+A0h] [rbp-88h] BYREF
char v13[104]; // [rsp+C0h] [rbp-68h] BYREF

if ( (unsigned __int8)ff_is_zero(a2) && (unsigned __int8)ff_is_zero(a2 + 32) )
return 0;
if ( !ec_on_curve(a2) )
return 0;
ec_mul((__int64)v11, (__int64)&ec_n, a2);
if ( !(unsigned __int8)ff_is_zero(v11)
|| !(unsigned __int8)ff_is_zero(v12)
|| (unsigned __int8)ff_is_zero(a3)
|| (unsigned __int8)ff_is_zero(a4)
|| (int)ff_compare(a3, &ec_n) >= 0
|| (int)ff_compare(a4, &ec_n) >= 0 )
{
return 0;
}
ff_inv(v7, a4, &ec_n);
ff_mul(v8, a1, v7, &ec_n);
ff_mul(v9, a3, v7, &ec_n);
ec_mul((__int64)v11, (__int64)v8, (__int64)&ec_G);
ec_mul((__int64)v13, (__int64)v9, a2);
ec_add((__int64)v11, (__int64)v11, (__int64)v13);
ff_zero(v10);
ff_add(v10, v10, v11, &ec_n);
return (unsigned int)ff_compare(v10, a3) == 0;
}

canonical_decompiled_code:
bool __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v7[32]; // [rsp+0h] [rbp-128h] BYREF
char v8[32]; // [rsp+20h] [rbp-108h] BYREF
char v9[32]; // [rsp+40h] [rbp-E8h] BYREF
char v10[32]; // [rsp+60h] [rbp-C8h] BYREF
char v11[32]; // [rsp+80h] [rbp-A8h] BYREF
char v12[32]; // [rsp+A0h] [rbp-88h] BYREF
char v13[104]; // [rsp+C0h] [rbp-68h] BYREF

if ( (unsigned __int8)ff_is_zero(a2) && (unsigned __int8)ff_is_zero(a2 + 32) )
return 0;
if ( !func5(a2) )
return 0;
func2((__int64)v11, (__int64)&ec_n, a2);
if ( !(unsigned __int8)ff_is_zero(v11)
|| !(unsigned __int8)ff_is_zero(v12)
|| (unsigned __int8)ff_is_zero(a3)
|| (unsigned __int8)ff_is_zero(a4)
|| (int)ff_compare(a3, &ec_n) >= 0
|| (int)ff_compare(a4, &ec_n) >= 0 )
{
return 0;
}
ff_inv(v7, a4, &ec_n);
ff_mul(v8, a1, v7, &ec_n);
ff_mul(v9, a3, v7, &ec_n);
func2((__int64)v11, (__int64)v8, (__int64)&ec_G);
func2((__int64)v13, (__int64)v9, a2);
func1((__int64)v11, (__int64)v11, (__int64)v13);
ff_zero(v10);
ff_add(v10, v10, v11, &ec_n);
return (unsigned int)ff_compare(v10, a3) == 0;
}

original_code:
_Bool ec_verify (FF_NUM const *const z, EC_POINT const *const Q, FF_NUM const *const r, FF_NUM const *const s)
{
 FF_NUM w, u1, u2, x1;
 EC_POINT tmp, tmp2;
 if ((ff_is_zero (&(Q->x))) && (ff_is_zero (&(Q->y))))
  return 0;
 if ((!ec_on_curve (Q)))
  return 0;
 ec_mul (&tmp, &ec_n, Q);
 if ((!ff_is_zero (&(tmp.x))) || (!ff_is_zero (&(tmp.y))))
  return 0;
 if ((ff_is_zero (r)) || (ff_is_zero (s)))
  return 0;
 if ((ff_compare (r, &ec_n) >= 0) || (ff_compare (s, &ec_n) >= 0))
  return 0;
 ff_inv (&w, s, &ec_n);
 ff_mul (&u1, z, &w, &ec_n);
 ff_mul (&u2, r, &w, &ec_n);
 ec_mul (&tmp, &u1, &ec_G);
 ec_mul (&tmp2, &u2, Q);
 ec_add (&tmp, &tmp, &tmp2);
 ff_zero (&x1);
 ff_add (&x1, &x1, &(tmp.x), &ec_n);
 if (ff_compare (&x1, r) != 0)
  return 0;
 return 1;
}

canonical_original_code:
_Bool ec_verify(struct FF_NUM *z, struct EC_POINT *Q, struct FF_NUM *r, struct FF_NUM *s)
{
 struct FF_NUM w; struct FF_NUM u1; struct FF_NUM u2; struct FF_NUM x1;
 struct EC_POINT tmp; struct EC_POINT tmp2;
 if ((ff_is_zero (&(Q->x))) && (ff_is_zero (&(Q->y))))
  return 0;
 if ((!ec_on_curve (Q)))
  return 0;
 ec_mul (&tmp, &ec_n, Q);
 if ((!ff_is_zero (&(tmp.x))) || (!ff_is_zero (&(tmp.y))))
  return 0;
 if ((ff_is_zero (r)) || (ff_is_zero (s)))
  return 0;
 if ((ff_compare (r, &ec_n) >= 0) || (ff_compare (s, &ec_n) >= 0))
  return 0;
 ff_inv (&w, s, &ec_n);
 ff_mul (&u1, z, &w, &ec_n);
 ff_mul (&u2, r, &w, &ec_n);
 ec_mul (&tmp, &u1, &ec_G);
 ec_mul (&tmp2, &u2, Q);
 ec_add (&tmp, &tmp, &tmp2);
 ff_zero (&x1);
 ff_add (&x1, &x1, &(tmp.x), &ec_n);
 if (ff_compare (&x1, r) != 0)
  return 0;
 return 1;
}

variable_types:
z
struct FF_NUM { unsigned int z[8]; } *

variable_types:
Q
struct EC_POINT { struct FF_NUM x; } *

variable_types:
r
struct FF_NUM *

variable_types:
s
struct FF_NUM *

variable_types:
w
struct FF_NUM { unsigned int z[8]; }


decompiled_code:
__int64 __fastcall ec_serialize(_BYTE *a1, __int64 a2, char a3)
{
unsigned int v3; // er12

if ( !a3 )
{
v3 = 65;
if ( a1 )
{
*a1 = 4;
ff_serialize(a1 + 1);
ff_serialize(a1 + 33);
}
return v3;
}
v3 = 33;
if ( !a1 )
return v3;
*a1 = (*(_BYTE *)(a2 + 32) & 1) + 2;
((void (*)(void))ff_serialize)();
return 33LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1, __int64 a2, char a3)
{
unsigned int v3; // er12

if ( !a3 )
{
v3 = 65;
if ( a1 )
{
*a1 = 4;
ff_serialize(a1 + 1);
ff_serialize(a1 + 33);
}
return v3;
}
v3 = 33;
if ( !a1 )
return v3;
*a1 = (*(_BYTE *)(a2 + 32) & 1) + 2;
((void (*)(void))ff_serialize)();
return 33LL;
}

original_code:
uint32_t ec_serialize (uint8_t *out, EC_POINT const *const P, _Bool compressed)
{
 if (!compressed) {
  if (out) {
   out[0] = 0x04;
   ff_serialize (out+1, &(P->x));
   ff_serialize (out+1+32, &(P->y));
  }
  return 65;
 }
 else {
  if (out) {
   out[0] = (P->y.z[0] & 1) ? 0x03 : 0x02;
   ff_serialize (out+1, &(P->x));
  }
  return 33;
 }
}

canonical_original_code:
unsigned int ec_serialize(unsigned char *out, struct EC_POINT *P, _Bool compressed)
{
 if (!compressed) {
  if (out) {
   out[0] = 0x04;
   ff_serialize (out+1, &(P->x));
   ff_serialize (out+1+32, &(P->y));
  }
  return 65;
 }
 else {
  if (out) {
   out[0] = (P->y.z[0] & 1) ? 0x03 : 0x02;
   ff_serialize (out+1, &(P->x));
  }
  return 33;
 }
}

variable_types:
out
unsigned char *

variable_types: struct EC_POINT { struct FF_NUM { unsigned int z[8]; } x; } *

return_type: unsigned int


original_code:
static char *test_vectors_partial (void) {
{
 SHA256_STATE sha256_state;
 uint8_t hash[33] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55};
 const uint8_t corpus_0[] = "Once upon a midnight dreary, while I pondered weak and weary,\n";
 const uint8_t corpus_1[] = "Over many a quaint and curious volume of forgotten lore,\n";
 const uint8_t corpus_2[] = "While I nodded, nearly napping, suddenly there came a tapping,\nAs of some one gently rapping, rapping at my chamber door.\n`'Tis some visitor,' I muttered, `tapping at my chamber door -\nOnly this, and nothing more.'";
 const uint8_t hash1[] = {0xac,0xeb,0x92,0xd5,0x16,0x25,0x47,0xc6,0x81,0xf7,0x2e,0xa7,0x9d,0x7b,0x39,0xfa,0x07,0xb3,0x21,0x4d,0x85,0x20,0xfd,0x48,0x94,0x82,0x0a,0x89,0xd9,0x6d,0x67,0xca};
 const uint8_t hash2[] = {0xc9,0xd8,0x87,0x82,0x21,0x40,0x58,0x0d,0x62,0xed,0xc4,0x66,0x19,0x27,0x6c,0x43,0x79,0x7f,0x88,0xfc,0x55,0xf4,0x8b,0xcb,0x23,0xdd,0x5f,0xa5,0xe7,0x74,0x55,0x9c};
 const uint8_t hash3[] = {0xe3,0xb0,0xc4,0x42,0x98,0xfc,0x1c,0x14,0x9a,0xfb,0xf4,0xc8,0x99,0x6f,0xb9,0x24,0x27,0xae,0x41,0xe4,0x64,0x9b,0x93,0x4c,0xa4,0x95,0x99,0x1b,0x78,0x52,0xb8,0x55};
 SHA256_partial (hash, &sha256_state, corpus_0, sizeof (corpus_0) - 1, 1, 0);
 SHA256_partial (hash, &sha256_state, corpus_1, sizeof (corpus_1) - 1, 0, 0);
 SHA256_partial (hash, &sha256_state, corpus_2, sizeof (corpus_2) - 1, 0, 1);
 do { if (!(memcmp (hash, hash1, 32) == 0)) return "SHA256_partial should correctly hash the test strings."; } while (0);
 for (int i = 0; i < 100; ++i)
  SHA256_partial (hash, &sha256_state, hash, 32, 1, 1);
 do { if (!(memcmp (hash, hash2, 32) == 0)) return "SHA256_partial should correctly hash in a feedback loop."; } while (0);
 SHA256_partial (hash, &sha256_state, 0, 0, 1, 1);
 do { if (!(memcmp (hash, hash3, 32) == 0)) return "SHA256_partial should correctly hash the zero-length string."; } while (0);
 do { if (!(hash[32] == 0x55)) return "SHA256 should not write more than 32 bytes to the destination array."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_vectors_partial() {
{
 struct SHA256_STATE sha256_state;
 unsigned char hash[33] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55};
 unsigned char corpus_0[] = "Once upon a midnight dreary, while I pondered weak and weary,\n";
 unsigned char corpus_1[] = "Over many a quaint and curious volume of forgotten lore,\n";
 unsigned char corpus_2[] = "While I nodded, nearly napping, suddenly there came a tapping,\nAs of some one gently rapping, rapping at my chamber door.\n`'Tis some visitor,' I muttered, `tapping at my chamber door -\nOnly this, and nothing more.'";
 unsigned char hash1[] = {0xac,0xeb,0x92,0xd5,0x16,0x25,0x47,0xc6,0x81,0xf7,0x2e,0xa7,0x9d,0x7b,0x39,0xfa,0x07,0xb3,0x21,0x4d,0x85,0x20,0xfd,0x48,0x94,0x82,0x0a,0x89,0xd9,0x6d,0x67,0xca};
 unsigned char hash2[] = {0xc9,0xd8,0x87,0x82,0x21,0x40,0x58,0x0d,0x62,0xed,0xc4,0x66,0x19,0x27,0x6c,0x43,0x79,0x7f,0x88,0xfc,0x55,0xf4,0x8b,0xcb,0x23,0xdd,0x5f,0xa5,0xe7,0x74,0x55,0x9c};
 unsigned char hash3[] = {0xe3,0xb0,0xc4,0x42,0x98,0xfc,0x1c,0x14,0x9a,0xfb,0xf4,0xc8,0x99,0x6f,0xb9,0x24,0x27,0xae,0x41,0xe4,0x64,0x9b,0x93,0x4c,0xa4,0x95,0x99,0x1b,0x78,0x52,0xb8,0x55};
 SHA256_partial (hash, &sha256_state, corpus_0, sizeof (corpus_0) - 1, 1, 0);
 SHA256_partial (hash, &sha256_state, corpus_1, sizeof (corpus_1) - 1, 0, 0);
 SHA256_partial (hash, &sha256_state, corpus_2, sizeof (corpus_2) - 1, 0, 1);
 do { if (!(memcmp (hash, hash1, 32) == 0)) return "SHA256_partial should correctly hash the test strings."; } while (0);
 for (int i = 0; i < 100; ++i)
  SHA256_partial (hash, &sha256_state, hash, 32, 1, 1);
 do { if (!(memcmp (hash, hash2, 32) == 0)) return "SHA256_partial should correctly hash in a feedback loop."; } while (0);
 SHA256_partial (hash, &sha256_state, 0, 0, 1, 1);
 do { if (!(memcmp (hash, hash3, 32) == 0)) return "SHA256_partial should correctly hash the zero-length string."; } while (0);
 do { if (!(hash[32] == 0x55)) return "SHA256 should not write more than 32 bytes to the destination array."; } while (0);
}
return 0;}

variable_types: struct SHA256_STATE { unsigned int state[8]; unsigned int chunk[16]; unsigned int chunk_len; unsigned int totallen; }

variable_types:
hash
unsigned char [33]

variable_types: i int


decompiled_code:
const char *test_sha256()
{
const char *result; // rax

result = test_vectors();
++tests_run;
if ( !result )
{
result = test_vectors_partial();
++tests_run;
}
return result;
}

canonical_decompiled_code:
const char *func2()
{
const char *result; // rax

result = func0();
++tests_run;
if ( !result )
{
result = func1();
++tests_run;
}
return result;
}

original_code:
char *test_sha256 (void)
{
 do { char *message = test_vectors(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_vectors_partial(); tests_run++; if (message) return message; } while (0);
 return 0;
}

canonical_original_code:
char *test_sha256()
{
 do { char *message = test_vectors(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_vectors_partial(); tests_run++; if (message) return message; } while (0);
 return 0;
}

variable_types:
message
char *


decompiled_code:
const char *test_vectors()
{
const char *result; // rax
__m128i v1; // [rsp+0h] [rbp-F8h]
__m128i v2; // [rsp+10h] [rbp-E8h]
__m128i v3; // [rsp+20h] [rbp-D8h]
__m128i v4; // [rsp+30h] [rbp-C8h]
__m128i v5; // [rsp+40h] [rbp-B8h]
__m128i v6; // [rsp+50h] [rbp-A8h]
__m128i v7; // [rsp+60h] [rbp-98h] BYREF
__m128i v8; // [rsp+70h] [rbp-88h]
char v9; // [rsp+80h] [rbp-78h]
__m128i v10; // [rsp+90h] [rbp-68h] BYREF
__m128i v11; // [rsp+A0h] [rbp-58h]
char v12[16]; // [rsp+B0h] [rbp-48h] BYREF
__int128 v13[2]; // [rsp+C0h] [rbp-38h] BYREF
char v14[16]; // [rsp+E0h] [rbp-18h] BYREF

v7 = _mm_load_si128((const __m128i *)&LC3);
v8 = v7;
v1 = _mm_load_si128((const __m128i *)&LC6);
v11 = _mm_load_si128((const __m128i *)&LC5);
v13[1] = (__int128)v11;
strcpy(v12, "he lazy dog");
v3 = _mm_load_si128((const __m128i *)&LC8);
strcpy(v14, "he lazy dog.");
v4 = _mm_load_si128((const __m128i *)&LC9);
v9 = 85;
v5 = _mm_load_si128((const __m128i *)&LC10);
v10 = _mm_load_si128((const __m128i *)&LC4);
v2 = _mm_load_si128((const __m128i *)&LC7);
v13[0] = (__int128)v10;
v6 = _mm_load_si128((const __m128i *)&LC11);
SHA256(&v7, &v10, 43LL);
if ( *(_OWORD *)&v1 != *(_OWORD *)&v7 )
return "SHA256 should correctly hash the test strings.";
if ( *(_OWORD *)&v2 != *(_OWORD *)&v8 )
return "SHA256 should correctly hash the test strings.";
SHA256(&v7, v13, 44LL);
if ( *(_OWORD *)&v3 != *(_OWORD *)&v7 || *(_OWORD *)&v4 != *(_OWORD *)&v8 )
return "SHA256 should correctly hash the test strings.";
SHA256(&v7, 0LL, 0LL);
if ( *(_OWORD *)&v5 != *(_OWORD *)&v7 || *(_OWORD *)&v6 != *(_OWORD *)&v8 )
return "SHA256 should correctly hash the zero-length string.";
result = "SHA256 should not write more than 32 bytes to the destination array.";
if ( v9 == 85 )
result = (const char *)(v6.m128i_i64[1] ^ v8.m128i_i64[1] | v6.m128i_i64[0] ^ v8.m128i_i64[0]);
return result;
}

canonical_decompiled_code:
const char *func0()
{
const char *result; // rax
__m128i v1; // [rsp+0h] [rbp-F8h]
__m128i v2; // [rsp+10h] [rbp-E8h]
__m128i v3; // [rsp+20h] [rbp-D8h]
__m128i v4; // [rsp+30h] [rbp-C8h]
__m128i v5; // [rsp+40h] [rbp-B8h]
__m128i v6; // [rsp+50h] [rbp-A8h]
__m128i v7; // [rsp+60h] [rbp-98h] BYREF
__m128i v8; // [rsp+70h] [rbp-88h]
char v9; // [rsp+80h] [rbp-78h]
__m128i v10; // [rsp+90h] [rbp-68h] BYREF
__m128i v11; // [rsp+A0h] [rbp-58h]
char v12[16]; // [rsp+B0h] [rbp-48h] BYREF
__int128 v13[2]; // [rsp+C0h] [rbp-38h] BYREF
char v14[16]; // [rsp+E0h] [rbp-18h] BYREF

v7 = _mm_load_si128((const __m128i *)&LC3);
v8 = v7;
v1 = _mm_load_si128((const __m128i *)&LC6);
v11 = _mm_load_si128((const __m128i *)&LC5);
v13[1] = (__int128)v11;
strcpy(v12, "he lazy dog");
v3 = _mm_load_si128((const __m128i *)&LC8);
strcpy(v14, "he lazy dog.");
v4 = _mm_load_si128((const __m128i *)&LC9);
v9 = 85;
v5 = _mm_load_si128((const __m128i *)&LC10);
v10 = _mm_load_si128((const __m128i *)&LC4);
v2 = _mm_load_si128((const __m128i *)&LC7);
v13[0] = (__int128)v10;
v6 = _mm_load_si128((const __m128i *)&LC11);
SHA256(&v7, &v10, 43LL);
if ( *(_OWORD *)&v1 != *(_OWORD *)&v7 )
return "SHA256 should correctly hash the test strings.";
if ( *(_OWORD *)&v2 != *(_OWORD *)&v8 )
return "SHA256 should correctly hash the test strings.";
SHA256(&v7, v13, 44LL);
if ( *(_OWORD *)&v3 != *(_OWORD *)&v7 || *(_OWORD *)&v4 != *(_OWORD *)&v8 )
return "SHA256 should correctly hash the test strings.";
SHA256(&v7, 0LL, 0LL);
if ( *(_OWORD *)&v5 != *(_OWORD *)&v7 || *(_OWORD *)&v6 != *(_OWORD *)&v8 )
return "SHA256 should correctly hash the zero-length string.";
result = "SHA256 should not write more than 32 bytes to the destination array.";
if ( v9 == 85 )
result = (const char *)(v6.m128i_i64[1] ^ v8.m128i_i64[1] | v6.m128i_i64[0] ^ v8.m128i_i64[0]);
return result;
}

original_code:
static char *test_vectors (void) {
{
 uint8_t hash[33] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55};
 const uint8_t str1[] = "The quick brown fox jumps over the lazy dog";
 const uint8_t hash1[] = {0xd7,0xa8,0xfb,0xb3,0x07,0xd7,0x80,0x94,0x69,0xca,0x9a,0xbc,0xb0,0x08,0x2e,0x4f,0x8d,0x56,0x51,0xe4,0x6d,0x3c,0xdb,0x76,0x2d,0x02,0xd0,0xbf,0x37,0xc9,0xe5,0x92};
 const uint8_t str2[] = "The quick brown fox jumps over the lazy dog.";
 const uint8_t hash2[] = {0xef,0x53,0x7f,0x25,0xc8,0x95,0xbf,0xa7,0x82,0x52,0x65,0x29,0xa9,0xb6,0x3d,0x97,0xaa,0x63,0x15,0x64,0xd5,0xd7,0x89,0xc2,0xb7,0x65,0x44,0x8c,0x86,0x35,0xfb,0x6c};
 const uint8_t hash3[] = {0xe3,0xb0,0xc4,0x42,0x98,0xfc,0x1c,0x14,0x9a,0xfb,0xf4,0xc8,0x99,0x6f,0xb9,0x24,0x27,0xae,0x41,0xe4,0x64,0x9b,0x93,0x4c,0xa4,0x95,0x99,0x1b,0x78,0x52,0xb8,0x55};
 SHA256 (hash, str1, sizeof(str1) - 1);
 do { if (!(memcmp (hash, hash1, 32) == 0)) return "SHA256 should correctly hash the test strings."; } while (0);
 SHA256 (hash, str2, sizeof(str2) - 1);
 do { if (!(memcmp (hash, hash2, 32) == 0)) return "SHA256 should correctly hash the test strings."; } while (0);
 SHA256 (hash, 0, 0);
 do { if (!(memcmp (hash, hash3, 32) == 0)) return "SHA256 should correctly hash the zero-length string."; } while (0);
 do { if (!(hash[32] == 0x55)) return "SHA256 should not write more than 32 bytes to the destination array."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_vectors() {
{
 unsigned char hash[33] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55};
 unsigned char str1[] = "The quick brown fox jumps over the lazy dog";
 unsigned char hash1[] = {0xd7,0xa8,0xfb,0xb3,0x07,0xd7,0x80,0x94,0x69,0xca,0x9a,0xbc,0xb0,0x08,0x2e,0x4f,0x8d,0x56,0x51,0xe4,0x6d,0x3c,0xdb,0x76,0x2d,0x02,0xd0,0xbf,0x37,0xc9,0xe5,0x92};
 unsigned char str2[] = "The quick brown fox jumps over the lazy dog.";
 unsigned char hash2[] = {0xef,0x53,0x7f,0x25,0xc8,0x95,0xbf,0xa7,0x82,0x52,0x65,0x29,0xa9,0xb6,0x3d,0x97,0xaa,0x63,0x15,0x64,0xd5,0xd7,0x89,0xc2,0xb7,0x65,0x44,0x8c,0x86,0x35,0xfb,0x6c};
 unsigned char hash3[] = {0xe3,0xb0,0xc4,0x42,0x98,0xfc,0x1c,0x14,0x9a,0xfb,0xf4,0xc8,0x99,0x6f,0xb9,0x24,0x27,0xae,0x41,0xe4,0x64,0x9b,0x93,0x4c,0xa4,0x95,0x99,0x1b,0x78,0x52,0xb8,0x55};
 SHA256 (hash, str1, sizeof(str1) - 1);
 do { if (!(memcmp (hash, hash1, 32) == 0)) return "SHA256 should correctly hash the test strings."; } while (0);
 SHA256 (hash, str2, sizeof(str2) - 1);
 do { if (!(memcmp (hash, hash2, 32) == 0)) return "SHA256 should correctly hash the test strings."; } while (0);
 SHA256 (hash, 0, 0);
 do { if (!(memcmp (hash, hash3, 32) == 0)) return "SHA256 should correctly hash the zero-length string."; } while (0);
 do { if (!(hash[32] == 0x55)) return "SHA256 should not write more than 32 bytes to the destination array."; } while (0);
}
return 0;}


decompiled_code:
const char *test_compare()
{
int v0; // er8
const char *result; // rax
int v2; // er8
bool v3; // sf
__int64 v4[4]; // [rsp+0h] [rbp-68h] BYREF
__int128 v5[2]; // [rsp+20h] [rbp-48h] BYREF
__int128 v6[2]; // [rsp+40h] [rbp-28h] BYREF

v4[0] = 0x1234567DEADBEEFLL;
v4[1] = 0xFEDCBA9889ABCDEFLL;
v4[2] = 0x7777777776543210LL;
v6[0] = 0LL;
v4[3] = 0xFFFFFFFE39103739LL;
LODWORD(v6[0]) = 1;
v5[0] = 0LL;
v5[1] = 0LL;
v6[1] = 0LL;
v0 = ff_compare(v4, v4);
result = "ff_compare should return 0 if the arguments are equal.";
if ( !v0 )
{
v2 = ff_compare(v4, v5);
result = "ff_compare should return >0 if the first argument is greater than the second.";
if ( v2 > 0 )
{
v3 = (int)ff_compare(v5, v6) < 0;
result = "ff_compare should return <0 if the first argument is less than the second.";
if ( v3 )
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
const char *func0()
{
int v0; // er8
const char *result; // rax
int v2; // er8
bool v3; // sf
__int64 v4[4]; // [rsp+0h] [rbp-68h] BYREF
__int128 v5[2]; // [rsp+20h] [rbp-48h] BYREF
__int128 v6[2]; // [rsp+40h] [rbp-28h] BYREF

v4[0] = 0x1234567DEADBEEFLL;
v4[1] = 0xFEDCBA9889ABCDEFLL;
v4[2] = 0x7777777776543210LL;
v6[0] = 0LL;
v4[3] = 0xFFFFFFFE39103739LL;
LODWORD(v6[0]) = 1;
v5[0] = 0LL;
v5[1] = 0LL;
v6[1] = 0LL;
v0 = ff_compare(v4, v4);
result = "ff_compare should return 0 if the arguments are equal.";
if ( !v0 )
{
v2 = ff_compare(v4, v5);
result = "ff_compare should return >0 if the first argument is greater than the second.";
if ( v2 > 0 )
{
v3 = (int)ff_compare(v5, v6) < 0;
result = "ff_compare should return <0 if the first argument is less than the second.";
if ( v3 )
result = 0LL;
}
}
return result;
}

original_code:
static char *test_compare (void) {
{
 const FF_NUM a = {0xDEADBEEF, 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x77777777, 0x39103739, 0xFFFFFFFE};
 const FF_NUM b = {0};
 const FF_NUM c = {1, 0, 0, 0, 0, 0, 0, 0};
 do { if (!(ff_compare (&a, &a) == 0)) return "ff_compare should return 0 if the arguments are equal."; } while (0);
 do { if (!(ff_compare (&a, &b) > 0)) return "ff_compare should return >0 if the first argument is greater than the second."; } while (0);
 do { if (!(ff_compare (&b, &c) < 0)) return "ff_compare should return <0 if the first argument is less than the second."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_compare() {
{
 struct FF_NUM a = {0xDEADBEEF, 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x77777777, 0x39103739, 0xFFFFFFFE};
 struct FF_NUM b = {0};
 struct FF_NUM c = {1, 0, 0, 0, 0, 0, 0, 0};
 do { if (!(ff_compare (&a, &a) == 0)) return "ff_compare should return 0 if the arguments are equal."; } while (0);
 do { if (!(ff_compare (&a, &b) > 0)) return "ff_compare should return >0 if the first argument is greater than the second."; } while (0);
 do { if (!(ff_compare (&b, &c) < 0)) return "ff_compare should return <0 if the first argument is less than the second."; } while (0);
}
return 0;}

variable_types:
a
struct FF_NUM { unsigned int z[8]; }

variable_types:
b
struct FF_NUM { unsigned int z[8]; }

variable_types:
c
struct FF_NUM { unsigned int z[8]; }


decompiled_code:
const char *test_copy()
{
int v0; // er8
const char *result; // rax
int v2; // er8
bool v3; // zf
__int64 v4[4]; // [rsp+0h] [rbp-68h] BYREF
__int64 v5[4]; // [rsp+20h] [rbp-48h] BYREF
__int128 v6[2]; // [rsp+40h] [rbp-28h] BYREF

v4[0] = 0x1234567DEADBEEFLL;
v5[0] = 0x1234567DEADBEEFLL;
v4[1] = 0xFEDCBA9889ABCDEFLL;
v4[2] = 0x7777777776543210LL;
v4[3] = 0xFFFFFFFE39103739LL;
v5[1] = 0xFEDCBA9889ABCDEFLL;
v5[2] = 0x7777777776543210LL;
v5[3] = 0xFFFFFFFE39103739LL;
v6[0] = 0LL;
v6[1] = 0LL;
ff_copy(v6, v4);
v0 = ff_compare(v4, v5);
result = "ff_copy should not modify the source argument.";
if ( !v0 )
{
v2 = ff_compare(v4, v6);
result = "ff_copy should create a duplicate copy of the source in the destination.";
if ( !v2 )
{
ff_copy(v6, v6);
v3 = (unsigned int)ff_compare(v6, v5) == 0;
result = "ff_copy should allow source and destination to point to the same FF_NUM.";
if ( v3 )
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
const char *func1()
{
int v0; // er8
const char *result; // rax
int v2; // er8
bool v3; // zf
__int64 v4[4]; // [rsp+0h] [rbp-68h] BYREF
__int64 v5[4]; // [rsp+20h] [rbp-48h] BYREF
__int128 v6[2]; // [rsp+40h] [rbp-28h] BYREF

v4[0] = 0x1234567DEADBEEFLL;
v5[0] = 0x1234567DEADBEEFLL;
v4[1] = 0xFEDCBA9889ABCDEFLL;
v4[2] = 0x7777777776543210LL;
v4[3] = 0xFFFFFFFE39103739LL;
v5[1] = 0xFEDCBA9889ABCDEFLL;
v5[2] = 0x7777777776543210LL;
v5[3] = 0xFFFFFFFE39103739LL;
v6[0] = 0LL;
v6[1] = 0LL;
ff_copy(v6, v4);
v0 = ff_compare(v4, v5);
result = "ff_copy should not modify the source argument.";
if ( !v0 )
{
v2 = ff_compare(v4, v6);
result = "ff_copy should create a duplicate copy of the source in the destination.";
if ( !v2 )
{
ff_copy(v6, v6);
v3 = (unsigned int)ff_compare(v6, v5) == 0;
result = "ff_copy should allow source and destination to point to the same FF_NUM.";
if ( v3 )
result = 0LL;
}
}
return result;
}

original_code:
static char *test_copy (void) {
{
 const FF_NUM a = {0xDEADBEEF, 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x77777777, 0x39103739, 0xFFFFFFFE};
 const FF_NUM b = {0xDEADBEEF, 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x77777777, 0x39103739, 0xFFFFFFFE};
 FF_NUM c = {0};
 ff_copy (&c, &a);
 do { if (!(ff_compare (&a, &b) == 0)) return "ff_copy should not modify the source argument."; } while (0);
 do { if (!(ff_compare (&a, &c) == 0)) return "ff_copy should create a duplicate copy of the source in the destination."; } while (0);
 ff_copy (&c, &c);
 do { if (!(ff_compare (&c, &b) == 0)) return "ff_copy should allow source and destination to point to the same FF_NUM."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_copy() {
{
 struct FF_NUM a = {0xDEADBEEF, 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x77777777, 0x39103739, 0xFFFFFFFE};
 struct FF_NUM b = {0xDEADBEEF, 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x77777777, 0x39103739, 0xFFFFFFFE};
 struct FF_NUM c = {0};
 ff_copy (&c, &a);
 do { if (!(ff_compare (&a, &b) == 0)) return "ff_copy should not modify the source argument."; } while (0);
 do { if (!(ff_compare (&a, &c) == 0)) return "ff_copy should create a duplicate copy of the source in the destination."; } while (0);
 ff_copy (&c, &c);
 do { if (!(ff_compare (&c, &b) == 0)) return "ff_copy should allow source and destination to point to the same FF_NUM."; } while (0);
}
return 0;}


variable_types:
d
struct FF_NUM { unsigned int z[8]; }

variable_types:
e
struct FF_NUM { unsigned int z[8]; }


decompiled_code:
const char *test_sub()
{
int v0; // er8
const char *result; // rax
int v2; // er8
char v3; // r8
bool v4; // zf
_BYTE v5[32]; // [rsp+0h] [rbp-148h] BYREF
char v6[32]; // [rsp+20h] [rbp-128h] BYREF
__int64 v7[4]; // [rsp+40h] [rbp-108h] BYREF
__int64 v8[4]; // [rsp+60h] [rbp-E8h] BYREF
__int64 v9[4]; // [rsp+80h] [rbp-C8h] BYREF
__int128 v10; // [rsp+A0h] [rbp-A8h] BYREF
__int64 v11; // [rsp+B0h] [rbp-98h]
int v12; // [rsp+B8h] [rbp-90h]
int v13; // [rsp+BCh] [rbp-8Ch]
__int128 v14[2]; // [rsp+C0h] [rbp-88h] BYREF
__int64 v15[4]; // [rsp+E0h] [rbp-68h] BYREF
__int64 v16[4]; // [rsp+100h] [rbp-48h] BYREF
__int128 v17[2]; // [rsp+120h] [rbp-28h] BYREF

v7[0] = 0x683BDD9E57AEA72FLL;
v7[1] = 0x3B452E510DD1423BLL;
v7[2] = 0xFE06213934C36974LL;
v7[3] = 0x80863FEF4E56ED4DLL;
v8[0] = 0x9AFC2CA10B4944ELL;
v8[1] = 0xFBC985B98BDDACCBLL;
v8[2] = 0x2BA734BE6FF3ACDLL;
v8[3] = 0x99F64C219AB70589LL;
v15[0] = 0x5E8C1AD446FA12E0LL;
v15[1] = 0x3F7BA89781F39570LL;
v15[2] = 0xFB4BADED4DC42EA6LL;
v15[3] = 0xE68FF3CDB39FE7C4LL;
v16[0] = 0x5E8C1AD446FA12E1LL;
v16[1] = 0x3F7BA89781F39570LL;
v16[2] = 0xFB4BADED4DC42EA6LL;
v14[0] = 0LL;
v17[0] = 0LL;
v16[3] = 0x768FF3CDB39FE7C4LL;
v10 = 0LL;
v14[1] = 0LL;
v17[1] = 0LL;
v9[0] = -1LL;
v9[1] = -1LL;
v9[2] = -1LL;
v9[3] = -1LL;
v11 = 0LL;
v12 = 0;
v13 = -1879048192;
LODWORD(v14[0]) = 66;
LODWORD(v17[0]) = 41;
ff_sub(v5, v7, v8, v9);
ff_sub(v6, v7, v8, &v10);
v0 = ff_compare(v5, v15);
result = "ff_sub should subtract arguments (mod 2^256-1).";
if ( !v0 )
{
v2 = ff_compare(v6, v16);
result = "ff_sub should subtract arguments (mod p).";
if ( !v2 )
{
ff_sub(v5, v5, v5, v9);
v3 = ff_is_zero(v5);
result = "ff_sub should allow the destination argument to be the same as the source arguments.";
if ( v3 )
{
ff_sub(v5, v7, v8, v14);
v4 = (unsigned int)ff_compare(v5, v17) == 0;
result = "ff_sub should subtract arguments (mod p) even if the arguments are greater than p.";
if ( v4 )
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
const char *func3()
{
int v0; // er8
const char *result; // rax
int v2; // er8
char v3; // r8
bool v4; // zf
_BYTE v5[32]; // [rsp+0h] [rbp-148h] BYREF
char v6[32]; // [rsp+20h] [rbp-128h] BYREF
__int64 v7[4]; // [rsp+40h] [rbp-108h] BYREF
__int64 v8[4]; // [rsp+60h] [rbp-E8h] BYREF
__int64 v9[4]; // [rsp+80h] [rbp-C8h] BYREF
__int128 v10; // [rsp+A0h] [rbp-A8h] BYREF
__int64 v11; // [rsp+B0h] [rbp-98h]
int v12; // [rsp+B8h] [rbp-90h]
int v13; // [rsp+BCh] [rbp-8Ch]
__int128 v14[2]; // [rsp+C0h] [rbp-88h] BYREF
__int64 v15[4]; // [rsp+E0h] [rbp-68h] BYREF
__int64 v16[4]; // [rsp+100h] [rbp-48h] BYREF
__int128 v17[2]; // [rsp+120h] [rbp-28h] BYREF

v7[0] = 0x683BDD9E57AEA72FLL;
v7[1] = 0x3B452E510DD1423BLL;
v7[2] = 0xFE06213934C36974LL;
v7[3] = 0x80863FEF4E56ED4DLL;
v8[0] = 0x9AFC2CA10B4944ELL;
v8[1] = 0xFBC985B98BDDACCBLL;
v8[2] = 0x2BA734BE6FF3ACDLL;
v8[3] = 0x99F64C219AB70589LL;
v15[0] = 0x5E8C1AD446FA12E0LL;
v15[1] = 0x3F7BA89781F39570LL;
v15[2] = 0xFB4BADED4DC42EA6LL;
v15[3] = 0xE68FF3CDB39FE7C4LL;
v16[0] = 0x5E8C1AD446FA12E1LL;
v16[1] = 0x3F7BA89781F39570LL;
v16[2] = 0xFB4BADED4DC42EA6LL;
v14[0] = 0LL;
v17[0] = 0LL;
v16[3] = 0x768FF3CDB39FE7C4LL;
v10 = 0LL;
v14[1] = 0LL;
v17[1] = 0LL;
v9[0] = -1LL;
v9[1] = -1LL;
v9[2] = -1LL;
v9[3] = -1LL;
v11 = 0LL;
v12 = 0;
v13 = -1879048192;
LODWORD(v14[0]) = 66;
LODWORD(v17[0]) = 41;
ff_sub(v5, v7, v8, v9);
ff_sub(v6, v7, v8, &v10);
v0 = ff_compare(v5, v15);
result = "ff_sub should subtract arguments (mod 2^256-1).";
if ( !v0 )
{
v2 = ff_compare(v6, v16);
result = "ff_sub should subtract arguments (mod p).";
if ( !v2 )
{
ff_sub(v5, v5, v5, v9);
v3 = ff_is_zero(v5);
result = "ff_sub should allow the destination argument to be the same as the source arguments.";
if ( v3 )
{
ff_sub(v5, v7, v8, v14);
v4 = (unsigned int)ff_compare(v5, v17) == 0;
result = "ff_sub should subtract arguments (mod p) even if the arguments are greater than p.";
if ( v4 )
result = 0LL;
}
}
}
return result;
}

original_code:
static char *test_sub (void) {
{
 FF_NUM d, e;
 const FF_NUM a = {0x57aea72f, 0x683bdd9e, 0x0dd1423b, 0x3b452e51, 0x34c36974, 0xfe062139, 0x4e56ed4d, 0x80863fef};
 const FF_NUM b = {0x10b4944e, 0x09afc2ca, 0x8bddaccb, 0xfbc985b9, 0xe6ff3acd, 0x02ba734b, 0x9ab70589, 0x99f64c21};
 const FF_NUM p1 = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
 const FF_NUM p2 = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x90000000};
 const FF_NUM p3 = {0x00000042, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000};
 const FF_NUM r1 = {0x46FA12E0, 0x5E8C1AD4, 0x81F39570, 0x3F7BA897, 0x4DC42EA6, 0xFB4BADED, 0xB39FE7C4, 0xE68FF3CD};
 const FF_NUM r2 = {0x46FA12E1, 0x5E8C1AD4, 0x81F39570, 0x3F7BA897, 0x4DC42EA6, 0xFB4BADED, 0xB39FE7C4, 0x768FF3CD};
 const FF_NUM r4 = {0x00000029, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000};
 ff_sub (&d, &a, &b, &p1);
 ff_sub (&e, &a, &b, &p2);
 do { if (!(ff_compare (&d, &r1) == 0)) return "ff_sub should subtract arguments (mod 2^256-1)."; } while (0);
 do { if (!(ff_compare (&e, &r2) == 0)) return "ff_sub should subtract arguments (mod p)."; } while (0);
 ff_sub (&d, &d, &d, &p1);
 do { if (!(ff_is_zero (&d))) return "ff_sub should allow the destination argument to be the same as the source arguments."; } while (0);
 ff_sub (&d, &a, &b, &p3);
 do { if (!(ff_compare (&d, &r4) == 0)) return "ff_sub should subtract arguments (mod p) even if the arguments are greater than p."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_sub() {
{
 struct FF_NUM d; struct FF_NUM e;
 struct FF_NUM a = {0x57aea72f, 0x683bdd9e, 0x0dd1423b, 0x3b452e51, 0x34c36974, 0xfe062139, 0x4e56ed4d, 0x80863fef};
 struct FF_NUM b = {0x10b4944e, 0x09afc2ca, 0x8bddaccb, 0xfbc985b9, 0xe6ff3acd, 0x02ba734b, 0x9ab70589, 0x99f64c21};
 struct FF_NUM p1 = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
 struct FF_NUM p2 = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x90000000};
 struct FF_NUM p3 = {0x00000042, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000};
 struct FF_NUM r1 = {0x46FA12E0, 0x5E8C1AD4, 0x81F39570, 0x3F7BA897, 0x4DC42EA6, 0xFB4BADED, 0xB39FE7C4, 0xE68FF3CD};
 struct FF_NUM r2 = {0x46FA12E1, 0x5E8C1AD4, 0x81F39570, 0x3F7BA897, 0x4DC42EA6, 0xFB4BADED, 0xB39FE7C4, 0x768FF3CD};
 struct FF_NUM r4 = {0x00000029, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000};
 ff_sub (&d, &a, &b, &p1);
 ff_sub (&e, &a, &b, &p2);
 do { if (!(ff_compare (&d, &r1) == 0)) return "ff_sub should subtract arguments (mod 2^256-1)."; } while (0);
 do { if (!(ff_compare (&e, &r2) == 0)) return "ff_sub should subtract arguments (mod p)."; } while (0);
 ff_sub (&d, &d, &d, &p1);
 do { if (!(ff_is_zero (&d))) return "ff_sub should allow the destination argument to be the same as the source arguments."; } while (0);
 ff_sub (&d, &a, &b, &p3);
 do { if (!(ff_compare (&d, &r4) == 0)) return "ff_sub should subtract arguments (mod p) even if the arguments are greater than p."; } while (0);
}
return 0;}


decompiled_code:
const char *test_inv()
{
char v0; // r8
const char *result; // rax
bool v2; // zf
_BYTE v3[32]; // [rsp+0h] [rbp-88h] BYREF
__int64 v4[4]; // [rsp+20h] [rbp-68h] BYREF
__int64 v5[4]; // [rsp+40h] [rbp-48h] BYREF
__int128 v6[2]; // [rsp+60h] [rbp-28h] BYREF

v4[0] = 0x22DD2A76D249A3F4LL;
v6[0] = 0LL;
v4[1] = 0x7037BB0DCC065A3DLL;
v4[2] = 0x19B55395F5532C1CLL;
v4[3] = 0x26A466B2E4885FD0LL;
v5[0] = 0xFFFFFFFEFFFFFC2FLL;
v6[1] = 0LL;
v5[1] = -1LL;
v5[2] = -1LL;
v5[3] = -1LL;
LODWORD(v6[0]) = 13;
ff_inv(v3, v4, v5);
ff_mul(v3, v3, v4, v5);
v0 = ff_is_one(v3);
result = "ff_inv on argument x should return a number, y, such that x * y = 1 (mod secp256k1 prime).";
if ( v0 )
{
ff_inv(v3, v4, v6);
ff_mul(v3, v3, v4, v6);
v2 = (unsigned __int8)ff_is_one(v3) == 0;
result = "ff_inv on argument x should return a number, y, such that x * y = 1 (mod 0x0D).";
if ( !v2 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
const char *func5()
{
char v0; // r8
const char *result; // rax
bool v2; // zf
_BYTE v3[32]; // [rsp+0h] [rbp-88h] BYREF
__int64 v4[4]; // [rsp+20h] [rbp-68h] BYREF
__int64 v5[4]; // [rsp+40h] [rbp-48h] BYREF
__int128 v6[2]; // [rsp+60h] [rbp-28h] BYREF

v4[0] = 0x22DD2A76D249A3F4LL;
v6[0] = 0LL;
v4[1] = 0x7037BB0DCC065A3DLL;
v4[2] = 0x19B55395F5532C1CLL;
v4[3] = 0x26A466B2E4885FD0LL;
v5[0] = 0xFFFFFFFEFFFFFC2FLL;
v6[1] = 0LL;
v5[1] = -1LL;
v5[2] = -1LL;
v5[3] = -1LL;
LODWORD(v6[0]) = 13;
ff_inv(v3, v4, v5);
ff_mul(v3, v3, v4, v5);
v0 = ff_is_one(v3);
result = "ff_inv on argument x should return a number, y, such that x * y = 1 (mod secp256k1 prime).";
if ( v0 )
{
ff_inv(v3, v4, v6);
ff_mul(v3, v3, v4, v6);
v2 = (unsigned __int8)ff_is_one(v3) == 0;
result = "ff_inv on argument x should return a number, y, such that x * y = 1 (mod 0x0D).";
if ( !v2 )
result = 0LL;
}
return result;
}

original_code:
static char *test_inv (void) {
{
 FF_NUM d;
 const FF_NUM a = {0xD249A3F4,0x22DD2A76,0xCC065A3D,0x7037BB0D,0xF5532C1C,0x19B55395,0xE4885FD0,0x26A466B2};
 const FF_NUM p1 = {0xFFFFFC2F,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 const FF_NUM p2 = {0x0000000D,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 ff_inv (&d, &a, &p1);
 ff_mul (&d, &d, &a, &p1);
 do { if (!(ff_is_one (&d))) return "ff_inv on argument x should return a number, y, such that x * y = 1 (mod secp256k1 prime)."; } while (0);
 ff_inv (&d, &a, &p2);
 ff_mul (&d, &d, &a, &p2);
 do { if (!(ff_is_one (&d))) return "ff_inv on argument x should return a number, y, such that x * y = 1 (mod 0x0D)."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_inv() {
{
 struct FF_NUM d;
 struct FF_NUM a = {0xD249A3F4,0x22DD2A76,0xCC065A3D,0x7037BB0D,0xF5532C1C,0x19B55395,0xE4885FD0,0x26A466B2};
 struct FF_NUM p1 = {0xFFFFFC2F,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 struct FF_NUM p2 = {0x0000000D,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 ff_inv (&d, &a, &p1);
 ff_mul (&d, &d, &a, &p1);
 do { if (!(ff_is_one (&d))) return "ff_inv on argument x should return a number, y, such that x * y = 1 (mod secp256k1 prime)."; } while (0);
 ff_inv (&d, &a, &p2);
 ff_mul (&d, &d, &a, &p2);
 do { if (!(ff_is_one (&d))) return "ff_inv on argument x should return a number, y, such that x * y = 1 (mod 0x0D)."; } while (0);
}
return 0;}


decompiled_code:
const char *test_finite_field()
{
const char *result; // rax

result = test_compare();
++tests_run;
if ( !result )
{
result = test_copy();
++tests_run;
if ( !result )
{
result = test_add();
++tests_run;
if ( !result )
{
result = test_sub();
++tests_run;
if ( !result )
{
result = test_mul();
++tests_run;
if ( !result )
{
result = test_inv();
++tests_run;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *func6()
{
const char *result; // rax

result = func0();
++tests_run;
if ( !result )
{
result = func1();
++tests_run;
if ( !result )
{
result = func2();
++tests_run;
if ( !result )
{
result = func3();
++tests_run;
if ( !result )
{
result = func4();
++tests_run;
if ( !result )
{
result = func5();
++tests_run;
}
}
}
}
}
return result;
}

original_code:
char *test_finite_field (void)
{
 do { char *message = test_compare(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_copy(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_add(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_sub(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_mul(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_inv(); tests_run++; if (message) return message; } while (0);
 return 0;
}

canonical_original_code:
char *test_finite_field()
{
 do { char *message = test_compare(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_copy(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_add(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_sub(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_mul(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_inv(); tests_run++; if (message) return message; } while (0);
 return 0;
}


original_code:
static char *test_mul (void) {
{
 FF_NUM d;
 const FF_NUM a = {0xD249A3F4,0x22DD2A76,0xCC065A3D,0x7037BB0D,0xF5532C1C,0x19B55395,0xE4885FD0,0x26A466B2};
 const FF_NUM b = {0x05948EAA,0x49B868D2,0x9647C8A9,0x629A3803,0x33D946DC,0x7F5E1D1C,0x6E9AD671,0xECF579FE};
 const FF_NUM c = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 const FF_NUM p1 = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 const FF_NUM p2 = {0x00000047,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 const FF_NUM p3 = {0xFFFFFC2F,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 const FF_NUM r1 = {0xE5EAB34B,0x550552FF,0x91C927A3,0x7542D3D1,0xA7217062,0x72817238,0xE85F7342,0xC1981797};
 const FF_NUM r2 = {0x00000014,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 const FF_NUM r3 = {0x60BBA991,0xD28A4644,0x30CFD47F,0x571A0E25,0x2994A715,0x12902A82,0xC4744637,0x6F695E19};
 const FF_NUM r4 = {0xB2F0531D,0x873E97E0,0x2DECF6DF,0x12B8CBBD,0xCAF8C266,0x5FB8A983,0xA0D7262C,0xF78F8F6D};
 ff_mul (&d, &a, &b, &p1);
 do { if (!(ff_compare (&d, &r1) == 0)) return "ff_mul should multiply arguments (mod 2^256-1)."; } while (0);
 ff_mul (&d, &a, &b, &p2);
 do { if (!(ff_compare (&d, &r2) == 0)) return "ff_mul should multiply arguments (mod 0x47)."; } while (0);
 ff_mul (&d, &a, &c, &p1);
 do { if (!(ff_is_zero (&d))) return "ff_mul should return 0 when one of the arguments is 0."; } while (0);
 ff_mul (&d, &a, &b, &p3);
 do { if (!(ff_compare (&d, &r3) == 0)) return "ff_mul should multiply arguments (mod secp256k1 prime)."; } while (0);
 ff_copy (&d, &a);
 ff_mul (&d, &d, &d, &p1);
 do { if (!(ff_compare (&d, &r4) == 0)) return "ff_mul should allow the destination argument to be the same as the source arguments."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_mul() {
{
 struct FF_NUM d;
 struct FF_NUM a = {0xD249A3F4,0x22DD2A76,0xCC065A3D,0x7037BB0D,0xF5532C1C,0x19B55395,0xE4885FD0,0x26A466B2};
 struct FF_NUM b = {0x05948EAA,0x49B868D2,0x9647C8A9,0x629A3803,0x33D946DC,0x7F5E1D1C,0x6E9AD671,0xECF579FE};
 struct FF_NUM c = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 struct FF_NUM p1 = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 struct FF_NUM p2 = {0x00000047,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 struct FF_NUM p3 = {0xFFFFFC2F,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 struct FF_NUM r1 = {0xE5EAB34B,0x550552FF,0x91C927A3,0x7542D3D1,0xA7217062,0x72817238,0xE85F7342,0xC1981797};
 struct FF_NUM r2 = {0x00000014,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 struct FF_NUM r3 = {0x60BBA991,0xD28A4644,0x30CFD47F,0x571A0E25,0x2994A715,0x12902A82,0xC4744637,0x6F695E19};
 struct FF_NUM r4 = {0xB2F0531D,0x873E97E0,0x2DECF6DF,0x12B8CBBD,0xCAF8C266,0x5FB8A983,0xA0D7262C,0xF78F8F6D};
 ff_mul (&d, &a, &b, &p1);
 do { if (!(ff_compare (&d, &r1) == 0)) return "ff_mul should multiply arguments (mod 2^256-1)."; } while (0);
 ff_mul (&d, &a, &b, &p2);
 do { if (!(ff_compare (&d, &r2) == 0)) return "ff_mul should multiply arguments (mod 0x47)."; } while (0);
 ff_mul (&d, &a, &c, &p1);
 do { if (!(ff_is_zero (&d))) return "ff_mul should return 0 when one of the arguments is 0."; } while (0);
 ff_mul (&d, &a, &b, &p3);
 do { if (!(ff_compare (&d, &r3) == 0)) return "ff_mul should multiply arguments (mod secp256k1 prime)."; } while (0);
 ff_copy (&d, &a);
 ff_mul (&d, &d, &d, &p1);
 do { if (!(ff_compare (&d, &r4) == 0)) return "ff_mul should allow the destination argument to be the same as the source arguments."; } while (0);
}
return 0;}


original_code:
static char *test_verify (void) {
{
 const EC_POINT pubkey = {
  {{0xad3268c7,0x66e9e496,0x9c52baa0,0x337fc245,0xf29d7977,0x2c633098,0x6a882ddb,0xed541a9a}},
  {{0x3d4f2412,0x1304ce26,0xda1fc20f,0xf127283a,0xeeaabe87,0x05226d42,0x7437ccf7,0x4786717f}}
 };
 const FF_NUM r = {{0xB6A4DF24,0x95E23954,0xD7ACE345,0x1C9AD8EC,0x182A6D4A,0x93D2E9DB,0xED96E0A8,0x5C9521E0}};
 const FF_NUM s = {{0x2FA43157,0xAD57CD5C,0x8769FEB0,0x788A8A34,0x39DC5910,0x5C62F71D,0xEFFBAEAF,0xFFF839DE}};
 const uint8_t hash_str[] = {0x3d,0x66,0xae,0x70,0x09,0x4f,0x28,0xe4,0xc4,0xa2,0xc3,0xf2,0x63,0x9b,0xb5,0xf6,0x4e,0x0f,0xfb,0x1e,0x76,0x6f,0x12,0x1f,0x08,0x7b,0xac,0x81,0x92,0x52,0xd8,0x62};
 FF_NUM hash = {0};
 const FF_NUM bad_hash = {{0xDEADBEEF,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000}};
 const EC_POINT badpubkey = {{{0}},{{0}}};
 const EC_POINT badpubkey2 = {{{1}},{{2}}};
 const EC_POINT badpubkey3 = {
  {{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}},
  {{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}}
 };
 ff_deserialize (&hash, hash_str);
 do { if (!(ec_verify (&hash, &pubkey, &r, &s))) return "ec_verify should return true on a valid signature."; } while (0);
 do { if (!(!ec_verify (&bad_hash, &pubkey, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
 do { if (!(!ec_verify (&hash, &badpubkey, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
 do { if (!(!ec_verify (&hash, &badpubkey2, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
 do { if (!(!ec_verify (&hash, &badpubkey3, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_verify() {
{
 struct EC_POINT pubkey = {
  {{0xad3268c7,0x66e9e496,0x9c52baa0,0x337fc245,0xf29d7977,0x2c633098,0x6a882ddb,0xed541a9a}},
  {{0x3d4f2412,0x1304ce26,0xda1fc20f,0xf127283a,0xeeaabe87,0x05226d42,0x7437ccf7,0x4786717f}}
 };
 struct FF_NUM r = {{0xB6A4DF24,0x95E23954,0xD7ACE345,0x1C9AD8EC,0x182A6D4A,0x93D2E9DB,0xED96E0A8,0x5C9521E0}};
 struct FF_NUM s = {{0x2FA43157,0xAD57CD5C,0x8769FEB0,0x788A8A34,0x39DC5910,0x5C62F71D,0xEFFBAEAF,0xFFF839DE}};
 unsigned char hash_str[] = {0x3d,0x66,0xae,0x70,0x09,0x4f,0x28,0xe4,0xc4,0xa2,0xc3,0xf2,0x63,0x9b,0xb5,0xf6,0x4e,0x0f,0xfb,0x1e,0x76,0x6f,0x12,0x1f,0x08,0x7b,0xac,0x81,0x92,0x52,0xd8,0x62};
 struct FF_NUM hash = {0};
 struct FF_NUM bad_hash = {{0xDEADBEEF,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000}};
 struct EC_POINT badpubkey = {{{0}},{{0}}};
 struct EC_POINT badpubkey2 = {{{1}},{{2}}};
 struct EC_POINT badpubkey3 = {
  {{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}},
  {{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}}
 };
 ff_deserialize (&hash, hash_str);
 do { if (!(ec_verify (&hash, &pubkey, &r, &s))) return "ec_verify should return true on a valid signature."; } while (0);
 do { if (!(!ec_verify (&bad_hash, &pubkey, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
 do { if (!(!ec_verify (&hash, &badpubkey, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
 do { if (!(!ec_verify (&hash, &badpubkey2, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
 do { if (!(!ec_verify (&hash, &badpubkey3, &r, &s))) return "ec_verify should return false on an invalid signature."; } while (0);
}
return 0;}

variable_types: struct EC_POINT { struct FF_NUM { unsigned int z[8]; } x; }

variable_types:
r
struct FF_NUM { unsigned int z[8]; }

variable_types:
s
struct FF_NUM { unsigned int z[8]; }

variable_types:
hash
struct FF_NUM { unsigned int z[8]; }


decompiled_code:
const char *test_sign_corner()
{
char v0; // r8
const char *result; // rax
char v2; // r8
bool v3; // zf
__int128 v4[2]; // [rsp+0h] [rbp-E8h] BYREF
__int128 v5[2]; // [rsp+20h] [rbp-C8h] BYREF
char v6[32]; // [rsp+40h] [rbp-A8h] BYREF
char v7[32]; // [rsp+60h] [rbp-88h] BYREF
__int64 v8[4]; // [rsp+80h] [rbp-68h] BYREF
char v9[72]; // [rsp+A0h] [rbp-48h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v5[0] = 0LL;
v5[1] = 0LL;
LODWORD(v4[0]) = 1;
v8[0] = -1LL;
v8[1] = -1LL;
v8[2] = -1LL;
v8[3] = -1LL;
ec_mul(v9, v4, &ec_G);
ec_sign(v6, v7, v5, v4);
v0 = ec_verify(v5, v9, v6, v7);
result = "ec_sign should create a signature that can be verified with ec_verify when the private key is 1.";
if ( v0 )
{
ec_create_key(v4, v9);
ec_sign(v6, v7, v5, v4);
v2 = ec_verify(v5, v9, v6, v7);
result = "ec_sign should create a signature that can be verified with ec_verify when the hash is 0.";
if ( v2 )
{
ec_sign(v6, v7, v8, v4);
v3 = (unsigned __int8)ec_verify(v8, v9, v6, v7) == 0;
result = "ec_sign should create a signature that can be verified with ec_verify when the hash is 2^256-1.";
if ( !v3 )
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
const char *func2()
{
char v0; // r8
const char *result; // rax
char v2; // r8
bool v3; // zf
__int128 v4[2]; // [rsp+0h] [rbp-E8h] BYREF
__int128 v5[2]; // [rsp+20h] [rbp-C8h] BYREF
char v6[32]; // [rsp+40h] [rbp-A8h] BYREF
char v7[32]; // [rsp+60h] [rbp-88h] BYREF
__int64 v8[4]; // [rsp+80h] [rbp-68h] BYREF
char v9[72]; // [rsp+A0h] [rbp-48h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v5[0] = 0LL;
v5[1] = 0LL;
LODWORD(v4[0]) = 1;
v8[0] = -1LL;
v8[1] = -1LL;
v8[2] = -1LL;
v8[3] = -1LL;
ec_mul(v9, v4, &ec_G);
ec_sign(v6, v7, v5, v4);
v0 = ec_verify(v5, v9, v6, v7);
result = "ec_sign should create a signature that can be verified with ec_verify when the private key is 1.";
if ( v0 )
{
ec_create_key(v4, v9);
ec_sign(v6, v7, v5, v4);
v2 = ec_verify(v5, v9, v6, v7);
result = "ec_sign should create a signature that can be verified with ec_verify when the hash is 0.";
if ( v2 )
{
ec_sign(v6, v7, v8, v4);
v3 = (unsigned __int8)ec_verify(v8, v9, v6, v7) == 0;
result = "ec_sign should create a signature that can be verified with ec_verify when the hash is 2^256-1.";
if ( !v3 )
result = 0LL;
}
}
return result;
}

original_code:
static char *test_sign_corner (void) {
{
 EC_POINT pubkey;
 FF_NUM privkey = {0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 const FF_NUM hash = {0};
 FF_NUM r, s;
 const FF_NUM hash2 = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 ec_mul (&pubkey, &privkey, &ec_G);
 ec_sign (&r, &s, &hash, &privkey);
 do { if (!(ec_verify (&hash, &pubkey, &r, &s))) return "ec_sign should create a signature that can be verified with ec_verify when the private key is 1."; } while (0);
 ec_create_key (&privkey, &pubkey);
 ec_sign (&r, &s, &hash, &privkey);
 do { if (!(ec_verify (&hash, &pubkey, &r, &s))) return "ec_sign should create a signature that can be verified with ec_verify when the hash is 0."; } while (0);
 ec_sign (&r, &s, &hash2, &privkey);
 do { if (!(ec_verify (&hash2, &pubkey, &r, &s))) return "ec_sign should create a signature that can be verified with ec_verify when the hash is 2^256-1."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_sign_corner() {
{
 struct EC_POINT pubkey;
 struct FF_NUM privkey = {0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 struct FF_NUM hash = {0};
 struct FF_NUM r; struct FF_NUM s;
 struct FF_NUM hash2 = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
 ec_mul (&pubkey, &privkey, &ec_G);
 ec_sign (&r, &s, &hash, &privkey);
 do { if (!(ec_verify (&hash, &pubkey, &r, &s))) return "ec_sign should create a signature that can be verified with ec_verify when the private key is 1."; } while (0);
 ec_create_key (&privkey, &pubkey);
 ec_sign (&r, &s, &hash, &privkey);
 do { if (!(ec_verify (&hash, &pubkey, &r, &s))) return "ec_sign should create a signature that can be verified with ec_verify when the hash is 0."; } while (0);
 ec_sign (&r, &s, &hash2, &privkey);
 do { if (!(ec_verify (&hash2, &pubkey, &r, &s))) return "ec_sign should create a signature that can be verified with ec_verify when the hash is 2^256-1."; } while (0);
}
return 0;}

variable_types:
privkey
struct FF_NUM { unsigned int z[8]; }


decompiled_code:
unsigned int *__fastcall print_ff(unsigned int *a1)
{
unsigned int *v1; // rbx
unsigned int *result; // rax

v1 = a1 + 7;
do
{
printf("%08X", *v1);
result = v1--;
}
while ( result != a1 );
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func3(unsigned int *a1)
{
unsigned int *v1; // rbx
unsigned int *result; // rax

v1 = a1 + 7;
do
{
printf("%08X", *v1);
result = v1--;
}
while ( result != a1 );
return result;
}

original_code:
void print_ff (FF_NUM const *const a)
{
 for (int i = 7; i >= 0; --i)
  printf ("%08X", a->z[i]);
}

canonical_original_code:
void print_ff(struct FF_NUM *a)
{
 for (int i = 7; i >= 0; --i)
  printf ("%08X", a->z[i]);
}

variable_types:
a
struct FF_NUM { unsigned int z[8]; } *


decompiled_code:
const char *test_random_addmul()
{
int v0; // ebx
unsigned int v2[8]; // [rsp+0h] [rbp-1A8h] BYREF
unsigned int v3[8]; // [rsp+20h] [rbp-188h] BYREF
unsigned int v4[8]; // [rsp+40h] [rbp-168h] BYREF
unsigned int v5[8]; // [rsp+60h] [rbp-148h] BYREF
unsigned int v6[8]; // [rsp+80h] [rbp-128h] BYREF
unsigned int v7[8]; // [rsp+A0h] [rbp-108h] BYREF
unsigned int v8[8]; // [rsp+C0h] [rbp-E8h] BYREF
unsigned int v9[8]; // [rsp+E0h] [rbp-C8h] BYREF
unsigned int v10[8]; // [rsp+100h] [rbp-A8h] BYREF
unsigned int v11[8]; // [rsp+120h] [rbp-88h] BYREF
unsigned int v12[8]; // [rsp+140h] [rbp-68h] BYREF
unsigned int v13[8]; // [rsp+160h] [rbp-48h] BYREF
unsigned int v14[10]; // [rsp+180h] [rbp-28h] BYREF

v0 = 10;
while ( 1 )
{
ff_rand(v2, &ec_n);
ff_rand(v3, &ec_n);
ff_add(v4, v2, v3, &ec_n);
ec_mul(v5, v2, &ec_G);
ec_mul(v7, v3, &ec_G);
ec_mul(v9, v4, &ec_G);
ec_add(v11, v5, v7);
ec_add(v13, v7, v5);
if ( (unsigned int)ff_compare(v11, v9)
|| (unsigned int)ff_compare(v12, v10)
|| (unsigned int)ff_compare(v13, v9)
|| (unsigned int)ff_compare(v14, v10) )
{
break;
}
if ( !--v0 )
return 0LL;
}
printf("a: ");
print_ff(v2);
printf("\nb: ");
print_ff(v3);
printf("\nc: ");
print_ff(v4);
printf("\nP: 04");
print_ff(v5);
print_ff(v6);
printf("\nQ: 04");
print_ff(v7);
print_ff(v8);
printf("\nR: 04");
print_ff(v9);
print_ff(v10);
printf("\nT1: 04");
print_ff(v11);
print_ff(v12);
printf("\nT2: 04");
print_ff(v13);
print_ff(v14);
putchar(10);
return "If c = a + b is true then the following should be true: aG + bG == cG and bG + aG == cG.";
}

canonical_decompiled_code:
const char *func4()
{
int v0; // ebx
unsigned int v2[8]; // [rsp+0h] [rbp-1A8h] BYREF
unsigned int v3[8]; // [rsp+20h] [rbp-188h] BYREF
unsigned int v4[8]; // [rsp+40h] [rbp-168h] BYREF
unsigned int v5[8]; // [rsp+60h] [rbp-148h] BYREF
unsigned int v6[8]; // [rsp+80h] [rbp-128h] BYREF
unsigned int v7[8]; // [rsp+A0h] [rbp-108h] BYREF
unsigned int v8[8]; // [rsp+C0h] [rbp-E8h] BYREF
unsigned int v9[8]; // [rsp+E0h] [rbp-C8h] BYREF
unsigned int v10[8]; // [rsp+100h] [rbp-A8h] BYREF
unsigned int v11[8]; // [rsp+120h] [rbp-88h] BYREF
unsigned int v12[8]; // [rsp+140h] [rbp-68h] BYREF
unsigned int v13[8]; // [rsp+160h] [rbp-48h] BYREF
unsigned int v14[10]; // [rsp+180h] [rbp-28h] BYREF

v0 = 10;
while ( 1 )
{
ff_rand(v2, &ec_n);
ff_rand(v3, &ec_n);
ff_add(v4, v2, v3, &ec_n);
ec_mul(v5, v2, &ec_G);
ec_mul(v7, v3, &ec_G);
ec_mul(v9, v4, &ec_G);
ec_add(v11, v5, v7);
ec_add(v13, v7, v5);
if ( (unsigned int)ff_compare(v11, v9)
|| (unsigned int)ff_compare(v12, v10)
|| (unsigned int)ff_compare(v13, v9)
|| (unsigned int)ff_compare(v14, v10) )
{
break;
}
if ( !--v0 )
return 0LL;
}
printf("a: ");
func3(v2);
printf("\nb: ");
func3(v3);
printf("\nc: ");
func3(v4);
printf("\nP: 04");
func3(v5);
func3(v6);
printf("\nQ: 04");
func3(v7);
func3(v8);
printf("\nR: 04");
func3(v9);
func3(v10);
printf("\nT1: 04");
func3(v11);
func3(v12);
printf("\nT2: 04");
func3(v13);
func3(v14);
putchar(10);
return "If c = a + b is true then the following should be true: aG + bG == cG and bG + aG == cG.";
}

original_code:
static char *test_random_addmul (void) {
{
 FF_NUM a, b, c;
 EC_POINT P, Q, R, T1, T2;
 for (int passes = 0; passes < 10; ++passes)
 {
  ff_rand (&a, &ec_n);
  ff_rand (&b, &ec_n);
  ff_add (&c, &a, &b, &ec_n);
  ec_mul (&P, &a, &ec_G);
  ec_mul (&Q, &b, &ec_G);
  ec_mul (&R, &c, &ec_G);
  ec_add (&T1, &P, &Q);
  ec_add (&T2, &Q, &P);
  if (ff_compare (&(T1.x), &(R.x)) != 0 || ff_compare (&(T1.y), &(R.y)) != 0 || ff_compare (&(T2.x), &(R.x)) != 0 || ff_compare (&(T2.y), &(R.y)) != 0)
  {
   printf ("a: ");
   print_ff (&a);
   printf ("\nb: ");
   print_ff (&b);
   printf ("\nc: ");
   print_ff (&c);
   printf ("\nP: 04");
   print_ff (&(P.x));
   print_ff (&(P.y));
   printf ("\nQ: 04");
   print_ff (&(Q.x));
   print_ff (&(Q.y));
   printf ("\nR: 04");
   print_ff (&(R.x));
   print_ff (&(R.y));
   printf ("\nT1: 04");
   print_ff (&(T1.x));
   print_ff (&(T1.y));
   printf ("\nT2: 04");
   print_ff (&(T2.x));
   print_ff (&(T2.y));
   printf ("\n");
   return "If c = a + b is true then the following should be true: aG + bG == cG and bG + aG == cG.";
  }
 }
}
return 0;}

canonical_original_code:
static char *test_random_addmul() {
{
 struct FF_NUM a; struct FF_NUM b; struct FF_NUM c;
 struct EC_POINT P; struct EC_POINT Q; struct EC_POINT R; struct EC_POINT T1; struct EC_POINT T2;
 for (int passes = 0; passes < 10; ++passes)
 {
  ff_rand (&a, &ec_n);
  ff_rand (&b, &ec_n);
  ff_add (&c, &a, &b, &ec_n);
  ec_mul (&P, &a, &ec_G);
  ec_mul (&Q, &b, &ec_G);
  ec_mul (&R, &c, &ec_G);
  ec_add (&T1, &P, &Q);
  ec_add (&T2, &Q, &P);
  if (ff_compare (&(T1.x), &(R.x)) != 0 || ff_compare (&(T1.y), &(R.y)) != 0 || ff_compare (&(T2.x), &(R.x)) != 0 || ff_compare (&(T2.y), &(R.y)) != 0)
  {
   printf ("a: ");
   print_ff (&a);
   printf ("\nb: ");
   print_ff (&b);
   printf ("\nc: ");
   print_ff (&c);
   printf ("\nP: 04");
   print_ff (&(P.x));
   print_ff (&(P.y));
   printf ("\nQ: 04");
   print_ff (&(Q.x));
   print_ff (&(Q.y));
   printf ("\nR: 04");
   print_ff (&(R.x));
   print_ff (&(R.y));
   printf ("\nT1: 04");
   print_ff (&(T1.x));
   print_ff (&(T1.y));
   printf ("\nT2: 04");
   print_ff (&(T2.x));
   print_ff (&(T2.y));
   printf ("\n");
   return "If c = a + b is true then the following should be true: aG + bG == cG and bG + aG == cG.";
  }
 }
}
return 0;}

variable_types: passes int


decompiled_code:
const char *test_random_sign()
{
int v0; // ebx
unsigned int v2[8]; // [rsp-20h] [rbp-E8h] BYREF
unsigned int v3[8]; // [rsp+0h] [rbp-C8h] BYREF
unsigned int v4[8]; // [rsp+20h] [rbp-A8h] BYREF
unsigned int v5[8]; // [rsp+40h] [rbp-88h] BYREF
__int128 v6[2]; // [rsp+60h] [rbp-68h] BYREF
unsigned int v7[8]; // [rsp+80h] [rbp-48h] BYREF
unsigned int v8[10]; // [rsp+A0h] [rbp-28h] BYREF

v0 = 10;
v6[0] = 0LL;
v6[1] = 0LL;
while ( 1 )
{
ec_create_key(v2, v7);
ff_rand(v3, v6);
ec_sign(v4, v5, v3, v2);
if ( !(unsigned __int8)ec_verify(v3, v7, v4, v5) )
break;
if ( !--v0 )
return 0LL;
}
printf("ec_sign failed to create a signature that could be verified with ec_verify.");
printf("Private Key: ");
print_ff(v2);
printf("\nPublic Key: 04");
print_ff(v7);
print_ff(v8);
printf("\nHash: ");
print_ff(v3);
printf("\nr: ");
print_ff(v4);
printf("\ns: ");
print_ff(v5);
putchar(10);
return "ec_sign should create a signature that can be verified with ec_verify for all possible hash values.";
}

canonical_decompiled_code:
const char *func5()
{
int v0; // ebx
unsigned int v2[8]; // [rsp-20h] [rbp-E8h] BYREF
unsigned int v3[8]; // [rsp+0h] [rbp-C8h] BYREF
unsigned int v4[8]; // [rsp+20h] [rbp-A8h] BYREF
unsigned int v5[8]; // [rsp+40h] [rbp-88h] BYREF
__int128 v6[2]; // [rsp+60h] [rbp-68h] BYREF
unsigned int v7[8]; // [rsp+80h] [rbp-48h] BYREF
unsigned int v8[10]; // [rsp+A0h] [rbp-28h] BYREF

v0 = 10;
v6[0] = 0LL;
v6[1] = 0LL;
while ( 1 )
{
ec_create_key(v2, v7);
ff_rand(v3, v6);
ec_sign(v4, v5, v3, v2);
if ( !(unsigned __int8)ec_verify(v3, v7, v4, v5) )
break;
if ( !--v0 )
return 0LL;
}
printf("ec_sign failed to create a signature that could be verified with ec_verify.");
printf("Private Key: ");
func3(v2);
printf("\nPublic Key: 04");
func3(v7);
func3(v8);
printf("\nHash: ");
func3(v3);
printf("\nr: ");
func3(v4);
printf("\ns: ");
func3(v5);
putchar(10);
return "ec_sign should create a signature that can be verified with ec_verify for all possible hash values.";
}

original_code:
static char *test_random_sign (void) {
{
 EC_POINT pubkey;
 FF_NUM privkey, hash, r, s;
 const FF_NUM max_hash = {0};
 for (int passes = 0; passes < 10; ++passes)
 {
  ec_create_key (&privkey, &pubkey);
  ff_rand (&hash, &max_hash);
  ec_sign (&r, &s, &hash, &privkey);
  if (!ec_verify (&hash, &pubkey, &r, &s))
  {
   printf ("ec_sign failed to create a signature that could be verified with ec_verify.");
   printf ("Private Key: ");
   print_ff (&privkey);
   printf ("\nPublic Key: 04");
   print_ff (&(pubkey.x));
   print_ff (&(pubkey.y));
   printf ("\nHash: ");
   print_ff (&hash);
   printf ("\nr: ");
   print_ff (&r);
   printf ("\ns: ");
   print_ff (&s);
   printf ("\n");
   return "ec_sign should create a signature that can be verified with ec_verify for all possible hash values.";
  }
 }
}
return 0;}

canonical_original_code:
static char *test_random_sign() {
{
 struct EC_POINT pubkey;
 struct FF_NUM privkey; struct FF_NUM hash; struct FF_NUM r; struct FF_NUM s;
 struct FF_NUM max_hash = {0};
 for (int passes = 0; passes < 10; ++passes)
 {
  ec_create_key (&privkey, &pubkey);
  ff_rand (&hash, &max_hash);
  ec_sign (&r, &s, &hash, &privkey);
  if (!ec_verify (&hash, &pubkey, &r, &s))
  {
   printf ("ec_sign failed to create a signature that could be verified with ec_verify.");
   printf ("Private Key: ");
   print_ff (&privkey);
   printf ("\nPublic Key: 04");
   print_ff (&(pubkey.x));
   print_ff (&(pubkey.y));
   printf ("\nHash: ");
   print_ff (&hash);
   printf ("\nr: ");
   print_ff (&r);
   printf ("\ns: ");
   print_ff (&s);
   printf ("\n");
   return "ec_sign should create a signature that can be verified with ec_verify for all possible hash values.";
  }
 }
}
return 0;}


decompiled_code:
const char *test_ecdsa()
{
const char *result; // rax

result = test_mul();
++tests_run;
if ( !result )
{
result = test_random_addmul();
++tests_run;
if ( !result )
{
result = test_verify();
++tests_run;
if ( !result )
{
result = test_sign_corner();
++tests_run;
if ( !result )
{
result = test_random_sign();
++tests_run;
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *func6()
{
const char *result; // rax

result = func0();
++tests_run;
if ( !result )
{
result = func4();
++tests_run;
if ( !result )
{
result = func1();
++tests_run;
if ( !result )
{
result = func2();
++tests_run;
if ( !result )
{
result = func5();
++tests_run;
}
}
}
}
return result;
}

original_code:
char *test_ecdsa (void)
{
 do { char *message = test_mul(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_random_addmul(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_verify(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_sign_corner(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_random_sign(); tests_run++; if (message) return message; } while (0);
 return 0;
}

canonical_original_code:
char *test_ecdsa()
{
 do { char *message = test_mul(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_random_addmul(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_verify(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_sign_corner(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_random_sign(); tests_run++; if (message) return message; } while (0);
 return 0;
}


decompiled_code:
const char *test_mul()
{
const char *result; // rax
__int64 v1[4]; // [rsp+0h] [rbp-148h] BYREF
__int64 v2[4]; // [rsp+20h] [rbp-128h] BYREF
__int64 v3[4]; // [rsp+40h] [rbp-108h] BYREF
__int64 v4[4]; // [rsp+60h] [rbp-E8h] BYREF
__int64 v5[4]; // [rsp+80h] [rbp-C8h] BYREF
__int64 v6[4]; // [rsp+A0h] [rbp-A8h] BYREF
__int128 v7[2]; // [rsp+C0h] [rbp-88h] BYREF
__int128 v8[2]; // [rsp+E0h] [rbp-68h] BYREF
char v9[32]; // [rsp+100h] [rbp-48h] BYREF
char v10[40]; // [rsp+120h] [rbp-28h] BYREF

v1[0] = 0x8EE3C2613BF99522LL;
v1[1] = 0x624D4CC0FA157859LL;
v1[2] = 0xA65527F7290311A3LL;
v1[3] = 0xAA5E28D6A97A2479LL;
v2[0] = 0xCFACDFA239FF49C6LL;
v2[1] = 0x99AA0AD9FD54EBCLL;
v2[2] = 0x3D192B3C5133A6BALL;
v2[3] = 0x34F9460F0E4F0839LL;
v3[0] = 0x1BB419E0F2CA232LL;
v3[1] = 0x7728A960686CB5A9LL;
v3[2] = 0x23F6D25A7A91E7DDLL;
v3[3] = 0xB71EA9BD730FD89LL;
v4[0] = 0x7E1E181E4DEECCECLL;
v4[1] = 0x44B8A0524C42422ALL;
v4[2] = 0xEFFF13EE4AD44C40LL;
v4[3] = 0x376A3A2CDCD12581LL;
v5[0] = 0x415EE4FE987DABA1LL;
v5[1] = 0xFED471EF3AA60A3ELL;
v5[2] = 0x92E5B36C81372CA6LL;
v5[3] = 0x14890E61FCD4B0BDLL;
v6[0] = 0xE66ADC272263F982LL;
v6[1] = 0xD1C2B7B0DBE23397LL;
v6[2] = 0x2D3BCA67EE0EB6DCLL;
v7[0] = 0LL;
v6[3] = 0x297B858D9F752AB4LL;
LODWORD(v7[0]) = 1;
v7[1] = 0LL;
v8[0] = 0LL;
v8[1] = 0LL;
ec_mul(v9, v1, &ec_G);
if ( (unsigned int)ff_compare(v9, v2) )
return "ec_mul should multiply G by a scalar value.";
if ( (unsigned int)ff_compare(v10, v3) )
return "ec_mul should multiply G by a scalar value.";
ec_mul(v9, v4, &ec_G);
if ( (unsigned int)ff_compare(v9, v5) || (unsigned int)ff_compare(v10, v6) )
return "ec_mul should multiply G by a scalar value.";
ec_mul(v9, v7, &ec_G);
if ( (unsigned int)ff_compare(v9, &ec_G) || (unsigned int)ff_compare(v10, (unsigned int)((_DWORD)&ec_G + 32)) )
return "ec_mul should return G when multiplying G by 1.";
ec_mul(v9, v8, &ec_G);
if ( !(unsigned __int8)ff_is_zero(v9) || !(unsigned __int8)ff_is_zero(v9) )
return "ec_mul should return Infinity when multiply G by n.";
ec_mul(v9, &ec_n, &ec_G);
if ( (unsigned __int8)ff_is_zero(v9) && (unsigned __int8)ff_is_zero(v10) )
result = 0LL;
else
result = "ec_mul should return Infinity when multiplying G by n.";
return result;
}

canonical_decompiled_code:
const char *func0()
{
const char *result; // rax
__int64 v1[4]; // [rsp+0h] [rbp-148h] BYREF
__int64 v2[4]; // [rsp+20h] [rbp-128h] BYREF
__int64 v3[4]; // [rsp+40h] [rbp-108h] BYREF
__int64 v4[4]; // [rsp+60h] [rbp-E8h] BYREF
__int64 v5[4]; // [rsp+80h] [rbp-C8h] BYREF
__int64 v6[4]; // [rsp+A0h] [rbp-A8h] BYREF
__int128 v7[2]; // [rsp+C0h] [rbp-88h] BYREF
__int128 v8[2]; // [rsp+E0h] [rbp-68h] BYREF
char v9[32]; // [rsp+100h] [rbp-48h] BYREF
char v10[40]; // [rsp+120h] [rbp-28h] BYREF

v1[0] = 0x8EE3C2613BF99522LL;
v1[1] = 0x624D4CC0FA157859LL;
v1[2] = 0xA65527F7290311A3LL;
v1[3] = 0xAA5E28D6A97A2479LL;
v2[0] = 0xCFACDFA239FF49C6LL;
v2[1] = 0x99AA0AD9FD54EBCLL;
v2[2] = 0x3D192B3C5133A6BALL;
v2[3] = 0x34F9460F0E4F0839LL;
v3[0] = 0x1BB419E0F2CA232LL;
v3[1] = 0x7728A960686CB5A9LL;
v3[2] = 0x23F6D25A7A91E7DDLL;
v3[3] = 0xB71EA9BD730FD89LL;
v4[0] = 0x7E1E181E4DEECCECLL;
v4[1] = 0x44B8A0524C42422ALL;
v4[2] = 0xEFFF13EE4AD44C40LL;
v4[3] = 0x376A3A2CDCD12581LL;
v5[0] = 0x415EE4FE987DABA1LL;
v5[1] = 0xFED471EF3AA60A3ELL;
v5[2] = 0x92E5B36C81372CA6LL;
v5[3] = 0x14890E61FCD4B0BDLL;
v6[0] = 0xE66ADC272263F982LL;
v6[1] = 0xD1C2B7B0DBE23397LL;
v6[2] = 0x2D3BCA67EE0EB6DCLL;
v7[0] = 0LL;
v6[3] = 0x297B858D9F752AB4LL;
LODWORD(v7[0]) = 1;
v7[1] = 0LL;
v8[0] = 0LL;
v8[1] = 0LL;
ec_mul(v9, v1, &ec_G);
if ( (unsigned int)ff_compare(v9, v2) )
return "ec_mul should multiply G by a scalar value.";
if ( (unsigned int)ff_compare(v10, v3) )
return "ec_mul should multiply G by a scalar value.";
ec_mul(v9, v4, &ec_G);
if ( (unsigned int)ff_compare(v9, v5) || (unsigned int)ff_compare(v10, v6) )
return "ec_mul should multiply G by a scalar value.";
ec_mul(v9, v7, &ec_G);
if ( (unsigned int)ff_compare(v9, &ec_G) || (unsigned int)ff_compare(v10, (unsigned int)((_DWORD)&ec_G + 32)) )
return "ec_mul should return G when multiplying G by 1.";
ec_mul(v9, v8, &ec_G);
if ( !(unsigned __int8)ff_is_zero(v9) || !(unsigned __int8)ff_is_zero(v9) )
return "ec_mul should return Infinity when multiply G by n.";
ec_mul(v9, &ec_n, &ec_G);
if ( (unsigned __int8)ff_is_zero(v9) && (unsigned __int8)ff_is_zero(v10) )
result = 0LL;
else
result = "ec_mul should return Infinity when multiplying G by n.";
return result;
}

original_code:
static char *test_mul (void) {
{
 const FF_NUM m1 = {0x3BF99522,0x8EE3C261,0xFA157859,0x624D4CC0,0x290311A3,0xA65527F7,0xA97A2479,0xAA5E28D6};
 const FF_NUM X1 = {0x39FF49C6,0xCFACDFA2,0x9FD54EBC,0x099AA0AD,0x5133A6BA,0x3D192B3C,0x0E4F0839,0x34F9460F};
 const FF_NUM Y1 = {0x0F2CA232,0x01BB419E,0x686CB5A9,0x7728A960,0x7A91E7DD,0x23F6D25A,0xD730FD89,0x0B71EA9B};
 const FF_NUM m2 = {0x4DEECCEC,0x7E1E181E,0x4C42422A,0x44B8A052,0x4AD44C40,0xEFFF13EE,0xDCD12581,0x376A3A2C};
 const FF_NUM X2 = {0x987DABA1,0x415EE4FE,0x3AA60A3E,0xFED471EF,0x81372CA6,0x92E5B36C,0xFCD4B0BD,0x14890E61};
 const FF_NUM Y2 = {0x2263F982,0xE66ADC27,0xDBE23397,0xD1C2B7B0,0xEE0EB6DC,0x2D3BCA67,0x9F752AB4,0x297B858D};
 const FF_NUM m3 = {0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 const FF_NUM m4 = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 EC_POINT Q;
 ec_mul (&Q, &m1, &ec_G);
 do { if (!(ff_compare (&(Q.x), &X1) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 do { if (!(ff_compare (&(Q.y), &Y1) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 ec_mul (&Q, &m2, &ec_G);
 do { if (!(ff_compare (&(Q.x), &X2) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 do { if (!(ff_compare (&(Q.y), &Y2) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 ec_mul (&Q, &m3, &ec_G);
 do { if (!(ff_compare (&(Q.x), &(ec_G.x)) == 0)) return "ec_mul should return G when multiplying G by 1."; } while (0);
 do { if (!(ff_compare (&(Q.y), &(ec_G.y)) == 0)) return "ec_mul should return G when multiplying G by 1."; } while (0);
 ec_mul (&Q, &m4, &ec_G);
 do { if (!(ff_is_zero (&(Q.x)))) return "ec_mul should return Infinity when multiply G by n."; } while (0);
 do { if (!(ff_is_zero (&(Q.x)))) return "ec_mul should return Infinity when multiply G by n."; } while (0);
 ec_mul (&Q, &ec_n, &ec_G);
 do { if (!(ff_is_zero (&(Q.x)))) return "ec_mul should return Infinity when multiplying G by n."; } while (0);
 do { if (!(ff_is_zero (&(Q.y)))) return "ec_mul should return Infinity when multiplying G by n."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_mul() {
{
 struct FF_NUM m1 = {0x3BF99522,0x8EE3C261,0xFA157859,0x624D4CC0,0x290311A3,0xA65527F7,0xA97A2479,0xAA5E28D6};
 struct FF_NUM X1 = {0x39FF49C6,0xCFACDFA2,0x9FD54EBC,0x099AA0AD,0x5133A6BA,0x3D192B3C,0x0E4F0839,0x34F9460F};
 struct FF_NUM Y1 = {0x0F2CA232,0x01BB419E,0x686CB5A9,0x7728A960,0x7A91E7DD,0x23F6D25A,0xD730FD89,0x0B71EA9B};
 struct FF_NUM m2 = {0x4DEECCEC,0x7E1E181E,0x4C42422A,0x44B8A052,0x4AD44C40,0xEFFF13EE,0xDCD12581,0x376A3A2C};
 struct FF_NUM X2 = {0x987DABA1,0x415EE4FE,0x3AA60A3E,0xFED471EF,0x81372CA6,0x92E5B36C,0xFCD4B0BD,0x14890E61};
 struct FF_NUM Y2 = {0x2263F982,0xE66ADC27,0xDBE23397,0xD1C2B7B0,0xEE0EB6DC,0x2D3BCA67,0x9F752AB4,0x297B858D};
 struct FF_NUM m3 = {0x00000001,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 struct FF_NUM m4 = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
 struct EC_POINT Q;
 ec_mul (&Q, &m1, &ec_G);
 do { if (!(ff_compare (&(Q.x), &X1) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 do { if (!(ff_compare (&(Q.y), &Y1) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 ec_mul (&Q, &m2, &ec_G);
 do { if (!(ff_compare (&(Q.x), &X2) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 do { if (!(ff_compare (&(Q.y), &Y2) == 0)) return "ec_mul should multiply G by a scalar value."; } while (0);
 ec_mul (&Q, &m3, &ec_G);
 do { if (!(ff_compare (&(Q.x), &(ec_G.x)) == 0)) return "ec_mul should return G when multiplying G by 1."; } while (0);
 do { if (!(ff_compare (&(Q.y), &(ec_G.y)) == 0)) return "ec_mul should return G when multiplying G by 1."; } while (0);
 ec_mul (&Q, &m4, &ec_G);
 do { if (!(ff_is_zero (&(Q.x)))) return "ec_mul should return Infinity when multiply G by n."; } while (0);
 do { if (!(ff_is_zero (&(Q.x)))) return "ec_mul should return Infinity when multiply G by n."; } while (0);
 ec_mul (&Q, &ec_n, &ec_G);
 do { if (!(ff_is_zero (&(Q.x)))) return "ec_mul should return Infinity when multiplying G by n."; } while (0);
 do { if (!(ff_is_zero (&(Q.y)))) return "ec_mul should return Infinity when multiplying G by n."; } while (0);
}
return 0;}