main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // rcx
char *v5; // rdi
int v6; // eax
__int64 v7; // rdx
int result; // eax
__int64 v9; // r13
__int64 v10[4]; // [rsp+0h] [rbp-498h] BYREF
char v11; // [rsp+20h] [rbp-478h] BYREF
unsigned int v12; // [rsp+44h] [rbp-454h]
char v13[1032]; // [rsp+60h] [rbp-438h] BYREF
unsigned __int64 v14; // [rsp+468h] [rbp-30h]

v14 = __readfsqword(0x28u);
if ( argc <= 1 )
{
__fprintf_chk();
result = 1;
}
else
{
v3 = open(argv[1], 0, envp);
if ( v3 < 0 )
{
perror(argv[1]);
result = 1;
}
else
{
v4 = 16LL;
v10[2] = 1024LL;
v5 = &v11;
v10[0] = (__int64)&v11;
while ( v4 )
{
*(_DWORD *)v5 = 0;
v5 += 4;
--v4;
}
v10[1] = (__int64)v13;
do
{
while ( 1 )
{
memset(v13, 0xCCu, 0x400uLL);
v6 = ioctl(v3, 0x40189206uLL, v10);
if ( v6 == -1 )
break;
if ( v6 < 0 )
goto LABEL_15;
if ( v12 )
{
if ( getenv("HEX") )
{
__printf_chk();
if ( v12 )
{
v9 = 0LL;
do
{
++v9;
__printf_chk();
}
while ( v12 > (unsigned int)v9 );
}
}
else if ( v12 > 0x14 || v12 <= 2 )
{
__fprintf_chk();
}
else
{
print_time("HEX", 1075352070LL, v7);
__printf_chk();
process_msg(v13, v12);
fflush(0LL);
}
}
}
}
while ( *__errno_location() == 4 );
LABEL_15:
perror("ioctl");
close(v3);
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // rcx
char *v5; // rdi
int v6; // eax
__int64 v7; // rdx
int result; // eax
__int64 v9; // r13
__int64 v10[4]; // [rsp+0h] [rbp-498h] BYREF
char v11; // [rsp+20h] [rbp-478h] BYREF
unsigned int v12; // [rsp+44h] [rbp-454h]
char v13[1032]; // [rsp+60h] [rbp-438h] BYREF
unsigned __int64 v14; // [rsp+468h] [rbp-30h]

v14 = __readfsqword(0x28u);
if ( argc <= 1 )
{
__fprintf_chk();
result = 1;
}
else
{
v3 = open(argv[1], 0, envp);
if ( v3 < 0 )
{
perror(argv[1]);
result = 1;
}
else
{
v4 = 16LL;
v10[2] = 1024LL;
v5 = &v11;
v10[0] = (__int64)&v11;
while ( v4 )
{
*(_DWORD *)v5 = 0;
v5 += 4;
--v4;
}
v10[1] = (__int64)v13;
do
{
while ( 1 )
{
memset(v13, 0xCCu, 0x400uLL);
v6 = ioctl(v3, 0x40189206uLL, v10);
if ( v6 == -1 )
break;
if ( v6 < 0 )
goto LABEL_15;
if ( v12 )
{
if ( getenv("HEX") )
{
__printf_chk();
if ( v12 )
{
v9 = 0LL;
do
{
++v9;
__printf_chk();
}
while ( v12 > (unsigned int)v9 );
}
}
else if ( v12 > 0x14 || v12 <= 2 )
{
__fprintf_chk();
}
else
{
func16("HEX", 1075352070LL, v7);
__printf_chk();
func15(v13, v12);
fflush(0LL);
}
}
}
}
while ( *__errno_location() == 4 );
LABEL_15:
perror("ioctl");
close(v3);
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char ** argv) {
 unsigned char data[1024];
 struct usbmon_packet hdr;
 struct mon_get_arg event;
 int fd, r;
 if (argc < 2) {
  fprintf(stderr, "Usage: %s /dev/usbmonX\n", argv[0]);
  return 1;
 }
 fd = open(argv[1], 00);
 if (fd < 0) {
  perror(argv[1]);
  return 1;
 }
 memset(&hdr, 0, sizeof hdr);
 event.hdr = &hdr;
 event.data = &data;
 event.alloc = sizeof data;
 for (;;) {
  memset(&data, 0xCC, sizeof data);
  r = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((6)) << 0) | ((((sizeof(struct mon_get_arg)))) << ((0 +8)+8))), &event);
  if (r == -1 && (*__errno_location ()) == 4) {
   continue;
  }
  if (r < 0) {
   perror("ioctl");
   break;
  }
  if (hdr.len_cap) {
   if (getenv("HEX")) {
    unsigned int i;
    printf("Type=%c\n", hdr.type);
    for (i=0; i<hdr.len_cap; i++) {
     printf("%02X%c", data[i],
      i + 1 == hdr.len_cap ? '\n' : ' ');
    }
   } else if (hdr.len_cap > sizeof (struct report)) {
    fprintf(stderr, "Discarding too large packet of length %u!\n", hdr.len_cap);
   } else {
    struct report *report = (struct report *)&data;
    if (hdr.len_cap < 3) {
     fprintf(stderr, "Short data len: %i\n", hdr.len_cap);
     continue;
    }
    print_time();
    if (hdr.type == 'C') {
     printf("\033[" "1;32" "m" "Recv\t" "\033[m");
    } else if (hdr.type == 'S') {
     printf("\033[" "1;31" "m" "Send\t" "\033[m");
    } else {
     printf("\033[" "1;35" "m" "Type=%c\t" "\033[m" "\n", hdr.type);
    }
    process_msg(report, hdr.len_cap);
    fflush(((void *)0));
   }
  }
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 unsigned char data[1024];
 struct usbmon_packet hdr;
 struct mon_get_arg event;
 int fd; int r;
 if (argc < 2) {
  fprintf(stderr, "Usage: %s /dev/usbmonX\n", argv[0]);
  return 1;
 }
 fd = open(argv[1], 00);
 if (fd < 0) {
  perror(argv[1]);
  return 1;
 }
 memset(&hdr, 0, sizeof hdr);
 event.hdr = &hdr;
 event.data = &data;
 event.alloc = sizeof data;
 for (;;) {
  memset(&data, 0xCC, sizeof data);
  r = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | (((0x92)) << (0 +8)) | (((6)) << 0) | ((((sizeof(struct mon_get_arg)))) << ((0 +8)+8))), &event);
  if (r == -1 && (*__errno_location ()) == 4) {
   continue;
  }
  if (r < 0) {
   perror("ioctl");
   break;
  }
  if (hdr.len_cap) {
   if (getenv("HEX")) {
    unsigned int i;
    printf("Type=%c\n", hdr.type);
    for (i=0; i<hdr.len_cap; i++) {
     printf("%02X%c", data[i],
      i + 1 == hdr.len_cap ? '\n' : ' ');
    }
   } else if (hdr.len_cap > sizeof (struct report)) {
    fprintf(stderr, "Discarding too large packet of length %u!\n", hdr.len_cap);
   } else {
    struct report *report = (struct report *)&data;
    if (hdr.len_cap < 3) {
     fprintf(stderr, "Short data len: %i\n", hdr.len_cap);
     continue;
    }
    print_time();
    if (hdr.type == 'C') {
     printf("\033[" "1;32" "m" "Recv\t" "\033[m");
    } else if (hdr.type == 'S') {
     printf("\033[" "1;31" "m" "Send\t" "\033[m");
    } else {
     printf("\033[" "1;35" "m" "Type=%c\t" "\033[m" "\n", hdr.type);
    }
    process_msg(report, hdr.len_cap);
    fflush(((void *)0));
   }
  }
 }
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
data
unsigned char [1024]

variable_types: struct mon_get_arg { struct usbmon_packet { unsigned long id; unsigned char type; unsigned char xfer_type; unsigned char epnum; unsigned char devnum; unsigned short busnum; char flag_setup; char flag_data; long ts_sec; int ts_usec; int status; unsigned int length; unsigned int len_cap; union { unsigned char setup[8]; struct iso_rec { int error_count; int numdesc; } iso; } s; int interval; int start_frame; unsigned int xfer_flags; unsigned int ndesc; } *hdr; void *data; unsigned long alloc; }

variable_types: fd int

variable_types: r int

variable_types:
i
unsigned int

user_defined_types: struct usbmon_packet { unsigned long id; unsigned char type; unsigned char xfer_type; unsigned char epnum; unsigned char devnum; unsigned short busnum; char flag_setup; char flag_data; long ts_sec; int ts_usec; int status; unsigned int length; unsigned int len_cap; union { unsigned char setup[8]; struct iso_rec iso; } s; int interval; int start_frame; unsigned int xfer_flags; unsigned int ndesc; }

user_defined_types: struct mon_get_arg { struct usbmon_packet *hdr; void *data; unsigned long alloc; }


repo: mir-ror/ltunify

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

if ( a1 > 6u )
{
result = "Usage: %s /dev/usbmonX\n" + 23;
if ( a1 == 0xFF )
result = "RECV";
}
else if ( a1 )
{
switch ( a1 )
{
case 2u:
result = "DEV2";
break;
case 3u:
result = "DEV3";
break;
case 4u:
result = "DEV4";
break;
case 5u:
result = "DEV5";
break;
case 6u:
result = "DEV6";
break;
default:
result = "DEV1";
break;
}
}
else
{
result = "Usage: %s /dev/usbmonX\n" + 23;
}
return result;
}

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

if ( a1 > 6u )
{
result = "Usage: %s /dev/usbmonX\n" + 23;
if ( a1 == 0xFF )
result = "RECV";
}
else if ( a1 )
{
switch ( a1 )
{
case 2u:
result = "DEV2";
break;
case 3u:
result = "DEV3";
break;
case 4u:
result = "DEV4";
break;
case 5u:
result = "DEV5";
break;
case 6u:
result = "DEV6";
break;
default:
result = "DEV1";
break;
}
}
else
{
result = "Usage: %s /dev/usbmonX\n" + 23;
}
return result;
}

original_code:
const char * device_type_str(u8 type) {
 switch (type) {
 case 0x01: return "DEV1";
 case 0x02: return "DEV2";
 case 0x03: return "DEV3";
 case 0x04: return "DEV4";
 case 0x05: return "DEV5";
 case 0x06: return "DEV6";
 case 0xFF: return "RECV";
 default: return "";
 }
}

canonical_original_code:
char *device_type_str(unsigned char type) {
 switch (type) {
 case 0x01: return "DEV1";
 case 0x02: return "DEV2";
 case 0x03: return "DEV3";
 case 0x04: return "DEV4";
 case 0x05: return "DEV5";
 case 0x06: return "DEV6";
 case 0xFF: return "RECV";
 default: return "";
 }
}

variable_types:
type
unsigned char

return_type: char *


decompiled_code:
void __fastcall my_pow(int a1, double a2)
{
double v3; // xmm0_8
int i; // eax

v3 = 1.0;
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v3 = v3 * a2;
}
}

canonical_decompiled_code:
void __fastcall func7(int a1, double a2)
{
double v3; // xmm0_8
int i; // eax

v3 = 1.0;
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v3 = v3 * a2;
}
}

original_code:
double my_pow(double n, int i)
{
  int j;
  double sum = 1.00000;
  for(j = 0; j < i; j++)
    sum *= n;
  return (sum);
}

variable_types: n double

variable_types: i int

variable_types: j int

variable_types: sum double

return_type: double


canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
my_pow(9LL, argv, envp, 3.141592);
printf("Hello, world! %f \n", 3.141592);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(9LL, argv, envp, 3.141592);
printf("Hello, world! %f \n", 3.141592);
return 0;
}

original_code:
int main(void)
{
  int i;
  printf("Hello, world! %f  \n", my_pow(3.141592, 9));
  return 0;
}

canonical_original_code:
int main()
{
  int i;
  printf("Hello, world! %f  \n", my_pow(3.141592, 9));
  return 0;
}

return_type: int


repo: mirror/wiimms-iso-tools

decompiled_code:
__int64 __fastcall Lzma2Dec_GetOldProps(unsigned __int8 a1, _BYTE *a2)
{
__int64 result; // rax
unsigned int v3; // edi
char v4; // cl
unsigned int v5; // eax
unsigned int v6; // edx

result = 4LL;
if ( a1 <= 0x28u )
{
if ( a1 == 40 )
{
LOBYTE(v5) = -1;
LOBYTE(v6) = -1;
v4 = -1;
LOBYTE(v3) = -1;
}
else
{
v3 = (a1 & 1 | 2) << ((a1 >> 1) + 11);
v4 = BYTE1(v3);
v5 = HIBYTE(v3);
v6 = HIWORD(v3);
}
*a2 = 4;
a2[1] = v3;
a2[2] = v4;
a2[3] = v6;
a2[4] = v5;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, _BYTE *a2)
{
__int64 result; // rax
unsigned int v3; // edi
char v4; // cl
unsigned int v5; // eax
unsigned int v6; // edx

result = 4LL;
if ( a1 <= 0x28u )
{
if ( a1 == 40 )
{
LOBYTE(v5) = -1;
LOBYTE(v6) = -1;
v4 = -1;
LOBYTE(v3) = -1;
}
else
{
v3 = (a1 & 1 | 2) << ((a1 >> 1) + 11);
v4 = BYTE1(v3);
v5 = HIBYTE(v3);
v6 = HIWORD(v3);
}
*a2 = 4;
a2[1] = v3;
a2[2] = v4;
a2[3] = v6;
a2[4] = v5;
result = 0LL;
}
return result;
}

original_code:
static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)
{
  UInt32 dicSize;
  if (prop > 40)
    return 4;
  dicSize = (prop == 40) ? 0xFFFFFFFF : (((UInt32)2 | ((prop) & 1)) << ((prop) / 2 + 11));
  props[0] = (Byte)4;
  props[1] = (Byte)(dicSize);
  props[2] = (Byte)(dicSize >> 8);
  props[3] = (Byte)(dicSize >> 16);
  props[4] = (Byte)(dicSize >> 24);
  return 0;
}

canonical_original_code:
static int Lzma2Dec_GetOldProps(unsigned char prop, unsigned char *props)
{
  unsigned int dicSize;
  if (prop > 40)
    return 4;
  dicSize = (prop == 40) ? 0xFFFFFFFF : (((unsigned int)2 | ((prop) & 1)) << ((prop) / 2 + 11));
  props[0] = (unsigned char)4;
  props[1] = (Byte)(dicSize);
  props[2] = (Byte)(dicSize >> 8);
  props[3] = (Byte)(dicSize >> 16);
  props[4] = (Byte)(dicSize >> 24);
  return 0;
}

variable_types:
prop
unsigned char

variable_types:
props
unsigned char *

variable_types:
dicSize
unsigned int


decompiled_code:
__int64 __fastcall Lzma2Dec_UpdateState(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // al
unsigned int v4; // esi
__int16 v5; // r8
int v6; // er11
bool v7; // sf

switch ( *(_DWORD *)(a1 + 144) )
{
case 0:
*(_BYTE *)(a1 + 148) = a2;
result = 8LL;
if ( !(_BYTE)a2 )
return result;
if ( (a2 & 0x80u) != 0 )
{
result = 1LL;
*(_DWORD *)(a1 + 140) = (a2 << 16) & 0x1F0000;
}
else if ( (unsigned __int8)a2 > 2u )
{
LABEL_4:
result = 9LL;
}
else
{
*(_DWORD *)(a1 + 140) = 0;
result = 1LL;
}
break;
case 1:
result = 2LL;
*(_DWORD *)(a1 + 140) |= (unsigned __int8)a2 << 8;
return result;
case 2:
v7 = *(char *)(a1 + 148) < 0;
*(_DWORD *)(a1 + 140) = (*(_DWORD *)(a1 + 140) | (unsigned __int8)a2) + 1;
if ( !v7 )
goto LABEL_8;
return 3LL;
case 3:
result = 4LL;
*(_DWORD *)(a1 + 136) = (unsigned __int8)a2 << 8;
return result;
case 4:
result = 5LL;
*(_DWORD *)(a1 + 136) = (*(_DWORD *)(a1 + 136) | (unsigned __int8)a2) + 1;
if ( (*(_BYTE *)(a1 + 148) & 0x40) != 0 )
return result;
if ( *(_DWORD *)(a1 + 160) )
goto LABEL_4;
goto LABEL_8;
case 5:
if ( (unsigned __int8)a2 > 0xE0u )
goto LABEL_4;
v3 = (unsigned __int8)a2 / 9u;
v4 = (unsigned __int8)a2 % 9u;
v5 = (unsigned __int16)(103 * v3) >> 9;
*(_DWORD *)(a1 + 8) = (unsigned __int8)v5;
v6 = (unsigned __int8)(v3 - 5 * v5);
if ( (int)(v4 + v6) > 4 )
goto LABEL_4;
*(_DWORD *)a1 = v4;
*(_DWORD *)(a1 + 4) = v6;
*(_DWORD *)(a1 + 160) = 0;
LABEL_8:
result = 6LL;
break;
default:
JUMPOUT(0x848LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // al
unsigned int v4; // esi
__int16 v5; // r8
int v6; // er11
bool v7; // sf

switch ( *(_DWORD *)(a1 + 144) )
{
case 0:
*(_BYTE *)(a1 + 148) = a2;
result = 8LL;
if ( !(_BYTE)a2 )
return result;
if ( (a2 & 0x80u) != 0 )
{
result = 1LL;
*(_DWORD *)(a1 + 140) = (a2 << 16) & 0x1F0000;
}
else if ( (unsigned __int8)a2 > 2u )
{
LABEL_4:
result = 9LL;
}
else
{
*(_DWORD *)(a1 + 140) = 0;
result = 1LL;
}
break;
case 1:
result = 2LL;
*(_DWORD *)(a1 + 140) |= (unsigned __int8)a2 << 8;
return result;
case 2:
v7 = *(char *)(a1 + 148) < 0;
*(_DWORD *)(a1 + 140) = (*(_DWORD *)(a1 + 140) | (unsigned __int8)a2) + 1;
if ( !v7 )
goto LABEL_8;
return 3LL;
case 3:
result = 4LL;
*(_DWORD *)(a1 + 136) = (unsigned __int8)a2 << 8;
return result;
case 4:
result = 5LL;
*(_DWORD *)(a1 + 136) = (*(_DWORD *)(a1 + 136) | (unsigned __int8)a2) + 1;
if ( (*(_BYTE *)(a1 + 148) & 0x40) != 0 )
return result;
if ( *(_DWORD *)(a1 + 160) )
goto LABEL_4;
goto LABEL_8;
case 5:
if ( (unsigned __int8)a2 > 0xE0u )
goto LABEL_4;
v3 = (unsigned __int8)a2 / 9u;
v4 = (unsigned __int8)a2 % 9u;
v5 = (unsigned __int16)(103 * v3) >> 9;
*(_DWORD *)(a1 + 8) = (unsigned __int8)v5;
v6 = (unsigned __int8)(v3 - 5 * v5);
if ( (int)(v4 + v6) > 4 )
goto LABEL_4;
*(_DWORD *)a1 = v4;
*(_DWORD *)(a1 + 4) = v6;
*(_DWORD *)(a1 + 160) = 0;
LABEL_8:
result = 6LL;
break;
default:
JUMPOUT(0x848LL);
}
return result;
}

original_code:
static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
{
  switch(p->state)
  {
    case LZMA2_STATE_CONTROL:
      p->control = b;
      ;
      ;
      if (p->control == 0)
        return LZMA2_STATE_FINISHED;
      if ((((p)->control & (1 << 7)) == 0))
      {
        if ((p->control & 0x7F) > 2)
          return LZMA2_STATE_ERROR;
        p->unpackSize = 0;
      }
      else
        p->unpackSize = (UInt32)(p->control & 0x1F) << 16;
      return LZMA2_STATE_UNPACK0;
    case LZMA2_STATE_UNPACK0:
      p->unpackSize |= (UInt32)b << 8;
      return LZMA2_STATE_UNPACK1;
    case LZMA2_STATE_UNPACK1:
      p->unpackSize |= (UInt32)b;
      p->unpackSize++;
      ;
      return ((((p)->control & (1 << 7)) == 0)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
    case LZMA2_STATE_PACK0:
      p->packSize = (UInt32)b << 8;
      return LZMA2_STATE_PACK1;
    case LZMA2_STATE_PACK1:
      p->packSize |= (UInt32)b;
      p->packSize++;
      ;
      return (((((p)->control >> 5) & 3)) >= 2) ? LZMA2_STATE_PROP:
        (p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
    case LZMA2_STATE_PROP:
    {
      int lc, lp;
      if (b >= (9 * 5 * 5))
        return LZMA2_STATE_ERROR;
      lc = b % 9;
      b /= 9;
      p->decoder.prop.pb = b / 5;
      lp = b % 5;
      if (lc + lp > 4)
        return LZMA2_STATE_ERROR;
      p->decoder.prop.lc = lc;
      p->decoder.prop.lp = lp;
      p->needInitProp = 0;
      return LZMA2_STATE_DATA;
    }
  }
  return LZMA2_STATE_ERROR;
}

canonical_original_code:
static enum ELzma2State Lzma2Dec_UpdateState(struct CLzma2Dec *p, unsigned char b)
{
  switch(p->state)
  {
    case LZMA2_STATE_CONTROL:
      p->control = b;
      ;
      ;
      if (p->control == 0)
        return LZMA2_STATE_FINISHED;
      if ((((p)->control & (1 << 7)) == 0))
      {
        if ((p->control & 0x7F) > 2)
          return LZMA2_STATE_ERROR;
        p->unpackSize = 0;
      }
      else
        p->unpackSize = (UInt32)(p->control & 0x1F) << 16;
      return LZMA2_STATE_UNPACK0;
    case LZMA2_STATE_UNPACK0:
      p->unpackSize |= (unsigned int)b << 8;
      return LZMA2_STATE_UNPACK1;
    case LZMA2_STATE_UNPACK1:
      p->unpackSize |= (unsigned int)b;
      p->unpackSize++;
      ;
      return ((((p)->control & (1 << 7)) == 0)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
    case LZMA2_STATE_PACK0:
      p->packSize = (unsigned int)b << 8;
      return LZMA2_STATE_PACK1;
    case LZMA2_STATE_PACK1:
      p->packSize |= (unsigned int)b;
      p->packSize++;
      ;
      return (((((p)->control >> 5) & 3)) >= 2) ? LZMA2_STATE_PROP:
        (p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
    case LZMA2_STATE_PROP:
    {
      int lc; int lp;
      if (b >= (9 * 5 * 5))
        return LZMA2_STATE_ERROR;
      lc = b % 9;
      b /= 9;
      p->decoder.prop.pb = b / 5;
      lp = b % 5;
      if (lc + lp > 4)
        return LZMA2_STATE_ERROR;
      p->decoder.prop.lc = lc;
      p->decoder.prop.lp = lp;
      p->needInitProp = 0;
      return LZMA2_STATE_DATA;
    }
  }
  return LZMA2_STATE_ERROR;
}

variable_types: struct CLzma2Dec { struct CLzmaDec { struct _CLzmaProps { unsigned int lc; unsigned int dicSize; } prop; unsigned int *probs; unsigned char *dic; unsigned char *buf; unsigned int range; unsigned long dicPos; unsigned long dicBufSize; unsigned int processedPos; unsigned int checkDicSize; unsigned int state; unsigned int reps[4]; unsigned int remainLen; int needFlush; int needInitState; unsigned int numProbs; unsigned int tempBufSize; unsigned char tempBuf[20]; } decoder; unsigned int packSize; unsigned int unpackSize; int state; unsigned char control; int needInitDic; int needInitState; int needInitProp; } *

variable_types:
b
unsigned char

variable_types: lc int

variable_types: lp int

return_type: enum ELzma2State { LZMA2_STATE_CONTROL=0, LZMA2_STATE_UNPACK0=1, LZMA2_STATE_UNPACK1=2, LZMA2_STATE_PACK0=3, LZMA2_STATE_PACK1=4, LZMA2_STATE_PROP=5, LZMA2_STATE_DATA=6, LZMA2_STATE_DATA_CONT=7, LZMA2_STATE_FINISHED=8, LZMA2_STATE_ERROR=9 }

user_defined_types: struct CLzma2Dec { struct CLzmaDec decoder; unsigned int packSize; unsigned int unpackSize; int state; unsigned char control; int needInitDic; int needInitState; int needInitProp; }

user_defined_types: struct CLzmaDec { struct _CLzmaProps prop; unsigned int *probs; unsigned char *dic; unsigned char *buf; unsigned int range; unsigned long dicPos; unsigned long dicBufSize; unsigned int processedPos; unsigned int checkDicSize; unsigned int state; unsigned int reps[4]; unsigned int remainLen; int needFlush; int needInitState; unsigned int numProbs; unsigned int tempBufSize; unsigned char tempBuf[20]; }


decompiled_code:
__int64 __fastcall LzmaDec_UpdateWithUncompressed(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
int v5; // edx

memcpy((void *)(*(_QWORD *)(a1 + 24) + *(_QWORD *)(a1 + 48)), a2, a3);
result = *(unsigned int *)(a1 + 68);
*(_QWORD *)(a1 + 48) += a3;
if ( (_DWORD)result )
{
v5 = *(_DWORD *)(a1 + 64);
LABEL_3:
*(_DWORD *)(a1 + 64) = a3 + v5;
return result;
}
v5 = *(_DWORD *)(a1 + 64);
if ( (unsigned int)(*(_DWORD *)(a1 + 12) - v5) > a3 )
goto LABEL_3;
*(_DWORD *)(a1 + 68) = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 64) = a3 + v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
int v5; // edx

memcpy((void *)(*(_QWORD *)(a1 + 24) + *(_QWORD *)(a1 + 48)), a2, a3);
result = *(unsigned int *)(a1 + 68);
*(_QWORD *)(a1 + 48) += a3;
if ( (_DWORD)result )
{
v5 = *(_DWORD *)(a1 + 64);
LABEL_3:
*(_DWORD *)(a1 + 64) = a3 + v5;
return result;
}
v5 = *(_DWORD *)(a1 + 64);
if ( (unsigned int)(*(_DWORD *)(a1 + 12) - v5) > a3 )
goto LABEL_3;
*(_DWORD *)(a1 + 68) = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 64) = a3 + v5;
return result;
}

original_code:
static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT size)
{
  memcpy(p->dic + p->dicPos, src, size);
  p->dicPos += size;
  if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= size)
    p->checkDicSize = p->prop.dicSize;
  p->processedPos += (UInt32)size;
}

canonical_original_code:
static void LzmaDec_UpdateWithUncompressed(struct CLzmaDec *p, unsigned char *src, unsigned long size)
{
  memcpy(p->dic + p->dicPos, src, size);
  p->dicPos += size;
  if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= size)
    p->checkDicSize = p->prop.dicSize;
  p->processedPos += (unsigned int)size;
}

variable_types: struct CLzmaDec { struct _CLzmaProps { unsigned int lc; unsigned int dicSize; } prop; unsigned int *probs; unsigned char *dic; unsigned char *buf; unsigned int range; unsigned long dicPos; unsigned long dicBufSize; unsigned int processedPos; unsigned int checkDicSize; unsigned int state; unsigned int reps[4]; unsigned int remainLen; int needFlush; int needInitState; unsigned int numProbs; unsigned int tempBufSize; unsigned char tempBuf[20]; } *

variable_types:
src
unsigned char *

variable_types:
size
unsigned long

return_type: void


decompiled_code:
__int64 __fastcall Lzma2Dec_AllocateProbs(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
__int64 v3; // r8
__int64 v4; // r9
char v5[13]; // [rsp+Bh] [rbp-Dh] BYREF

result = Lzma2Dec_GetOldProps(a2, v5);
if ( !(_DWORD)result )
result = LzmaDec_AllocateProbs(v3, v5, 5LL, v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
__int64 v3; // r8
__int64 v4; // r9
char v5[13]; // [rsp+Bh] [rbp-Dh] BYREF

result = func0(a2, v5);
if ( !(_DWORD)result )
result = LzmaDec_AllocateProbs(v3, v5, 5LL, v4);
return result;
}

original_code:
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
{
  Byte props[5];
  { int __result__ = (Lzma2Dec_GetOldProps(prop, props)); if (__result__ != 0) return __result__; };
  return LzmaDec_AllocateProbs(&p->decoder, props, 5, alloc);
}

canonical_original_code:
int Lzma2Dec_AllocateProbs(struct CLzma2Dec *p, unsigned char prop, struct ISzAlloc *alloc)
{
  unsigned char props[5];
  { int __result__ = (Lzma2Dec_GetOldProps(prop, props)); if (__result__ != 0) return __result__; };
  return LzmaDec_AllocateProbs(&p->decoder, props, 5, alloc);
}

variable_types: struct ISzAlloc { void *(*Alloc)(void *p, unsigned long size); void (*Free)(void *p, void *address); } *

variable_types:
props
unsigned char [5]

user_defined_types: struct _CLzmaProps { unsigned int lc; unsigned int dicSize; }


decompiled_code:
__int64 __fastcall Lzma2Dec_Allocate(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
__int64 v3; // r8
__int64 v4; // r9
char v5[13]; // [rsp+Bh] [rbp-Dh] BYREF

result = Lzma2Dec_GetOldProps(a2, v5);
if ( !(_DWORD)result )
result = LzmaDec_Allocate(v3, v5, 5LL, v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
__int64 v3; // r8
__int64 v4; // r9
char v5[13]; // [rsp+Bh] [rbp-Dh] BYREF

result = func0(a2, v5);
if ( !(_DWORD)result )
result = LzmaDec_Allocate(v3, v5, 5LL, v4);
return result;
}

original_code:
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
{
  Byte props[5];
  { int __result__ = (Lzma2Dec_GetOldProps(prop, props)); if (__result__ != 0) return __result__; };
  return LzmaDec_Allocate(&p->decoder, props, 5, alloc);
}

canonical_original_code:
int Lzma2Dec_Allocate(struct CLzma2Dec *p, unsigned char prop, struct ISzAlloc *alloc)
{
  unsigned char props[5];
  { int __result__ = (Lzma2Dec_GetOldProps(prop, props)); if (__result__ != 0) return __result__; };
  return LzmaDec_Allocate(&p->decoder, props, 5, alloc);
}

user_defined_types: struct ISzAlloc { void *(*Alloc)(void *p, unsigned long size); void (*Free)(void *p, void *address); }


original_code:
void Lzma2Dec_Init(CLzma2Dec *p)
{
  p->state = LZMA2_STATE_CONTROL;
  p->needInitDic = 1;
  p->needInitState = 1;
  p->needInitProp = 1;
  LzmaDec_Init(&p->decoder);
}

canonical_original_code:
void Lzma2Dec_Init(struct CLzma2Dec *p)
{
  p->state = LZMA2_STATE_CONTROL;
  p->needInitDic = 1;
  p->needInitState = 1;
  p->needInitProp = 1;
  LzmaDec_Init(&p->decoder);
}


original_code:
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{
  SizeT inSize = *srcLen;
  *srcLen = 0;
  *status = LZMA_STATUS_NOT_SPECIFIED;
  while (p->state != LZMA2_STATE_FINISHED)
  {
    SizeT dicPos = p->decoder.dicPos;
    if (p->state == LZMA2_STATE_ERROR)
      return 1;
    if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
    {
      *status = LZMA_STATUS_NOT_FINISHED;
      return 0;
    }
    if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
    {
      if (*srcLen == inSize)
      {
        *status = LZMA_STATUS_NEEDS_MORE_INPUT;
        return 0;
      }
      (*srcLen)++;
      p->state = Lzma2Dec_UpdateState(p, *src++);
      continue;
    }
    {
      SizeT destSizeCur = dicLimit - dicPos;
      SizeT srcSizeCur = inSize - *srcLen;
      ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
      if (p->unpackSize <= destSizeCur)
      {
        destSizeCur = (SizeT)p->unpackSize;
        curFinishMode = LZMA_FINISH_END;
      }
      if ((((p)->control & (1 << 7)) == 0))
      {
        if (*srcLen == inSize)
        {
          *status = LZMA_STATUS_NEEDS_MORE_INPUT;
          return 0;
        }
        if (p->state == LZMA2_STATE_DATA)
        {
          Bool initDic = (p->control == 1);
          if (initDic)
            p->needInitProp = p->needInitState = 1;
          else if (p->needInitDic)
            return 1;
          p->needInitDic = 0;
          LzmaDec_InitDicAndState(&p->decoder, initDic, 0);
        }
        if (srcSizeCur > destSizeCur)
          srcSizeCur = destSizeCur;
        if (srcSizeCur == 0)
          return 1;
        LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur);
        src += srcSizeCur;
        *srcLen += srcSizeCur;
        p->unpackSize -= (UInt32)srcSizeCur;
        p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
      }
      else
      {
        SizeT outSizeProcessed;
        SRes res;
        if (p->state == LZMA2_STATE_DATA)
        {
          int mode = (((p)->control >> 5) & 3);
          Bool initDic = (mode == 3);
          Bool initState = (mode > 0);
          if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
            return 1;
          LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
          p->needInitDic = 0;
          p->needInitState = 0;
          p->state = LZMA2_STATE_DATA_CONT;
        }
        if (srcSizeCur > p->packSize)
          srcSizeCur = (SizeT)p->packSize;
        res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);
        src += srcSizeCur;
        *srcLen += srcSizeCur;
        p->packSize -= (UInt32)srcSizeCur;
        outSizeProcessed = p->decoder.dicPos - dicPos;
        p->unpackSize -= (UInt32)outSizeProcessed;
        { int __result__ = (res); if (__result__ != 0) return __result__; };
        if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
          return res;
        if (srcSizeCur == 0 && outSizeProcessed == 0)
        {
          if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK ||
              p->unpackSize != 0 || p->packSize != 0)
            return 1;
          p->state = LZMA2_STATE_CONTROL;
        }
        if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
          *status = LZMA_STATUS_NOT_FINISHED;
      }
    }
  }
  *status = LZMA_STATUS_FINISHED_WITH_MARK;
  return 0;
}

canonical_original_code:
int Lzma2Dec_DecodeToDic(struct CLzma2Dec *p, unsigned long dicLimit, unsigned char *src, unsigned long *srcLen, enum ELzmaFinishMode finishMode, enum ELzmaStatus *status)
{
  unsigned long inSize = *srcLen;
  *srcLen = 0;
  *status = LZMA_STATUS_NOT_SPECIFIED;
  while (p->state != LZMA2_STATE_FINISHED)
  {
    unsigned long dicPos = p->decoder.dicPos;
    if (p->state == LZMA2_STATE_ERROR)
      return 1;
    if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
    {
      *status = LZMA_STATUS_NOT_FINISHED;
      return 0;
    }
    if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
    {
      if (*srcLen == inSize)
      {
        *status = LZMA_STATUS_NEEDS_MORE_INPUT;
        return 0;
      }
      (*srcLen)++;
      p->state = Lzma2Dec_UpdateState(p, *src++);
      continue;
    }
    {
      unsigned long destSizeCur = dicLimit - dicPos;
      unsigned long srcSizeCur = inSize - *srcLen;
      enum ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
      if (p->unpackSize <= destSizeCur)
      {
        destSizeCur = (unsigned long)p->unpackSize;
        curFinishMode = LZMA_FINISH_END;
      }
      if ((((p)->control & (1 << 7)) == 0))
      {
        if (*srcLen == inSize)
        {
          *status = LZMA_STATUS_NEEDS_MORE_INPUT;
          return 0;
        }
        if (p->state == LZMA2_STATE_DATA)
        {
          int initDic = (p->control == 1);
          if (initDic)
            p->needInitProp = p->needInitState = 1;
          else if (p->needInitDic)
            return 1;
          p->needInitDic = 0;
          LzmaDec_InitDicAndState(&p->decoder, initDic, 0);
        }
        if (srcSizeCur > destSizeCur)
          srcSizeCur = destSizeCur;
        if (srcSizeCur == 0)
          return 1;
        LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur);
        src += srcSizeCur;
        *srcLen += srcSizeCur;
        p->unpackSize -= (unsigned int)srcSizeCur;
        p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
      }
      else
      {
        unsigned long outSizeProcessed;
        int res;
        if (p->state == LZMA2_STATE_DATA)
        {
          int mode = (((p)->control >> 5) & 3);
          int initDic = (mode == 3);
          int initState = (mode > 0);
          if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
            return 1;
          LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
          p->needInitDic = 0;
          p->needInitState = 0;
          p->state = LZMA2_STATE_DATA_CONT;
        }
        if (srcSizeCur > p->packSize)
          srcSizeCur = (unsigned long)p->packSize;
        res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);
        src += srcSizeCur;
        *srcLen += srcSizeCur;
        p->packSize -= (unsigned int)srcSizeCur;
        outSizeProcessed = p->decoder.dicPos - dicPos;
        p->unpackSize -= (unsigned int)outSizeProcessed;
        { int __result__ = (res); if (__result__ != 0) return __result__; };
        if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
          return res;
        if (srcSizeCur == 0 && outSizeProcessed == 0)
        {
          if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK ||
              p->unpackSize != 0 || p->packSize != 0)
            return 1;
          p->state = LZMA2_STATE_CONTROL;
        }
        if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
          *status = LZMA_STATUS_NOT_FINISHED;
      }
    }
  }
  *status = LZMA_STATUS_FINISHED_WITH_MARK;
  return 0;
}

variable_types:
dicLimit
unsigned long

variable_types:
srcLen
unsigned long *

variable_types: enum ELzmaFinishMode { LZMA_FINISH_ANY=0, LZMA_FINISH_END=1 }

variable_types: enum ELzmaStatus { LZMA_STATUS_NOT_SPECIFIED=0, LZMA_STATUS_FINISHED_WITH_MARK=1, LZMA_STATUS_NOT_FINISHED=2, LZMA_STATUS_NEEDS_MORE_INPUT=3, LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK=4 } *

variable_types:
inSize
unsigned long

variable_types:
dicPos
unsigned long

variable_types:
destSizeCur
unsigned long

variable_types:
srcSizeCur
unsigned long

variable_types: initDic int

variable_types:
outSizeProcessed
unsigned long

variable_types: res int

variable_types: mode int

variable_types: initState int


original_code:
SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{
  SizeT outSize = *destLen, inSize = *srcLen;
  *srcLen = *destLen = 0;
  for (;;)
  {
    SizeT srcSizeCur = inSize, outSizeCur, dicPos;
    ELzmaFinishMode curFinishMode;
    SRes res;
    if (p->decoder.dicPos == p->decoder.dicBufSize)
      p->decoder.dicPos = 0;
    dicPos = p->decoder.dicPos;
    if (outSize > p->decoder.dicBufSize - dicPos)
    {
      outSizeCur = p->decoder.dicBufSize;
      curFinishMode = LZMA_FINISH_ANY;
    }
    else
    {
      outSizeCur = dicPos + outSize;
      curFinishMode = finishMode;
    }
    res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status);
    src += srcSizeCur;
    inSize -= srcSizeCur;
    *srcLen += srcSizeCur;
    outSizeCur = p->decoder.dicPos - dicPos;
    memcpy(dest, p->decoder.dic + dicPos, outSizeCur);
    dest += outSizeCur;
    outSize -= outSizeCur;
    *destLen += outSizeCur;
    if (res != 0)
      return res;
    if (outSizeCur == 0 || outSize == 0)
      return 0;
  }
}

canonical_original_code:
int Lzma2Dec_DecodeToBuf(struct CLzma2Dec *p, unsigned char *dest, unsigned long *destLen, unsigned char *src, unsigned long *srcLen, enum ELzmaFinishMode finishMode, enum ELzmaStatus *status)
{
  unsigned long outSize = *destLen; unsigned long inSize = *srcLen;
  *srcLen = *destLen = 0;
  for (;;)
  {
    unsigned long srcSizeCur = inSize; unsigned long outSizeCur; unsigned long dicPos;
    enum ELzmaFinishMode curFinishMode;
    int res;
    if (p->decoder.dicPos == p->decoder.dicBufSize)
      p->decoder.dicPos = 0;
    dicPos = p->decoder.dicPos;
    if (outSize > p->decoder.dicBufSize - dicPos)
    {
      outSizeCur = p->decoder.dicBufSize;
      curFinishMode = LZMA_FINISH_ANY;
    }
    else
    {
      outSizeCur = dicPos + outSize;
      curFinishMode = finishMode;
    }
    res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status);
    src += srcSizeCur;
    inSize -= srcSizeCur;
    *srcLen += srcSizeCur;
    outSizeCur = p->decoder.dicPos - dicPos;
    memcpy(dest, p->decoder.dic + dicPos, outSizeCur);
    dest += outSizeCur;
    outSize -= outSizeCur;
    *destLen += outSizeCur;
    if (res != 0)
      return res;
    if (outSizeCur == 0 || outSize == 0)
      return 0;
  }
}

variable_types: struct CLzma2Dec { struct CLzmaDec { struct _CLzmaProps { unsigned int lc; unsigned int dicSize; } prop; unsigned int *probs; unsigned char *dic; unsigned char *buf; unsigned int range; unsigned long dicPos; unsigned long dicBufSize; unsigned int processedPos; unsigned int checkDicSize; unsigned int state; unsigned int reps[4]; unsigned int remainLen; int needFlush; int needInitState; unsigned int numProbs; unsigned int tempBufSize; unsigned char tempBuf[20]; } decoder; unsigned int packSize; unsigned int unpackSize; int state; unsigned char control; int needInitDic; int needInitState; int needInitProp; } *

variable_types:
dest
unsigned char *

variable_types:
destLen
unsigned long *

variable_types:
src
unsigned char *

variable_types:
outSize
unsigned long

variable_types:
outSizeCur
unsigned long

user_defined_types: enum ELzmaFinishMode { LZMA_FINISH_ANY=0, LZMA_FINISH_END=1 }

user_defined_types: enum ELzmaStatus { LZMA_STATUS_NOT_SPECIFIED=0, LZMA_STATUS_FINISHED_WITH_MARK=1, LZMA_STATUS_NOT_FINISHED=2, LZMA_STATUS_NEEDS_MORE_INPUT=3, LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK=4 }


decompiled_code:
__int64 __fastcall Lzma2Decode(__int64 a1, __int64 *a2, unsigned __int8 *a3, __int64 *a4, unsigned __int8 a5, __int64 a6, int *a7, __int64 a8)
{
__int64 v10; // r14
__int64 v11; // r15
__int64 result; // rax
int v13; // er9
int v14; // ebp
int v15; // eax
unsigned int v16; // [rsp+Ch] [rbp-FCh]
char v17[5]; // [rsp+1Bh] [rbp-EDh] BYREF
char v18[16]; // [rsp+20h] [rbp-E8h] BYREF
__int64 v19; // [rsp+30h] [rbp-D8h]
__int64 v20; // [rsp+38h] [rbp-D0h]
__int64 v21; // [rsp+50h] [rbp-B8h]
__int64 v22; // [rsp+58h] [rbp-B0h]

v10 = *a2;
v11 = *a4;
*a4 = 0LL;
*a2 = 0LL;
v20 = a1;
*a7 = 0;
v19 = 0LL;
v22 = v10;
result = Lzma2Dec_GetOldProps(a5, v17);
if ( !(_DWORD)result )
{
v14 = v13;
result = LzmaDec_AllocateProbs(v18, v17, 5LL, a8);
if ( !(_DWORD)result )
{
*a4 = v11;
v15 = Lzma2Dec_DecodeToDic((__int64)v18, v10, a3, a4, v14, a7);
*a2 = v21;
if ( !v15 && *a7 == 3 )
v15 = 6;
v16 = v15;
LzmaDec_FreeProbs(v18, a8);
result = v16;
}
}
return result;
}

original_code:
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
    Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
{
  CLzma2Dec decoder;
  SRes res;
  SizeT outSize = *destLen, inSize = *srcLen;
  Byte props[5];
  { (&(&decoder)->decoder)->dic = 0; (&(&decoder)->decoder)->probs = 0; };
  *destLen = *srcLen = 0;
  *status = LZMA_STATUS_NOT_SPECIFIED;
  decoder.decoder.dic = dest;
  decoder.decoder.dicBufSize = outSize;
  { int __result__ = (Lzma2Dec_GetOldProps(prop, props)); if (__result__ != 0) return __result__; };
  { int __result__ = (LzmaDec_AllocateProbs(&decoder.decoder, props, 5, alloc)); if (__result__ != 0) return __result__; };
  *srcLen = inSize;
  res = Lzma2Dec_DecodeToDic(&decoder, outSize, src, srcLen, finishMode, status);
  *destLen = decoder.decoder.dicPos;
  if (res == 0 && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
    res = 6;
  LzmaDec_FreeProbs(&decoder.decoder, alloc);
  return res;
}

canonical_original_code:
int Lzma2Decode(unsigned char *dest, unsigned long *destLen, unsigned char *src, unsigned long *srcLen, unsigned char prop, enum ELzmaFinishMode finishMode, enum ELzmaStatus *status, struct ISzAlloc *alloc)
{
  struct CLzma2Dec decoder;
  int res;
  unsigned long outSize = *destLen; unsigned long inSize = *srcLen;
  unsigned char props[5];
  { (&(&decoder)->decoder)->dic = 0; (&(&decoder)->decoder)->probs = 0; };
  *destLen = *srcLen = 0;
  *status = LZMA_STATUS_NOT_SPECIFIED;
  decoder.decoder.dic = dest;
  decoder.decoder.dicBufSize = outSize;
  { int __result__ = (Lzma2Dec_GetOldProps(prop, props)); if (__result__ != 0) return __result__; };
  { int __result__ = (LzmaDec_AllocateProbs(&decoder.decoder, props, 5, alloc)); if (__result__ != 0) return __result__; };
  *srcLen = inSize;
  res = Lzma2Dec_DecodeToDic(&decoder, outSize, src, srcLen, finishMode, status);
  *destLen = decoder.decoder.dicPos;
  if (res == 0 && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
    res = 6;
  LzmaDec_FreeProbs(&decoder.decoder, alloc);
  return res;
}

variable_types:
srcLen
unsigned long *

variable_types:
prop
unsigned char

variable_types: enum ELzmaFinishMode { LZMA_FINISH_ANY=0, LZMA_FINISH_END=1 }

variable_types: struct ISzAlloc { void *(*Alloc)(void *p, unsigned long size); void (*Free)(void *p, void *address); } *

variable_types: struct CLzma2Dec { struct CLzmaDec { struct _CLzmaProps { unsigned int lc; unsigned int dicSize; } prop; unsigned int *probs; unsigned char *dic; unsigned char *buf; unsigned int range; unsigned long dicPos; unsigned long dicBufSize; unsigned int processedPos; unsigned int checkDicSize; unsigned int state; unsigned int reps[4]; unsigned int remainLen; int needFlush; int needInitState; unsigned int numProbs; unsigned int tempBufSize; unsigned char tempBuf[20]; } decoder; unsigned int packSize; unsigned int unpackSize; int state; unsigned char control; int needInitDic; int needInitState; int needInitProp; }

variable_types:
props
unsigned char [5]


decompiled_code:
const char *__fastcall GetMessageBZIP2(int a1, const char *a2)
{
const char *result; // rax

switch ( a1 )
{
case -9:
result = "CONFIG ERROR";
break;
case -7:
result = "UNEXPECTED EOF";
break;
case -6:
result = "IO ERROR";
break;
case -5:
result = "DATA ERROR MAGIC";
break;
case -4:
result = "DATA ERROR";
break;
case -3:
result = "MEM ERROR";
break;
case -2:
result = "PARAM ERROR";
break;
case -1:
result = "SEQUENCE ERROR";
break;
case 0:
result = (const char *)&unk_7ED;
break;
case 4:
result = "STREAM END";
break;
default:
result = a2;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1, const char *a2)
{
const char *result; // rax

switch ( a1 )
{
case -9:
result = "CONFIG ERROR";
break;
case -7:
result = "UNEXPECTED EOF";
break;
case -6:
result = "IO ERROR";
break;
case -5:
result = "DATA ERROR MAGIC";
break;
case -4:
result = "DATA ERROR";
break;
case -3:
result = "MEM ERROR";
break;
case -2:
result = "PARAM ERROR";
break;
case -1:
result = "SEQUENCE ERROR";
break;
case 0:
result = (const char *)&unk_7ED;
break;
case 4:
result = "STREAM END";
break;
default:
result = a2;
break;
}
return result;
}

original_code:
ccp GetMessageBZIP2
(
    int err,
    ccp unkown_error
)
{
    switch (err)
    {
 case 0: return "OK";
 case (-9): return "CONFIG ERROR";
 case (-4): return "DATA ERROR";
 case (-5): return "DATA ERROR MAGIC";
 case (-6): return "IO ERROR";
 case (-3): return "MEM ERROR";
 case (-2): return "PARAM ERROR";
 case (-1): return "SEQUENCE ERROR";
 case 4: return "STREAM END";
 case (-7): return "UNEXPECTED EOF";
    }
    return unkown_error;
}

canonical_original_code:
char *GetMessageBZIP2(int err, char *unkown_error)
{
    switch (err)
    {
 case 0: return "OK";
 case (-9): return "CONFIG ERROR";
 case (-4): return "DATA ERROR";
 case (-5): return "DATA ERROR MAGIC";
 case (-6): return "IO ERROR";
 case (-3): return "MEM ERROR";
 case (-2): return "PARAM ERROR";
 case (-1): return "SEQUENCE ERROR";
 case 4: return "STREAM END";
 case (-7): return "UNEXPECTED EOF";
    }
    return unkown_error;
}

variable_types: err int


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

result = 5LL;
if ( a1 > 0 )
{
result = 9LL;
if ( a1 <= 9 )
result = (unsigned int)a1;
}
return result;
}

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

result = 5LL;
if ( a1 > 0 )
{
result = 9LL;
if ( a1 <= 9 )
result = (unsigned int)a1;
}
return result;
}

original_code:
int CalcCompressionLevelBZIP2
(
    int compr_level
)
{
    return compr_level < 1
  ? 5
  : compr_level < 9
   ? compr_level
   : 9;
}

canonical_original_code:
int CalcCompressionLevelBZIP2(int compr_level)
{
    return compr_level < 1
  ? 5
  : compr_level < 9
   ? compr_level
   : 9;
}


decompiled_code:
__int64 __fastcall EncBZIP2buf(__int64 a1, int a2, _DWORD *a3, __int64 a4, __int64 a5, int a6)
{
unsigned int v7; // ecx
int v8; // eax
_DWORD *v9; // r10
int v10; // eax
int v11; // edi
__int64 result; // rax
__int64 v13; // rdx
__int64 v14; // rcx

CalcCompressionLevelBZIP2(a6);
v8 = _bswap_32(v7);
*v9 = v8;
*a3 = a2 - 4;
v10 = BZ2_bzBuffToBuffCompress(v9 + 1, a3);
*a3 += 4;
v11 = v10;
result = 0LL;
if ( v11 )
{
GetMessageBZIP2(v11, "?");
result = PrintError("EncBZIP2buf", "src/lib-bzip2.c", v13, v14, 24LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, _DWORD *a3, __int64 a4, __int64 a5, int a6)
{
unsigned int v7; // ecx
int v8; // eax
_DWORD *v9; // r10
int v10; // eax
int v11; // edi
__int64 result; // rax
__int64 v13; // rdx
__int64 v14; // rcx

func2(a6);
v8 = func0(v7);
*v9 = v8;
*a3 = a2 - 4;
v10 = BZ2_bzBuffToBuffCompress(v9 + 1, a3);
*a3 += 4;
v11 = v10;
result = 0LL;
if ( v11 )
{
func1(v11, "?");
result = PrintError("EncBZIP2buf", "src/lib-bzip2.c", v13, v14, 24LL);
}
return result;
}

original_code:
enumError EncBZIP2buf
(
    void *dest,
    uint dest_size,
    uint *dest_written,
    const void *src,
    uint src_size,
    int compr_level
)
{
    ;
    ;
    ;
    ;
    compr_level = CalcCompressionLevelBZIP2(compr_level);
    ;
    *(u32*)dest = htonl(src_size);
    *dest_written = dest_size - sizeof(u32);
    int bzerror = BZ2_bzBuffToBuffCompress ( dest+sizeof(u32), dest_written,
    (char*)src, src_size, compr_level, 0, 0 );
    *dest_written += 4;
    if ( bzerror != 0 )
 return PrintError(__FUNCTION__,"src/lib-bzip2.c",328,0,ERR_BZIP2,"Error while compressing data.\n-> bzip2 error: %s\n", GetMessageBZIP2(bzerror,"?"));
    return ERR_OK;
}

canonical_original_code:
enum enumError EncBZIP2buf(void *dest, unsigned int dest_size, unsigned int *dest_written, void *src, unsigned int src_size, int compr_level)
{
    ;
    ;
    ;
    ;
    compr_level = CalcCompressionLevelBZIP2(compr_level);
    ;
    *(unsigned int *)dest = htonl(src_size);
    *dest_written = dest_size - sizeof(u32);
    int bzerror = BZ2_bzBuffToBuffCompress ( dest+sizeof(u32), dest_written,
    (char*)src, src_size, compr_level, 0, 0 );
    *dest_written += 4;
    if ( bzerror != 0 )
 return PrintError(__FUNCTION__,"src/lib-bzip2.c",328,0,ERR_BZIP2,"Error while compressing data.\n-> bzip2 error: %s\n", GetMessageBZIP2(bzerror,"?"));
    return ERR_OK;
}

variable_types:
dest
void *

variable_types:
src
void *

variable_types: bzerror int

return_type: enum enumError { ERR_OK=0, ERR_DIFFER=1, ERR_NOTHING_TO_DO=2, ERR_NO_SOURCE_FOUND=3, ERR_JOB_IGNORED=4, ERR_WARNING=5, ERR_INVALID_FILE=6, ERR_INVALID_VERSION=7, ERR_NO_WDF=8, ERR_WDF_VERSION=9, ERR_WDF_SPLIT=10, ERR_WDF_INVALID=11, ERR_NO_CISO=12, ERR_CISO_INVALID=13, ERR_NO_GCZ=14, ERR_GCZ_INVALID=15, ERR_WPART_INVALID=16, ERR_WDISC_INVALID=17, ERR_WDISC_NOT_FOUND=18, ERR_NO_WBFS_FOUND=19, ERR_TO_MUCH_WBFS_FOUND=20, ERR_WBFS_INVALID=21, ERR_NO_WIA=22, ERR_WIA_INVALID=23, ERR_BZIP2=24, ERR_LZMA=25, ERR_ALREADY_EXISTS=26, ERR_CANT_OPEN=27, ERR_CANT_CREATE=28, ERR_CANT_CREATE_DIR=29, ERR_WRONG_FILE_TYPE=30, ERR_READ_FAILED=31, ERR_REMOVE_FAILED=32, ERR_WRITE_FAILED=33, ERR_WBFS=34, ERR_MISSING_PARAM=35, ERR_SEMANTIC=36, ERR_SYNTAX=37, ERR_INTERRUPT=38, ERR_ERROR=39, ERR_NOT_IMPLEMENTED=40, ERR_INTERNAL=41, ERR_OUT_OF_MEMORY=42, ERR_FATAL=43, ERR__N=44 }


decompiled_code:
__int64 __fastcall DecBZIP2buf(__int64 a1, __int64 a2, __int64 a3, unsigned int *a4)
{
int v5; // eax
_DWORD *v6; // rdx
__int64 v7; // rcx
unsigned int v8; // er10
__int64 v9; // r11
int v10; // edi
__int64 result; // rax
__int64 v12; // rdx
__int64 v13; // rcx

v5 = _bswap_32(*a4);
*v6 = v5;
v10 = BZ2_bzBuffToBuffDecompress(v9, a3, v7 + 4, v8);
result = 0LL;
if ( v10 )
{
GetMessageBZIP2(v10, "?");
result = PrintError("DecBZIP2buf", "src/lib-bzip2.c", v12, v13, 24LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, unsigned int *a4)
{
int v5; // eax
_DWORD *v6; // rdx
__int64 v7; // rcx
unsigned int v8; // er10
__int64 v9; // r11
int v10; // edi
__int64 result; // rax
__int64 v12; // rdx
__int64 v13; // rcx

v5 = func0(*a4);
*v6 = v5;
v10 = BZ2_bzBuffToBuffDecompress(v9, a3, v7 + 4, v8);
result = 0LL;
if ( v10 )
{
func1(v10, "?");
result = PrintError("DecBZIP2buf", "src/lib-bzip2.c", v12, v13, 24LL);
}
return result;
}

original_code:
enumError DecBZIP2buf
(
    void *dest,
    uint dest_size,
    uint *dest_written,
    const void *src,
    uint src_size
)
{
    ;
    ;
    ;
    ;
    uint dest_need = ntohl(*(u32*)src);
    *dest_written = dest_need;
    ;
    int bzerror = BZ2_bzBuffToBuffDecompress ( (char*)dest, dest_written,
    (char*)src+4, src_size-4, 0, 0 );
    if ( bzerror != 0 )
 return PrintError(__FUNCTION__,"src/lib-bzip2.c",406,0,ERR_BZIP2,"Error while decompressing data.\n-> bzip2 error: %s\n", GetMessageBZIP2(bzerror,"?"));
    return ERR_OK;
}

canonical_original_code:
enum enumError DecBZIP2buf(void *dest, unsigned int dest_size, unsigned int *dest_written, void *src, unsigned int src_size)
{
    ;
    ;
    ;
    ;
    unsigned int dest_need = ntohl(*(u32*)src);
    *dest_written = dest_need;
    ;
    int bzerror = BZ2_bzBuffToBuffDecompress ( (char*)dest, dest_written,
    (char*)src+4, src_size-4, 0, 0 );
    if ( bzerror != 0 )
 return PrintError(__FUNCTION__,"src/lib-bzip2.c",406,0,ERR_BZIP2,"Error while decompressing data.\n-> bzip2 error: %s\n", GetMessageBZIP2(bzerror,"?"));
    return ERR_OK;
}

user_defined_types: enum enumError { ERR_OK=0, ERR_DIFFER=1, ERR_NOTHING_TO_DO=2, ERR_NO_SOURCE_FOUND=3, ERR_JOB_IGNORED=4, ERR_WARNING=5, ERR_INVALID_FILE=6, ERR_INVALID_VERSION=7, ERR_NO_WDF=8, ERR_WDF_VERSION=9, ERR_WDF_SPLIT=10, ERR_WDF_INVALID=11, ERR_NO_CISO=12, ERR_CISO_INVALID=13, ERR_NO_GCZ=14, ERR_GCZ_INVALID=15, ERR_WPART_INVALID=16, ERR_WDISC_INVALID=17, ERR_WDISC_NOT_FOUND=18, ERR_NO_WBFS_FOUND=19, ERR_TO_MUCH_WBFS_FOUND=20, ERR_WBFS_INVALID=21, ERR_NO_WIA=22, ERR_WIA_INVALID=23, ERR_BZIP2=24, ERR_LZMA=25, ERR_ALREADY_EXISTS=26, ERR_CANT_OPEN=27, ERR_CANT_CREATE=28, ERR_CANT_CREATE_DIR=29, ERR_WRONG_FILE_TYPE=30, ERR_READ_FAILED=31, ERR_REMOVE_FAILED=32, ERR_WRITE_FAILED=33, ERR_WBFS=34, ERR_MISSING_PARAM=35, ERR_SEMANTIC=36, ERR_SYNTAX=37, ERR_INTERRUPT=38, ERR_ERROR=39, ERR_NOT_IMPLEMENTED=40, ERR_INTERNAL=41, ERR_OUT_OF_MEMORY=42, ERR_FATAL=43, ERR__N=44 }


decompiled_code:
__int64 __fastcall DecBZIP2(__int64 *a1, _DWORD *a2, unsigned int *a3)
{
unsigned int v4; // er12
__int64 v5; // rdx
__int64 v6; // rax
__int64 result; // rax
unsigned int v8; // [rsp+Ch] [rbp-2Ch]

v4 = _bswap_32(*a3);
v6 = my_malloc("DecBZIP2", "src/lib-bzip2.c", v5, v4);
*a1 = v6;
result = DecBZIP2buf(v6, v4, (__int64)a2, a3);
if ( (_DWORD)result )
{
v8 = result;
my_free(*a1);
*a1 = 0LL;
result = v8;
*a2 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 *a1, _DWORD *a2, unsigned int *a3)
{
unsigned int v4; // er12
__int64 v5; // rdx
__int64 v6; // rax
__int64 result; // rax
unsigned int v8; // [rsp+Ch] [rbp-2Ch]

v4 = func0(*a3);
v6 = my_malloc("DecBZIP2", "src/lib-bzip2.c", v5, v4);
*a1 = v6;
result = func12(v6, v4, (__int64)a2, a3);
if ( (_DWORD)result )
{
v8 = result;
my_free(*a1);
*a1 = 0LL;
result = v8;
*a2 = 0;
}
return result;
}

original_code:
enumError DecBZIP2
(
    u8 **dest_ptr,
    uint *dest_written,
    const void *src,
    uint src_size
)
{
    ;
    ;
    ;
    ;
    uint dest_size = ntohl(*(u32*)src);
    *dest_ptr = my_malloc(__FUNCTION__,"src/lib-bzip2.c",429,dest_size);
    enumError err = DecBZIP2buf(*dest_ptr,dest_size,dest_written,src,src_size);
    if (err)
    {
 my_free(*dest_ptr);
 *dest_ptr = 0;
 *dest_written = 0;
    }
    return err;
}

canonical_original_code:
enum enumError DecBZIP2(unsigned char **dest_ptr, unsigned int *dest_written, void *src, unsigned int src_size)
{
    ;
    ;
    ;
    ;
    unsigned int dest_size = ntohl(*(u32*)src);
    *dest_ptr = my_malloc(__FUNCTION__,"src/lib-bzip2.c",429,dest_size);
    enum enumError err = DecBZIP2buf(*dest_ptr,dest_size,dest_written,src,src_size);
    if (err)
    {
 my_free(*dest_ptr);
 *dest_ptr = 0;
 *dest_written = 0;
    }
    return err;
}

variable_types: enum enumError { ERR_OK=0, ERR_DIFFER=1, ERR_NOTHING_TO_DO=2, ERR_NO_SOURCE_FOUND=3, ERR_JOB_IGNORED=4, ERR_WARNING=5, ERR_INVALID_FILE=6, ERR_INVALID_VERSION=7, ERR_NO_WDF=8, ERR_WDF_VERSION=9, ERR_WDF_SPLIT=10, ERR_WDF_INVALID=11, ERR_NO_CISO=12, ERR_CISO_INVALID=13, ERR_NO_GCZ=14, ERR_GCZ_INVALID=15, ERR_WPART_INVALID=16, ERR_WDISC_INVALID=17, ERR_WDISC_NOT_FOUND=18, ERR_NO_WBFS_FOUND=19, ERR_TO_MUCH_WBFS_FOUND=20, ERR_WBFS_INVALID=21, ERR_NO_WIA=22, ERR_WIA_INVALID=23, ERR_BZIP2=24, ERR_LZMA=25, ERR_ALREADY_EXISTS=26, ERR_CANT_OPEN=27, ERR_CANT_CREATE=28, ERR_CANT_CREATE_DIR=29, ERR_WRONG_FILE_TYPE=30, ERR_READ_FAILED=31, ERR_REMOVE_FAILED=32, ERR_WRITE_FAILED=33, ERR_WBFS=34, ERR_MISSING_PARAM=35, ERR_SEMANTIC=36, ERR_SYNTAX=37, ERR_INTERRUPT=38, ERR_ERROR=39, ERR_NOT_IMPLEMENTED=40, ERR_INTERNAL=41, ERR_OUT_OF_MEMORY=42, ERR_FATAL=43, ERR__N=44 }


Progress

decompiled_code:
__int64 __fastcall Progress(__int64 (**a1)(void))
{
int v1; // er8
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = (*a1)();
result = 10LL;
if ( !v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 (**a1)(void))
{
int v1; // er8
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = (*a1)();
result = 10LL;
if ( !v1 )
result = 0LL;
return result;
}

original_code:
static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
{
  return (p && p->Progress(p, inSize, outSize) != 0) ? 10 : 0;
}

canonical_original_code:
static int Progress(struct ICompressProgress *p, unsigned long long inSize, unsigned long long outSize)
{
  return (p && p->Progress(p, inSize, outSize) != 0) ? 10 : 0;
}

variable_types: struct ICompressProgress { int (*Progress)(void *p, unsigned long long inSize, unsigned long long outSize); } *

variable_types:
inSize
unsigned long long

variable_types:
outSize
unsigned long long


decompiled_code:
__int64 __fastcall Lzma2EncInt_Init(__int64 *a1)
{
__int64 v2; // rdi
__int64 result; // rax
char v4; // dl
char v5[5]; // [rsp+3h] [rbp-15h] BYREF
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
v6 = 5LL;
result = LzmaEnc_SetProps(v2);
if ( !(_DWORD)result )
{
result = LzmaEnc_WriteProperties(*a1, v5, &v6);
if ( !(_DWORD)result )
{
v4 = v5[0];
a1[1] = 0LL;
*(__int64 *)((char *)a1 + 20) = 0x100000001LL;
*((_BYTE *)a1 + 16) = v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 v2; // rdi
__int64 result; // rax
char v4; // dl
char v5[5]; // [rsp+3h] [rbp-15h] BYREF
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

v2 = *a1;
v6 = 5LL;
result = LzmaEnc_SetProps(v2);
if ( !(_DWORD)result )
{
result = LzmaEnc_WriteProperties(*a1, v5, &v6);
if ( !(_DWORD)result )
{
v4 = v5[0];
a1[1] = 0LL;
*(__int64 *)((char *)a1 + 20) = 0x100000001LL;
*((_BYTE *)a1 + 16) = v4;
}
}
return result;
}

original_code:
static SRes Lzma2EncInt_Init(CLzma2EncInt *p, const CLzma2EncProps *props)
{
  Byte propsEncoded[5];
  SizeT propsSize = 5;
  { int __result__ = (LzmaEnc_SetProps(p->enc, &props->lzmaProps)); if (__result__ != 0) return __result__; };
  { int __result__ = (LzmaEnc_WriteProperties(p->enc, propsEncoded, &propsSize)); if (__result__ != 0) return __result__; };
  p->srcPos = 0;
  p->props = propsEncoded[0];
  p->needInitState = 1;
  p->needInitProp = 1;
  return 0;
}

canonical_original_code:
static int Lzma2EncInt_Init(struct CLzma2EncInt *p, struct CLzma2EncProps *props)
{
  unsigned char propsEncoded[5];
  unsigned long propsSize = 5;
  { int __result__ = (LzmaEnc_SetProps(p->enc, &props->lzmaProps)); if (__result__ != 0) return __result__; };
  { int __result__ = (LzmaEnc_WriteProperties(p->enc, propsEncoded, &propsSize)); if (__result__ != 0) return __result__; };
  p->srcPos = 0;
  p->props = propsEncoded[0];
  p->needInitState = 1;
  p->needInitProp = 1;
  return 0;
}

variable_types: struct CLzma2EncInt { void *enc; unsigned long long srcPos; unsigned char props; int needInitState; int needInitProp; } *

variable_types: struct CLzma2EncProps { struct _CLzmaEncProps { int level; unsigned int dictSize; int lc; int lp; int pb; int algo; int fb; int btMode; int numHashBytes; unsigned int mc; unsigned int writeEndMark; int numThreads; } lzmaProps; unsigned long blockSize; int numBlockThreads; int numTotalThreads; } *

variable_types:
propsEncoded
unsigned char [5]

variable_types:
propsSize
unsigned long

user_defined_types: struct CLzma2EncProps { struct _CLzmaEncProps lzmaProps; unsigned long blockSize; int numBlockThreads; int numTotalThreads; }


original_code:
static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
  ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)
{
  UInt64 packTotal = 0;
  SRes res = 0;
  if (mainEncoder->outBuf == 0)
  {
    mainEncoder->outBuf = (mainEncoder->alloc)->Alloc((mainEncoder->alloc), ((1 << 16) + 16));
    if (mainEncoder->outBuf == 0)
      return 2;
  }
  { int __result__ = (Lzma2EncInt_Init(p, &mainEncoder->props)); if (__result__ != 0) return __result__; };
  { int __result__ = (LzmaEnc_PrepareForLzma2(p->enc, inStream, (1 << 21), mainEncoder->alloc, mainEncoder->allocBig)); if (__result__ != 0) return __result__; };
  for (;;)
  {
    size_t packSize = ((1 << 16) + 16);
    res = Lzma2EncInt_EncodeSubblock(p, mainEncoder->outBuf, &packSize, outStream);
    if (res != 0)
      break;
    packTotal += packSize;
    res = Progress(progress, p->srcPos, packTotal);
    if (res != 0)
      break;
    if (packSize == 0)
      break;
  }
  LzmaEnc_Finish(p->enc);
  if (res == 0)
  {
    Byte b = 0;
    if (outStream->Write(outStream, &b, 1) != 1)
      return 9;
  }
  return res;
}

canonical_original_code:
static int Lzma2Enc_EncodeMt1(struct CLzma2EncInt *p, struct _CLzma2Enc *mainEncoder, struct ISeqOutStream *outStream, struct ISeqInStream *inStream, struct ICompressProgress *progress)
{
  unsigned long long packTotal = 0;
  int res = 0;
  if (mainEncoder->outBuf == 0)
  {
    mainEncoder->outBuf = (mainEncoder->alloc)->Alloc((mainEncoder->alloc), ((1 << 16) + 16));
    if (mainEncoder->outBuf == 0)
      return 2;
  }
  { int __result__ = (Lzma2EncInt_Init(p, &mainEncoder->props)); if (__result__ != 0) return __result__; };
  { int __result__ = (LzmaEnc_PrepareForLzma2(p->enc, inStream, (1 << 21), mainEncoder->alloc, mainEncoder->allocBig)); if (__result__ != 0) return __result__; };
  for (;;)
  {
    unsigned long packSize = ((1 << 16) + 16);
    res = Lzma2EncInt_EncodeSubblock(p, mainEncoder->outBuf, &packSize, outStream);
    if (res != 0)
      break;
    packTotal += packSize;
    res = Progress(progress, p->srcPos, packTotal);
    if (res != 0)
      break;
    if (packSize == 0)
      break;
  }
  LzmaEnc_Finish(p->enc);
  if (res == 0)
  {
    unsigned char b = 0;
    if (outStream->Write(outStream, &b, 1) != 1)
      return 9;
  }
  return res;
}

variable_types: struct _CLzma2Enc { unsigned char propEncoded; struct CLzma2EncProps { struct _CLzmaEncProps { int level; unsigned int dictSize; int lc; int lp; int pb; int algo; int fb; int btMode; int numHashBytes; unsigned int mc; unsigned int writeEndMark; int numThreads; } lzmaProps; unsigned long blockSize; int numBlockThreads; int numTotalThreads; } props; unsigned char *outBuf; struct ISzAlloc { void *(*Alloc)(void *p, unsigned long size); void (*Free)(void *p, void *address); } *alloc; struct ISzAlloc *allocBig; struct CLzma2EncInt coders[1]; } *

variable_types: struct ISeqOutStream { unsigned long (*Write)(void *p, void *buf, unsigned long size); } *

variable_types: struct ISeqInStream { int (*Read)(void *p, void *buf, unsigned long *size); } *

variable_types:
packTotal
unsigned long long

variable_types: res int

variable_types:
packSize
unsigned long

variable_types:
b
unsigned char

user_defined_types: struct CLzma2EncInt { void *enc; unsigned long long srcPos; unsigned char props; int needInitState; int needInitProp; }

user_defined_types: struct _CLzma2Enc { unsigned char propEncoded; struct CLzma2EncProps props; unsigned char *outBuf; struct ISzAlloc *alloc; struct ISzAlloc *allocBig; struct CLzma2EncInt coders[1]; }

user_defined_types: struct ICompressProgress { int (*Progress)(void *p, unsigned long long inSize, unsigned long long outSize); }


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

result = LzmaEncProps_Init();
*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 56) = -1LL;
return result;
}

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

result = LzmaEncProps_Init();
*(_QWORD *)(a1 + 48) = 0LL;
*(_QWORD *)(a1 + 56) = -1LL;
return result;
}

original_code:
void Lzma2EncProps_Init(CLzma2EncProps *p)
{
  LzmaEncProps_Init(&p->lzmaProps);
  p->numTotalThreads = -1;
  p->numBlockThreads = -1;
  p->blockSize = 0;
}

canonical_original_code:
void Lzma2EncProps_Init(struct CLzma2EncProps *p)
{
  LzmaEncProps_Init(&p->lzmaProps);
  p->numTotalThreads = -1;
  p->numBlockThreads = -1;
  p->blockSize = 0;
}

user_defined_types: struct _CLzmaEncProps { int level; unsigned int dictSize; int lc; int lp; int pb; int algo; int fb; int btMode; int numHashBytes; unsigned int mc; unsigned int writeEndMark; int numThreads; }


original_code:
void Lzma2EncProps_Normalize(CLzma2EncProps *p)
{
  int t1, t1n, t2, t3;
  {
    CLzmaEncProps lzmaProps = p->lzmaProps;
    LzmaEncProps_Normalize(&lzmaProps);
    t1n = lzmaProps.numThreads;
  }
  t1 = p->lzmaProps.numThreads;
  t2 = p->numBlockThreads;
  t3 = p->numTotalThreads;
  if (t2 > 1)
    t2 = 1;
  if (t3 <= 0)
  {
    if (t2 <= 0)
      t2 = 1;
    t3 = t1n * t2;
  }
  else if (t2 <= 0)
  {
    t2 = t3 / t1n;
    if (t2 == 0)
    {
      t1 = 1;
      t2 = t3;
    }
    if (t2 > 1)
      t2 = 1;
  }
  else if (t1 <= 0)
  {
    t1 = t3 / t2;
    if (t1 == 0)
      t1 = 1;
  }
  else
    t3 = t1n * t2;
  p->lzmaProps.numThreads = t1;
  p->numBlockThreads = t2;
  p->numTotalThreads = t3;
  LzmaEncProps_Normalize(&p->lzmaProps);
  if (p->blockSize == 0)
  {
    UInt32 dictSize = p->lzmaProps.dictSize;
    UInt64 blockSize = (UInt64)dictSize << 2;
    const UInt32 kMinSize = (UInt32)1 << 20;
    const UInt32 kMaxSize = (UInt32)1 << 28;
    if (blockSize < kMinSize) blockSize = kMinSize;
    if (blockSize > kMaxSize) blockSize = kMaxSize;
    if (blockSize < dictSize) blockSize = dictSize;
    p->blockSize = (size_t)blockSize;
  }
}

canonical_original_code:
void Lzma2EncProps_Normalize(struct CLzma2EncProps *p)
{
  int t1; int t1n; int t2; int t3;
  {
    struct _CLzmaEncProps lzmaProps = p->lzmaProps;
    LzmaEncProps_Normalize(&lzmaProps);
    t1n = lzmaProps.numThreads;
  }
  t1 = p->lzmaProps.numThreads;
  t2 = p->numBlockThreads;
  t3 = p->numTotalThreads;
  if (t2 > 1)
    t2 = 1;
  if (t3 <= 0)
  {
    if (t2 <= 0)
      t2 = 1;
    t3 = t1n * t2;
  }
  else if (t2 <= 0)
  {
    t2 = t3 / t1n;
    if (t2 == 0)
    {
      t1 = 1;
      t2 = t3;
    }
    if (t2 > 1)
      t2 = 1;
  }
  else if (t1 <= 0)
  {
    t1 = t3 / t2;
    if (t1 == 0)
      t1 = 1;
  }
  else
    t3 = t1n * t2;
  p->lzmaProps.numThreads = t1;
  p->numBlockThreads = t2;
  p->numTotalThreads = t3;
  LzmaEncProps_Normalize(&p->lzmaProps);
  if (p->blockSize == 0)
  {
    unsigned int dictSize = p->lzmaProps.dictSize;
    unsigned long long blockSize = (UInt64)dictSize << 2;
    unsigned int kMinSize = (UInt32)1 << 20;
    unsigned int kMaxSize = (UInt32)1 << 28;
    if (blockSize < kMinSize) blockSize = kMinSize;
    if (blockSize > kMaxSize) blockSize = kMaxSize;
    if (blockSize < dictSize) blockSize = dictSize;
    p->blockSize = (unsigned long)blockSize;
  }
}

variable_types: struct _CLzmaEncProps { int level; unsigned int dictSize; int lc; int lp; int pb; int algo; int fb; int btMode; int numHashBytes; unsigned int mc; unsigned int writeEndMark; int numThreads; }

variable_types:
dictSize
unsigned int

variable_types:
blockSize
unsigned long long

variable_types:
kMinSize
unsigned int

variable_types:
kMaxSize
unsigned int


original_code:
void Lzma2Enc_Destroy(CLzma2EncHandle pp)
{
  CLzma2Enc *p = (CLzma2Enc *)pp;
  unsigned i;
  for (i = 0; i < 1; i++)
  {
    CLzma2EncInt *t = &p->coders[i];
    if (t->enc)
    {
      LzmaEnc_Destroy(t->enc, p->alloc, p->allocBig);
      t->enc = 0;
    }
  }
  (p->alloc)->Free((p->alloc), p->outBuf);
  (p->alloc)->Free((p->alloc), pp);
}

canonical_original_code:
void Lzma2Enc_Destroy(void *pp)
{
  struct _CLzma2Enc *p = (CLzma2Enc *)pp;
  unsigned int i;
  for (i = 0; i < 1; i++)
  {
    struct CLzma2EncInt *t = &p->coders[i];
    if (t->enc)
    {
      LzmaEnc_Destroy(t->enc, p->alloc, p->allocBig);
      t->enc = 0;
    }
  }
  (p->alloc)->Free((p->alloc), p->outBuf);
  (p->alloc)->Free((p->alloc), pp);
}

variable_types:
pp
void *

variable_types: struct _CLzma2Enc { unsigned char propEncoded; struct CLzma2EncProps { struct _CLzmaEncProps { int level; unsigned int dictSize; int lc; int lp; int pb; int algo; int fb; int btMode; int numHashBytes; unsigned int mc; unsigned int writeEndMark; int numThreads; } lzmaProps; unsigned long blockSize; int numBlockThreads; int numTotalThreads; } props; unsigned char *outBuf; struct ISzAlloc { void *(*Alloc)(void *p, unsigned long size); void (*Free)(void *p, void *address); } *alloc; struct ISzAlloc *allocBig; struct CLzma2EncInt { void *enc; unsigned long long srcPos; unsigned char props; int needInitState; int needInitProp; } coders[1]; } *

variable_types:
i
unsigned int


original_code:
SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props)
{
  CLzma2Enc *p = (CLzma2Enc *)pp;
  CLzmaEncProps lzmaProps = props->lzmaProps;
  LzmaEncProps_Normalize(&lzmaProps);
  if (lzmaProps.lc + lzmaProps.lp > 4)
    return 5;
  p->props = *props;
  Lzma2EncProps_Normalize(&p->props);
  return 0;
}

canonical_original_code:
int Lzma2Enc_SetProps(void *pp, struct CLzma2EncProps *props)
{
  struct _CLzma2Enc *p = (CLzma2Enc *)pp;
  struct _CLzmaEncProps lzmaProps = props->lzmaProps;
  LzmaEncProps_Normalize(&lzmaProps);
  if (lzmaProps.lc + lzmaProps.lp > 4)
    return 5;
  p->props = *props;
  Lzma2EncProps_Normalize(&p->props);
  return 0;
}

variable_types: struct CLzma2EncProps { struct _CLzmaEncProps { int level; unsigned int dictSize; int lc; int lp; int pb; int algo; int fb; int btMode; int numHashBytes; unsigned int mc; unsigned int writeEndMark; int numThreads; } lzmaProps; unsigned long blockSize; int numBlockThreads; int numTotalThreads; } *


decompiled_code:
__int64 __fastcall Lzma2Enc_WriteProperties(__int64 a1)
{
unsigned int v1; // esi
__int64 result; // rax
unsigned int v3; // er8
char v4; // di

v1 = LzmaEncProps_GetDictSize(a1 + 8);
result = 0LL;
while ( (unsigned __int64)((result & 1 | 2) << ((unsigned __int8)((unsigned int)result >> 1) + 11)) < v1 )
{
v3 = result + 1;
v4 = result + 1;
result = (unsigned int)(result + 1);
if ( (v4 & 1 | 2u) << ((v3 >> 1) + 11) >= v1 )
break;
result = (unsigned int)(result + 1);
if ( (unsigned __int64)((result & 1 | 2) << ((unsigned __int8)((unsigned int)result >> 1) + 11)) >= v1 )
break;
result = v3 + 2;
if ( (v3 & 1 | 2) << (((v3 + 2) >> 1) + 11) >= v1 )
break;
result = v3 + 3;
if ( (((_BYTE)v3 + 3) & 1 | 2u) << (((v3 + 3) >> 1) + 11) >= v1 )
break;
result = v3 + 4;
if ( (v3 & 1 | 2) << (((v3 + 4) >> 1) + 11) >= v1 )
break;
result = v3 + 5;
if ( (((_BYTE)v3 + 5) & 1 | 2u) << (((v3 + 5) >> 1) + 11) >= v1 )
break;
result = v3 + 6;
if ( (v3 & 1 | 2) << (((v3 + 6) >> 1) + 11) >= v1 )
break;
result = v3 + 7;
if ( v3 == 33 )
return 40LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned int v1; // esi
__int64 result; // rax
unsigned int v3; // er8
char v4; // di

v1 = LzmaEncProps_GetDictSize(a1 + 8);
result = 0LL;
while ( (unsigned __int64)((result & 1 | 2) << ((unsigned __int8)((unsigned int)result >> 1) + 11)) < v1 )
{
v3 = result + 1;
v4 = result + 1;
result = (unsigned int)(result + 1);
if ( (v4 & 1 | 2u) << ((v3 >> 1) + 11) >= v1 )
break;
result = (unsigned int)(result + 1);
if ( (unsigned __int64)((result & 1 | 2) << ((unsigned __int8)((unsigned int)result >> 1) + 11)) >= v1 )
break;
result = v3 + 2;
if ( (v3 & 1 | 2) << (((v3 + 2) >> 1) + 11) >= v1 )
break;
result = v3 + 3;
if ( (((_BYTE)v3 + 3) & 1 | 2u) << (((v3 + 3) >> 1) + 11) >= v1 )
break;
result = v3 + 4;
if ( (v3 & 1 | 2) << (((v3 + 4) >> 1) + 11) >= v1 )
break;
result = v3 + 5;
if ( (((_BYTE)v3 + 5) & 1 | 2u) << (((v3 + 5) >> 1) + 11) >= v1 )
break;
result = v3 + 6;
if ( (v3 & 1 | 2) << (((v3 + 6) >> 1) + 11) >= v1 )
break;
result = v3 + 7;
if ( v3 == 33 )
return 40LL;
}
return result;
}

original_code:
Byte Lzma2Enc_WriteProperties(CLzma2EncHandle pp)
{
  CLzma2Enc *p = (CLzma2Enc *)pp;
  unsigned i;
  UInt32 dicSize = LzmaEncProps_GetDictSize(&p->props.lzmaProps);
  for (i = 0; i < 40; i++)
    if (dicSize <= (((UInt32)2 | ((i) & 1)) << ((i) / 2 + 11)))
      break;
  return (Byte)i;
}

canonical_original_code:
unsigned char Lzma2Enc_WriteProperties(void *pp)
{
  struct _CLzma2Enc *p = (CLzma2Enc *)pp;
  unsigned int i;
  unsigned int dicSize = LzmaEncProps_GetDictSize(&p->props.lzmaProps);
  for (i = 0; i < 40; i++)
    if (dicSize <= (((unsigned int)2 | ((i) & 1)) << ((i) / 2 + 11)))
      break;
  return (unsigned char)i;
}

variable_types:
dicSize
unsigned int

return_type: unsigned char


original_code:
SRes Lzma2Enc_Encode(CLzma2EncHandle pp,
    ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)
{
  CLzma2Enc *p = (CLzma2Enc *)pp;
  int i;
  for (i = 0; i < p->props.numBlockThreads; i++)
  {
    CLzma2EncInt *t = &p->coders[i];
    if (t->enc == ((void *)0))
    {
      t->enc = LzmaEnc_Create(p->alloc);
      if (t->enc == ((void *)0))
        return 2;
    }
  }
    return Lzma2Enc_EncodeMt1(&p->coders[0], p, outStream, inStream, progress);
}

canonical_original_code:
int Lzma2Enc_Encode(void *pp, struct ISeqOutStream *outStream, struct ISeqInStream *inStream, struct ICompressProgress *progress)
{
  struct _CLzma2Enc *p = (CLzma2Enc *)pp;
  int i;
  for (i = 0; i < p->props.numBlockThreads; i++)
  {
    struct CLzma2EncInt *t = &p->coders[i];
    if (t->enc == ((void *)0))
    {
      t->enc = LzmaEnc_Create(p->alloc);
      if (t->enc == ((void *)0))
        return 2;
    }
  }
    return Lzma2Enc_EncodeMt1(&p->coders[0], p, outStream, inStream, progress);
}

variable_types: struct ICompressProgress { int (*Progress)(void *p, unsigned long long inSize, unsigned long long outSize); } *

variable_types: i int

variable_types: struct CLzma2EncInt { void *enc; unsigned long long srcPos; unsigned char props; int needInitState; int needInitProp; } *

user_defined_types: struct ISeqOutStream { unsigned long (*Write)(void *p, void *buf, unsigned long size); }

user_defined_types: struct ISeqInStream { int (*Read)(void *p, void *buf, unsigned long *size); }


original_code:
int WIT_SHA1_Update (WIT_SHA_CTX *c, const void *data_, size_t len)
 {
 const unsigned char *data=data_;
 unsigned char *p;
 unsigned int l;
 size_t n;
 if (len==0) return 1;
 l=(c->Nl+(((unsigned int)len)<<3))&0xffffffffUL;
 if (l < c->Nl)
  c->Nh++;
 c->Nh+=(unsigned int)(len>>29);
 c->Nl=l;
 n = c->num;
 if (n != 0)
  {
  p=(unsigned char *)c->data;
  if (len >= (16*4) || len+n >= (16*4))
   {
   memcpy (p+n,data,(16*4)-n);
   wit_sha1_block_data_order (c,p,1);
   n = (16*4)-n;
   data += n;
   len -= n;
   c->num = 0;
   memset (p,0,(16*4));
   }
  else
   {
   memcpy (p+n,data,len);
   c->num += (unsigned int)len;
   return 1;
   }
  }
 n = len/(16*4);
 if (n > 0)
  {
  wit_sha1_block_data_order (c,data,n);
  n *= (16*4);
  data += n;
  len -= n;
  }
 if (len != 0)
  {
  p = (unsigned char *)c->data;
  c->num = (unsigned int)len;
  memcpy (p,data,len);
  }
 return 1;
 }

canonical_original_code:
int WIT_SHA1_Update(struct WIT_SHAstate_st *c, void *data_, unsigned long len)
 {
 unsigned char *data = data_;
 unsigned char *p;
 unsigned int l;
 unsigned long n;
 if (len==0) return 1;
 l=(c->Nl+(((unsigned int)len)<<3))&0xffffffffUL;
 if (l < c->Nl)
  c->Nh++;
 c->Nh+=(unsigned int)(len>>29);
 c->Nl=l;
 n = c->num;
 if (n != 0)
  {
  p=(unsigned char *)c->data;
  if (len >= (16*4) || len+n >= (16*4))
   {
   memcpy (p+n,data,(16*4)-n);
   wit_sha1_block_data_order (c,p,1);
   n = (16*4)-n;
   data += n;
   len -= n;
   c->num = 0;
   memset (p,0,(16*4));
   }
  else
   {
   memcpy (p+n,data,len);
   c->num += (unsigned int)len;
   return 1;
   }
  }
 n = len/(16*4);
 if (n > 0)
  {
  wit_sha1_block_data_order (c,data,n);
  n *= (16*4);
  data += n;
  len -= n;
  }
 if (len != 0)
  {
  p = (unsigned char *)c->data;
  c->num = (unsigned int)len;
  memcpy (p,data,len);
  }
 return 1;
 }

variable_types: struct WIT_SHAstate_st { unsigned int h0; unsigned int Nl; unsigned int data[16]; unsigned int num; } *

variable_types:
len
unsigned long

variable_types:
data
unsigned char *

variable_types:
p
unsigned char *

variable_types:
l
unsigned int

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall WIT_SHA1_Transform(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return wit_sha1_block_data_order(a1, a2, 1LL, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return wit_sha1_block_data_order(a1, a2, 1LL, a4, a5);
}

original_code:
void WIT_SHA1_Transform (WIT_SHA_CTX *c, const unsigned char *data)
 {
 wit_sha1_block_data_order (c,data,1);
 }

canonical_original_code:
void WIT_SHA1_Transform(struct WIT_SHAstate_st *c, unsigned char *data)
 {
 wit_sha1_block_data_order (c,data,1);
 }

user_defined_types: struct WIT_SHAstate_st { unsigned int h0; unsigned int Nl; unsigned int data[16]; unsigned int num; }


canonical_original_code:
int WIT_SHA1_Final(unsigned char *md, struct WIT_SHAstate_st *c)
 {
 unsigned char *p = (unsigned char *)c->data;
 unsigned long n = c->num;
 p[n] = 0x80;
 n++;
 if (n > ((16*4)-8))
  {
  memset (p+n,0,(16*4)-n);
  n=0;
  wit_sha1_block_data_order (c,p,1);
  }
 memset (p+n,0,(16*4)-8-n);
 p += (16*4)-8;
 (void)({ unsigned int r = (c->Nh); asm ("bswapl %0":"=r"(r):"0"(r)); *((unsigned int *)(p))=r; (p)+=4; r; });
 (void)({ unsigned int r = (c->Nl); asm ("bswapl %0":"=r"(r):"0"(r)); *((unsigned int *)(p))=r; (p)+=4; r; });
 p -= (16*4);
 wit_sha1_block_data_order (c,p,1);
 c->num=0;
 memset (p,0,(16*4));
 do { unsigned long ll; ll=(c)->h0; ({ unsigned int r = (ll); asm ("bswapl %0":"=r"(r):"0"(r)); *((unsigned int *)((md)))=r; ((md))+=4; r; }); ll=(c)->h1; ({ unsigned int r = (ll); asm ("bswapl %0":"=r"(r):"0"(r)); *((unsigned int *)((md)))=r; ((md))+=4; r; }); ll=(c)->h2; ({ unsigned int r = (ll); asm ("bswapl %0":"=r"(r):"0"(r)); *((unsigned int *)((md)))=r; ((md))+=4; r; }); ll=(c)->h3; ({ unsigned int r = (ll); asm ("bswapl %0":"=r"(r):"0"(r)); *((unsigned int *)((md)))=r; ((md))+=4; r; }); ll=(c)->h4; ({ unsigned int r = (ll); asm ("bswapl %0":"=r"(r):"0"(r)); *((unsigned int *)((md)))=r; ((md))+=4; r; }); } while (0);
 return 1;
 }

variable_types:
md
unsigned char *

variable_types:
r
unsigned int

variable_types:
ll
unsigned long


original_code:
int WIT_SHA1_Init (WIT_SHA_CTX *c)
 {
 memset (c,0,sizeof(*c));
 c->h0=0x67452301UL;
 c->h1=0xefcdab89UL;
 c->h2=0x98badcfeUL;
 c->h3=0x10325476UL;
 c->h4=0xc3d2e1f0UL;
 return 1;
 }

canonical_original_code:
int WIT_SHA1_Init(struct WIT_SHAstate_st *c)
 {
 memset (c,0,sizeof(*c));
 c->h0=0x67452301UL;
 c->h1=0xefcdab89UL;
 c->h2=0x98badcfeUL;
 c->h3=0x10325476UL;
 c->h4=0xc3d2e1f0UL;
 return 1;
 }


decompiled_code:
void *__fastcall WIT_SHA1(__int64 a1, __int64 a2, void *a3)
{
void *v3; // rbx
int v4; // er8
void *result; // rax
_BYTE v6[120]; // [rsp+0h] [rbp-78h] BYREF

v3 = &m_0;
if ( a3 )
v3 = a3;
v4 = WIT_SHA1_Init(v6);
result = 0LL;
if ( v4 )
{
WIT_SHA1_Update(v6, a1, a2);
WIT_SHA1_Final(v3, v6);
result = v3;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, __int64 a2, void *a3)
{
void *v3; // rbx
int v4; // er8
void *result; // rax
_BYTE v6[120]; // [rsp+0h] [rbp-78h] BYREF

v3 = &m_0;
if ( a3 )
v3 = a3;
v4 = WIT_SHA1_Init(v6);
result = 0LL;
if ( v4 )
{
WIT_SHA1_Update(v6, a1, a2);
WIT_SHA1_Final(v3, v6);
result = v3;
}
return result;
}

original_code:
unsigned char *WIT_SHA1(const unsigned char *d, size_t n, unsigned char *md)
{
 WIT_SHA_CTX c;
 static unsigned char m[20];
 if (md == ((void *)0)) md=m;
 if (!WIT_SHA1_Init(&c))
  return ((void *)0);
 WIT_SHA1_Update(&c,d,n);
 WIT_SHA1_Final(md,&c);
 return(md);
}

canonical_original_code:
unsigned char *WIT_SHA1(unsigned char *d, unsigned long n, unsigned char *md)
{
 struct WIT_SHAstate_st c;
 static unsigned char m[20];
 if (md == ((void *)0)) md=m;
 if (!WIT_SHA1_Init(&c))
  return ((void *)0);
 WIT_SHA1_Update(&c,d,n);
 WIT_SHA1_Final(md,&c);
 return(md);
}

variable_types:
d
unsigned char *

variable_types: struct WIT_SHAstate_st { unsigned int h0; unsigned int Nl; unsigned int data[16]; unsigned int num; }

variable_types:
m
unsigned char [20]

return_type: unsigned char *


isFileExist

repo: misaka-mikoto/bkx

decompiled_code:
_BOOL8 __fastcall isFileExist(const char *a1)
{
return access(a1, 0) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
return access(a1, 0) == 0;
}

original_code:
int isFileExist(char *route)
{
 if(access(route,0)==0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

variable_types:
route
char *


isFileCanRead

decompiled_code:
_BOOL8 __fastcall isFileCanRead(const char *a1)
{
return access(a1, 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
return access(a1, 4) == 0;
}

original_code:
int isFileCanRead(char *route)
{
 if(access(route,4)==0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}


isFileCanWrite

decompiled_code:
_BOOL8 __fastcall isFileCanWrite(const char *a1)
{
return access(a1, 2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1)
{
return access(a1, 2) == 0;
}

original_code:
int isFileCanWrite(char *route)
{
        if(access(route,2)==0)
        {
                return 1;
        }
        else
        {
                return 0;
        }
}


isDirectory

decompiled_code:
_BOOL8 __fastcall isDirectory(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return (v2.st_mode & 0xF000) == 0x4000;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return (v2.st_mode & 0xF000) == 0x4000;
}

original_code:
int isDirectory(char *route)
{
 struct stat fileInfo;
 stat(route,&fileInfo);
 if(((((fileInfo.st_mode)) & 0170000) == (0040000)))
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


makeDir

decompiled_code:
__int64 __fastcall makeDir(char *a1, __mode_t a2)
{
char v2; // al
__int64 v3; // rbx
char v5; // [rsp+1h] [rbp-419h]
__int128 v6; // [rsp+2h] [rbp-418h] BYREF
char v7[1008]; // [rsp+12h] [rbp-408h] BYREF

v6 = 0LL;
memset(v7, 0, sizeof(v7));
v2 = *a1;
if ( *a1 )
{
v3 = 1LL;
do
{
while ( 1 )
{
*(&v5 + v3) = v2;
v2 = a1[v3];
if ( v2 == 47 )
break;
++v3;
if ( !v2 )
return 1LL;
}
if ( !(unsigned int)isFileExist(&v6) )
mkdir((const char *)&v6, a2);
v2 = a1[v3++];
}
while ( v2 );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __mode_t a2)
{
char v2; // al
__int64 v3; // rbx
char v5; // [rsp+1h] [rbp-419h]
__int128 v6; // [rsp+2h] [rbp-418h] BYREF
char v7[1008]; // [rsp+12h] [rbp-408h] BYREF

v6 = 0LL;
memset(v7, 0, sizeof(v7));
v2 = *a1;
if ( *a1 )
{
v3 = 1LL;
do
{
while ( 1 )
{
*(&v5 + v3) = v2;
v2 = a1[v3];
if ( v2 == 47 )
break;
++v3;
if ( !v2 )
return 1LL;
}
if ( !(unsigned int)isFileExist(&v6) )
mkdir((const char *)&v6, a2);
v2 = a1[v3++];
}
while ( v2 );
}
return 1LL;
}

original_code:
int makeDir(char *filePath)
{
 char cachePath[1024]={0};
 int i=0;
 while(filePath[i]!='\0')
 {
         cachePath[i]=filePath[i];
         if(filePath[i+1]=='/')
           if(!isFileExist(cachePath))
   {
                  mkdir(cachePath);
            }
          i++;
 }
 return 1;
}

canonical_original_code:
int makeDir(char *filePath)
{
 char cachePath[1024] = {0};
 int i = 0;
 while(filePath[i]!='\0')
 {
         cachePath[i]=filePath[i];
         if(filePath[i+1]=='/')
           if(!isFileExist(cachePath))
   {
                  mkdir(cachePath);
            }
          i++;
 }
 return 1;
}

variable_types:
filePath
char *

variable_types:
cachePath
char [1024]


reply

decompiled_code:
__int64 __fastcall reply(char *filename)
{
__int64 v1; // rbp
__int64 result; // rax

v1 = (int)varyAdd();
if ( !(unsigned int)isFileExist(v1) )
return ERROR(10LL);
if ( !(unsigned int)isFileCanRead(v1) )
return ERROR(7LL);
if ( (unsigned int)isDirectory(v1) )
return ERROR(10LL);
if ( (unsigned int)isFileExist(filename) && remove(filename) == -1 )
ERROR(9LL);
result = fileCopy(v1, filename);
if ( (_DWORD)result )
exit(0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *filename)
{
__int64 v1; // rbp
__int64 result; // rax

v1 = (int)varyAdd();
if ( !(unsigned int)isFileExist(v1) )
return ERROR(10LL);
if ( !(unsigned int)isFileCanRead(v1) )
return ERROR(7LL);
if ( (unsigned int)isDirectory(v1) )
return ERROR(10LL);
if ( (unsigned int)isFileExist(filename) && remove(filename) == -1 )
ERROR(9LL);
result = fileCopy(v1, filename);
if ( (_DWORD)result )
exit(0);
return result;
}

original_code:
int reply(char *sourcePath)
{
        char *bkDir="/usr/local/share/bkx_backup_directory";
        char *backupPath=varyAdd(sourcePath);
 if(!isFileExist(backupPath))
        {
  ERROR(10);
 }
        else if(!isFileCanRead(backupPath))
        {
  ERROR(7);
 }
        else if(isDirectory(backupPath))
        {
  ERROR(10);
 }
        else
        {
  if(isFileExist(sourcePath))
         {
                 if(remove(sourcePath)==-1)
                         ERROR(9);
         }
                if(fileCopy(backupPath,sourcePath))
                {
   exit(0);
  }
        }
}

canonical_original_code:
int reply(char *sourcePath)
{
        char *bkDir = "/usr/local/share/bkx_backup_directory";
        char *backupPath = varyAdd(sourcePath);
 if(!isFileExist(backupPath))
        {
  ERROR(10);
 }
        else if(!isFileCanRead(backupPath))
        {
  ERROR(7);
 }
        else if(isDirectory(backupPath))
        {
  ERROR(10);
 }
        else
        {
  if(isFileExist(sourcePath))
         {
                 if(remove(sourcePath)==-1)
                         ERROR(9);
         }
                if(fileCopy(backupPath,sourcePath))
                {
   exit(0);
  }
        }
}

variable_types:
sourcePath
char *

variable_types:
bkDir
char *

variable_types:
backupPath
char *


help

decompiled_code:
int help()
{
return puts("Backup file:\n-s <source path>\nReply file:\n-r <original path>");
}

canonical_decompiled_code:
int func0()
{
return puts("Backup file:\n-s <source path>\nReply file:\n-r <original path>");
}

original_code:
int help()
{
 printf("Backup file:\n-s <source path>\nReply file:\n-r <original path>\n");
}


save

decompiled_code:
__int64 __fastcall save(__int64 a1)
{
const char *v2; // r12
__int64 result; // rax
__int64 v4; // rdi

v2 = (const char *)(int)varyAdd();
if ( !(unsigned int)isFileExist(a1) )
return ERROR(5LL);
if ( !(unsigned int)isFileCanRead(a1) )
return ERROR(3LL);
v4 = 4LL;
if ( (unsigned int)isDirectory(a1) )
return ERROR(v4);
if ( !(unsigned int)isFileExist("/usr/local/share/bkx_backup_directory") )
return ERROR(8LL);
if ( !(unsigned int)isDirectory("/usr/local/share/bkx_backup_directory")
|| !(unsigned int)isFileCanWrite("/usr/local/share/bkx_backup_directory") )
{
v4 = 7LL;
return ERROR(v4);
}
if ( (unsigned int)isFileExist(v2) && remove(v2) == -1 )
ERROR(9LL);
result = fileCopy(a1, v2);
if ( (_DWORD)result )
exit(0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char *v2; // r12
__int64 result; // rax
__int64 v4; // rdi

v2 = (const char *)(int)varyAdd();
if ( !(unsigned int)isFileExist(a1) )
return ERROR(5LL);
if ( !(unsigned int)isFileCanRead(a1) )
return ERROR(3LL);
v4 = 4LL;
if ( (unsigned int)isDirectory(a1) )
return ERROR(v4);
if ( !(unsigned int)isFileExist("/usr/local/share/bkx_backup_directory") )
return ERROR(8LL);
if ( !(unsigned int)isDirectory("/usr/local/share/bkx_backup_directory")
|| !(unsigned int)isFileCanWrite("/usr/local/share/bkx_backup_directory") )
{
v4 = 7LL;
return ERROR(v4);
}
if ( (unsigned int)isFileExist(v2) && remove(v2) == -1 )
ERROR(9LL);
result = fileCopy(a1, v2);
if ( (_DWORD)result )
exit(0);
return result;
}

original_code:
int save(char *filePath)
{
 char *bkDir="/usr/local/share/bkx_backup_directory";
 char *targetPath=varyAdd(filePath);
 if(!isFileExist(filePath))
  ERROR(5);
 else if(!isFileCanRead(filePath))
  ERROR(3);
 else if(isDirectory(filePath))
  ERROR(4);
 else if(!isFileExist(bkDir))
  ERROR(8);
 else if(!isDirectory(bkDir)||!isFileCanWrite(bkDir))
  ERROR(7);
 else
 {
  if(isFileExist(targetPath))
         {
                 if(remove(targetPath)==-1)
                         ERROR(9);
         }
  if(fileCopy(filePath,targetPath))
  {
   exit(0);
  }
 }
}

canonical_original_code:
int save(char *filePath)
{
 char *bkDir = "/usr/local/share/bkx_backup_directory";
 char *targetPath = varyAdd(filePath);
 if(!isFileExist(filePath))
  ERROR(5);
 else if(!isFileCanRead(filePath))
  ERROR(3);
 else if(isDirectory(filePath))
  ERROR(4);
 else if(!isFileExist(bkDir))
  ERROR(8);
 else if(!isDirectory(bkDir)||!isFileCanWrite(bkDir))
  ERROR(7);
 else
 {
  if(isFileExist(targetPath))
         {
                 if(remove(targetPath)==-1)
                         ERROR(9);
         }
  if(fileCopy(filePath,targetPath))
  {
   exit(0);
  }
 }
}

variable_types:
targetPath
char *


varyAdd

decompiled_code:
char *__fastcall varyAdd(char *src)
{
strcat(cachePath_1, src);
return cachePath_1;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
strcat(cachePath_1, src);
return cachePath_1;
}

original_code:
char *varyAdd(char *filePath)
{
 static char cachePath[]="/usr/local/share/bkx_backup_directory";
 strcat(cachePath,filePath);
 return cachePath;
}

canonical_original_code:
char *varyAdd(char *filePath)
{
 static char cachePath[] = "/usr/local/share/bkx_backup_directory";
 strcat(cachePath,filePath);
 return cachePath;
}

variable_types:
cachePath
char []


ERROR

decompiled_code:
int __fastcall ERROR(unsigned int a1)
{
printf("error%d:", a1);
switch ( a1 )
{
case 1u:
printf("Please input file path after parameter, or input 'bkx --help' for help.");
break;
case 2u:
printf("Please don't input more then one parameter, or input 'bkx --help' for help.");
break;
case 3u:
printf("Plz use super user!");
break;
case 4u:
printf("I don't support directory backup.");
break;
case 5u:
printf("Target doesn't exist!");
break;
case 6u:
printf("Copy Error!");
break;
case 7u:
printf("Plz use super user.");
break;
case 8u:
printf("Please create the backup file directory yourself.(/usr/local/share/bkx_backup_directory)");
break;
case 9u:
printf("File delete error!");
break;
case 0xAu:
printf("reply error!");
break;
default:
return putchar(10);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
printf("error%d:", a1);
switch ( a1 )
{
case 1u:
printf("Please input file path after parameter, or input 'bkx --help' for help.");
break;
case 2u:
printf("Please don't input more then one parameter, or input 'bkx --help' for help.");
break;
case 3u:
printf("Plz use super user!");
break;
case 4u:
printf("I don't support directory backup.");
break;
case 5u:
printf("Target doesn't exist!");
break;
case 6u:
printf("Copy Error!");
break;
case 7u:
printf("Plz use super user.");
break;
case 8u:
printf("Please create the backup file directory yourself.(/usr/local/share/bkx_backup_directory)");
break;
case 9u:
printf("File delete error!");
break;
case 0xAu:
printf("reply error!");
break;
default:
return putchar(10);
}
return putchar(10);
}

original_code:
void ERROR(int errNum)
{
 printf("error%d:",errNum);
 switch (errNum)
  {
  case 1:
   printf("Please input file path after parameter, or input 'bkx --help' for help.");
   break;
  case 2:
   printf("Please don't input more then one parameter, or input 'bkx --help' for help.");
   break;
  case 3:
   printf("Plz use super user!");
   break;
  case 4:
   printf("I don't support directory backup.");
   break;
  case 5:
   printf("Target doesn't exist!");
   break;
  case 6:
   printf("Copy Error!");
   break;
  case 7:
   printf("Plz use super user.");
   break;
  case 8:
   printf("Please create the backup file directory yourself.(/usr/local/share/bkx_backup_directory)");
   break;
  case 9:
   printf("File delete error!");
   break;
  case 10:
   printf("reply error!");
   break;
  }
 printf("\n");
}

variable_types: errNum int


updatemodifiers

repo: misanthrop/crayfish

decompiled_code:
void __fastcall updatemodifiers(__int64 a1, int a2)
{
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax

switch ( a1 )
{
case 65505LL:
case 65506LL:
v3 = modifiers | 1;
if ( !a2 )
v3 = modifiers & 0xFFFFFFFE;
modifiers = v3;
break;
case 65507LL:
case 65508LL:
v4 = modifiers | 4;
if ( !a2 )
v4 = modifiers & 0xFFFFFFFB;
modifiers = v4;
break;
case 65509LL:
if ( a2 )
modifiers ^= 2u;
break;
case 65513LL:
case 65514LL:
v5 = modifiers | 8;
if ( !a2 )
v5 = modifiers & 0xFFFFFFF7;
modifiers = v5;
break;
case 65515LL:
case 65516LL:
v2 = modifiers | 0x40;
if ( !a2 )
v2 = modifiers & 0xFFFFFFBF;
modifiers = v2;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax

switch ( a1 )
{
case 65505LL:
case 65506LL:
v3 = modifiers | 1;
if ( !a2 )
v3 = modifiers & 0xFFFFFFFE;
modifiers = v3;
break;
case 65507LL:
case 65508LL:
v4 = modifiers | 4;
if ( !a2 )
v4 = modifiers & 0xFFFFFFFB;
modifiers = v4;
break;
case 65509LL:
if ( a2 )
modifiers ^= 2u;
break;
case 65513LL:
case 65514LL:
v5 = modifiers | 8;
if ( !a2 )
v5 = modifiers & 0xFFFFFFF7;
modifiers = v5;
break;
case 65515LL:
case 65516LL:
v2 = modifiers | 0x40;
if ( !a2 )
v2 = modifiers & 0xFFFFFFBF;
modifiers = v2;
break;
default:
return;
}
}

original_code:
static void updatemodifiers(KeySym key, int press)
{
 switch(key)
 {
  case 0xffe1: case 0xffe2:
   if(press) modifiers |= (1<<0); else modifiers &= ~(1<<0);
   break;
  case 0xffe3: case 0xffe4:
   if(press) modifiers |= (1<<2); else modifiers &= ~(1<<2);
   break;
  case 0xffe9: case 0xffea:
   if(press) modifiers |= (1<<3); else modifiers &= ~(1<<3);
   break;
  case 0xffeb: case 0xffec:
   if(press) modifiers |= (1<<6); else modifiers &= ~(1<<6);
   break;
  case 0xffe5:
   if(press) modifiers ^= (1<<1);
   break;
 }
}

canonical_original_code:
static void updatemodifiers(unsigned long key, int press)
{
 switch(key)
 {
  case 0xffe1: case 0xffe2:
   if(press) modifiers |= (1<<0); else modifiers &= ~(1<<0);
   break;
  case 0xffe3: case 0xffe4:
   if(press) modifiers |= (1<<2); else modifiers &= ~(1<<2);
   break;
  case 0xffe9: case 0xffea:
   if(press) modifiers |= (1<<3); else modifiers &= ~(1<<3);
   break;
  case 0xffeb: case 0xffec:
   if(press) modifiers |= (1<<6); else modifiers &= ~(1<<6);
   break;
  case 0xffe5:
   if(press) modifiers ^= (1<<1);
   break;
 }
}

variable_types:
key
unsigned long

variable_types: press int


decompiled_code:
__int64 cf_width()
{
return (unsigned int)dpy->screens[(__int64)screen].width;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)dpy->screens[(__int64)screen].width;
}

original_code: unsigned cf_width() { return ((&((_XPrivDisplay)(dpy))->screens[screen])->width); }

canonical_original_code: unsigned int cf_width() { return ((&((_XPrivDisplay)(dpy))->screens[screen])->width); }

return_type: unsigned int


decompiled_code:
__int64 cf_height()
{
return (unsigned int)dpy->screens[(__int64)screen].height;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)dpy->screens[(__int64)screen].height;
}

original_code: unsigned cf_height() { return ((&((_XPrivDisplay)(dpy))->screens[screen])->height); }

canonical_original_code: unsigned int cf_height() { return ((&((_XPrivDisplay)(dpy))->screens[screen])->height); }


decompiled_code:
int __fastcall cf_sleep(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0x3E8;
v2.tv_nsec = 1000 * (a1 % 0x3E8);
return nanosleep(&v2, &remaining);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0x3E8;
v2.tv_nsec = 1000 * (a1 % 0x3E8);
return nanosleep(&v2, &remaining);
}

original_code:
void cf_sleep(unsigned milli)
{
 struct timespec req = {milli/1000, (milli%1000)*1000}, rem;
 nanosleep(&req, &rem);
}

canonical_original_code:
void cf_sleep(unsigned int milli)
{
 struct timespec req = {milli/1000, (milli%1000)*1000}; struct timespec rem;
 nanosleep(&req, &rem);
}

variable_types:
milli
unsigned int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int __fastcall cf_movepointer()
{
int v1; // [rsp+0h] [rbp-20h]
int v2; // [rsp+8h] [rbp-18h]

return XWarpPointer(dpy, 0LL, root, 0, 0, 0, 0, v1, v2);
}

canonical_decompiled_code:
int __fastcall func7()
{
int v1; // [rsp+0h] [rbp-20h]
int v2; // [rsp+8h] [rbp-18h]

return XWarpPointer(dpy, 0LL, root, 0, 0, 0, 0, v1, v2);
}

original_code: void cf_movepointer(int x, int y) { XWarpPointer(dpy, 0, root, 0,0,0,0, x,y); }

variable_types: x int

variable_types: y int


decompiled_code:
int __fastcall cf_button(int a1, int a2)
{
buttonevent(buttons_1[a1], (a2 == 0) + 4);
return XFlush(dpy);
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2)
{
func2(buttons_1[a1], (a2 == 0) + 4);
return XFlush(dpy);
}

original_code:
void cf_button(unsigned button, int press)
{
 static const unsigned buttons[] = { 1, 3, 2, 4, 5 };
 buttonevent(buttons[button], press ? 4 : 5);
 XFlush(dpy);
}

canonical_original_code:
void cf_button(unsigned int button, int press)
{
 static unsigned int buttons[] = { 1, 3, 2, 4, 5 };
 buttonevent(buttons[button], press ? 4 : 5);
 XFlush(dpy);
}

variable_types:
button
unsigned int

variable_types:
buttons
unsigned int []


decompiled_code:
void __fastcall cf_key(int a1, int a2)
{
KeySym v2; // r13
KeyCode v3; // al
int v4; // [rsp+4h] [rbp-24h] BYREF
Window v5[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = keys_0[a1];
XGetInputFocus(dpy, v5, &v4);
v3 = XKeysymToKeycode(dpy, v2);
keyevent(v5[0], v3, (a2 == 0) + 2);
XFlush(dpy);
updatemodifiers(v2, a2);
}

canonical_decompiled_code:
void __fastcall func9(int a1, int a2)
{
KeySym v2; // r13
KeyCode v3; // al
int v4; // [rsp+4h] [rbp-24h] BYREF
Window v5[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = keys_0[a1];
XGetInputFocus(dpy, v5, &v4);
v3 = XKeysymToKeycode(dpy, v2);
func3(v5[0], v3, (a2 == 0) + 2);
XFlush(dpy);
func0(v2, a2);
}

variable_types:
key
unsigned int

variable_types:
keys
unsigned int [-1]

variable_types:
focus
unsigned long

variable_types: revert int

variable_types:
ks
unsigned long


init

decompiled_code:
int init()
{
struct _XIM *v0; // rax

dpy = XOpenDisplay(0LL);
screen = dpy->default_screen;
root = dpy->screens[(__int64)screen].root;
v0 = XOpenIM(dpy, 0LL, 0LL, 0LL);
XCreateIC(v0, "inputStyle", 1032LL, 0LL);
return XSync(dpy, 0);
}

canonical_decompiled_code:
int func10()
{
struct _XIM *v0; // rax

dpy = XOpenDisplay(0LL);
screen = dpy->default_screen;
root = dpy->screens[(__int64)screen].root;
v0 = XOpenIM(dpy, 0LL, 0LL, 0LL);
XCreateIC(v0, "inputStyle", 1032LL, 0LL);
return XSync(dpy, 0);
}

original_code:
__attribute__((constructor)) static void init()
{
 dpy = XOpenDisplay(0);
 screen = (((_XPrivDisplay)(dpy))->default_screen);
 root = ((&((_XPrivDisplay)(dpy))->screens[screen])->root);
 im = XOpenIM(dpy, 0, 0, 0);
 ic = XCreateIC(im, "inputStyle", 0x0008L|0x0400L, 0);
 XSync(dpy, 0);
}


uninit

decompiled_code:
int uninit()
{
XSync(dpy, 0);
return XCloseDisplay(dpy);
}

canonical_decompiled_code:
int func11()
{
XSync(dpy, 0);
return XCloseDisplay(dpy);
}

original_code:
__attribute__((destructor)) static void uninit()
{
 XSync(dpy, 0);
 XCloseDisplay(dpy);
}


repo: misfit/dragonfighter

decompiled_code:
__int64 __fastcall setup_allegro(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
int *v6; // rax
unsigned int v7; // eax

v6 = _errno_location();
install_allegro_version_check(0LL, v6, &atexit, 263170LL);
install_keyboard();
install_timer();
v7 = time(0LL);
srand(v7);
set_color_depth(a4);
return set_gfx_mode(a1, a2, a3, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
int *v6; // rax
unsigned int v7; // eax

v6 = _errno_location();
install_allegro_version_check(0LL, v6, &atexit, 263170LL);
install_keyboard();
install_timer();
v7 = time(0LL);
srand(v7);
set_color_depth(a4);
return set_gfx_mode(a1, a2, a3, 0LL, 0LL);
}

original_code:
void setup_allegro (int mode, int screenw, int screenh, int cdepth) {
  _install_allegro_version_check(0, &(*__errno_location ()), (int (*)(void (*)(void)))atexit, (((4)<<16)|((4)<<8)|(2)));
  install_keyboard();
  install_timer();
  srand (time (((void *)0)));
  set_color_depth (cdepth);
  set_gfx_mode (mode, screenw, screenh, 0, 0);
}

canonical_original_code:
void setup_allegro(int mode, int screenw, int screenh, int cdepth) {
  _install_allegro_version_check(0, &(*__errno_location ()), (int (*)(void (*)()))atexit, (((4)<<16)|((4)<<8)|(2)));
  install_keyboard();
  install_timer();
  srand (time (((void *)0)));
  set_color_depth (cdepth);
  set_gfx_mode (mode, screenw, screenh, 0, 0);
}

variable_types: mode int

variable_types: screenw int

variable_types: screenh int

variable_types: cdepth int