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

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
do
{
v3 = v2;
v4 = a2;
v5 = a2 >> 31;
a2 = v3;
v2 = __SPAIR64__(v5, v4) % v3;
}
while ( v2 );
return (unsigned int)v3;
}

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

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
do
{
v3 = v2;
v4 = a2;
v5 = a2 >> 31;
a2 = v3;
v2 = __SPAIR64__(v5, v4) % v3;
}
while ( v2 );
return (unsigned int)v3;
}

original_code:
int gcd1(int m, int n)
{
    int r = 0;
    r = m % n;
    while(r) {
        m = n;
        n = r;
        r = m % n;
    }
    return n;
}

variable_types: n int

variable_types: r int


repo: dannoy/tools

decompiled_code:
__int64 __fastcall gcd2(int a1, int a2)
{
__int64 result; // rax
unsigned int v4; // ecx

LODWORD(result) = a1;
do
{
v4 = a2;
a2 = (int)result % a2;
result = v4;
}
while ( a2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
__int64 result; // rax
unsigned int v4; // ecx

LODWORD(result) = a1;
do
{
v4 = a2;
a2 = (int)result % a2;
result = v4;
}
while ( a2 );
return result;
}

original_code:
int gcd2(int m, int n)
{
    int r = 1;
    while(r) {
        r = m % n;
        m = n;
        n = r;
    }
    return m;
}

variable_types: m int

return_type: int


decompiled_code:
__int64 __fastcall gcd3(signed int a1, signed int a2)
{
do
{
a1 %= a2;
if ( !a1 )
return (unsigned int)a2;
a2 %= a1;
}
while ( a2 );
return (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(signed int a1, signed int a2)
{
do
{
a1 %= a2;
if ( !a1 )
return (unsigned int)a2;
a2 %= a1;
}
while ( a2 );
return (unsigned int)a1;
}

original_code:
int gcd3(int m, int n)
{
    while(1) {
        if(0 == (m = m % n)) {
            return n;
        }
        else if(0 == (n = n % m)) {
            return m;
        }
    }
    return 1;
}


decompiled_code:
__int64 __fastcall gcd4(int a1, int a2)
{
__int64 result; // rax
unsigned int v4; // ecx

LODWORD(result) = a1;
do
{
v4 = a2;
a2 = (int)result % a2;
result = v4;
}
while ( a2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
__int64 result; // rax
unsigned int v4; // ecx

LODWORD(result) = a1;
do
{
v4 = a2;
a2 = (int)result % a2;
result = v4;
}
while ( a2 );
return result;
}

original_code:
int gcd4(int m, int n)
{
    if(0 == m % n) {
        return n;
    }
    return gcd4(n, m % n);
}


main

canonical_name: main

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

v3 = gcd1(119LL, 544LL, envp);
printf("gcd1 is %d\n", v3);
v4 = gcd2(119LL, 544LL);
printf("gcd2 is %d\n", v4);
v5 = gcd3(119LL, 544LL);
printf("gcd3 is %d\n", v5);
v6 = gcd4(119LL, 544LL);
printf("gcd4 is %d\n", v6);
return 0;
}

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

v3 = func7(119LL, 544LL, envp);
printf("gcd1 is %d\n", v3);
v4 = func8(119LL, 544LL);
printf("gcd2 is %d\n", v4);
v5 = func9(119LL, 544LL);
printf("gcd3 is %d\n", v5);
v6 = func10(119LL, 544LL);
printf("gcd4 is %d\n", v6);
return 0;
}

original_code:
int main()
{
    int gcd = 0;
    gcd = gcd1(119, 544);
    printf("gcd1 is %d\n", gcd);
    gcd = gcd2(119, 544);
    printf("gcd2 is %d\n", gcd);
    gcd = gcd3(119, 544);
    printf("gcd3 is %d\n", gcd);
    gcd = gcd4(119, 544);
    printf("gcd4 is %d\n", gcd);
    return 0;
}

variable_types: gcd int


decompiled_code:
__int64 __fastcall get_number_partition_count(int a1, signed int a2, __int64 a3)
{
bool v5; // r12
int v6; // er13
__int64 v7; // rsi
__int64 v8; // rdi

v5 = a1 == 1;
v6 = 0;
LABEL_3:
if ( a2 != 1 )
{
while ( !v5 )
{
if ( a1 < a2 )
{
a2 = a1;
goto LABEL_3;
}
if ( a1 == a2 )
{
a2 = a1 - 1;
++v6;
goto LABEL_3;
}
if ( a1 <= a2 )
__assert_fail("0", "partition_number.c", 0x15u, "get_number_partition_count");
v7 = (unsigned int)a2;
v8 = (unsigned int)(a1 - a2--);
v6 += get_number_partition_count(v8, v7, a3);
if ( a2 == 1 )
return (unsigned int)(v6 + 1);
}
}
return (unsigned int)(v6 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, signed int a2, __int64 a3)
{
bool v5; // r12
int v6; // er13
__int64 v7; // rsi
__int64 v8; // rdi

v5 = a1 == 1;
v6 = 0;
LABEL_3:
if ( a2 != 1 )
{
while ( !v5 )
{
if ( a1 < a2 )
{
a2 = a1;
goto LABEL_3;
}
if ( a1 == a2 )
{
a2 = a1 - 1;
++v6;
goto LABEL_3;
}
if ( a1 <= a2 )
__assert_fail("0", "partition_number.c", 0x15u, "get_number_partition_count");
v7 = (unsigned int)a2;
v8 = (unsigned int)(a1 - a2--);
v6 += func7(v8, v7, a3);
if ( a2 == 1 )
return (unsigned int)(v6 + 1);
}
}
return (unsigned int)(v6 + 1);
}

original_code:
int get_number_partition_count(int n, int max)
{
    if(n == 1 || max == 1) {
        return 1;
    }
    else if(n < max) {
        return get_number_partition_count(n, n);
    }
    else if(n == max) {
        return 1 + get_number_partition_count(n, n - 1);
    }
    else if(n > max) {
        return get_number_partition_count(n - max, max) +
                    get_number_partition_count(n, max - 1);
    }
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "partition_number.c", 21, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

variable_types: max int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v4; // eax
__int64 v5; // rsi

for ( i = 1; i != 10; ++i )
{
v4 = get_number_partition_count(i, i, envp);
v5 = i;
printf("%d : %d\n", v5, v4);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
unsigned int v4; // eax
__int64 v5; // rsi

for ( i = 1; i != 10; ++i )
{
v4 = func7(i, i, envp);
v5 = i;
printf("%d : %d\n", v5, v4);
}
return 0;
}

original_code:
int main()
{
    int ret = 0;
    int n = 0;
    for(n = 1; n < 10; ++n) {
        int partition = get_number_partition_count(n, n);
        printf("%d : %d\n", n, partition);
    }
    return ret;
}

variable_types: ret int

variable_types: partition int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
char *v4; // rdi
int v6; // [rsp+Ch] [rbp-9Ch]
char v7[8]; // [rsp+10h] [rbp-98h] BYREF
char s; // [rsp+18h] [rbp-90h] BYREF
char v9; // [rsp+98h] [rbp-10h] BYREF

v3 = &s;
do
{
__isoc99_scanf();
v4 = v3;
v3 += 32;
*((double *)v3 - 5) = (double)v6;
sprintf(v4, "%d", (unsigned int)v6);
}
while ( v3 != &v9 );
if ( (unsigned __int8)game24(v7, 4LL) )
puts("Done");
else
puts("No Answer");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
char *v4; // rdi
int v6; // [rsp+Ch] [rbp-9Ch]
char v7[8]; // [rsp+10h] [rbp-98h] BYREF
char s; // [rsp+18h] [rbp-90h] BYREF
char v9; // [rsp+98h] [rbp-10h] BYREF

v3 = &s;
do
{
__isoc99_scanf();
v4 = v3;
v3 += 32;
*((double *)v3 - 5) = (double)v6;
sprintf(v4, "%d", (unsigned int)v6);
}
while ( v3 != &v9 );
if ( (unsigned __int8)func7(v7, 4LL) )
puts("Done");
else
puts("No Answer");
return 0;
}

original_code:
int main( void )
{
  int i, poke;
  Card card[4];
  for( i = 0; i < 4; i++ ) {
    scanf( "%d", &poke );
    card[i].value = ( double )poke;
    sprintf( card[i].expression, "%d", poke );
  }
  if( game24( card, 4 ) ) {
    printf( "Done\n");
  } else {
    printf( "No Answer\n" );
  }
  return 0;
}

canonical_original_code:
int main()
{
  int i; int poke;
  struct Card card[4];
  for( i = 0; i < 4; i++ ) {
    scanf( "%d", &poke );
    card[i].value = ( double )poke;
    sprintf( card[i].expression, "%d", poke );
  }
  if( game24( card, 4 ) ) {
    printf( "Done\n");
  } else {
    printf( "No Answer\n" );
  }
  return 0;
}

variable_types: i int

variable_types: poke int

variable_types: struct Card { double value; char expression[-1]; } [4]


original_code:
_Bool game24( Card *card, int size )
{
  Card stack[ size - 1 ];
  if( size == 1 ) {
    if( fabs( card[0].value - 24 ) < 1E-6 ) {
      printf( "%d = %s\n", 24, card[0].expression );
      return 1;
    } else {
      return 0;
    }
  }
  int m, n, i, t;
  for( m = 0; m < size - 1; m++ ) {
    for( n = m + 1; n < size; n++ ) {
      t = 0;
      for( i = 0; i < size; i++ ) {
 if( i != m && i != n ) {
   stack[t].value = card[i].value;
   sprintf( stack[t].expression, "%s", card[i].expression );
   t++;
 }
      }
      stack[size - 2].value = card[m].value + card[n].value;
      sprintf( stack[size - 2].expression, "(%s + %s)", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value > card[n].value ) {
 stack[size - 2].value = card[m].value - card[n].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[m].expression, card[n].expression );
      } else {
 stack[size - 2].value = card[n].value - card[m].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[n].expression, card[m].expression );
      }
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      stack[size - 2].value = card[m].value * card[n].value;
      sprintf( stack[size - 2].expression, "%s * %s", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value != 0 ) {
 stack[size - 2].value = card[n].value / card[m].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[n].expression, card[m].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
      if( card[n].value != 0 ) {
 stack[size - 2].value = card[m].value / card[n].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[m].expression, card[n].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
    }
  }
  return 0;
}

canonical_original_code:
_Bool game24(struct Card *card, int size)
{
  struct Card stack[-1];
  if( size == 1 ) {
    if( fabs( card[0].value - 24 ) < 1E-6 ) {
      printf( "%d = %s\n", 24, card[0].expression );
      return 1;
    } else {
      return 0;
    }
  }
  int m; int n; int i; int t;
  for( m = 0; m < size - 1; m++ ) {
    for( n = m + 1; n < size; n++ ) {
      t = 0;
      for( i = 0; i < size; i++ ) {
 if( i != m && i != n ) {
   stack[t].value = card[i].value;
   sprintf( stack[t].expression, "%s", card[i].expression );
   t++;
 }
      }
      stack[size - 2].value = card[m].value + card[n].value;
      sprintf( stack[size - 2].expression, "(%s + %s)", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value > card[n].value ) {
 stack[size - 2].value = card[m].value - card[n].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[m].expression, card[n].expression );
      } else {
 stack[size - 2].value = card[n].value - card[m].value;
 sprintf( stack[size - 2].expression, "(%s - %s)", card[n].expression, card[m].expression );
      }
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      stack[size - 2].value = card[m].value * card[n].value;
      sprintf( stack[size - 2].expression, "%s * %s", card[m].expression, card[n].expression );
      if( game24( stack, size - 1 ) ) {
 return 1;
      }
      if( card[m].value != 0 ) {
 stack[size - 2].value = card[n].value / card[m].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[n].expression, card[m].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
      if( card[n].value != 0 ) {
 stack[size - 2].value = card[m].value / card[n].value;
 sprintf( stack[size - 2].expression, "%s / %s", card[m].expression, card[n].expression );
 if( game24( stack, size - 1 ) ) {
   return 1;
 }
      }
    }
  }
  return 0;
}

variable_types: struct Card { double value; char expression[-1]; } *

variable_types: size int

variable_types: struct Card { double value; char expression[-1]; } [-1]

variable_types: t int


repo: dantin/sudoku

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
read(argc, argv, envp);
puts("Result(s):");
sudoku();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func12(argc, argv, envp);
puts("Result(s):");
func11();
return 0;
}

original_code:
int main( void )
{
  read();
  printf( "Result(s):\n" );
  sudoku();
  return 0;
}

canonical_original_code:
int main()
{
  read();
  printf( "Result(s):\n" );
  sudoku();
  return 0;
}


find

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

for ( result = 0LL; result != 81; ++result )
{
if ( !matrix[result] )
return (unsigned int)result;
}
return 0xFFFFFFFFLL;
}

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

for ( result = 0LL; result != 81; ++result )
{
if ( !matrix[result] )
return (unsigned int)result;
}
return 0xFFFFFFFFLL;
}

original_code:
static int find( void )
{
  int i;
  for( i = 0; i < 9 * 9; i++ ) {
    if( matrix[i] == 0 ) {
      return i;
    }
  }
  return -1;
}

canonical_original_code:
static int find()
{
  int i;
  for( i = 0; i < 9 * 9; i++ ) {
    if( matrix[i] == 0 ) {
      return i;
    }
  }
  return -1;
}


set

original_code:
static _Bool set( const int loc, const int num )
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  _Bool valid = matrix[loc] == 0
    && ( cols[c] & ( 1 << num ) ) == 0
    && ( rows[r] & ( 1 << num ) ) == 0
    && ( grids[g] & ( 1 << num ) ) == 0;
  if( !valid ) {
    return 0;
  }
  matrix[loc] = num;
  cols[c] |= ( 1 << num );
  rows[r] |= ( 1 << num );
  grids[g] |= ( 1 << num );
  return 1;
}

canonical_original_code:
static _Bool set(int loc, int num)
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  _Bool valid = matrix[loc] == 0
    && ( cols[c] & ( 1 << num ) ) == 0
    && ( rows[r] & ( 1 << num ) ) == 0
    && ( grids[g] & ( 1 << num ) ) == 0;
  if( !valid ) {
    return 0;
  }
  matrix[loc] = num;
  cols[c] |= ( 1 << num );
  rows[r] |= ( 1 << num );
  grids[g] |= ( 1 << num );
  return 1;
}

variable_types: loc int

variable_types: num int

variable_types: c int

variable_types: g int


unset

original_code:
static void unset( const int loc )
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  int num = matrix[loc];
  matrix[loc] = 0;
  cols[c] ^= ( 1 << num );
  rows[r] ^= ( 1 << num );
  grids[g] ^= ( 1 << num );
}

canonical_original_code:
static void unset(int loc)
{
  int r = loc / 9;
  int c = loc % 9;
  int g = ( r / 3 ) * 3 + c / 3;
  int num = matrix[loc];
  matrix[loc] = 0;
  cols[c] ^= ( 1 << num );
  rows[r] ^= ( 1 << num );
  grids[g] ^= ( 1 << num );
}

variable_types: r int

return_type: void


sudoku

decompiled_code:
int sudoku()
{
unsigned int v0; // ebx
int v1; // ebp
int result; // eax

v0 = 1;
v1 = find();
if ( v1 < 0 )
return print();
do
{
while ( 1 )
{
result = set(v1, v0);
if ( (_BYTE)result )
break;
if ( ++v0 == 10 )
return result;
}
sudoku();
++v0;
result = unset(v1);
}
while ( v0 != 10 );
return result;
}

canonical_decompiled_code:
int func11()
{
unsigned int v0; // ebx
int v1; // ebp
int result; // eax

v0 = 1;
v1 = func7();
if ( v1 < 0 )
return func10();
do
{
while ( 1 )
{
result = func8(v1, v0);
if ( (_BYTE)result )
break;
if ( ++v0 == 10 )
return result;
}
func11();
++v0;
result = func9(v1);
}
while ( v0 != 10 );
return result;
}

original_code:
void sudoku( void )
{
  int loc = find();
  if( loc < 0 ) {
    print();
    return;
  }
  int n;
  for( n = 1; n < 10; n++ ) {
    if( set( loc, n ) ) {
      sudoku();
      unset( loc );
    }
  }
}

canonical_original_code:
void sudoku()
{
  int loc = find();
  if( loc < 0 ) {
    print();
    return;
  }
  int n;
  for( n = 1; n < 10; n++ ) {
    if( set( loc, n ) ) {
      sudoku();
      unset( loc );
    }
  }
}

variable_types: n int


read

decompiled_code:
int read()
{
int v0; // ebx
int v1; // eax
int v2; // edi
int v4; // eax

v0 = 0;
while ( 1 )
{
v1 = getchar();
if ( v1 == -1 )
break;
if ( v1 == 35 )
{
do
v4 = getchar();
while ( v4 > 0 && v4 != 10 && v4 != 13 );
goto LABEL_3;
}
if ( (unsigned int)(v1 - 49) > 8 )
{
v0 += ((v1 - 46) & 0xFFFFFFFD) == 0;
LABEL_3:
if ( v0 == 81 )
break;
}
else
{
v2 = v0++;
set(v2, v1 - 48);
if ( v0 == 81 )
break;
}
}
puts("Sudoku Game:");
return print();
}

canonical_decompiled_code:
int func12()
{
int v0; // ebx
int v1; // eax
int v2; // edi
int v4; // eax

v0 = 0;
while ( 1 )
{
v1 = getchar();
if ( v1 == -1 )
break;
if ( v1 == 35 )
{
do
v4 = getchar();
while ( v4 > 0 && v4 != 10 && v4 != 13 );
goto LABEL_3;
}
if ( (unsigned int)(v1 - 49) > 8 )
{
v0 += ((v1 - 46) & 0xFFFFFFFD) == 0;
LABEL_3:
if ( v0 == 81 )
break;
}
else
{
v2 = v0++;
func8(v2, v1 - 48);
if ( v0 == 81 )
break;
}
}
puts("Sudoku Game:");
return func10();
}


decompiled_code:
__int64 __fastcall iterate_section_4(__int64 *a1, __int64 a2, double a3, double a4)
{
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9

if ( n_5 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v5, v6, v7, v8, a3, a4);
FDTD_2D_iterate_Ey(a1);
}
else
{
copy_simulation_up_to(a1, (_QWORD *)(2 * a1[7]), a3, a4);
}
return ++n_5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2, double a3, double a4)
{
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9

if ( n_5 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v5, v6, v7, v8, a3, a4);
FDTD_2D_iterate_Ey(a1);
}
else
{
func4(a1, (_QWORD *)(2 * a1[7]), a3, a4);
}
return ++n_5;
}

original_code:
long iterate_section_4(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_4(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
    }
    ++n;
    return n;
}

variable_types: struct fdtd_2d_t { long I; long J; double *Hz; double *Ex; double *Ey; double gamma_x; double gamma_y; long N_P; } *

variable_types: I long

variable_types: J long

variable_types:
Ex
double *

variable_types:
Ey
double *

variable_types:
Hz
double *

variable_types: n long

variable_types: i long

variable_types: j long

return_type: long


decompiled_code:
__int64 __fastcall iterate_section_7(__int64 *a1, __int64 a2, double a3, double a4)
{
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9

if ( n_2 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v5, v6, v7, v8, a3, a4);
FDTD_2D_iterate_Ey_mur(a1);
}
else
{
copy_simulation_up_to(a1, (_QWORD *)(2 * a1[7]), a3, a4);
}
return ++n_2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 a2, double a3, double a4)
{
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9

if ( n_2 )
{
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v5, v6, v7, v8, a3, a4);
FDTD_2D_iterate_Ey_mur(a1);
}
else
{
func4(a1, (_QWORD *)(2 * a1[7]), a3, a4);
}
return ++n_2;
}

original_code:
long iterate_section_7(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_7(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
    }
    ++n;
    return n;
}

user_defined_types: struct fdtd_2d_t { long I; long J; double *Hz; double *Ex; double *Ey; double gamma_x; double gamma_y; long N_P; }


decompiled_code:
__int64 __fastcall iterate_section_5(__int64 a1, __int64 a2, double a3, double a4)
{
__int64 v4; // rbx
double v6; // xmm1_8
__int64 v7; // r13
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
double v12; // xmm0_8

v4 = *(_QWORD *)(a1 + 56);
if ( n_4 )
{
v6 = *(double *)(a1 + 40);
v7 = *(_QWORD *)(a1 + 8);
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v8, v9, v10, v11, a3, v6);
FDTD_2D_iterate_Ey(a1);
v12 = round((double)(6 * (int)v4) * v6);
place_PEC_obstacle((__int64 *)a1, (unsigned int)(int)v12, v7 / 2, v7 / 2);
}
else
{
copy_simulation_up_to((__int64 *)a1, (_QWORD *)(2 * v4), a3, a4);
}
return ++n_4;
}

original_code:
long iterate_section_5(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_5(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

variable_types: S long


decompiled_code:
__int64 __fastcall iterate_section_8(__int64 a1, __int64 a2, double a3, double a4)
{
__int64 v4; // rbx
double v6; // xmm1_8
__int64 v7; // r13
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
double v12; // xmm0_8

v4 = *(_QWORD *)(a1 + 56);
if ( n_1 )
{
v6 = *(double *)(a1 + 40);
v7 = *(_QWORD *)(a1 + 8);
FDTD_2D_iterate_Hz(a1);
FDTD_2D_iterate_Ex(a1, a2, v8, v9, v10, v11, a3, v6);
FDTD_2D_iterate_Ey_mur(a1);
v12 = round((double)(6 * (int)v4) * v6);
place_PEC_obstacle((__int64 *)a1, (unsigned int)(int)v12, v7 / 2, v7 / 2);
}
else
{
copy_simulation_up_to((__int64 *)a1, (_QWORD *)(2 * v4), a3, a4);
}
return ++n_1;
}

original_code:
long iterate_section_8(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_8(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz(fdtd);
        FDTD_2D_iterate_Ex(fdtd);
        FDTD_2D_iterate_Ey_mur(fdtd);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}


decompiled_code:
__int64 __fastcall iterate_section_9(__int64 a1, double a2, double a3)
{
__int64 v3; // rbx
__int64 v5; // r13
double v6; // xmm0_8
double v7; // [rsp+8h] [rbp-30h]

v3 = *(_QWORD *)(a1 + 56);
if ( n_0 )
{
v5 = *(_QWORD *)(a1 + 8);
v7 = *(double *)(a1 + 40);
FDTD_2D_iterate_Hz_PML(a1, 20LL, 1.0);
FDTD_2D_iterate_Ex_PML(a1, 20LL, 1.0);
FDTD_2D_iterate_Ey_PML(a1, 20LL, 1.0);
v6 = round((double)(6 * (int)v3) * v7);
place_PEC_obstacle((__int64 *)a1, (unsigned int)(int)v6, v5 / 2, v5 / 2);
}
else
{
copy_simulation_up_to((__int64 *)a1, (_QWORD *)(2 * v3), a2, a3);
}
return ++n_0;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, double a2, double a3)
{
__int64 v3; // rbx
__int64 v5; // r13
double v6; // xmm0_8
double v7; // [rsp+8h] [rbp-30h]

v3 = *(_QWORD *)(a1 + 56);
if ( n_0 )
{
v5 = *(_QWORD *)(a1 + 8);
v7 = *(double *)(a1 + 40);
FDTD_2D_iterate_Hz_PML(a1, 20LL, 1.0);
FDTD_2D_iterate_Ex_PML(a1, 20LL, 1.0);
FDTD_2D_iterate_Ey_PML(a1, 20LL, 1.0);
v6 = round((double)(6 * (int)v3) * v7);
place_PEC_obstacle((__int64 *)a1, (unsigned int)(int)v6, v5 / 2, v5 / 2);
}
else
{
func4((__int64 *)a1, (_QWORD *)(2 * v3), a2, a3);
}
return ++n_0;
}

original_code:
long iterate_section_9(fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0, j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ex_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ey_PML(fdtd, 20, 1);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}

canonical_original_code:
long iterate_section_9(struct fdtd_2d_t *fdtd)
{
    long I = (fdtd)->I; long J = (fdtd)->J; long N_P = (fdtd)->N_P; double *Ex = (fdtd)->Ex; double *Ey = (fdtd)->Ey; double *Hz = (fdtd)->Hz; double alpha_Hz_Ey = (fdtd)->gamma_x / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Hz_Ex = (fdtd)->gamma_y / ((299792458.0f) * (3.14159265358979323846*4e-7)); double alpha_Ex = (fdtd)->gamma_y / ((299792458.0f) * (8.8542e-12)); double alpha_Ey = (fdtd)->gamma_x / ((299792458.0f) * (8.8542e-12));
    static long n = 0;
    long i = 0; long j = 0;
    long S = (long)round(6 * N_P * fdtd->gamma_x);
    if (0 == n) {
        copy_simulation_up_to(fdtd, 2*N_P);
    } else {
        FDTD_2D_iterate_Hz_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ex_PML(fdtd, 20, 1);
        FDTD_2D_iterate_Ey_PML(fdtd, 20, 1);
        place_PEC_obstacle(fdtd, S, J/2, J/2);
    }
    ++n;
    return n;
}


clamp

decompiled_code:
__int64 __fastcall clamp(__int64 a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 > 0 )
{
result = 0xFFFFFFFFLL;
if ( a1 <= 254 )
result = (unsigned int)a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 > 0 )
{
result = 0xFFFFFFFFLL;
if ( a1 <= 254 )
result = (unsigned int)a1;
}
return result;
}

original_code:
unsigned char clamp(long c)
{
    if (c <= 0) return 0;
    if (c >= 255) return 255;
    return c;
}

variable_types: c long

return_type: unsigned char


decompiled_code:
double __fastcall fdtd_excitation2(unsigned __int64 a1)
{
double result; // xmm0_8

result = *(double *)&LC3;
if ( a1 > 6 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func1(unsigned __int64 a1)
{
double result; // xmm0_8

result = *(double *)&LC3;
if ( a1 > 6 )
result = 0.0;
return result;
}

original_code:
double fdtd_excitation2(long n, long N_P)
{
    if ((n >=0) && (n <= 6)) {
        return 1.0f;
    } else {
        return 0;
    }
}

return_type: double


decompiled_code:
__int64 __fastcall get_next_time(char *a1)
{
char *v1; // rbx
char v2; // bp
__int64 v3; // r8
char *v4; // rax
char v5; // dl
__int64 result; // rax

v1 = c_0;
if ( first_time_1 == 1 )
{
c_0 = a1;
v1 = a1;
first_time_1 = 0;
}
v2 = *v1;
if ( !*v1 )
return -1LL;
v3 = atol(v1);
if ( v2 != 44 )
{
v4 = v1 + 1;
do
{
v5 = *v4;
v1 = v4++;
}
while ( v5 != 44 && v5 );
c_0 = v1;
if ( !v5 )
return v3;
}
result = v3;
c_0 = v1 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char *v1; // rbx
char v2; // bp
__int64 v3; // r8
char *v4; // rax
char v5; // dl
__int64 result; // rax

v1 = c_0;
if ( first_time_1 == 1 )
{
c_0 = a1;
v1 = a1;
first_time_1 = 0;
}
v2 = *v1;
if ( !*v1 )
return -1LL;
v3 = atol(v1);
if ( v2 != 44 )
{
v4 = v1 + 1;
do
{
v5 = *v4;
v1 = v4++;
}
while ( v5 != 44 && v5 );
c_0 = v1;
if ( !v5 )
return v3;
}
result = v3;
c_0 = v1 + 1;
return result;
}

original_code:
long get_next_time(char *snapshot_times)
{
    static short first_time = 1;
    static char *c = ((void *)0);
    long n = 0;
    if (1 == first_time) {
        c = snapshot_times;
        first_time = 0;
    }
    if ('\0' == *c) {
        return -1;
    } else {
        n = atol(c);
        while ((',' != *c) && ('\0' != *c)) ++c;
        if ('\0' != *c) ++c;
        return n;
    }
}

variable_types:
c
char *


usage

decompiled_code:
size_t usage()
{
return fwrite("USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n", 1uLL, 0x43uLL, stderr);
}

canonical_decompiled_code:
size_t func3()
{
return fwrite("USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n", 1uLL, 0x43uLL, stderr);
}

original_code:
void usage(void)
{
    fprintf(stderr, "USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n");
}

canonical_original_code:
void usage()
{
    fprintf(stderr, "USAGE: main [gamma] [[-v [duration] | -p [list of snapshot times]]\n");
}


repo: daogangtang/lgstring

decompiled_code:
__int64 __fastcall has_key(char *s1, _DWORD *a2)
{
__int64 v2; // rbx

v2 = 0LL;
while ( strcmp(s1, &tagset[6 * v2]) )
{
if ( ++v2 == 8 )
return 0LL;
}
*a2 = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *s1, _DWORD *a2)
{
__int64 v2; // rbx

v2 = 0LL;
while ( strcmp(s1, &tagset[6 * v2]) )
{
if ( ++v2 == 8 )
return 0LL;
}
*a2 = v2;
return 1LL;
}

original_code:
static int has_key (const char *str, int *which) {
 int i;
 for (i=0; i<8; i++) {
  if (!strcmp(str, tagset[i][0])) {
   *which = i;
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
static int has_key(char *str, int *which) {
 int i;
 for (i=0; i<8; i++) {
  if (!strcmp(str, tagset[i][0])) {
   *which = i;
   return 1;
  }
 }
 return 0;
}

variable_types:
str
char *

variable_types:
which
int *

variable_types: i int


decompiled_code:
__int64 __fastcall get_next_char(__int64 a1, int *a2, _BYTE *a3)
{
unsigned int v3; // er8
int v4; // eax

if ( !a1 )
{
puts("Error, the string is missing.");
exit(1);
}
v3 = 0;
if ( *(_BYTE *)(a1 + *a2) )
{
v4 = *a2 + 1;
v3 = 1;
*a2 = v4;
*a3 = *(_BYTE *)(a1 + v4);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int *a2, _BYTE *a3)
{
unsigned int v3; // er8
int v4; // eax

if ( !a1 )
{
puts("Error, the string is missing.");
exit(1);
}
v3 = 0;
if ( *(_BYTE *)(a1 + *a2) )
{
v4 = *a2 + 1;
v3 = 1;
*a2 = v4;
*a3 = *(_BYTE *)(a1 + v4);
}
return v3;
}

original_code:
static int get_next_char (const char* str, int* ip, char* ncp) {
 if (!str) {
  printf("Error, the string is missing.\n");
  exit(1);
 }
 if (str[*ip] != '\0') {
  *ip += 1;
  *ncp = str[*ip];
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
static int get_next_char(char *str, int *ip, char *ncp) {
 if (!str) {
  printf("Error, the string is missing.\n");
  exit(1);
 }
 if (str[*ip] != '\0') {
  *ip += 1;
  *ncp = str[*ip];
  return 1;
 }
 else
  return 0;
}

variable_types:
ip
int *

variable_types:
ncp
char *


repo: darconeous/bf-tools

decompiled_code:
int ask_newline()
{
__int64 v0; // rax

v0 = newline_count + 1;
newline_count = v0;
if ( v0 == 80 )
{
LODWORD(v0) = fputc(10, _bss_start);
newline_count = 0LL;
}
return v0;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rax

v0 = newline_count + 1;
newline_count = v0;
if ( v0 == 80 )
{
LODWORD(v0) = fputc(10, _bss_start);
newline_count = 0LL;
}
return v0;
}

original_code:
void ask_newline()
{
 if (++newline_count == 80) {
  fputc('\n', stdout);
  newline_count = 0;
 }
}


decompiled_code:
int __fastcall print_n_times_x(__int64 a1, int a2)
{
__int64 v2; // rbx
int result; // eax
__int64 v4; // rbx

v2 = a1;
if ( a1 < 0 )
{
v4 = -a1;
do
{
fputc(a2 - 1, _bss_start);
result = ask_newline();
--v4;
}
while ( v4 );
}
else if ( a1 )
{
do
{
fputc(a2 + 1, _bss_start);
result = ask_newline();
--v2;
}
while ( v2 );
}
return result;
}

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

v2 = a1;
if ( a1 < 0 )
{
v4 = -a1;
do
{
fputc(a2 - 1, _bss_start);
result = func7();
--v4;
}
while ( v4 );
}
else if ( a1 )
{
do
{
fputc(a2 + 1, _bss_start);
result = func7();
--v2;
}
while ( v2 );
}
return result;
}

original_code:
void print_n_times_x(long n, int x)
{
 long i;
 if (n < 0) {
  for (i = -n; i > 0; i--) {
   fputc(x - 1, stdout);
   ask_newline();
  }
 }
 if (n > 0) {
  for (i = n; i > 0; i--) {
   fputc(x + 1, stdout);
   ask_newline();
  }
 }
}

variable_types: x int


Hashkey

repo: darkac/deRedundance

decompiled_code:
unsigned __int64 __fastcall Hashkey(char *a1)
{
char *v1; // rsi
unsigned __int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rcx
__int64 v5; // rax
bool v6; // zf
__int64 v7; // rax

v1 = a1 + 64;
v2 = 0LL;
do
{
v3 = *a1++;
v4 = v3 + 16 * v2;
v5 = (unsigned int)v4 & 0xF0000000;
v6 = v5 == 0;
v7 = ~v5;
if ( !v6 )
v4 ^= (unsigned __int64)((unsigned int)v4 & 0xF0000000) >> 24;
v2 = v7 & v4;
}
while ( v1 != a1 );
return v2 % 0xE4E1C0;
}

original_code:
inline int Hashkey(const char *str)
{
 uint64_t h = 0, g;
 const char *end = str + 64;
 while (str < end)
 {
  h = (h << 4) + *str++;
  if ((g = h & 0xf0000000))
   h ^= g >> 24;
  h &= ~g;
 }
 return (uint32_t)(h % 15000000);
}

canonical_original_code:
inline int Hashkey(char *str)
{
 unsigned long h = 0; unsigned long g;
 char *end = str + 64;
 while (str < end)
 {
  h = (h << 4) + *str++;
  if ((g = h & 0xf0000000))
   h ^= g >> 24;
  h &= ~g;
 }
 return (unsigned int)(h % 15000000);
}

variable_types:
h
unsigned long

variable_types:
g
unsigned long

variable_types:
end
char *


decompiled_code:
__int64 HT_Init()
{
__int64 *v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = &hashTable;
do
{
++v0;
v1 = malloc(0x10uLL);
*(v0 - 1) = (__int64)v1;
result = CheckAndSetPointer(v1, 0LL, 16LL);
}
while ( v0 != (__int64 *)((char *)&unk_7270E00 + (_QWORD)&hashTable) );
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 *v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = &hashTable;
do
{
++v0;
v1 = malloc(0x10uLL);
*(v0 - 1) = (__int64)v1;
result = func12(v1, 0LL, 16LL);
}
while ( v0 != (__int64 *)((char *)&unk_7270E00 + (_QWORD)&hashTable) );
return result;
}

original_code:
void HT_Init()
{
 uint32_t i;
 for (i = 0; i < 15000000; ++i)
 {
  hashTable[i] = (hashnode_t *)malloc(sizeof(hashnode_t));
  CheckAndSetPointer(hashTable[i], 0, sizeof(hashnode_t));
 }
}

canonical_original_code:
void HT_Init()
{
 unsigned int i;
 for (i = 0; i < 15000000; ++i)
 {
  hashTable[i] = (struct hashnode *)malloc(sizeof(hashnode_t));
  CheckAndSetPointer(hashTable[i], 0, sizeof(hashnode_t));
 }
}

variable_types:
i
unsigned int

user_defined_types: struct hashnode { unsigned long m_start; struct hashnode *m_next; }


decompiled_code:
__int64 HT_Free()
{
__int64 *v0; // rbp
__int64 v1; // rdi
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v0 = &hashTable;
do
{
v1 = *v0;
v2 = *(_QWORD *)(*v0 + 8);
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
FreePointer(v3);
}
while ( v2 );
v1 = *v0;
}
result = FreePointer(v1);
++v0;
}
while ( v0 != (__int64 *)((char *)&unk_7270E00 + (_QWORD)&hashTable) );
return result;
}

original_code:
void HT_Free()
{
 uint32_t i;
 for (i = 0; i < 15000000; ++i)
 {
  hashnode_t *temp = hashTable[i]->m_next;
  hashnode_t *todel;
  while (temp != ((void *)0))
  {
   todel = temp;
   temp = temp->m_next;
   FreePointer(todel);
  }
  FreePointer(hashTable[i]);
 }
}

canonical_original_code:
void HT_Free()
{
 unsigned int i;
 for (i = 0; i < 15000000; ++i)
 {
  struct hashnode *temp = hashTable[i]->m_next;
  struct hashnode *todel;
  while (temp != ((void *)0))
  {
   todel = temp;
   temp = temp->m_next;
   FreePointer(todel);
  }
  FreePointer(hashTable[i]);
 }
}

variable_types: struct hashnode { unsigned long m_start; struct hashnode *m_next; } *


decompiled_code:
__int64 __fastcall HT_Insert(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // rbx
__int64 result; // rax

v2 = (int)Hashkey((char *)(a2 + a1));
v3 = malloc(0x10uLL);
CheckAndSetPointer(v3, 0LL, 16LL);
result = hashTable[v2];
*v3 = a2;
v3[1] = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // rbx
__int64 result; // rax

v2 = (int)func7((char *)(a2 + a1));
v3 = malloc(0x10uLL);
func12(v3, 0LL, 16LL);
result = hashTable[v2];
*v3 = a2;
v3[1] = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v3;
return result;
}

original_code:
void HT_Insert(const char *str, uint64_t position)
{
 int slot = Hashkey(str + position);
 hashnode_t *hnode = (hashnode_t *)malloc(sizeof(hashnode_t));
 CheckAndSetPointer(hnode, 0, sizeof(hashnode_t));
 hnode->m_start = position;
 hnode->m_next = hashTable[slot]->m_next;
 hashTable[slot]->m_next = hnode;
}

canonical_original_code:
void HT_Insert(char *str, unsigned long position)
{
 int slot = Hashkey(str + position);
 struct hashnode *hnode = (hashnode_t *)malloc(sizeof(hashnode_t));
 CheckAndSetPointer(hnode, 0, sizeof(hashnode_t));
 hnode->m_start = position;
 hnode->m_next = hashTable[slot]->m_next;
 hashTable[slot]->m_next = hnode;
}

variable_types:
position
unsigned long

variable_types: slot int


CheckAndSetPointer

decompiled_code:
void *__fastcall CheckAndSetPointer(void *a1, char a2, size_t a3)
{
if ( !a1 )
{
printf("Null pointer!");
exit(-1);
}
return memset(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func12(void *a1, char a2, size_t a3)
{
if ( !a1 )
{
printf("Null pointer!");
exit(-1);
}
return memset(a1, a2, a3);
}

original_code:
void CheckAndSetPointer(void *pointer, char content, size_t size)
{
 if (pointer == ((void *)0))
 {
  printf("Null pointer!");
  exit(-1);
 }
 memset(pointer, content, size);
}

canonical_original_code:
void CheckAndSetPointer(void *pointer, char content, unsigned long size)
{
 if (pointer == ((void *)0))
 {
  printf("Null pointer!");
  exit(-1);
 }
 memset(pointer, content, size);
}

variable_types:
pointer
void *

variable_types: content char

variable_types:
size
unsigned long


FreePointer

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

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

original_code:
void FreePointer(void *pointer)
{
 if (pointer != ((void *)0))
 {
  free(pointer);
  pointer = 0;
 }
}


IsOverlap

decompiled_code:
_BOOL8 __fastcall IsOverlap(int a1, unsigned int a2)
{
return a1 + 63 >= a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(int a1, unsigned int a2)
{
return a1 + 63 >= a2;
}

original_code:
int IsOverlap(uint32_t pf, uint32_t pp)
{
 if (pf + 64 - 1 >= pp)
  return 1;
 else
  return 0;
}

canonical_original_code:
int IsOverlap(unsigned int pf, unsigned int pp)
{
 if (pf + 64 - 1 >= pp)
  return 1;
 else
  return 0;
}

variable_types:
pf
unsigned int

variable_types:
pp
unsigned int


IsValid

decompiled_code:
__int64 __fastcall IsValid(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = a2 + 64;
if ( a2 >= a2 + 64 )
return 1LL;
while ( *(_DWORD *)(a1 + 4LL * a2) != 1 )
{
if ( ++a2 == v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = a2 + 64;
if ( a2 >= a2 + 64 )
return 1LL;
while ( *(_DWORD *)(a1 + 4LL * a2) != 1 )
{
if ( ++a2 == v2 )
return 1LL;
}
return 0LL;
}

original_code:
int IsValid(uint32_t marked[], uint32_t pf)
{
 uint32_t i;
 for (i = pf; i < pf + 64; ++i)
 {
  if (marked[i] == 1)
   return 0;
 }
 return 1;
}

canonical_original_code:
int IsValid(unsigned int marked[], unsigned int pf)
{
 unsigned int i;
 for (i = pf; i < pf + 64; ++i)
 {
  if (marked[i] == 1)
   return 0;
 }
 return 1;
}

variable_types:
marked
unsigned int []


identify

decompiled_code:
unsigned int __fastcall identify(__int64 a1, int a2, __int64 a3)
{
unsigned int v3; // er13
unsigned int v5; // ebx
unsigned int result; // eax
_QWORD *v7; // rax
int v8; // ecx
int v9; // ecx
__int64 v10; // rsi
__int64 v11; // rsi

v3 = a2 - 64;
v5 = 0;
do
{
while ( 1 )
{
v7 = HT_GetNode(a1, v5);
if ( v7 )
{
if ( !(unsigned int)IsValid(a3, *v7) )
{
v11 = v5++;
result = HT_Insert(a1, v11);
goto LABEL_5;
}
result = IsOverlap(v8, v5) ? (unsigned int)mark(a3, v9 + 64, v5 - v9) : (unsigned int)mark(a3, v5, 64);
v5 += 64;
}
else
{
v10 = v5++;
result = HT_Insert(a1, v10);
}
if ( (v5 & 0xFFFFF) == 0 )
break;
LABEL_5:
if ( v5 > v3 )
return result;
}
result = printf("Already processed %d MB (approximately)\n", v5 >> 20);
}
while ( v5 <= v3 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func17(__int64 a1, int a2, __int64 a3)
{
unsigned int v3; // er13
unsigned int v5; // ebx
unsigned int result; // eax
_QWORD *v7; // rax
int v8; // ecx
int v9; // ecx
__int64 v10; // rsi
__int64 v11; // rsi

v3 = a2 - 64;
v5 = 0;
do
{
while ( 1 )
{
v7 = HT_GetNode(a1, v5);
if ( v7 )
{
if ( !(unsigned int)func16(a3, *v7) )
{
v11 = v5++;
result = func10(a1, v11);
goto LABEL_5;
}
result = func15(v8, v5) ? (unsigned int)mark(a3, v9 + 64, v5 - v9) : (unsigned int)mark(a3, v5, 64);
v5 += 64;
}
else
{
v10 = v5++;
result = func10(a1, v10);
}
if ( (v5 & 0xFFFFF) == 0 )
break;
LABEL_5:
if ( v5 > v3 )
return result;
}
result = printf("Already processed %d MB (approximately)\n", v5 >> 20);
}
while ( v5 <= v3 );
return result;
}

original_code:
void identify(const char *file_buf, uint32_t dsize, uint32_t marked[])
{
 uint32_t idx = 0;
 uint32_t range = dsize - 64;
 while (idx <= range)
 {
  hashnode_t *found = HT_GetNode(file_buf, idx);
  if (found == ((void *)0))
  {
   HT_Insert(file_buf, idx);
   idx++;
  }
  else
  {
   uint32_t pf = found->m_start;
   int valid = IsValid(marked, pf);
   if (valid == 0)
   {
    HT_Insert(file_buf, idx);
    idx++;
    continue;
   }
   int overlap = IsOverlap(pf, idx);
   if (overlap == 0)
    mark(marked, idx, 64);
   else
    mark(marked, pf + 64, idx - pf);
   idx += 64;
  }
  if (idx % 1048576 == 0)
   printf("Already processed %d MB (approximately)\n", idx / 1048576);
 }
}

canonical_original_code:
void identify(char *file_buf, unsigned int dsize, unsigned int marked[])
{
 unsigned int idx = 0;
 unsigned int range = dsize - 64;
 while (idx <= range)
 {
  struct hashnode *found = HT_GetNode(file_buf, idx);
  if (found == ((void *)0))
  {
   HT_Insert(file_buf, idx);
   idx++;
  }
  else
  {
   unsigned int pf = found->m_start;
   int valid = IsValid(marked, pf);
   if (valid == 0)
   {
    HT_Insert(file_buf, idx);
    idx++;
    continue;
   }
   int overlap = IsOverlap(pf, idx);
   if (overlap == 0)
    mark(marked, idx, 64);
   else
    mark(marked, pf + 64, idx - pf);
   idx += 64;
  }
  if (idx % 1048576 == 0)
   printf("Already processed %d MB (approximately)\n", idx / 1048576);
 }
}

variable_types:
dsize
unsigned int

variable_types:
idx
unsigned int

variable_types:
range
unsigned int

variable_types: valid int

variable_types: overlap int


main

repo: darkhelmet/ntpstat

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
__int64 v4; // rdx
int v5; // edx
int v6; // eax
int v7; // ebp
int v8; // eax
char v9; // bl
int v10; // er12
char *v11; // rax
char *v12; // rax
const char *v13; // r14
char *v14; // rbx
char *v15; // r14
char *v16; // r15
char *v17; // r14
char *v18; // rax
char *v19; // rax
const char *v20; // rbp
char *v22; // rax
char *v23; // rax
char *v24; // r12
char v25; // al
double v26; // xmm0_8
const char *v27; // rsi
double v28; // [rsp+8h] [rbp-580h]
struct in_addr inp; // [rsp+10h] [rbp-578h] BYREF
char v30[8]; // [rsp+17h] [rbp-571h] BYREF
char v31[11]; // [rsp+1Fh] [rbp-569h] BYREF
char v32[18]; // [rsp+2Bh] [rbp-55Dh] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-548h] BYREF
struct timeval timeout; // [rsp+50h] [rbp-538h] BYREF
__int64 v35[10]; // [rsp+60h] [rbp-528h]
fd_set readfds; // [rsp+B0h] [rbp-4D8h] BYREF
char dest[480]; // [rsp+130h] [rbp-458h] BYREF
__int16 buf[2]; // [rsp+310h] [rbp-278h] BYREF
unsigned __int8 v39; // [rsp+314h] [rbp-274h]
char v40; // [rsp+315h] [rbp-273h]
char src[620]; // [rsp+31Ch] [rbp-26Ch] BYREF

strcpy(v32, "rootdisp=");
strcpy(&v32[10], "rootdelay=");
strcpy(&v31[3], "stratum=");
v35[0] = (__int64)"unspecified";
v35[1] = (__int64)"atomic clock";
v35[2] = (__int64)"VLF radio";
v35[3] = (__int64)"HF radio";
v35[4] = (__int64)&unk_40202B;
v35[5] = (__int64)"local net";
v35[6] = (__int64)"NTP server";
v35[7] = (__int64)"UDP/TIME";
v35[8] = (__int64)"wristwatch";
v35[9] = (__int64)"modem";
strcpy(v30, "tc=");
strcpy(&v30[4], "refid=");
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
inet_aton("127.0.0.1", &inp);
addr.sa_family = 2;
*(struct in_addr *)&addr.sa_data[2] = inp;
*(_WORD *)addr.sa_data = _bswap_16(123LL, 2LL, 0LL, 72LL);
memset(buf, 0, 8 * v3);
buf[0] = 534;
buf[1] = _bswap_16(1LL, 2LL, v4, 0LL);
v6 = socket(2, 2, v5);
if ( v6 < 0 )
die("unable to open socket");
v7 = v6;
if ( connect(v6, &addr, 0x10u) < 0 )
{
perror("On connect");
die("unable to connect to socket");
}
readfds.fds_bits[v7 >> 6] |= 1LL << v7;
if ( send(v7, buf, 0x240uLL, 0) < 0 )
{
perror("On send");
die("unable to send command to NTP port");
}
v8 = select(v7 + 1, &readfds, 0LL, 0LL, &timeout);
if ( !v8 )
die("timeout");
if ( v8 == -1 )
die("error on select");
if ( (int)recv(v7, buf, 0x240uLL, 0) < 0 )
die("Unable to talk to NTP daemon. Is it running?");
if ( (buf[0] & 0x3F) != 22 || (HIBYTE(buf[0]) & 0xDF) != 130 )
{
fprintf(stderr, "status word is 0x%02x%02x\n", LOBYTE(buf[0]), HIBYTE(buf[0]));
die("return data appears to be invalid based on status word");
}
if ( v39 >> 6 != 3 )
{
printf("synchronised to ");
v9 = v39 & 0x3F;
if ( (v39 & 0x3Fu) <= 9 )
{
printf("%s", (const char *)v35[v39 & 0x3F]);
if ( v9 == 6 )
{
strncpy(dest, src, 0x1D4uLL);
v22 = strstr(dest, &v30[4]);
if ( v22 )
{
v23 = strtok(v22 + 6, ",");
v24 = v23;
if ( *v23 && strlen(v23) <= 0x10 )
{
v27 = v24;
v10 = 0;
printf(" (%s)", v27);
}
else
{
v10 = 0;
printf(" <IP unreadable>");
}
}
else
{
v10 = 1;
printf(" <IP unknown>");
}
LABEL_13:
strncpy(dest, src, 0x1D4uLL);
v11 = strstr(dest, &v31[3]);
if ( v11 )
{
v12 = strtok(v11 + 8, ",");
v13 = v12;
if ( *v12 && strlen(v12) <= 2 )
printf(" at stratum %s \n", v13);
else
puts(", stratum unreadable");
}
else
{
v10 = 1;
puts(", stratum unknown");
}
strncpy(dest, src, 0x1D4uLL);
v14 = strstr(dest, v32);
if ( v14 && (v15 = strstr(dest, &v32[10])) != 0LL )
{
v16 = strtok(v14 + 9, ",");
v17 = strtok(v15 + 10, ",");
if ( *v16 && strlen(v16) <= 0xA && *v17 && strlen(v17) <= 0xA )
{
v28 = atof(v16);
v26 = atof(v17);
printf(" time correct to within %.0f ms\n", v26 * 0.5 + v28);
}
else
{
puts("accuracy unreadable");
}
}
else
{
v10 = 1;
puts("accuracy unknown");
}
goto LABEL_23;
}
}
else
{
printf("unknown source");
}
v10 = 0;
goto LABEL_13;
}
puts("unsynchronised");
v10 = 1;
if ( (v40 & 0xF) == 1 )
puts(" time server re-starting");
LABEL_23:
strncpy(dest, src, 0x1D4uLL);
v18 = strstr(dest, v30);
if ( v18 )
{
v19 = strtok(v18 + 3, ",");
v20 = v19;
if ( *v19 && strlen(v19) <= 2 )
{
v25 = atoi(v20);
printf(" polling server every %d s\n", (unsigned int)(1 << v25));
}
else
{
puts("poll interval unreadable");
}
}
else
{
v10 = 1;
puts("poll interval unknown");
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
__int64 v4; // rdx
int v5; // edx
int v6; // eax
int v7; // ebp
int v8; // eax
char v9; // bl
int v10; // er12
char *v11; // rax
char *v12; // rax
const char *v13; // r14
char *v14; // rbx
char *v15; // r14
char *v16; // r15
char *v17; // r14
char *v18; // rax
char *v19; // rax
const char *v20; // rbp
char *v22; // rax
char *v23; // rax
char *v24; // r12
char v25; // al
double v26; // xmm0_8
const char *v27; // rsi
double v28; // [rsp+8h] [rbp-580h]
struct in_addr inp; // [rsp+10h] [rbp-578h] BYREF
char v30[8]; // [rsp+17h] [rbp-571h] BYREF
char v31[11]; // [rsp+1Fh] [rbp-569h] BYREF
char v32[18]; // [rsp+2Bh] [rbp-55Dh] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-548h] BYREF
struct timeval timeout; // [rsp+50h] [rbp-538h] BYREF
__int64 v35[10]; // [rsp+60h] [rbp-528h]
fd_set readfds; // [rsp+B0h] [rbp-4D8h] BYREF
char dest[480]; // [rsp+130h] [rbp-458h] BYREF
__int16 buf[2]; // [rsp+310h] [rbp-278h] BYREF
unsigned __int8 v39; // [rsp+314h] [rbp-274h]
char v40; // [rsp+315h] [rbp-273h]
char src[620]; // [rsp+31Ch] [rbp-26Ch] BYREF

strcpy(v32, "rootdisp=");
strcpy(&v32[10], "rootdelay=");
strcpy(&v31[3], "stratum=");
v35[0] = (__int64)"unspecified";
v35[1] = (__int64)"atomic clock";
v35[2] = (__int64)"VLF radio";
v35[3] = (__int64)"HF radio";
v35[4] = (__int64)&unk_40202B;
v35[5] = (__int64)"local net";
v35[6] = (__int64)"NTP server";
v35[7] = (__int64)"UDP/TIME";
v35[8] = (__int64)"wristwatch";
v35[9] = (__int64)"modem";
strcpy(v30, "tc=");
strcpy(&v30[4], "refid=");
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
inet_aton("127.0.0.1", &inp);
addr.sa_family = 2;
*(struct in_addr *)&addr.sa_data[2] = inp;
*(_WORD *)addr.sa_data = func7(123LL, 2LL, 0LL, 72LL);
memset(buf, 0, 8 * v3);
buf[0] = 534;
buf[1] = func7(1LL, 2LL, v4, 0LL);
v6 = socket(2, 2, v5);
if ( v6 < 0 )
func8("unable to open socket");
v7 = v6;
if ( connect(v6, &addr, 0x10u) < 0 )
{
perror("On connect");
func8("unable to connect to socket");
}
readfds.fds_bits[v7 >> 6] |= 1LL << v7;
if ( send(v7, buf, 0x240uLL, 0) < 0 )
{
perror("On send");
func8("unable to send command to NTP port");
}
v8 = select(v7 + 1, &readfds, 0LL, 0LL, &timeout);
if ( !v8 )
func8("timeout");
if ( v8 == -1 )
func8("error on select");
if ( (int)recv(v7, buf, 0x240uLL, 0) < 0 )
func8("Unable to talk to NTP daemon. Is it running?");
if ( (buf[0] & 0x3F) != 22 || (HIBYTE(buf[0]) & 0xDF) != 130 )
{
fprintf(stderr, "status word is 0x%02x%02x\n", LOBYTE(buf[0]), HIBYTE(buf[0]));
func8("return data appears to be invalid based on status word");
}
if ( v39 >> 6 != 3 )
{
printf("synchronised to ");
v9 = v39 & 0x3F;
if ( (v39 & 0x3Fu) <= 9 )
{
printf("%s", (const char *)v35[v39 & 0x3F]);
if ( v9 == 6 )
{
strncpy(dest, src, 0x1D4uLL);
v22 = strstr(dest, &v30[4]);
if ( v22 )
{
v23 = strtok(v22 + 6, ",");
v24 = v23;
if ( *v23 && strlen(v23) <= 0x10 )
{
v27 = v24;
v10 = 0;
printf(" (%s)", v27);
}
else
{
v10 = 0;
printf(" <IP unreadable>");
}
}
else
{
v10 = 1;
printf(" <IP unknown>");
}
LABEL_13:
strncpy(dest, src, 0x1D4uLL);
v11 = strstr(dest, &v31[3]);
if ( v11 )
{
v12 = strtok(v11 + 8, ",");
v13 = v12;
if ( *v12 && strlen(v12) <= 2 )
printf(" at stratum %s \n", v13);
else
puts(", stratum unreadable");
}
else
{
v10 = 1;
puts(", stratum unknown");
}
strncpy(dest, src, 0x1D4uLL);
v14 = strstr(dest, v32);
if ( v14 && (v15 = strstr(dest, &v32[10])) != 0LL )
{
v16 = strtok(v14 + 9, ",");
v17 = strtok(v15 + 10, ",");
if ( *v16 && strlen(v16) <= 0xA && *v17 && strlen(v17) <= 0xA )
{
v28 = atof(v16);
v26 = atof(v17);
printf(" time correct to within %.0f ms\n", v26 * 0.5 + v28);
}
else
{
puts("accuracy unreadable");
}
}
else
{
v10 = 1;
puts("accuracy unknown");
}
goto LABEL_23;
}
}
else
{
printf("unknown source");
}
v10 = 0;
goto LABEL_13;
}
puts("unsynchronised");
v10 = 1;
if ( (v40 & 0xF) == 1 )
puts(" time server re-starting");
LABEL_23:
strncpy(dest, src, 0x1D4uLL);
v18 = strstr(dest, v30);
if ( v18 )
{
v19 = strtok(v18 + 3, ",");
v20 = v19;
if ( *v19 && strlen(v19) <= 2 )
{
v25 = atoi(v20);
printf(" polling server every %d s\n", (unsigned int)(1 << v25));
}
else
{
puts("poll interval unreadable");
}
}
else
{
v10 = 1;
puts("poll interval unknown");
}
return v10;
}

original_code:
int main (void) {
  int rc;
  struct sockaddr_in sock;
  struct in_addr address;
  int sd;
  fd_set fds;
  struct timeval tv;
  int n;
  unsigned char byte1ok;
  unsigned char byte2ok;
  struct {
    unsigned char byte1;
    unsigned char byte2;
    unsigned short sequence;
    unsigned char status1;
    unsigned char status2;
    unsigned short AssocID;
    unsigned short Offset;
    unsigned short Count;
    char payload[468];
    char authenticator[96];
  } ntpmsg;
  char buff[468];
  unsigned int clksrc;
  char *clksrcname[] = {
    "unspecified",
    "atomic clock",
    "VLF radio",
    "HF radio",
    "UHF radio",
    "local net",
    "NTP server",
    "UDP/TIME",
    "wristwatch",
    "modem"};
  char *newstr;
  char *dispstr;
  char *delaystr;
  const char DISP[] = "rootdisp=";
  const char DELAY[] = "rootdelay=";
  const char STRATUM[] = "stratum=";
  const char POLL[] = "tc=";
  const char REFID[] = "refid=";
  tv.tv_sec = 1;
  tv.tv_usec = 0;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  inet_aton("127.0.0.1", &address);
  sock.sin_family = 2;
  sock.sin_addr = address;
  sock.sin_port = htons(123);
  memset ( &ntpmsg, 0, sizeof(ntpmsg));
  ntpmsg.byte1 = 0x16;
  ntpmsg.byte2 = 2; ntpmsg.sequence=htons(1);
  if ((sd = socket (2, SOCK_DGRAM, 0)) < 0)
    die("unable to open socket");
  if (connect(sd, (struct sockaddr *)&sock, sizeof(sock)) < 0) {
    perror ("On connect");
    die("unable to connect to socket");
  }
  ((void) (((&fds)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
  if (send(sd, &ntpmsg, sizeof(ntpmsg), 0) < 0) {
    perror ("On send");
    die ("unable to send command to NTP port");
  }
  n = select (sd+1, &fds, (fd_set *)0, (fd_set *)0 , &tv);
  if (n == 0)
    die ("timeout");
  if (n == -1)
    die ("error on select");
  if ((n = recv (sd, &ntpmsg, sizeof(ntpmsg), 0)) < 0)
    die ("Unable to talk to NTP daemon. Is it running?");
  byte1ok = ((ntpmsg.byte1&0x3F) == 0x16);
  byte2ok = ((ntpmsg.byte2 & ~0x20) == (2|0x80));
  if (!(byte1ok && byte2ok)) {
    fprintf (stderr,"status word is 0x%02x%02x\n", ntpmsg.byte1,ntpmsg.byte2 );
    die ("return data appears to be invalid based on status word");
  }
  if (!(ntpmsg.byte2 | 0x40)) {
    fprintf (stderr,"status byte2 is %02x\n", ntpmsg.byte2 );
    die ("error bit is set in reply");
  }
  if (!(ntpmsg.byte2 | 0x20)) {
    fprintf (stderr,"status byte2 is %02x\n", ntpmsg.byte2 );
    fprintf (stderr,"More bit unexpected in reply");
  }
  if ((ntpmsg.status1 >> 6) == 3) {
    printf ("unsynchronised\n");
    if ((ntpmsg.status2 & 0x0F) == 1)
      printf ("  time server re-starting\n");
      rc=1;
  }
  else {
    rc=0;
    printf ("synchronised to ");
    clksrc = (ntpmsg.status1 & 0x3F);
    if (clksrc < 10)
      printf("%s", clksrcname[clksrc]);
    else
      printf("unknown source");
    if (clksrc == 6) {
      strncpy(buff, ntpmsg.payload, sizeof(buff));
      if ((newstr = strstr (buff, REFID))) {
 newstr += sizeof(REFID) - 1;
 dispstr = strtok(newstr,",");
 if ((strlen (dispstr) == 0) || (strlen (dispstr) > 16)) {
   printf (" <IP unreadable>");
 }
 else {
   printf(" (%s)",dispstr);
 }
      } else {
 rc=1;
 printf (" <IP unknown>");
      }
    }
    strncpy(buff, ntpmsg.payload, sizeof(buff));
    if ((newstr = strstr (buff, STRATUM))) {
      newstr += sizeof(STRATUM) - 1;
      dispstr = strtok(newstr,",");
      if ((strlen (dispstr) == 0) || (strlen (dispstr) > 2)) {
 printf (", stratum unreadable\n");
      }
      else {
 printf(" at stratum %s \n",dispstr);
      }
    } else {
      rc=1;
      printf (", stratum unknown\n");
    }
    strncpy(buff, ntpmsg.payload, sizeof(buff));
    if ((dispstr = strstr (buff, DISP)) && (delaystr = strstr (buff, DELAY))) {
      dispstr += sizeof(DISP) - 1;
      dispstr = strtok(dispstr,",");
      delaystr += sizeof(DELAY) - 1;
      delaystr = strtok(delaystr,",");
      if ((strlen (dispstr) == 0) || (strlen (dispstr) > 10) ||
       (strlen (delaystr) == 0) || (strlen (delaystr) > 10)) {
 printf ("accuracy unreadable\n");
      }
      else {
 printf("   time correct to within %.0f ms\n", atof(dispstr) + atof(delaystr) / 2.0);
      }
    } else {
      rc=1;
      printf ("accuracy unknown\n");
    }
  }
  strncpy(buff, ntpmsg.payload, sizeof(buff));
  if ((newstr = strstr (buff, POLL))) {
    newstr += sizeof(POLL) - 1;
    dispstr = strtok(newstr,",");
    if ((strlen (dispstr) == 0) || (strlen (dispstr) > 2)) {
      printf ("poll interval unreadable\n");
    }
    else {
      printf("   polling server every %d s\n",1 << atoi(dispstr));
    }
  } else {
    rc=1;
    printf ("poll interval unknown\n");
  }
  return rc;
}

canonical_original_code:
int main() {
  int rc;
  struct sockaddr_in sock;
  struct in_addr address;
  int sd;
  struct fd_set fds;
  struct timeval tv;
  int n;
  unsigned char byte1ok;
  unsigned char byte2ok;
  struct { unsigned char byte1; unsigned char byte2; unsigned short sequence; unsigned char status1; unsigned char status2; unsigned short AssocID; unsigned short Offset; unsigned short Count; char payload[468]; char authenticator[96]; } ntpmsg;
  char buff[468];
  unsigned int clksrc;
  char *clksrcname[] = {
    "unspecified",
    "atomic clock",
    "VLF radio",
    "HF radio",
    "UHF radio",
    "local net",
    "NTP server",
    "UDP/TIME",
    "wristwatch",
    "modem"};
  char *newstr;
  char *dispstr;
  char *delaystr;
  char DISP[] = "rootdisp=";
  char DELAY[] = "rootdelay=";
  char STRATUM[] = "stratum=";
  char POLL[] = "tc=";
  char REFID[] = "refid=";
  tv.tv_sec = 1;
  tv.tv_usec = 0;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  inet_aton("127.0.0.1", &address);
  sock.sin_family = 2;
  sock.sin_addr = address;
  sock.sin_port = htons(123);
  memset ( &ntpmsg, 0, sizeof(ntpmsg));
  ntpmsg.byte1 = 0x16;
  ntpmsg.byte2 = 2; ntpmsg.sequence=htons(1);
  if ((sd = socket (2, SOCK_DGRAM, 0)) < 0)
    die("unable to open socket");
  if (connect(sd, (struct sockaddr *)&sock, sizeof(sock)) < 0) {
    perror ("On connect");
    die("unable to connect to socket");
  }
  ((void) (((&fds)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
  if (send(sd, &ntpmsg, sizeof(ntpmsg), 0) < 0) {
    perror ("On send");
    die ("unable to send command to NTP port");
  }
  n = select (sd+1, &fds, (struct fd_set *)0, (struct fd_set *)0 , &tv);
  if (n == 0)
    die ("timeout");
  if (n == -1)
    die ("error on select");
  if ((n = recv (sd, &ntpmsg, sizeof(ntpmsg), 0)) < 0)
    die ("Unable to talk to NTP daemon. Is it running?");
  byte1ok = ((ntpmsg.byte1&0x3F) == 0x16);
  byte2ok = ((ntpmsg.byte2 & ~0x20) == (2|0x80));
  if (!(byte1ok && byte2ok)) {
    fprintf (stderr,"status word is 0x%02x%02x\n", ntpmsg.byte1,ntpmsg.byte2 );
    die ("return data appears to be invalid based on status word");
  }
  if (!(ntpmsg.byte2 | 0x40)) {
    fprintf (stderr,"status byte2 is %02x\n", ntpmsg.byte2 );
    die ("error bit is set in reply");
  }
  if (!(ntpmsg.byte2 | 0x20)) {
    fprintf (stderr,"status byte2 is %02x\n", ntpmsg.byte2 );
    fprintf (stderr,"More bit unexpected in reply");
  }
  if ((ntpmsg.status1 >> 6) == 3) {
    printf ("unsynchronised\n");
    if ((ntpmsg.status2 & 0x0F) == 1)
      printf ("  time server re-starting\n");
      rc=1;
  }
  else {
    rc=0;
    printf ("synchronised to ");
    clksrc = (ntpmsg.status1 & 0x3F);
    if (clksrc < 10)
      printf("%s", clksrcname[clksrc]);
    else
      printf("unknown source");
    if (clksrc == 6) {
      strncpy(buff, ntpmsg.payload, sizeof(buff));
      if ((newstr = strstr (buff, REFID))) {
 newstr += sizeof(REFID) - 1;
 dispstr = strtok(newstr,",");
 if ((strlen (dispstr) == 0) || (strlen (dispstr) > 16)) {
   printf (" <IP unreadable>");
 }
 else {
   printf(" (%s)",dispstr);
 }
      } else {
 rc=1;
 printf (" <IP unknown>");
      }
    }
    strncpy(buff, ntpmsg.payload, sizeof(buff));
    if ((newstr = strstr (buff, STRATUM))) {
      newstr += sizeof(STRATUM) - 1;
      dispstr = strtok(newstr,",");
      if ((strlen (dispstr) == 0) || (strlen (dispstr) > 2)) {
 printf (", stratum unreadable\n");
      }
      else {
 printf(" at stratum %s \n",dispstr);
      }
    } else {
      rc=1;
      printf (", stratum unknown\n");
    }
    strncpy(buff, ntpmsg.payload, sizeof(buff));
    if ((dispstr = strstr (buff, DISP)) && (delaystr = strstr (buff, DELAY))) {
      dispstr += sizeof(DISP) - 1;
      dispstr = strtok(dispstr,",");
      delaystr += sizeof(DELAY) - 1;
      delaystr = strtok(delaystr,",");
      if ((strlen (dispstr) == 0) || (strlen (dispstr) > 10) ||
       (strlen (delaystr) == 0) || (strlen (delaystr) > 10)) {
 printf ("accuracy unreadable\n");
      }
      else {
 printf("   time correct to within %.0f ms\n", atof(dispstr) + atof(delaystr) / 2.0);
      }
    } else {
      rc=1;
      printf ("accuracy unknown\n");
    }
  }
  strncpy(buff, ntpmsg.payload, sizeof(buff));
  if ((newstr = strstr (buff, POLL))) {
    newstr += sizeof(POLL) - 1;
    dispstr = strtok(newstr,",");
    if ((strlen (dispstr) == 0) || (strlen (dispstr) > 2)) {
      printf ("poll interval unreadable\n");
    }
    else {
      printf("   polling server every %d s\n",1 << atoi(dispstr));
    }
  } else {
    rc=1;
    printf ("poll interval unknown\n");
  }
  return rc;
}

variable_types: rc int

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

variable_types:
address
struct in_addr { unsigned int s_addr; }

variable_types: sd int

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

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

variable_types: n int

variable_types:
buff
char [468]

variable_types:
clksrc
unsigned int

variable_types:
clksrcname
char *[]

variable_types:
newstr
char *

variable_types:
dispstr
char *

variable_types:
delaystr
char *

variable_types:
DISP
char []

variable_types:
DELAY
char []

variable_types:
STRATUM
char []

variable_types:
POLL
char []

variable_types:
REFID
char []

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

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


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(2);
}

original_code:
void die (char *msg) {
  fprintf (stderr,"%s\n",msg);
  exit (2);
}

canonical_original_code:
void die(char *msg) {
  fprintf (stderr,"%s\n",msg);
  exit (2);
}

variable_types:
msg
char *


repo: darpa-xdata/xlang

decompiled_code:
void __fastcall __noreturn td_error(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void td_error(char *msg)
{
    fprintf(stderr, "%s\n", msg);
    exit(1);
}


decompiled_code:
__int64 __fastcall td_typeof(_QWORD *a1)
{
__int64 result; // rax

result = *(unsigned int *)a1;
if ( (unsigned int)result > 0x10 )
result = (*(__int64 (__fastcall **)(_QWORD))(*a1 + 112LL))(a1[1]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax

result = *(unsigned int *)a1;
if ( (unsigned int)result > 0x10 )
result = (*(__int64 (__fastcall **)(_QWORD))(*a1 + 112LL))(a1[1]);
return result;
}

original_code:
td_tag_t td_typeof(td_val_t *v)
{
    if (((v)->tag > TD_MAX_TAG))
        return v->owner->get_type(v->object);
    return v->tag;
}

canonical_original_code:
enum td_tag_t td_typeof(struct td_val_t *v)
{
    if (((v)->tag > TD_MAX_TAG))
        return v->owner->get_type(v->object);
    return v->tag;
}

variable_types: struct td_val_t { union { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; struct _td_env_t { char *name; void (*eval)(struct td_val_t *out, char *str); void (*invoke0)(struct td_val_t *out, char *f); void (*invoke1)(struct td_val_t *out, char *f, struct td_val_t *); void (*invoke2)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *); void (*invoke3)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke4)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke5)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invokeGraph0)(struct graph_t { int numNodes; char **nodeNames; double *edgeValues; double *nodeValues; int *rowOffsets; int *colIndices; } *out, char *f); void (*invokeGraph1)(struct graph_t *out, char *f, struct graph_t *in); void (*invokeGraph2)(struct graph_t *out, char *f, struct graph_t *in, int k); void (*invokeGraphAndCSC)(struct td_val_t *out, char *f, struct graph_t *in_graph, int *in_csc_offsets, int *in_csc_indics); void (*retain)(void *obj); void (*release)(void *obj); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_type)(void *); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_eltype)(void *); void *(*get_dataptr)(void *); unsigned long (*get_length)(void *); unsigned long (*get_ndims)(void *); void (*get_dims)(void *, unsigned long *dims); void (*get_strides)(void *, unsigned long *strides); } *owner; }; union { char int8_val; unsigned char uint8_val; short int16_val; unsigned short uint16_val; int int32_val; unsigned int uint32_val; long int64_val; unsigned long uint64_val; float float_val; double double_val; void *ptr_val; void *object; }; } *

user_defined_types: struct td_val_t { union { enum td_tag_t tag; struct _td_env_t *owner; }; union { char int8_val; unsigned char uint8_val; short int16_val; unsigned short uint16_val; int int32_val; unsigned int uint32_val; long int64_val; unsigned long uint64_val; float float_val; double double_val; void *ptr_val; void *object; }; }

user_defined_types: struct _td_env_t { char *name; void (*eval)(struct td_val_t *out, char *str); void (*invoke0)(struct td_val_t *out, char *f); void (*invoke1)(struct td_val_t *out, char *f, struct td_val_t *); void (*invoke2)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *); void (*invoke3)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke4)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke5)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invokeGraph0)(struct graph_t *out, char *f); void (*invokeGraph1)(struct graph_t *out, char *f, struct graph_t *in); void (*invokeGraph2)(struct graph_t *out, char *f, struct graph_t *in, int k); void (*invokeGraphAndCSC)(struct td_val_t *out, char *f, struct graph_t *in_graph, int *in_csc_offsets, int *in_csc_indics); void (*retain)(void *obj); void (*release)(void *obj); enum td_tag_t (*get_type)(void *); enum td_tag_t (*get_eltype)(void *); void *(*get_dataptr)(void *); unsigned long (*get_length)(void *); unsigned long (*get_ndims)(void *); void (*get_dims)(void *, unsigned long *dims); void (*get_strides)(void *, unsigned long *strides); }


decompiled_code:
__int64 __fastcall td_eltype(_QWORD *a1)
{
__int64 result; // rax

if ( *(_DWORD *)a1 == 12 )
result = *(unsigned int *)(a1[1] + 16LL);
else
result = (*(__int64 (__fastcall **)(_QWORD))(*a1 + 120LL))(a1[1]);
return result;
}

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

if ( *(_DWORD *)a1 == 12 )
result = *(unsigned int *)(a1[1] + 16LL);
else
result = (*(__int64 (__fastcall **)(_QWORD))(*a1 + 120LL))(a1[1]);
return result;
}

original_code:
td_tag_t td_eltype(td_val_t *v)
{
    if (v->tag == TD_ARRAY)
        return ((td_array_t*)v->object)->eltype;
    return v->owner->get_eltype(v->object);
}

canonical_original_code:
enum td_tag_t td_eltype(struct td_val_t *v)
{
    if (v->tag == TD_ARRAY)
        return ((struct td_array_t *)v->object)->eltype;
    return v->owner->get_eltype(v->object);
}

return_type: enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 }

user_defined_types: struct td_array_t { void *data; unsigned long length; enum td_tag_t eltype; unsigned long ndims; unsigned long size1; unsigned long stride1; }

user_defined_types: struct graph_t { int numNodes; char **nodeNames; double *edgeValues; double *nodeValues; int *rowOffsets; int *colIndices; }


original_code:
void *td_dataptr(td_val_t *v)
{
    if (((v)->tag > TD_MAX_TAG))
        return v->owner->get_dataptr(v->object);
    if (v->tag == TD_ARRAY)
        return ((td_array_t*)v->object)->data;
    if (v->tag == TD_UTF8)
        return ((td_string_t*)v->object)->data;
    return (void*)&(v->object);
}

canonical_original_code:
void *td_dataptr(struct td_val_t *v)
{
    if (((v)->tag > TD_MAX_TAG))
        return v->owner->get_dataptr(v->object);
    if (v->tag == TD_ARRAY)
        return ((struct td_array_t *)v->object)->data;
    if (v->tag == TD_UTF8)
        return ((struct td_string_t *)v->object)->data;
    return (void *)&(v->object);
}

return_type: void *

user_defined_types: struct td_string_t { void *data; unsigned long length; }

user_defined_types: enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 }


original_code:
size_t td_length(td_val_t *v)
{
    if (((v)->tag > TD_MAX_TAG))
        return v->owner->get_length(v->object);
    if (v->tag == TD_ARRAY)
        return ((td_array_t*)v->object)->length;
    if (v->tag == TD_UTF8)
        return ((td_string_t*)v->object)->length;
    return 1;
}

canonical_original_code:
unsigned long td_length(struct td_val_t *v)
{
    if (((v)->tag > TD_MAX_TAG))
        return v->owner->get_length(v->object);
    if (v->tag == TD_ARRAY)
        return ((struct td_array_t *)v->object)->length;
    if (v->tag == TD_UTF8)
        return ((struct td_string_t *)v->object)->length;
    return 1;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall td_int8(_QWORD *a1)
{
return *(unsigned __int8 *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
return *(unsigned __int8 *)func3(a1);
}

original_code: int8_t td_int8(td_val_t *v) { return *(int8_t*)td_dataptr(v); }

canonical_original_code: char td_int8(struct td_val_t *v) { return *(char *)td_dataptr(v); }

return_type: char


decompiled_code:
__int64 __fastcall td_uint8(_QWORD *a1)
{
return *(unsigned __int8 *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
return *(unsigned __int8 *)func3(a1);
}

original_code: uint8_t td_uint8(td_val_t *v) { return *(uint8_t*)td_dataptr(v); }

canonical_original_code: unsigned char td_uint8(struct td_val_t *v) { return *(unsigned char *)td_dataptr(v); }


decompiled_code:
__int64 __fastcall td_int16(_QWORD *a1)
{
return *(unsigned __int16 *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
return *(unsigned __int16 *)func3(a1);
}

original_code: int16_t td_int16(td_val_t *v) { return *(int16_t*)td_dataptr(v); }

canonical_original_code: short td_int16(struct td_val_t *v) { return *(short *)td_dataptr(v); }

return_type: short


decompiled_code:
__int64 __fastcall td_uint16(_QWORD *a1)
{
return *(unsigned __int16 *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
return *(unsigned __int16 *)func3(a1);
}

original_code: uint16_t td_uint16(td_val_t *v) { return *(uint16_t*)td_dataptr(v); }

canonical_original_code: unsigned short td_uint16(struct td_val_t *v) { return *(unsigned short *)td_dataptr(v); }

return_type: unsigned short


decompiled_code:
__int64 __fastcall td_int32(_QWORD *a1)
{
return *(unsigned int *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
return *(unsigned int *)func3(a1);
}

original_code: int32_t td_int32(td_val_t *v) { return *(int32_t*)td_dataptr(v); }

canonical_original_code: int td_int32(struct td_val_t *v) { return *(int *)td_dataptr(v); }


decompiled_code:
__int64 __fastcall td_uint32(_QWORD *a1)
{
return *(unsigned int *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
return *(unsigned int *)func3(a1);
}

original_code: uint32_t td_uint32(td_val_t *v) { return *(uint32_t*)td_dataptr(v); }

canonical_original_code: unsigned int td_uint32(struct td_val_t *v) { return *(unsigned int *)td_dataptr(v); }

return_type: unsigned int


decompiled_code:
__int64 __fastcall td_int64(_QWORD *a1)
{
return *(_QWORD *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
return *(_QWORD *)func3(a1);
}

original_code: int64_t td_int64(td_val_t *v) { return *(int64_t*)td_dataptr(v); }

canonical_original_code: long td_int64(struct td_val_t *v) { return *(long *)td_dataptr(v); }


decompiled_code:
__int64 __fastcall td_uint64(_QWORD *a1)
{
return *(_QWORD *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
return *(_QWORD *)func3(a1);
}

original_code: uint64_t td_uint64(td_val_t *v) { return *(uint64_t*)td_dataptr(v); }

canonical_original_code: unsigned long td_uint64(struct td_val_t *v) { return *(unsigned long *)td_dataptr(v); }


decompiled_code:
float __fastcall td_float(_QWORD *a1)
{
return *(float *)td_dataptr(a1);
}

canonical_decompiled_code:
float __fastcall func13(_QWORD *a1)
{
return *(float *)func3(a1);
}

original_code: float td_float(td_val_t *v) { return *(float*)td_dataptr(v); }

canonical_original_code: float td_float(struct td_val_t *v) { return *(float *)td_dataptr(v); }

return_type: float


decompiled_code:
double __fastcall td_double(_QWORD *a1)
{
return *(double *)td_dataptr(a1);
}

canonical_decompiled_code:
double __fastcall func14(_QWORD *a1)
{
return *(double *)func3(a1);
}

original_code: double td_double(td_val_t *v) { return *(double*)td_dataptr(v); }

canonical_original_code: double td_double(struct td_val_t *v) { return *(double *)td_dataptr(v); }


decompiled_code:
__int64 __fastcall td_pointer(_QWORD *a1)
{
return *(_QWORD *)td_dataptr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1)
{
return *(_QWORD *)func3(a1);
}

original_code: void *td_pointer(td_val_t *v) { return *(void**)td_dataptr(v); }

canonical_original_code: void *td_pointer(struct td_val_t *v) { return *(void **)td_dataptr(v); }


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

result = 8LL;
if ( a1 <= 0xA )
result = type_sizes[a1];
return result;
}

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

result = 8LL;
if ( a1 <= 0xA )
result = type_sizes[a1];
return result;
}

original_code:
size_t td_type_size(td_tag_t tag)
{
    if (tag < TD_UTF8) return type_sizes[tag];
    return sizeof(void*);
}

canonical_original_code:
unsigned long td_type_size(enum td_tag_t tag)
{
    if (tag < TD_UTF8) return type_sizes[tag];
    return sizeof(void *);
}

variable_types: enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 }


decompiled_code:
__int64 __fastcall td_env_julia(const char *a1, __int64 a2)
{
__int64 result; // rax
void *v3; // r12
void (__fastcall *v4)(__int64); // rax
char *v5; // rax
char v6[536]; // [rsp-218h] [rbp-218h] BYREF

result = cached_julia_env;
if ( !cached_julia_env )
{
snprintf(v6, 0x200uLL, "%s%s%s%s", a1, "/", "libtd_julia", ".so");
v3 = dlopen(v6, 258);
if ( !v3 )
{
v5 = dlerror();
fprintf(stderr, "%s\n", v5);
td_error("could not load libjulia");
}
v4 = (void (__fastcall *)(__int64))dlsym(v3, "td_jl_init");
v4(a2);
result = cached_julia_env;
if ( !cached_julia_env )
_assert_fail("cached_julia_env", "td.c", 0x69u, "td_env_julia");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1, __int64 a2)
{
__int64 result; // rax
void *v3; // r12
void (__fastcall *v4)(__int64); // rax
char *v5; // rax
char v6[536]; // [rsp-218h] [rbp-218h] BYREF

result = cached_julia_env;
if ( !cached_julia_env )
{
snprintf(v6, 0x200uLL, "%s%s%s%s", a1, "/", "libtd_julia", ".so");
v3 = dlopen(v6, 258);
if ( !v3 )
{
v5 = dlerror();
fprintf(stderr, "%s\n", v5);
func0("could not load libjulia");
}
v4 = (void (__fastcall *)(__int64))dlsym(v3, "td_jl_init");
v4(a2);
result = cached_julia_env;
if ( !cached_julia_env )
_assert_fail("cached_julia_env", "td.c", 0x69u, "td_env_julia");
}
return result;
}

original_code:
td_env_t *td_env_julia(char *plugin_path, char *julia_path)
{
    char path[512];
    if (cached_julia_env == ((void *)0)) {
        snprintf(path, sizeof(path), "%s%s%s%s",
                 plugin_path, "/", "libtd_julia", ".so");
        void *h = dlopen(path, 0x00100 | 0x00002);
        if (h == ((void *)0)) {
            fprintf(stderr, "%s\n", dlerror());
            td_error("could not load libjulia");
        }
        void (*init)(char*) = dlsym(h, "td_jl_init");
        init(julia_path);
        ((void) sizeof ((cached_julia_env) ? 1 : 0), __extension__ ({ if (cached_julia_env) ; else __assert_fail ("cached_julia_env", "td.c", 105, __extension__ __PRETTY_FUNCTION__); }));
    }
    return cached_julia_env;
}

canonical_original_code:
struct _td_env_t *td_env_julia(char *plugin_path, char *julia_path)
{
    char path[512];
    if (cached_julia_env == ((void *)0)) {
        snprintf(path, sizeof(path), "%s%s%s%s",
                 plugin_path, "/", "libtd_julia", ".so");
        void *h = dlopen(path, 0x00100 | 0x00002);
        if (h == ((void *)0)) {
            fprintf(stderr, "%s\n", dlerror());
            td_error("could not load libjulia");
        }
        void (*init)(char *) = dlsym(h, "td_jl_init");
        init(julia_path);
        ((void) sizeof ((cached_julia_env) ? 1 : 0), __extension__ ({ if (cached_julia_env) ; else __assert_fail ("cached_julia_env", "td.c", 105, __extension__ __PRETTY_FUNCTION__); }));
    }
    return cached_julia_env;
}

variable_types:
path
char [512]

variable_types:
h
void *

variable_types:
init
void (*)(char *)

return_type: struct _td_env_t { char *name; void (*eval)(struct td_val_t { union { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; struct _td_env_t *owner; }; union { char int8_val; unsigned char uint8_val; short int16_val; unsigned short uint16_val; int int32_val; unsigned int uint32_val; long int64_val; unsigned long uint64_val; float float_val; double double_val; void *ptr_val; void *object; }; } *out, char *str); void (*invoke0)(struct td_val_t *out, char *f); void (*invoke1)(struct td_val_t *out, char *f, struct td_val_t *); void (*invoke2)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *); void (*invoke3)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke4)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke5)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invokeGraph0)(struct graph_t { int numNodes; char **nodeNames; double *edgeValues; double *nodeValues; int *rowOffsets; int *colIndices; } *out, char *f); void (*invokeGraph1)(struct graph_t *out, char *f, struct graph_t *in); void (*invokeGraph2)(struct graph_t *out, char *f, struct graph_t *in, int k); void (*invokeGraphAndCSC)(struct td_val_t *out, char *f, struct graph_t *in_graph, int *in_csc_offsets, int *in_csc_indics); void (*retain)(void *obj); void (*release)(void *obj); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_type)(void *); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_eltype)(void *); void *(*get_dataptr)(void *); unsigned long (*get_length)(void *); unsigned long (*get_ndims)(void *); void (*get_dims)(void *, unsigned long *dims); void (*get_strides)(void *, unsigned long *strides); } *


decompiled_code:
void __fastcall td_provide_julia(__int64 a1)
{
cached_julia_env = a1;
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1)
{
cached_julia_env = a1;
}

original_code:
void td_provide_julia(td_env_t *e)
{
    cached_julia_env = e;
}

canonical_original_code:
void td_provide_julia(struct _td_env_t *e)
{
    cached_julia_env = e;
}

variable_types: struct _td_env_t { char *name; void (*eval)(struct td_val_t { union { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; struct _td_env_t *owner; }; union { char int8_val; unsigned char uint8_val; short int16_val; unsigned short uint16_val; int int32_val; unsigned int uint32_val; long int64_val; unsigned long uint64_val; float float_val; double double_val; void *ptr_val; void *object; }; } *out, char *str); void (*invoke0)(struct td_val_t *out, char *f); void (*invoke1)(struct td_val_t *out, char *f, struct td_val_t *); void (*invoke2)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *); void (*invoke3)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke4)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke5)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invokeGraph0)(struct graph_t { int numNodes; char **nodeNames; double *edgeValues; double *nodeValues; int *rowOffsets; int *colIndices; } *out, char *f); void (*invokeGraph1)(struct graph_t *out, char *f, struct graph_t *in); void (*invokeGraph2)(struct graph_t *out, char *f, struct graph_t *in, int k); void (*invokeGraphAndCSC)(struct td_val_t *out, char *f, struct graph_t *in_graph, int *in_csc_offsets, int *in_csc_indics); void (*retain)(void *obj); void (*release)(void *obj); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_type)(void *); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_eltype)(void *); void *(*get_dataptr)(void *); unsigned long (*get_length)(void *); unsigned long (*get_ndims)(void *); void (*get_dims)(void *, unsigned long *dims); void (*get_strides)(void *, unsigned long *strides); } *


decompiled_code:
__int64 __fastcall td_env_python(const char *a1, __int64 a2)
{
__int64 result; // rax
void *v3; // r12
void (__fastcall *v4)(__int64); // rax
char *v5; // rax
char v6[536]; // [rsp-218h] [rbp-218h] BYREF

result = cached_python_env;
if ( !cached_python_env )
{
snprintf(v6, 0x200uLL, "%s%s%s%s", a1, "/", "libtd_python", ".so");
v3 = dlopen(v6, 258);
if ( !v3 )
{
v5 = dlerror();
fprintf(stderr, "%s\n", v5);
td_error("could not load libpython");
}
v4 = (void (__fastcall *)(__int64))dlsym(v3, "td_py_init");
v4(a2);
result = cached_python_env;
if ( !cached_python_env )
_assert_fail("cached_python_env", "td.c", 0x84u, "td_env_python");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(const char *a1, __int64 a2)
{
__int64 result; // rax
void *v3; // r12
void (__fastcall *v4)(__int64); // rax
char *v5; // rax
char v6[536]; // [rsp-218h] [rbp-218h] BYREF

result = cached_python_env;
if ( !cached_python_env )
{
snprintf(v6, 0x200uLL, "%s%s%s%s", a1, "/", "libtd_python", ".so");
v3 = dlopen(v6, 258);
if ( !v3 )
{
v5 = dlerror();
fprintf(stderr, "%s\n", v5);
func0("could not load libpython");
}
v4 = (void (__fastcall *)(__int64))dlsym(v3, "td_py_init");
v4(a2);
result = cached_python_env;
if ( !cached_python_env )
_assert_fail("cached_python_env", "td.c", 0x84u, "td_env_python");
}
return result;
}

original_code:
td_env_t *td_env_python(char *plugin_path, char *python_path)
{
    char path[512];
    if (cached_python_env == ((void *)0)) {
        snprintf(path, sizeof(path), "%s%s%s%s",
                 plugin_path, "/", "libtd_python", ".so");
        void *h = dlopen(path, 0x00100 | 0x00002);
        if (h == ((void *)0)) {
            fprintf(stderr, "%s\n", dlerror());
            td_error("could not load libpython");
        }
        void (*init)(char*) = dlsym(h, "td_py_init");
        init(python_path);
        ((void) sizeof ((cached_python_env) ? 1 : 0), __extension__ ({ if (cached_python_env) ; else __assert_fail ("cached_python_env", "td.c", 132, __extension__ __PRETTY_FUNCTION__); }));
    }
    return cached_python_env;
}

canonical_original_code:
struct _td_env_t *td_env_python(char *plugin_path, char *python_path)
{
    char path[512];
    if (cached_python_env == ((void *)0)) {
        snprintf(path, sizeof(path), "%s%s%s%s",
                 plugin_path, "/", "libtd_python", ".so");
        void *h = dlopen(path, 0x00100 | 0x00002);
        if (h == ((void *)0)) {
            fprintf(stderr, "%s\n", dlerror());
            td_error("could not load libpython");
        }
        void (*init)(char *) = dlsym(h, "td_py_init");
        init(python_path);
        ((void) sizeof ((cached_python_env) ? 1 : 0), __extension__ ({ if (cached_python_env) ; else __assert_fail ("cached_python_env", "td.c", 132, __extension__ __PRETTY_FUNCTION__); }));
    }
    return cached_python_env;
}


decompiled_code:
void __fastcall td_provide_python(__int64 a1)
{
cached_python_env = a1;
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1)
{
cached_python_env = a1;
}

original_code:
void td_provide_python(td_env_t *e)
{
    cached_python_env = e;
}

canonical_original_code:
void td_provide_python(struct _td_env_t *e)
{
    cached_python_env = e;
}


decompiled_code:
__int64 __fastcall td_env_java(const char *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
void *v5; // r13
void (__fastcall *v6)(__int64, __int64); // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax
char v10[552]; // [rsp-228h] [rbp-228h] BYREF

result = cached_java_env;
if ( !cached_java_env )
{
snprintf(v10, 0x200uLL, "%s%s%s%s", a1, "/", "libtd_java", ".so");
printf("looking for lib at %s\n", v10);
v5 = dlopen(v10, 258);
if ( !v5 )
{
v7 = dlerror();
fprintf(stderr, "%s\n", v7);
v5 = dlopen("libtd_java.dll", 258);
if ( !v5 )
{
v8 = dlerror();
fprintf(stderr, "%s\n", v8);
v5 = dlopen("libtd_java.dylib", 258);
if ( !v5 )
{
v9 = dlerror();
fprintf(stderr, "%s\n", v9);
td_error("could not load libjava - did you set LD_LIBRARY_PATH to include the libjvm location?\n");
}
}
}
v6 = (void (__fastcall *)(__int64, __int64))dlsym(v5, "td_java_init");
v6(a2, a3);
result = cached_java_env;
if ( !cached_java_env )
_assert_fail("cached_java_env", "td.c", 0xABu, "td_env_java");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(const char *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
void *v5; // r13
void (__fastcall *v6)(__int64, __int64); // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax
char v10[552]; // [rsp-228h] [rbp-228h] BYREF

result = cached_java_env;
if ( !cached_java_env )
{
snprintf(v10, 0x200uLL, "%s%s%s%s", a1, "/", "libtd_java", ".so");
printf("looking for lib at %s\n", v10);
v5 = dlopen(v10, 258);
if ( !v5 )
{
v7 = dlerror();
fprintf(stderr, "%s\n", v7);
v5 = dlopen("libtd_java.dll", 258);
if ( !v5 )
{
v8 = dlerror();
fprintf(stderr, "%s\n", v8);
v5 = dlopen("libtd_java.dylib", 258);
if ( !v5 )
{
v9 = dlerror();
fprintf(stderr, "%s\n", v9);
func0("could not load libjava - did you set LD_LIBRARY_PATH to include the libjvm location?\n");
}
}
}
v6 = (void (__fastcall *)(__int64, __int64))dlsym(v5, "td_java_init");
v6(a2, a3);
result = cached_java_env;
if ( !cached_java_env )
_assert_fail("cached_java_env", "td.c", 0xABu, "td_env_java");
}
return result;
}

original_code:
td_env_t *td_env_java(char *plugin_path, char *classpath, char *java_path)
{
    char path[512];
    if (cached_java_env == ((void *)0)) {
        snprintf(path, sizeof(path), "%s%s%s%s",
                 plugin_path, "/", "libtd_java", ".so");
        printf("looking for lib at %s\n", path);
        void *h = dlopen(path, 0x00100 | 0x00002);
        if (h == ((void *)0)) {
         fprintf(stderr, "%s\n", dlerror());
         h = dlopen("libtd_java.dll", 0x00100 | 0x00002);
        }
        if (h == ((void *)0)) {
         fprintf(stderr, "%s\n", dlerror());
         h = dlopen("libtd_java.dylib", 0x00100 | 0x00002);
        }
        if (h == ((void *)0)) {
         fprintf(stderr, "%s\n", dlerror());
         td_error("could not load libjava - did you set LD_LIBRARY_PATH to include the libjvm location?\n");
         td_error("for instance something like : .:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/\n");
        }
        void (*init)(char*,char*) = dlsym(h, "td_java_init");
        init(classpath, java_path);
        ((void) sizeof ((cached_java_env) ? 1 : 0), __extension__ ({ if (cached_java_env) ; else __assert_fail ("cached_java_env", "td.c", 171, __extension__ __PRETTY_FUNCTION__); }));
    }
    return cached_java_env;
}

canonical_original_code:
struct _td_env_t *td_env_java(char *plugin_path, char *classpath, char *java_path)
{
    char path[512];
    if (cached_java_env == ((void *)0)) {
        snprintf(path, sizeof(path), "%s%s%s%s",
                 plugin_path, "/", "libtd_java", ".so");
        printf("looking for lib at %s\n", path);
        void *h = dlopen(path, 0x00100 | 0x00002);
        if (h == ((void *)0)) {
         fprintf(stderr, "%s\n", dlerror());
         h = dlopen("libtd_java.dll", 0x00100 | 0x00002);
        }
        if (h == ((void *)0)) {
         fprintf(stderr, "%s\n", dlerror());
         h = dlopen("libtd_java.dylib", 0x00100 | 0x00002);
        }
        if (h == ((void *)0)) {
         fprintf(stderr, "%s\n", dlerror());
         td_error("could not load libjava - did you set LD_LIBRARY_PATH to include the libjvm location?\n");
         td_error("for instance something like : .:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/\n");
        }
        void (*init)(char *, char *) = dlsym(h, "td_java_init");
        init(classpath, java_path);
        ((void) sizeof ((cached_java_env) ? 1 : 0), __extension__ ({ if (cached_java_env) ; else __assert_fail ("cached_java_env", "td.c", 171, __extension__ __PRETTY_FUNCTION__); }));
    }
    return cached_java_env;
}

variable_types:
classpath
char *

variable_types:
init
void (*)(char *, char *)


decompiled_code:
void __fastcall td_provide_java(__int64 a1)
{
cached_java_env = a1;
}

canonical_decompiled_code:
void __fastcall func22(__int64 a1)
{
cached_java_env = a1;
}

original_code:
void td_provide_java(td_env_t *e)
{
    cached_java_env = e;
}

canonical_original_code:
void td_provide_java(struct _td_env_t *e)
{
    cached_java_env = e;
}