main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r15
unsigned int v4; // er14
char v5; // r13
int v6; // er12
int v7; // ebx
int v8; // ebp
int v9; // eax
unsigned int v10; // eax
int result; // eax
char v12; // [rsp+Fh] [rbp-49h]
char *endptr[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = argv;
endptr[0] = 0LL;
if ( argc <= 1 )
{
v12 = 0;
v5 = 0;
v7 = 80;
v8 = 45;
LABEL_4:
v6 = detect_mode(*(_QWORD *)&argc, argv, envp);
goto LABEL_18;
}
v4 = argc;
v12 = 0;
v5 = 0;
v6 = 0;
v7 = 80;
v8 = 45;
while ( 1 )
{
argv = v3;
*(_QWORD *)&argc = v4;
v9 = getopt(v4, (char *const *)v3, "fdu:l:m:i:");
if ( v9 == -1 )
break;
switch ( v9 )
{
case 'd':
v12 = 1;
break;
case 'f':
v5 = 1;
break;
case 'l':
v8 = strtol(optarg, endptr, 0);
if ( endptr[0] == optarg )
showHelp(*v3);
return result;
case 'm':
v10 = strtol(optarg, endptr, 10);
v6 = v10;
if ( endptr[0] == optarg || v10 > 2 )
showHelp(*v3);
return result;
case 'u':
v7 = strtol(optarg, endptr, 0);
if ( endptr[0] == optarg )
showHelp(*v3);
return result;
default:
showHelp(*v3);
}
}
if ( !v6 )
goto LABEL_4;
LABEL_18:
if ( v6 < 0 )
{
fwrite("Unable to detect kernel 3.0 style or 3.8 style TMU or PWM\n", 1uLL, 0x3AuLL, stderr);
showHelp(*v3);
}
if ( v7 > 100 )
{
fwrite("Upper temperature cannot be above 100C\n", 1uLL, 0x27uLL, stderr);
showHelp(*v3);
}
if ( v8 > v7 )
{
fwrite("Upper temperature must be greater than or equal to lower temperature\n", 1uLL, 0x45uLL, stderr);
showHelp(*v3);
}
if ( !v12 )
{
while ( 1 )
{
LABEL_22:
sleep(1u);
u2_service(v6 - 1, v8, v7, v5, v12 ^ 1);
}
}
if ( !fork() )
{
fclose(stdout);
fclose(stderr);
goto LABEL_22;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r15
unsigned int v4; // er14
char v5; // r13
int v6; // er12
int v7; // ebx
int v8; // ebp
int v9; // eax
unsigned int v10; // eax
int result; // eax
char v12; // [rsp+Fh] [rbp-49h]
char *endptr[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = argv;
endptr[0] = 0LL;
if ( argc <= 1 )
{
v12 = 0;
v5 = 0;
v7 = 80;
v8 = 45;
LABEL_4:
v6 = func7(*(_QWORD *)&argc, argv, envp);
goto LABEL_18;
}
v4 = argc;
v12 = 0;
v5 = 0;
v6 = 0;
v7 = 80;
v8 = 45;
while ( 1 )
{
argv = v3;
*(_QWORD *)&argc = v4;
v9 = getopt(v4, (char *const *)v3, "fdu:l:m:i:");
if ( v9 == -1 )
break;
switch ( v9 )
{
case 'd':
v12 = 1;
break;
case 'f':
v5 = 1;
break;
case 'l':
v8 = strtol(optarg, endptr, 0);
if ( endptr[0] == optarg )
func9(*v3);
return result;
case 'm':
v10 = strtol(optarg, endptr, 10);
v6 = v10;
if ( endptr[0] == optarg || v10 > 2 )
func9(*v3);
return result;
case 'u':
v7 = strtol(optarg, endptr, 0);
if ( endptr[0] == optarg )
func9(*v3);
return result;
default:
func9(*v3);
}
}
if ( !v6 )
goto LABEL_4;
LABEL_18:
if ( v6 < 0 )
{
fwrite("Unable to detect kernel 3.0 style or 3.8 style TMU or PWM\n", 1uLL, 0x3AuLL, stderr);
func9(*v3);
}
if ( v7 > 100 )
{
fwrite("Upper temperature cannot be above 100C\n", 1uLL, 0x27uLL, stderr);
func9(*v3);
}
if ( v8 > v7 )
{
fwrite("Upper temperature must be greater than or equal to lower temperature\n", 1uLL, 0x45uLL, stderr);
func9(*v3);
}
if ( !v12 )
{
while ( 1 )
{
LABEL_22:
sleep(1u);
func8(v6 - 1, v8, v7, v5, v12 ^ 1);
}
}
if ( !fork() )
{
fclose(stdout);
fclose(stderr);
goto LABEL_22;
}
return 0;
}

original_code:
int main ( int argc, char *argv[] )
{
    int lower = 45;
    int upper = 80;
    int mode = 0;
    _Bool forceUpdates = 0;
    _Bool daemon = 0;
    int interval = 1;
    char * tmp = 0;
    if ( argc > 1 )
    {
        int opt = 0;
        while ( ( opt = getopt ( argc, argv, "fdu:l:m:i:" ) ) != -1 )
        {
            switch ( opt )
            {
                case 'f':
                    forceUpdates = 1;
                    break;
                case 'd':
                    daemon = 1;
                    break;
                case 'u':
                    upper = strtol ( optarg, &tmp, 0 );
                    if ( tmp == optarg )
                        showHelp ( argv[0] );
                    break;
                case 'l':
                    lower = strtol ( optarg, &tmp, 0 );
                    if ( tmp == optarg )
                        showHelp ( argv[0] );
                    break;
                case 'm':
                    mode = strtol ( optarg, &tmp, 10 );
                    if ( tmp == optarg || mode < 0 || mode > 2 )
                        showHelp ( argv[0] );
                    break;
                default:
                    showHelp ( argv[0] );
            }
        }
    }
    if ( mode == 0 )
    {
        mode = detect_mode();
    }
    if ( mode < 0 )
    {
        fprintf ( stderr, "Unable to detect kernel 3.0 style or 3.8 style TMU or PWM\n" );
        showHelp ( argv[0] );
    }
    if ( upper > 100 )
    {
        fprintf ( stderr, "Upper temperature cannot be above 100C\n" );
        showHelp ( argv[0] );
    }
    if ( upper < lower || lower > upper )
    {
        fprintf ( stderr, "Upper temperature must be greater than or equal to lower temperature\n" );
        showHelp ( argv[0] );
    }
    if ( ! daemon || fork() == 0 )
    {
        if ( daemon )
        {
            fclose ( stdout );
            fclose ( stderr );
        }
        while ( 1 )
        {
            sleep ( interval );
            u2_service ( mode - 1, lower, upper, forceUpdates, ! daemon );
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int lower = 45;
    int upper = 80;
    int mode = 0;
    _Bool forceUpdates = 0;
    _Bool daemon = 0;
    int interval = 1;
    char *tmp = 0;
    if ( argc > 1 )
    {
        int opt = 0;
        while ( ( opt = getopt ( argc, argv, "fdu:l:m:i:" ) ) != -1 )
        {
            switch ( opt )
            {
                case 'f':
                    forceUpdates = 1;
                    break;
                case 'd':
                    daemon = 1;
                    break;
                case 'u':
                    upper = strtol ( optarg, &tmp, 0 );
                    if ( tmp == optarg )
                        showHelp ( argv[0] );
                    break;
                case 'l':
                    lower = strtol ( optarg, &tmp, 0 );
                    if ( tmp == optarg )
                        showHelp ( argv[0] );
                    break;
                case 'm':
                    mode = strtol ( optarg, &tmp, 10 );
                    if ( tmp == optarg || mode < 0 || mode > 2 )
                        showHelp ( argv[0] );
                    break;
                default:
                    showHelp ( argv[0] );
            }
        }
    }
    if ( mode == 0 )
    {
        mode = detect_mode();
    }
    if ( mode < 0 )
    {
        fprintf ( stderr, "Unable to detect kernel 3.0 style or 3.8 style TMU or PWM\n" );
        showHelp ( argv[0] );
    }
    if ( upper > 100 )
    {
        fprintf ( stderr, "Upper temperature cannot be above 100C\n" );
        showHelp ( argv[0] );
    }
    if ( upper < lower || lower > upper )
    {
        fprintf ( stderr, "Upper temperature must be greater than or equal to lower temperature\n" );
        showHelp ( argv[0] );
    }
    if ( ! daemon || fork() == 0 )
    {
        if ( daemon )
        {
            fclose ( stdout );
            fclose ( stderr );
        }
        while ( 1 )
        {
            sleep ( interval );
            u2_service ( mode - 1, lower, upper, forceUpdates, ! daemon );
        }
    }
    return 0;
}

variable_types: lower int

variable_types: upper int

variable_types: mode int

variable_types: interval int

variable_types:
tmp
char *

variable_types: opt int


resetCrate

repo: sevko/termcrate

decompiled_code:
__int64 resetCrate()
{
unsigned int v0; // eax
__int64 result; // rax

audio("res/audio/crate.wav");
v0 = time(0LL);
srand(v0);
LODWORD(crate) = rand() % 176;
HIDWORD(crate) = rand() % 44;
result = weapons[rand() % 3];
*(__int64 *)((char *)&crate + 12) = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
__int64 result; // rax

audio("res/audio/crate.wav");
v0 = time(0LL);
srand(v0);
LODWORD(crate) = rand() % 176;
HIDWORD(crate) = rand() % 44;
result = weapons[rand() % 3];
*(__int64 *)((char *)&crate + 12) = result;
return result;
}

original_code:
void resetCrate(){
 audio("res/audio/" "crate.wav");
 srand(time(((void *)0)));
 _crate.geo.x = rand() % 176;
 _crate.geo.y = rand() % 44;
 _crate.weapon = _weapons[rand() % 3];
}

return_type: void


resetMessage

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

result = *((unsigned int *)&crate + 4);
switch ( (_DWORD)result )
{
case 2:
messages[14] = 75;
break;
case 0xF:
messages[2] = 75;
break;
case 0x1E:
messages[8] = 75;
break;
}
return result;
}

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

result = *((unsigned int *)&crate + 4);
switch ( (_DWORD)result )
{
case 2:
messages[14] = 75;
break;
case 0xF:
messages[2] = 75;
break;
case 0x1E:
messages[8] = 75;
break;
}
return result;
}

original_code:
void resetMessage(){
 if(_crate.weapon.rof == 2)
  _messages[2].display = 75;
 if(_crate.weapon.rof == 15)
  _messages[0].display = 75;
 if(_crate.weapon.rof == 30)
  _messages[1].display = 75;
}


updateCrate

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

if ( !(unsigned int)onSurface(crate, *((unsigned int *)&crate + 2)) )
++HIDWORD(crate);
result = collision(crate, *((unsigned int *)&crate + 2), player, *((unsigned int *)&player + 2));
if ( (_DWORD)result )
{
*(__int64 *)((char *)&player + 12) = *(__int64 *)((char *)&crate + 12);
++*((_DWORD *)&player + 8);
resetMessage();
result = resetCrate();
}
return result;
}

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

if ( !(unsigned int)onSurface(crate, *((unsigned int *)&crate + 2)) )
++HIDWORD(crate);
result = collision(crate, *((unsigned int *)&crate + 2), player, *((unsigned int *)&player + 2));
if ( (_DWORD)result )
{
*(__int64 *)((char *)&player + 12) = *(__int64 *)((char *)&crate + 12);
++*((_DWORD *)&player + 8);
func1();
result = func0();
}
return result;
}

original_code:
void updateCrate(){
 if(!onSurface(_crate.geo))
  _crate.geo.y++;
 if(collision(_crate.geo, _player.geo)){
  _player.weapon = _crate.weapon;
  _player.score++;
  resetMessage();
  resetCrate();
 }
}


spawnEnemy

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

result = (unsigned int)(200 * (tickCount / 200));
if ( tickCount == (_DWORD)result && numEnemies <= 49 )
result = addActor(1LL);
return result;
}

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

result = (unsigned int)(200 * (tickCount / 200));
if ( tickCount == (_DWORD)result && numEnemies <= 49 )
result = addActor(1LL);
return result;
}

original_code:
void spawnEnemy(){
 if(_tickCount % 200 == 0 && _numEnemies < 50){
  Actor_t enemy = _elements.enemy;
  enemy.geo.x = 88;
  addActor(1, enemy);
 }
}

canonical_original_code:
void spawnEnemy(){
 if(_tickCount % 200 == 0 && _numEnemies < 50){
  struct Actor_t enemy = _elements.enemy;
  enemy.geo.x = 88;
  addActor(1, enemy);
 }
}

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; }


enemyMove

original_code:
void enemyMove(Actor_t * enem) {
 if(_tickCount % 2 == 0) {
  if(enem->geo.y >= 44) {
   enem->geo.y = 0;
   enem->dirMotion *= -1;
  }
  if(enem->geo.x >= 176 - 1 || enem->geo.x <= 1) {
   enem->dirMotion *= -1;
  }
  enem->geo.x += enem->dirMotion;
  if(!onSurface(enem->geo)) {
   enem->geo.y += 1;
  }
 }
}

canonical_original_code:
void enemyMove(struct Actor_t *enem) {
 if(_tickCount % 2 == 0) {
  if(enem->geo.y >= 44) {
   enem->geo.y = 0;
   enem->dirMotion *= -1;
  }
  if(enem->geo.x >= 176 - 1 || enem->geo.x <= 1) {
   enem->dirMotion *= -1;
  }
  enem->geo.x += enem->dirMotion;
  if(!onSurface(enem->geo)) {
   enem->geo.y += 1;
  }
 }
}

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


updateEnemies

decompiled_code:
__int64 updateEnemies()
{
_QWORD *v0; // rbx
int v1; // ebp

if ( numEnemies > 0 )
{
v0 = &enemies;
v1 = 0;
while ( !(unsigned int)collision(*v0, *((unsigned int *)v0 + 2), player, *((unsigned int *)&player + 2)) )
{
enemyMove((int *)v0);
++v1;
v0 = (_QWORD *)((char *)v0 + 20);
if ( numEnemies <= v1 )
goto LABEL_7;
}
gameLost = 1;
}
LABEL_7:
spawnEnemy();
return expireActors(&enemies, &numEnemies);
}

canonical_decompiled_code:
__int64 func5()
{
_QWORD *v0; // rbx
int v1; // ebp

if ( numEnemies > 0 )
{
v0 = &enemies;
v1 = 0;
while ( !(unsigned int)collision(*v0, *((unsigned int *)v0 + 2), player, *((unsigned int *)&player + 2)) )
{
func4((int *)v0);
++v1;
v0 = (_QWORD *)((char *)v0 + 20);
if ( numEnemies <= v1 )
goto LABEL_7;
}
gameLost = 1;
}
LABEL_7:
func3();
return expireActors(&enemies, &numEnemies);
}

original_code:
void updateEnemies(){
 int enem;
 for(enem = 0; enem < _numEnemies; enem++){
  Actor_t * mob = &_enemies[enem];
  if(collision(mob->geo, _player.geo)){
   _gameLost = 1;
   break;
  }
  enemyMove(mob);
 }
 spawnEnemy();
 expireActors(_enemies, &_numEnemies);
}

canonical_original_code:
void updateEnemies(){
 int enem;
 for(enem = 0; enem < _numEnemies; enem++){
  struct Actor_t *mob = &_enemies[enem];
  if(collision(mob->geo, _player.geo)){
   _gameLost = 1;
   break;
  }
  enemyMove(mob);
 }
 spawnEnemy();
 expireActors(_enemies, &_numEnemies);
}

variable_types: enem int


spawnBullet

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

result = audio("res/audio/gunshot.wav");
if ( numBullets <= 49 )
{
result = addActor(0LL);
*((_DWORD *)&player + 6) = 0;
}
return result;
}

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

result = audio("res/audio/gunshot.wav");
if ( numBullets <= 49 )
{
result = addActor(0LL);
*((_DWORD *)&player + 6) = 0;
}
return result;
}

original_code:
void spawnBullet(){
 audio("res/audio/" "gunshot.wav");
 if(_numBullets < 50) {
  Actor_t bull = _elements.bullet;
  bull.geo.x = _player.geo.x;
  bull.geo.y = _player.geo.y;
  bull.dirMotion = _player.dirMotion;
  addActor(0, bull);
  _player.reload = 0;
 }
}

canonical_original_code:
void spawnBullet(){
 audio("res/audio/" "gunshot.wav");
 if(_numBullets < 50) {
  struct Actor_t bull = _elements.bullet;
  bull.geo.x = _player.geo.x;
  bull.geo.y = _player.geo.y;
  bull.dirMotion = _player.dirMotion;
  addActor(0, bull);
  _player.reload = 0;
 }
}


bulletMove

decompiled_code:
__int64 __fastcall bulletMove(int *a1)
{
int v1; // edx
__int64 result; // rax

v1 = *a1;
result = 178LL * (a1[1] - 1);
if ( mapBuf[*a1 + result] == 64 || (result = (unsigned int)(v1 - 1), (unsigned int)result > 0xAE) )
a1[4] = 0;
*a1 = a1[3] + v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
int v1; // edx
__int64 result; // rax

v1 = *a1;
result = 178LL * (a1[1] - 1);
if ( mapBuf[*a1 + result] == 64 || (result = (unsigned int)(v1 - 1), (unsigned int)result > 0xAE) )
a1[4] = 0;
*a1 = a1[3] + v1;
return result;
}

original_code:
void bulletMove(Actor_t * bull) {
 if(_tickCount % 1 == 0) {
  int inSurface = mapBuf[bull->geo.y - 1][bull->geo.x] == '@';
  if(bull->geo.x >= 176 || bull->geo.x <= 0 || inSurface) {
   bull->alive = 0;
  }
  bull->geo.x += bull->dirMotion;
 }
}

canonical_original_code:
void bulletMove(struct Actor_t *bull) {
 if(_tickCount % 1 == 0) {
  int inSurface = mapBuf[bull->geo.y - 1][bull->geo.x] == '@';
  if(bull->geo.x >= 176 || bull->geo.x <= 0 || inSurface) {
   bull->alive = 0;
  }
  bull->geo.x += bull->dirMotion;
 }
}

variable_types: inSurface int


updateBullets

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

if ( numBullets > 0 )
{
v0 = (int *)&bullets;
v1 = 0;
do
{
if ( numEnemies > 0 )
{
v3 = (unsigned int *)&enemies;
v2 = 0;
do
{
if ( (unsigned int)collision(*(_QWORD *)v0, (unsigned int)v0[2], *(_QWORD *)v3, v3[2]) )
{
v3[4] = 0;
v0[4] = 0;
}
++v2;
v3 += 5;
}
while ( numEnemies > v2 );
}
bulletMove(v0);
++v1;
v0 += 5;
}
while ( numBullets > v1 );
}
return expireActors(&bullets, &numBullets);
}

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

if ( numBullets > 0 )
{
v0 = (int *)&bullets;
v1 = 0;
do
{
if ( numEnemies > 0 )
{
v3 = (unsigned int *)&enemies;
v2 = 0;
do
{
if ( (unsigned int)collision(*(_QWORD *)v0, (unsigned int)v0[2], *(_QWORD *)v3, v3[2]) )
{
v3[4] = 0;
v0[4] = 0;
}
++v2;
v3 += 5;
}
while ( numEnemies > v2 );
}
func7(v0);
++v1;
v0 += 5;
}
while ( numBullets > v1 );
}
return expireActors(&bullets, &numBullets);
}

original_code:
void updateBullets(){
 int bull, enem;
 for(bull = 0; bull < _numBullets; bull++){
  Actor_t * ammo = &_bullets[bull];
  for(enem = 0; enem < _numEnemies; enem++) {
   Actor_t * mob = &_enemies[enem];
   if(collision(ammo->geo, mob->geo))
    ammo->alive = mob->alive = 0;
  }
  bulletMove(ammo);
 }
 expireActors(_bullets, &_numBullets);
}

canonical_original_code:
void updateBullets(){
 int bull; int enem;
 for(bull = 0; bull < _numBullets; bull++){
  struct Actor_t *ammo = &_bullets[bull];
  for(enem = 0; enem < _numEnemies; enem++) {
   struct Actor_t *mob = &_enemies[enem];
   if(collision(ammo->geo, mob->geo))
    ammo->alive = mob->alive = 0;
  }
  bulletMove(ammo);
 }
 expireActors(_bullets, &_numBullets);
}

variable_types: bull int


updateKeys

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

while ( 1 )
{
result = getkey();
switch ( (_DWORD)result )
{
case 0xFFFFFFFE:
return result;
case 0x77:
keys = 1;
goto LABEL_3;
case 0x61:
*(&keys + 1) = 1;
goto LABEL_11;
case 0x64:
*(&keys + 2) = 1;
break;
default:
LABEL_3:
if ( (_DWORD)result == 106 )
{
*(&keys + 3) = 1;
}
else
{
LABEL_11:
if ( (_DWORD)result == -31 )
gameLost = 1;
}
break;
}
}
}

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

while ( 1 )
{
result = getkey();
switch ( (_DWORD)result )
{
case 0xFFFFFFFE:
return result;
case 0x77:
keys = 1;
goto LABEL_3;
case 0x61:
*(&keys + 1) = 1;
goto LABEL_11;
case 0x64:
*(&keys + 2) = 1;
break;
default:
LABEL_3:
if ( (_DWORD)result == 106 )
{
*(&keys + 3) = 1;
}
else
{
LABEL_11:
if ( (_DWORD)result == -31 )
gameLost = 1;
}
break;
}
}
}

original_code:
void updateKeys() {
 int key;
 while((key = getkey()) != -2) {
  if(key == 'w')
   _keys.up = 1;
  if(key == 'a')
   _keys.left = 1;
  if(key == 'd')
   _keys.right = 1;
  if(key == 'j')
   _keys.fire = 1;
  if(key == -31)
   _gameLost = 1;
 }
}

variable_types: key int


moveUp

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

result = onSurface(player, *((unsigned int *)&player + 2));
if ( (_DWORD)result )
{
if ( SHIDWORD(player) > 0 )
{
result = audio("res/audio/jump.wav");
*((_DWORD *)&player + 7) = 15;
}
}
return result;
}

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

result = onSurface(player, *((unsigned int *)&player + 2));
if ( (_DWORD)result )
{
if ( SHIDWORD(player) > 0 )
{
result = audio("res/audio/jump.wav");
*((_DWORD *)&player + 7) = 15;
}
}
return result;
}

original_code:
void moveUp() {
 if(onSurface(_player.geo) && _player.geo.y > 0) {
  audio("res/audio/" "jump.wav");
  _player.jumpTime = 15;
 }
}


moveLeft

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

result = (unsigned int)player;
if ( (int)player > 1 )
{
result = (unsigned int)(player - 1);
LODWORD(player) = player - 1;
*((_DWORD *)&player + 5) = -1;
}
return result;
}

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

result = (unsigned int)player;
if ( (int)player > 1 )
{
result = (unsigned int)(player - 1);
LODWORD(player) = player - 1;
*((_DWORD *)&player + 5) = -1;
}
return result;
}

original_code:
void moveLeft() {
 if(_player.geo.x > 1) {
  _player.geo.x -= 1;
  _player.dirMotion = -1;
 }
}


moveRight

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

result = (unsigned int)player;
if ( (int)player <= 175 )
{
result = (unsigned int)(player + 1);
LODWORD(player) = player + 1;
*((_DWORD *)&player + 5) = 1;
}
return result;
}

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

result = (unsigned int)player;
if ( (int)player <= 175 )
{
result = (unsigned int)(player + 1);
LODWORD(player) = player + 1;
*((_DWORD *)&player + 5) = 1;
}
return result;
}

original_code:
void moveRight() {
 if(_player.geo.x < 176) {
  _player.geo.x += 1;
  _player.dirMotion = 1;
 }
}


updatePlayer

decompiled_code:
__int64 updatePlayer()
{
updateKeys();
if ( keys )
moveUp();
if ( *(&keys + 1) )
moveLeft();
if ( *(&keys + 2) )
moveRight();
if ( *(&keys + 3) && *((_DWORD *)&player + 6) >= *((_DWORD *)&player + 4) )
spawnBullet(*((unsigned int *)&player + 5));
clearKeys();
++*((_DWORD *)&player + 6);
return gravity();
}

canonical_decompiled_code:
__int64 func13()
{
func9();
if ( keys )
func10();
if ( *(&keys + 1) )
func11();
if ( *(&keys + 2) )
func12();
if ( *(&keys + 3) && *((_DWORD *)&player + 6) >= *((_DWORD *)&player + 4) )
func6(*((unsigned int *)&player + 5));
clearKeys();
++*((_DWORD *)&player + 6);
return gravity();
}

original_code:
void updatePlayer(){
 updateKeys();
 if(_tickCount % 1 == 0) {
  if(_keys.up)
   moveUp();
  if(_keys.left)
   moveLeft();
  if(_keys.right)
   moveRight();
  if(_keys.fire && _player.reload >= _player.weapon.rof)
   spawnBullet(_player.dirMotion);
  clearKeys();
  _player.reload += 1;
 }
 gravity();
}


tick

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

updateBullets();
updateEnemies();
updatePlayer();
result = updateCrate();
++tickCount;
return result;
}

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

func8();
func5();
func13();
result = func2();
++tickCount;
return result;
}

original_code:
void tick(){
 updateBullets();
 updateEnemies();
 updatePlayer();
 updateCrate();
 _tickCount++;
}


game

decompiled_code:
__int64 game()
{
config();
while ( !gameLost )
{
usleep(0x411Au);
render();
tick();
}
return menu();
}

canonical_decompiled_code:
__int64 func15()
{
config();
while ( !gameLost )
{
usleep(0x411Au);
render();
func14();
}
return menu();
}

original_code:
void game(){
 config();
 while(!_gameLost){
  usleep((1000000 / 60));
  render();
  tick();
 }
 menu();
}


moveDown

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

result = onSurface(player, *((unsigned int *)&player + 2));
if ( !(_DWORD)result )
++HIDWORD(player);
return result;
}

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

result = onSurface(player, *((unsigned int *)&player + 2));
if ( !(_DWORD)result )
++HIDWORD(player);
return result;
}

original_code:
void moveDown() {
 if(!onSurface(_player.geo))
  _player.geo.y += 1;
}


main

canonical_name: main

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

original_code:
int main(){
 menu();
 return 0;
}

canonical_original_code:
int main(){
 menu();
 return 0;
}

return_type: int


configMenu

original_code:
void configMenu(){
 stopAudio();
 Button_t play = {
  .x = ((176 / 2) - 2),
  .y = 16,
  .name = "play"
 };
 Button_t exit = {
  .x = ((176 / 2) - 2),
  .y = 22,
  .name = "exit"
 };
 _buttons[0] = play;
 _buttons[1] = exit;
 audio("res/audio/" "themeMenu.wav");
}

canonical_original_code:
void configMenu(){
 stopAudio();
 struct Button_t play = {
  .x = ((176 / 2) - 2),
  .y = 16,
  .name = "play"
 };
 struct Button_t exit = {
  .x = ((176 / 2) - 2),
  .y = 22,
  .name = "exit"
 };
 _buttons[0] = play;
 _buttons[1] = exit;
 audio("res/audio/" "themeMenu.wav");
}

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


menuMoveUp

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

result = (unsigned int)selectedButton;
if ( selectedButton > 0 )
result = (unsigned int)--selectedButton;
return result;
}

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

result = (unsigned int)selectedButton;
if ( selectedButton > 0 )
result = (unsigned int)--selectedButton;
return result;
}

original_code:
void menuMoveUp(){
 if(_selectedButton > 0)
  _selectedButton--;
}


menuMoveDown

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

result = (unsigned int)selectedButton;
if ( selectedButton <= 0 )
result = (unsigned int)++selectedButton;
return result;
}

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

result = (unsigned int)selectedButton;
if ( selectedButton <= 0 )
result = (unsigned int)++selectedButton;
return result;
}

original_code:
void menuMoveDown(){
 if(_selectedButton < 2 - 1)
  _selectedButton++;
}


buttonFunction

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

stopAudio();
result = audio("res/audio/button.wav");
if ( !selectedButton )
result = game();
if ( selectedButton == 1 )
exit(1);
return result;
}

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

stopAudio();
result = audio("res/audio/button.wav");
if ( !selectedButton )
result = game();
if ( selectedButton == 1 )
exit(1);
return result;
}

original_code:
void buttonFunction(){
 stopAudio();
 audio("res/audio/" "button.wav");
 if(_selectedButton == 0)
  game();
 if(_selectedButton == 1)
  exit(1);
}


menu

decompiled_code:
void __noreturn menu()
{
int v0; // eax

configMenu();
((void (*)(void))renderMenu)();
while ( 1 )
{
do
v0 = getkey();
while ( v0 == -2 );
switch ( v0 )
{
case -10:
menuMoveUp();
break;
case -11:
menuMoveDown();
break;
case 10:
buttonFunction();
break;
}
renderMenu((unsigned int)selectedButton);
}
}

canonical_decompiled_code:
void __noreturn func4()
{
int v0; // eax

func0();
((void (*)(void))renderMenu)();
while ( 1 )
{
do
v0 = getkey();
while ( v0 == -2 );
switch ( v0 )
{
case -10:
func1();
break;
case -11:
func2();
break;
case 10:
func3();
break;
}
renderMenu((unsigned int)selectedButton);
}
}

original_code:
void menu(){
 configMenu();
 renderMenu();
 int key;
 while(1){
  if((key = getkey()) != -2){
   if(key == -10)
    menuMoveUp();
   else if(key == -11)
    menuMoveDown();
   else if(key == 10)
    buttonFunction();
   renderMenu(_selectedButton);
  }
 }
}


audio

decompiled_code:
int __fastcall audio(char *src)
{
int result; // eax
char v2[16]; // [rsp+0h] [rbp-48h] BYREF
__int64 v3; // [rsp+10h] [rbp-38h]
__int64 v4; // [rsp+18h] [rbp-30h]
__int64 v5; // [rsp+20h] [rbp-28h]
__int64 v6; // [rsp+28h] [rbp-20h]
__int16 v7; // [rsp+30h] [rbp-18h]

strcpy(v2, "aplay --quiet ");
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0;
strcat(v2, src);
strcat(v2, " &");
result = system(v2);
if ( result == -1 )
exit(1);
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *src)
{
int result; // eax
char v2[16]; // [rsp+0h] [rbp-48h] BYREF
__int64 v3; // [rsp+10h] [rbp-38h]
__int64 v4; // [rsp+18h] [rbp-30h]
__int64 v5; // [rsp+20h] [rbp-28h]
__int64 v6; // [rsp+28h] [rbp-20h]
__int16 v7; // [rsp+30h] [rbp-18h]

strcpy(v2, "aplay --quiet ");
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0;
strcat(v2, src);
strcat(v2, " &");
result = system(v2);
if ( result == -1 )
exit(1);
return result;
}

original_code:
void audio(char * filePath){
 char sysCommand[50] = "aplay --quiet ";
 strcat(sysCommand, filePath);
 strcat(sysCommand, " &");
 if(system(sysCommand) == -1)
  exit(1);
}

canonical_original_code:
void audio(char *filePath){
 char sysCommand[50] = "aplay --quiet ";
 strcat(sysCommand, filePath);
 strcat(sysCommand, " &");
 if(system(sysCommand) == -1)
  exit(1);
}

variable_types:
filePath
char *

variable_types:
sysCommand
char [50]


stopAudio

decompiled_code:
int stopAudio()
{
int result; // eax

result = system("killall -9 aplay");
if ( result == -1 )
exit(1);
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

result = system("killall -9 aplay");
if ( result == -1 )
exit(1);
return result;
}

original_code:
void stopAudio(){
 if(system("killall -9 aplay") == -1)
  exit(1);
}


isBeginningOf

decompiled_code:
__int64 __fastcall isBeginningOf(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

original_code:
static int isBeginningOf(char *s, char *scode) {
 while (*scode) {
  if (*s++ != *scode++)
   return 0;
 }
 return 1;
}

variable_types:
s
char *

variable_types:
scode
char *


decompiled_code:
__int64 get_circ()
{
unsigned int v0; // esi

if ( !dword_358 )
return (unsigned int)-2;
v0 = circ[dword_354];
dword_354 = (dword_354 + 1) % 20;
--dword_358;
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // esi

if ( !dword_358 )
return (unsigned int)-2;
v0 = circ[dword_354];
dword_354 = (dword_354 + 1) % 20;
--dword_358;
return v0;
}

original_code:
static int get_circ(void) {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}

canonical_original_code:
static int get_circ() {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}


decompiled_code:
int getkey_terminate()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

canonical_decompiled_code:
int func4()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

original_code:
void getkey_terminate(void) {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}

canonical_original_code:
void getkey_terminate() {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}


decompiled_code:
int __fastcall xt_par0(const char *a1)
{
return printf("%s", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("%s", a1);
}

original_code:
void xt_par0(char *control_sequence) {
 printf("%s",control_sequence);
}


decompiled_code:
int __fastcall xt_par1(const char *a1)
{
return printf(a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf(a1);
}

original_code:
void xt_par1(char *control_sequence, int parameter1) {
 printf(control_sequence, parameter1);
}


decompiled_code:
int __fastcall xt_par2(const char *a1)
{
return printf(a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return printf(a1);
}

original_code:
void xt_par2(char *control_sequence, int parameter1, int parameter2) {
 printf(control_sequence, parameter1, parameter2);
}


repo: carloslima/deb-pkg-perp

decompiled_code:
__int64 upak_pack(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return upak_vpack(a1, a2, va);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return upak_vpack(a1, a2, va);
}

original_code:
ssize_t
upak_pack(uchar_t *buf, const char *fmt, ...)
{
  va_list args;
  ssize_t w;
  __builtin_va_start(args,fmt);
  w = upak_vpack(buf, fmt, args);
  __builtin_va_end(args);
  return w;
}

canonical_original_code:
long upak_pack(unsigned char *buf, char *fmt, ...)
{
  __builtin_va_list args;
  long w;
  __builtin_va_start(args,fmt);
  w = upak_vpack(buf, fmt, args);
  __builtin_va_end(args);
  return w;
}

variable_types:
buf
unsigned char *

variable_types:
fmt
char *

variable_types: w long

return_type: long


decompiled_code:
__int64 __fastcall cdb_cc(__int64 a1, __int64 a2)
{
return buf_copy(a1, a2, 64LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return buf_copy(a1, a2, 64LL);
}

original_code:
struct cdb *
cdb_cc(struct cdb *dest, const struct cdb *src)
{
    return (struct cdb *)buf_copy(dest, src, sizeof (struct cdb));
}

canonical_original_code:
struct cdb *cdb_cc(struct cdb *dest, struct cdb *src)
{
    return (struct cdb *)buf_copy(dest, src, sizeof (struct cdb));
}

variable_types:
dest
struct cdb *

variable_types:
src
struct cdb *

return_type: struct cdb { int fd; unsigned char *map; unsigned int map_size; unsigned int hbase; unsigned char *key; unsigned int klen; unsigned int h; unsigned int tbase; unsigned int tslots; unsigned int s0; unsigned int sN; unsigned int rpos; unsigned int dlen; } *


decompiled_code:
int __fastcall fd_cloexec(int a1)
{
return fcntl(a1, 2, 1LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
return fcntl(a1, 2, 1LL);
}

original_code:
int
fd_cloexec(int fd)
{
  return fcntl(fd, 2, 1);
}

variable_types: fd int


decompiled_code:
void __fastcall dynstuf_free(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // r13
unsigned __int64 v3; // rbx

v2 = *(_QWORD **)ptr;
if ( a2 && *((_QWORD *)ptr + 2) )
{
v3 = 0LL;
do
a2(v2[v3++]);
while ( *((_QWORD *)ptr + 2) > v3 );
}
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // r13
unsigned __int64 v3; // rbx

v2 = *(_QWORD **)ptr;
if ( a2 && *((_QWORD *)ptr + 2) )
{
v3 = 0LL;
do
a2(v2[v3++]);
while ( *((_QWORD *)ptr + 2) > v3 );
}
free(v2);
free(ptr);
}

original_code:
void
dynstuf_free(struct dynstuf *S, void (*free_data)(void *data))
{
    void **stuf = S->stuf;
    size_t i = 0;
    if(free_data != ((void *)0)){
        for(i = 0; i < S->items; ++i){
            free_data(stuf[i]);
        }
    }
    free(stuf);
    free(S);
    return;
}

canonical_original_code:
void dynstuf_free(struct dynstuf *S, void (*free_data)(void *data))
{
    void **stuf = S->stuf;
    unsigned long i = 0;
    if(free_data != ((void *)0)){
        for(i = 0; i < S->items; ++i){
            free_data(stuf[i]);
        }
    }
    free(stuf);
    free(S);
    return;
}

variable_types: struct dynstuf { void **stuf; unsigned long slots; unsigned long items; } *

variable_types:
stuf
void **

variable_types:
i
unsigned long


decompiled_code:
void __fastcall dynbuf_clear(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void
dynbuf_clear(struct dynbuf *d)
{
    d->p = 0;
    return;
}

variable_types: struct dynbuf { void *buf; unsigned long n; unsigned long p; } *


decompiled_code:
__int64 __fastcall cdbmk_addioq(__int64 a1, _QWORD *a2, unsigned __int64 a3, unsigned __int64 a4, _BYTE *a5, __int64 a6)
{
unsigned __int64 v8; // rbx
__int64 v9; // r15
__int64 result; // rax
__int64 v11; // rax
unsigned __int64 v12; // rbx
__int64 v13; // rcx
_BYTE *v14; // rbx
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rdx
__int64 v18; // rax
unsigned __int64 v19; // rbx
__int64 v20; // rsi
unsigned __int64 v21; // rbp
unsigned int v22; // [rsp+Ch] [rbp-6Ch]
unsigned __int64 v25; // [rsp+20h] [rbp-58h]
__int64 v26; // [rsp+28h] [rbp-50h]
unsigned int v27; // [rsp+30h] [rbp-48h] BYREF
char v28; // [rsp+37h] [rbp-41h] BYREF
char v29[64]; // [rsp+38h] [rbp-40h] BYREF

v8 = a4;
v25 = a4;
v9 = *(_QWORD *)(a1 + 8);
v27 = v9;
result = ufunc_u32add(&v27, 8LL);
if ( (_DWORD)result != -1 )
{
result = ufunc_u32add(&v27, (unsigned int)a3);
if ( (_DWORD)result != -1 )
{
result = ufunc_u32add(&v27, (unsigned int)v8);
if ( (_DWORD)result != -1 )
{
upak_pack(v29, &unk_2B3, a3, v8);
result = ioq_put(a1 + 1072, v29, 8LL);
if ( (_DWORD)result != -1 )
{
if ( a3 )
{
v22 = 5381;
while ( 1 )
{
v11 = ioq_feed(a2);
v12 = v11;
if ( v11 == -1 )
return 0xFFFFFFFFLL;
if ( !v11 )
break;
v13 = ioq_peek(a2);
if ( (unsigned int)v12 > a3 )
v12 = a3;
v26 = v13;
v22 = cdb_hashpart(v22, v13, v12);
result = ioq_put(a1 + 1072, v26, v12);
if ( (_DWORD)result == -1 )
return result;
ioq_seek(a2, v12);
a3 -= v12;
if ( !a3 )
goto LABEL_17;
}
*_errno_location() = 71;
result = 0xFFFFFFFFLL;
}
else
{
v22 = 5381;
LABEL_17:
if ( a6 )
{
v14 = &a5[a6];
do
{
v16 = a2[3];
if ( v16 )
{
v17 = a2[2];
v28 = *(_BYTE *)(a2[1] + v17);
a2[3] = v16 - 1;
a2[2] = v17 + 1;
}
else
{
v15 = ioq_get(a2, &v28, 1LL);
if ( v15 == -1 )
return 0xFFFFFFFFLL;
if ( !v15 )
goto LABEL_29;
}
if ( *a5 != v28 )
{
LABEL_29:
*_errno_location() = 71;
return 0xFFFFFFFFLL;
}
++a5;
}
while ( a5 != v14 );
}
if ( v25 )
{
while ( 1 )
{
v18 = ioq_feed(a2);
v19 = v18;
if ( v18 == -1 )
break;
if ( !v18 )
goto LABEL_29;
v20 = ioq_peek(a2);
v21 = v25;
if ( (unsigned int)v19 > v25 )
v19 = v25;
result = ioq_put(a1 + 1072, v20, v19);
if ( (_DWORD)result == -1 )
return result;
ioq_seek(a2, v19);
v25 -= v19;
if ( v21 == v19 )
goto LABEL_34;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_34:
result = cdbmk__update(a1, v22, (unsigned int)v9, v27);
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, unsigned __int64 a3, unsigned __int64 a4, _BYTE *a5, __int64 a6)
{
unsigned __int64 v8; // rbx
__int64 v9; // r15
__int64 result; // rax
__int64 v11; // rax
unsigned __int64 v12; // rbx
__int64 v13; // rcx
_BYTE *v14; // rbx
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rdx
__int64 v18; // rax
unsigned __int64 v19; // rbx
__int64 v20; // rsi
unsigned __int64 v21; // rbp
unsigned int v22; // [rsp+Ch] [rbp-6Ch]
unsigned __int64 v25; // [rsp+20h] [rbp-58h]
__int64 v26; // [rsp+28h] [rbp-50h]
unsigned int v27; // [rsp+30h] [rbp-48h] BYREF
char v28; // [rsp+37h] [rbp-41h] BYREF
char v29[64]; // [rsp+38h] [rbp-40h] BYREF

v8 = a4;
v25 = a4;
v9 = *(_QWORD *)(a1 + 8);
v27 = v9;
result = ufunc_u32add(&v27, 8LL);
if ( (_DWORD)result != -1 )
{
result = ufunc_u32add(&v27, (unsigned int)a3);
if ( (_DWORD)result != -1 )
{
result = ufunc_u32add(&v27, (unsigned int)v8);
if ( (_DWORD)result != -1 )
{
upak_pack(v29, &unk_2B3, a3, v8);
result = ioq_put(a1 + 1072, v29, 8LL);
if ( (_DWORD)result != -1 )
{
if ( a3 )
{
v22 = 5381;
while ( 1 )
{
v11 = ioq_feed(a2);
v12 = v11;
if ( v11 == -1 )
return 0xFFFFFFFFLL;
if ( !v11 )
break;
v13 = ioq_peek(a2);
if ( (unsigned int)v12 > a3 )
v12 = a3;
v26 = v13;
v22 = cdb_hashpart(v22, v13, v12);
result = ioq_put(a1 + 1072, v26, v12);
if ( (_DWORD)result == -1 )
return result;
ioq_seek(a2, v12);
a3 -= v12;
if ( !a3 )
goto LABEL_17;
}
*_errno_location() = 71;
result = 0xFFFFFFFFLL;
}
else
{
v22 = 5381;
LABEL_17:
if ( a6 )
{
v14 = &a5[a6];
do
{
v16 = a2[3];
if ( v16 )
{
v17 = a2[2];
v28 = *(_BYTE *)(a2[1] + v17);
a2[3] = v16 - 1;
a2[2] = v17 + 1;
}
else
{
v15 = ioq_get(a2, &v28, 1LL);
if ( v15 == -1 )
return 0xFFFFFFFFLL;
if ( !v15 )
goto LABEL_29;
}
if ( *a5 != v28 )
{
LABEL_29:
*_errno_location() = 71;
return 0xFFFFFFFFLL;
}
++a5;
}
while ( a5 != v14 );
}
if ( v25 )
{
while ( 1 )
{
v18 = ioq_feed(a2);
v19 = v18;
if ( v18 == -1 )
break;
if ( !v18 )
goto LABEL_29;
v20 = ioq_peek(a2);
v21 = v25;
if ( (unsigned int)v19 > v25 )
v19 = v25;
result = ioq_put(a1 + 1072, v20, v19);
if ( (_DWORD)result == -1 )
return result;
ioq_seek(a2, v19);
v25 -= v19;
if ( v21 == v19 )
goto LABEL_34;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_34:
result = cdbmk__update(a1, v22, (unsigned int)v9, v27);
}
}
}
}
}
}
return result;
}

original_code:
int
cdbmk_addioq(struct cdbmk *M,
  ioq_t *ioq_in,
  size_t klen, size_t dlen,
  uchar_t *sep, size_t seplen)
{
  uint32_t rpos = M->fp;
  uchar_t buf[8];
  uchar_t *inbuf;
  uchar_t ch;
  uint32_t hash;
  uint32_t fp_up;
  ssize_t r;
  fp_up = rpos;
  if(ufunc_u32add(&fp_up, 8) == -1) return -1;
  if(ufunc_u32add(&fp_up, klen) == -1) return -1;
  if(ufunc_u32add(&fp_up, dlen) == -1) return -1;
  upak_pack(buf, "dd", klen, dlen);
  if(ioq_put(&M->ioq, buf, sizeof buf) == -1){
      return -1;
  }
  hash = 5381;
  while(klen){
      r = ioq_feed(ioq_in);
      switch(r){
      case -1: return -1; break;
      case 0: (*__errno_location ()) = 71; return -1; break;
      }
      inbuf = ioq_peek(ioq_in);
      if((uint32_t)r > klen) r = klen;
      hash = cdb_hashpart(hash, inbuf, r);
      if(ioq_put(&M->ioq, inbuf, r) == -1){
          return -1;
      }
      ioq_seek(ioq_in, r);
      klen -= r;
  }
  while(seplen){
      switch(( ((ioq_in)->p > 0) ? *((uchar_t *)(&ch)) = (ioq_in)->buf[(ioq_in)->n], (ioq_in)->p -= 1, (ioq_in)->n += 1, 1 : ioq_get((ioq_in),(uchar_t *)(&ch),1) )){
      case -1: return -1; break;
      case 0: (*__errno_location ()) = 71; return -1; break;
      }
      if(ch != *sep){
          (*__errno_location ()) = 71;
          return -1;
      }
      ++sep; --seplen;
  }
  while(dlen){
      r = ioq_feed(ioq_in);
      switch(r){
      case -1: return -1; break;
      case 0: (*__errno_location ()) = 71; return -1; break;
      }
      inbuf = ioq_peek(ioq_in);
      if((uint32_t)r > dlen) r = dlen;
      if(ioq_put(&M->ioq, inbuf, r) == -1){
          return -1;
      }
      ioq_seek(ioq_in, r);
      dlen -= r;
  }
  return cdbmk__update(M, hash, rpos, fp_up);
}

canonical_original_code:
int cdbmk_addioq(struct cdbmk *M, struct ioq *ioq_in, unsigned long klen, unsigned long dlen, unsigned char *sep, unsigned long seplen)
{
  unsigned int rpos = M->fp;
  unsigned char buf[8];
  unsigned char *inbuf;
  unsigned char ch;
  unsigned int hash;
  unsigned int fp_up;
  long r;
  fp_up = rpos;
  if(ufunc_u32add(&fp_up, 8) == -1) return -1;
  if(ufunc_u32add(&fp_up, klen) == -1) return -1;
  if(ufunc_u32add(&fp_up, dlen) == -1) return -1;
  upak_pack(buf, "dd", klen, dlen);
  if(ioq_put(&M->ioq, buf, sizeof buf) == -1){
      return -1;
  }
  hash = 5381;
  while(klen){
      r = ioq_feed(ioq_in);
      switch(r){
      case -1: return -1; break;
      case 0: (*__errno_location ()) = 71; return -1; break;
      }
      inbuf = ioq_peek(ioq_in);
      if((unsigned int)r > klen) r = klen;
      hash = cdb_hashpart(hash, inbuf, r);
      if(ioq_put(&M->ioq, inbuf, r) == -1){
          return -1;
      }
      ioq_seek(ioq_in, r);
      klen -= r;
  }
  while(seplen){
      switch(( ((ioq_in)->p > 0) ? *((unsigned char *)(&ch)) = (ioq_in)->buf[(ioq_in)->n], (ioq_in)->p -= 1, (ioq_in)->n += 1, 1 : ioq_get((ioq_in),(unsigned char *)(&ch),1) )){
      case -1: return -1; break;
      case 0: (*__errno_location ()) = 71; return -1; break;
      }
      if(ch != *sep){
          (*__errno_location ()) = 71;
          return -1;
      }
      ++sep; --seplen;
  }
  while(dlen){
      r = ioq_feed(ioq_in);
      switch(r){
      case -1: return -1; break;
      case 0: (*__errno_location ()) = 71; return -1; break;
      }
      inbuf = ioq_peek(ioq_in);
      if((unsigned int)r > dlen) r = dlen;
      if(ioq_put(&M->ioq, inbuf, r) == -1){
          return -1;
      }
      ioq_seek(ioq_in, r);
      dlen -= r;
  }
  return cdbmk__update(M, hash, rpos, fp_up);
}

variable_types: struct cdbmk { int fd; long fp; struct input_block { struct hashoff { unsigned int hash; unsigned int rpos; } record[500]; int n; struct input_block *next; } *input_list[4]; unsigned int subtab_count[256]; struct ioq { int fd; unsigned char *buf; unsigned long n; unsigned long p; long (*op)(); } ioq; unsigned char buf[8192]; } *

variable_types:
klen
unsigned long

variable_types:
dlen
unsigned long

variable_types:
sep
unsigned char *

variable_types:
seplen
unsigned long

variable_types:
rpos
unsigned int

variable_types:
buf
unsigned char [8]

variable_types:
inbuf
unsigned char *

variable_types:
ch
unsigned char

variable_types:
hash
unsigned int

variable_types: r long

user_defined_types: struct cdbmk { int fd; long fp; struct input_block *input_list[4]; unsigned int subtab_count[256]; struct ioq ioq; unsigned char buf[8192]; }

user_defined_types: struct input_block { struct hashoff record[500]; int n; struct input_block *next; }


decompiled_code:
__int64 __fastcall padlock_shlock(__int64 a1, int a2)
{
__int16 v3[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]
__int64 v5; // [rsp+10h] [rbp-18h]

v3[0] = 0;
v3[1] = 0;
v4 = 0LL;
v5 = 0LL;
return padlock_fcntl(a1, (unsigned int)(a2 == 1) + 6, v3);
}

original_code:
int
padlock_shlock(int fd, enum padlock_wait wait)
{
  struct flock lock;
  int cmd;
  lock.l_type = 0;
  lock.l_whence = 0;
  lock.l_start = 0;
  lock.l_len = 0;
  cmd = (wait == PADLOCK_WAIT) ? 7 : 6;
  return padlock_fcntl(fd, cmd, &lock);
}

variable_types: enum padlock_wait { PADLOCK_NOW=0, PADLOCK_WAIT=1 }

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }

variable_types: cmd int


decompiled_code:
__int64 __fastcall padlock_extest(__int64 a1)
{
__int64 result; // rax
__int16 v2[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]
unsigned int v5; // [rsp+18h] [rbp-10h]

v2[0] = 1;
v2[1] = 0;
v3 = 0LL;
v4 = 0LL;
result = padlock_fcntl(a1, 5LL, v2);
if ( (int)result >= 0 )
{
result = 0LL;
if ( v2[0] != 2 )
result = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
__int16 v2[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]
unsigned int v5; // [rsp+18h] [rbp-10h]

v2[0] = 1;
v2[1] = 0;
v3 = 0LL;
v4 = 0LL;
result = padlock_fcntl(a1, 5LL, v2);
if ( (int)result >= 0 )
{
result = 0LL;
if ( v2[0] != 2 )
result = v5;
}
return result;
}

original_code:
pid_t
padlock_extest(int fd)
{
  struct flock lock;
  int e;
  lock.l_type = 1;
  lock.l_whence = 0;
  lock.l_start = 0;
  lock.l_len = 0;
  e = padlock_fcntl(fd, 5, &lock);
  if(e < 0)
      return (pid_t)e;
  return ((lock.l_type == 2) ? 0 : lock.l_pid);
}

canonical_original_code:
int padlock_extest(int fd)
{
  struct flock lock;
  int e;
  lock.l_type = 1;
  lock.l_whence = 0;
  lock.l_start = 0;
  lock.l_len = 0;
  e = padlock_fcntl(fd, 5, &lock);
  if(e < 0)
      return (int)e;
  return ((lock.l_type == 2) ? 0 : lock.l_pid);
}

variable_types: fd int

variable_types: e int

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


original_code:
void
hdbmk_clear(struct hdbmk *M)
{
  struct hdbmk_block *block, *next;
  int i;
  if(M == ((void *)0))
      return;
  for(i = 0; i < 8; ++i){
      block = M->block_list[i];
      for(;;){
          if(block == ((void *)0)) break;
          next = block->next;
          free(block);
          block = next;
      }
      M->block_list[i] = ((void *)0);
  }
  return;
}

canonical_original_code:
void hdbmk_clear(struct hdbmk *M)
{
  struct hdbmk_block *block; struct hdbmk_block *next;
  int i;
  if(M == ((void *)0))
      return;
  for(i = 0; i < 8; ++i){
      block = M->block_list[i];
      for(;;){
          if(block == ((void *)0)) break;
          next = block->next;
          free(block);
          block = next;
      }
      M->block_list[i] = ((void *)0);
  }
  return;
}

variable_types: struct hdbmk { int fd; long fp; unsigned int rbase; struct hdbmk_block { struct hdb_valoff { unsigned int value; unsigned int offset; } record[256]; int n; struct hdbmk_block *next; } *block_list[8]; unsigned int subtab_count[8]; struct ioq { int fd; unsigned char *buf; unsigned long n; unsigned long p; long (*op)(); } ioq; unsigned char buf[8192]; } *

variable_types: i int

user_defined_types: struct hdbmk { int fd; long fp; unsigned int rbase; struct hdbmk_block *block_list[8]; unsigned int subtab_count[8]; struct ioq ioq; unsigned char buf[8192]; }

user_defined_types: struct hdbmk_block { struct hdb_valoff record[256]; int n; struct hdbmk_block *next; }


decompiled_code:
__int64 __fastcall hdb_get(_DWORD *a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rdx

v4 = (unsigned int)a1[35];
if ( v4 > a3 )
v4 = a3;
return hdb_read(a1, a2, v4, (unsigned int)(a1[34] + a1[28] + 6));
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rdx

v4 = (unsigned int)a1[35];
if ( v4 > a3 )
v4 = a3;
return hdb_read(a1, a2, v4, (unsigned int)(a1[34] + a1[28] + 6));
}

original_code:
int
hdb_get(struct hdb *H, uchar_t *buf, size_t len)
{
    if(len > H->dlen)
        len = H->dlen;
    return (hdb_read(H, buf, len, ((H)->rpos + 6 + (H)->klen)));
}

canonical_original_code:
int hdb_get(struct hdb *H, unsigned char *buf, unsigned long len)
{
    if(len > H->dlen)
        len = H->dlen;
    return (hdb_read(H, buf, len, ((H)->rpos + 6 + (H)->klen)));
}

variable_types: struct hdb { int fd; unsigned char *map; unsigned int map_size; unsigned int nrecs; struct hdb_valoff { unsigned int value; unsigned int offset; } tndx[8]; unsigned int cbase; unsigned int rbase; unsigned int hbase; unsigned char *key; unsigned int klen; unsigned int h; unsigned int tbase; unsigned int tslots; unsigned int s0; unsigned int sN; unsigned int rpos; unsigned int dlen; } *

variable_types:
buf
unsigned char *

variable_types:
len
unsigned long

user_defined_types: struct hdb { int fd; unsigned char *map; unsigned int map_size; unsigned int nrecs; struct hdb_valoff tndx[8]; unsigned int cbase; unsigned int rbase; unsigned int hbase; unsigned char *key; unsigned int klen; unsigned int h; unsigned int tbase; unsigned int tslots; unsigned int s0; unsigned int sN; unsigned int rpos; unsigned int dlen; }


decompiled_code:
unsigned int __fastcall hdb_open(__int64 a1, const char *a2)
{
unsigned int result; // eax

result = open(a2, 2048);
if ( result != -1 )
result = hdb_init(a1, result);
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func0(__int64 a1, const char *a2)
{
unsigned int result; // eax

result = open(a2, 2048);
if ( result != -1 )
result = hdb_init(a1, result);
return result;
}

original_code:
int
hdb_open(struct hdb *H, const char *path)
{
  int fd;
  fd = open(path, 00 | 04000);
  if(fd == -1)
      return -1;
  return hdb_init(H, fd);
}

canonical_original_code:
int hdb_open(struct hdb *H, char *path)
{
  int fd;
  fd = open(path, 00 | 04000);
  if(fd == -1)
      return -1;
  return hdb_init(H, fd);
}

variable_types:
path
char *

user_defined_types: struct hdb_valoff { unsigned int value; unsigned int offset; }


decompiled_code:
_BOOL8 __fastcall dynstuf_isempty(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
size_t
dynstuf_isempty(struct dynstuf *S)
{
    return (S->items == 0);
}

canonical_original_code:
unsigned long dynstuf_isempty(struct dynstuf *S)
{
    return (S->items == 0);
}

variable_types: struct dynstuf { void **stuf; unsigned long slots; unsigned long items; } *

return_type: unsigned long


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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) < (unsigned __int64)(*(_QWORD *)(a1 + 8) + a2 + 1) )
result = dynstr_need();
return result;
}

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

result = 0LL;
if ( *(_QWORD *)(a1 + 16) < (unsigned __int64)(*(_QWORD *)(a1 + 8) + a2 + 1) )
result = dynstr_need();
return result;
}

original_code:
int
dynstr_grow(dynstr_t *S, size_t grow)
{
    size_t have = S->k;
    size_t need = S->n + grow + 1;
    if(have < need){
        return dynstr_need(S, need);
    }
    return 0;
}

canonical_original_code:
int dynstr_grow(struct dynstr *S, unsigned long grow)
{
    unsigned long have = S->k;
    unsigned long need = S->n + grow + 1;
    if(have < need){
        return dynstr_need(S, need);
    }
    return 0;
}

variable_types: struct dynstr { char *s; unsigned long n; unsigned long k; } *

variable_types:
grow
unsigned long

variable_types:
have
unsigned long

variable_types:
need
unsigned long


decompiled_code:
__int64 __fastcall ufunc_u48add(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rsi
__int64 result; // rax

if ( *a1 > 0xFFFFFFFFFFFFLL || a2 > 0xFFFFFFFFFFFFLL || (v2 = a2 + *a1, v2 > 0xFFFFFFFFFFFFLL) )
{
*_errno_location() = 34;
result = 0xFFFFFFFFLL;
}
else
{
*a1 = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rsi
__int64 result; // rax

if ( *a1 > 0xFFFFFFFFFFFFLL || a2 > 0xFFFFFFFFFFFFLL || (v2 = a2 + *a1, v2 > 0xFFFFFFFFFFFFLL) )
{
*_errno_location() = 34;
result = 0xFFFFFFFFLL;
}
else
{
*a1 = v2;
result = 0LL;
}
return result;
}

original_code:
int
ufunc_u48add(uint64_t *u, uint64_t add)
{
  uint64_t u_new = *u;
  if((u_new > (uint64_t)((1ULL<<48)-1)) || (add > (uint64_t)((1ULL<<48)-1))){
      (*__errno_location ()) = 34;
      return -1;
  }
  u_new += add;
  if(u_new > (uint64_t)((1ULL<<48)-1)){
      (*__errno_location ()) = 34;
      return -1;
  }
  *u = u_new;
  return 0;
}

canonical_original_code:
int ufunc_u48add(unsigned long *u, unsigned long add)
{
  unsigned long u_new = *u;
  if((u_new > (unsigned long)((1ULL<<48)-1)) || (add > (unsigned long)((1ULL<<48)-1))){
      (*__errno_location ()) = 34;
      return -1;
  }
  u_new += add;
  if(u_new > (unsigned long)((1ULL<<48)-1)){
      (*__errno_location ()) = 34;
      return -1;
  }
  *u = u_new;
  return 0;
}

variable_types:
u
unsigned long *

variable_types:
add
unsigned long


decompiled_code:
int __fastcall sig_block(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return sigprocmask(0, &v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return sigprocmask(0, &v2, 0LL);
}

original_code:
void sig_block(int sig)
{
  sigset_t ss;
  sigemptyset(&ss);
  sigaddset(&ss, sig);
  sigprocmask(0, &ss, (sigset_t *) 0);
  return;
}

canonical_original_code:
void sig_block(int sig)
{
  struct __sigset_t ss;
  sigemptyset(&ss);
  sigaddset(&ss, sig);
  sigprocmask(0, &ss, (struct __sigset_t *) 0);
  return;
}

variable_types: sig int

variable_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
__int64 __fastcall hdb_read(__int64 a1, char *a2, unsigned __int64 a3, unsigned int a4)
{
size_t v5; // rbx
__int64 v6; // rsi
unsigned int v7; // eax
__int64 result; // rax
int v9; // er12
ssize_t v10; // rax

v5 = a3;
v6 = *(_QWORD *)(a1 + 8);
if ( v6 )
{
v7 = *(_DWORD *)(a1 + 16);
if ( v7 <= a4 || v7 - a4 < a3 )
{
LABEL_12:
*_errno_location() = 71;
result = 0xFFFFFFFFLL;
}
else
{
buf_copy(a2, a4 + v6);
result = 0LL;
}
}
else
{
v9 = *(_DWORD *)a1;
if ( lseek(*(_DWORD *)a1, a4, 0) == -1 )
{
result = 0xFFFFFFFFLL;
}
else if ( v5 )
{
do
{
while ( 1 )
{
v10 = read(v9, a2, v5);
if ( v10 != -1 )
break;
if ( *_errno_location() != 4 )
return 0xFFFFFFFFLL;
}
if ( !v10 )
goto LABEL_12;
a2 += v10;
v5 -= v10;
}
while ( v5 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, unsigned __int64 a3, unsigned int a4)
{
size_t v5; // rbx
__int64 v6; // rsi
unsigned int v7; // eax
__int64 result; // rax
int v9; // er12
ssize_t v10; // rax

v5 = a3;
v6 = *(_QWORD *)(a1 + 8);
if ( v6 )
{
v7 = *(_DWORD *)(a1 + 16);
if ( v7 <= a4 || v7 - a4 < a3 )
{
LABEL_12:
*_errno_location() = 71;
result = 0xFFFFFFFFLL;
}
else
{
buf_copy(a2, a4 + v6);
result = 0LL;
}
}
else
{
v9 = *(_DWORD *)a1;
if ( lseek(*(_DWORD *)a1, a4, 0) == -1 )
{
result = 0xFFFFFFFFLL;
}
else if ( v5 )
{
do
{
while ( 1 )
{
v10 = read(v9, a2, v5);
if ( v10 != -1 )
break;
if ( *_errno_location() != 4 )
return 0xFFFFFFFFLL;
}
if ( !v10 )
goto LABEL_12;
a2 += v10;
v5 -= v10;
}
while ( v5 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int
hdb_read(struct hdb *H, uchar_t *buf, size_t len, uint32_t offset)
{
  int fd = H->fd;
  ssize_t r;
  if(H->map != 0){
      if((offset >= H->map_size) || ((H->map_size - offset) < len)){
          (*__errno_location ()) = 71;
          return -1;
      }
      buf_copy(buf, H->map + offset, len);
      return 0;
  }
  if(lseek(fd, (off_t)offset, 0) == -1){
      return -1;
  }
  while(len){
      do{
          r = read(fd, buf, len);
      }while((r == -1) && ((*__errno_location ()) == 4));
      switch(r){
      case -1:
          return -1; break;
      case 0:
          (*__errno_location ()) = 71;
          return -1; break;
      default:
          buf += r;
          len -= r;
      }
  }
  return 0;
}

canonical_original_code:
int hdb_read(struct hdb *H, unsigned char *buf, unsigned long len, unsigned int offset)
{
  int fd = H->fd;
  long r;
  if(H->map != 0){
      if((offset >= H->map_size) || ((H->map_size - offset) < len)){
          (*__errno_location ()) = 71;
          return -1;
      }
      buf_copy(buf, H->map + offset, len);
      return 0;
  }
  if(lseek(fd, (long)offset, 0) == -1){
      return -1;
  }
  while(len){
      do{
          r = read(fd, buf, len);
      }while((r == -1) && ((*__errno_location ()) == 4));
      switch(r){
      case -1:
          return -1; break;
      case 0:
          (*__errno_location ()) = 71;
          return -1; break;
      default:
          buf += r;
          len -= r;
      }
  }
  return 0;
}

variable_types:
offset
unsigned int

variable_types: fd int

variable_types: r long


original_code:
static void randomize_grid(struct ctx_s *ctx, int **grid) {
  int x, y, r;
  srand (time(((void *)0)) * ctx->rank);
  for (x=1; x < ctx->X+1; ++x) {
    for (y=1; y < ctx->Y+1; ++y) {
      r = rand() % 100;
      if (r <= 60) {
        grid[x][y] = tree;
      }
    }
  }
}

canonical_original_code:
static void randomize_grid(struct ctx_s *ctx, int **grid) {
  int x; int y; int r;
  srand (time(((void *)0)) * ctx->rank);
  for (x=1; x < ctx->X+1; ++x) {
    for (y=1; y < ctx->Y+1; ++y) {
      r = rand() % 100;
      if (r <= 60) {
        grid[x][y] = tree;
      }
    }
  }
}

variable_types: struct ctx_s { int X; int Y; int **grid; int **grid_next; int rank; int size; int *reduce_buffer; int timeStep; int domainCount; int domainX; char filename[256]; } *

variable_types:
grid
int **

variable_types: x int

variable_types: y int

variable_types: r int


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

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

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

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

original_code:
double get_timer() {
  struct timeval t;
  gettimeofday(&t, ((void *)0));
  return t.tv_sec * 1000000 + t.tv_usec;
}

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

return_type: double


decompiled_code:
double __fastcall diff_time(double a1, double a2)
{
return a1 - a2;
}

canonical_decompiled_code:
double __fastcall func12(double a1, double a2)
{
return a1 - a2;
}

original_code:
double diff_time (double end, double start) {
  return end - start;
}

canonical_original_code:
double diff_time(double end, double start) {
  return end - start;
}

variable_types: end double

variable_types: start double


decompiled_code:
int __fastcall print_time(__int64 a1, double a2)
{
return fprintf(stderr, "[%d] Temps de l'execution : %.2f s\n", *(unsigned int *)(a1 + 24), a2 / 1000000.0);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, double a2)
{
return fprintf(stderr, "[%d] Temps de l'execution : %.2f s\n", *(unsigned int *)(a1 + 24), a2 / 1000000.0);
}

original_code:
void print_time(struct ctx_s *ctx, double runtime) {
  double runtime_in_seconds = runtime / 1000000;
  fprintf(stderr, "[%d] Temps de l'execution : %.2f s\n", ctx->rank, runtime_in_seconds);
}

variable_types: runtime double

user_defined_types: struct ctx_s { int X; int Y; int **grid; int **grid_next; int rank; int size; int *reduce_buffer; int timeStep; int domainCount; int domainX; char filename[256]; }


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

result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2) + 4LL * a3);
if ( (_DWORD)result == 1 )
{
if ( a4 <= 0 )
{
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) = 1;
result = 0LL;
}
else
{
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) = 2;
}
}
else if ( (_DWORD)result == 2 )
{
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) = 3;
result = 1LL;
}
else
{
if ( (_DWORD)result == 3 )
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) = 3;
result = 0LL;
}
return result;
}

original_code:
int update_self(struct ctx_s *ctx, int x, int y, int nb_burning) {
  int update = 0;
  if (ctx->grid[x][y] == tree) {
    if (nb_burning > 0) {
      ctx->grid_next[x][y] = burning;
      update++;
    } else {
      ctx->grid_next[x][y] = tree;
    }
  } else if (ctx->grid[x][y] == burning) {
      ctx->grid_next[x][y] = burned;
      update++;
  } else if (ctx->grid[x][y] == burned) {
      ctx->grid_next[x][y] = burned;
  }
  return update;
}

variable_types: update int


original_code:
int update_cells (struct ctx_s *ctx) {
  int x, y;
  int top, bottom, left, right;
  int update = 0;
  for (x=1; x < ctx->X+1; ++x) {
    for (y=1; y < ctx->Y+1; ++y) {
      int nb_burning = 0;
      left = x - 1;
      right = x + 1;
      top = y - 1;
      bottom = y + 1;
      update_neighbor(ctx, left, y, &nb_burning);
      update_neighbor(ctx, right, y, &nb_burning);
      update_neighbor(ctx, x, top, &nb_burning);
      update_neighbor(ctx, x, bottom, &nb_burning);
      update += update_self(ctx, x, y, nb_burning);
    }
  }
  return update;
}

canonical_original_code:
int update_cells(struct ctx_s *ctx) {
  int x; int y;
  int top; int bottom; int left; int right;
  int update = 0;
  for (x=1; x < ctx->X+1; ++x) {
    for (y=1; y < ctx->Y+1; ++y) {
      int nb_burning = 0;
      left = x - 1;
      right = x + 1;
      top = y - 1;
      bottom = y + 1;
      update_neighbor(ctx, left, y, &nb_burning);
      update_neighbor(ctx, right, y, &nb_burning);
      update_neighbor(ctx, x, top, &nb_burning);
      update_neighbor(ctx, x, bottom, &nb_burning);
      update += update_self(ctx, x, y, nb_burning);
    }
  }
  return update;
}

variable_types: top int

variable_types: bottom int

variable_types: left int

variable_types: right int


original_code:
void initalize_mpi(int argc, char** argv, struct ctx_s *ctx)
{
  ctx->rank = 0;
  ctx->size = 1;
}

canonical_original_code:
void initalize_mpi(int argc, char **argv, struct ctx_s *ctx)
{
  ctx->rank = 0;
  ctx->size = 1;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void exchange_ghost_cells()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
void exchange_ghost_cells(struct ctx_s *ctx)
{
 }


decompiled_code:
void finalize_mpi()
{
;
}

canonical_decompiled_code:
void func19()
{
;
}

original_code:
void finalize_mpi(struct ctx_s *ctx)
{
}


decompiled_code:
void __fastcall gather_grid(__int64 a1, void *a2)
{
unsigned int v2; // eax

v2 = timeStep_0++;
display_render_step(a1, a2, 0LL, 0LL, 0LL, 100, 100, 0, v2);
free(a2);
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, void *a2)
{
unsigned int v2; // eax

v2 = timeStep_0++;
func9(a1, a2, 0LL, 0LL, 0LL, 100, 100, 0, v2);
free(a2);
}

original_code:
void gather_grid(struct ctx_s * ctx, int * recopy)
{
  static int timeStep = 0;
  display_render_step(ctx, recopy, 0,0,0, 100,100,0, timeStep++ );
  free(recopy);
}

canonical_original_code:
void gather_grid(struct ctx_s *ctx, int *recopy)
{
  static int timeStep = 0;
  display_render_step(ctx, recopy, 0,0,0, 100,100,0, timeStep++ );
  free(recopy);
}

variable_types:
recopy
int *

variable_types: timeStep int


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

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

original_code:
int check_final_conditions (struct ctx_s * ctx, int nb_updated_cells)
{
  return 0;
}

canonical_original_code:
int check_final_conditions(struct ctx_s *ctx, int nb_updated_cells)
{
  return 0;
}

variable_types: struct ctx_s { int X; int Y; int **grid; int **grid_next; int rank; int size; int *reduce_buffer; int timeStep; int domainCount; int domainX; char filename[256]; } *


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
double v4; // rbp
unsigned int i; // ebx
unsigned int v6; // eax
_QWORD *v7; // rax
__int64 v8; // rsi
_DWORD *v9; // rax
double v10; // xmm0_8
double v11; // xmm0_8
char v12[256]; // [rsp+0h] [rbp-258h] BYREF
unsigned int v13; // [rsp+100h] [rbp-158h] BYREF
unsigned int v14; // [rsp+104h] [rbp-154h]
_QWORD *v15; // [rsp+108h] [rbp-150h]
_QWORD *v16; // [rsp+110h] [rbp-148h]
unsigned int v17; // [rsp+118h] [rbp-140h]
int v18; // [rsp+11Ch] [rbp-13Ch]

initalize_mpi(*(__int64 *)&argc, (__int64)argv, (__int64)&v13);
v13 = 100 / v18;
v14 = 100;
v15 = init_grid((int *)&v13);
randomize_grid((int *)&v13, (__int64)v15);
v16 = init_grid((int *)&v13);
fprintf(stderr, "Starting task %d (%dx%d)\n", v17, v13, v14);
sprintf(v12, "output/Rank%d", v17);
display_init((__int64)&v13, v12, 100, 100, 0);
if ( !v17 )
*(_DWORD *)(v15[(int)(v13 + 2) / 2] + 4LL * ((int)(v14 + 2) / 2)) = 2;
v3 = recopy_grid((int *)&v13, (__int64)v15);
gather_grid((__int64)&v13, v3);
v4 = get_timer();
for ( i = 0; i != 600; ++i )
{
v6 = update_cells((int *)&v13);
if ( (unsigned int)check_final_conditions(&v13, v6) )
break;
v7 = v15;
v8 = (__int64)v16;
v15 = v16;
v16 = v7;
v9 = recopy_grid((int *)&v13, v8);
gather_grid((__int64)&v13, v9);
if ( !(v17 | ((int)i % 10)) )
fprintf(stderr, "..[%d]", i);
}
v10 = get_timer();
if ( !v17 )
fputc(10, stderr);
display_finalize((__int64)&v13);
v11 = diff_time(v10, v4);
print_time((__int64)&v13, v11);
exit(0);
}

original_code:
int main (int argc, char **argv) {
  struct ctx_s ctx;
  int i;
  int *recopy;
  double timer_start, timer_end;
  double runtime;
  char output[256];
  initalize_mpi(argc, argv, &ctx);
  ctx.X = 100 / ctx.size;
  ctx.Y = 100;
  ctx.grid = init_grid(&ctx);
  randomize_grid(&ctx, ctx.grid);
  ctx.grid_next = init_grid(&ctx);
  fprintf(stderr, "Starting task %d (%dx%d)\n", ctx.rank, ctx.X, ctx.Y);
  sprintf(output, "output/Rank%d", ctx.rank);
  display_init(&ctx, output, 100,100,0 );
  if (ctx.rank == 0) {
    ctx.grid[(ctx.X+2)/2][(ctx.Y+2)/2] = burning;
  }
  recopy = recopy_grid(&ctx, ctx.grid);
  gather_grid(&ctx, recopy);
  timer_start = get_timer();
  for (i=0; i < 600; ++i) {
    int **swap;
    int nb_updated_cells;
    int leave;
    exchange_ghost_cells(&ctx);
    nb_updated_cells = update_cells(&ctx);
    leave = check_final_conditions(&ctx, nb_updated_cells);
    if (leave) break;
    swap = ctx.grid;
    ctx.grid = ctx.grid_next;
    ctx.grid_next = swap;
    recopy = recopy_grid(&ctx, ctx.grid);
    gather_grid(&ctx, recopy);
    if (ctx.rank == 0 && i%10 == 0) {
      fprintf(stderr, "..[%d]", i);
    }
  }
  timer_end = get_timer();
  if (ctx.rank == 0) {
    fprintf(stderr, "\n");
  }
  display_finalize(&ctx);
  runtime = diff_time(timer_end, timer_start);
  print_time (&ctx, runtime);
  finalize_mpi(&ctx);
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv) {
  struct ctx_s ctx;
  int i;
  int *recopy;
  double timer_start; double timer_end;
  double runtime;
  char output[256];
  initalize_mpi(argc, argv, &ctx);
  ctx.X = 100 / ctx.size;
  ctx.Y = 100;
  ctx.grid = init_grid(&ctx);
  randomize_grid(&ctx, ctx.grid);
  ctx.grid_next = init_grid(&ctx);
  fprintf(stderr, "Starting task %d (%dx%d)\n", ctx.rank, ctx.X, ctx.Y);
  sprintf(output, "output/Rank%d", ctx.rank);
  display_init(&ctx, output, 100,100,0 );
  if (ctx.rank == 0) {
    ctx.grid[(ctx.X+2)/2][(ctx.Y+2)/2] = burning;
  }
  recopy = recopy_grid(&ctx, ctx.grid);
  gather_grid(&ctx, recopy);
  timer_start = get_timer();
  for (i=0; i < 600; ++i) {
    int **swap;
    int nb_updated_cells;
    int leave;
    exchange_ghost_cells(&ctx);
    nb_updated_cells = update_cells(&ctx);
    leave = check_final_conditions(&ctx, nb_updated_cells);
    if (leave) break;
    swap = ctx.grid;
    ctx.grid = ctx.grid_next;
    ctx.grid_next = swap;
    recopy = recopy_grid(&ctx, ctx.grid);
    gather_grid(&ctx, recopy);
    if (ctx.rank == 0 && i%10 == 0) {
      fprintf(stderr, "..[%d]", i);
    }
  }
  timer_end = get_timer();
  if (ctx.rank == 0) {
    fprintf(stderr, "\n");
  }
  display_finalize(&ctx);
  runtime = diff_time(timer_end, timer_start);
  print_time (&ctx, runtime);
  finalize_mpi(&ctx);
  exit(0);
}

variable_types: struct ctx_s { int X; int Y; int **grid; int **grid_next; int rank; int size; int *reduce_buffer; int timeStep; int domainCount; int domainX; char filename[256]; }

variable_types: i int

variable_types:
output
char [256]

variable_types:
swap
int **

variable_types: leave int


repo: carsonmcdonald/bluez-experiments

decompiled_code:
void ctrlc_handler()
{
global_done = 1;
}

canonical_decompiled_code:
void func7()
{
global_done = 1;
}

original_code:
void ctrlc_handler(int s)
{
  global_done = 1;
}

variable_types: s int


twoc

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

result = (unsigned int)a1;
if ( a1 < 0 )
result = (unsigned int)(a1 + (2 << (a2 - 1)));
return result;
}

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

result = (unsigned int)a1;
if ( a1 < 0 )
result = (unsigned int)(a1 + (2 << (a2 - 1)));
return result;
}

original_code:
unsigned int twoc(int in, int t)
{
  return (in < 0) ? (in + (2 << (t-1))) : in;
}

variable_types: in int

variable_types: t int

return_type: unsigned int


decompiled_code:
__int64 __fastcall enable_advertising(unsigned __int16 a1, const char *a2, __int16 a3, __int16 a4, int a5)
{
_DWORD *v5; // r15
size_t i; // rbp
unsigned int v7; // ebx
char *v8; // rax
__int64 result; // rax
unsigned int v10; // ebx
char *v11; // rax
int v12; // ebx
unsigned int v13; // ebx
char *v14; // rax
__int64 v18[5]; // [rsp+20h] [rbp-A8h] BYREF
char v19; // [rsp+4Fh] [rbp-79h] BYREF
__int64 v20; // [rsp+50h] [rbp-78h]
__int64 *v21; // [rsp+58h] [rbp-70h]
__int64 v22; // [rsp+60h] [rbp-68h]
unsigned __int8 *v23; // [rsp+68h] [rbp-60h]
__int64 v24; // [rsp+70h] [rbp-58h]
unsigned __int8 v25; // [rsp+80h] [rbp-48h] BYREF
__int64 v26; // [rsp+81h] [rbp-47h] BYREF
int v27; // [rsp+89h] [rbp-3Fh]
__int16 v28; // [rsp+8Dh] [rbp-3Bh]
char v29; // [rsp+8Fh] [rbp-39h]

hci_get_route();
if ( (int)hci_open_dev() < 0 )
{
perror("Could not open device");
exit(1);
}
v27 = 0;
v28 = 1792;
v29 = 0;
v26 = a1;
WORD1(v26) = a1;
v20 = 393224LL;
v22 = 15LL;
v24 = 1LL;
v21 = &v26;
v23 = &v25;
if ( (int)hci_send_req() < 0 )
{
hci_close_dev();
v7 = *__errno_location();
v8 = strerror(v7);
fprintf(stderr, "Can't send request %s (%d)\n", v8, v7);
return 1LL;
}
v19 = 1;
v20 = 655368LL;
v22 = 1LL;
v24 = 1LL;
v21 = (__int64 *)&v19;
v23 = &v25;
if ( (int)hci_send_req() < 0 )
{
hci_close_dev();
v10 = *__errno_location();
v11 = strerror(v10);
fprintf(stderr, "Can't send request %s (%d)\n", v11, v10);
return 1LL;
}
v18[0] = 0x4CFF001A010203LL;
v18[1] = 5378LL;
v18[2] = 0LL;
v18[3] = 0LL;
v5 = uuid_str_to_data(a2);
for ( i = 0LL; strlen(a2) >> 1 > i; ++i )
*((_BYTE *)v18 + (unsigned __int8)(i + 6) + 4) = v5[i];
*((_BYTE *)v18 + (unsigned __int8)(i + 6) + 4) = HIBYTE(a3);
*((_BYTE *)v18 + (unsigned __int8)(i + 7) + 4) = a3;
*((_BYTE *)v18 + (unsigned __int8)(i + 8) + 4) = HIBYTE(a4);
*((_BYTE *)v18 + (unsigned __int8)(i + 9) + 4) = a4;
*((_BYTE *)v18 + (unsigned __int8)(i + 10) + 4) = twoc(a5, 8);
BYTE4(v18[0]) = i + 10;
LOBYTE(v18[0]) = i + 14;
v20 = 524296LL;
v22 = 32LL;
v24 = 1LL;
v21 = v18;
v23 = &v25;
v12 = hci_send_req();
result = hci_close_dev();
if ( v12 < 0 )
{
v13 = *__errno_location();
v14 = strerror(v13);
fprintf(stderr, "Can't send request %s (%d)\n", v14, v13);
return 1LL;
}
if ( v25 )
{
fprintf(stderr, "LE set advertise returned status %d\n", v25);
return 1LL;
}
return result;
}

original_code:
int enable_advertising(int advertising_interval, char *advertising_uuid, int major_number, int minor_number, int rssi_value)
{
  int device_id = hci_get_route(((void *)0));
  int device_handle = 0;
  if((device_handle = hci_open_dev(device_id)) < 0)
  {
    perror("Could not open device");
    exit(1);
  }
  le_set_advertising_parameters_cp adv_params_cp;
  memset(&adv_params_cp, 0, sizeof(adv_params_cp));
  adv_params_cp.min_interval = (advertising_interval);
  adv_params_cp.max_interval = (advertising_interval);
  adv_params_cp.chan_map = 7;
  uint8_t status;
  struct hci_request rq;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x0006;
  rq.cparam = &adv_params_cp;
  rq.clen = 15;
  rq.rparam = &status;
  rq.rlen = 1;
  int ret = hci_send_req(device_handle, &rq, 1000);
  if (ret < 0)
  {
    hci_close_dev(device_handle);
    fprintf(stderr, "Can't send request %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  le_set_advertise_enable_cp advertise_cp;
  memset(&advertise_cp, 0, sizeof(advertise_cp));
  advertise_cp.enable = 0x01;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x000A;
  rq.cparam = &advertise_cp;
  rq.clen = 1;
  rq.rparam = &status;
  rq.rlen = 1;
  ret = hci_send_req(device_handle, &rq, 1000);
  if (ret < 0)
  {
    hci_close_dev(device_handle);
    fprintf(stderr, "Can't send request %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  le_set_advertising_data_cp adv_data_cp;
  memset(&adv_data_cp, 0, sizeof(adv_data_cp));
  uint8_t segment_length = 1;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0X01); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x1A); segment_length++;
  adv_data_cp.data[adv_data_cp.length] = (segment_length - 1);
  adv_data_cp.length += segment_length;
  segment_length = 1;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0xFF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x4C); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x00); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x02); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x15); segment_length++;
  unsigned int *uuid = uuid_str_to_data(advertising_uuid);
  int i;
  for(i=0; i<strlen(advertising_uuid)/2; i++)
  {
    adv_data_cp.data[adv_data_cp.length + segment_length] = (uuid[i]); segment_length++;
  }
  adv_data_cp.data[adv_data_cp.length + segment_length] = (major_number >> 8 & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (major_number & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (minor_number >> 8 & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (minor_number & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (twoc(rssi_value, 8)); segment_length++;
  adv_data_cp.data[adv_data_cp.length] = (segment_length - 1);
  adv_data_cp.length += segment_length;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x0008;
  rq.cparam = &adv_data_cp;
  rq.clen = 32;
  rq.rparam = &status;
  rq.rlen = 1;
  ret = hci_send_req(device_handle, &rq, 1000);
  hci_close_dev(device_handle);
  if(ret < 0)
  {
    fprintf(stderr, "Can't send request %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  if (status)
  {
    fprintf(stderr, "LE set advertise returned status %d\n", status);
    return(1);
  }
}

canonical_original_code:
int enable_advertising(int advertising_interval, char *advertising_uuid, int major_number, int minor_number, int rssi_value)
{
  int device_id = hci_get_route(((void *)0));
  int device_handle = 0;
  if((device_handle = hci_open_dev(device_id)) < 0)
  {
    perror("Could not open device");
    exit(1);
  }
  struct le_set_advertising_parameters_cp adv_params_cp;
  memset(&adv_params_cp, 0, sizeof(adv_params_cp));
  adv_params_cp.min_interval = (advertising_interval);
  adv_params_cp.max_interval = (advertising_interval);
  adv_params_cp.chan_map = 7;
  unsigned char status;
  struct hci_request rq;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x0006;
  rq.cparam = &adv_params_cp;
  rq.clen = 15;
  rq.rparam = &status;
  rq.rlen = 1;
  int ret = hci_send_req(device_handle, &rq, 1000);
  if (ret < 0)
  {
    hci_close_dev(device_handle);
    fprintf(stderr, "Can't send request %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  struct le_set_advertise_enable_cp advertise_cp;
  memset(&advertise_cp, 0, sizeof(advertise_cp));
  advertise_cp.enable = 0x01;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x000A;
  rq.cparam = &advertise_cp;
  rq.clen = 1;
  rq.rparam = &status;
  rq.rlen = 1;
  ret = hci_send_req(device_handle, &rq, 1000);
  if (ret < 0)
  {
    hci_close_dev(device_handle);
    fprintf(stderr, "Can't send request %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  struct le_set_advertising_data_cp adv_data_cp;
  memset(&adv_data_cp, 0, sizeof(adv_data_cp));
  unsigned char segment_length = 1;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0X01); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x1A); segment_length++;
  adv_data_cp.data[adv_data_cp.length] = (segment_length - 1);
  adv_data_cp.length += segment_length;
  segment_length = 1;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0xFF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x4C); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x00); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x02); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (0x15); segment_length++;
  unsigned int *uuid = uuid_str_to_data(advertising_uuid);
  int i;
  for(i=0; i<strlen(advertising_uuid)/2; i++)
  {
    adv_data_cp.data[adv_data_cp.length + segment_length] = (uuid[i]); segment_length++;
  }
  adv_data_cp.data[adv_data_cp.length + segment_length] = (major_number >> 8 & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (major_number & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (minor_number >> 8 & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (minor_number & 0x00FF); segment_length++;
  adv_data_cp.data[adv_data_cp.length + segment_length] = (twoc(rssi_value, 8)); segment_length++;
  adv_data_cp.data[adv_data_cp.length] = (segment_length - 1);
  adv_data_cp.length += segment_length;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x0008;
  rq.cparam = &adv_data_cp;
  rq.clen = 32;
  rq.rparam = &status;
  rq.rlen = 1;
  ret = hci_send_req(device_handle, &rq, 1000);
  hci_close_dev(device_handle);
  if(ret < 0)
  {
    fprintf(stderr, "Can't send request %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  if (status)
  {
    fprintf(stderr, "LE set advertise returned status %d\n", status);
    return(1);
  }
}

variable_types: struct le_set_advertising_parameters_cp { unsigned short min_interval; unsigned short max_interval; unsigned char advtype; unsigned char own_bdaddr_type; unsigned char direct_bdaddr_type; struct bdaddr_t { unsigned char b[6]; } direct_bdaddr; unsigned char chan_map; unsigned char filter; }

variable_types:
status
unsigned char

variable_types: struct hci_request { unsigned short ogf; unsigned short ocf; int event; void *cparam; int clen; void *rparam; int rlen; }

variable_types: ret int

variable_types: struct le_set_advertise_enable_cp { unsigned char enable; }

variable_types: struct le_set_advertising_data_cp { unsigned char length; unsigned char data[31]; }

variable_types:
uuid
unsigned int *

user_defined_types: struct le_set_advertising_parameters_cp { unsigned short min_interval; unsigned short max_interval; unsigned char advtype; unsigned char own_bdaddr_type; unsigned char direct_bdaddr_type; struct bdaddr_t direct_bdaddr; unsigned char chan_map; unsigned char filter; }


decompiled_code:
__int64 disable_advertising()
{
int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx
char *v3; // rax
unsigned __int8 v4; // [rsp+2Eh] [rbp-1Ah]

hci_get_route();
if ( (int)hci_open_dev() < 0 )
{
perror("Could not open device");
}
else
{
v0 = hci_send_req();
result = hci_close_dev();
if ( v0 < 0 )
{
v2 = *__errno_location();
v3 = strerror(v2);
fprintf(stderr, "Can't set advertise mode: %s (%d)\n", v3, v2);
}
else
{
if ( !v4 )
return result;
fprintf(stderr, "LE set advertise enable on returned status %d\n", v4);
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx
char *v3; // rax
unsigned __int8 v4; // [rsp+2Eh] [rbp-1Ah]

hci_get_route();
if ( (int)hci_open_dev() < 0 )
{
perror("Could not open device");
}
else
{
v0 = hci_send_req();
result = hci_close_dev();
if ( v0 < 0 )
{
v2 = *__errno_location();
v3 = strerror(v2);
fprintf(stderr, "Can't set advertise mode: %s (%d)\n", v3, v2);
}
else
{
if ( !v4 )
return result;
fprintf(stderr, "LE set advertise enable on returned status %d\n", v4);
}
}
return 1LL;
}

original_code:
int disable_advertising()
{
  int device_id = hci_get_route(((void *)0));
  int device_handle = 0;
  if((device_handle = hci_open_dev(device_id)) < 0)
  {
    perror("Could not open device");
    return(1);
  }
  le_set_advertise_enable_cp advertise_cp;
  uint8_t status;
  memset(&advertise_cp, 0, sizeof(advertise_cp));
  struct hci_request rq;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x000A;
  rq.cparam = &advertise_cp;
  rq.clen = 1;
  rq.rparam = &status;
  rq.rlen = 1;
  int ret = hci_send_req(device_handle, &rq, 1000);
  hci_close_dev(device_handle);
  if (ret < 0)
  {
    fprintf(stderr, "Can't set advertise mode: %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  if (status)
  {
    fprintf(stderr, "LE set advertise enable on returned status %d\n", status);
    return(1);
  }
}

canonical_original_code:
int disable_advertising()
{
  int device_id = hci_get_route(((void *)0));
  int device_handle = 0;
  if((device_handle = hci_open_dev(device_id)) < 0)
  {
    perror("Could not open device");
    return(1);
  }
  struct le_set_advertise_enable_cp advertise_cp;
  unsigned char status;
  memset(&advertise_cp, 0, sizeof(advertise_cp));
  struct hci_request rq;
  memset(&rq, 0, sizeof(rq));
  rq.ogf = 0x08;
  rq.ocf = 0x000A;
  rq.cparam = &advertise_cp;
  rq.clen = 1;
  rq.rparam = &status;
  rq.rlen = 1;
  int ret = hci_send_req(device_handle, &rq, 1000);
  hci_close_dev(device_handle);
  if (ret < 0)
  {
    fprintf(stderr, "Can't set advertise mode: %s (%d)\n", strerror((*__errno_location ())), (*__errno_location ()));
    return(1);
  }
  if (status)
  {
    fprintf(stderr, "LE set advertise enable on returned status %d\n", status);
    return(1);
  }
}

user_defined_types: struct le_set_advertise_enable_cp { unsigned char enable; }

user_defined_types: struct hci_request { unsigned short ogf; unsigned short ocf; int event; void *cparam; int clen; void *rparam; int rlen; }


decompiled_code:
__int64 __fastcall is_numeric(char *a1)
{
char v1; // al

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char v1; // al

v1 = *a1;
if ( !*a1 )
return 1LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v1 = *++a1;
if ( !*a1 )
return 1LL;
}
return 0LL;
}

original_code:
static int is_numeric(char* string)
{
 while (*string) {
  if (*string < '0' ||
      *string > '9')
   return (0);
  ++string;
 }
 return (1);
}

canonical_original_code:
static int is_numeric(char *string)
{
 while (*string) {
  if (*string < '0' ||
      *string > '9')
   return (0);
  ++string;
 }
 return (1);
}

variable_types:
string
char *


usage

decompiled_code:
int usage()
{
return puts(
"Usage: cheeky_control [option value]*\n"
"Here is a list of all options:\n"
"\t--brighness/-b: LED_LOW_BR (or 0), LED_MIDDLE_BR (or 1), LED_HIGH_BR (or 2)\n"
"\t--speed/-s: A number between 0 and 15\n"
"\t--horizontal_move/-m: LED_NO_HMOVE (or 0), LED_RIGHT_TO_LEFT (or 1), LED_LEFT_TO_RIGHT (or 2)\n"
"\t--vertical_move/-v: LED_NO_VMOVE (or 0), LED_UP_TO_DOWN (or 1), LED_DOWN_TO_UP (or 2)\n"
"\t--flash/-f: LED_NO_FLASH (or 0), LED_FLASHING (or 1)\n"
"\t--negative/-n: LED_NOEGATIVE_OFF (or 0), LED_NEGATIVE_ON (or 1)\n"
"\t--help/-h: Print this message");
}

canonical_decompiled_code:
int func8()
{
return puts(
"Usage: cheeky_control [option value]*\n"
"Here is a list of all options:\n"
"\t--brighness/-b: LED_LOW_BR (or 0), LED_MIDDLE_BR (or 1), LED_HIGH_BR (or 2)\n"
"\t--speed/-s: A number between 0 and 15\n"
"\t--horizontal_move/-m: LED_NO_HMOVE (or 0), LED_RIGHT_TO_LEFT (or 1), LED_LEFT_TO_RIGHT (or 2)\n"
"\t--vertical_move/-v: LED_NO_VMOVE (or 0), LED_UP_TO_DOWN (or 1), LED_DOWN_TO_UP (or 2)\n"
"\t--flash/-f: LED_NO_FLASH (or 0), LED_FLASHING (or 1)\n"
"\t--negative/-n: LED_NOEGATIVE_OFF (or 0), LED_NEGATIVE_ON (or 1)\n"
"\t--help/-h: Print this message");
}

original_code:
static void usage(void)
{
 printf("Usage: cheeky_control [option value]*\n"
        "Here is a list of all options:\n"
        "\t--brighness/-b: LED_LOW_BR (or 0), LED_MIDDLE_BR (or 1), LED_HIGH_BR (or 2)\n"
        "\t--speed/-s: A number between 0 and 15\n"
        "\t--horizontal_move/-m: LED_NO_HMOVE (or 0), LED_RIGHT_TO_LEFT (or 1), LED_LEFT_TO_RIGHT (or 2)\n"
        "\t--vertical_move/-v: LED_NO_VMOVE (or 0), LED_UP_TO_DOWN (or 1), LED_DOWN_TO_UP (or 2)\n"
        "\t--flash/-f: LED_NO_FLASH (or 0), LED_FLASHING (or 1)\n"
        "\t--negative/-n: LED_NOEGATIVE_OFF (or 0), LED_NEGATIVE_ON (or 1)\n"
        "\t--help/-h: Print this message\n");
}

canonical_original_code:
static void usage()
{
 printf("Usage: cheeky_control [option value]*\n"
        "Here is a list of all options:\n"
        "\t--brighness/-b: LED_LOW_BR (or 0), LED_MIDDLE_BR (or 1), LED_HIGH_BR (or 2)\n"
        "\t--speed/-s: A number between 0 and 15\n"
        "\t--horizontal_move/-m: LED_NO_HMOVE (or 0), LED_RIGHT_TO_LEFT (or 1), LED_LEFT_TO_RIGHT (or 2)\n"
        "\t--vertical_move/-v: LED_NO_VMOVE (or 0), LED_UP_TO_DOWN (or 1), LED_DOWN_TO_UP (or 2)\n"
        "\t--flash/-f: LED_NO_FLASH (or 0), LED_FLASHING (or 1)\n"
        "\t--negative/-n: LED_NOEGATIVE_OFF (or 0), LED_NEGATIVE_ON (or 1)\n"
        "\t--help/-h: Print this message\n");
}


decompiled_code:
__int64 __fastcall set_speed(char *nptr, int fd)
{
unsigned int v2; // eax
__int64 result; // rax

if ( (unsigned int)is_numeric(nptr) )
{
v2 = atoi(nptr);
ioctl(fd, 4uLL, v2);
result = 0LL;
}
else
{
puts("cheeky_display: Wrong argument to --speed!");
usage();
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *nptr, int fd)
{
unsigned int v2; // eax
__int64 result; // rax

if ( (unsigned int)func7(nptr) )
{
v2 = atoi(nptr);
ioctl(fd, 4uLL, v2);
result = 0LL;
}
else
{
puts("cheeky_display: Wrong argument to --speed!");
func8();
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int set_speed(char* arg,
     int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 2),
        atoi(arg));
 else {
  printf("cheeky_display: Wrong argument to --speed!\n");
  usage();
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int set_speed(char *arg, int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 2),
        atoi(arg));
 else {
  printf("cheeky_display: Wrong argument to --speed!\n");
  usage();
  return (-1);
 }
 return (0);
}

variable_types:
arg
char *


decompiled_code:
__int64 __fastcall set_brighness(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v4; // eax

if ( (unsigned int)is_numeric(nptr) )
{
v4 = atoi(nptr);
ioctl(fd, 2uLL, v4);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_LOW_BR") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 2uLL, 0LL);
}
else
{
v2 = strcmp(nptr, "LED_MIDDLE_BR") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 2uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_HIGH_BR") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 2uLL, 2LL);
}
else
{
puts("cheeky_display: Wrong argument to --brighness!");
usage();
v3 = -1;
}
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v4; // eax

if ( (unsigned int)func7(nptr) )
{
v4 = atoi(nptr);
ioctl(fd, 2uLL, v4);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_LOW_BR") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 2uLL, 0LL);
}
else
{
v2 = strcmp(nptr, "LED_MIDDLE_BR") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 2uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_HIGH_BR") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 2uLL, 2LL);
}
else
{
puts("cheeky_display: Wrong argument to --brighness!");
func8();
v3 = -1;
}
}
}
}
return v3;
}

original_code:
static int set_brighness(char* arg,
         int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 1),
        atoi(arg));
 else if (strcmp(arg, "LED_LOW_BR") == 0)
  ioctl(cheeky_device,
        (1 << 1),
        0);
 else if (strcmp(arg, "LED_MIDDLE_BR") == 0)
  ioctl(cheeky_device,
        (1 << 1),
        1);
 else if (strcmp(arg, "LED_HIGH_BR") == 0)
  ioctl(cheeky_device,
        (1 << 1),
        2);
 else {
  printf("cheeky_display: Wrong argument to --brighness!\n");
  usage();
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int set_brighness(char *arg, int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 1),
        atoi(arg));
 else if (strcmp(arg, "LED_LOW_BR") == 0)
  ioctl(cheeky_device,
        (1 << 1),
        0);
 else if (strcmp(arg, "LED_MIDDLE_BR") == 0)
  ioctl(cheeky_device,
        (1 << 1),
        1);
 else if (strcmp(arg, "LED_HIGH_BR") == 0)
  ioctl(cheeky_device,
        (1 << 1),
        2);
 else {
  printf("cheeky_display: Wrong argument to --brighness!\n");
  usage();
  return (-1);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall set_flashing(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v5; // eax

if ( (unsigned int)is_numeric(nptr) )
{
v5 = atoi(nptr);
ioctl(fd, 0x20uLL, v5);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_FLASHING") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x20uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_NO_FLASH") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x20uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --flash!");
usage();
v3 = -1;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v5; // eax

if ( (unsigned int)func7(nptr) )
{
v5 = atoi(nptr);
ioctl(fd, 0x20uLL, v5);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_FLASHING") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x20uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_NO_FLASH") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x20uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --flash!");
func8();
v3 = -1;
}
}
}
return v3;
}

original_code:
static int set_flashing(char* arg,
        int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 5),
        atoi(arg));
 else if (strcmp(arg, "LED_FLASHING") == 0)
  ioctl(cheeky_device,
        (1 << 5),
        1);
 else if (strcmp(arg, "LED_NO_FLASH") == 0)
  ioctl(cheeky_device,
        (1 << 5),
        0);
 else {
  printf("cheeky_display: Wrong argument to --flash!\n");
  usage();
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int set_flashing(char *arg, int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 5),
        atoi(arg));
 else if (strcmp(arg, "LED_FLASHING") == 0)
  ioctl(cheeky_device,
        (1 << 5),
        1);
 else if (strcmp(arg, "LED_NO_FLASH") == 0)
  ioctl(cheeky_device,
        (1 << 5),
        0);
 else {
  printf("cheeky_display: Wrong argument to --flash!\n");
  usage();
  return (-1);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall set_hmove(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v4; // eax

if ( (unsigned int)is_numeric(nptr) )
{
v4 = atoi(nptr);
ioctl(fd, 8uLL, v4);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_RIGHT_TO_LEFT") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 8uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_LEFT_TO_RIGHT") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 8uLL, 2LL);
}
else
{
v2 = strcmp(nptr, "LED_NO_HMOVE") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 8uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --hmove!");
usage();
v3 = -1;
}
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v4; // eax

if ( (unsigned int)func7(nptr) )
{
v4 = atoi(nptr);
ioctl(fd, 8uLL, v4);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_RIGHT_TO_LEFT") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 8uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_LEFT_TO_RIGHT") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 8uLL, 2LL);
}
else
{
v2 = strcmp(nptr, "LED_NO_HMOVE") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 8uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --hmove!");
func8();
v3 = -1;
}
}
}
}
return v3;
}

original_code:
static int set_hmove(char* arg,
     int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 3),
        atoi(arg));
 else if (strcmp(arg, "LED_RIGHT_TO_LEFT") == 0)
  ioctl(cheeky_device,
        (1 << 3),
        1);
 else if (strcmp(arg, "LED_LEFT_TO_RIGHT") == 0)
  ioctl(cheeky_device,
        (1 << 3),
        2);
 else if (strcmp(arg, "LED_NO_HMOVE") == 0)
  ioctl(cheeky_device,
        (1 << 3),
        0);
 else {
  printf("cheeky_display: Wrong argument to --hmove!\n");
  usage();
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int set_hmove(char *arg, int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 3),
        atoi(arg));
 else if (strcmp(arg, "LED_RIGHT_TO_LEFT") == 0)
  ioctl(cheeky_device,
        (1 << 3),
        1);
 else if (strcmp(arg, "LED_LEFT_TO_RIGHT") == 0)
  ioctl(cheeky_device,
        (1 << 3),
        2);
 else if (strcmp(arg, "LED_NO_HMOVE") == 0)
  ioctl(cheeky_device,
        (1 << 3),
        0);
 else {
  printf("cheeky_display: Wrong argument to --hmove!\n");
  usage();
  return (-1);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall set_negative(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v5; // eax

if ( (unsigned int)is_numeric(nptr) )
{
v5 = atoi(nptr);
ioctl(fd, 0x40uLL, v5);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_NEGATIVE_ON") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x40uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_NEGATIVE_OFF") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x40uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --negative!");
usage();
v3 = -1;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v5; // eax

if ( (unsigned int)func7(nptr) )
{
v5 = atoi(nptr);
ioctl(fd, 0x40uLL, v5);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_NEGATIVE_ON") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x40uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_NEGATIVE_OFF") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x40uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --negative!");
func8();
v3 = -1;
}
}
}
return v3;
}

original_code:
static int set_negative(char* arg,
        int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 6),
        atoi(arg));
 else if (strcmp(arg, "LED_NEGATIVE_ON") == 0)
  ioctl(cheeky_device,
        (1 << 6),
        1);
 else if (strcmp(arg, "LED_NEGATIVE_OFF") == 0)
  ioctl(cheeky_device,
        (1 << 6),
        0);
 else {
  printf("cheeky_display: Wrong argument to --negative!\n");
  usage();
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int set_negative(char *arg, int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 6),
        atoi(arg));
 else if (strcmp(arg, "LED_NEGATIVE_ON") == 0)
  ioctl(cheeky_device,
        (1 << 6),
        1);
 else if (strcmp(arg, "LED_NEGATIVE_OFF") == 0)
  ioctl(cheeky_device,
        (1 << 6),
        0);
 else {
  printf("cheeky_display: Wrong argument to --negative!\n");
  usage();
  return (-1);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall set_vmove(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v4; // eax

if ( (unsigned int)is_numeric(nptr) )
{
v4 = atoi(nptr);
ioctl(fd, 0x10uLL, v4);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_UP_TO_DOWN") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x10uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_DOWN_TO_UP") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x10uLL, 2LL);
}
else
{
v2 = strcmp(nptr, "LED_NO_VMOVE") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x10uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --vmove!");
usage();
v3 = -1;
}
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *nptr, int fd)
{
bool v2; // zf
unsigned int v3; // ebx
unsigned int v4; // eax

if ( (unsigned int)func7(nptr) )
{
v4 = atoi(nptr);
ioctl(fd, 0x10uLL, v4);
v3 = 0;
}
else
{
v2 = strcmp(nptr, "LED_UP_TO_DOWN") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x10uLL, 1LL);
}
else
{
v2 = strcmp(nptr, "LED_DOWN_TO_UP") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x10uLL, 2LL);
}
else
{
v2 = strcmp(nptr, "LED_NO_VMOVE") == 0;
v3 = !v2;
if ( v2 )
{
ioctl(fd, 0x10uLL, 0LL);
}
else
{
puts("cheeky_display: Wrong argument to --vmove!");
func8();
v3 = -1;
}
}
}
}
return v3;
}

original_code:
static int set_vmove(char* arg,
     int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 4),
        atoi(arg));
 else if (strcmp(arg, "LED_UP_TO_DOWN") == 0)
  ioctl(cheeky_device,
        (1 << 4),
        1);
 else if (strcmp(arg, "LED_DOWN_TO_UP") == 0)
  ioctl(cheeky_device,
        (1 << 4),
        2);
 else if (strcmp(arg, "LED_NO_VMOVE") == 0)
  ioctl(cheeky_device,
        (1 << 4),
        0);
 else {
  printf("cheeky_display: Wrong argument to --vmove!\n");
  usage();
  return (-1);
 }
 return (0);
}

canonical_original_code:
static int set_vmove(char *arg, int cheeky_device)
{
 if (is_numeric(arg))
  ioctl(cheeky_device,
        (1 << 4),
        atoi(arg));
 else if (strcmp(arg, "LED_UP_TO_DOWN") == 0)
  ioctl(cheeky_device,
        (1 << 4),
        1);
 else if (strcmp(arg, "LED_DOWN_TO_UP") == 0)
  ioctl(cheeky_device,
        (1 << 4),
        2);
 else if (strcmp(arg, "LED_NO_VMOVE") == 0)
  ioctl(cheeky_device,
        (1 << 4),
        0);
 else {
  printf("cheeky_display: Wrong argument to --vmove!\n");
  usage();
  return (-1);
 }
 return (0);
}