decompiled_code:
__int64 __fastcall sysfs_write_variable(char *file, void *buf)
{
int v2; // eax
int v3; // er12
_BYTE v5[4168]; // [rsp-1048h] [rbp-1048h] BYREF

if ( !buf )
return 0x8000000000000002LL;
memset(v5, 0, 0x1028uLL);
v2 = open64(file, 1, v5);
v3 = v2;
if ( v2 != -1 )
{
if ( write(v2, buf, 0x824uLL) == 2084 )
{
close(v3);
return 0LL;
}
close(v3);
}
return 0x8000000000000002LL;
}

original_code:
static efi_status_t
sysfs_write_variable(const char *filename, efi_variable_t *var)
{
 int fd;
 size_t writesize;
 char buffer[4096 +40];
 if (!filename || !var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 memset(buffer, 0, sizeof(buffer));
 fd = open(filename, 01);
 if (fd == -1) {
  return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 writesize = write(fd, var, sizeof(*var));
 if (writesize != sizeof(*var)) {
  close(fd);
  return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 close(fd);
 return 0;
}

canonical_original_code:
static unsigned long sysfs_write_variable(char *filename, struct _efi_variable_t *var)
{
 int fd;
 unsigned long writesize;
 char buffer[-1];
 if (!filename || !var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 memset(buffer, 0, sizeof(buffer));
 fd = open(filename, 01);
 if (fd == -1) {
  return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 writesize = write(fd, var, sizeof(*var));
 if (writesize != sizeof(*var)) {
  close(fd);
  return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 close(fd);
 return 0;
}

variable_types:
filename
char *

variable_types: struct _efi_variable_t { unsigned short VariableName[-1]; struct efi_guid_t { unsigned char b[16]; } VendorGuid; unsigned long DataSize; unsigned char Data[1024]; unsigned long Status; unsigned int Attributes; } *

variable_types:
writesize
unsigned long

variable_types:
buffer
char [-1]


repo: crass/uefivars

decompiled_code:
__int64 __fastcall sysfs_delete_variable(void *buf)
{
char v2[4104]; // [rsp-1008h] [rbp-1008h] BYREF

if ( !buf )
return 0x8000000000000002LL;
snprintf(v2, 0xFFFuLL, "%s/%s", "/sys/firmware/efi/vars", "del_var");
return sysfs_write_variable(v2, buf);
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf)
{
char v2[4104]; // [rsp-1008h] [rbp-1008h] BYREF

if ( !buf )
return 0x8000000000000002LL;
snprintf(v2, 0xFFFuLL, "%s/%s", "/sys/firmware/efi/vars", "del_var");
return func0(v2, buf);
}

original_code:
static efi_status_t
sysfs_delete_variable(efi_variable_t *var)
{
 char filename[4096];
 if (!var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 snprintf(filename, 4096 -1, "%s/%s", "/sys/firmware/efi/vars","del_var");
 return sysfs_write_variable(filename, var);
}

canonical_original_code:
static unsigned long sysfs_delete_variable(struct _efi_variable_t *var)
{
 char filename[4096];
 if (!var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 snprintf(filename, 4096 -1, "%s/%s", "/sys/firmware/efi/vars","del_var");
 return sysfs_write_variable(filename, var);
}

variable_types:
filename
char [4096]

return_type: unsigned long

user_defined_types: struct _efi_variable_t { unsigned short VariableName[-1]; struct efi_guid_t VendorGuid; unsigned long DataSize; unsigned char Data[1024]; unsigned long Status; unsigned int Attributes; }

user_defined_types: struct efi_guid_t { unsigned char b[16]; }


decompiled_code:
__int64 __fastcall sysfs_create_variable(void *buf)
{
char v2[4104]; // [rsp-1008h] [rbp-1008h] BYREF

if ( !buf )
return 0x8000000000000002LL;
snprintf(v2, 0xFFFuLL, "%s/%s", "/sys/firmware/efi/vars", "new_var");
return sysfs_write_variable(v2, buf);
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf)
{
char v2[4104]; // [rsp-1008h] [rbp-1008h] BYREF

if ( !buf )
return 0x8000000000000002LL;
snprintf(v2, 0xFFFuLL, "%s/%s", "/sys/firmware/efi/vars", "new_var");
return func0(v2, buf);
}

original_code:
static efi_status_t
sysfs_create_variable(efi_variable_t *var)
{
 char filename[4096];
 if (!var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 snprintf(filename, 4096 -1, "%s/%s", "/sys/firmware/efi/vars","new_var");
 return sysfs_write_variable(filename, var);
}

canonical_original_code:
static unsigned long sysfs_create_variable(struct _efi_variable_t *var)
{
 char filename[4096];
 if (!var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 snprintf(filename, 4096 -1, "%s/%s", "/sys/firmware/efi/vars","new_var");
 return sysfs_write_variable(filename, var);
}


decompiled_code:
__int64 __fastcall sysfs_edit_variable(const char *a1, void *a2)
{
char v3[4104]; // [rsp-1008h] [rbp-1008h] BYREF

if ( !a2 )
return 0x8000000000000002LL;
snprintf(v3, 0xFFFuLL, "%s/%s/raw_var", "/sys/firmware/efi/vars", a1);
return sysfs_write_variable(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, void *a2)
{
char v3[4104]; // [rsp-1008h] [rbp-1008h] BYREF

if ( !a2 )
return 0x8000000000000002LL;
snprintf(v3, 0xFFFuLL, "%s/%s/raw_var", "/sys/firmware/efi/vars", a1);
return func0(v3, a2);
}

original_code:
static efi_status_t
sysfs_edit_variable(const char *name, efi_variable_t *var)
{
 char filename[4096];
 if (!var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 snprintf(filename, 4096 -1, "%s/%s/raw_var", "/sys/firmware/efi/vars",name);
 return sysfs_write_variable(filename, var);
}

canonical_original_code:
static unsigned long sysfs_edit_variable(char *name, struct _efi_variable_t *var)
{
 char filename[4096];
 if (!var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 snprintf(filename, 4096 -1, "%s/%s/raw_var", "/sys/firmware/efi/vars",name);
 return sysfs_write_variable(filename, var);
}

variable_types:
name
char *


decompiled_code:
unsigned __int64 __fastcall sysfs_read_variable(__int64 a1, _QWORD *a2)
{
unsigned __int64 result; // rax
int v3; // ebp
char v4[4096]; // [rsp-1000h] [rbp-2048h] BYREF
char v5[4136]; // [rsp+0h] [rbp-1048h] BYREF

if ( !a1 )
return 0x8000000000000002LL;
result = 0x8000000000000002LL;
if ( a2 )
{
memset(v5, 0, sizeof(v5));
snprintf(v4, 0xFFFuLL, "%s/%s/raw_var", "/sys/firmware/efi/vars", a1);
v3 = open64(v4, 0);
result = 0x800000000000000ELL;
if ( v3 != -1 )
{
if ( read(v3, a2, 0x824uLL) == 2084 )
{
close(v3);
result = a2[259];
}
else
{
close(v3);
result = 0x8000000000000002LL;
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, _QWORD *a2)
{
unsigned __int64 result; // rax
int v3; // ebp
char v4[4096]; // [rsp-1000h] [rbp-2048h] BYREF
char v5[4136]; // [rsp+0h] [rbp-1048h] BYREF

if ( !a1 )
return 0x8000000000000002LL;
result = 0x8000000000000002LL;
if ( a2 )
{
memset(v5, 0, sizeof(v5));
snprintf(v4, 0xFFFuLL, "%s/%s/raw_var", "/sys/firmware/efi/vars", a1);
v3 = open64(v4, 0);
result = 0x800000000000000ELL;
if ( v3 != -1 )
{
if ( read(v3, a2, 0x824uLL) == 2084 )
{
close(v3);
result = a2[259];
}
else
{
close(v3);
result = 0x8000000000000002LL;
}
}
}
return result;
}

original_code:
static efi_status_t
sysfs_read_variable(const char *name, efi_variable_t *var)
{
 char filename[4096];
 int fd;
 size_t readsize;
 char buffer[4096 +40];
 if (!name || !var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 memset(buffer, 0, sizeof(buffer));
 snprintf(filename, 4096 -1, "%s/%s/raw_var", "/sys/firmware/efi/vars",name);
 fd = open(filename, 00);
 if (fd == -1) {
  return ((14) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 readsize = read(fd, var, sizeof(*var));
 if (readsize != sizeof(*var)) {
  close(fd);
  return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 close(fd);
 return var->Status;
}

canonical_original_code:
static unsigned long sysfs_read_variable(char *name, struct _efi_variable_t *var)
{
 char filename[4096];
 int fd;
 unsigned long readsize;
 char buffer[-1];
 if (!name || !var) return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 memset(buffer, 0, sizeof(buffer));
 snprintf(filename, 4096 -1, "%s/%s/raw_var", "/sys/firmware/efi/vars",name);
 fd = open(filename, 00);
 if (fd == -1) {
  return ((14) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 readsize = read(fd, var, sizeof(*var));
 if (readsize != sizeof(*var)) {
  close(fd);
  return ((2) | (1L << ((sizeof(unsigned long) * 8) - 1)));
 }
 close(fd);
 return var->Status;
}

variable_types: fd int

variable_types:
readsize
unsigned long


decompiled_code:
__int64 __fastcall idlun_to_components(_DWORD *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4, _BYTE *a5)
{
if ( !a1 || !a2 || a4 == 0LL || a3 == 0LL || !a5 )
return 1LL;
*a2 = HIBYTE(*a1);
*a3 = BYTE2(*a1);
*a4 = *a1;
*a5 = BYTE1(*a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4, _BYTE *a5)
{
if ( !a1 || !a2 || a4 == 0LL || a3 == 0LL || !a5 )
return 1LL;
*a2 = HIBYTE(*a1);
*a3 = BYTE2(*a1);
*a4 = *a1;
*a5 = BYTE1(*a1);
return 0LL;
}

original_code:
int
idlun_to_components (Scsi_Idlun *idlun,
       unsigned char *host,
       unsigned char *channel,
       unsigned char *id,
       unsigned char *lun)
{
 if (!idlun || !host || !channel || !id || !lun) return 1;
 *host = (idlun->dev_id >> 24) & 0xFF;
 *channel = (idlun->dev_id >> 16) & 0xFF;
 *id = (idlun->dev_id ) & 0xFF;
 *lun = (idlun->dev_id >> 8) & 0xFF;
 return 0;
}

canonical_original_code:
int idlun_to_components(struct scsi_idlun *idlun, unsigned char *host, unsigned char *channel, unsigned char *id, unsigned char *lun)
{
 if (!idlun || !host || !channel || !id || !lun) return 1;
 *host = (idlun->dev_id >> 24) & 0xFF;
 *channel = (idlun->dev_id >> 16) & 0xFF;
 *id = (idlun->dev_id ) & 0xFF;
 *lun = (idlun->dev_id >> 8) & 0xFF;
 return 0;
}

variable_types: struct scsi_idlun { unsigned int dev_id; unsigned int host_unique_id; } *

variable_types:
host
unsigned char *

variable_types:
channel
unsigned char *

variable_types:
id
unsigned char *

variable_types:
lun
unsigned char *

return_type: int


repo: crawford/SRCES

decompiled_code:
// attributes: thunk
void free_hiwi_pkt_ptr(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void free_hiwi_pkt_ptr(hiwi_pkt_ptr pkt) {
    free(pkt);
}

canonical_original_code:
void free_hiwi_pkt_ptr(struct hiwi_pkt_s *pkt) {
    free(pkt);
}

variable_types: struct hiwi_pkt_s { unsigned char start; unsigned char headers; unsigned char size; unsigned char data; unsigned char stop; } *

return_type: void


decompiled_code:
__int64 query_lock_state()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = init_pkt((__int64)v0);
*(_BYTE *)(result + 1) |= 0x20u;
*(_WORD *)(result + 2) = 0;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = func1((__int64)v0);
*(_BYTE *)(result + 1) |= 0x20u;
*(_WORD *)(result + 2) = 0;
return result;
}

original_code:
hiwi_pkt_ptr query_lock_state() {
    hiwi_pkt_ptr pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x00;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}

canonical_original_code:
struct hiwi_pkt_s *query_lock_state() {
    struct hiwi_pkt_s *pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x00;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}

return_type: struct hiwi_pkt_s { unsigned char start; unsigned char headers; unsigned char size; unsigned char data; unsigned char stop; } *


decompiled_code:
__int64 query_priv_state()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = init_pkt((__int64)v0);
*(_BYTE *)(result + 1) |= 0x21u;
*(_WORD *)(result + 2) = 0;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = func1((__int64)v0);
*(_BYTE *)(result + 1) |= 0x21u;
*(_WORD *)(result + 2) = 0;
return result;
}

original_code:
hiwi_pkt_ptr query_priv_state() {
    hiwi_pkt_ptr pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x01;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}

canonical_original_code:
struct hiwi_pkt_s *query_priv_state() {
    struct hiwi_pkt_s *pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x01;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}

user_defined_types: struct hiwi_pkt_s { unsigned char start; unsigned char headers; unsigned char size; unsigned char data; unsigned char stop; }


decompiled_code:
__int64 query_1wire_state()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = init_pkt((__int64)v0);
*(_BYTE *)(result + 1) |= 0x22u;
*(_WORD *)(result + 2) = 0;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = func1((__int64)v0);
*(_BYTE *)(result + 1) |= 0x22u;
*(_WORD *)(result + 2) = 0;
return result;
}

original_code:
hiwi_pkt_ptr query_1wire_state() {
    hiwi_pkt_ptr pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x02;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}

canonical_original_code:
struct hiwi_pkt_s *query_1wire_state() {
    struct hiwi_pkt_s *pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x02;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}


decompiled_code:
__int64 query_failed_logins()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = init_pkt((__int64)v0);
*(_BYTE *)(result + 1) |= 0x23u;
*(_WORD *)(result + 2) = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(5uLL);
result = func1((__int64)v0);
*(_BYTE *)(result + 1) |= 0x23u;
*(_WORD *)(result + 2) = 0;
return result;
}

original_code:
hiwi_pkt_ptr query_failed_logins() {
    hiwi_pkt_ptr pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x03;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}

canonical_original_code:
struct hiwi_pkt_s *query_failed_logins() {
    struct hiwi_pkt_s *pkt;
    pkt = malloc(5);
    pkt = init_pkt(pkt);
    pkt->headers |= 0x03;
    pkt->headers |= 0x20;
    pkt->size = 0;
    pkt->data = 0;
    return pkt;
}


decompiled_code:
__int64 __fastcall get_opcode(__int64 a1)
{
return *(_BYTE *)(a1 + 1) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_BYTE *)(a1 + 1) & 1;
}

original_code:
char get_opcode(hiwi_pkt_ptr pkt) {
    char headers = pkt->headers;
    headers &= 0x01;
    return headers;
}

canonical_original_code:
char get_opcode(struct hiwi_pkt_s *pkt) {
    char headers = pkt->headers;
    headers &= 0x01;
    return headers;
}

variable_types: headers char

return_type: char


decompiled_code:
char __fastcall get_message_type(__int64 a1)
{
return *(char *)(a1 + 1) >> 4;
}

canonical_decompiled_code:
char __fastcall func7(__int64 a1)
{
return *(char *)(a1 + 1) >> 4;
}

original_code:
char get_message_type(hiwi_pkt_ptr pkt) {
    char headers = pkt->headers;
    headers >>= 4;
    return headers;
}

canonical_original_code:
char get_message_type(struct hiwi_pkt_s *pkt) {
    char headers = pkt->headers;
    headers >>= 4;
    return headers;
}


decompiled_code:
__int64 __fastcall get_data(__int64 a1, _DWORD *a2)
{
__int64 result; // rax

if ( *(_BYTE *)(a1 + 2) )
{
result = 0LL;
*a2 = *(unsigned __int8 *)(a1 + 3);
}
else
{
result = 1LL;
*a2 = 255;
}
return result;
}

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

if ( *(_BYTE *)(a1 + 2) )
{
result = 0LL;
*a2 = *(unsigned __int8 *)(a1 + 3);
}
else
{
result = 1LL;
*a2 = 255;
}
return result;
}

original_code:
int get_data(hiwi_pkt_ptr pkt, int* data) {
    if (pkt->size == 0) {
        *data = 255;
        return 1;
    } else {
        *data = pkt->data;
        return 0;
    }
}

canonical_original_code:
int get_data(struct hiwi_pkt_s *pkt, int *data) {
    if (pkt->size == 0) {
        *data = 255;
        return 1;
    } else {
        *data = pkt->data;
        return 0;
    }
}

variable_types:
data
int *


decompiled_code:
__int64 __fastcall get_size(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 2);
}

original_code:
char get_size(hiwi_pkt_ptr pkt) {
    return pkt->size;
}

canonical_original_code:
char get_size(struct hiwi_pkt_s *pkt) {
    return pkt->size;
}


main

canonical_name: main

repo: crjohns/blogexamples

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(&th, 0LL, like_test, 0LL);
pthread_create(newthread, 0LL, like_test, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
printf("Post was liked %d times\n", (unsigned int)likes);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    pthread_t t1;
    pthread_t t2;
    pthread_create(&t1, ((void *)0), like_test, ((void *)0));
    pthread_create(&t2, ((void *)0), like_test, ((void *)0));
    pthread_join(t1, ((void *)0));
    pthread_join(t2, ((void *)0));
    printf("Post was liked %d times\n", likes);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long t1;
    unsigned long t2;
    pthread_create(&t1, ((void *)0), like_test, ((void *)0));
    pthread_create(&t2, ((void *)0), like_test, ((void *)0));
    pthread_join(t1, ((void *)0));
    pthread_join(t2, ((void *)0));
    printf("Post was liked %d times\n", likes);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void *__fastcall like_test(void *a1)
{
int v1; // ebx

v1 = 10000;
do
{
like_post();
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebx

v1 = 10000;
do
{
func7();
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *like_test(void *arg)
{
    for(int i=0; i<10000; i++)
        like_post();
    return ((void *)0);
}

canonical_original_code:
void *like_test(void *arg)
{
    for(int i = 0; i<10000; i++)
        like_post();
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: i int

return_type: void *


repo: crossplatformdev/Sudoku

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct _IO_FILE *v3; // rdi
__int64 v4; // r8
__int64 v5; // r9
__int64 v6; // rdx
__int64 v7; // rcx
int v8; // eax
unsigned int v9; // eax
__int64 v10; // rdx
__int64 v11; // rcx
__int64 v12; // r8
__int64 v13; // r9
unsigned int v14; // eax
_QWORD v16[2]; // [rsp+0h] [rbp-88h] BYREF
__int64 v17; // [rsp+10h] [rbp-78h] BYREF
__int64 v18; // [rsp+18h] [rbp-70h] BYREF
__int64 v19; // [rsp+20h] [rbp-68h]
_QWORD v20[2]; // [rsp+28h] [rbp-60h] BYREF
__int64 v21; // [rsp+38h] [rbp-50h] BYREF
__int64 v22; // [rsp+40h] [rbp-48h] BYREF
_QWORD v23[3]; // [rsp+50h] [rbp-38h] BYREF
__int128 v24; // [rsp+68h] [rbp-20h]

v3 = (struct _IO_FILE *)&unk_2E;
v4 = 46LL;
v5 = 46LL;
v6 = 46LL;
v7 = 46LL;
*(_OWORD *)&v23[1] = 0LL;
strcpy((char *)v16, ".........");
strcpy((char *)&v16[1] + 2, ".........");
strcpy((char *)&v17 + 4, ".........");
strcpy((char *)&v18 + 6, ".........");
strcpy((char *)v20, ".........");
strcpy((char *)&v20[1] + 2, ".........");
strcpy((char *)&v21 + 4, ".........");
strcpy((char *)&v22 + 6, ".........");
strcpy((char *)v23, ".........");
v24 = 0LL;
LABEL_2:
while ( 1 )
{
v8 = Seleccion(v3, 46LL, v6, v7, v4, v5, v16[0], v16[1], v17, v18, v19, v20[0], v20[1], v21, v22);
if ( v8 != 50 )
break;
LABEL_11:
LeerPartidasGuardadas(v16);
if ( (unsigned int)CargarPartida(v16) + 1 <= 1 )
return 0;
while ( 1 )
{
v3 = (struct _IO_FILE *)v16;
v14 = Jugar(v16);
if ( v14 >= 0xFFFFFFFE )
break;
while ( v14 != 1 )
{
if ( SHIDWORD(v24) <= 0 )
goto LABEL_2;
v3 = (struct _IO_FILE *)v16;
v14 = Jugar(v16);
if ( v14 >= 0xFFFFFFFE )
goto LABEL_16;
}
}
LABEL_16:
puts("Asi ha quedado el tablero:");
v3 = (struct _IO_FILE *)v16;
DibujarTablero(v16);
getchar();
}
while ( v8 != 51 )
{
if ( v8 != 49 )
goto LABEL_2;
if ( (unsigned int)EmpezarPartida(v16) + 1 <= 1 )
return 0;
while ( 1 )
{
v3 = (struct _IO_FILE *)v16;
v9 = Jugar(v16);
if ( v9 >= 0xFFFFFFFE )
break;
while ( v9 != 1 )
{
v6 = HIDWORD(v24);
if ( SHIDWORD(v24) <= 0 )
goto LABEL_2;
v3 = (struct _IO_FILE *)v16;
v9 = Jugar(v16);
if ( v9 >= 0xFFFFFFFE )
goto LABEL_10;
}
}
LABEL_10:
puts("Asi ha quedado el tablero:");
DibujarTablero(v16);
v3 = stdin;
fflush(stdin);
getchar();
v8 = Seleccion(v3, 46LL, v10, v11, v12, v13, v16[0], v16[1], v17, v18, v19, v20[0], v20[1], v21, v22);
if ( v8 == 50 )
goto LABEL_11;
}
puts("\nHASTA PRONTO!!!!!\n");
getchar();
return 0;
}

variable_types: error int

variable_types: seleccion int

variable_types: struct sudoku { char panel[-1][-1]; char partida[-1]; int espacios; }


repo: crotsos/hwdb-opendpi

decompiled_code:
void debug_printf()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void
debug_printf(unsigned int protocol, void *id_struct, ipq_log_level_t log_level,
    const char *format, ...) {
}

canonical_original_code:
static void debug_printf(unsigned int protocol, void *id_struct, enum ipq_log_level_t log_level, char *format, ...) {
}

variable_types:
protocol
unsigned int

variable_types: enum ipq_log_level_t { IPQ_LOG_ERROR=0, IPQ_LOG_TRACE=1, IPQ_LOG_DEBUG=2 }

variable_types:
format
char *


decompiled_code:
// attributes: thunk
void *malloc_wrapper(size_t size)
{
return malloc(size);
}

canonical_decompiled_code:
void *func2(size_t size)
{
return malloc(size);
}

original_code:
static void
*malloc_wrapper(unsigned long size) {
  return malloc(size);
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall extract_headers(_QWORD *a1, __int64 a2, int a3)
{
int v3; // edx
_QWORD *v4; // rcx
int v5; // eax
int v6; // edi
char v7; // r8
__int64 result; // rax

if ( a3 <= 13 )
return 0LL;
*a1 = a2;
if ( _bswap_16(*(_WORD *)(a2 + 12)) != 2048 )
return 0LL;
if ( v3 <= 33 )
return 0LL;
v4[1] = a2 + 14;
v5 = 4 * (*(_BYTE *)(a2 + 14) & 0xF);
v6 = v5 + 14;
if ( v5 + 14 > v3 )
return 0LL;
v7 = *(_BYTE *)(a2 + 23);
if ( v7 != 6 )
{
if ( v7 == 17 && v3 >= (unsigned __int64)(v5 + 22) )
{
result = 1LL;
v4[2] = v6 + a2;
return result;
}
return 0LL;
}
if ( v3 < (unsigned __int64)(v5 + 34) )
return 0LL;
result = 1LL;
v4[3] = v6 + a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, int a3)
{
int v3; // edx
_QWORD *v4; // rcx
int v5; // eax
int v6; // edi
char v7; // r8
__int64 result; // rax

if ( a3 <= 13 )
return 0LL;
*a1 = a2;
if ( func1(*(_WORD *)(a2 + 12)) != 2048 )
return 0LL;
if ( v3 <= 33 )
return 0LL;
v4[1] = a2 + 14;
v5 = 4 * (*(_BYTE *)(a2 + 14) & 0xF);
v6 = v5 + 14;
if ( v5 + 14 > v3 )
return 0LL;
v7 = *(_BYTE *)(a2 + 23);
if ( v7 != 6 )
{
if ( v7 == 17 && v3 >= (unsigned __int64)(v5 + 22) )
{
result = 1LL;
v4[2] = v6 + a2;
return result;
}
return 0LL;
}
if ( v3 < (unsigned __int64)(v5 + 34) )
return 0LL;
result = 1LL;
v4[3] = v6 + a2;
return result;
}

original_code:
int
extract_headers(struct packet_header *hdr, uint8_t *data, int data_len) {
  int ptr = 0;
  if(data_len < 14) return 0;
  hdr->ether = (struct ether_header *)data;
  ptr += 14;
  if(ntohs(hdr->ether->ether_type) != 0x0800) return 0;
  if(data_len < ptr + sizeof(struct iphdr)) return 0;
  hdr->ip = (struct iphdr *)(data + ptr);
  if(data_len < ptr + (hdr->ip->ihl)*4) return 0;
  ptr += hdr->ip->ihl*4;
  if(hdr->ip->protocol == 6) {
    if(data_len < ptr + sizeof(struct tcphdr)) return 0;
    hdr->tcp = (struct tcphdr *)(data + ptr);
  } else if(hdr->ip->protocol == 17) {
    if(data_len < ptr + sizeof(struct udphdr)) return 0;
    hdr->udp = (struct udphdr *)(data + ptr);
  } else
    return 0;
  return 1;
}

canonical_original_code:
int extract_headers(struct packet_header *hdr, unsigned char *data, int data_len) {
  int ptr = 0;
  if(data_len < 14) return 0;
  hdr->ether = (struct ether_header *)data;
  ptr += 14;
  if(ntohs(hdr->ether->ether_type) != 0x0800) return 0;
  if(data_len < ptr + sizeof(struct iphdr)) return 0;
  hdr->ip = (struct iphdr *)(data + ptr);
  if(data_len < ptr + (hdr->ip->ihl)*4) return 0;
  ptr += hdr->ip->ihl*4;
  if(hdr->ip->protocol == 6) {
    if(data_len < ptr + sizeof(struct tcphdr)) return 0;
    hdr->tcp = (struct tcphdr *)(data + ptr);
  } else if(hdr->ip->protocol == 17) {
    if(data_len < ptr + sizeof(struct udphdr)) return 0;
    hdr->udp = (struct udphdr *)(data + ptr);
  } else
    return 0;
  return 1;
}

variable_types: struct packet_header { struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *ether; struct iphdr { unsigned char ihl; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *ip; struct udphdr { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; } *udp; struct tcphdr { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short window; unsigned short check; unsigned short urg_ptr; } *tcp; } *

variable_types:
data
unsigned char *

variable_types: ptr int

user_defined_types: struct packet_header { struct ether_header *ether; struct iphdr *ip; struct udphdr *udp; struct tcphdr *tcp; }


decompiled_code:
__int64 init_cfg()
{
__int64 result; // rax
const char *v1; // rax

*(_QWORD *)obj_cfg = 0x100000000LL;
strcpy(&obj_cfg[2008], "udp or tcp");
strcpy(&obj_cfg[1008], "eth0");
*(_QWORD *)&obj_cfg[3128] = 0LL;
hi_init_str((unsigned int)((_DWORD)obj_cfg + 3136), 93563LL);
result = hi_init_str((unsigned int)((_DWORD)obj_cfg + 3144), 93563LL);
if ( (_DWORD)result )
{
v1 = (const char *)hi_strerror((unsigned int)result);
printf("Failed to init flow_hasr: %s\n", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
const char *v1; // rax

*(_QWORD *)obj_cfg = 0x100000000LL;
strcpy(&obj_cfg[2008], "udp or tcp");
strcpy(&obj_cfg[1008], "eth0");
*(_QWORD *)&obj_cfg[3128] = 0LL;
hi_init_str((unsigned int)((_DWORD)obj_cfg + 3136), 93563LL);
result = hi_init_str((unsigned int)((_DWORD)obj_cfg + 3144), 93563LL);
if ( (_DWORD)result )
{
v1 = (const char *)hi_strerror((unsigned int)result);
printf("Failed to init flow_hasr: %s\n", v1);
exit(1);
}
return result;
}

original_code:
void
init_cfg() {
  int res;
  obj_cfg.verbose = 0;
  obj_cfg.type = DEVICE_CAPTURE;
  strcpy(obj_cfg.dev_name, "eth0");
  strcpy(obj_cfg.pcap_filter, "udp or tcp");
  obj_cfg.ipoque_struct= ((void *)0);
  hi_init_str(&obj_cfg.hi_handle_ip, 93563);
  if( (res = hi_init_str(&obj_cfg.hi_handle_flows, 93563)) != 0) {
    printf("Failed to init flow_hasr: %s\n", hi_strerror(res));
    exit(1);
  }
}

variable_types: res int


decompiled_code:
unsigned int __fastcall parse_options(int argc, char **argv)
{
unsigned int result; // eax

init_cfg();
strcpy(&obj_cfg[3016], "localhost");
*(_WORD *)&obj_cfg[3116] = 987;
while ( 1 )
{
result = getopt(argc, argv, "f:r:i:v");
if ( result == -1 )
break;
switch ( result )
{
case 'f':
strcpy((char *)(unsigned int)((_DWORD)obj_cfg + 2008), optarg);
break;
case 'h':
printf("usage: %s\n", "./linklogger [-i device -f file -v]");
exit(0);
case 'i':
strcpy((char *)(unsigned int)((_DWORD)obj_cfg + 1008), optarg);
*(_DWORD *)&obj_cfg[4] = 1;
break;
case 'r':
strcpy((char *)(unsigned int)((_DWORD)obj_cfg + 8), optarg);
*(_DWORD *)&obj_cfg[4] = 0;
break;
case 'v':
*(_DWORD *)obj_cfg = 1;
break;
default:
printf("unknown param -%c. \n usage: %s\n", result, "./linklogger [-i device -f file -v]");
exit(0);
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func10(int argc, char **argv)
{
unsigned int result; // eax

func9();
strcpy(&obj_cfg[3016], "localhost");
*(_WORD *)&obj_cfg[3116] = 987;
while ( 1 )
{
result = getopt(argc, argv, "f:r:i:v");
if ( result == -1 )
break;
switch ( result )
{
case 'f':
strcpy((char *)(unsigned int)((_DWORD)obj_cfg + 2008), optarg);
break;
case 'h':
printf("usage: %s\n", "./linklogger [-i device -f file -v]");
exit(0);
case 'i':
strcpy((char *)(unsigned int)((_DWORD)obj_cfg + 1008), optarg);
*(_DWORD *)&obj_cfg[4] = 1;
break;
case 'r':
strcpy((char *)(unsigned int)((_DWORD)obj_cfg + 8), optarg);
*(_DWORD *)&obj_cfg[4] = 0;
break;
case 'v':
*(_DWORD *)obj_cfg = 1;
break;
default:
printf("unknown param -%c. \n usage: %s\n", result, "./linklogger [-i device -f file -v]");
exit(0);
}
}
return result;
}

original_code:
int
parse_options(int argc, char *argv[]) {
  int i, j, c;
  init_cfg();
  strcpy(obj_cfg.target, "localhost");
  obj_cfg.port = 987;
  while ((c = getopt (argc, argv, "f:r:i:v")) != -1) {
    switch (c) {
    case 'f':
      strcpy(obj_cfg.pcap_filter, optarg);
      break;
    case 'r':
      strcpy(obj_cfg.filename, optarg);
      obj_cfg.type = FILE_CAPTURE;
      break;
    case 'i':
      strcpy(obj_cfg.dev_name, optarg);
      obj_cfg.type = DEVICE_CAPTURE;
      break;
    case 'v':
      obj_cfg.verbose = 1;
      break;
    case 'h':
      printf("usage: %s\n", "./linklogger [-i device -f file -v]");
      exit(0);
    default:
      printf("unknown param -%c. \n usage: %s\n", c, "./linklogger [-i device -f file -v]");
      exit(0);
    }
  }
}

canonical_original_code:
int parse_options(int argc, char *argv[]) {
  int i; int j; int c;
  init_cfg();
  strcpy(obj_cfg.target, "localhost");
  obj_cfg.port = 987;
  while ((c = getopt (argc, argv, "f:r:i:v")) != -1) {
    switch (c) {
    case 'f':
      strcpy(obj_cfg.pcap_filter, optarg);
      break;
    case 'r':
      strcpy(obj_cfg.filename, optarg);
      obj_cfg.type = FILE_CAPTURE;
      break;
    case 'i':
      strcpy(obj_cfg.dev_name, optarg);
      obj_cfg.type = DEVICE_CAPTURE;
      break;
    case 'v':
      obj_cfg.verbose = 1;
      break;
    case 'h':
      printf("usage: %s\n", "./linklogger [-i device -f file -v]");
      exit(0);
    default:
      printf("unknown param -%c. \n usage: %s\n", c, "./linklogger [-i device -f file -v]");
      exit(0);
    }
  }
}

variable_types:
argv
char *[]

variable_types: j int

variable_types: c int


init

decompiled_code:
__int64 init()
{
int v0; // eax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v5; // rax
const char *v6; // rax
_BYTE v7[16]; // [rsp+0h] [rbp-128h] BYREF
__int64 v8[2]; // [rsp+10h] [rbp-118h] BYREF
char v9[264]; // [rsp+20h] [rbp-108h] BYREF

v0 = *(_DWORD *)&obj_cfg[4];
if ( v0 != 1 )
{
if ( v0 )
{
fwrite("No device or file was defined for capturing\n", 1uLL, 0x2CuLL, stderr);
exit(1);
}
if ( *(_DWORD *)obj_cfg )
printf("File is %s\n", (const char *)(unsigned int)((_DWORD)obj_cfg + 8));
v1 = pcap_open_offline((unsigned int)((_DWORD)obj_cfg + 8), v9);
*(_QWORD *)&obj_cfg[3008] = v1;
if ( v1 )
goto LABEL_6;
LABEL_17:
fprintf(stderr, "pcap_open_live(): %s\n", v9);
exit(1);
}
if ( *(_DWORD *)obj_cfg )
printf("Device is %s\n", (const char *)(unsigned int)((_DWORD)obj_cfg + 1008));
v5 = pcap_open_live((unsigned int)((_DWORD)obj_cfg + 1008), 0x2000LL, 1LL, 0xFFFFFFFFLL, v9);
*(_QWORD *)&obj_cfg[3008] = v5;
if ( !v5 )
goto LABEL_17;
LABEL_6:
if ( obj_cfg[2008] )
{
if ( (unsigned int)pcap_compile(*(_QWORD *)&obj_cfg[3008], v7, (unsigned int)((_DWORD)obj_cfg + 2008), 0LL, 0LL) == -1 )
{
v6 = (const char *)pcap_geterr(*(_QWORD *)&obj_cfg[3008]);
fprintf(stderr, "Error calling pcap_compile: $%s %s\n", (const char *)(unsigned int)((_DWORD)obj_cfg + 2008), v6);
exit(1);
}
if ( (unsigned int)pcap_setfilter(*(_QWORD *)&obj_cfg[3008], v7) == -1 )
{
fwrite("Error setting filter\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
}
if ( !(unsigned int)rpc_init(0LL) )
{
fwrite("Initialization failure for rpc system\n", 1uLL, 0x26uLL, stderr);
exit(-1);
}
v2 = rpc_connect("localhost", 987LL, "HWDB", 1LL);
*(_QWORD *)&obj_cfg[3120] = v2;
if ( !v2 )
{
fprintf(stderr, "Error connecting to HWDB at %s:%05u\n", "localhost", 987LL);
exit(-1);
}
v3 = ipoque_init_detection_module(1000LL, malloc_wrapper, debug_printf);
*(_QWORD *)&obj_cfg[3128] = v3;
if ( !v3 )
{
puts("ERROR: global structure initialization failed");
exit(-1);
}
v8[0] = -1LL;
v8[1] = -1LL;
return ipoque_set_protocol_detection_bitmask2(v3, v8);
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v5; // rax
const char *v6; // rax
_BYTE v7[16]; // [rsp+0h] [rbp-128h] BYREF
__int64 v8[2]; // [rsp+10h] [rbp-118h] BYREF
char v9[264]; // [rsp+20h] [rbp-108h] BYREF

v0 = *(_DWORD *)&obj_cfg[4];
if ( v0 != 1 )
{
if ( v0 )
{
fwrite("No device or file was defined for capturing\n", 1uLL, 0x2CuLL, stderr);
exit(1);
}
if ( *(_DWORD *)obj_cfg )
printf("File is %s\n", (const char *)(unsigned int)((_DWORD)obj_cfg + 8));
v1 = pcap_open_offline((unsigned int)((_DWORD)obj_cfg + 8), v9);
*(_QWORD *)&obj_cfg[3008] = v1;
if ( v1 )
goto LABEL_6;
LABEL_17:
fprintf(stderr, "pcap_open_live(): %s\n", v9);
exit(1);
}
if ( *(_DWORD *)obj_cfg )
printf("Device is %s\n", (const char *)(unsigned int)((_DWORD)obj_cfg + 1008));
v5 = pcap_open_live((unsigned int)((_DWORD)obj_cfg + 1008), 0x2000LL, 1LL, 0xFFFFFFFFLL, v9);
*(_QWORD *)&obj_cfg[3008] = v5;
if ( !v5 )
goto LABEL_17;
LABEL_6:
if ( obj_cfg[2008] )
{
if ( (unsigned int)pcap_compile(*(_QWORD *)&obj_cfg[3008], v7, (unsigned int)((_DWORD)obj_cfg + 2008), 0LL, 0LL) == -1 )
{
v6 = (const char *)pcap_geterr(*(_QWORD *)&obj_cfg[3008]);
fprintf(stderr, "Error calling pcap_compile: $%s %s\n", (const char *)(unsigned int)((_DWORD)obj_cfg + 2008), v6);
exit(1);
}
if ( (unsigned int)pcap_setfilter(*(_QWORD *)&obj_cfg[3008], v7) == -1 )
{
fwrite("Error setting filter\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
}
if ( !(unsigned int)rpc_init(0LL) )
{
fwrite("Initialization failure for rpc system\n", 1uLL, 0x26uLL, stderr);
exit(-1);
}
v2 = rpc_connect("localhost", 987LL, "HWDB", 1LL);
*(_QWORD *)&obj_cfg[3120] = v2;
if ( !v2 )
{
fprintf(stderr, "Error connecting to HWDB at %s:%05u\n", "localhost", 987LL);
exit(-1);
}
v3 = ipoque_init_detection_module(1000LL, malloc_wrapper, debug_printf);
*(_QWORD *)&obj_cfg[3128] = v3;
if ( !v3 )
{
puts("ERROR: global structure initialization failed");
exit(-1);
}
v8[0] = -1LL;
v8[1] = -1LL;
return ipoque_set_protocol_detection_bitmask2(v3, v8);
}

original_code:
int
init() {
  char errbuf[256];
  struct bpf_program fp;
  char *host = "localhost";
  unsigned short port = 987;
  struct ipoque_protocol_bitmask_struct all;
  uint32_t size_id_struct;
  uint32_t size_flow_struct;
  uint32_t i;
  if(obj_cfg.type == DEVICE_CAPTURE) {
    if (obj_cfg.verbose)
      printf("Device is %s\n", obj_cfg.dev_name);
    obj_cfg.pcap_dev = pcap_open_live(obj_cfg.dev_name, 8192, 1, -1, errbuf);
    if(obj_cfg.pcap_dev == ((void *)0)) {
      fprintf(stderr, "pcap_open_live(): %s\n", errbuf);
      exit(1);
    }
  } else if (obj_cfg.type == FILE_CAPTURE) {
    if (obj_cfg.verbose)
      printf("File is %s\n", obj_cfg.filename);
    obj_cfg.pcap_dev = pcap_open_offline(obj_cfg.filename, errbuf);
    if(obj_cfg.pcap_dev == ((void *)0)) {
      fprintf(stderr, "pcap_open_live(): %s\n", errbuf);
      exit(1);
    }
  } else {
      fprintf(stderr, "No device or file was defined for capturing\n");
      exit(1);
  }
  if(strlen(obj_cfg.pcap_filter) > 0) {
    if(pcap_compile(obj_cfg.pcap_dev, &fp, obj_cfg.pcap_filter, 0, 0) == -1) {
      fprintf(stderr, "Error calling pcap_compile: $%s %s\n", obj_cfg.pcap_filter, pcap_geterr(obj_cfg.pcap_dev));
      exit(1);
    }
    if(pcap_setfilter(obj_cfg.pcap_dev, &fp) == -1) {
      fprintf(stderr, "Error setting filter\n");
      exit(1);
    }
  }
  if (! rpc_init(0)) {
    fprintf(stderr, "Initialization failure for rpc system\n");
    exit(-1);
  }
  obj_cfg.rpc = rpc_connect(host, port, "HWDB", 1l);
  if (obj_cfg.rpc == ((void *)0)) {
    fprintf(stderr, "Error connecting to HWDB at %s:%05u\n",
     host, port);
    exit(-1);
  }
  obj_cfg.ipoque_struct = ipoque_init_detection_module(1000,
            malloc_wrapper, debug_printf);
  if (obj_cfg.ipoque_struct == ((void *)0)) {
    printf("ERROR: global structure initialization failed\n");
    exit(-1);
  }
  {((all).bitmask[0]) = 0xFFFFFFFFFFFFFFFFULL; ((all).bitmask[1]) = 0xFFFFFFFFFFFFFFFFULL;};
  ipoque_set_protocol_detection_bitmask2(obj_cfg.ipoque_struct, &all);
}

canonical_original_code:
int init() {
  char errbuf[256];
  struct bpf_program fp;
  char *host = "localhost";
  unsigned short port = 987;
  struct ipoque_protocol_bitmask_struct all;
  unsigned int size_id_struct;
  unsigned int size_flow_struct;
  unsigned int i;
  if(obj_cfg.type == DEVICE_CAPTURE) {
    if (obj_cfg.verbose)
      printf("Device is %s\n", obj_cfg.dev_name);
    obj_cfg.pcap_dev = pcap_open_live(obj_cfg.dev_name, 8192, 1, -1, errbuf);
    if(obj_cfg.pcap_dev == ((void *)0)) {
      fprintf(stderr, "pcap_open_live(): %s\n", errbuf);
      exit(1);
    }
  } else if (obj_cfg.type == FILE_CAPTURE) {
    if (obj_cfg.verbose)
      printf("File is %s\n", obj_cfg.filename);
    obj_cfg.pcap_dev = pcap_open_offline(obj_cfg.filename, errbuf);
    if(obj_cfg.pcap_dev == ((void *)0)) {
      fprintf(stderr, "pcap_open_live(): %s\n", errbuf);
      exit(1);
    }
  } else {
      fprintf(stderr, "No device or file was defined for capturing\n");
      exit(1);
  }
  if(strlen(obj_cfg.pcap_filter) > 0) {
    if(pcap_compile(obj_cfg.pcap_dev, &fp, obj_cfg.pcap_filter, 0, 0) == -1) {
      fprintf(stderr, "Error calling pcap_compile: $%s %s\n", obj_cfg.pcap_filter, pcap_geterr(obj_cfg.pcap_dev));
      exit(1);
    }
    if(pcap_setfilter(obj_cfg.pcap_dev, &fp) == -1) {
      fprintf(stderr, "Error setting filter\n");
      exit(1);
    }
  }
  if (! rpc_init(0)) {
    fprintf(stderr, "Initialization failure for rpc system\n");
    exit(-1);
  }
  obj_cfg.rpc = rpc_connect(host, port, "HWDB", 1l);
  if (obj_cfg.rpc == ((void *)0)) {
    fprintf(stderr, "Error connecting to HWDB at %s:%05u\n",
     host, port);
    exit(-1);
  }
  obj_cfg.ipoque_struct = ipoque_init_detection_module(1000,
            malloc_wrapper, debug_printf);
  if (obj_cfg.ipoque_struct == ((void *)0)) {
    printf("ERROR: global structure initialization failed\n");
    exit(-1);
  }
  {((all).bitmask[0]) = 0xFFFFFFFFFFFFFFFFULL; ((all).bitmask[1]) = 0xFFFFFFFFFFFFFFFFULL;};
  ipoque_set_protocol_detection_bitmask2(obj_cfg.ipoque_struct, &all);
}

variable_types:
errbuf
char [256]

variable_types: struct bpf_program { unsigned int bf_len; struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *bf_insns; }

variable_types:
host
char *

variable_types:
port
unsigned short

variable_types: struct ipoque_protocol_bitmask_struct { unsigned long long bitmask[2]; }

variable_types:
i
unsigned int

user_defined_types: struct bpf_program { unsigned int bf_len; struct bpf_insn *bf_insns; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
parse_options(argc, (char **)argv);
init();
pcap_loop(*(_QWORD *)&obj_cfg[3008], 0xFFFFFFFFLL, process_packet, 0LL);
fwrite("\nfinished\n", 1uLL, 0xAuLL, stderr);
pcap_close(*(_QWORD *)&obj_cfg[3008]);
puts("Starting hwdb-opendpi daemon...");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func10(argc, (char **)argv);
func11();
pcap_loop(*(_QWORD *)&obj_cfg[3008], 0xFFFFFFFFLL, process_packet, 0LL);
fwrite("\nfinished\n", 1uLL, 0xAuLL, stderr);
pcap_close(*(_QWORD *)&obj_cfg[3008]);
puts("Starting hwdb-opendpi daemon...");
return 0;
}

original_code:
int
main(int argc, char *argv[]) {
  char *dev;
  char errbuf[256];
  bpf_u_int32 maskp;
  bpf_u_int32 netp;
  u_char* args = ((void *)0);
  pthread_t thr;
  int i;
  char buf[100];
  parse_options(argc, argv);
  init();
  pcap_loop(obj_cfg.pcap_dev, -1, process_packet, args);
  fprintf(stderr, "\nfinished\n");
  pcap_close(obj_cfg.pcap_dev);
  printf("Starting hwdb-opendpi daemon...\n");
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  char *dev;
  char errbuf[256];
  unsigned int maskp;
  unsigned int netp;
  unsigned char *args = ((void *)0);
  unsigned long thr;
  int i;
  char buf[100];
  parse_options(argc, argv);
  init();
  pcap_loop(obj_cfg.pcap_dev, -1, process_packet, args);
  fprintf(stderr, "\nfinished\n");
  pcap_close(obj_cfg.pcap_dev);
  printf("Starting hwdb-opendpi daemon...\n");
  return 0;
}

variable_types: argc int

variable_types:
dev
char *

variable_types:
maskp
unsigned int

variable_types:
netp
unsigned int

variable_types:
args
unsigned char *

variable_types:
thr
unsigned long

variable_types: i int

variable_types:
buf
char [100]


decompiled_code:
__int64 tsl_create()
{
__int64 v0; // rax
__int64 v1; // r12

v0 = mem_alloc_location(112LL, "tslist.c", 27LL);
v1 = v0;
if ( !v0 )
return v1;
*(_QWORD *)v0 = 0LL;
*(_QWORD *)(v0 + 8) = 0LL;
*(_QWORD *)(v0 + 16) = 0LL;
if ( !pthread_mutex_init((pthread_mutex_t *)(v0 + 24), 0LL) && !pthread_cond_init((pthread_cond_t *)(v1 + 64), 0LL) )
return v1;
mem_free_location(v1, "tslist.c", 34LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // r12

v0 = mem_alloc_location(112LL, "tslist.c", 27LL);
v1 = v0;
if ( !v0 )
return v1;
*(_QWORD *)v0 = 0LL;
*(_QWORD *)(v0 + 8) = 0LL;
*(_QWORD *)(v0 + 16) = 0LL;
if ( !pthread_mutex_init((pthread_mutex_t *)(v0 + 24), 0LL) && !pthread_cond_init((pthread_cond_t *)(v1 + 64), 0LL) )
return v1;
mem_free_location(v1, "tslist.c", 34LL);
return 0LL;
}

original_code:
TSList tsl_create() {
 ListHead *lh = (ListHead *)mem_alloc_location((sizeof(ListHead)), "tslist.c", 27);
 if (lh) {
  lh->head = ((void *)0);
  lh->tail = ((void *)0);
  lh->count = 0l;
  if (pthread_mutex_init(&(lh->mutex), ((void *)0)) ||
      pthread_cond_init(&(lh->nonempty), ((void *)0))) {
   ((void)(mem_free_location((lh), "tslist.c", 34), (lh) = 0));
   lh = ((void *)0);
  }
 }
 return (TSList)lh;
}

canonical_original_code:
void *tsl_create() {
 struct listhead *lh = (ListHead *)mem_alloc_location((sizeof(ListHead)), "tslist.c", 27);
 if (lh) {
  lh->head = ((void *)0);
  lh->tail = ((void *)0);
  lh->count = 0l;
  if (pthread_mutex_init(&(lh->mutex), ((void *)0)) ||
      pthread_cond_init(&(lh->nonempty), ((void *)0))) {
   ((void)(mem_free_location((lh), "tslist.c", 34), (lh) = 0));
   lh = ((void *)0);
  }
 }
 return (void *)lh;
}

variable_types: struct listhead { struct element { struct element *next; void *addr; void *data; int size; } *head; struct element *tail; unsigned long count; 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; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } nonempty; } *

user_defined_types: struct listhead { struct element *head; struct element *tail; unsigned long count; union pthread_mutex_t mutex; union pthread_cond_t nonempty; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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:
__int64 __fastcall tsl_append(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rax

v6 = mem_alloc_location(32LL, "tslist.c", 45LL);
result = 0LL;
if ( v6 )
{
*(_DWORD *)(v6 + 24) = a4;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = a3;
*(_QWORD *)v6 = 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v8 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = v8 + 1;
if ( v8 )
**(_QWORD **)(a1 + 8) = v6;
else
*(_QWORD *)a1 = v6;
*(_QWORD *)(a1 + 8) = v6;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rax

v6 = mem_alloc_location(32LL, "tslist.c", 45LL);
result = 0LL;
if ( v6 )
{
*(_DWORD *)(v6 + 24) = a4;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = a3;
*(_QWORD *)v6 = 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v8 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = v8 + 1;
if ( v8 )
**(_QWORD **)(a1 + 8) = v6;
else
*(_QWORD *)a1 = v6;
*(_QWORD *)(a1 + 8) = v6;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
result = 1LL;
}
return result;
}

original_code:
int tsl_append(TSList tsl, void *a, void *b, int size) {
 ListHead *lh = (ListHead *)tsl;
 Element *e = (Element *)mem_alloc_location((sizeof(Element)), "tslist.c", 45);
 if (!e)
  return 0;
 e->addr = a;
 e->data = b;
 e->size = size;
 e->next = ((void *)0);
 pthread_mutex_lock(&(lh->mutex));
 if (! lh->count++)
  lh->head = e;
 else
  lh->tail->next = e;
 lh->tail = e;
 pthread_cond_signal(&(lh->nonempty));
 pthread_mutex_unlock(&(lh->mutex));
 return 1;
}

canonical_original_code:
int tsl_append(void *tsl, void *a, void *b, int size) {
 struct listhead *lh = (ListHead *)tsl;
 struct element *e = (Element *)mem_alloc_location((sizeof(Element)), "tslist.c", 45);
 if (!e)
  return 0;
 e->addr = a;
 e->data = b;
 e->size = size;
 e->next = ((void *)0);
 pthread_mutex_lock(&(lh->mutex));
 if (! lh->count++)
  lh->head = e;
 else
  lh->tail->next = e;
 lh->tail = e;
 pthread_cond_signal(&(lh->nonempty));
 pthread_mutex_unlock(&(lh->mutex));
 return 1;
}

variable_types:
tsl
void *

variable_types:
a
void *

variable_types:
b
void *

variable_types: size int

variable_types: struct element { struct element *next; void *addr; void *data; int size; } *

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

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


decompiled_code:
__int64 __fastcall tsl_prepend(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rax

v6 = mem_alloc_location(32LL, "tslist.c", 67LL);
result = 0LL;
if ( v6 )
{
*(_DWORD *)(v6 + 24) = a4;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = a3;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_QWORD *)v6 = *(_QWORD *)a1;
v8 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a1 = v6;
*(_QWORD *)(a1 + 16) = v8 + 1;
if ( !v8 )
*(_QWORD *)(a1 + 8) = v6;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rax

v6 = mem_alloc_location(32LL, "tslist.c", 67LL);
result = 0LL;
if ( v6 )
{
*(_DWORD *)(v6 + 24) = a4;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = a3;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_QWORD *)v6 = *(_QWORD *)a1;
v8 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a1 = v6;
*(_QWORD *)(a1 + 16) = v8 + 1;
if ( !v8 )
*(_QWORD *)(a1 + 8) = v6;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
result = 1LL;
}
return result;
}

original_code:
int tsl_prepend(TSList tsl, void *a, void *b, int size) {
 ListHead *lh = (ListHead *)tsl;
 Element *e = (Element *)mem_alloc_location((sizeof(Element)), "tslist.c", 67);
 if (!e)
  return 0;
 e->addr = a;
 e->data = b;
 e->size = size;
 pthread_mutex_lock(&(lh->mutex));
 e->next = lh->head;
 lh->head = e;
 if (! lh->count++)
  lh->tail = e;
 pthread_cond_signal(&(lh->nonempty));
 pthread_mutex_unlock(&(lh->mutex));
 return 1;
}

canonical_original_code:
int tsl_prepend(void *tsl, void *a, void *b, int size) {
 struct listhead *lh = (ListHead *)tsl;
 struct element *e = (Element *)mem_alloc_location((sizeof(Element)), "tslist.c", 67);
 if (!e)
  return 0;
 e->addr = a;
 e->data = b;
 e->size = size;
 pthread_mutex_lock(&(lh->mutex));
 e->next = lh->head;
 lh->head = e;
 if (! lh->count++)
  lh->tail = e;
 pthread_cond_signal(&(lh->nonempty));
 pthread_mutex_unlock(&(lh->mutex));
 return 1;
}

user_defined_types: struct element { struct element *next; void *addr; void *data; int size; }


original_code:
void tsl_remove(TSList tsl, void **a, void **b, int *size) {
 ListHead *lh = (ListHead *)tsl;
 Element *e;
 pthread_mutex_lock(&(lh->mutex));
 while (!lh->count)
  pthread_cond_wait(&(lh->nonempty), &(lh->mutex));
 e = lh->head;
 lh->head = e->next;
 if (! --lh->count)
  lh->tail = ((void *)0);
 pthread_mutex_unlock(&(lh->mutex));
 *a = e->addr;
 *b = e->data;
 *size = e->size;
 ((void)(mem_free_location((e), "tslist.c", 102), (e) = 0));
}

canonical_original_code:
void tsl_remove(void *tsl, void **a, void **b, int *size) {
 struct listhead *lh = (ListHead *)tsl;
 struct element *e;
 pthread_mutex_lock(&(lh->mutex));
 while (!lh->count)
  pthread_cond_wait(&(lh->nonempty), &(lh->mutex));
 e = lh->head;
 lh->head = e->next;
 if (! --lh->count)
  lh->tail = ((void *)0);
 pthread_mutex_unlock(&(lh->mutex));
 *a = e->addr;
 *b = e->data;
 *size = e->size;
 ((void)(mem_free_location((e), "tslist.c", 102), (e) = 0));
}

variable_types:
a
void **

variable_types:
b
void **

variable_types:
size
int *


matchedState

decompiled_code:
__int64 __fastcall matchedState(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // er8
__int64 v4; // rax

v3 = a3;
if ( a3 > 0 )
{
v4 = 0LL;
while ( *(_QWORD *)(a2 + 8 * v4) != a1 )
{
if ( ++v4 == a3 )
return v3;
}
v3 = v4;
}
return v3;
}

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

v3 = a3;
if ( a3 > 0 )
{
v4 = 0LL;
while ( *(_QWORD *)(a2 + 8 * v4) != a1 )
{
if ( ++v4 == a3 )
return v3;
}
v3 = v4;
}
return v3;
}

original_code:
static int matchedState(unsigned long st, unsigned long *states, int n) {
    int i;
    for (i = 0; i < n; i++)
 if (st == states[i])
     return i;
    return n;
}

variable_types:
st
unsigned long

variable_types:
states
unsigned long *

variable_types: n int


decompiled_code:
int __fastcall crecord_dump(_QWORD *a1)
{
endpoint_dump(a1[11]);
return fprintf(stderr, "seqno: %ld, state: %s\n", a1[2], (const char *)*(&statenames + a1[3]));
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1)
{
endpoint_dump(a1[11]);
return fprintf(stderr, "seqno: %ld, state: %s\n", a1[2], (const char *)*(&statenames + a1[3]));
}

original_code:
void crecord_dump(CRecord *cr, char *leadString) {
 endpoint_dump(cr->ep, leadString);
 fprintf(stderr, "seqno: %ld, state: %s\n", cr->seqno, statenames[cr->state]);
}

canonical_original_code:
void crecord_dump(struct c_record *cr, char *leadString) {
 endpoint_dump(cr->ep, leadString);
 fprintf(stderr, "seqno: %ld, state: %s\n", cr->seqno, statenames[cr->state]);
}

variable_types: struct c_record { struct c_record *next; struct c_record *link; unsigned long seqno; unsigned long state; 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; } *mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } stateChanged; struct rpc_endpoint { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned long subport; } *ep; struct s_record { struct s_record *s_next; char *s_name; void *s_queue; } *svc; void *pl; void *resp; unsigned int size; unsigned short nattempts; unsigned short ticks; unsigned short ticksLeft; unsigned short pingsTilPurge; unsigned short ticksTilPing; unsigned char lastFrag; } *

variable_types:
leadString
char *

user_defined_types: struct c_record { struct c_record *next; struct c_record *link; unsigned long seqno; unsigned long state; union pthread_mutex_t *mutex; union pthread_cond_t stateChanged; struct rpc_endpoint *ep; struct s_record *svc; void *pl; void *resp; unsigned int size; unsigned short nattempts; unsigned short ticks; unsigned short ticksLeft; unsigned short pingsTilPurge; unsigned short ticksTilPing; unsigned char lastFrag; }

user_defined_types: struct rpc_endpoint { struct sockaddr_in addr; unsigned long subport; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
int __fastcall crecord_setState(__int64 a1, __int64 a2)
{
__int64 v2; // rdi

*(_QWORD *)(a1 + 24) = a2;
v2 = a1 + 40;
*(_DWORD *)(v2 + 90) = 196608003;
return pthread_cond_broadcast((pthread_cond_t *)v2);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rdi

*(_QWORD *)(a1 + 24) = a2;
v2 = a1 + 40;
*(_DWORD *)(v2 + 90) = 196608003;
return pthread_cond_broadcast((pthread_cond_t *)v2);
}

original_code:
void crecord_setState(CRecord *cr, unsigned long state) {
 cr->state = state;
 cr->ticksTilPing = (60 * 50);
 cr->pingsTilPurge = 3;
 pthread_cond_broadcast(&cr->stateChanged);
}

canonical_original_code:
void crecord_setState(struct c_record *cr, unsigned long state) {
 cr->state = state;
 cr->ticksTilPing = (60 * 50);
 cr->pingsTilPurge = 3;
 pthread_cond_broadcast(&cr->stateChanged);
}

variable_types:
state
unsigned long

user_defined_types: struct s_record { struct s_record *s_next; char *s_name; void *s_queue; }


original_code:
void crecord_setPayload(CRecord *cr, void *pl, unsigned size,
          unsigned short nattempts, unsigned short ticks) {
 if (cr->pl)
  ((void)(mem_free_location((cr->pl), "crecord.c", 58), (cr->pl) = 0));
 cr->pl = pl;
 cr->size = size;
 cr->nattempts = nattempts;
 cr->ticks = ticks;
 cr->ticksLeft = ticks;
}

canonical_original_code:
void crecord_setPayload(struct c_record *cr, void *pl, unsigned int size, unsigned short nattempts, unsigned short ticks) {
 if (cr->pl)
  ((void)(mem_free_location((cr->pl), "crecord.c", 58), (cr->pl) = 0));
 cr->pl = pl;
 cr->size = size;
 cr->nattempts = nattempts;
 cr->ticks = ticks;
 cr->ticksLeft = ticks;
}

variable_types:
pl
void *

variable_types:
size
unsigned int

variable_types:
nattempts
unsigned short

variable_types:
ticks
unsigned short


decompiled_code:
void __fastcall crecord_setService(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 96) = a2;
}

original_code:
void crecord_setService(CRecord *cr, SRecord *sr) {
 cr->svc = sr;
}

canonical_original_code:
void crecord_setService(struct c_record *cr, struct s_record *sr) {
 cr->svc = sr;
}

variable_types:
sr
struct s_record *


decompiled_code:
__int64 __fastcall crecord_waitForState(__int64 a1, __int64 a2, int a3)
{
int v4; // eax

while ( 1 )
{
v4 = matchedState(*(_QWORD *)(a1 + 24), a2, a3);
if ( a3 != v4 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 40), *(pthread_mutex_t **)(a1 + 32));
}
return *(_QWORD *)(a2 + 8LL * v4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
int v4; // eax

while ( 1 )
{
v4 = func0(*(_QWORD *)(a1 + 24), a2, a3);
if ( a3 != v4 )
break;
pthread_cond_wait((pthread_cond_t *)(a1 + 40), *(pthread_mutex_t **)(a1 + 32));
}
return *(_QWORD *)(a2 + 8LL * v4);
}

original_code:
unsigned long crecord_waitForState(CRecord *cr, unsigned long *states, int n) {
    int i;
    while ((i = matchedState(cr->state, states, n)) == n)
 pthread_cond_wait(&cr->stateChanged, cr->mutex);
    return states[i];
}

canonical_original_code:
unsigned long crecord_waitForState(struct c_record *cr, unsigned long *states, int n) {
    int i;
    while ((i = matchedState(cr->state, states, n)) == n)
 pthread_cond_wait(&cr->stateChanged, cr->mutex);
    return states[i];
}

variable_types: i int


decompiled_code:
__int64 __fastcall crecord_destroy(_QWORD *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = a1[11];
if ( v2 )
{
mem_free_location(v2, "crecord.c", 90LL);
a1[11] = 0LL;
}
v3 = a1[13];
if ( v3 )
{
mem_free_location(v3, "crecord.c", 92LL);
a1[13] = 0LL;
}
v4 = a1[14];
if ( v4 )
{
mem_free_location(v4, "crecord.c", 94LL);
a1[14] = 0LL;
}
result = mem_free_location(a1, "crecord.c", 95LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = a1[11];
if ( v2 )
{
mem_free_location(v2, "crecord.c", 90LL);
a1[11] = 0LL;
}
v3 = a1[13];
if ( v3 )
{
mem_free_location(v3, "crecord.c", 92LL);
a1[13] = 0LL;
}
v4 = a1[14];
if ( v4 )
{
mem_free_location(v4, "crecord.c", 94LL);
a1[14] = 0LL;
}
result = mem_free_location(a1, "crecord.c", 95LL);
}
return result;
}

original_code:
void crecord_destroy(CRecord *cr) {
    if (cr) {
 if (cr->ep)
     ((void)(mem_free_location((cr->ep), "crecord.c", 90), (cr->ep) = 0));
 if (cr->pl)
     ((void)(mem_free_location((cr->pl), "crecord.c", 92), (cr->pl) = 0));
 if (cr->resp)
     ((void)(mem_free_location((cr->resp), "crecord.c", 94), (cr->resp) = 0));
 ((void)(mem_free_location((cr), "crecord.c", 95), (cr) = 0));
    }
}

canonical_original_code:
void crecord_destroy(struct c_record *cr) {
    if (cr) {
 if (cr->ep)
     ((void)(mem_free_location((cr->ep), "crecord.c", 90), (cr->ep) = 0));
 if (cr->pl)
     ((void)(mem_free_location((cr->pl), "crecord.c", 92), (cr->pl) = 0));
 if (cr->resp)
     ((void)(mem_free_location((cr->resp), "crecord.c", 94), (cr->resp) = 0));
 ((void)(mem_free_location((cr), "crecord.c", 95), (cr) = 0));
    }
}


decompiled_code:
__int64 __fastcall endpoint_equal(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx

result = memeq_constprop_0(a1, a1);
if ( (_DWORD)result )
result = *(_QWORD *)(a1 + 16) == *(_QWORD *)(v2 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx

result = func1(a1, a1);
if ( (_DWORD)result )
result = *(_QWORD *)(a1 + 16) == *(_QWORD *)(v2 + 16);
return result;
}

original_code:
int endpoint_equal(RpcEndpoint *ep1, RpcEndpoint *ep2) {
 int answer = 0;
 if (memeq(&(ep1->addr), &(ep1->addr), sizeof(struct sockaddr_in)))
  if (ep1->subport == ep2->subport)
   answer = 1;
 return answer;
}

canonical_original_code:
int endpoint_equal(struct rpc_endpoint *ep1, struct rpc_endpoint *ep2) {
 int answer = 0;
 if (memeq(&(ep1->addr), &(ep1->addr), sizeof(struct sockaddr_in)))
  if (ep1->subport == ep2->subport)
   answer = 1;
 return answer;
}

variable_types: struct rpc_endpoint { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned long subport; } *

variable_types: answer int


decompiled_code:
unsigned __int64 __fastcall endpoint_hash(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 *v2; // r8
unsigned __int8 *v3; // rcx
unsigned __int8 *v4; // rdi
unsigned int v5; // edx

v2 = a1;
v3 = a1;
v4 = a1 + 16;
v5 = 0;
do
v5 = (*v3++ + 7 * v5) % a2;
while ( v3 != v4 );
return (*((_QWORD *)v2 + 2) + (unsigned __int64)(7 * v5)) % a2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 *v2; // r8
unsigned __int8 *v3; // rcx
unsigned __int8 *v4; // rdi
unsigned int v5; // edx

v2 = a1;
v3 = a1;
v4 = a1 + 16;
v5 = 0;
do
v5 = (*v3++ + 7 * v5) % a2;
while ( v3 != v4 );
return (*((_QWORD *)v2 + 2) + (unsigned __int64)(7 * v5)) % a2;
}

original_code:
unsigned endpoint_hash(RpcEndpoint *ep, unsigned limit) {
 unsigned i;
 unsigned char *p;
 unsigned hash = 0;
 p = (unsigned char *)&(ep->addr);
 for (i = 0; i < sizeof(struct sockaddr_in); i++)
  hash = ((7 * hash) + *p++) % limit;
 hash = ((7 * hash) + ep->subport) % limit;
 return hash;
}

canonical_original_code:
unsigned int endpoint_hash(struct rpc_endpoint *ep, unsigned int limit) {
 unsigned int i;
 unsigned char *p;
 unsigned int hash = 0;
 p = (unsigned char *)&(ep->addr);
 for (i = 0; i < sizeof(struct sockaddr_in); i++)
  hash = ((7 * hash) + *p++) % limit;
 hash = ((7 * hash) + ep->subport) % limit;
 return hash;
}

variable_types:
limit
unsigned int

variable_types:
i
unsigned int

variable_types:
p
unsigned char *

variable_types:
hash
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall endpoint_dump(unsigned __int8 *a1, const char *a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rdx

v2 = a1;
fputs(a2, stderr);
do
{
v3 = *v2++;
fprintf(stderr, " %02x", v3);
}
while ( a1 + 24 != v2 );
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func5(unsigned __int8 *a1, const char *a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rdx

v2 = a1;
fputs(a2, stderr);
do
{
v3 = *v2++;
fprintf(stderr, " %02x", v3);
}
while ( a1 + 24 != v2 );
return fputc(10, stderr);
}

original_code:
void endpoint_dump(RpcEndpoint *ep, char *leadString) {
 unsigned i;
 unsigned char *p;
 fprintf(stderr, "%s", leadString);
 for (i = 0, p = (unsigned char *)ep; i < sizeof(RpcEndpoint); i++)
  fprintf(stderr, " %02x", *p++);
 fprintf(stderr, "\n");
}

canonical_original_code:
void endpoint_dump(struct rpc_endpoint *ep, char *leadString) {
 unsigned int i;
 unsigned char *p;
 fprintf(stderr, "%s", leadString);
 for (i = 0, p = (unsigned char *)ep; i < sizeof(RpcEndpoint); i++)
  fprintf(stderr, " %02x", *p++);
 fprintf(stderr, "\n");
}


hash

decompiled_code:
__int64 __fastcall hash(_BYTE *a1)
{
int v1; // eax
int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 7 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return (unsigned int)(v2 % 13);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 7 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return (unsigned int)(v2 % 13);
}

original_code:
static int hash(char *s) {
    int ans = 0;
    while (*s != '\0')
 ans = (7 * ans) + *s++;
    return ans % 13;
}

variable_types:
s
char *

variable_types: ans int


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

result = 0LL;
memset(&stable, 0, 0x68uLL);
return result;
}

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

result = 0LL;
memset(&stable, 0, 0x68uLL);
return result;
}

original_code:
void stable_init() {
    int i;
    for (i = 0; i < 13; i++)
        stable[i] = ((void *)0);
}


decompiled_code:
__int64 __fastcall stable_lookup(char *s2)
{
__int64 v1; // r12
__int64 i; // r12

v1 = (int)hash(s2);
pthread_mutex_lock(&mutex);
for ( i = stable[v1]; i; i = *(_QWORD *)i )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
pthread_mutex_unlock(&mutex);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
__int64 v1; // r12
__int64 i; // r12

v1 = (int)func0(s2);
pthread_mutex_lock(&mutex);
for ( i = stable[v1]; i; i = *(_QWORD *)i )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
pthread_mutex_unlock(&mutex);
return i;
}

original_code:
SRecord *stable_lookup(char *name) {
    int hv = hash(name);
    SRecord *r, *ans = ((void *)0);
    pthread_mutex_lock(&mutex);
    for (r = stable[hv]; r != ((void *)0); r = r->s_next)
        if (strcmp(r->s_name, name) == 0) {
            ans = r;
            break;
        }
    pthread_mutex_unlock(&mutex);
    return ans;
}

canonical_original_code:
struct s_record *stable_lookup(char *name) {
    int hv = hash(name);
    struct s_record *r; struct s_record *ans = ((void *)0);
    pthread_mutex_lock(&mutex);
    for (r = stable[hv]; r != ((void *)0); r = r->s_next)
        if (strcmp(r->s_name, name) == 0) {
            ans = r;
            break;
        }
    pthread_mutex_unlock(&mutex);
    return ans;
}

variable_types:
name
char *

variable_types: hv int

variable_types: struct s_record { struct s_record *s_next; char *s_name; void *s_queue; } *


decompiled_code:
__int64 __fastcall stable_remove(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // rbx
const char *v3; // r12
__int64 *v4; // rbp
int v5; // eax
__int64 *v6; // rdx

v1 = (int)hash(*(_BYTE **)(a1 + 8));
pthread_mutex_lock(&mutex);
v2 = stable[v1];
if ( v2 )
{
v3 = *(const char **)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = strcmp(v3, *(const char **)(v2 + 8));
v6 = (__int64 *)v2;
v2 = *(_QWORD *)v2;
if ( !v5 )
break;
v4 = v6;
if ( !v2 )
goto LABEL_7;
}
if ( v4 )
*v4 = v2;
else
stable[v1] = v2;
}
LABEL_7:
pthread_mutex_unlock(&mutex);
return mem_free_location(a1, "stable.c", 91LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // rbx
const char *v3; // r12
__int64 *v4; // rbp
int v5; // eax
__int64 *v6; // rdx

v1 = (int)func0(*(_BYTE **)(a1 + 8));
pthread_mutex_lock(&mutex);
v2 = stable[v1];
if ( v2 )
{
v3 = *(const char **)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = strcmp(v3, *(const char **)(v2 + 8));
v6 = (__int64 *)v2;
v2 = *(_QWORD *)v2;
if ( !v5 )
break;
v4 = v6;
if ( !v2 )
goto LABEL_7;
}
if ( v4 )
*v4 = v2;
else
stable[v1] = v2;
}
LABEL_7:
pthread_mutex_unlock(&mutex);
return mem_free_location(a1, "stable.c", 91LL);
}

original_code:
void stable_remove(SRecord *sr) {
    SRecord *pr, *cu;
    int hv = hash(sr->s_name);
    pthread_mutex_lock(&mutex);
    for (pr = ((void *)0), cu = stable[hv]; cu != ((void *)0); pr = cu, cu = pr->s_next) {
        if (strcmp(sr->s_name, cu->s_name) == 0) {
            if (pr == ((void *)0))
                stable[hv] = cu->s_next;
            else
                pr->s_next = cu->s_next;
            break;
        }
    }
    pthread_mutex_unlock(&mutex);
    ((void)(mem_free_location((sr), "stable.c", 91), (sr) = 0));
}

canonical_original_code:
void stable_remove(struct s_record *sr) {
    struct s_record *pr; struct s_record *cu;
    int hv = hash(sr->s_name);
    pthread_mutex_lock(&mutex);
    for (pr = ((void *)0), cu = stable[hv]; cu != ((void *)0); pr = cu, cu = pr->s_next) {
        if (strcmp(sr->s_name, cu->s_name) == 0) {
            if (pr == ((void *)0))
                stable[hv] = cu->s_next;
            else
                pr->s_next = cu->s_next;
            break;
        }
    }
    pthread_mutex_unlock(&mutex);
    ((void)(mem_free_location((sr), "stable.c", 91), (sr) = 0));
}


decompiled_code:
int stable_dump()
{
char *v0; // rbp
__int64 **v1; // rbx

v0 = (char *)stable;
pthread_mutex_lock(&mutex);
printf("Service table:");
do
{
v1 = *(__int64 ***)v0;
if ( *(_QWORD *)v0 )
{
do
{
printf(" %s", (const char *)v1[1]);
v1 = (__int64 **)*v1;
}
while ( v1 );
}
v0 += 8;
}
while ( v0 != "stable.c" );
putchar(10);
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int func4()
{
char *v0; // rbp
__int64 **v1; // rbx

v0 = (char *)stable;
pthread_mutex_lock(&mutex);
printf("Service table:");
do
{
v1 = *(__int64 ***)v0;
if ( *(_QWORD *)v0 )
{
do
{
printf(" %s", (const char *)v1[1]);
v1 = (__int64 **)*v1;
}
while ( v1 );
}
v0 += 8;
}
while ( v0 != "stable.c" );
putchar(10);
return pthread_mutex_unlock(&mutex);
}

original_code:
void stable_dump(void) {
    SRecord *p;
    int i;
    pthread_mutex_lock(&mutex);
    printf("Service table:");
    for (i = 0; i < 13; i++) {
        for (p = stable[i]; p != ((void *)0); p = p->s_next) {
     printf(" %s", p->s_name);
        }
    }
    printf("\n");
    pthread_mutex_unlock(&mutex);
}

canonical_original_code:
void stable_dump() {
    struct s_record *p;
    int i;
    pthread_mutex_lock(&mutex);
    printf("Service table:");
    for (i = 0; i < 13; i++) {
        for (p = stable[i]; p != ((void *)0); p = p->s_next) {
     printf(" %s", p->s_name);
        }
    }
    printf("\n");
    pthread_mutex_unlock(&mutex);
}


decompiled_code:
int ctable_lock()
{
return pthread_mutex_lock(&mutex);
}

canonical_decompiled_code:
int func0()
{
return pthread_mutex_lock(&mutex);
}

original_code:
void ctable_lock(void) {
    pthread_mutex_lock(&mutex);
}

canonical_original_code:
void ctable_lock() {
    pthread_mutex_lock(&mutex);
}


decompiled_code:
int ctable_unlock()
{
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int func1()
{
return pthread_mutex_unlock(&mutex);
}

original_code:
void ctable_unlock(void) {
    pthread_mutex_unlock(&mutex);
}

canonical_original_code:
void ctable_unlock() {
    pthread_mutex_unlock(&mutex);
}


canonical_decompiled_code:
pthread_mutex_t *func2()
{
return &mutex;
}

original_code:
pthread_mutex_t *ctable_getMutex(void) {
    return &mutex;
}

canonical_original_code:
union pthread_mutex_t *ctable_getMutex() {
    return &mutex;
}

return_type: 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; } *


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

pthread_mutex_init(&mutex, 0LL);
result = 0LL;
memset(&ctable, 0, 0xF8uLL);
return result;
}

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

pthread_mutex_init(&mutex, 0LL);
result = 0LL;
memset(&ctable, 0, 0xF8uLL);
return result;
}

original_code:
void ctable_init(void) {
    int i;
    pthread_mutex_init(&mutex, ((void *)0));
    for (i = 0; i < 31; i++)
        ctable[i] = ((void *)0);
}

canonical_original_code:
void ctable_init() {
    int i;
    pthread_mutex_init(&mutex, ((void *)0));
    for (i = 0; i < 31; i++)
        ctable[i] = ((void *)0);
}


decompiled_code:
__int64 ctable_newSubport()
{
unsigned __int16 v0; // ax
__int64 result; // rax

v0 = ctr + 1;
if ( (__int16)(ctr + 1) < 0 )
{
ctr = 1;
result = (getpid() << 16) | 1;
}
else
{
++ctr;
result = v0 | (getpid() << 16);
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int16 v0; // ax
__int64 result; // rax

v0 = ctr + 1;
if ( (__int16)(ctr + 1) < 0 )
{
ctr = 1;
result = (getpid() << 16) | 1;
}
else
{
++ctr;
result = v0 | (getpid() << 16);
}
return result;
}

original_code:
unsigned long ctable_newSubport(void) {
    unsigned long subport;
    pid_t pid;
    if (++ctr > 0x7fff)
        ctr = 1;
    pid = getpid();
    subport = (pid & 0xffff) << 16 | ctr;
    return subport;
}

canonical_original_code:
unsigned long ctable_newSubport() {
    unsigned long subport;
    int pid;
    if (++ctr > 0x7fff)
        ctr = 1;
    pid = getpid();
    subport = (pid & 0xffff) << 16 | ctr;
    return subport;
}

variable_types:
subport
unsigned long

variable_types: pid int


decompiled_code:
__int64 __fastcall ctable_insert(_QWORD *a1)
{
__int64 result; // rax

result = (unsigned int)endpoint_hash(a1[11], 31LL);
*a1 = ctable[(unsigned int)result];
ctable[(unsigned int)result] = (__int64)a1;
return result;
}

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

result = (unsigned int)endpoint_hash(a1[11], 31LL);
*a1 = ctable[(unsigned int)result];
ctable[(unsigned int)result] = (__int64)a1;
return result;
}

original_code:
void ctable_insert(CRecord *cr) {
    unsigned hash = endpoint_hash(cr->ep, 31);
    cr->next = ctable[hash];
    ctable[hash] = cr;
}

canonical_original_code:
void ctable_insert(struct c_record *cr) {
    unsigned int hash = endpoint_hash(cr->ep, 31);
    cr->next = ctable[hash];
    ctable[hash] = cr;
}

variable_types: struct c_record { struct c_record *next; struct c_record *link; unsigned long seqno; unsigned long state; 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; } *mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } stateChanged; struct rpc_endpoint { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned long subport; } *ep; struct s_record { struct s_record *s_next; char *s_name; void *s_queue; } *svc; void *pl; void *resp; unsigned int size; unsigned short nattempts; unsigned short ticks; unsigned short ticksLeft; unsigned short pingsTilPurge; unsigned short ticksTilPing; unsigned char lastFrag; } *


decompiled_code:
__int64 ctable_purge()
{
__int64 *v0; // rbp
_QWORD *v1; // rbx
_QWORD *v2; // rdi

v0 = ctable;
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
do
{
v1 = (_QWORD *)*v0;
if ( *v0 )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
crecord_destroy(v2);
}
while ( v1 );
}
++v0;
}
while ( v0 != (__int64 *)&unk_4B8 );
return ctable_init();
}

canonical_decompiled_code:
__int64 func7()
{
__int64 *v0; // rbp
_QWORD *v1; // rbx
_QWORD *v2; // rdi

v0 = ctable;
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
do
{
v1 = (_QWORD *)*v0;
if ( *v0 )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
crecord_destroy(v2);
}
while ( v1 );
}
++v0;
}
while ( v0 != (__int64 *)&unk_4B8 );
return func3();
}

original_code:
void ctable_purge(void) {
    CRecord *p, *next;
    int i;
    (void)pthread_mutex_trylock(&mutex);
    pthread_mutex_unlock(&mutex);
    pthread_mutex_destroy(&mutex);
    for (i = 0; i < 31; i++) {
        for (p = ctable[i]; p != ((void *)0); p = next) {
            next = p->next;
     crecord_destroy(p);
 }
    }
    ctable_init();
}

canonical_original_code:
void ctable_purge() {
    struct c_record *p; struct c_record *next;
    int i;
    (void)pthread_mutex_trylock(&mutex);
    pthread_mutex_unlock(&mutex);
    pthread_mutex_destroy(&mutex);
    for (i = 0; i < 31; i++) {
        for (p = ctable[i]; p != ((void *)0); p = next) {
            next = p->next;
     crecord_destroy(p);
 }
    }
    ctable_init();
}


decompiled_code:
__int64 __fastcall ctable_dump(__int64 a1)
{
__int64 *v1; // r12
_QWORD *v2; // rbx
__int64 result; // rax

v1 = ctable;
do
{
v2 = (_QWORD *)*v1;
if ( *v1 )
{
do
{
result = crecord_dump(v2, a1);
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
++v1;
}
while ( v1 != (__int64 *)&unk_4B8 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 *v1; // r12
_QWORD *v2; // rbx
__int64 result; // rax

v1 = ctable;
do
{
v2 = (_QWORD *)*v1;
if ( *v1 )
{
do
{
result = crecord_dump(v2, a1);
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
++v1;
}
while ( v1 != (__int64 *)&unk_4B8 );
return result;
}

original_code:
void ctable_dump(char *str) {
    CRecord *p;
    int i;
    for (i = 0; i < 31; i++) {
        for (p = ctable[i]; p != ((void *)0); p = p->next) {
            crecord_dump(p, str);
        }
    }
}

canonical_original_code:
void ctable_dump(char *str) {
    struct c_record *p;
    int i;
    for (i = 0; i < 31; i++) {
        for (p = ctable[i]; p != ((void *)0); p = p->next) {
            crecord_dump(p, str);
        }
    }
}

variable_types:
str
char *


decompiled_code:
void *__fastcall mem_alloc_location(size_t a1, const char *a2, unsigned int a3)
{
void *v4; // r12

v4 = malloc(a1);
if ( !v4 || !log_allocation )
return v4;
printf("%p allocated @ %s/line %d, %zd bytes\n", v4, a2, a3, a1);
return v4;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1, const char *a2, unsigned int a3)
{
void *v4; // r12

v4 = malloc(a1);
if ( !v4 || !log_allocation )
return v4;
printf("%p allocated @ %s/line %d, %zd bytes\n", v4, a2, a3, a1);
return v4;
}

original_code:
void *mem_alloc_location(size_t nbytes, const char *file, int line) {
    void *p;
    p = malloc(nbytes);
    if (p && log_allocation)
        printf("%p allocated @ %s/line %d, %zd bytes\n", p, file, line, nbytes);
    return p;
}

canonical_original_code:
void *mem_alloc_location(unsigned long nbytes, char *file, int line) {
    void *p;
    p = malloc(nbytes);
    if (p && log_allocation)
        printf("%p allocated @ %s/line %d, %zd bytes\n", p, file, line, nbytes);
    return p;
}

variable_types:
nbytes
unsigned long

variable_types:
file
char *

variable_types: line int

variable_types:
p
void *


decompiled_code:
void __fastcall mem_free_location(void *ptr, const char *a2, unsigned int a3)
{
if ( ptr )
{
if ( log_allocation )
printf("%p dealloced @ %s/line %d\n", ptr, a2, a3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr, const char *a2, unsigned int a3)
{
if ( ptr )
{
if ( log_allocation )
printf("%p dealloced @ %s/line %d\n", ptr, a2, a3);
free(ptr);
}
}

original_code:
void mem_free_location(void *ptr, const char *file, int line) {
    if (ptr) {
        if (log_allocation)
            printf("%p dealloced @ %s/line %d\n", ptr, file, line);
        free(ptr);
    }
}

canonical_original_code:
void mem_free_location(void *ptr, char *file, int line) {
    if (ptr) {
        if (log_allocation)
            printf("%p dealloced @ %s/line %d\n", ptr, file, line);
        free(ptr);
    }
}

variable_types:
ptr
void *


decompiled_code:
char *__fastcall str_dupl_location(char *src, const char *a2, unsigned int a3)
{
int v4; // eax
char *v5; // rax
char *v6; // r8

v4 = strlen(src);
v5 = (char *)mem_alloc_location(v4 + 1, a2, a3);
v6 = v5;
if ( v5 )
v6 = strcpy(v5, src);
return v6;
}

canonical_decompiled_code:
char *__fastcall func2(char *src, const char *a2, unsigned int a3)
{
int v4; // eax
char *v5; // rax
char *v6; // r8

v4 = strlen(src);
v5 = (char *)func0(v4 + 1, a2, a3);
v6 = v5;
if ( v5 )
v6 = strcpy(v5, src);
return v6;
}

original_code:
char *str_dupl_location(const char *s, const char *file, int line) {
    int n = strlen(s) + 1;
    char *p = (char *)mem_alloc_location(n, file, line);
    if (p)
 strcpy(p, s);
    return p;
}

canonical_original_code:
char *str_dupl_location(char *s, char *file, int line) {
    int n = strlen(s) + 1;
    char *p = (char *)mem_alloc_location(n, file, line);
    if (p)
 strcpy(p, s);
    return p;
}

variable_types: n int

variable_types:
p
char *

return_type: char *


decompiled_code:
int __fastcall mem_heap_end_address(const char *a1)
{
void *v1; // rax

v1 = sbrk(0LL);
return printf("%s %p\n", a1, v1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
void *v1; // rax

v1 = sbrk(0LL);
return printf("%s %p\n", a1, v1);
}

original_code:
void mem_heap_end_address(char *leadString) {
    printf("%s %p\n", leadString, sbrk(0));
}

variable_types:
leadString
char *


repo: crunkmaster/lisp

decompiled_code:
void *__fastcall new_atom(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func6(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
lisp_atom new_atom( char *s ) {
  char *dest = malloc( sizeof(char) * (strlen(s) + 1 )) ;
  if ( dest )
    strcpy( dest, s ) ;
  return dest ;
}

canonical_original_code:
char *new_atom(char *s) {
  char *dest = malloc( sizeof(char) * (strlen(s) + 1 ));
  if ( dest )
    strcpy( dest, s ) ;
  return dest ;
}

variable_types:
s
char *

variable_types:
dest
char *


decompiled_code:
_BOOL8 __fastcall equal_atom(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int equal_atom( lisp_atom atom1, lisp_atom atom2 ) {
  return strcmp( atom1, atom2 ) == 0 ;
}

canonical_original_code:
int equal_atom(char *atom1, char *atom2) {
  return strcmp( atom1, atom2 ) == 0 ;
}


gettoken

decompiled_code:
int *gettoken()
{
int *v0; // r13
__int64 v2; // rbp
unsigned __int64 v3; // rax
char *v4; // r12
const unsigned __int16 **v5; // r14
char v6; // al
char v7; // bl
char v8; // r15
_BYTE *v9; // r12
int v10; // eax
unsigned __int64 v11; // [rsp+8h] [rbp-40h]

v0 = (int *)p_lookahead;
if ( p_lookahead )
{
p_lookahead = 0LL;
}
else
{
tokenindex_1 = (tokenindex_1 + 1) % 2;
v2 = tokenindex_1;
v3 = 36LL * tokenindex_1;
v0 = &token_0[v3 / 4];
v11 = v3 + 4;
v4 = (char *)&unk_1E4 + v3;
do
{
v6 = getchar();
*v4 = v6;
v7 = v6;
v8 = v6;
if ( v6 == -1 )
{
token_0[9 * v2] = 4;
return v0;
}
v5 = _ctype_b_loc();
}
while ( ((*v5)[v7] & 0x2000) != 0 );
v4[1] = 0;
switch ( v8 )
{
case '(':
token_0[9 * v2] = 2;
break;
case ')':
token_0[9 * v2] = 1;
break;
case '\'':
token_0[9 * v2] = 0;
break;
default:
v9 = v4 + 1;
*((_BYTE *)token_0 + v11) = (*_ctype_toupper_loc())[v7];
while ( 1 )
{
v10 = getchar();
if ( v10 == -1 )
{
*v9 = 0;
goto LABEL_16;
}
if ( ((*v5)[v10] & 0x400) == 0 )
break;
*v9++ = toupper(v10);
}
*v9 = 0;
ungetc(v10, stdin);
LABEL_16:
token_0[9 * v2] = 3;
break;
}
}
return v0;
}

canonical_decompiled_code:
int *func0()
{
int *v0; // r13
__int64 v2; // rbp
unsigned __int64 v3; // rax
char *v4; // r12
const unsigned __int16 **v5; // r14
char v6; // al
char v7; // bl
char v8; // r15
_BYTE *v9; // r12
int v10; // eax
unsigned __int64 v11; // [rsp+8h] [rbp-40h]

v0 = (int *)p_lookahead;
if ( p_lookahead )
{
p_lookahead = 0LL;
}
else
{
tokenindex_1 = (tokenindex_1 + 1) % 2;
v2 = tokenindex_1;
v3 = 36LL * tokenindex_1;
v0 = &token_0[v3 / 4];
v11 = v3 + 4;
v4 = (char *)&unk_1E4 + v3;
do
{
v6 = getchar();
*v4 = v6;
v7 = v6;
v8 = v6;
if ( v6 == -1 )
{
token_0[9 * v2] = 4;
return v0;
}
v5 = _ctype_b_loc();
}
while ( ((*v5)[v7] & 0x2000) != 0 );
v4[1] = 0;
switch ( v8 )
{
case '(':
token_0[9 * v2] = 2;
break;
case ')':
token_0[9 * v2] = 1;
break;
case '\'':
token_0[9 * v2] = 0;
break;
default:
v9 = v4 + 1;
*((_BYTE *)token_0 + v11) = (*_ctype_toupper_loc())[v7];
while ( 1 )
{
v10 = getchar();
if ( v10 == -1 )
{
*v9 = 0;
goto LABEL_16;
}
if ( ((*v5)[v10] & 0x400) == 0 )
break;
*v9++ = toupper(v10);
}
*v9 = 0;
ungetc(v10, stdin);
LABEL_16:
token_0[9 * v2] = 3;
break;
}
}
return v0;
}

original_code:
tokendata *gettoken() {
  static tokendata token[2] ;
  static int tokenindex = 0 ;
  tokendata *p_token ;
  char *p_value ;
  int c ;
  if ( p_lookahead != ((void *)0) ) {
    p_token = p_lookahead ;
    p_lookahead = ((void *)0) ;
    return p_token ;
  }
  tokenindex = ( tokenindex + 1 ) % 2 ;
  p_token = &token[tokenindex] ;
  p_value = p_token -> tokenvalue ;
  do {
    if (( *p_value = getchar() ) == (-1) ) {
      p_token -> tokentype = EOF_T ;
      return p_token ;
    }
  } while ( ((*__ctype_b_loc ())[(int) ((*p_value))] & (unsigned short int) _ISspace)) ;
  p_value[1] = 0 ;
  switch ( *p_value ) {
  case '\'':
    p_token -> tokentype = QUOTE_T ;
    break ;
  case '(':
    p_token -> tokentype = LEFTPAREN_T ;
    break ;
  case ')':
    p_token -> tokentype = RIGHTPAREN_T ;
    break ;
  default:
    *p_value = toupper( *p_value ) ;
    p_value++ ;
    while (( c = getchar() ) != (-1) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha))
      *p_value++ = toupper( c ) ;
    *p_value = '\0' ;
    if ( c != (-1) )
      ungetc( c, stdin ) ;
    p_token -> tokentype = STRING_T ;
  }
  return p_token ;
}

canonical_original_code:
struct tokendata *gettoken() {
  static struct tokendata token[2];
  static int tokenindex = 0;
  struct tokendata *p_token;
  char *p_value;
  int c;
  if ( p_lookahead != ((void *)0) ) {
    p_token = p_lookahead ;
    p_lookahead = ((void *)0) ;
    return p_token ;
  }
  tokenindex = ( tokenindex + 1 ) % 2 ;
  p_token = &token[tokenindex] ;
  p_value = p_token -> tokenvalue ;
  do {
    if (( *p_value = getchar() ) == (-1) ) {
      p_token -> tokentype = EOF_T ;
      return p_token ;
    }
  } while ( ((*__ctype_b_loc ())[(int) ((*p_value))] & (unsigned short) _ISspace)) ;
  p_value[1] = 0 ;
  switch ( *p_value ) {
  case '\'':
    p_token -> tokentype = QUOTE_T ;
    break ;
  case '(':
    p_token -> tokentype = LEFTPAREN_T ;
    break ;
  case ')':
    p_token -> tokentype = RIGHTPAREN_T ;
    break ;
  default:
    *p_value = toupper( *p_value ) ;
    p_value++ ;
    while (( c = getchar() ) != (-1) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha))
      *p_value++ = toupper( c ) ;
    *p_value = '\0' ;
    if ( c != (-1) )
      ungetc( c, stdin ) ;
    p_token -> tokentype = STRING_T ;
  }
  return p_token ;
}

variable_types: struct tokendata { enum inputtype { QUOTE_T=0, RIGHTPAREN_T=1, LEFTPAREN_T=2, STRING_T=3, EOF_T=4 } tokentype; char tokenvalue[32]; } [2]

variable_types: tokenindex int

variable_types: struct tokendata { enum inputtype { QUOTE_T=0, RIGHTPAREN_T=1, LEFTPAREN_T=2, STRING_T=3, EOF_T=4 } tokentype; char tokenvalue[32]; } *

variable_types: c int

user_defined_types: struct tokendata { enum inputtype tokentype; char tokenvalue[32]; }


lookahead

decompiled_code:
int *lookahead()
{
int *result; // rax

result = (int *)p_lookahead;
if ( !p_lookahead )
{
result = gettoken();
p_lookahead = (__int64)result;
}
return result;
}

canonical_decompiled_code:
int *func1()
{
int *result; // rax

result = (int *)p_lookahead;
if ( !p_lookahead )
{
result = func0();
p_lookahead = (__int64)result;
}
return result;
}

canonical_original_code:
struct tokendata *lookahead() {
  if ( p_lookahead == ((void *)0) )
    p_lookahead = gettoken() ;
  return p_lookahead ;
}

return_type: struct tokendata { enum inputtype { QUOTE_T=0, RIGHTPAREN_T=1, LEFTPAREN_T=2, STRING_T=3, EOF_T=4 } tokentype; char tokenvalue[32]; } *


printerror

decompiled_code:
int __fastcall printerror(unsigned int a1)
{
int result; // eax

if ( a1 > 4 )
result = printf(" System Error. INvalid error number: %d\n", a1);
else
result = puts(errmsg_0[a1 - 1]);
return result;
}

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

if ( a1 > 4 )
result = printf(" System Error. INvalid error number: %d\n", a1);
else
result = puts(errmsg_0[a1 - 1]);
return result;
}

original_code:
void printerror( int errnum ) {
  static char *errmsg[] = {
    "unexpected end of file",
    "out of memory space",
    "syntax error",
    "error evaluating expression"
  } ;
  if ( errnum < 0 || errnum >= 5 ) {
    printf( " System Error. INvalid error number: %d\n", errnum ) ;
    return ;
  }
  printf( "%s\n", errmsg[errnum-1] ) ;
}

canonical_original_code:
void printerror(int errnum) {
  static char *errmsg[] = {
    "unexpected end of file",
    "out of memory space",
    "syntax error",
    "error evaluating expression"
  };
  if ( errnum < 0 || errnum >= 5 ) {
    printf( " System Error. INvalid error number: %d\n", errnum ) ;
    return ;
  }
  printf( "%s\n", errmsg[errnum-1] ) ;
}

variable_types: errnum int

variable_types:
errmsg
char *[]


top

repo: csbird/MySQLParser

decompiled_code:
__int64 __fastcall top(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
StackElementPtr top(StackElementPtr stack)
{
    return stack->next;
}

canonical_original_code:
struct stack_element *top(struct stack_element *stack)
{
    return stack->next;
}

variable_types:
stack
struct stack_element *

return_type: struct stack_element { int type; struct stack_element *next; } *


pop

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

result = *(_QWORD *)(a1 + 8);
if ( result )
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 8);
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( result )
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 8);
return result;
}

original_code:
StackElementPtr pop(StackElementPtr stack)
{
    StackElementPtr top = stack->next;
    if(top)
    {
        stack->next = top->next;
    }
    return top;
}

canonical_original_code:
struct stack_element *pop(struct stack_element *stack)
{
    struct stack_element *top = stack->next;
    if(top)
    {
        stack->next = top->next;
    }
    return top;
}

variable_types: struct stack_element { int type; struct stack_element *next; } *


destroy

decompiled_code:
void __fastcall destroy(__int64 a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)(a1 + 8);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void destroy(StackElementPtr stack)
{
    StackElementPtr p = stack->next;
    StackElementPtr temp;
    while(p)
    {
        temp = p;
        p = temp->next;
        free(temp);
    }
    stack->next = ((void *)0);
}

canonical_original_code:
void destroy(struct stack_element *stack)
{
    struct stack_element *p = stack->next;
    struct stack_element *temp;
    while(p)
    {
        temp = p;
        p = temp->next;
        free(temp);
    }
    stack->next = ((void *)0);
}

user_defined_types: struct stack_element { int type; struct stack_element *next; }


repo: csescholars/jGrade

decompiled_code:
__int64 __fastcall parse_CSV(char *a1, char **a2, int a3)
{
char **v3; // rbx
__int64 v4; // rbp
char *v5; // rax
char *save_ptr; // [rsp+8h] [rbp-20h] BYREF

save_ptr = 0LL;
if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
while ( 1 )
{
v5 = strtok_r(a1, ":\n", &save_ptr);
*v3 = v5;
if ( !v5 )
break;
++v3;
a1 = 0LL;
if ( v3 == (char **)v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char **a2, int a3)
{
char **v3; // rbx
__int64 v4; // rbp
char *v5; // rax
char *save_ptr; // [rsp+8h] [rbp-20h] BYREF

save_ptr = 0LL;
if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
while ( 1 )
{
v5 = strtok_r(a1, ":\n", &save_ptr);
*v3 = v5;
if ( !v5 )
break;
++v3;
a1 = 0LL;
if ( v3 == (char **)v4 )
return 0LL;
}
return 1LL;
}

original_code:
int parse_CSV(char *line, char *args[], int nargs) {
 char *save = ((void *)0), *parse;
 int i;
 for(i = 0, parse = line; i < nargs; i++) {
  args[i] = strtok_r(parse, ":\n", &save);
  if(!args[i])
   return 1;
  parse = ((void *)0);
 }
 return 0;
}

canonical_original_code:
int parse_CSV(char *line, char *args[], int nargs) {
 char *save = ((void *)0); char *parse;
 int i;
 for(i = 0, parse = line; i < nargs; i++) {
  args[i] = strtok_r(parse, ":\n", &save);
  if(!args[i])
   return 1;
  parse = ((void *)0);
 }
 return 0;
}

variable_types:
line
char *

variable_types:
args
char *[]

variable_types: nargs int

variable_types:
save
char *

variable_types:
parse
char *

variable_types: i int


diff

decompiled_code:
__int64 __fastcall diff(const char *a1, const char *a2)
{
int v2; // eax
unsigned int v3; // er8
char v5[184]; // [rsp+0h] [rbp-B8h] BYREF

snprintf(v5, 0xA0uLL, "diff -w %s %s > /dev/null", a1, a2);
v2 = system(v5);
v3 = 1;
if ( v2 != -1 && (v2 & 0x7F) == 0 )
v3 = BYTE1(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
int v2; // eax
unsigned int v3; // er8
char v5[184]; // [rsp+0h] [rbp-B8h] BYREF

snprintf(v5, 0xA0uLL, "diff -w %s %s > /dev/null", a1, a2);
v2 = system(v5);
v3 = 1;
if ( v2 != -1 && (v2 & 0x7F) == 0 )
v3 = BYTE1(v2);
return v3;
}

original_code:
int diff(char *f1, char *f2) {
 char command[161];
 int status;
 snprintf(command, 160, "diff -w %s %s > /dev/null", f1, f2);
 status = system(command);
 if(status == -1 || !(((status) & 0x7f) == 0))
  return 1;
 return (((status) & 0xff00) >> 8);
}

variable_types:
command
char [161]

variable_types: status int


mkpath

decompiled_code:
__int64 __fastcall mkpath(const char *a1, __mode_t a2)
{
int v2; // eax
char *v4; // r14
char *v5; // rax
char *v6; // rbp
char *v7; // rdi
char *v8; // rax
char *v9; // r15
unsigned int v10; // er12

v2 = *(unsigned __int8 *)a1;
if ( v2 == 46 && !a1[1] )
return *((unsigned __int8 *)a1 + 1);
if ( v2 != 47 || a1[1] )
{
v4 = strdup(a1);
if ( v4 )
{
v5 = strdup(a1);
v6 = v5;
if ( v5 )
{
v7 = dirname(v5);
if ( !v7 )
{
v10 = -1;
LABEL_13:
free(v6);
free(v4);
return v10;
}
v8 = strdup(v7);
v9 = v8;
if ( v8 )
{
if ( (unsigned int)mkpath(v8, a2) == -1 && *_errno_location() != 17
|| (v10 = 0, mkdir(v4, a2) == -1) && *_errno_location() != 17 )
{
v10 = -1;
}
free(v9);
goto LABEL_13;
}
}
}
exit(1);
}
return *((unsigned __int8 *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __mode_t a2)
{
int v2; // eax
char *v4; // r14
char *v5; // rax
char *v6; // rbp
char *v7; // rdi
char *v8; // rax
char *v9; // r15
unsigned int v10; // er12

v2 = *(unsigned __int8 *)a1;
if ( v2 == 46 && !a1[1] )
return *((unsigned __int8 *)a1 + 1);
if ( v2 != 47 || a1[1] )
{
v4 = strdup(a1);
if ( v4 )
{
v5 = strdup(a1);
v6 = v5;
if ( v5 )
{
v7 = dirname(v5);
if ( !v7 )
{
v10 = -1;
LABEL_13:
free(v6);
free(v4);
return v10;
}
v8 = strdup(v7);
v9 = v8;
if ( v8 )
{
if ( (unsigned int)func0(v8, a2) == -1 && *_errno_location() != 17
|| (v10 = 0, mkdir(v4, a2) == -1) && *_errno_location() != 17 )
{
v10 = -1;
}
free(v9);
goto LABEL_13;
}
}
}
exit(1);
}
return *((unsigned __int8 *)a1 + 1);
}

original_code:
int
mkpath(const char *s, mode_t mode){
 char *q, *r = ((void *)0), *path = ((void *)0), *up = ((void *)0);
 int rv;
 rv = -1;
 if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0)
  return (0);
 if ((path = strdup(s)) == ((void *)0))
  exit(1);
 if ((q = strdup(s)) == ((void *)0))
  exit(1);
 if ((r = dirname(q)) == ((void *)0))
  goto out;
 if ((up = strdup(r)) == ((void *)0))
  exit(1);
 if ((mkpath(up, mode) == -1) && ((*__errno_location ()) != 17))
  goto out;
 if ((mkdir(path, mode) == -1) && ((*__errno_location ()) != 17))
  rv = -1;
 else
  rv = 0;
out:
 if (up != ((void *)0))
  free(up);
 free(q);
 free(path);
 return (rv);
}

canonical_original_code:
int mkpath(char *s, unsigned int mode){
 char *q; char *r = ((void *)0); char *path = ((void *)0); char *up = ((void *)0);
 int rv;
 rv = -1;
 if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0)
  return (0);
 if ((path = strdup(s)) == ((void *)0))
  exit(1);
 if ((q = strdup(s)) == ((void *)0))
  exit(1);
 if ((r = dirname(q)) == ((void *)0))
  goto out;
 if ((up = strdup(r)) == ((void *)0))
  exit(1);
 if ((mkpath(up, mode) == -1) && ((*__errno_location ()) != 17))
  goto out;
 if ((mkdir(path, mode) == -1) && ((*__errno_location ()) != 17))
  rv = -1;
 else
  rv = 0;
out:
 if (up != ((void *)0))
  free(up);
 free(q);
 free(path);
 return (rv);
}

variable_types:
s
char *

variable_types:
mode
unsigned int

variable_types:
q
char *

variable_types:
r
char *

variable_types:
path
char *

variable_types:
up
char *

variable_types: rv int