decompiled_code:
const char *test_aes_256_ctr()
{
int v0; // edx
const char *result; // rax
int v2; // edx
__int64 v3[2]; // [rsp+0h] [rbp-108h] BYREF
__int64 v4[4]; // [rsp+10h] [rbp-F8h] BYREF
__int64 v5[8]; // [rsp+30h] [rbp-D8h] BYREF
__int64 s2[8]; // [rsp+70h] [rbp-98h] BYREF
__int64 s1[11]; // [rsp+B0h] [rbp-58h] BYREF

v4[0] = 0xBE71CA1510EB3D60LL;
v4[1] = 0x81777D85F0AE732BLL;
v4[2] = 0xD708613B072C351FLL;
v4[3] = 0xF4DF1409A310982DLL;
v3[0] = 0xF7F6F5F4F3F2F1F0LL;
v3[1] = 0xFFFEFDFCFBFAF9F8LL;
v5[0] = 0x969F402EE2BEC16BLL;
v5[1] = 0x2A179373117E3DE9LL;
v5[2] = 0x9CAC031E578A2DAELL;
v5[3] = 0x518EAF45AC6FB79ELL;
v5[4] = 0x11E45CA3461CC830LL;
v5[5] = 0xEF520A1A19C1FBE5LL;
v5[6] = 0x179B4FDF45249FF6LL;
v5[7] = 0x10376CE67B412BADLL;
s2[0] = 0xA589577713C31E60LL;
s2[1] = 0x28D2F3BB04F5A7B7LL;
s2[2] = 0x9AB5624DCAE343F4LL;
s2[3] = 0xC5F5CACA90E984CALL;
s2[4] = 0x4CE93DA2DA30092BLL;
s2[5] = 0x8D98842DBA1770E8LL;
s2[6] = 0xA6AD7AB68DC5C9DFLL;
s2[7] = 0xA641794508DDC213LL;
memset(s1, 85, 65);
aes256_crypt_ctr(s1, v4, v3, v5, 64LL);
v0 = memcmp(s1, s2, 0x40uLL);
result = "aes_crypt_ctr should correctly encrypt the test vectors.";
if ( !v0 )
{
aes256_crypt_ctr(s1, v4, v3, s1, 64LL);
v2 = memcmp(s1, v5, 0x40uLL);
result = "aes_crypt_ctr should correctly decrypt the test vectors.";
if ( !v2 )
{
result = "aes_crypt_ctr should not write more than len bytes to the destination array.";
if ( LOBYTE(s1[8]) == 85 )
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
const char *func1()
{
int v0; // edx
const char *result; // rax
int v2; // edx
__int64 v3[2]; // [rsp+0h] [rbp-108h] BYREF
__int64 v4[4]; // [rsp+10h] [rbp-F8h] BYREF
__int64 v5[8]; // [rsp+30h] [rbp-D8h] BYREF
__int64 s2[8]; // [rsp+70h] [rbp-98h] BYREF
__int64 s1[11]; // [rsp+B0h] [rbp-58h] BYREF

v4[0] = 0xBE71CA1510EB3D60LL;
v4[1] = 0x81777D85F0AE732BLL;
v4[2] = 0xD708613B072C351FLL;
v4[3] = 0xF4DF1409A310982DLL;
v3[0] = 0xF7F6F5F4F3F2F1F0LL;
v3[1] = 0xFFFEFDFCFBFAF9F8LL;
v5[0] = 0x969F402EE2BEC16BLL;
v5[1] = 0x2A179373117E3DE9LL;
v5[2] = 0x9CAC031E578A2DAELL;
v5[3] = 0x518EAF45AC6FB79ELL;
v5[4] = 0x11E45CA3461CC830LL;
v5[5] = 0xEF520A1A19C1FBE5LL;
v5[6] = 0x179B4FDF45249FF6LL;
v5[7] = 0x10376CE67B412BADLL;
s2[0] = 0xA589577713C31E60LL;
s2[1] = 0x28D2F3BB04F5A7B7LL;
s2[2] = 0x9AB5624DCAE343F4LL;
s2[3] = 0xC5F5CACA90E984CALL;
s2[4] = 0x4CE93DA2DA30092BLL;
s2[5] = 0x8D98842DBA1770E8LL;
s2[6] = 0xA6AD7AB68DC5C9DFLL;
s2[7] = 0xA641794508DDC213LL;
memset(s1, 85, 65);
aes256_crypt_ctr(s1, v4, v3, v5, 64LL);
v0 = memcmp(s1, s2, 0x40uLL);
result = "aes_crypt_ctr should correctly encrypt the test vectors.";
if ( !v0 )
{
aes256_crypt_ctr(s1, v4, v3, s1, 64LL);
v2 = memcmp(s1, v5, 0x40uLL);
result = "aes_crypt_ctr should correctly decrypt the test vectors.";
if ( !v2 )
{
result = "aes_crypt_ctr should not write more than len bytes to the destination array.";
if ( LOBYTE(s1[8]) == 85 )
result = 0LL;
}
}
return result;
}

original_code:
static char *test_aes_256_ctr (void) {
{
 uint8_t key1[32] = {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
                     0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4};
 uint8_t iv1[16] = {0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff};
 uint8_t plaintext1[] = {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
                        0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
          0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
          0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10};
 uint8_t ciphertext1[] = {0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
                          0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
     0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
     0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6};
 uint8_t ciphertext[sizeof(ciphertext1)+1] = {0};
 memset (ciphertext, 0x55, sizeof (ciphertext));
 aes256_crypt_ctr (ciphertext, key1, iv1, plaintext1, sizeof (ciphertext1));
 do { if (!(memcmp (ciphertext, ciphertext1, sizeof (ciphertext1)) == 0)) return "aes_crypt_ctr should correctly encrypt the test vectors."; } while (0);
 aes256_crypt_ctr (ciphertext, key1, iv1, ciphertext, sizeof (ciphertext1));
 do { if (!(memcmp (ciphertext, plaintext1, sizeof (plaintext1)) == 0)) return "aes_crypt_ctr should correctly decrypt the test vectors."; } while (0);
 do { if (!(ciphertext[sizeof(ciphertext)-1] == 0x55)) return "aes_crypt_ctr should not write more than len bytes to the destination array."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_aes_256_ctr() {
{
 unsigned char key1[32] = {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
                     0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4};
 unsigned char iv1[16] = {0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff};
 unsigned char plaintext1[] = {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
                        0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
          0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
          0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10};
 unsigned char ciphertext1[] = {0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
                          0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
     0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
     0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6};
 unsigned char ciphertext[-1] = {0};
 memset (ciphertext, 0x55, sizeof (ciphertext));
 aes256_crypt_ctr (ciphertext, key1, iv1, plaintext1, sizeof (ciphertext1));
 do { if (!(memcmp (ciphertext, ciphertext1, sizeof (ciphertext1)) == 0)) return "aes_crypt_ctr should correctly encrypt the test vectors."; } while (0);
 aes256_crypt_ctr (ciphertext, key1, iv1, ciphertext, sizeof (ciphertext1));
 do { if (!(memcmp (ciphertext, plaintext1, sizeof (plaintext1)) == 0)) return "aes_crypt_ctr should correctly decrypt the test vectors."; } while (0);
 do { if (!(ciphertext[sizeof(ciphertext)-1] == 0x55)) return "aes_crypt_ctr should not write more than len bytes to the destination array."; } while (0);
}
return 0;}

variable_types:
ciphertext
unsigned char [-1]


repo: fpgaminer/strong-arm

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

result = test_aes_256_block();
++tests_run;
if ( !result )
{
result = test_aes_256_ctr();
++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_aes (void)
{
 do { char *message = test_aes_256_block(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_aes_256_ctr(); tests_run++; if (message) return message; } while (0);
 return 0;
}

canonical_original_code:
char *test_aes()
{
 do { char *message = test_aes_256_block(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_aes_256_ctr(); tests_run++; if (message) return message; } while (0);
 return 0;
}

variable_types:
message
char *

return_type: char *


original_code:
static void HMAC_DRBG_Update (DRBG_STATE *const state, uint8_t const *const provided_data)
{
 uint8_t temp[129];
 memmove (temp, state->V, 32);
 temp[32] = 0x00;
 if (provided_data)
  memmove (temp + 33, provided_data, 96);
 HMAC (state->K, state->K, 32, temp, provided_data ? 129 : 33);
 HMAC (state->V, state->K, 32, state->V, 32);
 if (!provided_data)
  return;
 memmove (temp, state->V, 32);
 temp[32] = 0x01;
 HMAC (state->K, state->K, 32, temp, 129);
 HMAC (state->V, state->K, 32, state->V, 32);
}

canonical_original_code:
static void HMAC_DRBG_Update(struct DRBG_STATE *state, unsigned char *provided_data)
{
 unsigned char temp[129];
 memmove (temp, state->V, 32);
 temp[32] = 0x00;
 if (provided_data)
  memmove (temp + 33, provided_data, 96);
 HMAC (state->K, state->K, 32, temp, provided_data ? 129 : 33);
 HMAC (state->V, state->K, 32, state->V, 32);
 if (!provided_data)
  return;
 memmove (temp, state->V, 32);
 temp[32] = 0x01;
 HMAC (state->K, state->K, 32, temp, 129);
 HMAC (state->V, state->K, 32, state->V, 32);
}

variable_types: struct DRBG_STATE { unsigned char initialized; unsigned char K[32]; } *

variable_types:
temp
unsigned char [129]

return_type: void


decompiled_code:
__int64 __fastcall HMAC_DRBG_Generate(void *dest, _BYTE *a2)
{
if ( *a2 != 48 )
error_state();
HMAC(a2 + 33, a2 + 1, 32LL, a2 + 33, 32LL);
memmove(dest, a2 + 33, 0x20uLL);
return HMAC_DRBG_Update((__int64)a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(void *dest, _BYTE *a2)
{
if ( *a2 != 48 )
error_state();
HMAC(a2 + 33, a2 + 1, 32LL, a2 + 33, 32LL);
memmove(dest, a2 + 33, 0x20uLL);
return func0((__int64)a2, 0LL);
}

original_code:
void HMAC_DRBG_Generate (uint8_t *const dst, DRBG_STATE *const state)
{
 if (state->initialized != 0x30)
  error_state ();
 HMAC (state->V, state->K, 32, state->V, 32);
 memmove (dst, state->V, 32);
 HMAC_DRBG_Update (state, 0);
}

canonical_original_code:
void HMAC_DRBG_Generate(unsigned char *dst, struct DRBG_STATE *state)
{
 if (state->initialized != 0x30)
  error_state ();
 HMAC (state->V, state->K, 32, state->V, 32);
 memmove (dst, state->V, 32);
 HMAC_DRBG_Update (state, 0);
}

variable_types:
dst
unsigned char *

user_defined_types: struct DRBG_STATE { unsigned char initialized; unsigned char K[32]; }


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

result = test_vectors();
++tests_run;
return result;
}

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

result = func0();
++tests_run;
return result;
}

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

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


variable_types: struct DRBG_STATE { unsigned char initialized; unsigned char K[32]; }

variable_types:
result
unsigned char [33]

variable_types: i int


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

result = test_vectors();
++tests_run;
return result;
}

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

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


decompiled_code:
const char *test_vectors()
{
int v0; // edx
const char *result; // rax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx
__int64 v6; // [rsp+17h] [rbp-2E9h] BYREF
char v7[9]; // [rsp+1Fh] [rbp-2E1h] BYREF
_QWORD v8[2]; // [rsp+28h] [rbp-2D8h] BYREF
__int64 v9[2]; // [rsp+38h] [rbp-2C8h] BYREF
char v10[32]; // [rsp+48h] [rbp-2B8h] BYREF
char v11[32]; // [rsp+68h] [rbp-298h] BYREF
char v12[32]; // [rsp+88h] [rbp-278h] BYREF
char v13[32]; // [rsp+A8h] [rbp-258h] BYREF
__int64 s2[4]; // [rsp+C8h] [rbp-238h] BYREF
__int64 v15[4]; // [rsp+E8h] [rbp-218h] BYREF
__int64 v16[4]; // [rsp+108h] [rbp-1F8h] BYREF
__int64 v17[4]; // [rsp+128h] [rbp-1D8h] BYREF
__int64 v18[4]; // [rsp+148h] [rbp-1B8h] BYREF
__int64 v19[4]; // [rsp+168h] [rbp-198h] BYREF
__int64 v20[7]; // [rsp+188h] [rbp-178h] BYREF
int v21; // [rsp+1C0h] [rbp-140h]
__int64 v22[8]; // [rsp+1C8h] [rbp-138h] BYREF
__int64 s1[10]; // [rsp+208h] [rbp-F8h] BYREF
char v24[80]; // [rsp+258h] [rbp-A8h] BYREF
char v25[88]; // [rsp+2A8h] [rbp-58h] BYREF

strcpy(v11, "This passphrase is a secret.");
v6 = 0x777AEDE1B3CE4CEDLL;
strcpy(v7, "password");
strcpy(v10, "ATHENA.MIT.EDUraeburn");
strcpy(v24, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
strcpy(v12, "pass phrase equals block size");
strcpy(v25, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
strcpy(v13, "pass phrase exceeds block size");
s2[0] = 0x3C0C989EA1766003LL;
s2[1] = 0x867C601A1FA1ABBALL;
s2[2] = 0x638AD1744D374CE4LL;
s2[3] = 0x36B257B4AB214630LL;
v15[0] = 0x27BCC956A2C43CB6LL;
v15[1] = 0x4F1C7D4B417A1A75LL;
v15[2] = 0x682BC7BBFE6FC5EALL;
v15[3] = 0x256AE17FCC04579ALL;
v20[0] = 0xD70FB84CC84C89D1LL;
v20[1] = 0x315A4AECD292229ELL;
v20[2] = 0x58E5EB4AC51416FDLL;
v20[3] = 0x2EBE5594F9769865LL;
v20[4] = 0x5C7F6951C2F02F7LL;
v20[5] = 0x6F18BA9886E2477FLL;
v20[6] = 0x8728FF0753589530LL;
v21 = -876910802;
v8[0] = 0xCC689AD449F76ABCLL;
v8[1] = 0x660A9CE5AA3C3AFBLL;
v16[0] = 0xCC689AD449F76ABCLL;
v16[1] = 0x660A9CE5AA3C3AFBLL;
v16[2] = 0x979AF6491E359A04LL;
v16[3] = 0x210C9FBC412D271BLL;
v9[0] = 0xAB445BA62EB72F26LL;
v9[1] = 0x81A7BFC8F8A7EB5CLL;
v22[0] = 0xAB445BA62EB72F26LL;
v22[1] = 0x81A7BFC8F8A7EB5CLL;
v22[2] = 0x5773EB049293F95FLL;
v22[3] = 0x7757747D87759AA5LL;
v22[4] = 0xB0532AD68E349C6BLL;
v22[5] = 0x1FC97BA52E3CBA14LL;
v22[6] = 0x67B0DF4A581086FCLL;
v22[7] = 0x47E7A22DC2648691LL;
v17[0] = 0xC7ACF11524986AC7LL;
v17[1] = 0xDA6A5B3C2797C11DLL;
v17[2] = 0x181746ED1529F632LL;
v17[3] = 0xFA3324764328D3AALL;
v18[0] = 0xB62F2F4D9AB2DFC1LL;
v18[1] = 0x6763D674D0786F7CLL;
v18[2] = 0x7285591EDAD46F1ELL;
v18[3] = 0x61CFB76C25CFFEB1LL;
v19[0] = 0x7526E3B6C44B3422LL;
v19[1] = 0x1DE00BA83E0F09A8LL;
v19[2] = 0xFAC3DD2C6A12955FLL;
v19[3] = 0x58EC04CA6D5E4ACCLL;
memset(s1, 85, 65);
PBKDF2(s1, v11, 28LL, &v6, 8LL, 2000LL, 32LL);
v0 = memcmp(s1, s2, 0x20uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v0 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v11, 28LL, &v6, 8LL, 1LL, 32LL);
v2 = memcmp(s1, v15, 0x20uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v2 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v11, 28LL, &v6, 8LL, 1000LL, 60LL);
v3 = memcmp(s1, v20, 0x3CuLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v3 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[8]) == 85 )
{
LOBYTE(s1[2]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 1LL, 16LL);
v4 = memcmp(s1, v8, 0x10uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v4 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[2]) == 85 )
{
LOBYTE(s1[4]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 1LL, 32LL);
v5 = memcmp(s1, v16, 0x20uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v5 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
LOBYTE(s1[2]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 2LL, 16LL);
if ( !memcmp(s1, v9, 0x10uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[2]) == 85 )
{
PBKDF2(s1, v7, 8LL, v10, 21LL, 2LL, 64LL);
if ( !memcmp(s1, v22, 0x40uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[8]) == 85 )
{
LOBYTE(s1[4]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 1200LL, 32LL);
if ( !memcmp(s1, v17, 0x20uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v24, 64LL, v12, 29LL, 1200LL, 32LL);
if ( !memcmp(s1, v18, 0x20uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v25, 65LL, v13, 30LL, 1200LL, 32LL);
if ( !memcmp(s1, v19, 0x20uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
result = 0LL;
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *func0()
{
int v0; // edx
const char *result; // rax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx
__int64 v6; // [rsp+17h] [rbp-2E9h] BYREF
char v7[9]; // [rsp+1Fh] [rbp-2E1h] BYREF
_QWORD v8[2]; // [rsp+28h] [rbp-2D8h] BYREF
__int64 v9[2]; // [rsp+38h] [rbp-2C8h] BYREF
char v10[32]; // [rsp+48h] [rbp-2B8h] BYREF
char v11[32]; // [rsp+68h] [rbp-298h] BYREF
char v12[32]; // [rsp+88h] [rbp-278h] BYREF
char v13[32]; // [rsp+A8h] [rbp-258h] BYREF
__int64 s2[4]; // [rsp+C8h] [rbp-238h] BYREF
__int64 v15[4]; // [rsp+E8h] [rbp-218h] BYREF
__int64 v16[4]; // [rsp+108h] [rbp-1F8h] BYREF
__int64 v17[4]; // [rsp+128h] [rbp-1D8h] BYREF
__int64 v18[4]; // [rsp+148h] [rbp-1B8h] BYREF
__int64 v19[4]; // [rsp+168h] [rbp-198h] BYREF
__int64 v20[7]; // [rsp+188h] [rbp-178h] BYREF
int v21; // [rsp+1C0h] [rbp-140h]
__int64 v22[8]; // [rsp+1C8h] [rbp-138h] BYREF
__int64 s1[10]; // [rsp+208h] [rbp-F8h] BYREF
char v24[80]; // [rsp+258h] [rbp-A8h] BYREF
char v25[88]; // [rsp+2A8h] [rbp-58h] BYREF

strcpy(v11, "This passphrase is a secret.");
v6 = 0x777AEDE1B3CE4CEDLL;
strcpy(v7, "password");
strcpy(v10, "ATHENA.MIT.EDUraeburn");
strcpy(v24, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
strcpy(v12, "pass phrase equals block size");
strcpy(v25, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
strcpy(v13, "pass phrase exceeds block size");
s2[0] = 0x3C0C989EA1766003LL;
s2[1] = 0x867C601A1FA1ABBALL;
s2[2] = 0x638AD1744D374CE4LL;
s2[3] = 0x36B257B4AB214630LL;
v15[0] = 0x27BCC956A2C43CB6LL;
v15[1] = 0x4F1C7D4B417A1A75LL;
v15[2] = 0x682BC7BBFE6FC5EALL;
v15[3] = 0x256AE17FCC04579ALL;
v20[0] = 0xD70FB84CC84C89D1LL;
v20[1] = 0x315A4AECD292229ELL;
v20[2] = 0x58E5EB4AC51416FDLL;
v20[3] = 0x2EBE5594F9769865LL;
v20[4] = 0x5C7F6951C2F02F7LL;
v20[5] = 0x6F18BA9886E2477FLL;
v20[6] = 0x8728FF0753589530LL;
v21 = -876910802;
v8[0] = 0xCC689AD449F76ABCLL;
v8[1] = 0x660A9CE5AA3C3AFBLL;
v16[0] = 0xCC689AD449F76ABCLL;
v16[1] = 0x660A9CE5AA3C3AFBLL;
v16[2] = 0x979AF6491E359A04LL;
v16[3] = 0x210C9FBC412D271BLL;
v9[0] = 0xAB445BA62EB72F26LL;
v9[1] = 0x81A7BFC8F8A7EB5CLL;
v22[0] = 0xAB445BA62EB72F26LL;
v22[1] = 0x81A7BFC8F8A7EB5CLL;
v22[2] = 0x5773EB049293F95FLL;
v22[3] = 0x7757747D87759AA5LL;
v22[4] = 0xB0532AD68E349C6BLL;
v22[5] = 0x1FC97BA52E3CBA14LL;
v22[6] = 0x67B0DF4A581086FCLL;
v22[7] = 0x47E7A22DC2648691LL;
v17[0] = 0xC7ACF11524986AC7LL;
v17[1] = 0xDA6A5B3C2797C11DLL;
v17[2] = 0x181746ED1529F632LL;
v17[3] = 0xFA3324764328D3AALL;
v18[0] = 0xB62F2F4D9AB2DFC1LL;
v18[1] = 0x6763D674D0786F7CLL;
v18[2] = 0x7285591EDAD46F1ELL;
v18[3] = 0x61CFB76C25CFFEB1LL;
v19[0] = 0x7526E3B6C44B3422LL;
v19[1] = 0x1DE00BA83E0F09A8LL;
v19[2] = 0xFAC3DD2C6A12955FLL;
v19[3] = 0x58EC04CA6D5E4ACCLL;
memset(s1, 85, 65);
PBKDF2(s1, v11, 28LL, &v6, 8LL, 2000LL, 32LL);
v0 = memcmp(s1, s2, 0x20uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v0 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v11, 28LL, &v6, 8LL, 1LL, 32LL);
v2 = memcmp(s1, v15, 0x20uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v2 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v11, 28LL, &v6, 8LL, 1000LL, 60LL);
v3 = memcmp(s1, v20, 0x3CuLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v3 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[8]) == 85 )
{
LOBYTE(s1[2]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 1LL, 16LL);
v4 = memcmp(s1, v8, 0x10uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v4 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[2]) == 85 )
{
LOBYTE(s1[4]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 1LL, 32LL);
v5 = memcmp(s1, v16, 0x20uLL);
result = "PBKDF2 should generate a valid key for the test strings.";
if ( !v5 )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
LOBYTE(s1[2]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 2LL, 16LL);
if ( !memcmp(s1, v9, 0x10uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[2]) == 85 )
{
PBKDF2(s1, v7, 8LL, v10, 21LL, 2LL, 64LL);
if ( !memcmp(s1, v22, 0x40uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[8]) == 85 )
{
LOBYTE(s1[4]) = 85;
PBKDF2(s1, v7, 8LL, v10, 21LL, 1200LL, 32LL);
if ( !memcmp(s1, v17, 0x20uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v24, 64LL, v12, 29LL, 1200LL, 32LL);
if ( !memcmp(s1, v18, 0x20uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
{
PBKDF2(s1, v25, 65LL, v13, 30LL, 1200LL, 32LL);
if ( !memcmp(s1, v19, 0x20uLL) )
{
result = "PBKDF2 should not write more than the requested keylength to the destination.";
if ( LOBYTE(s1[4]) == 85 )
result = 0LL;
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
else
{
result = "PBKDF2 should generate a valid key for the test strings.";
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_original_code:
static char *test_vectors() {
{
 unsigned char key[65];
 unsigned char password1[] = "This passphrase is a secret.";
 unsigned char salt1[] = {0xED,0x4C,0xCE,0xB3,0xE1,0xED,0x7A,0x77};
 unsigned char password2[] = "password";
 unsigned char salt2[] = "ATHENA.MIT.EDUraeburn";
 unsigned char password3[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
 unsigned char salt3[] = "pass phrase equals block size";
 unsigned char password4[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
 unsigned char salt4[] = "pass phrase exceeds block size";
 unsigned char key1[] = {0x03,0x60,0x76,0xA1,0x9E,0x98,0x0C,0x3C,0xBA,0xAB,0xA1,0x1F,0x1A,0x60,0x7C,0x86,0xE4,0x4C,0x37,0x4D,0x74,0xD1,0x8A,0x63,0x30,0x46,0x21,0xAB,0xB4,0x57,0xB2,0x36};
 unsigned char key2[] = {0xB6,0x3C,0xC4,0xA2,0x56,0xC9,0xBC,0x27,0x75,0x1A,0x7A,0x41,0x4B,0x7D,0x1C,0x4F,0xEA,0xC5,0x6F,0xFE,0xBB,0xC7,0x2B,0x68,0x9A,0x57,0x04,0xCC,0x7F,0xE1,0x6A,0x25};
 unsigned char key3[] = {0xD1,0x89,0x4C,0xC8,0x4C,0xB8,0x0F,0xD7,0x9E,0x22,0x92,0xD2,0xEC,0x4A,0x5A,0x31,0xFD,0x16,0x14,0xC5,0x4A,0xEB,0xE5,0x58,0x65,0x98,0x76,0xF9,0x94,0x55,0xBE,0x2E,0xF7,0x02,0x2F,0x1C,0x95,0xF6,0xC7,0x05,0x7F,0x47,0xE2,0x86,0x98,0xBA,0x18,0x6F,0x30,0x95,0x58,0x53,0x07,0xFF,0x28,0x87,0x2E,0x67,0xBB,0xCB};
 unsigned char key4[] = {0xbc,0x6a,0xf7,0x49,0xd4,0x9a,0x68,0xcc,0xfb,0x3a,0x3c,0xaa,0xe5,0x9c,0x0a,0x66};
 unsigned char key5[] = {0xbc,0x6a,0xf7,0x49,0xd4,0x9a,0x68,0xcc,0xfb,0x3a,0x3c,0xaa,0xe5,0x9c,0x0a,0x66,0x04,0x9a,0x35,0x1e,0x49,0xf6,0x9a,0x97,0x1b,0x27,0x2d,0x41,0xbc,0x9f,0x0c,0x21};
 unsigned char key6[] = {0x26,0x2f,0xb7,0x2e,0xa6,0x5b,0x44,0xab,0x5c,0xeb,0xa7,0xf8,0xc8,0xbf,0xa7,0x81};
 unsigned char key7[] = {0x26,0x2f,0xb7,0x2e,0xa6,0x5b,0x44,0xab,0x5c,0xeb,0xa7,0xf8,0xc8,0xbf,0xa7,0x81,0x5f,0xf9,0x93,0x92,0x04,0xeb,0x73,0x57,0xa5,0x9a,0x75,0x87,0x7d,0x74,0x57,0x77,0x6b,0x9c,0x34,0x8e,0xd6,0x2a,0x53,0xb0,0x14,0xba,0x3c,0x2e,0xa5,0x7b,0xc9,0x1f,0xfc,0x86,0x10,0x58,0x4a,0xdf,0xb0,0x67,0x91,0x86,0x64,0xc2,0x2d,0xa2,0xe7,0x47};
 unsigned char key8[] = {0xc7,0x6a,0x98,0x24,0x15,0xf1,0xac,0xc7,0x1d,0xc1,0x97,0x27,0x3c,0x5b,0x6a,0xda,0x32,0xf6,0x29,0x15,0xed,0x46,0x17,0x18,0xaa,0xd3,0x28,0x43,0x76,0x24,0x33,0xfa};
 unsigned char key9[] = {0xc1,0xdf,0xb2,0x9a,0x4d,0x2f,0x2f,0xb6,0x7c,0x6f,0x78,0xd0,0x74,0xd6,0x63,0x67,0x1e,0x6f,0xd4,0xda,0x1e,0x59,0x85,0x72,0xb1,0xfe,0xcf,0x25,0x6c,0xb7,0xcf,0x61};
 unsigned char key10[] = {0x22,0x34,0x4b,0xc4,0xb6,0xe3,0x26,0x75,0xa8,0x09,0x0f,0x3e,0xa8,0x0b,0xe0,0x1d,0x5f,0x95,0x12,0x6a,0x2c,0xdd,0xc3,0xfa,0xcc,0x4a,0x5e,0x6d,0xca,0x04,0xec,0x58};
 memset (key, 0x55, 65);
 PBKDF2 (key, password1, sizeof(password1)-1, salt1, sizeof(salt1), 2000, 32);
 do { if (!(memcmp (key, key1, 32) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[32] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 PBKDF2 (key, password1, sizeof(password1)-1, salt1, sizeof(salt1), 1, 32);
 do { if (!(memcmp (key, key2, 32) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[32] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 PBKDF2 (key, password1, sizeof(password1)-1, salt1, sizeof(salt1), 1000, 60);
 do { if (!(memcmp (key, key3, 60) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[64] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 key[16] = 0x55;
 PBKDF2 (key, password2, sizeof (password2)-1, salt2, sizeof (salt2)-1, 1, 16);
 do { if (!(memcmp (key, key4, 16) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[16] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 key[32] = 0x55;
 PBKDF2 (key, password2, sizeof (password2)-1, salt2, sizeof (salt2)-1, 1, 32);
 do { if (!(memcmp (key, key5, 32) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[32] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 key[16] = 0x55;
 PBKDF2 (key, password2, sizeof (password2)-1, salt2, sizeof (salt2)-1, 2, 16);
 do { if (!(memcmp (key, key6, 16) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[16] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 PBKDF2 (key, password2, sizeof (password2)-1, salt2, sizeof (salt2)-1, 2, 64);
 do { if (!(memcmp (key, key7, 64) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[64] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 key[32] = 0x55;
 PBKDF2 (key, password2, sizeof (password2)-1, salt2, sizeof (salt2)-1, 1200, 32);
 do { if (!(memcmp (key, key8, 32) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[32] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 PBKDF2 (key, password3, sizeof (password3)-1, salt3, sizeof (salt3)-1, 1200, 32);
 do { if (!(memcmp (key, key9, 32) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[32] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
 PBKDF2 (key, password4, sizeof (password4)-1, salt4, sizeof (salt4)-1, 1200, 32);
 do { if (!(memcmp (key, key10, 32) == 0)) return "PBKDF2 should generate a valid key for the test strings."; } while (0);
 do { if (!(key[32] == 0x55)) return "PBKDF2 should not write more than the requested keylength to the destination."; } while (0);
}
return 0;}

variable_types:
key
unsigned char [65]


original_code:
static char *test_bitcount (void) {
{
 const uint32_t iterations = 1000000;
 const uint32_t subcount[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
 uint32_t ones = 0, tmp;
 random_uint32 ();
 for (uint32_t i = 0; i < iterations; ++i)
 {
  tmp = random_uint32 ();
  ones += subcount[(tmp >> 0) & 15];
  ones += subcount[(tmp >> 4) & 15];
  ones += subcount[(tmp >> 8) & 15];
  ones += subcount[(tmp >> 12) & 15];
  ones += subcount[(tmp >> 16) & 15];
  ones += subcount[(tmp >> 20) & 15];
  ones += subcount[(tmp >> 24) & 15];
  ones += subcount[(tmp >> 28) & 15];
 }
 uint32_t expected = iterations << 4;
 uint32_t error = (ones > expected) ? (ones - expected) : (expected - ones);
 printf ("Random Test: Bitcount\nOnes: %u (expected %u)\n", ones, expected);
 printf ("Error: %f%%\n\n", (error * 100.0f) / expected);
}
return 0;}

canonical_original_code:
static char *test_bitcount() {
{
 unsigned int iterations = 1000000;
 unsigned int subcount[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
 unsigned int ones = 0; unsigned int tmp;
 random_uint32 ();
 for (unsigned int i = 0; i < iterations; ++i)
 {
  tmp = random_uint32 ();
  ones += subcount[(tmp >> 0) & 15];
  ones += subcount[(tmp >> 4) & 15];
  ones += subcount[(tmp >> 8) & 15];
  ones += subcount[(tmp >> 12) & 15];
  ones += subcount[(tmp >> 16) & 15];
  ones += subcount[(tmp >> 20) & 15];
  ones += subcount[(tmp >> 24) & 15];
  ones += subcount[(tmp >> 28) & 15];
 }
 unsigned int expected = iterations << 4;
 unsigned int error = (ones > expected) ? (ones - expected) : (expected - ones);
 printf ("Random Test: Bitcount\nOnes: %u (expected %u)\n", ones, expected);
 printf ("Error: %f%%\n\n", (error * 100.0f) / expected);
}
return 0;}

variable_types:
iterations
unsigned int

variable_types:
subcount
unsigned int [16]

variable_types:
ones
unsigned int

variable_types:
tmp
unsigned int

variable_types:
i
unsigned int

variable_types:
expected
unsigned int

variable_types:
error
unsigned int


original_code:
void test_wordcount (uint32_t bits)
{
 const uint32_t iterations = 10000000;
 const uint32_t mask = (1 << bits) - 1;
 uint32_t buckets[32] = {0};
 uint32_t tmp;
 random_uint32 ();
 for (uint32_t i = 0; i < iterations; ++i)
 {
  tmp = random_uint32 ();
  for (uint32_t j = 0; j < 32 / bits; ++j)
   buckets[(tmp >> (j * bits)) & mask] += 1;
 }
 uint32_t expected = ((32 / bits) * iterations) >> bits;
 printf ("Random Test: Wordcount (k=%u)\n", bits);
 uint32_t maxerror = 0;
 for (uint32_t i = 0; i < (uint32_t)(1 << bits); ++i)
 {
  uint32_t error = (buckets[i] > expected) ? (buckets[i] - expected) : (expected - buckets[i]);
  printf ("[%2u] = %u (expected %u)\n", i, buckets[i], expected);
  if (error > maxerror)
   maxerror = error;
 }
 printf ("Max Error: %f%%\n\n", (maxerror * 100.0f) / expected);
}

canonical_original_code:
void test_wordcount(unsigned int bits)
{
 unsigned int iterations = 10000000;
 unsigned int mask = (1 << bits) - 1;
 unsigned int buckets[32] = {0};
 unsigned int tmp;
 random_uint32 ();
 for (unsigned int i = 0; i < iterations; ++i)
 {
  tmp = random_uint32 ();
  for (unsigned int j = 0; j < 32 / bits; ++j)
   buckets[(tmp >> (j * bits)) & mask] += 1;
 }
 unsigned int expected = ((32 / bits) * iterations) >> bits;
 printf ("Random Test: Wordcount (k=%u)\n", bits);
 unsigned int maxerror = 0;
 for (unsigned int i = 0; i < (unsigned int)(1 << bits); ++i)
 {
  unsigned int error = (buckets[i] > expected) ? (buckets[i] - expected) : (expected - buckets[i]);
  printf ("[%2u] = %u (expected %u)\n", i, buckets[i], expected);
  if (error > maxerror)
   maxerror = error;
 }
 printf ("Max Error: %f%%\n\n", (maxerror * 100.0f) / expected);
}

variable_types:
bits
unsigned int

variable_types:
mask
unsigned int

variable_types:
buckets
unsigned int [32]

variable_types:
j
unsigned int

variable_types:
maxerror
unsigned int


original_code:
char *test_random (void)
{
 do { char *message = test_bitcount(); tests_run++; if (message) return message; } while (0);
 test_wordcount (2);
 test_wordcount (3);
 test_wordcount (4);
 test_wordcount (5);
 return 0;
}

canonical_original_code:
char *test_random()
{
 do { char *message = test_bitcount(); tests_run++; if (message) return message; } while (0);
 test_wordcount (2);
 test_wordcount (3);
 test_wordcount (4);
 test_wordcount (5);
 return 0;
}

variable_types:
message
char *


decompiled_code:
__int64 __fastcall keychain_create(__int64 a1, __int64 a2)
{
ff_rand(a1, &restricted_ec_n);
return random_bytes(a2, 32LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
ff_rand(a1, &restricted_ec_n);
return random_bytes(a2, 32LL);
}

original_code:
void keychain_create (FF_NUM *const out_base_private_key, uint8_t out_chain_key[static 32])
{
 ff_rand (out_base_private_key, &restricted_ec_n);
 random_bytes (out_chain_key, 32);
}

canonical_original_code:
void keychain_create(struct FF_NUM *out_base_private_key, unsigned char out_chain_key[32])
{
 ff_rand (out_base_private_key, &restricted_ec_n);
 random_bytes (out_chain_key, 32);
}


original_code:
void keychain_calculate (FF_NUM *const out_privkey, EC_POINT *const out_pubkey, FF_NUM const *const base_private_key, uint8_t const chain_key[static 32], uint8_t const index[static 16])
{
 uint8_t encrypted_index[32] = {0};
 FF_NUM private_key_offset = {0};
 FF_NUM private_key = {0};
 if (ff_compare (base_private_key, &restricted_ec_n) >= 0 || ff_is_zero (base_private_key))
  error_state ();
 aes256_encrypt_block (encrypted_index+16, chain_key, index);
 ff_deserialize (&private_key_offset, encrypted_index);
 ff_add (&private_key, base_private_key, &private_key_offset, &ec_n);
 if (out_privkey)
  ff_copy (out_privkey, &private_key);
 if (out_pubkey)
  ec_mul (out_pubkey, &private_key, &ec_G);
 secure_memset (encrypted_index, 0, sizeof (encrypted_index));
 secure_memset (&private_key_offset, 0, sizeof (private_key_offset));
 secure_memset (&private_key, 0, sizeof (private_key));
}

canonical_original_code:
void keychain_calculate(struct FF_NUM *out_privkey, struct EC_POINT *out_pubkey, struct FF_NUM *base_private_key, unsigned char chain_key[32], unsigned char index[16])
{
 unsigned char encrypted_index[32] = {0};
 struct FF_NUM private_key_offset = {0};
 struct FF_NUM private_key = {0};
 if (ff_compare (base_private_key, &restricted_ec_n) >= 0 || ff_is_zero (base_private_key))
  error_state ();
 aes256_encrypt_block (encrypted_index+16, chain_key, index);
 ff_deserialize (&private_key_offset, encrypted_index);
 ff_add (&private_key, base_private_key, &private_key_offset, &ec_n);
 if (out_privkey)
  ff_copy (out_privkey, &private_key);
 if (out_pubkey)
  ec_mul (out_pubkey, &private_key, &ec_G);
 secure_memset (encrypted_index, 0, sizeof (encrypted_index));
 secure_memset (&private_key_offset, 0, sizeof (private_key_offset));
 secure_memset (&private_key, 0, sizeof (private_key));
}

variable_types:
index
unsigned char [16]

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


canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return (a1 >> 3) ^ __ROL4__(a1, 14) ^ __ROR4__(a1, 7);
}

canonical_original_code:
static inline unsigned int s0(unsigned int a)
{
 unsigned int tmp1; unsigned int tmp2;
 tmp1 = (((a) >> (7)) | ((a) << (32 - (7))));
 tmp2 = (((a) >> (18)) | ((a) << (32 - (18))));
 return tmp1 ^ tmp2 ^ (a >> 3);
}

variable_types:
a
unsigned int

return_type: unsigned int


canonical_original_code:
static inline unsigned int s1(unsigned int a)
{
 unsigned int tmp1; unsigned int tmp2;
 tmp1 = (((a) >> (17)) | ((a) << (32 - (17))));
 tmp2 = (((a) >> (19)) | ((a) << (32 - (19))));
 return tmp1 ^ tmp2 ^ (a >> 10);
}


original_code:
void SHA256_partial (uint8_t *hash, SHA256_STATE *const state, uint8_t const *src, uint32_t len, _Bool const first, _Bool const last)
{
 if (first) {
  state->chunk_len = 0;
  state->totallen = 0;
  memmove (state->state, initial_state, 32);
  memset (state->chunk, 0, 64);
 }
 while (len > 0)
 {
  while ((state->chunk_len < 64) && (len > 0))
  {
   state->chunk[state->chunk_len>>2] |= ((uint32_t)*(src++)) << (8*(3-(state->chunk_len&3)));
   state->chunk_len += 1;
   --len;
   state->totallen += 1;
  }
  if (state->chunk_len == 64)
  {
   compress (state->state, state->chunk);
   state->chunk_len = 0;
   memset (state->chunk, 0, 64);
  }
 }
 if (last)
 {
  state->chunk[state->chunk_len>>2] |= (uint32_t)1 << (8*(3-(state->chunk_len&3)) + 7);
  if ((state->totallen & 63) > 55)
  {
   compress (state->state, state->chunk);
   memset (state->chunk, 0, 64);
  }
  state->chunk[14] = (state->totallen >> 29);
  state->chunk[15] = state->totallen << 3;
  compress (state->state, state->chunk);
  for (int i = 0; i < 8; ++i)
  {
   *(hash++) = state->state[i] >> 24;
   *(hash++) = state->state[i] >> 16;
   *(hash++) = state->state[i] >> 8;
   *(hash++) = state->state[i];
  }
 }
}

canonical_original_code:
void SHA256_partial(unsigned char *hash, struct SHA256_STATE *state, unsigned char *src, unsigned int len, _Bool first, _Bool last)
{
 if (first) {
  state->chunk_len = 0;
  state->totallen = 0;
  memmove (state->state, initial_state, 32);
  memset (state->chunk, 0, 64);
 }
 while (len > 0)
 {
  while ((state->chunk_len < 64) && (len > 0))
  {
   state->chunk[state->chunk_len>>2] |= ((unsigned int)*(src++)) << (8*(3-(state->chunk_len&3)));
   state->chunk_len += 1;
   --len;
   state->totallen += 1;
  }
  if (state->chunk_len == 64)
  {
   compress (state->state, state->chunk);
   state->chunk_len = 0;
   memset (state->chunk, 0, 64);
  }
 }
 if (last)
 {
  state->chunk[state->chunk_len>>2] |= (unsigned int)1 << (8*(3-(state->chunk_len&3)) + 7);
  if ((state->totallen & 63) > 55)
  {
   compress (state->state, state->chunk);
   memset (state->chunk, 0, 64);
  }
  state->chunk[14] = (state->totallen >> 29);
  state->chunk[15] = state->totallen << 3;
  compress (state->state, state->chunk);
  for (int i = 0; i < 8; ++i)
  {
   *(hash++) = state->state[i] >> 24;
   *(hash++) = state->state[i] >> 16;
   *(hash++) = state->state[i] >> 8;
   *(hash++) = state->state[i];
  }
 }
}

variable_types:
hash
unsigned char *

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

variable_types:
src
unsigned char *

variable_types:
len
unsigned int

variable_types: i int


original_code:
static char *test_known (void) {
{
 const FF_NUM base_private_key0 = {{0x914432ca,0x0d08bc13,0x778232d4,0xe6558c2d,0x9b05ad7f,0x6928db34,0xbc050341,0xb6217431}};
 const uint8_t chain_key0[] = {0xa6,0xc0,0xaf,0xed,0xa0,0xcc,0x36,0x53,0x2c,0x23,0xaa,0xc0,0x75,0xd7,0x0f,0xb3,0xfc,0xb9,0xc6,0xb9,0xa6,0x33,0xc6,0x9e,0x33,0x0d,0xb2,0xd6,0x1a,0xde,0x83,0xfd};
 const uint8_t chain_index0[] = {0x7f,0x2c,0x2f,0x2b,0xd1,0x47,0xf7,0x64,0xa4,0xd1,0x5c,0xb6,0x1c,0x95,0x31,0x60};
 const EC_POINT pubkey0 = {{0x88B55835,0xD67CF499,0x680CA143,0xDF092255,0x3B72EE27,0xE7C6F1CE,0x5DB4396B,0x9FD04834},{0xA09B3F62,0x9EB89911,0x5EAD68DD,0x7F114C9E,0x31B9C3C8,0xDCBC6034,0x3A0A37DF,0x8A34AB11}};
 EC_POINT pubkey;
 keychain_calculate (((void *)0), &pubkey, &base_private_key0, chain_key0, chain_index0);
 do { if (!(memcmp (&pubkey, &pubkey0, sizeof (EC_POINT)) == 0)) return "key_chain_calculate should calculate the correct derived key for known results."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_known() {
{
 struct FF_NUM base_private_key0 = {{0x914432ca,0x0d08bc13,0x778232d4,0xe6558c2d,0x9b05ad7f,0x6928db34,0xbc050341,0xb6217431}};
 unsigned char chain_key0[] = {0xa6,0xc0,0xaf,0xed,0xa0,0xcc,0x36,0x53,0x2c,0x23,0xaa,0xc0,0x75,0xd7,0x0f,0xb3,0xfc,0xb9,0xc6,0xb9,0xa6,0x33,0xc6,0x9e,0x33,0x0d,0xb2,0xd6,0x1a,0xde,0x83,0xfd};
 unsigned char chain_index0[] = {0x7f,0x2c,0x2f,0x2b,0xd1,0x47,0xf7,0x64,0xa4,0xd1,0x5c,0xb6,0x1c,0x95,0x31,0x60};
 struct EC_POINT pubkey0 = {{0x88B55835,0xD67CF499,0x680CA143,0xDF092255,0x3B72EE27,0xE7C6F1CE,0x5DB4396B,0x9FD04834},{0xA09B3F62,0x9EB89911,0x5EAD68DD,0x7F114C9E,0x31B9C3C8,0xDCBC6034,0x3A0A37DF,0x8A34AB11}};
 struct EC_POINT pubkey;
 keychain_calculate (((void *)0), &pubkey, &base_private_key0, chain_key0, chain_index0);
 do { if (!(memcmp (&pubkey, &pubkey0, sizeof (EC_POINT)) == 0)) return "key_chain_calculate should calculate the correct derived key for known results."; } while (0);
}
return 0;}

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


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

result = test_known();
++tests_run;
return result;
}

original_code:
char *test_keychain (void)
{
 do { char *message = test_known(); tests_run++; if (message) return message; } while (0);
 return 0;
}

canonical_original_code:
char *test_keychain()
{
 do { char *message = test_known(); tests_run++; if (message) return message; } while (0);
 return 0;
}


original_code:
void HMAC_partial (void *hash, HMAC_STATE *const state, void const *const key, size_t klen, void const *msg, size_t mlen, _Bool const first, _Bool const last)
{
 if (first)
 {
  memset (state, 0, sizeof (HMAC_STATE));
  if (klen > 64)
   SHA256 (state->padded_key, key, klen);
  else
   memmove (state->padded_key, key, klen);
  for (uint32_t i = 0; i < 64; ++i)
   state->padded_key[i] ^= 0x36;
  SHA256_partial (0, &(state->sha256_state), state->padded_key, 64, 1, 0);
 }
 SHA256_partial (hash, &(state->sha256_state), msg, mlen, 0, last);
 if (!last)
  return;
 for (uint32_t i = 0; i < 64; ++i)
  state->padded_key[i] ^= 0x36 ^ 0x5C;
 SHA256_partial (((void *)0), &(state->sha256_state), state->padded_key, 64, 1, 0);
 SHA256_partial (hash, &(state->sha256_state), hash, 32, 0, 1);
}

canonical_original_code:
void HMAC_partial(void *hash, struct HMAC_STATE *state, void *key, unsigned long klen, void *msg, unsigned long mlen, _Bool first, _Bool last)
{
 if (first)
 {
  memset (state, 0, sizeof (HMAC_STATE));
  if (klen > 64)
   SHA256 (state->padded_key, key, klen);
  else
   memmove (state->padded_key, key, klen);
  for (unsigned int i = 0; i < 64; ++i)
   state->padded_key[i] ^= 0x36;
  SHA256_partial (0, &(state->sha256_state), state->padded_key, 64, 1, 0);
 }
 SHA256_partial (hash, &(state->sha256_state), msg, mlen, 0, last);
 if (!last)
  return;
 for (unsigned int i = 0; i < 64; ++i)
  state->padded_key[i] ^= 0x36 ^ 0x5C;
 SHA256_partial (((void *)0), &(state->sha256_state), state->padded_key, 64, 1, 0);
 SHA256_partial (hash, &(state->sha256_state), hash, 32, 0, 1);
}

variable_types:
hash
void *

variable_types: struct HMAC_STATE { struct SHA256_STATE { unsigned int state[8]; unsigned int chunk[16]; unsigned int chunk_len; unsigned int totallen; } sha256_state; unsigned char padded_key[64]; } *

variable_types:
key
void *

variable_types:
klen
unsigned long

variable_types:
msg
void *

variable_types:
mlen
unsigned long

variable_types:
i
unsigned int

user_defined_types: struct HMAC_STATE { struct SHA256_STATE sha256_state; unsigned char padded_key[64]; }


HMAC

decompiled_code:
__int64 __fastcall HMAC(__int64 a1, const void *a2, unsigned int a3, __int64 a4, unsigned int a5)
{
__int64 v6[23]; // [rsp+0h] [rbp-B8h] BYREF

return HMAC_partial(a1, v6, a2, a3, a4, a5, 1, 1u);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void *a2, unsigned int a3, __int64 a4, unsigned int a5)
{
__int64 v6[23]; // [rsp+0h] [rbp-B8h] BYREF

return func0(a1, v6, a2, a3, a4, a5, 1, 1u);
}

original_code:
void HMAC (uint8_t *const hash, uint8_t const *const key, uint32_t klen, uint8_t const *const msg, uint32_t mlen)
{
 HMAC_STATE state;
 HMAC_partial (hash, &state, key, klen, msg, mlen, 1, 1);
}

canonical_original_code:
void HMAC(unsigned char *hash, unsigned char *key, unsigned int klen, unsigned char *msg, unsigned int mlen)
{
 struct HMAC_STATE state;
 HMAC_partial (hash, &state, key, klen, msg, mlen, 1, 1);
}

variable_types:
key
unsigned char *

variable_types:
klen
unsigned int

variable_types:
msg
unsigned char *

variable_types:
mlen
unsigned int

variable_types: struct HMAC_STATE { struct SHA256_STATE { unsigned int state[8]; unsigned int chunk[16]; unsigned int chunk_len; unsigned int totallen; } sha256_state; unsigned char padded_key[64]; }


decompiled_code:
const char *test_base58encoding()
{
int v0; // edx
const char *result; // rax
int v2; // edx
int v3; // edx
__int16 v4; // [rsp+18h] [rbp-100h]
char v5[32]; // [rsp+60h] [rbp-B8h] BYREF
__int64 s2[6]; // [rsp+80h] [rbp-98h] BYREF
char v7[48]; // [rsp+B0h] [rbp-68h] BYREF
__int64 s1[3]; // [rsp+E0h] [rbp-38h] BYREF
__int64 v9[4]; // [rsp+F8h] [rbp-20h] BYREF

qmemcpy(v9, "UUUUUUUUUUUUU", 13);
LOBYTE(v4) = 0;
strcpy((char *)s2, "1JwSSubhmg6iPtRjtyqhUYYH7bZg1RstDD");
strcpy(v7, "2n1XR4oJkmBdJMxhBGQGb96gQ88xUzxLFyG");
strcpy(v5, "1111111111111111111111111");
s1[0] = 0x65B4FC91D7C5C400LL;
s1[1] = 0x3DADE03FE0F51E4ALL;
s1[2] = 0x27988F599CLL;
LOWORD(v9[0]) = v4;
base58_encode(s1);
v0 = memcmp(s1, s2, 0x23uLL);
result = "base58_encode should correctly encode the test strings, even if src and dst point to the same memory.";
if ( !v0 )
{
base58_encode(s1);
v2 = memcmp(s1, v7, 0x24uLL);
result = "base58_encode should correctly encode the test string of all 0xFF.";
if ( !v2 )
{
base58_encode(s1);
v3 = memcmp(s1, v5, 0x1AuLL);
result = "base58_encode should correctly encode the test string of all 0x00.";
if ( !v3 )
{
result = "base58_encode should not write more than 36 bytes to the destination array.";
if ( BYTE4(v9[1]) == 85 )
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
const char *func0()
{
int v0; // edx
const char *result; // rax
int v2; // edx
int v3; // edx
__int16 v4; // [rsp+18h] [rbp-100h]
char v5[32]; // [rsp+60h] [rbp-B8h] BYREF
__int64 s2[6]; // [rsp+80h] [rbp-98h] BYREF
char v7[48]; // [rsp+B0h] [rbp-68h] BYREF
__int64 s1[3]; // [rsp+E0h] [rbp-38h] BYREF
__int64 v9[4]; // [rsp+F8h] [rbp-20h] BYREF

qmemcpy(v9, "UUUUUUUUUUUUU", 13);
LOBYTE(v4) = 0;
strcpy((char *)s2, "1JwSSubhmg6iPtRjtyqhUYYH7bZg1RstDD");
strcpy(v7, "2n1XR4oJkmBdJMxhBGQGb96gQ88xUzxLFyG");
strcpy(v5, "1111111111111111111111111");
s1[0] = 0x65B4FC91D7C5C400LL;
s1[1] = 0x3DADE03FE0F51E4ALL;
s1[2] = 0x27988F599CLL;
LOWORD(v9[0]) = v4;
base58_encode(s1);
v0 = memcmp(s1, s2, 0x23uLL);
result = "base58_encode should correctly encode the test strings, even if src and dst point to the same memory.";
if ( !v0 )
{
base58_encode(s1);
v2 = memcmp(s1, v7, 0x24uLL);
result = "base58_encode should correctly encode the test string of all 0xFF.";
if ( !v2 )
{
base58_encode(s1);
v3 = memcmp(s1, v5, 0x1AuLL);
result = "base58_encode should correctly encode the test string of all 0x00.";
if ( !v3 )
{
result = "base58_encode should not write more than 36 bytes to the destination array.";
if ( BYTE4(v9[1]) == 85 )
result = 0LL;
}
}
}
return result;
}

original_code:
static char *test_base58encoding (void) {
{
 uint8_t encoding[37] = {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,0x55,0x55,0x55,0x55};
 const uint8_t str1[] = {0x00,0xc4,0xc5,0xd7,0x91,0xfc,0xb4,0x65,0x4a,0x1e,0xf5,0xe0,0x3f,0xe0,0xad,0x3d,0x9c,0x59,0x8f,0x98,0x27,0x00,0x00,0x00,0x00};
 const uint8_t encoding1[] = "1JwSSubhmg6iPtRjtyqhUYYH7bZg1RstDD";
 const uint8_t str2[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
 const uint8_t encoding2[] = "2n1XR4oJkmBdJMxhBGQGb96gQ88xUzxLFyG";
 const uint8_t str3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 const uint8_t encoding3[] = "1111111111111111111111111";
 memmove (encoding, str1, 26);
 base58_encode (encoding, encoding);
 do { if (!(memcmp (encoding, encoding1, sizeof(encoding1)) == 0)) return "base58_encode should correctly encode the test strings, even if src and dst point to the same memory."; } while (0);
 base58_encode (encoding, str2);
 do { if (!(memcmp (encoding, encoding2, sizeof(encoding2)) == 0)) return "base58_encode should correctly encode the test string of all 0xFF."; } while (0);
 base58_encode (encoding, str3);
 do { if (!(memcmp (encoding, encoding3, sizeof(encoding3)) == 0)) return "base58_encode should correctly encode the test string of all 0x00."; } while (0);
 do { if (!(encoding[36] == 0x55)) return "base58_encode should not write more than 36 bytes to the destination array."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_base58encoding() {
{
 unsigned char encoding[37] = {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,0x55,0x55,0x55,0x55};
 unsigned char str1[] = {0x00,0xc4,0xc5,0xd7,0x91,0xfc,0xb4,0x65,0x4a,0x1e,0xf5,0xe0,0x3f,0xe0,0xad,0x3d,0x9c,0x59,0x8f,0x98,0x27,0x00,0x00,0x00,0x00};
 unsigned char encoding1[] = "1JwSSubhmg6iPtRjtyqhUYYH7bZg1RstDD";
 unsigned char str2[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
 unsigned char encoding2[] = "2n1XR4oJkmBdJMxhBGQGb96gQ88xUzxLFyG";
 unsigned char str3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 unsigned char encoding3[] = "1111111111111111111111111";
 memmove (encoding, str1, 26);
 base58_encode (encoding, encoding);
 do { if (!(memcmp (encoding, encoding1, sizeof(encoding1)) == 0)) return "base58_encode should correctly encode the test strings, even if src and dst point to the same memory."; } while (0);
 base58_encode (encoding, str2);
 do { if (!(memcmp (encoding, encoding2, sizeof(encoding2)) == 0)) return "base58_encode should correctly encode the test string of all 0xFF."; } while (0);
 base58_encode (encoding, str3);
 do { if (!(memcmp (encoding, encoding3, sizeof(encoding3)) == 0)) return "base58_encode should correctly encode the test string of all 0x00."; } while (0);
 do { if (!(encoding[36] == 0x55)) return "base58_encode should not write more than 36 bytes to the destination array."; } while (0);
}
return 0;}

variable_types:
encoding
unsigned char [37]


decompiled_code:
const char *test_base58checkencoding()
{
int v0; // edx
const char *result; // rax
bool v2; // zf
__m128i v3; // [rsp+0h] [rbp-88h] BYREF
int v4; // [rsp+10h] [rbp-78h]
__int64 s2[6]; // [rsp+20h] [rbp-68h] BYREF
__int128 s1[3]; // [rsp+50h] [rbp-38h] BYREF

memset(s1, 85, 37);
v3.m128i_i64[0] = 0x4A65B4FC91D7C5C4LL;
v3.m128i_i64[1] = 0x9C3DADE03FE0F51ELL;
v4 = 664309593;
strcpy((char *)s2, "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T");
base58check_encode(s1, 0LL, &v3);
v0 = memcmp(s1, s2, 0x23uLL);
result = "base58check_encode should correctly encode the test strings.";
if ( !v0 )
{
s1[0] = (__int128)_mm_loadu_si128(&v3);
LODWORD(s1[1]) = v4;
base58check_encode(s1, 0LL, s1);
v2 = memcmp(s1, s2, 0x23uLL) == 0;
result = "base58check_encode should correctly encode the test strings, even if the src and dst point to the same memory.";
if ( v2 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
const char *func1()
{
int v0; // edx
const char *result; // rax
bool v2; // zf
__m128i v3; // [rsp+0h] [rbp-88h] BYREF
int v4; // [rsp+10h] [rbp-78h]
__int64 s2[6]; // [rsp+20h] [rbp-68h] BYREF
__int128 s1[3]; // [rsp+50h] [rbp-38h] BYREF

memset(s1, 85, 37);
v3.m128i_i64[0] = 0x4A65B4FC91D7C5C4LL;
v3.m128i_i64[1] = 0x9C3DADE03FE0F51ELL;
v4 = 664309593;
strcpy((char *)s2, "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T");
base58check_encode(s1, 0LL, &v3);
v0 = memcmp(s1, s2, 0x23uLL);
result = "base58check_encode should correctly encode the test strings.";
if ( !v0 )
{
s1[0] = (__int128)_mm_loadu_si128(&v3);
LODWORD(s1[1]) = v4;
base58check_encode(s1, 0LL, s1);
v2 = memcmp(s1, s2, 0x23uLL) == 0;
result = "base58check_encode should correctly encode the test strings, even if the src and dst point to the same memory.";
if ( v2 )
result = 0LL;
}
return result;
}

original_code:
static char *test_base58checkencoding (void) {
{
 uint8_t encoding[37] = {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,0x55,0x55,0x55,0x55};
 const uint8_t str1[] = {0xc4,0xc5,0xd7,0x91,0xfc,0xb4,0x65,0x4a,0x1e,0xf5,0xe0,0x3f,0xe0,0xad,0x3d,0x9c,0x59,0x8f,0x98,0x27};
 const uint8_t encoding1[] = "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T";
 base58check_encode (encoding, 0, str1);
 do { if (!(memcmp (encoding, encoding1, sizeof(encoding1)) == 0)) return "base58check_encode should correctly encode the test strings."; } while (0);
 memmove (encoding, str1, 20);
 base58check_encode (encoding, 0, encoding);
 do { if (!(memcmp (encoding, encoding1, sizeof(encoding1)) == 0)) return "base58check_encode should correctly encode the test strings, even if the src and dst point to the same memory."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_base58checkencoding() {
{
 unsigned char encoding[37] = {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,0x55,0x55,0x55,0x55};
 unsigned char str1[] = {0xc4,0xc5,0xd7,0x91,0xfc,0xb4,0x65,0x4a,0x1e,0xf5,0xe0,0x3f,0xe0,0xad,0x3d,0x9c,0x59,0x8f,0x98,0x27};
 unsigned char encoding1[] = "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T";
 base58check_encode (encoding, 0, str1);
 do { if (!(memcmp (encoding, encoding1, sizeof(encoding1)) == 0)) return "base58check_encode should correctly encode the test strings."; } while (0);
 memmove (encoding, str1, 20);
 base58check_encode (encoding, 0, encoding);
 do { if (!(memcmp (encoding, encoding1, sizeof(encoding1)) == 0)) return "base58check_encode should correctly encode the test strings, even if the src and dst point to the same memory."; } while (0);
}
return 0;}


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

result = test_base58encoding();
++tests_run;
if ( !result )
{
result = test_base58checkencoding();
++tests_run;
}
return result;
}

original_code:
char *test_base58 (void)
{
 do { char *message = test_base58encoding(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_base58checkencoding(); tests_run++; if (message) return message; } while (0);
 return 0;
}

canonical_original_code:
char *test_base58()
{
 do { char *message = test_base58encoding(); tests_run++; if (message) return message; } while (0);
 do { char *message = test_base58checkencoding(); tests_run++; if (message) return message; } while (0);
 return 0;
}

variable_types:
message
char *


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

result = test_vectors();
++tests_run;
return result;
}

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

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


decompiled_code:
const char *test_vectors()
{
int v0; // edx
const char *result; // rax
__int64 v2; // rdx
bool v3; // zf
_BYTE v4[32]; // [rsp+0h] [rbp-E8h] BYREF
__int64 s2[2]; // [rsp+20h] [rbp-C8h] BYREF
int v6; // [rsp+30h] [rbp-B8h]
__int64 v7[2]; // [rsp+40h] [rbp-A8h] BYREF
int v8; // [rsp+50h] [rbp-98h]
__int64 v9[2]; // [rsp+60h] [rbp-88h] BYREF
int v10; // [rsp+70h] [rbp-78h]
char v11[48]; // [rsp+80h] [rbp-68h] BYREF
char v12[56]; // [rsp+B0h] [rbp-38h] BYREF

strcpy(v11, "The quick brown fox jumps over the lazy dog");
s2[0] = 0xD97BB78DF632F337LL;
s2[1] = 0x67AD719596D4EDD7LL;
v6 = 1004402972;
strcpy(v12, "The quick brown fox jumps over the lazy cog");
v7[0] = 0x83330969DF722013LL;
v7[1] = 0xB6E7770BADB6B85ELL;
v8 = -674608399;
v9[0] = 0x54FCE9C5A585119CLL;
v9[1] = 0x48F5E87E97082861LL;
v10 = 831333810;
RIPEMD160(v4, v11, 43LL);
v0 = memcmp(v4, s2, 0x14uLL);
result = "RIPEMD160 should correctly hash the test strings.";
if ( !v0 )
{
RIPEMD160(v4, v12, 43LL);
v2 = (unsigned int)memcmp(v4, v7, 0x14uLL);
result = "RIPEMD160 should correctly hash the test strings.";
if ( !(_DWORD)v2 )
{
RIPEMD160(v4, 0LL, v2);
v3 = memcmp(v4, v9, 0x14uLL) == 0;
result = "RIPEMD160 should correctly hash the zero-length string.";
if ( v3 )
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
const char *func0()
{
int v0; // edx
const char *result; // rax
__int64 v2; // rdx
bool v3; // zf
_BYTE v4[32]; // [rsp+0h] [rbp-E8h] BYREF
__int64 s2[2]; // [rsp+20h] [rbp-C8h] BYREF
int v6; // [rsp+30h] [rbp-B8h]
__int64 v7[2]; // [rsp+40h] [rbp-A8h] BYREF
int v8; // [rsp+50h] [rbp-98h]
__int64 v9[2]; // [rsp+60h] [rbp-88h] BYREF
int v10; // [rsp+70h] [rbp-78h]
char v11[48]; // [rsp+80h] [rbp-68h] BYREF
char v12[56]; // [rsp+B0h] [rbp-38h] BYREF

strcpy(v11, "The quick brown fox jumps over the lazy dog");
s2[0] = 0xD97BB78DF632F337LL;
s2[1] = 0x67AD719596D4EDD7LL;
v6 = 1004402972;
strcpy(v12, "The quick brown fox jumps over the lazy cog");
v7[0] = 0x83330969DF722013LL;
v7[1] = 0xB6E7770BADB6B85ELL;
v8 = -674608399;
v9[0] = 0x54FCE9C5A585119CLL;
v9[1] = 0x48F5E87E97082861LL;
v10 = 831333810;
RIPEMD160(v4, v11, 43LL);
v0 = memcmp(v4, s2, 0x14uLL);
result = "RIPEMD160 should correctly hash the test strings.";
if ( !v0 )
{
RIPEMD160(v4, v12, 43LL);
v2 = (unsigned int)memcmp(v4, v7, 0x14uLL);
result = "RIPEMD160 should correctly hash the test strings.";
if ( !(_DWORD)v2 )
{
RIPEMD160(v4, 0LL, v2);
v3 = memcmp(v4, v9, 0x14uLL) == 0;
result = "RIPEMD160 should correctly hash the zero-length string.";
if ( v3 )
result = 0LL;
}
}
return result;
}

original_code:
static char *test_vectors (void) {
{
 uint8_t hash[20];
 const uint8_t str1[] = "The quick brown fox jumps over the lazy dog";
 const uint8_t hash1[] = {0x37,0xf3,0x32,0xf6,0x8d,0xb7,0x7b,0xd9,0xd7,0xed,0xd4,0x96,0x95,0x71,0xad,0x67,0x1c,0xf9,0xdd,0x3b};
 const uint8_t str2[] = "The quick brown fox jumps over the lazy cog";
 const uint8_t hash2[] = {0x13,0x20,0x72,0xdf,0x69,0x09,0x33,0x83,0x5e,0xb8,0xb6,0xad,0x0b,0x77,0xe7,0xb6,0xf1,0x4a,0xca,0xd7};
 const uint8_t hash3[] = {0x9c,0x11,0x85,0xa5,0xc5,0xe9,0xfc,0x54,0x61,0x28,0x08,0x97,0x7e,0xe8,0xf5,0x48,0xb2,0x25,0x8d,0x31};
 RIPEMD160 (hash, str1, sizeof(str1) - 1);
 do { if (!(memcmp (hash, hash1, 20) == 0)) return "RIPEMD160 should correctly hash the test strings."; } while (0);
 RIPEMD160 (hash, str2, sizeof(str2) - 1);
 do { if (!(memcmp (hash, hash2, 20) == 0)) return "RIPEMD160 should correctly hash the test strings."; } while (0);
 RIPEMD160 (hash, 0, 0);
 do { if (!(memcmp (hash, hash3, 20) == 0)) return "RIPEMD160 should correctly hash the zero-length string."; } while (0);
}
return 0;}

canonical_original_code:
static char *test_vectors() {
{
 unsigned char hash[20];
 unsigned char str1[] = "The quick brown fox jumps over the lazy dog";
 unsigned char hash1[] = {0x37,0xf3,0x32,0xf6,0x8d,0xb7,0x7b,0xd9,0xd7,0xed,0xd4,0x96,0x95,0x71,0xad,0x67,0x1c,0xf9,0xdd,0x3b};
 unsigned char str2[] = "The quick brown fox jumps over the lazy cog";
 unsigned char hash2[] = {0x13,0x20,0x72,0xdf,0x69,0x09,0x33,0x83,0x5e,0xb8,0xb6,0xad,0x0b,0x77,0xe7,0xb6,0xf1,0x4a,0xca,0xd7};
 unsigned char hash3[] = {0x9c,0x11,0x85,0xa5,0xc5,0xe9,0xfc,0x54,0x61,0x28,0x08,0x97,0x7e,0xe8,0xf5,0x48,0xb2,0x25,0x8d,0x31};
 RIPEMD160 (hash, str1, sizeof(str1) - 1);
 do { if (!(memcmp (hash, hash1, 20) == 0)) return "RIPEMD160 should correctly hash the test strings."; } while (0);
 RIPEMD160 (hash, str2, sizeof(str2) - 1);
 do { if (!(memcmp (hash, hash2, 20) == 0)) return "RIPEMD160 should correctly hash the test strings."; } while (0);
 RIPEMD160 (hash, 0, 0);
 do { if (!(memcmp (hash, hash3, 20) == 0)) return "RIPEMD160 should correctly hash the zero-length string."; } while (0);
}
return 0;}

variable_types:
hash
unsigned char [20]


repo: fragapanagos/multiplier

decompiled_code:
int __fastcall time_multiply(void (__fastcall *a1)(_QWORD, _QWORD), const char *a2)
{
int v2; // er13
unsigned int v3; // ebp
int v4; // ebx
int result; // eax
__int64 v6[2]; // [rsp+0h] [rbp-58h] BYREF
struct timespec v7; // [rsp+10h] [rbp-48h] BYREF
struct timespec tp; // [rsp+20h] [rbp-38h] BYREF

printf("\nTiming implementation using %s\n", a2);
puts("n\ttime(s) to compute n^2");
v2 = 16;
v3 = 1;
do
{
clock_gettime(2, &tp);
v4 = 1000;
do
{
a1(v3, v3);
--v4;
}
while ( v4 );
clock_gettime(2, &v7);
diff(&tp, &v7, v6);
result = printf("%d \t%lld.%.9ld\n", v3, v6[0], v6[1]);
v3 *= 2;
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(void (__fastcall *a1)(_QWORD, _QWORD), const char *a2)
{
int v2; // er13
unsigned int v3; // ebp
int v4; // ebx
int result; // eax
__int64 v6[2]; // [rsp+0h] [rbp-58h] BYREF
struct timespec v7; // [rsp+10h] [rbp-48h] BYREF
struct timespec tp; // [rsp+20h] [rbp-38h] BYREF

printf("\nTiming implementation using %s\n", a2);
puts("n\ttime(s) to compute n^2");
v2 = 16;
v3 = 1;
do
{
clock_gettime(2, &tp);
v4 = 1000;
do
{
a1(v3, v3);
--v4;
}
while ( v4 );
clock_gettime(2, &v7);
func7(&tp, &v7, v6);
result = printf("%d \t%lld.%.9ld\n", v3, v6[0], v6[1]);
v3 *= 2;
--v2;
}
while ( v2 );
return result;
}

original_code:
void time_multiply(int (*multiply_func)(int, int), const char *description)
{
   int num_iter = 1000;
   struct timespec time1, time2, time_diff;
   printf("\nTiming implementation using %s\n", description);
   printf("n\ttime(s) to compute n^2\n");
   for (int i = 1; i < 40000; i*=2) {
      clock_gettime(2, &time1);
      for (int j = 0; j<num_iter; j++) {
         multiply_func(i, i);
      }
      clock_gettime(2, &time2);
      diff(&time1, &time2, &time_diff);
      printf("%d \t%lld.%.9ld\n", i, (long long)time_diff.tv_sec, time_diff.tv_nsec);
   }
}

canonical_original_code:
void time_multiply(int (*multiply_func)(int, int), char *description)
{
   int num_iter = 1000;
   struct timespec time1; struct timespec time2; struct timespec time_diff;
   printf("\nTiming implementation using %s\n", description);
   printf("n\ttime(s) to compute n^2\n");
   for (int i = 1; i < 40000; i*=2) {
      clock_gettime(2, &time1);
      for (int j = 0; j<num_iter; j++) {
         multiply_func(i, i);
      }
      clock_gettime(2, &time2);
      diff(&time1, &time2, &time_diff);
      printf("%d \t%lld.%.9ld\n", i, (long long)time_diff.tv_sec, time_diff.tv_nsec);
   }
}

variable_types:
description
char *

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

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall multiply_by_adds(int a1, int a2)
{
int v2; // edx
int i; // eax

v2 = a1;
if ( a2 <= a1 )
v2 = a2;
if ( a2 < a1 )
a2 = a1;
if ( v2 <= 0 )
return 0LL;
for ( i = 0; i != v2; ++i )
;
return (unsigned int)(a2 * v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
int v2; // edx
int i; // eax

v2 = a1;
if ( a2 <= a1 )
v2 = a2;
if ( a2 < a1 )
a2 = a1;
if ( v2 <= 0 )
return 0LL;
for ( i = 0; i != v2; ++i )
;
return (unsigned int)(a2 * v2);
}

original_code:
int multiply_by_adds(int m, int n)
{
   int iterations = ((m) < (n) ? (m) : (n));
   int base = ((m) > (n) ? (m) : (n));
   int result = 0;
   for (int i=0; i < iterations; i++) {
      result += base;
   }
   return result;
}

canonical_original_code:
int multiply_by_adds(int m, int n)
{
   int iterations = ((m) < (n) ? (m) : (n));
   int base = ((m) > (n) ? (m) : (n));
   int result = 0;
   for (int i = 0; i < iterations; i++) {
      result += base;
   }
   return result;
}

variable_types: m int

variable_types: n int

variable_types: iterations int

variable_types: base int

variable_types: result int

return_type: int


decompiled_code:
__int64 __fastcall multiply_by_shifts_adds(int a1, int a2)
{
int v2; // er8
int v3; // ecx
unsigned int v4; // edx

v2 = a1;
if ( a2 <= a1 )
v2 = a2;
if ( a2 >= a1 )
a1 = a2;
v3 = 0;
v4 = 0;
do
{
if ( ((v2 >> v3) & 1) != 0 )
v4 += a1 << v3;
++v3;
}
while ( v3 != 32 );
return v4;
}

original_code:
int multiply_by_shifts_adds(int m, int n)
{
   int multiplier = ((m) < (n) ? (m) : (n));
   int base = ((m) > (n) ? (m) : (n));
   int result = 0;
   for (int i = 0; i < (sizeof(unsigned int) * 8); i++) {
      if (0x1 << i & multiplier) result += base << i;
   }
   return result;
}

variable_types: multiplier int


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

v2 = a1;
if ( a2 <= a1 )
v2 = a2;
v3 = v2;
if ( v2 )
{
if ( a2 < a1 )
a2 = a1;
_BitScanReverse(&v4, v2);
v5 = 31 - (v4 ^ 0x1F);
v3 = 0;
do
{
if ( ((v2 >> v5) & 1) != 0 )
v3 += a2 << v5;
--v5;
}
while ( v5 >= 0 );
}
return v3;
}

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

v2 = a1;
if ( a2 <= a1 )
v2 = a2;
v3 = v2;
if ( v2 )
{
if ( a2 < a1 )
a2 = a1;
_BitScanReverse(&v4, v2);
v5 = 31 - (v4 ^ 0x1F);
v3 = 0;
do
{
if ( ((v2 >> v5) & 1) != 0 )
v3 += a2 << v5;
--v5;
}
while ( v5 >= 0 );
}
return v3;
}

original_code:
int multiply_by_shifts_adds_opt(int m, int n)
{
   int multiplier = ((m) < (n) ? (m) : (n));
   int base = ((m) > (n) ? (m) : (n));
   int result = 0;
   if (multiplier == 0) return 0;
   int lead_zeros = __builtin_clz(multiplier);
   int highest_pow = (sizeof(unsigned int) * 8) - lead_zeros - 1;
   for (int i = highest_pow; i >= 0 ; i--) {
      if (0x1 << i & multiplier) result += base << i;
   }
   return result;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // ebx

puts("Enter two values to multiply together.");
__isoc99_scanf();
printf("%d x %d = %d\n", 10LL, 10LL, 100LL);
v3 = multiply_by_adds(10, 10);
v4 = multiply_by_shifts_adds(10, 10);
v5 = multiply_by_shifts_adds_opt(10, 10);
printf("Using repeated adds implementation, product is \t\t\t%d\n", v3);
printf("Using bitshift adds implementation, product is \t\t\t%d\n", v4);
printf("Using optimized bitshift adds implementation, product is \t%d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp
unsigned int v5; // ebx

puts("Enter two values to multiply together.");
__isoc99_scanf();
printf("%d x %d = %d\n", 10LL, 10LL, 100LL);
v3 = func9(10, 10);
v4 = func10(10, 10);
v5 = func11(10, 10);
printf("Using repeated adds implementation, product is \t\t\t%d\n", v3);
printf("Using bitshift adds implementation, product is \t\t\t%d\n", v4);
printf("Using optimized bitshift adds implementation, product is \t%d\n", v5);
return 0;
}

original_code:
int main()
{
   int m, n;
   m = 10;
   n = 10;
   printf("Enter two values to multiply together.\n");
   scanf("%d%d", &m, &n);
   printf("%d x %d = %d\n", m, n, m*n);
   int sign = 1;
   if (m < 0) {
      sign *= -1;
      m *= -1;
   }
   if (n < 0) {
      sign *= -1;
      n *= -1;
   }
   int prod_adds = multiply_by_adds(m, n);
   int prod_shifts_adds = multiply_by_shifts_adds(m, n);
   int prod_shifts_adds_opt = multiply_by_shifts_adds_opt(m, n);
   if (sign == -1) {
      prod_adds = -prod_adds;
      prod_shifts_adds = -prod_shifts_adds;
      prod_shifts_adds_opt = -prod_shifts_adds_opt;
   }
   printf("Using repeated adds implementation, product is \t\t\t%d\n", prod_adds);
   printf("Using bitshift adds implementation, product is \t\t\t%d\n", prod_shifts_adds);
   printf("Using optimized bitshift adds implementation, product is \t%d\n", prod_shifts_adds_opt);
   return 0;
}

canonical_original_code:
int main()
{
   int m; int n;
   m = 10;
   n = 10;
   printf("Enter two values to multiply together.\n");
   scanf("%d%d", &m, &n);
   printf("%d x %d = %d\n", m, n, m*n);
   int sign = 1;
   if (m < 0) {
      sign *= -1;
      m *= -1;
   }
   if (n < 0) {
      sign *= -1;
      n *= -1;
   }
   int prod_adds = multiply_by_adds(m, n);
   int prod_shifts_adds = multiply_by_shifts_adds(m, n);
   int prod_shifts_adds_opt = multiply_by_shifts_adds_opt(m, n);
   if (sign == -1) {
      prod_adds = -prod_adds;
      prod_shifts_adds = -prod_shifts_adds;
      prod_shifts_adds_opt = -prod_shifts_adds_opt;
   }
   printf("Using repeated adds implementation, product is \t\t\t%d\n", prod_adds);
   printf("Using bitshift adds implementation, product is \t\t\t%d\n", prod_shifts_adds);
   printf("Using optimized bitshift adds implementation, product is \t%d\n", prod_shifts_adds_opt);
   return 0;
}

variable_types: sign int


decompiled_code:
_DWORD *Questions_init()
{
_DWORD *result; // rax

result = malloc(0x50uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
result[5] = 0;
result[6] = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x50uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
result[5] = 0;
result[6] = 0;
return result;
}

original_code:
Questions *Questions_init() {
 Questions *questions = (Questions *)malloc(sizeof(Questions));
 questions->total = 0;
 questions->perCategory[GEOGRAPHY] = 0;
 questions->perCategory[ENTERTAINMENT] = 0;
 questions->perCategory[HISTORY] = 0;
 questions->perCategory[LITERATURE] = 0;
 questions->perCategory[SCIENCE_NATURE] = 0;
 questions->perCategory[SPORTS] = 0;
 return questions;
}

canonical_original_code:
struct Questions *Questions_init() {
 struct Questions *questions = (Questions *)malloc(sizeof(Questions));
 questions->total = 0;
 questions->perCategory[GEOGRAPHY] = 0;
 questions->perCategory[ENTERTAINMENT] = 0;
 questions->perCategory[HISTORY] = 0;
 questions->perCategory[LITERATURE] = 0;
 questions->perCategory[SCIENCE_NATURE] = 0;
 questions->perCategory[SPORTS] = 0;
 return questions;
}

variable_types: struct Questions { int total; int perCategory[6]; struct Question { enum QuestionType { GEOGRAPHY=0, ENTERTAINMENT=1, HISTORY=2, LITERATURE=3, SCIENCE_NATURE=4, SPORTS=5 } category; char question[255]; char valid[64]; char invalid1[64]; char invalid2[64]; char invalid3[64]; } *data[6]; } *

user_defined_types: struct Questions { int total; int perCategory[6]; struct Question *data[6]; }

user_defined_types: struct Question { enum QuestionType category; char question[255]; char valid[64]; char invalid1[64]; char invalid2[64]; char invalid3[64]; }


original_code:
void Questions_addToList(Questions *questions, Question *new) {
 int category = new->category;
 questions->data[category] = (Question *)realloc(questions->data[category], (questions->perCategory[category] + 1) * sizeof(Question));
 questions->total++;
 questions->perCategory[category]++;
 Question *q = &(questions->data[category][questions->perCategory[category] - 1]);
 q->category = new->category;
 strcpy(q->question, new->question);
 strcpy(q->valid, new->valid);
 strcpy(q->invalid1, new->invalid1);
 strcpy(q->invalid2, new->invalid2);
 strcpy(q->invalid3, new->invalid3);
}

canonical_original_code:
void Questions_addToList(struct Questions *questions, struct Question *new) {
 int category = new->category;
 questions->data[category] = (struct Question *)realloc(questions->data[category], (questions->perCategory[category] + 1) * sizeof(Question));
 questions->total++;
 questions->perCategory[category]++;
 struct Question *q = &(questions->data[category][questions->perCategory[category] - 1]);
 q->category = new->category;
 strcpy(q->question, new->question);
 strcpy(q->valid, new->valid);
 strcpy(q->invalid1, new->invalid1);
 strcpy(q->invalid2, new->invalid2);
 strcpy(q->invalid3, new->invalid3);
}

variable_types:
new
struct Question *

variable_types: category int

variable_types: struct Question { enum QuestionType { GEOGRAPHY=0, ENTERTAINMENT=1, HISTORY=2, LITERATURE=3, SCIENCE_NATURE=4, SPORTS=5 } category; char question[255]; char valid[64]; char invalid1[64]; char invalid2[64]; char invalid3[64]; } *


decompiled_code:
void __fastcall Questions_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func6(void *a1)
{
free(a1);
}

original_code:
void Questions_free(Questions *questions) {
 free(questions);
}

canonical_original_code:
void Questions_free(struct Questions *questions) {
 free(questions);
}

user_defined_types: enum QuestionType { GEOGRAPHY=0, ENTERTAINMENT=1, HISTORY=2, LITERATURE=3, SCIENCE_NATURE=4, SPORTS=5 }


decompiled_code:
void __fastcall __noreturn SeleccionCategoria_seleccion(unsigned int a1, unsigned int a2, unsigned int a3)
{
char v4[2]; // [rsp+Bh] [rbp-1Dh] BYREF
char s[2]; // [rsp+Dh] [rbp-1Bh] BYREF
char v6[25]; // [rsp+Fh] [rbp-19h] BYREF

printf(&format);
_isoc99_scanf(&unk_3B4, v6);
while ( 1 )
{
if ( v6[0] == 97 )
{
printf(aSeleccionadaCa, a1);
sprintf(s, "%d", a1);
Socket_escribir(a3, s);
}
else if ( v6[0] == 98 )
{
printf(aSeleccionadaCa, a2);
sprintf(v4, "%d", a2);
Socket_escribir(a3, v4);
}
else
{
printf("Respuesta incorrecta, vuelve a responder.\n>>");
_isoc99_scanf(&unk_3B4, v6);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1, unsigned int a2, unsigned int a3)
{
char v4[2]; // [rsp+Bh] [rbp-1Dh] BYREF
char s[2]; // [rsp+Dh] [rbp-1Bh] BYREF
char v6[25]; // [rsp+Fh] [rbp-19h] BYREF

printf(&format);
_isoc99_scanf(&unk_3B4, v6);
while ( 1 )
{
if ( v6[0] == 97 )
{
printf(aSeleccionadaCa, a1);
sprintf(s, "%d", a1);
Socket_escribir(a3, s);
}
else if ( v6[0] == 98 )
{
printf(aSeleccionadaCa, a2);
sprintf(v4, "%d", a2);
Socket_escribir(a3, v4);
}
else
{
printf("Respuesta incorrecta, vuelve a responder.\n>>");
_isoc99_scanf(&unk_3B4, v6);
}
}
}

original_code:
void SeleccionCategoria_seleccion(int categoria1, int categoria2, int socket){
 char selec;
 char cat1[2];
 char cat2[2];
 printf("¿Qué categoría deseas seleccionar?(a/b)\n>>");
 scanf("%c",&selec);
 while(selec!='a'||selec!='b'){
  if(selec=='a'){
   printf("Seleccionada categoría: %d",categoria1);
   sprintf(cat1, "%d", categoria1);
   Socket_escribir(socket, cat1);
  }else if(selec=='b'){
   printf("Seleccionada categoría: %d",categoria2);
   sprintf(cat2, "%d", categoria2);
   Socket_escribir(socket, cat2);
  }else{
   printf("Respuesta incorrecta, vuelve a responder.\n>>");
   scanf("%c",&selec);
  }
 }
}

variable_types: socket int

variable_types: selec char


decompiled_code:
__int64 __fastcall SeleccionCategoria_Pregunta(unsigned int a1)
{
__int64 v1; // r14
const char *v2; // r12
const char *v3; // rbx
const char *v4; // r13
const char *v5; // rbp
unsigned int v6; // eax
int v7; // eax
__int64 v8; // rdx
int v9; // eax
unsigned int v10; // er15

v1 = ((__int64 (*)(void))Socket_leer)();
v2 = (const char *)Socket_leer(a1);
v3 = (const char *)Socket_leer(a1);
v4 = (const char *)Socket_leer(a1);
v5 = (const char *)Socket_leer(a1);
v6 = time(0LL);
srand(v6);
v7 = rand();
v8 = (unsigned int)v7;
v9 = v7 % 4;
if ( v9 == 1 )
{
printf(&byte_378, v1, v8);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v5, v4, v3, v2);
v10 = 4;
}
else
{
v10 = v9;
if ( v9 == 2 )
{
printf(&byte_378, v1, v8);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v4, v2, v3, v5);
}
else if ( (v8 & 3) != 0 )
{
printf(&byte_378, v1);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v3, v5, v2, v4);
v10 = 3;
}
else
{
printf(&byte_378, v1);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v2, v3, v4, v5);
v10 = 1;
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 v1; // r14
const char *v2; // r12
const char *v3; // rbx
const char *v4; // r13
const char *v5; // rbp
unsigned int v6; // eax
int v7; // eax
__int64 v8; // rdx
int v9; // eax
unsigned int v10; // er15

v1 = ((__int64 (*)(void))Socket_leer)();
v2 = (const char *)Socket_leer(a1);
v3 = (const char *)Socket_leer(a1);
v4 = (const char *)Socket_leer(a1);
v5 = (const char *)Socket_leer(a1);
v6 = time(0LL);
srand(v6);
v7 = rand();
v8 = (unsigned int)v7;
v9 = v7 % 4;
if ( v9 == 1 )
{
printf(&byte_378, v1, v8);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v5, v4, v3, v2);
v10 = 4;
}
else
{
v10 = v9;
if ( v9 == 2 )
{
printf(&byte_378, v1, v8);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v4, v2, v3, v5);
}
else if ( (v8 & 3) != 0 )
{
printf(&byte_378, v1);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v3, v5, v2, v4);
v10 = 3;
}
else
{
printf(&byte_378, v1);
printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n", v2, v3, v4, v5);
v10 = 1;
}
}
return v10;
}

original_code:
int SeleccionCategoria_Pregunta(int socket){
 int correcta;
 char* pregunta;
 char *res1,*res2,*res3,*res4;
 pregunta=Socket_leer(socket);
 res1=Socket_leer(socket);
 res2=Socket_leer(socket);
 res3=Socket_leer(socket);
 res4=Socket_leer(socket);
 int hora = time(((void *)0));
 int numero;
 srand(hora);
 numero = rand()%4;
 switch(numero){
   case 0: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res1,res2,res3,res4);
    correcta=1;
    break;
   case 1: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res4,res3,res2,res1);
    correcta=4;
    break;
   case 2: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res3,res1,res2,res4);
    correcta=2;
    break;
 default: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res2,res4,res1,res3);
    correcta=3;
    break;
 }
 return correcta;
}

canonical_original_code:
int SeleccionCategoria_Pregunta(int socket){
 int correcta;
 char *pregunta;
 char *res1; char *res2; char *res3; char *res4;
 pregunta=Socket_leer(socket);
 res1=Socket_leer(socket);
 res2=Socket_leer(socket);
 res3=Socket_leer(socket);
 res4=Socket_leer(socket);
 int hora = time(((void *)0));
 int numero;
 srand(hora);
 numero = rand()%4;
 switch(numero){
   case 0: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res1,res2,res3,res4);
    correcta=1;
    break;
   case 1: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res4,res3,res2,res1);
    correcta=4;
    break;
   case 2: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res3,res1,res2,res4);
    correcta=2;
    break;
 default: printf("¿%s?\n----------------------------------------------------\n",pregunta);
    printf("\t1-%s.\n\t2-%s.\n\t3-%s.\n\t4-%s.\n",res2,res4,res1,res3);
    correcta=3;
    break;
 }
 return correcta;
}

variable_types: correcta int

variable_types:
pregunta
char *

variable_types: hora int

variable_types: numero int


decompiled_code:
__int64 __fastcall SeleccionCategoria_enviaPreguntas(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
const char *v3; // rdi
int v4; // ebp
__int64 v5; // r12
int v6; // er13
unsigned int v7; // eax
__int64 v8; // rbp
char v10[296]; // [rsp+0h] [rbp-128h] BYREF

v2 = a1;
v3 = (const char *)Socket_leer(a1);
v4 = atoi(v3);
strcpy(v10, "data/questions.db");
v5 = Questions_init(v3, a2, 0x642E736E6F697473LL);
Questions_load(v10, v5);
v6 = *(_DWORD *)(v5 + 4LL * v4 + 4);
v7 = time(0LL);
srand(v7);
v8 = *(_QWORD *)(v5 + 8LL * v4 + 32) + 516LL * (rand() % v6);
Socket_escribir(v2, v8 + 4);
Socket_escribir(v2, v8 + 259);
Socket_escribir(v2, v8 + 323);
Socket_escribir(v2, v8 + 387);
return Socket_escribir(v2, v8 + 451);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
const char *v3; // rdi
int v4; // ebp
__int64 v5; // r12
int v6; // er13
unsigned int v7; // eax
__int64 v8; // rbp
char v10[296]; // [rsp+0h] [rbp-128h] BYREF

v2 = a1;
v3 = (const char *)Socket_leer(a1);
v4 = atoi(v3);
strcpy(v10, "data/questions.db");
v5 = Questions_init(v3, a2, 0x642E736E6F697473LL);
Questions_load(v10, v5);
v6 = *(_DWORD *)(v5 + 4LL * v4 + 4);
v7 = time(0LL);
srand(v7);
v8 = *(_QWORD *)(v5 + 8LL * v4 + 32) + 516LL * (rand() % v6);
Socket_escribir(v2, v8 + 4);
Socket_escribir(v2, v8 + 259);
Socket_escribir(v2, v8 + 323);
Socket_escribir(v2, v8 + 387);
return Socket_escribir(v2, v8 + 451);
}

original_code:
void SeleccionCategoria_enviaPreguntas(int sock){
    Connector connector;
    char *cat = Socket_leer(sock);
    int categoria = atoi(cat);
    strcpy(connector.questionsFilename, "data/questions.db");
    Questions *questions = Questions_init();
    Questions_load(&connector, questions);
    int cuantasEnCategoria = questions->perCategory[categoria];
    srand(time(((void *)0)));
    int cual = rand() % cuantasEnCategoria;
    Question *question = &questions->data[categoria][cual];
    char *pregunta = question->question;
    char *respuestaValida = question->valid;
    char *res2 = question->invalid1;
    char *res3 = question->invalid2;
    char *res4 = question->invalid3;
    Socket_escribir(sock, pregunta);
    Socket_escribir(sock, respuestaValida);
    Socket_escribir(sock, res2);
    Socket_escribir(sock, res3);
    Socket_escribir(sock, res4);
}

canonical_original_code:
void SeleccionCategoria_enviaPreguntas(int sock){
    struct Connector connector;
    char *cat = Socket_leer(sock);
    int categoria = atoi(cat);
    strcpy(connector.questionsFilename, "data/questions.db");
    struct Questions *questions = Questions_init();
    Questions_load(&connector, questions);
    int cuantasEnCategoria = questions->perCategory[categoria];
    srand(time(((void *)0)));
    int cual = rand() % cuantasEnCategoria;
    struct Question *question = &questions->data[categoria][cual];
    char *pregunta = question->question;
    char *respuestaValida = question->valid;
    char *res2 = question->invalid1;
    char *res3 = question->invalid2;
    char *res4 = question->invalid3;
    Socket_escribir(sock, pregunta);
    Socket_escribir(sock, respuestaValida);
    Socket_escribir(sock, res2);
    Socket_escribir(sock, res3);
    Socket_escribir(sock, res4);
}

variable_types: sock int

variable_types: struct Connector { char questionsFilename[255]; }

variable_types:
cat
char *

variable_types: categoria int

variable_types: cuantasEnCategoria int

variable_types: cual int

variable_types:
respuestaValida
char *


decompiled_code:
__int64 __fastcall Socket_esperaConexiones(int a1)
{
int v1; // eax
unsigned int v2; // ebp
unsigned __int16 v3; // bx
unsigned int v4; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( a1 == -1 )
{
puts("Erro aceptando conexionr");
exit(-2);
}
v2 = v1;
v3 = _bswap_16(*(__int16 *)addr.sa_data);
v4 = _bswap_32(*(unsigned int *)&addr.sa_data[2]);
printf(
"Conexion establecida desde la IP %x con el puerto %d.\n----------------------------------------------\n",
v4,
v3);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // eax
unsigned int v2; // ebp
unsigned __int16 v3; // bx
unsigned int v4; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( a1 == -1 )
{
puts("Erro aceptando conexionr");
exit(-2);
}
v2 = v1;
v3 = func0(*(__int16 *)addr.sa_data);
v4 = func1(*(unsigned int *)&addr.sa_data[2]);
printf(
"Conexion establecida desde la IP %x con el puerto %d.\n----------------------------------------------\n",
v4,
v3);
return v2;
}

original_code:
int Socket_esperaConexiones(int sock){
    struct sockaddr_in cliente;
    unsigned int dirlen,cone=0;
    dirlen=sizeof(cliente);
    cone = accept (sock, (struct sockaddr *)&cliente,&dirlen);
    if (sock == -1){
 printf ("Erro aceptando conexionr\n");
 exit(-2);
    }
    printf("Conexion establecida desde la IP %x con el puerto %d.\n----------------------------------------------\n",ntohl(cliente.sin_addr.s_addr),ntohs(cliente.sin_port));
    return cone;
}

canonical_original_code:
int Socket_esperaConexiones(int sock){
    struct sockaddr_in cliente;
    unsigned int dirlen; unsigned int cone = 0;
    dirlen=sizeof(cliente);
    cone = accept (sock, (struct sockaddr *)&cliente,&dirlen);
    if (sock == -1){
 printf ("Erro aceptando conexionr\n");
 exit(-2);
    }
    printf("Conexion establecida desde la IP %x con el puerto %d.\n----------------------------------------------\n",ntohl(cliente.sin_addr.s_addr),ntohs(cliente.sin_port));
    return cone;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
dirlen
unsigned int

variable_types:
cone
unsigned int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall Socket_prepararServidor(const char *a1, const char *a2)
{
unsigned int v2; // ebp
int v3; // er12
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = atoi(a1);
v3 = atoi(a2);
v4 = socket(2, 1, 0);
v6.sa_family = 2;
*(_WORD *)v6.sa_data = _bswap_16(v2);
*(_DWORD *)&v6.sa_data[2] = _bswap_32(0);
if ( bind(v4, &v6, 0x10u) == -1 )
{
puts("Error:El puerto esta ocupado\n");
exit(-2);
}
printf("Escuchando conexiones en el puerto: %d\n", v2);
if ( listen(v4, v3) == -1 )
{
puts("Error creando servidor");
exit(-2);
}
return Socket_esperaConexiones(v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char *a2)
{
unsigned int v2; // ebp
int v3; // er12
int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v2 = atoi(a1);
v3 = atoi(a2);
v4 = socket(2, 1, 0);
v6.sa_family = 2;
*(_WORD *)v6.sa_data = func0(v2);
*(_DWORD *)&v6.sa_data[2] = func1(0);
if ( bind(v4, &v6, 0x10u) == -1 )
{
puts("Error:El puerto esta ocupado\n");
exit(-2);
}
printf("Escuchando conexiones en el puerto: %d\n", v2);
if ( listen(v4, v3) == -1 )
{
puts("Error creando servidor");
exit(-2);
}
return func2(v4);
}

original_code:
int Socket_prepararServidor(char p[],char m[]){
    int sock,puerto,max;
    struct sockaddr_in servidor;
    puerto=atoi(p);
 max=atoi(m);
    sock=socket(2,SOCK_STREAM,0);
    servidor.sin_family=2;
    servidor.sin_port=htons(puerto);
    servidor.sin_addr.s_addr= htonl(((in_addr_t) 0x00000000));
    if (bind (sock, (struct sockaddr *)&servidor, sizeof (servidor)) == -1) {
     printf ("Error:El puerto esta ocupado\n\n");
     exit(-2);
    }
    printf("Escuchando conexiones en el puerto: %d\n",puerto);
    if (listen (sock, max) == -1) {
     printf ("Error creando servidor\n");
     exit(-2);
    }
    return Socket_esperaConexiones(sock);
}

canonical_original_code:
int Socket_prepararServidor(char p[], char m[]){
    int sock; int puerto; int max;
    struct sockaddr_in servidor;
    puerto=atoi(p);
 max=atoi(m);
    sock=socket(2,SOCK_STREAM,0);
    servidor.sin_family=2;
    servidor.sin_port=htons(puerto);
    servidor.sin_addr.s_addr= htonl(((unsigned int) 0x00000000));
    if (bind (sock, (struct sockaddr *)&servidor, sizeof (servidor)) == -1) {
     printf ("Error:El puerto esta ocupado\n\n");
     exit(-2);
    }
    printf("Escuchando conexiones en el puerto: %d\n",puerto);
    if (listen (sock, max) == -1) {
     printf ("Error creando servidor\n");
     exit(-2);
    }
    return Socket_esperaConexiones(sock);
}

variable_types:
p
char []

variable_types:
m
char []

variable_types: puerto int

variable_types: max int


decompiled_code:
__int64 __fastcall Socket_prepararCliente(char *cp, char *nptr)
{
__int16 v2; // bp
int v3; // eax
unsigned int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
struct in_addr inp; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = atoi(nptr);
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
puts("Error no puedo abrir el socket");
exit(-1);
}
v4 = v3;
v6.sa_family = 2;
*(_WORD *)v6.sa_data = _bswap_16(v2);
if ( !inet_aton(cp, &inp) )
{
perror("inet_aton");
exit(1);
}
*(struct in_addr *)&v6.sa_data[2] = inp;
if ( connect(v4, &v6, 0x10u) == -1 )
{
puts("Error no puedo establecer la conexion con el servidor");
exit(-1);
}
puts("Conexion establecida correctamente.");
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *cp, char *nptr)
{
__int16 v2; // bp
int v3; // eax
unsigned int v4; // ebx
struct sockaddr v6; // [rsp+0h] [rbp-38h] BYREF
struct in_addr inp; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = atoi(nptr);
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
puts("Error no puedo abrir el socket");
exit(-1);
}
v4 = v3;
v6.sa_family = 2;
*(_WORD *)v6.sa_data = func0(v2);
if ( !inet_aton(cp, &inp) )
{
perror("inet_aton");
exit(1);
}
*(struct in_addr *)&v6.sa_data[2] = inp;
if ( connect(v4, &v6, 0x10u) == -1 )
{
puts("Error no puedo establecer la conexion con el servidor");
exit(-1);
}
puts("Conexion establecida correctamente.");
return v4;
}

original_code:
int Socket_prepararCliente(char ip[],char port[])
{
  int sock,puerto,conexion;
  struct in_addr dir_ip;
  struct in_addr addr;
  struct sockaddr_in DatoServidor;
  puerto = atoi(port);
  sock=socket(2,SOCK_STREAM,0);
  if (sock==-1) {
    printf("Error no puedo abrir el socket\n");
    exit(-1);
  }
  DatoServidor.sin_family=2;
  DatoServidor.sin_port=htons(puerto);
  if (inet_aton(ip, &dir_ip) == 0)
  {
    perror("inet_aton");
    exit(1);
  }
  DatoServidor.sin_addr=(dir_ip);
  conexion=connect(sock,(struct sockaddr *)&DatoServidor,sizeof(DatoServidor));
  if (conexion==-1)
  {
    printf("Error no puedo establecer la conexion con el servidor\n");
    exit(-1);
  }
  else{
    printf("Conexion establecida correctamente.\n");
    return sock;
  }
}

canonical_original_code:
int Socket_prepararCliente(char ip[], char port[])
{
  int sock; int puerto; int conexion;
  struct in_addr dir_ip;
  struct in_addr addr;
  struct sockaddr_in DatoServidor;
  puerto = atoi(port);
  sock=socket(2,SOCK_STREAM,0);
  if (sock==-1) {
    printf("Error no puedo abrir el socket\n");
    exit(-1);
  }
  DatoServidor.sin_family=2;
  DatoServidor.sin_port=htons(puerto);
  if (inet_aton(ip, &dir_ip) == 0)
  {
    perror("inet_aton");
    exit(1);
  }
  DatoServidor.sin_addr=(dir_ip);
  conexion=connect(sock,(struct sockaddr *)&DatoServidor,sizeof(DatoServidor));
  if (conexion==-1)
  {
    printf("Error no puedo establecer la conexion con el servidor\n");
    exit(-1);
  }
  else{
    printf("Conexion establecida correctamente.\n");
    return sock;
  }
}

variable_types:
ip
char []

variable_types:
port
char []

variable_types: conexion int

variable_types:
addr
struct in_addr { unsigned int s_addr; }


decompiled_code:
ssize_t __fastcall Socket_escribir(int fd, void *buf)
{
size_t v2; // rax

*((_BYTE *)buf + strlen((const char *)buf)) = 10;
*((_BYTE *)buf + strlen((const char *)buf)) = 0;
v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int fd, void *buf)
{
size_t v2; // rax

*((_BYTE *)buf + strlen((const char *)buf)) = 10;
*((_BYTE *)buf + strlen((const char *)buf)) = 0;
v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

original_code:
void Socket_escribir(int sock,char msj[]){
    msj[strlen(msj)]='\n';
    msj[strlen(msj)]=0;
    write(sock,msj,strlen(msj));
    return;
}

canonical_original_code:
void Socket_escribir(int sock, char msj[]){
    msj[strlen(msj)]='\n';
    msj[strlen(msj)]=0;
    write(sock,msj,strlen(msj));
    return;
}

variable_types: sock int

variable_types:
msj
char []


repo: franciozzy/synexec

decompiled_code:
void sigchld_h()
{
worker_pid = 0;
gettimeofday(&s1, 0LL);
while ( waitpid(-1, 0LL, 1) > 0 )
;
}

canonical_decompiled_code:
void func0()
{
worker_pid = 0;
gettimeofday(&s1, 0LL);
while ( waitpid(-1, 0LL, 1) > 0 )
;
}

original_code:
void
sigchld_h(){
 worker_pid = 0;
 gettimeofday(&worker_time[1], ((void *)0));
 while (waitpid(-1, ((void *)0), 1) > 0);
}


original_code:
static void
free_argvp(char **argp, char ***argv){
 int i = 0;
 if (*argv){
  while ((*argv)[i]){
   free((*argv)[i++]);
  }
  if (*argv){
   free(*argv);
   *argv = ((void *)0);
  }
 }
 if (*argp){
  free(*argp);
  *argp = ((void *)0);
 }
}

variable_types:
argp
char **

variable_types:
argv
char ***

variable_types: i int


decompiled_code:
__int64 __fastcall make_argv(char *s, char *a2, void **a3, void ***a4)
{
char *v5; // r13
int v6; // ebx
const unsigned __int16 *v7; // rcx
int v9; // er15
void **v10; // rax
char *v11; // rax
const char *v12; // r12
char *v13; // rax
char *v14; // rax
_QWORD *v15; // r12
char *v16; // rax
__int64 v17; // r12
__int64 v18; // rbx
char **v19; // r13
char *v20; // rax
char *v21; // rax
char **v22; // r13
char *v23; // rax

v5 = s;
v6 = 0;
while ( *v5 )
{
v7 = *_ctype_b_loc();
while ( (v7[*v5] & 0x2000) != 0 )
++v5;
if ( *v5 )
{
++v6;
do
++v5;
while ( *v5 && (v7[*v5] & 0x2000) == 0 );
}
}
if ( v6 )
{
v9 = v6 + 1;
v10 = (void **)calloc(1uLL, 8LL * (v6 + 1));
*a4 = v10;
if ( v10 )
{
v11 = strtok(s, delim);
v12 = v11;
if ( v11 )
{
v13 = strdup(v11);
*a3 = v13;
if ( v13 )
{
v14 = strrchr(v12, 47);
if ( v14 )
{
if ( v14[1] )
{
v15 = *a4;
v16 = strdup(v14 + 1);
*v15 = v16;
if ( v16 )
{
if ( v6 <= 1 )
{
++v6;
return (unsigned int)v6;
}
v17 = 8LL * (unsigned int)(v6 - 2) + 16;
v18 = 8LL;
while ( 1 )
{
v21 = strtok(0LL, delim);
if ( !v21 )
break;
if ( !strcmp(v21, ":CONF:") )
{
v22 = (char **)&(*a4)[(unsigned __int64)v18 / 8];
v23 = strdup(a2);
*v22 = v23;
if ( !v23 )
break;
}
else
{
v19 = (char **)&(*a4)[(unsigned __int64)v18 / 8];
v20 = strdup(v21);
*v19 = v20;
if ( !v20 )
break;
}
v18 += 8LL;
if ( v18 == v17 )
return (unsigned int)v9;
}
}
}
}
}
}
}
else
{
perror("calloc");
fprintf(stderr, "%s: Error alloc'ing %lu bytes for worker argv.\n", "make_argv", 8LL * v9);
}
free_argvp(a3, a4);
v6 = -1;
}
return (unsigned int)v6;
}

original_code:
static int
make_argv(char *data, char *conf_fn, char **argp, char ***argv){
 int argc = 0;
 int i;
 char *ptr = ((void *)0);
 int err = 0;
 ptr = data;
 while(*ptr){
  while (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short int) _ISspace)){
   ptr++;
  }
  if (*ptr){
   argc++;
   while ((*ptr != 0) && (!((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short int) _ISspace))){
    ptr++;
   }
  }
 }
 if (argc == 0){
  goto out;
 }
 argc++;
 if ((*argv = (char **)calloc(1, argc*sizeof(char *))) == ((void *)0)){
  perror("calloc");
  fprintf(stderr, "%s: Error alloc'ing %lu bytes for worker argv.\n", __FUNCTION__, argc*(long unsigned)sizeof(char *));
  goto err;
 }
 if (!(ptr = strtok(data, " \f\n\r\t\v"))) goto err;
 if (!(*argp = strdup(ptr))) goto err;
 if (!(ptr = strrchr(ptr, '/'))) goto err;
 if (!*++ptr) goto err;
 if (!((*argv)[0] = strdup(ptr))) goto err;
 for (i=1; i<argc-1; i++){
  if (!(ptr = strtok(((void *)0), " \f\n\r\t\v"))){
   goto err;
  }
  if (!strcmp(ptr, ":CONF:")){
   if (!((*argv)[i] = strdup(conf_fn))){
    goto err;
   }
  }else{
   if (!((*argv)[i] = strdup(ptr))){
    goto err;
   }
  }
 }
 err = argc;
out:
 return(err);
err:
 err = -1;
 free_argvp(argp, argv);
 goto out;
}

canonical_original_code:
static int make_argv(char *data, char *conf_fn, char **argp, char ***argv){
 int argc = 0;
 int i;
 char *ptr = ((void *)0);
 int err = 0;
 ptr = data;
 while(*ptr){
  while (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short) _ISspace)){
   ptr++;
  }
  if (*ptr){
   argc++;
   while ((*ptr != 0) && (!((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short) _ISspace))){
    ptr++;
   }
  }
 }
 if (argc == 0){
  goto out;
 }
 argc++;
 if ((*argv = (char **)calloc(1, argc*sizeof(char *))) == ((void *)0)){
  perror("calloc");
  fprintf(stderr, "%s: Error alloc'ing %lu bytes for worker argv.\n", __FUNCTION__, argc*(unsigned long)sizeof(char *));
  goto err;
 }
 if (!(ptr = strtok(data, " \f\n\r\t\v"))) goto err;
 if (!(*argp = strdup(ptr))) goto err;
 if (!(ptr = strrchr(ptr, '/'))) goto err;
 if (!*++ptr) goto err;
 if (!((*argv)[0] = strdup(ptr))) goto err;
 for (i=1; i<argc-1; i++){
  if (!(ptr = strtok(((void *)0), " \f\n\r\t\v"))){
   goto err;
  }
  if (!strcmp(ptr, ":CONF:")){
   if (!((*argv)[i] = strdup(conf_fn))){
    goto err;
   }
  }else{
   if (!((*argv)[i] = strdup(ptr))){
    goto err;
   }
  }
 }
 err = argc;
out:
 return(err);
err:
 err = -1;
 free_argvp(argp, argv);
 goto out;
}

variable_types:
data
char *

variable_types: argc int

variable_types:
ptr
char *

variable_types: err int