ccomp

decompiled_code:
__int64 __fastcall ccomp(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
static int ccomp(const void *v1, const void *v2)
{
 const LIBNCACHE *a1,*a2;
 a1=v1; a2=v2;
 return(a1->num - a2->num);
}

canonical_original_code:
static int ccomp(void *v1, void *v2)
{
 struct LIBNCACHE *a1; struct LIBNCACHE *a2;
 a1=v1; a2=v2;
 return(a1->num - a2->num);
}

variable_types: struct LIBNCACHE { int num; char *value; } *


FreeTags

decompiled_code:
void __fastcall FreeTags(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

original_code:
static void FreeTags(PSFTAG *tags)
{
 while(tags)
 {
  PSFTAG *tmp=tags->next;
  free(tags->key);
  free(tags->value);
  free(tags);
  tags=tmp;
 }
}

canonical_original_code:
static void FreeTags(struct __PSFTAG *tags)
{
 while(tags)
 {
  struct __PSFTAG *tmp = tags->next;
  free(tags->key);
  free(tags->value);
  free(tags);
  tags=tmp;
 }
}

variable_types: struct __PSFTAG { char *key; char *value; struct __PSFTAG *next; } *

return_type: void


TimeToMS

variable_types:
str
char *

variable_types: x int

variable_types: c int

variable_types: acc int

variable_types:
s
char [100]

return_type: long


GetFileWithBase

decompiled_code:
__int64 __fastcall GetFileWithBase(void *src, char *a2)
{
char *v2; // rax
size_t v3; // rbx
size_t v4; // rax
void *v5; // rbp
size_t v7; // rax

v2 = strrchr((const char *)src, 47);
if ( v2 )
{
v3 = v2 - (_BYTE *)src;
v4 = strlen(a2);
v5 = malloc(v3 + v4 + 2);
ret_1 = (__int64)v5;
memcpy(v5, src, v3);
*((_BYTE *)v5 + v3) = 47;
*((_BYTE *)v5 + v3 + 1) = 0;
strcat((char *)v5, a2);
}
else
{
v7 = strlen(a2);
ret_1 = (__int64)malloc(v7 + 1);
strcpy((char *)ret_1, a2);
}
return ret_1;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *src, char *a2)
{
char *v2; // rax
size_t v3; // rbx
size_t v4; // rax
void *v5; // rbp
size_t v7; // rax

v2 = strrchr((const char *)src, 47);
if ( v2 )
{
v3 = v2 - (_BYTE *)src;
v4 = strlen(a2);
v5 = malloc(v3 + v4 + 2);
ret_1 = (__int64)v5;
memcpy(v5, src, v3);
*((_BYTE *)v5 + v3) = 47;
*((_BYTE *)v5 + v3 + 1) = 0;
strcat((char *)v5, a2);
}
else
{
v7 = strlen(a2);
ret_1 = (__int64)malloc(v7 + 1);
strcpy((char *)ret_1, a2);
}
return ret_1;
}

original_code:
char *GetFileWithBase(const char *f, const char *newfile)
{
  static char *ret;
  char *tp1;
     tp1=((char *)strrchr(f,'/'));
     if(!tp1)
     {
      ret=malloc(strlen(newfile)+1);
      strcpy(ret,newfile);
     }
     else
     {
      ret=malloc(tp1-f+2+strlen(newfile));
      memcpy(ret,f,tp1-f);
      ret[tp1-f]='/';
      ret[tp1-f+1]=0;
      strcat(ret,newfile);
     }
    return(ret);
}

canonical_original_code:
char *GetFileWithBase(char *f, char *newfile)
{
  static char *ret;
  char *tp1;
     tp1=((char *)strrchr(f,'/'));
     if(!tp1)
     {
      ret=malloc(strlen(newfile)+1);
      strcpy(ret,newfile);
     }
     else
     {
      ret=malloc(tp1-f+2+strlen(newfile));
      memcpy(ret,f,tp1-f);
      ret[tp1-f]='/';
      ret[tp1-f+1]=0;
      strcat(ret,newfile);
     }
    return(ret);
}

variable_types:
f
char *

variable_types:
newfile
char *

variable_types:
ret
char *

return_type: char *


decompiled_code:
void __fastcall sexy_freepsfinfo(void *ptr)
{
FreeTags(*((void **)ptr + 10));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
func2(*((void **)ptr + 10));
free(ptr);
}

original_code:
void sexy_freepsfinfo(PSFINFO *info)
{
 FreeTags(info->tags);
 free(info);
}

canonical_original_code:
void sexy_freepsfinfo(struct PSFINFO *info)
{
 FreeTags(info->tags);
 free(info);
}

variable_types: struct PSFINFO { unsigned int length; unsigned int stop; unsigned int fade; char *title; struct __PSFTAG { char *key; char *value; struct __PSFTAG *next; } *tags; } *

user_defined_types: struct PSFINFO { unsigned int length; unsigned int stop; unsigned int fade; char *title; struct __PSFTAG *tags; }


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 v4; // ebp
unsigned int v6; // er14
__int64 v7; // rax
void *v8; // rdi
int v9; // edx

if ( a2 > 0 )
{
v4 = a2;
do
{
if ( (_WORD)a1 )
{
v6 = 0x10000 - (unsigned __int16)a1;
if ( v6 > v4 )
v6 = v4;
v7 = *(_QWORD *)(psxMemLUT + 8LL * HIWORD(a1));
if ( v7 )
memcpy((void *)(v7 + (unsigned __int16)a1), a3, v6);
a1 += v6;
a3 += v6;
v4 -= v6;
}
else
{
v8 = *(void **)(psxMemLUT + 8LL * HIWORD(a1));
if ( v8 )
{
v9 = 0x10000;
if ( v4 <= 0x10000 )
v9 = v4;
memcpy(v8, a3, v9);
}
a3 += 0x10000;
a1 += 0x10000;
v4 -= 0x10000;
}
}
while ( v4 > 0 );
}
}

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


psxMemInit

decompiled_code:
__int64 psxMemInit()
{
void *v0; // r12
void *v1; // rbp
void *v2; // rbx
void *v3; // rax
__int64 i; // rdx
_QWORD *v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rdx
__int64 result; // rax

writeok = 1;
psxMemLUT = malloc(0x80000uLL);
memset(psxMemLUT, 0, 0x80000uLL);
v0 = malloc(0x200000uLL);
psxM = v0;
v1 = malloc(0x10000uLL);
psxP = v1;
v2 = malloc(0x10000uLL);
psxH = v2;
v3 = malloc(0x80000uLL);
psxR = v3;
if ( v2 == 0LL || v1 == 0LL || v0 == 0LL || !v3 )
{
printf("Error allocating memory");
result = 0xFFFFFFFFLL;
}
else
{
for ( i = 0LL; i != 1024; i += 8LL )
*(_QWORD *)((char *)psxMemLUT + i) = psxM + (((_DWORD)i << 13) & 0x1F0000);
v5 = psxMemLUT;
v6 = (__int64)psxMemLUT + 0x40000;
*((_QWORD *)psxMemLUT + 0x8000) = *(_QWORD *)psxMemLUT;
v5[32895] = v5[127];
qmemcpy(
(void *)((unsigned __int64)(v5 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v5 - (v6 - ((unsigned __int64)(v5 + 32769) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v6 - (((_DWORD)v5 + 262152) & 0xFFFFFFF8) + 1024) >> 3));
v5[40960] = *v5;
v5[41087] = v5[127];
qmemcpy(
(void *)((unsigned __int64)(v5 + 40961) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(((unsigned __int64)(v5 + 40961) & 0xFFFFFFFFFFFFFFF8LL) - 327680),
8LL * (((_DWORD)v5 + 327680 - (((_DWORD)v5 + 327688) & 0xFFFFFFF8) + 1024) >> 3));
v5[7936] = psxP;
*((_QWORD *)psxMemLUT + 8064) = psxH;
v7 = 392704LL;
v8 = 0LL;
do
{
*(_QWORD *)((char *)psxMemLUT + v7) = (unsigned int)(psxR + v8);
v8 += 0x10000LL;
v7 += 8LL;
}
while ( v7 != 392768 );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
void *v0; // r12
void *v1; // rbp
void *v2; // rbx
void *v3; // rax
__int64 i; // rdx
_QWORD *v5; // rax
__int64 v6; // rdx
__int64 v7; // rax
__int64 v8; // rdx
__int64 result; // rax

writeok = 1;
psxMemLUT = malloc(0x80000uLL);
memset(psxMemLUT, 0, 0x80000uLL);
v0 = malloc(0x200000uLL);
psxM = v0;
v1 = malloc(0x10000uLL);
psxP = v1;
v2 = malloc(0x10000uLL);
psxH = v2;
v3 = malloc(0x80000uLL);
psxR = v3;
if ( v2 == 0LL || v1 == 0LL || v0 == 0LL || !v3 )
{
printf("Error allocating memory");
result = 0xFFFFFFFFLL;
}
else
{
for ( i = 0LL; i != 1024; i += 8LL )
*(_QWORD *)((char *)psxMemLUT + i) = psxM + (((_DWORD)i << 13) & 0x1F0000);
v5 = psxMemLUT;
v6 = (__int64)psxMemLUT + 0x40000;
*((_QWORD *)psxMemLUT + 0x8000) = *(_QWORD *)psxMemLUT;
v5[32895] = v5[127];
qmemcpy(
(void *)((unsigned __int64)(v5 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v5 - (v6 - ((unsigned __int64)(v5 + 32769) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v6 - (((_DWORD)v5 + 262152) & 0xFFFFFFF8) + 1024) >> 3));
v5[40960] = *v5;
v5[41087] = v5[127];
qmemcpy(
(void *)((unsigned __int64)(v5 + 40961) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(((unsigned __int64)(v5 + 40961) & 0xFFFFFFFFFFFFFFF8LL) - 327680),
8LL * (((_DWORD)v5 + 327680 - (((_DWORD)v5 + 327688) & 0xFFFFFFF8) + 1024) >> 3));
v5[7936] = psxP;
*((_QWORD *)psxMemLUT + 8064) = psxH;
v7 = 392704LL;
v8 = 0LL;
do
{
*(_QWORD *)((char *)psxMemLUT + v7) = (unsigned int)(psxR + v8);
v8 += 0x10000LL;
v7 += 8LL;
}
while ( v7 != 392768 );
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((void *)psxR);
free(psxMemLUT);
}

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

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


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

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

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

if ( HIWORD(a1) == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead8();
else
result = *(unsigned __int8 *)(psxH + (unsigned __int16)a1);
}
else
{
v1 = *((_QWORD *)psxMemLUT + HIWORD(a1));
result = 0LL;
if ( v1 )
result = *(unsigned __int8 *)(v1 + (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; // rdx
__int64 result; // rax

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

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

if ( HIWORD(a1) == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead16();
else
result = func0(*(unsigned __int16 *)(psxH + (unsigned __int16)a1));
}
else
{
v1 = *((_QWORD *)psxMemLUT + HIWORD(a1));
result = 0LL;
if ( v1 )
result = func0(*(unsigned __int16 *)(v1 + (unsigned __int16)a1));
}
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; // rdx
__int64 result; // rax

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

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

if ( HIWORD(a1) == 8064 )
{
if ( a1 > 0x1F800FFF )
result = psxHwRead32();
else
result = func1(*(_DWORD *)(psxH + (unsigned __int16)a1));
}
else
{
v1 = *((_QWORD *)psxMemLUT + HIWORD(a1));
result = 0LL;
if ( v1 )
result = func1(*(_DWORD *)(v1 + (unsigned __int16)a1));
}
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 result; // rax

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

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

if ( WORD1(a1) == 8064 )
{
if ( (unsigned int)a1 > 0x1F800FFF )
{
result = psxHwWrite8(a1, a2);
}
else
{
result = psxH;
*(_BYTE *)(psxH + (unsigned __int16)a1) = a2;
}
}
else
{
result = *((_QWORD *)psxMemLUT + WORD1(a1));
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 result; // rax
_WORD *v3; // rbx
_WORD *v4; // rbx

if ( WORD1(a1) == 8064 )
{
if ( (unsigned int)a1 > 0x1F800FFF )
{
result = psxHwWrite16(a1, a2);
}
else
{
v4 = (_WORD *)(psxH + (unsigned __int16)a1);
result = BFLIP16(a2);
*v4 = result;
}
}
else
{
result = *((_QWORD *)psxMemLUT + WORD1(a1));
if ( result )
{
v3 = (_WORD *)(result + (unsigned __int16)a1);
result = BFLIP16(a2);
*v3 = result;
}
}
return result;
}

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

if ( WORD1(a1) == 8064 )
{
if ( (unsigned int)a1 > 0x1F800FFF )
{
result = psxHwWrite16(a1, a2);
}
else
{
v4 = (_WORD *)(psxH + (unsigned __int16)a1);
result = func0(a2);
*v4 = result;
}
}
else
{
result = *((_QWORD *)psxMemLUT + WORD1(a1));
if ( result )
{
v3 = (_WORD *)(result + (unsigned __int16)a1);
result = func0(a2);
*v3 = 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)
{
_QWORD *v2; // rdx
__int64 result; // rax
_DWORD *v4; // rbx
_DWORD *v5; // rbx
_QWORD *v6; // rdx
__int64 i; // rdx
char *v8; // rax
char *v9; // rdx
char *v10; // rdi

if ( HIWORD(a1) == 8064 )
{
if ( a1 > 0x1F800FFF )
{
result = psxHwWrite32();
}
else
{
v5 = (_DWORD *)(psxH + (unsigned __int16)a1);
result = BFLIP32(a2);
*v5 = result;
}
}
else
{
v2 = psxMemLUT;
result = *((_QWORD *)psxMemLUT + HIWORD(a1));
if ( result )
{
v4 = (_DWORD *)(result + (unsigned __int16)a1);
result = BFLIP32(a2);
*v4 = result;
return result;
}
if ( a1 == -130768 )
{
if ( a2 == 2052 )
{
LABEL_12:
if ( writeok )
{
writeok = 0;
result = 0LL;
*(_QWORD *)psxMemLUT = 0LL;
v2[127] = 0LL;
memset(
(void *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 1024) >> 3));
v6 = psxMemLUT;
*((_QWORD *)psxMemLUT + 0x8000) = 0LL;
v6[32895] = 0LL;
memset(
(void *)((unsigned __int64)(v6 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 262152) & 0xFFFFFFF8) + 263168) >> 3));
v6[40960] = 0LL;
v6[41087] = 0LL;
memset(
(void *)((unsigned __int64)(v6 + 40961) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 327688) & 0xFFFFFFF8) + 328704) >> 3));
}
return result;
}
if ( a2 != 125320 )
{
if ( a2 != 2048 )
return result;
goto LABEL_12;
}
if ( writeok != 1 )
{
writeok = 1;
for ( i = 0LL; i != 1024; i += 8LL )
*(_QWORD *)((char *)psxMemLUT + i) = psxM + (((_DWORD)i << 13) & 0x1F0000);
v8 = (char *)psxMemLUT;
v9 = (char *)psxMemLUT + 0x40000;
*((_QWORD *)psxMemLUT + 0x8000) = *(_QWORD *)psxMemLUT;
*((_QWORD *)v8 + 32895) = *((_QWORD *)v8 + 127);
qmemcpy(
(void *)((unsigned __int64)(v8 + 262152) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v8 - &v9[-((unsigned __int64)(v8 + 262152) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((unsigned int)v9 - (((_DWORD)v8 + 262152) & 0xFFFFFFF8) + 1024) >> 3));
*((_QWORD *)v8 + 40960) = *(_QWORD *)v8;
*((_QWORD *)v8 + 41087) = *((_QWORD *)v8 + 127);
v10 = (char *)((unsigned __int64)(v8 + 327688) & 0xFFFFFFFFFFFFFFF8LL);
LODWORD(v9) = (_DWORD)v8 + 327680 - (_DWORD)v10;
result = (__int64)(v10 - 327680);
qmemcpy(v10, v10 - 327680, 8LL * ((unsigned int)((_DWORD)v9 + 1024) >> 3));
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, unsigned int a2)
{
_QWORD *v2; // rdx
__int64 result; // rax
_DWORD *v4; // rbx
_DWORD *v5; // rbx
_QWORD *v6; // rdx
__int64 i; // rdx
char *v8; // rax
char *v9; // rdx
char *v10; // rdi

if ( HIWORD(a1) == 8064 )
{
if ( a1 > 0x1F800FFF )
{
result = psxHwWrite32();
}
else
{
v5 = (_DWORD *)(psxH + (unsigned __int16)a1);
result = func1(a2);
*v5 = result;
}
}
else
{
v2 = psxMemLUT;
result = *((_QWORD *)psxMemLUT + HIWORD(a1));
if ( result )
{
v4 = (_DWORD *)(result + (unsigned __int16)a1);
result = func1(a2);
*v4 = result;
return result;
}
if ( a1 == -130768 )
{
if ( a2 == 2052 )
{
LABEL_12:
if ( writeok )
{
writeok = 0;
result = 0LL;
*(_QWORD *)psxMemLUT = 0LL;
v2[127] = 0LL;
memset(
(void *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 1024) >> 3));
v6 = psxMemLUT;
*((_QWORD *)psxMemLUT + 0x8000) = 0LL;
v6[32895] = 0LL;
memset(
(void *)((unsigned __int64)(v6 + 32769) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 262152) & 0xFFFFFFF8) + 263168) >> 3));
v6[40960] = 0LL;
v6[41087] = 0LL;
memset(
(void *)((unsigned __int64)(v6 + 40961) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 327688) & 0xFFFFFFF8) + 328704) >> 3));
}
return result;
}
if ( a2 != 125320 )
{
if ( a2 != 2048 )
return result;
goto LABEL_12;
}
if ( writeok != 1 )
{
writeok = 1;
for ( i = 0LL; i != 1024; i += 8LL )
*(_QWORD *)((char *)psxMemLUT + i) = psxM + (((_DWORD)i << 13) & 0x1F0000);
v8 = (char *)psxMemLUT;
v9 = (char *)psxMemLUT + 0x40000;
*((_QWORD *)psxMemLUT + 0x8000) = *(_QWORD *)psxMemLUT;
*((_QWORD *)v8 + 32895) = *((_QWORD *)v8 + 127);
qmemcpy(
(void *)((unsigned __int64)(v8 + 262152) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v8 - &v9[-((unsigned __int64)(v8 + 262152) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * (((unsigned int)v9 - (((_DWORD)v8 + 262152) & 0xFFFFFFF8) + 1024) >> 3));
*((_QWORD *)v8 + 40960) = *(_QWORD *)v8;
*((_QWORD *)v8 + 41087) = *((_QWORD *)v8 + 127);
v10 = (char *)((unsigned __int64)(v8 + 327688) & 0xFFFFFFFFFFFFFFF8LL);
LODWORD(v9) = (_DWORD)v8 + 327680 - (_DWORD)v10;
result = (__int64)(v10 - 327680);
qmemcpy(v10, v10 - 327680, 8LL * ((unsigned int)((_DWORD)v9 + 1024) >> 3));
}
}
}
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; // ebx
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;
v3 = 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");
v5[0] = 16;
if ( ioctl(v1, 0xC0045005uLL, v5) == -1 )
return puts("Sound format not supported!");
if ( v5[0] != 16 )
return puts("Sound format not supported!");
if ( ioctl(v1, 0xC0045003uLL, &v3) == -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; // ebx
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;
v3 = 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");
v5[0] = 16;
if ( ioctl(v1, 0xC0045005uLL, v5) == -1 )
return puts("Sound format not supported!");
if ( v5[0] != 16 )
return puts("Sound format not supported!");
if ( ioctl(v1, 0xC0045003uLL, &v3) == -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:
int __fastcall sexyd_update(void *buf, size_t n)
{
int result; // eax
int v3; // eax
char v4[268]; // [rsp+0h] [rbp-118h] BYREF
int v5[3]; // [rsp+10Ch] [rbp-Ch] BYREF

result = oss_audio_fd;
if ( oss_audio_fd != -1 )
{
write(oss_audio_fd, buf, n);
v3 = fileno(stdin);
result = ioctl(v3, 0x541BuLL, v5);
if ( !result )
{
if ( v5[0] )
{
result = (unsigned int)fgets(v4, 256, stdin);
if ( v4[0] == 113 )
result = sexy_stop();
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(void *buf, size_t n)
{
int result; // eax
int v3; // eax
char v4[268]; // [rsp+0h] [rbp-118h] BYREF
int v5[3]; // [rsp+10Ch] [rbp-Ch] BYREF

result = oss_audio_fd;
if ( oss_audio_fd != -1 )
{
write(oss_audio_fd, buf, n);
v3 = fileno(stdin);
result = ioctl(v3, 0x541BuLL, v5);
if ( !result )
{
if ( v5[0] )
{
result = (unsigned int)fgets(v4, 256, stdin);
if ( v4[0] == 113 )
result = sexy_stop();
}
}
}
return result;
}

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:
int *__fastcall psxDma6(unsigned int a1, int a2, int a3)
{
int *v3; // rcx
int *result; // rax
unsigned int v5; // er8
int v6; // edi

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

canonical_decompiled_code:
int *__fastcall func1(unsigned int a1, int a2, int a3)
{
int *v3; // rcx
int *result; // rax
unsigned int v5; // er8
int v6; // edi

v3 = *(int **)(psxMemLUT + 8LL * HIWORD(a1));
result = (int *)((char *)v3 + (unsigned __int16)a1);
if ( v3 )
v3 = (int *)((char *)v3 + (unsigned __int16)a1);
if ( a3 == 285212674 )
{
v5 = a2 - 1;
if ( a2 )
{
result = v3;
v6 = a1 - 4 - (_DWORD)v3;
do
{
*result = (v6 + (_DWORD)result) & 0xFFFFFF;
--result;
}
while ( result != &v3[-v5 - 1] );
v3 += ~(unsigned __int64)v5;
}
v3[1] = 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;
}

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

variable_types:
x
unsigned short


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

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

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 v2; // rbx
__int16 v3; // ax
__int64 result; // rax
_WORD *v5; // rbx

if ( (_DWORD)a1 == 528486512 )
{
v2 = psxH;
v3 = BFLIP16(*(unsigned __int16 *)(psxH + 4212LL));
result = BFLIP16((unsigned __int16)(a2 & v3));
*(_WORD *)(v2 + 4208) &= result;
}
else if ( (unsigned int)(a1 - 528489472) <= 0x1FF )
{
result = SPUwriteRegister(a1, a2);
}
else
{
v5 = (_WORD *)(psxH + (unsigned __int16)a1);
result = BFLIP16(a2);
*v5 = result;
}
return result;
}

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

if ( (_DWORD)a1 == 528486512 )
{
v2 = psxH;
v3 = func0(*(unsigned __int16 *)(psxH + 4212LL));
result = func0((unsigned __int16)(a2 & v3));
*(_WORD *)(v2 + 4208) &= result;
}
else if ( (unsigned int)(a1 - 528489472) <= 0x1FF )
{
result = SPUwriteRegister(a1, a2);
}
else
{
v5 = (_WORD *)(psxH + (unsigned __int16)a1);
result = func0(a2);
*v5 = result;
}
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; // r12
unsigned int v3; // eax
__int64 result; // rax
unsigned int v5; // ebx
unsigned int v6; // ebp
unsigned int v7; // eax
int v8; // eax
__int64 v9; // rbx
unsigned int v10; // ebp
__int64 v11; // rbx
int v12; // eax
__int64 v13; // rbx
int v14; // eax
_DWORD *v15; // rbx

if ( a1 > 0x1F801128 )
goto LABEL_22;
if ( a1 > 0x1F8010F3 )
{
switch ( a1 )
{
case 0x1F8010F4u:
v13 = psxH;
v14 = BFLIP32(*(_DWORD *)(psxH + 4340LL));
result = BFLIP32(~(_DWORD)a2 & v14 ^ (a2 | v14) & 0xFFFFFF);
*(_DWORD *)(v13 + 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_22;
}
return result;
}
if ( a1 == 528486512 )
{
v11 = psxH;
v12 = BFLIP32(*(_DWORD *)(psxH + 4212LL));
result = BFLIP32((unsigned int)a2 & v12);
*(_DWORD *)(v11 + 4208) &= result;
return result;
}
if ( a1 != 528486600 )
{
LABEL_22:
v15 = (_DWORD *)(psxH + (unsigned __int16)a1);
result = BFLIP32(a2);
*v15 = result;
return result;
}
v2 = (unsigned int *)psxH;
v3 = BFLIP32(a2);
v2[1074] = v3;
result = BFLIP32(v3);
v5 = result;
if ( (result & 0x1000000) != 0 )
{
result = BFLIP32(v2[1084]);
if ( (result & 0x80000) != 0 )
{
v6 = BFLIP32(v2[1073]);
v7 = BFLIP32(v2[1072]);
psxDma4(v7, v6, v5);
v8 = BFLIP32(0xFEFFFFFF);
v9 = psxH;
*(_DWORD *)(psxH + 4296LL) &= v8;
v10 = *(_DWORD *)(v9 + 4340);
result = BFLIP32(v10);
if ( (result & 0x100000) != 0 )
{
*(_DWORD *)(v9 + 4340) = BFLIP32(0x10000000u) | v10;
result = BFLIP32(8u);
*(_DWORD *)(v9 + 4208) |= result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2)
{
unsigned int *v2; // r12
unsigned int v3; // eax
__int64 result; // rax
unsigned int v5; // ebx
unsigned int v6; // ebp
unsigned int v7; // eax
int v8; // eax
__int64 v9; // rbx
unsigned int v10; // ebp
__int64 v11; // rbx
int v12; // eax
__int64 v13; // rbx
int v14; // eax
_DWORD *v15; // rbx

if ( a1 > 0x1F801128 )
goto LABEL_22;
if ( a1 > 0x1F8010F3 )
{
switch ( a1 )
{
case 0x1F8010F4u:
v13 = psxH;
v14 = func1(*(_DWORD *)(psxH + 4340LL));
result = func1(~(_DWORD)a2 & v14 ^ (a2 | v14) & 0xFFFFFF);
*(_DWORD *)(v13 + 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_22;
}
return result;
}
if ( a1 == 528486512 )
{
v11 = psxH;
v12 = func1(*(_DWORD *)(psxH + 4212LL));
result = func1((unsigned int)a2 & v12);
*(_DWORD *)(v11 + 4208) &= result;
return result;
}
if ( a1 != 528486600 )
{
LABEL_22:
v15 = (_DWORD *)(psxH + (unsigned __int16)a1);
result = func1(a2);
*v15 = result;
return result;
}
v2 = (unsigned int *)psxH;
v3 = func1(a2);
v2[1074] = v3;
result = func1(v3);
v5 = result;
if ( (result & 0x1000000) != 0 )
{
result = func1(v2[1084]);
if ( (result & 0x80000) != 0 )
{
v6 = func1(v2[1073]);
v7 = func1(v2[1072]);
psxDma4(v7, v6, v5);
v8 = func1(0xFEFFFFFF);
v9 = psxH;
*(_DWORD *)(psxH + 4296LL) &= v8;
v10 = *(_DWORD *)(v9 + 4340);
result = func1(v10);
if ( (result & 0x100000) != 0 )
{
*(_DWORD *)(v9 + 4340) = func1(0x10000000u) | v10;
result = func1(8u);
*(_DWORD *)(v9 + 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;
result = psxMemInit();
if ( (_DWORD)result != -1 )
result = ((__int64 (*)(void))*psxCpu)();
return result;
}

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

psxCpu = &psxInt;
result = psxMemInit();
if ( (_DWORD)result != -1 )
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 + 66) = -1077936128;
*((_DWORD *)&psxRegs + 46) = 277872640;
*((_DWORD *)&psxRegs + 49) = 2;
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 + 66) = -1077936128;
*((_DWORD *)&psxRegs + 46) = 277872640;
*((_DWORD *)&psxRegs + 49) = 2;
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

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

psxRegs[47] = a1;
if ( a2 )
{
psxRegs[47] = a1 | 0x80000000;
psxRegs[48] = psxRegs[66] - 4;
}
else
{
psxRegs[48] = psxRegs[66];
}
v2 = psxRegs[46];
psxRegs[66] = (v2 & 0x400000) == 0 ? -2147483520 : -1077935744;
psxRegs[46] = v2 & 0xFFFFFFC0 | (4 * (_BYTE)v2) & 0x3C;
return psxBiosException();
}

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:
_DWORD *psxExecuteBios()
{
_DWORD *result; // rax

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

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

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

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


SPUirq

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

v0 = BFLIP32(0x200u);
result = psxH;
*(_DWORD *)(psxH + 4208LL) |= v0;
return result;
}

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

v0 = func0(0x200u);
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
const char **v2; // rbx
char *result; // rax

v1 = skip_task_list;
if ( !skip_task_list )
return 0LL;
v2 = (const char **)&skip_task_list;
while ( 1 )
{
result = strstr(haystack, v1);
if ( result )
break;
v1 = *++v2;
if ( !*v2 )
return result;
}
return (_BYTE *)(skip_task + 1);
}

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

v1 = skip_task_list;
if ( !skip_task_list )
return 0LL;
v2 = (const char **)&skip_task_list;
while ( 1 )
{
result = strstr(haystack, v1);
if ( result )
break;
v1 = *++v2;
if ( !*v2 )
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; // rdx
_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; // rdx
_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()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = task_list;
if ( task_list )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[33];
free(v1);
task_list = v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func4()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = task_list;
if ( task_list )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[33];
free(v1);
task_list = v0;
}
while ( v0 );
}
}

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:
__m128i __fastcall lkp_getavgvalue(const char *a1, const char *a2, const char *a3)
{
int v3; // eax
unsigned int v4; // ebx
int v5; // ecx
float *v6; // rax
__m128i v7; // xmm0
void *ptr; // [rsp+8h] [rbp-10h] BYREF

v3 = lkp_getvalue(a1, a2, a3, (float **)&ptr);
v4 = LC8;
if ( v3 )
{
v5 = v3;
if ( v3 <= 0 )
{
v7 = 0LL;
}
else
{
v6 = (float *)ptr;
v7 = 0LL;
do
*(float *)v7.m128i_i32 = *(float *)v7.m128i_i32 + *v6++;
while ( v6 != (float *)((char *)ptr + 4 * (unsigned int)(v5 - 1) + 4) );
}
*(float *)v7.m128i_i32 = *(float *)v7.m128i_i32 / (float)v5;
v4 = _mm_cvtsi128_si32(v7);
free(ptr);
}
return _mm_cvtsi32_si128(v4);
}

canonical_decompiled_code:
__m128i __fastcall func8(const char *a1, const char *a2, const char *a3)
{
int v3; // eax
unsigned int v4; // ebx
int v5; // ecx
float *v6; // rax
__m128i v7; // xmm0
void *ptr; // [rsp+8h] [rbp-10h] BYREF

v3 = func7(a1, a2, a3, (float **)&ptr);
v4 = LC8;
if ( v3 )
{
v5 = v3;
if ( v3 <= 0 )
{
v7 = 0LL;
}
else
{
v6 = (float *)ptr;
v7 = 0LL;
do
*(float *)v7.m128i_i32 = *(float *)v7.m128i_i32 + *v6++;
while ( v6 != (float *)((char *)ptr + 4 * (unsigned int)(v5 - 1) + 4) );
}
*(float *)v7.m128i_i32 = *(float *)v7.m128i_i32 / (float)v5;
v4 = _mm_cvtsi128_si32(v7);
free(ptr);
}
return _mm_cvtsi32_si128(v4);
}

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(const char *a1, const char *a2)
{
const char **v2; // r13
const char *v3; // rbp
char *v4; // rax
__int64 v5; // r12
float v6; // xmm0_4
float v7; // [rsp+0h] [rbp-40h]
float v8; // [rsp+4h] [rbp-3Ch]

if ( host_list[0] )
{
v2 = (const char **)host_list;
do
{
v3 = (const char *)task_list;
if ( task_list )
{
do
{
v7 = *(float *)lkp_getavgvalue(*v2, v3, a1).m128i_i32;
LODWORD(v8) = lkp_getavgvalue(*v2, v3, a2).m128i_u32[0];
if ( v7 < 0.0 || v8 < 0.0 )
{
v3 = (const char *)*((_QWORD *)v3 + 33);
}
else
{
v4 = (char *)malloc(0x1C0uLL);
v5 = (__int64)v4;
if ( v4 )
{
strcpy(v4, *v2);
strcpy((char *)(v5 + 56), v3);
strcpy((char *)(v5 + 312), a1);
strcpy((char *)(v5 + 368), a2);
*(float *)(v5 + 424) = v7;
*(float *)(v5 + 428) = v8;
v6 = (float)(v8 - v7) / v7;
*(float *)(v5 + 432) = v6;
if ( *((_DWORD *)v3 + 64) )
*(_DWORD *)(v5 + 432) = LODWORD(v6) ^ LC9;
lkp_linkdata(v5);
v3 = (const char *)*((_QWORD *)v3 + 33);
}
else
{
v3 = (const char *)*((_QWORD *)v3 + 33);
}
}
}
while ( v3 );
}
++v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func11(const char *a1, const char *a2)
{
const char **v2; // r13
const char *v3; // rbp
char *v4; // rax
__int64 v5; // r12
float v6; // xmm0_4
float v7; // [rsp+0h] [rbp-40h]
float v8; // [rsp+4h] [rbp-3Ch]

if ( host_list[0] )
{
v2 = (const char **)host_list;
do
{
v3 = (const char *)task_list;
if ( task_list )
{
do
{
v7 = *(float *)func8(*v2, v3, a1).m128i_i32;
LODWORD(v8) = func8(*v2, v3, a2).m128i_u32[0];
if ( v7 < 0.0 || v8 < 0.0 )
{
v3 = (const char *)*((_QWORD *)v3 + 33);
}
else
{
v4 = (char *)malloc(0x1C0uLL);
v5 = (__int64)v4;
if ( v4 )
{
strcpy(v4, *v2);
strcpy((char *)(v5 + 56), v3);
strcpy((char *)(v5 + 312), a1);
strcpy((char *)(v5 + 368), a2);
*(float *)(v5 + 424) = v7;
*(float *)(v5 + 428) = v8;
v6 = (float)(v8 - v7) / v7;
*(float *)(v5 + 432) = v6;
if ( *((_DWORD *)v3 + 64) )
*(_DWORD *)(v5 + 432) = LODWORD(v6) ^ LC9;
func9(v5);
v3 = (const char *)*((_QWORD *)v3 + 33);
}
else
{
v3 = (const char *)*((_QWORD *)v3 + 33);
}
}
}
while ( v3 );
}
++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; // rbx

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; // rbx

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)
{
const char *v3; // rbp
const char *v4; // rbx

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 = argv[1];
v4 = 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)
{
const char *v3; // rbp
const char *v4; // rbx

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 = argv[1];
v4 = 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)
{
char *v3; // r13
char *v4; // rbx
int v5; // ebp
char v6; // di
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

while ( 1 )
{
if ( (int)read(0, v7, 0xFFuLL) < 0 )
exit(1);
if ( v7[0] == 10 || !v7[0] )
exit(0);
v3 = v7;
v4 = v7;
v5 = 0;
while ( 1 )
{
v6 = *v4;
if ( *v4 == 10 || !v6 )
break;
*v4 = caesar(v6);
++v5;
++v4;
if ( v5 == 255 )
{
if ( (int)write(1, v7, 0x100uLL) >= 0 )
goto LABEL_14;
LABEL_16:
exit(1);
}
}
if ( (int)write(1, v7, (unsigned int)(v5 + 1)) < 0 )
goto LABEL_16;
if ( v5 > 0 )
{
do
LABEL_14:
*v3++ = 0;
while ( v3 != &v7[v5 - 1 + 1] );
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // rbx
int v5; // ebp
char v6; // di
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

while ( 1 )
{
if ( (int)read(0, v7, 0xFFuLL) < 0 )
exit(1);
if ( v7[0] == 10 || !v7[0] )
exit(0);
v3 = v7;
v4 = v7;
v5 = 0;
while ( 1 )
{
v6 = *v4;
if ( *v4 == 10 || !v6 )
break;
*v4 = func0(v6);
++v5;
++v4;
if ( v5 == 255 )
{
if ( (int)write(1, v7, 0x100uLL) >= 0 )
goto LABEL_14;
LABEL_16:
exit(1);
}
}
if ( (int)write(1, v7, (unsigned int)(v5 + 1)) < 0 )
goto LABEL_16;
if ( v5 > 0 )
{
do
LABEL_14:
*v3++ = 0;
while ( v3 != &v7[v5 - 1 + 1] );
}
}
}

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

decompiled_code:
__int64 __fastcall Contains(const char *a1, const char *a2)
{
int v2; // er12
int v3; // eax
int v4; // er11
__int64 v5; // rdx
int v6; // ecx
__int64 v7; // r8
__int64 i; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 <= 0 )
return 0LL;
v4 = v3;
v5 = 0LL;
v6 = 0;
v7 = (unsigned int)(v3 - 1);
while ( 1 )
{
if ( a1[v5] == *a2 )
{
if ( v4 > 0 )
{
for ( i = 0LL; ; ++i )
{
v6 += a1[v5 + i] == a2[i];
if ( v7 == i )
break;
}
}
if ( v4 == v6 )
break;
}
if ( v5 == v2 - 1 )
return 0LL;
++v5;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
int v2; // er12
int v3; // eax
int v4; // er11
__int64 v5; // rdx
int v6; // ecx
__int64 v7; // r8
__int64 i; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 <= 0 )
return 0LL;
v4 = v3;
v5 = 0LL;
v6 = 0;
v7 = (unsigned int)(v3 - 1);
while ( 1 )
{
if ( a1[v5] == *a2 )
{
if ( v4 > 0 )
{
for ( i = 0LL; ; ++i )
{
v6 += a1[v5 + i] == a2[i];
if ( v7 == i )
break;
}
}
if ( v4 == v6 )
break;
}
if ( v5 == v2 - 1 )
return 0LL;
++v5;
}
return 1LL;
}

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 *v5; // rax
double *v6; // rdi
int *v7; // rdx
double *v8; // rsi

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

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

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

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

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

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

if ( a2 > 0 )
{
v2 = a1;
do
printf("%2.4f \n", *v2++);
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 *result; // rax
bool v3; // dl

if ( report_type_is_hidpp(a1) )
{
result = report_types[a2];
}
else
{
v3 = report_type_is_dj(a1);
result = "";
if ( !v3 )
return result;
result = (char *)dj_report_types[a2];
}
if ( !result )
result = "";
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char a1, unsigned __int8 a2)
{
char *result; // rax
bool v3; // dl

if ( func7(a1) )
{
result = report_types[a2];
}
else
{
v3 = func8(a1);
result = "";
if ( !v3 )
return result;
result = (char *)dj_report_types[a2];
}
if ( !result )
result = "";
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 *


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

result = error_messages[a1];
if ( !result )
result = "";
return result;
}

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

result = error_messages[a1];
if ( !result )
result = "";
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 = "";
return result;
}

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

result = error_messages_hidpp20[a1];
if ( !result )
result = "";
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 = "";
return result;
}

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

result = registers[a1];
if ( !result )
result = "";
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 v2; // bp
char result; // al
unsigned __int8 v4; // r14
int v5; // ebp
char v6; // bl

v2 = *a1;
result = report_type_is_hidpp(*a1);
if ( !result )
{
v4 = 0;
goto LABEL_17;
}
v4 = a1[2];
if ( v4 == 0x8F )
{
report_type_str(v2, a1[3]);
__printf_chk();
register_str(a1[4]);
__printf_chk();
error_str(a1[5]);
result = __printf_chk();
v4 = 4;
goto LABEL_17;
}
if ( v4 <= 0x8Fu )
{
if ( v4 )
{
if ( (unsigned __int8)(v4 + 0x80) > 3u )
{
v4 = 0;
}
else
{
register_str(a1[3]);
result = __printf_chk();
v4 = 1;
}
}
else if ( a2 == 4 || a2 == 17 )
{
__printf_chk();
result = __printf_chk();
v4 = 1;
}
LABEL_17:
if ( v4 >= a2 )
return result;
goto LABEL_10;
}
if ( v4 != 0xFF )
{
v4 = 0;
goto LABEL_17;
}
v4 = 0;
if ( a2 != 17 )
goto LABEL_17;
__printf_chk();
__printf_chk();
__printf_chk();
error_str_hidpp20(a1[5]);
__printf_chk();
v4 = 3;
LABEL_10:
__printf_chk();
v5 = (unsigned __int8)(v4 + 1);
v6 = 0;
do
{
__printf_chk();
if ( (v6 & 3) == 3 && a2 > v5 )
putchar(32);
++v6;
result = v5++;
}
while ( a2 > (unsigned __int8)(v5 - 1) );
return result;
}

canonical_decompiled_code:
char __fastcall func14(char *a1, unsigned __int8 a2)
{
char v2; // bp
char result; // al
unsigned __int8 v4; // r14
int v5; // ebp
char v6; // bl

v2 = *a1;
result = func7(*a1);
if ( !result )
{
v4 = 0;
goto LABEL_17;
}
v4 = a1[2];
if ( v4 == 0x8F )
{
func9(v2, a1[3]);
__printf_chk();
func13(a1[4]);
__printf_chk();
func11(a1[5]);
result = __printf_chk();
v4 = 4;
goto LABEL_17;
}
if ( v4 <= 0x8Fu )
{
if ( v4 )
{
if ( (unsigned __int8)(v4 + 0x80) > 3u )
{
v4 = 0;
}
else
{
func13(a1[3]);
result = __printf_chk();
v4 = 1;
}
}
else if ( a2 == 4 || a2 == 17 )
{
__printf_chk();
result = __printf_chk();
v4 = 1;
}
LABEL_17:
if ( v4 >= a2 )
return result;
goto LABEL_10;
}
if ( v4 != 0xFF )
{
v4 = 0;
goto LABEL_17;
}
v4 = 0;
if ( a2 != 17 )
goto LABEL_17;
__printf_chk();
__printf_chk();
__printf_chk();
func12(a1[5]);
__printf_chk();
v4 = 3;
LABEL_10:
__printf_chk();
v5 = (unsigned __int8)(v4 + 1);
v6 = 0;
do
{
__printf_chk();
if ( (v6 & 3) == 3 && a2 > v5 )
putchar(32);
++v6;
result = v5++;
}
while ( a2 > (unsigned __int8)(v5 - 1) );
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; }; }