updateParticles

decompiled_code:
__int64 updateParticles()
{
__int64 v0; // rbp
char *v1; // r12
float v2; // xmm1_4
float *v3; // rbx
__int64 result; // rax
float v5; // xmm0_4
float v6; // xmm0_4
int v7; // eax
_DWORD *v8; // rdx
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
signed int v13; // eax
double v14; // xmm0_8
int v15; // eax
double v16; // xmm0_8
double v17; // [rsp+0h] [rbp-28h]
double v18; // [rsp+8h] [rbp-20h]

v0 = 0LL;
v1 = (char *)particleList;
v2 = *(float *)&LC1;
do
{
v3 = (float *)&v1[v0];
result = *(unsigned int *)&v1[v0];
if ( (_DWORD)result )
{
v5 = v3[1];
if ( v5 > 317.0 || v2 > v5 || (v6 = v3[2], v6 > 237.0) || v6 < 3.0 )
{
*v3 = 0.0;
}
else
{
if ( (_DWORD)result == 7 )
{
v15 = getTimeSingleton();
v1 = (char *)particleList;
v3 = (float *)((char *)particleList + v0);
v16 = sin((double)(v15 - *(_DWORD *)((char *)particleList + v0 + 20)));
result = *(unsigned int *)v3;
v2 = *(float *)&LC1;
*(float *)&v16 = v16 * 3.0;
v3[3] = *(float *)&v16;
}
if ( (_DWORD)result == 6 )
{
v13 = ((unsigned int)getTimeSingleton() - *(_DWORD *)((char *)particleList + v0 + 20)) / 0x64;
*(float *)((char *)particleList + v0 + 4) = *(float *)((char *)particleList + v0 + 4)
+ *(float *)((char *)particleList + v0 + 12);
v17 = (double)v13;
v18 = exp(0.2 * (double)v13);
v14 = sin(v17 * 10.0);
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v3 = (float *)((char *)particleList + v0);
result = *(unsigned int *)((char *)particleList + v0);
*(float *)&v14 = (v14 * v18 + v17) * *(float *)((char *)particleList + v0 + 16) * 0.5
+ *(float *)((char *)particleList + v0 + 8);
*(_DWORD *)((char *)particleList + v0 + 8) = LODWORD(v14);
}
else
{
v3[1] = v3[1] + v3[3];
v3[2] = v3[2] + v3[4];
}
switch ( (int)result )
{
case 1:
case 6:
v10 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v10 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0xFA )
goto LABEL_13;
break;
case 2:
case 5:
v9 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v9 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0x64 )
goto LABEL_13;
break;
case 3:
case 4:
v3[4] = v3[4] + 0.40000001;
v7 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v7 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0xC8 )
goto LABEL_13;
break;
case 7:
v12 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v12 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0x15E )
goto LABEL_13;
break;
case 8:
v11 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v11 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0xAF )
LABEL_13:
*v8 = 0;
break;
default:
break;
}
}
}
v0 += 24LL;
}
while ( v0 != 2400 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp
char *v1; // r12
float v2; // xmm1_4
float *v3; // rbx
__int64 result; // rax
float v5; // xmm0_4
float v6; // xmm0_4
int v7; // eax
_DWORD *v8; // rdx
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
signed int v13; // eax
double v14; // xmm0_8
int v15; // eax
double v16; // xmm0_8
double v17; // [rsp+0h] [rbp-28h]
double v18; // [rsp+8h] [rbp-20h]

v0 = 0LL;
v1 = (char *)particleList;
v2 = *(float *)&LC1;
do
{
v3 = (float *)&v1[v0];
result = *(unsigned int *)&v1[v0];
if ( (_DWORD)result )
{
v5 = v3[1];
if ( v5 > 317.0 || v2 > v5 || (v6 = v3[2], v6 > 237.0) || v6 < 3.0 )
{
*v3 = 0.0;
}
else
{
if ( (_DWORD)result == 7 )
{
v15 = getTimeSingleton();
v1 = (char *)particleList;
v3 = (float *)((char *)particleList + v0);
v16 = sin((double)(v15 - *(_DWORD *)((char *)particleList + v0 + 20)));
result = *(unsigned int *)v3;
v2 = *(float *)&LC1;
*(float *)&v16 = v16 * 3.0;
v3[3] = *(float *)&v16;
}
if ( (_DWORD)result == 6 )
{
v13 = ((unsigned int)getTimeSingleton() - *(_DWORD *)((char *)particleList + v0 + 20)) / 0x64;
*(float *)((char *)particleList + v0 + 4) = *(float *)((char *)particleList + v0 + 4)
+ *(float *)((char *)particleList + v0 + 12);
v17 = (double)v13;
v18 = exp(0.2 * (double)v13);
v14 = sin(v17 * 10.0);
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v3 = (float *)((char *)particleList + v0);
result = *(unsigned int *)((char *)particleList + v0);
*(float *)&v14 = (v14 * v18 + v17) * *(float *)((char *)particleList + v0 + 16) * 0.5
+ *(float *)((char *)particleList + v0 + 8);
*(_DWORD *)((char *)particleList + v0 + 8) = LODWORD(v14);
}
else
{
v3[1] = v3[1] + v3[3];
v3[2] = v3[2] + v3[4];
}
switch ( (int)result )
{
case 1:
case 6:
v10 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v10 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0xFA )
goto LABEL_13;
break;
case 2:
case 5:
v9 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v9 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0x64 )
goto LABEL_13;
break;
case 3:
case 4:
v3[4] = v3[4] + 0.40000001;
v7 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v7 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0xC8 )
goto LABEL_13;
break;
case 7:
v12 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v12 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0x15E )
goto LABEL_13;
break;
case 8:
v11 = getTimeSingleton();
v1 = (char *)particleList;
v2 = *(float *)&LC1;
v8 = (char *)particleList + v0;
result = (unsigned int)(v11 - *(_DWORD *)((char *)particleList + v0 + 20));
if ( (unsigned int)result > 0xAF )
LABEL_13:
*v8 = 0;
break;
default:
break;
}
}
}
v0 += 24LL;
}
while ( v0 != 2400 );
return result;
}

original_code:
void updateParticles()
{
 int i;
 for (i = 0; i < 100; i++)
 {
  if (particleList[i].type == NONE)
  {
   continue;
  }
  if (particleList[i].x > 320 - 3 || particleList[i].x < 1 || particleList[i].y > 240 - 3 || particleList[i].y < 3)
  {
   particleList[i].type = NONE;
   continue;
  }
  if (particleList[i].type == FIRE)
  {
   Uint32 delta = (getTimeSingleton() - particleList[i].startTime);
   particleList[i].xVelo = (float)(3*sin(delta));
  }
  if (particleList[i].type == TELESPARK)
  {
   Uint32 delta = (getTimeSingleton() - particleList[i].startTime)/100;
   particleList[i].x += particleList[i].xVelo;
   particleList[i].y += (delta + exp(0.20 * delta) * sin(10.0 * delta)) * particleList[i].yVelo/2.0f;
  }
  else
  {
   particleList[i].x += particleList[i].xVelo;
   particleList[i].y += particleList[i].yVelo;
  }
  switch(particleList[i].type)
  {
   case TELESPARK:
   case ICE:
   if (getTimeSingleton() - particleList[i].startTime > 250)
   {
    particleList[i].type = NONE;
   }
   break;
   case BLOOD:
   case SWEAT:
   particleList[i].yVelo += 0.4f;
   if (getTimeSingleton() - particleList[i].startTime > 200)
   {
    particleList[i].type = NONE;
   }
   break;
   case HEALTHSPARK:
   case MUD:
   if (getTimeSingleton() - particleList[i].startTime > 100)
   {
    particleList[i].type = NONE;
   }
   break;
   case LIFETEXT:
   if (getTimeSingleton() - particleList[i].startTime > 175)
   {
    particleList[i].type = NONE;
   }
   break;
   case FIRE:
   if (getTimeSingleton() - particleList[i].startTime > 350)
   {
    particleList[i].type = NONE;
   }
   break;
   default:
   break;
  }
 }
}

canonical_original_code:
void updateParticles()
{
 int i;
 for (i = 0; i < 100; i++)
 {
  if (particleList[i].type == NONE)
  {
   continue;
  }
  if (particleList[i].x > 320 - 3 || particleList[i].x < 1 || particleList[i].y > 240 - 3 || particleList[i].y < 3)
  {
   particleList[i].type = NONE;
   continue;
  }
  if (particleList[i].type == FIRE)
  {
   unsigned int delta = (getTimeSingleton() - particleList[i].startTime);
   particleList[i].xVelo = (float)(3*sin(delta));
  }
  if (particleList[i].type == TELESPARK)
  {
   unsigned int delta = (getTimeSingleton() - particleList[i].startTime)/100;
   particleList[i].x += particleList[i].xVelo;
   particleList[i].y += (delta + exp(0.20 * delta) * sin(10.0 * delta)) * particleList[i].yVelo/2.0f;
  }
  else
  {
   particleList[i].x += particleList[i].xVelo;
   particleList[i].y += particleList[i].yVelo;
  }
  switch(particleList[i].type)
  {
   case TELESPARK:
   case ICE:
   if (getTimeSingleton() - particleList[i].startTime > 250)
   {
    particleList[i].type = NONE;
   }
   break;
   case BLOOD:
   case SWEAT:
   particleList[i].yVelo += 0.4f;
   if (getTimeSingleton() - particleList[i].startTime > 200)
   {
    particleList[i].type = NONE;
   }
   break;
   case HEALTHSPARK:
   case MUD:
   if (getTimeSingleton() - particleList[i].startTime > 100)
   {
    particleList[i].type = NONE;
   }
   break;
   case LIFETEXT:
   if (getTimeSingleton() - particleList[i].startTime > 175)
   {
    particleList[i].type = NONE;
   }
   break;
   case FIRE:
   if (getTimeSingleton() - particleList[i].startTime > 350)
   {
    particleList[i].type = NONE;
   }
   break;
   default:
   break;
  }
 }
}

variable_types:
delta
unsigned int


pushParticle

repo: FrostTree-Games/PrinceProtect

decompiled_code:
__int64 __fastcall pushParticle(int a1, float a2, float a3, float a4, float a5)
{
float *v5; // rbx

v5 = (float *)particleList;
while ( *(_DWORD *)v5 )
{
v5 += 6;
if ( v5 == (float *)((char *)particleList + 2400) )
return 0LL;
}
*(_DWORD *)v5 = a1;
v5[1] = a2;
v5[2] = a3;
v5[3] = a4;
v5[4] = a5;
*((_DWORD *)v5 + 5) = getTimeSingleton();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, float a2, float a3, float a4, float a5)
{
float *v5; // rbx

v5 = (float *)particleList;
while ( *(_DWORD *)v5 )
{
v5 += 6;
if ( v5 == (float *)((char *)particleList + 2400) )
return 0LL;
}
*(_DWORD *)v5 = a1;
v5[1] = a2;
v5[2] = a3;
v5[3] = a4;
v5[4] = a5;
*((_DWORD *)v5 + 5) = getTimeSingleton();
return 1LL;
}

original_code:
int pushParticle(ParticleType p, float newX, float newY, float newXSpeed, float newYSpeed)
{
 int i;
 for (i = 0; i < 100; i++)
 {
  if (particleList[i].type != NONE)
  {
   continue;
  }
  else
  {
   particleList[i].type = p;
   particleList[i].x = newX;
                        particleList[i].y = newY;
                        particleList[i].xVelo = newXSpeed;
                        particleList[i].yVelo = newYSpeed;
                        particleList[i].startTime = getTimeSingleton();
                        return 1;
  }
 }
 return 0;
}

canonical_original_code:
int pushParticle(enum ParticleType p, float newX, float newY, float newXSpeed, float newYSpeed)
{
 int i;
 for (i = 0; i < 100; i++)
 {
  if (particleList[i].type != NONE)
  {
   continue;
  }
  else
  {
   particleList[i].type = p;
   particleList[i].x = newX;
                        particleList[i].y = newY;
                        particleList[i].xVelo = newXSpeed;
                        particleList[i].yVelo = newYSpeed;
                        particleList[i].startTime = getTimeSingleton();
                        return 1;
  }
 }
 return 0;
}

variable_types: enum ParticleType { NONE=0, ICE=1, MUD=2, BLOOD=3, SWEAT=4, HEALTHSPARK=5, TELESPARK=6, FIRE=7, LIFETEXT=8 }

variable_types: newX float

variable_types: newY float

variable_types: newXSpeed float

variable_types: newYSpeed float

variable_types: i int

return_type: int


getParticleList

decompiled_code:
void *getParticleList()
{
return particleList;
}

canonical_decompiled_code:
void *func4()
{
return particleList;
}

original_code:
Particle* getParticleList()
{
 return particleList;
}

canonical_original_code:
struct Particle *getParticleList()
{
 return particleList;
}

return_type: struct Particle { enum ParticleType { NONE=0, ICE=1, MUD=2, BLOOD=3, SWEAT=4, HEALTHSPARK=5, TELESPARK=6, FIRE=7, LIFETEXT=8 } type; float x; float xVelo; unsigned int startTime; } *

user_defined_types: struct Particle { enum ParticleType type; float x; float xVelo; unsigned int startTime; }


loadSFXFiles

decompiled_code:
__int64 loadSFXFiles()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax

v0 = SDL_RWFromFile("aud/sfx/open.wav", &unk_FC4);
wipe_open = Mix_LoadWAV_RW(v0, 1LL);
if ( !wipe_open )
fwrite("Error loading wipe 1 sound effect. Check for aud/sfx/open.wav\n", 1uLL, 0x3EuLL, stderr);
v1 = SDL_RWFromFile("aud/sfx/close.wav", &unk_FC4);
wipe_close = Mix_LoadWAV_RW(v1, 1LL);
if ( !wipe_close )
fwrite("Error loading wipe 2 sound effect. Check for aud/sfx/close.wav\n", 1uLL, 0x3FuLL, stderr);
v2 = SDL_RWFromFile("aud/sfx/die.wav", &unk_FC4);
player_die = Mix_LoadWAV_RW(v2, 1LL);
if ( !player_die )
fwrite("Error loading knockout sound effect. Check for aud/sfx/die.wav\n", 1uLL, 0x3FuLL, stderr);
v3 = SDL_RWFromFile("aud/sfx/crash.wav", &unk_FC4);
crash = Mix_LoadWAV_RW(v3, 1LL);
if ( !crash )
fwrite("Error loading knockout crash effect. Check for aud/sfx/crash.wav\n", 1uLL, 0x41uLL, stderr);
v4 = SDL_RWFromFile("aud/sfx/menu.wav", &unk_FC4);
menuClick = Mix_LoadWAV_RW(v4, 1LL);
if ( !menuClick )
fwrite("Error loading menu sound effect. Check for aud/sfx/menu.wav\n", 1uLL, 0x3CuLL, stderr);
v5 = SDL_RWFromFile("aud/sfx/explosion.wav", &unk_FC4);
explosion = Mix_LoadWAV_RW(v5, 1LL);
if ( !explosion )
fwrite("Error loading explosion sound effect. Check for aud/sfx/explosion.wav\n", 1uLL, 0x46uLL, stderr);
v6 = SDL_RWFromFile("aud/sfx/hurt.wav", &unk_FC4);
player_hurt = Mix_LoadWAV_RW(v6, 1LL);
if ( !player_hurt )
fwrite("Error loading player damage sound effect. Check for aud/sfx/hurt.wav\n", 1uLL, 0x45uLL, stderr);
v7 = SDL_RWFromFile("aud/sfx/ice.wav", &unk_FC4);
ice = Mix_LoadWAV_RW(v7, 1LL);
if ( !ice )
fwrite("Error loading ice sound effect. Check for aud/sfx/ice.wav\n", 1uLL, 0x3AuLL, stderr);
v8 = SDL_RWFromFile("aud/sfx/laser.wav", &unk_FC4);
laser = Mix_LoadWAV_RW(v8, 1LL);
if ( !laser )
fwrite("Error loading shiruken sound effect. Check for aud/sfx/laser.wav\n", 1uLL, 0x41uLL, stderr);
v9 = SDL_RWFromFile("aud/sfx/laser_alt.wav", &unk_FC4);
laser_alt = Mix_LoadWAV_RW(v9, 1LL);
if ( !laser_alt )
fwrite("Error loading second shiruken sound effect. Check for aud/sfx/laser_alt.wav\n", 1uLL, 0x4CuLL, stderr);
v10 = SDL_RWFromFile("aud/sfx/mud.wav", &unk_FC4);
mudSplat = Mix_LoadWAV_RW(v10, 1LL);
if ( !mudSplat )
fwrite("Error loading poof sound effect. Check for aud/sfx/mud.wav\n", 1uLL, 0x3BuLL, stderr);
v11 = SDL_RWFromFile("aud/sfx/mud2.wav", &unk_FC4);
mudSplat2 = Mix_LoadWAV_RW(v11, 1LL);
if ( !mudSplat2 )
fwrite("Error loading glue sound effect. Check for aud/sfx/mud2.wav\n", 1uLL, 0x3CuLL, stderr);
v12 = SDL_RWFromFile("aud/sfx/sword.wav", &unk_FC4);
swordStrike = Mix_LoadWAV_RW(v12, 1LL);
if ( !swordStrike )
fwrite("Error loading sword sound effect. Check for aud/sfx/sword.wav\n", 1uLL, 0x3EuLL, stderr);
v13 = SDL_RWFromFile("aud/sfx/teleport.wav", &unk_FC4);
teleport = Mix_LoadWAV_RW(v13, 1LL);
if ( !teleport )
fwrite("Error loading teleport sound effect. Check for aud/sfx/teleport.wav\n", 1uLL, 0x44uLL, stderr);
v14 = SDL_RWFromFile("aud/sfx/princess.wav", &unk_FC4);
princessYell = Mix_LoadWAV_RW(v14, 1LL);
if ( !princessYell )
fwrite("Error loading prince yelling sound effect. Check for aud/sfx/princess.wav\n", 1uLL, 0x4AuLL, stderr);
v15 = SDL_RWFromFile("aud/sfx/enemyKill.wav", &unk_FC4);
enemy_die = Mix_LoadWAV_RW(v15, 1LL);
if ( !enemy_die )
fwrite("Error loading enemy death sound effect. Check for aud/sfx/enemyKill.wav\n", 1uLL, 0x48uLL, stderr);
v16 = SDL_RWFromFile("aud/sfx/enemyHurt.wav", &unk_FC4);
enemy_hurt = Mix_LoadWAV_RW(v16, 1LL);
if ( !enemy_hurt )
fwrite("Error loading enemy damage sound effect. Check for aud/sfx/enemyHurt.wav\n", 1uLL, 0x49uLL, stderr);
v17 = SDL_RWFromFile("aud/sfx/getHammer.wav", &unk_FC4);
get_hammer = Mix_LoadWAV_RW(v17, 1LL);
if ( !get_hammer )
fwrite("Error loading hammer sound effect. Check for aud/sfx/getHammer.wav\n", 1uLL, 0x43uLL, stderr);
v18 = SDL_RWFromFile("aud/sfx/ready.wav", &unk_FC4);
readyJingle = Mix_LoadWAV_RW(v18, 1LL);
if ( !readyJingle )
fwrite("Error loading ready Jingle effect. Check for aud/sfx/ready.wav\n", 1uLL, 0x3FuLL, stderr);
v19 = SDL_RWFromFile("aud/sfx/losePrincess.wav", &unk_FC4);
losePrincess = Mix_LoadWAV_RW(v19, 1LL);
if ( !losePrincess )
fwrite("Error loading prince escape effect. Check for aud/sfx/losePrincess.wav\n", 1uLL, 0x47uLL, stderr);
v20 = SDL_RWFromFile("aud/sfx/decoy.wav", &unk_FC4);
decoyYell = Mix_LoadWAV_RW(v20, 1LL);
if ( !decoyYell )
fwrite("Error loading decoy prince effect. Check for aud/sfx/decoy.wav\n", 1uLL, 0x3FuLL, stderr);
v21 = SDL_RWFromFile("aud/sfx/heart.wav", &unk_FC4);
heartSound = Mix_LoadWAV_RW(v21, 1LL);
if ( !heartSound )
fwrite("Error loading heart sound effect. Check for aud/sfx/heart.wav\n", 1uLL, 0x3EuLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax

v0 = SDL_RWFromFile("aud/sfx/open.wav", &unk_FC4);
wipe_open = Mix_LoadWAV_RW(v0, 1LL);
if ( !wipe_open )
fwrite("Error loading wipe 1 sound effect. Check for aud/sfx/open.wav\n", 1uLL, 0x3EuLL, stderr);
v1 = SDL_RWFromFile("aud/sfx/close.wav", &unk_FC4);
wipe_close = Mix_LoadWAV_RW(v1, 1LL);
if ( !wipe_close )
fwrite("Error loading wipe 2 sound effect. Check for aud/sfx/close.wav\n", 1uLL, 0x3FuLL, stderr);
v2 = SDL_RWFromFile("aud/sfx/die.wav", &unk_FC4);
player_die = Mix_LoadWAV_RW(v2, 1LL);
if ( !player_die )
fwrite("Error loading knockout sound effect. Check for aud/sfx/die.wav\n", 1uLL, 0x3FuLL, stderr);
v3 = SDL_RWFromFile("aud/sfx/crash.wav", &unk_FC4);
crash = Mix_LoadWAV_RW(v3, 1LL);
if ( !crash )
fwrite("Error loading knockout crash effect. Check for aud/sfx/crash.wav\n", 1uLL, 0x41uLL, stderr);
v4 = SDL_RWFromFile("aud/sfx/menu.wav", &unk_FC4);
menuClick = Mix_LoadWAV_RW(v4, 1LL);
if ( !menuClick )
fwrite("Error loading menu sound effect. Check for aud/sfx/menu.wav\n", 1uLL, 0x3CuLL, stderr);
v5 = SDL_RWFromFile("aud/sfx/explosion.wav", &unk_FC4);
explosion = Mix_LoadWAV_RW(v5, 1LL);
if ( !explosion )
fwrite("Error loading explosion sound effect. Check for aud/sfx/explosion.wav\n", 1uLL, 0x46uLL, stderr);
v6 = SDL_RWFromFile("aud/sfx/hurt.wav", &unk_FC4);
player_hurt = Mix_LoadWAV_RW(v6, 1LL);
if ( !player_hurt )
fwrite("Error loading player damage sound effect. Check for aud/sfx/hurt.wav\n", 1uLL, 0x45uLL, stderr);
v7 = SDL_RWFromFile("aud/sfx/ice.wav", &unk_FC4);
ice = Mix_LoadWAV_RW(v7, 1LL);
if ( !ice )
fwrite("Error loading ice sound effect. Check for aud/sfx/ice.wav\n", 1uLL, 0x3AuLL, stderr);
v8 = SDL_RWFromFile("aud/sfx/laser.wav", &unk_FC4);
laser = Mix_LoadWAV_RW(v8, 1LL);
if ( !laser )
fwrite("Error loading shiruken sound effect. Check for aud/sfx/laser.wav\n", 1uLL, 0x41uLL, stderr);
v9 = SDL_RWFromFile("aud/sfx/laser_alt.wav", &unk_FC4);
laser_alt = Mix_LoadWAV_RW(v9, 1LL);
if ( !laser_alt )
fwrite("Error loading second shiruken sound effect. Check for aud/sfx/laser_alt.wav\n", 1uLL, 0x4CuLL, stderr);
v10 = SDL_RWFromFile("aud/sfx/mud.wav", &unk_FC4);
mudSplat = Mix_LoadWAV_RW(v10, 1LL);
if ( !mudSplat )
fwrite("Error loading poof sound effect. Check for aud/sfx/mud.wav\n", 1uLL, 0x3BuLL, stderr);
v11 = SDL_RWFromFile("aud/sfx/mud2.wav", &unk_FC4);
mudSplat2 = Mix_LoadWAV_RW(v11, 1LL);
if ( !mudSplat2 )
fwrite("Error loading glue sound effect. Check for aud/sfx/mud2.wav\n", 1uLL, 0x3CuLL, stderr);
v12 = SDL_RWFromFile("aud/sfx/sword.wav", &unk_FC4);
swordStrike = Mix_LoadWAV_RW(v12, 1LL);
if ( !swordStrike )
fwrite("Error loading sword sound effect. Check for aud/sfx/sword.wav\n", 1uLL, 0x3EuLL, stderr);
v13 = SDL_RWFromFile("aud/sfx/teleport.wav", &unk_FC4);
teleport = Mix_LoadWAV_RW(v13, 1LL);
if ( !teleport )
fwrite("Error loading teleport sound effect. Check for aud/sfx/teleport.wav\n", 1uLL, 0x44uLL, stderr);
v14 = SDL_RWFromFile("aud/sfx/princess.wav", &unk_FC4);
princessYell = Mix_LoadWAV_RW(v14, 1LL);
if ( !princessYell )
fwrite("Error loading prince yelling sound effect. Check for aud/sfx/princess.wav\n", 1uLL, 0x4AuLL, stderr);
v15 = SDL_RWFromFile("aud/sfx/enemyKill.wav", &unk_FC4);
enemy_die = Mix_LoadWAV_RW(v15, 1LL);
if ( !enemy_die )
fwrite("Error loading enemy death sound effect. Check for aud/sfx/enemyKill.wav\n", 1uLL, 0x48uLL, stderr);
v16 = SDL_RWFromFile("aud/sfx/enemyHurt.wav", &unk_FC4);
enemy_hurt = Mix_LoadWAV_RW(v16, 1LL);
if ( !enemy_hurt )
fwrite("Error loading enemy damage sound effect. Check for aud/sfx/enemyHurt.wav\n", 1uLL, 0x49uLL, stderr);
v17 = SDL_RWFromFile("aud/sfx/getHammer.wav", &unk_FC4);
get_hammer = Mix_LoadWAV_RW(v17, 1LL);
if ( !get_hammer )
fwrite("Error loading hammer sound effect. Check for aud/sfx/getHammer.wav\n", 1uLL, 0x43uLL, stderr);
v18 = SDL_RWFromFile("aud/sfx/ready.wav", &unk_FC4);
readyJingle = Mix_LoadWAV_RW(v18, 1LL);
if ( !readyJingle )
fwrite("Error loading ready Jingle effect. Check for aud/sfx/ready.wav\n", 1uLL, 0x3FuLL, stderr);
v19 = SDL_RWFromFile("aud/sfx/losePrincess.wav", &unk_FC4);
losePrincess = Mix_LoadWAV_RW(v19, 1LL);
if ( !losePrincess )
fwrite("Error loading prince escape effect. Check for aud/sfx/losePrincess.wav\n", 1uLL, 0x47uLL, stderr);
v20 = SDL_RWFromFile("aud/sfx/decoy.wav", &unk_FC4);
decoyYell = Mix_LoadWAV_RW(v20, 1LL);
if ( !decoyYell )
fwrite("Error loading decoy prince effect. Check for aud/sfx/decoy.wav\n", 1uLL, 0x3FuLL, stderr);
v21 = SDL_RWFromFile("aud/sfx/heart.wav", &unk_FC4);
heartSound = Mix_LoadWAV_RW(v21, 1LL);
if ( !heartSound )
fwrite("Error loading heart sound effect. Check for aud/sfx/heart.wav\n", 1uLL, 0x3EuLL, stderr);
return 0LL;
}

original_code:
int loadSFXFiles()
{
 if ( (wipe_open = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/open.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading wipe 1 sound effect. Check for aud/sfx/open.wav\n");
 }
 if ( (wipe_close = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/close.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading wipe 2 sound effect. Check for aud/sfx/close.wav\n");
 }
 if ( (player_die = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/die.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading knockout sound effect. Check for aud/sfx/die.wav\n");
 }
 if ( (crash = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/crash.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading knockout crash effect. Check for aud/sfx/crash.wav\n");
 }
 if ( (menuClick = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/menu.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading menu sound effect. Check for aud/sfx/menu.wav\n");
 }
 if ( (explosion = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/explosion.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading explosion sound effect. Check for aud/sfx/explosion.wav\n");
 }
 if ( (player_hurt = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/hurt.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading player damage sound effect. Check for aud/sfx/hurt.wav\n");
 }
 if ( (ice = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/ice.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading ice sound effect. Check for aud/sfx/ice.wav\n");
 }
 if ( (laser = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/laser.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading shiruken sound effect. Check for aud/sfx/laser.wav\n");
 }
 if ( (laser_alt = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/laser_alt.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading second shiruken sound effect. Check for aud/sfx/laser_alt.wav\n");
 }
 if ( (mudSplat = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/mud.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading poof sound effect. Check for aud/sfx/mud.wav\n");
 }
 if ( (mudSplat2 = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/mud2.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading glue sound effect. Check for aud/sfx/mud2.wav\n");
 }
 if ( (swordStrike = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/sword.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading sword sound effect. Check for aud/sfx/sword.wav\n");
 }
 if ( (teleport = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/teleport.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading teleport sound effect. Check for aud/sfx/teleport.wav\n");
 }
 if ( (princessYell = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/princess.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading prince yelling sound effect. Check for aud/sfx/princess.wav\n");
 }
 if ( (enemy_die = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/enemyKill.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading enemy death sound effect. Check for aud/sfx/enemyKill.wav\n");
 }
 if ( (enemy_hurt = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/enemyHurt.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading enemy damage sound effect. Check for aud/sfx/enemyHurt.wav\n");
 }
 if ( (get_hammer = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/getHammer.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading hammer sound effect. Check for aud/sfx/getHammer.wav\n");
 }
 if ( (readyJingle = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/ready.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading ready Jingle effect. Check for aud/sfx/ready.wav\n");
 }
 if ( (losePrincess = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/losePrincess.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading prince escape effect. Check for aud/sfx/losePrincess.wav\n");
 }
 if ( (decoyYell = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/decoy.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading decoy prince effect. Check for aud/sfx/decoy.wav\n");
 }
 if ( (heartSound = Mix_LoadWAV_RW(SDL_RWFromFile("aud/sfx/heart.wav", "rb"), 1)) == ((void *)0))
 {
  fprintf(stderr, "Error loading heart sound effect. Check for aud/sfx/heart.wav\n");
 }
 return 0;
}


loadBGMFiles

decompiled_code:
__int64 loadBGMFiles()
{
bgm1 = Mix_LoadMUS("aud/bgm/artifical_turf.it");
if ( !bgm1 )
fwrite("Error loading background music 1. Check for aud/sfx/artifical_turf.it\n", 1uLL, 0x46uLL, stderr);
bgm2 = Mix_LoadMUS("aud/bgm/pretty_weeds.it");
if ( !bgm2 )
fwrite("Error loading background music 2. Check for aud/sfx/pretty_weeds.it\n", 1uLL, 0x44uLL, stderr);
bgm3 = Mix_LoadMUS("aud/bgm/real_grass.it");
if ( !bgm3 )
fwrite("Error loading background music 2. Check for aud/sfx/real_grass.it\n", 1uLL, 0x42uLL, stderr);
titleSong = Mix_LoadMUS("aud/bgm/title.ogg");
if ( !titleSong )
fwrite("Error loading title screen music! Oh no! Check for aud/sfx/title.ogg\n", 1uLL, 0x45uLL, stderr);
keyConfig = Mix_LoadMUS("aud/bgm/keyConfig.wav");
if ( !keyConfig )
fwrite("Error loading key config music. Check for aud/sfx/keyConfig.wav\n", 1uLL, 0x40uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
bgm1 = Mix_LoadMUS("aud/bgm/artifical_turf.it");
if ( !bgm1 )
fwrite("Error loading background music 1. Check for aud/sfx/artifical_turf.it\n", 1uLL, 0x46uLL, stderr);
bgm2 = Mix_LoadMUS("aud/bgm/pretty_weeds.it");
if ( !bgm2 )
fwrite("Error loading background music 2. Check for aud/sfx/pretty_weeds.it\n", 1uLL, 0x44uLL, stderr);
bgm3 = Mix_LoadMUS("aud/bgm/real_grass.it");
if ( !bgm3 )
fwrite("Error loading background music 2. Check for aud/sfx/real_grass.it\n", 1uLL, 0x42uLL, stderr);
titleSong = Mix_LoadMUS("aud/bgm/title.ogg");
if ( !titleSong )
fwrite("Error loading title screen music! Oh no! Check for aud/sfx/title.ogg\n", 1uLL, 0x45uLL, stderr);
keyConfig = Mix_LoadMUS("aud/bgm/keyConfig.wav");
if ( !keyConfig )
fwrite("Error loading key config music. Check for aud/sfx/keyConfig.wav\n", 1uLL, 0x40uLL, stderr);
return 0LL;
}

original_code:
int loadBGMFiles()
{
 if ( (bgm1 = Mix_LoadMUS("aud/bgm/artifical_turf.it")) == ((void *)0))
 {
  fprintf(stderr, "Error loading background music 1. Check for aud/sfx/artifical_turf.it\n");
 }
 if ( (bgm2 = Mix_LoadMUS("aud/bgm/pretty_weeds.it")) == ((void *)0))
 {
  fprintf(stderr, "Error loading background music 2. Check for aud/sfx/pretty_weeds.it\n");
 }
 if ( (bgm3 = Mix_LoadMUS("aud/bgm/real_grass.it")) == ((void *)0))
 {
  fprintf(stderr, "Error loading background music 2. Check for aud/sfx/real_grass.it\n");
 }
 if ( (titleSong = Mix_LoadMUS("aud/bgm/title.ogg")) == ((void *)0))
 {
  fprintf(stderr, "Error loading title screen music! Oh no! Check for aud/sfx/title.ogg\n");
 }
 if ( (keyConfig = Mix_LoadMUS("aud/bgm/keyConfig.wav")) == ((void *)0))
 {
  fprintf(stderr, "Error loading key config music. Check for aud/sfx/keyConfig.wav\n");
 }
 return 0;
}


setupAudio

decompiled_code:
__int64 setupAudio()
{
const char *v0; // rax
__int64 result; // rax
const char *v2; // rax

if ( (Mix_Init(10LL) & 0xA) != 10 )
{
fwrite("Mix_Init: Failed to init required ogg support!\n", 1uLL, 0x2FuLL, stderr);
v0 = (const char *)SDL_GetError();
fprintf(stderr, "Mix_Init: %s\n", v0);
}
if ( (unsigned int)Mix_OpenAudio(22050LL, 32784LL, 2LL, 4096LL) == -1 )
{
fwrite("Error initalizing SDL_mixer. Check various libs.\n", 1uLL, 0x31uLL, stderr);
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Mix_OpenAudio: %s\n", v2);
result = 1LL;
}
else if ( (unsigned int)loadSFXFiles() == 1 || (unsigned int)loadBGMFiles() == 1 )
{
result = 1LL;
}
else
{
audioInitalized = 1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
const char *v0; // rax
__int64 result; // rax
const char *v2; // rax

if ( (Mix_Init(10LL) & 0xA) != 10 )
{
fwrite("Mix_Init: Failed to init required ogg support!\n", 1uLL, 0x2FuLL, stderr);
v0 = (const char *)SDL_GetError();
fprintf(stderr, "Mix_Init: %s\n", v0);
}
if ( (unsigned int)Mix_OpenAudio(22050LL, 32784LL, 2LL, 4096LL) == -1 )
{
fwrite("Error initalizing SDL_mixer. Check various libs.\n", 1uLL, 0x31uLL, stderr);
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Mix_OpenAudio: %s\n", v2);
result = 1LL;
}
else if ( (unsigned int)func0() == 1 || (unsigned int)func1() == 1 )
{
result = 1LL;
}
else
{
audioInitalized = 1;
result = 0LL;
}
return result;
}

original_code:
int setupAudio()
{
 int flags=MIX_INIT_OGG | MIX_INIT_MOD;
 int initted=Mix_Init(flags);
 if((initted & flags) != flags)
 {
  fprintf(stderr, "Mix_Init: Failed to init required ogg support!\n");
  fprintf(stderr, "Mix_Init: %s\n", SDL_GetError());
 }
 if (Mix_OpenAudio(22050, 0x8010, 2, 4096) == -1)
 {
  fprintf(stderr, "Error initalizing SDL_mixer. Check various libs.\n");
  fprintf(stderr, "Mix_OpenAudio: %s\n", SDL_GetError());
  return 1;
 }
 if (loadSFXFiles() == 1)
 {
  return 1;
 }
 if (loadBGMFiles() == 1)
 {
  return 1;
 }
 audioInitalized = 1;
 return 0;
}

canonical_original_code:
int setupAudio()
{
 int flags = MIX_INIT_OGG | MIX_INIT_MOD;
 int initted = Mix_Init(flags);
 if((initted & flags) != flags)
 {
  fprintf(stderr, "Mix_Init: Failed to init required ogg support!\n");
  fprintf(stderr, "Mix_Init: %s\n", SDL_GetError());
 }
 if (Mix_OpenAudio(22050, 0x8010, 2, 4096) == -1)
 {
  fprintf(stderr, "Error initalizing SDL_mixer. Check various libs.\n");
  fprintf(stderr, "Mix_OpenAudio: %s\n", SDL_GetError());
  return 1;
 }
 if (loadSFXFiles() == 1)
 {
  return 1;
 }
 if (loadBGMFiles() == 1)
 {
  return 1;
 }
 audioInitalized = 1;
 return 0;
}

variable_types: flags int

variable_types: initted int


clearAudio

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

Mix_FreeChunk(explosion);
Mix_FreeChunk(player_hurt);
Mix_FreeChunk(ice);
Mix_FreeChunk(laser);
Mix_FreeChunk(laser_alt);
Mix_FreeChunk(mudSplat);
Mix_FreeChunk(mudSplat2);
Mix_FreeChunk(swordStrike);
Mix_FreeChunk(teleport);
Mix_FreeChunk(princessYell);
Mix_FreeChunk(crash);
Mix_FreeChunk(wipe_open);
Mix_FreeChunk(wipe_close);
Mix_FreeChunk(enemy_die);
Mix_FreeChunk(enemy_hurt);
Mix_FreeChunk(get_hammer);
Mix_FreeChunk(readyJingle);
Mix_FreeChunk(losePrincess);
Mix_FreeChunk(decoyYell);
Mix_FreeChunk(heartSound);
Mix_FreeMusic(bgm1);
Mix_FreeMusic(bgm2);
Mix_FreeMusic(bgm3);
Mix_FreeMusic(titleSong);
Mix_FreeMusic(keyConfig);
result = Mix_CloseAudio();
audioInitalized = 0;
return result;
}

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

Mix_FreeChunk(explosion);
Mix_FreeChunk(player_hurt);
Mix_FreeChunk(ice);
Mix_FreeChunk(laser);
Mix_FreeChunk(laser_alt);
Mix_FreeChunk(mudSplat);
Mix_FreeChunk(mudSplat2);
Mix_FreeChunk(swordStrike);
Mix_FreeChunk(teleport);
Mix_FreeChunk(princessYell);
Mix_FreeChunk(crash);
Mix_FreeChunk(wipe_open);
Mix_FreeChunk(wipe_close);
Mix_FreeChunk(enemy_die);
Mix_FreeChunk(enemy_hurt);
Mix_FreeChunk(get_hammer);
Mix_FreeChunk(readyJingle);
Mix_FreeChunk(losePrincess);
Mix_FreeChunk(decoyYell);
Mix_FreeChunk(heartSound);
Mix_FreeMusic(bgm1);
Mix_FreeMusic(bgm2);
Mix_FreeMusic(bgm3);
Mix_FreeMusic(titleSong);
Mix_FreeMusic(keyConfig);
result = Mix_CloseAudio();
audioInitalized = 0;
return result;
}

original_code:
void clearAudio()
{
 Mix_FreeChunk(explosion);
 Mix_FreeChunk(player_hurt);
 Mix_FreeChunk(ice);
 Mix_FreeChunk(laser);
 Mix_FreeChunk(laser_alt);
 Mix_FreeChunk(mudSplat);
 Mix_FreeChunk(mudSplat2);
 Mix_FreeChunk(swordStrike);
 Mix_FreeChunk(teleport);
 Mix_FreeChunk(princessYell);
 Mix_FreeChunk(crash);
 Mix_FreeChunk(wipe_open);
 Mix_FreeChunk(wipe_close);
 Mix_FreeChunk(enemy_die);
 Mix_FreeChunk(enemy_hurt);
 Mix_FreeChunk(get_hammer);
 Mix_FreeChunk(readyJingle);
 Mix_FreeChunk(losePrincess);
 Mix_FreeChunk(decoyYell);
 Mix_FreeChunk(heartSound);
 Mix_FreeMusic(bgm1);
 Mix_FreeMusic(bgm2);
 Mix_FreeMusic(bgm3);
 Mix_FreeMusic(titleSong);
 Mix_FreeMusic(keyConfig);
 Mix_CloseAudio();
 audioInitalized = 0;
 return;
}

return_type: void


playSFX

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

if ( muteSFX != 1 && a1 )
{
switch ( a1 )
{
case 1:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, explosion, 0LL, 0xFFFFFFFFLL);
break;
case 3:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, player_hurt, 0LL, 0xFFFFFFFFLL);
break;
case 14:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, player_die, 0LL, 0xFFFFFFFFLL);
break;
case 4:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, ice, 0LL, 0xFFFFFFFFLL);
break;
case 5:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, laser, 0LL, 0xFFFFFFFFLL);
break;
case 6:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, laser_alt, 0LL, 0xFFFFFFFFLL);
break;
case 7:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, menuClick, 0LL, 0xFFFFFFFFLL);
break;
case 8:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, mudSplat, 0LL, 0xFFFFFFFFLL);
break;
case 9:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, mudSplat2, 0LL, 0xFFFFFFFFLL);
break;
case 10:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, swordStrike, 0LL, 0xFFFFFFFFLL);
break;
case 11:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, teleport, 0LL, 0xFFFFFFFFLL);
break;
case 12:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, princessYell, 0LL, 0xFFFFFFFFLL);
break;
case 2:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, crash, 0LL, 0xFFFFFFFFLL);
break;
case 15:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, wipe_open, 0LL, 0xFFFFFFFFLL);
break;
case 16:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, wipe_close, 0LL, 0xFFFFFFFFLL);
break;
case 17:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, enemy_die, 0LL, 0xFFFFFFFFLL);
break;
case 18:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, enemy_hurt, 0LL, 0xFFFFFFFFLL);
break;
case 19:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, get_hammer, 0LL, 0xFFFFFFFFLL);
break;
case 20:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, readyJingle, 0LL, 0xFFFFFFFFLL);
break;
case 21:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, losePrincess, 0LL, 0xFFFFFFFFLL);
break;
case 13:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, decoyYell, 0LL, 0xFFFFFFFFLL);
break;
case 22:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, heartSound, 0LL, 0xFFFFFFFFLL);
break;
}
}
return result;
}

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

if ( muteSFX != 1 && a1 )
{
switch ( a1 )
{
case 1:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, explosion, 0LL, 0xFFFFFFFFLL);
break;
case 3:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, player_hurt, 0LL, 0xFFFFFFFFLL);
break;
case 14:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, player_die, 0LL, 0xFFFFFFFFLL);
break;
case 4:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, ice, 0LL, 0xFFFFFFFFLL);
break;
case 5:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, laser, 0LL, 0xFFFFFFFFLL);
break;
case 6:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, laser_alt, 0LL, 0xFFFFFFFFLL);
break;
case 7:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, menuClick, 0LL, 0xFFFFFFFFLL);
break;
case 8:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, mudSplat, 0LL, 0xFFFFFFFFLL);
break;
case 9:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, mudSplat2, 0LL, 0xFFFFFFFFLL);
break;
case 10:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, swordStrike, 0LL, 0xFFFFFFFFLL);
break;
case 11:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, teleport, 0LL, 0xFFFFFFFFLL);
break;
case 12:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, princessYell, 0LL, 0xFFFFFFFFLL);
break;
case 2:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, crash, 0LL, 0xFFFFFFFFLL);
break;
case 15:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, wipe_open, 0LL, 0xFFFFFFFFLL);
break;
case 16:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, wipe_close, 0LL, 0xFFFFFFFFLL);
break;
case 17:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, enemy_die, 0LL, 0xFFFFFFFFLL);
break;
case 18:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, enemy_hurt, 0LL, 0xFFFFFFFFLL);
break;
case 19:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, get_hammer, 0LL, 0xFFFFFFFFLL);
break;
case 20:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, readyJingle, 0LL, 0xFFFFFFFFLL);
break;
case 21:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, losePrincess, 0LL, 0xFFFFFFFFLL);
break;
case 13:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, decoyYell, 0LL, 0xFFFFFFFFLL);
break;
case 22:
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, heartSound, 0LL, 0xFFFFFFFFLL);
break;
}
}
return result;
}

original_code:
void playSFX(SFXType fx)
{
 if (muteSFX == 1)
 {
  return;
 }
 if (fx == SFX_NONE)
 {
  return;
 }
 if (fx == SFX_EXPLOSION)
 {
  Mix_PlayChannelTimed(-1,explosion,0,-1);
 }
 if (fx == SFX_PLAYER_HURT)
 {
  Mix_PlayChannelTimed(-1,player_hurt,0,-1);
 }
 if (fx == SFX_PLAYER_DEATH)
 {
  Mix_PlayChannelTimed(-1,player_die,0,-1);
 }
 if (fx == SFX_ICE_TINK)
 {
  Mix_PlayChannelTimed(-1,ice,0,-1);
 }
 if (fx == SFX_LASER_1)
 {
  Mix_PlayChannelTimed(-1,laser,0,-1);
 }
 if (fx == SFX_LASER_2)
 {
  Mix_PlayChannelTimed(-1,laser_alt,0,-1);
 }
 if (fx == SFX_MENU)
 {
  Mix_PlayChannelTimed(-1,menuClick,0,-1);
 }
 if (fx == SFX_MUD)
 {
  Mix_PlayChannelTimed(-1,mudSplat,0,-1);
 }
 if (fx == SFX_MUD2)
 {
  Mix_PlayChannelTimed(-1,mudSplat2,0,-1);
 }
 if (fx == SFX_SWORD)
 {
  Mix_PlayChannelTimed(-1,swordStrike,0,-1);
 }
 if (fx == SFX_TELEPORT)
 {
  Mix_PlayChannelTimed(-1,teleport,0,-1);
 }
 if (fx == SFX_PRINCESS_YELL)
 {
  Mix_PlayChannelTimed(-1,princessYell,0,-1);
 }
 if (fx == SFX_CRASH)
 {
  Mix_PlayChannelTimed(-1,crash,0,-1);
 }
 if (fx == SFX_WIPE_OPEN)
 {
  Mix_PlayChannelTimed(-1,wipe_open,0,-1);
 }
 if (fx == SFX_WIPE_CLOSE)
 {
  Mix_PlayChannelTimed(-1,wipe_close,0,-1);
 }
 if (fx == SFX_ENEMY_DIE)
 {
  Mix_PlayChannelTimed(-1,enemy_die,0,-1);
 }
 if (fx == SFX_ENEMY_HURT)
 {
  Mix_PlayChannelTimed(-1,enemy_hurt,0,-1);
 }
 if (fx == SFX_GET_HAMMER)
 {
  Mix_PlayChannelTimed(-1,get_hammer,0,-1);
 }
 if (fx == SFX_READY_JINGLE)
 {
  Mix_PlayChannelTimed(-1,readyJingle,0,-1);
 }
 if (fx == SFX_LOSE_PRINCESS)
 {
  Mix_PlayChannelTimed(-1,losePrincess,0,-1);
 }
 if (fx == SFX_DECOY_YELL)
 {
  Mix_PlayChannelTimed(-1,decoyYell,0,-1);
 }
 if (fx == SFX_LIFEUP)
 {
  Mix_PlayChannelTimed(-1,heartSound,0,-1);
 }
}

canonical_original_code:
void playSFX(enum SFXType fx)
{
 if (muteSFX == 1)
 {
  return;
 }
 if (fx == SFX_NONE)
 {
  return;
 }
 if (fx == SFX_EXPLOSION)
 {
  Mix_PlayChannelTimed(-1,explosion,0,-1);
 }
 if (fx == SFX_PLAYER_HURT)
 {
  Mix_PlayChannelTimed(-1,player_hurt,0,-1);
 }
 if (fx == SFX_PLAYER_DEATH)
 {
  Mix_PlayChannelTimed(-1,player_die,0,-1);
 }
 if (fx == SFX_ICE_TINK)
 {
  Mix_PlayChannelTimed(-1,ice,0,-1);
 }
 if (fx == SFX_LASER_1)
 {
  Mix_PlayChannelTimed(-1,laser,0,-1);
 }
 if (fx == SFX_LASER_2)
 {
  Mix_PlayChannelTimed(-1,laser_alt,0,-1);
 }
 if (fx == SFX_MENU)
 {
  Mix_PlayChannelTimed(-1,menuClick,0,-1);
 }
 if (fx == SFX_MUD)
 {
  Mix_PlayChannelTimed(-1,mudSplat,0,-1);
 }
 if (fx == SFX_MUD2)
 {
  Mix_PlayChannelTimed(-1,mudSplat2,0,-1);
 }
 if (fx == SFX_SWORD)
 {
  Mix_PlayChannelTimed(-1,swordStrike,0,-1);
 }
 if (fx == SFX_TELEPORT)
 {
  Mix_PlayChannelTimed(-1,teleport,0,-1);
 }
 if (fx == SFX_PRINCESS_YELL)
 {
  Mix_PlayChannelTimed(-1,princessYell,0,-1);
 }
 if (fx == SFX_CRASH)
 {
  Mix_PlayChannelTimed(-1,crash,0,-1);
 }
 if (fx == SFX_WIPE_OPEN)
 {
  Mix_PlayChannelTimed(-1,wipe_open,0,-1);
 }
 if (fx == SFX_WIPE_CLOSE)
 {
  Mix_PlayChannelTimed(-1,wipe_close,0,-1);
 }
 if (fx == SFX_ENEMY_DIE)
 {
  Mix_PlayChannelTimed(-1,enemy_die,0,-1);
 }
 if (fx == SFX_ENEMY_HURT)
 {
  Mix_PlayChannelTimed(-1,enemy_hurt,0,-1);
 }
 if (fx == SFX_GET_HAMMER)
 {
  Mix_PlayChannelTimed(-1,get_hammer,0,-1);
 }
 if (fx == SFX_READY_JINGLE)
 {
  Mix_PlayChannelTimed(-1,readyJingle,0,-1);
 }
 if (fx == SFX_LOSE_PRINCESS)
 {
  Mix_PlayChannelTimed(-1,losePrincess,0,-1);
 }
 if (fx == SFX_DECOY_YELL)
 {
  Mix_PlayChannelTimed(-1,decoyYell,0,-1);
 }
 if (fx == SFX_LIFEUP)
 {
  Mix_PlayChannelTimed(-1,heartSound,0,-1);
 }
}

variable_types: enum SFXType { SFX_NONE=0, SFX_EXPLOSION=1, SFX_CRASH=2, SFX_PLAYER_HURT=3, SFX_ICE_TINK=4, SFX_LASER_1=5, SFX_LASER_2=6, SFX_MENU=7, SFX_MUD=8, SFX_MUD2=9, SFX_SWORD=10, SFX_TELEPORT=11, SFX_PRINCESS_YELL=12, SFX_DECOY_YELL=13, SFX_PLAYER_DEATH=14, SFX_WIPE_OPEN=15, SFX_WIPE_CLOSE=16, SFX_ENEMY_DIE=17, SFX_ENEMY_HURT=18, SFX_GET_HAMMER=19, SFX_READY_JINGLE=20, SFX_LOSE_PRINCESS=21, SFX_LIFEUP=22 }


stopAllSFX

decompiled_code:
__int64 stopAllSFX()
{
return Mix_HaltChannel(0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 func5()
{
return Mix_HaltChannel(0xFFFFFFFFLL);
}

original_code:
void stopAllSFX()
{
 Mix_HaltChannel(-1);
}


playBGM

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

if ( muteBGM != 1 )
{
result = Mix_HaltMusic();
switch ( a1 )
{
case 2:
result = Mix_PlayMusic(bgm1, 0xFFFFFFFFLL);
break;
case 3:
result = Mix_PlayMusic(bgm2, 0xFFFFFFFFLL);
break;
case 4:
result = Mix_PlayMusic(bgm3, 0xFFFFFFFFLL);
break;
case 5:
result = Mix_PlayMusic(titleSong, 0LL);
break;
case 6:
result = Mix_PlayMusic(keyConfig, 0xFFFFFFFFLL);
break;
default:
return result;
}
}
return result;
}

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

if ( muteBGM != 1 )
{
result = Mix_HaltMusic();
switch ( a1 )
{
case 2:
result = Mix_PlayMusic(bgm1, 0xFFFFFFFFLL);
break;
case 3:
result = Mix_PlayMusic(bgm2, 0xFFFFFFFFLL);
break;
case 4:
result = Mix_PlayMusic(bgm3, 0xFFFFFFFFLL);
break;
case 5:
result = Mix_PlayMusic(titleSong, 0LL);
break;
case 6:
result = Mix_PlayMusic(keyConfig, 0xFFFFFFFFLL);
break;
default:
return result;
}
}
return result;
}

original_code:
void playBGM(BGMType bg)
{
 if (muteBGM == 1)
 {
  return;
 }
 Mix_HaltMusic();
 switch (bg)
 {
  case BGM_1:
  Mix_PlayMusic(bgm1, -1);
  break;
  case BGM_2:
  Mix_PlayMusic(bgm2, -1);
  break;
  case BGM_3:
  Mix_PlayMusic(bgm3, -1);
  break;
  case BGM_TITLE:
  Mix_PlayMusic(titleSong, 0);
  break;
  case BGM_KEYCONFIG:
  Mix_PlayMusic(keyConfig, -1);
  break;
  default:
  break;
 }
}

canonical_original_code:
void playBGM(enum BGMType bg)
{
 if (muteBGM == 1)
 {
  return;
 }
 Mix_HaltMusic();
 switch (bg)
 {
  case BGM_1:
  Mix_PlayMusic(bgm1, -1);
  break;
  case BGM_2:
  Mix_PlayMusic(bgm2, -1);
  break;
  case BGM_3:
  Mix_PlayMusic(bgm3, -1);
  break;
  case BGM_TITLE:
  Mix_PlayMusic(titleSong, 0);
  break;
  case BGM_KEYCONFIG:
  Mix_PlayMusic(keyConfig, -1);
  break;
  default:
  break;
 }
}

variable_types: enum BGMType { BGM_NONE=0, BGM_ANGSTY=1, BGM_1=2, BGM_2=3, BGM_3=4, BGM_TITLE=5, BGM_KEYCONFIG=6 }


stopBGM

decompiled_code:
// attributes: thunk
__int64 stopBGM()
{
return Mix_HaltMusic();
}

canonical_decompiled_code:
__int64 func7()
{
return Mix_HaltMusic();
}

original_code:
void stopBGM()
{
 Mix_HaltMusic();
}

canonical_original_code:
void stopBGM()
{
 Mix_HaltMusic();
}


fadeBGM

decompiled_code:
__int64 fadeBGM()
{
return Mix_FadeOutMusic(2000LL);
}

canonical_decompiled_code:
__int64 func8()
{
return Mix_FadeOutMusic(2000LL);
}

original_code:
void fadeBGM()
{
 Mix_FadeOutMusic(2000);
}


toggleBGM

decompiled_code:
_BOOL8 __fastcall toggleBGM(int a1)
{
_BOOL8 result; // rax

result = a1 == 0;
muteBGM = a1 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1)
{
_BOOL8 result; // rax

result = a1 == 0;
muteBGM = a1 == 0;
return result;
}

original_code:
void toggleBGM(int aud)
{
 if (aud == 0)
 {
  muteBGM = 1;
 }
 else
 {
  muteBGM = 0;
 }
}

variable_types: aud int


toggleSFX

decompiled_code:
_BOOL8 __fastcall toggleSFX(int a1)
{
_BOOL8 result; // rax

result = a1 == 0;
muteSFX = a1 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(int a1)
{
_BOOL8 result; // rax

result = a1 == 0;
muteSFX = a1 == 0;
return result;
}

original_code:
void toggleSFX(int aud)
{
 if (aud == 0)
 {
  muteSFX = 1;
 }
 else
 {
  muteSFX = 0;
 }
}


repo: FunkyCat/crypt-bruteforce

decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv, __int64 a3)
{
int v5; // eax
const char *v6; // rdi
const char *v7; // rdi
char *v8; // rax
const char *v9; // rdi
const char *v10; // rdi
__int64 v11; // rsi
int v12; // eax
const char *v13; // rdi
const char *v15; // rdi
const char *v16; // rdi
char *v17; // rax

while ( 1 )
{
v5 = getopt(argc, argv, "smctlbpahxye");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v10 = argv[optind++];
*(_DWORD *)(a3 + 188) = inet_addr(v10);
break;
case 'b':
v9 = argv[optind++];
*(_DWORD *)(a3 + 176) = atoi(v9);
break;
case 'c':
*(_DWORD *)(a3 + 180) = 2;
break;
case 'e':
*(_DWORD *)(a3 + 180) = 6;
break;
case 'h':
v8 = argv[optind++];
*(_QWORD *)(a3 + 16) = v8;
break;
case 'l':
v7 = argv[optind++];
*(_DWORD *)(a3 + 8) = atoi(v7);
break;
case 'm':
*(_DWORD *)(a3 + 180) = 1;
break;
case 'p':
v6 = argv[optind++];
*(_WORD *)(a3 + 184) = atoi(v6);
break;
case 's':
*(_DWORD *)(a3 + 180) = 0;
break;
case 't':
*(_DWORD *)(a3 + 180) = 3;
break;
case 'x':
*(_DWORD *)(a3 + 180) = 5;
break;
case 'y':
*(_DWORD *)(a3 + 180) = 4;
break;
default:
fprintf(stderr, "Usage: %s [-smctlbaph]\n", *argv);
exit(1);
}
}
if ( *(int *)(a3 + 176) < 0 )
{
fwrite("Block size parameter can't be less then 0\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
v11 = *(unsigned int *)(a3 + 8);
if ( (int)v11 <= 0 )
{
fwrite("Max length parameter can't be less then 1\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
if ( *(__int16 *)(a3 + 184) <= 0 )
{
fwrite("Port value should be between 1 and 65535\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
v12 = *(_DWORD *)(a3 + 180);
if ( !*(_QWORD *)(a3 + 16) && ((v12 - 2) & 0xFFFFFFFD) != 0 )
{
fwrite("error: hash not defined\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
switch ( v12 )
{
case 0:
v15 = "run_mode = RM_SINGLE";
goto LABEL_26;
case 1:
v15 = "run_mode = RM_MULTI";
LABEL_26:
puts(v15);
printf("hash = %s\n", *(const char **)(a3 + 16));
v11 = *(unsigned int *)(a3 + 8);
break;
case 2:
v16 = "run_mode = RM_CLIENT";
goto LABEL_29;
case 3:
v13 = "run_mode = RM_SERVER";
goto LABEL_21;
case 4:
v16 = "run_mode = RM_CLIENT_ASYNC";
LABEL_29:
puts(v16);
printf("port = %d\n", (unsigned int)*(__int16 *)(a3 + 184));
v17 = inet_ntoa(*(struct in_addr *)(a3 + 188));
printf("addr = %s\n", v17);
v11 = *(unsigned int *)(a3 + 8);
break;
case 5:
v13 = "run_mode = RM_SERVER_ASYNC";
goto LABEL_21;
case 6:
v13 = "run_mode = RM_SERVER_EPOLL";
LABEL_21:
puts(v13);
printf("port = %d\n", (unsigned int)*(__int16 *)(a3 + 184));
v11 = *(unsigned int *)(a3 + 8);
break;
default:
break;
}
printf("max_length = %d\n", v11);
printf("block_size = %d\n", *(unsigned int *)(a3 + 176));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, __int64 a3)
{
int v5; // eax
const char *v6; // rdi
const char *v7; // rdi
char *v8; // rax
const char *v9; // rdi
const char *v10; // rdi
__int64 v11; // rsi
int v12; // eax
const char *v13; // rdi
const char *v15; // rdi
const char *v16; // rdi
char *v17; // rax

while ( 1 )
{
v5 = getopt(argc, argv, "smctlbpahxye");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v10 = argv[optind++];
*(_DWORD *)(a3 + 188) = inet_addr(v10);
break;
case 'b':
v9 = argv[optind++];
*(_DWORD *)(a3 + 176) = atoi(v9);
break;
case 'c':
*(_DWORD *)(a3 + 180) = 2;
break;
case 'e':
*(_DWORD *)(a3 + 180) = 6;
break;
case 'h':
v8 = argv[optind++];
*(_QWORD *)(a3 + 16) = v8;
break;
case 'l':
v7 = argv[optind++];
*(_DWORD *)(a3 + 8) = atoi(v7);
break;
case 'm':
*(_DWORD *)(a3 + 180) = 1;
break;
case 'p':
v6 = argv[optind++];
*(_WORD *)(a3 + 184) = atoi(v6);
break;
case 's':
*(_DWORD *)(a3 + 180) = 0;
break;
case 't':
*(_DWORD *)(a3 + 180) = 3;
break;
case 'x':
*(_DWORD *)(a3 + 180) = 5;
break;
case 'y':
*(_DWORD *)(a3 + 180) = 4;
break;
default:
fprintf(stderr, "Usage: %s [-smctlbaph]\n", *argv);
exit(1);
}
}
if ( *(int *)(a3 + 176) < 0 )
{
fwrite("Block size parameter can't be less then 0\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
v11 = *(unsigned int *)(a3 + 8);
if ( (int)v11 <= 0 )
{
fwrite("Max length parameter can't be less then 1\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
if ( *(__int16 *)(a3 + 184) <= 0 )
{
fwrite("Port value should be between 1 and 65535\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
v12 = *(_DWORD *)(a3 + 180);
if ( !*(_QWORD *)(a3 + 16) && ((v12 - 2) & 0xFFFFFFFD) != 0 )
{
fwrite("error: hash not defined\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
switch ( v12 )
{
case 0:
v15 = "run_mode = RM_SINGLE";
goto LABEL_26;
case 1:
v15 = "run_mode = RM_MULTI";
LABEL_26:
puts(v15);
printf("hash = %s\n", *(const char **)(a3 + 16));
v11 = *(unsigned int *)(a3 + 8);
break;
case 2:
v16 = "run_mode = RM_CLIENT";
goto LABEL_29;
case 3:
v13 = "run_mode = RM_SERVER";
goto LABEL_21;
case 4:
v16 = "run_mode = RM_CLIENT_ASYNC";
LABEL_29:
puts(v16);
printf("port = %d\n", (unsigned int)*(__int16 *)(a3 + 184));
v17 = inet_ntoa(*(struct in_addr *)(a3 + 188));
printf("addr = %s\n", v17);
v11 = *(unsigned int *)(a3 + 8);
break;
case 5:
v13 = "run_mode = RM_SERVER_ASYNC";
goto LABEL_21;
case 6:
v13 = "run_mode = RM_SERVER_EPOLL";
LABEL_21:
puts(v13);
printf("port = %d\n", (unsigned int)*(__int16 *)(a3 + 184));
v11 = *(unsigned int *)(a3 + 8);
break;
default:
break;
}
printf("max_length = %d\n", v11);
printf("block_size = %d\n", *(unsigned int *)(a3 + 176));
return 0LL;
}

original_code:
int parse_args (int argc, char * argv[], context_t * context)
{
  int opt;
  while ((opt = getopt (argc, argv, "smctlbpahxye")) != -1)
    {
      switch (opt)
 {
 case 's':
   context->run_mode = RM_SINGLE;
   break;
 case 'm':
   context->run_mode = RM_MULTI;
   break;
 case 'c':
   context->run_mode = RM_CLIENT;
   break;
 case 't':
   context->run_mode = RM_SERVER;
   break;
 case 'x':
   context->run_mode = RM_SERVER_ASYNC;
   break;
 case 'y':
   context->run_mode = RM_CLIENT_ASYNC;
   break;
 case 'e':
   context->run_mode = RM_SERVER_EPOLL;
   break;
 case 'l':
   context->max_length = atoi (argv[optind++]);
   break;
 case 'b':
   context->block_size = atoi (argv[optind++]);
   break;
 case 'a':
   context->addr.s_addr = inet_addr (argv[optind++]);
   break;
 case 'p':
   context->port = atoi (argv[optind++]);
   break;
 case 'h':
   context->hash = argv[optind++];
   break;
 default:
   fprintf (stderr, "Usage: %s [-smctlbaph]\n", argv[0]);
   exit (1);
 }
    }
  if (context->block_size < 0)
    {
      fprintf (stderr, "Block size parameter can't be less then 0\n");
      exit (1);
    }
  if (context->max_length < 1)
    {
      fprintf (stderr, "Max length parameter can't be less then 1\n");
      exit (1);
    }
  if (context->port < 1 || context->port > 65535)
    {
      fprintf (stderr, "Port value should be between 1 and 65535\n");
      exit (1);
    }
  if ((context->hash == ((void *)0)) && (context->run_mode != RM_CLIENT) && (context->run_mode != RM_CLIENT_ASYNC))
    {
      fprintf (stderr, "error: hash not defined\n");
      exit (1);
    }
  switch (context->run_mode)
    {
    case RM_SINGLE:
      printf ("run_mode = RM_SINGLE\n");
      printf ("hash = %s\n", context->hash);
      break;
    case RM_MULTI:
      printf ("run_mode = RM_MULTI\n");
      printf ("hash = %s\n", context->hash);
      break;
    case RM_CLIENT:
      printf ("run_mode = RM_CLIENT\n");
      printf ("port = %d\n", context->port);
      printf ("addr = %s\n", inet_ntoa (context->addr));
      break;
    case RM_SERVER:
      printf ("run_mode = RM_SERVER\n");
      printf ("port = %d\n", context->port);
      break;
    case RM_CLIENT_ASYNC:
      printf ("run_mode = RM_CLIENT_ASYNC\n");
      printf ("port = %d\n", context->port);
      printf ("addr = %s\n", inet_ntoa (context->addr));
      break;
    case RM_SERVER_ASYNC:
      printf ("run_mode = RM_SERVER_ASYNC\n");
      printf ("port = %d\n", context->port);
      break;
    case RM_SERVER_EPOLL:
      printf ("run_mode = RM_SERVER_EPOLL\n");
      printf ("port = %d\n", context->port);
      break;
    }
  printf ("max_length = %d\n", context->max_length);
  printf ("block_size = %d\n", context->block_size);
  return 0;
}

canonical_original_code:
int parse_args(int argc, char *argv[], struct context_s *context)
{
  int opt;
  while ((opt = getopt (argc, argv, "smctlbpahxye")) != -1)
    {
      switch (opt)
 {
 case 's':
   context->run_mode = RM_SINGLE;
   break;
 case 'm':
   context->run_mode = RM_MULTI;
   break;
 case 'c':
   context->run_mode = RM_CLIENT;
   break;
 case 't':
   context->run_mode = RM_SERVER;
   break;
 case 'x':
   context->run_mode = RM_SERVER_ASYNC;
   break;
 case 'y':
   context->run_mode = RM_CLIENT_ASYNC;
   break;
 case 'e':
   context->run_mode = RM_SERVER_EPOLL;
   break;
 case 'l':
   context->max_length = atoi (argv[optind++]);
   break;
 case 'b':
   context->block_size = atoi (argv[optind++]);
   break;
 case 'a':
   context->addr.s_addr = inet_addr (argv[optind++]);
   break;
 case 'p':
   context->port = atoi (argv[optind++]);
   break;
 case 'h':
   context->hash = argv[optind++];
   break;
 default:
   fprintf (stderr, "Usage: %s [-smctlbaph]\n", argv[0]);
   exit (1);
 }
    }
  if (context->block_size < 0)
    {
      fprintf (stderr, "Block size parameter can't be less then 0\n");
      exit (1);
    }
  if (context->max_length < 1)
    {
      fprintf (stderr, "Max length parameter can't be less then 1\n");
      exit (1);
    }
  if (context->port < 1 || context->port > 65535)
    {
      fprintf (stderr, "Port value should be between 1 and 65535\n");
      exit (1);
    }
  if ((context->hash == ((void *)0)) && (context->run_mode != RM_CLIENT) && (context->run_mode != RM_CLIENT_ASYNC))
    {
      fprintf (stderr, "error: hash not defined\n");
      exit (1);
    }
  switch (context->run_mode)
    {
    case RM_SINGLE:
      printf ("run_mode = RM_SINGLE\n");
      printf ("hash = %s\n", context->hash);
      break;
    case RM_MULTI:
      printf ("run_mode = RM_MULTI\n");
      printf ("hash = %s\n", context->hash);
      break;
    case RM_CLIENT:
      printf ("run_mode = RM_CLIENT\n");
      printf ("port = %d\n", context->port);
      printf ("addr = %s\n", inet_ntoa (context->addr));
      break;
    case RM_SERVER:
      printf ("run_mode = RM_SERVER\n");
      printf ("port = %d\n", context->port);
      break;
    case RM_CLIENT_ASYNC:
      printf ("run_mode = RM_CLIENT_ASYNC\n");
      printf ("port = %d\n", context->port);
      printf ("addr = %s\n", inet_ntoa (context->addr));
      break;
    case RM_SERVER_ASYNC:
      printf ("run_mode = RM_SERVER_ASYNC\n");
      printf ("port = %d\n", context->port);
      break;
    case RM_SERVER_EPOLL:
      printf ("run_mode = RM_SERVER_EPOLL\n");
      printf ("port = %d\n", context->port);
      break;
    }
  printf ("max_length = %d\n", context->max_length);
  printf ("block_size = %d\n", context->block_size);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct context_s { char *alph; int max_length; char *hash; struct brute_result_s { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } found_mutex; char password[-1]; int found; } result; int block_size; enum run_mode_t { RM_SINGLE=0, RM_MULTI=1, RM_CLIENT=2, RM_SERVER=3, RM_CLIENT_ASYNC=4, RM_SERVER_ASYNC=5, RM_SERVER_EPOLL=6 } run_mode; short port; struct in_addr { unsigned int s_addr; } addr; int n_cpus; int listener_socket; struct queue_s { struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; } *cd; } queue[-1]; union sem_t { char __size[32]; long __align; } full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } queue; int tasks_in_process; union pthread_mutex_t tasks_in_process_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } tasks_in_process_sem; int threads; union pthread_mutex_t threads_mutex; union pthread_cond_t threads_sem; int continue_execute; union pthread_mutex_t continue_execute_mutex; union pthread_cond_t continue_execute_sem; int id; void *(*srv_client_thread)(struct context_s *, int); struct result_queue_s { struct result_s { struct brute_result_s result; int id; int idx; int final; } queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } result_queue; } *

variable_types: opt int

user_defined_types: struct context_s { char *alph; int max_length; char *hash; struct brute_result_s result; int block_size; enum run_mode_t run_mode; short port; struct in_addr addr; int n_cpus; int listener_socket; struct queue_s queue; int tasks_in_process; union pthread_mutex_t tasks_in_process_mutex; union pthread_cond_t tasks_in_process_sem; int threads; union pthread_mutex_t threads_mutex; union pthread_cond_t threads_sem; int continue_execute; union pthread_mutex_t continue_execute_mutex; union pthread_cond_t continue_execute_sem; int id; void *(*srv_client_thread)(struct context_s *, int); struct result_queue_s result_queue; }

user_defined_types: struct brute_result_s { union pthread_mutex_t found_mutex; char password[-1]; int found; }

user_defined_types: struct queue_s { struct task_s queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct result_queue_s { struct result_s queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data *cd; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[407]; // [rsp+0h] [rbp-CB8h] BYREF

memset(v4, 0, 0xCA8uLL);
v4[0] = (__int64)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
v4[22] = 0x100000001LL;
LOWORD(v4[23]) = 3456;
LODWORD(v4[1]) = 6;
v4[24] = 0xFFFFFFFF00000001LL;
parse_args(argc, (char **)argv, (__int64)v4);
switch ( HIDWORD(v4[22]) )
{
case 0:
single_mode(v4);
break;
case 1:
multi_mode(v4);
break;
case 2:
client_mode(v4);
break;
case 3:
server_mode(v4);
break;
case 4:
client_async_mode(v4);
break;
case 5:
server_async_mode(v4);
break;
case 6:
server_epoll_mode(v4);
break;
default:
break;
}
if ( ((HIDWORD(v4[22]) - 2) & 0xFFFFFFFD) != 0 )
{
if ( LODWORD(v4[21]) )
printf("Found! Password: %s\n", (const char *)&v4[8]);
else
puts("Not found");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[407]; // [rsp+0h] [rbp-CB8h] BYREF

memset(v4, 0, 0xCA8uLL);
v4[0] = (__int64)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
v4[22] = 0x100000001LL;
LOWORD(v4[23]) = 3456;
LODWORD(v4[1]) = 6;
v4[24] = 0xFFFFFFFF00000001LL;
func0(argc, (char **)argv, (__int64)v4);
switch ( HIDWORD(v4[22]) )
{
case 0:
single_mode(v4);
break;
case 1:
multi_mode(v4);
break;
case 2:
client_mode(v4);
break;
case 3:
server_mode(v4);
break;
case 4:
client_async_mode(v4);
break;
case 5:
server_async_mode(v4);
break;
case 6:
server_epoll_mode(v4);
break;
default:
break;
}
if ( ((HIDWORD(v4[22]) - 2) & 0xFFFFFFFD) != 0 )
{
if ( LODWORD(v4[21]) )
printf("Found! Password: %s\n", (const char *)&v4[8]);
else
puts("Not found");
}
return 0;
}

original_code:
int main (int argc, char* argv[])
{
  context_t context = {
    .alph = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
    .max_length = 6,
    .result = {
      .found = 0,
      .password[0] = 0,
    },
    .block_size = 1,
    .run_mode = RM_MULTI,
    .port = 3456,
    .addr.s_addr = ((in_addr_t) 0x00000000),
    .n_cpus = 1,
    .hash = ((void *)0),
    .listener_socket = -1,
    .id = 0,
  };
  parse_args (argc, argv, &context);
  switch (context.run_mode)
    {
    case RM_SINGLE:
      single_mode (&context);
      break;
    case RM_MULTI:
      multi_mode (&context);
      break;
    case RM_CLIENT:
      client_mode (&context);
      break;
    case RM_SERVER:
      server_mode (&context);
      break;
    case RM_CLIENT_ASYNC:
      client_async_mode (&context);
      break;
    case RM_SERVER_ASYNC:
      server_async_mode (&context);
      break;
    case RM_SERVER_EPOLL:
      server_epoll_mode (&context);
      break;
    }
  if (context.run_mode != RM_CLIENT && context.run_mode != RM_CLIENT_ASYNC)
    {
      if (context.result.found)
 {
   printf ("Found! Password: %s\n", context.result.password);
 }
      else
 {
   printf ("Not found\n");
 }
    }
  return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  struct context_s context = {
    .alph = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
    .max_length = 6,
    .result = {
      .found = 0,
      .password[0] = 0,
    },
    .block_size = 1,
    .run_mode = RM_MULTI,
    .port = 3456,
    .addr.s_addr = ((in_addr_t) 0x00000000),
    .n_cpus = 1,
    .hash = ((void *)0),
    .listener_socket = -1,
    .id = 0,
  };
  parse_args (argc, argv, &context);
  switch (context.run_mode)
    {
    case RM_SINGLE:
      single_mode (&context);
      break;
    case RM_MULTI:
      multi_mode (&context);
      break;
    case RM_CLIENT:
      client_mode (&context);
      break;
    case RM_SERVER:
      server_mode (&context);
      break;
    case RM_CLIENT_ASYNC:
      client_async_mode (&context);
      break;
    case RM_SERVER_ASYNC:
      server_async_mode (&context);
      break;
    case RM_SERVER_EPOLL:
      server_epoll_mode (&context);
      break;
    }
  if (context.run_mode != RM_CLIENT && context.run_mode != RM_CLIENT_ASYNC)
    {
      if (context.result.found)
 {
   printf ("Found! Password: %s\n", context.result.password);
 }
      else
 {
   printf ("Not found\n");
 }
    }
  return (0);
}

variable_types: struct context_s { char *alph; int max_length; char *hash; struct brute_result_s { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } found_mutex; char password[-1]; int found; } result; int block_size; enum run_mode_t { RM_SINGLE=0, RM_MULTI=1, RM_CLIENT=2, RM_SERVER=3, RM_CLIENT_ASYNC=4, RM_SERVER_ASYNC=5, RM_SERVER_EPOLL=6 } run_mode; short port; struct in_addr { unsigned int s_addr; } addr; int n_cpus; int listener_socket; struct queue_s { struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; } *cd; } queue[-1]; union sem_t { char __size[32]; long __align; } full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } queue; int tasks_in_process; union pthread_mutex_t tasks_in_process_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } tasks_in_process_sem; int threads; union pthread_mutex_t threads_mutex; union pthread_cond_t threads_sem; int continue_execute; union pthread_mutex_t continue_execute_mutex; union pthread_cond_t continue_execute_sem; int id; void *(*srv_client_thread)(struct context_s *, int); struct result_queue_s { struct result_s { struct brute_result_s result; int id; int idx; int final; } queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } result_queue; }


decompiled_code:
void *__fastcall tam_reader_thread(void *a1)
{
__int64 v1; // rbp
int v2; // er12
__int64 v3; // rax
void *ptr; // [rsp+8h] [rbp-130h] BYREF
char v6[144]; // [rsp+10h] [rbp-128h] BYREF
int v7; // [rsp+A0h] [rbp-98h]
int v8; // [rsp+B0h] [rbp-88h]
char src[132]; // [rsp+B4h] [rbp-84h] BYREF

v1 = *((_QWORD *)a1 + 151);
while ( !*(_DWORD *)(v1 + 168) )
{
v2 = recv_message(*((unsigned int *)a1 + 300), &ptr);
fflush(stdout);
if ( v2 )
{
*((_DWORD *)a1 + 304) = 1;
break;
}
xml_to_message(ptr, v6);
free(ptr);
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 1096));
fflush(stdout);
v3 = *((int *)a1 + 272);
*((_DWORD *)a1 + 272) = v3 + 1;
*((_DWORD *)a1 + v3 + 292) = v7;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 1096));
sem_post((sem_t *)((char *)a1 + 1136));
dec_sem(v1 + 1440, v1 + 1488, v1 + 1448);
if ( v8 )
{
*(_DWORD *)(v1 + 168) = 1;
strcpy((char *)(v1 + 64), src);
*(_DWORD *)(v1 + 1632) = 0;
}
}
pthread_cond_broadcast((pthread_cond_t *)(v1 + 1680));
printf("(%d) reader ended\n", *((unsigned int *)a1 + 300));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v1; // rbp
int v2; // er12
__int64 v3; // rax
void *ptr; // [rsp+8h] [rbp-130h] BYREF
char v6[144]; // [rsp+10h] [rbp-128h] BYREF
int v7; // [rsp+A0h] [rbp-98h]
int v8; // [rsp+B0h] [rbp-88h]
char src[132]; // [rsp+B4h] [rbp-84h] BYREF

v1 = *((_QWORD *)a1 + 151);
while ( !*(_DWORD *)(v1 + 168) )
{
v2 = recv_message(*((unsigned int *)a1 + 300), &ptr);
fflush(stdout);
if ( v2 )
{
*((_DWORD *)a1 + 304) = 1;
break;
}
xml_to_message(ptr, v6);
free(ptr);
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 1096));
fflush(stdout);
v3 = *((int *)a1 + 272);
*((_DWORD *)a1 + 272) = v3 + 1;
*((_DWORD *)a1 + v3 + 292) = v7;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 1096));
sem_post((sem_t *)((char *)a1 + 1136));
dec_sem(v1 + 1440, v1 + 1488, v1 + 1448);
if ( v8 )
{
*(_DWORD *)(v1 + 168) = 1;
strcpy((char *)(v1 + 64), src);
*(_DWORD *)(v1 + 1632) = 0;
}
}
pthread_cond_broadcast((pthread_cond_t *)(v1 + 1680));
printf("(%d) reader ended\n", *((unsigned int *)a1 + 300));
return 0LL;
}

original_code:
void * tam_reader_thread (void * args)
{
  client_t * client = args;
  context_t * context = client->context;
  cs_status_t recv_status;
  char * buffer;
  cs_message_t message;
  for (; !context->result.found;)
    {
      recv_status = recv_message (client->fd, &buffer);
      fflush (stdout);
      if (recv_status == S_SUCCESS)
 {
   xml_to_message (buffer, &message);
   free (buffer);
   pthread_mutex_lock (&client->tasks_register.free_mutex);
   fflush (stdout);
   client->tasks_register.free_idx[client->tasks_register.free++] = message.task.idx;
   pthread_mutex_unlock (&client->tasks_register.free_mutex);
   sem_post (&client->tasks_register.empty);
   dec_sem (&context->tasks_in_process, &context->tasks_in_process_sem, &context->tasks_in_process_mutex);
   if (message.result)
     {
       context->result.found = !0;
       strcpy (context->result.password, message.password);
       context->continue_execute = 0;
     }
 }
      else
 {
   client->close = !0;
   break;
 }
    }
  pthread_cond_broadcast (&context->continue_execute_sem);
  printf ("(%d) reader ended\n", client->fd);
  return ((void *)0);
}

canonical_original_code:
void *tam_reader_thread(void *args)
{
  struct client_s *client = args;
  struct context_s *context = client->context;
  enum cs_status_t recv_status;
  char *buffer;
  struct cs_message_t message;
  for (; !context->result.found;)
    {
      recv_status = recv_message (client->fd, &buffer);
      fflush (stdout);
      if (recv_status == S_SUCCESS)
 {
   xml_to_message (buffer, &message);
   free (buffer);
   pthread_mutex_lock (&client->tasks_register.free_mutex);
   fflush (stdout);
   client->tasks_register.free_idx[client->tasks_register.free++] = message.task.idx;
   pthread_mutex_unlock (&client->tasks_register.free_mutex);
   sem_post (&client->tasks_register.empty);
   dec_sem (&context->tasks_in_process, &context->tasks_in_process_sem, &context->tasks_in_process_mutex);
   if (message.result)
     {
       context->result.found = !0;
       strcpy (context->result.password, message.password);
       context->continue_execute = 0;
     }
 }
      else
 {
   client->close = !0;
   break;
 }
    }
  pthread_cond_broadcast (&context->continue_execute_sem);
  printf ("(%d) reader ended\n", client->fd);
  return ((void *)0);
}

variable_types:
args
void *

variable_types: struct client_s { struct tasks_register_s { struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; } *cd; } tasks[-1]; int free; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } free_mutex; union sem_t { char __size[32]; long __align; } empty; int free_idx[-1]; } tasks_register; int fd; struct context_s { char *alph; int max_length; char *hash; struct brute_result_s { union pthread_mutex_t found_mutex; char password[-1]; int found; } result; int block_size; enum run_mode_t { RM_SINGLE=0, RM_MULTI=1, RM_CLIENT=2, RM_SERVER=3, RM_CLIENT_ASYNC=4, RM_SERVER_ASYNC=5, RM_SERVER_EPOLL=6 } run_mode; short port; struct in_addr { unsigned int s_addr; } addr; int n_cpus; int listener_socket; struct queue_s { struct task_s queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } queue; int tasks_in_process; union pthread_mutex_t tasks_in_process_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } tasks_in_process_sem; int threads; union pthread_mutex_t threads_mutex; union pthread_cond_t threads_sem; int continue_execute; union pthread_mutex_t continue_execute_mutex; union pthread_cond_t continue_execute_sem; int id; void *(*srv_client_thread)(struct context_s *, int); struct result_queue_s { struct result_s { struct brute_result_s result; int id; int idx; int final; } queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } result_queue; } *context; int close; int err; } *

variable_types: enum cs_status_t { S_SUCCESS=0, S_MEMORY_ERROR=1, S_RECV_ERROR=2, S_SEND_ERROR=3, S_CONNECTION_CLOSED=4 }

variable_types:
buffer
char *

variable_types: struct cs_message_t { enum cs_message_type_t { MT_SEND_JOB=0, MT_REPORT_RESULT=1 } type; char *alph; char *hash; struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; } *cd; } task; int result; char password[-1]; }

return_type: void *

user_defined_types: struct cs_message_t { enum cs_message_type_t type; char *alph; char *hash; struct task_s task; int result; char password[-1]; }

user_defined_types: struct client_s { struct tasks_register_s tasks_register; int fd; struct context_s *context; int close; int err; }

user_defined_types: struct tasks_register_s { struct task_s tasks[-1]; int free; union pthread_mutex_t free_mutex; union sem_t empty; int free_idx[-1]; }


original_code:
void * tam_writer_thread (void * args)
{
  client_t * client = args;
  context_t * context = client->context;
  task_t task;
  cs_message_t message;
  int send_status;
  for (;;)
    {
      sem_wait (&client->tasks_register.empty);
      queue_pop (&context->queue, &task);
      if (task.final)
 {
   sem_post (&client->tasks_register.empty);
   queue_push (&context->queue, &task);
   break;
 }
      if (context->result.found)
 {
   dec_sem (&context->tasks_in_process, &context->tasks_in_process_sem, &context->tasks_in_process_mutex);
   sem_post (&client->tasks_register.empty);
   continue;
 }
      pthread_mutex_lock (&client->tasks_register.free_mutex);
      task.idx = client->tasks_register.free_idx[--client->tasks_register.free];
      pthread_mutex_unlock (&client->tasks_register.free_mutex);
      client->tasks_register.tasks[task.idx] = task;
      message.type = MT_SEND_JOB;
      message.alph = context->alph;
      message.hash = context->hash;
      message.task = task;
      printf ("(%d) task: [%d.%d] %s\n", client->fd, task.id, task.idx, task.password);
      fflush (stdout);
      send_status = send_message (client->fd, &message);
      if (send_status == -1)
 {
   fprintf (stderr, "error: send_message()\n");
   client->close = !0;
   break;
 }
    }
  pthread_cond_broadcast (&context->continue_execute_sem);
  printf ("(%d) writer ended\n", client->fd);
  return ((void *)0);
}

canonical_original_code:
void *tam_writer_thread(void *args)
{
  struct client_s *client = args;
  struct context_s *context = client->context;
  struct task_s task;
  struct cs_message_t message;
  int send_status;
  for (;;)
    {
      sem_wait (&client->tasks_register.empty);
      queue_pop (&context->queue, &task);
      if (task.final)
 {
   sem_post (&client->tasks_register.empty);
   queue_push (&context->queue, &task);
   break;
 }
      if (context->result.found)
 {
   dec_sem (&context->tasks_in_process, &context->tasks_in_process_sem, &context->tasks_in_process_mutex);
   sem_post (&client->tasks_register.empty);
   continue;
 }
      pthread_mutex_lock (&client->tasks_register.free_mutex);
      task.idx = client->tasks_register.free_idx[--client->tasks_register.free];
      pthread_mutex_unlock (&client->tasks_register.free_mutex);
      client->tasks_register.tasks[task.idx] = task;
      message.type = MT_SEND_JOB;
      message.alph = context->alph;
      message.hash = context->hash;
      message.task = task;
      printf ("(%d) task: [%d.%d] %s\n", client->fd, task.id, task.idx, task.password);
      fflush (stdout);
      send_status = send_message (client->fd, &message);
      if (send_status == -1)
 {
   fprintf (stderr, "error: send_message()\n");
   client->close = !0;
   break;
 }
    }
  pthread_cond_broadcast (&context->continue_execute_sem);
  printf ("(%d) writer ended\n", client->fd);
  return ((void *)0);
}

variable_types: struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; } *cd; }

user_defined_types: enum cs_message_type_t { MT_SEND_JOB=0, MT_REPORT_RESULT=1 }

user_defined_types: enum run_mode_t { RM_SINGLE=0, RM_MULTI=1, RM_CLIENT=2, RM_SERVER=3, RM_CLIENT_ASYNC=4, RM_SERVER_ASYNC=5, RM_SERVER_EPOLL=6 }

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct result_s { struct brute_result_s result; int id; int idx; int final; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
void tasks_register_init (tasks_register_t * tasks_register)
{
  pthread_mutex_init (&tasks_register->free_mutex, ((void *)0));
  sem_init (&tasks_register->empty, 0, (8));
  tasks_register->free = (8);
  int i;
  for (i = 0; i < (8); i++)
    tasks_register->free_idx[i] = i;
}

canonical_original_code:
void tasks_register_init(struct tasks_register_s *tasks_register)
{
  pthread_mutex_init (&tasks_register->free_mutex, ((void *)0));
  sem_init (&tasks_register->empty, 0, (8));
  tasks_register->free = (8);
  int i;
  for (i = 0; i < (8); i++)
    tasks_register->free_idx[i] = i;
}

variable_types: struct tasks_register_s { struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; } *cd; } tasks[-1]; int free; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } free_mutex; union sem_t { char __size[32]; long __align; } empty; int free_idx[-1]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall tam_client_thread(__int64 a1, __int64 a2)
{
char *v3; // rax
char *v4; // rcx
__int64 v5; // rdx
int v6; // eax
int *v7; // r9
char *v8; // rbp
int *v9; // [rsp+8h] [rbp-540h]
pthread_t newthread; // [rsp+10h] [rbp-538h] BYREF
pthread_t th; // [rsp+18h] [rbp-530h] BYREF
__int128 v12[2]; // [rsp+20h] [rbp-528h] BYREF
char arg[1088]; // [rsp+40h] [rbp-508h] BYREF
int v14; // [rsp+480h] [rbp-C8h] BYREF
sem_t sem; // [rsp+4B0h] [rbp-98h] BYREF
char v16[32]; // [rsp+4D0h] [rbp-78h] BYREF
unsigned int v17; // [rsp+4F0h] [rbp-58h]
__int64 v18; // [rsp+4F8h] [rbp-50h]
int v19; // [rsp+500h] [rbp-48h]

printf("(%d) connected\n", a2);
fflush(stdout);
inc_sem(a1 + 1536, a1 + 1584, a1 + 1544);
memset(arg, 0, 0x4C8uLL);
v17 = a2;
v18 = a1;
tasks_register_init((__int64)arg);
pthread_create(&newthread, 0LL, tam_reader_thread, arg);
pthread_create(&th, 0LL, tam_writer_thread, arg);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 1640));
while ( *(_DWORD *)(a1 + 1632) )
{
if ( v19 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 1680), (pthread_mutex_t *)(a1 + 1640));
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 1640));
shutdown(a2, 2);
close(a2);
sem_post(&sem);
printf("(%d) disconnected\n", (unsigned int)a2);
printf("(%d) wait for threads\n", (unsigned int)a2);
pthread_join(th, 0LL);
pthread_join(newthread, 0LL);
printf("(%d) pushing back\n", (unsigned int)a2);
if ( !*(_DWORD *)(a1 + 168) )
{
v12[0] = (__int128)_mm_load_si128((const __m128i *)&LC10);
v12[1] = v12[0];
if ( v14 <= 0 )
{
v6 = 16843009;
}
else
{
v3 = v16;
v4 = &v16[4 * (v14 - 1) + 4];
do
{
v5 = *(int *)v3;
v3 += 4;
*((_DWORD *)v12 + v5) = 0;
}
while ( v3 != v4 );
v6 = v12[0];
}
v7 = (int *)v12 + 1;
v8 = arg;
while ( 1 )
{
if ( v6 )
{
v9 = v7;
printf("(%d) pushed back: [%d.%d] %s\n", v17, *((unsigned int *)v8 + 29), *((unsigned int *)v8 + 30), v8);
queue_push(a1 + 200, v8);
v7 = v9;
}
v8 += 136;
if ( v8 == (char *)&v14 )
break;
v6 = *v7++;
}
}
printf("(%d) ended\n", (unsigned int)a2);
dec_sem(a1 + 1536, a1 + 1584, a1 + 1544);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
char *v3; // rax
char *v4; // rcx
__int64 v5; // rdx
int v6; // eax
int *v7; // r9
char *v8; // rbp
int *v9; // [rsp+8h] [rbp-540h]
pthread_t newthread; // [rsp+10h] [rbp-538h] BYREF
pthread_t th; // [rsp+18h] [rbp-530h] BYREF
__int128 v12[2]; // [rsp+20h] [rbp-528h] BYREF
char arg[1088]; // [rsp+40h] [rbp-508h] BYREF
int v14; // [rsp+480h] [rbp-C8h] BYREF
sem_t sem; // [rsp+4B0h] [rbp-98h] BYREF
char v16[32]; // [rsp+4D0h] [rbp-78h] BYREF
unsigned int v17; // [rsp+4F0h] [rbp-58h]
__int64 v18; // [rsp+4F8h] [rbp-50h]
int v19; // [rsp+500h] [rbp-48h]

printf("(%d) connected\n", a2);
fflush(stdout);
inc_sem(a1 + 1536, a1 + 1584, a1 + 1544);
memset(arg, 0, 0x4C8uLL);
v17 = a2;
v18 = a1;
func2((__int64)arg);
pthread_create(&newthread, 0LL, tam_reader_thread, arg);
pthread_create(&th, 0LL, tam_writer_thread, arg);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 1640));
while ( *(_DWORD *)(a1 + 1632) )
{
if ( v19 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 1680), (pthread_mutex_t *)(a1 + 1640));
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 1640));
shutdown(a2, 2);
close(a2);
sem_post(&sem);
printf("(%d) disconnected\n", (unsigned int)a2);
printf("(%d) wait for threads\n", (unsigned int)a2);
pthread_join(th, 0LL);
pthread_join(newthread, 0LL);
printf("(%d) pushing back\n", (unsigned int)a2);
if ( !*(_DWORD *)(a1 + 168) )
{
v12[0] = (__int128)_mm_load_si128((const __m128i *)&LC10);
v12[1] = v12[0];
if ( v14 <= 0 )
{
v6 = 16843009;
}
else
{
v3 = v16;
v4 = &v16[4 * (v14 - 1) + 4];
do
{
v5 = *(int *)v3;
v3 += 4;
*((_DWORD *)v12 + v5) = 0;
}
while ( v3 != v4 );
v6 = v12[0];
}
v7 = (int *)v12 + 1;
v8 = arg;
while ( 1 )
{
if ( v6 )
{
v9 = v7;
printf("(%d) pushed back: [%d.%d] %s\n", v17, *((unsigned int *)v8 + 29), *((unsigned int *)v8 + 30), v8);
queue_push(a1 + 200, v8);
v7 = v9;
}
v8 += 136;
if ( v8 == (char *)&v14 )
break;
v6 = *v7++;
}
}
printf("(%d) ended\n", (unsigned int)a2);
dec_sem(a1 + 1536, a1 + 1584, a1 + 1544);
return 0LL;
}

original_code:
void * tam_client_thread (context_t * context, int client_socket)
{
 printf ("(%d) connected\n", client_socket);
 fflush (stdout);
 inc_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  client_t client =
    {
      .fd = client_socket,
      .context = context,
      .close = 0,
      .err = 0,
    };
  tasks_register_init (&client.tasks_register);
  pthread_t reader_thread;
  pthread_create (&reader_thread, ((void *)0), tam_reader_thread, &client);
  pthread_t writer_thread;
  pthread_create (&writer_thread, ((void *)0), tam_writer_thread, &client);
  pthread_mutex_lock (&context->continue_execute_mutex);
  while (context->continue_execute != 0 && client.close == 0)
    {
      pthread_cond_wait (&context->continue_execute_sem, &context->continue_execute_mutex);
    }
  pthread_mutex_unlock (&context->continue_execute_mutex);
  shutdown (client_socket, 2);
  close (client_socket);
  sem_post (&client.tasks_register.empty);
  printf ("(%d) disconnected\n", client_socket);
  printf ("(%d) wait for threads\n", client_socket);
  pthread_join (writer_thread, ((void *)0));
  pthread_join (reader_thread, ((void *)0));
  printf ("(%d) pushing back\n", client_socket);
  if (!context->result.found)
    {
      int in_use [(8)];
      memset (in_use, !0, sizeof (in_use));
      int i;
      for (i = 0; i < client.tasks_register.free; i++)
 {
   in_use[client.tasks_register.free_idx[i]] = 0;
 }
      for (i = 0; i < (8); i++)
 {
   if (in_use[i] != 0)
     {
       printf ("(%d) pushed back: [%d.%d] %s\n", client.fd, client.tasks_register.tasks[i].id, client.tasks_register.tasks[i].idx, client.tasks_register.tasks[i].password);
       queue_push (&context->queue, &client.tasks_register.tasks[i]);
     }
 }
    }
  printf ("(%d) ended\n", client_socket);
  dec_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  return ((void *)0);
}

canonical_original_code:
void *tam_client_thread(struct context_s *context, int client_socket)
{
 printf ("(%d) connected\n", client_socket);
 fflush (stdout);
 inc_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  struct client_s client = {
      .fd = client_socket,
      .context = context,
      .close = 0,
      .err = 0,
    };
  tasks_register_init (&client.tasks_register);
  unsigned long reader_thread;
  pthread_create (&reader_thread, ((void *)0), tam_reader_thread, &client);
  unsigned long writer_thread;
  pthread_create (&writer_thread, ((void *)0), tam_writer_thread, &client);
  pthread_mutex_lock (&context->continue_execute_mutex);
  while (context->continue_execute != 0 && client.close == 0)
    {
      pthread_cond_wait (&context->continue_execute_sem, &context->continue_execute_mutex);
    }
  pthread_mutex_unlock (&context->continue_execute_mutex);
  shutdown (client_socket, 2);
  close (client_socket);
  sem_post (&client.tasks_register.empty);
  printf ("(%d) disconnected\n", client_socket);
  printf ("(%d) wait for threads\n", client_socket);
  pthread_join (writer_thread, ((void *)0));
  pthread_join (reader_thread, ((void *)0));
  printf ("(%d) pushing back\n", client_socket);
  if (!context->result.found)
    {
      int in_use[-1];
      memset (in_use, !0, sizeof (in_use));
      int i;
      for (i = 0; i < client.tasks_register.free; i++)
 {
   in_use[client.tasks_register.free_idx[i]] = 0;
 }
      for (i = 0; i < (8); i++)
 {
   if (in_use[i] != 0)
     {
       printf ("(%d) pushed back: [%d.%d] %s\n", client.fd, client.tasks_register.tasks[i].id, client.tasks_register.tasks[i].idx, client.tasks_register.tasks[i].password);
       queue_push (&context->queue, &client.tasks_register.tasks[i]);
     }
 }
    }
  printf ("(%d) ended\n", client_socket);
  dec_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  return ((void *)0);
}

variable_types: struct client_s { struct tasks_register_s { struct task_s { char password[-1]; int left; int right; int final; int id; int idx; struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; } *cd; } tasks[-1]; int free; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } free_mutex; union sem_t { char __size[32]; long __align; } empty; int free_idx[-1]; } tasks_register; int fd; struct context_s { char *alph; int max_length; char *hash; struct brute_result_s { union pthread_mutex_t found_mutex; char password[-1]; int found; } result; int block_size; enum run_mode_t { RM_SINGLE=0, RM_MULTI=1, RM_CLIENT=2, RM_SERVER=3, RM_CLIENT_ASYNC=4, RM_SERVER_ASYNC=5, RM_SERVER_EPOLL=6 } run_mode; short port; struct in_addr { unsigned int s_addr; } addr; int n_cpus; int listener_socket; struct queue_s { struct task_s queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } queue; int tasks_in_process; union pthread_mutex_t tasks_in_process_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } tasks_in_process_sem; int threads; union pthread_mutex_t threads_mutex; union pthread_cond_t threads_sem; int continue_execute; union pthread_mutex_t continue_execute_mutex; union pthread_cond_t continue_execute_sem; int id; void *(*srv_client_thread)(struct context_s *, int); struct result_queue_s { struct result_s { struct brute_result_s result; int id; int idx; int final; } queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; } result_queue; } *context; int close; int err; }

user_defined_types: struct context_s { char *alph; int max_length; char *hash; struct brute_result_s result; int block_size; enum run_mode_t run_mode; short port; struct in_addr addr; int n_cpus; int listener_socket; struct queue_s queue; int tasks_in_process; union pthread_mutex_t tasks_in_process_mutex; union pthread_cond_t tasks_in_process_sem; int threads; union pthread_mutex_t threads_mutex; union pthread_cond_t threads_sem; int continue_execute; union pthread_mutex_t continue_execute_mutex; union pthread_cond_t continue_execute_sem; int id; void *(*srv_client_thread)(struct context_s *, int); struct result_queue_s result_queue; }


decompiled_code:
__int64 __fastcall server_async_mode(__int64 a1)
{
*(_QWORD *)(a1 + 1736) = tam_client_thread;
init_sem(a1 + 1632, 1LL, a1 + 1680, a1 + 1640);
return server(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
*(_QWORD *)(a1 + 1736) = tam_client_thread;
init_sem(a1 + 1632, 1LL, a1 + 1680, a1 + 1640);
return server(a1);
}

original_code:
void server_async_mode (context_t * context)
{
  context->srv_client_thread = tam_client_thread;
  init_sem (&context->continue_execute, 1, &context->continue_execute_sem, &context->continue_execute_mutex);
  server (context);
}

canonical_original_code:
void server_async_mode(struct context_s *context)
{
  context->srv_client_thread = tam_client_thread;
  init_sem (&context->continue_execute, 1, &context->continue_execute_sem, &context->continue_execute_mutex);
  server (context);
}

user_defined_types: struct brute_result_s { union pthread_mutex_t found_mutex; char password[-1]; int found; }

user_defined_types: struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; }


decompiled_code:
void *__fastcall cam_checker_thread(void *a1)
{
char *v1; // rbp
char v3[112]; // [rsp+10h] [rbp-20218h] BYREF
int v4; // [rsp+80h] [rbp-201A8h]
unsigned int v5; // [rsp+84h] [rbp-201A4h]
unsigned int v6; // [rsp+88h] [rbp-201A0h]
char *v7; // [rsp+90h] [rbp-20198h]
char v8[40]; // [rsp+A0h] [rbp-20188h] BYREF
char dest[104]; // [rsp+C8h] [rbp-20160h] BYREF
int v10; // [rsp+130h] [rbp-200F8h]
unsigned int v11; // [rsp+138h] [rbp-200F0h]
unsigned int v12; // [rsp+13Ch] [rbp-200ECh]
int v13; // [rsp+140h] [rbp-200E8h]
char s[131288]; // [rsp+150h] [rbp-200D8h] BYREF

v1 = (char *)a1 + 200;
memset(s, 0, 0x200A0uLL);
puts("checker");
inc_sem((char *)a1 + 1536, (char *)a1 + 1584, (char *)a1 + 1544);
while ( 1 )
{
queue_pop(v1, v3);
if ( v4 )
break;
v7 = s;
v11 = v5;
v12 = v6;
v13 = 0;
printf("C. check task: [%d.%d] %s\n", v5, v6, v3);
*((_DWORD *)a1 + 42) = 0;
if ( (unsigned int)brute_block_iterative(v3, &check_password, a1) )
{
v10 = 1;
strcpy(dest, (const char *)a1 + 64);
}
else
{
v10 = 0;
}
result_queue_push((char *)a1 + 1744, v8);
}
queue_push(v1, v3);
dec_sem((char *)a1 + 1536, (char *)a1 + 1584, (char *)a1 + 1544);
puts("Checker ended.");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
char *v1; // rbp
char v3[112]; // [rsp+10h] [rbp-20218h] BYREF
int v4; // [rsp+80h] [rbp-201A8h]
unsigned int v5; // [rsp+84h] [rbp-201A4h]
unsigned int v6; // [rsp+88h] [rbp-201A0h]
char *v7; // [rsp+90h] [rbp-20198h]
char v8[40]; // [rsp+A0h] [rbp-20188h] BYREF
char dest[104]; // [rsp+C8h] [rbp-20160h] BYREF
int v10; // [rsp+130h] [rbp-200F8h]
unsigned int v11; // [rsp+138h] [rbp-200F0h]
unsigned int v12; // [rsp+13Ch] [rbp-200ECh]
int v13; // [rsp+140h] [rbp-200E8h]
char s[131288]; // [rsp+150h] [rbp-200D8h] BYREF

v1 = (char *)a1 + 200;
memset(s, 0, 0x200A0uLL);
puts("checker");
inc_sem((char *)a1 + 1536, (char *)a1 + 1584, (char *)a1 + 1544);
while ( 1 )
{
queue_pop(v1, v3);
if ( v4 )
break;
v7 = s;
v11 = v5;
v12 = v6;
v13 = 0;
printf("C. check task: [%d.%d] %s\n", v5, v6, v3);
*((_DWORD *)a1 + 42) = 0;
if ( (unsigned int)brute_block_iterative(v3, &check_password, a1) )
{
v10 = 1;
strcpy(dest, (const char *)a1 + 64);
}
else
{
v10 = 0;
}
result_queue_push((char *)a1 + 1744, v8);
}
queue_push(v1, v3);
dec_sem((char *)a1 + 1536, (char *)a1 + 1584, (char *)a1 + 1544);
puts("Checker ended.");
return 0LL;
}

original_code:
void * cam_checker_thread (void * args)
{
  context_t * context = args;
  struct crypt_data cd = { .initialized = 0 };
  task_t task;
  result_t result;
  printf ("checker\n");
  inc_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  for (;;)
    {
      queue_pop (&context->queue, &task);
      if (task.final)
 {
   queue_push (&context->queue, &task);
   break;
 }
      task.cd = &cd;
      result.id = task.id;
      result.idx = task.idx;
      result.final = 0;
      printf ("C. check task: [%d.%d] %s\n", task.id, task.idx, task.password);
      context->result.found = 0;
      if (brute_block_iterative (&task, check_password, context))
 {
   result.result.found = !0;
   strcpy (result.result.password, context->result.password);
 }
      else
 {
   result.result.found = 0;
 }
      result_queue_push (&context->result_queue, &result);
    }
  dec_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  printf ("Checker ended.\n");
  return ((void *)0);
}

canonical_original_code:
void *cam_checker_thread(void *args)
{
  struct context_s *context = args;
  struct crypt_data cd = { .initialized = 0 };
  struct task_s task;
  struct result_s result;
  printf ("checker\n");
  inc_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  for (;;)
    {
      queue_pop (&context->queue, &task);
      if (task.final)
 {
   queue_push (&context->queue, &task);
   break;
 }
      task.cd = &cd;
      result.id = task.id;
      result.idx = task.idx;
      result.final = 0;
      printf ("C. check task: [%d.%d] %s\n", task.id, task.idx, task.password);
      context->result.found = 0;
      if (brute_block_iterative (&task, check_password, context))
 {
   result.result.found = !0;
   strcpy (result.result.password, context->result.password);
 }
      else
 {
   result.result.found = 0;
 }
      result_queue_push (&context->result_queue, &result);
    }
  dec_sem (&context->threads, &context->threads_sem, &context->threads_mutex);
  printf ("Checker ended.\n");
  return ((void *)0);
}

variable_types: struct crypt_data { char keysched[-1]; char sb0[32768]; char sb1[32768]; char sb2[32768]; char sb3[32768]; char crypt_3_buf[14]; char current_salt[2]; long current_saltbits; int direction; }

variable_types: struct result_s { struct brute_result_s { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } found_mutex; char password[-1]; int found; } result; int id; int idx; int final; }

user_defined_types: struct queue_s { struct task_s queue[-1]; union sem_t full; union sem_t empty; int head; int tail; union pthread_mutex_t head_mutex; union pthread_mutex_t tail_mutex; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }