decompiled_code:
__int64 sexy_execute()
{
return (*(__int64 (**)(void))(psxCpu + 16LL))();
}

original_code:
void sexy_execute(void)
{
 psxCpu->Execute();
}

canonical_original_code:
void sexy_execute()
{
 psxCpu->Execute();
}


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

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

original_code:
static inline u16 BFLIP16(u16 x)
{
 return x;
}

canonical_original_code:
static inline unsigned short BFLIP16(unsigned short x)
{
 return x;
}

variable_types:
x
unsigned short

return_type: unsigned short


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

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

original_code:
static inline u32 BFLIP32(u32 x)
{
 return x;
}

canonical_original_code:
static inline unsigned int BFLIP32(unsigned int x)
{
 return x;
}

variable_types:
x
unsigned int

return_type: unsigned int


LoadPSXMem

decompiled_code:
void __fastcall LoadPSXMem(unsigned int a1, int a2, char *a3)
{
int i; // ebp
int v6; // edx
char *v7; // rdi
unsigned int v8; // er14
__int64 v9; // rdx

if ( a2 > 0 )
{
for ( i = a2; i > 0; i -= 0x10000 )
{
while ( 1 )
{
v7 = *(char **)(psxMemLUT + 8LL * HIWORD(a1));
if ( !(_WORD)a1 )
break;
v8 = 0x10000 - (unsigned __int16)a1;
if ( v8 > i )
v8 = i;
v9 = v8;
if ( v7 )
{
memcpy(&v7[(unsigned __int16)a1], a3, v8);
v9 = v8;
}
i -= v8;
a1 += v8;
a3 += v9;
if ( i <= 0 )
return;
}
if ( v7 )
{
v6 = 0x10000;
if ( i <= 0x10000 )
v6 = i;
memcpy(v7, a3, v6);
}
a3 += 0x10000;
a1 += 0x10000;
}
}
}

original_code:
void LoadPSXMem(u32 address, s32 length, char *data)
{
 while(length>0)
 {
  if(address&65535)
  {
   u32 tmplen;
   tmplen=((65536-(address&65535))>length)?length:65536-(address&65535);
   if(psxMemLUT[address>>16])
    memcpy((char *)(psxMemLUT[address>>16]+(address&65535)),data,tmplen);
   address+=tmplen;
   data+=tmplen;
   length-=tmplen;
   continue;
  }
  if(psxMemLUT[address>>16])
  {
   memcpy((char *)(psxMemLUT[address>>16]),data,(length<65536)?length:65536);
  }
  data+=65536;
  address+=65536;
  length-=65536;
 }
}

canonical_original_code:
void LoadPSXMem(unsigned int address, int length, char *data)
{
 while(length>0)
 {
  if(address&65535)
  {
   unsigned int tmplen;
   tmplen=((65536-(address&65535))>length)?length:65536-(address&65535);
   if(psxMemLUT[address>>16])
    memcpy((char *)(psxMemLUT[address>>16]+(address&65535)),data,tmplen);
   address+=tmplen;
   data+=tmplen;
   length-=tmplen;
   continue;
  }
  if(psxMemLUT[address>>16])
  {
   memcpy((char *)(psxMemLUT[address>>16]),data,(length<65536)?length:65536);
  }
  data+=65536;
  address+=65536;
  length-=65536;
 }
}

variable_types:
address
unsigned int

variable_types: length int

variable_types:
data
char *

variable_types:
tmplen
unsigned int

return_type: void


psxMemInit

decompiled_code:
__int64 psxMemInit()
{
char *v0; // rbx
char *v1; // rbp
void *v2; // r13
void *v3; // r12
char *v4; // r8
__int64 i; // rdx
char *v6; // rdi
char *v7; // rsi
char *v8; // rax
char *v9; // rbx
__int64 v10; // rdx
__int64 result; // rax

writeok = 1;
v0 = (char *)calloc(0x80000uLL, 1uLL);
psxMemLUT = v0;
v1 = (char *)malloc(0x200000uLL);
psxM = v1;
v2 = malloc(0x10000uLL);
psxP = v2;
v3 = malloc(0x10000uLL);
psxH = v3;
v4 = (char *)malloc(0x80000uLL);
psxR = v4;
if ( v3 == 0LL || v1 == 0LL || v2 == 0LL || !v4 )
{
printf("Error allocating memory");
result = 0xFFFFFFFFLL;
}
else
{
for ( i = 0LL; i != 128; ++i )
*(_QWORD *)&v0[8 * i] = &v1[((_DWORD)i << 16) & 0x1F0000];
qmemcpy(v0 + 0x40000, v0, 0x400uLL);
v6 = v0 + 327680;
v7 = v0;
v8 = v4;
v9 = v0 + 392704;
qmemcpy(v6, v7, 0x400uLL);
*((_QWORD *)v9 - 41152) = (unsigned int)v2;
*((_QWORD *)v9 - 41024) = (unsigned int)v3;
do
{
v10 = (unsigned int)v8;
v8 += 0x10000;
v9 += 8;
*((_QWORD *)v9 - 1) = v10;
}
while ( v4 + 0x80000 != v8 );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
char *v0; // rbx
char *v1; // rbp
void *v2; // r13
void *v3; // r12
char *v4; // r8
__int64 i; // rdx
char *v6; // rdi
char *v7; // rsi
char *v8; // rax
char *v9; // rbx
__int64 v10; // rdx
__int64 result; // rax

writeok = 1;
v0 = (char *)calloc(0x80000uLL, 1uLL);
psxMemLUT = v0;
v1 = (char *)malloc(0x200000uLL);
psxM = v1;
v2 = malloc(0x10000uLL);
psxP = v2;
v3 = malloc(0x10000uLL);
psxH = v3;
v4 = (char *)malloc(0x80000uLL);
psxR = v4;
if ( v3 == 0LL || v1 == 0LL || v2 == 0LL || !v4 )
{
printf("Error allocating memory");
result = 0xFFFFFFFFLL;
}
else
{
for ( i = 0LL; i != 128; ++i )
*(_QWORD *)&v0[8 * i] = &v1[((_DWORD)i << 16) & 0x1F0000];
qmemcpy(v0 + 0x40000, v0, 0x400uLL);
v6 = v0 + 327680;
v7 = v0;
v8 = v4;
v9 = v0 + 392704;
qmemcpy(v6, v7, 0x400uLL);
*((_QWORD *)v9 - 41152) = (unsigned int)v2;
*((_QWORD *)v9 - 41024) = (unsigned int)v3;
do
{
v10 = (unsigned int)v8;
v8 += 0x10000;
v9 += 8;
*((_QWORD *)v9 - 1) = v10;
}
while ( v4 + 0x80000 != v8 );
result = 0LL;
}
return result;
}

original_code:
int psxMemInit() {
 int i;
 writeok=1;
 psxMemLUT = malloc(0x10000 * sizeof *psxMemLUT);
 memset(psxMemLUT, 0, 0x10000 * sizeof *psxMemLUT);
 psxM = (char*)malloc(0x00200000);
 psxP = (char*)malloc(0x00010000);
 psxH = (char*)malloc(0x00010000);
 psxR = (char*)malloc(0x00080000);
 if (psxMemLUT == ((void *)0) || psxM == ((void *)0) || psxP == ((void *)0) || psxH == ((void *)0) || psxR == ((void *)0)) {
  printf("Error allocating memory"); return -1;
 }
 for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = &psxM[(i & 0x1f) << 16];
 memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
 memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
 for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f00] = (u32)&psxP[i << 16];
 for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f80] = (u32)&psxH[i << 16];
 for (i=0; i<0x08; i++) psxMemLUT[i + 0xbfc0] = (u32)&psxR[i << 16];
 return 0;
}

canonical_original_code:
int psxMemInit() {
 int i;
 writeok=1;
 psxMemLUT = malloc(0x10000 * sizeof *psxMemLUT);
 memset(psxMemLUT, 0, 0x10000 * sizeof *psxMemLUT);
 psxM = (char *)malloc(0x00200000);
 psxP = (char *)malloc(0x00010000);
 psxH = (char *)malloc(0x00010000);
 psxR = (char *)malloc(0x00080000);
 if (psxMemLUT == ((void *)0) || psxM == ((void *)0) || psxP == ((void *)0) || psxH == ((void *)0) || psxR == ((void *)0)) {
  printf("Error allocating memory"); return -1;
 }
 for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = &psxM[(i & 0x1f) << 16];
 memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
 memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
 for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f00] = (u32)&psxP[i << 16];
 for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f80] = (u32)&psxH[i << 16];
 for (i=0; i<0x08; i++) psxMemLUT[i + 0xbfc0] = (u32)&psxR[i << 16];
 return 0;
}

variable_types: i int

return_type: int


psxMemReset

decompiled_code:
void *psxMemReset()
{
memset(psxM, 0, 0x200000uLL);
return memset(psxP, 0, 0x10000uLL);
}

canonical_decompiled_code:
void *func4()
{
memset(psxM, 0, 0x200000uLL);
return memset(psxP, 0, 0x10000uLL);
}

original_code:
void psxMemReset() {
 memset(psxM, 0, 0x00200000);
 memset(psxP, 0, 0x00010000);
}


psxMemShutdown

decompiled_code:
void psxMemShutdown()
{
free(psxM);
free(psxP);
free(psxH);
free(psxR);
free(psxMemLUT);
}

canonical_decompiled_code:
void func5()
{
free(psxM);
free(psxP);
free(psxH);
free(psxR);
free(psxMemLUT);
}


decompiled_code:
__int64 __fastcall psxMemRead8(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 result; // rax

v1 = HIWORD(a1);
if ( (_DWORD)v1 == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead8();
else
result = *(unsigned __int8 *)(psxH + (unsigned __int16)a1);
}
else
{
v2 = *(_QWORD *)(psxMemLUT + 8 * v1);
result = 0LL;
if ( v2 )
result = *(unsigned __int8 *)(v2 + (unsigned __int16)a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 result; // rax

v1 = HIWORD(a1);
if ( (_DWORD)v1 == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead8();
else
result = *(unsigned __int8 *)(psxH + (unsigned __int16)a1);
}
else
{
v2 = *(_QWORD *)(psxMemLUT + 8 * v1);
result = 0LL;
if ( v2 )
result = *(unsigned __int8 *)(v2 + (unsigned __int16)a1);
}
return result;
}

original_code:
u8 psxMemRead8(u32 mem) {
 char *p;
 u32 t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   return (*(u8*) &psxH[(mem) & 0xffff]);
  else
   return psxHwRead8(mem);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   return *(u8 *)(p + (mem & 0xffff));
  } else {
   return 0;
  }
 }
}

canonical_original_code:
unsigned char psxMemRead8(unsigned int mem) {
 char *p;
 unsigned int t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   return (*(unsigned char *) &psxH[(mem) & 0xffff]);
  else
   return psxHwRead8(mem);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   return *(unsigned char *)(p + (mem & 0xffff));
  } else {
   return 0;
  }
 }
}

variable_types:
mem
unsigned int

variable_types:
p
char *

variable_types:
t
unsigned int

return_type: unsigned char


decompiled_code:
__int64 __fastcall psxMemRead16(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = HIWORD(a1);
if ( (_DWORD)v1 == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead16();
else
result = BFLIP16(*(unsigned __int16 *)(psxH + (unsigned __int16)a1));
}
else
{
v2 = *(_QWORD *)(psxMemLUT + 8 * v1);
if ( v2 )
result = BFLIP16(*(unsigned __int16 *)(v2 + (unsigned __int16)a1));
else
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = HIWORD(a1);
if ( (_DWORD)v1 == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead16();
else
result = func0(*(unsigned __int16 *)(psxH + (unsigned __int16)a1));
}
else
{
v2 = *(_QWORD *)(psxMemLUT + 8 * v1);
if ( v2 )
result = func0(*(unsigned __int16 *)(v2 + (unsigned __int16)a1));
else
result = 0LL;
}
return result;
}

original_code:
u16 psxMemRead16(u32 mem) {
 char *p;
 u32 t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   return BFLIP16((*(u16*)&psxH[(mem) & 0xffff]));
  else
   return psxHwRead16(mem);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   return BFLIP16(*(u16 *)(p + (mem & 0xffff)));
  } else {
   return 0;
  }
 }
}

canonical_original_code:
unsigned short psxMemRead16(unsigned int mem) {
 char *p;
 unsigned int t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   return BFLIP16((*(unsigned short *)&psxH[(mem) & 0xffff]));
  else
   return psxHwRead16(mem);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   return BFLIP16(*(unsigned short *)(p + (mem & 0xffff)));
  } else {
   return 0;
  }
 }
}


decompiled_code:
__int64 __fastcall psxMemRead32(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = HIWORD(a1);
if ( (_DWORD)v1 == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead32();
else
result = BFLIP32(*(_DWORD *)(psxH + (unsigned __int16)a1));
}
else
{
v2 = *(_QWORD *)(psxMemLUT + 8 * v1);
if ( v2 )
result = BFLIP32(*(_DWORD *)(v2 + (unsigned __int16)a1));
else
result = 0LL;
}
return result;
}

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

v1 = HIWORD(a1);
if ( (_DWORD)v1 == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead32();
else
result = func1(*(_DWORD *)(psxH + (unsigned __int16)a1));
}
else
{
v2 = *(_QWORD *)(psxMemLUT + 8 * v1);
if ( v2 )
result = func1(*(_DWORD *)(v2 + (unsigned __int16)a1));
else
result = 0LL;
}
return result;
}

original_code:
u32 psxMemRead32(u32 mem) {
 char *p;
 u32 t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   return BFLIP32((*(u32*)&psxH[(mem) & 0xffff]));
  else
   return psxHwRead32(mem);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   return BFLIP32(*(u32 *)(p + (mem & 0xffff)));
  } else {
   return 0;
  }
 }
}

canonical_original_code:
unsigned int psxMemRead32(unsigned int mem) {
 char *p;
 unsigned int t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   return BFLIP32((*(unsigned int *)&psxH[(mem) & 0xffff]));
  else
   return psxHwRead32(mem);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   return BFLIP32(*(unsigned int *)(p + (mem & 0xffff)));
  } else {
   return 0;
  }
 }
}


decompiled_code:
__int64 __fastcall psxMemWrite8(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = WORD1(a1);
if ( (_DWORD)v2 == 8064 )
{
if ( (unsigned int)a1 > 0x1F800FFF )
{
result = psxHwWrite8(a1, a2);
}
else
{
result = psxH;
*(_BYTE *)(psxH + (unsigned __int16)a1) = a2;
}
}
else
{
result = *(_QWORD *)(psxMemLUT + 8 * v2);
if ( result )
*(_BYTE *)(result + (unsigned __int16)a1) = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = WORD1(a1);
if ( (_DWORD)v2 == 8064 )
{
if ( (unsigned int)a1 > 0x1F800FFF )
{
result = psxHwWrite8(a1, a2);
}
else
{
result = psxH;
*(_BYTE *)(psxH + (unsigned __int16)a1) = a2;
}
}
else
{
result = *(_QWORD *)(psxMemLUT + 8 * v2);
if ( result )
*(_BYTE *)(result + (unsigned __int16)a1) = a2;
}
return result;
}

original_code:
void psxMemWrite8(u32 mem, u8 value) {
 char *p;
 u32 t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   (*(u8*) &psxH[(mem) & 0xffff]) = value;
  else
   psxHwWrite8(mem, value);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   *(u8 *)(p + (mem & 0xffff)) = value;
  }
 }
}

canonical_original_code:
void psxMemWrite8(unsigned int mem, unsigned char value) {
 char *p;
 unsigned int t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   (*(unsigned char *) &psxH[(mem) & 0xffff]) = value;
  else
   psxHwWrite8(mem, value);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   *(unsigned char *)(p + (mem & 0xffff)) = value;
  }
 }
}

variable_types:
value
unsigned char


decompiled_code:
__int64 __fastcall psxMemWrite16(__int64 a1, unsigned __int16 a2)
{
__int64 v2; // rax
__int64 result; // rax
_WORD *v4; // rdx
_WORD *v5; // rdx

v2 = WORD1(a1);
if ( (_DWORD)v2 == 8064 )
{
if ( (unsigned int)a1 > 0x1F800FFF )
{
result = psxHwWrite16(a1, a2);
}
else
{
result = BFLIP16(a2);
*v5 = result;
}
}
else
{
result = *(_QWORD *)(psxMemLUT + 8 * v2);
if ( result )
{
result = BFLIP16(a2);
*v4 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int16 a2)
{
__int64 v2; // rax
__int64 result; // rax
_WORD *v4; // rdx
_WORD *v5; // rdx

v2 = WORD1(a1);
if ( (_DWORD)v2 == 8064 )
{
if ( (unsigned int)a1 > 0x1F800FFF )
{
result = psxHwWrite16(a1, a2);
}
else
{
result = func0(a2);
*v5 = result;
}
}
else
{
result = *(_QWORD *)(psxMemLUT + 8 * v2);
if ( result )
{
result = func0(a2);
*v4 = result;
}
}
return result;
}

original_code:
void psxMemWrite16(u32 mem, u16 value) {
 char *p;
 u32 t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   (*(u16*)&psxH[(mem) & 0xffff]) = BFLIP16(value);
  else
   psxHwWrite16(mem, value);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   *(u16 *)(p + (mem & 0xffff)) = BFLIP16(value);
  }
 }
}

canonical_original_code:
void psxMemWrite16(unsigned int mem, unsigned short value) {
 char *p;
 unsigned int t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   (*(unsigned short *)&psxH[(mem) & 0xffff]) = BFLIP16(value);
  else
   psxHwWrite16(mem, value);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   *(unsigned short *)(p + (mem & 0xffff)) = BFLIP16(value);
  }
 }
}

variable_types:
value
unsigned short


decompiled_code:
__int64 __fastcall psxMemWrite32(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
_QWORD *v3; // r8
__int64 result; // rax
_DWORD *v5; // rdx
_DWORD *v6; // rdx
void *v7; // rdi
_QWORD *v8; // rdx
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // rcx
char *v12; // rdi
__int64 v13; // rdx

v2 = HIWORD(a1);
if ( (_DWORD)v2 == 8064 )
{
if ( a1 > 0x1F800FFF )
{
result = psxHwWrite32();
}
else
{
result = BFLIP32(a2);
*v6 = result;
}
}
else
{
v3 = psxMemLUT;
result = psxMemLUT[v2];
if ( result )
{
result = BFLIP32(a2);
*v5 = result;
return result;
}
if ( a1 == -130768 )
{
if ( a2 == 2052 )
{
LABEL_11:
result = (unsigned int)writeok;
if ( writeok )
{
writeok = 0;
result = 0LL;
v7 = (void *)((unsigned __int64)(psxMemLUT + 1) & 0xFFFFFFFFFFFFFFF8LL);
*psxMemLUT = 0LL;
v3[127] = 0LL;
memset(v7, 0, 8LL * ((unsigned int)((_DWORD)v3 - (_DWORD)v7 + 1024) >> 3));
v8 = psxMemLUT;
psxMemLUT[0x8000] = 0LL;
v8[32895] = 0LL;
memset(
(void *)((unsigned __int64)(v8 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v8 - (((_DWORD)v8 + 262152) & 0xFFFFFFF8) + 263168) >> 3));
v8[40960] = 0LL;
v8[41087] = 0LL;
memset(
(void *)((unsigned __int64)(v8 + 40961) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v8 - (((_DWORD)v8 + 327688) & 0xFFFFFFF8) + 328704) >> 3));
}
return result;
}
if ( a2 != 125320 )
{
if ( a2 != 2048 )
return result;
goto LABEL_11;
}
if ( writeok != 1 )
{
v9 = 0LL;
writeok = 1;
v10 = psxM;
do
{
v3[v9] = v10 + (((_DWORD)v9 << 16) & 0x1F0000);
++v9;
}
while ( v9 != 128 );
v11 = v3[127];
v3[0x8000] = *v3;
v3[32895] = v11;
qmemcpy(
(void *)((unsigned __int64)(v3 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(((unsigned __int64)(v3 + 32769) & 0xFFFFFFFFFFFFFFF8LL) - 0x40000),
8LL * (((_DWORD)v3 + 0x40000 - (((_DWORD)v3 + 262152) & 0xFFFFFFF8) + 1024) >> 3));
v12 = (char *)((unsigned __int64)(v3 + 40961) & 0xFFFFFFFFFFFFFFF8LL);
v13 = v3[127];
result = (unsigned int)((_DWORD)v3 + 327680 - (_DWORD)v12 + 1024) >> 3;
v3[40960] = *v3;
v3[41087] = v13;
qmemcpy(v12, v12 - 327680, 8LL * (unsigned int)result);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
_QWORD *v3; // r8
__int64 result; // rax
_DWORD *v5; // rdx
_DWORD *v6; // rdx
void *v7; // rdi
_QWORD *v8; // rdx
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // rcx
char *v12; // rdi
__int64 v13; // rdx

v2 = HIWORD(a1);
if ( (_DWORD)v2 == 8064 )
{
if ( a1 > 0x1F800FFF )
{
result = psxHwWrite32();
}
else
{
result = func1(a2);
*v6 = result;
}
}
else
{
v3 = psxMemLUT;
result = psxMemLUT[v2];
if ( result )
{
result = func1(a2);
*v5 = result;
return result;
}
if ( a1 == -130768 )
{
if ( a2 == 2052 )
{
LABEL_11:
result = (unsigned int)writeok;
if ( writeok )
{
writeok = 0;
result = 0LL;
v7 = (void *)((unsigned __int64)(psxMemLUT + 1) & 0xFFFFFFFFFFFFFFF8LL);
*psxMemLUT = 0LL;
v3[127] = 0LL;
memset(v7, 0, 8LL * ((unsigned int)((_DWORD)v3 - (_DWORD)v7 + 1024) >> 3));
v8 = psxMemLUT;
psxMemLUT[0x8000] = 0LL;
v8[32895] = 0LL;
memset(
(void *)((unsigned __int64)(v8 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v8 - (((_DWORD)v8 + 262152) & 0xFFFFFFF8) + 263168) >> 3));
v8[40960] = 0LL;
v8[41087] = 0LL;
memset(
(void *)((unsigned __int64)(v8 + 40961) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v8 - (((_DWORD)v8 + 327688) & 0xFFFFFFF8) + 328704) >> 3));
}
return result;
}
if ( a2 != 125320 )
{
if ( a2 != 2048 )
return result;
goto LABEL_11;
}
if ( writeok != 1 )
{
v9 = 0LL;
writeok = 1;
v10 = psxM;
do
{
v3[v9] = v10 + (((_DWORD)v9 << 16) & 0x1F0000);
++v9;
}
while ( v9 != 128 );
v11 = v3[127];
v3[0x8000] = *v3;
v3[32895] = v11;
qmemcpy(
(void *)((unsigned __int64)(v3 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(((unsigned __int64)(v3 + 32769) & 0xFFFFFFFFFFFFFFF8LL) - 0x40000),
8LL * (((_DWORD)v3 + 0x40000 - (((_DWORD)v3 + 262152) & 0xFFFFFFF8) + 1024) >> 3));
v12 = (char *)((unsigned __int64)(v3 + 40961) & 0xFFFFFFFFFFFFFFF8LL);
v13 = v3[127];
result = (unsigned int)((_DWORD)v3 + 327680 - (_DWORD)v12 + 1024) >> 3;
v3[40960] = *v3;
v3[41087] = v13;
qmemcpy(v12, v12 - 327680, 8LL * (unsigned int)result);
}
}
}
return result;
}

original_code:
void psxMemWrite32(u32 mem, u32 value) {
 char *p;
 u32 t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   (*(u32*)&psxH[(mem) & 0xffff]) = BFLIP32(value);
  else
   psxHwWrite32(mem, value);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   *(u32 *)(p + (mem & 0xffff)) = BFLIP32(value);
  } else {
   if (mem != 0xfffe0130) {
   } else {
    int i;
    switch (value) {
     case 0x800: case 0x804:
      if (writeok == 0) break;
      writeok = 0;
      memset(psxMemLUT + 0x0000, 0, 0x80 * sizeof *psxMemLUT);
      memset(psxMemLUT + 0x8000, 0, 0x80 * sizeof *psxMemLUT);
      memset(psxMemLUT + 0xa000, 0, 0x80 * sizeof *psxMemLUT);
      break;
     case 0x1e988:
      if (writeok == 1) break;
      writeok = 1;
      for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = &psxM[(i & 0x1f) << 16];
      memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
      memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
      break;
     default:
      break;
    }
   }
  }
 }
}

canonical_original_code:
void psxMemWrite32(unsigned int mem, unsigned int value) {
 char *p;
 unsigned int t;
 t = mem >> 16;
 if (t == 0x1f80) {
  if (mem < 0x1f801000)
   (*(unsigned int *)&psxH[(mem) & 0xffff]) = BFLIP32(value);
  else
   psxHwWrite32(mem, value);
 } else {
  p = (char *)(psxMemLUT[t]);
  if (p != ((void *)0)) {
   *(unsigned int *)(p + (mem & 0xffff)) = BFLIP32(value);
  } else {
   if (mem != 0xfffe0130) {
   } else {
    int i;
    switch (value) {
     case 0x800: case 0x804:
      if (writeok == 0) break;
      writeok = 0;
      memset(psxMemLUT + 0x0000, 0, 0x80 * sizeof *psxMemLUT);
      memset(psxMemLUT + 0x8000, 0, 0x80 * sizeof *psxMemLUT);
      memset(psxMemLUT + 0xa000, 0, 0x80 * sizeof *psxMemLUT);
      break;
     case 0x1e988:
      if (writeok == 1) break;
      writeok = 1;
      for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = &psxM[(i & 0x1f) << 16];
      memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
      memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * sizeof *psxMemLUT);
      break;
     default:
      break;
    }
   }
  }
 }
}

variable_types:
value
unsigned int


SetupSound

decompiled_code:
int SetupSound()
{
int v0; // eax
int v1; // ebp
int result; // eax
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 44100;
v5[0] = 1;
v0 = open("/dev/dsp", 1, 0LL);
oss_audio_fd = v0;
if ( v0 == -1 )
return puts("Sound device not available!");
v1 = v0;
if ( ioctl(v0, 0x5000uLL, 0LL) == -1 )
return puts("Sound reset failed");
v3 = 16;
if ( ioctl(v1, 0xC0045005uLL, &v3) == -1 || v3 != 16 )
return puts("Sound format not supported!");
if ( ioctl(v1, 0xC0045003uLL, v5) == -1 )
return puts("Stereo mode not supported!");
result = ioctl(v1, 0xC0045002uLL, &v4);
if ( result == -1 || v4 != 44100 )
result = puts("Sound frequency not supported");
return result;
}

canonical_decompiled_code:
int func0()
{
int v0; // eax
int v1; // ebp
int result; // eax
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 44100;
v5[0] = 1;
v0 = open("/dev/dsp", 1, 0LL);
oss_audio_fd = v0;
if ( v0 == -1 )
return puts("Sound device not available!");
v1 = v0;
if ( ioctl(v0, 0x5000uLL, 0LL) == -1 )
return puts("Sound reset failed");
v3 = 16;
if ( ioctl(v1, 0xC0045005uLL, &v3) == -1 || v3 != 16 )
return puts("Sound format not supported!");
if ( ioctl(v1, 0xC0045003uLL, v5) == -1 )
return puts("Stereo mode not supported!");
result = ioctl(v1, 0xC0045002uLL, &v4);
if ( result == -1 || v4 != 44100 )
result = puts("Sound frequency not supported");
return result;
}

original_code:
void SetupSound(void)
{
 int pspeed=44100;
 int pstereo;
 int format;
 int fragsize = 0;
 int myfrag;
 int oss_speed, oss_stereo;
 pstereo=1;
 oss_speed = pspeed;
 oss_stereo = pstereo;
 if((oss_audio_fd=open("/dev/dsp",01,0))==-1)
  {
   printf("Sound device not available!\n");
   return;
  }
 if(ioctl(oss_audio_fd,(((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((0)) << 0) | ((0) << ((0 +8)+8))),0)==-1)
  {
   printf("Sound reset failed\n");
   return;
  }
 format = 0x00000010;
 if(ioctl(oss_audio_fd,(((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))),&format) == -1)
  {
   printf("Sound format not supported!\n");
   return;
  }
 if(format!=0x00000010)
  {
   printf("Sound format not supported!\n");
   return;
  }
 if(ioctl(oss_audio_fd,(((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((3)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))),&oss_stereo)==-1)
  {
   printf("Stereo mode not supported!\n");
   return;
  }
 if(ioctl(oss_audio_fd,(((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))),&oss_speed)==-1)
  {
   printf("Sound frequency not supported\n");
   return;
  }
 if(oss_speed!=pspeed)
  {
   printf("Sound frequency not supported\n");
   return;
  }
}

canonical_original_code:
void SetupSound()
{
 int pspeed = 44100;
 int pstereo;
 int format;
 int fragsize = 0;
 int myfrag;
 int oss_speed; int oss_stereo;
 pstereo=1;
 oss_speed = pspeed;
 oss_stereo = pstereo;
 if((oss_audio_fd=open("/dev/dsp",01,0))==-1)
  {
   printf("Sound device not available!\n");
   return;
  }
 if(ioctl(oss_audio_fd,(((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((0)) << 0) | ((0) << ((0 +8)+8))),0)==-1)
  {
   printf("Sound reset failed\n");
   return;
  }
 format = 0x00000010;
 if(ioctl(oss_audio_fd,(((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))),&format) == -1)
  {
   printf("Sound format not supported!\n");
   return;
  }
 if(format!=0x00000010)
  {
   printf("Sound format not supported!\n");
   return;
  }
 if(ioctl(oss_audio_fd,(((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((3)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))),&oss_stereo)==-1)
  {
   printf("Stereo mode not supported!\n");
   return;
  }
 if(ioctl(oss_audio_fd,(((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))),&oss_speed)==-1)
  {
   printf("Sound frequency not supported\n");
   return;
  }
 if(oss_speed!=pspeed)
  {
   printf("Sound frequency not supported\n");
   return;
  }
}

variable_types: pspeed int

variable_types: pstereo int

variable_types: format int

variable_types: fragsize int

variable_types: myfrag int


RemoveSound

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

if ( oss_audio_fd != -1 )
{
result = close(oss_audio_fd);
oss_audio_fd = -1;
}
return result;
}

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

if ( oss_audio_fd != -1 )
{
result = close(oss_audio_fd);
oss_audio_fd = -1;
}
return result;
}

original_code:
void RemoveSound(void)
{
 if(oss_audio_fd != -1 )
  {
   close(oss_audio_fd);
   oss_audio_fd = -1;
  }
}

canonical_original_code:
void RemoveSound()
{
 if(oss_audio_fd != -1 )
  {
   close(oss_audio_fd);
   oss_audio_fd = -1;
  }
}


decompiled_code:
void __fastcall sexyd_update(void *buf, size_t n)
{
int v2; // eax
int v3; // [rsp+0h] [rbp-10Ch] BYREF
char s[264]; // [rsp+4h] [rbp-108h] BYREF

if ( oss_audio_fd != -1 )
{
write(oss_audio_fd, buf, n);
v2 = fileno(stdin);
if ( !ioctl(v2, 0x541BuLL, &v3) )
{
if ( v3 )
{
fgets(s, 256, stdin);
if ( s[0] == 113 )
sexy_stop();
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(void *buf, size_t n)
{
int v2; // eax
int v3; // [rsp+0h] [rbp-10Ch] BYREF
char s[264]; // [rsp+4h] [rbp-108h] BYREF

if ( oss_audio_fd != -1 )
{
write(oss_audio_fd, buf, n);
v2 = fileno(stdin);
if ( !ioctl(v2, 0x541BuLL, &v3) )
{
if ( v3 )
{
fgets(s, 256, stdin);
if ( s[0] == 113 )
sexy_stop();
}
}
}
}

original_code:
void sexyd_update(unsigned char* pSound,long lBytes)
{
 int check;
 if(oss_audio_fd == -1) return;
 write(oss_audio_fd,pSound,lBytes);
 if(!ioctl(fileno(stdin),0x541B,&check))
  if(check)
  {
   char buf[256];
   fgets(buf,256,stdin);
   if(buf[0]=='q') sexy_stop();
  }
}

canonical_original_code:
void sexyd_update(unsigned char *pSound, long lBytes)
{
 int check;
 if(oss_audio_fd == -1) return;
 write(oss_audio_fd,pSound,lBytes);
 if(!ioctl(fileno(stdin),0x541B,&check))
  if(check)
  {
   char buf[256];
   fgets(buf,256,stdin);
   if(buf[0]=='q') sexy_stop();
  }
}

variable_types:
pSound
unsigned char *

variable_types: lBytes long

variable_types: check int

variable_types:
buf
char [256]


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

if ( a3 == 16777728 )
return SPUreadDMAMem(a1, 2 * HIWORD(a2) * (unsigned __int16)a2);
if ( a3 == 16777729 )
result = SPUwriteDMAMem(a1, 2 * HIWORD(a2) * (unsigned __int16)a2);
return result;
}

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

if ( a3 == 16777728 )
return SPUreadDMAMem(a1, 2 * HIWORD(a2) * (unsigned __int16)a2);
if ( a3 == 16777729 )
result = SPUwriteDMAMem(a1, 2 * HIWORD(a2) * (unsigned __int16)a2);
return result;
}

original_code:
void psxDma4(u32 madr, u32 bcr, u32 chcr) {
 switch (chcr) {
  case 0x01000201:
  {
   bcr= (bcr>>16) * (bcr&0xffff) * 2;
   SPUwriteDMAMem(madr, bcr);
  }
  break;
  case 0x01000200:
  {
     SPUreadDMAMem (madr, (bcr >> 16) * (bcr & 0xffff) * 2);
  }
  break;
 }
}

canonical_original_code:
void psxDma4(unsigned int madr, unsigned int bcr, unsigned int chcr) {
 switch (chcr) {
  case 0x01000201:
  {
   bcr= (bcr>>16) * (bcr&0xffff) * 2;
   SPUwriteDMAMem(madr, bcr);
  }
  break;
  case 0x01000200:
  {
     SPUreadDMAMem (madr, (bcr >> 16) * (bcr & 0xffff) * 2);
  }
  break;
 }
}

variable_types:
madr
unsigned int

variable_types:
bcr
unsigned int

variable_types:
chcr
unsigned int


decompiled_code:
__int64 __fastcall psxDma6(unsigned int a1, int a2, int a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // r9
int v6; // edx

v3 = *(_QWORD *)(psxMemLUT + 8LL * HIWORD(a1));
result = v3 + (unsigned __int16)a1;
if ( v3 )
v3 += (unsigned __int16)a1;
if ( a3 == 285212674 )
{
v5 = (unsigned int)(a2 - 1);
if ( a2 )
{
result = v3;
do
{
v6 = a1 - 4 - v3 + result;
result -= 4LL;
*(_DWORD *)(result + 4) = v6 & 0xFFFFFF;
}
while ( result != v3 - 4 * v5 - 4 );
v3 += 4 * ~v5;
}
*(_DWORD *)(v3 + 4) = 0xFFFFFF;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, int a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // r9
int v6; // edx

v3 = *(_QWORD *)(psxMemLUT + 8LL * HIWORD(a1));
result = v3 + (unsigned __int16)a1;
if ( v3 )
v3 += (unsigned __int16)a1;
if ( a3 == 285212674 )
{
v5 = (unsigned int)(a2 - 1);
if ( a2 )
{
result = v3;
do
{
v6 = a1 - 4 - v3 + result;
result -= 4LL;
*(_DWORD *)(result + 4) = v6 & 0xFFFFFF;
}
while ( result != v3 - 4 * v5 - 4 );
v3 += 4 * ~v5;
}
*(_DWORD *)(v3 + 4) = 0xFFFFFF;
}
return result;
}

original_code:
void psxDma6(u32 madr, u32 bcr, u32 chcr) {
 u32 *mem = (u32 *)(psxMemLUT[(madr) >> 16] == 0 ? ((void *)0) : (void*)(psxMemLUT[(madr) >> 16] + ((madr) & 0xffff)));
 if (chcr == 0x11000002) {
  while (bcr--) {
   *mem-- = (madr - 4) & 0xffffff;
   madr -= 4;
  }
  mem++; *mem = 0xffffff;
 } else {
 }
}

canonical_original_code:
void psxDma6(unsigned int madr, unsigned int bcr, unsigned int chcr) {
 unsigned int *mem = (u32 *)(psxMemLUT[(madr) >> 16] == 0 ? ((void *)0) : (void*)(psxMemLUT[(madr) >> 16] + ((madr) & 0xffff)));
 if (chcr == 0x11000002) {
  while (bcr--) {
   *mem-- = (madr - 4) & 0xffffff;
   madr -= 4;
  }
  mem++; *mem = 0xffffff;
 } else {
 }
}

variable_types:
mem
unsigned int *


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

variable_types:
x
unsigned short


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

variable_types:
x
unsigned int


psxHwReset

decompiled_code:
__int64 psxHwReset()
{
memset(psxH, 0, 0x10000uLL);
return psxRcntInit();
}

canonical_decompiled_code:
__int64 func2()
{
memset(psxH, 0, 0x10000uLL);
return psxRcntInit();
}

original_code:
void psxHwReset() {
 memset(psxH, 0, 0x10000);
 psxRcntInit();
}


decompiled_code:
__int64 __fastcall psxHwRead8(unsigned __int16 a1)
{
return *(unsigned __int8 *)(psxH + a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1)
{
return *(unsigned __int8 *)(psxH + a1);
}

original_code:
u8 psxHwRead8(u32 add) {
 u8 hard;
 switch (add) {
  default:
   hard = (*(u8*) &psxH[(add) & 0xffff]);
   return hard;
 }
 return hard;
}

canonical_original_code:
unsigned char psxHwRead8(unsigned int add) {
 unsigned char hard;
 switch (add) {
  default:
   hard = (*(unsigned char *) &psxH[(add) & 0xffff]);
   return hard;
 }
 return hard;
}

variable_types:
add
unsigned int

variable_types:
hard
unsigned char


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

switch ( a1 )
{
case 528486656:
result = psxRcntRcount(0LL);
break;
case 528486660:
result = psxCounters[2];
break;
case 528486664:
result = psxCounters[4];
break;
case 528486672:
result = psxRcntRcount(1LL);
break;
case 528486676:
result = psxCounters[16];
break;
case 528486680:
result = psxCounters[18];
break;
case 528486688:
result = psxRcntRcount(2LL);
break;
case 528486692:
result = psxCounters[30];
break;
case 528486696:
result = psxCounters[32];
break;
default:
if ( (unsigned int)(a1 - 528489472) <= 0x1FF )
result = SPUreadRegister();
else
result = BFLIP16(*(unsigned __int16 *)(psxH + (unsigned __int16)a1));
break;
}
return result;
}

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

switch ( a1 )
{
case 528486656:
result = psxRcntRcount(0LL);
break;
case 528486660:
result = psxCounters[2];
break;
case 528486664:
result = psxCounters[4];
break;
case 528486672:
result = psxRcntRcount(1LL);
break;
case 528486676:
result = psxCounters[16];
break;
case 528486680:
result = psxCounters[18];
break;
case 528486688:
result = psxRcntRcount(2LL);
break;
case 528486692:
result = psxCounters[30];
break;
case 528486696:
result = psxCounters[32];
break;
default:
if ( (unsigned int)(a1 - 528489472) <= 0x1FF )
result = SPUreadRegister();
else
result = func0(*(unsigned __int16 *)(psxH + (unsigned __int16)a1));
break;
}
return result;
}

original_code:
u16 psxHwRead16(u32 add) {
 u16 hard;
 switch (add) {
                case 0x1f801100:
                        hard = psxRcntRcount(0);
                        return hard;
                case 0x1f801104:
                        hard = psxCounters[0].mode;
                        return hard;
                case 0x1f801108:
                        hard = psxCounters[0].target;
                        return hard;
                case 0x1f801110:
                        hard = psxRcntRcount(1);
                        return hard;
                case 0x1f801114:
                        hard = psxCounters[1].mode;
                        return hard;
                case 0x1f801118:
                        hard = psxCounters[1].target;
                        return hard;
  case 0x1f801120:
   hard = psxRcntRcount(2);
   return hard;
  case 0x1f801124:
   hard = psxCounters[2].mode;
   return hard;
  case 0x1f801128:
   hard = psxCounters[2].target;
   return hard;
  default:
   if (add>=0x1f801c00 && add<0x1f801e00) {
                hard = SPUreadRegister(add);
   } else {
    hard = BFLIP16((*(u16*)&psxH[(add) & 0xffff]));
   }
            return hard;
 }
 return hard;
}

canonical_original_code:
unsigned short psxHwRead16(unsigned int add) {
 unsigned short hard;
 switch (add) {
                case 0x1f801100:
                        hard = psxRcntRcount(0);
                        return hard;
                case 0x1f801104:
                        hard = psxCounters[0].mode;
                        return hard;
                case 0x1f801108:
                        hard = psxCounters[0].target;
                        return hard;
                case 0x1f801110:
                        hard = psxRcntRcount(1);
                        return hard;
                case 0x1f801114:
                        hard = psxCounters[1].mode;
                        return hard;
                case 0x1f801118:
                        hard = psxCounters[1].target;
                        return hard;
  case 0x1f801120:
   hard = psxRcntRcount(2);
   return hard;
  case 0x1f801124:
   hard = psxCounters[2].mode;
   return hard;
  case 0x1f801128:
   hard = psxCounters[2].target;
   return hard;
  default:
   if (add>=0x1f801c00 && add<0x1f801e00) {
                hard = SPUreadRegister(add);
   } else {
    hard = BFLIP16((*(unsigned short *)&psxH[(add) & 0xffff]));
   }
            return hard;
 }
 return hard;
}

variable_types:
hard
unsigned short


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

switch ( a1 )
{
case 528486656:
result = psxRcntRcount(0LL);
break;
case 528486660:
result = *(unsigned int *)&psxCounters[2];
break;
case 528486664:
result = *(unsigned int *)&psxCounters[4];
break;
case 528486672:
result = psxRcntRcount(1LL);
break;
case 528486676:
result = *(unsigned int *)&psxCounters[16];
break;
case 528486680:
result = *(unsigned int *)&psxCounters[18];
break;
case 528486688:
result = psxRcntRcount(2LL);
break;
case 528486692:
result = *(unsigned int *)&psxCounters[30];
break;
case 528486696:
result = *(unsigned int *)&psxCounters[32];
break;
default:
result = BFLIP32(*(_DWORD *)(psxH + (unsigned __int16)a1));
break;
}
return result;
}

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

switch ( a1 )
{
case 528486656:
result = psxRcntRcount(0LL);
break;
case 528486660:
result = *(unsigned int *)&psxCounters[2];
break;
case 528486664:
result = *(unsigned int *)&psxCounters[4];
break;
case 528486672:
result = psxRcntRcount(1LL);
break;
case 528486676:
result = *(unsigned int *)&psxCounters[16];
break;
case 528486680:
result = *(unsigned int *)&psxCounters[18];
break;
case 528486688:
result = psxRcntRcount(2LL);
break;
case 528486692:
result = *(unsigned int *)&psxCounters[30];
break;
case 528486696:
result = *(unsigned int *)&psxCounters[32];
break;
default:
result = func1(*(_DWORD *)(psxH + (unsigned __int16)a1));
break;
}
return result;
}

original_code:
u32 psxHwRead32(u32 add) {
 u32 hard;
 switch (add) {
                case 0x1f801100:
                        hard = psxRcntRcount(0);
                        return hard;
                case 0x1f801104:
                        hard = psxCounters[0].mode;
                        return hard;
                case 0x1f801108:
                        hard = psxCounters[0].target;
                        return hard;
               case 0x1f801110:
                        hard = psxRcntRcount(1);
                        return hard;
                case 0x1f801114:
                        hard = psxCounters[1].mode;
                        return hard;
                case 0x1f801118:
                        hard = psxCounters[1].target;
                        return hard;
  case 0x1f801120:
   hard = psxRcntRcount(2);
   return hard;
  case 0x1f801124:
   hard = psxCounters[2].mode;
   return hard;
  case 0x1f801128:
   hard = psxCounters[2].target;
   return hard;
  default:
   hard = BFLIP32((*(u32*)&psxH[(add) & 0xffff]));
   return hard;
 }
 return hard;
}

canonical_original_code:
unsigned int psxHwRead32(unsigned int add) {
 unsigned int hard;
 switch (add) {
                case 0x1f801100:
                        hard = psxRcntRcount(0);
                        return hard;
                case 0x1f801104:
                        hard = psxCounters[0].mode;
                        return hard;
                case 0x1f801108:
                        hard = psxCounters[0].target;
                        return hard;
               case 0x1f801110:
                        hard = psxRcntRcount(1);
                        return hard;
                case 0x1f801114:
                        hard = psxCounters[1].mode;
                        return hard;
                case 0x1f801118:
                        hard = psxCounters[1].target;
                        return hard;
  case 0x1f801120:
   hard = psxRcntRcount(2);
   return hard;
  case 0x1f801124:
   hard = psxCounters[2].mode;
   return hard;
  case 0x1f801128:
   hard = psxCounters[2].target;
   return hard;
  default:
   hard = BFLIP32((*(unsigned int *)&psxH[(add) & 0xffff]));
   return hard;
 }
 return hard;
}

variable_types:
hard
unsigned int


decompiled_code:
__int64 __fastcall psxHwWrite8(unsigned __int16 a1, char a2)
{
__int64 result; // rax

result = psxH;
*(_BYTE *)(psxH + a1) = a2;
return result;
}

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

result = psxH;
*(_BYTE *)(psxH + a1) = a2;
return result;
}

original_code:
void psxHwWrite8(u32 add, u8 value) {
 switch (add) {
  default:
   (*(u8*) &psxH[(add) & 0xffff]) = value;
   return;
 }
 (*(u8*) &psxH[(add) & 0xffff]) = value;
}

canonical_original_code:
void psxHwWrite8(unsigned int add, unsigned char value) {
 switch (add) {
  default:
   (*(unsigned char *) &psxH[(add) & 0xffff]) = value;
   return;
 }
 (*(unsigned char *) &psxH[(add) & 0xffff]) = value;
}

variable_types:
value
unsigned char


decompiled_code:
__int64 __fastcall psxHwWrite16(__int64 a1, unsigned __int16 a2)
{
__int64 result; // rax
_WORD *v3; // r8
__int16 v4; // ax
__int64 v5; // rdx

if ( (_DWORD)a1 == 528486512 )
{
v4 = BFLIP16(*(unsigned __int16 *)(psxH + 4212LL));
result = BFLIP16((unsigned __int16)(v4 & a2));
*(_WORD *)(v5 + 4208) &= result;
}
else
{
switch ( (int)a1 )
{
case 528486656:
result = psxRcntWcount(0LL, a2);
break;
case 528486660:
result = psxRcntWmode(0LL, a2);
break;
case 528486664:
result = psxRcntWtarget(0LL, a2);
break;
case 528486672:
result = psxRcntWcount(1LL, a2);
break;
case 528486676:
result = psxRcntWmode(1LL, a2);
break;
case 528486680:
result = psxRcntWtarget(1LL, a2);
break;
case 528486688:
result = psxRcntWcount(2LL, a2);
break;
case 528486692:
result = psxRcntWmode(2LL, a2);
break;
case 528486696:
result = psxRcntWtarget(2LL, a2);
break;
default:
if ( (unsigned int)(a1 - 528489472) <= 0x1FF )
{
result = SPUwriteRegister(a1, a2);
}
else
{
result = BFLIP16(a2);
*v3 = result;
}
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int16 a2)
{
__int64 result; // rax
_WORD *v3; // r8
__int16 v4; // ax
__int64 v5; // rdx

if ( (_DWORD)a1 == 528486512 )
{
v4 = func0(*(unsigned __int16 *)(psxH + 4212LL));
result = func0((unsigned __int16)(v4 & a2));
*(_WORD *)(v5 + 4208) &= result;
}
else
{
switch ( (int)a1 )
{
case 528486656:
result = psxRcntWcount(0LL, a2);
break;
case 528486660:
result = psxRcntWmode(0LL, a2);
break;
case 528486664:
result = psxRcntWtarget(0LL, a2);
break;
case 528486672:
result = psxRcntWcount(1LL, a2);
break;
case 528486676:
result = psxRcntWmode(1LL, a2);
break;
case 528486680:
result = psxRcntWtarget(1LL, a2);
break;
case 528486688:
result = psxRcntWcount(2LL, a2);
break;
case 528486692:
result = psxRcntWmode(2LL, a2);
break;
case 528486696:
result = psxRcntWtarget(2LL, a2);
break;
default:
if ( (unsigned int)(a1 - 528489472) <= 0x1FF )
{
result = SPUwriteRegister(a1, a2);
}
else
{
result = func0(a2);
*v3 = result;
}
break;
}
}
return result;
}

original_code:
void psxHwWrite16(u32 add, u16 value) {
 switch (add) {
  case 0x1f801070:
   (*(u16*)&psxH[(0x1070) & 0xffff]) &= BFLIP16( BFLIP16((*(u16*)&psxH[(0x1074) & 0xffff])) & value);
   return;
                case 0x1f801100:
                        psxRcntWcount(0, value); return;
                case 0x1f801104:
                        psxRcntWmode(0, value); return;
                case 0x1f801108:
                        psxRcntWtarget(0, value); return;
                case 0x1f801110:
                        psxRcntWcount(1, value); return;
                case 0x1f801114:
                        psxRcntWmode(1, value); return;
                case 0x1f801118:
                        psxRcntWtarget(1, value); return;
                case 0x1f801120:
                        psxRcntWcount(2, value); return;
                case 0x1f801124:
                        psxRcntWmode(2, value); return;
                case 0x1f801128:
                        psxRcntWtarget(2, value); return;
  default:
   if (add>=0x1f801c00 && add<0x1f801e00) {
               SPUwriteRegister(add, value);
    return;
   }
   (*(u16*)&psxH[(add) & 0xffff]) = BFLIP16(value);
   return;
 }
 (*(u16*)&psxH[(add) & 0xffff]) = BFLIP16(value);
}

canonical_original_code:
void psxHwWrite16(unsigned int add, unsigned short value) {
 switch (add) {
  case 0x1f801070:
   (*(unsigned short *)&psxH[(0x1070) & 0xffff]) &= BFLIP16( BFLIP16((*(unsigned short *)&psxH[(0x1074) & 0xffff])) & value);
   return;
                case 0x1f801100:
                        psxRcntWcount(0, value); return;
                case 0x1f801104:
                        psxRcntWmode(0, value); return;
                case 0x1f801108:
                        psxRcntWtarget(0, value); return;
                case 0x1f801110:
                        psxRcntWcount(1, value); return;
                case 0x1f801114:
                        psxRcntWmode(1, value); return;
                case 0x1f801118:
                        psxRcntWtarget(1, value); return;
                case 0x1f801120:
                        psxRcntWcount(2, value); return;
                case 0x1f801124:
                        psxRcntWmode(2, value); return;
                case 0x1f801128:
                        psxRcntWtarget(2, value); return;
  default:
   if (add>=0x1f801c00 && add<0x1f801e00) {
               SPUwriteRegister(add, value);
    return;
   }
   (*(unsigned short *)&psxH[(add) & 0xffff]) = BFLIP16(value);
   return;
 }
 (*(unsigned short *)&psxH[(add) & 0xffff]) = BFLIP16(value);
}

variable_types:
value
unsigned short


decompiled_code:
__int64 __fastcall psxHwWrite32(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax
__int64 result; // rax
__int64 v4; // rcx
__int64 v5; // rcx
__int64 v6; // rcx
__int64 v7; // rsi
unsigned int v8; // eax
int v9; // eax
__int64 v10; // rdx
int v11; // eax
int v12; // ecx
__int64 v13; // rdx
__int64 v14; // rdx
_DWORD *v15; // rdx
int v16; // eax
__int64 v17; // rcx
int v18; // eax
__int64 v19; // rdx

if ( a1 > 0x1F801128 )
goto LABEL_11;
if ( a1 > 0x1F8010F3 )
{
switch ( a1 )
{
case 0x1F8010F4u:
v16 = BFLIP32(*(_DWORD *)(psxH + 4340LL));
result = BFLIP32((a2 | v16) & 0xFFFFFF ^ v16 & ~(_DWORD)a2);
*(_DWORD *)(v17 + 4340) = result;
break;
case 0x1F801100u:
result = psxRcntWcount(0LL, (unsigned __int16)a2);
break;
case 0x1F801104u:
result = psxRcntWmode(0LL, a2);
break;
case 0x1F801108u:
result = psxRcntWtarget(0LL, (unsigned __int16)a2);
break;
case 0x1F801110u:
result = psxRcntWcount(1LL, (unsigned __int16)a2);
break;
case 0x1F801114u:
result = psxRcntWmode(1LL, a2);
break;
case 0x1F801118u:
result = psxRcntWtarget(1LL, (unsigned __int16)a2);
break;
case 0x1F801120u:
result = psxRcntWcount(2LL, (unsigned __int16)a2);
break;
case 0x1F801124u:
result = psxRcntWmode(2LL, a2);
break;
case 0x1F801128u:
result = psxRcntWtarget(2LL, (unsigned __int16)a2);
break;
default:
goto LABEL_11;
}
return result;
}
if ( a1 == 528486512 )
{
v18 = BFLIP32(*(_DWORD *)(psxH + 4212LL));
result = BFLIP32((unsigned int)a2 & v18);
*(_DWORD *)(v19 + 4208) &= result;
return result;
}
if ( a1 != 528486600 )
{
LABEL_11:
result = BFLIP32(a2);
*v15 = result;
return result;
}
v2 = BFLIP32(a2);
*(_DWORD *)(psxH + 4296LL) = v2;
result = BFLIP32(v2);
if ( (result & 0x1000000) != 0 )
{
result = BFLIP32(*(_DWORD *)(v4 + 4336));
if ( (result & 0x80000) != 0 )
{
v7 = (unsigned int)BFLIP32(*(_DWORD *)(v5 + 4292));
v8 = BFLIP32(*(_DWORD *)(v6 + 4288));
psxDma4(v8, v7);
v9 = BFLIP32(0xFEFFFFFF);
v10 = psxH;
*(_DWORD *)(psxH + 4296LL) &= v9;
result = BFLIP32(*(_DWORD *)(v10 + 4340));
if ( (result & 0x100000) != 0 )
{
v11 = BFLIP32(0x10000000u);
*(_DWORD *)(v13 + 4340) = v11 | v12;
result = BFLIP32(8u);
*(_DWORD *)(v14 + 4208) |= result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax
__int64 result; // rax
__int64 v4; // rcx
__int64 v5; // rcx
__int64 v6; // rcx
__int64 v7; // rsi
unsigned int v8; // eax
int v9; // eax
__int64 v10; // rdx
int v11; // eax
int v12; // ecx
__int64 v13; // rdx
__int64 v14; // rdx
_DWORD *v15; // rdx
int v16; // eax
__int64 v17; // rcx
int v18; // eax
__int64 v19; // rdx

if ( a1 > 0x1F801128 )
goto LABEL_11;
if ( a1 > 0x1F8010F3 )
{
switch ( a1 )
{
case 0x1F8010F4u:
v16 = func1(*(_DWORD *)(psxH + 4340LL));
result = func1((a2 | v16) & 0xFFFFFF ^ v16 & ~(_DWORD)a2);
*(_DWORD *)(v17 + 4340) = result;
break;
case 0x1F801100u:
result = psxRcntWcount(0LL, (unsigned __int16)a2);
break;
case 0x1F801104u:
result = psxRcntWmode(0LL, a2);
break;
case 0x1F801108u:
result = psxRcntWtarget(0LL, (unsigned __int16)a2);
break;
case 0x1F801110u:
result = psxRcntWcount(1LL, (unsigned __int16)a2);
break;
case 0x1F801114u:
result = psxRcntWmode(1LL, a2);
break;
case 0x1F801118u:
result = psxRcntWtarget(1LL, (unsigned __int16)a2);
break;
case 0x1F801120u:
result = psxRcntWcount(2LL, (unsigned __int16)a2);
break;
case 0x1F801124u:
result = psxRcntWmode(2LL, a2);
break;
case 0x1F801128u:
result = psxRcntWtarget(2LL, (unsigned __int16)a2);
break;
default:
goto LABEL_11;
}
return result;
}
if ( a1 == 528486512 )
{
v18 = func1(*(_DWORD *)(psxH + 4212LL));
result = func1((unsigned int)a2 & v18);
*(_DWORD *)(v19 + 4208) &= result;
return result;
}
if ( a1 != 528486600 )
{
LABEL_11:
result = func1(a2);
*v15 = result;
return result;
}
v2 = func1(a2);
*(_DWORD *)(psxH + 4296LL) = v2;
result = func1(v2);
if ( (result & 0x1000000) != 0 )
{
result = func1(*(_DWORD *)(v4 + 4336));
if ( (result & 0x80000) != 0 )
{
v7 = (unsigned int)func1(*(_DWORD *)(v5 + 4292));
v8 = func1(*(_DWORD *)(v6 + 4288));
psxDma4(v8, v7);
v9 = func1(0xFEFFFFFF);
v10 = psxH;
*(_DWORD *)(psxH + 4296LL) &= v9;
result = func1(*(_DWORD *)(v10 + 4340));
if ( (result & 0x100000) != 0 )
{
v11 = func1(0x10000000u);
*(_DWORD *)(v13 + 4340) = v11 | v12;
result = func1(8u);
*(_DWORD *)(v14 + 4208) |= result;
}
}
}
return result;
}

original_code:
void psxHwWrite32(u32 add, u32 value) {
 switch (add) {
  case 0x1f801070:
   (*(u32*)&psxH[(0x1070) & 0xffff]) &= BFLIP32(BFLIP32((*(u32*)&psxH[(0x1074) & 0xffff])) & value);
   return;
  case 0x1f8010c8:
   ((*(u32*)&psxH[(0x10c8) & 0xffff])) = BFLIP32(value);
   { if (BFLIP32(((*(u32*)&psxH[(0x10c8) & 0xffff]))) & 0x01000000 && BFLIP32(((*(u32*)&psxH[(0x10f0) & 0xffff]))) & (8 << (4 * 4))) { psxDma4(BFLIP32(((*(u32*)&psxH[(0x10c0) & 0xffff]))), BFLIP32(((*(u32*)&psxH[(0x10c4) & 0xffff]))), BFLIP32(((*(u32*)&psxH[(0x10c8) & 0xffff])))); ((*(u32*)&psxH[(0x10c8) & 0xffff])) &= BFLIP32(~0x01000000); if (BFLIP32(((*(u32*)&psxH[(0x10f4) & 0xffff]))) & (1 << (16 + 4))) { ((*(u32*)&psxH[(0x10f4) & 0xffff]))|= BFLIP32(1 << (24 + 4)); (*(u32*)&psxH[(0x1070) & 0xffff]) |= BFLIP32(8); }; } };
   return;
  case 0x1f8010f4:
  {
   u32 tmp = (~value) & BFLIP32(((*(u32*)&psxH[(0x10f4) & 0xffff])));
   ((*(u32*)&psxH[(0x10f4) & 0xffff])) = BFLIP32(((tmp ^ value) & 0xffffff) ^ tmp);
   return;
  }
                case 0x1f801100:
                        psxRcntWcount(0, value & 0xffff); return;
                case 0x1f801104:
                        psxRcntWmode(0, value); return;
                case 0x1f801108:
                        psxRcntWtarget(0, value & 0xffff); return;
                case 0x1f801110:
                        psxRcntWcount(1, value & 0xffff); return;
                case 0x1f801114:
                        psxRcntWmode(1, value); return;
                case 0x1f801118:
                        psxRcntWtarget(1, value & 0xffff); return;
  case 0x1f801120:
   psxRcntWcount(2, value & 0xffff); return;
  case 0x1f801124:
   psxRcntWmode(2, value); return;
  case 0x1f801128:
   psxRcntWtarget(2, value & 0xffff); return;
  default:
   (*(u32*)&psxH[(add) & 0xffff]) = BFLIP32(value);
   return;
 }
 (*(u32*)&psxH[(add) & 0xffff]) = BFLIP32(value);
}

canonical_original_code:
void psxHwWrite32(unsigned int add, unsigned int value) {
 switch (add) {
  case 0x1f801070:
   (*(unsigned int *)&psxH[(0x1070) & 0xffff]) &= BFLIP32(BFLIP32((*(unsigned int *)&psxH[(0x1074) & 0xffff])) & value);
   return;
  case 0x1f8010c8:
   ((*(unsigned int *)&psxH[(0x10c8) & 0xffff])) = BFLIP32(value);
   { if (BFLIP32(((*(unsigned int *)&psxH[(0x10c8) & 0xffff]))) & 0x01000000 && BFLIP32(((*(unsigned int *)&psxH[(0x10f0) & 0xffff]))) & (8 << (4 * 4))) { psxDma4(BFLIP32(((*(unsigned int *)&psxH[(0x10c0) & 0xffff]))), BFLIP32(((*(unsigned int *)&psxH[(0x10c4) & 0xffff]))), BFLIP32(((*(unsigned int *)&psxH[(0x10c8) & 0xffff])))); ((*(unsigned int *)&psxH[(0x10c8) & 0xffff])) &= BFLIP32(~0x01000000); if (BFLIP32(((*(unsigned int *)&psxH[(0x10f4) & 0xffff]))) & (1 << (16 + 4))) { ((*(unsigned int *)&psxH[(0x10f4) & 0xffff]))|= BFLIP32(1 << (24 + 4)); (*(unsigned int *)&psxH[(0x1070) & 0xffff]) |= BFLIP32(8); }; } };
   return;
  case 0x1f8010f4:
  {
   unsigned int tmp = (~value) & BFLIP32(((*(u32*)&psxH[(0x10f4) & 0xffff])));
   ((*(unsigned int *)&psxH[(0x10f4) & 0xffff])) = BFLIP32(((tmp ^ value) & 0xffffff) ^ tmp);
   return;
  }
                case 0x1f801100:
                        psxRcntWcount(0, value & 0xffff); return;
                case 0x1f801104:
                        psxRcntWmode(0, value); return;
                case 0x1f801108:
                        psxRcntWtarget(0, value & 0xffff); return;
                case 0x1f801110:
                        psxRcntWcount(1, value & 0xffff); return;
                case 0x1f801114:
                        psxRcntWmode(1, value); return;
                case 0x1f801118:
                        psxRcntWtarget(1, value & 0xffff); return;
  case 0x1f801120:
   psxRcntWcount(2, value & 0xffff); return;
  case 0x1f801124:
   psxRcntWmode(2, value); return;
  case 0x1f801128:
   psxRcntWtarget(2, value & 0xffff); return;
  default:
   (*(unsigned int *)&psxH[(add) & 0xffff]) = BFLIP32(value);
   return;
 }
 (*(unsigned int *)&psxH[(add) & 0xffff]) = BFLIP32(value);
}

variable_types:
value
unsigned int

variable_types:
tmp
unsigned int


psxInit

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

psxCpu = &psxInt;
if ( (unsigned int)psxMemInit() == -1 )
result = 0xFFFFFFFFLL;
else
result = ((__int64 (*)(void))*psxCpu)();
return result;
}

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

psxCpu = &psxInt;
if ( (unsigned int)psxMemInit() == -1 )
result = 0xFFFFFFFFLL;
else
result = ((__int64 (*)(void))*psxCpu)();
return result;
}

original_code:
int psxInit() {
 psxCpu = &psxInt;
 if (psxMemInit() == -1) return -1;
 return psxCpu->Init();
}


psxReset

decompiled_code:
__int64 psxReset()
{
((void (*)(void))psxCpu[1])();
psxMemReset();
psxRegs = 0LL;
*((_QWORD *)&psxRegs + 34) = 0LL;
memset(
(void *)(((unsigned __int64)&psxRegs + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)&psxRegs - (((unsigned int)&psxRegs + 8) & 0xFFFFFFF8) + 280) >> 3));
*((_DWORD *)&psxRegs + 46) = 277872640;
*((_DWORD *)&psxRegs + 49) = 2;
*((_DWORD *)&psxRegs + 66) = -1077936128;
psxHwReset();
return psxBiosInit();
}

canonical_decompiled_code:
__int64 func1()
{
((void (*)(void))psxCpu[1])();
psxMemReset();
psxRegs = 0LL;
*((_QWORD *)&psxRegs + 34) = 0LL;
memset(
(void *)(((unsigned __int64)&psxRegs + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)&psxRegs - (((unsigned int)&psxRegs + 8) & 0xFFFFFFF8) + 280) >> 3));
*((_DWORD *)&psxRegs + 46) = 277872640;
*((_DWORD *)&psxRegs + 49) = 2;
*((_DWORD *)&psxRegs + 66) = -1077936128;
psxHwReset();
return psxBiosInit();
}

original_code:
void psxReset() {
 psxCpu->Reset();
 psxMemReset();
 memset(&psxRegs, 0, sizeof(psxRegs));
 psxRegs.pc = 0xbfc00000;
 psxRegs.CP0.r[12] = 0x10900000;
 psxRegs.CP0.r[15] = 0x00000002;
 psxHwReset();
 psxBiosInit();
}


psxShutdown

decompiled_code:
__int64 psxShutdown()
{
psxMemShutdown();
psxBiosShutdown();
((void (*)(void))psxCpu[5])();
return SPUclose();
}

canonical_decompiled_code:
__int64 func2()
{
psxMemShutdown();
psxBiosShutdown();
((void (*)(void))psxCpu[5])();
return SPUclose();
}

original_code:
void psxShutdown() {
 psxMemShutdown();
 psxBiosShutdown();
 psxCpu->Shutdown();
 SPUclose();
}


psxException

original_code:
void psxException(u32 code, u32 bd) {
 psxRegs.CP0.n.Cause = code;
 if (bd) {
  psxRegs.CP0.n.Cause|= 0x80000000;
  psxRegs.CP0.n.EPC = (psxRegs.pc - 4);
 } else
  psxRegs.CP0.n.EPC = (psxRegs.pc);
 if (psxRegs.CP0.n.Status & 0x400000)
  psxRegs.pc = 0xbfc00180;
 else
  psxRegs.pc = 0x80000080;
 psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status &~0x3f) |
        ((psxRegs.CP0.n.Status & 0xf) << 2);
 psxBiosException();
}

canonical_original_code:
void psxException(unsigned int code, unsigned int bd) {
 psxRegs.CP0.n.Cause = code;
 if (bd) {
  psxRegs.CP0.n.Cause|= 0x80000000;
  psxRegs.CP0.n.EPC = (psxRegs.pc - 4);
 } else
  psxRegs.CP0.n.EPC = (psxRegs.pc);
 if (psxRegs.CP0.n.Status & 0x400000)
  psxRegs.pc = 0xbfc00180;
 else
  psxRegs.pc = 0x80000080;
 psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status &~0x3f) |
        ((psxRegs.CP0.n.Status & 0xf) << 2);
 psxBiosException();
}

variable_types:
code
unsigned int

variable_types:
bd
unsigned int


psxBranchTest

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

if ( (unsigned int)(psxRegs[68] - psxNextsCounter) >= psxNextCounter )
psxRcntUpdate();
result = (unsigned int)(*(_DWORD *)(psxH + 4212LL) & *(_DWORD *)(psxH + 4208LL));
if ( (*(_DWORD *)(psxH + 4212LL) & *(_DWORD *)(psxH + 4208LL)) != 0 )
{
result = psxRegs[46] & 0x401;
if ( (_DWORD)result == 1025 )
result = psxException(1024, 0);
}
return result;
}

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

if ( (unsigned int)(psxRegs[68] - psxNextsCounter) >= psxNextCounter )
psxRcntUpdate();
result = (unsigned int)(*(_DWORD *)(psxH + 4212LL) & *(_DWORD *)(psxH + 4208LL));
if ( (*(_DWORD *)(psxH + 4212LL) & *(_DWORD *)(psxH + 4208LL)) != 0 )
{
result = psxRegs[46] & 0x401;
if ( (_DWORD)result == 1025 )
result = func3(1024, 0);
}
return result;
}

original_code:
void psxBranchTest() {
 if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter)
  psxRcntUpdate();
 if ((*(u32*)&psxH[(0x1070) & 0xffff]) & (*(u32*)&psxH[(0x1074) & 0xffff])) {
  if ((psxRegs.CP0.n.Status & 0x401) == 0x401) {
   psxException(0x400, 0);
  }
 }
}

canonical_original_code:
void psxBranchTest() {
 if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter)
  psxRcntUpdate();
 if ((*(unsigned int *)&psxH[(0x1070) & 0xffff]) & (*(unsigned int *)&psxH[(0x1074) & 0xffff])) {
  if ((psxRegs.CP0.n.Status & 0x401) == 0x401) {
   psxException(0x400, 0);
  }
 }
}


psxExecuteBios

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

for ( ; psxRegs[66] != -2147287040; result = ((__int64 (*)(void))psxCpu[3])() )
;
return result;
}

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

for ( ; psxRegs[66] != -2147287040; result = ((__int64 (*)(void))psxCpu[3])() )
;
return result;
}

original_code:
void psxExecuteBios() {
 while (psxRegs.pc != 0x80030000)
  psxCpu->ExecuteBlock();
}


SPUirq

decompiled_code:
__int64 SPUirq()
{
int v0; // er8
__int64 result; // rax

v0 = BFLIP32_constprop_0();
result = psxH;
*(_DWORD *)(psxH + 4208LL) |= v0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er8
__int64 result; // rax

v0 = func0();
result = psxH;
*(_DWORD *)(psxH + 4208LL) |= v0;
return result;
}

canonical_original_code:
void SPUirq() {
 (*(unsigned int *)&psxH[(0x1070) & 0xffff])|=BFLIP32(0x200);
}


repo: minggr/backup

decompiled_code:
char *__fastcall skip_task(char *haystack)
{
const char *v1; // rsi
char **i; // rbx
char *result; // rax

v1 = skip_task_list[0];
if ( !skip_task_list[0] )
return 0LL;
for ( i = skip_task_list; ; ++i )
{
result = strstr(haystack, v1);
if ( result )
break;
v1 = i[1];
if ( !v1 )
return result;
}
return (_BYTE *)(skip_task + 1);
}

canonical_decompiled_code:
char *__fastcall func0(char *haystack)
{
const char *v1; // rsi
char **i; // rbx
char *result; // rax

v1 = skip_task_list[0];
if ( !skip_task_list[0] )
return 0LL;
for ( i = skip_task_list; ; ++i )
{
result = strstr(haystack, v1);
if ( result )
break;
v1 = i[1];
if ( !v1 )
return result;
}
return (_BYTE *)(skip_task + 1);
}

original_code:
int skip_task(char *name)
{
 char **task;
 task = skip_task_list;
 while (*task) {
  if (strstr(name, *task))
   return 1;
  task++;
 }
 return 0;
}

variable_types:
name
char *

variable_types:
task
char **


decompiled_code:
_BOOL8 lkp_connect()
{
__int64 v0; // r8
_BOOL8 result; // rax

v0 = mysql_init(&mysql);
result = 0LL;
if ( v0 )
{
conn = mysql_real_connect(&mysql, "lkp-os", "perf", "perf", "ymz_stp_results_internal", 0LL, 0LL, 0LL);
result = conn != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func1()
{
__int64 v0; // r8
_BOOL8 result; // rax

v0 = mysql_init(&mysql);
result = 0LL;
if ( v0 )
{
conn = mysql_real_connect(&mysql, "lkp-os", "perf", "perf", "ymz_stp_results_internal", 0LL, 0LL, 0LL);
result = conn != 0;
}
return result;
}

original_code:
int lkp_connect()
{
 if (!mysql_init(&mysql))
  return 0;
 conn = mysql_real_connect(&mysql, "lkp-os", "perf", "perf", "ymz_stp_results_internal", 0, ((void *)0), 0);
 if (!conn) {
 ;
 ;
  return 0;
 }
 return 1;
}


decompiled_code:
__int64 lkp_close()
{
return mysql_close(conn);
}

canonical_decompiled_code:
__int64 func2()
{
return mysql_close(conn);
}

original_code:
void lkp_close()
{
 mysql_close(conn);
}

canonical_original_code:
void lkp_close()
{
 mysql_close(conn);
}


decompiled_code:
void lkp_freealltask()
{
char *i; // rbx
char *v1; // rdi

for ( i = task_list; i; task_list = i )
{
v1 = i;
i = (char *)*((_QWORD *)i + 33);
free(v1);
}
}

canonical_decompiled_code:
void func4()
{
char *i; // rbx
char *v1; // rdi

for ( i = task_list; i; task_list = i )
{
v1 = i;
i = (char *)*((_QWORD *)i + 33);
free(v1);
}
}

original_code:
void lkp_freealltask()
{
 LKP_TASK *next_task;
 while (task_list) {
  next_task = task_list->next;
  free(task_list);
  task_list = next_task;
 }
}

canonical_original_code:
void lkp_freealltask()
{
 struct lkp_task *next_task;
 while (task_list) {
  next_task = task_list->next;
  free(task_list);
  task_list = next_task;
 }
}

variable_types: struct lkp_task { char name[256]; int invert; struct lkp_task *next; } *


decompiled_code:
float __fastcall lkp_getavgvalue(const char *a1, const char *a2, const char *a3)
{
int v3; // eax
float result; // xmm0_4
int v5; // ecx
float *v6; // rax
float v7; // xmm0_4
float v8; // [rsp+Ch] [rbp-1Ch]
void *ptr; // [rsp+18h] [rbp-10h] BYREF

v3 = lkp_getvalue(a1, a2, a3, (float **)&ptr);
result = *(float *)&LC12;
if ( v3 )
{
v5 = v3;
if ( v3 <= 0 )
{
v7 = 0.0;
}
else
{
v6 = (float *)ptr;
v7 = 0.0;
do
v7 = v7 + *v6++;
while ( v6 != (float *)((char *)ptr + 4 * (unsigned int)(v5 - 1) + 4) );
}
v8 = v7 / (float)v5;
free(ptr);
result = v8;
}
return result;
}

canonical_decompiled_code:
float __fastcall func8(const char *a1, const char *a2, const char *a3)
{
int v3; // eax
float result; // xmm0_4
int v5; // ecx
float *v6; // rax
float v7; // xmm0_4
float v8; // [rsp+Ch] [rbp-1Ch]
void *ptr; // [rsp+18h] [rbp-10h] BYREF

v3 = func7(a1, a2, a3, (float **)&ptr);
result = *(float *)&LC12;
if ( v3 )
{
v5 = v3;
if ( v3 <= 0 )
{
v7 = 0.0;
}
else
{
v6 = (float *)ptr;
v7 = 0.0;
do
v7 = v7 + *v6++;
while ( v6 != (float *)((char *)ptr + 4 * (unsigned int)(v5 - 1) + 4) );
}
v8 = v7 / (float)v5;
free(ptr);
result = v8;
}
return result;
}

original_code:
float lkp_getavgvalue(char *host, char *task, char *kernel)
{
 float *value, v = 0;
 int count, i;
 count = lkp_getvalue(host, task, kernel, &value);
 if (!count)
  return -1;
 for (i = 0; i < count; i++) {
  v += value[i];
 }
 v = v / count;
 free(value);
 return v;
}

canonical_original_code:
float lkp_getavgvalue(char *host, char *task, char *kernel)
{
 float *value; float v = 0;
 int count; int i;
 count = lkp_getvalue(host, task, kernel, &value);
 if (!count)
  return -1;
 for (i = 0; i < count; i++) {
  v += value[i];
 }
 v = v / count;
 free(value);
 return v;
}

variable_types:
host
char *

variable_types:
task
char *

variable_types:
kernel
char *

variable_types:
value
float *

variable_types: v float

variable_types: count int

variable_types: i int

return_type: float


decompiled_code:
void lkp_freealldata()
{
char *i; // rbx
char *v1; // rdi

for ( i = data_list; i; data_list = i )
{
v1 = i;
i = (char *)*((_QWORD *)i + 55);
free(v1);
}
}

canonical_decompiled_code:
void func10()
{
char *i; // rbx
char *v1; // rdi

for ( i = data_list; i; data_list = i )
{
v1 = i;
i = (char *)*((_QWORD *)i + 55);
free(v1);
}
}

original_code:
void lkp_freealldata()
{
 LKP_DATA *next_data;
 while (data_list) {
  next_data = data_list->next;
  free(data_list);
  data_list = next_data;
 }
}

canonical_original_code:
void lkp_freealldata()
{
 struct lkp_data *next_data;
 while (data_list) {
  next_data = data_list->next;
  free(data_list);
  data_list = next_data;
 }
}

variable_types: struct lkp_data { char host[56]; char task[256]; char prev_kernel[56]; char this_kernel[56]; float prev_value; float this_value; float pct; struct lkp_data *next; } *


decompiled_code:
void __fastcall lkp_getalldata(char *src, char *a2)
{
const char **v2; // rbx
char *i; // r13
float v4; // xmm0_4
char *v5; // rax
__int64 v6; // r14
int v7; // eax
float v8; // xmm0_4
__int64 v9; // [rsp+0h] [rbp-30h]

if ( host_list[0] )
{
v2 = (const char **)host_list;
do
{
for ( i = task_list; i; i = (char *)*((_QWORD *)i + 33) )
{
LODWORD(v9) = lkp_getavgvalue(*v2, i, src);
v4 = lkp_getavgvalue(*v2, i, a2);
if ( *(float *)&v9 >= 0.0 && v4 >= 0.0 )
{
*((float *)&v9 + 1) = v4;
v5 = (char *)malloc(0x1C0uLL);
v6 = (__int64)v5;
if ( v5 )
{
strcpy(v5, *v2);
strcpy((char *)(v6 + 56), i);
strcpy((char *)(v6 + 312), src);
strcpy((char *)(v6 + 368), a2);
v7 = *((_DWORD *)i + 64);
*(_QWORD *)(v6 + 424) = v9;
v8 = (float)(v4 - *(float *)&v9) / *(float *)&v9;
*(float *)(v6 + 432) = v8;
if ( v7 )
*(_DWORD *)(v6 + 432) = LODWORD(v8) ^ LC13;
lkp_linkdata(v6);
}
}
}
++v2;
}
while ( *v2 );
}
}

original_code:
void lkp_getalldata(char *prev_kernel, char *this_kernel)
{
 char **host;
 LKP_TASK *task;
 float prev_value, this_value;
 LKP_DATA *data;
 host = host_list;
 while (*host) {
  task = task_list;
  while (task) {
   prev_value = lkp_getavgvalue(*host, task->name, prev_kernel);
   this_value = lkp_getavgvalue(*host, task->name, this_kernel);
   if (prev_value < 0 || this_value < 0) {
    task = task->next;
    continue;
   }
   data = malloc(sizeof(LKP_DATA));
   if (!data) {
   ;
    task = task->next;
    continue;
   }
   strcpy(data->host, *host);
   strcpy(data->task, task->name);
   strcpy(data->prev_kernel, prev_kernel);
   strcpy(data->this_kernel, this_kernel);
   data->prev_value = prev_value;
   data->this_value = this_value;
   data->pct = (this_value - prev_value) / prev_value;
   if (task->invert)
    data->pct = -(data->pct);
   lkp_linkdata(data);
   task = task->next;
  }
  host++;
 }
}

canonical_original_code:
void lkp_getalldata(char *prev_kernel, char *this_kernel)
{
 char **host;
 struct lkp_task *task;
 float prev_value; float this_value;
 struct lkp_data *data;
 host = host_list;
 while (*host) {
  task = task_list;
  while (task) {
   prev_value = lkp_getavgvalue(*host, task->name, prev_kernel);
   this_value = lkp_getavgvalue(*host, task->name, this_kernel);
   if (prev_value < 0 || this_value < 0) {
    task = task->next;
    continue;
   }
   data = malloc(sizeof(LKP_DATA));
   if (!data) {
   ;
    task = task->next;
    continue;
   }
   strcpy(data->host, *host);
   strcpy(data->task, task->name);
   strcpy(data->prev_kernel, prev_kernel);
   strcpy(data->this_kernel, this_kernel);
   data->prev_value = prev_value;
   data->this_value = this_value;
   data->pct = (this_value - prev_value) / prev_value;
   if (task->invert)
    data->pct = -(data->pct);
   lkp_linkdata(data);
   task = task->next;
  }
  host++;
 }
}

variable_types:
host
char **

user_defined_types: struct lkp_task { char name[256]; int invert; struct lkp_task *next; }

user_defined_types: struct lkp_data { char host[56]; char task[256]; char prev_kernel[56]; char this_kernel[56]; float prev_value; float this_value; float pct; struct lkp_data *next; }


decompiled_code:
char *__fastcall lkp_searchdata(char *s2, char *a2)
{
char *i; // r12

for ( i = data_list; i; i = (char *)*((_QWORD *)i + 55) )
{
if ( !strcmp(i, s2) && !strcmp(i + 56, a2) )
break;
}
return i;
}

canonical_decompiled_code:
char *__fastcall func12(char *s2, char *a2)
{
char *i; // r12

for ( i = data_list; i; i = (char *)*((_QWORD *)i + 55) )
{
if ( !strcmp(i, s2) && !strcmp(i + 56, a2) )
break;
}
return i;
}

original_code:
LKP_DATA* lkp_searchdata(char *host, char *task)
{
 LKP_DATA *data;
 data = data_list;
 while (data) {
  if (!strcmp(data->host, host) && !strcmp(data->task, task))
   return data;
  data = data->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct lkp_data *lkp_searchdata(char *host, char *task)
{
 struct lkp_data *data;
 data = data_list;
 while (data) {
  if (!strcmp(data->host, host) && !strcmp(data->task, task))
   return data;
  data = data->next;
 }
 return ((void *)0);
}

return_type: struct lkp_data { char host[56]; char task[256]; char prev_kernel[56]; char this_kernel[56]; float prev_value; float this_value; float pct; struct lkp_data *next; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rbp

if ( argc <= 2 )
{
printf("Usage: %s <new_kernel> <old_kernel>\n", *argv);
printf("For example: %s 2.6.33-rc4 2.6.33-rc3\n", *argv);
exit(0);
}
v3 = (char *)argv[1];
v4 = (char *)argv[2];
if ( !lkp_connect() )
return -1;
lkp_getalltask();
lkp_getalldata(v4, v3);
lkp_csv(v4, v3);
lkp_freealldata();
lkp_freealltask();
lkp_close();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v4; // rbp

if ( argc <= 2 )
{
printf("Usage: %s <new_kernel> <old_kernel>\n", *argv);
printf("For example: %s 2.6.33-rc4 2.6.33-rc3\n", *argv);
exit(0);
}
v3 = (char *)argv[1];
v4 = (char *)argv[2];
if ( !func1() )
return -1;
func5();
func11(v4, v3);
func14(v4, v3);
func10();
func4();
func2();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 float *value, v = 0;
 int count, i;
 char *prev_kernel;
 char *this_kernel;
 if (argc < 3) {
  printf("Usage: %s <new_kernel> <old_kernel>\n", argv[0]);
  printf("For example: %s 2.6.33-rc4 2.6.33-rc3\n", argv[0]);
  exit(0);
 }
 this_kernel = argv[1];
 prev_kernel = argv[2];
 if (!lkp_connect()) {
  return -1;
 }
 lkp_getalltask();
 lkp_getalldata(prev_kernel, this_kernel);
 lkp_csv(prev_kernel, this_kernel);
 lkp_freealldata();
 lkp_freealltask();
 lkp_close();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 float *value; float v = 0;
 int count; int i;
 char *prev_kernel;
 char *this_kernel;
 if (argc < 3) {
  printf("Usage: %s <new_kernel> <old_kernel>\n", argv[0]);
  printf("For example: %s 2.6.33-rc4 2.6.33-rc3\n", argv[0]);
  exit(0);
 }
 this_kernel = argv[1];
 prev_kernel = argv[2];
 if (!lkp_connect()) {
  return -1;
 }
 lkp_getalltask();
 lkp_getalldata(prev_kernel, this_kernel);
 lkp_csv(prev_kernel, this_kernel);
 lkp_freealldata();
 lkp_freealltask();
 lkp_close();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


caesar

repo: minghaow/miscellaneous

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

if ( (unsigned __int8)((a1 & 0xDF) - 65) <= 0xCu )
return a1 + 13;
result = a1 - 13;
if ( (unsigned __int8)((a1 & 0xDF) - 78) >= 0xDu )
result = a1;
return result;
}

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

if ( (unsigned __int8)((a1 & 0xDF) - 65) <= 0xCu )
return a1 + 13;
result = a1 - 13;
if ( (unsigned __int8)((a1 & 0xDF) - 78) >= 0xDu )
result = a1;
return result;
}

variable_types: c char

return_type: char


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // edi
__int64 v4; // rcx
char v5; // al
__int64 v6; // rcx
int v7; // ebx
__int64 v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

while ( 1 )
{
do
{
if ( (int)read(0, v9, 0xFFuLL) < 0 )
exit(1);
v3 = v9[0];
if ( v9[0] == 10 || !v9[0] )
exit(0);
LODWORD(v4) = 0;
while ( 1 )
{
v7 = v4;
if ( (_BYTE)v3 == 10 || !(_BYTE)v3 )
break;
v5 = caesar(v3);
v9[v6] = v5;
v4 = v6 + 1;
if ( v4 == 255 )
{
v7 = 255;
if ( (int)write(1, v9, 0x100uLL) < 0 )
exit(1);
goto LABEL_11;
}
v3 = v9[v4];
}
if ( (int)write(1, v9, (unsigned int)(v4 + 1)) < 0 )
exit(1);
}
while ( !v7 );
LABEL_11:
v8 = 0LL;
do
v9[v8++] = 0;
while ( v7 > (int)v8 );
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // edi
__int64 v4; // rcx
char v5; // al
__int64 v6; // rcx
int v7; // ebx
__int64 v8; // rax
char v9[264]; // [rsp+0h] [rbp-108h] BYREF

while ( 1 )
{
do
{
if ( (int)read(0, v9, 0xFFuLL) < 0 )
exit(1);
v3 = v9[0];
if ( v9[0] == 10 || !v9[0] )
exit(0);
LODWORD(v4) = 0;
while ( 1 )
{
v7 = v4;
if ( (_BYTE)v3 == 10 || !(_BYTE)v3 )
break;
v5 = func0(v3);
v9[v6] = v5;
v4 = v6 + 1;
if ( v4 == 255 )
{
v7 = 255;
if ( (int)write(1, v9, 0x100uLL) < 0 )
exit(1);
goto LABEL_11;
}
v3 = v9[v4];
}
if ( (int)write(1, v9, (unsigned int)(v4 + 1)) < 0 )
exit(1);
}
while ( !v7 );
LABEL_11:
v8 = 0LL;
do
v9[v8++] = 0;
while ( v7 > (int)v8 );
}
}

original_code:
int main(void) {
    int i, count;
    char buffer[255];
    while (1) {
        if (read(0, buffer, 255) < 0)
            exit(1);
        if (buffer[0] == '\n' || buffer[0] == '\0')
            exit(0);
        for (count = 0; count < 255; count++) {
            char tmp = buffer[count];
            if (tmp == '\n' || tmp == '\0') break;
            buffer[count] = caesar(tmp);
        }
        if (write(1, buffer, count + 1) < 0)
            exit(1);
        for (i = 0; i < count; i++)
            buffer[i] = '\0';
    }
    return 0;
}

canonical_original_code:
int main() {
    int i; int count;
    char buffer[255];
    while (1) {
        if (read(0, buffer, 255) < 0)
            exit(1);
        if (buffer[0] == '\n' || buffer[0] == '\0')
            exit(0);
        for (count = 0; count < 255; count++) {
            char tmp = buffer[count];
            if (tmp == '\n' || tmp == '\0') break;
            buffer[count] = caesar(tmp);
        }
        if (write(1, buffer, count + 1) < 0)
            exit(1);
        for (i = 0; i < count; i++)
            buffer[i] = '\0';
    }
    return 0;
}

variable_types:
buffer
char [255]

variable_types: tmp char


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("test function %d\n", 4096LL);
return 0;
}

original_code:
int main()
{
    int type =0 ;
    type = type | 0x1000;
    type = type | HA_ONOFF_SWITCH;
 printf("test function %d\n", type);
 return 0;
}

canonical_original_code:
int main()
{
    int type = 0;
    type = type | 0x1000;
    type = type | HA_ONOFF_SWITCH;
 printf("test function %d\n", type);
 return 0;
}

variable_types: type int


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

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

original_code:
int zigbee_connect(char *addr, int port)
{
 return ZB_SUCCESS;
}

variable_types:
addr
char *

variable_types: port int


test

repo: minou/ldx-box

decompiled_code:
__int64 __fastcall test(char *src)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, src);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, src);
return 1LL;
}

original_code:
int test(char *src)
{
    char buffer[1024];
    strcpy(buffer, src);
    return 1;
}

variable_types:
src
char *

variable_types:
buffer
char [1024]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test((char *)argv[1]);
puts("Done..");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7((char *)argv[1]);
puts("Done..");
return 0;
}

original_code:
int main(int argc, char **argv)
{
    test(argv[1]);
    printf("Done..\n");
    return 0;
}

variable_types:
argv
char **


Contains

repo: mintmlyx/ParallelShapelet

original_code:
int Contains(char* MyChar, char* Search)
{
    int LoopOne = 0;
    int LoopTwo;
    int LoopThree;
    int MyCharSize = (int) strlen(MyChar);
    int SearchSize = (int) strlen(Search);
    int Yes = 0;
    while(LoopOne < MyCharSize)
    {
        if(MyChar[LoopOne] == Search[0])
        {
            LoopTwo = 0;
            LoopThree = LoopOne;
            while(LoopTwo < SearchSize)
            {
                if(MyChar[LoopThree] == Search[LoopTwo])
                    Yes++;
                LoopTwo++;
                LoopThree++;
            }
            if(Yes == SearchSize)
                return 1;
        }
        LoopOne++;
    }
    return 0;
}

canonical_original_code:
int Contains(char *MyChar, char *Search)
{
    int LoopOne = 0;
    int LoopTwo;
    int LoopThree;
    int MyCharSize = (int) strlen(MyChar);
    int SearchSize = (int) strlen(Search);
    int Yes = 0;
    while(LoopOne < MyCharSize)
    {
        if(MyChar[LoopOne] == Search[0])
        {
            LoopTwo = 0;
            LoopThree = LoopOne;
            while(LoopTwo < SearchSize)
            {
                if(MyChar[LoopThree] == Search[LoopTwo])
                    Yes++;
                LoopTwo++;
                LoopThree++;
            }
            if(Yes == SearchSize)
                return 1;
        }
        LoopOne++;
    }
    return 0;
}

variable_types:
MyChar
char *

variable_types:
Search
char *

variable_types: LoopOne int

variable_types: LoopTwo int

variable_types: LoopThree int

variable_types: MyCharSize int

variable_types: SearchSize int

variable_types: Yes int


getColumn

decompiled_code:
double *__fastcall getColumn(int a1, int a2, __int64 a3)
{
double *v4; // rax
double *v5; // r8
double *v6; // rsi
int *v7; // rdx
int v8; // ecx

v4 = (double *)malloc(8LL * a2);
v5 = v4;
if ( a2 > 0 )
{
v6 = &v4[a2];
v7 = (int *)(a3 + 4LL * (a1 - 1));
do
{
v8 = *v7;
++v4;
v7 += 7;
*(v4 - 1) = (double)v8;
}
while ( v4 != v6 );
}
return v5;
}

canonical_decompiled_code:
double *__fastcall func1(int a1, int a2, __int64 a3)
{
double *v4; // rax
double *v5; // r8
double *v6; // rsi
int *v7; // rdx
int v8; // ecx

v4 = (double *)malloc(8LL * a2);
v5 = v4;
if ( a2 > 0 )
{
v6 = &v4[a2];
v7 = (int *)(a3 + 4LL * (a1 - 1));
do
{
v8 = *v7;
++v4;
v7 += 7;
*(v4 - 1) = (double)v8;
}
while ( v4 != v6 );
}
return v5;
}

original_code:
double* getColumn(int field, int nrow, Dataset *s)
{
 double *output = (double *) malloc (sizeof(double) * nrow);
 for (int i = 0; i < nrow; i++) {
  output[i] = s[i].count[field - 1];
 }
 return output;
}

canonical_original_code:
double *getColumn(int field, int nrow, struct Sample *s)
{
 double *output = (double *) malloc (sizeof(double) * nrow);
 for (int i = 0; i < nrow; i++) {
  output[i] = s[i].count[field - 1];
 }
 return output;
}

variable_types: field int

variable_types: nrow int

variable_types: struct Sample { unsigned int count[7]; } *

variable_types:
output
double *

variable_types: i int

return_type: double *


Dumpdata

decompiled_code:
int __fastcall Dumpdata(double *a1, int a2)
{
double *v2; // rbx
double v3; // xmm0_8

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = *v2++;
printf("%2.4f \n", v3);
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(double *a1, int a2)
{
double *v2; // rbx
double v3; // xmm0_8

if ( a2 > 0 )
{
v2 = a1;
do
{
v3 = *v2++;
printf("%2.4f \n", v3);
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return putchar(10);
}

original_code:
void Dumpdata(double * data, int cnt)
{
 for(int i=0; i < cnt; i++) {
  printf("%2.4f \n", data[i]);
 }
 printf("\n");
}

canonical_original_code:
void Dumpdata(double *data, int cnt)
{
 for(int i = 0; i < cnt; i++) {
  printf("%2.4f \n", data[i]);
 }
 printf("\n");
}

variable_types:
data
double *

variable_types: cnt int


repo: mir-ror/ltunify

decompiled_code:
bool __fastcall report_type_is_hidpp(char a1)
{
return (unsigned __int8)(a1 - 16) <= 1u;
}

canonical_decompiled_code:
bool __fastcall func7(char a1)
{
return (unsigned __int8)(a1 - 16) <= 1u;
}

original_code:
_Bool report_type_is_hidpp(u8 report_id) {
 return report_id == 0x10 || report_id == 0x11;
}

canonical_original_code:
_Bool report_type_is_hidpp(unsigned char report_id) {
 return report_id == 0x10 || report_id == 0x11;
}


decompiled_code:
bool __fastcall report_type_is_dj(char a1)
{
return (unsigned __int8)(a1 - 32) <= 1u;
}

canonical_decompiled_code:
bool __fastcall func8(char a1)
{
return (unsigned __int8)(a1 - 32) <= 1u;
}

original_code:
_Bool report_type_is_dj(u8 report_id) {
 return report_id == 0x20 || report_id == 0x21;
}

canonical_original_code:
_Bool report_type_is_dj(unsigned char report_id) {
 return report_id == 0x20 || report_id == 0x21;
}


decompiled_code:
char *__fastcall report_type_str(char a1, unsigned __int8 a2)
{
char v2; // r8
char *result; // rax
bool v4; // r8

if ( report_type_is_hidpp(a1) )
{
result = report_types[a2];
}
else
{
v4 = report_type_is_dj(v2);
result = "Usage: %s /dev/usbmonX\n" + 23;
if ( !v4 )
return result;
result = (char *)dj_report_types[a2];
}
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char a1, unsigned __int8 a2)
{
char v2; // r8
char *result; // rax
bool v4; // r8

if ( func7(a1) )
{
result = report_types[a2];
}
else
{
v4 = func8(v2);
result = "Usage: %s /dev/usbmonX\n" + 23;
if ( !v4 )
return result;
result = (char *)dj_report_types[a2];
}
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

original_code:
const char * report_type_str(u8 report_id, u8 type) {
 const char *str = ((void *)0);
 if (report_type_is_hidpp(report_id))
  str = report_types[type];
 else if (report_type_is_dj(report_id))
  str = dj_report_types[type];
 return str ? str : "";
}

canonical_original_code:
char *report_type_str(unsigned char report_id, unsigned char type) {
 char *str = ((void *)0);
 if (report_type_is_hidpp(report_id))
  str = report_types[type];
 else if (report_type_is_dj(report_id))
  str = dj_report_types[type];
 return str ? str : "";
}

variable_types:
type
unsigned char

variable_types:
str
char *

return_type: char *


decompiled_code:
char *__fastcall error_str(unsigned __int8 a1)
{
char *result; // rax

result = error_messages[a1];
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

canonical_decompiled_code:
char *__fastcall func11(unsigned __int8 a1)
{
char *result; // rax

result = error_messages[a1];
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

original_code:
const char *error_str(u8 er) {
 const char * str = error_messages[er];
 return str ? str : "";
}

canonical_original_code:
char *error_str(unsigned char er) {
 char *str = error_messages[er];
 return str ? str : "";
}

variable_types:
er
unsigned char


decompiled_code:
char *__fastcall error_str_hidpp20(unsigned __int8 a1)
{
char *result; // rax

result = error_messages_hidpp20[a1];
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

canonical_decompiled_code:
char *__fastcall func12(unsigned __int8 a1)
{
char *result; // rax

result = error_messages_hidpp20[a1];
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

original_code:
const char *error_str_hidpp20(u8 er) {
 const char * str = error_messages_hidpp20[er];
 return str ? str : "";
}

canonical_original_code:
char *error_str_hidpp20(unsigned char er) {
 char *str = error_messages_hidpp20[er];
 return str ? str : "";
}


decompiled_code:
char *__fastcall register_str(unsigned __int8 a1)
{
char *result; // rax

result = registers[a1];
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

canonical_decompiled_code:
char *__fastcall func13(unsigned __int8 a1)
{
char *result; // rax

result = registers[a1];
if ( !result )
result = "Usage: %s /dev/usbmonX\n" + 23;
return result;
}

original_code:
const char *register_str(u8 reg) {
 const char * str = registers[reg];
 return str ? str : "";
}

canonical_original_code:
char *register_str(unsigned char reg) {
 char *str = registers[reg];
 return str ? str : "";
}

variable_types:
reg
unsigned char


decompiled_code:
char __fastcall process_msg_payload(char *a1, unsigned __int8 a2)
{
char result; // al
char v3; // r8
unsigned __int8 v4; // r12
char v5; // r13
int v6; // ebp
char v7; // bl
int v8; // er12
bool v9; // zf

result = report_type_is_hidpp(*a1);
if ( !result )
{
LABEL_13:
v4 = 0;
goto LABEL_14;
}
v4 = a1[2];
if ( v4 == 0x8F )
{
v4 = 4;
report_type_str(v3, a1[3]);
__printf_chk();
register_str(a1[4]);
__printf_chk();
error_str(a1[5]);
result = __printf_chk();
goto LABEL_14;
}
if ( v4 <= 0x8Fu )
{
if ( v4 )
{
if ( (unsigned __int8)(v4 + 0x80) <= 3u )
{
v4 = 1;
register_str(a1[3]);
result = __printf_chk();
if ( a2 <= 1u )
return result;
goto LABEL_7;
}
goto LABEL_13;
}
if ( a2 == 4 || a2 == 17 )
{
v4 = 1;
__printf_chk();
result = __printf_chk();
}
LABEL_14:
if ( v4 >= a2 )
return result;
goto LABEL_7;
}
v9 = v4 == 0xFF;
v4 = 0;
if ( !v9 || a2 != 17 )
goto LABEL_14;
v4 = 3;
__printf_chk();
__printf_chk();
__printf_chk();
error_str_hidpp20(a1[5]);
__printf_chk();
LABEL_7:
v5 = a2 - v4;
__printf_chk();
__printf_chk();
result = v4 + 1;
v6 = (_DWORD)a1 + (unsigned __int8)(v4 + 1);
v7 = 0;
v8 = (unsigned __int8)(v4 + 2) - v6;
while ( v5 != ++v7 )
{
__printf_chk();
result = v7 & 3;
if ( (v7 & 3) == 3 )
{
result = v8 + v6;
if ( a2 > v8 + v6 )
result = putchar(32);
}
++v6;
}
return result;
}

canonical_decompiled_code:
char __fastcall func14(char *a1, unsigned __int8 a2)
{
char result; // al
char v3; // r8
unsigned __int8 v4; // r12
char v5; // r13
int v6; // ebp
char v7; // bl
int v8; // er12
bool v9; // zf

result = func7(*a1);
if ( !result )
{
LABEL_13:
v4 = 0;
goto LABEL_14;
}
v4 = a1[2];
if ( v4 == 0x8F )
{
v4 = 4;
func9(v3, a1[3]);
__printf_chk();
func13(a1[4]);
__printf_chk();
func11(a1[5]);
result = __printf_chk();
goto LABEL_14;
}
if ( v4 <= 0x8Fu )
{
if ( v4 )
{
if ( (unsigned __int8)(v4 + 0x80) <= 3u )
{
v4 = 1;
func13(a1[3]);
result = __printf_chk();
if ( a2 <= 1u )
return result;
goto LABEL_7;
}
goto LABEL_13;
}
if ( a2 == 4 || a2 == 17 )
{
v4 = 1;
__printf_chk();
result = __printf_chk();
}
LABEL_14:
if ( v4 >= a2 )
return result;
goto LABEL_7;
}
v9 = v4 == 0xFF;
v4 = 0;
if ( !v9 || a2 != 17 )
goto LABEL_14;
v4 = 3;
__printf_chk();
__printf_chk();
__printf_chk();
func12(a1[5]);
__printf_chk();
LABEL_7:
v5 = a2 - v4;
__printf_chk();
__printf_chk();
result = v4 + 1;
v6 = (_DWORD)a1 + (unsigned __int8)(v4 + 1);
v7 = 0;
v8 = (unsigned __int8)(v4 + 2) - v6;
while ( v5 != ++v7 )
{
__printf_chk();
result = v7 & 3;
if ( (v7 & 3) == 3 )
{
result = v8 + v6;
if ( a2 > v8 + v6 )
result = putchar(32);
}
++v6;
}
return result;
}

original_code:
void process_msg_payload(struct report *r, u8 data_len) {
 u8 pos, i;
 u8 * bytes = (u8 *) &r->s;
 pos = 0;
 if (report_type_is_hidpp(r->report_id))
 switch (r->sub_id) {
 case 0x00:
  if (data_len == 4 || data_len == 17) {
   printf("func=%X  ", bytes[0] >> 4);
   printf("swId=%X  ", bytes[0] & 0xF);
   pos = 1;
  }
  break;
 case 0xFF:
  if (data_len == 17) {
   printf("feat=%X  ", bytes[0]);
   printf("func=%X  ", bytes[1] >> 4);
   printf("swId=%X  ", bytes[1] & 0xF);
   printf("err=%02X %s  ", bytes[2], error_str_hidpp20(bytes[2]));
   pos = 3;
  }
  break;
 case 0x8F:
  printf("SubID=%02X %s  ", bytes[0], report_type_str(r->report_id, bytes[0]));
  printf("reg=%02X %s  ", bytes[1], register_str(bytes[1]));
  printf("err=%02X %s  ", bytes[2], error_str(bytes[2]));
  pos = 4;
  break;
 case 0x80:
 case 0x81:
 case 0x82:
 case 0x83:
  printf("reg=%02X %s  ", bytes[0], register_str(bytes[0]));
  pos = 1;
  break;
 }
 if (pos < data_len) {
  printf("params=");
 }
 for (i = 0; pos < data_len; pos++, i++) {
  printf("%02X ", bytes[pos]);
  if (i % 4 == 3 && pos + 1 < data_len) {
   putchar(' ');
  }
 }
}

canonical_original_code:
void process_msg_payload(struct report *r, unsigned char data_len) {
 unsigned char pos; unsigned char i;
 unsigned char *bytes = (u8 *) &r->s;
 pos = 0;
 if (report_type_is_hidpp(r->report_id))
 switch (r->sub_id) {
 case 0x00:
  if (data_len == 4 || data_len == 17) {
   printf("func=%X  ", bytes[0] >> 4);
   printf("swId=%X  ", bytes[0] & 0xF);
   pos = 1;
  }
  break;
 case 0xFF:
  if (data_len == 17) {
   printf("feat=%X  ", bytes[0]);
   printf("func=%X  ", bytes[1] >> 4);
   printf("swId=%X  ", bytes[1] & 0xF);
   printf("err=%02X %s  ", bytes[2], error_str_hidpp20(bytes[2]));
   pos = 3;
  }
  break;
 case 0x8F:
  printf("SubID=%02X %s  ", bytes[0], report_type_str(r->report_id, bytes[0]));
  printf("reg=%02X %s  ", bytes[1], register_str(bytes[1]));
  printf("err=%02X %s  ", bytes[2], error_str(bytes[2]));
  pos = 4;
  break;
 case 0x80:
 case 0x81:
 case 0x82:
 case 0x83:
  printf("reg=%02X %s  ", bytes[0], register_str(bytes[0]));
  pos = 1;
  break;
 }
 if (pos < data_len) {
  printf("params=");
 }
 for (i = 0; pos < data_len; pos++, i++) {
  printf("%02X ", bytes[pos]);
  if (i % 4 == 3 && pos + 1 < data_len) {
   putchar(' ');
  }
 }
}

variable_types: struct report { unsigned char report_id; unsigned char device_index; unsigned char sub_id; union { struct payload_long { unsigned char address; unsigned char str[16]; } l; struct payload_short { unsigned char address; unsigned char value[3]; } s; }; } *

variable_types:
pos
unsigned char

variable_types:
i
unsigned char

variable_types:
bytes
unsigned char *

user_defined_types: struct report { unsigned char report_id; unsigned char device_index; unsigned char sub_id; union { struct payload_long l; struct payload_short s; }; }


decompiled_code:
int __fastcall process_msg(__int64 a1, __int64 a2)
{
char v2; // dl
int result; // eax

v2 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 32 )
{
if ( a2 == 15 )
goto LABEL_6;
return __fprintf_chk();
}
if ( (unsigned __int8)v2 > 0x20u )
{
if ( v2 != 33 )
goto LABEL_14;
if ( a2 == 32 )
goto LABEL_6;
return __fprintf_chk();
}
if ( v2 == 16 )
{
if ( a2 == 7 )
goto LABEL_6;
return __fprintf_chk();
}
if ( v2 == 17 )
{
if ( a2 == 20 )
{
LABEL_6:
__printf_chk();
device_type_str(*(_BYTE *)(a1 + 1));
__printf_chk();
report_type_str(*(_BYTE *)a1, *(_BYTE *)(a1 + 2));
__printf_chk();
LABEL_7:
process_msg_payload((char *)a1, a2 - 3);
return putchar(10);
}
return __fprintf_chk();
}
LABEL_14:
if ( a2 > 2 )
{
__printf_chk();
device_type_str(*(_BYTE *)(a1 + 1));
__printf_chk();
report_type_str(*(_BYTE *)a1, *(_BYTE *)(a1 + 2));
__printf_chk();
if ( a2 == 3 )
return putchar(10);
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, __int64 a2)
{
char v2; // dl
int result; // eax

v2 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 32 )
{
if ( a2 == 15 )
goto LABEL_6;
return __fprintf_chk();
}
if ( (unsigned __int8)v2 > 0x20u )
{
if ( v2 != 33 )
goto LABEL_14;
if ( a2 == 32 )
goto LABEL_6;
return __fprintf_chk();
}
if ( v2 == 16 )
{
if ( a2 == 7 )
goto LABEL_6;
return __fprintf_chk();
}
if ( v2 == 17 )
{
if ( a2 == 20 )
{
LABEL_6:
__printf_chk();
func10(*(_BYTE *)(a1 + 1));
__printf_chk();
func9(*(_BYTE *)a1, *(_BYTE *)(a1 + 2));
__printf_chk();
LABEL_7:
func14((char *)a1, a2 - 3);
return putchar(10);
}
return __fprintf_chk();
}
LABEL_14:
if ( a2 > 2 )
{
__printf_chk();
func10(*(_BYTE *)(a1 + 1));
__printf_chk();
func9(*(_BYTE *)a1, *(_BYTE *)(a1 + 2));
__printf_chk();
if ( a2 == 3 )
return putchar(10);
goto LABEL_7;
}
return result;
}

original_code:
void process_msg(struct report *report, ssize_t size) {
 const char * report_type;
 switch (report->report_id) {
 case 0x10:
  report_type = "short";
  if (size != 7) {
   fprintf(stderr, "Invalid short msg len %zi\n", size);
   return;
  }
  break;
 case 0x11:
  report_type = "long";
  if (size != 20) {
   fprintf(stderr, "Invalid long msg len %zi\n", size);
   return;
  }
  break;
 case 0x20:
  report_type = "dj_s";
  if (size != 15) {
   fprintf(stderr, "Invalid DJ short msg len %zi\n", size);
   return;
  }
  break;
 case 0x21:
  report_type = "dj_l";
  if (size != 32) {
   fprintf(stderr, "Invalid DJ long msg len %zi\n", size);
   return;
  }
  break;
 default:
  report_type = "unkn";
  if (size < 3) {
   return;
  }
  break;
 }
 printf("report_id=%02X %-5s ", report->report_id, report_type);
 printf("device=%02X %-4s ", report->device_index,
   device_type_str(report->device_index));
 printf("type=%02X %-23s ", report->sub_id,
   report_type_str(report->report_id, report->sub_id));
 if (size > 3) {
  process_msg_payload(report, size - 3);
 }
 putchar('\n');
}

canonical_original_code:
void process_msg(struct report *report, long size) {
 char *report_type;
 switch (report->report_id) {
 case 0x10:
  report_type = "short";
  if (size != 7) {
   fprintf(stderr, "Invalid short msg len %zi\n", size);
   return;
  }
  break;
 case 0x11:
  report_type = "long";
  if (size != 20) {
   fprintf(stderr, "Invalid long msg len %zi\n", size);
   return;
  }
  break;
 case 0x20:
  report_type = "dj_s";
  if (size != 15) {
   fprintf(stderr, "Invalid DJ short msg len %zi\n", size);
   return;
  }
  break;
 case 0x21:
  report_type = "dj_l";
  if (size != 32) {
   fprintf(stderr, "Invalid DJ long msg len %zi\n", size);
   return;
  }
  break;
 default:
  report_type = "unkn";
  if (size < 3) {
   return;
  }
  break;
 }
 printf("report_id=%02X %-5s ", report->report_id, report_type);
 printf("device=%02X %-4s ", report->device_index,
   device_type_str(report->device_index));
 printf("type=%02X %-23s ", report->sub_id,
   report_type_str(report->report_id, report->sub_id));
 if (size > 3) {
  process_msg_payload(report, size - 3);
 }
 putchar('\n');
}

variable_types: size long

user_defined_types: struct payload_long { unsigned char address; unsigned char str[16]; }

user_defined_types: struct payload_short { unsigned char address; unsigned char value[3]; }


decompiled_code:
void print_time()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v0, 0LL) )
{
perror("gettimeofday");
}
else
{
localtime(&v0.tv_sec);
__printf_chk();
}
}

canonical_decompiled_code:
void func16()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v0, 0LL) )
{
perror("gettimeofday");
}
else
{
localtime(&v0.tv_sec);
__printf_chk();
}
}

original_code:
void print_time(void) {
 struct timeval tval;
 struct tm *tm;
 if (gettimeofday(&tval, ((void *)0))) {
  perror("gettimeofday");
  return;
 }
 tm = localtime(&tval.tv_sec);
 printf("%02d:%02d:%02d.%03ld ",
  tm->tm_hour, tm->tm_min, tm->tm_sec,
  tval.tv_usec / 1000);
}

canonical_original_code:
void print_time() {
 struct timeval tval;
 struct tm *tm;
 if (gettimeofday(&tval, ((void *)0))) {
  perror("gettimeofday");
  return;
 }
 tm = localtime(&tval.tv_sec);
 printf("%02d:%02d:%02d.%03ld ",
  tm->tm_hour, tm->tm_min, tm->tm_sec,
  tval.tv_usec / 1000);
}

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

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *