decompiled_code:
__int64 __fastcall handle_signal(int a1)
{
atomic(1LL);
switch ( a1 )
{
case 10:
k_i_process_enter((__int64)&p_table);
break;
case 12:
k_i_process_enter((unsigned int)((_DWORD)&p_table + 272));
break;
case 14:
k_i_process_enter((unsigned int)((_DWORD)&p_table + 544));
break;
default:
k_terminate();
break;
}
return atomic(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
atomic(1LL);
switch ( a1 )
{
case 10:
func0((__int64)&p_table);
break;
case 12:
func0((unsigned int)((_DWORD)&p_table + 272));
break;
case 14:
func0((unsigned int)((_DWORD)&p_table + 544));
break;
default:
k_terminate();
break;
}
return atomic(0LL);
}

original_code:
void handle_signal(int sig_num)
{
    atomic(1);
    switch (sig_num)
    {
        case 2:
        case 7:
        case 1:
        case 4:
        case 3:
        case 11:
        case 15:
        case 6:
            k_terminate();
            break;
        case 14:
            k_i_process_enter(&p_table[2]);
            break;
        case 10:
            k_i_process_enter(&p_table[0]);
            break;
        case 12:
            k_i_process_enter(&p_table[1]);
            break;
        default:
            k_terminate();
    }
    atomic(0);
}


checkCardResponse

repo: Uepsilon/smartcard-sample-c

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

result = 0LL;
if ( *(_BYTE *)(a1 + a2 - 2) == 0x90 )
result = *(_BYTE *)(a1 + a2 - 1) == 0;
return result;
}

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

result = 0LL;
if ( *(_BYTE *)(a1 + a2 - 2) == 0x90 )
result = *(_BYTE *)(a1 + a2 - 1) == 0;
return result;
}

original_code:
int checkCardResponse(BYTE *receiveBuffer, DWORD receiveBufferLen)
{
  int resultValid = 0;
  if ( ( receiveBuffer[(receiveBufferLen - 2)] == 0x90 ) &&
       ( receiveBuffer[(receiveBufferLen - 1)] == 0x00 ) )
  {
    resultValid = 1;
  }
  return resultValid;
}

canonical_original_code:
int checkCardResponse(unsigned char *receiveBuffer, unsigned long receiveBufferLen)
{
  int resultValid = 0;
  if ( ( receiveBuffer[(receiveBufferLen - 2)] == 0x90 ) &&
       ( receiveBuffer[(receiveBufferLen - 1)] == 0x00 ) )
  {
    resultValid = 1;
  }
  return resultValid;
}

variable_types:
receiveBuffer
unsigned char *

variable_types:
receiveBufferLen
unsigned long

variable_types: resultValid int

return_type: int


checkSCardResult

decompiled_code:
__int64 __fastcall checkSCardResult(const char *a1, __int64 a2)
{
const char *v2; // rax
__int64 result; // rax

if ( a2 )
{
v2 = (const char *)pcsc_stringify_error();
printf("%s: %s\n", a1, v2);
result = 0LL;
}
else
{
printf("%s: Result OK\n", a1);
result = 1LL;
}
return result;
}

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

if ( a2 )
{
v2 = (const char *)pcsc_stringify_error();
printf("%s: %s\n", a1, v2);
result = 0LL;
}
else
{
printf("%s: Result OK\n", a1);
result = 1LL;
}
return result;
}

original_code:
int checkSCardResult(char* method_name, LONG result)
{
  int ret_val;
  if ( result != ((LONG)0x00000000) )
  {
    printf("%s: %s\n", method_name, pcsc_stringify_error(result));
    ret_val = 0;
  }
  else
  {
    printf("%s: Result OK\n", method_name);
    ret_val = 1;
  }
  return ret_val;
}

canonical_original_code:
int checkSCardResult(char *method_name, long result)
{
  int ret_val;
  if ( result != ((long)0x00000000) )
  {
    printf("%s: %s\n", method_name, pcsc_stringify_error(result));
    ret_val = 0;
  }
  else
  {
    printf("%s: Result OK\n", method_name);
    ret_val = 1;
  }
  return ret_val;
}

variable_types: result long


runCmd

decompiled_code:
unsigned __int64 __fastcall runCmd(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4, __int64 a5, unsigned __int64 a6)
{
__int64 v9; // r14
unsigned __int8 *v10; // rbx
unsigned __int8 *v11; // rbp
unsigned __int64 v12; // rbx
unsigned __int64 v13; // rbx

v9 = SCardTransmit();
printf("\nSending CMD: ");
if ( a4 )
{
v10 = a3;
v11 = &a3[a4];
do
printf(" %02X", *v10++);
while ( v10 != v11 );
}
putchar(10);
if ( v9 )
{
checkSCardResult("SCardTransmit", v9);
}
else
{
v12 = a6;
if ( checkCardResponse(a5, a6) )
{
a6 -= 2LL;
printf("Result (HEX): ");
if ( v12 != 2 )
{
v13 = 0LL;
do
printf(" %02X", *(unsigned __int8 *)(a5 + v13++));
while ( a6 > v13 );
}
puts("\n");
}
else
{
puts("Result from Card != SUCCESS");
a6 = 0LL;
}
}
return a6;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4, __int64 a5, unsigned __int64 a6)
{
__int64 v9; // r14
unsigned __int8 *v10; // rbx
unsigned __int8 *v11; // rbp
unsigned __int64 v12; // rbx
unsigned __int64 v13; // rbx

v9 = SCardTransmit();
printf("\nSending CMD: ");
if ( a4 )
{
v10 = a3;
v11 = &a3[a4];
do
printf(" %02X", *v10++);
while ( v10 != v11 );
}
putchar(10);
if ( v9 )
{
func8("SCardTransmit", v9);
}
else
{
v12 = a6;
if ( func7(a5, a6) )
{
a6 -= 2LL;
printf("Result (HEX): ");
if ( v12 != 2 )
{
v13 = 0LL;
do
printf(" %02X", *(unsigned __int8 *)(a5 + v13++));
while ( a6 > v13 );
}
puts("\n");
}
else
{
puts("Result from Card != SUCCESS");
a6 = 0LL;
}
}
return a6;
}

original_code:
DWORD runCmd(SCARDHANDLE card, SCARD_IO_REQUEST *protStruct, BYTE *cmd, DWORD cmdLen, BYTE *receiveBuffer, DWORD receiveBufferLen)
{
  LONG rv;
  int i;
  rv = SCardTransmit(card, protStruct, cmd, cmdLen, protStruct, receiveBuffer, &receiveBufferLen);
  printf("\nSending CMD: ");
  for(i = 0; i < cmdLen; i++)
    printf(" %02X", cmd[i]);
  printf("\n");
  if (rv == ((LONG)0x00000000) )
  {
    if ( checkCardResponse(receiveBuffer, receiveBufferLen) )
    {
      receiveBufferLen -= 2;
      printf("Result (HEX): ");
      for(i = 0; i < receiveBufferLen; i++)
        printf(" %02X", receiveBuffer[i]);
      printf("\n\n");
    }
    else
    {
      printf("Result from Card != SUCCESS\n");
      receiveBufferLen = 0;
    }
  }
  else
  {
    checkSCardResult("SCardTransmit", rv);
  }
  return receiveBufferLen;
}

canonical_original_code:
unsigned long runCmd(long card, struct SCARD_IO_REQUEST *protStruct, unsigned char *cmd, unsigned long cmdLen, unsigned char *receiveBuffer, unsigned long receiveBufferLen)
{
  long rv;
  int i;
  rv = SCardTransmit(card, protStruct, cmd, cmdLen, protStruct, receiveBuffer, &receiveBufferLen);
  printf("\nSending CMD: ");
  for(i = 0; i < cmdLen; i++)
    printf(" %02X", cmd[i]);
  printf("\n");
  if (rv == ((long)0x00000000) )
  {
    if ( checkCardResponse(receiveBuffer, receiveBufferLen) )
    {
      receiveBufferLen -= 2;
      printf("Result (HEX): ");
      for(i = 0; i < receiveBufferLen; i++)
        printf(" %02X", receiveBuffer[i]);
      printf("\n\n");
    }
    else
    {
      printf("Result from Card != SUCCESS\n");
      receiveBufferLen = 0;
    }
  }
  else
  {
    checkSCardResult("SCardTransmit", rv);
  }
  return receiveBufferLen;
}

variable_types: card long

variable_types: struct SCARD_IO_REQUEST { unsigned long dwProtocol; unsigned long cbPciLength; } *

variable_types:
cmd
unsigned char *

variable_types:
cmdLen
unsigned long

variable_types: rv long

variable_types: i int

return_type: unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
char *v5; // rbx
__int64 v6; // rax
int result; // eax
unsigned __int64 i; // rbp
unsigned __int8 *v9; // rbp
char *v10; // r12
unsigned __int64 v11; // r12
int v12; // [rsp+Bh] [rbp-18Dh] BYREF
char v13; // [rsp+Fh] [rbp-189h]
__m128i v14; // [rsp+10h] [rbp-188h] BYREF
char v15[128]; // [rsp+20h] [rbp-178h] BYREF
char v16[128]; // [rsp+A0h] [rbp-F8h] BYREF
size_t size; // [rsp+120h] [rbp-78h]
__int64 v18; // [rsp+128h] [rbp-70h]
__int64 v19; // [rsp+130h] [rbp-68h]
unsigned __int64 v20; // [rsp+138h] [rbp-60h]
char v21[48]; // [rsp+140h] [rbp-58h]
__int64 v22; // [rsp+170h] [rbp-28h]

v12 = 51967;
v13 = 0;
v3 = SCardEstablishContext();
if ( v3 )
{
printf("Cannot connect to PCSC: %lX\n", v3);
result = 1;
}
else
{
v4 = SCardListReaders();
if ( v4 )
printf("SCardListReader: %lX\n", v4);
v5 = (char *)malloc(size);
if ( v5 )
{
v6 = SCardListReaders();
if ( v6 )
printf("SCardListReader: %lX\n", v6);
if ( *v5 )
{
printf("Reader #%d: %s\n", 1LL, v5);
while ( SCardConnect() )
;
if ( v18 == 1 )
{
v14 = _mm_loadu_si128((const __m128i *)&g_rgSCardT0Pci);
}
else if ( v18 == 2 )
{
v14 = _mm_loadu_si128((const __m128i *)&g_rgSCardT1Pci);
}
v20 = 33LL;
if ( !SCardStatus() )
{
printf(" Reader: %s (length %ld bytes)\n", v16, size);
printf(" State: 0x%lX\n", v19);
printf(" Prot: %ld\n", v18);
printf(" ATR (length %ld bytes):", v20);
if ( v20 )
{
for ( i = 0LL; i < v20; ++i )
printf(" %02X", (unsigned __int8)v21[i]);
}
putchar(10);
}
v11 = runCmd(v22, (__int64)&v14, (unsigned __int8 *)&v12, 5LL, (__int64)v15, 8uLL);
if ( v11 )
{
printf("Card-UID: ");
v9 = (unsigned __int8 *)v15;
v10 = &v15[v11];
do
printf("%d", *v9++);
while ( v10 != (char *)v9 );
putchar(10);
}
SCardDisconnect();
SCardReleaseContext();
free(v5);
result = 0;
}
else
{
puts("No reader found");
result = 1;
}
}
else
{
puts("malloc: not enough memory");
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
char *v5; // rbx
__int64 v6; // rax
int result; // eax
unsigned __int64 i; // rbp
unsigned __int8 *v9; // rbp
char *v10; // r12
unsigned __int64 v11; // r12
int v12; // [rsp+Bh] [rbp-18Dh] BYREF
char v13; // [rsp+Fh] [rbp-189h]
__m128i v14; // [rsp+10h] [rbp-188h] BYREF
char v15[128]; // [rsp+20h] [rbp-178h] BYREF
char v16[128]; // [rsp+A0h] [rbp-F8h] BYREF
size_t size; // [rsp+120h] [rbp-78h]
__int64 v18; // [rsp+128h] [rbp-70h]
__int64 v19; // [rsp+130h] [rbp-68h]
unsigned __int64 v20; // [rsp+138h] [rbp-60h]
char v21[48]; // [rsp+140h] [rbp-58h]
__int64 v22; // [rsp+170h] [rbp-28h]

v12 = 51967;
v13 = 0;
v3 = SCardEstablishContext();
if ( v3 )
{
printf("Cannot connect to PCSC: %lX\n", v3);
result = 1;
}
else
{
v4 = SCardListReaders();
if ( v4 )
printf("SCardListReader: %lX\n", v4);
v5 = (char *)malloc(size);
if ( v5 )
{
v6 = SCardListReaders();
if ( v6 )
printf("SCardListReader: %lX\n", v6);
if ( *v5 )
{
printf("Reader #%d: %s\n", 1LL, v5);
while ( SCardConnect() )
;
if ( v18 == 1 )
{
v14 = _mm_loadu_si128((const __m128i *)&g_rgSCardT0Pci);
}
else if ( v18 == 2 )
{
v14 = _mm_loadu_si128((const __m128i *)&g_rgSCardT1Pci);
}
v20 = 33LL;
if ( !SCardStatus() )
{
printf(" Reader: %s (length %ld bytes)\n", v16, size);
printf(" State: 0x%lX\n", v19);
printf(" Prot: %ld\n", v18);
printf(" ATR (length %ld bytes):", v20);
if ( v20 )
{
for ( i = 0LL; i < v20; ++i )
printf(" %02X", (unsigned __int8)v21[i]);
}
putchar(10);
}
v11 = func9(v22, (__int64)&v14, (unsigned __int8 *)&v12, 5LL, (__int64)v15, 8uLL);
if ( v11 )
{
printf("Card-UID: ");
v9 = (unsigned __int8 *)v15;
v10 = &v15[v11];
do
printf("%d", *v9++);
while ( v10 != (char *)v9 );
putchar(10);
}
SCardDisconnect();
SCardReleaseContext();
free(v5);
result = 0;
}
else
{
puts("No reader found");
result = 1;
}
}
else
{
puts("malloc: not enough memory");
result = 1;
}
}
return result;
}

original_code:
int main(void)
{
  LONG rv;
  SCARDCONTEXT cardContext;
  SCARDHANDLE card;
  BYTE cardAtr[33];
  DWORD cardAtrLen;
  DWORD cardStatus;
  DWORD usedProtocol;
  LPSTR foundReaders;
  DWORD readersLen;
  char *readersList[1];
  BYTE readerName[128];
  int i;
  int numOfReaders = 0;
  char* ptr;
  BYTE receiveBuffer[125];
  DWORD receiveBufferLen;
  SCARD_IO_REQUEST protStruct;
  BYTE cmdReadUID[] = {0xFF, 0xCA, 0x00, 0x00, 0x00};
  rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), &cardContext);
  if ( rv != ((LONG)0x00000000))
  {
    printf("Cannot connect to PCSC: %lX\n", rv);
    return 1;
  }
  rv = SCardListReaders(cardContext, ((void *)0), ((void *)0), &readersLen);
  if (rv != ((LONG)0x00000000))
  {
    printf("SCardListReader: %lX\n", rv);
  }
  foundReaders = malloc(sizeof(char)*readersLen);
  if (foundReaders == ((void *)0))
  {
    printf("malloc: not enough memory\n");
    return 1;
  }
  rv = SCardListReaders(cardContext, ((void *)0), foundReaders, &readersLen);
  if (rv != ((LONG)0x00000000))
  {
    printf("SCardListReader: %lX\n", rv);
  }
  ptr = foundReaders;
  while ((*ptr != '\0') && (numOfReaders < 1))
  {
    printf("Reader #%d: %s\n", (numOfReaders+1), ptr);
    readersList[numOfReaders] = ptr;
    ptr += strlen(ptr)+1;
    numOfReaders++;
  }
  if (numOfReaders == 0)
  {
    printf("No reader found\n");
    return 1;
  }
  while ( SCardConnect(cardContext, readersList[0], 0x0001, 0x0001, &card, &usedProtocol) != ((LONG)0x00000000) )
  {
  }
  switch(usedProtocol)
  {
    case 0x0001:
      protStruct = *(&g_rgSCardT0Pci);
      break;
    case 0x0002:
      protStruct = *(&g_rgSCardT1Pci);
      break;
  }
  cardAtrLen = sizeof(cardAtr);
  rv = SCardStatus(card, readerName, &readersLen, &cardStatus, &usedProtocol, cardAtr, &cardAtrLen);
  if ( rv == ((LONG)0x00000000) )
  {
    printf(" Reader: %s (length %ld bytes)\n", readerName, readersLen);
    printf(" State: 0x%lX\n", cardStatus);
    printf(" Prot: %ld\n", usedProtocol);
    printf(" ATR (length %ld bytes):", cardAtrLen);
    for (i = 0; i < cardAtrLen; i++)
      printf(" %02X", cardAtr[i]);
    printf("\n");
  }
  receiveBufferLen = runCmd(card, &protStruct, cmdReadUID, sizeof(cmdReadUID), receiveBuffer, sizeof(receiveBufferLen));
  if ( receiveBufferLen > 0 )
  {
    printf("Card-UID: ");
    for(i = 0; i < receiveBufferLen; i++)
    {
      printf("%d", receiveBuffer[i]);
    }
    printf("\n");
  }
  rv = SCardDisconnect(card, 0x0002);
  rv = SCardReleaseContext(cardContext);
  free(foundReaders);
  return 0;
}

canonical_original_code:
int main()
{
  long rv;
  long cardContext;
  long card;
  unsigned char cardAtr[33];
  unsigned long cardAtrLen;
  unsigned long cardStatus;
  unsigned long usedProtocol;
  char *foundReaders;
  unsigned long readersLen;
  char *readersList[1];
  unsigned char readerName[128];
  int i;
  int numOfReaders = 0;
  char *ptr;
  unsigned char receiveBuffer[125];
  unsigned long receiveBufferLen;
  struct SCARD_IO_REQUEST protStruct;
  unsigned char cmdReadUID[] = {0xFF, 0xCA, 0x00, 0x00, 0x00};
  rv = SCardEstablishContext(0x0002, ((void *)0), ((void *)0), &cardContext);
  if ( rv != ((long)0x00000000))
  {
    printf("Cannot connect to PCSC: %lX\n", rv);
    return 1;
  }
  rv = SCardListReaders(cardContext, ((void *)0), ((void *)0), &readersLen);
  if (rv != ((long)0x00000000))
  {
    printf("SCardListReader: %lX\n", rv);
  }
  foundReaders = malloc(sizeof(char)*readersLen);
  if (foundReaders == ((void *)0))
  {
    printf("malloc: not enough memory\n");
    return 1;
  }
  rv = SCardListReaders(cardContext, ((void *)0), foundReaders, &readersLen);
  if (rv != ((long)0x00000000))
  {
    printf("SCardListReader: %lX\n", rv);
  }
  ptr = foundReaders;
  while ((*ptr != '\0') && (numOfReaders < 1))
  {
    printf("Reader #%d: %s\n", (numOfReaders+1), ptr);
    readersList[numOfReaders] = ptr;
    ptr += strlen(ptr)+1;
    numOfReaders++;
  }
  if (numOfReaders == 0)
  {
    printf("No reader found\n");
    return 1;
  }
  while ( SCardConnect(cardContext, readersList[0], 0x0001, 0x0001, &card, &usedProtocol) != ((long)0x00000000) )
  {
  }
  switch(usedProtocol)
  {
    case 0x0001:
      protStruct = *(&g_rgSCardT0Pci);
      break;
    case 0x0002:
      protStruct = *(&g_rgSCardT1Pci);
      break;
  }
  cardAtrLen = sizeof(cardAtr);
  rv = SCardStatus(card, readerName, &readersLen, &cardStatus, &usedProtocol, cardAtr, &cardAtrLen);
  if ( rv == ((long)0x00000000) )
  {
    printf(" Reader: %s (length %ld bytes)\n", readerName, readersLen);
    printf(" State: 0x%lX\n", cardStatus);
    printf(" Prot: %ld\n", usedProtocol);
    printf(" ATR (length %ld bytes):", cardAtrLen);
    for (i = 0; i < cardAtrLen; i++)
      printf(" %02X", cardAtr[i]);
    printf("\n");
  }
  receiveBufferLen = runCmd(card, &protStruct, cmdReadUID, sizeof(cmdReadUID), receiveBuffer, sizeof(receiveBufferLen));
  if ( receiveBufferLen > 0 )
  {
    printf("Card-UID: ");
    for(i = 0; i < receiveBufferLen; i++)
    {
      printf("%d", receiveBuffer[i]);
    }
    printf("\n");
  }
  rv = SCardDisconnect(card, 0x0002);
  rv = SCardReleaseContext(cardContext);
  free(foundReaders);
  return 0;
}

variable_types: cardContext long

variable_types:
cardAtr
unsigned char [33]

variable_types:
cardAtrLen
unsigned long

variable_types:
cardStatus
unsigned long

variable_types:
usedProtocol
unsigned long

variable_types:
foundReaders
char *

variable_types:
readersLen
unsigned long

variable_types:
readersList
char *[1]

variable_types:
readerName
unsigned char [128]

variable_types: numOfReaders int

variable_types:
ptr
char *

variable_types:
receiveBuffer
unsigned char [125]

variable_types: struct SCARD_IO_REQUEST { unsigned long dwProtocol; unsigned long cbPciLength; }

variable_types:
cmdReadUID
unsigned char []


decompiled_code:
void __fastcall check_status(int a1, __int64 a2)
{
if ( a1 == 3 )
{
printf("window id # 0x%lx does not exists!", a2);
exit(1);
}
if ( a1 )
{
printf("XGetWindowProperty failed!");
exit(2);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1, __int64 a2)
{
if ( a1 == 3 )
{
printf("window id # 0x%lx does not exists!", a2);
exit(1);
}
if ( a1 )
{
printf("XGetWindowProperty failed!");
exit(2);
}
}

original_code:
void check_status(int status, unsigned long window)
{
    if (status == 3) {
        printf("window id # 0x%lx does not exists!", window);
        exit(1);
    }
    if (status != 0) {
        printf("XGetWindowProperty failed!");
        exit(2);
    }
}

variable_types: status int

variable_types:
window
unsigned long

return_type: void


decompiled_code:
unsigned __int8 *__fastcall get_string_property(char *a1)
{
Atom v1; // rax
int v2; // eax
unsigned __int64 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v5; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+14h] [rbp-14h] BYREF
Atom v7[2]; // [rsp+18h] [rbp-10h] BYREF

v1 = XInternAtom(display, a1, 1);
v2 = XGetWindowProperty(display, window, v1, 0LL, 1000LL, 0, 0LL, v7, &v6, &v5, &v4, &prop);
check_status(v2, window);
return prop;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func8(char *a1)
{
Atom v1; // rax
int v2; // eax
unsigned __int64 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v5; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+14h] [rbp-14h] BYREF
Atom v7[2]; // [rsp+18h] [rbp-10h] BYREF

v1 = XInternAtom(display, a1, 1);
v2 = XGetWindowProperty(display, window, v1, 0LL, 1000LL, 0, 0LL, v7, &v6, &v5, &v4, &prop);
func7(v2, window);
return prop;
}

original_code:
unsigned char* get_string_property(char* property_name)
{
    Atom actual_type, filter_atom;
    int actual_format, status;
    unsigned long nitems, bytes_after;
    filter_atom = XInternAtom(display, property_name, 1);
    status = XGetWindowProperty(display, window, filter_atom, 0, 1000, 0, 0L,
                                &actual_type, &actual_format, &nitems, &bytes_after, &prop);
    check_status(status, window);
    return prop;
}

canonical_original_code:
unsigned char *get_string_property(char *property_name)
{
    unsigned long actual_type; unsigned long filter_atom;
    int actual_format; int status;
    unsigned long nitems; unsigned long bytes_after;
    filter_atom = XInternAtom(display, property_name, 1);
    status = XGetWindowProperty(display, window, filter_atom, 0, 1000, 0, 0L,
                                &actual_type, &actual_format, &nitems, &bytes_after, &prop);
    check_status(status, window);
    return prop;
}

variable_types:
nitems
unsigned long

return_type: unsigned char *


decompiled_code:
__int64 __fastcall get_long_property(char *a1)
{
get_string_property(a1);
return (prop[1] << 8) + *prop + (prop[2] << 16) + (prop[3] << 24);
}

original_code:
unsigned long get_long_property(char* property_name)
{
    get_string_property(property_name);
    unsigned long long_property = prop[0] + (prop[1]<<8) + (prop[2]<<16) + (prop[3]<<24);
    return long_property;
}

canonical_original_code:
unsigned long get_long_property(char *property_name)
{
    get_string_property(property_name);
    unsigned long long_property = prop[0] + (prop[1]<<8) + (prop[2]<<16) + (prop[3]<<24);
    return long_property;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
unsigned __int8 *v4; // rax
unsigned __int8 *v5; // rax
char *v7; // rax

display = XOpenDisplay(0LL);
if ( !display )
{
v7 = XDisplayName(0LL);
fprintf(stderr, "%s: unable to open display '%s'\n", *argv, v7);
}
window = display->screens[(__int64)XDefaultScreen(display)].root;
window = get_long_property("_NET_ACTIVE_WINDOW");
v3 = get_long_property("_NET_WM_PID");
printf("_NET_WM_PID: %lu\n", v3);
v4 = get_string_property("WM_CLASS");
printf("WM_CLASS: %s\n", (const char *)v4);
v5 = get_string_property("_NET_WM_NAME");
printf("_NET_WM_NAME: %s\n", (const char *)v5);
XCloseDisplay(display);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
unsigned __int8 *v4; // rax
unsigned __int8 *v5; // rax
char *v7; // rax

display = XOpenDisplay(0LL);
if ( !display )
{
v7 = XDisplayName(0LL);
fprintf(stderr, "%s: unable to open display '%s'\n", *argv, v7);
}
window = display->screens[(__int64)XDefaultScreen(display)].root;
window = func9("_NET_ACTIVE_WINDOW");
v3 = func9("_NET_WM_PID");
printf("_NET_WM_PID: %lu\n", v3);
v4 = func8("WM_CLASS");
printf("WM_CLASS: %s\n", (const char *)v4);
v5 = func8("_NET_WM_NAME");
printf("_NET_WM_NAME: %s\n", (const char *)v5);
XCloseDisplay(display);
return 0;
}

original_code:
int main(int argc, char** argv)
{
    char *display_name = ((void *)0);
    display = XOpenDisplay(display_name);
    if (display == ((void *)0)) {
        fprintf (stderr, "%s:  unable to open display '%s'\n", argv[0], XDisplayName (display_name));
    }
    int screen = XDefaultScreen(display);
    window = ((&((_XPrivDisplay)(display))->screens[screen])->root);
    window = get_long_property("_NET_ACTIVE_WINDOW");
    printf("_NET_WM_PID: %lu\n", get_long_property("_NET_WM_PID"));
    printf("WM_CLASS: %s\n", get_string_property("WM_CLASS"));
    printf("_NET_WM_NAME: %s\n", get_string_property("_NET_WM_NAME"));
    XCloseDisplay(display);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *display_name = ((void *)0);
    display = XOpenDisplay(display_name);
    if (display == ((void *)0)) {
        fprintf (stderr, "%s:  unable to open display '%s'\n", argv[0], XDisplayName (display_name));
    }
    int screen = XDefaultScreen(display);
    window = ((&((_XPrivDisplay)(display))->screens[screen])->root);
    window = get_long_property("_NET_ACTIVE_WINDOW");
    printf("_NET_WM_PID: %lu\n", get_long_property("_NET_WM_PID"));
    printf("WM_CLASS: %s\n", get_string_property("WM_CLASS"));
    printf("_NET_WM_NAME: %s\n", get_string_property("_NET_WM_NAME"));
    XCloseDisplay(display);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: screen int


ReadFileWrapper

repo: UniqueStudio/ibcp

original_code:
void ReadFileWrapper(void *vargs) {
 unsigned long long *args = vargs;
 ReadFile(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
}

variable_types:
vargs
void *

variable_types:
args
unsigned long long *


RecvBufWrapper

original_code:
void RecvBufWrapper(void *vargs) {
 unsigned long long *args = vargs;
 RecvBuf(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
}


WriteFileWrapper

decompiled_code:
__int64 __fastcall WriteFileWrapper(void *a1)
{
return WriteFile(
*(_QWORD *)a1,
*((_QWORD *)a1 + 1),
*((_QWORD *)a1 + 2),
*((_QWORD *)a1 + 3),
*((_QWORD *)a1 + 4),
*((_QWORD *)a1 + 5),
*((_QWORD *)a1 + 6));
}

original_code:
void WriteFileWrapper(void *vargs) {
 unsigned long long *args = vargs;
 WriteFile(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
}


SendBufWrapper

original_code:
void SendBufWrapper(void *vargs) {
 unsigned long long *args = vargs;
 SendBuf(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // eax
int v6; // eax
int result; // eax
__pid_t v8; // er15
__pid_t v9; // eax
void *v10; // r14
char *v11; // rbx
__pid_t *v12; // r13
__int64 v13; // rcx
int v14; // esi
int v15; // edx
char *v16; // rax
__int64 v17; // r12
__int64 i; // rbx
__pid_t v19; // eax
__pid_t *v20; // rbx
__int64 j; // rbx
size_t v22; // rbp
void *v23; // r13
void *v24; // r12
int v25; // ebx
int v26; // eax
_QWORD *v27; // rbx
_QWORD *v28; // rcx
char v29[312]; // [rsp+0h] [rbp-138h] BYREF

v3 = time(0LL);
srand(v3);
config = strdup("mlx4_0");
*((_DWORD *)&config + 4) = 19879;
*((_DWORD *)&config + 5) = 1;
v4 = 1;
while ( 2 )
{
v5 = getopt_long(argc, (char *const *)argv, "p:d:w:f:l:r:cvi:s:n:", &long_options_0, 0LL);
if ( v5 == -1 )
{
v8 = is_client;
if ( is_client )
{
v9 = fork();
v8 = v9;
if ( !v9 )
{
sprintf(
v29,
"ssh %s ibcp -n %d -w %d >/dev/null 2>/dev/null",
*((const char **)&config + 1),
(unsigned int)v4,
added_config);
system(v29);
exit(0);
}
if ( v9 < 0 )
puts("Failed to fork");
}
v10 = malloc(8LL * v4);
v11 = (char *)malloc(8LL * v4);
memset(v10, 0, 8LL * v4);
memset(v11, 0, 8LL * v4);
file_linkedlist_creat();
v12 = (__pid_t *)malloc(4LL * v4);
if ( v4 > 0 )
{
v13 = head_node;
if ( head_node )
{
v14 = 0;
do
{
v15 = v14 % v4;
++v14;
v16 = &v11[8 * v15];
if ( *(_QWORD *)v16 )
{
*(_QWORD *)(*(_QWORD *)v16 + 272LL) = v13;
*(_QWORD *)v16 = v13;
}
else
{
*(_QWORD *)v16 = v13;
*((_QWORD *)v10 + v15) = v13;
}
v13 = *(_QWORD *)(v13 + 272);
*(_QWORD *)(*(_QWORD *)v16 + 272LL) = 0LL;
}
while ( v13 );
}
v17 = (unsigned int)(v4 - 1);
for ( i = 0LL; ; ++i )
{
v19 = fork();
if ( v19 <= 0 )
{
if ( !v19 )
{
*((_DWORD *)&config + 4) += i;
head_node = *((_QWORD *)v10 + (int)i);
break;
}
puts("Failed to fork");
}
else
{
v12[i] = v19;
}
if ( v17 == i )
{
v20 = v12;
do
waitpid(*v20++, 0LL, 0);
while ( &v12[v17 + 1] != v20 );
puts(
"-------------------------------------------\n"
"Client send data end, waiting for remote to finish writing\n"
"--------------------------------------------");
waitpid(v8, 0LL, 0);
puts("Remote write finished");
exit(0);
}
}
}
printf("IS Client: %d\n", (unsigned int)is_client);
v22 = (__int64)added_config << 10;
v23 = malloc(v22);
v24 = malloc(v22);
pthread_mutex_init(&m1lockw, 0LL);
pthread_mutex_init(&m1lockr, 0LL);
pthread_mutex_init(&m2lockw, 0LL);
pthread_mutex_init(&m2lockr, 0LL);
puts("start to read");
fileBuf = (__int64)malloc(v22);
memset((void *)fileBuf, 0, v22);
v25 = 50000;
do
{
v26 = init_ib(fileBuf, v22);
res = v26;
if ( v26 )
break;
usleep(0x64u);
--v25;
}
while ( v25 );
if ( res )
{
puts("Connection established");
v27 = malloc(0x40uLL);
*v27 = head_node;
v27[1] = v22;
v27[2] = v23;
v27[3] = v24;
v27[4] = &m1lockw;
v27[5] = &m1lockr;
v27[6] = &m2lockw;
v27[7] = &m2lockr;
pthread_mutex_lock(&m1lockw);
pthread_mutex_lock(&m1lockr);
if ( is_client )
pthread_create(&tRead, 0LL, (void *(*)(void *))ReadFileWrapper, v27);
else
pthread_create(&tRead, 0LL, (void *(*)(void *))RecvBufWrapper, v27);
v28 = malloc(0x38uLL);
*v28 = v23;
v28[1] = v24;
v28[2] = v22;
v28[3] = &m1lockw;
v28[4] = &m1lockr;
v28[5] = &m2lockw;
v28[6] = &m2lockr;
if ( is_client )
pthread_create(&tWrite, 0LL, (void *(*)(void *))SendBufWrapper, v28);
else
pthread_create(&tWrite, 0LL, (void *(*)(void *))WriteFileWrapper, v28);
pthread_join(tRead, 0LL);
pthread_join(tWrite, 0LL);
if ( verbose_mode )
{
puts("-----------SUMMARY-------------------");
printf("head_node\tfilename:%s\n", head_node);
for ( j = head_node; j; j = *(_QWORD *)(j + 272) )
{
printf("name:%s\n", (const char *)j);
printf("size:%ld\n", *(_QWORD *)(j + 256));
printf("mode:%d\n", *(unsigned int *)(j + 264));
}
}
resources_destroy(res);
result = 0;
}
else
{
printf("fail to init the ib");
result = 0;
}
}
else
{
switch ( v5 )
{
case 'd':
config = strdup(optarg);
continue;
case 'f':
*((_QWORD *)&added_config + 1) = strdup(optarg);
continue;
case 'i':
v6 = strtoul(optarg, 0LL, 0);
*((_DWORD *)&config + 5) = v6;
if ( v6 >= 0 )
continue;
printf("error tcp port");
result = 1;
break;
case 'l':
*((_QWORD *)&added_config + 3) = strdup(optarg);
continue;
case 'n':
v4 = strtoul(optarg, 0LL, 0);
continue;
case 'p':
*((_DWORD *)&config + 4) = strtoul(optarg, 0LL, 0);
continue;
case 'r':
*((_QWORD *)&added_config + 2) = strdup(optarg);
continue;
case 's':
*((_QWORD *)&config + 1) = strdup(optarg);
is_client = 1;
continue;
case 'v':
verbose_mode = 1;
continue;
case 'w':
added_config = strtoul(optarg, 0LL, 0);
continue;
default:
continue;
}
}
break;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 srand(time(0));
 int nprocs = 1;
 config.dev_name=strdup("mlx4_0");
 config.tcp_port=19879;
 config.ib_port=1;
 while (1) {
  int c;
  static struct option long_options[] = {
   {.name = "port",.has_arg = 1,.val = 'p'},
   {.name = "ib-dev",.has_arg = 1,.val = 'd'},
   {.name = "windowsize",.has_arg = 1,.val = 'w'},
   {.name = "file",.has_arg = 1,.val = 'f'},
   {.name = "list",.has_arg = 1,.val = 'l'},
   {.name = "reserve",.has_arg = 0,.val = 'r'},
   {.name = "cover",.has_arg = 0,.val = 'c'},
   {.name = "verbose",.has_arg = 0,.val = 'v'},
   {.name = "ib-port",.has_arg = 1,.val = 'i'},
   {.name = "server", .has_arg = 1, .val = 's'},
   {.name = "nprocs", .has_arg = 1, .val = 'n'},
   {.name = ((void *)0), .has_arg = 0, .val = '\0'}
  };
  c = getopt_long(argc, argv, "p:d:w:f:l:r:cvi:s:n:", long_options,
    ((void *)0));
  if (c == -1)
   break;
  switch (c) {
  case 'p':
   config.tcp_port = strtoul(optarg, ((void *)0), 0);
   break;
  case 'd':
   config.dev_name = strdup(optarg);
   break;
  case 'i':
   config.ib_port = strtoul(optarg, ((void *)0), 0);
   if (config.ib_port < 0) {
    printf("error tcp port");
    return 1;
   }
   break;
  case 'w':
   added_config.windowsize = strtoul(optarg, ((void *)0), 0);
   break;
  case 'f':
   added_config.p_filename = strdup(optarg);
   break;
  case 'l':
   added_config.p_listname = strdup(optarg);
   break;
  case 's':
   config.server_name = strdup(optarg);
   is_client = 1;
   break;
  case 'n':
   nprocs = strtoul(optarg, ((void *)0), 0);
   break;
  case 'r':
   added_config.p_dir=strdup(optarg);
   break;
  case 'v':
   verbose_mode = 1;
   break;
  }
 }
 pid_t server_conn_pid = 0;
 if (is_client) {
  server_conn_pid = fork();
  if (server_conn_pid == 0) {
   char cmd[256];
   sprintf(cmd, "ssh %s ibcp -n %d -w %d >/dev/null 2>/dev/null", config.server_name, nprocs, added_config.windowsize);
   system(cmd);
   exit(0);
  } else if (server_conn_pid < 0) {
   printf("Failed to fork\n");
  }
 }
 struct f_linkedlist **head_nodes = malloc(sizeof(struct f_linkedlist*) * nprocs);
 struct f_linkedlist **nows = malloc(sizeof(struct f_linkedlist*) * nprocs);
 memset(head_nodes, 0, sizeof(struct f_linkedlist*) * nprocs);
 memset(nows, 0, sizeof(struct f_linkedlist*) * nprocs);
 file_linkedlist_creat();
 pid_t *pids = malloc(sizeof(pid_t) * nprocs);
 if (nprocs >= 1) {
  struct f_linkedlist *now = head_node;
  int id = 0;
  while (now != ((void *)0)) {
   int random = id % nprocs;
   id += 1;
   if (nows[random] == ((void *)0)) {
    nows[random] = now;
    head_nodes[random] = now;
   } else {
    nows[random]->next = now;
    nows[random] = now;
   }
   struct f_linkedlist *newnow = now->next;
   nows[random]->next = ((void *)0);
   now = newnow;
  }
  int k = 0;
  int child = 0;
  for (k = 0; k < nprocs; k++) {
   pid_t pid = fork();
   if (pid > 0) {
    *(pids + k) = pid;
   } else if (pid == 0) {
    child = 1;
    break;
   } else {
    printf("Failed to fork\n");
   }
  }
  if (child) {
   config.tcp_port += k;
   head_node = head_nodes[k];
   goto core;
  } else {
   for (k = 0; k < nprocs; k++) waitpid(pids[k], ((void *)0), 0);
   printf("-------------------------------------------\nClient send data end, waiting for remote to finish writing\n--------------------------------------------\n");
   waitpid(server_conn_pid, ((void *)0), 0);
   printf("Remote write finished\n");
   exit(0);
  }
 }
core:
 printf("IS Client: %d\n", is_client);
 long int bufSize = added_config.windowsize;
 void *buf1 = malloc(bufSize*1024);
 void *buf2 = malloc(bufSize*1024);
 pthread_mutex_init(&m1lockw, ((void *)0));
 pthread_mutex_init(&m1lockr, ((void *)0));
 pthread_mutex_init(&m2lockw, ((void *)0));
 pthread_mutex_init(&m2lockr, ((void *)0));
 printf("start to read\n");
 fileBuf = malloc(bufSize * 1024);
 memset(fileBuf, 0, bufSize * 1024);
 int tt = 50000;
 while (tt--) {
  res = init_ib(fileBuf, bufSize * 1024);
  if (res) break;
  usleep(100);
 }
 if (!res) {
  printf("fail to init the ib");
  return 0;
 }
 printf("Connection established\n");
 unsigned long long *argsRead = malloc(sizeof(unsigned long long) * 8);
 argsRead[0] = (unsigned long long) (head_node);
 argsRead[1] = bufSize * 1024;
 argsRead[2] = buf1;
 argsRead[3] = buf2;
 argsRead[4] = &m1lockw;
 argsRead[5] = &m1lockr;
 argsRead[6] = &m2lockw;
 argsRead[7] = &m2lockr;
 pthread_mutex_lock(&m1lockw);
 pthread_mutex_lock(&m1lockr);
 if (is_client)
  pthread_create(&tRead, ((void *)0), &ReadFileWrapper, argsRead);
 else
  pthread_create(&tRead, ((void *)0), &RecvBufWrapper, argsRead);
 unsigned long long *argsWrite = malloc(sizeof(unsigned long long) * 7);
 argsWrite[0] = buf1;
 argsWrite[1] = buf2;
 argsWrite[2] = bufSize * 1024;
 argsWrite[3] = &m1lockw;
 argsWrite[4] = &m1lockr;
 argsWrite[5] = &m2lockw;
 argsWrite[6] = &m2lockr;
 if (is_client)
  pthread_create(&tWrite, ((void *)0), &SendBufWrapper, argsWrite);
 else
  pthread_create(&tWrite, ((void *)0), *WriteFileWrapper, argsWrite);
 pthread_join(tRead, ((void *)0));
 pthread_join(tWrite, ((void *)0));
 if (verbose_mode) {
  printf("-----------SUMMARY-------------------\n");
  printf("head_node\tfilename:%s\n", head_node->f_name);
  struct f_linkedlist *temp;
  temp = head_node;
  while (temp != ((void *)0)) {
   printf("name:%s\n", temp->f_name);
   printf("size:%ld\n", temp->f_size);
   printf("mode:%d\n", temp->f_mode);
   temp = temp->next;
  }
 }
 resources_destroy(res);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 srand(time(0));
 int nprocs = 1;
 config.dev_name=strdup("mlx4_0");
 config.tcp_port=19879;
 config.ib_port=1;
 while (1) {
  int c;
  static struct option long_options[] = {
   {.name = "port",.has_arg = 1,.val = 'p'},
   {.name = "ib-dev",.has_arg = 1,.val = 'd'},
   {.name = "windowsize",.has_arg = 1,.val = 'w'},
   {.name = "file",.has_arg = 1,.val = 'f'},
   {.name = "list",.has_arg = 1,.val = 'l'},
   {.name = "reserve",.has_arg = 0,.val = 'r'},
   {.name = "cover",.has_arg = 0,.val = 'c'},
   {.name = "verbose",.has_arg = 0,.val = 'v'},
   {.name = "ib-port",.has_arg = 1,.val = 'i'},
   {.name = "server", .has_arg = 1, .val = 's'},
   {.name = "nprocs", .has_arg = 1, .val = 'n'},
   {.name = ((void *)0), .has_arg = 0, .val = '\0'}
  };
  c = getopt_long(argc, argv, "p:d:w:f:l:r:cvi:s:n:", long_options,
    ((void *)0));
  if (c == -1)
   break;
  switch (c) {
  case 'p':
   config.tcp_port = strtoul(optarg, ((void *)0), 0);
   break;
  case 'd':
   config.dev_name = strdup(optarg);
   break;
  case 'i':
   config.ib_port = strtoul(optarg, ((void *)0), 0);
   if (config.ib_port < 0) {
    printf("error tcp port");
    return 1;
   }
   break;
  case 'w':
   added_config.windowsize = strtoul(optarg, ((void *)0), 0);
   break;
  case 'f':
   added_config.p_filename = strdup(optarg);
   break;
  case 'l':
   added_config.p_listname = strdup(optarg);
   break;
  case 's':
   config.server_name = strdup(optarg);
   is_client = 1;
   break;
  case 'n':
   nprocs = strtoul(optarg, ((void *)0), 0);
   break;
  case 'r':
   added_config.p_dir=strdup(optarg);
   break;
  case 'v':
   verbose_mode = 1;
   break;
  }
 }
 int server_conn_pid = 0;
 if (is_client) {
  server_conn_pid = fork();
  if (server_conn_pid == 0) {
   char cmd[256];
   sprintf(cmd, "ssh %s ibcp -n %d -w %d >/dev/null 2>/dev/null", config.server_name, nprocs, added_config.windowsize);
   system(cmd);
   exit(0);
  } else if (server_conn_pid < 0) {
   printf("Failed to fork\n");
  }
 }
 struct f_linkedlist **head_nodes = malloc(sizeof(struct f_linkedlist*) * nprocs);
 struct f_linkedlist **nows = malloc(sizeof(struct f_linkedlist*) * nprocs);
 memset(head_nodes, 0, sizeof(struct f_linkedlist *) * nprocs);
 memset(nows, 0, sizeof(struct f_linkedlist *) * nprocs);
 file_linkedlist_creat();
 int *pids = malloc(sizeof(pid_t) * nprocs);
 if (nprocs >= 1) {
  struct f_linkedlist *now = head_node;
  int id = 0;
  while (now != ((void *)0)) {
   int random = id % nprocs;
   id += 1;
   if (nows[random] == ((void *)0)) {
    nows[random] = now;
    head_nodes[random] = now;
   } else {
    nows[random]->next = now;
    nows[random] = now;
   }
   struct f_linkedlist *newnow = now->next;
   nows[random]->next = ((void *)0);
   now = newnow;
  }
  int k = 0;
  int child = 0;
  for (k = 0; k < nprocs; k++) {
   int pid = fork();
   if (pid > 0) {
    *(pids + k) = pid;
   } else if (pid == 0) {
    child = 1;
    break;
   } else {
    printf("Failed to fork\n");
   }
  }
  if (child) {
   config.tcp_port += k;
   head_node = head_nodes[k];
   goto core;
  } else {
   for (k = 0; k < nprocs; k++) waitpid(pids[k], ((void *)0), 0);
   printf("-------------------------------------------\nClient send data end, waiting for remote to finish writing\n--------------------------------------------\n");
   waitpid(server_conn_pid, ((void *)0), 0);
   printf("Remote write finished\n");
   exit(0);
  }
 }
core:
 printf("IS Client: %d\n", is_client);
 long bufSize = added_config.windowsize;
 void *buf1 = malloc(bufSize*1024);
 void *buf2 = malloc(bufSize*1024);
 pthread_mutex_init(&m1lockw, ((void *)0));
 pthread_mutex_init(&m1lockr, ((void *)0));
 pthread_mutex_init(&m2lockw, ((void *)0));
 pthread_mutex_init(&m2lockr, ((void *)0));
 printf("start to read\n");
 fileBuf = malloc(bufSize * 1024);
 memset(fileBuf, 0, bufSize * 1024);
 int tt = 50000;
 while (tt--) {
  res = init_ib(fileBuf, bufSize * 1024);
  if (res) break;
  usleep(100);
 }
 if (!res) {
  printf("fail to init the ib");
  return 0;
 }
 printf("Connection established\n");
 unsigned long long *argsRead = malloc(sizeof(unsigned long long) * 8);
 argsRead[0] = (unsigned long long) (head_node);
 argsRead[1] = bufSize * 1024;
 argsRead[2] = buf1;
 argsRead[3] = buf2;
 argsRead[4] = &m1lockw;
 argsRead[5] = &m1lockr;
 argsRead[6] = &m2lockw;
 argsRead[7] = &m2lockr;
 pthread_mutex_lock(&m1lockw);
 pthread_mutex_lock(&m1lockr);
 if (is_client)
  pthread_create(&tRead, ((void *)0), &ReadFileWrapper, argsRead);
 else
  pthread_create(&tRead, ((void *)0), &RecvBufWrapper, argsRead);
 unsigned long long *argsWrite = malloc(sizeof(unsigned long long) * 7);
 argsWrite[0] = buf1;
 argsWrite[1] = buf2;
 argsWrite[2] = bufSize * 1024;
 argsWrite[3] = &m1lockw;
 argsWrite[4] = &m1lockr;
 argsWrite[5] = &m2lockw;
 argsWrite[6] = &m2lockr;
 if (is_client)
  pthread_create(&tWrite, ((void *)0), &SendBufWrapper, argsWrite);
 else
  pthread_create(&tWrite, ((void *)0), *WriteFileWrapper, argsWrite);
 pthread_join(tRead, ((void *)0));
 pthread_join(tWrite, ((void *)0));
 if (verbose_mode) {
  printf("-----------SUMMARY-------------------\n");
  printf("head_node\tfilename:%s\n", head_node->f_name);
  struct f_linkedlist *temp;
  temp = head_node;
  while (temp != ((void *)0)) {
   printf("name:%s\n", temp->f_name);
   printf("size:%ld\n", temp->f_size);
   printf("mode:%d\n", temp->f_mode);
   temp = temp->next;
  }
 }
 resources_destroy(res);
 return 0;
}

variable_types:
argv
char *[]

variable_types: nprocs int

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
cmd
char [256]

variable_types: struct f_linkedlist { char f_name[256]; long f_size; int f_mode; struct f_linkedlist *next; } **

variable_types:
pids
int *

variable_types: id int

variable_types: random int

variable_types: k int

variable_types: child int

variable_types: pid int

variable_types: bufSize long

variable_types: tt int

variable_types:
argsRead
unsigned long long *

variable_types:
argsWrite
unsigned long long *


decompiled_code:
__int64 __fastcall sock_recv(int fd, size_t n, void *buf)
{
unsigned int v4; // ebx
unsigned int v5; // er15
int *v6; // rbp
char *v7; // rax

do
{
v4 = recv(fd, buf, n, 256);
v5 = v4;
if ( v4 == n )
return 0;
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "recv failed: %s, rc=%d\n", v7, v4);
}
while ( *v6 == 4 && v4 );
if ( !v4 )
v5 = -1;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, size_t n, void *buf)
{
unsigned int v4; // ebx
unsigned int v5; // er15
int *v6; // rbp
char *v7; // rax

do
{
v4 = recv(fd, buf, n, 256);
v5 = v4;
if ( v4 == n )
return 0;
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "recv failed: %s, rc=%d\n", v7, v4);
}
while ( *v6 == 4 && v4 );
if ( !v4 )
v5 = -1;
return v5;
}

original_code:
static int sock_recv(int sock_fd, size_t size, void *buf)
{
 int rc;
      retry_after_signal:
 rc = recv(sock_fd, buf, size, MSG_WAITALL);
 if (rc != size) {
  fprintf(stderr, "recv failed: %s, rc=%d\n", strerror((*__errno_location ())),
   rc);
  if (((*__errno_location ()) == 4) && (rc != 0))
   goto retry_after_signal;
  if (rc)
   return rc;
  else
   return -1;
 }
 return 0;
}

canonical_original_code:
static int sock_recv(int sock_fd, unsigned long size, void *buf)
{
 int rc;
      retry_after_signal:
 rc = recv(sock_fd, buf, size, MSG_WAITALL);
 if (rc != size) {
  fprintf(stderr, "recv failed: %s, rc=%d\n", strerror((*__errno_location ())),
   rc);
  if (((*__errno_location ()) == 4) && (rc != 0))
   goto retry_after_signal;
  if (rc)
   return rc;
  else
   return -1;
 }
 return 0;
}

variable_types:
size
unsigned long

variable_types:
buf
void *

variable_types: rc int


decompiled_code:
__int64 __fastcall sock_send(int fd, size_t n, void *buf)
{
unsigned int v4; // ebx
unsigned int v5; // er15
int *v6; // rbp
char *v7; // rax

do
{
v4 = send(fd, buf, n, 0);
v5 = v4;
if ( v4 == n )
return 0;
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "send failed: %s, rc=%d\n", v7, v4);
}
while ( *v6 == 4 && v4 );
if ( !v4 )
v5 = -1;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, size_t n, void *buf)
{
unsigned int v4; // ebx
unsigned int v5; // er15
int *v6; // rbp
char *v7; // rax

do
{
v4 = send(fd, buf, n, 0);
v5 = v4;
if ( v4 == n )
return 0;
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "send failed: %s, rc=%d\n", v7, v4);
}
while ( *v6 == 4 && v4 );
if ( !v4 )
v5 = -1;
return v5;
}

original_code:
static int sock_send(int sock_fd, size_t size, const void *buf)
{
 int rc;
      retry_after_signal:
 rc = send(sock_fd, buf, size, 0);
 if (rc != size) {
  fprintf(stderr, "send failed: %s, rc=%d\n", strerror((*__errno_location ())),
   rc);
  if (((*__errno_location ()) == 4) && (rc != 0))
   goto retry_after_signal;
  if (rc)
   return rc;
  else
   return -1;
 }
 return 0;
}

canonical_original_code:
static int sock_send(int sock_fd, unsigned long size, void *buf)
{
 int rc;
      retry_after_signal:
 rc = send(sock_fd, buf, size, 0);
 if (rc != size) {
  fprintf(stderr, "send failed: %s, rc=%d\n", strerror((*__errno_location ())),
   rc);
  if (((*__errno_location ()) == 4) && (rc != 0))
   goto retry_after_signal;
  if (rc)
   return rc;
  else
   return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall sock_daemon_connect(unsigned int a1)
{
int v1; // eax
struct addrinfo *v2; // rbx
int v3; // ebx
const char *v4; // rax
int v5; // eax
int v6; // ebp
int optval; // [rsp+4h] [rbp-64h] BYREF
char *ptr; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-20h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( asprintf(&ptr, "%d", a1) < 0 )
{
fwrite("asprintf failed\n", 1uLL, 0x10uLL, stderr);
v3 = -1;
}
else
{
v1 = getaddrinfo(0LL, ptr, &req, &pai);
optval = v1;
if ( v1 < 0 )
{
v4 = gai_strerror(v1);
fprintf(stderr, "%s for port %d\n", v4, a1);
free(ptr);
v3 = -1;
}
else
{
v2 = pai;
if ( pai )
{
do
{
v5 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v6 = v5;
if ( v5 >= 0 )
{
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( !bind(v6, v2->ai_addr, v2->ai_addrlen) )
{
freeaddrinfo(pai);
free(ptr);
goto LABEL_13;
}
close(v6);
v6 = -1;
}
v2 = v2->ai_next;
}
while ( v2 );
freeaddrinfo(pai);
free(ptr);
if ( v6 < 0 )
goto LABEL_5;
LABEL_13:
listen(v6, 1);
v3 = accept(v6, 0LL, 0LL);
close(v6);
if ( v3 < 0 )
{
fwrite("accept() failed\n", 1uLL, 0x10uLL, stderr);
v3 = -1;
}
}
else
{
freeaddrinfo(0LL);
free(ptr);
LABEL_5:
fprintf(stderr, "couldn't listen to port %d\n", a1);
v3 = -1;
}
}
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
int v1; // eax
struct addrinfo *v2; // rbx
int v3; // ebx
const char *v4; // rax
int v5; // eax
int v6; // ebp
int optval; // [rsp+4h] [rbp-64h] BYREF
char *ptr; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-20h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( asprintf(&ptr, "%d", a1) < 0 )
{
fwrite("asprintf failed\n", 1uLL, 0x10uLL, stderr);
v3 = -1;
}
else
{
v1 = getaddrinfo(0LL, ptr, &req, &pai);
optval = v1;
if ( v1 < 0 )
{
v4 = gai_strerror(v1);
fprintf(stderr, "%s for port %d\n", v4, a1);
free(ptr);
v3 = -1;
}
else
{
v2 = pai;
if ( pai )
{
do
{
v5 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v6 = v5;
if ( v5 >= 0 )
{
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( !bind(v6, v2->ai_addr, v2->ai_addrlen) )
{
freeaddrinfo(pai);
free(ptr);
goto LABEL_13;
}
close(v6);
v6 = -1;
}
v2 = v2->ai_next;
}
while ( v2 );
freeaddrinfo(pai);
free(ptr);
if ( v6 < 0 )
goto LABEL_5;
LABEL_13:
listen(v6, 1);
v3 = accept(v6, 0LL, 0LL);
close(v6);
if ( v3 < 0 )
{
fwrite("accept() failed\n", 1uLL, 0x10uLL, stderr);
v3 = -1;
}
}
else
{
freeaddrinfo(0LL);
free(ptr);
LABEL_5:
fprintf(stderr, "couldn't listen to port %d\n", a1);
v3 = -1;
}
}
}
return (unsigned int)v3;
}

original_code:
int sock_daemon_connect(int port)
{
 struct addrinfo *res, *t;
 struct addrinfo hints = {
  .ai_flags = 0x0001,
  .ai_family = 0,
  .ai_socktype = SOCK_STREAM
 };
 char *service;
 int n;
 int sockfd = -1, connfd;
 if (asprintf(&service, "%d", port) < 0) {
  fprintf(stderr, "asprintf failed\n");
  return -1;
 }
 n = getaddrinfo(((void *)0), service, &hints, &res);
 if (n < 0) {
  fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
  free(service);
  return -1;
 }
 for (t = res; t; t = t->ai_next) {
  sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
  if (sockfd >= 0) {
   n = 1;
   setsockopt(sockfd, 1, 2, &n,
       sizeof n);
   if (!bind(sockfd, t->ai_addr, t->ai_addrlen))
    break;
   close(sockfd);
   sockfd = -1;
  }
 }
 freeaddrinfo(res);
 free(service);
 if (sockfd < 0) {
  fprintf(stderr, "couldn't listen to port %d\n", port);
  return -1;
 }
 listen(sockfd, 1);
 connfd = accept(sockfd, ((void *)0), 0);
 close(sockfd);
 if (connfd < 0) {
  fprintf(stderr, "accept() failed\n");
  return -1;
 }
 return connfd;
}

canonical_original_code:
int sock_daemon_connect(int port)
{
 struct addrinfo *res; struct addrinfo *t;
 struct addrinfo hints = {
  .ai_flags = 0x0001,
  .ai_family = 0,
  .ai_socktype = SOCK_STREAM
 };
 char *service;
 int n;
 int sockfd = -1; int connfd;
 if (asprintf(&service, "%d", port) < 0) {
  fprintf(stderr, "asprintf failed\n");
  return -1;
 }
 n = getaddrinfo(((void *)0), service, &hints, &res);
 if (n < 0) {
  fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
  free(service);
  return -1;
 }
 for (t = res; t; t = t->ai_next) {
  sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
  if (sockfd >= 0) {
   n = 1;
   setsockopt(sockfd, 1, 2, &n,
       sizeof n);
   if (!bind(sockfd, t->ai_addr, t->ai_addrlen))
    break;
   close(sockfd);
   sockfd = -1;
  }
 }
 freeaddrinfo(res);
 free(service);
 if (sockfd < 0) {
  fprintf(stderr, "couldn't listen to port %d\n", port);
  return -1;
 }
 listen(sockfd, 1);
 connfd = accept(sockfd, ((void *)0), 0);
 close(sockfd);
 if (connfd < 0) {
  fprintf(stderr, "accept() failed\n");
  return -1;
 }
 return connfd;
}

variable_types: port int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
service
char *

variable_types: n int

variable_types: sockfd int

variable_types: connfd int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall sock_client_connect(char *name, unsigned int a2)
{
int v2; // eax
struct addrinfo *v3; // rbx
__int64 result; // rax
const char *v5; // rax
int v6; // eax
int v7; // ebp
char *ptr; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-20h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( asprintf(&ptr, "%d", a2) < 0 )
{
fwrite("asprintf failed\n", 1uLL, 0x10uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = getaddrinfo(name, ptr, &req, &pai);
if ( v2 < 0 )
{
v5 = gai_strerror(v2);
fprintf(stderr, "%s for %s:%d\n", v5, name, a2);
free(ptr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = pai;
if ( pai )
{
while ( 1 )
{
v6 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v7 = v6;
if ( v6 >= 0 )
{
if ( !connect(v6, v3->ai_addr, v3->ai_addrlen) )
goto LABEL_12;
close(v7);
v7 = -1;
}
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_12;
}
}
v7 = -1;
LABEL_12:
freeaddrinfo(pai);
free(ptr);
result = 0xFFFFFFFFLL;
if ( v7 >= 0 )
result = (unsigned int)v7;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *name, unsigned int a2)
{
int v2; // eax
struct addrinfo *v3; // rbx
__int64 result; // rax
const char *v5; // rax
int v6; // eax
int v7; // ebp
char *ptr; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-20h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( asprintf(&ptr, "%d", a2) < 0 )
{
fwrite("asprintf failed\n", 1uLL, 0x10uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = getaddrinfo(name, ptr, &req, &pai);
if ( v2 < 0 )
{
v5 = gai_strerror(v2);
fprintf(stderr, "%s for %s:%d\n", v5, name, a2);
free(ptr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = pai;
if ( pai )
{
while ( 1 )
{
v6 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v7 = v6;
if ( v6 >= 0 )
{
if ( !connect(v6, v3->ai_addr, v3->ai_addrlen) )
goto LABEL_12;
close(v7);
v7 = -1;
}
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_12;
}
}
v7 = -1;
LABEL_12:
freeaddrinfo(pai);
free(ptr);
result = 0xFFFFFFFFLL;
if ( v7 >= 0 )
result = (unsigned int)v7;
}
}
return result;
}

original_code:
int sock_client_connect(const char *server_name, int port)
{
 struct addrinfo *res, *t;
 struct addrinfo hints = {
  .ai_family = 0,
  .ai_socktype = SOCK_STREAM
 };
 char *service;
 int n;
 int sockfd = -1;
 if (asprintf(&service, "%d", port) < 0) {
  fprintf(stderr, "asprintf failed\n");
  return -1;
 }
 n = getaddrinfo(server_name, service, &hints, &res);
 if (n < 0) {
  fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), server_name,
   port);
  free(service);
  return -1;
 }
 for (t = res; t; t = t->ai_next) {
  sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
  if (sockfd >= 0) {
   if (!connect(sockfd, t->ai_addr, t->ai_addrlen))
    break;
   close(sockfd);
   sockfd = -1;
  }
 }
 freeaddrinfo(res);
 free(service);
 if (sockfd < 0) {
  return -1;
 }
 return sockfd;
}

canonical_original_code:
int sock_client_connect(char *server_name, int port)
{
 struct addrinfo *res; struct addrinfo *t;
 struct addrinfo hints = {
  .ai_family = 0,
  .ai_socktype = SOCK_STREAM
 };
 char *service;
 int n;
 int sockfd = -1;
 if (asprintf(&service, "%d", port) < 0) {
  fprintf(stderr, "asprintf failed\n");
  return -1;
 }
 n = getaddrinfo(server_name, service, &hints, &res);
 if (n < 0) {
  fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), server_name,
   port);
  free(service);
  return -1;
 }
 for (t = res; t; t = t->ai_next) {
  sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
  if (sockfd >= 0) {
   if (!connect(sockfd, t->ai_addr, t->ai_addrlen))
    break;
   close(sockfd);
   sockfd = -1;
  }
 }
 freeaddrinfo(res);
 free(service);
 if (sockfd < 0) {
  return -1;
 }
 return sockfd;
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall sock_sync_data(int fd, int a2, size_t a3, void *a4, void *a5)
{
__int64 result; // rax

if ( a2 )
{
result = sock_recv(fd, a3, a5);
if ( !(_DWORD)result )
result = sock_send(fd, a3, a4);
}
else
{
result = sock_send(fd, a3, a4);
if ( !(_DWORD)result )
result = sock_recv(fd, a3, a5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2, size_t a3, void *a4, void *a5)
{
__int64 result; // rax

if ( a2 )
{
result = func0(fd, a3, a5);
if ( !(_DWORD)result )
result = func1(fd, a3, a4);
}
else
{
result = func1(fd, a3, a4);
if ( !(_DWORD)result )
result = func0(fd, a3, a5);
}
return result;
}

original_code:
int sock_sync_data(int sock_fd,
     int is_daemon,
     size_t size, const void *out_buf, void *in_buf)
{
 int rc;
 if (!is_daemon) {
  rc = sock_send(sock_fd, size, out_buf);
  if (rc)
   return rc;
  rc = sock_recv(sock_fd, size, in_buf);
  if (rc)
   return rc;
 } else {
  rc = sock_recv(sock_fd, size, in_buf);
  if (rc)
   return rc;
  rc = sock_send(sock_fd, size, out_buf);
  if (rc)
   return rc;
 }
 return 0;
}

canonical_original_code:
int sock_sync_data(int sock_fd, int is_daemon, unsigned long size, void *out_buf, void *in_buf)
{
 int rc;
 if (!is_daemon) {
  rc = sock_send(sock_fd, size, out_buf);
  if (rc)
   return rc;
  rc = sock_recv(sock_fd, size, in_buf);
  if (rc)
   return rc;
 } else {
  rc = sock_recv(sock_fd, size, in_buf);
  if (rc)
   return rc;
  rc = sock_send(sock_fd, size, out_buf);
  if (rc)
   return rc;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall sock_sync_ready(int a1, int a2)
{
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

v3[0] = 97;
return sock_sync_data(a1, a2, 1uLL, v3, v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

v3[0] = 97;
return func4(a1, a2, 1uLL, v3, v3);
}

original_code:
int sock_sync_ready(int sock_fd, int is_daemon)
{
 char cm_buf = 'a';
 return sock_sync_data(sock_fd, is_daemon, sizeof(cm_buf), &cm_buf,
         &cm_buf);
}


SendBuf

decompiled_code:
int __fastcall SendBuf(void *a1, __int64 a2, int a3, pthread_mutex_t *a4, pthread_mutex_t *a5, pthread_mutex_t *a6, pthread_mutex_t *mutex)
{
int result; // eax
void *src; // [rsp+10h] [rbp-48h] BYREF
int v13[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v13[0] = -1;
src = a1;
pthread_mutex_lock(a5);
while ( 1 )
{
memcpy(fileBuf, src, a3);
if ( (unsigned int)sock_sync_ready(*(unsigned int *)(res + 360LL), config[1] == 0LL) )
{
puts("sync failed");
resources_destroy(res);
exit(1);
}
if ( (unsigned int)sock_sync_ready(*(unsigned int *)(res + 360LL), config[1] == 0LL) )
{
puts("sync failed 2");
resources_destroy(res);
exit(1);
}
if ( *(_DWORD *)src == 1 )
break;
switchMemory(v13, &src, a1, a2, a4, a5, a6, mutex);
src = (char *)src - 4;
}
if ( v13[0] == -1 )
{
pthread_mutex_unlock(a4);
result = pthread_mutex_unlock(a5);
}
else
{
pthread_mutex_unlock(a6);
result = pthread_mutex_unlock(mutex);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(void *a1, __int64 a2, int a3, pthread_mutex_t *a4, pthread_mutex_t *a5, pthread_mutex_t *a6, pthread_mutex_t *mutex)
{
int result; // eax
void *src; // [rsp+10h] [rbp-48h] BYREF
int v13[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v13[0] = -1;
src = a1;
pthread_mutex_lock(a5);
while ( 1 )
{
memcpy(fileBuf, src, a3);
if ( (unsigned int)sock_sync_ready(*(unsigned int *)(res + 360LL), config[1] == 0LL) )
{
puts("sync failed");
resources_destroy(res);
exit(1);
}
if ( (unsigned int)sock_sync_ready(*(unsigned int *)(res + 360LL), config[1] == 0LL) )
{
puts("sync failed 2");
resources_destroy(res);
exit(1);
}
if ( *(_DWORD *)src == 1 )
break;
switchMemory(v13, &src, a1, a2, a4, a5, a6, mutex);
src = (char *)src - 4;
}
if ( v13[0] == -1 )
{
pthread_mutex_unlock(a4);
result = pthread_mutex_unlock(a5);
}
else
{
pthread_mutex_unlock(a6);
result = pthread_mutex_unlock(mutex);
}
return result;
}

original_code:
void SendBuf(void *memory1, void *memory2, int bufSize, pthread_mutex_t *m1lockw, pthread_mutex_t *m1lockr, pthread_mutex_t *m2lockw, pthread_mutex_t *m2lockr) {
 long int remainMemory = bufSize;
 int currentMemory = -1;
 void *p = memory1;
 pthread_mutex_lock(m1lockr);
 while (1) {
  memcpy(fileBuf, p, bufSize);
  if (sock_sync_ready(res->sock, !config.server_name)) { printf("sync failed\n"); resources_destroy(res); exit(1); }
  if (sock_sync_ready(res->sock, !config.server_name)) { printf("sync failed 2\n"); resources_destroy(res); exit(1); }
  if ((*(int *)p) == 1) break;
  switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
  p -= sizeof(int);
 }
 if (currentMemory == -1) { pthread_mutex_unlock(m1lockw); pthread_mutex_unlock(m1lockr); }
 else { pthread_mutex_unlock(m2lockw); pthread_mutex_unlock(m2lockr); }
}

canonical_original_code:
void SendBuf(void *memory1, void *memory2, int bufSize, union pthread_mutex_t *m1lockw, union pthread_mutex_t *m1lockr, union pthread_mutex_t *m2lockw, union pthread_mutex_t *m2lockr) {
 long remainMemory = bufSize;
 int currentMemory = -1;
 void *p = memory1;
 pthread_mutex_lock(m1lockr);
 while (1) {
  memcpy(fileBuf, p, bufSize);
  if (sock_sync_ready(res->sock, !config.server_name)) { printf("sync failed\n"); resources_destroy(res); exit(1); }
  if (sock_sync_ready(res->sock, !config.server_name)) { printf("sync failed 2\n"); resources_destroy(res); exit(1); }
  if ((*(int *)p) == 1) break;
  switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
  p -= sizeof(int);
 }
 if (currentMemory == -1) { pthread_mutex_unlock(m1lockw); pthread_mutex_unlock(m1lockr); }
 else { pthread_mutex_unlock(m2lockw); pthread_mutex_unlock(m2lockr); }
}

variable_types: bufSize int

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

variable_types: remainMemory long

variable_types: currentMemory int

variable_types:
p
void *

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

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


decompiled_code:
int __fastcall dir_proc(const char *a1)
{
int result; // eax

result = nftw(a1, singlefile_proc, 20, 9);
if ( result == -1 )
{
perror("error to call ntfw");
exit(5);
}
return result;
}

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

result = nftw(a1, singlefile_proc, 20, 9);
if ( result == -1 )
{
perror("error to call ntfw");
exit(5);
}
return result;
}

original_code:
void dir_proc(const char *dirname)
{
    int flags=0;
    flags|=FTW_DEPTH;
    flags|=FTW_PHYS;
    if(nftw(dirname,singlefile_proc,20,flags)==-1)
    {
        perror("error to call ntfw");
        exit(5);
    }
}

canonical_original_code:
void dir_proc(char *dirname)
{
    int flags = 0;
    flags|=FTW_DEPTH;
    flags|=FTW_PHYS;
    if(nftw(dirname,singlefile_proc,20,flags)==-1)
    {
        perror("error to call ntfw");
        exit(5);
    }
}

variable_types:
dirname
char *

variable_types: flags int


decompiled_code:
__int64 __fastcall node_creat(char *file, __int64 *a2)
{
void *v2; // rax
__int64 v3; // rbx
__int64 result; // rax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v2 = malloc(0x118uLL);
if ( !v2 )
{
perror("error to malloc p_temp");
exit(2);
}
v3 = (__int64)v2;
memset(v2, 0, 0x118uLL);
strcpy((char *)v2, file);
if ( stat(file, &v5) < 0 )
{
perror("error to call stat()");
exit(3);
}
*(_QWORD *)(v3 + 256) = v5.st_size;
result = v5.st_mode;
*(_DWORD *)(v3 + 264) = v5.st_mode;
if ( *a2 )
{
result = p_0;
*(_QWORD *)(p_0 + 272) = v3;
}
else
{
*a2 = v3;
}
p_0 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *file, __int64 *a2)
{
void *v2; // rax
__int64 v3; // rbx
__int64 result; // rax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v2 = malloc(0x118uLL);
if ( !v2 )
{
perror("error to malloc p_temp");
exit(2);
}
v3 = (__int64)v2;
memset(v2, 0, 0x118uLL);
strcpy((char *)v2, file);
if ( stat(file, &v5) < 0 )
{
perror("error to call stat()");
exit(3);
}
*(_QWORD *)(v3 + 256) = v5.st_size;
result = v5.st_mode;
*(_DWORD *)(v3 + 264) = v5.st_mode;
if ( *a2 )
{
result = p_0;
*(_QWORD *)(p_0 + 272) = v3;
}
else
{
*a2 = v3;
}
p_0 = v3;
return result;
}

original_code:
void node_creat(const char *name,struct f_linkedlist** p_head_node)
{
    static struct f_linkedlist* p=((void *)0);
    struct stat st;
    struct f_linkedlist *p_temp =(struct f_linkedlist*)malloc(sizeof(struct f_linkedlist));
    if(p_temp==((void *)0))
    {
        perror("error to malloc p_temp");
        exit(2);
    }
    memset(p_temp,0,sizeof(struct f_linkedlist));
    strcpy(p_temp->f_name,name);
    if(stat(name,&st)<0)
    {
        perror("error to call stat()");
        exit(3);
    }
    p_temp->f_size=st.st_size;
    p_temp->f_mode=st.st_mode;
    if((*p_head_node)!=((void *)0))
    {
        p->next=p_temp;
    }else
        *p_head_node=p_temp;
        p=p_temp;
}

canonical_original_code:
void node_creat(char *name, struct f_linkedlist **p_head_node)
{
    static struct f_linkedlist *p = ((void *)0);
    struct stat st;
    struct f_linkedlist *p_temp = (struct f_linkedlist*)malloc(sizeof(struct f_linkedlist));
    if(p_temp==((void *)0))
    {
        perror("error to malloc p_temp");
        exit(2);
    }
    memset(p_temp,0,sizeof(struct f_linkedlist));
    strcpy(p_temp->f_name,name);
    if(stat(name,&st)<0)
    {
        perror("error to call stat()");
        exit(3);
    }
    p_temp->f_size=st.st_size;
    p_temp->f_mode=st.st_mode;
    if((*p_head_node)!=((void *)0))
    {
        p->next=p_temp;
    }else
        *p_head_node=p_temp;
        p=p_temp;
}

variable_types:
name
char *

variable_types: struct f_linkedlist { char f_name[256]; long f_size; int f_mode; struct f_linkedlist *next; } **

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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall singlefile_proc(const char *filename, const struct stat *status, int flag, struct FTW *info)
{
if ( !flag )
node_creat((char *)filename, (__int64 *)&head_node);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *filename, const struct stat *status, int flag, struct FTW *info)
{
if ( !flag )
func1((char *)filename, (__int64 *)&head_node);
return 0LL;
}

original_code:
static int singlefile_proc(const char* fpath,const struct stat *sb,int tflag,struct FTW *ftwbuf)
{
    if(tflag==FTW_F)
    {
        node_creat(fpath,&head_node);
    }
    return 0;
}

canonical_original_code:
static int singlefile_proc(char *fpath, struct stat *sb, int tflag, struct FTW *ftwbuf)
{
    if(tflag==FTW_F)
    {
        node_creat(fpath,&head_node);
    }
    return 0;
}

variable_types:
fpath
char *

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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } *

variable_types: tflag int

variable_types:
ftwbuf
struct FTW { int base; int level; } *


decompiled_code:
void file_linkedlist_del()
{
void *v0; // rbx
void *v1; // rdi

v0 = head_node;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 34);
free(v1);
}
head_node = 0LL;
}

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

v0 = head_node;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 34);
free(v1);
}
head_node = 0LL;
}

original_code:
void file_linkedlist_del(void)
{
    struct f_linkedlist* rc=head_node;
    struct f_linkedlist* temp;
    while(rc!=((void *)0))
    {
        temp=rc->next;
        free(rc);
        rc=temp;
    }
    head_node=((void *)0);
}

canonical_original_code:
void file_linkedlist_del()
{
    struct f_linkedlist *rc = head_node;
    struct f_linkedlist *temp;
    while(rc!=((void *)0))
    {
        temp=rc->next;
        free(rc);
        rc=temp;
    }
    head_node=((void *)0);
}

variable_types: struct f_linkedlist { char f_name[256]; long f_size; int f_mode; struct f_linkedlist *next; } *


mkpath

decompiled_code:
__int64 __fastcall mkpath(char *path, __mode_t mode)
{
char *v2; // rbx
unsigned int v3; // er13

if ( !path || !*path )
_assert_fail("file_path && *file_path", "writefile.c", 0x37u, "mkpath");
v2 = strchr(path + 1, 47);
if ( !v2 )
return 0;
do
{
*v2 = 0;
v3 = mkdir(path, mode);
if ( v3 == -1 && *_errno_location() != 17 )
{
*v2 = 47;
return v3;
}
*v2 = 47;
v2 = strchr(v2 + 1, 47);
}
while ( v2 );
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *path, __mode_t mode)
{
char *v2; // rbx
unsigned int v3; // er13

if ( !path || !*path )
_assert_fail("file_path && *file_path", "writefile.c", 0x37u, "mkpath");
v2 = strchr(path + 1, 47);
if ( !v2 )
return 0;
do
{
*v2 = 0;
v3 = mkdir(path, mode);
if ( v3 == -1 && *_errno_location() != 17 )
{
*v2 = 47;
return v3;
}
*v2 = 47;
v2 = strchr(v2 + 1, 47);
}
while ( v2 );
return 0;
}

original_code:
int mkpath(char* file_path, mode_t mode) {
   ((void) sizeof ((file_path && *file_path) ? 1 : 0), __extension__ ({ if (file_path && *file_path) ; else __assert_fail ("file_path && *file_path", "writefile.c", 55, __extension__ __PRETTY_FUNCTION__); }));
   char* p;
   for (p=strchr(file_path+1, '/'); p; p=strchr(p+1, '/')) {
     *p='\0';
     if (mkdir(file_path, mode)==-1) {
       if ((*__errno_location ())!=17) { *p='/'; return -1; }
     }
     *p='/';
   }
   return 0;
 }

canonical_original_code:
int mkpath(char *file_path, unsigned int mode) {
   ((void) sizeof ((file_path && *file_path) ? 1 : 0), __extension__ ({ if (file_path && *file_path) ; else __assert_fail ("file_path && *file_path", "writefile.c", 55, __extension__ __PRETTY_FUNCTION__); }));
   char *p;
   for (p=strchr(file_path+1, '/'); p; p=strchr(p+1, '/')) {
     *p='\0';
     if (mkdir(file_path, mode)==-1) {
       if ((*__errno_location ())!=17) { *p='/'; return -1; }
     }
     *p='/';
   }
   return 0;
 }

variable_types:
mode
unsigned int

variable_types:
p
char *


WriteFile

original_code:
void WriteFile(void *memory1, void *memory2, int bufSize, pthread_mutex_t *m1lockw, pthread_mutex_t *m1lockr, pthread_mutex_t *m2lockw, pthread_mutex_t *m2lockr)
{
 bufSize -= sizeof(int);
 long int remainMemory = bufSize;
 int currentMemory = -1;
 void *writeMemory = memory1 + sizeof(int);
 void *p = writeMemory;
 pthread_mutex_lock(m1lockr);
 while (*(int*)memory1 == 0) { pthread_mutex_unlock(m1lockr); usleep(100); pthread_mutex_lock(m1lockr); }
 while (1) {
  if (remainMemory < sizeof(fileStruct)) {
   switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   remainMemory = bufSize;
  }
  fileStruct * nowfile = (fileStruct *) p;
  char filename[256]="";
  strcpy(filename,nowfile->fileName);
  printf("will write %s",filename);
  mkpath(filename,0755);
  int fd = open(filename , 0100, nowfile->fileMode);
  if(!fd){
   printf("create file error");
   exit(1);
  }
  close(fd);
  int f=open(filename,01);
  printf("size:%dmode:%d",nowfile->fileSize,nowfile->fileMode);
  fileStruct * endWrite = nowfile->next;
  remainMemory -= sizeof(fileStruct);
  if (nowfile->fileSize < remainMemory) {
   write(f, nowfile + 1, nowfile->fileSize);
   remainMemory -= nowfile->fileSize;
   p += sizeof(fileStruct);
   p += nowfile->fileSize;
   close(f);
  }
  else if (nowfile->fileSize == remainMemory) {
   write(f, nowfile + 1, nowfile->fileSize);
   remainMemory = bufSize;
   switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   close(f);
  }
  else if (nowfile->fileSize > remainMemory) {
   write(f, nowfile + 1, remainMemory);
   int fileSize = nowfile->fileSize;
   switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   int writeTimes = ceil((nowfile->fileSize - remainMemory) / (float)bufSize);
   int i = 1;
   for (i = 1; i < writeTimes;i++)
     {
    write(f, p, bufSize);
    switchMemory(&currentMemory, &p, memory1,
           memory2, m1lockw, m1lockr, m2lockw, m2lockr);
    }
   int lastSize =
       fileSize - remainMemory - (writeTimes -
             1) * bufSize;
   write(f, p, lastSize);
   p += lastSize;
   remainMemory = bufSize - lastSize;
   if (!remainMemory) {
    remainMemory = bufSize;
    switchMemory(&currentMemory, &p, memory1,
           memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   }
   close(f);
  }
  if (!endWrite)
   break;
 }
 if (currentMemory == -1) { pthread_mutex_unlock(m1lockr); pthread_mutex_unlock(m1lockw); }
 else { pthread_mutex_unlock(m2lockr); pthread_mutex_unlock(m2lockw);}
}

canonical_original_code:
void WriteFile(void *memory1, void *memory2, int bufSize, union pthread_mutex_t *m1lockw, union pthread_mutex_t *m1lockr, union pthread_mutex_t *m2lockw, union pthread_mutex_t *m2lockr)
{
 bufSize -= sizeof(int);
 long remainMemory = bufSize;
 int currentMemory = -1;
 void *writeMemory = memory1 + sizeof(int);
 void *p = writeMemory;
 pthread_mutex_lock(m1lockr);
 while (*(int *)memory1 == 0) { pthread_mutex_unlock(m1lockr); usleep(100); pthread_mutex_lock(m1lockr); }
 while (1) {
  if (remainMemory < sizeof(fileStruct)) {
   switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   remainMemory = bufSize;
  }
  struct fileStruct *nowfile = (fileStruct *) p;
  char filename[256] = "";
  strcpy(filename,nowfile->fileName);
  printf("will write %s",filename);
  mkpath(filename,0755);
  int fd = open(filename , 0100, nowfile->fileMode);
  if(!fd){
   printf("create file error");
   exit(1);
  }
  close(fd);
  int f = open(filename,01);
  printf("size:%dmode:%d",nowfile->fileSize,nowfile->fileMode);
  struct fileStruct *endWrite = nowfile->next;
  remainMemory -= sizeof(fileStruct);
  if (nowfile->fileSize < remainMemory) {
   write(f, nowfile + 1, nowfile->fileSize);
   remainMemory -= nowfile->fileSize;
   p += sizeof(fileStruct);
   p += nowfile->fileSize;
   close(f);
  }
  else if (nowfile->fileSize == remainMemory) {
   write(f, nowfile + 1, nowfile->fileSize);
   remainMemory = bufSize;
   switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   close(f);
  }
  else if (nowfile->fileSize > remainMemory) {
   write(f, nowfile + 1, remainMemory);
   int fileSize = nowfile->fileSize;
   switchMemory(&currentMemory, &p, memory1, memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   int writeTimes = ceil((nowfile->fileSize - remainMemory) / (float)bufSize);
   int i = 1;
   for (i = 1; i < writeTimes;i++)
     {
    write(f, p, bufSize);
    switchMemory(&currentMemory, &p, memory1,
           memory2, m1lockw, m1lockr, m2lockw, m2lockr);
    }
   int lastSize = fileSize - remainMemory - (writeTimes -
             1) * bufSize;
   write(f, p, lastSize);
   p += lastSize;
   remainMemory = bufSize - lastSize;
   if (!remainMemory) {
    remainMemory = bufSize;
    switchMemory(&currentMemory, &p, memory1,
           memory2, m1lockw, m1lockr, m2lockw, m2lockr);
   }
   close(f);
  }
  if (!endWrite)
   break;
 }
 if (currentMemory == -1) { pthread_mutex_unlock(m1lockr); pthread_mutex_unlock(m1lockw); }
 else { pthread_mutex_unlock(m2lockr); pthread_mutex_unlock(m2lockw);}
}

variable_types: bufSize int

variable_types:
writeMemory
void *

variable_types: struct fileStruct { char fileName[256]; long fileSize; int fileMode; struct fileStruct *next; } *

variable_types:
filename
char [256]

variable_types: fd int

variable_types: f int

variable_types: fileSize int

variable_types: writeTimes int

variable_types: i int

variable_types: lastSize int

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


repo: Vanders/logsmash

decompiled_code:
void handle_sigterm()
{
run_s = 0;
}

canonical_decompiled_code:
void func7()
{
run_s = 0;
}

original_code:
void handle_sigterm(int signo){
  run_s = 0;
}

variable_types: signo int


decompiled_code:
__int64 get_prio_rand()
{
return (unsigned int)prio_s[rand() % 8];
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)prio_s[rand() % 8];
}

original_code:
int get_prio_rand(void){
    int r;
    r = rand() % 8;
    return prio_s[r];
}

canonical_original_code:
int get_prio_rand(){
    int r;
    r = rand() % 8;
    return prio_s[r];
}

variable_types: r int


decompiled_code:
char *get_message_rand()
{
return msg_s[rand() % 7];
}

canonical_decompiled_code:
char *func9()
{
return msg_s[rand() % 7];
}

original_code:
const char* get_message_rand(void){
    int r;
    r = rand() % 7;
    return msg_s[r];
}

canonical_original_code:
char *get_message_rand(){
    int r;
    r = rand() % 7;
    return msg_s[r];
}

return_type: char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er12
int v5; // ebx
int v6; // eax
unsigned int v7; // eax
__int64 i; // r13
int v9; // ebp
int v10; // er14
char *v11; // rax
const char *v12; // rbp
int v13; // edi
int v15; // [rsp+8h] [rbp-E0h]
int useconds; // [rsp+Ch] [rbp-DCh]
struct sigaction v17; // [rsp+10h] [rbp-D8h] BYREF

v15 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "scl:q");
if ( v6 == -1 )
break;
if ( v6 == 108 )
{
v3 = atoi(optarg);
}
else if ( v6 <= 108 )
{
if ( v6 == 63 )
return 1;
if ( v6 == 99 )
v4 = 1;
}
else if ( v6 == 113 )
{
v15 = 1;
}
else if ( v6 == 115 )
{
v5 = 1;
}
}
useconds = 0;
if ( v3 > 0 )
useconds = 1000000 / v3;
v7 = time(0LL);
srand(v7);
v17.sa_handler = (__sighandler_t)handle_sigterm;
sigemptyset(&v17.sa_mask);
v17.sa_flags = 0;
sigaction(2, &v17, 0LL);
sigaction(15, &v17, 0LL);
openlog("logsmash", 11, 136);
for ( i = 0LL; ; ++i )
{
v10 = get_prio_rand();
v11 = get_message_rand();
v12 = v11;
if ( v5 )
{
printf("%lu %s\n", i, v11);
}
else if ( v4 )
{
printf("\r%lu ", i);
fflush(stdout);
}
if ( !v15 )
{
v13 = v10;
LOBYTE(v13) = v10 | 0x80;
syslog(v13, "%lu %s", i, v12);
}
if ( v3 )
usleep(useconds);
v9 = run_s;
if ( !run_s )
break;
}
putchar(10);
fflush(stdout);
closelog();
return v9;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er12
int v5; // ebx
int v6; // eax
unsigned int v7; // eax
__int64 i; // r13
int v9; // ebp
int v10; // er14
char *v11; // rax
const char *v12; // rbp
int v13; // edi
int v15; // [rsp+8h] [rbp-E0h]
int useconds; // [rsp+Ch] [rbp-DCh]
struct sigaction v17; // [rsp+10h] [rbp-D8h] BYREF

v15 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "scl:q");
if ( v6 == -1 )
break;
if ( v6 == 108 )
{
v3 = atoi(optarg);
}
else if ( v6 <= 108 )
{
if ( v6 == 63 )
return 1;
if ( v6 == 99 )
v4 = 1;
}
else if ( v6 == 113 )
{
v15 = 1;
}
else if ( v6 == 115 )
{
v5 = 1;
}
}
useconds = 0;
if ( v3 > 0 )
useconds = 1000000 / v3;
v7 = time(0LL);
srand(v7);
v17.sa_handler = (__sighandler_t)handle_sigterm;
sigemptyset(&v17.sa_mask);
v17.sa_flags = 0;
sigaction(2, &v17, 0LL);
sigaction(15, &v17, 0LL);
openlog("logsmash", 11, 136);
for ( i = 0LL; ; ++i )
{
v10 = func8();
v11 = func9();
v12 = v11;
if ( v5 )
{
printf("%lu %s\n", i, v11);
}
else if ( v4 )
{
printf("\r%lu ", i);
fflush(stdout);
}
if ( !v15 )
{
v13 = v10;
LOBYTE(v13) = v10 | 0x80;
syslog(v13, "%lu %s", i, v12);
}
if ( v3 )
usleep(useconds);
v9 = run_s;
if ( !run_s )
break;
}
putchar(10);
fflush(stdout);
closelog();
return v9;
}

original_code:
int main(int argc, char* argv[]){
    int c;
    int std_output = 0;
    int count_output = 0;
    int usec, rate = 0;
    int quiet = 0;
    unsigned long n;
    struct sigaction sa;
    while( (c = getopt( argc, argv, "scl:q") ) != -1 ) {
        switch(c){
            case 's':
                std_output = 1;
                break;
            case 'c':
                count_output = 1;
                break;
            case 'l':
                rate = atoi(optarg);
                break;
            case 'q':
                quiet = 1;
                break;
            case '?':
                return 1;
        }
    }
    if( rate > 0 ){
        usec = 1000000 / rate;
    } else {
        usec = 0;
    }
    srand(time(((void *)0)));
    sa.__sigaction_handler.sa_handler = handle_sigterm;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sigaction(2, &sa, ((void *)0));
    sigaction(15, &sa, ((void *)0));
    openlog("logsmash", 0x02 | 0x01 | 0x08, (17<<3));
    for(n=0;;n++){
        int p;
        const char* m;
        p = get_prio_rand();
        m = get_message_rand();
        if(std_output)
            printf("%lu %s\n", n, m);
        else if(count_output){
            printf("\r%lu      ", n );
            fflush(stdout);
        }
        if(!quiet)
            syslog((((16<<3)) | (p)), "%lu %s", n, m);
        if(rate)
            usleep(usec);
        if(!run_s){
          printf("\n");
          fflush(stdout);
          break;
        }
    }
    closelog();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    int c;
    int std_output = 0;
    int count_output = 0;
    int usec; int rate = 0;
    int quiet = 0;
    unsigned long n;
    struct sigaction sa;
    while( (c = getopt( argc, argv, "scl:q") ) != -1 ) {
        switch(c){
            case 's':
                std_output = 1;
                break;
            case 'c':
                count_output = 1;
                break;
            case 'l':
                rate = atoi(optarg);
                break;
            case 'q':
                quiet = 1;
                break;
            case '?':
                return 1;
        }
    }
    if( rate > 0 ){
        usec = 1000000 / rate;
    } else {
        usec = 0;
    }
    srand(time(((void *)0)));
    sa.__sigaction_handler.sa_handler = handle_sigterm;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sigaction(2, &sa, ((void *)0));
    sigaction(15, &sa, ((void *)0));
    openlog("logsmash", 0x02 | 0x01 | 0x08, (17<<3));
    for(n=0;;n++){
        int p;
        char *m;
        p = get_prio_rand();
        m = get_message_rand();
        if(std_output)
            printf("%lu %s\n", n, m);
        else if(count_output){
            printf("\r%lu      ", n );
            fflush(stdout);
        }
        if(!quiet)
            syslog((((16<<3)) | (p)), "%lu %s", n, m);
        if(rate)
            usleep(usec);
        if(!run_s){
          printf("\n");
          fflush(stdout);
          break;
        }
    }
    closelog();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: usec int

variable_types: rate int

variable_types: quiet int

variable_types:
n
unsigned long

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: p int

variable_types:
m
char *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__int64 __fastcall child_hash(__int64 a1)
{
return *(unsigned int *)(a1 + 32);
}

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

original_code:
static unsigned int child_hash(void *data)
{
    return (unsigned int) ((struct ChildEntry *) data)->pid;
}

variable_types:
data
void *

return_type: unsigned int

user_defined_types: struct ChildEntry { struct hash_bucket_t hash; void (*handler)(int pid, int status, void *data); int pid; void *data; }

user_defined_types: struct hash_bucket_t { struct hash_bucket_t *next; struct hash_bucket_t *prev; unsigned int hashval; }


decompiled_code:
_BOOL8 __fastcall child_compare(__int64 a1, __int64 a2)
{
return *(_DWORD *)(a1 + 32) != *(_DWORD *)(a2 + 32);
}

original_code:
static int child_compare(void *d1, void *d2)
{
    return ((struct ChildEntry *)d1)->pid != ((struct ChildEntry *)d2)->pid;
}


decompiled_code:
ssize_t __fastcall sig_handler(unsigned int a1)
{
ssize_t result; // rax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 <= 0x41 )
{
result = 16LL * (int)a1;
*(int *)((char *)&SignalHandlers + result) = 1;
if ( !PipeFull )
{
result = write(fd, buf, 1uLL);
PipeFull = 1;
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(unsigned int a1)
{
ssize_t result; // rax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 <= 0x41 )
{
result = 16LL * (int)a1;
*(int *)((char *)&SignalHandlers + result) = 1;
if ( !PipeFull )
{
result = write(fd, buf, 1uLL);
PipeFull = 1;
}
}
return result;
}

original_code:
static void
sig_handler(int sig)
{
    if (sig <0 || sig > (64 + 1)) {
 return;
    }
    SignalHandlers[sig].fired = 1;
    if (!PipeFull) {
 write(Pipe[1], &sig, 1);
 PipeFull = 1;
    }
}

variable_types: sig int


decompiled_code:
__pid_t child_handler()
{
__pid_t result; // eax
unsigned int v1; // ebx
__int64 v2; // rax
_QWORD *v3; // rbp
void (__fastcall *v4)(_QWORD, _QWORD, _QWORD); // rax
_DWORD v5[15]; // [rsp+0h] [rbp-58h] BYREF
int stat_loc[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

while ( 1 )
{
result = waitpid(-1, stat_loc, 1);
v1 = result;
if ( result <= 0 )
break;
v5[8] = result;
v2 = hash_find(&child_process_table, v5);
v3 = (_QWORD *)v2;
if ( v2 )
{
v4 = *(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(v2 + 24);
if ( v4 )
v4(v1, (unsigned int)stat_loc[0], v3[5]);
hash_remove(&child_process_table, v3);
free(v3);
}
}
return result;
}

canonical_decompiled_code:
__pid_t func4()
{
__pid_t result; // eax
unsigned int v1; // ebx
__int64 v2; // rax
_QWORD *v3; // rbp
void (__fastcall *v4)(_QWORD, _QWORD, _QWORD); // rax
_DWORD v5[15]; // [rsp+0h] [rbp-58h] BYREF
int stat_loc[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

while ( 1 )
{
result = waitpid(-1, stat_loc, 1);
v1 = result;
if ( result <= 0 )
break;
v5[8] = result;
v2 = hash_find(&child_process_table, v5);
v3 = (_QWORD *)v2;
if ( v2 )
{
v4 = *(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(v2 + 24);
if ( v4 )
v4(v1, (unsigned int)stat_loc[0], v3[5]);
hash_remove(&child_process_table, v3);
free(v3);
}
}
return result;
}

original_code:
static void
child_handler(int sig)
{
    int status;
    int pid;
    struct ChildEntry *ce;
    struct ChildEntry candidate;
    while ((pid = waitpid(-1, &status, 1)) > 0) {
 candidate.pid = (pid_t) pid;
 ce = hash_find(&child_process_table, &candidate);
 if (ce) {
     if (ce->handler) {
  ce->handler(pid, status, ce->data);
     }
     hash_remove(&child_process_table, ce);
     free(ce);
 }
    }
}

canonical_original_code:
static void child_handler(int sig)
{
    int status;
    int pid;
    struct ChildEntry *ce;
    struct ChildEntry candidate;
    while ((pid = waitpid(-1, &status, 1)) > 0) {
 candidate.pid = (int) pid;
 ce = hash_find(&child_process_table, &candidate);
 if (ce) {
     if (ce->handler) {
  ce->handler(pid, status, ce->data);
     }
     hash_remove(&child_process_table, ce);
     free(ce);
 }
    }
}

variable_types: status int

variable_types: pid int

variable_types: struct ChildEntry { struct hash_bucket_t { struct hash_bucket_t *next; struct hash_bucket_t *prev; unsigned int hashval; } hash; void (*handler)(int pid, int status, void *data); int pid; void *data; } *


decompiled_code:
__int64 __fastcall Event_HandleSignal(__int64 a1, int a2, __int64 a3)
{
struct sigaction v5; // [rsp+0h] [rbp-B8h] BYREF

if ( (int)SetupPipes(a1) < 0 )
return 0xFFFFFFFFLL;
v5.sa_handler = (__sighandler_t)sig_handler;
sigemptyset(&v5.sa_mask);
v5.sa_flags = (a2 == 17) + 0x10000000;
if ( sigaction(a2, &v5, 0LL) < 0 )
return 0xFFFFFFFFLL;
qword_528[2 * a2] = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, __int64 a3)
{
struct sigaction v5; // [rsp+0h] [rbp-B8h] BYREF

if ( (int)func3(a1) < 0 )
return 0xFFFFFFFFLL;
v5.sa_handler = (__sighandler_t)sig_handler;
sigemptyset(&v5.sa_mask);
v5.sa_flags = (a2 == 17) + 0x10000000;
if ( sigaction(a2, &v5, 0LL) < 0 )
return 0xFFFFFFFFLL;
qword_528[2 * a2] = a3;
return 0LL;
}

original_code:
int
Event_HandleSignal(EventSelector *es,
     int sig,
     void (*handler)(int sig))
{
    struct sigaction act;
    if (SetupPipes(es) < 0) return -1;
    act.__sigaction_handler.sa_handler = sig_handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    act.sa_flags |= 0x10000000;
    if (sig == 17) {
 act.sa_flags |= 1;
    }
    if (sigaction(sig, &act, ((void *)0)) < 0) return -1;
    SignalHandlers[sig].handler = handler;
    return 0;
}

canonical_original_code:
int Event_HandleSignal(struct EventSelector_t *es, int sig, void (*handler)(int sig))
{
    struct sigaction act;
    if (SetupPipes(es) < 0) return -1;
    act.__sigaction_handler.sa_handler = sig_handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    act.sa_flags |= 0x10000000;
    if (sig == 17) {
 act.sa_flags |= 1;
    }
    if (sigaction(sig, &act, ((void *)0)) < 0) return -1;
    SignalHandlers[sig].handler = handler;
    return 0;
}

variable_types: struct EventSelector_t { struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } tmout; void (*fn)(struct EventSelector_t *es, int fd, unsigned int flags, void *data); void *data; } *handlers; int nestLevel; int opsPending; int destroyPending; } *

variable_types:
handler
void (*)(int sig)

user_defined_types: struct EventSelector_t { struct EventHandler_t *handlers; int nestLevel; int opsPending; int destroyPending; }

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

user_defined_types: struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval tmout; void (*fn)(struct EventSelector_t *es, int fd, unsigned int flags, void *data); void *data; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


decompiled_code:
__int64 __fastcall Event_HandleChildExit(__int64 a1, int a2, __int64 a3, __int64 a4)
{
_DWORD *v6; // rax

if ( (int)Event_HandleSignal(a1, 17, (__int64)child_handler) < 0 )
return 0xFFFFFFFFLL;
v6 = malloc(0x30uLL);
if ( !v6 )
return 0xFFFFFFFFLL;
v6[8] = a2;
*((_QWORD *)v6 + 5) = a4;
*((_QWORD *)v6 + 3) = a3;
hash_insert(&child_process_table, v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, __int64 a3, __int64 a4)
{
_DWORD *v6; // rax

if ( (int)func5(a1, 17, (__int64)child_handler) < 0 )
return 0xFFFFFFFFLL;
v6 = malloc(0x30uLL);
if ( !v6 )
return 0xFFFFFFFFLL;
v6[8] = a2;
*((_QWORD *)v6 + 5) = a4;
*((_QWORD *)v6 + 3) = a3;
hash_insert(&child_process_table, v6);
return 0LL;
}

original_code:
int
Event_HandleChildExit(EventSelector *es,
        pid_t pid,
        void (*handler)(pid_t, int, void *),
        void *data)
{
    struct ChildEntry *ce;
    if (Event_HandleSignal(es, 17, child_handler) < 0) return -1;
    ce = malloc(sizeof(struct ChildEntry));
    if (!ce) return -1;
    ce->pid = pid;
    ce->data = data;
    ce->handler = handler;
    hash_insert(&child_process_table, ce);
    return 0;
}

canonical_original_code:
int Event_HandleChildExit(struct EventSelector_t *es, int pid, void (*handler)(int, int, void *), void *data)
{
    struct ChildEntry *ce;
    if (Event_HandleSignal(es, 17, child_handler) < 0) return -1;
    ce = malloc(sizeof(struct ChildEntry));
    if (!ce) return -1;
    ce->pid = pid;
    ce->data = data;
    ce->handler = handler;
    hash_insert(&child_process_table, ce);
    return 0;
}

variable_types:
handler
void (*)(int, int, void *)

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


decompiled_code:
__int64 __fastcall hash_next_cursor(__int64 a1, __int64 *a2)
{
__int64 v2; // rdx
__int64 v4; // rax

if ( !a2 )
return 0LL;
v2 = *a2;
if ( !*a2 )
{
LODWORD(v4) = *((_DWORD *)a2 + 4) % 0x43u + 1;
if ( (unsigned int)v4 <= 0x42 )
{
v4 = (unsigned int)v4;
do
{
v2 = *(_QWORD *)(a1 + 8 * v4);
if ( v2 )
break;
++v4;
}
while ( (unsigned int)v4 <= 0x42 );
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 *a2)
{
__int64 v2; // rdx
__int64 v4; // rax

if ( !a2 )
return 0LL;
v2 = *a2;
if ( !*a2 )
{
LODWORD(v4) = *((_DWORD *)a2 + 4) % 0x43u + 1;
if ( (unsigned int)v4 <= 0x42 )
{
v4 = (unsigned int)v4;
do
{
v2 = *(_QWORD *)(a1 + 8 * v4);
if ( v2 )
break;
++v4;
}
while ( (unsigned int)v4 <= 0x42 );
}
}
return v2;
}

original_code:
static void *
hash_next_cursor(hash_table *tab, hash_bucket *b)
{
    unsigned int i;
    if (!b) return ((void *)0);
    if (b->next) return b->next;
    i = b->hashval % 67;
    for (++i; i<67; ++i) {
 if (tab->buckets[i]) return tab->buckets[i];
    }
    return ((void *)0);
}

canonical_original_code:
static void *hash_next_cursor(struct hash_table_t *tab, struct hash_bucket_t *b)
{
    unsigned int i;
    if (!b) return ((void *)0);
    if (b->next) return b->next;
    i = b->hashval % 67;
    for (++i; i<67; ++i) {
 if (tab->buckets[i]) return tab->buckets[i];
    }
    return ((void *)0);
}

variable_types: struct hash_table_t { struct hash_bucket_t { struct hash_bucket_t *next; struct hash_bucket_t *prev; unsigned int hashval; } *buckets[67]; unsigned long hash_offset; unsigned int (*compute_hash)(void *data); int (*compare)(void *item1, void *item2); unsigned long num_entries; } *

variable_types:
b
struct hash_bucket_t *

variable_types:
i
unsigned int

return_type: void *

user_defined_types: struct hash_table_t { struct hash_bucket_t *buckets[67]; unsigned long hash_offset; unsigned int (*compute_hash)(void *data); int (*compare)(void *item1, void *item2); unsigned long num_entries; }


decompiled_code:
__int64 __fastcall hash_insert(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax
__int64 v4; // rdx

v2 = *(_QWORD *)(a1 + 536) + a2;
LODWORD(result) = (*(__int64 (__fastcall **)(__int64))(a1 + 544))(a2);
*(_DWORD *)(v2 + 16) = result;
LODWORD(result) = (unsigned int)result % 0x43;
*(_QWORD *)(v2 + 8) = 0LL;
v4 = *(_QWORD *)(a1 + 8LL * (unsigned int)result);
*(_QWORD *)v2 = v4;
if ( v4 )
*(_QWORD *)(v4 + 8) = v2;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8LL * (unsigned int)result) = v2;
++*(_QWORD *)(a1 + 560);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax
__int64 v4; // rdx

v2 = *(_QWORD *)(a1 + 536) + a2;
LODWORD(result) = (*(__int64 (__fastcall **)(__int64))(a1 + 544))(a2);
*(_DWORD *)(v2 + 16) = result;
LODWORD(result) = (unsigned int)result % 0x43;
*(_QWORD *)(v2 + 8) = 0LL;
v4 = *(_QWORD *)(a1 + 8LL * (unsigned int)result);
*(_QWORD *)v2 = v4;
if ( v4 )
*(_QWORD *)(v4 + 8) = v2;
result = (unsigned int)result;
*(_QWORD *)(a1 + 8LL * (unsigned int)result) = v2;
++*(_QWORD *)(a1 + 560);
return result;
}

original_code:
void
hash_insert(hash_table *tab,
     void *item)
{
    hash_bucket *b = ((hash_bucket *) ((char *) (item) + (tab)->hash_offset));
    unsigned int val = tab->compute_hash(item);
    b->hashval = val;
    val %= 67;
    b->prev = ((void *)0);
    b->next = tab->buckets[val];
    if (b->next) {
 b->next->prev = b;
    }
    tab->buckets[val] = b;
    tab->num_entries++;
}

canonical_original_code:
void hash_insert(struct hash_table_t *tab, void *item)
{
    struct hash_bucket_t *b = ((hash_bucket *) ((char *) (item) + (tab)->hash_offset));
    unsigned int val = tab->compute_hash(item);
    b->hashval = val;
    val %= 67;
    b->prev = ((void *)0);
    b->next = tab->buckets[val];
    if (b->next) {
 b->next->prev = b;
    }
    tab->buckets[val] = b;
    tab->num_entries++;
}

variable_types:
item
void *

variable_types: struct hash_bucket_t { struct hash_bucket_t *next; struct hash_bucket_t *prev; unsigned int hashval; } *

variable_types:
val
unsigned int


original_code:
void
hash_remove(hash_table *tab,
     void *item)
{
    hash_bucket *b = ((hash_bucket *) ((char *) (item) + (tab)->hash_offset));
    unsigned int val = b->hashval % 67;
    if (b->prev) {
 b->prev->next = b->next;
    } else {
 tab->buckets[val] = b->next;
    }
    if (b->next) {
 b->next->prev = b->prev;
    }
    tab->num_entries--;
}

canonical_original_code:
void hash_remove(struct hash_table_t *tab, void *item)
{
    struct hash_bucket_t *b = ((hash_bucket *) ((char *) (item) + (tab)->hash_offset));
    unsigned int val = b->hashval % 67;
    if (b->prev) {
 b->prev->next = b->next;
    } else {
 tab->buckets[val] = b->next;
    }
    if (b->next) {
 b->next->prev = b->prev;
    }
    tab->num_entries--;
}


decompiled_code:
char *__fastcall hash_find(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
char *v3; // r12

v2 = *(_QWORD **)(a1 + 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 544))(a2) % 0x43));
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = (char *)v2 - *(_QWORD *)(a1 + 536);
if ( !(*(unsigned int (__fastcall **)(__int64, char *))(a1 + 552))(a2, v3) )
break;
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
void *
hash_find(hash_table *tab,
   void *item)
{
    unsigned int val = tab->compute_hash(item) % 67;
    hash_bucket *b;
    for (b = tab->buckets[val]; b; b = b->next) {
 void *item2 = ((void *) (((char *) (void *) b) - (tab)->hash_offset));
 if (!tab->compare(item, item2)) return item2;
    }
    return ((void *)0);
}

canonical_original_code:
void *hash_find(struct hash_table_t *tab, void *item)
{
    unsigned int val = tab->compute_hash(item) % 67;
    struct hash_bucket_t *b;
    for (b = tab->buckets[val]; b; b = b->next) {
 void *item2 = ((void *) (((char *) (void *) b) - (tab)->hash_offset));
 if (!tab->compare(item, item2)) return item2;
    }
    return ((void *)0);
}


decompiled_code:
char *__fastcall hash_find_next(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
char *v3; // r12

v2 = *(_QWORD **)(*(_QWORD *)(a1 + 536) + a2);
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = (char *)v2 - *(_QWORD *)(a1 + 536);
if ( !(*(unsigned int (__fastcall **)(__int64, char *))(a1 + 552))(a2, v3) )
break;
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
char *v3; // r12

v2 = *(_QWORD **)(*(_QWORD *)(a1 + 536) + a2);
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = (char *)v2 - *(_QWORD *)(a1 + 536);
if ( !(*(unsigned int (__fastcall **)(__int64, char *))(a1 + 552))(a2, v3) )
break;
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
void *
hash_find_next(hash_table *tab,
        void *item)
{
    hash_bucket *b = ((hash_bucket *) ((char *) (item) + (tab)->hash_offset));
    for (b = b->next; b; b = b->next) {
 void *item2 = ((void *) (((char *) (void *) b) - (tab)->hash_offset));
 if (!tab->compare(item, item2)) return item2;
    }
    return ((void *)0);
}

canonical_original_code:
void *hash_find_next(struct hash_table_t *tab, void *item)
{
    struct hash_bucket_t *b = ((hash_bucket *) ((char *) (item) + (tab)->hash_offset));
    for (b = b->next; b; b = b->next) {
 void *item2 = ((void *) (((char *) (void *) b) - (tab)->hash_offset));
 if (!tab->compare(item, item2)) return item2;
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall hash_num_entries(__int64 a1)
{
return *(_QWORD *)(a1 + 560);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 560);
}

original_code:
size_t
hash_num_entries(hash_table *tab)
{
    return tab->num_entries;
}

canonical_original_code:
unsigned long hash_num_entries(struct hash_table_t *tab)
{
    return tab->num_entries;
}