addActor

decompiled_code:
__int64 __fastcall addActor(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, int a8)
{
int v8; // eax
__int64 result; // rax

if ( a1 && (v8 = numEnemies, numEnemies <= 49) )
{
++numEnemies;
result = 20LL * v8;
*(__m128i *)((char *)&enemies + result) = _mm_loadu_si128((const __m128i *)&a7);
*(_DWORD *)((char *)&enemies + result + 16) = a8;
}
else
{
result = numBullets;
if ( numBullets <= 49 )
{
++numBullets;
result = 20LL * (int)result;
*(__m128i *)((char *)&bullets + result) = _mm_loadu_si128((const __m128i *)&a7);
*(_DWORD *)((char *)&bullets + result + 16) = a8;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, int a8)
{
int v8; // eax
__int64 result; // rax

if ( a1 && (v8 = numEnemies, numEnemies <= 49) )
{
++numEnemies;
result = 20LL * v8;
*(__m128i *)((char *)&enemies + result) = _mm_loadu_si128((const __m128i *)&a7);
*(_DWORD *)((char *)&enemies + result + 16) = a8;
}
else
{
result = numBullets;
if ( numBullets <= 49 )
{
++numBullets;
result = 20LL * (int)result;
*(__m128i *)((char *)&bullets + result) = _mm_loadu_si128((const __m128i *)&a7);
*(_DWORD *)((char *)&bullets + result + 16) = a8;
}
}
return result;
}

original_code:
void addActor(int enem, Actor_t newActor){
 if(enem && _numEnemies < 50) {
  _enemies[_numEnemies++] = newActor;
 }
 else if(_numBullets < 50) {
  _bullets[_numBullets++] = newActor;
 }
}

canonical_original_code:
void addActor(int enem, struct Actor_t newActor){
 if(enem && _numEnemies < 50) {
  _enemies[_numEnemies++] = newActor;
 }
 else if(_numBullets < 50) {
  _bullets[_numBullets++] = newActor;
 }
}

variable_types: enem int

variable_types: struct Actor_t { struct Geometry_t { int x; } geo; int dirMotion; }

user_defined_types: struct Actor_t { struct Geometry_t geo; int dirMotion; }


drawSprite

repo: sevko/termcrate

decompiled_code:
__int64 __fastcall drawSprite(const char *a1, __int64 a2)
{
xt_par0("\x1B[1m");
xt_par0(a2);
printf("%s", a1);
return xt_par0("\x1B[0m");
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
xt_par0("\x1B[1m");
xt_par0(a2);
printf("%s", a1);
return xt_par0("\x1B[0m");
}

original_code:
void drawSprite(char * sprite, char * color){
 xt_par0("\033[1m");
 xt_par0(color);
 printf("%s", sprite);
 xt_par0("\033[0m");
}

canonical_original_code:
void drawSprite(char *sprite, char *color){
 xt_par0("\033[1m");
 xt_par0(color);
 printf("%s", sprite);
 xt_par0("\033[0m");
}

variable_types:
sprite
char *

variable_types:
color
char *

return_type: void


renderActors

decompiled_code:
__int64 renderActors()
{
unsigned int *v0; // rbx
int v1; // ebp
unsigned int *v2; // rbx
int v3; // ebp

if ( numEnemies > 0 )
{
v0 = (unsigned int *)&enemies;
v1 = 0;
do
{
xt_par2("\x1B[%d;%dH", v0[1], *v0);
drawSprite("X", (__int64)"\x1B[32m");
++v1;
v0 += 5;
}
while ( numEnemies > v1 );
}
if ( numBullets > 0 )
{
v2 = (unsigned int *)&bullets;
v3 = 0;
do
{
xt_par2("\x1B[%d;%dH", v2[1], *v2);
drawSprite(byte_54C, (__int64)"\x1B[34m");
++v3;
v2 += 5;
}
while ( numBullets > v3 );
}
xt_par2("\x1B[%d;%dH", *((unsigned int *)&crate + 1), crate);
drawSprite("I", (__int64)"\x1B[33m");
xt_par2("\x1B[%d;%dH", *((unsigned int *)&player + 1), player);
return drawSprite("O", (__int64)"\x1B[35m");
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int *v0; // rbx
int v1; // ebp
unsigned int *v2; // rbx
int v3; // ebp

if ( numEnemies > 0 )
{
v0 = (unsigned int *)&enemies;
v1 = 0;
do
{
xt_par2("\x1B[%d;%dH", v0[1], *v0);
func2("X", (__int64)"\x1B[32m");
++v1;
v0 += 5;
}
while ( numEnemies > v1 );
}
if ( numBullets > 0 )
{
v2 = (unsigned int *)&bullets;
v3 = 0;
do
{
xt_par2("\x1B[%d;%dH", v2[1], *v2);
func2(byte_54C, (__int64)"\x1B[34m");
++v3;
v2 += 5;
}
while ( numBullets > v3 );
}
xt_par2("\x1B[%d;%dH", *((unsigned int *)&crate + 1), crate);
func2("I", (__int64)"\x1B[33m");
xt_par2("\x1B[%d;%dH", *((unsigned int *)&player + 1), player);
return func2("O", (__int64)"\x1B[35m");
}

original_code:
void renderActors(){
 int enem;
 for(enem = 0; enem < _numEnemies; enem++){
  Actor_t mob = _enemies[enem];
  xt_par2("\033[%d;%dH", mob.geo.y, mob.geo.x);
  drawSprite("X", "\033[32m");
 }
 int bull;
 for(bull = 0; bull < _numBullets; bull++){
  Actor_t bullet = _bullets[bull];
  xt_par2("\033[%d;%dH", bullet.geo.y, bullet.geo.x);
  drawSprite("·", "\033[34m");
 }
 xt_par2("\033[%d;%dH", _crate.geo.y, _crate.geo.x);
 drawSprite("I", "\033[33m");
 xt_par2("\033[%d;%dH", _player.geo.y, _player.geo.x);
 drawSprite("O", "\033[35m");
}

canonical_original_code:
void renderActors(){
 int enem;
 for(enem = 0; enem < _numEnemies; enem++){
  struct Actor_t mob = _enemies[enem];
  xt_par2("\033[%d;%dH", mob.geo.y, mob.geo.x);
  drawSprite("X", "\033[32m");
 }
 int bull;
 for(bull = 0; bull < _numBullets; bull++){
  struct Actor_t bullet = _bullets[bull];
  xt_par2("\033[%d;%dH", bullet.geo.y, bullet.geo.x);
  drawSprite("·", "\033[34m");
 }
 xt_par2("\033[%d;%dH", _crate.geo.y, _crate.geo.x);
 drawSprite("I", "\033[33m");
 xt_par2("\033[%d;%dH", _player.geo.y, _player.geo.x);
 drawSprite("O", "\033[35m");
}

variable_types: bull int


drawString

decompiled_code:
size_t __fastcall drawString(char *s, int a2, int a3)
{
unsigned __int64 v4; // rbx
int v5; // er12
int v6; // er13
size_t result; // rax

v4 = 0LL;
v5 = 0;
v6 = 0;
while ( 1 )
{
result = strlen(s);
if ( result <= v4 )
break;
if ( s[v4] == 10 )
{
++v6;
v5 = 0;
}
else
{
xt_par2("\x1B[%d;%dH", (unsigned int)(v6 + a3), (unsigned int)(v5 + a2));
putchar(s[v4]);
++v5;
}
++v4;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(char *s, int a2, int a3)
{
unsigned __int64 v4; // rbx
int v5; // er12
int v6; // er13
size_t result; // rax

v4 = 0LL;
v5 = 0;
v6 = 0;
while ( 1 )
{
result = strlen(s);
if ( result <= v4 )
break;
if ( s[v4] == 10 )
{
++v6;
v5 = 0;
}
else
{
xt_par2("\x1B[%d;%dH", (unsigned int)(v6 + a3), (unsigned int)(v5 + a2));
putchar(s[v4]);
++v5;
}
++v4;
}
return result;
}

original_code:
void drawString(char * text, int x, int y) {
 int row = 0, col = 0 , len = 0;
 while(len < strlen(text)) {
  if(text[len] == '\n'){
   row++;
   col = 0;
  } else {
   xt_par2("\033[%d;%dH", y + row, x + col);
   printf("%c", text[len]);
   col++;
  }
  len++;
 }
}

canonical_original_code:
void drawString(char *text, int x, int y) {
 int row = 0; int col = 0; int len = 0;
 while(len < strlen(text)) {
  if(text[len] == '\n'){
   row++;
   col = 0;
  } else {
   xt_par2("\033[%d;%dH", y + row, x + col);
   printf("%c", text[len]);
   col++;
  }
  len++;
 }
}

variable_types:
text
char *

variable_types: x int

variable_types: y int

variable_types: row int

variable_types: col int

variable_types: len int


renderScore

original_code:
void renderScore(){
 int score = _player.score;
 int numDig = (int)log10(score) + 1;
 int dig;
 xt_par0("\033[37m");
 for(dig = numDig - 1; dig >= 0; dig--){
  int xPos = 176 / 2 + numDig * 5 / 2 - (numDig - dig - 1) * 5;
  drawString(_numberSprites[score % 10], xPos, 44 * 0.1);
  score /= 10;
 }
 xt_par0("\033[0m");
}

variable_types: score int

variable_types: numDig int

variable_types: dig int

variable_types: xPos int


drawMessage

original_code:
void drawMessage(Message_t * message) {
    xt_par0("\033[1m");
    xt_par0("\033[31m");
    drawString(message->text, message->geo.x, message->geo.y);
    message->display -= 1;
    xt_par0("\033[0m");
}

canonical_original_code:
void drawMessage(struct Message_t *message) {
    xt_par0("\033[1m");
    xt_par0("\033[31m");
    drawString(message->text, message->geo.x, message->geo.y);
    message->display -= 1;
    xt_par0("\033[0m");
}

variable_types: struct Message_t { char *text; int display; struct Geometry_t { int x; } geo; } *

user_defined_types: struct Message_t { char *text; int display; struct Geometry_t geo; }


renderMessages

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

if ( messages[2] )
result = drawMessage((__int64)messages);
if ( messages[8] )
result = drawMessage((unsigned int)((_DWORD)messages + 24));
if ( messages[14] )
result = drawMessage((unsigned int)((_DWORD)messages + 48));
return result;
}

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

if ( messages[2] )
result = func6((__int64)messages);
if ( messages[8] )
result = func6((unsigned int)((_DWORD)messages + 24));
if ( messages[14] )
result = func6((unsigned int)((_DWORD)messages + 48));
return result;
}

original_code:
void renderMessages() {
 if(_messages[0].display) {
  drawMessage(&_messages[0]);
 }
 if(_messages[1].display) {
  drawMessage(&_messages[1]);
 }
 if(_messages[2].display) {
  drawMessage(&_messages[2]);
 }
}


resetCursor

decompiled_code:
__int64 resetCursor()
{
return xt_par2("\x1B[%d;%dH", 1LL, 1LL);
}

canonical_decompiled_code:
__int64 func8()
{
return xt_par2("\x1B[%d;%dH", 1LL, 1LL);
}

original_code:
void resetCursor(){
 xt_par2("\033[%d;%dH", 1, 1);
}


clearScreen

decompiled_code:
__int64 clearScreen()
{
resetCursor();
return xt_par0("\x1B[2J");
}

canonical_decompiled_code:
__int64 func9()
{
func8();
return xt_par0("\x1B[2J");
}

original_code:
void clearScreen(){
 resetCursor();
 xt_par0("\033[2J");
}


renderMenu

variable_types: button int

variable_types: struct Button_t { int x; int num; char name[10]; }


render

decompiled_code:
__int64 render()
{
clearScreen();
renderMap();
renderActors();
renderScore();
renderMessages();
return resetCursor();
}

canonical_decompiled_code:
__int64 func11()
{
func9();
func0();
func3();
func5();
func7();
return func8();
}

original_code:
void render(){
 clearScreen();
 renderMap();
 renderActors();
 renderScore();
 renderMessages();
 resetCursor();
}


loadWeapons

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

result = elements[12];
weapons = result;
*((_DWORD *)&weapons + 2) = 20;
*((_DWORD *)&weapons + 3) = 30;
*((_DWORD *)&weapons + 4) = 100;
*((_DWORD *)&weapons + 5) = 2;
return result;
}

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

result = elements[12];
weapons = result;
*((_DWORD *)&weapons + 2) = 20;
*((_DWORD *)&weapons + 3) = 30;
*((_DWORD *)&weapons + 4) = 100;
*((_DWORD *)&weapons + 5) = 2;
return result;
}

original_code:
void loadWeapons(){
 Weapon_t shotgun = { .ammo = 20, .rof = 30 };
 Weapon_t machineGun = { .ammo = 100, .rof = 2 };
 _weapons[0] = _elements.pistol;
 _weapons[1] = shotgun;
 _weapons[2] = machineGun;
}

canonical_original_code:
void loadWeapons(){
 struct Weapon_t shotgun = { .ammo = 20, .rof = 30 };
 struct Weapon_t machineGun = { .ammo = 100, .rof = 2 };
 _weapons[0] = _elements.pistol;
 _weapons[1] = shotgun;
 _weapons[2] = machineGun;
}

variable_types:
shotgun
struct Weapon_t { int ammo; }

variable_types:
machineGun
struct Weapon_t { int ammo; }


loadElements

decompiled_code:
void loadElements()
{
elements[0] = 0x50000000ALL;
LODWORD(elements[1]) = 1;
HIDWORD(elements[1]) = 1;
LODWORD(elements[2]) = 1;
HIDWORD(elements[2]) = 10;
LODWORD(elements[3]) = 5;
HIDWORD(elements[3]) = 1;
LODWORD(elements[4]) = 1;
HIDWORD(elements[4]) = 1;
LODWORD(elements[5]) = 10;
HIDWORD(elements[5]) = 5;
LODWORD(elements[6]) = 1;
HIDWORD(elements[6]) = 1000000;
LODWORD(elements[7]) = 15;
HIDWORD(elements[7]) = 10;
LODWORD(elements[8]) = 5;
HIDWORD(elements[8]) = 1;
LODWORD(elements[9]) = 1000000;
HIDWORD(elements[9]) = 15;
LODWORD(elements[10]) = 1;
HIDWORD(elements[10]) = 0;
LODWORD(elements[11]) = 0;
HIDWORD(elements[11]) = 0;
LODWORD(elements[12]) = 1000000;
HIDWORD(elements[12]) = 15;
}

canonical_decompiled_code:
void func1()
{
elements[0] = 0x50000000ALL;
LODWORD(elements[1]) = 1;
HIDWORD(elements[1]) = 1;
LODWORD(elements[2]) = 1;
HIDWORD(elements[2]) = 10;
LODWORD(elements[3]) = 5;
HIDWORD(elements[3]) = 1;
LODWORD(elements[4]) = 1;
HIDWORD(elements[4]) = 1;
LODWORD(elements[5]) = 10;
HIDWORD(elements[5]) = 5;
LODWORD(elements[6]) = 1;
HIDWORD(elements[6]) = 1000000;
LODWORD(elements[7]) = 15;
HIDWORD(elements[7]) = 10;
LODWORD(elements[8]) = 5;
HIDWORD(elements[8]) = 1;
LODWORD(elements[9]) = 1000000;
HIDWORD(elements[9]) = 15;
LODWORD(elements[10]) = 1;
HIDWORD(elements[10]) = 0;
LODWORD(elements[11]) = 0;
HIDWORD(elements[11]) = 0;
LODWORD(elements[12]) = 1000000;
HIDWORD(elements[12]) = 15;
}

original_code:
void loadElements(){
 Geometry_t geo = {
  .x = 10,
  .y = 5,
  .rad = 1
 };
 Actor_t actor = {
  .geo = geo,
  .dirMotion = 1,
  .alive = 1
 };
 Weapon_t pistol = { .ammo = 1000000, .rof = 15 };
 Crate_t crate = { .geo = geo, .weapon = pistol};
 Player_t player = {
  .geo = geo,
  .dirMotion = 1,
  .jumpTime = 0,
  .weapon = pistol,
  .score = 0
 };
 _elements.enemy = actor;
 _elements.bullet = actor;
 _elements.crate = crate;
 _elements.player = player;
 _elements.pistol = pistol;
}

canonical_original_code:
void loadElements(){
 struct Geometry_t geo = {
  .x = 10,
  .y = 5,
  .rad = 1
 };
 struct Actor_t actor = {
  .geo = geo,
  .dirMotion = 1,
  .alive = 1
 };
 struct Weapon_t pistol = { .ammo = 1000000, .rof = 15 };
 struct Crate_t crate = { .geo = geo, .weapon = pistol};
 struct Player_t player = {
  .geo = geo,
  .dirMotion = 1,
  .jumpTime = 0,
  .weapon = pistol,
  .score = 0
 };
 _elements.enemy = actor;
 _elements.bullet = actor;
 _elements.crate = crate;
 _elements.player = player;
 _elements.pistol = pistol;
}

variable_types:
geo
struct Geometry_t { int x; }

variable_types: struct Actor_t { struct Geometry_t { int x; } geo; int dirMotion; }

variable_types:
pistol
struct Weapon_t { int ammo; }

variable_types: struct Crate_t { struct Geometry_t { int x; } geo; struct Weapon_t { int ammo; } weapon; }

variable_types: struct Player_t { struct Geometry_t { int x; } geo; struct Weapon_t { int ammo; } weapon; int dirMotion; int reload; int jumpTime; int score; }

user_defined_types: struct Crate_t { struct Geometry_t geo; struct Weapon_t weapon; }

user_defined_types: struct Player_t { struct Geometry_t geo; struct Weapon_t weapon; int dirMotion; int reload; int jumpTime; int score; }


loadMessages

variable_types: struct Message_t { char *text; int display; struct Geometry_t { int x; } geo; }


config

decompiled_code:
__int64 config()
{
numEnemies = 0;
numBullets = 0;
gameLost = 0;
tickCount = 0;
loadMap();
loadElements();
loadWeapons();
loadMessages();
loadNumbers();
player = _mm_loadu_si128((const __m128i *)((char *)&elements[7] + 4));
*((__m128i *)&player + 1) = _mm_loadu_si128((const __m128i *)((char *)&elements[9] + 4));
*((_DWORD *)&player + 8) = HIDWORD(elements[11]);
crate = _mm_loadu_si128((const __m128i *)&elements[5]);
*((_DWORD *)&crate + 4) = elements[7];
keys[0] = 0;
keys[1] = 0;
keys[2] = 0;
keys[3] = 0;
resetCrate();
return audio("res/audio/themeGame.wav");
}

canonical_decompiled_code:
__int64 func4()
{
numEnemies = 0;
numBullets = 0;
gameLost = 0;
tickCount = 0;
loadMap();
func1();
func0();
func2();
func3();
player = _mm_loadu_si128((const __m128i *)((char *)&elements[7] + 4));
*((__m128i *)&player + 1) = _mm_loadu_si128((const __m128i *)((char *)&elements[9] + 4));
*((_DWORD *)&player + 8) = HIDWORD(elements[11]);
crate = _mm_loadu_si128((const __m128i *)&elements[5]);
*((_DWORD *)&crate + 4) = elements[7];
keys[0] = 0;
keys[1] = 0;
keys[2] = 0;
keys[3] = 0;
resetCrate();
return audio("res/audio/themeGame.wav");
}

original_code:
void config(){
 _numEnemies = 0;
 _numBullets = 0;
 _gameLost = 0;
 _tickCount = 0;
 loadMap();
 loadElements();
 loadWeapons();
 loadMessages();
 loadNumbers();
 _player = _elements.player;
 _crate = _elements.crate;
 Keys_t keys = { 0 };
 _keys = keys;
 resetCrate();
 audio("res/audio/" "themeGame.wav");
}

canonical_original_code:
void config(){
 _numEnemies = 0;
 _numBullets = 0;
 _gameLost = 0;
 _tickCount = 0;
 loadMap();
 loadElements();
 loadWeapons();
 loadMessages();
 loadNumbers();
 _player = _elements.player;
 _crate = _elements.crate;
 struct Keys_t keys = { 0 };
 _keys = keys;
 resetCrate();
 audio("res/audio/" "themeGame.wav");
}

variable_types:
keys
struct Keys_t { int up; int fire; }


abs

decompiled_code:
__int64 __fastcall abs(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return abs32(a1);
}

original_code:
int abs(int val){
 if(val < 0)
  return val * -1;
 return val;
}

variable_types: val int

return_type: int


collision

decompiled_code:
_BOOL8 __fastcall collision(__int64 a1, int a2, __int64 a3, int a4)
{
int v4; // ecx
_BOOL4 v5; // edx
int v7; // [rsp+0h] [rbp-20h]

v7 = a3;
v4 = a2 + a4;
LODWORD(a3) = 0;
if ( (int)abs32(HIDWORD(a1) - HIDWORD(a3) + 1) < v4 )
v5 = (int)abs32(a1 - v7 + 1) < v4;
return v5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, int a2, __int64 a3, int a4)
{
int v4; // ecx
_BOOL4 v5; // edx
int v7; // [rsp+0h] [rbp-20h]

v7 = a3;
v4 = a2 + a4;
LODWORD(a3) = 0;
if ( (int)abs32(HIDWORD(a1) - HIDWORD(a3) + 1) < v4 )
v5 = (int)abs32(a1 - v7 + 1) < v4;
return v5;
}

original_code:
int collision(Geometry_t g1, Geometry_t g2){
 int sumRad = g1.rad + g2.rad;
 return abs(g1.y - g2.y + 1) < sumRad && abs(g1.x - g2.x + 1) < sumRad;
}

canonical_original_code:
int collision(struct Geometry_t g1, struct Geometry_t g2){
 int sumRad = g1.rad + g2.rad;
 return abs(g1.y - g2.y + 1) < sumRad && abs(g1.x - g2.x + 1) < sumRad;
}

variable_types: sumRad int


onSurface

decompiled_code:
_BOOL8 __fastcall onSurface(__int64 a1)
{
return mapBuf[178 * (a1 >> 32) - 1 + (int)a1] == 64;
}

original_code:
int onSurface(Geometry_t geo) {
 return mapBuf[geo.y][geo.x - 1] == '@';
}

canonical_original_code:
int onSurface(struct Geometry_t geo) {
 return mapBuf[geo.y][geo.x - 1] == '@';
}


belowSurface

decompiled_code:
_BOOL8 __fastcall belowSurface(__int64 a1)
{
return mapBuf[178 * HIDWORD(a1) - 357 + (int)a1] == 64;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1)
{
return mapBuf[178 * HIDWORD(a1) - 357 + (int)a1] == 64;
}

original_code:
int belowSurface(Geometry_t geo) {
 return mapBuf[geo.y - 2][geo.x - 1] == '@';
}

canonical_original_code:
int belowSurface(struct Geometry_t geo) {
 return mapBuf[geo.y - 2][geo.x - 1] == '@';
}


clearKeys

decompiled_code:
void clearKeys()
{
keys[0] = 0;
keys[1] = 0;
keys[2] = 0;
keys[3] = 0;
}

original_code:
void clearKeys() {
 Keys_t keys = {0};
 _keys = keys;
}

canonical_original_code:
void clearKeys() {
 struct Keys_t keys = {0};
 _keys = keys;
}


expireActors

original_code:
void expireActors(Actor_t * actors, int * numAct) {
 int act;
 for(act = 0; act < *numAct; act++)
  if(!actors[act].alive) {
   int shift;
   for(shift = act; shift <= *numAct; shift++)
    actors[shift] = actors[shift + 1];
   (*numAct)--;
  }
}

canonical_original_code:
void expireActors(struct Actor_t *actors, int *numAct) {
 int act;
 for(act = 0; act < *numAct; act++)
  if(!actors[act].alive) {
   int shift;
   for(shift = act; shift <= *numAct; shift++)
    actors[shift] = actors[shift + 1];
   (*numAct)--;
  }
}

variable_types: struct Actor_t { struct Geometry_t { int x; } geo; int dirMotion; } *

variable_types:
numAct
int *

variable_types: act int

variable_types: shift int


gravity

decompiled_code:
__int64 gravity()
{
__int64 result; // rax
int v1; // eax

result = (unsigned int)(3 * (tickCount / 3));
if ( tickCount == (_DWORD)result )
{
if ( belowSurface(player) )
{
*((_DWORD *)&player + 7) = 0;
}
else
{
v1 = *((_DWORD *)&player + 7);
if ( v1 )
{
--*((_DWORD *)&player + 1);
result = (unsigned int)(v1 - 1);
*((_DWORD *)&player + 7) = result;
return result;
}
}
result = onSurface(player);
if ( !(_DWORD)result )
++*((_DWORD *)&player + 1);
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax
int v1; // eax

result = (unsigned int)(3 * (tickCount / 3));
if ( tickCount == (_DWORD)result )
{
if ( func8(player) )
{
*((_DWORD *)&player + 7) = 0;
}
else
{
v1 = *((_DWORD *)&player + 7);
if ( v1 )
{
--*((_DWORD *)&player + 1);
result = (unsigned int)(v1 - 1);
*((_DWORD *)&player + 7) = result;
return result;
}
}
result = func7(player);
if ( !(_DWORD)result )
++*((_DWORD *)&player + 1);
}
return result;
}

original_code:
void gravity() {
 if(_tickCount % 3 == 0) {
  if(belowSurface(_player.geo))
   _player.jumpTime = 0;
  if(_player.jumpTime) {
   _player.geo.y -= 1;
   _player.jumpTime -= 1;
  } else if(!onSurface(_player.geo)) {
   _player.geo.y += 1;
  }
 }
}


decompiled_code:
void *__fastcall readlink_malloc(char *path)
{
size_t v1; // rbp
void *v2; // rbx
int v4; // eax

v1 = 10LL;
v2 = 0LL;
while ( 1 )
{
v2 = realloc(v2, v1);
v4 = readlink(path, (char *)v2, v1);
if ( v4 < 0 )
break;
if ( v4 < (int)v1 )
return v2;
v1 += 10LL;
}
free(v2);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(char *path)
{
size_t v1; // rbp
void *v2; // rbx
int v4; // eax

v1 = 10LL;
v2 = 0LL;
while ( 1 )
{
v2 = realloc(v2, v1);
v4 = readlink(path, (char *)v2, v1);
if ( v4 < 0 )
break;
if ( v4 < (int)v1 )
return v2;
v1 += 10LL;
}
free(v2);
return 0LL;
}

original_code:
char *readlink_malloc(const char *filename)
{
    int size = 10;
    char *buffer = ((void *)0);
    while(1)
    {
        buffer = (char*) realloc(buffer, size);
        int nchars = readlink(filename, buffer, size);
        if(nchars < 0)
        {
            free(buffer);
            return ((void *)0);
        }
        if(nchars < size)
            return buffer;
        size += 10;
    }
}

canonical_original_code:
char *readlink_malloc(char *filename)
{
    int size = 10;
    char *buffer = ((void *)0);
    while(1)
    {
        buffer = (char *) realloc(buffer, size);
        int nchars = readlink(filename, buffer, size);
        if(nchars < 0)
        {
            free(buffer);
            return ((void *)0);
        }
        if(nchars < size)
            return buffer;
        size += 10;
    }
}

variable_types:
filename
char *

variable_types: size int

variable_types:
buffer
char *

variable_types: nchars int

return_type: char *


decompiled_code:
__int64 __fastcall create_spk(const char *a1, int a2, const char **a3)
{
return create_spk_ex(a1, a2, a3, 0LL, 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2, const char **a3)
{
return func1(a1, a2, a3, 0LL, 0, 0);
}

original_code:
short create_spk(char *outfile, int inlen, char *in[])
{
    return create_spk_ex(outfile, inlen, in, 0, 0, 0);
}

variable_types:
outfile
char *

variable_types: inlen int

variable_types:
in
char *[]

return_type: short


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int result; // eax
const char *v5; // rbp
_QWORD *v6; // rax
_QWORD *v7; // r13
const char **v8; // r14
const char **v9; // r15
const char *v10; // rbx
const char *v11; // rax
__int64 v12; // rax
int v13; // er14
unsigned int v14; // er14
_QWORD *v15; // r12
_QWORD *v16; // rbx
void *v17; // rdi
__int16 v18; // bx
const char *v19; // rax
__int16 v20; // ax
const char *v21; // rax
char v22; // dl
char v23; // [rsp+4h] [rbp-44h]
unsigned __int8 v24; // [rsp+8h] [rbp-40h]
bool v25; // [rsp+Fh] [rbp-39h]

if ( argc <= 2 )
{
LABEL_3:
print_usage();
result = 0;
}
else
{
v25 = strchr(argv[1], 118) != 0LL;
v3 = 2LL;
v23 = 0;
v24 = 0;
while ( 1 )
{
v5 = argv[v3];
if ( *v5 != 45 )
break;
if ( !strcmp(argv[v3], "--no-uid-gid") )
{
v24 = 1;
}
else if ( !strcmp(argv[v3], "--no-mode") )
{
v23 = 1;
}
else
{
fprintf(stderr, "Unknown argument %s\n", argv[v3]);
}
if ( ++v3 == argc )
{
fwrite("No archive specified\n", 1uLL, 0x15uLL, stderr);
return 1;
}
}
v22 = *argv[1];
if ( v22 == 99 )
{
if ( argc <= 3 )
goto LABEL_3;
v6 = malloc(0x10uLL);
v7 = v6;
if ( !v6 )
goto LABEL_16;
v6[1] = 0LL;
*v6 = 0LL;
if ( argc <= (int)v3 + 1 )
{
v13 = 0;
}
else
{
v8 = &argv[(int)v3 + 1];
v9 = &(&argv[(unsigned int)(argc - 2 - v3)])[(__int64)(int)v3 + 2];
do
{
v10 = *v8;
v11 = &v10[strlen(*v8) - 1];
if ( *v11 == 47 )
*v11 = 0;
recursive_add_to_array(v7, *v8++);
}
while ( v8 != v9 );
v12 = v7[1];
if ( v12 )
{
v13 = 0;
do
{
++v13;
v12 = *(_QWORD *)(v12 + 8);
}
while ( v12 );
}
else
{
v13 = 0;
}
}
v14 = v13 + 1;
v15 = malloc(8LL * (int)v14);
v16 = v15;
if ( !v15 )
{
LABEL_16:
fwrite("Not enough memory available\n", 1uLL, 0x1CuLL, stderr);
return 1;
}
do
{
*v16 = *v7;
v17 = v7;
v7 = (_QWORD *)v7[1];
free(v17);
++v16;
}
while ( v7 );
v18 = create_spk_ex(v5, v14, v15, v25, v24 & 1, v23 & 1);
free(v15);
if ( v18 )
{
v19 = (const char *)strerror_spk((unsigned int)v18);
fprintf(stderr, "%s\n", v19);
}
}
else if ( v22 == 120 )
{
v20 = extract_spk_ex(argv[v3], ".", v25, v24, v23 & 1);
v18 = v20;
if ( v20 )
{
v21 = (const char *)strerror_spk((unsigned int)v20);
fprintf(stderr, "%s\n", v21);
}
}
else
{
fprintf(stderr, "Unknown operation %c\n", (unsigned int)v22);
v18 = 1;
}
result = v18 != 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int result; // eax
const char *v5; // rbp
_QWORD *v6; // rax
_QWORD *v7; // r13
const char **v8; // r14
const char **v9; // r15
const char *v10; // rbx
const char *v11; // rax
__int64 v12; // rax
int v13; // er14
unsigned int v14; // er14
_QWORD *v15; // r12
_QWORD *v16; // rbx
void *v17; // rdi
__int16 v18; // bx
const char *v19; // rax
__int16 v20; // ax
const char *v21; // rax
char v22; // dl
char v23; // [rsp+4h] [rbp-44h]
unsigned __int8 v24; // [rsp+8h] [rbp-40h]
bool v25; // [rsp+Fh] [rbp-39h]

if ( argc <= 2 )
{
LABEL_3:
func2();
result = 0;
}
else
{
v25 = strchr(argv[1], 118) != 0LL;
v3 = 2LL;
v23 = 0;
v24 = 0;
while ( 1 )
{
v5 = argv[v3];
if ( *v5 != 45 )
break;
if ( !strcmp(argv[v3], "--no-uid-gid") )
{
v24 = 1;
}
else if ( !strcmp(argv[v3], "--no-mode") )
{
v23 = 1;
}
else
{
fprintf(stderr, "Unknown argument %s\n", argv[v3]);
}
if ( ++v3 == argc )
{
fwrite("No archive specified\n", 1uLL, 0x15uLL, stderr);
return 1;
}
}
v22 = *argv[1];
if ( v22 == 99 )
{
if ( argc <= 3 )
goto LABEL_3;
v6 = malloc(0x10uLL);
v7 = v6;
if ( !v6 )
goto LABEL_16;
v6[1] = 0LL;
*v6 = 0LL;
if ( argc <= (int)v3 + 1 )
{
v13 = 0;
}
else
{
v8 = &argv[(int)v3 + 1];
v9 = &(&argv[(unsigned int)(argc - 2 - v3)])[(__int64)(int)v3 + 2];
do
{
v10 = *v8;
v11 = &v10[strlen(*v8) - 1];
if ( *v11 == 47 )
*v11 = 0;
func1(v7, *v8++);
}
while ( v8 != v9 );
v12 = v7[1];
if ( v12 )
{
v13 = 0;
do
{
++v13;
v12 = *(_QWORD *)(v12 + 8);
}
while ( v12 );
}
else
{
v13 = 0;
}
}
v14 = v13 + 1;
v15 = malloc(8LL * (int)v14);
v16 = v15;
if ( !v15 )
{
LABEL_16:
fwrite("Not enough memory available\n", 1uLL, 0x1CuLL, stderr);
return 1;
}
do
{
*v16 = *v7;
v17 = v7;
v7 = (_QWORD *)v7[1];
free(v17);
++v16;
}
while ( v7 );
v18 = create_spk_ex(v5, v14, v15, v25, v24 & 1, v23 & 1);
free(v15);
if ( v18 )
{
v19 = (const char *)strerror_spk((unsigned int)v18);
fprintf(stderr, "%s\n", v19);
}
}
else if ( v22 == 120 )
{
v20 = extract_spk_ex(argv[v3], ".", v25, v24, v23 & 1);
v18 = v20;
if ( v20 )
{
v21 = (const char *)strerror_spk((unsigned int)v20);
fprintf(stderr, "%s\n", v21);
}
}
else
{
fprintf(stderr, "Unknown operation %c\n", (unsigned int)v22);
v18 = 1;
}
result = v18 != 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    short co = 1;
    if(argc < 3)
    {
        print_usage();
        return 0;
    }
    else
    {
        _Bool verbose = (strchr(argv[1], 'v') != ((void *)0));
        _Bool no_gid_uid = 0, no_mode = 0;
        int i, archiven;
        char *archivep = ((void *)0);
        for(i = 2; i < argc; i++)
        {
            if(argv[i][0] != '-')
            {
                archivep = argv[i];
                archiven = i;
                break;
            }
            if(!strcmp(argv[i], "--no-uid-gid")) { no_gid_uid = 1; continue; }
            if(!strcmp(argv[i], "--no-mode")) { no_mode = 1; continue; }
            fprintf(stderr, "Unknown argument %s\n", argv[i]);
        }
        if(archivep == ((void *)0)) { fprintf(stderr, "No archive specified\n"); return 1; }
        switch(argv[1][0])
        {
            case 'c':
                if(argc < 4)
                {
                    print_usage();
                    return 0;
                }
                int i, len;
                ll_node *in, *cur, *tmp;
                char **arr;
                in = malloc(sizeof(ll_node));
                if(in == ((void *)0))
                {
                    fprintf(stderr, "Not enough memory available\n");
                    return 1;
                }
                in->next = ((void *)0);
                in->v = (const char*) ((void *)0);
                for(i = archiven + 1; i < argc; i++)
                {
                    if(argv[i][strlen(argv[i]) - 1] == '/') argv[i][strlen(argv[i]) - 1] = 0;
                    recursive_add_to_array(in, argv[i]);
                }
                cur = in;
                len = 0;
                while((cur = cur->next) != ((void *)0))
                    len++;
                len++;
                arr = malloc(len * sizeof(char*));
                if(arr == ((void *)0))
                {
                    fprintf(stderr, "Not enough memory available\n");
                    return 1;
                }
                cur = in;
                i = 0;
                while(cur != ((void *)0))
                {
                    arr[i] = (char*) cur->v;
                    i++;
                    tmp = cur;
                    cur = cur->next;
                    free(tmp);
                }
                co = create_spk_ex(archivep, len, arr, verbose, no_gid_uid, no_mode);
                free(arr);
                if(co != 0x00) fprintf(stderr, "%s\n", strerror_spk(co));
                break;
            case 'x':
                co = extract_spk_ex(archivep, ".", verbose, no_gid_uid, no_mode);
                if(co != 0x00) fprintf(stderr, "%s\n", strerror_spk(co));
                break;
            default:
                fprintf(stderr, "Unknown operation %c\n", argv[1][0]);
                break;
        }
    }
    return (co == 0x00)?0:1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    short co = 1;
    if(argc < 3)
    {
        print_usage();
        return 0;
    }
    else
    {
        _Bool verbose = (strchr(argv[1], 'v') != ((void *)0));
        _Bool no_gid_uid = 0; _Bool no_mode = 0;
        int i; int archiven;
        char *archivep = ((void *)0);
        for(i = 2; i < argc; i++)
        {
            if(argv[i][0] != '-')
            {
                archivep = argv[i];
                archiven = i;
                break;
            }
            if(!strcmp(argv[i], "--no-uid-gid")) { no_gid_uid = 1; continue; }
            if(!strcmp(argv[i], "--no-mode")) { no_mode = 1; continue; }
            fprintf(stderr, "Unknown argument %s\n", argv[i]);
        }
        if(archivep == ((void *)0)) { fprintf(stderr, "No archive specified\n"); return 1; }
        switch(argv[1][0])
        {
            case 'c':
                if(argc < 4)
                {
                    print_usage();
                    return 0;
                }
                int i; int len;
                struct ll_node *in; struct ll_node *cur; struct ll_node *tmp;
                char **arr;
                in = malloc(sizeof(ll_node));
                if(in == ((void *)0))
                {
                    fprintf(stderr, "Not enough memory available\n");
                    return 1;
                }
                in->next = ((void *)0);
                in->v = (char *) ((void *)0);
                for(i = archiven + 1; i < argc; i++)
                {
                    if(argv[i][strlen(argv[i]) - 1] == '/') argv[i][strlen(argv[i]) - 1] = 0;
                    recursive_add_to_array(in, argv[i]);
                }
                cur = in;
                len = 0;
                while((cur = cur->next) != ((void *)0))
                    len++;
                len++;
                arr = malloc(len * sizeof(char *));
                if(arr == ((void *)0))
                {
                    fprintf(stderr, "Not enough memory available\n");
                    return 1;
                }
                cur = in;
                i = 0;
                while(cur != ((void *)0))
                {
                    arr[i] = (char *) cur->v;
                    i++;
                    tmp = cur;
                    cur = cur->next;
                    free(tmp);
                }
                co = create_spk_ex(archivep, len, arr, verbose, no_gid_uid, no_mode);
                free(arr);
                if(co != 0x00) fprintf(stderr, "%s\n", strerror_spk(co));
                break;
            case 'x':
                co = extract_spk_ex(archivep, ".", verbose, no_gid_uid, no_mode);
                if(co != 0x00) fprintf(stderr, "%s\n", strerror_spk(co));
                break;
            default:
                fprintf(stderr, "Unknown operation %c\n", argv[1][0]);
                break;
        }
    }
    return (co == 0x00)?0:1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: co short

variable_types: i int

variable_types: archiven int

variable_types:
archivep
char *

variable_types: len int

variable_types: struct ll_node { char *v; struct ll_node *next; } *

variable_types:
arr
char **


decompiled_code:
__int64 __fastcall extract_spk(char *a1, const char *a2)
{
return extract_spk_ex(a1, a2, 0, 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, const char *a2)
{
return func0(a1, a2, 0, 0, 0);
}

original_code:
short extract_spk(char *filename, char *outdir)
{
    return extract_spk_ex(filename, outdir, 0, 0, 0);
}

variable_types:
outdir
char *


stringtodouble

repo: sfeek/ballistics

decompiled_code:
__int64 __fastcall stringtodouble(char *nptr, double *a2)
{
int *v2; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = _errno_location();
*v2 = 0;
*a2 = strtod(nptr, &endptr);
if ( *v2 == 34 )
{
puts("\nNumber Overflow/Underflow Error!");
result = 1LL;
}
else
{
result = 0LL;
if ( endptr == nptr )
{
puts("\nInvalid Number Conversion Error!");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *nptr, double *a2)
{
int *v2; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = _errno_location();
*v2 = 0;
*a2 = strtod(nptr, &endptr);
if ( *v2 == 34 )
{
puts("\nNumber Overflow/Underflow Error!");
result = 1LL;
}
else
{
result = 0LL;
if ( endptr == nptr )
{
puts("\nInvalid Number Conversion Error!");
result = 1LL;
}
}
return result;
}

original_code:
int stringtodouble (const char *str, double *v)
{
 char *ptr;
 (*__errno_location ()) = 0;
 *v = strtod (str, &ptr);
 if ((*__errno_location ()) == 34)
 {
  printf ("\nNumber Overflow/Underflow Error!\n");
  return 1;
 }
 if (str == ptr)
 {
  printf ("\nInvalid Number Conversion Error!\n");
  return 1;
 }
 return 0;
}

canonical_original_code:
int stringtodouble(char *str, double *v)
{
 char *ptr;
 (*__errno_location ()) = 0;
 *v = strtod (str, &ptr);
 if ((*__errno_location ()) == 34)
 {
  printf ("\nNumber Overflow/Underflow Error!\n");
  return 1;
 }
 if (str == ptr)
 {
  printf ("\nInvalid Number Conversion Error!\n");
  return 1;
 }
 return 0;
}

variable_types:
str
char *

variable_types:
v
double *

variable_types:
ptr
char *


stringtoint

decompiled_code:
__int64 __fastcall stringtoint(char *nptr, _DWORD *a2)
{
int *v2; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = _errno_location();
*v2 = 0;
*a2 = strtol(nptr, &endptr, 10);
if ( *v2 == 34 )
{
puts("\nNumber Overflow/Underflow Error!");
result = 1LL;
}
else
{
result = 0LL;
if ( endptr == nptr )
{
puts("\nInvalid Number Conversion Error!");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr, _DWORD *a2)
{
int *v2; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = _errno_location();
*v2 = 0;
*a2 = strtol(nptr, &endptr, 10);
if ( *v2 == 34 )
{
puts("\nNumber Overflow/Underflow Error!");
result = 1LL;
}
else
{
result = 0LL;
if ( endptr == nptr )
{
puts("\nInvalid Number Conversion Error!");
result = 1LL;
}
}
return result;
}

original_code:
int stringtoint (const char *str, int *v)
{
 char *ptr;
 (*__errno_location ()) = 0;
 *v = (int) strtol (str, &ptr, 10);
 if ((*__errno_location ()) == 34)
 {
  printf ("\nNumber Overflow/Underflow Error!\n");
  return 1;
 }
 if (str == ptr)
 {
  printf ("\nInvalid Number Conversion Error!\n");
  return 1;
 }
 return 0;
}

canonical_original_code:
int stringtoint(char *str, int *v)
{
 char *ptr;
 (*__errno_location ()) = 0;
 *v = (int) strtol (str, &ptr, 10);
 if ((*__errno_location ()) == 34)
 {
  printf ("\nNumber Overflow/Underflow Error!\n");
  return 1;
 }
 if (str == ptr)
 {
  printf ("\nInvalid Number Conversion Error!\n");
  return 1;
 }
 return 0;
}

variable_types:
v
int *


getdouble

decompiled_code:
double __fastcall getdouble(const char *a1)
{
char *v1; // rbx
int v2; // ebp
double v4[4]; // [rsp+8h] [rbp-20h] BYREF

do
{
v1 = getstring(a1);
v2 = stringtodouble(v1, v4);
free(v1);
}
while ( v2 );
return v4[0];
}

canonical_decompiled_code:
double __fastcall func2(const char *a1)
{
char *v1; // rbx
int v2; // ebp
double v4[4]; // [rsp+8h] [rbp-20h] BYREF

do
{
v1 = getstring(a1);
v2 = func0(v1, v4);
free(v1);
}
while ( v2 );
return v4[0];
}

original_code:
double getdouble (const char *display)
{
 char *buffer;
 double value;
 int rtn;
 while (1)
 {
  buffer = getstring (display);
  rtn = stringtodouble (buffer, &value);
  free (buffer);
  if (rtn == 0)
   return value;
 }
}

canonical_original_code:
double getdouble(char *display)
{
 char *buffer;
 double value;
 int rtn;
 while (1)
 {
  buffer = getstring (display);
  rtn = stringtodouble (buffer, &value);
  free (buffer);
  if (rtn == 0)
   return value;
 }
}

variable_types:
display
char *

variable_types:
buffer
char *

variable_types: value double

variable_types: rtn int

return_type: double


getint

decompiled_code:
__int64 __fastcall getint(const char *a1)
{
char *v1; // rbx
int v2; // ebp
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

do
{
v1 = getstring(a1);
v2 = stringtoint(v1, v4);
free(v1);
}
while ( v2 );
return v4[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char *v1; // rbx
int v2; // ebp
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

do
{
v1 = getstring(a1);
v2 = func1(v1, v4);
free(v1);
}
while ( v2 );
return v4[0];
}

original_code:
int getint (const char *display)
{
 char *buffer;
 int value;
 int rtn;
 while (1)
 {
  buffer = getstring (display);
  rtn = stringtoint (buffer, &value);
  free (buffer);
  if (rtn == 0)
   return value;
 }
}

canonical_original_code:
int getint(char *display)
{
 char *buffer;
 int value;
 int rtn;
 while (1)
 {
  buffer = getstring (display);
  rtn = stringtoint (buffer, &value);
  free (buffer);
  if (rtn == 0)
   return value;
 }
}

variable_types: value int


repo: sfeek/plogger

decompiled_code:
void signal_handler_IO()
{
wait_flag = 0;
}

canonical_decompiled_code:
void func7()
{
wait_flag = 0;
}

original_code:
void signal_handler_IO (int status)
{
 wait_flag = 0;
}

canonical_original_code:
void signal_handler_IO(int status)
{
 wait_flag = 0;
}

variable_types: status int


getkey

decompiled_code:
__int64 getkey()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
struct termios v5; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

v0 = fileno(stdin);
tcgetattr(v0, &termios_p);
*(__m128i *)&v5.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v5.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v5.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v5.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v5.c_ospeed = termios_p.c_ospeed;
v5.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v5.c_cc[5] = 0;
v1 = fileno(stdin);
tcsetattr(v1, 0, &v5);
v2 = fgetc(stdin);
v3 = fileno(stdin);
tcsetattr(v3, 0, &termios_p);
return v2;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
struct termios v5; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

v0 = fileno(stdin);
tcgetattr(v0, &termios_p);
*(__m128i *)&v5.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v5.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v5.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v5.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v5.c_ospeed = termios_p.c_ospeed;
v5.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v5.c_cc[5] = 0;
v1 = fileno(stdin);
tcsetattr(v1, 0, &v5);
v2 = fgetc(stdin);
v3 = fileno(stdin);
tcsetattr(v3, 0, &termios_p);
return v2;
}

original_code:
int getkey()
{
 int character;
 struct termios orig_term_attr;
 struct termios new_term_attr;
 tcgetattr (fileno (stdin), &orig_term_attr);
 memcpy (&new_term_attr, &orig_term_attr, sizeof (struct termios));
 new_term_attr.c_lflag &= ~ (0000010 | 0000002);
 new_term_attr.c_cc[5] = 0;
 new_term_attr.c_cc[6] = 0;
 tcsetattr (fileno (stdin), 0, &new_term_attr);
 character = fgetc (stdin);
 tcsetattr (fileno (stdin), 0, &orig_term_attr);
 return character;
}

variable_types: character int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


stringtodouble

repo: sfeek/rfassistant


showfrequency

original_code:
void showfrequency (double v)
{
 double a = fabs (v);
 if (a >= 1e9)
 {
  printf ("%3.3f GHz", v / 1e9);
  return;
 }
 if (a >= 1e6)
 {
  printf ("%3.3f MHz", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KHz", v / 1e3);
  return;
 }
 printf ("%3.3f Hz", v);
 return;
}

canonical_original_code:
void showfrequency(double v)
{
 double a = fabs (v);
 if (a >= 1e9)
 {
  printf ("%3.3f GHz", v / 1e9);
  return;
 }
 if (a >= 1e6)
 {
  printf ("%3.3f MHz", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KHz", v / 1e3);
  return;
 }
 printf ("%3.3f Hz", v);
 return;
}

variable_types: v double

variable_types: a double


showcapacitance

original_code:
void showcapacitance (double v)
{
 double a = fabs (v);
 if (a >= 1e0)
 {
  printf ("%3.3f F", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mF", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μF", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nF", v / 1e-9);
  return;
 }
 if (a >= 1e-12)
 {
  printf ("%3.3f pF", v / 1e-12);
  return;
 }
 printf ("%e F", v);
 return;
}

canonical_original_code:
void showcapacitance(double v)
{
 double a = fabs (v);
 if (a >= 1e0)
 {
  printf ("%3.3f F", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mF", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μF", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nF", v / 1e-9);
  return;
 }
 if (a >= 1e-12)
 {
  printf ("%3.3f pF", v / 1e-12);
  return;
 }
 printf ("%e F", v);
 return;
}


showinductance

original_code:
void showinductance (double v)
{
 double a = fabs (v);
 if (a >= 1e0)
 {
  printf ("%3.3f H", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mH", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μH", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nH", v / 1e-9);
  return;
 }
 if (a >= 1e-12)
 {
  printf ("%3.3f pH", v / 1e-12);
  return;
 }
 printf ("%e H", v);
 return;
}

canonical_original_code:
void showinductance(double v)
{
 double a = fabs (v);
 if (a >= 1e0)
 {
  printf ("%3.3f H", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mH", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μH", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nH", v / 1e-9);
  return;
 }
 if (a >= 1e-12)
 {
  printf ("%3.3f pH", v / 1e-12);
  return;
 }
 printf ("%e H", v);
 return;
}


showresistance

original_code:
void showresistance (double v)
{
 double a = fabs (v);
 if (a >= 1e9)
 {
  printf ("%3.3f GΩ", v / 1e9);
  return;
 }
 if (a >= 1e6)
 {
  printf ("%3.3f MΩ", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KΩ", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f Ω ", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mΩ", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μΩ", v / 1e-6);
  return;
 }
 printf ("%e Ω", v);
 return;
}

canonical_original_code:
void showresistance(double v)
{
 double a = fabs (v);
 if (a >= 1e9)
 {
  printf ("%3.3f GΩ", v / 1e9);
  return;
 }
 if (a >= 1e6)
 {
  printf ("%3.3f MΩ", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KΩ", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f Ω ", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mΩ", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μΩ", v / 1e-6);
  return;
 }
 printf ("%e Ω", v);
 return;
}


showpower

original_code:
void showpower (double v)
{
 double a = fabs (v);
 if (a >= 1e9)
 {
  printf ("%3.3f GW", v / 1e9);
  return;
 }
 if (a >= 1e6)
 {
  printf ("%3.3f MW", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KW", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f W", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mW", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μW", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nW", v / 1e-9);
  return;
 }
 if (a >= 1e-12)
 {
  printf ("%3.3f pW", v / 1e-12);
  return;
 }
 printf ("%e W", v);
 return;
}

canonical_original_code:
void showpower(double v)
{
 double a = fabs (v);
 if (a >= 1e9)
 {
  printf ("%3.3f GW", v / 1e9);
  return;
 }
 if (a >= 1e6)
 {
  printf ("%3.3f MW", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KW", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f W", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mW", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μW", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nW", v / 1e-9);
  return;
 }
 if (a >= 1e-12)
 {
  printf ("%3.3f pW", v / 1e-12);
  return;
 }
 printf ("%e W", v);
 return;
}


showvoltage

original_code:
void showvoltage (double v)
{
 double a = fabs (v);
 if (a >= 1e6)
 {
  printf ("%3.3f MV", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KV", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f V", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mV", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μV", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nV", v / 1e-9);
  return;
 }
 printf ("%e V", v);
 return;
}

canonical_original_code:
void showvoltage(double v)
{
 double a = fabs (v);
 if (a >= 1e6)
 {
  printf ("%3.3f MV", v / 1e6);
  return;
 }
 if (a >= 1e3)
 {
  printf ("%3.3f KV", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f V", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mV", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μV", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nV", v / 1e-9);
  return;
 }
 printf ("%e V", v);
 return;
}


showamperage

original_code:
void showamperage (double v)
{
 double a = fabs (v);
 if (a >= 1e3)
 {
  printf ("%3.3f KA", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f A", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mA", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μA", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nA", v / 1e-9);
  return;
 }
 printf ("%e A", v);
 return;
}

canonical_original_code:
void showamperage(double v)
{
 double a = fabs (v);
 if (a >= 1e3)
 {
  printf ("%3.3f KA", v / 1e3);
  return;
 }
 if (a >= 1e0)
 {
  printf ("%3.3f A", v);
  return;
 }
 if (a >= 1e-3)
 {
  printf ("%3.3f mA", v / 1e-3);
  return;
 }
 if (a >= 1e-6)
 {
  printf ("%3.3f μA", v / 1e-6);
  return;
 }
 if (a >= 1e-9)
 {
  printf ("%3.3f nA", v / 1e-9);
  return;
 }
 printf ("%e A", v);
 return;
}


getfrequency

decompiled_code:
double __fastcall getfrequency(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx
int v3; // eax

while ( 1 )
{
v1 = getdouble(a1);
v2 = v1;
v3 = getint("\n1)Hz 2)KHz 3)MHz 4)GHz : ");
if ( v3 == 3 )
break;
if ( v3 > 3 )
{
if ( v3 == 4 )
return v1 * 1000000000.0;
}
else
{
if ( v3 == 1 )
return v2;
if ( v3 == 2 )
return v1 * 1000.0;
}
}
return v1 * 1000000.0;
}

canonical_decompiled_code:
double __fastcall func11(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx
int v3; // eax

while ( 1 )
{
v1 = func2(a1);
v2 = v1;
v3 = func3("\n1)Hz 2)KHz 3)MHz 4)GHz : ");
if ( v3 == 3 )
break;
if ( v3 > 3 )
{
if ( v3 == 4 )
return v1 * 1000000000.0;
}
else
{
if ( v3 == 1 )
return v2;
if ( v3 == 2 )
return v1 * 1000.0;
}
}
return v1 * 1000000.0;
}

original_code:
double getfrequency (const char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)Hz  2)KHz  3)MHz  4)GHz : ");
  switch (i)
  {
   case 1:
    return v;
   case 2:
    return v * 1e3;
   case 3:
    return v * 1e6;
   case 4:
    return v * 1e9;
  }
 }
}

canonical_original_code:
double getfrequency(char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)Hz  2)KHz  3)MHz  4)GHz : ");
  switch (i)
  {
   case 1:
    return v;
   case 2:
    return v * 1e3;
   case 3:
    return v * 1e6;
   case 4:
    return v * 1e9;
  }
 }
}

variable_types: i int


getcapacitance

decompiled_code:
double __fastcall getcapacitance(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = getdouble(a1);
v2 = v1;
switch ( (unsigned int)getint(a1F2Mf3) )
{
case 1u:
return v2;
case 2u:
v2 = v1 * 0.001;
break;
case 3u:
v2 = v1 * 0.000001;
break;
case 4u:
v2 = v1 * 0.000000001;
break;
case 5u:
v2 = v1 * 1.0e-12;
break;
default:
continue;
}
break;
}
return v2;
}

canonical_decompiled_code:
double __fastcall func12(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = func2(a1);
v2 = v1;
switch ( (unsigned int)func3(a1F2Mf3) )
{
case 1u:
return v2;
case 2u:
v2 = v1 * 0.001;
break;
case 3u:
v2 = v1 * 0.000001;
break;
case 4u:
v2 = v1 * 0.000000001;
break;
case 5u:
v2 = v1 * 1.0e-12;
break;
default:
continue;
}
break;
}
return v2;
}

original_code:
double getcapacitance (const char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)F  2)mF  3)μF  4)nF  5)pF : ");
  switch (i)
  {
   case 1:
    return v;
   case 2:
    return v * 1e-3;
   case 3:
    return v * 1e-6;
   case 4:
    return v * 1e-9;
   case 5:
    return v * 1e-12;
  }
 }
}

canonical_original_code:
double getcapacitance(char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)F  2)mF  3)μF  4)nF  5)pF : ");
  switch (i)
  {
   case 1:
    return v;
   case 2:
    return v * 1e-3;
   case 3:
    return v * 1e-6;
   case 4:
    return v * 1e-9;
   case 5:
    return v * 1e-12;
  }
 }
}


getinductance

decompiled_code:
double __fastcall getinductance(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = getdouble(a1);
v2 = v1;
switch ( (unsigned int)getint(a1H2Mh3) )
{
case 1u:
return v2;
case 2u:
v2 = v1 * 0.001;
break;
case 3u:
v2 = v1 * 0.000001;
break;
case 4u:
v2 = v1 * 0.000000001;
break;
case 5u:
v2 = v1 * 1.0e-12;
break;
default:
continue;
}
break;
}
return v2;
}

canonical_decompiled_code:
double __fastcall func13(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = func2(a1);
v2 = v1;
switch ( (unsigned int)func3(a1H2Mh3) )
{
case 1u:
return v2;
case 2u:
v2 = v1 * 0.001;
break;
case 3u:
v2 = v1 * 0.000001;
break;
case 4u:
v2 = v1 * 0.000000001;
break;
case 5u:
v2 = v1 * 1.0e-12;
break;
default:
continue;
}
break;
}
return v2;
}

original_code:
double getinductance (const char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)H  2)mH  3)μH  4)nH  5)pH : ");
  switch (i)
  {
   case 1:
    return v;
   case 2:
    return v * 1e-3;
   case 3:
    return v * 1e-6;
   case 4:
    return v * 1e-9;
   case 5:
    return v * 1e-12;
  }
 }
}

canonical_original_code:
double getinductance(char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)H  2)mH  3)μH  4)nH  5)pH : ");
  switch (i)
  {
   case 1:
    return v;
   case 2:
    return v * 1e-3;
   case 3:
    return v * 1e-6;
   case 4:
    return v * 1e-9;
   case 5:
    return v * 1e-12;
  }
 }
}


getresistance

decompiled_code:
double __fastcall getresistance(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx
int v3; // eax

while ( 1 )
{
v1 = getdouble(a1);
v2 = v1;
v3 = getint(a1M);
if ( v3 == 3 )
break;
if ( v3 > 3 )
{
if ( v3 == 4 )
return v1 * 0.001;
}
else
{
if ( v3 == 1 )
return v1 * 1000000.0;
if ( v3 == 2 )
return v1 * 1000.0;
}
}
return v2;
}

canonical_decompiled_code:
double __fastcall func14(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx
int v3; // eax

while ( 1 )
{
v1 = func2(a1);
v2 = v1;
v3 = func3(a1M);
if ( v3 == 3 )
break;
if ( v3 > 3 )
{
if ( v3 == 4 )
return v1 * 0.001;
}
else
{
if ( v3 == 1 )
return v1 * 1000000.0;
if ( v3 == 2 )
return v1 * 1000.0;
}
}
return v2;
}

original_code:
double getresistance (const char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)MΩ  2)KΩ  3)Ω  4)mΩ : ");
  switch (i)
  {
   case 1:
    return v * 1e6;
   case 2:
    return v * 1e3;
   case 3:
    return v;
   case 4:
    return v * 1e-3;
  }
 }
}

canonical_original_code:
double getresistance(char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)MΩ  2)KΩ  3)Ω  4)mΩ : ");
  switch (i)
  {
   case 1:
    return v * 1e6;
   case 2:
    return v * 1e3;
   case 3:
    return v;
   case 4:
    return v * 1e-3;
  }
 }
}


getpower

decompiled_code:
double __fastcall getpower(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = getdouble(a1);
v2 = v1;
switch ( (unsigned int)getint(a1Mw2Kw3W4Mw5) )
{
case 1u:
v2 = v1 * 1000000.0;
break;
case 2u:
v2 = v1 * 1000.0;
break;
case 3u:
return v2;
case 4u:
v2 = v1 * 0.001;
break;
case 5u:
v2 = v1 * 0.000001;
break;
default:
continue;
}
break;
}
return v2;
}

canonical_decompiled_code:
double __fastcall func15(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = func2(a1);
v2 = v1;
switch ( (unsigned int)func3(a1Mw2Kw3W4Mw5) )
{
case 1u:
v2 = v1 * 1000000.0;
break;
case 2u:
v2 = v1 * 1000.0;
break;
case 3u:
return v2;
case 4u:
v2 = v1 * 0.001;
break;
case 5u:
v2 = v1 * 0.000001;
break;
default:
continue;
}
break;
}
return v2;
}

original_code:
double getpower (const char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)MW  2)KW  3)W  4)mW  5)μW : ");
  switch (i)
  {
   case 1:
    return v * 1e6;
   case 2:
    return v * 1e3;
   case 3:
    return v;
   case 4:
    return v * 1e-3;
   case 5:
    return v * 1e-6;
  }
 }
}

canonical_original_code:
double getpower(char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)MW  2)KW  3)W  4)mW  5)μW : ");
  switch (i)
  {
   case 1:
    return v * 1e6;
   case 2:
    return v * 1e3;
   case 3:
    return v;
   case 4:
    return v * 1e-3;
   case 5:
    return v * 1e-6;
  }
 }
}


getvoltage

decompiled_code:
double __fastcall getvoltage(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = getdouble(a1);
v2 = v1;
switch ( (unsigned int)getint(a1Mv2Kv3V4Mv5) )
{
case 1u:
v2 = v1 * 1000000.0;
break;
case 2u:
v2 = v1 * 1000.0;
break;
case 3u:
return v2;
case 4u:
v2 = v1 * 0.001;
break;
case 5u:
v2 = v1 * 0.000001;
break;
case 6u:
v2 = v1 * 0.000000001;
break;
default:
continue;
}
break;
}
return v2;
}

canonical_decompiled_code:
double __fastcall func16(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = func2(a1);
v2 = v1;
switch ( (unsigned int)func3(a1Mv2Kv3V4Mv5) )
{
case 1u:
v2 = v1 * 1000000.0;
break;
case 2u:
v2 = v1 * 1000.0;
break;
case 3u:
return v2;
case 4u:
v2 = v1 * 0.001;
break;
case 5u:
v2 = v1 * 0.000001;
break;
case 6u:
v2 = v1 * 0.000000001;
break;
default:
continue;
}
break;
}
return v2;
}

original_code:
double getvoltage (const char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)MV  2)KV  3)V  4)mV  5)μV  6)nV: ");
  switch (i)
  {
   case 1:
    return v * 1e6;
   case 2:
    return v * 1e3;
   case 3:
    return v;
   case 4:
    return v * 1e-3;
   case 5:
    return v * 1e-6;
   case 6:
    return v * 1e-9;
  }
 }
}

canonical_original_code:
double getvoltage(char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)MV  2)KV  3)V  4)mV  5)μV  6)nV: ");
  switch (i)
  {
   case 1:
    return v * 1e6;
   case 2:
    return v * 1e3;
   case 3:
    return v;
   case 4:
    return v * 1e-3;
   case 5:
    return v * 1e-6;
   case 6:
    return v * 1e-9;
  }
 }
}


getamperage

decompiled_code:
double __fastcall getamperage(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = getdouble(a1);
v2 = v1;
switch ( (unsigned int)getint(a1Ka2A3Ma4) )
{
case 1u:
v2 = v1 * 1000.0;
break;
case 2u:
return v2;
case 3u:
v2 = v1 * 0.001;
break;
case 4u:
v2 = v1 * 0.000001;
break;
case 5u:
v2 = v1 * 0.000000001;
break;
default:
continue;
}
break;
}
return v2;
}

canonical_decompiled_code:
double __fastcall func17(const char *a1)
{
double v1; // xmm0_8
double v2; // rbx

while ( 2 )
{
v1 = func2(a1);
v2 = v1;
switch ( (unsigned int)func3(a1Ka2A3Ma4) )
{
case 1u:
v2 = v1 * 1000.0;
break;
case 2u:
return v2;
case 3u:
v2 = v1 * 0.001;
break;
case 4u:
v2 = v1 * 0.000001;
break;
case 5u:
v2 = v1 * 0.000000001;
break;
default:
continue;
}
break;
}
return v2;
}

original_code:
double getamperage (const char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)KA  2)A  3)mA  4)μA  5)nA: ");
  switch (i)
  {
   case 1:
    return v * 1e3;
   case 2:
    return v;
   case 3:
    return v * 1e-3;
   case 4:
    return v * 1e-6;
   case 5:
    return v * 1e-9;
  }
 }
}

canonical_original_code:
double getamperage(char *display)
{
 double v;
 int i;
 while (1)
 {
  v = getdouble (display);
  i = getint ("\n1)KA  2)A  3)mA  4)μA  5)nA: ");
  switch (i)
  {
   case 1:
    return v * 1e3;
   case 2:
    return v;
   case 3:
    return v * 1e-3;
   case 4:
    return v * 1e-6;
   case 5:
    return v * 1e-9;
  }
 }
}


repo: sgerin/DCT

decompiled_code:
void coef_dct()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void coef_dct(int nbe, float **table)
{
}

variable_types: nbe int

variable_types:
table
float **


dct

decompiled_code:
void dct()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void dct(int inverse,
  int nbe,
  const float *entree,
  float *sortie
  )
{
}

canonical_original_code:
void dct(int inverse, int nbe, float *entree, float *sortie)
{
}

variable_types: inverse int

variable_types:
entree
float *

variable_types:
sortie
float *


decompiled_code:
__int64 compresse_tst()
{
compresse_test(3u, (__int64)&t1_4, 2, (__int64)&ok1_3);
return compresse_test(9u, (__int64)&t2_2, 7, (__int64)&ok2_1);
}

original_code:
void compresse_tst()
{
  static float t1[] = { 0, 0, 5 } ;
  static int ok1[] = { 2, 5 } ;
  static float t2[] = { -0.4, -0.9, 0, 0.4, 0.9, 2 , 0,0,0 } ;
  static int ok2[] = { 1,-1, 2,1, 0,2, 3 } ;
  compresse_test(( sizeof(t1) / sizeof(t1[0]) ), t1, ( sizeof(ok1) / sizeof(ok1[0]) ), ok1) ;
  compresse_test(( sizeof(t2) / sizeof(t2[0]) ), t2, ( sizeof(ok2) / sizeof(ok2[0]) ), ok2) ;
  return ;
}

canonical_original_code:
void compresse_tst()
{
  static float t1[] = { 0, 0, 5 };
  static int ok1[] = { 2, 5 };
  static float t2[] = { -0.4, -0.9, 0, 0.4, 0.9, 2 , 0,0,0 };
  static int ok2[] = { 1,-1, 2,1, 0,2, 3 };
  compresse_test(( sizeof(t1) / sizeof(t1[0]) ), t1, ( sizeof(ok1) / sizeof(ok1[0]) ), ok1) ;
  compresse_test(( sizeof(t2) / sizeof(t2[0]) ), t2, ( sizeof(ok2) / sizeof(ok2[0]) ), ok2) ;
  return ;
}


decompiled_code:
__int64 allocation_matrice_carree_float()
{
return 0LL;
}

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

original_code:
float** allocation_matrice_carree_float(int nbe)
{
return 0 ;
}

canonical_original_code:
float **allocation_matrice_carree_float(int nbe)
{
return 0 ;
}

return_type: float **


decompiled_code:
void liberation_matrice_carree_float()
{
;
}

original_code:
void liberation_matrice_carree_float(float **table, int nbe)
{
}


original_code:
void produit_matrices_carrees_float(int nbe, float **a, float **b, float **resultat)
 {
  int j, i, k ;
  float s ;
  for(j=0; j<nbe; j++)
    for(i=0; i<nbe; i++)
      {
 s = 0 ;
 for(k=0;k<nbe;k++)
   s += a[j][k]*b[k][i] ;
 resultat[j][i] = s ;
      }
 }

canonical_original_code:
void produit_matrices_carrees_float(int nbe, float **a, float **b, float **resultat)
 {
  int j; int i; int k;
  float s;
  for(j=0; j<nbe; j++)
    for(i=0; i<nbe; i++)
      {
 s = 0 ;
 for(k=0;k<nbe;k++)
   s += a[j][k]*b[k][i] ;
 resultat[j][i] = s ;
      }
 }

variable_types:
a
float **

variable_types:
b
float **

variable_types:
resultat
float **

variable_types: j int

variable_types: k int

variable_types: s float


original_code:
void produit_matrice_carree_vecteur(int nbe, float **m, const float *v, float *resultat)
 {
  int j, i ;
  float s ;
  for(j=0; j<nbe; j++)
    {
      s = 0 ;
      for(i=0;i<nbe;i++)
 s += m[j][i] * v[i] ;
      resultat[j] = s ;
    }
 }

canonical_original_code:
void produit_matrice_carree_vecteur(int nbe, float **m, float *v, float *resultat)
 {
  int j; int i;
  float s;
  for(j=0; j<nbe; j++)
    {
      s = 0 ;
      for(i=0;i<nbe;i++)
 s += m[j][i] * v[i] ;
      resultat[j] = s ;
    }
 }

variable_types:
m
float **

variable_types:
v
float *

variable_types:
resultat
float *


decompiled_code:
void __fastcall transposition_matrice_carree(int a1, __int64 a2, _QWORD *a3)
{
__int64 v5; // rdi
__int64 v6; // rcx
__int64 v7; // rax

if ( a1 > 0 )
{
v5 = 4LL * (unsigned int)a1;
v6 = 0LL;
do
{
v7 = 0LL;
do
{
*(_DWORD *)(*a3 + v7) = *(_DWORD *)(*(_QWORD *)(a2 + 2 * v7) + v6);
v7 += 4LL;
}
while ( v7 != v5 );
v6 += 4LL;
++a3;
}
while ( v6 != v5 );
}
}

original_code:
void transposition_matrice_carree(int nbe, float **a, float **a_t)
 {
  int i, j ;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      a_t[j][i] = a[i][j] ;
 }

canonical_original_code:
void transposition_matrice_carree(int nbe, float **a, float **a_t)
 {
  int i; int j;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      a_t[j][i] = a[i][j] ;
 }


simple

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

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

original_code:
static int simple(int n)
{
  return(n) ;
}

variable_types: n int


aleatoire

decompiled_code:
__int64 __fastcall aleatoire(unsigned int a1)
{
srand(a1);
return (unsigned int)(rand() % 50);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
srand(a1);
return (unsigned int)(rand() % 50);
}

original_code:
static int aleatoire(int n)
{
  srand(n) ;
  return( rand() % 50 ) ;
}


decompiled_code:
__int64 __fastcall aleatoire2(unsigned int a1)
{
int v1; // eax

srand(a1);
v1 = rand();
return (unsigned int)(int)pow((double)(v1 % 50), 0.1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
int v1; // eax

srand(a1);
v1 = rand();
return (unsigned int)(int)pow((double)(v1 % 50), 0.1);
}

original_code:
static int aleatoire2(int n)
{
  srand(n) ;
  return( pow( rand() % 50, .1 ) ) ;
}


decompiled_code:
__int64 __fastcall trouve_position(_DWORD *a1, int a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
int v5; // edx

if ( !*a1 )
return a4;
for ( result = 0LL; ; ++result )
{
v5 = a1[2 * result + 1];
if ( v5 == a2 )
break;
if ( v5 == 0x7FFFFFFF )
a4 = result;
if ( result == *a1 - 1 )
return a4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
int v5; // edx

if ( !*a1 )
return a4;
for ( result = 0LL; ; ++result )
{
v5 = a1[2 * result + 1];
if ( v5 == a2 )
break;
if ( v5 == 0x7FFFFFFF )
a4 = result;
if ( result == *a1 - 1 )
return a4;
}
return result;
}

original_code:
static int trouve_position(const struct shannon_fano *sf, int evenement)
{
 unsigned int i;
 unsigned int escape;
 for(i=0; i<sf->nb_evenements; ++i)
 {
  if(sf->evenements[i].valeur == evenement)
   return i;
  if(sf->evenements[i].valeur == 0x7fffffff)
   escape = i;
 }
 return escape;
}

canonical_original_code:
static int trouve_position(struct shannon_fano *sf, int evenement)
{
 unsigned int i;
 unsigned int escape;
 for(i=0; i<sf->nb_evenements; ++i)
 {
  if(sf->evenements[i].valeur == evenement)
   return i;
  if(sf->evenements[i].valeur == 0x7fffffff)
   escape = i;
 }
 return escape;
}

variable_types: struct shannon_fano { int nb_evenements; struct evenement { int valeur; int nb_occurrences; } evenements[200000]; } *

variable_types: evenement int

variable_types:
i
unsigned int

variable_types:
escape
unsigned int

user_defined_types: struct shannon_fano { int nb_evenements; struct evenement evenements[200000]; }


decompiled_code:
__int64 __fastcall trouve_separation(__int64 a1, int a2, int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // edx

result = (unsigned int)a3;
if ( a2 <= a3 )
{
v4 = 0;
v5 = 0;
do
{
if ( v5 >= v4 )
{
v4 += *(_DWORD *)(a1 + 8LL * (int)result + 8);
result = (unsigned int)(result - 1);
}
else
{
v5 += *(_DWORD *)(a1 + 8LL * a2++ + 8);
}
}
while ( (int)result >= a2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // edx

result = (unsigned int)a3;
if ( a2 <= a3 )
{
v4 = 0;
v5 = 0;
do
{
if ( v5 >= v4 )
{
v4 += *(_DWORD *)(a1 + 8LL * (int)result + 8);
result = (unsigned int)(result - 1);
}
else
{
v5 += *(_DWORD *)(a1 + 8LL * a2++ + 8);
}
}
while ( (int)result >= a2 );
}
return result;
}

original_code:
static int trouve_separation(const struct shannon_fano *sf
        , int position_min
        , int position_max)
{
 unsigned int sum_inf = 0;
 unsigned int sum_sup = 0;
 while(position_min <= position_max)
 {
  if(sum_inf < sum_sup)
  {
   sum_inf += sf->evenements[position_min].nb_occurrences;
   ++position_min;
  }
  else
  {
   sum_sup += sf->evenements[position_max].nb_occurrences;
   --position_max;
  }
 }
 return position_max;
}

canonical_original_code:
static int trouve_separation(struct shannon_fano *sf, int position_min, int position_max)
{
 unsigned int sum_inf = 0;
 unsigned int sum_sup = 0;
 while(position_min <= position_max)
 {
  if(sum_inf < sum_sup)
  {
   sum_inf += sf->evenements[position_min].nb_occurrences;
   ++position_min;
  }
  else
  {
   sum_sup += sf->evenements[position_max].nb_occurrences;
   --position_max;
  }
 }
 return position_max;
}

user_defined_types: struct evenement { int valeur; int nb_occurrences; }


decompiled_code:
__int64 __fastcall incremente_et_ordonne(__int64 a1, int a2)
{
unsigned int *v2; // r8
__int64 result; // rax
int v4; // ecx
int v5; // edx
unsigned int v6; // edx

v2 = (unsigned int *)(a1 + 8LL * a2);
result = v2[2];
v4 = result + 1;
v2[2] = result + 1;
if ( a2 > 0 )
{
result = a2 - 1;
v5 = a2;
do
{
if ( v4 > *(_DWORD *)(a1 + 8 * result + 8) )
v5 = result;
--result;
}
while ( (int)result >= 0 );
if ( v5 != a2 )
{
v6 = *(v2 - 1);
result = *v2;
*(_QWORD *)(v2 - 1) = *(_QWORD *)(a1 + 8LL * a2 + 4);
v2[1] = v6;
v2[2] = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned int *v2; // r8
__int64 result; // rax
int v4; // ecx
int v5; // edx
unsigned int v6; // edx

v2 = (unsigned int *)(a1 + 8LL * a2);
result = v2[2];
v4 = result + 1;
v2[2] = result + 1;
if ( a2 > 0 )
{
result = a2 - 1;
v5 = a2;
do
{
if ( v4 > *(_DWORD *)(a1 + 8 * result + 8) )
v5 = result;
--result;
}
while ( (int)result >= 0 );
if ( v5 != a2 )
{
v6 = *(v2 - 1);
result = *v2;
*(_QWORD *)(v2 - 1) = *(_QWORD *)(a1 + 8LL * a2 + 4);
v2[1] = v6;
v2[2] = result;
}
}
return result;
}

original_code:
static void incremente_et_ordonne(struct shannon_fano *sf, int position)
{
 sf->evenements[position].nb_occurrences++;
 if(position > 0)
 {
  int position_swap = position;
  int i;
  for(i=position-1; i>=0; i--)
  {
   if(sf->evenements[i].nb_occurrences < sf->evenements[position].nb_occurrences)
    position_swap = i;
  }
  if(position_swap != position)
  {
   struct evenement tmp = sf->evenements[position-1];
   sf->evenements[position-1] = sf->evenements[position];
   sf->evenements[position] = tmp;
  }
 }
}

variable_types: position int

variable_types: i int

variable_types: struct evenement { int valeur; int nb_occurrences; }


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

result = malloc(0x186A04uLL);
if ( !result )
{
fwrite("Plus de memoire\n", 1uLL, 0x10uLL, stderr);
fprintf(stderr, "%s:%d\n", "sf.c", 34LL);
abort();
}
*result = 1;
result[1] = 0x7FFFFFFF;
result[2] = 1;
return result;
}

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

result = malloc(0x186A04uLL);
if ( !result )
{
fwrite("Plus de memoire\n", 1uLL, 0x10uLL, stderr);
fprintf(stderr, "%s:%d\n", "sf.c", 34LL);
abort();
}
*result = 1;
result[1] = 0x7FFFFFFF;
result[2] = 1;
return result;
}

original_code:
struct shannon_fano* open_shannon_fano()
{
 struct shannon_fano* sf;
 do if ( (sf = malloc(sizeof(*(sf)) * (1))) == 0 ) { fprintf(stderr, "Plus de memoire\n") ; do { fprintf(stderr,"%s:%d\n","sf.c",34) ; abort() ; } while(0) ; } while(0);
 sf->nb_evenements = 1;
 sf->evenements[0].valeur = 0x7fffffff;
 sf->evenements[0].nb_occurrences = 1;
 return sf;
}

canonical_original_code:
struct shannon_fano *open_shannon_fano()
{
 struct shannon_fano *sf;
 do if ( (sf = malloc(sizeof(*(sf)) * (1))) == 0 ) { fprintf(stderr, "Plus de memoire\n") ; do { fprintf(stderr,"%s:%d\n","sf.c",34) ; abort() ; } while(0) ; } while(0);
 sf->nb_evenements = 1;
 sf->evenements[0].valeur = 0x7fffffff;
 sf->evenements[0].nb_occurrences = 1;
 return sf;
}

return_type: struct shannon_fano { int nb_evenements; struct evenement { int valeur; int nb_occurrences; } evenements[200000]; } *


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

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

original_code:
void close_shannon_fano(struct shannon_fano *sf)
{
 free(sf);
}


decompiled_code:
__int64 __fastcall sf_get_nb_evenements(unsigned int *a1)
{
return *a1;
}

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

original_code:
int sf_get_nb_evenements(struct shannon_fano *sf)
 {
   return sf->nb_evenements ;
 }


decompiled_code:
__int64 nb_bits_utile_tst()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = 0LL;
while ( 1 )
{
result = nb_bits_utile(v0);
if ( (_DWORD)result != n_0[v0] )
break;
if ( ++v0 == 9 )
return result;
}
return eprintf("nb_bits_utile(%d) != %d\n", (unsigned int)v0);
}

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

v0 = 0LL;
while ( 1 )
{
result = nb_bits_utile(v0);
if ( (_DWORD)result != n_0[v0] )
break;
if ( ++v0 == 9 )
return result;
}
return eprintf("nb_bits_utile(%d) != %d\n", (unsigned int)v0);
}

original_code:
void nb_bits_utile_tst()
{
  int i ;
  static int n[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4 } ;
  for( i=0; i<( sizeof(n) / sizeof(n[0]) ); i++)
    if ( nb_bits_utile(i) != n[i] )
      {
 eprintf("nb_bits_utile(%d) != %d\n", i, n[i]) ;
 return ;
      }
}

canonical_original_code:
void nb_bits_utile_tst()
{
  int i;
  static int n[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4 };
  for( i=0; i<( sizeof(n) / sizeof(n[0]) ); i++)
    if ( nb_bits_utile(i) != n[i] )
      {
 eprintf("nb_bits_utile(%d) != %d\n", i, n[i]) ;
 return ;
      }
}

variable_types:
n
int []


decompiled_code:
int __fastcall pow2_tst(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

v2 = 0;
if ( pow2(0LL) == 1 )
{
do
{
v3 = pow2(v2 + 1);
if ( v3 != 2 * pow2(v2) )
{
LODWORD(v4) = eprintf("pow2(%d) != pow2(%d)*2\n", v2 + 1);
return v4;
}
++v2;
}
while ( v2 != 31 );
v4 = pow2(70LL);
if ( v4 )
{
v5 = pow2(70LL);
LODWORD(v4) = fprintf(
stderr,
"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n : ",
v5);
}
}
else
{
LODWORD(v4) = eprintf("pow2(0) != 1\n", a2);
}
return v4;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

v2 = 0;
if ( pow2(0LL) == 1 )
{
do
{
v3 = pow2(v2 + 1);
if ( v3 != 2 * pow2(v2) )
{
LODWORD(v4) = eprintf("pow2(%d) != pow2(%d)*2\n", v2 + 1);
return v4;
}
++v2;
}
while ( v2 != 31 );
v4 = pow2(70LL);
if ( v4 )
{
v5 = pow2(70LL);
LODWORD(v4) = fprintf(
stderr,
"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n : ",
v5);
}
}
else
{
LODWORD(v4) = eprintf("pow2(0) != 1\n", a2);
}
return v4;
}

original_code:
void pow2_tst()
{
  int i ;
  if ( pow2(0) != 1 )
    {
      eprintf("pow2(0) != 1\n") ;
      return ;
    }
  for(i=0;i<31;i++)
    if ( pow2(i+1) != pow2(i)*2 )
      {
 eprintf("pow2(%d) != pow2(%d)*2\n", i+1, i) ;
 return ;
      }
  if ( pow2(70) != 0 )
    fprintf(stderr,"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n                                         : ",pow2(70));
}

canonical_original_code:
void pow2_tst()
{
  int i;
  if ( pow2(0) != 1 )
    {
      eprintf("pow2(0) != 1\n") ;
      return ;
    }
  for(i=0;i<31;i++)
    if ( pow2(i+1) != pow2(i)*2 )
      {
 eprintf("pow2(%d) != pow2(%d)*2\n", i+1, i) ;
 return ;
      }
  if ( pow2(70) != 0 )
    fprintf(stderr,"...\nAttention : pow2(70)!=0 (vous trouvez %ld)\n                                         : ",pow2(70));
}


decompiled_code:
__int64 prend_bit_tst()
{
int v0; // er15
int v1; // er13
int v2; // er12
unsigned int i; // ebx
__int64 result; // rax
__int64 v5; // rsi

v0 = 1000;
while ( 1 )
{
v1 = rand();
v2 = 0;
for ( i = 0; i != 64; ++i )
{
v5 = i;
if ( (unsigned int)prend_bit(v1, i) == 1 )
{
result = pow2(i);
v2 |= result;
}
else
{
v5 = i;
result = prend_bit(v1, i);
if ( (_DWORD)result )
return eprintf("Retourne ni Faux, ni Vrai\n", i);
}
}
if ( v2 != v1 )
break;
if ( !--v0 )
return result;
}
return eprintf("Mauvais\n", v5);
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er15
int v1; // er13
int v2; // er12
unsigned int i; // ebx
__int64 result; // rax
__int64 v5; // rsi

v0 = 1000;
while ( 1 )
{
v1 = rand();
v2 = 0;
for ( i = 0; i != 64; ++i )
{
v5 = i;
if ( (unsigned int)prend_bit(v1, i) == 1 )
{
result = pow2(i);
v2 |= result;
}
else
{
v5 = i;
result = prend_bit(v1, i);
if ( (_DWORD)result )
return eprintf("Retourne ni Faux, ni Vrai\n", i);
}
}
if ( v2 != v1 )
break;
if ( !--v0 )
return result;
}
return eprintf("Mauvais\n", v5);
}

original_code:
void prend_bit_tst()
{
  int i, j, k, s ;
  for(i=0;i<1000;i++)
    {
      j = rand() ;
      s = 0 ;
      for(k=0;k<8*sizeof(unsigned long);k++)
 if ( prend_bit(j, k) == Vrai )
   s |= pow2(k) ;
 else
   if ( prend_bit(j, k) != Faux )
     {
       eprintf("Retourne ni Faux, ni Vrai\n") ;
       return ;
     }
      if ( s != j )
 {
   eprintf("Mauvais\n") ;
   return ;
 }
    }
}

canonical_original_code:
void prend_bit_tst()
{
  int i; int j; int k; int s;
  for(i=0;i<1000;i++)
    {
      j = rand() ;
      s = 0 ;
      for(k=0;k<8*sizeof(unsigned long);k++)
 if ( prend_bit(j, k) == Vrai )
   s |= pow2(k) ;
 else
   if ( prend_bit(j, k) != Faux )
     {
       eprintf("Retourne ni Faux, ni Vrai\n") ;
       return ;
     }
      if ( s != j )
 {
   eprintf("Mauvais\n") ;
   return ;
 }
    }
}

variable_types: s int


decompiled_code:
__int64 coef_dct_tst()
{
__int64 v0; // rbx
_QWORD *v1; // rdx
__int64 v2; // rcx
unsigned int i; // er13
__int64 result; // rax
_QWORD *v5; // r14
unsigned int v6; // ebp
__int64 v7; // r12
float v8; // ebx

v0 = allocation_matrice_carree_float(5LL);
coef_dct(5LL, v0);
v1 = (_QWORD *)v0;
v2 = 0LL;
for ( i = 0; i != 5; ++i )
{
v5 = v1;
for ( result = 0LL; result != 5; ++result )
{
v6 = result;
v7 = 4 * result;
v8 = t_1[result + v2];
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(*v1 + 4 * result) - v8) & LC0) > 0.0001 )
{
eprintf("La matrice est mauvaise.\n");
return eprintf("dct[%d][%d] = %g au lieu de %g\n", i, v6, *(float *)(*v5 + v7), v8);
}
}
++v1;
v2 += 5LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
_QWORD *v1; // rdx
__int64 v2; // rcx
unsigned int i; // er13
__int64 result; // rax
_QWORD *v5; // r14
unsigned int v6; // ebp
__int64 v7; // r12
float v8; // ebx

v0 = allocation_matrice_carree_float(5LL);
coef_dct(5LL, v0);
v1 = (_QWORD *)v0;
v2 = 0LL;
for ( i = 0; i != 5; ++i )
{
v5 = v1;
for ( result = 0LL; result != 5; ++result )
{
v6 = result;
v7 = 4 * result;
v8 = t_1[result + v2];
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(*v1 + 4 * result) - v8) & LC0) > 0.0001 )
{
eprintf("La matrice est mauvaise.\n");
return eprintf("dct[%d][%d] = %g au lieu de %g\n", i, v6, *(float *)(*v5 + v7), v8);
}
}
++v1;
v2 += 5LL;
}
return result;
}

variable_types:
table
float **

variable_types:
t
float [5][5]


decompiled_code:
void dct_tst()
{
__int64 i; // rbx
double v1; // rbp
double v2; // r14
int v3; // xmm0_4
__int64 j; // rax
unsigned int v5; // ebp
float v6; // ebx
double v7; // xmm0_8
char *v8; // rax
__int64 v9; // rbx
double v10; // r14
double v11; // r15
double v12; // xmm1_8
float v13[128]; // [rsp+10h] [rbp-428h] BYREF
float v14[128]; // [rsp+210h] [rbp-228h] BYREF
char v15; // [rsp+410h] [rbp-28h] BYREF

for ( i = 0LL; i != 128; ++i )
{
v1 = cos((double)(int)i);
v2 = cos(0.25 * (double)(int)i + 0.1);
*(float *)&v3 = v1 + v2 + cos((double)(int)i / 7.0 + 2.0);
v14[i] = *(float *)&v3;
}
dct(0LL, 128LL, v14, v13);
for ( j = 0LL; j != 128; ++j )
{
v5 = j;
v6 = dct_ok_0[j];
v7 = COERCE_FLOAT(COERCE_UNSIGNED_INT(v13[j] - v6) & LC0);
if ( v7 > 0.0001 )
{
eprintf("La dct est mauvaise.\n", v7, *(double *)&LC1, COERCE_DOUBLE((unsigned __int64)LC0));
eprintf("sortie[%d] = %g au lieu de %g\n", v5, v13[v5], v6);
return;
}
}
v8 = (char *)v14;
do
{
*(_DWORD *)v8 = LC10;
v8 += 4;
}
while ( v8 != &v15 );
dct(1LL, 128LL, v13, v14);
v9 = 0LL;
while ( 1 )
{
v10 = cos((double)(int)v9);
v11 = cos(0.25 * (double)(int)v9 + 0.1);
v12 = cos((double)(int)v9 / 7.0 + 2.0);
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v14[v9] - (v10 + v11 + v12)) & LC11) > 0.01 )
break;
if ( ++v9 == 128 )
return;
}
eprintf("La dct inverse est mauvaise.\n");
eprintf("sortie[%d] = %g au lieu de %g\n", (unsigned int)v9, v14[(int)v9], v10 + v11 + v12);
}

canonical_decompiled_code:
void func1()
{
__int64 i; // rbx
double v1; // rbp
double v2; // r14
int v3; // xmm0_4
__int64 j; // rax
unsigned int v5; // ebp
float v6; // ebx
double v7; // xmm0_8
char *v8; // rax
__int64 v9; // rbx
double v10; // r14
double v11; // r15
double v12; // xmm1_8
float v13[128]; // [rsp+10h] [rbp-428h] BYREF
float v14[128]; // [rsp+210h] [rbp-228h] BYREF
char v15; // [rsp+410h] [rbp-28h] BYREF

for ( i = 0LL; i != 128; ++i )
{
v1 = cos((double)(int)i);
v2 = cos(0.25 * (double)(int)i + 0.1);
*(float *)&v3 = v1 + v2 + cos((double)(int)i / 7.0 + 2.0);
v14[i] = *(float *)&v3;
}
dct(0LL, 128LL, v14, v13);
for ( j = 0LL; j != 128; ++j )
{
v5 = j;
v6 = dct_ok_0[j];
v7 = COERCE_FLOAT(COERCE_UNSIGNED_INT(v13[j] - v6) & LC0);
if ( v7 > 0.0001 )
{
eprintf("La dct est mauvaise.\n", v7, *(double *)&LC1, COERCE_DOUBLE((unsigned __int64)LC0));
eprintf("sortie[%d] = %g au lieu de %g\n", v5, v13[v5], v6);
return;
}
}
v8 = (char *)v14;
do
{
*(_DWORD *)v8 = LC10;
v8 += 4;
}
while ( v8 != &v15 );
dct(1LL, 128LL, v13, v14);
v9 = 0LL;
while ( 1 )
{
v10 = cos((double)(int)v9);
v11 = cos(0.25 * (double)(int)v9 + 0.1);
v12 = cos((double)(int)v9 / 7.0 + 2.0);
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v14[v9] - (v10 + v11 + v12)) & LC11) > 0.01 )
break;
if ( ++v9 == 128 )
return;
}
eprintf("La dct inverse est mauvaise.\n");
eprintf("sortie[%d] = %g au lieu de %g\n", (unsigned int)v9, v14[(int)v9], v10 + v11 + v12);
}

variable_types:
entree
float [128]

variable_types:
sortie
float [128]


decompiled_code:
__int64 allocation_image()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
struct image* allocation_image(int hauteur, int largeur)
{
return 0 ;
}

canonical_original_code:
struct image *allocation_image(int hauteur, int largeur)
{
return 0 ;
}

variable_types: hauteur int

variable_types: largeur int

return_type: struct image { int largeur; int hauteur; unsigned char **pixels; } *


decompiled_code:
void liberation_image()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void liberation_image(struct image* image)
{
}

canonical_original_code:
void liberation_image(struct image *image)
{
}

variable_types: struct image { int largeur; int hauteur; unsigned char **pixels; } *


original_code:
static void extrait_matrice(int y, int x, int nbe
       , const struct image *entree
       , float **extrait
       )
 {
  int i, j ;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < entree->hauteur && i+x < entree->largeur )
 extrait[j][i] = entree->pixels[j+y][i+x] ;
      else
 extrait[j][i] = 0 ;
 }

canonical_original_code:
static void extrait_matrice(int y, int x, int nbe, struct image *entree, float **extrait)
 {
  int i; int j;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < entree->hauteur && i+x < entree->largeur )
 extrait[j][i] = entree->pixels[j+y][i+x] ;
      else
 extrait[j][i] = 0 ;
 }

variable_types: y int

variable_types: x int

variable_types: nbe int

variable_types:
extrait
float **

variable_types: j int

user_defined_types: struct image { int largeur; int hauteur; unsigned char **pixels; }


original_code:
static void insert_matrice(int y, int x, int nbe
      , float **extrait
      , struct image *sortie
      )
 {
  int i, j ;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < sortie->hauteur && i+x < sortie->largeur )
 {
   if ( extrait[j][i] < 0 )
     sortie->pixels[j+y][i+x] = 0 ;
   else
     {
       if ( extrait[j][i] > 255 )
  sortie->pixels[j+y][i+x] = 255 ;
       else
  sortie->pixels[j+y][i+x] = rint(extrait[j][i]) ;
     }
 }
 }

canonical_original_code:
static void insert_matrice(int y, int x, int nbe, float **extrait, struct image *sortie)
 {
  int i; int j;
  for(j=0;j<nbe;j++)
    for(i=0;i<nbe;i++)
      if ( j+y < sortie->hauteur && i+x < sortie->largeur )
 {
   if ( extrait[j][i] < 0 )
     sortie->pixels[j+y][i+x] = 0 ;
   else
     {
       if ( extrait[j][i] > 255 )
  sortie->pixels[j+y][i+x] = 255 ;
       else
  sortie->pixels[j+y][i+x] = rint(extrait[j][i]) ;
     }
 }
 }


decompiled_code:
void dct_image()
{
;
}

original_code:
void dct_image(int inverse, int nbe, float **image)
{
}

variable_types: inverse int

variable_types:
image
float **


quantification

decompiled_code:
void quantification()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void quantification(int nbe, int qualite, float **extrait, int inverse)
{
}

variable_types: qualite int


zigzag

decompiled_code:
void zigzag()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void zigzag(int nbe, int *y, int *x)
{
}

variable_types:
y
int *

variable_types:
x
int *


decompiled_code:
__int64 allocation_image_tst()
{
__int64 v0; // rcx
__int64 i; // rax
__int64 v2; // rcx
__int64 result; // rax

v0 = allocation_image(1LL, 1000LL);
for ( i = 0LL; i != 1000; ++i )
*(_BYTE *)(**(_QWORD **)(v0 + 8) + i) = 99;
v2 = allocation_image(1000LL, 1LL);
for ( result = 0LL; result != 8000; result += 8LL )
**(_BYTE **)(*(_QWORD *)(v2 + 8) + result) = 99;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rcx
__int64 i; // rax
__int64 v2; // rcx
__int64 result; // rax

v0 = allocation_image(1LL, 1000LL);
for ( i = 0LL; i != 1000; ++i )
*(_BYTE *)(**(_QWORD **)(v0 + 8) + i) = 99;
v2 = allocation_image(1000LL, 1LL);
for ( result = 0LL; result != 8000; result += 8LL )
**(_BYTE **)(*(_QWORD *)(v2 + 8) + result) = 99;
return result;
}

original_code:
void allocation_image_tst()
{
  struct image *image ;
  int i ;
  image = allocation_image(1, 1000) ;
  for(i=0; i<1000; i++)
    image->pixels[0][i] = 99 ;
  image = allocation_image(1000, 1) ;
  for(i=0; i<1000; i++)
    image->pixels[i][0] = 99 ;
}

canonical_original_code:
void allocation_image_tst()
{
  struct image *image;
  int i;
  image = allocation_image(1, 1000) ;
  for(i=0; i<1000; i++)
    image->pixels[0][i] = 99 ;
  image = allocation_image(1000, 1) ;
  for(i=0; i<1000; i++)
    image->pixels[i][0] = 99 ;
}

variable_types: i int


decompiled_code:
__int64 lecture_image_tst()
{
FILE *v0; // rax
unsigned int *v1; // rax
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // r10
__int64 v5; // r9
__int64 v6; // rsi
__int64 i; // rcx
__int64 result; // rax

v0 = fopen("DONNEES/bat710.pgm", "r");
v1 = (unsigned int *)lecture_image(v0);
v2 = v1[1];
if ( (_DWORD)v2 != 135 )
return eprintf("Mauvaise hauteur : %d au lieu de 135\n", v2);
v3 = *v1;
if ( (_DWORD)v3 != 254 )
return eprintf("Mauvaise largeur : %d au lieu de 254\n", v3);
v4 = *((_QWORD *)v1 + 1);
v5 = 0LL;
LODWORD(v6) = 0;
do
{
for ( i = 1LL; i != 255; ++i )
{
result = (unsigned int)((int)(v5 * *(unsigned __int8 *)(*(_QWORD *)(v4 + 8 * v5) + i - 1)) / (int)i);
v6 = (unsigned int)(result + v6);
}
++v5;
}
while ( v5 != 135 );
if ( (_DWORD)v6 != 5709193 )
result = eprintf("Mauvais pixels : Checksum = %d\n", v6);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
FILE *v0; // rax
unsigned int *v1; // rax
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // r10
__int64 v5; // r9
__int64 v6; // rsi
__int64 i; // rcx
__int64 result; // rax

v0 = fopen("DONNEES/bat710.pgm", "r");
v1 = (unsigned int *)lecture_image(v0);
v2 = v1[1];
if ( (_DWORD)v2 != 135 )
return eprintf("Mauvaise hauteur : %d au lieu de 135\n", v2);
v3 = *v1;
if ( (_DWORD)v3 != 254 )
return eprintf("Mauvaise largeur : %d au lieu de 254\n", v3);
v4 = *((_QWORD *)v1 + 1);
v5 = 0LL;
LODWORD(v6) = 0;
do
{
for ( i = 1LL; i != 255; ++i )
{
result = (unsigned int)((int)(v5 * *(unsigned __int8 *)(*(_QWORD *)(v4 + 8 * v5) + i - 1)) / (int)i);
v6 = (unsigned int)(result + v6);
}
++v5;
}
while ( v5 != 135 );
if ( (_DWORD)v6 != 5709193 )
result = eprintf("Mauvais pixels : Checksum = %d\n", v6);
return result;
}

original_code:
void lecture_image_tst()
{
  struct image *image ;
  int j, i ;
  int s ;
  image = lecture_image(fopen("DONNEES/bat710.pgm","r")) ;
  if ( image->hauteur != 135 )
    {
      eprintf("Mauvaise hauteur : %d au lieu de 135\n", image->hauteur) ;
      return ;
    }
  if ( image->largeur != 254 )
    {
      eprintf("Mauvaise largeur : %d au lieu de 254\n", image->largeur) ;
      return ;
    }
  s = 0 ;
  for(j=0; j<image->hauteur; j++)
    for(i=0; i<image->largeur; i++)
      s += (j*image->pixels[j][i])/(i+1) ;
  if ( s != 5709193 )
    eprintf("Mauvais pixels : Checksum = %d\n", s) ;
}

canonical_original_code:
void lecture_image_tst()
{
  struct image *image;
  int j; int i;
  int s;
  image = lecture_image(fopen("DONNEES/bat710.pgm","r")) ;
  if ( image->hauteur != 135 )
    {
      eprintf("Mauvaise hauteur : %d au lieu de 135\n", image->hauteur) ;
      return ;
    }
  if ( image->largeur != 254 )
    {
      eprintf("Mauvaise largeur : %d au lieu de 254\n", image->largeur) ;
      return ;
    }
  s = 0 ;
  for(j=0; j<image->hauteur; j++)
    for(i=0; i<image->largeur; i++)
      s += (j*image->pixels[j][i])/(i+1) ;
  if ( s != 5709193 )
    eprintf("Mauvais pixels : Checksum = %d\n", s) ;
}

variable_types: s int


decompiled_code:
__int64 psycho_tst()
{
__int64 result; // rax
int v1[98]; // [rsp+0h] [rbp-188h] BYREF

qmemcpy(v1, &t_1, 0x174uLL);
psycho(93LL, v1, 1.0);
result = 0LL;
while ( *(float *)&t_ok_0[result] == *(float *)&v1[result] )
{
if ( ++result == 93 )
return result * 4;
}
return eprintf("Voir le source du test\n");
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1[98]; // [rsp+0h] [rbp-188h] BYREF

qmemcpy(v1, &t_1, 0x174uLL);
psycho(93LL, v1, 1.0);
result = 0LL;
while ( *(float *)&t_ok_0[result] == *(float *)&v1[result] )
{
if ( ++result == 93 )
return result * 4;
}
return eprintf("Voir le source du test\n");
}

variable_types:
t
float []

variable_types:
tt
float [-1]


psycho

decompiled_code:
void psycho()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void psycho(int nbe, float *dct, float c)
{
}

variable_types:
dct
float *

variable_types: c float


eprintf

decompiled_code:
int eprintf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( premiere )
{
premiere = 0;
fwrite("\n\n************** ERREUR ! ***************\n\n", 1uLL, 0x2BuLL, stderr);
}
va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( premiere )
{
premiere = 0;
fwrite("\n\n************** ERREUR ! ***************\n\n", 1uLL, 0x2BuLL, stderr);
}
va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
int eprintf(const char *format, ...)
{
    va_list ap;
    int i ;
    if ( premiere )
      {
 premiere = 0 ;
 fprintf(stderr, "\n\n************** ERREUR ! ***************\n\n") ;
      }
    __builtin_va_start(ap,format);
    i = vfprintf(stderr, format, ap );
    __builtin_va_end(ap);
    return(i) ;
}

canonical_original_code:
int eprintf(char *format, ...)
{
    __builtin_va_list ap;
    int i;
    if ( premiere )
      {
 premiere = 0 ;
 fprintf(stderr, "\n\n************** ERREUR ! ***************\n\n") ;
      }
    __builtin_va_start(ap,format);
    i = vfprintf(stderr, format, ap );
    __builtin_va_end(ap);
    return(i) ;
}

variable_types:
format
char *


decompiled_code:
_BOOL8 eprintf_utilisee()
{
return premiere == 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return premiere == 0;
}

original_code:
int eprintf_utilisee()
{
  return(premiere==0) ;
}


htonHeader

decompiled_code:
__int16 __fastcall htonHeader(int a1, __int16 *a2)
{
__int16 result; // ax

*a2 = _bswap_16(a1);
result = _bswap_16(SHIWORD(a1));
a2[1] = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func2(int a1, __int16 *a2)
{
__int16 result; // ax

*a2 = func0(a1);
result = func0(SHIWORD(a1));
a2[1] = result;
return result;
}

original_code:
void htonHeader(pkt_header head, char* buffer) {
    uint16_t type, len;
    type = htons(head.type);
    memcpy(buffer+0,&type,2);
    len = htons(head.length);
    memcpy(buffer+2,&len,2);
}

canonical_original_code:
void htonHeader(struct pkt_header head, char *buffer) {
    unsigned short type; unsigned short len;
    type = htons(head.type);
    memcpy(buffer+0,&type,2);
    len = htons(head.length);
    memcpy(buffer+2,&len,2);
}

variable_types: struct pkt_header { unsigned short type; unsigned short length; }

variable_types:
buffer
char *

variable_types:
type
unsigned short

variable_types:
len
unsigned short


htonProxyInfo

decompiled_code:
__int64 __fastcall htonProxyInfo(__int64 a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a2 = _bswap_32(*(_DWORD *)a1);
*(_WORD *)(a2 + 4) = _bswap_16(*(_WORD *)(a1 + 4));
*(_DWORD *)(a2 + 6) = *(_DWORD *)(a1 + 6);
result = *(unsigned __int16 *)(a1 + 10);
*(_WORD *)(a2 + 10) = result;
return result;
}

original_code:
void htonProxyInfo(proxy_info* proxy, char* buffer) {
    uint32_t ip = htonl(proxy->ip);
    memcpy(buffer,&ip,4);
    uint16_t portno = htons(proxy->portno);
    memcpy(buffer+4,&portno,2);
    memcpy(buffer+6,&proxy->macaddr,6);
}

canonical_original_code:
void htonProxyInfo(struct proxy_info *proxy, char *buffer) {
    unsigned int ip = htonl(proxy->ip);
    memcpy(buffer,&ip,4);
    unsigned short portno = htons(proxy->portno);
    memcpy(buffer+4,&portno,2);
    memcpy(buffer+6,&proxy->macaddr,6);
}

variable_types: struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } *

variable_types:
ip
unsigned int

variable_types:
portno
unsigned short


htonLinkstate

original_code:
void htonLinkstate(linkstate_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    uint16_t numNeighbors;
    numNeighbors = htons(pkt->numNeighbors);
    memcpy(buffer+4,&numNeighbors,2);
    htonProxyInfo(&pkt->source,buffer+6);
    linkstate_node* list = pkt->list;
    int i = 0;
    while (list != ((void *)0)) {
        htonProxyInfo(&list->local,buffer+18+36*i);
        htonProxyInfo(&list->remote,buffer+30+36*i);
        uint32_t linkweight;
        linkweight = htonl(list->linkweight);
        memcpy(buffer+42+36*i,&linkweight,4);
        uint64_t ID;
        ID = htonll(list->ID);
        memcpy(buffer+46+36*i,&ID,8);
        list = list->next;
        i++;
    }
}

canonical_original_code:
void htonLinkstate(struct linkstate_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    unsigned short numNeighbors;
    numNeighbors = htons(pkt->numNeighbors);
    memcpy(buffer+4,&numNeighbors,2);
    htonProxyInfo(&pkt->source,buffer+6);
    struct linkstate_node *list = pkt->list;
    int i = 0;
    while (list != ((void *)0)) {
        htonProxyInfo(&list->local,buffer+18+36*i);
        htonProxyInfo(&list->remote,buffer+30+36*i);
        unsigned int linkweight;
        linkweight = htonl(list->linkweight);
        memcpy(buffer+42+36*i,&linkweight,4);
        unsigned long ID;
        ID = htonll(list->ID);
        memcpy(buffer+46+36*i,&ID,8);
        list = list->next;
        i++;
    }
}

variable_types: struct linkstate_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; unsigned short numNeighbors; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } source; struct linkstate_node { struct proxy_info local; struct proxy_info remote; unsigned int linkweight; unsigned long ID; struct linkstate_node *next; } *list; } *

variable_types:
numNeighbors
unsigned short

variable_types: struct linkstate_node { struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; struct proxy_info remote; unsigned int linkweight; unsigned long ID; struct linkstate_node *next; } *

variable_types:
linkweight
unsigned int

variable_types:
ID
unsigned long

user_defined_types: struct linkstate_pkt { struct pkt_header head; unsigned short numNeighbors; struct proxy_info source; struct linkstate_node *list; }


htonData

decompiled_code:
__int64 __fastcall htonData(__int64 a1, __int64 a2)
{
__int64 result; // rax

htonHeader(*(_DWORD *)a1, (__int16 *)a2);
*(_QWORD *)(a2 + 4) = *(_QWORD *)(a1 + 8);
result = *(_QWORD *)(a1 + 2048);
*(_QWORD *)(a2 + 2044) = result;
qmemcpy(
(void *)((a2 + 12) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a1 + 8 - (a2 + 4 - ((a2 + 12) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((_DWORD)a2 + 4 - (((_DWORD)a2 + 12) & 0xFFFFFFF8) + 2048) >> 3));
return result;
}

original_code:
void htonData(data_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    memcpy(buffer+4,&pkt->data,2048);
}

canonical_original_code:
void htonData(struct data_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    memcpy(buffer+4,&pkt->data,2048);
}

variable_types: struct data_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; void *data; } *

user_defined_types: struct data_pkt { struct pkt_header head; void *data; }


htonLeave

decompiled_code:
__int64 __fastcall htonLeave(__int64 a1, __int64 a2)
{
__int64 result; // rax

htonHeader(*(_DWORD *)a1, (__int16 *)a2);
htonProxyInfo(a1 + 4, a2 + 4);
result = htonll(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 result; // rax

func2(*(_DWORD *)a1, (__int16 *)a2);
func3(a1 + 4, a2 + 4);
result = htonll(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

original_code:
void htonLeave(leave_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    uint64_t ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

canonical_original_code:
void htonLeave(struct leave_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    unsigned long ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

variable_types: struct leave_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *

user_defined_types: struct leave_pkt { struct pkt_header head; struct proxy_info local; unsigned long ID; }


ntohLeave

decompiled_code:
char *__fastcall ntohLeave(__int64 a1)
{
char *v1; // rbx
_WORD *v2; // r13
_WORD *v3; // rbp

v1 = (char *)malloc(0x18uLL);
v2 = ntohHeader((__int16 *)a1);
*(_DWORD *)v1 = *(_DWORD *)v2;
v3 = ntohProxyInfo(a1 + 4);
*(_QWORD *)(v1 + 4) = *(_QWORD *)v3;
*((_DWORD *)v1 + 3) = *((_DWORD *)v3 + 2);
*((_QWORD *)v1 + 2) = htonll(*(_QWORD *)(a1 + 16));
free(v2);
free(v3);
return v1;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
char *v1; // rbx
_WORD *v2; // r13
_WORD *v3; // rbp

v1 = (char *)malloc(0x18uLL);
v2 = ntohHeader((__int16 *)a1);
*(_DWORD *)v1 = *(_DWORD *)v2;
v3 = ntohProxyInfo(a1 + 4);
*(_QWORD *)(v1 + 4) = *(_QWORD *)v3;
*((_DWORD *)v1 + 3) = *((_DWORD *)v3 + 2);
*((_QWORD *)v1 + 2) = htonll(*(_QWORD *)(a1 + 16));
free(v2);
free(v3);
return v1;
}

original_code:
leave_pkt* ntohLeave(char *buffer) {
    leave_pkt* pkt = malloc(sizeof(leave_pkt));
    pkt_header* head = ntohHeader(buffer);
    pkt->head = *head;
    proxy_info* local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    uint64_t ID;
    ID = htonll(*(uint64_t*)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

canonical_original_code:
struct leave_pkt *ntohLeave(char *buffer) {
    struct leave_pkt *pkt = malloc(sizeof(leave_pkt));
    struct pkt_header *head = ntohHeader(buffer);
    pkt->head = *head;
    struct proxy_info *local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    unsigned long ID;
    ID = htonll(*(unsigned long *)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

variable_types: struct pkt_header { unsigned short type; unsigned short length; } *

return_type: struct leave_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *