compare

decompiled_code:
__int64 compare()
{
int i; // er10
unsigned int v1; // er10
__int64 result; // rax
int v3; // er10
int v4; // ecx

for ( i = 0; i != 16; i = v3 + 1 )
{
naive(i, 16843009);
result = branchless(v1, 16843009);
if ( v4 != (_DWORD)result )
__assert_fail("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 0x4Fu, "compare");
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int i; // er10
unsigned int v1; // er10
__int64 result; // rax
int v3; // er10
int v4; // ecx

for ( i = 0; i != 16; i = v3 + 1 )
{
func7(i, 16843009);
result = func8(v1, 16843009);
if ( v4 != (_DWORD)result )
__assert_fail("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 0x4Fu, "compare");
}
return result;
}

original_code:
void compare() {
    const uint32_t mask = 0x01010101;
    for (int i=0; i < 16; i++) {
        ((naive(i, mask) == branchless(i, mask)) ? (void) (0) : __assert_fail ("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 79, __extension__ __PRETTY_FUNCTION__));
    }
}

canonical_original_code:
void compare() {
    unsigned int mask = 0x01010101;
    for (int i = 0; i < 16; i++) {
        ((naive(i, mask) == branchless(i, mask)) ? (void) (0) : __assert_fail ("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 79, __extension__ __PRETTY_FUNCTION__));
    }
}


repo: WojciechMula/toys

decompiled_code:
double __fastcall test_naive(int a1, int a2)
{
int v2; // er12
int i; // er10
int v5; // [rsp+Ch] [rbp-1Ch]

v5 = 0;
v2 = get_time();
if ( a1 > 0 )
{
for ( i = 0; i != a1; v5 += naive(i, a2) )
;
}
return (double)(int)(get_time() - v2) / 1000000.0;
}

canonical_decompiled_code:
double __fastcall func11(int a1, int a2)
{
int v2; // er12
int i; // er10
int v5; // [rsp+Ch] [rbp-1Ch]

v5 = 0;
v2 = func9();
if ( a1 > 0 )
{
for ( i = 0; i != a1; v5 += func7(i, a2) )
;
}
return (double)(int)(func9() - v2) / 1000000.0;
}

original_code:
double test_naive(int iterations, const uint32_t mask) {
    volatile uint32_t result = 0;
    const uint32_t t1 = get_time();
    for (int i=0; i < iterations; i++) {
        result += naive(i, mask);
    }
    const uint32_t t2 = get_time();
    return (t2 - t1)/1000000.0;
}

canonical_original_code:
double test_naive(int iterations, unsigned int mask) {
    unsigned int result = 0;
    unsigned int t1 = get_time();
    for (int i = 0; i < iterations; i++) {
        result += naive(i, mask);
    }
    unsigned int t2 = get_time();
    return (t2 - t1)/1000000.0;
}

variable_types: iterations int

variable_types:
mask
unsigned int

variable_types:
result
unsigned int

variable_types: i int

return_type: double


decompiled_code:
double __fastcall test_branchless(int a1, int a2)
{
int v2; // er12
unsigned int i; // ecx
int v5; // [rsp+Ch] [rbp-1Ch]

v5 = 0;
v2 = get_time();
if ( a1 > 0 )
{
for ( i = 0; i != a1; v5 += branchless(i, a2) )
;
}
return (double)(int)(get_time() - v2) / 1000000.0;
}

canonical_decompiled_code:
double __fastcall func12(int a1, int a2)
{
int v2; // er12
unsigned int i; // ecx
int v5; // [rsp+Ch] [rbp-1Ch]

v5 = 0;
v2 = func9();
if ( a1 > 0 )
{
for ( i = 0; i != a1; v5 += func8(i, a2) )
;
}
return (double)(int)(func9() - v2) / 1000000.0;
}

original_code:
double test_branchless(int iterations, const uint32_t mask) {
    volatile uint32_t result = 0;
    const uint32_t t1 = get_time();
    for (int i=0; i < iterations; i++) {
        result += branchless(i, mask);
    }
    const uint32_t t2 = get_time();
    return (t2 - t1)/1000000.0;
}

canonical_original_code:
double test_branchless(int iterations, unsigned int mask) {
    unsigned int result = 0;
    unsigned int t1 = get_time();
    for (int i = 0; i < iterations; i++) {
        result += branchless(i, mask);
    }
    unsigned int t2 = get_time();
    return (t2 - t1)/1000000.0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // ebx
__int64 v5; // rsi
double v6; // xmm1_8
double v8; // [rsp+8h] [rbp-20h]

v3 = 33;
v4 = 0;
compare(argc, argv, envp);
printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
do
{
v8 = test_naive(0x100000LL, v4);
v5 = v4;
v6 = test_branchless(0x100000LL, v4);
v4 = 2 * v4 + 1;
printf("| %08x | %15.4f | %15.4f | %10.2f |\n", v5, v8, v6, v8 / v6);
--v3;
}
while ( v3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // ebx
__int64 v5; // rsi
double v6; // xmm1_8
double v8; // [rsp+8h] [rbp-20h]

v3 = 33;
v4 = 0;
func10(argc, argv, envp);
printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
do
{
v8 = func11(0x100000LL, v4);
v5 = v4;
v6 = func12(0x100000LL, v4);
v4 = 2 * v4 + 1;
printf("| %08x | %15.4f | %15.4f | %10.2f |\n", v5, v8, v6, v8 / v6);
--v3;
}
while ( v3 );
return 0;
}

original_code:
int main() {
    compare();
    const int iterations = (1 << 20);
    uint32_t mask = 0;
    printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
    for (int i=0; i < 33; i++) {
        const double tn = test_naive(iterations, mask);
        const double tb = test_branchless(iterations, mask);
        const double speedup = tn / tb;
        printf("| %08x | %15.4f | %15.4f | %10.2f |\n", mask, tn, tb, speedup);
        mask = 2*mask + 1;
    }
}

canonical_original_code:
int main() {
    compare();
    int iterations = (1 << 20);
    unsigned int mask = 0;
    printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
    for (int i = 0; i < 33; i++) {
        double tn = test_naive(iterations, mask);
        double tb = test_branchless(iterations, mask);
        double speedup = tn / tb;
        printf("| %08x | %15.4f | %15.4f | %10.2f |\n", mask, tn, tb, speedup);
        mask = 2*mask + 1;
    }
}

variable_types: tn double

variable_types: tb double

variable_types: speedup double

return_type: int


decompiled_code:
__int64 get_time()
{
gettimeofday(&T_1, 0LL);
return (unsigned int)(LODWORD(T_1.tv_usec) + 1000000 * LODWORD(T_1.tv_sec));
}

canonical_decompiled_code:
__int64 func9()
{
gettimeofday(&T_1, 0LL);
return (unsigned int)(LODWORD(T_1.tv_usec) + 1000000 * LODWORD(T_1.tv_sec));
}

original_code:
uint32_t get_time(void) {
    static struct timeval T;
    gettimeofday(&T, ((void *)0));
    return (T.tv_sec * 1000000) + T.tv_usec;
}

canonical_original_code:
unsigned int get_time() {
    static struct timeval T;
    gettimeofday(&T, ((void *)0));
    return (T.tv_sec * 1000000) + T.tv_usec;
}

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

return_type: unsigned int


decompiled_code:
void __fastcall anynonzero_epi32(const char *a1, double a2, __m128 _XMM1)
{
__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k0, zmm0, zmm1
kortestw k0, k0
}
}

canonical_decompiled_code:
void __fastcall func7(const char *a1, double a2, __m128 _XMM1)
{
__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k0, zmm0, zmm1
kortestw k0, k0
}
}

original_code:
int anynonzero_epi32(__m512i x) {
    const __m512i zero = _mm512_setzero_si512();
    const __mmask16 mask = _mm512_cmpneq_epi32_mask(x, zero);
    return mask != 0;
}

canonical_original_code:
int anynonzero_epi32(long long x) {
    long long zero = _mm512_setzero_si512();
    unsigned short mask = _mm512_cmpneq_epi32_mask(x, zero);
    return mask != 0;
}

variable_types:
x
long long

variable_types:
zero
long long

variable_types:
mask
unsigned short


decompiled_code:
__int64 __fastcall anynonzero_epi32_asm(double a1, __m128 _XMM1)
{
__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k1, zmm0, zmm1
ktestw k1, k1
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(double a1, __m128 _XMM1)
{
__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k1, zmm0, zmm1
ktestw k1, k1
}
return 0LL;
}

original_code:
int anynonzero_epi32_asm(__m512i x) {
    __asm__ __volatile__(
        "vpxor      %xmm1, %xmm1, %xmm1\n"
        "vpcmpneqd	%zmm1, %zmm0, %k1\n"
        "xor        %eax, %eax\n"
        "ktestw     %k1, %k1\n"
        "setne      %al\n"
    );
}

canonical_original_code:
int anynonzero_epi32_asm(long long x) {
    __asm__ __volatile__(
        "vpxor      %xmm1, %xmm1, %xmm1\n"
        "vpcmpneqd	%zmm1, %zmm0, %k1\n"
        "xor        %eax, %eax\n"
        "ktestw     %k1, %k1\n"
        "setne      %al\n"
    );
}


decompiled_code:
__int64 __fastcall decimal_digits_sse(signed int a1)
{
__m128i v1; // xmm0

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_sse.c", 9u, "decimal_digits_sse");
v1 = _mm_shuffle_epi32(_mm_cvtsi32_si128(a1), 0);
_EAX = (unsigned __int16)~_mm_movemask_epi8(
_mm_packs_epi16(
_mm_packs_epi32(
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020E0),
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020F0)),
_mm_packs_epi32(_mm_cmpgt_epi32(v1, (__m128i)xmmword_402100), (__m128i)0LL)));
__asm { tzcnt eax, eax }
return (unsigned int)(_EAX + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(signed int a1)
{
__m128i v1; // xmm0

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_sse.c", 9u, "decimal_digits_sse");
v1 = _mm_shuffle_epi32(_mm_cvtsi32_si128(a1), 0);
_EAX = (unsigned __int16)~_mm_movemask_epi8(
_mm_packs_epi16(
_mm_packs_epi32(
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020E0),
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020F0)),
_mm_packs_epi32(_mm_cmpgt_epi32(v1, (__m128i)xmmword_402100), (__m128i)0LL)));
__asm { tzcnt eax, eax }
return (unsigned int)(_EAX + 1);
}

original_code:
int decimal_digits_sse(int32_t x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "decimal_digits_sse.c", 9, __extension__ __PRETTY_FUNCTION__));
    const __m128i powers_a = _mm_setr_epi32(9, 99, 999, 9999);
    const __m128i powers_b = _mm_setr_epi32(99999, 999999, 9999999, 99999999);
    const __m128i powers_c = _mm_setr_epi32(999999999, 2147483647, 2147483647, 2147483647);
    const __m128i value = _mm_set1_epi32(x);
    const __m128i gt0 = _mm_cmpgt_epi32(value, powers_a);
    const __m128i gt1 = _mm_cmpgt_epi32(value, powers_b);
    const __m128i gt2 = _mm_cmpgt_epi32(value, powers_c);
    const __m128i t0 = _mm_packs_epi32(gt0, gt1);
    const __m128i t1 = _mm_packs_epi32(gt2, _mm_setzero_si128());
    const __m128i t2 = _mm_packs_epi16(t0, t1);
    const uint16_t m = ~_mm_movemask_epi8(t2);
    return __builtin_ctz(m) + 1;
}

canonical_original_code:
int decimal_digits_sse(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "decimal_digits_sse.c", 9, __extension__ __PRETTY_FUNCTION__));
    long long powers_a = _mm_setr_epi32(9, 99, 999, 9999);
    long long powers_b = _mm_setr_epi32(99999, 999999, 9999999, 99999999);
    long long powers_c = _mm_setr_epi32(999999999, 2147483647, 2147483647, 2147483647);
    long long value = _mm_set1_epi32(x);
    long long gt0 = _mm_cmpgt_epi32(value, powers_a);
    long long gt1 = _mm_cmpgt_epi32(value, powers_b);
    long long gt2 = _mm_cmpgt_epi32(value, powers_c);
    long long t0 = _mm_packs_epi32(gt0, gt1);
    long long t1 = _mm_packs_epi32(gt2, _mm_setzero_si128());
    long long t2 = _mm_packs_epi16(t0, t1);
    unsigned short m = ~_mm_movemask_epi8(t2);
    return __builtin_ctz(m) + 1;
}

variable_types: x int

variable_types:
value
long long

variable_types:
m
unsigned short


decompiled_code:
__int64 __fastcall decimal_digits_naive(int a1)
{
unsigned int v1; // er8
int i; // eax

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_naive.c", 3u, "decimal_digits_naive");
v1 = 1;
if ( a1 )
{
v1 = 0;
for ( i = 1; i <= a1; i *= 10 )
++v1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // er8
int i; // eax

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_naive.c", 3u, "decimal_digits_naive");
v1 = 1;
if ( a1 )
{
v1 = 0;
for ( i = 1; i <= a1; i *= 10 )
++v1;
}
return v1;
}

original_code:
int decimal_digits_naive(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "decimal_digits_naive.c", 3, __extension__ __PRETTY_FUNCTION__));
 if (x == 0)
  return 1;
 int pow = 1;
 int digits = 0;
 while (x >= pow) {
  pow *= 10;
  digits += 1;
 }
 return digits;
}

variable_types: pow int

variable_types: digits int


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

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
while ( 1 )
{
v7 = atoi(*v4);
v8 = v7;
if ( v7 >= 0 )
break;
++v4;
printf("%15d: negative numbers not supported\n", (unsigned int)v7);
if ( v4 == v3 )
return 0;
}
v5 = (unsigned int)decimal_digits_naive((unsigned int)v7);
printf("%15d: digits %2d (correct)", v8, v5);
v6 = (unsigned int)decimal_digits_sse(v8);
printf(", %2d (SSE proc)", v6);
if ( (_DWORD)v5 != (_DWORD)v6 )
printf(" FAILED");
++v4;
putchar(10);
}
while ( v4 != v3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
const char **v4; // rbx
__int64 v5; // r13
__int64 v6; // rbp
int v7; // eax
unsigned int v8; // ebp

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
while ( 1 )
{
v7 = atoi(*v4);
v8 = v7;
if ( v7 >= 0 )
break;
++v4;
printf("%15d: negative numbers not supported\n", (unsigned int)v7);
if ( v4 == v3 )
return 0;
}
v5 = (unsigned int)func8((unsigned int)v7);
printf("%15d: digits %2d (correct)", v8, v5);
v6 = (unsigned int)func7(v8);
printf(", %2d (SSE proc)", v6);
if ( (_DWORD)v5 != (_DWORD)v6 )
printf(" FAILED");
++v4;
putchar(10);
}
while ( v4 != v3 );
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 for (int i=1; i < argc; i++) {
  const int x = atoi(argv[i]);
  if (x < 0) {
   printf("%15d: negative numbers not supported\n", x);
            continue;
        }
        const int ref = decimal_digits_naive(x);
        printf("%15d: digits %2d (correct)", x, ref);
        const int sse = decimal_digits_sse(x);
        printf(", %2d (SSE proc)", sse);
        if (sse != ref)
            printf(" FAILED");
        putchar('\n');
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 for (int i = 1; i < argc; i++) {
  int x = atoi(argv[i]);
  if (x < 0) {
   printf("%15d: negative numbers not supported\n", x);
            continue;
        }
        int ref = decimal_digits_naive(x);
        printf("%15d: digits %2d (correct)", x, ref);
        int sse = decimal_digits_sse(x);
        printf(", %2d (SSE proc)", sse);
        if (sse != ref)
            printf(" FAILED");
        putchar('\n');
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ref int

variable_types: sse int


decompiled_code:
__int64 get_mxcsr()
{
_mm_getcsr();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
_mm_getcsr();
return 0LL;
}

original_code:
uint32_t get_mxcsr() {
 uint32_t result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

canonical_original_code:
unsigned int get_mxcsr() {
 unsigned int result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

variable_types:
result
unsigned int


decompiled_code:
int *__fastcall set_mxcsr(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

canonical_decompiled_code:
int *__fastcall func8(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

original_code:
void set_mxcsr(uint32_t mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

canonical_original_code:
void set_mxcsr(unsigned int mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

variable_types:
mxcsr
unsigned int

return_type: void


decompiled_code:
int dump_mxcsr()
{
unsigned int v0; // eax

v0 = get_mxcsr();
return print_mxcsr(_bss_start, v0);
}

canonical_decompiled_code:
int func11()
{
unsigned int v0; // eax

v0 = func7();
return func10(_bss_start, v0);
}

original_code:
void dump_mxcsr() {
 print_mxcsr(stdout, get_mxcsr());
}


decompiled_code:
const char *__fastcall fpclassifyf_str(float a1)
{
float v2; // xmm0_4
const char *result; // rax

v2 = fabs(a1);
if ( v2 > 3.4028235e38 )
return "infinite";
result = "normalized";
if ( v2 < 1.1754944e-38 )
{
if ( a1 == 0.0 )
result = "denormals are zero" + 14;
else
result = (const char *)&unk_40211C;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(float a1)
{
float v2; // xmm0_4
const char *result; // rax

v2 = fabs(a1);
if ( v2 > 3.4028235e38 )
return "infinite";
result = "normalized";
if ( v2 < 1.1754944e-38 )
{
if ( a1 == 0.0 )
result = "denormals are zero" + 14;
else
result = (const char *)&unk_40211C;
}
return result;
}

original_code:
const char* fpclassifyf_str(const float x) {
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, x)) {
  case 0:
   return "NaN";
  case 1:
   return "infinite";
  case 2:
   return "zero";
  case 3:
   return "denormalized";
  case 4:
   return "normalized";
  default:
   return "<unknown>";
 }
}

canonical_original_code:
char *fpclassifyf_str(float x) {
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, x)) {
  case 0:
   return "NaN";
  case 1:
   return "infinite";
  case 2:
   return "zero";
  case 3:
   return "denormalized";
  case 4:
   return "normalized";
  default:
   return "<unknown>";
 }
}

variable_types: x float

return_type: char *


original_code:
void test_loop() {
 const int32_t iterations = 10000000;
 uint32_t dummy;
 __asm__ __volatile__(
  "movups %2, %%xmm3\n"
  "movups	%3, %%xmm4\n"
  "1:\n"
  "movaps %%xmm3, %%xmm0\n"
  "movaps %%xmm4, %%xmm1\n"
  "pxor   %%xmm2, %%xmm2\n"
  "mulps  %%xmm1, %%xmm0\n"
  "addps	%%xmm2, %%xmm0\n"
  "loop 1b\n"
  "movups %%xmm0, %4\n"
  : "=c" (dummy)
  : "c" (iterations)
  , "m" (tiny_value)
  , "m" (large_divisor)
  , "m" (final_value)
  : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
 );
}

canonical_original_code:
void test_loop() {
 int iterations = 10000000;
 unsigned int dummy;
 __asm__ __volatile__(
  "movups %2, %%xmm3\n"
  "movups	%3, %%xmm4\n"
  "1:\n"
  "movaps %%xmm3, %%xmm0\n"
  "movaps %%xmm4, %%xmm1\n"
  "pxor   %%xmm2, %%xmm2\n"
  "mulps  %%xmm1, %%xmm0\n"
  "addps	%%xmm2, %%xmm0\n"
  "loop 1b\n"
  "movups %%xmm0, %4\n"
  : "=c" (dummy)
  : "c" (iterations)
  , "m" (tiny_value)
  , "m" (large_divisor)
  , "m" (final_value)
  : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
 );
}

variable_types: iterations int

variable_types:
dummy
unsigned int


decompiled_code:
__int64 __fastcall float2int(__m128i a1)
{
unsigned int v1; // ebx
int *v2; // rax
int *v3; // rdx
__int64 result; // rax
int v5; // esi
int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // ebx
unsigned int v9; // ebx
bool v10; // sf

v1 = _mm_cvtsi128_si32(a1);
v2 = __errno_location();
*v2 = 0;
v3 = v2;
result = 0LL;
v5 = (unsigned __int8)(v1 >> 23);
v6 = v5 - 150;
if ( v5 - 150 >= -23 )
{
v7 = HIBYTE(v1);
if ( v6 > 7 )
{
*v3 = 34;
result = (v1 >> 31) + 0x7FFFFFFF;
}
else
{
v8 = v1 & 0x7FFFFF | 0x800000;
if ( v6 < 0 )
v9 = v8 >> (-106 - v5);
else
v9 = v8 << (v5 + 106);
v10 = (v7 & 0x80u) != 0;
result = v9;
if ( v10 )
result = -v9;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__m128i a1)
{
unsigned int v1; // ebx
int *v2; // rax
int *v3; // rdx
__int64 result; // rax
int v5; // esi
int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // ebx
unsigned int v9; // ebx
bool v10; // sf

v1 = _mm_cvtsi128_si32(a1);
v2 = __errno_location();
*v2 = 0;
v3 = v2;
result = 0LL;
v5 = (unsigned __int8)(v1 >> 23);
v6 = v5 - 150;
if ( v5 - 150 >= -23 )
{
v7 = HIBYTE(v1);
if ( v6 > 7 )
{
*v3 = 34;
result = (v1 >> 31) + 0x7FFFFFFF;
}
else
{
v8 = v1 & 0x7FFFFF | 0x800000;
if ( v6 < 0 )
v9 = v8 >> (-106 - v5);
else
v9 = v8 << (v5 + 106);
v10 = (v7 & 0x80u) != 0;
result = v9;
if ( v10 )
result = -v9;
}
}
return result;
}

original_code:
int float2int(const float value) {
 const uint32_t INT32_MIN_POSITIVE = 2147483648;
 IEEE745_float number = {.value = value};
 (*__errno_location ()) = 0;
 const int shift = number.fields.exp_bias - IEEE745_FLOAT_BIAS - 23;
 if (shift < -23) {
  return 0;
 }
 if (shift > 7) {
  (*__errno_location ()) = 34;
  return number.fields.sign ? (-2147483647-1) : (2147483647);
 }
 uint32_t integer = number.fields.fraction | (1 << 23);
 if (shift < 0)
  integer >>= -shift;
 else if (shift > 0)
  integer <<= shift;
 if (shift == 7) {
  if (number.fields.sign) {
   if (integer > INT32_MIN_POSITIVE) {
    (*__errno_location ()) = 34;
    return (-2147483647-1);
   }
  } else {
   if (integer > (2147483647)) {
    (*__errno_location ()) = 34;
    return (2147483647);
   }
  }
 }
 return (number.fields.sign) ? -integer : integer;
}

canonical_original_code:
int float2int(float value) {
 unsigned int INT32_MIN_POSITIVE = 2147483648;
 union IEEE745_float number = {.value = value};
 (*__errno_location ()) = 0;
 int shift = number.fields.exp_bias - IEEE745_FLOAT_BIAS - 23;
 if (shift < -23) {
  return 0;
 }
 if (shift > 7) {
  (*__errno_location ()) = 34;
  return number.fields.sign ? (-2147483647-1) : (2147483647);
 }
 unsigned int integer = number.fields.fraction | (1 << 23);
 if (shift < 0)
  integer >>= -shift;
 else if (shift > 0)
  integer <<= shift;
 if (shift == 7) {
  if (number.fields.sign) {
   if (integer > INT32_MIN_POSITIVE) {
    (*__errno_location ()) = 34;
    return (-2147483647-1);
   }
  } else {
   if (integer > (2147483647)) {
    (*__errno_location ()) = 34;
    return (2147483647);
   }
  }
 }
 return (number.fields.sign) ? -integer : integer;
}

variable_types: value float

variable_types: union IEEE745_float { struct { unsigned int fraction; unsigned int exp_bias; unsigned int sign; } fields; unsigned int dword; float value; }

variable_types: shift int

variable_types:
integer
unsigned int


decompiled_code:
int __fastcall print_double_params(double a1)
{
printf("sign = %d\n", a1 < 0.0);
printf("exponent = %d\n", (unsigned int)((*(_QWORD *)&a1 >> 52) & 0x7FF) - 1023);
return printf("fraction [hex] = %013llx\n", *(_QWORD *)&a1 & 0xFFFFFFFFFFFFFLL);
}

canonical_decompiled_code:
int __fastcall func7(double a1)
{
printf("sign = %d\n", a1 < 0.0);
printf("exponent = %d\n", (unsigned int)((*(_QWORD *)&a1 >> 52) & 0x7FF) - 1023);
return printf("fraction [hex] = %013llx\n", *(_QWORD *)&a1 & 0xFFFFFFFFFFFFFLL);
}

original_code:
void print_double_params(const double x) {
 IEEE754_double number = {.value = x};
 printf("sign           = %d\n", number.fields.sign);
 printf("exponent       = %d\n", number.fields.exp_bias - IEEE754_DOUBLE_BIAS);
 printf("fraction [hex] = %013llx\n", number.fields.fraction);
}

canonical_original_code:
void print_double_params(double x) {
 union IEEE754_double number = {.value = x};
 printf("sign           = %d\n", number.fields.sign);
 printf("exponent       = %d\n", number.fields.exp_bias - IEEE754_DOUBLE_BIAS);
 printf("fraction [hex] = %013llx\n", number.fields.fraction);
}

variable_types: x double

variable_types: union IEEE754_double { struct { unsigned long fraction; unsigned long exp_bias; unsigned long sign; } fields; unsigned long qword; double value; }


decompiled_code:
int __fastcall print_bin(__int64 a1, int a2, int a3)
{
unsigned __int64 v4; // rbx
int result; // eax

if ( a3 >= a2 )
{
v4 = (unsigned int)a3;
do
{
while ( _bittest64(&a1, v4) )
{
v4 = (unsigned int)(v4 - 1);
result = putchar(49);
if ( a2 > (int)v4 )
return result;
}
v4 = (unsigned int)(v4 - 1);
result = putchar(48);
}
while ( a2 <= (int)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, int a2, int a3)
{
unsigned __int64 v4; // rbx
int result; // eax

if ( a3 >= a2 )
{
v4 = (unsigned int)a3;
do
{
while ( _bittest64(&a1, v4) )
{
v4 = (unsigned int)(v4 - 1);
result = putchar(49);
if ( a2 > (int)v4 )
return result;
}
v4 = (unsigned int)(v4 - 1);
result = putchar(48);
}
while ( a2 <= (int)v4 );
}
return result;
}

original_code:
void print_bin(const uint64_t value, int minbits, int maxbits) {
 for (int bit=maxbits; bit >= minbits; bit--) {
  if (value & ((uint64_t)1 << bit)) {
   putchar('1');
  } else {
   putchar('0');
  }
 }
}

canonical_original_code:
void print_bin(unsigned long value, int minbits, int maxbits) {
 for (int bit = maxbits; bit >= minbits; bit--) {
  if (value & ((unsigned long)1 << bit)) {
   putchar('1');
  } else {
   putchar('0');
  }
 }
}

variable_types:
value
unsigned long

variable_types: minbits int

variable_types: maxbits int

variable_types: bit int


decompiled_code:
int __fastcall repeat_char(char a1, int a2)
{
int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = putchar(a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char a1, int a2)
{
int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = putchar(a1);
}
return result;
}

original_code:
void repeat_char(const char c, const int repeat) {
 for (int i=0; i < repeat; i++)
  putchar(c);
}

canonical_original_code:
void repeat_char(char c, int repeat) {
 for (int i = 0; i < repeat; i++)
  putchar(c);
}

variable_types: c char

variable_types: repeat int

variable_types: i int


decompiled_code:
int __fastcall print_double(double a1)
{
putchar(43);
repeat_char(45, 1);
putchar(43);
repeat_char(45, 11);
putchar(43);
repeat_char(45, 52);
putchar(43);
putchar(10);
putchar(124);
print_bin(*(__int64 *)&a1, 63, 63);
putchar(124);
print_bin(*(__int64 *)&a1, 52, 62);
putchar(124);
print_bin(*(__int64 *)&a1, 0, 51);
putchar(124);
putchar(10);
putchar(43);
repeat_char(45, 1);
putchar(43);
repeat_char(45, 11);
putchar(43);
repeat_char(45, 52);
putchar(43);
putchar(10);
printf("63");
repeat_char(32, 1);
printf("62");
repeat_char(32, 7);
printf("52");
repeat_char(32, 1);
printf("51");
repeat_char(32, 50);
putchar(48);
return putchar(10);
}

original_code:
void print_double(const double x) {
 IEEE754_double number = {.value = x};
 putchar('+');
 repeat_char('-', 1);
 putchar('+');
 repeat_char('-', 11);
 putchar('+');
 repeat_char('-', 52);
 putchar('+');
 putchar('\n');
 putchar('|');
  print_bin(number.qword, 63, 63);
 putchar('|');
  print_bin(number.qword, 52, 62);
 putchar('|');
  print_bin(number.qword, 0, 51);
 putchar('|');
 putchar('\n');
 putchar('+');
 repeat_char('-', 1);
 putchar('+');
 repeat_char('-', 11);
 putchar('+');
 repeat_char('-', 52);
 putchar('+');
 putchar('\n');
 printf("63");
 repeat_char(' ', 1);
 printf("62");
 repeat_char(' ', 7);
 printf("52");
 repeat_char(' ', 1);
 printf("51");
 repeat_char(' ', 50);
 printf("0");
 putchar('\n');
}

canonical_original_code:
void print_double(double x) {
 union IEEE754_double number = {.value = x};
 putchar('+');
 repeat_char('-', 1);
 putchar('+');
 repeat_char('-', 11);
 putchar('+');
 repeat_char('-', 52);
 putchar('+');
 putchar('\n');
 putchar('|');
  print_bin(number.qword, 63, 63);
 putchar('|');
  print_bin(number.qword, 52, 62);
 putchar('|');
  print_bin(number.qword, 0, 51);
 putchar('|');
 putchar('\n');
 putchar('+');
 repeat_char('-', 1);
 putchar('+');
 repeat_char('-', 11);
 putchar('+');
 repeat_char('-', 52);
 putchar('+');
 putchar('\n');
 printf("63");
 repeat_char(' ', 1);
 printf("62");
 repeat_char(' ', 7);
 printf("52");
 repeat_char(' ', 1);
 printf("51");
 repeat_char(' ', 50);
 printf("0");
 putchar('\n');
}

user_defined_types: union IEEE754_double { struct { unsigned long fraction; unsigned long exp_bias; unsigned long sign; } fields; unsigned long qword; double value; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
const char *v5; // rdi
double v7; // [rsp+0h] [rbp-20h]

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
v5 = *v4++;
v7 = atof(v5);
print_double_params();
print_double(v7);
}
while ( v4 != v3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
const char *v5; // rdi
double v7; // [rsp+0h] [rbp-20h]

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
v5 = *v4++;
v7 = atof(v5);
func7();
func10(v7);
}
while ( v4 != v3 );
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 for (int i=1; i < argc; i++) {
  const double value = atof(argv[i]);
  print_double_params(value);
  print_double(value);
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 for (int i = 1; i < argc; i++) {
  double value = atof(argv[i]);
  print_double_params(value);
  print_double(value);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: value double


pext

decompiled_code:
__int64 __fastcall pext(int a1, int a2)
{
int v2; // edx
unsigned int v3; // er8
int i; // eax
int v5; // eax

v2 = 1;
v3 = 0;
for ( i = a2 & -a2; i; i = a2 & -a2 )
{
a2 &= ~i;
v5 = v2 & (-(a1 & i) >> 31);
v2 *= 2;
v3 |= v5;
}
return v3;
}

original_code:
uint32_t pext(uint32_t src, uint32_t mask) {
    uint32_t result = 0;
    uint32_t bit = 1;
    while (1) {
        const uint32_t LSB = (-mask & mask);
        if (LSB == 0) {
            return result;
        }
        mask &= ~LSB;
        const uint32_t value = src & LSB;
        const uint32_t mv = ((int32_t)(-value)) >> 31;
        result |= mv & bit;
        bit <<= 1;
    }
    return result;
}

canonical_original_code:
unsigned int pext(unsigned int src, unsigned int mask) {
    unsigned int result = 0;
    unsigned int bit = 1;
    while (1) {
        unsigned int LSB = (-mask & mask);
        if (LSB == 0) {
            return result;
        }
        mask &= ~LSB;
        unsigned int value = src & LSB;
        unsigned int mv = ((int32_t)(-value)) >> 31;
        result |= mv & bit;
        bit <<= 1;
    }
    return result;
}

variable_types:
src
unsigned int

variable_types:
mask
unsigned int

variable_types:
result
unsigned int

variable_types:
bit
unsigned int

variable_types:
LSB
unsigned int

variable_types:
value
unsigned int

variable_types:
mv
unsigned int


decompiled_code:
bool __fastcall get_bit(int a1, char a2)
{
return (a1 & (1 << a2)) != 0;
}

canonical_decompiled_code:
bool __fastcall func8(int a1, char a2)
{
return (a1 & (1 << a2)) != 0;
}

original_code:
char get_bit(uint32_t v, int bit) {
    const uint32_t mask = ((uint32_t)(1) << bit);
    return (v & mask) != 0;
}

canonical_original_code:
char get_bit(unsigned int v, int bit) {
    unsigned int mask = ((uint32_t)(1) << bit);
    return (v & mask) != 0;
}

variable_types:
v
unsigned int

return_type: char


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

result = a1 & (unsigned int)~(1 << a2);
if ( a3 )
result = a1 | (unsigned int)(1 << a2);
return result;
}

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

result = a1 & (unsigned int)~(1 << a2);
if ( a3 )
result = a1 | (unsigned int)(1 << a2);
return result;
}

original_code:
uint32_t assign_bit(uint32_t v, int bit, int value) {
    const uint32_t mask = ((uint32_t)(1) << bit);
    if (value) {
        return v | mask;
    } else {
        return v & ~mask;
    }
}

canonical_original_code:
unsigned int assign_bit(unsigned int v, int bit, int value) {
    unsigned int mask = ((uint32_t)(1) << bit);
    if (value) {
        return v | mask;
    } else {
        return v & ~mask;
    }
}

variable_types: value int


decompiled_code:
__int64 __fastcall pext_naive(int a1, int a2)
{
int v3; // er9
char v4; // si
unsigned int v5; // er8
int v6; // er9
bool v7; // al
int v8; // er8
char v9; // r10

LOBYTE(v3) = 0;
do
{
v4 = v3;
if ( get_bit(a2, v3) )
{
v7 = get_bit(a1, v4);
v5 = assign_bit(v8, v9, v7);
}
v3 = v6 + 1;
}
while ( v3 != 32 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v3; // er9
char v4; // si
unsigned int v5; // er8
int v6; // er9
bool v7; // al
int v8; // er8
char v9; // r10

LOBYTE(v3) = 0;
do
{
v4 = v3;
if ( func8(a2, v3) )
{
v7 = func8(a1, v4);
v5 = func9(v8, v9, v7);
}
v3 = v6 + 1;
}
while ( v3 != 32 );
return v5;
}

original_code:
uint32_t pext_naive(uint32_t src, uint32_t mask) {
    uint32_t result = 0;
    int k = 0;
    for (int i=0; i < 32; i++) {
        const char bit = get_bit(mask, i);
        if (bit) {
            result = assign_bit(result, k, get_bit(src, i));
            k += 1;
        }
    }
    return result;
}

canonical_original_code:
unsigned int pext_naive(unsigned int src, unsigned int mask) {
    unsigned int result = 0;
    int k = 0;
    for (int i = 0; i < 32; i++) {
        char bit = get_bit(mask, i);
        if (bit) {
            result = assign_bit(result, k, get_bit(src, i));
            k += 1;
        }
    }
    return result;
}

variable_types: k int

variable_types: bit char


original_code:
double sin_taylor5(const double x) {
 const double x2 = x*x;
 const double x3 = x*x2;
 const double x5 = x3*x2;
 const double x7 = x5*x2;
 const double x9 = x7*x2;
 return x - x3*(1.0/6) + x5*(1.0/120) - x7*(1.0/5040) + x9*(1.0/362880);
}

variable_types: x double


original_code:
double sin_taylor4(const double x) {
 const double x2 = x*x;
 const double x3 = x*x2;
 const double x5 = x3*x2;
 const double x7 = x5*x2;
 return x - x3*(1.0/6) + x5*(1.0/120) - x7*(1.0/5040);
}

canonical_original_code:
double sin_taylor4(double x) {
 double x2 = x*x;
 double x3 = x*x2;
 double x5 = x3*x2;
 double x7 = x5*x2;
 return x - x3*(1.0/6) + x5*(1.0/120) - x7*(1.0/5040);
}


original_code:
double sin_taylor3(const double x) {
 const double x2 = x*x;
 const double x3 = x*x2;
 const double x5 = x3*x2;
 return x - x3*(1.0/6) + x5*(1.0/120);
}

canonical_original_code:
double sin_taylor3(double x) {
 double x2 = x*x;
 double x3 = x*x2;
 double x5 = x3*x2;
 return x - x3*(1.0/6) + x5*(1.0/120);
}


mesure

variable_types:
msg
char *

variable_types: tref double

variable_types:
function
double (*)(double x)

variable_types: t double


decompiled_code:
__int64 get_time()
{
gettimeofday(&T_0, 0LL);
return (unsigned int)(LODWORD(T_0.tv_usec) + 1000000 * LODWORD(T_0.tv_sec));
}

canonical_decompiled_code:
__int64 func10()
{
gettimeofday(&T_0, 0LL);
return (unsigned int)(LODWORD(T_0.tv_usec) + 1000000 * LODWORD(T_0.tv_sec));
}

original_code:
uint32_t get_time(void) {
 static struct timeval T;
 gettimeofday(&T, ((void *)0));
 return (T.tv_sec * 1000000) + T.tv_usec;
}

canonical_original_code:
unsigned int get_time() {
 static struct timeval T;
 gettimeofday(&T, ((void *)0));
 return (T.tv_sec * 1000000) + T.tv_usec;
}

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


decompiled_code:
double strstr_wrapper()
{
int v0; // ebx

v0 = get_time();
return (double)(int)(get_time() - v0) / 1000000.0;
}

canonical_decompiled_code:
double func8()
{
int v0; // ebx

v0 = func7();
return (double)(int)(func7() - v0) / 1000000.0;
}

original_code:
double strstr_wrapper(char* data, char* substr) {
 uint32_t t1 = get_time();
 char* c = strstr(data, substr);
 uint32_t t2 = get_time();
 return (t2 - t1)/1000000.0;
}

canonical_original_code:
double strstr_wrapper(char *data, char *substr) {
 unsigned int t1 = get_time();
 char *c = strstr(data, substr);
 unsigned int t2 = get_time();
 return (t2 - t1)/1000000.0;
}

variable_types:
data
char *

variable_types:
substr
char *

variable_types:
c
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int result; // eax
_BYTE *v5; // rax
_BYTE *v6; // rbp
const char **v7; // rbx
const char **v8; // r12
const char *v9; // rsi

result = 0;
if ( argc != 1 )
{
v5 = malloc(0x1000000uLL);
v6 = v5;
if ( v5 )
{
memset(v5, 63, 0x1000000uLL);
v6[0xFFFFFF] = 0;
if ( argc > 1 )
{
v7 = argv + 1;
v8 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v9 = *v7++;
printf("searching string '%s'... ", v9);
fflush(stdout);
strstr_wrapper(v6, *(v7 - 1));
printf("time: %0.3f\n", v3);
}
while ( v7 != v8 );
}
free(v6);
result = 0;
}
else
{
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int result; // eax
_BYTE *v5; // rax
_BYTE *v6; // rbp
const char **v7; // rbx
const char **v8; // r12
const char *v9; // rsi

result = 0;
if ( argc != 1 )
{
v5 = malloc(0x1000000uLL);
v6 = v5;
if ( v5 )
{
memset(v5, 63, 0x1000000uLL);
v6[0xFFFFFF] = 0;
if ( argc > 1 )
{
v7 = argv + 1;
v8 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v9 = *v7++;
printf("searching string '%s'... ", v9);
fflush(stdout);
func8(v6, *(v7 - 1));
printf("time: %0.3f\n", v3);
}
while ( v7 != v8 );
}
free(v6);
result = 0;
}
else
{
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char* argv[]) {
 if (argc == 1)
  return 0;
 const uint32_t MiB = 1024*1024;
 const uint32_t size = 16*MiB;
 char* buffer = (char*)malloc(size);
 if (buffer == ((void *)0))
  return 1;
 memset(buffer, '?', size);
 buffer[size - 1] = '\0';
 for (int i=1; i < argc; i++) {
  printf("searching string '%s'... ", argv[i]);
  fflush(stdout);
  const double dt = strstr_wrapper(buffer, argv[i]);
  printf("time: %0.3f\n", dt);
 }
 free(buffer);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc == 1)
  return 0;
 unsigned int MiB = 1024*1024;
 unsigned int size = 16*MiB;
 char *buffer = (char*)malloc(size);
 if (buffer == ((void *)0))
  return 1;
 memset(buffer, '?', size);
 buffer[size - 1] = '\0';
 for (int i = 1; i < argc; i++) {
  printf("searching string '%s'... ", argv[i]);
  fflush(stdout);
  double dt = strstr_wrapper(buffer, argv[i]);
  printf("time: %0.3f\n", dt);
 }
 free(buffer);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
MiB
unsigned int

variable_types:
size
unsigned int

variable_types:
buffer
char *

variable_types: i int

variable_types: dt double


canonical_decompiled_code:
__int64 func7()
{
gettimeofday(&T_0, 0LL);
return (unsigned int)(LODWORD(T_0.tv_usec) + 1000000 * LODWORD(T_0.tv_sec));
}

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


decompiled_code:
char *__fastcall invoke_fbstp(double a1)
{
char *result; // rax

result = (char *)&buffer;
buffer = __FBSTP__(a1);
return result;
}

canonical_decompiled_code:
char *__fastcall func7(double a1)
{
char *result; // rax

result = (char *)&buffer;
buffer = __FBSTP__(a1);
return result;
}

original_code:
void invoke_fbstp(const double x) {
 __asm__ (
  "fbstp (%1)\n"
  :
  : "f" (x), "r" (buffer)
  : "memory"
 );
}

canonical_original_code:
void invoke_fbstp(double x) {
 __asm__ (
  "fbstp (%1)\n"
  :
  : "f" (x), "r" (buffer)
  : "memory"
 );
}


decompiled_code:
void __fastcall simple_itoa(int a1)
{
int v1; // eax

if ( a1 > 0 )
{
do
{
v1 = a1;
a1 /= 0xAu;
}
while ( v1 > 9 );
LOBYTE(buffer) = v1 + 48;
}
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
int v1; // eax

if ( a1 > 0 )
{
do
{
v1 = a1;
a1 /= 0xAu;
}
while ( v1 > 9 );
LOBYTE(buffer) = v1 + 48;
}
}

original_code:
void simple_itoa(int x) {
 int i = 0;
 while (x > 0) {
  buffer[i] = x % 10 + '0';
  x /= 10;
 }
}

variable_types: x int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rdi
int v4; // eax
int v5; // edx
int v6; // ebx
double v7; // r14
FILE *v8; // rdi
int v9; // eax
__int64 v10; // rdx
unsigned int v11; // ecx
int v12; // ebx
__int64 v13; // rdi
double v15; // [rsp+8h] [rbp-20h]

printf("FBSTP [");
v3 = _bss_start;
fflush(_bss_start);
v4 = get_time(v3, argv);
v5 = 1;
v6 = v4;
do
invoke_fbstp(v3, argv, (unsigned int)(v5 + 1), (double)v5);
while ( v5 != 10000000 );
v7 = (double)(int)(get_time(v3, argv) - v6) / 1000000.0;
printf("%0.3f]", v7);
fflush(_bss_start);
printf(" simple itoa [");
v8 = _bss_start;
fflush(_bss_start);
v9 = get_time(v8, argv);
v11 = 1;
v12 = v9;
do
{
v13 = v11;
simple_itoa(v11, argv, v10, v11 + 1);
}
while ( v11 != 10000000 );
v15 = (double)(int)(get_time(v13, argv) - v12) / 1000000.0;
printf("%0.3f]\n", v15);
fflush(_bss_start);
puts("");
printf("FBST is %.2f slower than simple itoa\n", v7 / v15);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rdi
int v4; // eax
int v5; // edx
int v6; // ebx
double v7; // r14
FILE *v8; // rdi
int v9; // eax
__int64 v10; // rdx
unsigned int v11; // ecx
int v12; // ebx
__int64 v13; // rdi
double v15; // [rsp+8h] [rbp-20h]

printf("FBSTP [");
v3 = _bss_start;
fflush(_bss_start);
v4 = func9(v3, argv);
v5 = 1;
v6 = v4;
do
func7(v3, argv, (unsigned int)(v5 + 1), (double)v5);
while ( v5 != 10000000 );
v7 = (double)(int)(func9(v3, argv) - v6) / 1000000.0;
printf("%0.3f]", v7);
fflush(_bss_start);
printf(" simple itoa [");
v8 = _bss_start;
fflush(_bss_start);
v9 = func9(v8, argv);
v11 = 1;
v12 = v9;
do
{
v13 = v11;
func8(v11, argv, v10, v11 + 1);
}
while ( v11 != 10000000 );
v15 = (double)(int)(func9(v13, argv) - v12) / 1000000.0;
printf("%0.3f]\n", v15);
fflush(_bss_start);
puts("");
printf("FBST is %.2f slower than simple itoa\n", v7 / v15);
return 0;
}

original_code:
int main() {
 int i;
 uint32_t t1, t2;
    double fbstp_time, naive_time;
 const int max = 10000000;
 printf("FBSTP [");
    fflush(stdout);
 t1 = get_time();
 for (i=1; i < max; i++) {
  invoke_fbstp(i);
 }
 t2 = get_time();
    fbstp_time = (t2 - t1)/1000000.0;
 printf("%0.3f]", fbstp_time);
    fflush(stdout);
 printf(" simple itoa [");
    fflush(stdout);
 t1 = get_time();
 for (i=1; i < max; i++) {
  simple_itoa(i);
 }
 t2 = get_time();
    naive_time = (t2 - t1)/1000000.0;
 printf("%0.3f]\n", naive_time);
    fflush(stdout);
    puts("");
    printf("FBST is %.2f slower than simple itoa\n", fbstp_time / naive_time);
 return 0;
}

canonical_original_code:
int main() {
 int i;
 unsigned int t1; unsigned int t2;
    double fbstp_time; double naive_time;
 int max = 10000000;
 printf("FBSTP [");
    fflush(stdout);
 t1 = get_time();
 for (i=1; i < max; i++) {
  invoke_fbstp(i);
 }
 t2 = get_time();
    fbstp_time = (t2 - t1)/1000000.0;
 printf("%0.3f]", fbstp_time);
    fflush(stdout);
 printf(" simple itoa [");
    fflush(stdout);
 t1 = get_time();
 for (i=1; i < max; i++) {
  simple_itoa(i);
 }
 t2 = get_time();
    naive_time = (t2 - t1)/1000000.0;
 printf("%0.3f]\n", naive_time);
    fflush(stdout);
    puts("");
    printf("FBST is %.2f slower than simple itoa\n", fbstp_time / naive_time);
 return 0;
}

variable_types: max int


decompiled_code:
__int64 get_time()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (unsigned int)(LODWORD(v1.tv_usec) + 1000000 * LODWORD(v1.tv_sec));
}

canonical_decompiled_code:
__int64 func9()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (unsigned int)(LODWORD(v1.tv_usec) + 1000000 * LODWORD(v1.tv_sec));
}

original_code:
uint32_t get_time(void) {
 struct timeval T;
 gettimeofday(&T, ((void *)0));
 return (T.tv_sec * 1000000) + T.tv_usec;
}

canonical_original_code:
unsigned int get_time() {
 struct timeval T;
 gettimeofday(&T, ((void *)0));
 return (T.tv_sec * 1000000) + T.tv_usec;
}


decompiled_code:
__int64 get_mxcsr()
{
_mm_getcsr();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
_mm_getcsr();
return 0LL;
}

original_code:
uint32_t get_mxcsr() {
 uint32_t result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

canonical_original_code:
unsigned int get_mxcsr() {
 unsigned int result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

variable_types:
result
unsigned int


decompiled_code:
int *__fastcall set_mxcsr(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

canonical_decompiled_code:
int *__fastcall func8(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

original_code:
void set_mxcsr(uint32_t mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

canonical_original_code:
void set_mxcsr(unsigned int mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

variable_types:
mxcsr
unsigned int


decompiled_code:
int dump_mxcsr()
{
unsigned int v0; // eax

v0 = get_mxcsr();
return print_mxcsr(_bss_start, v0);
}

canonical_decompiled_code:
int func11()
{
unsigned int v0; // eax

v0 = func7();
return func10(_bss_start, v0);
}

original_code:
void dump_mxcsr() {
 print_mxcsr(stdout, get_mxcsr());
}


decompiled_code:
const char *__fastcall fpclassifyf_str(float a1)
{
float v2; // xmm0_4
const char *result; // rax

v2 = fabs(a1);
if ( v2 > 3.4028235e38 )
return "infinite";
result = "normalized";
if ( v2 < 1.1754944e-38 )
{
if ( a1 == 0.0 )
result = "flush to zero" + 9;
else
result = (const char *)&unk_40211C;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(float a1)
{
float v2; // xmm0_4
const char *result; // rax

v2 = fabs(a1);
if ( v2 > 3.4028235e38 )
return "infinite";
result = "normalized";
if ( v2 < 1.1754944e-38 )
{
if ( a1 == 0.0 )
result = "flush to zero" + 9;
else
result = (const char *)&unk_40211C;
}
return result;
}

original_code:
const char* fpclassifyf_str(const float x) {
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, x)) {
  case 0:
   return "NaN";
  case 1:
   return "infinite";
  case 2:
   return "zero";
  case 3:
   return "denormalized";
  case 4:
   return "normalized";
  default:
   return "<unknown>";
 }
}

canonical_original_code:
char *fpclassifyf_str(float x) {
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, x)) {
  case 0:
   return "NaN";
  case 1:
   return "infinite";
  case 2:
   return "zero";
  case 3:
   return "denormalized";
  case 4:
   return "normalized";
  default:
   return "<unknown>";
 }
}

variable_types: x float


decompiled_code:
void mulps_in_loop()
{
__int64 v0; // rcx
__m128 v1; // xmm1

v0 = 10000000LL;
do
{
v1 = _mm_mul_ps((__m128)min_floats, (__m128)min_floats);
--v0;
}
while ( v0 );
final_value = (__int128)v1;
}

original_code:
void mulps_in_loop() {
 const int32_t iterations = 10000000;
 uint32_t dummy;
 __asm__ __volatile__(
  "movups 	%2, %%xmm0\n"
  "1:\n"
  "movaps 	%%xmm0, %%xmm1\n"
  "mulps 		%%xmm1, %%xmm1\n"
  "loop 		1b\n"
  "movups		%%xmm1, %3\n"
  : "=c" (dummy)
  : "c" (iterations)
  , "m" (min_floats)
  , "m" (final_value)
  : "xmm0", "xmm1"
 );
}

canonical_original_code:
void mulps_in_loop() {
 int iterations = 10000000;
 unsigned int dummy;
 __asm__ __volatile__(
  "movups 	%2, %%xmm0\n"
  "1:\n"
  "movaps 	%%xmm0, %%xmm1\n"
  "mulps 		%%xmm1, %%xmm1\n"
  "loop 		1b\n"
  "movups		%%xmm1, %3\n"
  : "=c" (dummy)
  : "c" (iterations)
  , "m" (min_floats)
  , "m" (final_value)
  : "xmm0", "xmm1"
 );
}

variable_types: iterations int

variable_types:
dummy
unsigned int


bswap

decompiled_code:
__int64 __fastcall bswap(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
return _byteswap_ulong(a1);
}

original_code:
uint32_t bswap(uint32_t x) {
    uint32_t result;
    __asm__ __volatile__("bswap %0" : "=&r" (result) : "0" (x));
    return result;
}

canonical_original_code:
unsigned int bswap(unsigned int x) {
    unsigned int result;
    __asm__ __volatile__("bswap %0" : "=&r" (result) : "0" (x));
    return result;
}

variable_types:
x
unsigned int


pext

decompiled_code:
__int64 __fastcall pext(int a1, int a2)
{
int v2; // edx
unsigned int v3; // er8
int i; // eax
int v5; // eax

v2 = 1;
v3 = 0;
for ( i = a2 & -a2; i; i = a2 & -a2 )
{
a2 &= ~i;
v5 = v2 & (-(a1 & i) >> 31);
v2 *= 2;
v3 |= v5;
}
return v3;
}

original_code:
uint32_t pext(uint32_t src, uint32_t mask) {
    uint32_t result = 0;
    uint32_t bit = 1;
    while (1) {
        const uint32_t LSB = (-mask & mask);
        if (LSB == 0) {
            return result;
        }
        mask &= ~LSB;
        const uint32_t value = src & LSB;
        const uint32_t mv = ((int32_t)(-value)) >> 31;
        result |= mv & bit;
        bit <<= 1;
    }
    return result;
}

canonical_original_code:
unsigned int pext(unsigned int src, unsigned int mask) {
    unsigned int result = 0;
    unsigned int bit = 1;
    while (1) {
        unsigned int LSB = (-mask & mask);
        if (LSB == 0) {
            return result;
        }
        mask &= ~LSB;
        unsigned int value = src & LSB;
        unsigned int mv = ((int32_t)(-value)) >> 31;
        result |= mv & bit;
        bit <<= 1;
    }
    return result;
}

variable_types:
src
unsigned int

variable_types:
mask
unsigned int

variable_types:
bit
unsigned int

variable_types:
LSB
unsigned int

variable_types:
value
unsigned int

variable_types:
mv
unsigned int


decompiled_code:
__int64 __fastcall nibble_from_string(unsigned int *a1)
{
unsigned int v1; // edi
int v2; // eax

v1 = *a1;
if ( (v1 & 0xCECECECE) != 0 )
return 0xFFFFFFFFLL;
v2 = bswap(v1);
return pext(v2, 16843009);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
unsigned int v1; // edi
int v2; // eax

v1 = *a1;
if ( (v1 & 0xCECECECE) != 0 )
return 0xFFFFFFFFLL;
v2 = func7(v1);
return func8(v2, 16843009);
}

original_code:
int nibble_from_string(char* string) {
    const uint32_t chars = *((uint32_t*)string);
    if ((chars & ((uint8_t)(~0x31) * 0x01010101u)) != 0) {
        return -1;
    }
    return pext(bswap(chars), 0x01010101);
}

canonical_original_code:
int nibble_from_string(char *string) {
    unsigned int chars = *((uint32_t*)string);
    if ((chars & ((unsigned char)(~0x31) * 0x01010101u)) != 0) {
        return -1;
    }
    return pext(bswap(chars), 0x01010101);
}

variable_types:
string
char *

variable_types:
chars
unsigned int


decompiled_code:
char __fastcall to_bin_naive(int a1, _BYTE *a2)
{
_BYTE *v2; // rdx
int i; // ecx
char result; // al

v2 = a2;
for ( i = 3; i != -1; --i )
{
result = 48 - (((a1 & (1 << i)) == 0) - 1);
*v2++ = result;
}
a2[4] = 0;
return result;
}

canonical_decompiled_code:
char __fastcall func10(int a1, _BYTE *a2)
{
_BYTE *v2; // rdx
int i; // ecx
char result; // al

v2 = a2;
for ( i = 3; i != -1; --i )
{
result = 48 - (((a1 & (1 << i)) == 0) - 1);
*v2++ = result;
}
a2[4] = 0;
return result;
}

original_code:
void to_bin_naive(uint32_t x, char* c) {
    for (int i=3; i >= 0; i--, c++) {
        const uint32_t bit = (1 << i);
        *c = (x & bit) ? '1' : '0';
    }
    *c = 0;
}

canonical_original_code:
void to_bin_naive(unsigned int x, char *c) {
    for (int i = 3; i >= 0; i--, c++) {
        unsigned int bit = (1 << i);
        *c = (x & bit) ? '1' : '0';
    }
    *c = 0;
}

variable_types:
c
char *

variable_types: i int


decompiled_code:
void *__fastcall fill_buffer(double a1)
{
void *result; // rax

result = &buffer;
*(long double *)(unsigned int)&buffer = __FBSTP__(a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func7(double a1)
{
void *result; // rax

result = &buffer;
*(long double *)(unsigned int)&buffer = __FBSTP__(a1);
return result;
}

original_code:
void fill_buffer(const double x) {
 __asm__ (
  "fbstp (%%eax)\n"
  :
  : "f" (x), "a" (buffer)
  : "memory"
 );
}

canonical_original_code:
void fill_buffer(double x) {
 __asm__ (
  "fbstp (%%eax)\n"
  :
  : "f" (x), "a" (buffer)
  : "memory"
 );
}

variable_types: x double


decompiled_code:
int print_buffer()
{
unsigned __int8 *v0; // r14
char v1; // r15
char *v2; // rax
__int64 v3; // rsi
unsigned __int8 v4; // bp
char v5; // bl
char v6; // al

if ( byte_404051 )
{
if ( byte_404051 != (char)0x80 )
{
LODWORD(v2) = printf("NaN/overflow");
return (int)v2;
}
putchar(45);
}
v0 = (unsigned __int8 *)&unk_404050;
v1 = 0;
while ( 1 )
{
v3 = *v0 >> 4;
v4 = *v0 & 0xF;
v5 = *v0 >> 4;
v6 = v1 & 1 | ((_DWORD)v3 != 0);
if ( !v6 )
{
v1 = 0;
if ( (*v0 & 0xF) != 0 )
goto LABEL_12;
goto LABEL_6;
}
printf("%d", v3);
if ( v5 )
break;
v6 = v1 & 1;
if ( v4 )
goto LABEL_12;
LABEL_6:
if ( v6 )
goto LABEL_12;
v1 = 0;
v2 = (char *)(v0 - 1);
if ( &buffer == (_UNKNOWN *)v0 )
goto LABEL_15;
LABEL_8:
v0 = (unsigned __int8 *)v2;
}
v1 = 1;
LABEL_12:
printf("%d", v4);
if ( v4 )
v1 = 1;
v2 = (char *)(v0 - 1);
if ( &buffer != (_UNKNOWN *)v0 )
goto LABEL_8;
LABEL_15:
if ( !v1 )
LODWORD(v2) = putchar(48);
return (int)v2;
}

canonical_decompiled_code:
int func8()
{
unsigned __int8 *v0; // r14
char v1; // r15
char *v2; // rax
__int64 v3; // rsi
unsigned __int8 v4; // bp
char v5; // bl
char v6; // al

if ( byte_404051 )
{
if ( byte_404051 != (char)0x80 )
{
LODWORD(v2) = printf("NaN/overflow");
return (int)v2;
}
putchar(45);
}
v0 = (unsigned __int8 *)&unk_404050;
v1 = 0;
while ( 1 )
{
v3 = *v0 >> 4;
v4 = *v0 & 0xF;
v5 = *v0 >> 4;
v6 = v1 & 1 | ((_DWORD)v3 != 0);
if ( !v6 )
{
v1 = 0;
if ( (*v0 & 0xF) != 0 )
goto LABEL_12;
goto LABEL_6;
}
printf("%d", v3);
if ( v5 )
break;
v6 = v1 & 1;
if ( v4 )
goto LABEL_12;
LABEL_6:
if ( v6 )
goto LABEL_12;
v1 = 0;
v2 = (char *)(v0 - 1);
if ( &buffer == (_UNKNOWN *)v0 )
goto LABEL_15;
LABEL_8:
v0 = (unsigned __int8 *)v2;
}
v1 = 1;
LABEL_12:
printf("%d", v4);
if ( v4 )
v1 = 1;
v2 = (char *)(v0 - 1);
if ( &buffer != (_UNKNOWN *)v0 )
goto LABEL_8;
LABEL_15:
if ( !v1 )
LODWORD(v2) = putchar(48);
return (int)v2;
}

original_code:
void print_buffer() {
 int i;
 char nonzero = 0;
 switch (buffer[9]) {
  case 0x00:
   break;
  case 0x80:
   putchar('-');
   break;
  default:
   printf("NaN/overflow");
   return;
 }
 for (i=8; i >= 0; i--) {
  const int lo = buffer[i] & 0x0f;
  const int hi = (buffer[i] >> 4) & 0x0f;
  if (nonzero || hi > 0) {
   printf("%d", hi);
   if (hi > 0)
    nonzero = 1;
  }
  if (nonzero || lo > 0) {
   printf("%d", lo);
   if (lo > 0)
    nonzero = 1;
  }
 }
 if (!nonzero) {
  putchar('0');
 }
}

canonical_original_code:
void print_buffer() {
 int i;
 char nonzero = 0;
 switch (buffer[9]) {
  case 0x00:
   break;
  case 0x80:
   putchar('-');
   break;
  default:
   printf("NaN/overflow");
   return;
 }
 for (i=8; i >= 0; i--) {
  int lo = buffer[i] & 0x0f;
  int hi = (buffer[i] >> 4) & 0x0f;
  if (nonzero || hi > 0) {
   printf("%d", hi);
   if (hi > 0)
    nonzero = 1;
  }
  if (nonzero || lo > 0) {
   printf("%d", lo);
   if (lo > 0)
    nonzero = 1;
  }
 }
 if (!nonzero) {
  putchar('0');
 }
}

variable_types: nonzero char

variable_types: lo int

variable_types: hi int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
const char *v5; // rdi
int v6; // eax
double v8; // [rsp+0h] [rbp-20h]

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
v5 = *v4++;
atof(v5);
v8 = (double)v6;
printf("printf => %f\n", (double)v6);
printf("FBSTP => ");
fill_buffer(v8);
print_buffer();
putchar(10);
}
while ( v4 != v3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
const char *v5; // rdi
int v6; // eax
double v8; // [rsp+0h] [rbp-20h]

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
v5 = *v4++;
atof(v5);
v8 = (double)v6;
printf("printf => %f\n", (double)v6);
printf("FBSTP => ");
func7(v8);
func8();
putchar(10);
}
while ( v4 != v3 );
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 double x;
 int i;
 for (i=1; i < argc; i++) {
  x = atof(argv[i]);
  printf("printf => %f\n", x);
  printf("FBSTP  => ");
  fill_buffer(x);
  print_buffer();
  putchar('\n');
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 double x;
 int i;
 for (i=1; i < argc; i++) {
  x = atof(argv[i]);
  printf("printf => %f\n", x);
  printf("FBSTP  => ");
  fill_buffer(x);
  print_buffer();
  putchar('\n');
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
double __fastcall custom_floor(double result)
{
__int64 v1; // rdx

v1 = (*(_QWORD *)&result >> 52) & 0x7FFLL;
if ( 1075 - (int)v1 > 52 )
return 0.0;
if ( (unsigned int)(1074 - v1) <= 0x33 )
*(_QWORD *)&result = (-1LL << (51 - (unsigned __int8)(*(_QWORD *)&result >> 52))) & *(_QWORD *)&result & 0xFFFFFFFFFFFFFLL | *(_QWORD *)&result & 0xFFF0000000000000LL;
return result;
}

canonical_decompiled_code:
double __fastcall func7(double result)
{
__int64 v1; // rdx

v1 = (*(_QWORD *)&result >> 52) & 0x7FFLL;
if ( 1075 - (int)v1 > 52 )
return 0.0;
if ( (unsigned int)(1074 - v1) <= 0x33 )
*(_QWORD *)&result = (-1LL << (51 - (unsigned __int8)(*(_QWORD *)&result >> 52))) & *(_QWORD *)&result & 0xFFFFFFFFFFFFFLL | *(_QWORD *)&result & 0xFFF0000000000000LL;
return result;
}

original_code:
double custom_floor(const double x) {
 IEEE754_double number = {.value=x};
 const int dot_position = 52 - (number.fields.exp_bias - IEEE754_DOUBLE_BIAS);
 if (dot_position > 52) {
  return 0.0;
 }
 if (dot_position > 0 && dot_position <= 52) {
  const uint64_t mask = ((uint64_t)1 << dot_position) - 1;
  number.fields.fraction &= ~mask;
 }
 return number.value;
}

canonical_original_code:
double custom_floor(double x) {
 union IEEE754_double number = {.value=x};
 int dot_position = 52 - (number.fields.exp_bias - IEEE754_DOUBLE_BIAS);
 if (dot_position > 52) {
  return 0.0;
 }
 if (dot_position > 0 && dot_position <= 52) {
  unsigned long mask = ((uint64_t)1 << dot_position) - 1;
  number.fields.fraction &= ~mask;
 }
 return number.value;
}

variable_types: union IEEE754_double { struct { unsigned long fraction; unsigned long exp_bias; unsigned long sign; } fields; unsigned long qword; double value; }

variable_types:
mask
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v3; // xmm0
double v4; // xmm1_8
const char **v5; // rbp
const char **v6; // rbx
const char *v7; // rdi
__int128 v8; // xmm2

if ( argc <= 1 )
return 0;
v5 = &argv[(unsigned int)(argc - 2) + 2];
v6 = argv + 1;
do
{
v7 = *v6++;
*(double *)&v3 = atof(v7);
v8 = v3;
v4 = custom_floor(*(double *)&v3, v4, *(double *)&v3);
*((_QWORD *)&v3 + 1) = *((_QWORD *)&v8 + 1);
printf("floor(%0.8f) = %0.8f\n", *(double *)&v8, v4);
}
while ( v6 != v5 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v3; // xmm0
double v4; // xmm1_8
const char **v5; // rbp
const char **v6; // rbx
const char *v7; // rdi
__int128 v8; // xmm2

if ( argc <= 1 )
return 0;
v5 = &argv[(unsigned int)(argc - 2) + 2];
v6 = argv + 1;
do
{
v7 = *v6++;
*(double *)&v3 = atof(v7);
v8 = v3;
v4 = func7(*(double *)&v3, v4, *(double *)&v3);
*((_QWORD *)&v3 + 1) = *((_QWORD *)&v8 + 1);
printf("floor(%0.8f) = %0.8f\n", *(double *)&v8, v4);
}
while ( v6 != v5 );
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 for (int i=1; i < argc; i++) {
  const double x = atof(argv[i]);
  const double floor_x = custom_floor(x);
  printf("floor(%0.8f) = %0.8f\n", x, floor_x);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 for (int i = 1; i < argc; i++) {
  double x = atof(argv[i]);
  double floor_x = custom_floor(x);
  printf("floor(%0.8f) = %0.8f\n", x, floor_x);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall fill_word_naive(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( a1 )
{
if ( !is_power_of_two_non_zero(a1) )
__assert_fail("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 0x1Eu, "fill_word_naive");
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = a1;
if ( a1 )
{
if ( !func7(a1) )
__assert_fail("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 0x1Eu, "fill_word_naive");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
uint32_t fill_word_naive(uint32_t x) {
    ((x == 0 || is_power_of_two_non_zero(x)) ? (void) (0) : __assert_fail ("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 30, __extension__ __PRETTY_FUNCTION__));
    return x ? 0xffffffff : 0;
}

canonical_original_code:
unsigned int fill_word_naive(unsigned int x) {
    ((x == 0 || is_power_of_two_non_zero(x)) ? (void) (0) : __assert_fail ("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 30, __extension__ __PRETTY_FUNCTION__));
    return x ? 0xffffffff : 0;
}

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall fill_word_branchless(int a1)
{
if ( !a1 )
return 0LL;
if ( !is_power_of_two_non_zero(a1) )
__assert_fail("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 0x25u, "fill_word_branchless");
return (unsigned int)(-a1 >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
if ( !a1 )
return 0LL;
if ( !func7(a1) )
__assert_fail("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 0x25u, "fill_word_branchless");
return (unsigned int)(-a1 >> 31);
}

original_code:
uint32_t fill_word_branchless(uint32_t x) {
    ((x == 0 || is_power_of_two_non_zero(x)) ? (void) (0) : __assert_fail ("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 37, __extension__ __PRETTY_FUNCTION__));
    const uint32_t y = -x;
    return ((int32_t)(y) >> 31);
}

canonical_original_code:
unsigned int fill_word_branchless(unsigned int x) {
    ((x == 0 || is_power_of_two_non_zero(x)) ? (void) (0) : __assert_fail ("x == 0 || is_power_of_two_non_zero(x)", "single_bit_to_mask.c", 37, __extension__ __PRETTY_FUNCTION__));
    unsigned int y = -x;
    return ((int)(y) >> 31);
}

variable_types:
y
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
verify(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func10(argc, argv, envp);
return 0;
}

original_code:
int main() {
    verify();
}

canonical_original_code:
int main() {
    verify();
}


decompiled_code:
_BOOL8 __fastcall is_power_of_two_non_zero(int a1)
{
return (a1 & -a1) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
return (a1 & -a1) == a1;
}

original_code:
int is_power_of_two_non_zero(uint32_t x) {
    return (x & -x) == x;
}

canonical_original_code:
int is_power_of_two_non_zero(unsigned int x) {
    return (x & -x) == x;
}


verify

decompiled_code:
__int64 verify()
{
int v0; // ebx
int v1; // er12
unsigned int v2; // ebx
int v3; // ebp
__int64 result; // rax

v0 = fill_word_branchless(0);
if ( v0 != (unsigned int)fill_word_naive(0) )
__assert_fail("fill_word_branchless(0) == fill_word_naive(0)", "single_bit_to_mask.c", 0x31u, "verify");
v1 = 32;
v2 = 1;
do
{
v3 = fill_word_branchless(v2);
result = fill_word_naive(v2);
if ( v3 != (_DWORD)result )
__assert_fail("fill_word_branchless(bit) == fill_word_naive(bit)", "single_bit_to_mask.c", 0x36u, "verify");
v2 *= 2;
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
int v1; // er12
unsigned int v2; // ebx
int v3; // ebp
__int64 result; // rax

v0 = func9(0);
if ( v0 != (unsigned int)func8(0) )
__assert_fail("fill_word_branchless(0) == fill_word_naive(0)", "single_bit_to_mask.c", 0x31u, "verify");
v1 = 32;
v2 = 1;
do
{
v3 = func9(v2);
result = func8(v2);
if ( v3 != (_DWORD)result )
__assert_fail("fill_word_branchless(bit) == fill_word_naive(bit)", "single_bit_to_mask.c", 0x36u, "verify");
v2 *= 2;
--v1;
}
while ( v1 );
return result;
}

original_code:
void verify() {
    ((fill_word_branchless(0) == fill_word_naive(0)) ? (void) (0) : __assert_fail ("fill_word_branchless(0) == fill_word_naive(0)", "single_bit_to_mask.c", 49, __extension__ __PRETTY_FUNCTION__));
    uint32_t bit = 1;
    for (int i=0; i < 32; i++, bit <<= 1) {
        ((fill_word_branchless(bit) == fill_word_naive(bit)) ? (void) (0) : __assert_fail ("fill_word_branchless(bit) == fill_word_naive(bit)", "single_bit_to_mask.c", 54, __extension__ __PRETTY_FUNCTION__));
    }
}

canonical_original_code:
void verify() {
    ((fill_word_branchless(0) == fill_word_naive(0)) ? (void) (0) : __assert_fail ("fill_word_branchless(0) == fill_word_naive(0)", "single_bit_to_mask.c", 49, __extension__ __PRETTY_FUNCTION__));
    unsigned int bit = 1;
    for (int i = 0; i < 32; i++, bit <<= 1) {
        ((fill_word_branchless(bit) == fill_word_naive(bit)) ? (void) (0) : __assert_fail ("fill_word_branchless(bit) == fill_word_naive(bit)", "single_bit_to_mask.c", 54, __extension__ __PRETTY_FUNCTION__));
    }
}

variable_types:
bit
unsigned int


thread

original_code:
void* thread(void* sec) {
 Job *job;
 double dRe, dIm;
 double Cre, Cim, Xre, Xim, Tre, Tim;
 int x, y, i;
 processed_t result;
    result.processed = 0;
 while (1) {
  pthread_mutex_lock(&mutex);
  if (free_job_idx == (((1024*4))/256 * ((1024*4))/256)) {
   pthread_mutex_unlock(&mutex);
   break;
  }
  else {
   job = &jobs[free_job_idx];
   free_job_idx += 1;
  }
  pthread_mutex_unlock(&mutex);
  result.processed += 1;
  dRe = (job->Re2 - job->Re1)/job->width;
  dIm = (job->Im2 - job->Im1)/job->height;
  Cim = job->Im1;
  for (y=0; y < job->height; y++) {
   Cre = job->Re1;
   for (x=0; x < job->width; x++) {
    Xre = 0.0;
    Xim = 0.0;
    for (i=0; i < job->maxiters; i++) {
     Tre = Xre*Xre - Xim*Xim + Cre;
     Tim = 2*Xre*Xim + Cim;
     if (Tre*Tre + Tim*Tim > job->threshold)
      break;
     Xre = Tre;
     Xim = Tim;
    }
    Image[job->yo + y][job->xo + x] = (job->maxiters - i);
    Cre += dRe;
   }
   Cim += dIm;
  }
 }
 return result.thread_result;
}

canonical_original_code:
void *thread(void *sec) {
 struct Job *job;
 double dRe; double dIm;
 double Cre; double Cim; double Xre; double Xim; double Tre; double Tim;
 int x; int y; int i;
 union processed_t result;
    result.processed = 0;
 while (1) {
  pthread_mutex_lock(&mutex);
  if (free_job_idx == (((1024*4))/256 * ((1024*4))/256)) {
   pthread_mutex_unlock(&mutex);
   break;
  }
  else {
   job = &jobs[free_job_idx];
   free_job_idx += 1;
  }
  pthread_mutex_unlock(&mutex);
  result.processed += 1;
  dRe = (job->Re2 - job->Re1)/job->width;
  dIm = (job->Im2 - job->Im1)/job->height;
  Cim = job->Im1;
  for (y=0; y < job->height; y++) {
   Cre = job->Re1;
   for (x=0; x < job->width; x++) {
    Xre = 0.0;
    Xim = 0.0;
    for (i=0; i < job->maxiters; i++) {
     Tre = Xre*Xre - Xim*Xim + Cre;
     Tim = 2*Xre*Xim + Cim;
     if (Tre*Tre + Tim*Tim > job->threshold)
      break;
     Xre = Tre;
     Xim = Tim;
    }
    Image[job->yo + y][job->xo + x] = (job->maxiters - i);
    Cre += dRe;
   }
   Cim += dIm;
  }
 }
 return result.thread_result;
}

variable_types:
sec
void *

variable_types: struct Job { int id; double Re1; double threshold; int xo; int width; int maxiters; } *

variable_types: dRe double

variable_types: dIm double

variable_types: Cre double

variable_types: Cim double

variable_types: Xre double

variable_types: Xim double

variable_types: Tre double

variable_types: Tim double

variable_types: x int

variable_types: y int

variable_types: union processed_t { int processed; void *thread_result; }

return_type: void *


decompiled_code:
int __fastcall print_errno(const char *a1)
{
unsigned int v1; // er12
char *v2; // rax

v1 = *__errno_location();
v2 = strerror(v1);
return printf("%s: %s [errno=%d]\n", a1, v2, v1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
unsigned int v1; // er12
char *v2; // rax

v1 = *__errno_location();
v2 = strerror(v1);
return printf("%s: %s [errno=%d]\n", a1, v2, v1);
}

original_code:
void print_errno(const char* prefix) {
 printf("%s: %s [errno=%d]\n", prefix, strerror((*__errno_location ())), (*__errno_location ()));
}

canonical_original_code:
void print_errno(char *prefix) {
 printf("%s: %s [errno=%d]\n", prefix, strerror((*__errno_location ())), (*__errno_location ()));
}

variable_types:
prefix
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rbp
char *v5; // rdi
int result; // eax

if ( argc <= 1 )
{
printf("usage: %s directory\n", *argv);
result = 1;
}
else
{
v3 = (char **)(argv + 1);
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
fopen_directory(v5);
}
while ( v3 != (char **)v4 );
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rbp
char *v5; // rdi
int result; // eax

if ( argc <= 1 )
{
printf("usage: %s directory\n", *argv);
result = 1;
}
else
{
v3 = (char **)(argv + 1);
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
func8(v5);
}
while ( v3 != (char **)v4 );
result = 0;
}
return result;
}

original_code:
int main(int argc, char* argv[]) {
 int i;
 if (argc > 1) {
  for (i=1; i < argc; i++)
   fopen_directory(argv[i]);
  return 0;
 } else {
  printf("usage: %s directory\n", argv[0]);
  return 1;
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int i;
 if (argc > 1) {
  for (i=1; i < argc; i++)
   fopen_directory(argv[i]);
  return 0;
 } else {
  printf("usage: %s directory\n", argv[0]);
  return 1;
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int


decompiled_code:
__int64 get_mxcsr()
{
_mm_getcsr();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
_mm_getcsr();
return 0LL;
}

original_code:
uint32_t get_mxcsr() {
 uint32_t result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

canonical_original_code:
unsigned int get_mxcsr() {
 unsigned int result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

variable_types:
result
unsigned int


decompiled_code:
int *__fastcall set_mxcsr(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

canonical_decompiled_code:
int *__fastcall func8(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

original_code:
void set_mxcsr(uint32_t mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

canonical_original_code:
void set_mxcsr(unsigned int mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

variable_types:
mxcsr
unsigned int


decompiled_code:
int dump_mxcsr()
{
unsigned int v0; // eax

v0 = get_mxcsr();
return print_mxcsr(_bss_start, v0);
}

canonical_decompiled_code:
int func11()
{
unsigned int v0; // eax

v0 = func7();
return func10(_bss_start, v0);
}

original_code:
void dump_mxcsr() {
 print_mxcsr(stdout, get_mxcsr());
}


gettime

decompiled_code:
__suseconds_t gettime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (v1.tv_usec + 1000000 * v1.tv_sec) / 1000;
}

canonical_decompiled_code:
__suseconds_t func18()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (v1.tv_usec + 1000000 * v1.tv_sec) / 1000;
}

original_code:
unsigned gettime() {
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return (tv.tv_sec * 1000000 + tv.tv_usec)/1000;
}

canonical_original_code:
unsigned int gettime() {
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return (tv.tv_sec * 1000000 + tv.tv_usec)/1000;
}

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
void *v4; // rbp
FILE *v5; // rax
FILE *v6; // r12
unsigned int v7; // eax
FILE *v8; // rax
FILE *v9; // r12
int v10; // er14
int v11; // er13
int v12; // er15
unsigned __int64 v13; // rbx
unsigned int i; // er12
__int64 v15; // rsi
int v16; // eax
__int64 v17; // [rsp+0h] [rbp-48h] BYREF
unsigned __int64 v18; // [rsp+8h] [rbp-40h]

if ( argc == 4 )
{
printf("loading dictionary... ");
fflush(_bss_start);
v4 = (void *)trie_new_node();
if ( !v4 )
__assert_fail("root != NULL", "test.c", 0x70u, "main");
v5 = fopen(argv[1], "rt");
v6 = v5;
if ( !v5 )
__assert_fail("f != NULL", "test.c", 0x72u, "main");
v7 = load_dictionary(v4, v5);
printf("%d words loaded\n", v7);
fclose(v6);
printf("loading test words... ");
fflush(_bss_start);
v8 = fopen(argv[2], "rt");
v9 = v8;
if ( !v8 )
__assert_fail("f != NULL", "test.c", 0x7Cu, "main");
load_words(v8);
printf("%ld words loaded\n", v18);
fclose(v9);
puts("benchmarking...");
v10 = atoi(argv[3]);
if ( v10 <= 0 )
__assert_fail("iterations > 0", "test.c", 0x85u, "main");
v11 = 0;
v12 = gettime();
do
{
v13 = 0LL;
for ( i = 0; v18 > v13; i += trie_lookup(v4, v15) )
v15 = *(_QWORD *)(v17 + 8 * v13++);
++v11;
}
while ( v10 != v11 );
v16 = gettime();
printf("... time = %d ms, matched words = %d\n", (unsigned int)(v16 - v12), i);
free_strings(&v17);
trie_destroy(v4);
result = 0;
}
else
{
usage(argc, argv, envp);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
void *v4; // rbp
FILE *v5; // rax
FILE *v6; // r12
unsigned int v7; // eax
FILE *v8; // rax
FILE *v9; // r12
int v10; // er14
int v11; // er13
int v12; // er15
unsigned __int64 v13; // rbx
unsigned int i; // er12
__int64 v15; // rsi
int v16; // eax
__int64 v17; // [rsp+0h] [rbp-48h] BYREF
unsigned __int64 v18; // [rsp+8h] [rbp-40h]

if ( argc == 4 )
{
printf("loading dictionary... ");
fflush(_bss_start);
v4 = (void *)func10();
if ( !v4 )
__assert_fail("root != NULL", "test.c", 0x70u, "main");
v5 = fopen(argv[1], "rt");
v6 = v5;
if ( !v5 )
__assert_fail("f != NULL", "test.c", 0x72u, "main");
v7 = func15(v4, v5);
printf("%d words loaded\n", v7);
fclose(v6);
printf("loading test words... ");
fflush(_bss_start);
v8 = fopen(argv[2], "rt");
v9 = v8;
if ( !v8 )
__assert_fail("f != NULL", "test.c", 0x7Cu, "main");
func16(v8);
printf("%ld words loaded\n", v18);
fclose(v9);
puts("benchmarking...");
v10 = atoi(argv[3]);
if ( v10 <= 0 )
__assert_fail("iterations > 0", "test.c", 0x85u, "main");
v11 = 0;
v12 = func18();
do
{
v13 = 0LL;
for ( i = 0; v18 > v13; i += func12(v4, v15) )
v15 = *(_QWORD *)(v17 + 8 * v13++);
++v11;
}
while ( v10 != v11 );
v16 = func18();
printf("... time = %d ms, matched words = %d\n", (unsigned int)(v16 - v12), i);
func17(&v17);
func13(v4);
result = 0;
}
else
{
func19(argc, argv, envp);
result = 1;
}
return result;
}

original_code:
int main(int argc, char* argv[]) {
 if (argc < 4)
  usage();
    const uint32_t min = atoi(argv[1]);
    const uint32_t max = atoi(argv[2]);
    if (min >= max) {
        usage();
    }
    const uint32_t count = atoi(argv[3]);
    printf("Parameters: min = %u, max = %d, count = %d\n", min, max, count);
    struct Procedure* item;
    unsigned reference_time = 0;
    for (item = procedures; item->procedure != ((void *)0); item++) {
        if (!is_keyword(item->keyword, argc, argv)) {
            continue;
        }
        unsigned tmp = count;
        convfun proc = item->procedure;
        printf("%-20s ", item->name);
        fflush(stdout);
        const unsigned t1 = gettime();
        while (tmp-- > 0) {
            for (uint32_t x = min; x <= max; x++) {
                proc(x);
            }
        }
        const unsigned t2 = gettime();
        const unsigned time = t2 - t1;
        printf("%6u ms", time);
        if (reference_time == 0) {
            reference_time = time;
            putchar('\n');
        } else {
            printf(" (%0.2f)\n", ((float)reference_time)/time);
        }
    }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc < 4)
  usage();
    unsigned int min = atoi(argv[1]);
    unsigned int max = atoi(argv[2]);
    if (min >= max) {
        usage();
    }
    unsigned int count = atoi(argv[3]);
    printf("Parameters: min = %u, max = %d, count = %d\n", min, max, count);
    struct Procedure *item;
    unsigned int reference_time = 0;
    for (item = procedures; item->procedure != ((void *)0); item++) {
        if (!is_keyword(item->keyword, argc, argv)) {
            continue;
        }
        unsigned int tmp = count;
        char *(*proc)(unsigned int) = item->procedure;
        printf("%-20s ", item->name);
        fflush(stdout);
        unsigned int t1 = gettime();
        while (tmp-- > 0) {
            for (unsigned int x = min; x <= max; x++) {
                proc(x);
            }
        }
        unsigned int t2 = gettime();
        unsigned int time = t2 - t1;
        printf("%6u ms", time);
        if (reference_time == 0) {
            reference_time = time;
            putchar('\n');
        } else {
            printf(" (%0.2f)\n", ((float)reference_time)/time);
        }
    }
 return 0;
}

variable_types:
min
unsigned int

variable_types:
max
unsigned int

variable_types:
count
unsigned int

variable_types: struct Procedure { char *(*procedure)(unsigned int); char *name; char *keyword; } *

variable_types:
tmp
unsigned int

variable_types:
proc
char *(*)(unsigned int)

variable_types:
x
unsigned int

variable_types:
time
unsigned int


usage

decompiled_code:
int usage()
{
return puts("program dictionary-file word-test-file iterations-count");
}

canonical_decompiled_code:
int func19()
{
return puts("program dictionary-file word-test-file iterations-count");
}

original_code:
void usage() {
 puts("usage: progname min max count [functions]");
 puts("");
 puts("where function is:");
    struct Procedure* item;
    for (item = procedures; item->procedure != ((void *)0); item++) {
        printf("* %-8s - %s\n", item->keyword, item->name);
    }
 exit(1);
}

canonical_original_code:
void usage() {
 puts("usage: progname min max count [functions]");
 puts("");
 puts("where function is:");
    struct Procedure *item;
    for (item = procedures; item->procedure != ((void *)0); item++) {
        printf("* %-8s - %s\n", item->keyword, item->name);
    }
 exit(1);
}

user_defined_types: struct Procedure { char *(*procedure)(unsigned int); char *name; char *keyword; }


bswap

decompiled_code:
__int64 __fastcall bswap(unsigned int a1)
{
return HIBYTE(a1) | (BYTE1(a1) << 16) | ((unsigned __int8)a1 << 24) | (BYTE2(a1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
return HIBYTE(a1) | (BYTE1(a1) << 16) | ((unsigned __int8)a1 << 24) | (BYTE2(a1) << 8);
}

original_code:
uint32_t bswap(uint32_t x) {
    uint32_t result;
    __asm__ __volatile__("bswap %0" : "=&r" (result) : "0" (x));
    return result;
}

canonical_original_code:
unsigned int bswap(unsigned int x) {
    unsigned int result;
    __asm__ __volatile__("bswap %0" : "=&r" (result) : "0" (x));
    return result;
}


verify

decompiled_code:
__int64 verify(void)
{
__int64 result; // rax
int v1; // [rsp+10h] [rbp-20h]
int v2; // [rsp+14h] [rbp-1Ch]
__int64 v3; // [rsp+18h] [rbp-18h]
int v4; // [rsp+20h] [rbp-10h]
int v5; // [rsp+24h] [rbp-Ch]
unsigned int v6; // [rsp+28h] [rbp-8h]
unsigned int i; // [rsp+2Ch] [rbp-4h]

prepare_single_lookup();
result = prepare_two_lookups();
for ( i = 0; i <= 0xFFF; ++i )
{
v6 = to_oct_naive(i);
v5 = to_oct_mul(i);
v4 = to_oct_pdep(i);
v3 = to_oct_sse2(i | (i << 12));
v2 = to_oct_single_lookup(i);
v1 = to_oct_two_lookups(i);
if ( v6 != v5 )
__assert_fail("naive == mul", "verify.cpp", 0x34u, "void verify()");
if ( v6 != v4 )
__assert_fail("naive == pdep", "verify.cpp", 0x35u, "void verify()");
if ( v6 != (_DWORD)v3 )
__assert_fail("naive == sse2_lo", "verify.cpp", 0x36u, "void verify()");
if ( v6 != HIDWORD(v3) )
__assert_fail("naive == sse2_hi", "verify.cpp", 0x37u, "void verify()");
if ( v6 != v2 )
__assert_fail("naive == LUT1", "verify.cpp", 0x38u, "void verify()");
result = v6;
if ( v6 != v1 )
__assert_fail("naive == LUT2", "verify.cpp", 0x39u, "void verify()");
}
return result;
}

canonical_decompiled_code:
__int64 func8(void)
{
__int64 result; // rax
int v1; // [rsp+10h] [rbp-20h]
int v2; // [rsp+14h] [rbp-1Ch]
__int64 v3; // [rsp+18h] [rbp-18h]
int v4; // [rsp+20h] [rbp-10h]
int v5; // [rsp+24h] [rbp-Ch]
unsigned int v6; // [rsp+28h] [rbp-8h]
unsigned int i; // [rsp+2Ch] [rbp-4h]

func17();
result = func19();
for ( i = 0; i <= 0xFFF; ++i )
{
v6 = func13(i);
v5 = func14(i);
v4 = func15(i);
v3 = func16(i | (i << 12));
v2 = func18(i);
v1 = func20(i);
if ( v6 != v5 )
__assert_fail("naive == mul", "verify.cpp", 0x34u, "void verify()");
if ( v6 != v4 )
__assert_fail("naive == pdep", "verify.cpp", 0x35u, "void verify()");
if ( v6 != (_DWORD)v3 )
__assert_fail("naive == sse2_lo", "verify.cpp", 0x36u, "void verify()");
if ( v6 != HIDWORD(v3) )
__assert_fail("naive == sse2_hi", "verify.cpp", 0x37u, "void verify()");
if ( v6 != v2 )
__assert_fail("naive == LUT1", "verify.cpp", 0x38u, "void verify()");
result = v6;
if ( v6 != v1 )
__assert_fail("naive == LUT2", "verify.cpp", 0x39u, "void verify()");
}
return result;
}

original_code:
void verify() {
    char buf[5];
    for (int x=0; x < 16; x++) {
        to_bin_naive(x, buf);
        const int parsed = nibble_from_string(buf);
        printf("%d => '%s' => %d\n", x, buf, parsed);
        ((x == parsed) ? (void) (0) : __assert_fail ("x == parsed", "parse_string.c", 54, __extension__ __PRETTY_FUNCTION__));
    }
    buf[0] = '?';
    ((nibble_from_string(buf) < 0) ? (void) (0) : __assert_fail ("nibble_from_string(buf) < 0", "parse_string.c", 58, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void verify() {
    char buf[5];
    for (int x = 0; x < 16; x++) {
        to_bin_naive(x, buf);
        int parsed = nibble_from_string(buf);
        printf("%d => '%s' => %d\n", x, buf, parsed);
        ((x == parsed) ? (void) (0) : __assert_fail ("x == parsed", "parse_string.c", 54, __extension__ __PRETTY_FUNCTION__));
    }
    buf[0] = '?';
    ((nibble_from_string(buf) < 0) ? (void) (0) : __assert_fail ("nibble_from_string(buf) < 0", "parse_string.c", 58, __extension__ __PRETTY_FUNCTION__));
}

variable_types:
buf
char [5]

variable_types: x int

variable_types: parsed int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
verify_correcteness();
verify();
puts("all ok");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7();
func8();
puts("all ok");
return 0;
}


compare

original_code:
void compare() {
    const uint32_t mask = 0x01010101;
    for (int i=0; i < 16; i++) {
        ((naive(i, mask) == branchless(i, mask)) ? (void) (0) : __assert_fail ("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 79, __extension__ __PRETTY_FUNCTION__));
    }
}

canonical_original_code:
void compare() {
    unsigned int mask = 0x01010101;
    for (int i = 0; i < 16; i++) {
        ((naive(i, mask) == branchless(i, mask)) ? (void) (0) : __assert_fail ("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 79, __extension__ __PRETTY_FUNCTION__));
    }
}

variable_types:
mask
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
compare(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9(argc, argv, envp);
return 0;
}

original_code:
int main() {
    compare();
    const int iterations = (1 << 20);
    uint32_t mask = 0;
    printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
    for (int i=0; i < 33; i++) {
        const double tn = test_naive(iterations, mask);
        const double tb = test_branchless(iterations, mask);
        const double speedup = tn / tb;
        printf("| %08x | %15.4f | %15.4f | %10.2f |\n", mask, tn, tb, speedup);
        mask = 2*mask + 1;
    }
}

canonical_original_code:
int main() {
    compare();
    int iterations = (1 << 20);
    unsigned int mask = 0;
    printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
    for (int i = 0; i < 33; i++) {
        double tn = test_naive(iterations, mask);
        double tb = test_branchless(iterations, mask);
        double speedup = tn / tb;
        printf("| %08x | %15.4f | %15.4f | %10.2f |\n", mask, tn, tb, speedup);
        mask = 2*mask + 1;
    }
}

variable_types: iterations int

variable_types: tn double

variable_types: tb double

variable_types: speedup double


naive

decompiled_code:
__int64 __fastcall convert_to_bin::naive(convert_to_bin *this)
{
char v1; // dl
__int64 v3; // [rsp+4h] [rbp-10h]
unsigned __int8 v4; // [rsp+Fh] [rbp-5h]
int i; // [rsp+10h] [rbp-4h]

for ( i = 7; i >= 0; --i )
{
v4 = 1 << i;
if ( (v4 & (unsigned __int8)this) != 0 )
v1 = 49;
else
v1 = 48;
*((_BYTE *)&v3 + i) = v1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall convert_to_bin::func7(convert_to_bin *this)
{
char v1; // dl
__int64 v3; // [rsp+4h] [rbp-10h]
unsigned __int8 v4; // [rsp+Fh] [rbp-5h]
int i; // [rsp+10h] [rbp-4h]

for ( i = 7; i >= 0; --i )
{
v4 = 1 << i;
if ( (v4 & (unsigned __int8)this) != 0 )
v1 = 49;
else
v1 = 48;
*((_BYTE *)&v3 + i) = v1;
}
return v3;
}

original_code:
uint32_t naive(uint32_t src, uint32_t mask) {
    uint32_t result = 0;
    uint32_t mask_bit = 1;
    uint32_t src_bit = 1;
    int i;
    for (i=0; i < 32; i++, mask_bit <<= 1) {
        if (mask & mask_bit) {
            if (src & src_bit) {
                result |= mask_bit;
            }
            src_bit <<= 1;
        }
    }
    return result;
}

canonical_original_code:
unsigned int naive(unsigned int src, unsigned int mask) {
    unsigned int result = 0;
    unsigned int mask_bit = 1;
    unsigned int src_bit = 1;
    int i;
    for (i=0; i < 32; i++, mask_bit <<= 1) {
        if (mask & mask_bit) {
            if (src & src_bit) {
                result |= mask_bit;
            }
            src_bit <<= 1;
        }
    }
    return result;
}

variable_types:
src
unsigned int

variable_types:
result
unsigned int

variable_types: i int


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
convert_to_bin::prepare_lookup(*(convert_to_bin **)&argc);
verify();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
convert_to_bin::func9(*(convert_to_bin **)&argc);
func15();
return 0;
}


bswap

decompiled_code:
__int64 __fastcall bswap(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
return _byteswap_ulong(a1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("preconditions...");
verify_correctness();
puts("nibble expand...");
verify_expand();
puts("conversion to hex...");
verify_conv_to_hex();
puts("all ok!");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("preconditions...");
func18();
puts("nibble expand...");
func20();
puts("conversion to hex...");
func19();
puts("all ok!");
return 0;
}

original_code:
int main() {
    verify();
}


strtonum

repo: WrathOfChris/event

decompiled_code:
__int64 __fastcall strtonum(char *nptr, __int64 a2, __int64 a3, _QWORD *a4)
{
int *v6; // rax
int v7; // er15
int *v8; // rbx
int v9; // edx
__int64 v10; // rax
__int64 v11; // r8
char *endptr[16]; // [rsp+8h] [rbp-80h] BYREF

endptr[3] = "invalid";
endptr[5] = "too small";
endptr[7] = "too large";
v6 = _errno_location();
v7 = *v6;
v8 = v6;
*v6 = 0;
if ( a2 > a3 || (v11 = strtoll(nptr, endptr, 10), endptr[0] == nptr) || *endptr[0] )
{
v9 = 22;
v10 = 1LL;
goto LABEL_3;
}
if ( v11 == 0x8000000000000000LL )
{
v9 = *v8;
if ( *v8 == 34 )
{
LABEL_19:
v10 = 2LL;
goto LABEL_3;
}
if ( a2 == 0x8000000000000000LL )
goto LABEL_12;
LABEL_18:
v9 = 34;
goto LABEL_19;
}
if ( a2 > v11 )
goto LABEL_18;
if ( v11 == 0x7FFFFFFFFFFFFFFFLL )
{
v9 = *v8;
if ( *v8 == 34 )
{
v10 = 3LL;
LABEL_3:
if ( a4 )
{
v11 = 0LL;
*a4 = endptr[2 * v10 + 1];
*v8 = v9;
}
else
{
*v8 = v9;
v11 = 0LL;
}
return v11;
}
}
v9 = 34;
v10 = 3LL;
if ( a3 < v11 )
goto LABEL_3;
LABEL_12:
if ( a4 )
*a4 = 0LL;
*v8 = v7;
return v11;
}

original_code:
long long
strtonum(const char *numstr, long long minval, long long maxval,
    const char **errstrp)
{
 long long ll = 0;
 char *ep;
 int error = 0;
 struct errval {
  const char *errstr;
  int err;
 } ev[4] = {
  { ((void *)0), 0 },
  { "invalid", 22 },
  { "too small", 34 },
  { "too large", 34 },
 };
 ev[0].err = (*__errno_location ());
 (*__errno_location ()) = 0;
 if (minval > maxval)
  error = 1;
 else {
  ll = strtoll(numstr, &ep, 10);
  if (numstr == ep || *ep != '\0')
   error = 1;
  else if ((ll == (-0x7fffffffffffffffLL - 1LL) && (*__errno_location ()) == 34) || ll < minval)
   error = 2;
  else if ((ll == 0x7fffffffffffffffLL && (*__errno_location ()) == 34) || ll > maxval)
   error = 3;
 }
 if (errstrp != ((void *)0))
  *errstrp = ev[error].errstr;
 (*__errno_location ()) = ev[error].err;
 if (error)
  ll = 0;
 return (ll);
}

canonical_original_code:
long long strtonum(char *numstr, long long minval, long long maxval, char **errstrp)
{
 long long ll = 0;
 char *ep;
 int error = 0;
 struct errval ev[4] = {
  { ((void *)0), 0 },
  { "invalid", 22 },
  { "too small", 34 },
  { "too large", 34 },
 };
 ev[0].err = (*__errno_location ());
 (*__errno_location ()) = 0;
 if (minval > maxval)
  error = 1;
 else {
  ll = strtoll(numstr, &ep, 10);
  if (numstr == ep || *ep != '\0')
   error = 1;
  else if ((ll == (-0x7fffffffffffffffLL - 1LL) && (*__errno_location ()) == 34) || ll < minval)
   error = 2;
  else if ((ll == 0x7fffffffffffffffLL && (*__errno_location ()) == 34) || ll > maxval)
   error = 3;
 }
 if (errstrp != ((void *)0))
  *errstrp = ev[error].errstr;
 (*__errno_location ()) = ev[error].err;
 if (error)
  ll = 0;
 return (ll);
}

variable_types:
numstr
char *

variable_types:
minval
long long

variable_types:
maxval
long long

variable_types:
errstrp
char **

variable_types:
ll
long long

variable_types:
ep
char *

variable_types: error int

variable_types: struct errval { char *errstr; int err; } [4]

return_type: long long


repo: XanClic/shiny-c

decompiled_code:
__int64 __fastcall refl_assign(__m128i *a1, __m128i *a2)
{
__int64 v4; // rax
__int64 v5; // rbp
__int64 result; // rax
__int64 v7; // rax
const char *v8; // rdi
__int64 v9; // r13
const char *v10; // rsi
__int64 v11; // rax
const char *v12; // r13
const char *v13; // r14
const char *v14; // rax

v4 = ((__int64 (*)(void))refl_hash_find)();
v5 = v4;
if ( a1 == a2 )
{
*a2 = _mm_loadu_si128((const __m128i *)(v4 + 24));
}
else if ( (unsigned __int8)refl_is_virtual(a2) )
{
v7 = refl_hash_find(a2);
v8 = *(const char **)(v5 + 56);
v9 = v7;
if ( v8 )
{
v10 = *(const char **)(v7 + 56);
if ( v10 )
{
if ( strcmp(v8, v10) )
{
v11 = refl_get_name(a2);
v12 = *(const char **)(v9 + 56);
v13 = (const char *)v11;
v14 = (const char *)refl_get_name(a1);
fprintf(
stderr,
"Cannot redirect function %#lx (%s %s) to %#lx (%s %s); signatures differ\n",
a1,
*(const char **)(v5 + 56),
v14,
a2,
v12,
v13);
_assert_fail("0", "lib/assign.c", 0x21u, "refl_assign");
}
}
}
*(__m128i *)(*(_QWORD *)(v5 + 40) + 80LL) = _mm_loadu_si128((const __m128i *)(v9 + 24));
establish_trampoline(v5);
}
else
{
*(__m128i *)(*(_QWORD *)(v5 + 40) + 80LL) = _mm_loadu_si128(a2);
establish_trampoline(v5);
}
result = *(_QWORD *)(v5 + 40);
*(_QWORD *)(result + 72) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__m128i *a1, __m128i *a2)
{
__int64 v4; // rax
__int64 v5; // rbp
__int64 result; // rax
__int64 v7; // rax
const char *v8; // rdi
__int64 v9; // r13
const char *v10; // rsi
__int64 v11; // rax
const char *v12; // r13
const char *v13; // r14
const char *v14; // rax

v4 = ((__int64 (*)(void))refl_hash_find)();
v5 = v4;
if ( a1 == a2 )
{
*a2 = _mm_loadu_si128((const __m128i *)(v4 + 24));
}
else if ( (unsigned __int8)refl_is_virtual(a2) )
{
v7 = refl_hash_find(a2);
v8 = *(const char **)(v5 + 56);
v9 = v7;
if ( v8 )
{
v10 = *(const char **)(v7 + 56);
if ( v10 )
{
if ( strcmp(v8, v10) )
{
v11 = refl_get_name(a2);
v12 = *(const char **)(v9 + 56);
v13 = (const char *)v11;
v14 = (const char *)refl_get_name(a1);
fprintf(
stderr,
"Cannot redirect function %#lx (%s %s) to %#lx (%s %s); signatures differ\n",
a1,
*(const char **)(v5 + 56),
v14,
a2,
v12,
v13);
_assert_fail("0", "lib/assign.c", 0x21u, "refl_assign");
}
}
}
*(__m128i *)(*(_QWORD *)(v5 + 40) + 80LL) = _mm_loadu_si128((const __m128i *)(v9 + 24));
func0(v5);
}
else
{
*(__m128i *)(*(_QWORD *)(v5 + 40) + 80LL) = _mm_loadu_si128(a2);
func0(v5);
}
result = *(_QWORD *)(v5 + 40);
*(_QWORD *)(result + 72) = a2;
return result;
}

original_code:
void refl_assign(func_t dest, func_t src)
{
    const struct vf_ht_entry *de = refl_hash_find(dest);
    if (src == dest)
        memcpy((void *)dest, de->prologue, 16);
    else if (refl_is_virtual(src))
    {
        const struct vf_ht_entry *se = refl_hash_find(src);
        if (de->signature && se->signature && strcmp(de->signature, se->signature))
        {
            fprintf(stderr, "Cannot redirect function %#lx (%s %s) to %#lx (%s %s); signatures differ\n", dest, de->signature, refl_get_name(dest), src, se->signature, refl_get_name(src));
            ((0) ? (void) (0) : __assert_fail ("0", "lib/assign.c", 33, __extension__ __PRETTY_FUNCTION__));
        }
        memcpy(de->trampoline->prologue, se->prologue, 16);
        establish_trampoline(de);
    }
    else
    {
        memcpy(de->trampoline->prologue, (void *)src, 16);
        establish_trampoline(de);
    }
    de->trampoline->target = src;
}

canonical_original_code:
void refl_assign(unsigned long dest, unsigned long src)
{
    struct vf_ht_entry *de = refl_hash_find(dest);
    if (src == dest)
        memcpy((void *)dest, de->prologue, 16);
    else if (refl_is_virtual(src))
    {
        struct vf_ht_entry *se = refl_hash_find(src);
        if (de->signature && se->signature && strcmp(de->signature, se->signature))
        {
            fprintf(stderr, "Cannot redirect function %#lx (%s %s) to %#lx (%s %s); signatures differ\n", dest, de->signature, refl_get_name(dest), src, se->signature, refl_get_name(src));
            ((0) ? (void) (0) : __assert_fail ("0", "lib/assign.c", 33, __extension__ __PRETTY_FUNCTION__));
        }
        memcpy(de->trampoline->prologue, se->prologue, 16);
        establish_trampoline(de);
    }
    else
    {
        memcpy(de->trampoline->prologue, (void *)src, 16);
        establish_trampoline(de);
    }
    de->trampoline->target = src;
}

variable_types:
dest
unsigned long

variable_types:
src
unsigned long

variable_types: struct vf_ht_entry { struct vf_ht_entry *next; unsigned long vf; int symtab_idx; unsigned long prologue[2]; struct virt_trampoline { unsigned long code[8]; unsigned long scratch_ret; unsigned long target; unsigned long prologue[2]; unsigned long trampoline[2]; } *trampoline; struct annotation_entry { struct refl_annotation { unsigned long func; enum refl_annotation_type { REFL_ANNOTATION_FUNCSIG_PAR_TYPE=32768, REFL_ANNOTATION_FUNCSIG_RET_TYPE=expr } type; char *data; } annotation; struct annotation_entry *next; } *annotation_list; char *signature; } *

user_defined_types: struct vf_ht_entry { struct vf_ht_entry *next; unsigned long vf; int symtab_idx; unsigned long prologue[2]; struct virt_trampoline *trampoline; struct annotation_entry *annotation_list; char *signature; }

user_defined_types: struct annotation_entry { struct refl_annotation annotation; struct annotation_entry *next; }

user_defined_types: struct refl_annotation { unsigned long func; enum refl_annotation_type type; char *data; }


decompiled_code:
// attributes: thunk
int puts_wrapper(const char *s)
{
return puts(s);
}

canonical_decompiled_code:
int func0(const char *s)
{
return puts(s);
}

original_code:
void puts_wrapper(const char *s)
{
    puts(s);
}

canonical_original_code:
void puts_wrapper(char *s)
{
    puts(s);
}

variable_types:
s
char *


foo

decompiled_code:
int __fastcall foo(unsigned int a1, unsigned int a2)
{
return printf("foo %i %i\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, unsigned int a2)
{
return printf("foo %i %i\n", a1, a2);
}

original_code:
void foo(int x, int y)
{
    printf("foo %i %i\n", x, y);
}

variable_types: x int

variable_types: y int


bar

decompiled_code:
int __fastcall bar(unsigned int a1, unsigned int a2)
{
return printf("bar %x %x\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, unsigned int a2)
{
return printf("bar %x %x\n", a1, a2);
}

original_code:
void bar(int x, int y)
{
    printf("bar %x %x\n", x, y);
}


decompiled_code:
int __fastcall print_target(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rax
const char *v3; // rax

v1 = refl_find();
v2 = refl_get_target(v1);
v3 = (const char *)refl_get_name(v2);
return printf("%s() points to %s()\n", a1, v3);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rax
const char *v3; // rax

v1 = refl_find();
v2 = refl_get_target(v1);
v3 = (const char *)refl_get_name(v2);
return printf("%s() points to %s()\n", a1, v3);
}

original_code:
void print_target(const char *func)
{
    printf("%s() points to %s()\n", func, refl_get_name(refl_get_target(refl_find(func))));
}

canonical_original_code:
void print_target(char *func)
{
    printf("%s() points to %s()\n", func, refl_get_name(refl_get_target(refl_find(func))));
}

variable_types:
func
char *


decompiled_code:
__int64 __fastcall refl_find(char *s2)
{
unsigned int *v1; // rbx
__int64 v2; // r12
__int64 v3; // r13

if ( _symtab_entries <= 0 )
return 0LL;
v1 = (unsigned int *)_symtab;
v2 = _strtab;
v3 = _symtab + 24LL * (unsigned int)(_symtab_entries - 1) + 24;
do
{
if ( !strcmp((const char *)(v2 + *v1), s2) )
return *((_QWORD *)v1 + 1) + _relocation;
v1 += 6;
}
while ( v1 != (unsigned int *)v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
unsigned int *v1; // rbx
__int64 v2; // r12
__int64 v3; // r13

if ( _symtab_entries <= 0 )
return 0LL;
v1 = (unsigned int *)_symtab;
v2 = _strtab;
v3 = _symtab + 24LL * (unsigned int)(_symtab_entries - 1) + 24;
do
{
if ( !strcmp((const char *)(v2 + *v1), s2) )
return *((_QWORD *)v1 + 1) + _relocation;
v1 += 6;
}
while ( v1 != (unsigned int *)v3 );
return 0LL;
}

original_code:
func_t refl_find(const char *name)
{
    for (int i = 0; i < __symtab_entries; i++)
        if (!strcmp(__strtab + __symtab[i].st_name, name))
            return __symtab[i].st_value + __relocation;
    return 0;
}

canonical_original_code:
unsigned long refl_find(char *name)
{
    for (int i = 0; i < __symtab_entries; i++)
        if (!strcmp(__strtab + __symtab[i].st_name, name))
            return __symtab[i].st_value + __relocation;
    return 0;
}

variable_types:
name
char *

return_type: unsigned long


decompiled_code:
__int64 __fastcall hash_vf(unsigned __int64 a1)
{
return (unsigned __int8)(a1 >> 4);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
return (unsigned __int8)(a1 >> 4);
}

original_code:
static unsigned hash_vf(func_t func)
{
    return (func >> 4) & ((1 << 8) - 1);
}

canonical_original_code:
static unsigned int hash_vf(unsigned long func)
{
    return (func >> 4) & ((1 << 8) - 1);
}

variable_types:
func
unsigned long


decompiled_code:
bool __fastcall refl_is_virtual(unsigned __int64 a1)
{
bool result; // al

result = 0;
if ( _vmin <= a1 )
result = _vmax > a1;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(unsigned __int64 a1)
{
bool result; // al

result = 0;
if ( _vmin <= a1 )
result = _vmax > a1;
return result;
}

original_code:
_Bool refl_is_virtual(func_t func)
{
    return (func >= __vmin) && (func < __vmax);
}

canonical_original_code:
_Bool refl_is_virtual(unsigned long func)
{
    return (func >= __vmin) && (func < __vmax);
}