GetIndexOfLetterInPrefixTree

decompiled_code:
__int64 __fastcall GetIndexOfLetterInPrefixTree(__int64 a1, char *a2, int a3)
{
char *v3; // rcx
__int64 v4; // rsi
int v5; // eax
int v6; // edx
__int64 result; // rax

if ( a3 <= 0 )
{
v5 = 0;
LABEL_6:
result = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 116LL * v5);
}
else
{
v3 = a2;
v4 = (__int64)&a2[a3 - 1 + 1];
v5 = 0;
while ( 1 )
{
v6 = *v3 - 65;
if ( v6 < 0 )
_assert_fail("c >= 0", "prefix_tree.c", 0x5Fu, "GetIndexOfLetterInPrefixTree");
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 116LL * v5 + 4LL * v6 + 4);
if ( v5 < 0 )
break;
if ( ++v3 == (char *)v4 )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a3 <= 0 )
{
v5 = 0;
LABEL_6:
result = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 116LL * v5);
}
else
{
v3 = a2;
v4 = (__int64)&a2[a3 - 1 + 1];
v5 = 0;
while ( 1 )
{
v6 = *v3 - 65;
if ( v6 < 0 )
_assert_fail("c >= 0", "prefix_tree.c", 0x5Fu, "GetIndexOfLetterInPrefixTree");
v5 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 116LL * v5 + 4LL * v6 + 4);
if ( v5 < 0 )
break;
if ( ++v3 == (char *)v4 )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int GetIndexOfLetterInPrefixTree(PrefixTree *pTree, char *s, int n)
{
    int c, ind = 0;
    for (int i = 0; i < n; i++)
    {
        c = s[i] - 'A';
        ((c >= 0) ? (void) (0) : __assert_fail ("c >= 0", "prefix_tree.c", 95, __extension__ __PRETTY_FUNCTION__));
        if (pTree->nodes[ind].children[c] >= 0)
            ind = pTree->nodes[ind].children[c];
        else
            return -1;
    }
    return pTree->nodes[ind].rank;
}

canonical_original_code:
int GetIndexOfLetterInPrefixTree(struct _prefixTree *pTree, char *s, int n)
{
    int c; int ind = 0;
    for (int i = 0; i < n; i++)
    {
        c = s[i] - 'A';
        ((c >= 0) ? (void) (0) : __assert_fail ("c >= 0", "prefix_tree.c", 95, __extension__ __PRETTY_FUNCTION__));
        if (pTree->nodes[ind].children[c] >= 0)
            ind = pTree->nodes[ind].children[c];
        else
            return -1;
    }
    return pTree->nodes[ind].rank;
}

variable_types:
s
char *

variable_types: n int

variable_types: c int

variable_types: ind int


repo: pllopis/libxenvchan

decompiled_code:
__int64 __fastcall do_send(__int64 a1, char *a2, unsigned __int64 a3)
{
_DWORD *v4; // r12
int v5; // eax
int v6; // er14
int v7; // eax
size_t v8; // r12
__int64 v9; // rax
_DWORD *v10; // rax
bool v11; // sf
__int64 result; // rax
void *v13; // rax

v4 = (_DWORD *)wr_prod(a1);
v5 = wr_ring_size(a1);
v6 = *v4 & (v5 - 1);
v7 = v5 - v6;
if ( v7 > a3 )
v7 = a3;
v8 = v7;
v9 = wr_ring(a1);
memcpy((void *)(v9 + v6), a2, v8);
if ( v8 < a3 )
{
v13 = (void *)wr_ring(a1);
memcpy(v13, &a2[v8], a3 - v8);
}
v10 = (_DWORD *)wr_prod(a1);
*v10 += a3;
v11 = do_notify(a1) < 0;
result = 0xFFFFFFFFLL;
if ( !v11 )
result = (unsigned int)a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char *a2, unsigned __int64 a3)
{
_DWORD *v4; // r12
int v5; // eax
int v6; // er14
int v7; // eax
size_t v8; // r12
__int64 v9; // rax
_DWORD *v10; // rax
bool v11; // sf
__int64 result; // rax
void *v13; // rax

v4 = (_DWORD *)func2(a1);
v5 = func6(a1);
v6 = *v4 & (v5 - 1);
v7 = v5 - v6;
if ( v7 > a3 )
v7 = a3;
v8 = v7;
v9 = func5(a1);
memcpy((void *)(v9 + v6), a2, v8);
if ( v8 < a3 )
{
v13 = (void *)func5(a1);
memcpy(v13, &a2[v8], a3 - v8);
}
v10 = (_DWORD *)func2(a1);
*v10 += a3;
v11 = func8(a1) < 0;
result = 0xFFFFFFFFLL;
if ( !v11 )
result = (unsigned int)a3;
return result;
}

original_code:
static int do_send(struct libvchan *ctrl, const void *data, size_t size)
{
   int real_idx = (*_wr_prod(ctrl)) & (wr_ring_size(ctrl) - 1);
   int avail_contig = wr_ring_size(ctrl) - real_idx;
   if (0) {
       char metainfo[32];
       struct iovec iov[2];
       iov[0].iov_base = metainfo;
       iov[0].iov_len = snprintf(metainfo, 32, "vchan wr %d/%d", ctrl->other_domain_id, ctrl->device_number);
       iov[1].iov_base = (void *)data;
       iov[1].iov_len = size;
       writev(-1, iov, 2);
   }
   if (avail_contig > size)
       avail_contig = size;
   memcpy(wr_ring(ctrl) + real_idx, data, avail_contig);
   if (avail_contig < size)
   {
       memcpy(wr_ring(ctrl), data + avail_contig, size - avail_contig);
   }
   asm volatile("" ::: "memory");
   (*_wr_prod(ctrl)) += size;
   asm volatile("" ::: "memory");
   if (do_notify(ctrl) < 0)
       return -1;
   return size;
}

canonical_original_code:
static int do_send(struct libvchan *ctrl, void *data, unsigned long size)
{
   int real_idx = (*_wr_prod(ctrl)) & (wr_ring_size(ctrl) - 1);
   int avail_contig = wr_ring_size(ctrl) - real_idx;
   if (0) {
       char metainfo[32];
       struct iovec iov[2];
       iov[0].iov_base = metainfo;
       iov[0].iov_len = snprintf(metainfo, 32, "vchan wr %d/%d", ctrl->other_domain_id, ctrl->device_number);
       iov[1].iov_base = (void *)data;
       iov[1].iov_len = size;
       writev(-1, iov, 2);
   }
   if (avail_contig > size)
       avail_contig = size;
   memcpy(wr_ring(ctrl) + real_idx, data, avail_contig);
   if (avail_contig < size)
   {
       memcpy(wr_ring(ctrl), data + avail_contig, size - avail_contig);
   }
   asm volatile("" ::: "memory");
   (*_wr_prod(ctrl)) += size;
   asm volatile("" ::: "memory");
   if (do_notify(ctrl) < 0)
       return -1;
   return size;
}

variable_types: struct libvchan { int other_domain_id; int device_number; struct vchan_interface { struct ring_shared { unsigned int cons; } left; unsigned short left_order; unsigned char cli_live; unsigned short debug; unsigned int grants[]; } *ring; int event_fd; unsigned int event_port; int is_server; int server_persist; int blocking; struct libvchan_ring { struct ring_shared *shr; void *buffer; int order; } read; } *

variable_types:
data
void *

variable_types:
size
unsigned long

variable_types:
metainfo
char [32]

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

return_type: int

user_defined_types: struct libvchan { int other_domain_id; int device_number; struct vchan_interface *ring; int event_fd; unsigned int event_port; int is_server; int server_persist; int blocking; struct libvchan_ring read; }

user_defined_types: struct vchan_interface { struct ring_shared left; unsigned short left_order; unsigned char cli_live; unsigned short debug; unsigned int grants[]; }


decompiled_code:
__int64 __fastcall do_recv(__int64 a1, char *a2, unsigned __int64 a3)
{
_DWORD *v4; // r12
int v5; // eax
int v6; // er14
int v7; // eax
size_t v8; // r12
__int64 v9; // rax
_DWORD *v10; // rax
bool v11; // sf
__int64 result; // rax
const void *v13; // rax

v4 = (_DWORD *)rd_cons(a1);
v5 = rd_ring_size(a1);
v6 = *v4 & (v5 - 1);
v7 = v5 - v6;
if ( v7 > a3 )
v7 = a3;
v8 = v7;
v9 = rd_ring(a1);
memcpy(a2, (const void *)(v9 + v6), v8);
if ( v8 < a3 )
{
v13 = (const void *)rd_ring(a1);
memcpy(&a2[v8], v13, a3 - v8);
}
v10 = (_DWORD *)rd_cons(a1);
*v10 += a3;
v11 = do_notify(a1) < 0;
result = 0xFFFFFFFFLL;
if ( !v11 )
result = (unsigned int)a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char *a2, unsigned __int64 a3)
{
_DWORD *v4; // r12
int v5; // eax
int v6; // er14
int v7; // eax
size_t v8; // r12
__int64 v9; // rax
_DWORD *v10; // rax
bool v11; // sf
__int64 result; // rax
const void *v13; // rax

v4 = (_DWORD *)func1(a1);
v5 = func7(a1);
v6 = *v4 & (v5 - 1);
v7 = v5 - v6;
if ( v7 > a3 )
v7 = a3;
v8 = v7;
v9 = func4(a1);
memcpy(a2, (const void *)(v9 + v6), v8);
if ( v8 < a3 )
{
v13 = (const void *)func4(a1);
memcpy(&a2[v8], v13, a3 - v8);
}
v10 = (_DWORD *)func1(a1);
*v10 += a3;
v11 = func8(a1) < 0;
result = 0xFFFFFFFFLL;
if ( !v11 )
result = (unsigned int)a3;
return result;
}

original_code:
static int do_recv(struct libvchan *ctrl, void *data, size_t size)
{
   int real_idx = (*_rd_cons(ctrl)) & (rd_ring_size(ctrl) - 1);
   int avail_contig = rd_ring_size(ctrl) - real_idx;
   if (avail_contig > size)
       avail_contig = size;
   asm volatile("" ::: "memory");
   memcpy(data, rd_ring(ctrl) + real_idx, avail_contig);
   if (avail_contig < size)
   {
       memcpy(data + avail_contig, rd_ring(ctrl), size - avail_contig);
   }
   (*_rd_cons(ctrl)) += size;
   if (0) {
       char metainfo[32];
       struct iovec iov[2];
       iov[0].iov_base = metainfo;
       iov[0].iov_len = snprintf(metainfo, 32, "vchan rd %d/%d", ctrl->other_domain_id, ctrl->device_number);
       iov[1].iov_base = data;
       iov[1].iov_len = size;
       writev(-1, iov, 2);
   }
   asm volatile("" ::: "memory");
   if (do_notify(ctrl) < 0)
       return -1;
   return size;
}

canonical_original_code:
static int do_recv(struct libvchan *ctrl, void *data, unsigned long size)
{
   int real_idx = (*_rd_cons(ctrl)) & (rd_ring_size(ctrl) - 1);
   int avail_contig = rd_ring_size(ctrl) - real_idx;
   if (avail_contig > size)
       avail_contig = size;
   asm volatile("" ::: "memory");
   memcpy(data, rd_ring(ctrl) + real_idx, avail_contig);
   if (avail_contig < size)
   {
       memcpy(data + avail_contig, rd_ring(ctrl), size - avail_contig);
   }
   (*_rd_cons(ctrl)) += size;
   if (0) {
       char metainfo[32];
       struct iovec iov[2];
       iov[0].iov_base = metainfo;
       iov[0].iov_len = snprintf(metainfo, 32, "vchan rd %d/%d", ctrl->other_domain_id, ctrl->device_number);
       iov[1].iov_base = data;
       iov[1].iov_len = size;
       writev(-1, iov, 2);
   }
   asm volatile("" ::: "memory");
   if (do_notify(ctrl) < 0)
       return -1;
   return size;
}

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }

user_defined_types: struct libvchan_ring { struct ring_shared *shr; void *buffer; int order; }

user_defined_types: struct ring_shared { unsigned int cons; }


decompiled_code:
__int64 __fastcall libvchan_data_ready(__int64 a1)
{
int v1; // ebx

v1 = rd_prod(a1);
return (unsigned int)(v1 - *(_DWORD *)rd_cons(a1));
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // ebx

v1 = func0(a1);
return (unsigned int)(v1 - *(_DWORD *)func1(a1));
}

original_code:
int libvchan_data_ready(struct libvchan *ctrl)
{
   return rd_prod(ctrl) - (*_rd_cons(ctrl));
}


decompiled_code:
__int64 __fastcall libvchan_buffer_space(__int64 a1)
{
int v1; // ebx
int v2; // er13

v1 = wr_ring_size(a1);
v2 = wr_cons(a1);
return (unsigned int)(v1 + v2 - *(_DWORD *)wr_prod(a1));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // ebx
int v2; // er13

v1 = func6(a1);
v2 = func3(a1);
return (unsigned int)(v1 + v2 - *(_DWORD *)func2(a1));
}

original_code:
int libvchan_buffer_space(struct libvchan *ctrl)
{
   return wr_ring_size(ctrl) - ((*_wr_prod(ctrl)) - wr_cons(ctrl));
}


decompiled_code:
__int64 __fastcall libvchan_wait(__int64 a1)
{
unsigned int v1; // edx
char buf[12]; // [rsp+Ch] [rbp-14h] BYREF

v1 = read(*(_DWORD *)(a1 + 16), buf, 4uLL);
if ( v1 != -1 )
{
write(*(_DWORD *)(a1 + 16), buf, 4uLL);
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
unsigned int v1; // edx
char buf[12]; // [rsp+Ch] [rbp-14h] BYREF

v1 = read(*(_DWORD *)(a1 + 16), buf, 4uLL);
if ( v1 != -1 )
{
write(*(_DWORD *)(a1 + 16), buf, 4uLL);
v1 = 0;
}
return v1;
}

original_code:
int libvchan_wait(struct libvchan *ctrl)
{
   int ret;
   uint32_t dummy;
   ret = read(ctrl->event_fd, &dummy, sizeof(dummy));
   if (ret == -1)
       return -1;
   write(ctrl->event_fd, &dummy, sizeof(dummy));
   return 0;
}

canonical_original_code:
int libvchan_wait(struct libvchan *ctrl)
{
   int ret;
   unsigned int dummy;
   ret = read(ctrl->event_fd, &dummy, sizeof(dummy));
   if (ret == -1)
       return -1;
   write(ctrl->event_fd, &dummy, sizeof(dummy));
   return 0;
}

variable_types: ret int

variable_types:
dummy
unsigned int


original_code:
int libvchan_is_open(struct libvchan* ctrl)
{
   if (ctrl->is_server)
       return ctrl->server_persist || ctrl->ring->cli_live;
   else
       return ctrl->ring->srv_live;
}

canonical_original_code:
int libvchan_is_open(struct libvchan *ctrl)
{
   if (ctrl->is_server)
       return ctrl->server_persist || ctrl->ring->cli_live;
   else
       return ctrl->ring->srv_live;
}


decompiled_code:
__int64 __fastcall libvchan_send(__int64 a1, char *a2, unsigned __int64 a3)
{
while ( 1 )
{
if ( !(unsigned int)libvchan_is_open(a1) )
return 0xFFFFFFFFLL;
if ( (int)libvchan_buffer_space(a1) >= a3 )
return do_send(a1, a2, a3);
if ( (*(_BYTE *)(a1 + 24) & 4) == 0 )
return 0LL;
if ( (unsigned int)wr_ring_size(a1) < a3 )
break;
if ( (unsigned int)libvchan_wait(a1) )
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, char *a2, unsigned __int64 a3)
{
while ( 1 )
{
if ( !(unsigned int)func14(a1) )
return 0xFFFFFFFFLL;
if ( (int)func12(a1) >= a3 )
return func9(a1, a2, a3);
if ( (*(_BYTE *)(a1 + 24) & 4) == 0 )
return 0LL;
if ( (unsigned int)func6(a1) < a3 )
break;
if ( (unsigned int)func13(a1) )
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}

original_code:
int libvchan_send(struct libvchan *ctrl, const void *data, size_t size)
{
   int avail;
   while (1) {
       if (!libvchan_is_open(ctrl))
           return -1;
       avail = libvchan_buffer_space(ctrl);
       if (size <= avail)
           return do_send(ctrl, data, size);
       if (!ctrl->blocking)
           return 0;
       if (size > wr_ring_size(ctrl))
           return -1;
       if (libvchan_wait(ctrl))
           return -1;
   }
}

canonical_original_code:
int libvchan_send(struct libvchan *ctrl, void *data, unsigned long size)
{
   int avail;
   while (1) {
       if (!libvchan_is_open(ctrl))
           return -1;
       avail = libvchan_buffer_space(ctrl);
       if (size <= avail)
           return do_send(ctrl, data, size);
       if (!ctrl->blocking)
           return 0;
       if (size > wr_ring_size(ctrl))
           return -1;
       if (libvchan_wait(ctrl))
           return -1;
   }
}

variable_types: avail int


decompiled_code:
__int64 __fastcall libvchan_write(__int64 a1, char *a2, unsigned __int64 a3)
{
__int64 v4; // rbx
int v5; // eax
__int64 result; // rax
int v7; // eax
unsigned __int64 v8; // rdx

if ( !(unsigned int)libvchan_is_open(a1) )
return 0xFFFFFFFFLL;
if ( (*(_BYTE *)(a1 + 24) & 4) != 0 )
{
v4 = 0LL;
do
{
v5 = libvchan_buffer_space(a1);
if ( v4 + v5 > a3 )
v5 = a3 - v4;
if ( v5 )
v4 += (int)do_send(a1, &a2[v4], v5);
if ( v4 == a3 )
return (unsigned int)a3;
if ( (unsigned int)libvchan_wait(a1) )
return 0xFFFFFFFFLL;
}
while ( (unsigned int)libvchan_is_open(a1) );
result = 0xFFFFFFFFLL;
}
else
{
v7 = libvchan_buffer_space(a1);
v8 = a3;
if ( v7 <= a3 )
v8 = v7;
result = 0LL;
if ( v8 )
result = do_send(a1, a2, v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char *a2, unsigned __int64 a3)
{
__int64 v4; // rbx
int v5; // eax
__int64 result; // rax
int v7; // eax
unsigned __int64 v8; // rdx

if ( !(unsigned int)func14(a1) )
return 0xFFFFFFFFLL;
if ( (*(_BYTE *)(a1 + 24) & 4) != 0 )
{
v4 = 0LL;
do
{
v5 = func12(a1);
if ( v4 + v5 > a3 )
v5 = a3 - v4;
if ( v5 )
v4 += (int)func9(a1, &a2[v4], v5);
if ( v4 == a3 )
return (unsigned int)a3;
if ( (unsigned int)func13(a1) )
return 0xFFFFFFFFLL;
}
while ( (unsigned int)func14(a1) );
result = 0xFFFFFFFFLL;
}
else
{
v7 = func12(a1);
v8 = a3;
if ( v7 <= a3 )
v8 = v7;
result = 0LL;
if ( v8 )
result = func9(a1, a2, v8);
}
return result;
}

original_code:
int libvchan_write(struct libvchan *ctrl, const void *data, size_t size)
{
   int avail;
   if (!libvchan_is_open(ctrl))
       return -1;
   if (ctrl->blocking) {
       size_t pos = 0;
       while (1) {
           avail = libvchan_buffer_space(ctrl);
           if (pos + avail > size)
               avail = size - pos;
           if (avail)
               pos += do_send(ctrl, data + pos, avail);
           if (pos == size)
               return pos;
           if (libvchan_wait(ctrl))
               return -1;
           if (!libvchan_is_open(ctrl))
               return -1;
       }
   } else {
       avail = libvchan_buffer_space(ctrl);
       if (size > avail)
           size = avail;
       if (size == 0)
           return 0;
       return do_send(ctrl, data, size);
   }
}

canonical_original_code:
int libvchan_write(struct libvchan *ctrl, void *data, unsigned long size)
{
   int avail;
   if (!libvchan_is_open(ctrl))
       return -1;
   if (ctrl->blocking) {
       unsigned long pos = 0;
       while (1) {
           avail = libvchan_buffer_space(ctrl);
           if (pos + avail > size)
               avail = size - pos;
           if (avail)
               pos += do_send(ctrl, data + pos, avail);
           if (pos == size)
               return pos;
           if (libvchan_wait(ctrl))
               return -1;
           if (!libvchan_is_open(ctrl))
               return -1;
       }
   } else {
       avail = libvchan_buffer_space(ctrl);
       if (size > avail)
           size = avail;
       if (size == 0)
           return 0;
       return do_send(ctrl, data, size);
   }
}

variable_types:
pos
unsigned long


decompiled_code:
__int64 __fastcall libvchan_recv(__int64 a1, char *a2, unsigned __int64 a3)
{
while ( 1 )
{
if ( (int)libvchan_data_ready(a1) >= a3 )
return do_recv(a1, a2, a3);
if ( !(unsigned int)libvchan_is_open(a1) )
return 0xFFFFFFFFLL;
if ( (*(_BYTE *)(a1 + 24) & 4) == 0 )
return 0LL;
if ( (unsigned int)rd_ring_size(a1) < a3 )
break;
if ( (unsigned int)libvchan_wait(a1) )
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, char *a2, unsigned __int64 a3)
{
while ( 1 )
{
if ( (int)func11(a1) >= a3 )
return func10(a1, a2, a3);
if ( !(unsigned int)func14(a1) )
return 0xFFFFFFFFLL;
if ( (*(_BYTE *)(a1 + 24) & 4) == 0 )
return 0LL;
if ( (unsigned int)func7(a1) < a3 )
break;
if ( (unsigned int)func13(a1) )
return 0xFFFFFFFFLL;
}
return 0xFFFFFFFFLL;
}

original_code:
int libvchan_recv(struct libvchan *ctrl, void *data, size_t size)
{
   while (1) {
       int avail = libvchan_data_ready(ctrl);
       if (size <= avail)
           return do_recv(ctrl, data, size);
       if (!libvchan_is_open(ctrl))
           return -1;
       if (!ctrl->blocking)
           return 0;
       if (size > rd_ring_size(ctrl))
           return -1;
       if (libvchan_wait(ctrl))
           return -1;
   }
}

canonical_original_code:
int libvchan_recv(struct libvchan *ctrl, void *data, unsigned long size)
{
   while (1) {
       int avail = libvchan_data_ready(ctrl);
       if (size <= avail)
           return do_recv(ctrl, data, size);
       if (!libvchan_is_open(ctrl))
           return -1;
       if (!ctrl->blocking)
           return 0;
       if (size > rd_ring_size(ctrl))
           return -1;
       if (libvchan_wait(ctrl))
           return -1;
   }
}


decompiled_code:
__int64 __fastcall libvchan_read(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned int v4; // ebx
int v5; // eax
unsigned __int64 v6; // rdx

while ( 1 )
{
v5 = libvchan_data_ready(a1);
v4 = v5;
if ( v5 )
break;
if ( !(unsigned int)libvchan_is_open(a1) )
return (unsigned int)-1;
if ( (*(_BYTE *)(a1 + 24) & 4) == 0 )
return v4;
if ( (unsigned int)libvchan_wait(a1) )
return (unsigned int)-1;
}
v6 = a3;
if ( v5 <= a3 )
v6 = v5;
return (unsigned int)do_recv(a1, a2, v6);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned int v4; // ebx
int v5; // eax
unsigned __int64 v6; // rdx

while ( 1 )
{
v5 = func11(a1);
v4 = v5;
if ( v5 )
break;
if ( !(unsigned int)func14(a1) )
return (unsigned int)-1;
if ( (*(_BYTE *)(a1 + 24) & 4) == 0 )
return v4;
if ( (unsigned int)func13(a1) )
return (unsigned int)-1;
}
v6 = a3;
if ( v5 <= a3 )
v6 = v5;
return (unsigned int)func10(a1, a2, v6);
}

original_code:
int libvchan_read(struct libvchan *ctrl, void *data, size_t size)
{
   while (1) {
       int avail = libvchan_data_ready(ctrl);
       if (avail && size > avail)
           size = avail;
       if (avail)
           return do_recv(ctrl, data, size);
       if (!libvchan_is_open(ctrl))
           return -1;
       if (!ctrl->blocking)
           return 0;
       if (libvchan_wait(ctrl))
           return -1;
   }
}

canonical_original_code:
int libvchan_read(struct libvchan *ctrl, void *data, unsigned long size)
{
   while (1) {
       int avail = libvchan_data_ready(ctrl);
       if (avail && size > avail)
           size = avail;
       if (avail)
           return do_recv(ctrl, data, size);
       if (!libvchan_is_open(ctrl))
           return -1;
       if (!ctrl->blocking)
           return 0;
       if (libvchan_wait(ctrl))
           return -1;
   }
}


decompiled_code:
__int64 __fastcall libvchan_fd_for_select(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int libvchan_fd_for_select(struct libvchan *ctrl)
{
   return ctrl->event_fd;
}


original_code:
void libvchan_close(struct libvchan *ctrl)
{
   if (!ctrl)
       return;
   if (ctrl->ring) {
       if (ctrl->is_server)
           ctrl->ring->srv_live = 0;
       else
           ctrl->ring->cli_live = 0;
       munmap(ctrl->ring, 4096);
   }
   if (ctrl->event_fd != -1) {
       if (ctrl->event_port > 0 && ctrl->ring)
           do_notify(ctrl);
       close(ctrl->event_fd);
   }
   if (ctrl->read.order >= 12)
       munmap(ctrl->read.buffer, 1 << ctrl->read.order);
   if (ctrl->write.order >= 12)
       munmap(ctrl->write.buffer, 1 << ctrl->write.order);
   free(ctrl);
}

return_type: void


main

canonical_name: main

repo: plumbum/easyface

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int i; // er12
int v4; // ebp
unsigned __int16 *v5; // rbx
size_t v6; // rax
size_t v7; // rax
char v8[270]; // [rsp+0h] [rbp-1C8h] BYREF
unsigned __int16 v9; // [rsp+10Eh] [rbp-BAh] BYREF
__int16 v10[16]; // [rsp+110h] [rbp-B8h] BYREF
char v11[152]; // [rsp+130h] [rbp-98h] BYREF

modbus_init_rtu(v11, "/dev/ttyUSB1", 19200LL, "none", 8LL, 1LL);
modbus_set_debug(v11, 0LL);
if ( (unsigned int)modbus_connect(v11) != -1 )
{
memset(malloc(5uLL), 0, 5uLL);
memset(malloc(5uLL), 0, 5uLL);
memset(malloc(0xAuLL), 0, 0xAuLL);
memset(malloc(0xAuLL), 0, 0xAuLL);
for ( i = 0; ; ++i )
{
v9 = 0;
read_input_registers(v11, 1LL, 0x4000LL, 1LL, &v9);
usleep(0x4E20u);
if ( v9 )
{
read_input_registers(v11, 1LL, 16385LL, v9, v10);
usleep(0x4E20u);
printf("Scancode (%d):", v9);
if ( v9 )
{
v5 = (unsigned __int16 *)v10;
v4 = 0;
do
{
if ( *v5 != 0xFFFF )
{
printf(" 0x%02x", *v5);
sprintf(v8, "[0x%02x]", *v5);
v6 = strlen(v8);
preset_multiple_registers(v11, 1LL, 385LL, (unsigned int)(v6 >> 1) + 1, v8);
usleep(0x4E20u);
}
++v4;
++v5;
}
while ( v9 > v4 );
}
printf("\r\n");
}
sprintf(v8, "(%d)", i);
v7 = strlen(v8);
preset_multiple_registers(v11, 1LL, 257LL, (unsigned int)(v7 >> 1) + 1, v8);
usleep(0x4E20u);
}
}
puts("ERROR Connection failed");
exit(1);
}

original_code:
int main(void)
{
        int ret;
        int nb_fail;
        int nb_loop;
        int addr;
        int nb;
        uint8_t *tab_rq_status;
        uint8_t *tab_rp_status;
        uint16_t *tab_rq_registers;
        uint16_t *tab_rp_registers;
        modbus_param_t mb_param;
        modbus_init_rtu(&mb_param, "/dev/ttyUSB1", 19200, "none", 8, 1);
        modbus_set_debug(&mb_param, 0);
        if (modbus_connect(&mb_param) == -1) {
                printf("ERROR Connection failed\n");
                exit(1);
        }
        nb = 0x16 - 0x11;
        tab_rq_status = (uint8_t *) malloc(nb * sizeof(uint8_t));
        memset(tab_rq_status, 0, nb * sizeof(uint8_t));
        tab_rp_status = (uint8_t *) malloc(nb * sizeof(uint8_t));
        memset(tab_rp_status, 0, nb * sizeof(uint8_t));
        tab_rq_registers = (uint16_t *) malloc(nb * sizeof(uint16_t));
        memset(tab_rq_registers, 0, nb * sizeof(uint16_t));
        tab_rp_registers = (uint16_t *) malloc(nb * sizeof(uint16_t));
        memset(tab_rp_registers, 0, nb * sizeof(uint16_t));
        uint16_t readed[16];
        uint16_t scan_cnt;
        char message[256];
        int cnt = 0;
        while(1)
        {
            scan_cnt = 0;
            ret = read_input_registers(&mb_param, 0x01, 0x4000, 1, &scan_cnt);
            usleep(20000);
            if(scan_cnt > 0)
            {
                ret = read_input_registers(&mb_param, 0x01, 0x4001, scan_cnt, readed);
                usleep(20000);
                int i;
                printf("Scancode (%d):", scan_cnt);
                for(i=0; i<scan_cnt; i++)
                {
                    if(readed[i] != 0xFFFF)
                    {
                        printf(" 0x%02x", readed[i]);
                        sprintf(message, "[0x%02x]", readed[i]);
                        ret = preset_multiple_registers(&mb_param, 0x01,
                                                        3<<7 | 1, strlen(message)/2+1, message);
                        usleep(20000);
                    }
                }
                printf("\r\n", readed[i]);
            }
            sprintf(message, "(%d)", cnt++);
            ret = preset_multiple_registers(&mb_param, 0x01,
                                            2<<7 | 1, strlen(message)/2+1, message);
            usleep(20000);
        }
        return 0;
        free(tab_rq_status);
        free(tab_rp_status);
        free(tab_rq_registers);
        free(tab_rp_registers);
        modbus_close(&mb_param);
        return 0;
}

canonical_original_code:
int main()
{
        int ret;
        int nb_fail;
        int nb_loop;
        int addr;
        int nb;
        unsigned char *tab_rq_status;
        unsigned char *tab_rp_status;
        unsigned short *tab_rq_registers;
        unsigned short *tab_rp_registers;
        struct modbus_param_t mb_param;
        modbus_init_rtu(&mb_param, "/dev/ttyUSB1", 19200, "none", 8, 1);
        modbus_set_debug(&mb_param, 0);
        if (modbus_connect(&mb_param) == -1) {
                printf("ERROR Connection failed\n");
                exit(1);
        }
        nb = 0x16 - 0x11;
        tab_rq_status = (unsigned char *) malloc(nb * sizeof(unsigned char));
        memset(tab_rq_status, 0, nb * sizeof(unsigned char));
        tab_rp_status = (unsigned char *) malloc(nb * sizeof(unsigned char));
        memset(tab_rp_status, 0, nb * sizeof(unsigned char));
        tab_rq_registers = (unsigned short *) malloc(nb * sizeof(unsigned short));
        memset(tab_rq_registers, 0, nb * sizeof(unsigned short));
        tab_rp_registers = (unsigned short *) malloc(nb * sizeof(unsigned short));
        memset(tab_rp_registers, 0, nb * sizeof(unsigned short));
        unsigned short readed[16];
        unsigned short scan_cnt;
        char message[256];
        int cnt = 0;
        while(1)
        {
            scan_cnt = 0;
            ret = read_input_registers(&mb_param, 0x01, 0x4000, 1, &scan_cnt);
            usleep(20000);
            if(scan_cnt > 0)
            {
                ret = read_input_registers(&mb_param, 0x01, 0x4001, scan_cnt, readed);
                usleep(20000);
                int i;
                printf("Scancode (%d):", scan_cnt);
                for(i=0; i<scan_cnt; i++)
                {
                    if(readed[i] != 0xFFFF)
                    {
                        printf(" 0x%02x", readed[i]);
                        sprintf(message, "[0x%02x]", readed[i]);
                        ret = preset_multiple_registers(&mb_param, 0x01,
                                                        3<<7 | 1, strlen(message)/2+1, message);
                        usleep(20000);
                    }
                }
                printf("\r\n", readed[i]);
            }
            sprintf(message, "(%d)", cnt++);
            ret = preset_multiple_registers(&mb_param, 0x01,
                                            2<<7 | 1, strlen(message)/2+1, message);
            usleep(20000);
        }
        return 0;
        free(tab_rq_status);
        free(tab_rp_status);
        free(tab_rq_registers);
        free(tab_rp_registers);
        modbus_close(&mb_param);
        return 0;
}

variable_types: addr int

variable_types: nb int

variable_types: struct modbus_param_t { int fd; enum type_com_t { RTU=0, TCP=1 } type_com; int debug; int header_length; int checksum_length; int port; char device[16]; int baud; unsigned char data_bit; unsigned char stop_bit; char parity[5]; unsigned char error_handling; char ip[16]; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } old_tios; }

variable_types:
readed
unsigned short [16]

variable_types:
message
char [256]

variable_types: cnt int

variable_types: i int

user_defined_types: struct modbus_param_t { int fd; enum type_com_t type_com; int debug; int header_length; int checksum_length; int port; char device[16]; int baud; unsigned char data_bit; unsigned char stop_bit; char parity[5]; unsigned char error_handling; char ip[16]; struct termios old_tios; }


repo: pmeinhardt/libgopro

decompiled_code:
__int64 __fastcall gopro_camera_receive(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx

v4 = a3 * a2;
if ( (unsigned int)vbuffer_append(a4, a1, a3 * a2) )
v4 = 0LL;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx

v4 = a3 * a2;
if ( (unsigned int)vbuffer_append(a4, a1, a3 * a2) )
v4 = 0LL;
return v4;
}

original_code:
size_t gopro_camera_receive(char *data, size_t size, size_t n, void *context) {
  vbuffer *buffer = (vbuffer *)context;
  int err = vbuffer_append(buffer, data, size * n);
  return (err == 0) ? size * n : 0;
}

canonical_original_code:
unsigned long gopro_camera_receive(char *data, unsigned long size, unsigned long n, void *context) {
  struct vbuffer *buffer = (vbuffer *)context;
  int err = vbuffer_append(buffer, data, size * n);
  return (err == 0) ? size * n : 0;
}

variable_types:
data
char *

variable_types:
n
unsigned long

variable_types:
context
void *

variable_types: struct vbuffer { void *data; unsigned long capacity; unsigned long length; } *

variable_types: err int

return_type: unsigned long


decompiled_code:
void __fastcall gopro_camera_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( !ptr )
_assert_fail("cam", "src/camera.c", 0x37u, "gopro_camera_free");
if ( *((_QWORD *)ptr + 2) )
gopro_client_free();
v2 = *(void **)ptr;
if ( *(_QWORD *)ptr )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( !ptr )
_assert_fail("cam", "src/camera.c", 0x37u, "gopro_camera_free");
if ( *((_QWORD *)ptr + 2) )
gopro_client_free();
v2 = *(void **)ptr;
if ( *(_QWORD *)ptr )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void gopro_camera_free(gopro_camera *cam) {
  ((void) sizeof ((cam) ? 1 : 0), __extension__ ({ if (cam) ; else __assert_fail ("cam", "src/camera.c", 55, __extension__ __PRETTY_FUNCTION__); }));
  if (cam->client != ((void *)0)) gopro_client_free(cam->client);
  if (cam->ipaddr != ((void *)0)) free(cam->ipaddr);
  if (cam->password != ((void *)0)) free(cam->password);
  free(cam);
}

canonical_original_code:
void gopro_camera_free(struct gopro_camera *cam) {
  ((void) sizeof ((cam) ? 1 : 0), __extension__ ({ if (cam) ; else __assert_fail ("cam", "src/camera.c", 55, __extension__ __PRETTY_FUNCTION__); }));
  if (cam->client != ((void *)0)) gopro_client_free(cam->client);
  if (cam->ipaddr != ((void *)0)) free(cam->ipaddr);
  if (cam->password != ((void *)0)) free(cam->password);
  free(cam);
}

variable_types: struct gopro_camera { char *ipaddr; char *password; void *client; } *


decompiled_code:
void __fastcall gopro_camera_free_url(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
free(a1);
}

original_code:
void gopro_camera_free_url(char *url) {
  free(url);
}

variable_types:
url
char *


decompiled_code:
char *__fastcall gopro_camera_build_url(const char **a1, const char *a2)
{
const char *v2; // r13
const char *v3; // r12
int v4; // er14
int v5; // ebx
int v6; // eax
char *v7; // rbx

v2 = *a1;
v3 = a1[1];
v4 = strlen(*a1);
v5 = strlen(a2);
v6 = strlen(v3);
v7 = (char *)malloc(v6 + v4 + v5 + 19);
*v7 = 0;
*(_QWORD *)&v7[strlen(v7)] = 0x2F2F3A70747468LL;
strcat(v7, v2);
strcat(v7, "/camera/");
strcat(v7, a2);
*(_DWORD *)&v7[strlen(v7)] = 4027455;
return strcat(v7, v3);
}

canonical_decompiled_code:
char *__fastcall func3(const char **a1, const char *a2)
{
const char *v2; // r13
const char *v3; // r12
int v4; // er14
int v5; // ebx
int v6; // eax
char *v7; // rbx

v2 = *a1;
v3 = a1[1];
v4 = strlen(*a1);
v5 = strlen(a2);
v6 = strlen(v3);
v7 = (char *)malloc(v6 + v4 + v5 + 19);
*v7 = 0;
*(_QWORD *)&v7[strlen(v7)] = 0x2F2F3A70747468LL;
strcat(v7, v2);
strcat(v7, "/camera/");
strcat(v7, a2);
*(_DWORD *)&v7[strlen(v7)] = 4027455;
return strcat(v7, v3);
}

original_code:
char *gopro_camera_build_url(gopro_camera *cam, char *action) {
  char *host = cam->ipaddr;
  char *pass = cam->password;
  int buflen = strlen(host) + strlen(action) + strlen(pass) + 19;
  char *url = (char *)malloc(buflen);
  url[0] = '\0';
  strcat(url, "http://");
  strcat(url, host);
  strcat(url, "/camera/");
  strcat(url, action);
  strcat(url, "?t=");
  strcat(url, pass);
  return url;
}

canonical_original_code:
char *gopro_camera_build_url(struct gopro_camera *cam, char *action) {
  char *host = cam->ipaddr;
  char *pass = cam->password;
  int buflen = strlen(host) + strlen(action) + strlen(pass) + 19;
  char *url = (char *)malloc(buflen);
  url[0] = '\0';
  strcat(url, "http://");
  strcat(url, host);
  strcat(url, "/camera/");
  strcat(url, action);
  strcat(url, "?t=");
  strcat(url, pass);
  return url;
}

variable_types:
action
char *

variable_types:
host
char *

variable_types:
pass
char *

variable_types: buflen int

return_type: char *

user_defined_types: struct gopro_camera { char *ipaddr; char *password; void *client; }


decompiled_code:
char *__fastcall gopro_camera_build_param_url(const char **a1, const char *a2, char a3)
{
char *v4; // rbp
int v5; // eax
char *v6; // rbx
const char *v7; // rbp
char v9[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v4 = gopro_camera_build_url(a1, a2);
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 6);
*v6 = 0;
strcat(v6, v4);
gopro_camera_free_url(v4);
v9[0] = a3;
v9[1] = 0;
v7 = (const char *)curl_easy_escape(0LL, v9, 1LL);
*(_DWORD *)&v6[strlen(v6)] = 4026406;
strcat(v6, v7);
curl_free(v7);
return v6;
}

canonical_decompiled_code:
char *__fastcall func4(const char **a1, const char *a2, char a3)
{
char *v4; // rbp
int v5; // eax
char *v6; // rbx
const char *v7; // rbp
char v9[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v4 = func3(a1, a2);
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 6);
*v6 = 0;
strcat(v6, v4);
func2(v4);
v9[0] = a3;
v9[1] = 0;
v7 = (const char *)curl_easy_escape(0LL, v9, 1LL);
*(_DWORD *)&v6[strlen(v6)] = 4026406;
strcat(v6, v7);
curl_free(v7);
return v6;
}

original_code:
char *gopro_camera_build_param_url(gopro_camera *cam, char *action, char par) {
  char *base = gopro_camera_build_url(cam, action);
  int buflen = strlen(base) + 6;
  char *url = (char *)malloc(buflen);
  url[0] = '\0';
  strcat(url, base);
  gopro_camera_free_url(base);
  char pstr[2];
  pstr[0] = par;
  pstr[1] = '\0';
  char *penc = curl_easy_escape(((void *)0), pstr, 1);
  strcat(url, "&p=");
  strcat(url, penc);
  curl_free(penc);
  return url;
}

canonical_original_code:
char *gopro_camera_build_param_url(struct gopro_camera *cam, char *action, char par) {
  char *base = gopro_camera_build_url(cam, action);
  int buflen = strlen(base) + 6;
  char *url = (char *)malloc(buflen);
  url[0] = '\0';
  strcat(url, base);
  gopro_camera_free_url(base);
  char pstr[2];
  pstr[0] = par;
  pstr[1] = '\0';
  char *penc = curl_easy_escape(((void *)0), pstr, 1);
  strcat(url, "&p=");
  strcat(url, penc);
  curl_free(penc);
  return url;
}

variable_types: par char

variable_types:
base
char *

variable_types:
pstr
char [2]

variable_types:
penc
char *


decompiled_code:
__int64 __fastcall gopro_camera_send(__int64 a1, const char *a2)
{
char *v2; // rbp
unsigned int v3; // ebx

if ( !a2 )
_assert_fail("action", "src/camera.c", 0x72u, "gopro_camera_send");
if ( !a1 )
_assert_fail("cam", "src/camera.c", 0x73u, "gopro_camera_send");
v2 = gopro_camera_build_url((const char **)a1, a2);
v3 = gopro_client_get(*(_QWORD *)(a1 + 16), v2, 0LL, 0LL);
gopro_camera_free_url(v2);
return v3;
}

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

if ( !a2 )
_assert_fail("action", "src/camera.c", 0x72u, "gopro_camera_send");
if ( !a1 )
_assert_fail("cam", "src/camera.c", 0x73u, "gopro_camera_send");
v2 = func3((const char **)a1, a2);
v3 = gopro_client_get(*(_QWORD *)(a1 + 16), v2, 0LL, 0LL);
func2(v2);
return v3;
}

original_code:
int gopro_camera_send(gopro_camera *cam, char *action) {
  ((void) sizeof ((action) ? 1 : 0), __extension__ ({ if (action) ; else __assert_fail ("action", "src/camera.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((cam) ? 1 : 0), __extension__ ({ if (cam) ; else __assert_fail ("cam", "src/camera.c", 115, __extension__ __PRETTY_FUNCTION__); }));
  char *url = gopro_camera_build_url(cam, action);
  int code = gopro_client_get((gopro_client *)(cam->client), url, ((void *)0), ((void *)0));
  gopro_camera_free_url(url);
  return code;
}

canonical_original_code:
int gopro_camera_send(struct gopro_camera *cam, char *action) {
  ((void) sizeof ((action) ? 1 : 0), __extension__ ({ if (action) ; else __assert_fail ("action", "src/camera.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((cam) ? 1 : 0), __extension__ ({ if (cam) ; else __assert_fail ("cam", "src/camera.c", 115, __extension__ __PRETTY_FUNCTION__); }));
  char *url = gopro_camera_build_url(cam, action);
  int code = gopro_client_get((gopro_client *)(cam->client), url, ((void *)0), ((void *)0));
  gopro_camera_free_url(url);
  return code;
}

variable_types: code int


decompiled_code:
__int64 __fastcall gopro_camera_send_param(__int64 a1, const char *a2, char a3)
{
char *v3; // rbp
unsigned int v4; // ebx

if ( !a2 )
_assert_fail("action", "src/camera.c", 0x7Du, "gopro_camera_send_param");
if ( !a1 )
_assert_fail("cam", "src/camera.c", 0x7Eu, "gopro_camera_send_param");
v3 = gopro_camera_build_param_url((const char **)a1, a2, a3);
v4 = gopro_client_get(*(_QWORD *)(a1 + 16), v3, 0LL, 0LL);
gopro_camera_free_url(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, char a3)
{
char *v3; // rbp
unsigned int v4; // ebx

if ( !a2 )
_assert_fail("action", "src/camera.c", 0x7Du, "gopro_camera_send_param");
if ( !a1 )
_assert_fail("cam", "src/camera.c", 0x7Eu, "gopro_camera_send_param");
v3 = func4((const char **)a1, a2, a3);
v4 = gopro_client_get(*(_QWORD *)(a1 + 16), v3, 0LL, 0LL);
func2(v3);
return v4;
}

original_code:
int gopro_camera_send_param(gopro_camera *cam, char *action, int param) {
  ((void) sizeof ((action) ? 1 : 0), __extension__ ({ if (action) ; else __assert_fail ("action", "src/camera.c", 125, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((cam) ? 1 : 0), __extension__ ({ if (cam) ; else __assert_fail ("cam", "src/camera.c", 126, __extension__ __PRETTY_FUNCTION__); }));
  char *url = gopro_camera_build_param_url(cam, action, param);
  int code = gopro_client_get((gopro_client *)(cam->client), url, ((void *)0), ((void *)0));
  gopro_camera_free_url(url);
  return code;
}

canonical_original_code:
int gopro_camera_send_param(struct gopro_camera *cam, char *action, int param) {
  ((void) sizeof ((action) ? 1 : 0), __extension__ ({ if (action) ; else __assert_fail ("action", "src/camera.c", 125, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((cam) ? 1 : 0), __extension__ ({ if (cam) ; else __assert_fail ("cam", "src/camera.c", 126, __extension__ __PRETTY_FUNCTION__); }));
  char *url = gopro_camera_build_param_url(cam, action, param);
  int code = gopro_client_get((gopro_client *)(cam->client), url, ((void *)0), ((void *)0));
  gopro_camera_free_url(url);
  return code;
}

variable_types: param int


decompiled_code:
__int64 __fastcall gopro_camera_get_status(__int64 a1, _DWORD *a2)
{
__int64 v2; // r14
__int64 v3; // rbx
char *v4; // r12
unsigned int v5; // ebp

v2 = *(_QWORD *)(a1 + 16);
v3 = vbuffer_create(32LL);
v4 = gopro_camera_build_url((const char **)a1, "se");
if ( (unsigned int)gopro_client_get(v2, v4, v3, gopro_camera_receive) )
{
gopro_camera_free_url(v4);
vbuffer_free(v3);
v5 = 1;
}
else
{
v5 = 0;
if ( *(_QWORD *)(v3 + 16) <= 0x1EuLL )
_assert_fail("buffer->length >= 31", "src/camera.c", 0xA2u, "gopro_camera_get_status");
gopro_status_parse(a2, *(char **)v3);
gopro_camera_free_url(v4);
vbuffer_free(v3);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _DWORD *a2)
{
__int64 v2; // r14
__int64 v3; // rbx
char *v4; // r12
unsigned int v5; // ebp

v2 = *(_QWORD *)(a1 + 16);
v3 = vbuffer_create(32LL);
v4 = func3((const char **)a1, "se");
if ( (unsigned int)gopro_client_get(v2, v4, v3, gopro_camera_receive) )
{
func2(v4);
vbuffer_free(v3);
v5 = 1;
}
else
{
v5 = 0;
if ( *(_QWORD *)(v3 + 16) <= 0x1EuLL )
_assert_fail("buffer->length >= 31", "src/camera.c", 0xA2u, "gopro_camera_get_status");
func7(a2, *(char **)v3);
func2(v4);
vbuffer_free(v3);
}
return v5;
}

original_code:
int gopro_camera_get_status(gopro_camera *cam, gopro_status *status) {
  gopro_client_cb *callback = (gopro_client_cb *)gopro_camera_receive;
  gopro_client *client = (gopro_client *)(cam->client);
  vbuffer *buffer = vbuffer_create(32);
  char *url = gopro_camera_build_url(cam, "se");
  int err = gopro_client_get(client, url, buffer, callback);
  if (err != 0) {
    gopro_camera_free_url(url);
    vbuffer_free(buffer);
    return 1;
  }
  ((void) sizeof ((buffer->length >= 31) ? 1 : 0), __extension__ ({ if (buffer->length >= 31) ; else __assert_fail ("buffer->length >= 31", "src/camera.c", 162, __extension__ __PRETTY_FUNCTION__); }));
  gopro_status_parse(status, buffer->data);
  gopro_camera_free_url(url);
  vbuffer_free(buffer);
  return 0;
}

canonical_original_code:
int gopro_camera_get_status(struct gopro_camera *cam, struct gopro_status *status) {
  unsigned long (**callback)(char *, unsigned long, unsigned long, void *) = (gopro_client_cb *)gopro_camera_receive;
  struct gopro_client *client = (gopro_client *)(cam->client);
  struct vbuffer *buffer = vbuffer_create(32);
  char *url = gopro_camera_build_url(cam, "se");
  int err = gopro_client_get(client, url, buffer, callback);
  if (err != 0) {
    gopro_camera_free_url(url);
    vbuffer_free(buffer);
    return 1;
  }
  ((void) sizeof ((buffer->length >= 31) ? 1 : 0), __extension__ ({ if (buffer->length >= 31) ; else __assert_fail ("buffer->length >= 31", "src/camera.c", 162, __extension__ __PRETTY_FUNCTION__); }));
  gopro_status_parse(status, buffer->data);
  gopro_camera_free_url(url);
  vbuffer_free(buffer);
  return 0;
}

variable_types: struct gopro_status { int photo_count; int video_count; } *

variable_types: unsigned long (**)(char *, unsigned long, unsigned long, void *)

variable_types:
client
struct gopro_client { void *curl; } *

user_defined_types: struct vbuffer { void *data; unsigned long capacity; unsigned long length; }


decompiled_code:
__int64 __fastcall gopro_camera_start_capture(__int64 a1)
{
return gopro_camera_send_param(a1, "SH", 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func6(a1, "SH", 1);
}

original_code:
int gopro_camera_start_capture(gopro_camera *cam) {
  return gopro_camera_send_param(cam, "SH", 1);
}

canonical_original_code:
int gopro_camera_start_capture(struct gopro_camera *cam) {
  return gopro_camera_send_param(cam, "SH", 1);
}


decompiled_code:
__int64 __fastcall gopro_camera_stop_capture(__int64 a1)
{
return gopro_camera_send_param(a1, "SH", 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func6(a1, "SH", 0);
}

original_code:
int gopro_camera_stop_capture(gopro_camera *cam) {
  return gopro_camera_send_param(cam, "SH", 0);
}

canonical_original_code:
int gopro_camera_stop_capture(struct gopro_camera *cam) {
  return gopro_camera_send_param(cam, "SH", 0);
}


decompiled_code:
__int64 __fastcall gopro_camera_set_mode(__int64 a1, char a2)
{
return gopro_camera_send_param(a1, "CM", a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char a2)
{
return func6(a1, "CM", a2);
}

original_code:
int gopro_camera_set_mode(gopro_camera *cam, gopro_mode mode) {
  return gopro_camera_send_param(cam, "CM", mode);
}

canonical_original_code:
int gopro_camera_set_mode(struct gopro_camera *cam, enum gopro_mode mode) {
  return gopro_camera_send_param(cam, "CM", mode);
}

variable_types: enum gopro_mode { GOPRO_MODE_VIDEO=0, GOPRO_MODE_PHOTO=1, GOPRO_MODE_BURST=2, GOPRO_MODE_TIMELAPSE=3, GOPRO_MODE_MENU=7 }


decompiled_code:
__int64 __fastcall gopro_camera_set_video_mode(__int64 a1)
{
return gopro_camera_set_mode(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func11(a1, 0);
}

original_code:
int gopro_camera_set_video_mode(gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_VIDEO);
}

canonical_original_code:
int gopro_camera_set_video_mode(struct gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_VIDEO);
}


decompiled_code:
__int64 __fastcall gopro_camera_set_photo_mode(__int64 a1)
{
return gopro_camera_set_mode(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return func11(a1, 1);
}

original_code:
int gopro_camera_set_photo_mode(gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_PHOTO);
}

canonical_original_code:
int gopro_camera_set_photo_mode(struct gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_PHOTO);
}


decompiled_code:
__int64 __fastcall gopro_camera_set_burst_mode(__int64 a1)
{
return gopro_camera_set_mode(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func11(a1, 2);
}

original_code:
int gopro_camera_set_burst_mode(gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_BURST);
}

canonical_original_code:
int gopro_camera_set_burst_mode(struct gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_BURST);
}


decompiled_code:
__int64 __fastcall gopro_camera_set_timelapse_mode(__int64 a1)
{
return gopro_camera_set_mode(a1, 3);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func11(a1, 3);
}

original_code:
int gopro_camera_set_timelapse_mode(gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_TIMELAPSE);
}

canonical_original_code:
int gopro_camera_set_timelapse_mode(struct gopro_camera *cam) {
  return gopro_camera_set_mode(cam, GOPRO_MODE_TIMELAPSE);
}


decompiled_code:
__int64 __fastcall gopro_camera_set_head_up(__int64 a1)
{
return gopro_camera_send_param(a1, "UP", 0);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return func6(a1, "UP", 0);
}

original_code:
int gopro_camera_set_head_up(gopro_camera *cam) {
  return gopro_camera_send_param(cam, "UP", 0);
}

canonical_original_code:
int gopro_camera_set_head_up(struct gopro_camera *cam) {
  return gopro_camera_send_param(cam, "UP", 0);
}


decompiled_code:
__int64 __fastcall gopro_camera_set_head_down(__int64 a1)
{
return gopro_camera_send_param(a1, "UP", 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func6(a1, "UP", 1);
}

original_code:
int gopro_camera_set_head_down(gopro_camera *cam) {
  return gopro_camera_send_param(cam, "UP", 1);
}

canonical_original_code:
int gopro_camera_set_head_down(struct gopro_camera *cam) {
  return gopro_camera_send_param(cam, "UP", 1);
}


decompiled_code:
__int64 __fastcall gopro_camera_delete_last(__int64 a1)
{
return gopro_camera_send(a1, "DL");
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return func5(a1, "DL");
}

original_code:
int gopro_camera_delete_last(gopro_camera *cam) {
  return gopro_camera_send(cam, "DL");
}

canonical_original_code:
int gopro_camera_delete_last(struct gopro_camera *cam) {
  return gopro_camera_send(cam, "DL");
}


decompiled_code:
__int64 __fastcall gopro_camera_delete_all(__int64 a1)
{
return gopro_camera_send(a1, "DA");
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return func5(a1, "DA");
}

original_code:
int gopro_camera_delete_all(gopro_camera *cam) {
  return gopro_camera_send(cam, "DA");
}

canonical_original_code:
int gopro_camera_delete_all(struct gopro_camera *cam) {
  return gopro_camera_send(cam, "DA");
}


decompiled_code:
void __fastcall vbuffer_free(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void vbuffer_free(vbuffer *buffer) {
  if (buffer->data != ((void *)0)) free(buffer->data);
  free(buffer);
}

canonical_original_code:
void vbuffer_free(struct vbuffer *buffer) {
  if (buffer->data != ((void *)0)) free(buffer->data);
  free(buffer);
}

variable_types: struct vbuffer { void *data; unsigned long capacity; unsigned long length; } *


decompiled_code:
__int64 __fastcall vbuffer_resize(__int64 a1, size_t a2)
{
__int64 result; // rax
size_t v4; // rbx
void *v5; // r12
void *v6; // rdi

result = 0LL;
if ( *(_QWORD *)(a1 + 8) != a2 )
{
v4 = a2;
v5 = *(void **)a1;
v6 = malloc(a2);
*(_QWORD *)a1 = v6;
if ( v6 )
{
*(_QWORD *)(a1 + 8) = a2;
result = 0LL;
if ( v5 )
{
if ( *(_QWORD *)(a1 + 16) <= a2 )
v4 = *(_QWORD *)(a1 + 16);
memcpy(v6, v5, v4);
*(_QWORD *)(a1 + 16) = v4;
free(v5);
result = 0LL;
}
}
else
{
perror("Error allocating memory for buffer resize");
*(_QWORD *)a1 = v5;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, size_t a2)
{
__int64 result; // rax
size_t v4; // rbx
void *v5; // r12
void *v6; // rdi

result = 0LL;
if ( *(_QWORD *)(a1 + 8) != a2 )
{
v4 = a2;
v5 = *(void **)a1;
v6 = malloc(a2);
*(_QWORD *)a1 = v6;
if ( v6 )
{
*(_QWORD *)(a1 + 8) = a2;
result = 0LL;
if ( v5 )
{
if ( *(_QWORD *)(a1 + 16) <= a2 )
v4 = *(_QWORD *)(a1 + 16);
memcpy(v6, v5, v4);
*(_QWORD *)(a1 + 16) = v4;
free(v5);
result = 0LL;
}
}
else
{
perror("Error allocating memory for buffer resize");
*(_QWORD *)a1 = v5;
result = 1LL;
}
}
return result;
}

original_code:
int vbuffer_resize(vbuffer *buffer, size_t new_capacity) {
  size_t copylen;
  void *backup;
  if (new_capacity == buffer->capacity) return 0;
  backup = buffer->data;
  buffer->data = malloc(new_capacity);
  if (buffer->data == ((void *)0)) {
    perror("Error allocating memory for buffer resize");
    buffer->data = backup;
    return 1;
  }
  buffer->capacity = new_capacity;
  if (backup != ((void *)0)) {
    copylen = (new_capacity < buffer->length) ? new_capacity : buffer->length;
    memcpy(buffer->data, backup, copylen);
    buffer->length = copylen;
    free(backup);
  }
  return 0;
}

canonical_original_code:
int vbuffer_resize(struct vbuffer *buffer, unsigned long new_capacity) {
  unsigned long copylen;
  void *backup;
  if (new_capacity == buffer->capacity) return 0;
  backup = buffer->data;
  buffer->data = malloc(new_capacity);
  if (buffer->data == ((void *)0)) {
    perror("Error allocating memory for buffer resize");
    buffer->data = backup;
    return 1;
  }
  buffer->capacity = new_capacity;
  if (backup != ((void *)0)) {
    copylen = (new_capacity < buffer->length) ? new_capacity : buffer->length;
    memcpy(buffer->data, backup, copylen);
    buffer->length = copylen;
    free(backup);
  }
  return 0;
}

variable_types:
copylen
unsigned long

variable_types:
backup
void *


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

v5 = a1[2] + a3;
if ( a1[1] >= v5 || (v6 = vbuffer_resize((__int64)a1, v5), result = 1LL, !v6) )
{
memcpy((void *)(*a1 + a1[2]), a2, a3);
a1[2] += a3;
result = 0LL;
}
return result;
}

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

v5 = a1[2] + a3;
if ( a1[1] >= v5 || (v6 = func1((__int64)a1, v5), result = 1LL, !v6) )
{
memcpy((void *)(*a1 + a1[2]), a2, a3);
a1[2] += a3;
result = 0LL;
}
return result;
}

original_code:
int vbuffer_append(vbuffer *buffer, void *data, size_t n) {
  size_t new_capacity;
  int err;
  if (buffer->capacity < buffer->length + n) {
    new_capacity = buffer->length + n;
    err = vbuffer_resize(buffer, new_capacity);
    if (err != 0) return 1;
  }
  void *end = ((char *)buffer->data) + buffer->length;
  memcpy(end, data, n);
  buffer->length += n;
  return 0;
}

canonical_original_code:
int vbuffer_append(struct vbuffer *buffer, void *data, unsigned long n) {
  unsigned long new_capacity;
  int err;
  if (buffer->capacity < buffer->length + n) {
    new_capacity = buffer->length + n;
    err = vbuffer_resize(buffer, new_capacity);
    if (err != 0) return 1;
  }
  void *end = ((char *)buffer->data) + buffer->length;
  memcpy(end, data, n);
  buffer->length += n;
  return 0;
}

variable_types:
data
void *

variable_types:
n
unsigned long

variable_types: err int

variable_types:
end
void *


decompiled_code:
void __fastcall gopro_client_free(void *ptr)
{
if ( !ptr )
_assert_fail("client", "src/client.c", 0x1Cu, "gopro_client_free");
if ( *(_QWORD *)ptr )
curl_easy_cleanup();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( !ptr )
_assert_fail("client", "src/client.c", 0x1Cu, "gopro_client_free");
if ( *(_QWORD *)ptr )
curl_easy_cleanup();
free(ptr);
}

original_code:
void gopro_client_free(gopro_client *client) {
  ((void) sizeof ((client) ? 1 : 0), __extension__ ({ if (client) ; else __assert_fail ("client", "src/client.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  if (client->curl != ((void *)0)) curl_easy_cleanup(client->curl);
  free(client);
}

canonical_original_code:
void gopro_client_free(struct gopro_client *client) {
  ((void) sizeof ((client) ? 1 : 0), __extension__ ({ if (client) ; else __assert_fail ("client", "src/client.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  if (client->curl != ((void *)0)) curl_easy_cleanup(client->curl);
  free(client);
}


decompiled_code:
_QWORD *gopro_client_create()
{
_QWORD *v0; // rbx
__int64 v1; // rbp

v0 = malloc(8uLL);
if ( v0 )
{
v1 = curl_easy_init();
*v0 = v1;
if ( !v1 )
{
fwrite("Error allocating curl handle\n", 1uLL, 0x1DuLL, stderr);
gopro_client_free(v0);
v0 = 0LL;
}
}
else
{
perror("Error allocating client object");
}
return v0;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rbx
__int64 v1; // rbp

v0 = malloc(8uLL);
if ( v0 )
{
v1 = curl_easy_init();
*v0 = v1;
if ( !v1 )
{
fwrite("Error allocating curl handle\n", 1uLL, 0x1DuLL, stderr);
func1(v0);
v0 = 0LL;
}
}
else
{
perror("Error allocating client object");
}
return v0;
}

original_code:
gopro_client *gopro_client_create() {
  gopro_client *client = (gopro_client *)malloc(sizeof(gopro_client));
  if (client == ((void *)0)) {
    perror("Error allocating client object");
    return ((void *)0);
  }
  client->curl = curl_easy_init();
  if (client->curl == ((void *)0)) {
    fprintf(stderr, "Error allocating curl handle\n");
    gopro_client_free(client);
    return ((void *)0);
  }
  return client;
}

canonical_original_code:
struct gopro_client *gopro_client_create() {
  struct gopro_client *client = (gopro_client *)malloc(sizeof(gopro_client));
  if (client == ((void *)0)) {
    perror("Error allocating client object");
    return ((void *)0);
  }
  client->curl = curl_easy_init();
  if (client->curl == ((void *)0)) {
    fprintf(stderr, "Error allocating curl handle\n");
    gopro_client_free(client);
    return ((void *)0);
  }
  return client;
}

return_type: struct gopro_client { void *curl; } *


repo: pmem/linux-examples

decompiled_code:
void *__fastcall pmem_map_fit(int fd, size_t a2)
{
void *v2; // rax
void *v3; // rbx

v2 = mmap(0LL, a2, 3, 2, fd, 0LL);
if ( v2 == (void *)-1LL )
return 0LL;
v3 = v2;
PM_base = (__int64)v2;
PM_fd = dup(fd);
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(int fd, size_t a2)
{
void *v2; // rax
void *v3; // rbx

v2 = mmap(0LL, a2, 3, 2, fd, 0LL);
if ( v2 == (void *)-1LL )
return 0LL;
v3 = v2;
PM_base = (__int64)v2;
PM_fd = dup(fd);
return v3;
}

original_code:
void *
pmem_map_fit(int fd, size_t len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x02,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 PM_base = (uintptr_t)base;
 PM_fd = dup(fd);
 return base;
}

canonical_original_code:
void *pmem_map_fit(int fd, unsigned long len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x02,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 PM_base = (unsigned long)base;
 PM_fd = dup(fd);
 return base;
}

variable_types: fd int

variable_types:
len
unsigned long

variable_types:
base
void *

return_type: void *


decompiled_code:
void pmem_drain_pm_stores_fit()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
pmem_drain_pm_stores_fit(void)
{
}

canonical_original_code:
void pmem_drain_pm_stores_fit()
{
}


decompiled_code:
void __fastcall pmem_flush_cache_fit(__int64 a1, __int64 a2)
{
char *v2; // rbx
__int64 v3; // r15
int *v4; // rax

if ( !PM_base )
fatal(0LL, "pmem_fit.c", 99LL, "pmem_flush_cache_fit", "pmem_map hasn't been called");
v2 = (char *)(a1 & 0xFFFFFFFFFFFFFFC0LL);
if ( (a1 & 0xFFFFFFFFFFFFFFC0LL) < a1 + a2 )
{
do
{
if ( pwrite(PM_fd, v2, 0x40uLL, (__off_t)&v2[-PM_base]) < 0 )
{
v3 = a1 - PM_base;
v4 = _errno_location();
fatal((unsigned int)*v4, "pmem_fit.c", 109LL, "pmem_flush_cache_fit", "pwrite len %d offset %lu", a2, v3);
}
v2 += 64;
}
while ( (unsigned __int64)v2 < a1 + a2 );
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
char *v2; // rbx
__int64 v3; // r15
int *v4; // rax

if ( !PM_base )
fatal(0LL, "pmem_fit.c", 99LL, "pmem_flush_cache_fit", "pmem_map hasn't been called");
v2 = (char *)(a1 & 0xFFFFFFFFFFFFFFC0LL);
if ( (a1 & 0xFFFFFFFFFFFFFFC0LL) < a1 + a2 )
{
do
{
if ( pwrite(PM_fd, v2, 0x40uLL, (__off_t)&v2[-PM_base]) < 0 )
{
v3 = a1 - PM_base;
v4 = _errno_location();
fatal((unsigned int)*v4, "pmem_fit.c", 109LL, "pmem_flush_cache_fit", "pwrite len %d offset %lu", a2, v3);
}
v2 += 64;
}
while ( (unsigned __int64)v2 < a1 + a2 );
}
}

original_code:
void
pmem_flush_cache_fit(void *addr, size_t len, int flags)
{
 uintptr_t uptr;
 if (!PM_base)
  fatal(0, "pmem_fit.c", 99, __func__, "pmem_map hasn't been called");
 for (uptr = (uintptr_t)addr & ~(64 - 1);
   uptr < (uintptr_t)addr + len; uptr += 64)
  if (pwrite(PM_fd, (void *)uptr, 64, uptr - PM_base) < 0)
   fatal((*__errno_location ()), "pmem_fit.c", 109, __func__, "pwrite len %d offset %lu", len, addr - PM_base);
}

canonical_original_code:
void pmem_flush_cache_fit(void *addr, unsigned long len, int flags)
{
 unsigned long uptr;
 if (!PM_base)
  fatal(0, "pmem_fit.c", 99, __func__, "pmem_map hasn't been called");
 for (uptr = (unsigned long)addr & ~(64 - 1);
   uptr < (unsigned long)addr + len; uptr += 64)
  if (pwrite(PM_fd, (void *)uptr, 64, uptr - PM_base) < 0)
   fatal((*__errno_location ()), "pmem_fit.c", 109, __func__, "pwrite len %d offset %lu", len, addr - PM_base);
}

variable_types:
addr
void *

variable_types: flags int

variable_types:
uptr
unsigned long


decompiled_code:
void __fastcall pmem_persist_fit(__int64 a1, __int64 a2)
{
pmem_flush_cache_fit(a1, a2);
_mm_sfence();
pmem_drain_pm_stores_fit();
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
func2(a1, a2);
_mm_sfence();
func1();
}

original_code:
void
pmem_persist_fit(void *addr, size_t len, int flags)
{
 pmem_flush_cache_fit(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_fit();
}

canonical_original_code:
void pmem_persist_fit(void *addr, unsigned long len, int flags)
{
 pmem_flush_cache_fit(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_fit();
}


decompiled_code:
__int64 __fastcall tree_insert_subtree(_QWORD *a1, const char *a2)
{
__int64 v3; // rdi
__int64 v4; // r12
__int64 v5; // r13
int v6; // eax
__int64 result; // rax
size_t v8; // rax
__int64 v9; // r12
__int64 v10; // r13
__int64 v11; // rdi
int *v12; // rax

debug("tree.c", 98LL, "tree_insert_subtree", "*rootp_ = %lx", *a1);
v3 = *a1;
if ( v3 )
{
v4 = Pmp;
v5 = Pmp + v3;
v6 = strcmp(a2, (const char *)(Pmp + v3 + 20));
if ( v6 )
{
if ( v6 < 0 )
result = tree_insert_subtree(v5, a2);
else
result = tree_insert_subtree(v5 + 8, a2);
}
else
{
++*(_DWORD *)(v5 + 16);
pmem_persist(*a1 + v4 + 16, 4LL, 0LL);
result = debug("tree.c", 123LL, "tree_insert_subtree", "new count=%u", *(unsigned int *)(Pmp + *a1 + 16));
}
}
else
{
v8 = strlen(a2);
v9 = pmemalloc_reserve(Pmp, v8 + 25);
if ( !v9 )
{
v12 = _errno_location();
fatal((unsigned int)*v12, "tree.c", 107LL, "tree_insert_subtree", "pmem_alloc");
}
v10 = Pmp;
v11 = Pmp + v9;
*(_QWORD *)(v11 + 8) = 0LL;
*(_QWORD *)v11 = 0LL;
*(_DWORD *)(v11 + 16) = 1;
strcpy((char *)(v11 + 20), a2);
pmemalloc_onactive(v10, v9, a1, v9);
pmemalloc_activate(Pmp, v9);
result = debug("tree.c", 117LL, "tree_insert_subtree", "new node inserted, count=1");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const char *a2)
{
__int64 v3; // rdi
__int64 v4; // r12
__int64 v5; // r13
int v6; // eax
__int64 result; // rax
size_t v8; // rax
__int64 v9; // r12
__int64 v10; // r13
__int64 v11; // rdi
int *v12; // rax

debug("tree.c", 98LL, "tree_insert_subtree", "*rootp_ = %lx", *a1);
v3 = *a1;
if ( v3 )
{
v4 = Pmp;
v5 = Pmp + v3;
v6 = strcmp(a2, (const char *)(Pmp + v3 + 20));
if ( v6 )
{
if ( v6 < 0 )
result = func0(v5, a2);
else
result = func0(v5 + 8, a2);
}
else
{
++*(_DWORD *)(v5 + 16);
pmem_persist(*a1 + v4 + 16, 4LL, 0LL);
result = debug("tree.c", 123LL, "tree_insert_subtree", "new count=%u", *(unsigned int *)(Pmp + *a1 + 16));
}
}
else
{
v8 = strlen(a2);
v9 = pmemalloc_reserve(Pmp, v8 + 25);
if ( !v9 )
{
v12 = _errno_location();
fatal((unsigned int)*v12, "tree.c", 107LL, "tree_insert_subtree", "pmem_alloc");
}
v10 = Pmp;
v11 = Pmp + v9;
*(_QWORD *)(v11 + 8) = 0LL;
*(_QWORD *)v11 = 0LL;
*(_DWORD *)(v11 + 16) = 1;
strcpy((char *)(v11 + 20), a2);
pmemalloc_onactive(v10, v9, a1, v9);
pmemalloc_activate(Pmp, v9);
result = debug("tree.c", 117LL, "tree_insert_subtree", "new node inserted, count=1");
}
return result;
}

original_code:
static void
tree_insert_subtree(struct tnode **rootp_, const char *s)
{
 int diff;
 debug("tree.c", 98, __func__, "*rootp_ = %lx", (uintptr_t)*rootp_);
 if (*rootp_ == ((void *)0)) {
  struct tnode *tnp_;
  size_t slen = strlen(s) + 1;
  if ((tnp_ = pmemalloc_reserve(Pmp, sizeof(*tnp_) +
      slen)) == ((void *)0))
   fatal((*__errno_location ()), "tree.c", 107, __func__, "pmem_alloc");
  ((typeof(tnp_))(Pmp + (uintptr_t)tnp_))->left_ =
  ((typeof(tnp_))(Pmp + (uintptr_t)tnp_))->right_ = ((void *)0);
  ((typeof(tnp_))(Pmp + (uintptr_t)tnp_))->count = 1;
  strcpy(((typeof(tnp_))(Pmp + (uintptr_t)tnp_))->s, s);
  pmemalloc_onactive(Pmp, tnp_, (void **)rootp_, tnp_);
  pmemalloc_activate(Pmp, tnp_);
  debug("tree.c", 117, __func__, "new node inserted, count=1");
 } else if ((diff = strcmp(s, ((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->s)) == 0) {
  ((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->count++;
  pmem_persist(&((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->count, sizeof(unsigned), 0);
  debug("tree.c", 123, __func__, "new count=%u", ((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->count);
 } else if (diff < 0) {
  tree_insert_subtree(&((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->left_, s);
 } else {
  tree_insert_subtree(&((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->right_, s);
 }
}

canonical_original_code:
static void tree_insert_subtree(struct tnode **rootp_, char *s)
{
 int diff;
 debug("tree.c", 98, __func__, "*rootp_ = %lx", (unsigned long)*rootp_);
 if (*rootp_ == ((void *)0)) {
  struct tnode *tnp_;
  unsigned long slen = strlen(s) + 1;
  if ((tnp_ = pmemalloc_reserve(Pmp, sizeof(*tnp_) +
      slen)) == ((void *)0))
   fatal((*__errno_location ()), "tree.c", 107, __func__, "pmem_alloc");
  ((typeof(tnp_))(Pmp + (unsigned long)tnp_))->left_ =
  ((typeof(tnp_))(Pmp + (unsigned long)tnp_))->right_ = ((void *)0);
  ((typeof(tnp_))(Pmp + (unsigned long)tnp_))->count = 1;
  strcpy(((typeof(tnp_))(Pmp + (unsigned long)tnp_))->s, s);
  pmemalloc_onactive(Pmp, tnp_, (void **)rootp_, tnp_);
  pmemalloc_activate(Pmp, tnp_);
  debug("tree.c", 117, __func__, "new node inserted, count=1");
 } else if ((diff = strcmp(s, ((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->s)) == 0) {
  ((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->count++;
  pmem_persist(&((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->count, sizeof(unsigned int), 0);
  debug("tree.c", 123, __func__, "new count=%u", ((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->count);
 } else if (diff < 0) {
  tree_insert_subtree(&((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->left_, s);
 } else {
  tree_insert_subtree(&((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->right_, s);
 }
}

variable_types: struct tnode { struct tnode *left_; struct tnode *right_; unsigned int count; char s[]; } **

variable_types:
s
char *

variable_types: diff int

variable_types:
slen
unsigned long


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

result = debug("tree.c", 152LL, "tree_walk_subtree", "root_ = %lx", a1);
if ( a1 )
{
tree_walk_subtree(*(_QWORD *)(Pmp + a1));
printf("%5d %s\n", *(unsigned int *)(Pmp + a1 + 16), (const char *)(Pmp + a1 + 20));
result = tree_walk_subtree(*(_QWORD *)(Pmp + a1 + 8));
}
return result;
}

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

result = debug("tree.c", 152LL, "tree_walk_subtree", "root_ = %lx", a1);
if ( a1 )
{
func1(*(_QWORD *)(Pmp + a1));
printf("%5d %s\n", *(unsigned int *)(Pmp + a1 + 16), (const char *)(Pmp + a1 + 20));
result = func1(*(_QWORD *)(Pmp + a1 + 8));
}
return result;
}

original_code:
static void
tree_walk_subtree(struct tnode *root_)
{
 debug("tree.c", 152, __func__, "root_ = %lx", (uintptr_t)root_);
 if (root_) {
  tree_walk_subtree(((typeof(root_))(Pmp + (uintptr_t)root_))->left_);
  printf("%5d %s\n",
    ((typeof(root_))(Pmp + (uintptr_t)root_))->count,
    ((typeof(root_))(Pmp + (uintptr_t)root_))->s);
  tree_walk_subtree(((typeof(root_))(Pmp + (uintptr_t)root_))->right_);
 }
}

canonical_original_code:
static void tree_walk_subtree(struct tnode *root_)
{
 debug("tree.c", 152, __func__, "root_ = %lx", (unsigned long)root_);
 if (root_) {
  tree_walk_subtree(((typeof(root_))(Pmp + (unsigned long)root_))->left_);
  printf("%5d %s\n",
    ((typeof(root_))(Pmp + (unsigned long)root_))->count,
    ((typeof(root_))(Pmp + (unsigned long)root_))->s);
  tree_walk_subtree(((typeof(root_))(Pmp + (unsigned long)root_))->right_);
 }
}

variable_types: struct tnode { struct tnode *left_; struct tnode *right_; unsigned int count; char s[]; } *


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

result = debug("tree.c", 187LL, "tree_free_subtree", "*rootp_ = %lx", *a1);
v3 = *a1;
if ( v3 )
{
tree_free_subtree(Pmp + v3);
tree_free_subtree(Pmp + *a1 + 8);
pmemalloc_onfree(Pmp, *a1, a1, 0LL);
result = pmemalloc_free(Pmp, *a1);
}
return result;
}

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

result = debug("tree.c", 187LL, "tree_free_subtree", "*rootp_ = %lx", *a1);
v3 = *a1;
if ( v3 )
{
func2(Pmp + v3);
func2(Pmp + *a1 + 8);
pmemalloc_onfree(Pmp, *a1, a1, 0LL);
result = pmemalloc_free(Pmp, *a1);
}
return result;
}

original_code:
static void
tree_free_subtree(struct tnode **rootp_)
{
 debug("tree.c", 187, __func__, "*rootp_ = %lx", (uintptr_t)*rootp_);
 if (*rootp_ != ((void *)0)) {
  tree_free_subtree(&((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->left_);
  tree_free_subtree(&((typeof(*rootp_))(Pmp + (uintptr_t)*rootp_))->right_);
  pmemalloc_onfree(Pmp, (void *)*rootp_, (void **)rootp_, ((void *)0));
  pmemalloc_free(Pmp, (void *)*rootp_);
 }
}

canonical_original_code:
static void tree_free_subtree(struct tnode **rootp_)
{
 debug("tree.c", 187, __func__, "*rootp_ = %lx", (unsigned long)*rootp_);
 if (*rootp_ != ((void *)0)) {
  tree_free_subtree(&((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->left_);
  tree_free_subtree(&((typeof(*rootp_))(Pmp + (unsigned long)*rootp_))->right_);
  pmemalloc_onfree(Pmp, (void *)*rootp_, (void **)rootp_, ((void *)0));
  pmemalloc_free(Pmp, (void *)*rootp_);
 }
}

user_defined_types: struct tnode { struct tnode *left_; struct tnode *right_; unsigned int count; char s[]; }


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

debug("tree.c", 82LL, "tree_init", "path \"%s\" size %lu", a1, a2);
result = pmemalloc_init(a1, a2);
Pmp = result;
if ( !result )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "tree.c", 85LL, "tree_init", "pmemalloc_init on %s", a1);
}
return result;
}

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

debug("tree.c", 82LL, "tree_init", "path \"%s\" size %lu", a1, a2);
result = pmemalloc_init(a1, a2);
Pmp = result;
if ( !result )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "tree.c", 85LL, "tree_init", "pmemalloc_init on %s", a1);
}
return result;
}

original_code:
void
tree_init(const char *path, size_t size)
{
 debug("tree.c", 82, __func__, "path \"%s\" size %lu", path, size);
 if ((Pmp = pmemalloc_init(path, size)) == ((void *)0))
  fatal((*__errno_location ()), "tree.c", 85, __func__, "pmemalloc_init on %s", path);
}

canonical_original_code:
void tree_init(char *path, unsigned long size)
{
 debug("tree.c", 82, __func__, "path \"%s\" size %lu", path, size);
 if ((Pmp = pmemalloc_init(path, size)) == ((void *)0))
  fatal((*__errno_location ()), "tree.c", 85, __func__, "pmemalloc_init on %s", path);
}

variable_types:
path
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall tree_insert(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)pmemalloc_static_area(Pmp);
return tree_insert_subtree(v1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)pmemalloc_static_area(Pmp);
return func0(v1, a1);
}

original_code:
void
tree_insert(const char *s)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_insert_subtree(&sp->root_, s);
}

canonical_original_code:
void tree_insert(char *s)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_insert_subtree(&sp->root_, s);
}

variable_types: struct static_info { struct tnode { struct tnode *left_; struct tnode *right_; unsigned int count; char s[]; } *root_; } *

user_defined_types: struct static_info { struct tnode *root_; }


decompiled_code:
__int64 tree_walk()
{
__int64 *v0; // rax

v0 = (__int64 *)pmemalloc_static_area(Pmp);
return tree_walk_subtree(*v0);
}

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

v0 = (__int64 *)pmemalloc_static_area(Pmp);
return func1(*v0);
}

original_code:
void
tree_walk(void)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_walk_subtree(sp->root_);
}

canonical_original_code:
void tree_walk()
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_walk_subtree(sp->root_);
}


decompiled_code:
__int64 tree_free()
{
_QWORD *v0; // rax

v0 = (_QWORD *)pmemalloc_static_area(Pmp);
return tree_free_subtree(v0);
}

canonical_decompiled_code:
__int64 func6()
{
_QWORD *v0; // rax

v0 = (_QWORD *)pmemalloc_static_area(Pmp);
return func2(v0);
}

original_code:
void
tree_free(void)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_free_subtree(&sp->root_);
}

canonical_original_code:
void tree_free()
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_free_subtree(&sp->root_);
}


exename

decompiled_code:
char *exename()
{
unsigned int v0; // eax
int v1; // eax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

v0 = getpid();
snprintf(v3, 0x1000uLL, "/proc/%d/exe", v0);
v1 = readlink(v3, exename_0, 0x1000uLL);
if ( v1 < 0 )
strcpy(exename_0, "Unknown");
else
exename_0[v1] = 0;
return exename_0;
}

canonical_decompiled_code:
char *func0()
{
unsigned int v0; // eax
int v1; // eax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

v0 = getpid();
snprintf(v3, 0x1000uLL, "/proc/%d/exe", v0);
v1 = readlink(v3, exename_0, 0x1000uLL);
if ( v1 < 0 )
strcpy(exename_0, "Unknown");
else
exename_0[v1] = 0;
return exename_0;
}

original_code:
static const char *
exename(void)
{
 char proc[4096];
 static char exename[4096];
 int nbytes;
 snprintf(proc, 4096, "/proc/%d/exe", getpid());
 if ((nbytes = readlink(proc, exename, 4096)) < 0)
  strcpy(exename, "Unknown");
 else
  exename[nbytes] = '\0';
 return exename;
}

canonical_original_code:
static char *exename()
{
 char proc[4096];
 static char exename[4096];
 int nbytes;
 snprintf(proc, 4096, "/proc/%d/exe", getpid());
 if ((nbytes = readlink(proc, exename, 4096)) < 0)
  strcpy(exename, "Unknown");
 else
  exename[nbytes] = '\0';
 return exename;
}

variable_types:
proc
char [4096]

variable_types:
exename
char [4096]

variable_types: nbytes int


debug

decompiled_code:
void debug(const char *a1, unsigned int a2, const char *a3, const char *a4, ...)
{
int *v6; // rbx
int v7; // er15
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

if ( Debug )
{
v6 = _errno_location();
v7 = *v6;
fprintf(stderr, "debug: %s:%d %s()", a1, a2, a3);
if ( a4 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a4);
vfprintf(stderr, a4, arg);
}
fputc(10, stderr);
*v6 = v7;
}
}

canonical_decompiled_code:
void func1(const char *a1, unsigned int a2, const char *a3, const char *a4, ...)
{
int *v6; // rbx
int v7; // er15
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

if ( Debug )
{
v6 = _errno_location();
v7 = *v6;
fprintf(stderr, "debug: %s:%d %s()", a1, a2, a3);
if ( a4 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a4);
vfprintf(stderr, a4, arg);
}
fputc(10, stderr);
*v6 = v7;
}
}

original_code:
void
debug(const char *file, int line, const char *func, const char *fmt, ...)
{
 va_list ap;
 int save_errno;
 if (!Debug)
  return;
 save_errno = (*__errno_location ());
 fprintf(stderr, "debug: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 (*__errno_location ()) = save_errno;
}

canonical_original_code:
void debug(char *file, int line, char *func, char *fmt, ...)
{
 __builtin_va_list ap;
 int save_errno;
 if (!Debug)
  return;
 save_errno = (*__errno_location ());
 fprintf(stderr, "debug: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 (*__errno_location ()) = save_errno;
}

variable_types:
file
char *

variable_types: line int

variable_types:
func
char *

variable_types:
fmt
char *


fatal

decompiled_code:
void __noreturn fatal(int errnum, const char *a2, unsigned int a3, const char *a4, const char *a5, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

fprintf(stderr, "ERROR: %s:%d %s()", a2, a3, a4);
if ( a5 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a5);
vfprintf(stderr, a5, arg);
}
if ( errnum )
{
v6 = strerror(errnum);
fprintf(stderr, ": %s", v6);
}
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2(int errnum, const char *a2, unsigned int a3, const char *a4, const char *a5, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

fprintf(stderr, "ERROR: %s:%d %s()", a2, a3, a4);
if ( a5 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a5);
vfprintf(stderr, a5, arg);
}
if ( errnum )
{
v6 = strerror(errnum);
fprintf(stderr, ": %s", v6);
}
fputc(10, stderr);
exit(1);
}

original_code:
void
fatal(int err, const char *file, int line, const char *func,
 const char *fmt, ...)
{
 va_list ap;
 fprintf(stderr, "ERROR: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 if (err)
  fprintf(stderr, ": %s", strerror(err));
 fprintf(stderr, "\n");
 exit(1);
}

canonical_original_code:
void fatal(int err, char *file, int line, char *func, char *fmt, ...)
{
 __builtin_va_list ap;
 fprintf(stderr, "ERROR: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 if (err)
  fprintf(stderr, ": %s", strerror(err));
 fprintf(stderr, "\n");
 exit(1);
}

variable_types: err int


usage

decompiled_code:
void __noreturn usage(const char *a1, const char *a2, ...)
{
char *v2; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)Myname;
if ( !Myname )
v2 = exename();
fprintf(stderr, "Usage: %s", v2);
if ( a1 )
fprintf(stderr, " %s", a1);
if ( a2 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a2);
vfprintf(stderr, a2, arg);
}
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(const char *a1, const char *a2, ...)
{
char *v2; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)Myname;
if ( !Myname )
v2 = func0();
fprintf(stderr, "Usage: %s", v2);
if ( a1 )
fprintf(stderr, " %s", a1);
if ( a2 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a2);
vfprintf(stderr, a2, arg);
}
fputc(10, stderr);
exit(1);
}

original_code:
void
usage(const char *argfmt, const char *fmt, ...)
{
 va_list ap;
 fprintf(stderr, "Usage: %s", (Myname == ((void *)0)) ? exename() : Myname);
 if (argfmt)
  fprintf(stderr, " %s", argfmt);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 exit(1);
}

canonical_original_code:
void usage(char *argfmt, char *fmt, ...)
{
 __builtin_va_list ap;
 fprintf(stderr, "Usage: %s", (Myname == ((void *)0)) ? exename() : Myname);
 if (argfmt)
  fprintf(stderr, " %s", argfmt);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 exit(1);
}

variable_types:
argfmt
char *


decompiled_code:
void *__fastcall pmem_map_msync(int fd, size_t a2)
{
void *result; // rax

result = mmap(0LL, a2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int fd, size_t a2)
{
void *result; // rax

result = mmap(0LL, a2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

original_code:
void *
pmem_map_msync(int fd, size_t len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}

canonical_original_code:
void *pmem_map_msync(int fd, unsigned long len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}

variable_types: fd int

variable_types:
len
unsigned long

variable_types:
base
void *


decompiled_code:
void pmem_drain_pm_stores_msync()
{
;
}

original_code:
void
pmem_drain_pm_stores_msync(void)
{
}

canonical_original_code:
void pmem_drain_pm_stores_msync()
{
}


decompiled_code:
int __fastcall pmem_flush_cache_msync(__int64 a1, __int64 a2)
{
int result; // eax
int *v3; // rax

result = msync((void *)(a1 & 0xFFFFFFFFFFFFF000LL), ((a1 & 0xFFF) + a2 + 4095) & 0xFFFFFFFFFFFFF000LL, 4);
if ( result < 0 )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "pmem_msync.c", 106LL, "pmem_flush_cache_msync", "msync");
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
int result; // eax
int *v3; // rax

result = msync((void *)(a1 & 0xFFFFFFFFFFFFF000LL), ((a1 & 0xFFF) + a2 + 4095) & 0xFFFFFFFFFFFFF000LL, 4);
if ( result < 0 )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "pmem_msync.c", 106LL, "pmem_flush_cache_msync", "msync");
}
return result;
}

original_code:
void
pmem_flush_cache_msync(void *addr, size_t len, int flags)
{
 uintptr_t uptr;
 len += (uintptr_t)addr & (4096 - 1);
 uptr = (uintptr_t)addr & ~(4096 - 1);
 len = (len + (4096 - 1)) & ~(4096 - 1);
 if (msync((void *)uptr, len, 4) < 0)
  fatal((*__errno_location ()), "pmem_msync.c", 106, __func__, "msync");
}

canonical_original_code:
void pmem_flush_cache_msync(void *addr, unsigned long len, int flags)
{
 unsigned long uptr;
 len += (unsigned long)addr & (4096 - 1);
 uptr = (unsigned long)addr & ~(4096 - 1);
 len = (len + (4096 - 1)) & ~(4096 - 1);
 if (msync((void *)uptr, len, 4) < 0)
  fatal((*__errno_location ()), "pmem_msync.c", 106, __func__, "msync");
}

variable_types:
addr
void *

variable_types: flags int

variable_types:
uptr
unsigned long


decompiled_code:
void __fastcall pmem_persist_msync(__int64 a1, __int64 a2)
{
pmem_flush_cache_msync(a1, a2);
_mm_sfence();
pmem_drain_pm_stores_msync();
}

original_code:
void
pmem_persist_msync(void *addr, size_t len, int flags)
{
 pmem_flush_cache_msync(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_msync();
}

canonical_original_code:
void pmem_persist_msync(void *addr, unsigned long len, int flags)
{
 pmem_flush_cache_msync(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_msync();
}


trigger

decompiled_code:
void trigger()
{
Nothing = 0LL;
}

canonical_decompiled_code:
void func0()
{
Nothing = 0LL;
}

original_code:
static void
trigger(void)
{
 Nothing = 0;
}

canonical_original_code:
static void trigger()
{
 Nothing = 0;
}


handler

decompiled_code:
void __noreturn handler()
{
longjmp(Trigjmp, 1);
}

canonical_decompiled_code:
void __noreturn func1()
{
longjmp(Trigjmp, 1);
}

original_code:
static void
handler()
{
 longjmp(Trigjmp, 1);
}


pretrigger

decompiled_code:
void __noreturn pretrigger()
{
getpid();
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func2()
{
getpid();
while ( 1 )
;
}

original_code:
static void
pretrigger(void)
{
 int x = getpid();
 while (1) {
  x++;
  Nothing += x;
 }
}

canonical_original_code:
static void pretrigger()
{
 int x = getpid();
 while (1) {
  x++;
  Nothing += x;
 }
}

variable_types: x int


decompiled_code:
__pid_t icount_stop()
{
__pid_t result; // eax
int *v1; // rax
int *v2; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( read(Tracerpipe[0], &Total, 8uLL) < 0 )
{
v1 = _errno_location();
fatal((unsigned int)*v1, "../icount/icount.c", 246LL, "icount_stop", "read from pipe");
}
close(Tracerpipe[0]);
result = waitpid(Tracer_pid, stat_loc, 0);
if ( result < 0 )
{
v2 = _errno_location();
result = fatal(
(unsigned int)*v2,
"../icount/icount.c",
251LL,
"icount_stop",
"waitpid(pid=%d)",
(unsigned int)Tracer_pid);
}
Tracer_pid = 0;
return result;
}

canonical_decompiled_code:
__pid_t func4()
{
__pid_t result; // eax
int *v1; // rax
int *v2; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( read(Tracerpipe[0], &Total, 8uLL) < 0 )
{
v1 = _errno_location();
fatal((unsigned int)*v1, "../icount/icount.c", 246LL, "icount_stop", "read from pipe");
}
close(Tracerpipe[0]);
result = waitpid(Tracer_pid, stat_loc, 0);
if ( result < 0 )
{
v2 = _errno_location();
result = fatal(
(unsigned int)*v2,
"../icount/icount.c",
251LL,
"icount_stop",
"waitpid(pid=%d)",
(unsigned int)Tracer_pid);
}
Tracer_pid = 0;
return result;
}

original_code:
void
icount_stop(void)
{
 int status;
 if (read(Tracerpipe[0], &Total, sizeof(Total)) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 246, __func__, "read from pipe");
 close(Tracerpipe[0]);
 if (waitpid(Tracer_pid, &status, 0) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 251, __func__, "waitpid(pid=%d)", Tracer_pid);
 Tracer_pid = 0;
}

canonical_original_code:
void icount_stop()
{
 int status;
 if (read(Tracerpipe[0], &Total, sizeof(Total)) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 246, __func__, "read from pipe");
 close(Tracerpipe[0]);
 if (waitpid(Tracer_pid, &status, 0) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 251, __func__, "waitpid(pid=%d)", Tracer_pid);
 Tracer_pid = 0;
}

variable_types: status int


decompiled_code:
__int64 icount_total()
{
return Total;
}

canonical_decompiled_code:
__int64 func6()
{
return Total;
}

original_code:
unsigned long
icount_total(void)
{
 return Total;
}

canonical_original_code:
unsigned long icount_total()
{
 return Total;
}


decompiled_code:
void *__fastcall pmem_map_cl(int fd, size_t a2)
{
void *result; // rax

result = mmap(0LL, a2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

original_code:
void *
pmem_map_cl(int fd, size_t len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}

canonical_original_code:
void *pmem_map_cl(int fd, unsigned long len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}


decompiled_code:
void pmem_drain_pm_stores_cl()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
pmem_drain_pm_stores_cl(void)
{
}

canonical_original_code:
void pmem_drain_pm_stores_cl()
{
}


decompiled_code:
char *__fastcall pmem_flush_cache_cl(__int64 a1, __int64 a2)
{
char *result; // rax
unsigned __int64 v3; // rsi

result = (char *)(a1 & 0xFFFFFFFFFFFFFFC0LL);
v3 = a1 + a2;
if ( (a1 & 0xFFFFFFFFFFFFFFC0LL) < v3 )
{
do
{
_mm_clflush(result);
result += 64;
}
while ( (unsigned __int64)result < v3 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int64 a2)
{
char *result; // rax
unsigned __int64 v3; // rsi

result = (char *)(a1 & 0xFFFFFFFFFFFFFFC0LL);
v3 = a1 + a2;
if ( (a1 & 0xFFFFFFFFFFFFFFC0LL) < v3 )
{
do
{
_mm_clflush(result);
result += 64;
}
while ( (unsigned __int64)result < v3 );
}
return result;
}

original_code:
void
pmem_flush_cache_cl(void *addr, size_t len, int flags)
{
 uintptr_t uptr;
 for (uptr = (uintptr_t)addr & ~(64 - 1);
   uptr < (uintptr_t)addr + len; uptr += 64)
  __builtin_ia32_clflush((void *)uptr);
}

canonical_original_code:
void pmem_flush_cache_cl(void *addr, unsigned long len, int flags)
{
 unsigned long uptr;
 for (uptr = (unsigned long)addr & ~(64 - 1);
   uptr < (unsigned long)addr + len; uptr += 64)
  __builtin_ia32_clflush((void *)uptr);
}


decompiled_code:
void __fastcall pmem_persist_cl(__int64 a1, __int64 a2)
{
pmem_flush_cache_cl(a1, a2);
_mm_sfence();
pmem_drain_pm_stores_cl();
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
func2(a1, a2);
_mm_sfence();
func1();
}

original_code:
void
pmem_persist_cl(void *addr, size_t len, int flags)
{
 pmem_flush_cache_cl(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_cl();
}

canonical_original_code:
void pmem_persist_cl(void *addr, unsigned long len, int flags)
{
 pmem_flush_cache_cl(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_cl();
}


decompiled_code:
void pmem_msync_mode()
{
Mode = 1;
}

canonical_decompiled_code:
void func0()
{
Mode = 1;
}

original_code:
void
pmem_msync_mode(void)
{
 Mode = 1;
}

canonical_original_code:
void pmem_msync_mode()
{
 Mode = 1;
}


decompiled_code:
void pmem_fit_mode()
{
Mode = 2;
}

canonical_decompiled_code:
void func1()
{
Mode = 2;
}

original_code:
void
pmem_fit_mode(void)
{
 Mode = 2;
}

canonical_original_code:
void pmem_fit_mode()
{
 Mode = 2;
}


decompiled_code:
__int64 pmem_map()
{
return ((__int64 (*)(void))*(&Map + Mode))();
}

original_code:
void *
pmem_map(int fd, size_t len)
{
 return (*Map[Mode])(fd, len);
}

canonical_original_code:
void *pmem_map(int fd, unsigned long len)
{
 return (*Map[Mode])(fd, len);
}


decompiled_code:
__int64 pmem_persist()
{
return ((__int64 (*)(void))*(&Persist + Mode))();
}

canonical_decompiled_code:
__int64 func3()
{
return ((__int64 (*)(void))*(&Persist + Mode))();
}

original_code:
void
pmem_persist(void *addr, size_t len, int flags)
{
 (*Persist[Mode])(addr, len, flags);
}

canonical_original_code:
void pmem_persist(void *addr, unsigned long len, int flags)
{
 (*Persist[Mode])(addr, len, flags);
}


decompiled_code:
__int64 pmem_flush_cache()
{
return ((__int64 (*)(void))*(&Flush + Mode))();
}

original_code:
void
pmem_flush_cache(void *addr, size_t len, int flags)
{
 (*Flush[Mode])(addr, len, flags);
}

canonical_original_code:
void pmem_flush_cache(void *addr, unsigned long len, int flags)
{
 (*Flush[Mode])(addr, len, flags);
}


decompiled_code:
void pmem_fence()
{
_mm_sfence();
}

canonical_decompiled_code:
void func5()
{
_mm_sfence();
}

original_code:
void
pmem_fence(void)
{
 __builtin_ia32_sfence();
}

canonical_original_code:
void pmem_fence()
{
 __builtin_ia32_sfence();
}


decompiled_code:
__int64 pmem_drain_pm_stores()
{
return ((__int64 (*)(void))*(&Drain_pm_stores + Mode))();
}

canonical_decompiled_code:
__int64 func6()
{
return ((__int64 (*)(void))*(&Drain_pm_stores + Mode))();
}

original_code:
void
pmem_drain_pm_stores(void)
{
 (*Drain_pm_stores[Mode])();
}

canonical_original_code:
void pmem_drain_pm_stores()
{
 (*Drain_pm_stores[Mode])();
}


repo: pmer/yak

decompiled_code:
int create_uithread()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++nthreads;
return pthread_create(newthread, 0LL, uimain, 0LL);
}

canonical_decompiled_code:
int func6()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++nthreads;
return pthread_create(newthread, 0LL, uimain, 0LL);
}

original_code:
static void create_uithread()
{
 pthread_t thread;
 nthreads++;
 pthread_create(&thread, ((void *)0), uimain, ((void *)0));
}

canonical_original_code:
static void create_uithread()
{
 unsigned long thread;
 nthreads++;
 pthread_create(&thread, ((void *)0), uimain, ((void *)0));
}

variable_types:
thread
unsigned long


say

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

if ( chan )
result = ircproto_privmsg();
else
result = info();
return result;
}

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

if ( chan )
result = ircproto_privmsg();
else
result = info();
return result;
}

original_code:
static void say(char *line)
{
 if (*chan)
  ircproto_privmsg(chan, "%s", line);
 else
  info("please '/cd' into a channel first");
}

variable_types:
line
char *


uimain

decompiled_code:
__int64 __fastcall uimain(void *a1)
{
_BYTE *v1; // rbx

while ( 1 )
{
v1 = (_BYTE *)readline();
if ( !v1 )
break;
mutex_on();
if ( *v1 == 47 )
{
if ( !(unsigned __int8)eval_emit() )
info();
}
else
{
say(v1);
}
mutex_off();
free(v1);
}
putchar(10);
return safe_shutdown_and_die();
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1)
{
_BYTE *v1; // rbx

while ( 1 )
{
v1 = (_BYTE *)readline();
if ( !v1 )
break;
mutex_on();
if ( *v1 == 47 )
{
if ( !(unsigned __int8)eval_emit() )
info();
}
else
{
func8(v1);
}
mutex_off();
free(v1);
}
putchar(10);
return safe_shutdown_and_die();
}

original_code:
static void *uimain(void *unused)
{
 char *line;
 while (line = readline("> ")) {
  mutex_on();
  if (line[0] == '/') {
   if (!eval_emit(ectx, line + 1)) {
    info("invalid command: %s", line);
   }
  } else {
   say(line);
  }
  mutex_off();
  free(line);
 }
 printf("\n");
 safe_shutdown_and_die(0);
}

variable_types:
unused
void *


msg

decompiled_code:
__int64 msg()
{
return ircproto_privmsg();
}

canonical_decompiled_code:
__int64 func10()
{
return ircproto_privmsg();
}

original_code:
static void msg(char *line, char **caps, int ncaps)
{
 ircproto_privmsg(caps[0], "%s", caps[1]);
}

variable_types:
caps
char **

variable_types: ncaps int


nick

decompiled_code:
__int64 __fastcall nick(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
free(bot_nick);
bot_nick = strdup(*(const char **)a2);
return ircproto_nick();
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
free(bot_nick);
bot_nick = strdup(*(const char **)a2);
return ircproto_nick();
}

original_code:
static void nick(char *line, char **caps, int ncaps)
{
 if (ncaps > 1 && *caps[1])
  info("nick: must have one argument");
 free(bot_nick);
 bot_nick = strdup(caps[0]);
 ircproto_nick(caps[0]);
}


cd

decompiled_code:
char *__fastcall cd(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
info();
return strcpy(&chan, *(const char **)a2);
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
info();
return strcpy(&chan, *(const char **)a2);
}

original_code:
static void cd(char *line, char **caps, int ncaps)
{
 if (ncaps > 1 && *caps[1])
  info("cd: must have one argument");
 info("now talking on %s", caps[0]);
 strcpy(chan, caps[0]);
}


quit

decompiled_code:
__int64 quit()
{
return safe_shutdown_and_die();
}

canonical_decompiled_code:
__int64 func7()
{
return safe_shutdown_and_die();
}

original_code:
static void quit(char *line, char **caps, int ncaps)
{
 safe_shutdown_and_die(0);
}


finish

decompiled_code:
__int64 finish()
{
return eval_destroy();
}

canonical_decompiled_code:
__int64 func14()
{
return eval_destroy();
}

original_code:
void finish()
{
 eval_destroy(ectx);
}

canonical_original_code:
void finish()
{
 eval_destroy(ectx);
}


decompiled_code:
__int64 __fastcall ircproto_parse_prefix(char *src, char *dest, int a3, char *a4, int a5, char *a6, int a7)
{
char *v8; // rbp
__int64 result; // rax
int v10; // er14
int v11; // er13
int v12; // er15
int v13; // er14
int v14; // er13
int v15; // ebx
int v16; // er12
char *v19; // [rsp+18h] [rbp-50h]
int v21; // [rsp+28h] [rbp-40h]

v8 = strchr(src, 33);
v19 = strchr(src, 64);
result = strlen(src);
v21 = result;
if ( dest )
{
v10 = (_DWORD)v8 - (_DWORD)src;
if ( !v8 )
v10 = result;
v11 = a3 - 1;
v12 = v10;
if ( v11 <= v10 )
v12 = v11;
result = (__int64)strncpy(dest, src, v12);
dest[v12] = 0;
if ( v11 < v10 )
result = info("parse_prefix: %s: nick overflow", dest);
}
if ( a4 )
{
if ( v8 )
{
v13 = (_DWORD)v19 - ((_DWORD)v8 + 1);
v14 = v13;
if ( a5 - 1 <= v13 )
v14 = a5 - 1;
result = (__int64)strncpy(a4, v8 + 1, v14);
a4[v14] = 0;
if ( a5 - 1 < v13 )
result = info("parse_prefix: %s: uname overflow", a4);
}
else
{
result = (__int64)a4;
*a4 = 0;
}
}
if ( a6 )
{
if ( v19 )
{
v15 = v21 + (_DWORD)src - ((_DWORD)v19 + 1);
v16 = v15;
if ( a7 - 1 <= v15 )
v16 = a7 - 1;
result = (__int64)strncpy(a6, v19 + 1, v16);
a6[v16] = 0;
if ( a7 - 1 < v15 )
result = info("parse_prefix: %s: host overflow", a6);
}
else
{
result = (__int64)a6;
*a6 = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, char *dest, int a3, char *a4, int a5, char *a6, int a7)
{
char *v8; // rbp
__int64 result; // rax
int v10; // er14
int v11; // er13
int v12; // er15
int v13; // er14
int v14; // er13
int v15; // ebx
int v16; // er12
char *v19; // [rsp+18h] [rbp-50h]
int v21; // [rsp+28h] [rbp-40h]

v8 = strchr(src, 33);
v19 = strchr(src, 64);
result = strlen(src);
v21 = result;
if ( dest )
{
v10 = (_DWORD)v8 - (_DWORD)src;
if ( !v8 )
v10 = result;
v11 = a3 - 1;
v12 = v10;
if ( v11 <= v10 )
v12 = v11;
result = (__int64)strncpy(dest, src, v12);
dest[v12] = 0;
if ( v11 < v10 )
result = info("parse_prefix: %s: nick overflow", dest);
}
if ( a4 )
{
if ( v8 )
{
v13 = (_DWORD)v19 - ((_DWORD)v8 + 1);
v14 = v13;
if ( a5 - 1 <= v13 )
v14 = a5 - 1;
result = (__int64)strncpy(a4, v8 + 1, v14);
a4[v14] = 0;
if ( a5 - 1 < v13 )
result = info("parse_prefix: %s: uname overflow", a4);
}
else
{
result = (__int64)a4;
*a4 = 0;
}
}
if ( a6 )
{
if ( v19 )
{
v15 = v21 + (_DWORD)src - ((_DWORD)v19 + 1);
v16 = v15;
if ( a7 - 1 <= v15 )
v16 = a7 - 1;
result = (__int64)strncpy(a6, v19 + 1, v16);
a6[v16] = 0;
if ( a7 - 1 < v15 )
result = info("parse_prefix: %s: host overflow", a6);
}
else
{
result = (__int64)a6;
*a6 = 0;
}
}
return result;
}

original_code:
void ircproto_parse_prefix(char *prefix,
                  char *nick, int nicksz,
                  char *user, int usersz,
                  char *host, int hostsz)
{
 char *bang, *at, *end, *uidx, *hidx;
 int nlen, ulen, hlen;
 int ncpy, ucpy, hcpy;
 bang = strchr(prefix, '!');
 at = strchr(prefix, '@');
 end = prefix + strlen(prefix);
 if (nick) {
  nlen = bang ? bang - prefix : end - prefix;
  ncpy = ((nlen) < (nicksz - 1) ? (nlen) : (nicksz - 1));
  strncpy(nick, prefix, ncpy);
  nick[ncpy] = '\0';
  if (ncpy != nlen)
   info("parse_prefix: %s: nick overflow", nick);
 }
 if (user) {
  if (bang) {
   uidx = bang + 1;
   ulen = at - uidx;
   ucpy = ((ulen) < (usersz - 1) ? (ulen) : (usersz - 1));
   strncpy(user, uidx, ucpy);
   user[ucpy] = '\0';
   if (ucpy != ulen)
    info("parse_prefix: %s: uname overflow", user);
  }
  else
   user[0] = '\0';
 }
 if (host) {
  if (at) {
   hidx = at + 1;
   hlen = end - hidx;
   hcpy = ((hlen) < (hostsz - 1) ? (hlen) : (hostsz - 1));
   strncpy(host, hidx, hcpy);
   host[hcpy] = '\0';
   if (hcpy != hlen)
    info("parse_prefix: %s: host overflow", host);
  }
  else
   host[0] = '\0';
 }
}

canonical_original_code:
void ircproto_parse_prefix(char *prefix, char *nick, int nicksz, char *user, int usersz, char *host, int hostsz)
{
 char *bang; char *at; char *end; char *uidx; char *hidx;
 int nlen; int ulen; int hlen;
 int ncpy; int ucpy; int hcpy;
 bang = strchr(prefix, '!');
 at = strchr(prefix, '@');
 end = prefix + strlen(prefix);
 if (nick) {
  nlen = bang ? bang - prefix : end - prefix;
  ncpy = ((nlen) < (nicksz - 1) ? (nlen) : (nicksz - 1));
  strncpy(nick, prefix, ncpy);
  nick[ncpy] = '\0';
  if (ncpy != nlen)
   info("parse_prefix: %s: nick overflow", nick);
 }
 if (user) {
  if (bang) {
   uidx = bang + 1;
   ulen = at - uidx;
   ucpy = ((ulen) < (usersz - 1) ? (ulen) : (usersz - 1));
   strncpy(user, uidx, ucpy);
   user[ucpy] = '\0';
   if (ucpy != ulen)
    info("parse_prefix: %s: uname overflow", user);
  }
  else
   user[0] = '\0';
 }
 if (host) {
  if (at) {
   hidx = at + 1;
   hlen = end - hidx;
   hcpy = ((hlen) < (hostsz - 1) ? (hlen) : (hostsz - 1));
   strncpy(host, hidx, hcpy);
   host[hcpy] = '\0';
   if (hcpy != hlen)
    info("parse_prefix: %s: host overflow", host);
  }
  else
   host[0] = '\0';
 }
}

variable_types:
prefix
char *

variable_types:
nick
char *

variable_types: nicksz int

variable_types:
user
char *

variable_types: usersz int

variable_types:
host
char *

variable_types: hostsz int

variable_types:
bang
char *

variable_types:
at
char *

variable_types:
end
char *

variable_types:
uidx
char *

variable_types:
hidx
char *

variable_types: nlen int

variable_types: ulen int

variable_types: hlen int

variable_types: ncpy int

variable_types: ucpy int

variable_types: hcpy int


decompiled_code:
__int64 __fastcall ircproto_pong(const char *a1)
{
return sock_sendline("PONG %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
return sock_sendline("PONG %s", a1);
}

original_code:
void ircproto_pong(char *id)
{
 sock_sendline("PONG %s", id);
}

variable_types:
id
char *